DBA Data[Home] [Help]

PACKAGE BODY: APPS.GMD_NPD_MIGRATE

Source


1 PACKAGE BODY GMD_NPD_MIGRATE AS
2 /* $Header: GMDPDMGB.pls 120.6 2006/12/04 19:12:59 txdaniel noship $ */
3 
4 FUNCTION Get_Profile_Value(P_Profile_Name IN VARCHAR2) RETURN VARCHAR2;
5 
6 /*====================================================================
7 --  FUNCTION:
8 --    Get_Profile_Value
9 --
10 --  DESCRIPTION:
11 --    This is an internal function used to retrieve the site level
12 --    value of the the profile.
13 --
14 --  PARAMETERS:
15 --    p_profile_name    - Profile name to retrieve the value.
16 --
17 --  SYNOPSIS:
18 --    Get_Profile_Value(p_profile_name => 'GMD_FORMULA_VERSION_CONTROL');
19 --
20 --  HISTORY
21 --====================================================================*/
22 
23 FUNCTION Get_Profile_Value(P_Profile_Name IN VARCHAR2) RETURN VARCHAR2 IS
24 
25   /*  ------------- LOCAL VARIABLES ------------------- */
26   l_profile_value VARCHAR2(2000);
27 
28   /*  ------------------ CURSORS ---------------------- */
29   -- Get Site level profile values
30   CURSOR Cur_get_profile_value IS
31     SELECT PROFILE_OPTION_VALUE
32     FROM   Fnd_Profile_Options a, Fnd_Profile_Option_Values b
33     WHERE  a.Profile_Option_Id = b.Profile_Option_Id
34     AND    a.Profile_Option_Name = P_Profile_Name
35     AND    level_id = 10001;
36 
37 BEGIN
38 
39   OPEN Cur_get_profile_value;
40   FETCH Cur_get_profile_value INTO l_profile_value;
41   CLOSE Cur_get_profile_value;
42 
43   RETURN(l_profile_value);
44 
45 END Get_Profile_Value;
46 
47 
48 
49 /*====================================================================
50 --  PROCEDURE:
51 --    Migrate_Plant_Lab_Ind
52 --
53 --  DESCRIPTION:
54 --    This PL/SQL procedure is used to migrate the plant and lab
55 --    indicators to product development parameters.
56 --
57 --  PARAMETERS:
58 --    P_migration_run_id    - id to use to right to migration log
59 --    x_failure_count       - Number of failures occurred.
60 --
61 --  SYNOPSIS:
62 --    Migrate_Plant_Lab_Ind(p_migartion_id    => l_migration_id,
63 --			    P_commit	      => 'T',
64 --                          x_failure_count   => l_failure_count );
65 --
66 --  HISTORY
67 --    Added migrated_ind = 1 condition to fetch only those orgranizations
68 --    which are migrated.
69 --====================================================================*/
70 PROCEDURE Migrate_Plant_Lab_Ind (P_migration_run_id	IN NUMBER,
71                                  P_commit		IN VARCHAR2,
72                                  x_failure_count	OUT NOCOPY NUMBER) IS
73 
74   /*  ------------- LOCAL VARIABLES ------------------- */
75   l_parameter_id		NUMBER(15);
76   l_rowid			VARCHAR2(80);
77   l_exists 			NUMBER(1);
78   l_migrate_count		NUMBER(5) DEFAULT 0;
79   l_lab_ind			NUMBER := 0;
80   l_plant_ind			NUMBER := 0;
81 
82   /*  ------------------ CURSORS ---------------------- */
83   CURSOR Cur_get_plant_lab_ind IS
84     SELECT orgn_code, plant_ind, organization_id, created_by,
85            Last_updated_by, creation_date, last_update_date,
86            Last_update_login
87     FROM   sy_orgn_mst
88     WHERE  plant_ind > 0
89     AND    delete_mark = 0
90     AND    migrated_ind = 1;
91 
92   CURSOR Cur_check_existence (V_organization_id NUMBER) IS
93     SELECT 1
94     FROM   sys.dual
95     WHERE  EXISTS (SELECT 1
96                    FROM   gmd_parameters_hdr
97                    WHERE  organization_id = V_organization_id);
98 
99   CURSOR Cur_get_new_parameter_id IS
100     SELECT GMD_Parameter_Id_S.nextval
101     FROM dual;
102 
103   /*  --------EXCEPTIONS ------------- */
104   ORG_NOT_MIGRATED      EXCEPTION;
105 
106 BEGIN
107 
108   X_failure_count := 0;
109 
110   GMA_COMMON_LOGGING.gma_migration_central_log (
111        p_run_id          => P_migration_run_id,
112        p_log_level       => FND_LOG.LEVEL_PROCEDURE,
113        p_message_token   => 'GMA_MIGRATION_TABLE_STARTED',
114        p_table_name      => 'GMD_PARAMETERS',
115        p_context         => 'PROFILES',
116        p_param1          => NULL,
117        p_param2          => NULL,
118        p_param3          => NULL,
119        p_param4          => NULL,
120        p_param5          => NULL,
121        p_db_error        => NULL,
122        p_app_short_name  => 'GMD');
123 
124   /* Fetch the migrated organization record for updating the indicators */
125   FOR l_rec IN Cur_get_plant_lab_ind LOOP
126     BEGIN
127       /* Check the id column to determine if the org has migrated */
128       IF l_rec.organization_id IS NULL THEN
129         RAISE ORG_NOT_MIGRATED;
130       END IF;
131       /* Lets check if the org record already exists */
132       OPEN Cur_check_existence (l_rec.organization_id);
133       FETCH Cur_check_existence INTO l_exists;
134       IF Cur_check_existence%NOTFOUND THEN
135 
136 	OPEN Cur_get_new_parameter_id;
137 	FETCH Cur_get_new_parameter_id INTO l_Parameter_Id;
138 	CLOSE Cur_get_new_parameter_id;
139 
140         /*Bug5695948- Reset the plant or lab indicator */
141         l_plant_ind := 0;
142         l_lab_ind := 0;
143 
144 	/* Get Plant and Lab Indicator values */
145 	IF l_rec.plant_ind = 1 THEN
146 		l_plant_ind  := 1;
147         ELSIF  l_rec.plant_ind = 2 THEN
148 		l_lab_ind  := 1;
149         END IF;
150 
151         /* Lets create the parameter record for the organization */
152         GMD_PARAMETERS_HDR_PKG.Insert_Row
153           (X_rowid		=> l_rowid,
154            X_Parameter_Id	=> l_Parameter_Id,
155            X_organization_id	=> l_rec.organization_id,
156            X_Lab_Ind		=> l_lab_ind,
157            X_plant_Ind		=> l_plant_ind,
158            X_creation_date	=> l_rec.creation_date,
159            X_created_by		=> l_rec.created_by,
160            X_last_update_date	=> l_rec.last_update_date,
161            X_last_updated_by	=> l_rec.last_updated_by,
162            X_last_update_login	=> l_rec.last_update_login);
163 
164         /* Lets save the changes now based on the commit parameter*/
165         IF p_commit = 'Y' THEN
166           COMMIT;
167         END IF;
168         L_migrate_count := L_migrate_count + 1;
169       END IF;
170       CLOSE Cur_check_existence;
171     EXCEPTION
172       WHEN Org_Not_Migrated THEN
173         X_failure_count := X_failure_count + 1;
174 
175         GMA_COMMON_LOGGING.gma_migration_central_log (
176           p_run_id          => P_migration_run_id,
177           p_log_level       => FND_LOG.LEVEL_ERROR,
178           p_message_token   => 'GMD_ORG_NOT_MIGRATED',
179           p_table_name      => 'GMD_PARAMETERS',
180           p_context         => 'PROFILES',
181           p_param1          => l_rec.orgn_code,
182           p_param2          => NULL,
183           p_param3          => NULL,
184           p_param4          => NULL,
185           p_param5          => NULL,
186           p_db_error        => NULL,
187           p_app_short_name  => 'GMD');
188 
189       WHEN OTHERS THEN
190         x_failure_count := x_failure_count + 1;
191 
192         GMA_COMMON_LOGGING.gma_migration_central_log (
193           p_run_id          => P_migration_run_id,
194           p_log_level       => FND_LOG.LEVEL_UNEXPECTED,
195           p_message_token   => 'GMA_MIGRATION_DB_ERROR',
196           p_table_name      => 'GMD_PARAMETERS',
197           p_context         => 'PROFILES',
198           p_param1          => NULL,
199           p_param2          => NULL,
200           p_param3          => NULL,
201           p_param4          => NULL,
202           p_param5          => NULL,
203           p_db_error        => SQLERRM,
204           p_app_short_name  => 'GMD');
205     END;
206   END LOOP;
207 
208   IF (p_commit = FND_API.G_TRUE) THEN
209    COMMIT;
210   END IF;
211 
212   GMA_COMMON_LOGGING.gma_migration_central_log (
213        p_run_id          => P_migration_run_id,
214        p_log_level       => FND_LOG.LEVEL_PROCEDURE,
215        p_message_token   => 'GMA_MIGRATION_TABLE_SUCCESS',
216        p_table_name      => 'GMD_PARAMETERS',
217        p_context         => 'PROFILES',
218        p_param1          => l_migrate_count,
219        p_param2          => X_failure_count,
220        p_param3          => NULL,
221        p_param4          => NULL,
222        p_param5          => NULL,
223        p_db_error        => NULL,
224        p_app_short_name  => 'GMD');
225 
226 EXCEPTION
227   WHEN OTHERS THEN
228     x_failure_count := x_failure_count + 1;
229 
230     GMA_COMMON_LOGGING.gma_migration_central_log (
231           p_run_id          => P_migration_run_id,
232           p_log_level       => FND_LOG.LEVEL_UNEXPECTED,
233           p_message_token   => 'GMA_MIGRATION_DB_ERROR',
234           p_table_name      => 'GMD_PARAMETERS',
235           p_context         => 'PROFILES',
236           p_param1          => l_migrate_count,
237           p_param2          => x_failure_count,
238           p_param3          => NULL,
239           p_param4          => NULL,
240           p_param5          => NULL,
241           p_db_error        => SQLERRM,
242           p_app_short_name  => 'GMD');
243 
244     GMA_COMMON_LOGGING.gma_migration_central_log (
245           p_run_id          => P_migration_run_id,
246           p_log_level       => FND_LOG.LEVEL_PROCEDURE,
247           p_message_token   => 'GMA_TABLE_MIGRATION_TABLE_FAIL',
248           p_table_name      => 'GMD_PARAMETERS',
249           p_context         => 'PROFILES',
250           p_param1          => l_migrate_count,
251           p_param2          => x_failure_count,
252           p_param3          => NULL,
253           p_param4          => NULL,
254           p_param5          => NULL,
255           p_db_error        => NULL,
256           p_app_short_name  => 'GMD');
257 
258 END Migrate_Plant_Lab_Ind;
259 
260 /*====================================================================
261 --  PROCEDURE:
262 --    Migrate_Profiles
263 --
264 --  DESCRIPTION:
265 --    This PL/SQL procedure is used to migrate the profile values as
266 --    product development parameters.
267 --
268 --    The following parameters are migrated from Site Level (pre-convergence)
269 --    to Global Orgn. level (post-convergence)
270 --
271 --    Formula Parameters
272 --    GMD: Formula Version Control
273 --    GMD: Byproduct Active
274 --    GMD: Allow Zero Ingredient Qty
275 --    GMD: Mass UOM Type
276 --    GMD: Volume UOM Type
277 --    GMD: Yield Type
278 --
279 --    Operation Parameter(s)
280 --    GMD: Operation Version Control
281 --
282 --    Routing Parameters
283 --    GMD: Routing Version Control
284 --    GMD: Enforce Step Dependency
285 --    GMD: Default Step Release Type
286 --
287 --    Recipe Parameters
288 --    GMD: Recipe Version Control
289 --    GMD: Process Instruction Paragraph
290 --
291 --  PARAMETERS:
292 --    P_migration_run_id - id to use to right to migration log
293 --    x_failure_count       - Number of failures occurred.
294 --
295 --  SYNOPSIS:
296 --    Migrate_Profiles(p_migartion_id    => l_migration_id,
297 --                     p_commit          => 'T',
298 --                     x_failure_count   => l_failure_count );
299 --
300 --  HISTORY
301 --====================================================================*/
302 
303 PROCEDURE Migrate_Profiles (P_migration_run_id	IN NUMBER,
304                             P_commit		IN VARCHAR2,
305                             X_failure_count	OUT NOCOPY NUMBER) IS
306 
307   /*  ------------- LOCAL VARIABLES ------------------- */
308   l_parameter_id		NUMBER(15)	;
309   l_rowid			VARCHAR2(80)	;
310   l_profile_value		VARCHAR2(80)	;
311   l_exists			NUMBER(5)	;
312   l_new				NUMBER(5) DEFAULT 0;
313   l_parameter_line_id		NUMBER;
314   l_migrate_count		NUMBER;
315 
316   /*  ------------------ CURSORS ---------------------- */
317   CURSOR Cur_get_parameter_id IS
318     SELECT parameter_id
319     FROM   gmd_parameters_hdr
320     WHERE  organization_id IS NULL;
321 
322   CURSOR Cur_check_parameter_exists (V_parameter_id NUMBER,
323                                      V_parameter VARCHAR2) IS
324     SELECT 1
325     FROM   sys.dual
326     WHERE  EXISTS (SELECT 1
327                    FROM   gmd_parameters_dtl
328                    WHERE  parameter_id = V_parameter_id
329                    AND    parameter_name = V_parameter);
330 
331   CURSOR Cur_get_new_parameter_id IS
332 	SELECT GMD_Parameter_Id_S.nextval
333 	FROM dual;
334 
335   CURSOR Cur_get_new_parameter_line_id IS
336 	SELECT GMD_Parameter_Line_Id_S.nextval
337 	FROM dual;
338 
339 BEGIN
340 
341   X_failure_count := 0;
342   l_migrate_count := 0;
343 
344      GMA_COMMON_LOGGING.gma_migration_central_log (
345        p_run_id          => P_migration_run_id,
346        p_log_level       => FND_LOG.LEVEL_PROCEDURE,
347        p_message_token   => 'GMA_MIGRATION_TABLE_STARTED',
348        p_table_name      => 'GMD_PARAMETERS',
349        p_context         => 'PROFILES',
350        p_param1          => NULL,
351        p_param2          => NULL,
352        p_param3          => NULL,
353        p_param4          => NULL,
354        p_param5          => NULL,
355        p_db_error        => NULL,
356        p_app_short_name  => 'GMD');
357 
358 
359     /* Check if the header record exists */
360     OPEN Cur_get_parameter_id;
361     FETCH Cur_get_parameter_id INTO l_parameter_id;
362     IF Cur_get_parameter_id%NOTFOUND THEN
363       /* Fetch the surrogate key value for parameter header */
364 	OPEN Cur_get_new_parameter_id;
365 	FETCH Cur_get_new_parameter_id INTO l_Parameter_Id;
366 	CLOSE Cur_get_new_parameter_id;
367 
368       L_new := 1;
369 
370 	/*Insert a row into the header table for Global organization */
371 	GMD_PARAMETERS_HDR_PKG.Insert_Row (	X_rowid			=> l_rowid,
372 						X_Parameter_Id		=> l_parameter_id,
373 						X_organization_id	=> NULL,
374 						X_Lab_Ind		=> 0,
375 						X_plant_Ind		=> 0,
376 						X_creation_date		=> SYSDATE,
377 						X_created_by		=> 0,
378 						X_last_update_date	=> SYSDATE,
379 						X_last_updated_by	=> 0,
380 						X_last_update_login	=> NULL);
381     END IF;
382     CLOSE Cur_get_parameter_id;
383 
384 
385   /* Logging the start of the migration*/
386   GMA_COMMON_LOGGING.gma_migration_central_log (
387        p_run_id          => P_migration_run_id,
388        p_log_level       => FND_LOG.LEVEL_EVENT,
389        p_message_token   => 'GMA_MIGRATION_STARTED',
390        p_table_name      => 'GMD_PARAMETERS',
391        p_context         => 'PROFILES',
392        p_param1          => NULL,
393        p_param2          => NULL,
394        p_param3          => NULL,
395        p_param4          => NULL,
396        p_param5          => NULL,
397        p_db_error        => NULL,
398        p_app_short_name  => 'GMD');
399 
400   -- L_parameter_id := GMD_Parameter_Id_S.nextval; ???
401 
402 
403 /* Migration of Formula Parameters */
404 
405   /* Check if the formula version control profile value exists*/
406 IF l_new = 1 THEN
407   L_exists := 0;
408 ELSE
409   OPEN Cur_check_parameter_exists (l_parameter_id,
410                                    'GMD_FORMULA_VERSION_CONTROL');
411   FETCH Cur_check_parameter_exists INTO l_exists;
412   IF Cur_check_parameter_exists%NOTFOUND THEN
413     L_exists := 0;
414   ELSE
415     L_exists := 1;
416   END IF;
417   CLOSE Cur_check_parameter_exists;
418 END IF;
419 
420 IF l_exists = 0 THEN
421   /* Fetch the formula version control profile value */
422   l_profile_value := NULL;
423   l_profile_value :=
424       Get_Profile_Value('GMD_FORMULA_VERSION_CONTROL');
425   IF l_profile_value IS NOT NULL THEN
426 
427     OPEN Cur_get_new_parameter_line_id;
428     FETCH Cur_get_new_parameter_line_id INTO l_Parameter_line_Id;
429     CLOSE Cur_get_new_parameter_line_id;
430 
431     GMD_Parameters_Dtl_Pkg.Insert_Row
432     (	X_rowid			=> l_rowid,
433 	X_parameter_line_id	=> l_Parameter_line_Id,
434 	X_parameter_id		=> l_parameter_id,
435 	X_parm_Type		=> 1,
436 	X_parameter_name	=> 'GMD_FORMULA_VERSION_CONTROL',
437 	X_parameter_value	=> l_profile_value,
438 	X_creation_date		=> SYSDATE,
439 	X_created_by		=> 0,
440 	X_last_update_date	=> SYSDATE,
441 	X_last_updated_by	=> 0,
442 	X_last_update_login	=> NULL);
443 
444    l_migrate_count := l_migrate_count + 1;
445   END IF;
446 END IF;
447 
448 /* Check if the By Product Active profile value exists*/
449 IF l_new = 1 THEN
450   L_exists := 0;
451 ELSE
452   OPEN Cur_check_parameter_exists (l_parameter_id,
453                                    'FM$BYPROD_ACTIVE');
454   FETCH Cur_check_parameter_exists INTO l_exists;
455   IF Cur_check_parameter_exists%NOTFOUND THEN
456     L_exists := 0;
457   ELSE
458     L_exists := 1;
459   END IF;
460   CLOSE Cur_check_parameter_exists;
461 END IF;
462 
463 IF l_exists = 0 THEN
464   /* Fetch the By Product Active profile value */
465   l_profile_value := NULL;
466   l_profile_value :=  Get_Profile_Value('FM$BYPROD_ACTIVE');
467   IF l_profile_value IS NOT NULL THEN
468 
469     OPEN Cur_get_new_parameter_line_id;
470     FETCH Cur_get_new_parameter_line_id INTO l_Parameter_line_Id;
471     CLOSE Cur_get_new_parameter_line_id;
472 
473     GMD_Parameters_Dtl_Pkg.Insert_Row
474     (	X_rowid			=> l_rowid,
475 	X_parameter_line_id	=> l_Parameter_line_Id,
476 	X_parameter_id		=> l_parameter_id,
477 	X_parm_Type		=> 1,
478 	X_parameter_name	=> 'GMD_BYPRODUCT_ACTIVE',
479 	X_parameter_value	=> l_profile_value,
480 	X_creation_date		=> SYSDATE,
481 	X_created_by		=> 0,
482 	X_last_update_date	=> SYSDATE,
483 	X_last_updated_by	=> 0,
484 	X_last_update_login	=> NULL);
485    l_migrate_count := l_migrate_count + 1;
486   END IF;
487 END IF;
488 
489 
490 
491 /* Check if the Allow Zero Ingredient Qty profile value exists*/
492 IF l_new = 1 THEN
493   L_exists := 0;
494 ELSE
495   OPEN Cur_check_parameter_exists (l_parameter_id,
496                                    'GMD_ZERO_INGREDIENT_QTY');
497   FETCH Cur_check_parameter_exists INTO l_exists;
498   IF Cur_check_parameter_exists%NOTFOUND THEN
499     L_exists := 0;
500   ELSE
501     L_exists := 1;
502   END IF;
503   CLOSE Cur_check_parameter_exists;
504 END IF;
505 
506 IF l_exists = 0 THEN
507   /* Fetch the Allow Zero Ingredient Qty profile value */
508   l_profile_value := NULL;
509   l_profile_value :=  Get_Profile_Value('FM$ALLOW_ZERO_INGR_QTY');
510   IF l_profile_value IS NOT NULL THEN
511 
512     OPEN Cur_get_new_parameter_line_id;
513     FETCH Cur_get_new_parameter_line_id INTO l_Parameter_line_Id;
514     CLOSE Cur_get_new_parameter_line_id;
515 
516     GMD_Parameters_Dtl_Pkg.Insert_Row
517     (	X_rowid			=> l_rowid,
518 	X_parameter_line_id	=> l_parameter_line_id,
519 	X_parameter_id		=> l_parameter_id,
520 	X_parm_Type		=> 1,
521 	X_parameter_name	=> 'GMD_ZERO_INGREDIENT_QTY',
522 	X_parameter_value	=> l_profile_value,
523 	X_creation_date		=> SYSDATE,
524 	X_created_by		=> 0,
525 	X_last_update_date	=> SYSDATE,
526 	X_last_updated_by	=> 0,
527 	X_last_update_login	=> NULL);
528    l_migrate_count := l_migrate_count + 1;
529   END IF;
530 END IF;
531 
532 
533 /* Check if the Mass UOM profile value exists*/
534 IF l_new = 1 THEN
535   L_exists := 0;
536 ELSE
537   OPEN Cur_check_parameter_exists (l_parameter_id,
538                                    'GMD_MASS_UM_TYPE');
539   FETCH Cur_check_parameter_exists INTO l_exists;
540   IF Cur_check_parameter_exists%NOTFOUND THEN
541     l_exists := 0;
542   ELSE
543     l_exists := 1;
544   END IF;
545   CLOSE Cur_check_parameter_exists;
546 END IF;
547 
548 IF l_exists = 0 THEN
549   /* Fetch the Mass UOM profile value */
550   l_profile_value := NULL;
551   l_profile_value :=  Get_Profile_Value('LM$UOM_MASS_TYPE');
552   IF l_profile_value IS NOT NULL THEN
553 
554     OPEN Cur_get_new_parameter_line_id;
555     FETCH Cur_get_new_parameter_line_id INTO l_Parameter_line_Id;
556     CLOSE Cur_get_new_parameter_line_id;
557 
558     GMD_Parameters_Dtl_Pkg.Insert_Row
559     (	X_rowid			=> l_rowid,
560 	X_parameter_line_id	=> l_parameter_line_id,
561 	X_parameter_id		=> l_parameter_id,
562 	X_parm_Type		=> 1,
563 	X_parameter_name	=> 'GMD_MASS_UM_TYPE',
564 	X_parameter_value	=> l_profile_value,
565 	X_creation_date		=> SYSDATE,
566 	X_created_by		=> 0,
567 	X_last_update_date	=> SYSDATE,
568 	X_last_updated_by	=> 0,
569 	X_last_update_login	=> NULL);
570    l_migrate_count := l_migrate_count + 1;
571   END IF;
572 END IF;
573 
574 /* Check if the Volume UOM profile value exists*/
575 IF l_new = 1 THEN
576   L_exists := 0;
577 ELSE
578   OPEN Cur_check_parameter_exists (l_parameter_id,
579                                    'GMD_VOLUME_UM_TYPE');
580   FETCH Cur_check_parameter_exists INTO l_exists;
581   IF Cur_check_parameter_exists%NOTFOUND THEN
582     L_exists := 0;
583   ELSE
584     L_exists := 1;
585   END IF;
586   CLOSE Cur_check_parameter_exists;
587 END IF;
588 
589 IF l_exists = 0 THEN
590   /* Fetch the Volume UOM profile value */
591   l_profile_value := NULL;
592   l_profile_value :=  Get_Profile_Value('LM$UOM_VOLUME_TYPE');
593   IF l_profile_value IS NOT NULL THEN
594 
595     OPEN Cur_get_new_parameter_line_id;
596     FETCH Cur_get_new_parameter_line_id INTO l_Parameter_line_Id;
597     CLOSE Cur_get_new_parameter_line_id;
598 
599     GMD_Parameters_Dtl_Pkg.Insert_Row
600     (	X_rowid			=> l_rowid,
601 	X_parameter_line_id	=> l_parameter_line_id,
602 	X_parameter_id		=> l_parameter_id,
603 	X_parm_Type		=> 1,
604 	X_parameter_name	=> 'GMD_VOLUME_UM_TYPE',
605 	X_parameter_value	=> l_profile_value,
606 	X_creation_date		=> SYSDATE,
607 	X_created_by		=> 0,
608 	X_last_update_date	=> SYSDATE,
609 	X_last_updated_by	=> 0,
610 	X_last_update_login	=> NULL);
611    l_migrate_count := l_migrate_count + 1;
612   END IF;
613 END IF;
614 
615 /* Check if the Yield Type profile value exists*/
616 IF l_new = 1 THEN
617   l_exists := 0;
618 ELSE
619   OPEN Cur_check_parameter_exists (l_parameter_id,
620                                    'FM_YIELD_TYPE');
621   FETCH Cur_check_parameter_exists INTO l_exists;
622   IF Cur_check_parameter_exists%NOTFOUND THEN
623     l_exists := 0;
624   ELSE
625     l_exists := 1;
626   END IF;
627   CLOSE Cur_check_parameter_exists;
628 END IF;
629 
630 IF l_exists = 0 THEN
631   /* Fetch the Yield Type profile value */
632   l_profile_value := NULL;
633   l_profile_value :=  Get_Profile_Value('FM_YIELD_TYPE');
634   IF l_profile_value IS NOT NULL THEN
635 
636     OPEN Cur_get_new_parameter_line_id;
637     FETCH Cur_get_new_parameter_line_id INTO l_Parameter_line_Id;
638     CLOSE Cur_get_new_parameter_line_id;
639 
640     GMD_Parameters_Dtl_Pkg.Insert_Row
641     (	X_rowid			=> l_rowid,
642 	X_parameter_line_id	=> l_parameter_line_id,
643 	X_parameter_id		=> l_parameter_id,
644 	X_parm_Type		=> 1,
645 	X_parameter_name	=> 'FM_YIELD_TYPE',
646 	X_parameter_value	=> l_profile_value,
647 	X_creation_date		=> SYSDATE,
648 	X_created_by		=> 0,
649 	X_last_update_date	=> SYSDATE,
650 	X_last_updated_by	=> 0,
651 	X_last_update_login	=> NULL);
652    l_migrate_count := l_migrate_count + 1;
653   END IF;
654 END IF;
655 
656 
657 /* Check if the Default Release Type profile value exists*/
658 IF l_new = 1 THEN
659   l_exists := 0;
660 ELSE
661   OPEN Cur_check_parameter_exists (l_parameter_id,
662                                    'FM$DEFAULT_RELEASE_TYPE');
663   FETCH Cur_check_parameter_exists INTO l_exists;
664   IF Cur_check_parameter_exists%NOTFOUND THEN
665     l_exists := 0;
666   ELSE
667     l_exists := 1;
668   END IF;
669   CLOSE Cur_check_parameter_exists;
670 END IF;
671 
672 IF l_exists = 0 THEN
673   /* Fetch the Default Release Type profile value */
674   l_profile_value := NULL;
675   l_profile_value :=  Get_Profile_Value('FM$DEFAULT_RELEASE_TYPE');
676   IF l_profile_value IS NOT NULL THEN
677 
678     OPEN Cur_get_new_parameter_line_id;
679     FETCH Cur_get_new_parameter_line_id INTO l_Parameter_line_Id;
680     CLOSE Cur_get_new_parameter_line_id;
681 
682     GMD_Parameters_Dtl_Pkg.Insert_Row
683     (	X_rowid			=> l_rowid,
684 	X_parameter_line_id	=> l_parameter_line_id,
685 	X_parameter_id		=> l_parameter_id,
686 	X_parm_Type		=> 1,
687 	X_parameter_name	=> 'FM$DEFAULT_RELEASE_TYPE',
688 	X_parameter_value	=> l_profile_value,
689 	X_creation_date		=> SYSDATE,
690 	X_created_by		=> 0,
691 	X_last_update_date	=> SYSDATE,
692 	X_last_updated_by	=> 0,
693 	X_last_update_login	=> NULL);
694    l_migrate_count := l_migrate_count + 1;
695   END IF;
696 END IF;
697 
698 /* END - Migration of Formula Parameters */
699 
700 
701 /* Migration of Recipe Parameters */
702 
703 /* Check if the Recipe Version Control profile value exists*/
704 IF l_new = 1 THEN
705   L_exists := 0;
706 ELSE
707   OPEN Cur_check_parameter_exists (l_parameter_id,
708                                    'GMD_RECIPE_VERSION_CONTROL');
709   FETCH Cur_check_parameter_exists INTO l_exists;
710   IF Cur_check_parameter_exists%NOTFOUND THEN
711     l_exists := 0;
712   ELSE
713     l_exists := 1;
714   END IF;
715   CLOSE Cur_check_parameter_exists;
716 END IF;
717 
718 IF l_exists = 0 THEN
719   /* Fetch the Recipe Version Control profile value */
720   l_profile_value := NULL;
721   l_profile_value :=  Get_Profile_Value('GMD_RECIPE_VERSION_CONTROL');
722   IF l_profile_value IS NOT NULL THEN
723 
724     OPEN Cur_get_new_parameter_line_id;
725     FETCH Cur_get_new_parameter_line_id INTO l_Parameter_line_Id;
726     CLOSE Cur_get_new_parameter_line_id;
727 
728     GMD_Parameters_Dtl_Pkg.Insert_Row
729     (	X_rowid			=> l_rowid,
730 	X_parameter_line_id	=> l_parameter_line_id,
731 	X_parameter_id		=> l_parameter_id,
732 	X_parm_Type		=> 4,
733 	X_parameter_name	=> 'GMD_RECIPE_VERSION_CONTROL',
734 	X_parameter_value	=> l_profile_value,
735 	X_creation_date		=> SYSDATE,
736 	X_created_by		=> 0,
737 	X_last_update_date	=> SYSDATE,
738 	X_last_updated_by	=> 0,
739 	X_last_update_login	=> NULL);
740    l_migrate_count := l_migrate_count + 1;
741   END IF;
742 END IF;
743 
744 /* Check if the Process Instruction Paragraph profile value exists*/
745 IF l_new = 1 THEN
746   L_exists := 0;
747 ELSE
748   OPEN Cur_check_parameter_exists (l_parameter_id,
749                                    'GMD_PROC_INSTR_PARAGRAPH');
750   FETCH Cur_check_parameter_exists INTO l_exists;
751   IF Cur_check_parameter_exists%NOTFOUND THEN
752     L_exists := 0;
753   ELSE
754     L_exists := 1;
755   END IF;
756   CLOSE Cur_check_parameter_exists;
757 END IF;
758 
759 IF l_exists = 0 THEN
760   /* Fetch the Process Instruction Paragraph profile value */
761   l_profile_value := NULL;
762   l_profile_value :=  Get_Profile_Value('GMD_PROC_INSTR_PARAGRAPH');
763   IF l_profile_value IS NOT NULL THEN
764 
765     OPEN Cur_get_new_parameter_line_id;
766     FETCH Cur_get_new_parameter_line_id INTO l_Parameter_line_Id;
767     CLOSE Cur_get_new_parameter_line_id;
768 
769     GMD_Parameters_Dtl_Pkg.Insert_Row
770     (	X_rowid			=> l_rowid,
771 	X_parameter_line_id	=> l_parameter_line_id,
772 	X_parameter_id		=> l_parameter_id,
773 	X_parm_Type		=> 4,
774 	X_parameter_name	=> 'GMD_PROC_INSTR_PARAGRAPH',
775 	X_parameter_value	=> l_profile_value,
776 	X_creation_date		=> SYSDATE,
777 	X_created_by		=> 0,
778 	X_last_update_date	=> SYSDATE,
779 	X_last_updated_by	=> 0,
780 	X_last_update_login	=> NULL);
781    l_migrate_count := l_migrate_count + 1;
782   END IF;
783 END IF;
784 
785 /* END - Migration of Recipe Parameters */
786 
787 
788 /* Migration of Operation Parameters */
789 
790 /* Check if the Operation Version Control profile value exists*/
791 IF l_new = 1 THEN
792   L_exists := 0;
793 ELSE
794   OPEN Cur_check_parameter_exists (l_parameter_id,
795                                    'GMD_OPERATION_VERSION_CONTROL');
796   FETCH Cur_check_parameter_exists INTO l_exists;
797   IF Cur_check_parameter_exists%NOTFOUND THEN
798     L_exists := 0;
799   ELSE
800     L_exists := 1;
801   END IF;
802   CLOSE Cur_check_parameter_exists;
803 END IF;
804 
805 IF l_exists = 0 THEN
806   /* Fetch the Operation Version Control profile value */
807   l_profile_value := NULL;
808   l_profile_value :=  Get_Profile_Value('GMD_OPERATION_VERSION_CONTROL');
809   IF l_profile_value IS NOT NULL THEN
810 
811     OPEN Cur_get_new_parameter_line_id;
812     FETCH Cur_get_new_parameter_line_id INTO l_Parameter_line_Id;
813     CLOSE Cur_get_new_parameter_line_id;
814 
815     GMD_Parameters_Dtl_Pkg.Insert_Row
816     (	X_rowid			=> l_rowid,
817 	X_parameter_line_id	=> l_parameter_line_id,
818 	X_parameter_id		=> l_parameter_id,
819 	X_parm_Type		=> 2,
820 	X_parameter_name	=> 'GMD_OPERATION_VERSION_CONTROL',
821 	X_parameter_value	=> l_profile_value,
822 	X_creation_date		=> SYSDATE,
823 	X_created_by		=> 0,
824 	X_last_update_date	=> SYSDATE,
825 	X_last_updated_by	=> 0,
826 	X_last_update_login	=> NULL);
827    l_migrate_count := l_migrate_count + 1;
828   END IF;
829 END IF;
830 
831 /* END - Migration of Operation Parameters */
832 
833 
834 /* Migration of Routing Parameters */
835 
836 /* Check if the Routing Version Control profile value exists*/
837 IF l_new = 1 THEN
838   L_exists := 0;
839 ELSE
840   OPEN Cur_check_parameter_exists (l_parameter_id,
841                                    'GMD_ROUTING_VERSION_CONTROL');
842   FETCH Cur_check_parameter_exists INTO l_exists;
843   IF Cur_check_parameter_exists%NOTFOUND THEN
844     L_exists := 0;
845   ELSE
846     L_exists := 1;
847   END IF;
848   CLOSE Cur_check_parameter_exists;
849 END IF;
850 
851 IF l_exists = 0 THEN
852   /* Fetch the Routing Version Control profile value */
853   l_profile_value := NULL;
854   l_profile_value :=  Get_Profile_Value('GMD_ROUTING_VERSION_CONTROL');
855   IF l_profile_value IS NOT NULL THEN
856 
857     OPEN Cur_get_new_parameter_line_id;
858     FETCH Cur_get_new_parameter_line_id INTO l_Parameter_line_Id;
859     CLOSE Cur_get_new_parameter_line_id;
860 
861     GMD_Parameters_Dtl_Pkg.Insert_Row
862     (	X_rowid			=> l_rowid,
863 	X_parameter_line_id	=> l_parameter_line_id,
864 	X_parameter_id		=> l_parameter_id,
865 	X_parm_Type		=> 3,
866 	X_parameter_name	=> 'GMD_ROUTING_VERSION_CONTROL',
867 	X_parameter_value	=> l_profile_value,
868 	X_creation_date		=> SYSDATE,
869 	X_created_by		=> 0,
870 	X_last_update_date	=> SYSDATE,
871 	X_last_updated_by	=> 0,
872 	X_last_update_login	=> NULL);
873    l_migrate_count := l_migrate_count + 1;
874   END IF;
875 END IF;
876 
877 /* Check if the Enforce Step Dependency profile value exists*/
878 IF l_new = 1 THEN
879   L_exists := 0;
880 ELSE
881   OPEN Cur_check_parameter_exists (l_parameter_id,
882                                    'GMD_ENFORCE_STEP_DEPENDENCY');
883   FETCH Cur_check_parameter_exists INTO l_exists;
884   IF Cur_check_parameter_exists%NOTFOUND THEN
885     L_exists := 0;
886   ELSE
887     L_exists := 1;
888   END IF;
889   CLOSE Cur_check_parameter_exists;
890 END IF;
891 
892 IF l_exists = 0 THEN
893   /* Fetch the Enforce Step Dependency profile value */
894   l_profile_value := NULL;
895   l_profile_value :=  Get_Profile_Value('GMD_ENFORCE_STEP_DEPENDENCY');
896   IF l_profile_value IS NOT NULL THEN
897 
898     OPEN Cur_get_new_parameter_line_id;
899     FETCH Cur_get_new_parameter_line_id INTO l_Parameter_line_Id;
900     CLOSE Cur_get_new_parameter_line_id;
901 
902     GMD_Parameters_Dtl_Pkg.Insert_Row
903     (	X_rowid			=> l_rowid,
904 	X_parameter_line_id	=> l_parameter_line_id,
905 	X_parameter_id		=> l_parameter_id,
906 	X_parm_Type		=> 3,
907 	X_parameter_name	=> 'GMD_ENFORCE_STEP_DEPENDENCY',
908 	X_parameter_value	=> l_profile_value,
909 	X_creation_date		=> SYSDATE,
910 	X_created_by		=> 0,
911 	X_last_update_date	=> SYSDATE,
912 	X_last_updated_by	=> 0,
913 	X_last_update_login	=> NULL);
914    l_migrate_count := l_migrate_count + 1;
915   END IF;
916 END IF;
917 
918 
919 /* Check if the Default Step Release type profile value exists*/
920 IF l_new = 1 THEN
921   L_exists := 0;
922 ELSE
923   OPEN Cur_check_parameter_exists (l_parameter_id,
924                                    'GMD_DEFAULT_STEP_RELEASE_TYPE');
925   FETCH Cur_check_parameter_exists INTO l_exists;
926   IF Cur_check_parameter_exists%NOTFOUND THEN
927     L_exists := 0;
928   ELSE
929     L_exists := 1;
930   END IF;
931   CLOSE Cur_check_parameter_exists;
932 END IF;
933 
934 IF l_exists = 0 THEN
935   /* Fetch the Default Step Release type profile value */
936   l_profile_value := NULL;
937   l_profile_value :=  Get_Profile_Value('GMD_DEFAULT_STEP_RELEASE_TYPE');
938   IF l_profile_value IS NOT NULL THEN
939 
940     OPEN Cur_get_new_parameter_line_id;
941     FETCH Cur_get_new_parameter_line_id INTO l_Parameter_line_Id;
942     CLOSE Cur_get_new_parameter_line_id;
943 
944     GMD_Parameters_Dtl_Pkg.Insert_Row
945     (	X_rowid			=> l_rowid,
946 	X_parameter_line_id	=> l_parameter_line_id,
947 	X_parameter_id		=> l_parameter_id,
948 	X_parm_Type		=> 3,
949 	X_parameter_name	=> 'STEPRELEASE_TYPE',
950 	X_parameter_value	=> l_profile_value,
951 	X_creation_date		=> SYSDATE,
952 	X_created_by		=> 0,
953 	X_last_update_date	=> SYSDATE,
954 	X_last_updated_by	=> 0,
955 	X_last_update_login	=> NULL);
956    l_migrate_count := l_migrate_count + 1;
957   END IF;
958 END IF;
959 
960 /* END - Migration of Routing Parameters */
961 
962 /* Lets save the changes now based on the commit parameter*/
963 IF (p_commit = FND_API.G_TRUE) THEN
964    COMMIT;
965 END IF;
966 
967 GMA_COMMON_LOGGING.gma_migration_central_log (
968        p_run_id          => P_migration_run_id,
969        p_log_level       => FND_LOG.LEVEL_PROCEDURE,
970        p_message_token   => 'GMA_MIGRATION_TABLE_SUCCESS',
971        p_table_name      => 'GMD_PARAMETERS',
972        p_context         => 'PROFILES',
973        p_param1          => l_migrate_count,
974        p_param2          => 0,
975        p_param3          => NULL,
976        p_param4          => NULL,
977        p_param5          => NULL,
978        p_db_error        => NULL,
979        p_app_short_name  => 'GMD');
980 
981 
982 EXCEPTION
983   WHEN OTHERS THEN
984     x_failure_count := x_failure_count + 1;
985 
986     GMA_COMMON_LOGGING.gma_migration_central_log (
987           p_run_id          => P_migration_run_id,
988           p_log_level       => FND_LOG.LEVEL_UNEXPECTED,
989           p_message_token   => 'GMA_MIGRATION_DB_ERROR',
990           p_table_name      => 'GMD_PARAMETERS',
991           p_context         => 'PROFILES',
992           p_param1          => l_migrate_count,
993           p_param2          => x_failure_count,
994           p_param3          => NULL,
995           p_param4          => NULL,
996           p_param5          => NULL,
997           p_db_error        => SQLERRM,
998           p_app_short_name  => 'GMD');
999 
1000     GMA_COMMON_LOGGING.gma_migration_central_log (
1001           p_run_id          => P_migration_run_id,
1002           p_log_level       => FND_LOG.LEVEL_PROCEDURE,
1003           p_message_token   => 'GMA_TABLE_MIGRATION_TABLE_FAIL',
1004           p_table_name      => 'GMD_PARAMETERS',
1005           p_context         => 'PROFILES',
1006           p_param1          => l_migrate_count,
1007           p_param2          => x_failure_count,
1008           p_param3          => NULL,
1009           p_param4          => NULL,
1010           p_param5          => NULL,
1011           p_db_error        => NULL,
1012           p_app_short_name  => 'GMD');
1013 
1014 END Migrate_Profiles;
1015 
1016 /*====================================================================
1017 --  PROCEDURE:
1018 --    Migrate_Recipe_Types
1019 --
1020 --  DESCRIPTION:
1021 --    This PL/SQL procedure is used to migrate the recipe types.
1022 --
1023 --    Recipes migrated to the Master Inventory Organization would default to 'General' recipes,
1024 --    while recipes migrated to all other inventory orgs would default to 'Site' recipes.
1025 --
1026 --  PARAMETERS:
1027 --    P_migration_run_id - id to use to right to migration log
1028 --    x_failure_count    - Number of failures occurred.
1029 --
1030 --  SYNOPSIS:
1031 --    Migrate_Recipe_Types(p_migartion_id    => l_migration_id,
1032 --                         p_commit          => 'T',
1033 --                         x_failure_count   => l_failure_count );
1034 --
1035 --  HISTORY
1036 --====================================================================*/
1037 
1038 PROCEDURE Migrate_Recipe_Types (P_migration_run_id	IN NUMBER,
1039 				P_commit		IN VARCHAR2,
1040 				X_failure_count		OUT NOCOPY NUMBER) IS
1041 
1042   /*  ------------------ CURSORS ---------------------- */
1043 
1044   CURSOR Cur_get_recipe IS
1045     SELECT chld.recipe_id, mst.recipe_id master_recipe_id
1046     FROM   gmd_recipes_b chld,
1047            (SELECT recipe_id, owner_organization_id, recipe_no, formula_id, routing_id
1048             FROM   gmd_recipes_b
1049             WHERE  recipe_type = 0 ) mst,
1050            Mtl_parameters org
1051     WHERE  org.master_organization_id = mst.owner_organization_id
1052     AND    chld.owner_organization_id = org.organization_id
1053     AND    mst.recipe_no = chld.recipe_no
1054     AND    mst.formula_id = chld.formula_id
1055     AND    NVL(mst.routing_id, -1) = NVL(chld.routing_id, -1)
1056     AND    chld.master_recipe_id IS NULL;
1057 
1058 BEGIN
1059 
1060   X_failure_count := 0;
1061 
1062   /* Logging the start of the migration*/
1063   GMA_COMMON_LOGGING.gma_migration_central_log (
1064        p_run_id          => P_migration_run_id,
1065        p_log_level       => FND_LOG.LEVEL_EVENT,
1066        p_message_token   => 'GMA_MIGRATION_STARTED',
1067        p_table_name      => 'GMD_RECIPES_B',
1068        p_context         => 'GMD_RECIPE_TYPE',
1069        p_param1          => NULL,
1070        p_param2          => NULL,
1071        p_param3          => NULL,
1072        p_param4          => NULL,
1073        p_param5          => NULL,
1074        p_db_error        => NULL,
1075        p_app_short_name  => 'GMD');
1076 
1077 
1078   /* Running the Migration */
1079 
1080       /* Select all the master organizations and update them to "General" recipe type */
1081       UPDATE gmd_recipes_b
1082          SET recipe_type = 0
1083        WHERE recipe_type IS NULL
1084 	 AND owner_organization_id IN ( SELECT DISTINCT owner_organization_id
1085 					  FROM gmd_recipes_b r
1086 					 WHERE EXISTS (SELECT 1
1087 					                 FROM mtl_parameters o
1088 						        WHERE o.master_organization_id = r.owner_organization_id));
1089 
1090       /* Now lets update the rest of the recipe types as "Site" */
1091       UPDATE gmd_recipes_b
1092       SET recipe_type = 1
1093       WHERE recipe_type IS NULL;
1094 
1095       /* Now lets update the master recipe id for the recipes */
1096       FOR l_recipe_rec IN Cur_get_recipe LOOP
1097         UPDATE gmd_recipes_b
1098         SET master_recipe_id = l_recipe_rec.master_recipe_id
1099         WHERE recipe_id = l_recipe_rec.recipe_id;
1100       END LOOP;
1101 
1102 
1103     IF (p_commit = FND_API.G_TRUE) THEN
1104 	COMMIT;
1105     END IF;
1106 
1107 
1108   GMA_COMMON_LOGGING.gma_migration_central_log (
1109                         p_run_id          => P_migration_run_id,
1110                         p_log_level       => FND_LOG.LEVEL_EVENT,
1111                         p_message_token   => 'GMA_MIGRATION_COMPLETED',
1112                         p_table_name      => 'GMD_RECIPES_B',
1113 			p_context         => 'GMD_RECIPE_TYPE',
1114                         p_param1          => NULL,
1115                         p_param2          => NULL,
1116                         p_param3          => NULL,
1117                         p_param4          => NULL,
1118                         p_param5          => NULL,
1119                         p_db_error        => NULL,
1120                         p_app_short_name  => 'GMD');
1121 
1122   GMA_MIGRATION.gma_migration_end (l_run_id => P_migration_run_id);
1123 
1124 EXCEPTION
1125   WHEN OTHERS THEN
1126     x_failure_count := x_failure_count + 1;
1127 
1128     GMA_COMMON_LOGGING.gma_migration_central_log (
1129           p_run_id          => P_migration_run_id,
1130           p_log_level       => FND_LOG.LEVEL_UNEXPECTED,
1131           p_message_token   => 'GMA_MIGRATION_DB_ERROR',
1132           p_table_name      => 'GMD_RECIPES_B',
1133           p_context         => 'GMD_RECIPE_TYPE',
1134           p_param1          => NULL,
1135           p_param2          => NULL,
1136           p_param3          => NULL,
1137           p_param4          => NULL,
1138           p_param5          => NULL,
1139           p_db_error        => SQLERRM,
1140           p_app_short_name  => 'GMD');
1141 
1142     GMA_COMMON_LOGGING.gma_migration_central_log (
1143           p_run_id          => P_migration_run_id,
1144           p_log_level       => FND_LOG.LEVEL_PROCEDURE,
1145           p_message_token   => 'GMA_TABLE_MIGRATION_TABLE_FAIL',
1146           p_table_name      => 'GMD_RECIPES_B',
1147           p_context         => 'GMD_RECIPE_TYPE',
1148           p_param1          => NULL,
1149           p_param2          => NULL,
1150           p_param3          => NULL,
1151           p_param4          => NULL,
1152           p_param5          => NULL,
1153           p_db_error        => NULL,
1154           p_app_short_name  => 'GMD');
1155 
1156 END  Migrate_Recipe_Types;
1157 
1158 /*====================================================================
1159 --  PROCEDURE:
1160 --    update_lab_simulator
1161 --
1162 --  DESCRIPTION:
1163 --    This PL/SQL procedure is used to update the lab_organization_id.
1164 --
1165 --    lab_organization_id column in lm_sprd_fls will be updated wih the profile
1166 --    value gmd$default_lab_type organization_id.
1167 --
1168 --  PARAMETERS:
1169 --    P_migration_run_id - id to use to right to migration log
1170 --    x_failure_count    - Number of failures occurred.
1171 --
1172 --  SYNOPSIS:
1173 --    update_lab_simulator(p_migartion_id    => l_migration_id,
1174 --                         p_commit          => 'T',
1175 --                         x_failure_count   => l_failure_count );
1176 --
1177 --  HISTORY
1178 --====================================================================*/
1179 
1180   PROCEDURE update_lab_simulator (P_migration_run_id	IN  NUMBER,
1181 				  P_commit		IN  VARCHAR2,
1182 				  X_failure_count	OUT NOCOPY NUMBER) IS
1183     CURSOR Cur_get_orgn (V_orgn_code VARCHAR2) IS
1184       SELECT organization_id
1185       FROM   sy_orgn_mst_b
1186       WHERE  orgn_code = V_orgn_code
1187       AND    migrated_ind = 1;
1188 
1189     l_profile_value		VARCHAR2(80);
1190     l_organization_id		NUMBER;
1191 
1192   /*  --------EXCEPTIONS ------------- */
1193     ORGN_MISSING      EXCEPTION;
1194   BEGIN
1195     X_failure_count := 0;
1196 
1197     /* Logging the start of the migration*/
1198     GMA_COMMON_LOGGING.gma_migration_central_log (
1199        p_run_id          => P_migration_run_id,
1200        p_log_level       => FND_LOG.LEVEL_EVENT,
1201        p_message_token   => 'GMA_MIGRATION_STARTED',
1202        p_table_name      => 'LM_SPRD_FLS',
1203        p_context         => 'SIMULATOR_LAB_TYPE',
1204        p_param1          => NULL,
1205        p_param2          => NULL,
1206        p_param3          => NULL,
1207        p_param4          => NULL,
1208        p_param5          => NULL,
1209        p_db_error        => NULL,
1210        p_app_short_name  => 'GMD');
1211 
1212     --Now update the lab_organization_id wih the organization_id value fetched
1213     --from the gemms_default_lab_type profile.
1214     l_profile_value :=  FND_PROFILE.VALUE('GEMMS_DEFAULT_LAB_TYPE');
1215     IF l_profile_value IS NOT NULL THEN
1216       OPEN Cur_get_orgn(l_profile_value);
1217       FETCH Cur_get_orgn INTO l_organization_id;
1218       CLOSE Cur_get_orgn;
1219       IF (l_organization_id IS NULL) THEN
1220         RAISE ORGN_MISSING;
1221       END IF;
1222       UPDATE lm_sprd_fls
1223       SET    lab_organization_id = l_organization_id
1224       WHERE  lab_organization_id IS NULL;
1225     END IF;
1226 
1227     IF (p_commit = FND_API.G_TRUE) THEN
1228       COMMIT;
1229     END IF;
1230 
1231     GMA_COMMON_LOGGING.gma_migration_central_log (
1232                         p_run_id          => P_migration_run_id,
1233                         p_log_level       => FND_LOG.LEVEL_EVENT,
1234                         p_message_token   => 'GMA_MIGRATION_COMPLETED',
1235                         p_table_name      => 'LM_SPRD_FLS',
1236 			p_context         => 'SIMULATOR_LAB_TYPE',
1237                         p_param1          => NULL,
1238                         p_param2          => NULL,
1239                         p_param3          => NULL,
1240                         p_param4          => NULL,
1241                         p_param5          => NULL,
1242                         p_db_error        => NULL,
1243                         p_app_short_name  => 'GMD');
1244 
1245     GMA_MIGRATION.gma_migration_end (l_run_id => P_migration_run_id);
1246 
1247 EXCEPTION
1248   WHEN ORGN_MISSING THEN
1249       x_failure_count := x_failure_count + 1;
1250       GMA_COMMON_LOGGING.gma_migration_central_log (
1251           p_run_id          => P_migration_run_id,
1252           p_log_level       => FND_LOG.LEVEL_ERROR,
1253           p_message_token   => 'GMA_ORGN_MISSING_ERROR',
1254           p_table_name      => 'LM_SPRD_FLS',
1255           p_context         => 'SIMULATOR_LAB_TYPE',
1256 	  p_token1          => 'ORGANIZATION',
1257           p_param1          => l_profile_value,
1258           p_app_short_name  => 'GMA');
1259 
1260   WHEN OTHERS THEN
1261     x_failure_count := x_failure_count + 1;
1262 
1263     GMA_COMMON_LOGGING.gma_migration_central_log (
1264           p_run_id          => P_migration_run_id,
1265           p_log_level       => FND_LOG.LEVEL_UNEXPECTED,
1266           p_message_token   => 'GMA_MIGRATION_DB_ERROR',
1267           p_table_name      => 'LM_SPRD_FLS',
1268           p_context         => 'SIMULATOR_LAB_TYPE',
1269           p_param1          => NULL,
1270           p_param2          => NULL,
1271           p_param3          => NULL,
1272           p_param4          => NULL,
1273           p_param5          => NULL,
1274           p_db_error        => SQLERRM,
1275           p_app_short_name  => 'GMD');
1276 
1277     GMA_COMMON_LOGGING.gma_migration_central_log (
1278           p_run_id          => P_migration_run_id,
1279           p_log_level       => FND_LOG.LEVEL_PROCEDURE,
1280           p_message_token   => 'GMA_TABLE_MIGRATION_TABLE_FAIL',
1281           p_table_name      => 'LM_SPRD_FLS',
1282           p_context         => 'SIMULATOR_LAB_TYPE',
1283           p_param1          => NULL,
1284           p_param2          => NULL,
1285           p_param3          => NULL,
1286           p_param4          => NULL,
1287           p_param5          => NULL,
1288           p_db_error        => NULL,
1289           p_app_short_name  => 'GMD');
1290   END update_lab_simulator;
1291 
1292 
1293 END GMD_NPD_MIGRATE;
1294