DBA Data[Home] [Help]

PACKAGE BODY: APPS.ENG_VALIDATE_REVISED_ITEM

Source


1 PACKAGE BODY ENG_Validate_Revised_Item AS
2 /* $Header: ENGLRITB.pls 120.12.12000000.2 2007/02/26 11:33:47 asjohal ship $ */
3 
4 --  Global constant holding the package name
5 
6         G_PKG_NAME      CONSTANT VARCHAR2(30) := 'ENG_Validate_Revised_Item';
7 
8         /* Added by MK on 09/01/2000 ECO for Routing */
9         l_sub_locator_control         NUMBER;
10         l_locator_control             NUMBER;
11         l_org_locator_control         NUMBER;
12         l_item_locator_control        NUMBER;
13         l_item_loc_restricted         NUMBER; -- 1,Locator is Restricted,else 2
14 
15 
16 /****************************************************************************
17 * Function      : Compatible_Item_Type
18 * Parameters IN : Change Notice
19 *                 Organization ID
20 *                 Revised item ID
21 * Returns       : True or False
22 * Purpose       : Function will look at the type of ECO by looking at the
23 *                 change order type. If it has Engineering as checked, then the
24 *                 ECO can allow for manufacturing as well as engineering item
25 *                 else it can have only manufacturing items. To verify the type
26 *                 of item, the function will also look at the item's
27 *                 eng_item_flag attribute.
28 ******************************************************************************/
29 FUNCTION Compatible_Item_Type
30 ( p_organization_id             IN  NUMBER
31 , p_revised_item_id             IN NUMBER
32 , p_assembly_type               IN NUMBER)RETURN BOOLEAN
33 IS
34         l_assembly_type         NUMBER := 0;
35 
36         l_eng_item_flag         VARCHAR2(1) := NULL;
37         CURSOR eng_item_cur IS
38                 SELECT eng_item_flag
39                   FROM mtl_system_items
40                  WHERE inventory_item_id = p_revised_item_id
41                    AND organization_id = p_organization_id;
42 
43 BEGIN
44 
45   OPEN eng_item_cur;
46   FETCH eng_item_cur into l_eng_item_flag;
47   CLOSE eng_item_cur;
48 
49   IF (p_assembly_type = 1 and l_eng_item_flag = 'N') or
50      (p_assembly_type = 2)
51   THEN
52         RETURN TRUE;
53   ELSE
54         RETURN FALSE;
55   END IF;
56 
57 END Compatible_Item_Type;
58 
59 
60 /******************************************************************************
61 * Function      : Pending_High_Rev (Local function)
62 * Parameters    : Change Notice
63 *                 Organization Id
64 *                 revised item id
65 * Returns       : True if the highest revision exists on another ECO else False
66 * Purpose       : Checks if the (currently) highest un-implemented revision of
67 *                 the revised item exists on another ECO
68 ******************************************************************************/
69 PROCEDURE Pending_High_Rev
70 ( p_change_notice               IN  VARCHAR2
71 , p_organization_id             IN  NUMBER
72 , p_revised_item_id             IN  NUMBER
73 , x_change_notice               OUT NOCOPY VARCHAR2
74 , x_revision                    OUT NOCOPY VARCHAR2
75 )
76 IS
77         l_change_notice         VARCHAR2(10) := NULL;
78 
79         l_item_rev      VARCHAR2(3) := NULL;
80 
81         CURSOR ITEM_REV IS
82                SELECT revision
83                  FROM Mtl_Item_Revisions
84                 WHERE inventory_item_id = p_revised_item_id
85                   AND organization_id = p_organization_id
86              ORDER BY effectivity_date desc, revision desc;
87 
88 BEGIN
89         OPEN ITEM_REV;
90         FETCH ITEM_REV into l_item_rev;
91         CLOSE ITEM_REV;
92 
93         IF l_item_rev IS NOT NULL
94         THEN
95                 l_change_notice :=
96                         ENG_REVISED_ITEMS_PKG.Get_High_Rev_ECO
97                         ( X_Organization_Id       => p_organization_id
98                         , X_Revised_Item_Id       => p_revised_item_id
99                         , X_New_Item_Revision     => l_item_rev
100                         );
101 
102         END IF;
103         x_change_notice := l_change_notice;
104         x_revision := l_item_rev;
105 END Pending_High_Rev;
106 
107 /******************************************************************************
108 * Added by MK on 08/26/2000
109 * Function      :  Get_High_Rtg_Rev_ECO (Local function)
110 * Parameters    : New Routing Revision
111 *                 Organization Id
112 *                 revised item id
113 * Returns       : ECO Name if the routing revision exists on revised item
114 ******************************************************************************/
115 
116 FUNCTION Get_High_Rtg_Rev_ECO
117 ( p_organization_id      IN NUMBER
118 , p_revised_item_id      IN NUMBER
119 , p_new_routing_revision IN VARCHAR2)
120 RETURN VARCHAR2
121 IS
122 
123 l_eco_name  VARCHAR2(10) ;
124 
125 CURSOR l_change_notice_csr ( p_organization_id NUMBER
126                            , p_revised_item_id NUMBER
127                            , p_new_routing_revision VARCHAR2 )
128 IS
129    SELECT change_notice
130    FROM   ENG_REVISED_ITEMS
131    WHERE  cancellation_date IS NULL
132    AND implementation_date IS NULL -- Added for bug 3598711, Query to fetch un-implemented ECOs only.
133    AND    revised_item_id   =  p_revised_item_id
134    AND    new_routing_revision = p_new_routing_revision
135    AND    organization_id      = p_organization_id ;
136 
137 BEGIN
138 
139    OPEN l_change_notice_csr ( p_organization_id
140                             , p_revised_item_id
141                             , p_new_routing_revision );
142    FETCH l_change_notice_csr INTO l_eco_name ;
143 
144    IF l_change_notice_csr%FOUND THEN
145    	CLOSE l_change_notice_csr ;
146        RETURN l_eco_name ;
147    ELSE
148    	CLOSE l_change_notice_csr ;
149    RETURN NULL ;
150 
151    END IF ;
152 
153 END Get_High_Rtg_Rev_ECO ;
154 
155 /******************************************************************************
156 * Added by MK on 08/26/2000
157 * Function      : Pending_High_Rtg_Rev (Local function)
158 * Parameters    : Change Notice
159 *                 Organization Id
160 *                 revised item id
161 * Returns       : True if the highest routing revision exists on another ECO else False
162 * Purpose       : Checks if the (currently) highest un-implemented revision of
163 *                 the revised item exists on another ECO
164 ******************************************************************************/
165 PROCEDURE Pending_High_Rtg_Rev
166 ( p_change_notice               IN  VARCHAR2
167 , p_organization_id             IN  NUMBER
168 , p_revised_item_id             IN  NUMBER
169 , x_change_notice               OUT NOCOPY VARCHAR2
170 , x_revision                    OUT NOCOPY VARCHAR2
171 )
172 IS
173         l_change_notice         VARCHAR2(10) := NULL;
174 
175         l_routing_rev      VARCHAR2(3) := NULL;
176 
177         CURSOR RTG_REV IS
178                SELECT process_revision
179                  FROM MTL_RTG_ITEM_REVISIONS
180                 WHERE inventory_item_id = p_revised_item_id
181                   AND organization_id   = p_organization_id
182              ORDER BY effectivity_date desc, process_revision desc;
183 
184 BEGIN
185 
186         OPEN  RTG_REV;
187         FETCH RTG_REV into l_routing_rev;
188         CLOSE RTG_REV;
189 
190         IF l_routing_rev IS NOT NULL
191         THEN
192                 l_change_notice :=
193                         Get_High_Rtg_Rev_ECO
194                         ( p_organization_id       => p_organization_id
195                         , p_revised_item_id       => p_revised_item_id
196                         , p_new_routing_revision  => l_routing_rev
197                         );
198 
199         END IF;
200         x_change_notice := l_change_notice;
201         x_revision      := l_routing_rev;
202 
203 END Pending_High_Rtg_Rev;
204 
205 
206 
207 
208 FUNCTION Validate_Use_Up_Plan
209 ( p_use_up_plan_name IN VARCHAR2
210 , p_use_up_item_id IN NUMBER
211 , p_organization_id IN NUMBER
212 )
213 RETURN BOOLEAN
214 IS
215 l_dummy                       VARCHAR2(10) := NULL;
216 l_err_text      VARCHAR2(2000) := NULL;
217 
218 CURSOR USE_UP_PLAN IS
219     SELECT 'VALID'
220     FROM   mrp_system_items
221     WHERE  inventory_item_id = p_use_up_item_id
222     AND    organization_id = p_organization_id
223     AND    compile_designator = p_use_up_plan_name
224     AND    inventory_use_up_date >= SYSDATE;
225 
226 BEGIN
227    OPEN USE_UP_PLAN;
228    FETCH USE_UP_PLAN INTO l_dummy;
229    CLOSE USE_UP_PLAN;
230 
231     IF p_use_up_item_id IS NOT NULL AND
232        l_dummy IS NULL
233     THEN
234         RETURN FALSE;
235     END IF;
236 
237     RETURN TRUE;
238 END Validate_Use_Up_Plan;
239 
240 /******************************************************************************
241 * Function      : Get_Current_Item_Revision
242 * Parameters IN : Revised Item ID
243 *                 Organization ID
244 *                 Revision Date
245 * Returns       : VARCHAR2
246 * Purpose       : Function will return the current revision of the given revised
247 *                 item.
248 ******************************************************************************/
249 FUNCTION Get_Current_Item_Revision
250 ( p_revised_item_id IN NUMBER
251 , p_organization_id IN NUMBER
252 , p_revision_date IN DATE
253 ) RETURN VARCHAR2
254 IS
255 l_current_revision      VARCHAR2(3) := NULL;
256 
257 CURSOR NO_ECO_ITEM_REV IS
258        SELECT REVISION
259        FROM   MTL_ITEM_REVISIONS
260        WHERE  INVENTORY_ITEM_ID = p_revised_item_id
261        AND    ORGANIZATION_ID = p_organization_id
262        AND    EFFECTIVITY_DATE <= p_revision_date
263        AND    IMPLEMENTATION_DATE IS NOT NULL
264        ORDER BY EFFECTIVITY_DATE DESC, REVISION DESC;
265 BEGIN
266    OPEN NO_ECO_ITEM_REV;
267    FETCH NO_ECO_ITEM_REV INTO l_current_revision;
268    CLOSE NO_ECO_ITEM_REV;
269 
270    RETURN l_current_revision;
271 END Get_Current_Item_Revision;
272 
273 
274 /*****************************************************************************
275 * Function      : Validate_New_Item_Revision
276 * Parameters IN : Revised Item ID
277 *                 Organization ID
278 *                 New Revised item Revision
279 *                 Revised item sequence Id
280 *                 Updated Revised item Revision
281 * Returns       : Number - 1 - if the revision is less than the current rev.
282 *                          2 - if the
283 *                          3 - if the
284 * Purpose       : Function will check if the new_revised_item_revision or the
285 *                 updated_revised_item_revision is not less than the current
286 *                 item revision. If it is then the function will return a
287 *                 value of 1. Else it will proceed to check if the revision
288 *                 is being created by another ECO and is still un-implemented
289 *                 If it finds this, then the function will return a value of 2.
290 *                 Else it will check if the revision exists in an implemented
291 *                 state. If it does exist then the function will return 3
292 *                 indicating that the revision already exists. If none of the
293 *                 conditions are true then the function returns a 0.
294 *
295 *                 11.5.10E
296 *                 If from PLM, the validation is done against the 'From Revision'
297 *                 instead of the current revision.
298 ******************************************************************************/
299 FUNCTION Validate_New_Item_Revision
300 ( p_revised_item_id IN NUMBER
301 , p_organization_id IN NUMBER
302 , p_from_revision IN VARCHAR2
303 , p_new_item_revision IN VARCHAR2
304 , p_revised_item_sequence_id IN NUMBER
305 , x_change_notice OUT NOCOPY VARCHAR2
306 ) RETURN NUMBER
307 IS
308   l_Rev_Compare         NUMBER          := NULL;
309   l_Change_Notice       VARCHAR2(10)    := NULL;
310   l_Curr_Rev            VARCHAR2(4)     := NULL;
311   l_Pending_Rev         NUMBER          := 0;
312   l_rev_sequence        NUMBER;
313 
314   CURSOR c1 IS          SELECT change_notice
315                           FROM MTL_ITEM_REVISIONS
316                          WHERE inventory_item_id = p_revised_item_id
317                            AND organization_id = p_organization_id
318                            AND revision = p_new_item_revision
319                            AND revised_item_sequence_id <>
320                                 NVL(p_revised_item_sequence_id,
321                                     revised_item_sequence_id+99)
322                            AND implementation_date is null;
323 
324   CURSOR c2 IS          SELECT 1
325                           FROM MTL_ITEM_REVISIONS
326                          WHERE inventory_item_id = p_revised_item_id
327                            AND organization_id = p_organization_id
328                            AND revision = p_new_item_revision
329                            AND implementation_date is not null;
330 BEGIN
331 
332       -- verify revised item has a valid current revision
333 
334 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Validating revised item revision . . .' ||
335 p_new_item_revision);
336 END IF;
337       --11.5.10E
338       --Commented out as From revision is being supported.
339       /*l_Curr_Rev := Get_Current_Item_Revision
340                     (  p_revised_item_id => p_revised_item_id
341                      , p_organization_id => p_organization_id
342                      , p_revision_date   => SYSDATE
343                      );*/
344       l_Curr_Rev := p_from_revision;
345 
346 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Current revision. . . ' || l_Curr_Rev); END IF;
347       -- revision must be greater than the current revision
348 
349       l_Rev_Compare := BOM_REVISIONS.Compare_Revision(
350                                 rev1    => p_new_item_revision,
351                                 rev2    => l_Curr_Rev);
352       IF l_Rev_Compare = 1 THEN
353 
354 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Revision not the latest . . .'); END IF;
355 
356         RETURN 1;
357       END IF;
358 
359       -- check if revision has been created in another ECO
360 
361       OPEN c1;
362       FETCH c1 INTO l_Change_Notice;
363       CLOSE c1;
364       IF l_Change_Notice IS NOT NULL
365       THEN
366 
367 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Revision created thru another ECO . . .'); END IF;
368         x_Change_Notice := l_Change_Notice;
369         RETURN 2;
370       END IF;
371 
372       -- check if this revision has already been implemented
373 
374       IF p_new_item_revision <> l_Curr_Rev THEN
375 
376         l_Pending_Rev := 0;
377         FOR x_count IN c2 LOOP
378           l_Pending_Rev := 1;
379           RETURN 3;
380         END LOOP;
381 
382       END IF;
383 
384       RETURN 0;
385 
386 END Validate_New_Item_Revision;
387 
388 -- Added for bug 3618662
389 /*****************************************************************************
390 * Function      : High_Date_Low_Revision
391 * Parameters IN : Revised Item ID
392 *                 Organization ID
393 *                 New Revised item Revision
394 *                 Scheduled Date
395 *                 Revised item sequence Id
396 * Returns       : Number - 1 - if the revision is invalid
397 *                          2 - if the revision is valid
398 * Purpose       : Function will check if the revisions and effectivity dates
399 *                 in ascending order. Return 1 if there exists an invalid combination.
400 *                 Return 2 otherwise.
401 ******************************************************************************/
402 FUNCTION High_Date_Low_Revision (
403     p_revised_item_id	IN NUMBER
404   , p_organization_id	IN NUMBER
405   , p_new_item_revision	IN VARCHAR2
406   , p_scheduled_date	IN DATE
407   , p_rev_item_seq_id	IN NUMBER
408 ) RETURN NUMBER
409 IS
410 
411  CURSOR check_high_date_low_rev
412  IS
413  SELECT 1
414  FROM mtl_item_revisions r
415  WHERE r.inventory_item_id = p_revised_item_id
416  AND   r.organization_id = p_organization_id
417  AND   NVL(r.revised_item_sequence_id, -1) <> NVL(p_rev_item_seq_id, -2)
418  AND ((r.effectivity_date >= p_scheduled_date and r.revision < p_new_item_revision)
419    OR (r.effectivity_date <= p_scheduled_date and r.revision > p_new_item_revision)
420      );
421 
422  l_is_revision_invalid NUMBER;
423 
424 BEGIN
425 	l_is_revision_invalid := 2; -- Revision is not INVALID
426 
427 	OPEN check_high_date_low_rev;
428 	FETCH check_high_date_low_rev INTO l_is_revision_invalid;
429 	CLOSE check_high_date_low_rev;
430 
431 	RETURN l_is_revision_invalid;
432 END High_Date_Low_Revision;
433 
434 -- 11.5.10E
435 /*****************************************************************************
436 * Function      : Scheduled_Date_From_Revision
437 * Parameters IN : Revised Item ID
438 *                 Organization ID
439 *                 From Item Revision
440 *                 Scheduled Date
441 *                 From Revision ID
442 *                 Revised item sequence Id
443 * Returns       : Number - 1 - if the schedule date is invalid
444 *                          2 - if the schedule date is valid
445 * Purpose       : Function will check if the scheduled date is valid for a revised
446 *                 item.
447 ******************************************************************************/
448 FUNCTION Scheduled_Date_From_Revision (
449     p_revised_item_id    IN NUMBER
450   , p_organization_id    IN NUMBER
451   , p_from_item_revision IN VARCHAR2
452   , p_scheduled_date     IN DATE
453   , p_rev_item_seq_id    IN NUMBER
454 ) RETURN NUMBER
455 IS
456 
457  CURSOR sheduled_date_from_revision
458  IS
459  SELECT 1
460  FROM mtl_item_revisions r
461  WHERE r.inventory_item_id = p_revised_item_id
462  AND   r.organization_id = p_organization_id
463  AND   r.effectivity_date >= p_scheduled_date
464  AND   r.revision = p_from_item_revision;
465 
466  l_is_scheduled_date_valid NUMBER;
467 
468 BEGIN
469   l_is_scheduled_date_valid := 2; -- Date is VALID
470 
471   OPEN sheduled_date_from_revision;
472   FETCH sheduled_date_from_revision INTO l_is_scheduled_date_valid;
473   CLOSE sheduled_date_from_revision;
474 
475   RETURN l_is_scheduled_date_valid;
476 
477   EXCEPTION
478     WHEN OTHERS THEN
479       IF sheduled_date_from_revision%ISOPEN
480       THEN
481         CLOSE sheduled_date_from_revision;
482       END IF;
483       RETURN l_is_scheduled_date_valid;
484 
485 END Scheduled_Date_From_Revision;
486 
487 -- Fix for bug 3311749
488 /*****************************************************************************
489 * Function      : Exp_Validate_New_Item_Revision
490 * Parameters IN : Revised Item ID
491 *                 Organization ID
492 *                 New Revised item Revision
493 *                 Revised item sequence Id
494 *                 Updated Revised item Revision
495 * Returns       : Number - 1 - if the revision is less than the current rev.
496 *                          2 - if the
497 *                          3 - if the
498 * Purpose       : Function will check if the new_revised_item_revision or the
499 *                 updated_revised_item_revision is not less than the current
500 *                 item revision. If it is then the function will return a
501 *                 value of 1. Else it will proceed to check if the revision
502 *                 is being created by another ECO and is still un-implemented
503 *                 If it finds this, then the function will return a value of 2.
504 *                 Else it will check if the revision exists in an implemented
505 *                 state. If it does exist then the function will return 3
506 *                 indicating that the revision already exists. If none of the
507 *                 conditions are true then the function returns a 0.
508 ******************************************************************************/
509 FUNCTION Exp_Validate_New_Item_Revision
510 ( p_revised_item_id IN NUMBER
511 , p_organization_id IN NUMBER
512 , p_new_item_revision IN VARCHAR2
513 , p_revised_item_sequence_id IN NUMBER
514 , x_change_notice OUT NOCOPY VARCHAR2
515 ) RETURN NUMBER
516 IS
517   l_Rev_Compare         NUMBER          := NULL;
518   l_Change_Notice       VARCHAR2(10)    := NULL;
519   l_Curr_Rev            VARCHAR2(4)     := NULL;
520   l_Pending_Rev         NUMBER          := 0;
521   l_rev_sequence        NUMBER;
522 
523   CURSOR c1 IS          SELECT change_notice
524                           FROM MTL_ITEM_REVISIONS
525                          WHERE inventory_item_id = p_revised_item_id
526                            AND organization_id = p_organization_id
527                            AND revision = p_new_item_revision
528                            AND implementation_date is null;
529 
530   CURSOR c2 IS          SELECT 1
531                           FROM MTL_ITEM_REVISIONS
532                          WHERE inventory_item_id = p_revised_item_id
533                            AND organization_id = p_organization_id
534                            AND revision = p_new_item_revision
535                            AND implementation_date is not null;
536 BEGIN
537 
538       -- verify revised item has a valid current revision
539 
540 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Validating revised item revision . . .' ||
541 p_new_item_revision);
542 END IF;
543       l_Curr_Rev := Get_Current_Item_Revision
544                     (  p_revised_item_id => p_revised_item_id
545                      , p_organization_id => p_organization_id
546                      , p_revision_date   => SYSDATE
547                      );
548 
549 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Current revision. . . ' || l_Curr_Rev); END IF;
550       -- revision must be greater than the current revision
551 
552       l_Rev_Compare := BOM_REVISIONS.Compare_Revision(
553                                 rev1    => p_new_item_revision,
554                                 rev2    => l_Curr_Rev);
555       IF l_Rev_Compare = 1 THEN
556 
557 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Revision not the latest . . .'); END IF;
558 
559         RETURN 1;
560       END IF;
561 
562       -- check if revision has been created in another ECO
563 
564       OPEN c1;
565       FETCH c1 INTO l_Change_Notice;
566       CLOSE c1;
567       IF l_Change_Notice IS NOT NULL
568       THEN
569 
570 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Revision created thru another ECO . . .'); END IF;
571         x_Change_Notice := l_Change_Notice;
572         RETURN 2;
573       END IF;
574 
575       -- check if this revision has already been implemented
576 
577      -- IF p_new_item_revision <> l_Curr_Rev THEN
578 
579         l_Pending_Rev := 0;
580         FOR x_count IN c2 LOOP
581           l_Pending_Rev := 1;
582           RETURN 3;
583         END LOOP;
584 
585       -- END IF;
586 
587       RETURN 0;
588 
589 END Exp_Validate_New_Item_Revision;
590 
591 
592 
593 
594 /******************************************************************************
595 * Function      : Get_Current_Rtg_Revision
596 * Parameters IN : Revised Item ID
597 *                 Organization ID
598 *                 Revision Date
599 * Returns       : VARCHAR2
600 * Purpose       : Function will return the current revision of the given revised
601 *                 item.
602 ******************************************************************************/
603 FUNCTION Get_Current_Rtg_Revision
604 ( p_revised_item_id IN NUMBER
605 , p_organization_id IN NUMBER
606 , p_revision_date IN DATE
607 ) RETURN VARCHAR2
608 IS
609 l_current_revision      VARCHAR2(3) := NULL;
610 
611 CURSOR NO_ECO_ROUTING_REV IS
612        SELECT process_revision
613        FROM   MTL_RTG_ITEM_REVISIONS
614        WHERE  INVENTORY_ITEM_ID  = p_revised_item_id
615        AND    ORGANIZATION_ID    = p_organization_id
616        AND    EFFECTIVITY_DATE   <= p_revision_date
617        AND    IMPLEMENTATION_DATE IS NOT NULL
618        ORDER BY EFFECTIVITY_DATE DESC, PROCESS_REVISION DESC;
619 BEGIN
620    OPEN NO_ECO_ROUTING_REV;
621    FETCH NO_ECO_ROUTING_REV INTO l_current_revision;
622 
623        -- Added by MK on 11/27/00
624        IF NO_ECO_ROUTING_REV%NOTFOUND THEN
625           SELECT mp.starting_revision
626           INTO   l_current_revision
627           FROM  MTL_PARAMETERS mp
628           WHERE mp.organization_id = p_organization_id
629           AND   NOT EXISTS( SELECT NULL
630                             FROM MTL_RTG_ITEM_REVISIONS
631                             WHERE implementation_date IS NOT NULL
632                             AND   organization_id = p_organization_id
633                             AND   inventory_item_id = p_revised_item_id
634                            ) ;
635        END IF ;
636 
637    CLOSE NO_ECO_ROUTING_REV;
638 
639    RETURN l_current_revision;
640 END Get_Current_Rtg_Revision;
641 -- Added by MK on 08/26/2000
642 
643 /*****************************************************************************
644 * Added by MK on 08/26/2000
645 * Function      : Validate_New_Rtg_Revision
646 * Parameters IN : Revised Item ID
647 *                 Organization ID
648 *                 New Routing Revision
649 *                 Revised item sequence Id
650 * Returns       : Number - 1 - if the revision is less than the current rev.
651 *                          2 - if the
652 *                          3 - if the
653 * Purpose       : Function will check if the new_routing_revision or the updated
654 *                 _routing_revision is not less than the current routing revision.
655 *                 If it is then the function will return a value of 1.
656 *                 Else it will proceed to check if the revision is being created
657 *                 by another ECO and is still un-implemented.
658 *                 If it finds this, then the function will return a value of 2.
659 *                 Else it will check if the revision exists in an implemented
660 *                 state. If it does exist then the function will return 3
661 *                 indicating that the revision already exists. If none of the
662 *                 conditions are true then the function returns a 0.
663 ******************************************************************************/
664 FUNCTION Validate_New_Rtg_Revision
665 ( p_revised_item_id   IN NUMBER
666 , p_organization_id   IN NUMBER
667 , p_new_routing_revision IN VARCHAR2
668 , p_revised_item_sequence_id IN NUMBER
669 , x_change_notice OUT NOCOPY VARCHAR2
670 ) RETURN NUMBER
671 IS
672   l_Rev_Compare         NUMBER          := NULL;
673   l_Change_Notice       VARCHAR2(10)    := NULL;
674   l_Curr_Rev            VARCHAR2(4)     := NULL;
675   l_Pending_Rev         NUMBER          := 0;
676   l_rev_sequence        NUMBER;
677 
678   CURSOR c1 IS          SELECT change_notice
679                           FROM MTL_RTG_ITEM_REVISIONS
680                          WHERE inventory_item_id = p_revised_item_id
681                            AND organization_id = p_organization_id
682                            AND process_revision = p_new_routing_revision
683                            AND revised_item_sequence_id <>
684                                 NVL(p_revised_item_sequence_id,
685                                     revised_item_sequence_id+99)
686                            AND implementation_date is null;
687 
688   CURSOR c2 IS          SELECT 1
689                           FROM MTL_RTG_ITEM_REVISIONS
690                          WHERE inventory_item_id = p_revised_item_id
691                            AND organization_id = p_organization_id
692                            AND process_revision = p_new_routing_revision
693                            AND implementation_date is not null;
694 BEGIN
695 
696       -- verify revised item has a valid current revision
697 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Validating routing revision . . .' ||
698 p_new_routing_revision);
699 END IF;
700       l_Curr_Rev := Get_Current_Rtg_Revision
701                     (  p_revised_item_id => p_revised_item_id
702                      , p_organization_id => p_organization_id
703                      , p_revision_date   => SYSDATE
704                      );
705 
706 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Current revision. . . ' || l_Curr_Rev); END IF;
707       -- revision must be greater than the current revision
708 
709       l_Rev_Compare := BOM_REVISIONS.Compare_Revision(
710                                 rev1    => p_new_routing_revision,
711                                 rev2    => l_Curr_Rev);
712       IF l_Rev_Compare = 1 THEN
713 
714 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Revision not the latest . . .'); END IF;
715 
716         RETURN 1;
717       END IF;
718 
719       -- check if revision has been created in another ECO
720 
721       OPEN c1;
722       FETCH c1 INTO l_Change_Notice;
723       CLOSE c1;
724       IF l_Change_Notice IS NOT NULL
725       THEN
726 
727 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Revision created thru another ECO . . .'); END IF;
728         x_Change_Notice := l_Change_Notice;
729         RETURN 2;
730       END IF;
731 
732       -- check if this revision has already been implemented
733 
734       IF p_new_routing_revision <> l_Curr_Rev THEN
735 
736         l_Pending_Rev := 0;
737         FOR x_count IN c2 LOOP
738           l_Pending_Rev := 1;
739           RETURN 3;
740         END LOOP;
741 
742       END IF;
743 
744       RETURN 0;
745 
746 END Validate_New_Rtg_Revision;
747 -- Added by MK on 08/26/2000
748 
749 
750 /*****************************************************************************
751 * Function      : Pending_ECO_Hint
752 * Parameters IN : Revised item ID
753 *                 Change Notice
754 * Returns       : True if the revised item is found pending on other ECO, False
755 *                 otherwise.
756 * Purpose       : Function will verify if the revised item is pending on any
757 *                 other ECO in the same organization.
758 ******************************************************************************/
759 FUNCTION Pending_ECO_Hint(  p_change_notice     VARCHAR2
760                           , p_revised_item_id   NUMBER
761                           , p_organization_id   NUMBER
762                          )
763 RETURN BOOLEAN
764 IS
765         CURSOR c_CheckPendingECO
766         IS SELECT 1
767              FROM ENG_REVISED_ITEMS
768             WHERE implementation_date IS NULL
769               AND cancellation_date   IS NULL
770               AND change_notice       <> p_change_notice
771               AND revised_item_id      = p_revised_item_id
772               AND organization_id      = p_organization_id;
773 
774 BEGIN
775 
776   FOR CheckPendingECO IN c_CheckPendingECO LOOP
777       RETURN TRUE;
778   END LOOP;
779 
780   RETURN FALSE;
781 
782 END Pending_ECO_Hint;
783 
784 /*****************************************************************************
785 * Function      : Eng_Primary_Bill_Exists
786 * Parameters IN : Revised item Id
787 *                 Organization Id
788 * Returns       : True if the revised item has a Primary bill, False otherwise
789 * Purpose       : Verify if the given revised item has a primary bill
790 *                 associated with it. If yes then return a TRUE else return
791 *                 False.
792 ******************************************************************************/
793 FUNCTION Eng_Primary_Bill_Exists(  p_Revised_Item_Id NUMBER
794                                  , p_Organization_Id NUMBER
795                                  , p_assembly_type   NUMBER)
796 RETURN BOOLEAN
797 IS
798         l_Bill_Exists NUMBER := 0;
799         CURSOR c_CheckPrimary IS
800         SELECT bill_sequence_id
801           FROM Bom_Bill_Of_Materials
802          WHERE assembly_item_id = p_Revised_Item_Id
803            AND organization_id  = p_Organization_Id
804            AND alternate_bom_designator is null
805            AND ((assembly_type = 1 and p_Assembly_Type = 1)
806                         or p_Assembly_Type = 2);
807 BEGIN
808 
809         FOR l_Count in c_CheckPrimary LOOP
810                 RETURN TRUE;
811 
812 IF BOM_Globals.get_debug = 'Y'
813 THEN
814      error_handler.write_debug('Check Primary Bill fuction, return True ' );
815 END IF;
816 
817         END LOOP;
818 
819 IF BOM_Globals.get_debug = 'Y'
820 THEN
821      error_handler.write_debug('Check Primary Bill fuction, return False ' );
822 END IF;
823 
824         RETURN FALSE;
825 
826 END Eng_Primary_Bill_Exists;
827 
828 
829 
830 /*****************************************************************************
831 * Added by MK 08/26/2000
832 * Function      : Eng_Primary_Routing_Exists
833 * Parameters IN : Revised item Id
834 *                 Organization Id
835 * Returns       : True if the revised item has a Primary Routing, False otherwise
836 * Purpose       : Verify if the given revised item has a primary bill
837 *                 associated with it. If yes then return a TRUE else return
838 *                 False.
839 ******************************************************************************/
840 FUNCTION Eng_Primary_Routing_Exists(  p_revised_item_id NUMBER
841                                     , p_organization_id NUMBER
842                                     , p_assembly_type   NUMBER)
843 RETURN BOOLEAN
844 IS
845         l_rtg_exists    NUMBER := 0;
846 
847         CURSOR l_checkprimary IS
848         SELECT routing_sequence_id
849           FROM BOM_OPERATIONAL_ROUTINGS
850          WHERE assembly_item_id =  p_revised_item_id
851            AND organization_id  =  p_organization_id
852            AND alternate_routing_designator IS NULL
853            AND ( (routing_type = 1 and p_assembly_type = 1)
854                OR p_assembly_type = 2 )  ;
855 BEGIN
856 
857         FOR l_check_primary_rec in l_checkprimary LOOP
858             RETURN TRUE;
859 
860 IF BOM_Globals.get_debug = 'Y'
861 THEN
862      error_handler.write_debug('Check Primary Routing fuction, return True ' );
863 END IF;
864         END LOOP;
865 
866 
867 IF BOM_Globals.get_debug = 'Y'
868 THEN
869      error_handler.write_debug('Check Primary Routing fuction, return False ' );
870 END IF;
871 
872         RETURN FALSE;
873 
874 END Eng_Primary_Routing_Exists;
875 -- Added by MK 08/26/2000
876 
877 
878 -- Function Check_Reference_Common
879 -- Cannot delete revised item if another bill references it as a common bill
880 
881 FUNCTION Check_Reference_Common
882 ( p_change_notice       VARCHAR2
883 , p_bill_sequence_id    NUMBER
884 )RETURN NUMBER
885 IS
886   l_count1                      NUMBER := 0;
887   l_count2                      NUMBER := 0;
888   cursor pending_on_eco is
889                 select 1
890                   from BOM_BILL_OF_MATERIALS
891                  where bill_sequence_id = p_bill_sequence_id
892                    and pending_from_ecn is not null
893                    and pending_from_ecn = p_change_notice;
894   cursor reference_common is
895                 select 1
896                   from BOM_BILL_OF_MATERIALS
897                  where source_bill_sequence_id = p_bill_sequence_id -- R12: Common Bom
898                    and source_bill_sequence_id <> bill_sequence_id;
899 BEGIN
900 
901   l_count1 := 0;
902 
903   for l_pending_on_eco in pending_on_eco loop
904     l_count1 := 1;
905   end loop;
906 
907   if l_count1 = 1
908   then
909     l_count2 := 0;
910 
911     for l_reference_common in reference_common loop
912       l_count2 := 1;
913     end loop;
914   end if;
915 
916   return (l_count2);
917 END Check_Reference_Common;
918 
919 /*********************************************************************
920 -- Added by MK on 08/26/2000
921 -- Enhancements for ECO Routing
922 *********************************************************************/
923 -- Function Check_Reference_Rtg_Common
924 -- Cannot delete revised item if another Routing references it as a common routing
925 
926 FUNCTION Check_Reference_Rtg_Common
927 ( p_change_notice          VARCHAR2
928 , p_routing_sequence_id    NUMBER
929 )RETURN NUMBER
930 IS
931   l_count1                      NUMBER := 0;
932   l_count2                      NUMBER := 0;
933   cursor pending_on_eco is
934                 select 1
935                   from BOM_OPERATIONAL_ROUTINGS
936                  where routing_sequence_id = p_routing_sequence_id
937                    and pending_from_ecn is not null
938                    and pending_from_ecn = p_change_notice;
939   cursor reference_common is
940                 select 1
941                   from BOM_OPERATIONAL_ROUTINGS
942                  where common_routing_sequence_id = p_routing_sequence_id
943                    and common_routing_sequence_id <> routing_sequence_id;
944 BEGIN
945 
946   l_count1 := 0;
947 
948   for l_pending_on_eco in pending_on_eco loop
949     l_count1 := 1;
950   end loop;
951 
952   if l_count1 = 1
953   then
954     l_count2 := 0;
955 
956     for l_reference_common in reference_common loop
957       l_count2 := 1;
958     end loop;
959   end if;
960 
961   return (l_count2);
962 END Check_Reference_Rtg_Common;
963 -- Added by MK on 08/26/2000
964 
965 
966 -- Function Check_Common
967 -- Checks if the bill is referencing another bill as a common bill
968 
969 FUNCTION Check_Common
970 ( p_bill_sequence_id    IN NUMBER
971 )RETURN BOOLEAN
972 IS
973 l_dummy         NUMBER;
974 cursor common_exists is select common_assembly_item_id
975                           from BOM_BILL_OF_MATERIALS
976                          where bill_sequence_id = p_bill_sequence_id
977                            and bill_sequence_id <> source_bill_sequence_id; --R12
978 BEGIN
979   open common_exists;
980   fetch common_exists into l_dummy;
981   close common_exists;
982 
983   IF l_dummy IS NULL
984   THEN
985     return FALSE;
986   ELSE
987     RETURN TRUE;
988   END IF;
989 END Check_Common;
990 
991 /*********************************************************************
992 -- Added by MK on 08/26/2000
993 -- Enhancements for ECO Routing
994 *********************************************************************/
995 -- Function Check Rtg_Common
996 -- Checks if the routing is referencing another routing as a common routing
997 
998 FUNCTION Check_Rtg_Common
999 ( p_routing_sequence_id    IN NUMBER
1000 )RETURN BOOLEAN
1001 IS
1002 l_dummy         NUMBER;
1003 cursor common_exists is select 'Referencing'
1004                           from BOM_OPERATIONAL_ROUTINGS
1005                          where routing_sequence_id = p_routing_sequence_id
1006                            and routing_sequence_id <> common_routing_sequence_id;
1007 BEGIN
1008   open common_exists;
1009   fetch common_exists into l_dummy;
1010   close common_exists;
1011 
1012   IF l_dummy IS NULL
1013   THEN
1014     return FALSE;
1015   ELSE
1016     RETURN TRUE;
1017   END IF;
1018 END Check_Rtg_Common;
1019 
1020 
1021 /******************************************************************************
1022 * Function      : ECO_Approval_Requested
1023 * Parameters IN : Change Notice
1024 *                 Organization ID
1025 * Returns       : True or False
1026 * Purpose       : Function will verify if the change notice has an approval
1027 *                 status of "Approval Requested". If it does then the procedure
1028 *                 will return True else it will return False.
1029 ******************************************************************************/
1030 FUNCTION ECO_Approval_Requested
1031 ( p_change_notice       IN VARCHAR2
1032 , p_organization_id     IN NUMBER
1033 )RETURN BOOLEAN
1034 IS
1035   l_ret                         BOOLEAN := FALSE;
1036 
1037   CURSOR check_ECO IS
1038                 SELECT 1
1039                   FROM ENG_ENGINEERING_CHANGES
1040                  WHERE change_notice = p_change_notice
1041                    AND organization_id = p_organization_id
1042                    AND approval_status_type = 3;
1043 BEGIN
1044   for l_approval_requested IN check_ECO loop
1045     l_ret := TRUE;
1046   end loop;
1047 
1048   RETURN l_ret;
1049 END ECO_Approval_Requested;
1050 
1051 /*****************************************************************************
1052 * Function      : ECO_Open
1053 * Parameters IN : Change Notice
1054 *                 Organization ID
1055 * Returns       : True or False
1056 * Purpose       : Function will check if the ECO status is Open. If the status
1057 *                 is Open, then the function will return TRUE otherwise FALSE.
1058 ******************************************************************************/
1059 FUNCTION ECO_Open
1060 ( p_change_notice IN VARCHAR2
1061 , p_organization_id IN NUMBER
1062 )RETURN BOOLEAN
1063 IS
1064   l_ret                         BOOLEAN := FALSE;
1065 
1066   CURSOR check_ECO  IS
1067                 SELECT 1
1068                   FROM ENG_ENGINEERING_CHANGES
1069                  WHERE change_notice = p_change_notice
1070                    AND organization_id = p_organization_id
1071                    AND status_type = 1;
1072 BEGIN
1073   FOR l_open IN check_ECO LOOP
1074     l_ret := TRUE;
1075   END LOOP;
1076 
1077   RETURN l_ret;
1078 END ECO_Open;
1079 
1080 
1081 
1082 /****************************************************************************
1083 * Added by MK on 08/26/2000
1084 * Function      : Check_Rtg_Reschedule
1085 * Parameters IN : Revised item exposed column record
1086 *                 Revised item unexposed column record.
1087 * Returns       : BOOLEAN
1088 *                 If the ECO has date that is greater than the disable
1089 *                 date of the any of the revised operations, return False.
1090 * Purpose       : Function will check if the new effective date is greater
1091 *                 than the disable date of any operations on that revised item
1092 *                 and this change notice. If there are any such components then
1093 *                 the function will return FALSE  and the revised item will
1094 *                 not be rescheduled.
1095 ******************************************************************************/
1096 
1097 FUNCTION Check_Rtg_Reschedule
1098 (  p_revised_item_rec           IN  ENG_Eco_PUB.Revised_Item_Rec_Type
1099  , p_rev_item_unexp_rec         IN  Eng_Eco_Pub.Rev_item_unexposed_rec_type
1100 )RETURN BOOLEAN
1101 IS
1102 
1103     l_ret_status BOOLEAN := TRUE ;
1104 
1105     CURSOR rtg_reschedule_valid
1106     IS
1107         SELECT 'Invalid Op Seq Exists'
1108         FROM   SYS.DUAL
1109         WHERE  EXISTS     ( SELECT 'X'
1110                             FROM BOM_OPERATION_SEQUENCES
1111                             WHERE change_notice = p_revised_item_rec.eco_name
1112                             AND routing_sequence_id = p_rev_item_unexp_rec.routing_sequence_id
1113                             AND revised_item_sequence_id =
1114                                                     p_rev_item_unexp_rec.Revised_Item_Sequence_Id
1115                             AND nvl(disable_date, p_revised_item_rec.new_effective_date+ 1)
1116                                         <= p_revised_item_rec.new_effective_date ) ;
1117 BEGIN
1118     FOR Is_Resched_Valid IN rtg_reschedule_valid
1119     LOOP
1120         -- Before returning result, set G_SCHED_DATE_CHANGED. Database
1121         -- writes to ENG_CURRENT_SCHEDULED_DATES in Eng_Revised_Item_Util
1122         -- happen based on this flag.
1123 
1124         Eng_Default_Revised_Item.G_SCHED_DATE_CHANGED := FALSE;
1125         l_ret_status := FALSE ;
1126     END LOOP ;
1127 
1128         RETURN l_ret_status ;
1129 
1130 
1131 END Check_Rtg_Reschedule ;
1132 -- Added by MK on 08/26/2000
1133 
1134 
1135 /****************************************************************************
1136 * Function      : Check_Reschedule
1137 * Parameters IN : Revised item exposed column record
1138 *                 Revised item unexposed column record.
1139 * Returns       : NUMBER
1140 *                 1 - If the ECO  is Approval Requested
1141 *                 2 - If the ECO  has date that is greater than the disable
1142 *                     date of the any of the revised components.
1143 *                 3 - If the ECO has date that is greater than the disable
1144 *                     date of the any of the revised operations.
1145 *                     Added by MK on 08/26/2000
1146 *
1147 * Purpose       : Function will check if the new effective date is greater
1148 *                 than the disable date of any components on that revised item
1149 *                 and this change notice. If there are any such components then
1150 *                 the function will return a 2 and the revised item will
1151 *                 not be rescheduled otherwise it will check if the ECO has
1152 *                 approval requested, if yes even then the revised item cannot
1153 *                 be rescheduled. If none of these conitions are satisfied then
1154 *                 the function return True and the revised item can be re-
1155 *                 scheduled.
1156 ******************************************************************************/
1157 FUNCTION Check_Reschedule
1158 (  p_revised_item_rec           IN  ENG_Eco_PUB.Revised_Item_Rec_Type
1159  , p_rev_item_unexp_rec         IN  Eng_Eco_Pub.Rev_item_unexposed_rec_type
1160 )RETURN NUMBER
1161 IS
1162   l_count1                      NUMBER  := 0;
1163   l_count2                      NUMBER  := NULL;
1164   CURSOR reschedule_valid IS
1165                 SELECT 1
1166                   FROM BOM_INVENTORY_COMPONENTS
1167                  WHERE change_notice = p_revised_item_rec.eco_name
1168                    AND bill_sequence_id = p_rev_item_unexp_rec.Bill_Sequence_Id
1169                    AND revised_item_sequence_id =
1170                         p_rev_item_unexp_rec.Revised_Item_Sequence_Id
1171                    AND nvl(disable_date,
1172                            p_revised_item_rec.new_effective_date+ 1)
1173                         <= p_revised_item_rec.new_effective_date
1174                    AND acd_type in (1,2);
1175 
1176 
1177 
1178 BEGIN
1179         l_count1 := 0;
1180         for Is_Resched_Valid in reschedule_valid loop
1181                 l_count1 := 1;
1182         end loop;
1183 
1184         -- Before returning result, set G_SCHED_DATE_CHANGED. Database
1185         -- writes to ENG_CURRENT_SCHEDULED_DATES in Eng_Revised_Item_Util
1186         -- happen based on this flag.
1187         -- By AS on 10/12/99
1188 
1189         IF l_count1 <> 0
1190         THEN
1191                 Eng_Default_Revised_Item.G_SCHED_DATE_CHANGED := FALSE;
1192                 return 2;
1193         ELSIF ECO_Approval_Requested
1194               (  p_change_notice => p_revised_item_rec.eco_name
1195                , p_organization_id => p_rev_item_unexp_rec.organization_id
1196                ) = TRUE
1197         THEN
1198                 Eng_Default_Revised_Item.G_SCHED_DATE_CHANGED := FALSE;
1199                 RETURN 1;
1200         ELSE
1201                 Eng_Default_Revised_Item.G_SCHED_DATE_CHANGED := TRUE;
1202                 RETURN 0;
1203         END IF;
1204 
1205 END Check_Reschedule;
1206 
1207 /****************************************************************************
1208 * Function      : Check_Date
1209 * Parameters IN : Revised item id
1210 *                 organization id
1211 *                 Plan Name
1212 *                 Schedule date or the new schedule date
1213 * Returns       : True on Success, False otherwise
1214 * Purpose       : Function will check if the schedule date of the revised item
1215 *                 matches with the inventory_use_up_date of the plan. If it
1216 *                 does then the function will return with True otherwise False.
1217 *****************************************************************************/
1218 FUNCTION Check_Date(  p_revised_item_id IN  NUMBER
1219                     , p_organization_id IN  NUMBER
1220                     , p_use_up_plan     IN  VARCHAR2
1221                     , p_schedule_date   IN  DATE
1222                     , x_inventory_use_up_date   OUT NOCOPY DATE
1223                     )
1224 RETURN BOOLEAN
1225 IS
1226         CURSOR c_CheckUseUpDate IS
1227                 SELECT inventory_use_up_date
1228                   FROM mrp_system_items
1229                  WHERE inventory_use_up_date = p_schedule_date
1230                    AND inventory_item_id     = p_revised_item_id
1231                    AND organization_id       = p_organization_id
1232                    AND compile_designator    = p_use_up_plan;
1233 BEGIN
1234         FOR CheckUseUpDate IN c_CheckUseUpDate LOOP
1235                 x_inventory_use_up_date := CheckUseUpDate.inventory_use_up_date;
1236                 RETURN TRUE;
1237         END LOOP;
1238 
1239         x_inventory_use_up_date := SYSDATE;
1240         RETURN FALSE;
1241 
1242 END Check_Date;
1243 
1244 
1245 
1246 
1247 /*****************************************************************************
1248 * Added by MK on 12/01/2000
1249 * Function      : Val_Rev_Item_for_Rtg
1250 * Parameters IN : Revised item Id
1251 *                 Organization Id
1252 * Returns       : True if the revised item can be on Routing.
1253 * Purpose       : Verify if the given revised item is not planning item, pto item
1254 *                 and its attribute: Bom allowed is true.
1255 ******************************************************************************/
1256 FUNCTION Val_Rev_Item_for_Rtg
1257                           ( p_revised_item_id   NUMBER
1258                           , p_organization_id   NUMBER  )
1259 RETURN BOOLEAN
1260 IS
1261     l_PLANNING          CONSTANT NUMBER := 3 ;
1262 
1263     -- Get Revised Item Attr. Value
1264     CURSOR   l_item_cur (p_org_id NUMBER, p_item_id NUMBER) IS
1265        SELECT   bom_item_type
1266               , pick_components_flag
1267               , bom_enabled_flag
1268               , eng_item_flag
1269        FROM  MTL_SYSTEM_ITEMS
1270        WHERE (  bom_enabled_flag <> 'Y'
1271              OR pick_components_flag <> 'N'
1272              OR bom_item_type = l_PLANNING )
1273        AND   organization_id   = p_org_id
1274        AND   inventory_item_id = p_item_id
1275        ;
1276 
1277 BEGIN
1278 
1279        -- First Query all the attributes for the Assembly item used Entity Validation
1280        FOR l_item_rec IN l_item_cur(  p_org_id  => p_organization_id
1281                                     , p_item_id => p_revised_item_id
1282                                     )
1283        LOOP
1284            RETURN FALSE;
1285        END LOOP ;
1286 
1287            RETURN TRUE;
1288 
1289 END Val_Rev_Item_for_Rtg ;
1290 -- Added by MK 12/01/2000
1291 
1292 
1293 /*********************************************************************
1294 -- Added by MK on 08/26/2000
1295 -- Enhancements for ECO Routing
1296 -- Check CTP Flag:Yes is Unique
1297 *********************************************************************/
1298 FUNCTION Check_CTP_Flag (  p_revised_item_id  	 IN  NUMBER
1299                          , p_organization_id  	 IN  NUMBER
1300                          , p_cfm_routing_flag    IN  NUMBER
1301 			 , p_routing_sequence_id IN NUMBER)
1302 RETURN BOOLEAN
1303 IS
1304 
1305      CURSOR l_ctp_csr    (  p_revised_item_id  NUMBER
1306                           , p_organization_id  NUMBER
1307                           , p_cfm_routing_flag NUMBER
1308 			  , p_routing_sequence_id NUMBER)
1309 
1310      IS
1311          SELECT 'CTP not unique'
1312          FROM   SYS.DUAL
1313          WHERE  EXISTS  (SELECT NULL
1314                          FROM   BOM_OPERATIONAL_ROUTINGS
1315                          WHERE  ctp_flag = 1 -- Yes
1316                          AND    NVL(cfm_routing_flag, 2)  = NVL(p_cfm_routing_flag, 2)
1317                          AND    organization_id = p_organization_id
1318                          AND    assembly_item_id = p_revised_item_id
1319 			 AND    routing_sequence_id <> p_routing_sequence_id) ;
1320 
1321 l_ret_status BOOLEAN := TRUE ;
1322 
1323 BEGIN
1324     FOR l_ctp_rec IN l_ctp_csr (  p_revised_item_id
1325                                 , p_organization_id
1326                                 , p_cfm_routing_flag
1327 				, p_routing_sequence_id)
1328     LOOP
1329         l_ret_status := FALSE ;
1330     END LOOP ;
1331         RETURN l_ret_status ;
1332 
1333 END Check_CTP_Flag ;
1334 -- Added by MK on 08/26/2000
1335 
1336 
1337 /*********************************************************************
1338 -- Added by MK on 08/26/2000
1339 -- Enhancements for ECO Routing
1340 -- Check if Priority is unique
1341 *********************************************************************/
1342 FUNCTION Check_Priority (  p_revised_item_id  IN  NUMBER
1343                          , p_organization_id  IN  NUMBER
1344                          , p_cfm_routing_flag IN  NUMBER
1345                          , p_priority         IN  NUMBER )
1346 RETURN BOOLEAN
1347 IS
1348 
1349      CURSOR l_priority_csr   (  p_revised_item_id  NUMBER
1350                               , p_organization_id  NUMBER
1351                               , p_cfm_routing_flag NUMBER
1352                               , p_priority         NUMBER )
1353 
1354      IS
1355          SELECT 'Priority not unique'
1356          FROM   SYS.DUAL
1357          WHERE  EXISTS  (SELECT NULL
1358                          FROM   BOM_OPERATIONAL_ROUTINGS
1359                          WHERE  priority = p_priority
1360                          AND    NVL(cfm_routing_flag, 2)  = NVL(p_cfm_routing_flag, 2)
1361                          AND    organization_id = p_organization_id
1362                          AND    assembly_item_id = p_revised_item_id) ;
1363 
1364 l_ret_status BOOLEAN := TRUE ;
1365 
1366 BEGIN
1367 
1368     FOR l_priority_rec  IN l_priority_csr (  p_revised_item_id
1369                                            , p_organization_id
1370                                            , p_cfm_routing_flag
1371                                            , p_priority         )
1372     LOOP
1373         l_ret_status := FALSE ;
1374     END LOOP ;
1375         RETURN l_ret_status ;
1376 
1377 END Check_Priority ;
1378 -- Added by MK on 08/26/2000
1379 
1380 
1381 /*********************************************************************
1382 -- Added by MK on 08/26/2000
1383 -- Enhancements for ECO Routing
1384 -- Check if Subinventory Exists
1385 *********************************************************************/
1386 FUNCTION Check_SubInv_Exists(  p_organization_id  IN  NUMBER
1387                              , p_subinventory     IN VARCHAR2 )
1388 RETURN BOOLEAN
1389 IS
1390 
1391    -- cursor for checking subinventory exsiting
1392    CURSOR l_subinv_csr         ( p_organization_id NUMBER
1393                                , p_subinventory    VARCHAR2)
1394    IS
1395       SELECT 'SubInv exists'
1396       FROM   SYS.DUAL
1397       WHERE  NOT EXISTS ( SELECT  null
1398                           FROM mtl_secondary_inventories
1399                           WHERE organization_id =  p_organization_id
1400                           AND secondary_inventory_name = p_subinventory
1401                          );
1402 
1403 
1404 l_ret_status BOOLEAN := TRUE ;
1405 
1406 BEGIN
1407 
1408     FOR l_subinv_rec  IN l_subinv_csr  ( p_organization_id
1409                                        , p_subinventory )
1410     LOOP
1411         l_ret_status := FALSE ;
1412     END LOOP ;
1413         RETURN l_ret_status ;
1414 
1415 END Check_SubInv_Exists ;
1416 -- Added by MK on 08/26/2000
1417 
1418 
1419 /*********************************************************************
1420 -- Added by MK on 08/26/2000
1421 -- Enhancements for ECO Routing
1422 --  Get Restrict Subinventory Flag and Inventory Asset Flag for the Item
1423 *********************************************************************/
1424 PROCEDURE Get_SubInv_Flag (    p_revised_item_id   IN  NUMBER
1425                               , p_organization_id  IN  NUMBER
1426                               , x_rest_subinv_code OUT NOCOPY VARCHAR2
1427                               , x_inv_asset_flag   OUT NOCOPY VARCHAR2 )
1428 IS
1429 
1430    -- cursor for checking subinventory exsiting
1431    CURSOR l_subinv_flag_csr  ( p_organization_id NUMBER
1432                              , p_revised_item_id NUMBER)
1433    IS
1434        SELECT   DECODE(restrict_subinventories_code, 1, 'Y', 'N') restrict_code
1435               , inventory_asset_flag
1436        FROM   MTL_SYSTEM_ITEMS
1437        WHERE  inventory_item_id = p_revised_item_id
1438        AND    organization_id  = p_organization_id  ;
1439 
1440 
1441 BEGIN
1442 
1443     FOR l_subinv_flag_rec  IN l_subinv_flag_csr  ( p_organization_id
1444                                                  , p_revised_item_id)
1445     LOOP
1446         x_rest_subinv_code := l_subinv_flag_rec.restrict_code ;
1447         x_inv_asset_flag   := l_subinv_flag_rec.inventory_asset_flag ;
1448     END LOOP ;
1449 
1450 END Get_SubInv_Flag ;
1451 -- Added by MK on 08/26/2000
1452 
1453 
1454 
1455 /*********************************************************************
1456 -- Added by MK on 08/26/2000
1457 -- Enhancements for ECO Routing
1458 -- Check Locator
1459 *********************************************************************/
1460 
1461 -- Local function to verify locators
1462 FUNCTION Check_Locators (  p_organization_id  IN NUMBER
1463                          , p_revised_item_id  IN NUMBEr
1464                          , p_locator_id       IN NUMBER
1465                          , p_subinventory     IN VARCHAR2 )
1466 RETURN BOOLEAN
1467 IS
1468     Cursor CheckDuplicate is
1469     SELECT 'checking for duplicates' dummy
1470     FROM sys.dual
1471     WHERE EXISTS (
1472                    SELECT null
1473                    FROM mtl_item_locations
1474                    WHERE organization_id = p_organization_id
1475                    AND   inventory_location_id = p_locator_id
1476                    AND subinventory_code <>  p_subinventory
1477                   );
1478 
1479     x_control   NUMBER;
1480     l_success   BOOLEAN;
1481     l_dummy     VARCHAR2(20) ;
1482 
1483 BEGIN
1484 
1485 IF Bom_Globals.Get_Debug = 'Y' THEN
1486     Error_Handler.Write_Debug('Check Locators. . .Locator Id is ' || to_char(p_locator_id));
1487 END IF;
1488 
1489    l_org_locator_control := 0 ;
1490    l_item_locator_control := 0;
1491 
1492 
1493    -- Get Value of Org_Locator and item_Locator.
1494    SELECT stock_locator_control_code
1495    INTO l_org_locator_control
1496    FROM mtl_parameters
1497    WHERE organization_id = p_organization_id;
1498 
1499    -- Get Value of Item Locator
1500    SELECT location_control_code
1501    INTO l_item_locator_control
1502    FROM mtl_system_items
1503    WHERE organization_id = p_organization_id
1504    AND inventory_item_id = p_revised_item_id;
1505 
1506    -- Get if locator is restricted or unrestricted
1507    SELECT RESTRICT_LOCATORS_CODE
1508    INTO l_item_loc_restricted
1509    FROM mtl_system_items
1510    WHERE organization_id = p_organization_id
1511    AND inventory_item_id = p_revised_item_id;
1512 
1513 
1514 IF Bom_Globals.Get_Debug = 'Y' THEN
1515     Error_Handler.Write_Debug('Org - Stock Locator Control : '|| to_char(l_org_locator_control)  );
1516     Error_Handler.Write_Debug('Item - Location Control : '|| to_char(l_item_locator_control)  );
1517     Error_Handler.Write_Debug('Item - Restrict Locator : '|| to_char(l_item_loc_restricted)  );
1518 END IF;
1519 
1520 /**************************************
1521 -- Locator_Control_Code
1522 -- 1 : No Locator Control
1523 -- 2 : Prespecified Locator Control
1524 -- 3 : Dynamic Entiry Locator Control
1525 -- 4 : Determined by Sub Inv Level
1526 -- 5 : Determined at Item Level
1527 ***************************************/
1528 
1529 /*
1530    --
1531    -- Locator cannot be NULL is if locator restricted
1532    --
1533    IF p_locator_id IS NULL
1534    AND l_item_loc_restricted = 1
1535    THEN
1536        l_locator_control := 4;
1537        RETURN FALSE;
1538    ELSIF p_locator_id IS NULL
1539    AND l_item_loc_restricted = 2
1540    THEN
1541        RETURN TRUE;
1542    END IF;
1543 */
1544 
1545 IF Bom_Globals.Get_Debug = 'Y' THEN
1546     Error_Handler.Write_Debug('Sub Inv - Loc Control : '|| to_char(l_sub_locator_control)  );
1547 END IF;
1548 
1549 
1550 
1551    IF l_org_locator_control  is not null AND
1552       l_sub_locator_control  is not null AND
1553       l_item_locator_control is not null
1554    THEN
1555          --   dbms_output.put_line
1556          --   ('Org _Control: ' || to_char(l_org_locator_control));
1557          --    dbms_output.put_line('Sub _Control: ' ||
1558          --    to_char(l_sub_locator_control));
1559          --    dbms_output.put_line('Item Control: ' ||
1560          --    to_char(l_item_locator_control));
1561 
1562 
1563        x_control := BOM_Validate_Rtg_Header.Control
1564        (  Org_Control  => l_org_locator_control,
1565           Sub_Control  => l_sub_locator_control,
1566           Item_Control => l_item_locator_control
1567        );
1568 
1569 IF Bom_Globals.Get_Debug = 'Y' THEN
1570     Error_Handler.Write_Debug('Calling BOM_Validate_Rtg_Header.Control. Loc Control '||
1571                               to_char(x_control)  );
1572 END IF;
1573 
1574        l_locator_control := x_control;
1575        -- Variable to identify if the dynamic loc.
1576        -- Message must be logged.
1577 
1578        IF x_Control = 1  AND p_locator_id IS NOT  NULL  THEN  -- No Locator Control
1579          RETURN FALSE;
1580        ELSIF   p_locator_id IS  NULL  THEN
1581 	 RETURN TRUE;  -- No Locator and Locator Id is
1582                               -- supplied then raise Error
1583        ELSIF x_Control = 2 THEN   -- PRESPECIFIED
1584           BEGIN
1585 
1586 IF Bom_Globals.Get_Debug = 'Y' THEN
1587     Error_Handler.Write_Debug  ('Checking when x_control returned 2 and ' ||
1588                                 ' item locator is ' ||
1589                                 to_char(l_item_locator_control));
1590 END IF;
1591 --bug 2463393 modified the above check
1592             --
1593             -- Locator cannot be NULL is if locator control is prespecified
1594             --
1595             IF p_locator_id IS NULL
1596             AND p_subinventory is NOT NULL
1597             THEN
1598                 l_locator_control := 4;
1599                 RETURN FALSE;
1600             END IF;
1601 
1602 -- If restrict locators is Y then check in
1603 -- mtl_secondary_locators if the item is
1604 -- assigned to the subinventory/location
1605 -- combination If restrict locators is N then
1606 -- check that the locator exists
1607 -- and is assigned to the subinventory and this
1608 -- combination is found in mtl_item_locations.
1609 
1610             IF l_item_loc_restricted = 1 -- Restrict Locators  = YES
1611             THEN
1612                 -- Check for restrict Locators YES
1613 IF Bom_Globals.Get_Debug = 'Y' THEN
1614     Error_Handler.Write_Debug  ('Before Checking for restrict Locators Yes. ' );
1615 END IF;
1616                 SELECT 'Valid'
1617                 INTO l_dummy
1618                 FROM mtl_item_locations mil,
1619                      mtl_secondary_locators msl
1620                 WHERE msl.inventory_item_id = p_revised_item_id
1621                 AND msl.organization_id     = p_organization_id
1622                 AND msl.subinventory_code   = p_subinventory
1623                 AND msl.secondary_locator   = p_locator_id
1624                 AND mil.inventory_location_id = msl.secondary_locator
1625                 AND mil.organization_id     =   msl.organization_id
1626                 AND NVL(mil.disable_date, SYSDATE+1) > SYSDATE ;
1627 
1628 IF Bom_Globals.Get_Debug = 'Y' THEN
1629     Error_Handler.Write_Debug  ('Restrict locators is Y . ' ||
1630                                 'Sub Inv :  ' || p_subinventory || 'Comp Loc : ' || to_char(p_locator_id )
1631                                 || ' are valid.'  );
1632 END IF;
1633 
1634                 -- If no exception is raised then the
1635                 -- Locator is Valid
1636                 RETURN TRUE;
1637 
1638             ELSE
1639                 -- Check for restrict Locators NO
1640 
1641                 SELECT 'Valid'
1642                 INTO l_dummy
1643                 FROM mtl_item_locations mil
1644                 WHERE mil.subinventory_code = p_subinventory
1645                 AND   mil.inventory_location_id = p_locator_id
1646                 AND    mil.organization_id      = p_organization_id
1647                 AND NVL(mil.DISABLE_DATE, SYSDATE+1) > SYSDATE;
1648 
1649 IF Bom_Globals.Get_Debug = 'Y' THEN
1650     Error_Handler.Write_Debug  ('Restrict locators is No . ' ||
1651                                 'Sub Inv :  ' || p_subinventory || 'Comp Loc : ' || to_char(p_locator_id )
1652                                 || ' are valid.'  );
1653 END IF;
1654 
1655                 -- If no exception is raised then the
1656                 -- Locator is Valid
1657                 RETURN TRUE;
1658 
1659             END IF;
1660 
1661          EXCEPTION
1662             WHEN NO_DATA_FOUND THEN
1663 
1664 IF Bom_Globals.Get_Debug = 'Y' THEN
1665     Error_Handler.Write_Debug  ('Locator is invlaid . ' );
1666 END IF ;
1667 
1668                RETURN FALSE;
1669          END; -- x_control=2 Ends
1670 
1671       ELSIF x_Control = 3 THEN
1672          -- DYNAMIC LOCATORS ARE NOT ALLOWED IN OI.
1673          -- Dynamic locators are not allowed in open
1674          -- interface, so raise an error if the locator
1675          -- control is dynamic.
1676 IF Bom_Globals.Get_Debug = 'Y' THEN
1677     Error_Handler.Write_Debug  ('Dynamic Locator Control. ' ) ;
1678 END IF ;
1679          l_locator_control := 3;
1680 
1681 
1682          RETURN FALSE;
1683       ELSE
1684          -- dbms_output.put_line
1685          -- ('Finally returing a true value . . .');
1686          RETURN TRUE;
1687 
1688       END IF; -- X_control Checking Ends
1689 
1690    ELSE
1691       RETURN TRUE;
1692    END IF;  -- If Locator Control check Ends.
1693 
1694 END Check_Locators;
1695 -- Added by MK on 08/26/2000
1696 
1697 
1698 --
1699 -- Function Check_RevItem_BillAlternate
1700 -- Called from Check_Access
1701 --
1702 -- This fuction moved from Rev Comp(Check_Access) to resolove ECO dependency
1703 -- by MK on 12/03/00
1704 FUNCTION Check_RevItem_BillAlternate(  p_revised_item_id         IN  NUMBER
1705                                      , p_organization_id         IN  NUMBER
1706                                      , p_change_notice           IN  VARCHAR2
1707                                      , p_new_item_revision       IN  VARCHAR2
1708                                      , p_new_routing_revsion     IN  VARCHAR2
1709                                      , p_effective_date          IN  DATE
1710                                      , p_from_end_item_number    IN  VARCHAR2
1711                                      )
1712 RETURN BOOLEAN
1713 IS
1714 
1715                 l_return_status BOOLEAN ;
1716 
1717                 CURSOR c_CheckPrimary    (  p_revied_item_id   NUMBER
1718                                           , p_organization_id  NUMBER)
1719                 IS
1720 
1721                     SELECT 1
1722                     FROM bom_bill_of_materials
1723                     WHERE assembly_item_id = p_revied_item_id
1724                     AND   organization_id    = p_organization_id
1725                     AND   NVL(alternate_bom_designator, 'NONE') = 'NONE';
1726 
1727                 CURSOR c_Alternate_Check    (  p_revised_item_id         NUMBER
1728                                              , p_organization_id         NUMBER
1729                                              , p_change_notice           VARCHAR2
1730                                              , p_new_item_revision       VARCHAR2
1731                                              , p_new_routing_revsion     VARCHAR2
1732                                              , p_from_end_item_number    VARCHAR2
1733                                              , p_effective_date          DATE
1734                                              )
1735                 IS
1736 
1737                     SELECT   'Rev Item is only Eco for altenate routing'
1738                     FROM     ENG_REVISED_ITEMS  eri
1739                           ,  BOM_OPERATIONAL_ROUTINGS bor
1740                     WHERE    bor.alternate_routing_designator  IS NOT NULL
1741                     AND      eri.routing_sequence_id         =   bor.routing_sequence_id(+)
1742                     AND      eri.routing_sequence_id        IS NOT NULL
1743                     AND      eri.bill_sequence_id           IS NULL
1744                     AND      NVL(eri.from_end_item_unit_number,FND_API.G_MISS_CHAR)
1745                                                    = NVL(p_from_end_item_number,FND_API.G_MISS_CHAR )
1746                     AND      NVL(eri.new_item_revision,FND_API.G_MISS_CHAR)
1747                                                    = NVL(p_new_item_revision ,FND_API.G_MISS_CHAR)
1748                     AND      NVL(eri.new_routing_revision,FND_API.G_MISS_CHAR)
1749                                                    = NVL(p_new_routing_revsion,FND_API.G_MISS_CHAR)
1750                     AND      TRUNC(eri.scheduled_date)      = TRUNC(p_effective_date)
1751                     AND      eri.change_notice              = p_change_notice
1752                     AND      eri.organization_id            = p_organization_id
1753                     AND      eri.revised_item_id            = p_revised_item_id ;
1754 
1755 
1756 BEGIN
1757 
1758                 FOR CheckPrimary IN c_CheckPrimary(p_revised_item_id, p_organization_id)
1759                 LOOP
1760                         RETURN TRUE ;
1761                 END LOOP;
1762 
1763 
1764                 FOR CheckRevAlt IN c_Alternate_Check
1765                                    (  p_revised_item_id
1766                                     , p_organization_id
1767                                     , p_change_notice
1768                                     , p_new_item_revision
1769                                     , p_new_routing_revsion
1770                                     , p_from_end_item_number
1771                                     , p_effective_date
1772                                     )
1773                 LOOP
1774                         RETURN FALSE ;
1775                 END LOOP;
1776 
1777 
1778 
1779                 -- If the loop does not execute then
1780                 -- return True`
1781 
1782                 RETURN TRUE ;
1783 
1784 END Check_RevItem_BillAlternate ;
1785 
1786 -- Bug 4210718
1787 /*****************************************************************************
1788 * Procedure      : Get_Structure_Type
1789 * Parameters IN  : p_inventory_item_id => Revised item
1790 *                  p_organization_id => Organization Id
1791 *                  p_alternate_bom_code => Alternate_Bom_Designator
1792 * Parameters OUT : x_structure_type_id => Structure Type Id of the bill/alternate
1793 * Purpose        : Fetches the bill's/alternate's structure type.
1794 *******************************************************************************/
1795 PROCEDURE Get_Structure_Type
1796 ( p_inventory_item_id   IN NUMBER
1797 , p_organization_id     IN NUMBER
1798 , p_alternate_bom_code  IN VARCHAR2
1799 , x_structure_type_id   OUT NOCOPY NUMBER
1800 ) IS
1801   CURSOR get_bill_structure_type IS
1802   SELECT structure_type_id
1803   FROM bom_structures_b
1804   WHERE assembly_item_id = p_inventory_item_id
1805   AND organization_id = p_organization_id
1806   AND ((alternate_bom_designator IS NULL AND p_alternate_bom_code IS NULL)
1807       OR (p_alternate_bom_code IS NOT NULL AND alternate_bom_designator = p_alternate_bom_code));
1808 
1809   CURSOR get_alt_structure_type IS
1810   SELECT bad.structure_type_id
1811   FROM bom_alternate_designators bad
1812   WHERE ((p_alternate_bom_code IS NULL AND bad.alternate_designator_code IS NULL AND bad.organization_id = -1)
1813         OR (p_alternate_bom_code IS NOT NULL AND bad.alternate_designator_code = p_alternate_bom_code
1814             AND bad.organization_id = p_organization_id));
1815 
1816 BEGIN
1817     IF x_structure_type_id IS NULL
1818     THEN
1819       OPEN get_bill_structure_type;
1820       FETCH get_bill_structure_type INTO x_structure_type_id ;
1821       CLOSE get_bill_structure_type;
1822       IF x_structure_type_id IS NULL
1823       THEN
1824         OPEN get_alt_structure_type;
1825         FETCH get_alt_structure_type INTO x_structure_type_id ;
1826         CLOSE get_alt_structure_type;
1827       END IF;
1828     END IF;
1829 EXCEPTION
1830 WHEN OTHERS THEN
1831     IF get_bill_structure_type%ISOPEN THEN
1832        CLOSE get_bill_structure_type;
1833     END IF;
1834     IF get_alt_structure_type%ISOPEN THEN
1835        CLOSE get_alt_structure_type;
1836     END IF;
1837 END Get_Structure_Type;
1838 
1839 -- Bug 4210718
1840 /*****************************************************************************
1841 * Procedure      : Check_Structure_Type_Policy
1842 * Parameters IN  : p_inventory_item_id => Revised item
1843 *                  p_organization_id => Organization Id
1844 *                  p_alternate_bom_code => Alternate_Bom_Designator
1845 * Parameters OUT : x_structure_type_id => Structure Type Id of the bill/alternate
1846 *                  x_strc_cp_not_allowed => 1 if change policy is not allowed
1847 *                                              , 2 otherwise
1848 * Purpose        : To check if the a bill for given revised item with the given
1849 *                  alternate designator has structure policy NOT_ALLOWED
1850 *                  associated with its structure type.
1851 *******************************************************************************/
1852 PROCEDURE Check_Structure_Type_Policy
1853 ( p_inventory_item_id   IN NUMBER
1854 , p_organization_id     IN NUMBER
1855 , p_alternate_bom_code  IN VARCHAR2
1856 , x_structure_type_id   OUT NOCOPY NUMBER
1857 , x_strc_cp_not_allowed OUT NOCOPY NUMBER
1858 ) IS
1859 
1860   l_rev_policy  VARCHAR2(30);
1861 BEGIN
1862     Get_Structure_Type(p_inventory_item_id, p_organization_id, p_alternate_bom_code, x_structure_type_id);
1863     x_strc_cp_not_allowed := 2;
1864 
1865     l_rev_policy := BOM_GLOBALS.Get_Change_Policy_Val (p_item_id => p_inventory_item_id,
1866                                                        p_org_id => p_organization_id,
1867                                                        p_rev_id => NULL,
1868                                                        p_rev_date => sysdate,
1869                                                        p_structure_type_id => x_structure_type_id);
1870     IF l_rev_policy = 'NOT_ALLOWED'
1871     THEN
1872       x_strc_cp_not_allowed := 1;
1873     END IF;
1874 
1875 EXCEPTION
1876 WHEN OTHERS THEN
1877     x_strc_cp_not_allowed := 2;
1878 END Check_Structure_Type_Policy;
1879 --
1880 -- Function Check_RevItem_BillAlternate
1881 -- Called from Check_Access
1882 --
1883 -- This fuction moved from Rev Op(Check_Access) to resolove ECO dependency
1884 -- by MK on 12/03/00
1885 --
1886 FUNCTION Check_RevItem_RtgAlternate    (  p_revised_item_id         IN  NUMBER
1887                                          , p_organization_id         IN  NUMBER
1888                                          , p_change_notice           IN  VARCHAR2
1889                                          , p_new_item_revision       IN  VARCHAR2
1890                                          , p_new_routing_revsion     IN  VARCHAR2
1891                                          , p_effective_date          IN  DATE
1892                                          , p_from_end_item_number    IN VARCHAR2
1893                                          )
1894 RETURN BOOLEAN
1895 IS
1896 
1897                 l_return_status BOOLEAN ;
1898 
1899                 CURSOR c_CheckPrimary    (  p_revied_item_id   NUMBER
1900                                           , p_organization_id  NUMBER)
1901                 IS
1902 
1903                     SELECT 1
1904                     FROM  BOM_OPERATIONAL_ROUTINGS
1905                     WHERE assembly_item_id = p_revied_item_id
1906                     AND   organization_id    = p_organization_id
1907                     AND   NVL(alternate_routing_designator, 'NONE') = 'NONE';
1908 
1909                 CURSOR c_Alternate_Check    (  p_revised_item_id         NUMBER
1910                                              , p_organization_id         NUMBER
1911                                              , p_change_notice           VARCHAR2
1912                                              , p_new_item_revision       VARCHAR2
1913                                              , p_new_routing_revsion     VARCHAR2
1914                                              , p_from_end_item_number    VARCHAR2
1915                                              , p_effective_date          DATE
1916                                              )
1917                 IS
1918 
1919 
1920                     SELECT   'Rev Item is only Eco for altenate routing'
1921                     FROM     ENG_REVISED_ITEMS  eri
1922                           ,  BOM_BILL_OF_MATERIALS bom
1923                     WHERE    bom.alternate_bom_designator   IS NOT NULL
1924                     AND      eri.bill_sequence_id           =   bom.bill_sequence_id(+)
1925                     AND      eri.bill_sequence_id           IS NOT NULL
1926                     AND      eri.routing_sequence_id        IS NULL
1927                     AND      NVL(eri.from_end_item_unit_number, FND_API.G_MISS_CHAR)
1928                                                    = NVL(p_from_end_item_number, FND_API.G_MISS_CHAR)
1929                     AND      NVL(eri.new_item_revision,FND_API.G_MISS_CHAR)
1930                                                    = NVL(p_new_item_revision ,FND_API.G_MISS_CHAR)
1931                     AND      NVL(eri.new_routing_revision,FND_API.G_MISS_CHAR)
1932                                                    = NVL(p_new_routing_revsion,FND_API.G_MISS_CHAR)
1933                     AND      TRUNC(eri.scheduled_date)      = trunc(p_effective_date)
1934                     AND      eri.change_notice              = p_change_notice
1935                     AND      eri.organization_id            = p_organization_id
1936                     AND      eri.revised_item_id            = p_revised_item_id ;
1937 
1938 
1939 
1940 BEGIN
1941 
1942                 FOR CheckPrimary IN c_CheckPrimary(p_revised_item_id, p_organization_id)
1943                 LOOP
1944                         RETURN TRUE ;
1945                 END LOOP;
1946 
1947 
1948                 FOR CheckRevAlt IN c_Alternate_Check
1949                                             (  p_revised_item_id
1950                                              , p_organization_id
1951                                              , p_change_notice
1952                                              , p_new_item_revision
1953                                              , p_new_routing_revsion
1954                                              , p_from_end_item_number
1955                                              , p_effective_date
1956                                              )
1957 
1958                 LOOP
1959                         RETURN FALSE ;
1960                 END LOOP;
1961 
1962 
1963 
1964                 -- If the loop does not execute then
1965                 -- return True`
1966 
1967                 RETURN TRUE ;
1968 
1969 END Check_RevItem_RtgAlternate ;
1970 
1971 
1972 /*****************************************************************************
1973 * Procedure     : Check_Required
1974 * Parameters IN : Revised item Exposed column record
1975 * Parameters OUT: Mesg Token Table
1976 *                 Return_Status
1977 * Purpose       : Check_Required procedure will verifu that all the required
1978 *                 columns for the revised item entity have been given by the
1979 *                 user. One error message per missing value will be returned
1980 *                 with an error status.
1981 *****************************************************************************/
1982 PROCEDURE Check_Required
1983 (  x_return_status      OUT NOCOPY VARCHAR2
1984  , x_Mesg_Token_Tbl     OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
1985  , p_revised_item_Rec   IN  Eng_Eco_Pub.Revised_Item_Rec_Type
1986  )
1987 IS
1988         l_Mesg_Token_Tbl        Error_Handler.Mesg_Token_Tbl_Type;
1989         l_Token_Tbl             Error_Handler.Token_Tbl_Type;
1990 BEGIN
1991         x_return_status := FND_API.G_RET_STS_SUCCESS;
1992         l_Token_Tbl(1).Token_name := 'REVISED_ITEM_NAME';
1993         l_Token_Tbl(1).Token_Value := p_revised_item_Rec.revised_item_name;
1994 
1995         BOM_Globals.Set_Require_Item_Rev
1996                 (FND_PROFILE.VALUE('ENG:ECO_REVISED_ITEM_REVISION'));
1997 
1998     IF (Bom_globals.Get_Caller_Type = BOM_GLOBALS.G_MASS_CHANGE) THEN
1999                 Null;
2000     ELSE
2001         IF ( p_revised_item_rec.new_revised_item_revision IS NULL OR
2002              p_revised_item_rec.new_revised_item_revision = FND_API.G_MISS_CHAR
2003             ) AND
2004             NVL(BOM_Globals.Is_Item_Rev_Required, 0) = 1
2005         THEN
2006                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2007                 THEN
2008                         Error_Handler.Add_Error_Token
2009                         (  p_Message_Name       => 'ENG_NEW_REVISION_MISSING'
2010                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2011                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2012                          , p_Token_Tbl          => l_Token_Tbl
2013                          );
2014                 END IF;
2015                 x_return_status := FND_API.G_RET_STS_ERROR;
2016         END IF;
2017     END IF;
2018 
2019         IF NVL(BOM_Globals.Is_Item_Rev_Required, 0) = 1 AND
2020            p_revised_item_rec.updated_revised_item_revision =
2021                                         FND_API.G_MISS_CHAR
2022            AND
2023            p_revised_item_rec.alternate_bom_code IS NULL AND
2024            p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE
2025         THEN
2026                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2027                 THEN
2028                         Error_Handler.Add_Error_Token
2029                         (  p_Message_Name       =>'ENG_UPDATED_REVISION_MISSING'
2030                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2031                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2032                          , p_Token_Tbl          => l_Token_Tbl
2033                         );
2034                 END IF;
2035                 x_return_status := FND_API.G_RET_STS_ERROR;
2036         END IF;
2037 
2038         x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
2039 
2040 END Check_Required;
2041 
2042 /******************************************************************************
2043 * Procedure     : Check_Entity
2044 * Parameters IN : Revised item exposed column record
2045 *                 Revised item unexposed column record
2046 *                 Old revised item exposed column record
2047 *                 Old revised item unexposed column record
2048 * Parameters OUT: Mesg Token Table
2049 *                 Return_Status
2050 * Purpose       : Check_Entity procedure will execute the business logic to
2051 *                 validate the revised item entity. It will perform all the
2052 *                 necessary cross entity validations and will also make sure
2053 *                 the user is not entering conflicting values for columns.
2054 ******************************************************************************/
2055 PROCEDURE Check_Entity
2056 (  p_revised_item_rec           IN  ENG_Eco_PUB.Revised_Item_Rec_Type
2057  , p_rev_item_unexp_rec         IN  Eng_Eco_Pub.Rev_Item_Unexposed_Rec_Type
2058  , p_old_revised_item_rec       IN  ENG_Eco_PUB.Revised_Item_Rec_Type
2059  , p_old_rev_item_unexp_rec     IN  Eng_Eco_Pub.Rev_Item_Unexposed_Rec_Type
2060  , p_control_rec                IN  BOM_BO_Pub.Control_Rec_Type
2061                                         := BOM_BO_PUB.G_DEFAULT_CONTROL_REC
2062  , x_Mesg_Token_Tbl             OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
2063  , x_Return_Status              OUT NOCOPY VARCHAR2
2064 )
2065 IS
2066         l_return_status               VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
2067         l_new_revision_status         NUMBER := 0;
2068         l_assembly_type               NUMBER := 0;
2069         l_err_text                    VARCHAR2(2000) := NULL;
2070         l_current_item_revision       VARCHAR2(3);
2071         l_result                      NUMBER;
2072         l_change_notice               VARCHAR2(10) := NULL;
2073         l_revision                    VARCHAR2(3) := NULL;
2074         l_is_item_unit_controlled     BOOLEAN := FALSE;
2075 
2076         l_dup_exists                  NUMBER := 0;
2077 	l_ret_Value                   BOOLEAN ;
2078 	l_plm_or_erp_change           VARCHAR2(3); -- Added for bug 3618676
2079         l_from_revision               VARCHAR2(3);
2080         l_message_name                VARCHAR2(80);
2081 
2082         CURSOR CheckDupUnit IS
2083         SELECT 'x'
2084           FROM eng_revised_items
2085          WHERE revised_item_id = p_rev_item_unexp_rec.revised_item_id
2086            AND from_end_item_unit_number = p_revised_item_rec.From_End_Item_Unit_Number
2087            AND revised_item_sequence_id <> NVL(p_rev_item_unexp_rec.revised_item_sequence_id,0)
2088            AND change_notice = p_revised_item_rec.eco_name;
2089 
2090         CURSOR CheckDupDateUnit IS
2091         SELECT 'x'
2092           FROM eng_revised_items
2093          WHERE revised_item_id = p_rev_item_unexp_rec.revised_item_id
2094            AND from_end_item_unit_number = NVL(p_revised_item_rec.New_From_End_Item_Unit_Number,
2095                                         (NVL(p_revised_item_rec.From_End_Item_Unit_Number,
2096                                                 FND_API.G_MISS_NUM)))
2097            AND scheduled_date = NVL(p_revised_item_rec.New_Effective_Date,
2098                                                 p_revised_item_rec.Start_Effective_Date)
2099            AND new_item_revision = NVL(p_revised_item_rec.updated_revised_item_revision,
2100                                         (NVL(p_revised_item_rec.new_revised_item_revision,
2101                                                 FND_API.G_MISS_NUM)))
2102            AND organization_id = p_rev_item_unexp_rec.organization_id
2103            AND change_notice = p_revised_item_rec.eco_name;
2104 
2105         l_ECO_approved  NUMBER := 0;
2106         cursor c_CheckEcoApproval IS
2107                 SELECT 1
2108                   FROM eng_engineering_changes
2109                  WHERE change_notice = p_revised_item_rec.eco_name
2110                    AND organization_id = p_rev_item_unexp_rec.organization_id
2111                    AND approval_status_type = 5;
2112 
2113         l_bom_enabled_flag      VARCHAR2(1);
2114         CURSOR c_CheckBomEnabled IS
2115                 SELECT bom_enabled_flag
2116                   FROM mtl_system_items msi
2117                  WHERE msi.inventory_item_id =
2118                                 p_rev_item_unexp_rec.revised_item_id
2119                    AND msi.organization_id =
2120                                 p_rev_item_unexp_rec.organization_id;
2121 
2122         l_alternate_bom_designator VARCHAR2(10) := NULL;
2123 
2124         CURSOR c_GetAlternateDesignator IS
2125                  SELECT alternate_bom_designator
2126                    FROM bom_bill_of_materials
2127                   WHERE bill_sequence_id =
2128                                 nvl(p_rev_item_unexp_rec.bill_sequence_id,
2129                                         FND_API.G_MISS_NUM);
2130 
2131         l_product_family        BOOLEAN := FALSE;
2132         CURSOR c_CheckItemProductFamily IS
2133                 SELECT 'Product Family'
2134                   FROM mtl_system_items
2135                  WHERE inventory_item_id = p_rev_item_unexp_rec.revised_item_id
2136                    AND organization_id   = p_rev_item_unexp_rec.organization_id
2137                    AND bom_item_type     = 5;    -- Product Family
2138 
2139         /*******************************************************************
2140         --
2141         -- Cursor will check if the given use_up_item is one from the
2142         -- list of implemented components on the bill
2143         -- The value for use_up_date is queried in the previous validation
2144         -- where it is checked if the inventory_use_up_date must be equal to
2145         -- the schedule date.
2146         -- This quering may actually not be required and the scheduled date
2147         -- can just be used.
2148         --
2149         ********************************************************************/
2150          CURSOR c_CheckUseUpItem(   p_revised_item_id           NUMBER
2151                                   , p_alternate_designator      VARCHAR2
2152                                   , p_organization_id           NUMBER
2153                                   , p_use_up_item_id            NUMBER
2154                                   , p_use_up_date               DATE
2155                                   )
2156         IS
2157         SELECT component_sequence_id
2158           FROM bom_inventory_components bic,
2159                bom_bill_of_materials    bom
2160          WHERE bic.component_item_id = p_use_up_item_id
2161            AND bic.implementation_date IS NOT NULL
2162            AND bic.bill_sequence_id = bom.bill_sequence_id
2163            AND bom.assembly_item_id = p_revised_item_id
2164            AND bom.organization_id  = p_organization_id
2165            AND NVL(bom.alternate_bom_designator, 'NONE') =
2166                NVL(p_alternate_designator, 'NONE')
2167            AND NVL(bic.acd_type, -1) <> 3   -- Modified by MK on 10/30/2000
2168            AND bic.effectivity_date <= NVL(p_use_up_date,SYSDATE)
2169            AND NVL(bic.disable_date,p_use_up_date) >= NVL(p_use_up_date,SYSDATE);                                            -- 2199507
2170 
2171 
2172         /*******************************************************************
2173         -- Following Cusrsors are for New ECO Effectivites and ECO Routing
2174         -- Added by MK on 08/26/2000
2175         ********************************************************************/
2176 
2177         -- Check ECO for Cum Qty
2178         CURSOR l_wipjob_for_eco_cum_csr( p_wip_entity_id       NUMBER
2179                                        , p_bill_sequence_id    NUMBER
2180                                        , p_routing_sequence_id NUMBER )
2181         IS
2182            SELECT    scheduled_start_date
2183                    , start_quantity
2184            FROM    WIP_DISCRETE_JOBS
2185            WHERE   status_type   = 1
2186            AND     wip_entity_id = p_wip_entity_id
2187            AND    ( common_bom_sequence_id = p_bill_sequence_id
2188                     OR  common_routing_sequence_id = p_routing_sequence_id
2189                    ) ;
2190 
2191         l_wipjob_for_eco_cum_rec l_wipjob_for_eco_cum_csr%ROWTYPE ;
2192 
2193 
2194         -- Check ECO for Lot Number
2195         CURSOR l_wipjob_for_eco_lot_csr(  p_lot_number           VARCHAR2
2196                                         , p_start_effective_date DATE
2197                                         , p_org_id               NUMBER
2198                                         , p_rev_item_id          NUMBER
2199                                        )
2200         IS
2201            SELECT    'Lot Number is invalid'
2202            FROM     SYS.DUAL
2203            WHERE    NOT EXISTS  ( SELECT 'Valid Lot'
2204                                   FROM   WIP_DISCRETE_JOBS wdj1
2205                                   WHERE   wdj1.lot_number  = p_lot_number
2206                                   AND     wdj1.status_type = 1
2207                                   AND     wdj1.scheduled_start_date  >= p_start_effective_date
2208                                   AND     wdj1.organization_Id = p_org_id
2209                                   AND     wdj1.primary_item_id = p_rev_item_id
2210                                  )
2211            OR       EXISTS     (SELECT 'Invalid Lot'
2212                                 FROM WIP_DISCRETE_JOBS  wdj2
2213                                 WHERE  wdj2.lot_number = p_lot_number
2214                                 AND    ( wdj2.status_type <> 1 OR
2215                                          wdj2.scheduled_start_date  < p_start_effective_date)
2216                                 AND    wdj2.organization_Id = p_org_id
2217                                 AND    wdj2.primary_item_id = p_rev_item_id
2218                                  ) ;
2219 
2220 
2221          -- Check ECO for WO Order
2222         CURSOR l_wipjob_for_eco_wo_csr(  p_from_wo_num          VARCHAR2
2223                                        , p_to_wo_num            VARCHAR2
2224                                        , p_org_id               NUMBER
2225                                        , p_start_effective_date DATE
2226                                        , p_bill_sequence_id     NUMBER
2227                                        , p_routing_sequence_id  NUMBER )
2228         IS
2229            SELECT    'WO Range is invalid'
2230            FROM     SYS.DUAL
2231            WHERE    NOT  EXISTS  ( SELECT 'Valid WO'
2232                                    FROM    WIP_DISCRETE_JOBS wdj1
2233                                          , WIP_ENTITIES      we1
2234                                    WHERE   wdj1.status_type = 1
2235                                    AND    ( wdj1.common_bom_sequence_id = p_bill_sequence_id
2236                                            OR  wdj1.common_routing_sequence_id = p_routing_sequence_id
2237                                           )
2238                                    AND     wdj1.scheduled_start_date  >= p_start_effective_date
2239                                    AND     wdj1.wip_entity_id = we1.wip_entity_id
2240                                    AND     we1.organization_id = p_org_id
2241                                    AND     we1.wip_entity_name >= p_from_wo_num
2242                                    AND     we1.wip_entity_name <= NVL(p_to_wo_num, p_from_wo_num)
2243                                   )
2244            OR       EXISTS       ( SELECT 'Invalid WO'
2245                                    FROM   WIP_DISCRETE_JOBS wdj2
2246                                        , WIP_ENTITIES      we2
2247                                    WHERE   ( wdj2.status_type <> 1 OR
2248                                             wdj2.scheduled_start_date  < p_start_effective_date )
2249                                    AND    ( wdj2.common_bom_sequence_id = p_bill_sequence_id
2250                                            OR  wdj2.common_routing_sequence_id = p_routing_sequence_id
2251                                           )
2252                                    AND     wdj2.wip_entity_id = we2.wip_entity_id
2253                                    AND     we2.organization_id = p_org_id
2254                                    AND     we2.wip_entity_name >= p_from_wo_num
2255                                    AND     we2.wip_entity_name <= NVL(p_to_wo_num, p_from_wo_num)
2256                                  ) ;
2257 
2258 
2259          -- Check if Routing Info is updated
2260         CURSOR l_rtg_header_csr (  p_revised_item_id        NUMBER
2261                                  , p_alternate_routing_code VARCHAR2
2262                                  , p_org_id                 NUMBER
2263                                 )
2264         IS
2265             SELECT   completion_subinventory
2266                    , completion_locator_id
2267                    , ctp_flag
2268                    , priority
2269             FROM     BOM_OPERATIONAL_ROUTINGS
2270             WHERE    assembly_item_id     =  p_revised_item_id
2271             AND      organization_id      =  p_org_id
2272             AND      alternate_routing_designator = p_alternate_routing_code
2273             ;
2274 
2275        l_rtg_header_rec l_rtg_header_csr%ROWTYPE ;
2276 
2277 
2278 
2279         -- Cursors for completion_subinventory check
2280         CURSOR c_Restrict_SubInv_Asset ( p_revised_item_id NUMBER
2281                                        , p_organization_id NUMBER
2282                                        , p_subinventory    VARCHAR2 )
2283         IS
2284             SELECT locator_type
2285             FROM mtl_item_sub_ast_trk_val_v
2286             WHERE inventory_item_id =  p_revised_item_id
2287             AND organization_id = p_organization_id
2288             AND secondary_inventory_name = p_subinventory;
2289 
2290 
2291         CURSOR c_Restrict_SubInv_Trk  (  p_revised_item_id NUMBER
2292                                        , p_organization_id NUMBER
2293                                        , p_subinventory    VARCHAR2 )
2294 
2295         IS
2296             SELECT locator_type
2297             FROM  mtl_item_sub_trk_val_v
2298             WHERE inventory_item_id =  p_revised_item_id
2299             AND organization_id = p_organization_id
2300             AND secondary_inventory_name = p_subinventory;
2301 
2302 
2303         CURSOR c_SubInventory_Asset   (  p_organization_id NUMBER
2304                                        , p_subinventory    VARCHAR2 )
2305         IS
2306             SELECT locator_type
2307             FROM mtl_sub_ast_trk_val_v
2308             WHERE organization_id = p_organization_id
2309             AND   secondary_inventory_name = p_subinventory;
2310 
2311 
2312 
2313         CURSOR c_SubInventory_Tracked  ( p_organization_id NUMBER
2314                                        , p_subinventory    VARCHAR2 )
2315         IS
2316             SELECT locator_type
2317             FROM  mtl_subinventories_trk_val_v
2318             WHERE organization_id = p_organization_id
2319             AND   secondary_inventory_name = p_subinventory;
2320 
2321 
2322         l_alternate_rtg_designator VARCHAR2(10) := NULL ;
2323 
2324         CURSOR c_GetRtgAltDesignator
2325         IS
2326            SELECT alternate_routing_designator
2327            FROM   BOM_OPERATIONAL_ROUTINGS
2328            WHERE  routing_sequence_id = NVL(  p_rev_item_unexp_rec.routing_sequence_id
2329                                             , FND_API.G_MISS_NUM );
2330 
2331 
2332         /*******************************************************************
2333         --End of Cursor Definition  Added by MK on 08/26/2000
2334         ********************************************************************/
2335 
2336 
2337         l_IsUseUpValid          BOOLEAN;
2338         l_IsDateValid           BOOLEAN;
2339         l_Mesg_Token_Tbl        Error_Handler.Mesg_Token_Tbl_Type;
2340         l_Token_Tbl             Error_Handler.Token_Tbl_Type;
2341         l_use_up_date           DATE := SYSDATE;
2342         l_new_rev_required      NUMBER := 0;
2343 
2344         -- Followings are added by MK on 08/26/2000
2345         l_allow_expense_to_asset    VARCHAR2(10);
2346         l_rest_subinv_code          VARCHAR2(1);
2347         l_inv_asset_flag            VARCHAR2(1);
2348 
2349 
2350         l_is_revision_invalid  NUMBER;
2351         l_is_scheduled_date_invalid   NUMBER;
2352 
2353 BEGIN
2354 
2355 IF Bom_Globals.Get_Debug = 'Y' THEN
2356    Error_Handler.Write_Debug('Performing Check Entity in Revised Item - Trans type: ' || p_revised_item_rec.transaction_Type );
2357 END IF;
2358 
2359         --
2360         -- Set revised item token name and value.
2361         --
2362         l_Token_Tbl(1).Token_Name  := 'REVISED_ITEM_NAME';
2363         l_Token_Tbl(1).Token_Value := p_revised_item_rec.revised_item_name;
2364 
2365         IF p_control_rec.caller_type = 'FORM' AND
2366            p_rev_item_unexp_rec.revised_item_id IS NULL
2367         THEN
2368                 --  Done validating entity
2369 
2370                 x_return_status := l_return_status;
2371                 x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
2372                 RETURN;
2373         END IF;
2374         IF p_control_rec.caller_type <> 'FORM'
2375         THEN
2376                 l_new_rev_required := BOM_Globals.Is_Item_Rev_Required;
2377                 l_is_item_unit_controlled := BOM_Globals.Get_Unit_Controlled_Item;
2378         ELSE
2379                 l_new_rev_required := p_control_rec.require_item_rev;
2380                 l_is_item_unit_controlled := p_control_rec.unit_controlled_item;
2381         END IF;
2382 
2383 	-- Initialize PLM or ERP Change
2384 	-- Added for 3618676
2385 	IF (p_control_rec.caller_type = 'SSWA')
2386 	THEN
2387             l_plm_or_erp_change := 'PLM';
2388 	ELSE
2389             l_plm_or_erp_change := Eng_Globals.Get_PLM_Or_ERP_Change(p_revised_item_rec.eco_name, p_rev_item_unexp_rec.organization_id);
2390 	END IF;
2391 /*********************************************************************************
2392 ** Added by MK on 08/25/2000.
2393 ** Check Entity for New ECO Effectivities and ECO Routing.
2394 **********************************************************************************/
2395 
2396         /*********************************************************************
2397          -- If revised item is unit controlled, From Work Order, To Work Order
2398          -- Lot Number and Cum Qty must be null
2399          -- Added by MK 08/25/2000
2400         **********************************************************************/
2401         IF l_is_item_unit_controlled AND
2402            ((p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE OR
2403              p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE)
2404              AND
2405              ( p_revised_item_rec.lot_number               IS NOT NULL OR
2406                p_revised_item_rec.from_cumulative_quantity IS NOT NULL OR
2407                p_rev_item_unexp_rec.to_wip_entity_id       IS NOT NULL OR
2408                p_rev_item_unexp_rec.from_wip_entity_id     IS NOT NULL   )
2409              )
2410         THEN
2411                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2412                 THEN
2413                     Error_Handler.Add_Error_Token
2414                     (  p_Message_Name       => 'ENG_RIT_ACCESS_WOECTV_DENIED'
2415                      , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2416                      , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2417                      , p_Token_Tbl          => l_Token_Tbl
2418                     );
2419                 END IF;
2420                 l_return_status := FND_API.G_RET_STS_ERROR;
2421         END IF;
2422 IF BOM_Globals.get_debug = 'Y' THEN
2423     error_handler.write_debug('After check if rev item is unit conrolled in new eco type. . . the return status : ' ||
2424                               l_Return_Status );
2425 END IF;
2426 
2427 
2428         /*********************************************************************
2429          -- If MRP Active is not No and Update WIP is not Yes, From Work Order,
2430          -- To Work Order Lot Number and Cum Qty must be null
2431          -- Added by MK 08/25/2000
2432         **********************************************************************/
2433         IF (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE OR
2434             p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE  )
2435           AND ( p_revised_item_rec.mrp_active <> 2  OR
2436                 p_revised_item_rec.update_wip <> 1    )
2437           AND
2438              ( p_revised_item_rec.lot_number               IS NOT NULL OR
2439                p_revised_item_rec.from_cumulative_quantity IS NOT NULL OR
2440                p_rev_item_unexp_rec.to_wip_entity_id       IS NOT NULL OR
2441                p_rev_item_unexp_rec.from_wip_entity_id     IS NOT NULL
2442              )
2443         THEN
2444                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2445                 THEN
2446                     Error_Handler.Add_Error_Token
2447                     (  p_Message_Name       => 'ENG_RIT_MAC_UWIP_INVALID'
2448                      , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2449                      , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2450                      , p_Token_Tbl          => l_Token_Tbl
2451                     );
2452                 END IF;
2453                 l_return_status := FND_API.G_RET_STS_ERROR;
2454         END IF;
2455 
2456 IF BOM_Globals.get_debug = 'Y' THEN
2457     error_handler.write_debug('After check new eco type attributes, the return status is ' ||
2458                               l_Return_Status);
2459 END IF;
2460 
2461         /*********************************************************************
2462          -- Followings are Entity Validation for New Effectivities
2463         **********************************************************************/
2464         IF p_revised_item_rec.mrp_active = 2 AND p_revised_item_rec.update_wip = 1
2465         THEN
2466 
2467             /*****************************************************************
2468              -- If From Work Order is not Null then Lot Number must be Null
2469              -- Added by MK 08/25/2000
2470             ******************************************************************/
2471             IF (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE OR
2472                 p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE  )
2473             AND  p_rev_item_unexp_rec.from_wip_entity_id IS NOT NULL
2474             AND  p_revised_item_rec.lot_number           IS NOT NULL
2475             THEN
2476                  IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2477                 THEN
2478                     Error_Handler.Add_Error_Token
2479                     (  p_Message_Name       => 'ENG_RIT_LOTNUM_MUSTBE_NULL'
2480                      , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2481                      , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2482                      , p_Token_Tbl          => l_Token_Tbl
2483                     );
2484                 END IF;
2485                 l_return_status := FND_API.G_RET_STS_ERROR;
2486             END IF;
2487 
2488 IF BOM_Globals.get_debug = 'Y' THEN
2489      error_handler.write_debug('After check lot number and type, the return status is ' ||
2490                                l_Return_Status);
2491 END IF;
2492 
2493             /*****************************************************************
2494              -- If To Work Order is not Null then
2495              -- From Work Order must not be null
2496              -- Added by MK 08/25/2000
2497             ******************************************************************/
2498             IF (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE OR
2499                 p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE  )
2500             AND  p_rev_item_unexp_rec.to_wip_entity_id     IS NOT NULL
2501             AND  p_rev_item_unexp_rec.from_wip_entity_id   IS NULL
2502             THEN
2503                  IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2504                 THEN
2505                     Error_Handler.Add_Error_Token
2506                     (  p_Message_Name       => 'ENG_RIT_FROMWO_MUSTNOT_NULL'
2507                      , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2508                      , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2509                      , p_Token_Tbl          => l_Token_Tbl
2510                     );
2511                 END IF;
2512                 l_return_status := FND_API.G_RET_STS_ERROR;
2513             END IF;
2514 
2515 IF BOM_Globals.get_debug = 'Y' THEN
2516      error_handler.write_debug('After check wip id, the return status is ' || l_Return_Status);
2517 END IF;
2518             /*****************************************************************
2519              -- If To Work Order is not Null then
2520              -- To Work Order must be greater than From Work Order
2521              -- Added by MK 08/25/2000
2522             ******************************************************************/
2523             IF (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE OR
2524                 p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE  )
2525             AND  p_rev_item_unexp_rec.to_wip_entity_id   IS NOT NULL
2526             AND  ( p_revised_item_rec.from_work_order  >  p_revised_item_rec.to_work_order
2527                    OR p_rev_item_unexp_rec.from_wip_entity_id IS NULL)
2528             THEN
2529                  IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2530                 THEN
2531                     Error_Handler.Add_Error_Token
2532                     (  p_Message_Name       => 'ENG_RIT_FROMWO_INVALID'
2533                      , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2534                      , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2535                      , p_Token_Tbl          => l_Token_Tbl
2536                     );
2537                 END IF;
2538                 l_return_status := FND_API.G_RET_STS_ERROR;
2539             END IF;
2540 
2541 IF BOM_Globals.get_debug = 'Y' THEN
2542      error_handler.write_debug('After check work order, the return status is ' || l_Return_Status);
2543 END IF;
2544 
2545            /*****************************************************************
2546              -- If From Work Order and To Work Order is not Null then
2547              -- Cumulative Quantity must be null.
2548              -- Added by MK 08/25/2000
2549             ******************************************************************/
2550             IF (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE OR
2551                 p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE  )
2552             AND  p_rev_item_unexp_rec.to_wip_entity_id   IS NOT NULL
2553             AND  p_rev_item_unexp_rec.from_wip_entity_id IS NOT NULL
2554             AND  p_revised_item_rec.from_cumulative_quantity IS NOT NULL
2555             THEN
2556                  IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2557                 THEN
2558                     Error_Handler.Add_Error_Token
2559                     (  p_Message_Name       => 'ENG_RIT_CUMQTY_INVALID'
2560                      , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2561                      , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2562                      , p_Token_Tbl          => l_Token_Tbl
2563                     );
2564                 END IF;
2565                 l_return_status := FND_API.G_RET_STS_ERROR;
2566             END IF;
2567 
2568 IF BOM_Globals.get_debug = 'Y' THEN
2569      error_handler.write_debug('After check type and cumu, the return status is ' ||
2570                                 l_Return_Status);
2571 END IF;
2572            /*****************************************************************
2573              -- If Cumulative Quantity is not null then
2574              -- From Work Order must not be null and To Work Order must be null.
2575              -- Added by MK 08/25/2000
2576             ******************************************************************/
2577             IF (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE OR
2578                 p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE  )
2579             AND  ( p_rev_item_unexp_rec.from_wip_entity_id     IS NULL
2580                  OR  p_rev_item_unexp_rec.to_wip_entity_id     IS NOT NULL )
2581             AND  p_revised_item_rec.from_cumulative_quantity IS NOT NULL
2582             THEN
2583                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2584                 THEN
2585                     Error_Handler.Add_Error_Token
2586                     (  p_Message_Name       => 'ENG_RIT_ECO_BY_CUMQTY_INVALID'
2587                      , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2588                      , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2589                      , p_Token_Tbl          => l_Token_Tbl
2590                     );
2591                 END IF;
2592                 l_return_status := FND_API.G_RET_STS_ERROR;
2593             END IF;
2594 
2595 IF BOM_Globals.get_debug = 'Y' THEN
2596      error_handler.write_debug('After check cumulative qty and from/to id, the return status is ' ||
2597                                 l_Return_Status);
2598 END IF;
2599 
2600            /*****************************************************************
2601              -- If From Work Order is not null then
2602              -- To Work Order or Cumulative Quantity must not be null.
2603              -- Added by MK 08/25/2000
2604             ******************************************************************/
2605             IF (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE OR
2606                 p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE  )
2607             AND  p_rev_item_unexp_rec.from_wip_entity_id     IS NOT NULL
2608             AND  p_rev_item_unexp_rec.to_wip_entity_id        IS NULL
2609             AND  p_revised_item_rec.from_cumulative_quantity  IS  NULL
2610             THEN
2611                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2612                 THEN
2613                     Error_Handler.Add_Error_Token
2614                     (  p_Message_Name       => 'ENG_RIT_FROMWO_ISNOT_NULL'
2615                      , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2616                      , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2617                      , p_Token_Tbl          => l_Token_Tbl
2618                     );
2619                 END IF;
2620                 l_return_status := FND_API.G_RET_STS_ERROR;
2621             END IF;
2622 
2623 IF BOM_Globals.get_debug = 'Y' THEN
2624      error_handler.write_debug('After check work order and cumulative qty, the return status is ' ||
2625                                 l_Return_Status);
2626 END IF;
2627 
2628             /*****************************************************************
2629              -- If Lot Number is not null then
2630              -- From Work Order, To Work Order and Cum Quantity  must be null.
2631              -- Added by MK 08/25/2000
2632             ******************************************************************/
2633             IF (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE OR
2634                 p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE  )
2635             AND  p_revised_item_rec.lot_number IS NOT NULL
2636             THEN
2637 
2638                 IF ( p_revised_item_rec.from_cumulative_quantity IS NOT NULL OR
2639                      p_rev_item_unexp_rec.to_wip_entity_id       IS NOT NULL OR
2640                      p_rev_item_unexp_rec.from_wip_entity_id     IS NOT NULL
2641                    )
2642                 THEN
2643                     IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2644                     THEN
2645                         Error_Handler.Add_Error_Token
2646                         (  p_Message_Name       => 'ENG_RIT_ECO_BY_LOT_INVALID'
2647                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2648                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2649                          , p_Token_Tbl          => l_Token_Tbl
2650                         );
2651                     END IF;
2652                     l_return_status := FND_API.G_RET_STS_ERROR;
2653 
2654                 /*************************************************************
2655                 -- Validation for ECO Lot
2656                 -- Check if there is unreleased work order with lot number
2657                 -- with start date < effective date
2658                 -- Added by MK 08/26/2000
2659                 *************************************************************/
2660                 ELSE
2661 
2662                     FOR l_wipjob_for_eco_lot_rec IN l_wipjob_for_eco_lot_csr
2663                         (  p_lot_number  =>  p_revised_item_rec.lot_number
2664                          , p_start_effective_date
2665                                          =>  p_revised_item_rec.start_effective_date
2666                          , p_org_id      =>  p_rev_item_unexp_rec.organization_id
2667                          , p_rev_item_id =>  p_rev_item_unexp_rec.revised_item_id
2668                         )
2669                     LOOP
2670                         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2671                         THEN
2672                             Error_Handler.Add_Error_Token
2673                             (  p_Message_Name       => 'ENG_RIT_LOTNUM_WO_RELEASED'
2674                              , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2675                              , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2676                              , p_Token_Tbl          => l_Token_Tbl
2677                             );
2678                         END IF;
2679                         l_return_status := FND_API.G_RET_STS_ERROR;
2680                     END LOOP ;
2681                 END IF ;
2682             END IF ;
2683 
2684 IF BOM_Globals.get_debug = 'Y'THEN
2685     error_handler.write_debug('After check release status, the return status is ' ||
2686                                l_Return_Status);
2687 END IF;
2688 
2689             /*****************************************************************
2690              -- Validation for ECO Cum Qty
2691              -- From Work Order must be unreleased order.
2692              -- From Cum Qty must be smaller or equal than Wip Job's Start Qty
2693              -- Rev Item Effective Date msut be past than WIP Job's start date
2694              -- Added by MK 08/25/2000
2695             ******************************************************************/
2696             IF (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE OR
2697                 p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE  )
2698             AND  p_rev_item_unexp_rec.from_wip_entity_id     IS NOT NULL
2699             AND  p_revised_item_rec.from_cumulative_quantity IS NOT NULL
2700             AND  p_revised_item_rec.lot_number               IS NULL
2701             AND  p_rev_item_unexp_rec.to_wip_entity_id       IS NULL
2702             THEN
2703 
2704                 OPEN  l_wipjob_for_eco_cum_csr
2705                       (  p_wip_entity_id       => p_rev_item_unexp_rec.from_wip_entity_id
2706                       ,  p_bill_sequence_id    => p_rev_item_unexp_rec.bill_sequence_id
2707                       ,  p_routing_sequence_id => p_rev_item_unexp_rec.routing_sequence_id
2708                       );
2709 
2710                 FETCH l_wipjob_for_eco_cum_csr INTO l_wipjob_for_eco_cum_rec ;
2711                     IF l_wipjob_for_eco_cum_csr%NOTFOUND THEN
2712                         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2713                         THEN
2714 
2715                             Error_Handler.Add_Error_Token
2716                             (  p_Message_Name       => 'ENG_RIT_CUMQTY_WO_RELEASED'
2717                              , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2718                              , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2719                              , p_Token_Tbl          => l_Token_Tbl
2720                             );
2721                         END IF;
2722                         l_return_status := FND_API.G_RET_STS_ERROR;
2723                     ELSE
2724                         IF p_revised_item_rec.from_cumulative_quantity > l_wipjob_for_eco_cum_rec.start_quantity
2725                            OR p_revised_item_rec.from_cumulative_quantity < 0
2726                         THEN
2727                             IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2728                             THEN
2729                                     l_Token_Tbl(2).Token_Name  := 'WORK_ORDER';
2730                                     l_Token_Tbl(2).Token_Value := p_revised_item_rec.from_work_order ;
2731 
2732                                     Error_Handler.Add_Error_Token
2733                                     (  p_Message_Name       => 'ENG_RIT_CUMQTY_WO_QTY_INVALID'
2734                                      , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2735                                      , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2736                                      , p_Token_Tbl          => l_Token_Tbl
2737                                     );
2738                             END IF;
2739                             l_return_status := FND_API.G_RET_STS_ERROR;
2740                         END IF ;
2741 
2742                         IF p_revised_item_rec.start_effective_date > l_wipjob_for_eco_cum_rec.scheduled_start_date
2743                         THEN
2744                             IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2745                             THEN
2746                                     l_Token_Tbl(2).Token_Name  := 'WORK_ORDER';
2747                                     l_Token_Tbl(2).Token_Value := p_revised_item_rec.from_work_order ;
2748 
2749                                     Error_Handler.Add_Error_Token
2750                                     (  p_Message_Name       => 'ENG_RIT_CUMQTY_WO_DATE_INVALID'
2751                                      , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2752                                      , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2753                                      , p_Token_Tbl          => l_Token_Tbl
2754                                     );
2755                             END IF;
2756                             l_return_status := FND_API.G_RET_STS_ERROR;
2757                         END IF ;
2758                     END IF ;
2759                CLOSE l_wipjob_for_eco_cum_csr ;
2760            END IF ;
2761 
2762 IF BOM_Globals.get_debug = 'Y' THEN
2763     error_handler.write_debug('After check released status and cum, the return status is ' ||
2764                                l_Return_Status);
2765 END IF;
2766 
2767             /*****************************************************************
2768              -- Validation for ECO WO Number
2769              -- The WOs between From Work Order and To Work Order
2770              -- must be unreleased order.
2771              -- Rev Item Effective Date msut be past than WIP Job's start date
2772              -- Added by MK 08/25/2000
2773             ******************************************************************/
2774             IF (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE OR
2775                 p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE  )
2776             AND  p_rev_item_unexp_rec.from_wip_entity_id     IS NOT NULL
2777             AND  p_revised_item_rec.from_cumulative_quantity IS NULL
2778             AND  p_revised_item_rec.lot_number               IS NULL
2779             AND  p_revised_item_rec.from_work_order <=  p_revised_item_rec.to_work_order
2780 
2781             THEN
2782 
2783                 FOR l_wipjob_for_eco_wo_rec IN l_wipjob_for_eco_wo_csr
2784                 (  p_from_wo_num =>  p_revised_item_rec.from_work_order
2785                  , p_to_wo_num   =>  p_revised_item_rec.to_work_order
2786                  , p_org_id      =>  p_rev_item_unexp_rec.organization_id
2787                  , p_start_effective_date =>  p_revised_item_rec.start_effective_date
2788                  , p_bill_sequence_id     => p_rev_item_unexp_rec.bill_sequence_id
2789                  , p_routing_sequence_id  => p_rev_item_unexp_rec.routing_sequence_id
2790                 )
2791                 LOOP
2792                     IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2793                     THEN
2794                         Error_Handler.Add_Error_Token
2795                         (  p_Message_Name       => 'ENG_RIT_WORANGE_WO_RELEASED'
2796                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2797                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2798                          , p_Token_Tbl          => l_Token_Tbl
2799                          );
2800                      END IF;
2801                      l_return_status := FND_API.G_RET_STS_ERROR;
2802                 END LOOP ;
2803 
2804 IF BOM_Globals.get_debug = 'Y' THEN
2805     error_handler.write_debug('From WO Num : ' || p_revised_item_rec.from_work_order );
2806     error_handler.write_debug('To WO Num : ' ||   p_revised_item_rec.to_work_order );
2807     error_handler.write_debug('Effective Date : ' || to_char(p_revised_item_rec.start_effective_date
2808                                                             ,'YYYY-MM-DD') );
2809     error_handler.write_debug('After check ECO WO Number, the return status is');
2810 END IF;
2811             END IF ;
2812 
2813         END IF ;
2814          --End of Entity Validation for New Effectivities
2815 
2816 IF BOM_Globals.get_debug = 'Y' THEN
2817     error_handler.write_debug('After check new  Effectivities, the return status is ' ||
2818                                 l_Return_Status);
2819 END IF;
2820 
2821         /*****************************************************************
2822         -- Validation for ECO For Production Flag
2823         -- If Eco For Production is Yes, ECO Type should be either
2824         -- ECO by Lot Num, ECO by WO, or ECO by Cum Qty
2825         -- Added by MK 10/06/2000
2826         -- Modified by MK 01/29/2001
2827         -- Eco for produciton must be Yes when Eco type is Eco by Prod
2828         -- also Eco for production must be No when Eco Type is not Eco by Prod.
2829         ******************************************************************/
2830         IF (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE OR
2831             p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE  )
2832           AND p_revised_item_rec.eco_for_production = 1 -- Yes
2833           AND
2834              ( p_revised_item_rec.lot_number               IS NULL AND
2835                p_rev_item_unexp_rec.from_wip_entity_id     IS NULL
2836              )
2837         THEN
2838 
2839             IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2840             THEN
2841                 Error_Handler.Add_Error_Token
2842                 (  p_Message_Name       => 'ENG_RIT_ECO_FOR_PROD_MUSTBE_NO'
2843                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2844                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2845                  , p_Token_Tbl          => l_Token_Tbl
2846                 );
2847             END IF;
2848             l_return_status := FND_API.G_RET_STS_ERROR;
2849 
2850         ELSIF
2851            (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE OR
2852             p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE  )
2853           AND p_revised_item_rec.eco_for_production = 2 -- No
2854           AND
2855              ( p_revised_item_rec.lot_number               IS NOT NULL OR
2856                p_rev_item_unexp_rec.from_wip_entity_id     IS NOT NULL
2857              )
2858         THEN
2859             IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2860             THEN
2861                 Error_Handler.Add_Error_Token
2862                 (  p_Message_Name       => 'ENG_RIT_ECO_FOR_PROD_MUSTBE_Y'
2863                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2864                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2865                  , p_Token_Tbl          => l_Token_Tbl
2866                 );
2867             END IF;
2868             l_return_status := FND_API.G_RET_STS_ERROR;
2869         END IF ;
2870 
2871 
2872         /*********************************************************************
2873          -- Added by MK on 08/26/2000.
2874          -- If revised item is unit controlled, the user must not update
2875          -- modifiy current routing
2876         **********************************************************************/
2877         IF (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE OR
2878                 p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE  )
2879         AND l_is_item_unit_controlled
2880         AND ( p_revised_item_rec.completion_subinventory  IS NOT NULL OR
2881               p_revised_item_rec.new_routing_revision     IS NOT NULL OR
2882               p_revised_item_rec.updated_routing_revision IS NOT NULL OR
2883               p_rev_item_unexp_rec.completion_locator_id  IS NOT NULL OR
2884               NVL(p_revised_item_rec.ctp_flag, Bom_Default_Rtg_Header.Get_Ctp_Flag)
2885                                                <> Bom_Default_Rtg_Header.Get_Ctp_Flag  OR
2886               p_revised_item_rec.routing_comment          IS NOT NULL OR
2887               p_revised_item_rec.priority                 IS NOT NULL   )
2888         THEN
2889 
2890                 OPEN  l_rtg_header_csr ( p_revised_item_id        => p_rev_item_unexp_rec.revised_item_id
2891                                        , p_alternate_routing_code => p_revised_item_rec.alternate_bom_code
2892                                        , p_org_id                 => p_rev_item_unexp_rec.organization_id
2893                                        );
2894 
2895 
2896                 FETCH l_rtg_header_csr INTO l_rtg_header_rec ;
2897                     IF l_rtg_header_csr%FOUND
2898                     AND
2899                     (      l_rtg_header_rec.completion_subinventory <> p_revised_item_rec.completion_subinventory
2900                       OR   p_revised_item_rec.updated_routing_revision <> p_revised_item_rec.new_routing_revision
2901                       OR   l_rtg_header_rec.completion_locator_id <> p_rev_item_unexp_rec.completion_locator_id
2902                       OR   l_rtg_header_rec.ctp_flag <> p_revised_item_rec.ctp_flag
2903                       OR   l_rtg_header_rec.priority <> p_revised_item_rec.priority
2904                     )
2905                     THEN
2906 
2907                         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2908                         THEN
2909                             Error_Handler.Add_Error_Token
2910                             (  p_Message_Name       => 'ENG_RIT_CANNOT_CHANGE_RTG'
2911                              , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2912                              , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2913                              , p_Token_Tbl          => l_Token_Tbl
2914                             );
2915                         END IF;
2916                         l_return_status := FND_API.G_RET_STS_ERROR;
2917                     END IF ;
2918                close l_rtg_header_csr;
2919          END IF ;
2920 
2921 IF BOM_Globals.get_debug = 'Y' THEN
2922     error_handler.write_debug('After check unit control for Routing, the return status is ' ||
2923                                l_Return_Status);
2924 END IF;
2925 
2926 
2927         /*********************************************************************
2928         -- Added by MK on 02/15/2001 insted of below the validation
2929         -- Cannot update alternate routing designator
2930         **********************************************************************/
2931         IF p_revised_item_rec.alternate_bom_code IS NOT NULL AND
2932 	 p_revised_item_rec.alternate_bom_code <> p_old_revised_item_rec.alternate_bom_code AND -- R12:LKASTURI:7/11/2005
2933            p_revised_item_rec.transaction_type = ENG_Globals.G_OPR_UPDATE AND
2934            ( NVL(p_rev_item_unexp_rec.routing_sequence_id, 0) <>
2935                   NVL(p_old_rev_item_unexp_rec.routing_sequence_id, 0) OR
2936              NVL(p_rev_item_unexp_rec.bill_sequence_id, 0) <>
2937                   NVL(p_old_rev_item_unexp_rec.bill_sequence_id, 0)
2938            )
2939         THEN
2940 
2941 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Alternate you have entered : '
2942                                             || p_revised_item_rec.alternate_bom_code ); END IF;
2943 
2944                 l_token_tbl.DELETE;
2945                 l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
2946                 l_token_tbl(1).token_value :=
2947                                         p_revised_item_rec.revised_item_name;
2948                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2949                 THEN
2950                         Error_Handler.Add_Error_Token
2951                         (  p_Message_Name       => 'ENG_ALT_DESG_NOT_UPDATEABLE'
2952                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2953                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2954                          , p_Token_Tbl          => l_Token_Tbl
2955                         );
2956                 END IF;
2957                 l_return_status := FND_API.G_RET_STS_ERROR;
2958 
2959 IF Bom_Globals.Get_Debug = 'Y' THEN
2960     Error_Handler.Write_Debug('After check if alternate code is changed, the return status is ' ||
2961                                l_Return_Status);
2962 END IF;
2963 
2964 
2965         END IF ;
2966 
2967 
2968         /*********************************************************************
2969         -- Added by MK on 08/26/2000
2970         -- Cannot update alternate routing designator
2971         -- Comment out by MK on 02/15/2001 no longer used.
2972         FOR  alt IN c_GetRtgAltDesignator
2973         LOOP
2974              l_alternate_rtg_designator := alt.alternate_routing_designator ;
2975 
2976 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('alternate: ' || l_alternate_rtg_designator); END IF;
2977 
2978         END LOOP;
2979 
2980         IF l_alternate_rtg_designator IS NOT NULL AND
2981            p_revised_item_rec.alternate_bom_code <> l_alternate_rtg_designator AND
2982            p_revised_item_rec.transaction_type = ENG_Globals.G_OPR_UPDATE
2983         THEN
2984                 l_token_tbl.DELETE;
2985                 l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
2986                 l_token_tbl(1).token_value :=
2987                                         p_revised_item_rec.revised_item_name;
2988                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
2989                 THEN
2990                         Error_Handler.Add_Error_Token
2991                         (  p_Message_Name       => 'ENG_ALT_DESG_NOT_UPDATEABLE'
2992                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2993                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
2994                          , p_Token_Tbl          => l_Token_Tbl
2995                         );
2996                 END IF;
2997                 l_return_status := FND_API.G_RET_STS_ERROR;
2998         END IF;
2999         **********************************************************************/
3000 
3001         l_token_tbl.delete;
3002         l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
3003         l_token_tbl(1).token_value := p_revised_item_rec.revised_item_name;
3004 
3005 
3006         /*********************************************************************
3007         -- Added by MK on 12/01/2000
3008         -- Cannot enter New Routing Revision and Routings's Attributes
3009         -- if the revised item is PTO item, Planning Item ,Not Bom Allowed
3010         -- or referencing a common rouitng.
3011         **********************************************************************/
3012 	 IF((p_revised_item_rec.new_routing_revision IS NOT NULL AND
3013             p_revised_item_rec.new_routing_revision <> FND_API.G_MISS_CHAR) OR
3014            (p_revised_item_rec.updated_routing_revision IS NOT NULL AND
3015             p_revised_item_rec.updated_routing_revision <> FND_API.G_MISS_CHAR) OR
3016            ( p_revised_item_rec.completion_subinventory IS NOT NULL AND
3017              p_revised_item_rec.completion_subinventory <> FND_API.G_MISS_CHAR )OR
3018            (p_revised_item_rec.completion_location_name IS NOT NULL AND
3019             p_revised_item_rec.completion_location_name <> FND_API.G_MISS_CHAR )
3020            ) AND
3021         	Not Val_Rev_Item_for_Rtg(  p_revised_item_id => p_rev_item_unexp_rec.revised_item_id
3022                                      , p_organization_id => p_rev_item_unexp_rec.organization_id
3023                                      )
3024         AND  ( ((p_revised_item_rec.new_routing_revision IS NOT NULL) AND
3025 	       (p_revised_item_rec.new_routing_revision <> FND_API.G_MISS_CHAR))
3026 	     OR	(p_revised_item_rec.updated_routing_revision IS NOT NULL AND
3027                  p_revised_item_rec.updated_routing_revision <> FND_API.G_MISS_CHAR)
3028              OR  p_revised_item_rec.ctp_flag <> Bom_Default_Rtg_Header.Get_Ctp_Flag
3029              OR  p_revised_item_rec.completion_subinventory IS NOT NULL
3030              OR  p_revised_item_rec.completion_location_name IS NOT NULL
3031              OR  p_revised_item_rec.priority IS NOT NULL
3032              OR  p_revised_item_rec.routing_comment IS NOT NULL
3033              )
3034         AND  p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE
3035         THEN
3036 
3037                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3038                 THEN
3039                         Error_Handler.Add_Error_Token
3040                         (  p_Message_Name       => 'ENG_RIT_CANNOT_BE_ON_RTG'
3041                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3042                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3043                          , p_Token_Tbl          => l_Token_Tbl
3044                         );
3045                 END IF;
3046                 l_return_status := FND_API.G_RET_STS_ERROR;
3047 
3048 IF Bom_Globals.Get_Debug = 'Y' THEN
3049     Error_Handler.Write_Debug('After check if a rtg can be created for this rev item, the return status is ' || l_Return_Status);
3050 END IF;
3051 
3052 
3053         END IF ;
3054 
3055         /*********************************************************************
3056         -- Added by MK on 08/26/2000
3057         -- Cannot have routing revision, if routing is an alternate.
3058         **********************************************************************/
3059         IF p_revised_item_rec.new_routing_revision IS NOT NULL AND
3060            p_revised_item_rec.alternate_bom_code IS NOT NULL AND
3061            p_revised_item_rec.transaction_type = ENG_Globals.G_OPR_CREATE
3062         THEN
3063                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3064                 THEN
3065                         Error_Handler.Add_Error_Token
3066                         (  p_Message_Name       => 'ENG_CANNOT_HAVE_RTG_REVISION'
3067                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3068                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3069                          , p_Token_Tbl          => l_Token_Tbl
3070                         );
3071 
3072                 END IF;
3073                 l_return_status := FND_API.G_RET_STS_ERROR;
3074         ELSIF p_revised_item_rec.transaction_type = ENG_Globals.G_OPR_UPDATE AND
3075               p_revised_item_rec.alternate_bom_code IS NOT NULL AND
3076               p_revised_item_rec.updated_routing_revision IS NOT NULL
3077         THEN
3078                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3079                 THEN
3080                         Error_Handler.Add_Error_Token
3081                         (  p_Message_Name   => 'ENG_CANNOT_HAVE_RTG_REVISION'
3082                          , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3083                          , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3084                          , p_Token_Tbl      => l_Token_Tbl
3085                         );
3086                 END IF;
3087                 l_return_status := FND_API.G_RET_STS_ERROR;
3088         END IF;
3089 
3090 IF Bom_Globals.Get_Debug = 'Y' THEN
3091    Error_Handler.Write_Debug('After checking rtg revision is null when alt code is not null, the return status is ' || l_return_status );
3092 END IF;
3093 
3094 
3095 
3096         /*********************************************************************
3097         -- Added by MK on 08/26/2000
3098         -- New Routing Revision name is not allowed to use 'Quote'.
3099         **********************************************************************/
3100 
3101          IF INSTR(NVL(p_revised_item_rec.updated_routing_revision,
3102                       p_revised_item_rec.new_routing_revision     )
3103                   , '''') <> 0
3104          THEN
3105               IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3106               THEN
3107                    Error_Handler.Add_Error_Token
3108                    (  p_Message_Name       => 'ENG_RIT_RTGREV_QTE_NOT_ALLOWED'
3109                     , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3110                     , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3111                     , p_Token_Tbl          => l_Token_Tbl
3112                     );
3113               END IF;
3114               l_return_status := FND_API.G_RET_STS_ERROR;
3115 
3116          END IF;
3117 
3118 IF BOM_Globals.get_debug = 'Y' THEN
3119      error_handler.write_debug('After check routing rev, the return status is ' || l_Return_Status);
3120 END IF;
3121 
3122 
3123         /*********************************************************************
3124         -- Added by MK on 08/26/2000
3125         -- Check if the (currently) highest un-implemented routing revision of the
3126         -- revised item exists on another ECO - log warning
3127         *********************************************************************/
3128 
3129         IF (p_control_rec.caller_type = 'FORM'
3130           AND p_revised_item_rec.transaction_type = 'CREATE'
3131           AND p_control_rec.validation_controller = 'REVISED_ITEM')
3132           OR
3133           (p_control_rec.caller_type <> 'FORM' AND p_control_rec.caller_type <> 'SSWA')
3134         THEN
3135 
3136             Pending_High_Rtg_Rev
3137             ( p_change_notice   => p_revised_item_rec.eco_name
3138             , p_organization_id => p_rev_item_unexp_rec.organization_id
3139             , p_revised_item_id => p_rev_item_unexp_rec.revised_item_id
3140             , x_change_notice   => l_change_notice
3141             , x_revision        => l_revision
3142             );
3143 
3144 IF BOM_Globals.get_debug = 'Y'THEN
3145      error_handler.write_debug('After Pending_High_Rtg_Rev, the return status is ' || l_Return_Status);
3146 END IF;
3147 
3148 
3149 
3150             --  Modified by MK on 10/27/2000
3151             --  Warnig is occurred when the current highest un-implemented revision
3152             --  for the revised item exists on another ECO.
3153             --
3154             --  IF l_change_notice IS NOT NULL
3155 
3156             IF l_change_notice <> p_revised_item_rec.eco_name
3157             THEN
3158                 l_token_tbl.delete;
3159                 l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
3160                 l_token_tbl(1).token_value :=  p_revised_item_rec.revised_item_name;
3161                 l_token_tbl(2).token_name  := 'ECO_NAME';
3162                 l_token_tbl(2).token_value := l_change_notice;
3163                 l_token_tbl(3).token_name  := 'REVISION';
3164                 l_token_tbl(3).token_value := l_revision;
3165 
3166                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3167                 THEN
3168                         Error_Handler.Add_Error_Token
3169                         (  p_Message_Name       => 'ENG_RIT_HIGH_RTG_REV_PENDING'
3170                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3171                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3172                          , p_Token_Tbl          => l_Token_Tbl
3173                          , p_message_type       => 'W');
3174                 END IF;
3175             END IF;
3176 
3177 IF BOM_Globals.get_debug = 'Y' THEN
3178      error_handler.write_debug('After check pending eco, the return status is '  ||  l_Return_Status);
3179 END IF;
3180 
3181         END IF;
3182 
3183         /*********************************************************************
3184         -- Added by MK 08/26/2000
3185         -- if the transaction type is create or update, the check new_routing_revision
3186         **********************************************************************/
3187 
3188         IF ( p_revised_item_rec.updated_routing_revision <>
3189              p_old_revised_item_rec.new_routing_revision AND
3190              p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE
3191            ) OR
3192            p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE
3193         THEN
3194                 --
3195                 -- if the transaction type is create, the check new_routing_revision
3196                 --
3197                IF p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE
3198                THEN
3199                   l_new_revision_status :=
3200                   Validate_New_Rtg_Revision
3201                   ( p_revised_item_id     => p_rev_item_unexp_rec.revised_item_id
3202                   , p_organization_id     => p_rev_item_unexp_rec.organization_id
3203                   , p_new_routing_revision      =>
3204                                 p_revised_item_rec.new_routing_revision
3205                   , p_revised_item_sequence_id  =>
3206                                 p_rev_item_unexp_rec.revised_item_sequence_id
3207                   , x_change_notice       => l_change_notice
3208                   );
3209                ELSE /* If Update, pass updated_routing_revision */
3210                   l_new_revision_status :=
3211                   Validate_New_Rtg_Revision
3212                  ( p_revised_item_id         => p_rev_item_unexp_rec.revised_item_id
3213                   , p_organization_id        => p_rev_item_unexp_rec.organization_id
3214                   , p_new_routing_revision   =>
3215                         p_revised_item_rec.updated_routing_revision
3216                   , p_revised_item_sequence_id    =>
3217                         p_rev_item_unexp_rec.revised_item_sequence_id
3218                   , x_change_notice          => l_change_notice
3219                   );
3220                END IF;
3221 
3222                IF l_new_revision_status = 1
3223                THEN
3224                         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3225                         THEN
3226 
3227                             l_token_tbl(1).token_name :=  'REVISED_ITEM_NAME';
3228                             l_token_tbl(1).token_value := p_revised_item_rec.revised_item_name;
3229 
3230                             Error_Handler.Add_Error_Token
3231                             ( p_Message_Name  => 'ENG_RIT_NEW_RTG_REV_NOT_CURR'
3232                             , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3233                             , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3234                             , p_Token_Tbl      => l_Token_Tbl );
3235                         END IF;
3236                         l_return_status := FND_API.G_RET_STS_ERROR;
3237                ELSIF l_new_revision_status = 2
3238                THEN
3239                         l_token_tbl.delete;
3240 
3241                         l_token_tbl(1).token_name :=  'REVISED_ITEM_NAME';
3242                         l_token_tbl(1).token_value := p_revised_item_rec.revised_item_name;
3243 
3244                         -- Added by MK on 11/05/00
3245                         IF p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE
3246                         THEN
3247                             l_token_tbl(2).token_name  := 'NEW_RTG_REVISION';
3248                             l_token_tbl(2).token_value := p_revised_item_rec.new_routing_revision;
3249                         ELSE
3250                             l_token_tbl(2).token_name  := 'NEW_RTG_REVISION';
3251                             l_token_tbl(2).token_value := p_revised_item_rec.updated_routing_revision;
3252                         END IF ;
3253 
3254                         l_token_tbl(3).token_name := 'ECO_NAME';
3255                         l_token_tbl(3).token_value := l_change_notice;
3256 
3257                         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3258                         THEN
3259                                 Error_Handler.Add_Error_Token
3260                                 (  p_Message_Name   => 'ENG_RIT_NEW_RTG_REV_EXISTS'
3261                                  , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3262                                  , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3263                                  , p_token_tbl      => l_token_tbl
3264                                  , p_message_type   => 'E'
3265                                 );
3266                         END IF;
3267 
3268                         l_return_status := FND_API.G_RET_STS_ERROR;
3269                 ELSIF l_new_revision_status = 3
3270                 THEN
3271                         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3272                         THEN
3273 
3274                             l_token_tbl(1).token_name :=  'REVISED_ITEM_NAME';
3275                             l_token_tbl(1).token_value := p_revised_item_rec.revised_item_name;
3276 
3277                             Error_Handler.Add_Error_Token
3278                                 (  p_Message_Name   => 'ENG_RIT_NEW_RTG_REV_IMPL'
3279                                  , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3280                                  , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3281                                  , p_Token_Tbl      => l_Token_Tbl
3282                                 );
3283                         END IF;
3284                         l_return_status := FND_API.G_RET_STS_ERROR;
3285                 END IF;
3286         END IF;
3287 
3288 IF BOM_Globals.get_debug = 'Y' THEN
3289      error_handler.write_debug('After check transaction type, the return status is ' ||  l_Return_Status);
3290 END IF;
3291 
3292 
3293         /*********************************************************************
3294         -- Added by MK 08/26/2000
3295         -- if the transaction type is create or update, the check ctp_flag
3296         **********************************************************************/
3297         IF ( p_revised_item_rec.ctp_flag <> p_old_revised_item_rec.ctp_flag AND
3298              p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE
3299            ) OR
3300            p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE AND
3301            p_revised_item_rec.ctp_flag = 1
3302         THEN
3303             IF NOT Check_CTP_Flag
3304                (  p_revised_item_id    => p_rev_item_unexp_rec.revised_item_id
3305                 , p_organization_id    => p_rev_item_unexp_rec.organization_id
3306                 , p_cfm_routing_flag   => p_rev_item_unexp_rec.cfm_routing_flag
3307 		, p_routing_sequence_id =>
3308 				p_rev_item_unexp_rec.routing_sequence_id
3309                 )
3310             THEN
3311                 IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR)
3312                 THEN
3313                     Error_Handler.Add_Error_Token
3314                     (  p_Message_Name   => 'ENG_RIT_CTP_ALREADY_EXISTS'
3315                      , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3316                      , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3317                      , p_Token_Tbl      => l_Token_Tbl
3318                     );
3319                 END IF;
3320                 l_return_status := FND_API.G_RET_STS_ERROR;
3321             END IF ;
3322 
3323 IF BOM_Globals.get_debug = 'Y' THEN
3324      error_handler.write_debug('After check ctp flag, the return status is '  ||  l_Return_Status);
3325 END IF;
3326         END IF ;
3327 
3328         /*********************************************************************
3329         -- Added by MK 08/26/2000
3330         -- if the transaction type is create or update, the check priority
3331         **********************************************************************/
3332         IF ( p_revised_item_rec.priority <> p_old_revised_item_rec.priority AND
3333              p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE
3334            ) OR
3335            p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE AND
3336            p_revised_item_rec.priority  IS NOT NULL
3337         THEN
3338             IF NOT Check_Priority
3339                (  p_revised_item_id    => p_rev_item_unexp_rec.revised_item_id
3340                 , p_organization_id    => p_rev_item_unexp_rec.organization_id
3341                 , p_cfm_routing_flag   => p_rev_item_unexp_rec.cfm_routing_flag
3342                 , p_priority           => p_revised_item_rec.priority  )
3343             THEN
3344                 IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR)
3345                 THEN
3346                     Error_Handler.Add_Error_Token
3347                     (  p_Message_Name   => 'ENG_RIT_PRIORITY_DUPLICATE'
3348                      , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3349                      , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3350                      , p_Token_Tbl      => l_Token_Tbl
3351                     );
3352                 END IF;
3353                 l_return_status := FND_API.G_RET_STS_ERROR;
3354             END IF ;
3355 
3356 IF BOM_Globals.get_debug = 'Y' THEN
3357      error_handler.write_debug('After check priority, the return status is ' ||  l_Return_Status);
3358 END IF;
3359 
3360         END IF ;
3361 
3362 
3363         /*********************************************************************
3364         -- Added by MK 08/26/2000
3365         -- Check Completion Subinventory
3366         **********************************************************************/
3367 IF Bom_Globals.Get_Debug = 'Y' THEN
3368     Error_Handler.Write_Debug('Performing completeion subinventory check. . . Sub Inv : '
3369                              || p_revised_item_rec.completion_subinventory ) ;
3370     Error_Handler.Write_Debug('Old Completion_subinv is:'||p_old_revised_item_rec.completion_subinventory );
3371 END IF;
3372 
3373         IF (( p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE
3374               AND
3375                   NVL(p_revised_item_rec.completion_subinventory, '0') <>
3376                   NVL(p_old_revised_item_rec.completion_subinventory, '0')
3377           )
3378              OR p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE
3379              )
3380         AND ( p_revised_item_rec.completion_subinventory IS  NULL
3381              OR p_revised_item_rec.completion_subinventory =  FND_API.G_MISS_CHAR)
3382         THEN
3383 
3384 IF Bom_Globals.Get_Debug = 'Y' THEN
3385     Error_Handler.Write_Debug('Inside the process when subinventory is null' ) ;
3386 END IF;
3387 
3388             IF  p_rev_item_unexp_rec.completion_locator_id IS NOT NULL
3389             AND  p_rev_item_unexp_rec.completion_locator_id <>  FND_API.G_MISS_NUM
3390             -- OR  p_rev_item_unexp_rec.completion_locator_id <>  FND_API.G_MISS_NUM
3391             -- updated by MK on 11/15/00
3392             THEN
3393                 l_token_tbl(1).token_name  := 'ASSEMBLY_ITEM_NAME' ;
3394                 l_token_tbl(1).token_value :=  p_revised_item_rec.revised_item_name;
3395                 -- l_token_tbl(2).token_name  :=  'COMPLETION_SUBINVENTORY';
3396                 -- l_token_tbl(2).token_value :=  p_revised_item_rec.completion_subinventory;
3397 
3398                 Error_Handler.Add_Error_Token
3399                 (  p_message_name       =>  'BOM_RTG_LOCATOR_MUST_BE_NULL'
3400                  , p_token_tbl          => l_token_tbl
3401                  , p_mesg_token_tbl     => l_mesg_token_tbl
3402                  , x_mesg_token_tbl     => l_mesg_token_tbl
3403                  );
3404                 l_return_status := FND_API.G_RET_STS_ERROR;
3405              END IF;
3406 
3407         -- Check if Subinventory exists
3408         ELSIF
3409             (( p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE
3410               AND NVL(p_revised_item_rec.completion_subinventory, '0') <>
3411                   NVL(p_old_revised_item_rec.completion_subinventory, '0')
3412             )
3413              OR p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE
3414              )
3415         AND    ( p_revised_item_rec.completion_subinventory IS NOT NULL
3416                OR p_revised_item_rec.completion_subinventory <>  FND_API.G_MISS_CHAR)
3417         THEN
3418 
3419 IF Bom_Globals.Get_Debug = 'Y' THEN
3420     Error_Handler.Write_Debug('Inside the process when subinventory is not null' ) ;
3421 END IF;
3422 
3423             IF NOT Check_SubInv_Exists(p_organization_id =>  p_rev_item_unexp_rec.organization_id
3424                                      , p_subinventory    => p_revised_item_rec.completion_subinventory
3425                                        )
3426             THEN
3427 
3428                 l_token_tbl(1).token_name  := 'ASSEMBLY_ITEM_NAME' ;
3429                 l_token_tbl(1).token_value :=  p_revised_item_rec.revised_item_name ;
3430                 l_token_tbl(2).token_name  := 'COMPLETION_SUBINVENTORY' ;
3431                 l_token_tbl(2).token_value :=  p_revised_item_rec.completion_subinventory ;
3432 
3433                 Error_Handler.Add_Error_Token
3434                 (  p_message_name       =>  'BOM_RTG_SUBINV_NAME_INVALID'
3435                  , p_token_tbl          => l_token_tbl
3436                  , p_mesg_token_tbl     => l_mesg_token_tbl
3437                  , x_mesg_token_tbl     => l_mesg_token_tbl
3438                 ) ;
3439 
3440            ELSE
3441 
3442                l_allow_expense_to_asset := fnd_profile.value
3443                                     ('INV:EXPENSE_TO_ASSET_TRANSFER');
3444 
3445 
3446               Get_SubInv_Flag
3447               (    p_revised_item_id   =>  p_rev_item_unexp_rec.revised_item_id
3448                 ,  p_organization_id   =>  p_rev_item_unexp_rec.organization_id
3449                 ,  x_rest_subinv_code  =>  l_rest_subinv_code
3450                 ,  x_inv_asset_flag    =>  l_inv_asset_flag ) ;
3451 
3452 
3453 IF BOM_Globals.get_debug = 'Y' THEN
3454      error_handler.write_debug('Get Sub Inv Flag . . . ');
3455      error_handler.write_debug('Expense to asset transfer : '||  l_allow_expense_to_asset );
3456      error_handler.write_debug('Restrict Sub Inv Code : ' || l_rest_subinv_code );
3457      error_handler.write_debug('Inv Asset Flag : '||  l_inv_asset_flag );
3458 
3459 END IF;
3460 
3461               IF l_rest_subinv_code = 'Y' THEN
3462                   IF l_allow_expense_to_asset = '1' THEN
3463 
3464 IF BOM_Globals.get_debug = 'Y' THEN
3465      error_handler.write_debug('Before  OPEN c_Restrict_SubInv_Trk');
3466 END IF;
3467                       OPEN c_Restrict_SubInv_Trk
3468                           ( p_revised_item_id   =>  p_rev_item_unexp_rec.revised_item_id
3469                           , p_organization_id   =>  p_rev_item_unexp_rec.organization_id
3470                           , p_subinventory      =>  p_revised_item_rec.completion_subinventory);
3471 
3472                       FETCH c_Restrict_SubInv_Trk INTO l_sub_locator_control ;
3473 
3474 
3475                       IF c_Restrict_SubInv_Trk%NOTFOUND THEN
3476                            CLOSE c_Restrict_SubInv_Trk;
3477 
3478                           l_token_tbl(1).token_name  := 'ASSEMBLY_ITEM_NAME';
3479                           l_token_tbl(1).token_value :=  p_revised_item_rec.revised_item_name;
3480                           l_token_tbl(2).token_name  :=  'COMPLETION_SUBINVENTORY';
3481                           l_token_tbl(2).token_value :=  p_revised_item_rec.completion_subinventory;
3482 
3483                           Error_Handler.Add_Error_Token
3484                           (  p_message_name       => 'BOM_RTG_SINV_RSTRCT_EXPASST'
3485                            , p_token_tbl          => l_token_tbl
3486                            , p_mesg_token_tbl     => l_mesg_token_tbl
3487                            , x_mesg_token_tbl     => l_mesg_token_tbl
3488                           ) ;
3489                          l_return_status := FND_API.G_RET_STS_ERROR;
3490                       ELSE
3491                          CLOSE  c_Restrict_SubInv_Trk;
3492 
3493                       END IF;
3494 
3495 IF BOM_Globals.get_debug = 'Y' THEN
3496      error_handler.write_debug('After c_Restrict_SubInv_Trk, the return status is ' ||  l_Return_Status);
3497 END IF;
3498 
3499                 ELSE
3500                    IF l_inv_asset_flag = 'Y' THEN
3501 
3502 IF BOM_Globals.get_debug = 'Y' THEN
3503      error_handler.write_debug('Before  OPEN c_Restrict_SubInv_Asset');
3504 END IF;
3505 
3506                          OPEN c_Restrict_SubInv_Asset
3507                          ( p_revised_item_id   =>  p_rev_item_unexp_rec.revised_item_id
3508                          , p_organization_id   =>  p_rev_item_unexp_rec.organization_id
3509                          , p_subinventory      =>  p_revised_item_rec.completion_subinventory);
3510 
3511                          FETCH c_Restrict_SubInv_Asset INTO l_sub_locator_control ;
3512                          IF c_Restrict_SubInv_Asset%NOTFOUND THEN
3513                              CLOSE c_Restrict_SubInv_Asset;
3514 
3515                             l_token_tbl(1).token_name  := 'ASSEMBLY_ITEM_NAME' ;
3516                             l_token_tbl(1).token_value :=  p_revised_item_rec.revised_item_name;
3517                             l_token_tbl(2).token_name  :=  'COMPLETION_SUBINVENTORY';
3518                             l_token_tbl(2).token_value :=  p_revised_item_rec.completion_subinventory;
3519 
3520                             Error_Handler.Add_Error_Token
3521                             (  p_message_name       =>  'BOM_RTG_SINV_RSTRCT_INVASST'
3522                              , p_token_tbl          => l_token_tbl
3523                              , p_mesg_token_tbl     => l_mesg_token_tbl
3524                              , x_mesg_token_tbl     => l_mesg_token_tbl
3525                             ) ;
3526                             l_return_status := FND_API.G_RET_STS_ERROR;
3527                          ELSE
3528                             CLOSE  c_Restrict_SubInv_Asset ;
3529                          END IF;
3530 
3531 IF BOM_Globals.get_debug = 'Y' THEN
3532      error_handler.write_debug('After c_Restrict_SubInv_Asset, the return status is ' ||  l_Return_Status);
3533 END IF;
3534                    ELSE
3535 
3536 IF BOM_Globals.get_debug = 'Y' THEN
3537      error_handler.write_debug('Before second  c_Restrict_SubInv_Trk');
3538 END IF;
3539                       OPEN c_Restrict_SubInv_Trk
3540                      ( p_revised_item_id   =>  p_rev_item_unexp_rec.revised_item_id
3541                      , p_organization_id   =>  p_rev_item_unexp_rec.organization_id
3542                      , p_subinventory      =>  p_revised_item_rec.completion_subinventory);
3543 
3544                       FETCH c_Restrict_SubInv_Trk INTO  l_sub_locator_control ;
3545                       IF c_Restrict_SubInv_Trk%NOTFOUND THEN
3546                           CLOSE c_Restrict_SubInv_Trk;
3547 
3548 
3549                             l_token_tbl(1).token_name  := 'ASSEMBLY_ITEM_NAME' ;
3550                             l_token_tbl(1).token_value :=  p_revised_item_rec.revised_item_name;
3551                             l_token_tbl(2).token_name  :=  'COMPLETION_SUBINVENTORY';
3552                             l_token_tbl(2).token_value :=  p_revised_item_rec.completion_subinventory;
3553 
3554                             Error_Handler.Add_Error_Token
3555                             (  p_message_name       =>  'BOM_RTG_SINV_RSTRCT_NOASST'
3556                              , p_token_tbl          => l_token_tbl
3557                              , p_mesg_token_tbl     => l_mesg_token_tbl
3558                              , x_mesg_token_tbl     => l_mesg_token_tbl
3559                             ) ;
3560                             l_return_status := FND_API.G_RET_STS_ERROR;
3561                         ELSE
3562                             CLOSE c_Restrict_SubInv_Trk;
3563                         END IF;
3564 
3565 IF BOM_Globals.get_debug = 'Y' THEN
3566      error_handler.write_debug('After c_Restrict_SubInv_Trk, the return status is '|| l_Return_Status);
3567 END IF;
3568                   END IF ; -- End of l_inv_asset_flag = 'Y'
3569                END IF ; -- End of l_allow_expense_to_asset = '1'
3570 
3571 
3572           ELSE -- l_rest_subinv_code <> 'Y'
3573               IF l_allow_expense_to_asset = '1' THEN
3574 
3575 IF BOM_Globals.get_debug = 'Y' THEN
3576      error_handler.write_debug('Before open c_SubInventory_Tracked');
3577 END IF;
3578                   OPEN c_SubInventory_Tracked
3579                      ( p_organization_id   =>  p_rev_item_unexp_rec.organization_id
3580                      , p_subinventory      =>  p_revised_item_rec.completion_subinventory);
3581 
3582                   FETCH c_SubInventory_Tracked INTO l_sub_locator_control ;
3583 
3584                   IF c_SubInventory_Tracked%NOTFOUND THEN
3585                        CLOSE c_SubInventory_Tracked;
3586 
3587                             l_token_tbl(1).token_name  := 'ASSEMBLY_ITEM_NAME' ;
3588                             l_token_tbl(1).token_value :=  p_revised_item_rec.revised_item_name;
3589                             l_token_tbl(2).token_name  :=  'COMPLETION_SUBINVENTORY';
3590                             l_token_tbl(2).token_value :=  p_revised_item_rec.completion_subinventory;
3591 
3592                             Error_Handler.Add_Error_Token
3593                             (  p_message_name       => 'BOM_RTG_SINV_NOTRSTRCT_EXPASST'
3594                              , p_token_tbl          => l_token_tbl
3595                              , p_mesg_token_tbl     => l_mesg_token_tbl
3596                              , x_mesg_token_tbl     => l_mesg_token_tbl
3597                             ) ;
3598                             l_return_status := FND_API.G_RET_STS_ERROR;
3599                   ELSE
3600                       CLOSE c_SubInventory_Tracked;
3601                   END IF;
3602 
3603 IF BOM_Globals.get_debug = 'Y' THEN
3604      error_handler.write_debug('After c_SubInventory_Tracked, the return status is '||  l_Return_Status);
3605 END IF;
3606 
3607               ELSE
3608                   IF l_inv_asset_flag = 'Y' THEN
3609 
3610 IF BOM_Globals.get_debug = 'Y' THEN
3611      error_handler.write_debug('Before open second c_SubInventory_Asset');
3612 END IF;
3613                       OPEN c_SubInventory_Asset
3614                      ( p_organization_id   =>  p_rev_item_unexp_rec.organization_id
3615                      , p_subinventory      =>  p_revised_item_rec.completion_subinventory);
3616 
3617                       FETCH c_SubInventory_Asset INTO l_Sub_Locator_Control;
3618                       IF c_SubInventory_Asset%NOTFOUND THEN
3619                            CLOSE c_SubInventory_Asset;
3620 
3621                             l_token_tbl(1).token_name  := 'ASSEMBLY_ITEM_NAME' ;
3622                             l_token_tbl(1).token_value :=  p_revised_item_rec.revised_item_name;
3623                             l_token_tbl(2).token_name  :=  'COMPLETION_SUBINVENTORY';
3624                             l_token_tbl(2).token_value :=  p_revised_item_rec.completion_subinventory;
3625 
3626                             Error_Handler.Add_Error_Token
3627                             (  p_message_name       => 'BOM_RTG_SINV_NOTRSTRCT_ASST'
3628                              , p_token_tbl          => l_token_tbl
3629                              , p_mesg_token_tbl     => l_mesg_token_tbl
3630                              , x_mesg_token_tbl     => l_mesg_token_tbl
3631                              ) ;
3632                             l_return_status := FND_API.G_RET_STS_ERROR;
3633                       ELSE
3634                           CLOSE c_SubInventory_Asset;
3635                       END IF;
3636 IF BOM_Globals.get_debug = 'Y' THEN
3637      error_handler.write_debug('After c_SubInventory_Asset, the return status is ' || l_Return_Status);
3638 END IF;
3639                   ELSE
3640 IF BOM_Globals.get_debug = 'Y' THEN
3641      error_handler.write_debug('Before open  second c_SubInventory_tracked');
3642 END IF;
3643                    IF p_revised_item_rec.completion_subinventory IS NOT NULL THEN
3644 
3645                        OPEN c_Subinventory_Tracked
3646                      ( p_organization_id   =>  p_rev_item_unexp_rec.organization_id
3647                      , p_subinventory      =>  p_revised_item_rec.completion_subinventory);
3648 
3649                        FETCH c_Subinventory_Tracked INTO  l_Sub_Locator_Control;
3650                        IF c_SubInventory_Tracked%NOTFOUND THEN
3651                             CLOSE c_Subinventory_Tracked;
3652 
3653                             l_token_tbl(1).token_name  := 'ASSEMBLY_ITEM_NAME';
3654                             l_token_tbl(1).token_value :=  p_revised_item_rec.revised_item_name;
3655                             l_token_tbl(2).token_name  :=  'COMPLETION_SUBINVENTORY';
3656                             l_token_tbl(2).token_value :=  p_revised_item_rec.completion_subinventory;
3657 
3658                             Error_Handler.Add_Error_Token
3659                             (  p_message_name       => 'BOM_RTG_SINV_NOTRSTRCT_NOASST'
3660                              , p_token_tbl          => l_token_tbl
3661                              , p_mesg_token_tbl     => l_mesg_token_tbl
3662                              , x_mesg_token_tbl     => l_mesg_token_tbl
3663                             ) ;
3664                             l_return_status := FND_API.G_RET_STS_ERROR;
3665 
3666                        ELSE
3667                            CLOSE c_Subinventory_Tracked;
3668                        END IF;
3669                    END IF;
3670 
3671 IF BOM_Globals.get_debug = 'Y' THEN
3672      error_handler.write_debug('After c_Subinventory_Tracked, the return status is '|| l_Return_Status);
3673 END IF;
3674 
3675                   END IF ; -- End of l_inv_asset_flag = 'Y'
3676               END IF ;  -- End of l_allow_expense_to_asset = '1'
3677           END IF; -- End of -- l_rest_subinv_code = 'Y'
3678 
3679        END IF ;   -- End of IF NOT Check_SubInv_Exists
3680 
3681     END IF ;
3682 
3683         /*********************************************************************
3684         -- Added by MK 08/26/2000
3685         -- Check Completion Locator
3686         **********************************************************************/
3687 
3688 IF Bom_Globals.Get_Debug = 'Y' THEN
3689     Error_Handler.Write_Debug('Performing completion locator. . .') ;
3690     Error_Handler.Write_Debug('Sub Inv - Loc Control : '|| to_char(l_sub_locator_control)  );
3691 END IF;
3692 
3693     IF (Bom_globals.Get_Caller_Type = BOM_GLOBALS.G_MASS_CHANGE) THEN
3694                 Null;
3695     Else
3696         IF  p_control_rec.caller_type <> 'FORM'
3697 	AND p_revised_item_rec.completion_subinventory is not null -- Bug 2871420 added this condition
3698         AND (( p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE
3699               AND NVL(p_rev_item_unexp_rec.completion_locator_id , 0) <>
3700                   NVL(p_old_rev_item_unexp_rec.completion_locator_id , 0)
3701               )
3702              OR (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE
3703 			AND  p_revised_item_rec.completion_subinventory is not null
3704                        AND p_revised_item_rec.completion_subinventory <> FND_API.G_MISS_CHAR)
3705              )
3706         AND  NOT Check_Locators( p_organization_id => p_rev_item_unexp_rec.organization_id
3707                                , p_revised_item_id => p_rev_item_unexp_rec.revised_item_id
3708                                , p_locator_id      => p_rev_item_unexp_rec.completion_locator_id
3709                                , p_subinventory    => p_revised_item_rec.completion_subinventory )
3710         THEN
3711 
3712              IF l_locator_control = 4 THEN
3713                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3714                 THEN
3715                     l_token_tbl(1).token_name  := 'ASSEMBLY_ITEM_NAME';
3716                     l_token_tbl(1).token_value :=  p_revised_item_rec.revised_item_name;
3717                     Error_Handler.Add_Error_Token
3718                       (  p_message_name       => 'BOM_RTG_LOCATOR_REQUIRED'
3719                        , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3720                        , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3721                        , p_Token_Tbl          => l_Token_Tbl
3722                       );
3723                 END IF;
3724 
3725              ELSIF l_locator_control = 3 THEN
3726                 -- Log the Dynamic locator control message.
3727                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3728                 THEN
3729                     l_token_tbl(1).token_name  := 'ASSEMBLY_ITEM_NAME';
3730                     l_token_tbl(1).token_value :=  p_revised_item_rec.revised_item_name;
3731 
3732                       Error_Handler.Add_Error_Token
3733                       (  p_message_name   => 'BOM_RTG_LOC_CANNOT_BE_DYNAMIC'
3734                        , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3735                        , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3736                        , p_Token_Tbl      => l_Token_Tbl
3737                       );
3738                 END IF;
3739              ELSIF l_locator_control = 2 THEN
3740                 IF  l_item_loc_restricted  = 1 THEN
3741 
3742                     -- if error occured when item_locator_control was
3743                     -- restrcited
3744 
3745                     IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3746                     THEN
3747                         l_token_tbl(1).token_name  := 'ASSEMBLY_ITEM_NAME';
3748                         l_token_tbl(1).token_value :=  p_revised_item_rec.revised_item_name;
3749 
3750                         Error_Handler.Add_Error_Token
3751                         (  p_message_name   => 'BOM_RTG_ITEM_LOC_RESTRICTED'
3752                          , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3753                          , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3754                          , p_Token_Tbl      => l_Token_Tbl
3755                          );
3756                     END IF;
3757                 ELSE
3758                     IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3759                     THEN
3760                         l_token_tbl(1).token_name  := 'ASSEMBLY_ITEM_NAME';
3761                         l_token_tbl(1).token_value :=  p_revised_item_rec.revised_item_name;
3762 
3763                         Error_Handler.Add_Error_Token
3764                         (  p_message_name   => 'BOM_RTG_LOCATOR_NOT_IN_SUBINV'
3765                          , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3766                          , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3767                          , p_Token_Tbl      => l_Token_Tbl
3768                          );
3769                     END IF;
3770                 END IF;
3771              ELSIF l_locator_control = 1 THEN
3772 
3773                     IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3774                     THEN
3775                         l_token_tbl(1).token_name  := 'ASSEMBLY_ITEM_NAME';
3776                         l_token_tbl(1).token_value :=  p_revised_item_rec.revised_item_name;
3777 
3778                         Error_Handler.Add_Error_Token
3779                         (  p_message_name   => 'BOM_RTG_ITEM_NO_LOC_CONTROL'
3780                          , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3781                          , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3782                          , p_Token_Tbl      => l_Token_Tbl
3783                          );
3784                     END IF;
3785              END IF;
3786 
3787              l_return_status := FND_API.G_RET_STS_ERROR;
3788 
3789         -- Comment out by MK, already checked in validation for Sub Inv.
3790         --
3791         -- ELSIF p_revised_item_rec.completion_location_name IS NOT NULL AND
3792         --       p_revised_item_rec.completion_subinventory IS NULL
3793         -- THEN
3794         --        IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3795         --        THEN
3796         --        Error_Handler.Add_Error_Token
3797         --        (  p_message_name       => 'BOM_RTG_LOCATOR_MUST_BE_NULL'
3798         --         , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3799         --         , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3800         --          , p_Token_Tbl          => l_Token_Tbl
3801         --         );
3802         --         END IF;
3803         --         l_return_status := FND_API.G_RET_STS_ERROR;
3804 
3805 IF BOM_Globals.get_debug = 'Y' THEN
3806      error_handler.write_debug('completion locator check  when locator name is not null,the return status is ' ||
3807                                 l_Return_Status);
3808 END IF;
3809 
3810         END IF;  ---end of locator check
3811     END IF;
3812 IF BOM_Globals.get_debug = 'Y' THEN
3813      error_handler.write_debug('After locator check,the return status is '|| l_Return_Status);
3814 END IF;
3815 
3816         /*********************************************************************
3817         -- Added by MK 08/26/2000
3818         -- Check Mixed_Model_Map_Flag for future release
3819 
3820         IF ( p_revised_item_rec.mixed_model_map <> p_old_revised_item_rec.mixed_model_map AND
3821              p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE
3822            ) OR
3823            p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE AND
3824            p_revised_item_rec.mixed_model_map = 1
3825         THEN
3826             IF NOT Check_Mixed_Model_Map THEN
3827                 IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_ERROR)
3828                 THEN
3829                     Error_Handler.Add_Error_Token
3830                     (  p_Message_Name   => 'ENG_MMMF_ALREADY_EXISTS'
3831                      , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3832                      , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3833                      , p_Token_Tbl      => l_Token_Tbl
3834                     );
3835                 END IF;
3836         **********************************************************************/
3837 
3838 
3839 /*********************************************************************************
3840 ** End of Check Entity for New ECO Effectivities and ECO Routing.
3841 ** Added by MK on 08/25/2000.
3842 **********************************************************************************/
3843 
3844         --
3845         --  Check conditionally required attributes here.
3846         --
3847         /*********************************************************************
3848          -- Added by AS on 07/06.
3849          -- If revised item is unit controlled, the user must enter a
3850          -- From End Item Unit Number
3851         **********************************************************************/
3852         IF p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE AND
3853            l_plm_or_erp_change <> 'PLM' AND -- not required for plm
3854            l_is_item_unit_controlled AND
3855            p_revised_item_rec.from_end_item_unit_number IS NULL
3856         THEN
3857                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3858                 THEN
3859                         Error_Handler.Add_Error_Token
3860                         (  p_Message_Name       => 'ENG_FROM_UNIT_NUM_REQUIRED'
3861                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3862                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3863                          , p_Token_Tbl          => l_Token_Tbl
3864                          );
3865                 END IF;
3866                 l_return_status := FND_API.G_RET_STS_ERROR;
3867         END IF;
3868 
3869         /*********************************************************************
3870         --
3871         -- If the user has entered the use_us_plan_name but not given a
3872         -- use_up_item and the vice-versa then it should get an error.
3873         --
3874         **********************************************************************/
3875         /**** Form allows the user to enter the useup item even when the plan name is
3876               not chosen.
3877 
3878         IF p_revised_item_rec.use_up_plan_name IS NOT NULL AND
3879            p_revised_item_rec.use_up_item_name IS NULL     AND
3880            p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE
3881         THEN
3882                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3883                 THEN
3884                         Error_Handler.Add_Error_Token
3885                         (  p_Message_Name       => 'ENG_USE_UP_ITEM_MISSING'
3886                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3887                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3888                          , p_Token_Tbl          => l_Token_Tbl
3889                          );
3890                 END IF;
3891                 l_return_status := FND_API.G_RET_STS_ERROR;
3892 
3893         ELSIF p_revised_item_rec.use_up_plan_name IS NULL     AND
3894               p_revised_item_rec.use_up_item_name IS NOT NULL AND
3895               p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE
3896         THEN
3897                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3898                 THEN
3899                         Error_Handler.Add_Error_Token
3900                         (  p_Message_Name       => 'ENG_USE_UP_PLAN_MISSING'
3901                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3902                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3903                          , p_Token_Tbl          => l_Token_Tbl
3904                          );
3905                 END IF;
3906                 l_return_status := FND_API.G_RET_STS_ERROR;
3907         ELS
3908 
3909         *** End of Comment */
3910 
3911 
3912          IF p_revised_item_rec.use_up_plan_name IS NOT NULL AND
3913               p_rev_item_unexp_rec.use_up_item_id IS NOT NULL AND
3914               NOT Validate_Use_Up_Plan
3915                   (  p_use_up_plan_name => p_revised_item_rec.use_up_plan_name
3916                    , p_use_up_item_id   => p_rev_item_unexp_rec.use_up_item_id
3917                    , p_organization_id  => p_rev_item_unexp_rec.organization_id
3918                    )
3919         THEN
3920                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3921                 THEN
3922                         Error_Handler.Add_Error_Token
3923                         (  p_Message_Name       => 'ENG_USE_UP_PLANITEM_INVALID'
3924                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3925                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3926                          );
3927                 END IF;
3928                 l_return_status := FND_API.G_RET_STS_ERROR;
3929         END IF;
3930 
3931         --
3932         -- End of check for conditionally required attributes
3933         --
3934 
3935         IF p_control_rec.caller_type = 'FORM'
3936         THEN
3937                 l_dup_exists := 0;
3938                 FOR X_CheckDupUnit IN CheckDupUnit LOOP
3939                         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3940                         THEN
3941                                 Error_Handler.Add_Error_Token
3942                                 (  p_Message_Name       => 'ENG_UNIT_NUM_DUPLICATE'
3943                                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3944                                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3945                                  , p_Token_Tbl          => l_Token_Tbl
3946                                  );
3947                         END IF;
3948                         l_return_status := FND_API.G_RET_STS_ERROR;
3949                 END LOOP;
3950 
3951         ELSIF p_control_rec.caller_type <> 'SSWA' THEN -- not required for plm
3952 	-- Peform the following validation only if called thru open interface
3953 
3954                 l_dup_exists := 0;
3955                 --
3956                 -- If the user is trying to update the revised item with new values then make sure that
3957                 -- the new values are not creating a duplicate row in the table.
3958                 --
3959                 IF  ( p_revised_item_rec.new_effective_date IS NOT NULL AND
3960                       p_revised_item_rec.new_effective_date <> FND_API.G_MISS_DATE
3961                     ) OR
3962                     ( p_revised_item_rec.updated_revised_item_revision IS NOT NULL AND
3963                        p_revised_item_rec.updated_revised_item_revision <> FND_API.G_MISS_CHAR
3964                     )
3965                 THEN
3966                         FOR X_CheckDupUnit IN CheckDupDateUnit LOOP
3967                         --
3968                         -- The message text for this message is:
3969                         -- The revised item REVISED_ITEM_NAME already exists on ECO ECO_NAME with revision
3970                         -- NEW_OR_UPDATED_ITEM_REVISION and effective date NEW_OR_UPDATED_EFFECTIVE_DATE
3971                         -- So the tokens updated_item_revision and effective_date would need to replaced
3972                         -- depending
3973                         -- on what is being changed, since the user can change one and then leave the other
3974                         -- column to default.
3975                         --
3976                                 SELECT DECODE(p_revised_item_rec.updated_revised_item_revision, NULL,
3977                                               p_revised_item_rec.new_revised_item_revision,
3978                                               p_revised_item_rec.updated_revised_item_revision
3979                                               ),
3980                                        DECODE(p_revised_item_rec.new_effective_date, NULL,
3981                                               p_revised_item_rec.start_effective_date,
3982                                               p_revised_item_rec.new_effective_date
3983                                               )
3984                                     INTO l_token_tbl(3).token_value,
3985                                          l_token_tbl(4).token_value
3986                                     FROM SYS.DUAL;
3987 
3988                                     l_token_tbl(2).token_name := 'ECO_NAME';
3989                                     l_token_tbl(2).token_value := p_revised_item_rec.eco_name;
3990 
3991                                     l_token_tbl(3).token_name := 'NEW_OR_UPDATED_ITEM_REVISION';
3992                                     l_token_tbl(4).token_name := 'NEW_OR_UPDATED_EFFECTIVE_DATE';
3993 
3994                                 Error_Handler.Add_Error_Token
3995                                 (  p_Message_Name       => 'ENG_RIT_UPD_ALREADY_EXISTS'
3996                                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3997                                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3998                                  , p_Token_Tbl          => l_Token_Tbl
3999                                  );
4000                                 l_return_status := FND_API.G_RET_STS_ERROR;
4001                         END LOOP;
4002                  END IF; /* If updating revision or effective date Ends */
4003 
4004           /*********************************************************************
4005           --
4006           -- Cannot update an ECO that has
4007           -- (a process and Approval Status of 'Approval Requested')
4008           -- or is cancelled or implemented
4009           --
4010           *********************************************************************/
4011           IF ENG_Globals.ECO_Cannot_Update
4012              (  p_change_notice   => p_revised_item_rec.Eco_Name
4013              , p_organization_id => p_rev_item_unexp_rec.organization_id
4014              )
4015 	     AND p_control_rec.caller_type <> 'SSWA'  -- not required for plm
4016           THEN
4017                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4018                 THEN
4019                         Error_Handler.Add_Error_Token
4020                         (  p_Message_Name       => 'ENG_PROC_UPD_DISALLOWED'
4021                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4022                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4023                          , p_Token_Tbl          => l_Token_Tbl
4024                         );
4025                 END IF;
4026                 l_return_status := FND_API.G_RET_STS_ERROR;
4027           END IF;
4028 
4029 
4030           /*********************************************************************
4031           --
4032           -- Creating a record with status of Cancelled should get an error.
4033           --
4034           *********************************************************************/
4035           IF p_revised_item_rec.Transaction_Type = ENG_Globals.G_OPR_CREATE AND
4036              p_revised_item_rec.status_type = 5
4037           THEN
4038                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4039                 THEN
4040                         Error_Handler.Add_Error_Token
4041                         (  p_Message_Name       => 'ENG_STAT_MUST_NOT_BE_CANCL'
4042                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4043                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4044                          , p_Token_Tbl          => l_Token_Tbl
4045                          );
4046                 END IF;
4047                 l_return_status := FND_API.G_RET_STS_ERROR;
4048           END IF;
4049 
4050           /********************************************************************
4051           --
4052           -- For Creates, Product Family item cannot be added on an ECO
4053           --
4054           *********************************************************************/
4055 
4056           l_product_family := FALSE;
4057 
4058           FOR x_count IN c_CheckItemProductFamily LOOP
4059                 l_product_family := TRUE;
4060           END LOOP;
4061 
4062           IF p_revised_item_rec.Transaction_Type = ENG_Globals.G_OPR_CREATE AND
4063              l_product_family
4064           THEN
4065                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4066                 THEN
4067                         Error_Handler.Add_Error_Token
4068                         (  p_Message_Name       => 'ENG_CANNOT_ADD_PF_ITEM'
4069                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4070                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4071                         );
4072                 END IF;
4073                 l_return_status := FND_API.G_RET_STS_ERROR;
4074           END IF;
4075 
4076         /*********************************************************************
4077          -- Added by AS on 07/06.
4078          -- If revised item is unit controlled, no effective date must be
4079          -- entered
4080         **********************************************************************/
4081       -- removed for solving conflicting with unique check in ENGSVIDB.pls
4082       /*  IF l_is_item_unit_controlled AND
4083            ((p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE AND
4084              p_revised_item_rec.start_effective_date IS NOT NULL)
4085             OR
4086             (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE AND
4087              p_revised_item_rec.new_effective_date IS NOT NULL))
4088         THEN
4089                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4090                 THEN
4091                         Error_Handler.Add_Error_Token
4092                         (  p_Message_Name       => 'ENG_RIT_UNIT_EFFDATE_NULL'
4093                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4094                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4095                          , p_Token_Tbl          => l_Token_Tbl
4096                          );
4097                 END IF;
4098                 l_return_status := FND_API.G_RET_STS_ERROR;
4099         END IF;
4100 
4101      */
4102         /*********************************************************************
4103          -- Added by AS on 07/06.
4104          -- If revised item is not unit controlled, no unit number must be
4105          -- entered
4106         **********************************************************************/
4107         IF NOT l_is_item_unit_controlled AND
4108            ((p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE AND
4109              p_revised_item_rec.from_end_item_unit_number IS NOT NULL)
4110             OR
4111             (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE AND
4112              p_revised_item_rec.new_from_end_item_unit_number IS NOT NULL))
4113         THEN
4114                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4115                 THEN
4116                         Error_Handler.Add_Error_Token
4117                         (  p_Message_Name       => 'ENG_RIT_DATE_UNIT_NULL'
4118                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4119                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4120                          , p_Token_Tbl          => l_Token_Tbl
4121                          );
4122                 END IF;
4123                 l_return_status := FND_API.G_RET_STS_ERROR;
4124         END IF;
4125 
4126         IF l_is_item_unit_controlled AND
4127            p_revised_item_rec.update_wip = 1
4128         THEN
4129                 /**********************************************************************
4130                  -- Added by AS on 07/06.
4131                  -- If revised item is unit controlled, Update_WIP must not be set
4132                  -- to Yes.
4133                 **********************************************************************/
4134                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4135                 THEN
4136                         Error_Handler.Add_Error_Token
4137                         (  p_Message_Name       => 'ENG_ITEM_UNIT_UPDATE_WIP'
4138                         , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4139                         , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4140                         , p_Token_Tbl          => l_Token_Tbl
4141                         );
4142                END IF;
4143                l_return_status := FND_API.G_RET_STS_ERROR;
4144         END IF;
4145 
4146         /**********************************************************************
4147           --
4148           -- Revised item status cannot be updated to 'scheduled' if ECO has not
4149           -- been approved
4150           --
4151           **********************************************************************/
4152         IF l_plm_or_erp_change <> 'PLM'  -- not required for plm
4153 	THEN
4154           l_ECO_approved := 0;
4155           FOR x_count IN c_CheckECOApproval LOOP
4156                 -- Eco Approved will be set to 1 only if the cursor executes
4157                 -- indicating that the eco is approved.
4158                 l_ECO_approved := 1;
4159           END LOOP;
4160 
4161           IF p_revised_item_rec.status_type = 4 /* Scheduled */
4162              AND
4163              l_ECO_approved <> 1  /* if not approved */
4164           THEN
4165                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4166                 THEN
4167                         l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
4168                         l_token_tbl(1).token_value :=
4169                                         p_revised_item_rec.revised_item_name;
4170                         l_token_tbl(2).token_name  := 'ECO_NAME';
4171                         l_token_tbl(2).token_value :=
4172                                         p_revised_item_rec.eco_name;
4173 
4174                         Error_Handler.Add_Error_Token
4175                         (  p_Message_Name       => 'ENG_STAT_MUST_NOT_BE_SCHED'
4176                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4177                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4178                          , p_Token_Tbl          => l_Token_Tbl
4179                         );
4180                 END IF;
4181                 l_return_status := FND_API.G_RET_STS_ERROR;
4182           END IF;
4183         END IF;
4184           /*********************************************************************
4185           --
4186           -- If the user is trying to update schedule date to NULL by giving a
4187           -- missing value in the input record then that should get an error.
4188           -- Check if scheduled_date is being set to null
4189           --
4190           **********************************************************************/
4191 
4192           IF p_revised_item_rec.new_effective_date = FND_API.G_MISS_DATE AND
4193              p_revised_item_rec.transaction_type = Eng_Globals.G_OPR_UPDATE
4194           THEN
4195                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4196                 THEN
4197                         Error_Handler.Add_Error_Token
4198                         (  p_Message_Name       => 'ENG_SCHED_DATE_NOT_NULL'
4199                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4200                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4201                          , p_Token_Tbl          => l_Token_Tbl
4202                          );
4203                 END IF;
4204                 l_return_status := FND_API.G_RET_STS_ERROR;
4205           END IF;
4206 
4207         END IF; -- End of code executed only if called thru open interface
4208 
4209         /*********************************************************************
4210         --
4211         -- Check if the (currently) highest un-implemented revision of the
4212         -- revised item exists on another ECO - log warning
4213         --
4214         *********************************************************************/
4215 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('caller type: ' || p_control_rec.caller_type); END IF;
4216 
4217       IF (p_control_rec.caller_type = 'FORM'
4218           AND p_revised_item_rec.transaction_type = 'CREATE'
4219           AND p_control_rec.validation_controller = 'REVISED_ITEM')
4220          OR
4221          (p_control_rec.caller_type <> 'FORM' AND p_control_rec.caller_type <> 'SSWA')
4222       THEN
4223         Pending_High_Rev
4224         ( p_change_notice   => p_revised_item_rec.eco_name
4225         , p_organization_id => p_rev_item_unexp_rec.organization_id
4226         , p_revised_item_id => p_rev_item_unexp_rec.revised_item_id
4227         , x_change_notice   => l_change_notice
4228         , x_revision        => l_revision
4229         );
4230 
4231             --  Modified by MK on 10/27/2000
4232             --  Warnig is occurred when the current highest un-implemented revision
4233             --  for the revised item exists on another ECO.
4234             --
4235             --  IF l_change_notice IS NOT NULL
4236 
4237             IF l_change_notice <> p_revised_item_rec.eco_name
4238             THEN
4239                 l_token_tbl.delete;
4240 /* Bug 1492149
4241   Changed the message ENG_ITEM_HIGH_REV_PENDING to ENG_ECN_REVISION
4242   As the prior message is misleading
4243 */
4244 
4245 /*
4246                 l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
4247                 l_token_tbl(1).token_value :=
4248                                         p_revised_item_rec.revised_item_name;
4249                 l_token_tbl(2).token_name  := 'ECO_NAME';
4250                 l_token_tbl(2).token_value := l_change_notice;
4251                 l_token_tbl(3).token_name  := 'REVISION';
4252                 l_token_tbl(3).token_value := l_revision;
4253 */
4254                 l_token_tbl(1).token_name  := 'ENTITY1';
4255                 l_token_tbl(1).token_value := l_revision;
4256                 l_token_tbl(2).token_name  := 'ENTITY2';
4257                 l_token_tbl(2).token_value := l_change_notice;
4258                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4259                 THEN
4260                         Error_Handler.Add_Error_Token
4261                         ( p_Message_Name       => 'ENG_ECN_REVISION'
4262                      --  , p_Message_Name       => 'ENG_ITEM_HIGH_REV_PENDING'
4263                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4264                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4265                          , p_Token_Tbl          => l_Token_Tbl
4266                          , p_message_type       => 'W');
4267                 END IF;
4268           END IF;
4269       END IF;
4270 
4271       -- Added by MK on 11/01/2000
4272       IF p_control_rec.caller_type = 'FORM' OR p_control_rec.caller_type = 'SSWA'
4273       THEN
4274            l_assembly_type := p_control_rec.eco_assembly_type ;
4275       ELSE
4276            l_assembly_type :=
4277                 ENG_Globals.Get_ECO_Assembly_Type
4278                 (  p_change_notice   => p_revised_item_rec.eco_name
4279                  , p_organization_id => p_rev_item_unexp_rec.organization_id
4280                 );
4281       END IF ;
4282 
4283 IF BOM_Globals.get_debug = 'Y'
4284 THEN
4285      error_handler.write_debug('Get Eco Assembly Type, Assebly Type : '|| to_char(l_assembly_type) );
4286 END IF;
4287 
4288         /********************************************************************
4289         --
4290         -- Check if revised item assembly type is compatible with that of the
4291         -- change order type. Manufacuturing ECO's can only have manufacturing
4292         -- items.
4293         --
4294         *********************************************************************/
4295 
4296         IF  p_control_rec.caller_type <> 'FORM' AND
4297             p_revised_item_rec.Transaction_Type = ENG_GLOBALS.G_OPR_CREATE AND
4298             NOT Compatible_Item_Type
4299                 (  p_assembly_type  => l_assembly_type
4300                  , p_revised_item_id => p_rev_item_unexp_rec.revised_item_id
4301                  , p_organization_id => p_rev_item_unexp_rec.organization_id
4302                 )
4303         THEN
4304                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4305                 THEN
4306                         l_token_tbl.delete;
4307                         l_token_tbl(1).token_name  := 'ECO_NAME';
4308                         l_token_tbl(1).token_value :=
4309                                                 p_revised_item_rec.eco_name;
4310                         Error_Handler.Add_Error_Token
4311                         (  p_Message_Name       => 'ENG_INCOMPATIBLE_ITEM_TYPE'
4312                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4313                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4314                          , p_Token_Tbl          => l_Token_Tbl
4315                          );
4316                 END IF;
4317                 l_return_status := FND_API.G_RET_STS_ERROR;
4318         END IF;
4319 
4320         --
4321         -- Early Scheduled date must be <= Scheduled Date
4322         --
4323 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Early effective Date: '
4324                      || to_char(p_revised_item_rec.earliest_effective_date));
4325 END IF;
4326 
4327 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Start effective Date: ' ||
4328                     to_char(p_revised_item_rec.start_effective_date));
4329 END IF;
4330         IF NOT l_is_item_unit_controlled AND
4331            ((p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE AND
4332              trunc(p_revised_item_rec.earliest_effective_date) >
4333              trunc(p_revised_item_rec.start_effective_date))
4334             OR
4335             (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE AND
4336              trunc(p_revised_item_rec.earliest_effective_date) >
4337              NVL(trunc(p_revised_item_rec.new_effective_date),
4338                         p_revised_item_rec.start_effective_date)))
4339         THEN
4340                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4341                 THEN
4342                         l_token_tbl.delete;
4343                         l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
4344                         l_token_tbl(1).token_value :=
4345                                 p_revised_item_rec.revised_item_name;
4346                         Error_Handler.Add_Error_Token
4347                         (  p_Message_Name       =>'ENG_EARLY_SCHED_DATE_INVALID'
4348                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4349                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4350                          , p_Token_Tbl          => l_Token_Tbl
4351                          );
4352                 END IF;
4353                 l_return_status := FND_API.G_RET_STS_ERROR;
4354         END IF;
4355 
4356         /********************************************************************
4357         --
4358         -- If the use_up_plan is given then verify that the schedule_date
4359         -- for the revised component matches with the inventory_use_up_date
4360         -- for that plan and item in MRP_System_Items
4361         -- Similarly if the user is trying to update the schedule_date and
4362         -- the use_up_item is not null, then check if the new_effective_date
4363         -- matches the inventory_use_up_date
4364         --
4365         *********************************************************************/
4366 
4367         IF p_revised_item_rec.use_up_plan_name IS NOT NULL AND
4368            p_rev_item_unexp_rec.use_up_item_id IS NOT NULL AND  -- Added by MK on 10/31/00
4369            p_revised_item_rec.start_effective_date IS NOT NULL AND
4370            p_revised_item_rec.start_effective_date <> FND_API.G_MISS_DATE AND
4371            (  p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE OR
4372               (  p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE
4373                  AND
4374                  ( p_revised_item_rec.new_effective_date IS NOT NULL AND
4375                    p_revised_item_rec.new_effective_date <> FND_API.G_MISS_DATE
4376                   )
4377                )
4378             )
4379         THEN
4380                 l_IsDateValid := FALSE;
4381                 IF p_revised_item_rec.transaction_type=ENG_GLOBALS.G_OPR_CREATE
4382                 THEN
4383                         l_IsDateValid :=
4384                         Check_Date
4385                         (  p_revised_item_id    =>
4386                            p_rev_item_unexp_rec.use_up_item_id
4387 --                         p_rev_item_unexp_rec.revised_item_id    /*2199507*/
4388                          , p_organization_id    =>
4389                            p_rev_item_unexp_rec.organization_id
4390                          , p_use_up_plan        =>
4391                            p_revised_item_rec.use_up_plan_name
4392                          , p_schedule_date      =>
4393                            p_revised_item_rec.start_effective_date
4394                          , x_inventory_use_up_date => l_use_up_date
4395                         );
4396 
4397                 ELSE
4398                         l_IsDateValid :=
4399                         Check_Date
4400                         (  p_revised_item_id    =>
4401                            p_rev_item_unexp_rec.use_up_item_id
4402 --                         p_rev_item_unexp_rec.revised_item_id    /*2199507*/
4403                          , p_organization_id    =>
4404                            p_rev_item_unexp_rec.organization_id
4405                          , p_use_up_plan        =>
4406                            p_revised_item_rec.use_up_plan_name
4407                          , p_schedule_date      =>
4408                            p_revised_item_rec.new_effective_date
4409                          , x_inventory_use_up_date => l_use_up_date
4410                         );
4411                 END IF;
4412 
4413                 IF l_IsDateValid = FALSE
4414                 THEN
4415                         IF FND_MSG_PUB.Check_Msg_Level
4416                         (FND_MSG_PUB.G_MSG_LVL_ERROR)
4417                         THEN
4418                                 l_token_tbl.delete;
4419                                 l_token_tbl(1).token_name  :=
4420                                                 'REVISED_ITEM_NAME';
4421                                 l_token_tbl(1).token_value :=
4422                                         p_revised_item_rec.revised_item_name;
4423 
4424                                 Error_Handler.Add_Error_Token
4425                                 (  p_Message_Name    =>'ENG_SCHD_DATE_NOT_MATCH'
4426                                  , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4427                                  , x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4428                                  , p_Token_Tbl       => l_Token_Tbl
4429                                 );
4430                         END IF;
4431                         l_return_status := FND_API.G_RET_STS_ERROR;
4432                 END IF;
4433 
4434 IF BOM_Globals.get_debug = 'Y' THEN
4435      error_handler.write_debug('After validation for shedule date, the return status is ' ||
4436                                 l_Return_Status);
4437 END IF;
4438 
4439         END IF;
4440 
4441 
4442         /**********************************************************************
4443         --
4444         -- Use up item must be either revised item or any of its implemented
4445         -- components
4446         --
4447         ***********************************************************************/
4448 
4449         IF ( ( p_rev_item_unexp_rec.use_up_item_id IS NOT NULL AND
4450                p_revised_item_rec.Transaction_Type = ENG_Globals.G_OPR_CREATE
4451              )   OR
4452              (  p_revised_item_rec.Transaction_Type = ENG_Globals.G_OPR_UPDATE
4453                 AND
4454                 p_rev_item_unexp_rec.use_up_item_id <>
4455                 NVL(p_old_rev_item_unexp_rec.use_up_item_id, 0)
4456              )
4457            ) AND
4458            p_rev_item_unexp_rec.use_up_item_id <>
4459            p_rev_item_unexp_rec.revised_item_id AND
4460            p_rev_item_unexp_rec.use_up_item_id <> FND_API.G_MISS_NUM
4461         THEN
4462                 l_IsUseUpValid := FALSE;
4463 
4464                 FOR CheckItem IN c_CheckUseUpItem
4465                                  (  p_revised_item_id       =>
4466                                     p_rev_item_unexp_rec.revised_item_id
4467                                   , p_alternate_designator  =>
4468                                     p_revised_item_rec.alternate_bom_code
4469                                   , p_organization_id       =>
4470                                     p_rev_item_unexp_rec.organization_id
4471                                   , p_use_up_item_id        =>
4472                                     p_rev_item_unexp_rec.use_up_item_id
4473                                   , p_use_up_date           =>
4474                                         l_use_up_date
4475                                   )
4476                 LOOP
4477                         -- If loop executes then the use-up-item is valid.
4478                         -- else set the Use_Up_Item invalid variable.
4479 
4480                         l_IsUseUpValid := TRUE;
4481 
4482                 END LOOP;
4483 
4484                 IF l_IsUseUpValid = FALSE THEN
4485                         IF FND_MSG_PUB.Check_Msg_Level
4486                            (FND_MSG_PUB.G_MSG_LVL_ERROR)
4487                         THEN
4488                                 l_token_tbl.delete;
4489                                 Error_Handler.Add_Error_Token
4490                                 (  p_Message_Name    =>'ENG_USE_UP_ITEM_INVALID'
4491                                  , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4492                                  , x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4493                                 );
4494                         END IF;
4495 
4496 
4497 
4498                         l_return_status := FND_API.G_RET_STS_ERROR;
4499                 END IF;
4500 
4501 IF BOM_Globals.get_debug = 'Y' THEN
4502      error_handler.write_debug('After validation for Use Up Item, the return status is '|| l_Return_Status);
4503 END IF;
4504         END IF;
4505 
4506         /*********************************************************************
4507         --
4508         -- Cannot create an alternate if primary bill does not already exist.
4509         -- and primary routing does not already exist.
4510         -- Modified by MK on 10/31/2000
4511         -- Also added Eng_Primary_Bill_Exists check in Rev Comp and
4512         -- Eng_Primary_Routing_Exists in Rev Op
4513         **********************************************************************/
4514 
4515 IF BOM_Globals.get_debug = 'Y' THEN
4516      error_handler.write_debug('Org Id : ' || to_char(p_rev_item_unexp_rec.organization_id) );
4517      error_handler.write_debug('Rev Item Id : ' || to_char(p_rev_item_unexp_rec.revised_item_id) );
4518      error_handler.write_debug('Assem Type  : ' || to_char(l_assembly_type) );
4519 END IF;
4520 
4521 
4522         IF p_revised_item_rec.Transaction_Type = ENG_Globals.G_OPR_CREATE AND
4523            p_revised_item_rec.alternate_bom_code IS NOT NULL       AND
4524            (    NOT Eng_Primary_Bill_Exists
4525                 ( p_Revised_Item_Id => p_rev_item_unexp_rec.revised_item_id
4526                 , p_Organization_Id => p_rev_item_unexp_rec.organization_id
4527                 , p_assembly_type   => l_assembly_type)
4528            AND
4529                 NOT Eng_Primary_Routing_Exists
4530                 ( p_revised_Item_Id => p_rev_item_unexp_rec.revised_item_id
4531                 , p_organization_Id => p_rev_item_unexp_rec.organization_id
4532                 , p_assembly_type   => l_assembly_type)
4533            )
4534 	   AND l_plm_or_erp_change <> 'PLM'
4535         THEN
4536                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4537                 THEN
4538                         l_token_tbl.delete;
4539                         l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
4540                         l_token_tbl(1).token_value :=
4541                                         p_revised_item_rec.revised_item_name;
4542 
4543                         Error_Handler.Add_Error_Token
4544                         (  p_Message_Name       => 'ENG_CANNOT_ADD_ALTERNATE'
4545                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4546                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4547                          , p_Token_Tbl          => l_Token_Tbl
4548                          );
4549 
4550                         Error_Handler.Add_Error_Token
4551                         (  p_Message_Name       => 'ENG_RIT_RTG_CANT_ADD_ALTERNATE'
4552                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4553                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4554                          , p_Token_Tbl          => l_Token_Tbl
4555                         );
4556 
4557                 END IF;
4558                 l_return_status := FND_API.G_RET_STS_ERROR;
4559         END IF;
4560 
4561         /*********************************************************************
4562         -- Added by MK on 08/26/2000
4563         IF p_revised_item_rec.transaction_type = ENG_Globals.G_OPR_CREATE AND
4564            p_revised_item_rec.alternate_bom_code IS NOT NULL       AND
4565            NOT Eng_Primary_Routing_Exists
4566                 ( p_revised_Item_Id => p_rev_item_unexp_rec.revised_item_id
4567                 , p_organization_Id => p_rev_item_unexp_rec.organization_id
4568                 , p_assembly_type   => l_assembly_type)
4569         THEN
4570                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4571                 THEN
4572                     l_token_tbl.delete;
4573                     l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
4574                     l_token_tbl(1).token_value :=
4575                                         p_revised_item_rec.revised_item_name;
4576 
4577                     Error_Handler.Add_Error_Token
4578                     (  p_Message_Name       => 'ENG_RIT_RTG_CANT_ADD_ALTERNATE'
4579                      , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4580                      , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4581                      , p_Token_Tbl          => l_Token_Tbl
4582                      );
4583                 END IF;
4584                 l_return_status := FND_API.G_RET_STS_ERROR;
4585         END IF;
4586         -- Added by MK on 08/26/2000
4587         **********************************************************************/
4588 
4589 IF BOM_Globals.get_debug = 'Y' THEN
4590      error_handler.write_debug('End of check primary routing and bill, the return status is ' || l_Return_Status);
4591 END IF;
4592 
4593 
4594         /*********************************************************************
4595         --
4596         -- If revised item is being referenced as pending on another ECO
4597         -- then log warning
4598         --
4599         **********************************************************************/
4600 
4601         IF (p_control_rec.caller_type = 'FORM'
4602             AND p_revised_item_rec.transaction_type = 'CREATE'
4603             AND p_control_rec.validation_controller = 'ALTERNATE_BOM_DESIGNATOR')
4604            OR
4605            (p_control_rec.caller_type <> 'FORM' AND p_control_rec.caller_type <> 'SSWA')
4606         THEN
4607                 IF Pending_ECO_Hint
4608                    ( p_Change_Notice    => p_revised_item_rec.eco_name
4609                    , p_Revised_Item_Id  => p_rev_item_unexp_rec.revised_item_id
4610                    , p_organization_id  => p_rev_item_unexp_rec.organization_id
4611                    )
4612                 THEN
4613 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('ENG_ITEM_IN_OTHER_ECOS Warning . . .'); END IF;
4614 
4615                         l_token_tbl.delete;
4616 
4617                         l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
4618                         l_token_tbl(1).token_value :=
4619                                         p_revised_item_rec.revised_item_name;
4620                         Error_Handler.Add_Error_Token
4621                         (  p_Message_Name       => 'ENG_ITEM_IN_OTHER_ECOS'
4622                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4623                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4624                          , p_Token_Tbl          => l_Token_Tbl
4625                          , p_message_type       => 'W');
4626                 END IF;
4627         END IF;
4628 
4629         IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('checked - if item is on other ECOs'); END IF;
4630 
4631 
4632         /*********************************************************************
4633         --
4634         -- Revised item scheduled_date cannot be greater than the disable date
4635         -- of any of its revised components with acd_type of Add or Change
4636         -- or if the ECO has an approval status of 'Approval Requested'
4637         --
4638         -- The below condition was modified by MK on 11/13/00
4639         **********************************************************************/
4640         IF p_revised_item_rec.Transaction_Type = ENG_Globals.G_OPR_UPDATE
4641            AND
4642            (  -- (p_control_rec.caller_type = 'FORM' AND
4643               --  p_control_rec.validation_controller = 'SCHEDULED_DATE')
4644               --  OR
4645               -- (p_control_rec.caller_type = 'OI' AND
4646               NVL( p_revised_item_rec.new_effective_date,
4647                    p_revised_item_rec.start_effective_date
4648                   ) <> p_old_revised_item_rec.start_effective_date
4649             )
4650         THEN
4651                 l_result := Check_Reschedule
4652                             (  p_revised_item_rec   => p_revised_item_rec
4653                              , p_rev_item_unexp_rec => p_rev_item_unexp_rec
4654                              );
4655                 IF l_result = 1 THEN
4656                         IF FND_MSG_PUB.Check_Msg_Level
4657                            (FND_MSG_PUB.G_MSG_LVL_ERROR)
4658                         THEN
4659                             l_token_tbl.delete;
4660                             l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
4661                             l_token_tbl(1).token_value :=
4662                                         p_revised_item_rec.revised_item_name;
4663                             l_token_tbl(2).token_name  := 'ECO_NAME';
4664                             l_token_tbl(2).token_value :=
4665                                         p_revised_item_rec.eco_name;
4666                             Error_Handler.Add_Error_Token
4667                             (  p_Message_Name   => 'ENG_ITEM_RESCHED_ECO_APPREQ'
4668                              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4669                              , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4670                              , p_Token_Tbl              => l_Token_Tbl
4671                              );
4672                         END IF;
4673                         l_return_status := FND_API.G_RET_STS_ERROR;
4674                 ELSIF l_result = 2 THEN
4675                         IF FND_MSG_PUB.Check_Msg_Level
4676                            (FND_MSG_PUB.G_MSG_LVL_ERROR)
4677                         THEN
4678                             l_token_tbl.delete;
4679                             l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
4680                             l_token_tbl(1).token_value :=
4681                                         p_revised_item_rec.revised_item_name;
4682 
4683                             Error_Handler.Add_Error_Token
4684                             (  p_Message_Name=> 'ENG_ITEM_RESCHED_COMP_DISABLED'
4685                              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4686                              , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4687                              , p_Token_Tbl              => l_Token_Tbl
4688                              );
4689                         END IF;
4690                         l_return_status := FND_API.G_RET_STS_ERROR;
4691                 END IF;
4692         END IF;
4693 
4694 IF BOM_Globals.get_debug = 'Y' THEN
4695      error_handler.write_debug('End of new revised item, the return status is ' ||  l_Return_Status);
4696 END IF;
4697 
4698         /*********************************************************************
4699         -- Added by MK on 09/01/2000
4700         -- Revised item scheduled_date cannot be greater than the disable date
4701         -- of any of its revised operations with acd_type of Add or Change
4702         -- Modified below condition by MK on 11/13/00
4703         **********************************************************************/
4704         IF p_revised_item_rec.transaction_type = ENG_Globals.G_OPR_UPDATE
4705            AND
4706            (  -- (p_control_rec.caller_type = 'FORM' AND
4707               --  p_control_rec.validation_controller = 'SCHEDULED_DATE')
4708               -- OR
4709               -- (p_control_rec.caller_type = 'OI' AND
4710              NVL( p_revised_item_rec.new_effective_date,
4711                  p_revised_item_rec.start_effective_date
4712                  ) <> p_old_revised_item_rec.start_effective_date
4713            )
4714         THEN
4715                 IF NOT Check_Rtg_Reschedule
4716                             (  p_revised_item_rec   => p_revised_item_rec
4717                              , p_rev_item_unexp_rec => p_rev_item_unexp_rec
4718                              )
4719                 THEN
4720                     IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4721                     THEN
4722                         l_token_tbl.delete;
4723                         l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
4724                         l_token_tbl(1).token_value := p_revised_item_rec.revised_item_name;
4725                         Error_Handler.Add_Error_Token
4726                             (  p_Message_Name=> 'ENG_ITEM_RESCHED_OP_DISABLED'
4727                              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4728                              , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4729                              , p_Token_Tbl      => l_Token_Tbl
4730                              );
4731 
4732                      END IF;
4733                      l_return_status := FND_API.G_RET_STS_ERROR;
4734                 END IF;
4735         END IF;
4736         -- Added by MK on 09/01/2000
4737 IF BOM_Globals.get_debug = 'Y' THEN
4738      error_handler.write_debug('End of transaction type and call type chceck, the return status is '||
4739                                 l_Return_Status);
4740 END IF;
4741 
4742 
4743 
4744         /*********************************************************************
4745         --
4746         -- Revised item status_type cannot change to 'Open', 'Hold', 'Released',
4747         -- 'Scheduled' if ECO status is not 'Open'
4748         --
4749         **********************************************************************/
4750 
4751         IF  p_control_rec.caller_type <> 'FORM' AND
4752             (( p_revised_item_rec.transaction_type=ENG_Globals.G_OPR_UPDATE AND
4753                NVL( p_revised_item_rec.status_type, 0) <>
4754                     p_old_revised_item_rec.status_type
4755               )
4756             )
4757            AND
4758            NOT ECO_Open
4759                (  p_change_notice   => p_revised_item_rec.eco_name
4760                 , p_organization_id => p_rev_item_unexp_rec.organization_id
4761                 )
4762            AND
4763            p_revised_item_rec.status_type IN (1,2,4,7)
4764 	   AND p_control_rec.caller_type <> 'SSWA'
4765         THEN
4766                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4767                 THEN
4768                         l_token_tbl.delete;
4769                         l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
4770                         l_token_tbl(1).token_value :=
4771                                         p_revised_item_rec.revised_item_name;
4772                         l_token_tbl(2).token_name  := 'STATUS_TYPE';
4773                         l_token_tbl(2).token_value :=
4774                                         p_revised_item_rec.status_type;
4775                         l_token_tbl(3).token_name  := 'ECO_NAME';
4776                         l_token_tbl(3).token_value := p_revised_item_rec.eco_name;
4777                         Error_Handler.Add_Error_Token
4778                         (  p_Message_Name       => 'ENG_RIT_STAT_ECO_NOT_OPEN'
4779                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4780                          , x_Mesg_Token_tbl     => l_Mesg_Token_Tbl
4781                          , p_Token_Tbl          => l_Token_Tbl);
4782                 END IF;
4783                 l_return_status := FND_API.G_RET_STS_ERROR;
4784         END IF;
4785 IF BOM_Globals.get_debug = 'Y' THEN
4786      error_handler.write_debug('End of call type check for form, the return status is ' ||
4787                                 l_Return_Status);
4788 END IF;
4789 
4790 
4791         /*******************************************************************
4792         --
4793         -- If creates, then the revised item status type must be the same
4794         -- as the status type of the ECO. This excludes ECO status of
4795         -- cancel because in that case ECO is not updateable.
4796         --
4797         ********************************************************************/
4798         IF p_control_rec.caller_type <> 'FORM' AND
4799            p_revised_item_rec.transaction_type = Eng_Globals.G_OPR_CREATE
4800 	   AND l_plm_or_erp_change = 'ERP'          -- Added for bug 3618676
4801         THEN
4802                 BEGIN
4803                         SELECT 1
4804                           INTO l_result
4805                           FROM eng_engineering_changes
4806                          WHERE change_notice   = p_revised_item_rec.eco_name
4807                            AND organization_id =
4808                                         p_rev_item_unexp_rec.organization_id
4809                            AND status_type = p_revised_item_rec.status_type;
4810 
4811 
4812                         --
4813                         -- if no exceptions are raised then the status
4814                         -- type match. Other wise it is an error.
4815                         --
4816                         EXCEPTION
4817                            WHEN NO_DATA_FOUND THEN
4818                                 IF FND_MSG_PUB.Check_Msg_Level
4819                                    (FND_MSG_PUB.G_MSG_LVL_ERROR)
4820                                 THEN
4821                                   l_token_tbl.delete;
4822                                   Error_Handler.Add_Error_Token
4823                                   ( p_Message_Name    =>
4824                                                  'ENG_RIT_CREATE_STAT_INVALID'
4825                                    , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4826                                    , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4827                                    );
4828                                 END IF;
4829                                 l_return_status := FND_API.G_RET_STS_ERROR;
4830                 END;
4831         END IF;
4832 IF BOM_Globals.get_debug = 'Y' THEN
4833      error_handler.write_debug('End of check call type, the return status is '|| l_Return_Status);
4834 END IF;
4835 
4836 
4837         /*********************************************************************
4838         --
4839         -- Revised item status_type cannot change if ECO status_type
4840         -- is set to 'Approval Requested'
4841         --
4842         **********************************************************************/
4843 
4844         IF  p_revised_item_rec.transaction_type = ENG_Globals.G_OPR_UPDATE AND
4845             NVL(p_revised_item_rec.status_type, 0) <>
4846                 p_old_revised_item_rec.status_type
4847             AND p_control_rec.caller_type <> 'SSWA'
4848 	    AND
4849             ECO_Approval_Requested
4850             (  p_change_notice => p_revised_item_rec.eco_name
4851              , p_organization_id => p_rev_item_unexp_rec.organization_id
4852              )
4853 
4854         THEN
4855                l_token_tbl.delete;
4856                l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
4857                l_token_tbl(1).token_value :=
4858                                    p_revised_item_rec.revised_item_name;
4859                l_token_tbl(2).token_name  := 'STATUS_TYPE';
4860                l_token_tbl(2).token_value :=
4861                                    p_revised_item_rec.status_type;
4862 
4863                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4864                 THEN
4865                         Error_Handler.Add_Error_Token
4866                         (  p_Message_Name       => 'ENG_RIT_STAT_ECO_APPREQ'
4867                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4868                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4869                          , p_Token_Tbl          => l_Token_Tbl
4870                          );
4871                 END IF;
4872                 l_return_status := FND_API.G_RET_STS_ERROR;
4873         END IF;
4874 
4875         IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('checked - is status updateable'); END IF;
4876 
4877         -- Cannot have new revision for alternate bill item
4878 
4879         /*********************************************************************
4880         -- Comment out by MK on 02/15/2001
4881         -- No longer used. Instead of this validation, Added new the new
4882         -- validation
4883         FOR alt IN c_GetAlternateDesignator
4884         LOOP
4885                 l_alternate_bom_designator :=
4886                         alt.alternate_bom_designator;
4887                 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('alternate: ' || l_alternate_bom_designator); END IF;
4888         END LOOP;
4889 
4890         IF l_alternate_bom_designator IS NOT NULL AND
4891            (p_revised_item_rec.alternate_bom_code <>
4892             l_alternate_bom_designator
4893             ) AND
4894             p_revised_item_rec.transaction_type = Eng_globals.G_OPR_UPDATE
4895         THEN
4896                 l_token_tbl.DELETE;
4897                 l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
4898                 l_token_tbl(1).token_value :=
4899                                         p_revised_item_rec.revised_item_name;
4900                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4901                 THEN
4902                         Error_Handler.Add_Error_Token
4903                         (  p_Message_Name       => 'ENG_ALT_DESG_NOT_UPDATEABLE'
4904                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4905                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4906                          , p_Token_Tbl          => l_Token_Tbl
4907                         );
4908                 END IF;
4909                 l_return_status := FND_API.G_RET_STS_ERROR;
4910         END IF;
4911         **********************************************************************/
4912 
4913         l_token_tbl.delete;
4914         l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
4915         l_token_tbl(1).token_value := p_revised_item_rec.revised_item_name;
4916 
4917 
4918         IF p_revised_item_rec.new_revised_item_revision IS NOT NULL AND
4919            p_revised_item_rec.alternate_bom_code IS NOT NULL AND
4920            p_revised_item_rec.transaction_type = Eng_Globals.G_OPR_CREATE
4921            AND l_plm_or_erp_change <> 'PLM'
4922         THEN
4923                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4924                 THEN
4925                         Error_Handler.Add_Error_Token
4926                         (  p_Message_Name       => 'ENG_CANNOT_HAVE_REVISION'
4927                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4928                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4929                          , p_Token_Tbl          => l_Token_Tbl
4930                         );
4931                 END IF;
4932                 l_return_status := FND_API.G_RET_STS_ERROR;
4933         ELSIF p_revised_item_rec.transaction_type = Eng_Globals.G_OPR_UPDATE AND
4934               p_revised_item_rec.alternate_bom_code IS NOT NULL AND
4935               p_revised_item_rec.updated_revised_item_revision IS NOT NULL
4936               AND l_plm_or_erp_change <> 'PLM'
4937         THEN
4938                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4939                 THEN
4940                         Error_Handler.Add_Error_Token
4941                         (  p_Message_Name   => 'ENG_CANNOT_HAVE_REVISION'
4942                          , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4943                          , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4944                          , p_Token_Tbl      => l_Token_Tbl
4945                         );
4946                 END IF;
4947                 l_return_status := FND_API.G_RET_STS_ERROR;
4948         END IF;
4949 IF Bom_Globals.Get_Debug = 'Y' THEN
4950    Error_Handler.Write_Debug('After checking item  revision is null when alt code is not null, the return status is ' || l_return_status );
4951 END IF;
4952 
4953 
4954         -- Revised Item must have a current (implemented) revision
4955 
4956         l_current_item_revision := Get_Current_Item_Revision
4957            (  p_revised_item_id => p_rev_item_unexp_rec.revised_item_id
4958             , p_organization_id => p_rev_item_unexp_rec.organization_id
4959             , p_revision_date   => SYSDATE
4960             );
4961         IF l_current_item_revision IS NULL AND
4962            p_Revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE
4963         THEN
4964                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4965                 THEN
4966                         Error_Handler.Add_Error_Token
4967                         (  p_Message_Name       => 'ENG_ITEM_NO_CURR_REV'
4968                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4969                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4970                          , p_Token_Tbl          => l_Token_Tbl
4971                         );
4972                 END IF;
4973                 l_return_status := FND_API.G_RET_STS_ERROR;
4974         END IF;
4975 
4976         IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('checked - is there current item rev. for item'); END IF;
4977 
4978         l_token_tbl.delete;
4979         l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
4980         l_token_tbl(1).token_value := p_revised_item_rec.revised_item_name;
4981 
4982         /*********************************************************************
4983         --
4984         -- Added by AS on 09/13/99.
4985         -- Fixed bug 902423 in business object APIs also.
4986         -- Cannot enter a revision that is equal to CURRENT revision if
4987         -- profile ENG: Require Revised Item New Revision is set to Yes.
4988         **********************************************************************/
4989 
4990         IF  l_new_rev_required = 1 AND
4991             (( p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE AND
4992               p_revised_item_rec.new_revised_item_revision = l_current_item_revision)
4993              OR
4994              ( p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE AND
4995                p_revised_item_rec.updated_revised_item_revision = l_current_item_revision))
4996         THEN
4997                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4998                 THEN
4999                         Error_Handler.Add_Error_Token
5000                         (  p_Message_Name       => 'ENG_ITEM_REV_NOT_EQ_CURR_REV'
5001                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5002                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5003                          , p_Token_Tbl          => l_Token_Tbl
5004                          );
5005                 END IF;
5006                 l_return_status := FND_API.G_RET_STS_ERROR;
5007         END IF;
5008 IF BOM_Globals.get_debug = 'Y' THEN
5009      error_handler.write_debug('End of validating revision, the return status is ' || l_Return_Status);
5010 END IF;
5011 
5012         /*********************************************************************
5013         --
5014         -- if the operation is create, the check new_revised_item_rev
5015         -- else check updated_revised_item_revision
5016         --
5017         **********************************************************************/
5018 
5019         IF ( p_revised_item_rec.updated_revised_item_revision <>
5020              p_old_revised_item_rec.new_revised_item_revision AND
5021              p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE
5022            ) OR
5023            (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE AND
5024             p_revised_item_rec.new_revised_item_revision IS NOT NULL)
5025         THEN
5026 
5027             -- 11.5.10E
5028             -- Using from revision instead of the current revision in case
5029             -- of PLM.
5030             IF (l_plm_or_erp_change = 'PLM' AND
5031                 p_revised_item_rec.from_item_revision IS NOT NULL AND
5032                 p_revised_item_rec.from_item_revision <> FND_API.G_MISS_CHAR)
5033             THEN
5034               l_from_revision := p_revised_item_rec.from_item_revision;
5035               l_message_name := 'ENG_NEW_ITEM_REV_NOT_VALID';
5036             ELSE
5037               l_from_revision := Get_Current_Item_Revision
5038                                   ( p_revised_item_id => p_rev_item_unexp_rec.revised_item_id
5039                                   , p_organization_id => p_rev_item_unexp_rec.organization_id
5040                                   , p_revision_date   => SYSDATE
5041                                    );
5042               l_message_name := 'ENG_NEW_ITEM_REV_NOT_CURR';
5043             END IF;
5044 
5045                 --
5046                 -- if the operation is create, the check new_revised_item_rev
5047                 -- else check updated_revised_item_revision
5048                 --
5049 
5050             IF p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE
5051             THEN
5052                 l_new_revision_status :=
5053                 Validate_New_Item_Revision
5054                 (  p_revised_item_id    => p_rev_item_unexp_rec.revised_item_id
5055                 , p_organization_id     => p_rev_item_unexp_rec.organization_id
5056                 , p_from_revision       => l_from_revision
5057                 , p_new_item_revision   =>
5058                                 p_revised_item_rec.new_revised_item_revision
5059                 , p_revised_item_sequence_id    =>
5060                                 p_rev_item_unexp_rec.revised_item_sequence_id
5061                 , x_change_notice       => l_change_notice
5062                 );
5063 		if ((l_new_revision_status = 2) and (l_change_notice =  p_revised_item_rec.eco_name)
5064 		and p_control_rec.caller_type = 'FORM' -- Added for bug 3432944
5065 		-- Skipping the validation of revision of a revised item when craeted using form, since
5066 		-- it is done at form commit.
5067 		) then
5068 			l_new_revision_status := 0;
5069 		end if;
5070             ELSE /* If Update, pass updated_revised_item_revision */
5071                   l_new_revision_status :=
5072                 Validate_New_Item_Revision
5073                 (  p_revised_item_id    => p_rev_item_unexp_rec.revised_item_id
5074                 , p_organization_id     => p_rev_item_unexp_rec.organization_id
5075                 , p_from_revision       => l_from_revision
5076                 , p_new_item_revision   =>
5077                         p_revised_item_rec.updated_revised_item_revision
5078                 , p_revised_item_sequence_id    =>
5079                         p_rev_item_unexp_rec.revised_item_sequence_id
5080                 , x_change_notice       => l_change_notice
5081                 );
5082             END IF;
5083 
5084             IF l_new_revision_status = 1
5085             THEN
5086                         IF FND_MSG_PUB.Check_Msg_Level
5087                            (FND_MSG_PUB.G_MSG_LVL_ERROR)
5088                         THEN
5089                                 Error_Handler.Add_Error_Token
5090                                 ( --p_Message_Name  => 'ENG_NEW_ITEM_REV_NOT_CURR'
5091                                   p_Message_Name   => l_message_name
5092                                 , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5093                                 , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5094                                 , p_Token_Tbl      => l_Token_Tbl);
5095                         END IF;
5096                         l_return_status := FND_API.G_RET_STS_ERROR;
5097             ELSIF l_new_revision_status = 2
5098             THEN
5099                         l_token_tbl.delete;
5100 
5101                  -- Added by MK on 11/05/00
5102                  IF p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE
5103                  THEN
5104                         l_token_tbl(1).token_name  := 'NEW_UPD_ITEM_REVISION';
5105                         l_token_tbl(1).token_value := p_revised_item_rec.new_revised_item_revision;
5106                  ELSE
5107                         l_token_tbl(1).token_name  := 'NEW_UPD_ITEM_REVISION';
5108                         l_token_tbl(1).token_value := p_revised_item_rec.updated_revised_item_revision ;
5109                  END IF ;
5110 
5111 
5112                         l_token_tbl(2).token_name :=  'REVISED_ITEM_NAME';
5113                         l_token_tbl(2).token_value := p_revised_item_rec.revised_item_name;
5114 
5115                         l_token_tbl(3).token_name := 'ECO_NAME';
5116                         l_token_tbl(3).token_value := l_change_notice;
5117                         IF FND_MSG_PUB.Check_Msg_Level
5118                            (FND_MSG_PUB.G_MSG_LVL_ERROR)
5119                         THEN
5120                                 Error_Handler.Add_Error_Token
5121                                 (  p_Message_Name   => 'ENG_NEW_ITEM_REV_EXISTS'
5122                                  , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5123                                  , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5124                                  , p_token_tbl      => l_token_tbl
5125                                 );
5126                         END IF;
5127 
5128                         l_return_status := FND_API.G_RET_STS_ERROR;
5129             ELSIF l_new_revision_status = 3
5130             THEN
5131                         IF FND_MSG_PUB.Check_Msg_Level
5132                            (FND_MSG_PUB.G_MSG_LVL_ERROR)
5133                         THEN
5134                                 Error_Handler.Add_Error_Token
5135                                 (  p_Message_Name   => 'ENG_NEW_ITEM_REV_IMPL'
5136                                  , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5137                                  , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5138                                  , p_Token_Tbl      => l_Token_Tbl
5139                                 );
5140                         END IF;
5141                         l_return_status := FND_API.G_RET_STS_ERROR;
5142             END IF;
5143         END IF;
5144     IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('checked - is new item revision valid'); END IF;
5145 
5146         -- Changes for bug 3618662
5147 	IF Bom_Globals.Get_Debug = 'Y'
5148 	THEN
5149 		Error_Handler.Write_Debug('Validate if the revisions and effectivity dates in ascending order. . . . ');
5150         END IF;
5151 
5152         IF (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE
5153 	      AND p_revised_item_rec.new_revised_item_revision IS NOT NULL
5154 	      AND p_control_rec.caller_type <> 'FORM' AND p_control_rec.caller_type <> 'SSWA')
5155         THEN
5156 		l_is_revision_invalid := High_Date_Low_Revision (
5157 			    p_revised_item_id	=> p_rev_item_unexp_rec.revised_item_id
5158 			  , p_organization_id	=> p_rev_item_unexp_rec.organization_id
5159 			  , p_new_item_revision	=> p_revised_item_rec.new_revised_item_revision
5160 			  , p_scheduled_date	=> p_revised_item_rec.Start_Effective_Date
5161 			  , p_rev_item_seq_id	=> p_rev_item_unexp_rec.revised_item_sequence_id);
5162 	ELSIF (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE
5163 	       AND p_revised_item_rec.updated_revised_item_revision IS NOT NULL
5164 	       AND ((p_revised_item_rec.new_revised_item_revision IS NOT NULL
5165 	             AND p_revised_item_rec.updated_revised_item_revision <> p_revised_item_rec.new_revised_item_revision)
5166 		    OR (p_revised_item_rec.new_revised_item_revision IS NULL))
5167 	       AND p_control_rec.caller_type <> 'FORM' AND p_control_rec.caller_type <> 'SSWA')
5168 	THEN
5169 		l_is_revision_invalid := High_Date_Low_Revision (
5170 			    p_revised_item_id	=> p_rev_item_unexp_rec.revised_item_id
5171 			  , p_organization_id	=> p_rev_item_unexp_rec.organization_id
5172 			  , p_new_item_revision	=> p_revised_item_rec.updated_revised_item_revision
5173 			  , p_scheduled_date	=> NVL(p_revised_item_rec.New_Effective_Date, p_revised_item_rec.Start_Effective_Date)
5174 			  , p_rev_item_seq_id	=> p_rev_item_unexp_rec.revised_item_sequence_id);
5175 	END IF;
5176 
5177 	IF l_is_revision_invalid = 1
5178 	THEN
5179 	        IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5180                     THEN
5181 			l_Token_Tbl.delete;
5182                             Error_Handler.Add_Error_Token
5183                             (  p_Message_Name   => 'ENG_REVISION_ORDER'
5184                              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5185                              , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5186                              , p_Token_Tbl      => l_Token_Tbl
5187                             );
5188                     END IF;
5189                     l_return_status := FND_API.G_RET_STS_ERROR;
5190 	END IF;
5191         IF Bom_Globals.Get_Debug = 'Y'
5192 	THEN
5193 	Error_Handler.Write_Debug('End of validation of revisions and effectivity dates in ascending order.'
5194 	||' The return status is ' || l_Return_Status);
5195         END IF;
5196 	-- End changes for bug 3618662
5197 
5198         -- 11.5.10E
5199         -- The scheduled date must be greater than the effectivity date of the from revision
5200         IF (p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE
5201 	      AND p_revised_item_rec.new_revised_item_revision IS NULL
5202 	      AND p_control_rec.caller_type <> 'FORM' AND p_control_rec.caller_type <> 'SSWA'
5203               AND p_revised_item_rec.from_item_revision IS NOT NULL
5204               AND p_revised_item_rec.from_item_revision <> FND_API.G_MISS_CHAR)
5205         THEN
5206           l_is_scheduled_date_invalid := Scheduled_Date_From_Revision (
5207 			    p_revised_item_id    => p_rev_item_unexp_rec.revised_item_id
5208 			  , p_organization_id    => p_rev_item_unexp_rec.organization_id
5209 			  , p_from_item_revision => p_revised_item_rec.from_item_revision
5210 			  , p_scheduled_date     => p_revised_item_rec.Start_Effective_Date
5211 			  , p_rev_item_seq_id    => p_rev_item_unexp_rec.revised_item_sequence_id);
5212 
5213           IF l_is_scheduled_date_invalid = 1
5214           THEN
5215             IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5216             THEN
5217               Error_Handler.Add_Error_Token
5218                   (  p_Message_Name   => 'ENG_INVALID_SCHED_DATE'
5219                    , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5220                    , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5221                    , p_Token_Tbl      => l_Token_Tbl
5222                    );
5223             END IF;
5224             l_return_status := FND_API.G_RET_STS_ERROR;
5225           END IF;
5226 
5227         END IF;
5228 
5229 -- Fix for bug 3577967
5230   /*********************************************************************
5231           --  Bug No:3577967
5232           -- If the user is trying to  add Revised Items to the ECO and the Catalogue Catagory associated at the Subject Level
5233 	  -- to the header type of the ECO is not same as that of the Revised items the item should not get added as revised item.
5234           --
5235    **********************************************************************/
5236    IF p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE AND p_control_rec.caller_type <> 'SSWA'
5237    THEN
5238    IF BOM_Globals.get_debug = 'Y' THEN
5239      error_handler.write_debug('Verifying the subject level security for PLM ' );
5240    END IF;
5241    validate_rev_items_for_sub(
5242                  p_change_notice     => p_revised_item_rec.eco_name
5243                 ,p_inventory_item_id => p_rev_item_unexp_rec.revised_item_id
5244                 ,p_org_id            => p_rev_item_unexp_rec.organization_id
5245                 ,x_ret_Value         => l_ret_Value);
5246 
5247    IF (l_ret_Value = FALSE)   THEN
5248         l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
5249         l_token_tbl(1).token_value :=  p_revised_item_rec.revised_item_name;
5250         l_token_tbl(2).token_name  := 'ECO_NAME';
5251         l_token_tbl(2).token_value :=  p_revised_item_rec.eco_name;
5252         Error_Handler.Add_Error_Token
5253              (  p_Message_Name   => 'ENG_REV_ITEM_SUB_DIFF'
5254               , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5255               , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5256               , p_Token_Tbl      => l_Token_Tbl
5257              );
5258        l_return_status :=FND_API.G_RET_STS_ERROR;
5259    END IF;
5260    END IF;
5261     --  Done validating entity
5262 IF BOM_Globals.get_debug = 'Y' THEN
5263      error_handler.write_debug('End of validating entity, the return status is ' || l_Return_Status);
5264 END IF;
5265 
5266     x_return_status := l_return_status;
5267     x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
5268 
5269 EXCEPTION
5270     WHEN FND_API.G_EXC_ERROR THEN
5271 
5272         x_return_status := FND_API.G_RET_STS_ERROR;
5273         x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
5274 
5275     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5276 
5277         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5278         x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
5279 
5280     WHEN OTHERS THEN
5281 
5282         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5283 
5284         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5285         THEN
5286             l_err_text := G_PKG_NAME || ' : (Entity Validation) ' ||
5287                           substrb(SQLERRM,1,200);
5288             Error_Handler.Add_Error_Token
5289             (  p_Message_Name   => NULL
5290              , p_Message_Text   => l_err_text
5291              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5292              , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5293              );
5294         END IF;
5295         x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
5296 
5297 END Check_Entity;
5298 
5299 
5300 /******************************************************************************
5301 * Function      : Get_Approval_Status (Local function)
5302 * Parameters    : Revised item id
5303 *                 Organization Id
5304 * Returns       : The Approval Status of the item.
5305 ******************************************************************************/
5306 
5307 FUNCTION Get_Approval_Status
5308 (  p_item_id     IN    NUMBER,
5309    p_org_id      IN    NUMBER)
5310 RETURN VARCHAR2 IS
5311     l_approval_status  VARCHAR2(30);
5312 
5313     CURSOR c_approval_status IS
5314     SELECT nvl(approval_status,'A')
5315     FROM MTL_SYSTEM_ITEMS_B
5316     WHERE inventory_item_id = p_item_id
5317     AND   organization_id   = p_org_id;
5318 BEGIN
5319     OPEN c_approval_status;
5320     FETCH c_approval_status INTO l_approval_status;
5321     CLOSE c_approval_status;
5322     RETURN l_approval_status;
5323 END Get_Approval_Status;
5324 
5325 
5326 --  Procedure Attributes
5327 /****************************************************************************
5328 * Procedure     : Check_Attributes
5329 * Parameters IN : Revised Item Exposed Column record
5330 *                 Revised Item Unexposed Column record
5331 *                 Old Revised Item Exposed Column record
5332 *                 Old Revised Item unexposed column record
5333 * Parameters OUT: Return Status
5334 *                 Mesg Token Table
5335 * Purpose       : Check_Attrbibutes procedure will validate every revised item
5336 *                 attrbiute in its entirety.
5337 *****************************************************************************/
5338 PROCEDURE Check_Attributes
5339 (  x_return_status              OUT  NOCOPY VARCHAR2
5340  , x_Mesg_Token_Tbl             OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
5341  , p_revised_item_rec           IN  ENG_Eco_PUB.Revised_Item_Rec_Type
5342  , p_rev_item_unexp_rec         IN  Eng_Eco_Pub.Rev_Item_Unexposed_Rec_Type
5343  , p_old_revised_item_rec       IN  ENG_Eco_PUB.Revised_Item_Rec_Type
5344  , p_old_rev_item_unexp_rec     IN  Eng_Eco_Pub.Rev_Item_Unexposed_Rec_Type
5345 )
5346 IS
5347    l_err_text              VARCHAR2(2000) := NULL;
5348    l_Mesg_Token_Tbl        Error_Handler.Mesg_Token_Tbl_Type;
5349    l_Token_Tbl             Error_Handler.Token_Tbl_Type;
5350 
5351    -- Added by MK on 02/15/2001
5352    -- to validate alternate designator.
5353    CURSOR c_Check_Alternate(  p_alt_designator     VARCHAR2,
5354                               p_organization_id    NUMBER ) IS
5355    SELECT 'Invalid Alaternatae'
5356    FROM   SYS.DUAL
5357    WHERE  NOT EXISTS ( SELECT NULL
5358                        FROM bom_alternate_designators
5359                        WHERE alternate_designator_code = p_alt_designator
5360                        AND organization_id = p_organization_id
5361                      ) ;
5362 
5363 
5364 BEGIN
5365 
5366     x_return_status := FND_API.G_RET_STS_SUCCESS;
5367 
5368 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Within Revised Item Check Attributes . . .'); END IF;
5369 
5370     -- Set revised item token name and value.
5371 
5372     l_Token_Tbl(1).Token_Name  := 'REVISED_ITEM_NAME';
5373     l_Token_Tbl(1).Token_Value := p_revised_item_rec.revised_item_name;
5374 
5375     --  Validate revised_item attributes
5376 
5377     IF  p_revised_item_rec.status_type IS NOT NULL AND
5378         (   p_revised_item_rec.status_type <>
5379             p_old_revised_item_rec.status_type OR
5380             p_old_revised_item_rec.status_type IS NULL )
5381     THEN
5382         IF NOT ENG_Validate.Status_Type(p_revised_item_rec.status_type ,
5383                                         l_err_text ) THEN
5384             IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5385             THEN
5386                 l_token_tbl(2).token_name  := 'STATUS_TYPE';
5387                 l_token_tbl(2).token_value := p_revised_item_rec.status_type;
5388                 Error_Handler.Add_Error_Token
5389                 (  p_Message_Name       => 'ENG_RIT_STAT_TYPE_INVALID'
5390                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5391                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5392                  , p_Token_Tbl          => l_Token_Tbl);
5393            END IF;
5394 
5395             x_return_status := FND_API.G_RET_STS_ERROR;
5396         END IF;
5397 
5398         -- Status Type cannot be missing.
5399         IF p_revised_item_rec.status_type = FND_API.G_MISS_NUM
5400         THEN
5401             IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5402             THEN
5403                 Error_Handler.Add_Error_Token
5404                 (  p_Message_Name       => 'ENG_RIT_STAT_TYPE_MISSING'
5405                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5406                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5407                  , p_Token_Tbl          => l_Token_Tbl);
5408            END IF;
5409 
5410             x_return_status := FND_API.G_RET_STS_ERROR;
5411 
5412         END IF;
5413 
5414 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Status Type Validated . . . ' ); END IF;
5415 
5416         --  Creates or Updates of records marked Implemented is not allowed
5417         IF p_revised_item_rec.status_type = 6
5418         THEN
5419                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5420                 THEN
5421                         Error_Handler.Add_Error_Token
5422                         (  p_Message_Name       => 'ENG_RIT_STAT_CANNOT_BE_IMPL'
5423                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5424                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5425                         );
5426            END IF;
5427            x_return_status := FND_API.G_RET_STS_ERROR;
5428         END IF;
5429 
5430 
5431         /* Comment out by MK on 12/06/00
5432         --  This validation is no longer used.
5433         --  Creates of revised items that are not OPEN is not allowed
5434         IF p_revised_item_rec.transaction_type = 'CREATE'
5435            AND
5436            ( p_revised_item_rec.status_type <> 1 AND
5437              p_revised_item_rec.status_type <> 4
5438             )
5439         THEN
5440                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5441                 THEN
5442                         Error_Handler.Add_Error_Token
5443                         (  p_Message_Name       => 'ENG_RIT_CREATE_STAT_INVALID'
5444                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5445                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5446                         );
5447            END IF;
5448            x_return_status := FND_API.G_RET_STS_ERROR;
5449         END IF;
5450         */   -- Comment out
5451 
5452 
5453     END IF;
5454 
5455     IF  p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_CREATE AND
5456         (p_revised_item_rec.from_end_item_unit_number IS NOT NULL
5457          AND
5458          p_revised_item_rec.from_end_item_unit_number <> FND_API.G_MISS_CHAR)
5459     THEN
5460         IF NOT  ENG_Validate.End_Item_Unit_Number
5461                 ( p_from_end_item_unit_number =>
5462                         p_revised_item_rec.from_end_item_unit_number
5463                 , p_revised_item_id =>
5464                         p_rev_item_unexp_rec.revised_item_id
5465                 , x_err_text => l_err_text
5466                 )
5467         THEN
5468             x_return_status := FND_API.G_RET_STS_ERROR;
5469             IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5470             THEN
5471                      l_token_tbl(2).token_name  := 'FROM_END_ITEM_UNIT_NUMBER';
5472                      l_token_tbl(2).token_value :=
5473                                     p_revised_item_rec.from_end_item_unit_number;
5474                      Error_Handler.Add_Error_Token
5475                      ( p_Message_Name       => 'ENG_FROM_END_ITEM_INVALID'
5476                      , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5477                      , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5478                      , p_Token_Tbl          => l_Token_Tbl
5479                      );
5480             END IF;
5481         END IF;
5482     END IF;
5483 
5484     IF  p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE AND
5485         (p_revised_item_rec.new_from_end_item_unit_number IS NOT NULL
5486          AND
5487          p_revised_item_rec.new_from_end_item_unit_number <> FND_API.G_MISS_CHAR)
5488     THEN
5489         IF NOT  ENG_Validate.End_Item_Unit_Number
5490                 ( p_from_end_item_unit_number =>
5491                         p_revised_item_rec.new_from_end_item_unit_number
5492                 , p_revised_item_id =>
5493                         p_rev_item_unexp_rec.revised_item_id
5494                 , x_err_text => l_err_text
5495                 )
5496         THEN
5497             x_return_status := FND_API.G_RET_STS_ERROR;
5498             IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5499             THEN
5500                      l_token_tbl(2).token_name  := 'FROM_END_ITEM_UNIT_NUMBER';
5501                      l_token_tbl(2).token_value :=
5502                                     p_revised_item_rec.new_from_end_item_unit_number;
5503                      Error_Handler.Add_Error_Token
5504                      ( p_Message_Name       => 'ENG_FROM_END_ITEM_INVALID'
5505                      , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5506                      , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5507                      , p_Token_Tbl          => l_Token_Tbl
5508                      );
5509             END IF;
5510         END IF;
5511     END IF;
5512 
5513     IF  p_revised_item_rec.mrp_active IS NOT NULL AND
5514         (   p_revised_item_rec.mrp_active <>
5515             p_old_revised_item_rec.mrp_active OR
5516             p_old_revised_item_rec.mrp_active IS NULL )
5517     THEN
5518         IF NOT ENG_Validate.Mrp_Active(p_revised_item_rec.mrp_active ,
5519                                         l_err_text ) THEN
5520             x_return_status := FND_API.G_RET_STS_ERROR;
5521                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5522                 THEN
5523                         l_token_tbl(2).token_name  := 'MRP_ACTIVE';
5524                         l_token_tbl(2).token_value :=
5525                                                 p_revised_item_rec.mrp_active;
5526                         Error_Handler.Add_Error_Token
5527                         (  p_Message_Name       => 'ENG_MRP_ACTIVE_INVALID'
5528                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5529                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5530                          , p_Token_Tbl          => l_Token_Tbl
5531                         );
5532                 END IF;
5533 
5534         END IF;
5535     END IF;
5536 
5537     IF p_revised_item_rec.mrp_active = FND_API.G_MISS_NUM
5538     THEN
5539         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5540         THEN
5541                 Error_Handler.Add_Error_Token
5542                 (  p_Message_Name       => 'ENG_MRP_ACTIVE_MISSING'
5543                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5544                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5545                  , p_Token_Tbl          => l_Token_Tbl
5546                  );
5547         END IF;
5548 
5549             x_return_status := FND_API.G_RET_STS_ERROR;
5550 
5551     END IF;
5552 
5553 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('MRP Active Validated . . .'); END IF;
5554 
5555     IF  p_revised_item_rec.update_wip IS NOT NULL AND
5556         (   p_revised_item_rec.update_wip <>
5557             p_old_revised_item_rec.update_wip OR
5558             p_old_revised_item_rec.update_wip IS NULL )
5559     THEN
5560         IF NOT ENG_Validate.Update_Wip(p_revised_item_rec.update_wip ,
5561                                         l_err_text ) THEN
5562             x_return_status := FND_API.G_RET_STS_ERROR;
5563             IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5564             THEN
5565                         l_token_tbl(2).token_name  := 'UPDATE_WIP';
5566                         l_token_tbl(2).token_value :=
5567                                                 p_revised_item_rec.update_wip;
5568                         Error_Handler.Add_Error_Token
5569                         (  p_Message_Name       => 'ENG_UPDATE_WIP_INVALID'
5570                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5571                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5572                          , p_Token_Tbl          => l_Token_Tbl
5573                         );
5574              END IF;
5575         END IF;
5576     END IF;
5577 
5578     IF p_revised_item_rec.update_wip = FND_API.G_MISS_NUM
5579     THEN
5580         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5581         THEN
5582                 Error_Handler.Add_Error_Token
5583                 (  p_Message_Name       => 'ENG_UPDATE_WIP_MISSING'
5584                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5585                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5586                  , p_Token_Tbl          => l_Token_Tbl
5587                  );
5588         END IF;
5589 
5590             x_return_status := FND_API.G_RET_STS_ERROR;
5591 
5592     END IF;
5593 
5594 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Update WIP Validated . . .'); END IF;
5595 
5596     IF  p_revised_item_rec.use_up_plan_name IS NOT NULL AND
5597         (   p_revised_item_rec.use_up_plan_name <>
5598             p_old_revised_item_rec.use_up_plan_name OR
5599             p_old_revised_item_rec.use_up_plan_name IS NULL )
5600     THEN
5601         IF NOT ENG_Validate.Use_Up_Plan_Name
5602                         (  p_revised_item_rec.use_up_plan_name
5603                          , p_rev_item_unexp_rec.organization_id
5604                          , l_err_text )
5605         THEN
5606                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5607                 THEN
5608                         -- If the function returns with an error then
5609                         -- l_err_text will carry the message_name to be
5610                         -- displayed.
5611                         l_token_tbl(1).token_name  := 'USE_UP_PLAN_NAME';
5612                         l_token_tbl(1).token_value :=
5613                                         p_revised_item_rec.use_up_plan_name;
5614 
5615                         IF l_err_text = 'ENG_USE_UP_PLAN_INVALID'
5616                         THEN
5617                            l_token_tbl(2).token_name  := 'ORGANIZATION_CODE';
5618                            l_token_tbl(2).token_value :=
5619                                         p_revised_item_rec.organization_code;
5620                         ELSIF l_err_text = 'ENG_DATA_COMPL_DATE_INVALID' OR
5621                               l_err_text = 'ENG_PLAN_COMPL_DATE_INVALID'
5622                         THEN
5623                            l_token_tbl(2).token_name  := 'REVISED_ITEM_NAME';
5624                            l_token_tbl(2).token_value :=
5625                                         p_revised_item_rec.revised_item_name;
5626                         END IF;
5627 
5628                         Error_Handler.Add_Error_Token
5629                         (  p_Message_Name   => l_err_text
5630                          , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5631                          , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5632                          , p_Token_Tbl      => l_Token_Tbl
5633                          );
5634 IF Bom_Globals.Get_Debug = 'Y' THEN
5635     Error_Handler.Write_Debug('Use_Up_Plan validation returned with an error ' ||
5636                               l_err_text);
5637 END IF;
5638                 END IF;
5639             x_return_status := FND_API.G_RET_STS_ERROR;
5640         END IF;
5641     END IF;
5642 
5643     IF  p_revised_item_rec.disposition_type IS NOT NULL AND
5644         (   p_revised_item_rec.disposition_type <>
5645             p_old_revised_item_rec.disposition_type OR
5646             p_old_revised_item_rec.disposition_type IS NULL )
5647     THEN
5648         IF NOT ENG_Validate.Disposition_Type
5649                 (  p_revised_item_rec.disposition_type
5650                  , l_err_text )
5651         THEN
5652                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5653                 THEN
5654                         l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
5655                         l_token_tbl(1).token_value :=
5656                                         p_revised_item_rec.revised_item_name;
5657                         l_token_tbl(2).token_name  := 'DISPOSITION_TYPE';
5658                         l_token_tbl(2).token_value :=
5659                                         p_revised_item_rec.disposition_type;
5660                         Error_Handler.Add_Error_Token
5661                         (  p_Message_Name   => 'ENG_DISPOSITION_TYPE_INVALID'
5662                          , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5663                          , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5664                          , p_Token_Tbl      => l_Token_Tbl
5665                          );
5666                 END IF;
5667                 x_return_status := FND_API.G_RET_STS_ERROR;
5668         END IF;
5669     END IF;
5670 
5671     IF p_revised_item_rec.disposition_type = FND_API.G_MISS_NUM
5672     THEN
5673         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5674         THEN
5675              Error_Handler.Add_Error_Token
5676              (  p_Message_Name    => 'ENG_DISPOSITION_TYPE_MISSING'
5677               , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
5678               , x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
5679               , p_Token_Tbl       => l_Token_Tbl
5680               );
5681         END IF;
5682         x_return_status := FND_API.G_RET_STS_ERROR;
5683     END IF;
5684 
5685 
5686     /**********************************************************************
5687     -- Following Attribute Validations are for ECO Routing or
5688     -- New ECO Effectivities
5689     -- Added by MK 08/24/2000
5690     **********************************************************************/
5691     -- CTP Flag
5692     IF p_revised_item_rec.ctp_flag IS NOT NULL AND
5693        p_revised_item_rec.ctp_flag <> FND_API.G_MISS_NUM AND
5694        p_revised_item_rec.ctp_flag NOT IN (1,2)
5695     THEN
5696         l_token_tbl(1).token_name  := 'ASSEMBLY_ITEM_NAME';
5697         l_token_tbl(1).token_value := p_revised_item_rec.revised_item_name;
5698         Error_Handler.Add_Error_Token
5699         (  p_message_name       => 'BOM_RTG_CTP_INVALID'
5700          , p_token_tbl          => l_token_tbl
5701          , p_mesg_token_tbl     => l_mesg_token_tbl
5702          , x_mesg_token_tbl     => l_mesg_token_tbl
5703         );
5704         x_return_status := FND_API.G_RET_STS_ERROR;
5705     END IF;
5706 
5707     -- Eco For Production Added by MK on 10/06/2000
5708     IF p_revised_item_rec.eco_for_production IS NOT NULL AND
5709        p_revised_item_rec.eco_for_production <> FND_API.G_MISS_NUM AND
5710        p_revised_item_rec.eco_for_production NOT IN (1,2)
5711     THEN
5712         l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
5713         l_token_tbl(1).token_value := p_revised_item_rec.revised_item_name;
5714         Error_Handler.Add_Error_Token
5715         (  p_message_name       => 'ENG_RIT_ECO_FOR_PROD_INVALID'
5716          , p_token_tbl          => l_token_tbl
5717          , p_mesg_token_tbl     => l_mesg_token_tbl
5718          , x_mesg_token_tbl     => l_mesg_token_tbl
5719         );
5720         x_return_status := FND_API.G_RET_STS_ERROR;
5721     END IF;
5722 
5723     -- Missing Eco For Production Added by MK on 10/06/2000
5724     IF p_revised_item_rec.eco_for_production = FND_API.G_MISS_NUM AND
5725        p_revised_item_rec.transaction_type = ENG_GLOBALS.G_OPR_UPDATE
5726     THEN
5727         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5728         THEN
5729                 Error_Handler.Add_Error_Token
5730                 (  p_Message_Name       => 'ENG_RIT_ECO_FOR_PROD_MISSING'
5731                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5732                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5733                  , p_Token_Tbl          => l_Token_Tbl
5734                  );
5735         END IF;
5736             x_return_status := FND_API.G_RET_STS_ERROR;
5737     END IF;
5738 
5739     /* Comment Out by MK Flow Routing is not supported in Current Rel
5740     IF p_revised_item_rec.mixed_model_map_flag IS NOT NULL AND
5741        p_revised_item_rec.mixed_model_map_flag <> FND_API.G_MISS_NUM AND
5742        p_revised_item_rec.mixed_model_map_flag NOT IN (1,2)
5743     THEN
5744         l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
5745         l_token_tbl(1).token_value :=  p_revised_item_rec.revised_item_name;
5746         l_token_tbl(2).token_name  := 'MODEL_MAP_FLAG';
5747         l_token_tbl(2).token_value :=  p_revised_item_rec.mixed_model_map_flag;
5748         Error_Handler.Add_Error_Token
5749         (  p_message_name       =>'BOM_RIT_MIXED_MDL_MAP_INVALID'
5750          , p_token_tbl          => l_token_tbl
5751          , p_mesg_token_tbl     => l_mesg_token_tbl
5752          , x_mesg_token_tbl     => l_mesg_token_tbl
5753         );
5754         x_return_status := FND_API.G_RET_STS_ERROR;
5755     END IF;
5756     */
5757     -- Added by MK on 08/24/2000
5758 
5759 
5760     -- Added by MK on 02/15/2001
5761     -- Validate alternate bom code
5762     IF p_revised_item_rec.alternate_bom_code IS NOT NULL AND
5763        p_revised_item_rec.alternate_bom_code <> FND_API.G_MISS_CHAR
5764     THEN
5765 
5766          FOR check_alternate IN
5767              c_Check_Alternate
5768              ( p_alt_designator  => p_revised_item_rec.alternate_bom_code,
5769                p_organization_id => p_rev_item_unexp_rec.organization_id )
5770          LOOP
5771 
5772              l_token_tbl(1).token_name := 'ALTERNATE_BOM_CODE';
5773              l_token_tbl(1).token_value :=
5774                                         p_revised_item_rec.alternate_bom_code;
5775              l_token_tbl(2).token_name := 'ORGANIZATION_CODE';
5776              l_token_tbl(2).token_value := p_revised_item_rec.organization_code;
5777 
5778              Error_Handler.Add_Error_Token
5779              (  p_Message_Name       => 'BOM_ALT_DESIGNATOR_INVALID'
5780               , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5781               , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5782               , p_token_tbl          => l_token_tbl
5783              );
5784 
5785              x_return_status := FND_API.G_RET_STS_ERROR;
5786              l_token_tbl.delete ;
5787              l_token_tbl(1).token_name := 'REVISED_ITEM_NAME';
5788              l_token_tbl(1).token_value := p_revised_item_rec.revised_item_name;
5789 
5790          END LOOP;
5791 
5792 
5793 IF Bom_Globals.Get_Debug = 'Y' THEN
5794     Error_Handler.Write_Debug('Alternate Desig Validated . . . status : '||x_return_status );
5795 END IF;
5796 
5797     END IF;
5798 
5799 --  Check if the revised item is an approved item. Unapproved items cannot be added as revised items.
5800     IF Get_Approval_Status(p_rev_item_unexp_rec.revised_item_id,
5801                            p_rev_item_unexp_rec.organization_id) <> 'A'
5802     THEN
5803         l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
5804         l_token_tbl(1).token_value := p_revised_item_rec.revised_item_name;
5805         Error_Handler.Add_Error_Token
5806         (  p_message_name       => 'ENG_REV_ITEM_UNAPPROVED'
5807          , p_token_tbl          => l_token_tbl
5808          , p_mesg_token_tbl     => l_mesg_token_tbl
5809          , x_mesg_token_tbl     => l_mesg_token_tbl
5810         );
5811         x_return_status := FND_API.G_RET_STS_ERROR;
5812     END IF;
5813 
5814     --  Done validating attributes
5815     x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
5816 
5817 
5818 EXCEPTION
5819 
5820     WHEN FND_API.G_EXC_ERROR THEN
5821         x_return_status := FND_API.G_RET_STS_ERROR;
5822         x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
5823 
5824     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5825 
5826         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5827         Error_Handler.Add_Error_Token
5828             (  p_Message_Name   => NULL
5829              , p_Message_Text   => l_Err_Text
5830              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5831              , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5832              );
5833         x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
5834     WHEN OTHERS THEN
5835 
5836         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5837 
5838         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5839         THEN
5840             l_err_text := G_PKG_NAME || ' : (Attribute Validation) ' ||
5841                           substrb(SQLERRM,1,200);
5842             Error_Handler.Add_Error_Token
5843             (  p_Message_Name   => NULL
5844              , p_Message_Text   => l_Err_Text
5845              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5846              , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5847              );
5848         END IF;
5849         x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
5850 
5851 END Check_Attributes;
5852 
5853 
5854 /*****************************************************************************
5855 * Procedure     : Entity_Delete
5856 * Parameters IN : Revised item exposed column record
5857 *                 Revised item unexposed column record
5858 * Parameters OUT: Mesg Token Table
5859 *                 Return Status
5860 * Purpose       : Entity Delete procedure will check if the given revised item
5861 *                 can be deleted without violating any business rules or
5862 *                 constraints. Revised item's cannot be deleted if there are
5863 *                 components on the bill or it revised item's bill is being
5864 *                 referenced as common by any other bills in the same org or
5865 *                 any other org.
5866 *                 (Check of revised item being implemented or cancelled is done
5867 *                  in the previous steps of the process flow)
5868 ******************************************************************************/
5869 PROCEDURE Check_Entity_Delete
5870 (  x_return_status              OUT NOCOPY VARCHAR2
5871  , x_Mesg_Token_Tbl             OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
5872  , p_revised_item_rec           IN  ENG_Eco_PUB.Revised_Item_Rec_Type
5873  , p_rev_item_unexp_rec         IN  Eng_Eco_Pub.Rev_Item_Unexposed_Rec_Type
5874 )
5875 IS
5876   l_err_text                  VARCHAR2(2000) := NULL;
5877   l_return_status       VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
5878   check_delete          NUMBER := 0;
5879   l_count1              NUMBER := 0;
5880   l_allow_rev           NUMBER := 0;
5881 
5882   CURSOR rev_comps IS
5883       SELECT 1
5884       FROM BOM_INVENTORY_COMPONENTS
5885       WHERE revised_item_sequence_id =
5886                p_rev_item_unexp_rec.revised_item_sequence_id;
5887 
5888 
5889   /******************************************************************
5890   -- Added by MK on 08/26/2000
5891   -- Enhancement for ECO Routing
5892   ******************************************************************/
5893   CURSOR rev_op_seq IS
5894   SELECT 'Rev Op Exist'
5895   FROM    SYS.DUAL
5896   WHERE EXISTS  ( SELECT NULL
5897                   FROM BOM_OPERATION_SEQUENCES
5898                   WHERE revised_item_sequence_id =
5899                        p_rev_item_unexp_rec.revised_item_sequence_id) ;
5900   -- Added by MK on 08/26/2000
5901 
5902   -- 11.5.10E
5903   -- Delete should be allowed only if the new revision doesn't appear as
5904   -- from revision for some other revised item
5905 
5906   -- Bug No: 4273087
5907   -- Checking for additional references when removing the 'New Revision'
5908   -- Bug 4946817: Fixed performance issues
5909   CURSOR allow_delete_rev IS
5910   SELECT 1
5911   FROM ENG_REVISED_ITEMS itm,
5912   ENG_REVISED_ITEMS sitm
5913   WHERE itm.REVISED_ITEM_ID = sitm.REVISED_ITEM_ID
5914   AND itm.ORGANIZATION_ID = sitm.ORGANIZATION_ID
5915   AND sitm.revised_item_sequence_id = p_rev_item_unexp_rec.revised_item_sequence_id
5916   AND itm.STATUS_TYPE not in (5, 6)
5917   AND (itm.CURRENT_ITEM_REVISION_ID = sitm.new_item_revision_id
5918        OR itm.FROM_END_ITEM_REV_ID = sitm.new_item_revision_id)
5919   UNION ALL
5920   SELECT 1
5921   FROM ENG_REVISED_ITEMS sitm  , bom_structures_b bsb
5922   WHERE sitm.revised_item_sequence_id = p_rev_item_unexp_rec.revised_item_sequence_id
5923   AND bsb.assembly_item_id = sitm.revised_item_id
5924   AND bsb.organization_id = sitm.organization_id
5925   AND EXISTS ( SELECT 1
5926                FROM BOM_COMPONENTS_B bic
5927                WHERE bic.bill_sequence_id = bsb.bill_sequence_id   and
5928                (bic.FROM_END_ITEM_REV_ID = sitm.new_item_revision_id
5929                OR bic.TO_END_ITEM_REV_ID = sitm.new_item_revision_id
5930                ))
5931   UNION ALL
5932   SELECT 1
5933   FROM eng_revised_items sitm
5934   WHERE sitm.revised_item_sequence_id = p_rev_item_unexp_rec.revised_item_sequence_id
5935   AND EXISTS ( SELECT 1
5936                FROM BOM_COMPONENTS_B bic
5937                WHERE bic.component_item_id = sitm.revised_item_id   and
5938                bic.COMPONENT_ITEM_REVISION_ID = sitm.new_item_revision_id);
5939 
5940         l_Mesg_Token_Tbl        Error_Handler.Mesg_Token_Tbl_Type;
5941         l_Token_Tbl             Error_Handler.Token_Tbl_Type;
5942 BEGIN
5943         --
5944         -- Set the revised item token name and value
5945         --
5946         l_Token_Tbl(1).Token_Name  := 'REVISED_ITEM_NAME';
5947         l_Token_Tbl(1).Token_Value := p_revised_item_rec.revised_item_name;
5948 
5949         FOR l_rev_comps IN rev_comps
5950         LOOP
5951                 --
5952                 -- if loop executes, then component exist on that bill
5953                 -- so it cannot be deleted.
5954                 --
5955                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5956                 THEN
5957                         Error_Handler.Add_Error_Token
5958                         (  p_Message_Name       => 'ENG_CANNOT_DEL_COMP_EXIST'
5959                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5960                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5961                          , p_Token_Tbl          => l_Token_Tbl
5962                          );
5963                 END IF;
5964                 l_return_status := FND_API.G_RET_STS_ERROR;
5965         END LOOP;
5966 
5967 
5968 
5969         /******************************************************************
5970         -- Added by MK on 08/26/2000
5971         -- Enhancement for ECO Routing
5972         ******************************************************************/
5973         FOR l_rev_op_seq IN rev_op_seq
5974         LOOP
5975                 --
5976                 -- if loop executes, then revised operation exist on that
5977                 -- routing so it cannot be deleted.
5978                 --
5979                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5980                 THEN
5981                         Error_Handler.Add_Error_Token
5982                         (  p_Message_Name       => 'ENG_CANNOT_DEL_OP_EXIST'
5983                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5984                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5985                          , p_Token_Tbl          => l_Token_Tbl
5986                          );
5987                 END IF;
5988                 l_return_status := FND_API.G_RET_STS_ERROR;
5989         END LOOP;
5990         -- Added by MK on 08/26/2000
5991 
5992 
5993 
5994         /*********************************************************************
5995         --
5996         -- Check if the revised item's bill is being referenced as common
5997         --
5998         **********************************************************************/
5999         check_delete := Check_Reference_Common
6000                   ( p_change_notice     => p_revised_item_rec.eco_name
6001                   , p_bill_sequence_id  => p_rev_item_unexp_rec.bill_sequence_id
6002                   );
6003 
6004         IF check_delete <> 0
6005         THEN
6006                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
6007                 THEN
6008                         Error_Handler.Add_Error_Token
6009                         (  p_Message_Name       => 'ENG_CANNOT_DEL_COMMON_EXIST'
6010                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6011                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6012                          , p_Token_Tbl          => l_Token_Tbl
6013                          );
6014                 END IF;
6015                 l_return_status := FND_API.G_RET_STS_ERROR;
6016         END IF;
6017 
6018         /*********************************************************************
6019         -- Added by MK on 08/26/2000
6020         -- Check if the revised item's routing is being referenced as common
6021         **********************************************************************/
6022         check_delete := 0 ;
6023         check_delete :=  Check_Reference_Rtg_Common
6024                   ( p_change_notice     => p_revised_item_rec.eco_name
6025                   , p_routing_sequence_id  => p_rev_item_unexp_rec.routing_sequence_id
6026                   );
6027 
6028         IF check_delete <> 0
6029         THEN
6030                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
6031                 THEN
6032                         Error_Handler.Add_Error_Token
6033                         (  p_Message_Name       => 'ENG_CANNOT_DEL_RTG_COMMON_EXIST'
6034                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6035                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6036                          , p_Token_Tbl          => l_Token_Tbl
6037                          );
6038                 END IF;
6039                 l_return_status := FND_API.G_RET_STS_ERROR;
6040         END IF;
6041         -- Added by MK on 08/26/2000
6042 
6043         -- 11.5.10E
6044         -- Validation for new_revision while deleting rev items
6045         OPEN allow_delete_rev;
6046         FETCH allow_delete_rev into l_allow_rev;
6047         IF l_allow_rev = 1
6048         THEN
6049           IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
6050           THEN
6051             Error_Handler.Add_Error_Token
6052               (  p_Message_Name       => 'ENG_CANNOT_DEL_REVISION_IN_USE'
6053                , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6054                , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6055                , p_Token_Tbl          => l_Token_Tbl
6056               );
6057           END IF;
6058           l_return_status := FND_API.G_RET_STS_ERROR;
6059         END IF;
6060         CLOSE allow_delete_rev;
6061         -- Done with the validations
6062         x_return_status := l_return_status;
6063         x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
6064 
6065 EXCEPTION
6066 
6067     WHEN FND_API.G_EXC_ERROR THEN
6068 
6069         x_return_status := FND_API.G_RET_STS_ERROR;
6070 
6071     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6072 
6073         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6074 
6075     WHEN OTHERS THEN
6076 
6077         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6078 
6079         IF allow_delete_rev%ISOPEN
6080         THEN
6081           CLOSE allow_delete_rev;
6082         END IF;
6083 
6084         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6085         THEN
6086             l_err_text := G_PKG_NAME || ' : (Entity Delete Validation) ' ||
6087                           substrb(SQLERRM,1,200);
6088             Error_Handler.Add_Error_Token
6089             (  p_Message_Name   => NULL
6090              , p_Message_Text   => l_Err_Text
6091              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
6092              , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
6093              );
6094         END IF;
6095 
6096 END Check_Entity_Delete;
6097 
6098 /*****************************************************************************
6099 * Procedure     : Check_Existence
6100 * Parameters IN : Revised Item exposed column record
6101 *                 Revised Item unexposed column record
6102 * Parameters OUT: Old Revised Item exposed column record
6103 *                 Old Revised Item unexposed column record
6104 *                 Mesg Token Table
6105 *                 Return Status
6106 * Purpose       : Check_Existence will poerform a query using the primary key
6107 *                 information and will return a success if the operation is
6108 *                 CREATE and the record EXISTS or will return an
6109 *                 error if the operation is UPDATE and the record DOES NOT
6110 *                 EXIST.
6111 *                 In case of UPDATE if the record exists then the procedure
6112 *                 will return the old record in the old entity parameters
6113 *                 with a success status.
6114 ****************************************************************************/
6115 
6116 PROCEDURE Check_Existence
6117 (  p_revised_item_rec       IN  Eng_Eco_Pub.Revised_Item_Rec_Type
6118  , p_rev_item_unexp_rec     IN  Eng_Eco_Pub.Rev_Item_Unexposed_Rec_Type
6119  , x_old_revised_item_rec   IN OUT NOCOPY Eng_Eco_Pub.Revised_Item_Rec_Type
6120  , x_old_rev_item_unexp_rec IN OUT NOCOPY Eng_Eco_Pub.Rev_Item_Unexposed_Rec_Type
6121  , x_Mesg_Token_Tbl         OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
6122  , x_Return_Status          OUT NOCOPY VARCHAR2
6123  , x_disable_revision       OUT NOCOPY NUMBER --Bug no:3034642
6124 )
6125 IS
6126         l_token_tbl      Error_Handler.Token_Tbl_Type;
6127         l_Mesg_Token_Tbl Error_Handler.Mesg_Token_Tbl_Type;
6128         l_return_status  VARCHAR2(1);
6129 	--Start of changes Bug no:3034642
6130         l_profile_exist     BOOLEAN;
6131         l_profile_val       VARCHAR2(30);
6132         l_phase_change_code VARCHAR2(30)       :='REVISE';
6133         l_catalog_category_id MTL_SYSTEM_ITEMS_B.ITEM_CATALOG_GROUP_ID%TYPE;
6134         l_Lifecycle_Id        NUMBER;
6135         l_policy_code         VARCHAR2(100);
6136         l_Old_Phase_Id        mtl_item_revisions_b.current_phase_id%TYPE;
6137         l_Error_Code          NUMBER;
6138         l_Msg_Data            VARCHAR2(2000);
6139         l_api_version         CONSTANT NUMBER           := 1.0;
6140         l_project_id          NUMBER :=NULL;
6141         l_msg_count           NUMBER;
6142 	l_package_name   varchar2(100) := 'EGO_LIFECYCLE_USER_PUB.get_policy_for_phase_change';
6143 
6144 	CURSOR c_get_default_life(inv_id NUMBER,cp_org_id NUMBER)
6145         IS
6146           select current_phase_id, LIFECYCLE_ID  ,ITEM_CATALOG_GROUP_ID  from  mtl_system_items
6147           where INVENTORY_ITEM_ID =inv_id and organization_id =cp_org_id;
6148 
6149 --End  of changes Bug no:3034642
6150 BEGIN
6151         l_Token_Tbl(1).Token_Name  := 'REVISED_ITEM_NAME';
6152         l_Token_Tbl(1).Token_Value := p_revised_item_rec.revised_item_name;
6153         l_token_tbl(2).token_name  := 'ECO_NAME';
6154         l_token_tbl(2).token_value := p_revised_item_rec.eco_name;
6155 
6156         ENG_Revised_Item_Util.Query_Row
6157         ( p_revised_item_id     => p_rev_item_unexp_rec.revised_item_id
6158         , p_organization_id     => p_rev_item_unexp_rec.organization_id
6159         , p_change_notice       => p_revised_item_rec.eco_name
6160         , p_new_item_revision   => p_revised_item_rec.new_revised_item_revision
6161         , p_new_routing_revision => p_revised_item_rec.new_routing_revision
6162         , p_start_eff_date      => p_revised_item_rec.start_effective_date
6163         , p_from_end_item_number => p_revised_item_rec.from_end_item_unit_number
6164         , p_alternate_designator => p_revised_item_rec.alternate_bom_code  -- To Fix 2869146
6165         , x_revised_item_rec    => x_old_revised_item_rec
6166         , x_rev_item_unexp_rec  => x_old_rev_item_unexp_rec
6167         , x_Return_status       => l_return_status
6168         );
6169         IF l_return_status = Eng_Globals.G_RECORD_FOUND AND
6170            p_revised_item_rec.transaction_type = Eng_Globals.G_OPR_CREATE
6171         THEN
6172                 Error_Handler.Add_Error_Token
6173                 (  x_Mesg_token_tbl => l_Mesg_Token_Tbl
6174                  , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
6175                  , p_message_name  => 'ENG_REV_ITEM_ALREADY_EXISTS'
6176                  , p_token_tbl     => l_token_tbl
6177                  );
6178                  l_return_status := FND_API.G_RET_STS_ERROR;
6179         ELSIF l_return_status = Eng_Globals.G_RECORD_NOT_FOUND AND
6180               p_revised_item_rec.transaction_type IN
6181                 (Eng_Globals.G_OPR_UPDATE, Eng_Globals.G_OPR_DELETE)
6182         THEN
6183                 Error_Handler.Add_Error_Token
6184                 (  x_Mesg_token_tbl => l_Mesg_Token_Tbl
6185                  , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
6186                  , p_message_name  => 'ENG_REV_ITEM_DOESNOT_EXIST'
6187                  , p_token_tbl     => l_token_tbl
6188                  );
6189                  l_return_status := FND_API.G_RET_STS_ERROR;
6190         ELSIF l_Return_status = FND_API.G_RET_STS_UNEXP_ERROR
6191         THEN
6192                 Error_Handler.Add_Error_Token
6193                 (  x_Mesg_token_tbl     => l_Mesg_Token_Tbl
6194                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6195                  , p_message_name       => NULL
6196                  , p_message_text       =>
6197                    'Unexpected error while existence verification of ' ||
6198                    'Revised Item ' || p_revised_item_rec.revised_item_name
6199                  , p_token_tbl          => l_token_tbl
6200                  );
6201         ELSE
6202                  l_return_status := FND_API.G_RET_STS_SUCCESS;
6203         END IF;
6204 	 --Start of changes Bug no:3034642
6205 
6206 	x_disable_revision :=2;
6207         l_profile_exist := FND_PROFILE.DEFINED ( 'EGO_ITEM_RESTRICT_INV_ACTIONS' );
6208         if (l_profile_exist = TRUE) then
6209             FND_PROFILE.GET ( 'EGO_ITEM_RESTRICT_INV_ACTIONS', l_profile_val );
6210             if ( l_profile_val = '2') then
6211                FOR sc IN c_get_default_life(p_rev_item_unexp_rec.Revised_Item_Id ,  p_rev_item_unexp_rec.Organization_Id)
6212                 LOOP
6213                   l_Old_Phase_Id := sc.current_phase_id;
6214                   l_Lifecycle_Id     := sc.LIFECYCLE_ID;
6215                   l_catalog_category_id :=sc.ITEM_CATALOG_GROUP_ID;
6216                END LOOP;
6217               execute immediate 'begin ' || l_package_name || '(:1,:2, :3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13); end;'
6218                using in l_api_version ,in l_project_id, in p_rev_item_unexp_rec.Revised_Item_Id , in p_rev_item_unexp_rec.Organization_Id,in l_Old_Phase_Id,in l_Old_Phase_Id,in l_phase_change_code ,in l_Lifecycle_Id    ,
6219                out l_Policy_Code,out l_Return_Status,out l_Error_Code,out l_Msg_Count,out l_Msg_Data ;
6220               if  l_Policy_Code <> 'ALLOWED' THEN
6221 	           x_disable_revision := 1; --not allowed thus revison field should be disabled
6222       	      end if;
6223             end if; --end of if l_profile_val = '1'
6224             if UPPER(p_revised_item_rec.Transaction_Type) =UPPER('Create')
6225 	       and p_revised_item_rec.New_Revised_Item_Revision is not null
6226 	       and x_disable_revision = 1
6227             then
6228                	  error_handler.add_error_token (
6229                         p_message_name=> 'ENG_ITEMREV_NOT_ALLOW',
6230                         p_mesg_token_tbl=> l_mesg_token_tbl,
6231                         x_mesg_token_tbl=> l_mesg_token_tbl,
6232                         p_token_tbl=> l_token_tbl
6233                      );
6234                      l_return_status := fnd_api.g_ret_sts_error;
6235             end if;
6236         end if;   --end of if profile value exists
6237 
6238   --end of changes Bug no:3034642
6239 
6240         x_return_status := l_return_status;
6241         x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
6242 
6243 END Check_Existence;
6244 
6245 /*****************************************************************************
6246 * Procedure     : Check_Access_Scheduled
6247 * Parameters IN : Revised Item exposed column record
6248 *                 Revised Item unexposed column record
6249 * Parameters OUT: Mesg Token Table
6250 *                 Return Status
6251 * Purpose       : Check_Access_Scheduled will check the validity of the revised item
6252 *                 record when the CO is in scheduled status
6253 *                 Added for Enhancement 5470261
6254 
6255 ****************************************************************************/
6256 PROCEDURE Check_Access_Scheduled
6257 (  p_revised_item_rec           IN  ENG_Eco_PUB.Revised_Item_Rec_Type
6258  , p_rev_item_unexp_rec         IN  Eng_Eco_Pub.Rev_Item_Unexposed_Rec_Type
6259 
6260  , x_Mesg_Token_Tbl             OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
6261  , x_Return_Status              OUT NOCOPY VARCHAR2
6262 )
6263 IS
6264   l_Mesg_Token_Tbl Error_Handler.Mesg_Token_Tbl_Type;
6265   l_return_status       VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
6266   l_token_tbl      Error_Handler.Token_Tbl_Type;
6267 
6268 BEGIN
6269 
6270 
6271   l_Token_Tbl(1).token_name  := 'REVISED_ITEM_NAME';
6272   l_token_tbl(1).token_value := p_revised_item_rec.revised_item_name;
6273   IF(
6274      p_rev_item_unexp_rec.implementation_date IS NOT NULL
6275      OR p_rev_item_unexp_rec.cancellation_date IS NOT NULL
6276      OR p_revised_item_rec.cancel_comments IS NOT NULL
6277      OR p_revised_item_rec.disposition_type IS NOT NULL
6278      OR p_revised_item_rec.updated_revised_item_revision IS NOT NULL
6279      OR p_revised_item_rec.earliest_effective_date IS NOT NULL
6280      OR p_revised_item_rec.attribute_category IS NOT NULL
6281      OR p_revised_item_rec.attribute2 IS NOT NULL
6282      OR p_revised_item_rec.attribute3 IS NOT NULL
6283      OR p_revised_item_rec.attribute4  IS NOT NULL
6284      OR p_revised_item_rec.attribute5 IS NOT NULL
6285      OR p_revised_item_rec.attribute7  IS NOT NULL
6286      OR p_revised_item_rec.attribute8 IS NOT NULL
6287      OR p_revised_item_rec.attribute9 IS NOT NULL
6288      OR p_revised_item_rec.attribute11 IS NOT NULL
6289      OR p_revised_item_rec.attribute12 IS NOT NULL
6290      OR p_revised_item_rec.attribute13 IS NOT NULL
6291      OR p_revised_item_rec.attribute14 IS NOT NULL
6292      OR p_revised_item_rec.attribute15 IS NOT NULL
6293      OR p_revised_item_rec.status_type IS NOT NULL
6294      --p_revised_item_rec.new_effective_date --scheduled date
6295      --p_rev_item_unexp_rec.bill_sequence_id IS NOT NULL
6296      OR p_revised_item_rec.mrp_active IS NOT NULL
6297      OR p_revised_item_rec.update_wip IS NOT NULL
6298      OR p_rev_item_unexp_rec.use_up IS NOT NULL
6299      OR p_rev_item_unexp_rec.use_up_item_id IS NOT NULL
6300      OR p_rev_item_unexp_rec.revised_item_sequence_id IS NOT NULL
6301      OR p_revised_item_rec.use_up_plan_name IS NOT NULL
6302      OR p_revised_item_rec.change_description IS NOT NULL
6303      OR p_rev_item_unexp_rec.auto_implement_date IS NOT NULL
6304      OR p_revised_item_rec.from_end_item_unit_number IS NOT NULL
6305      OR p_revised_item_rec.attribute1 IS NOT NULL
6306      OR p_revised_item_rec.attribute6 IS NOT NULL
6307      OR p_revised_item_rec.attribute10 IS NOT NULL
6308      OR p_revised_item_rec.original_system_reference IS NOT NULL
6309      OR p_rev_item_unexp_rec.from_wip_entity_id IS NOT NULL
6310      OR p_rev_item_unexp_rec.to_wip_entity_id IS NOT NULL
6311      OR p_revised_item_rec.from_cumulative_quantity IS NOT NULL
6312      OR p_revised_item_rec.lot_number IS NOT NULL
6313      OR p_rev_item_unexp_rec.cfm_routing_flag IS NOT NULL
6314      OR p_revised_item_rec.completion_subinventory IS NOT NULL
6315      OR p_rev_item_unexp_rec.completion_locator_id IS NOT NULL
6316      OR p_revised_item_rec.priority IS NOT NULL
6317      OR p_revised_item_rec.ctp_flag IS NOT NULL
6318      OR p_rev_item_unexp_rec.routing_sequence_id IS NOT NULL
6319      OR p_revised_item_rec.updated_routing_revision IS NOT NULL
6320      OR p_revised_item_rec.routing_comment IS NOT NULL
6321      OR p_revised_item_rec.eco_for_production IS NOT NULL
6322      --p_rev_item_unexp_rec.change_id IS NOT NULL
6323      OR p_revised_item_rec.Transfer_Or_Copy IS NOT NULL
6324      OR p_revised_item_rec.Transfer_OR_Copy_Item IS NOT NULL
6325      OR p_revised_item_rec.Transfer_OR_Copy_Bill IS NOT NULL
6326      OR p_revised_item_rec.Transfer_OR_Copy_Routing IS NOT NULL
6327      OR p_revised_item_rec.Copy_To_Item IS NOT NULL
6328      OR p_revised_item_rec.Copy_To_Item_Desc IS NOT NULL
6329      OR p_revised_item_rec.selection_option IS NOT NULL
6330      OR p_revised_item_rec.selection_date IS NOT NULL
6331      OR p_revised_item_rec.selection_unit_number IS NOT NULL
6332      OR p_rev_item_unexp_rec.status_code IS NOT NULL
6333      OR p_revised_item_rec.status_type IS NOT NULL
6334 
6335     ) THEN
6336 	-- The user has given values for some other colums
6337 	-- Thus, it is assumed that the user is trying to update these columns
6338 	-- Since these values cannot be updated when the CO is in scheduled status
6339 	-- Error is thrown
6340          Error_Handler.Add_Error_Token
6341                 (  p_Message_Name       => 'ENG_RIT_NO_UPDATE_SCHEDULED'
6342                  , p_Mesg_Token_Tbl     => l_mesg_token_tbl
6343                  , x_Mesg_Token_Tbl     => l_mesg_token_tbl
6344                  , p_Token_Tbl          => l_token_tbl
6345                 );
6346 
6347                 l_return_status := FND_API.G_RET_STS_ERROR;
6348       ELSIF  (p_revised_item_rec.new_effective_date IS NULL) THEN
6349 	 -- The change is in scheduled status and the user has not given a
6350 	 -- value for the new scheduled date.
6351 	 Error_Handler.Add_Error_Token
6352                 (  p_Message_Name       => 'ENG_RIT_SCHEDULED_DATE_NULL'
6353                  , p_Mesg_Token_Tbl     => l_mesg_token_tbl
6354                  , x_Mesg_Token_Tbl     => l_mesg_token_tbl
6355                  , p_Token_Tbl          => l_token_tbl
6356                 );
6357 
6358                 l_return_status := FND_API.G_RET_STS_ERROR;
6359        ELSIF (p_revised_item_rec.new_effective_date < SYSDATE) THEN
6360 	  -- While rescheduling the new effective date shall not be less than
6361 	  -- the current date...
6362 	 Error_Handler.Add_Error_Token
6363                 (  p_Message_Name       => 'ENG_RIT_EFF_DATE_INVALID'
6364                  , p_Mesg_Token_Tbl     => l_mesg_token_tbl
6365                  , x_Mesg_Token_Tbl     => l_mesg_token_tbl
6366                  , p_Token_Tbl          => l_token_tbl
6367                 );
6368 
6369                 l_return_status := FND_API.G_RET_STS_ERROR;
6370     end if;
6371     x_return_status := l_return_status;
6372     x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
6373 
6374 END Check_Access_Scheduled;
6375 
6376 
6377 PROCEDURE Check_Access
6378 (  p_change_notice              IN  VARCHAR2
6379  , p_organization_id            IN  NUMBER
6380  , p_revised_item_id            IN  NUMBER
6381  , p_new_item_revision          IN  VARCHAR2
6382  , p_effectivity_date           IN  DATE
6383  , p_new_routing_revsion        IN  VARCHAR2 -- Added by MK on 11/02/00
6384  , p_from_end_item_number       IN  VARCHAR2 -- Added by MK on 11/02/00
6385  , p_revised_item_name          IN  VARCHAR2
6386  , p_entity_processed           IN  VARCHAR2 := NULL
6387  , p_operation_seq_num          IN  NUMBER   := NULL
6388  , p_routing_sequence_id        IN  NUMBER   := NULL
6389  , p_operation_type             IN  NUMBER   := NULL
6390  , p_alternate_bom_code         IN  VARCHAR2   := NULL
6391  , p_Mesg_Token_Tbl             IN  Error_Handler.Mesg_Token_Tbl_Type :=
6392                                         Error_Handler.G_MISS_MESG_TOKEN_TBL
6393  , x_Mesg_Token_Tbl             OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
6394  , x_Return_Status              OUT NOCOPY VARCHAR2
6395  , p_check_scheduled_status IN BOOLEAN DEFAULT TRUE  -- Added for bug 5756870
6396 )
6397 IS
6398         l_Mesg_Token_Tbl        Error_Handler.Mesg_Token_Tbl_Type :=
6399                                 p_Mesg_Token_Tbl;
6400         l_Token_Tbl             Error_Handler.Token_Tbl_Type;
6401         l_Return_Status         VARCHAR2(1);
6402         l_is_item_unit_controlled BOOLEAN := FALSE;
6403 
6404         CURSOR c_CheckRevisedItem IS
6405         SELECT status_type
6406           FROM eng_revised_items
6407          WHERE revised_item_id   = p_revised_item_id
6408 	   AND organization_id = p_organization_id --* Added for Bug 5174223
6409            AND change_notice     = p_change_notice
6410            AND NVL(from_end_item_unit_number, 'NONE')
6411                       = NVL(p_from_end_item_number, 'NONE')
6412            AND NVL(new_routing_revision,'NULL')
6413                       = NVL(p_new_routing_revsion,'NULL')
6414            AND NVL(new_item_revision, 'NULL') = NVL(p_new_item_revision, 'NULL')
6415            AND trunc(scheduled_date)    = trunc(p_effectivity_date);
6416 
6417         CURSOR c_RevItemType IS
6418         SELECT bom_item_type,eng_item_flag
6419           FROM mtl_system_items
6420          WHERE inventory_item_id = p_revised_item_id
6421            AND organization_id   = p_organization_id;
6422 
6423         -- Moved from BOM_Validate_Op_Seq.Check_Access by MK on 12/04
6424         CURSOR c_CheckCancelled IS
6425            SELECT 1
6426            FROM SYS.DUAL
6427            WHERE NOT EXISTS
6428                         ( SELECT NULL
6429                           FROM   BOM_OPERATION_SEQUENCES
6430                           WHERE  NVL(operation_type, 1) = NVL(p_operation_type, 1)
6431                           AND    effectivity_date       = p_effectivity_date
6432                           AND    routing_sequence_id    = p_routing_sequence_id
6433                           AND    operation_seq_num      = p_operation_seq_num
6434                         )
6435             AND  EXISTS
6436                         ( SELECT NULL
6437                           FROM ENG_REVISED_OPERATIONS
6438                           WHERE  NVL(operation_type, 1) = NVL(p_operation_type, 1)
6439                           AND    TRUNC(effectivity_date)     = TRUNC(p_effectivity_date)
6440                           AND    routing_sequence_id  = p_routing_sequence_id
6441                           AND    operation_seq_num    = p_operation_seq_num
6442                           );
6443         -- Bug 4210718
6444         l_cp_not_allowed        NUMBER;
6445         l_structure_type_id     NUMBER;
6446         -- Bug 4276451
6447         l_status_type_name      fnd_lookup_values_vl.meaning%TYPE;
6448 	l_status_valid		BOOLEAN;
6449 
6450 
6451 BEGIN
6452         l_return_status := FND_API.G_RET_STS_SUCCESS;
6453 
6454         l_Token_Tbl(1).token_name  := 'REVISED_ITEM_NAME';
6455         l_token_tbl(1).token_value := p_revised_item_name;
6456 
6457         l_is_item_unit_controlled := BOM_Globals.Get_Unit_Controlled_Item;
6458 
6459         --
6460         -- The driving procedure must make sure that the ECO
6461         -- Check_Access has been called and has returned with a success.
6462         --
6463         /*******************************
6464         Eng_Validate_ECO.Check_Access
6465         (  p_change_notice      => p_change_notice
6466          , p_organization_id    => p_organization_id
6467          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6468          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6469          , x_Return_Status      => l_return_status
6470         );
6471         ***********************************/
6472 
6473 	  ---Check if user has access to Engineering item or not bug:4942705
6474 	  IF (NVL(fnd_profile.value('ENG:ENG_ITEM_ECN_ACCESS'), 1) = 2)
6475           THEN
6476 	    FOR revised_item IN c_RevItemType
6477                 LOOP
6478                         IF revised_item.eng_item_flag = 'Y' THEN
6479                             Error_Handler.Add_Error_Token
6480                                   (  p_Message_Name       => 'ENG_ITEM_ACCESS_DENIED'
6481                                    , p_Mesg_Token_Tbl     => l_mesg_token_tbl
6482                                    , x_Mesg_Token_Tbl     => l_mesg_token_tbl
6483                                    , p_Token_Tbl          => l_token_tbl
6484                                   );
6485                              l_return_status := FND_API.G_RET_STS_ERROR;
6486                          END IF;
6487                  END LOOP;
6488 	END IF;
6489 
6490         --
6491         -- Check revised item is not implemented or Cancelled
6492         --
6493         IF BOM_Globals.Is_RItem_Cancl IS NULL AND
6494            BOM_Globals.Is_RItem_Impl  IS NULL
6495         THEN
6496 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Checking for revised item impl /canceled . . .'); END IF;
6497 
6498                 FOR revised_item IN c_CheckRevisedItem
6499                 LOOP
6500                         IF revised_item.status_type = 5 THEN
6501                                 BOM_Globals.Set_RItem_Cancl
6502                                 (p_ritem_cancl  => TRUE);
6503                         ELSIF revised_item.status_type = 6 THEN
6504                                 BOM_Globals.Set_RItem_Impl
6505                                 (p_ritem_impl   => TRUE);
6506                         ELSE
6507                                 BOM_Globals.Set_RItem_Cancl
6508                                 (p_ritem_cancl  => FALSE);
6509                                 BOM_Globals.Set_RItem_Impl
6510                                 (p_ritem_impl   => FALSE);
6511                         END IF;
6512                         -- Bug 4276451
6513                         -- Check if the revised item is updateable for PLM ECOs
6514                         IF ENG_Globals.Get_PLM_Or_ERP_Change(p_change_notice, p_organization_id) = 'PLM'
6515                            AND ENG_GLOBALS.G_ENG_LAUNCH_IMPORT <> 2 -- should not be checked for propagation
6516                         THEN
6517                             l_status_valid := TRUE;
6518 			    IF revised_item.status_type NOT in( 1, 4) THEN
6519 				l_status_valid := FALSE;
6520 			    ELSIF ((revised_item.status_type = 4) AND (p_check_scheduled_status = TRUE)) THEN
6521 				l_status_valid := FALSE;
6522 			    END IF;
6523 
6524 			    IF (l_status_valid = FALSE)
6525                             THEN
6526                                 BEGIN
6527                                     SELECT meaning
6528                                     INTO l_status_type_name
6529                                     FROM fnd_lookup_values_vl
6530                                     WHERE lookup_type='ECG_ECN_STATUS'
6531                                     AND lookup_code = revised_item.status_type;
6532                                     l_Token_Tbl(2).token_name  := 'STATUS_TYPE_NAME';
6533                                     l_token_tbl(2).token_value := l_status_type_name;
6534                                 EXCEPTION
6535                                 WHEN NO_DATA_FOUND THEN
6536                                     l_status_type_name := NULL;
6537                                 END;
6538                                 Error_Handler.Add_Error_Token
6539                                   (  p_Message_Name       => 'ENG_RIT_PLM_NO_ACCESS_STATUS'
6540                                    , p_Mesg_Token_Tbl     => l_mesg_token_tbl
6541                                    , x_Mesg_Token_Tbl     => l_mesg_token_tbl
6542                                    , p_Token_Tbl          => l_token_tbl
6543                                   );
6544 
6545                                 l_return_status := FND_API.G_RET_STS_ERROR;
6546                             END IF;
6547                         END IF;
6548                         -- End fix for Bug 4276451
6549                 END LOOP;
6550         END IF;
6551 
6552         IF NVL(BOM_Globals.Is_RItem_Impl, FALSE) = TRUE
6553         THEN
6554                 Error_Handler.Add_Error_Token
6555                 (  p_Message_Name       => 'ENG_RIT_IMPLEMENTED'
6556                  , p_Mesg_Token_Tbl     => l_mesg_token_tbl
6557                  , x_Mesg_Token_Tbl     => l_mesg_token_tbl
6558                  , p_Token_Tbl          => l_token_tbl
6559                 );
6560 
6561                 l_return_status := FND_API.G_RET_STS_ERROR;
6562         ELSIF NVL(BOM_Globals.Is_RItem_Cancl, FALSE) = TRUE
6563         THEN
6564                 Error_Handler.Add_Error_Token
6565                 (  p_Message_Name       => 'ENG_RIT_CANCELLED'
6566                  , p_Mesg_Token_Tbl     => l_mesg_token_tbl
6567                  , x_Mesg_Token_Tbl     => l_mesg_token_tbl
6568                  , p_Token_Tbl          => l_token_tbl
6569                 );
6570                 l_return_status := FND_API.G_RET_STS_ERROR;
6571         END IF;
6572 
6573 
6574 
6575         --
6576         -- Check that the user has access to the BOM Item Type
6577         -- of the revised item
6578         --
6579         IF BOM_Globals.Get_STD_Item_Access IS NULL AND
6580            BOM_Globals.Get_PLN_Item_Access IS NULL AND
6581            BOM_Globals.Get_MDL_Item_Access IS NULL
6582         THEN
6583 
6584                 --
6585                 -- Get respective profile values
6586                 --
6587                 IF NVL(fnd_profile.value('ENG:STANDARD_ITEM_ECN_ACCESS'), 1) = 1
6588                 THEN
6589                         BOM_Globals.Set_STD_Item_Access
6590                         ( p_std_item_access     => 4);
6591                 ELSE
6592 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('no access to standard items'); END IF;
6593                         BOM_Globals.Set_STD_Item_Access
6594                         (p_std_item_access      => NULL);
6595                 END IF;
6596 
6597                 IF fnd_profile.value('ENG:MODEL_ITEM_ECN_ACCESS') = '1'
6598                 THEN
6599                         BOM_Globals.Set_MDL_Item_Access
6600                         ( p_mdl_item_access     => 1);
6601                         BOM_Globals.Set_OC_Item_Access
6602                         ( p_oc_item_access      => 2);
6603                 ELSE
6604                         BOM_Globals.Set_MDL_Item_Access
6605                         ( p_mdl_item_access     => NULL);
6606                         BOM_Globals.Set_OC_Item_Access
6607                         ( p_oc_item_access      => NULL);
6608                 END IF;
6609 
6610                 IF fnd_profile.value('ENG:PLANNING_ITEM_ECN_ACCESS') = '1'
6611                 THEN
6612                         BOM_Globals.Set_PLN_Item_Access
6613                         ( p_pln_item_access     => 3);
6614                 ELSE
6615                         BOM_Globals.Set_PLN_Item_Access
6616                         ( p_pln_item_access     => NULL);
6617                 END IF;
6618         END IF;
6619 
6620         FOR RevItem IN  c_RevItemType
6621         LOOP
6622                 IF RevItem.Bom_Item_Type = 5
6623                 THEN
6624                         Error_Handler.Add_Error_Token
6625                         (  p_Message_Name       => 'ENG_REV_ITEM_PROD_FAMILY'
6626                          , p_Mesg_Token_Tbl     => l_mesg_token_tbl
6627                          , x_Mesg_Token_Tbl     => l_mesg_token_tbl
6628                          , p_Token_Tbl          => l_token_tbl
6629                         );
6630                         l_return_status := FND_API.G_RET_STS_ERROR;
6631                 ELSIF RevItem.Bom_Item_Type NOT IN
6632                       ( NVL(BOM_Globals.Get_STD_Item_Access, 0),
6633                         NVL(BOM_Globals.Get_PLN_Item_Access, 0),
6634                         NVL(BOM_Globals.Get_OC_Item_Access, 0) ,
6635                         NVL(BOM_Globals.Get_MDL_Item_Access, 0)
6636                        )
6637                 THEN
6638                         l_Token_Tbl(2).Token_Name := 'BOM_ITEM_TYPE';
6639                         l_Token_Tbl(2).Translate  := TRUE;
6640                         IF RevItem.Bom_Item_Type = 1
6641                         THEN
6642                                 l_Token_Tbl(2).Token_Value := 'ENG_MODEL';
6643                         ELSIF RevItem.Bom_Item_Type = 2
6644                         THEN
6645                                 l_Token_Tbl(2).Token_Value:='ENG_OPTION_CLASS';
6646                         ELSIF RevItem.Bom_Item_Type = 3
6647                         THEN
6648                                 l_Token_Tbl(2).Token_Value := 'ENG_PLANNING';
6649                         ELSIF RevItem.Bom_Item_Type = 4
6650                         THEN
6651                                 l_Token_Tbl(2).Token_Value := 'ENG_STANDARD';
6652                         END IF;
6653 
6654                         Error_Handler.Add_Error_Token
6655                         (  p_Message_Name       => 'ENG_REV_ITEM_ACCESS_DENIED'
6656                          , p_Mesg_Token_Tbl     => l_mesg_token_tbl
6657                          , x_Mesg_Token_Tbl     => l_mesg_token_tbl
6658                          , p_Token_Tbl          => l_token_tbl
6659                         );
6660                         l_return_status := FND_API.G_RET_STS_ERROR;
6661 
6662                 END IF;
6663         END LOOP;
6664 
6665         /*********************************************************************
6666          -- Added by AS on 07/06/99
6667          -- Checks that unit effective items are allowed only if the profile
6668          -- value allows them (profile value stored in system_information)
6669         *********************************************************************/
6670 
6671         IF NOT BOM_Globals.Get_Unit_Effectivity AND
6672            l_is_item_unit_controlled
6673         THEN
6674                 Error_Handler.Add_Error_Token
6675                 ( p_Message_Name   => 'ENG_REV_ITEM_UNIT_CONTROL'
6676                 , p_Mesg_Token_Tbl => l_mesg_token_tbl
6677                 , x_Mesg_Token_Tbl => l_mesg_token_tbl
6678                 , p_Token_Tbl      => l_token_tbl
6679                 );
6680                 l_return_status := FND_API.G_RET_STS_ERROR;
6681         END IF;
6682 
6683 
6684 
6685         /**************************************************************
6686         -- Added by MK on 11/01/2000
6687         -- If bill sequence id is null(Trans Type : CREATE) and this revised
6688         --  item does not have primary bill, verify that parent revised
6689         -- item does not have routing sequence id which has alternate code.
6690         -- (Verify this eco is not only for alternate routing)
6691         --
6692         -- Moved to Engineering space to resolve ECO dependency
6693         -- by MK on 12/03/00
6694         **************************************************************/
6695         IF p_entity_processed = 'RC'
6696         AND Not Check_RevItem_BillAlternate
6697                                     (  p_revised_item_id   =>  p_revised_item_id
6698                                      , p_organization_id   =>  p_organization_id
6699                                      , p_change_notice     =>  p_change_notice
6700                                      , p_new_item_revision =>  p_new_item_revision
6701                                      , p_new_routing_revsion => p_new_routing_revsion
6702                                      , p_effective_date    =>  p_effectivity_date
6703                                      , p_from_end_item_number => p_from_end_item_number
6704                                      )
6705 
6706         THEN
6707 
6708                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
6709                 THEN
6710                         l_token_tbl.delete;
6711                         l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
6712                         l_token_tbl(1).token_value := p_revised_item_name ;
6713 
6714                         Error_Handler.Add_Error_Token
6715                         (  p_Message_Name       => 'ENG_CANNOT_ADD_ALTERNATE'
6716                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6717                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6718                          , p_Token_Tbl          => l_Token_Tbl
6719                          );
6720 
6721                 END IF;
6722                 l_return_status := FND_API.G_RET_STS_ERROR;
6723 
6724 
6725 
6726         /**************************************************************
6727         -- Added by MK on 11/01/2000
6728         -- If routing sequence id is null(Trans Type : CREATE) and this
6729         -- revised item does not have primary routing, verify that parent revised
6730         -- item does not have bill sequence id which has alternate code.
6731         -- (Verify this eco is not only for alternate bill )
6732         --
6733         **************************************************************/
6734         ELSIF p_entity_processed = 'ROP'
6735         AND Not Check_RevItem_RtgAlternate
6736                                     (  p_revised_item_id   =>  p_revised_item_id
6737                                      , p_organization_id   =>  p_organization_id
6738                                      , p_change_notice     =>  p_change_notice
6739                                      , p_new_item_revision =>  p_new_item_revision
6740                                      , p_new_routing_revsion => p_new_routing_revsion
6741                                      , p_effective_date    =>  p_effectivity_date
6742                                      , p_from_end_item_number => p_from_end_item_number
6743                                      )
6744 
6745         THEN
6746 
6747                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
6748                 THEN
6749                         l_token_tbl.delete;
6750                         l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
6751                         l_token_tbl(1).token_value := p_revised_item_name ;
6752 
6753                         Error_Handler.Add_Error_Token
6754                         (  p_Message_Name       => 'ENG_RIT_RTG_CANT_ADD_ALTERNATE'
6755                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6756                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6757                          , p_Token_Tbl          => l_Token_Tbl
6758                          );
6759 
6760                 END IF;
6761                 l_return_status := FND_API.G_RET_STS_ERROR;
6762         END IF;
6763 
6764 
6765 
6766         IF   p_entity_processed IN ('ROP', 'RES', 'SR')
6767         THEN
6768 
6769             IF BOM_Rtg_Globals.Is_ROP_Cancl IS NULL THEN
6770                 FOR RevOp IN c_CheckCancelled
6771                 LOOP
6772                     l_token_tbl.DELETE;
6773                     l_Token_Tbl(1).Token_Name  := 'OP_SEQ_NUMBER';
6774                     l_Token_Tbl(1).Token_value := p_operation_seq_num;
6775                     Error_Handler.Add_Error_Token
6776                     (  p_Message_Name       => 'BOM_REV_OP_CANCELLED'
6777                      , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6778                      , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6779                      , p_Token_Tbl          => l_token_tbl
6780                     );
6781 
6782                     l_return_status := FND_API.G_RET_STS_ERROR;
6783                 END LOOP;
6784              END IF;
6785         END IF ;
6786         -- Bug 4210718
6787         -- Added the check for change policy for bill
6788         IF p_entity_processed IN ('SBC', 'RFD', 'RC')
6789         THEN
6790                 Check_Structure_Type_Policy
6791                     ( p_inventory_item_id   => p_revised_item_id
6792                     , p_organization_id     => p_organization_id
6793                     , p_alternate_bom_code  => p_alternate_bom_code
6794                     , x_structure_type_id   => l_structure_type_id
6795                     , x_strc_cp_not_allowed => l_cp_not_allowed
6796                     );
6797                 IF l_cp_not_allowed = 1
6798                 THEN
6799                     l_token_tbl.DELETE;
6800                     l_Token_Tbl(1).Token_Name  := 'STRUCTURE_NAME';
6801                     l_Token_Tbl(1).Token_value := p_alternate_bom_code;
6802                     Error_Handler.Add_Error_Token
6803                     (  p_Message_Name    => 'ENG_BILL_CHANGES_NOT_ALLOWED'
6804                      , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
6805                      , x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
6806                      , p_Token_Tbl       => l_token_tbl
6807                     );
6808 
6809                     l_return_status := FND_API.G_RET_STS_ERROR;
6810                 END IF;
6811         END IF;
6812         --
6813         -- If all the access checks are satisfied then return a status of
6814         -- success, else return error.
6815         --
6816 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Revised Item Check Access returning . . . ' ||
6817         l_return_status);
6818 END IF;
6819 
6820         x_Return_Status := l_return_status;
6821         x_Mesg_Token_Tbl := l_mesg_token_tbl;
6822 END Check_Access;
6823 
6824 -- Fix for bug 3577967
6825 /******************************************************************************
6826 * Procedure        : Get_Where_Clause_For_Subjects
6827 * Parameters IN    : Change Notice
6828 * Returns  IN OUT  : All ITEM_LIFECYCLE_PHASE_ID concatenated value for  where clause
6829 *                  : All ITEM_CATALOGUE_GROUP_ID concatenated value for  where clause
6830 *                  : All ITEM_TYPE_ID concatenated value for where clause
6831 * Purpose          : Procedure will verify if the change notice has subjects
6832 *                    at the header type level . If it does then the procedure
6833 *                    will return the subject values.
6834 ******************************************************************************/
6835  PROCEDURE Get_Where_Clause_For_Subjects(p_change_notice            IN VARCHAR2
6836                                         ,x_item_lifecycle_Phase     IN OUT NOCOPY VARCHAR2
6837                                         ,x_item_catalogue_Group     IN OUT NOCOPY VARCHAR2
6838                                         ,x_item_type                IN OUT NOCOPY VARCHAR2)
6839    IS
6840      l_item_lifecycle_Phase   VARCHAR2(2000) :=null;
6841      l_item_catalogue_Group   VARCHAR2(2000) :=null;
6842      l_item_type              VARCHAR2(2000) :=null;
6843 
6844      CURSOR GetSubjects IS
6845          SELECT ecpv.attribute_code ,
6846                 ecpv.attribute_char_value
6847            FROM eng_change_policies_v ecpv ,
6848                 eng_engineering_changes eec
6849           WHERE ecpv.policy_object_name = 'EGO_CHANGE_TYPE'
6850             AND ecpv.policy_object_pk1_value  = eec.change_order_type_id
6851             AND eec.change_notice = p_change_notice;
6852  BEGIN
6853       FOR c8rec IN GetSubjects LOOP
6854         IF( c8rec.ATTRIBUTE_CODE ='ITEM_LIFECYCLE_PHASE'  ) THEN
6855           IF(l_item_lifecycle_Phase  IS NOT  NULL) THEN
6856              l_item_lifecycle_Phase := l_item_lifecycle_Phase ||',';
6857           END IF;
6858           l_item_lifecycle_Phase := l_item_lifecycle_Phase || c8rec.ATTRIBUTE_CHAR_VALUE;
6859         END IF ;
6860         IF( c8rec.ATTRIBUTE_CODE ='CATALOG_CATEGORY') THEN
6861           IF(l_item_catalogue_Group  IS NOT  NULL) THEN
6862              l_item_catalogue_Group := l_item_catalogue_Group ||',';
6863           END IF;
6864           l_item_catalogue_Group := l_item_catalogue_Group || c8rec.ATTRIBUTE_CHAR_VALUE;
6865         END IF;
6866         IF(c8rec.ATTRIBUTE_CODE ='ITEM_TYPE' ) THEN
6867           IF(l_item_type  IS NOT  NULL ) THEN
6868             l_item_type := l_item_type ||',';
6869           END IF;
6870           l_item_type := l_item_type || '''' || c8rec.ATTRIBUTE_CHAR_VALUE ||'''';
6871         END IF;
6872       END LOOP;
6873       x_item_lifecycle_Phase :=l_item_lifecycle_Phase;
6874       x_item_catalogue_Group := l_item_catalogue_Group;
6875       x_item_type := l_item_type;
6876  EXCEPTION
6877      WHEN NO_DATA_FOUND THEN
6878         x_item_lifecycle_Phase :=null;
6879         x_item_catalogue_Group :=null;
6880         x_item_type            :=null;
6881  END Get_Where_Clause_For_Subjects;
6882 
6883 -- Fix for bug 3577967
6884 /******************************************************************************
6885 * Procedure        : validate_rev_items_for_sub
6886 * Parameters IN    : Change Notice
6887 *                  : Organization Id
6888 * Returns  IN OUT  : True If this item has same subjects same as the header type of change notice else
6889 *                  : False
6890 * Purpose          : Procedure will verify if the Item  has same subjects as
6891 *                    at the header type level of the change order.
6892 ******************************************************************************/
6893  PROCEDURE validate_rev_items_for_sub(
6894                            p_change_notice     IN VARCHAR2
6895                           ,p_inventory_item_id IN NUMBER
6896                           ,p_org_id            IN NUMBER
6897                           ,x_ret_Value         OUT NOCOPY BOOLEAN
6898                            ) IS
6899         l_current_phase_id          VARCHAR2(2000) ;
6900         l_item_catalog_group_id     VARCHAR2(2000) ;
6901         l_item_type                 VARCHAR2(2000) ;
6902         l_count_items               NUMBER  :=0;
6903         l_sql varchar2(2000);
6904  BEGIN
6905        Get_Where_Clause_For_Subjects(
6906                                p_change_notice          =>   p_change_notice
6907                               ,x_item_lifecycle_Phase   =>   l_current_phase_id
6908                               ,x_item_catalogue_Group   =>   l_item_catalog_group_id
6909                               ,x_item_type              =>   l_item_type);
6910        l_sql := 'SELECT COUNT(*)
6911                  FROM mtl_system_items_b
6912                  WHERE organization_id = :1
6913                    AND inventory_item_status_code not in (''Inactive'', ''Obsolete'')
6914                    AND inventory_item_id = :2';
6915         if l_current_phase_id IS NOT NULL then
6916           l_sql := l_sql||' AND current_phase_id in ('||l_current_phase_id||')';
6917         end if;
6918         if l_item_catalog_group_id IS NOT NULL then
6919           l_sql := l_sql || ' AND item_catalog_group_id in ('|| l_item_catalog_group_id||')';
6920         end if;
6921         IF l_item_type IS NOT NULL THEN
6922           l_sql := l_sql || ' AND item_type in('||l_item_type||')';
6923         END IF;
6924         EXECUTE IMMEDIATE l_sql into l_count_items using p_org_id, p_inventory_item_id;
6925         IF(l_count_items = 0 )
6926            THEN  x_ret_Value := FALSE;
6927            ELSE x_ret_Value  :=  TRUE;
6928         END IF;
6929  EXCEPTION
6930     WHEN NO_DATA_FOUND THEN
6931         x_ret_Value := FALSE;
6932  END validate_rev_items_for_sub;
6933 
6934 PROCEDURE Validate_Revised_Item (
6935     p_api_version               IN NUMBER := 1.0                         --
6936   , p_init_msg_list             IN VARCHAR2 := FND_API.G_FALSE           --
6937   , p_commit                    IN VARCHAR2 := FND_API.G_FALSE           --
6938   , p_validation_level          IN NUMBER  := FND_API.G_VALID_LEVEL_FULL --
6939   , p_debug                     IN VARCHAR2 := 'N'                       --
6940   , p_output_dir                IN VARCHAR2 := NULL                      --
6941   , p_debug_filename            IN VARCHAR2 := 'VALREVITEMS.log'       --
6942   , x_return_status             OUT NOCOPY VARCHAR2                      --
6943   , x_msg_count                 OUT NOCOPY NUMBER                        --
6944   , x_msg_data                  OUT NOCOPY VARCHAR2                      --
6945   -- Initialization
6946   , p_bo_identifier             IN VARCHAR2 := 'ECO'
6947   , p_transaction_type          IN VARCHAR2
6948   -- Change context
6949   , p_organization_id           IN NUMBER
6950   , p_change_id                 IN NUMBER
6951   , p_change_notice             IN VARCHAR2
6952   , p_assembly_type             IN NUMBER
6953   -- revised item
6954   , p_revised_item_sequence_id  IN NUMBER
6955   , p_revised_item_id           IN NUMBER
6956   , p_status_type               IN NUMBER
6957   , p_status_code               IN NUMBER
6958   -- new revision
6959   , p_new_revised_item_revision IN VARCHAR2
6960   , p_new_revised_item_rev_desc IN VARCHAR2
6961   , p_from_item_revision_id     IN NUMBER
6962   , p_new_revision_reason_code  IN VARCHAR2
6963   , p_new_revision_label        IN VARCHAR2
6964   , p_updated_revision          IN VARCHAR2
6965   , p_new_item_revision_id      IN NUMBER
6966   , p_current_item_revision_id  IN NUMBER
6967   -- effectivity
6968   , p_start_effective_date      IN DATE
6969   , p_new_effective_date        IN DATE
6970   , p_earliest_effective_date   IN DATE
6971   -- bill and routing
6972   , p_alternate_bom_code        IN VARCHAR2
6973   , p_bill_sequence_id          IN NUMBER
6974   , p_from_unit_number          IN VARCHAR2
6975   , p_new_from_unit_number      IN VARCHAR2
6976   , p_from_end_item_id          IN NUMBER
6977   , p_from_end_item_revision_id IN NUMBER
6978   , p_routing_sequence_id       IN NUMBER
6979   , p_completion_subinventory   IN VARCHAR2
6980   , p_completion_locator_id     IN NUMBER
6981   , p_priority                  IN NUMBER
6982   , p_ctp_flag                  IN NUMBER
6983   , p_new_routing_revision      IN VARCHAR2
6984   , p_updated_routing_revision  IN VARCHAR2
6985   , p_eco_for_production        IN NUMBER
6986   , p_cfm_routing_flag          IN NUMBER
6987   -- useup
6988   , p_use_up_plan_name          IN VARCHAR2
6989   , p_use_up_item_id            IN NUMBER
6990   , p_use_up                    IN NUMBER
6991   -- wip
6992   , p_disposition_type          IN NUMBER
6993   , p_update_wip                IN NUMBER
6994   , p_mrp_active                IN NUMBER
6995   , p_from_wip_entity_id        IN NUMBER
6996   , p_to_wip_entity_id          IN NUMBER
6997   , p_from_cumulative_quantity  IN NUMBER
6998   , p_lot_number                IN VARCHAR2
6999 )
7000 IS
7001     l_api_name                  CONSTANT VARCHAR2(30)   := 'Validate_Revised_Item';
7002     l_api_version               CONSTANT NUMBER := 1.0;
7003     l_return_status             VARCHAR2(1);
7004     l_mesg_token_tbl            Error_Handler.Mesg_Token_Tbl_Type;
7005 
7006     l_revised_item_rec          ENG_Eco_PUB.Revised_Item_Rec_Type;
7007     l_rev_item_unexp_rec        Eng_Eco_Pub.Rev_Item_Unexposed_Rec_Type;
7008     l_old_revised_item_rec      ENG_Eco_PUB.Revised_Item_Rec_Type;
7009     l_old_rev_item_unexp_rec    Eng_Eco_Pub.Rev_Item_Unexposed_Rec_Type;
7010     l_control_rec               BOM_BO_Pub.Control_Rec_Type;
7011 
7012     EXC_ERR_PVT_API_MAIN        EXCEPTION;
7013 
7014     -- init the following
7015     l_org_code                  VARCHAR2(3);
7016     l_revised_item_number       mtl_system_items_vl.concatenated_segments%TYPE;
7017     l_use_up_item_name          mtl_system_items_vl.concatenated_segments%TYPE;
7018     l_from_item_revision        mtl_item_revisions.revision%TYPE;
7019     l_completion_location_name  VARCHAR2(1);
7020     l_from_work_order           VARCHAR2(1);
7021     l_to_work_order             VARCHAR2(1);
7022     l_msg_data                  VARCHAR2(32000);
7023 BEGIN
7024 
7025     -- Standard call to check for call compatibility
7026     IF NOT FND_API.Compatible_API_Call(l_api_version, p_api_version, l_api_name, G_PKG_NAME)
7027     THEN
7028         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7029     END IF;
7030 
7031     -- Initialize message list if p_init_msg_list is set to TRUE.
7032     IF FND_API.to_Boolean(p_init_msg_list) THEN
7033         FND_MSG_PUB.Initialize;
7034         Error_Handler.Initialize;
7035     END IF;
7036 
7037     IF p_debug = 'Y'
7038     THEN
7039         BOM_Globals.Set_Debug(p_debug);
7040         Error_Handler.Open_Debug_Session(
7041             p_debug_filename     => p_debug_filename
7042           , p_output_dir         => p_output_dir
7043           , x_return_status      => l_return_status
7044           , x_error_mesg         => x_msg_data
7045           );
7046         IF l_return_status <> 'S'
7047         THEN
7048             BOM_Globals.Set_Debug('N');
7049         END IF;
7050     END IF;
7051     -- Initialize System_Information
7052     ENG_GLOBALS.Init_System_Info_Rec(
7053         x_mesg_token_tbl => l_mesg_token_tbl
7054       , x_return_status  => l_return_status
7055       );
7056     IF l_return_status <> FND_API.G_RET_STS_SUCCESS
7057     THEN
7058         RAISE EXC_ERR_PVT_API_MAIN;
7059     END IF;
7060     -- Initialize Unit_Effectivity flag
7061     IF PJM_UNIT_EFF.Enabled = 'Y'
7062     THEN
7063         BOM_Globals.Set_Unit_Effectivity (TRUE);
7064         ENG_Globals.Set_Unit_Effectivity (TRUE);
7065     ELSE
7066         BOM_Globals.Set_Unit_Effectivity (FALSE);
7067         ENG_Globals.Set_Unit_Effectivity (FALSE);
7068     END IF;
7069     --
7070     BOM_Globals.Set_Unit_Controlled_Item(
7071         p_inventory_item_id => p_revised_item_id
7072       , p_organization_id   => p_organization_id
7073       );
7074     BOM_Globals.Set_Require_Item_Rev(FND_PROFILE.VALUE('ENG:ECO_REVISED_ITEM_REVISION'));
7075     Eng_Globals.Set_Bo_Identifier( p_bo_identifier => p_bo_identifier);
7076     Eng_Globals.Set_Org_Id( p_org_id => p_organization_id);
7077 
7078     l_return_status := 'S';
7079 
7080     -- Start processing
7081     l_control_rec.caller_type                       := 'SSWA';
7082     l_control_rec.eco_assembly_type                 := p_assembly_type;
7083     -- Initialize the revised Item records
7084     -- change context
7085     l_rev_item_unexp_rec.organization_id            := p_organization_id;
7086     l_revised_item_rec.organization_code            := l_org_code;
7087     l_rev_item_unexp_rec.change_id                  := p_change_id;
7088     l_revised_item_rec.eco_name                     := p_change_notice;
7089     -- revised item
7090     l_rev_item_unexp_rec.revised_item_sequence_id   := p_revised_item_sequence_id;
7091     l_rev_item_unexp_rec.revised_item_id            := p_revised_item_id;
7092     l_revised_item_rec.status_type                  := p_status_type;
7093     l_rev_item_unexp_rec.status_code                := p_status_code;
7094     l_revised_item_rec.revised_item_name            := l_revised_item_number;
7095     -- new revision
7096     l_revised_item_rec.new_revised_item_revision    := p_new_revised_item_revision;
7097     l_revised_item_rec.New_Revised_Item_Rev_Desc    := p_new_revised_item_rev_desc;
7098     l_revised_item_rec.Updated_Revised_Item_Revision:= p_updated_revision;
7099     l_revised_item_rec.New_Revision_Label           := p_new_revision_label;
7100     l_revised_item_rec.New_Revised_Item_Rev_Desc    := p_new_revised_item_rev_desc;
7101     l_rev_item_unexp_rec.from_item_revision_id      := p_from_item_revision_id;
7102     l_rev_item_unexp_rec.new_revision_reason_code   := p_new_revision_reason_code;
7103     l_rev_item_unexp_rec.new_item_revision_id       := p_new_item_revision_id;
7104     l_rev_item_unexp_rec.current_item_revision_id   := p_current_item_revision_id;
7105     l_revised_item_rec.from_item_revision           := l_from_item_revision;
7106     -- Effectivity
7107     l_revised_item_rec.start_effective_date         := p_start_effective_date;
7108     l_revised_item_rec.New_Effective_Date           := p_new_effective_date;
7109     l_revised_item_rec.earliest_effective_date      := p_earliest_effective_date;
7110     -- Bill and routing
7111     l_revised_item_rec.alternate_bom_code           := p_alternate_bom_code;
7112     l_rev_item_unexp_rec.Bill_Sequence_Id           := p_Bill_Sequence_Id;
7113     l_rev_item_unexp_rec.from_end_item_id           := p_from_end_item_id;
7114     l_rev_item_unexp_rec.from_end_item_revision_id  := p_from_end_item_revision_id;
7115     l_revised_item_rec.From_End_Item_Unit_Number    := p_from_unit_number;
7116     l_revised_item_rec.New_From_End_Item_Unit_Number:= p_new_from_unit_number;
7117     l_rev_item_unexp_rec.routing_sequence_id        := p_routing_sequence_id;
7118     l_rev_item_unexp_rec.cfm_routing_flag           := p_cfm_routing_flag;
7119     l_revised_item_rec.ctp_flag                     := p_ctp_flag;
7120     l_revised_item_rec.completion_subinventory      := p_completion_subinventory;
7121     l_revised_item_rec.completion_location_name     := l_completion_location_name;
7122     l_rev_item_unexp_rec.completion_locator_id      := p_completion_locator_id;
7123     l_revised_item_rec.new_routing_revision         := p_new_routing_revision;
7124     l_revised_item_rec.updated_routing_revision     := p_updated_routing_revision;
7125     l_revised_item_rec.priority                     := p_priority;
7126     l_revised_item_rec.eco_for_production           := p_eco_for_production;
7127     -- use up
7128     l_revised_item_rec.use_up_item_name             := l_use_up_item_name;
7129     l_revised_item_rec.use_up_plan_name             := p_use_up_plan_name;
7130     l_rev_item_unexp_rec.use_up_item_id             := p_use_up_item_id;
7131     l_rev_item_unexp_rec.use_up                     := p_use_up;
7132     -- WIP
7133     l_revised_item_rec.disposition_type             := p_disposition_type;
7134     l_revised_item_rec.update_wip                   := p_update_wip;
7135     l_revised_item_rec.mrp_active                   := p_mrp_active;
7136     l_rev_item_unexp_rec.from_wip_entity_id         := p_from_wip_entity_id;
7137     l_rev_item_unexp_rec.to_wip_entity_id           := p_to_wip_entity_id;
7138     l_revised_item_rec.from_work_order              := l_from_work_order;
7139     l_revised_item_rec.to_work_order                := l_to_work_order;
7140     l_revised_item_rec.from_cumulative_quantity     := p_from_cumulative_quantity;
7141     l_revised_item_rec.lot_number                   := p_lot_number;
7142     -- Other
7143     l_revised_item_rec.return_status                := l_return_status;
7144     l_revised_item_rec.transaction_type             := p_transaction_type;
7145     -- End Initialize the revised item record
7146     -- Start initialize the old revised item record
7147 
7148     BEGIN
7149         SELECT
7150             change_notice
7151           , organization_id
7152           , revised_item_id
7153           , implementation_date
7154           , cancellation_date
7155           , cancel_comments
7156           , disposition_type
7157           , new_item_revision
7158           , early_schedule_date
7159           , attribute_category
7160           , attribute2
7161           , attribute3
7162           , attribute4
7163           , attribute5
7164           , attribute7
7165           , attribute8
7166           , attribute9
7167           , attribute11
7168           , attribute12
7169           , attribute13
7170           , attribute14
7171           , attribute15
7172           , status_type
7173           , scheduled_date
7174           , bill_sequence_id
7175           , mrp_active
7176           , update_wip
7177           , use_up
7178           , use_up_item_id
7179           , revised_item_sequence_id
7180           , use_up_plan_name
7181           , descriptive_text
7182           , auto_implement_date
7183           , attribute1
7184           , attribute6
7185           , attribute10
7186           , from_wip_entity_id
7187           , to_wip_entity_id
7188           , from_cum_qty
7189           , lot_number
7190           , cfm_routing_flag
7191           , completion_subinventory
7192           , completion_locator_id
7193           , priority
7194           , ctp_flag
7195           , routing_sequence_id
7196           , new_routing_revision
7197           , routing_comment
7198           , eco_for_production
7199           , change_id
7200           , status_code
7201         INTO
7202             l_old_revised_item_rec.eco_name
7203           , l_old_rev_item_unexp_rec.organization_id
7204           , l_old_rev_item_unexp_rec.revised_item_id
7205           , l_old_rev_item_unexp_rec.implementation_date
7206           , l_old_rev_item_unexp_rec.cancellation_date
7207           , l_old_revised_item_rec.cancel_comments
7208           , l_old_revised_item_rec.disposition_type
7209           , l_old_revised_item_rec.new_revised_item_revision
7210           , l_old_revised_item_rec.earliest_effective_date
7211           , l_old_revised_item_rec.attribute_category
7212           , l_old_revised_item_rec.attribute2
7213           , l_old_revised_item_rec.attribute3
7214           , l_old_revised_item_rec.attribute4
7215           , l_old_revised_item_rec.attribute5
7216           , l_old_revised_item_rec.attribute7
7217           , l_old_revised_item_rec.attribute8
7218           , l_old_revised_item_rec.attribute9
7219           , l_old_revised_item_rec.attribute11
7220           , l_old_revised_item_rec.attribute12
7221           , l_old_revised_item_rec.attribute13
7222           , l_old_revised_item_rec.attribute14
7223           , l_old_revised_item_rec.attribute15
7224           , l_old_revised_item_rec.status_type
7225           , l_old_revised_item_rec.start_effective_date
7226           , l_rev_item_unexp_rec.bill_sequence_id
7227           , l_old_revised_item_rec.mrp_active
7228           , l_old_revised_item_rec.update_wip
7229           , l_old_rev_item_unexp_rec.use_up
7230           , l_old_rev_item_unexp_rec.use_up_item_id
7231           , l_old_rev_item_unexp_rec.revised_item_sequence_id
7232           , l_old_revised_item_rec.use_up_plan_name
7233           , l_old_revised_item_rec.change_description
7234           , l_old_rev_item_unexp_rec.auto_implement_date
7235           , l_old_revised_item_rec.attribute1
7236           , l_old_revised_item_rec.attribute6
7237           , l_old_revised_item_rec.attribute10
7238           , l_old_rev_item_unexp_rec.from_wip_entity_id
7239           , l_old_rev_item_unexp_rec.to_wip_entity_id
7240           , l_old_revised_item_rec.from_cumulative_quantity
7241           , l_old_revised_item_rec.lot_number
7242           , l_old_rev_item_unexp_rec.cfm_routing_flag
7243           , l_old_revised_item_rec.completion_subinventory
7244           , l_old_rev_item_unexp_rec.completion_locator_id
7245           , l_old_revised_item_rec.priority
7246           , l_old_revised_item_rec.ctp_flag
7247           , l_old_rev_item_unexp_rec.routing_sequence_id
7248           , l_old_revised_item_rec.new_routing_revision
7249           , l_old_revised_item_rec.routing_comment
7250           , l_old_revised_item_rec.eco_for_production
7251           , l_old_rev_item_unexp_rec.change_id
7252           , l_old_rev_item_unexp_rec.status_code
7253         FROM eng_revised_items
7254         WHERE revised_item_sequence_id = p_revised_item_sequence_id;
7255     EXCEPTION
7256     WHEN NO_DATA_FOUND THEN
7257         null;
7258     END;
7259 
7260     IF l_return_status = 'S'
7261     THEN
7262         Check_Attributes(
7263             x_return_status           => l_return_status
7264           , x_Mesg_Token_Tbl          => l_mesg_token_tbl
7265           , p_revised_item_rec        => l_revised_item_rec
7266           , p_rev_item_unexp_rec      => l_rev_item_unexp_rec
7267           , p_old_revised_item_rec    => l_old_revised_item_rec
7268           , p_old_rev_item_unexp_rec  => l_old_rev_item_unexp_rec
7269           );
7270     END IF;
7271 
7272     IF l_return_status = 'S'
7273     THEN
7274         Check_Entity(
7275             p_revised_item_rec         => l_revised_item_rec
7276           , p_rev_item_unexp_rec       => l_rev_item_unexp_rec
7277           , p_old_revised_item_rec     => l_old_revised_item_rec
7278           , p_old_rev_item_unexp_rec   => l_old_rev_item_unexp_rec
7279           , p_control_rec              => l_control_rec
7280           , x_Mesg_Token_Tbl           => l_mesg_token_tbl
7281           , x_Return_Status            => l_return_status
7282           );
7283     END IF;
7284 
7285     IF l_return_status <> 'S'
7286     THEN
7287         FOR l_LoopIndex IN 1..l_mesg_token_tbl.COUNT
7288         LOOP
7289             fnd_message.clear;
7290             FND_MESSAGE.Set_Name(
7291                 application => 'ENG'
7292               , name        => 'ENG_ACTION_MESSAGE'
7293               );
7294             /*IF l_mesg_token_tbl(l_LoopIndex).token_name IS NOT NULL
7295             THEN*/
7296                 fnd_message.set_token(
7297                     token     => 'ACTION'
7298                   , value     => l_mesg_token_tbl(l_LoopIndex).message_text
7299                   );
7300                 fnd_message.set_token(
7301                     token     => 'ENTITY'
7302                   , value     => ' '
7303                   );
7304 /*            END IF;*/
7305             Fnd_msg_pub.add;
7306         END LOOP;
7307     END IF;
7308 
7309     -- Start of Closure to procedure
7310     x_return_status := l_return_status;
7311 
7312     FND_MSG_PUB.Count_And_Get(
7313         p_count => x_msg_count
7314       , p_data  => l_msg_data
7315       );
7316 
7317     x_msg_data := l_msg_data;
7318     IF Bom_Globals.Get_Debug = 'Y'
7319     THEN
7320         Error_Handler.Write_Debug('-***-End API Validate_Revised_Item-***-');
7321         Error_Handler.Close_Debug_Session;
7322     END IF;
7323 
7324 
7325 EXCEPTION
7326 WHEN OTHERS THEN
7327     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
7328     IF FND_MSG_PUB.Check_Msg_Level( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
7329     THEN
7330         FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME, l_api_name);
7331     END IF;
7332     FND_MSG_PUB.Count_And_Get(
7333         p_count => x_msg_count
7334       , p_data  => x_msg_data
7335       );
7336     IF Bom_Globals.Get_Debug = 'Y'
7337     THEN
7338         Error_Handler.Write_Debug('Unexpected Error ');
7339         Error_Handler.Close_Debug_Session;
7340     END IF;
7341 
7342 END Validate_Revised_Item;
7343 
7344 END ENG_Validate_Revised_Item;