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