DBA Data[Home] [Help]

PACKAGE BODY: APPS.CSI_MASS_EDIT_PUB

Source


1 PACKAGE BODY csi_mass_edit_pub as
2 /* $Header: csipmeeb.pls 120.59.12020000.2 2012/08/13 05:53:04 sjawaji ship $ */
3 -- Start of Comments
4 -- Package name     : CSI_MASS_EDIT_PUB
5 -- Purpose          :
6 
7 -- History          :
8 -- NOTE             :
9 -- End of Comments
10 
11 G_PKG_NAME  CONSTANT VARCHAR2(30) := 'CSI_MASS_EDIT_PUB';
12 G_FILE_NAME CONSTANT VARCHAR2(12) := 'csipmeeb.pls';
13 
14 /* local routine to wrap the gen utility debug stuff */
15 
16   PROCEDURE debug(
17     p_message IN varchar2)
18   IS
19   BEGIN
20     FND_FILE.PUT_LINE (FND_FILE.LOG, p_message );
21     csi_t_gen_utility_pvt.add(p_message);
22   END debug;
23 
24   PROCEDURE debug_out(
25     p_message IN varchar2)
26   IS
27   BEGIN
28     FND_FILE.PUT_LINE (FND_FILE.OUTPUT, p_message );
29   END debug_out;
30 
31 
32 
33   PROCEDURE conc_report (
34     p_temp_merror_tbl          IN  CSI_MASS_EDIT_PUB.Mass_Upd_Rep_Error_Tbl,
35     p_name                     IN  VARCHAR2,
36     p_batch_id                 IN  NUMBER,
37     p_batch_name               IN  VARCHAR2
38     ) IS
39    l_temp_merror_tbl           csi_mass_edit_pub.Mass_Upd_Rep_Error_Tbl;
40    l_repo_merror_tbl           csi_mass_edit_pub.Mass_Upd_Rep_Error_Tbl;
41    l_rep_instance_id           NUMBER;
42    l_rep_txn_line_id           NUMBER;
43 
44   BEGIN
45     -- Sorting the error table based on the Instance_Id
46     l_temp_merror_tbl.delete;
47     l_temp_merror_tbl := p_temp_merror_tbl;
48     IF p_temp_merror_tbl.COUNT > 0 THEN
49     For i in l_temp_merror_tbl.FIRST .. l_temp_merror_tbl.LAST
50     LOOP
51       If l_temp_merror_tbl.exists(i)
52       Then
53         l_repo_merror_tbl(l_repo_merror_tbl.count + 1) := l_temp_merror_tbl(i);
54         l_rep_instance_id := l_temp_merror_tbl(i).Instance_Id;
55         -- l_rep_txn_line_id := l_temp_merror_tbl(i).txn_line_detail_id;
56         l_temp_merror_tbl.DELETE(i);
57         If l_temp_merror_tbl.count > 0
58         Then
59           For j in l_temp_merror_tbl.FIRST .. l_temp_merror_tbl.LAST
60           Loop
61             If l_temp_merror_tbl.EXISTS(j)
62             Then
63               If l_temp_merror_tbl(j).INSTANCE_ID        = l_rep_instance_id
64                 -- AND
65                 -- l_temp_merror_tbl(j).txn_line_detail_id = l_rep_txn_line_id
66               Then
67                  l_repo_merror_tbl(l_repo_merror_tbl.count + 1) := l_temp_merror_tbl(j);
68                  l_temp_merror_tbl.DELETE(j);
69               End If;
70             End If;
71           End Loop;
72         End If;
73       End If;
74     End Loop;
75    END IF; -- IF p_temp_merror_tbl.COUNT > 0 THEN
76     If l_repo_merror_tbl.count > 0
77     Then
78       /*
79       -- Log File
80       debug(' ');
81       debug('************************ Begin  Report for Batch ('||P_BATCH_NAME||')  ************************');
82       debug(' ');
83       debug('Instance  Error Code  Error Message');
84       debug('--------  ----------  -------------');
85       For i in l_repo_merror_tbl.FIRST .. l_repo_merror_tbl.LAST
86       LOOP
87         debug(rpad(to_char(l_repo_merror_tbl(i).instance_id),10,' ')||rpad(l_repo_merror_tbl(i).error_code,12,' ')||substr(l_repo_merror_tbl(i).error_message,1,length(l_repo_merror_tbl(i).error_message)));
88       ENd Loop;
89       debug(' ');
90       debug('************************ End Of Report for Batch ('||P_BATCH_NAME||')  ************************');
91       debug(' ');
92       */
93       Debug(' ');
94       Debug('Mass Edit Batch Status : FAILED');
95       Debug(' ');
96 
97       -- Out File
98       Debug_out(' ');
99       Debug_out('Mass Edit Batch Status : FAILED');
100       Debug_out(' ');
101       debug_out(' ');
102       debug_out('************************ Begin  Report for Batch ('||P_BATCH_NAME||')  ************************');
103       debug_out(' ');
104       Debug_out('Instance/s in this batch completed with the following error.');
105       For i in l_repo_merror_tbl.FIRST .. l_repo_merror_tbl.FIRST
106       LOOP
107       Debug_out('Error message: '||substr(l_repo_merror_tbl(i).error_message,1,length(l_repo_merror_tbl(i).error_message)));
108       end loop;
109       Debug_out(' ');
110       /* -- Commented for bug 5167944
111       debug_out('Instance  Error Code  Error Message');
112       debug_out('--------  ----------  -------------');
113       For i in l_repo_merror_tbl.FIRST .. l_repo_merror_tbl.LAST
114       LOOP
115         debug_out(rpad(to_char(l_repo_merror_tbl(i).instance_id),10,' ')||rpad(l_repo_merror_tbl(i).error_code,12,' ')||substr(l_repo_merror_tbl(i).error_message,1,length(l_repo_merror_tbl(i).error_message)));
116       ENd Loop;
117       debug_out(' ');
118       */
119       debug_out('************************ End Of Report for Batch ('||P_BATCH_NAME||')  ************************');
120       debug_out(' ');
121 
122     End If;
123 
124   End conc_report;
125 
126 
127 PROCEDURE update_error_status (
128     p_error_tbl             IN   csi_mass_edit_pub.Mass_Upd_Rep_Error_Tbl,
129     p_txn_line_id           IN   NUMBER,
130     p_entry_id              IN   NUMBER
131    ) is
132 l_instance_id    NUMBER;
133 l_error_flag     VARCHAR2(1) := 'N';
134 PRAGMA AUTONOMOUS_TRANSACTION;
135 Begin
136 
137   -- Updating Batch status
138   UPDATE csi_mass_edit_entries_b
139   SET    status_code = 'FAILED'
140   WHERE  entry_id    = p_entry_id;
141 
142   -- Updating status for each failed transaction_line_detail_id with instance
143   IF p_error_tbl.COUNT > 0 THEN
144   FOR j in p_error_tbl.FIRST .. p_error_tbl.LAST
145   LOOP
146     -- UPDATE csi_t_txn_line_details
147     -- SET    error_explanation   = p_grp_error_tbl(j).Error_Message,
148     --        processing_status   = 'ERROR',
149     --        error_code          = 'E'
150     -- WHERE  transaction_line_id = p_txn_line_id
151     -- AND    instance_id         = p_grp_error_tbl(j).Instance_ID;
152     If l_instance_id is null
153     Then
154       l_instance_id := p_error_tbl(j).instance_id;
155     End If;
156 
157     If l_instance_id = p_error_tbl(j).instance_id
158     Then
159       If  p_error_tbl(j).ERROR_CODE in ('E','U')
160       Then
161          l_error_flag := 'E';
162       ElsIf p_error_tbl(j).ERROR_CODE = 'W'
163            AND
164             l_error_flag <> 'E'
165       Then
166            l_error_flag := 'W';
167       End If;
168     End If;
169 
170     If l_instance_id <> p_error_tbl(j).instance_id
171     Then
172       If l_error_flag = 'E'
173       Then
174          UPDATE csi_t_txn_line_details
175          SET    processing_status   = 'ERROR',
176                 ERROR_CODE          = 'E'
177          WHERE  transaction_line_id = p_txn_line_id
178          AND    instance_id         = l_instance_id;
179       Else
180          UPDATE csi_t_txn_line_details
181          SET    processing_status   = 'WARNING',
182                 ERROR_CODE          = 'W'
183          WHERE  transaction_line_id = p_txn_line_id
184          AND    instance_id         = l_instance_id;
185       End If;
186       l_error_flag := 'N';
187       If  p_error_tbl(j).ERROR_CODE in ('E','U')
188       Then
189          l_error_flag := 'E';
190       ElsIf p_error_tbl(j).ERROR_CODE = 'W'
191       Then
192          l_error_flag := 'W';
193       End If;
194       l_instance_id := p_error_tbl(j).instance_id;
195     End If;
196   END LOOP;
197   END IF; -- IF p_error_tbl.COUNT > 0 THEN
198 
199   Commit;
200 
201 End update_error_status;
202 
203 PROCEDURE UPDATE_MUSYS_ERR_STATUS (
204     p_entry_id              IN   NUMBER
205    ) IS
206 PRAGMA AUTONOMOUS_TRANSACTION;
207 BEGIN
208 
209   -- Updating Batch status
210   UPDATE csi_mass_edit_entries_b
211   SET    status_code = 'FAILED'
212   WHERE  entry_id    = p_entry_id;
213 
214 COMMIT;
215 
216 END UPDATE_MUSYS_ERR_STATUS;
217 
218 PROCEDURE validate_loc_pty
219 ( p_instance_id     IN      NUMBER  ,
220   p_txn_line_id     IN      NUMBER  ,
221   x_return_status   OUT NOCOPY     VARCHAR2
222  ) IS
223 
224 CURSOR core_csr (p_instance_id IN NUMBER) IS
225 SELECT cii.location_id                location_id
226       ,cii.location_type_code         location_type_code
227       ,cii.install_location_id        install_location_id
228       ,cii.install_location_type_code install_location_type_code
229       ,cip.party_id                   party_id
230       ,cip.party_source_table         party_source_table
231 FROM  csi_item_instances cii
232      ,csi_i_parties      cip
233 WHERE cii.instance_id = p_instance_id
234 AND   cip.instance_id = cii.instance_id
235 AND   cip.relationship_type_code = 'OWNER';
236 
237 CURSOR source_csr (p_txn_line_id IN NUMBER,p_instance_id IN NUMBER) IS
238 SELECT cil.location_id                 location_id
239        ,cil.location_type_code         location_type_code
240        ,cil.install_location_id        install_location_id
241        ,cil.install_location_type_code install_location_type_code
242        ,cid.party_source_id            party_id
243        ,cid.party_source_table         party_source_table
244 FROM  csi_t_txn_line_details cil
245      ,csi_t_party_details    cid
246 WHERE cil.transaction_line_id = p_txn_line_id
247 AND   cil.instance_id         = p_instance_id
248 AND   cid.txn_line_detail_id  = cil.txn_line_detail_id
249 AND   cid.relationship_type_code = 'OWNER';
250 
251 l_core_csr      core_csr%ROWTYPE;
252 l_source_csr    source_csr%ROWTYPE;
253 
254 BEGIN
255 
256 OPEN   core_csr (p_instance_id);
257 FETCH  core_csr INTO l_core_csr;
258 CLOSE  core_csr;
259 
260 OPEN   source_csr (p_txn_line_id,p_instance_id);
261 FETCH  source_csr INTO l_source_csr;
262 CLOSE  source_csr;
263 
264   IF    NVL(l_core_csr.location_id,-1) <> NVL(l_source_csr.location_id,-1)
265     OR NVL(l_core_csr.location_type_code,'#@*') <> NVL(l_source_csr.location_type_code,'#@*')
266     OR NVL(l_core_csr.install_location_id,-1) <> NVL(l_source_csr.install_location_id,-1) --third addition
267     OR NVL(l_core_csr.install_location_type_code,'#@*') <> NVL(l_source_csr.install_location_type_code,'#@*')
268     OR l_core_csr.party_id <> l_source_csr.party_id
269     OR l_core_csr.party_source_table <> l_source_csr.party_source_table
270   THEN
271     x_return_status:='F';
272   END IF;
273   x_return_status:='T';
274 EXCEPTION
275   WHEN OTHERS THEN
276   x_return_status:='F';
277 END;
278 
279 /* ---------------------------------------------------------------- */
280 -- Procedure Initiate_Mass_Edit is registered as concurrent program
281 -- This program fires periodically at the specified time interval
282 -- and kicks of the Process_mass_edit_batch(Another concurrent process)
283 -- whenever it finds records with status SCHEDULED.
284 /* ---------------------------------------------------------------- */
285 PROCEDURE Initiate_Mass_Edit
286    (
287      errbuf                       OUT NOCOPY    VARCHAR2
288     ,retcode                      OUT NOCOPY    NUMBER
289     ,p_entry_id                   IN  NUMBER
290     )
291  IS
292 l_api_name                   CONSTANT VARCHAR2(30) := 'Initiate_Mass_Edit';
293 l_api_version                CONSTANT NUMBER       := 1.0;
294 l_return_status_full                  VARCHAR2(1);
295 l_access_flag                         VARCHAR2(1);
296 l_line_count                          NUMBER;
297 l_debug_level                         NUMBER;
298 l_entry_id                            NUMBER       := 0;
299 l_request_id                          NUMBER     ;
300 l_errbuf                              VARCHAR2(2000);
301 l_mass_edit_tbl                       csi_mass_edit_pub.mass_edit_tbl;
302 i                                     NUMBER;
303 --l_txn_rec                             csi_datastructures_pub.transaction_rec;
304 l_count                               NUMBER;
305 l_warning                             NUMBER := 0;
306 l_error                               NUMBER := 0;
307 l_success                             NUMBER := 0;
308 l_temp                                BOOLEAN;
309 l_is_re_upload						  BOOLEAN := FALSE;
310 l_reupld_batch_id					  NUMBER;
311 l_dummy								  VARCHAR2(1);
312 
313 
314 CURSOR mass_edit_csr(p_entry_id in NUMBER) IS
315     SELECT entry_id, batch_type, name, schedule_date
316     FROM   csi_mass_edit_entries_vl
317     WHERE  status_code = 'SCHEDULED'
318     AND    schedule_date <= SYSDATE
319     AND    entry_id = nvl(p_entry_id,entry_id);
320 
321  BEGIN
322 
323       debug(' ');
324       debug( 'Initiate Mass Edit Concurrent Process');
325       debug(' ');
326 
327       debug_out(' ');
328       debug_out( 'Initiate Mass Edit Concurrent Program');
329       debug_out(' ');
330 
331       --Checking if it is a re-uploaded WEB ADI batch
332 	  IF(p_entry_id IS NOT NULL) THEN
333 		  BEGIN
334 			Select 'Y' INTO l_dummy from dual where
335 			EXISTS( select 'Y'
336 					from  csi_mass_edit_entries_vl cmeev, CSI_WEBADI_STAGING cws
337 					WHERE cmeev.ENTRY_ID = cws.BATCH_ID
338 					AND cmeev.STATUS_CODE IN ('SUCCESSFUL', 'FAILED')
339 					AND cmeev.BATCH_TYPE = 'WBADI'
340 					AND nvl(cws.PROCESSING_STATUS, 'N') <> 'P'
341 					AND cmeev.ENTRY_ID = p_entry_id);
342 			debug('re-up query got executed');
343 			l_is_re_upload	:= TRUE;
344 		  EXCEPTION
345 				WHEN NO_DATA_FOUND THEN
346 					l_is_re_upload	:= FALSE;
347 					debug('In re-up no data found block.');
348 		  END;
349 
350 		  IF(l_is_re_upload) THEN
351 			debug('The Mass update batch being processed is a re-uploaded Web ADI batch.');
352 			debug_out('The Mass update batch being processed is a re-uploaded Web ADI batch.');
353 			Create_Reupload_Batch(errbuf			=>	errbuf,
354 								  retcode			=>	retcode,
355 								  p_entry_id		=>	p_entry_id,
356 								  p_reupld_batch_id	=>	l_reupld_batch_id);
357 			IF(l_reupld_batch_id IS NOT NULL) THEN
358 				l_entry_id	:=	l_reupld_batch_id;
359 			ELSE
360 				debug('The p_reupld_batch_id returned from Create_Reupload_Batch is NULL.');
361 				l_entry_id	:=	p_entry_id;
362 			END IF;
363 		  ELSE
364 			l_entry_id	:=	p_entry_id;
365 			debug('The batch being processed is is not a re-uploaded Web ADI batch.');
366 		  END IF;
367 	  ELSE
368 		l_entry_id	:=	NULL; --Added for Bug 14481917
369 	  END IF;
370 	  --End of code for re-uploaded batch
371 
372 	  BEGIN
373 	  	UPDATE csi_mass_edit_entries_b
374 		SET    status_code = 'SCHEDULED',
375              SCHEDULE_DATE = SYSDATE
376 		WHERE  BATCH_TYPE = 'WBADI'
377              AND status_code = 'CREATED';
378 
379 		i:=0;
380         FOR l_mass_edit_csr IN mass_edit_csr(l_entry_id)
381         LOOP
382           i:=i+1;
383           l_mass_edit_tbl(i).entry_id := l_mass_edit_csr.entry_id;
384 		  l_mass_edit_tbl(i).batch_type := l_mass_edit_csr.batch_type;
385 		  l_mass_edit_tbl(i).schedule_date := l_mass_edit_csr.schedule_date;
386 		  l_mass_edit_tbl(i).name := l_mass_edit_csr.name;
387         END LOOP;
388       EXCEPTION
389          WHEN NO_DATA_FOUND THEN
390               NULL;
391       END;
392       l_count:=l_mass_edit_tbl.count;
393 
394       IF l_count > 0
395       THEN
396         FOR call_csr IN 1..l_count
397         LOOP
398 		  IF l_mass_edit_tbl(call_csr).batch_type = 'WBADI' THEN
399 			  debug(' Processing Mass Edit Batch : '||l_mass_edit_tbl(call_csr).name);
400 			  debug('                Batch Id    : '||l_mass_edit_tbl(call_csr).entry_id);
401 			  debug('                Batch Type  : '||l_mass_edit_tbl(call_csr).batch_type);
402 			  debug(' ');
403 
404 			  debug_out(' ');
405 			  debug_out(' ');
406 			  debug_out(' Processing Mass Edit Batch : '||l_mass_edit_tbl(call_csr).name);
407 			  debug_out('                Batch Id    : '||l_mass_edit_tbl(call_csr).entry_id);
408 			  debug_out('                Batch Type  : '||l_mass_edit_tbl(call_csr).batch_type);
409 			  debug_out(' ');
410 			Process_webadi_batch(errbuf, retcode, l_mass_edit_tbl(call_csr).entry_id, l_mass_edit_tbl(call_csr).batch_type, l_mass_edit_tbl(call_csr).schedule_date);
411 		  ELSE
412 			Process_mass_edit_batch(errbuf,retcode,l_mass_edit_tbl(call_csr).entry_id);
413 		  END IF;
414 
415           /*
416           l_request_id := FND_REQUEST.SUBMIT_REQUEST('CSI', 'CSIMEDT', 'Mass Edit Concurrent program ' , NULL, FALSE, l_mass_edit_tbl(call_csr).entry_id);--, l_txn_rec);
417 
418           debug('Calling Process Mass Edit Batch Concurrent Process');
419           debug('');
420           debug('Submitting with Parameters');
421           debug('Batch Id        : '|| l_mass_edit_tbl(call_csr).entry_id);
422           debug('');
423           IF (l_request_id = 0) THEN
424             l_errbuf  := FND_MESSAGE.GET;
425             debug('Call to Process Mass Edit Batch Concurrent Process has errored');
426             debug('For Batch Id'||l_mass_edit_tbl(call_csr).entry_id);
427             debug('Error message   :'||substr(l_errbuf,1,75));
428             debug('                :'||substr(l_errbuf,76,150));
429             debug('                :'||substr(l_errbuf,151,225));
430             debug('                :'||substr(l_errbuf,226,300));
431           END IF;
432           */
433           If errbuf = 'W'
434           Then
435             l_warning := l_warning + 1;
436           Elsif errbuf = 'E'
437           Then
438             l_error    := l_error + 1;
439           Else
440             l_success  := l_success + 1;
441           End If;
442         END LOOP;
443 
444         If l_error > 0
445         Then
446           l_temp := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR','');
447         ElsIf l_warning > 0
448         Then
449          l_temp := FND_CONCURRENT.SET_COMPLETION_STATUS('WARNING','');
450         End If;
451 
452       ELSE
453          debug(' ');
454          debug('Unable to find any records to call Process Mass Edit Batch Concurrent Process ');
455          debug(' ');
456       END IF;
457 
458       --
459       -- End of API body
460       --
461 
462 EXCEPTION
463  WHEN OTHERS THEN
464     debug('When others exception from Initiate_Mass_Edit');
465 END Initiate_Mass_Edit;
466 
467 /* ------------------------------------------------------------------- */
468 -- Procedure Process_mass_edit_batch is registered as concurrent program
469 -- This program gets initiated by initiate_mass_edit concurren program.
470 /* ------------------------------------------------------------------- */
471 PROCEDURE Process_mass_edit_batch
472    ( errbuf                       OUT NOCOPY    VARCHAR2
473     ,retcode                      OUT NOCOPY    NUMBER
474     ,p_Entry_id                   IN     NUMBER
475    ) IS
476 
477   -- Cursors
478   CURSOR selected_instance_csr (p_txn_line_id IN NUMBER) IS
479    SELECT ctld.instance_id
480          ,ctld.transaction_line_id
481          ,nvl(ctld.location_id, FND_API.G_MISS_NUM) location_id
482          ,nvl(ctld.location_type_code, FND_API.G_MISS_CHAR) location_type_code
483          ,nvl(ctld.install_location_id, FND_API.G_MISS_NUM) install_location_id
484          ,nvl(ctld.install_location_type_code, FND_API.G_MISS_CHAR) install_location_type_code
485          ,cii.object_version_number
486          ,cii.instance_usage_code
487    FROM   csi_t_txn_line_details ctld,
488           csi_item_instances cii
489    WHERE  ctld.transaction_line_id = p_txn_line_id
490    AND    ctld.INSTANCE_ID is not null
491    AND    ctld.preserve_detail_flag = 'Y'
492    AND    cii.instance_id = ctld.instance_id;
493 
494   CURSOR core_inst_pty_acct_csr (p_txn_line_id IN NUMBER) IS
495     SELECT cip.instance_party_id          pty_instance_party_id,
496            cip.instance_id                pty_instance_id,
497            cip.party_source_table         pty_party_source_table,
498            cip.party_id                   pty_party_id,
499            cip.relationship_type_code     pty_rel_type_code,
500            cip.object_version_number      pty_obj_version_number
501           ,cia.ip_account_id              pty_acc_ip_account_id,
502            cia.instance_party_id          pty_acc_instance_party_id,
503            cia.party_account_id           pty_acc_party_account_id,
504            cia.relationship_type_code     pty_acct_rel_type_code,
505            cia.object_version_number      pty_acct_obj_version_number
506     FROM   csi_i_parties cip,
507            csi_ip_accounts cia,
508            csi_t_txn_line_details ctld
509     WHERE  cip.instance_id            = ctld.instance_id
510     AND    cip.contact_flag           ='N'
511     AND    cip.relationship_type_code = 'OWNER'
512     AND    ctld.transaction_line_id   = p_txn_line_id
513     AND    ctld.instance_exists_flag  = 'Y'
514     AND    ctld.preserve_detail_flag  = 'Y'
515     AND    cia.instance_party_id      = cip.instance_party_id
516     AND    cia.relationship_type_code = 'OWNER'
517 
518     UNION
519     SELECT cip.instance_party_id          pty_instance_party_id,
520            cip.instance_id                pty_instance_id,
521            cip.party_source_table         pty_party_source_table,
522            cip.party_id                   pty_party_id,
523            cip.relationship_type_code     pty_rel_type_code,
524            cip.object_version_number      pty_obj_version_number,
525            null              			  pty_acc_ip_account_id,
526            null              			  pty_acc_instance_party_id,
527            null              			  pty_acc_party_account_id,
528            null              			  pty_acct_rel_type_code,
529            null              			  pty_acct_obj_version_number
530     FROM   csi_i_parties cip,
531            csi_t_txn_line_details ctld
532     WHERE  cip.instance_id            = ctld.instance_id
533     AND    cip.contact_flag           ='N'
534     AND    cip.relationship_type_code = 'OWNER'
535     AND    ctld.transaction_line_id   = p_txn_line_id
536     AND    ctld.instance_exists_flag  = 'Y'
537     AND    ctld.preserve_detail_flag  = 'Y'
538 	AND    cip.party_id in (SELECT INTERNAL_PARTY_ID FROM csi_install_parameters)
539 	AND    NOT EXISTS (SELECT 'X' FROM csi_i_parties cip, csi_ip_accounts cia
540 						WHERE cip.INSTANCE_PARTY_ID = cia.INSTANCE_PARTY_ID
541 						AND   cip.instance_id = ctld.instance_id
542 			            AND   cip.contact_flag           = 'N'
543 			            AND   cip.relationship_type_code = 'OWNER');
544 
545   CURSOR curr_asso_csr (p_instance_id IN NUMBER) IS
546     SELECT cip.instance_party_id          pty_instance_party_id,
547            cip.instance_id                pty_instance_id,
548            cip.party_source_table         pty_party_source_table,
549            cip.party_id                   pty_party_id,
550            cip.relationship_type_code     pty_rel_type_code,
551            cip.object_version_number      pty_obj_version_number
552     FROM   csi_i_parties cip
553     WHERE  cip.instance_id            = p_instance_id
554     AND    cip.contact_flag           = 'N'
555     AND    nvl(cip.active_end_date,sysdate) >= sysdate;
556 
557   CURSOR core_iea_val_csr (p_txn_line_id IN NUMBER) IS
558     SELECT ciev.attribute_value_id
559           ,ciev.attribute_id
560           ,ctld.instance_id  --  Bug 7613909
561           ,ciev.attribute_value
562           ,ciev.object_version_number
563     FROM   csi_iea_values ciev,
564            csi_t_txn_line_details ctld
565     WHERE  ciev.instance_id (+)     = ctld.instance_id   --  Bug 7613909
566     AND    ctld.transaction_line_id = p_txn_line_id
567     AND    ctld.instance_id is not null;
568    -- Local Variables
569    l_txn_rec                         csi_datastructures_pub.transaction_rec;
570 
571    -- Variables for Dummy record details
572    d_txn_line_query_rec        csi_t_datastructures_grp.txn_line_query_rec;
573    d_txn_line_detail_query_rec csi_t_datastructures_grp.txn_line_detail_query_rec;
574    d_line_dtl_tbl              csi_t_datastructures_grp.txn_line_detail_tbl;
575    d_pty_dtl_tbl               csi_t_datastructures_grp.txn_party_detail_tbl;
576    d_pty_acct_tbl              csi_t_datastructures_grp.txn_pty_acct_detail_tbl;
577    d_ii_rltns_tbl              csi_t_datastructures_grp.txn_ii_rltns_tbl;
578    d_org_assgn_tbl             csi_t_datastructures_grp.txn_org_assgn_tbl;
579    d_ext_attrib_tbl            csi_t_datastructures_grp.txn_ext_attrib_vals_tbl;
580    d_csi_ea_tbl                csi_t_datastructures_grp.csi_ext_attribs_tbl;
581    d_csi_eav_tbl               csi_t_datastructures_grp.csi_ext_attrib_vals_tbl;
582    d_txn_systems_tbl           csi_t_datastructures_grp.txn_systems_tbl;
583    l_return_status             VARCHAR2(1) := fnd_api.g_ret_sts_success;
584    l_msg_count                 NUMBER;
585    l_msg_data                  VARCHAR2(2000);
586 
587    -- New Tables for the selected instances in the batch
588    n_instance_tbl              csi_datastructures_pub.instance_tbl;
589    n_party_tbl                 csi_datastructures_pub.party_tbl;
590    n_party_account_tbl         csi_datastructures_pub.party_account_tbl;
591    n_ext_attrib_values_tbl     csi_datastructures_pub.extend_attrib_values_tbl;
592    n_price_tbl                 csi_datastructures_pub.pricing_attribs_tbl;
593    n_org_assignments_tbl       csi_datastructures_pub.organization_units_tbl;
594    n_asset_assignment_tbl      csi_datastructures_pub.instance_asset_tbl;
595    n_txn_rec                   csi_datastructures_pub.transaction_rec;
596    n_rel_txn_rec               csi_datastructures_pub.transaction_rec;
597    n_grp_error_tbl             csi_datastructures_pub.grp_upd_error_tbl;
598    n_instance_id_lst           csi_datastructures_pub.id_tbl;
599 
600    l_api_version               NUMBER:=1.0;
601    l_commit                    VARCHAR2(1) ;
602    l_msg_index                 NUMBER;
603    l_error_message             VARCHAR2(2000);
604    l_warning_message           VARCHAR2(2000);
605    l_errbuf                    VARCHAR2(2000);
606    n_inst_ind                  NUMBER := 0;
607    l_parent_tbl_index          NUMBER := 0;
608    l_pty_index                 NUMBER := 0;
609    l_acct_index                NUMBER := 0;
610    l_cont_index                number := 0;
611    l_ext_attr_ind              NUMBER := 0;
612 
613    -- NEW OWNER Party variables
614    l_pty_src_table             VARCHAR2(80);
615    l_pty_party_id              NUMBER;
616    l_pty_rel_typ               VARCHAR2(80);
617    -- Assoc to expire
618    l_assoc_src_table           VARCHAR2(80);
619    l_assoc_party_id            NUMBER;
620    l_assoc_rel_typ             VARCHAR2(80);
621    l_assoc_end_date            DATE;
622    -- NEW OWNER Account variables
623    l_pry_account_id            NUMBER;
624    l_acct_rel_typ              VARCHAR2(80);
625    l_acct_bill_to              NUMBER;
626    l_acct_ship_to              NUMBER;
627    l_party_detail_id           NUMBER;
628    l_pty_tbl_ind               NUMBER := 0;
629 
630 
631    l_debug_level               NUMBER;
632    l_status                    VARCHAR2(1) :='N';
633    l_txn_line_id               NUMBER;
634    l_instance_id               NUMBER;
635    l_batch_type                VARCHAR2(30);
636    l_found_batch               VARCHAR2(30);
637    l_conc_status               BOOLEAN;
638 
639    l_medit_error_tbl           csi_mass_edit_pub.mass_edit_error_tbl;
640    l_temp_merror_tbl           csi_mass_edit_pub.Mass_Upd_Rep_Error_Tbl;
641    l_repo_merror_tbl           csi_mass_edit_pub.Mass_Upd_Rep_Error_Tbl;
642    l_rep_instance_id           NUMBER;
643    l_rep_txn_line_id           NUMBER;
644    l_found_error               VARCHAR2(1) := 'N';
645 
646    px_medit_rec                csi_mass_edit_pub.mass_edit_rec;
647 
648    l_note_id                   NUMBER;
649    l_batch_desc                VARCHAR2(2000);
650    l_name                      VARCHAR2(50);
651    l_batch_meaning             VARCHAR2(50);
652    l_batch_sch_date            DATE;
653    l_jtf_error                 VARCHAR2(1) := 'N';
654    l_jtf_err_ind               NUMBER := 0;
655    l_grp_api_ind               NUMBER := 0;
656 
657    l_system_cascade            VARCHAR2(1) := 'N'; -- ER 6031179
658    l_perform_system_mu         VARCHAR2(1) := 'N';
659    l_new_owner                 VARCHAR2(1);
660    l_old_owner                 VARCHAR2(1);
661    l_ext_attrib_exists         BOOLEAN;     -- Bug 8495187
662 
663 
664 BEGIN
665   l_debug_level:=fnd_profile.value('DEBUG_LEVEL');
666 
667     debug(' Processing .... ');
668     debug(' ');
669 
670   -- Checking for Batch Status
671   BEGIN
672     SELECT  a.txn_line_id,
673             a.batch_type,
674             b.meaning,
675             a.description,
676             a.name,
677             a.schedule_date,
678             a.system_cascade
679     INTO    l_txn_line_id,
680             l_batch_type,
681             l_batch_meaning,
682             l_batch_desc,
683             l_name,
684             l_batch_sch_date,
685             l_system_cascade
686     FROM    csi_mass_edit_entries_vl a,
687             csi_lookups b
688     WHERE   a.entry_id       = p_entry_id
689     AND     a.status_code    = 'SCHEDULED'
690     AND     a.schedule_date <= SYSDATE
691     AND     b.lookup_type    = 'CSI_IB_TXN_TYPE_CODE'
692     AND     b.lookup_code    = a.batch_type;
693 
694     l_status := 'Y';
695     debug('Found data for mass edit processing...  ');
696     debug(' ');
697 
698   EXCEPTION
699     WHEN NO_DATA_FOUND THEN
700       debug('No data for processing Mass Edit...  ');
701       debug('Aborting Concurrent Program');
702       debug(' ');
703       errbuf := 'E';
704     WHEN OTHERS THEN
705       debug('When others exception from Mass Edit Entry processing query..'||to_char(sqlcode)||'-'||substr(sqlerrm, 1, 255));
706       raise fnd_api.g_exc_error;
707   END;
708 
709   debug(' Processing Mass Edit Batch :'||l_name);
710   debug('                Batch Id    : '||p_entry_id);
711   debug('                Batch Type  : '||l_batch_meaning);
712   debug(' ');
713 
714   debug_out(' ');
715   debug_out(' ');
716   debug_out('Processing Mass Edit Batch : '||l_name);
717   debug_out('               Batch Id    : '||p_entry_id);
718   debug_out('               Batch Type  : '||l_batch_meaning);
719   debug_out(' ');
720 
721   -- Building Transaction rec
722   n_txn_rec.transaction_type_id     := 3;
723   --n_txn_rec.source_transaction_date := SYSDATE;
724   n_txn_rec.source_transaction_date := l_batch_sch_date;
725   n_txn_rec.transaction_date := SYSDATE;
726   n_txn_rec.SOURCE_HEADER_REF_ID    := p_entry_id;
727   n_txn_rec.SOURCE_GROUP_REF        := l_batch_type;
728 
729   -- Batch Type Validation
730   BEGIN
731     SELECT ib_txn_type_code
732     INTO   l_found_batch
733     FROM   csi_txn_sub_types
734     WHERE  transaction_type_id = 3
735     AND    ib_txn_type_code    = l_batch_type;
736 
737   EXCEPTION
738     WHEN NO_DATA_FOUND THEN
739       debug('Batch Type is not set for processing Mass Edit...  ');
740       debug('Aborting Concurrent Program');
741       errbuf := 'E';
742       debug(' ');
743     WHEN OTHERS THEN
744       debug('When others exception from Mass Edit Entry processing query..'||to_char(sqlcode)||'-'||substr(sqlerrm, 1, 255));
745       raise fnd_api.g_exc_error;
746   END;
747 
748   IF l_found_batch is not null
749   THEN
750     l_status := 'Y';
751   ELSE
752     l_status := 'N';
753   END IF;
754 
755   IF l_status = 'Y'
756   THEN
757 
758     -- Setting the Batch Status to 'Processing'
759     UPDATE csi_mass_edit_entries_b
760     SET    status_code = 'PROCESSING',
761            request_id  = FND_GLOBAL.CONC_REQUEST_ID
762     WHERE  entry_id = p_entry_id;
763     COMMIT;
764 
765     -- Common Validations
766     -- Validating the Current Location Attributes and Owner Party of the
767     -- Instances selecetd for processing with actual table values
768 
769     -- px_medit_rec.entry_id    :=  p_entry_id;
770     px_medit_rec.txn_line_id :=  l_txn_line_id;
771     px_medit_rec.batch_type  :=  l_batch_type;
772     px_medit_rec.name  :=  l_name;
773     -- px_medit_rec.description :=  l_batch_desc;
774 
775     csi_mass_edit_pvt.validate_batch(
776                           px_mass_edit_rec      => px_medit_rec,
777                           p_mode                => 'CP',
778                           x_mass_edit_error_tbl => l_medit_error_tbl,
779                           x_return_status       => l_return_status
780                          );
781     debug('Return status from validation routine : '|| l_return_status);
782 
783     If l_return_status <> fnd_api.g_ret_sts_success
784     Then
785       If l_medit_error_tbl.count > 0
786       Then
787         l_temp_merror_tbl.delete;
788         For e in l_medit_error_tbl.FIRST .. l_medit_error_tbl.LAST
789         Loop
790           l_temp_merror_tbl(e).Entry_Id           := l_medit_error_tbl(e).entry_id;
791           l_temp_merror_tbl(e).Txn_Line_Detail_Id := l_medit_error_tbl(e).Txn_Line_Detail_Id;
792           l_temp_merror_tbl(e).Instance_Id        := l_medit_error_tbl(e).Instance_Id;
793           l_temp_merror_tbl(e).Error_Message      := l_medit_error_tbl(e).Error_Text;
794           l_temp_merror_tbl(e).Error_Code         := l_medit_error_tbl(e).Error_Code;
795           l_temp_merror_tbl(e).NAME               := l_medit_error_tbl(e).NAME;
796           l_temp_merror_tbl(e).Entity_Name        := 'TXNLINE';
797         End Loop;
798       End If;
799       If l_return_status = 'E'
800       Then
801         l_found_error := 'E';
802         -- debug('Call update error status');
803         update_error_status(l_temp_merror_tbl,l_txn_line_id,p_entry_id);
804         -- debug('Call error report');
805         conc_report ( p_temp_merror_tbl => l_temp_merror_tbl,
806                       p_name            => 'VALERROR',
807                       p_batch_id        => p_entry_id,
808                       p_batch_name      => l_name
809                      );
810         debug('Aborting Concurrent Program by raising exception');
811         -- l_conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR','');
812         errbuf := 'E';
813       Else
814         If l_return_status = 'W'
815         Then
816           l_found_error := 'W';
817           errbuf := 'W';
818         End If;
819         l_return_status := 'T';
820       End If;
821     Else
822       l_return_status := 'T';
823     End If;
824 
825    BEGIN
826     savepoint START_PROCESSING;
827     IF l_return_status = 'T'
828     THEN
829       --l_total_count:=0;
830       --l_error_count:=0;
831 
832       -- Populating the New Data from dummy record
833       d_txn_line_query_rec.TRANSACTION_LINE_ID         := l_txn_line_id;
834       d_txn_line_query_rec.SOURCE_TRANSACTION_TABLE    := 'CSI_MASS_EDIT_ENTRIES';
835       d_txn_line_query_rec.source_transaction_id       := p_entry_id;
836       d_txn_line_detail_query_rec.TRANSACTION_LINE_ID  := l_txn_line_id;
837       d_txn_line_detail_query_rec.instance_exists_flag := 'N';
838 
839       csi_t_txn_details_grp.get_transaction_details(
840         p_api_version                => 1.0,
841         p_commit                     => fnd_api.g_false,
842         p_init_msg_list              => fnd_api.g_true,
843         p_validation_level           => fnd_api.g_valid_level_full,
844         p_txn_line_query_rec         => d_txn_line_query_rec,
845         p_txn_line_detail_query_rec  => d_txn_line_detail_query_rec,
846         x_txn_line_detail_tbl        => d_line_dtl_tbl,
847         p_get_parties_flag           => fnd_api.g_true,
848         x_txn_party_detail_tbl       => d_pty_dtl_tbl,
849         p_get_pty_accts_flag         => fnd_api.g_true,
850         x_txn_pty_acct_detail_tbl    => d_pty_acct_tbl,
851         p_get_ii_rltns_flag          => fnd_api.g_true,
852         x_txn_ii_rltns_tbl           => d_ii_rltns_tbl,
853         p_get_org_assgns_flag        => fnd_api.g_true,
854         x_txn_org_assgn_tbl          => d_org_assgn_tbl,
855         p_get_ext_attrib_vals_flag   => fnd_api.g_true,
856         x_txn_ext_attrib_vals_tbl    => d_ext_attrib_tbl,
857         p_get_csi_attribs_flag       => fnd_api.g_false,
858         x_csi_ext_attribs_tbl        => d_csi_ea_tbl,
859         p_get_csi_iea_values_flag    => fnd_api.g_false,
860         x_csi_iea_values_tbl         => d_csi_eav_tbl,
861         p_get_txn_systems_flag       => fnd_api.g_false,
862         x_txn_systems_tbl            => d_txn_systems_tbl,
863         x_return_status              => l_return_status,
864         x_msg_count                  => l_msg_count,
865         x_msg_data                   => l_msg_data);
866 
867       IF l_return_status <> fnd_api.g_ret_sts_success THEN
868         RAISE fnd_api.g_exc_error;
869       END IF;
870 
871       debug('After get_transaction_details :');
872       debug('  line_dtl_tbl.count   :'||d_line_dtl_tbl.count);
873       debug('  pty_dtl_tbl.count    :'||d_pty_dtl_tbl.count);
874       debug('  pty_acct_tbl.count   :'||d_pty_acct_tbl.count);
875       debug('  ext_attrib_tbl.count :'||d_ext_attrib_tbl.count);
876 
877       debug('Dump Txn Details Information .....');
878 
879       csi_t_gen_utility_pvt.dump_txn_tables(
880         p_ids_or_index_based => 'I',
881         p_line_detail_tbl    =>   d_line_dtl_tbl,
882         p_party_detail_tbl   =>   d_pty_dtl_tbl,
883         p_pty_acct_tbl       =>   d_pty_acct_tbl,
884         p_ii_rltns_tbl       =>   d_ii_rltns_tbl,
885         p_org_assgn_tbl      =>   d_org_assgn_tbl,
886         p_ea_vals_tbl        =>   d_ext_attrib_tbl);
887 
888       -- Building Instance rec
889       FOR l_instance_csr IN selected_instance_csr(l_txn_line_id)
890       LOOP
891         n_inst_ind := n_inst_ind + 1;
892         n_instance_tbl(n_inst_ind).instance_id           := l_instance_csr.instance_id;
893         n_instance_tbl(n_inst_ind).object_version_number := l_instance_csr.object_version_number;
894         -- System
895         If nvl(d_line_dtl_tbl(1).csi_system_id,fnd_api.g_miss_num) <> fnd_api.g_miss_num
896         Then
897           n_instance_tbl(n_inst_ind).system_id           := d_line_dtl_tbl(1).csi_system_id;
898         End If;
899         -- Instance Status
900         If nvl(d_line_dtl_tbl(1).instance_status_id,fnd_api.g_miss_num) <> fnd_api.g_miss_num
901         Then
902           n_instance_tbl(n_inst_ind).instance_status_id  := d_line_dtl_tbl(1).instance_status_id;
903         End If;
904         -- External Reference
905         If nvl(d_line_dtl_tbl(1).external_reference,fnd_api.g_miss_char) <> fnd_api.g_miss_char
906         Then
907           n_instance_tbl(n_inst_ind).external_reference  := d_line_dtl_tbl(1).external_reference;
908         End If;
909         -- Version Label
910         If nvl(d_line_dtl_tbl(1).version_label,fnd_api.g_miss_char) <> fnd_api.g_miss_char
911         Then
912           n_instance_tbl(n_inst_ind).version_label       := d_line_dtl_tbl(1).version_label;
913         End If ;
914         -- Transfer Date
915         IF nvl(d_line_dtl_tbl(1).active_start_date,fnd_api.g_miss_date) <> fnd_api.g_miss_date
916         Then
917           n_instance_tbl(n_inst_ind).active_start_date   := d_line_dtl_tbl(1).active_start_date;
918         End If;
919         -- Termination Date
920         IF nvl(d_line_dtl_tbl(1).active_end_date,fnd_api.g_miss_date) <> fnd_api.g_miss_date
921         Then
922           n_instance_tbl(n_inst_ind).active_end_date   := d_line_dtl_tbl(1).active_end_date;
923         End If;
924 
925         IF nvl(d_line_dtl_tbl(1).active_end_date,fnd_api.g_miss_date) <> fnd_api.g_miss_date THEN
926           debug('Setting Termination Date in instance Rec');
927           n_txn_rec.source_transaction_date := d_line_dtl_tbl(1).active_end_date;
928         End If;
929         debug('Termination Date.........................:'||n_txn_rec.source_transaction_date);
930 
931         -- Install Date
932         IF nvl(d_line_dtl_tbl(1).installation_date,fnd_api.g_miss_date) <> fnd_api.g_miss_date
933         Then
934           n_instance_tbl(n_inst_ind).install_date        := d_line_dtl_tbl(1).installation_date;
935         End If;
936 
937         -- Install and Current Location Changes
938         IF l_batch_type in ('XFER','MOVE')
939         Then
940           IF nvl(l_instance_csr.instance_usage_code,fnd_api.g_miss_char) = 'IN_RELATIONSHIP'
941           Then
942              n_instance_tbl(n_inst_ind).location_id                := fnd_api.g_miss_num;
943              n_instance_tbl(n_inst_ind).location_type_code         := fnd_api.g_miss_char;
944              n_instance_tbl(n_inst_ind).install_location_id        := fnd_api.g_miss_num;
945              n_instance_tbl(n_inst_ind).install_location_type_code := fnd_api.g_miss_char;
946           Else
947             IF nvl(d_line_dtl_tbl(1).location_id,fnd_api.g_miss_num) <> fnd_api.g_miss_num
948             Then
949               n_instance_tbl(n_inst_ind).location_id                := d_line_dtl_tbl(1).location_id;
950             End If;
951             IF nvl(d_line_dtl_tbl(1).location_type_code,fnd_api.g_miss_char) <> fnd_api.g_miss_char
952             Then
953               n_instance_tbl(n_inst_ind).location_type_code         := d_line_dtl_tbl(1).location_type_code;
954             End If;
955             IF nvl(d_line_dtl_tbl(1).install_location_id,fnd_api.g_miss_num) <> fnd_api.g_miss_num
956             Then
957               n_instance_tbl(n_inst_ind).install_location_id        := d_line_dtl_tbl(1).install_location_id;
958             End If;
959             IF nvl(d_line_dtl_tbl(1).install_location_type_code,fnd_api.g_miss_char) <> fnd_api.g_miss_char
960             Then
961               n_instance_tbl(n_inst_ind).install_location_type_code := d_line_dtl_tbl(1).install_location_type_code;
962             End If;
963           End If;
964         End If;
965 ----------------------------DKC -------------- for bug 12362188
966 
967                -- Building extended attribs
968         IF d_ext_attrib_tbl.count > 0
969         THEN
970           FOR m in d_ext_attrib_tbl.FIRST .. d_ext_attrib_tbl.LAST
971           LOOP
972             l_ext_attrib_exists := FALSE;   -- Bug 8495187
973             FOR l_core_ieav_val_rec IN core_iea_val_csr(l_txn_line_id)
974             LOOP
975               --IF  l_core_ieav_val_rec.instance_id  = l_core_inst_pty_det.pty_instance_id  THEN      -- bug 7613909
976                 IF  l_core_ieav_val_rec.attribute_id = d_ext_attrib_tbl(m).attribute_source_id      -- bug 7613909
977                 THEN
978                   l_ext_attr_ind := l_ext_attr_ind + 1;
979                   -- Attribute already existing to this Instance
980                   n_ext_attrib_values_tbl(l_ext_attr_ind).parent_tbl_index      := l_parent_tbl_index;
981                   n_ext_attrib_values_tbl(l_ext_attr_ind).attribute_value_id    := l_core_ieav_val_rec.attribute_value_id;
982                   n_ext_attrib_values_tbl(l_ext_attr_ind).attribute_value       := d_ext_attrib_tbl(m).attribute_value;
983                   n_ext_attrib_values_tbl(l_ext_attr_ind).object_version_number := l_core_ieav_val_rec.object_version_number;
984                   l_ext_attrib_exists := TRUE;   -- Bug 8495187
985                /* ELSE                 -- Bug 8495187
986                   l_ext_attr_ind := l_ext_attr_ind + 1;
987                   -- Create new attribute to this Instance
988                   n_ext_attrib_values_tbl(l_ext_attr_ind).parent_tbl_index      := l_parent_tbl_index;
989                   n_ext_attrib_values_tbl(l_ext_attr_ind).instance_id           := l_core_ieav_val_rec.instance_id;
990                   n_ext_attrib_values_tbl(l_ext_attr_ind).attribute_id          := d_ext_attrib_tbl(m).attribute_source_id;
991                   n_ext_attrib_values_tbl(l_ext_attr_ind).attribute_value       := d_ext_attrib_tbl(m).attribute_value; */      -- Bug 8495187
992                 END IF;
993               --END IF;                               -- bug 7613909
994             END LOOP;
995             IF l_ext_attrib_exists = FALSE THEN  -- Bug 8495187  start
996               l_ext_attr_ind := l_ext_attr_ind + 1;
997               -- Create new attribute to this Instance
998               n_ext_attrib_values_tbl(l_ext_attr_ind).parent_tbl_index      := l_parent_tbl_index;
999               n_ext_attrib_values_tbl(l_ext_attr_ind).instance_id           := l_instance_csr.instance_id;
1000               n_ext_attrib_values_tbl(l_ext_attr_ind).attribute_id          := d_ext_attrib_tbl(m).attribute_source_id;
1001               n_ext_attrib_values_tbl(l_ext_attr_ind).attribute_value       := d_ext_attrib_tbl(m).attribute_value;
1002 
1003             END IF;   -- Bug 8495187  end
1004           END LOOP;
1005         END IF;
1006 ----------------------------DKC -------------- for bug 12362188
1007       END LOOP;
1008 
1009       -- Identifying New Owner Account details
1010       IF d_pty_acct_tbl.count > 0
1011       THEN
1012         FOR i in d_pty_acct_tbl.FIRST .. d_pty_acct_tbl.LAST
1013         LOOP
1014           IF d_pty_acct_tbl(i).relationship_type_code = 'OWNER'
1015           THEN
1016             l_pry_account_id := d_pty_acct_tbl(i).ACCOUNT_ID;
1017             l_acct_rel_typ   := d_pty_acct_tbl(i).RELATIONSHIP_TYPE_CODE;
1018             l_acct_bill_to   := d_pty_acct_tbl(i).BILL_TO_ADDRESS_ID;
1019             l_acct_ship_to   := d_pty_acct_tbl(i).SHIP_TO_ADDRESS_ID;
1020           END IF;
1021         END LOOP;
1022       END IF;
1023       l_parent_tbl_index := 0;
1024       l_pty_index        := 0;
1025       l_acct_index       := 0;
1026       l_cont_index       := 0;
1027       l_ext_attr_ind     := 0;      -- bug 7613909
1028       FOR l_core_inst_pty_det IN core_inst_pty_acct_csr(l_txn_line_id)
1029       LOOP
1030         -- debug('l_core_inst_pty_det.instance_id '||l_core_inst_pty_det.pty_instance_id);
1031         -- Party Table
1032        l_parent_tbl_index := l_parent_tbl_index + 1;
1033 
1034        IF d_pty_dtl_tbl.count > 0 THEN
1035 
1036         FOR j in d_pty_dtl_tbl.FIRST .. d_pty_dtl_tbl.LAST
1037         LOOP
1038           -- Building New owner party
1039           IF d_pty_dtl_tbl(j).relationship_type_code = 'OWNER'
1040             AND
1041              nvl(d_pty_dtl_tbl(j).contact_flag,fnd_api.g_miss_char) = 'N'
1042             AND
1043              l_batch_type = 'XFER'
1044           THEN
1045             l_pty_index        := l_pty_index + 1;
1046             n_party_tbl(l_pty_index).parent_tbl_index       := l_parent_tbl_index;
1047             n_party_tbl(l_pty_index).instance_party_id      := l_core_inst_pty_det.pty_instance_party_id;
1048             n_party_tbl(l_pty_index).instance_id            := l_core_inst_pty_det.pty_instance_id;
1049             n_party_tbl(l_pty_index).party_source_table     := d_pty_dtl_tbl(j).PARTY_SOURCE_TABLE;
1050             n_party_tbl(l_pty_index).party_id               := d_pty_dtl_tbl(j).PARTY_SOURCE_ID;
1051             n_party_tbl(l_pty_index).relationship_type_code := d_pty_dtl_tbl(j).RELATIONSHIP_TYPE_CODE;
1052             n_party_tbl(l_pty_index).object_version_number  := l_core_inst_pty_det.pty_obj_version_number;
1053             n_party_tbl(l_pty_index).contact_flag           := 'N';
1054 
1055 
1056             IF nvl(d_pty_dtl_tbl(j).active_start_date,fnd_api.g_miss_date) <> fnd_api.g_miss_date THEN
1057               debug('Setting Party Transfer Date in Transaction Rec');
1058               n_txn_rec.source_transaction_date := d_pty_dtl_tbl(j).active_start_date;
1059             End If;
1060             debug('Transfer Date.........................:'||n_txn_rec.source_transaction_date);
1061 
1062             l_party_detail_id := d_pty_dtl_tbl(j).txn_party_detail_id;
1063             l_pty_tbl_ind     := l_pty_index;
1064 
1065             l_acct_index := l_acct_index + 1;
1066             n_party_account_tbl(l_acct_index).ip_account_id          := l_core_inst_pty_det.pty_acc_ip_account_id;
1067             n_party_account_tbl(l_acct_index).instance_party_id      := l_core_inst_pty_det.pty_acc_instance_party_id;
1068             n_party_account_tbl(l_acct_index).parent_tbl_index       := l_pty_index;
1069             n_party_account_tbl(l_acct_index).party_account_id       := l_pry_account_id;
1070             n_party_account_tbl(l_acct_index).relationship_type_code := l_acct_rel_typ;
1071             n_party_account_tbl(l_acct_index).bill_to_address        := l_acct_bill_to;
1072             n_party_account_tbl(l_acct_index).ship_to_address        := l_acct_ship_to;
1073             n_party_account_tbl(l_acct_index).object_version_number  := l_core_inst_pty_det.pty_acct_obj_version_number;
1074           ELSIF d_pty_dtl_tbl(j).relationship_type_code = 'OWNER'
1075             AND
1076              nvl(d_pty_dtl_tbl(j).contact_flag,fnd_api.g_miss_char) = 'N'
1077             AND
1078              l_batch_type = 'MOVE'
1079           THEN
1080             l_pty_index        := l_pty_index + 1;
1081             n_party_tbl(l_pty_index).parent_tbl_index       := l_parent_tbl_index;
1082             n_party_tbl(l_pty_index).instance_party_id      := l_core_inst_pty_det.pty_instance_party_id;
1083             n_party_tbl(l_pty_index).instance_id            := l_core_inst_pty_det.pty_instance_id;
1084             n_party_tbl(l_pty_index).party_source_table     := l_core_inst_pty_det.pty_party_source_table;
1085             n_party_tbl(l_pty_index).party_id               := l_core_inst_pty_det.pty_party_id;
1086             n_party_tbl(l_pty_index).relationship_type_code := l_core_inst_pty_det.pty_rel_type_code;
1087             n_party_tbl(l_pty_index).object_version_number  := l_core_inst_pty_det.pty_obj_version_number;
1088             n_party_tbl(l_pty_index).contact_flag           := 'N';
1089 
1090             l_party_detail_id := d_pty_dtl_tbl(j).txn_party_detail_id;
1091             l_pty_tbl_ind     := l_pty_index;
1092 
1093             l_acct_index := l_acct_index + 1;
1094             n_party_account_tbl(l_acct_index).ip_account_id          := l_core_inst_pty_det.pty_acc_ip_account_id;
1095             n_party_account_tbl(l_acct_index).instance_party_id      := l_core_inst_pty_det.pty_acc_instance_party_id;
1096             n_party_account_tbl(l_acct_index).parent_tbl_index       := l_pty_index;
1097             n_party_account_tbl(l_acct_index).party_account_id       := l_core_inst_pty_det.pty_acc_party_account_id;
1098             n_party_account_tbl(l_acct_index).relationship_type_code := l_core_inst_pty_det.pty_acct_rel_type_code;
1099             n_party_account_tbl(l_acct_index).bill_to_address        := l_acct_bill_to;
1100             n_party_account_tbl(l_acct_index).ship_to_address        := l_acct_ship_to;
1101             n_party_account_tbl(l_acct_index).object_version_number  := l_core_inst_pty_det.pty_acct_obj_version_number;
1102 
1103             -- Building New Party other than owner
1104           ELSIF d_pty_dtl_tbl(j).relationship_type_code <> 'OWNER'
1105                AND
1106                 nvl(d_pty_dtl_tbl(j).contact_flag,fnd_api.g_miss_char) = 'N'
1107                AND
1108                 d_pty_dtl_tbl(j).active_end_date is null
1109                AND
1110                 l_batch_type in ('XFER','MOVE','GEN')
1111           THEN
1112             l_pty_index        := l_pty_index + 1;
1113             n_party_tbl(l_pty_index).parent_tbl_index       := l_parent_tbl_index;
1114             n_party_tbl(l_pty_index).instance_id            := l_core_inst_pty_det.pty_instance_id;
1115             n_party_tbl(l_pty_index).party_source_table     := d_pty_dtl_tbl(j).PARTY_SOURCE_TABLE;
1116             n_party_tbl(l_pty_index).party_id               := d_pty_dtl_tbl(j).PARTY_SOURCE_ID;
1117             n_party_tbl(l_pty_index).relationship_type_code := d_pty_dtl_tbl(j).RELATIONSHIP_TYPE_CODE;
1118             n_party_tbl(l_pty_index).contact_flag           := 'N';
1119             l_party_detail_id := d_pty_dtl_tbl(j).txn_party_detail_id;
1120             l_pty_tbl_ind     := l_pty_index;
1121             -- Building Association to be expired
1122           ELSIF d_pty_dtl_tbl(j).relationship_type_code <> 'OWNER'
1123                AND
1124                 nvl(d_pty_dtl_tbl(j).contact_flag,fnd_api.g_miss_char) = 'N'
1125                AND
1126                 nvl(d_pty_dtl_tbl(j).active_end_date,fnd_api.g_miss_date) <> fnd_api.g_miss_date
1127                AND
1128                 l_batch_type in ('XFER','MOVE','GEN')
1129           THEN
1130             FOR l_asso_exp_rec IN curr_asso_csr(l_core_inst_pty_det.pty_instance_id)
1131             LOOP
1132               IF l_asso_exp_rec.pty_party_source_table = d_pty_dtl_tbl(j).PARTY_SOURCE_TABLE
1133                 AND
1134                  l_asso_exp_rec.pty_party_id           = d_pty_dtl_tbl(j).PARTY_SOURCE_ID
1135                 AND
1136                  l_asso_exp_rec.pty_rel_type_code      = d_pty_dtl_tbl(j).RELATIONSHIP_TYPE_CODE
1137               THEN
1138                 l_pty_index        := l_pty_index + 1;
1139                 n_party_tbl(l_pty_index).parent_tbl_index       := l_parent_tbl_index;
1140                 n_party_tbl(l_pty_index).instance_party_id      := l_asso_exp_rec.pty_instance_party_id;
1141                 n_party_tbl(l_pty_index).instance_id            := l_core_inst_pty_det.pty_instance_id;
1142                 n_party_tbl(l_pty_index).party_source_table     := d_pty_dtl_tbl(j).PARTY_SOURCE_TABLE;
1143                 n_party_tbl(l_pty_index).party_id               := d_pty_dtl_tbl(j).PARTY_SOURCE_ID;
1144                 n_party_tbl(l_pty_index).relationship_type_code := d_pty_dtl_tbl(j).RELATIONSHIP_TYPE_CODE;
1145                 n_party_tbl(l_pty_index).active_end_date        := d_pty_dtl_tbl(j).ACTIVE_END_DATE;
1146                 n_party_tbl(l_pty_index).object_version_number  := l_asso_exp_rec.pty_obj_version_number;
1147                 n_party_tbl(l_pty_index).contact_flag           := 'N';
1148               END IF;
1149             END LOOP;
1150           END IF;
1151           IF l_party_detail_id is not null
1152           THEN
1153             -- Building Accounts
1154             IF d_pty_acct_tbl.count > 0
1155             THEN
1156               FOR k IN d_pty_acct_tbl.FIRST .. d_pty_acct_tbl.LAST
1157               LOOP
1158                 IF d_pty_acct_tbl(K).TXN_PARTY_DETAIL_ID = l_party_detail_id
1159                 THEN
1160                   IF d_pty_acct_tbl(K).relationship_type_code <> 'OWNER'
1161                   THEN
1162                     l_acct_index := l_acct_index + 1;
1163                     n_party_account_tbl(l_acct_index).parent_tbl_index       := l_pty_tbl_ind;
1164                     n_party_account_tbl(l_acct_index).party_account_id       := d_pty_acct_tbl(K).ACCOUNT_ID;
1165                     n_party_account_tbl(l_acct_index).relationship_type_code := d_pty_acct_tbl(K).RELATIONSHIP_TYPE_CODE;
1166                     n_party_account_tbl(l_acct_index).bill_to_address        := d_pty_acct_tbl(K).BILL_TO_ADDRESS_ID;
1167                     n_party_account_tbl(l_acct_index).ship_to_address        := d_pty_acct_tbl(K).SHIP_TO_ADDRESS_ID;
1168                   END IF;
1169                 END IF;
1170               END LOOP;
1171             END IF;
1172             -- Building Contacts
1173             FOR l in d_pty_dtl_tbl.FIRST .. d_pty_dtl_tbl.LAST
1174             LOOP
1175               IF d_pty_dtl_tbl(l).contact_party_id = l_party_detail_id
1176               THEN
1177                 l_pty_index := l_pty_index + 1;
1178                 n_party_tbl(l_pty_index).parent_tbl_index         := l_parent_tbl_index;
1179                 n_party_tbl(l_pty_index).contact_parent_tbl_index := l_pty_tbl_ind;
1180                 n_party_tbl(l_pty_index).instance_id              := l_core_inst_pty_det.pty_instance_id;
1181                 n_party_tbl(l_pty_index).party_source_table       := d_pty_dtl_tbl(l).PARTY_SOURCE_TABLE;
1182                 n_party_tbl(l_pty_index).party_id                 := d_pty_dtl_tbl(l).PARTY_SOURCE_ID;
1183                 n_party_tbl(l_pty_index).relationship_type_code   := d_pty_dtl_tbl(l).RELATIONSHIP_TYPE_CODE;
1184                 n_party_tbl(l_pty_index).contact_flag             := 'Y';
1185               END IF;
1186             END LOOP;
1187             l_party_detail_id := '';
1188           END IF;
1189         END LOOP; -- Loop end for each record in party_detail table
1190        END IF;
1191       END LOOP; -- Loop end for each instance rec
1192       debug('Details passed to group API : ');
1193       debug('  Instance_tbl      '||n_instance_tbl.count);
1194       debug('  party_tbl         '||n_party_tbl.count);
1195       debug('  party_account_tbl '||n_party_account_tbl.count);
1196       debug('  Extendedattr_tbl  '||n_ext_attrib_values_tbl.count);
1197       IF n_instance_tbl.count > 0
1198       THEN
1199 
1200         csi_t_gen_utility_pvt.dump_csi_instance_tbl(n_instance_tbl);
1201         csi_t_gen_utility_pvt.dump_csi_party_tbl(n_party_tbl);
1202         csi_t_gen_utility_pvt.dump_csi_account_tbl(n_party_account_tbl);
1203         debug('Source Transaction Date in Transaction: '||n_txn_rec.source_transaction_date);
1204         debug('Transaction Date in Transaction: '||n_txn_rec.transaction_date);
1205 
1206         csi_item_instance_grp.update_item_instance (
1207                 p_api_version           => 1.0
1208                ,p_commit                => fnd_api.g_false
1209                ,p_init_msg_list         => fnd_api.g_true
1210                ,p_validation_level      => fnd_api.g_valid_level_full
1211                ,p_instance_tbl          => n_instance_tbl
1212                ,p_ext_attrib_values_tbl => n_ext_attrib_values_tbl
1213                ,p_party_tbl             => n_party_tbl
1214                ,p_account_tbl           => n_party_account_tbl
1215                ,p_pricing_attrib_tbl    => n_price_tbl
1216                ,p_org_assignments_tbl   => n_org_assignments_tbl
1217                ,p_asset_assignment_tbl  => n_asset_assignment_tbl
1218                ,p_txn_rec               => n_txn_rec
1219                ,x_instance_id_lst       => n_instance_id_lst
1220                ,p_grp_upd_error_tbl     => n_grp_error_tbl
1221                ,x_return_status         => l_return_status
1222                ,x_msg_count             => l_msg_count
1223                ,x_msg_data              => l_msg_data);
1224           debug('Group API Return status :'|| l_return_status);
1225          -- IF NOT l_return_status = fnd_api.g_ret_sts_success
1226          -- THEN
1227          --   l_msg_index := 1;
1228          --   l_Error_Message := l_Msg_Data;
1229          --   WHILE l_msg_count > 0
1230          --   LOOP
1231          --      l_Error_Message := FND_MSG_PUB.GET(l_msg_index, FND_API.G_FALSE);
1232          --      l_msg_index := l_msg_index + 1;
1233          --      l_Msg_Count := l_Msg_Count - 1;
1234          --   END LOOP;
1235          --     RAISE fnd_api.g_exc_error;
1236          -- END IF;
1237          -- END IF;
1238 
1239           If n_grp_error_tbl.count > 0
1240           Then
1241             l_return_status := fnd_api.g_ret_sts_error;
1242             errbuf := 'E';
1243         -- Added for bug 5169999
1244           Elsif l_return_status = 'W'
1245           Then
1246 		     errbuf := 'W';
1247              l_errbuf :='W';
1248             l_msg_index := 1;
1249 
1250             l_warning_message := l_msg_data;
1251             WHILE l_msg_count > 0
1252             LOOP
1253                l_warning_message := FND_MSG_PUB.GET(l_msg_index, FND_API.G_FALSE);
1254                debug_out('Warning message '||l_msg_index||' from OKS API is :'||l_warning_message);
1255                l_msg_index := l_msg_index + 1;
1256                l_msg_count := l_msg_count - 1;
1257             END LOOP;
1258           End If;
1259 
1260 
1261           If NOT (l_return_status = fnd_api.g_ret_sts_success) AND
1262                   errbuf <>'W'
1263           Then
1264             -- Buildinig the error table for sorting and reporting
1265             If nvl(n_grp_error_tbl.count,0) > 0
1266             Then
1267               If l_found_error = 'W'
1268               Then
1269                 For i in n_grp_error_tbl.FIRST .. n_grp_error_tbl.LAST
1270                 LOOP
1271                   l_grp_api_ind := l_temp_merror_tbl.count + 1;
1272                   l_temp_merror_tbl(l_grp_api_ind).Entry_Id           := p_entry_id;
1273                   -- l_temp_merror_tbl(l_grp_api_ind).Txn_Line_Detail_Id := n_grp_error_tbl(i).Txn_Line_Detail_Id;
1274                   l_temp_merror_tbl(l_grp_api_ind).Instance_Id        := n_grp_error_tbl(i).Instance_id;
1275                   l_temp_merror_tbl(l_grp_api_ind).Error_Message      := n_grp_error_tbl(i).Error_Message;
1276                   l_temp_merror_tbl(l_grp_api_ind).Error_Code         := 'E';
1277                   l_temp_merror_tbl(l_grp_api_ind).NAME               := l_name;
1278                   l_temp_merror_tbl(l_grp_api_ind).Entity_Name        := n_grp_error_tbl(i).Entity_Name;
1279                 End Loop;
1280               Else
1281                 For i in n_grp_error_tbl.FIRST .. n_grp_error_tbl.LAST
1282                 LOOP
1283                   l_temp_merror_tbl(i).Entry_Id           := p_entry_id;
1284                   -- l_temp_merror_tbl(l_temp_merror_tbl.count + 1).Txn_Line_Detail_Id := n_grp_error_tbl(i).Txn_Line_Detail_Id;
1285                   l_temp_merror_tbl(i).Instance_Id        := n_grp_error_tbl(i).Instance_id;
1286                   l_temp_merror_tbl(i).Error_Message      := n_grp_error_tbl(i).Error_Message;
1287                   l_temp_merror_tbl(i).Error_Code         := 'E';
1288                   l_temp_merror_tbl(i).NAME               := l_name;
1289                   l_temp_merror_tbl(i).Entity_Name        := n_grp_error_tbl(i).Entity_Name;
1290                 End Loop;
1291               End If;
1292             END IF;
1293             -- debug('Call update error status');
1294             update_error_status(l_temp_merror_tbl,l_txn_line_id,p_entry_id);
1295             -- debug('Call error report');
1296             conc_report ( p_temp_merror_tbl => l_temp_merror_tbl,
1297                           p_name            => 'GRPERROR',
1298                           p_batch_id        => p_entry_id,
1299                           p_batch_name      => l_name
1300                          );
1301             debug('Aborting Concurrent Program by raising exception');
1302             RAISE fnd_api.g_exc_error;
1303           Else
1304             -- For each Instance need to Create Notes
1305             IF  n_instance_tbl.count > 0
1306             THEN
1307               IF l_batch_desc IS NOT NULL
1308               THEN
1309                 l_temp_merror_tbl.delete;
1310                 FOR i in n_instance_tbl.FIRST .. n_instance_tbl.LAST
1311                 LOOP
1312                     JTF_NOTES_PUB.CREATE_NOTE
1313                        (
1314                           p_parent_note_id         => NULL,
1315                           p_api_version            => 1,
1316                           p_init_msg_list          => NULL,
1317                           p_commit                 => FND_API.G_FALSE,
1318                           p_validation_level       => fnd_api.g_valid_level_full, --0,
1319                           x_return_status          => l_return_status,
1320                           x_msg_count              => l_msg_count,
1321                           x_msg_data               => l_msg_data,
1322                           x_jtf_note_id            => l_note_id,
1323                           p_org_id                 => NULL,
1324                           p_source_object_id       => n_instance_tbl(i).instance_id,
1325                           p_source_object_code     => 'CP',
1326                           p_notes                  => l_batch_desc,
1327                           --  p_notes_detail           => COMMENTS,
1328                           p_note_status            => 'I',
1329                           p_entered_by             => FND_GLOBAL.USER_ID,
1330                           p_entered_date           => SYSDATE,
1331                           p_last_update_date       => SYSDATE,
1332                           p_last_updated_by        => FND_GLOBAL.USER_ID,
1333                           p_creation_date          => SYSDATE,
1334                           p_created_by             => FND_GLOBAL.USER_ID
1335                        );
1336 
1337                     debug('JTF API Return status :'||l_return_status);
1338                     IF NOT(l_return_status = FND_API.G_RET_STS_SUCCESS)
1339                     Then
1340                       If l_jtf_error = 'N'
1341                       Then
1342                         l_jtf_error := 'Y';
1343                         errbuf := 'E';
1344                       End If;
1345 
1346                       l_msg_index := 1;
1347                       l_Error_Message := l_Msg_Data;
1348                       WHILE l_msg_count > 0
1349                       LOOP
1350                         l_Error_Message := FND_MSG_PUB.GET(l_msg_index, FND_API.G_FALSE);
1351                         l_msg_index := l_msg_index + 1;
1352                         l_Msg_Count := l_Msg_Count - 1;
1353                       END LOOP;
1354 
1355                       l_jtf_err_ind := l_temp_merror_tbl.count + 1;
1356                       l_temp_merror_tbl(l_jtf_err_ind).Entry_Id           := p_entry_id;
1357                       -- l_temp_merror_tbl(l_jtf_err_ind).Txn_Line_Detail_Id := n_grp_error_tbl(i).Txn_Line_Detail_Id;
1358                       l_temp_merror_tbl(l_jtf_err_ind).Instance_Id        := n_grp_error_tbl(i).Instance_id;
1359                       l_temp_merror_tbl(l_jtf_err_ind).Error_Message      := l_Error_Message;
1360                       l_temp_merror_tbl(l_jtf_err_ind).Error_Code         := 'E';
1361                       l_temp_merror_tbl(l_jtf_err_ind).NAME               := l_name;
1362                       l_temp_merror_tbl(l_jtf_err_ind).Entity_Name        := 'JTFNOTES';
1363                     END IF;
1364                 END LOOP;
1365               END IF;
1366               If l_jtf_error <> 'Y'
1367               Then
1368                 Debug('Notes created for instance successfully');
1369                 Debug_out('Notes created for instance successfully');
1370                 Debug('Checking for system mass update');
1371                 Debug_out('Checking for system mass update');
1372                 -- Bug 7483403
1373                 IF NVL(l_system_cascade, FND_API.G_MISS_CHAR) = FND_API.G_MISS_CHAR THEN
1374                   l_system_cascade := 'N';
1375                 END IF;  -- NVL(l_system_cascade, FND_API.G_MISS_CHAR) = FND_API.G_MISS_CHAR
1376                 IF l_system_cascade = 'N' THEN
1377                   -- The system cascade is not set
1378                   -- Update the mass update status and exit
1379                    -- Updating the status of transaction line for the batch
1380                     UPDATE csi_t_transaction_lines
1381                     SET    processing_status   = 'PROCESSED'
1382                     WHERE  transaction_line_id = l_txn_line_id;
1383 
1384                     -- Update the status of all the transaction line details for the batch
1385                     UPDATE csi_t_txn_line_details
1386                     SET    error_explanation   = '',
1387                            processing_status   = 'PROCESSED',
1388                            error_code          = 'P'
1389                     WHERE  transaction_line_id = l_txn_line_id
1390                     AND    instance_id is not null;
1391 
1392                     -- Updating batch status
1393                     UPDATE csi_mass_edit_entries_b
1394                     SET    status_code = 'SUCCESSFUL'
1395                     WHERE  entry_id    = p_entry_id;
1396 
1397                    IF l_errbuf='W'
1398                    THEN
1399                     Debug(' ');
1400                     Debug(' **** Mass Edit Batch ('||l_name||') Status : WARNING');
1401                     Debug(' ');
1402 
1403                     Debug_out(' ');
1404                     Debug_out('Mass Edit Batch ('||l_name||') Status : WARNING');
1405                     Debug_out(' ');
1406                     Debug_out('---------------------------------------------------');
1407                    ELSE
1408                     Debug(' ');
1409                     Debug(' **** Mass Edit Batch ('||l_name||') Status : SUCCESSFUL');
1410                     Debug(' ');
1411 
1412                     Debug_out(' ');
1413                     Debug_out('Mass Edit Batch ('||l_name||') Status : SUCCESSFUL');
1414                     Debug_out(' ');
1415                     Debug_out('---------------------------------------------------');
1416                    END IF;
1417                 END IF;  -- l_system_cascade = 'N'
1418                 -- End Bug 7483403
1419 
1420               Else
1421                 -- debug('Call update error status');
1422                 update_error_status(l_temp_merror_tbl,l_txn_line_id,p_entry_id);
1423 
1424                 -- debug('Call error report');
1425                 conc_report ( p_temp_merror_tbl => l_temp_merror_tbl,
1426                               p_name            => 'JTFERROR',
1427                               p_batch_id        => p_entry_id,
1428                               p_batch_name      => l_name
1429                              );
1430                 debug('Aborting Concurrent Program by raising exception');
1431                 RAISE fnd_api.g_exc_error;
1432               End If;
1433             END IF; -- End If for Notes API
1434           END IF; -- End If for Failure/success
1435       END IF; -- End If for Grp APi
1436 
1437       -- Added for the ER 6031179
1438       -- Checking to see if there are instances which needs to be updated
1439       -- This block will update systems for transfer owner batch
1440       -- The system will be updated if all the active item instances
1441       -- which are part of the system is included in the transfer owner batch
1442 
1443       IF NVL(l_system_cascade, FND_API.G_MISS_CHAR) = FND_API.G_MISS_CHAR THEN
1444         l_system_cascade := 'N';
1445       END IF;
1446 
1447       debug('System Cascade : ' || l_system_cascade);
1448       Debug_out('System Cascade :' || l_system_cascade);
1449 
1450       BEGIN
1451         SELECT 'x' INTO l_new_owner
1452         FROM CSI_T_PARTY_DETAILS WHERE TXN_LINE_DETAIL_ID IN(
1453           SELECT TXN_LINE_DETAIL_ID FROM CSI_T_TXN_LINE_DETAILS CTLD, CSI_MASS_EDIT_ENTRIES_VL CMEE
1454           WHERE CTLD.TRANSACTION_LINE_ID =  CMEE.TXN_LINE_ID
1455               AND CMEE.ENTRY_ID = p_entry_id
1456               AND INSTANCE_ID IS NULL)
1457         AND PARTY_SOURCE_TABLE = 'HZ_PARTIES'
1458         AND RELATIONSHIP_TYPE_CODE = 'OWNER'
1459         AND ROWNUM = 1;
1460 
1461         SELECT 'x' INTO l_old_owner
1462         FROM CSI_T_PARTY_DETAILS WHERE TXN_LINE_DETAIL_ID IN(
1463             SELECT TXN_LINE_DETAIL_ID FROM CSI_T_TXN_LINE_DETAILS CTLD, CSI_MASS_EDIT_ENTRIES_VL CMEE
1464             WHERE CTLD.TRANSACTION_LINE_ID =  CMEE.TXN_LINE_ID
1465               AND CMEE.ENTRY_ID = p_entry_id
1466               AND INSTANCE_ID IS NOT NULL)
1467           AND PARTY_SOURCE_TABLE = 'HZ_PARTIES'
1468           AND RELATIONSHIP_TYPE_CODE = 'OWNER'
1469           AND ROWNUM = 1;
1470 
1471       debug('l_old_owner type - ' || l_old_owner);
1472       debug('l_new_owner type - ' || l_new_owner);
1473 
1474        IF  l_old_owner IS NOT NULL AND l_new_owner IS NOT NULL THEN
1475         l_perform_system_mu := 'Y';
1476        END IF;
1477 
1478       EXCEPTION
1479         WHEN OTHERS THEN
1480         debug('The Batch doesn not qualify for system mass update
1481               as the owner type is not HZ_PARTIES');
1482          l_perform_system_mu := 'N';
1483       END;
1484 
1485       -- The processing of systems must proceed only if the owner type is HZ_PARTIES
1486       IF l_batch_type in ('XFER') AND l_system_cascade = 'Y' AND l_perform_system_mu = 'Y' THEN
1487         IF n_instance_tbl.count > 0 THEN
1488 
1489         -- Call the PROCESS_SYSTEM_MASS_UPDATE to
1490         -- 1. Identify the systems which are part of the mass update transfer owner batch
1491         -- 2. After identifying the systems, update them
1492 
1493         PROCESS_SYSTEM_MASS_UPDATE (
1494                 p_api_version           => 1.0
1495                ,p_commit                => fnd_api.g_false
1496                ,p_Entry_id              => p_Entry_id
1497                ,p_instance_tbl          => n_instance_tbl
1498                ,p_ext_attrib_values_tbl => n_ext_attrib_values_tbl   -- Not used, retained for future enhancements
1499                ,p_party_tbl             => n_party_tbl
1500                ,p_account_tbl           => n_party_account_tbl
1501                ,p_txn_rec               => n_txn_rec
1502                ,x_return_status         => l_return_status
1503                ,x_msg_count             => l_msg_count
1504                ,x_msg_data              => l_msg_data);
1505 
1506               IF NOT l_return_status = fnd_api.g_ret_sts_success
1507               THEN
1508               l_msg_index := 1;
1509               l_Error_Message := l_Msg_Data;
1510               WHILE l_msg_count > 0
1511               LOOP
1512                 l_Error_Message := FND_MSG_PUB.GET(l_msg_index, FND_API.G_FALSE);
1513                 --debug_out('  ');
1514                 l_msg_index := l_msg_index + 1;
1515                 l_Msg_Count := l_Msg_Count - 1;
1516               END LOOP;
1517                -- RAISE fnd_api.g_exc_error;
1518               END IF;
1519        --  END IF;
1520 
1521         IF l_return_status = fnd_api.g_ret_sts_success THEN
1522           -- Updating the status of transaction line for the batch
1523           UPDATE csi_t_transaction_lines
1524           SET    processing_status   = 'PROCESSED'
1525           WHERE  transaction_line_id = l_txn_line_id;
1526 
1527           -- Update the status of all the transaction line details for the batch
1528           UPDATE csi_t_txn_line_details
1529           SET    error_explanation   = '',
1530                  processing_status   = 'PROCESSED',
1531                  error_code          = 'P'
1532           WHERE  transaction_line_id = l_txn_line_id
1533           AND    instance_id is not null;
1534 
1535           -- Updating batch status
1536           UPDATE csi_mass_edit_entries_b
1537           SET    status_code = 'SUCCESSFUL'
1538           WHERE  entry_id    = p_entry_id;
1539 
1540          IF l_errbuf='W'
1541          THEN
1542           Debug(' ');
1543           Debug(' **** Mass Edit Batch ('||l_name||') Status : WARNING');
1544           Debug(' ');
1545 
1546           Debug_out(' ');
1547           Debug_out('Mass Edit Batch ('||l_name||') Status : WARNING');
1548           Debug_out(' ');
1549           Debug_out('---------------------------------------------------');
1550          ELSE
1551           Debug(' ');
1552           Debug(' **** Mass Edit Batch ('||l_name||') Status : SUCCESSFUL');
1553           Debug(' ');
1554 
1555           Debug_out(' ');
1556           Debug_out('Mass Edit Batch ('||l_name||') Status : SUCCESSFUL');
1557           Debug_out(' ');
1558           Debug_out('---------------------------------------------------');
1559          END IF; -- l_errbuf='W'
1560        ELSE
1561          -- debug('Call update error status');
1562                 update_error_status(l_temp_merror_tbl,l_txn_line_id,p_entry_id);
1563 
1564           -- debug('Call error report');
1565           conc_report ( p_temp_merror_tbl => l_temp_merror_tbl,
1566                         p_name            => 'JTFERROR',
1567                         p_batch_id        => p_entry_id,
1568                         p_batch_name      => l_name
1569                        );
1570 
1571           UPDATE_MUSYS_ERR_STATUS(p_entry_id);
1572 
1573           debug('Aborting Concurrent Program by raising exception');
1574           RAISE fnd_api.g_exc_error;
1575         END IF;  -- l_return_status = fnd_api.g_ret_sts_success
1576 
1577 
1578         END IF; -- n_instance_tbl.count Loop
1579       END IF; -- l_batch_type in ('XFER')
1580       -- End of Addition for the ER 6031179
1581 
1582     END IF; -- Common Validations
1583   END;
1584   END IF; -- Batch Not Found
1585 
1586   Commit;
1587 
1588 EXCEPTION
1589    WHEN fnd_api.g_exc_error THEN
1590        ROLLBACK TO START_PROCESSING;
1591        debug( 'Program Errored : ');
1592        -- l_conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR','');
1593        errbuf := 'E';
1594    WHEN fnd_api.g_exc_unexpected_error THEN
1595        ROLLBACK TO START_PROCESSING;
1596        debug( 'Program Errored : ');
1597        -- l_conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR','');
1598        errbuf := 'E';
1599    WHEN OTHERS THEN
1600        ROLLBACK TO START_PROCESSING;
1601        debug( 'When others exception from Process_mass_edit_batch');
1602        debug( to_char(SQLCODE)||substr(SQLERRM, 1, 255));
1603        -- l_conc_status := FND_CONCURRENT.SET_COMPLETION_STATUS('ERROR','');
1604        errbuf := 'E';
1605 END Process_mass_edit_batch;
1606 
1607 PROCEDURE CREATE_MASS_EDIT_BATCH
1608    (
1609     p_api_version          		IN   NUMBER,
1610     p_commit                	IN   VARCHAR2 := fnd_api.g_false,
1611     p_init_msg_list         	IN   VARCHAR2 := fnd_api.g_false,
1612     p_validation_level      	IN   NUMBER   := fnd_api.g_valid_level_full,
1613     px_mass_edit_rec          	IN OUT NOCOPY csi_mass_edit_pub.mass_edit_rec,
1614     px_txn_line_rec             IN OUT NOCOPY csi_t_datastructures_grp.txn_line_rec ,
1615     px_mass_edit_inst_tbl       IN OUT NOCOPY csi_mass_edit_pub.mass_edit_inst_tbl,
1616     px_txn_line_detail_rec      IN OUT NOCOPY csi_t_datastructures_grp.txn_line_detail_rec,
1617     px_txn_party_detail_tbl     IN OUT NOCOPY csi_t_datastructures_grp.txn_party_detail_tbl,
1618     px_txn_pty_acct_detail_tbl  IN OUT NOCOPY csi_t_datastructures_grp.txn_pty_acct_detail_tbl,
1619     px_txn_ext_attrib_vals_tbl  IN OUT NOCOPY csi_t_datastructures_grp.txn_ext_attrib_vals_tbl,
1620     x_mass_edit_error_tbl       OUT NOCOPY    mass_edit_error_tbl,
1621     x_return_status          	OUT NOCOPY    VARCHAR2,
1622     x_msg_count              	OUT NOCOPY    NUMBER,
1623     x_msg_data	                OUT NOCOPY    VARCHAR2
1624 
1625   ) IS
1626   l_api_version NUMBER := 1.0;
1627   l_api_name VARCHAR2(30) := 'CREATE_MASS_EDIT_BATCH_PUB';
1628 
1629   l_debug_level                  NUMBER;
1630 
1631   l_return_status                VARCHAR2(1)   := FND_API.G_ret_sts_success;
1632   l_msg_count                    NUMBER;
1633   l_msg_data                     VARCHAR2(512);
1634 
1635 
1636   Begin
1637     -- Standard Start of API savepoint
1638     SAVEPOINT create_mass_edit_pub;
1639 
1640     csi_t_gen_utility_pvt.add('API Being Executed     : CREATE_MASS_EDIT_BATCH_PUB');
1641     csi_t_gen_utility_pvt.add('Transaction Start Time :'||to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
1642 
1643     -- Initialize message list if p_init_msg_list is set to TRUE.
1644     IF FND_API.To_Boolean( p_init_msg_list ) THEN
1645       FND_MSG_PUB.Initialize;
1646     END IF;
1647 
1648     --  Initialize API return status to success
1649     x_return_status := FND_API.G_RET_STS_SUCCESS;
1650 
1651     -- Standard call to check for call compatibility.
1652     IF NOT
1653 
1654        FND_API.Compatible_API_Call (
1655          p_current_version_number => l_api_version,
1656          p_caller_version_number  => p_api_version,
1657          p_api_name               => l_api_name,
1658          p_pkg_name               => g_pkg_name) THEN
1659 
1660       RAISE FND_API.G_Exc_Unexpected_Error;
1661 
1662     END IF;
1663     -- main code starts here
1664     --
1665     -- This procedure check if the installed base is active, If not active
1666     -- populates the error message in the message queue and raises the
1667     -- fnd_api.g_exc_error exception
1668     --
1669 
1670     csi_utility_grp.check_ib_active;
1671 
1672     debug('px_txn_line_detail_tbl.count: '||px_mass_edit_inst_tbl.count);
1673 
1674     csi_mass_edit_pvt.create_mass_edit_batch
1675            (
1676             p_api_version              => l_api_version,
1677             p_commit                   => p_commit,
1678             p_init_msg_list            => p_init_msg_list,
1679             p_validation_level         => p_validation_level,
1680             px_mass_edit_rec           => px_mass_edit_rec,
1681             px_txn_line_rec            => px_txn_line_rec,
1682             px_mass_edit_inst_tbl      => px_mass_edit_inst_tbl,
1683             px_txn_line_detail_rec     => px_txn_line_detail_rec,
1684             px_txn_party_detail_tbl    => px_txn_party_detail_tbl,
1685             px_txn_pty_acct_detail_tbl => px_txn_pty_acct_detail_tbl,
1686             px_txn_ext_attrib_vals_tbl => px_txn_ext_attrib_vals_tbl,
1687             x_mass_edit_error_tbl      => x_mass_edit_error_tbl,
1688             x_return_status            => x_return_status,
1689             x_msg_count                => x_msg_count,
1690             x_msg_data                 => x_msg_data
1691             );
1692 
1693 
1694     IF x_return_status <> fnd_api.g_ret_sts_success THEN
1695       RAISE fnd_api.g_exc_error;
1696     END IF;
1697 
1698       -- Standard check of p_commit.
1699       IF FND_API.To_Boolean( p_commit ) THEN
1700            COMMIT WORK;
1701       END IF;
1702 
1703       -- Standard call to get message count and IF count is  get message info.
1704       FND_MSG_PUB.Count_And_Get
1705            (p_count  =>  x_msg_count,
1706             p_data   =>  x_msg_data
1707            );
1708 
1709     csi_t_gen_utility_pvt.add('Transaction End Time :'||to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
1710 EXCEPTION
1711     WHEN FND_API.G_EXC_ERROR THEN
1712           ROLLBACK TO create_mass_edit_pub;
1713             x_return_status := FND_API.G_RET_STS_ERROR ;
1714             FND_MSG_PUB.Count_And_Get
1715                 (p_count  =>  x_msg_count,
1716                  p_data   =>  x_msg_data
1717                 );
1718     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1719           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1720           ROLLBACK TO create_mass_edit_pub;
1721           FND_MSG_PUB.Count_And_Get
1722                 ( p_count  =>  x_msg_count,
1723                   p_data   =>  x_msg_data
1724                 );
1725     WHEN OTHERS THEN
1726           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1727           ROLLBACK TO create_mass_edit_pub;
1728               IF   FND_MSG_PUB.Check_Msg_Level
1729                   (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1730               THEN
1731                     FND_MSG_PUB.Add_Exc_Msg
1732                   (G_PKG_NAME ,
1733                    l_api_name
1734                   );
1735               END IF;
1736               FND_MSG_PUB.Count_And_Get
1737                   (p_count  =>  x_msg_count,
1738                    p_data   =>  x_msg_data
1739                   );
1740 
1741   End CREATE_MASS_EDIT_BATCH;
1742 
1743 Procedure validate_dup_batch_instances
1744 (
1745 	 p_txn_line_id      IN  NUMBER,
1746 	 px_mass_edit_inst_tbl       IN mass_edit_inst_tbl,
1747      x_output	in out nocopy varchar2
1748 )
1749 IS
1750 CURSOR selected_instance_csr (p_txn_line_id IN NUMBER) IS
1751        select   cii.instance_id,
1752 		cii.instance_number
1753        from     csi_instance_search_v cii,
1754 		csi_t_txn_line_details tld
1755        where    tld.transaction_line_id = p_txn_line_id and
1756 		tld.instance_id is not null and
1757 		tld.instance_id = cii.instance_id and
1758 		nvl(tld.active_end_date(+),sysdate+1) > sysdate;
1759 BEGIN
1760 	FOR l_instance_csr IN selected_instance_csr(p_txn_line_id)
1761     LOOP
1762 		if px_mass_edit_inst_tbl.count > 0 then
1763 			for i in px_mass_edit_inst_tbl.first..px_mass_edit_inst_tbl.last
1764 			loop
1765 				IF l_instance_csr.instance_id = px_mass_edit_inst_tbl(i).instance_id THEN
1766 					IF x_output IS NOT NULL THEN
1767 						x_output := x_output || ',' ;
1768 					END IF;
1769 					x_output := x_output || l_instance_csr.instance_number;
1770 				END IF;
1771 			end loop;
1772 		end if;
1773 	END LOOP;
1774 END;
1775 
1776 PROCEDURE UPDATE_MASS_EDIT_BATCH (
1777     p_api_version               IN     NUMBER,
1778     p_commit                    IN     VARCHAR2 := fnd_api.g_false,
1779     p_init_msg_list             IN     VARCHAR2 := fnd_api.g_false,
1780     p_validation_level          IN     NUMBER   := fnd_api.g_valid_level_full,
1781     px_mass_edit_rec            IN OUT NOCOPY csi_mass_edit_pub.mass_edit_rec,
1782     px_txn_line_rec             IN OUT NOCOPY csi_t_datastructures_grp.txn_line_rec ,
1783     px_mass_edit_inst_tbl       IN OUT NOCOPY mass_edit_inst_tbl,
1784     px_txn_line_detail_rec      IN OUT NOCOPY csi_t_datastructures_grp.txn_line_detail_rec,
1785     px_txn_party_detail_tbl     IN OUT NOCOPY csi_t_datastructures_grp.txn_party_detail_tbl,
1786     px_txn_pty_acct_detail_tbl  IN OUT NOCOPY csi_t_datastructures_grp.txn_pty_acct_detail_tbl,
1787     px_txn_ext_attrib_vals_tbl  IN OUT NOCOPY csi_t_datastructures_grp.txn_ext_attrib_vals_tbl,
1788     x_mass_edit_error_tbl       OUT NOCOPY    mass_edit_error_tbl,
1789     x_return_status             OUT NOCOPY    VARCHAR2,
1790     x_msg_count                 OUT NOCOPY    NUMBER,
1791     x_msg_data                  OUT NOCOPY    VARCHAR2) IS
1792 
1793 
1794     l_api_version             NUMBER          := 1.0;
1795     l_api_name                VARCHAR2(30) := 'UPDATE_MASS_EDIT_BATCH_PUB';
1796     l_msg_count               NUMBER;
1797     l_msg_data                VARCHAR2(200);
1798     l_return_status           VARCHAR2(1);
1799     x_output varchar2(4000);
1800 BEGIN
1801 
1802     -- Standard Start of API savepoint
1803     SAVEPOINT update_mass_edit_pub;
1804 
1805     csi_t_gen_utility_pvt.add('API Being Executed     : UPDATE_MASS_EDIT_BATCH_PUB');
1806     csi_t_gen_utility_pvt.add('Transaction Start Time :'||to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
1807 
1808     -- Initialize message list if p_init_msg_list is set to TRUE.
1809     IF FND_API.To_Boolean( p_init_msg_list ) THEN
1810       FND_MSG_PUB.Initialize;
1811     END IF;
1812 
1813     --  Initialize API return status to success
1814     x_return_status := FND_API.G_RET_STS_SUCCESS;
1815 
1816     -- Standard call to check for call compatibility.
1817     IF NOT
1818 
1819        FND_API.Compatible_API_Call (
1820          p_current_version_number => l_api_version,
1821          p_caller_version_number  => p_api_version,
1822          p_api_name               => l_api_name,
1823          p_pkg_name               => g_pkg_name) THEN
1824 
1825       RAISE FND_API.G_Exc_Unexpected_Error;
1826 
1827     END IF;
1828     -- main code starts here
1829 
1830     validate_dup_batch_instances(
1831             px_txn_line_rec.TRANSACTION_LINE_ID,
1832             px_mass_edit_inst_tbl,
1833             x_output);
1834 
1835     IF x_output IS NOT NULL THEN
1836 	FND_MESSAGE.set_name('CSI','CSI_MU_DUP_BATCH_INSTANCES');
1837     	FND_MESSAGE.set_token('INST_NUM',x_output);
1838         FND_MSG_PUB.add;
1839 	RAISE FND_API.g_exc_error;
1840     END IF;
1841 
1842 -- call API to run
1843      csi_t_gen_utility_pvt.add('px_txn_line_detail_tbl.count: '||px_mass_edit_inst_tbl.count);
1844 
1845 
1846     csi_mass_edit_pvt.update_mass_edit_batch
1847                      (
1848                       p_api_version              => l_api_version,
1849                       p_commit                   => p_commit,
1850                       p_init_msg_list            => p_init_msg_list,
1851                       p_validation_level         => p_validation_level,
1852                       px_mass_edit_rec           => px_mass_edit_rec,
1853                       px_txn_line_rec            => px_txn_line_rec,
1854                       px_mass_edit_inst_tbl      => px_mass_edit_inst_tbl,
1855                       px_txn_line_detail_rec     => px_txn_line_detail_rec,
1856                       px_txn_party_detail_tbl    => px_txn_party_detail_tbl,
1857                       px_txn_pty_acct_detail_tbl => px_txn_pty_acct_detail_tbl,
1858                       px_txn_ext_attrib_vals_tbl => px_txn_ext_attrib_vals_tbl,
1859                       x_mass_edit_error_tbl      => x_mass_edit_error_tbl,
1860                       x_return_status            => l_return_status,
1861                       x_msg_count                => l_msg_count,
1862                       x_msg_data                 => l_msg_data
1863                       );
1864 
1865 
1866     IF l_return_status <> fnd_api.g_ret_sts_success THEN
1867       RAISE fnd_api.g_exc_error;
1868     END IF;
1869 
1870     -- Standard check of p_commit.
1871     IF FND_API.To_Boolean( p_commit ) THEN
1872          COMMIT WORK;
1873     END IF;
1874 
1875     csi_t_gen_utility_pvt.add('Transaction End Time :'||to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
1876 EXCEPTION
1877     WHEN FND_API.G_EXC_ERROR THEN
1878           ROLLBACK TO update_mass_edit_pub;
1879             x_return_status := FND_API.G_RET_STS_ERROR ;
1880             FND_MSG_PUB.Count_And_Get
1881                 (p_count  =>  x_msg_count,
1882                  p_data   =>  x_msg_data
1883                 );
1884     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1885           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1886           ROLLBACK TO update_mass_edit_pub;
1887           FND_MSG_PUB.Count_And_Get
1888                 ( p_count  =>  x_msg_count,
1889                   p_data   =>  x_msg_data
1890                 );
1891     WHEN OTHERS THEN
1892           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1893           ROLLBACK TO update_mass_edit_pub;
1894               IF   FND_MSG_PUB.Check_Msg_Level
1895                   (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
1896               THEN
1897                     FND_MSG_PUB.Add_Exc_Msg
1898                   (G_PKG_NAME ,
1899                    l_api_name
1900                   );
1901               END IF;
1902               FND_MSG_PUB.Count_And_Get
1903                   (p_count  =>  x_msg_count,
1904                    p_data   =>  x_msg_data
1905                   );
1906 
1907 END update_mass_edit_batch;
1908 
1909 PROCEDURE DELETE_MASS_EDIT_BATCH
1910    (
1911     p_api_version               IN  NUMBER,
1912     p_commit                	IN  VARCHAR2 := fnd_api.g_false,
1913     p_init_msg_list         	IN  VARCHAR2 := fnd_api.g_false,
1914     p_validation_level      	IN  NUMBER   := fnd_api.g_valid_level_full,
1915     p_mass_edit_rec          	IN  mass_edit_rec,
1916     x_return_status          	OUT NOCOPY    VARCHAR2,
1917     x_msg_count              	OUT NOCOPY    NUMBER,
1918     x_msg_data	                OUT NOCOPY    VARCHAR2
1919 
1920   ) IS
1921 
1922     l_api_version             NUMBER          := 1.0;
1923     l_api_name                VARCHAR2(30)    := 'DELETE_MASS_EDIT_BATCH';
1924     l_msg_count               NUMBER;
1925     l_msg_data                VARCHAR2(2000);
1926     l_return_status           VARCHAR2(1);
1927 
1928 BEGIN
1929 
1930     -- Standard Start of API savepoint
1931     SAVEPOINT delete_mass_edit_batch;
1932 
1933     csi_t_gen_utility_pvt.add('API Being Executed     : DELETE_MASS_EDIT_BATCH');
1934     csi_t_gen_utility_pvt.add('Transaction Start Time :'||to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
1935 
1936     -- Initialize message list if p_init_msg_list is set to TRUE.
1937     IF FND_API.To_Boolean( p_init_msg_list ) THEN
1938       FND_MSG_PUB.Initialize;
1939     END IF;
1940 
1941     --  Initialize API return status to success
1942     x_return_status := FND_API.G_RET_STS_SUCCESS;
1943 
1944     -- Standard call to check for call compatibility.
1945     IF NOT
1946        FND_API.Compatible_API_Call (
1947          p_current_version_number => l_api_version,
1948          p_caller_version_number  => p_api_version,
1949          p_api_name               => l_api_name,
1950          p_pkg_name               => g_pkg_name) THEN
1951 
1952       RAISE FND_API.G_Exc_Unexpected_Error;
1953     END IF;
1954     -- This procedure check if the installed base is active, If not active
1955     -- populates the error message in the message queue and raises the
1956     -- fnd_api.g_exc_error exception
1957     --
1958      csi_utility_grp.check_ib_active;
1959 
1960      -- check required params
1961      -- either the batch id OR the batch name is required for a delete
1962   IF ( nvl(p_mass_edit_rec.entry_id, fnd_api.g_miss_num) = fnd_api.g_miss_num
1963      AND nvl(p_mass_edit_rec.name, fnd_api.g_miss_char) = fnd_api.g_miss_char ) THEN
1964 
1965       FND_MESSAGE.set_name('CSI','CSI_API_REQD_PARAM_MISSING');
1966       FND_MESSAGE.set_token('API_NAME',l_api_name);
1967       FND_MESSAGE.set_token('MISSING_PARAM','Batch ID OR Batch Name');
1968       FND_MSG_PUB.add;
1969       RAISE FND_API.g_exc_error;
1970   END IF;
1971 
1972   csi_mass_edit_pvt.delete_mass_edit_batch (
1973          p_api_version      => p_api_version,
1974          p_commit           => p_commit,
1975          p_init_msg_list    => p_init_msg_list,
1976          p_validation_level => p_validation_level,
1977          p_mass_edit_rec    => p_mass_edit_rec,
1978          x_return_status    => l_return_status,
1979          x_msg_count        => l_msg_count,
1980          x_msg_data         => l_msg_data
1981         );
1982 
1983     IF l_return_status <> fnd_api.g_ret_sts_success THEN
1984       RAISE fnd_api.g_exc_error;
1985     END IF;
1986 
1987     -- Standard check of p_commit.
1988     IF FND_API.To_Boolean( p_commit ) THEN
1989          COMMIT WORK;
1990     END IF;
1991 
1992     -- Standard call to get message count and IF count is  get message info.
1993     FND_MSG_PUB.Count_And_Get
1994          (p_count  =>  x_msg_count,
1995           p_data   =>  x_msg_data
1996          );
1997 
1998     csi_t_gen_utility_pvt.add('API Executed         : Delete Mass Edit Batch');
1999     csi_t_gen_utility_pvt.add('Transaction End Time :'||to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
2000 
2001     csi_t_gen_utility_pvt.set_debug_off;
2002 
2003   EXCEPTION
2004     WHEN FND_API.G_EXC_ERROR THEN
2005 
2006       ROLLBACK TO Delete_Mass_Edit_Batch;
2007       x_return_status := FND_API.G_RET_STS_ERROR ;
2008       FND_MSG_PUB.Count_And_Get (
2009         p_count  => x_msg_count,
2010         p_data   => x_msg_data);
2011 
2012       csi_t_gen_utility_pvt.set_debug_off;
2013 
2014     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2015 
2016       ROLLBACK TO Delete_Mass_Edit_Batch;
2017       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2018 
2019       FND_MSG_PUB.Count_And_Get(
2020         p_count  => x_msg_count,
2021         p_data   => x_msg_data);
2022 
2023       csi_t_gen_utility_pvt.set_debug_off;
2024 
2025     WHEN OTHERS THEN
2026 
2027       ROLLBACK TO Delete_Mass_Edit_Batch;
2028       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2029 
2030       IF FND_MSG_PUB.Check_Msg_Level(
2031            p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
2032 
2033         FND_MSG_PUB.Add_Exc_Msg(
2034           p_pkg_name       => G_PKG_NAME,
2035           p_procedure_name => l_api_name);
2036 
2037       END IF;
2038 
2039       FND_MSG_PUB.Count_And_Get(
2040         p_count  => x_msg_count,
2041         p_data   => x_msg_data);
2042 
2043       csi_t_gen_utility_pvt.set_debug_off;
2044 
2045   END Delete_Mass_Edit_Batch;
2046 
2047 /* This is the wrapper API to handle multiple batch deletes. Calls the DELETE_MASS_EDIT_BATCH */
2048 
2049 PROCEDURE DELETE_MASS_EDIT_BATCHES
2050    (
2051     p_api_version               IN  NUMBER,
2052     p_commit                	IN  VARCHAR2 := fnd_api.g_false,
2053     p_init_msg_list         	IN  VARCHAR2 := fnd_api.g_false,
2054     p_validation_level      	IN  NUMBER   := fnd_api.g_valid_level_full,
2055     p_mass_edit_tbl          	IN  mass_edit_tbl,
2056     x_return_status          	OUT NOCOPY    VARCHAR2,
2057     x_msg_count              	OUT NOCOPY    NUMBER,
2058     x_msg_data	                OUT NOCOPY    VARCHAR2
2059 
2060   ) IS
2061 
2062     l_api_version             NUMBER          := 1.0;
2063     l_api_name                VARCHAR2(30)    := 'DELETE_MASS_EDIT_BATCHES';
2064     l_msg_count               NUMBER;
2065     l_msg_data                VARCHAR2(2000);
2066     l_return_status           VARCHAR2(1);
2067 
2068 BEGIN
2069 
2070     -- Standard Start of API savepoint
2071     SAVEPOINT delete_mass_edit_batches;
2072 
2073     csi_t_gen_utility_pvt.add('API Being Executed     : DELETE_MASS_EDIT_BATCHES');
2074     csi_t_gen_utility_pvt.add('Transaction Start Time :'||to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
2075 
2076     -- Initialize message list if p_init_msg_list is set to TRUE.
2077     IF FND_API.To_Boolean( p_init_msg_list ) THEN
2078       FND_MSG_PUB.Initialize;
2079     END IF;
2080 
2081     --  Initialize API return status to success
2082     x_return_status := FND_API.G_RET_STS_SUCCESS;
2083 
2084     -- Standard call to check for call compatibility.
2085     IF NOT
2086        FND_API.Compatible_API_Call (
2087          p_current_version_number => l_api_version,
2088          p_caller_version_number  => p_api_version,
2089          p_api_name               => l_api_name,
2090          p_pkg_name               => g_pkg_name) THEN
2091 
2092       RAISE FND_API.G_Exc_Unexpected_Error;
2093     END IF;
2094     -- This procedure check if the installed base is active, If not active
2095     -- populates the error message in the message queue and raises the
2096     -- fnd_api.g_exc_error exception
2097     --
2098      csi_utility_grp.check_ib_active;
2099 
2100      -- check required params
2101      -- either the batch id OR the batch name is required for a delete
2102      IF p_mass_edit_tbl.count > 0 THEN
2103       FOR m_ind in p_mass_edit_tbl.FIRST .. p_mass_edit_tbl.LAST LOOP
2104           IF ( nvl(p_mass_edit_tbl(m_ind).entry_id, fnd_api.g_miss_num) = fnd_api.g_miss_num
2105              AND nvl(p_mass_edit_tbl(m_ind).name, fnd_api.g_miss_char) = fnd_api.g_miss_char ) THEN
2106 
2107               FND_MESSAGE.set_name('CSI','CSI_API_REQD_PARAM_MISSING');
2108               FND_MESSAGE.set_token('API_NAME',l_api_name);
2109               FND_MESSAGE.set_token('MISSING_PARAM','Batch ID OR Batch Name');
2110               FND_MSG_PUB.add;
2111               RAISE FND_API.g_exc_error;
2112           END IF;
2113 
2114           csi_mass_edit_pvt.delete_mass_edit_batch (
2115                  p_api_version      => p_api_version,
2116                  p_commit           => p_commit,
2117                  p_init_msg_list    => p_init_msg_list,
2118                  p_validation_level => p_validation_level,
2119                  p_mass_edit_rec    => p_mass_edit_tbl(m_ind),
2120                  x_return_status    => l_return_status,
2121                  x_msg_count        => l_msg_count,
2122                  x_msg_data         => l_msg_data
2123                 );
2124 
2125             IF l_return_status <> fnd_api.g_ret_sts_success THEN
2126               RAISE fnd_api.g_exc_error;
2127             END IF;
2128       END LOOP;
2129      END IF;
2130 
2131     -- Standard check of p_commit.
2132     IF FND_API.To_Boolean( p_commit ) THEN
2133          COMMIT WORK;
2134     END IF;
2135 
2136     -- Standard call to get message count and IF count is  get message info.
2137     FND_MSG_PUB.Count_And_Get
2138          (p_count  =>  x_msg_count,
2139           p_data   =>  x_msg_data
2140          );
2141 
2142     csi_t_gen_utility_pvt.add('API Executed         : Delete Mass Edit Batches');
2143     csi_t_gen_utility_pvt.add('Transaction End Time :'||to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
2144 
2145     csi_t_gen_utility_pvt.set_debug_off;
2146 
2147   EXCEPTION
2148     WHEN FND_API.G_EXC_ERROR THEN
2149 
2150       ROLLBACK TO Delete_Mass_Edit_Batches;
2151       x_return_status := FND_API.G_RET_STS_ERROR ;
2152       FND_MSG_PUB.Count_And_Get (
2153         p_count  => x_msg_count,
2154         p_data   => x_msg_data);
2155 
2156       csi_t_gen_utility_pvt.set_debug_off;
2157 
2158     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2159 
2160       ROLLBACK TO Delete_Mass_Edit_Batches;
2161       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2162 
2163       FND_MSG_PUB.Count_And_Get(
2164         p_count  => x_msg_count,
2165         p_data   => x_msg_data);
2166 
2167       csi_t_gen_utility_pvt.set_debug_off;
2168 
2169     WHEN OTHERS THEN
2170 
2171       ROLLBACK TO Delete_Mass_Edit_Batches;
2172       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2173 
2174       IF FND_MSG_PUB.Check_Msg_Level(
2175            p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
2176 
2177         FND_MSG_PUB.Add_Exc_Msg(
2178           p_pkg_name       => G_PKG_NAME,
2179           p_procedure_name => l_api_name);
2180       END IF;
2181 
2182       FND_MSG_PUB.Count_And_Get(
2183         p_count  => x_msg_count,
2184         p_data   => x_msg_data);
2185 
2186       csi_t_gen_utility_pvt.set_debug_off;
2187 
2188   END Delete_Mass_Edit_Batches;
2189 
2190   /*
2191      This API gets all the transaction line details and also the child records for each of
2192      these line details, for a given mass edit batch.
2193   */
2194 
2195   PROCEDURE GET_MASS_EDIT_DETAILS (
2196     p_api_version          	IN  NUMBER,
2197     p_commit               	IN  VARCHAR2 := fnd_api.g_false,
2198     p_init_msg_list        	IN  VARCHAR2 := fnd_api.g_false,
2199     p_validation_level     	IN  NUMBER   := fnd_api.g_valid_level_full,
2200     px_mass_edit_rec          	IN  OUT NOCOPY mass_edit_rec,
2201     x_txn_line_detail_tbl       OUT NOCOPY csi_t_datastructures_grp.txn_line_detail_tbl ,
2202     x_txn_party_detail_tbl      OUT NOCOPY csi_t_datastructures_grp.txn_party_detail_tbl,
2203     x_txn_pty_acct_detail_tbl   OUT NOCOPY csi_t_datastructures_grp.txn_pty_acct_detail_tbl,
2204     x_txn_ext_attrib_vals_tbl   OUT NOCOPY csi_t_datastructures_grp.txn_ext_attrib_vals_tbl,
2205     x_return_status             OUT NOCOPY VARCHAR2,
2206     x_msg_count                 OUT NOCOPY NUMBER ,
2207     x_msg_data                  OUT NOCOPY VARCHAR2)
2208 IS
2209 
2210     l_api_version             NUMBER          := 1.0;
2211     l_api_name                VARCHAR2(30)    := 'GET_MASS_EDIT_DETAILS';
2212     l_msg_count               NUMBER;
2213     l_msg_data                VARCHAR2(2000);
2214     l_return_status           VARCHAR2(1);
2215 
2216 BEGIN
2217 
2218     -- Standard Start of API savepoint
2219     SAVEPOINT get_mass_edit_details;
2220 
2221     csi_t_gen_utility_pvt.add('API Being Executed     : GET_MASS_EDIT_DETAILS');
2222     csi_t_gen_utility_pvt.add('Transaction Start Time :'||to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
2223 
2224     -- Initialize message list if p_init_msg_list is set to TRUE.
2225     IF FND_API.To_Boolean( p_init_msg_list ) THEN
2226       FND_MSG_PUB.Initialize;
2227     END IF;
2228 
2229     --  Initialize API return status to success
2230     x_return_status := FND_API.G_RET_STS_SUCCESS;
2231 
2232     -- Standard call to check for call compatibility.
2233     IF NOT
2234        FND_API.Compatible_API_Call (
2235          p_current_version_number => l_api_version,
2236          p_caller_version_number  => p_api_version,
2237          p_api_name               => l_api_name,
2238          p_pkg_name               => g_pkg_name) THEN
2239 
2240       RAISE FND_API.G_Exc_Unexpected_Error;
2241     END IF;
2242     -- This procedure check if the installed base is active, If not active
2243     -- populates the error message in the message queue and raises the
2244     -- fnd_api.g_exc_error exception
2245     --
2246      csi_utility_grp.check_ib_active;
2247 
2248      -- check required params
2249      -- Currently the Get queries txn details for a given source transaction id (batch). So a unique
2250      -- identifier like the batch id/txn line ID OR the batch name is required for a Get
2251 
2252   IF ( nvl(px_mass_edit_rec.entry_id, fnd_api.g_miss_num) = fnd_api.g_miss_num
2253      AND nvl(px_mass_edit_rec.name, fnd_api.g_miss_char) = fnd_api.g_miss_char
2254      AND nvl(px_mass_edit_rec.txn_line_id, fnd_api.g_miss_num) = fnd_api.g_miss_num
2255      ) THEN
2256       FND_MESSAGE.set_name('CSI','CSI_API_REQD_PARAM_MISSING');
2257       FND_MESSAGE.set_token('API_NAME',l_api_name);
2258       FND_MESSAGE.set_token('MISSING_PARAM','Batch ID / Batch Name / Transaction Line ID');
2259       FND_MSG_PUB.add;
2260       RAISE FND_API.g_exc_error;
2261   END IF;
2262 
2263   csi_mass_edit_pvt.get_mass_edit_details (
2264          p_api_version              => p_api_version,
2265          p_commit                   => p_commit,
2266          p_init_msg_list            => p_init_msg_list,
2267          p_validation_level         => p_validation_level,
2268          px_mass_edit_rec           => px_mass_edit_rec,
2269          x_txn_line_detail_tbl      => x_txn_line_detail_tbl,
2270          x_txn_party_detail_tbl     => x_txn_party_detail_tbl,
2271          x_txn_pty_acct_detail_tbl  => x_txn_pty_acct_detail_tbl,
2272          x_txn_ext_attrib_vals_tbl  => x_txn_ext_attrib_vals_tbl,
2273          x_return_status            => l_return_status,
2274          x_msg_count                => l_msg_count,
2275          x_msg_data                 => l_msg_data
2276         );
2277 
2278     IF l_return_status <> fnd_api.g_ret_sts_success THEN
2279       RAISE fnd_api.g_exc_error;
2280     END IF;
2281 
2282     -- Standard check of p_commit.
2283     IF FND_API.To_Boolean( p_commit ) THEN
2284          COMMIT WORK;
2285     END IF;
2286 
2287     -- Standard call to get message count and IF count is  get message info.
2288     FND_MSG_PUB.Count_And_Get
2289          (p_count  =>  x_msg_count,
2290           p_data   =>  x_msg_data
2291          );
2292 
2293     csi_t_gen_utility_pvt.add('API Executed         : Get Mass Edit Details');
2294     csi_t_gen_utility_pvt.add('Transaction End Time :'||to_char(sysdate, 'MM/DD/YY HH24:MI:SS'));
2295 
2296     csi_t_gen_utility_pvt.set_debug_off;
2297 
2298   EXCEPTION
2299     WHEN FND_API.G_EXC_ERROR THEN
2300 
2301       ROLLBACK TO Get_mass_edit_details;
2302       x_return_status := FND_API.G_RET_STS_ERROR ;
2303       FND_MSG_PUB.Count_And_Get (
2304         p_count  => x_msg_count,
2305         p_data   => x_msg_data);
2306 
2307       csi_t_gen_utility_pvt.set_debug_off;
2308 
2309     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2310 
2311       ROLLBACK TO Get_mass_edit_details;
2312       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2313 
2314       FND_MSG_PUB.Count_And_Get(
2315         p_count  => x_msg_count,
2316         p_data   => x_msg_data);
2317 
2318       csi_t_gen_utility_pvt.set_debug_off;
2319 
2320     WHEN OTHERS THEN
2321 
2322       ROLLBACK TO Get_mass_edit_details;
2323       x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2324 
2325       IF FND_MSG_PUB.Check_Msg_Level(
2326            p_message_level => FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
2327 
2328         FND_MSG_PUB.Add_Exc_Msg(
2329           p_pkg_name       => G_PKG_NAME,
2330           p_procedure_name => l_api_name);
2331 
2332       END IF;
2333 
2334       FND_MSG_PUB.Count_And_Get(
2335         p_count  => x_msg_count,
2336         p_data   => x_msg_data);
2337 
2338       csi_t_gen_utility_pvt.set_debug_off;
2339 
2340   END Get_mass_edit_details;
2341 
2342 /*----------------------------------------------------*/
2343 /* Procedure name: PROCESS_SYSTEM_MASS_UPDATE         */
2344 /* Description :   procedure used to update System in */
2345 /*                 mass update batch                  */
2346 /*----------------------------------------------------*/
2347 
2348 PROCEDURE PROCESS_SYSTEM_MASS_UPDATE
2349  (
2350      p_api_version           IN     NUMBER
2351     ,p_commit                IN     VARCHAR2 := fnd_api.g_false
2352     ,p_entry_id             IN NUMBER
2353     ,p_instance_tbl          IN OUT NOCOPY csi_datastructures_pub.instance_tbl
2354     ,p_ext_attrib_values_tbl IN OUT NOCOPY csi_datastructures_pub.extend_attrib_values_tbl
2355     ,p_party_tbl             IN OUT NOCOPY csi_datastructures_pub.party_tbl
2356     ,p_account_tbl           IN OUT NOCOPY csi_datastructures_pub.party_account_tbl
2357     ,p_txn_rec               IN OUT NOCOPY csi_datastructures_pub.transaction_rec
2358     ,x_return_status         OUT NOCOPY    VARCHAR2
2359     ,x_msg_count             OUT NOCOPY    NUMBER
2360     ,x_msg_data              OUT NOCOPY    VARCHAR2
2361  )
2362  IS
2363 
2364   CURSOR mu_new_party_csr(p_transaction_line_id NUMBER) IS
2365     SELECT tp.party_source_table PartySourceTable,
2366     tp.party_source_id PartyId,
2367     ta.account_id AccountId,
2368     party.party_number PartyNumber
2369      FROM csi_t_txn_line_details tld,
2370           csi_t_party_details tp,
2371           csi_t_party_accounts ta,
2372           hz_parties party,
2373           hz_cust_accounts account
2374     WHERE tld.txn_line_detail_id = tp.txn_line_detail_id
2375           AND tld.transaction_line_id    = p_transaction_line_id
2376           AND tld.INSTANCE_ID           IS NULL
2377           AND tp.txn_party_detail_id     = ta.txn_party_detail_id
2378           AND tp.party_source_id         = party.party_id
2379           AND ta.account_id              = account.cust_account_id
2380           AND tp.relationship_type_code  = 'OWNER'
2381           AND tp.party_source_table      = 'HZ_PARTIES';
2382  -- Bug 7350165
2383  -- CURSOR mu_customer_id_csr (p_party_id IN NUMBER, p_account_number IN NUMBER) IS
2384  --   SELECT CUST_ACCOUNT_ID  CUSTOMER_ID
2385  --     FROM HZ_CUST_ACCOUNTS
2386  --     WHERE PARTY_ID = p_party_id
2387  --        AND ACCOUNT_NUMBER = p_account_number;
2388 
2389   CURSOR mu_system_csr (p_system_id IN NUMBER) IS
2390     SELECT  SYSTEM_TYPE_CODE,
2391             SYSTEM_NUMBER,
2392             PARENT_SYSTEM_ID,
2393             COTERMINATE_DAY_MONTH,
2394             START_DATE_ACTIVE,
2395             END_DATE_ACTIVE,
2396             CONTEXT,
2397             ATTRIBUTE1,
2398             ATTRIBUTE2,
2399             ATTRIBUTE3,
2400             ATTRIBUTE4,
2401             ATTRIBUTE5,
2402             ATTRIBUTE6,
2403             ATTRIBUTE7,
2404             ATTRIBUTE8,
2405             ATTRIBUTE9,
2406             ATTRIBUTE10,
2407             ATTRIBUTE11,
2408             ATTRIBUTE12,
2409             ATTRIBUTE13,
2410             ATTRIBUTE14,
2411             ATTRIBUTE15,
2412             OBJECT_VERSION_NUMBER,
2413             OPERATING_UNIT_ID,
2414             PROGRAM_APPLICATION_ID,
2415             PROGRAM_ID
2416       FROM CSI_SYSTEMS_B
2417       WHERE SYSTEM_ID = p_system_id;
2418 
2419   CURSOR mu_system_tl_csr (p_system_id IN NUMBER) IS
2420     SELECT  NAME,
2421             DESCRIPTION
2422       FROM CSI_SYSTEMS_TL
2423       WHERE SYSTEM_ID = p_system_id;
2424 
2425 
2426 
2427   l_api_name               CONSTANT VARCHAR2(30)     := 'PROCESS_SYSTEM_MASS_UPDATE';
2428   l_api_version            CONSTANT NUMBER           := 1.0;
2429   l_debug_level            NUMBER;
2430   l_txn_line_id               NUMBER;
2431 
2432   upd_system_tbl             csi_datastructures_pub.mu_systems_tbl;
2433   l_txn_sys_rec              csi_datastructures_pub.system_rec;
2434   l_t_txn_sys_rec               csi_t_datastructures_grp.txn_system_rec;
2435   l_mu_new_party_rec         mu_new_party_csr%ROWTYPE;
2436   --l_mu_customer_id_rec       mu_customer_id_csr%ROWTYPE; -- 7350165
2437   l_mu_system_rec               mu_system_csr%ROWTYPE;
2438   l_mu_system_tl_rec          mu_system_tl_csr%ROWTYPE;
2439 
2440 
2441   l_msg_count               NUMBER;
2442   l_msg_data                VARCHAR2(2000);
2443   l_return_status             VARCHAR2(1) := fnd_api.g_ret_sts_success;
2444 
2445  BEGIN
2446 
2447   -- Standard Start of API savepoint
2448   SAVEPOINT       PROCESS_SYSTEM_MASS_UPDATE;
2449 
2450   debug('Inside PROCESS_SYSTEM_MASS_UPDATE');
2451 
2452   csi_utility_grp.check_ib_active;
2453 
2454   -- Standard call to check for call compatibility.
2455   IF NOT FND_API.Compatible_API_Call (l_api_version,
2456             p_api_version,
2457             l_api_name       ,
2458             G_PKG_NAME       )
2459   THEN
2460     RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2461   END IF;
2462 
2463   --  Initialize API return status to success
2464   x_return_status := FND_API.G_RET_STS_SUCCESS;
2465 
2466   -- Check the profile option debug_level for debug message reporting
2467   l_debug_level:=fnd_profile.value('CSI_DEBUG_LEVEL');
2468 
2469   -- If debug_level = 1 then dump the procedure name
2470   IF (l_debug_level > 0) THEN
2471 	  csi_gen_utility_pvt.put_line( 'PROCESS_SYSTEM_MASS_UPDATE');
2472   END IF;
2473 
2474   debug('Starting System Cascade for Entry ID - ' || p_entry_id);
2475   -- Identifying systems
2476   -- Fetching the transaction line id
2477   BEGIN
2478   SELECT  cmee.txn_line_id
2479     INTO    l_txn_line_id
2480     FROM    csi_mass_edit_entries_vl cmee,
2481             csi_lookups clkps
2482     WHERE   cmee.entry_id       = p_entry_id
2483     --AND     cmee.status_code    = 'SCHEDULED'
2484     AND     cmee.schedule_date <= SYSDATE
2485     AND     clkps.lookup_type    = 'CSI_IB_TXN_TYPE_CODE'
2486     AND     clkps.lookup_code    = cmee.batch_type;
2487 
2488   EXCEPTION
2489   WHEN NO_DATA_FOUND THEN
2490       debug('No data Found while fetching txn line id for system cascade');
2491       RAISE FND_API.G_EXC_ERROR;
2492     WHEN OTHERS THEN
2493       debug('Others Exception while fetching txn line id for system cascade');
2494       RAISE FND_API.G_EXC_ERROR;
2495   END;
2496   debug('l_txn_line_id - ' || l_txn_line_id);
2497 
2498   IDENTIFY_SYSTEM_FOR_UPDATE (
2499         p_txn_line_id           => l_txn_line_id
2500        ,p_upd_system_tbl        => upd_system_tbl
2501        ,x_return_status         => l_return_status);
2502 
2503   IF NOT l_return_status = FND_API.G_RET_STS_SUCCESS THEN
2504     RAISE FND_API.G_EXC_ERROR;
2505   END IF;
2506 
2507   IF upd_system_tbl.COUNT > 0 THEN
2508 
2509   -- Validations of the identified systems
2510   VALIDATE_SYSTEM_BATCH (
2511         p_entry_id              => p_entry_id
2512        ,p_txn_line_id           => l_txn_line_id
2513        ,p_upd_system_tbl        => upd_system_tbl
2514        ,x_return_status         => l_return_status);
2515 
2516   IF NOT l_return_status = FND_API.G_RET_STS_SUCCESS THEN
2517     RAISE FND_API.G_EXC_ERROR;
2518   END IF;
2519 
2520   -- System update
2521   -- Fetch the new Party Information (Party Id, Account Id)
2522   BEGIN
2523     OPEN   mu_new_party_csr (l_txn_line_id);
2524     FETCH  mu_new_party_csr INTO l_mu_new_party_rec;
2525     CLOSE  mu_new_party_csr;
2526   EXCEPTION
2527    WHEN OTHERS THEN
2528       debug('In to Others Exception while finding new party information');
2529       debug( to_char(SQLCODE)||substr(SQLERRM, 1, 255));
2530       RAISE FND_API.G_EXC_ERROR;
2531   END;
2532 
2533   -- Fetch Customer id from party id and account id
2534  /* BEGIN
2535     OPEN   mu_customer_id_csr (l_mu_new_party_rec.PartyId, l_mu_new_party_rec.AccountId);
2536     FETCH  mu_customer_id_csr INTO l_mu_customer_id_rec;
2537     CLOSE  mu_customer_id_csr;
2538   EXCEPTION
2539     WHEN NO_DATA_FOUND THEN
2540       fnd_message.set_name('CSI', 'CSI_CUSTOMER_ID_NOT_FOUND');
2541       fnd_message.set_token('PARTY_ID',l_mu_new_party_rec.PartyId);
2542       fnd_message.set_token('ACCOUNT_NUMBER',l_mu_new_party_rec.AccountId);
2543       fnd_msg_pub.add;
2544       RAISE FND_API.G_EXC_ERROR;
2545 
2546    WHEN TOO_MANY_ROWS THEN
2547       fnd_message.set_name('CSI', 'CSI_MULTIPLE_CUSTOMER_ID_FOUND');
2548       fnd_message.set_token('PARTY_ID',l_mu_new_party_rec.PartyId);
2549       fnd_message.set_token('ACCOUNT_NUMBER',l_mu_new_party_rec.AccountId);
2550       fnd_msg_pub.add;
2551       RAISE FND_API.G_EXC_ERROR;
2552    WHEN OTHERS THEN
2553       debug('In to Others Exception while finding customer id');
2554       RAISE FND_API.G_EXC_ERROR;
2555   END;
2556   */
2557    FOR system_rec_ind IN upd_system_tbl.FIRST .. upd_system_tbl.LAST
2558    LOOP
2559     l_txn_sys_rec.SYSTEM_ID := upd_system_tbl(system_rec_ind).SYSTEM_ID;
2560     -- Fix for the bug 7350165
2561     l_txn_sys_rec.CUSTOMER_ID := l_mu_new_party_rec.AccountId;
2562     --l_txn_sys_rec.CUSTOMER_ID := l_mu_customer_id_rec.CUSTOMER_ID;
2563     l_txn_sys_rec.REQUEST_ID := FND_GLOBAL.CONC_REQUEST_ID;
2564 
2565     -- Assign null values to the contact ids, site use ids
2566     -- TODO New enhancement has to be made at the mass update page
2567     -- to capture contact ids, site use id and that information
2568     -- should be populated here
2569 
2570     -- Important : Also note the base update package has been modified to
2571     -- accept null values update_row_for_mu
2572     l_txn_sys_rec.SHIP_TO_CONTACT_ID := FND_API.G_MISS_NUM;
2573     l_txn_sys_rec.BILL_TO_CONTACT_ID := FND_API.G_MISS_NUM;
2574     l_txn_sys_rec.TECHNICAL_CONTACT_ID := FND_API.G_MISS_NUM;
2575     l_txn_sys_rec.SERVICE_ADMIN_CONTACT_ID := FND_API.G_MISS_NUM;
2576     l_txn_sys_rec.SHIP_TO_SITE_USE_ID := FND_API.G_MISS_NUM;
2577     l_txn_sys_rec.BILL_TO_SITE_USE_ID := FND_API.G_MISS_NUM;
2578     l_txn_sys_rec.INSTALL_SITE_USE_ID := FND_API.G_MISS_NUM;
2579 
2580     -- Fetch the existing values of the system
2581     -- Other information which are non related to the system party owner
2582     -- is retained
2583     OPEN   mu_system_csr (upd_system_tbl(system_rec_ind).SYSTEM_ID);
2584     FETCH  mu_system_csr INTO l_mu_system_rec;
2585     CLOSE  mu_system_csr;
2586 
2587     OPEN   mu_system_tl_csr (upd_system_tbl(system_rec_ind).SYSTEM_ID);
2588     FETCH  mu_system_tl_csr INTO l_mu_system_tl_rec;
2589     CLOSE  mu_system_tl_csr;
2590 
2591     -- retaining the existing values of the system
2592     l_txn_sys_rec.SYSTEM_TYPE_CODE := l_mu_system_rec.SYSTEM_TYPE_CODE;
2593     l_txn_sys_rec.SYSTEM_NUMBER := l_mu_system_rec.SYSTEM_NUMBER;
2594     l_txn_sys_rec.PARENT_SYSTEM_ID := l_mu_system_rec.PARENT_SYSTEM_ID;
2595     l_txn_sys_rec.COTERMINATE_DAY_MONTH := l_mu_system_rec.COTERMINATE_DAY_MONTH;
2596     l_txn_sys_rec.START_DATE_ACTIVE := l_mu_system_rec.START_DATE_ACTIVE;
2597     l_txn_sys_rec.END_DATE_ACTIVE := l_mu_system_rec.END_DATE_ACTIVE;
2598     l_txn_sys_rec.CONTEXT := l_mu_system_rec.CONTEXT;
2599     l_txn_sys_rec.NAME := l_mu_system_tl_rec.NAME;
2600     l_txn_sys_rec.DESCRIPTION := l_mu_system_tl_rec.DESCRIPTION;
2601     l_txn_sys_rec.ATTRIBUTE1 := l_mu_system_rec.ATTRIBUTE1;
2602     l_txn_sys_rec.ATTRIBUTE2 := l_mu_system_rec.ATTRIBUTE2;
2603     l_txn_sys_rec.ATTRIBUTE3 := l_mu_system_rec.ATTRIBUTE3;
2604     l_txn_sys_rec.ATTRIBUTE4 := l_mu_system_rec.ATTRIBUTE4;
2605     l_txn_sys_rec.ATTRIBUTE5 := l_mu_system_rec.ATTRIBUTE5;
2606     l_txn_sys_rec.ATTRIBUTE6 := l_mu_system_rec.ATTRIBUTE6;
2607     l_txn_sys_rec.ATTRIBUTE7 := l_mu_system_rec.ATTRIBUTE7;
2608     l_txn_sys_rec.ATTRIBUTE8 := l_mu_system_rec.ATTRIBUTE8;
2609     l_txn_sys_rec.ATTRIBUTE9 := l_mu_system_rec.ATTRIBUTE9;
2610     l_txn_sys_rec.ATTRIBUTE10 := l_mu_system_rec.ATTRIBUTE10;
2611     l_txn_sys_rec.ATTRIBUTE11 := l_mu_system_rec.ATTRIBUTE11;
2612     l_txn_sys_rec.ATTRIBUTE12 := l_mu_system_rec.ATTRIBUTE12;
2613     l_txn_sys_rec.ATTRIBUTE13 := l_mu_system_rec.ATTRIBUTE13;
2614     l_txn_sys_rec.ATTRIBUTE14 := l_mu_system_rec.ATTRIBUTE14;
2615     l_txn_sys_rec.ATTRIBUTE15 := l_mu_system_rec.ATTRIBUTE15;
2616     l_txn_sys_rec.OBJECT_VERSION_NUMBER := l_mu_system_rec.OBJECT_VERSION_NUMBER;
2617     l_txn_sys_rec.OPERATING_UNIT_ID := l_mu_system_rec.OPERATING_UNIT_ID;
2618     l_txn_sys_rec.PROGRAM_APPLICATION_ID := l_mu_system_rec.PROGRAM_APPLICATION_ID;
2619     l_txn_sys_rec.PROGRAM_ID := l_mu_system_rec.PROGRAM_ID;
2620 
2621     -- To Create System transaction lines in CSI_T_TXN_SYSTEMS
2622     -- Construct system transaction record
2623     -- This transaction record is not really used for MU TR processing, but
2624     -- transactions are created for any future enhacements/tracking
2625     --
2626     l_t_txn_sys_rec.TRANSACTION_LINE_ID := l_txn_line_id;
2627     l_t_txn_sys_rec.SYSTEM_NAME := l_mu_system_tl_rec.NAME;
2628     l_t_txn_sys_rec.DESCRIPTION := l_mu_system_tl_rec.DESCRIPTION;
2629     l_t_txn_sys_rec.SYSTEM_TYPE_CODE := l_mu_system_rec.SYSTEM_TYPE_CODE;
2630     l_t_txn_sys_rec.SYSTEM_NUMBER := l_mu_system_rec.SYSTEM_NUMBER;
2631     -- Bug 7350165
2632     l_t_txn_sys_rec.CUSTOMER_ID := l_mu_new_party_rec.AccountId;
2633     --l_t_txn_sys_rec.CUSTOMER_ID := l_mu_customer_id_rec.CUSTOMER_ID;
2634     l_t_txn_sys_rec.BILL_TO_CONTACT_ID := FND_API.G_MISS_NUM;
2635     l_t_txn_sys_rec.SHIP_TO_CONTACT_ID := FND_API.G_MISS_NUM;
2636     l_t_txn_sys_rec.TECHNICAL_CONTACT_ID := FND_API.G_MISS_NUM;
2637     l_t_txn_sys_rec.SERVICE_ADMIN_CONTACT_ID := FND_API.G_MISS_NUM;
2638     l_t_txn_sys_rec.SHIP_TO_SITE_USE_ID := FND_API.G_MISS_NUM;
2639     l_t_txn_sys_rec.BILL_TO_SITE_USE_ID := FND_API.G_MISS_NUM;
2640     l_t_txn_sys_rec.INSTALL_SITE_USE_ID := FND_API.G_MISS_NUM;
2641     l_t_txn_sys_rec.COTERMINATE_DAY_MONTH := l_mu_system_rec.COTERMINATE_DAY_MONTH;
2642     l_t_txn_sys_rec.START_DATE_ACTIVE := l_mu_system_rec.START_DATE_ACTIVE;
2643     l_t_txn_sys_rec.END_DATE_ACTIVE := l_mu_system_rec.END_DATE_ACTIVE;
2644     l_t_txn_sys_rec.CONTEXT := l_txn_line_id;
2645     l_t_txn_sys_rec.ATTRIBUTE1 := l_mu_system_rec.ATTRIBUTE1;
2646     l_t_txn_sys_rec.ATTRIBUTE2 := l_mu_system_rec.ATTRIBUTE2;
2647     l_t_txn_sys_rec.ATTRIBUTE3 := l_mu_system_rec.ATTRIBUTE3;
2648     l_t_txn_sys_rec.ATTRIBUTE4 := l_mu_system_rec.ATTRIBUTE4;
2649     l_t_txn_sys_rec.ATTRIBUTE5 := l_mu_system_rec.ATTRIBUTE5;
2650     l_t_txn_sys_rec.ATTRIBUTE6 := l_mu_system_rec.ATTRIBUTE6;
2651     l_t_txn_sys_rec.ATTRIBUTE7 := l_mu_system_rec.ATTRIBUTE7;
2652     l_t_txn_sys_rec.ATTRIBUTE8 := l_mu_system_rec.ATTRIBUTE8;
2653     l_t_txn_sys_rec.ATTRIBUTE9 := l_mu_system_rec.ATTRIBUTE9;
2654     l_t_txn_sys_rec.ATTRIBUTE10 := l_mu_system_rec.ATTRIBUTE10;
2655     l_t_txn_sys_rec.ATTRIBUTE11 := l_mu_system_rec.ATTRIBUTE11;
2656     l_t_txn_sys_rec.ATTRIBUTE12 := l_mu_system_rec.ATTRIBUTE12;
2657     l_t_txn_sys_rec.ATTRIBUTE13 := l_mu_system_rec.ATTRIBUTE13;
2658     l_t_txn_sys_rec.ATTRIBUTE14 := l_mu_system_rec.ATTRIBUTE14;
2659     l_t_txn_sys_rec.ATTRIBUTE15 := l_mu_system_rec.ATTRIBUTE15;
2660     l_t_txn_sys_rec.OBJECT_VERSION_NUMBER := l_mu_system_rec.OBJECT_VERSION_NUMBER;
2661 
2662     debug('Creating system t transaction');
2663     csi_t_txn_systems_pvt.create_txn_system(
2664       p_api_version                => 1.0,
2665       p_commit                     => FND_API.G_FALSE,
2666       p_init_msg_list              => FND_API.G_FALSE,
2667       p_validation_level           => FND_API.G_VALID_LEVEL_FULL,
2668       p_txn_system_rec             => l_t_txn_sys_rec,
2669       x_txn_system_id              => upd_system_tbl(system_rec_ind).SYSTEM_ID,
2670       x_return_status              => l_return_status,
2671       x_msg_count                  => l_msg_count,
2672       x_msg_data                   => l_msg_data
2673    );
2674 
2675     debug('Calling UPDATE_SYSTEM');
2676     -- Calling CSI_SYSTEMS_PVT to update the system
2677     -- with l_txn_sys_rec as the system parameter
2678     CSI_SYSTEMS_PVT.UPDATE_SYSTEM(
2679       p_api_version                => 1.0,
2680       p_commit                     => FND_API.G_FALSE,
2681       p_init_msg_list              => FND_API.G_FALSE,
2682       p_validation_level           => FND_API.G_VALID_LEVEL_FULL,
2683       p_system_rec                 => l_txn_sys_rec,
2684       p_txn_rec                    => p_txn_rec,
2685       x_return_status              => l_return_status,
2686       x_msg_count                  => l_msg_count,
2687       x_msg_data                   => l_msg_data);
2688 
2689     IF NOT l_return_status = fnd_api.g_ret_sts_success
2690     THEN
2691       debug('Error updating systems in PROCESS_SYSTEM_MASS_UPDATE - System ID - ' || upd_system_tbl(system_rec_ind).SYSTEM_ID);
2692       RAISE FND_API.G_EXC_ERROR;
2693     END IF;
2694 
2695    END LOOP; -- upd_system_tbl
2696 
2697    ELSE -- upd_system_tbl.COUNT > 0
2698     x_return_status := fnd_api.g_ret_sts_success;
2699    END IF; -- upd_system_tbl.COUNT > 0
2700 
2701  EXCEPTION
2702     WHEN FND_API.G_EXC_ERROR THEN
2703        ROLLBACK TO PROCESS_SYSTEM_MASS_UPDATE;
2704        x_return_status := FND_API.G_RET_STS_ERROR ;
2705        FND_MSG_PUB.Count_And_Get
2706                 (       p_count                 =>      x_msg_count,
2707                 p_data                  =>      x_msg_data
2708                 );
2709 
2710     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2711        ROLLBACK TO PROCESS_SYSTEM_MASS_UPDATE;
2712        x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2713        FND_MSG_PUB.Count_And_Get
2714         (       p_count                 =>      x_msg_count,
2715                 p_data                  =>      x_msg_data
2716         );
2717 
2718     WHEN OTHERS THEN
2719        ROLLBACK TO PROCESS_SYSTEM_MASS_UPDATE;
2720        x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2721        IF FND_MSG_PUB.Check_Msg_Level
2722           (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
2723        THEN
2724           FND_MSG_PUB.Add_Exc_Msg
2725                 (       G_PKG_NAME          ,
2726                         l_api_name
2727                 );
2728        END IF;
2729        FND_MSG_PUB.Count_And_Get
2730                 (       p_count                 =>      x_msg_count,
2731                         p_data                  =>      x_msg_data
2732                 );
2733  END PROCESS_SYSTEM_MASS_UPDATE; -- PROCESS_SYSTEM_MASS_UPDATE
2734 
2735 /*----------------------------------------------------*/
2736 /* Procedure name: IDENTIFY_SYSTEM_FOR_UPDATE         */
2737 /* Description :   procedure used to identifies System for */
2738 /*                 mass update batch                  */
2739 /*----------------------------------------------------*/
2740 PROCEDURE IDENTIFY_SYSTEM_FOR_UPDATE
2741  (
2742      p_txn_line_id          IN           NUMBER
2743     ,p_upd_system_tbl      OUT NOCOPY   csi_datastructures_pub.mu_systems_tbl
2744     ,x_return_status       OUT NOCOPY   VARCHAR2
2745  )
2746  IS
2747 
2748   -- Cursors
2749   CURSOR distinct_system_cur (txn_line_id IN NUMBER) IS
2750    SELECT distinct cii.system_id system_id
2751    FROM   csi_t_txn_line_details ctld,
2752           csi_item_instances cii
2753    WHERE  ctld.transaction_line_id = txn_line_id
2754    AND    ctld.INSTANCE_ID is not null
2755    AND    ctld.preserve_detail_flag = 'Y'
2756    AND    cii.instance_id = ctld.instance_id;
2757 
2758   l_active_instance_count           NUMBER := 0;
2759   l_mu_instance_count               NUMBER := 0;
2760   l_sys_ind                  		    NUMBER := 0;
2761   l_return_status             VARCHAR2(1) := fnd_api.g_ret_sts_success;
2762 
2763 
2764  BEGIN
2765 
2766  debug('Inside IDENTIFY_SYSTEM_FOR_UPDATE');
2767 
2768  FOR l_mu_systems_csr IN distinct_system_cur(p_txn_line_id)
2769  LOOP
2770    debug ('System ID - ' || l_mu_systems_csr.system_id);
2771    IF l_mu_systems_csr.system_id IS NOT NULL THEN
2772     -- To get the count of active item instances in the system
2773      SELECT COUNT(1)
2774      INTO l_active_instance_count
2775      FROM csi_item_instances cisv,
2776       CSI_SYSTEMS_B csb
2777       WHERE cisv.SYSTEM_ID                    = l_mu_systems_csr.system_id
2778       AND cisv.system_id                      = csb.system_id
2779       AND NVL(cisv.ACTIVE_END_DATE,sysdate+1) > sysdate
2780       AND NVL(csb.END_DATE_ACTIVE,sysdate +1) > sysdate;
2781 
2782     debug('Total Active Instance in the System - ' || l_active_instance_count);
2783 
2784     -- To get total instances included in the mass update batch belonging to the system
2785      SELECT COUNT(1)
2786        INTO l_mu_instance_count
2787        FROM csi_t_txn_line_details ctld,
2788       csi_item_instances cii
2789       WHERE ctld.transaction_line_id = p_txn_line_id
2790       AND cii.system_id                = l_mu_systems_csr.system_id
2791       AND ctld.INSTANCE_ID            IS NOT NULL
2792       AND ctld.preserve_detail_flag    = 'Y'
2793       AND cii.instance_id              = ctld.instance_id;
2794 
2795     debug('Total Instances in Batch belonging to System - ' || l_mu_instance_count);
2796 
2797     IF l_mu_instance_count > 0 THEN
2798       IF l_mu_instance_count = l_active_instance_count THEN
2799       -- All the active item instances which are part of the system is included in the transfer owner batch
2800       -- Adding the system id to be updated
2801       l_sys_ind := l_sys_ind + 1;
2802       p_upd_system_tbl(l_sys_ind).SYSTEM_ID := l_mu_systems_csr.system_id;
2803       debug('System Qualifying for Mass Update - ' || l_mu_systems_csr.system_id);
2804       debug_out('System Qualifying for Mass Update - ' || l_mu_systems_csr.system_id);
2805 
2806       END IF; -- l_mu_instance_count = l_active_instance_count
2807     END IF; -- l_mu_instance_count > 0
2808    END IF; -- l_mu_systems_csr.system_id IS NOT NULL
2809  END LOOP; -- distinct_system_cur(p_txn_line_id)
2810 
2811  debug('Total Number of Systems to be updated - ' || p_upd_system_tbl.COUNT);
2812  debug_out('Total Number of Systems to be updated - ' || p_upd_system_tbl.COUNT);
2813  x_return_status := FND_API.G_RET_STS_SUCCESS;
2814  debug('End IDENTIFY_SYSTEM_FOR_UPDATE');
2815  EXCEPTION
2816   WHEN OTHERS THEN
2817    debug('Exception in IDENTIFY_SYSTEM_FOR_UPDATE');
2818    x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
2819 
2820 END IDENTIFY_SYSTEM_FOR_UPDATE; -- IDENTIFY_SYSTEM_FOR_UPDATE
2821 
2822 /*----------------------------------------------------*/
2823 /* Procedure name: VALIDATE_SYSTEM_BATCH               */
2824 /* Description :   procedure to validate systems before*/
2825 /*                  before mass update                 */
2826 /*----------------------------------------------------*/
2827 PROCEDURE VALIDATE_SYSTEM_BATCH
2828  (
2829      p_entry_id             IN           NUMBER
2830     ,p_txn_line_id          IN           NUMBER
2831     ,p_upd_system_tbl       IN   csi_datastructures_pub.mu_systems_tbl
2832     ,x_return_status        OUT NOCOPY   VARCHAR2
2833  )
2834  IS
2835 
2836  CURSOR SYS_ACCOUNT_CSR (p_entry_id IN NUMBER) IS
2837  SELECT TA.ACCOUNT_ID ACCOUNT_ID,
2838         TP.PARTY_SOURCE_ID PARTY_ID
2839    FROM CSI_T_PARTY_DETAILS TP,
2840     CSI_T_PARTY_ACCOUNTS TA     ,
2841     CSI_T_TXN_LINE_DETAILS CTLD ,
2842     CSI_MASS_EDIT_ENTRIES_VL CMEE
2843   WHERE CMEE.ENTRY_ID            = p_entry_id
2844     AND TA.TXN_PARTY_DETAIL_ID   = TP.TXN_PARTY_DETAIL_ID
2845     AND TP.TXN_LINE_DETAIL_ID    = CTLD.TXN_LINE_DETAIL_ID
2846     AND CTLD.TRANSACTION_LINE_ID = CMEE.TXN_LINE_ID
2847     AND CTLD.INSTANCE_ID         IS NOT NULL
2848     AND ROWNUM                   = 1;
2849 
2850  -- Bug 7350165
2851  --CURSOR SYS_CUST_CSR (p_party_id IN NUMBER, p_account_number IN NUMBER) IS
2852  --   SELECT CUST_ACCOUNT_ID  CUSTOMER_ID
2853  --     FROM HZ_CUST_ACCOUNTS
2854  --     WHERE PARTY_ID = p_party_id
2855  --        AND ACCOUNT_NUMBER = p_account_number;
2856 
2857  -- l_sys_cust_rec          SYS_CUST_CSR%ROWTYPE; bug 7350165
2858  l_sys_acct_rec          SYS_ACCOUNT_CSR%ROWTYPE;
2859  l_mu_sys_error_tbl      csi_mass_edit_pub.mass_edit_sys_error_tbl;
2860  l_errors_found              VARCHAR2(1) := 'N';
2861  l_warnings_found            VARCHAR2(1) := 'N';
2862 
2863  BEGIN
2864 
2865   debug('Inside VALIDATE_SYSTEM_BATCH');
2866 
2867   -- Validation logic
2868   x_return_status := FND_API.G_RET_STS_SUCCESS;
2869 
2870   OPEN   SYS_ACCOUNT_CSR (p_entry_id);
2871   FETCH  SYS_ACCOUNT_CSR INTO l_sys_acct_rec;
2872   CLOSE  SYS_ACCOUNT_CSR;
2873 
2874   -- Bug 7350165
2875   -- Fetch Customer id from party id and account id
2876  /* BEGIN
2877     OPEN   SYS_CUST_CSR (l_sys_acct_rec.Party_Id, l_sys_acct_rec.Account_Id);
2878     FETCH  SYS_CUST_CSR INTO l_sys_cust_rec;
2879     CLOSE  SYS_CUST_CSR;
2880   EXCEPTION
2881     WHEN NO_DATA_FOUND THEN
2882       fnd_message.set_name('CSI', 'CSI_CUSTOMER_ID_NOT_FOUND');
2883       fnd_message.set_token('PARTY_ID',l_sys_acct_rec.Party_Id);
2884       fnd_message.set_token('ACCOUNT_NUMBER',l_sys_acct_rec.Account_Id);
2885       fnd_msg_pub.add;
2886       RAISE FND_API.G_EXC_ERROR;
2887 
2888    WHEN TOO_MANY_ROWS THEN
2889       fnd_message.set_name('CSI', 'CSI_MULTIPLE_CUSTOMER_ID_FOUND');
2890       fnd_message.set_token('PARTY_ID',l_sys_acct_rec.Party_Id);
2891       fnd_message.set_token('ACCOUNT_NUMBER',l_sys_acct_rec.Account_Id);
2892       fnd_msg_pub.add;
2893       RAISE FND_API.G_EXC_ERROR;
2894    WHEN OTHERS THEN
2895       debug('In to Others Exception while finding customer id');
2896       RAISE FND_API.G_EXC_ERROR;
2897   END;
2898   */
2899   debug('Total Number of Systems qualifying for mass update - ' || p_upd_system_tbl.COUNT);
2900    IF p_upd_system_tbl.COUNT > 0 THEN
2901    FOR system_rec_ind IN p_upd_system_tbl.FIRST .. p_upd_system_tbl.LAST
2902    LOOP
2903 
2904       -- Validate the system with the transaction details
2905       -- The validation verify whether the system got updated after the batch has been created
2906       -- Following validations take place
2907       --
2908       -- 1. Whether the System is active or not - VLD_SYSTEM_ACTIVE
2909       -- 2. To check if the current owner of the system matches with the
2910       --    current owner for the batch - VLD_SYSTEM_CURRENT_OWNER
2911       -- 3. To check if the transfer ownership date doesnt exceed the sysdate
2912       --    and system termination date - VLD_SYSTEM_TERM_DATE
2913       -- 4. To check if the system location ids changed after batch was
2914       --    scheduled - VLD_SYSTEM_LOCATION_CHGD
2915 
2916       IF NVL(p_upd_system_tbl(system_rec_ind).SYSTEM_ID, FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM THEN
2917 
2918         -- Whether the System is active or not
2919         debug('Executing VLD_SYSTEM_ACTIVE');
2920         CSI_MASS_EDIT_PVT.VLD_SYSTEM_ACTIVE(
2921                  p_upd_system_tbl(system_rec_ind).SYSTEM_ID,
2922                  p_txn_line_id,
2923                  l_mu_sys_error_tbl);
2924 
2925         -- Checking current owner
2926         debug('Executing VLD_SYSTEM_CURRENT_OWNER');
2927         CSI_MASS_EDIT_PVT.VLD_SYSTEM_CURRENT_OWNER(
2928                  p_upd_system_tbl(system_rec_ind).SYSTEM_ID,
2929                  l_sys_acct_rec.Account_Id,
2930                  --l_sys_cust_rec.CUSTOMER_ID,
2931                  p_txn_line_id,
2932                  l_mu_sys_error_tbl);
2933 
2934         -- Checking Transfer ownerhips date doesnt exceed system termination date
2935         -- Commented since the system updation happens at sysdate
2936         -- and VLD_SYSTEM_ACTIVE would have checked this condition
2937         /*debug('Executing VLD_SYSTEM_TERM_DATE');
2938         CSI_MASS_EDIT_PVT.VLD_SYSTEM_TERM_DATE(
2939                  upd_system_tbl(system_rec_ind).SYSTEM_ID,
2940                  l_mu_sys_error_tbl); */
2941 
2942         -- Checking whether location id/contact id changed after batch was created
2943         -- This procedure is not implemented for the ER 6031179 as the locations will
2944         -- be cleared. But this is retained for future enhacenments
2945         -- This should check to make sure that location id hasnt changed since
2946         -- the batch was created. If it has changed an error message must be
2947         -- displayed
2948         debug('Executing VLD_SYSTEM_LOCATION_CHGD');
2949         CSI_MASS_EDIT_PVT.VLD_SYSTEM_LOCATION_CHGD(
2950                  p_upd_system_tbl(system_rec_ind).SYSTEM_ID,
2951                  p_txn_line_id,
2952                  l_mu_sys_error_tbl);
2953       END IF; -- NVL(l_system_rec.system_id, FND_API.G_MISS_NUM) <> FND_API.G_MISS_NUM
2954    END LOOP; -- system_rec_ind IN
2955    END IF; -- p_upd_system_tbl.COUNT
2956 
2957    -- Check the Error table
2958    IF l_mu_sys_error_tbl.count > 0 THEN
2959     debug('Total Number of errors after system validation: '||l_mu_sys_error_tbl.count);
2960     FOR f in l_mu_sys_error_tbl.first .. l_mu_sys_error_tbl.last LOOP
2961       IF (l_mu_sys_error_tbl(f).error_code = fnd_api.g_ret_sts_error AND
2962          l_errors_found = 'N') THEN
2963         l_errors_found := 'Y';
2964         debug('Errors found from system validation');
2965         debug('Error message: '||substr(l_mu_sys_error_tbl(f).ERROR_TEXT,1,length(l_mu_sys_error_tbl(f).ERROR_TEXT)));
2966 
2967         debug_out('Errors found from system validation');
2968         debug_out('Error message: '||substr(l_mu_sys_error_tbl(f).ERROR_TEXT,1,length(l_mu_sys_error_tbl(f).ERROR_TEXT)));
2969       ELSIF (l_mu_sys_error_tbl(f).error_code = 'W' AND
2970              l_warnings_found = 'N') THEN
2971         l_warnings_found := 'Y';
2972         debug('Warnings found from system validation');
2973         debug('Warning message: '||substr(l_mu_sys_error_tbl(f).ERROR_TEXT,1,length(l_mu_sys_error_tbl(f).ERROR_TEXT)));
2974 
2975         debug_out('Warnings found from system validation');
2976         debug_out('Warning message: '||substr(l_mu_sys_error_tbl(f).ERROR_TEXT,1,length(l_mu_sys_error_tbl(f).ERROR_TEXT)));
2977 
2978       END IF;
2979     END LOOP;
2980 
2981     IF (l_errors_found = 'Y' and l_warnings_found = 'Y' OR
2982         l_errors_found = 'Y' and l_warnings_found = 'N') THEN
2983       debug('Errors found from VALIDATE_SYSTEM_BATCH and raising FND_API.G_EXC_ERROR');
2984       RAISE FND_API.G_EXC_ERROR;
2985     ELSIF (l_errors_found = 'N' and l_warnings_found = 'Y') THEN
2986       x_return_status       := 'W';
2987     END IF;
2988     debug('Return Status from VALIDATE_SYSTEM_BATCH: '||x_return_status);
2989     ELSE
2990         x_return_status := fnd_api.g_ret_sts_success;
2991     END IF;
2992 
2993   EXCEPTION
2994     WHEN FND_API.G_EXC_ERROR THEN
2995           debug('Encountered FND_API.G_EXC_ERROR in VALIDATE_SYSTEM_BATCH');
2996           x_return_status := FND_API.G_RET_STS_ERROR ;
2997     WHEN OTHERS THEN
2998           debug('Encountered WHEN OTHERS in VALIDATE_SYSTEM_BATCH');
2999           debug( to_char(SQLCODE)||substr(SQLERRM, 1, 255));
3000           x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
3001 
3002 END VALIDATE_SYSTEM_BATCH; -- VALIDATE_SYSTEM_BATCH
3003 
3004 
3005 
3006 --Updated the csi_mass_edit_entries_b table with status_code to SCHEDULED from status CREATED
3007 --This program is called from CSI_MASS_EDIT_PUB.Process_mass_edit_batch
3008 PROCEDURE Process_webadi_batch
3009    ( errbuf                       OUT NOCOPY    VARCHAR2
3010     ,retcode                      OUT NOCOPY    NUMBER
3011     ,p_Entry_id                   IN     NUMBER
3012 	,p_batch_type             	  IN	 VARCHAR2
3013 	,p_schedule_date          	  DATE
3014    ) IS
3015 
3016 
3017     px_csi_txn_rec			csi_datastructures_pub.transaction_rec;
3018 	l_return_status			varchar2(1) := fnd_api.g_ret_sts_success;
3019 	l_msg_count				number;
3020 	l_msg_data				varchar2(2000);
3021 	l_Error_Message			varchar2(2000);
3022 	l_crt_count         	number;
3023 	l_updt_count        	number;
3024 	l_inst_count			number;
3025 	l_msg_index     		NUMBER;
3026 
3027 BEGIN
3028 	debug('Start procedure: Process_webadi_batch');
3029 	-- Setting the Batch Status to 'Processing'
3030 
3031 	BEGIN
3032 		UPDATE CSI_WEBADI_STAGING
3033 		SET PROCESSING_STATUS = 'P'
3034 		WHERE BATCH_ID = p_entry_id;
3035 
3036 		UPDATE csi_mass_edit_entries_b
3037 		SET    status_code = 'PROCESSING',
3038 			   request_id  = FND_GLOBAL.CONC_REQUEST_ID
3039 		WHERE  entry_id = p_entry_id;
3040 		COMMIT;
3041 	EXCEPTION
3042 		WHEN OTHERS THEN
3043 			debug('Exception while either updating the records to processed(P) status, ' ||
3044 					'or updating the batch to PROCESSING status');
3045 			debug('Error: ' || to_char(SQLCODE)||substr(SQLERRM, 1, 255));
3046 	END;
3047 
3048 	Populate_WebAdi_Ids
3049 	   (errbuf		=>	errbuf,
3050 	    retcode		=>	retcode,
3051 	    p_Entry_id	=>	p_Entry_id
3052 		);
3053 
3054 	SELECT Count(*) INTO l_crt_count
3055 	FROM CSI_WEBADI_STAGING
3056 		where BATCH_ID = p_entry_id
3057 		and INSTANCE_ID is null;
3058 
3059 	SELECT Count(*) INTO l_updt_count
3060 	FROM CSI_WEBADI_STAGING
3061 		where BATCH_ID = p_entry_id
3062 		and INSTANCE_ID is NOT null;
3063 
3064 	l_inst_count :=  l_crt_count + l_updt_count;
3065 
3066 
3067 	--Validations
3068 	--Add Code for validations
3069 
3070 	px_csi_txn_rec.transaction_date        :=  sysdate;
3071 	px_csi_txn_rec.source_transaction_date :=  p_schedule_date;
3072 	px_csi_txn_rec.transaction_type_id     :=  3; --verify if this is the transaction id, 3 is for mass edit
3073 	--px_csi_txn_rec.transacted_by           :=  created_by;	--how to get created by?
3074 	px_csi_txn_rec.transaction_status_code :=  'COMPLETE';
3075 	px_csi_txn_rec.object_version_number   :=  1;
3076 	   px_csi_txn_rec.source_header_ref_id        := p_entry_id;
3077 	   px_csi_txn_rec.source_group_ref           := p_batch_type;
3078 
3079 
3080 
3081 	csi_transactions_pvt.create_transaction(
3082 		p_api_version            => 1.0,
3083 		p_commit                 => fnd_api.g_false,
3084 		p_init_msg_list          => fnd_api.g_true,
3085 		p_validation_level       => fnd_api.g_valid_level_full,
3086 		p_success_if_exists_flag => 'Y',
3087 		p_transaction_rec        => px_csi_txn_rec,
3088 		x_return_status          => l_return_status,
3089 		x_msg_count              => l_msg_count,
3090 		x_msg_data               => l_msg_data);
3091 
3092 	IF l_return_status <> fnd_api.g_ret_sts_success THEN
3093 		debug_out('The transaction record creation failed, please look into Request log for detailed error');
3094 		debug('Call to csi_transactions_pvt.create_transaction not successful');
3095 		l_msg_index := 1;
3096 		l_Error_Message := l_msg_data;
3097 		WHILE l_msg_count > 0 LOOP
3098 			l_Error_Message := FND_MSG_PUB.GET(l_msg_index, FND_API.G_FALSE);
3099 			l_msg_index := l_msg_index + 1;
3100 			l_msg_count := l_msg_count - 1;
3101 			debug_out('Error: ' || l_Error_Message);
3102 		END LOOP;
3103 	END IF;
3104 
3105 		--debug_out('****************** Dummy Output Just for Demo *****************************');
3106 	debug_out(' ');
3107 	debug_out('Total Item Instance records processed: ' || l_inst_count );
3108 	debug_out('No.of records submitted for creation : ' || l_crt_count);
3109 	debug_out('No.of records submitted for update : ' || l_updt_count);
3110 	debug_out(' ');
3111 	--debug_out('No.of records successfully created : ' || (l_crt_count - l_crt_fld_count));
3112 	--debug_out('No.of create records failed : ' || l_crt_fld_count);
3113 	--debug_out(' ');
3114 	--debug_out('No.of records successfully updated : ' || (l_updt_count - l_updt_fld_count));
3115 	--debug_out('No.of update records failed : ' || l_update_fld_count);
3116 
3117 	IF(l_crt_count > 0)
3118 	THEN
3119 		Process_webadi_create(errbuf, retcode, p_Entry_id, px_csi_txn_rec);
3120 	END IF;
3121 
3122 	IF(l_updt_count > 0)
3123 	THEN
3124 		Process_webadi_update(errbuf, retcode, p_Entry_id, px_csi_txn_rec);
3125 	END IF;
3126 
3127 	IF(errbuf = 'E') THEN
3128 		UPDATE csi_mass_edit_entries_b
3129 		SET    status_code = 'FAILED'
3130 		WHERE  entry_id = p_entry_id;
3131 		COMMIT;
3132 	ELSE
3133 		UPDATE csi_mass_edit_entries_b
3134 		SET    status_code = 'SUCCESSFUL'
3135 		WHERE  entry_id = p_entry_id;
3136 		COMMIT;
3137 	END IF;
3138 
3139 	debug('End procedure: Process_webadi_batch');
3140 EXCEPTION
3141 	WHEN OTHERS THEN
3142 		debug_out('Encountered unexpected error while processing Web ADI batch. '||
3143 									'Please check the request log for error details');
3144 		debug('Encountered unexpected exception in Process_webadi_batch.');
3145 		debug('Unexpected error: ' || to_char(SQLCODE)||substr(SQLERRM, 1, 255));
3146 		errbuf := 'E';
3147 End Process_webadi_batch;
3148 
3149 
3150 PROCEDURE Process_webadi_create
3151    ( errbuf                       OUT NOCOPY    VARCHAR2
3152     ,retcode                      OUT NOCOPY    NUMBER
3153     ,p_Entry_id                   IN     NUMBER
3154 	,p_csi_txn_rec				  IN OUT NOCOPY csi_datastructures_pub.transaction_rec
3155    ) IS
3156 
3157     CURSOR instances_for_create_csr(p_entry_id IN NUMBER) IS
3158 		SELECT
3159 			ITEM_ID,
3160 			ITEM_NUMBER ,
3161 			INSTANCE_ID,
3162 			PRODUCT_NUMBER,
3163 			INSTANCE_DESCRIPTION,
3164 			ITEM_REV,
3165 			UOM,
3166 			QUANTITY,
3167 			SERIAL_NUMBER ,
3168 			LOT_NUMBER ,
3169 			ORGANIZATION,
3170 			LAST_VLD_ORGANIZATION_ID,
3171 			INSTANCE_STATUS_ID,
3172 			EXTERNAL_REF ,
3173 			OPERATIONAL_STATUS_CODE ,
3174 			INTERNALLY_OWNED,
3175 			OWNER_PARTY_SOURCE_TABLE ,
3176 			OWNER_PARTY_TYPE ,
3177 			OWNER_PARTY_NUM,
3178 			OWNER_NAME,
3179 			OWNER_ACCOUNT_NUMBER ,
3180 			OWNER_ID,
3181 			OWNER_ACCOUNT_ID,
3182 			OBJECT_VERSION_NUMBER,
3183 			PRODUCT_TYPE_CODE ,
3184 			INSTALL_DATE,
3185 			VERSION_LABEL ,
3186 			CREATION_DATE,
3187 			ACTIVE_START_DATE,
3188 			EXPIRATION_DATE ,
3189 			CONTRACT_NUMBER ,
3190 			PARENT_INSTANCE ,
3191 			ASSOCIATE_BILL_TO_PARTY_TYPE,
3192 			ASSOCIATE_BILL_TO_PARTY_NUMBER,
3193 			ASSOCIATE_BILL_TO_PARTY_NAME,
3194 			ASSOCIATE_BILL_TO_PARTY_ID,
3195 			ASSOCIATE_BILL_TO_ACCT_NUM,
3196 			ASSOCIATE_BILL_TO_ACCT_ID,
3197 			ASSOCIATE_SHIP_TO_PARTY_TYPE,
3198 			ASSOCIATE_SHIP_TO_PARTY_NUMBER,
3199 			ASSOCIATE_SHIP_TO_PARTY_NAME,
3200 			ASSOCIATE_SHIP_TO_PARTY_ID,
3201 			ASSOCIATE_SHIP_TO_ACCT_NUM,
3202 			ASSOCIATE_SHIP_TO_ACCT_ID,
3203 			BILL_TO_LOC_ID,
3204 			SHIP_TO_LOC_ID ,
3205 			LOCATION_ID,
3206 			LOCATION_TYPE_CODE ,
3207 			INSTALL_LOCATION_ID,
3208 			INSTALL_LOCATION_TYPE_CODE ,
3209 			ASSOCIATE_CONTRACT_ID,
3210 			ASSOCIATE_CONTRACT_NUMBER,
3211 			ASSOCIATE_CONTRACT_MODIFIER,
3212 			ASSOCIATE_SERVICE_LINE,
3213 			ASSOCIATE_SERVICE_LINE_ID,
3214 			CREATE_CONTRACT,
3215 			SYSTEM_ID,
3216 			SYSTEM_NAME,
3217 			Pricing_context,
3218 			Pricing_attribute1,
3219 			Pricing_attribute2,
3220 			Pricing_attribute3,
3221 			Pricing_attribute4,
3222 			Pricing_attribute5,
3223 			Pricing_attribute6,
3224 			Pricing_attribute7,
3225 			Pricing_attribute8,
3226 			Pricing_attribute9,
3227 			Pricing_attribute10,
3228 			Pricing_attribute11,
3229 			Pricing_attribute12,
3230 			Pricing_attribute13,
3231 			Pricing_attribute14,
3232 			Pricing_attribute15,
3233 			Pricing_attribute16,
3234 			Pricing_attribute17,
3235 			Pricing_attribute18,
3236 			Pricing_attribute19,
3237 			Pricing_attribute20,
3238 			Pricing_attribute21,
3239 			Pricing_attribute22,
3240 			Pricing_attribute23,
3241 			Pricing_attribute24,
3242 			Pricing_attribute25,
3243 			Pricing_attribute26,
3244 			Pricing_attribute27,
3245 			Pricing_attribute28,
3246 			Pricing_attribute29,
3247 			Pricing_attribute30,
3248 			Pricing_attribute31,
3249 			Pricing_attribute32,
3250 			Pricing_attribute33,
3251 			Pricing_attribute34,
3252 			Pricing_attribute35,
3253 			Pricing_attribute36,
3254 			Pricing_attribute37,
3255 			Pricing_attribute38,
3256 			Pricing_attribute39,
3257 			Pricing_attribute40,
3258 			Pricing_attribute41,
3259 			Pricing_attribute42,
3260 			Pricing_attribute43,
3261 			Pricing_attribute44,
3262 			Pricing_attribute45,
3263 			Pricing_attribute46,
3264 			Pricing_attribute47,
3265 			Pricing_attribute48,
3266 			Pricing_attribute49,
3267 			Pricing_attribute50,
3268 			Pricing_attribute51,
3269 			Pricing_attribute52,
3270 			Pricing_attribute53,
3271 			Pricing_attribute54,
3272 			Pricing_attribute55,
3273 			Pricing_attribute56,
3274 			Pricing_attribute57,
3275 			Pricing_attribute58,
3276 			Pricing_attribute59,
3277 			Pricing_attribute60,
3278 			Pricing_attribute61,
3279 			Pricing_attribute62,
3280 			Pricing_attribute63,
3281 			Pricing_attribute64,
3282 			Pricing_attribute65,
3283 			Pricing_attribute66,
3284 			Pricing_attribute67,
3285 			Pricing_attribute68,
3286 			Pricing_attribute69,
3287 			Pricing_attribute70,
3288 			Pricing_attribute71,
3289 			Pricing_attribute72,
3290 			Pricing_attribute73,
3291 			Pricing_attribute74,
3292 			Pricing_attribute75,
3293 			Pricing_attribute76,
3294 			Pricing_attribute77,
3295 			Pricing_attribute78,
3296 			Pricing_attribute79,
3297 			Pricing_attribute80,
3298 			Pricing_attribute81,
3299 			Pricing_attribute82,
3300 			Pricing_attribute83,
3301 			Pricing_attribute84,
3302 			Pricing_attribute85,
3303 			Pricing_attribute86,
3304 			Pricing_attribute87,
3305 			Pricing_attribute88,
3306 			Pricing_attribute89,
3307 			Pricing_attribute90,
3308 			Pricing_attribute91,
3309 			Pricing_attribute92,
3310 			Pricing_attribute93,
3311 			Pricing_attribute94,
3312 			Pricing_attribute95,
3313 			Pricing_attribute96,
3314 			Pricing_attribute97,
3315 			Pricing_attribute98,
3316 			Pricing_attribute99,
3317 			Pricing_attribute100,
3318 			BATCH_ID,
3319 			CONTEXT,
3320 			ATTRIBUTE1,
3321 			ATTRIBUTE2,
3322 			ATTRIBUTE3,
3323 			ATTRIBUTE4,
3324 			ATTRIBUTE5,
3325 			ATTRIBUTE6,
3326 			ATTRIBUTE7,
3327 			ATTRIBUTE8,
3328 			ATTRIBUTE9,
3329 			ATTRIBUTE10,
3330 			ATTRIBUTE11,
3331 			ATTRIBUTE12,
3332 			ATTRIBUTE13,
3333 			ATTRIBUTE14,
3334 			ATTRIBUTE15,
3335 			ATTRIBUTE16,
3336 			ATTRIBUTE17,
3337 			ATTRIBUTE18,
3338 			ATTRIBUTE19,
3339 			ATTRIBUTE20,
3340 			ATTRIBUTE21,
3341 			ATTRIBUTE22,
3342 			ATTRIBUTE23,
3343 			ATTRIBUTE24,
3344 			ATTRIBUTE25,
3345 			ATTRIBUTE26,
3346 			ATTRIBUTE27,
3347 			ATTRIBUTE28,
3348 			ATTRIBUTE29,
3349 			ATTRIBUTE30
3350 		FROM CSI_WEBADI_STAGING
3351 		where BATCH_ID = p_entry_id
3352 		and INSTANCE_ID is null;
3353 
3354 		c_instance_tbl			csi_datastructures_pub.instance_tbl;
3355 		c_ext_attrib_values_tbl	csi_datastructures_pub.extend_attrib_values_tbl;
3356 	    c_party_tbl				csi_datastructures_pub.party_tbl;
3357 	    c_account_tbl			csi_datastructures_pub.party_account_tbl;
3358 	    c_pricing_attrib_tbl	csi_datastructures_pub.pricing_attribs_tbl;
3359 	    c_org_assignments_tbl	csi_datastructures_pub.organization_units_tbl;
3360 	    c_instance_asset_tbl	csi_datastructures_pub.instance_asset_tbl;
3361 	    c_csi_txn_tbl			csi_datastructures_pub.transaction_tbl;
3362 	    c_grp_error_tbl         csi_datastructures_pub.grp_error_tbl;
3363 	    l_instance        		instances_for_create_csr%ROWTYPE;
3364 		c_relationship_tbl      csi_datastructures_pub.ii_relationship_tbl;
3365 		l_relationship_tbl 		csi_datastructures_pub.ii_relationship_tbl;
3366 		c_pricing_attribs_tbl	csi_datastructures_pub.pricing_attribs_tbl;
3367 		TYPE number_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
3368 		l_chr_id_tbl			number_tbl;
3369 		l_attach2_line_id_tbl	number_tbl;
3370 		l_covlvl_id				NUMBER;
3371 		l_cov_line_tbl			OKS_IBINT_PUB.k_cov_line_tbl;
3372 		l_log_tbl				csi_mass_edit_pub.log_tbl;
3373 		l_par_instance_id		NUMBER;
3374 		l_return_status			varchar2(1) := fnd_api.g_ret_sts_success;
3375 		l_crt_return_status		varchar2(1) := fnd_api.g_ret_sts_success;
3376 		l_msg_count				number;
3377 		l_msg_data				varchar2(2000);
3378 		l_msg_index     		NUMBER;
3379 		l_error_message 		VARCHAR2(2000);
3380 		inst_idx            	PLS_INTEGER;
3381 		rel_idx            		PLS_INTEGER;
3382 		l_rel_idx            	PLS_INTEGER;
3383 		oks_idx					PLS_INTEGER;
3384 		xls_idx					PLS_INTEGER;
3385 		c_pa_idx				PLS_INTEGER;
3386 		l_internal_party_id		NUMBER;
3387 		l_falied_count			NUMBER	:=0;
3388 		party_idx 				NUMBER;
3389 		account_idx				NUMBER;
3390 		isRecValid				BOOLEAN;
3391 		l_crt_count				NUMBER;
3392 		l_batch_desc			Varchar2(2000);
3393 		l_note_id               NUMBER;
3394 		l_rec_idx				NUMBER;
3395 
3396 BEGIN
3397 	debug('Start procedure: Process_webadi_create');
3398 	inst_idx	:= 0;
3399 	rel_idx		:= 0;
3400 	l_rel_idx	:= 0;
3401 	party_idx	:= 0;
3402 	account_idx	:= 0;
3403 	oks_idx		:= 0;
3404 	xls_idx		:= 0;
3405 	c_pa_idx		:= 0;
3406 
3407 	--CREATE PROCESSING STARTS
3408 	--Retrieving batch description
3409 	BEGIN
3410 		Select DESCRIPTION
3411 		into l_batch_desc
3412 		FROM csi_mass_edit_entries_vl
3413 		where ENTRY_ID = p_Entry_id;
3414 	EXCEPTION
3415 		WHEN no_data_found then
3416 			debug('Batch not found when trying to get its description.');
3417 			debug_out('The Mass update batch is not found. So the create records are not processed.');
3418 			RETURN;
3419 	END;
3420 	--Traversing through the cursor and processing for each instance to create
3421 	FOR l_instance IN instances_for_create_csr(p_entry_id)
3422 	LOOP
3423 		--Validations
3424 		isRecValid := true;
3425 		xls_idx := xls_idx + 1;
3426 
3427 		--Validating Organization
3428 		IF(l_instance.LAST_VLD_ORGANIZATION_ID IS NULL) THEN
3429 			IF(l_instance.ORGANIZATION IS NULL) THEN
3430 				debug_out('In the uploaded create record #' || xls_idx ||
3431 					'. Value not entered for Mandatory column: Organization.');
3432 				isRecValid := false;
3433 			ELSE
3434 				debug_out('In the uploaded create record #' || xls_idx || '. Invalid value for column: Organization.');
3435 				isRecValid := false;
3436 			END IF;
3437 		END IF;
3438 
3439 		--Validating Item
3440 		IF(l_instance.ITEM_ID IS NULL) THEN
3441 			IF(l_instance.ITEM_NUMBER IS NULL) THEN
3442 				debug_out('In the uploaded create record #' || xls_idx ||
3443 					'. Value not entered for Mandatory column: Item Number.');
3444 				isRecValid := false;
3445 			ELSE
3446 				debug_out('In the uploaded create record #' || xls_idx || '. Invalid value for column: Item Number');
3447 				isRecValid := false;
3448 			END IF;
3449 		END IF;
3450 
3451 		--Validating Owner party
3452 		IF(l_instance.OWNER_ID IS NULL AND
3453 			nvl(l_instance.OWNER_PARTY_TYPE, fnd_api.g_miss_char) <> 'HZ_PARTIES' AND
3454 			nvl(l_instance.INTERNALLY_OWNED, 'N') = 'N') THEN
3455 			IF(l_instance.OWNER_PARTY_NUM IS NOT NULL AND l_instance.OWNER_NAME IS NOT NULL) THEN
3456 				debug_out('In the uploaded create record #' || xls_idx ||
3457 						'. For Employee/Vendor party type, Invalid Value(s) or invaid ' ||
3458 						'combination of values for: Owner Party Num, Owner Name.');
3459 				isRecValid := false;
3460 			ELSE
3461 				IF(l_instance.OWNER_PARTY_NUM IS NULL) THEN
3462 					IF(l_instance.OWNER_NAME IS NULL) THEN
3463 						debug_out('In the uploaded create record #' || xls_idx ||
3464 							'. For Employee/Vendor party type, value not entered for ' ||
3465 							'Mandatory columns: Owner Party Num, Owner Name.');
3466 						isRecValid := false;
3467 					ELSE
3468 					debug_out('In the uploaded create record #' || xls_idx ||
3469 							'. For Employee/Vendor party type, value not entered for ' ||
3470 							'Mandatory column: Owner Party Num.');
3471 					isRecValid := false;
3472 					END IF;
3473 				ELSE
3474 					debug_out('In the uploaded create record #' || xls_idx ||
3475 							'. For Employee/Vendor party type, value not entered for ' ||
3476 							'Mandatory column: Owner Name.');
3477 					isRecValid := false;
3478 				END IF;
3479 			END IF;
3480 		ELSE
3481 			debug('Validation for Owner details is not required.');
3482 		END IF;
3483 
3484 		IF(l_instance.OWNER_ID IS NULL AND l_instance.OWNER_PARTY_TYPE = 'HZ_PARTIES') THEN
3485 			IF(l_instance.OWNER_PARTY_NUM IS NULL) THEN
3486 				debug_out('In the uploaded create record #' || xls_idx ||
3487 					'. Value not entered for column: Owner Party Num.');
3488 				isRecValid := false;
3489 			ELSE
3490 				debug_out('In the uploaded create record #' || xls_idx ||
3491 					'. Invalid value entered for column: Owner Party Num.');
3492 				isRecValid := false;
3493 			END IF;
3494 		END IF;
3495 
3496 		--Validating Owner account
3497 		IF(l_instance.OWNER_ACCOUNT_ID IS NULL) THEN
3498 			IF(l_instance.OWNER_ACCOUNT_NUMBER IS NOT NULL) THEN
3499 				debug_out('In the uploaded create record #' || xls_idx ||
3500 					'. Invalid value for column: Owner Account Number');
3501 				isRecValid := false;
3502 			ELSIF(l_instance.OWNER_PARTY_TYPE = 'HZ_PARTIES') THEN
3503 					debug_out('In the uploaded create record #' || xls_idx ||
3504 						'. Value not entered for Mandatory column: Owner Account Number.');
3505 					isRecValid := false;
3506 			END IF;
3507 		END IF;
3508 
3509 		--Validation of current location type
3510 		IF(l_instance.LOCATION_TYPE_CODE IS NULL) THEN
3511 			debug_out('In the uploaded create record #' || xls_idx ||
3512 				'. Value not entered for Mandatory column: Location Type Code.');
3513 			isRecValid := false;
3514 		END IF;
3515 
3516 		--Validation of current location
3517 		IF(l_instance.LOCATION_ID IS NULL) THEN
3518 			debug_out('In the uploaded create record #' || xls_idx ||
3519 				'. Value not entered for Mandatory column: Location Id.');
3520 			isRecValid := false;
3521 		END IF;
3522 
3523 
3524 		--Validating Bill To Party
3525 		IF(l_instance.ASSOCIATE_BILL_TO_PARTY_ID IS NULL
3526 		AND l_instance.ASSOCIATE_BILL_TO_PARTY_TYPE IS NOT NULL
3527 		AND l_instance.ASSOCIATE_BILL_TO_PARTY_TYPE <> 'HZ_PARTIES') THEN
3528 			IF(l_instance.ASSOCIATE_BILL_TO_PARTY_NUMBER IS NOT NULL
3529 				AND l_instance.ASSOCIATE_BILL_TO_PARTY_NAME IS NOT NULL) THEN
3530 					debug_out('In the uploaded create record #' || xls_idx ||
3531 							'. For Employee/Vendor party type, invalid Value(s) ' ||
3532 							'or invaid combination of values for: ' ||
3533 							'Associate Bill To Party Number, Associate Bill To Party Name.');
3534 					isRecValid := false;
3535 			ELSE
3536 				IF(l_instance.ASSOCIATE_BILL_TO_PARTY_NUMBER IS NULL
3537 					AND l_instance.ASSOCIATE_BILL_TO_PARTY_NAME IS NOT NULL) THEN
3538 						debug_out('In the uploaded create record #' || xls_idx ||
3539 								'. For Employee/Vendor party type, value not entered for' ||
3540 								' column: Associate Bill To Party Number.');
3541 					isRecValid := false;
3542 				ELSIF(l_instance.ASSOCIATE_BILL_TO_PARTY_NUMBER IS NOT NULL
3543 					AND l_instance.ASSOCIATE_BILL_TO_PARTY_NAME IS NULL) THEN
3544 					debug_out('In the uploaded create record #' || xls_idx ||
3545 							'. For Employee/Vendor party type, value not entered for ' ||
3546 							'column: Associate Bill To Party Name.');
3547 					isRecValid := false;
3548 				END IF;
3549 			END IF;
3550 		END IF;
3551 
3552 		IF(l_instance.ASSOCIATE_BILL_TO_PARTY_ID IS NULL
3553 		AND l_instance.ASSOCIATE_BILL_TO_PARTY_TYPE = 'HZ_PARTIES'
3554 		AND l_instance.ASSOCIATE_BILL_TO_PARTY_NUMBER IS NOT NULL) THEN
3555 			debug_out('In the uploaded create record #' || xls_idx ||
3556 					'. Invalid value entered for column: Associate Bill To Party Number.');
3557 			isRecValid := false;
3558 		END IF;
3559 
3560 		--Validating Bill To account
3561 		IF(l_instance.ASSOCIATE_BILL_TO_ACCT_ID IS NULL
3562 			AND l_instance.ASSOCIATE_BILL_TO_ACCT_NUM IS NOT NULL) THEN
3563 				debug_out('In the uploaded create record #' || xls_idx ||
3564 					'. Invalid value for column: Associate Bill To Acct Num');
3565 				isRecValid := false;
3566 		END IF;
3567 
3568 		--Validating if there is a Bill To account provided without a Bill To party
3569 		IF(l_instance.ASSOCIATE_BILL_TO_ACCT_NUM IS NOT NULL
3570 			AND l_instance.ASSOCIATE_BILL_TO_PARTY_ID IS NULL) THEN
3571 				debug_out('In the uploaded create record #' || xls_idx ||
3572 						'. The column, Associate Bill To Acct Num, cannot be used without a valid' ||
3573 						' value in the columns: Associate Bill To Party Number, Associate Bill To Party Name');
3574 				isRecValid := false;
3575 		END IF;
3576 
3577 		--Validating Ship To Party
3578 		IF(l_instance.ASSOCIATE_SHIP_TO_PARTY_ID IS NULL
3579 		AND l_instance.ASSOCIATE_SHIP_TO_PARTY_TYPE IS NOT NULL
3580 		AND l_instance.ASSOCIATE_SHIP_TO_PARTY_TYPE <> 'HZ_PARTIES') THEN
3581 			IF(l_instance.ASSOCIATE_SHIP_TO_PARTY_NUMBER IS NOT NULL
3582 			AND l_instance.ASSOCIATE_SHIP_TO_PARTY_NAME IS NOT NULL) THEN
3583 				debug_out('In the uploaded update record #' || xls_idx ||
3584 						'. For Employee/Vendor party type, Invalid Value(s) or invaid' ||
3585 						' combination of values for: ' ||
3586 						'Associate Ship To Party Number, Associate Ship To Party Name.');
3587 				isRecValid := false;
3588 			ELSE
3589 				IF(l_instance.ASSOCIATE_SHIP_TO_PARTY_NUMBER IS NULL
3590 					AND l_instance.ASSOCIATE_SHIP_TO_PARTY_NAME IS NOT NULL) THEN
3591 						debug_out('In the uploaded update record #' || xls_idx ||
3592 								'. For Employee/Vendor party type, value not entered for' ||
3593 								' column: Associate Ship To Party Number.');
3594 						isRecValid := false;
3595 				ELSIF(l_instance.ASSOCIATE_SHIP_TO_PARTY_NUMBER IS NOT NULL
3596 					AND l_instance.ASSOCIATE_SHIP_TO_PARTY_NAME IS NULL) THEN
3597 					debug_out('In the uploaded update record #' || xls_idx ||
3598 							'. For Employee/Vendor party type, value not entered for ' ||
3599 							'column: Associate Ship To Party Name.');
3600 					isRecValid := false;
3601 				END IF;
3602 			END IF;
3603 		END IF;
3604 
3605 		IF(l_instance.ASSOCIATE_SHIP_TO_PARTY_ID IS NULL
3606 		AND l_instance.ASSOCIATE_SHIP_TO_PARTY_TYPE = 'HZ_PARTIES'
3607 		AND l_instance.ASSOCIATE_SHIP_TO_PARTY_NUMBER IS NOT NULL) THEN
3608 			debug_out('In the uploaded update record #' || xls_idx ||
3609 					'. Invalid value entered for column: Associate Ship To Party Number.');
3610 			isRecValid := false;
3611 		END IF;
3612 
3613 		--Validating Ship To account
3614 		IF(l_instance.ASSOCIATE_SHIP_TO_ACCT_ID IS NULL
3615 			AND l_instance.ASSOCIATE_SHIP_TO_ACCT_NUM IS NOT NULL) THEN
3616 				debug_out('In the uploaded create record #' || xls_idx ||
3617 					'. Invalid value for column: Associate Ship To Acct Num');
3618 				isRecValid := false;
3619 		END IF;
3620 
3621 		--Validating if there is a Ship To account provided without a Ship To party
3622 		IF(l_instance.ASSOCIATE_SHIP_TO_ACCT_NUM IS NOT NULL
3623 			AND l_instance.ASSOCIATE_SHIP_TO_PARTY_ID IS NULL) THEN
3624 				debug_out('In the uploaded create record #' || xls_idx ||
3625 						'. The column, Associate Ship To Acct Num, cannot be used without a valid' ||
3626 						' value in the columns: Associate Ship To Party Number, Associate Ship To Party Name');
3627 				isRecValid := false;
3628 		END IF;
3629 
3630 		--Validation Associate Contract Number
3631 		IF(l_instance.ASSOCIATE_CONTRACT_ID IS NULL
3632 			AND (l_instance.ASSOCIATE_CONTRACT_NUMBER IS NOT NULL OR l_instance.ASSOCIATE_CONTRACT_MODIFIER IS NOT NULL)) THEN
3633 				debug_out('In the uploaded create record #' || xls_idx ||
3634 					'. Invalid value/combination of values for columns: Associate Contract Number, Associate Contract Modifier');
3635 				isRecValid := false;
3636 		END IF;
3637 
3638 		--Validating Service line
3639 		IF(l_instance.ASSOCIATE_SERVICE_LINE_ID IS NULL
3640 			AND l_instance.ASSOCIATE_SERVICE_LINE IS NOT NULL) THEN
3641 				debug_out('In the uploaded create record #' || xls_idx ||
3642 					'. Invalid value for column: Associate Service Line');
3643 				isRecValid := false;
3644 		END IF;
3645 
3646 		--Validating if there is a Service line provided without a Contract
3647 		IF(l_instance.ASSOCIATE_SERVICE_LINE IS NOT NULL
3648 			AND l_instance.ASSOCIATE_CONTRACT_ID IS NULL) THEN
3649 				debug_out('In the uploaded create record #' || xls_idx ||
3650 						'. The column, Associate Service Line, cannot be used without a valid' ||
3651 						' value in the columns: Associate Contract Number, Associate Contract Modifier');
3652 				isRecValid := false;
3653 		END IF;
3654 
3655 		--Validating if there is a  Contract provided without a Service line
3656 		IF(l_instance.ASSOCIATE_CONTRACT_ID IS NOT NULL
3657 			AND l_instance.ASSOCIATE_SERVICE_LINE IS NULL) THEN
3658 				debug_out('In the uploaded create record #' || xls_idx ||
3659 						'. The column, Associate Service Line should be provided ' ||
3660 						' for the contract, specified with Associate Contract Number and Associate Contract Modifier');
3661 				isRecValid := false;
3662 		END IF;
3663 
3664 		--Validating System
3665 		IF(l_instance.SYSTEM_ID IS NULL
3666 			AND l_instance.SYSTEM_NAME IS NOT NULL) THEN
3667 				debug_out('In the uploaded create record #' || xls_idx ||
3668 					'. Invalid value for column: System Name');
3669 				isRecValid := false;
3670 		END IF;
3671 
3672 		--Retrieving Instance ID for the parant
3673 		l_par_instance_id := null;
3674 		IF(l_instance.PARENT_INSTANCE IS NOT NULL) THEN
3675 			BEGIN
3676 				SELECT instance_id INTO l_par_instance_id
3677 				FROM csi_item_instances
3678 				WHERE instance_number = l_instance.PARENT_INSTANCE;
3679 			EXCEPTION
3680 				when no_data_found then
3681 					debug_out('In the uploaded create record #' || xls_idx ||
3682 						'. Invalid value for column: Parent Instance');
3683 					isRecValid := false;
3684 			END;
3685 		END IF;
3686 
3687 		--Validating Operational Status Code
3688 		IF(nvl(l_instance.OPERATIONAL_STATUS_CODE, FND_API.G_MISS_CHAR) <> 'NOT_USED') THEN
3689 				debug_out('In the uploaded create record #' || xls_idx ||
3690 					'. Only the value, NOT_USED is supported for column: Operational Status Code');
3691 				isRecValid := false;
3692 		END IF;
3693 
3694 		--Validations end, processing starts
3695 
3696 		IF(NOT isRecValid) THEN
3697 			debug_out('The uploaded create record #' || xls_idx ||
3698 				' is not processed due to the failure of the above mentioned validation(s).');
3699 			l_falied_count := l_falied_count + 1;
3700 
3701 		ELSE
3702 			--Processing of the valid records
3703 			inst_idx := inst_idx + 1;
3704 			debug('Processing Instance Record ' || inst_idx || ' for Create');
3705 
3706 			c_instance_tbl(inst_idx).INSTANCE_NUMBER   		:= l_instance.PRODUCT_NUMBER;
3707 			c_instance_tbl(inst_idx).INSTANCE_DESCRIPTION   := l_instance.INSTANCE_DESCRIPTION;
3708 			c_instance_tbl(inst_idx).VLD_ORGANIZATION_ID 	:= l_instance.LAST_VLD_ORGANIZATION_ID;
3709 			c_instance_tbl(inst_idx).INSTANCE_ID       		:= NULL;
3710 			c_instance_tbl(inst_idx).INVENTORY_ITEM_ID 		:= l_instance.ITEM_ID;
3711 			c_instance_tbl(inst_idx).LOCATION_TYPE_CODE 	:= l_instance.LOCATION_TYPE_CODE;
3712 			c_instance_tbl(inst_idx).LOCATION_ID 			:=  l_instance.LOCATION_ID;
3713 			c_instance_tbl(inst_idx).OBJECT_VERSION_NUMBER 	:= l_instance.OBJECT_VERSION_NUMBER;
3714 			c_instance_tbl(inst_idx).LOT_NUMBER 			:= l_instance.LOT_NUMBER;
3715 			c_instance_tbl(inst_idx).SERIAL_NUMBER 			:= l_instance.SERIAL_NUMBER;
3716 			c_instance_tbl(inst_idx).INVENTORY_REVISION 	:= l_instance.ITEM_REV;
3717 			c_instance_tbl(inst_idx).EXTERNAL_REFERENCE 	:= l_instance.EXTERNAL_REF;
3718 			c_instance_tbl(inst_idx).QUANTITY 				:= l_instance.QUANTITY;
3719 			c_instance_tbl(inst_idx).UNIT_OF_MEASURE 		:= l_instance.UOM;
3720 			c_instance_tbl(inst_idx).INSTANCE_STATUS_ID 	:= l_instance.INSTANCE_STATUS_ID;
3721 			c_instance_tbl(inst_idx).INSTANCE_TYPE_CODE 	:= l_instance.PRODUCT_TYPE_CODE;
3722 			c_instance_tbl(inst_idx).ACTIVE_START_DATE  	:= l_instance.ACTIVE_START_DATE;
3723 			c_instance_tbl(inst_idx).ACTIVE_END_DATE  		:= l_instance.EXPIRATION_DATE;
3724 			c_instance_tbl(inst_idx).install_date 			:= l_instance.INSTALL_DATE;
3725 			c_instance_tbl(inst_idx).INSTALL_LOCATION_TYPE_CODE := l_instance.INSTALL_LOCATION_TYPE_CODE;
3726 			c_instance_tbl(inst_idx).INSTALL_LOCATION_ID 		:= l_instance.INSTALL_LOCATION_ID;
3727 			c_instance_tbl(inst_idx).operational_status_code 	:= l_instance.OPERATIONAL_STATUS_CODE ;
3728 			c_instance_tbl(inst_idx).CONTEXT				:= l_instance.CONTEXT;
3729 			c_instance_tbl(inst_idx).ATTRIBUTE1				:= l_instance.ATTRIBUTE1;
3730 			c_instance_tbl(inst_idx).ATTRIBUTE2				:= l_instance.ATTRIBUTE2;
3731 			c_instance_tbl(inst_idx).ATTRIBUTE3				:= l_instance.ATTRIBUTE3;
3732 			c_instance_tbl(inst_idx).ATTRIBUTE4				:= l_instance.ATTRIBUTE4;
3733 			c_instance_tbl(inst_idx).ATTRIBUTE5				:= l_instance.ATTRIBUTE5;
3734 			c_instance_tbl(inst_idx).ATTRIBUTE6				:= l_instance.ATTRIBUTE6;
3735 			c_instance_tbl(inst_idx).ATTRIBUTE7				:= l_instance.ATTRIBUTE7;
3736 			c_instance_tbl(inst_idx).ATTRIBUTE8				:= l_instance.ATTRIBUTE8;
3737 			c_instance_tbl(inst_idx).ATTRIBUTE9				:= l_instance.ATTRIBUTE9;
3738 			c_instance_tbl(inst_idx).ATTRIBUTE10			:= l_instance.ATTRIBUTE10;
3739 			c_instance_tbl(inst_idx).ATTRIBUTE11			:= l_instance.ATTRIBUTE11;
3740 			c_instance_tbl(inst_idx).ATTRIBUTE12			:= l_instance.ATTRIBUTE12;
3741 			c_instance_tbl(inst_idx).ATTRIBUTE13			:= l_instance.ATTRIBUTE13;
3742 			c_instance_tbl(inst_idx).ATTRIBUTE14			:= l_instance.ATTRIBUTE14;
3743 			c_instance_tbl(inst_idx).ATTRIBUTE15			:= l_instance.ATTRIBUTE15;
3744 			c_instance_tbl(inst_idx).ATTRIBUTE16			:= l_instance.ATTRIBUTE16;
3745 			c_instance_tbl(inst_idx).ATTRIBUTE17			:= l_instance.ATTRIBUTE17;
3746 			c_instance_tbl(inst_idx).ATTRIBUTE18			:= l_instance.ATTRIBUTE18;
3747 			c_instance_tbl(inst_idx).ATTRIBUTE19			:= l_instance.ATTRIBUTE19;
3748 			c_instance_tbl(inst_idx).ATTRIBUTE20			:= l_instance.ATTRIBUTE20;
3749 			c_instance_tbl(inst_idx).ATTRIBUTE21			:= l_instance.ATTRIBUTE21;
3750 			c_instance_tbl(inst_idx).ATTRIBUTE22			:= l_instance.ATTRIBUTE22;
3751 			c_instance_tbl(inst_idx).ATTRIBUTE23			:= l_instance.ATTRIBUTE23;
3752 			c_instance_tbl(inst_idx).ATTRIBUTE24			:= l_instance.ATTRIBUTE24;
3753 			c_instance_tbl(inst_idx).ATTRIBUTE25			:= l_instance.ATTRIBUTE25;
3754 			c_instance_tbl(inst_idx).ATTRIBUTE26			:= l_instance.ATTRIBUTE26;
3755 			c_instance_tbl(inst_idx).ATTRIBUTE27			:= l_instance.ATTRIBUTE27;
3756 			c_instance_tbl(inst_idx).ATTRIBUTE28			:= l_instance.ATTRIBUTE28;
3757 			c_instance_tbl(inst_idx).ATTRIBUTE29			:= l_instance.ATTRIBUTE29;
3758 			c_instance_tbl(inst_idx).ATTRIBUTE30			:= l_instance.ATTRIBUTE30;
3759 			c_instance_tbl(inst_idx).SYSTEM_ID  			:= l_instance.SYSTEM_ID;
3760 			c_instance_tbl(inst_idx).VERSION_LABEL			:= l_instance.VERSION_LABEL;
3761 			c_instance_tbl(inst_idx).CREATION_COMPLETE_FLAG := 'Y'; --Added for Bug 12631458
3762 			c_instance_tbl(inst_idx).REC_INDEX				:= inst_idx; --Added for Bug 10414679
3763 			IF(l_instance.CREATE_CONTRACT = 'Y') THEN
3764 				c_instance_tbl(inst_idx).CALL_CONTRACTS     :=  FND_API.G_TRUE;
3765 			ELSE
3766 				c_instance_tbl(inst_idx).CALL_CONTRACTS     :=  FND_API.G_FALSE;
3767 			END IF;
3768 
3769 			--Added for Bug 10414679
3770 			l_log_tbl(inst_idx).ITEM_NUMBER 				:= l_instance.ITEM_NUMBER;
3771 			l_log_tbl(inst_idx).QUANTITY					:= l_instance.QUANTITY;
3772 			--Corrected the code while making changes for Bug 12631458
3773 			IF(nvl(l_instance.EXTERNAL_REF, FND_API.G_MISS_CHAR) <> FND_API.G_MISS_CHAR)
3774 			THEN
3775 				l_log_tbl(inst_idx).EXTERNAL_REFERENCE			:= l_instance.EXTERNAL_REF;
3776 			ELSE
3777 				l_log_tbl(inst_idx).EXTERNAL_REFERENCE			:= ' ';
3778 			END IF;
3779 
3780 			IF(nvl(l_instance.SERIAL_NUMBER, FND_API.G_MISS_CHAR) <> FND_API.G_MISS_CHAR)
3781 			THEN
3782 				l_log_tbl(inst_idx).SERIAL_NUMBER			:= l_instance.SERIAL_NUMBER;
3783 			ELSE
3784 				l_log_tbl(inst_idx).SERIAL_NUMBER			:= ' ';
3785 			END IF;
3786 
3787 			IF(nvl(l_instance.LOT_NUMBER, FND_API.G_MISS_CHAR) <> FND_API.G_MISS_CHAR)
3788 			THEN
3789 				l_log_tbl(inst_idx).LOT_NUMBER			:= l_instance.LOT_NUMBER;
3790 			ELSE
3791 				l_log_tbl(inst_idx).LOT_NUMBER			:= ' ';
3792 			END IF;
3793 
3794 			IF(nvl(l_instance.SYSTEM_NAME, FND_API.G_MISS_CHAR) <> FND_API.G_MISS_CHAR)
3795 			THEN
3796 				l_log_tbl(inst_idx).SYSTEM_NAME			:= l_instance.SYSTEM_NAME;
3797 			ELSE
3798 				l_log_tbl(inst_idx).SYSTEM_NAME			:= ' ';
3799 			END IF;
3800 
3801 
3802 			--Contract Association rec
3803 			IF(l_instance.ASSOCIATE_CONTRACT_ID IS NOT NULL
3804 				AND l_instance.ASSOCIATE_SERVICE_LINE_ID IS NOT NULL)
3805 			THEN
3806 				debug('Populating Contract association details');
3807 				oks_idx := oks_idx + 1;
3808 				l_cov_line_tbl(oks_idx).quantity 				:= l_instance.quantity;
3809 				l_cov_line_tbl(oks_idx).Unit_of_measure 		:= l_instance.UOM;
3810 				l_cov_line_tbl(oks_idx).Inventory_item_id 		:= l_instance.Item_Id;
3811 				l_cov_line_tbl(oks_idx).Customer_acct_id 		:= l_instance.Owner_Account_Id;
3812 				l_cov_line_tbl(oks_idx).Organization_id 		:= l_instance.LAST_VLD_ORGANIZATION_ID;
3813 				l_cov_line_tbl(oks_idx).parent_tbl_idx			:= inst_idx;
3814 
3815 				l_chr_id_tbl(oks_idx) 							:= l_instance.ASSOCIATE_CONTRACT_ID;
3816 				l_attach2_line_id_tbl(oks_idx) 					:= l_instance.ASSOCIATE_SERVICE_LINE_ID;
3817 			END IF;
3818 
3819 			--Pricing attributes rec
3820 			IF(l_instance.Pricing_context IS NOT NULL) THEN
3821 				debug('Populating Pricing attributes details');
3822 				c_pa_idx := c_pa_idx + 1;
3823 				c_pricing_attribs_tbl(c_pa_idx).pricing_context		:= l_instance.Pricing_context;
3824 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute1	:= l_instance.pricing_attribute1;
3825 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute2	:= l_instance.pricing_attribute2;
3826 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute3	:= l_instance.pricing_attribute3;
3827 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute4	:= l_instance.pricing_attribute4;
3828 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute5	:= l_instance.pricing_attribute5;
3829 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute6	:= l_instance.pricing_attribute6;
3830 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute7	:= l_instance.pricing_attribute7;
3831 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute8	:= l_instance.pricing_attribute8;
3832 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute9	:= l_instance.pricing_attribute9;
3833 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute10	:= l_instance.pricing_attribute10;
3834 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute11	:= l_instance.pricing_attribute11;
3835 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute12	:= l_instance.pricing_attribute12;
3836 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute13	:= l_instance.pricing_attribute13;
3837 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute14	:= l_instance.pricing_attribute14;
3838 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute15	:= l_instance.pricing_attribute15;
3839 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute16	:= l_instance.pricing_attribute16;
3840 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute17	:= l_instance.pricing_attribute17;
3841 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute18	:= l_instance.pricing_attribute18;
3842 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute19	:= l_instance.pricing_attribute19;
3843 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute20	:= l_instance.pricing_attribute20;
3844 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute21	:= l_instance.pricing_attribute21;
3845 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute22	:= l_instance.pricing_attribute22;
3846 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute23	:= l_instance.pricing_attribute23;
3847 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute24	:= l_instance.pricing_attribute24;
3848 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute25	:= l_instance.pricing_attribute25;
3849 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute26	:= l_instance.pricing_attribute26;
3850 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute27	:= l_instance.pricing_attribute27;
3851 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute28	:= l_instance.pricing_attribute28;
3852 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute29	:= l_instance.pricing_attribute29;
3853 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute30	:= l_instance.pricing_attribute30;
3854 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute31	:= l_instance.pricing_attribute31;
3855 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute32	:= l_instance.pricing_attribute32;
3856 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute33	:= l_instance.pricing_attribute33;
3857 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute34	:= l_instance.pricing_attribute34;
3858 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute35	:= l_instance.pricing_attribute35;
3859 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute36	:= l_instance.pricing_attribute36;
3860 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute37	:= l_instance.pricing_attribute37;
3861 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute38	:= l_instance.pricing_attribute38;
3862 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute39	:= l_instance.pricing_attribute39;
3863 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute40	:= l_instance.pricing_attribute40;
3864 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute41	:= l_instance.pricing_attribute41;
3865 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute42	:= l_instance.pricing_attribute42;
3866 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute43	:= l_instance.pricing_attribute43;
3867 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute44	:= l_instance.pricing_attribute44;
3868 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute45	:= l_instance.pricing_attribute45;
3869 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute46	:= l_instance.pricing_attribute46;
3870 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute47	:= l_instance.pricing_attribute47;
3871 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute48	:= l_instance.pricing_attribute48;
3872 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute49	:= l_instance.pricing_attribute49;
3873 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute50	:= l_instance.pricing_attribute50;
3874 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute51	:= l_instance.pricing_attribute51;
3875 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute52	:= l_instance.pricing_attribute52;
3876 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute53	:= l_instance.pricing_attribute53;
3877 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute54	:= l_instance.pricing_attribute54;
3878 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute55	:= l_instance.pricing_attribute55;
3879 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute56	:= l_instance.pricing_attribute56;
3880 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute57	:= l_instance.pricing_attribute57;
3881 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute58	:= l_instance.pricing_attribute58;
3882 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute59	:= l_instance.pricing_attribute59;
3883 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute60	:= l_instance.pricing_attribute60;
3884 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute61	:= l_instance.pricing_attribute61;
3885 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute62	:= l_instance.pricing_attribute62;
3886 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute63	:= l_instance.pricing_attribute63;
3887 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute64	:= l_instance.pricing_attribute64;
3888 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute65	:= l_instance.pricing_attribute65;
3889 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute66	:= l_instance.pricing_attribute66;
3890 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute67	:= l_instance.pricing_attribute67;
3891 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute68	:= l_instance.pricing_attribute68;
3892 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute69	:= l_instance.pricing_attribute69;
3893 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute70	:= l_instance.pricing_attribute70;
3894 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute71	:= l_instance.pricing_attribute71;
3895 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute72	:= l_instance.pricing_attribute72;
3896 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute73	:= l_instance.pricing_attribute73;
3897 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute74	:= l_instance.pricing_attribute74;
3898 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute75	:= l_instance.pricing_attribute75;
3899 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute76	:= l_instance.pricing_attribute76;
3900 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute77	:= l_instance.pricing_attribute77;
3901 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute78	:= l_instance.pricing_attribute78;
3902 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute79	:= l_instance.pricing_attribute79;
3903 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute80	:= l_instance.pricing_attribute80;
3904 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute81	:= l_instance.pricing_attribute81;
3905 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute82	:= l_instance.pricing_attribute82;
3906 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute83	:= l_instance.pricing_attribute83;
3907 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute84	:= l_instance.pricing_attribute84;
3908 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute85	:= l_instance.pricing_attribute85;
3909 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute86	:= l_instance.pricing_attribute86;
3910 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute87	:= l_instance.pricing_attribute87;
3911 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute88	:= l_instance.pricing_attribute88;
3912 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute89	:= l_instance.pricing_attribute89;
3913 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute90	:= l_instance.pricing_attribute90;
3914 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute91	:= l_instance.pricing_attribute91;
3915 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute92	:= l_instance.pricing_attribute92;
3916 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute93	:= l_instance.pricing_attribute93;
3917 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute94	:= l_instance.pricing_attribute94;
3918 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute95	:= l_instance.pricing_attribute95;
3919 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute96	:= l_instance.pricing_attribute96;
3920 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute97	:= l_instance.pricing_attribute97;
3921 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute98	:= l_instance.pricing_attribute98;
3922 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute99	:= l_instance.pricing_attribute99;
3923 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute100	:= l_instance.pricing_attribute100;
3924 				c_pricing_attribs_tbl(c_pa_idx).parent_tbl_index		:= inst_idx;
3925 			END IF;
3926 
3927 			--Part yRecord
3928 			party_idx := party_idx + 1;
3929 			c_party_tbl(party_idx).instance_party_id 		:= NULL;
3930 			c_party_tbl(party_idx).instance_id       		:= NULL;
3931 			c_party_tbl(party_idx).parent_tbl_index   		:= inst_idx;
3932 			c_party_tbl(party_idx).contact_flag 			:= 'N';
3933 			c_party_tbl(party_idx).relationship_type_code 	:= 'OWNER';
3934 			c_party_tbl(party_idx).OBJECT_VERSION_NUMBER  	:= 1;
3935 
3936 			IF(l_instance.INTERNALLY_OWNED = 'Y') THEN
3937 				debug('Populating Internal owner party details.');
3938 				BEGIN
3939 					SELECT INTERNAL_PARTY_ID
3940 					INTO l_internal_party_id
3941 					FROM csi_install_parameters;
3942 				EXCEPTION
3943 					WHEN others THEN
3944 						raise fnd_api.g_exc_error;
3945 				END;
3946 
3947 				c_party_tbl(party_idx).party_source_table 			:= 'HZ_PARTIES';
3948 				c_party_tbl(party_idx).party_id 					:= l_internal_party_id;
3949 				--Added for Bug 10414679
3950 				l_log_tbl(inst_idx).INTERNALLY_OWNED				:= 'Y';
3951 				l_log_tbl(inst_idx).OWNER_PARTY_NUM				    := ' ';
3952 				l_log_tbl(inst_idx).OWNER_NAME					    := ' ';
3953 
3954 			ELSE
3955 
3956 				debug('Populating owner party details.');
3957 				c_party_tbl(party_idx).party_source_table 			:= l_instance.OWNER_PARTY_TYPE;
3958 				c_party_tbl(party_idx).party_id 					:= l_instance.OWNER_ID;
3959 
3960 				--Added for Bug 10414679
3961 				l_log_tbl(inst_idx).INTERNALLY_OWNED				:= 'N';
3962 				l_log_tbl(inst_idx).OWNER_PARTY_NUM				    := l_instance.OWNER_PARTY_NUM;
3963 				l_log_tbl(inst_idx).OWNER_NAME					    := l_instance.OWNER_NAME;
3964 
3965 				--Account Record
3966 				IF l_instance.OWNER_PARTY_TYPE = 'HZ_PARTIES' THEN
3967 					debug('Populating owner account details.');
3968 					account_idx := account_idx + 1;
3969 					c_account_tbl(account_idx).ip_account_id     		:= fnd_api.g_miss_num;
3970 					c_account_tbl(account_idx).instance_party_id 		:= fnd_api.g_miss_num;
3971 					c_account_tbl(account_idx).parent_tbl_index  		:= party_idx;
3972 					c_account_tbl(account_idx).party_account_id 		:= l_instance.OWNER_ACCOUNT_ID;
3973 					c_account_tbl(account_idx).relationship_type_code 	:= 'OWNER';
3974 					c_account_tbl(account_idx).bill_to_address 			:= l_instance.BILL_TO_LOC_ID;
3975 					c_account_tbl(account_idx).ship_to_address 			:= l_instance.SHIP_TO_LOC_ID;
3976 					c_account_tbl(account_idx).OBJECT_VERSION_NUMBER 	:= 1;
3977 					IF(l_instance.CREATE_CONTRACT = 'Y') THEN
3978 						c_account_tbl(account_idx).CALL_CONTRACTS 		:= FND_API.G_TRUE;
3979 					ELSE
3980 						c_account_tbl(account_idx).CALL_CONTRACTS 		:= FND_API.G_FALSE;
3981 					END IF;
3982 				END IF;
3983 			END IF;
3984 
3985 			--Bill to Relationship
3986 			IF(l_instance.ASSOCIATE_BILL_TO_PARTY_ID is not null) THEN
3987 				debug('Populating Bill To Party details');
3988 				party_idx := party_idx + 1;
3989 				account_idx := account_idx + 1;
3990 				--Part yRecord
3991 				c_party_tbl(party_idx).instance_id       				:= l_instance.INSTANCE_ID;
3992 				c_party_tbl(party_idx).parent_tbl_index   				:= inst_idx;
3993 				c_party_tbl(party_idx).contact_flag := 'N';
3994 				c_party_tbl(party_idx).relationship_type_code 			:= 'BILL_TO';
3995 				c_party_tbl(party_idx).OBJECT_VERSION_NUMBER  			:= 1;
3996 				c_party_tbl(party_idx).party_source_table 				:= l_instance.ASSOCIATE_BILL_TO_PARTY_TYPE;
3997 				c_party_tbl(party_idx).party_id 						:= l_instance.ASSOCIATE_BILL_TO_PARTY_ID;
3998 				--Account Record
3999 				IF(l_instance.ASSOCIATE_BILL_TO_ACCT_ID is not null) THEN
4000 					debug('Populating Bill To Party Account details');
4001 					c_account_tbl(account_idx).parent_tbl_index  		:= party_idx;
4002 					c_account_tbl(account_idx).party_account_id 		:= l_instance.ASSOCIATE_BILL_TO_ACCT_ID;
4003 					c_account_tbl(account_idx).relationship_type_code 	:= 'BILL_TO';
4004 					c_account_tbl(account_idx).OBJECT_VERSION_NUMBER 	:= 1;
4005 					IF(l_instance.CREATE_CONTRACT = 'Y') THEN
4006 						c_account_tbl(account_idx).CALL_CONTRACTS 		:= FND_API.G_TRUE;
4007 					ELSE
4008 						c_account_tbl(account_idx).CALL_CONTRACTS 		:= FND_API.G_FALSE;
4009 					END IF;
4010 				END IF;
4011 			END IF;
4012 
4013 			--Ship to Relationship
4014 			IF(l_instance.ASSOCIATE_SHIP_TO_PARTY_ID is not null) THEN
4015 				debug('Populating Ship To Party details');
4016 				party_idx := party_idx + 1;
4017 				account_idx := account_idx + 1;
4018 				--Part yRecord
4019 				c_party_tbl(party_idx).instance_id       		:= l_instance.INSTANCE_ID;
4020 				c_party_tbl(party_idx).parent_tbl_index   		:= inst_idx;
4021 				c_party_tbl(party_idx).contact_flag 			:= 'N';
4022 				c_party_tbl(party_idx).relationship_type_code 	:= 'SHIP_TO';
4023 				c_party_tbl(party_idx).OBJECT_VERSION_NUMBER  	:= 1;
4024 				c_party_tbl(party_idx).party_source_table 		:= l_instance.ASSOCIATE_SHIP_TO_PARTY_TYPE;
4025 				c_party_tbl(party_idx).party_id 				:= l_instance.ASSOCIATE_SHIP_TO_PARTY_ID;
4026 
4027 				--Account Record
4028 				IF(l_instance.ASSOCIATE_SHIP_TO_ACCT_ID is not null) THEN
4029 					debug('Populating Ship To Party details');
4030 					c_account_tbl(account_idx).parent_tbl_index  		:= party_idx;
4031 					c_account_tbl(account_idx).party_account_id 		:= l_instance.ASSOCIATE_SHIP_TO_ACCT_ID;
4032 					c_account_tbl(account_idx).relationship_type_code 	:= 'SHIP_TO';
4033 					c_account_tbl(account_idx).OBJECT_VERSION_NUMBER 	:= 1;
4034 					IF(l_instance.CREATE_CONTRACT = 'Y') THEN
4035 						c_account_tbl(account_idx).CALL_CONTRACTS 		:= FND_API.G_TRUE;
4036 					ELSE
4037 						c_account_tbl(account_idx).CALL_CONTRACTS 		:= FND_API.G_FALSE;
4038 					END IF;
4039 				END IF;
4040 			END IF;
4041 
4042 			--Txn Rec
4043 			c_csi_txn_tbl(inst_idx) 	:= p_csi_txn_rec;
4044 			--Relationship record
4045 			IF(l_par_instance_id IS NOT NULL) THEN
4046 				debug('Populating Instance Relationship details');
4047 				rel_idx := rel_idx + 1;
4048 				c_relationship_tbl(rel_idx).relationship_type_code   := 'COMPONENT-OF';
4049 				c_relationship_tbl(rel_idx).object_id                := l_par_instance_id;
4050 				c_relationship_tbl(rel_idx).PARENT_TBL_INDEX		 := inst_idx;
4051 			END IF;
4052 
4053 			--Org Assignments, ****** check if it really required
4054 			c_org_assignments_tbl(inst_idx).operating_unit_id 		:= FND_PROFILE.VALUE('ORG_ID');
4055 			c_org_assignments_tbl(inst_idx).relationship_type_code 	:= 'SOLD_FROM';
4056 			c_org_assignments_tbl(inst_idx).parent_tbl_index 		:= inst_idx;
4057 		END IF;
4058 	END LOOP; --end of instances_for_create_csr traversing
4059 
4060 	debug('Number of records populated to call Create API: ' || c_instance_tbl.count);
4061 	IF(c_instance_tbl.count > 0) then
4062 		csi_item_instance_grp.create_item_instance (
4063 			  p_api_version           => 1.0,
4064 			  p_commit                => fnd_api.g_false,
4065 			  p_init_msg_list         => fnd_api.g_true,
4066 			  p_validation_level      => fnd_api.g_valid_level_full,
4067 			  p_instance_tbl          => c_instance_tbl,
4068 			  p_ext_attrib_values_tbl => c_ext_attrib_values_tbl,
4069 			  p_party_tbl             => c_party_tbl,
4070 			  p_account_tbl           => c_account_tbl,
4071 			  p_pricing_attrib_tbl    => c_pricing_attrib_tbl,
4072 			  p_org_assignments_tbl   => c_org_assignments_tbl,
4073 			  p_asset_assignment_tbl  => c_instance_asset_tbl,
4074 			  p_txn_tbl               => c_csi_txn_tbl,
4075 			  p_call_from_bom_expl    => 'N',
4076 			  p_grp_error_tbl         => c_grp_error_tbl,
4077 			  x_return_status         => l_crt_return_status,
4078 			  x_msg_count             => l_msg_count,
4079 			  x_msg_data              => l_msg_data);
4080 
4081 		IF NOT l_crt_return_status = FND_API.G_RET_STS_SUCCESS
4082 		THEN
4083 		    debug('Call to create_item_instance not successful');
4084 			debug_out('Creation of item instances failed, please check the request log for further details');
4085 			l_falied_count := l_falied_count + c_instance_tbl.count;
4086 			l_msg_index := 1;
4087 		    l_Error_Message := l_Msg_Data;
4088 		    WHILE l_msg_count > 0 LOOP
4089 			    l_Error_Message := FND_MSG_PUB.GET(l_msg_index, FND_API.G_FALSE);
4090 			    l_msg_index := l_msg_index + 1;
4091 			    l_msg_count := l_msg_count - 1;
4092 			    debug('Error: ' || l_Error_Message);
4093 		    END LOOP;
4094 
4095 		ELSE
4096 			Commit;
4097 			IF(c_grp_error_tbl.count >0) THEN
4098 			  --Added for Bug 10414679
4099 			    debug_out(rpad('=',390, '='));
4100 				debug_out(rpad('Item Number', 43, ' ') ||
4101 						rpad('Internally Owned', 20, ' ') ||
4102 						rpad('Owner Party Number', 33, ' ') ||
4103 						rpad('Quantity', 33, '') ||
4104 						rpad('Serail Number', 33, ' ') ||
4105 						rpad('Lot Number', 83, ' ') ||
4106 						rpad('External Reference', 33, ' ') ||
4107 						rpad('System Name', 53, ' ') ||
4108 						rpad('Status', 14, ' ') ||
4109 						rpad('Instance Number', 33, ' ') ||
4110 						'ERROR');
4111 				debug_out(rpad('=',390, '='));
4112 				FOR inst_tab_row IN c_grp_error_tbl.FIRST .. c_grp_error_tbl.LAST
4113 				LOOP
4114 					IF c_grp_error_tbl.EXISTS(inst_tab_row) THEN
4115 					    debug('Processed Instance Record #' ||
4116 								c_grp_error_tbl(inst_tab_row).Group_Inst_Num || ': ');
4117 					    --Changed for Bug 10414679
4118 						l_rec_idx := c_instance_tbl(inst_tab_row).rec_index;
4119 
4120 					    IF(c_grp_error_tbl(inst_tab_row).Process_Status <> 'E')
4121 						AND c_instance_tbl.EXISTS(inst_tab_row) THEN
4122 							debug_out(rpad(l_log_tbl(l_rec_idx).ITEM_NUMBER, 43, ' ') ||
4123 								rpad(l_log_tbl(l_rec_idx).INTERNALLY_OWNED, 20, ' ') ||
4124 								rpad(l_log_tbl(l_rec_idx).OWNER_PARTY_NUM, 33, ' ') ||
4125 								rpad(l_log_tbl(l_rec_idx).QUANTITY, 33, '') ||
4126 								rpad(l_log_tbl(l_rec_idx).SERIAL_NUMBER, 33, ' ') ||
4127 								rpad(l_log_tbl(l_rec_idx).LOT_NUMBER, 83, ' ') ||
4128 								rpad(l_log_tbl(l_rec_idx).EXTERNAL_REFERENCE, 33, ' ') ||
4129 								rpad(l_log_tbl(l_rec_idx).SYSTEM_NAME, 53, ' ') ||
4130 								rpad('SUCCESSFUL', 14, ' ') ||
4131 								rpad(c_instance_tbl(inst_tab_row).INSTANCE_NUMBER, 33, ' '));
4132 
4133 							debug('		Created with the Instance Number: ' ||
4134 										c_instance_tbl(inst_tab_row).INSTANCE_NUMBER);
4135 					    ELSE
4136 							debug_out(rpad(l_log_tbl(l_rec_idx).ITEM_NUMBER, 43, ' ') ||
4137 								rpad(l_log_tbl(l_rec_idx).INTERNALLY_OWNED, 20, ' ') ||
4138 								rpad(l_log_tbl(l_rec_idx).OWNER_PARTY_NUM, 33, ' ') ||
4139 								rpad(l_log_tbl(l_rec_idx).QUANTITY, 33, '') ||
4140 								rpad(l_log_tbl(l_rec_idx).SERIAL_NUMBER, 33, ' ') ||
4141 								rpad(l_log_tbl(l_rec_idx).LOT_NUMBER, 83, ' ') ||
4142 								rpad(l_log_tbl(l_rec_idx).EXTERNAL_REFERENCE, 33, ' ') ||
4143 								rpad(l_log_tbl(l_rec_idx).SYSTEM_NAME, 53, ' ') ||
4144 								rpad('FAILED', 14, ' ') ||
4145 								rpad('-------', 33, ' ') ||
4146 								c_grp_error_tbl(inst_tab_row).Error_Message);
4147 
4148 							l_falied_count := l_falied_count + 1;
4149 						    debug('		Error while creating: ' || c_grp_error_tbl(inst_tab_row).Error_Message);
4150 						END IF;
4151 					END IF;
4152 				END LOOP;
4153 				debug_out(rpad('=',390, '='));
4154 			END IF;
4155 		END IF;
4156 	END IF;
4157 
4158 	SELECT Count(*) INTO l_crt_count
4159 		FROM CSI_WEBADI_STAGING
4160 		where BATCH_ID = p_entry_id
4161 		and INSTANCE_ID is null;
4162 
4163 	debug_out('	');
4164 	debug_out('Total no. of Item Instances created successfully: ' || (l_crt_count - l_falied_count));
4165 	debug_out('Total no. of create records failed: ' || l_falied_count);
4166 	debug_out('	');
4167 
4168 	debug('Total no. of Item Instances created successfully: ' || (l_crt_count - l_falied_count));
4169 	debug('Total no. of create records failed: ' || l_falied_count);
4170 
4171 	--Creating notes for all the successful instances created
4172 	IF(l_batch_desc IS NOT NULL) THEN
4173 		IF(c_grp_error_tbl.count >0) THEN
4174 			FOR inst_tab_row IN c_grp_error_tbl.FIRST .. c_grp_error_tbl.LAST
4175 			LOOP
4176 				IF c_grp_error_tbl.EXISTS(inst_tab_row) THEN
4177 					IF(c_grp_error_tbl(inst_tab_row).Process_Status <> 'E')
4178 					AND c_instance_tbl.EXISTS(inst_tab_row) THEN
4179 						debug('Calling JTF_NOTES_PUB.CREATE_NOTE for created Instance: '
4180 								|| c_instance_tbl(inst_tab_row).INSTANCE_NUMBER);
4181 						JTF_NOTES_PUB.CREATE_NOTE
4182 						(	p_parent_note_id         => NULL,
4183 							p_api_version            => 1,
4184 							p_init_msg_list          => NULL,
4185 							p_commit                 => FND_API.G_FALSE,
4186 							p_validation_level       => fnd_api.g_valid_level_full,
4187 							x_return_status          => l_return_status,
4188 							x_msg_count              => l_msg_count,
4189 							x_msg_data               => l_msg_data,
4190 							x_jtf_note_id            => l_note_id,
4191 							p_org_id                 => NULL,
4192 							p_source_object_id       => c_instance_tbl(inst_tab_row).INSTANCE_ID,
4193 							p_source_object_code     => 'CP',
4194 							p_notes                  => l_batch_desc,
4195 							p_note_status            => 'I',
4196 							p_entered_by             => FND_GLOBAL.USER_ID,
4197 							p_entered_date           => SYSDATE,
4198 							p_last_update_date       => SYSDATE,
4199 							p_last_updated_by        => FND_GLOBAL.USER_ID,
4200 							p_creation_date          => SYSDATE,
4201 							p_created_by             => FND_GLOBAL.USER_ID
4202 						);
4203 
4204 						IF NOT(l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
4205 							debug_out('Error occured while creating a note for the created Instance: '
4206 													|| c_instance_tbl(inst_tab_row).INSTANCE_NUMBER);
4207 							debug('Error occured while creating a note for the created Instance: '
4208 													|| c_instance_tbl(inst_tab_row).INSTANCE_NUMBER);
4209 							l_msg_index := 1;
4210 							l_Error_Message := l_msg_data;
4211 							WHILE l_msg_count > 0
4212 							LOOP
4213 							l_Error_Message := FND_MSG_PUB.GET(l_msg_index, FND_API.G_FALSE);
4214 							l_msg_index := l_msg_index + 1;
4215 							l_msg_count := l_msg_count - 1;
4216 							debug('Error: ' || l_Error_Message);
4217 							END LOOP;
4218 						END IF;
4219 					END IF;
4220 				END IF;
4221 			END LOOP;
4222 		END IF;
4223 	END IF;
4224 
4225 	--Populating relationship records with the Instance Ids created   and calling ceate API
4226 	debug('Number of records populated before filtering, for the call to Create Relationships API: ' ||
4227 				c_relationship_tbl.count);
4228 	IF (c_relationship_tbl.count > 0 AND l_crt_return_status = FND_API.G_RET_STS_SUCCESS) THEN
4229 
4230 		FOR inst_tab_row IN c_relationship_tbl.FIRST .. c_relationship_tbl.LAST
4231 		LOOP
4232 			IF c_relationship_tbl.EXISTS(inst_tab_row) THEN
4233 			  c_relationship_tbl(inst_tab_row).subject_id	 :=
4234 							  c_instance_tbl(c_relationship_tbl(inst_tab_row).PARENT_TBL_INDEX).INSTANCE_ID;
4235 			  IF(c_grp_error_tbl(c_relationship_tbl(inst_tab_row).PARENT_TBL_INDEX).Process_Status <> 'E')
4236 				AND NOT nvl(c_relationship_tbl(inst_tab_row).subject_id, FND_API.G_MISS_NUM) = FND_API.G_MISS_NUM
4237 			  THEN
4238 					  l_rel_idx := l_rel_idx + 1;
4239 					  l_relationship_tbl(l_rel_idx) := c_relationship_tbl(inst_tab_row);
4240 			  END IF;
4241 			END IF;
4242 		END LOOP;
4243 		debug('Number of records eligible for call to Create Relationships API: ' || l_relationship_tbl.count);
4244 		csi_ii_relationships_pub.create_relationship(
4245 			p_api_version           => 1.0,
4246 			p_commit                => fnd_api.g_false,
4247 			p_init_msg_list         => fnd_api.g_true,
4248 			p_validation_level      => fnd_api.g_valid_level_full,
4249 			p_relationship_tbl      => l_relationship_tbl,
4250 			p_txn_rec               => p_csi_txn_rec,
4251 			x_return_status         => l_return_status,
4252 			x_msg_count             => l_msg_count,
4253 			x_msg_data              => l_msg_data);
4254 		IF NOT l_return_status = FND_API.G_RET_STS_SUCCESS
4255 		THEN
4256 			debug_out('Error occured, while creating relationship for the newly created instance(s).' ||
4257 								'Please check the request log for further details');
4258 			debug('Call to create_relationship while Create is not successful');
4259 			l_msg_index := 1;
4260 		    l_Error_Message := l_Msg_Data;
4261 		    WHILE l_msg_count > 0 LOOP
4262 			    l_Error_Message := FND_MSG_PUB.GET(l_msg_index, FND_API.G_FALSE);
4263 			    l_msg_index := l_msg_index + 1;
4264 			    l_msg_count := l_msg_count - 1;
4265 			    debug('Error: ' || l_Error_Message);
4266 		    END LOOP;
4267 		ELSE
4268 			Commit;
4269 		END IF;
4270 	END IF;
4271 
4272 	--Populating contract records with the Instance Ids created   and calling OKS API
4273 	debug('Number of records populated to call OKS API: ' || l_cov_line_tbl.count);
4274 	IF (l_cov_line_tbl.count > 0 AND l_crt_return_status = FND_API.G_RET_STS_SUCCESS) THEN
4275 
4276 		FOR tab_row IN l_cov_line_tbl.FIRST .. l_cov_line_tbl.LAST
4277 		LOOP
4278 			IF l_cov_line_tbl.EXISTS(tab_row) THEN
4279 			  l_cov_line_tbl(tab_row).customer_product_id :=
4280 							  c_instance_tbl(l_cov_line_tbl(tab_row).parent_tbl_idx).INSTANCE_ID;
4281 				IF(c_grp_error_tbl(l_cov_line_tbl(tab_row).parent_tbl_idx).Process_Status <> 'E')
4282 					AND NOT nvl(l_cov_line_tbl(tab_row).customer_product_id, FND_API.G_MISS_NUM)
4283 																			= FND_API.G_MISS_NUM
4284 				THEN
4285 					l_covlvl_id := NULL;
4286 					OKS_IBINT_PUB.create_k_covered_levels_webadi(
4287 						p_chr_id 			=> 		  l_chr_id_tbl(tab_row),
4288 						p_attach2_line_id	=>        l_attach2_line_id_tbl(tab_row),
4289 						p_k_covd_rec        =>        l_cov_line_tbl(tab_row),
4290 						x_covlvl_id         =>        l_covlvl_id,
4291 						x_return_status     =>        l_return_status,
4292 						x_msg_count         =>        l_msg_count,
4293 						x_msg_data          =>        l_msg_data
4294 						);
4295 
4296 					IF NOT l_return_status = FND_API.G_RET_STS_SUCCESS
4297 					THEN
4298 						debug('Error Occured in call to OKS_IBINT_PUB.create_k_covered_levels_webadi ' ||
4299 									'for the Instance: ' ||
4300 									c_instance_tbl(l_cov_line_tbl(tab_row).parent_tbl_idx).INSTANCE_NUMBER);
4301 						debug('Error: ' || l_msg_data);
4302 						debug_out('Failed to associate the specified contract for the Instance ' ||
4303 										c_instance_tbl(l_cov_line_tbl(tab_row).parent_tbl_idx).INSTANCE_NUMBER ||
4304 										'. And is due to: ');
4305 						debug_out('' || l_msg_data);
4306 					ELSE
4307 						commit;
4308 						debug_out('Contract successfully associated to the Instance ' ||
4309 							c_instance_tbl(l_cov_line_tbl(tab_row).parent_tbl_idx).INSTANCE_NUMBER ||
4310 							' with the cover level ID: ' || l_covlvl_id);
4311 						debug('Contract successfully associated to the Instance ' ||
4312 							c_instance_tbl(l_cov_line_tbl(tab_row).parent_tbl_idx).INSTANCE_NUMBER ||
4313 							' with the cover level ID: ' || l_covlvl_id);
4314 					END IF;
4315 				END IF;
4316 			END IF;
4317 		END LOOP;
4318 	END IF;
4319 
4320 	--Populating Pricing attr records with the Instance Ids created and Calling Pricing Attributes API
4321 	debug('Number of records populated to call create Pricing attributes API: ' || c_pricing_attribs_tbl.count);
4322 	IF (c_pricing_attribs_tbl.count > 0 AND l_crt_return_status = FND_API.G_RET_STS_SUCCESS) THEN
4323 
4324 		FOR tab_row IN c_pricing_attribs_tbl.FIRST .. c_pricing_attribs_tbl.LAST
4325 		LOOP
4326 			IF c_pricing_attribs_tbl.EXISTS(tab_row) THEN
4327 			  c_pricing_attribs_tbl(tab_row).instance_id :=
4328 							  c_instance_tbl(c_pricing_attribs_tbl(tab_row).parent_tbl_index).INSTANCE_ID;
4329 				IF(c_grp_error_tbl(c_pricing_attribs_tbl(tab_row).parent_tbl_index).Process_Status <> 'E')
4330 					AND NOT nvl(c_pricing_attribs_tbl(tab_row).instance_id, FND_API.G_MISS_NUM)
4331 																			= FND_API.G_MISS_NUM
4332 				THEN
4333 					csi_pricing_attribs_pvt.create_pricing_attribs(
4334 						p_api_version			=>	1.0,
4335 						p_commit              	=>	fnd_api.g_false,
4336 						p_init_msg_list       	=>	fnd_api.g_true,
4337 						p_validation_level    	=>	fnd_api.g_valid_level_full,
4338 						p_pricing_attribs_rec 	=>	c_pricing_attribs_tbl(tab_row),
4339 						p_txn_rec             	=>	p_csi_txn_rec,
4340 						x_return_status       	=>	l_return_status,
4341 						x_msg_count           	=>	l_msg_count,
4342 						x_msg_data            	=>	l_msg_data);
4343 					IF NOT l_return_status = FND_API.G_RET_STS_SUCCESS
4344 					THEN
4345 						debug_out('Error occured, while creating Pricing attributes, for the newly created instance ' ||
4346 										c_instance_tbl(c_pricing_attribs_tbl(tab_row).parent_tbl_index).INSTANCE_NUMBER ||
4347 										'. Please check the request log for further details');
4348 						debug('Error Occured in call to create_pricing_attribs for the Instance: ' ||
4349 									c_instance_tbl(c_pricing_attribs_tbl(tab_row).parent_tbl_index).INSTANCE_NUMBER);
4350 						debug('Error: ');
4351 
4352 						l_msg_index := 1;
4353 					    l_Error_Message := l_msg_data;
4354 					    WHILE l_msg_count > 0 LOOP
4355 						    l_Error_Message := FND_MSG_PUB.GET(l_msg_index, FND_API.G_FALSE);
4356 						    l_msg_index := l_msg_index + 1;
4357 						    l_msg_count := l_msg_count - 1;
4358 						    debug('Error: ' || l_Error_Message);
4359 					    END LOOP;
4360 					ELSE
4361 						Commit;
4362 						debug('Pricing attributes successfully created for the Instance ' ||
4363 							c_instance_tbl(c_pricing_attribs_tbl(tab_row).parent_tbl_index).INSTANCE_NUMBER);
4364 					END IF;
4365 				END IF;
4366 			END IF;
4367 		END LOOP;
4368 	END IF;
4369 	debug('End procedure: Process_webadi_create');
4370 EXCEPTION
4371     WHEN OTHERS THEN
4372 		debug_out('Encountered unexpected error while create. Please check the request log for error details');
4373         debug('Encountered unexpected exception in Process_webadi_create');
4374         debug('Unexpected error: ' || to_char(SQLCODE)||substr(SQLERRM, 1, 255));
4375         errbuf := 'E';
4376 End Process_webadi_create;
4377 
4378 PROCEDURE Process_webadi_update
4379    ( errbuf                       OUT NOCOPY    VARCHAR2
4380     ,retcode                      OUT NOCOPY    NUMBER
4381     ,p_Entry_id                   IN     NUMBER
4382 	,p_csi_txn_rec				  IN OUT NOCOPY csi_datastructures_pub.transaction_rec
4383    ) IS
4384 
4385     CURSOR instances_for_update_csr(p_entry_id IN NUMBER) IS
4386 		SELECT
4387 			ITEM_ID,
4388 			ORGANIZATION,
4389 			ITEM_NUMBER ,
4390 			INSTANCE_ID,
4391 			PRODUCT_NUMBER ,
4392 			INSTANCE_DESCRIPTION,
4393 			ITEM_REV,
4394 			UOM,
4395 			QUANTITY,
4396 			LAST_VLD_ORGANIZATION_ID,
4397 			SERIAL_NUMBER ,
4398 			LOT_NUMBER ,
4399 			INSTANCE_STATUS_ID,
4400 			EXTERNAL_REF ,
4401 			OPERATIONAL_STATUS_CODE ,
4402 			OWNER_PARTY_SOURCE_TABLE ,
4403 			OWNER_PARTY_TYPE ,
4404 			OWNER_PARTY_NUM,
4405 			OWNER_NAME,
4406 			OWNER_ACCOUNT_NUMBER ,
4407 			OWNER_ID,
4408 			OWNER_ACCOUNT_ID,
4409 			OBJECT_VERSION_NUMBER,
4410 			PRODUCT_TYPE_CODE ,
4411 			INSTALL_DATE,
4412 			VERSION_LABEL ,
4413 			CREATION_DATE,
4414 			ACTIVE_START_DATE,
4415 			EXPIRATION_DATE ,
4416 			CONTRACT_NUMBER ,
4417 			PARENT_INSTANCE ,
4418 			OLD_PARENT_INSTANCE,
4419 			SPLIT_QTY,
4420 			ASSOCIATE_BILL_TO_PARTY_TYPE,
4421 			ASSOCIATE_BILL_TO_PARTY_NUMBER,
4422 			ASSOCIATE_BILL_TO_PARTY_NAME,
4423 			ASSOCIATE_BILL_TO_PARTY_ID,
4424 			ASSOCIATE_BILL_TO_ACCT_NUM,
4425 			ASSOCIATE_BILL_TO_ACCT_ID,
4426 			ASSOCIATE_SHIP_TO_PARTY_TYPE,
4427 			ASSOCIATE_SHIP_TO_PARTY_NUMBER,
4428 			ASSOCIATE_SHIP_TO_PARTY_NAME,
4429 			ASSOCIATE_SHIP_TO_PARTY_ID,
4430 			ASSOCIATE_SHIP_TO_ACCT_NUM,
4431 			ASSOCIATE_SHIP_TO_ACCT_ID,
4432 			BILL_TO_LOC_ID,
4433 			SHIP_TO_LOC_ID ,
4434 			LOCATION_ID,
4435 			LOCATION_TYPE_CODE ,
4436 			INSTALL_LOCATION_ID,
4437 			INSTALL_LOCATION_TYPE_CODE ,
4438 			ASSOCIATE_CONTRACT_ID,
4439 			ASSOCIATE_CONTRACT_NUMBER,
4440 			ASSOCIATE_CONTRACT_MODIFIER,
4441 			ASSOCIATE_SERVICE_LINE,
4442 			ASSOCIATE_SERVICE_LINE_ID,
4443 			SYSTEM_ID,
4444 			SYSTEM_NAME,
4445 			Pricing_context,
4446 			Pricing_attribute1,
4447 			Pricing_attribute2,
4448 			Pricing_attribute3,
4449 			Pricing_attribute4,
4450 			Pricing_attribute5,
4451 			Pricing_attribute6,
4452 			Pricing_attribute7,
4453 			Pricing_attribute8,
4454 			Pricing_attribute9,
4455 			Pricing_attribute10,
4456 			Pricing_attribute11,
4457 			Pricing_attribute12,
4458 			Pricing_attribute13,
4459 			Pricing_attribute14,
4460 			Pricing_attribute15,
4461 			Pricing_attribute16,
4462 			Pricing_attribute17,
4463 			Pricing_attribute18,
4464 			Pricing_attribute19,
4465 			Pricing_attribute20,
4466 			Pricing_attribute21,
4467 			Pricing_attribute22,
4468 			Pricing_attribute23,
4469 			Pricing_attribute24,
4470 			Pricing_attribute25,
4471 			Pricing_attribute26,
4472 			Pricing_attribute27,
4473 			Pricing_attribute28,
4474 			Pricing_attribute29,
4475 			Pricing_attribute30,
4476 			Pricing_attribute31,
4477 			Pricing_attribute32,
4478 			Pricing_attribute33,
4479 			Pricing_attribute34,
4480 			Pricing_attribute35,
4481 			Pricing_attribute36,
4482 			Pricing_attribute37,
4483 			Pricing_attribute38,
4484 			Pricing_attribute39,
4485 			Pricing_attribute40,
4486 			Pricing_attribute41,
4487 			Pricing_attribute42,
4488 			Pricing_attribute43,
4489 			Pricing_attribute44,
4490 			Pricing_attribute45,
4491 			Pricing_attribute46,
4492 			Pricing_attribute47,
4493 			Pricing_attribute48,
4494 			Pricing_attribute49,
4495 			Pricing_attribute50,
4496 			Pricing_attribute51,
4497 			Pricing_attribute52,
4498 			Pricing_attribute53,
4499 			Pricing_attribute54,
4500 			Pricing_attribute55,
4501 			Pricing_attribute56,
4502 			Pricing_attribute57,
4503 			Pricing_attribute58,
4504 			Pricing_attribute59,
4505 			Pricing_attribute60,
4506 			Pricing_attribute61,
4507 			Pricing_attribute62,
4508 			Pricing_attribute63,
4509 			Pricing_attribute64,
4510 			Pricing_attribute65,
4511 			Pricing_attribute66,
4512 			Pricing_attribute67,
4513 			Pricing_attribute68,
4514 			Pricing_attribute69,
4515 			Pricing_attribute70,
4516 			Pricing_attribute71,
4517 			Pricing_attribute72,
4518 			Pricing_attribute73,
4519 			Pricing_attribute74,
4520 			Pricing_attribute75,
4521 			Pricing_attribute76,
4522 			Pricing_attribute77,
4523 			Pricing_attribute78,
4524 			Pricing_attribute79,
4525 			Pricing_attribute80,
4526 			Pricing_attribute81,
4527 			Pricing_attribute82,
4528 			Pricing_attribute83,
4529 			Pricing_attribute84,
4530 			Pricing_attribute85,
4531 			Pricing_attribute86,
4532 			Pricing_attribute87,
4533 			Pricing_attribute88,
4534 			Pricing_attribute89,
4535 			Pricing_attribute90,
4536 			Pricing_attribute91,
4537 			Pricing_attribute92,
4538 			Pricing_attribute93,
4539 			Pricing_attribute94,
4540 			Pricing_attribute95,
4541 			Pricing_attribute96,
4542 			Pricing_attribute97,
4543 			Pricing_attribute98,
4544 			Pricing_attribute99,
4545 			Pricing_attribute100,
4546 			BATCH_ID,
4547 			CASCADE_UPDATE,
4548 			CONTEXT,
4549 			ATTRIBUTE1,
4550 			ATTRIBUTE2,
4551 			ATTRIBUTE3,
4552 			ATTRIBUTE4,
4553 			ATTRIBUTE5,
4554 			ATTRIBUTE6,
4555 			ATTRIBUTE7,
4556 			ATTRIBUTE8,
4557 			ATTRIBUTE9,
4558 			ATTRIBUTE10,
4559 			ATTRIBUTE11,
4560 			ATTRIBUTE12,
4561 			ATTRIBUTE13,
4562 			ATTRIBUTE14,
4563 			ATTRIBUTE15,
4564 			ATTRIBUTE16,
4565 			ATTRIBUTE17,
4566 			ATTRIBUTE18,
4567 			ATTRIBUTE19,
4568 			ATTRIBUTE20,
4569 			ATTRIBUTE21,
4570 			ATTRIBUTE22,
4571 			ATTRIBUTE23,
4572 			ATTRIBUTE24,
4573 			ATTRIBUTE25,
4574 			ATTRIBUTE26,
4575 			ATTRIBUTE27,
4576 			ATTRIBUTE28,
4577 			ATTRIBUTE29,
4578 			ATTRIBUTE30
4579 		FROM CSI_WEBADI_STAGING
4580 		where BATCH_ID = p_entry_id
4581 		and INSTANCE_ID is not null;
4582 
4583 
4584     px_csi_txn_rec			csi_datastructures_pub.transaction_rec;
4585     u_instance_tbl			csi_datastructures_pub.instance_tbl;
4586 	u_ext_attrib_values_tbl	csi_datastructures_pub.extend_attrib_values_tbl;
4587     u_party_tbl				csi_datastructures_pub.party_tbl;
4588     u_account_tbl			csi_datastructures_pub.party_account_tbl;
4589     u_pricing_attrib_tbl	csi_datastructures_pub.pricing_attribs_tbl;
4590     u_org_assignments_tbl	csi_datastructures_pub.organization_units_tbl;
4591     u_instance_asset_tbl	csi_datastructures_pub.instance_asset_tbl;
4592     u_csi_txn_tbl			csi_datastructures_pub.transaction_tbl;
4593     u_grp_upd_error_tbl		csi_datastructures_pub.grp_upd_error_tbl;
4594 	l_instance_id_lst		csi_datastructures_pub.id_tbl;
4595     l_instance        		instances_for_update_csr%ROWTYPE;
4596 	c_relationship_tbl      csi_datastructures_pub.ii_relationship_tbl;
4597 	e_relationship_tbl      csi_datastructures_pub.ii_relationship_tbl;
4598 	l_instance_split_tbl	csi_datastructures_pub.instance_tbl;
4599 	c_pricing_attribs_tbl	csi_datastructures_pub.pricing_attribs_tbl;
4600 	u_pricing_attribs_tbl	csi_datastructures_pub.pricing_attribs_tbl;
4601 	TYPE varchar_tbl IS TABLE OF Varchar2(30) INDEX BY BINARY_INTEGER;
4602 	l_split_inst_num_tbl	varchar_tbl;
4603 	l_oks_inst_num_tbl		varchar_tbl;
4604 	TYPE number_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
4605 	l_chr_id_tbl			number_tbl;
4606 	l_attach2_line_id_tbl	number_tbl;
4607 	l_covlvl_id				NUMBER;
4608 	l_cov_line_tbl			OKS_IBINT_PUB.k_cov_line_tbl;
4609 	l_split_new_inst_rec	csi_datastructures_pub.instance_rec;
4610 	l_return_status			varchar2(1) := fnd_api.g_ret_sts_success;
4611 	l_msg_count				number;
4612 	l_msg_data				varchar2(2000);
4613 	inst_idx            	PLS_INTEGER;
4614 	party_idx            	PLS_INTEGER;
4615 	account_idx            	PLS_INTEGER;
4616 	split_idx				PLS_INTEGER;
4617 	c_rel_idx            	PLS_INTEGER;
4618 	e_rel_idx            	PLS_INTEGER;
4619 	oks_idx					PLS_INTEGER;
4620 	xls_idx					PLS_INTEGER;
4621 	c_pa_idx				PLS_INTEGER;
4622 	u_pa_idx				PLS_INTEGER;
4623 	l_msg_index     		NUMBER;
4624 	l_error_message 		VARCHAR2(2000);
4625 	l_quantity1         	NUMBER;
4626 	l_quantity2         	NUMBER;
4627 	is_party_change			BOOLEAN := FALSE;
4628 	add_party				BOOLEAN;
4629 	l_instance_party_id		NUMBER;
4630 	l_curr_partyid			NUMBER;
4631 	l_curr_accountid		NUMBER;
4632 	l_ip_account_id			NUMBER;
4633 	l_quantity				NUMBER;
4634 	l_splitqty				NUMBER;
4635 	l_rel_exists			BOOLEAN;
4636 	l_dummy_var      		VARCHAR2(30);
4637 	l_party_obj_ver      	NUMBER;
4638 	l_act_obj_ver      		NUMBER;
4639 	l_rel_obj_ver         	NUMBER;
4640 	l_relationship_id		NUMBER;
4641 	l_old_par_instance_id	NUMBER;
4642 	l_par_instance_id		NUMBER;
4643 	l_rel_instance_id_lst	csi_datastructures_pub.id_tbl;
4644 	l_instance_number				VARCHAR2(30);
4645 	l_serial_number_control_code 	NUMBER;
4646 	l_old_version_label				VARCHAR2(30);
4647 	l_object_version_number			NUMBER;
4648 	l_last_vld_organization_id		NUMBER;
4649 	isRecValid						BOOLEAN;
4650 	l_falied_count					NUMBER := 0;
4651 	l_updt_count					NUMBER;
4652 	l_batch_desc					Varchar2(2000);
4653 	l_note_id               		NUMBER;
4654 	l_pricing_attribute_id			NUMBER;
4655 	l_pa_obj_version_num			NUMBER;
4656 	l_operational_status_code		VARCHAR2(30);
4657 	l_internal_party_id				NUMBER;
4658 	l_cust_sys_id					NUMBER;
4659 	l_location_type_code 			VARCHAR2(30);
4660 
4661 BEGIN
4662 	debug('Start procedure: Process_webadi_update');
4663 	inst_idx	:= 0;
4664 	party_idx	:= 0;
4665 	account_idx := 0;
4666 	split_idx	:= 0;
4667 	c_rel_idx	:= 0;
4668 	e_rel_idx	:= 0;
4669 	oks_idx		:= 0;
4670 	xls_idx		:= 0;
4671 	c_pa_idx	:= 0;
4672 	u_pa_idx	:= 0;
4673 	--UPDATE PROCESSING STARTS
4674 	--Retrieving batch description
4675 	BEGIN
4676 		Select DESCRIPTION
4677 		into l_batch_desc
4678 		FROM csi_mass_edit_entries_vl
4679 		where ENTRY_ID = p_Entry_id;
4680 	EXCEPTION
4681 		WHEN no_data_found then
4682 			debug('Batch not found when trying to get its description.');
4683 			debug_out('The Mass update batch is not found. So the update records are not processed.');
4684 			RETURN;
4685 	END;
4686 
4687 	--Traversing through the cursor and processing for each instance to update
4688 	FOR l_instance IN instances_for_update_csr(p_entry_id)
4689 	LOOP
4690 		--Validations
4691 		isRecValid := true;
4692 		xls_idx := xls_idx + 1;
4693 
4694 		--Validating Owner party
4695 		IF(l_instance.OWNER_ID IS NULL AND
4696 			nvl(l_instance.OWNER_PARTY_TYPE, fnd_api.g_miss_char) <> 'HZ_PARTIES') THEN
4697 			IF(l_instance.OWNER_PARTY_NUM IS NOT NULL AND l_instance.OWNER_NAME IS NOT NULL) THEN
4698 				debug_out('In the uploaded update record #' || xls_idx ||
4699 						'. For Employee/Vendor party type, invalid Value(s) or invaid combination of' ||
4700 						' values for columns: Owner Party Num, Owner Name.');
4701 				isRecValid := false;
4702 			ELSE
4703 				IF(l_instance.OWNER_PARTY_NUM IS NULL AND l_instance.OWNER_NAME IS NOT NULL) THEN
4704 						debug_out('In the uploaded update record #' || xls_idx ||
4705 							'. For Employee/Vendor type, value not entered for column: Owner Party Num.');
4706 						isRecValid := false;
4707 				ELSIF(l_instance.OWNER_PARTY_NUM IS NOT NULL AND l_instance.OWNER_NAME IS NULL) THEN
4708 						debug_out('In the uploaded update record #' || xls_idx ||
4709 								'. For Employee/Vendor type, value not entered for column: Owner Name.');
4710 						isRecValid := false;
4711 					END IF;
4712 			END IF;
4713 		END IF;
4714 
4715 		IF(l_instance.OWNER_ID IS NULL AND l_instance.OWNER_PARTY_TYPE = 'HZ_PARTIES') THEN
4716 			IF(l_instance.OWNER_PARTY_NUM IS NULL) THEN
4717 				debug_out('In the uploaded update record #' || xls_idx ||
4718 					'. Value not entered for column: Owner Party Num.');
4719 				isRecValid := false;
4720 			ELSE
4721 				debug_out('In the uploaded update record #' || xls_idx ||
4722 					'. Invalid value entered for column: Owner Party Num.');
4723 				isRecValid := false;
4724 			END IF;
4725 		END IF;
4726 
4727 		--Validating Owner account
4728 		IF(l_instance.OWNER_ACCOUNT_ID IS NULL
4729 			AND l_instance.OWNER_ACCOUNT_NUMBER IS NOT NULL) THEN
4730 				debug_out('In the uploaded update record #' || xls_idx ||
4731 					'. Invalid value for column: Owner Account Number');
4732 				isRecValid := false;
4733 		END IF;
4734 
4735 		--Validating if there is a Owner account provided without a Owner party
4736 		IF(l_instance.OWNER_ACCOUNT_NUMBER IS NOT NULL
4737 			AND l_instance.OWNER_ID IS NULL) THEN
4738 				debug_out('In the uploaded update record #' || xls_idx ||
4739 						'. The column, Owner Account Number, cannot be used without a valid' ||
4740 						' value in the columns: Owner Party Num, Owner Name.');
4741 				isRecValid := false;
4742 		END IF;
4743 
4744 		--Validation of current location type
4745 		IF(l_instance.LOCATION_TYPE_CODE IS NULL) THEN
4746 			debug_out('In the uploaded update record #' || xls_idx ||
4747 				'. Value not entered for Mandatory column: Location Type Code.');
4748 			isRecValid := false;
4749 		END IF;
4750 
4751 		--Validation of current location
4752 		IF(l_instance.LOCATION_ID IS NULL) THEN
4753 			debug_out('In the uploaded update record #' || xls_idx ||
4754 				'. Value not entered for Mandatory column: Location Id.');
4755 			isRecValid := false;
4756 		END IF;
4757 
4758 		--Validating Bill To Party
4759 		IF(l_instance.ASSOCIATE_BILL_TO_PARTY_ID IS NULL
4760 		AND l_instance.ASSOCIATE_BILL_TO_PARTY_TYPE IS NOT NULL
4761 		AND l_instance.ASSOCIATE_BILL_TO_PARTY_TYPE <> 'HZ_PARTIES') THEN
4762 			IF(l_instance.ASSOCIATE_BILL_TO_PARTY_NUMBER IS NOT NULL
4763 				AND l_instance.ASSOCIATE_BILL_TO_PARTY_NAME IS NOT NULL) THEN
4764 					debug_out('In the uploaded update record #' || xls_idx ||
4765 							'. For Employee/Vendor party type, invalid Value(s) ' ||
4766 							'or invaid combination of values for: ' ||
4767 							'Associate Bill To Party Number, Associate Bill To Party Name.');
4768 					isRecValid := false;
4769 			ELSE
4770 				IF(l_instance.ASSOCIATE_BILL_TO_PARTY_NUMBER IS NULL
4771 					AND l_instance.ASSOCIATE_BILL_TO_PARTY_NAME IS NOT NULL) THEN
4772 						debug_out('In the uploaded update record #' || xls_idx ||
4773 								'. For Employee/Vendor party type, value not entered for' ||
4774 								' column: Associate Bill To Party Number.');
4775 					isRecValid := false;
4776 				ELSIF(l_instance.ASSOCIATE_BILL_TO_PARTY_NUMBER IS NOT NULL
4777 					AND l_instance.ASSOCIATE_BILL_TO_PARTY_NAME IS NULL) THEN
4778 					debug_out('In the uploaded update record #' || xls_idx ||
4779 							'. For Employee/Vendor party type, value not entered for ' ||
4780 							'column: Associate Bill To Party Name.');
4781 					isRecValid := false;
4782 				END IF;
4783 			END IF;
4784 		END IF;
4785 
4786 		IF(l_instance.ASSOCIATE_BILL_TO_PARTY_ID IS NULL
4787 		AND l_instance.ASSOCIATE_BILL_TO_PARTY_TYPE = 'HZ_PARTIES'
4788 		AND l_instance.ASSOCIATE_BILL_TO_PARTY_NUMBER IS NOT NULL) THEN
4789 			debug_out('In the uploaded update record #' || xls_idx ||
4790 					'. Invalid value entered for column: Associate Bill To Party Number.');
4791 			isRecValid := false;
4792 		END IF;
4793 
4794 		--Validating Bill To account
4795 		IF(l_instance.ASSOCIATE_BILL_TO_ACCT_ID IS NULL
4796 			AND l_instance.ASSOCIATE_BILL_TO_ACCT_NUM IS NOT NULL) THEN
4797 				debug_out('In the uploaded update record #' || xls_idx ||
4798 					'. Invalid value for column: Associate Bill To Acct Num');
4799 				isRecValid := false;
4800 		END IF;
4801 
4802 		--Validating if there is a Bill To account provided without a Bill To party
4803 		IF(l_instance.ASSOCIATE_BILL_TO_ACCT_NUM IS NOT NULL
4804 			AND l_instance.ASSOCIATE_BILL_TO_PARTY_ID IS NULL) THEN
4805 				debug_out('In the uploaded update record #' || xls_idx ||
4806 						'. The column, Associate Bill To Acct Num, cannot be used without a valid' ||
4807 						' value in the columns: Associate Bill To Party Number, Associate Bill To Party Name');
4808 				isRecValid := false;
4809 		END IF;
4810 
4811 
4812 		--Validating Ship To Party
4813 		IF(l_instance.ASSOCIATE_SHIP_TO_PARTY_ID IS NULL
4814 		AND l_instance.ASSOCIATE_SHIP_TO_PARTY_TYPE IS NOT NULL
4815 		AND l_instance.ASSOCIATE_SHIP_TO_PARTY_TYPE <> 'HZ_PARTIES') THEN
4816 			IF(l_instance.ASSOCIATE_SHIP_TO_PARTY_NUMBER IS NOT NULL
4817 			AND l_instance.ASSOCIATE_SHIP_TO_PARTY_NAME IS NOT NULL) THEN
4818 				debug_out('In the uploaded update record #' || xls_idx ||
4819 						'. For Employee/Vendor party type, Invalid Value(s) or invaid' ||
4820 						' combination of values for: ' ||
4821 						'Associate Ship To Party Number, Associate Ship To Party Name.');
4822 				isRecValid := false;
4823 			ELSE
4824 				IF(l_instance.ASSOCIATE_SHIP_TO_PARTY_NUMBER IS NULL
4825 					AND l_instance.ASSOCIATE_SHIP_TO_PARTY_NAME IS NOT NULL) THEN
4826 						debug_out('In the uploaded update record #' || xls_idx ||
4827 								'. For Employee/Vendor party type, value not entered for' ||
4828 								' column: Associate Ship To Party Number.');
4829 						isRecValid := false;
4830 				ELSIF(l_instance.ASSOCIATE_SHIP_TO_PARTY_NUMBER IS NOT NULL
4831 					AND l_instance.ASSOCIATE_SHIP_TO_PARTY_NAME IS NULL) THEN
4832 					debug_out('In the uploaded update record #' || xls_idx ||
4833 							'. For Employee/Vendor party type, value not entered for ' ||
4834 							'column: Associate Ship To Party Name.');
4835 					isRecValid := false;
4836 				END IF;
4837 			END IF;
4838 		END IF;
4839 
4840 		IF(l_instance.ASSOCIATE_SHIP_TO_PARTY_ID IS NULL
4841 		AND l_instance.ASSOCIATE_SHIP_TO_PARTY_TYPE = 'HZ_PARTIES'
4842 		AND l_instance.ASSOCIATE_SHIP_TO_PARTY_NUMBER IS NOT NULL) THEN
4843 			debug_out('In the uploaded update record #' || xls_idx ||
4844 					'. Invalid value entered for column: Associate Ship To Party Number.');
4845 			isRecValid := false;
4846 		END IF;
4847 
4848 		--Validating Ship To account
4849 		IF(l_instance.ASSOCIATE_SHIP_TO_ACCT_ID IS NULL
4850 			AND l_instance.ASSOCIATE_SHIP_TO_ACCT_NUM IS NOT NULL) THEN
4851 				debug_out('In the uploaded update record #' || xls_idx ||
4852 					'. Invalid value for column: Associate Ship To Acct Num');
4853 				isRecValid := false;
4854 		END IF;
4855 
4856 		--Validating if there is a Ship To account provided without a Ship To party
4857 		IF(l_instance.ASSOCIATE_SHIP_TO_ACCT_NUM IS NOT NULL
4858 			AND l_instance.ASSOCIATE_SHIP_TO_PARTY_ID IS NULL) THEN
4859 				debug_out('In the uploaded update record #' || xls_idx ||
4860 						'. The column, Associate Ship To Acct Num, cannot be used without a valid' ||
4861 						' value in the columns: Associate Ship To Party Number, Associate Ship To Party Name');
4862 				isRecValid := false;
4863 		END IF;
4864 
4865 		--Validation Associate Contract Number
4866 		IF(l_instance.ASSOCIATE_CONTRACT_ID IS NULL
4867 			AND (l_instance.ASSOCIATE_CONTRACT_NUMBER IS NOT NULL OR l_instance.ASSOCIATE_CONTRACT_MODIFIER IS NOT NULL)) THEN
4868 				debug_out('In the uploaded update record #' || xls_idx ||
4869 					'. Invalid value/combination of values for columns: Associate Contract Number, Associate Contract Modifier');
4870 				isRecValid := false;
4871 		END IF;
4872 
4873 		--Validating Service line
4874 		IF(l_instance.ASSOCIATE_SERVICE_LINE_ID IS NULL
4875 			AND l_instance.ASSOCIATE_SERVICE_LINE IS NOT NULL) THEN
4876 				debug_out('In the uploaded update record #' || xls_idx ||
4877 					'. Invalid value for column: Associate Service Line');
4878 				isRecValid := false;
4879 		END IF;
4880 
4881 		--Validating if there is a Service line provided without a Contract
4882 		IF(l_instance.ASSOCIATE_SERVICE_LINE IS NOT NULL
4883 			AND l_instance.ASSOCIATE_CONTRACT_ID IS NULL) THEN
4884 				debug_out('In the uploaded update record #' || xls_idx ||
4885 						'. The column, Associate Service Line, cannot be used without a valid' ||
4886 						' value in the columns: Associate Contract Number, Associate Contract Modifier');
4887 				isRecValid := false;
4888 		END IF;
4889 
4890 		--Validating if there is a  Contract provided without a Service line
4891 		IF(l_instance.ASSOCIATE_CONTRACT_ID IS NOT NULL
4892 			AND l_instance.ASSOCIATE_SERVICE_LINE IS NULL) THEN
4893 				debug_out('In the uploaded update record #' || xls_idx ||
4894 						'. The column, Associate Service Line should be provided ' ||
4895 						' for the contract, specified with Associate Contract Number and Associate Contract Modifier');
4896 				isRecValid := false;
4897 		END IF;
4898 
4899 		--Validating System
4900 		IF(l_instance.SYSTEM_ID IS NULL
4901 			AND l_instance.SYSTEM_NAME IS NOT NULL) THEN
4902 				debug_out('In the uploaded update record #' || xls_idx ||
4903 					'. Invalid value for column: System Name');
4904 				isRecValid := false;
4905 		END IF;
4906 
4907 		IF(l_instance.SYSTEM_ID IS NOT NULL) THEN
4908 			BEGIN
4909 				SELECT system_id
4910 				INTO l_cust_sys_id
4911 				FROM
4912 				(	SELECT sys.system_id
4913 					FROM csi_systems_vl sys, HZ_PARTIES hzp, HZ_CUST_ACCOUNTS acct,
4914 						CSI_LOOKUPS LK
4915 					WHERE sys.CUSTOMER_ID = acct.CUST_ACCOUNT_ID
4916 						and acct.PARTY_ID = hzp.PARTY_ID
4917 						and acct.account_number = l_instance.OWNER_ACCOUNT_NUMBER
4918 						and sys.SYSTEM_TYPE_CODE = LK.LOOKUP_CODE(+)
4919 						and LK.LOOKUP_TYPE (+) = 'CSI_SYSTEM_TYPE'
4920 						and sys.name = l_instance.SYSTEM_NAME
4921 					UNION
4922 					SELECT sys.system_id
4923 					FROM csi_systems_vl sys, HZ_PARTIES hzp, HZ_CUST_ACCOUNTS acct,
4924 						HZ_CUST_ACCT_RELATE_ALL acctall, CSI_LOOKUPS LK
4925 					WHERE sys.CUSTOMER_ID = acctall.RELATED_CUST_ACCOUNT_ID
4926 						and sys.CUSTOMER_ID = acct.CUST_ACCOUNT_ID
4927 						and acct.PARTY_ID = hzp.PARTY_ID
4928 						and acctall.CUST_ACCOUNT_ID = acct.CUST_ACCOUNT_ID
4929 						and acct.account_number = l_instance.OWNER_ACCOUNT_NUMBER
4930 						and sys.SYSTEM_TYPE_CODE = LK.LOOKUP_CODE(+)
4931 						and LK.LOOKUP_TYPE (+) = 'CSI_SYSTEM_TYPE'
4932 						and sys.name = l_instance.SYSTEM_NAME
4933 				);
4934 			EXCEPTION
4935 					WHEN no_data_found THEN
4936 						l_cust_sys_id := NULL;
4937 					WHEN others THEN
4938 						l_cust_sys_id := 1;
4939 			END;
4940 
4941 			IF(l_cust_sys_id IS NULL) THEN
4942 				debug_out('In the uploaded update record #' || xls_idx ||
4943 					'. WARNING: The Owner account of the System is neither ' ||
4944 					'same nor a related account of the Item Instance Owner.');
4945 			END IF;
4946 		END IF;
4947 
4948 		--populating few paramters which are retrieved from the database.
4949 		BEGIN
4950 			Select OBJECT_VERSION_NUMBER, LAST_VLD_ORGANIZATION_ID, LOCATION_TYPE_CODE
4951 			into l_object_version_number, l_last_vld_organization_id, l_location_type_code
4952 			from csi_item_instances
4953 			where instance_id = l_instance.INSTANCE_ID;
4954 		EXCEPTION
4955 			WHEN others THEN
4956 				debug_out('In the uploaded update record #' || xls_idx ||
4957 					' the Instance ' || l_instance.PRODUCT_NUMBER ||
4958 					' is not found');
4959 				debug('In the uploaded update record #' || xls_idx ||
4960 					' the Instance ' || l_instance.PRODUCT_NUMBER ||
4961 					' is not found, while retrieving OBJECT_VERSION_NUMBER, LAST_VLD_ORGANIZATION_ID');
4962 				isRecValid := false;
4963 		END;
4964 
4965 		--Retrieving serial control code
4966 		BEGIN
4967 			 SELECT SERIAL_NUMBER_CONTROL_CODE
4968 			 INTO l_serial_number_control_code
4969 			 FROM mtl_system_items_b
4970 			 WHERE INVENTORY_ITEM_ID = l_instance.ITEM_ID
4971 			 AND  ORGANIZATION_ID = l_last_vld_organization_id;
4972 		EXCEPTION
4973 			when no_data_found then
4974 				debug_out('In the uploaded update record #' || xls_idx ||
4975 				' It is an invalid Item for the Organization chosen.');
4976 				isRecValid := false;
4977 		END;
4978 
4979 		--Retrieving current Owner details
4980 		l_ip_account_id		:= null;
4981 		l_instance_party_id	:= null;
4982 		BEGIN
4983 			Select cip.INSTANCE_PARTY_ID, cip.PARTY_ID, cia.PARTY_ACCOUNT_ID, cia.IP_ACCOUNT_ID,
4984 					CIP.OBJECT_VERSION_NUMBER, CIA.OBJECT_VERSION_NUMBER
4985 			into l_instance_party_id, l_curr_partyid, l_curr_accountid, l_ip_account_id,
4986 					l_party_obj_ver, l_act_obj_ver
4987 			from CSI_I_PARTIES cip, csi_ip_accounts cia
4988 			where cip.INSTANCE_PARTY_ID = cia.INSTANCE_PARTY_ID
4989 			AND cip.RELATIONSHIP_TYPE_CODE  = 'OWNER' AND cip.CONTACT_FLAG = 'N'
4990 			AND Nvl(cip.ACTIVE_START_DATE, SYSDATE - 1) < SYSDATE
4991 			AND Nvl(cip.ACTIVE_END_DATE, SYSDATE  + 1) > SYSDATE
4992 			AND Nvl(cia.ACTIVE_START_DATE, SYSDATE - 1) < SYSDATE
4993 			AND Nvl(cia.ACTIVE_END_DATE, SYSDATE  + 1) > SYSDATE
4994 			AND cip.INSTANCE_ID = l_instance.INSTANCE_ID;
4995 		EXCEPTION
4996 			when no_data_found then
4997 				BEGIN
4998 					Select cip.INSTANCE_PARTY_ID, cip.PARTY_ID,	CIP.OBJECT_VERSION_NUMBER
4999 					into l_instance_party_id, l_curr_partyid, l_party_obj_ver
5000 					from CSI_I_PARTIES cip
5001 					where cip.RELATIONSHIP_TYPE_CODE  = 'OWNER' AND cip.CONTACT_FLAG = 'N'
5002 					AND Nvl(cip.ACTIVE_START_DATE, SYSDATE - 1) < SYSDATE
5003 					AND Nvl(cip.ACTIVE_END_DATE, SYSDATE  + 1) > SYSDATE
5004 					AND cip.INSTANCE_ID = l_instance.INSTANCE_ID;
5005 				EXCEPTION
5006 					when no_data_found then
5007 					debug_out('In the uploaded update record #' || xls_idx ||
5008 						' for instance ' || l_instance.PRODUCT_NUMBER ||
5009 						' current Owner details are not found.');
5010 					isRecValid := false;
5011 				END;
5012 		END;
5013 
5014 		--Retrieving Instance ID for the parant
5015 		l_par_instance_id := null;
5016 		IF(l_instance.PARENT_INSTANCE IS NOT NULL) THEN
5017 			BEGIN
5018 				SELECT instance_id INTO l_par_instance_id
5019 				FROM csi_item_instances
5020 				WHERE instance_number = l_instance.PARENT_INSTANCE;
5021 			EXCEPTION
5022 				when no_data_found then
5023 					debug_out('In the uploaded update record #' || xls_idx ||
5024 						'. Invalid value for column: Parent Instance');
5025 				isRecValid := false;
5026 			END;
5027 		END IF;
5028 
5029 		--Retrieving Instance ID for the old parant instance
5030 		l_old_par_instance_id := null;
5031 		IF(l_instance.OLD_PARENT_INSTANCE IS NOT NULL) THEN
5032 			BEGIN
5033 				SELECT instance_id INTO l_old_par_instance_id
5034 				FROM csi_item_instances
5035 				WHERE instance_number = l_instance.OLD_PARENT_INSTANCE;
5036 			EXCEPTION
5037 				when no_data_found then
5038 					debug_out('In the uploaded update record #' || xls_idx ||
5039 						'. Invalid value for hidden column: Old Parent Instance.');
5040 				isRecValid := false;
5041 			END;
5042 		END IF;
5043 
5044 		--Validating to see if the instance is not an inventory instance
5045 		IF(l_location_type_code = 'INVENTORY') THEN
5046 				debug_out('In the uploaded update record #' || xls_idx ||
5047 					'. Update of Inventory instance is not allowed.');
5048 				isRecValid := false;
5049 		END IF;
5050 
5051 		--Validating Operational Status Code
5052 		BEGIN
5053 			SELECT operational_status_code INTO l_operational_status_code
5054 			FROM csi_item_instances
5055 			WHERE instance_id = l_instance.INSTANCE_ID;
5056 		EXCEPTION
5057 			when no_data_found then
5058 				debug_out('In the uploaded update record #' || xls_idx ||
5059 					'. Invalid value for hidden column: Instance Id.');
5060 			isRecValid := false;
5061 		END;
5062 		IF(nvl(l_instance.OPERATIONAL_STATUS_CODE, FND_API.G_MISS_CHAR) <>
5063 				nvl(l_operational_status_code, FND_API.G_MISS_CHAR)) THEN
5064 				debug_out('In the uploaded update record #' || xls_idx ||
5065 					'. Change of value is not supported for the column: Operational Status Code');
5066 				isRecValid := false;
5067 		END IF;
5068 
5069 		--Owner Change?
5070 		is_party_change := false;
5071 		IF(l_curr_partyid <> l_instance.OWNER_ID OR
5072 				l_curr_accountid <> l_instance.OWNER_ACCOUNT_ID) THEN
5073 			is_party_change := true;
5074 		END IF;
5075 
5076 		--Validations end, processing starts
5077 
5078 		IF(NOT isRecValid) THEN
5079 			debug_out('The uploaded update record #' || xls_idx ||
5080 				' is not processed due to the failure of the above mentioned validation(s).');
5081 			l_falied_count := l_falied_count + 1;
5082 		ELSE
5083 			--Processing of the valid records
5084 			inst_idx := inst_idx + 1;
5085 			debug('Processing Instance Record ' || inst_idx ||
5086 									' for Update. Instance Number: ' || l_instance.PRODUCT_NUMBER);
5087 
5088 			--Updating the instance
5089 			u_instance_tbl(inst_idx).INSTANCE_ID       				:= l_instance.INSTANCE_ID;
5090 			--u_instance_tbl(inst_idx).INSTANCE_NUMBER   				:= l_instance.PRODUCT_NUMBER;
5091 			u_instance_tbl(inst_idx).SERIAL_NUMBER 					:= l_instance.SERIAL_NUMBER;
5092 			u_instance_tbl(inst_idx).INSTANCE_DESCRIPTION   		:= l_instance.INSTANCE_DESCRIPTION;
5093 			u_instance_tbl(inst_idx).LOCATION_TYPE_CODE 			:= l_instance.LOCATION_TYPE_CODE;
5094 			u_instance_tbl(inst_idx).LOCATION_ID 					:= l_instance.LOCATION_ID;
5095 			u_instance_tbl(inst_idx).EXTERNAL_REFERENCE 			:= l_instance.EXTERNAL_REF;
5096 			u_instance_tbl(inst_idx).INSTANCE_STATUS_ID 			:= l_instance.INSTANCE_STATUS_ID;
5097 			u_instance_tbl(inst_idx).INSTANCE_TYPE_CODE 			:= l_instance.PRODUCT_TYPE_CODE;
5098 			u_instance_tbl(inst_idx).ACTIVE_END_DATE  				:= l_instance.EXPIRATION_DATE;
5099 			u_instance_tbl(inst_idx).install_date 					:= l_instance.INSTALL_DATE;
5100 			u_instance_tbl(inst_idx).INSTALL_LOCATION_TYPE_CODE 	:= l_instance.INSTALL_LOCATION_TYPE_CODE;
5101 			u_instance_tbl(inst_idx).INSTALL_LOCATION_ID 			:= l_instance.INSTALL_LOCATION_ID;
5102 			u_instance_tbl(inst_idx).operational_status_code 		:= l_instance.OPERATIONAL_STATUS_CODE;
5103 			u_instance_tbl(inst_idx).CASCADE_OWNERSHIP_FLAG			:= l_instance.CASCADE_UPDATE;
5104 			u_instance_tbl(inst_idx).CONTEXT						:= l_instance.CONTEXT;
5105 			u_instance_tbl(inst_idx).ATTRIBUTE1						:= l_instance.ATTRIBUTE1;
5106 			u_instance_tbl(inst_idx).ATTRIBUTE2						:= l_instance.ATTRIBUTE2;
5107 			u_instance_tbl(inst_idx).ATTRIBUTE3						:= l_instance.ATTRIBUTE3;
5108 			u_instance_tbl(inst_idx).ATTRIBUTE4						:= l_instance.ATTRIBUTE4;
5109 			u_instance_tbl(inst_idx).ATTRIBUTE5						:= l_instance.ATTRIBUTE5;
5110 			u_instance_tbl(inst_idx).ATTRIBUTE6						:= l_instance.ATTRIBUTE6;
5111 			u_instance_tbl(inst_idx).ATTRIBUTE7						:= l_instance.ATTRIBUTE7;
5112 			u_instance_tbl(inst_idx).ATTRIBUTE8						:= l_instance.ATTRIBUTE8;
5113 			u_instance_tbl(inst_idx).ATTRIBUTE9						:= l_instance.ATTRIBUTE9;
5114 			u_instance_tbl(inst_idx).ATTRIBUTE10					:= l_instance.ATTRIBUTE10;
5115 			u_instance_tbl(inst_idx).ATTRIBUTE11					:= l_instance.ATTRIBUTE11;
5116 			u_instance_tbl(inst_idx).ATTRIBUTE12					:= l_instance.ATTRIBUTE12;
5117 			u_instance_tbl(inst_idx).ATTRIBUTE13					:= l_instance.ATTRIBUTE13;
5118 			u_instance_tbl(inst_idx).ATTRIBUTE14					:= l_instance.ATTRIBUTE14;
5119 			u_instance_tbl(inst_idx).ATTRIBUTE15					:= l_instance.ATTRIBUTE15;
5120 			u_instance_tbl(inst_idx).ATTRIBUTE16					:= l_instance.ATTRIBUTE16;
5121 			u_instance_tbl(inst_idx).ATTRIBUTE17					:= l_instance.ATTRIBUTE17;
5122 			u_instance_tbl(inst_idx).ATTRIBUTE18					:= l_instance.ATTRIBUTE18;
5123 			u_instance_tbl(inst_idx).ATTRIBUTE19					:= l_instance.ATTRIBUTE19;
5124 			u_instance_tbl(inst_idx).ATTRIBUTE20					:= l_instance.ATTRIBUTE20;
5125 			u_instance_tbl(inst_idx).ATTRIBUTE21					:= l_instance.ATTRIBUTE21;
5126 			u_instance_tbl(inst_idx).ATTRIBUTE22					:= l_instance.ATTRIBUTE22;
5127 			u_instance_tbl(inst_idx).ATTRIBUTE23					:= l_instance.ATTRIBUTE23;
5128 			u_instance_tbl(inst_idx).ATTRIBUTE24					:= l_instance.ATTRIBUTE24;
5129 			u_instance_tbl(inst_idx).ATTRIBUTE25					:= l_instance.ATTRIBUTE25;
5130 			u_instance_tbl(inst_idx).ATTRIBUTE26					:= l_instance.ATTRIBUTE26;
5131 			u_instance_tbl(inst_idx).ATTRIBUTE27					:= l_instance.ATTRIBUTE27;
5132 			u_instance_tbl(inst_idx).ATTRIBUTE28					:= l_instance.ATTRIBUTE28;
5133 			u_instance_tbl(inst_idx).ATTRIBUTE29					:= l_instance.ATTRIBUTE29;
5134 			u_instance_tbl(inst_idx).ATTRIBUTE30					:= l_instance.ATTRIBUTE30;
5135 			u_instance_tbl(inst_idx).SYSTEM_ID  					:= l_instance.SYSTEM_ID;
5136 
5137 			u_instance_tbl(inst_idx).OBJECT_VERSION_NUMBER 			:= l_object_version_number;
5138 			u_instance_tbl(inst_idx).VLD_ORGANIZATION_ID 			:= l_last_vld_organization_id;
5139 			IF(is_party_change) THEN
5140 				u_instance_tbl(inst_idx).CALL_CONTRACTS          		:=  FND_API.G_FALSE;
5141 			ELSE
5142 				u_instance_tbl(inst_idx).CALL_CONTRACTS          		:=  FND_API.G_TRUE;
5143 			END IF;
5144 			--Populating Version label, if it is changed wrt to the old version label
5145 			IF l_instance.VERSION_LABEL IS NOT NULL THEN
5146 				BEGIN
5147 					SELECT cil1.VERSION_LABEL
5148 					INTO l_old_version_label
5149 					FROM csi_i_version_labels cil1
5150 					WHERE cil1.instance_id = l_instance.INSTANCE_ID
5151 					AND nvl(cil1.DATE_TIME_STAMP, sysdate) = nvl ( (SELECT max(cil2.DATE_TIME_STAMP)
5152 					           FROM csi_i_version_labels cil2
5153 								WHERE cil2.instance_id = cil1.instance_id ) , sysdate );
5154 
5155 				EXCEPTION
5156 					when no_data_found then
5157 							l_old_version_label	:= null;
5158 				END;
5159 
5160 				IF l_old_version_label <> l_instance.VERSION_LABEL THEN
5161 					debug('Change in Version label.');
5162 					u_instance_tbl(inst_idx).VERSION_LABEL	:= l_instance.VERSION_LABEL;
5163 				END IF;
5164 			END IF;
5165 
5166 			--Checking for serial control code, to allow quantity update only for non serial
5167 			IF(l_serial_number_control_code = 1) THEN
5168 				u_instance_tbl(inst_idx).QUANTITY := l_instance.QUANTITY;
5169 			END IF;
5170 
5171 			--Records eligible for split
5172 			IF(l_instance.SPLIT_QTY IS NOT null AND l_instance.SPLIT_QTY <> 0) THEN
5173 				IF(l_serial_number_control_code = 1) THEN
5174 					debug('Populating Split Instance details.');
5175 					split_idx := split_idx +1;
5176 					l_instance_split_tbl(split_idx) := u_instance_tbl(inst_idx);
5177 					l_split_inst_num_tbl(split_idx)	:= l_instance.PRODUCT_NUMBER;
5178 				ELSE
5179 					debug_out('Split for a Serial Item Instance, ' || l_instance.PRODUCT_NUMBER || ' is not allowed');
5180 				END IF;
5181 			END IF;
5182 
5183 			--Contract association recs
5184 			IF(l_instance.ASSOCIATE_CONTRACT_ID IS NOT NULL
5185 				AND l_instance.ASSOCIATE_SERVICE_LINE_ID IS NOT NULL)
5186 			THEN
5187 				debug('Populating Instnace association details.');
5188 				oks_idx := oks_idx + 1;
5189 				l_cov_line_tbl(oks_idx).customer_product_id := l_instance.instance_id;
5190 				l_cov_line_tbl(oks_idx).quantity := l_instance.quantity;
5191 				l_cov_line_tbl(oks_idx).Unit_of_measure := l_instance.UOM;
5192 				l_cov_line_tbl(oks_idx).Inventory_item_id := l_instance.Item_Id;
5193 				l_cov_line_tbl(oks_idx).Customer_acct_id := l_instance.Owner_Account_Id;
5194 				l_cov_line_tbl(oks_idx).Organization_id := l_last_vld_organization_id;
5195 				l_cov_line_tbl(oks_idx).parent_tbl_idx	:= inst_idx;
5196 				l_oks_inst_num_tbl(oks_idx)		:= l_instance.PRODUCT_NUMBER;
5197 				l_chr_id_tbl(oks_idx) 			:= l_instance.ASSOCIATE_CONTRACT_ID;
5198 				l_attach2_line_id_tbl(oks_idx) 	:= l_instance.ASSOCIATE_SERVICE_LINE_ID;
5199 			END IF;
5200 
5201 			--Pricing attributes rec
5202 			l_pricing_attribute_id := null;
5203 			BEGIN
5204 				SELECT pricing_attribute_id, object_version_number
5205 				INTO l_pricing_attribute_id, l_pa_obj_version_num
5206 				FROM csi_i_pricing_attribs
5207 				WHERE Nvl(active_end_date, SYSDATE + 1) > SYSDATE
5208 				AND instance_id = l_instance.instance_id;
5209 			EXCEPTION
5210 				WHEN no_data_found THEN
5211 					debug('Pricing Attributes does not exist for Instance: ' ||
5212 														l_instance.PRODUCT_NUMBER);
5213 					l_pricing_attribute_id := null;
5214 				WHEN OTHERS THEN
5215 					debug('Error while checking the existance of Pricing ' ||
5216 						'attributes for Instance: ' || l_instance.PRODUCT_NUMBER);
5217 					debug('Error: ' || to_char(SQLCODE)||substr(SQLERRM, 1, 255));
5218 					debug_out('Could not create/update Pricing attributes for Instance: ' ||
5219 						l_instance.PRODUCT_NUMBER ||
5220 						'. Please check the request log, for further error details');
5221 					l_pricing_attribute_id := FND_API.G_MISS_NUM;
5222 			END;
5223 
5224 			IF(l_instance.Pricing_context IS NOT NULL) THEN
5225 				IF(l_pricing_attribute_id IS NULL) THEN
5226 					debug('Populating Create Pricing attributes details');
5227 					c_pa_idx := c_pa_idx + 1;
5228 					c_pricing_attribs_tbl(c_pa_idx).pricing_context
5229 														:= l_instance.Pricing_context;
5230 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute1
5231 														:= l_instance.pricing_attribute1;
5232 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute2
5233 														:= l_instance.pricing_attribute2;
5234 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute3
5235 														:= l_instance.pricing_attribute3;
5236 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute4
5237 														:= l_instance.pricing_attribute4;
5238 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute5
5239 														:= l_instance.pricing_attribute5;
5240 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute6
5241 														:= l_instance.pricing_attribute6;
5242 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute7
5243 														:= l_instance.pricing_attribute7;
5244 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute8
5245 														:= l_instance.pricing_attribute8;
5246 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute9
5247 														:= l_instance.pricing_attribute9;
5248 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute10
5249 														:= l_instance.pricing_attribute10;
5250 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute11
5251 														:= l_instance.pricing_attribute11;
5252 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute12
5253 														:= l_instance.pricing_attribute12;
5254 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute13
5255 														:= l_instance.pricing_attribute13;
5256 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute14
5257 														:= l_instance.pricing_attribute14;
5258 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute15
5259 														:= l_instance.pricing_attribute15;
5260 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute16
5261 														:= l_instance.pricing_attribute16;
5262 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute17
5263 														:= l_instance.pricing_attribute17;
5264 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute18
5265 														:= l_instance.pricing_attribute18;
5266 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute19
5267 														:= l_instance.pricing_attribute19;
5268 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute20
5269 														:= l_instance.pricing_attribute20;
5270 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute21
5271 														:= l_instance.pricing_attribute21;
5272 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute22
5273 														:= l_instance.pricing_attribute22;
5274 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute23
5275 														:= l_instance.pricing_attribute23;
5276 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute24
5277 														:= l_instance.pricing_attribute24;
5278 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute25
5279 														:= l_instance.pricing_attribute25;
5280 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute26
5281 														:= l_instance.pricing_attribute26;
5282 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute27
5283 														:= l_instance.pricing_attribute27;
5284 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute28
5285 														:= l_instance.pricing_attribute28;
5286 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute29
5287 														:= l_instance.pricing_attribute29;
5288 					c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute30
5289 														:= l_instance.pricing_attribute30;
5290 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute31	:= l_instance.pricing_attribute31;
5291 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute32	:= l_instance.pricing_attribute32;
5292 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute33	:= l_instance.pricing_attribute33;
5293 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute34	:= l_instance.pricing_attribute34;
5294 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute35	:= l_instance.pricing_attribute35;
5295 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute36	:= l_instance.pricing_attribute36;
5296 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute37	:= l_instance.pricing_attribute37;
5297 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute38	:= l_instance.pricing_attribute38;
5298 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute39	:= l_instance.pricing_attribute39;
5299 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute40	:= l_instance.pricing_attribute40;
5300 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute41	:= l_instance.pricing_attribute41;
5301 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute42	:= l_instance.pricing_attribute42;
5302 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute43	:= l_instance.pricing_attribute43;
5303 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute44	:= l_instance.pricing_attribute44;
5304 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute45	:= l_instance.pricing_attribute45;
5305 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute46	:= l_instance.pricing_attribute46;
5306 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute47	:= l_instance.pricing_attribute47;
5307 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute48	:= l_instance.pricing_attribute48;
5308 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute49	:= l_instance.pricing_attribute49;
5309 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute50	:= l_instance.pricing_attribute50;
5310 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute51	:= l_instance.pricing_attribute51;
5311 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute52	:= l_instance.pricing_attribute52;
5312 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute53	:= l_instance.pricing_attribute53;
5313 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute54	:= l_instance.pricing_attribute54;
5314 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute55	:= l_instance.pricing_attribute55;
5315 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute56	:= l_instance.pricing_attribute56;
5316 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute57	:= l_instance.pricing_attribute57;
5317 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute58	:= l_instance.pricing_attribute58;
5318 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute59	:= l_instance.pricing_attribute59;
5319 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute60	:= l_instance.pricing_attribute60;
5320 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute61	:= l_instance.pricing_attribute61;
5321 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute62	:= l_instance.pricing_attribute62;
5322 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute63	:= l_instance.pricing_attribute63;
5323 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute64	:= l_instance.pricing_attribute64;
5324 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute65	:= l_instance.pricing_attribute65;
5325 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute66	:= l_instance.pricing_attribute66;
5326 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute67	:= l_instance.pricing_attribute67;
5327 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute68	:= l_instance.pricing_attribute68;
5328 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute69	:= l_instance.pricing_attribute69;
5329 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute70	:= l_instance.pricing_attribute70;
5330 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute71	:= l_instance.pricing_attribute71;
5331 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute72	:= l_instance.pricing_attribute72;
5332 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute73	:= l_instance.pricing_attribute73;
5333 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute74	:= l_instance.pricing_attribute74;
5334 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute75	:= l_instance.pricing_attribute75;
5335 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute76	:= l_instance.pricing_attribute76;
5336 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute77	:= l_instance.pricing_attribute77;
5337 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute78	:= l_instance.pricing_attribute78;
5338 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute79	:= l_instance.pricing_attribute79;
5339 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute80	:= l_instance.pricing_attribute80;
5340 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute81	:= l_instance.pricing_attribute81;
5341 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute82	:= l_instance.pricing_attribute82;
5342 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute83	:= l_instance.pricing_attribute83;
5343 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute84	:= l_instance.pricing_attribute84;
5344 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute85	:= l_instance.pricing_attribute85;
5345 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute86	:= l_instance.pricing_attribute86;
5346 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute87	:= l_instance.pricing_attribute87;
5347 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute88	:= l_instance.pricing_attribute88;
5348 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute89	:= l_instance.pricing_attribute89;
5349 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute90	:= l_instance.pricing_attribute90;
5350 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute91	:= l_instance.pricing_attribute91;
5351 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute92	:= l_instance.pricing_attribute92;
5352 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute93	:= l_instance.pricing_attribute93;
5353 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute94	:= l_instance.pricing_attribute94;
5354 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute95	:= l_instance.pricing_attribute95;
5355 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute96	:= l_instance.pricing_attribute96;
5356 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute97	:= l_instance.pricing_attribute97;
5357 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute98	:= l_instance.pricing_attribute98;
5358 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute99	:= l_instance.pricing_attribute99;
5359 				c_pricing_attribs_tbl(c_pa_idx).Pricing_attribute100	:= l_instance.pricing_attribute100;
5360 
5361 					c_pricing_attribs_tbl(c_pa_idx).instance_id
5362 														:= l_instance.INSTANCE_ID;
5363 					c_pricing_attribs_tbl(c_pa_idx).parent_tbl_index
5364 														:= inst_idx;
5365 				ELSIF(l_pricing_attribute_id IS NOT NULL
5366 					AND l_pricing_attribute_id <> FND_API.G_MISS_NUM) THEN
5367 					u_pa_idx := u_pa_idx + 1;
5368 					u_pricing_attribs_tbl(u_pa_idx).pricing_context
5369 														:= l_instance.Pricing_context;
5370 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute1
5371 														:= l_instance.pricing_attribute1;
5372 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute2
5373 														:= l_instance.pricing_attribute2;
5374 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute3
5375 														:= l_instance.pricing_attribute3;
5376 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute4
5377 														:= l_instance.pricing_attribute4;
5378 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute5
5379 														:= l_instance.pricing_attribute5;
5380 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute6
5381 														:= l_instance.pricing_attribute6;
5382 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute7
5383 														:= l_instance.pricing_attribute7;
5384 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute8
5385 														:= l_instance.pricing_attribute8;
5386 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute9
5387 														:= l_instance.pricing_attribute9;
5388 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute10
5389 														:= l_instance.pricing_attribute10;
5390 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute11
5391 														:= l_instance.pricing_attribute11;
5392 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute12
5393 														:= l_instance.pricing_attribute12;
5394 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute13
5395 														:= l_instance.pricing_attribute13;
5396 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute14
5397 														:= l_instance.pricing_attribute14;
5398 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute15
5399 														:= l_instance.pricing_attribute15;
5400 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute16
5401 														:= l_instance.pricing_attribute16;
5402 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute17
5403 														:= l_instance.pricing_attribute17;
5404 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute18
5405 														:= l_instance.pricing_attribute18;
5406 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute19
5407 														:= l_instance.pricing_attribute19;
5408 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute20
5409 														:= l_instance.pricing_attribute20;
5410 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute21
5411 														:= l_instance.pricing_attribute21;
5412 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute22
5413 														:= l_instance.pricing_attribute22;
5414 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute23
5415 														:= l_instance.pricing_attribute23;
5416 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute24
5417 														:= l_instance.pricing_attribute24;
5418 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute25
5419 														:= l_instance.pricing_attribute25;
5420 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute26
5421 														:= l_instance.pricing_attribute26;
5422 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute27
5423 														:= l_instance.pricing_attribute27;
5424 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute28
5425 														:= l_instance.pricing_attribute28;
5426 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute29
5427 														:= l_instance.pricing_attribute29;
5428 					u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute30
5429 														:= l_instance.pricing_attribute30;
5430 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute31	:= l_instance.pricing_attribute31;
5431 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute32	:= l_instance.pricing_attribute32;
5432 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute33	:= l_instance.pricing_attribute33;
5433 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute34	:= l_instance.pricing_attribute34;
5434 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute35	:= l_instance.pricing_attribute35;
5435 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute36	:= l_instance.pricing_attribute36;
5436 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute37	:= l_instance.pricing_attribute37;
5437 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute38	:= l_instance.pricing_attribute38;
5438 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute39	:= l_instance.pricing_attribute39;
5439 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute40	:= l_instance.pricing_attribute40;
5440 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute41	:= l_instance.pricing_attribute41;
5441 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute42	:= l_instance.pricing_attribute42;
5442 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute43	:= l_instance.pricing_attribute43;
5443 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute44	:= l_instance.pricing_attribute44;
5444 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute45	:= l_instance.pricing_attribute45;
5445 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute46	:= l_instance.pricing_attribute46;
5446 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute47	:= l_instance.pricing_attribute47;
5447 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute48	:= l_instance.pricing_attribute48;
5448 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute49	:= l_instance.pricing_attribute49;
5449 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute50	:= l_instance.pricing_attribute50;
5450 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute51	:= l_instance.pricing_attribute51;
5451 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute52	:= l_instance.pricing_attribute52;
5452 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute53	:= l_instance.pricing_attribute53;
5453 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute54	:= l_instance.pricing_attribute54;
5454 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute55	:= l_instance.pricing_attribute55;
5455 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute56	:= l_instance.pricing_attribute56;
5456 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute57	:= l_instance.pricing_attribute57;
5457 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute58	:= l_instance.pricing_attribute58;
5458 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute59	:= l_instance.pricing_attribute59;
5459 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute60	:= l_instance.pricing_attribute60;
5460 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute61	:= l_instance.pricing_attribute61;
5461 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute62	:= l_instance.pricing_attribute62;
5462 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute63	:= l_instance.pricing_attribute63;
5463 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute64	:= l_instance.pricing_attribute64;
5464 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute65	:= l_instance.pricing_attribute65;
5465 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute66	:= l_instance.pricing_attribute66;
5466 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute67	:= l_instance.pricing_attribute67;
5467 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute68	:= l_instance.pricing_attribute68;
5468 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute69	:= l_instance.pricing_attribute69;
5469 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute70	:= l_instance.pricing_attribute70;
5470 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute71	:= l_instance.pricing_attribute71;
5471 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute72	:= l_instance.pricing_attribute72;
5472 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute73	:= l_instance.pricing_attribute73;
5473 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute74	:= l_instance.pricing_attribute74;
5474 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute75	:= l_instance.pricing_attribute75;
5475 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute76	:= l_instance.pricing_attribute76;
5476 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute77	:= l_instance.pricing_attribute77;
5477 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute78	:= l_instance.pricing_attribute78;
5478 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute79	:= l_instance.pricing_attribute79;
5479 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute80	:= l_instance.pricing_attribute80;
5480 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute81	:= l_instance.pricing_attribute81;
5481 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute82	:= l_instance.pricing_attribute82;
5482 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute83	:= l_instance.pricing_attribute83;
5483 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute84	:= l_instance.pricing_attribute84;
5484 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute85	:= l_instance.pricing_attribute85;
5485 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute86	:= l_instance.pricing_attribute86;
5486 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute87	:= l_instance.pricing_attribute87;
5487 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute88	:= l_instance.pricing_attribute88;
5488 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute89	:= l_instance.pricing_attribute89;
5489 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute90	:= l_instance.pricing_attribute90;
5490 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute91	:= l_instance.pricing_attribute91;
5491 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute92	:= l_instance.pricing_attribute92;
5492 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute93	:= l_instance.pricing_attribute93;
5493 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute94	:= l_instance.pricing_attribute94;
5494 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute95	:= l_instance.pricing_attribute95;
5495 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute96	:= l_instance.pricing_attribute96;
5496 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute97	:= l_instance.pricing_attribute97;
5497 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute98	:= l_instance.pricing_attribute98;
5498 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute99	:= l_instance.pricing_attribute99;
5499 				u_pricing_attribs_tbl(u_pa_idx).Pricing_attribute100	:= l_instance.pricing_attribute100;
5500 
5501 					u_pricing_attribs_tbl(u_pa_idx).instance_id
5502 														:= l_instance.INSTANCE_ID;
5503 					u_pricing_attribs_tbl(u_pa_idx).pricing_attribute_id
5504 														:= l_pricing_attribute_id;
5505 					u_pricing_attribs_tbl(u_pa_idx).object_version_number
5506 														:= l_pa_obj_version_num;
5507 					u_pricing_attribs_tbl(u_pa_idx).parent_tbl_index
5508 														:= inst_idx;
5509 				END IF;
5510 			END IF;
5511 
5512 			--Getting internal party
5513 			BEGIN
5514 				SELECT INTERNAL_PARTY_ID
5515 				INTO l_internal_party_id
5516 				FROM csi_install_parameters;
5517 			EXCEPTION
5518 				WHEN others THEN
5519 					raise fnd_api.g_exc_error;
5520 			END;
5521 
5522 			--Party Record
5523 			party_idx := party_idx + 1;
5524 			u_party_tbl(party_idx).instance_party_id 				:= l_instance_party_id;
5525 			u_party_tbl(party_idx).instance_id       				:= l_instance.INSTANCE_ID;
5526 			u_party_tbl(party_idx).parent_tbl_index   				:= inst_idx;
5527 			u_party_tbl(party_idx).contact_flag := 'N';
5528 			u_party_tbl(party_idx).relationship_type_code 			:= 'OWNER';
5529 			u_party_tbl(party_idx).OBJECT_VERSION_NUMBER  			:= l_party_obj_ver;
5530 			u_party_tbl(party_idx).party_source_table 				:= l_instance.OWNER_PARTY_TYPE;
5531 			u_party_tbl(party_idx).party_id 						:= l_instance.OWNER_ID;
5532 			u_party_tbl(party_idx).CASCADE_OWNERSHIP_FLAG			:= l_instance.CASCADE_UPDATE;
5533 			--Account Record
5534 			IF l_instance.OWNER_PARTY_TYPE = 'HZ_PARTIES'
5535 				AND nvl(l_internal_party_id, fnd_api.g_miss_num) <>
5536 					nvl(l_instance.OWNER_ID, fnd_api.g_miss_num) THEN
5537 				debug('Populating owner account details.');
5538 				account_idx := account_idx + 1;
5539 				u_account_tbl(account_idx).ip_account_id     			:= l_ip_account_id;
5540 				u_account_tbl(account_idx).instance_party_id 			:= l_instance_party_id;
5541 				u_account_tbl(account_idx).parent_tbl_index  			:= party_idx;
5542 				u_account_tbl(account_idx).party_account_id 			:= l_instance.OWNER_ACCOUNT_ID;
5543 				u_account_tbl(account_idx).relationship_type_code 		:= 'OWNER';
5544 				u_account_tbl(account_idx).bill_to_address 				:= l_instance.BILL_TO_LOC_ID;
5545 				u_account_tbl(account_idx).ship_to_address 				:= l_instance.SHIP_TO_LOC_ID;
5546 				u_account_tbl(account_idx).OBJECT_VERSION_NUMBER 		:= l_act_obj_ver;
5547 				u_account_tbl(account_idx).CASCADE_OWNERSHIP_FLAG		:= l_instance.CASCADE_UPDATE;
5548 				IF(is_party_change) THEN
5549 					u_account_tbl(account_idx).CALL_CONTRACTS  				:= FND_API.G_FALSE;
5550 				ELSE
5551 					u_account_tbl(account_idx).CALL_CONTRACTS  				:= FND_API.G_TRUE;
5552 				END IF;
5553 			END IF;
5554 
5555 
5556 			--Bill to relationship
5557 			IF(l_instance.ASSOCIATE_BILL_TO_PARTY_ID is not null) then
5558 				add_party 	:= true;
5559 				l_dummy_var	:= 'Y';
5560 				BEGIN
5561 					Select 'X'
5562 					into l_dummy_var
5563 					from CSI_I_PARTIES cip
5564 					where cip.RELATIONSHIP_TYPE_CODE  = 'BILL_TO' AND cip.CONTACT_FLAG = 'N'
5565 					AND Nvl(cip.ACTIVE_END_DATE, SYSDATE  + 1) > SYSDATE
5566 					AND cip.INSTANCE_ID = l_instance.INSTANCE_ID
5567 					AND cip.PARTY_ID = l_instance.ASSOCIATE_BILL_TO_PARTY_ID;
5568 				EXCEPTION
5569 					when no_data_found then
5570 						add_party := true;
5571 					when too_many_rows then
5572 						add_party := false;
5573 				END;
5574 
5575 				IF(l_dummy_var <> 'Y') THEN
5576 					add_party := false;
5577 				END IF;
5578 
5579 				IF(add_party) THEN
5580 					debug('Populating new Bill To Party details');
5581 					party_idx := party_idx + 1;
5582 					account_idx := account_idx + 1;
5583 					--Part yRecord
5584 					u_party_tbl(party_idx).instance_id       		:= l_instance.INSTANCE_ID;
5585 					u_party_tbl(party_idx).parent_tbl_index   		:= inst_idx;
5586 					u_party_tbl(party_idx).contact_flag := 'N';
5587 					u_party_tbl(party_idx).relationship_type_code 	:= 'BILL_TO';
5588 					u_party_tbl(party_idx).OBJECT_VERSION_NUMBER  	:= 1;
5589 					u_party_tbl(party_idx).party_source_table 		:= l_instance.ASSOCIATE_BILL_TO_PARTY_TYPE;
5590 					u_party_tbl(party_idx).party_id 				:= l_instance.ASSOCIATE_BILL_TO_PARTY_ID;
5591 					IF(l_instance.ASSOCIATE_BILL_TO_ACCT_ID is not null) then
5592 						debug('Populating new Bill To Party Account details');
5593 						--Account Record
5594 						u_account_tbl(account_idx).parent_tbl_index  		:= party_idx;
5595 						u_account_tbl(account_idx).party_account_id 		:= l_instance.ASSOCIATE_BILL_TO_ACCT_ID;
5596 						u_account_tbl(account_idx).relationship_type_code 	:= 'BILL_TO';
5597 						u_account_tbl(account_idx).OBJECT_VERSION_NUMBER 	:= 1;
5598 						u_account_tbl(account_idx).CALL_CONTRACTS  			:= FND_API.G_FALSE;
5599 					END IF;
5600 				ELSE
5601 					debug_out('Bill To party relationship with party, ' || l_instance.ASSOCIATE_BILL_TO_PARTY_NUMBER ||
5602 									' already exists with the Instance ' || l_instance.PRODUCT_NUMBER);
5603 				END IF;
5604 			END IF;
5605 
5606 			--Ship to relationship
5607 			IF(l_instance.ASSOCIATE_SHIP_TO_PARTY_ID is not null) then
5608 				add_party 	:= true;
5609 				l_dummy_var	:= 'Y';
5610 				BEGIN
5611 					Select 'X'
5612 					into l_dummy_var
5613 					from CSI_I_PARTIES cip
5614 					where cip.RELATIONSHIP_TYPE_CODE  = 'SHIP_TO' AND cip.CONTACT_FLAG = 'N'
5615 					AND Nvl(cip.ACTIVE_END_DATE, SYSDATE  + 1) > SYSDATE
5616 					AND cip.INSTANCE_ID = l_instance.INSTANCE_ID
5617 					AND cip.PARTY_ID = l_instance.ASSOCIATE_SHIP_TO_PARTY_ID;
5618 				EXCEPTION
5619 					when no_data_found then
5620 						add_party := true;
5621 					when too_many_rows then
5622 						add_party := false;
5623 				END;
5624 
5625 				IF(l_dummy_var <> 'Y') THEN
5626 					add_party := false;
5627 				END IF;
5628 
5629 				IF(add_party) THEN
5630 					debug('Populating new Ship To Party details');
5631 					party_idx := party_idx + 1;
5632 					account_idx := account_idx + 1;
5633 					--Part yRecord
5634 					u_party_tbl(party_idx).instance_id       := l_instance.INSTANCE_ID;
5635 					u_party_tbl(party_idx).parent_tbl_index   := inst_idx;
5636 					u_party_tbl(party_idx).contact_flag := 'N';
5637 					u_party_tbl(party_idx).relationship_type_code := 'SHIP_TO';
5638 					u_party_tbl(party_idx).OBJECT_VERSION_NUMBER  := 1;
5639 					u_party_tbl(party_idx).party_source_table := l_instance.ASSOCIATE_SHIP_TO_PARTY_TYPE;
5640 					u_party_tbl(party_idx).party_id := l_instance.ASSOCIATE_SHIP_TO_PARTY_ID;
5641 					IF(l_instance.ASSOCIATE_SHIP_TO_ACCT_ID is not null) then
5642 						debug('Populating new Ship To Party Account details');
5643 						--Account Record
5644 						u_account_tbl(account_idx).parent_tbl_index  := party_idx;
5645 						u_account_tbl(account_idx).party_account_id := l_instance.ASSOCIATE_SHIP_TO_ACCT_ID;
5646 						u_account_tbl(account_idx).relationship_type_code := 'SHIP_TO';
5647 						u_account_tbl(account_idx).OBJECT_VERSION_NUMBER := 1;
5648 						u_account_tbl(account_idx).CALL_CONTRACTS  := FND_API.G_FALSE;
5649 					END IF;
5650 				ELSE
5651 					debug_out('Ship To party relationship with party, ' || l_instance.ASSOCIATE_SHIP_TO_PARTY_NUMBER ||
5652 									' already exists with the Instance ' || l_instance.PRODUCT_NUMBER);
5653 				END IF;
5654 			END IF;
5655 
5656 			--Txn Rec
5657 			u_csi_txn_tbl(inst_idx) := p_csi_txn_rec;
5658 
5659 			IF (Nvl(l_instance.PARENT_INSTANCE,FND_API.G_MISS_NUM) <> Nvl(l_instance.OLD_PARENT_INSTANCE, FND_API.G_MISS_NUM)) THEN
5660 	            IF   l_instance.OLD_PARENT_INSTANCE IS NOT NULL THEN
5661 					--Building the expire records
5662 					BEGIN
5663 						SELECT RELATIONSHIP_ID, OBJECT_VERSION_NUMBER
5664 							INTO l_relationship_id, l_rel_obj_ver
5665 							FROM csi_ii_relationships
5666 							WHERE object_id = l_old_par_instance_id
5667 							AND subject_id  = l_instance.INSTANCE_ID
5668 							AND nvl(ACTIVE_END_DATE, sysdate + 1) > sysdate;
5669 						debug('Populating expire Instance relationship record details');
5670 						e_rel_idx := e_rel_idx + 1;
5671 						e_relationship_tbl(c_rel_idx).relationship_type_code   	:= 'COMPONENT-OF';
5672 						e_relationship_tbl(c_rel_idx).object_id                	:= l_old_par_instance_id;
5673 				        e_relationship_tbl(c_rel_idx).subject_id               	:= l_instance.INSTANCE_ID;
5674 						e_relationship_tbl(c_rel_idx).RELATIONSHIP_ID			:= l_relationship_id;
5675 						e_relationship_tbl(c_rel_idx).OBJECT_VERSION_NUMBER		:= l_rel_obj_ver;
5676 						e_relationship_tbl(c_rel_idx).ACTIVE_END_DATE			:= sysdate;
5677 					EXCEPTION
5678 						WHEN NO_DATA_FOUND THEN
5679 						debug('Active relationship with Instance' || l_instance.OLD_PARENT_INSTANCE || ' does not exists to expire');
5680 					END;
5681 				END IF;
5682 			    IF l_instance.PARENT_INSTANCE IS NOT NULL THEN
5683 					--Building the relationship records for create
5684 						debug('Populating Create Instance relationship record details');
5685 						c_rel_idx := c_rel_idx + 1;
5686 						c_relationship_tbl(c_rel_idx).relationship_type_code   := 'COMPONENT-OF';
5687 						c_relationship_tbl(c_rel_idx).object_id                := l_par_instance_id;
5688 				        c_relationship_tbl(c_rel_idx).subject_id               := l_instance.INSTANCE_ID;
5689 				END IF;
5690 			END IF;
5691 		END IF;
5692 	END LOOP;
5693 
5694 	--Call to Update API
5695 	debug('Number of records populated to call Update API: ' || u_instance_tbl.count);
5696 	IF(u_instance_tbl.count > 0) then
5697 
5698 		csi_item_instance_grp.update_item_instance (
5699 			p_api_version           => 1.0,
5700 			p_commit                => fnd_api.g_false,
5701 			p_init_msg_list         => fnd_api.g_true,
5702 			p_validation_level      => fnd_api.g_valid_level_full,
5703 			p_instance_tbl          => u_instance_tbl,
5704 			p_ext_attrib_values_tbl => u_ext_attrib_values_tbl,
5705 			p_party_tbl             => u_party_tbl,
5706 			p_account_tbl           => u_account_tbl,
5707 			p_pricing_attrib_tbl    => u_pricing_attrib_tbl,
5708 			p_org_assignments_tbl   => u_org_assignments_tbl,
5709 			p_asset_assignment_tbl  => u_instance_asset_tbl,
5710 			p_txn_rec               => p_csi_txn_rec,
5711 			x_instance_id_lst		=> l_instance_id_lst,
5712 			p_grp_upd_error_tbl     => u_grp_upd_error_tbl,
5713 			x_return_status         => l_return_status,
5714 			x_msg_count             => l_msg_count,
5715 			x_msg_data              => l_msg_data);
5716 
5717 		IF NOT l_return_status = FND_API.G_RET_STS_SUCCESS
5718 		THEN
5719 			debug('Call to update_item_instance not successful');
5720 			debug_out('Update of the instances not successful, please check the request log for further details.');
5721 			l_msg_index := 1;
5722 			l_Error_Message := l_msg_Data;
5723 			WHILE l_msg_count > 0 LOOP
5724 				l_Error_Message := FND_MSG_PUB.GET(l_msg_index, FND_API.G_FALSE);
5725 				l_msg_index := l_msg_index + 1;
5726 				l_msg_count := l_msg_count - 1;
5727 				debug('Error: ' || l_Error_Message);
5728 			END LOOP;
5729 			l_falied_count := l_falied_count + u_instance_tbl.count;
5730 		ELSE
5731 			--Creating notes for all the updated instances
5732 			IF(l_batch_desc IS NOT NULL) THEN
5733 				IF(u_instance_tbl.count >0) THEN
5734 					FOR inst_tab_row IN u_instance_tbl.FIRST .. u_instance_tbl.LAST
5735 					LOOP
5736 						IF u_instance_tbl.EXISTS(inst_tab_row) THEN
5737 							BEGIN
5738 								SELECT instance_number
5739 								INTO l_instance_number
5740 								FROM csi_item_instances
5741 								WHERE instance_id = u_instance_tbl(inst_tab_row).Instance_id;							 EXCEPTION
5742 							  WHEN No_Data_Found THEN
5743 							   debug('Instance not found for ID: ' ||
5744 										u_instance_tbl(inst_tab_row).Instance_id);
5745 							END;
5746 							debug('Calling JTF_NOTES_PUB.CREATE_NOTE for update record Instance: '
5747 									|| l_instance_number);
5748 							JTF_NOTES_PUB.CREATE_NOTE
5749 							(	p_parent_note_id         => NULL,
5750 								p_api_version            => 1,
5751 								p_init_msg_list          => NULL,
5752 								p_commit                 => FND_API.G_FALSE,
5753 								p_validation_level       => fnd_api.g_valid_level_full,
5754 								x_return_status          => l_return_status,
5755 								x_msg_count              => l_msg_count,
5756 								x_msg_data               => l_msg_data,
5757 								x_jtf_note_id            => l_note_id,
5758 								p_org_id                 => NULL,
5759 								p_source_object_id       => u_instance_tbl(inst_tab_row).INSTANCE_ID,
5760 								p_source_object_code     => 'CP',
5761 								p_notes                  => l_batch_desc,
5762 								p_note_status            => 'I',
5763 								p_entered_by             => FND_GLOBAL.USER_ID,
5764 								p_entered_date           => SYSDATE,
5765 								p_last_update_date       => SYSDATE,
5766 								p_last_updated_by        => FND_GLOBAL.USER_ID,
5767 								p_creation_date          => SYSDATE,
5768 								p_created_by             => FND_GLOBAL.USER_ID
5769 							);
5770 
5771 							IF NOT(l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
5772 								debug_out('Error occured while creating a note for the ' ||
5773 											'update record Instance: ' || l_instance_number);
5774 								debug('Error occured while creating a note for the ' ||
5775 											'update record Instance: ' || l_instance_number);
5776 								l_msg_index := 1;
5777 								l_Error_Message := l_msg_data;
5778 								WHILE l_msg_count > 0
5779 								LOOP
5780 									l_Error_Message := FND_MSG_PUB.GET(l_msg_index, FND_API.G_FALSE);
5781 									l_msg_index := l_msg_index + 1;
5782 									l_msg_count := l_msg_count - 1;
5783 									debug('Error: ' || l_Error_Message);
5784 								END LOOP;
5785 							END IF;
5786 						END IF;
5787 					END LOOP;
5788 				END IF;
5789 			END IF;
5790 		END IF;
5791 		Commit;
5792 		IF(u_grp_upd_error_tbl.count >0) THEN
5793 			l_falied_count := l_falied_count + u_grp_upd_error_tbl.count;
5794 			FOR inst_tab_row IN u_grp_upd_error_tbl.FIRST .. u_grp_upd_error_tbl.LAST
5795 			LOOP
5796 				IF u_grp_upd_error_tbl.EXISTS(inst_tab_row) THEN
5797 					BEGIN
5798 						SELECT instance_number
5799 						INTO l_instance_number
5800 						FROM csi_item_instances
5801 						WHERE instance_id = u_grp_upd_error_tbl(inst_tab_row).Instance_id;
5802 
5803 						debug_out('Update of Instance ' || l_instance_number || ' : Failed with the error ' ||
5804 							u_grp_upd_error_tbl(inst_tab_row).Entity_Name || '- ' || u_grp_upd_error_tbl(inst_tab_row).Error_Message );
5805 						debug('Update of Instance ' || l_instance_number || ' : Failed with the error ' ||
5806 							u_grp_upd_error_tbl(inst_tab_row).Entity_Name || '- ' || u_grp_upd_error_tbl(inst_tab_row).Error_Message );
5807 					EXCEPTION
5808 					  WHEN No_Data_Found THEN
5809 					   debug('Instance not found for ID: ' || u_grp_upd_error_tbl(inst_tab_row).Instance_id);
5810 					END;
5811 				END IF;
5812 			END LOOP;
5813 		END IF;
5814 	END IF;
5815 
5816 	SELECT Count(*) INTO l_updt_count
5817 		FROM CSI_WEBADI_STAGING
5818 		where BATCH_ID = p_entry_id
5819 		and INSTANCE_ID is NOT null;
5820 
5821 	debug_out('	');
5822 	debug_out('Total no. of Item Instances Updated successfully: ' || (l_updt_count - l_falied_count));
5823 	debug_out('Total no. of update records failed: ' || l_falied_count);
5824 	debug_out('	');
5825 
5826 	debug('Total no. of Item Instances Updated successfully: ' || (l_updt_count - l_falied_count));
5827 	debug('Total no. of update records failed: ' || l_falied_count);
5828 
5829 	--Expire relationships
5830 	debug('Number of records populated to call Expire Instance relationships API: '
5831 															|| e_relationship_tbl.count);
5832 	IF(e_relationship_tbl.Count > 0) THEN
5833 		FOR tab_row IN e_relationship_tbl.FIRST .. e_relationship_tbl.LAST
5834 		LOOP
5835 			IF e_relationship_tbl.EXISTS(tab_row) THEN
5836 				csi_ii_relationships_pub.expire_relationship(
5837 					p_api_version           => 1.0,
5838 					p_commit                => fnd_api.g_false,
5839 					p_init_msg_list         => fnd_api.g_true,
5840 					p_validation_level      => fnd_api.g_valid_level_full,
5841 					p_relationship_rec      => e_relationship_tbl(tab_row),
5842 					p_txn_rec               => p_csi_txn_rec,
5843 					x_instance_id_lst		    => l_rel_instance_id_lst,
5844 					x_return_status         => l_return_status,
5845 					x_msg_count             => l_msg_count,
5846 					x_msg_data              => l_msg_data);
5847 
5848 				IF NOT l_return_status = FND_API.G_RET_STS_SUCCESS
5849 				THEN
5850 					debug_out('Expire relationship not successful for Instance: ' ||
5851 								e_relationship_tbl(tab_row).subject_id ||
5852 								'. Check request log for further details.');
5853 					debug('Call to csi_ii_relationships_pub.expire_relationship falied.');
5854 					l_msg_index := 1;
5855 					l_Error_Message := l_Msg_Data;
5856 					WHILE l_msg_count > 0 LOOP
5857 						l_Error_Message := FND_MSG_PUB.GET(l_msg_index, FND_API.G_FALSE);
5858 						l_msg_index := l_msg_index + 1;
5859 						l_msg_count := l_msg_count - 1;
5860 						debug('Error: ' || l_Error_Message);
5861 					END LOOP;
5862 				ELSE
5863 					commit;
5864 				END IF;
5865 			END IF;
5866 		END LOOP;
5867 	END IF;
5868 
5869 	--Create Relationships
5870 	debug('Number of records populated to call Create Instance relationships API: '
5871 															|| c_relationship_tbl.count);
5872 	IF(c_relationship_tbl.Count > 0) THEN
5873 		csi_ii_relationships_pub.create_relationship(
5874 		  p_api_version           => 1.0,
5875 		  p_commit                => fnd_api.g_false,
5876 		  p_init_msg_list         => fnd_api.g_true,
5877 		  p_validation_level      => fnd_api.g_valid_level_full,
5878 		  p_relationship_tbl      => c_relationship_tbl,
5879 		  p_txn_rec               => p_csi_txn_rec,
5880 		  x_return_status         => l_return_status,
5881 		  x_msg_count             => l_msg_count,
5882 		  x_msg_data              => l_msg_data);
5883 
5884 		IF NOT l_return_status = FND_API.G_RET_STS_SUCCESS
5885 		THEN
5886 			debug_out('Error occured while creating new relationships, please check the request log for detailed error');
5887 			debug('Call to csi_ii_relationships_pub.create_relationship not successful');
5888 			l_msg_index := 1;
5889 			l_Error_Message := l_Msg_Data;
5890 			WHILE l_msg_count > 0 LOOP
5891 				l_Error_Message := FND_MSG_PUB.GET(l_msg_index, FND_API.G_FALSE);
5892 				l_msg_index := l_msg_index + 1;
5893 				l_msg_count := l_msg_count - 1;
5894 				debug('Error: ' || l_Error_Message);
5895 			END LOOP;
5896 		ELSE
5897 			commit;
5898 		END IF;
5899 	END IF;
5900 
5901 	--Split Instance code, actually have to be done only if update for the instance is a success
5902 	--split_idx	:= 0;
5903 	--UPDATE PROCESSING STARTS
5904 	--Traversing through the cursor and processing for each instance to update
5905 	debug('Number of records populated to call Split Instance API: ' || l_instance_split_tbl.count);
5906 	IF(l_instance_split_tbl.count > 0) THEN
5907 		FOR inst_tab_row IN l_instance_split_tbl.FIRST .. l_instance_split_tbl.LAST
5908 		LOOP
5909 	    	Select QUANTITY, SPLIT_QTY
5910 			INTO l_quantity, l_splitqty
5911 			from CSI_WEBADI_STAGING
5912 			where BATCH_ID = p_Entry_id
5913 			and INSTANCE_ID = l_instance_split_tbl(inst_tab_row).instance_id;
5914 
5915 			IF(l_quantity < l_splitqty) THEN
5916 				debug_out('Error: Spilt quanity for instance ' || l_split_inst_num_tbl(inst_tab_row) || ' is more than the original quantity');
5917 			ELSE
5918 				l_quantity1 := l_quantity - l_splitqty;
5919 				l_quantity2 := l_splitqty;
5920 
5921 				csi_item_instance_pvt.split_item_instance (
5922 					p_api_version            => 1.0,
5923 					p_commit                 => fnd_api.g_false,
5924 					p_init_msg_list          => fnd_api.g_true,
5925 					p_validation_level       => fnd_api.g_valid_level_full,
5926 					p_source_instance_rec    => l_instance_split_tbl(inst_tab_row),
5927 					p_quantity1              => l_quantity1,
5928 					p_quantity2              => l_quantity2,
5929 					p_copy_ext_attribs       => fnd_api.g_true,
5930 					p_copy_org_assignments   => fnd_api.g_true,
5931 					p_copy_parties           => fnd_api.g_true,
5932 					p_copy_accounts          => fnd_api.g_true,
5933 					p_copy_asset_assignments => fnd_api.g_true,
5934 					p_copy_pricing_attribs   => fnd_api.g_true,
5935 					p_txn_rec                => p_csi_txn_rec,
5936 					x_new_instance_rec       => l_split_new_inst_rec,
5937 					x_return_status          => l_return_status,
5938 					x_msg_count              => l_msg_count,
5939 					x_msg_data               => l_msg_data);
5940 
5941 					IF NOT l_return_status = FND_API.G_RET_STS_SUCCESS
5942 					THEN
5943 					  debug_out('Error Occured while splitting the Instance ' ||
5944 							l_split_inst_num_tbl(inst_tab_row) ||
5945 							'. Check request log for further details.');
5946 					  debug('Call to csi_item_instance_pvt.split_item_instance is not successful for Instance' ||
5947 																		l_split_inst_num_tbl(inst_tab_row) );
5948 					  l_msg_index := 1;
5949 					  l_Error_Message := l_Msg_Data;
5950 					  WHILE l_msg_count > 0 LOOP
5951 						  l_Error_Message := FND_MSG_PUB.GET(l_msg_index, FND_API.G_FALSE);
5952 						  l_msg_index := l_msg_index + 1;
5953 						  l_msg_count := l_msg_count - 1;
5954 						  debug('Error: ' || l_Error_Message);
5955 					  END LOOP;
5956 					ELSE
5957 						commit;
5958 						--change check
5959 						debug_out('Split Instance successful for '  || l_split_inst_num_tbl(inst_tab_row) || ' and the new Instance number created is: ' || l_split_new_inst_rec.instance_number);
5960 						debug('Split Instance successful for '  || l_split_inst_num_tbl(inst_tab_row) || ' and the new Instance number created is: ' || l_split_new_inst_rec.instance_number);
5961 					END IF;
5962 			END IF;
5963 		END LOOP;
5964 	END IF;
5965 
5966 	debug('Number of records populated to call OKS API: ' || l_cov_line_tbl.count);
5967 	IF(l_cov_line_tbl.Count > 0) THEN
5968 		FOR tab_row IN l_cov_line_tbl.FIRST .. l_cov_line_tbl.LAST
5969 		LOOP
5970 			l_covlvl_id := NULL;
5971 			IF l_cov_line_tbl.EXISTS(tab_row) THEN
5972 				OKS_IBINT_PUB.create_k_covered_levels_webadi(
5973 					p_chr_id 			=> 		  l_chr_id_tbl(tab_row),
5974 					p_attach2_line_id	=>        l_attach2_line_id_tbl(tab_row),
5975 					p_k_covd_rec        =>        l_cov_line_tbl(tab_row),
5976 					x_covlvl_id         =>        l_covlvl_id,
5977 					x_return_status     =>        l_return_status,
5978 					x_msg_count         =>        l_msg_count,
5979 					x_msg_data          =>        l_msg_data
5980 					);
5981 
5982 				IF NOT l_return_status = FND_API.G_RET_STS_SUCCESS
5983 				THEN
5984 					debug('Error Occured in call to OKS_IBINT_PUB.create_k_covered_levels_webadi ' ||
5985 								'for the Instance: ' || l_oks_inst_num_tbl(tab_row));
5986 					debug('Error: ' || l_msg_data);
5987 					debug_out('Failed to associate the specified contract for the Instance ' ||
5988 									l_oks_inst_num_tbl(tab_row) || ' And is due to: ');
5989 					debug_out('' || l_msg_data);
5990 				ELSE
5991 					commit;
5992 					debug_out('Contract successfully associated to the Instance ' ||
5993 						l_oks_inst_num_tbl(tab_row) || ' with the cover level ID: ' || l_covlvl_id);
5994 				END IF;
5995 			END IF;
5996 		END LOOP;
5997 	END IF;
5998 
5999 	debug('Number of records populated to call create Pricing attributes API: ' ||
6000 														c_pricing_attribs_tbl.count);
6001 	IF(c_pricing_attribs_tbl.count > 0) THEN
6002 		FOR tab_row IN c_pricing_attribs_tbl.FIRST .. c_pricing_attribs_tbl.LAST
6003 		LOOP
6004 			IF c_pricing_attribs_tbl.EXISTS(tab_row) THEN
6005 				csi_pricing_attribs_pvt.create_pricing_attribs(
6006 					p_api_version			=>	1.0,
6007 					p_commit              	=>	fnd_api.g_false,
6008 					p_init_msg_list       	=>	fnd_api.g_true,
6009 					p_validation_level    	=>	fnd_api.g_valid_level_full,
6010 					p_pricing_attribs_rec 	=>	c_pricing_attribs_tbl(tab_row),
6011 					p_txn_rec             	=>	p_csi_txn_rec,
6012 					x_return_status       	=>	l_return_status,
6013 					x_msg_count           	=>	l_msg_count,
6014 					x_msg_data            	=>	l_msg_data);
6015 				l_instance_number := null;
6016 				IF NOT l_return_status = FND_API.G_RET_STS_SUCCESS
6017 				THEN
6018 					BEGIN
6019 						SELECT instance_number
6020 						INTO l_instance_number
6021 						FROM csi_item_instances
6022 						WHERE instance_id = c_pricing_attribs_tbl(tab_row).instance_id;					   EXCEPTION
6023 					  WHEN No_Data_Found THEN
6024 					   debug('Instance not found, while debug for create_pricing_attribs' ||
6025 						' for ID: ' || c_pricing_attribs_tbl(tab_row).instance_id);
6026 					END;
6027 					debug_out('Error Occured while creating Pricing attributes, ' ||
6028 						'for the Instance: ' || l_instance_number);
6029 					debug('Error Occured in call to create_pricing_attribs for the Instance: ' ||
6030 																			l_instance_number);
6031 					debug('Error: ');
6032 					l_msg_index := 1;
6033 					l_Error_Message := l_msg_data;
6034 					WHILE l_msg_count > 0 LOOP
6035 						l_Error_Message := FND_MSG_PUB.GET(l_msg_index, FND_API.G_FALSE);
6036 						l_msg_index := l_msg_index + 1;
6037 						l_msg_count := l_msg_count - 1;
6038 						debug('Error: ' || l_Error_Message);
6039 					END LOOP;
6040 				ELSE
6041 					commit;
6042 				END IF;
6043 			END IF;
6044 		END LOOP;
6045 	END IF;
6046 
6047 	debug('Number of records populated to call update Pricing attributes API: ' ||
6048 														u_pricing_attribs_tbl.count);
6049 	IF(u_pricing_attribs_tbl.count > 0) THEN
6050 		FOR tab_row IN u_pricing_attribs_tbl.FIRST .. u_pricing_attribs_tbl.LAST
6051 		LOOP
6052 			IF u_pricing_attribs_tbl.EXISTS(tab_row) THEN
6053 				csi_pricing_attribs_pvt.update_pricing_attribs(
6054 					p_api_version			=>	1.0,
6055 					p_commit              	=>	fnd_api.g_false,
6056 					p_init_msg_list       	=>	fnd_api.g_true,
6057 					p_validation_level    	=>	fnd_api.g_valid_level_full,
6058 					p_pricing_attribs_rec 	=>	u_pricing_attribs_tbl(tab_row),
6059 					p_txn_rec             	=>	p_csi_txn_rec,
6060 					x_return_status       	=>	l_return_status,
6061 					x_msg_count           	=>	l_msg_count,
6062 					x_msg_data            	=>	l_msg_data);
6063 				l_instance_number := null;
6064 				IF NOT l_return_status = FND_API.G_RET_STS_SUCCESS
6065 				THEN
6066 					BEGIN
6067 						SELECT instance_number
6068 						INTO l_instance_number
6069 						FROM csi_item_instances
6070 						WHERE instance_id = u_pricing_attribs_tbl(tab_row).instance_id;					   EXCEPTION
6071 					  WHEN No_Data_Found THEN
6072 					   debug('Instance not found, while debug for update_pricing_attribs' ||
6073 						' for ID: ' || u_pricing_attribs_tbl(tab_row).instance_id);
6074 					END;
6075 					debug_out('Error Occured while updating Pricing attributes, ' ||
6076 						'for the Instance: ' || l_instance_number);
6077 					debug('Error Occured in call to update_pricing_attribs for the Instance: ' ||
6078 																			l_instance_number);
6079 					l_msg_index := 1;
6080 					l_Error_Message := l_msg_data;
6081 					WHILE l_msg_count > 0 LOOP
6082 						l_Error_Message := FND_MSG_PUB.GET(l_msg_index, FND_API.G_FALSE);
6083 						l_msg_index := l_msg_index + 1;
6084 						l_msg_count := l_msg_count - 1;
6085 						debug('Error: ' || l_Error_Message);
6086 					END LOOP;
6087 				ELSE
6088 					commit;
6089 				END IF;
6090 			END IF;
6091 		END LOOP;
6092 	END IF;
6093 	debug('End procedure: Process_webadi_update');
6094 
6095 EXCEPTION
6096 	WHEN OTHERS THEN
6097 		debug_out('Encountered unexpected error while update. Please check the request log for error details');
6098 		debug('Encountered unexpected exception in Process_webadi_update');
6099 		debug('Unexpected error: ' || to_char(SQLCODE)||substr(SQLERRM, 1, 255));
6100 		errbuf := 'E';
6101 END Process_webadi_update;
6102 
6103 PROCEDURE Create_Reupload_Batch
6104    ( errbuf                       OUT NOCOPY    VARCHAR2
6105     ,retcode                      OUT NOCOPY    NUMBER
6106     ,p_Entry_id                   IN     NUMBER
6107 	,p_reupld_batch_id			  OUT NOCOPY	NUMBER
6108    ) IS
6109 
6110 	l_mass_edit_rec            csi_mass_edit_pub.mass_edit_rec;
6111 	l_txn_line_rec             csi_t_datastructures_grp.txn_line_rec;
6112 	l_mass_edit_inst_tbl       csi_mass_edit_pub.mass_edit_inst_tbl;
6113 	l_txn_line_detail_rec      csi_t_datastructures_grp.txn_line_detail_rec;
6114 	l_txn_party_detail_tbl     csi_t_datastructures_grp.txn_party_detail_tbl;
6115 	l_txn_pty_acct_detail_tbl  csi_t_datastructures_grp.txn_pty_acct_detail_tbl;
6116 	l_txn_ext_attrib_vals_tbl  csi_t_datastructures_grp.txn_ext_attrib_vals_tbl;
6117 	l_mass_edit_error_tbl      csi_mass_edit_pub.mass_edit_error_tbl;
6118 
6119 	l_return_status			varchar2(1) := fnd_api.g_ret_sts_success;
6120 	l_msg_count				number;
6121 	l_msg_data				varchar2(2000);
6122 	l_msg_index     		NUMBER;
6123 	l_error_message 		VARCHAR2(2000);
6124 	l_old_batch_name		VARCHAR2(50);
6125 	l_old_batch_desc        VARCHAR2(2000);
6126 	l_new_batch_seq			NUMBER;
6127 
6128 BEGIN
6129 	debug('Start procedure: Create_Reupload_Batch for old batch: ' || p_Entry_id);
6130 	BEGIN
6131 		SELECT  name,
6132 	            description
6133 	    INTO    l_old_batch_name,
6134 	            l_old_batch_desc
6135 	    FROM    csi_mass_edit_entries_vl
6136 	    WHERE   entry_id = p_entry_id;
6137 	EXCEPTION
6138 		WHEN OTHERS THEN
6139 			debug_out('Unable to find the old batch which is re-uploaded');
6140 	END;
6141 
6142 	select CSI_MU_REUPLOAD_S.NEXTVAL INTO l_new_batch_seq from DUAL;
6143 
6144 	l_mass_edit_rec.name		:=	l_old_batch_name || '_' || l_new_batch_seq;
6145 	l_mass_edit_rec.description	:=	l_old_batch_desc;
6146 	l_mass_edit_rec.batch_type	:=	'WBADI';
6147 
6148 	debug('Calling API csi_mass_edit_pub.CREATE_MASS_EDIT_BATCH.');
6149 	csi_mass_edit_pub.CREATE_MASS_EDIT_BATCH
6150 	   (p_api_version          		=> 	1.0,
6151 	    p_commit                	=> 	fnd_api.g_false,
6152 	    p_init_msg_list         	=> 	fnd_api.g_true,
6153 	    p_validation_level      	=> 	fnd_api.g_valid_level_full,
6154 	    px_mass_edit_rec          	=>	l_mass_edit_rec,
6155 	    px_txn_line_rec             =>	l_txn_line_rec,
6156 	    px_mass_edit_inst_tbl       =>	l_mass_edit_inst_tbl,
6157 	    px_txn_line_detail_rec      =>	l_txn_line_detail_rec,
6158 	    px_txn_party_detail_tbl     =>	l_txn_party_detail_tbl,
6159 	    px_txn_pty_acct_detail_tbl  =>	l_txn_pty_acct_detail_tbl,
6160 	    px_txn_ext_attrib_vals_tbl  =>	l_txn_ext_attrib_vals_tbl,
6161 	    x_mass_edit_error_tbl       =>	l_mass_edit_error_tbl,
6162 	    x_return_status          	=> 	l_return_status,
6163 	    x_msg_count              	=> 	l_msg_count,
6164 	    x_msg_data	                => 	l_msg_data);
6165 
6166 	IF NOT l_return_status = FND_API.G_RET_STS_SUCCESS
6167 	THEN
6168 		debug_out('Error occured while creating new batch for re-upload, please check ' ||
6169 											'the request log for detailed error.');
6170 		debug('Call to CREATE_MASS_EDIT_BATCH for new re-upload batch not successful');
6171 		l_msg_index := 1;
6172 		l_Error_Message := l_Msg_Data;
6173 		WHILE l_msg_count > 0 LOOP
6174 			l_Error_Message := FND_MSG_PUB.GET(l_msg_index, FND_API.G_FALSE);
6175 			l_msg_index := l_msg_index + 1;
6176 			l_msg_count := l_msg_count - 1;
6177 			debug('Error: ' || l_Error_Message);
6178 		END LOOP;
6179 	ELSE
6180 		commit;
6181 		debug('New batch ' || l_mass_edit_rec.name || ' created on re-upload of batch '
6182 				|| l_old_batch_name || 'with batch Id ' || l_mass_edit_rec.entry_id);
6183 		p_reupld_batch_id	:=	l_mass_edit_rec.entry_id;
6184 	END IF;
6185 
6186 	IF(p_reupld_batch_id is not null) THEN
6187 		--Updating the new records with the new batch Id
6188 		UPDATE CSI_WEBADI_STAGING
6189 		SET BATCH_ID = p_reupld_batch_id,
6190 			BATCH_NAME = l_mass_edit_rec.name
6191 		WHERE nvl(PROCESSING_STATUS, 'N') <> 'P'
6192 		AND BATCH_ID = p_entry_id;
6193 	END IF;
6194 
6195 	debug('End procedure: Create_Reupload_Batch');
6196 EXCEPTION
6197 	WHEN OTHERS THEN
6198 		debug_out('Encountered unexpected error while Creating new batch for re-upload. ' ||
6199 					'Please check the request log for error details');
6200 		debug('Encountered unexpected exception in Create_Reupload_Batch');
6201 		debug('Unexpected error: ' || to_char(SQLCODE)||substr(SQLERRM, 1, 255));
6202 		errbuf := 'E';
6203 END Create_Reupload_Batch;
6204 
6205 
6206 PROCEDURE Populate_WebAdi_Ids
6207    ( errbuf                       OUT NOCOPY    VARCHAR2
6208     ,retcode                      OUT NOCOPY    NUMBER
6209     ,p_Entry_id                   IN     NUMBER
6210 	) IS
6211 
6212 BEGIN
6213 
6214 	--LAST_VLD_ORGANIZATION_ID
6215 	BEGIN
6216 		UPDATE csi_webadi_staging cws SET LAST_VLD_ORGANIZATION_ID =
6217 		(
6218 			SELECT O.ORGANIZATION_ID
6219 			FROM HR_ALL_ORGANIZATION_UNITS O, HR_ALL_ORGANIZATION_UNITS_TL OTL
6220 			WHERE O.ORGANIZATION_ID = OTL.ORGANIZATION_ID
6221 			AND OTL.LANGUAGE = userenv('LANG')
6222 			AND OTL.NAME = cws.ORGANIZATION
6223 		)
6224 		WHERE cws.batch_id = p_Entry_id;
6225 		debug('Populated LAST_VLD_ORGANIZATION_ID column');
6226 	EXCEPTION
6227 		WHEN OTHERS THEN
6228 			debug('Unexpected error while populating LAST_VLD_ORGANIZATION_ID column: ');
6229 			debug(to_char(SQLCODE)||substr(SQLERRM, 1, 255));
6230 			debug_out('Unexpected error occured while generating IDs for Organization field. '
6231 						|| 'Please use Organization LOV');
6232 	END;
6233 
6234 	--INSTANCE_ID
6235 	BEGIN
6236 		UPDATE csi_webadi_staging cws SET INSTANCE_ID =
6237 		(
6238 			SELECT INSTANCE_ID FROM csi_item_instances cii
6239 			WHERE cii.instance_number = cws.PRODUCT_NUMBER
6240 		)
6241 		WHERE cws.batch_id = p_Entry_id;
6242 		debug('Populated INSTANCE_ID column');
6243 	EXCEPTION
6244 		WHEN OTHERS THEN
6245 			debug('Unexpected error while populating INSTANCE_ID column: ');
6246 			debug(to_char(SQLCODE)||substr(SQLERRM, 1, 255));
6247 			debug_out('Unexpected error occured while generating IDs for Product Number field.');
6248 	END;
6249 
6250 	--ITEM_ID
6251 	BEGIN
6252 		UPDATE csi_webadi_staging cws SET ITEM_ID =
6253 		(
6254 			SELECT m2.inventory_item_id
6255 			FROM    mtl_system_items_kfv m2,
6256 				 mtl_system_items m1,
6257 				 fnd_lookup_values fcl,
6258 				 mtl_parameters m3
6259 			WHERE   m1.COMMS_NL_TRACKABLE_FLAG = 'Y'
6260 			 and sysdate between nvl(m1.START_DATE_ACTIVE,sysdate)
6261 			 and nvl(m1.END_DATE_ACTIVE ,sysdate)
6262 			 and m2.inventory_item_id = m1.inventory_item_id
6263 			 and fcl.lookup_type(+) = 'ITEM_TYPE'
6264 			 and fcl.lookup_code(+) = m2.item_type
6265 			 and sysdate between nvl(m2.START_DATE_ACTIVE,sysdate)
6266 			 and nvl(m2.END_DATE_ACTIVE ,sysdate)
6267 			 and fcl.LANGUAGE(+) = userenv('LANG')
6268 			 and m3.organization_id = m2.organization_id
6269 			 and m3.organization_id = m1.organization_id
6270 			 and m2.inventory_item_status_code not in ('Inactive')
6271 			 AND m2.concatenated_segments = cws.ITEM_NUMBER
6272 			 AND m2.organization_id = cws.LAST_VLD_ORGANIZATION_ID
6273 		 )
6274 		WHERE cws.batch_id = p_Entry_id;
6275 		debug('Populated ITEM_ID column');
6276 	EXCEPTION
6277 		WHEN OTHERS THEN
6278 			debug('Unexpected error while populating ITEM_ID column: ');
6279 			debug(to_char(SQLCODE)||substr(SQLERRM, 1, 255));
6280 			debug_out('Unexpected error occured while generating IDs. '||
6281 						'Please use Item Number LOV, for this set of data.');
6282 	END;
6283 
6284 	--OWNER_ID
6285 	BEGIN
6286 		UPDATE csi_webadi_staging cws SET OWNER_ID =
6287 		(
6288 		decode(cws.OWNER_PARTY_TYPE,
6289 			'HZ_PARTIES',
6290 			(SELECT party_id FROM hz_parties WHERE party_number = cws.OWNER_PARTY_NUM),
6291 			'EMPLOYEE',
6292 			(SELECT employee_id FROM  per_employees_current_x
6293 				WHERE employee_num = cws.OWNER_PARTY_NUM
6294 				AND full_name = cws.OWNER_NAME),
6295 			'PO_VENDORS',
6296 			(SELECT vendor_id FROM po_vendors WHERE segment1 = cws.OWNER_PARTY_NUM
6297 				AND vendor_name = cws.OWNER_NAME
6298 				AND nvl(start_date_active,sysdate) <= sysdate AND nvl(end_date_Active, sysdate+1) > SYSDATE
6299 				AND enabled_flag = 'Y'),
6300 			null)
6301 		)
6302 		WHERE cws.batch_id = p_Entry_id;
6303 		debug('Populated OWNER_ID column');
6304 	EXCEPTION
6305 		WHEN OTHERS THEN
6306 			debug('Unexpected error while populating OWNER_ID column: ');
6307 			debug(to_char(SQLCODE)||substr(SQLERRM, 1, 255));
6308 			debug_out('Unexpected error occured while generating IDs. '||
6309 						'Please use Owner Party Num LOV, for this set of data');
6310 	END;
6311 
6312 	--ASSOCIATE_BILL_TO_PARTY_ID
6313 	BEGIN
6314 		UPDATE csi_webadi_staging cws SET ASSOCIATE_BILL_TO_PARTY_ID =
6315 		(
6316 		decode(cws.ASSOCIATE_BILL_TO_PARTY_TYPE,
6317 			'HZ_PARTIES',
6318 			(SELECT party_id FROM hz_parties
6319 				WHERE party_number = cws.ASSOCIATE_BILL_TO_PARTY_NUMBER),
6320 			'EMPLOYEE',
6321 			(SELECT employee_id FROM  per_employees_current_x
6322 				WHERE employee_num = cws.ASSOCIATE_BILL_TO_PARTY_NUMBER
6323 				AND full_name = cws.ASSOCIATE_BILL_TO_PARTY_NAME),
6324 			'PO_VENDORS',
6325 			(SELECT vendor_id FROM po_vendors
6326 				WHERE segment1 = cws.ASSOCIATE_BILL_TO_PARTY_NUMBER
6327 				AND vendor_name = cws.ASSOCIATE_BILL_TO_PARTY_NAME
6328 				AND nvl(start_date_active,sysdate) <= sysdate AND nvl(end_date_Active, sysdate+1) > SYSDATE
6329 				AND enabled_flag = 'Y'),
6330 			null)
6331 		)
6332 		WHERE cws.batch_id = p_Entry_id;
6333 		debug('Populated ASSOCIATE_BILL_TO_PARTY_ID column');
6334 	EXCEPTION
6335 		WHEN OTHERS THEN
6336 			debug('Unexpected error while populating ASSOCIATE_BILL_TO_PARTY_ID column: ');
6337 			debug(to_char(SQLCODE)||substr(SQLERRM, 1, 255));
6338 			debug_out('Unexpected error occured while generating IDs. '||
6339 						'Please use Associate Bill To Party Number LOV, for this set of data');
6340 	END;
6341 
6342 	--ASSOCIATE_SHIP_TO_PARTY_ID
6343 	BEGIN
6344 		UPDATE csi_webadi_staging cws SET ASSOCIATE_SHIP_TO_PARTY_ID =
6345 		(
6346 		decode(cws.ASSOCIATE_SHIP_TO_PARTY_TYPE,
6347 			'HZ_PARTIES',
6348 			(SELECT party_id FROM hz_parties
6349 				WHERE party_number = cws.ASSOCIATE_SHIP_TO_PARTY_NUMBER),
6350 			'EMPLOYEE',
6351 			(SELECT employee_id FROM  per_employees_current_x
6352 				WHERE employee_num = cws.ASSOCIATE_SHIP_TO_PARTY_NUMBER
6353 				AND full_name = cws.ASSOCIATE_SHIP_TO_PARTY_NAME),
6354 			'PO_VENDORS',
6355 			(SELECT vendor_id FROM po_vendors
6356 				WHERE segment1 = cws.ASSOCIATE_SHIP_TO_PARTY_NUMBER
6357 				AND vendor_name = cws.ASSOCIATE_SHIP_TO_PARTY_NAME
6358 				AND nvl(start_date_active,sysdate) <= sysdate AND nvl(end_date_Active, sysdate+1) > SYSDATE
6359 				AND enabled_flag = 'Y'),
6360 			null)
6361 		)
6362 		WHERE cws.batch_id = p_Entry_id;
6363 		debug('Populated ASSOCIATE_SHIP_TO_PARTY_ID column');
6364 	EXCEPTION
6365 		WHEN OTHERS THEN
6366 			debug('Unexpected error while populating ASSOCIATE_SHIP_TO_PARTY_ID column: ');
6367 			debug(to_char(SQLCODE)||substr(SQLERRM, 1, 255));
6368 			debug_out('Unexpected error occured while generating IDs. '||
6369 						'Please use Associate Ship To Party Number LOV, for this set of data');
6370 	END;
6371 
6372 	--OWNER_ACCOUNT_ID
6373 	BEGIN
6374 		UPDATE csi_webadi_staging cws SET OWNER_ACCOUNT_ID =
6375 		(
6376 			SELECT CUST_ACCOUNT_ID FROM hz_cust_accounts
6377 			WHERE status = 'A'
6378 			AND sysdate between nvl(ACCOUNT_ACTIVATION_DATE,sysdate) and nvl(ACCOUNT_TERMINATION_DATE ,sysdate)
6379 			AND PARTY_ID = cws.OWNER_ID
6380 			AND ACCOUNT_NUMBER = cws.OWNER_ACCOUNT_NUMBER
6381 		)
6382 		WHERE cws.batch_id = p_Entry_id;
6383 		debug('Populated OWNER_ACCOUNT_ID column');
6384 	EXCEPTION
6385 		WHEN OTHERS THEN
6386 			debug('Unexpected error while populating OWNER_ACCOUNT_ID column: ');
6387 			debug(to_char(SQLCODE)||substr(SQLERRM, 1, 255));
6388 			debug_out('Unexpected error occured while generating IDs. '||
6389 						'Please use Owner Account Number LOV, for this set of data');
6390 	END;
6391 
6392 	--ASSOCIATE_BILL_TO_ACCT_ID
6393 	BEGIN
6394 		UPDATE csi_webadi_staging cws SET ASSOCIATE_BILL_TO_ACCT_ID =
6395 		(
6396 			SELECT CUST_ACCOUNT_ID FROM hz_cust_accounts
6397 			WHERE status = 'A'
6398 			AND sysdate between nvl(ACCOUNT_ACTIVATION_DATE,sysdate) and nvl(ACCOUNT_TERMINATION_DATE ,sysdate)
6399 			AND PARTY_ID = cws.ASSOCIATE_BILL_TO_PARTY_ID
6400 			AND ACCOUNT_NUMBER = cws.ASSOCIATE_BILL_TO_ACCT_NUM
6401 		)
6402 		WHERE cws.batch_id = p_Entry_id;
6403 		debug('Populated ASSOCIATE_BILL_TO_ACCT_ID column');
6404 	EXCEPTION
6405 		WHEN OTHERS THEN
6406 			debug('Unexpected error while populating ASSOCIATE_BILL_TO_ACCT_ID column: ');
6407 			debug(to_char(SQLCODE)||substr(SQLERRM, 1, 255));
6408 			debug_out('Unexpected error occured while generating IDs. '||
6409 						'Please use Associate Bill To Acct Num LOV, for this set of data');
6410 	END;
6411 
6412 	-- ASSOCIATE_SHIP_TO_ACCT_ID
6413 	BEGIN
6414 		UPDATE csi_webadi_staging cws SET ASSOCIATE_SHIP_TO_ACCT_ID =
6415 		(
6416 			SELECT CUST_ACCOUNT_ID FROM hz_cust_accounts
6417 			WHERE status = 'A'
6418 			AND sysdate between nvl(ACCOUNT_ACTIVATION_DATE,sysdate) and nvl(ACCOUNT_TERMINATION_DATE ,sysdate)
6419 			AND PARTY_ID = cws.ASSOCIATE_SHIP_TO_PARTY_ID
6420 			AND ACCOUNT_NUMBER = cws.ASSOCIATE_SHIP_TO_ACCT_NUM
6421 		)
6422 		WHERE cws.batch_id = p_Entry_id;
6423 		debug('Populated ASSOCIATE_SHIP_TO_ACCT_ID column');
6424 	EXCEPTION
6425 		WHEN OTHERS THEN
6426 			debug('Unexpected error while populating ASSOCIATE_SHIP_TO_ACCT_ID column: ');
6427 			debug(to_char(SQLCODE)||substr(SQLERRM, 1, 255));
6428 			debug_out('Unexpected error occured while generating IDs. '||
6429 						'Please use Associate Ship To Acct Num LOV, for this set of data');
6430 	END;
6431 
6432 	--ASSOCIATE_CONTRACT_ID
6433 	BEGIN
6434 		UPDATE csi_webadi_staging cws SET ASSOCIATE_CONTRACT_ID =
6435 		(
6436 			SELECT okch.id ContractId
6437 			FROM okc_k_headers_all_b okch, okc_statuses_b sts, okc_k_party_roles_b k_party
6438 			WHERE okch.sts_code = sts.code
6439 			  AND okch.scs_code IN ('SERVICE','WARRANTY') AND sts.ste_code = 'ENTERED'
6440 			  AND okch.id = k_party.chr_id  AND k_party.jtot_object1_code IN ('OKX_PARTY')
6441 			  AND contract_number = cws.ASSOCIATE_CONTRACT_NUMBER
6442 			  AND Nvl(contract_number_modifier, fnd_api.g_miss_char)
6443 								= Nvl(cws.ASSOCIATE_CONTRACT_MODIFIER, fnd_api.g_miss_char)
6444 			  AND EXISTS (SELECT 1 FROM HZ_CUST_ACCOUNTS CA1
6445 		                        WHERE CA1.party_id = k_party.object1_id1 AND CA1.status = 'A'
6446 		                        AND CA1.account_number = cws.OWNER_ACCOUNT_NUMBER
6447 			                UNION ALL
6448 			                SELECT 1 FROM HZ_CUST_ACCOUNTS CA2, HZ_CUST_ACCT_RELATE_ALL REL
6449 		                        WHERE CA2.party_id = k_party.object1_id1
6450 								AND REL.cust_account_id = CA2.CUST_ACCOUNT_ID
6451 		                        AND REL.org_id = okch.AUTHORING_ORG_ID AND REL.status = 'A'
6452 		                        AND CA2.status = 'A'
6453 		                        AND REL.related_cust_account_id = CA2.CUST_ACCOUNT_ID
6454 		                        and CA2.account_number = cws.OWNER_ACCOUNT_NUMBER)
6455 		)
6456 		WHERE cws.batch_id = p_Entry_id;
6457 		debug('Populated ASSOCIATE_CONTRACT_ID column');
6458 	EXCEPTION
6459 		WHEN OTHERS THEN
6460 			debug('Unexpected error while populating ASSOCIATE_CONTRACT_ID column: ');
6461 			debug(to_char(SQLCODE)||substr(SQLERRM, 1, 255));
6462 			debug_out('Unexpected error occured while generating IDs. '||
6463 						'Please use Associate Contract Number LOV, for this set of data');
6464 	END;
6465 
6466 	--ASSOCIATE_SERVICE_LINE_ID
6467 	BEGIN
6468 		UPDATE csi_webadi_staging cws SET ASSOCIATE_SERVICE_LINE_ID =
6469 		(
6470 			SELECT okl.id
6471 			FROM okc_k_lines_b okl, okc_k_items oki,
6472 				mtl_system_items_kfv mtl, okc_k_headers_all_b okh
6473 			WHERE oki.cle_id = okl.id
6474 			  AND mtl.inventory_item_id = oki.object1_id1
6475 			  AND mtl.organization_id = oki.object1_id2
6476 			  AND oki.jtot_object1_code = 'OKX_SERVICE'
6477 			  AND okl.chr_id = okh.id AND okl.lse_id IN (1,19)
6478 			  AND okh.contract_number= cws.ASSOCIATE_CONTRACT_NUMBER
6479 			  AND nvl(okh.contract_number_modifier, fnd_api.g_miss_char)
6480 							= nvl(cws.ASSOCIATE_CONTRACT_MODIFIER, fnd_api.g_miss_char)
6481 			  AND okl.line_number =  cws.ASSOCIATE_SERVICE_LINE
6482 		)
6483 		WHERE cws.batch_id = p_Entry_id;
6484 		debug('Populated ASSOCIATE_SERVICE_LINE_ID column');
6485 	EXCEPTION
6486 		WHEN OTHERS THEN
6487 			debug('Unexpected error while populating ASSOCIATE_SERVICE_LINE_ID column: ');
6488 			debug(to_char(SQLCODE)||substr(SQLERRM, 1, 255));
6489 			debug_out('Unexpected error occured while generating IDs. '||
6490 						'Please use Associate Service Line LOV, for this set of data');
6491 	END;
6492 
6493 	--OLD_PARENT_INSTANCE
6494 	BEGIN
6495 		UPDATE csi_webadi_staging cws SET OLD_PARENT_INSTANCE =
6496 		(
6497 		 select cii.instance_number
6498 		 from  csi_ii_relationships cir, csi_item_instances cii
6499 		 where cir.subject_id = cws.INSTANCE_ID
6500 		 and cir.object_id = cii.instance_id
6501 		 and Nvl(cir.ACTIVE_END_DATE, SYSDATE + 1) > sysdate
6502 		)
6503 		WHERE cws.batch_id = p_Entry_id;
6504 		debug('Populated OLD_PARENT_INSTANCE column');
6505 	EXCEPTION
6506 		WHEN OTHERS THEN
6507 			debug('Unexpected error while populating OLD_PARENT_INSTANCE column: ');
6508 			debug(to_char(SQLCODE)||substr(SQLERRM, 1, 255));
6509 			debug_out('Unexpected error occured while populating hidden column: Old Parent Instance.');
6510 	END;
6511 
6512 	--SYSTEM_ID
6513 	BEGIN
6514 		UPDATE csi_webadi_staging cws SET SYSTEM_ID =
6515 		(
6516 			select s.SYSTEM_ID
6517 			FROM CSI_LOOKUPS LK, csi_systems_v s
6518 			WHERE s.SYSTEM_TYPE_CODE = LK.LOOKUP_CODE(+)
6519 				AND LK.LOOKUP_TYPE (+) = 'CSI_SYSTEM_TYPE'
6520 				AND s.NAME = cws.SYSTEM_NAME
6521 		)
6522 		WHERE cws.batch_id = p_Entry_id;
6523 		debug('Populated SYSTEM_ID column');
6524 	EXCEPTION
6525 		WHEN OTHERS THEN
6526 			debug('Unexpected error while populating SYSTEM_ID column: ');
6527 			debug(to_char(SQLCODE)||substr(SQLERRM, 1, 255));
6528 			debug_out('Unexpected error occured while generating IDs for System Name field.');
6529 	END;
6530 
6531 END Populate_WebAdi_Ids;
6532 
6533 End CSI_MASS_EDIT_PUB;