DBA Data[Home] [Help]

PACKAGE BODY: APPS.GMF_MIGRATION

Source


1 PACKAGE BODY GMF_MIGRATION AS
2 /* $Header: gmfmigrb.pls 120.48 2006/12/16 14:21:54 anthiyag noship $ */
3 
4 	 /**********************************************************************
5 	 *    FUNCTION:                                                        *
6 	 *      Get_Inventory_Item_Id                                          *
7 	 *                                                                     *
8 	 *    DESCRIPTION:                                                     *
9 	 *      This is an internal function used to retrieve the Inventory    *
10 	 *      Item Id value for the OPM Item Id passed                       *
11 	 *                                                                     *
12 	 *    PARAMETERS:                                                      *
13 	 *      p_item_id    - OPM Item Id to retrieve the value.              *
14 	 *                                                                     *
15 	 *    SYNOPSIS:                                                        *
16 	 *      Get_Inventory_Item_Id (p_Item_id => 12121);                    *
17 	 *                                                                     *
18 	 *    HISTORY                                                          *
19 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
20 	 **********************************************************************/
21 	 FUNCTION Get_Inventory_Item_Id
22 	 (
23 	 p_Item_id               IN             NUMBER
24 	 )
25 	 RETURN NUMBER
26 	 IS
27 
28 			/************************
29 			* Local Variables       *
30 			************************/
31 
32 			l_Inventory_item_id           mtl_system_items_b.inventory_item_id%TYPE;
33 
34 			/****************
35 			* Cursors       *
36 			****************/
37 
38 			CURSOR      cur_Inventory_item_id
39 			(
40 			p_Item_id            IN       NUMBER
41 			)
42 			IS
43 			SELECT      inventory_item_id
44 			FROM        ic_item_mst_b_mig
45 			WHERE       item_id = p_item_id
46 			AND         inventory_item_id IS NOT NULL
47 			AND         ROWNUM = 1;
48 
49 	 BEGIN
50 
51 			OPEN Cur_Inventory_item_id(p_item_id);
52 			FETCH Cur_Inventory_item_id INTO L_Inventory_item_id;
53 
54 			IF Cur_Inventory_item_id%NOTFOUND THEN
55 				CLOSE Cur_Inventory_item_id;
56 				RAISE NO_DATA_FOUND;
57 			END IF;
58 
59 			CLOSE Cur_Inventory_item_id;
60 
61 			RETURN(L_Inventory_item_id);
62 
63 	 EXCEPTION
64 			WHEN OTHERS THEN
65 
66 				 /********************************
67 				 * Migration Started Log Message *
68 				 ********************************/
69 
70 				 GMA_COMMON_LOGGING.gma_migration_central_log
71 				 (
72 				 p_run_id             =>       G_migration_run_id,
73 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
74 				 p_message_token      =>       'GMA_MIG_ITEM_ERROR',
75 				 p_table_name         =>       G_Table_name,
76 				 p_context            =>       G_context,
77 				 p_token1             =>       'ITEM_ID',
78 				 p_param1             =>       p_item_id,
79 				 p_db_error           =>       NULL,
80 				 p_app_short_name     =>       'GMA'
81 				 );
82 
83 				RETURN NULL;
84 
85 	 END Get_Inventory_item_id;
86 
87 	 /****************************************************************************
88 	 *    FUNCTION:                                                              *
89 	 *      Get_Legal_entity_Id                                                  *
90 	 *                                                                           *
91 	 *    DESCRIPTION:                                                           *
92 	 *      This is an internal function used to retrieve the Legal Entity Id    *
93 	 *      value for the Company Code passed                                    *
94 	 *                                                                           *
95 	 *    PARAMETERS:                                                            *
96 	 *      p_co_code    - Company Code to retrieve the value.                   *
97 	 *                                                                           *
98 	 *    SYNOPSIS:                                                              *
99 	 *      Get_Legal_entity_Id (p_co_code => 'PR1',                             *
100 	 *                          p_source_type => 'O');                           *
101 	 *                                                                           *
102 	 *    HISTORY                                                                *
103 	 *       27-Apr-2005 Created  Anand Thiyagarajan                             *
104 	 *                                                                           *
105 	 ****************************************************************************/
106 	 FUNCTION Get_Legal_Entity_Id
107 	 (
108 	 p_co_code               IN             VARCHAR2,
109 	 p_source_type           IN             VARCHAR2
110 	 )
111 	 RETURN NUMBER
112 	 IS
113 
114 			/************************
115 			* Local Variables       *
116 			************************/
117 
118 			L_legal_entity_id       gmf_fiscal_policies.legal_entity_id%TYPE;
119 
120 			/****************
121 			* Cursors       *
122 			****************/
123 
124 			CURSOR      cur_legal_entity
125 			(
126 			p_co_code      IN    VARCHAR2,
127 			p_source_type  IN    VARCHAR2
128 			)
129 			IS
130 			SELECT      to_number(a.org_information2) legal_entity_id
131 			FROM        hr_organization_information a, gl_plcy_mst b
132 			WHERE       a.organization_id = b.org_id
133 			AND         b.co_code = p_co_code
134 			AND         p_source_type = 'O'
135 			and         a.org_information_context = 'Operating Unit Information'
136 			UNION
137 			SELECT      a.legal_entity_id
138 			FROM        gl_plcy_mst a
139 			WHERE       a.co_code = p_co_code
140 			AND         p_source_type = 'N';
141 
142 	 BEGIN
143 
144 			OPEN Cur_legal_entity(p_co_code, p_source_type);
145 			FETCH Cur_legal_entity INTO L_legal_entity_id;
146 
147 			IF Cur_legal_entity%NOTFOUND THEN
148 				CLOSE Cur_legal_entity;
149 				RAISE NO_DATA_FOUND;
150 			END IF;
151 
152 			CLOSE Cur_legal_entity;
153 
154 			RETURN(L_legal_entity_id);
155 
156 	 EXCEPTION
157 			WHEN no_data_found THEN
158 
159 				 /********************************
160 				 * Migration Started Log Message *
161 				 ********************************/
162 
163 				 GMA_COMMON_LOGGING.gma_migration_central_log
164 				 (
165 				 p_run_id             =>       G_migration_run_id,
166 				 p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
167 				 p_message_token      =>       'GMA_MIG_LE_CO_ERROR',
168 				 p_table_name         =>       G_Table_name,
169 				 p_context            =>       G_context,
170 				 p_token1             =>       'CO_CODE',
171 				 p_param1             =>       p_co_code,
172 				 p_db_error           =>       NULL,
173 				 p_app_short_name     =>       'GMA'
174 				 );
175 
176 				RETURN NULL;
177 
178 	 END Get_Legal_Entity_id;
179 
180 	 /****************************************************************************
181 	 *    FUNCTION:                                                              *
182 	 *      Get_Legal_entity_Id                                                  *
183 	 *                                                                           *
184 	 *    DESCRIPTION:                                                           *
185 	 *      This is a overhealoaded function used to retrieve the Legal Entity Id*
186 	 *      value for the Organization Id passed                                 *
187 	 *                                                                           *
188 	 *    PARAMETERS:                                                            *
189 	 *      p_organization_id - Organization Id to retrieve the value.           *
190 	 *                                                                           *
191 	 *    SYNOPSIS:                                                              *
192 	 *      Get_Legal_entity_Id (p_organization_id => 1381);                     *
193 	 *                                                                           *
194 	 *    HISTORY                                                                *
195 	 *       27-Apr-2005 Created  Anand Thiyagarajan                             *
196 	 *                                                                           *
197 	 ****************************************************************************/
198 	 FUNCTION Get_Legal_Entity_Id
199 	 (
200 	 p_organization_id       IN             NUMBER
201 	 )
202 	 RETURN NUMBER
203 	 IS
204 
205 			/************************
206 			* Local Variables       *
207 			************************/
208 
209 			L_legal_entity_id       gmf_fiscal_policies.legal_entity_id%TYPE;
210 
211 			/****************
212 			* Cursors       *
213 			****************/
214 
215 			CURSOR      cur_legal_entity
216 			(
217 			p_organization_id   IN    NUMBER
218 			)
219 			IS
220 			SELECT      to_number(a.org_information2) legal_entity_id
221 			FROM        hr_organization_information a
222 			WHERE       a.organization_id = p_organization_id
223 			AND         a.org_information_context = 'Accounting Information';
224 
225 	 BEGIN
226 
227 			OPEN Cur_legal_entity(p_organization_id);
228 			FETCH Cur_legal_entity INTO L_legal_entity_id;
229 
230 			IF Cur_legal_entity%NOTFOUND THEN
231 				CLOSE Cur_legal_entity;
232 				RAISE NO_DATA_FOUND;
233 			END IF;
234 
235 			CLOSE Cur_legal_entity;
236 
237 			RETURN(L_legal_entity_id);
238 
239 	 EXCEPTION
240 			WHEN no_data_found THEN
241 
242 				 /********************************
243 				 * Migration Started Log Message *
244 				 ********************************/
245 
246 				 GMA_COMMON_LOGGING.gma_migration_central_log
247 				 (
248 				 p_run_id             =>       G_migration_run_id,
249 				 p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
250 				 p_message_token      =>       'GMA_MIG_LE_ORG_ERROR',
251 				 p_table_name         =>       G_Table_name,
252 				 p_context            =>       G_context,
253 				 p_token1             =>       'ORGANIZATION_ID',
254 				 p_param1             =>       p_organization_id,
255 				 p_db_error           =>       NULL,
256 				 p_app_short_name     =>       'GMA'
257 				 );
258 
259 				RETURN NULL;
260 
261 	 END Get_Legal_Entity_id;
262 
263 	 /****************************************************************************
264 	 *    FUNCTION:                                                              *
265 	 *      Get_Legal_entity_Id                                                  *
266 	 *                                                                           *
267 	 *    DESCRIPTION:                                                           *
268 	 *      This is a overhealoaded function used to retrieve the Legal Entity Id*
269 	 *      value for the Warehouse Code passed                                  *
270 	 *                                                                           *
271 	 *    PARAMETERS:                                                            *
272 	 *      p_whse_code_id - Warehouse code to retrieve the value.               *
273 	 *                                                                           *
274 	 *    SYNOPSIS:                                                              *
275 	 *      Get_Legal_entity_Id (p_whse_code=> 'PR1');                           *
276 	 *                                                                           *
277 	 *    HISTORY                                                                *
278 	 *       27-Apr-2005 Created  Anand Thiyagarajan                             *
279 	 *                                                                           *
280 	 ****************************************************************************/
281 	 FUNCTION Get_Legal_Entity_Id
282 	 (
283 	 p_whse_code             IN             VARCHAR2
284 	 )
285 	 RETURN NUMBER
286 	 IS
287 
288 			/************************
289 			* Local Variables       *
290 			************************/
291 
292 			L_legal_entity_id       gmf_fiscal_policies.legal_entity_id%TYPE;
293 
294 			/****************
295 			* Cursors       *
296 			****************/
297 
298 			CURSOR      cur_legal_entity
299 			(
300 			p_whse_code   IN    VARCHAR2
301 			)
302 			IS
303 			SELECT      to_number(a.org_information2) legal_entity_id
304 			FROM        hr_organization_information a, ic_whse_mst b
305 			WHERE       a.organization_id = decode(nvl(b.subinventory_ind_flag, 'N'), 'Y', b.organization_id, b.mtl_organization_id)
306 			AND         b.whse_code = p_whse_code
307 			AND         a.org_information_context = 'Accounting Information';
308 
309 	 BEGIN
310 
311 			OPEN Cur_legal_entity(p_whse_code);
312 			FETCH Cur_legal_entity INTO L_legal_entity_id;
313 
314 			IF Cur_legal_entity%NOTFOUND THEN
315 				CLOSE Cur_legal_entity;
316 				RAISE NO_DATA_FOUND;
317 			END IF;
318 
319 			CLOSE Cur_legal_entity;
320 
321 			RETURN(L_legal_entity_id);
322 
323 	 EXCEPTION
324 			WHEN no_data_found THEN
325 
326 				 /********************************
327 				 * Migration Started Log Message *
328 				 ********************************/
329 
330 				 GMA_COMMON_LOGGING.gma_migration_central_log
331 				 (
332 				 p_run_id             =>       G_migration_run_id,
333 				 p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
334 				 p_message_token      =>       'GMA_MIG_LE_WHSE_ERROR',
335 				 p_table_name         =>       G_Table_name,
336 				 p_context            =>       G_context,
337 				 p_token1             =>       'WHSE_CODE',
338 				 p_param1             =>       p_whse_code,
339 				 p_db_error           =>       NULL,
340 				 p_app_short_name     =>       'GMA'
341 				 );
342 
343 				RETURN NULL;
344 
345 	 END Get_Legal_Entity_id;
346 
347 	 /**********************************************************************
348 	 *    FUNCTION:                                                        *
349 	 *      Get_Item_number                                                *
350 	 *                                                                     *
351 	 *    DESCRIPTION:                                                     *
352 	 *      This is an internal function used to retrieve the Item Number  *
353 	 *                                                                     *
354 	 *    PARAMETERS:                                                      *
355 	 *      p_inventory_item_id - ODM Item Id to retrieve the value.       *
356 	 *                                                                     *
357 	 *    SYNOPSIS:                                                        *
358 	 *      Get_Item_number (p_inventory_Item_id => 12121);                *
359 	 *                                                                     *
360 	 *    HISTORY                                                          *
361 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
362 	 **********************************************************************/
363 	 FUNCTION Get_Item_Number
364 	 (
365 	 p_inventory_item_id     IN             NUMBER
366 	 )
367 	 RETURN VARCHAR2
368 	 IS
369 
370 			/************************
371 			* Local Variables       *
372 			************************/
373 
374 			l_Item_number           mtl_item_flexfields.item_number%TYPE;
375 
376 			/****************
377 			* Cursors       *
378 			****************/
379 
380 			CURSOR      cur_item_number
381 			(
382 			p_Inventory_item_id  IN       NUMBER
383 			)
384 			IS
385 			SELECT      item_number
386 			FROM        mtl_item_flexfields
387 			WHERE       inventory_item_id = p_inventory_item_id
388 			AND         ROWNUM = 1;
389 
390 	 BEGIN
391 
392 			OPEN Cur_item_number(p_inventory_item_id);
393 			FETCH Cur_item_number INTO L_item_number;
394 
395 			IF Cur_item_number%NOTFOUND THEN
396 				CLOSE Cur_item_number;
397 				RAISE NO_DATA_FOUND;
398 			END IF;
399 
400 			CLOSE Cur_item_number;
401 
402 			RETURN(L_item_number);
403 
404 	 EXCEPTION
405 			WHEN OTHERS THEN
406 
407 				 /********************************
408 				 * Migration Started Log Message *
409 				 ********************************/
410 
411 				 GMA_COMMON_LOGGING.gma_migration_central_log
412 				 (
413 				 p_run_id             =>       G_migration_run_id,
414 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
415 				 p_message_token      =>       'GMA_MIG_ITEM_NO_ERROR',
416 				 p_table_name         =>       G_Table_name,
417 				 p_context            =>       G_context,
418 				 p_token1             =>       'INVENTORY_ITEM_ID',
419 				 p_param1             =>       p_inventory_item_id,
420 				 p_db_error           =>       NULL,
421 				 p_app_short_name     =>       'GMA'
422 				 );
423 
424 				RETURN NULL;
425 
426 	 END Get_item_number;
427 
428 	 /**********************************************************************
429 	 *    FUNCTION:                                                        *
430 	 *      Get_Customer_no                                                *
431 	 *                                                                     *
432 	 *    DESCRIPTION:                                                     *
433 	 *      This is an internal function used to retrieve the Customer No  *
434 	 *                                                                     *
435 	 *    PARAMETERS:                                                      *
436 	 *      p_cust_id - OPM Customer Id to retrieve the value.             *
437 	 *                                                                     *
438 	 *    SYNOPSIS:                                                        *
439 	 *      Get_Customer_no (p_cust_id => 12121);                          *
440 	 *                                                                     *
441 	 *    HISTORY                                                          *
442 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
443 	 **********************************************************************/
444 	 FUNCTION Get_Customer_no
445 	 (
446 	 p_cust_id     IN             NUMBER
447 	 )
448 	 RETURN VARCHAR2
449 	 IS
450 
451 			/************************
452 			* Local Variables       *
453 			************************/
454 
455 			l_customer_no                 op_cust_mst.cust_no%TYPE;
456 
457 			/****************
458 			* Cursors       *
459 			****************/
460 
461 			CURSOR      cur_cust_no
462 			(
463 			p_cust_id  IN       NUMBER
464 			)
465 			IS
466 			SELECT      cust_no
467 			FROM        op_cust_mst
468 			WHERE       cust_id = p_cust_id;
469 
470 	 BEGIN
471 
472 			OPEN Cur_cust_no(p_cust_id);
473 			FETCH Cur_cust_no INTO l_customer_no;
474 
475 			IF Cur_cust_no%NOTFOUND THEN
476 				CLOSE Cur_cust_no;
477 				RAISE NO_DATA_FOUND;
478 			END IF;
479 
480 			CLOSE Cur_cust_no;
481 
482 			RETURN(l_customer_no);
483 
484 	 EXCEPTION
485 			WHEN OTHERS THEN
486 
487 				 /********************************
488 				 * Migration Started Log Message *
489 				 ********************************/
490 
491 				 GMA_COMMON_LOGGING.gma_migration_central_log
492 				 (
493 				 p_run_id             =>       G_migration_run_id,
494 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
495 				 p_message_token      =>       'GMA_MIG_CUSTOMER_ERROR',
496 				 p_table_name         =>       G_Table_name,
497 				 p_context            =>       G_context,
498 				 p_token1             =>       'CUST_ID',
499 				 p_param1             =>       p_cust_id,
500 				 p_db_error           =>       NULL,
501 				 p_app_short_name     =>       'GMA'
502 				 );
503 
504 				RETURN NULL;
505 
506 	 END Get_Customer_no;
507 
508 	 /**********************************************************************
509 	 *    FUNCTION:                                                        *
510 	 *      Get_Vendor_id                                                  *
511 	 *                                                                     *
512 	 *    DESCRIPTION:                                                     *
513 	 *      This is an internal function used to retrieve the Vendor No    *
514 	 *                                                                     *
515 	 *    PARAMETERS:                                                      *
516 	 *      p_vendor_id - OPM Vendor Id to retrieve the value.             *
517 	 *                                                                     *
518 	 *    SYNOPSIS:                                                        *
519 	 *      Get_Vendor_id (p_vendor_id => 12121);                          *
520 	 *                                                                     *
521 	 *    HISTORY                                                          *
522 	 *       27-Apr-2005  Created  Anand Thiyagarajan                      *
523    *       12-Oct-2006  Modified Anand Thiyagarajan                      *
524    *          Modified Procedure to fetch of_vendor_site_id              *
525 	 **********************************************************************/
526 	 FUNCTION Get_Vendor_id
527 	 (
528 	 p_vendor_id       IN             NUMBER
529 	 )
530 	 RETURN NUMBER
531 	 IS
532 
533 			/************************
534 			* Local Variables       *
535 			************************/
536 
537 			l_vendor_site_id                   po_vend_mst.of_vendor_site_id%TYPE;
538 
539 			/****************
540 			* Cursors       *
541 			****************/
542 
543 			CURSOR      cur_vendor_id
544 			(
545 			p_vendor_id  IN       NUMBER
546 			)
547 			IS
548 			SELECT      of_vendor_site_id
549 			FROM        po_vend_mst
550 			WHERE       vendor_id = p_vendor_id;
551 
552 	 BEGIN
553 			OPEN cur_vendor_id(p_vendor_id);
554 			FETCH cur_vendor_id INTO l_vendor_site_id;
555 			IF cur_vendor_id%NOTFOUND THEN
556 				CLOSE cur_vendor_id;
557 				RAISE NO_DATA_FOUND;
558 			END IF;
559 			CLOSE cur_vendor_id;
560 			RETURN(l_vendor_site_id);
561 	 EXCEPTION
562 			WHEN OTHERS THEN
563 				 /********************************
564 				 * Migration Started Log Message *
565 				 ********************************/
566 				 GMA_COMMON_LOGGING.gma_migration_central_log
567 				 (
568 				 p_run_id             =>       G_migration_run_id,
569 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
570 				 p_message_token      =>       'GMA_MIG_VENDOR_ERROR',
571 				 p_table_name         =>       G_Table_name,
572 				 p_context            =>       G_context,
573 				 p_token1             =>       'VENDOR_ID',
574 				 p_param1             =>       p_vendor_id,
575 				 p_db_error           =>       NULL,
576 				 p_app_short_name     =>       'GMA'
577 				 );
578 				RETURN NULL;
579 	 END Get_Vendor_id;
580 
581 	 /**********************************************************************
582 	 *    FUNCTION:                                                        *
583 	 *      Get_Vendor_no                                                  *
584 	 *                                                                     *
585 	 *    DESCRIPTION:                                                     *
586 	 *      This is an internal function used to retrieve the Vendor No    *
587 	 *                                                                     *
588 	 *    PARAMETERS:                                                      *
589 	 *      p_vendor_id - OPM Vendor Id to retrieve the value.             *
590 	 *                                                                     *
591 	 *    SYNOPSIS:                                                        *
592 	 *      Get_Vendor_no (p_vendor_id => 12121);                          *
593 	 *                                                                     *
594 	 *    HISTORY                                                          *
595 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
596 	 **********************************************************************/
597 	 FUNCTION Get_Vendor_no
598 	 (
599 	 p_vendor_id       IN             NUMBER
600 	 )
601 	 RETURN VARCHAR2
602 	 IS
603 			/************************
604 			* Local Variables       *
605 			************************/
606 			l_vendor_no                   po_vend_mst.vendor_no%TYPE;
607 			/****************
608 			* Cursors       *
609 			****************/
610 			CURSOR      cur_vendor_no
611 			(
612 			p_vendor_id  IN       NUMBER
613 			)
614 			IS
615 			SELECT      vendor_no
616 			FROM        po_vend_mst
617 			WHERE       vendor_id = p_vendor_id;
618 	 BEGIN
619 			OPEN cur_vendor_no(p_vendor_id);
620 			FETCH cur_vendor_no INTO l_vendor_no;
621 			IF cur_vendor_no%NOTFOUND THEN
622 				CLOSE cur_vendor_no;
623 				RAISE NO_DATA_FOUND;
624 			END IF;
625 			CLOSE cur_vendor_no;
626 			RETURN(l_vendor_no);
627 	 EXCEPTION
628 			WHEN OTHERS THEN
629 				 /********************************
630 				 * Migration Started Log Message *
631 				 ********************************/
632 				 GMA_COMMON_LOGGING.gma_migration_central_log
633 				 (
634 				 p_run_id             =>       G_migration_run_id,
635 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
636 				 p_message_token      =>       'GMA_MIG_VENDOR_ERROR',
637 				 p_table_name         =>       G_Table_name,
638 				 p_context            =>       G_context,
639 				 p_token1             =>       'VENDOR_ID',
640 				 p_param1             =>       p_vendor_id,
641 				 p_db_error           =>       NULL,
642 				 p_app_short_name     =>       'GMA'
643 				 );
644 				RETURN NULL;
645 	 END Get_Vendor_no;
646 
647 	 /**********************************************************************
648 	 *    FUNCTION:                                                        *
649 	 *      Get_reason_id                                                  *
650 	 *                                                                     *
651 	 *    DESCRIPTION:                                                     *
652 	 *      This is an internal function used to retrieve the Reason_id    *
653 	 *                                                                     *
654 	 *    PARAMETERS:                                                      *
655 	 *      p_reason_code - OPM Reason Code to retrieve the value.         *
656 	 *                                                                     *
657 	 *    SYNOPSIS:                                                        *
658 	 *      Get_Reason_id(p_reason_code => 'ADD');                         *
659 	 *                                                                     *
660 	 *    HISTORY                                                          *
661 	 *       28-Sep-2006 Created  Anand Thiyagarajan                       *
662 	 **********************************************************************/
663 	 FUNCTION Get_reason_id
664 	 (
665 	 p_reason_code        IN          VARCHAR2
666 	 )
667 	 RETURN NUMBER
668 	 IS
669 
670 			/************************
671 			* Local Variables       *
672 			************************/
673 
674 			l_reason_id                   mtl_transaction_Reasons.reason_id%TYPE;
675 
676 			/****************
677 			* Cursors       *
678 			****************/
679 
680 			CURSOR      cur_reason_id
681 			(
682 			p_reason_Code   IN      VARCHAR2
683 			)
684 			IS
685 			SELECT      reason_id
686 			FROM        mtl_transaction_Reasons
687 			WHERE       reason_name = p_reason_code;
688 
689 	 BEGIN
690 
691 			OPEN cur_reason_id(p_reason_code);
692 			FETCH cur_reason_id INTO l_reason_id;
693 
694 			IF cur_reason_id%NOTFOUND THEN
695 				CLOSE cur_reason_id;
696 				RAISE NO_DATA_FOUND;
697 			END IF;
698 
699 			CLOSE cur_reason_id;
700 
701 			RETURN(l_reason_id);
702 
703 	 EXCEPTION
704 			WHEN OTHERS THEN
705 				RETURN NULL;
706 	 END Get_reason_id;
707 
708 	 /**********************************************************************
709 	 *    PROCEDURE                                                        *
710 	 *      Get_Routing_no                                                 *
711 	 *                                                                     *
712 	 *    DESCRIPTION:                                                     *
713 	 *      This is an internal procedure used to retrieve the routing No  *
714 	 *                                                                     *
715 	 *    PARAMETERS:                                                      *
716 	 *      p_routing_id - OPM routing Id to retrieve the value.           *
717 	 *                                                                     *
718 	 *    SYNOPSIS:                                                        *
719 	 *      Get_routing_no (p_routing_id => 12121);                        *
720 	 *                                                                     *
721 	 *    HISTORY                                                          *
722 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
723 	 **********************************************************************/
724 	 PROCEDURE Get_Routing_no
725 	 (
726 	 p_routing_id         IN                NUMBER,
727 	 x_routing_no            OUT   NOCOPY   VARCHAR2,
728 	 x_routing_vers          OUT   NOCOPY   NUMBER
729 	 )
730 	 IS
731 
732 			/************************
733 			* Local Variables       *
734 			************************/
735 
736 			l_routing_no                   GMD_ROUTINGS_B.routing_no%TYPE;
737 			l_routing_vers                 GMD_ROUTINGS_B.routing_vers%TYPE;
738 
739 			/****************
740 			* Cursors       *
741 			****************/
742 
743 			CURSOR      cur_routing_no
744 			(
745 			p_routing_id  IN       NUMBER
746 			)
747 			IS
748 			SELECT      routing_no,
749 									routing_vers
750 			FROM        GMD_ROUTINGS_B
751 			WHERE       routing_id = p_routing_id;
752 
753 	 BEGIN
754 
755 			OPEN cur_routing_no(p_routing_id);
756 			FETCH cur_routing_no INTO l_routing_no, l_routing_vers;
757 
758 			IF cur_routing_no%NOTFOUND THEN
759 				CLOSE cur_routing_no;
760 				RAISE NO_DATA_FOUND;
761 			END IF;
762 
763 			CLOSE cur_routing_no;
764 
765 			x_routing_no := l_routing_no;
766 			x_routing_vers := l_routing_vers;
767 
768 	 EXCEPTION
769 			WHEN OTHERS THEN
770 
771 				 /********************************
772 				 * Migration Started Log Message *
773 				 ********************************/
774 
775 				 GMA_COMMON_LOGGING.gma_migration_central_log
776 				 (
777 				 p_run_id             =>       G_migration_run_id,
778 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
779 				 p_message_token      =>       'GMA_MIG_ROUTING_ERROR',
780 				 p_table_name         =>       G_Table_name,
781 				 p_context            =>       G_context,
782 				 p_token1             =>       'ROUTING_ID',
783 				 p_param1             =>       p_routing_id,
784 				 p_db_error           =>       NULL,
785 				 p_app_short_name     =>       'GMA'
786 				 );
787 
788 			x_routing_no := NULL;
789 			x_routing_vers := NULL;
790 
791 	 END Get_routing_no;
792 
793 	 /**********************************************************************
794 	 *    FUNCTION:                                                        *
795 	 *      Get_aqui_cost_code                                             *
796 	 *                                                                     *
797 	 *    DESCRIPTION:                                                     *
798 	 *      This is an internal function used to retrieve aqui cost Code   *
799 	 *                                                                     *
800 	 *    PARAMETERS:                                                      *
801 	 *      p_aqui_cost_id - OPM aqui_cost Id to retrieve the value.       *
802 	 *                                                                     *
803 	 *    SYNOPSIS:                                                        *
804 	 *      Get_aqui_cost_code (p_aqui_cost_id => 12121);                  *
805 	 *                                                                     *
806 	 *    HISTORY                                                          *
807 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
808 	 **********************************************************************/
809 	 FUNCTION Get_price_element_Type_id
810 	 (
811 	 p_aqui_cost_id       IN             NUMBER
812 	 )
813 	 RETURN NUMBER
814 	 IS
815 			/************************
816 			* Local Variables       *
817 			************************/
818 			l_price_element_type_id          po_cost_mst.price_element_type_id%TYPE;
819 			/****************
820 			* Cursors       *
821 			****************/
822 			CURSOR      cur_price_element_type_id
823 			(
824 			p_aqui_cost_id  IN       NUMBER
825 			)
826 			IS
827 			SELECT      price_element_type_id
828 			FROM        po_cost_mst
829 			WHERE       aqui_cost_id = p_aqui_cost_id
830 			AND         nvl(migrated_ind, 0) = 1;
831 
832 	 BEGIN
833 
834 			OPEN cur_price_element_type_id(p_aqui_cost_id);
835 			FETCH cur_price_element_type_id INTO l_price_element_type_id;
836 
837 			IF cur_price_element_type_id%NOTFOUND THEN
838 				CLOSE cur_price_element_type_id;
839 				RAISE NO_DATA_FOUND;
840 			END IF;
841 			CLOSE cur_price_element_type_id;
842 			RETURN(l_price_element_type_id);
843 	 EXCEPTION
844 			WHEN OTHERS THEN
845 				 /********************************
846 				 * Migration Started Log Message *
847 				 ********************************/
848 				 GMA_COMMON_LOGGING.gma_migration_central_log
849 				 (
850 				 p_run_id             =>       G_migration_run_id,
851 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
852 				 p_message_token      =>       'GMA_MIG_AQUI_CODE_ERROR',
853 				 p_table_name         =>       G_Table_name,
854 				 p_context            =>       G_context,
855 				 p_token1             =>       'AQUI_COST_ID',
856 				 p_param1             =>       p_aqui_cost_id,
857 				 p_db_error           =>       NULL,
858 				 p_app_short_name     =>       'GMA'
859 				 );
860 				RETURN NULL;
861 	 END Get_price_element_Type_id;
862 
863 	 /**********************************************************************
864 	 *    FUNCTION:                                                        *
865 	 *      Get_cost_cmpntcls_code                                         *
866 	 *                                                                     *
867 	 *    DESCRIPTION:                                                     *
868 	 *      This is an internal function used to retrieve costcmpntcls Code*
869 	 *                                                                     *
870 	 *    PARAMETERS:                                                      *
871 	 *      p_cost_cmpntcls_id - OPM cost_cmpntcls Id to retrieve the value*
872 	 *                                                                     *
873 	 *    SYNOPSIS:                                                        *
874 	 *      Get_cost_cmpntcls_code (p_cost_cmpntcls_id => 12121);          *
875 	 *                                                                     *
876 	 *    HISTORY                                                          *
877 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
878 	 **********************************************************************/
879 	 FUNCTION Get_Cost_cmpntcls_code
880 	 (
881 	 p_cost_cmpntcls_id       IN             NUMBER
882 	 )
883 	 RETURN VARCHAR2
884 	 IS
885 
886 			/************************
887 			* Local Variables       *
888 			************************/
889 
890 			l_cost_cmpntcls_code                   cm_cmpt_mst.cost_cmpntcls_code%TYPE;
891 
892 			/****************
893 			* Cursors       *
894 			****************/
895 
896 			CURSOR      cur_cost_cmpntcls_code
897 			(
898 			p_cost_cmpntcls_id  IN       NUMBER
899 			)
900 			IS
901 			SELECT      cost_cmpntcls_code
902 			FROM        cm_cmpt_mst
903 			WHERE       cost_cmpntcls_id = p_cost_cmpntcls_id;
904 
905 	 BEGIN
906 
907 			OPEN cur_cost_cmpntcls_code(p_cost_cmpntcls_id);
908 			FETCH cur_cost_cmpntcls_code INTO l_cost_cmpntcls_code;
909 
910 			IF cur_cost_cmpntcls_code%NOTFOUND THEN
911 				CLOSE cur_cost_cmpntcls_code;
912 				RAISE NO_DATA_FOUND;
913 			END IF;
914 
915 			CLOSE cur_cost_cmpntcls_code;
916 
917 			RETURN(l_cost_cmpntcls_code);
918 
919 	 EXCEPTION
920 			WHEN OTHERS THEN
921 
922 				 /********************************
923 				 * Migration Started Log Message *
924 				 ********************************/
925 
926 				 GMA_COMMON_LOGGING.gma_migration_central_log
927 				 (
928 				 p_run_id             =>       G_migration_run_id,
929 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
930 				 p_message_token      =>       'GMA_MIG_CMPNTCLS_ERROR',
931 				 p_table_name         =>       G_Table_name,
932 				 p_context            =>       G_context,
933 				 p_token1             =>       'COST_CMPNTCLS_ID',
934 				 p_param1             =>       p_cost_cmpntcls_id,
935 				 p_db_error           =>       NULL,
936 				 p_app_short_name     =>       'GMA'
937 				 );
938 
939 				RETURN NULL;
940 
941 	 END Get_cost_cmpntcls_code;
942 
943 	 /**********************************************************************
944 	 *    FUNCTION:                                                        *
945 	 *      Get_Order_type_code                                            *
946 	 *                                                                     *
947 	 *    DESCRIPTION:                                                     *
948 	 *      This is an internal function used to retrieve Order_type Code  *
949 	 *                                                                     *
950 	 *    PARAMETERS:                                                      *
951 	 *      p_Order_type_id - OPM Order_type Id to retrieve the value.     *
952 	 *                                                                     *
953 	 *    SYNOPSIS:                                                        *
954 	 *      Get_Order_type_code (p_Order_type_id => 12121);                *
955 	 *                                                                     *
956 	 *    HISTORY                                                          *
957 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
958 	 **********************************************************************/
959 	 FUNCTION Get_Order_type_code
960 	 (
961 	 p_Order_type            IN             NUMBER,
962 	 p_source_type           IN             NUMBER
963 	 )
964 	 RETURN VARCHAR2
965 	 IS
966 
967 			/************************
968 			* Local Variables       *
969 			************************/
970 
971 			l_Order_type_code                   OP_ORDR_TYP.Order_type_code%TYPE;
972 
973 			/****************
974 			* Cursors       *
975 			****************/
976 
977 			CURSOR      cur_Order_type_code
978 			(
979 			p_Order_type      IN       NUMBER,
980 			p_source_type     IN       NUMBER
981 			)
982 			IS
983 			SELECT      order_type_code
984 			FROM        op_ordr_typ
985 			WHERE       lang_code = userenv('LANG')
986 			AND         nvl(p_source_type,0) = 0
987 			AND         order_type = p_Order_type
988 			UNION ALL
989 			SELECT      tl.name
990 			FROM        oe_transaction_types_all t,
991 									oe_transaction_types_tl tl
992 			WHERE       t.transaction_type_id = tl.transaction_type_id
993 			AND         tl.language = userenv('LANG')
994 			AND         nvl(p_source_type,0) = 11
995 			AND         t.transaction_type_code = 'ORDER'
996 			AND         t.transaction_type_id = p_Order_type;
997 
998 	 BEGIN
999 
1000 			OPEN cur_Order_type_code(p_Order_type, p_source_type);
1001 			FETCH cur_Order_type_code INTO l_Order_type_code;
1002 
1003 			IF cur_Order_type_code%NOTFOUND THEN
1004 				CLOSE cur_Order_type_code;
1005 				RAISE NO_DATA_FOUND;
1006 			END IF;
1007 
1008 			CLOSE cur_Order_type_code;
1009 
1010 			RETURN(l_Order_type_code);
1011 
1012 	 EXCEPTION
1013 			WHEN OTHERS THEN
1014 
1015 				 /********************************
1016 				 * Migration Started Log Message *
1017 				 ********************************/
1018 
1019 				 GMA_COMMON_LOGGING.gma_migration_central_log
1020 				 (
1021 				 p_run_id             =>       G_migration_run_id,
1022 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
1023 				 p_message_token      =>       'GMA_MIG_ORDER_TYPE_ERROR',
1024 				 p_table_name         =>       G_Table_name,
1025 				 p_context            =>       G_context,
1026 				 p_token1             =>       'ORDER_TYPE',
1027 				 p_param1             =>       p_Order_type,
1028 				 p_db_error           =>       NULL,
1029 				 p_app_short_name     =>       'GMA'
1030 				 );
1031 
1032 				RETURN NULL;
1033 
1034 	 END Get_Order_type_code;
1035 
1036 	 /**********************************************************************
1037 	 *    FUNCTION:                                                        *
1038 	 *      Get_Line_type_code                                             *
1039 	 *                                                                     *
1040 	 *    DESCRIPTION:                                                     *
1041 	 *      This is an internal function used to retrieve Line_type Code   *
1042 	 *                                                                     *
1043 	 *    PARAMETERS:                                                      *
1044 	 *      p_Line_type_id - OPM Line_type Id to retrieve the value.       *
1045 	 *                                                                     *
1046 	 *    SYNOPSIS:                                                        *
1047 	 *      Get_Line_type_code (p_Line_type => 12121);                     *
1048 	 *                                                                     *
1049 	 *    HISTORY                                                          *
1050 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
1051 	 **********************************************************************/
1052 	 FUNCTION Get_Line_type_code
1053 	 (
1054 	 p_Line_type            IN             NUMBER
1055 	 )
1056 	 RETURN VARCHAR2
1057 	 IS
1058 
1059 			/************************
1060 			* Local Variables       *
1061 			************************/
1062 
1063 			l_Line_type_code                    gem_lookups.meaning%TYPE;
1064 			l_om                                NUMBER;
1065 			l_opm_om                            VARCHAR2(10);
1066 
1067 			/****************
1068 			* Cursors       *
1069 			****************/
1070 
1071 			CURSOR      cur_Line_type_code
1072 			(
1073 			p_Line_type       IN       NUMBER
1074 			)
1075 			IS
1076 			SELECT         meaning
1077 			FROM           gem_lookups
1078 			WHERE          lookup_type = 'LINE_TYPE'
1079 			AND            nvl(start_date_active,sysdate) <= sysdate
1080 			AND            nvl(end_date_active,sysdate) >= sysdate
1081 			AND            enabled_flag = 'Y'
1082 			AND            lookup_code = p_line_type;
1083 
1084 	 BEGIN
1085 
1086 			OPEN cur_Line_type_code(p_Line_type);
1087 			FETCH cur_Line_type_code INTO l_Line_type_code;
1088 
1089 			IF cur_Line_type_code%NOTFOUND THEN
1090 				CLOSE cur_Line_type_code;
1091 				RAISE NO_DATA_FOUND;
1092 			END IF;
1093 
1094 			CLOSE cur_Line_type_code;
1095 
1096 			RETURN(l_Line_type_code);
1097 
1098 	 EXCEPTION
1099 			WHEN OTHERS THEN
1100 
1101 				 /********************************
1102 				 * Migration Started Log Message *
1103 				 ********************************/
1104 
1105 				 GMA_COMMON_LOGGING.gma_migration_central_log
1106 				 (
1107 				 p_run_id             =>       G_migration_run_id,
1108 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
1109 				 p_message_token      =>       'GMA_MIG_LINE_TYPE_ERROR',
1110 				 p_table_name         =>       G_Table_name,
1111 				 p_context            =>       G_context,
1112 				 p_token1             =>       'LINE_TYPE',
1113 				 p_param1             =>       p_Line_type,
1114 				 p_db_error           =>       NULL,
1115 				 p_app_short_name     =>       'GMA'
1116 				 );
1117 
1118 				RETURN NULL;
1119 
1120 	 END Get_Line_type_code;
1121 
1122 	 /**********************************************************************
1123 	 *    FUNCTION:                                                        *
1124 	 *      Get_ar_trx_type_code                                           *
1125 	 *                                                                     *
1126 	 *    DESCRIPTION:                                                     *
1127 	 *      This is an internal function used to retrieve costcmpntcls Code*
1128 	 *                                                                     *
1129 	 *    PARAMETERS:                                                      *
1130 	 *      p_ar_trx_type_id - OPM ar_trx_type Id to retrieve the value    *
1131 	 *                                                                     *
1132 	 *    SYNOPSIS:                                                        *
1133 	 *      Get_Ar_trx_type_code ( p_ar_trx_type_id => 12121,              *
1134 	 *                             p_co_code = 'PRU');                     *
1135 	 *                                                                     *
1136 	 *    HISTORY                                                          *
1137 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
1138 	 **********************************************************************/
1139 	 FUNCTION Get_Ar_trx_type_code
1140 	 (
1141 	 p_ar_trx_type_id        IN             NUMBER,
1142 	 p_legal_entity_id       IN             NUMBER
1143 	 )
1144 	 RETURN VARCHAR2
1145 	 IS
1146 
1147 			/************************
1148 			* Local Variables       *
1149 			************************/
1150 
1151 			l_ar_trx_type_code                  RA_CUST_TRX_TYPES_ALL.name%TYPE;
1152 
1153 			/****************
1154 			* Cursors       *
1155 			****************/
1156 
1157 			CURSOR      cur_Ar_trx_type_code
1158 			(
1159 			p_Ar_trx_type_id        IN       NUMBER,
1160 			p_legal_entity_id       IN       NUMBER
1161 			)
1162 			IS
1163 			SELECT            rctta.name
1164 			FROM              ra_cust_trx_types_all rctta, ar_lookups al, gl_plcy_mst plcy
1165 			WHERE             sysdate between nvl(rctta.start_date, sysdate-1) and nvl(rctta.end_date, sysdate+1)
1166 			AND               al.lookup_type = 'INV/CM'
1167 			AND               al.lookup_code = rctta.type
1168 			AND               rctta.org_id = plcy.org_id
1169 			AND               plcy.legal_entity_id = p_legal_entity_id
1170 			AND               rctta.cust_trx_type_id = p_Ar_trx_type_id;
1171 
1172 	 BEGIN
1173 
1174 			OPEN cur_Ar_trx_type_code(p_Ar_trx_type_id, p_legal_entity_id);
1175 			FETCH cur_Ar_trx_type_code INTO l_Ar_trx_type_code;
1176 
1177 			IF cur_Ar_trx_type_code%NOTFOUND THEN
1178 				CLOSE cur_Ar_trx_type_code;
1179 				RAISE NO_DATA_FOUND;
1180 			END IF;
1181 
1182 			CLOSE cur_Ar_trx_type_code;
1183 
1184 			RETURN(l_Ar_trx_type_code);
1185 
1186 	 EXCEPTION
1187 			WHEN OTHERS THEN
1188 
1189 				 /********************************
1190 				 * Migration Started Log Message *
1191 				 ********************************/
1192 
1193 				 GMA_COMMON_LOGGING.gma_migration_central_log
1194 				 (
1195 				 p_run_id             =>       G_migration_run_id,
1196 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
1197 				 p_message_token      =>       'GMA_MIG_AR_TRX_TYPE_ERROR',
1198 				 p_table_name         =>       G_Table_name,
1199 				 p_context            =>       G_context,
1200 				 p_token1             =>       'AR_TRX_TYPE_ID',
1201 				 p_param1             =>       p_Ar_trx_type_id,
1202 				 p_db_error           =>       NULL,
1203 				 p_app_short_name     =>       'GMA'
1204 				 );
1205 
1206 				RETURN NULL;
1207 
1208 	 END Get_Ar_trx_type_code;
1209 
1210 	 /**********************************************************************
1211 	 *    FUNCTION:                                                        *
1212 	 *      Get_gl_business_class_cat                                      *
1213 	 *                                                                     *
1214 	 *    DESCRIPTION:                                                     *
1215 	 *      This is an internal function used to retrieve gl_business_class*
1216 	 *                                                                     *
1217 	 *    PARAMETERS:                                                      *
1218 	 *      p_gl_business_class_cat_id - OPM gl_business_class_cat Id      *
1219 	 *                                   to retrieve the value             *
1220 	 *                                                                     *
1221 	 *    SYNOPSIS:                                                        *
1222 	 *      Get_gl_business_class_cat (p_gl_business_class_cat_id => 12121)*
1223 	 *                                                                     *
1224 	 *    HISTORY                                                          *
1225 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
1226 	 **********************************************************************/
1227 	 FUNCTION Get_Gl_business_class_cat
1228 	 (
1229 	 p_Gl_business_class_cat_id          IN             NUMBER
1230 	 )
1231 	 RETURN VARCHAR2
1232 	 IS
1233 
1234 			/************************
1235 			* Local Variables       *
1236 			************************/
1237 
1238 			l_Gl_business_class_cat                  MTL_CATEGORIES_VL.description%TYPE;
1239 
1240 			/****************
1241 			* Cursors       *
1242 			****************/
1243 
1244 			CURSOR      cur_Gl_business_class_cat
1245 			(
1246 			p_Gl_business_class_cat_id    IN       NUMBER
1247 			)
1248 			IS
1249 			SELECT               description
1250 			FROM                 mtl_categories_vl
1251 			WHERE                structure_id IN   (
1252 																						 SELECT       fifs.id_flex_num
1253 																						 FROM         fnd_id_flex_structures_vl fifs
1254 																						 WHERE        fifs.application_id = 401
1255 																						 AND          fifs.id_flex_code = 'MCAT'
1256 																						 AND          fifs.id_flex_structure_code = 'GL_BUSINESS_CLASS'
1257 																						 AND          enabled_flag = 'Y'
1258 																						 )
1259 			AND                  category_id = p_Gl_business_class_cat_id;
1260 
1261 	 BEGIN
1262 
1263 			OPEN cur_Gl_business_class_cat(p_Gl_business_class_cat_id);
1264 			FETCH cur_Gl_business_class_cat INTO l_Gl_business_class_cat;
1265 
1266 			IF cur_Gl_business_class_cat%NOTFOUND THEN
1267 				CLOSE cur_Gl_business_class_cat;
1268 				RAISE NO_DATA_FOUND;
1269 			END IF;
1270 
1271 			CLOSE cur_Gl_business_class_cat;
1272 
1273 			RETURN(l_Gl_business_class_cat);
1274 
1275 	 EXCEPTION
1276 			WHEN OTHERS THEN
1277 
1278 				 /********************************
1279 				 * Migration Started Log Message *
1280 				 ********************************/
1281 
1282 				 GMA_COMMON_LOGGING.gma_migration_central_log
1283 				 (
1284 				 p_run_id             =>       G_migration_run_id,
1285 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
1286 				 p_message_token      =>       'GMA_MIG_GL_BUS_CLASS_ERROR',
1287 				 p_table_name         =>       G_Table_name,
1288 				 p_context            =>       G_context,
1289 				 p_token1             =>       'GL_BUSINESS_CLASS_CAT_ID',
1290 				 p_param1             =>       p_Gl_business_class_cat_id,
1291 				 p_db_error           =>       NULL,
1292 				 p_app_short_name     =>       'GMA'
1293 				 );
1294 
1295 				RETURN NULL;
1296 
1297 	 END Get_Gl_business_class_cat;
1298 
1299 	 /**********************************************************************
1300 	 *    FUNCTION:                                                        *
1301 	 *      Get_gl_product_line_cat                                      *
1302 	 *                                                                     *
1303 	 *    DESCRIPTION:                                                     *
1304 	 *      This is an internal function used to retrieve gl_product_line*
1305 	 *                                                                     *
1306 	 *    PARAMETERS:                                                      *
1307 	 *      p_gl_product_line_cat_id - OPM gl_product_line_cat Id      *
1308 	 *                                   to retrieve the value             *
1309 	 *                                                                     *
1310 	 *    SYNOPSIS:                                                        *
1311 	 *      Get_gl_product_line_cat (p_gl_product_line_cat_id => 12121)*
1312 	 *                                                                     *
1313 	 *    HISTORY                                                          *
1314 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
1315 	 **********************************************************************/
1316 	 FUNCTION Get_Gl_product_line_cat
1317 	 (
1318 	 p_Gl_product_line_cat_id          IN             NUMBER
1319 	 )
1320 	 RETURN VARCHAR2
1321 	 IS
1322 
1323 			/************************
1324 			* Local Variables       *
1325 			************************/
1326 
1327 			l_Gl_product_line_cat                  MTL_CATEGORIES_VL.description%TYPE;
1328 
1329 			/****************
1330 			* Cursors       *
1331 			****************/
1332 
1333 			CURSOR      cur_Gl_product_line_cat
1334 			(
1335 			p_Gl_product_line_cat_id    IN       NUMBER
1336 			)
1337 			IS
1338 			SELECT               description
1339 			FROM                 mtl_categories_vl
1340 			WHERE                structure_id IN
1341 																						 (
1342 																						 SELECT       fifs.id_flex_num
1343 																						 FROM         fnd_id_flex_structures_vl fifs
1344 																						 WHERE        fifs.application_id = 401
1345 																						 AND          fifs.id_flex_code = 'MCAT'
1346 																						 AND          fifs.id_flex_structure_code = 'GL_PRODUCT_LINE'
1347 																						 AND          enabled_flag = 'Y'
1348 																						 )
1349 			AND                  category_id = p_Gl_product_line_cat_id;
1350 
1351 	 BEGIN
1352 
1353 			OPEN cur_Gl_product_line_cat(p_Gl_product_line_cat_id);
1354 			FETCH cur_Gl_product_line_cat INTO l_Gl_product_line_cat;
1355 
1356 			IF cur_Gl_product_line_cat%NOTFOUND THEN
1357 				CLOSE cur_Gl_product_line_cat;
1358 				RAISE NO_DATA_FOUND;
1359 			END IF;
1360 
1361 			CLOSE cur_Gl_product_line_cat;
1362 
1363 			RETURN(l_Gl_product_line_cat);
1364 
1365 	 EXCEPTION
1366 			WHEN OTHERS THEN
1367 
1368 				 /********************************
1369 				 * Migration Started Log Message *
1370 				 ********************************/
1371 
1372 				 GMA_COMMON_LOGGING.gma_migration_central_log
1373 				 (
1374 				 p_run_id             =>       G_migration_run_id,
1375 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
1376 				 p_message_token      =>       'GMA_MIG_GL_PROD_LINE_ERROR',
1377 				 p_table_name         =>       G_Table_name,
1378 				 p_context            =>       G_context,
1379 				 p_token1             =>       'GL_PRODUCT_LINE_CAT_ID',
1380 				 p_param1             =>       p_Gl_product_line_cat_id,
1381 				 p_db_error           =>       NULL,
1382 				 p_app_short_name     =>       'GMA'
1383 				 );
1384 
1385 				RETURN NULL;
1386 
1387 	 END Get_Gl_product_line_cat;
1388 
1389 	 /**********************************************************************
1390 	 *    FUNCTION:                                                        *
1391 	 *      Get_UOM_code                                                   *
1392 	 *                                                                     *
1393 	 *    DESCRIPTION:                                                     *
1394 	 *      This is an internal function used to retrieve the UOM Code     *
1395 	 *      for the OPM UM passed                                          *
1396 	 *                                                                     *
1397 	 *    PARAMETERS:                                                      *
1398 	 *      p_UM_code  - Unit Of Measure Code                              *
1399 	 *                                                                     *
1400 	 *    SYNOPSIS:                                                        *
1401 	 *      Get_UOM_code (p_UM_Code => 'Hours');                           *
1402 	 *                                                                     *
1403 	 *    HISTORY                                                          *
1404 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
1405 	 **********************************************************************/
1406 	 FUNCTION Get_Uom_Code
1407 	 (
1408 	 p_um_code               IN             VARCHAR2
1409 	 )
1410 	 RETURN VARCHAR2
1411 	 IS
1412 
1413 			/************************
1414 			* Local Variables       *
1415 			************************/
1416 
1417 			L_uom_code           sy_uoms_mst.uom_code%TYPE;
1418 
1419 			/****************
1420 			* Cursors       *
1421 			****************/
1422 
1423 			CURSOR      cur_uom_code
1424 			(
1425 			p_um_code            IN       VARCHAR2
1426 			)
1427 			IS
1428 			SELECT      uom_code
1429 			FROM        sy_uoms_mst
1430 			WHERE       um_code = p_um_code;
1431 
1432 	 BEGIN
1433 
1434 			OPEN cur_uom_code(p_um_code);
1435 			FETCH cur_uom_code INTO L_uom_code;
1436 
1437 			IF cur_uom_code%NOTFOUND THEN
1438 				CLOSE cur_uom_code;
1439 				RAISE NO_DATA_FOUND;
1440 			END IF;
1441 
1442 			CLOSE cur_uom_code;
1443 
1444 			RETURN(L_uom_code);
1445 
1446 	 EXCEPTION
1447 			WHEN OTHERS THEN
1448 
1449 				 /********************************
1450 				 * Migration Started Log Message *
1451 				 ********************************/
1452 
1453 				 GMA_COMMON_LOGGING.gma_migration_central_log
1454 				 (
1455 				 p_run_id             =>       G_migration_run_id,
1456 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
1457 				 p_message_token      =>       'GMA_MIG_UOM_ERROR',
1458 				 p_table_name         =>       G_Table_name,
1459 				 p_context            =>       G_context,
1460 				 p_token1             =>       'UM_CODE',
1461 				 p_param1             =>       p_um_code,
1462 				 p_db_error           =>       NULL,
1463 				 p_app_short_name     =>       'GMA'
1464 				 );
1465 
1466 				RETURN NULL;
1467 
1468 	 END Get_uom_Code;
1469 
1470 	 /**********************************************************************
1471 	 *    FUNCTION:                                                        *
1472 	 *      Get_Account_Id                                                 *
1473 	 *                                                                     *
1474 	 *    DESCRIPTION:                                                     *
1475 	 *      This is an internal function used to retrieve the Account Id   *
1476 	 *      value from the Financials setup for the Account Code and       *
1477 	 *      Company Code passed                                            *
1478 	 *                                                                     *
1479 	 *    PARAMETERS:                                                      *
1480 	 *      p_Account_code      - Account Code                             *
1481 	 *      p_co_code           - Company Code                             *
1482 	 *                                                                     *
1483 	 *    SYNOPSIS:                                                        *
1484 	 *      Get_Account_Id (p_Account_Code => '100-0000-0000-0000-0000',   *
1485 	 *                      p_co_code => 'PRU');                           *
1486 	 *                                                                     *
1487 	 *    HISTORY                                                          *
1488 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
1489 	 *       05-Jul-2006 rseshadr bug 5374823 - date has to be formatted   *
1490 	 *         appropriate in the call to fnd_flex_ext.                    *
1491 	 **********************************************************************/
1492 	 FUNCTION Get_Account_Id
1493 	 (
1494 	 p_account_code          IN             VARCHAR2,
1495 	 p_co_code               IN             VARCHAR2
1496 	 )
1497 	 RETURN VARCHAR2
1498 	 IS
1499 
1500 			/*****************************
1501 			* PL/SQL Table Definition    *
1502 			*****************************/
1503 
1504 			TYPE segment_values_tbl IS TABLE OF VARCHAR2(240) INDEX BY BINARY_INTEGER;
1505 
1506 			/******************
1507 			* Local Variables *
1508 			******************/
1509 
1510 			L_segment               segment_values_tbl;
1511 			L_segment_index         NUMBER(10) DEFAULT 0;
1512 			L_value                 NUMBER(10);
1513 			L_index                 NUMBER(10);
1514 			L_position              NUMBER(10) DEFAULT 1;
1515 			L_length                NUMBER(10);
1516 			L_result                VARCHAR2(2000);
1517 			L_segment_values        gmf_get_mappings.my_opm_seg_values;
1518 			L_segment_delimiter     VARCHAR2(10);
1519 			L_chart_of_accounts_id  NUMBER;
1520 			L_Account_Id            NUMBER;
1521 
1522 			/**********
1523 			* Cursors *
1524 			**********/
1525 
1526 			CURSOR      cur_plcy_seg
1527 			IS
1528 			SELECT      p.type,
1529 									p.length,
1530 									p.segment_no segment_ref,
1531 									pm.segment_delimiter
1532 			FROM        gl_plcy_seg p,
1533 									gl_plcy_mst pm,
1534 									fnd_id_flex_segments f,
1535 									gl_sets_of_books s
1536 			WHERE       p.co_code = p_co_code
1537 			AND         p.delete_mark = 0
1538 			AND         p.co_code = pm.co_code
1539 			AND         pm.sob_id = s.set_of_books_id
1540 			AND         s.chart_of_accounts_id = f.id_flex_num
1541 			AND         f.application_id = 101
1542 			AND         f.id_flex_code = 'GL#'
1543 			AND         LOWER(f.segment_name)  = LOWER(p.short_name)
1544 			AND         f.enabled_flag         = 'Y'
1545 			ORDER BY    f.segment_num;
1546 
1547 			CURSOR cur_segment_delimiter
1548 			IS
1549 			SELECT      concatenated_segment_delimiter,
1550 									glsob.chart_of_accounts_id
1551 			FROM        gl_sets_of_books glsob,
1552 									fnd_id_flex_structures fifstr,
1553 									fnd_application fa,
1554 									gl_plcy_mst gpm
1555 			WHERE       glsob.chart_of_accounts_id = fifstr.id_flex_num
1556 			AND         fifstr.id_flex_code = 'GL#'
1557 			AND         fifstr.application_id = fa.application_id
1558 			AND         fa.application_short_name = 'SQLGL'
1559 			AND         gpm.sob_id = glsob.set_of_books_id
1560 			AND         gpm.co_code = p_co_code;
1561 
1562 	 BEGIN
1563 
1564 			OPEN cur_segment_delimiter;
1565 			FETCH cur_segment_delimiter INTO L_segment_delimiter, L_Chart_of_accounts_id;
1566 
1567 			IF cur_segment_delimiter%NOTFOUND THEN
1568 				CLOSE cur_segment_delimiter;
1569 				RAISE NO_DATA_FOUND;
1570 			END IF;
1571 
1572 			CLOSE cur_segment_delimiter;
1573 
1574 			L_segment_values := gmf_get_mappings.get_opm_segment_values(p_account_code,p_co_code,2);
1575 
1576 			FOR i IN 1..30 LOOP
1577 				 L_segment(i) := NULL;
1578 			END LOOP;
1579 
1580 			FOR cur_plcy_seg_tmp IN cur_plcy_seg LOOP
1581 
1582 				 L_segment_index := L_segment_index + 1;
1583 
1584 				 IF (cur_plcy_seg_tmp.segment_ref = 0) THEN
1585 						L_value := L_segment_index;
1586 				 ELSE
1587 						L_value := cur_plcy_seg_tmp.segment_ref;
1588 				 END IF;
1589 
1590 				 L_index  := L_value;
1591 				 L_length := cur_plcy_seg_tmp.length;
1592 				 L_segment(L_index) := L_segment_values(L_position);
1593 				 L_position := L_position +  1;
1594 
1595 			END LOOP;
1596 
1597 			FOR i IN 1..30 LOOP
1598 				IF (i < 30) THEN
1599 					 L_result := L_result||L_segment(i)||L_segment_delimiter;
1600 				ELSE
1601 						L_result := L_result||L_segment(i);
1602 				END IF;
1603 			END LOOP;
1604 
1605 			/**
1606 			* rseshadr bug 5374823 - format date in call to fnd_flex_ext otherwise
1607 			* raises an error
1608 			**/
1609 			L_Account_id := fnd_flex_ext.get_ccid(
1610 				application_short_name => 'SQLGL',
1611 				key_flex_code => 'GL#',
1612 				structure_number => L_Chart_of_Accounts_id,
1613 				validation_date => TO_CHAR(SYSDATE, FND_FLEX_EXT.DATE_FORMAT),
1614 				concatenated_segments => L_Result);
1615 
1616 			IF L_Account_id IS NULL OR L_Account_id <= 0 THEN
1617 				 RAISE NO_DATA_FOUND;
1618 			END IF;
1619 
1620 			RETURN (L_Account_id);
1621 
1622 	 EXCEPTION
1623 			WHEN OTHERS THEN
1624 
1625 				 /********************************
1626 				 * Migration Started Log Message *
1627 				 ********************************/
1628 
1629 				 GMA_COMMON_LOGGING.gma_migration_central_log
1630 				 (
1631 				 p_run_id             =>       G_migration_run_id,
1632 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
1633 				 p_message_token      =>       'GMA_MIG_ACCOUNT_ERROR',
1634 				 p_table_name         =>       G_Table_name,
1635 				 p_context            =>       G_context,
1636 				 p_token1             =>       'ACCOUNT_CODE',
1637 				 p_token2             =>       'CO_CODE',
1638 				 p_param1             =>       p_account_code,
1639 				 p_param2             =>       p_co_code,
1640 				 p_db_error           =>       NULL,
1641 				 p_app_short_name     =>       'GMA'
1642 				 );
1643 
1644 				RETURN NULL;
1645 
1646 	 END get_account_id;
1647 
1648 	 /****************************************************************************
1649 	 *    FUNCTION:                                                              *
1650 	 *      Get_co_code                                                          *
1651 	 *                                                                           *
1652 	 *    DESCRIPTION:                                                           *
1653 	 *      This is an internal function used to retrieve the Company Code       *
1654 	 *      value for the Warehouse Code passed                                  *
1655 	 *                                                                           *
1656 	 *    PARAMETERS:                                                            *
1657 	 *      p_whse_code    - Warehouse Code to retrieve the value.               *
1658 	 *                                                                           *
1659 	 *    SYNOPSIS:                                                              *
1660 	 *      Get_Co_Code (p_whse_code => 'PR1');                                  *
1661 	 *                                                                           *
1662 	 *    HISTORY                                                                *
1663 	 *       27-Apr-2005 Created  Anand Thiyagarajan                             *
1664 	 *                                                                           *
1665 	 ****************************************************************************/
1666 	 FUNCTION Get_Co_Code
1667 	 (
1668 	 p_whse_code             IN             VARCHAR2
1669 	 )
1670 	 RETURN VARCHAR2
1671 	 IS
1672 
1673 			/************************
1674 			* Local Variables       *
1675 			************************/
1676 
1677 			L_co_code  sy_orgn_mst.co_code%TYPE;
1678 
1679 			/****************
1680 			* Cursors       *
1681 			****************/
1682 
1683 			CURSOR      cur_co_code
1684 			(
1685 			p_whse_code   IN    VARCHAR2
1686 			)
1687 			IS
1688 			select      a.co_code
1689 			from        sy_orgn_mst a,
1690 									ic_whse_mst b
1691 			where       a.orgn_code = b.orgn_code
1692 			and         b.whse_code = p_whse_code;
1693 
1694 	 BEGIN
1695 
1696 			OPEN Cur_co_code(p_whse_code);
1697 			FETCH Cur_co_code INTO L_co_code;
1698 
1699 			IF Cur_co_code%NOTFOUND THEN
1700 				CLOSE Cur_co_code;
1701 				RAISE NO_DATA_FOUND;
1702 			END IF;
1703 
1704 			CLOSE Cur_co_code;
1705 
1706 			RETURN(L_co_code);
1707 
1708 	 EXCEPTION
1709 			WHEN OTHERS THEN
1710 
1711 				 /********************************
1712 				 * Migration Started Log Message *
1713 				 ********************************/
1714 
1715 				 GMA_COMMON_LOGGING.gma_migration_central_log
1716 				 (
1717 				 p_run_id             =>       G_migration_run_id,
1718 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
1719 				 p_message_token      =>       'GMA_MIG_CO_WHSE_ERROR',
1720 				 p_table_name         =>       G_Table_name,
1721 				 p_context            =>       G_context,
1722 				 p_token1             =>       'WHSE_CODE',
1723 				 p_param1             =>       p_whse_code,
1724 				 p_db_error           =>       NULL,
1725 				 p_app_short_name     =>       'GMA'
1726 				 );
1727 
1728 				RETURN NULL;
1729 
1730 	 END get_co_code;
1731 
1732 	 /**********************************************************************
1733 	 * PROCEDURE:                                                          *
1734 	 *   Migrate_Fiscal_policies_LE                                        *
1735 	 *                                                                     *
1736 	 * DESCRIPTION:                                                        *
1737 	 *   This PL/SQL procedure is used to migrate the Fiscal Policies from *
1738 	 *   GL_PLCY_MST to GMF_FISCAL_POLICIES table.                         *
1739 	 *                                                                     *
1740 	 * PARAMETERS:                                                         *
1741 	 *   P_migration_run_id - id to use to right to migration log          *
1742 	 *   x_exception_count  - Number of exceptions occurred.               *
1743 	 *                                                                     *
1744 	 * SYNOPSIS:                                                           *
1745 	 *   Migrate_Fiscal_policies_LE(p_migartion_id    => l_migration_id,   *
1746 	 *                    p_commit          => 'T',                        *
1747 	 *                    x_exception_count => l_exception_count );        *
1748 	 *                                                                     *
1749 	 * HISTORY                                                             *
1750 	 *    27-Apr-2005 Created  Anand Thiyagarajan                          *
1751 	 *    24-May-2006 rseshadr bug 5246510 - Use the new cost mthd if      *
1752 	 *       set by the user otherwise default from the old cost mthd      *
1753 	 *       Also, ordered the main cursor by le_id because if a null      *
1754 	 *       LE row comes first but the Company points to already mapped   *
1755 	 *       LE, then we may end up with an incorrect gl cost mthd for     *
1756 	 *       the already mapped LEs.  Removed the L_new_legal_entity_id    *
1757 	 *       variable reference in update                                  *
1758 	 *    23-Jun-2006 rseshadr bug 5354837 - do not rely on the view       *
1759 	 *      gmf_legal_entities.  The underlying tables are not populated   *
1760 	 *      until after a much later phase (upg+74).  Use the same logic   *
1761 	 *      as an auto upgrade without the pre-mig ui                      *
1762 	 *                                                                     *
1763 	 **********************************************************************/
1764 	 PROCEDURE Migrate_Fiscal_Policies_LE
1765 	 (
1766 	 P_migration_run_id      IN             NUMBER,
1767 	 P_commit                IN             VARCHAR2,
1768 	 X_failure_count         OUT   NOCOPY   NUMBER
1769 	 )
1770 	 IS
1771 
1772 			/***************************
1773 			* PL/SQL Table Definitions *
1774 			***************************/
1775 
1776 			/************************
1777 			* Local Variables       *
1778 			************************/
1779 
1780 			L_legal_entity_id             NUMBER(15);
1781 			L_ledger_id                   NUMBER(15);
1782 			/* L_new_legal_entity_id         NUMBER(15); */
1783 			l_le_count                    NUMBER;
1784 
1785 			/****************
1786 			* Cursors       *
1787 			****************/
1788 
1789 			CURSOR      cur_get_fiscal_policies IS
1790 			SELECT      *
1791 			FROM        gl_plcy_mst
1792 			WHERE       NVL(migrated_ind,'~') <> '1'
1793 			ORDER BY legal_entity_id NULLS LAST;
1794 
1795 	 BEGIN
1796 
1797 			G_Migration_run_id := P_migration_run_id;
1798 			G_Table_name := 'GMF_FISCAL_POLICIES';
1799 			G_Context := 'Fiscal Policies LE Migration';
1800 			X_failure_count := 0;
1801 
1802 			/********************************
1803 			* Migration Started Log Message *
1804 			********************************/
1805 
1806 			GMA_COMMON_LOGGING.gma_migration_central_log
1807 			(
1808 			p_run_id             =>       G_migration_run_id,
1809 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
1810 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
1811 			p_table_name         =>       G_Table_name,
1812 			p_context            =>       G_Context,
1813 			p_db_error           =>       NULL,
1814 			p_app_short_name     =>       'GMA'
1815 			);
1816 
1817 
1818 			/****************************************
1819 			* Insert a row into gmf_fiscal_policies *
1820 			****************************************/
1821 
1822 			FOR i IN Cur_get_fiscal_policies
1823 			LOOP
1824 				 IF i.legal_entity_id IS NULL THEN
1825 					 BEGIN
1826 							SELECT   to_number(org_information2),
1827 											 to_number(org_information3)
1828 							INTO     l_legal_entity_id,
1829 											 l_ledger_id
1830 							FROM     hr_organization_information
1831 							WHERE    org_information_context = 'Operating Unit Information'
1832 							AND      organization_id = i.org_id;
1833 					 EXCEPTION
1834 							WHEN OTHERS THEN
1835 								 L_legal_entity_id := NULL;
1836 								 L_ledger_id := NULL;
1837 					 END;
1838 				 ELSE
1839 					 L_legal_entity_id := i.legal_entity_id;
1840 					 BEGIN
1841 						 SELECT   to_number(org_information3)
1842 						 INTO     l_ledger_id
1843 						 FROM     hr_organization_information
1844 						 WHERE    org_information_context = 'Operating Unit Information'
1845 						 AND      organization_id = i.org_id;
1846 					 EXCEPTION
1847 						 WHEN OTHERS THEN
1848 							 L_ledger_id := NULL;
1849 					 END;
1850 				 END IF;
1851 
1852 				 BEGIN
1853 						SELECT         count(1)
1854 						INTO           l_le_count
1855 						FROM           gmf_fiscal_policies
1856 						WHERE          legal_entity_id = L_legal_entity_id;
1857 				 EXCEPTION
1858 						WHEN no_data_found THEN
1859 							 l_le_count := 0;
1860 						WHEN too_many_rows THEN
1861 							 l_le_count := 99;
1862 						WHEN OTHERS THEN
1863 							 l_le_count := 0;
1864 				 END;
1865 
1866 				 IF L_legal_entity_id IS NOT NULL AND nvl(l_le_count,0) = 0 THEN
1867 
1868 						BEGIN
1869 							 INSERT INTO gmf_fiscal_policies
1870 							 (
1871 							 LEGAL_ENTITY_ID,
1872 							 BASE_CURRENCY_CODE,
1873 							 LEDGER_ID,
1874 							 MTL_CMPNTCLS_ID,
1875 							 MTL_ANALYSIS_CODE,
1876 							 GL_COST_MTHD,
1877 							 COST_BASIS,
1878 							 TEXT_CODE,
1879 							 DELETE_MARK,
1880 							 CREATED_BY,
1881 							 CREATION_DATE,
1882 							 LAST_UPDATE_LOGIN,
1883 							 LAST_UPDATE_DATE,
1884 							 LAST_UPDATED_BY,
1885 							 ATTRIBUTE1,
1886 							 ATTRIBUTE2,
1887 							 ATTRIBUTE3,
1888 							 ATTRIBUTE4,
1889 							 ATTRIBUTE5,
1890 							 ATTRIBUTE6,
1891 							 ATTRIBUTE7,
1892 							 ATTRIBUTE8,
1893 							 ATTRIBUTE9,
1894 							 ATTRIBUTE10,
1895 							 ATTRIBUTE11,
1896 							 ATTRIBUTE12,
1897 							 ATTRIBUTE13,
1898 							 ATTRIBUTE14,
1899 							 ATTRIBUTE15,
1900 							 ATTRIBUTE16,
1901 							 ATTRIBUTE17,
1902 							 ATTRIBUTE18,
1903 							 ATTRIBUTE19,
1904 							 ATTRIBUTE20,
1905 							 ATTRIBUTE21,
1906 							 ATTRIBUTE22,
1907 							 ATTRIBUTE23,
1908 							 ATTRIBUTE24,
1909 							 ATTRIBUTE25,
1910 							 ATTRIBUTE26,
1911 							 ATTRIBUTE27,
1912 							 ATTRIBUTE28,
1913 							 ATTRIBUTE29,
1914 							 ATTRIBUTE30,
1915 							 ATTRIBUTE_CATEGORY
1916 							 )
1917 							 VALUES
1918 							 (
1919 							 L_legal_entity_id,
1920 							 i.base_currency_code,
1921 							 L_ledger_id,
1922 							 i.mtl_cmpntcls_id,
1923 							 i.mtl_analysis_code,
1924 							 NVL(i.new_le_cost_mthd_code,i.gl_cost_mthd),
1925 							 i.cost_basis,
1926 							 i.text_code,
1927 							 i.delete_mark,
1928 							 i.created_by,
1929 							 i.creation_date,
1930 							 i.last_update_login,
1931 							 i.last_update_date,
1932 							 i.last_updated_by,
1933 							 i.attribute1,
1934 							 i.attribute2,
1935 							 i.attribute3,
1936 							 i.attribute4,
1937 							 i.attribute5,
1938 							 i.attribute6,
1939 							 i.attribute7,
1940 							 i.attribute8,
1941 							 i.attribute9,
1942 							 i.attribute10,
1943 							 i.attribute11,
1944 							 i.attribute12,
1945 							 i.attribute13,
1946 							 i.attribute14,
1947 							 i.attribute15,
1948 							 i.attribute16,
1949 							 i.attribute17,
1950 							 i.attribute18,
1951 							 i.attribute19,
1952 							 i.attribute20,
1953 							 i.attribute21,
1954 							 i.attribute22,
1955 							 i.attribute23,
1956 							 i.attribute24,
1957 							 i.attribute25,
1958 							 i.attribute26,
1959 							 i.attribute27,
1960 							 i.attribute28,
1961 							 i.attribute29,
1962 							 i.attribute30,
1963 							 i.attribute_category
1964 							 );
1965 
1966 							 UPDATE   gl_plcy_mst
1967 							 SET      migrated_ind = '1',
1968 												legal_entity_id = decode(legal_entity_id, NULL, L_legal_entity_id, legal_entity_id),
1969 												last_update_date = SYSDATE
1970 							 WHERE    co_code = i.co_code;
1971 
1972 						EXCEPTION
1973 							 WHEN OTHERS THEN
1974 
1975 									/************************************************
1976 									* Increment Failure Count for Failed Migrations *
1977 									************************************************/
1978 									x_failure_count := x_failure_count + 1;
1979 
1980 									GMA_COMMON_LOGGING.gma_migration_central_log
1981 									(
1982 									p_run_id             =>       G_migration_run_id,
1983 									p_log_level          =>       FND_LOG.LEVEL_ERROR,
1984 									p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
1985 									p_table_name         =>       G_Table_name,
1986 									p_context            =>       G_Context,
1987 									p_db_error           =>       SQLERRM,
1988 									p_app_short_name     =>       'GMA'
1989 									);
1990 
1991 									GMA_COMMON_LOGGING.gma_migration_central_log
1992 									(
1993 									p_run_id             =>       G_migration_run_id,
1994 									p_log_level          =>       FND_LOG.LEVEL_ERROR,
1995 									p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
1996 									p_table_name         =>       G_Table_name,
1997 									p_context            =>       G_Context,
1998 									p_db_error           =>       NULL,
1999 									p_app_short_name     =>       'GMA'
2000 									);
2001 						END;
2002 
2003 					ELSIF L_legal_entity_id IS NOT NULL AND nvl(l_le_count,0) > 0 THEN
2004 
2005 						 UPDATE   gl_plcy_mst
2006 						 SET      migrated_ind = '1',
2007 											legal_entity_id = decode(legal_entity_id, NULL, L_legal_entity_id, legal_entity_id),
2008 											last_update_date = SYSDATE
2009 						 WHERE    co_code = i.co_code;
2010 
2011 					ELSE
2012 
2013 						 x_failure_count := x_failure_count + 1;
2014 						 L_legal_entity_id := NULL;
2015 
2016 						 GMA_COMMON_LOGGING.gma_migration_central_log
2017 						 (
2018 						 p_run_id             =>       G_migration_run_id,
2019 						 p_log_level          =>       FND_LOG.LEVEL_ERROR,
2020 						 p_message_token      =>       'GMA_MIG_FISCAL_DUP_LE_ERROR',
2021 						 p_table_name         =>       G_Table_name,
2022 						 p_context            =>       G_Context,
2023 						 p_token1             =>       'CO_CODE',
2024 						 p_param1             =>       i.co_code,
2025 						 p_db_error           =>       NULL,
2026 						 p_app_short_name     =>       'GMA'
2027 						 );
2028 
2029 				 END IF;
2030 
2031 			END LOOP;
2032 
2033 			/**********************************************
2034 			* Handle all the rows which were not migrated *
2035 			**********************************************/
2036 
2037 			SELECT            count(*)
2038 			INTO              x_failure_count
2039 			FROM              gl_plcy_mst
2040 			WHERE             (legal_entity_id IS NULL AND co_code IS NOT NULL);
2041 
2042 			IF nvl(x_failure_count,0) > 0 THEN
2043 
2044 				/**************************************
2045 				* Migration Failure Log Message       *
2046 				**************************************/
2047 
2048 				GMA_COMMON_LOGGING.gma_migration_central_log
2049 				(
2050 				p_run_id             =>       gmf_migration.G_migration_run_id,
2051 				p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
2052 				p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
2053 				p_table_name         =>       gmf_migration.G_Table_name,
2054 				p_context            =>       gmf_migration.G_context,
2055 				p_db_error           =>       NULL,
2056 				p_app_short_name     =>       'GMA'
2057 				);
2058 
2059 			ELSE
2060 
2061 				/**************************************
2062 				* Migration Success Log Message       *
2063 				**************************************/
2064 
2065 				GMA_COMMON_LOGGING.gma_migration_central_log
2066 				(
2067 				p_run_id             =>       G_migration_run_id,
2068 				p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
2069 				p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
2070 				p_table_name         =>       G_Table_name,
2071 				p_context            =>       G_Context,
2072 				p_param1             =>       1,
2073 				p_param2             =>       0,
2074 				p_db_error           =>       NULL,
2075 				p_app_short_name     =>       'GMA'
2076 				);
2077 
2078 			END IF;
2079 
2080 			/****************************************************************
2081 			* Lets save the changes now based on the commit parameter       *
2082 			****************************************************************/
2083 
2084 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
2085 				 COMMIT;
2086 			END IF;
2087 
2088 	 EXCEPTION
2089 			WHEN OTHERS THEN
2090 
2091 				 /************************************************
2092 				 * Increment Failure Count for Failed Migrations *
2093 				 ************************************************/
2094 				 x_failure_count := x_failure_count + 1;
2095 
2096 				 /**************************************
2097 				 * Migration DB Error Log Message      *
2098 				 **************************************/
2099 
2100 				 GMA_COMMON_LOGGING.gma_migration_central_log
2101 				 (
2102 				 p_run_id             =>       G_migration_run_id,
2103 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
2104 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
2105 				 p_table_name         =>       G_Table_name,
2106 				 p_context            =>       G_Context,
2107 				 p_db_error           =>       SQLERRM,
2108 				 p_app_short_name     =>       'GMA'
2109 				 );
2110 
2111 				 /**************************************
2112 				 * Migration Failure Log Message       *
2113 				 **************************************/
2114 
2115 				 GMA_COMMON_LOGGING.gma_migration_central_log
2116 				 (
2117 				 p_run_id             =>       G_migration_run_id,
2118 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
2119 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
2120 				 p_table_name         =>       G_Table_name,
2121 				 p_context            =>       G_Context,
2122 				 p_db_error           =>       NULL,
2123 				 p_app_short_name     =>       'GMA'
2124 				 );
2125 
2126 	 END Migrate_Fiscal_policies_LE;
2127 
2128 	 /**********************************************************************
2129 	 * PROCEDURE:                                                          *
2130 	 *   Migrate_Fiscal_Policies_Others                                    *
2131 	 *                                                                     *
2132 	 * DESCRIPTION:                                                        *
2133 	 *   This PL/SQL procedure is used to migrate the Cost Method          *
2134 	 *   and Periods                                                       *
2135 	 *                                                                     *
2136 	 * PARAMETERS:                                                         *
2137 	 *   P_migration_run_id - id to use to right to migration log          *
2138 	 *   x_exception_count  - Number of exceptions occurred.               *
2139 	 *                                                                     *
2140 	 * SYNOPSIS:                                                           *
2141 	 *   Migrate_Fiscal_Policies_Others(p_migartion_id => l_migration_id,  *
2142 	 *                    p_commit          => 'T',                        *
2143 	 *                    x_exception_count => l_exception_count );        *
2144 	 *                                                                     *
2145 	 * HISTORY                                                             *
2146 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
2147 	 *       22-aug-2006 bug 5473365, pmarada, inserting records in        *
2148 	 *                   gmf_ledger_valuation_methods table                *
2149 	 *                                                                     *
2150 	 **********************************************************************/
2151 	 PROCEDURE Migrate_Fiscal_Policies_Others
2152 	 (
2153 	 P_migration_run_id      IN             NUMBER,
2154 	 P_commit                IN             VARCHAR2,
2155 	 X_failure_count         OUT   NOCOPY   NUMBER
2156 	 )
2157 	 IS
2158 
2159 			/**************************
2160 			* PL/SQL Table Definition *
2161 			**************************/
2162 
2163 			/******************
2164 			* Local Variables *
2165 			******************/
2166 
2167 	 BEGIN
2168 
2169 			G_Migration_run_id := P_migration_run_id;
2170 			G_Table_name := 'GMF_FISCAL_POLICIES';
2171 			G_Context := 'Fiscal Policies Migration - Others';
2172 			X_failure_count := 0;
2173 
2174 			/********************************
2175 			* Migration Started Log Message *
2176 			********************************/
2177 
2178 			GMA_COMMON_LOGGING.gma_migration_central_log
2179 			(
2180 			p_run_id             =>       G_migration_run_id,
2181 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
2182 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
2183 			p_table_name         =>       G_Table_name,
2184 			p_context            =>       G_Context,
2185 			p_db_error           =>       NULL,
2186 			p_app_short_name     =>       'GMA'
2187 			);
2188 
2189 			/********************************************************
2190 			* Update a row in GMF_FISCAL_POLICIES for GL cost Types *
2191 			********************************************************/
2192 
2193 			BEGIN
2194 				 UPDATE      gmf_fiscal_policies a
2195 				 SET         a.cost_type_id =  (
2196 																			 SELECT      x.cost_type_id
2197 																			 FROM        cm_mthd_mst x
2198 																			 WHERE       x.cost_mthd_code = a.gl_cost_mthd
2199 																			 )
2200 				 WHERE       a.cost_type_id IS NULL AND a.gl_cost_mthd IS NOT NULL;
2201 
2202 				/*************************************************************************
2203 				* Insert rows in GMF_ledger_valuation_methods table for the legal entity *
2204 				**************************************************************************/
2205 
2206 				INSERT INTO gmf_ledger_valuation_methods
2207 				(
2208 				legal_entity_id,
2209 				ledger_id,
2210 				cost_type_id,
2211 				creation_date,
2212 				created_by,
2213 				last_update_date,
2214 				last_updated_by,
2215 				last_update_login,
2216 				text_code,
2217 				delete_mark
2218 				)
2219 				SELECT        gfp.legal_entity_id,
2220 											gfp.ledger_id,
2221 											gfp.cost_type_id,
2222 											gfp.creation_date,
2223 											gfp.created_by,
2224 											gfp.last_update_date,
2225 											gfp.last_updated_by,
2226 											gfp.last_update_login,
2227 											gfp.text_code,
2228 											0
2229 				FROM          gmf_fiscal_policies gfp
2230 				WHERE         NOT EXISTS  (
2231 																	SELECT          '1'
2232 																	FROM            gmf_ledger_valuation_methods glvm
2233 																	WHERE           glvm.legal_entity_id = gfp.legal_entity_id
2234 																	AND             glvm.ledger_id = gfp.ledger_id
2235 																	);
2236 
2237 			EXCEPTION
2238 				 WHEN OTHERS THEN
2239 
2240 						/************************************************
2241 						* Increment Failure Count for Failed Migrations *
2242 						************************************************/
2243 
2244 						x_failure_count := x_failure_count + 1;
2245 
2246 						/**************************************
2247 						* Migration DB Error Log Message      *
2248 						**************************************/
2249 
2250 						GMA_COMMON_LOGGING.gma_migration_central_log
2251 						(
2252 						p_run_id             =>       G_migration_run_id,
2253 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
2254 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
2255 						p_table_name         =>       G_Table_name,
2256 						p_context            =>       G_Context,
2257 						p_db_error           =>       SQLERRM,
2258 						p_app_short_name     =>       'GMA'
2259 						);
2260 
2261 						/**************************************
2262 						* Migration Failure Log Message       *
2263 						**************************************/
2264 
2265 						GMA_COMMON_LOGGING.gma_migration_central_log
2266 						(
2267 						p_run_id             =>       G_migration_run_id,
2268 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
2269 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
2270 						p_table_name         =>       G_Table_name,
2271 						p_context            =>       G_Context,
2272 						p_db_error           =>       NULL,
2273 						p_app_short_name     =>       'GMA'
2274 						);
2275 
2276 			END;
2277 
2278 			/**********************************************
2279 			* Handle all the rows which were not migrated *
2280 			**********************************************/
2281 
2282 			SELECT            count(*)
2283 			INTO              x_failure_count
2284 			FROM              gmf_fiscal_policies
2285 			WHERE             (cost_type_id IS NULL AND gl_cost_mthd IS NOT NULL);
2286 
2287 			IF nvl(x_failure_count,0) > 0 THEN
2288 
2289 				/**************************************
2290 				* Migration Failure Log Message       *
2291 				**************************************/
2292 
2293 				GMA_COMMON_LOGGING.gma_migration_central_log
2294 				(
2295 				p_run_id             =>       gmf_migration.G_migration_run_id,
2296 				p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
2297 				p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
2298 				p_table_name         =>       gmf_migration.G_Table_name,
2299 				p_context            =>       gmf_migration.G_context,
2300 				p_db_error           =>       NULL,
2301 				p_app_short_name     =>       'GMA'
2302 				);
2303 
2304 			ELSE
2305 
2306 				/**************************************
2307 				* Migration Success Log Message       *
2308 				**************************************/
2309 
2310 				GMA_COMMON_LOGGING.gma_migration_central_log
2311 				(
2312 				p_run_id             =>       G_migration_run_id,
2313 				p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
2314 				p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
2315 				p_table_name         =>       G_Table_name,
2316 				p_context            =>       G_Context,
2317 				p_param1             =>       1,
2318 				p_param2             =>       0,
2319 				p_db_error           =>       NULL,
2320 				p_app_short_name     =>       'GMA'
2321 				);
2322 
2323 			END IF;
2324 
2325 			/****************************************************************
2326 			* Lets save the changes now based on the commit parameter       *
2327 			****************************************************************/
2328 
2329 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
2330 				 COMMIT;
2331 			END IF;
2332 
2333 	 EXCEPTION
2334 			WHEN OTHERS THEN
2335 
2336 				 /************************************************
2337 				 * Increment Failure Count for Failed Migrations *
2338 				 ************************************************/
2339 
2340 				 x_failure_count := x_failure_count + 1;
2341 
2342 				 /**************************************
2343 				 * Migration DB Error Log Message      *
2344 				 **************************************/
2345 
2346 				 GMA_COMMON_LOGGING.gma_migration_central_log
2347 				 (
2348 				 p_run_id             =>       G_migration_run_id,
2349 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
2350 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
2351 				 p_table_name         =>       G_Table_name,
2352 				 p_context            =>       G_Context,
2353 				 p_db_error           =>       SQLERRM,
2354 				 p_app_short_name     =>       'GMA'
2355 				 );
2356 
2357 				 /**************************************
2358 				 * Migration Failure Log Message       *
2359 				 **************************************/
2360 
2361 				 GMA_COMMON_LOGGING.gma_migration_central_log
2362 				 (
2363 				 p_run_id             =>       G_migration_run_id,
2364 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
2365 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
2366 				 p_table_name         =>       G_Table_name,
2367 				 p_context            =>       G_Context,
2368 				 p_db_error           =>       NULL,
2369 				 p_app_short_name     =>       'GMA'
2370 				 );
2371 
2372 	 END Migrate_Fiscal_Policies_Others;
2373 
2374 	 /**********************************************************************
2375 	 * PROCEDURE:                                                          *
2376 	 *   Migrate_Cost_Methods                                              *
2377 	 *                                                                     *
2378 	 * DESCRIPTION:                                                        *
2379 	 *   This PL/SQL procedure is used to transform the Cost Methods       *
2380 	 *   data in CM_MTHD_MST                                               *
2381 	 *                                                                     *
2382 	 * PARAMETERS:                                                         *
2383 	 *   P_migration_run_id - id to use to right to migration log          *
2384 	 *   x_exception_count  - Number of exceptions occurred.               *
2385 	 *                                                                     *
2386 	 * SYNOPSIS:                                                           *
2387 	 *   Migrate_cost_methods(p_migartion_id    => l_migration_id,         *
2388 	 *                    p_commit          => 'T',                        *
2389 	 *                    x_exception_count => l_exception_count );        *
2390 	 *                                                                     *
2391 	 * HISTORY                                                             *
2392 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
2393 	 *                                                                     *
2394 	 **********************************************************************/
2395 	 PROCEDURE Migrate_Cost_Methods
2396 	 (
2397 	 P_migration_run_id      IN             NUMBER,
2398 	 P_commit                IN             VARCHAR2,
2399 	 X_failure_count         OUT   NOCOPY   NUMBER
2400 	 )
2401 	 IS
2402 
2403 			/****************
2404 			* PL/SQL Tables *
2405 			****************/
2406 
2407 			/******************
2408 			* Local Variables *
2409 			******************/
2410 
2411 	 BEGIN
2412 
2413 			G_Migration_run_id := P_migration_run_id;
2414 			G_Table_name := 'CM_MTHD_MST';
2415 			G_Context := 'Cost Types Migration';
2416 			X_failure_count := 0;
2417 
2418 			/********************************
2419 			* Migration Started Log Message *
2420 			********************************/
2421 
2422 			GMA_COMMON_LOGGING.gma_migration_central_log
2423 			(
2424 			p_run_id             =>       G_migration_run_id,
2425 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
2426 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
2427 			p_table_name         =>       G_table_name,
2428 			p_context            =>       G_context,
2429 			p_db_error           =>       NULL,
2430 			p_app_short_name     =>       'GMA'
2431 			);
2432 
2433 			/*****************************************
2434 			* Update rows For Cost Type Identifier   *
2435 			*****************************************/
2436 
2437 			UPDATE      cm_mthd_mst
2438 			SET         cost_type_id = gmf_cost_type_id_s.NEXTVAL
2439 			WHERE       (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL);
2440 
2441 			/**********************************************
2442 			* Handle all the rows which were not migrated *
2443 			**********************************************/
2444 
2445 			SELECT               count(*)
2446 			INTO                 x_failure_count
2447 			FROM                 cm_mthd_mst
2448 			WHERE                (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL);
2449 
2450 			IF nvl(x_failure_count,0) > 0 THEN
2451 
2452 				/**************************************
2453 				* Migration Failure Log Message       *
2454 				**************************************/
2455 
2456 				GMA_COMMON_LOGGING.gma_migration_central_log
2457 				(
2458 				p_run_id             =>       gmf_migration.G_migration_run_id,
2459 				p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
2460 				p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
2461 				p_table_name         =>       gmf_migration.G_Table_name,
2462 				p_context            =>       gmf_migration.G_context,
2463 				p_db_error           =>       NULL,
2464 				p_app_short_name     =>       'GMA'
2465 				);
2466 
2467 			ELSE
2468 
2469 				/**************************************
2470 				* Migration Success Log Message       *
2471 				**************************************/
2472 
2473 				GMA_COMMON_LOGGING.gma_migration_central_log
2474 				(
2475 				p_run_id             =>       G_migration_run_id,
2476 				p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
2477 				p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
2478 				p_table_name         =>       G_Table_name,
2479 				p_context            =>       G_Context,
2480 				p_param1             =>       1,
2481 				p_param2             =>       0,
2482 				p_db_error           =>       NULL,
2483 				p_app_short_name     =>       'GMA'
2484 				);
2485 
2486 			END IF;
2487 
2488 			/****************************************************************
2489 			*Lets save the changes now based on the commit parameter        *
2490 			****************************************************************/
2491 
2492 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
2493 				 COMMIT;
2494 			END IF;
2495 
2496 	 EXCEPTION
2497 			WHEN OTHERS THEN
2498 
2499 				 /************************************************
2500 				 * Increment Failure Count for Failed Migrations *
2501 				 ************************************************/
2502 				 x_failure_count := x_failure_count + 1;
2503 
2504 				 /**************************************
2505 				 * Migration DB Error Log Message      *
2506 				 **************************************/
2507 
2508 				 GMA_COMMON_LOGGING.gma_migration_central_log
2509 				 (
2510 				 p_run_id             =>       G_migration_run_id,
2511 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
2512 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
2513 				 p_table_name         =>       G_table_name,
2514 				 p_context            =>       G_context,
2515 				 p_db_error           =>       SQLERRM,
2516 				 p_app_short_name     =>       'GMA'
2517 				 );
2518 
2519 				 /**************************************
2520 				 * Migration Failure Log Message       *
2521 				 **************************************/
2522 
2523 				 GMA_COMMON_LOGGING.gma_migration_central_log
2524 				 (
2525 				 p_run_id             =>       G_migration_run_id,
2526 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
2527 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
2528 				 p_table_name         =>       G_table_name,
2529 				 p_context            =>       G_context,
2530 				 p_db_error           =>       NULL,
2531 				 p_app_short_name     =>       'GMA'
2532 				 );
2533 
2534 	 END Migrate_Cost_Methods;
2535 
2536 	 /**********************************************************************
2537 	 * PROCEDURE:                                                          *
2538 	 *   Migrate_Lot_Cost_Methods                                          *
2539 	 *                                                                     *
2540 	 * DESCRIPTION:                                                        *
2541 	 *   This PL/SQL procedure is used to transform the Lot Cost Methods   *
2542 	 *   data in CM_MTHD_MST                                               *
2543 	 *                                                                     *
2544 	 * PARAMETERS:                                                         *
2545 	 *   P_migration_run_id - id to use to right to migration log          *
2546 	 *   x_exception_count  - Number of exceptions occurred.               *
2547 	 *                                                                     *
2548 	 * SYNOPSIS:                                                           *
2549 	 *   Migrate_lot_cost_methods(p_migartion_id    => l_migration_id,     *
2550 	 *                    p_commit          => 'T',                        *
2551 	 *                    x_exception_count => l_exception_count );        *
2552 	 *                                                                     *
2553 	 * HISTORY                                                             *
2554 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
2555 	 *                                                                     *
2556 	 **********************************************************************/
2557 	 PROCEDURE Migrate_Lot_Cost_Methods
2558 	 (
2559 	 P_migration_run_id      IN             NUMBER,
2560 	 P_commit                IN             VARCHAR2,
2561 	 X_failure_count         OUT   NOCOPY   NUMBER
2562 	 )
2563 	 IS
2564 
2565 			/**************************
2566 			* PL/SQL Table Definition *
2567 			**************************/
2568 
2569 			/******************
2570 			* Local Variables *
2571 			******************/
2572 
2573 			/**********
2574 			* Cursors *
2575 			**********/
2576 
2577 	 BEGIN
2578 
2579 			G_Migration_run_id := P_migration_run_id;
2580 			G_Table_name := 'CM_MTHD_MST';
2581 			G_Context := 'Lot Cost Types Migration';
2582 			X_failure_count := 0;
2583 
2584 			/********************************
2585 			* Migration Started Log Message *
2586 			********************************/
2587 
2588 			GMA_COMMON_LOGGING.gma_migration_central_log
2589 			(
2590 			p_run_id             =>       G_migration_run_id,
2591 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
2592 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
2593 			p_table_name         =>       G_table_name,
2594 			p_context            =>       G_context,
2595 			p_db_error           =>       NULL,
2596 			p_app_short_name     =>       'GMA'
2597 			);
2598 
2599 			/*********************************************
2600 			* Update a row in cm_mthd_mst for Lot Costs *
2601 			*********************************************/
2602 			BEGIN
2603 
2604 				 UPDATE      cm_mthd_mst a
2605 				 SET         a.default_lot_cost_type_id =  (
2606 																									 SELECT         x.cost_type_id
2607 																									 FROM           cm_mthd_mst x
2608 																									 WHERE          x.cost_mthd_code = a.default_lot_cost_mthd
2609 																									 ),
2610 										 a.cost_type = 6,
2611 										 a.lot_actual_cost = NULL
2612 				 WHERE       cost_type_id IS NOT NULL
2613 				 AND         a.cost_type = 1
2614 				 AND         nvl(a.lot_actual_cost,-1) = 1;
2615 
2616 			EXCEPTION
2617 				 WHEN OTHERS THEN
2618 
2619 						/************************************************
2620 						* Increment Failure Count for Failed Migrations *
2621 						************************************************/
2622 
2623 						x_failure_count := x_failure_count + 1;
2624 
2625 						/**************************************
2626 						* Migration DB Error Log Message      *
2627 						**************************************/
2628 
2629 						GMA_COMMON_LOGGING.gma_migration_central_log
2630 						(
2631 						p_run_id             =>       G_migration_run_id,
2632 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
2633 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
2634 						p_table_name         =>       G_table_name,
2635 						p_context            =>       G_context,
2636 						p_db_error           =>       SQLERRM,
2637 						p_app_short_name     =>       'GMA'
2638 						);
2639 
2640 						/**************************************
2641 						* Migration Failure Log Message       *
2642 						**************************************/
2643 
2644 						GMA_COMMON_LOGGING.gma_migration_central_log
2645 						(
2646 						p_run_id             =>       G_migration_run_id,
2647 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
2648 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
2649 						p_table_name         =>       G_table_name,
2650 						p_context            =>       G_context,
2651 						p_db_error           =>       NULL,
2652 						p_app_short_name     =>       'GMA'
2653 						);
2654 
2655 			END;
2656 
2657 			/**********************************************
2658 			* Handle all the rows which were not migrated *
2659 			**********************************************/
2660 
2661 			SELECT            count(*)
2662 			INTO              x_failure_count
2663 			FROM              cm_mthd_mst
2664 			WHERE             (
2665 												(default_lot_cost_type_id IS NULL AND default_lot_cost_mthd IS NOT NULL)
2666 			OR                (cost_type = 1 AND nvl(lot_actual_cost,-1) = 1)
2667 												);
2668 
2669 			IF nvl(x_failure_count,0) > 0 THEN
2670 
2671 				/**************************************
2672 				* Migration Failure Log Message       *
2673 				**************************************/
2674 
2675 				GMA_COMMON_LOGGING.gma_migration_central_log
2676 				(
2677 				p_run_id             =>       gmf_migration.G_migration_run_id,
2678 				p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
2679 				p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
2680 				p_table_name         =>       gmf_migration.G_Table_name,
2681 				p_context            =>       gmf_migration.G_context,
2682 				p_db_error           =>       NULL,
2683 				p_app_short_name     =>       'GMA'
2684 				);
2685 
2686 			ELSE
2687 
2688 				/**************************************
2689 				* Migration Success Log Message       *
2690 				**************************************/
2691 
2692 				GMA_COMMON_LOGGING.gma_migration_central_log
2693 				(
2694 				p_run_id             =>       G_migration_run_id,
2695 				p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
2696 				p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
2697 				p_table_name         =>       G_Table_name,
2698 				p_context            =>       G_Context,
2699 				p_param1             =>       1,
2700 				p_param2             =>       0,
2701 				p_db_error           =>       NULL,
2702 				p_app_short_name     =>       'GMA'
2703 				);
2704 
2705 			END IF;
2706 
2707 			/****************************************************************
2708 			*Lets save the changes now based on the commit parameter        *
2709 			****************************************************************/
2710 
2711 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
2712 				 COMMIT;
2713 			END IF;
2714 
2715 	 EXCEPTION
2716 			WHEN OTHERS THEN
2717 
2718 				 /************************************************
2719 				 * Increment Failure Count for Failed Migrations *
2720 				 ************************************************/
2721 
2722 				 x_failure_count := x_failure_count + 1;
2723 
2724 				 /**************************************
2725 				 * Migration DB Error Log Message      *
2726 				 **************************************/
2727 
2728 				 GMA_COMMON_LOGGING.gma_migration_central_log
2729 				 (
2730 				 p_run_id             =>       G_migration_run_id,
2731 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
2732 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
2733 				 p_table_name         =>       G_table_name,
2734 				 p_context            =>       G_context,
2735 				 p_db_error           =>       SQLERRM,
2736 				 p_app_short_name     =>       'GMA'
2737 				 );
2738 
2739 				 /**************************************
2740 				 * Migration Failure Log Message       *
2741 				 **************************************/
2742 
2743 				 GMA_COMMON_LOGGING.gma_migration_central_log
2744 				 (
2745 				 p_run_id             =>       G_migration_run_id,
2746 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
2747 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
2748 				 p_table_name         =>       G_table_name,
2749 				 p_context            =>       G_context,
2750 				 p_db_error           =>       NULL,
2751 				 p_app_short_name     =>       'GMA'
2752 				 );
2753 
2754 	 END Migrate_Lot_Cost_Methods;
2755 
2756 	 /**********************************************************************
2757 	 * PROCEDURE:                                                          *
2758 	 *   Migrate_Cost_Calendars                                            *
2759 	 *                                                                     *
2760 	 * DESCRIPTION:                                                        *
2761 	 *   This PL/SQL procedure is used to transform the Cost Calendars     *
2762 	 *   data in CM_CLDR_HDR_B AND CM_CLDR_DTL to GMF_CALENDAR_ASSIGNMENTS *
2763 	 *   and GMF_PERIOD_STATUSES                                           *
2764 	 *                                                                     *
2765 	 * PARAMETERS:                                                         *
2766 	 *   P_migration_run_id - id to use to right to migration log          *
2767 	 *   x_exception_count  - Number of exceptions occurred.               *
2768 	 *                                                                     *
2769 	 * SYNOPSIS:                                                           *
2770 	 *   Migrate_cost_calendars(p_migartion_id    => l_migration_id,       *
2771 	 *                    p_commit          => 'T',                        *
2772 	 *                    x_exception_count => l_exception_count );        *
2773 	 *                                                                     *
2774 	 * HISTORY                                                             *
2775 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
2776    *       16-Dec-2006 Bug#5716122 Anand Thiyagarajan                    *
2777    *        Modified Code to remve call to gmf_legal_entity_tz API       *
2778    *        since dates in t he DB are always stored in SRV TZ and not   *
2779    *        in LE TZ                                                     *
2780 	 *                                                                     *
2781 	 **********************************************************************/
2782 	 PROCEDURE Migrate_Cost_Calendars
2783 	 (
2784 	 P_migration_run_id      IN             NUMBER,
2785 	 P_commit                IN             VARCHAR2,
2786 	 X_failure_count         OUT   NOCOPY   NUMBER
2787 	 )
2788 	 IS
2789 
2790 			/*****************
2791 			* PL/SQL Cursors *
2792 			*****************/
2793 
2794 			CURSOR cur_overlap_Calendar
2795 			IS
2796 			SELECT      a.legal_entity_id,
2797 									a.cost_Type_id,
2798 									a.calendar_code
2799 			FROM        gmf_calendar_assignments a
2800 			ORDER BY    a.legal_entity_id,
2801 									a.cost_Type_id,
2802 									a.calendar_code;
2803 
2804 			/******************
2805 			* Local Variables *
2806 			******************/
2807 
2808 			l_exception_count                   NUMBER := 0;
2809 
2810 	 BEGIN
2811 
2812 			G_Migration_run_id := P_migration_run_id;
2813 			G_Table_name := 'GMF_CALENDAR_ASSIGNMENTS';
2814 			G_Context := 'Cost Calendar Assignments Migration';
2815 			X_failure_count := 0;
2816 
2817 			/********************************
2818 			* Migration Started Log Message *
2819 			********************************/
2820 
2821 			GMA_COMMON_LOGGING.gma_migration_central_log
2822 			(
2823 			p_run_id             =>       G_migration_run_id,
2824 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
2825 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
2826 			p_table_name         =>       G_table_name,
2827 			p_context            =>       G_context,
2828 			p_db_error           =>       NULL,
2829 			p_app_short_name     =>       'GMA'
2830 			);
2831 
2832 			/****************************************************************************
2833 			* Insert a row in gmf_calendar_assignments for Direct Calendar Assignments  *
2834 			*****************************************************************************/
2835 			BEGIN
2836 
2837 				INSERT      INTO     gmf_calendar_assignments
2838 				(
2839 				ASSIGNMENT_ID,
2840 				CALENDAR_CODE,
2841 				LEGAL_ENTITY_ID,
2842 				COST_TYPE_ID,
2843 				CREATION_DATE,
2844 				CREATED_BY,
2845 				LAST_UPDATE_DATE,
2846 				LAST_UPDATED_BY,
2847 				LAST_UPDATE_LOGIN,
2848 				TEXT_CODE,
2849 				DELETE_MARK
2850 				)
2851 				SELECT        gmf_calendar_assignments_s.NEXTVAL,
2852 											a.calendar_code,
2853 											b.legal_entity_id,
2854 											c.cost_type_id,
2855 											a.creation_date,
2856 											a.created_by,
2857 											a.last_update_date,
2858 											a.last_updated_by,
2859 											a.last_update_login,
2860 											a.text_code,
2861 											a.delete_mark
2862 				FROM          cm_cldr_hdr_b a,
2863 											gl_plcy_mst b,
2864 											cm_mthd_mst c
2865 				WHERE         a.cost_mthd_code IS NOT NULL
2866 				AND           a.co_code IS NOT NULL
2867 				AND           b.legal_entity_id IS NOT NULL
2868 				AND           c.cost_type_id IS NOT NULL
2869 				AND           a.co_code = b.co_code
2870 				AND           c.cost_mthd_code = a.cost_mthd_code
2871 				AND           NOT EXISTS  (
2872 																	SELECT     'X'
2873 																	FROM        gmf_calendar_assignments x
2874 																	WHERE       x.calendar_code = a.calendar_code
2875 																	AND         x.cost_type_id = c.cost_type_id
2876 																	AND         x.legal_entity_id = b.legal_entity_id
2877 																	);
2878 
2879 			EXCEPTION
2880 				 WHEN OTHERS THEN
2881 
2882 						/************************************************
2883 						* Increment Failure Count for Failed Migrations *
2884 						************************************************/
2885 
2886 						x_failure_count := x_failure_count + 1;
2887 
2888 						/**************************************
2889 						* Migration DB Error Log Message      *
2890 						**************************************/
2891 
2892 						GMA_COMMON_LOGGING.gma_migration_central_log
2893 						(
2894 						p_run_id             =>       G_migration_run_id,
2895 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
2896 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
2897 						p_table_name         =>       G_Table_name,
2898 						p_context            =>       G_context,
2899 						p_db_error           =>       SQLERRM,
2900 						p_app_short_name     =>       'GMA'
2901 						);
2902 
2903 						/**************************************
2904 						* Migration Failure Log Message       *
2905 						**************************************/
2906 
2907 						GMA_COMMON_LOGGING.gma_migration_central_log
2908 						(
2909 						p_run_id             =>       G_migration_run_id,
2910 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
2911 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
2912 						p_table_name         =>       G_Table_name,
2913 						p_context            =>       G_context,
2914 						p_db_error           =>       NULL,
2915 						p_app_short_name     =>       'GMA'
2916 						);
2917 			END;
2918 
2919 			/**********************************************************************
2920 			* Insert a row in gmf_calendar_assignments for transaction table data *
2921 			**********************************************************************/
2922 			BEGIN
2923 
2924 				 INSERT      INTO     gmf_calendar_assignments
2925 				 (
2926 				 ASSIGNMENT_ID,
2927 				 CALENDAR_CODE,
2928 				 LEGAL_ENTITY_ID,
2929 				 COST_TYPE_ID,
2930 				 CREATION_DATE,
2931 				 CREATED_BY,
2932 				 LAST_UPDATE_DATE,
2933 				 LAST_UPDATED_BY,
2934 				 LAST_UPDATE_LOGIN,
2935 				 TEXT_CODE,
2936 				 DELETE_MARK
2937 				 )
2938 				 (
2939 				 SELECT       gmf_calendar_assignments_s.NEXTVAL,
2940 											g.calendar_code,
2941 											i.legal_entity_id,
2942 											h.cost_type_id,
2943 											g.creation_date,
2944 											g.created_by,
2945 											g.last_update_date,
2946 											g.last_updated_by,
2947 											g.last_update_login,
2948 											g.text_code,
2949 											1
2950 				FROM          cm_cldr_hdr_b g,
2951 											cm_mthd_mst h,
2952 											gl_plcy_mst i
2953 				WHERE         g.co_code IS NOT NULL
2954 				AND           i.legal_entity_id IS NOT NULL
2955 				AND           g.cost_mthd_code <> h.cost_mthd_code
2956 				AND           i.co_code = g.co_code
2957 				AND           EXISTS  (
2958 															SELECT      'CM_RSRC_DTL'
2959 															FROM        cm_rsrc_dtl a
2960 															WHERE       a.calendar_code is not null
2961 															AND         a.cost_mthd_Code is not null
2962 															AND         a.calendar_code = g.calendar_code
2963 															AND         a.cost_mthd_code = h.cost_mthd_code
2964 															UNION
2965 															SELECT      'CM_CMPT_DTL'
2966 															FROM        cm_cmpt_dtl a
2967 															WHERE       a.calendar_code is not null
2968 															AND         a.cost_mthd_Code is not null
2969 															AND         a.calendar_code = g.calendar_code
2970 															AND         a.cost_mthd_code = h.cost_mthd_code
2971 															UNION
2972 															SELECT      'CM_BRDN_DTL'
2973 															FROM        cm_brdn_dtl a
2974 															WHERE       a.calendar_code is not null
2975 															AND         a.cost_mthd_Code is not null
2976 															AND         a.calendar_code = g.calendar_code
2977 															AND         a.cost_mthd_code = h.cost_mthd_code
2978 															UNION
2979 															SELECT      'CM_ADJS_DTL'
2980 															FROM        cm_adjs_dtl a
2981 															WHERE       a.calendar_code is not null
2982 															AND         a.cost_mthd_Code is not null
2983 															AND         a.calendar_code = g.calendar_code
2984 															AND         a.cost_mthd_code = h.cost_mthd_code
2985 															UNION
2986 															SELECT      'CM_RLUP_CTL'
2987 															FROM        cm_rlup_ctl a
2988 															WHERE       a.calendar_code is not null
2989 															AND         a.cost_mthd_Code is not null
2990 															AND         a.calendar_code = g.calendar_code
2991 															AND         a.cost_mthd_code = h.cost_mthd_code
2992 															UNION
2993 															SELECT      'CM_ACPR_CTL'
2994 															FROM        cm_acpr_ctl a
2995 															WHERE       a.calendar_code is not null
2996 															AND         a.cost_mthd_Code is not null
2997 															AND         a.calendar_code = g.calendar_code
2998 															AND         a.cost_mthd_code = h.cost_mthd_code
2999 															UNION
3000 															SELECT      'CM_CUPD_CTL'
3001 															FROM        cm_cupd_ctl a
3002 															WHERE       a.calendar_code is not null
3003 															AND         a.cost_mthd_Code is not null
3004 															AND         a.calendar_code = g.calendar_code
3005 															AND         a.cost_mthd_code = h.cost_mthd_code
3006 															)
3007 				AND           NOT EXISTS  (
3008 																	SELECT     'X'
3009 																	FROM        gmf_calendar_assignments x
3010 																	WHERE       x.calendar_code = g.calendar_code
3011 																	AND         x.cost_type_id = h.cost_type_id
3012 																	AND         x.legal_entity_id = i.legal_entity_id
3013 																	)
3014 				 );
3015 
3016 			EXCEPTION
3017 				 WHEN OTHERS THEN
3018 
3019 						/************************************************
3020 						* Increment Failure Count for Failed Migrations *
3021 						************************************************/
3022 
3023 						x_failure_count := x_failure_count + 1;
3024 
3025 						/**************************************
3026 						* Migration DB Error Log Message      *
3027 						**************************************/
3028 
3029 						GMA_COMMON_LOGGING.gma_migration_central_log
3030 						(
3031 						p_run_id             =>       G_migration_run_id,
3032 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
3033 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
3034 						p_table_name         =>       G_Table_name,
3035 						p_context            =>       G_context,
3036 						p_db_error           =>       SQLERRM,
3037 						p_app_short_name     =>       'GMA'
3038 						);
3039 
3040 						/**************************************
3041 						* Migration Failure Log Message       *
3042 						**************************************/
3043 
3044 						GMA_COMMON_LOGGING.gma_migration_central_log
3045 						(
3046 						p_run_id             =>       G_migration_run_id,
3047 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
3048 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
3049 						p_table_name         =>       G_Table_name,
3050 						p_context            =>       G_context,
3051 						p_db_error           =>       NULL,
3052 						p_app_short_name     =>       'GMA'
3053 						);
3054 			END;
3055 
3056 			/**********************************************************************
3057 			* Insert a row in gmf_calendar_assignments for CM_RSRC_DTL table data *
3058 			**********************************************************************/
3059 			BEGIN
3060 
3061 				 INSERT      INTO     gmf_calendar_assignments
3062 				 (
3063 				 ASSIGNMENT_ID,
3064 				 CALENDAR_CODE,
3065 				 LEGAL_ENTITY_ID,
3066 				 COST_TYPE_ID,
3067 				 CREATION_DATE,
3068 				 CREATED_BY,
3069 				 LAST_UPDATE_DATE,
3070 				 LAST_UPDATED_BY,
3071 				 LAST_UPDATE_LOGIN,
3072 				 TEXT_CODE,
3073 				 DELETE_MARK
3074 				 )
3075 				 (
3076 				 SELECT       gmf_calendar_assignments_s.NEXTVAL,
3077 											x.*
3078 				 FROM         (
3079 											SELECT        DISTINCT
3080 																		g.calendar_code,
3081 																		i.legal_entity_id,
3082 																		h.cost_type_id,
3083 																		g.creation_date,
3084 																		g.created_by,
3085 																		g.last_update_date,
3086 																		g.last_updated_by,
3087 																		g.last_update_login,
3088 																		g.text_code,
3089 																		1
3090 											FROM          cm_cldr_hdr_b g,
3091 																		cm_mthd_mst h,
3092 																		gl_plcy_mst i,
3093 																		sy_orgn_mst j,
3094 																		cm_rsrc_dtl k
3095 											WHERE         g.co_code IS NOT NULL
3096 											AND           j.orgn_code = k.orgn_code
3097 											AND           i.co_code = j.co_code
3098 											AND           i.legal_entity_id IS NOT NULL
3099 											AND           j.co_code <> g.co_code
3100 											AND           h.cost_mthd_code = k.cost_mthd_code
3101 											AND           g.calendar_code = k.calendar_code
3102 											AND           NOT EXISTS  (
3103 																								SELECT        'X'
3104 																								FROM          gmf_calendar_assignments x
3105 																								WHERE         x.calendar_code = g.calendar_code
3106 																								AND           x.cost_type_id = h.cost_Type_id
3107 																								AND           x.legal_entity_id = i.legal_Entity_id
3108 																								)
3109 											) x
3110 				 );
3111 
3112 			EXCEPTION
3113 				 WHEN OTHERS THEN
3114 
3115 						/************************************************
3116 						* Increment Failure Count for Failed Migrations *
3117 						************************************************/
3118 
3119 						x_failure_count := x_failure_count + 1;
3120 
3121 						/**************************************
3122 						* Migration DB Error Log Message      *
3123 						**************************************/
3124 
3125 						GMA_COMMON_LOGGING.gma_migration_central_log
3126 						(
3127 						p_run_id             =>       G_migration_run_id,
3128 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
3129 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
3130 						p_table_name         =>       G_Table_name,
3131 						p_context            =>       G_context,
3132 						p_db_error           =>       SQLERRM,
3133 						p_app_short_name     =>       'GMA'
3134 						);
3135 
3136 						/**************************************
3137 						* Migration Failure Log Message       *
3138 						**************************************/
3139 
3140 						GMA_COMMON_LOGGING.gma_migration_central_log
3141 						(
3142 						p_run_id             =>       G_migration_run_id,
3143 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
3144 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
3145 						p_table_name         =>       G_Table_name,
3146 						p_context            =>       G_context,
3147 						p_db_error           =>       NULL,
3148 						p_app_short_name     =>       'GMA'
3149 						);
3150 			END;
3151 
3152 			/**********************************************************************
3153 			* Insert a row in gmf_calendar_assignments for CM_BRDN_DTL table data *
3154 			**********************************************************************/
3155 			BEGIN
3156 
3157 				 INSERT      INTO     gmf_calendar_assignments
3158 				 (
3159 				 ASSIGNMENT_ID,
3160 				 CALENDAR_CODE,
3161 				 LEGAL_ENTITY_ID,
3162 				 COST_TYPE_ID,
3163 				 CREATION_DATE,
3164 				 CREATED_BY,
3165 				 LAST_UPDATE_DATE,
3166 				 LAST_UPDATED_BY,
3167 				 LAST_UPDATE_LOGIN,
3168 				 TEXT_CODE,
3169 				 DELETE_MARK
3170 				 )
3171 				 (
3172 				 SELECT       gmf_calendar_assignments_s.NEXTVAL,
3173 											x.*
3174 				 FROM         (
3175 											SELECT        DISTINCT
3176 																		g.calendar_code,
3177 																		i.legal_entity_id,
3178 																		h.cost_type_id,
3179 																		g.creation_date,
3180 																		g.created_by,
3181 																		g.last_update_date,
3182 																		g.last_updated_by,
3183 																		g.last_update_login,
3184 																		g.text_code,
3185 																		1
3186 											FROM          cm_cldr_hdr_b g,
3187 																		cm_mthd_mst h,
3188 																		gl_plcy_mst i,
3189 																		sy_orgn_mst j,
3190 																		cm_brdn_dtl k
3191 											WHERE         g.co_code IS NOT NULL
3192 											AND           j.orgn_code = k.orgn_code
3193 											AND           i.co_code = j.co_code
3194 											AND           i.legal_entity_id IS NOT NULL
3195 											AND           j.co_code <> g.co_code
3196 											AND           h.cost_mthd_code = k.cost_mthd_code
3197 											AND           g.calendar_code = k.calendar_code
3198 											AND           NOT EXISTS  (
3199 																								SELECT        'X'
3200 																								FROM          gmf_calendar_assignments x
3201 																								WHERE         x.calendar_code = g.calendar_code
3202 																								AND           x.cost_type_id = h.cost_Type_id
3203 																								AND           x.legal_entity_id = i.legal_Entity_id
3204 																								)
3205 											) x
3206 				 );
3207 
3208 			EXCEPTION
3209 				 WHEN OTHERS THEN
3210 
3211 						/************************************************
3212 						* Increment Failure Count for Failed Migrations *
3213 						************************************************/
3214 
3215 						x_failure_count := x_failure_count + 1;
3216 
3217 						/**************************************
3218 						* Migration DB Error Log Message      *
3219 						**************************************/
3220 
3221 						GMA_COMMON_LOGGING.gma_migration_central_log
3222 						(
3223 						p_run_id             =>       G_migration_run_id,
3224 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
3225 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
3226 						p_table_name         =>       G_Table_name,
3227 						p_context            =>       G_context,
3228 						p_db_error           =>       SQLERRM,
3229 						p_app_short_name     =>       'GMA'
3230 						);
3231 
3232 						/**************************************
3233 						* Migration Failure Log Message       *
3234 						**************************************/
3235 
3236 						GMA_COMMON_LOGGING.gma_migration_central_log
3237 						(
3238 						p_run_id             =>       G_migration_run_id,
3239 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
3240 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
3241 						p_table_name         =>       G_Table_name,
3242 						p_context            =>       G_context,
3243 						p_db_error           =>       NULL,
3244 						p_app_short_name     =>       'GMA'
3245 						);
3246 			END;
3247 
3248 			/**********************************************************************
3249 			* Insert a row in gmf_calendar_assignments for CM_CMPT_DTL table data *
3250 			**********************************************************************/
3251 			BEGIN
3252 
3253 				 INSERT      INTO     gmf_calendar_assignments
3254 				 (
3255 				 ASSIGNMENT_ID,
3256 				 CALENDAR_CODE,
3257 				 LEGAL_ENTITY_ID,
3258 				 COST_TYPE_ID,
3259 				 CREATION_DATE,
3260 				 CREATED_BY,
3261 				 LAST_UPDATE_DATE,
3262 				 LAST_UPDATED_BY,
3263 				 LAST_UPDATE_LOGIN,
3264 				 TEXT_CODE,
3265 				 DELETE_MARK
3266 				 )
3267 				 (
3268 				 SELECT       gmf_calendar_assignments_s.NEXTVAL,
3269 											x.*
3270 				 FROM         (
3271 											SELECT        DISTINCT
3272 																		g.calendar_code,
3273 																		i.legal_entity_id,
3274 																		h.cost_type_id,
3275 																		g.creation_date,
3276 																		g.created_by,
3277 																		g.last_update_date,
3278 																		g.last_updated_by,
3279 																		g.last_update_login,
3280 																		g.text_code,
3281 																		1
3282 											FROM          cm_cldr_hdr_b g,
3283 																		cm_mthd_mst h,
3284 																		gl_plcy_mst i,
3285 																		sy_orgn_mst j,
3286 																		cm_cmpt_dtl k,
3287 																		ic_whse_mst l
3288 											WHERE         g.co_code IS NOT NULL
3289 											AND           l.whse_code = k.whse_code
3290 											AND           j.orgn_code = l.orgn_code
3291 											AND           i.co_code = j.co_code
3292 											AND           i.legal_entity_id IS NOT NULL
3293 											AND           j.co_code <> g.co_code
3294 											AND           h.cost_mthd_code = k.cost_mthd_code
3295 											AND           g.calendar_code = k.calendar_code
3296 											AND           NOT EXISTS  (
3297 																								SELECT        'X'
3298 																								FROM          gmf_calendar_assignments x
3299 																								WHERE         x.calendar_code = g.calendar_code
3300 																								AND           x.cost_type_id = h.cost_Type_id
3301 																								AND           x.legal_entity_id = i.legal_Entity_id
3302 																								)
3303 											) x
3304 				 );
3305 
3306 			EXCEPTION
3307 				 WHEN OTHERS THEN
3308 
3309 						/************************************************
3310 						* Increment Failure Count for Failed Migrations *
3311 						************************************************/
3312 
3313 						x_failure_count := x_failure_count + 1;
3314 
3315 						/**************************************
3316 						* Migration DB Error Log Message      *
3317 						**************************************/
3318 
3319 						GMA_COMMON_LOGGING.gma_migration_central_log
3320 						(
3321 						p_run_id             =>       G_migration_run_id,
3322 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
3323 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
3324 						p_table_name         =>       G_Table_name,
3325 						p_context            =>       G_context,
3326 						p_db_error           =>       SQLERRM,
3327 						p_app_short_name     =>       'GMA'
3328 						);
3329 
3330 						/**************************************
3331 						* Migration Failure Log Message       *
3332 						**************************************/
3333 
3334 						GMA_COMMON_LOGGING.gma_migration_central_log
3335 						(
3336 						p_run_id             =>       G_migration_run_id,
3337 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
3338 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
3339 						p_table_name         =>       G_Table_name,
3340 						p_context            =>       G_context,
3341 						p_db_error           =>       NULL,
3342 						p_app_short_name     =>       'GMA'
3343 						);
3344 			END;
3345 
3346 			/**********************************************************************
3347 			* Insert a row in gmf_calendar_assignments for CM_ADJS_DTL table data *
3348 			**********************************************************************/
3349 			BEGIN
3350 
3351 				 INSERT      INTO     gmf_calendar_assignments
3352 				 (
3353 				 ASSIGNMENT_ID,
3354 				 CALENDAR_CODE,
3355 				 LEGAL_ENTITY_ID,
3356 				 COST_TYPE_ID,
3357 				 CREATION_DATE,
3358 				 CREATED_BY,
3359 				 LAST_UPDATE_DATE,
3360 				 LAST_UPDATED_BY,
3361 				 LAST_UPDATE_LOGIN,
3362 				 TEXT_CODE,
3363 				 DELETE_MARK
3364 				 )
3365 				 (
3366 				 SELECT       gmf_calendar_assignments_s.NEXTVAL,
3367 											x.*
3368 				 FROM         (
3369 											SELECT        DISTINCT
3370 																		g.calendar_code,
3371 																		i.legal_entity_id,
3372 																		h.cost_type_id,
3373 																		g.creation_date,
3374 																		g.created_by,
3375 																		g.last_update_date,
3376 																		g.last_updated_by,
3377 																		g.last_update_login,
3378 																		g.text_code,
3379 																		1
3380 											FROM          cm_cldr_hdr_b g,
3381 																		cm_mthd_mst h,
3382 																		gl_plcy_mst i,
3383 																		sy_orgn_mst j,
3384 																		cm_adjs_dtl k,
3385 																		ic_whse_mst l
3386 											WHERE         g.co_code IS NOT NULL
3387 											AND           l.whse_code = k.whse_code
3388 											AND           j.orgn_code = l.orgn_code
3389 											AND           i.co_code = j.co_code
3390 											AND           i.legal_entity_id IS NOT NULL
3391 											AND           j.co_code <> g.co_code
3392 											AND           h.cost_mthd_code = k.cost_mthd_code
3393 											AND           g.calendar_code = k.calendar_code
3394 											AND           NOT EXISTS  (
3395 																								SELECT        'X'
3396 																								FROM          gmf_calendar_assignments x
3397 																								WHERE         x.calendar_code = g.calendar_code
3398 																								AND           x.cost_type_id = h.cost_Type_id
3399 																								AND           x.legal_entity_id = i.legal_Entity_id
3400 																								)
3401 											) x
3402 				 );
3403 
3404 			EXCEPTION
3405 				 WHEN OTHERS THEN
3406 
3407 						/************************************************
3408 						* Increment Failure Count for Failed Migrations *
3409 						************************************************/
3410 
3411 						x_failure_count := x_failure_count + 1;
3412 
3413 						/**************************************
3414 						* Migration DB Error Log Message      *
3415 						**************************************/
3416 
3417 						GMA_COMMON_LOGGING.gma_migration_central_log
3418 						(
3419 						p_run_id             =>       G_migration_run_id,
3420 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
3421 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
3422 						p_table_name         =>       G_Table_name,
3423 						p_context            =>       G_context,
3424 						p_db_error           =>       SQLERRM,
3425 						p_app_short_name     =>       'GMA'
3426 						);
3427 
3428 						/**************************************
3429 						* Migration Failure Log Message       *
3430 						**************************************/
3431 
3432 						GMA_COMMON_LOGGING.gma_migration_central_log
3433 						(
3434 						p_run_id             =>       G_migration_run_id,
3435 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
3436 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
3437 						p_table_name         =>       G_Table_name,
3438 						p_context            =>       G_context,
3439 						p_db_error           =>       NULL,
3440 						p_app_short_name     =>       'GMA'
3441 						);
3442 			END;
3443 
3444 			FOR i IN cur_overlap_calendar loop
3445 				UPDATE  GMF_CALENDAR_ASSIGNMENTS g
3446 				SET     g.delete_mark = 1
3447 				WHERE   g.delete_mark <> 1
3448 				AND     EXISTS  (
3449 												SELECT          'X'
3450 												FROM            gmf_calendar_assignments a,
3451 																				cm_cldr_dtl b
3452 												WHERE           a.calendar_code = b.calendar_code
3453 												AND             a.calendar_code = g.calendar_code
3454 												AND             a.legal_entity_id = g.legal_entity_id
3455 												AND             a.cost_Type_id = g.cost_type_id
3456 												AND             EXISTS  (
3457 																								SELECT 'X' FROM (
3458 																																SELECT      m.legal_entity_id,
3459 																																						m.cost_type_id,
3460 																																						m.calendar_code,
3461 																																						min(n.start_date) mindate,
3462 																																						max(n.end_date) maxdate
3463 																																FROM        gmf_calendar_assignments m,
3464 																																						cm_cldr_dtl n
3465 																																WHERE       m.calendar_code = n.calendar_code
3466 																																AND         m.calendar_code = i.calendar_code
3467 																																AND         m.legal_entity_id = i.legal_entity_id
3468 																																AND         m.cost_type_id = i.cost_type_id
3469 																																AND         m.delete_mark <> 1
3470 																																GROUP by    m.legal_entity_id,
3471 																																						m.calendar_code,
3472 																																						m.cost_type_id
3473 																																) x
3474 																								WHERE   x.legal_entity_id = a.legal_entity_id
3475 																								AND     x.cost_type_id = a.cost_Type_id
3476 																								AND     x.calendar_code <> a.calendar_Code
3477 																								AND     (
3478 																												b.start_date BETWEEN x.mindate AND x.maxdate
3479 																												OR
3480 																												b.end_date BETWEEN x.mindate AND x.maxdate
3481 																												)
3482 																								)
3483 													);
3484 				END LOOP;
3485 
3486 			/**************************************
3487 			* Migration Success Log Message       *
3488 			**************************************/
3489 
3490 			GMA_COMMON_LOGGING.gma_migration_central_log
3491 			(
3492 			p_run_id             =>       G_migration_run_id,
3493 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
3494 			p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
3495 			p_table_name         =>       G_Table_name,
3496 			p_context            =>       G_context,
3497 			p_param1             =>       1,
3498 			p_param2             =>       0,
3499 			p_db_error           =>       NULL,
3500 			p_app_short_name     =>       'GMA'
3501 			);
3502 
3503 			G_Migration_run_id := P_migration_run_id;
3504 			G_Table_name := 'GMF_PERIOD_STATUSES';
3505 			G_Context := 'Cost Calendar Period Statuses Migration';
3506 
3507 			/********************************
3508 			* Migration Started Log Message *
3509 			********************************/
3510 
3511 			GMA_COMMON_LOGGING.gma_migration_central_log
3512 			(
3513 			p_run_id             =>       G_migration_run_id,
3514 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
3515 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
3516 			p_table_name         =>       G_Table_name,
3517 			p_context            =>       G_context,
3518 			p_db_error           =>       NULL,
3519 			p_app_short_name     =>       'GMA'
3520 			);
3521 
3522 			/*****************************************
3523 			* Insert a row into gmf_period_statuses  *
3524 			*****************************************/
3525 
3526 			BEGIN
3527 
3528 				 INSERT    INTO    gmf_period_statuses
3529 				 (
3530 				 PERIOD_ID,
3531 				 LEGAL_ENTITY_ID,
3532 				 COST_TYPE_ID,
3533 				 CALENDAR_CODE,
3534 				 PERIOD_CODE,
3535 				 START_DATE,
3536 				 END_DATE,
3537 				 PERIOD_STATUS,
3538 				 CREATION_DATE,
3539 				 CREATED_BY,
3540 				 LAST_UPDATE_DATE,
3541 				 LAST_UPDATED_BY,
3542 				 LAST_UPDATE_LOGIN,
3543 				 TEXT_CODE,
3544 				 DELETE_MARK
3545 				 )
3546 				 SELECT      gmf_period_id_s.NEXTVAL,
3547 										 a.legal_entity_id,
3548 										 a.cost_type_id,
3549 										 a.calendar_code,
3550 										 b.period_code,
3551 										 b.start_date, /* Bug#5716122 ANTHIYAG 16-Dec-2006 */
3552 										 b.end_date, /* Bug#5716122 ANTHIYAG 16-Dec-2006 */
3553 										 decode(b.period_status, 0, 'O', 1, 'F', 2, 'C', 'O') period_status,
3554 										 b.creation_date,
3555 										 b.created_by,
3556 										 b.last_update_date,
3557 										 b.last_updated_by,
3558 										 b.last_update_login,
3559 										 b.text_code,
3560 										 decode(a.delete_mark + b.delete_mark, 0, 0, 1)
3561 				 FROM        gmf_calendar_assignments a,
3562 										 cm_cldr_dtl b,
3563 										 cm_cldr_hdr_b h
3564 				 WHERE       a.calendar_code = b.calendar_code
3565 				 AND         b.calendar_code = h.calendar_code
3566 				 AND         h.co_code IS NOT NULL
3567 				 AND         h.cost_mthd_code IS NOT NULL
3568 				 AND         NOT EXISTS (
3569 																SELECT   'X'
3570 																FROM     gmf_period_statuses p
3571 																WHERE    p.legal_entity_id = a.legal_entity_id
3572 																AND      p.cost_type_id = a.cost_type_id
3573 																AND      p.calendar_code = b.calendar_code
3574 																AND      p.period_code = b.period_code
3575 																);
3576 
3577 				 UPDATE     gmf_period_statuses a
3578 				 SET        a.delete_mark = 1
3579 				 WHERE      EXISTS (
3580 													 SELECT          'X'
3581 													 FROM            gmf_calendar_assignments x
3582 													 WHERE           x.legal_entity_id = a.legal_entity_id
3583 													 AND             x.calendar_code = a.calendar_code
3584 													 AND             x.cost_type_id = a.cost_type_id
3585 													 AND             x.delete_mark = 1
3586 													 );
3587 
3588 			EXCEPTION
3589 				 WHEN OTHERS THEN
3590 
3591 						/************************************************
3592 						* Increment Failure Count for Failed Migrations *
3593 						************************************************/
3594 
3595 						x_failure_count := x_failure_count + 1;
3596 
3597 						/**************************************
3598 						* Migration DB Error Log Message      *
3599 						**************************************/
3600 
3601 						GMA_COMMON_LOGGING.gma_migration_central_log
3602 						(
3603 						p_run_id             =>       G_migration_run_id,
3604 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
3605 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
3606 						p_table_name         =>       G_Table_name,
3607 						p_context            =>       G_context,
3608 						p_db_error           =>       SQLERRM,
3609 						p_app_short_name     =>       'GMA'
3610 						);
3611 
3612 						/**************************************
3613 						* Migration Failure Log Message       *
3614 						**************************************/
3615 
3616 						GMA_COMMON_LOGGING.gma_migration_central_log
3617 						(
3618 						p_run_id             =>       G_migration_run_id,
3619 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
3620 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
3621 						p_table_name         =>       G_Table_name,
3622 						p_context            =>       G_context,
3623 						p_db_error           =>       NULL,
3624 						p_app_short_name     =>       'GMA'
3625 						);
3626 
3627 			END;
3628 
3629 			/**************************************
3630 			* Migration Success Log Message       *
3631 			**************************************/
3632 
3633 			GMA_COMMON_LOGGING.gma_migration_central_log
3634 			(
3635 			p_run_id             =>       G_migration_run_id,
3636 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
3637 			p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
3638 			p_table_name         =>       G_Table_name,
3639 			p_context            =>       G_context,
3640 			p_param1             =>       1,
3641 			p_param2             =>       0,
3642 			p_db_error           =>       NULL,
3643 			p_app_short_name     =>       'GMA'
3644 			);
3645 
3646 			/****************************************************************
3647 			* Lets save the changes now based on the commit parameter       *
3648 			****************************************************************/
3649 
3650 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
3651 				 COMMIT;
3652 			END IF;
3653 
3654 	 EXCEPTION
3655 			WHEN OTHERS THEN
3656 
3657 				 /************************************************
3658 				 * Increment Failure Count for Failed Migrations *
3659 				 ************************************************/
3660 
3661 				 x_failure_count := x_failure_count + 1;
3662 
3663 				 /**************************************
3664 				 * Migration DB Error Log Message      *
3665 				 **************************************/
3666 
3667 				 GMA_COMMON_LOGGING.gma_migration_central_log
3668 				 (
3669 				 p_run_id             =>       G_migration_run_id,
3670 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
3671 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
3672 				 p_table_name         =>       G_Table_name,
3673 				 p_context            =>       G_context,
3674 				 p_db_error           =>       SQLERRM,
3675 				 p_app_short_name     =>       'GMA'
3676 				 );
3677 
3678 				 /**************************************
3679 				 * Migration Failure Log Message       *
3680 				 **************************************/
3681 
3682 				 GMA_COMMON_LOGGING.gma_migration_central_log
3683 				 (
3684 				 p_run_id             =>       G_migration_run_id,
3685 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
3686 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
3687 				 p_table_name         =>       G_Table_name,
3688 				 p_context            =>       G_context,
3689 				 p_db_error           =>       NULL,
3690 				 p_app_short_name     =>       'GMA'
3691 				 );
3692 
3693 	 END Migrate_Cost_Calendars;
3694 
3695 	 /**********************************************************************
3696 	 * PROCEDURE:                                                          *
3697 	 *   Migrate_Burden_Percentages                                        *
3698 	 *                                                                     *
3699 	 * DESCRIPTION:                                                        *
3700 	 *   This PL/SQL procedure is used to migrate the Burden Percentages   *
3701 	 *                                                                     *
3702 	 * PARAMETERS:                                                         *
3703 	 *   P_migration_run_id - id to use to right to migration log          *
3704 	 *   x_exception_count  - Number of exceptions occurred.               *
3705 	 *                                                                     *
3706 	 * SYNOPSIS:                                                           *
3707 	 *   Migrate_Burden_Percentages(p_migartion_id    => l_migration_id,   *
3708 	 *                    p_commit          => 'T',                        *
3709 	 *                    x_exception_count => l_exception_count );        *
3710 	 *                                                                     *
3711 	 * HISTORY                                                             *
3712 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
3713 	 *       05-Jul-2006 rseshadr bug 5374823 - call item mig inline for   *
3714 	 *         the current table                                           *
3715 	 *                                                                     *
3716 	 **********************************************************************/
3717 	 PROCEDURE Migrate_Burden_Percentages
3718 	 (
3719 	 P_migration_run_id      IN             NUMBER,
3720 	 P_commit                IN             VARCHAR2,
3721 	 X_failure_count         OUT   NOCOPY   NUMBER
3722 	 )
3723 	 IS
3724 
3725 			/****************
3726 			* PL/SQL Tables *
3727 			****************/
3728 
3729 			/******************
3730 			* Local Variables *
3731 			******************/
3732 
3733 			l_inventory_item_id                 NUMBER;
3734 			l_itm_failure_count                 NUMBER;
3735 			l_itm_failure_count_all             NUMBER;
3736 
3737 			/****************
3738 			* Cursors       *
3739 			****************/
3740 
3741 			CURSOR            cur_get_gmf_items IS
3742 			SELECT            DISTINCT item_id,
3743 												organization_id
3744 			FROM              (
3745 												SELECT            a.item_id,
3746 																					nvl(DECODE(NVL(c.subinventory_ind_flag,'N'), 'Y', c.organization_id, c.mtl_organization_id), DECODE(NVL(b.subinventory_ind_flag,'N'), 'Y', b.organization_id, b.mtl_organization_id)) organization_id
3747 												FROM              gmf_burden_percentages a,
3748 																					ic_whse_mst b,
3749 																					ic_whse_mst c
3750 												WHERE             a.item_id IS NOT NULL
3751 												AND               b.orgn_code = a.orgn_code
3752 												AND               c.whse_code(+) = a.whse_code
3753 												);
3754 
3755 	 BEGIN
3756 
3757 			G_Migration_run_id := P_migration_run_id;
3758 			G_Table_name := 'GMF_BURDEN_PERCENTAGES';
3759 			G_Context := 'Burden Percentages Migration';
3760 			X_failure_count := 0;
3761 
3762 			/********************************
3763 			* Migration Started Log Message *
3764 			********************************/
3765 
3766 			GMA_COMMON_LOGGING.gma_migration_central_log
3767 			(
3768 			p_run_id             =>       G_migration_run_id,
3769 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
3770 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
3771 			p_table_name         =>       G_Table_name,
3772 			p_context            =>       G_context,
3773 			p_db_error           =>       NULL,
3774 			p_app_short_name     =>       'GMA'
3775 			);
3776 
3777 			/********************************************
3778 			* rseshadr bug 5374823                      *
3779 			* Call Item Migration API in a loop         *
3780 			* To Migrate necessary items for this table *
3781 			*********************************************/
3782 
3783 			FOR i IN cur_get_gmf_items
3784 			LOOP
3785 				IF i.item_id IS NOT NULL AND i.organization_id IS NOT NULL THEN
3786 					inv_opm_item_migration.get_odm_item
3787 					(
3788 					p_migration_run_id        =>        p_migration_run_id,
3789 					p_item_id                 =>        i.item_id,
3790 					p_organization_id         =>        i.organization_id,
3791 					p_mode                    =>        NULL,
3792 					p_commit                  =>        FND_API.G_TRUE,
3793 					x_inventory_item_id       =>        l_inventory_item_id,
3794 					x_failure_count           =>        l_itm_failure_count
3795 					);
3796 				END IF;
3797 				l_itm_failure_count_all := nvl(l_itm_failure_count_all,0) + nvl(l_itm_failure_count,0);
3798 			END LOOP;
3799 
3800 			/********************************************************
3801 			* Update a row in GMF_BURDEN_PERCENTAGES                *
3802 			********************************************************/
3803 
3804 			BEGIN
3805 
3806 				INSERT
3807 				INTO        gmf_burden_percentages
3808 				(
3809 				burden_percentage_id,
3810 				calendar_code,
3811 				period_code,
3812 				cost_mthd_code,
3813 				burden_id,
3814 				orgn_code,
3815 				whse_code,
3816 				item_id,
3817 				percentage,
3818 				created_by,
3819 				creation_date,
3820 				last_updated_by,
3821 				last_update_date,
3822 				last_update_login,
3823 				delete_mark,
3824 				gl_business_category_id,
3825 				gl_category_id,
3826 				cost_category_id,
3827 				gl_prod_line_category_id
3828 				)
3829 				(
3830 				SELECT      gmf_burden_percentage_id_s.NEXTVAL,
3831 										a.calendar_code,
3832 										a.period_code,
3833 										a.cost_mthd_code,
3834 										a.burden_id,
3835 										a.orgn_code,
3836 										e.whse_code,
3837 										a.item_id,
3838 										a.percentage,
3839 										a.created_by,
3840 										sysdate,
3841 										a.last_updated_by,
3842 										sysdate,
3843 										a.last_update_login,
3844 										a.delete_mark,
3845 										a.gl_business_category_id,
3846 										a.gl_category_id,
3847 										a.cost_category_id,
3848 										a.gl_prod_line_category_id
3849 				FROM        gmf_burden_percentages a,
3850 										ic_whse_mst e
3851 				WHERE       a.orgn_code IS NOT NULL
3852 				AND         a.whse_code IS NULL
3853 				AND         a.orgn_code = e.orgn_code
3854 				AND         e.mtl_organization_id IS NOT NULL
3855 				AND         nvl(e.subinventory_ind_flag,'N') <> 'Y'
3856 				AND         NOT EXISTS  (
3857 																SELECT            'X'
3858 																FROM              gmf_burden_percentages x
3859 																WHERE             x.calendar_code = a.calendar_code
3860 																AND               x.period_code = a.period_code
3861 																AND               x.cost_mthd_code = a.cost_mthd_code
3862 																AND               x.burden_id = a.burden_id
3863 																AND               x.orgn_code = a.orgn_code
3864 																AND               x.whse_code = e.whse_code
3865 																AND               nvl(x.item_id, -1) = nvl(a.item_id, -1)
3866 																AND               nvl(x.gl_category_id, -1) = nvl(a.gl_category_id, -1)
3867 																AND               nvl(x.cost_category_id, -1) = nvl(a.cost_category_id, -1)
3868 																AND               nvl(x.gl_business_category_id, -1) = nvl(a.gl_business_category_id, -1)
3869 																AND               nvl(x.gl_prod_line_category_id, -1) = nvl(a.gl_prod_line_category_id, -1)
3870 																)
3871 				);
3872 
3873 				UPDATE      gmf_burden_percentages a
3874 				SET         (
3875 										a.cost_type_id,
3876 										a.period_id,
3877 										a.legal_entity_id
3878 										)
3879 				=           (
3880 										SELECT      x.cost_type_id,
3881 																x.period_id,
3882 																x.legal_entity_id
3883 										FROM        gmf_period_statuses x,
3884 																cm_mthd_mst y,
3885 																cm_cldr_hdr_b z,
3886 																gl_plcy_mst w
3887 										WHERE       y.cost_mthd_code = a.cost_mthd_code
3888 										AND         x.cost_type_id   = y.cost_type_id
3889 										AND         x.calendar_code  = a.calendar_code
3890 										AND         x.period_code    = a.period_code
3891 										AND         z.calendar_code  = x.calendar_code
3892 										AND         z.co_code        = w.co_code
3893 										AND         x.legal_entity_id= w.legal_entity_id
3894 										),
3895 										(
3896 										a.organization_id,
3897 										a.delete_mark
3898 										)
3899 				=           (
3900 										SELECT            DECODE(a.whse_code, null, DECODE(NVL(Y.INVENTORY_ORG_IND,'N'), 'Y', y.organization_id, NULL), DECODE(NVL(x.subinventory_ind_flag,'N'), 'Y', x.organization_id, x.mtl_organization_id)),
3901 																			DECODE(a.delete_mark, 1, a.delete_mark, DECODE(a.whse_code, null, DECODE(NVL(Y.INVENTORY_ORG_IND,'N'), 'Y', 0, 1), DECODE(NVL(x.subinventory_ind_flag,'N'), 'Y', 1, 0)))
3902 										FROM              ic_whse_mst x, sy_orgn_mst y
3903 										WHERE             x.whse_code = nvl(a.whse_code, x.whse_code)
3904 										and               y.orgn_code = DECODE(a.whse_code, NULL, a.orgn_code, x.orgn_code)
3905 										AND               ROWNUM = 1
3906 										)
3907 				WHERE       (
3908 										(a.cost_type_id IS NULL AND a.cost_mthd_code IS NOT NULL)
3909 				OR          (a.calendar_code IS NOT NULL AND a.period_code IS NOT NULL AND a.period_id IS NULL)
3910 				OR          (a.calendar_code IS NOT NULL AND a.legal_entity_id IS NULL)
3911 				OR          (a.organization_id IS NULL AND (a.whse_code IS NOT NULL OR a.orgn_code IS NOT NULL))
3912 										);
3913 
3914 			EXCEPTION
3915 				 WHEN OTHERS THEN
3916 
3917 						/************************************************
3918 						* Increment Failure Count for Failed Migrations *
3919 						************************************************/
3920 
3921 						x_failure_count := x_failure_count + 1;
3922 
3923 						/**************************************
3924 						* Migration DB Error Log Message      *
3925 						**************************************/
3926 
3927 						GMA_COMMON_LOGGING.gma_migration_central_log
3928 						(
3929 						p_run_id             =>       G_migration_run_id,
3930 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
3931 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
3932 						p_table_name         =>       G_Table_name,
3933 						p_context            =>       G_context,
3934 						p_db_error           =>       SQLERRM,
3935 						p_app_short_name     =>       'GMA'
3936 						);
3937 
3938 						/**************************************
3939 						* Migration Failure Log Message       *
3940 						**************************************/
3941 
3942 						GMA_COMMON_LOGGING.gma_migration_central_log
3943 						(
3944 						p_run_id             =>       G_migration_run_id,
3945 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
3946 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
3947 						p_table_name         =>       G_Table_name,
3948 						p_context            =>       G_context,
3949 						p_db_error           =>       NULL,
3950 						p_app_short_name     =>       'GMA'
3951 						);
3952 
3953 			END;
3954 
3955 			BEGIN
3956 				UPDATE      gmf_burden_percentages a
3957 				SET         (
3958 										a.master_organization_id,
3959 										a.inventory_item_id
3960 										)
3961 				=           (
3962 										SELECT            z.master_organization_id,
3963 																			y.inventory_item_id
3964 										FROM              ic_item_mst_b_mig y,
3965 																			mtl_parameters z,
3966 																			hr_organization_information hoi
3967 										WHERE             y.item_id = a.item_id
3968 										AND               y.organization_id = z.organization_id
3969 										AND               hoi.organization_id = z.organization_id
3970 										AND               hoi.org_information_context = 'Accounting Information'
3971 										AND               hoi.org_information2 = a.legal_entity_id
3972 										AND               ROWNUM = 1
3973 										)
3974 				WHERE       (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
3975 				OR          (a.master_organization_id IS NULL AND a.item_id IS NOT NULL);
3976 
3977 				UPDATE      gmf_burden_percentages a
3978 				SET         a.delete_mark = 1
3979 				WHERE       ROWID NOT IN  (
3980 																	SELECT  MIN(x.ROWID)
3981 																	FROM    gmf_burden_percentages x
3982 																	WHERE   x.legal_entity_id = a.legal_entity_id
3983 																	AND     x.period_id = a.period_id
3984 																	AND     x.cost_type_id = a.cost_type_id
3985 																	AND     x.burden_id = a.burden_id
3986 																	AND     nvl(x.inventory_item_id, -1) = nvl(a.inventory_item_id, -1)
3987 																	AND     nvl(x.organization_id, -1) = nvl(a.organization_id, -1)
3988 																	AND     nvl(x.gl_category_id, -1) = nvl(a.gl_category_id, -1)
3989 																	AND     nvl(x.cost_category_id, -1) = nvl(a.cost_category_id, -1)
3990 																	AND     nvl(x.gl_business_category_id, -1) = nvl(a.gl_business_category_id, -1)
3991 																	AND     nvl(x.gl_prod_line_category_id, -1) = nvl(a.gl_prod_line_category_id, -1)
3992 																	AND     x.delete_mark <> 1
3993 																	);
3994 
3995 			EXCEPTION
3996 				WHEN OTHERS THEN
3997 
3998 						/************************************************
3999 						* Increment Failure Count for Failed Migrations *
4000 						************************************************/
4001 
4002 						x_failure_count := x_failure_count + 1;
4003 
4004 						/**************************************
4005 						* Migration DB Error Log Message      *
4006 						**************************************/
4007 
4008 						GMA_COMMON_LOGGING.gma_migration_central_log
4009 						(
4010 						p_run_id             =>       G_migration_run_id,
4011 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
4012 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
4013 						p_table_name         =>       G_Table_name,
4014 						p_context            =>       G_context,
4015 						p_db_error           =>       SQLERRM,
4016 						p_app_short_name     =>       'GMA'
4017 						);
4018 
4019 						/**************************************
4020 						* Migration Failure Log Message       *
4021 						**************************************/
4022 
4023 						GMA_COMMON_LOGGING.gma_migration_central_log
4024 						(
4025 						p_run_id             =>       G_migration_run_id,
4026 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
4027 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
4028 						p_table_name         =>       G_Table_name,
4029 						p_context            =>       G_context,
4030 						p_db_error           =>       NULL,
4031 						p_app_short_name     =>       'GMA'
4032 						);
4033 
4034 			END;
4035 
4036 			/**********************************************
4037 			* Handle all the rows which were not migrated *
4038 			**********************************************/
4039 
4040 			SELECT               count(*)
4041 			INTO                 x_failure_count
4042 			FROM                 gmf_burden_percentages
4043 			WHERE                (
4044 													 (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
4045 			OR                   (calendar_code IS NOT NULL AND period_code IS NOT NULL AND period_id IS NULL)
4046 			OR                   (calendar_code IS NOT NULL AND legal_entity_id IS NULL)
4047 			OR                   (organization_id IS NULL AND delete_mark = 0 AND (whse_code IS NOT NULL OR orgn_code IS NOT NULL))
4048 			OR                   (inventory_item_id IS NULL AND item_id IS NOT NULL)
4049 			OR                   (master_organization_id IS NULL AND item_id IS NOT NULL)
4050 													 );
4051 
4052 			IF nvl(x_failure_count,0) > 0 THEN
4053 
4054 				/**************************************
4055 				* Migration Failure Log Message       *
4056 				**************************************/
4057 
4058 				GMA_COMMON_LOGGING.gma_migration_central_log
4059 				(
4060 				p_run_id             =>       gmf_migration.G_migration_run_id,
4061 				p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
4062 				p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
4063 				p_table_name         =>       gmf_migration.G_Table_name,
4064 				p_context            =>       gmf_migration.G_context,
4065 				p_db_error           =>       NULL,
4066 				p_app_short_name     =>       'GMA'
4067 				);
4068 
4069 			ELSE
4070 
4071 				/**************************************
4072 				* Migration Success Log Message       *
4073 				**************************************/
4074 
4075 				GMA_COMMON_LOGGING.gma_migration_central_log
4076 				(
4077 				p_run_id             =>       G_migration_run_id,
4078 				p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
4079 				p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
4080 				p_table_name         =>       G_Table_name,
4081 				p_context            =>       G_Context,
4082 				p_param1             =>       1,
4083 				p_param2             =>       0,
4084 				p_db_error           =>       NULL,
4085 				p_app_short_name     =>       'GMA'
4086 				);
4087 
4088 			END IF;
4089 
4090 			/****************************************************************
4091 			* Lets save the changes now based on the commit parameter       *
4092 			****************************************************************/
4093 
4094 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
4095 				 COMMIT;
4096 			END IF;
4097 
4098 	 EXCEPTION
4099 			WHEN OTHERS THEN
4100 
4101 				 /************************************************
4102 				 * Increment Failure Count for Failed Migrations *
4103 				 ************************************************/
4104 
4105 				 x_failure_count := x_failure_count + 1;
4106 
4107 				 /**************************************
4108 				 * Migration DB Error Log Message      *
4109 				 **************************************/
4110 
4111 				 GMA_COMMON_LOGGING.gma_migration_central_log
4112 				 (
4113 				 p_run_id             =>       G_migration_run_id,
4114 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
4115 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
4116 				 p_table_name         =>       G_Table_name,
4117 				 p_context            =>       G_context,
4118 				 p_db_error           =>       SQLERRM,
4119 				 p_app_short_name     =>       'GMA'
4120 				 );
4121 
4122 				 /**************************************
4123 				 * Migration Failure Log Message       *
4124 				 **************************************/
4125 
4126 				 GMA_COMMON_LOGGING.gma_migration_central_log
4127 				 (
4128 				 p_run_id             =>       G_migration_run_id,
4129 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
4130 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
4131 				 p_table_name         =>       G_Table_name,
4132 				 p_context            =>       G_context,
4133 				 p_db_error           =>       NULL,
4134 				 p_app_short_name     =>       'GMA'
4135 				 );
4136 
4137 	 END Migrate_Burden_Percentages;
4138 
4139 	 /**********************************************************************
4140 	 * PROCEDURE:                                                          *
4141 	 *   Migrate_Lot_Costs                                                 *
4142 	 *                                                                     *
4143 	 * DESCRIPTION:                                                        *
4144 	 *   This PL/SQL procedure is used to migrate the Lot Costs            *
4145 	 *                                                                     *
4146 	 * PARAMETERS:                                                         *
4147 	 *   P_migration_run_id - id to use to right to migration log          *
4148 	 *   x_exception_count  - Number of exceptions occurred.               *
4149 	 *                                                                     *
4150 	 * SYNOPSIS:                                                           *
4151 	 *   Migrate_Lot_Costs(p_migartion_id    => l_migration_id,            *
4152 	 *                    p_commit          => 'T',                        *
4153 	 *                    x_exception_count => l_exception_count );        *
4154 	 *                                                                     *
4155 	 * HISTORY                                                             *
4156 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
4157    *       31-Oct-2006 Modified Anand Thiyagarajan                       *
4158    *          Modified Code to add insertion of Lot cost records for new *
4159    *          lots created by the Lot migration process for lot id's     *
4160 	 *                                                                     *
4161 	 **********************************************************************/
4162 	 PROCEDURE Migrate_Lot_Costs
4163 	 (
4164 	 P_migration_run_id      IN             NUMBER,
4165 	 P_commit                IN             VARCHAR2,
4166 	 X_failure_count         OUT   NOCOPY   NUMBER
4167 	 )
4168 	 IS
4169 
4170 			/**************************
4171 			* PL/SQL Table Definition *
4172 			**************************/
4173 
4174 			/******************
4175 			* Local Variables *
4176 			******************/
4177 
4178 	 BEGIN
4179 
4180 			G_Migration_run_id := P_migration_run_id;
4181 			G_Table_name := 'GMF_LOT_COSTS';
4182 			G_Context := 'Lot Costs Migration';
4183 			X_failure_count := 0;
4184 
4185 			/********************************
4186 			* Migration Started Log Message *
4187 			********************************/
4188 
4189 			GMA_COMMON_LOGGING.gma_migration_central_log
4190 			(
4191 			p_run_id             =>       G_migration_run_id,
4192 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
4193 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
4194 			p_table_name         =>       G_Table_name,
4195 			p_context            =>       G_context,
4196 			p_db_error           =>       NULL,
4197 			p_app_short_name     =>       'GMA'
4198 			);
4199 
4200 			BEGIN
4201 
4202 				 /******************************
4203 				 * Update a row for cost Types *
4204 				 ******************************/
4205 
4206 				 UPDATE      gmf_lot_costs a
4207 				 SET         a.cost_type_id
4208 				 =           (
4209 										 SELECT      x.cost_Type_id
4210 										 FROM        cm_mthd_mst x
4211 										 WHERE       x.cost_mthd_code = a.cost_mthd_code
4212 										 ),
4213 										 (
4214 										 a.organization_id,
4215 										 a.inventory_item_id
4216 										 )
4217 				 =           (
4218 										 SELECT      decode(x.cost_organization_id, -1, -1, y.organization_id),
4219 																 y.inventory_item_id
4220 										 FROM        ic_whse_mst x,
4221 																 ic_item_mst_b_mig y
4222 										 WHERE       x.whse_code = a.whse_code
4223 										 AND         y.item_id = a.item_id
4224 										 AND         y.organization_id = NVL(DECODE(x.cost_organization_id, -1, x.mtl_organization_id, x.cost_organization_id), x.mtl_organization_id)
4225 										 )
4226 				 WHERE       (
4227 										 (a.cost_type_id IS NULL AND a.cost_mthd_code IS NOT NULL)
4228 				 OR          (a.organization_id IS NULL AND a.whse_code IS NOT NULL)
4229 				 OR          (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
4230 										 );
4231 
4232 			EXCEPTION
4233 				 WHEN OTHERS THEN
4234 
4235 						/************************************************
4236 						* Increment Failure Count for Failed Migrations *
4237 						************************************************/
4238 
4239 						x_failure_count := x_failure_count + 1;
4240 
4241 						/**************************************
4242 						* Migration DB Error Log Message      *
4243 						**************************************/
4244 
4245 						GMA_COMMON_LOGGING.gma_migration_central_log
4246 						(
4247 						p_run_id             =>       G_migration_run_id,
4248 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
4249 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
4250 						p_table_name         =>       G_Table_name,
4251 						p_context            =>       G_context,
4252 						p_db_error           =>       SQLERRM,
4253 						p_app_short_name     =>       'GMA'
4254 						);
4255 
4256 						/**************************************
4257 						* Migration Failure Log Message       *
4258 						**************************************/
4259 
4260 						GMA_COMMON_LOGGING.gma_migration_central_log
4261 						(
4262 						p_run_id             =>       G_migration_run_id,
4263 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
4264 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
4265 						p_table_name         =>       G_Table_name,
4266 						p_context            =>       G_context,
4267 						p_db_error           =>       NULL,
4268 						p_app_short_name     =>       'GMA'
4269 						);
4270 
4271 			END;
4272 
4273       BEGIN
4274          /****************************************************************************
4275          * Insert rows for Additional Lots Created as part of Lot Balances Migration *
4276          ****************************************************************************/
4277           INSERT INTO           gmf_lot_costs
4278           (
4279           header_id,
4280           unit_cost,
4281           cost_date,
4282           onhand_qty,
4283           frozen_ind,
4284           attribute1,
4285           attribute2,
4286           attribute3,
4287           attribute4,
4288           attribute5,
4289           attribute6,
4290           attribute7,
4291           attribute8,
4292           attribute9,
4293           attribute10,
4294           attribute11,
4295           attribute12,
4296           attribute13,
4297           attribute14,
4298           attribute15,
4299           attribute16,
4300           attribute17,
4301           attribute18,
4302           attribute19,
4303           attribute20,
4304           attribute21,
4305           attribute22,
4306           attribute23,
4307           attribute24,
4308           attribute25,
4309           attribute26,
4310           attribute27,
4311           attribute28,
4312           attribute29,
4313           attribute30,
4314           attribute_category,
4315           creation_date,
4316           created_by,
4317           last_update_date,
4318           last_updated_by,
4319           last_update_login,
4320           text_code,
4321           delete_mark,
4322           final_cost_flag,
4323           cost_type_id,
4324           inventory_item_id,
4325           lot_number,
4326           organization_id
4327           )
4328           (
4329           SELECT                gmf_cost_header_id_s.NEXTVAL,
4330                                 a.unit_cost,
4331                                 a.cost_date,
4332                                 a.onhand_qty,
4333                                 a.frozen_ind,
4334                                 a.attribute1,
4335                                 a.attribute2,
4336                                 a.attribute3,
4337                                 a.attribute4,
4338                                 a.attribute5,
4339                                 a.attribute6,
4340                                 a.attribute7,
4341                                 a.attribute8,
4342                                 a.attribute9,
4343                                 a.attribute10,
4344                                 a.attribute11,
4345                                 a.attribute12,
4346                                 a.attribute13,
4347                                 a.attribute14,
4348                                 a.attribute15,
4349                                 a.attribute16,
4350                                 a.attribute17,
4351                                 a.attribute18,
4352                                 a.attribute19,
4353                                 a.attribute20,
4354                                 a.attribute21,
4355                                 a.attribute22,
4356                                 a.attribute23,
4357                                 a.attribute24,
4358                                 a.attribute25,
4359                                 a.attribute26,
4360                                 a.attribute27,
4361                                 a.attribute28,
4362                                 a.attribute29,
4363                                 a.attribute30,
4364                                 a.attribute_category,
4365                                 sysdate,
4366                                 a.created_by,
4367                                 sysdate,
4368                                 a.last_updated_by,
4369                                 a.last_update_login,
4370                                 a.header_id,
4371                                 a.delete_mark,
4372                                 a.final_cost_flag,
4373                                 a.cost_type_id,
4374                                 a.inventory_item_id,
4375                                 b.lot_number,
4376                                 a.organization_id
4377           FROM                  gmf_lot_costs a,
4378                                 ic_lots_mst_mig b
4379           WHERE                 a.lot_id = b.lot_id
4380           AND                   nvl(b.additional_status_lot,0) = 1
4381           AND                   (
4382                                 (a.cost_type_id IS NOT NULL AND a.cost_mthd_code IS NOT NULL)
4383           OR                    (a.organization_id IS NOT NULL AND a.whse_code IS NOT NULL)
4384           OR                    (a.inventory_item_id IS NOT NULL AND a.item_id IS NOT NULL)
4385           OR                    (a.lot_number IS NOT NULL AND a.lot_id IS NOT NULL)
4386                                 )
4387           AND                   NOT EXISTS  (
4388                                             SELECT            'RECORD_ALREADY_EXISTS'
4389                                             FROM              gmf_lot_costs x
4390                                             WHERE             x.organization_id = a.organization_id
4391                                             AND               x.inventory_item_id = a.inventory_item_id
4392                                             AND               x.cost_type_id = a.cost_type_id
4393                                             AND               x.lot_number = b.lot_number
4394                                             AND               x.cost_date = a.cost_date
4395                                             )
4396           );
4397       EXCEPTION
4398          WHEN OTHERS THEN
4399             /************************************************
4400             * Increment Failure Count for Failed Migrations *
4401             ************************************************/
4402             x_failure_count := x_failure_count + 1;
4403             /**************************************
4404             * Migration DB Error Log Message      *
4405             **************************************/
4406             GMA_COMMON_LOGGING.gma_migration_central_log
4407             (
4408             p_run_id             =>       G_migration_run_id,
4409             p_log_level          =>       FND_LOG.LEVEL_ERROR,
4410             p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
4411             p_table_name         =>       G_Table_name,
4412             p_context            =>       G_context,
4413             p_db_error           =>       SQLERRM,
4414             p_app_short_name     =>       'GMA'
4415             );
4416             /**************************************
4417             * Migration Failure Log Message       *
4418             **************************************/
4419             GMA_COMMON_LOGGING.gma_migration_central_log
4420             (
4421             p_run_id             =>       G_migration_run_id,
4422             p_log_level          =>       FND_LOG.LEVEL_ERROR,
4423             p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
4424             p_table_name         =>       G_Table_name,
4425             p_context            =>       G_context,
4426             p_db_error           =>       NULL,
4427             p_app_short_name     =>       'GMA'
4428             );
4429       END;
4430 
4431       BEGIN
4432         /****************************************************************************
4433         * Insert rows for Additional Lots Created as part of Lot Balances Migration *
4434         ****************************************************************************/
4435         INSERT  INTO                    gmf_lot_cost_details
4436         (
4437         header_id,
4438         detail_id,
4439         cost_cmpntcls_id,
4440         cost_analysis_code,
4441         cost_level,
4442         component_cost,
4443         burden_ind,
4444         cost_origin,
4445         frozen_ind,
4446         attribute1,
4447         attribute2,
4448         attribute3,
4449         attribute4,
4450         attribute5,
4451         attribute6,
4452         attribute7,
4453         attribute8,
4454         attribute9,
4455         attribute10,
4456         attribute11,
4457         attribute12,
4458         attribute13,
4459         attribute14,
4460         attribute15,
4461         attribute16,
4462         attribute17,
4463         attribute18,
4464         attribute19,
4465         attribute20,
4466         attribute21,
4467         attribute22,
4468         attribute23,
4469         attribute24,
4470         attribute25,
4471         attribute26,
4472         attribute27,
4473         attribute28,
4474         attribute29,
4475         attribute30,
4476         attribute_category,
4477         creation_date,
4478         created_by,
4479         last_update_date,
4480         last_updated_by,
4481         last_update_login,
4482         text_code,
4483         delete_mark,
4484         final_cost_flag
4485         )
4486         (
4487         SELECT                          b.header_id,
4488                                         gmf_cost_detail_id_s.NEXTVAL,
4489                                         a.cost_cmpntcls_id,
4490                                         a.cost_analysis_code,
4491                                         a.cost_level,
4492                                         a.component_cost,
4493                                         a.burden_ind,
4494                                         a.cost_origin,
4495                                         a.frozen_ind,
4496                                         a.attribute1,
4497                                         a.attribute2,
4498                                         a.attribute3,
4499                                         a.attribute4,
4500                                         a.attribute5,
4501                                         a.attribute6,
4502                                         a.attribute7,
4503                                         a.attribute8,
4504                                         a.attribute9,
4505                                         a.attribute10,
4506                                         a.attribute11,
4507                                         a.attribute12,
4508                                         a.attribute13,
4509                                         a.attribute14,
4510                                         a.attribute15,
4511                                         a.attribute16,
4512                                         a.attribute17,
4513                                         a.attribute18,
4514                                         a.attribute19,
4515                                         a.attribute20,
4516                                         a.attribute21,
4517                                         a.attribute22,
4518                                         a.attribute23,
4519                                         a.attribute24,
4520                                         a.attribute25,
4521                                         a.attribute26,
4522                                         a.attribute27,
4523                                         a.attribute28,
4524                                         a.attribute29,
4525                                         a.attribute30,
4526                                         a.attribute_category,
4527                                         SYSDATE,
4528                                         a.created_by,
4529                                         SYSDATE,
4530                                         a.last_updated_by,
4531                                         a.last_update_login,
4532                                         a.detail_id,
4533                                         a.delete_mark,
4534                                         a.final_cost_flag
4535         FROM                            gmf_lot_cost_details a,
4536                                         gmf_lot_costs b
4537         WHERE                           a.header_id = b.text_code
4538         AND                             b.text_code IS NOT NULL
4539         AND                             (
4540                                         (b.cost_type_id IS NOT NULL AND b.cost_mthd_code IS NULL)
4541         OR                              (b.organization_id IS NOT NULL AND b.whse_code IS NULL)
4542         OR                              (b.inventory_item_id IS NOT NULL AND b.item_id IS NULL)
4543         OR                              (b.lot_number IS NOT NULL AND b.lot_id IS NULL)
4544                                         )
4545         AND                             NOT EXISTS  (
4546                                                     SELECT            'RECORD_ALREADY_EXISTS'
4547                                                     FROM              gmf_lot_cost_details x
4548                                                     WHERE             b.header_id = x.header_id
4549                                                     )
4550         );
4551       EXCEPTION
4552          WHEN OTHERS THEN
4553             /************************************************
4554             * Increment Failure Count for Failed Migrations *
4555             ************************************************/
4556             x_failure_count := x_failure_count + 1;
4557             /**************************************
4558             * Migration DB Error Log Message      *
4559             **************************************/
4560             GMA_COMMON_LOGGING.gma_migration_central_log
4561             (
4562             p_run_id             =>       G_migration_run_id,
4563             p_log_level          =>       FND_LOG.LEVEL_ERROR,
4564             p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
4565             p_table_name         =>       G_Table_name,
4566             p_context            =>       G_context,
4567             p_db_error           =>       SQLERRM,
4568             p_app_short_name     =>       'GMA'
4569             );
4570             /**************************************
4571             * Migration Failure Log Message       *
4572             **************************************/
4573             GMA_COMMON_LOGGING.gma_migration_central_log
4574             (
4575             p_run_id             =>       G_migration_run_id,
4576             p_log_level          =>       FND_LOG.LEVEL_ERROR,
4577             p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
4578             p_table_name         =>       G_Table_name,
4579             p_context            =>       G_context,
4580             p_db_error           =>       NULL,
4581             p_app_short_name     =>       'GMA'
4582             );
4583       END;
4584 
4585 			/**********************************************
4586 			* Handle all the rows which were not migrated *
4587 			**********************************************/
4588 			gmf_migration.Log_Errors  (
4589 																p_log_level               =>          1,
4590 																p_from_rowid              =>          NULL,
4591 																p_to_rowid                =>          NULL
4592 																);
4593 
4594 			/****************************************************************
4595 			* Lets save the changes now based on the commit parameter       *
4596 			****************************************************************/
4597 
4598 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
4599 				 COMMIT;
4600 			END IF;
4601 
4602 	 EXCEPTION
4603 			WHEN OTHERS THEN
4604 
4605 				 /************************************************
4606 				 * Increment Failure Count for Failed Migrations *
4607 				 ************************************************/
4608 
4609 				 x_failure_count := x_failure_count + 1;
4610 
4611 				 /**************************************
4612 				 * Migration DB Error Log Message      *
4613 				 **************************************/
4614 
4615 				 GMA_COMMON_LOGGING.gma_migration_central_log
4616 				 (
4617 				 p_run_id             =>       G_migration_run_id,
4618 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
4619 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
4620 				 p_table_name         =>       G_Table_name,
4621 				 p_context            =>       G_context,
4622 				 p_db_error           =>       SQLERRM,
4623 				 p_app_short_name     =>       'GMA'
4624 				 );
4625 
4626 				 /**************************************
4627 				 * Migration Failure Log Message       *
4628 				 **************************************/
4629 
4630 				 GMA_COMMON_LOGGING.gma_migration_central_log
4631 				 (
4632 				 p_run_id             =>       G_migration_run_id,
4633 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
4634 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
4635 				 p_table_name         =>       G_Table_name,
4636 				 p_context            =>       G_context,
4637 				 p_db_error           =>       NULL,
4638 				 p_app_short_name     =>       'GMA'
4639 				 );
4640 
4641 	 END Migrate_Lot_Costs;
4642 
4643 	 /**********************************************************************
4644 	 * PROCEDURE:                                                          *
4645 	 *   Migrate_Lot_Costed_Items                                          *
4646 	 *                                                                     *
4647 	 * DESCRIPTION:                                                        *
4648 	 *   This PL/SQL procedure is used to migrate the Lot Costed Items     *
4649 	 *                                                                     *
4650 	 * PARAMETERS:                                                         *
4651 	 *   P_migration_run_id - id to use to right to migration log          *
4652 	 *   x_exception_count  - Number of exceptions occurred.               *
4653 	 *                                                                     *
4654 	 * SYNOPSIS:                                                           *
4655 	 *   Migrate_Lot_Costed_Items(p_migartion_id    => l_migration_id,     *
4656 	 *                    p_commit          => 'T',                        *
4657 	 *                    x_exception_count => l_exception_count );        *
4658 	 *                                                                     *
4659 	 * HISTORY                                                             *
4660 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
4661 	 *                                                                     *
4662 	 **********************************************************************/
4663 	 PROCEDURE Migrate_Lot_Costed_Items
4664 	 (
4665 	 P_migration_run_id      IN             NUMBER,
4666 	 P_commit                IN             VARCHAR2,
4667 	 X_failure_count         OUT   NOCOPY   NUMBER
4668 	 )
4669 	 IS
4670 
4671 			/**************************
4672 			* PL/SQL Table Definition *
4673 			**************************/
4674 
4675 			/******************
4676 			* Local Variables *
4677 			******************/
4678 
4679 	 BEGIN
4680 
4681 			G_Migration_run_id := P_migration_run_id;
4682 			G_Table_name := 'GMF_LOT_COSTED_ITEMS';
4683 			G_Context := 'Lot Costed Items Migration';
4684 			X_failure_count := 0;
4685 
4686 			/********************************
4687 			* Migration Started Log Message *
4688 			********************************/
4689 
4690 			GMA_COMMON_LOGGING.gma_migration_central_log
4691 			(
4692 			p_run_id             =>       G_migration_run_id,
4693 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
4694 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
4695 			p_table_name         =>       G_Table_name,
4696 			p_context            =>       G_context,
4697 			p_db_error           =>       NULL,
4698 			p_app_short_name     =>       'GMA'
4699 			);
4700 
4701 			BEGIN
4702 
4703 				 /***************************************************************
4704 				 * Update a row for cost Types, LE, Organization Id and Item Id *
4705 				 ***************************************************************/
4706 
4707 				 UPDATE      gmf_lot_costed_items a
4708 				 SET         a.cost_type_id
4709 				 =           (
4710 										 SELECT      x.cost_Type_id
4711 										 FROM        cm_mthd_mst x
4712 										 WHERE       x.cost_mthd_code = a.cost_mthd_code
4713 										 ),
4714 										 a.legal_entity_id
4715 				 =           (
4716 										 SELECT            x.legal_entity_id
4717 										 FROM              gl_plcy_mst x
4718 										 WHERE             x.co_code = a.co_code
4719 										 )
4720 				 WHERE       (a.cost_type_id IS NULL AND a.cost_mthd_code IS NOT NULL)
4721 										 OR (a.legal_entity_id IS NULL AND a.co_code IS NOT NULL);
4722 
4723 			EXCEPTION
4724 				 WHEN OTHERS THEN
4725 
4726 						/************************************************
4727 						* Increment Failure Count for Failed Migrations *
4728 						************************************************/
4729 
4730 						x_failure_count := x_failure_count + 1;
4731 
4732 						/**************************************
4733 						* Migration DB Error Log Message      *
4734 						**************************************/
4735 
4736 						GMA_COMMON_LOGGING.gma_migration_central_log
4737 						(
4738 						p_run_id             =>       G_migration_run_id,
4739 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
4740 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
4741 						p_table_name         =>       G_Table_name,
4742 						p_context            =>       G_context,
4743 						p_db_error           =>       SQLERRM,
4744 						p_app_short_name     =>       'GMA'
4745 						);
4746 
4747 						/**************************************
4748 						* Migration Failure Log Message       *
4749 						**************************************/
4750 
4751 						GMA_COMMON_LOGGING.gma_migration_central_log
4752 						(
4753 						p_run_id             =>       G_migration_run_id,
4754 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
4755 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
4756 						p_table_name         =>       G_Table_name,
4757 						p_context            =>       G_context,
4758 						p_db_error           =>       NULL,
4759 						p_app_short_name     =>       'GMA'
4760 						);
4761 
4762 			END;
4763 
4764 			BEGIN
4765 
4766 				 /***************************************************************
4767 				 * Update a row for Master_Organization Id and Item Id          *
4768 				 ***************************************************************/
4769 
4770 				 UPDATE      gmf_lot_costed_items a
4771 				 SET         (
4772 										 a.master_organization_id,
4773 										 a.inventory_item_id
4774 										 )
4775 				 =
4776 										 (
4777 										 SELECT         z.master_organization_id,
4778 																		y.inventory_item_id
4779 										 FROM           ic_item_mst_b_mig y,
4780 																		mtl_parameters z,
4781 																		hr_organization_information hoi
4782 										 WHERE          y.item_id = a.item_id
4783 										 AND            y.organization_id = z.organization_id
4784 										 AND            hoi.organization_id = z.organization_id
4785 										 AND            hoi.org_information_context = 'Accounting Information'
4786 										 AND            hoi.org_information2 = a.legal_entity_id
4787 										 AND            ROWNUM = 1
4788 										 )
4789 				 WHERE       (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
4790 				 OR          (a.master_organization_id IS NULL AND a.item_id IS NOT NULL);
4791 
4792 			EXCEPTION
4793 				 WHEN OTHERS THEN
4794 
4795 						/************************************************
4796 						* Increment Failure Count for Failed Migrations *
4797 						************************************************/
4798 
4799 						x_failure_count := x_failure_count + 1;
4800 
4801 						/**************************************
4802 						* Migration DB Error Log Message      *
4803 						**************************************/
4804 
4805 						GMA_COMMON_LOGGING.gma_migration_central_log
4806 						(
4807 						p_run_id             =>       G_migration_run_id,
4808 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
4809 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
4810 						p_table_name         =>       G_Table_name,
4811 						p_context            =>       G_context,
4812 						p_db_error           =>       SQLERRM,
4813 						p_app_short_name     =>       'GMA'
4814 						);
4815 
4816 						/**************************************
4817 						* Migration Failure Log Message       *
4818 						**************************************/
4819 
4820 						GMA_COMMON_LOGGING.gma_migration_central_log
4821 						(
4822 						p_run_id             =>       G_migration_run_id,
4823 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
4824 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
4825 						p_table_name         =>       G_Table_name,
4826 						p_context            =>       G_context,
4827 						p_db_error           =>       NULL,
4828 						p_app_short_name     =>       'GMA'
4829 						);
4830 
4831 			END;
4832 
4833 			/**********************************************
4834 			* Handle all the rows which were not migrated *
4835 			**********************************************/
4836 			gmf_migration.Log_Errors  (
4837 																p_log_level               =>          1,
4838 																p_from_rowid              =>          NULL,
4839 																p_to_rowid                =>          NULL
4840 																);
4841 
4842 			/****************************************************************
4843 			* Lets save the changes now based on the commit parameter       *
4844 			****************************************************************/
4845 
4846 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
4847 				 COMMIT;
4848 			END IF;
4849 
4850 	 EXCEPTION
4851 			WHEN OTHERS THEN
4852 
4853 				 /************************************************
4854 				 * Increment Failure Count for Failed Migrations *
4855 				 ************************************************/
4856 
4857 				 x_failure_count := x_failure_count + 1;
4858 
4859 				 /**************************************
4860 				 * Migration DB Error Log Message      *
4861 				 **************************************/
4862 
4863 				 GMA_COMMON_LOGGING.gma_migration_central_log
4864 				 (
4865 				 p_run_id             =>       G_migration_run_id,
4866 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
4867 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
4868 				 p_table_name         =>       G_Table_name,
4869 				 p_context            =>       G_context,
4870 				 p_db_error           =>       SQLERRM,
4871 				 p_app_short_name     =>       'GMA'
4872 				 );
4873 
4874 				 /**************************************
4875 				 * Migration Failure Log Message       *
4876 				 **************************************/
4877 
4878 				 GMA_COMMON_LOGGING.gma_migration_central_log
4879 				 (
4880 				 p_run_id             =>       G_migration_run_id,
4881 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
4882 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
4883 				 p_table_name         =>       G_Table_name,
4884 				 p_context            =>       G_context,
4885 				 p_db_error           =>       NULL,
4886 				 p_app_short_name     =>       'GMA'
4887 				 );
4888 
4889 	 END Migrate_Lot_Costed_Items;
4890 
4891 	 /**********************************************************************
4892 	 * PROCEDURE:                                                          *
4893 	 *   Migrate_Lot_Cost_Adjustments                                      *
4894 	 *                                                                     *
4895 	 * DESCRIPTION:                                                        *
4896 	 *   This PL/SQL procedure is used to migrate the Lot Cost Adjustments *
4897 	 *                                                                     *
4898 	 * PARAMETERS:                                                         *
4899 	 *   P_migration_run_id - id to use to right to migration log          *
4900 	 *   x_exception_count  - Number of exceptions occurred.               *
4901 	 *                                                                     *
4902 	 * SYNOPSIS:                                                           *
4903 	 *   Migrate_Lot_Cost_adjustments(p_migartion_id    => l_migration_id, *
4904 	 *                    p_commit          => 'T',                        *
4905 	 *                    x_exception_count => l_exception_count );        *
4906 	 *                                                                     *
4907 	 * HISTORY                                                             *
4908 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
4909 	 *                                                                     *
4910 	 **********************************************************************/
4911 	 PROCEDURE Migrate_Lot_Cost_Adjustments
4912 	 (
4913 	 P_migration_run_id      IN             NUMBER,
4914 	 P_commit                IN             VARCHAR2,
4915 	 X_failure_count         OUT   NOCOPY   NUMBER
4916 	 )
4917 	 IS
4918 
4919 			/**************************
4920 			* PL/SQL Table Definition *
4921 			**************************/
4922 
4923 			/******************
4924 			* Local Variables *
4925 			******************/
4926 
4927 	 BEGIN
4928 
4929 			G_Migration_run_id := P_migration_run_id;
4930 			G_Table_name := 'GMF_LOT_COST_ADJUSTMENTS';
4931 			G_Context := 'Lot Cost Adjustments Migration';
4932 			X_failure_count := 0;
4933 
4934 			/********************************
4935 			* Migration Started Log Message *
4936 			********************************/
4937 
4938 			GMA_COMMON_LOGGING.gma_migration_central_log
4939 			(
4940 			p_run_id             =>       G_migration_run_id,
4941 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
4942 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
4943 			p_table_name         =>       G_Table_name,
4944 			p_context            =>       G_context,
4945 			p_db_error           =>       NULL,
4946 			p_app_short_name     =>       'GMA'
4947 			);
4948 
4949 			BEGIN
4950 
4951 				 /**********************************************************
4952 				 * Update a row in GMF_LOT_COST_ADJUSTMENTS for cost Types *
4953 				 **********************************************************/
4954 
4955 				 UPDATE      gmf_lot_cost_adjustments a
4956 				 SET         a.cost_type_id
4957 				 =           (
4958 										 SELECT      x.cost_Type_id
4959 										 FROM        cm_mthd_mst x
4960 										 WHERE       x.cost_mthd_code = a.cost_mthd_code
4961 										 ),
4962 										 a.legal_entity_id
4963 				 =           (
4964 										 SELECT            x.legal_entity_id
4965 										 FROM              gl_plcy_mst x
4966 										 WHERE             x.co_code = a.co_code
4967 										 ),
4968 										 (
4969 										 a.organization_id,
4970 										 a.inventory_item_id
4971 										 )
4972 				 =           (
4973 										 SELECT      decode(x.cost_organization_id, -1, -1, y.organization_id),
4974 																 y.inventory_item_id
4975 										 FROM        ic_whse_mst x,
4976 																 ic_item_mst_b_mig y
4977 										 WHERE       x.whse_code = a.whse_code
4978 										 AND         y.item_id = a.item_id
4979 										 AND         y.organization_id = NVL(DECODE(x.cost_organization_id, -1, x.mtl_organization_id, x.cost_organization_id), x.mtl_organization_id)
4980 										 )
4981 				 WHERE       (
4982 										 (a.cost_type_id IS NULL AND a.cost_mthd_code IS NOT NULL)
4983 				 OR          (a.organization_id IS NULL AND a.whse_code IS NOT NULL)
4984 				 OR          (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
4985 				 OR          (a.legal_entity_id IS NULL AND a.co_code IS NOT NULL)
4986 										 );
4987 
4988 			EXCEPTION
4989 				 WHEN OTHERS THEN
4990 
4991 						/************************************************
4992 						* Increment Failure Count for Failed Migrations *
4993 						************************************************/
4994 
4995 						x_failure_count := x_failure_count + 1;
4996 
4997 						/**************************************
4998 						* Migration DB Error Log Message      *
4999 						**************************************/
5000 
5001 						GMA_COMMON_LOGGING.gma_migration_central_log
5002 						(
5003 						p_run_id             =>       G_migration_run_id,
5004 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
5005 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
5006 						p_table_name         =>       G_Table_name,
5007 						p_context            =>       G_context,
5008 						p_db_error           =>       SQLERRM,
5009 						p_app_short_name     =>       'GMA'
5010 						);
5011 
5012 						/**************************************
5013 						* Migration Failure Log Message       *
5014 						**************************************/
5015 
5016 						GMA_COMMON_LOGGING.gma_migration_central_log
5017 						(
5018 						p_run_id             =>       G_migration_run_id,
5019 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
5020 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
5021 						p_table_name         =>       G_Table_name,
5022 						p_context            =>       G_context,
5023 						p_db_error           =>       NULL,
5024 						p_app_short_name     =>       'GMA'
5025 						);
5026 
5027 			END;
5028 
5029       BEGIN
5030         /****************************************************************************
5031         * Insert rows for Additional Lots Created as part of Lot Balances Migration *
5032         ****************************************************************************/
5033         INSERT INTO             gmf_lot_cost_adjustments
5034         (
5035         adjustment_id,
5036         adjustment_date,
5037         reason_code,
5038         applied_ind,
5039         gl_posted_ind,
5040         delete_mark,
5041         text_code,
5042         created_by,
5043         creation_date,
5044         last_updated_by,
5045         last_update_login,
5046         last_update_date,
5047         attribute1,
5048         attribute2,
5049         attribute3,
5050         attribute4,
5051         attribute5,
5052         attribute6,
5053         attribute7,
5054         attribute8,
5055         attribute9,
5056         attribute10,
5057         attribute11,
5058         attribute12,
5059         attribute13,
5060         attribute14,
5061         attribute15,
5062         attribute16,
5063         attribute17,
5064         attribute18,
5065         attribute19,
5066         attribute20,
5067         attribute21,
5068         attribute22,
5069         attribute23,
5070         attribute24,
5071         attribute25,
5072         attribute26,
5073         attribute27,
5074         attribute28,
5075         attribute29,
5076         attribute30,
5077         attribute_category,
5078         onhand_qty,
5079         cost_type_id,
5080         inventory_item_id,
5081         legal_entity_id,
5082         lot_number,
5083         organization_id
5084         )
5085         (
5086         SELECT               gmf_lot_cost_adjs_id_s.NEXTVAL,
5087                              a.adjustment_date,
5088                              a.reason_code,
5089                              a.applied_ind,
5090                              a.gl_posted_ind,
5091                              a.delete_mark,
5092                              a.adjustment_id,
5093                              a.created_by,
5094                              SYSDATE,
5095                              a.last_updated_by,
5096                              a.last_update_login,
5097                              SYSDATE,
5098                              a.attribute1,
5099                              a.attribute2,
5100                              a.attribute3,
5101                              a.attribute4,
5102                              a.attribute5,
5103                              a.attribute6,
5104                              a.attribute7,
5105                              a.attribute8,
5106                              a.attribute9,
5107                              a.attribute10,
5108                              a.attribute11,
5109                              a.attribute12,
5110                              a.attribute13,
5111                              a.attribute14,
5112                              a.attribute15,
5113                              a.attribute16,
5114                              a.attribute17,
5115                              a.attribute18,
5116                              a.attribute19,
5117                              a.attribute20,
5118                              a.attribute21,
5119                              a.attribute22,
5120                              a.attribute23,
5121                              a.attribute24,
5122                              a.attribute25,
5123                              a.attribute26,
5124                              a.attribute27,
5125                              a.attribute28,
5126                              a.attribute29,
5127                              a.attribute30,
5128                              a.attribute_category,
5129                              a.onhand_qty,
5130                              a.cost_type_id,
5131                              a.inventory_item_id,
5132                              a.legal_entity_id,
5133                              b.lot_number,
5134                              a.organization_id
5135         FROM                 gmf_lot_cost_adjustments a,
5136                              ic_lots_mst_mig b
5137         WHERE                a.lot_id = b.lot_id
5138         AND                  nvl(b.additional_status_lot,0) = 1
5139         AND                  (
5140                              (a.cost_type_id IS NOT NULL AND a.cost_mthd_code IS NOT NULL)
5141         OR                   (a.organization_id IS NOT NULL AND a.whse_code IS NOT NULL)
5142         OR                   (a.inventory_item_id IS NOT NULL AND a.item_id IS NOT NULL)
5143         OR                   (a.legal_entity_id IS NOT NULL AND a.co_code IS NOT NULL)
5144                              )
5145         AND                  NOT EXISTS  (
5146                                          SELECT            'RECORD_ALREADY_EXISTS'
5147                                          FROM              gmf_lot_cost_adjustments x
5148                                          WHERE             x.legal_entity_id = a.legal_entity_id
5149                                          AND               x.organization_id = a.organization_id
5150                                          AND               x.inventory_item_id = a.inventory_item_id
5151                                          AND               x.cost_type_id = a.cost_type_id
5152                                          AND               x.lot_number = b.lot_number
5153                                          AND               x.adjustment_date = a.adjustment_date
5154                                          )
5155         );
5156       EXCEPTION
5157          WHEN OTHERS THEN
5158             /************************************************
5159             * Increment Failure Count for Failed Migrations *
5160             ************************************************/
5161             x_failure_count := x_failure_count + 1;
5162             /**************************************
5163             * Migration DB Error Log Message      *
5164             **************************************/
5165             GMA_COMMON_LOGGING.gma_migration_central_log
5166             (
5167             p_run_id             =>       G_migration_run_id,
5168             p_log_level          =>       FND_LOG.LEVEL_ERROR,
5169             p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
5170             p_table_name         =>       G_Table_name,
5171             p_context            =>       G_context,
5172             p_db_error           =>       SQLERRM,
5173             p_app_short_name     =>       'GMA'
5174             );
5175             /**************************************
5176             * Migration Failure Log Message       *
5177             **************************************/
5178             GMA_COMMON_LOGGING.gma_migration_central_log
5179             (
5180             p_run_id             =>       G_migration_run_id,
5181             p_log_level          =>       FND_LOG.LEVEL_ERROR,
5182             p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
5183             p_table_name         =>       G_Table_name,
5184             p_context            =>       G_context,
5185             p_db_error           =>       NULL,
5186             p_app_short_name     =>       'GMA'
5187             );
5188       END;
5189 
5190       BEGIN
5191         /****************************************************************************
5192         * Insert rows for Additional Lots Created as part of Lot Balances Migration *
5193         ****************************************************************************/
5194         INSERT  INTO                    gmf_lot_cost_adjustment_dtls
5195         (
5196         adjustment_dtl_id,
5197         adjustment_id,
5198         cost_cmpntcls_id,
5199         cost_analysis_code,
5200         adjustment_cost,
5201         delete_mark,
5202         text_code,
5203         created_by,
5204         creation_date,
5205         last_updated_by,
5206         last_update_login,
5207         last_update_date
5208         )
5209         (
5210         SELECT                          gmf_lot_cost_adjs_dtl_id_s.NEXTVAL,
5211                                         b.adjustment_id,
5212                                         a.cost_cmpntcls_id,
5213                                         a.cost_analysis_code,
5214                                         a.adjustment_cost,
5215                                         a.delete_mark,
5216                                         a.adjustment_dtl_id,
5217                                         a.created_by,
5218                                         SYSDATE,
5219                                         a.last_updated_by,
5220                                         a.last_update_login,
5221                                         SYSDATE
5222         FROM                            gmf_lot_cost_adjustment_dtls a,
5223                                         gmf_lot_cost_adjustments b
5224         WHERE                           a.adjustment_id = b.text_code
5225         AND                             b.text_code IS NOT NULL
5226         AND                             (
5227                                         (b.cost_type_id IS NOT NULL AND b.cost_mthd_code IS NULL)
5228         OR                              (b.organization_id IS NOT NULL AND b.whse_code IS NULL)
5229         OR                              (b.inventory_item_id IS NOT NULL AND b.item_id IS NULL)
5230         OR                              (b.legal_entity_id IS NOT NULL AND b.co_code IS NULL)
5231                                         )
5232         AND                             NOT EXISTS  (
5233                                                     SELECT            'RECORD_ALREADY_EXISTS'
5234                                                     FROM              gmf_lot_cost_adjustment_dtls x
5235                                                     WHERE             b.adjustment_id = x.adjustment_id
5236                                                     )
5237         );
5238       EXCEPTION
5239         WHEN OTHERS THEN
5240            /************************************************
5241            * Increment Failure Count for Failed Migrations *
5242            ************************************************/
5243            x_failure_count := x_failure_count + 1;
5244            /**************************************
5245            * Migration DB Error Log Message      *
5246            **************************************/
5247            GMA_COMMON_LOGGING.gma_migration_central_log
5248            (
5249            p_run_id             =>       G_migration_run_id,
5250            p_log_level          =>       FND_LOG.LEVEL_ERROR,
5251            p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
5252            p_table_name         =>       G_Table_name,
5253            p_context            =>       G_context,
5254            p_db_error           =>       SQLERRM,
5255            p_app_short_name     =>       'GMA'
5256            );
5257            /**************************************
5258            * Migration Failure Log Message       *
5259            **************************************/
5260            GMA_COMMON_LOGGING.gma_migration_central_log
5261            (
5262            p_run_id             =>       G_migration_run_id,
5263            p_log_level          =>       FND_LOG.LEVEL_ERROR,
5264            p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
5265            p_table_name         =>       G_Table_name,
5266            p_context            =>       G_context,
5267            p_db_error           =>       NULL,
5268            p_app_short_name     =>       'GMA'
5269            );
5270       END;
5271 
5272 			/**********************************************
5273 			* Handle all the rows which were not migrated *
5274 			**********************************************/
5275 			gmf_migration.Log_Errors  (
5276 																p_log_level               =>          1,
5277 																p_from_rowid              =>          NULL,
5278 																p_to_rowid                =>          NULL
5279 																);
5280 
5281 			/****************************************************************
5282 			* Lets save the changes now based on the commit parameter       *
5283 			****************************************************************/
5284 
5285 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
5286 				 COMMIT;
5287 			END IF;
5288 
5289 	 EXCEPTION
5290 			WHEN OTHERS THEN
5291 
5292 				 /************************************************
5293 				 * Increment Failure Count for Failed Migrations *
5294 				 ************************************************/
5295 
5296 				 x_failure_count := x_failure_count + 1;
5297 
5298 				 /**************************************
5299 				 * Migration DB Error Log Message      *
5300 				 **************************************/
5301 
5302 				 GMA_COMMON_LOGGING.gma_migration_central_log
5303 				 (
5304 				 p_run_id             =>       G_migration_run_id,
5305 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
5306 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
5307 				 p_table_name         =>       G_Table_name,
5308 				 p_context            =>       G_context,
5309 				 p_db_error           =>       SQLERRM,
5310 				 p_app_short_name     =>       'GMA'
5311 				 );
5312 
5313 				 /**************************************
5314 				 * Migration Failure Log Message       *
5315 				 **************************************/
5316 
5317 				 GMA_COMMON_LOGGING.gma_migration_central_log
5318 				 (
5319 				 p_run_id             =>       G_migration_run_id,
5320 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
5321 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
5322 				 p_table_name         =>       G_Table_name,
5323 				 p_context            =>       G_context,
5324 				 p_db_error           =>       NULL,
5325 				 p_app_short_name     =>       'GMA'
5326 				 );
5327 
5328 	 END Migrate_Lot_Cost_Adjustments;
5329 
5330 	 /**********************************************************************
5331 	 * PROCEDURE:                                                          *
5332 	 *   Migrate_Material_Lot_Cost_Txns                                    *
5333 	 *                                                                     *
5334 	 * DESCRIPTION:                                                        *
5335 	 *   This PL/SQL procedure is used to migrate the Lot Cost Adjustments *
5336 	 *                                                                     *
5337 	 * PARAMETERS:                                                         *
5338 	 *   P_migration_run_id - id to use to right to migration log          *
5339 	 *   x_exception_count  - Number of exceptions occurred.               *
5340 	 *                                                                     *
5341 	 * SYNOPSIS:                                                           *
5342 	 *   Migrate_Material_Lot_Cost_Txns(p_migartion_id  => l_migration_id, *
5343 	 *                    p_commit          => 'T',                        *
5344 	 *                    x_exception_count => l_exception_count );        *
5345 	 *                                                                     *
5346 	 * HISTORY                                                             *
5347 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
5348 	 *                                                                     *
5349 	 **********************************************************************/
5350 	 PROCEDURE Migrate_Material_Lot_Cost_Txns
5351 	 (
5352 	 P_migration_run_id      IN             NUMBER,
5353 	 P_commit                IN             VARCHAR2,
5354 	 X_failure_count         OUT   NOCOPY   NUMBER
5355 	 )
5356 	 IS
5357 
5358 			/**************************
5359 			* PL/SQL Table Definition *
5360 			**************************/
5361 
5362 			/******************
5363 			* Local Variables *
5364 			******************/
5365 
5366 	 BEGIN
5367 
5368 			G_Migration_run_id := P_migration_run_id;
5369 			G_Table_name := 'GMF_MATERIAL_LOT_COST_TXNS';
5370 			G_Context := 'Material Lot Cost Transactions Migration';
5371 			X_failure_count := 0;
5372 
5373 			/********************************
5374 			* Migration Started Log Message *
5375 			********************************/
5376 
5377 			GMA_COMMON_LOGGING.gma_migration_central_log
5378 			(
5379 			p_run_id             =>       G_migration_run_id,
5380 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
5381 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
5382 			p_table_name         =>       G_Table_name,
5383 			p_context            =>       G_context,
5384 			p_db_error           =>       NULL,
5385 			p_app_short_name     =>       'GMA'
5386 			);
5387 
5388 			BEGIN
5389 
5390 				 /**********************************************************
5391 				 * Update a row in GMF_MATERIAL_LOT_COST_TXNS for cost Types *
5392 				 **********************************************************/
5393 
5394 				 UPDATE      gmf_material_lot_cost_txns a
5395 				 SET         a.cost_type_id =  (
5396 																			 SELECT      x.cost_Type_id
5397 																			 FROM        cm_mthd_mst x
5398 																			 WHERE       x.cost_mthd_code = a.cost_type_code
5399 																			 ),
5400 										 a.cost_trans_um = (
5401 																			 SELECT      x.uom_Code
5402 																			 FROM        sy_uoms_mst x
5403 																			 WHERE       x.um_code = a.cost_trans_uom
5404 																			 )
5405 				 WHERE       (
5406 										 (a.cost_type_id IS NULL AND a.cost_type_code IS NOT NULL)
5407 				 OR          (a.cost_trans_um IS NULL AND a.cost_trans_uom IS NOT NULL)
5408 										 );
5409 
5410 			EXCEPTION
5411 				 WHEN OTHERS THEN
5412 
5413 						/************************************************
5414 						* Increment Failure Count for Failed Migrations *
5415 						************************************************/
5416 
5417 						x_failure_count := x_failure_count + 1;
5418 
5419 						/**************************************
5420 						* Migration DB Error Log Message      *
5421 						**************************************/
5422 
5423 						GMA_COMMON_LOGGING.gma_migration_central_log
5424 						(
5425 						p_run_id             =>       G_migration_run_id,
5426 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
5427 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
5428 						p_table_name         =>       G_Table_name,
5429 						p_context            =>       G_context,
5430 						p_db_error           =>       SQLERRM,
5431 						p_app_short_name     =>       'GMA'
5432 						);
5433 
5434 						/**************************************
5435 						* Migration Failure Log Message       *
5436 						**************************************/
5437 
5438 						GMA_COMMON_LOGGING.gma_migration_central_log
5439 						(
5440 						p_run_id             =>       G_migration_run_id,
5441 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
5442 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
5443 						p_table_name         =>       G_Table_name,
5444 						p_context            =>       G_context,
5445 						p_db_error           =>       NULL,
5446 						p_app_short_name     =>       'GMA'
5447 						);
5448 
5449 			END;
5450 
5451 			/**********************************************
5452 			* Handle all the rows which were not migrated *
5453 			**********************************************/
5454 			gmf_migration.Log_Errors  (
5455 																p_log_level               =>          1,
5456 																p_from_rowid              =>          NULL,
5457 																p_to_rowid                =>          NULL
5458 																);
5459 
5460 			/****************************************************************
5461 			* Lets save the changes now based on the commit parameter       *
5462 			****************************************************************/
5463 
5464 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
5465 				 COMMIT;
5466 			END IF;
5467 
5468 	 EXCEPTION
5469 			WHEN OTHERS THEN
5470 
5471 				 /************************************************
5472 				 * Increment Failure Count for Failed Migrations *
5473 				 ************************************************/
5474 
5475 				 x_failure_count := x_failure_count + 1;
5476 
5477 				 /**************************************
5478 				 * Migration DB Error Log Message      *
5479 				 **************************************/
5480 
5481 				 GMA_COMMON_LOGGING.gma_migration_central_log
5482 				 (
5483 				 p_run_id             =>       G_migration_run_id,
5484 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
5485 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
5486 				 p_table_name         =>       G_Table_name,
5487 				 p_context            =>       G_context,
5488 				 p_db_error           =>       SQLERRM,
5489 				 p_app_short_name     =>       'GMA'
5490 				 );
5491 
5492 				 /**************************************
5493 				 * Migration Failure Log Message       *
5494 				 **************************************/
5495 
5496 				 GMA_COMMON_LOGGING.gma_migration_central_log
5497 				 (
5498 				 p_run_id             =>       G_migration_run_id,
5499 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
5500 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
5501 				 p_table_name         =>       G_Table_name,
5502 				 p_context            =>       G_context,
5503 				 p_db_error           =>       NULL,
5504 				 p_app_short_name     =>       'GMA'
5505 				 );
5506 
5507 	 END Migrate_Material_Lot_Cost_txns;
5508 
5509 	 /**********************************************************************
5510 	 * PROCEDURE:                                                          *
5511 	 *   Migrate_Lot_Cost_Burdens                                          *
5512 	 *                                                                     *
5513 	 * DESCRIPTION:                                                        *
5514 	 *   This PL/SQL procedure is used to migrate the Lot Cost Burdens     *
5515 	 *                                                                     *
5516 	 * PARAMETERS:                                                         *
5517 	 *   P_migration_run_id - id to use to right to migration log          *
5518 	 *   x_exception_count  - Number of exceptions occurred.               *
5519 	 *                                                                     *
5520 	 * SYNOPSIS:                                                           *
5521 	 *   Migrate_Lot_Cost_Burdens(p_migartion_id    => l_migration_id,     *
5522 	 *                    p_commit          => 'T',                        *
5523 	 *                    x_exception_count => l_exception_count );        *
5524 	 *                                                                     *
5525 	 * HISTORY                                                             *
5526 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
5527 	 *                                                                     *
5528 	 **********************************************************************/
5529 	 PROCEDURE Migrate_Lot_Cost_Burdens
5530 	 (
5531 	 P_migration_run_id      IN             NUMBER,
5532 	 P_commit                IN             VARCHAR2,
5533 	 X_failure_count         OUT   NOCOPY   NUMBER
5534 	 )
5535 	 IS
5536 
5537 			/**************************
5538 			* PL/SQL Table Definition *
5539 			**************************/
5540 
5541 			/******************
5542 			* Local Variables *
5543 			******************/
5544 
5545 			/**********
5546 			* Cursors *
5547 			**********/
5548 
5549 	 BEGIN
5550 
5551 			G_Migration_run_id := P_migration_run_id;
5552 			G_Table_name := 'GMF_LOT_COST_BURDENS';
5553 			G_Context := 'Lot Cost Burdens Migration';
5554 			X_failure_count := 0;
5555 
5556 			/********************************
5557 			* Migration Started Log Message *
5558 			********************************/
5559 
5560 			GMA_COMMON_LOGGING.gma_migration_central_log
5561 			(
5562 			p_run_id             =>       G_migration_run_id,
5563 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
5564 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
5565 			p_table_name         =>       G_Table_name,
5566 			p_context            =>       G_context,
5567 			p_db_error           =>       NULL,
5568 			p_app_short_name     =>       'GMA'
5569 			);
5570 
5571 			BEGIN
5572 
5573 				 /******************************************************
5574 				 * Update a row in GMF_LOT_COST_BURDENS for cost Types *
5575 				 ******************************************************/
5576 
5577 				 UPDATE      gmf_lot_cost_burdens a
5578 				 SET         a.cost_type_id
5579 				 =           (
5580 										 SELECT      x.cost_Type_id
5581 										 FROM        cm_mthd_mst x
5582 										 WHERE       x.cost_mthd_code = a.cost_mthd_code
5583 										 ),
5584 										 a.item_uom
5585 				 =           (
5586 										 SELECT      x.uom_code
5587 										 FROM        sy_uoms_mst x
5588 										 WHERE       x.um_code = a.item_um
5589 										 ),
5590 										 a.resource_uom
5591 				 =           (
5592 										 SELECT      y.uom_code
5593 										 FROM        sy_uoms_mst y
5594 										 WHERE       y.um_code = a.resource_um
5595 										 ),
5596 										 (
5597 										 a.organization_id,
5598 										 a.inventory_item_id
5599 										 )
5600 				 =           (
5601 										 SELECT      decode(x.cost_organization_id, -1, -1, y.organization_id),
5602 																 y.inventory_item_id
5603 										 FROM        ic_whse_mst x,
5604 																 ic_item_mst_b_mig y
5605 										 WHERE       x.whse_code = a.whse_code
5606 										 AND         y.item_id = a.item_id
5607 										 AND         y.organization_id = NVL(DECODE(x.cost_organization_id, -1, x.mtl_organization_id, x.cost_organization_id), x.mtl_organization_id)
5608 										 )
5609 				 WHERE       (
5610 										 (a.cost_type_id IS NULL AND a.cost_mthd_code IS NOT NULL)
5611 				 OR          (a.item_uom IS NULL AND a.item_um IS NOT NULL)
5612 				 OR          (a.resource_uom IS NULL AND a.resource_um IS NOT NULL)
5613 				 OR          (a.organization_id IS NULL AND a.whse_code IS NOT NULL)
5614 				 OR          (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
5615 										 );
5616 
5617 			EXCEPTION
5618 				 WHEN OTHERS THEN
5619 
5620 						/************************************************
5621 						* Increment Failure Count for Failed Migrations *
5622 						************************************************/
5623 
5624 						x_failure_count := x_failure_count + 1;
5625 
5626 						/**************************************
5627 						* Migration DB Error Log Message      *
5628 						**************************************/
5629 
5630 						GMA_COMMON_LOGGING.gma_migration_central_log
5631 						(
5632 						p_run_id             =>       G_migration_run_id,
5633 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
5634 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
5635 						p_table_name         =>       G_Table_name,
5636 						p_context            =>       G_context,
5637 						p_db_error           =>       SQLERRM,
5638 						p_app_short_name     =>       'GMA'
5639 						);
5640 
5641 						/**************************************
5642 						* Migration Failure Log Message       *
5643 						**************************************/
5644 
5645 						GMA_COMMON_LOGGING.gma_migration_central_log
5646 						(
5647 						p_run_id             =>       G_migration_run_id,
5648 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
5649 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
5650 						p_table_name         =>       G_Table_name,
5651 						p_context            =>       G_context,
5652 						p_db_error           =>       NULL,
5653 						p_app_short_name     =>       'GMA'
5654 						);
5655 
5656 			END;
5657       BEGIN
5658         /****************************************************************************
5659         * Insert rows for Additional Lots Created as part of Lot Balances Migration *
5660         ****************************************************************************/
5661         INSERT INTO             gmf_lot_cost_burdens
5662         (
5663         lot_burden_line_id,
5664         resources,
5665         cost_cmpntcls_id,
5666         cost_analysis_code,
5667         start_date,
5668         end_date,
5669         resource_usage,
5670         resource_count,
5671         item_qty,
5672         burden_factor,
5673         applied_ind,
5674         delete_mark,
5675         text_code,
5676         created_by,
5677         creation_date,
5678         last_updated_by,
5679         last_update_date,
5680         last_update_login,
5681         attribute1,
5682         attribute2,
5683         attribute3,
5684         attribute4,
5685         attribute5,
5686         attribute6,
5687         attribute7,
5688         attribute8,
5689         attribute9,
5690         attribute10,
5691         attribute11,
5692         attribute12,
5693         attribute13,
5694         attribute14,
5695         attribute15,
5696         attribute16,
5697         attribute17,
5698         attribute18,
5699         attribute19,
5700         attribute20,
5701         attribute21,
5702         attribute22,
5703         attribute23,
5704         attribute24,
5705         attribute25,
5706         attribute26,
5707         attribute27,
5708         attribute28,
5709         attribute29,
5710         attribute30,
5711         attribute_category,
5712         cost_type_id,
5713         inventory_item_id,
5714         item_uom,
5715         lot_number,
5716         organization_id,
5717         resource_uom
5718         )
5719         (
5720         SELECT                GMF_LOT_BURDEN_LINE_ID_S.NEXTVAL,
5721                               a.resources,
5722                               a.cost_cmpntcls_id,
5723                               a.cost_analysis_code,
5724                               a.start_date,
5725                               a.end_date,
5726                               a.resource_usage,
5727                               a.resource_count,
5728                               a.item_qty,
5729                               a.burden_factor,
5730                               a.applied_ind,
5731                               a.delete_mark,
5732                               a.lot_burden_line_id,
5733                               a.created_by,
5734                               SYSDATE,
5735                               a.last_updated_by,
5736                               SYSDATE,
5737                               a.last_update_login,
5738                               a.attribute1,
5739                               a.attribute2,
5740                               a.attribute3,
5741                               a.attribute4,
5742                               a.attribute5,
5743                               a.attribute6,
5744                               a.attribute7,
5745                               a.attribute8,
5746                               a.attribute9,
5747                               a.attribute10,
5748                               a.attribute11,
5749                               a.attribute12,
5750                               a.attribute13,
5751                               a.attribute14,
5752                               a.attribute15,
5753                               a.attribute16,
5754                               a.attribute17,
5755                               a.attribute18,
5756                               a.attribute19,
5757                               a.attribute20,
5758                               a.attribute21,
5759                               a.attribute22,
5760                               a.attribute23,
5761                               a.attribute24,
5762                               a.attribute25,
5763                               a.attribute26,
5764                               a.attribute27,
5765                               a.attribute28,
5766                               a.attribute29,
5767                               a.attribute30,
5768                               a.attribute_category,
5769                               a.cost_type_id,
5770                               a.inventory_item_id,
5771                               a.item_uom,
5772                               b.lot_number,
5773                               a.organization_id,
5774                               a.resource_uom
5775         FROM                  gmf_lot_cost_burdens a,
5776                               ic_lots_mst_mig b
5777         WHERE                 a.lot_id = b.lot_id
5778         AND                   nvl(b.additional_status_lot,0) = 1
5779         AND                   (
5780 							                (a.cost_type_id IS NOT NULL AND a.cost_mthd_code IS NOT NULL)
5781 	      OR                    (a.item_uom IS NOT NULL AND a.item_um IS NOT NULL)
5782 		    OR                    (a.resource_uom IS NOT NULL AND a.resource_um IS NOT NULL)
5783 		    OR                    (a.organization_id IS NOT NULL AND a.whse_code IS NOT NULL)
5784 		    OR                    (a.inventory_item_id IS NOT NULL AND a.item_id IS NOT NULL)
5785 							                )
5786         AND                   NOT EXISTS  (
5787                                           SELECT            'RECORD_ALREADY_EXISTS'
5788                                           FROM              gmf_lot_cost_burdens x
5789                                           WHERE             x.organization_id = a.organization_id
5790                                           AND               x.inventory_item_id = a.inventory_item_id
5791                                           AND               x.cost_type_id = a.cost_type_id
5792                                           AND               x.lot_number = b.lot_number
5793                                           AND               x.resources = a.resources
5794                                           AND               x.cost_cmpntcls_id = a.cost_cmpntcls_id
5795                                           AND               x.cost_analysis_code = a.cost_analysis_code
5796                                           )
5797         );
5798       EXCEPTION
5799          WHEN OTHERS THEN
5800             /************************************************
5801             * Increment Failure Count for Failed Migrations *
5802             ************************************************/
5803             x_failure_count := x_failure_count + 1;
5804             /**************************************
5805             * Migration DB Error Log Message      *
5806             **************************************/
5807             GMA_COMMON_LOGGING.gma_migration_central_log
5808             (
5809             p_run_id             =>       G_migration_run_id,
5810             p_log_level          =>       FND_LOG.LEVEL_ERROR,
5811             p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
5812             p_table_name         =>       G_Table_name,
5813             p_context            =>       G_context,
5814             p_db_error           =>       SQLERRM,
5815             p_app_short_name     =>       'GMA'
5816             );
5817             /**************************************
5818             * Migration Failure Log Message       *
5819             **************************************/
5820             GMA_COMMON_LOGGING.gma_migration_central_log
5821             (
5822             p_run_id             =>       G_migration_run_id,
5823             p_log_level          =>       FND_LOG.LEVEL_ERROR,
5824             p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
5825             p_table_name         =>       G_Table_name,
5826             p_context            =>       G_context,
5827             p_db_error           =>       NULL,
5828             p_app_short_name     =>       'GMA'
5829             );
5830       END;
5831 
5832 			/**********************************************
5833 			* Handle all the rows which were not migrated *
5834 			**********************************************/
5835 			gmf_migration.Log_Errors  (
5836 																p_log_level               =>          1,
5837 																p_from_rowid              =>          NULL,
5838 																p_to_rowid                =>          NULL
5839 																);
5840 
5841 			/****************************************************************
5842 			* Lets save the changes now based on the commit parameter       *
5843 			****************************************************************/
5844 
5845 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
5846 				 COMMIT;
5847 			END IF;
5848 
5849 	 EXCEPTION
5850 			WHEN OTHERS THEN
5851 
5852 				 /************************************************
5853 				 * Increment Failure Count for Failed Migrations *
5854 				 ************************************************/
5855 
5856 				 x_failure_count := x_failure_count + 1;
5857 
5858 				 /**************************************
5859 				 * Migration DB Error Log Message      *
5860 				 **************************************/
5861 
5862 				 GMA_COMMON_LOGGING.gma_migration_central_log
5863 				 (
5864 				 p_run_id             =>       G_migration_run_id,
5865 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
5866 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
5867 				 p_table_name         =>       G_Table_name,
5868 				 p_context            =>       G_context,
5869 				 p_db_error           =>       SQLERRM,
5870 				 p_app_short_name     =>       'GMA'
5871 				 );
5872 
5873 				 /**************************************
5874 				 * Migration Failure Log Message       *
5875 				 **************************************/
5876 
5877 				 GMA_COMMON_LOGGING.gma_migration_central_log
5878 				 (
5879 				 p_run_id             =>       G_migration_run_id,
5880 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
5881 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
5882 				 p_table_name         =>       G_Table_name,
5883 				 p_context            =>       G_context,
5884 				 p_db_error           =>       NULL,
5885 				 p_app_short_name     =>       'GMA'
5886 				 );
5887 
5888 	 END Migrate_Lot_Cost_Burdens;
5889 
5890 	 /**********************************************************************
5891 	 * PROCEDURE:                                                          *
5892 	 *   Migrate_Allocation_Basis                                          *
5893 	 *                                                                     *
5894 	 * DESCRIPTION:                                                        *
5895 	 *   This PL/SQL procedure is used to migrate the Expense Allocation   *
5896 	 *   Basis Records                                                     *
5897 	 *                                                                     *
5898 	 * PARAMETERS:                                                         *
5899 	 *   P_migration_run_id - id to use to right to migration log          *
5900 	 *   x_exception_count  - Number of exceptions occurred.               *
5901 	 *                                                                     *
5902 	 * SYNOPSIS:                                                           *
5903 	 *   Migrate_Allocation_Basis(p_migartion_id    => l_migration_id,     *
5904 	 *                    p_commit          => 'T',                        *
5905 	 *                    x_exception_count => l_exception_count );        *
5906 	 *                                                                     *
5907 	 * HISTORY                                                             *
5908 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
5909 	 *                                                                     *
5910 	 **********************************************************************/
5911 	 PROCEDURE Migrate_Allocation_Basis
5912 	 (
5913 	 P_migration_run_id      IN             NUMBER,
5914 	 P_commit                IN             VARCHAR2,
5915 	 X_failure_count         OUT   NOCOPY   NUMBER
5916 	 )
5917 	 IS
5918 
5919 			/**************************
5920 			* PL/SQL Table Definition *
5921 			**************************/
5922 
5923 			/******************
5924 			* Local Variables *
5925 			******************/
5926 
5927 			l_inventory_item_id                 NUMBER;
5928 			l_itm_failure_count                 NUMBER;
5929 			l_itm_failure_count_all             NUMBER;
5930 
5931 			/**********
5932 			* Cursors *
5933 			**********/
5934 
5935 			CURSOR            cur_get_gmf_items
5936 			IS
5937 			SELECT            DISTINCT
5938 												item_id,
5939 												organization_id
5940 			FROM              (
5941 												SELECT            a.item_id,
5942 																					DECODE(NVL(b.subinventory_ind_flag,'N'), 'Y', b.organization_id, b.mtl_organization_id) organization_id
5943 												FROM              gl_aloc_bas a,
5944 																					ic_whse_mst b
5945 												WHERE             a.item_id IS NOT NULL
5946 												AND               b.whse_code = a.whse_code
5947 												);
5948 
5949 	 BEGIN
5950 
5951 			G_Migration_run_id := P_migration_run_id;
5952 			G_Table_name := 'GL_ALOC_BAS';
5953 			G_Context := 'Expense Allocation Basis Migration';
5954 			X_failure_count := 0;
5955 
5956 			/********************************
5957 			* Migration Started Log Message *
5958 			********************************/
5959 
5960 			GMA_COMMON_LOGGING.gma_migration_central_log
5961 			(
5962 			p_run_id             =>       G_migration_run_id,
5963 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
5964 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
5965 			p_table_name         =>       G_Table_name,
5966 			p_context            =>       G_context,
5967 			p_db_error           =>       NULL,
5968 			p_app_short_name     =>       'GMA'
5969 			);
5970 
5971 			/****************************************************************
5972 			* Migrating Items IN GL_ALOC_BAS table to Converged Item Master *
5973 			****************************************************************/
5974 
5975 			FOR i IN cur_get_gmf_items
5976 			LOOP
5977 				IF  i.item_id IS NOT NULL
5978 				AND i.organization_id IS NOT NULL
5979 				THEN
5980 					inv_opm_item_migration.get_odm_item
5981 					(
5982 					p_migration_run_id        =>        p_migration_run_id,
5983 					p_item_id                 =>        i.item_id,
5984 					p_organization_id         =>        i.organization_id,
5985 					p_mode                    =>        NULL,
5986 					p_commit                  =>        FND_API.G_TRUE,
5987 					x_inventory_item_id       =>        l_inventory_item_id,
5988 					x_failure_count           =>        l_itm_failure_count
5989 					);
5990 				END IF;
5991 				l_itm_failure_count_all := nvl(l_itm_failure_count_all,0) + nvl(l_itm_failure_count,0);
5992 			END LOOP;
5993 
5994 			/**********************************************************
5995 			* Update a row in GL_ALOC_BAS for Account Codes           *
5996 			**********************************************************/
5997 
5998 			BEGIN
5999 
6000 				 UPDATE      gl_aloc_bas a
6001 				 SET         a.basis_account_id
6002 				 =           (
6003 										 SELECT      gmf_migration.get_account_id(a.basis_Account_key, x.co_code)
6004 										 FROM        gl_aloc_mst x
6005 										 WHERE       x.alloc_id = a.alloc_id
6006 										 ),
6007 										 a.basis_type = decode(a.alloc_method, 0, a.basis_type, 1),
6008 										 (
6009 										 a.organization_id,
6010 										 a.inventory_item_id
6011 										 )
6012 				 =           (
6013 										 SELECT      y.organization_id,
6014 																 y.inventory_item_id
6015 										 FROM        ic_whse_mst x,
6016 																 ic_item_mst_b_mig y
6017 										 WHERE       x.whse_code = a.whse_code
6018 										 AND         y.item_id = a.item_id
6019 										 AND         y.organization_id = DECODE(NVL(x.subinventory_ind_flag, 'N'), 'Y', x.organization_id, x.mtl_organization_id)
6020 										 )
6021 				 WHERE       (
6022 										 (a.basis_account_key IS NOT NULL AND a.basis_account_id IS NULL)
6023 				 OR          (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
6024 				 OR          (a.organization_id IS NULL AND a.whse_code IS NOT NULL)
6025 										 );
6026 
6027 			EXCEPTION
6028 				 WHEN OTHERS THEN
6029 
6030 						/************************************************
6031 						* Increment Failure Count for Failed Migrations *
6032 						************************************************/
6033 
6034 						x_failure_count := x_failure_count + 1;
6035 
6036 						/**************************************
6037 						* Migration DB Error Log Message      *
6038 						**************************************/
6039 
6040 						GMA_COMMON_LOGGING.gma_migration_central_log
6041 						(
6042 						p_run_id             =>       G_migration_run_id,
6043 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
6044 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
6045 						p_table_name         =>       G_Table_name,
6046 						p_context            =>       G_context,
6047 						p_db_error           =>       SQLERRM,
6048 						p_app_short_name     =>       'GMA'
6049 						);
6050 
6051 						/**************************************
6052 						* Migration Failure Log Message       *
6053 						**************************************/
6054 
6055 						GMA_COMMON_LOGGING.gma_migration_central_log
6056 						(
6057 						p_run_id             =>       G_migration_run_id,
6058 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
6059 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
6060 						p_table_name         =>       G_Table_name,
6061 						p_context            =>       G_context,
6062 						p_db_error           =>       NULL,
6063 						p_app_short_name     =>       'GMA'
6064 						);
6065 
6066 			END;
6067 
6068 			/**********************************************
6069 			* Handle all the rows which were not migrated *
6070 			**********************************************/
6071 
6072 			SELECT               count(*)
6073 			INTO                 x_failure_count
6074 			FROM                 gl_aloc_bas
6075 			WHERE                (
6076 													 (basis_account_key IS NOT NULL AND basis_account_id IS NULL)
6077 			OR                   (inventory_item_id IS NULL AND item_id IS NOT NULL)
6078 			OR                   (organization_id IS NULL AND whse_code IS NOT NULL)
6079 													 );
6080 
6081 			IF nvl(x_failure_count,0) > 0 THEN
6082 
6083 				/**************************************
6084 				* Migration Failure Log Message       *
6085 				**************************************/
6086 
6087 				GMA_COMMON_LOGGING.gma_migration_central_log
6088 				(
6089 				p_run_id             =>       gmf_migration.G_migration_run_id,
6090 				p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
6091 				p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
6092 				p_table_name         =>       gmf_migration.G_Table_name,
6093 				p_context            =>       gmf_migration.G_context,
6094 				p_db_error           =>       NULL,
6095 				p_app_short_name     =>       'GMA'
6096 				);
6097 
6098 			ELSE
6099 
6100 				/**************************************
6101 				* Migration Success Log Message       *
6102 				**************************************/
6103 
6104 				GMA_COMMON_LOGGING.gma_migration_central_log
6105 				(
6106 				p_run_id             =>       G_migration_run_id,
6107 				p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
6108 				p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
6109 				p_table_name         =>       G_Table_name,
6110 				p_context            =>       G_Context,
6111 				p_param1             =>       1,
6112 				p_param2             =>       0,
6113 				p_db_error           =>       NULL,
6114 				p_app_short_name     =>       'GMA'
6115 				);
6116 
6117 			END IF;
6118 
6119 			/****************************************************************
6120 			* Lets save the changes now based on the commit parameter       *
6121 			****************************************************************/
6122 
6123 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
6124 				 COMMIT;
6125 			END IF;
6126 
6127 	 EXCEPTION
6128 			WHEN OTHERS THEN
6129 
6130 				 /************************************************
6131 				 * Increment Failure Count for Failed Migrations *
6132 				 ************************************************/
6133 
6134 				 x_failure_count := x_failure_count + 1;
6135 
6136 				 /**************************************
6137 				 * Migration DB Error Log Message      *
6138 				 **************************************/
6139 
6140 				 GMA_COMMON_LOGGING.gma_migration_central_log
6141 				 (
6142 				 p_run_id             =>       G_migration_run_id,
6143 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
6144 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
6145 				 p_table_name         =>       G_Table_name,
6146 				 p_context            =>       G_context,
6147 				 p_db_error           =>       SQLERRM,
6148 				 p_app_short_name     =>       'GMA'
6149 				 );
6150 
6151 				 /**************************************
6152 				 * Migration Failure Log Message       *
6153 				 **************************************/
6154 
6155 				 GMA_COMMON_LOGGING.gma_migration_central_log
6156 				 (
6157 				 p_run_id             =>       G_migration_run_id,
6158 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
6159 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
6160 				 p_table_name         =>       G_Table_name,
6161 				 p_context            =>       G_context,
6162 				 p_db_error           =>       NULL,
6163 				 p_app_short_name     =>       'GMA'
6164 				 );
6165 
6166 	 END Migrate_Allocation_Basis;
6167 
6168 	 /**********************************************************************
6169 	 * PROCEDURE:                                                          *
6170 	 *   Migrate_Allocation_Expenses                                       *
6171 	 *                                                                     *
6172 	 * DESCRIPTION:                                                        *
6173 	 *   This PL/SQL procedure is used to migrate the Expense Allocation   *
6174 	 *   Expenses Records                                                  *
6175 	 *                                                                     *
6176 	 * PARAMETERS:                                                         *
6177 	 *   P_migration_run_id - id to use to right to migration log          *
6178 	 *   x_exception_count  - Number of exceptions occurred.               *
6179 	 *                                                                     *
6180 	 * SYNOPSIS:                                                           *
6181 	 *   Migrate_Allocation_Expenses(p_migartion_id    => l_migration_id,  *
6182 	 *                    p_commit          => 'T',                        *
6183 	 *                    x_exception_count => l_exception_count );        *
6184 	 *                                                                     *
6185 	 * HISTORY                                                             *
6186 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
6187 	 *                                                                     *
6188 	 **********************************************************************/
6189 	 PROCEDURE Migrate_Allocation_Expenses
6190 	 (
6191 	 P_migration_run_id      IN             NUMBER,
6192 	 P_commit                IN             VARCHAR2,
6193 	 X_failure_count         OUT   NOCOPY   NUMBER
6194 	 )
6195 	 IS
6196 
6197 			/***************************
6198 			* PL/SQL Table Definitions *
6199 			***************************/
6200 
6201 			/******************
6202 			* Local Variables *
6203 			******************/
6204 
6205 	 BEGIN
6206 
6207 			G_Migration_run_id := P_migration_run_id;
6208 			G_Table_name := 'GL_ALOC_EXP';
6209 			G_Context := 'Expense Allocation Expenses Migration';
6210 			X_failure_count := 0;
6211 
6212 			/********************************
6213 			* Migration Started Log Message *
6214 			********************************/
6215 
6216 			GMA_COMMON_LOGGING.gma_migration_central_log
6217 			(
6218 			p_run_id             =>       G_migration_run_id,
6219 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
6220 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
6221 			p_table_name         =>       G_Table_name,
6222 			p_context            =>       G_context,
6223 			p_db_error           =>       NULL,
6224 			p_app_short_name     =>       'GMA'
6225 			);
6226 
6227 
6228 			/**********************************************************
6229 			* Update a row in GL_ALOC_EXP for Account Codes           *
6230 			**********************************************************/
6231 
6232 			BEGIN
6233 				 UPDATE         gl_aloc_exp a
6234 				 SET            (
6235 												a.from_account_id,
6236 												a.to_account_id
6237 												)
6238 				 =              (
6239 												SELECT      gmf_migration.get_account_id(a.from_account, x.co_code),
6240 																		gmf_migration.get_account_id(a.to_account, x.co_code)
6241 												FROM        gl_aloc_mst x
6242 												WHERE       x.alloc_id = a.alloc_id
6243 												)
6244 				 WHERE          (
6245 												(from_account_id IS NULL AND from_account IS NOT NULL)
6246 				 OR             (to_account_id IS NULL AND to_account IS NOT NULL)
6247 												);
6248 
6249 			EXCEPTION
6250 				 WHEN OTHERS THEN
6251 
6252 						/************************************************
6253 						* Increment Failure Count for Failed Migrations *
6254 						************************************************/
6255 
6256 						x_failure_count := x_failure_count + 1;
6257 
6258 						/**************************************
6259 						* Migration DB Error Log Message      *
6260 						**************************************/
6261 
6262 						GMA_COMMON_LOGGING.gma_migration_central_log
6263 						(
6264 						p_run_id             =>       G_migration_run_id,
6265 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
6266 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
6267 						p_table_name         =>       G_Table_name,
6268 						p_context            =>       G_context,
6269 						p_db_error           =>       SQLERRM,
6270 						p_app_short_name     =>       'GMA'
6271 						);
6272 
6273 						/**************************************
6274 						* Migration Failure Log Message       *
6275 						**************************************/
6276 
6277 						GMA_COMMON_LOGGING.gma_migration_central_log
6278 						(
6279 						p_run_id             =>       G_migration_run_id,
6280 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
6281 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
6282 						p_table_name         =>       G_Table_name,
6283 						p_context            =>       G_context,
6284 						p_db_error           =>       NULL,
6285 						p_app_short_name     =>       'GMA'
6286 						);
6287 
6288 			END;
6289 
6290 			/**********************************************
6291 			* Handle all the rows which were not migrated *
6292 			**********************************************/
6293 
6294 			SELECT               count(*)
6295 			INTO                 x_failure_count
6296 			FROM                 gl_aloc_exp
6297 			WHERE                (
6298 													 (from_account_id IS NULL AND from_account IS NOT NULL)
6299 			OR                   (to_account_id IS NULL AND to_account IS NOT NULL)
6300 													 );
6301 
6302 			IF nvl(x_failure_count,0) > 0 THEN
6303 
6304 				/**************************************
6305 				* Migration Failure Log Message       *
6306 				**************************************/
6307 
6308 				GMA_COMMON_LOGGING.gma_migration_central_log
6309 				(
6310 				p_run_id             =>       gmf_migration.G_migration_run_id,
6311 				p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
6312 				p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
6313 				p_table_name         =>       gmf_migration.G_Table_name,
6314 				p_context            =>       gmf_migration.G_context,
6315 				p_db_error           =>       NULL,
6316 				p_app_short_name     =>       'GMA'
6317 				);
6318 
6319 			ELSE
6320 
6321 				/**************************************
6322 				* Migration Success Log Message       *
6323 				**************************************/
6324 
6325 				GMA_COMMON_LOGGING.gma_migration_central_log
6326 				(
6327 				p_run_id             =>       G_migration_run_id,
6328 				p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
6329 				p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
6330 				p_table_name         =>       G_Table_name,
6331 				p_context            =>       G_Context,
6332 				p_param1             =>       1,
6333 				p_param2             =>       0,
6334 				p_db_error           =>       NULL,
6335 				p_app_short_name     =>       'GMA'
6336 				);
6337 
6338 			END IF;
6339 
6340 			/****************************************************************
6341 			* Lets save the changes now based on the commit parameter       *
6342 			****************************************************************/
6343 
6344 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
6345 				 COMMIT;
6346 			END IF;
6347 
6348 	 EXCEPTION
6349 
6350 			WHEN OTHERS THEN
6351 
6352 				 /************************************************
6353 				 * Increment Failure Count for Failed Migrations *
6354 				 ************************************************/
6355 
6356 				 x_failure_count := x_failure_count + 1;
6357 
6358 				 /**************************************
6359 				 * Migration DB Error Log Message      *
6360 				 **************************************/
6361 
6362 				 GMA_COMMON_LOGGING.gma_migration_central_log
6363 				 (
6364 				 p_run_id             =>       G_migration_run_id,
6365 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
6366 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
6367 				 p_table_name         =>       G_Table_name,
6368 				 p_context            =>       G_context,
6369 				 p_param1             =>       NULL,
6370 				 p_param2             =>       NULL,
6371 				 p_db_error           =>       SQLERRM,
6372 				 p_app_short_name     =>       'GMA'
6373 				 );
6374 
6375 				 /**************************************
6376 				 * Migration Failure Log Message       *
6377 				 **************************************/
6378 
6379 				 GMA_COMMON_LOGGING.gma_migration_central_log
6380 				 (
6381 				 p_run_id             =>       G_migration_run_id,
6382 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
6383 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
6384 				 p_table_name         =>       G_Table_name,
6385 				 p_context            =>       G_context,
6386 				 p_db_error           =>       NULL,
6387 				 p_app_short_name     =>       'GMA'
6388 				 );
6389 
6390 	 END Migrate_Allocation_Expenses;
6391 
6392 	 /**********************************************************************
6393 	 * PROCEDURE:                                                          *
6394 	 *   Migrate_Account_Mappings                                          *
6395 	 *                                                                     *
6396 	 * DESCRIPTION:                                                        *
6397 	 *   This PL/SQL procedure is used to migrate the Account Mappings from*
6398 	 *   OPM Data model to SLA ADR Model                                   *
6399 	 *                                                                     *
6400 	 * PARAMETERS:                                                         *
6401 	 *   P_migration_run_id - id to use to right to migration log          *
6402 	 *   x_exception_count  - Number of exceptions occurred.               *
6403 	 *                                                                     *
6404 	 * SYNOPSIS:                                                           *
6405 	 *   Migrate_Account_Mappings(p_migartion_id => l_migration_id,        *
6406 	 *                    p_commit          => 'T',                        *
6407 	 *                    x_exception_count => l_exception_count );        *
6408 	 *                                                                     *
6409 	 * HISTORY                                                             *
6410 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
6411 	 *                                                                     *
6412 	 **********************************************************************/
6413 	 PROCEDURE Migrate_Account_Mappings
6414 	 (
6415 	 P_migration_run_id      IN             NUMBER,
6416 	 P_commit                IN             VARCHAR2,
6417 	 X_failure_count         OUT   NOCOPY   NUMBER
6418 	 )
6419 	 IS
6420 
6421 			/**************************
6422 			* PL/SQL Table Definition *
6423 			**************************/
6424 
6425 			TYPE my_order_tbl IS TABLE OF NUMBER(2) INDEX BY BINARY_INTEGER;
6426 			TYPE t_event_class_code IS TABLE OF VARCHAR2(30) INDEX BY VARCHAR2(4);
6427 			TYPE t_event_type_code IS TABLE OF VARCHAR2(30) INDEX BY VARCHAR2(4);
6428 
6429 			TYPE t_co_code IS TABLE OF GL_ACCT_MAP.CO_CODE%TYPE INDEX BY BINARY_INTEGER;
6430 			TYPE t_orgn_code IS TABLE OF GL_ACCT_MAP.ORGN_CODE%TYPE INDEX BY BINARY_INTEGER;
6431 			TYPE t_whse_code IS TABLE OF GL_ACCT_MAP.WHSE_CODE%TYPE INDEX BY BINARY_INTEGER;
6432 			TYPE t_item_id IS TABLE OF GL_ACCT_MAP.ITEM_ID%TYPE INDEX BY BINARY_INTEGER;
6433 			TYPE t_vendor_id IS TABLE OF GL_ACCT_MAP.VENDOR_ID%TYPE INDEX BY BINARY_INTEGER;
6434 			TYPE t_cust_id IS TABLE OF GL_ACCT_MAP.CUST_ID%TYPE INDEX BY BINARY_INTEGER;
6435 			TYPE t_reason_code IS TABLE OF GL_ACCT_MAP.REASON_CODE%TYPE INDEX BY BINARY_INTEGER;
6436 			TYPE t_gl_category_id IS TABLE OF GL_ACCT_MAP.GL_CATEGORY_ID%TYPE INDEX BY BINARY_INTEGER;
6437 			TYPE t_vendgl_class IS TABLE OF GL_ACCT_MAP.VENDGL_CLASS%TYPE INDEX BY BINARY_INTEGER;
6438 			TYPE t_custgl_class IS TABLE OF GL_ACCT_MAP.CUSTGL_CLASS%TYPE INDEX BY BINARY_INTEGER;
6439 			TYPE t_currency_code IS TABLE OF GL_ACCT_MAP.CURRENCY_CODE%TYPE INDEX BY BINARY_INTEGER;
6440 			TYPE t_routing_id IS TABLE OF GL_ACCT_MAP.ROUTING_ID%TYPE INDEX BY BINARY_INTEGER;
6441 			TYPE t_charge_id IS TABLE OF GL_ACCT_MAP.CHARGE_ID%TYPE INDEX BY BINARY_INTEGER;
6442 			TYPE t_taxauth_id IS TABLE OF GL_ACCT_MAP.TAXAUTH_ID%TYPE INDEX BY BINARY_INTEGER;
6443 			TYPE t_acct_id IS TABLE OF GL_ACCT_MAP.ACCT_ID%TYPE INDEX BY BINARY_INTEGER;
6444 			TYPE t_aqui_cost_id IS TABLE OF GL_ACCT_MAP.AQUI_COST_ID%TYPE INDEX BY BINARY_INTEGER;
6445 			TYPE t_resources IS TABLE OF GL_ACCT_MAP.RESOURCES%TYPE INDEX BY BINARY_INTEGER;
6446 			TYPE t_cost_cmpntcls_id IS TABLE OF GL_ACCT_MAP.COST_CMPNTCLS_ID%TYPE INDEX BY BINARY_INTEGER;
6447 			TYPE t_cost_analysis_code IS TABLE OF GL_ACCT_MAP.COST_ANALYSIS_CODE%TYPE INDEX BY BINARY_INTEGER;
6448 			TYPE t_order_type IS TABLE OF GL_ACCT_MAP.ORDER_TYPE%TYPE INDEX BY BINARY_INTEGER;
6449 			TYPE t_gl_business_class_cat_id IS TABLE OF GL_ACCT_MAP.GL_BUSINESS_CLASS_CAT_ID%TYPE INDEX BY BINARY_INTEGER;
6450 			TYPE t_gl_product_line_cat_id IS TABLE OF GL_ACCT_MAP.GL_PRODUCT_LINE_CAT_ID%TYPE INDEX BY BINARY_INTEGER;
6451 			TYPE t_line_type IS TABLE OF GL_ACCT_MAP.LINE_TYPE%TYPE INDEX BY BINARY_INTEGER;
6452 			TYPE t_ar_trx_type_id IS TABLE OF GL_ACCT_MAP.AR_TRX_TYPE_ID%TYPE INDEX BY BINARY_INTEGER;
6453 			TYPE t_rowid IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
6454 			TYPE t_inventory_org_ind IS TABLE OF SY_ORGN_MST.INVENTORY_ORG_IND%TYPE INDEX BY BINARY_INTEGER;
6455 			TYPE t_organization_id IS TABLE OF SY_ORGN_MST.ORGANIZATION_ID%TYPE INDEX BY BINARY_INTEGER;
6456 			TYPE t_mtl_organization_id IS TABLE OF IC_WHSE_MST.MTL_ORGANIZATION_ID%TYPE INDEX BY BINARY_INTEGER;
6457 			TYPE t_subinventory_ind_flag IS TABLE OF IC_WHSE_MST.SUBINVENTORY_IND_FLAG%TYPE INDEX BY BINARY_INTEGER;
6458 			TYPE t_acct_no IS TABLE OF GL_ACCT_MST.ACCT_NO%TYPE INDEX BY BINARY_INTEGER;
6459 			TYPE t_source_type IS TABLE OF GL_ACCT_MAP.SOURCE_TYPE%TYPE INDEX BY BINARY_INTEGER;
6460 
6461 			/******************
6462 			* Local Variables *
6463 			******************/
6464 
6465 			l_legal_entity_id             GMF_FISCAL_POLICIES.LEGAL_ENTITY_ID%TYPE;
6466 			l_adr_priority                NUMBER := 10;
6467 			l_adr_condition_priority      NUMBER := 10;
6468 			l_old_adr_condition_priority  NUMBER := 10;
6469 			l_adr_rule_code               VARCHAR2(30);
6470 			l_adr_rule_name               VARCHAR2(80);
6471 			l_acctg_unit_count            NUMBER;
6472 			l_segment_value               VARCHAR2(240);
6473 
6474 			X_sqlstmt                     VARCHAR2(32000);
6475 			X_sqlwhere                    VARCHAR2(32000);
6476 			X_my_order_by                 VARCHAR2(200);
6477 			X_sqlcolumns                  VARCHAR2(32000);
6478 			X_sqlordby                    VARCHAR2(32000);
6479 			X_tmp1                        NUMBER(10);
6480 			X_cursor_handle               INTEGER;
6481 			X_var_col                     VARCHAR2(32000);
6482 			X_rows_processed              NUMBER(15);
6483 
6484 			x_order_tbl                   my_order_tbl;
6485 
6486 			l_inventory_item_id           MTL_SYSTEM_ITEMS_B.inventory_item_id%TYPE;
6487 			l_item                        MTL_ITEM_FLEXFIELDS.item_number%TYPE;
6488 			l_customer_no                 OP_CUST_MST.cust_no%TYPE;
6489 			l_vendor_site_id              PO_VEND_MST.of_vendor_site_id%TYPE;
6490 			l_taxauth_code                TX_TAXA_MST.taxauth_code%TYPE;
6491 			l_Charge_code                 OP_CHRG_MST.Charge_code%TYPE;
6492 			l_routing_no                  GMD_ROUTINGS_B.routing_no%TYPE;
6493 			l_routing_vers                GMD_ROUTINGS_B.routing_vers%TYPE;
6494 			l_price_element_type_id       PO_COST_MST.price_element_type_id%TYPE;
6495 			l_cost_cmpntcls_code          CM_CMPT_MST.cost_cmpntcls_code%TYPE;
6496 			l_Order_type_code             OP_ORDR_TYP.Order_type_code%TYPE;
6497 			l_Line_type_code              GEM_LOOKUPS.meaning%TYPE;
6498 			l_ar_trx_type_code            RA_CUST_TRX_TYPES_ALL.name%TYPE;
6499 
6500 			l_co_code                     t_co_code;
6501 			l_orgn_code                   t_orgn_code;
6502 			l_whse_code                   t_whse_code;
6503 			l_item_id                     t_item_id;
6504 			l_vendor_id                   t_vendor_id;
6505 			l_cust_id                     t_cust_id;
6506 			l_reason_code                 t_reason_code;
6507 			l_gl_category_id              t_gl_category_id;
6508 			l_vendgl_class                t_vendgl_class;
6509 			l_custgl_class                t_custgl_class;
6510 			l_currency_code               t_currency_code;
6511 			l_routing_id                  t_routing_id;
6512 			l_charge_id                   t_charge_id;
6513 			l_taxauth_id                  t_taxauth_id;
6514 			l_acct_id                     t_acct_id;
6515 			l_aqui_cost_id                t_aqui_cost_id;
6516 			l_resources                   t_resources;
6517 			l_cost_cmpntcls_id            t_cost_cmpntcls_id;
6518 			l_cost_analysis_code          t_cost_analysis_code;
6519 			l_order_type                  t_order_type;
6520 			l_gl_business_class_cat_id    t_gl_business_class_cat_id;
6521 			l_gl_product_line_cat_id      t_gl_product_line_cat_id;
6522 			l_line_type                   t_line_type;
6523 			l_ar_trx_type_id              t_ar_trx_type_id;
6524 			l_rowid                       t_rowid;
6525 			l_acct_no                     t_acct_no;
6526 			l_inventory_org_ind           t_inventory_org_ind;
6527 			l_subinventory_ind_flag       t_subinventory_ind_flag;
6528 			l_source_type                 t_source_type;
6529 			l_organization_id             t_organization_id;
6530 			l_mtl_organization_id         t_mtl_organization_id;
6531 
6532 			l_orgn_code_pri               GL_ACCT_HRC.ORGN_CODE_PRI%TYPE := 0;
6533 			l_whse_code_pri               GL_ACCT_HRC.WHSE_CODE_PRI%TYPE := 0;
6534 			l_item_pri                    GL_ACCT_HRC.ITEM_PRI%TYPE := 0;
6535 			l_vendor_pri                  GL_ACCT_HRC.VENDOR_PRI%TYPE := 0;
6536 			l_customer_pri                GL_ACCT_HRC.CUSTOMER_PRI%TYPE := 0;
6537 			l_reason_code_pri             GL_ACCT_HRC.REASON_CODE_PRI%TYPE := 0;
6538 			l_icgl_class_pri              GL_ACCT_HRC.ICGL_CLASS_PRI%TYPE := 0;
6539 			l_vendgl_class_pri            GL_ACCT_HRC.VENDGL_CLASS_PRI%TYPE := 0;
6540 			l_custgl_class_pri            GL_ACCT_HRC.CUSTGL_CLASS_PRI%TYPE := 0;
6541 			l_currency_code_pri           GL_ACCT_HRC.CURRENCY_CODE_PRI%TYPE := 0;
6542 			l_routing_pri                 GL_ACCT_HRC.ROUTING_PRI%TYPE := 0;
6543 			l_charge_pri                  GL_ACCT_HRC.CHARGE_PRI%TYPE := 0;
6544 			l_tax_auth_pri                GL_ACCT_HRC.TAX_AUTH_PRI%TYPE := 0;
6545 			l_aqui_cost_code_pri          GL_ACCT_HRC.AQUI_COST_CODE_PRI%TYPE := 0;
6546 			l_resource_pri                GL_ACCT_HRC.RESOURCE_PRI%TYPE := 0;
6547 			l_cost_cmpntcls_pri           GL_ACCT_HRC.COST_CMPNTCLS_PRI%TYPE := 0;
6548 			l_cost_analysis_pri           GL_ACCT_HRC.COST_ANALYSIS_PRI%TYPE := 0;
6549 			l_order_type_pri              GL_ACCT_HRC.ORDER_TYPE_PRI%TYPE := 0;
6550 			l_gl_business_class_pri       GL_ACCT_HRC.GL_BUSINESS_CLASS_PRI%TYPE := 0;
6551 			l_gl_product_line_pri         GL_ACCT_HRC.GL_PRODUCT_LINE_PRI%TYPE := 0;
6552 			l_line_type_pri               GL_ACCT_HRC.LINE_TYPE_PRI%TYPE := 0;
6553 			l_ar_trx_type_pri             GL_ACCT_HRC.AR_TRX_TYPE_PRI%TYPE := 0;
6554 			l_co_code1                    GL_ACCT_HRC.CO_CODE%TYPE;
6555 
6556 			l_reason_id                   MTL_TRANSACTION_REASONS.REASON_ID%TYPE;
6557 			l_row_id                      ROWID;
6558 
6559 			xct                           PLS_INTEGER := 1;
6560 			xrt                           PLS_INTEGER := 1;
6561 			xlat                          PLS_INTEGER := 1;
6562 			xrdt                          PLS_INTEGER := 1;
6563 			mcnt                          PLS_INTEGER := 1;
6564 			l_event_class_code            t_event_class_code;
6565 			l_event_type_code             t_event_type_code;
6566 			l_segment_rule_detail_id      NUMBER(38);
6567 			l_old_segment_rule_detail_id  NUMBER(38);
6568 			l_amb_context                 VARCHAR2(30);
6569 
6570 			/**********
6571 			* Cursors *
6572 			**********/
6573 
6574 			CURSOR               cur_legal_entities
6575 			IS
6576 			SELECT               a.legal_entity_id,
6577 													 d.organization_code,
6578 													 c.legal_entity_name organization_name,
6579 													 b.segment_delimiter,
6580 													 b.co_code,
6581 													 e.chart_of_accounts_id,
6582 													 e.short_name,
6583 													 e.name,
6584 													 e.ledger_id
6585 			FROM                 gmf_fiscal_policies a,
6586 													 gl_plcy_mst b,
6587 													 gmf_legal_entities c,
6588 													 mtl_parameters d,
6589 													 gl_ledgers e
6590 			WHERE                a.legal_entity_id = b.legal_entity_id
6591 			AND                  c.legal_entity_id = a.legal_entity_id
6592 			AND                  d.organization_id(+) = c.legal_entity_id
6593 			AND                  e.ledger_id = a.ledger_id
6594 			ORDER BY             a.legal_entity_id;
6595 
6596 			CURSOR               cur_account_title
6597 			IS
6598 			SELECT               DISTINCT
6599 													 DECODE(acct_ttl_code, 'PCO', 'COGS', 'IPF', 'IOPR', 'XFC', 'XTC', acct_ttl_code) acct_ttl_code,
6600 													 DECODE(acct_ttl_code, 'PCO', 'Cost of Goods Sold' , 'IPF', 'Inter-Org Profit', 'XFC', 'Inter-org Transfer Credit', acct_ttl_desc) acct_ttl_desc,
6601 													 acct_ttl_type
6602 			FROM                 gl_acct_ttl
6603 			ORDER BY             acct_ttl_code;
6604 
6605 			CURSOR               cur_plcy_seg
6606 			(
6607 			p_co_code           IN                VARCHAR2,
6608 			p_coa_id            IN                NUMBER
6609 			)
6610 			IS
6611 			SELECT               a.segment_no,
6612 													 a.type,
6613 													 b.segment_name short_name,
6614 													 b.application_column_name,
6615 													 c.id_flex_structure_code structure_code,
6616 													 c.id_flex_structure_name structure_name
6617 			FROM                 gl_plcy_seg a,
6618 													 fnd_id_flex_segments b,
6619 													 fnd_id_flex_structures_vl c
6620 			WHERE                a.co_code = p_co_code
6621 			AND                  b.segment_num = a.segment_ref
6622 			AND                  b.id_flex_num = p_coa_id
6623 			AND                  b.enabled_flag = 'Y'
6624 			AND                  b.id_flex_code = 'GL#'
6625 			AND                  b.application_id = 101
6626 			AND                  c.application_id = b.application_id
6627 			AND                  c.id_flex_code = b.id_flex_code
6628 			AND                  c.id_flex_num = b.id_flex_num
6629 			ORDER BY             a.type,
6630 													 a.segment_no;
6631 
6632 			CURSOR               cur_account_unit_map
6633 			(
6634 			p_co_code           IN                VARCHAR2
6635 			)
6636 			IS
6637 			SELECT               a.co_code,
6638 													 a.orgn_code,
6639 													 NVL(c.inventory_org_ind,'N') inventory_org_ind,
6640 													 c.organization_id,
6641 													 a.whse_code,
6642 													 NVL(d.subinventory_ind_flag,'N') subinventory_ind_flag,
6643 													 d.mtl_organization_id,
6644 													 b.acctg_unit_id,
6645 													 b.acctg_unit_no,
6646 													 a.accu_map_id
6647 			FROM                 gl_accu_map a,
6648 													 gl_accu_mst b,
6649 													 sy_orgn_mst c,
6650 													 ic_whse_mst d
6651 			WHERE                a.co_code = p_co_code
6652 			AND                  b.acctg_unit_id = a.acctg_unit_id
6653 			AND                  c.orgn_code(+) = a.orgn_code
6654 			AND                  d.whse_code(+) = a.whse_code
6655 		  AND                  nvl(a.migrated_ind,0) <> 1
6656 			ORDER BY             a.co_code,
6657 													 a.orgn_code NULLS LAST,
6658 													 a.whse_code NULLS LAST;
6659 
6660 			CURSOR               cur_whse_accu
6661 			(
6662 			p_orgn_code          IN                   VARCHAR2,
6663 			p_co_code            IN                   VARCHAR2,
6664 			p_acctg_unit_id      IN                   VARCHAR2
6665 			)
6666 			IS
6667 			SELECT               a.whse_code,
6668 													 a.whse_name,
6669 													 NVL(a.subinventory_ind_flag,'N') subinventory_ind_flag,
6670 													 a.mtl_organization_id
6671 			FROM                 ic_whse_mst a
6672 			WHERE                a.orgn_code = p_orgn_code
6673 			AND                  NOT EXISTS
6674 																		(
6675 																		SELECT      'X'
6676 																		FROM        gl_accu_map x
6677 																		WHERE       x.whse_code = a.whse_code
6678 																		AND         x.co_code = p_co_code
6679 																		AND         x.orgn_code = a.orgn_code
6680 																		AND         x.acctg_unit_id = p_acctg_unit_id
6681 																		)
6682 			ORDER BY             a.whse_code;
6683 
6684 			CURSOR               cur_whse_acct
6685 			(
6686 			p_orgn_code          IN                   VARCHAR2,
6687 			p_co_code            IN                   VARCHAR2,
6688 			p_acct_id            IN                   VARCHAR2
6689 			)
6690 			IS
6691 			SELECT               a.whse_code,
6692 													 a.whse_name,
6693 													 NVL(a.subinventory_ind_flag,'N') subinventory_ind_flag,
6694 													 a.mtl_organization_id
6695 			FROM                 ic_whse_mst a
6696 			WHERE                a.orgn_code = p_orgn_code
6697 			AND                  NOT EXISTS
6698 																		(
6699 																		SELECT      'X'
6700 																		FROM        gl_acct_map x
6701 																		WHERE       x.whse_code = a.whse_code
6702 																		AND         x.co_code = p_co_code
6703 																		AND         x.orgn_code = a.orgn_code
6704 																		AND         x.acct_id = p_acct_id
6705 																		)
6706 			ORDER BY             a.whse_code;
6707 
6708 			CURSOR               cur_sub_event_code
6709 			(
6710 			p_acct_ttl_type     IN      gl_acct_ttl.acct_ttl_type%TYPE
6711 			)
6712 			IS
6713 			SELECT              DISTINCT c.sub_event_code,
6714 													d.event_class_code,
6715 													d.event_Type_code
6716 			FROM                gl_sevt_ttl a,
6717 													gl_sevt_mst c,
6718 													gmf_xla_event_model d
6719 			WHERE               a.acct_ttl_type = p_acct_ttl_type
6720 			AND                 c.sub_event_type = a.sub_event_type
6721 			AND                 c.sub_event_type = d.sub_event_type
6722       AND                 1 = 2; /* Stubbed to avoid migration for Line Assignments */
6723 
6724 			/*********************
6725 			* Local Sub-Programs *
6726 			*********************/
6727 
6728 			PROCEDURE            insert_conditions
6729 			(
6730 			p_condition_tag               IN                VARCHAR2,
6731 			p_sequence                    IN OUT   NOCOPY   NUMBER,
6732 			p_source                      IN                VARCHAR2,
6733 			p_comparision_operator        IN                VARCHAR2,
6734 			p_value_type                  IN                VARCHAR2,
6735 			p_value                       IN                VARCHAR2,
6736 			p_logical_operator            IN                VARCHAR2,
6737 			p_segment_rule_detail_id      IN                NUMBER
6738 			)
6739 			IS
6740 				 l_logical_operator_code                      VARCHAR2(1);
6741 			BEGIN
6742 				 IF p_condition_tag IN ('FIRST', 'ONLY') THEN
6743 						p_sequence := 10;
6744 						IF p_condition_tag = 'ONLY' THEN
6745 							l_logical_operator_code := NULL;
6746 						ELSE
6747 							l_logical_operator_code := p_logical_operator;
6748 						END IF;
6749 				 ELSE
6750 						p_sequence := nvl(p_sequence,0) + 10;
6751 						IF p_condition_tag <> 'LAST' THEN
6752 							l_logical_operator_code := p_logical_operator;
6753 						END IF;
6754 				 END IF;
6755 				/***************************************
6756 				* Loading XLA_CONDITIONS_T Structure   *
6757 				***************************************/
6758 				INSERT INTO xla_conditions_t
6759 				(
6760 				CONDITION_ID,
6761 				APPLICATION_ID,
6762 				AMB_CONTEXT_CODE,
6763 				SEGMENT_RULE_DETAIL_ID,
6764 				USER_SEQUENCE,
6765 				BRACKET_LEFT_CODE,
6766 				BRACKET_RIGHT_CODE,
6767 				VALUE_TYPE_CODE,
6768 				SOURCE_APPLICATION_ID,
6769 				SOURCE_TYPE_CODE,
6770 				SOURCE_CODE,
6771 				FLEXFIELD_SEGMENT_CODE,
6772 				VALUE_FLEXFIELD_SEGMENT_CODE,
6773 				VALUE_SOURCE_APPLICATION_ID,
6774 				VALUE_SOURCE_TYPE_CODE,
6775 				VALUE_SOURCE_CODE,
6776 				VALUE_CONSTANT,
6777 				LINE_OPERATOR_CODE,
6778 				LOGICAL_OPERATOR_CODE,
6779 				INDEPENDENT_VALUE_CONSTANT,
6780 				ERROR_VALUE
6781 				)
6782 				VALUES
6783 				(
6784 				xla_conditions_s.NEXTVAL,
6785 				G_Application_id,
6786 				l_amb_context,
6787 				p_segment_rule_detail_id,
6788 				p_sequence,
6789 				NULL,
6790 				NULL,
6791 				p_value_type,
6792 				G_Application_id,
6793 				'S',
6794 				p_source,
6795 				NULL,
6796 				NULL,
6797 				NULL,
6798 				NULL,
6799 				NULL,
6800 				p_value,
6801 				p_comparision_operator,
6802 				l_logical_operator_code,
6803 				NULL,
6804 				0
6805 				);
6806 			END insert_conditions;
6807 	 BEGIN
6808 
6809 			G_Migration_run_id := P_migration_run_id;
6810 			G_Table_name := 'SLA_ADR_MIGRATION';
6811 			G_Context := 'Account Mappings Migration';
6812 			X_failure_count := 0;
6813 
6814 			/********************************
6815 			* Migration Started Log Message *
6816 			********************************/
6817 			GMA_COMMON_LOGGING.gma_migration_central_log
6818 			(
6819 			p_run_id             =>       G_migration_run_id,
6820 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
6821 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
6822 			p_table_name         =>       G_Table_name,
6823 			p_context            =>       G_Context,
6824 			p_db_error           =>       NULL,
6825 			p_app_short_name     =>       'GMA'
6826 			);
6827 
6828       l_amb_context := 'DEFAULT';
6829 
6830       <<ACCOUNT_TITLES>>
6831 			FOR k IN cur_account_title LOOP
6832 				 <<LEGAL_ENTITIES>>
6833 				 FOR i IN cur_legal_entities LOOP
6834 						/***************************************************************************************************
6835 						* Looping through Company Codes to migrate the Accounting Unit and Accounting Number Mappings once *
6836 						***************************************************************************************************/
6837 						BEGIN
6838 							SELECT         count(1)
6839 							INTO           l_acctg_unit_count
6840 							FROM           gl_plcy_seg a
6841 							WHERE          TYPE = 0
6842 							AND            a.co_code = i.co_code;
6843 						EXCEPTION
6844 							WHEN OTHERS THEN
6845 								l_acctg_unit_count := 0;
6846 						END;
6847 						<<POLICY_SEGMENTS>>
6848 						FOR j IN cur_plcy_seg(p_co_code => i.co_code, p_coa_id => i.chart_of_accounts_id) LOOP
6849 							IF j.TYPE = 0 THEN /* Accounting Unit Mapping */
6850 									l_adr_rule_code := REPLACE( UPPER (SUBSTRB(i.short_name, 1, 14) ||'_'||k.acct_ttl_code||'_'||SUBSTRB(j.short_name, 1, 10)), ' ', '_');
6851 									l_adr_rule_name := SUBSTRB(i.name, 1, 20 )||': ('|| k.acct_ttl_code ||') '|| SUBSTRB(k.acct_ttl_desc, 1, 25) ||' For '||SUBSTRB(j.short_name, 1, 10)||' Segment';
6852 									xrt := 0;
6853 									/********************************
6854 									* Loading XLA_RULES_T GTMP      *
6855 									********************************/
6856 									BEGIN
6857 										SELECT          count(*)
6858 										INTO            xrt
6859 										FROM            xla_rules_t
6860 										WHERE           application_id = G_Application_id
6861 										AND             segment_rule_code = l_adr_rule_code
6862 										AND             amb_context_code = l_amb_context;
6863 									EXCEPTION
6864 										WHEN no_data_found THEN
6865 											xrt := 0;
6866 									END;
6867 									IF nvl(xrt,0) = 0 THEN
6868 										INSERT INTO xla_rules_t
6869 										(
6870 										APPLICATION_ID,
6871 										AMB_CONTEXT_CODE,
6872 										SEGMENT_RULE_TYPE_CODE,
6873 										SEGMENT_RULE_CODE,
6874 										TRANSACTION_COA_ID,
6875 										ACCOUNTING_COA_ID,
6876 										FLEXFIELD_ASSIGN_MODE_CODE,
6877 										FLEXFIELD_SEGMENT_CODE,
6878 										ENABLED_FLAG,
6879 										NAME,
6880 										DESCRIPTION,
6881 										ERROR_VALUE
6882 										)
6883 										VALUES
6884 										(
6885 										G_Application_id,
6886 										l_amb_context,
6887 										'C',
6888 										l_adr_rule_code,
6889 										i.chart_of_accounts_id,
6890 										i.chart_of_accounts_id,
6891 										'S',
6892 										j.application_column_name,
6893 										'Y',
6894 										l_adr_rule_name,
6895 										'ADR for Ledger: '|| i.name ||' - JLT: ('|| k.acct_ttl_code ||') '||SUBSTRB(k.acct_ttl_desc, 1, 25)||' - Segment: '||j.short_name,
6896 										0
6897 										);
6898 										l_adr_priority := 10;
6899 									ELSE
6900 										BEGIN
6901 											SELECT        nvl(MAX(nvl(user_sequence,0)) + 10,10)
6902 											INTO          l_adr_priority
6903 											FROM          xla_rule_details_t
6904 											WHERE         application_id = G_Application_id
6905 											AND           segment_rule_code = l_adr_rule_code
6906 											AND           amb_context_code = l_amb_context;
6907 										EXCEPTION
6908 											WHEN no_data_found THEN
6909 												l_adr_priority := 10;
6910 										END;
6911 									END IF;
6912 									<<SUB_EVENT_CODE_1>>
6913 									FOR m IN cur_sub_event_code (k.acct_ttl_type) LOOP
6914 										/***************************************
6915 										* Loading XLA_LINE_ASSGNS_T Structure  *
6916 										***************************************/
6917 										BEGIN
6918 											SELECT      count(*)
6919 											INTO        xlat
6920 											FROM        xla_line_assgns_t
6921 											WHERE       application_id = G_Application_id
6922 											AND         amb_context_code = l_amb_context
6923 											AND         event_class_code = m.event_class_code
6924 											AND         event_type_code = m.event_type_code
6925 											AND         line_definition_code = m.event_type_code
6926 											AND         accounting_line_code = k.acct_ttl_code
6927 											AND         segment_rule_code = l_adr_rule_code
6928 											AND         flexfield_segment_code = j.application_column_name;
6929 										EXCEPTION
6930 											WHEN no_data_found THEN
6931 												xlat := 0;
6932 										END;
6933 										IF nvl(xlat,0) = 0 THEN
6934 											INSERT INTO xla_line_assgns_t
6935 											(
6936 											APPLICATION_ID,
6937 											AMB_CONTEXT_CODE,
6938 											EVENT_CLASS_CODE,
6939 											EVENT_TYPE_CODE,
6940 											LINE_DEFINITION_OWNER_CODE,
6941 											LINE_DEFINITION_CODE,
6942 											ACCOUNTING_LINE_TYPE_CODE,
6943 											ACCOUNTING_LINE_CODE,
6944 											FLEXFIELD_SEGMENT_CODE,
6945 											SEGMENT_RULE_TYPE_CODE,
6946 											SEGMENT_RULE_CODE,
6947 											ERROR_VALUE
6948 											)
6949 											VALUES
6950 											(
6951 											G_Application_id,
6952 											l_amb_context,
6953 											m.event_class_code,
6954 											m.event_type_code,
6955 											'C',
6956 											m.event_type_code,
6957 											'S',
6958 											k.acct_ttl_code,
6959 											j.application_column_name,
6960 											'C',
6961 											l_adr_rule_code,
6962 											0
6963 											);
6964 										END IF;
6965 									END LOOP SUB_EVENT_CODE_1;
6966 									<<ACCOUNTING_UNITS>>
6967 									FOR l IN cur_account_unit_map(p_co_code => i.co_code) LOOP
6968 										 SELECT      substrb(a, decode(b-1, 0, 1, instr(a, c, 1, (b-1))+ 1), decode(instr(a, c, 1, b), 0, (length(a) - instr(a, c, 1, (b-1))+ 1), (instr(a, c, 1, b)) - decode(b-1, 0, 1, instr(a, c, 1, (b-1))+ 1)))
6969 										 INTO        l_segment_value
6970 										 FROM        (
6971 																 SELECT      l.acctg_unit_no a,
6972 																						 j.segment_no b,
6973 																						 i.segment_delimiter c
6974 																 FROM        dual
6975 																 );
6976 										/***************************************
6977 										* Loading XLA_RULE_DETAILS_T Structure *
6978 										***************************************/
6979 										BEGIN
6980 											SELECT        nvl(MAX(nvl(user_sequence,0)) + 10,10)
6981 											INTO          l_adr_priority
6982 											FROM          xla_rule_details_t
6983 											WHERE         application_id = G_Application_id
6984 											AND           segment_rule_code = l_adr_rule_code
6985 											AND           amb_context_code = l_amb_context;
6986 										EXCEPTION
6987 											WHEN no_data_found THEN
6988 												l_adr_priority := 10;
6989 										END;
6990 										l_segment_rule_detail_id := NULL;
6991 										INSERT INTO xla_rule_details_t
6992 										(
6993 										APPLICATION_ID,
6994 										AMB_CONTEXT_CODE,
6995 										SEGMENT_RULE_TYPE_CODE,
6996 										SEGMENT_RULE_CODE,
6997 										SEGMENT_RULE_DETAIL_ID,
6998 										USER_SEQUENCE,
6999 										VALUE_TYPE_CODE,
7000 										VALUE_SOURCE_APPLICATION_ID,
7001 										VALUE_SOURCE_TYPE_CODE,
7002 										VALUE_SOURCE_CODE,
7003 										VALUE_CONSTANT,
7004 										VALUE_CODE_COMBINATION_ID,
7005 										VALUE_MAPPING_SET_CODE,
7006 										VALUE_FLEXFIELD_SEGMENT_CODE,
7007 										INPUT_SOURCE_APPLICATION_ID,
7008 										INPUT_SOURCE_TYPE_CODE,
7009 										INPUT_SOURCE_CODE,
7010 										VALUE_SEGMENT_RULE_APPL_ID,
7011 										VALUE_SEGMENT_RULE_TYPE_CODE,
7012 										VALUE_SEGMENT_RULE_CODE,
7013 										VALUE_ADR_VERSION_NUM,
7014 										ERROR_VALUE
7015 										)
7016 										VALUES
7017 										(
7018 										G_Application_id,
7019 										l_amb_context,
7020 										'C',
7021 										l_adr_rule_code,
7022 										xla_seg_rule_details_s.NEXTVAL,
7023 										l_adr_priority,
7024 										'C',
7025 										NULL,
7026 										NULL,
7027 										NULL,
7028 										l_segment_value,
7029 										NULL,
7030 										NULL,
7031 										NULL,
7032 										NULL,
7033 										NULL,
7034 										NULL,
7035 										NULL,
7036 										NULL,
7037 										NULL,
7038 										NULL,
7039 										0
7040 										) returning segment_rule_detail_id INTO l_segment_rule_detail_id;
7041 										IF l_segment_rule_detail_id IS NOT NULL THEN
7042 											insert_conditions (
7043 																				p_condition_tag               =>                'FIRST',
7044 																				p_sequence                    =>                l_adr_condition_priority,
7045 																				p_source                      =>                G_Journal_Line_Type,
7046 																				p_comparision_operator        =>                G_Equal,
7047 																				p_value_type                  =>                G_constant,
7048 																				p_value                       =>                k.acct_ttl_code,
7049 																				p_logical_operator            =>                G_And,
7050 																				p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7051 																				);
7052 											insert_conditions (
7053 																				p_condition_tag               =>                'MID',
7054 																				p_sequence                    =>                l_adr_condition_priority,
7055 																				p_source                      =>                G_ledger_id,
7056 																				p_comparision_operator        =>                G_Equal,
7057 																				p_value_type                  =>                G_constant,
7058 																				p_value                       =>                i.ledger_id,
7059 																				p_logical_operator            =>                G_And,
7060 																				p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7061 																				);
7062 											insert_conditions (
7063 																				p_condition_tag               =>                'MID',
7064 																				p_sequence                    =>                l_adr_condition_priority,
7065 																				p_source                      =>                G_legal_entity,
7066 																				p_comparision_operator        =>                G_Equal,
7067 																				p_value_type                  =>                G_constant,
7068 																				p_value                       =>                i.legal_entity_id,
7069 																				p_logical_operator            =>                G_And,
7070 																				p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7071 																				);
7072 											IF l.orgn_code IS NOT NULL THEN
7073 												IF l.whse_code IS NOT NULL AND nvl(l.subinventory_ind_flag,'N') = 'Y' AND NVL(l.inventory_org_ind,'N') = 'Y' THEN
7074 													/************************************************************
7075 													* OPM Organizations is Migrated as inventory Organization   *
7076 													************************************************************/
7077 													insert_conditions (
7078 																						p_condition_tag               =>                'MID',
7079 																						p_sequence                    =>                l_adr_condition_priority,
7080 																						p_source                      =>                G_Organization,
7081 																						p_comparision_operator        =>                G_Equal,
7082 																						p_value_type                  =>                G_constant,
7083 																						p_value                       =>                l.organization_id,
7084 																						p_logical_operator            =>                G_and,
7085 																						p_segment_rule_detail_id       =>               l_segment_rule_detail_id
7086 																						);
7087 													 /*******************************************************************
7088 													 * Warehouse Code Is specified and is migrated as subinventories    *
7089 													 *******************************************************************/
7090 													 insert_conditions (
7091 																						 p_condition_tag               =>                'LAST',
7092 																						 p_sequence                    =>                l_adr_condition_priority,
7093 																						 p_source                      =>                G_subinventory,
7094 																						 p_comparision_operator        =>                G_Equal,
7095 																						 p_value_type                  =>                G_constant,
7096 																						 p_value                       =>                l.whse_code,
7097 																						 p_logical_operator            =>                NULL,
7098 																						 p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7099 																						 );
7100 												ELSIF l.whse_code IS NOT NULL AND nvl(l.subinventory_ind_flag,'N') <> 'Y' THEN
7101 													/****************************************************************************
7102 													* Warehouse Code Is specified and is migrated as Inventory Organizations    *
7103 													****************************************************************************/
7104 													 insert_conditions (
7105 																						 p_condition_tag               =>                'LAST',
7106 																						 p_sequence                    =>                l_adr_condition_priority,
7107 																						 p_source                      =>                G_Organization,
7108 																						 p_comparision_operator        =>                G_Equal,
7109 																						 p_value_type                  =>                G_constant,
7110 																						 p_value                       =>                l.mtl_organization_id,
7111 																						 p_logical_operator            =>                NULL,
7112 																						 p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7113 																						 );
7114 												ELSE
7115 													/*******************************************************************************************************
7116 													* Warehouse Code Is not specified, so inserting a record for all warehouses under the OPM organization *
7117 													*******************************************************************************************************/
7118 													mcnt := 1;
7119 													<<WAREHOUSE_ACCU>>
7120 													FOR m IN cur_whse_accu (l.orgn_code, i.co_code, l.acctg_unit_id) LOOP
7121 														IF m.mtl_organization_id <> nvl(l.organization_id, -1) THEN
7122 															IF mcnt > 1 THEN
7123 																BEGIN
7124 																	SELECT        nvl(MAX(nvl(user_sequence,0)) + 10,10)
7125 																	INTO          l_adr_priority
7126 																	FROM          xla_rule_details_t
7127 																	WHERE         application_id = G_Application_id
7128 																	AND           segment_rule_code = l_adr_rule_code
7129 																	AND           amb_context_code = l_amb_context;
7130 																EXCEPTION
7131 																	WHEN no_data_found THEN
7132 																		l_adr_priority := 10;
7133 																END;
7134 																l_segment_rule_detail_id := NULL;
7135 																INSERT INTO xla_rule_details_t
7136 																(
7137 																APPLICATION_ID,
7138 																AMB_CONTEXT_CODE,
7139 																SEGMENT_RULE_TYPE_CODE,
7140 																SEGMENT_RULE_CODE,
7141 																SEGMENT_RULE_DETAIL_ID,
7142 																USER_SEQUENCE,
7143 																VALUE_TYPE_CODE,
7144 																VALUE_SOURCE_APPLICATION_ID,
7145 																VALUE_SOURCE_TYPE_CODE,
7146 																VALUE_SOURCE_CODE,
7147 																VALUE_CONSTANT,
7148 																VALUE_CODE_COMBINATION_ID,
7149 																VALUE_MAPPING_SET_CODE,
7150 																VALUE_FLEXFIELD_SEGMENT_CODE,
7151 																INPUT_SOURCE_APPLICATION_ID,
7152 																INPUT_SOURCE_TYPE_CODE,
7153 																INPUT_SOURCE_CODE,
7154 																VALUE_SEGMENT_RULE_APPL_ID,
7155 																VALUE_SEGMENT_RULE_TYPE_CODE,
7156 																VALUE_SEGMENT_RULE_CODE,
7157 																VALUE_ADR_VERSION_NUM,
7158 																ERROR_VALUE
7159 																)
7160 																VALUES
7161 																(
7162 																G_Application_id,
7163 																l_amb_context,
7164 																'C',
7165 																l_adr_rule_code,
7166 																xla_seg_rule_details_s.NEXTVAL,
7167 																l_adr_priority,
7168 																'C',
7169 																NULL,
7170 																NULL,
7171 																NULL,
7172 																l_segment_value,
7173 																NULL,
7174 																NULL,
7175 																NULL,
7176 																NULL,
7177 																NULL,
7178 																NULL,
7179 																NULL,
7180 																NULL,
7181 																NULL,
7182 																NULL,
7183 																0
7184 																) returning segment_rule_detail_id INTO l_segment_rule_detail_id;
7185 																insert_conditions (
7186 																									p_condition_tag               =>                'FIRST',
7187 																									p_sequence                    =>                l_adr_condition_priority,
7188 																									p_source                      =>                G_Journal_Line_Type,
7189 																									p_comparision_operator        =>                G_Equal,
7190 																									p_value_type                  =>                G_constant,
7191 																									p_value                       =>                k.acct_ttl_code,
7192 																									p_logical_operator            =>                G_And,
7193 																									p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7194 																									);
7195 																insert_conditions (
7196 																									p_condition_tag               =>                'MID',
7197 																									p_sequence                    =>                l_adr_condition_priority,
7198 																									p_source                      =>                G_ledger_id,
7199 																									p_comparision_operator        =>                G_Equal,
7200 																									p_value_type                  =>                G_constant,
7201 																									p_value                       =>                i.ledger_id,
7202 																									p_logical_operator            =>                G_And,
7203 																									p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7204 																									);
7205 																insert_conditions (
7206 																									p_condition_tag               =>                'MID',
7207 																									p_sequence                    =>                l_adr_condition_priority,
7208 																									p_source                      =>                G_legal_entity,
7209 																									p_comparision_operator        =>                G_Equal,
7210 																									p_value_type                  =>                G_constant,
7211 																									p_value                       =>                i.legal_entity_id,
7212 																									p_logical_operator            =>                G_And,
7213 																									p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7214 																									);
7215 															END IF;
7216 															IF nvl(m.subinventory_ind_flag,'N') = 'Y' THEN
7217 																/************************************************************
7218 																* OPM Organizations is Migrated as inventory Organization   *
7219 																************************************************************/
7220 																insert_conditions (
7221 																									p_condition_tag               =>                'MID',
7222 																									p_sequence                    =>                l_adr_condition_priority,
7223 																									p_source                      =>                G_Organization,
7224 																									p_comparision_operator        =>                G_Equal,
7225 																									p_value_type                  =>                G_constant,
7226 																									p_value                       =>                l.organization_id,
7227 																									p_logical_operator            =>                G_and,
7228 																									p_segment_rule_detail_id       =>               l_segment_rule_detail_id
7229 																									);
7230 																 /*******************************************************************
7231 																 * Warehouse Code Is specified and is migrated as subinventories    *
7232 																 *******************************************************************/
7233 																 insert_conditions (
7234 																									 p_condition_tag               =>                'LAST',
7235 																									 p_sequence                    =>                l_adr_condition_priority,
7236 																									 p_source                      =>                G_subinventory,
7237 																									 p_comparision_operator        =>                G_Equal,
7238 																									 p_value_type                  =>                G_constant,
7239 																									 p_value                       =>                m.whse_code,
7240 																									 p_logical_operator            =>                NULL,
7241 																									 p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7242 																									 );
7243 															ELSIF nvl(m.subinventory_ind_flag,'N') <> 'Y' THEN
7244 																/****************************************************************************
7245 																* Warehouse Code Is specified and is migrated as Inventory Organizations    *
7246 																****************************************************************************/
7247 																insert_conditions  (
7248 																									 p_condition_tag               =>                'LAST',
7249 																									 p_sequence                    =>                l_adr_condition_priority,
7250 																									 p_source                      =>                G_Organization,
7251 																									 p_comparision_operator        =>                G_Equal,
7252 																									 p_value_type                  =>                G_constant,
7253 																									 p_value                       =>                m.mtl_organization_id,
7254 																									 p_logical_operator            =>                NULL,
7255 																									 p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7256 																									 );
7257 															END IF;
7258 															mcnt := nvl(mcnt,1) + 1;
7259 														END IF;
7260 													END LOOP WAREHOUSE_ACCU;
7261 													IF NVL(l.inventory_org_ind,'N') = 'Y' AND nvl(mcnt, 1) > 1 THEN
7262 														BEGIN
7263 															SELECT        nvl(MAX(nvl(user_sequence,0)) + 10,10)
7264 															INTO          l_adr_priority
7265 															FROM          xla_rule_details_t
7266 															WHERE         application_id = G_Application_id
7267 															AND           segment_rule_code = l_adr_rule_code
7268 															AND           amb_context_code = l_amb_context;
7269 														EXCEPTION
7270 															WHEN no_data_found THEN
7271 																l_adr_priority := 10;
7272 														END;
7273 														 l_segment_rule_detail_id := NULL;
7274 														 INSERT INTO xla_rule_details_t
7275 														 (
7276 														 APPLICATION_ID,
7277 														 AMB_CONTEXT_CODE,
7278 														 SEGMENT_RULE_TYPE_CODE,
7279 														 SEGMENT_RULE_CODE,
7280 														 SEGMENT_RULE_DETAIL_ID,
7281 														 USER_SEQUENCE,
7282 														 VALUE_TYPE_CODE,
7283 														 VALUE_SOURCE_APPLICATION_ID,
7284 														 VALUE_SOURCE_TYPE_CODE,
7285 														 VALUE_SOURCE_CODE,
7286 														 VALUE_CONSTANT,
7287 														 VALUE_CODE_COMBINATION_ID,
7288 														 VALUE_MAPPING_SET_CODE,
7289 														 VALUE_FLEXFIELD_SEGMENT_CODE,
7290 														 INPUT_SOURCE_APPLICATION_ID,
7291 														 INPUT_SOURCE_TYPE_CODE,
7292 														 INPUT_SOURCE_CODE,
7293 														 VALUE_SEGMENT_RULE_APPL_ID,
7294 														 VALUE_SEGMENT_RULE_TYPE_CODE,
7295 														 VALUE_SEGMENT_RULE_CODE,
7296 														 VALUE_ADR_VERSION_NUM,
7297 														 ERROR_VALUE
7298 														 )
7299 														 VALUES
7300 														 (
7301 														 G_Application_id,
7302 														 l_amb_context,
7303 														 'C',
7304 														 l_adr_rule_code,
7305 														 xla_seg_rule_details_s.NEXTVAL,
7306 														 l_adr_priority,
7307 														 'C',
7308 														 NULL,
7309 														 NULL,
7310 														 NULL,
7311 														 l_segment_value,
7312 														 NULL,
7313 														 NULL,
7314 														 NULL,
7315 														 NULL,
7316 														 NULL,
7317 														 NULL,
7318 														 NULL,
7319 														 NULL,
7320 														 NULL,
7321 														 NULL,
7322 														 0
7323 														 ) returning segment_rule_detail_id INTO l_segment_rule_detail_id;
7324 														 IF l_segment_rule_detail_id IS NOT NULL THEN
7325 															 insert_conditions (
7326 																								 p_condition_tag               =>                'FIRST',
7327 																								 p_sequence                    =>                l_adr_condition_priority,
7328 																								 p_source                      =>                G_Journal_Line_Type,
7329 																								 p_comparision_operator        =>                G_Equal,
7330 																								 p_value_type                  =>                G_constant,
7331 																								 p_value                       =>                k.acct_ttl_code,
7332 																								 p_logical_operator            =>                G_And,
7333 																								 p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7334 																								 );
7335 															 insert_conditions (
7336 																								 p_condition_tag               =>                'MID',
7337 																								 p_sequence                    =>                l_adr_condition_priority,
7338 																								 p_source                      =>                G_ledger_id,
7339 																								 p_comparision_operator        =>                G_Equal,
7340 																								 p_value_type                  =>                G_constant,
7341 																								 p_value                       =>                i.ledger_id,
7342 																								 p_logical_operator            =>                G_And,
7343 																								 p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7344 																								 );
7345 															 insert_conditions (
7346 																								 p_condition_tag               =>                'MID',
7347 																								 p_sequence                    =>                l_adr_condition_priority,
7348 																								 p_source                      =>                G_legal_entity,
7349 																								 p_comparision_operator        =>                G_Equal,
7350 																								 p_value_type                  =>                G_constant,
7351 																								 p_value                       =>                i.legal_entity_id,
7352 																								 p_logical_operator            =>                G_And,
7353 																								 p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7354 																								 );
7355 															 insert_conditions (
7356 																								 p_condition_tag               =>                'LAST',
7357 																								 p_sequence                    =>                l_adr_condition_priority,
7358 																								 p_source                      =>                G_Organization,
7359 																								 p_comparision_operator        =>                G_Equal,
7360 																								 p_value_type                  =>                G_constant,
7361 																								 p_value                       =>                l.organization_id,
7362 																								 p_logical_operator            =>                NULL,
7363 																								 p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7364 																								 );
7365 														 END IF;
7366 													ELSIF NVL(l.inventory_org_ind,'N') <> 'Y' THEN
7367 														BEGIN
7368 															UPDATE    xla_conditions_t
7369 															SET       logical_operator_code = NULL
7370 															WHERE     user_sequence = l_adr_condition_priority
7371 															AND       segment_rule_detail_id = l_segment_rule_detail_id
7372 															AND       amb_context_code = l_amb_context;
7373 														EXCEPTION
7374 															WHEN OTHERS THEN
7375 																NULL;
7376 														END;
7377 													ELSE
7378 														insert_conditions (
7379 																							p_condition_tag               =>                'LAST',
7380 																							p_sequence                    =>                l_adr_condition_priority,
7381 																							p_source                      =>                G_Organization,
7382 																							p_comparision_operator        =>                G_Equal,
7383 																							p_value_type                  =>                G_constant,
7384 																							p_value                       =>                l.organization_id,
7385 																							p_logical_operator            =>                NULL,
7386 																							p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7387 																							);
7388 													END IF;
7389 												 END IF;
7390 											 ELSE
7391 												 BEGIN
7392 													 UPDATE    xla_conditions_t
7393 													 SET       logical_operator_code = NULL
7394 													 WHERE     user_sequence = l_adr_condition_priority
7395 													 AND       segment_rule_detail_id = l_segment_rule_detail_id
7396 													 AND       amb_context_code = l_amb_context;
7397 												 EXCEPTION
7398 													 WHEN OTHERS THEN
7399 														 NULL;
7400 												 END;
7401 											 END IF;
7402 										END IF;
7403 									END LOOP ACCOUNTING_UNITS;
7404 								ELSE /* Account Mapping */
7405 									/***************************************
7406 									* Migration of Account Number Mappings *
7407 									***************************************/
7408 									l_adr_rule_code := REPLACE (UPPER (SUBSTRB(i.short_name, 1, 14) ||'_'||k.acct_ttl_code||'_'||SUBSTRB(j.short_name, 1, 10)), ' ', '_');
7409                   l_adr_rule_name := SUBSTRB(i.name, 1, 20 )||': ('|| k.acct_ttl_code ||') '|| SUBSTRB(k.acct_ttl_desc, 1, 25) ||' For '||SUBSTRB(j.short_name, 1, 10)||' Segment';
7410 									xrt := 0;
7411 									/********************************
7412 									* Loading XLA_RULES_T GTMP      *
7413 									********************************/
7414 									BEGIN
7415 										SELECT          count(*)
7416 										INTO            xrt
7417 										FROM            xla_rules_t
7418 										WHERE           application_id = G_Application_id
7419 										AND             SEGMENT_RULE_CODE = l_adr_rule_code
7420 										AND             amb_context_code = l_amb_context;
7421 									EXCEPTION
7422 										WHEN no_data_found THEN
7423 											xrt := 0;
7424 									END;
7425 									IF nvl(xrt,0) = 0 THEN
7426 										INSERT INTO xla_rules_t
7427 										(
7428 										APPLICATION_ID,
7429 										AMB_CONTEXT_CODE,
7430 										SEGMENT_RULE_TYPE_CODE,
7431 										SEGMENT_RULE_CODE,
7432 										TRANSACTION_COA_ID,
7433 										ACCOUNTING_COA_ID,
7434 										FLEXFIELD_ASSIGN_MODE_CODE,
7435 										FLEXFIELD_SEGMENT_CODE,
7436 										ENABLED_FLAG,
7437 										NAME,
7438 										DESCRIPTION,
7439 										ERROR_VALUE
7440 										)
7441 										VALUES
7442 										(
7443 										G_Application_id,
7444 										l_amb_context,
7445 										'C',
7446 										l_adr_rule_code,
7447 										i.chart_of_accounts_id,
7448 										i.chart_of_accounts_id,
7449 										'S',
7450 										j.application_column_name,
7451 										'Y',
7452 										l_adr_rule_name,
7453                     'ADR for Ledger: '|| i.name ||' - JLT: ('|| k.acct_ttl_code ||') '||SUBSTRB(k.acct_ttl_desc, 1, 25)||' - Segment: '||j.short_name,
7454 										0
7455 										);
7456 										l_adr_priority := 10;
7457 									ELSE
7458 										BEGIN
7459 											SELECT        nvl(MAX(nvl(user_sequence,0)) + 10,10)
7460 											INTO          l_adr_priority
7461 											FROM          xla_rule_details_t
7462 											WHERE         application_id = G_Application_id
7463 											AND           segment_rule_code = l_adr_rule_code
7464 											AND           amb_context_code = l_amb_context;
7465 										EXCEPTION
7466 											WHEN no_data_found THEN
7467 												l_adr_priority := 10;
7468 										END;
7469 									END IF;
7470 									<<SUB_EVENT_CODE_2>>
7471 									FOR m IN cur_sub_event_code (k.acct_ttl_type) LOOP
7472 										/***************************************
7473 										* Loading XLA_LINE_ASSGNS_T Structure  *
7474 										***************************************/
7475 										BEGIN
7476 											SELECT      count(*)
7477 											INTO        xlat
7478 											FROM        xla_line_assgns_t
7479 											WHERE       application_id = G_Application_id
7480 											AND         amb_context_code = l_amb_context
7481 											AND         event_class_code = m.event_class_code
7482 											AND         event_type_code = m.event_type_code
7483 											AND         line_definition_code = m.event_type_code
7484 											AND         accounting_line_code = k.acct_ttl_code
7485 											AND         segment_rule_code = l_adr_rule_code
7486 											AND         flexfield_segment_code = j.application_column_name;
7487 										EXCEPTION
7488 											WHEN no_data_found THEN
7489 												xlat := 0;
7490 										END;
7491 										IF nvl(xlat,0) = 0 THEN
7492 											INSERT INTO xla_line_assgns_t
7493 											(
7494 											APPLICATION_ID,
7495 											AMB_CONTEXT_CODE,
7496 											EVENT_CLASS_CODE,
7497 											EVENT_TYPE_CODE,
7498 											LINE_DEFINITION_OWNER_CODE,
7499 											LINE_DEFINITION_CODE,
7500 											ACCOUNTING_LINE_TYPE_CODE,
7501 											ACCOUNTING_LINE_CODE,
7502 											FLEXFIELD_SEGMENT_CODE,
7503 											SEGMENT_RULE_TYPE_CODE,
7504 											SEGMENT_RULE_CODE,
7505 											ERROR_VALUE
7506 											)
7507 											VALUES
7508 											(
7509 											G_Application_id,
7510 											l_amb_context,
7511 											m.event_class_code,
7512 											m.event_type_code,
7513 											'C',
7514 											m.event_type_code,
7515 											'S',
7516 											k.acct_ttl_code,
7517 											j.application_column_name,
7518 											'C',
7519 											l_adr_rule_code,
7520 											0
7521 											);
7522 										END IF;
7523 									END LOOP SUB_EVENT_CODE_2;
7524 									X_sqlstmt :=  'SELECT     a.co_code,
7525 																						a.orgn_code_pri,
7526 																						a.whse_code_pri,
7527 																						a.icgl_class_pri,
7528 																						a.custgl_class_pri,
7529 																						a.vendgl_class_pri ,
7530 																						a.item_pri,
7531 																						a.customer_pri,
7532 																						a.vendor_pri,
7533 																						a.tax_auth_pri,
7534 																						a.charge_pri,
7535 																						a.currency_code_pri,
7536 																						a.reason_code_pri,
7537 																						a.routing_pri,
7538 																						a.aqui_cost_code_pri,
7539 																						a.resource_pri,
7540 																						a.cost_cmpntcls_pri,
7541 																						a.cost_analysis_pri,
7542 																						a.order_type_pri,
7543 																						a.gl_business_class_pri,
7544 																						a.gl_product_line_pri,
7545 																						a.line_type_pri,
7546 																						a.ar_trx_type_pri
7547 																FROM        gl_acct_hrc a
7548 																WHERE       a.acct_ttl_type = :p_acct_ttl_type
7549 																AND         a.co_code = :p_co_code
7550 																ORDER BY    1 desc';
7551 									BEGIN
7552 										EXECUTE   IMMEDIATE X_sqlstmt
7553 										INTO      l_co_code1,       l_orgn_code_pri,        l_whse_code_pri,
7554 															l_icgl_class_pri, l_custgl_class_pri,     l_vendgl_class_pri,
7555 															l_item_pri,       l_customer_pri,         l_vendor_pri,
7556 															l_tax_auth_pri,   l_charge_pri,           l_currency_code_pri,
7557 															l_reason_code_pri,l_routing_pri,          l_aqui_cost_code_pri,
7558 															l_resource_pri,   l_cost_cmpntcls_pri,    l_cost_analysis_pri,
7559 															l_order_type_pri, l_gl_business_class_pri,l_gl_product_line_pri,
7560 															l_line_type_pri,  l_ar_trx_type_pri
7561 										 using    k.acct_ttl_type, i.co_code;
7562 									EXCEPTION
7563 										WHEN no_data_found THEN
7564 											NULL;
7565 									END;
7566 									FOR z IN 1..23 LOOP
7567 										X_order_tbl(z) := 0;
7568 									END LOOP;
7569 									X_my_order_by :=  ' ORDER BY 1';
7570 									IF sql%rowcount > 0  THEN
7571 										IF l_orgn_code_pri > 0 THEN
7572 											x_tmp1:= l_orgn_code_pri + 1;
7573 											X_order_tbl(x_tmp1) := 2;
7574 										END IF;
7575 										IF l_whse_code_pri > 0 THEN
7576 											x_tmp1:= l_whse_code_pri + 1;
7577 											X_order_tbl(x_tmp1) := 3;
7578 										END IF;
7579 										IF l_icgl_class_pri > 0 THEN
7580 											x_tmp1:= l_icgl_class_pri + 1;
7581 											X_order_tbl(x_tmp1) := 4;
7582 										END IF;
7583 										IF l_custgl_class_pri > 0 THEN
7584 											x_tmp1:= l_custgl_class_pri + 1;
7585 											X_order_tbl(x_tmp1) := 5;
7586 										END IF;
7587 										IF l_vendgl_class_pri > 0 THEN
7588 											x_tmp1:= l_vendgl_class_pri + 1;
7589 											X_order_tbl(x_tmp1) := 6;
7590 										END IF;
7591 										IF l_item_pri > 0 THEN
7592 											x_tmp1:= l_item_pri + 1;
7593 											X_order_tbl(x_tmp1) := 7;
7594 										END IF;
7595 										IF l_customer_pri > 0 THEN
7596 											x_tmp1:= l_customer_pri + 1;
7597 											X_order_tbl(x_tmp1) := 8;
7598 										END IF;
7599 										IF l_vendor_pri > 0 THEN
7600 											x_tmp1:= l_vendor_pri + 1;
7601 											X_order_tbl(x_tmp1) := 9;
7602 										END IF;
7603 										IF l_tax_auth_pri > 0 THEN
7604 											x_tmp1:= l_tax_auth_pri + 1;
7605 											X_order_tbl(x_tmp1) := 10;
7606 										END IF;
7607 										IF l_charge_pri > 0 THEN
7608 											x_tmp1:= l_charge_pri + 1;
7609 											X_order_tbl(x_tmp1) := 11;
7610 										END IF;
7611 										IF l_currency_code_pri > 0 THEN
7612 											x_tmp1:= l_currency_code_pri + 1;
7613 											X_order_tbl(x_tmp1) := 12;
7614 										END IF;
7615 										IF l_reason_code_pri > 0 THEN
7616 											x_tmp1:= l_reason_code_pri + 1;
7617 											X_order_tbl(x_tmp1) := 13;
7618 										END IF;
7619 										IF l_routing_pri > 0 THEN
7620 											x_tmp1:= l_routing_pri + 1;
7621 											X_order_tbl(x_tmp1) := 14;
7622 										END IF;
7623 										IF l_aqui_cost_code_pri > 0 THEN
7624 											x_tmp1:= l_aqui_cost_code_pri + 1;
7625 											X_order_tbl(x_tmp1) := 15;
7626 										END IF;
7627 										IF l_resource_pri > 0 THEN
7628 											x_tmp1:= l_resource_pri + 1;
7629 											X_order_tbl(x_tmp1) := 16;
7630 										END IF;
7631 										IF l_cost_cmpntcls_pri > 0 THEN
7632 											x_tmp1:= l_cost_cmpntcls_pri + 1;
7633 											X_order_tbl(x_tmp1) := 17;
7634 										END IF;
7635 										IF l_cost_analysis_pri > 0 THEN
7636 											x_tmp1:= l_cost_analysis_pri + 1;
7637 											X_order_tbl(x_tmp1) := 18;
7638 										END IF;
7639 										IF l_order_type_pri > 0 THEN
7640 											x_tmp1:= l_order_type_pri + 1;
7641 											X_order_tbl(x_tmp1) := 19;
7642 										END IF;
7643 										IF l_gl_business_class_pri > 0 THEN
7644 											x_tmp1:= l_gl_business_class_pri + 1;
7645 											X_order_tbl(x_tmp1) := 20;
7646 										END IF;
7647 										IF l_gl_product_line_pri > 0 THEN
7648 											x_tmp1:= l_gl_product_line_pri + 1;
7649 											X_order_tbl(x_tmp1) := 21;
7650 										END IF;
7651 										IF l_line_type_pri > 0 THEN
7652 											x_tmp1:= l_line_type_pri + 1;
7653 											X_order_tbl(x_tmp1) := 22;
7654 										END IF;
7655 										IF l_ar_trx_type_pri > 0 THEN
7656 											x_tmp1:= l_ar_trx_type_pri + 1;
7657 											X_order_tbl(x_tmp1) := 23;
7658 										END IF;
7659 									END IF;
7660 									FOR z IN 2..23 LOOP
7661 										IF X_order_tbl(z) > 0 THEN
7662 											X_my_order_by := X_my_order_by||', '||to_char(x_order_tbl(z))||' NULLS LAST ';
7663 										END IF;
7664 									END LOOP;
7665 									X_sqlcolumns:=  ' SELECT          a.co_code,
7666 																										a.orgn_code,
7667 																										a.whse_code,
7668 																										a.gl_category_id,
7669 																										a.custgl_class,
7670 																										a.vendgl_class,
7671 																										a.item_id,
7672 																										a.cust_id,
7673 																										a.vendor_id,
7674 																										a.taxauth_id,
7675 																										a.charge_id,
7676 																										a.currency_code,
7677 																										a.reason_code,
7678 																										a.routing_id,
7679 																										a.aqui_cost_id,
7680 																										a.resources,
7681 																										a.cost_cmpntcls_id,
7682 																										a.cost_analysis_code,
7683 																										a.order_type,
7684 																										a.gl_business_class_cat_id,
7685 																										a.gl_product_line_cat_id,
7686 																										a.line_type,
7687 																										a.ar_trx_type_id,
7688 																										b.acct_id,
7689 																										b.acct_no,
7690 																										NVL(c.inventory_org_ind,''N'') inventory_org_ind,
7691 																										NVL(d.subinventory_ind_flag,''N'') subinventory_ind_flag,
7692 																										a.ROWID,
7693 																										a.source_type,
7694 																										c.organization_id,
7695 																										d.mtl_organization_id ';
7696 									X_sqlwhere := ' WHERE             a.acct_ttl_type = :p_acct_ttl_type
7697 																	AND               a.co_code = :p_co_code
7698 																	AND               a.co_code = b.co_code
7699 																	AND               a.acct_id = b.acct_id
7700 																	AND               c.orgn_code(+) = a.orgn_code
7701 																	AND               d.whse_code(+) = a.whse_code
7702                                   AND               a.taxauth_id IS NULL
7703                                   AND               a.charge_id IS NULL
7704                                   AND               nvl(a.migrated_ind,0) <> 1 ';
7705 									X_sqlordby:=      X_my_order_by;
7706 									BEGIN
7707 										EXECUTE IMMEDIATE     X_sqlcolumns  ||
7708 																					' FROM        gl_acct_map a,
7709 																												gl_acct_mst b,
7710 																												sy_orgn_mst c,
7711 																												ic_whse_mst d '
7712 																												||
7713 																												X_sqlwhere
7714 																												||
7715 																												X_sqlordby
7716 										BULK COLLECT INTO     l_co_code,
7717 																					l_orgn_code,
7718 																					l_whse_code,
7719 																					l_gl_category_id,
7720 																					l_custgl_class,
7721 																					l_vendgl_class,
7722 																					l_item_id,
7723 																					l_cust_id,
7724 																					l_vendor_id,
7725 																					l_taxauth_id,
7726 																					l_charge_id,
7727 																					l_currency_code,
7728 																					l_reason_code,
7729 																					l_routing_id,
7730 																					l_aqui_cost_id,
7731 																					l_resources,
7732 																					l_cost_cmpntcls_id,
7733 																					l_cost_analysis_code,
7734 																					l_order_type,
7735 																					l_gl_business_class_cat_id,
7736 																					l_gl_product_line_cat_id,
7737 																					l_line_type,
7738 																					l_ar_trx_type_id,
7739 																					l_acct_id,
7740 																					l_acct_no,
7741 																					l_inventory_org_ind,
7742 																					l_subinventory_ind_flag,
7743 																					l_rowid,
7744 																					l_source_type,
7745 																					l_organization_id,
7746 																					l_mtl_organization_id
7747 										USING                 k.acct_ttl_type,
7748 																					i.co_code;
7749 									EXCEPTION
7750 										WHEN no_data_found THEN
7751 											NULL;
7752 									END;
7753 									IF nvl(l_rowid.count,0) > 0 THEN
7754 										<<GL_ACCT_MAP>>
7755 										FOR m in l_rowid.FIRST..l_rowid.LAST LOOP
7756 											SELECT      substrb(a, decode(b-1, 0, 1, instr(a, c, 1, (b-1))+ 1), decode(instr(a, c, 1, b), 0, (length(a) - instr(a, c, 1, (b-1))+ 1), (instr(a, c, 1, b)) - decode(b-1, 0, 1, instr(a, c, 1, (b-1))+ 1)))
7757 											INTO        l_segment_value
7758 											FROM        (
7759 																	SELECT      l_acct_no(m) a,
7760 																							(j.segment_no - l_acctg_unit_count) b,
7761 																							i.segment_delimiter c
7762 																	FROM        dual
7763 																	);
7764 											/***************************************
7765 											* Loading XLA_RULE_DETAILS_T Structure *
7766 											***************************************/
7767 											BEGIN
7768 												SELECT        NVL(MAX(nvl(user_sequence,0)) + 10,10)
7769 												INTO          l_adr_priority
7770 												FROM          xla_rule_details_t
7771 												WHERE         application_id = G_Application_id
7772 												AND           segment_rule_code = l_adr_rule_code
7773 												AND           amb_context_code = l_amb_context;
7774 											EXCEPTION
7775 												WHEN no_data_found THEN
7776 													l_adr_priority := 10;
7777 											END;
7778 											l_segment_rule_detail_id := NULL;
7779 											INSERT INTO xla_rule_details_t
7780 											(
7781 											APPLICATION_ID,
7782 											AMB_CONTEXT_CODE,
7783 											SEGMENT_RULE_TYPE_CODE,
7784 											SEGMENT_RULE_CODE,
7785 											SEGMENT_RULE_DETAIL_ID,
7786 											USER_SEQUENCE,
7787 											VALUE_TYPE_CODE,
7788 											VALUE_SOURCE_APPLICATION_ID,
7789 											VALUE_SOURCE_TYPE_CODE,
7790 											VALUE_SOURCE_CODE,
7791 											VALUE_CONSTANT,
7792 											VALUE_CODE_COMBINATION_ID,
7793 											VALUE_MAPPING_SET_CODE,
7794 											VALUE_FLEXFIELD_SEGMENT_CODE,
7795 											INPUT_SOURCE_APPLICATION_ID,
7796 											INPUT_SOURCE_TYPE_CODE,
7797 											INPUT_SOURCE_CODE,
7798 											VALUE_SEGMENT_RULE_APPL_ID,
7799 											VALUE_SEGMENT_RULE_TYPE_CODE,
7800 											VALUE_SEGMENT_RULE_CODE,
7801 											VALUE_ADR_VERSION_NUM,
7802 											ERROR_VALUE
7803 											)
7804 											VALUES
7805 											(
7806 											G_Application_id,
7807 											l_amb_context,
7808 											'C',
7809 											l_adr_rule_code,
7810 											xla_seg_rule_details_s.NEXTVAL,
7811 											l_adr_priority,
7812 											'C',
7813 											NULL,
7814 											NULL,
7815 											NULL,
7816 											l_segment_value,
7817 											NULL,
7818 											NULL,
7819 											NULL,
7820 											NULL,
7821 											NULL,
7822 											NULL,
7823 											NULL,
7824 											NULL,
7825 											NULL,
7826 											NULL,
7827 											0
7828 											) returning segment_rule_detail_id INTO l_segment_rule_detail_id;
7829 											IF l_segment_rule_detail_id IS NOT NULL THEN
7830 												insert_conditions (
7831 																					p_condition_tag               =>                'FIRST',
7832 																					p_sequence                    =>                l_adr_condition_priority,
7833 																					p_source                      =>                G_Journal_Line_Type,
7834 																					p_comparision_operator        =>                G_Equal,
7835 																					p_value_type                  =>                G_constant,
7836 																					p_value                       =>                k.acct_ttl_code,
7837 																					p_logical_operator            =>                G_And,
7838 																					p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7839 																					);
7840 												insert_conditions (
7841 																					p_condition_tag               =>                'MID',
7842 																					p_sequence                    =>                l_adr_condition_priority,
7843 																					p_source                      =>                G_ledger_id,
7844 																					p_comparision_operator        =>                G_Equal,
7845 																					p_value_type                  =>                G_constant,
7846 																					p_value                       =>                i.ledger_id,
7847 																					p_logical_operator            =>                G_And,
7848 																					p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7849 																					);
7850 												insert_conditions (
7851 																					p_condition_tag               =>                'MID',
7852 																					p_sequence                    =>                l_adr_condition_priority,
7853 																					p_source                      =>                G_legal_entity,
7854 																					p_comparision_operator        =>                G_Equal,
7855 																					p_value_type                  =>                G_constant,
7856 																					p_value                       =>                i.legal_entity_id,
7857 																					p_logical_operator            =>                G_And,
7858 																					p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7859 																					);
7860 												IF l_gl_category_id(m) IS NOT NULL THEN
7861 													insert_conditions (
7862 																						p_condition_tag               =>                'MID',
7863 																						p_sequence                    =>                l_adr_condition_priority,
7864 																						p_source                      =>                G_gl_category_id,
7865 																						p_comparision_operator        =>                G_Equal,
7866 																						p_value_type                  =>                G_constant,
7867 																						p_value                       =>                l_gl_category_id(m),
7868 																						p_logical_operator            =>                G_And,
7869 																						p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7870 																						);
7871 												END IF;
7872 												IF l_custgl_class(m) IS NOT NULL THEN
7873 													insert_conditions (
7874 																						p_condition_tag               =>                'MID',
7875 																						p_sequence                    =>                l_adr_condition_priority,
7876 																						p_source                      =>                G_custgl_class,
7877 																						p_comparision_operator        =>                G_Equal,
7878 																						p_value_type                  =>                G_constant,
7879 																						p_value                       =>                l_custgl_class(m),
7880 																						p_logical_operator            =>                G_And,
7881 																						p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7882 																						);
7883 												END IF;
7884 												IF l_vendgl_class(m) IS NOT NULL THEN
7885 													insert_conditions (
7886 																						p_condition_tag               =>                'MID',
7887 																						p_sequence                    =>                l_adr_condition_priority,
7888 																						p_source                      =>                G_vendgl_class,
7889 																						p_comparision_operator        =>                G_Equal,
7890 																						p_value_type                  =>                G_constant,
7891 																						p_value                       =>                l_vendgl_class(m),
7892 																						p_logical_operator            =>                G_And,
7893 																						p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7894 																						);
7895 												END IF;
7896 												IF l_item_id(m) IS NOT NULL THEN
7897 													l_inventory_item_id := gmf_migration.get_inventory_item_id(p_item_id => l_item_id(m));
7898 													IF l_inventory_item_id IS NOT NULL THEN
7899 														insert_conditions (
7900 																							p_condition_tag               =>                'MID',
7901 																							p_sequence                    =>                l_adr_condition_priority,
7902 																							p_source                      =>                G_Inventory_item_id,
7903 																							p_comparision_operator        =>                G_Equal,
7904 																							p_value_type                  =>                G_constant,
7905 																							p_value                       =>                l_inventory_item_id,
7906 																							p_logical_operator            =>                G_And,
7907 																							p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7908 																							);
7909 													END IF;
7910 												END IF;
7911 												IF l_cust_id(m) IS NOT NULL THEN
7912 													insert_conditions (
7913 																						p_condition_tag               =>                'MID',
7914 																						p_sequence                    =>                l_adr_condition_priority,
7915 																						p_source                      =>                G_customer,
7916 																						p_comparision_operator        =>                G_Equal,
7917 																						p_value_type                  =>                G_constant,
7918 																						p_value                       =>                l_cust_id(m),
7919 																						p_logical_operator            =>                G_And,
7920 																						p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7921 																						);
7922 												END IF;
7923 												IF l_vendor_id(m) IS NOT NULL THEN
7924                           l_vendor_site_id := Get_Vendor_id (p_vendor_id => l_vendor_id(m));
7925                           IF l_vendor_site_id IS NOT NULL THEN
7926   													insert_conditions (
7927   																						p_condition_tag               =>                'MID',
7928   																						p_sequence                    =>                l_adr_condition_priority,
7929   																						p_source                      =>                G_vendor,
7930   																						p_comparision_operator        =>                G_Equal,
7931   																						p_value_type                  =>                G_constant,
7932   																						p_value                       =>                l_vendor_site_id,
7933   																						p_logical_operator            =>                G_And,
7934   																						p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7935   																						);
7936                           END IF;
7937 												END IF;
7938 												IF l_currency_code(m) IS NOT NULL THEN
7939 													insert_conditions (
7940 																						p_condition_tag               =>                'MID',
7941 																						p_sequence                    =>                l_adr_condition_priority,
7942 																						p_source                      =>                G_currency_code,
7943 																						p_comparision_operator        =>                G_Equal,
7944 																						p_value_type                  =>                G_constant,
7945 																						p_value                       =>                l_currency_code(m),
7946 																						p_logical_operator            =>                G_And,
7947 																						p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7948 																						);
7949 												END IF;
7950 												IF l_reason_code(m) IS NOT NULL THEN
7951 													l_reason_id := gmf_migration.Get_reason_id(p_reason_code => l_reason_code(m));
7952 													IF l_reason_id IS NOT NULL THEN
7953 														insert_conditions (
7954 																							p_condition_tag               =>                'MID',
7955 																							p_sequence                    =>                l_adr_condition_priority,
7956 																							p_source                      =>                G_reason_id,
7957 																							p_comparision_operator        =>                G_Equal,
7958 																							p_value_type                  =>                G_constant,
7959 																							p_value                       =>                l_reason_id,
7960 																							p_logical_operator            =>                G_And,
7961 																							p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7962 																							);
7963 													END IF;
7964 												END IF;
7965 												IF l_routing_id(m) IS NOT NULL THEN
7966 													insert_conditions (
7967 																						p_condition_tag               =>                'MID',
7968 																						p_sequence                    =>                l_adr_condition_priority,
7969 																						p_source                      =>                G_routing_id,
7970 																						p_comparision_operator        =>                G_Equal,
7971 																						p_value_type                  =>                G_constant,
7972 																						p_value                       =>                l_routing_id(m),
7973 																						p_logical_operator            =>                G_And,
7974 																						p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7975 																						);
7976 												END IF;
7977 												IF l_aqui_cost_id(m) IS NOT NULL THEN
7978 													l_price_element_type_id := gmf_migration.Get_price_element_type_id(p_aqui_cost_id => l_aqui_cost_id(m));
7979 													IF l_price_element_type_id IS NOT NULL THEN
7980 														insert_conditions (
7981 																							p_condition_tag               =>                'MID',
7982 																							p_sequence                    =>                l_adr_condition_priority,
7983 																							p_source                      =>                G_price_element_type_id,
7984 																							p_comparision_operator        =>                G_Equal,
7985 																							p_value_type                  =>                G_constant,
7986 																							p_value                       =>                l_price_element_type_id,
7987 																							p_logical_operator            =>                G_And,
7988 																							p_segment_rule_detail_id      =>                l_segment_rule_detail_id
7989 																							);
7990 													END IF;
7991 												END IF;
7992 												IF l_resources(m) IS NOT NULL THEN
7993 													insert_conditions (
7994 																						p_condition_tag               =>                'MID',
7995 																						p_sequence                    =>                l_adr_condition_priority,
7996 																						p_source                      =>                G_resources,
7997 																						p_comparision_operator        =>                G_Equal,
7998 																						p_value_type                  =>                G_constant,
7999 																						p_value                       =>                l_resources(m),
8000 																						p_logical_operator            =>                G_And,
8001 																						p_segment_rule_detail_id      =>                l_segment_rule_detail_id
8002 																						);
8003 												END IF;
8004 												IF l_cost_cmpntcls_id(m) IS NOT NULL THEN
8005 													insert_conditions (
8006 																						p_condition_tag               =>                'MID',
8007 																						p_sequence                    =>                l_adr_condition_priority,
8008 																						p_source                      =>                G_cost_cmpntcls_id,
8009 																						p_comparision_operator        =>                G_Equal,
8010 																						p_value_type                  =>                G_constant,
8011 																						p_value                       =>                l_cost_cmpntcls_id(m),
8012 																						p_logical_operator            =>                G_And,
8013 																						p_segment_rule_detail_id      =>                l_segment_rule_detail_id
8014 																						);
8015 												END IF;
8016 												IF l_cost_analysis_code(m) IS NOT NULL THEN
8017 													insert_conditions (
8018 																						p_condition_tag               =>                'MID',
8019 																						p_sequence                    =>                l_adr_condition_priority,
8020 																						p_source                      =>                G_cost_analysis_code,
8021 																						p_comparision_operator        =>                G_Equal,
8022 																						p_value_type                  =>                G_constant,
8023 																						p_value                       =>                l_cost_analysis_code(m),
8024 																						p_logical_operator            =>                G_And,
8025 																						p_segment_rule_detail_id      =>                l_segment_rule_detail_id
8026 																						);
8027 												END IF;
8028 												IF l_order_type(m) IS NOT NULL THEN
8029 													insert_conditions (
8030 																						p_condition_tag               =>                'MID',
8031 																						p_sequence                    =>                l_adr_condition_priority,
8032 																						p_source                      =>                G_order_type,
8033 																						p_comparision_operator        =>                G_Equal,
8034 																						p_value_type                  =>                G_constant,
8035 																						p_value                       =>                l_order_type(m),
8036 																						p_logical_operator            =>                G_And,
8037 																						p_segment_rule_detail_id      =>                l_segment_rule_detail_id
8038 																						);
8039 												END IF;
8040 												IF l_gl_business_class_cat_id(m) IS NOT NULL THEN
8041 													insert_conditions (
8042 																						p_condition_tag               =>                'MID',
8043 																						p_sequence                    =>                l_adr_condition_priority,
8044 																						p_source                      =>                G_gl_business_class_cat_id,
8045 																						p_comparision_operator        =>                G_Equal,
8046 																						p_value_type                  =>                G_constant,
8047 																						p_value                       =>                l_gl_business_class_cat_id(m),
8048 																						p_logical_operator            =>                G_And,
8049 																						p_segment_rule_detail_id      =>                l_segment_rule_detail_id
8050 																						);
8051 												END IF;
8052 												IF l_gl_product_line_cat_id(m) IS NOT NULL THEN
8053 													insert_conditions (
8054 																						p_condition_tag               =>                'MID',
8055 																						p_sequence                    =>                l_adr_condition_priority,
8056 																						p_source                      =>                G_gl_product_line_cat_id,
8057 																						p_comparision_operator        =>                G_Equal,
8058 																						p_value_type                  =>                G_constant,
8059 																						p_value                       =>                l_gl_product_line_cat_id(m),
8060 																						p_logical_operator            =>                G_And,
8061 																						p_segment_rule_detail_id      =>                l_segment_rule_detail_id
8062 																						);
8063 												END IF;
8064 												IF l_line_type(m) IS NOT NULL THEN
8065 													insert_conditions (
8066 																						p_condition_tag               =>                'MID',
8067 																						p_sequence                    =>                l_adr_condition_priority,
8068 																						p_source                      =>                G_line_type,
8069 																						p_comparision_operator        =>                G_Equal,
8070 																						p_value_type                  =>                G_constant,
8071 																						p_value                       =>                l_line_type(m),
8072 																						p_logical_operator            =>                G_And,
8073 																						p_segment_rule_detail_id      =>                l_segment_rule_detail_id
8074 																						);
8075 												END IF;
8076 												IF l_ar_trx_type_id(m) IS NOT NULL THEN
8077 													insert_conditions (
8078 																						p_condition_tag               =>                'MID',
8079 																						p_sequence                    =>                l_adr_condition_priority,
8080 																						p_source                      =>                G_ar_trx_type,
8081 																						p_comparision_operator        =>                G_Equal,
8082 																						p_value_type                  =>                G_constant,
8083 																						p_value                       =>                l_ar_trx_type_id(m),
8084 																						p_logical_operator            =>                G_And,
8085 																						p_segment_rule_detail_id      =>                l_segment_rule_detail_id
8086 																						);
8087 												END IF;
8088 												IF l_orgn_code(m) IS NOT NULL THEN
8089 													IF l_whse_code(m) IS NOT NULL AND nvl(l_subinventory_ind_flag(m),'N') = 'Y' AND NVL(l_inventory_org_ind(m),'N') = 'Y' THEN
8090 														/************************************************************
8091 														* OPM Organizations is Migrated as inventory Organization   *
8092 														************************************************************/
8093 														insert_conditions (
8094 																							p_condition_tag               =>                'MID',
8095 																							p_sequence                    =>                l_adr_condition_priority,
8096 																							p_source                      =>                G_Organization,
8097 																							p_comparision_operator        =>                G_Equal,
8098 																							p_value_type                  =>                G_constant,
8099 																							p_value                       =>                l_organization_id(m),
8100 																							p_logical_operator            =>                G_and,
8101 																							p_segment_rule_detail_id       =>               l_segment_rule_detail_id
8102 																							);
8103 														 /*******************************************************************
8104 														 * Warehouse Code Is specified and is migrated as subinventories    *
8105 														 *******************************************************************/
8106 														 insert_conditions (
8107 																							 p_condition_tag               =>                'LAST',
8108 																							 p_sequence                    =>                l_adr_condition_priority,
8109 																							 p_source                      =>                G_subinventory,
8110 																							 p_comparision_operator        =>                G_Equal,
8111 																							 p_value_type                  =>                G_constant,
8112 																							 p_value                       =>                l_whse_code(m),
8113 																							 p_logical_operator            =>                NULL,
8114 																							 p_segment_rule_detail_id      =>                l_segment_rule_detail_id
8115 																							 );
8116 													ELSIF l_whse_code(m) IS NOT NULL AND nvl(l_subinventory_ind_flag(m),'N') <> 'Y' THEN
8117 														insert_conditions (
8118 																							p_condition_tag               =>                'LAST',
8119 																							p_sequence                    =>                l_adr_condition_priority,
8120 																							p_source                      =>                G_Organization,
8121 																							p_comparision_operator        =>                G_Equal,
8122 																							p_value_type                  =>                G_constant,
8123 																							p_value                       =>                l_mtl_organization_id(m),
8124 																							p_logical_operator            =>                G_and,
8125 																							p_segment_rule_detail_id       =>               l_segment_rule_detail_id
8126 																							);
8127 													ELSE
8128 														l_old_segment_rule_detail_id := l_segment_rule_detail_id;
8129 														l_old_adr_condition_priority := l_adr_condition_priority;
8130 														mcnt := 1;
8131 														<<WAREHOUSE_ACCOUNT>>
8132 														FOR n IN cur_whse_acct(l_orgn_code(m), i.co_code, l_acct_id(m)) LOOP
8133 															IF n.mtl_organization_id <> nvl(l_organization_id(m), -1) THEN
8134 																IF mcnt > 1 THEN
8135 																	BEGIN
8136 																		SELECT          NVL(MAX(nvl(user_sequence,0)) + 10,10)
8137 																		INTO            l_adr_priority
8138 																		FROM            xla_rule_details_t
8139 																		WHERE           application_id = G_Application_id
8140 																		AND             segment_rule_code = l_adr_rule_code
8141 																		AND             amb_context_code = l_amb_context;
8142 																	EXCEPTION
8143 																		WHEN no_data_found THEN
8144 																			l_adr_priority := 10;
8145 																	END;
8146 																	INSERT INTO xla_rule_details_t
8147 																	(
8148 																	APPLICATION_ID,
8149 																	AMB_CONTEXT_CODE,
8150 																	SEGMENT_RULE_TYPE_CODE,
8151 																	SEGMENT_RULE_CODE,
8152 																	SEGMENT_RULE_DETAIL_ID,
8153 																	USER_SEQUENCE,
8154 																	VALUE_TYPE_CODE,
8155 																	VALUE_SOURCE_APPLICATION_ID,
8156 																	VALUE_SOURCE_TYPE_CODE,
8157 																	VALUE_SOURCE_CODE,
8158 																	VALUE_CONSTANT,
8159 																	VALUE_CODE_COMBINATION_ID,
8160 																	VALUE_MAPPING_SET_CODE,
8161 																	VALUE_FLEXFIELD_SEGMENT_CODE,
8162 																	INPUT_SOURCE_APPLICATION_ID,
8163 																	INPUT_SOURCE_TYPE_CODE,
8164 																	INPUT_SOURCE_CODE,
8165 																	VALUE_SEGMENT_RULE_APPL_ID,
8166 																	VALUE_SEGMENT_RULE_TYPE_CODE,
8167 																	VALUE_SEGMENT_RULE_CODE,
8168 																	VALUE_ADR_VERSION_NUM,
8169 																	ERROR_VALUE
8170 																	)
8171 																	VALUES
8172 																	(
8173 																	G_Application_id,
8174 																	l_amb_context,
8175 																	'C',
8176 																	l_adr_rule_code,
8177 																	xla_seg_rule_details_s.NEXTVAL,
8178 																	l_adr_priority,
8179 																	'C',
8180 																	NULL,
8181 																	NULL,
8182 																	NULL,
8183 																	l_segment_value,
8184 																	NULL,
8185 																	NULL,
8186 																	NULL,
8187 																	NULL,
8188 																	NULL,
8189 																	NULL,
8190 																	NULL,
8191 																	NULL,
8192 																	NULL,
8193 																	NULL,
8194 																	0
8195 																	) returning segment_rule_detail_id INTO l_segment_rule_detail_id;
8196 																	INSERT INTO xla_conditions_t
8197 																	(
8198 																	CONDITION_ID,
8199 																	APPLICATION_ID,
8200 																	AMB_CONTEXT_CODE,
8201 																	SEGMENT_RULE_DETAIL_ID,
8202 																	USER_SEQUENCE,
8203 																	BRACKET_LEFT_CODE,
8204 																	BRACKET_RIGHT_CODE,
8205 																	VALUE_TYPE_CODE,
8206 																	SOURCE_APPLICATION_ID,
8207 																	SOURCE_TYPE_CODE,
8208 																	SOURCE_CODE,
8209 																	FLEXFIELD_SEGMENT_CODE,
8210 																	VALUE_FLEXFIELD_SEGMENT_CODE,
8211 																	VALUE_SOURCE_APPLICATION_ID,
8212 																	VALUE_SOURCE_TYPE_CODE,
8213 																	VALUE_SOURCE_CODE,
8214 																	VALUE_CONSTANT,
8215 																	LINE_OPERATOR_CODE,
8216 																	LOGICAL_OPERATOR_CODE,
8217 																	INDEPENDENT_VALUE_CONSTANT,
8218 																	ERROR_VALUE
8219 																	)
8220 																	(
8221 																	SELECT          xla_conditions_s.NEXTVAL,
8222 																									APPLICATION_ID,
8223 																									AMB_CONTEXT_CODE,
8224 																									l_segment_rule_detail_id,
8225 																									USER_SEQUENCE,
8226 																									BRACKET_LEFT_CODE,
8227 																									BRACKET_RIGHT_CODE,
8228 																									VALUE_TYPE_CODE,
8229 																									SOURCE_APPLICATION_ID,
8230 																									SOURCE_TYPE_CODE,
8231 																									SOURCE_CODE,
8232 																									FLEXFIELD_SEGMENT_CODE,
8233 																									VALUE_FLEXFIELD_SEGMENT_CODE,
8234 																									VALUE_SOURCE_APPLICATION_ID,
8235 																									VALUE_SOURCE_TYPE_CODE,
8236 																									VALUE_SOURCE_CODE,
8237 																									VALUE_CONSTANT,
8238 																									LINE_OPERATOR_CODE,
8239 																									LOGICAL_OPERATOR_CODE,
8240 																									INDEPENDENT_VALUE_CONSTANT,
8241 																									ERROR_VALUE
8242 																	FROM            xla_conditions_t
8243 																	WHERE           segment_rule_detail_id = l_old_segment_rule_detail_id
8244 																	AND             amb_context_code = l_amb_context
8245 																	AND             user_sequence <= l_old_adr_condition_priority
8246 																	);
8247 																	l_adr_condition_priority := l_old_adr_condition_priority;
8248 																END IF;
8249 																IF nvl(n.subinventory_ind_flag,'N') = 'Y' THEN
8250 																	/************************************************************
8251 																	* OPM Organizations is Migrated as inventory Organization   *
8252 																	************************************************************/
8253 																	insert_conditions (
8254 																										p_condition_tag               =>                'MID',
8255 																										p_sequence                    =>                l_adr_condition_priority,
8256 																										p_source                      =>                G_Organization,
8257 																										p_comparision_operator        =>                G_Equal,
8258 																										p_value_type                  =>                G_constant,
8259 																										p_value                       =>                l_organization_id(m),
8260 																										p_logical_operator            =>                G_and,
8261 																										p_segment_rule_detail_id       =>               l_segment_rule_detail_id
8262 																										);
8263 																	 /*******************************************************************
8264 																	 * Warehouse Code Is specified and is migrated as subinventories    *
8265 																	 *******************************************************************/
8266 																	 insert_conditions (
8267 																										 p_condition_tag               =>                'LAST',
8268 																										 p_sequence                    =>                l_adr_condition_priority,
8269 																										 p_source                      =>                G_subinventory,
8270 																										 p_comparision_operator        =>                G_Equal,
8271 																										 p_value_type                  =>                G_constant,
8272 																										 p_value                       =>                n.whse_code,
8273 																										 p_logical_operator            =>                NULL,
8274 																										 p_segment_rule_detail_id      =>                l_segment_rule_detail_id
8275 																										 );
8276 																ELSIF nvl(n.subinventory_ind_flag,'N') <> 'Y' THEN
8277 																	insert_conditions (
8278 																										p_condition_tag               =>                'LAST',
8279 																										p_sequence                    =>                l_adr_condition_priority,
8280 																										p_source                      =>                G_Organization,
8281 																										p_comparision_operator        =>                G_Equal,
8282 																										p_value_type                  =>                G_constant,
8283 																										p_value                       =>                n.mtl_organization_id,
8284 																										p_logical_operator            =>                G_and,
8285 																										p_segment_rule_detail_id       =>               l_segment_rule_detail_id
8286 																										);
8287 																END IF;
8288 																mcnt := nvl(mcnt,1) + 1;
8289 															END IF;
8290 														END LOOP WAREHOUSE_ACCOUNT;
8291 														IF NVL(l_inventory_org_ind(m),'N') = 'Y' AND nvl(mcnt, 1) > 1 THEN
8292 															BEGIN
8293 																SELECT        NVL(MAX(nvl(user_sequence,0)) + 10,10)
8294 																INTO          l_adr_priority
8295 																FROM          xla_rule_details_t
8296 																WHERE         application_id = G_Application_id
8297 																AND           segment_rule_code = l_adr_rule_code
8298 																AND           amb_context_code = l_amb_context;
8299 															EXCEPTION
8300 																WHEN no_data_found THEN
8301 																	l_adr_priority := 10;
8302 															END;
8303 															l_segment_rule_detail_id := NULL;
8304 															INSERT INTO xla_rule_details_t
8305 															(
8306 															APPLICATION_ID,
8307 															AMB_CONTEXT_CODE,
8308 															SEGMENT_RULE_TYPE_CODE,
8309 															SEGMENT_RULE_CODE,
8310 															SEGMENT_RULE_DETAIL_ID,
8311 															USER_SEQUENCE,
8312 															VALUE_TYPE_CODE,
8313 															VALUE_SOURCE_APPLICATION_ID,
8314 															VALUE_SOURCE_TYPE_CODE,
8315 															VALUE_SOURCE_CODE,
8316 															VALUE_CONSTANT,
8317 															VALUE_CODE_COMBINATION_ID,
8318 															VALUE_MAPPING_SET_CODE,
8319 															VALUE_FLEXFIELD_SEGMENT_CODE,
8320 															INPUT_SOURCE_APPLICATION_ID,
8321 															INPUT_SOURCE_TYPE_CODE,
8322 															INPUT_SOURCE_CODE,
8323 															VALUE_SEGMENT_RULE_APPL_ID,
8324 															VALUE_SEGMENT_RULE_TYPE_CODE,
8325 															VALUE_SEGMENT_RULE_CODE,
8326 															VALUE_ADR_VERSION_NUM,
8327 															ERROR_VALUE
8328 															)
8329 															VALUES
8330 															(
8331 															G_Application_id,
8332 															l_amb_context,
8333 															'C',
8334 															l_adr_rule_code,
8335 															xla_seg_rule_details_s.NEXTVAL,
8336 															l_adr_priority,
8337 															'C',
8338 															NULL,
8339 															NULL,
8340 															NULL,
8341 															l_segment_value,
8342 															NULL,
8343 															NULL,
8344 															NULL,
8345 															NULL,
8346 															NULL,
8347 															NULL,
8348 															NULL,
8349 															NULL,
8350 															NULL,
8351 															NULL,
8352 															0
8353 															) returning segment_rule_detail_id INTO l_segment_rule_detail_id;
8354 															INSERT INTO xla_conditions_t
8355 															(
8356 															CONDITION_ID,
8357 															APPLICATION_ID,
8358 															AMB_CONTEXT_CODE,
8359 															SEGMENT_RULE_DETAIL_ID,
8360 															USER_SEQUENCE,
8361 															BRACKET_LEFT_CODE,
8362 															BRACKET_RIGHT_CODE,
8363 															VALUE_TYPE_CODE,
8364 															SOURCE_APPLICATION_ID,
8365 															SOURCE_TYPE_CODE,
8366 															SOURCE_CODE,
8367 															FLEXFIELD_SEGMENT_CODE,
8368 															VALUE_FLEXFIELD_SEGMENT_CODE,
8369 															VALUE_SOURCE_APPLICATION_ID,
8370 															VALUE_SOURCE_TYPE_CODE,
8371 															VALUE_SOURCE_CODE,
8372 															VALUE_CONSTANT,
8373 															LINE_OPERATOR_CODE,
8374 															LOGICAL_OPERATOR_CODE,
8375 															INDEPENDENT_VALUE_CONSTANT,
8376 															ERROR_VALUE
8377 															)
8378 															(
8379 															SELECT          xla_conditions_s.NEXTVAL,
8380 																							APPLICATION_ID,
8381 																							AMB_CONTEXT_CODE,
8382 																							l_segment_rule_detail_id,
8383 																							USER_SEQUENCE,
8384 																							BRACKET_LEFT_CODE,
8385 																							BRACKET_RIGHT_CODE,
8386 																							VALUE_TYPE_CODE,
8387 																							SOURCE_APPLICATION_ID,
8388 																							SOURCE_TYPE_CODE,
8389 																							SOURCE_CODE,
8390 																							FLEXFIELD_SEGMENT_CODE,
8391 																							VALUE_FLEXFIELD_SEGMENT_CODE,
8392 																							VALUE_SOURCE_APPLICATION_ID,
8393 																							VALUE_SOURCE_TYPE_CODE,
8394 																							VALUE_SOURCE_CODE,
8395 																							VALUE_CONSTANT,
8396 																							LINE_OPERATOR_CODE,
8397 																							LOGICAL_OPERATOR_CODE,
8398 																							INDEPENDENT_VALUE_CONSTANT,
8399 																							ERROR_VALUE
8400 															FROM            xla_conditions_t
8401 															WHERE           segment_rule_detail_id = l_old_segment_rule_detail_id
8402 															AND             amb_context_code = l_amb_context
8403 															AND             user_sequence <= l_old_adr_condition_priority
8404 															);
8405 															l_adr_condition_priority := l_old_adr_condition_priority;
8406 															insert_conditions (
8407 																								p_condition_tag               =>                'LAST',
8408 																								p_sequence                    =>                l_adr_condition_priority,
8409 																								p_source                      =>                G_Organization,
8410 																								p_comparision_operator        =>                G_Equal,
8411 																								p_value_type                  =>                G_constant,
8412 																								p_value                       =>                l_organization_id(m),
8413 																								p_logical_operator            =>                G_and,
8414 																								p_segment_rule_detail_id       =>               l_segment_rule_detail_id
8415 																								);
8416 														ELSIF NVL(l_inventory_org_ind(m),'N') <> 'Y' THEN
8417 															BEGIN
8418 																UPDATE    xla_conditions_t
8419 																SET       logical_operator_code = NULL
8420 																WHERE     user_sequence = l_adr_condition_priority
8421 																AND       segment_rule_detail_id = l_segment_rule_detail_id
8422 																AND       amb_context_code = l_amb_context;
8423 															EXCEPTION
8424 																WHEN OTHERS THEN
8425 																	NULL;
8426 															END;
8427 														ELSE
8428 															insert_conditions (
8429 																								p_condition_tag               =>                'LAST',
8430 																								p_sequence                    =>                l_adr_condition_priority,
8431 																								p_source                      =>                G_Organization,
8432 																								p_comparision_operator        =>                G_Equal,
8433 																								p_value_type                  =>                G_constant,
8434 																								p_value                       =>                l_organization_id(m),
8435 																								p_logical_operator            =>                G_and,
8436 																								p_segment_rule_detail_id       =>               l_segment_rule_detail_id
8437 																								);
8438 														END IF;
8439 													END IF;
8440 												ELSE
8441 													BEGIN
8442 														UPDATE    xla_conditions_t
8443 														SET       logical_operator_code = NULL
8444 														WHERE     user_sequence = l_adr_condition_priority
8445 														AND       segment_rule_detail_id = l_segment_rule_detail_id
8446 														AND       amb_context_code = l_amb_context;
8447 													EXCEPTION
8448 														WHEN OTHERS THEN
8449 															NULL;
8450 													END;
8451 												END IF;
8452 										END IF;
8453 									END LOOP GL_ACCT_MAP;
8454 								END IF;
8455 							END IF;
8456 						END LOOP POLICY_SEGMENTS;
8457 						BEGIN
8458 							UPDATE    gl_acct_map
8459 							SET       migrated_ind = 1
8460 							WHERE     co_code = i.co_code
8461 							AND       acct_ttl_type = k.acct_ttl_type;
8462 						EXCEPTION
8463 							WHEN OTHERS THEN
8464 								RAISE;
8465 						END;
8466 				 END LOOP LEGAL_ENTITIES;
8467 			END LOOP ACCOUNT_TITLE;
8468       BEGIN
8469 				UPDATE    GL_ACCU_MAP
8470 				SET       MIGRATED_IND = 1;
8471 			EXCEPTION
8472 				WHEN OTHERS THEN
8473 					RAISE;
8474 			END;
8475 			/******************************************************
8476 			* Upload Data IN XLA interface tables into XLA tables *
8477 			******************************************************/
8478 			xla_adr_interface_pkg.upload_rules;
8479 			/****************************************************************
8480 			* Lets save the changes now based on the commit parameter       *
8481 			****************************************************************/
8482 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
8483 				COMMIT;
8484 			END IF;
8485 			/************************************
8486 			* ADR Rules Migration Error Logging *
8487 			************************************/
8488 			gmf_migration.G_Table_name := 'XLA_RULES_T';
8489 			gmf_migration.G_context := 'GMF Error Logging';
8490 			gmf_migration.Log_Errors  (
8491 																p_log_level               =>          1,
8492 																p_from_rowid              =>          NULL,
8493 																p_to_rowid                =>          NULL
8494 																);
8495 			/*******************************************
8496 			* ADR Rule Details Migration Error Logging *
8497 			*******************************************/
8498 			gmf_migration.G_Table_name := 'XLA_RULE_DETAILS_T';
8499 			gmf_migration.G_context := 'GMF Error Logging';
8500 			gmf_migration.Log_Errors  (
8501 																p_log_level               =>          1,
8502 																p_from_rowid              =>          NULL,
8503 																p_to_rowid                =>          NULL
8504 																);
8505 			/*****************************************
8506 			* ADR Conditions Migration Error Logging *
8507 			*****************************************/
8508 			gmf_migration.G_Table_name := 'XLA_CONDITIONS_T';
8509 			gmf_migration.G_context := 'GMF Error Logging';
8510 			gmf_migration.Log_Errors  (
8511 																p_log_level               =>          1,
8512 																p_from_rowid              =>          NULL,
8513 																p_to_rowid                =>          NULL
8514 																);
8515 			/***********************************************
8516 			* ADR Line Assignments Migration Error Logging *
8517 			***********************************************/
8518 			gmf_migration.G_Table_name := 'XLA_LINE_ASSGNS_T';
8519 			gmf_migration.G_context := 'GMF Error Logging';
8520 			gmf_migration.Log_Errors  (
8521 																p_log_level               =>          1,
8522 																p_from_rowid              =>          NULL,
8523 																p_to_rowid                =>          NULL
8524 																);
8525 	EXCEPTION
8526 		WHEN OTHERS THEN
8527 			/************************************************
8528 			* Increment Failure Count for Failed Migrations *
8529 			************************************************/
8530 			x_failure_count := x_failure_count + 1;
8531 			/**************************************
8532 			* Migration DB Error Log Message      *
8533 			**************************************/
8534 			GMA_COMMON_LOGGING.gma_migration_central_log
8535 			(
8536 			p_run_id             =>       G_migration_run_id,
8537 			p_log_level          =>       FND_LOG.LEVEL_ERROR,
8538 			p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
8539 			p_table_name         =>       G_Table_name,
8540 			p_context            =>       G_Context,
8541 			p_db_error           =>       SQLERRM,
8542 			p_app_short_name     =>       'GMA'
8543 			);
8544 			/**************************************
8545 			* Migration Failure Log Message       *
8546 			**************************************/
8547 			GMA_COMMON_LOGGING.gma_migration_central_log
8548 			(
8549 			p_run_id             =>       G_migration_run_id,
8550 			p_log_level          =>       FND_LOG.LEVEL_ERROR,
8551 			p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
8552 			p_table_name         =>       G_Table_name,
8553 			p_context            =>       G_Context,
8554 			p_db_error           =>       NULL,
8555 			p_app_short_name     =>       'GMA'
8556 			);
8557 	 END Migrate_Account_Mappings;
8558 
8559 	 /**********************************************************************
8560 	 * PROCEDURE:                                                          *
8561 	 *   Migrate_Acquisition_codes                                         *
8562 	 *                                                                     *
8563 	 * DESCRIPTION:                                                        *
8564 	 *   This PL/SQL procedure is used to migrate the Acquisition Codes    *
8565 	 *                                                                     *
8566 	 * PARAMETERS:                                                         *
8567 	 *   P_migration_run_id - id to use to right to migration log          *
8568 	 *   x_exception_count  - Number of exceptions occurred.               *
8569 	 *                                                                     *
8570 	 * SYNOPSIS:                                                           *
8571 	 *   Migrate_Acquisition_Codes(p_migartion_id    => l_migration_id,    *
8572 	 *                    p_commit          => 'T',                        *
8573 	 *                    x_exception_count => l_exception_count );        *
8574 	 *                                                                     *
8575 	 * HISTORY                                                             *
8576 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
8577 	 *                                                                     *
8578 	 **********************************************************************/
8579 	 PROCEDURE Migrate_Acquisition_Codes
8580 	 (
8581 	 P_migration_run_id      IN             NUMBER,
8582 	 P_commit                IN             VARCHAR2,
8583 	 X_failure_count         OUT   NOCOPY   NUMBER
8584 	 )
8585 	 IS
8586 
8587 			/**************************
8588 			* PL/SQL Table Definition *
8589 			**************************/
8590 
8591 			TYPE t_rowid IS TABLE OF ROWID INDEX BY BINARY_INTEGER;
8592 			TYPE t_price_element_type_id IS TABLE OF PO_COST_MST.PRICE_ELEMENT_TYPE_ID%TYPE INDEX BY BINARY_INTEGER;
8593 			TYPE t_aqui_cost_code IS TABLE OF PO_COST_MST.AQUI_COST_CODE%TYPE INDEX BY BINARY_INTEGER;
8594 			TYPE t_aqui_cost_desc IS TABLE OF PO_COST_MST.AQUI_COST_DESC%TYPE INDEX BY BINARY_INTEGER;
8595 			TYPE t_cmpntcls_id IS TABLE OF PO_COST_MST.CMPNTCLS_ID%TYPE INDEX BY BINARY_INTEGER;
8596 			TYPE t_analysis_code IS TABLE OF PO_COST_MST.ANALYSIS_CODE%TYPE INDEX BY BINARY_INTEGER;
8597 			TYPE t_incl_ind IS TABLE OF PO_COST_MST.INCL_IND%TYPE INDEX BY BINARY_INTEGER;
8598 
8599 			/******************
8600 			* Local Variables *
8601 			******************/
8602 
8603 			l_rowid                             t_rowid;
8604 			l_aqui_cost_code                    t_aqui_cost_code;
8605 			l_aqui_cost_desc                    t_aqui_cost_desc;
8606 			l_cmpntcls_id                       t_cmpntcls_id;
8607 			l_analysis_code                     t_analysis_code;
8608 			l_incl_ind                          t_incl_ind;
8609 			l_price_element_type_id             t_price_element_type_id;
8610 
8611 			l_exception_count                   NUMBER := 0;
8612 			l_pricing_basis                     VARCHAR2(10);
8613 			l_cost_acquisition_code             VARCHAR2(1);
8614 			l_return_status                     VARCHAR2(1);
8615 			l_msg_data                          VARCHAR2(2000);
8616 			l_msg_count                         NUMBER;
8617 			l_insert_update_flag                VARCHAR2(10);
8618 
8619 	 BEGIN
8620 
8621 			G_Migration_run_id := P_migration_run_id;
8622 			G_Table_name := 'PO_COST_MST';
8623 			G_Context := 'Acquisiton Codes Migration';
8624 			X_failure_count := 0;
8625 
8626 			/********************************
8627 			* Migration Started Log Message *
8628 			********************************/
8629 
8630 			GMA_COMMON_LOGGING.gma_migration_central_log
8631 			(
8632 			p_run_id             =>       G_migration_run_id,
8633 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
8634 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
8635 			p_table_name         =>       G_Table_name,
8636 			p_context            =>       G_context,
8637 			p_db_error           =>       NULL,
8638 			p_app_short_name     =>       'GMA'
8639 			);
8640 
8641 			SELECT               ROWID,
8642 													 aqui_cost_code,
8643 													 aqui_cost_desc,
8644 													 cmpntcls_id,
8645 													 analysis_code,
8646 													 incl_ind
8647 			BULK COLLECT INTO    l_rowid,
8648 													 l_aqui_cost_code,
8649 													 l_aqui_cost_desc,
8650 													 l_cmpntcls_id,
8651 													 l_analysis_code,
8652 													 l_incl_ind
8653 			FROM                 po_cost_mst
8654 			WHERE                price_element_type_id IS NULL;
8655 
8656 			l_pricing_basis := 'PER_UNIT';
8657 
8658 			IF SQL%FOUND THEN
8659 
8660 				 FOR i IN l_rowid.FIRST..l_rowid.LAST LOOP
8661 
8662 						CASE l_incl_ind(i)
8663 							 WHEN 1 THEN
8664 								 l_cost_acquisition_code := 'I';
8665 							 WHEN 0 THEN
8666 								 l_cost_acquisition_code := 'E';
8667 							 ELSE
8668 								 l_cost_acquisition_code := 'I';
8669 						END CASE;
8670 
8671 						PON_CF_TYPE_GRP.opm_create_update_cost_factor
8672 						(
8673 						p_api_version               =>             1.0
8674 						, p_price_element_code      =>             l_aqui_cost_code(i)
8675 						, p_pricing_basis           =>             'PER_UNIT'
8676 						, p_cost_component_class_id =>             l_cmpntcls_id(i)
8677 						, p_cost_analysis_code      =>             l_analysis_code(i)
8678 						, p_cost_acquisition_code   =>             l_cost_acquisition_code
8679 						, p_name                    =>             l_aqui_cost_code(i)
8680 						, p_description             =>             l_aqui_cost_desc(i)
8681 						, x_insert_update_action    =>             l_insert_update_flag
8682 						, x_price_element_type_id   =>             l_price_element_type_id(i)
8683 						, x_pricing_basis           =>             l_pricing_basis
8684 						, x_return_status           =>             l_return_status
8685 						, x_msg_data                =>             l_msg_data
8686 						, x_msg_count               =>             l_msg_count
8687 						);
8688 
8689 				 END LOOP;
8690 
8691 				 FORALL j IN indices OF l_rowid SAVE EXCEPTIONS
8692 						UPDATE      po_cost_mst
8693 						SET         migrated_ind = 1,
8694 												price_element_type_id = l_price_element_type_id(j)
8695 						WHERE       ROWID = l_rowid(j)
8696 						AND         price_element_type_id IS NULL;
8697 
8698 				 l_exception_count := nvl(l_exception_count,0) + SQL%BULK_EXCEPTIONS.COUNT;
8699 
8700 				 FOR i IN 1..SQL%BULK_EXCEPTIONS.COUNT LOOP
8701 
8702 						/************************************************
8703 						* Increment Failure Count for Failed Migrations *
8704 						************************************************/
8705 
8706 						x_failure_count := x_failure_count + 1;
8707 
8708 						/**************************************
8709 						* Migration DB Error Log Message      *
8710 						**************************************/
8711 
8712 						GMA_COMMON_LOGGING.gma_migration_central_log
8713 						(
8714 						p_run_id             =>       G_migration_run_id,
8715 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
8716 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
8717 						p_table_name         =>       G_Table_name,
8718 						p_context            =>       G_context,
8719 						p_db_error           =>       SQLERRM(SQL%BULK_EXCEPTIONS(i).ERROR_CODE),
8720 						p_app_short_name     =>       'GMA'
8721 						);
8722 
8723 						/**************************************
8724 						* Migration Failure Log Message       *
8725 						**************************************/
8726 
8727 						GMA_COMMON_LOGGING.gma_migration_central_log
8728 						(
8729 						p_run_id             =>       G_migration_run_id,
8730 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
8731 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
8732 						p_table_name         =>       G_Table_name,
8733 						p_context            =>       G_context,
8734 						p_app_short_name     =>       'GMA'
8735 						);
8736 
8737 				 END LOOP;
8738 
8739 				 /**********************************************
8740 				 * Handle all the rows which were not migrated *
8741 				 **********************************************/
8742 
8743 				 SELECT               count(*)
8744 				 INTO                 x_failure_count
8745 				 FROM                 po_cost_mst
8746 				 WHERE                price_element_type_id IS NULL;
8747 
8748 				 IF nvl(x_failure_count,0) > 0 THEN
8749 
8750 					 /**************************************
8751 					 * Migration Failure Log Message       *
8752 					 **************************************/
8753 
8754 					 GMA_COMMON_LOGGING.gma_migration_central_log
8755 					 (
8756 					 p_run_id             =>       gmf_migration.G_migration_run_id,
8757 					 p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
8758 					 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
8759 					 p_table_name         =>       gmf_migration.G_Table_name,
8760 					 p_context            =>       gmf_migration.G_context,
8761 					 p_db_error           =>       NULL,
8762 					 p_app_short_name     =>       'GMA'
8763 					 );
8764 
8765 				 ELSE
8766 
8767 					 /**************************************
8768 					 * Migration Success Log Message       *
8769 					 **************************************/
8770 
8771 					 GMA_COMMON_LOGGING.gma_migration_central_log
8772 					 (
8773 					 p_run_id             =>       G_migration_run_id,
8774 					 p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
8775 					 p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
8776 					 p_table_name         =>       G_Table_name,
8777 					 p_context            =>       G_Context,
8778 					 p_param1             =>       1,
8779 					 p_param2             =>       0,
8780 					 p_db_error           =>       NULL,
8781 					 p_app_short_name     =>       'GMA'
8782 					 );
8783 
8784 				 END IF;
8785 
8786 				 /****************************************************************
8787 				 * Lets save the changes now based on the commit parameter       *
8788 				 ****************************************************************/
8789 
8790 				 IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
8791 						COMMIT;
8792 				 END IF;
8793 
8794 			END IF;
8795 
8796 	 EXCEPTION
8797 			WHEN OTHERS THEN
8798 
8799 				 /************************************************
8800 				 * Increment Failure Count for Failed Migrations *
8801 				 ************************************************/
8802 
8803 				 x_failure_count := x_failure_count + 1;
8804 
8805 				 /**************************************
8806 				 * Migration DB Error Log Message      *
8807 				 **************************************/
8808 
8809 				 GMA_COMMON_LOGGING.gma_migration_central_log
8810 				 (
8811 				 p_run_id             =>       G_migration_run_id,
8812 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
8813 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
8814 				 p_table_name         =>       G_Table_name,
8815 				 p_context            =>       G_context,
8816 				 p_db_error           =>       SQLERRM,
8817 				 p_app_short_name     =>       'GMA'
8818 				 );
8819 
8820 				 /**************************************
8821 				 * Migration Failure Log Message       *
8822 				 **************************************/
8823 
8824 				 GMA_COMMON_LOGGING.gma_migration_central_log
8825 				 (
8826 				 p_run_id             =>       G_migration_run_id,
8827 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
8828 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
8829 				 p_table_name         =>       G_Table_name,
8830 				 p_context            =>       G_context,
8831 				 p_db_error           =>       NULL,
8832 				 p_app_short_name     =>       'GMA'
8833 				 );
8834 
8835 	 END Migrate_Acquisition_Codes;
8836 
8837 	 /**********************************************************************
8838 	 * PROCEDURE:                                                          *
8839 	 *   Migrate_Period_Balances                                           *
8840 	 *                                                                     *
8841 	 * DESCRIPTION:                                                        *
8842 	 *   This PL/SQL procedure is used to migrate the Period Balances      *
8843 	 *                                                                     *
8844 	 * PARAMETERS:                                                         *
8845 	 *   P_migration_run_id - id to use to right to migration log          *
8846 	 *   x_exception_count  - Number of exceptions occurred.               *
8847 	 *                                                                     *
8848 	 * SYNOPSIS:                                                           *
8849 	 *   Migrate_Period_Balances(p_migartion_id    => l_migration_id,      *
8850 	 *                    p_commit          => 'T',                        *
8851 	 *                    x_exception_count => l_exception_count );        *
8852 	 *                                                                     *
8853 	 * HISTORY                                                             *
8854 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
8855 	 *                                                                     *
8856 	 **********************************************************************/
8857 	 PROCEDURE Migrate_Period_Balances
8858 	 (
8859 	 P_migration_run_id      IN             NUMBER,
8860 	 P_commit                IN             VARCHAR2,
8861 	 X_failure_count         OUT   NOCOPY   NUMBER
8862 	 )
8863 	 IS
8864 
8865 			/**************************
8866 			* PL/SQL Table Definition *
8867 			**************************/
8868 
8869 			/******************
8870 			* Local Variables *
8871 			******************/
8872 
8873 			l_perd_bal_count                    NUMBER := 0;
8874 
8875 			/**********
8876 			* Cursors *
8877 			**********/
8878 
8879 			CURSOR               cur_orgn_periods
8880 			IS
8881 			SELECT   DISTINCT    a.orgn_code,
8882 													 e.whse_code,
8883 													 NVL(e.subinventory_ind_flag,'N') subinventory_ind_flag,
8884 													 DECODE(NVL(e.subinventory_ind_flag,'N'), 'Y', e.organization_id, e.mtl_organization_id) organization_id,
8885 													 d.acct_period_id,
8886 													 d.period_start_date,
8887 													 d.schedule_close_date,
8888 													 b.period_id curr_period_id,
8889 													 b.period_end_date curr_period_end_date,
8890 													 c.period_id prior_period_id,
8891 													 c.period_end_date prior_period_end_date,
8892 													 c.closed_period_ind prior_period_closed_ind
8893 			FROM                 sy_orgn_mst a,
8894 													 ic_cldr_dtl b,
8895 													 ic_cldr_dtl c,
8896 													 org_acct_periods d,
8897 													 hr_organization_information hoi,
8898 													 ic_whse_mst e,
8899 													 gl_ledgers f
8900 			WHERE                a.orgn_code = b.orgn_code
8901 			AND                  c.orgn_code = a.orgn_code
8902 			AND                  e.orgn_code = a.orgn_code
8903 			AND                  d.organization_id = e.cost_organization_id
8904 			AND                  hoi.organization_id = d.organization_id
8905 			AND                  hoi.org_information_context = 'Accounting Information'
8906 			AND                  hoi.org_information1 = f.ledger_id
8907 			AND                  f.period_set_name = d.period_Set_name
8908 			AND                  c.period_end_date = d.schedule_close_date
8909 			AND                  nvl(c.closed_period_ind, 1) = 3
8910 			AND                  b.period_end_date =  (
8911 																								SELECT      MIN(x.period_end_date)
8912 																								FROM        ic_cldr_dtl x
8913 																								WHERE       a.orgn_code = x.orgn_code
8914 																								AND         SYSDATE < x.period_end_date
8915 																								)
8916 			AND                  c.period_end_date =  (
8917 																								SELECT      MAX(y.period_end_date)
8918 																								FROM        ic_cldr_dtl y
8919 																								WHERE       a.orgn_code = y.orgn_code
8920 																								AND         SYSDATE > y.period_end_Date
8921 																								);
8922 
8923 	 BEGIN
8924 
8925 			G_Migration_run_id := P_migration_run_id;
8926 			G_Table_name := 'GMF_PERIOD_BALANCES';
8927 			G_Context := 'Period Balances Migration';
8928 			X_failure_count := 0;
8929 
8930 			/********************************
8931 			* Migration Started Log Message *
8932 			********************************/
8933 
8934 			GMA_COMMON_LOGGING.gma_migration_central_log
8935 			(
8936 			p_run_id             =>       G_migration_run_id,
8937 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
8938 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
8939 			p_table_name         =>       G_Table_name,
8940 			p_context            =>       G_context,
8941 			p_db_error           =>       NULL,
8942 			p_app_short_name     =>       'GMA'
8943 			);
8944 
8945 			<<WAREHOUSES>>
8946 			FOR i IN cur_orgn_periods LOOP
8947 
8948 				 SELECT            count(1)
8949 				 INTO              l_perd_bal_count
8950 				 FROM              ic_perd_bal
8951 				 WHERE             whse_code = i.whse_code
8952 				 AND               period_id = i.prior_period_id;
8953 
8954 				 INSERT   INTO     gmf_period_balances
8955 				 (
8956 				 period_balance_id,
8957 				 acct_period_id,
8958 				 organization_id,
8959 				 cost_group_id,
8960 				 subinventory_code,
8961 				 inventory_item_id,
8962 				 lot_number,
8963 				 locator_id,
8964 				 primary_quantity,
8965 				 secondary_quantity,
8966 				 intransit_primary_quantity,
8967 				 intransit_secondary_quantity,
8968 				 accounted_value,
8969 				 intransit_accounted_value,
8970 				 costed_flag,
8971 				 creation_date,
8972 				 created_by,
8973 				 last_update_date,
8974 				 last_updated_by,
8975 				 last_update_login,
8976 				 request_id,
8977 				 program_application_id,
8978 				 program_id,
8979 				 program_update_date
8980 				 )
8981 				 (
8982 				 SELECT            gmf_period_balances_s.NEXTVAL,
8983 													 i.acct_period_id,
8984 													 i.organization_id,
8985 													 decode(i.subinventory_ind_flag, 'N', NULL, e.default_cost_group_id),
8986 													 decode(i.subinventory_ind_flag, 'N', NULL, e.secondary_inventory_name),
8987 													 b.inventory_item_id,
8988 													 c.lot_number,
8989 													 d.inventory_location_id,
8990 													 a.loct_onhand,
8991 													 a.loct_onhand2,
8992 													 0,
8993 													 0,
8994 													 a.loct_value,
8995 													 0,
8996 													 NULL,
8997 													 SYSDATE,
8998 													 1,
8999 													 SYSDATE,
9000 													 1,
9001 													 1,
9002 													 NULL,
9003 													 NULL,
9004 													 NULL,
9005 													 NULL
9006 				 FROM              ic_perd_bal a,
9007 													 ic_item_mst_b_mig b,
9008 													 ic_lots_mst_mig c,
9009 													 ic_loct_mst d,
9010 													 mtl_secondary_inventories e
9011 				 WHERE             a.whse_code = i.whse_code
9012 				 AND               a.period_id = i.prior_period_id
9013 				 AND               b.organization_id = i.organization_id
9014 				 AND               e.secondary_inventory_name(+) = i.whse_code
9015 				 AND               e.organization_id(+) = i.organization_id
9016 				 AND               b.item_id = a.item_id
9017 				 AND               c.item_id = a.item_id
9018 				 AND               c.lot_id = a.lot_id
9019 				 AND               c.whse_code = a.whse_code
9020 				 AND               c.location = a.location
9021 				 AND               d.whse_code = a.whse_code
9022 				 AND               d.location = a.location
9023 				 AND               NOT EXISTS (
9024 																			SELECT            'X'
9025 																			FROM              gmf_period_balances x
9026 																			WHERE             x.acct_period_id = i.acct_period_id
9027 																			AND               x.organization_id = i.organization_id
9028 																			AND               x.inventory_item_id = b.inventory_item_id
9029 																			AND               nvl(x.subinventory_code, '~') = nvl(decode(i.subinventory_ind_flag, 'N', NULL, e.secondary_inventory_name), '~')
9030 																			AND               nvl(x.lot_number,'~') = nvl(c.lot_number, '~')
9031 																			AND               nvl(x.locator_id, -1) = nvl(d.inventory_location_id, -1)
9032 																			)
9033 				 );
9034 
9035 				 IF l_perd_bal_count = SQL%ROWCOUNT THEN
9036 
9037 						/**********************************************************************
9038 						* Handle the periods for which the period balances have been migrated *
9039 						**********************************************************************/
9040 
9041 						UPDATE               org_acct_periods
9042 						SET                  period_close_date = SYSDATE,
9043 																 open_flag = 'N',
9044 																 summarized_flag = 'Y'
9045 						WHERE                acct_period_id = i.prior_period_id
9046 						AND                  organization_id = i.organization_id;
9047 
9048 				 ELSE
9049 
9050 						/**********************************************
9051 						* Handle all the rows which were not migrated *
9052 						**********************************************/
9053 
9054 						SELECT               count(*)
9055 						INTO                 x_failure_count
9056 						FROM                 ic_perd_bal
9057 						WHERE                whse_code = i.whse_code
9058 						AND                  period_id = i.prior_period_id;
9059 
9060 						IF nvl(x_failure_count,0) > 0 THEN
9061 
9062 							/**************************************
9063 							* Migration Failure Log Message       *
9064 							**************************************/
9065 
9066 							GMA_COMMON_LOGGING.gma_migration_central_log
9067 							(
9068 							p_run_id             =>       gmf_migration.G_migration_run_id,
9069 							p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
9070 							p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
9071 							p_table_name         =>       gmf_migration.G_Table_name,
9072 							p_context            =>       gmf_migration.G_context,
9073 							p_db_error           =>       NULL,
9074 							p_app_short_name     =>       'GMA'
9075 							);
9076 
9077 						ELSE
9078 
9079 							/**************************************
9080 							* Migration Success Log Message       *
9081 							**************************************/
9082 
9083 							GMA_COMMON_LOGGING.gma_migration_central_log
9084 							(
9085 							p_run_id             =>       G_migration_run_id,
9086 							p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
9087 							p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
9088 							p_table_name         =>       G_Table_name,
9089 							p_context            =>       G_Context,
9090 							p_param1             =>       1,
9091 							p_param2             =>       0,
9092 							p_db_error           =>       NULL,
9093 							p_app_short_name     =>       'GMA'
9094 							);
9095 
9096 						END IF;
9097 
9098 				 END IF;
9099 
9100 			END LOOP WAREHOUSES;
9101 
9102 			/**************************************
9103 			* Migration Success Log Message       *
9104 			**************************************/
9105 
9106 			GMA_COMMON_LOGGING.gma_migration_central_log
9107 			(
9108 			p_run_id             =>       G_migration_run_id,
9109 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
9110 			p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
9111 			p_table_name         =>       G_Table_name,
9112 			p_context            =>       G_context,
9113 			p_param1             =>       1,
9114 			p_param2             =>       0,
9115 			p_db_error           =>       NULL,
9116 			p_app_short_name     =>       'GMA'
9117 			);
9118 
9119 			/****************************************************************
9120 			* Lets save the changes now based on the commit parameter       *
9121 			****************************************************************/
9122 
9123 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
9124 				 COMMIT;
9125 			END IF;
9126 
9127 	 EXCEPTION
9128 			WHEN OTHERS THEN
9129 
9130 				 /************************************************
9131 				 * Increment Failure Count for Failed Migrations *
9132 				 ************************************************/
9133 
9134 				 x_failure_count := x_failure_count + 1;
9135 
9136 				 /**************************************
9137 				 * Migration DB Error Log Message      *
9138 				 **************************************/
9139 
9140 				 GMA_COMMON_LOGGING.gma_migration_central_log
9141 				 (
9142 				 p_run_id             =>       G_migration_run_id,
9143 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
9144 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
9145 				 p_table_name         =>       G_Table_name,
9146 				 p_context            =>       G_context,
9147 				 p_db_error           =>       SQLERRM,
9148 				 p_app_short_name     =>       'GMA'
9149 				 );
9150 
9151 				 /**************************************
9152 				 * Migration Failure Log Message       *
9153 				 **************************************/
9154 
9155 				 GMA_COMMON_LOGGING.gma_migration_central_log
9156 				 (
9157 				 p_run_id             =>       G_migration_run_id,
9158 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
9159 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
9160 				 p_table_name         =>       G_Table_name,
9161 				 p_context            =>       G_context,
9162 				 p_db_error           =>       NULL,
9163 				 p_app_short_name     =>       'GMA'
9164 				 );
9165 
9166 	 END Migrate_Period_Balances;
9167 
9168 	 /**********************************************************************
9169 	 * PROCEDURE:                                                          *
9170 	 *   Migrate_Allocation_Inputs                                         *
9171 	 *                                                                     *
9172 	 * DESCRIPTION:                                                        *
9173 	 *   This PL/SQL procedure is used to migrate the Expense Allocation   *
9174 	 *   Input Records used for Account Balance maintenance                *
9175 	 *                                                                     *
9176 	 * PARAMETERS:                                                         *
9177 	 *   P_migration_run_id - id to use to right to migration log          *
9178 	 *   x_exception_count  - Number of exceptions occurred.               *
9179 	 *                                                                     *
9180 	 * SYNOPSIS:                                                           *
9181 	 *   Migrate_Allocation_Inputs(p_migartion_id    => l_migration_id,    *
9182 	 *                    p_commit          => 'T',                        *
9183 	 *                    x_exception_count => l_exception_count );        *
9184 	 *                                                                     *
9185 	 * HISTORY                                                             *
9186 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
9187 	 *                                                                     *
9188 	 **********************************************************************/
9189 	 PROCEDURE Migrate_Allocation_Inputs
9190 	 (
9191 	 P_migration_run_id      IN             NUMBER,
9192 	 P_commit                IN             VARCHAR2,
9193 	 X_failure_count         OUT   NOCOPY   NUMBER
9194 	 )
9195 	 IS
9196 
9197 			/***************************
9198 			* PL/SQL Table Definitions *
9199 			***************************/
9200 
9201 			/******************
9202 			* Local Variables *
9203 			******************/
9204 
9205 	 BEGIN
9206 
9207 			G_Migration_run_id := P_migration_run_id;
9208 			G_Table_name := 'GL_ALOC_INP';
9209 			G_Context := 'Expense Allocation Inputs Migration';
9210 			X_failure_count := 0;
9211 
9212 			/********************************
9213 			* Migration Started Log Message *
9214 			********************************/
9215 
9216 			GMA_COMMON_LOGGING.gma_migration_central_log
9217 			(
9218 			p_run_id             =>       G_migration_run_id,
9219 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
9220 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
9221 			p_table_name         =>       G_Table_name,
9222 			p_context            =>       G_context,
9223 			p_db_error           =>       NULL,
9224 			p_app_short_name     =>       'GMA'
9225 			);
9226 
9227 			/**********************************************************
9228 			* Update a row in GL_ALOC_INP for Account Codes           *
9229 			**********************************************************/
9230 
9231 			BEGIN
9232 
9233 				 UPDATE         gl_aloc_inp a
9234 				 SET            a.account_id  =  (
9235 																			 SELECT      gmf_migration.get_account_id(a.account_key, x.co_code)
9236 																			 FROM        gl_aloc_mst x
9237 																			 WHERE       x.alloc_id = a.alloc_id
9238 																			 )
9239 				 WHERE          (account_id IS NULL AND a.account_key IS NOT NULL);
9240 
9241 			EXCEPTION
9242 
9243 				 WHEN OTHERS THEN
9244 
9245 						/************************************************
9246 						* Increment Failure Count for Failed Migrations *
9247 						************************************************/
9248 
9249 						x_failure_count := x_failure_count + 1;
9250 
9251 						/**************************************
9252 						* Migration DB Error Log Message      *
9253 						**************************************/
9254 
9255 						GMA_COMMON_LOGGING.gma_migration_central_log
9256 						(
9257 						p_run_id             =>       G_migration_run_id,
9258 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
9259 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
9260 						p_table_name         =>       G_Table_name,
9261 						p_context            =>       G_context,
9262 						p_param1             =>       NULL,
9263 						p_param2             =>       NULL,
9264 						p_db_error           =>       SQLERRM,
9265 						p_app_short_name     =>       'GMA'
9266 						);
9267 
9268 						/**************************************
9269 						* Migration Failure Log Message       *
9270 						**************************************/
9271 
9272 						GMA_COMMON_LOGGING.gma_migration_central_log
9273 						(
9274 						p_run_id             =>       G_migration_run_id,
9275 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
9276 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
9277 						p_table_name         =>       G_Table_name,
9278 						p_context            =>       G_context,
9279 						p_db_error           =>       NULL,
9280 						p_app_short_name     =>       'GMA'
9281 						);
9282 
9283 			END;
9284 
9285 			/**********************************************
9286 			* Handle all the rows which were not migrated *
9287 			**********************************************/
9288 
9289 			SELECT               count(*)
9290 			INTO                 x_failure_count
9291 			FROM                 gl_aloc_inp
9292 			WHERE                (account_id IS NULL AND account_key IS NOT NULL);
9293 
9294 			IF nvl(x_failure_count,0) > 0 THEN
9295 
9296 				/**************************************
9297 				* Migration Failure Log Message       *
9298 				**************************************/
9299 
9300 				GMA_COMMON_LOGGING.gma_migration_central_log
9301 				(
9302 				p_run_id             =>       gmf_migration.G_migration_run_id,
9303 				p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
9304 				p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
9305 				p_table_name         =>       gmf_migration.G_Table_name,
9306 				p_context            =>       gmf_migration.G_context,
9307 				p_db_error           =>       NULL,
9308 				p_app_short_name     =>       'GMA'
9309 				);
9310 
9311 			ELSE
9312 
9313 				/**************************************
9314 				* Migration Success Log Message       *
9315 				**************************************/
9316 
9317 				GMA_COMMON_LOGGING.gma_migration_central_log
9318 				(
9319 				p_run_id             =>       G_migration_run_id,
9320 				p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
9321 				p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
9322 				p_table_name         =>       G_Table_name,
9323 				p_context            =>       G_Context,
9324 				p_param1             =>       1,
9325 				p_param2             =>       0,
9326 				p_db_error           =>       NULL,
9327 				p_app_short_name     =>       'GMA'
9328 				);
9329 
9330 			END IF;
9331 
9332 			/****************************************************************
9333 			* Lets save the changes now based on the commit parameter       *
9334 			****************************************************************/
9335 
9336 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
9337 				 COMMIT;
9338 			END IF;
9339 
9340 	 EXCEPTION
9341 
9342 			WHEN OTHERS THEN
9343 
9344 				 /************************************************
9345 				 * Increment Failure Count for Failed Migrations *
9346 				 ************************************************/
9347 
9348 				 x_failure_count := x_failure_count + 1;
9349 
9350 				 /**************************************
9351 				 * Migration DB Error Log Message      *
9352 				 **************************************/
9353 
9354 				 GMA_COMMON_LOGGING.gma_migration_central_log
9355 				 (
9356 				 p_run_id             =>       G_migration_run_id,
9357 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
9358 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
9359 				 p_table_name         =>       G_Table_name,
9360 				 p_context            =>       G_context,
9361 				 p_param1             =>       NULL,
9362 				 p_param2             =>       NULL,
9363 				 p_db_error           =>       SQLERRM,
9364 				 p_app_short_name     =>       'GMA'
9365 				 );
9366 
9367 				 /**************************************
9368 				 * Migration Failure Log Message       *
9369 				 **************************************/
9370 
9371 				 GMA_COMMON_LOGGING.gma_migration_central_log
9372 				 (
9373 				 p_run_id             =>       G_migration_run_id,
9374 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
9375 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
9376 				 p_table_name         =>       G_Table_name,
9377 				 p_context            =>       G_context,
9378 				 p_db_error           =>       NULL,
9379 				 p_app_short_name     =>       'GMA'
9380 				 );
9381 
9382 	 END Migrate_Allocation_Inputs;
9383 
9384 	 /**********************************************************************
9385 	 * PROCEDURE:                                                          *
9386 	 *   Migrate_Burden_Priorities                                         *
9387 	 *                                                                     *
9388 	 * DESCRIPTION:                                                        *
9389 	 *   This PL/SQL procedure is used to migrate the Burden Priorities    *
9390 	 *                                                                     *
9391 	 * PARAMETERS:                                                         *
9392 	 *   P_migration_run_id - id to use to right to migration log          *
9393 	 *   x_exception_count  - Number of exceptions occurred.               *
9394 	 *                                                                     *
9395 	 * SYNOPSIS:                                                           *
9396 	 *   Migrate_Burden_Priorities(p_migartion_id    => l_migration_id,    *
9397 	 *                    p_commit          => 'T',                        *
9398 	 *                    x_exception_count => l_exception_count );        *
9399 	 *                                                                     *
9400 	 * HISTORY                                                             *
9401 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
9402 	 *                                                                     *
9403 	 **********************************************************************/
9404 	 PROCEDURE Migrate_Burden_Priorities
9405 	 (
9406 	 P_migration_run_id      IN             NUMBER,
9407 	 P_commit                IN             VARCHAR2,
9408 	 X_failure_count         OUT   NOCOPY   NUMBER
9409 	 )
9410 	 IS
9411 			/***************************
9412 			* PL/SQL Table Definitions *
9413 			***************************/
9414 
9415 			/*******************
9416 			* Local Variables  *
9417 			*******************/
9418 
9419 	 BEGIN
9420 
9421 			G_Migration_run_id := P_migration_run_id;
9422 			G_Table_name := 'GMF_BURDEN_PRIORITIES';
9423 			G_Context := 'Burden Priorities Migration';
9424 			X_failure_count := 0;
9425 
9426 			/********************************
9427 			* Migration Started Log Message *
9428 			********************************/
9429 
9430 			GMA_COMMON_LOGGING.gma_migration_central_log
9431 			(
9432 			p_run_id             =>       G_migration_run_id,
9433 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
9434 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
9435 			p_table_name         =>       G_table_name,
9436 			p_context            =>       G_context,
9437 			p_db_error           =>       NULL,
9438 			p_app_short_name     =>       'GMA'
9439 			);
9440 
9441 			/*****************************************
9442 			* Update rows For Organization Priority  *
9443 			*****************************************/
9444 
9445 			UPDATE      gmf_burden_priorities a
9446 			SET         a.organization_pri = nvl(a.whse_code_pri, a.orgn_code_pri),
9447 									a.legal_entity_id
9448 			=           (
9449 									SELECT      x.legal_entity_id
9450 									FROM        gl_plcy_mst x
9451 									WHERE       x.co_code = a.co_code
9452 									)
9453 			WHERE       ((a.whse_code_pri IS NOT NULL OR a.orgn_code_pri IS NOT null) AND a.organization_pri IS NULL)
9454 			OR          (a.co_code IS NOT NULL AND a.legal_entity_id IS NULL);
9455 
9456 			UPDATE      gmf_burden_priorities a
9457 			SET         a.delete_mark = 1
9458 			WHERE       a.ROWID NOT IN  (
9459 																	SELECT      MIN(x.ROWID)
9460 																	FROM        gmf_burden_priorities x
9461 																	WHERE       x.burden_id = a.burden_id
9462 																	AND         x.legal_entity_id = a.legal_Entity_id
9463 																	AND         x.delete_mark <> 1
9464 																	);
9465 
9466 			UPDATE      gmf_burden_priorities
9467 			SET         organization_pri      =  decode(trunc(nvl(organization_pri,0) / orgn_code_pri), 0, organization_pri, organization_pri - 1),
9468 									item_id_pri           =  decode(trunc(nvl(item_id_pri,0) / orgn_code_pri), 0, item_id_pri, item_id_pri - 1),
9469 									icgl_class_pri        =  decode(trunc(nvl(icgl_class_pri,0) / orgn_code_pri), 0, icgl_class_pri, icgl_class_pri - 1),
9470 									itemcost_class_pri    =  decode(trunc(nvl(itemcost_class_pri,0) / orgn_code_pri), 0, itemcost_class_pri, itemcost_class_pri - 1),
9471 									gl_prod_line_pri      =  decode(trunc(nvl(gl_prod_line_pri,0) / orgn_code_pri), 0, gl_prod_line_pri, gl_prod_line_pri - 1),
9472 									gl_business_class_pri =  decode(trunc(nvl(gl_business_class_pri,0) / orgn_code_pri), 0, gl_business_class_pri, gl_business_class_pri - 1),
9473 									orgn_code_pri = NULL
9474 			WHERE       orgn_code_pri IS NOT NULL
9475 			AND         orgn_code_pri < 7
9476 			AND         whse_code_pri IS NOT NULL;
9477 
9478 			/**********************************************
9479 			* Handle all the rows which were not migrated *
9480 			**********************************************/
9481 
9482 			SELECT               count(*)
9483 			INTO                 x_failure_count
9484 			FROM                 gmf_burden_priorities a
9485 			WHERE                ((a.whse_code_pri IS NOT NULL OR a.orgn_code_pri IS NOT null) AND a.organization_pri IS NULL)
9486 			OR                   (a.co_code IS NOT NULL AND a.legal_entity_id IS NULL);
9487 
9488 			IF nvl(x_failure_count,0) > 0 THEN
9489 
9490 				/**************************************
9491 				* Migration Failure Log Message       *
9492 				**************************************/
9493 
9494 				GMA_COMMON_LOGGING.gma_migration_central_log
9495 				(
9496 				p_run_id             =>       gmf_migration.G_migration_run_id,
9497 				p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
9498 				p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
9499 				p_table_name         =>       gmf_migration.G_Table_name,
9500 				p_context            =>       gmf_migration.G_context,
9501 				p_db_error           =>       NULL,
9502 				p_app_short_name     =>       'GMA'
9503 				);
9504 
9505 			ELSE
9506 
9507 				/**************************************
9508 				* Migration Success Log Message       *
9509 				**************************************/
9510 
9511 				GMA_COMMON_LOGGING.gma_migration_central_log
9512 				(
9513 				p_run_id             =>       G_migration_run_id,
9514 				p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
9515 				p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
9516 				p_table_name         =>       G_Table_name,
9517 				p_context            =>       G_Context,
9518 				p_param1             =>       1,
9519 				p_param2             =>       0,
9520 				p_db_error           =>       NULL,
9521 				p_app_short_name     =>       'GMA'
9522 				);
9523 
9524 			END IF;
9525 
9526 			/****************************************************************
9527 			* Lets save the changes now based on the commit parameter       *
9528 			****************************************************************/
9529 
9530 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
9531 				 COMMIT;
9532 			END IF;
9533 
9534 	 EXCEPTION
9535 			WHEN OTHERS THEN
9536 
9537 				 /************************************************
9538 				 * Increment Failure Count for Failed Migrations *
9539 				 ************************************************/
9540 				 x_failure_count := x_failure_count + 1;
9541 
9542 				 /**************************************
9543 				 * Migration DB Error Log Message      *
9544 				 **************************************/
9545 
9546 				 GMA_COMMON_LOGGING.gma_migration_central_log
9547 				 (
9548 				 p_run_id             =>       G_migration_run_id,
9549 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
9550 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
9551 				 p_table_name         =>       G_table_name,
9552 				 p_context            =>       G_context,
9553 				 p_db_error           =>       SQLERRM,
9554 				 p_app_short_name     =>       'GMA'
9555 				 );
9556 
9557 				 /**************************************
9558 				 * Migration Failure Log Message       *
9559 				 **************************************/
9560 
9561 				 GMA_COMMON_LOGGING.gma_migration_central_log
9562 				 (
9563 				 p_run_id             =>       G_migration_run_id,
9564 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
9565 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
9566 				 p_table_name         =>       G_table_name,
9567 				 p_context            =>       G_context,
9568 				 p_db_error           =>       NULL,
9569 				 p_app_short_name     =>       'GMA'
9570 				 );
9571 
9572 	 END Migrate_Burden_Priorities;
9573 
9574 	 /**********************************************************************
9575 	 * PROCEDURE:                                                          *
9576 	 *   Migrate_Component_Materials                                       *
9577 	 *                                                                     *
9578 	 * DESCRIPTION:                                                        *
9579 	 *   This PL/SQL procedure is used to migrate the Material Components  *
9580 	 *                                                                     *
9581 	 * PARAMETERS:                                                         *
9582 	 *   P_migration_run_id - id to use to right to migration log          *
9583 	 *   x_exception_count  - Number of exceptions occurred.               *
9584 	 *                                                                     *
9585 	 * SYNOPSIS:                                                           *
9586 	 *   Migrate_component_Materials(p_migartion_id    => l_migration_id,  *
9587 	 *                    p_commit          => 'T',                        *
9588 	 *                    x_exception_count => l_exception_count );        *
9589 	 *                                                                     *
9590 	 * HISTORY                                                             *
9591 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
9592 	 *       05-Jul-2006 rseshadr bug 5374823 - call item mig inline for   *
9593 	 *         the current table                                           *
9594 	 *                                                                     *
9595 	 **********************************************************************/
9596 	 PROCEDURE Migrate_Component_Materials
9597 	 (
9598 	 P_migration_run_id      IN             NUMBER,
9599 	 P_commit                IN             VARCHAR2,
9600 	 X_failure_count         OUT   NOCOPY   NUMBER
9601 	 )
9602 	 IS
9603 			/***************************
9604 			* PL/SQL Table Definitions *
9605 			***************************/
9606 
9607 			/*******************
9608 			* Local Variables  *
9609 			*******************/
9610 
9611 			l_inventory_item_id                 NUMBER;
9612 			l_itm_failure_count                 NUMBER;
9613 			l_itm_failure_count_all             NUMBER;
9614 
9615 
9616 			/****************
9617 			* Cursors       *
9618 			****************/
9619 
9620 			CURSOR      cur_get_gmf_items IS
9621 			SELECT      DISTINCT
9622 									item_id,
9623 									organization_id
9624 			FROM        (
9625 									SELECT        a.item_id,
9626 																decode(NVL(c.subinventory_ind_flag,'N'), 'Y', c.organization_id, c.mtl_organization_id) organization_id
9627 									FROM          cm_cmpt_mtl a,
9628 																sy_orgn_mst b,
9629 																ic_whse_mst c
9630 									WHERE         a.item_id IS NOT NULL
9631 									AND           a.co_code = b.co_code
9632 									AND           b.orgn_code = c.orgn_code
9633 									AND           nvl(c.subinventory_ind_flag, 'N') <> 'Y'
9634 									);
9635 
9636 	 BEGIN
9637 
9638 			G_Migration_run_id := P_migration_run_id;
9639 			G_Table_name := 'CM_CMPT_MTL';
9640 			G_Context := 'Material Cost Components Migration';
9641 			X_failure_count := 0;
9642 
9643 			/********************************
9644 			* Migration Started Log Message *
9645 			********************************/
9646 
9647 			GMA_COMMON_LOGGING.gma_migration_central_log
9648 			(
9649 			p_run_id             =>       G_migration_run_id,
9650 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
9651 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
9652 			p_table_name         =>       G_table_name,
9653 			p_context            =>       G_context,
9654 			p_db_error           =>       NULL,
9655 			p_app_short_name     =>       'GMA'
9656 			);
9657 
9658 			/********************************************
9659 			* rseshadr bug 5374823                      *
9660 			* Call Item Migration API in a loop         *
9661 			* To Migrate necessary items for this table *
9662 			*********************************************/
9663 
9664 			FOR i IN cur_get_gmf_items
9665 			LOOP
9666 				IF i.item_id IS NOT NULL AND i.organization_id IS NOT NULL THEN
9667 					inv_opm_item_migration.get_odm_item
9668 					(
9669 						p_migration_run_id        =>        p_migration_run_id,
9670 						p_item_id                 =>        i.item_id,
9671 						p_organization_id         =>        i.organization_id,
9672 						p_mode                    =>        NULL,
9673 						p_commit                  =>        FND_API.G_TRUE,
9674 						x_inventory_item_id       =>        l_inventory_item_id,
9675 						x_failure_count           =>        l_itm_failure_count
9676 					);
9677 				END IF;
9678 				l_itm_failure_count_all := nvl(l_itm_failure_count_all,0) + nvl(l_itm_failure_count,0);
9679 			END LOOP;
9680 
9681 			/*****************************************
9682 			* Update rows For Legal Entity and Item  *
9683 			*****************************************/
9684 
9685 			UPDATE      cm_cmpt_mtl a
9686 			SET         a.legal_entity_id
9687 			=           (
9688 									SELECT            x.legal_entity_id
9689 									FROM              gl_plcy_mst x
9690 									WHERE             x.co_code = a.co_code
9691 									)
9692 			WHERE       (a.legal_entity_id IS NULL AND a.co_code IS NOT NULL);
9693 
9694 			UPDATE      cm_cmpt_mtl a
9695 			SET         (
9696 									a.master_organization_id,
9697 									a.inventory_item_id
9698 									)
9699 			=           (
9700 									SELECT            z.master_organization_id,
9701 																		y.inventory_item_id
9702 									FROM              ic_item_mst_b_mig y,
9703 																		mtl_parameters z,
9704 																		hr_organization_information hoi
9705 									WHERE             y.item_id = a.item_id
9706 									AND               y.organization_id = z.organization_id
9707 									AND               hoi.organization_id = z.organization_id
9708 									AND               hoi.org_information_context = 'Accounting Information'
9709 									AND               hoi.org_information2 = a.legal_entity_id
9710 									AND               ROWNUM = 1
9711 									)
9712 			WHERE       (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
9713 			OR          (a.master_organization_id IS NULL AND a.item_id IS NOT NULL);
9714 
9715 			UPDATE      cm_cmpt_mtl a
9716 			SET         a.delete_mark = 1
9717 			WHERE       a.ROWID NOT IN  (
9718 																	SELECT      MIN(x.ROWID)
9719 																	FROM        cm_cmpt_mtl x
9720 																	WHERE       x.legal_entity_id = a.legal_Entity_id
9721 																	AND         nvl(x.inventory_item_id, -1) = nvl(a.inventory_item_id, -1)
9722 																	AND         nvl(x.cost_category_id, -1) = nvl(a.cost_category_id, -1)
9723 																	AND         x.delete_mark <> 1
9724 																	AND         (
9725 																							a.eff_start_date BETWEEN x.eff_start_date and x.eff_end_date
9726 																							OR
9727 																							a.eff_end_date BETWEEN x.eff_start_date  and x.eff_end_date
9728 																							)
9729 																	);
9730 
9731 			/**********************************************
9732 			* Handle all the rows which were not migrated *
9733 			**********************************************/
9734 
9735 			SELECT                count(*)
9736 			INTO                  x_failure_count
9737 			FROM                  cm_cmpt_mtl
9738 			WHERE                 (
9739 														(inventory_item_id IS NULL AND item_id IS NOT NULL)
9740 			OR                    (legal_entity_id IS NULL AND co_code IS NOT NULL)
9741 			OR                    (master_organization_id IS NULL AND item_id IS NOT NULL)
9742 														);
9743 
9744 			IF nvl(x_failure_count,0) > 0 THEN
9745 
9746 				/**************************************
9747 				* Migration Failure Log Message       *
9748 				**************************************/
9749 
9750 				GMA_COMMON_LOGGING.gma_migration_central_log
9751 				(
9752 				p_run_id             =>       gmf_migration.G_migration_run_id,
9753 				p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
9754 				p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
9755 				p_table_name         =>       gmf_migration.G_Table_name,
9756 				p_context            =>       gmf_migration.G_context,
9757 				p_db_error           =>       NULL,
9758 				p_app_short_name     =>       'GMA'
9759 				);
9760 
9761 			ELSE
9762 
9763 				/**************************************
9764 				* Migration Success Log Message       *
9765 				**************************************/
9766 
9767 				GMA_COMMON_LOGGING.gma_migration_central_log
9768 				(
9769 				p_run_id             =>       G_migration_run_id,
9770 				p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
9771 				p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
9772 				p_table_name         =>       G_Table_name,
9773 				p_context            =>       G_Context,
9774 				p_param1             =>       1,
9775 				p_param2             =>       0,
9776 				p_db_error           =>       NULL,
9777 				p_app_short_name     =>       'GMA'
9778 				);
9779 
9780 			END IF;
9781 
9782 			/****************************************************************
9783 			* Lets save the changes now based on the commit parameter       *
9784 			****************************************************************/
9785 
9786 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
9787 				 COMMIT;
9788 			END IF;
9789 
9790 	 EXCEPTION
9791 			WHEN OTHERS THEN
9792 
9793 				 /************************************************
9794 				 * Increment Failure Count for Failed Migrations *
9795 				 ************************************************/
9796 				 x_failure_count := x_failure_count + 1;
9797 
9798 				 /**************************************
9799 				 * Migration DB Error Log Message      *
9800 				 **************************************/
9801 
9802 				 GMA_COMMON_LOGGING.gma_migration_central_log
9803 				 (
9804 				 p_run_id             =>       G_migration_run_id,
9805 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
9806 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
9807 				 p_table_name         =>       G_table_name,
9808 				 p_context            =>       G_context,
9809 				 p_db_error           =>       SQLERRM,
9810 				 p_app_short_name     =>       'GMA'
9811 				 );
9812 
9813 				 /**************************************
9814 				 * Migration Failure Log Message       *
9815 				 **************************************/
9816 
9817 				 GMA_COMMON_LOGGING.gma_migration_central_log
9818 				 (
9819 				 p_run_id             =>       G_migration_run_id,
9820 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
9821 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
9822 				 p_table_name         =>       G_table_name,
9823 				 p_context            =>       G_context,
9824 				 p_db_error           =>       NULL,
9825 				 p_app_short_name     =>       'GMA'
9826 				 );
9827 
9828 	 END Migrate_Component_Materials;
9829 
9830 	 /**********************************************************************
9831 	 * PROCEDURE:                                                          *
9832 	 *   Migrate_Allocation_Codes                                          *
9833 	 *                                                                     *
9834 	 * DESCRIPTION:                                                        *
9835 	 *   This PL/SQL procedure is used to migrate the Expense Allocation   *
9836 	 *   Basis Records                                                     *
9837 	 *                                                                     *
9838 	 * PARAMETERS:                                                         *
9839 	 *   P_migration_run_id - id to use to right to migration log          *
9840 	 *   x_exception_count  - Number of exceptions occurred.               *
9841 	 *                                                                     *
9842 	 * SYNOPSIS:                                                           *
9843 	 *   Migrate_Allocation_Codes(p_migartion_id    => l_migration_id,     *
9844 	 *                    p_commit          => 'T',                        *
9845 	 *                    x_exception_count => l_exception_count );        *
9846 	 *                                                                     *
9847 	 * HISTORY                                                             *
9848 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
9849 	 *                                                                     *
9850 	 **********************************************************************/
9851 	 PROCEDURE Migrate_Allocation_Codes
9852 	 (
9853 	 P_migration_run_id      IN             NUMBER,
9854 	 P_commit                IN             VARCHAR2,
9855 	 X_failure_count         OUT   NOCOPY   NUMBER
9856 	 )
9857 	 IS
9858 			/***************************
9859 			* PL/SQL Table Definitions *
9860 			***************************/
9861 
9862 			/**********
9863 			* Cursors *
9864 			**********/
9865 
9866 			CURSOR        c_gl_aloc_bas
9867 			IS
9868 			SELECT        y.alloc_id,
9869 										y.mina,
9870 										count(x.alloc_id) cnt
9871 			FROM          gl_aloc_bas x,  (
9872 																		SELECT        a.alloc_id,
9873 																									(
9874 																									SELECT          MIN(h.alloc_id)
9875 																									FROM            gl_aloc_mst h
9876 																									WHERE           (h.legal_entity_id, h.alloc_code) IN  (
9877 																																																				SELECT        i.legal_entity_id, i.alloc_code
9878 																																																				FROM          gl_aloc_mst i
9879 																																																				WHERE         i.alloc_id = a.alloc_id
9880 																																																				)
9881 																									) mina
9882 																		FROM          gl_aloc_bas a
9883 																		GROUP BY      a.alloc_id
9884 																		) y
9885 			WHERE         x.alloc_id(+) = y.mina
9886 			GROUP BY      y.alloc_id,
9887 										x.alloc_id,
9888 										y.mina
9889 			HAVING        y.alloc_id <> y.mina;
9890 
9891 			CURSOR        c_gl_aloc_exp
9892 			IS
9893 			SELECT        y.alloc_id,
9894 										y.mina,
9895 										count(x.alloc_id) cnt
9896 			FROM          gl_aloc_exp x,  (
9897 																		SELECT        a.alloc_id,
9898 																									(
9899 																									SELECT          MIN(h.alloc_id)
9900 																									FROM            gl_aloc_mst h
9901 																									WHERE           (h.legal_entity_id, h.alloc_code) IN  (
9902 																																																				SELECT        i.legal_entity_id, i.alloc_code
9903 																																																				FROM          gl_aloc_mst i
9904 																																																				WHERE         i.alloc_id = a.alloc_id
9905 																																																				)
9906 																									) mina
9907 																		FROM          gl_aloc_exp a
9908 																		GROUP BY      a.alloc_id
9909 																		) y
9910 			WHERE         x.alloc_id(+) = y.mina
9911 			GROUP BY      y.alloc_id,
9912 										x.alloc_id,
9913 										y.mina
9914 			HAVING        y.alloc_id <> y.mina;
9915 
9916 			CURSOR        c_gl_aloc_inp
9917 			IS
9918 			SELECT        y.alloc_id,
9919 										y.mina,
9920 										count(x.alloc_id) cnt
9921 			FROM          gl_aloc_inp x,  (
9922 																		SELECT        a.alloc_id,
9923 																									(
9924 																									SELECT          MIN(h.alloc_id)
9925 																									FROM            gl_aloc_mst h
9926 																									WHERE           (h.legal_entity_id, h.alloc_code) IN  (
9927 																																																				SELECT        i.legal_entity_id, i.alloc_code
9928 																																																				FROM          gl_aloc_mst i
9929 																																																				WHERE         i.alloc_id = a.alloc_id
9930 																																																				)
9931 																									) mina
9932 																		FROM          gl_aloc_inp a
9933 																		GROUP BY      a.alloc_id
9934 																		) y
9935 			WHERE         x.alloc_id(+) = y.mina
9936 			GROUP BY      y.alloc_id,
9937 										x.alloc_id,
9938 										y.mina
9939 			HAVING        y.alloc_id <> y.mina;
9940 
9941 			/*******************
9942 			* Local Variables  *
9943 			*******************/
9944 
9945 	 BEGIN
9946 
9947 			G_Migration_run_id := P_migration_run_id;
9948 			G_Table_name := 'GL_ALOC_MST';
9949 			G_Context := 'Expense Allocation Codes Migration';
9950 			X_failure_count := 0;
9951 
9952 			/********************************
9953 			* Migration Started Log Message *
9954 			********************************/
9955 
9956 			GMA_COMMON_LOGGING.gma_migration_central_log
9957 			(
9958 			p_run_id             =>       G_migration_run_id,
9959 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
9960 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
9961 			p_table_name         =>       G_table_name,
9962 			p_context            =>       G_context,
9963 			p_db_error           =>       NULL,
9964 			p_app_short_name     =>       'GMA'
9965 			);
9966 
9967 			/*****************************************
9968 			* Update rows For Legal Entity           *
9969 			*****************************************/
9970 
9971 			UPDATE      gl_aloc_mst a
9972 			SET         a.legal_entity_id =  (
9973 																			 SELECT      x.legal_entity_id
9974 																			 FROM        gl_plcy_mst x
9975 																			 WHERE       x.co_code = a.co_code
9976 																			 )
9977 			WHERE       (a.legal_entity_id IS NULL AND a.co_code IS NOT NULL);
9978 
9979 			/**************************************************************************************************************
9980 			* Migrating records can have duplicate value of Allocation codes since, codes from different companies        *
9981 			* are merged together to form the legal entities allocation records. so we delete the duplicate records       *
9982 			* from the allocation tables. Since there are some references too the allocation codes in Allocation basis    *
9983 			* we have to delete the records from those tables as well.                                                    *
9984 			**************************************************************************************************************/
9985 
9986 			UPDATE      gl_aloc_mst a
9987 			SET         a.delete_mark = 1
9988 			WHERE       a.ROWID NOT IN  (
9989 																	SELECT      MIN(x.ROWID)
9990 																	FROM        gl_aloc_mst x
9991 																	WHERE       x.alloc_code = a.alloc_code
9992 																	AND         x.legal_entity_id = a.legal_Entity_id
9993 																	AND         x.delete_mark <> 1
9994 																	);
9995 
9996 			/******************************************************************
9997 			* Deleting referenced records and updating records in GL_ALOC_BAS *
9998 			******************************************************************/
9999 
10000 			FOR i IN c_gl_aloc_bas LOOP
10001 				IF i.cnt > 0 THEN
10002 					UPDATE    gl_aloc_bas a
10003 					SET       a.delete_mark = 1
10004 					WHERE     a.alloc_id = i.alloc_id
10005 					AND       a.delete_mark <> 1;
10006 				ELSE
10007 					UPDATE    gl_aloc_bas a
10008 					SET       a.alloc_id = i.mina
10009 					WHERE     a.alloc_id = i.alloc_id
10010 					AND       a.delete_mark <> 1;
10011 				END IF;
10012 			END LOOP;
10013 
10014 			/******************************************************************
10015 			* Deleting referenced records and updating records in GL_ALOC_EXP *
10016 			******************************************************************/
10017 
10018 			FOR i IN c_gl_aloc_exp LOOP
10019 				IF i.cnt > 0 THEN
10020 					UPDATE    gl_aloc_exp a
10021 					SET       a.delete_mark = 1
10022 					WHERE     a.alloc_id = i.alloc_id
10023 					AND       a.delete_mark <> 1;
10024 				ELSE
10025 					UPDATE    gl_aloc_exp a
10026 					SET       a.alloc_id = i.mina
10027 					WHERE     a.alloc_id = i.alloc_id
10028 					AND       a.delete_mark <> 1;
10029 				END IF;
10030 			END LOOP;
10031 
10032 			/******************************************************************
10033 			* Deleting referenced records and updating records in GL_ALOC_INP *
10034 			******************************************************************/
10035 
10036 			FOR i IN c_gl_aloc_inp LOOP
10037 				IF i.cnt > 0 THEN
10038 					UPDATE    gl_aloc_inp a
10039 					SET       a.delete_mark = 1
10040 					WHERE     a.alloc_id = i.alloc_id
10041 					AND       a.delete_mark <> 1;
10042 				ELSE
10043 					UPDATE    gl_aloc_inp a
10044 					SET       a.alloc_id = i.mina
10045 					WHERE     a.alloc_id = i.alloc_id
10046 					AND       a.delete_mark <> 1;
10047 				END IF;
10048 			END LOOP;
10049 
10050 			/**********************************************
10051 			* Handle all the rows which were not migrated *
10052 			**********************************************/
10053 
10054 			SELECT               count(*)
10055 			INTO                 x_failure_count
10056 			FROM                 gl_aloc_mst
10057 			WHERE                (legal_entity_id IS NULL AND co_code IS NOT NULL);
10058 
10059 			IF nvl(x_failure_count,0) > 0 THEN
10060 
10061 				/**************************************
10062 				* Migration Failure Log Message       *
10063 				**************************************/
10064 
10065 				GMA_COMMON_LOGGING.gma_migration_central_log
10066 				(
10067 				p_run_id             =>       gmf_migration.G_migration_run_id,
10068 				p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
10069 				p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
10070 				p_table_name         =>       gmf_migration.G_Table_name,
10071 				p_context            =>       gmf_migration.G_context,
10072 				p_db_error           =>       NULL,
10073 				p_app_short_name     =>       'GMA'
10074 				);
10075 
10076 			ELSE
10077 
10078 				/**************************************
10079 				* Migration Success Log Message       *
10080 				**************************************/
10081 
10082 				GMA_COMMON_LOGGING.gma_migration_central_log
10083 				(
10084 				p_run_id             =>       G_migration_run_id,
10085 				p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
10086 				p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
10087 				p_table_name         =>       G_Table_name,
10088 				p_context            =>       G_Context,
10089 				p_param1             =>       1,
10090 				p_param2             =>       0,
10091 				p_db_error           =>       NULL,
10092 				p_app_short_name     =>       'GMA'
10093 				);
10094 
10095 			END IF;
10096 
10097 			/****************************************************************
10098 			* Lets save the changes now based on the commit parameter       *
10099 			****************************************************************/
10100 
10101 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
10102 				 COMMIT;
10103 			END IF;
10104 
10105 	 EXCEPTION
10106 			WHEN OTHERS THEN
10107 
10108 				 /************************************************
10109 				 * Increment Failure Count for Failed Migrations *
10110 				 ************************************************/
10111 				 x_failure_count := x_failure_count + 1;
10112 
10113 				 /**************************************
10114 				 * Migration DB Error Log Message      *
10115 				 **************************************/
10116 
10117 				 GMA_COMMON_LOGGING.gma_migration_central_log
10118 				 (
10119 				 p_run_id             =>       G_migration_run_id,
10120 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
10121 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
10122 				 p_table_name         =>       G_table_name,
10123 				 p_context            =>       G_context,
10124 				 p_db_error           =>       SQLERRM,
10125 				 p_app_short_name     =>       'GMA'
10126 				 );
10127 
10128 				 /**************************************
10129 				 * Migration Failure Log Message       *
10130 				 **************************************/
10131 
10132 				 GMA_COMMON_LOGGING.gma_migration_central_log
10133 				 (
10134 				 p_run_id             =>       G_migration_run_id,
10135 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
10136 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
10137 				 p_table_name         =>       G_table_name,
10138 				 p_context            =>       G_context,
10139 				 p_db_error           =>       NULL,
10140 				 p_app_short_name     =>       'GMA'
10141 				 );
10142 
10143 	 END Migrate_Allocation_Codes;
10144 
10145 	 /**********************************************************************
10146 	 * PROCEDURE:                                                          *
10147 	 *   Migrate_Event Policies                                            *
10148 	 *                                                                     *
10149 	 * DESCRIPTION:                                                        *
10150 	 *   This PL/SQL procedure is used to migrate the Event Fiscal Policies*
10151 	 *                                                                     *
10152 	 * PARAMETERS:                                                         *
10153 	 *   P_migration_run_id - id to use to right to migration log          *
10154 	 *   x_exception_count  - Number of exceptions occurred.               *
10155 	 *                                                                     *
10156 	 * SYNOPSIS:                                                           *
10157 	 *   Migrate_Evenr_Policies(p_migartion_id    => l_migration_id,       *
10158 	 *                    p_commit          => 'T',                        *
10159 	 *                    x_exception_count => l_exception_count );        *
10160 	 *                                                                     *
10161 	 * HISTORY                                                             *
10162 	 *       27-Apr-2005 Created  Anand Thiyagarajan                       *
10163 	 *                                                                     *
10164 	 **********************************************************************/
10165 	 PROCEDURE Migrate_Event_Policies
10166 	 (
10167 	 P_migration_run_id      IN             NUMBER,
10168 	 P_commit                IN             VARCHAR2,
10169 	 X_failure_count         OUT   NOCOPY   NUMBER
10170 	 )
10171 	 IS
10172 
10173 			/***************************
10174 			* PL/SQL Table Definitions *
10175 			***************************/
10176 
10177 			/*******************
10178 			* Local Variables  *
10179 			*******************/
10180 
10181 	 BEGIN
10182 
10183 			G_Migration_run_id := P_migration_run_id;
10184 			G_Table_name := 'GL_EVNT_PLC';
10185 			G_Context := 'Event Fiscal Policies Migration';
10186 			X_failure_count := 0;
10187 
10188 			/********************************
10189 			* Migration Started Log Message *
10190 			********************************/
10191 
10192 			GMA_COMMON_LOGGING.gma_migration_central_log
10193 			(
10194 			p_run_id             =>       G_migration_run_id,
10195 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
10196 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
10197 			p_table_name         =>       G_table_name,
10198 			p_context            =>       G_context,
10199 			p_db_error           =>       NULL,
10200 			p_app_short_name     =>       'GMA'
10201 			);
10202 
10203 			/*****************************************
10204 			* Update rows For Legal Entity           *
10205 			*****************************************/
10206 
10207 			UPDATE      gl_evnt_plc a
10208 			SET         a.legal_entity_id =  (
10209 																			 SELECT      x.legal_entity_id
10210 																			 FROM        gl_plcy_mst x
10211 																			 WHERE       x.co_code = a.co_code
10212 																			 ),
10213 									a.entity_code = decode(a.trans_source_type, 12, 'PURCHASING', NULL),
10214 									a.event_class_code = decode(a.event_type, 110, 'DELIVER', NULL)
10215 			WHERE       (a.legal_entity_id IS NULL AND a.co_code IS NOT NULL);
10216 
10217 			/**************************************************************************************************************
10218 			* Migrating records can have duplicate value of Event Fiscal Policies since, codes from different companies   *
10219 			* are merged together to form the LE Event Fiscal Policy records.so we delete the duplicate records           *
10220 			* from the Event Fiscal Policy tables.                                                                        *
10221 			**************************************************************************************************************/
10222 
10223 			UPDATE      gl_evnt_plc a
10224 			SET         a.delete_mark = 1
10225 			WHERE       a.ROWID NOT IN  (
10226 																	SELECT      MIN(x.ROWID)
10227 																	FROM        gl_evnt_plc x
10228 																	WHERE       x.legal_entity_id = a.legal_Entity_id
10229 																	AND         nvl(x.trans_source_type, -1) = nvl(a.trans_source_type, -1)
10230 																	AND         nvl(x.event_type, -1) = nvl(a.event_type, -1)
10231 																	AND         x.delete_mark <> 1
10232 																	);
10233 
10234 			/**********************************************
10235 			* Handle all the rows which were not migrated *
10236 			**********************************************/
10237 
10238 			SELECT               count(*)
10239 			INTO                 x_failure_count
10240 			FROM                 gl_evnt_plc
10241 			WHERE                (legal_entity_id IS NULL AND co_code IS NOT NULL);
10242 
10243 			IF nvl(x_failure_count,0) > 0 THEN
10244 
10245 				/**************************************
10246 				* Migration Failure Log Message       *
10247 				**************************************/
10248 
10249 				GMA_COMMON_LOGGING.gma_migration_central_log
10250 				(
10251 				p_run_id             =>       gmf_migration.G_migration_run_id,
10252 				p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
10253 				p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
10254 				p_table_name         =>       gmf_migration.G_Table_name,
10255 				p_context            =>       gmf_migration.G_context,
10256 				p_db_error           =>       NULL,
10257 				p_app_short_name     =>       'GMA'
10258 				);
10259 
10260 			ELSE
10261 
10262 				/**************************************
10263 				* Migration Success Log Message       *
10264 				**************************************/
10265 
10266 				GMA_COMMON_LOGGING.gma_migration_central_log
10267 				(
10268 				p_run_id             =>       G_migration_run_id,
10269 				p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
10270 				p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
10271 				p_table_name         =>       G_Table_name,
10272 				p_context            =>       G_Context,
10273 				p_param1             =>       1,
10274 				p_param2             =>       0,
10275 				p_db_error           =>       NULL,
10276 				p_app_short_name     =>       'GMA'
10277 				);
10278 
10279 			END IF;
10280 
10281 			/****************************************************************
10282 			* Lets save the changes now based on the commit parameter       *
10283 			****************************************************************/
10284 
10285 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
10286 				 COMMIT;
10287 			END IF;
10288 
10289 	 EXCEPTION
10290 			WHEN OTHERS THEN
10291 
10292 				 /************************************************
10293 				 * Increment Failure Count for Failed Migrations *
10294 				 ************************************************/
10295 				 x_failure_count := x_failure_count + 1;
10296 
10297 				 /**************************************
10298 				 * Migration DB Error Log Message      *
10299 				 **************************************/
10300 
10301 				 GMA_COMMON_LOGGING.gma_migration_central_log
10302 				 (
10303 				 p_run_id             =>       G_migration_run_id,
10304 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
10305 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
10306 				 p_table_name         =>       G_table_name,
10307 				 p_context            =>       G_context,
10308 				 p_db_error           =>       SQLERRM,
10309 				 p_app_short_name     =>       'GMA'
10310 				 );
10311 
10312 				 /**************************************
10313 				 * Migration Failure Log Message       *
10314 				 **************************************/
10315 
10316 				 GMA_COMMON_LOGGING.gma_migration_central_log
10317 				 (
10318 				 p_run_id             =>       G_migration_run_id,
10319 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
10320 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
10321 				 p_table_name         =>       G_table_name,
10322 				 p_context            =>       G_context,
10323 				 p_db_error           =>       NULL,
10324 				 p_app_short_name     =>       'GMA'
10325 				 );
10326 
10327 	 END Migrate_Event_Policies;
10328 
10329 	 /**********************************************************************
10330 	 * PROCEDURE:                                                          *
10331 	 *   Migrate_source_Warehouses                                         *
10332 	 *                                                                     *
10333 	 * DESCRIPTION:                                                        *
10334 	 *   This PL/SQL procedure is used to transform the Source Warehouses  *
10335 	 *   data in CM_WHSE_SRC                                               *
10336 	 *                                                                     *
10337 	 * PARAMETERS:                                                         *
10338 	 *   P_migration_run_id - id to use to right to migration log          *
10339 	 *   x_exception_count  - Number of exceptions occurred.               *
10340 	 *                                                                     *
10341 	 * SYNOPSIS:                                                           *
10342 	 *   Migrate_Source_Warehouses(p_migartion_id    => l_migration_id,    *
10343 	 *                    p_commit          => 'T',                        *
10344 	 *                    x_exception_count => l_exception_count );        *
10345 	 *                                                                     *
10346 	 * HISTORY                                                             *
10347 	 *       04-Apr-2006 Created  anthiyag                                 *
10348 	 *                                                                     *
10349 	 **********************************************************************/
10350 	 PROCEDURE Migrate_Source_Warehouses
10351 	 (
10352 	 P_migration_run_id      IN             NUMBER,
10353 	 P_commit                IN             VARCHAR2,
10354 	 X_failure_count         OUT   NOCOPY   NUMBER
10355 	 )
10356 	 IS
10357 
10358 			/****************
10359 			* PL/SQL Tables *
10360 			****************/
10361 
10362 			/******************
10363 			* Local Variables *
10364 			******************/
10365 
10366 	 BEGIN
10367 
10368 			G_Migration_run_id := P_migration_run_id;
10369 			G_Table_name := 'CM_WHSE_SRC';
10370 			G_Context := 'Source Warehouses Migration';
10371 			X_failure_count := 0;
10372 
10373 			/********************************
10374 			* Migration Started Log Message *
10375 			********************************/
10376 
10377 			GMA_COMMON_LOGGING.gma_migration_central_log
10378 			(
10379 			p_run_id             =>       G_migration_run_id,
10380 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
10381 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
10382 			p_table_name         =>       G_table_name,
10383 			p_context            =>       G_context,
10384 			p_db_error           =>       NULL,
10385 			p_app_short_name     =>       'GMA'
10386 			);
10387 
10388 			/***********************************************
10389 			* Update rows For Source Warehouses            *
10390 			***********************************************/
10391 
10392 			UPDATE      cm_whse_src a
10393 			SET         (
10394 									a.organization_id,
10395 									a.legal_entity_id,
10396 									a.delete_mark
10397 									)
10398 			=           (
10399 									SELECT      w.organization_id, z.legal_entity_id, decode(a.delete_mark, 1, 1, decode(nvl(w.inventory_org_ind, 'N'), 'Y', 0, 1))
10400 									FROM        gl_plcy_mst z, sy_orgn_mst w
10401 									WHERE       w.orgn_code = a.orgn_code
10402 									AND         w.co_code = z.co_code
10403 									),
10404 									a.source_organization_id =  (
10405 																							SELECT            DECODE(NVL(subinventory_ind_flag,'N'), 'Y', organization_id, mtl_organization_id)
10406 																							FROM              ic_whse_mst w1
10407 																							WHERE             w1.whse_code = a.whse_code
10408 																							)
10409 			WHERE       (a.legal_entity_id IS NULL AND a.orgn_code IS NOT NULL)
10410 			OR          (a.organization_id IS NULL AND a.orgn_code IS NOT NULL)
10411 			OR          (a.source_organization_id IS NULL AND a.whse_code IS NOT NULL);
10412 
10413 			UPDATE      cm_whse_src a
10414 			SET         (
10415 									a.master_organization_id,
10416 									a.inventory_item_id
10417 									)
10418 			=
10419 									(
10420 									SELECT         z.master_organization_id,
10421 																 y.inventory_item_id
10422 									FROM           ic_item_mst_b_mig y,
10423 																 mtl_parameters z,
10424 																 hr_organization_information hoi
10425 									WHERE          y.item_id = a.item_id
10426 									AND            y.organization_id = z.organization_id
10427 									AND            hoi.organization_id = z.organization_id
10428 									AND            hoi.org_information_context = 'Accounting Information'
10429 									AND            hoi.org_information2 = a.legal_entity_id
10430 									AND            y.organization_id = nvl(a.organization_id, y.organization_id)
10431 									AND            ROWNUM = 1
10432 									)
10433 			WHERE       (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
10434 			OR          (a.master_organization_id IS NULL AND a.item_id IS NOT NULL);
10435 
10436 			/********************************************************************************************************
10437 			* Insert records for Warehouses falling under OPM Organizations not migrated as Inventory Organizations *
10438 			********************************************************************************************************/
10439 
10440 			INSERT
10441 			INTO        cm_whse_src
10442 			(
10443 			src_whse_id,
10444 			calendar_code,
10445 			period_code,
10446 			sourcing_alloc_pct,
10447 			creation_date,
10448 			created_by,
10449 			last_update_date,
10450 			trans_cnt,
10451 			text_code,
10452 			delete_mark,
10453 			last_updated_by,
10454 			last_update_login,
10455 			cost_category_id,
10456 			inventory_item_id,
10457 			organization_id,
10458 			source_organization_id,
10459 			master_organization_id,
10460 			legal_entity_id
10461 			)
10462 			(
10463 			SELECT      /*+ ROWID(a) */
10464 									GEM5_src_whse_id_s.NEXTVAL,
10465 									a.calendar_code,
10466 									a.period_code,
10467 									a.sourcing_alloc_pct,
10468 									a.creation_date,
10469 									a.created_by,
10470 									a.last_update_date,
10471 									a.trans_cnt,
10472 									a.text_code,
10473 									0,
10474 									a.last_updated_by,
10475 									a.last_update_login,
10476 									a.cost_category_id,
10477 									a.inventory_item_id,
10478 									e.mtl_organization_id,
10479 									a.source_organization_id,
10480 									a.master_organization_id,
10481 									a.legal_entity_id
10482 			FROM        cm_whse_src a,
10483 									ic_whse_mst e
10484 			WHERE       NOT EXISTS  (
10485 															SELECT  'X'
10486 															FROM     cm_whse_src x
10487 															WHERE    x.legal_entity_id = a.legal_entity_id
10488 															AND      nvl(x.organization_id, -1) = nvl(e.mtl_organization_id, -1)
10489 															AND      x.calendar_code = a.calendar_code
10490 															AND      x.period_code = a.period_code
10491 															AND      nvl(x.inventory_item_id, -1) = nvl(a.inventory_item_id, -1)
10492 															AND      nvl(x.cost_category_id, -1) = nvl(a.cost_category_id, -1)
10493 															)
10494 			AND         e.orgn_code = a.orgn_code
10495 			AND         nvl(e.subinventory_ind_flag,'N') <> 'Y'
10496 			AND         e.mtl_organization_id IS NOT NULL
10497       AND         a.source_organization_id IS NOT NULL
10498       AND         a.inventory_item_id IS NOT NULL
10499       AND         a.legal_entity_id IS NOT NULL
10500 			);
10501 
10502 			/**********************************************
10503 			* Handle all the rows which were not migrated *
10504 			**********************************************/
10505 			gmf_migration.Log_Errors  (
10506 																p_log_level               =>          1,
10507 																p_from_rowid              =>          NULL,
10508 																p_to_rowid                =>          NULL
10509 																);
10510 
10511 			/****************************************************************
10512 			*Lets save the changes now based on the commit parameter        *
10513 			****************************************************************/
10514 
10515 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
10516 				 COMMIT;
10517 			END IF;
10518 
10519 	 EXCEPTION
10520 			WHEN OTHERS THEN
10521 
10522 				 /************************************************
10523 				 * Increment Failure Count for Failed Migrations *
10524 				 ************************************************/
10525 				 x_failure_count := x_failure_count + 1;
10526 
10527 				 /**************************************
10528 				 * Migration DB Error Log Message      *
10529 				 **************************************/
10530 
10531 				 GMA_COMMON_LOGGING.gma_migration_central_log
10532 				 (
10533 				 p_run_id             =>       G_migration_run_id,
10534 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
10535 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
10536 				 p_table_name         =>       G_table_name,
10537 				 p_context            =>       G_context,
10538 				 p_db_error           =>       SQLERRM,
10539 				 p_app_short_name     =>       'GMA'
10540 				 );
10541 
10542 				 /**************************************
10543 				 * Migration Failure Log Message       *
10544 				 **************************************/
10545 
10546 				 GMA_COMMON_LOGGING.gma_migration_central_log
10547 				 (
10548 				 p_run_id             =>       G_migration_run_id,
10549 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
10550 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
10551 				 p_table_name         =>       G_table_name,
10552 				 p_context            =>       G_context,
10553 				 p_db_error           =>       NULL,
10554 				 p_app_short_name     =>       'GMA'
10555 				 );
10556 
10557 	 END Migrate_Source_Warehouses;
10558 
10559 	 /**********************************************************************
10560 	 * PROCEDURE:                                                          *
10561 	 *   Migrate_Items                                                     *
10562 	 *                                                                     *
10563 	 * DESCRIPTION:                                                        *
10564 	 *   This PL/SQL procedure is used to migrate all OPM Financials Items *
10565 	 *                                                                     *
10566 	 * PARAMETERS:                                                         *
10567 	 *                                                                     *
10568 	 * SYNOPSIS:                                                           *
10569 	 *   Migrate_Items;                                                    *
10570 	 *                                                                     *
10571 	 * HISTORY                                                             *
10572 	 *       26-May-2006 Created  Anand Thiyagarajan                       *
10573 	 *       05-Jul-2006 rseshadr bug 5374823 - removed cm_cmpt_mtl and    *
10574 	 *         burden_percentages from cursor as these are now done inline *
10575 	 *                                                                     *
10576 	 **********************************************************************/
10577 	 PROCEDURE Migrate_Items
10578 	 (
10579 	 P_migration_run_id      IN             NUMBER,
10580 	 P_commit                IN             VARCHAR2,
10581 	 X_failure_count         OUT   NOCOPY   NUMBER
10582 	 )
10583 	 IS
10584 
10585 			/***************************
10586 			* PL/SQL Table Definitions *
10587 			***************************/
10588 
10589 			/************************
10590 			* Local Variables       *
10591 			************************/
10592 
10593 			l_inventory_item_id                 NUMBER;
10594 			l_failure_count                     NUMBER;
10595 
10596 			/****************
10597 			* Cursors       *
10598 			****************/
10599 
10600 			CURSOR            cur_get_gmf_items IS
10601 			SELECT            DISTINCT
10602 												item_id,
10603 												organization_id
10604 			FROM
10605 			(
10606 			SELECT            a.item_id,
10607 												NVL(DECODE(b.cost_organization_id, -1, b.mtl_organization_id, b.cost_organization_id), b.mtl_organization_id) organization_id
10608 			FROM              cm_acst_led a,
10609 												ic_whse_mst b
10610 			WHERE             a.item_id IS NOT NULL
10611 			AND               a.whse_code = b.whse_code
10612 			UNION
10613 			SELECT            a.item_id,
10614 												NVL(DECODE(b.cost_organization_id, -1, b.mtl_organization_id, b.cost_organization_id), b.mtl_organization_id) organization_id
10615 			FROM              cm_adjs_dtl a,
10616 												ic_whse_mst b
10617 			WHERE             a.item_id IS NOT NULL
10618 			AND               a.whse_code = b.whse_code
10619 			UNION
10620 			SELECT            a.item_id,
10621 												NVL(DECODE(b.cost_organization_id, -1, b.mtl_organization_id, b.cost_organization_id), b.mtl_organization_id) organization_id
10622 			FROM              cm_brdn_dtl a,
10623 												ic_whse_mst b
10624 			WHERE             a.item_id IS NOT NULL
10625 			AND               a.whse_code = b.whse_code
10626 			UNION
10627 			SELECT            a.item_id,
10628 												NVL(DECODE(b.cost_organization_id, -1, b.mtl_organization_id, b.cost_organization_id), b.mtl_organization_id) organization_id
10629 			FROM              cm_cmpt_dtl a,
10630 												ic_whse_mst b
10631 			WHERE             a.item_id IS NOT NULL
10632 			AND               a.whse_code = b.whse_code
10633 			UNION
10634 			SELECT            a.item_id,
10635 												NVL(DECODE(b.cost_organization_id, -1, b.mtl_organization_id, b.cost_organization_id), b.mtl_organization_id) organization_id
10636 			FROM              cm_scst_led a,
10637 												ic_whse_mst b
10638 			WHERE             a.item_id IS NOT NULL
10639 			AND               a.whse_code = b.whse_code
10640 			UNION
10641 			SELECT            a.item_id,
10642 												nvl(DECODE(NVL(c.subinventory_ind_flag,'N'), 'Y', c.organization_id, c.mtl_organization_id), DECODE(NVL(b.subinventory_ind_flag,'N'), 'Y', b.organization_id, b.mtl_organization_id)) organization_id
10643 			FROM              cm_whse_src a,
10644 												ic_whse_mst b,
10645 												ic_whse_mst c
10646 			WHERE             a.item_id IS NOT NULL
10647 			AND               b.orgn_code = a.orgn_code
10648 			AND               c.whse_code(+) = a.whse_code
10649 			UNION
10650 			SELECT            a.item_id,
10651 												NVL(DECODE(b.cost_organization_id, -1, b.mtl_organization_id, b.cost_organization_id), b.mtl_organization_id) organization_id
10652 			FROM              gl_item_cst a,
10653 												ic_whse_mst b
10654 			WHERE             a.item_id IS NOT NULL
10655 			AND               a.whse_code = b.whse_code
10656 			UNION
10657 			SELECT            a.item_id,
10658 												DECODE(NVL(c.subinventory_ind_flag,'N'), 'Y', c.organization_id, c.mtl_organization_id) organization_id
10659 			FROM              gmf_lot_costed_items a,
10660 												sy_orgn_mst b,
10661 												ic_whse_mst c
10662 			WHERE             a.item_id IS NOT NULL
10663 			AND               a.co_code = b.co_Code
10664 			AND               b.orgn_code = c.orgn_code
10665 			AND               nvl(c.subinventory_ind_flag,'N') <> 'Y'
10666 			UNION
10667 			SELECT            a.item_id,
10668 												NVL(DECODE(b.cost_organization_id, -1, b.mtl_organization_id, b.cost_organization_id), b.mtl_organization_id) organization_id
10669 			FROM              gmf_lot_Costs a,
10670 												ic_whse_mst b
10671 			WHERE             a.item_id IS NOT NULL
10672 			AND               a.whse_code = b.whse_code
10673 			UNION
10674 			SELECT            a.item_id,
10675 												NVL(DECODE(b.cost_organization_id, -1, b.mtl_organization_id, b.cost_organization_id), b.mtl_organization_id) organization_id
10676 			FROM              gmf_lot_Cost_adjustments a,
10677 												ic_whse_mst b
10678 			WHERE             a.item_id IS NOT NULL
10679 			AND               a.whse_code = b.whse_code
10680 			UNION
10681 			SELECT            a.item_id,
10682 												NVL(DECODE(b.cost_organization_id, -1, b.mtl_organization_id, b.cost_organization_id), b.mtl_organization_id) organization_id
10683 			FROM              gmf_lot_Cost_burdens a,
10684 												ic_whse_mst b
10685 			WHERE             a.item_id IS NOT NULL
10686 			AND               a.whse_code = b.whse_code
10687 			) x
10688 			WHERE             NOT EXISTS
10689 												(
10690 												SELECT        'X'
10691 												FROM          ic_item_mst_b_mig y
10692 												WHERE         y.item_id = x.item_id
10693 												AND           y.organization_id = x.organization_id
10694 												);
10695 
10696 	 BEGIN
10697 
10698 			G_Migration_run_id := P_migration_run_id;
10699 			G_Table_name := 'GMF_ITEMS_MIGRATION';
10700 			G_Context := 'Process Costing Items Migration';
10701 			X_failure_count := 0;
10702 
10703 			/********************************
10704 			* Migration Started Log Message *
10705 			********************************/
10706 
10707 			GMA_COMMON_LOGGING.gma_migration_central_log
10708 			(
10709 			p_run_id             =>       G_migration_run_id,
10710 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
10711 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
10712 			p_table_name         =>       G_Table_name,
10713 			p_context            =>       G_Context,
10714 			p_db_error           =>       NULL,
10715 			p_app_short_name     =>       'GMA'
10716 			);
10717 
10718 			/****************************************
10719 			* Call Item Migration API in a loop     *
10720 			****************************************/
10721 
10722 			FOR i IN cur_get_gmf_items
10723 			LOOP
10724 				IF i.item_id IS NOT NULL AND i.organization_id IS NOT NULL THEN
10725 					inv_opm_item_migration.get_odm_item
10726 					(
10727 					p_migration_run_id        =>        p_migration_run_id,
10728 					p_item_id                 =>        i.item_id,
10729 					p_organization_id         =>        i.organization_id,
10730 					p_mode                    =>        NULL,
10731 					p_commit                  =>        FND_API.G_TRUE,
10732 					x_inventory_item_id       =>        l_inventory_item_id,
10733 					x_failure_count           =>        l_failure_count
10734 					);
10735 				END IF;
10736 				x_failure_count := nvl(x_failure_count,0) + nvl(l_failure_count,0);
10737 			END LOOP;
10738 
10739 			/****************************************************************
10740 			* Lets save the changes now based on the commit parameter       *
10741 			****************************************************************/
10742 
10743 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
10744 				 COMMIT;
10745 			END IF;
10746 
10747 	 EXCEPTION
10748 			WHEN OTHERS THEN
10749 
10750 				 /************************************************
10751 				 * Increment Failure Count for Failed Migrations *
10752 				 ************************************************/
10753 				 x_failure_count := x_failure_count + 1;
10754 
10755 				 /**************************************
10756 				 * Migration DB Error Log Message      *
10757 				 **************************************/
10758 
10759 				 GMA_COMMON_LOGGING.gma_migration_central_log
10760 				 (
10761 				 p_run_id             =>       G_migration_run_id,
10762 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
10763 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
10764 				 p_table_name         =>       G_Table_name,
10765 				 p_context            =>       G_Context,
10766 				 p_db_error           =>       SQLERRM,
10767 				 p_app_short_name     =>       'GMA'
10768 				 );
10769 
10770 				 /**************************************
10771 				 * Migration Failure Log Message       *
10772 				 **************************************/
10773 
10774 				 GMA_COMMON_LOGGING.gma_migration_central_log
10775 				 (
10776 				 p_run_id             =>       G_migration_run_id,
10777 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
10778 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
10779 				 p_table_name         =>       G_Table_name,
10780 				 p_context            =>       G_Context,
10781 				 p_db_error           =>       NULL,
10782 				 p_app_short_name     =>       'GMA'
10783 				 );
10784 
10785 	 END Migrate_Items;
10786 
10787 	 /**********************************************************************
10788 	 * PROCEDURE:                                                          *
10789 	 *   Migrate_ActualCost_control                                        *
10790 	 *                                                                     *
10791 	 * DESCRIPTION:                                                        *
10792 	 *   This PL/SQL procedure is used to migrate the Actual cost control  *
10793 	 *   date Records                                                      *
10794 	 *                                                                     *
10795 	 * PARAMETERS:                                                         *
10796 	 *   P_migration_run_id - id to use to right to migration log          *
10797 	 *   x_exception_count  - Number of exceptions occurred.               *
10798 	 *                                                                     *
10799 	 * SYNOPSIS:                                                           *
10800 	 *   Migrate_ActualCost_control(p_migartion_id    => l_migration_id,   *
10801 	 *                    p_commit          => 'T',                        *
10802 	 *                    x_exception_count => l_exception_count );        *
10803 	 *                                                                     *
10804 	 * HISTORY                                                             *
10805 	 *       22-Aug-2006 Created  Prasad Marada, bug 5473343               *
10806 	 *                                                                     *
10807 	 **********************************************************************/
10808 	 PROCEDURE Migrate_ActualCost_control
10809 	 (
10810 	 P_migration_run_id      IN             NUMBER,
10811 	 P_commit                IN             VARCHAR2,
10812 	 X_failure_count         OUT   NOCOPY   NUMBER
10813 	 )
10814 	 IS
10815 
10816 			/***************************
10817 			* PL/SQL Table Definitions *
10818 			***************************/
10819 
10820 			/******************
10821 			* Local Variables *
10822 			******************/
10823 
10824 	 BEGIN
10825 
10826 			G_Migration_run_id := P_migration_run_id;
10827 			G_Table_name := 'CM_ACPR_CTL';
10828 			G_Context := 'Actual cost control data Migration';
10829 			X_failure_count := 0;
10830 
10831 			/********************************
10832 			* Migration Started Log Message *
10833 			********************************/
10834 
10835 			GMA_COMMON_LOGGING.gma_migration_central_log
10836 			(
10837 			p_run_id             =>       G_migration_run_id,
10838 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
10839 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
10840 			p_table_name         =>       G_Table_name,
10841 			p_context            =>       G_context,
10842 			p_db_error           =>       NULL,
10843 			p_app_short_name     =>       'GMA'
10844 			);
10845 
10846 
10847 			/**********************************
10848 			* Update row in CM_ACPR_CTL table *
10849 			***********************************/
10850 
10851 			BEGIN
10852 				UPDATE        cm_acpr_ctl cac
10853 				SET           (
10854 											cac.legal_entity_id,
10855 											cac.period_id,
10856 											cac.cost_type_id
10857 											)
10858 				=
10859 											(
10860 											select        gps.legal_entity_id, gps.period_id, gps.cost_type_id
10861 											from          gmf_period_statuses gps,
10862 																		cm_mthd_mst cmm,
10863 																		cm_cldr_hdr_b cch,
10864 																		gl_plcy_mst gpm
10865 											where         gps.calendar_code = cac.calendar_code
10866 											and           cch.calendar_code = cac.calendar_code
10867 											and           cch.co_code = gpm.co_code
10868 											and           gps.legal_entity_id = gpm.legal_entity_id
10869 											and           gps.period_code = cac.period_code
10870 											and           cmm.cost_mthd_code = cac.cost_mthd_code
10871 											and           cmm.cost_type_id = gps.cost_type_id
10872 											)
10873 				where         (cac.calendar_code is not null and cac.legal_entity_id is null)
10874 				OR            (cac.cost_mthd_code is not null AND cac.cost_type_id is null)
10875 				OR            (cac.calendar_code is not null and cac.period_code is not NULL AND cac.period_id is null);
10876 
10877 			EXCEPTION
10878 				 WHEN OTHERS THEN
10879 
10880 						/************************************************
10881 						* Increment Failure Count for Failed Migrations *
10882 						************************************************/
10883 
10884 						x_failure_count := x_failure_count + 1;
10885 
10886 						/**************************************
10887 						* Migration DB Error Log Message      *
10888 						**************************************/
10889 
10890 						GMA_COMMON_LOGGING.gma_migration_central_log
10891 						(
10892 						p_run_id             =>       G_migration_run_id,
10893 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
10894 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
10895 						p_table_name         =>       G_Table_name,
10896 						p_context            =>       G_context,
10897 						p_db_error           =>       SQLERRM,
10898 						p_app_short_name     =>       'GMA'
10899 						);
10900 
10901 						/**************************************
10902 						* Migration Failure Log Message       *
10903 						**************************************/
10904 
10905 						GMA_COMMON_LOGGING.gma_migration_central_log
10906 						(
10907 						p_run_id             =>       G_migration_run_id,
10908 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
10909 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
10910 						p_table_name         =>       G_Table_name,
10911 						p_context            =>       G_context,
10912 						p_db_error           =>       NULL,
10913 						p_app_short_name     =>       'GMA'
10914 						);
10915 
10916 			END;
10917 
10918 			/**********************************************
10919 			* Handle all the rows which were not migrated *
10920 			**********************************************/
10921 			gmf_migration.Log_Errors  (
10922 																p_log_level               =>          1,
10923 																p_from_rowid              =>          NULL,
10924 																p_to_rowid                =>          NULL
10925 																);
10926 
10927 			/****************************************************************
10928 			* Lets save the changes now based on the commit parameter       *
10929 			****************************************************************/
10930 
10931 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
10932 				 COMMIT;
10933 			END IF;
10934 
10935 	 EXCEPTION
10936 
10937 			WHEN OTHERS THEN
10938 
10939 				 /************************************************
10940 				 * Increment Failure Count for Failed Migrations *
10941 				 ************************************************/
10942 
10943 				 x_failure_count := x_failure_count + 1;
10944 
10945 				 /**************************************
10946 				 * Migration DB Error Log Message      *
10947 				 **************************************/
10948 
10949 				 GMA_COMMON_LOGGING.gma_migration_central_log
10950 				 (
10951 				 p_run_id             =>       G_migration_run_id,
10952 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
10953 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
10954 				 p_table_name         =>       G_Table_name,
10955 				 p_context            =>       G_context,
10956 				 p_param1             =>       NULL,
10957 				 p_param2             =>       NULL,
10958 				 p_db_error           =>       SQLERRM,
10959 				 p_app_short_name     =>       'GMA'
10960 				 );
10961 
10962 				 /**************************************
10963 				 * Migration Failure Log Message       *
10964 				 **************************************/
10965 
10966 				 GMA_COMMON_LOGGING.gma_migration_central_log
10967 				 (
10968 				 p_run_id             =>       G_migration_run_id,
10969 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
10970 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
10971 				 p_table_name         =>       G_Table_name,
10972 				 p_context            =>       G_context,
10973 				 p_db_error           =>       NULL,
10974 				 p_app_short_name     =>       'GMA'
10975 				 );
10976 
10977 	 END Migrate_ActualCost_control;
10978 
10979 	 /**********************************************************************
10980 	 * PROCEDURE:                                                          *
10981 	 *   Migrate_Rollup_control                                            *
10982 	 *                                                                     *
10983 	 * DESCRIPTION:                                                        *
10984 	 *   This PL/SQL procedure is used to migrate the rollup cost control  *
10985 	 *   data Records                                                      *
10986 	 *                                                                     *
10987 	 * PARAMETERS:                                                         *
10988 	 *   P_migration_run_id - id to use to right to migration log          *
10989 	 *   x_exception_count  - Number of exceptions occurred.               *
10990 	 *                                                                     *
10991 	 * SYNOPSIS:                                                           *
10992 	 *   Migrate_rollup_control(p_migartion_id    => l_migration_id,       *
10993 	 *                    p_commit          => 'T',                        *
10994 	 *                    x_exception_count => l_exception_count );        *
10995 	 *                                                                     *
10996 	 * HISTORY                                                             *
10997 	 *       30-Aug-2006 Created  Prasad Marada, bug 5473343               *
10998 	 *                                                                     *
10999 	 **********************************************************************/
11000 	 PROCEDURE Migrate_Rollup_control
11001 	 (
11002 	 P_migration_run_id      IN             NUMBER,
11003 	 P_commit                IN             VARCHAR2,
11004 	 X_failure_count         OUT   NOCOPY   NUMBER
11005 	 )
11006 	 IS
11007 
11008 			/***************************
11009 			* PL/SQL Table Definitions *
11010 			***************************/
11011 
11012 			/******************
11013 			* Local Variables *
11014 			******************/
11015 
11016 	 BEGIN
11017 
11018 			G_Migration_run_id := P_migration_run_id;
11019 			G_Table_name := 'CM_RLUP_CTL';
11020 			G_Context := 'Rollup Control Record Migration';
11021 			X_failure_count := 0;
11022 
11023 			/********************************
11024 			* Migration Started Log Message *
11025 			********************************/
11026 
11027 			GMA_COMMON_LOGGING.gma_migration_central_log
11028 			(
11029 			p_run_id             =>       G_migration_run_id,
11030 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
11031 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
11032 			p_table_name         =>       G_Table_name,
11033 			p_context            =>       G_context,
11034 			p_db_error           =>       NULL,
11035 			p_app_short_name     =>       'GMA'
11036 			);
11037 
11038 			/**********************************
11039 			* Update row in CM_RLUP_CTL table *
11040 			***********************************/
11041 
11042 			BEGIN
11043 
11044 				UPDATE            cm_rlup_ctl crc
11045 				SET               (
11046 													crc.legal_entity_id,
11047 													crc.period_id,
11048 													crc.cost_type_id
11049 													)
11050 				=
11051 													(
11052 													SELECT        gps.legal_entity_id,
11053 																				gps.period_id,
11054 																				gps.cost_type_id
11055 													FROM          gmf_period_statuses gps,
11056 																				cm_mthd_mst cmm,
11057 																				cm_cldr_hdr_b cch,
11058 																				gl_plcy_mst gpm
11059 													WHERE         gps.calendar_code = crc.calendar_code
11060 													AND           cch.calendar_code = crc.calendar_code
11061 													AND           cch.co_code = gpm.co_code
11062 													AND           gps.legal_entity_id = gpm.legal_entity_id
11063 													AND           gps.period_code = crc.period_code
11064 													AND           cmm.cost_mthd_code = crc.cost_mthd_code
11065 													AND           cmm.cost_type_id = gps.cost_type_id
11066 													)
11067 				WHERE             (crc.CALENDAR_CODE IS NOT NULL  AND crc.PERIOD_CODE IS NOT NULL AND crc.PERIOD_ID IS NULL)
11068 				OR                (crc.COST_MTHD_CODE IS NOT NULL AND crc.COST_TYPE_ID IS NULL)
11069 				OR                (crc.CALENDAR_CODE IS NOT NULL  AND crc.LEGAL_ENTITY_ID IS NULL);
11070 
11071 				UPDATE            cm_rlup_ctl a
11072 				SET               (
11073 													a.master_organization_id,
11074 													a.inventory_item_id
11075 													)
11076 				=                 (
11077 													SELECT            z.master_organization_id,
11078 																						y.inventory_item_id
11079 													FROM              ic_item_mst_b_mig y,
11080 																						mtl_parameters z,
11081 																						hr_organization_information hoi
11082 													WHERE             y.item_id = a.item_id
11083 													AND               y.organization_id = z.organization_id
11084 													AND               hoi.organization_id = z.organization_id
11085 													AND               hoi.org_information_context = 'Accounting Information'
11086 													AND               hoi.org_information2 = a.legal_entity_id
11087 													AND               ROWNUM = 1
11088 													)
11089 				WHERE             (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
11090 				OR                (a.master_organization_id IS NULL AND a.item_id IS NOT NULL);
11091 
11092 			EXCEPTION
11093 				 WHEN OTHERS THEN
11094 
11095 						/************************************************
11096 						* Increment Failure Count for Failed Migrations *
11097 						************************************************/
11098 
11099 						x_failure_count := x_failure_count + 1;
11100 
11101 						/**************************************
11102 						* Migration DB Error Log Message      *
11103 						**************************************/
11104 
11105 						GMA_COMMON_LOGGING.gma_migration_central_log
11106 						(
11107 						p_run_id             =>       G_migration_run_id,
11108 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
11109 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
11110 						p_table_name         =>       G_Table_name,
11111 						p_context            =>       G_context,
11112 						p_db_error           =>       SQLERRM,
11113 						p_app_short_name     =>       'GMA'
11114 						);
11115 
11116 						/**************************************
11117 						* Migration Failure Log Message       *
11118 						**************************************/
11119 
11120 						GMA_COMMON_LOGGING.gma_migration_central_log
11121 						(
11122 						p_run_id             =>       G_migration_run_id,
11123 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
11124 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
11125 						p_table_name         =>       G_Table_name,
11126 						p_context            =>       G_context,
11127 						p_db_error           =>       NULL,
11128 						p_app_short_name     =>       'GMA'
11129 						);
11130 
11131 			END;
11132 
11133 			/**********************************************
11134 			* Handle all the rows which were not migrated *
11135 			**********************************************/
11136 			gmf_migration.Log_Errors  (
11137 																p_log_level               =>          1,
11138 																p_from_rowid              =>          NULL,
11139 																p_to_rowid                =>          NULL
11140 																);
11141 
11142 			G_Table_name := 'CM_RLUP_ITM';
11143 			G_Context := 'Rollup Items Migration';
11144 			X_failure_count := 0;
11145 
11146 			/********************************
11147 			* Migration Started Log Message *
11148 			********************************/
11149 
11150 			GMA_COMMON_LOGGING.gma_migration_central_log
11151 			(
11152 			p_run_id             =>       G_migration_run_id,
11153 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
11154 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
11155 			p_table_name         =>       G_Table_name,
11156 			p_context            =>       G_context,
11157 			p_db_error           =>       NULL,
11158 			p_app_short_name     =>       'GMA'
11159 			);
11160 
11161 			/**********************************
11162 			* Update row in CM_RLUP_ITM table *
11163 			***********************************/
11164 
11165 			BEGIN
11166 
11167 				UPDATE            cm_rlup_itm a
11168 				SET               (
11169 													a.organization_id,
11170 													a.inventory_item_id
11171 													)
11172 				=                 (
11173 													SELECT            z.master_organization_id,
11174 																						y.inventory_item_id
11175 													FROM              ic_item_mst_b_mig y,
11176 																						mtl_parameters z,
11177 																						hr_organization_information hoi,
11178 																						cm_rlup_ctl x
11179 													WHERE             y.item_id = a.item_id
11180 													AND               y.organization_id = z.organization_id
11181 													AND               hoi.organization_id = z.organization_id
11182 													AND               hoi.org_information_context = 'Accounting Information'
11183 													AND               hoi.org_information2 = x.legal_entity_id
11184 													AND               x.rollup_id = a.rollup_id
11185 													AND               ROWNUM = 1
11186 													)
11187 				WHERE             (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
11188 				OR                (a.organization_id IS NULL AND a.item_id IS NOT NULL);
11189 
11190 			EXCEPTION
11191 				 WHEN OTHERS THEN
11192 
11193 						/************************************************
11194 						* Increment Failure Count for Failed Migrations *
11195 						************************************************/
11196 
11197 						x_failure_count := x_failure_count + 1;
11198 
11199 						/**************************************
11200 						* Migration DB Error Log Message      *
11201 						**************************************/
11202 
11203 						GMA_COMMON_LOGGING.gma_migration_central_log
11204 						(
11205 						p_run_id             =>       G_migration_run_id,
11206 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
11207 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
11208 						p_table_name         =>       G_Table_name,
11209 						p_context            =>       G_context,
11210 						p_db_error           =>       SQLERRM,
11211 						p_app_short_name     =>       'GMA'
11212 						);
11213 
11214 						/**************************************
11215 						* Migration Failure Log Message       *
11216 						**************************************/
11217 
11218 						GMA_COMMON_LOGGING.gma_migration_central_log
11219 						(
11220 						p_run_id             =>       G_migration_run_id,
11221 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
11222 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
11223 						p_table_name         =>       G_Table_name,
11224 						p_context            =>       G_context,
11225 						p_db_error           =>       NULL,
11226 						p_app_short_name     =>       'GMA'
11227 						);
11228 
11229 			END;
11230 
11231 			/**********************************************
11232 			* Handle all the rows which were not migrated *
11233 			**********************************************/
11234 			gmf_migration.Log_Errors  (
11235 																p_log_level               =>          1,
11236 																p_from_rowid              =>          NULL,
11237 																p_to_rowid                =>          NULL
11238 																);
11239 
11240 			/****************************************************************
11241 			* Lets save the changes now based on the commit parameter       *
11242 			****************************************************************/
11243 
11244 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
11245 				 COMMIT;
11246 			END IF;
11247 
11248 	 EXCEPTION
11249 
11250 			WHEN OTHERS THEN
11251 
11252 				 /************************************************
11253 				 * Increment Failure Count for Failed Migrations *
11254 				 ************************************************/
11255 
11256 				 x_failure_count := x_failure_count + 1;
11257 
11258 				 /**************************************
11259 				 * Migration DB Error Log Message      *
11260 				 **************************************/
11261 
11262 				 GMA_COMMON_LOGGING.gma_migration_central_log
11263 				 (
11264 				 p_run_id             =>       G_migration_run_id,
11265 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
11266 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
11267 				 p_table_name         =>       G_Table_name,
11268 				 p_context            =>       G_context,
11269 				 p_param1             =>       NULL,
11270 				 p_param2             =>       NULL,
11271 				 p_db_error           =>       SQLERRM,
11272 				 p_app_short_name     =>       'GMA'
11273 				 );
11274 
11275 				 /**************************************
11276 				 * Migration Failure Log Message       *
11277 				 **************************************/
11278 
11279 				 GMA_COMMON_LOGGING.gma_migration_central_log
11280 				 (
11281 				 p_run_id             =>       G_migration_run_id,
11282 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
11283 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
11284 				 p_table_name         =>       G_Table_name,
11285 				 p_context            =>       G_context,
11286 				 p_db_error           =>       NULL,
11287 				 p_app_short_name     =>       'GMA'
11288 				 );
11289 
11290 	 END Migrate_Rollup_control;
11291 
11292 	 /**********************************************************************
11293 	 * PROCEDURE:                                                          *
11294 	 *   Migrate_CostUpdate_control                                        *
11295 	 *                                                                     *
11296 	 * DESCRIPTION:                                                        *
11297 	 *   This PL/SQL procedure is used to migrate the Cost Update control  *
11298 	 *   date Records                                                      *
11299 	 *                                                                     *
11300 	 * PARAMETERS:                                                         *
11301 	 *   P_migration_run_id - id to use to right to migration log          *
11302 	 *   x_exception_count  - Number of exceptions occurred.               *
11303 	 *                                                                     *
11304 	 * SYNOPSIS:                                                           *
11305 	 *   Migrate_CostUpdate_control(p_migartion_id    => l_migration_id,   *
11306 	 *                    p_commit          => 'T',                        *
11307 	 *                    x_exception_count => l_exception_count );        *
11308 	 *                                                                     *
11309 	 * HISTORY                                                             *
11310 	 *       08-Sep-2006 Created  Anand Thiyagarajan                       *
11311 	 *                                                                     *
11312 	 **********************************************************************/
11313 	 PROCEDURE Migrate_CostUpdate_control
11314 	 (
11315 	 P_migration_run_id      IN             NUMBER,
11316 	 P_commit                IN             VARCHAR2,
11317 	 X_failure_count         OUT   NOCOPY   NUMBER
11318 	 )
11319 	 IS
11320 
11321 			/***************************
11322 			* PL/SQL Table Definitions *
11323 			***************************/
11324 
11325 			/******************
11326 			* Local Variables *
11327 			******************/
11328 
11329 	 BEGIN
11330 
11331 			G_Migration_run_id := P_migration_run_id;
11332 			G_Table_name := 'CM_CUPD_CTL';
11333 			G_Context := 'Cost Update control data Migration';
11334 			X_failure_count := 0;
11335 
11336 			/********************************
11337 			* Migration Started Log Message *
11338 			********************************/
11339 
11340 			GMA_COMMON_LOGGING.gma_migration_central_log
11341 			(
11342 			p_run_id             =>       G_migration_run_id,
11343 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
11344 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
11345 			p_table_name         =>       G_Table_name,
11346 			p_context            =>       G_context,
11347 			p_db_error           =>       NULL,
11348 			p_app_short_name     =>       'GMA'
11349 			);
11350 
11351 
11352 			/**********************************
11353 			* Update row in CM_ACPR_CTL table *
11354 			***********************************/
11355 
11356 			BEGIN
11357 				UPDATE        cm_cupd_ctl ccc
11358 				SET           (
11359 											ccc.legal_entity_id,
11360 											ccc.period_id,
11361 											ccc.cost_type_id
11362 											)
11363 				=
11364 											(
11365 											select        gps.legal_entity_id, gps.period_id, gps.cost_type_id
11366 											from          gmf_period_statuses gps,
11367 																		cm_mthd_mst cmm,
11368 																		gl_plcy_mst gpm
11369 											where         gps.calendar_code = ccc.calendar_code
11370 											and           gpm.co_code = ccc.co_code
11371 											and           gps.period_code = ccc.period_code
11372 											and           cmm.cost_mthd_code = ccc.cost_mthd_code
11373 											and           gps.legal_entity_id = gpm.legal_entity_id
11374 											and           cmm.cost_type_id = gps.cost_type_id
11375 											)
11376 				where         (ccc.calendar_code is not null and ccc.legal_entity_id is null)
11377 				OR            (ccc.cost_mthd_code is not null AND ccc.cost_type_id is null)
11378 				OR            (ccc.calendar_code is not null and ccc.period_code is not NULL AND ccc.period_id is null);
11379 
11380 			EXCEPTION
11381 				 WHEN OTHERS THEN
11382 
11383 						/************************************************
11384 						* Increment Failure Count for Failed Migrations *
11385 						************************************************/
11386 
11387 						x_failure_count := x_failure_count + 1;
11388 
11389 						/**************************************
11390 						* Migration DB Error Log Message      *
11391 						**************************************/
11392 
11393 						GMA_COMMON_LOGGING.gma_migration_central_log
11394 						(
11395 						p_run_id             =>       G_migration_run_id,
11396 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
11397 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
11398 						p_table_name         =>       G_Table_name,
11399 						p_context            =>       G_context,
11400 						p_db_error           =>       SQLERRM,
11401 						p_app_short_name     =>       'GMA'
11402 						);
11403 
11404 						/**************************************
11405 						* Migration Failure Log Message       *
11406 						**************************************/
11407 
11408 						GMA_COMMON_LOGGING.gma_migration_central_log
11409 						(
11410 						p_run_id             =>       G_migration_run_id,
11411 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
11412 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
11413 						p_table_name         =>       G_Table_name,
11414 						p_context            =>       G_context,
11415 						p_db_error           =>       NULL,
11416 						p_app_short_name     =>       'GMA'
11417 						);
11418 
11419 			END;
11420 
11421 			/**********************************************
11422 			* Handle all the rows which were not migrated *
11423 			**********************************************/
11424 			gmf_migration.Log_Errors  (
11425 																p_log_level               =>          1,
11426 																p_from_rowid              =>          NULL,
11427 																p_to_rowid                =>          NULL
11428 																);
11429 
11430 			/****************************************************************
11431 			* Lets save the changes now based on the commit parameter       *
11432 			****************************************************************/
11433 
11434 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
11435 				 COMMIT;
11436 			END IF;
11437 
11438 	 EXCEPTION
11439 
11440 			WHEN OTHERS THEN
11441 
11442 				 /************************************************
11443 				 * Increment Failure Count for Failed Migrations *
11444 				 ************************************************/
11445 
11446 				 x_failure_count := x_failure_count + 1;
11447 
11448 				 /**************************************
11449 				 * Migration DB Error Log Message      *
11450 				 **************************************/
11451 
11452 				 GMA_COMMON_LOGGING.gma_migration_central_log
11453 				 (
11454 				 p_run_id             =>       G_migration_run_id,
11455 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
11456 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
11457 				 p_table_name         =>       G_Table_name,
11458 				 p_context            =>       G_context,
11459 				 p_param1             =>       NULL,
11460 				 p_param2             =>       NULL,
11461 				 p_db_error           =>       SQLERRM,
11462 				 p_app_short_name     =>       'GMA'
11463 				 );
11464 
11465 				 /**************************************
11466 				 * Migration Failure Log Message       *
11467 				 **************************************/
11468 
11469 				 GMA_COMMON_LOGGING.gma_migration_central_log
11470 				 (
11471 				 p_run_id             =>       G_migration_run_id,
11472 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
11473 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
11474 				 p_table_name         =>       G_Table_name,
11475 				 p_context            =>       G_context,
11476 				 p_db_error           =>       NULL,
11477 				 p_app_short_name     =>       'GMA'
11478 				 );
11479 
11480 	 END Migrate_CostUpdate_control;
11481 
11482 	 /**********************************************************************
11483 	 * PROCEDURE:                                                          *
11484 	 *   Migrate_SubLedger_control                                         *
11485 	 *                                                                     *
11486 	 * DESCRIPTION:                                                        *
11487 	 *   This PL/SQL procedure is used to migrate the Sub Ledger control   *
11488 	 *   date Records                                                      *
11489 	 *                                                                     *
11490 	 * PARAMETERS:                                                         *
11491 	 *   P_migration_run_id - id to use to right to migration log          *
11492 	 *   x_exception_count  - Number of exceptions occurred.               *
11493 	 *                                                                     *
11494 	 * SYNOPSIS:                                                           *
11495 	 *   Migrate_SubLedger_control(p_migartion_id    => l_migration_id,    *
11496 	 *                    p_commit          => 'T',                        *
11497 	 *                    x_exception_count => l_exception_count );        *
11498 	 *                                                                     *
11499 	 * HISTORY                                                             *
11500 	 *       08-Sep-2006 Created  Anand Thiyagarajan                       *
11501 	 *                                                                     *
11502 	 **********************************************************************/
11503 	 PROCEDURE Migrate_SubLedger_control
11504 	 (
11505 	 P_migration_run_id      IN             NUMBER,
11506 	 P_commit                IN             VARCHAR2,
11507 	 X_failure_count         OUT   NOCOPY   NUMBER
11508 	 )
11509 	 IS
11510 
11511 			/***************************
11512 			* PL/SQL Table Definitions *
11513 			***************************/
11514 
11515 			/******************
11516 			* Local Variables *
11517 			******************/
11518 
11519 	 BEGIN
11520 
11521 			G_Migration_run_id := P_migration_run_id;
11522 			G_Table_name := 'GL_SUBR_STA';
11523 			G_Context := 'Sub Ledger control data Migration';
11524 			X_failure_count := 0;
11525 
11526 			/********************************
11527 			* Migration Started Log Message *
11528 			********************************/
11529 
11530 			GMA_COMMON_LOGGING.gma_migration_central_log
11531 			(
11532 			p_run_id             =>       G_migration_run_id,
11533 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
11534 			p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
11535 			p_table_name         =>       G_Table_name,
11536 			p_context            =>       G_context,
11537 			p_db_error           =>       NULL,
11538 			p_app_short_name     =>       'GMA'
11539 			);
11540 
11541 
11542 			/**********************************
11543 			* Update row in GL_SUBR_STA table *
11544 			***********************************/
11545 
11546 			BEGIN
11547 				UPDATE        gl_subr_sta a
11548 				SET           (
11549 											a.legal_entity_id,
11550 											a.legal_entity_name,
11551 											a.base_currency,
11552 											a.ledger_id,
11553 											a.cost_mthd_code,
11554 											a.cost_type,
11555 											a.cost_type_id,
11556 											a.default_cost_mthd_code,
11557 											a.default_cost_type_id,
11558 											a.cost_basis
11559 											)
11560 				=
11561 											(
11562 											select        gfp.legal_entity_id,
11563 																		xep.name,
11564 																		gfp.base_currency_code,
11565 																		gfp.ledger_id,
11566 																		cmm.cost_mthd_code,
11567 																		cmm.cost_type,
11568 																		cmm.cost_type_id,
11569 																		dcmm.cost_mthd_code default_lot_cost_mthd_code,
11570 																		cmm.default_lot_cost_type_id,
11571 																		gfp.cost_basis
11572 											from          cm_mthd_mst cmm,
11573 																		cm_mthd_mst dcmm,
11574 																		gl_plcy_mst gpm,
11575 																		gmf_fiscal_policies gfp,
11576 																		xle_entity_profiles xep
11577 											where         gpm.co_code = a.co_code
11578 											and           gfp.legal_entity_id = gpm.legal_entity_id
11579 											and           xep.legal_entity_id = gfp.legal_entity_id
11580 											and           cmm.cost_type_id = gfp.cost_type_id
11581 											and           cmm.default_lot_cost_type_id = dcmm.cost_type_id(+)
11582 											),
11583 											a.post_cm_rval = decode(a.post_cm, 1, 1, 0),
11584 											a.post_cm_cadj = 0
11585 				where         (a.co_code is not null and a.legal_entity_id is null)
11586 				OR            (a.co_code is not null and a.cost_type_id is null);
11587 
11588 				UPDATE        gl_subr_sta gss
11589 				SET           (
11590 											gss.crev_curr_cost_type_id,
11591 											gss.crev_curr_period_id
11592 											)
11593 				=
11594 											(
11595 											select        gps.cost_type_id , gps.period_id
11596 											from          gmf_period_statuses gps,
11597 																		cm_mthd_mst cmm
11598 											where         gps.calendar_code = gss.crev_curr_calendar
11599 											and           gps.period_code = gss.crev_curr_period
11600 											and           cmm.cost_mthd_code = gss.crev_curr_mthd
11601 											and           gps.legal_entity_id = gss.legal_entity_id
11602 											and           cmm.cost_type_id = gps.cost_type_id
11603 											),
11604 											(
11605 											gss.crev_prev_cost_type_id,
11606 											gss.crev_prev_period_id
11607 											)
11608 				=
11609 											(
11610 											select        gps.cost_type_id , gps.period_id
11611 											from          gmf_period_statuses gps,
11612 																		cm_mthd_mst cmm
11613 											where         gps.calendar_code = gss.crev_prev_calendar
11614 											and           gps.period_code = gss.crev_prev_period
11615 											and           cmm.cost_mthd_code = gss.crev_prev_mthd
11616 											and           gps.legal_entity_id = gss.legal_entity_id
11617 											and           cmm.cost_type_id = gps.cost_type_id
11618 											),
11619 											gss.period_id
11620 				=             (
11621 											SELECT        x.period_id
11622 											FROM          gmf_period_statuses x
11623 											WHERE         x.legal_entity_id = gss.legal_entity_id
11624 											AND           x.cost_type_id    = gss.cost_type_id
11625 											AND           gss.period_start_date between x.start_date and x.end_date
11626 											AND           gss.period_end_date between x.start_date and x.end_date
11627 											AND           x.delete_mark <> 1
11628 											AND           ROWNUM = 1
11629 											)
11630 				where         (gss.crev_curr_mthd is not null AND gss.crev_curr_cost_type_id IS NULL)
11631 				OR            (gss.crev_curr_calendar is not null and gss.crev_curr_period is not NULL AND gss.crev_curr_period_id is null)
11632 				OR            (gss.crev_prev_mthd is not null AND gss.crev_prev_cost_type_id IS NULL)
11633 				OR            (gss.crev_prev_calendar is not null and gss.crev_prev_period is not NULL AND gss.crev_prev_period_id is null)
11634 				OR            (gss.legal_entity_id IS NOT NULL AND gss.cost_type_id IS NOT NULL AND gss.period_id IS NULL);
11635 
11636 			EXCEPTION
11637 				 WHEN OTHERS THEN
11638 
11639 						/************************************************
11640 						* Increment Failure Count for Failed Migrations *
11641 						************************************************/
11642 
11643 						x_failure_count := x_failure_count + 1;
11644 
11645 						/**************************************
11646 						* Migration DB Error Log Message      *
11647 						**************************************/
11648 
11649 						GMA_COMMON_LOGGING.gma_migration_central_log
11650 						(
11651 						p_run_id             =>       G_migration_run_id,
11652 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
11653 						p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
11654 						p_table_name         =>       G_Table_name,
11655 						p_context            =>       G_context,
11656 						p_db_error           =>       SQLERRM,
11657 						p_app_short_name     =>       'GMA'
11658 						);
11659 
11660 						/**************************************
11661 						* Migration Failure Log Message       *
11662 						**************************************/
11663 
11664 						GMA_COMMON_LOGGING.gma_migration_central_log
11665 						(
11666 						p_run_id             =>       G_migration_run_id,
11667 						p_log_level          =>       FND_LOG.LEVEL_ERROR,
11668 						p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
11669 						p_table_name         =>       G_Table_name,
11670 						p_context            =>       G_context,
11671 						p_db_error           =>       NULL,
11672 						p_app_short_name     =>       'GMA'
11673 						);
11674 
11675 			END;
11676 
11677 			/**********************************************
11678 			* Handle all the rows which were not migrated *
11679 			**********************************************/
11680 			gmf_migration.Log_Errors  (
11681 																p_log_level               =>          1,
11682 																p_from_rowid              =>          NULL,
11683 																p_to_rowid                =>          NULL
11684 																);
11685 
11686 			/****************************************************************
11687 			* Lets save the changes now based on the commit parameter       *
11688 			****************************************************************/
11689 
11690 			IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
11691 				 COMMIT;
11692 			END IF;
11693 
11694 	 EXCEPTION
11695 
11696 			WHEN OTHERS THEN
11697 
11698 				 /************************************************
11699 				 * Increment Failure Count for Failed Migrations *
11700 				 ************************************************/
11701 
11702 				 x_failure_count := x_failure_count + 1;
11703 
11704 				 /**************************************
11705 				 * Migration DB Error Log Message      *
11706 				 **************************************/
11707 
11708 				 GMA_COMMON_LOGGING.gma_migration_central_log
11709 				 (
11710 				 p_run_id             =>       G_migration_run_id,
11711 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
11712 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
11713 				 p_table_name         =>       G_Table_name,
11714 				 p_context            =>       G_context,
11715 				 p_param1             =>       NULL,
11716 				 p_param2             =>       NULL,
11717 				 p_db_error           =>       SQLERRM,
11718 				 p_app_short_name     =>       'GMA'
11719 				 );
11720 
11721 				 /**************************************
11722 				 * Migration Failure Log Message       *
11723 				 **************************************/
11724 
11725 				 GMA_COMMON_LOGGING.gma_migration_central_log
11726 				 (
11727 				 p_run_id             =>       G_migration_run_id,
11728 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
11729 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
11730 				 p_table_name         =>       G_Table_name,
11731 				 p_context            =>       G_context,
11732 				 p_db_error           =>       NULL,
11733 				 p_app_short_name     =>       'GMA'
11734 				 );
11735 
11736 	 END Migrate_SubLedger_control;
11737 
11738 	/**********************************************************************
11739 	* PROCEDURE:                                                          *
11740 	*   Migrate_Cost_Warehouses                                           *
11741 	*                                                                     *
11742 	* DESCRIPTION:                                                        *
11743 	*   This PL/SQL procedure is used to transform the Cost Warehouses    *
11744 	*   data in CM_WHSE_ASC                                               *
11745 	*                                                                     *
11746 	* PARAMETERS:                                                         *
11747 	*   P_migration_run_id - id to use to right to migration log          *
11748 	*   x_exception_count  - Number of exceptions occurred.               *
11749 	*                                                                     *
11750 	* SYNOPSIS:                                                           *
11751 	*   Migrate_Cost_Warehouses(p_migartion_id    => l_migration_id,      *
11752 	*                    p_commit          => 'T',                        *
11753 	*                    x_exception_count => l_exception_count );        *
11754 	*                                                                     *
11755 	* HISTORY                                                             *
11756 	*       04-Nov-2005 Created  rseshadr                                 *
11757 	*                                                                     *
11758 	**********************************************************************/
11759 	PROCEDURE Migrate_Cost_Warehouses
11760 	(
11761 	P_migration_run_id      IN             NUMBER,
11762 	P_commit                IN             VARCHAR2,
11763 	X_failure_count         OUT   NOCOPY   NUMBER
11764 	)
11765 	IS
11766 
11767 			/****************
11768 			* PL/SQL Tables *
11769 			****************/
11770 
11771 			/******************
11772 			* Local Variables *
11773 			******************/
11774 
11775 			l_costing_organization_id           NUMBER;
11776 
11777 			/**********
11778 			* Cursors *
11779 			**********/
11780 		 CURSOR                 cur_ic_whse_mst
11781 		 IS
11782 		 SELECT                 a.whse_code,
11783 														NVL(a.subinventory_ind_flag, 'N') subinventory_ind_flag,
11784 														a.mtl_organization_id,
11785 														a.organization_id,
11786 														b.orgn_code,
11787 														NVL(b.inventory_org_ind, 'N') inventory_org_ind,
11788 														NVL(b.migrate_as_ind, 0) orgn_migrated_as_ind,
11789 														decode(a.organization_id, a.mtl_organization_id, 'Y', 'N') same_plant_whse,
11790 														SUM(decode(NVL(c.subinventory_ind_flag, 'N'), 'N', 0, 1)) Subinventory_count,
11791 														DECODE(COUNT(d.cost_whse_code), 0, 'N', 'Y') cost_warehouse,
11792 														DECODE(COUNT(f.cost_whse_code), 0, 'N', 'Y') same_plant_cost_warehouse,
11793 														DECODE(SUM(DECODE(f.cost_whse_code, NULL, 0, DECODE(NVL(c.subinventory_ind_flag, 'N'), 'N', 0, 1))), 0, 'N', 'Y') cost_whse_is_subinv,
11794 														DECODE(COUNT(e.whse_code), 0, 'N', 'Y') inv_warehouse
11795 		 FROM                   ic_whse_mst a,
11796 														sy_orgn_mst b,
11797 														ic_whse_mst c,
11798 														cm_whse_asc d,
11799 														cm_whse_asc e,
11800 														cm_whse_asc f
11801 		 WHERE                  a.orgn_code = b.orgn_code
11802 		 AND                    c.orgn_code = a.orgn_code
11803 		 AND                    d.cost_whse_code(+) = a.whse_code
11804 		 AND                    f.cost_whse_code(+) = c.whse_code
11805 		 AND                    e.whse_code(+) = a.whse_code
11806 		 AND                    SYSDATE BETWEEN d.eff_start_date(+) AND d.eff_end_date(+)
11807 		 AND                    SYSDATE BETWEEN e.eff_start_date(+) AND e.eff_end_date(+)
11808 		 AND                    SYSDATE BETWEEN f.eff_start_date(+) AND f.eff_end_date(+)
11809 		 GROUP BY               a.whse_code,
11810 														a.subinventory_ind_flag,
11811 														a.mtl_organization_id,
11812 														a.organization_id,
11813 														b.orgn_code,
11814 														b.inventory_org_ind,
11815 														b.migrate_as_ind,
11816 														b.organization_id
11817 		 ORDER BY               a.whse_code;
11818 	BEGIN
11819 
11820 		G_Migration_run_id := P_migration_run_id;
11821 		G_Table_name := 'CM_WHSE_ASC';
11822 		G_Context := 'Cost Warehouses Migration';
11823 		X_failure_count := 0;
11824 
11825 		/********************************
11826 		* Migration Started Log Message *
11827 		********************************/
11828 
11829 		GMA_COMMON_LOGGING.gma_migration_central_log
11830 		(
11831 		p_run_id             =>       G_migration_run_id,
11832 		p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
11833 		p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
11834 		p_table_name         =>       G_table_name,
11835 		p_context            =>       G_context,
11836 		p_db_error           =>       NULL,
11837 		p_app_short_name     =>       'GMA'
11838 		);
11839 
11840 		/***********************************************************************************
11841 		* Migrate warehouse records in IC_WHSE_MST to facilitate Cost Warehouse Derivation *
11842 		***********************************************************************************/
11843 		FOR i IN cur_ic_whse_mst LOOP
11844 			IF nvl(i.subinventory_ind_flag, 'N') <> 'Y' THEN            /* Migrated as Inventory Organization */
11845 				l_costing_organization_id := i.mtl_organization_id;
11846 			ELSE                                                        /* Migrated as Sub-Inventory */
11847 				IF nvl(i.Subinventory_count,0) = 1  THEN                  /* Only Warehouse under the plant Migrated as Sub-Inventory */
11848 					l_costing_organization_id := i.organization_id;
11849 				ELSE                                                      /* More than One Sub-inventory under the plant */
11850 					IF NVL(i.cost_warehouse,'N') = 'Y' THEN                 /* Exists as Cost Warehoue */
11851 						IF NVL(i.orgn_migrated_as_ind, 0) IN (1, 2) THEN      /* OPM Plant Migrated as New or Existing Organization*/
11852 							l_costing_organization_id := i.organization_id;
11853 						ELSE                                                  /* OPM Plant Migrated as None or Inactive */
11854 							l_costing_organization_id := i.mtl_organization_id;
11855 						END IF;
11856 					ELSIF NVL(i.inv_warehouse,'N') = 'Y' THEN               /* Exists as Inventory Warehoue under a Cost Warehouse */
11857 						IF nvl(i.same_plant_whse, 'N') = 'Y'
11858 						AND nvl(i.same_plant_cost_warehouse, 'N') = 'Y'
11859 						AND nvl(i.cost_whse_is_subinv, 'N') = 'Y' THEN         /* OPM Plant Migrated to Own Warehouse's Organization Id */
11860 							l_costing_organization_id := -1;
11861 						ELSE                                                  /* Migrated to Different Warehouse's Organization Id */
11862 							l_costing_organization_id := i.mtl_organization_id;
11863 						END IF;
11864 					ELSE                                                    /* Doesnt Exist as INV or Cost Warehouse */
11865 						l_costing_organization_id := i.mtl_organization_id;
11866 					END IF;
11867 				END IF;
11868 			END IF;
11869 
11870 			UPDATE              ic_whse_mst a
11871 			SET                 a.cost_organization_id = l_costing_organization_id
11872 			WHERE               a.whse_code = i.whse_code;
11873 		END LOOP;
11874 
11875 		UPDATE                  cm_whse_asc a
11876 		SET                     (
11877 														a.organization_id
11878 														)
11879 		=                       (
11880 														SELECT            x.cost_organization_id
11881 														FROM              ic_whse_mst x
11882 														WHERE             x.whse_code = a.whse_code
11883 														),
11884 														(
11885 														a.cost_organization_id
11886 														)
11887 		=                       (
11888 														SELECT            x.cost_organization_id
11889 														FROM              ic_whse_mst x
11890 														WHERE             x.whse_code = a.cost_whse_code
11891 														);
11892 
11893 		UPDATE                  cm_whse_asc a
11894 		SET                     delete_mark = 1
11895 		WHERE                   (
11896 														ROWID NOT IN  (
11897 																					SELECT        MIN(ROWID)
11898 																					FROM          cm_whse_asc x
11899 																					WHERE         x.cost_organization_id = a.cost_organization_id
11900 																					AND           x.organization_id = a.organization_id
11901 																					AND           x.delete_mark <> 1
11902 																					AND           (
11903 																												(a.eff_start_date BETWEEN x.eff_start_date AND x.eff_end_date)
11904 																												OR
11905 																												(a.eff_end_date BETWEEN x.eff_start_date AND x.eff_end_date)
11906 																												)
11907 																					)
11908 														)
11909 		OR                      cost_organization_id = -1;
11910 
11911 		/**********************************************
11912 		* Handle all the rows which were not migrated *
11913 		**********************************************/
11914 
11915 		SELECT               count(*)
11916 		INTO                 x_failure_count
11917 		FROM                 cm_whse_asc
11918 		WHERE                (organization_id IS NULL AND whse_code IS NOT NULL)
11919 		OR                   (cost_organization_id IS NULL AND cost_whse_code IS NOT NULL);
11920 
11921 		IF nvl(x_failure_count,0) > 0 THEN
11922 
11923 			/**************************************
11924 			* Migration Failure Log Message       *
11925 			**************************************/
11926 
11927 			GMA_COMMON_LOGGING.gma_migration_central_log
11928 			(
11929 			p_run_id             =>       gmf_migration.G_migration_run_id,
11930 			p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
11931 			p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
11932 			p_table_name         =>       gmf_migration.G_Table_name,
11933 			p_context            =>       gmf_migration.G_context,
11934 			p_db_error           =>       NULL,
11935 			p_app_short_name     =>       'GMA'
11936 			);
11937 
11938 		ELSE
11939 
11940 			/**************************************
11941 			* Migration Success Log Message       *
11942 			**************************************/
11943 
11944 			GMA_COMMON_LOGGING.gma_migration_central_log
11945 			(
11946 			p_run_id             =>       G_migration_run_id,
11947 			p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
11948 			p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
11949 			p_table_name         =>       G_Table_name,
11950 			p_context            =>       G_Context,
11951 			p_param1             =>       1,
11952 			p_param2             =>       0,
11953 			p_db_error           =>       NULL,
11954 			p_app_short_name     =>       'GMA'
11955 			);
11956 
11957 		END IF;
11958 
11959 		/****************************************************************
11960 		* Lets save the changes now based on the commit parameter       *
11961 		****************************************************************/
11962 
11963 		IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
11964 			 COMMIT;
11965 		END IF;
11966 
11967 	 EXCEPTION
11968 			WHEN OTHERS THEN
11969 
11970 				 /************************************************
11971 				 * Increment Failure Count for Failed Migrations *
11972 				 ************************************************/
11973 				 x_failure_count := x_failure_count + 1;
11974 
11975 				 /**************************************
11976 				 * Migration DB Error Log Message      *
11977 				 **************************************/
11978 
11979 				 GMA_COMMON_LOGGING.gma_migration_central_log
11980 				 (
11981 				 p_run_id             =>       G_migration_run_id,
11982 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
11983 				 p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
11984 				 p_table_name         =>       G_table_name,
11985 				 p_context            =>       G_context,
11986 				 p_db_error           =>       SQLERRM,
11987 				 p_app_short_name     =>       'GMA'
11988 				 );
11989 
11990 				 /**************************************
11991 				 * Migration Failure Log Message       *
11992 				 **************************************/
11993 
11994 				 GMA_COMMON_LOGGING.gma_migration_central_log
11995 				 (
11996 				 p_run_id             =>       G_migration_run_id,
11997 				 p_log_level          =>       FND_LOG.LEVEL_ERROR,
11998 				 p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
11999 				 p_table_name         =>       G_table_name,
12000 				 p_context            =>       G_context,
12001 				 p_db_error           =>       NULL,
12002 				 p_app_short_name     =>       'GMA'
12003 				 );
12004 
12005 	 END Migrate_Cost_Warehouses;
12006 
12007 	/**********************************************************************
12008 	* PROCEDURE:                                                          *
12009 	*   Log_Errors                                                        *
12010 	*                                                                     *
12011 	* DESCRIPTION:                                                        *
12012 	*   This PL/SQL procedure is used to Log Errors from the Migration Run*
12013 	*                                                                     *
12014 	* PARAMETERS:                                                         *
12015 	*                                                                     *
12016 	* SYNOPSIS:                                                           *
12017 	*   Log Errors;                                                       *
12018 	*                                                                     *
12019 	* HISTORY                                                             *
12020 	*       23-Sep-2006 Created  Anand Thiyagarajan                       *
12021 	*                                                                     *
12022 	**********************************************************************/
12023 	PROCEDURE Log_Errors
12024 	(
12025 	p_log_level             IN             PLS_INTEGER DEFAULT 2,
12026 	p_from_rowid            IN             ROWID,
12027 	p_to_rowid              IN             ROWID
12028 	)
12029 	IS
12030 
12031 			/****************
12032 			* PL/SQL Tables *
12033 			****************/
12034 			TYPE p_error_rec IS RECORD (table_name VARCHAR2(30), column_name VARCHAR2(30), parameters VARCHAR2(1000), records BINARY_INTEGER);
12035 			TYPE p_error_tbl IS TABLE OF p_error_rec INDEX BY BINARY_INTEGER;
12036 
12037       TYPE p_cur_gmf_log_errors IS REF CURSOR;
12038 
12039 			/******************
12040 			* Local Variables *
12041 			******************/
12042 			l_error_tbl                     p_error_tbl;
12043 			l_table_name                    VARCHAR2(256) := gmf_migration.G_Table_name;
12044 			l_sql_statement                 VARCHAR2(32000) := 'SELECT count(*) FROM '||l_table_name||' WHERE ';
12045 			l_failure_count                 NUMBER;
12046 			l_legal_entity_count            PLS_INTEGER := 0;
12047 			l_organization_count            PLS_INTEGER := 0;
12048 			l_source_organization_count     PLS_INTEGER := 0;
12049 			l_master_organization_count     PLS_INTEGER := 0;
12050 			l_inventory_item_count          PLS_INTEGER := 0;
12051       l_lot_number_count              PLS_INTEGER := 0;
12052 			l_cost_type_count               PLS_INTEGER := 0;
12053 			l_prev_cost_type_count          PLS_INTEGER := 0;
12054 			l_curr_cost_type_count          PLS_INTEGER := 0;
12055 			l_period_count                  PLS_INTEGER := 0;
12056 			l_prev_period_count             PLS_INTEGER := 0;
12057 			l_curr_period_count             PLS_INTEGER := 0;
12058 			l_adjustment_ind_count          PLS_INTEGER := 0;
12059 			l_uom_count1                    PLS_INTEGER := 0;
12060 			l_uom_count2                    PLS_INTEGER := 0;
12061 			l_uom_count3                    PLS_INTEGER := 0;
12062 			l_unique_error_count            PLS_INTEGER := 0;
12063 			l_not_null_error_count          PLS_INTEGER := 0;
12064 			l_value_error_count             PLS_INTEGER := 0;
12065 			l_parent_key_error_count        PLS_INTEGER := 0;
12066 			l_too_long_error_count          PLS_INTEGER := 0;
12067 			l_invalid_number_error_count    PLS_INTEGER := 0;
12068       l_not_picked_up_error_count     PLS_INTEGER := 0;
12069 			l_total_error_count             PLS_INTEGER := 0;
12070 
12071 			l_cm_rsrc_dtl                   VARCHAR2(32000) := 'SELECT                ''CM_RSRC_DTL'' table_name,
12072                                                   														  cm_rsrc_dtl.*
12073                                                     			FROM                  (
12074                                                     														SELECT                ''LEGAL_ENTITY_ID'' column_name,
12075                                                     																									''Orgn Code: ''|| orgn_code parameters,
12076                                                     																									count(*) records
12077                                                     														FROM                  cm_rsrc_dtl
12078                                                     														WHERE                 (legal_entity_id IS NULL AND orgn_code IS NOT NULL)
12079                                                     														GROUP BY              orgn_code
12080                                                     														HAVING                count(*) > 0
12081                                                     														UNION
12082                                                     														SELECT                ''ORGANIZATION_ID'' column_name,
12083                                                     																									''Orgn Code: ''|| orgn_code parameters,
12084                                                     																									count(*) records
12085                                                     														FROM                  cm_rsrc_dtl
12086                                                     														WHERE                 (organization_id IS NULL AND delete_mark = 0 AND orgn_code IS NOT NULL)
12087                                                     														GROUP BY              orgn_code
12088                                                     														HAVING                count(*) > 0
12089                                                     														UNION
12090                                                     														SELECT                ''COST_TYPE_ID'' column_name,
12091                                                     																									''Cost Method Code: ''|| cost_mthd_code parameters,
12092                                                     																									count(*) records
12093                                                     														FROM                  cm_rsrc_dtl
12094                                                     														WHERE                 (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
12095                                                     														GROUP BY              cost_mthd_code
12096                                                     														HAVING                count(*) > 0
12097                                                     														UNION
12098                                                     														SELECT                ''PERIOD_ID'' column_name,
12099                                                     																									''Calendar Code: ''|| calendar_code ||'', Period Code: ''|| period_code parameters,
12100                                                     																									count(*) records
12101                                                     														FROM                  cm_rsrc_dtl
12102                                                     														WHERE                 (period_id IS NULL AND calendar_code IS NOT NULL AND period_code IS NOT NULL)
12103                                                     														GROUP BY              calendar_code, period_code
12104                                                     														HAVING                count(*) > 0
12105                                                     														UNION
12106                                                     														SELECT                ''USAGE_UOM'' column_name,
12107                                                     																									''UM Code: ''|| usage_um parameters,
12108                                                     																									count(*) records
12109                                                     														FROM                  cm_rsrc_dtl
12110                                                     														WHERE                 (usage_uom IS NULL AND usage_um IS NOT NULL)
12111                                                     														GROUP BY              usage_um
12112                                                     														HAVING                count(*) > 0
12113                                                     														) cm_rsrc_dtl';
12114 			l_cm_adjs_dtl                   VARCHAR2(32000) := 'SELECT                ''CM_ADJS_DTL'' table_name,
12115                                                                                 cm_adjs_dtl.*
12116                                                             FROM                (
12117                                                                                 SELECT                ''ORGANIZATION_ID'' column_name,
12118                                                                                                       ''Warehouse Code: ''|| whse_code parameters,
12119                                                                                                       count(*) records
12120                                                                                 FROM                  cm_adjs_dtl
12121                                                                                 WHERE                 (organization_id IS NULL AND whse_code IS NOT NULL)
12122                                                                                 GROUP BY              whse_code
12123                                                                                 HAVING                count(*) > 0
12124                                                                                 UNION
12125                                                                                 SELECT                ''INVENTORY_ITEM_ID'' column_name,
12126                                                                                                       ''Item No: ''|| b.item_no parameters,
12127                                                                                                       count(*) records
12128                                                                                 FROM                  cm_adjs_dtl a, ic_item_mst b
12129                                                                                 WHERE                 (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
12130                                                                                 AND                   b.item_id = a.item_id
12131                                                                                 GROUP BY              b.item_no
12132                                                                                 HAVING                count(*) > 0
12133                                                                                 UNION
12134                                                                                 SELECT                ''COST_TYPE_ID'' column_name,
12135                                                                                                       ''Cost Method Code: ''|| cost_mthd_code parameters,
12136                                                                                                       count(*) records
12137                                                                                 FROM                  cm_adjs_dtl
12138                                                                                 WHERE                 (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
12139                                                                                 GROUP BY              cost_mthd_code
12140                                                                                 HAVING                count(*) > 0
12141                                                                                 UNION
12142                                                                                 SELECT                ''PERIOD_ID'' column_name,
12143                                                                                                       ''Calendar Code: ''|| calendar_code ||'', Period Code: ''|| period_code parameters,
12144                                                                                                       count(*) records
12145                                                                                 FROM                  cm_adjs_dtl
12146                                                                                 WHERE                 (period_id IS NULL AND calendar_code IS NOT NULL AND period_code IS NOT NULL)
12147                                                                                 GROUP BY              calendar_code, period_code
12148                                                                                 HAVING                count(*) > 0
12149                                                                                 UNION
12150                                                                                 SELECT                ''ADJUST_QTY_UOM'' column_name,
12151                                                                                                       ''Adjust qty UM: ''|| adjust_qty_um parameters,
12152                                                                                                       count(*) records
12153                                                                                 FROM                  cm_adjs_dtl
12154                                                                                 WHERE                 (adjust_qty_uom IS NULL AND adjust_qty_um IS NOT NULL)
12155                                                                                 GROUP BY              adjust_qty_um
12156                                                                                 HAVING                count(*) > 0
12157                                                                                 UNION
12158                                                                                 SELECT                ''ADJUSTMENT_IND'' column_name,
12159                                                                                                       ''NULL'' parameters,
12160                                                                                                       count(*) records
12161                                                                                 FROM                  cm_adjs_dtl
12162                                                                                 WHERE                 (adjustment_ind IS NULL)
12163                                                                                 HAVING                count(*) > 0
12164                                                                                 ) cm_adjs_dtl';
12165 			l_cm_cmpt_dtl                   VARCHAR2(32000) := 'SELECT                ''CM_CMPT_DTL'' table_name,
12166                                                     														cm_cmpt_dtl.*
12167                                                     			FROM                  (
12168                                                     														SELECT                ''ORGANIZATION_ID'' column_name,
12169                                                     																									''Warehouse Code: ''|| whse_code parameters,
12170                                                     																									count(*) records
12171                                                     														FROM                  cm_cmpt_dtl
12172                                                     														WHERE                 (organization_id IS NULL AND whse_code IS NOT NULL)
12173                                                     														GROUP BY              whse_code
12174                                                     														HAVING                count(*) > 0
12175                                                     														UNION
12176                                                     														SELECT                ''INVENTORY_ITEM_ID'' column_name,
12177                                                     																									''Item No: ''|| b.item_no parameters,
12178                                                     																									count(*) records
12179                                                     														FROM                  cm_cmpt_dtl a, ic_item_mst b
12180                                                     														WHERE                 (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
12181                                                     														AND                   b.item_id = a.item_id
12182                                                     														GROUP BY              b.item_no
12183                                                     														HAVING                count(*) > 0
12184                                                     														UNION
12185                                                     														SELECT                ''COST_TYPE_ID'' column_name,
12186                                                     																									''Cost Method Code: ''|| cost_mthd_code parameters,
12187                                                     																									count(*) records
12188                                                     														FROM                  cm_cmpt_dtl
12189                                                     														WHERE                 (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
12190                                                     														GROUP BY              cost_mthd_code
12191                                                     														HAVING                count(*) > 0
12192                                                     														UNION
12193                                                     														SELECT                ''PERIOD_ID'' column_name,
12194                                                     																									''Calendar Code: ''|| calendar_code ||'', Period Code: ''|| period_code parameters,
12195                                                     																									count(*) records
12196                                                     														FROM                  cm_cmpt_dtl
12197                                                     														WHERE                 (period_id IS NULL AND calendar_code IS NOT NULL AND period_code IS NOT NULL)
12198                                                     														GROUP BY              calendar_code, period_code
12199                                                     														HAVING                count(*) > 0
12200                                                     														) cm_cmpt_dtl';
12201       l_cm_brdn_dtl                   VARCHAR2(32000) := 'SELECT                ''CM_BRDN_DTL'' table_name,
12202                                                       														cm_brdn_dtl.*
12203                                                           FROM                  (
12204                                                                                 SELECT                ''ORGANIZATION_ID'' column_name,
12205                                                                                                       ''Warehouse Code: ''|| whse_code parameters,
12206                                                                                                       count(*) records
12207                                                                                 FROM                  cm_brdn_dtl
12208                                                                                 WHERE                 (organization_id IS NULL AND whse_code IS NOT NULL)
12209                                                                                 GROUP BY              whse_code
12210                                                                                 HAVING                count(*) > 0
12211                                                                                 UNION
12212                                                                                 SELECT                ''INVENTORY_ITEM_ID'' column_name,
12213                                                                                                       ''Item No: ''|| b.item_no parameters,
12214                                                                                                       count(*) records
12215                                                                                 FROM                  cm_brdn_dtl a, ic_item_mst b
12216                                                                                 WHERE                 (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
12217                                                                                 AND                   b.item_id = a.item_id
12218                                                                                 GROUP BY              b.item_no
12219                                                                                 HAVING                count(*) > 0
12220                                                                                 UNION
12221                                                                                 SELECT                ''COST_TYPE_ID'' column_name,
12222                                                                                                       ''Cost Method Code: ''|| cost_mthd_code parameters,
12223                                                                                                       count(*) records
12224                                                                                 FROM                  cm_brdn_dtl
12225                                                                                 WHERE                 (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
12226                                                                                 GROUP BY              cost_mthd_code
12227                                                                                 HAVING                count(*) > 0
12228                                                                                 UNION
12229                                                                                 SELECT                ''PERIOD_ID'' column_name,
12230                                                                                                       ''Calendar Code: ''|| calendar_code ||'', Period Code: ''|| period_code parameters,
12231                                                                                                       count(*) records
12232                                                                                 FROM                  cm_brdn_dtl
12233                                                                                 WHERE                 (period_id IS NULL AND calendar_code IS NOT NULL AND period_code IS NOT NULL)
12234                                                                                 GROUP BY              calendar_code, period_code
12235                                                                                 HAVING                count(*) > 0
12236                                                                                 UNION
12237                                                                                 SELECT                ''ITEM_UOM'' column_name,
12238                                                                                                       ''Item UM: ''|| item_um parameters,
12239                                                                                                       count(*) records
12240                                                                                 FROM                  cm_brdn_dtl
12241                                                                                 WHERE                 (item_uom IS NULL AND item_um IS NOT NULL)
12242                                                                                 GROUP BY              item_um
12243                                                                                 HAVING                count(*) > 0
12244                                                                                 UNION
12245                                                                                 SELECT                ''BURDEN_UOM'' column_name,
12246                                                                                                       ''Burden UM: ''|| burden_um parameters,
12247                                                                                                       count(*) records
12248                                                                                 FROM                  cm_brdn_dtl
12249                                                                                 WHERE                 (burden_uom IS NULL AND burden_um IS NOT NULL)
12250                                                                                 GROUP BY              burden_um
12251                                                                                 HAVING                count(*) > 0
12252                                                                                 ) cm_brdn_dtl';
12253 			l_gl_item_cst                   VARCHAR2(32000) := 'SELECT                ''GL_ITEM_CST'' table_name,
12254                                                                                   gl_item_cst.*
12255                                                           FROM                  (
12256                                                                                 SELECT                ''ORGANIZATION_ID'' column_name,
12257                                                                                                       ''Warehouse Code: ''|| whse_code parameters,
12258                                                                                                       count(*) records
12259                                                                                 FROM                  gl_item_cst
12260                                                                                 WHERE                 (organization_id IS NULL AND whse_code IS NOT NULL)
12261                                                                                 GROUP BY              whse_code
12262                                                                                 HAVING                count(*) > 0
12263                                                                                 UNION
12264                                                                                 SELECT                ''INVENTORY_ITEM_ID'' column_name,
12265                                                                                                       ''Item No: ''|| b.item_no parameters,
12266                                                                                                       count(*) records
12267                                                                                 FROM                  gl_item_cst a, ic_item_mst b
12268                                                                                 WHERE                 (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
12269                                                                                 AND                   b.item_id = a.item_id
12270                                                                                 GROUP BY              b.item_no
12271                                                                                 HAVING                count(*) > 0
12272                                                                                 UNION
12273                                                                                 SELECT                ''COST_TYPE_ID'' column_name,
12274                                                                                                       ''Cost Method Code: ''|| cost_mthd_code parameters,
12275                                                                                                       count(*) records
12276                                                                                 FROM                  gl_item_cst
12277                                                                                 WHERE                 (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
12278                                                                                 GROUP BY              cost_mthd_code
12279                                                                                 HAVING                count(*) > 0
12280                                                                                 UNION
12281                                                                                 SELECT                ''PERIOD_ID'' column_name,
12282                                                                                                       ''Calendar Code: ''|| calendar_code ||'', Period Code: ''|| period_code parameters,
12283                                                                                                       count(*) records
12284                                                                                 FROM                  gl_item_cst
12285                                                                                 WHERE                 (period_id IS NULL AND calendar_code IS NOT NULL AND period_code IS NOT NULL)
12286                                                                                 GROUP BY              calendar_code, period_code
12287                                                                                 HAVING                count(*) > 0
12288                                                                                 ) gl_item_cst';
12289       l_cm_scst_led                   VARCHAR2(32000) := 'SELECT                ''CM_SCST_LED'' table_name,
12290                                                       														cm_scst_led.*
12291                                                           FROM                  (
12292                                                                                 SELECT                ''ORGANIZATION_ID'' column_name,
12293                                                                                                       ''Warehouse Code: ''|| whse_code parameters,
12294                                                                                                       count(*) records
12295                                                                                 FROM                  cm_scst_led
12296                                                                                 WHERE                 (organization_id IS NULL AND whse_code IS NOT NULL)
12297                                                                                 GROUP BY              whse_code
12298                                                                                 HAVING                count(*) > 0
12299                                                                                 UNION
12300                                                                                 SELECT                ''INVENTORY_ITEM_ID'' column_name,
12301                                                                                                       ''Item No: ''|| b.item_no parameters,
12302                                                                                                       count(*) records
12303                                                                                 FROM                  cm_scst_led a, ic_item_mst b
12304                                                                                 WHERE                 (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
12305                                                                                 AND                   b.item_id = a.item_id
12306                                                                                 GROUP BY              b.item_no
12307                                                                                 HAVING                count(*) > 0
12308                                                                                 UNION
12309                                                                                 SELECT                ''FORM_PROD_UOM'' column_name,
12310                                                                                                       ''Formula UM: ''|| form_prod_um parameters,
12311                                                                                                       count(*) records
12312                                                                                 FROM                  cm_scst_led
12313                                                                                 WHERE                 (form_prod_uom IS NULL AND form_prod_um IS NOT NULL)
12314                                                                                 GROUP BY              form_prod_um
12315                                                                                 HAVING                count(*) > 0
12316                                                                                 UNION
12317                                                                                 SELECT                ''ITEM_FMQTY_UOM'' column_name,
12318                                                                                                       ''Item UOM: ''|| item_fmqty_um parameters,
12319                                                                                                       count(*) records
12320                                                                                 FROM                  cm_scst_led
12321                                                                                 WHERE                 (item_fmqty_uom IS NULL AND item_fmqty_um IS NOT NULL)
12322                                                                                 GROUP BY              item_fmqty_um
12323                                                                                 HAVING                count(*) > 0
12324                                                                                 UNION
12325                                                                                 SELECT                ''USAGE_UOM'' column_name,
12326                                                                                                       ''Usage UOM: ''|| usage_um parameters,
12327                                                                                                       count(*) records
12328                                                                                 FROM                  cm_scst_led
12329                                                                                 WHERE                 (usage_uom IS NULL AND usage_um IS NOT NULL)
12330                                                                                 GROUP BY              usage_um
12331                                                                                 HAVING                count(*) > 0
12332                                                                                 ) cm_scst_led';
12333 			l_cm_acst_led                   VARCHAR2(32000) := 'SELECT                ''CM_ACST_LED'' table_name,
12334                                                     														cm_acst_led.*
12335                                                     			FROM                  (
12336                                                     														SELECT                ''ORGANIZATION_ID'' column_name,
12337                                                     																									''Warehouse Code: ''|| whse_code parameters,
12338                                                     																									count(*) records
12339                                                     														FROM                  cm_acst_led
12340                                                     														WHERE                 (organization_id IS NULL AND whse_code IS NOT NULL)
12341                                                     														GROUP BY              whse_code
12342                                                     														HAVING                count(*) > 0
12343                                                     														UNION
12344                                                     														SELECT                ''INVENTORY_ITEM_ID'' column_name,
12345                                                     																									''Item No: ''|| b.item_no parameters,
12346                                                     																									count(*) records
12347                                                     														FROM                  cm_acst_led a, ic_item_mst b
12348                                                     														WHERE                 (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
12349                                                     														AND                   b.item_id = a.item_id
12350                                                     														GROUP BY              b.item_no
12351                                                     														HAVING                count(*) > 0
12352                                                     														UNION
12353                                                     														SELECT                ''COST_TYPE_ID'' column_name,
12354                                                     																									''Cost Method Code: ''|| cost_mthd_code parameters,
12355                                                     																									count(*) records
12356                                                     														FROM                  cm_acst_led
12357                                                     														WHERE                 (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
12358                                                     														GROUP BY              cost_mthd_code
12359                                                     														HAVING                count(*) > 0
12360                                                     														UNION
12361                                                     														SELECT                ''PERIOD_ID'' column_name,
12362                                                     																									''Calendar Code: ''|| calendar_code ||'', Period Code: ''|| period_code parameters,
12363                                                     																									count(*) records
12364                                                     														FROM                  cm_acst_led
12365                                                     														WHERE                 (period_id IS NULL AND calendar_code IS NOT NULL AND period_code IS NOT NULL)
12366                                                     														GROUP BY              calendar_code, period_code
12367                                                     														HAVING                count(*) > 0
12368                                                     														) cm_acst_led';
12369 			l_gmf_lot_costs                 VARCHAR2(32000) := 'SELECT                ''GMF_LOT_COSTS'' table_name,
12370                                                                                 gmf_lot_costs.*
12371                                                           FROM                  (
12372                                                                                 SELECT                ''ORGANIZATION_ID'' column_name,
12373                                                                                                       ''Warehouse Code: ''|| whse_code parameters,
12374                                                                                                       count(*) records
12375                                                                                 FROM                  gmf_lot_costs
12376                                                                                 WHERE                 (organization_id IS NULL AND whse_code IS NOT NULL)
12377                                                                                 GROUP BY              whse_code
12378                                                                                 HAVING                count(*) > 0
12379                                                                                 UNION
12380                                                                                 SELECT                ''INVENTORY_ITEM_ID'' column_name,
12381                                                                                                       ''Item No: ''|| b.item_no parameters,
12382                                                                                                       count(*) records
12383                                                                                 FROM                  gmf_lot_costs a, ic_item_mst b
12384                                                                                 WHERE                 (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
12385                                                                                 AND                   b.item_id = a.item_id
12386                                                                                 GROUP BY              b.item_no
12387                                                                                 HAVING                count(*) > 0
12388                                                                                 UNION
12389                                                                                 SELECT                ''COST_TYPE_ID'' column_name,
12390                                                                                                       ''Cost Method Code: ''|| cost_mthd_code parameters,
12391                                                                                                       count(*) records
12392                                                                                 FROM                  gmf_lot_costs
12393                                                                                 WHERE                 (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
12394                                                                                 GROUP BY              cost_mthd_code
12395                                                                                 HAVING                count(*) > 0
12396                                                                                 UNION
12397                                                                                 SELECT                ''LOT_NUMBER'' column_name,
12398                                                                                                       ''Lot Id: ''|| lot_id parameters,
12399                                                                                                       count(*) records
12400                                                                                 FROM                  gmf_lot_costs
12401                                                                                 WHERE                 (lot_number IS NULL AND lot_id IS NOT NULL)
12402                                                                                 GROUP BY              lot_id
12403                                                                                 HAVING                count(*) > 0
12404                                                                                 ) gmf_lot_costs';
12405 			l_gmf_lot_costed_items          VARCHAR2(32000) := 'SELECT                ''GMF_LOT_COSTED_ITEMS'' table_name,
12406                                                     														gmf_lot_costed_items.*
12407                                                     			FROM                  (
12408                                                     														SELECT                ''LEGAL_ENTITY_ID'' column_name,
12409                                                     																									''Co Code: ''|| co_code parameters,
12410                                                     																									count(*) records
12411                                                     														FROM                  gmf_lot_costed_items
12412                                                     														WHERE                 (legal_entity_id IS NULL AND co_code IS NOT NULL)
12413                                                     														GROUP BY              co_code
12414                                                     														HAVING                count(*) > 0
12415                                                     														UNION
12416                                                     														SELECT                ''MASTER_ORGANIZATION_ID'' column_name,
12417                                                     																									''Item No: ''|| b.item_no ||'' Legal Entity: ''||a.legal_entity_id parameters,
12418                                                     																									count(*) records
12419                                                     														FROM                  gmf_lot_costed_items a, ic_item_mst b
12420                                                     														WHERE                 (a.legal_entity_id IS NULL AND a.item_id IS NOT NULL)
12421                                                     														AND                   b.item_id = a.item_id
12422                                                     														GROUP BY              b.item_no, a.legal_entity_id
12423                                                     														HAVING                count(*) > 0
12424                                                     														UNION
12425                                                     														SELECT                ''INVENTORY_ITEM_ID'' column_name,
12426                                                     																									''Item No: ''|| b.item_no parameters,
12427                                                     																									count(*) records
12428                                                     														FROM                  gmf_lot_costed_items a, ic_item_mst b
12429                                                     														WHERE                 (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
12430                                                     														AND                   b.item_id = a.item_id
12431                                                     														GROUP BY              b.item_no
12432                                                     														HAVING                count(*) > 0
12433                                                     														UNION
12434                                                     														SELECT                ''COST_TYPE_ID'' column_name,
12435                                                     																									''Cost Method Code: ''|| cost_mthd_code parameters,
12436                                                     																									count(*) records
12437                                                     														FROM                  gmf_lot_costed_items
12438                                                     														WHERE                 (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
12439                                                     														GROUP BY              cost_mthd_code
12440                                                     														HAVING                count(*) > 0
12441                                                     														) gmf_lot_costed_items';
12442 			l_gmf_lot_cost_burdens          VARCHAR2(32000) := 'SELECT                ''GMF_LOT_COST_BURDENS'' table_name,
12443                                                     														gmf_lot_cost_burdens.*
12444                                                     			FROM                  (
12445                                                     														SELECT                ''ORGANIZATION_ID'' column_name,
12446                                                     																									''Warehouse Code: ''|| whse_code parameters,
12447                                                     																									count(*) records
12448                                                     														FROM                  gmf_lot_cost_burdens
12449                                                     														WHERE                 (organization_id IS NULL AND whse_code IS NOT NULL)
12450                                                     														GROUP BY              whse_code
12451                                                     														HAVING                count(*) > 0
12452                                                     														UNION
12453                                                     														SELECT                ''INVENTORY_ITEM_ID'' column_name,
12454                                                     																									''Item No: ''|| b.item_no parameters,
12455                                                     																									count(*) records
12456                                                     														FROM                  gmf_lot_cost_burdens a, ic_item_mst b
12457                                                     														WHERE                 (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
12458                                                     														AND                   b.item_id = a.item_id
12459                                                     														GROUP BY              b.item_no
12460                                                     														HAVING                count(*) > 0
12461                                                     														UNION
12462                                                     														SELECT                ''COST_TYPE_ID'' column_name,
12463                                                     																									''Cost Method Code: ''|| cost_mthd_code parameters,
12464                                                     																									count(*) records
12465                                                     														FROM                  gmf_lot_cost_burdens
12466                                                     														WHERE                 (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
12467                                                     														GROUP BY              cost_mthd_code
12468                                                     														HAVING                count(*) > 0
12469                                                     														UNION
12470                                                     														SELECT                ''ITEM_UOM'' column_name,
12471                                                     																									''Item UOM: ''|| Item_um parameters,
12472                                                     																									count(*) records
12473                                                     														FROM                  gmf_lot_cost_burdens
12474                                                     														WHERE                 (item_uom IS NULL AND item_um IS NOT NULL)
12475                                                     														GROUP BY              item_um
12476                                                     														HAVING                count(*) > 0
12477                                                     														UNION
12478                                                     														SELECT                ''RESOURCE_UOM'' column_name,
12479                                                     																									''Resource UOM: ''|| Resource_um parameters,
12480                                                     																									count(*) records
12481                                                     														FROM                  gmf_lot_cost_burdens
12482                                                     														WHERE                 (resource_uom IS NULL AND resource_um IS NOT NULL)
12483                                                     														GROUP BY              resource_um
12484                                                     														HAVING                count(*) > 0
12485                                                                                 UNION
12486                                                                                 SELECT                ''LOT_NUMBER'' column_name,
12487                                                                                                       ''Lot Id: ''|| lot_id parameters,
12488                                                                                                       count(*) records
12489                                                                                 FROM                  gmf_lot_cost_burdens
12490                                                                                 WHERE                 (lot_number IS NULL AND lot_id IS NOT NULL)
12491                                                                                 GROUP BY              lot_id
12492                                                                                 HAVING                count(*) > 0
12493                                                     														) gmf_lot_cost_burdens';
12494 			l_gmf_lot_cost_adjustments      VARCHAR2(32000) := 'SELECT                ''GMF_LOT_COST_ADJUSTMENTS'' table_name,
12495                                                     														gmf_lot_cost_adjustments.*
12496                                                     			FROM                  (
12497                                                     														SELECT                ''ORGANIZATION_ID'' column_name,
12498                                                     																									''Warehouse Code: ''|| whse_code parameters,
12499                                                     																									count(*) records
12500                                                     														FROM                  gmf_lot_cost_adjustments
12501                                                     														WHERE                 (organization_id IS NULL AND whse_code IS NOT NULL)
12502                                                     														GROUP BY              whse_code
12503                                                     														HAVING                count(*) > 0
12504                                                     														UNION
12505                                                     														SELECT                ''INVENTORY_ITEM_ID'' column_name,
12506                                                     																									''Item No: ''|| b.item_no parameters,
12507                                                     																									count(*) records
12508                                                     														FROM                  gmf_lot_cost_adjustments a, ic_item_mst b
12509                                                     														WHERE                 (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
12510                                                     														AND                   b.item_id = a.item_id
12511                                                     														GROUP BY              b.item_no
12512                                                     														HAVING                count(*) > 0
12513                                                     														UNION
12514                                                     														SELECT                ''COST_TYPE_ID'' column_name,
12515                                                     																									''Cost Method Code: ''|| cost_mthd_code parameters,
12516                                                     																									count(*) records
12517                                                     														FROM                  gmf_lot_cost_adjustments
12518                                                     														WHERE                 (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
12519                                                     														GROUP BY              cost_mthd_code
12520                                                     														HAVING                count(*) > 0
12521                                                     														UNION
12522                                                     														SELECT                ''LEGAL_ENTITY_ID'' column_name,
12523                                                     																									''Co Code: ''|| co_code parameters,
12524                                                     																									count(*) records
12525                                                     														FROM                  gmf_lot_cost_adjustments
12526                                                     														WHERE                 (legal_entity_id IS NULL AND co_code IS NOT NULL)
12527                                                     														GROUP BY              co_code
12528                                                     														HAVING                count(*) > 0
12529                                                                                 UNION
12530                                                                                 SELECT                ''LOT_NUMBER'' column_name,
12531                                                                                                       ''Lot Id: ''|| lot_id parameters,
12532                                                                                                       count(*) records
12533                                                                                 FROM                  gmf_lot_cost_adjustments
12534                                                                                 WHERE                 (lot_number IS NULL AND lot_id IS NOT NULL)
12535                                                                                 GROUP BY              lot_id
12536                                                                                 HAVING                count(*) > 0
12537                                                     														) gmf_lot_cost_adjustments';
12538 			l_gmf_material_lot_cost_txns    VARCHAR2(32000) := 'SELECT                ''GMF_MATERIAL_LOT_COST_TXNS'' table_name,
12539                                                                                 gmf_material_lot_cost_txns.*
12540                                                           FROM                  (
12541                                                                                 SELECT                ''COST_TYPE_ID'' column_name,
12542                                                                                                       ''Cost Type Code: ''|| cost_type_code parameters,
12543                                                                                                       count(*) records
12544                                                                                 FROM                  gmf_material_lot_cost_txns
12545                                                                                 WHERE                 (cost_type_id IS NULL AND cost_type_code IS NOT NULL)
12546                                                                                 GROUP BY              cost_type_code
12547                                                                                 HAVING                count(*) > 0
12548                                                                                 UNION
12549                                                                                 SELECT                ''COST_TRANS_UOM'' column_name,
12550                                                                                                       ''Cost Trans UOM: ''|| cost_trans_uom parameters,
12551                                                                                                       count(*) records
12552                                                                                 FROM                  gmf_material_lot_cost_txns
12553                                                                                 WHERE                 (cost_trans_um IS NULL AND cost_trans_uom IS NOT NULL)
12554                                                                                 GROUP BY              cost_trans_uom
12555                                                                                 HAVING                count(*) > 0
12556                                                                                 ) gmf_material_lot_cost_txns';
12557 			l_cm_whse_src                   VARCHAR2(32000) := 'SELECT                ''CM_WHSE_SRC'' table_name,
12558                                                                                 cm_whse_src.*
12559                                                           FROM                  (
12560                                                                                 SELECT                ''SOURCE_ORGANIZATION_ID'' column_name,
12561                                                                                                       ''Warehouse Code: ''|| whse_code parameters,
12562                                                                                                       count(*) records
12563                                                                                 FROM                  cm_whse_src
12564                                                                                 WHERE                 (source_organization_id IS NULL AND whse_code IS NOT NULL)
12565                                                                                 GROUP BY              whse_code
12566                                                                                 HAVING                count(*) > 0
12567                                                                                 UNION
12568                                                                                 SELECT                ''ORGANIZATION_ID'' column_name,
12569                                                                                                       ''Orgn Code: ''|| orgn_code parameters,
12570                                                                                                       count(*) records
12571                                                                                 FROM                  cm_whse_src
12572                                                                                 WHERE                 (organization_id IS NULL AND orgn_code IS NOT NULL AND delete_mark = 0)
12573                                                                                 GROUP BY              orgn_code
12574                                                                                 HAVING                count(*) > 0
12575                                                                                 UNION
12576                                                                                 SELECT                ''MASTER_ORGANIZATION_ID'' column_name,
12577                                                                                                       ''Item No: ''|| b.item_no ||'' Legal Entity: ''||a.legal_entity_id parameters,
12578                                                                                                       count(*) records
12579                                                                                 FROM                  cm_whse_src a, ic_item_mst b
12580                                                                                 WHERE                 (a.legal_entity_id IS NULL AND a.item_id IS NOT NULL)
12581                                                                                 AND                   b.item_id = a.item_id
12582                                                                                 GROUP BY              b.item_no, a.legal_entity_id
12583                                                                                 HAVING                count(*) > 0
12584                                                                                 UNION
12585                                                                                 SELECT                ''INVENTORY_ITEM_ID'' column_name,
12586                                                                                                       ''Item No: ''|| b.item_no parameters,
12587                                                                                                       count(*) records
12588                                                                                 FROM                  cm_whse_src a, ic_item_mst b
12589                                                                                 WHERE                 (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
12590                                                                                 AND                   b.item_id = a.item_id
12591                                                                                 GROUP BY              b.item_no
12592                                                                                 HAVING                count(*) > 0
12593                                                                                 UNION
12594                                                                                 SELECT                ''LEGAL_ENTITY_ID'' column_name,
12595                                                                                                       ''Orgn Code: ''|| orgn_code parameters,
12596                                                                                                       count(*) records
12597                                                                                 FROM                  cm_whse_src
12598                                                                                 WHERE                 (legal_entity_id IS NULL AND orgn_code IS NOT NULL)
12599                                                                                 GROUP BY              orgn_code
12600                                                                                 HAVING                count(*) > 0
12601                                                                                 ) cm_whse_src';
12602 			l_cm_acpr_ctl                   VARCHAR2(32000) := 'SELECT                ''CM_ACPR_CTL'' table_name,
12603                                                     														cm_acpr_ctl.*
12604                                                     			FROM                  (
12605                                                     														SELECT                ''COST_TYPE_ID'' column_name,
12606                                                     																									''Cost Method Code: ''|| cost_mthd_code parameters,
12607                                                     																									count(*) records
12608                                                     														FROM                  cm_acpr_ctl
12609                                                     														WHERE                 (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
12610                                                     														GROUP BY              cost_mthd_code
12611                                                     														HAVING                count(*) > 0
12612                                                     														UNION
12613                                                     														SELECT                ''PERIOD_ID'' column_name,
12614                                                     																									''Calendar Code: ''|| calendar_code ||'', Period Code: ''|| period_code parameters,
12615                                                     																									count(*) records
12616                                                     														FROM                  cm_acpr_ctl
12617                                                     														WHERE                 (period_id IS NULL AND calendar_code IS NOT NULL AND period_code IS NOT NULL)
12618                                                     														GROUP BY              calendar_code, period_code
12619                                                     														HAVING                count(*) > 0
12620                                                     														UNION
12621                                                     														SELECT                ''LEGAL_ENTITY_ID'' column_name,
12622                                                     																									''Calendar Code: ''|| calendar_code parameters,
12623                                                     																									count(*) records
12624                                                     														FROM                  cm_acpr_ctl
12625                                                     														WHERE                 (legal_entity_id IS NULL AND calendar_code IS NOT NULL)
12626                                                     														GROUP BY              calendar_code
12627                                                     														HAVING                count(*) > 0
12628                                                     														) cm_acpr_ctl';
12629 			l_cm_rlup_ctl                   VARCHAR2(32000) := 'SELECT                ''CM_RLUP_CTL'' table_name,
12630                                                     														cm_rlup_ctl.*
12631                                                     			FROM                  (
12632                                                     														SELECT                ''COST_TYPE_ID'' column_name,
12633                                                     																									''Cost Method Code: ''|| cost_mthd_code parameters,
12634                                                     																									count(*) records
12635                                                     														FROM                  cm_rlup_ctl
12636                                                     														WHERE                 (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
12637                                                     														GROUP BY              cost_mthd_code
12638                                                     														HAVING                count(*) > 0
12639                                                     														UNION
12640                                                     														SELECT                ''PERIOD_ID'' column_name,
12641                                                     																									''Calendar Code: ''|| calendar_code ||'', Period Code: ''|| period_code parameters,
12642                                                     																									count(*) records
12643                                                     														FROM                  cm_rlup_ctl
12644                                                     														WHERE                 (period_id IS NULL AND calendar_code IS NOT NULL AND period_code IS NOT NULL)
12645                                                     														GROUP BY              calendar_code, period_code
12646                                                     														HAVING                count(*) > 0
12647                                                     														UNION
12648                                                     														SELECT                ''LEGAL_ENTITY_ID'' column_name,
12649                                                     																									''Calendar Code: ''|| calendar_code parameters,
12650                                                     																									count(*) records
12651                                                     														FROM                  cm_rlup_ctl
12652                                                     														WHERE                 (legal_entity_id IS NULL AND calendar_code IS NOT NULL)
12653                                                     														GROUP BY              calendar_code
12654                                                     														HAVING                count(*) > 0
12655                                                     														UNION
12656                                                     														SELECT                ''MASTER_ORGANIZATION_ID'' column_name,
12657                                                     																									''Item No: ''|| b.item_no ||'' Legal Entity: ''||a.legal_entity_id parameters,
12658                                                     																									count(*) records
12659                                                     														FROM                  cm_rlup_ctl a, ic_item_mst b
12660                                                     														WHERE                 (a.legal_entity_id IS NULL AND a.item_id IS NOT NULL)
12661                                                     														AND                   b.item_id = a.item_id
12662                                                     														GROUP BY              b.item_no, a.legal_entity_id
12663                                                     														HAVING                count(*) > 0
12664                                                     														UNION
12665                                                     														SELECT                ''INVENTORY_ITEM_ID'' column_name,
12666                                                     																									''Item No: ''|| b.item_no parameters,
12667                                                     																									count(*) records
12668                                                     														FROM                  cm_rlup_ctl a, ic_item_mst b
12669                                                     														WHERE                 (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
12670                                                     														AND                   b.item_id = a.item_id
12671                                                     														GROUP BY              b.item_no
12672                                                     														HAVING                count(*) > 0
12673                                                     														) cm_rlup_ctl';
12674 			l_cm_rlup_itm                   VARCHAR2(32000) := 'SELECT                ''CM_RLUP_ITM'' table_name,
12675                                                     														cm_rlup_itm.*
12676                                                     			FROM                  (
12677                                                     														SELECT                ''ORGANIZATION_ID'' column_name,
12678                                                     																									''Item No: ''|| b.item_no ||'' Legal Entity: ''||c.legal_entity_id parameters,
12679                                                     																									count(*) records
12680                                                     														FROM                  cm_rlup_ctl a, ic_item_mst b, cm_rlup_ctl c
12681                                                     														WHERE                 (a.legal_entity_id IS NULL AND a.item_id IS NOT NULL)
12682                                                     														AND                   b.item_id = a.item_id
12683                                                     														AND                   c.rollup_id = a.rollup_id
12684                                                     														GROUP BY              b.item_no, c.legal_entity_id
12685                                                     														HAVING                count(*) > 0
12686                                                     														UNION
12687                                                     														SELECT                ''INVENTORY_ITEM_ID'' column_name,
12688                                                     																									''Item No: ''|| b.item_no parameters,
12689                                                     																									count(*) records
12690                                                     														FROM                  cm_rlup_itm a, ic_item_mst b
12691                                                     														WHERE                 (a.inventory_item_id IS NULL AND a.item_id IS NOT NULL)
12692                                                     														AND                   b.item_id = a.item_id
12693                                                     														GROUP BY              b.item_no
12694                                                     														HAVING                count(*) > 0
12695                                                     														) cm_rlup_itm';
12696       l_cm_cupd_ctl                   VARCHAR2(32000) := 'SELECT                ''CM_CUPD_CTL'' table_name,
12697                                                                                 cm_cupd_ctl.*
12698                                                           FROM                  (
12699                                                                                 SELECT                ''COST_TYPE_ID'' column_name,
12700                                                                                                       ''Cost Method Code: ''|| cost_mthd_code parameters,
12701                                                                                                       count(*) records
12702                                                                                 FROM                  cm_cupd_ctl
12703                                                                                 WHERE                 (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
12704                                                                                 GROUP BY              cost_mthd_code
12705                                                                                 HAVING                count(*) > 0
12706                                                                                 UNION
12707                                                                                 SELECT                ''PERIOD_ID'' column_name,
12708                                                                                                       ''Calendar Code: ''|| calendar_code ||'', Period Code: ''|| period_code parameters,
12709                                                                                                       count(*) records
12710                                                                                 FROM                  cm_cupd_ctl
12711                                                                                 WHERE                 (period_id IS NULL AND calendar_code IS NOT NULL AND period_code IS NOT NULL)
12712                                                                                 GROUP BY              calendar_code, period_code
12713                                                                                 HAVING                count(*) > 0
12714                                                                                 UNION
12715                                                                                 SELECT                ''LEGAL_ENTITY_ID'' column_name,
12716                                                                                                       ''Calendar Code: ''|| calendar_code parameters,
12717                                                                                                       count(*) records
12718                                                                                 FROM                  cm_cupd_ctl
12719                                                                                 WHERE                 (legal_entity_id IS NULL AND calendar_code IS NOT NULL)
12720                                                                                 GROUP BY              calendar_code
12721                                                                                 HAVING                count(*) > 0
12722                                                                                 ) cm_cupd_ctl';
12723       l_gl_subr_sta                   VARCHAR2(32000) := 'SELECT                ''GL_SUBR_STA'' table_name,
12724                                                     														gl_subr_sta.*
12725                                                     			FROM                  (
12726                                                     														SELECT                ''CREV_CURR_COST_TYPE_ID'' column_name,
12727                                                     																									''Current Cost Method Code: ''|| crev_curr_mthd parameters,
12728                                                     																									count(*) records
12729                                                     														FROM                  gl_subr_sta
12730                                                     														WHERE                 (crev_curr_cost_type_id IS NULL AND crev_curr_mthd IS NOT NULL)
12731                                                     														GROUP BY              crev_curr_mthd
12732                                                     														HAVING                count(*) > 0
12733                                                     														UNION
12734                                                     														SELECT                ''CREV_CURR_PERIOD_ID'' column_name,
12735                                                     																									''Current Calendar Code: ''|| crev_curr_calendar ||'', Period Code: ''|| crev_curr_period parameters,
12736                                                     																									count(*) records
12737                                                     														FROM                  gl_subr_sta
12738                                                     														WHERE                 (crev_curr_calendar is not null and crev_curr_period is not NULL AND crev_curr_period_id is null)
12739                                                     														GROUP BY              crev_curr_calendar, crev_curr_period
12740                                                     														HAVING                count(*) > 0
12741                                                     														UNION
12742                                                     														SELECT                ''CREV_PREV_COST_TYPE_ID'' column_name,
12743                                                     																									''Previous Cost Method Code: ''|| crev_prev_mthd parameters,
12744                                                     																									count(*) records
12745                                                     														FROM                  gl_subr_sta
12746                                                     														WHERE                 (crev_prev_cost_type_id IS NULL AND crev_prev_mthd IS NOT NULL)
12747                                                     														GROUP BY              crev_prev_mthd
12748                                                     														HAVING                count(*) > 0
12749                                                     														UNION
12750                                                     														SELECT                ''CREV_PREV_PERIOD_ID'' column_name,
12751                                                     																									''Previous Calendar Code: ''|| crev_prev_calendar ||'', Period Code: ''|| crev_prev_period parameters,
12752                                                     																									count(*) records
12753                                                     														FROM                  gl_subr_sta
12754                                                     														WHERE                 (crev_prev_calendar is not null and crev_prev_period is not NULL AND crev_prev_period_id is null)
12755                                                     														GROUP BY              crev_prev_calendar, crev_prev_period
12756                                                     														HAVING                count(*) > 0
12757                                                     														UNION
12758                                                     														SELECT                ''LEGAL_ENTITY_ID'' column_name,
12759                                                     																									''Co Code: ''|| co_code parameters,
12760                                                     																									count(*) records
12761                                                     														FROM                  gl_subr_sta
12762                                                     														WHERE                 (legal_entity_id IS NULL AND co_code IS NOT NULL)
12763                                                     														GROUP BY              co_code
12764                                                     														HAVING                count(*) > 0
12765                                                     														UNION
12766                                                     														SELECT                ''COST_TYPE_ID'' column_name,
12767                                                     																									''Co Code: ''|| co_code parameters,
12768                                                     																									count(*) records
12769                                                     														FROM                  gl_subr_sta
12770                                                     														WHERE                 (cost_type_id IS NULL AND co_code IS NOT NULL)
12771                                                     														GROUP BY              co_code
12772                                                     														HAVING                count(*) > 0
12773                                                     														) gl_subr_sta';
12774 			l_xla_rules_t                   VARCHAR2(32000) := 'SELECT                ''XLA_RULES_T'' table_name,
12775                                                     														xla_rules_t.*
12776                                                     			FROM                  (
12777                                                     														SELECT                ''ALL'' column_name,
12778                                                     																									''Unique Constraint Error'' parameters,
12779                                                     																									count(*) records
12780                                                     														FROM                  xla_rules_t
12781                                                     														WHERE                 error_value = -1
12782                                                     														HAVING                count(*) > 0
12783                                                     														UNION
12784                                                     														SELECT                ''ALL'' column_name,
12785                                                     																									''Not Null Constraint'' parameters,
12786                                                     																									count(*) records
12787                                                     														FROM                  xla_rules_t
12788                                                     														WHERE                 error_value = -1400
12789                                                     														HAVING                count(*) > 0
12790                                                     														UNION
12791                                                     														SELECT                ''ALL'' column_name,
12792                                                     																									''Invalid Value Error'' parameters,
12793                                                     																									count(*) records
12794                                                     														FROM                  xla_rules_t
12795                                                     														WHERE                 error_value = -6502
12796                                                     														HAVING                count(*) > 0
12797                                                     														UNION
12798                                                     														SELECT                ''ALL'' column_name,
12799                                                     																									''Parent-Key Not Found Error'' parameters,
12800                                                     																									count(*) records
12801                                                     														FROM                  xla_rules_t
12802                                                     														WHERE                 error_value = -2291
12803                                                     														HAVING                count(*) > 0
12804                                                     														UNION
12805                                                     														SELECT                ''ALL'' column_name,
12806                                                     																									''Value Too Long Error'' parameters,
12807                                                     																									count(*) records
12808                                                     														FROM                  xla_rules_t
12809                                                     														WHERE                 error_value in (-1438, -12899)
12810                                                     														HAVING                count(*) > 0
12811                                                     														UNION
12812                                                     														SELECT                ''ALL'' column_name,
12813                                                     																									''Invalid Number Error'' parameters,
12814                                                     																									count(*) records
12815                                                     														FROM                  xla_rules_t
12816                                                     														WHERE                 error_value = -1722
12817                                                     														HAVING                count(*) > 0
12818                                                     														UNION
12819                                                     														SELECT                ''ALL'' column_name,
12820                                                     																									''Records not Picked up'' parameters,
12821                                                     																									count(*) records
12822                                                     														FROM                  xla_rules_t
12823                                                     														WHERE                 error_value = 0
12824                                                     														HAVING                count(*) > 0
12825                                                     														UNION
12826                                                     														SELECT                ''ALL'' column_name,
12827                                                     																									''Other Errors'' parameters,
12828                                                     																									count(*) records
12829                                                     														FROM                  xla_rules_t
12830                                                     														WHERE                 error_value not in (-1, -1400, -6502, -2291, -1438, -12899, -1722, 1, 0)
12831                                                     														HAVING                count(*) > 0
12832                                                     														) xla_rules_t';
12833 			l_xla_rule_details_t            VARCHAR2(32000) := 'SELECT                ''XLA_RULE_DETAILS_T'' table_name,
12834                                                     														xla_rule_details_t.*
12835                                                     			FROM                  (
12836                                                     														SELECT                ''ALL'' column_name,
12837                                                     																									''Unique Constraint Error'' parameters,
12838                                                     																									count(*) records
12839                                                     														FROM                  xla_rule_details_t
12840                                                     														WHERE                 error_value = -1
12841                                                     														HAVING                count(*) > 0
12842                                                     														UNION
12843                                                     														SELECT                ''ALL'' column_name,
12844                                                     																									''Not Null Constraint'' parameters,
12845                                                     																									count(*) records
12846                                                     														FROM                  xla_rule_details_t
12847                                                     														WHERE                 error_value = -1400
12848                                                     														HAVING                count(*) > 0
12849                                                     														UNION
12850                                                     														SELECT                ''ALL'' column_name,
12851                                                     																									''Invalid Value Error'' parameters,
12852                                                     																									count(*) records
12853                                                     														FROM                  xla_rule_details_t
12854                                                     														WHERE                 error_value = -6502
12855                                                     														HAVING                count(*) > 0
12856                                                     														UNION
12857                                                     														SELECT                ''ALL'' column_name,
12858                                                     																									''Parent-Key Not Found Error'' parameters,
12859                                                     																									count(*) records
12860                                                     														FROM                  xla_rule_details_t
12861                                                     														WHERE                 error_value = -2291
12862                                                     														HAVING                count(*) > 0
12863                                                     														UNION
12864                                                     														SELECT                ''ALL'' column_name,
12865                                                     																									''Value Too Long Error'' parameters,
12866                                                     																									count(*) records
12867                                                     														FROM                  xla_rule_details_t
12868                                                     														WHERE                 error_value in (-1438, -12899)
12869                                                     														HAVING                count(*) > 0
12870                                                     														UNION
12871                                                     														SELECT                ''ALL'' column_name,
12872                                                     																									''Invalid Number Error'' parameters,
12873                                                     																									count(*) records
12874                                                     														FROM                  xla_rule_details_t
12875                                                     														WHERE                 error_value = -1722
12876                                                     														HAVING                count(*) > 0
12877                                                     														UNION
12878                                                     														SELECT                ''ALL'' column_name,
12879                                                     																									''Records not Picked up'' parameters,
12880                                                     																									count(*) records
12881                                                     														FROM                  xla_rule_details_t
12882                                                     														WHERE                 error_value = 0
12883                                                     														HAVING                count(*) > 0
12884                                                     														UNION
12885                                                     														SELECT                ''ALL'' column_name,
12886                                                     																									''Other Errors'' parameters,
12887                                                     																									count(*) records
12888                                                     														FROM                  xla_rule_details_t
12889                                                     														WHERE                 error_value not in (-1, -1400, -6502, -2291, -1438, -12899, -1722, 1, 0)
12890                                                     														HAVING                count(*) > 0
12891                                                     														) xla_rule_details_t';
12892 			l_xla_conditions_t              VARCHAR2(32000) := 'SELECT                ''XLA_CONDITIONS_T'' table_name,
12893                                                     														xla_conditions_t.*
12894                                                     			FROM                  (
12895                                                     														SELECT                ''ALL'' column_name,
12896                                                     																									''Unique Constraint Error'' parameters,
12897                                                     																									count(*) records
12898                                                     														FROM                  xla_conditions_t
12899                                                     														WHERE                 error_value = -1
12900                                                     														HAVING                count(*) > 0
12901                                                     														UNION
12902                                                     														SELECT                ''ALL'' column_name,
12903                                                     																									''Not Null Constraint'' parameters,
12904                                                     																									count(*) records
12905                                                     														FROM                  xla_conditions_t
12906                                                     														WHERE                 error_value = -1400
12907                                                     														HAVING                count(*) > 0
12908                                                     														UNION
12909                                                     														SELECT                ''ALL'' column_name,
12910                                                     																									''Invalid Value Error'' parameters,
12911                                                     																									count(*) records
12912                                                     														FROM                  xla_conditions_t
12913                                                     														WHERE                 error_value = -6502
12914                                                     														HAVING                count(*) > 0
12915                                                     														UNION
12916                                                     														SELECT                ''ALL'' column_name,
12917                                                     																									''Parent-Key Not Found Error'' parameters,
12918                                                     																									count(*) records
12919                                                     														FROM                  xla_conditions_t
12920                                                     														WHERE                 error_value = -2291
12921                                                     														HAVING                count(*) > 0
12922                                                     														UNION
12923                                                     														SELECT                ''ALL'' column_name,
12924                                                     																									''Value Too Long Error'' parameters,
12925                                                     																									count(*) records
12926                                                     														FROM                  xla_conditions_t
12927                                                     														WHERE                 error_value in (-1438, -12899)
12928                                                     														HAVING                count(*) > 0
12929                                                     														UNION
12930                                                     														SELECT                ''ALL'' column_name,
12931                                                     																									''Invalid Number Error'' parameters,
12932                                                     																									count(*) records
12933                                                     														FROM                  xla_conditions_t
12934                                                     														WHERE                 error_value = -1722
12935                                                     														HAVING                count(*) > 0
12936                                                     														UNION
12937                                                     														SELECT                ''ALL'' column_name,
12938                                                     																									''Records not Picked up'' parameters,
12939                                                     																									count(*) records
12940                                                     														FROM                  xla_conditions_t
12941                                                     														WHERE                 error_value = 0
12942                                                     														HAVING                count(*) > 0
12943                                                     														UNION
12944                                                     														SELECT                ''ALL'' column_name,
12945                                                     																									''Other Errors'' parameters,
12946                                                     																									count(*) records
12947                                                     														FROM                  xla_conditions_t
12948                                                     														WHERE                 error_value not in (-1, -1400, -6502, -2291, -1438, -12899, -1722, 1, 0)
12949                                                     														HAVING                count(*) > 0
12950                                                     														) xla_conditions_t';
12951 			l_xla_line_assgns_t             VARCHAR2(32000) := 'SELECT                ''XLA_LINE_ASSGNS_T'' table_name,
12952                                                       														xla_line_assgns_t.*
12953                                                           FROM                  (
12954                                                                                 SELECT                ''ALL'' column_name,
12955                                                                                                       ''Unique Constraint Error'' parameters,
12956                                                                                                       count(*) records
12957                                                                                 FROM                  xla_line_assgns_t
12958                                                                                 WHERE                 error_value = -1
12959                                                                                 HAVING                count(*) > 0
12960                                                                                 UNION
12961                                                                                 SELECT                ''ALL'' column_name,
12962                                                                                                       ''Not Null Constraint'' parameters,
12963                                                                                                       count(*) records
12964                                                                                 FROM                  xla_line_assgns_t
12965                                                                                 WHERE                 error_value = -1400
12966                                                                                 HAVING                count(*) > 0
12967                                                                                 UNION
12968                                                                                 SELECT                ''ALL'' column_name,
12969                                                                                                       ''Invalid Value Error'' parameters,
12970                                                                                                       count(*) records
12971                                                                                 FROM                  xla_line_assgns_t
12972                                                                                 WHERE                 error_value = -6502
12973                                                                                 HAVING                count(*) > 0
12974                                                                                 UNION
12975                                                                                 SELECT                ''ALL'' column_name,
12976                                                                                                       ''Parent-Key Not Found Error'' parameters,
12977                                                                                                       count(*) records
12978                                                                                 FROM                  xla_line_assgns_t
12979                                                                                 WHERE                 error_value = -2291
12980                                                                                 HAVING                count(*) > 0
12981                                                                                 UNION
12982                                                                                 SELECT                ''ALL'' column_name,
12983                                                                                                       ''Value Too Long Error'' parameters,
12984                                                                                                       count(*) records
12985                                                                                 FROM                  xla_line_assgns_t
12986                                                                                 WHERE                 error_value in (-1438, -12899)
12987                                                                                 HAVING                count(*) > 0
12988                                                                                 UNION
12989                                                                                 SELECT                ''ALL'' column_name,
12990                                                                                                       ''Invalid Number Error'' parameters,
12991                                                                                                       count(*) records
12992                                                                                 FROM                  xla_line_assgns_t
12993                                                                                 WHERE                 error_value = -1722
12994                                                                                 HAVING                count(*) > 0
12995                                                                                 UNION
12996                                                                                 SELECT                ''ALL'' column_name,
12997                                                                                                       ''Records not Picked up'' parameters,
12998                                                                                                       count(*) records
12999                                                                                 FROM                  xla_line_assgns_t
13000                                                                                 WHERE                 error_value = 0
13001                                                                                 HAVING                count(*) > 0
13002                                                                                 UNION
13003                                                                                 SELECT                ''ALL'' column_name,
13004                                                                                                       ''Other Errors'' parameters,
13005                                                                                                       count(*) records
13006                                                                                 FROM                  xla_line_assgns_t
13007                                                                                 WHERE                 error_value not in (-1, -1400, -6502, -2291, -1438, -12899, -1722, 1, 0)
13008                                                                                 HAVING                count(*) > 0
13009                                                                                 ) xla_line_assgns_t';
13010 
13011     /*****************
13012     * PL/SQL Cursors *
13013     *****************/
13014     cur_gmf_log_errors              p_cur_gmf_log_errors;
13015 
13016 	BEGIN
13017 		/*****************************************************************************
13018 		* ROWID's are required only when called from inside a LTU Migration Loop and *
13019 		* it cannot be passed for a Detailed Error Log                               *
13020 		*****************************************************************************/
13021 		IF p_from_rowid IS NOT NULL AND p_to_rowid IS NOT NULL THEN
13022 			IF p_log_level <> 1 THEN
13023 				RETURN;
13024 			ELSE
13025 				l_sql_statement := l_sql_statement||' ROWID BETWEEN :1 AND :2 AND ';
13026 			END IF;
13027 		END IF;
13028 		/**************************************************************************
13029 		* Printing Error Log's for all tables cannot be done in Log Level 1 and 2 *
13030 		**************************************************************************/
13031 		IF l_table_name = 'GMF_LOG_ERRORS' AND p_log_level IN (1, 2) THEN
13032 			RETURN;
13033 		END IF;
13034 		IF p_log_level IN (1, 2) THEN
13035 			/************************************************
13036 			* Migration Error Logging for table CM_RSRC_DTL *
13037 			************************************************/
13038 			IF l_table_name IN ('CM_RSRC_DTL') THEN
13039 				IF p_log_level = 1 THEN
13040 					l_sql_statement :=  l_sql_statement
13041 															||
13042 															'(                (legal_entity_id IS NULL AND orgn_code IS NOT NULL)
13043 															OR                (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
13044 															OR                (period_id IS NULL AND period_code IS NOT NULL AND calendar_code is not null)
13045 															OR                (usage_uom IS NULL AND usage_um IS NOT NULL)
13046 															OR                (organization_id IS NULL AND delete_mark = 0 AND orgn_code IS NOT NULL)
13047 															)';
13048 					IF p_from_rowid IS NOT NULL AND p_to_rowid IS NOT NULL THEN
13049 						execute IMMEDIATE l_sql_statement INTO l_failure_count using p_from_rowid, p_to_rowid;
13050 					ELSE
13051 						execute IMMEDIATE l_sql_statement INTO l_failure_count;
13052 					END IF;
13053 				ELSIF p_log_level = 2 THEN
13054 					SELECT        SUM(CASE WHEN (legal_entity_id IS NULL AND orgn_code IS NOT NULL) THEN 1 ELSE 0 END),
13055 												SUM(CASE WHEN (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL) THEN 1 ELSE 0 END),
13056 												SUM(CASE WHEN (period_id IS NULL AND period_code IS NOT NULL AND calendar_code IS NOT NULL) THEN 1 ELSE 0 END),
13057 												SUM(CASE WHEN (usage_uom IS NULL AND usage_um IS NOT NULL) THEN 1 ELSE 0 END),
13058 												SUM(CASE WHEN (organization_id IS NULL AND delete_mark = 0 AND orgn_code IS NOT NULL) THEN 1 ELSE 0 END)
13059 					INTO          l_legal_entity_count,
13060 												l_cost_type_count,
13061 												l_period_count,
13062 												l_uom_count1,
13063 												l_organization_count
13064 					FROM          cm_rsrc_dtl;
13065 				END IF;
13066 			END IF;
13067 			/************************************************
13068 			* Migration Error Logging for table CM_ADJS_DTL *
13069 			************************************************/
13070 			IF l_table_name IN ('CM_ADJS_DTL') THEN
13071 				IF p_log_level = 1 THEN
13072 					l_sql_statement :=  l_sql_statement
13073 															||
13074 															'(                (organization_id IS NULL AND whse_code IS NOT NULL)
13075 															OR                (inventory_item_id IS NULL AND item_id IS NOT NULL)
13076 															OR                (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
13077 															OR                (period_id IS NULL AND period_code IS NOT NULL AND calendar_code IS NOT NULL)
13078 															OR                (adjust_qty_uom IS NULL AND adjust_qty_um IS NOT NULL)
13079 															OR                (adjustment_ind IS NULL)
13080 															)';
13081 					IF p_from_rowid IS NOT NULL AND p_to_rowid IS NOT NULL THEN
13082 						execute IMMEDIATE l_sql_statement INTO l_failure_count using p_from_rowid, p_to_rowid;
13083 					ELSE
13084 						execute IMMEDIATE l_sql_statement INTO l_failure_count;
13085 					END IF;
13086 				ELSIF p_log_level = 2 THEN
13087 					SELECT        SUM(CASE WHEN (organization_id IS NULL AND whse_code IS NOT NULL) THEN 1 ELSE 0 END),
13088 												SUM(CASE WHEN (inventory_item_id IS NULL AND item_id IS NOT NULL) THEN 1 ELSE 0 END),
13089 												SUM(CASE WHEN (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL) THEN 1 ELSE 0 END),
13090 												SUM(CASE WHEN (period_id IS NULL AND period_code IS NOT NULL AND calendar_code IS NOT NULL) THEN 1 ELSE 0 END),
13091 												SUM(CASE WHEN (adjust_qty_uom IS NULL AND adjust_qty_um IS NOT NULL) THEN 1 ELSE 0 END),
13092 												SUM(CASE WHEN (adjustment_ind IS NULL) THEN 1 ELSE 0 END)
13093 					INTO          l_organization_count,
13094 												l_inventory_item_count,
13095 												l_cost_type_count,
13096 												l_period_count,
13097 												l_uom_count1,
13098 												l_adjustment_ind_count
13099 					FROM          cm_adjs_dtl;
13100 				END IF;
13101 			END IF;
13102 			/************************************************
13103 			* Migration Error Logging for table CM_CMPT_DTL *
13104 			************************************************/
13105 			IF l_table_name IN ('CM_CMPT_DTL') THEN
13106 				IF p_log_level = 1 THEN
13107 					l_sql_statement :=  l_sql_statement
13108 															||
13109 															'(                (organization_id IS NULL AND whse_code IS NOT NULL)
13110 															OR                (inventory_item_id IS NULL AND item_id IS NOT NULL)
13111 															OR                (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
13112 															OR                (period_id IS NULL AND period_code IS NOT NULL)
13113 															)';
13114 					IF p_from_rowid IS NOT NULL AND p_to_rowid IS NOT NULL THEN
13115 						execute IMMEDIATE l_sql_statement INTO l_failure_count using p_from_rowid, p_to_rowid;
13116 					ELSE
13117 						execute IMMEDIATE l_sql_statement INTO l_failure_count;
13118 					END IF;
13119 				ELSIF p_log_level = 2 THEN
13120 					SELECT        SUM(CASE WHEN (organization_id IS NULL AND whse_code IS NOT NULL) THEN 1 ELSE 0 END),
13121 												SUM(CASE WHEN (inventory_item_id IS NULL AND item_id IS NOT NULL) THEN 1 ELSE 0 END),
13122 												SUM(CASE WHEN (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL) THEN 1 ELSE 0 END),
13123 												SUM(CASE WHEN (period_id IS NULL AND period_code IS NOT NULL AND calendar_code IS NOT NULL) THEN 1 ELSE 0 END)
13124 					INTO          l_organization_count,
13125 												l_inventory_item_count,
13126 												l_cost_type_count,
13127 												l_period_count
13128 					FROM          cm_cmpt_dtl;
13129 				END IF;
13130 			END IF;
13131 			/************************************************
13132 			* Migration Error Logging for table CM_BRDN_DTL *
13133 			************************************************/
13134 			IF l_table_name IN ('CM_BRDN_DTL') THEN
13135 				IF p_log_level = 1 THEN
13136 					l_sql_statement :=  l_sql_statement
13137 															||
13138 															'(                (organization_id IS NULL AND whse_code IS NOT NULL)
13139 															OR                (inventory_item_id IS NULL AND item_id IS NOT NULL)
13140 															OR                (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
13141 															OR                (period_id IS NULL AND period_code IS NOT NULL)
13142 															OR                (item_uom IS NULL AND item_um IS NOT NULL)
13143 															OR                (burden_uom IS NULL AND burden_um IS NOT NULL)
13144 															)';
13145 					IF p_from_rowid IS NOT NULL AND p_to_rowid IS NOT NULL THEN
13146 						execute IMMEDIATE l_sql_statement INTO l_failure_count using p_from_rowid, p_to_rowid;
13147 					ELSE
13148 						execute IMMEDIATE l_sql_statement INTO l_failure_count;
13149 					END IF;
13150 				ELSIF p_log_level = 2 THEN
13151 					SELECT        SUM(CASE WHEN (organization_id IS NULL AND whse_code IS NOT NULL) THEN 1 ELSE 0 END),
13152 												SUM(CASE WHEN (inventory_item_id IS NULL AND item_id IS NOT NULL) THEN 1 ELSE 0 END),
13153 												SUM(CASE WHEN (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL) THEN 1 ELSE 0 END),
13154 												SUM(CASE WHEN (period_id IS NULL AND period_code IS NOT NULL AND calendar_code IS NOT NULL) THEN 1 ELSE 0 END),
13155 												SUM(CASE WHEN (item_uom IS NULL AND item_um IS NOT NULL) THEN 1 ELSE 0 END),
13156 												SUM(CASE WHEN (burden_uom IS NULL AND burden_um IS NOT NULL) THEN 1 ELSE 0 END)
13157 					INTO          l_organization_count,
13158 												l_inventory_item_count,
13159 												l_cost_type_count,
13160 												l_period_count,
13161 												l_uom_count1,
13162 												l_uom_count2
13163 					FROM          cm_brdn_dtl;
13164 				END IF;
13165 			END IF;
13166 			/************************************************
13167 			* Migration Error Logging for table GL_ITEM_CST *
13168 			************************************************/
13169 			IF l_table_name IN ('GL_ITEM_CST') THEN
13170 				IF p_log_level = 1 THEN
13171 					l_sql_statement :=  l_sql_statement
13172 															||
13173 															'(                (organization_id IS NULL AND whse_code IS NOT NULL)
13174 															OR                (inventory_item_id IS NULL AND item_id IS NOT NULL)
13175 															OR                (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
13176 															OR                (period_id IS NULL AND period_code IS NOT NULL)
13177 															)';
13178 					IF p_from_rowid IS NOT NULL AND p_to_rowid IS NOT NULL THEN
13179 						execute IMMEDIATE l_sql_statement INTO l_failure_count using p_from_rowid, p_to_rowid;
13180 					ELSE
13181 						execute IMMEDIATE l_sql_statement INTO l_failure_count;
13182 					END IF;
13183 				ELSIF p_log_level = 2 THEN
13184 					SELECT        SUM(CASE WHEN (organization_id IS NULL AND whse_code IS NOT NULL) THEN 1 ELSE 0 END),
13185 												SUM(CASE WHEN (inventory_item_id IS NULL AND item_id IS NOT NULL) THEN 1 ELSE 0 END),
13186 												SUM(CASE WHEN (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL) THEN 1 ELSE 0 END),
13187 												SUM(CASE WHEN (period_id IS NULL AND period_code IS NOT NULL AND calendar_code IS NOT NULL) THEN 1 ELSE 0 END)
13188 					INTO          l_organization_count,
13189 												l_inventory_item_count,
13190 												l_cost_type_count,
13191 												l_period_count
13192 					FROM          gl_item_cst;
13193 				END IF;
13194 			END IF;
13195 			/************************************************
13196 			* Migration Error Logging for table CM_SCST_LED *
13197 			************************************************/
13198 			IF l_table_name IN ('CM_SCST_LED') THEN
13199 				IF p_log_level = 1 THEN
13200 					l_sql_statement :=  l_sql_statement
13201 															||
13202 															'(                (organization_id IS NULL AND whse_code IS NOT NULL)
13203 															OR                (inventory_item_id IS NULL AND item_id IS NOT NULL)
13204 															OR                (form_prod_uom IS NULL AND form_prod_um IS NOT NULL)
13205 															OR                (item_fmqty_uom IS NULL AND item_fmqty_um IS NOT NULL)
13206 															OR                (usage_uom IS NULL AND usage_um IS NOT NULL)
13207 															)';
13208 					IF p_from_rowid IS NOT NULL AND p_to_rowid IS NOT NULL THEN
13209 						execute IMMEDIATE l_sql_statement INTO l_failure_count using p_from_rowid, p_to_rowid;
13210 					ELSE
13211 						execute IMMEDIATE l_sql_statement INTO l_failure_count;
13212 					END IF;
13213 				ELSIF p_log_level = 2 THEN
13214 					SELECT        SUM(CASE WHEN (organization_id IS NULL AND whse_code IS NOT NULL) THEN 1 ELSE 0 END),
13215 												SUM(CASE WHEN (inventory_item_id IS NULL AND item_id IS NOT NULL) THEN 1 ELSE 0 END),
13216 												SUM(CASE WHEN (form_prod_uom IS NULL AND form_prod_um IS NOT NULL) THEN 1 ELSE 0 END),
13217 												SUM(CASE WHEN (item_fmqty_uom IS NULL AND item_fmqty_um IS NOT NULL) THEN 1 ELSE 0 END),
13218 												SUM(CASE WHEN (usage_uom IS NULL AND usage_um IS NOT NULL) THEN 1 ELSE 0 END)
13219 					INTO          l_organization_count,
13220 												l_inventory_item_count,
13221 												l_uom_count1,
13222 												l_uom_count2,
13223 												l_uom_count3
13224 					FROM          cm_scst_led;
13225 				END IF;
13226 			END IF;
13227 			/************************************************
13228 			* Migration Error Logging for table CM_ACST_LED *
13229 			************************************************/
13230 			IF l_table_name IN ('CM_ACST_LED') THEN
13231 				IF p_log_level = 1 THEN
13232 					l_sql_statement :=  l_sql_statement
13233 															||
13234 															'(                (organization_id IS NULL AND whse_code IS NOT NULL)
13235 															OR                (inventory_item_id IS NULL AND item_id IS NOT NULL)
13236 															OR                (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
13237 															OR                (period_id IS NULL AND period_code IS NOT NULL)
13238 															)';
13239 					IF p_from_rowid IS NOT NULL AND p_to_rowid IS NOT NULL THEN
13240 						execute IMMEDIATE l_sql_statement INTO l_failure_count using p_from_rowid, p_to_rowid;
13241 					ELSE
13242 						execute IMMEDIATE l_sql_statement INTO l_failure_count;
13243 					END IF;
13244 				ELSIF p_log_level = 2 THEN
13245 					SELECT        SUM(CASE WHEN (organization_id IS NULL AND whse_code IS NOT NULL) THEN 1 ELSE 0 END),
13246 												SUM(CASE WHEN (inventory_item_id IS NULL AND item_id IS NOT NULL) THEN 1 ELSE 0 END),
13247 												SUM(CASE WHEN (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL) THEN 1 ELSE 0 END),
13248 												SUM(CASE WHEN (period_id IS NULL AND period_code IS NOT NULL AND calendar_code IS NOT NULL) THEN 1 ELSE 0 END)
13249 					INTO          l_organization_count,
13250 												l_inventory_item_count,
13251 												l_cost_type_count,
13252 												l_period_count
13253 					FROM          cm_acst_led;
13254 				END IF;
13255 			END IF;
13256 			/************************************************
13257 			* Migration Error Logging for table XLA_RULES_T *
13258 			************************************************/
13259 			IF l_table_name IN ('XLA_RULES_T') THEN
13260 				IF p_log_level = 1 THEN
13261 					l_sql_statement :=  l_sql_statement || ' ERROR_VALUE <> 1 ';
13262 					execute IMMEDIATE l_sql_statement INTO l_failure_count;
13263 				ELSIF p_log_level = 2 THEN
13264 					SELECT        SUM(DECODE(error_value, -1, 1, 0)),
13265 												SUM(DECODE(error_value, -1400, 1, 0)),
13266 												SUM(DECODE(error_value, -6502, 1, 0)),
13267 												SUM(DECODE(error_value, -2291, 1, 0)),
13268 												SUM(DECODE(error_value, -1438, 1, -12899, 1, 0)),
13269 												SUM(DECODE(error_value, -1722, 1, 0)),
13270                         SUM(DECODE(error_value, 0, 1, 0)),
13271 												SUM(DECODE(error_value, 1, 0, 1))
13272 					INTO          l_unique_error_count,
13273 												l_not_null_error_count,
13274 												l_value_error_count,
13275 												l_parent_key_error_count,
13276 												l_too_long_error_count,
13277 												l_invalid_number_error_count,
13278                         l_not_picked_up_error_count,
13279 												l_total_error_count
13280 					FROM          xla_rules_t;
13281 				END IF;
13282 			END IF;
13283 			/*******************************************************
13284 			* Migration Error Logging for table XLA_RULE_DETAILS_T *
13285 			*******************************************************/
13286 			IF l_table_name IN ('XLA_RULE_DETAILS_T') THEN
13287 				IF p_log_level = 1 THEN
13288 					l_sql_statement :=  l_sql_statement || ' ERROR_VALUE <> 1 ';
13289 					execute IMMEDIATE l_sql_statement INTO l_failure_count;
13290 				ELSIF p_log_level = 2 THEN
13291 					SELECT        SUM(DECODE(error_value, -1, 1, 0)),
13292 												SUM(DECODE(error_value, -1400, 1, 0)),
13293 												SUM(DECODE(error_value, -6502, 1, 0)),
13294 												SUM(DECODE(error_value, -2291, 1, 0)),
13295 												SUM(DECODE(error_value, -1438, 1, -12899, 1, 0)),
13296 												SUM(DECODE(error_value, -1722, 1, 0)),
13297                         SUM(DECODE(error_value, 0, 1, 0)),
13298 												SUM(DECODE(error_value, 1, 0, 1))
13299 					INTO          l_unique_error_count,
13300 												l_not_null_error_count,
13301 												l_value_error_count,
13302 												l_parent_key_error_count,
13303 												l_too_long_error_count,
13304 												l_invalid_number_error_count,
13305                         l_not_picked_up_error_count,
13306 												l_total_error_count
13307 					FROM          xla_rule_details_t;
13308 				END IF;
13309 			END IF;
13310 			/*******************************************************
13311 			* Migration Error Logging for table XLA_CONDITIONS_T *
13312 			*******************************************************/
13313 			IF l_table_name IN ('XLA_CONDITIONS_T') THEN
13314 				IF p_log_level = 1 THEN
13315 					l_sql_statement :=  l_sql_statement || ' ERROR_VALUE <> 1 ';
13316 					execute IMMEDIATE l_sql_statement INTO l_failure_count;
13317 				ELSIF p_log_level = 2 THEN
13318 					SELECT        SUM(DECODE(error_value, -1, 1, 0)),
13319 												SUM(DECODE(error_value, -1400, 1, 0)),
13320 												SUM(DECODE(error_value, -6502, 1, 0)),
13321 												SUM(DECODE(error_value, -2291, 1, 0)),
13322 												SUM(DECODE(error_value, -1438, 1, -12899, 1, 0)),
13323 												SUM(DECODE(error_value, -1722, 1, 0)),
13324                         SUM(DECODE(error_value, 0, 1, 0)),
13325 												SUM(DECODE(error_value, 1, 0, 1))
13326 					INTO          l_unique_error_count,
13327 												l_not_null_error_count,
13328 												l_value_error_count,
13329 												l_parent_key_error_count,
13330 												l_too_long_error_count,
13331 												l_invalid_number_error_count,
13332                         l_not_picked_up_error_count,
13333 												l_total_error_count
13334 					FROM          xla_conditions_t;
13335 				END IF;
13336 			END IF;
13337 			/*******************************************************
13338 			* Migration Error Logging for table XLA_LINE_ASSGNS_T *
13339 			*******************************************************/
13340 			IF l_table_name IN ('XLA_LINE_ASSGNS_T') THEN
13341 				IF p_log_level = 1 THEN
13342 					l_sql_statement :=  l_sql_statement || ' ERROR_VALUE <> 1 ';
13343 					execute IMMEDIATE l_sql_statement INTO l_failure_count;
13344 				ELSIF p_log_level = 2 THEN
13345 					SELECT        SUM(DECODE(error_value, -1, 1, 0)),
13346 												SUM(DECODE(error_value, -1400, 1, 0)),
13347 												SUM(DECODE(error_value, -6502, 1, 0)),
13348 												SUM(DECODE(error_value, -2291, 1, 0)),
13349 												SUM(DECODE(error_value, -1438, 1, -12899, 1, 0)),
13350 												SUM(DECODE(error_value, -1722, 1, 0)),
13351                         SUM(DECODE(error_value, 0, 1, 0)),
13352 												SUM(DECODE(error_value, 1, 0, 1))
13353 					INTO          l_unique_error_count,
13354 												l_not_null_error_count,
13355 												l_value_error_count,
13356 												l_parent_key_error_count,
13357 												l_too_long_error_count,
13358 												l_invalid_number_error_count,
13359                         l_not_picked_up_error_count,
13360 												l_total_error_count
13361 					FROM          xla_line_assgns_t;
13362 				END IF;
13363 			END IF;
13364 			/**************************************************
13365 			* Migration Error Logging for table GMF_LOT_COSTS *
13366 			**************************************************/
13367 			IF l_table_name IN ('GMF_LOT_COSTS') THEN
13368 				IF p_log_level = 1 THEN
13369 					l_sql_statement :=  l_sql_statement
13370 															||
13371 															'(                (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
13372 															OR                (organization_id IS NULL AND whse_code IS NOT NULL)
13373 															OR                (inventory_item_id IS NULL AND item_id IS NOT NULL)
13374                               OR                (lot_number IS NULL AND lot_id IS NOT NULL)
13375 															)';
13376 					execute IMMEDIATE l_sql_statement INTO l_failure_count;
13377 				ELSIF p_log_level = 2 THEN
13378 					SELECT        SUM(CASE WHEN (organization_id IS NULL AND whse_code IS NOT NULL) THEN 1 ELSE 0 END),
13379 												SUM(CASE WHEN (inventory_item_id IS NULL AND item_id IS NOT NULL) THEN 1 ELSE 0 END),
13380 												SUM(CASE WHEN (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL) THEN 1 ELSE 0 END),
13381                         SUM(CASE WHEN (lot_number IS NULL AND lot_id IS NOT NULL) THEN 1 ELSE 0 END)
13382 					INTO          l_organization_count,
13383 												l_inventory_item_count,
13384 												l_cost_type_count,
13385                         l_lot_number_count
13386 					FROM          gmf_lot_costs;
13387 				END IF;
13388 			END IF;
13389 			/*********************************************************
13390 			* Migration Error Logging for table GMF_LOT_COSTED_ITEMS *
13391 			*********************************************************/
13392 			IF l_table_name IN ('GMF_LOT_COSTED_ITEMS') THEN
13393 				IF p_log_level = 1 THEN
13394 					l_sql_statement :=  l_sql_statement
13395 															||
13396 															'(                (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
13397 															OR                (legal_entity_id IS NULL AND co_code IS NOT NULL)
13398 															OR                (inventory_item_id IS NULL AND item_id IS NOT NULL)
13399 															OR                (master_organization_id IS NULL AND item_id IS NOT NULL)
13400 															)';
13401 					execute IMMEDIATE l_sql_statement INTO l_failure_count;
13402 				ELSIF p_log_level = 2 THEN
13403 					SELECT        SUM(CASE WHEN (master_organization_id IS NULL AND item_id IS NOT NULL) THEN 1 ELSE 0 END),
13404 												SUM(CASE WHEN (inventory_item_id IS NULL AND item_id IS NOT NULL) THEN 1 ELSE 0 END),
13405 												SUM(CASE WHEN (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL) THEN 1 ELSE 0 END),
13406 												SUM(CASE WHEN (legal_entity_id IS NULL AND co_code IS NOT NULL) THEN 1 ELSE 0 END)
13407 					INTO          l_master_organization_count,
13408 												l_inventory_item_count,
13409 												l_cost_type_count,
13410 												l_legal_entity_count
13411 					FROM          gmf_lot_costed_items;
13412 				END IF;
13413 			END IF;
13414 			/*********************************************************
13415 			* Migration Error Logging for table GMF_LOT_COST_BURDENS *
13416 			*********************************************************/
13417 			IF l_table_name IN ('GMF_LOT_COST_BURDENS') THEN
13418 				IF p_log_level = 1 THEN
13419 					l_sql_statement :=  l_sql_statement
13420 															||
13421 															'(                (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
13422 															OR                (organization_id IS NULL AND whse_code IS NOT NULL)
13423 															OR                (inventory_item_id IS NULL AND item_id IS NOT NULL)
13424 															OR                (item_uom IS NULL AND item_um IS NOT NULL)
13425 															OR                (resource_uom IS NULL AND resource_um IS NOT NULL)
13426                               OR                (lot_number IS NULL AND lot_id IS NOT NULL)
13427 															)';
13428 					execute IMMEDIATE l_sql_statement INTO l_failure_count;
13429 				ELSIF p_log_level = 2 THEN
13430 					SELECT        SUM(CASE WHEN (organization_id IS NULL AND whse_code IS NOT NULL) THEN 1 ELSE 0 END),
13431 												SUM(CASE WHEN (inventory_item_id IS NULL AND item_id IS NOT NULL) THEN 1 ELSE 0 END),
13432 												SUM(CASE WHEN (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL) THEN 1 ELSE 0 END),
13433 												SUM(CASE WHEN (item_uom IS NULL AND item_um IS NOT NULL) THEN 1 ELSE 0 END),
13434 												SUM(CASE WHEN (resource_uom IS NULL AND resource_um IS NOT NULL) THEN 1 ELSE 0 END),
13435                         SUM(CASE WHEN (lot_number IS NULL AND lot_id IS NOT NULL) THEN 1 ELSE 0 END)
13436 					INTO          l_organization_count,
13437 												l_inventory_item_count,
13438 												l_cost_type_count,
13439 												l_uom_count1,
13440 												l_uom_count2,
13441                         l_lot_number_count
13442 					FROM          gmf_lot_cost_burdens;
13443 				END IF;
13444 			END IF;
13445 			/*************************************************************
13446 			* Migration Error Logging for table GMF_LOT_COST_ADJUSTMENTS *
13447 			*************************************************************/
13448 			IF l_table_name IN ('GMF_LOT_COST_ADJUSTMENTS') THEN
13449 				IF p_log_level = 1 THEN
13450 					l_sql_statement :=  l_sql_statement
13451 															||
13452 															'(                (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL)
13453 															OR                (organization_id IS NULL AND whse_code IS NOT NULL)
13454 															OR                (inventory_item_id IS NULL AND item_id IS NOT NULL)
13455 															OR                (legal_entity_id IS NULL AND co_code IS NOT NULL)
13456                               OR                (lot_number IS NULL AND lot_id IS NOT NULL)
13457 															)';
13458 					execute IMMEDIATE l_sql_statement INTO l_failure_count;
13459 				ELSIF p_log_level = 2 THEN
13460 					SELECT        SUM(CASE WHEN (organization_id IS NULL AND whse_code IS NOT NULL) THEN 1 ELSE 0 END),
13461 												SUM(CASE WHEN (inventory_item_id IS NULL AND item_id IS NOT NULL) THEN 1 ELSE 0 END),
13462 												SUM(CASE WHEN (cost_type_id IS NULL AND cost_mthd_code IS NOT NULL) THEN 1 ELSE 0 END),
13463 												SUM(CASE WHEN (legal_entity_id IS NULL AND co_code IS NOT NULL) THEN 1 ELSE 0 END),
13464                         SUM(CASE WHEN (lot_number IS NULL AND lot_id IS NOT NULL) THEN 1 ELSE 0 END)
13465 					INTO          l_organization_count,
13466 												l_inventory_item_count,
13467 												l_cost_type_count,
13468 												l_legal_entity_count,
13469                         l_lot_number_count
13470 					FROM          gmf_lot_cost_adjustments;
13471 				END IF;
13472 			END IF;
13473 			/***************************************************************
13474 			* Migration Error Logging for table GMF_MATERIAL_LOT_COST_TXNS *
13475 			***************************************************************/
13476 			IF l_table_name IN ('GMF_MATERIAL_LOT_COST_TXNS') THEN
13477 				IF p_log_level = 1 THEN
13478 					l_sql_statement :=  l_sql_statement
13479 															||
13480 															'(                (cost_type_id IS NULL AND cost_type_code IS NOT NULL)
13481 															OR                (cost_trans_um IS NULL AND cost_trans_uom IS NOT NULL)
13482 															)';
13483 					execute IMMEDIATE l_sql_statement INTO l_failure_count;
13484 				ELSIF p_log_level = 2 THEN
13485 					SELECT        SUM(CASE WHEN (cost_type_id IS NULL AND cost_type_code IS NOT NULL) THEN 1 ELSE 0 END),
13486 												SUM(CASE WHEN (cost_trans_um IS NULL AND cost_trans_uom IS NOT NULL) THEN 1 ELSE 0 END)
13487 					INTO          l_cost_type_count,
13488 												l_uom_count1
13489 					FROM          gmf_material_lot_cost_txns;
13490 				END IF;
13491 			END IF;
13492 			/************************************************
13493 			* Migration Error Logging for table CM_WHSE_SRC *
13494 			************************************************/
13495 			IF l_table_name IN ('CM_WHSE_SRC') THEN
13496 				IF p_log_level = 1 THEN
13497 					l_sql_statement :=  l_sql_statement
13498 															||
13499 															'(                    (legal_entity_id IS NULL AND orgn_code IS NOT NULL)
13500 															OR                    (source_organization_id IS NULL AND whse_code IS NOT NULL)
13501 															OR                    (inventory_item_id IS NULL AND item_id IS NOT NULL)
13502 															OR                    (master_organization_id IS NULL AND item_id IS NOT NULL)
13503 															OR                    (organization_id IS NULL AND delete_mark = 0 AND orgn_code IS NOT NULL)
13504 															)';
13505 					execute IMMEDIATE l_sql_statement INTO l_failure_count;
13506 				ELSIF p_log_level = 2 THEN
13507 					SELECT        SUM(CASE WHEN (source_organization_id IS NULL AND whse_code IS NOT NULL) THEN 1 ELSE 0 END),
13508 												SUM(CASE WHEN (inventory_item_id IS NULL AND item_id IS NOT NULL) THEN 1 ELSE 0 END),
13509 												SUM(CASE WHEN (organization_id IS NULL AND delete_mark = 0 AND orgn_code IS NOT NULL) THEN 1 ELSE 0 END),
13510 												SUM(CASE WHEN (legal_entity_id IS NULL AND orgn_code IS NOT NULL) THEN 1 ELSE 0 END),
13511 												SUM(CASE WHEN (master_organization_id IS NULL AND item_id IS NOT NULL) THEN 1 ELSE 0 END)
13512 					INTO          l_source_organization_count,
13513 												l_inventory_item_count,
13514 												l_organization_count,
13515 												l_legal_entity_count,
13516 												l_master_organization_count
13517 					FROM          cm_whse_src;
13518 				END IF;
13519 			END IF;
13520 			/************************************************
13521 			* Migration Error Logging for table CM_ACPR_CTL *
13522 			************************************************/
13523 			IF l_table_name IN ('CM_ACPR_CTL') THEN
13524 				IF p_log_level = 1 THEN
13525 					l_sql_statement :=  l_sql_statement
13526 															||
13527 															'(              (calendar_code IS NOT NULL AND period_code IS NOT NULL and period_id IS NULL)
13528 															OR              (cost_mthd_code IS NOT NULL AND cost_type_id is NULL)
13529 															OR              (calendar_code IS NOT NULL AND legal_entity_id IS NULL)
13530 															)';
13531 					execute IMMEDIATE l_sql_statement INTO l_failure_count;
13532 				ELSIF p_log_level = 2 THEN
13533 					SELECT        SUM(CASE WHEN (calendar_code IS NOT NULL AND period_code IS NOT NULL and period_id IS NULL) THEN 1 ELSE 0 END),
13534 												SUM(CASE WHEN (cost_mthd_code IS NOT NULL AND cost_type_id is NULL) THEN 1 ELSE 0 END),
13535 												SUM(CASE WHEN (calendar_code IS NOT NULL AND legal_entity_id IS NULL) THEN 1 ELSE 0 END)
13536 					INTO          l_period_count,
13537 												l_cost_type_count,
13538 												l_legal_entity_count
13539 					FROM          cm_acpr_ctl;
13540 				END IF;
13541 			END IF;
13542 			/************************************************
13543 			* Migration Error Logging for table CM_RLUP_CTL *
13544 			************************************************/
13545 			IF l_table_name IN ('CM_RLUP_CTL') THEN
13546 				IF p_log_level = 1 THEN
13547 					l_sql_statement :=  l_sql_statement
13548 															||
13549 															'(                (calendar_code is not null and period_code is not null and period_id is null)
13550 															or                (cost_mthd_code is not null and cost_type_id is null)
13551 															or                (calendar_code is not null and legal_entity_id is null)
13552 															or                (inventory_item_id is null and item_id is not null)
13553 															or                (master_organization_id is null and item_id is not null)
13554 															)';
13555 					execute IMMEDIATE l_sql_statement INTO l_failure_count;
13556 				ELSIF p_log_level = 2 THEN
13557 					SELECT        SUM(CASE WHEN (calendar_code IS NOT NULL AND period_code IS NOT NULL and period_id IS NULL) THEN 1 ELSE 0 END),
13558 												SUM(CASE WHEN (cost_mthd_code IS NOT NULL AND cost_type_id is NULL) THEN 1 ELSE 0 END),
13559 												SUM(CASE WHEN (calendar_code IS NOT NULL AND legal_entity_id IS NULL) THEN 1 ELSE 0 END),
13560 												SUM(CASE WHEN (inventory_item_id IS NULL AND item_id IS NOT NULL) THEN 1 ELSE 0 END),
13561 												SUM(CASE WHEN (master_organization_id IS NULL AND item_id IS NOT NULL) THEN 1 ELSE 0 END)
13562 					INTO          l_period_count,
13563 												l_cost_type_count,
13564 												l_legal_entity_count,
13565 												l_inventory_item_count,
13566 												l_master_organization_count
13567 					FROM          cm_rlup_ctl;
13568 				END IF;
13569 			END IF;
13570 			/************************************************
13571 			* Migration Error Logging for table CM_RLUP_ITM *
13572 			************************************************/
13573 			IF l_table_name IN ('CM_RLUP_ITM') THEN
13574 				IF p_log_level = 1 THEN
13575 					l_sql_statement :=  l_sql_statement
13576 															||
13577 															'(                (inventory_item_id is null and item_id is not null)
13578 															or                (organization_id is null and item_id is not null)
13579 															)';
13580 					execute IMMEDIATE l_sql_statement INTO l_failure_count;
13581 				ELSIF p_log_level = 2 THEN
13582 					SELECT        SUM(CASE WHEN (inventory_item_id IS NULL AND item_id IS NOT NULL) THEN 1 ELSE 0 END),
13583 												SUM(CASE WHEN (organization_id IS NULL AND item_id IS NOT NULL) THEN 1 ELSE 0 END)
13584 					INTO          l_inventory_item_count,
13585 												l_master_organization_count
13586 					FROM          cm_rlup_itm;
13587 				END IF;
13588 			END IF;
13589 			/************************************************
13590 			* Migration Error Logging for table CM_CUPD_CTL *
13591 			************************************************/
13592 			IF l_table_name IN ('CM_CUPD_CTL') THEN
13593 				IF p_log_level = 1 THEN
13594 					l_sql_statement :=  l_sql_statement
13595 															||
13596 															'(              (calendar_code IS NOT NULL AND period_code IS NOT NULL and period_id IS NULL)
13597 															OR              (cost_mthd_code IS NOT NULL AND cost_type_id is NULL)
13598 															OR              (calendar_code IS NOT NULL AND legal_entity_id IS NULL)
13599 															)';
13600 					execute IMMEDIATE l_sql_statement INTO l_failure_count;
13601 				ELSIF p_log_level = 2 THEN
13602 					SELECT        SUM(CASE WHEN (calendar_code IS NOT NULL AND period_code IS NOT NULL and period_id IS NULL) THEN 1 ELSE 0 END),
13603 												SUM(CASE WHEN (cost_mthd_code IS NOT NULL AND cost_type_id is NULL) THEN 1 ELSE 0 END),
13604 												SUM(CASE WHEN (calendar_code IS NOT NULL AND legal_entity_id IS NULL) THEN 1 ELSE 0 END)
13605 					INTO          l_period_count,
13606 												l_cost_type_count,
13607 												l_legal_entity_count
13608 					FROM          cm_cupd_ctl;
13609 				END IF;
13610 			END IF;
13611 			/************************************************
13612 			* Migration Error Logging for table GL_SUBR_STA *
13613 			************************************************/
13614 			IF l_table_name IN ('GL_SUBR_STA') THEN
13615 				IF p_log_level = 1 THEN
13616 					l_sql_statement :=  l_sql_statement
13617 															||
13618 															'(              (crev_curr_mthd is not null AND crev_curr_cost_type_id IS NULL)
13619 															OR              (crev_curr_calendar is not null and crev_curr_period is not NULL AND crev_curr_period_id is null)
13620 															OR              (crev_prev_mthd is not null AND crev_prev_cost_type_id IS NULL)
13621 															OR              (crev_prev_calendar is not null and crev_prev_period is not NULL AND crev_prev_period_id is null)
13622 															OR              (co_code is not null and legal_entity_id is null)
13623 															OR              (co_code is not null AND cost_type_id is null)
13624 															)';
13625 					execute IMMEDIATE l_sql_statement INTO l_failure_count;
13626 				ELSIF p_log_level = 2 THEN
13627 					SELECT        SUM(CASE WHEN (crev_curr_mthd is not null AND crev_curr_cost_type_id IS NULL) THEN 1 ELSE 0 END),
13628 												SUM(CASE WHEN (crev_curr_calendar is not null and crev_curr_period is not NULL AND crev_curr_period_id is null) THEN 1 ELSE 0 END),
13629 												SUM(CASE WHEN (crev_prev_mthd is not null AND crev_prev_cost_type_id IS NULL) THEN 1 ELSE 0 END),
13630 												SUM(CASE WHEN (crev_prev_calendar is not null and crev_prev_period is not NULL AND crev_prev_period_id is null) THEN 1 ELSE 0 END),
13631 												SUM(CASE WHEN (co_code is not null and legal_entity_id is null) THEN 1 ELSE 0 END),
13632 												SUM(CASE WHEN (co_code is not null AND cost_type_id is null) THEN 1 ELSE 0 END)
13633 					INTO          l_curr_cost_type_count,
13634 												l_curr_period_count,
13635 												l_prev_cost_type_count,
13636 												l_prev_period_count,
13637 												l_legal_entity_count,
13638 												l_cost_type_count
13639 					FROM          gl_subr_sta;
13640 				END IF;
13641 			END IF;
13642 		ELSIF p_log_level = 3 THEN
13643       IF l_table_name = 'CM_RSRC_DTL' THEN
13644   			OPEN cur_gmf_log_errors FOR l_cm_rsrc_dtl;
13645   			FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13646   			CLOSE cur_gmf_log_errors;
13647       ELSIF l_table_name = 'CM_ADJS_DTL' THEN
13648   			OPEN cur_gmf_log_errors FOR l_cm_adjs_dtl;
13649   			FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13650   			CLOSE cur_gmf_log_errors;
13651       ELSIF l_table_name = 'CM_CMPT_DTL' THEN
13652         OPEN cur_gmf_log_errors FOR l_cm_cmpt_dtl;
13653         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13654         CLOSE cur_gmf_log_errors;
13655       ELSIF l_table_name = 'CM_BRDN_DTL' THEN
13656         OPEN cur_gmf_log_errors FOR l_cm_brdn_dtl;
13657         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13658         CLOSE cur_gmf_log_errors;
13659       ELSIF l_table_name = 'GL_ITEM_CST' THEN
13660         OPEN cur_gmf_log_errors FOR l_gl_item_cst;
13661         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13662         CLOSE cur_gmf_log_errors;
13663       ELSIF l_table_name = 'CM_SCST_LED' THEN
13664         OPEN cur_gmf_log_errors FOR l_cm_scst_led;
13665         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13666         CLOSE cur_gmf_log_errors;
13667       ELSIF l_table_name = 'CM_ACST_LED' THEN
13668         OPEN cur_gmf_log_errors FOR l_cm_acst_led;
13669         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13670         CLOSE cur_gmf_log_errors;
13671       ELSIF l_table_name = 'XLA_RULES_T' THEN
13672         OPEN cur_gmf_log_errors FOR l_xla_rules_t;
13673         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13674         CLOSE cur_gmf_log_errors;
13675       ELSIF l_table_name = 'XLA_RULE_DETAILS_T' THEN
13676         OPEN cur_gmf_log_errors FOR l_xla_rule_details_t;
13677         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13678         CLOSE cur_gmf_log_errors;
13679       ELSIF l_table_name = 'XLA_CONDITIONS_T' THEN
13680         OPEN cur_gmf_log_errors FOR l_xla_conditions_t;
13681         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13682         CLOSE cur_gmf_log_errors;
13683       ELSIF l_table_name = 'XLA_LINE_ASSGNS_T' THEN
13684         OPEN cur_gmf_log_errors FOR l_xla_line_assgns_t;
13685         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13686         CLOSE cur_gmf_log_errors;
13687       ELSIF l_table_name = 'GMF_LOT_COSTS' THEN
13688         OPEN cur_gmf_log_errors FOR l_gmf_lot_costs;
13689         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13690         CLOSE cur_gmf_log_errors;
13691       ELSIF l_table_name = 'GMF_LOT_COSTED_ITEMS' THEN
13692         OPEN cur_gmf_log_errors FOR l_gmf_lot_costed_items;
13693         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13694         CLOSE cur_gmf_log_errors;
13695       ELSIF l_table_name = 'GMF_LOT_COST_BURDENS' THEN
13696         OPEN cur_gmf_log_errors FOR l_gmf_lot_cost_burdens;
13697         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13698         CLOSE cur_gmf_log_errors;
13699       ELSIF l_table_name = 'GMF_LOT_COST_ADJUSTMENTS' THEN
13700         OPEN cur_gmf_log_errors FOR l_gmf_lot_cost_adjustments;
13701         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13702         CLOSE cur_gmf_log_errors;
13703       ELSIF l_table_name = 'GMF_MATERIAL_LOT_COST_TXNS' THEN
13704         OPEN cur_gmf_log_errors FOR l_gmf_material_lot_cost_txns;
13705         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13706         CLOSE cur_gmf_log_errors;
13707       ELSIF l_table_name = 'CM_WHSE_SRC' THEN
13708         OPEN cur_gmf_log_errors FOR l_cm_whse_src;
13709         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13710         CLOSE cur_gmf_log_errors;
13711       ELSIF l_table_name = 'CM_ACPR_CTL' THEN
13712         OPEN cur_gmf_log_errors FOR l_cm_acpr_ctl;
13713         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13714         CLOSE cur_gmf_log_errors;
13715       ELSIF l_table_name = 'CM_RLUP_CTL' THEN
13716         OPEN cur_gmf_log_errors FOR l_cm_rlup_ctl;
13717         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13718         CLOSE cur_gmf_log_errors;
13719       ELSIF l_table_name = 'CM_RLUP_ITM' THEN
13720         OPEN cur_gmf_log_errors FOR l_cm_rlup_itm;
13721         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13722         CLOSE cur_gmf_log_errors;
13723       ELSIF l_table_name = 'CM_CUPD_CTL' THEN
13724         OPEN cur_gmf_log_errors FOR l_cm_cupd_ctl;
13725         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13726         CLOSE cur_gmf_log_errors;
13727       ELSIF l_table_name = 'GL_SUBR_STA' THEN
13728         OPEN cur_gmf_log_errors FOR l_gl_subr_sta;
13729         FETCH cur_gmf_log_errors bulk collect INTO l_error_tbl;
13730         CLOSE cur_gmf_log_errors;
13731       END IF;
13732 		END IF;
13733 		/********************************************
13734 		* Logging Errors in GMA_MIGRATION_LOG table *
13735 		********************************************/
13736 		IF p_log_level = 1 THEN
13737 			IF nvl(l_failure_count,0) > 0 THEN
13738 				/**************************************
13739 				* Migration Failure Log Message       *
13740 				**************************************/
13741 				GMA_COMMON_LOGGING.gma_migration_central_log
13742 				(
13743 				p_run_id             =>       gmf_migration.G_migration_run_id,
13744 				p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
13745 				p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
13746 				p_table_name         =>       gmf_migration.G_Table_name,
13747 				p_context            =>       gmf_migration.G_context,
13748 				p_db_error           =>       NULL,
13749 				p_app_short_name     =>       'GMA'
13750 				);
13751 			ELSE
13752 				/**************************************
13753 				* Migration Success Log Message       *
13754 				**************************************/
13755 				GMA_COMMON_LOGGING.gma_migration_central_log
13756 				(
13757 				p_run_id             =>       gmf_migration.G_migration_run_id,
13758 				p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
13759 				p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
13760 				p_table_name         =>       gmf_migration.G_Table_name,
13761 				p_context            =>       gmf_migration.G_context,
13762 				p_param1             =>       1,
13763 				p_param2             =>       0,
13764 				p_db_error           =>       NULL,
13765 				p_app_short_name     =>       'GMA'
13766 				);
13767 			END IF;
13768 		ELSIF p_log_level = 2 THEN
13769 			l_failure_count :=  nvl(l_legal_entity_count, 0) + nvl(l_organization_count, 0) + nvl(l_cost_type_count, 0) +
13770 													nvl(l_period_count, 0) + nvl(l_uom_count1, 0) + nvl(l_uom_count2, 0) + nvl(l_uom_count3, 0) +
13771 													nvl(l_inventory_item_count, 0) + nvl(l_adjustment_ind_count, 0) + nvl(l_source_organization_count, 0) +
13772 													nvl(l_master_organization_count, 0) + nvl(l_prev_cost_type_count, 0) + nvl(l_prev_period_count, 0) +
13773 													nvl(l_curr_cost_type_count, 0) + nvl(l_curr_period_count, 0) + nvl(l_total_error_count, 0) +
13774                           nvl(l_lot_number_count, 0);
13775 			IF nvl(l_failure_count,0) > 0 THEN
13776 				/***********************************
13777 				* Legal Entity Migration Error Log *
13778 				***********************************/
13779 				IF nvl(l_legal_entity_count,0) > 0 THEN
13780 					GMA_COMMON_LOGGING.gma_migration_central_log
13781 					(
13782 					p_run_id             =>       gmf_migration.G_migration_run_id,
13783 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
13784 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
13785 					p_table_name         =>       gmf_migration.G_Table_name,
13786 					p_context            =>       gmf_migration.G_Context,
13787 					p_token1             =>       'TABLE_NAME',
13788 					p_token2             =>       'COLUMN_NAME',
13789 					p_token3             =>       'RECORD_COUNT',
13790 					p_param1             =>       gmf_migration.G_Table_name,
13791 					p_param2             =>       'Legal Entities',
13792 					p_param3             =>       l_legal_entity_count,
13793 					p_db_error           =>       NULL,
13794 					p_app_short_name     =>       'GMA'
13795 					);
13796 				END IF;
13797 				/***********************************
13798 				* Organization Migration Error Log *
13799 				***********************************/
13800 				IF nvl(l_organization_count,0) > 0 THEN
13801 					GMA_COMMON_LOGGING.gma_migration_central_log
13802 					(
13803 					p_run_id             =>       gmf_migration.G_migration_run_id,
13804 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
13805 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
13806 					p_table_name         =>       gmf_migration.G_Table_name,
13807 					p_context            =>       gmf_migration.G_Context,
13808 					p_token1             =>       'TABLE_NAME',
13809 					p_token2             =>       'COLUMN_NAME',
13810 					p_token3             =>       'RECORD_COUNT',
13811 					p_param1             =>       gmf_migration.G_Table_name,
13812 					p_param2             =>       'Organizations',
13813 					p_param3             =>       l_organization_count,
13814 					p_db_error           =>       NULL,
13815 					p_app_short_name     =>       'GMA'
13816 					);
13817 				END IF;
13818 				/******************************************
13819 				* Source Organization Migration Error Log *
13820 				******************************************/
13821 				IF nvl(l_source_organization_count,0) > 0 THEN
13822 					GMA_COMMON_LOGGING.gma_migration_central_log
13823 					(
13824 					p_run_id             =>       gmf_migration.G_migration_run_id,
13825 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
13826 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
13827 					p_table_name         =>       gmf_migration.G_Table_name,
13828 					p_context            =>       gmf_migration.G_Context,
13829 					p_token1             =>       'TABLE_NAME',
13830 					p_token2             =>       'COLUMN_NAME',
13831 					p_token3             =>       'RECORD_COUNT',
13832 					p_param1             =>       gmf_migration.G_Table_name,
13833 					p_param2             =>       'Source Organizations',
13834 					p_param3             =>       l_source_organization_count,
13835 					p_db_error           =>       NULL,
13836 					p_app_short_name     =>       'GMA'
13837 					);
13838 				END IF;
13839 				/******************************************
13840 				* Master Organization Migration Error Log *
13841 				******************************************/
13842 				IF nvl(l_master_organization_count,0) > 0 THEN
13843 					GMA_COMMON_LOGGING.gma_migration_central_log
13844 					(
13845 					p_run_id             =>       gmf_migration.G_migration_run_id,
13846 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
13847 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
13848 					p_table_name         =>       gmf_migration.G_Table_name,
13849 					p_context            =>       gmf_migration.G_Context,
13850 					p_token1             =>       'TABLE_NAME',
13851 					p_token2             =>       'COLUMN_NAME',
13852 					p_token3             =>       'RECORD_COUNT',
13853 					p_param1             =>       gmf_migration.G_Table_name,
13854 					p_param2             =>       'Master Organizations',
13855 					p_param3             =>       l_master_organization_count,
13856 					p_db_error           =>       NULL,
13857 					p_app_short_name     =>       'GMA'
13858 					);
13859 				END IF;
13860 				/***************************
13861 				* Item Migration Error Log *
13862 				***************************/
13863 				IF nvl(l_inventory_item_count,0) > 0 THEN
13864 					GMA_COMMON_LOGGING.gma_migration_central_log
13865 					(
13866 					p_run_id             =>       gmf_migration.G_migration_run_id,
13867 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
13868 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
13869 					p_table_name         =>       gmf_migration.G_Table_name,
13870 					p_context            =>       gmf_migration.G_Context,
13871 					p_token1             =>       'TABLE_NAME',
13872 					p_token2             =>       'COLUMN_NAME',
13873 					p_token3             =>       'RECORD_COUNT',
13874 					p_param1             =>       gmf_migration.G_Table_name,
13875 					p_param2             =>       'Items',
13876 					p_param3             =>       l_inventory_item_count,
13877 					p_db_error           =>       NULL,
13878 					p_app_short_name     =>       'GMA'
13879 					);
13880 				END IF;
13881 				/***********************************
13882 				* Cost Type Migration Error Log    *
13883 				***********************************/
13884 				IF nvl(l_cost_type_count,0) > 0 THEN
13885 					GMA_COMMON_LOGGING.gma_migration_central_log
13886 					(
13887 					p_run_id             =>       gmf_migration.G_migration_run_id,
13888 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
13889 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
13890 					p_table_name         =>       gmf_migration.G_Table_name,
13891 					p_context            =>       gmf_migration.G_Context,
13892 					p_token1             =>       'TABLE_NAME',
13893 					p_token2             =>       'COLUMN_NAME',
13894 					p_token3             =>       'RECORD_COUNT',
13895 					p_param1             =>       gmf_migration.G_Table_name,
13896 					p_param2             =>       'Cost Types',
13897 					p_param3             =>       l_cost_type_count,
13898 					p_db_error           =>       NULL,
13899 					p_app_short_name     =>       'GMA'
13900 					);
13901 				END IF;
13902 				/********************************************
13903 				* Previous Cost Type Migration Error Log    *
13904 				********************************************/
13905 				IF nvl(l_prev_cost_type_count,0) > 0 THEN
13906 					GMA_COMMON_LOGGING.gma_migration_central_log
13907 					(
13908 					p_run_id             =>       gmf_migration.G_migration_run_id,
13909 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
13910 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
13911 					p_table_name         =>       gmf_migration.G_Table_name,
13912 					p_context            =>       gmf_migration.G_Context,
13913 					p_token1             =>       'TABLE_NAME',
13914 					p_token2             =>       'COLUMN_NAME',
13915 					p_token3             =>       'RECORD_COUNT',
13916 					p_param1             =>       gmf_migration.G_Table_name,
13917 					p_param2             =>       'Previous Cost Types',
13918 					p_param3             =>       l_prev_cost_type_count,
13919 					p_db_error           =>       NULL,
13920 					p_app_short_name     =>       'GMA'
13921 					);
13922 				END IF;
13923 				/*******************************************
13924 				* Current Cost Type Migration Error Log    *
13925 				*******************************************/
13926 				IF nvl(l_curr_cost_type_count,0) > 0 THEN
13927 					GMA_COMMON_LOGGING.gma_migration_central_log
13928 					(
13929 					p_run_id             =>       gmf_migration.G_migration_run_id,
13930 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
13931 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
13932 					p_table_name         =>       gmf_migration.G_Table_name,
13933 					p_context            =>       gmf_migration.G_Context,
13934 					p_token1             =>       'TABLE_NAME',
13935 					p_token2             =>       'COLUMN_NAME',
13936 					p_token3             =>       'RECORD_COUNT',
13937 					p_param1             =>       gmf_migration.G_Table_name,
13938 					p_param2             =>       'Current Cost Types',
13939 					p_param3             =>       l_curr_cost_type_count,
13940 					p_db_error           =>       NULL,
13941 					p_app_short_name     =>       'GMA'
13942 					);
13943 				END IF;
13944 				/***********************************
13945 				* Periods Migration Error Log      *
13946 				***********************************/
13947 				IF nvl(l_period_count,0) > 0 THEN
13948 					GMA_COMMON_LOGGING.gma_migration_central_log
13949 					(
13950 					p_run_id             =>       gmf_migration.G_migration_run_id,
13951 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
13952 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
13953 					p_table_name         =>       gmf_migration.G_Table_name,
13954 					p_context            =>       gmf_migration.G_Context,
13955 					p_token1             =>       'TABLE_NAME',
13956 					p_token2             =>       'COLUMN_NAME',
13957 					p_token3             =>       'RECORD_COUNT',
13958 					p_param1             =>       gmf_migration.G_Table_name,
13959 					p_param2             =>       'Periods',
13960 					p_param3             =>       l_period_count,
13961 					p_db_error           =>       NULL,
13962 					p_app_short_name     =>       'GMA'
13963 					);
13964 				END IF;
13965 				/********************************************
13966 				* Previous Periods Migration Error Log      *
13967 				********************************************/
13968 				IF nvl(l_prev_period_count,0) > 0 THEN
13969 					GMA_COMMON_LOGGING.gma_migration_central_log
13970 					(
13971 					p_run_id             =>       gmf_migration.G_migration_run_id,
13972 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
13973 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
13974 					p_table_name         =>       gmf_migration.G_Table_name,
13975 					p_context            =>       gmf_migration.G_Context,
13976 					p_token1             =>       'TABLE_NAME',
13977 					p_token2             =>       'COLUMN_NAME',
13978 					p_token3             =>       'RECORD_COUNT',
13979 					p_param1             =>       gmf_migration.G_Table_name,
13980 					p_param2             =>       'Previous Periods',
13981 					p_param3             =>       l_prev_period_count,
13982 					p_db_error           =>       NULL,
13983 					p_app_short_name     =>       'GMA'
13984 					);
13985 				END IF;
13986 				/********************************************
13987 				* Current Periods Migration Error Log      *
13988 				********************************************/
13989 				IF nvl(l_curr_period_count,0) > 0 THEN
13990 					GMA_COMMON_LOGGING.gma_migration_central_log
13991 					(
13992 					p_run_id             =>       gmf_migration.G_migration_run_id,
13993 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
13994 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
13995 					p_table_name         =>       gmf_migration.G_Table_name,
13996 					p_context            =>       gmf_migration.G_Context,
13997 					p_token1             =>       'TABLE_NAME',
13998 					p_token2             =>       'COLUMN_NAME',
13999 					p_token3             =>       'RECORD_COUNT',
14000 					p_param1             =>       gmf_migration.G_Table_name,
14001 					p_param2             =>       'Current Periods',
14002 					p_param3             =>       l_curr_period_count,
14003 					p_db_error           =>       NULL,
14004 					p_app_short_name     =>       'GMA'
14005 					);
14006 				END IF;
14007 				/***********************************
14008 				* UOM-1 Migration Error Log        *
14009 				***********************************/
14010 				IF nvl(l_uom_count1,0) > 0 THEN
14011 					GMA_COMMON_LOGGING.gma_migration_central_log
14012 					(
14013 					p_run_id             =>       gmf_migration.G_migration_run_id,
14014 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
14015 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
14016 					p_table_name         =>       gmf_migration.G_Table_name,
14017 					p_context            =>       gmf_migration.G_Context,
14018 					p_token1             =>       'TABLE_NAME',
14019 					p_token2             =>       'COLUMN_NAME',
14020 					p_token3             =>       'RECORD_COUNT',
14021 					p_param1             =>       gmf_migration.G_Table_name,
14022 					p_param2             =>       'UOMs',
14023 					p_param3             =>       l_uom_count1,
14024 					p_db_error           =>       NULL,
14025 					p_app_short_name     =>       'GMA'
14026 					);
14027 				END IF;
14028 				/***********************************
14029 				* UOM-2 Migration Error Log        *
14030 				***********************************/
14031 				IF nvl(l_uom_count2,0) > 0 THEN
14032 					GMA_COMMON_LOGGING.gma_migration_central_log
14033 					(
14034 					p_run_id             =>       gmf_migration.G_migration_run_id,
14035 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
14036 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
14037 					p_table_name         =>       gmf_migration.G_Table_name,
14038 					p_context            =>       gmf_migration.G_Context,
14039 					p_token1             =>       'TABLE_NAME',
14040 					p_token2             =>       'COLUMN_NAME',
14041 					p_token3             =>       'RECORD_COUNT',
14042 					p_param1             =>       gmf_migration.G_Table_name,
14043 					p_param2             =>       'UOMs',
14044 					p_param3             =>       l_uom_count2,
14045 					p_db_error           =>       NULL,
14046 					p_app_short_name     =>       'GMA'
14047 					);
14048 				END IF;
14049 				/***********************************
14050 				* UOM-3 Migration Error Log        *
14051 				***********************************/
14052 				IF nvl(l_uom_count3,0) > 0 THEN
14053 					GMA_COMMON_LOGGING.gma_migration_central_log
14054 					(
14055 					p_run_id             =>       gmf_migration.G_migration_run_id,
14056 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
14057 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
14058 					p_table_name         =>       gmf_migration.G_Table_name,
14059 					p_context            =>       gmf_migration.G_Context,
14060 					p_token1             =>       'TABLE_NAME',
14061 					p_token2             =>       'COLUMN_NAME',
14062 					p_token3             =>       'RECORD_COUNT',
14063 					p_param1             =>       gmf_migration.G_Table_name,
14064 					p_param2             =>       'UOMs',
14065 					p_param3             =>       l_uom_count3,
14066 					p_db_error           =>       NULL,
14067 					p_app_short_name     =>       'GMA'
14068 					);
14069 				END IF;
14070 				/*******************************************
14071 				* Adjustment Indicator Migration Error Log *
14072 				*******************************************/
14073 				IF nvl(l_adjustment_ind_count,0) > 0 THEN
14074 					GMA_COMMON_LOGGING.gma_migration_central_log
14075 					(
14076 					p_run_id             =>       gmf_migration.G_migration_run_id,
14077 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
14078 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
14079 					p_table_name         =>       gmf_migration.G_Table_name,
14080 					p_context            =>       gmf_migration.G_Context,
14081 					p_token1             =>       'TABLE_NAME',
14082 					p_token2             =>       'COLUMN_NAME',
14083 					p_token3             =>       'RECORD_COUNT',
14084 					p_param1             =>       gmf_migration.G_Table_name,
14085 					p_param2             =>       'Adjustment Indicators',
14086 					p_param3             =>       l_adjustment_ind_count,
14087 					p_db_error           =>       NULL,
14088 					p_app_short_name     =>       'GMA'
14089 					);
14090 				END IF;
14091         /***********************************
14092         * Lot Number Migration Error Log *
14093         ***********************************/
14094         IF nvl(l_lot_number_count,0) > 0 THEN
14095           GMA_COMMON_LOGGING.gma_migration_central_log
14096           (
14097           p_run_id             =>       gmf_migration.G_migration_run_id,
14098           p_log_level          =>       FND_LOG.LEVEL_ERROR,
14099           p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
14100           p_table_name         =>       gmf_migration.G_Table_name,
14101           p_context            =>       gmf_migration.G_Context,
14102           p_token1             =>       'TABLE_NAME',
14103           p_token2             =>       'COLUMN_NAME',
14104           p_token3             =>       'RECORD_COUNT',
14105           p_param1             =>       gmf_migration.G_Table_name,
14106           p_param2             =>       'Lot Numbers',
14107           p_param3             =>       l_lot_number_count,
14108           p_db_error           =>       NULL,
14109           p_app_short_name     =>       'GMA'
14110           );
14111         END IF;
14112 				/****************************************
14113 				* Unique Constraint Migration Error Log *
14114 				****************************************/
14115 				IF nvl(l_unique_error_count,0) > 0 THEN
14116 					GMA_COMMON_LOGGING.gma_migration_central_log
14117 					(
14118 					p_run_id             =>       gmf_migration.G_migration_run_id,
14119 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
14120 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
14121 					p_table_name         =>       gmf_migration.G_Table_name,
14122 					p_context            =>       gmf_migration.G_Context,
14123 					p_token1             =>       'TABLE_NAME',
14124 					p_token2             =>       'COLUMN_NAME',
14125 					p_token3             =>       'RECORD_COUNT',
14126 					p_param1             =>       gmf_migration.G_Table_name,
14127 					p_param2             =>       'Unique Constraint',
14128 					p_param3             =>       l_unique_error_count,
14129 					p_db_error           =>       NULL,
14130 					p_app_short_name     =>       'GMA'
14131 					);
14132 				END IF;
14133 				/******************************************
14134 				* Not Null Constraint Migration Error Log *
14135 				******************************************/
14136 				IF nvl(l_not_null_error_count,0) > 0 THEN
14137 					GMA_COMMON_LOGGING.gma_migration_central_log
14138 					(
14139 					p_run_id             =>       gmf_migration.G_migration_run_id,
14140 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
14141 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
14142 					p_table_name         =>       gmf_migration.G_Table_name,
14143 					p_context            =>       gmf_migration.G_Context,
14144 					p_token1             =>       'TABLE_NAME',
14145 					p_token2             =>       'COLUMN_NAME',
14146 					p_token3             =>       'RECORD_COUNT',
14147 					p_param1             =>       gmf_migration.G_Table_name,
14148 					p_param2             =>       'Not Null Constraint',
14149 					p_param3             =>       l_not_null_error_count,
14150 					p_db_error           =>       NULL,
14151 					p_app_short_name     =>       'GMA'
14152 					);
14153 				END IF;
14154 				/************************************
14155 				* Invalid Value Migration Error Log *
14156 				************************************/
14157 				IF nvl(l_value_error_count,0) > 0 THEN
14158 					GMA_COMMON_LOGGING.gma_migration_central_log
14159 					(
14160 					p_run_id             =>       gmf_migration.G_migration_run_id,
14161 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
14162 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
14163 					p_table_name         =>       gmf_migration.G_Table_name,
14164 					p_context            =>       gmf_migration.G_Context,
14165 					p_token1             =>       'TABLE_NAME',
14166 					p_token2             =>       'COLUMN_NAME',
14167 					p_token3             =>       'RECORD_COUNT',
14168 					p_param1             =>       gmf_migration.G_Table_name,
14169 					p_param2             =>       'Invalid Value',
14170 					p_param3             =>       l_value_error_count,
14171 					p_db_error           =>       NULL,
14172 					p_app_short_name     =>       'GMA'
14173 					);
14174 				END IF;
14175 				/*******************************************
14176 				* Parent Key Not-found Migration Error Log *
14177 				*******************************************/
14178 				IF nvl(l_parent_key_error_count,0) > 0 THEN
14179 					GMA_COMMON_LOGGING.gma_migration_central_log
14180 					(
14181 					p_run_id             =>       gmf_migration.G_migration_run_id,
14182 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
14183 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
14184 					p_table_name         =>       gmf_migration.G_Table_name,
14185 					p_context            =>       gmf_migration.G_Context,
14186 					p_token1             =>       'TABLE_NAME',
14187 					p_token2             =>       'COLUMN_NAME',
14188 					p_token3             =>       'RECORD_COUNT',
14189 					p_param1             =>       gmf_migration.G_Table_name,
14190 					p_param2             =>       'Parent Key Constraint',
14191 					p_param3             =>       l_parent_key_error_count,
14192 					p_db_error           =>       NULL,
14193 					p_app_short_name     =>       'GMA'
14194 					);
14195 				END IF;
14196 				/*************************************
14197 				* Value Too Long Migration Error Log *
14198 				*************************************/
14199 				IF nvl(l_too_long_error_count,0) > 0 THEN
14200 					GMA_COMMON_LOGGING.gma_migration_central_log
14201 					(
14202 					p_run_id             =>       gmf_migration.G_migration_run_id,
14203 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
14204 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
14205 					p_table_name         =>       gmf_migration.G_Table_name,
14206 					p_context            =>       gmf_migration.G_Context,
14207 					p_token1             =>       'TABLE_NAME',
14208 					p_token2             =>       'COLUMN_NAME',
14209 					p_token3             =>       'RECORD_COUNT',
14210 					p_param1             =>       gmf_migration.G_Table_name,
14211 					p_param2             =>       'Value Too Long Error',
14212 					p_param3             =>       l_too_long_error_count,
14213 					p_db_error           =>       NULL,
14214 					p_app_short_name     =>       'GMA'
14215 					);
14216 				END IF;
14217 				/*************************************
14218 				* Invalid Number Migration Error Log *
14219 				*************************************/
14220 				IF nvl(l_invalid_number_error_count,0) > 0 THEN
14221 					GMA_COMMON_LOGGING.gma_migration_central_log
14222 					(
14223 					p_run_id             =>       gmf_migration.G_migration_run_id,
14224 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
14225 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
14226 					p_table_name         =>       gmf_migration.G_Table_name,
14227 					p_context            =>       gmf_migration.G_Context,
14228 					p_token1             =>       'TABLE_NAME',
14229 					p_token2             =>       'COLUMN_NAME',
14230 					p_token3             =>       'RECORD_COUNT',
14231 					p_param1             =>       gmf_migration.G_Table_name,
14232 					p_param2             =>       'Invalid Number Error',
14233 					p_param3             =>       l_invalid_number_error_count,
14234 					p_db_error           =>       NULL,
14235 					p_app_short_name     =>       'GMA'
14236 					);
14237 				END IF;
14238         /********************************************
14239         * Records not picked up Migration Error Log *
14240         ********************************************/
14241         IF nvl(l_not_picked_up_error_count,0) > 0 THEN
14242           GMA_COMMON_LOGGING.gma_migration_central_log
14243           (
14244           p_run_id             =>       gmf_migration.G_migration_run_id,
14245           p_log_level          =>       FND_LOG.LEVEL_ERROR,
14246           p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
14247           p_table_name         =>       gmf_migration.G_Table_name,
14248           p_context            =>       gmf_migration.G_Context,
14249           p_token1             =>       'TABLE_NAME',
14250           p_token2             =>       'COLUMN_NAME',
14251           p_token3             =>       'RECORD_COUNT',
14252           p_param1             =>       gmf_migration.G_Table_name,
14253           p_param2             =>       'Records not Picked up Error',
14254           p_param3             =>       l_not_picked_up_error_count,
14255           p_db_error           =>       NULL,
14256           p_app_short_name     =>       'GMA'
14257           );
14258         END IF;
14259 				/***********************************
14260 				* Other Errors Migration Error Log *
14261 				***********************************/
14262 				IF nvl(l_total_error_count,0) - (
14263 																				nvl(l_unique_error_count,0) +
14264 																				nvl(l_not_null_error_count,0) +
14265 																				nvl(l_value_error_count,0) +
14266 																				nvl(l_parent_key_error_count,0) +
14267 																				nvl(l_invalid_number_error_count,0) +
14268                                         nvl(l_not_picked_up_error_count,0) +
14269 																				nvl(l_too_long_error_count,0)
14270 																				) > 0 THEN
14271 					GMA_COMMON_LOGGING.gma_migration_central_log
14272 					(
14273 					p_run_id             =>       gmf_migration.G_migration_run_id,
14274 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
14275 					p_message_token      =>       'GMA_MIGRATION_ERROR_ABSTRACT',
14276 					p_table_name         =>       gmf_migration.G_Table_name,
14277 					p_context            =>       gmf_migration.G_Context,
14278 					p_token1             =>       'TABLE_NAME',
14279 					p_token2             =>       'COLUMN_NAME',
14280 					p_token3             =>       'RECORD_COUNT',
14281 					p_param1             =>       gmf_migration.G_Table_name,
14282 					p_param2             =>       'Other Errors',
14283 					p_param3             =>       nvl(l_total_error_count,0) -  (
14284 																																			nvl(l_unique_error_count,0) +
14285 																																			nvl(l_not_null_error_count,0) +
14286 																																			nvl(l_value_error_count,0) +
14287 																																			nvl(l_parent_key_error_count,0) +
14288 																																			nvl(l_invalid_number_error_count,0) +
14289                                                                       nvl(l_not_picked_up_error_count,0) +
14290 																																			nvl(l_too_long_error_count,0)
14291 																																			),
14292 					p_db_error           =>       NULL,
14293 					p_app_short_name     =>       'GMA'
14294 					);
14295 				END IF;
14296 			ELSE
14297 				/**************************************
14298 				* Migration Success Log Message       *
14299 				**************************************/
14300 				GMA_COMMON_LOGGING.gma_migration_central_log
14301 				(
14302 				p_run_id             =>       gmf_migration.G_migration_run_id,
14303 				p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
14304 				p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
14305 				p_table_name         =>       gmf_migration.G_Table_name,
14306 				p_context            =>       gmf_migration.G_context,
14307 				p_param1             =>       1,
14308 				p_param2             =>       0,
14309 				p_db_error           =>       NULL,
14310 				p_app_short_name     =>       'GMA'
14311 				);
14312 			END IF;
14313 		ELSIF p_log_level = 3 THEN
14314 			IF l_error_tbl.count > 0 THEN
14315 				FOR i IN l_error_tbl.first..l_error_tbl.last LOOP
14316 					GMA_COMMON_LOGGING.gma_migration_central_log
14317 					(
14318 					p_run_id             =>       gmf_migration.G_migration_run_id,
14319 					p_log_level          =>       FND_LOG.LEVEL_ERROR,
14320 					p_message_token      =>       'GMA_MIGRATION_ERROR_DETAIL',
14321 					p_table_name         =>       gmf_migration.G_Table_name,
14322 					p_context            =>       gmf_migration.G_Context,
14323 					p_token1             =>       'TABLE_NAME',
14324 					p_token2             =>       'COLUMN_NAME',
14325 					p_token3             =>       'PARAMETERS',
14326 					p_token4             =>       'RECORD_COUNT',
14327 					p_param1             =>       l_error_tbl(i).table_name,
14328 					p_param2             =>       l_error_tbl(i).column_name,
14329 					p_param3             =>       l_error_tbl(i).parameters,
14330 					p_param4             =>       l_error_tbl(i).records,
14331 					p_db_error           =>       NULL,
14332 					p_app_short_name     =>       'GMA'
14333 					);
14334 				END LOOP;
14335 			ELSE
14336 				/**************************************
14337 				* Migration Success Log Message       *
14338 				**************************************/
14339 				GMA_COMMON_LOGGING.gma_migration_central_log
14340 				(
14341 				p_run_id             =>       gmf_migration.G_migration_run_id,
14342 				p_log_level          =>       FND_LOG.LEVEL_PROCEDURE,
14343 				p_message_token      =>       'GMA_MIGRATION_TABLE_SUCCESS',
14344 				p_table_name         =>       gmf_migration.G_Table_name,
14345 				p_context            =>       gmf_migration.G_context,
14346 				p_param1             =>       1,
14347 				p_param2             =>       0,
14348 				p_db_error           =>       NULL,
14349 				p_app_short_name     =>       'GMA'
14350 				);
14351 			END IF;
14352 		END IF;
14353 	END Log_Errors;
14354 
14355 	/**********************************************************************
14356 	* PROCEDURE:                                                          *
14357 	*   Migrate_Vendor Id                                                 *
14358 	*                                                                     *
14359 	* DESCRIPTION:                                                        *
14360 	*   This PL/SQL procedure is used to transform the Vendor Id          *
14361 	*   data in GL_ACCT_MAP                                               *
14362 	*                                                                     *
14363 	* PARAMETERS:                                                         *
14364 	*   P_migration_run_id - id to use to right to migration log          *
14365 	*   x_exception_count  - Number of exceptions occurred.               *
14366 	*                                                                     *
14367 	* SYNOPSIS:                                                           *
14368 	*   Migrate_Vendor_id(p_migartion_id    => l_migration_id,            *
14369 	*                    p_commit          => 'T',                        *
14370 	*                    x_exception_count => l_exception_count );        *
14371 	*                                                                     *
14372 	* HISTORY                                                             *
14373 	*       05-Oct-2006 Created  Anand Thiyagarajan                       *
14374   *       12-Oct-2006 Modified Anand Thiyagarajan                       *
14375   *         Stubbed PROCEDURE not to migrate records as this being done *
14376   *         in the ADR migration scripts itself                         *
14377 	*                                                                     *
14378 	**********************************************************************/
14379 	PROCEDURE Migrate_Vendor_id
14380 	(
14381 	P_migration_run_id      IN             NUMBER,
14382 	P_commit                IN             VARCHAR2,
14383 	X_failure_count         OUT   NOCOPY   NUMBER
14384 	)
14385 	IS
14386 		/****************
14387 		* PL/SQL Tables *
14388 		****************/
14389 
14390 		/******************
14391 		* Local Variables *
14392 		 ******************/
14393 
14394   BEGIN
14395 
14396     /****************************************************************************************
14397     * Commented the following code snippet to avoid migrating the records for vendor Id,    *
14398     * as the fetching of_vendor_site_id vendor_site_id is done ine the ADR migration script *
14399     * itself directly.                                                                      *
14400     ****************************************************************************************/
14401     /****************************************************************************************
14402 		G_Migration_run_id := P_migration_run_id;
14403 		G_Table_name := 'GL_ACCT_MAP';
14404 		G_Context := 'Vendor Id Migration';
14405 		X_failure_count := 0;
14406 
14407 		GMA_COMMON_LOGGING.gma_migration_central_log
14408 		(
14409 		p_run_id             =>       G_migration_run_id,
14410 		p_log_level          =>       FND_LOG.LEVEL_STATEMENT,
14411 		p_message_token      =>       'GMA_MIGRATION_TABLE_STARTED',
14412 		p_table_name         =>       G_table_name,
14413 		p_context            =>       G_context,
14414 		p_db_error           =>       NULL,
14415 		p_app_short_name     =>       'GMA'
14416 		);
14417 
14418 		UPDATE              gl_acct_map gam
14419 		SET                 gam.vendor_id
14420 		=                   (
14421 												SELECT        v.of_vendor_site_id
14422 												FROM          po_vend_mst v
14423 												WHERE         v.vendor_id = gam.vendor_id
14424 												),
14425                         gam.migrated_ind = 1
14426 		WHERE               gam.vendor_id IS NOT NULL
14427     AND                 nvl(gam.migrated_ind, -1) <> 1;
14428 
14429 		IF NVL(p_commit,'~') = FND_API.G_TRUE THEN
14430 			COMMIT;
14431 		END IF;
14432     ****************************************************************************************/
14433     NULL;
14434 
14435 	EXCEPTION
14436 		WHEN OTHERS THEN
14437 			/************************************************
14438 			* Increment Failure Count for Failed Migrations *
14439 			************************************************/
14440 			x_failure_count := x_failure_count + 1;
14441 
14442 			/**************************************
14443 			* Migration DB Error Log Message      *
14444 			**************************************/
14445 			GMA_COMMON_LOGGING.gma_migration_central_log
14446 			(
14447 			p_run_id             =>       G_migration_run_id,
14448 			p_log_level          =>       FND_LOG.LEVEL_ERROR,
14449 			p_message_token      =>       'GMA_MIGRATION_DB_ERROR',
14450 			p_table_name         =>       G_table_name,
14451 			p_context            =>       G_context,
14452 			p_db_error           =>       SQLERRM,
14453 			p_app_short_name     =>       'GMA'
14454 			);
14455 
14456 			/**************************************
14457 			* Migration Failure Log Message       *
14458 			**************************************/
14459 			GMA_COMMON_LOGGING.gma_migration_central_log
14460 			(
14461 			p_run_id             =>       G_migration_run_id,
14462 			p_log_level          =>       FND_LOG.LEVEL_ERROR,
14463 			p_message_token      =>       'GMA_TABLE_MIGRATION_TABLE_FAIL',
14464 			p_table_name         =>       G_table_name,
14465 			p_context            =>       G_context,
14466 			p_db_error           =>       NULL,
14467 			p_app_short_name     =>       'GMA'
14468 			);
14469 	END Migrate_Vendor_id;
14470 
14471 END GMF_MIGRATION;