DBA Data[Home] [Help]

PACKAGE BODY: APPS.BOM_VALIDATE_BOM_COMPONENT

Source


1 PACKAGE BODY BOM_Validate_Bom_Component AS
2 /* $Header: BOMLCMPB.pls 120.62.12020000.2 2012/07/20 02:55:33 vbrobbey ship $ */
3 /*************************************************************************
4 --
5 --  Copyright (c) 1996 Oracle Corporation, Redwood Shores, CA, USA
6 --  All rights reserved.
7 --
8 --  FILENAME
9 --
10 --      BOMLCMPB.pls
11 --
12 --  DESCRIPTION
13 --
14 --      Body of package BOM_Validate_Bom_Component
15 --
16 --  NOTES
17 --
18 --  HISTORY
19 --
20 --  11-JUN-99 Rahul Chitko	Initial Creation
21 --
22 --  08-MAY-2001 Refai Farook    EAM related changes
23 --
24 --  30-AUG-01   Refai Farook    One To Many support changes
25 --
26 --  25-SEP-01   Refai Farook    Added new function (Check_Unit_Number) and changes to the Check_Entity
27 --                              procedure. (Mass changes for unit effectivity changes)
28 --
29 --  15-NOV-02	Anirban Dey	Added support for Auto_Request_Material in 11.5.9
30 --
31 --  06-May-05 Abhishek Rudresh        Common BOM Attrs update
32 
33 --  20-Jun-05   Vani Hymavathi       Validations for to OPM convergence project
34 **************************************************************************/
35 
36 	G_PKG_NAME		      VARCHAR2(30) :=
37 					'BOM_Validate_Bom_Component';
38 
39 	l_dummy                                VARCHAR2(80);
40 	/*
41 	l_MODEL                       CONSTANT NUMBER := 1;
42 	l_OPTION_CLASS                CONSTANT NUMBER := 2;
43 	l_PLANNING                    CONSTANT NUMBER := 3;
44 	l_STANDARD                    CONSTANT NUMBER := 4;
45 	l_PRODUCT_FAMILY	      CONSTANT NUMBER := 5;
46 	*/
47 	l_Sub_Locator_Control         NUMBER;
48 	l_locator_control             NUMBER;
49 	l_org_locator_control         NUMBER;
50 	l_item_locator_control        NUMBER;
51 	l_item_loc_restricted         NUMBER; -- 1,Locator is Restricted,else 2
52 
53 	g_Comp_Item_Type        NUMBER; -- Bom_Item_Type of Component
54 	g_Assy_Item_Type        NUMBER; -- Bom_Item_Type of Assembly
55 	g_Comp_ATO_flag         CHAR;   -- ATO flag for Component
56 	g_Assy_ATO_flag         CHAR;   -- ATO flag for Assembly
57 	g_Comp_PTO_flag         CHAR;   -- PTO flag for Component
58 	g_Assy_PTO_flag         CHAR;   -- PTO flag for Assembly
59 	g_Comp_Config           CHAR;   -- Is component a config item
60 	g_Comp_ATO_Forecast_Control NUMBER;  -- Component items ATO Frcst Ctrl
61 	g_Assy_Config           CHAR;   -- Is assembly  a config item
62 	g_Comp_Eng_Flag         CHAR;   -- Is component an Engineering Item
63 	g_Assy_Eng_Flag         CHAR;   -- Is assembly an Engineering Item
64 	g_Comp_ATP_Comp_flag    CHAR;   -- Components ATP Component Flag
65 	g_Assy_ATP_Comp_flag    CHAR;   -- Assembly's ATP Component flag
66 	g_Comp_ATP_Check_flag   CHAR;   -- Components ATP check flag
67 	g_Assy_ATP_Check_flag   CHAR;   -- Assembly's ATP check flag
68 	g_Assy_Wip_supply_Type  NUMBER; -- Assembly 's wip supply type
69 	g_Comp_Wip_Supply_Type  NUMBER; -- Components WIP Supply Type
70 	g_Assy_Bom_Enabled_flag CHAR;   -- Assembly's bom_enabled_flag
71 	g_Comp_Bom_Enabled_flag CHAR;   -- Component's bom_enabled_flag
72         g_Assy_Effectivity_Control  NUMBER;             --2044133
73         g_Comp_Effectivity_Control  NUMBER;             --2044133
74         g_Comp_Tracking_Quantity_Ind VARCHAR2(30);
75         g_Assy_Tracking_Quantity_Ind VARCHAR2(30);
76 	g_Assy_Assembly_Type        NUMBER;             --4161794
77 
78         g_rev_component_rec           Bom_bo_Pub.Rev_Component_Rec_Type;
79 	g_Rev_Comp_Unexp_Rec          Bom_Bo_Pub.Rev_Comp_Unexposed_Rec_Type;
80 	g_Token_Tbl                   Error_Handler.Token_Tbl_Type;
81 
82 FUNCTION Item_Revision_Exists (p_item_id IN NUMBER,
83 				p_org_id  IN NUMBER,
84 				p_eff_dt  IN DATE)
85 RETURN BOOLEAN
86 IS
87     CURSOR c1 IS
88        SELECT REVISION
89        FROM   MTL_ITEM_REVISIONS_B MIR
90        WHERE  INVENTORY_ITEM_ID = p_item_id
91        AND    ORGANIZATION_ID = p_org_id
92        AND    MIR.EFFECTIVITY_DATE <= p_eff_dt;
93 BEGIN
94      Error_Handler.Write_Debug('In Item Check Revisio' );
95      Error_Handler.Write_Debug('Item id '||to_char(p_item_id));
96      Error_Handler.Write_Debug('Org id '||to_char(p_org_id));
97      Error_Handler.Write_Debug('Eff Dt '||to_char(p_eff_dt));
98   FOR r1 IN c1
99   LOOP
100      Error_Handler.Write_Debug('In loop');
101     Return TRUE;
102   END LOOP;
103      Error_Handler.Write_Debug('Returning False' );
104   Return FALSE;
105 END;
106 
107 
108 /*******************************************************************
109 * PROCEDURE	: Check_Component_Type_Rule
110 * Parameters IN	: p_parent_item_id   parent item id
111 *		  p_child_item_id    child item id
112 *		  p_organization_id  org id.
113 *                 p_init_msg_list    Default value is TRUE.By default
114 *                 the error handler is initialized.If the caller does not
115 *                 want the error handler to get initialized, the caller
116 *                 has to pass FALSE.
117 * Parameters OUT: x_return_status is FND_API.G_RET_STS_SUCCESS or
118 *                                    FND_API.G_RET_STS_ERROR
119 *                 x_error_message    The error message passed to the
120 	 			     caller
121 * Purpose	: This procedure will actually check if any component
122 *                 type rule exists between the two item types of the item
123 *                 which are to be associated.If such any component type
124 *                 rule exists then the procedure checks if these items
125 *                 can be associated according to the rule.If not the
126 *                 procedure returns the error staus and error message.
127 *                 If the items can be associated then it returns success.
128 *******************************************************************/
129 
130 PROCEDURE Check_Component_Type_Rule(
131 		x_return_status	   IN OUT NOCOPY VARCHAR2
132 	      ,	x_error_message    IN OUT NOCOPY /* file.sql.39 change */  VARCHAR2
133               , p_init_msg_list    IN  BOOLEAN := TRUE
134               , p_parent_item_id   IN NUMBER
135  	      , p_child_item_id    IN NUMBER
136 	      , p_organization_id  IN NUMBER
137 	      )
138 IS
139         l_customization_code       AK_CUSTOMIZATIONS.CUSTOMIZATION_CODE%TYPE;
140         l_parent_item_type         MTL_SYSTEM_ITEMS.ITEM_TYPE%TYPE;
141 	l_child_item_type          MTL_SYSTEM_ITEMS.ITEM_TYPE%TYPE;
142 	l_parent_item_type_name    FND_LOOKUP_VALUES_VL.MEANING%TYPE;
143 	l_child_item_type_name     FND_LOOKUP_VALUES_VL.MEANING%TYPE;
144 	l_return_status            VARCHAR2(1);
145 	l_mesg_token_tbl           Error_Handler.Mesg_Token_Tbl_Type;
146 	l_token_tbl                Error_Handler.Token_Tbl_Type;
147 	l_message_list             Error_Handler.Error_Tbl_Type;
148 	l_parent_name              VARCHAR2(700);
149 	l_child_name               VARCHAR2(700);
150 
151 BEGIN
152 
153         --
154         -- Initialize the message list if the user has set the
155         -- Init Message List parameter
156         --
157         IF p_init_msg_list
158         THEN
159            Error_Handler.Initialize;
160         END IF;
161 
162 
163 	x_return_status := FND_API.G_RET_STS_SUCCESS;
164 	l_return_status := 'N';
165 
166 	SELECT MSI.ITEM_TYPE, LOOKUP.MEANING ,MSI.CONCATENATED_SEGMENTS
167 	INTO l_parent_item_type,l_parent_item_type_name,l_parent_name
168 	FROM MTL_SYSTEM_ITEMS_KFV MSI ,FND_COMMON_LOOKUPS LOOKUP
169 	WHERE
170 	INVENTORY_ITEM_ID = p_parent_item_id AND ORGANIZATION_ID = p_organization_id
171 	AND MSI.ITEM_TYPE = LOOKUP.LOOKUP_CODE(+)
172 	AND LOOKUP.LOOKUP_TYPE(+) = 'ITEM_TYPE'
173 	AND LOOKUP.ENABLED_FLAG(+) = 'Y'
174 	AND (LOOKUP.START_DATE_ACTIVE IS NULL OR LOOKUP.START_DATE_ACTIVE < SYSDATE)
175 	AND (LOOKUP.END_DATE_ACTIVE IS NULL OR LOOKUP.END_DATE_ACTIVE > SYSDATE);
176 
177 	--dbms_output.put_line('l_parent_item_type_name '||l_parent_item_type_name);
178 	--dbms_output.put_line('l_parent_name '||l_parent_name);
179 	--dbms_output.put_line('l_parent_item_type '||l_parent_item_type);
180 
181 	SELECT MSI.ITEM_TYPE, LOOKUP.MEANING ,MSI.CONCATENATED_SEGMENTS
182 	INTO l_child_item_type , l_child_item_type_name,l_child_name
183 	FROM MTL_SYSTEM_ITEMS_KFV MSI ,FND_COMMON_LOOKUPS LOOKUP
184 	WHERE
185 	INVENTORY_ITEM_ID = p_child_item_id AND ORGANIZATION_ID = p_organization_id
186 	AND MSI.ITEM_TYPE = LOOKUP.LOOKUP_CODE(+)
187 	AND LOOKUP.LOOKUP_TYPE(+) = 'ITEM_TYPE'
188 	AND LOOKUP.ENABLED_FLAG(+) = 'Y'
189 	AND (LOOKUP.START_DATE_ACTIVE IS NULL OR LOOKUP.START_DATE_ACTIVE < SYSDATE)
190         AND (LOOKUP.END_DATE_ACTIVE IS NULL OR LOOKUP.END_DATE_ACTIVE > SYSDATE);
191 
192         --dbms_output.put_line('l_child_item_type_name '||l_child_item_type_name);
193 	--dbms_output.put_line('l_child_name '||l_child_name);
194 	--dbms_output.put_line('l_child_item_type '||l_child_item_type);
195 
196 	-- dbms_output.put_line('CHILD ITEM TYPE '||l_child_item_type_name);
197 	IF (l_parent_item_type IS NOT  NULL)
198 	THEN
199 	    SELECT TEMPLATES.CUSTOMIZATION_CODE INTO l_customization_code
200   	    FROM FND_COMMON_LOOKUPS LOOKUP,
201      	         EGO_CRITERIA_TEMPLATES_V TEMPLATES
202 	    WHERE LOOKUP.LOOKUP_TYPE = 'ITEM_TYPE'
203 	         AND LOOKUP.ENABLED_FLAG = 'Y'
204 		 AND (LOOKUP.START_DATE_ACTIVE IS NULL OR LOOKUP.START_DATE_ACTIVE < SYSDATE)
205 		 AND (LOOKUP.END_DATE_ACTIVE IS NULL OR LOOKUP.END_DATE_ACTIVE > SYSDATE)
206 		 AND LOOKUP.LOOKUP_CODE = TEMPLATES.CLASSIFICATION1
207 		 AND TEMPLATES.CUSTOMIZATION_APPLICATION_ID = 702
208 		 AND TEMPLATES.REGION_APPLICATION_ID = 702
209 		 AND TEMPLATES.REGION_CODE = 'BOM_ITEM_TYPE_REGION'
210 		 AND LOOKUP_CODE = l_parent_item_type
211                  AND TEMPLATES.CLASSIFICATION1 = l_parent_item_type;
212 	     --dbms_output.put_line('l_customization_code '||l_customization_code);
213 	BEGIN
214 
215 	    SELECT 'Y' INTO l_return_status FROM DUAL
216 	    WHERE l_child_item_type IN
217 	    (
218 	       SELECT VALUE_VARCHAR2 FROM EGO_CRITERIA_V
219 	       WHERE
220 	       CUSTOMIZATION_APPLICATION_ID = 702 AND
221 	       REGION_APPLICATION_ID = 702 AND
222 	       REGION_CODE = 'BOM_ITEM_TYPE_REGION'
223 	       AND  CUSTOMIZATION_CODE = l_customization_code
224 	    );
225 	EXCEPTION
226 	WHEN NO_DATA_FOUND THEN
227 	  IF l_return_status <> 'Y'
228 	  THEN
229 		    l_token_tbl(1).token_name  := 'PARENT_ITEM_NAME';
230 		    l_token_tbl(1).token_value := l_parent_name;
231 		    l_token_tbl(2).token_name  := 'PARENT_ITEM_TYPE';
232 		    l_token_tbl(2).token_value := l_parent_item_type_name;
233 		    l_token_tbl(3).token_name  := 'CHILD_ITEM_NAME';
234 		    l_token_tbl(3).token_value   := l_child_name;
235 		    l_token_tbl(4).token_name  := 'CHILD_ITEM_TYPE';
236 		    l_token_tbl(4).token_value   := l_child_item_type_name;
237 
238 	    Error_Handler.Add_Error_Token
239 		(  p_Message_Name       => 'BOM_COMP_ASSOC_DENIED'
240 		 , p_Mesg_Token_Tbl     => l_mesg_token_tbl
241 		 , x_Mesg_Token_Tbl     => l_mesg_token_tbl
242 		 , p_Token_Tbl          => l_token_tbl
243 		);
244 
245 	    Error_Handler.Translate_And_Insert_Messages
246 		(  p_mesg_token_tbl     => l_mesg_token_tbl
247 		 , p_application_id     => 'BOM'
248 		);
249 
250 	    Error_Handler.Get_Message_List( x_message_list => l_message_list);
251 	    x_error_message := l_message_list(1).Message_Text;
252 	    x_return_status := FND_API.G_RET_STS_ERROR;
253 	    -- dbms_output.put_line('RETURN STATUS WITH EXCEPTION '||l_return_status);
254 	    -- dbms_output.put_line('RETURN STATUS '||x_return_status);
255 	    -- dbms_output.put_line('RETURN MESSAGE '||x_error_message);
256             IF p_init_msg_list
257             THEN
258                 Error_Handler.Write_To_DebugFile;
259 	        Error_Handler.Close_Debug_Session;
260             END IF;
261 	  END IF;
262 	END;
263 	ELSE
264 	  l_return_status := 'Y' ;
265 	END IF;
266 
267 	IF l_return_status = 'Y'
268 	THEN
269 	    x_return_status  := FND_API.G_RET_STS_SUCCESS;
270 	    -- dbms_output.put_line('CRITERIA TEMPLATE FOUND.ITEM TYPES MATCH FOUND.');
271 	    -- dbms_output.put_line('RETURN STATUS '||x_return_status);
272 	    -- dbms_output.put_line('RETURN MESSAGE '||x_error_message);
273 	END IF;
274 
275 EXCEPTION
276       WHEN NO_DATA_FOUND THEN
277       x_return_status  := FND_API.G_RET_STS_SUCCESS;
278       -- dbms_output.put_line('NO CRITERIA TEMPLATE FOUND. SO ANYTHING CAN BE ADDED');
279       -- dbms_output.put_line('RETURN STATUS '||x_return_status);
280       -- dbms_output.put_line('RETURN MESSAGE '||x_error_message);
281 
282 END Check_Component_Type_Rule;
283 
284 	/*******************************************************************
285 	* Procedure	: Check_Entity
286 	* Parameters IN	: Bom Component Exposed Column record
287 	*		  Bom Component unexposed column record
288 	*		  Bom Component old exposed column record
289 	*		  Bom Component old unexposed column record
290 	* Parameters OUT: Return Status
291 	*		  Message Token Table
292 	* Purpose	: Procedure will execute the business logic and will
293 	*		  also perform any required cross entity validations
294 	*******************************************************************/
295 	PROCEDURE Check_Entity
296 	( x_return_status	   IN OUT NOCOPY VARCHAR2
297 	, x_Mesg_Token_Tbl	   IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
298 	, p_bom_component_rec	   IN  Bom_Bo_Pub.Bom_Comps_Rec_Type
299 	, p_bom_Comp_Unexp_Rec	   IN  Bom_Bo_Pub.Bom_Comps_Unexposed_Rec_Type
300 	, p_old_bom_Component_Rec  IN  Bom_Bo_Pub.Bom_Comps_Rec_Type
301 	, p_old_bom_Comp_Unexp_Rec IN  Bom_Bo_Pub.Bom_Comps_Unexposed_Rec_Type
302 	)
303 	IS
304 		l_rev_component_rec	Bom_Bo_Pub.Rev_Component_Rec_Type;
305 		l_rev_comp_unexp_rec	Bom_Bo_Pub.Rev_Comp_Unexposed_Rec_Type;
306 		l_old_rev_component_rec	Bom_Bo_Pub.Rev_Component_Rec_Type;
307 		l_old_rev_comp_unexp_rec
308 					Bom_Bo_Pub.Rev_Comp_Unexposed_Rec_Type;
309 	BEGIN
310 		x_return_status := FND_API.G_RET_STS_SUCCESS;
311 
312 		-- Convert BOM record into ECO record
313 
314 		Bom_Bo_Pub.Convert_BomComp_To_EcoComp
315 		(  p_bom_component_rec	=> p_bom_component_rec
316 		 , p_bom_comp_unexp_rec	=> p_bom_comp_unexp_rec
317 		 , x_rev_component_rec	=> l_rev_component_rec
318 		 , x_rev_comp_unexp_rec	=> l_rev_comp_unexp_rec
319 		);
320 
321 		-- Also convert Old BOM component record into ECO
322 		Bom_Bo_Pub.Convert_BomComp_To_EcoComp
323 		(  p_bom_component_rec	=> p_old_bom_component_rec
324 		 , p_bom_comp_unexp_rec	=> p_old_bom_comp_unexp_rec
325 		 , x_rev_component_rec	=> l_old_rev_component_rec
326 		 , x_rev_comp_unexp_rec	=> l_old_rev_comp_unexp_rec
327 		 );
328 
329 		-- Call Check Entity
330 		Bom_Validate_Bom_Component.Check_Entity
331 		(  p_rev_component_rec	=> l_rev_component_rec
332 		 , p_rev_comp_unexp_rec	=> l_rev_comp_unexp_rec
333 		 , p_old_rev_component_rec	=> l_old_rev_component_rec
334 		 , p_old_rev_comp_unexp_rec	=> l_old_rev_comp_unexp_rec
335 		 , x_return_status	=> x_return_status
336 		 , x_mesg_token_tbl	=> x_mesg_token_tbl
337 		 );
338 
339 	END Check_Entity;
340 
341 
342 	/********************************************************************
343 	* Procedure	: Check_Attributes
344 	* Parameters IN	: Bom Component exposed column record
345 	*		  Bom component unexposed column record
346 	* Parameters OUT: Return Status
347 	*		  Message Token Table
348 	* Purpose	: Check_Attributes will verify the exposed attributes
349 	*		  of the component record in their own entirety. No
350 	*		  cross entity validations will be performed.
351 	********************************************************************/
352 	PROCEDURE Check_Attributes
353 	( x_return_status	IN OUT NOCOPY VARCHAR2
354 	, x_Mesg_Token_Tbl	IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
355 	, p_bom_component_rec	IN  Bom_Bo_Pub.Bom_Comps_Rec_Type
356 	, p_bom_Comp_Unexp_Rec	IN  Bom_Bo_Pub.Bom_Comps_Unexposed_Rec_Type
357 	)
358 	IS
359 
360 		l_rev_component_rec	Bom_Bo_Pub.Rev_Component_Rec_Type;
361 		l_rev_comp_unexp_rec	Bom_Bo_Pub.Rev_Comp_Unexposed_Rec_Type;
362 	BEGIN
363 		Bom_Bo_Pub.Convert_BomComp_To_EcoComp
364 		(  p_bom_component_rec	=> p_bom_component_rec
365 		 , p_bom_comp_unexp_rec	=> p_bom_comp_unexp_rec
366 		 , x_rev_component_rec	=> l_rev_component_rec
367 		 , x_rev_comp_unexp_rec	=> l_rev_comp_unexp_rec
368 		 );
369 
370 		-- Call Check Attributes procedure
371 		Bom_Validate_Bom_Component.Check_Attributes
372 		(  p_rev_component_rec	=> l_rev_component_rec
373 		 , p_rev_comp_unexp_rec	=> l_rev_comp_unexp_rec
374 		 , x_return_status	=> x_return_status
375 		 , x_mesg_token_tbl	=> x_mesg_token_tbl
376 		);
377 
378 	END Check_Attributes;
379 
380 	PROCEDURE Check_Entity_Delete
381 	( x_return_status	IN OUT NOCOPY VARCHAR2
382 	, x_Mesg_Token_Tbl	IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
383 	, p_bom_component_rec	IN  Bom_Bo_Pub.Bom_Comps_Rec_Type
384 	, p_bom_Comp_Unexp_Rec	IN  Bom_Bo_Pub.Bom_Comps_Unexposed_Rec_Type
385 	)
386 	IS
387 	BEGIN
388 		NULL;
389 	END Check_Entity_Delete;
390 
391 
392 	PROCEDURE Check_Required
393 	( x_return_status		IN OUT NOCOPY VARCHAR2
394 	, x_Mesg_Token_Tbl              IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
395 	, p_bom_component_rec           IN  Bom_Bo_Pub.Bom_Comps_Rec_Type
396 	)
397 	IS
398 		l_rev_component_rec	Bom_Bo_Pub.Rev_Component_Rec_Type;
399 		l_rev_comp_unexp_rec	Bom_Bo_Pub.Rev_Comp_Unexposed_Rec_Type;
400 	BEGIN
401 		Bom_Bo_Pub.Convert_BomComp_to_EcoComp
402 		(  p_bom_component_rec	=> p_bom_component_rec
403 	 	 , x_rev_component_rec	=> l_rev_component_rec
404 		 , x_rev_comp_unexp_rec	=> l_rev_comp_unexp_rec
405 		 );
406 
407 		Bom_Validate_Bom_Component.Check_required
408 		(  p_rev_component_rec	=> l_rev_component_rec
409 		 , x_return_status	=> x_return_status
410 		 , x_mesg_token_tbl	=> x_mesg_token_tbl
411 		 );
412 	END Check_Required;
413 
414 
415 	PROCEDURE Check_Existence
416 	(  p_bom_component_rec	     IN  Bom_Bo_Pub.Bom_Comps_Rec_Type
417 	 , p_bom_comp_unexp_rec	     IN  Bom_Bo_Pub.Bom_Comps_Unexposed_Rec_Type
418 	 , x_old_bom_component_rec   IN OUT NOCOPY Bom_Bo_Pub.Bom_Comps_Rec_Type
419 	 , x_old_bom_comp_unexp_rec  IN OUT NOCOPY Bom_Bo_Pub.Bom_Comps_Unexposed_Rec_Type
420 	 , x_Mesg_Token_Tbl	     IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
421 	 , x_return_status	     IN OUT NOCOPY VARCHAR2
422 	)
423 	IS
424 		l_rev_component_rec	 Bom_Bo_Pub.Rev_Component_Rec_Type;
425 		l_rev_comp_unexp_rec	 Bom_Bo_Pub.Rev_Comp_Unexposed_Rec_Type;
426 		l_old_rev_component_rec	 Bom_Bo_Pub.Rev_Component_Rec_Type;
427 		l_old_rev_comp_unexp_rec Bom_Bo_Pub.Rev_Comp_Unexposed_Rec_Type;
428 	BEGIN
429 		-- Convert bom component to eco component
430 		Bom_Bo_Pub.Convert_BomComp_To_EcoComp
431 		(  p_bom_component_rec	=> p_bom_component_rec
432 		 , p_bom_comp_unexp_rec	=> p_bom_comp_unexp_rec
433 		 , x_rev_component_rec	=> l_rev_component_rec
434 		 , x_rev_comp_unexp_rec	=> l_rev_comp_unexp_rec
435 		);
436 
437 		Bom_Validate_Bom_Component.Check_Existence
438 		(  p_rev_component_rec	=> l_rev_component_rec
439 		 , p_rev_comp_unexp_rec	=> l_rev_comp_unexp_rec
440 		 , x_old_rev_component_rec => l_old_rev_component_rec
441 		 , x_old_rev_comp_unexp_rec => l_old_rev_comp_unexp_rec
442 		 , x_return_status	=> x_return_status
443 		 , x_mesg_token_tbl	=> x_mesg_token_tbl
444 		);
445 
446 		-- Convert old Eco Record back to Comp
447 
448 		Bom_Bo_Pub.Convert_EcoComp_To_BomComp
449 		(  p_rev_component_rec	=> l_old_rev_component_rec
450 		 , p_rev_comp_unexp_rec	=> l_old_rev_comp_unexp_rec
451 		 , x_bom_component_rec	=> x_old_bom_component_rec
452 		 , x_bom_comp_unexp_rec	=> x_old_bom_comp_unexp_rec
453 		 );
454 
455 	END Check_Existence;
456 
457         /* Component count under a bill cannot exceed 9999 */
458 
459 	PROCEDURE Check_ComponentCount
460 	(  p_bom_component_rec       IN  Bom_Bo_Pub.Bom_Comps_Rec_Type
461 	 , p_bom_comp_unexp_rec      IN  Bom_Bo_Pub.Bom_Comps_Unexposed_Rec_Type
462 	 , x_Mesg_Token_Tbl          IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
463  	 , x_Return_Status           IN OUT NOCOPY VARCHAR2
464 	)
465 	IS
466 
467 	  l_total 		NUMBER := 0;
468        	  l_mesg_token_tbl	Error_Handler.Mesg_Token_Tbl_type;
469 
470 	BEGIN
471 
472           x_return_status := FND_API.G_RET_STS_SUCCESS;
473 
474 /*	Added condition for date through bug 3238782 */
475 
476 	  SELECT count(*) INTO l_total FROM bom_inventory_components WHERE
477 	   bill_sequence_id = p_bom_comp_unexp_rec.bill_sequence_id
478 		and sysdate between effectivity_date and
479                          nvl(disable_date,sysdate + 1);
480 
481 	  IF l_total > BOM_GLOBALS.G_COMPS_LIMIT THEN
482                 g_token_tbl(1).token_name := 'ASSEMBLY_ITEM_NAME';
483                 g_token_tbl(1).token_value :=
484                                 p_bom_component_rec.assembly_item_name;
485               	Error_Handler.Add_Error_Token
486                 ( p_message_name       => 'BOM_COMP_COUNT_EXCEEDS_LIMIT'
487                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
488                 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
489                 , p_Token_Tbl          => g_Token_Tbl
490 		, p_message_type       => 'W' -- Bug 3238782
491                  );
492                 --x_return_status := FND_API.G_RET_STS_ERROR; -- bug 3238782
493           END IF;
494 
495           x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
496 
497 	END Check_ComponentCount;
498 
499 	PROCEDURE Check_Lineage
500 	(  p_bom_component_rec       IN  Bom_Bo_Pub.Bom_Comps_Rec_Type
501 	 , p_bom_comp_unexp_rec      IN  Bom_Bo_Pub.Bom_Comps_Unexposed_Rec_Type
502 	 , x_Mesg_Token_Tbl          IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
503  	 , x_Return_Status           IN OUT NOCOPY VARCHAR2
504 	)
505 	IS
506 	BEGIN
507 		NULL;
508 
509 	END Check_Lineage;
510 
511 	/**********************************************************************
512 	* Procedure	: Check_Acces
513 	* Parameters IN	: Organization_Id
514 	*		  Component Item Id and Name
515 	*		  Message Token Table
516 	* Parameters OUT: Message Token Table
517 	*		  Return Status
518 	* Purpose	: This procedure will check if the user has access to
519 	* 		  the inventory components BOM_ITEM_TYPE.
520 	**********************************************************************/
521 	PROCEDURE Check_Access
522 	(  p_organization_id            IN  NUMBER
523 	 , p_component_item_id          IN  NUMBER
524 	 , p_component_name             IN  VARCHAR2
525 	 , p_Mesg_Token_Tbl             IN  Error_Handler.Mesg_Token_Tbl_Type :=
526                                     Error_Handler.G_MISS_MESG_TOKEN_TBL
527 	 , x_Mesg_Token_Tbl             IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
528 	 , x_Return_Status              IN OUT NOCOPY VARCHAR2
529 	)
530 	IS
531 		l_bom_comp_item_type	NUMBER;
532                 l_OPM_org        VARCHAR2(1);
533 		l_return_status		VARCHAR2(1):=FND_API.G_RET_STS_SUCCESS;
534 		l_mesg_token_tbl	Error_Handler.Mesg_Token_Tbl_type;
535 		l_token_tbl		Error_Handler.Token_Tbl_Type;
536 	BEGIN
537         	/*************************************************************
538         	--
539         	-- Check if the user has access to the revised component's
540         	-- bom_item_type
541         	--
542         	**************************************************************/
543         	SELECT bom_item_type
544            	  INTO l_Bom_comp_item_type
545           	  FROM mtl_system_items
546          	 WHERE inventory_item_id = p_component_item_id
547            	   AND organization_id   = p_organization_id;
548 
549                  SELECT process_enabled_flag
550                    INTO  l_OPM_org
551                    FROM mtl_parameters
552                   WHERE  organization_id   = p_organization_id;
553 
554                  /* Validations for OPM Convergence Project
555                     Model/Option class items are not allowed in OPM organizations*/
556 
557                   IF (l_OPM_org='Y' and l_bom_comp_item_type in ( Bom_Globals.G_MODEL, Bom_Globals.G_OPTION_CLASS))THEN
558                          Error_Handler.Add_Error_Token
559                          (  p_Message_name       => 'BOM_OPM_ORG_MODEL_OC'
560                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
561                           , x_mesg_token_tbl     => l_mesg_token_tbl
562                           );
563                          l_return_status := FND_API.G_RET_STS_ERROR;
564                   END IF;
565 
566         	IF l_bom_comp_item_type NOT IN
567            	(NVL(BOM_Globals.Get_MDL_Item_Access,0),
568             	 NVL(BOM_Globals.Get_OC_Item_Access,0),
569             	 NVL(BOM_Globals.Get_PLN_Item_Access,0),
570           	 NVL(BOM_Globals.Get_STD_Item_Access,0)
571            	)
572         	THEN
573                 	l_token_tbl(1).token_name  := 'COMPONENT_ITEM_NAME';
574                 	l_token_tbl(1).token_value := p_component_name;
575                 	l_token_tbl(2).token_name  := 'BOM_ITEM_TYPE';
576                 	l_token_tbl(2).translate   := TRUE;
577 
578                 	IF l_bom_comp_Item_Type = 1
579                 	THEN
580                       		l_Token_Tbl(2).Token_Value := 'BOM_MODEL';
581                 	ELSIF l_bom_comp_Item_Type = 2
582                 	THEN
583                      	 	l_Token_Tbl(2).Token_Value:='BOM_OPTION_CLASS';
584                 	ELSIF l_bom_comp_Item_Type = 3
585                 	THEN
586                       		l_Token_Tbl(2).Token_Value := 'BOM_PLANNING';
587                 	ELSIF l_bom_comp_Item_Type = 4
588                 	THEN
589                       		l_Token_Tbl(2).Token_Value := 'BOM_STANDARD';
590                 	END IF;
591 
592                 	Error_Handler.Add_Error_Token
593                 	(  p_Message_Name       => 'BOM_BOM_COMP_ACCESS_DENIED'
594                  	 , p_Mesg_Token_Tbl     => l_mesg_token_tbl
595                  	 , x_Mesg_Token_Tbl     => l_mesg_token_tbl
596                 	 , p_Token_Tbl          => l_token_tbl
597                  	);
598                  	l_token_tbl.DELETE(2);
599                  	l_return_status := FND_API.G_RET_STS_ERROR;
600         	END IF;
601 
602 	END Check_Access;
603 
604 	/*******************************************************************
605 	-- Since ENG and BOM Business object share the entities Revised comp.
606 	-- Reference Designator and Substitute Component but use a different
607 	-- Record structure for exposed and unexposed columns, there are two
608 	-- sets of procedures. Internally the Bom Bo will call the ECO's
609 	-- Check_<Funtion> procedure since ECO was coded earlier than BOM BO.
610 	--
611 	-- Parameters to the ECO's BO are revised component where are the
612 	-- parameter to the BOM's BO are Bom Component.
613 	*********************************************************************/
614 
615 	/*****************************************************************
616 	* Procedure     : Check_Required
617 	* Parameters IN : Revised Component exposed column record
618 	* Paramaters OUT: Return Status
619 	*                 Mesg Token Table
620 	* Purpose       : Procedure will check if the user has given all the
621 	*		  required columns for the type of operation user is
622 	*		  trying to perform. If the required columns are not
623 	*		  filled in, then the record would get an error.
624 	********************************************************************/
625 	PROCEDURE Check_Required
626 	(  x_return_status               IN OUT NOCOPY VARCHAR2
627 	 , x_Mesg_Token_Tbl              IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
628 	 , p_rev_component_rec           IN  Bom_Bo_Pub.Rev_Component_Rec_Type
629 	 )
630 	IS
631         	l_Mesg_Token_Tbl        Error_Handler.Mesg_Token_Tbl_Type;
632 	BEGIN
633         	x_return_status := FND_API.G_RET_STS_SUCCESS;
634 
635         	g_token_tbl(1).token_name := 'REVISED_COMPONENT_NAME';
636         	g_token_tbl(1).token_value :=
637 				p_rev_component_rec.component_item_name;
638 
639         	IF ( p_rev_component_rec.acd_type IS NULL OR
640            	     p_rev_component_rec.acd_type = FND_API.G_MISS_NUM
641 		    ) AND
642 		    Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_ECO_BO
643         	THEN
644                 	Error_Handler.Add_Error_Token
645                 	( p_message_name       => 'BOM_ACD_TYPE_MISSING'
646                 	, p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
647                 	, x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
648                 	, p_Token_Tbl          => g_Token_Tbl
649                 	);
650                 	x_return_status := FND_API.G_RET_STS_ERROR;
651         	END IF;
652 
653 		IF ( p_rev_component_rec.start_effective_date IS NULL OR
654 		     p_rev_component_rec.start_effective_date = FND_API.G_MISS_DATE
655 		    ) AND
656 		   ( p_rev_component_rec.from_end_item_unit_number IS NULL OR
657 		     p_rev_component_rec.from_end_item_unit_number = FND_API.G_MISS_CHAR
658 		    )
659 		THEN
660 			Error_Handler.Add_Error_Token
661                         ( p_message_name       => 'BOM_EFFECTIVITY_MISSING'
662                         , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
663                         , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
664                         , p_Token_Tbl          => g_Token_Tbl
665                         );
666                         x_return_status := FND_API.G_RET_STS_ERROR;
667 		END IF;
668 
669         	-- Return the message table.
670 
671         	x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
672 
673 	END Check_Required;
674 
675 
676 	 /*****************************************************************
677 	 * Function	: Control
678 	 * Parameter IN	: Org Level Control
679 	 *		  Subinventory Level Control
680 	 *		  Item Level Control
681 	 * Returns	: Number
682 	 * Purpose	: Control procedure will take the various level control
683 	 *		  values and decide if the Locator is controlled at the
684          *		  org,subinventory or item level. It will also decide
685 	 *		  if the locator is pre-specified or dynamic.
686 	 *******************************************************************/
687  	FUNCTION CONTROL(org_control      IN    number,
688                     sub_control      IN    number,
689                     item_control     IN    number default NULL)
690                     RETURN NUMBER
691 	IS
692   		locator_control number;
693   	BEGIN
694 
695     		IF (org_control = 1) then
696        			locator_control := 1;
697     		ELSIF (org_control = 2) then
698        			locator_control := 2;
699     		ELSIF (org_control = 3) then
700        			locator_control := 3;
701     		ELSIF (org_control = 4) then
702       			IF (sub_control = 1) then
703          			locator_control := 1;
704       			ELSIF (sub_control = 2) then
705          			locator_control := 2;
706       			ELSIF (sub_control = 3) then
707          			locator_control := 3;
708       			ELSIF (sub_control = 5) then
709         			IF (item_control = 1) then
710            				locator_control := 1;
711         			ELSIF (item_control = 2) then
712            				locator_control := 2;
713         			ELSIF (item_control = 3) then
714            				locator_control := 3;
715         			ELSIF (item_control IS NULL) then
716            				locator_control := sub_control;
717         			END IF;
718       			END IF;
719     		END IF;
720 
721     		RETURN locator_control;
722 
723   	END CONTROL;
724 
725 	/*******************************************************************
726 	* Function	: Check_Overlap_Dates (Local function)
727 	* Parameter IN: Effectivity Date
728 	*		  Disable Date
729 	*		  Bill Sequence Id
730 	*		  Component Item Id
731 	* Return	: True if dates are overlapping else false.
732 	* Purpose	: The function will check if the same component is
733 	*		  entered with overlapping dates. Components with
734 	*		  overlapping dates will get a warning.
735 	******************************************************************/
736 	FUNCTION Check_Overlap_Dates
737 		( X_Effectivity_Date DATE,
738 		  X_Disable_Date     DATE,
739                   X_Member_Item_Id   NUMBER,
740                   X_Bill_Sequence_Id NUMBER,
741                   X_Rowid            VARCHAR2,
742                   X_Comp_Seq_Id      NUMBER,
743                   X_Operation_Seq_Num NUMBER)
744 	RETURN BOOLEAN
745   	IS
746   		X_Count NUMBER := 0;
747         	CURSOR X_All_Dates IS
748                 	SELECT 'X' date_available FROM sys.dual
749                  	WHERE EXISTS (
750                                 SELECT 1 from BOM_Inventory_Components
751                                  WHERE Component_Item_Id = X_Member_Item_Id
752                                    AND Bill_Sequence_Id  = X_Bill_Sequence_Id
753                                    AND Operation_Seq_Num = X_Operation_Seq_Num
754 				   --Commented out line below for bug 8839091
755                                    --Uncommented for bug 9780939
756            AND Component_Sequence_Id <> X_Comp_Seq_Id
757 				   AND (( RowId <> X_RowID ) or
758 					(X_RowId IS NULL))
759                                    AND ( X_Disable_Date IS NULL
760                                          OR ( Trunc(X_Disable_Date) >
761 					      Trunc(Effectivity_Date)
762                                             )
763                                         )
764                                    AND ( Trunc(X_Effectivity_Date) <
765 					 Trunc(Disable_Date)
766                                          OR Disable_Date IS NULL
767                                         )
768                                );
769     	BEGIN
770 
771         	FOR X_Date IN X_All_Dates LOOP
772           		X_Count := X_Count + 1;
773           	END LOOP;
774 
775           	-- If count <> 0 that means the current date is overlapping with
776 	  	-- some record.
777                 IF X_Count <> 0 THEN
778                         RETURN TRUE;
779                 ELSE
780                         RETURN FALSE;
781                 END IF;
782 
783 	END Check_Overlap_Dates;
784 
785 
786 	/*******************************************************************
787 	* Function    : Check_Overlap_Numbers (Local function)
788 	* Parameter IN: from end item unit number
789 	*               to end item unit number
790 	*               Bill Sequence Id
791 	*               Component Item Id
792 	* Return      : True if unit numbers are overlapping, else false.
793 	* Purpose     : The function will check if the same component is entered
794 	*               with overlapping unit numbers. Components with
795 	*		overlapping unit numbers will get a warning.
796 	* History	: Created by AS on 07/08/99 as part of unit effectivity
797 	*		  functionality.
798 	*********************************************************************/
799 	FUNCTION Check_Overlap_Numbers
800 		 (  X_From_End_Item_Number VARCHAR2
801                   , X_To_End_Item_Number VARCHAR2
802                   , X_Member_Item_Id   NUMBER
803                   , X_Bill_Sequence_Id NUMBER
804                   , X_Rowid            VARCHAR2
805 		  , X_Comp_Seq_Id      NUMBER
806 		  , X_Operation_Seq_Num NUMBER)
807   	RETURN BOOLEAN
808   	IS
809         	X_Count NUMBER := 0;
810         	CURSOR X_All_Numbers IS
811                 	SELECT 'X' unit_available FROM sys.dual
812                  	WHERE EXISTS (
813                                 SELECT 1 from BOM_Inventory_Components
814                                  WHERE Component_Item_Id = X_Member_Item_Id
815                                    AND Bill_Sequence_Id  = X_Bill_Sequence_Id
816 				   AND Operation_Seq_Num = X_Operation_Seq_Num
817            AND DISABLE_DATE IS NULL --bug:5347036 Consider only enabled components
818 				   AND Component_Sequence_Id <> X_Comp_Seq_Id
819 				   AND (RowId <> X_RowID
820                                         OR X_RowId IS NULL)
821                                    AND (X_To_End_Item_Number IS NULL
822                                         OR X_To_End_Item_Number >
823                                            From_End_Item_Unit_Number)
824                                    AND (X_From_End_Item_Number <
825                                          To_End_Item_Unit_Number
826                                          OR To_End_Item_Unit_Number IS NULL
827                                         )
828                                );
829     	BEGIN
830 
831           	FOR X_Unit IN X_All_Numbers LOOP
832                 	X_Count := X_Count + 1;
833           	END LOOP;
834 
835           	-- If count <> 0 that means the unit numbers are overlapping
836                 IF X_Count <> 0 THEN
837                         RETURN TRUE;
838                 ELSE
839                         RETURN FALSE;
840                 END IF;
841 
842    	END Check_Overlap_Numbers;
843 
844 
845 	/********************************************************************
846 	* Function	: Verify_Item_Attributes
847 	* Prameters IN	: Organization_Id
848 	*		  Component Item Id
849 	*		  Assembly Item Id
850 	*		  Eng Bill flag for Assembly
851 	* Parameters OUT: Mesg Token_Tbl
852 	* Return	: True if no attributes are invalid and False otherwise
853 	* Purpose	: The function will validate the following BOM Matrix.
854 	*----------------------------------------------------------------------
855 	*                                    Component Types
856 	*----------------------------------------------------------------------
857 	*Bill            PTO     ATO     PTO   ATO             ATO    PTO   Std
858 	*Types           Model   Model   OC    OC   Planning   Item   Item  Item
859 	*-------------  --------------------------------------------------------
860 	*PTO Model       Yes     Yes     Yes   No   No         Yes    Yes   Yes
861 	*ATO Model       No      Yes     No    Yes  No         Yes    No    Yes
862 	*PTO OC          Yes     Yes     Yes   No   No         Yes    Yes   Yes
863 	*ATO OC          No      Yes     No    Yes  No         Yes    No    Yes
864 	*Planning        Yes     Yes     Yes   Yes  Yes        Yes    Yes   Yes
865 	*ATO Item        No      No      No    No   No         Yes    No    Yes
866 	*PTO Item        No      No      No    No   No          No    Yes   Yes
867 	*Standard Item   No      No      No    No   No         Yes    No    Yes
868 	*Config Item     No      Yes     No    Yes  No         Yes    No    Yes
869 	*
870 	**********************************************************************/
871 	FUNCTION Verify_Item_Attributes
872 	(  p_Mesg_token_tbl IN  Error_Handler.Mesg_Token_Tbl_Type
873          , x_Mesg_Token_Tbl IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type)
874 	RETURN BOOLEAN
875 	IS
876 		dummy	NUMBER;
877 		l_allow_eng_comps VARCHAR2(10);
878 		l_Mesg_Token_Tbl	Error_Handler.Mesg_Token_Tbl_Type;
879 
880 	BEGIN
881 		l_Mesg_Token_Tbl := p_Mesg_Token_Tbl;
882 
883 --		dbms_output.put_line
884 --		('Within the Verify Item Attributes procedure . . . ');
885 
886 		-- Verify Eng flag for Assembly and Component
887 		l_allow_eng_comps := fnd_profile.value('ENG:ALLOW_ENG_COMPS');
888 		IF (g_Assy_Assembly_Type = 1 and  -- Bill is manufacturing
889 		-- Introduced new global variable to hold assembly_type of
890 		-- bill header.
891 		--bug: 4161794
892 	   	   g_Comp_Eng_Flag = 'Y' and  -- and component is Engineering
893                    (l_allow_eng_comps is NULL or l_allow_eng_comps <> '1'))
894 		THEN
895 			Error_Handler.Add_Error_Token
896 			(  x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
897 			 , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
898 			 , p_message_name    => 'BOM_ASSY_COMP_ENG_FLG_MISMATCH'
899 			 , p_Token_Tbl	     => g_Token_Tbl
900 			 );
901 			x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
902 			RETURN FALSE;
903 		END IF;
904 
905 		/************************************************************
906 		-- Verify ATO MODEL OR ATO OPTION CLASS Assembly(not config)
907 		-- Attributes ATO Model does not allow
908 		-- 1. Planning Components
909 		-- 2. PTO Model or PTO Option Class
910 		-- 3. PTO Standard
911 		-- If the Assembly is ATO Standard, then it does not allow the
912 		-- above three types and
913 		-- 4. ATO Model or
914 		-- 5. ATO Option Class
915 		**************************************************************/
916 		IF ( ( ( g_Assy_Item_Type IN
917 			  (Bom_Globals.G_MODEL, Bom_Globals.G_OPTION_CLASS, Bom_Globals.G_STANDARD)  AND
918 	         	 g_Assy_ATO_flag  = 'Y' AND
919 		 	 g_Assy_Config = 'N'
920 	        	 )
921 	      	      ) AND
922 	      	      ( g_Comp_Item_Type = Bom_Globals.G_PLANNING OR
923 	        	( g_Comp_Item_Type IN
924 				(Bom_Globals.G_MODEL, Bom_Globals.G_OPTION_CLASS, Bom_Globals.G_STANDARD) AND
925 	          		g_Comp_PTO_Flag  = 'Y'
926 	        	 )
927 	       	       )
928 	    	    ) OR
929 	    	   (
930 			g_Assy_Item_Type = Bom_Globals.G_STANDARD AND
931 			g_Assy_ATO_flag = 'Y'    AND
932 			g_Assy_Config = 'N' 	 AND
933 			( g_Comp_Item_Type IN (Bom_Globals.G_MODEL, Bom_Globals.G_OPTION_CLASS) AND
934 		  	  g_Comp_ATO_Flag = 'Y'
935 			 )
936 	    	    )
937 		THEN
938 			IF g_Assy_Item_Type = Bom_Globals.G_MODEL
939 			THEN
940 				g_Token_Tbl(2).Token_Name := 'ITEM_TYPE';
941 				g_Token_Tbl(2).Token_Value := 'BOM_MODEL_TYPE';
942 				g_Token_Tbl(2).Translate := TRUE;
943 			ELSIF g_Assy_Item_Type = Bom_Globals.G_OPTION_CLASS
944 			THEN
945 				g_Token_Tbl(2).Token_Name := 'ITEM_TYPE';
946                         	g_Token_Tbl(2).Token_Value :=
947 						'BOM_OPTION_CLASS_TYPE';
948                         	g_Token_Tbl(2).Translate := TRUE;
949 			ELSE
950 				g_Token_Tbl(2).Token_Name := 'ITEM_TYPE';
951                         	g_Token_Tbl(2).Token_Value :=
952 							'BOM_STANDARD_TYPE';
953                         	g_Token_Tbl(2).Translate := TRUE;
954 			END IF;
955 			g_token_tbl(3).token_name := 'REVISED_ITEM_NAME';
956 			g_token_tbl(3).token_value :=
957 					g_rev_component_rec.revised_item_name;
958 
959 			IF g_Assy_Item_Type IN ( Bom_Globals.G_MODEL, Bom_Globals.G_OPTION_CLASS)
960 			THEN
961 				Error_Handler.Add_Error_Token
962 				( p_message_name    => 'BOM_ATO_PROP_MISMATCH'
963 		 		, p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
964 		 		, x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
965 		 		, p_Token_Tbl	    => g_Token_Tbl
966                 		);
967 			ELSE
968                         	Error_Handler.Add_Error_Token
969                         	( p_message_name => 'BOM_ATO_STD_PROP_MISMATCH'
970                        		 , p_Mesg_Token_Tbl      => l_Mesg_Token_Tbl
971                        		 , x_Mesg_Token_Tbl      => l_Mesg_Token_Tbl
972                        		 , p_Token_Tbl           => g_Token_Tbl
973                        		 );
974 			END IF;
975 			g_Token_Tbl.DELETE(2);
976 			g_Token_Tbl.DELETE(3);
977 
978 			x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
979                 	RETURN FALSE;
980 
981 		/*************************************************************
982 		-- If the Assembly is a Config Item i.e. ATO with Base_Item_Id
983 		-- NOT NULL then it will allow
984 		-- 1. ATO Standard or
985 		-- 2. Standard item
986 		-- and
987 		-- 1. ATO Model
988 		-- 2. ATO Option Class
989 		-- only if the assemly is Phantom is Wip_Supply_Type is 6
990 		-- validation is changed by vhymavat for bug 2595175
991 		*************************************************************/
992 		ELSIF g_Assy_ATO_Flag = 'Y' AND
993 	      		g_Assy_Config   = 'Y'
994 		THEN
995 			IF( g_rev_component_rec.Wip_Supply_Type <> 6 AND
996 		   	  g_Comp_Item_Type IN
997 				(Bom_Globals.G_MODEL, Bom_Globals.G_OPTION_CLASS)
998 		       		AND
999 		       	    g_Comp_ATO_Flag = 'Y'
1000 		      	   )
1001 
1002 			THEN
1003 				g_token_tbl(2).token_name:='REVISED_ITEM_NAME';
1004 				g_token_tbl(2).token_value :=
1005 					g_rev_component_rec.revised_item_name;
1006 
1007 				Error_Handler.Add_Error_Token
1008                 		( p_message_name => 'BOM_CFG_SUPPLY_NOT_PHANTOM'
1009                  		, p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1010                  		, x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1011                  		, p_Token_Tbl          => g_Token_Tbl
1012                 		);
1013 				g_token_tbl.delete(2);
1014 
1015 				x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
1016 				RETURN FALSE;
1017 
1018 		      	/****************************************************
1019 		       	-- Assembly is Config item with Wip Supply of Phantom
1020 		       	-- but the component item types do not match
1021 		       	****************************************************/
1022 			ELSIF
1023 		      	NOT
1024 		      	( ( g_Comp_Item_Type IN
1025 			      (Bom_Globals.G_MODEL, Bom_Globals.G_OPTION_CLASS, Bom_Globals.G_STANDARD)
1026                           	AND
1027                              g_Comp_ATO_Flag = 'Y'
1028                             ) OR
1029                             g_Comp_Item_Type = Bom_Globals.G_STANDARD
1030                          )
1031 			THEN
1032 		 		g_token_tbl(2).token_name:= 'REVISED_ITEM_NAME';
1033                         	g_token_tbl(2).token_value :=
1034                                 	g_rev_component_rec.revised_item_name;
1035 
1036 				Error_Handler.Add_Error_Token
1037                         	( p_message_name => 'BOM_CONFIG_PROP_MISMATCH'
1038                        		 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1039                        		 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1040                        		 , p_Token_Tbl          => g_Token_Tbl
1041                        		 );
1042 
1043 				x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
1044 				g_token_tbl.delete(2);
1045                         	RETURN FALSE;
1046 			END IF;
1047 
1048 		/*************************************************************
1049 		-- Verify PTO MODEL or OPTION CLASS Assembly Attributes
1050 	     	-- PTO Models do not allow
1051 		-- 1. ATO Option Class and
1052 		-- 2. Planning components
1053 		**************************************************************/
1054 		ELSIF g_Assy_Item_Type IN ( Bom_Globals.G_MODEL, Bom_Globals.G_OPTION_CLASS) AND
1055 	      		g_Assy_PTO_flag  = 'Y' AND
1056 	      		( g_Comp_Item_Type = Bom_Globals.G_PLANNING OR
1057 				( g_Comp_Item_Type = Bom_Globals.G_OPTION_CLASS AND
1058 		  	          g_Comp_ATO_flag  = 'Y'
1059 			 	 )
1060 	       	         )
1061 		THEN
1062 			IF g_Assy_Item_Type = Bom_Globals.G_MODEL
1063 			THEN
1064                         	g_Token_Tbl(2).Token_Name := 'ITEM_TYPE';
1065                         	g_Token_Tbl(2).Token_Value := 'BOM_MODEL_TYPE';
1066                         	g_Token_Tbl(2).Translate := TRUE;
1067                 	ELSIF g_Assy_Item_Type = Bom_Globals.G_OPTION_CLASS
1068                 	THEN
1069                         	g_Token_Tbl(2).Token_Name := 'ITEM_TYPE';
1070                         	g_Token_Tbl(2).Token_Value :=
1071 					'BOM_OPTION_CLASS_TYPE';
1072                         	g_Token_Tbl(2).Translate := TRUE;
1073 			END IF;
1074 
1075 			g_token_tbl(3).token_name  := 'REVISED_ITEM_NAME';
1076 			g_token_tbl(3).token_value :=
1077 				g_rev_component_rec.revised_item_name;
1078 
1079 			Error_Handler.Add_Error_Token
1080 			(  p_message_name	=> 'BOM_MODEL_OC_PROP_MISMATCH'
1081 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
1082 			 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
1083 			 , p_Token_Tbl		=> g_Token_Tbl
1084                 	 );
1085 
1086 			g_Token_Tbl.DELETE(2);
1087 			g_token_tbl.delete(3);
1088 			x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
1089                 	RETURN FALSE;
1090 
1091 			/****************************************************
1092 			--
1093 			-- PTO STandard will only allow Standard or PTO Standard
1094 			--
1095 			*****************************************************/
1096 		ELSIF g_Assy_Item_Type = Bom_Globals.G_STANDARD AND
1097               	      g_Assy_PTO_Flag  = 'Y' AND
1098 	      	      NOT
1099 	      	      ( g_Comp_Item_Type = Bom_Globals.G_STANDARD AND
1100 			      ( ( g_Comp_PTO_Flag = 'Y' AND
1101 		    	          g_comp_ATO_Flag = 'N'
1102 		   		 ) OR
1103 		   		 ( g_comp_ATO_Flag = 'N' AND
1104 		     		   g_comp_PTO_Flag = 'N'
1105 		   		  ) OR  --added for BOM ER 9946990
1106                                   (g_comp_ATO_Flag = 'Y' AND
1107 		     		   g_comp_PTO_Flag = 'N' AND
1108                                    nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) = 1
1109 		   		  )
1110 		 	       )
1111 	      		)
1112      /* Commenting for Bug 2627352
1113               	      NOT ( ( g_Comp_Item_Type = Bom_Globals.G_STANDARD AND
1114                       	      g_Comp_PTO_flag  = 'Y'
1115                     	     ) OR
1116                     	     ( g_Comp_Item_Type = Bom_Globals.G_STANDARD)
1117                   	    )
1118     */
1119         	THEN
1120 		g_token_tbl(2).token_name  := 'REVISED_ITEM_NAME';
1121 		g_token_tbl(2).token_value :=
1122 					g_rev_component_rec.revised_item_name;
1123                 Error_Handler.Add_Error_Token
1124 		(  p_message_name	=> 'BOM_PTO_STD_PROP_MISMATCH'
1125 		 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
1126 		 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
1127 		 , p_Token_Tbl		=> g_Token_Tbl
1128                  );
1129 		x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
1130 		g_token_tbl.delete(2);
1131                 RETURN FALSE;
1132 
1133 		/************************************************************
1134 		--
1135 		-- A STANDARD bill will only allow ATO Standard and Standard
1136 		-- items as components
1137 		--
1138 		*************************************************************/
1139 		ELSIF g_Assy_Item_Type = Bom_Globals.G_STANDARD AND
1140 	      	      g_Assy_PTO_Flag = 'N' AND
1141 	      	      g_Assy_ATO_Flag = 'N' AND
1142 	      	      NOT
1143 	      	      ( g_Comp_Item_Type = Bom_Globals.G_STANDARD AND
1144 			      ( ( g_Comp_ATO_Flag = 'Y' AND
1145 		    	          g_comp_PTO_Flag = 'N'
1146 		   		 ) OR
1147 		   		 ( g_comp_ATO_Flag = 'N' AND
1148 		     		   g_comp_PTO_Flag = 'N'
1149 		   		  )
1150 		 		)
1151 	      		)
1152 		THEN
1153 			g_token_tbl(2).token_name  := 'REVISED_ITEM_NAME';
1154                 	g_token_tbl(2).token_value :=
1155                                         g_rev_component_rec.revised_item_name;
1156 		 	Error_Handler.Add_Error_Token
1157                 	(  p_message_name       => 'BOM_STANDARD_PROP_MISMATCH'
1158                 	 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1159                 	 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
1160                 	 , p_Token_Tbl          => g_Token_Tbl
1161                 	 );
1162                 	x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
1163 			g_token_tbl.delete(2);
1164                 	RETURN FALSE;
1165 
1166 		END IF;
1167 
1168                 /**************************************************************
1169                 -- ATP Validation for components is changed and now there is no restriction
1170                 -- Comment out by MK on 06/05/2001
1171 
1172 		-- Once the matrix is verified then check the ATP Components
1173 		-- and ATP Check attributes
1174 
1175 IF BOM_Globals.get_debug = 'Y' THEN
1176      error_handler.write_debug('Check the ATP Components and ATP Check attribute.' );
1177      error_handler.write_debug('Assy ATP Comp Flag : ' || g_Assy_ATP_Comp_flag  );
1178      error_handler.write_debug('Comp ATP Check Flag : ' || g_Comp_Atp_Check_Flag );
1179 END IF;
1180 
1181          	IF ( g_Assy_ATP_Comp_flag = 'N' AND
1182                      g_Comp_Atp_Check_Flag = 'Y'
1183 	    	    )
1184 		THEN
1185 			g_token_tbl(2).token_name  := 'REVISED_ITEM_NAME';
1186                 	g_token_tbl(2).token_value :=
1187                                         g_rev_component_rec.revised_item_name;
1188 
1189 			Error_Handler.Add_Error_Token
1190 			(  p_message_name	=> 'BOM_ASSY_COMP_ATP_MISMATCH'
1191 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
1192 			 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
1193 			 , p_Token_Tbl		=> g_Token_Tbl
1194                  	);
1195 			x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
1196 			g_token_tbl.delete(2);
1197       			RETURN FALSE;  -- ATP Item Attribute Invalid
1198 		END IF;
1199 --		dbms_output.put_line('End of Item Attribute Validation . . .');
1200 
1201 IF BOM_Globals.get_debug = 'Y' THEN
1202      error_handler.write_debug('Check the ATP Components and ATP Check attribute.' );
1203 END IF;
1204 
1205                 **************************************************************/
1206 
1207    	-- If control comes till this point then it would mean a success of
1208    	-- attribute validation. Hence,
1209 
1210    		x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
1211    		RETURN TRUE;
1212 
1213 	END Verify_Item_Attributes;
1214 
1215 	/********************************************************************
1216 	* Function	: Check_PTO_ATO_For_Optional (Local Function)
1217 	* Returns	: 0 if Success
1218 	*		  1 if Optional value is incorrect for ATO/PTO Model/OC
1219 	*		  2 if Optional value is incorrect for Plan/Stdd Bill
1220 	* Purpose	: Function will verify the following things:
1221 	*		  1. Optional must be NO (2) if Bill if Pln or Standard
1222 	*		  2. If Bill is PTO Model or OC and component is
1223 	*		     ATO Std with no base mdl then Optional must be Yes
1224 	*	 	     (1)
1225 	***********************************************************************/
1226 	--
1227 	-- Check if the PTO and ATO flags of Assembly and Component for the
1228 	-- Optional flag to be correct.
1229 	--
1230 
1231 	FUNCTION  Check_PTO_ATO_for_Optional
1232 	RETURN NUMBER
1233 	IS
1234 	BEGIN
1235 
1236 --		dbms_output.put_line
1237 -- 		('Value of Optional when checking ATO / PTO . . .');
1238 
1239 		IF ( g_Assy_PTO_flag = 'Y' 			    AND
1240                     --following clause modified for BOM ER 9946990
1241 	     	    ( (g_Assy_Item_Type = Bom_Globals.G_MODEL and nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) <> 1) OR g_Assy_Item_Type = Bom_Globals.G_OPTION_CLASS) AND
1242 	     	     g_Comp_ATO_flag = 'Y' 			    AND
1243 	     	     g_Comp_Item_Type = Bom_Globals.G_STANDARD 		    AND
1244 	     	     g_Comp_Config = 'N' 			    AND
1245 	     	     g_Rev_Component_Rec.optional = 2
1246 	    	     )
1247 		THEN
1248 			RETURN 1;
1249 		ELSIF ( g_Assy_Item_Type IN (Bom_Globals.G_STANDARD, Bom_Globals.G_PLANNING)  AND
1250 	        	g_Rev_Component_Rec.optional = 1
1251 	       		)
1252 		THEN
1253 			RETURN 2;
1254 		ELSE
1255 			RETURN 0;
1256 		END IF;
1257 
1258 	END Check_PTO_ATO_for_Optional;
1259 
1260 	/********************************************************************
1261 	* Function	: Check_Planning_Percent
1262 	* Returns	: 0 for Success else 1, 2, or 3 for errors
1263 	* Purpose	: The function will verify the following:
1264 	*		  Planning percent can be <> 100 only if
1265 	*		  1. Bill is Planning else RETURN error code 1 Or
1266 	*		  2. Bill is a Model/Option Class and Component is
1267 	*		     optional Or else return error code 2.
1268 	*		  3. Bill is a Model/Option Class and component is not
1269 	*		     Optional and forecase control is = 2
1270 	*		     (Consume and Derive)
1271 	********************************************************************/
1272 	FUNCTION Check_Planning_Percent RETURN NUMBER
1273 	IS
1274 	BEGIN
1275 		IF g_rev_component_rec.planning_percent <> 100 THEN
1276 			IF g_Assy_Item_Type = Bom_Globals.G_STANDARD THEN
1277 				RETURN 1;
1278 			ELSIF ( g_Assy_Item_Type IN (Bom_Globals.G_MODEL, Bom_Globals.G_OPTION_CLASS)
1279 				AND
1280 				g_rev_component_rec.optional <> 1 AND
1281 				g_Comp_ATO_Forecast_Control  <> 2
1282 		       		)
1283 			THEN
1284 				RETURN 2;
1285         --Commented out condition below for bug 7392603
1286 			/*ELSIF ( g_Assy_Item_Type IN (Bom_Globals.G_MODEL, Bom_Globals.G_OPTION_CLASS)
1287 				AND
1288                         	( g_rev_component_rec.optional = 1 AND              -- changed for Bug3163342
1289 		 	  	  g_Comp_ATO_Forecast_Control <> 2
1290 			         )
1291                        		)
1292 			THEN
1293 				RETURN 3;*/
1294 			ELSE
1295 				RETURN 0;
1296 			END IF;
1297 		ELSE
1298 			RETURN -1;
1299 		END IF;
1300 
1301 	END Check_Planning_Percent;
1302 
1303 
1304 	/*******************************************************************
1305 	* Function	: Chk_Req_For_Rev_Or_Shp
1306 	* Returns	: 1 if Required for Revenue is invalid
1307 	*		  2 if Required to Ship is invalid
1308 	*		  3 if both are incorrect
1309 	*		  0 if both are correct
1310 	* Purpose	: Function will verify the following:
1311 	*		  Required for Revenue / Required to Ship must be NO if
1312 	*		  Replenish_To_Order_Flag is 'Y' for the Bill
1313 	********************************************************************/
1314 	FUNCTION Chk_Req_For_Rev_Or_Shp
1315 	RETURN NUMBER
1316 	IS
1317 	BEGIN
1318 
1319 		IF g_rev_component_rec.required_for_revenue = 1 AND
1320 	   	   g_rev_component_rec.required_to_ship = 2 AND
1321 	   	   g_Assy_ATO_Flag = 'Y'
1322 		THEN
1323 			RETURN 1;
1324 		ELSIF g_rev_component_rec.required_to_ship = 1 AND
1325 	      	      g_rev_component_rec.required_for_revenue = 2 AND
1326 	      	      g_Assy_ATO_Flag = 'Y'
1327 		THEN
1328 			RETURN 2;
1329 		ELSIF g_rev_component_rec.required_to_ship = 1 AND
1330 	      	      g_rev_component_rec.required_for_revenue = 1 AND
1331 	              g_Assy_ATO_Flag = 'Y'
1332 		THEN
1333 			RETURN 3;
1334 		ELSE
1335 			RETURN 0;
1336 		END IF;
1337 
1338 	END Chk_Req_For_Rev_Or_Shp;
1339 
1340 
1341 	-- Local Function for Product Family Members
1342 	/********************************************************************
1343         *Function       : CheckUnique_PF_Member
1344         *Returns        : 1 This component exits in an other Product Family
1345         *		  Bill
1346         *                 0 This component does not exist in other product
1347         *		  family Bill.
1348         *Purpose        : Function will verify if the component exists in
1349         *                 other product family Bills.
1350         **********************************************************************/
1351 	FUNCTION CheckUnique_PF_Member RETURN NUMBER
1352 	IS
1353 		Pf_Item_Id	Number ;
1354 	BEGIN
1355               --dbms_output.put_line('Withing Function CheckUnique_PF_Member . . .');
1356 
1357 		IF g_Assy_Item_Type = Bom_Globals.G_PRODUCT_FAMILY
1358 		THEN
1359 			BEGIN
1360 				SELECT product_family_item_id
1361 				INTO   Pf_Item_Id
1362 				FROM   mtl_system_items_b
1363 				WHERE  inventory_item_id = g_rev_comp_Unexp_rec.component_item_id
1364 				AND    organization_id = g_rev_comp_Unexp_rec.organization_id;
1365 
1366 				If (Pf_Item_Id is NULL) THEN
1367 					RETURN 0;
1368 				ELSE
1369 					RETURN 1;
1370 				END IF;
1371 			END;
1372 		END IF;
1373 		RETURN 0; -- This should never happen.  CheckUnique_PF_Member should be called if item type is PF.
1374 
1375 	END CheckUnique_PF_Member;
1376 
1377 	-- Local Function Check_ATP
1378 	/********************************************************************
1379 	*Function	: Check_ATP
1380 	*Returns	: 1 if ATP invalid because qty is -ve
1381 	*		  2 if ATP invalid because qty is fractional
1382 	*		  0 if the ATP value is valid.
1383 	*Purpose	: Function will verify if the Check_Atp value is correct
1384 	*		  wrt to the check_atp and atp_components_flag of the
1385 	*		  parent and component. It will also check if the
1386 	*		  component quantity is greater than 0 for the
1387 	*		  check_atp to be yes.
1388 	**********************************************************************/
1389 	FUNCTION Check_ATP RETURN NUMBER
1390 	IS
1391 	BEGIN
1392 --		dbms_output.put_line('Withing Function Check_ATP . . .');
1393 
1394     		IF g_Assy_ATP_Comp_flag IN ('Y','R','C') AND
1395        		   g_Comp_ATP_Check_flag in ('Y', 'C', 'R')
1396     		THEN
1397 			IF g_rev_component_rec.quantity_per_assembly < 0 THEN
1398 				RETURN 1;
1399 			ELSIF round(g_rev_component_rec.quantity_per_assembly)
1400 			      <>  g_rev_component_rec.quantity_per_assembly
1401 			THEN
1402 				RETURN 2;
1403 			ELSE
1404 				RETURN 0;
1405 			END IF;
1406     		ELSE
1407 			RETURN 1;
1408     		END IF;
1409 
1410 	END Check_ATP;
1411 
1412 	/********************************************************************
1413 	* Function	: Check_Mutually_Exclusive
1414 	* Returns	: 0 if the Mutually exlusive values is correct
1415 	*		  1 if BOM is not Installed
1416 	*		  2 if Revised Component is Model or Option Class
1417 	* Purpose	: Will verify the value of mutually exclusive options
1418 	*		  column by verifying if BOM is Installed and the
1419 	*		  component is either a Model or Option Class.
1420 	*		  In only this case the column can have a value of
1421 	*		  Yes (1).
1422 	*********************************************************************/
1423 	--Local function to validate Mutually_Exclusive_Option
1424 	FUNCTION Check_Mutually_Exclusive RETURN NUMBER
1425 	IS
1426 		X_Bom_Status	VARCHAR2(80);
1427 		X_Industry	VARCHAR2(80);
1428 		X_Install_Bom	BOOLEAN;
1429 	BEGIN
1430 --		dbms_output.put_Line
1431 --		('Checking Mutually Exclusive for value : ' ||
1432 --		to_char(g_rev_component_rec.Mutually_Exclusive));
1433 
1434 		IF g_rev_component_rec.Mutually_Exclusive = 1 THEN
1435  			X_install_bom := Fnd_Installation.Get
1436 				 ( appl_id     => '702',
1437                                    dep_appl_id => '702',
1438                                    status      => X_bom_status,
1439                                    industry    => X_industry);
1440 			IF X_install_bom AND
1441 		   		g_Comp_Item_Type IN (Bom_Globals.G_MODEL, Bom_Globals.G_OPTION_CLASS)
1442 			THEN
1443 				RETURN 0;
1444 			ELSIF g_Comp_Item_Type NOT IN (Bom_Globals.G_MODEL, Bom_Globals.G_OPTION_CLASS)
1445 			THEN
1446 				RETURN 2;
1447 			ELSE
1448 				RETURN 1;
1449 			END IF;
1450 		ELSE
1451 			RETURN 0;
1452 		END IF;
1453 
1454 	END Check_Mutually_Exclusive;
1455 
1456 
1457 	/******************************************************************
1458 	* Function	: Check_Supply_Type
1459 	* Returns	: TRUE if the supply type is correct, false otherwise
1460 	* Purpose	: Function will verify if the Wip_supply_Type value is
1461 	*		  is correct by doing the following checks:
1462 	*		  1. Wip_Supply_Type = 6 (Phantom), then component must
1463 	*		     have a bill, else log a warning.
1464 	*		  2. Wip_Supply_Type must be Phantom if the component is
1465 	*		     Model or Option Class
1466 	********************************************************************/
1467 	FUNCTION Check_Supply_Type
1468 	 (  p_Mesg_Token_Tbl IN  Error_Handler.Mesg_Token_Tbl_Type
1469 	  , x_Mesg_token_tbl IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type)
1470 	RETURN BOOLEAN
1471 	IS
1472 		l_Mesg_Token_Tbl Error_Handler.Mesg_Token_Tbl_Type;
1473 	BEGIN
1474 		l_Mesg_token_Tbl := p_Mesg_Token_Tbl;
1475 
1476 		IF g_rev_component_rec.WIP_Supply_Type IS NOT NULL
1477 		THEN
1478 			IF g_rev_component_rec.wip_supply_type = 6 /* PHANTOM */
1479 			THEN
1480 		  	BEGIN
1481 				-- If Phantom then Component must be a Bill
1482 		   		SELECT 'Valid'
1483 		     		INTO l_dummy
1484 		     		FROM bom_bill_of_materials
1485 		    		WHERE assembly_item_id =
1486 			  		g_rev_comp_unexp_rec.component_item_id
1487 		      		AND organization_id  =
1488 					  g_rev_comp_unexp_rec.organization_id
1489 				AND rownum < 2; -- bug 2986752
1490 
1491 		    		x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
1492 		    		RETURN TRUE;
1493 
1494 		    		EXCEPTION
1495 				   WHEN NO_DATA_FOUND THEN
1496             				Error_Handler.Add_Error_Token
1497 					(  p_message_name   => 'BOM_NO_BILL'
1498 					 , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1499 					 , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1500                                  	 , p_message_type   => 'W'
1501 					);
1502 					x_Mesg_token_tbl := l_Mesg_Token_Tbl;
1503 					RETURN TRUE;
1504 					-- Since this is a warning return true
1505 			END; -- Check if phantom block
1506 
1507 /* bug 2681317 this restriction is removed as per CTO team's suggestions ref1588889
1508 			ELSE
1509 				-- If component is Model/OC then
1510 				-- WIP_Supply Type must be Phantom
1511 				IF g_Comp_Item_Type IN
1512 					(l_MODEL, l_OPTION_CLASS) AND
1513 			   	   g_rev_component_rec.wip_supply_type <> 6
1514 				THEN
1515                                     Error_Handler.Add_Error_Token
1516                                     ( p_message_name => 'BOM_WIP_SUPPLY_PHANTOM'
1517                                      ,p_Mesg_Token_Tbl=> l_Mesg_token_Tbl
1518                                      ,x_Mesg_Token_Tbl=> l_Mesg_Token_Tbl
1519                                      ,p_token_tbl     => g_Token_Tbl
1520                                      , p_message_type   => 'W'
1521                                      );
1522 				     x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
1523 --				     dbms_output.put_line
1524 --				('Returing False Check Supply Type....');
1525 
1526                                      RETURN TRUE;
1527 				END IF;
1528 */
1529 	       		END IF;
1530 		END IF;
1531 	x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
1532 	RETURN TRUE;
1533 	END Check_Supply_Type;
1534 
1535 	-- Local Function to verify Minimum Quantity.
1536 	FUNCTION Check_Min_Quantity RETURN BOOLEAN
1537 	IS
1538 	BEGIN
1539 --		dbms_output.put_line('Low Quantity : ' ||
1540 --		to_char(g_rev_component_rec.minimum_allowed_quantity));
1541 --		dbms_output.put_line('Component Quantity : ' ||
1542 --		to_char(g_rev_component_rec.quantity_per_assembly));
1543 		IF NVL(g_rev_component_rec.minimum_allowed_quantity, 0) >
1544 	           NVL(g_rev_component_rec.quantity_per_assembly, 0) THEN
1545                 	RETURN FALSE;
1546 		ELSE
1547 			RETURN TRUE;
1548 		END IF;
1549 
1550 	END Check_Min_Quantity;
1551 
1552 	-- Local function to verify High Quantity
1553 	FUNCTION Check_Max_Quantity RETURN BOOLEAN
1554 	IS
1555 	BEGIN
1556 --		dbms_output.put_line('High Quantity : ' ||
1557 --		to_char(g_rev_component_rec.maximum_allowed_quantity));
1558 --        	dbms_output.put_line('Component Quantity : ' ||
1559 --		to_char(g_rev_component_rec.quantity_per_assembly));
1560 
1561         	IF NVL(g_rev_component_rec.maximum_allowed_quantity, 0) <
1562 		   NVL(g_rev_component_rec.quantity_per_assembly, 0) THEN
1563                 	RETURN FALSE;
1564 		ELSE
1565 			RETURN TRUE;
1566         	END IF;
1567 
1568 	END Check_Max_Quantity;
1569 
1570 	-- Local function to check supply subinventory
1571 	FUNCTION Check_Supply_SubInventory RETURN BOOLEAN
1572 	IS
1573 		l_allow_expense_to_asset VARCHAR2(10);
1574 		l_RestrictSubInventory VARCHAR2(1);
1575 		l_InventoryAsset	VARCHAR2(1);
1576 
1577 		CURSOR c_Restrict_SubInv_Asset IS
1578 		SELECT locator_type
1579 	  	FROM mtl_item_sub_ast_trk_val_v
1580 	 	WHERE inventory_item_id = g_rev_comp_Unexp_rec.component_item_id
1581 	   	AND organization_id = g_rev_comp_Unexp_rec.organization_id
1582 	   	AND secondary_inventory_name =
1583 	       		g_rev_component_rec.supply_subinventory;
1584 
1585 		CURSOR c_Restrict_SubInv_Trk IS
1586 		SELECT locator_type
1587 	  	FROM mtl_item_sub_trk_val_v
1588 	 	WHERE inventory_item_id = g_rev_comp_Unexp_rec.component_item_id
1589 	   	AND organization_id   = g_rev_comp_Unexp_rec.organization_id
1590 	   	AND secondary_inventory_name =
1591 	       		g_rev_component_rec.supply_subinventory;
1592 
1593 		CURSOR c_SubInventory_Asset IS
1594 		SELECT locator_type
1595 	  	FROM mtl_sub_ast_trk_val_v
1596 	 	WHERE organization_id = g_rev_comp_Unexp_rec.organization_id
1597 	   	AND secondary_inventory_name =
1598 	       		g_rev_component_rec.supply_subinventory;
1599 
1600 		CURSOR c_Subinventory_Tracked IS
1601 		SELECT locator_type
1602 	  	FROM mtl_subinventories_trk_val_v
1603 	 	WHERE organization_id = g_rev_comp_Unexp_rec.organization_id
1604 	   	AND secondary_inventory_name =
1605 	       		g_rev_component_rec.supply_subinventory;
1606 
1607 	BEGIN
1608 
1609 --		dbms_output.put_line('Checking Subinv value . . . ' ||
1610 --		g_rev_component_rec.supply_subinventory);
1611 
1612 		l_allow_expense_to_asset := fnd_profile.value
1613 				    ('INV:EXPENSE_TO_ASSET_TRANSFER');
1614 
1615 		-- Get Restrict_Subinventory_Flag for the Item
1616 		SELECT DECODE(restrict_subinventories_code, 1, 'Y', 'N'),
1617 	       		inventory_asset_flag
1618 	  	INTO l_RestrictSubInventory,
1619 	       	     l_InventoryAsset
1620 	  	FROM mtl_system_items
1621 	 	WHERE inventory_item_id = g_rev_comp_Unexp_rec.component_item_id
1622 	   	AND organization_id   = g_rev_comp_Unexp_rec.organization_id;
1623 
1624 		IF l_RestrictSubInventory = 'Y' THEN
1625 
1626 --			dbms_output.put_line('Subinventory is Restricted...');
1627 
1628 			IF l_allow_expense_to_asset = '1' THEN
1629 
1630 --				dbms_output.put_line
1631 --				('Allow Expense to Asset 1 . . .');
1632 
1633 				OPEN c_Restrict_SubInv_Trk;
1634 				FETCH c_Restrict_SubInv_Trk INTO
1635 					l_Sub_Locator_Control;
1636 --				dbms_output.put_line('Within locator check ' ||
1637 --				to_char(l_Sub_Locator_Control));
1638 
1639 				IF c_Restrict_SubInv_Trk%Found THEN
1640 					CLOSE c_Restrict_SubInv_Trk;
1641 					RETURN TRUE;
1642 				ELSE
1643 --					dbms_output.put_line
1644 --					('Sub loc in Subinv: ' ||
1645 --					to_char(l_Sub_Locator_Control));
1646 
1647 					CLOSE c_Restrict_SubInv_Trk;
1648 					RETURN FALSE;
1649 				END IF;
1650 			ELSE
1651 				IF l_InventoryAsset = 'Y' THEN
1652 
1653 --					dbms_output.put_line
1654 --					('Inventory Asset Yes . . .');
1655 
1656 					OPEN c_Restrict_SubInv_Asset;
1657                         		FETCH c_Restrict_SubInv_Asset INTO
1658 				      		l_Sub_Locator_Control;
1659                         		IF c_Restrict_SubInv_Asset%Found THEN
1660                                 		CLOSE c_Restrict_SubInv_Asset;
1661                                 		RETURN TRUE;
1662                         		ELSE
1663                                 		CLOSE c_Restrict_SubInv_Asset;
1664                                 		RETURN FALSE;
1665                         		END IF;
1666 				ELSE
1667 --					dbms_output.put_line
1668 --					('Inventory Asset No . . .');
1669 
1670 					OPEN c_Restrict_SubInv_Trk;
1671                         		FETCH c_Restrict_SubInv_Trk INTO
1672 				      		l_Sub_Locator_Control;
1673                         		IF c_Restrict_SubInv_Trk%Found THEN
1674                                 		CLOSE c_Restrict_SubInv_Trk;
1675                                 		RETURN TRUE;
1676                         		ELSE
1677                                 		CLOSE c_Restrict_SubInv_Trk;
1678                                 		RETURN FALSE;
1679                         		END IF;
1680 
1681 				END IF;
1682 			END IF;
1683 		ELSE
1684 
1685 --			dbms_output.put_line('Subinventory not restricted...');
1686 
1687 			IF l_Allow_Expense_To_Asset = '1' THEN
1688 
1689 --				dbms_output.put_line
1690 --				('Allow Expense to Asset = 1 ...');
1691 
1692 				OPEN c_SubInventory_Tracked;
1693 				FETCH c_SubInventory_Tracked INTO
1694 					l_Sub_Locator_Control;
1695 				IF c_SubInventory_Tracked%FOUND THEN
1696 					CLOSE c_SubInventory_Tracked;
1697 					RETURN TRUE;
1698 				ELSE
1699 					CLOSE c_SubInventory_Tracked;
1700 					RETURN FALSE;
1701 				END IF;
1702 			ELSE
1703 				IF l_InventoryAsset = 'Y' THEN
1704 --					dbms_output.put_line
1705 --					('Inventory Asset = Y . . .');
1706 
1707 					OPEN c_SubInventory_Asset;
1708 					FETCH c_SubInventory_Asset INTO
1709 				      		l_Sub_Locator_Control;
1710 					IF c_SubInventory_Asset%FOUND THEN
1711 						CLOSE c_SubInventory_Asset;
1712 						RETURN TRUE;
1713 					ELSE
1714 						CLOSE c_SubInventory_Asset;
1715 						RETURN FALSE;
1716 					END IF;
1717 				ELSE
1718 --					dbms_output.put_line
1719 --					('Fetched from Subinventory Tracked..');
1720 
1721 					OPEN c_Subinventory_Tracked;
1722 					FETCH c_Subinventory_Tracked INTO
1723 				      		l_Sub_Locator_Control;
1724 					IF c_SubInventory_Tracked%FOUND THEN
1725 						CLOSE c_Subinventory_Tracked;
1726 						RETURN TRUE;
1727 					ELSE
1728 						CLOSE c_Subinventory_Tracked;
1729 						RETURN FALSE;
1730 					END IF;
1731 				END IF;
1732 			END IF;
1733 		END IF;
1734 	END Check_Supply_SubInventory;
1735 
1736 	-- Local function to verify locators
1737 	FUNCTION Check_Locators RETURN BOOLEAN
1738 	IS
1739   		Cursor CheckDuplicate is
1740         	SELECT 'checking for duplicates' dummy
1741          	FROM sys.dual
1742         	WHERE EXISTS (
1743           		SELECT null
1744             		FROM mtl_item_locations
1745            		WHERE organization_id =
1746 				g_rev_comp_Unexp_rec.organization_id
1747              		AND inventory_location_id =
1748 				g_rev_comp_Unexp_rec.supply_locator_id
1749              		AND subinventory_code <>
1750 				g_rev_component_rec.supply_subinventory
1751 				);
1752 
1753 		x_Control NUMBER;
1754   		l_Success	BOOLEAN;
1755 	 BEGIN
1756 
1757 		l_org_locator_control := 0 ;
1758 		l_item_locator_control := 0;
1759 
1760 
1761 --		dbms_output.put_line('Within Check Locators function. . .');
1762 
1763 		-- Get Value of Org_Locator and item_Locator.
1764 		SELECT stock_locator_control_code
1765 	  	INTO l_org_locator_control
1766           	FROM mtl_parameters
1767        		WHERE organization_id = g_rev_comp_Unexp_rec.organization_id;
1768 
1769 		-- Get Value of Item Locator
1770   		SELECT location_control_code
1771 	  	INTO l_item_locator_control
1772 	  	FROM mtl_system_items
1773 	 	WHERE organization_id = g_rev_comp_Unexp_rec.organization_id
1774 	   	AND inventory_item_id = g_rev_comp_Unexp_rec.component_item_id;
1775 
1776 		-- Get if locator is restricted or unrestricted
1777 
1778         	SELECT RESTRICT_LOCATORS_CODE
1779           	INTO l_item_loc_restricted
1780           	FROM mtl_system_items
1781          	WHERE organization_id = g_rev_comp_Unexp_rec.organization_id
1782            	AND inventory_item_id = g_rev_comp_Unexp_rec.component_item_id;
1783 
1784 		--
1785   		-- When a SubInventory is validated, then depending on the
1786 		-- Cursor being
1787 		-- used in the Check_SubInventory procedure, the value of
1788 		-- l_Sub_Locator_Control would be set.
1789 		-- Else if there is no change in subinv
1790   		-- then excute subinv check.
1791   		--
1792 
1793 --		dbms_output.put_line('Checking Subinventory locator control,
1794 --		calling Check_Supply_SubInventory . . .');
1795 
1796 
1797 IF Bom_Globals.Get_Debug = 'Y' THEN
1798      Error_Handler.Write_Debug('L_SUB_LOC_CONTROL :' || to_number( l_Sub_Locator_Control)  );
1799      Error_Handler.Write_Debug('Now calling Check SupplySubInv: '|| g_rev_component_rec.supply_subinventory );
1800 END IF;
1801 
1802 		IF l_Sub_Locator_Control IS NULL AND
1803      		   g_rev_component_rec.supply_subinventory IS NOT NULL
1804 		THEN
1805 
1806 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
1807      ('Now calling Check SupplySubInv. . .');
1808 END IF;
1809 
1810 
1811 			l_Success := Check_Supply_SubInventory;
1812   		END IF;
1813 
1814 -- 		dbms_output.put_line
1815 --		('After calling Check_Supply_SubInventory in Check_Locators..');
1816 
1817         /*
1818 		Locator is not required.  But that validation should not be combined with Sub Inventory
1819 		level locator control value.  So commenting this validation.  Bug 5032528
1820   		--
1821   		-- Locator cannot be NULL is if locator restricted
1822   		--
1823   		IF g_rev_comp_Unexp_rec.supply_locator_id IS NULL
1824      		AND l_item_loc_restricted = 1
1825   		THEN
1826 			l_locator_control := 4;
1827 			RETURN FALSE;
1828   		ELSIF g_rev_comp_Unexp_rec.supply_locator_id IS NULL
1829         		AND l_item_loc_restricted = 2
1830 		THEN
1831 			RETURN TRUE;
1832 		END IF;
1833         */
1834 --		dbms_output.put_line('Within Check locators . . .');
1835 
1836 		IF l_org_locator_control  is not null AND
1837      		   l_sub_locator_control  is not null AND
1838      		   l_item_locator_control is not null
1839 		THEN
1840 --			dbms_output.put_line
1841 --			('Org _Control: ' || to_char(l_org_locator_control));
1842 --			dbms_output.put_line('Sub _Control: ' ||
1843 --			to_char(l_sub_locator_control));
1844 --			dbms_output.put_line('Item Control: ' ||
1845 --			to_char(l_item_locator_control));
1846 
1847      			x_control := Control
1848 			( Org_Control  => l_org_locator_control,
1849         		   Sub_Control  => l_sub_locator_control,
1850         		   Item_Control => l_item_locator_control
1851 			  );
1852 
1853      			l_locator_control := x_control;
1854 			-- Variable to identify if the dynamic loc.
1855 			-- Message must be logged.
1856 
1857      			IF x_Control = 1
1858 		        -- Added for bug 5032528, If locator is set, when locator control is none then only throw error
1859 		         AND g_rev_comp_Unexp_rec.supply_locator_id IS NOT NULL THEN  -- No Locator Control
1860  				RETURN FALSE;  -- No Locator and Locator Id is
1861 					       -- supplied then raise Error
1862      			ELSIF x_Control = 2 OR x_Control = 3 THEN   -- PRESPECIFIED
1863 			/*
1864 			 * Added OR x_Control = 3 as part of FP fix for bug 3624635
1865 			 * Even for dynamic locators if the locators are
1866 			 * in the system then we should be allowing.
1867 			 */
1868 			BEGIN
1869 
1870 --				dbms_output.put_line
1871 --				('Checking when x_control returned 2 and ' ||
1872 --				' item locator is ' ||
1873 --				to_char(l_item_locator_control));
1874 
1875 	    			-- If restrict locators is Y then check in
1876 				-- mtl_secondary_locators if the item is
1877 				-- assigned to the subinventory/location
1878 				-- combination If restrict locators is N then
1879 				-- check that the locator exists
1880 	    			-- and is assigned to the subinventory and this
1881 				-- combination is found in mtl_item_locations.
1882 
1883 	    			IF l_item_loc_restricted = 1
1884 					-- Restrict Locators  = YES
1885 	    			THEN
1886 
1887 					--** Check for restrict Locators YES**
1888 					SELECT 'Valid'
1889 		  			INTO l_dummy
1890 		  			FROM mtl_item_locations mil,
1891 		       		             mtl_secondary_locators msl
1892                	 			WHERE msl.inventory_item_id =
1893 		       			g_rev_comp_Unexp_rec.component_item_id
1894                	   			AND msl.organization_id =
1895 		       			g_rev_comp_Unexp_rec.organization_id
1896                	   			AND msl.subinventory_code =
1897 		       			g_rev_component_rec.supply_subinventory
1898 		   			AND msl.secondary_locator =
1899 		       			g_rev_comp_Unexp_rec.supply_locator_id
1900 		   			AND mil.inventory_location_id =
1901 						msl.secondary_locator
1902 		   			AND mil.organization_id =
1903 					msl.organization_id
1904 		   			AND NVL(mil.disable_date, SYSDATE+1) >
1905 						SYSDATE ;
1906 
1907 					-- If no exception is raised then the
1908 					-- Locator is Valid
1909 					RETURN TRUE;
1910 	     			ELSE
1911 					--**Check for restrict Locators NO**
1912 --					dbms_output.put_line
1913 --					('Item restrict locators is NO . . .');
1914 
1915 					SELECT 'Valid'
1916                   			INTO l_dummy
1917                   			FROM mtl_item_locations mil
1918                  			WHERE mil.subinventory_code 	 =
1919 		       			g_rev_component_rec.supply_subinventory
1920                    			AND mil.inventory_location_id =
1921 		       			g_rev_comp_Unexp_rec.supply_locator_id
1922 		   			AND mil.organization_id 	 =
1923 		       			g_rev_comp_Unexp_rec.organization_id
1924 		   			AND NVL(mil.DISABLE_DATE, SYSDATE+1) >
1925 					SYSDATE;
1926 
1927                 			-- If no exception is raised then the
1928 					-- Locator is Valid
1929                 			RETURN TRUE;
1930 
1931 	     			END IF;
1932 
1933 				EXCEPTION
1934 					WHEN NO_DATA_FOUND THEN
1935 						RETURN FALSE;
1936 			END; -- x-control=2 OR x_Control = 3 Ends
1937                         /* Commented as part of FP fix for bug 3624635
1938      			ELSIF x_Control = 3 THEN
1939 				-- DYNAMIC LOCATORS ARE NOT ALLOWED IN OI.
1940 				-- Dynamic locators are not allowed in open
1941 				-- interface, so raise an error if the locator
1942 				-- control is dynamic.
1943 				l_locator_control := 3;
1944 				RETURN FALSE;
1945                         */
1946      			ELSE
1947 --				dbms_output.put_line
1948 --				('Finally returing a true value . . .');
1949                 		RETURN TRUE;
1950 
1951      			END IF; -- X_control Checking Ends
1952 
1953   		ELSE
1954 			RETURN TRUE;
1955   		END IF;  -- If Locator Control check Ends.
1956 
1957 	END Check_Locators;
1958 
1959         /*******************************************************************
1960         * Function      : Check_Routing_Exists
1961         * Returns       : TRUE if routing exists for revised item
1962         *                 FALSE if no routing exists for the revised item
1963         * Purpose       : Verify the following:
1964         *                 Function Check_Routing_Exists checks if there is a
1965         *                 routing for the revised item.
1966         *                 If there is no routing, the user can only enter an
1967         *                 Operation Sequence Number of 1. Otherwise, the user
1968         *                 enter a NOT 1 value to indicate the routing operation.
1969         * History 	: Created by AS on 08/20. This validation modifies the
1970 			  original Operation Sequence Number validation slightly.
1971 	**********************************************************************/
1972 
1973 	FUNCTION Check_Routing_Exists
1974 	RETURN BOOLEAN
1975 	IS
1976                 l_alternate_bom_designator VARCHAR2(10) := NULL;
1977 
1978                 CURSOR GetAlternate IS
1979                 SELECT alternate_bom_designator
1980                 FROM bom_bill_of_materials
1981                 WHERE bill_sequence_id = g_rev_comp_unexp_rec.bill_sequence_id;
1982 
1983   		CURSOR CheckRouting IS
1984    		SELECT 'x'
1985      		FROM bom_operation_sequences bos, bom_operational_routings bor
1986     		WHERE bor.common_routing_sequence_id = bos.routing_sequence_id
1987       		AND bor.organization_id = g_rev_comp_unexp_rec.organization_id
1988       		AND bor.assembly_item_id = g_rev_comp_unexp_rec.revised_item_id
1989       		AND nvl(bor.alternate_routing_designator,
1990               		nvl(l_alternate_bom_designator, 'NONE')) =
1991           		nvl(l_alternate_bom_designator, 'NONE');
1992 
1993 		l_dummy VARCHAR2(1);
1994 
1995 	BEGIN
1996 		IF g_rev_comp_unexp_rec.bill_sequence_id IS NULL
1997 		THEN
1998 			RETURN FALSE;
1999 		END IF;
2000 
2001 		OPEN GetAlternate;
2002 		FETCH GetAlternate INTO l_alternate_bom_designator;
2003 		Close GetAlternate;
2004 
2005 	        OPEN CheckRouting;
2006                 FETCH CheckRouting INTO l_dummy;
2007                 IF CheckRouting%FOUND THEN
2008                         CLOSE CheckRouting;
2009                         RETURN TRUE;
2010                 ELSE
2011                         CLOSE CheckRouting;
2012                         RETURN FALSE;
2013                 END IF;
2014 	END Check_Routing_Exists;
2015 
2016 	/*******************************************************************
2017 	* Function	: Check_Op_Seq
2018 	* Parameters	: l_unit_controlled_item - indicates whether revised
2019         *		  item is unit or date controlled
2020 	* Returns	: 0 if new op_seq or op_seq is valid
2021 	* 		  1 if new_op_seq or op_seq does not exist
2022 	*		  2 if new_op_seq or op_seq is not unique
2023 	                  3 if comp Operations exist with same op seq num
2024 	* Purpose	: Verify the following:
2025 	* 		  Function Check_Op_Seq will check if the op_seq_num
2026 	*		  or the new_op_seq_num exists.
2027 	*		  If they exist, then it will go ahead and check if
2028 	*		  the the same component does not already exist with
2029 	*		  the same op_seq_num
2030 	**********************************************************************/
2031 	FUNCTION Check_Op_Seq
2032 	( l_unit_controlled_item	BOOLEAN
2033 	)
2034 	RETURN NUMBER
2035 	IS
2036 
2037 /* Bug 2573061
2038 The cursor Valid_Op_Seq is checking whether the operation_seq_num of the
2039 alternate_bill is existing in the alternate_routing or not.  If alternating
2040 routing not exists for that alternate bill then it is returning error.
2041 But it should not do that.  If alternate routing not exists it should validate
2042 the operation_seq_nums from the primary routing.  so modified the cursor.
2043 */
2044 
2045 		CURSOR Valid_Op_Seq (p_eco_for_production NUMBER)  IS
2046        		SELECT 'Valid' valid_op_seq
2047          	  FROM
2048 /*                     bom_operational_routings bor,
2049               	       bom_operation_sequences bos
2050         	 WHERE bor.assembly_item_id =
2051 				g_rev_comp_Unexp_rec.revised_item_id
2052           	   AND bor.organization_id  =
2053 				g_rev_comp_Unexp_rec.organization_id
2054           	   AND NVL(bor.alternate_routing_designator, 'NONE') =
2055               	       NVL(g_rev_component_rec.alternate_bom_code, 'NONE')
2056           	   AND bos.routing_sequence_id = bor.common_routing_sequence_id
2057 */
2058                        bom_operation_sequences  bos
2059                  WHERE
2060                    bos.routing_sequence_id =
2061                    (
2062                       select common_routing_sequence_id
2063                       from bom_operational_routings
2064                       where assembly_item_id = g_rev_comp_Unexp_rec.revised_item_id
2065                             and organization_id = g_rev_comp_Unexp_rec.organization_id
2066                             and nvl(alternate_routing_designator,
2067                                   nvl(g_rev_component_rec.alternate_bom_code, 'NONE')) =
2068                                 nvl(g_rev_component_rec.alternate_bom_code, 'NONE')
2069                             and (g_rev_component_rec.alternate_bom_code is null
2070                                or (g_rev_component_rec.alternate_bom_code is not null
2071                                    and (alternate_routing_designator =
2072                                           g_rev_component_rec.alternate_bom_code
2073                                         or not exists
2074                                           (select null
2075                                            from bom_operational_routings bor2
2076                                            where bor2.assembly_item_id =
2077                                                  g_rev_comp_Unexp_rec.revised_item_id
2078                                                  and bor2.organization_id = g_rev_comp_Unexp_rec.organization_id
2079                                                  and bor2.alternate_routing_designator =
2080                                                  g_rev_component_rec.alternate_bom_code
2081                                            )
2082                                         )
2083                                     )
2084                                  )
2085                    )
2086 	      	   AND bos.operation_seq_num =
2087 			decode(g_rev_component_rec.new_operation_sequence_number,
2088 		      	      NULL,
2089 		      	      g_rev_component_rec.Operation_Sequence_Number,
2090 		      	      g_rev_component_rec.new_Operation_sequence_number
2091 		     	      )
2092                     -- commented following AND condition for bug 7339077
2093                     -- AND nvl(trunc(disable_date), trunc(sysdate)+1)  > trunc(sysdate)
2094                       -- added following AND conditon for bug 7339077
2095                       AND nvl(disable_date, trunc(sysdate)+1) >= sysdate
2096 
2097 
2098                    AND (   (     p_eco_for_production = 2
2099                             AND  nvl(bos.eco_for_production, 2) <> 1
2100                             )
2101                         OR (    p_eco_for_production = 1
2102                             AND (   bos.implementation_date IS NOT NULL
2103                                     OR ( bos.revised_item_sequence_id
2104                                          = g_rev_comp_unexp_rec.revised_item_sequence_id)
2105                                 )
2106                             )
2107                         ) ;
2108 
2109                    -- Added above conditions for Eco for Production by MK 02/02/2001
2110                    -- Form has this validation in LOV for New Operation Sequence Number filed
2111 
2112                 l_eco_for_production NUMBER ; -- Added by MK 02/02/2001
2113 
2114 		CURSOR c_Op_Seq_Date_Used IS
2115 			/* Check same component is not already effective */
2116 		SELECT 'Already Used' op_seq_used
2117 	  	  FROM bom_inventory_components bic
2118          	 WHERE bic.bill_sequence_id    =
2119 			g_rev_comp_Unexp_rec.bill_sequence_id
2120            	   AND bic.component_item_id   =
2121 		       g_rev_comp_Unexp_rec.component_item_id
2122            	   AND bic.operation_seq_num   =
2123 	       	       decode(g_rev_component_rec.new_operation_sequence_number,
2124                        	      NULL,
2125                        	      g_rev_component_rec.operation_sequence_number,
2126                        	      g_rev_component_rec.new_operation_sequence_number
2127                       	      )
2128 		   /* Added extra condition to accomodate bill components
2129 		   */
2130        AND bic.component_sequence_id <>
2131               g_rev_comp_Unexp_rec.component_sequence_id
2132        /*added extra condition to avoid validation against the same comp*/
2133 		   AND (trunc(bic.effectivity_date)
2134 				    < trunc(g_rev_component_rec.start_effective_date)
2135            	   	AND nvl(trunc(bic.disable_date),
2136 				 trunc(g_rev_component_rec.start_effective_date) + 2)
2137             			    > trunc(g_rev_component_rec.start_effective_date));
2138 
2139                 CURSOR c_Op_Seq_Unit_Used IS
2140                         /* Check same component is not already effective */
2141                 SELECT 'Already Used' op_seq_used
2142                   FROM bom_inventory_components bic
2143                  WHERE bic.bill_sequence_id    =
2144                         g_rev_comp_Unexp_rec.bill_sequence_id
2145                    AND bic.component_item_id   =
2146                        g_rev_comp_Unexp_rec.component_item_id
2147                    AND bic.operation_seq_num   =
2148                        decode(g_rev_component_rec.new_operation_sequence_number,
2149                               NULL,
2150                               g_rev_component_rec.operation_sequence_number,
2151                               g_rev_component_rec.new_operation_sequence_number
2152                               )
2153 		   AND DECODE(g_rev_component_rec.new_effectivity_date,
2154                               NULL,
2155                               g_rev_component_rec.start_effective_date,
2156                               g_rev_component_rec.new_effectivity_date
2157                               ) between bic.effectivity_date AND NVL(bic.disable_date, SYSDATE)
2158                    AND bic.component_sequence_id <> g_rev_comp_unexp_rec.component_sequence_id
2159                         /* Added extra condition to accomodate bill components
2160                         */
2161                    AND (bic.from_end_item_unit_number
2162                                 <= g_rev_component_rec.from_end_item_unit_number
2163                              AND NVL(bic.to_end_item_unit_number,
2164                                 g_rev_component_rec.from_end_item_unit_number)
2165                                 >= g_rev_component_rec.from_end_item_unit_number);
2166 	/* bug:4240031 Checking for the existence of Component Operation
2167 	 * with the same Op_seq_num
2168 	*/
2169 		CURSOR c_Comp_Operation_Exist IS
2170 		SELECT 'Already Exists' op_seq_exists
2171 		 FROM  bom_component_operations bco
2172 		 WHERE bco.component_sequence_id =
2173 		                g_rev_comp_Unexp_rec.component_sequence_id
2174 		  AND  bco.operation_seq_num =
2175 		              decode(g_rev_component_rec.new_operation_sequence_number,
2176                                      NULL,
2177                                      g_rev_component_rec.operation_sequence_number,
2178                                      g_rev_component_rec.new_operation_sequence_number
2179                                     );
2180 
2181 	BEGIN
2182 
2183 		-- If a record is found then it will mean that though
2184 		-- the Operation Sequence exists in the Routings table
2185 		-- a component already exist with that operation sequence abd
2186 		-- Effectivity date so it cannot be inserted. So return an error
2187 		-- hence, this function will return a false.
2188 
2189                 l_eco_for_production  := NVL(Bom_Globals.Get_Eco_For_Production,2)  ;
2190 
2191 		FOR l_valid_op IN  Valid_Op_Seq(l_eco_for_production)  LOOP
2192 			-- if operation_seq exists in Operation_Sequences then
2193 			-- verify that the same component does not already exist
2194 			-- for that bill with the same operation seq.
2195 		-- bug :4240031
2196 		     OPEN c_Comp_Operation_Exist;
2197 		     FETCH c_Comp_Operation_Exist INTO l_dummy;
2198 		     IF c_Comp_Operation_Exist%FOUND THEN
2199 		         CLOSE c_Comp_Operation_Exist;
2200 			 RETURN 3;
2201 	             ELSE
2202 		         CLOSE c_Comp_Operation_Exist;
2203 		     END IF;
2204                 -- bug:4240031 ends
2205 		    IF l_unit_controlled_item
2206 		    THEN
2207 			FOR l_Op_Seq_Unit_Used IN c_Op_Seq_Unit_Used LOOP
2208 				RETURN 2;
2209 				-- Op_seq_num or the new_op_seq_num not unique
2210 			END LOOP;
2211 		    ELSE
2212 			FOR l_Op_Seq_Date_Used IN c_Op_Seq_Date_Used LOOP
2213                                 RETURN 2;
2214                                 -- Op_seq_num or the new_op_seq_num not unique
2215                         END LOOP;
2216           --For date eff bills, editable common bills may exist. The operation seq num
2217           --must be valid for those bils too.
2218           IF NOT BOMPCMBM.Check_Op_Seq_In_Ref_Boms(p_src_bill_seq_id => g_rev_comp_Unexp_rec.bill_sequence_id
2219                                                   , p_op_seq => nvl(g_rev_component_rec.new_operation_sequence_number,
2220                                                                     g_rev_component_rec.operation_sequence_number)
2221                                                   )
2222           THEN RETURN 4;
2223           END IF;
2224 
2225 		    END IF;
2226 
2227 --			dbms_output.put_line
2228 --			('Check Op Seq returing with Success (0) ');
2229 
2230 	            RETURN 0;  -- op_seq_num or new_op_seq_num is valid
2231 
2232 		END LOOP;
2233 
2234 		RETURN 1;
2235 		-- op_seq_num or new_op_seq_num is invalid
2236 		-- i.e does not exist in bom_oper_sequences
2237 
2238 	END Check_Op_Seq;
2239 
2240         /*
2241         ** Function Check_Unit_Number
2242         ** Will be called when the user is attempting to modify a unit effective BOM
2243         ** If the new unit number is creating a component with overlapping effectivity
2244         ** then this method will return 1
2245         ** else it will return 0
2246         */
2247         FUNCTION Check_Unit_Number
2248         RETURN NUMBER
2249         IS
2250                 CURSOR c_Unit_Num_Used IS
2251                         /* Check same component is not already effective */
2252                 SELECT 'Already Used' unit_num_used
2253                   FROM bom_inventory_components bic
2254                  WHERE bic.bill_sequence_id    =
2255                         g_rev_comp_Unexp_rec.bill_sequence_id
2256                    AND bic.component_item_id   =
2257                        g_rev_comp_Unexp_rec.component_item_id
2258                    AND bic.operation_seq_num   =
2259                        decode(g_rev_component_rec.new_operation_sequence_number,
2260                               NULL,
2261                               g_rev_component_rec.operation_sequence_number,
2262                               g_rev_component_rec.new_operation_sequence_number
2263                               )
2264                    AND DECODE(g_rev_component_rec.new_effectivity_date,
2265                               NULL,
2266                               g_rev_component_rec.start_effective_date,
2267                               g_rev_component_rec.new_effectivity_date
2268                               ) between bic.effectivity_date AND NVL(bic.disable_date, SYSDATE)
2269                    AND bic.component_sequence_id <> g_rev_comp_unexp_rec.component_sequence_id
2270                         /* Added extra condition to accomodate bill components
2271                         */
2272                    AND (( bic.from_end_item_unit_number
2273                                 <= DECODE(g_rev_component_rec.new_from_end_item_unit_number,FND_API.G_MISS_CHAR, /* bug 8314145 */
2274                                           g_rev_component_rec.from_end_item_unit_number,
2275                                           NULL, g_rev_component_rec.from_end_item_unit_number,
2276                                           g_rev_component_rec.new_from_end_item_unit_number
2277                                           )
2278                              AND NVL(bic.to_end_item_unit_number,g_rev_component_rec.from_end_item_unit_number)
2279                                 >= g_rev_component_rec.from_end_item_unit_number
2280                           )
2281                           OR
2282                           ( bic.from_end_item_unit_number
2283                                 > DECODE(g_rev_component_rec.new_from_end_item_unit_number,FND_API.G_MISS_CHAR, /* bug 8314145 */
2284                                           g_rev_component_rec.from_end_item_unit_number,
2285                                           NULL, g_rev_component_rec.from_end_item_unit_number,
2286                                           g_rev_component_rec.new_from_end_item_unit_number
2287                                           )
2288                              AND NVL(bic.to_end_item_unit_number,g_rev_component_rec.from_end_item_unit_number)
2289                                 <= g_rev_component_rec.from_end_item_unit_number
2290                           )
2291                         );
2292 
2293         BEGIN
2294 
2295                 FOR is_overlap_unit_num IN c_Unit_Num_Used LOOP
2296                         RETURN 1;
2297                 END LOOP;
2298 
2299 
2300                 -- else return 0 for success
2301 
2302                 return 0;
2303 
2304         END Check_Unit_Number;
2305 
2306        /*----------------- bug:4240031 creating a new function-------------*/
2307        /*
2308         * Bug:4240031 :Adding a function to validate the case of changing the Attribute Optional.
2309 	* If there are component operations defined for the component then the value of the
2310 	* Attribtue Optional can not be changed from Yes to No
2311        */
2312        FUNCTION Check_Optional_For_Comp_Ops RETURN BOOLEAN
2313        IS
2314 		  CURSOR c_Change_Optional IS
2315 		  SELECT 'Exist' there_Exist
2316 		  FROM   bom_component_operations bco,
2317 		         bom_components_b comp
2318 		  WHERE  bco.component_sequence_id = comp.component_sequence_id
2319 		  AND    comp.component_sequence_id = g_rev_comp_Unexp_rec.component_sequence_id
2320 		  AND    comp.optional = 1
2321 		  AND    g_rev_component_rec.Optional = 2;
2322        BEGIN
2323                 OPEN c_Change_Optional;
2324 		FETCH c_Change_Optional INTO l_dummy;
2325 		IF c_Change_Optional%FOUND THEN
2326 		      CLOSE c_Change_Optional;
2327 		      RETURN TRUE;
2328 		ELSE
2329 		      CLOSE c_Change_Optional;
2330 		      RETURN FALSE;
2331 		END IF;
2332       END Check_Optional_For_Comp_Ops;
2333 
2334       /*--------------------Changes for bug:4240031 end-----------------*/
2335 
2336 	FUNCTION Check_Optional RETURN BOOLEAN
2337 	IS
2338 		CURSOR c_CheckOptional IS
2339 		SELECT 'Valid' is_Valid
2340 	  	FROM mtl_system_items assy,
2341 	       	     mtl_system_items comp
2342 	       WHERE assy.organization_id = g_rev_comp_Unexp_rec.organization_id
2343 	   	 AND assy.inventory_item_id =
2344 					g_rev_comp_Unexp_rec.revised_item_id
2345 	   	 AND comp.organization_id = g_rev_comp_Unexp_rec.organization_id
2346 	   	 AND comp.inventory_item_id =
2347 					g_rev_comp_Unexp_rec.component_item_id
2348 	   	 AND ( ( assy.bom_item_type IN ( Bom_Globals.G_PLANNING, Bom_Globals.G_STANDARD)
2349 	                 AND g_rev_component_rec.optional = 2  /* NO */
2350 	                )
2351 	    	  	OR
2352 		  	( assy.bom_item_type IN ( Bom_Globals.G_MODEL, Bom_Globals.G_OPTION_CLASS)
2353 		    	  AND assy.pick_components_flag = 'Y'
2354 					/* PTO Model or PTO Option Class */
2355 		          AND comp.bom_item_type = Bom_Globals.G_STANDARD
2356 		          AND comp.replenish_to_order_flag = 'Y'
2357 		          AND comp.base_item_id IS NULL
2358 		          AND g_rev_component_rec.Optional = 1
2359 		        )
2360 		      );
2361 
2362 	BEGIN
2363 		-- Optional must be 2 if Bill is Planning or Standard.
2364 		-- If the Bill is PTO Model or PTO OC and the Component
2365 		-- is an ATO Std item with no Base Model then Optional must be 1
2366 		-- Else it can be anything from 1 and 2.
2367 
2368 
2369 
2370 		OPEN c_CheckOptional;
2371 		FETCH c_CheckOptional INTO l_dummy;
2372 		IF c_CheckOptional%FOUND THEN
2373 			CLOSE c_CheckOptional;
2374 			RETURN TRUE;
2375 		ELSE
2376 			CLOSE c_CheckOptional;
2377 			RETURN FALSE;
2378 		END IF;
2379 
2380 	END Check_Optional;
2381 
2382 
2383 	/******************************************************************
2384 	* Function	: Check_Common_Other_Orgs
2385 	* Return	: True if component exists in other orgs, else False
2386 	* Purpose	: If component is being added to a bill that is being
2387 	*		  referenced by items (bills) in other orgs
2388 	*	          (as a common), the component must exist in those orgs
2389 	*		  as well, with the correct item attributes.
2390 	*		  This function will verify this and will return True
2391 	*		  on success and false on failure.
2392 	*********************************************************************/
2393 	FUNCTION Check_Common_Other_Orgs
2394 	RETURN NUMBER
2395 	IS
2396   		l_other_orgs   BOOLEAN;
2397       l_invalid_bill NUMBER;
2398       l_allow_eng_comps varchar2(10) := nvl(fnd_profile.value('ENG:ALLOW_ENG_COMPS'), '2'); -- Bug 6274872
2399   		CURSOR bom_enabled_in_other_orgs IS
2400   		SELECT 1
2401         	FROM BOM_BILL_OF_MATERIALS bom
2402         	WHERE bom.source_bill_sequence_id =
2403 	      		g_rev_comp_Unexp_rec.bill_sequence_id
2404           	  AND bom.organization_id <>
2405 					g_rev_comp_Unexp_rec.organization_id
2406           	  AND NOT EXISTS (SELECT 1
2407                           	    FROM MTL_SYSTEM_ITEMS msi
2408                           	   WHERE msi.organization_id =
2409 						bom.organization_id
2410                             	     AND msi.inventory_item_id =
2411 					 g_rev_comp_Unexp_rec.component_item_id
2412                             	     AND msi.bom_enabled_flag = 'Y'  -- Uncommented for bug 5925020
2413 			  	  );
2414 
2415 		CURSOR in_other_orgs IS
2416 		SELECT 1
2417 	  	FROM BOM_BILL_OF_MATERIALS bom
2418          	WHERE bom.source_bill_sequence_id =
2419                		g_rev_comp_Unexp_rec.bill_sequence_id
2420            	AND bom.organization_id <> g_rev_comp_Unexp_rec.organization_id
2421            	AND NOT EXISTS (SELECT 1
2422                           	FROM MTL_SYSTEM_ITEMS msi
2423                           	WHERE msi.organization_id = bom.organization_id
2424                             	AND msi.inventory_item_id =
2425                                 	g_rev_comp_Unexp_rec.component_item_id
2426 			 	);
2427 
2428 		CURSOR eng_flag_in_other_orgs
2429 		IS
2430 		SELECT 1
2431 	  	FROM BOM_BILL_OF_MATERIALS bom
2432         	WHERE bom.source_bill_sequence_id =
2433               		g_rev_comp_Unexp_rec.bill_sequence_id
2434           	AND bom.organization_id <> g_rev_comp_Unexp_rec.organization_id
2435           	AND NOT EXISTS (SELECT 1
2436                           	FROM MTL_SYSTEM_ITEMS msi
2437                           	WHERE msi.organization_id = bom.organization_id
2438                             	AND msi.inventory_item_id =
2439                                 	g_rev_comp_Unexp_rec.component_item_id
2440                             	AND msi.bom_enabled_flag = 'Y'    -- Uncommented for bug 5925020
2441 
2442 				AND (( bom.assembly_type = 1 AND
2443                                    	((msi.eng_item_flag = 'N' and l_allow_eng_comps = '2' ) or l_allow_eng_comps = '1' ) -- Bug 6274872
2444                                   	)
2445                                   	OR bom.assembly_type = 2
2446                                      )
2447                           	);
2448 
2449     /*Cursor editable_common_bom_other_org
2450     IS
2451     SELECT bill_Sequence_id
2452     FROM BOM_BILL_OF_MATERIALS
2453     WHERE common_bill_Sequence_id <> source_bill_sequence_id
2454       AND source_bill_sequence_id = g_rev_comp_Unexp_rec.bill_sequence_id
2455       AND organization_id <> g_rev_comp_Unexp_rec.organization_id;
2456 
2457     Cursor valid_op_seq(p_bill_seq_id NUMBER)
2458     IS
2459     SELECT 1
2460     FROM BOM_OPERATION_SEQUENCES bos, BOM_OPERATIONAL_ROUTINGS bor, BOM_BILL_OF_MATERIALS bom
2461     WHERE (bor.routing_sequence_id = bos.routing_sequence_id
2462     AND bor.assembly_item_id = bom.assembly_item_id
2463     AND bor.organization_id = bom.organization_id
2464     AND nvl(bor.alternate_routing_designator, 'XXX') = nvl(bom.alternate_bom_designator, 'XXX')
2465     AND bom.bill_sequence_id = p_bill_seq_id
2466     AND bos.operation_sequence_id <> g_rev_component_rec.New_Operation_Sequence_Number)
2467     OR g_rev_component_rec.New_Operation_Sequence_Number = 1;*/
2468 
2469 	BEGIN
2470 
2471 		-- If component not in other Orgs that refer the bill as common
2472 		-- then return an error code of 1
2473 
2474 --		dbms_output.put_line
2475 --		('Checking if comp exists in other ORGS when bill is common..');
2476 
2477 		FOR c_other_orgs IN in_other_orgs LOOP
2478         		RETURN 1;
2479         	END LOOP;
2480 
2481 --		dbms_output.put_line
2482 --		('Checking if component is BOM enabled in other ORGS . . .');
2483 
2484 		FOR c_bom_enabled IN bom_enabled_in_other_orgs LOOP
2485 			RETURN 2;
2486 		END LOOP;
2487 
2488 --		dbms_output.put_line('Checking if component is ENG flag is compatible in other ORGS . . .');
2489 
2490 		FOR c_eng_flag IN eng_flag_in_other_orgs LOOP
2491 			RETURN 3;
2492 		END LOOP;
2493 
2494     /*FOR c_editable_comm_bill in  editable_common_bom_other_org
2495     LOOP
2496       OPEN invalid_op_seq(c_editable_comm_bill.bill_Sequence_id);
2497       FETCH invalid_op_seq INTO l_invalid_Bill;
2498       IF invalid_op_seq%FOUND
2499       THEN
2500         RETURN 4;
2501       END IF;
2502     END LOOP;*/
2503     --Moved this to check_op_seq as this should be caled even for commoning withing the org.
2504 
2505 		RETURN 0;
2506 
2507 	END Check_Common_Other_Orgs;
2508 
2509 	--
2510 	-- Function Check_Prrimary Bill
2511 	--
2512 	FUNCTION Check_PrimaryBill
2513 	RETURN BOOLEAN
2514 	IS
2515 		CURSOR c_CheckPrimary IS
2516 		SELECT 1
2517 	  	FROM bom_bill_of_materials
2518 	 	WHERE assembly_item_id = g_Rev_Comp_Unexp_Rec.revised_item_id
2519 	   	AND organization_id  = g_Rev_Comp_Unexp_Rec.Organization_Id
2520 	   	AND NVL(alternate_bom_designator, 'NONE') = 'NONE';
2521 	BEGIN
2522 		FOR CheckPrimary IN c_CheckPrimary LOOP
2523 			RETURN TRUE;
2524 		END LOOP;
2525 
2526 		-- If the loop does not execute then
2527 		-- return false
2528 
2529 		RETURN FALSE;
2530 	END Check_PrimaryBill;
2531 
2532 	--
2533 	-- Function Check_RevItem_Alternate
2534 	-- Added by MK on 11/01/2000
2535         -- Called from Check_Access
2536         --
2537         -- This fuction moved to Engineering space to resolove ECO dependency
2538         -- by MK on 12/03/00
2539         /*
2540         FUNCTION Check_RevItem_Alternate(  p_revised_item_id         IN  NUMBER
2541                                          , p_organization_id         IN  NUMBER
2542                                          , p_change_notice           IN  VARCHAR2
2543                                          , p_new_item_revision       IN  VARCHAR2
2544                                          , p_new_routing_revsion     IN  VARCHAR2
2545                                          , p_effective_date          IN  DATE
2546                                          , p_from_end_item_number    IN  VARCHAR2
2547                                          )
2548         RETURN BOOLEAN
2549         IS
2550 
2551                 l_return_status BOOLEAN ;
2552 
2553                 CURSOR c_CheckPrimary    (  p_revied_item_id   NUMBER
2554                                           , p_organization_id  NUMBER)
2555                 IS
2556 
2557                     SELECT 1
2558                     FROM bom_bill_of_materials
2559                     WHERE assembly_item_id = p_revied_item_id
2560                     AND   organization_id    = p_organization_id
2561                     AND   NVL(alternate_bom_designator, 'NONE') = 'NONE';
2562 
2563                 CURSOR c_Alternate_Check    (  p_revised_item_id         NUMBER
2564                                              , p_organization_id         NUMBER
2565                                              , p_change_notice           VARCHAR2
2566                                              , p_new_item_revision       VARCHAR2
2567                                              , p_new_routing_revsion     VARCHAR2
2568                                              , p_from_end_item_number    VARCHAR2
2569                                              , p_effective_date          DATE
2570                                              )
2571                 IS
2572 
2573                     SELECT   'Rev Item is only Eco for altenate routing'
2574                     FROM     ENG_REVISED_ITEMS  eri
2575                           ,  BOM_OPERATIONAL_ROUTINGS bor
2576                     WHERE    bor.alternate_routing_designator  IS NOT NULL
2577                     AND      eri.routing_sequence_id         =   bor.routing_sequence_id(+)
2578                     AND      eri.routing_sequence_id        IS NOT NULL
2579                     AND      eri.bill_sequence_id           IS NULL
2580                     AND      NVL(eri.from_end_item_unit_number, 'NONE')
2581                                                    = NVL(p_from_end_item_number, 'NONE')
2582                     AND      NVL(eri.new_item_revision,'NULL') = NVL(p_new_item_revision ,'NULL')
2583                     AND      NVL(eri.new_routing_revision,'NULL') = NVL(p_new_routing_revsion,'NULL')
2584                     AND      TRUNC(eri.scheduled_date)      = TRUNC(p_effective_date)
2585                     AND      eri.change_notice              = p_change_notice
2586                     AND      eri.organization_id            = p_organization_id
2587                     AND      eri.revised_item_id            = p_revised_item_id ;
2588 
2589 
2590          BEGIN
2591 
2592                 FOR CheckPrimary IN c_CheckPrimary(p_revised_item_id, p_organization_id)
2593                 LOOP
2594                         RETURN TRUE ;
2595                 END LOOP;
2596 
2597 
2598                 FOR CheckRevAlt IN c_Alternate_Check
2599                                             (  p_revised_item_id
2600                                              , p_organization_id
2601                                              , p_change_notice
2602                                              , p_new_item_revision
2603                                              , p_new_routing_revsion
2604                                              , p_from_end_item_number
2605                                              , p_effective_date
2606                                              )
2607 
2608                 LOOP
2609                         RETURN FALSE ;
2610                 END LOOP;
2611 
2612 
2613 
2614                 -- If the loop does not execute then
2615                 -- return True`
2616 
2617                 RETURN TRUE ;
2618 
2619          END ;
2620          */ -- Comment out by MK on 12/03/00
2621 
2622 
2623          /*****************************************************
2624          * Added by MK on 01/26/2001 for ECO New Effectivities
2625          * This function is copied from
2626          * ENG_Validate.Check_RevCmp_In_ECO_By_WO which is
2627          * no longer used and modified.
2628          *
2629          * Function      : Check_RevCmp_In_ECO_By_WO
2630          * Parameters IN : Revised Item Sequence Id
2631          *                 Component Item Id
2632          *                 Operation Seq Num
2633          * Returns       : True if All Jobs in ECO by Lot, WO, Cum Qty have the
2634          *                 Rev Component and Op Seq Number else False.
2635          * Purpose       : Check if Component Item, Op Seq Num exists in material requirements
2636          *                 info of jobs and schedules Verify the user can create a revised
2637          *                 component record in ECO by WO
2638          *****************************************************************************/
2639          FUNCTION Check_RevCmp_In_ECO_By_WO
2640              ( p_revised_item_sequence_id IN  NUMBER
2641              , p_rev_comp_item_id         IN  NUMBER
2642              , p_operation_seq_num        IN  NUMBER
2643              , p_organization_id          IN  NUMBER
2644              , p_rev_item_id              IN  NUMBER
2645              )
2646 
2647          RETURN BOOLEAN
2648          IS
2649                 l_ret_status BOOLEAN := TRUE ;
2650 
2651                 l_lot_number varchar2(30) := NULL;
2652                 l_from_wip_entity_id NUMBER :=0;
2653                 l_to_wip_entity_id NUMBER :=0;
2654                 l_from_cum_qty  NUMBER :=0;
2655 
2656 
2657                 CURSOR  l_check_lot_num_csr ( p_lot_number        VARCHAR2
2658                                             , p_rev_comp_item_id  NUMBER
2659                                             , p_operation_seq_num NUMBER
2660                                             , p_organization_id   NUMBER
2661                                             , p_rev_item_id       NUMBER )
2662                 IS
2663                    SELECT 'Cmp does not exist'
2664                    FROM   SYS.DUAL
2665                    WHERE  EXISTS (SELECT  NULL
2666                                   FROM    WIP_DISCRETE_JOBS  wdj
2667                                   WHERE  (wdj.status_type <> 1
2668                                            OR
2669                                            NOT EXISTS(SELECT NULL
2670                                                       FROM   WIP_REQUIREMENT_OPERATIONS wro
2671                                                       WHERE  (wro.operation_seq_num = p_operation_seq_num
2672                                                               OR p_operation_seq_num = 1)
2673                                                       AND    wro.inventory_item_id = p_rev_comp_item_id
2674                                                       AND    wro.wip_entity_id     = wdj.wip_entity_id)
2675                                           )
2676                                  AND      wdj.lot_number = p_lot_number
2677                                  AND      wdj.organization_id = p_organization_id
2678                                  AND      wdj.primary_item_id = p_rev_item_id
2679                    ) ;
2680 
2681                 CURSOR  l_check_wo_csr (  p_from_wip_entity_id NUMBER
2682                                         , p_to_wip_entity_id   NUMBER
2683                                         , p_rev_comp_item_id   NUMBER
2684                                         , p_operation_seq_num  NUMBER
2685                                         , p_organization_id    NUMBER )
2686                 IS
2687                    SELECT 'Cmp does not exist'
2688                    FROM   SYS.DUAL
2689                    WHERE  EXISTS (SELECT  NULL
2690                                   FROM    WIP_DISCRETE_JOBS  wdj
2691                                         , WIP_ENTITIES       we
2692                                         , WIP_ENTITIES       we1
2693                                         , WIP_ENTITIES       we2
2694                                   WHERE   (wdj.status_type <> 1
2695                                            OR
2696                                            NOT EXISTS (SELECT NULL
2697                                                        FROM   WIP_REQUIREMENT_OPERATIONS wro
2698                                                        WHERE  (wro.operation_seq_num = p_operation_seq_num
2699                                                                OR p_operation_seq_num = 1)
2700                                                        AND    wro.inventory_item_id = p_rev_comp_item_id
2701                                                        AND    wro.wip_entity_id     = wdj.wip_entity_id)
2702                                           )
2703                                   AND     wdj.wip_entity_id = we.wip_entity_id
2704                                   AND     we.organization_Id =  p_organization_id
2705                                   AND     we.wip_entity_name >= we1.wip_entity_name
2706                                   AND     we.wip_entity_name <= we2.wip_entity_name
2707                                   AND     we1.wip_entity_id = p_from_wip_entity_id
2708                                   AND     we2.wip_entity_id = NVL(p_to_wip_entity_id, p_from_wip_entity_id)
2709                                   ) ;
2710 
2711 
2712                CURSOR  l_check_cum_csr (  p_from_wip_entity_id NUMBER
2713                                         , p_rev_comp_item_id   NUMBER
2714                                         , p_operation_seq_num  NUMBER)
2715                 IS
2716                    SELECT 'Cmp does not exist'
2717                    FROM   SYS.DUAL
2718                    WHERE  EXISTS (SELECT  NULL
2719                                   FROM    WIP_DISCRETE_JOBS  wdj
2720                                   WHERE   (wdj.status_type <> 1
2721                                            OR
2722                                            NOT EXISTS(SELECT NULL
2723                                                       FROM   WIP_REQUIREMENT_OPERATIONS wro
2724                                                       WHERE  (wro.operation_seq_num = p_operation_seq_num
2725                                                               OR p_operation_seq_num = 1)
2726                                                       AND    wro.inventory_item_id = p_rev_comp_item_id
2727                                                       AND    wro.wip_entity_id     = wdj.wip_entity_id)
2728                                           )
2729                                   AND     wdj.wip_entity_id = p_from_wip_entity_id
2730                                   ) ;
2731 
2732              BEGIN
2733 
2734 
2735                 l_lot_number := BOM_Globals.Get_Lot_Number;
2736                 l_from_wip_entity_id := BOM_Globals.Get_From_Wip_Entity_Id;
2737                 l_to_wip_entity_id := BOM_Globals.Get_To_Wip_Entity_Id;
2738                 l_from_cum_qty := BOM_Globals.Get_From_Cum_Qty;
2739 
2740 IF Bom_Globals.Get_Debug = 'Y' THEN
2741     Error_Handler.Write_Debug('Check if the rev component is valid in Eco by Prod. . .' );
2742     Error_Handler.Write_Debug('Lot Number in parent rev item : ' || l_lot_number );
2743     Error_Handler.Write_Debug('From WIP Entity Id  in parent rev item : ' || to_char(l_from_wip_entity_id) );
2744     Error_Handler.Write_Debug('To WIP Entity Id  in parent rev item : ' || to_char(l_to_wip_entity_id) );
2745     Error_Handler.Write_Debug('Cum Qty in parent rev item : ' || to_char(l_from_cum_qty) );
2746 END IF;
2747 
2748 
2749                 -- Check if comp exists in ECO by Lot
2750                 IF   l_lot_number         IS NOT NULL
2751                 AND  l_from_wip_entity_id IS NULL
2752                 AND  l_to_wip_entity_id   IS NULL
2753                 AND  l_from_cum_qty       IS NULL
2754                 THEN
2755 
2756                       FOR l_lot_num_rec IN l_check_lot_num_csr
2757                                         ( p_lot_number        => l_lot_number
2758                                         , p_rev_comp_item_id  => p_rev_comp_item_id
2759                                         , p_operation_seq_num => p_operation_seq_num
2760                                         , p_organization_id   => p_organization_id
2761                                         , p_rev_item_id       => p_rev_item_id
2762                                         )
2763                       LOOP
2764 
2765 IF Bom_Globals.Get_Debug = 'Y' THEN
2766     Error_Handler.Write_Debug('In Eco by Lot Number, this rev component is invalid. . .' );
2767 END IF;
2768                           l_ret_status  := FALSE ;
2769                       END LOOP ;
2770 
2771 
2772                 -- Check if comp exists  in ECO by Cum
2773                 ELSIF  l_lot_number         IS NULL
2774                 AND    l_from_wip_entity_id IS NOT NULL
2775                 AND    l_to_wip_entity_id   IS NULL
2776                 AND    l_from_cum_qty       IS NOT NULL
2777                 THEN
2778 
2779                       FOR l_cum_rec IN l_check_cum_csr
2780                                         ( p_from_wip_entity_id => l_from_wip_entity_id
2781                                         , p_rev_comp_item_id   => p_rev_comp_item_id
2782                                         , p_operation_seq_num  => p_operation_seq_num )
2783                       LOOP
2784 
2785 IF Bom_Globals.Get_Debug = 'Y' THEN
2786     Error_Handler.Write_Debug('In Eco by Cum Qty, this rev component is invalid. . .' );
2787 END IF;
2788 
2789                           l_ret_status  := FALSE ;
2790                       END LOOP ;
2791 
2792                 -- Check if comp exists  in ECO by WO
2793                 ELSIF  l_lot_number         IS NULL
2794                 AND    l_from_wip_entity_id IS NOT NULL
2795                 AND    l_from_cum_qty       IS NULL
2796                 THEN
2797 
2798                       FOR l_wo_rec IN l_check_wo_csr
2799                                         ( p_from_wip_entity_id => l_from_wip_entity_id
2800                                         , p_to_wip_entity_id   => l_to_wip_entity_id
2801                                         , p_rev_comp_item_id   => p_rev_comp_item_id
2802                                         , p_operation_seq_num  => p_operation_seq_num
2803                                         , p_organization_id    => p_organization_Id   )
2804                       LOOP
2805 
2806 IF Bom_Globals.Get_Debug = 'Y' THEN
2807     Error_Handler.Write_Debug('In Eco by range work order, this rev component is invalid. . .' );
2808 END IF;
2809 
2810                           l_ret_status  := FALSE ;
2811                       END LOOP ;
2812 
2813                 ELSIF  l_lot_number         IS NULL
2814                 AND    l_from_wip_entity_id IS NULL
2815                 AND    l_to_wip_entity_id   IS NULL
2816                 AND    l_from_cum_qty       IS NULL
2817                 THEN
2818 
2819 IF Bom_Globals.Get_Debug = 'Y' THEN
2820     Error_Handler.Write_Debug('Parent revised item is not Eco by production. . .' );
2821 END IF;
2822 
2823                       NULL ;
2824 
2825                    --  ELSE
2826                    --     l_ret_status  := FALSE ;
2827                    --
2828 
2829                 END IF ;
2830 
2831                 RETURN l_ret_status ;
2832 
2833          END Check_RevCmp_In_ECO_By_WO ;
2834 
2835 
2836 	/******************** Local Procedures End **********************/
2837 
2838 
2839 	/******************************************************************
2840         * Procedure     : Set_Item_Attributes
2841         * Purpose       : Set the global attribute flags. This procedure is
2842         *                 called ONLY by the ECO FORM. The open interfaces
2843         *                 will perform this step in the Entity validation
2844         *                 procedure.
2845         **********************************************************************/
2846 
2847 	PROCEDURE Set_Item_Attributes
2848 	( p_RI_bom_item_type            NUMBER
2849 	, p_RC_bom_item_type            NUMBER
2850 	, p_RC_replenish_to_order_flag  CHAR
2851 	, p_RI_replenish_to_order_flag  CHAR
2852 	, p_RC_pick_components_flag     CHAR
2853 	, p_RI_pick_components_flag     CHAR
2854 	, p_RC_base_item_id             NUMBER
2855 	, p_RC_ato_forecast_control     NUMBER
2856 	, p_RI_base_item_id             NUMBER
2857 	, p_RC_eng_item_flag            CHAR
2858 	, p_RI_eng_item_flag            CHAR
2859 	, p_RC_atp_components_flag      CHAR
2860 	, p_RI_atp_components_flag      CHAR
2861 	, p_RC_atp_flag                 CHAR
2862 	, p_RI_wip_supply_type          NUMBER
2863 	, p_RC_wip_supply_type          NUMBER
2864 	, p_RI_bom_enabled_flag         CHAR
2865 	, p_RC_bom_enabled_flag         CHAR
2866 	)
2867 	IS
2868 	BEGIN
2869 
2870 		IF p_RI_base_item_id IS NULL OR
2871 		   p_RI_base_item_id = 0
2872 		THEN
2873 			g_Assy_Config := 'N';
2874 		ELSE
2875 			g_Assy_Config := 'Y';
2876 		END IF;
2877 
2878 		IF p_RC_base_item_id IS NULL OR
2879                    p_RC_base_item_id = 0
2880                 THEN
2881                         g_Comp_Config := 'N';
2882                 ELSE
2883                         g_Comp_Config := 'Y';
2884                 END IF;
2885 
2886                 g_Assy_Item_Type := p_RI_bom_item_type;
2887 		g_Assy_PTO_flag := p_RI_pick_components_flag;
2888                 g_Assy_ATO_flag := p_RI_replenish_to_order_flag;
2889                 g_Assy_Wip_Supply_Type := p_RI_wip_supply_type;
2890                 g_Assy_Eng_Flag := p_RI_eng_item_flag;
2891                 g_Assy_ATP_Comp_flag := p_RI_atp_components_flag;
2892                 g_Assy_Bom_Enabled_flag := p_RI_bom_enabled_flag;
2893                 g_Comp_Item_Type := p_RC_bom_item_type;
2894                 g_Comp_PTO_flag := p_RC_pick_components_flag;
2895                 g_Comp_ATO_flag := p_RC_replenish_to_order_flag;
2896                 g_Comp_Wip_Supply_Type := p_RC_wip_supply_type;
2897                 g_Comp_Eng_Flag := p_RC_eng_item_flag;
2898                 g_Comp_ATP_Comp_flag := p_RC_atp_components_flag;
2899                 g_Comp_ATP_Check_flag := p_RC_atp_flag;
2900                 g_Comp_Bom_Enabled_flag := p_RC_bom_enabled_flag;
2901                 g_Comp_ATO_Forecast_Control := p_RC_ato_forecast_control;
2902 	END Set_Item_Attributes;
2903 
2904 
2905 
2906 
2907 
2908 FUNCTION Dereferenced_Bom(p_bill_sequence_id NUMBER)
2909 Return boolean
2910 IS
2911 l_deref_bom varchar2(1);
2912 BEGIN
2913 	SELECT 'Y' into l_deref_bom
2914 	FROM BOM_BILL_OF_MATERIALS
2915 	WHERE bill_sequence_id =  common_bill_sequence_id
2916 	 AND bill_sequence_id <> nvl(source_bill_sequence_id, common_bill_sequence_id)
2917 	 AND bill_sequence_id = p_bill_sequence_id;
2918 	IF l_deref_bom = 'Y' THEN
2919 	  Return true;
2920   END IF;
2921   Return false;
2922 EXCEPTION
2923 WHEN NO_DATA_FOUND THEN
2924   return false;
2925 END;
2926 
2927 
2928 FUNCTION Is_Bill_Common(p_bill_sequence_id IN NUMBER)
2929 RETURN Boolean
2930 IS
2931   l_dummy VARCHAR2(1);
2932 BEGIN
2933   SELECT 'Y'
2934   INTO l_dummy
2935   FROM BOM_STRUCTURES_B
2936   WHERE BILL_SEQUENCE_ID = p_bill_sequence_id
2937   AND BILL_SEQUENCE_ID <> SOURCE_BILL_SEQUENCE_ID;
2938   Return true;
2939 EXCEPTION
2940   WHEN NO_DATA_FOUND THEN
2941     return false;
2942 END;
2943 
2944 
2945 
2946 FUNCTION valid_common_bom_change( p_rev_component_rec      IN  Bom_Bo_Pub.Rev_Component_Rec_Type
2947                                  , p_Old_Rev_Component_Rec  IN  Bom_Bo_Pub.Rev_Component_Rec_Type)
2948 RETURN boolean
2949 IS
2950 BEGIN
2951 	IF p_Old_Rev_Component_Rec.Organization_Code <> p_rev_component_rec.Organization_Code
2952 		OR p_Old_Rev_Component_Rec.Revised_Item_Name <> p_rev_component_rec.Revised_Item_Name
2953 		--OR p_Old_Rev_Component_Rec.New_revised_Item_Revision  <> p_rev_component_rec.New_revised_Item_Revision
2954 		--OR p_Old_Rev_Component_Rec.Start_Effective_Date      <> p_rev_component_rec.Start_Effective_Date
2955 		OR p_Old_Rev_Component_Rec.New_Effectivity_Date      <> p_rev_component_rec.New_Effectivity_Date
2956 		OR p_Old_Rev_Component_Rec.Disable_Date        <> p_rev_component_rec.Disable_Date
2957 --		OR p_Old_Rev_Component_Rec.Operation_Sequence_Number     <> p_rev_component_rec.Operation_Sequence_Number
2958 		OR p_Old_Rev_Component_Rec.Component_Item_Name       <> p_rev_component_rec.Component_Item_Name
2959 		OR p_Old_Rev_Component_Rec.Alternate_BOM_Code        <> p_rev_component_rec.Alternate_BOM_Code
2960 		--OR p_Old_Rev_Component_Rec.ACD_Type          <> p_rev_component_rec.ACD_Type
2961 		OR p_Old_Rev_Component_Rec.Old_Effectivity_Date      <> p_rev_component_rec.Old_Effectivity_Date
2962 		OR p_Old_Rev_Component_Rec.Old_Operation_Sequence_Number   <> p_rev_component_rec.Old_Operation_Sequence_Number
2963 		OR p_Old_Rev_Component_Rec.New_Operation_Sequence_Number   <> p_rev_component_rec.New_Operation_Sequence_Number
2964 		OR p_Old_Rev_Component_Rec.Item_Sequence_Number      <> p_rev_component_rec.Item_Sequence_Number
2965 		OR p_Old_Rev_Component_Rec.Quantity_Per_Assembly     <> p_rev_component_rec.Quantity_Per_Assembly
2966 		OR p_Old_Rev_Component_Rec.Inverse_Quantity          <> p_rev_component_rec.Inverse_Quantity
2967 		OR p_Old_Rev_Component_Rec.Planning_Percent        <> p_rev_component_rec.Planning_Percent
2968 		OR p_Old_Rev_Component_Rec.Projected_Yield       <> p_rev_component_rec.Projected_Yield
2969 --		OR p_Old_Rev_Component_Rec.Include_In_Cost_Rollup  <> p_rev_component_rec.Include_In_Cost_Rollup
2970 		OR p_Old_Rev_Component_Rec.So_Basis            <> p_rev_component_rec.So_Basis
2971 		OR p_Old_Rev_Component_Rec.Optional            <> p_rev_component_rec.Optional
2972 		OR p_Old_Rev_Component_Rec.Mutually_Exclusive  <> p_rev_component_rec.Mutually_Exclusive
2973 		OR p_Old_Rev_Component_Rec.Check_Atp           <> p_rev_component_rec.Check_Atp
2974 		OR p_Old_Rev_Component_Rec.Shipping_Allowed    <> p_rev_component_rec.Shipping_Allowed
2975 		OR p_Old_Rev_Component_Rec.Required_To_Ship    <> p_rev_component_rec.Required_To_Ship
2976 		OR p_Old_Rev_Component_Rec.Required_For_Revenue<> p_rev_component_rec.Required_For_Revenue
2977 		OR p_Old_Rev_Component_Rec.Include_On_Ship_Docs <> p_rev_component_rec.Include_On_Ship_Docs
2978 		OR p_Old_Rev_Component_Rec.Quantity_Related  <> p_rev_component_rec.Quantity_Related
2979 		OR p_Old_Rev_Component_Rec.Minimum_Allowed_Quantity      <> p_rev_component_rec.Minimum_Allowed_Quantity
2980 		OR p_Old_Rev_Component_Rec.Maximum_Allowed_Quantity      <> p_rev_component_rec.Maximum_Allowed_Quantity
2981 		OR p_Old_Rev_Component_Rec.comments        <> p_rev_component_rec.comments
2982 		OR p_Old_Rev_Component_Rec.cancel_comments   <> p_rev_component_rec.cancel_comments
2983 		OR p_Old_Rev_Component_Rec.Attribute_category   <> p_rev_component_rec.Attribute_category
2984 		OR p_Old_Rev_Component_Rec.Attribute1    <> p_rev_component_rec.Attribute1
2985 		OR p_Old_Rev_Component_Rec.Attribute2    <> p_rev_component_rec.Attribute2
2986 		OR p_Old_Rev_Component_Rec.Attribute3     <> p_rev_component_rec.Attribute3
2987 		OR p_Old_Rev_Component_Rec.Attribute4        <> p_rev_component_rec.Attribute4
2988 		OR p_Old_Rev_Component_Rec.Attribute5     <> p_rev_component_rec.Attribute5
2989 		OR p_Old_Rev_Component_Rec.Attribute6    <> p_rev_component_rec.Attribute6
2990 		OR p_Old_Rev_Component_Rec.Attribute7    <> p_rev_component_rec.Attribute7
2991 		OR p_Old_Rev_Component_Rec.Attribute8    <> p_rev_component_rec.Attribute8
2992 		OR p_Old_Rev_Component_Rec.Attribute9     <> p_rev_component_rec.Attribute9
2993 		OR p_Old_Rev_Component_Rec.Attribute10   <> p_rev_component_rec.Attribute10
2994 		OR p_Old_Rev_Component_Rec.Attribute11   <> p_rev_component_rec.Attribute11
2995 		OR p_Old_Rev_Component_Rec.Attribute12   <> p_rev_component_rec.Attribute12
2996 		OR p_Old_Rev_Component_Rec.Attribute13       <> p_rev_component_rec.Attribute13
2997 		OR p_Old_Rev_Component_Rec.Attribute14     <> p_rev_component_rec.Attribute14
2998 		OR p_Old_Rev_Component_Rec.Attribute15      <> p_rev_component_rec.Attribute15
2999 		OR p_Old_Rev_Component_Rec.From_End_Item_Unit_Number    <> p_rev_component_rec.From_End_Item_Unit_Number
3000 		OR p_Old_Rev_Component_Rec.Old_From_End_Item_Unit_Number  <> p_rev_component_rec.Old_From_End_Item_Unit_Number
3001 		OR p_Old_Rev_Component_Rec.New_From_End_Item_Unit_Number   <> p_rev_component_rec.New_From_End_Item_Unit_Number
3002 		OR p_Old_Rev_Component_Rec.To_End_Item_Unit_Number        <> p_rev_component_rec.To_End_Item_Unit_Number
3003 		OR p_Old_Rev_Component_Rec.New_Routing_Revision      <> p_rev_component_rec.New_Routing_Revision
3004 		OR p_Old_Rev_Component_Rec.Enforce_Int_Requirements  <> p_rev_component_rec.Enforce_Int_Requirements
3005 		OR p_Old_Rev_Component_Rec.Auto_Request_Material     <> p_rev_component_rec.Auto_Request_Material
3006 		OR p_Old_Rev_Component_Rec.Suggested_Vendor_Name     <> p_rev_component_rec.Suggested_Vendor_Name
3007 		OR p_Old_Rev_Component_Rec.Unit_Price           <> p_rev_component_rec.Unit_Price
3008 		OR p_Old_Rev_Component_Rec.Original_System_Reference     <> p_rev_component_rec.Original_System_Reference
3009 	THEN return false;
3010 	END IF;
3011 	RETURN true;
3012 END;
3013 
3014 
3015 
3016 --Bug 8874286 begin
3017 FUNCTION Get_Structure_Type_Name( p_bill_sequence_id IN NUMBER)
3018   RETURN VARCHAR2
3019   IS
3020   l_structure_type_name      VARCHAR2(30) := NULL;
3021 
3022   BEGIN
3023     SELECT STRUCTURE_TYPE_NAME
3024     INTO
3025     l_structure_type_name
3026     FROM BOM_STRUCTURE_TYPES_B STRUCT_TYPE,
3027     BOM_STRUCTURES_B  BOM_STRUCT
3028     WHERE  BOM_STRUCT.STRUCTURE_TYPE_ID = STRUCT_TYPE.STRUCTURE_TYPE_ID
3029     AND BOM_STRUCT.BILL_SEQUENCE_ID = p_bill_sequence_id;
3030 
3031     RETURN l_structure_type_name;
3032 
3033     EXCEPTION
3034      WHEN NO_DATA_FOUND THEN
3035        RETURN NULL;
3036 
3037   END;
3038 --Bug 8874286 end
3039 
3040 
3041 	/******************************************************************
3042 	* Procedure	: Check_Entity
3043 	* Parameters IN : Revised component exposed column record
3044 	*		  Revised component unexposed column record
3045 	*		  Revised component old exposed column record
3046 	*		  Revised component old unexposed column record
3047 	*		  Control record
3048 	* Parameters OUT: Mesg _Token_Tbl
3049 	*		  Return Status
3050 	* Purpose	: Check_Entity validate the entity for the correct
3051 	*		  business logic. It will verify the values by running
3052 	*		  checks on inter-dependent columns.
3053 	*		  It will also verify that changes in one column value
3054 	*		  does not invalidate some other columns.
3055 	**********************************************************************/
3056 	PROCEDURE Check_Entity
3057 	( x_return_status	  IN OUT NOCOPY  VARCHAR2
3058 	, x_Mesg_Token_Tbl	  IN OUT NOCOPY  Error_Handler.Mesg_Token_Tbl_Type
3059 	, p_rev_component_rec  	   IN  Bom_Bo_Pub.Rev_Component_Rec_Type
3060 	, p_Rev_Comp_Unexp_Rec	   IN  Bom_Bo_Pub.Rev_Comp_Unexposed_Rec_Type
3061 	, p_control_rec            IN  BOM_BO_PUB.Control_Rec_Type
3062                                    := BOM_BO_PUB.G_DEFAULT_CONTROL_REC
3063 	, p_Old_Rev_Component_Rec  IN  Bom_Bo_Pub.Rev_Component_Rec_Type
3064 	, p_Old_Rev_Comp_Unexp_Rec IN  Bom_Bo_Pub.Rev_Comp_Unexposed_Rec_Type
3065 	)
3066 	IS
3067 		l_return_status		VARCHAR2(1):= FND_API.G_RET_STS_SUCCESS;
3068 		l_bill_sequence_id      NUMBER;
3069 		l_processed		BOOLEAN;
3070 		l_result		NUMBER;
3071 		l_Err_Text		VARCHAR2(2000);
3072 		l_bom_item_type		NUMBER;
3073 		l_Mesg_Token_Tbl	Error_Handler.Mesg_Token_Tbl_Type;
3074 		l_is_comp_unit_Controlled BOOLEAN := FALSE;
3075 		l_is_item_unit_controlled BOOLEAN := FALSE;
3076 		l_debug_error_mesg       VARCHAR2(2000);
3077 		l_new_compare_date       DATE;
3078                 l_new_op_seq_num         NUMBER; --added for bug 9920911
3079 	        l_total_rds              NUMBER;
3080                 l_Token_Tbl             Error_Handler.Token_Tbl_Type;
3081     l_Structure_Type_Name    VARCHAR2(30);
3082 
3083     --bug 14351192 added local variable below
3084  	  l_RC_Duplicate_Comps NUMBER :=0;
3085 
3086 		CURSOR c_RefDesgs IS
3087 		SELECT count(component_sequence_id) number_of_desgs
3088   		FROM bom_reference_designators
3089  		WHERE component_sequence_id =
3090 			p_rev_comp_unexp_rec.component_sequence_id;
3091 
3092 		CURSOR c_NewBill IS
3093 		SELECT revised_item_id, change_notice, organization_id
3094 	  	FROM eng_revised_items
3095 	 	WHERE revised_item_sequence_id =
3096 	       		p_rev_comp_Unexp_rec.revised_item_sequence_id;
3097 
3098 		CURSOR CheckForNew IS
3099        		SELECT 'Valid'
3100          	FROM eng_revised_items eri
3101         	WHERE eri.revised_item_sequence_id =
3102 	      		p_rev_comp_Unexp_rec.revised_item_sequence_id
3103           	AND eri.bill_sequence_id         IS NULL
3104           	AND NOT EXISTS (SELECT 1
3105                             	FROM bom_bill_of_materials bom
3106                            	WHERE bom.bill_sequence_id =
3107 				 	p_rev_comp_Unexp_rec.bill_sequence_id
3108 			  	);
3109 
3110 		item_num_for_bill number := 0;
3111 		CURSOR c_ItemDateNum IS
3112 		SELECT 'Valid'
3113           	FROM BOM_inventory_components
3114          	WHERE item_num = p_rev_component_rec.item_sequence_number
3115            	AND component_item_id <> p_rev_comp_unexp_rec.component_item_id
3116 		AND trunc(effectivity_date) <=
3117 				trunc(p_rev_component_rec.start_effective_date)
3118             	AND nvl(trunc(disable_date),
3119 		        trunc(p_rev_component_rec.start_effective_date) + 1) >=
3120                 		trunc(p_rev_component_rec.start_effective_date)
3121 		AND bill_sequence_id = p_Rev_Comp_Unexp_rec.bill_sequence_id;
3122 
3123                 CURSOR c_ItemUnitNum IS
3124                 SELECT 'Valid'
3125                 FROM BOM_inventory_components
3126                 WHERE item_num = p_rev_component_rec.item_sequence_number
3127                 AND component_item_id <> p_rev_comp_unexp_rec.component_item_id
3128                 AND disable_date is NULL
3129                 AND from_end_item_unit_number <=
3130                         p_rev_component_rec.from_end_item_unit_number
3131                 AND NVL(to_end_item_unit_number,
3132                         p_rev_component_rec.from_end_item_unit_number) >=
3133                                 p_rev_component_rec.from_end_item_unit_number
3134                 AND bill_sequence_id = p_Rev_Comp_Unexp_rec.bill_sequence_id;
3135 
3136 		l_bom_ifce_key VARCHAR2(80);
3137 
3138 		-------------------------------------------------
3139 		-- Added since quantity cannot be fractional
3140 		-- if OE is installed and revised item is
3141 		-- ATO/PTO.
3142 
3143 		-- Fix made by AS 04/27/98
3144 		-- Bug 651689
3145 		-------------------------------------------------
3146 		Is_OE_Installed VARCHAR2(1) := 'N';
3147 
3148                 -- Modified by MK on 11/13/00
3149 		CURSOR c_OE_installed IS
3150 		SELECT distinct 'I'
3151 	  	FROM fnd_product_installations
3152 	 	-- WHERE application_id = 300  -- Order Entry
3153                 WHERE  application_id = 660 -- ONT: Order Management
3154 	   	AND status = 'I';
3155 
3156 		Is_Item_ATO VARCHAR2(1) := 'N';
3157 		Is_Item_PTO VARCHAR2(1) := 'N';
3158 
3159 		CURSOR c_ATO_PTO IS
3160 		SELECT replenish_to_order_flag, pick_components_flag
3161 	  	FROM mtl_system_items
3162 	 	WHERE inventory_item_id =
3163 			p_rev_comp_unexp_rec.revised_item_id
3164 	   	AND organization_id = p_rev_comp_unexp_rec.organization_id;
3165 
3166 		Cursor Unit_Controlled_Item IS
3167         	SELECT effectivity_control
3168           	FROM mtl_system_items
3169          	WHERE inventory_item_id = p_rev_comp_unexp_rec.revised_item_id
3170            	AND organization_id   = p_rev_comp_unexp_rec.organization_id;
3171 
3172 		l_bill_to_end_number VARCHAR2(30);
3173 		CURSOR c_To_End_Item_Number IS
3174         	SELECT To_End_Item_Unit_Number
3175           	FROM BOM_Inventory_Components
3176          	WHERE component_sequence_id =
3177                 	g_rev_comp_unexp_rec.old_component_sequence_id;
3178 
3179 
3180                -- Added by MK on 02/02/2001
3181                -- Form has this validation LOV for Old Operation Sequence Number
3182                l_eco_for_production NUMBER ;
3183 
3184                CURSOR old_comp_csr (p_old_comp_seq_id NUMBER ,
3185                                     p_eco_for_production NUMBER)
3186                IS
3187                   SELECT 'Old Comp is invalid'
3188                   FROM   SYS.DUAL
3189                   WHERE  NOT EXISTS ( SELECT NULL
3190                                       FROM    BOM_INVENTORY_COMPONENTS ic
3191                                       WHERE   /*bug 11786826 comment this.  TRUNC(ic.effectivity_date) <=
3192                                                 TRUNC(p_rev_component_rec.start_effective_date)
3193                                       AND   */
3194 				        NVL(ic.disable_date,
3195                                                   TRUNC(p_rev_component_rec.start_effective_date)+1)
3196                                                   > p_rev_component_rec.start_effective_date
3197                                       AND     NVL(ic.disable_date , SYSDATE + 1) > SYSDATE
3198                                       AND     NVL(ic.revised_item_sequence_id, -999)
3199                                                   <> NVL(p_rev_comp_unexp_rec.revised_item_sequence_id, -100)
3200                                       AND     NOT EXISTS (SELECT NULL
3201                                                           FROM  bom_inventory_components ic2
3202                                                           WHERE ic2.revised_item_sequence_id
3203                                                                 = NVL(p_rev_comp_unexp_rec.revised_item_sequence_id,
3204                                                                       -888)
3205                                                           AND decode(ic2.implementation_date,
3206                                                                      null,
3207                                                                      ic2.old_component_sequence_id,
3208                                                                      ic2.component_sequence_id) =
3209                                                               decode(ic.implementation_date,
3210                                                                      null,
3211                                                                      ic.old_component_sequence_id,
3212                                                                      ic.component_sequence_id)
3213                                                           AND ic2.component_sequence_id <>
3214                                                                        p_rev_comp_unexp_rec.component_sequence_id
3215                                                           )
3216                                       AND    ((    p_eco_for_production = 2
3217                                                AND NVL(ic.eco_for_production, 2) <> 1 )
3218                                                OR (p_eco_for_production = 1
3219                                                    AND ic.implementation_date IS NOT NULL
3220                                                    )
3221                                               )
3222                                       AND ic.component_sequence_id = p_old_comp_seq_id
3223                                     ) ;
3224 
3225 	BEGIN
3226 
3227         g_rev_component_rec := p_rev_component_rec;
3228         g_Rev_Comp_Unexp_Rec := p_Rev_Comp_Unexp_Rec;
3229 
3230 /*          5134934           */
3231   -- Basis type cannot be Lot if there are existing Reference Desigantors.
3232   IF (p_rev_component_rec.transaction_type = Bom_Globals.G_OPR_UPDATE) THEN
3233 
3234     If(p_rev_component_rec.Basis_type = 2) THEN
3235         select count(*) into l_total_rds from bom_reference_designators
3236         where nvl(p_rev_component_rec.acd_type,1) <>3 and component_sequence_id=p_Rev_Comp_Unexp_Rec.component_sequence_id;
3237      IF(l_total_rds <>0) THEN
3238          l_Token_Tbl(1).Token_Name := 'REVISED_COMPONENT_NAME';
3239        l_Token_Tbl(1).Token_Value := p_rev_component_rec.component_item_name;
3240        Error_Handler.Add_Error_Token
3241           (  x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3242             , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3243             , p_message_name       => 'BOM_LOT_BASED_RDS'
3244             , p_Token_Tbl          => l_Token_Tbl
3245           );
3246           l_return_status := FND_API.G_RET_STS_ERROR;
3247      END IF;
3248   END IF;
3249 END IF;
3250 
3251 
3252 
3253 IF Bom_Globals.Get_Debug = 'Y'
3254 THEN
3255   Error_Handler.Write_Debug('Performing Revised component Entity Validation. . .');
3256 END IF;
3257 
3258     l_is_comp_unit_controlled := BOM_GLOBALS.Get_Unit_Controlled_Component;
3259     l_is_item_unit_controlled := BOM_GLOBALS.Get_Unit_Controlled_Item;
3260 
3261 IF Bom_Globals.Get_Debug = 'Y' THEN
3262    Error_Handler.Write_Debug('Checked if revised item is unit controlled. . .');
3263    Error_Handler.Write_Debug('Org id: ' || to_char(g_rev_Comp_Unexp_Rec.Organization_Id));
3264    Error_Handler.Write_Debug('Item id: ' || to_char(g_rev_Comp_Unexp_Rec.revised_item_id));
3265    Error_Handler.Write_Debug('Comp id: ' || to_char(g_rev_Comp_Unexp_Rec.Component_item_id));
3266    Error_Handler.Write_Debug('Trans type: ' || g_rev_component_rec.transaction_type);
3267 END IF;
3268 
3269     -- First Query all the attributes for the Assembly item and
3270     -- component item.
3271         SELECT  assy.bom_item_type,
3272                 assy.pick_components_flag,
3273                 assy.replenish_to_order_flag,
3274                 assy.wip_supply_type,
3275                 DECODE(NVL(assy.base_item_id, 0), 0 , 'N', 'Y'),
3276 		assy.eng_item_flag,
3277                 assy.atp_components_flag,
3278                 assy.atp_flag,
3279 		assy.bom_enabled_flag,
3280                 assy.effectivity_control,                      --2044133
3281                 assy.tracking_quantity_ind,
3282                 comp.bom_item_type,
3283                 comp.pick_components_flag,
3284                 comp.replenish_to_order_flag,
3285                 comp.wip_supply_type,
3286                 DECODE(NVL(comp.base_item_id, 0), 0 , 'N', 'Y'),
3287                 comp.eng_item_flag,
3288                 comp.atp_components_flag,
3289                 comp.atp_flag,
3290 		comp.bom_enabled_flag,
3291 		comp.ato_forecast_control,
3292                 comp.effectivity_control,                       --2044133
3293                 comp.tracking_quantity_ind
3294           INTO  g_Assy_Item_Type,
3295                 g_Assy_PTO_flag,
3296                 g_Assy_ATO_flag,
3297                 g_Assy_Wip_Supply_Type,
3298                 g_Assy_Config,
3299 		g_Assy_Eng_Flag,
3300                 g_Assy_ATP_Comp_flag,
3301                 g_Assy_ATP_Check_flag,
3302 		g_Assy_Bom_Enabled_flag,
3303                 g_Assy_Effectivity_Control,                   --2044133
3304                 G_Assy_Tracking_Quantity_Ind,
3305                 g_Comp_Item_Type,
3306                 g_Comp_PTO_flag,
3307                 g_Comp_ATO_flag,
3308                 g_Comp_Wip_Supply_Type,
3309                 g_Comp_Config,
3310                 g_Comp_Eng_Flag,
3311                 g_Comp_ATP_Comp_flag,
3312                 g_Comp_ATP_Check_flag,
3313 		g_Comp_Bom_Enabled_flag,
3314 		g_Comp_ATO_Forecast_Control,
3315                 g_Comp_Effectivity_Control,                    --2044133
3316                 G_Comp_Tracking_Quantity_Ind
3317           FROM  mtl_system_items assy,
3318                 mtl_system_items comp
3319          WHERE  assy.organization_id   = g_rev_Comp_Unexp_Rec.Organization_Id
3320            AND  assy.inventory_item_id = g_rev_Comp_Unexp_Rec.revised_item_id
3321            AND  comp.organization_id   = g_rev_Comp_Unexp_Rec.Organization_Id
3322            AND  comp.inventory_item_id = g_rev_Comp_Unexp_Rec.Component_item_id;
3323 -- dbms_output.put_line('Queried all assembly and component attributes. . .');
3324 
3325 
3326 	--
3327 	-- Set the assembly Type of the Assembly
3328 	--
3329 
3330 	IF Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_BOM_BO
3331 	THEN
3332 	  select assembly_type
3333 	  into g_Assy_Assembly_Type
3334 	  --bug: 4161794. Introduced new global variable to hold value of assembly type
3335 	  -- of the header.
3336 	  from bom_bill_of_materials
3337 	  where bill_sequence_id = p_rev_comp_Unexp_rec.bill_sequence_id;
3338 	END IF;
3339 
3340        --if an ATO item was added in a kit when the related profile was set, you cannot
3341        --update or delete the component once the profile is unset
3342        --BOM ER #9946990 changes (begin)
3343 
3344        IF
3345         p_rev_component_rec.Transaction_Type IN (BOM_GLOBALS.G_OPR_UPDATE, BOM_Globals.G_OPR_DELETE) AND
3346         nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) <> 1 AND
3347         g_Assy_Item_Type = Bom_Globals.G_STANDARD AND
3348         g_Assy_PTO_Flag  = 'Y' AND
3349         g_comp_ATO_Flag = 'Y' AND
3350         g_comp_PTO_Flag = 'N' AND
3351         g_Comp_Item_Type = Bom_Globals.G_STANDARD
3352 
3353         THEN
3354 
3355         Error_Handler.Add_Error_Token
3356                 (  p_message_name       => 'BOM_KIT_COMP_PRF_NOT_SET'
3357                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3358                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3359                  , p_Token_Tbl          => g_Token_Tbl
3360                  );
3361         l_return_status := FND_API.G_RET_STS_ERROR;
3362         END IF;
3363 
3364 
3365 
3366         --if a mandatory ATO item was added in a pto model when the related profile was set, you cannot
3367        --update or delete the component once the profile is unset
3368        --BOM ER #9946990 changes (begin)
3369        IF
3370         p_rev_component_rec.Transaction_Type IN (BOM_GLOBALS.G_OPR_UPDATE, BOM_Globals.G_OPR_DELETE) AND
3371         nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) <> 1 AND
3372         g_Assy_Item_Type = Bom_Globals.G_MODEL AND
3373         g_Assy_PTO_Flag  = 'Y' AND
3374         g_comp_ATO_Flag = 'Y' AND
3375         g_comp_PTO_Flag = 'N' AND
3376         g_Comp_Item_Type = Bom_Globals.G_STANDARD AND
3377         g_Rev_Component_Rec.optional = 2
3378 
3379         THEN
3380         Error_Handler.Add_Error_Token
3381                 (  p_message_name       => 'BOM_MODEL_COMP_PRF_NOT_SET'
3382                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3383                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3384                  , p_Token_Tbl          => g_Token_Tbl
3385                  );
3386          l_return_status := FND_API.G_RET_STS_ERROR;
3387         END IF;
3388 
3389        --BOM ER #9946990 changes (end)
3390 
3391        --BOM ER #9946990 changes(begin)
3392        --if user is trying to disable a mandatory ato component in a pto model when related bom profile is
3393        --not set, then throw error
3394 
3395         IF BOM_Globals.Get_Bo_Identifier = BOM_Globals.G_ECO_BO AND
3396         p_rev_component_rec.Transaction_Type = BOM_Globals.G_OPR_CREATE AND
3397         NVL(p_rev_component_rec.acd_type, 1) in (2, 3) AND --had to include acd_type 2 in here since while updating the record optional flag may not be populated or may not undergo a change
3398         nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) <> 1 AND
3399         g_Assy_Item_Type = Bom_Globals.G_MODEL AND
3400         g_Assy_PTO_Flag  = 'Y' AND
3401         g_comp_ATO_Flag = 'Y' AND
3402         g_comp_PTO_Flag = 'N' AND
3403         g_Comp_Item_Type = Bom_Globals.G_STANDARD AND
3404         nvl(g_Rev_Component_Rec.optional,1) = 2
3405 
3406         THEN
3407         Error_Handler.Add_Error_Token
3408                 (  p_message_name       => 'BOM_MODEL_COMP_PRF_NOT_SET'
3409                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3410                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3411                  , p_Token_Tbl          => g_Token_Tbl
3412                  );
3413          l_return_status := FND_API.G_RET_STS_ERROR;
3414         END IF;
3415 
3416         --BOM ER #9946990 changes (end)
3417 	--
3418 	-- Set the 1st token of Token Table to Revised Component value
3419 	--
3420 	g_Token_Tbl(1).Token_Name  := 'REVISED_COMPONENT_NAME';
3421 	g_Token_Tbl(1).Token_Value := p_rev_component_rec.component_item_name;
3422 
3423         -- The ECO can be updated but a warning needs to be generated and
3424         -- scheduled revised items need to be update to Open
3425         -- and the ECO status need to be changed to Not Submitted for Approval
3426 
3427 
3428 	IF Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_ECO_BO
3429 	THEN
3430         	BOM_GLOBALS.Check_Approved_For_Process
3431 		(p_change_notice    => p_rev_component_rec.eco_name,
3432          	 p_organization_id  => p_rev_comp_unexp_rec.organization_id,
3433          	 x_processed        => l_processed,
3434          	 x_err_text         => l_err_text
3435          	);
3436         	IF l_processed = TRUE
3437         	THEN
3438         	-- If the above process returns true then set the ECO approval.
3439         	BEGIN
3440         		BOM_GLOBALS.Set_Request_For_Approval
3441 			(p_change_notice 	=>
3442 			 p_rev_component_rec.eco_name,
3443                  	 p_organization_id 	=>
3444 			 p_rev_comp_unexp_rec.organization_id,
3445                  	 x_err_text          	=> l_err_text
3446                  	);
3447 
3448         	EXCEPTION
3449                 	WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3450                               l_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
3451         	END;
3452         	END IF;
3453 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Check Eco Status . . .' || l_return_status); END IF;
3454 
3455                 -- Added by MK on 01/26/2001 for ECO New Effectivities
3456                 -- Verify the ECO Effectivity, If ECO by WO, Lot Num, Or Cum Qty, then
3457                 -- Check if the component exists in the WO or Lot Num.
3458                 --
3459                 IF   p_rev_component_rec.transaction_type = BOM_Globals.G_OPR_CREATE
3460                 AND  p_rev_component_rec.acd_type  IN (2 , 3) -- Change or Disable
3461                 THEN
3462 
3463                    IF NOT Check_RevCmp_In_ECO_By_WO
3464                     ( p_revised_item_sequence_id => p_rev_comp_unexp_rec.revised_item_sequence_id
3465                     , p_rev_comp_item_id         => p_rev_comp_unexp_rec.component_item_id
3466                     , p_operation_seq_num        => p_rev_component_rec.old_operation_sequence_number
3467                     , p_organization_id          => p_rev_comp_unexp_rec.organization_id
3468                     , p_rev_item_id              => p_rev_comp_unexp_rec.revised_item_id
3469                     )
3470                    THEN
3471                       g_token_tbl.delete;
3472                       g_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
3473                       g_token_tbl(1).token_value := p_rev_component_rec.revised_item_name;
3474 		      g_token_tbl(2).token_name  := 'REVISED_COMPONENT_NAME';
3475                       g_token_tbl(2).token_value :=
3476                                         g_rev_component_rec.component_item_name;
3477 
3478                       Error_Handler.Add_Error_Token
3479                       (  p_message_name   => 'BOM_CMP_RIT_ECO_WO_EFF_INVALID'
3480                        , p_mesg_token_tbl => l_Mesg_Token_Tbl
3481                        , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3482                        , p_token_tbl      => g_token_tbl
3483                       );
3484                       l_return_status := FND_API.G_RET_STS_ERROR;
3485 	              g_token_tbl.delete;
3486 	              g_Token_Tbl(1).Token_Name  := 'REVISED_COMPONENT_NAME';
3487 	              g_Token_Tbl(1).Token_Value := p_rev_component_rec.component_item_name;
3488                    END IF ;
3489 IF Bom_Globals.Get_Debug = 'Y' THEN
3490     Error_Handler.Write_Debug('Check if the rev component is valid in Eco by Prod. . .' || l_return_status);
3491 END IF;
3492                 END IF ;
3493 
3494 
3495 	END IF; -- validations called by only ECO BO
3496 	-- To End Item Unit Number must be greater than or equal to
3497 	-- From End Item Unit Number
3498 
3499 	IF (p_rev_component_rec.To_End_Item_Unit_Number IS NOT NULL AND
3500 	    p_rev_component_rec.To_End_Item_Unit_Number <> FND_API.G_MISS_CHAR AND
3501 	    p_rev_component_rec.From_End_Item_Unit_Number IS NOT NULL AND
3502 	    p_rev_component_rec.From_End_Item_Unit_Number <> FND_API.G_MISS_CHAR
3503 	    )
3504 	    AND
3505 	    (p_rev_component_rec.From_End_Item_Unit_Number > p_rev_component_rec.To_End_Item_Unit_Number)
3506 	THEN
3507                 g_token_tbl.delete;
3508 		g_token_tbl(1).token_name  := 'REVISED_COMPONENT_NAME';
3509                 g_token_tbl(1).token_value :=
3510                                         g_rev_component_rec.component_item_name;
3511                 Error_Handler.Add_Error_Token
3512                 (  p_message_name       => 'BOM_TOUNIT_LESS_THAN_FROMUNIT'
3513                  , p_mesg_token_tbl     => l_Mesg_Token_Tbl
3514                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3515                  , p_token_tbl          => g_token_tbl
3516                  );
3517 
3518                 l_return_status := FND_API.G_RET_STS_ERROR;
3519 
3520 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Check to end item unit number. . .' || l_return_status); END IF;
3521 
3522         END IF;
3523 
3524    --
3525    -- Verify that the Parent is BOM Enabled
3526    --
3527    IF g_Assy_Bom_Enabled_flag <> 'Y'
3528    THEN
3529      g_token_tbl.delete;
3530      g_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
3531      g_token_tbl(1).token_value :=
3532            g_rev_component_rec.revised_item_name;
3533 
3534      Error_Handler.Add_Error_Token
3535      (  p_message_name => 'BOM_REV_ITEM_BOM_NOT_ENABLED'
3536       , p_mesg_token_tbl => l_Mesg_Token_Tbl
3537       , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3538                   , p_token_tbl    => g_token_tbl
3539       );
3540 
3541      l_return_status := FND_API.G_RET_STS_ERROR;
3542  /*    g_token_tbl(1).token_name  := 'REVISED_COMPONENT_NAME';
3543                  g_token_tbl(1).token_value :=
3544                                          p_rev_component_rec.component_item_name;*/
3545 
3546    END IF;
3547 
3548 
3549    --
3550    -- All validations that only apply to Operation Type  CREATE
3551    --
3552    IF p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_CREATE THEN
3553 
3554 	-- When disabling a component, to end item number must be the same
3555 	-- as the value in the bill component being disabled.
3556 
3557     IF NVL(g_rev_component_rec.acd_type, 1) = 3 AND
3558        l_is_comp_unit_controlled
3559     THEN
3560       FOR To_End_Item_Number IN c_To_End_Item_Number
3561           LOOP
3562               l_bill_to_end_number :=
3563           To_End_Item_Number.To_End_Item_Unit_Number;
3564           END LOOP;
3565 
3566       IF l_bill_to_end_number <>
3567         p_rev_component_rec.to_end_item_unit_number
3568       THEN
3569         g_token_tbl.delete;
3570         g_token_tbl(1).token_name  := 'REVISED_COMPONENT_NAME';
3571                     g_token_tbl(1).token_value :=
3572                                           g_rev_component_rec.component_item_name;
3573 
3574                     Error_Handler.Add_Error_Token
3575                     (  p_message_name       => 'BOM_DISABLE_TOUNIT_INVALID'
3576                     , p_mesg_token_tbl     => l_Mesg_Token_Tbl
3577                     , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3578                     , p_token_tbl          => g_token_tbl
3579                     );
3580 
3581                     l_return_status := FND_API.G_RET_STS_ERROR;
3582       END IF;
3583     END IF;
3584            -- Component can be unit controlled only if parent revised item is
3585         -- unit controlled.
3586         -- Added by AS on 07/08/99 as part of unit effectivity changes
3587 
3588 -- Bug 2044133 Fix Begin
3589 --	IF NVL(g_rev_component_rec.acd_type, 1) = 1 AND
3590 --	   l_is_comp_unit_controlled AND
3591 --	   NOT l_is_item_unit_controlled
3592         IF NVL(g_rev_component_rec.acd_type, 1) = 1 AND
3593            g_Assy_Effectivity_Control = 1 AND
3594            g_Comp_Effectivity_Control = 2
3595 -- Bug 2044133 Fix End
3596 
3597       	THEN
3598            g_token_tbl(1).token_name  := 'REVISED_COMPONENT_NAME';
3599                 g_token_tbl(1).token_value :=
3600                                         g_rev_component_rec.component_item_name;
3601                 g_token_tbl(2).token_name  := 'REVISED_ITEM_NAME';
3602                 g_token_tbl(2).token_value :=
3603                                         g_rev_component_rec.revised_item_name;
3604 
3605                 Error_Handler.Add_Error_Token
3606                 (  p_message_name       => 'BOM_CMP_UNIT_RIT_NOT_UNIT'
3607                  , p_mesg_token_tbl     => l_Mesg_Token_Tbl
3608                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3609                  , p_token_tbl          => g_token_tbl
3610                  );
3611 
3612                 l_return_status := FND_API.G_RET_STS_ERROR;
3613 	      END IF;
3614 		        -- Unit controlled revised items can only have non-ATO or non-PTO
3615         -- standard items as components.
3616         -- Added by AS on 07/08/99 as part of unit effectivity changes
3617 
3618         IF NVL(g_rev_component_rec.acd_type, 1) = 1 AND
3619            l_is_comp_unit_controlled AND
3620            (g_comp_item_type <> 4 OR
3621 	    g_comp_ato_flag = 'Y' OR
3622 	    g_comp_pto_flag = 'Y')
3623         THEN
3624                 g_token_tbl.delete;
3625 		g_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
3626                 g_token_tbl(1).token_value :=
3627                                         g_rev_component_rec.revised_item_name;
3628 
3629                 Error_Handler.Add_Error_Token
3630                 (  p_message_name       => 'BOM_CMP_UNIT_TYPE_NOT_VALID'
3631                  , p_mesg_token_tbl     => l_Mesg_Token_Tbl
3632                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
3633                  , p_token_tbl          => g_token_tbl
3634                  );
3635 
3636                 l_return_status := FND_API.G_RET_STS_ERROR;
3637         END IF;
3638 	--
3639 	-- Verify that the Parent has BOM Enabled
3640 	--
3641   --Moved this check out, so that its applicable for all transaction types
3642 /* IF g_Assy_Bom_Enabled_flag <> 'Y'
3643 	THEN
3644 		g_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
3645 		g_token_tbl(1).token_value :=
3646 					g_rev_component_rec.revised_item_name;
3647 
3648 		Error_Handler.Add_Error_Token
3649 		(  p_message_name	=> 'BOM_REV_ITEM_BOM_NOT_ENABLED'
3650 		 , p_mesg_token_tbl	=> l_Mesg_Token_Tbl
3651 		 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
3652                  , p_token_tbl		=> g_token_tbl
3653 		 );
3654 
3655 		l_return_status := FND_API.G_RET_STS_ERROR;
3656 		g_token_tbl(1).token_name  := 'REVISED_COMPONENT_NAME';
3657                 g_token_tbl(1).token_value :=
3658                                         p_rev_component_rec.component_item_name;
3659 
3660 	END IF; */
3661 	IF NOT Check_PrimaryBill AND Nvl(Bom_Globals.Get_Validate_For_Plm,'N') = 'N'
3662            THEN
3663 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('ACD type to be add if primary bill does not exist . . .'); END IF;
3664 		IF NVL(p_rev_component_rec.acd_type, 1) <> 1 AND
3665 		   Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_ECO_BO
3666 		THEN
3667 			/*****************************************************
3668 			--
3669 			-- If the primary bill does not exist then the acd type
3670 			-- of the component cannot be other that add.
3671 			--
3672 			******************************************************/
3673 			IF FND_MSG_PUB.Check_Msg_Level
3674 			   (FND_MSG_PUB.G_MSG_LVL_ERROR)
3675         		THEN
3676             			Error_Handler.Add_Error_Token
3677 				(  p_message_name   => 'BOM_CMP_ACD_TYPE_ADD'
3678 				 , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3679 				 , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3680                                  , p_token_tbl      => g_token_tbl
3681 				);
3682         		END IF;
3683 			l_return_status := FND_API.G_RET_STS_ERROR;
3684 		END IF;
3685 
3686    	END IF;  -- End checking of ACD Type
3687 
3688 	-- Component cannot be added if the Bill is referencing another
3689 	-- bill as common
3690 	BEGIN
3691          IF Bom_Globals.Get_Caller_Type <> 'MIGRATION' THEN
3692                 SELECT 'Valid'
3693                   INTO l_dummy
3694                   FROM bom_bill_of_materials bom
3695                  WHERE bom.bill_sequence_id = p_rev_comp_unexp_rec.bill_sequence_id
3696                    AND bom.source_bill_sequence_id  <> bom.bill_sequence_id
3697                    AND nvl(p_rev_component_rec.acd_type, 1) in (1,3);
3698 
3699          --Dont reject updates outright. Some updates are allowed on Common BOM.
3700          --This is for updates through CO.
3701 
3702        -- If no exception is raised then Bill is referencing another
3703 		   -- bill
3704 
3705           IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3706           THEN
3707               g_token_tbl(2).token_name := 'REVISED_ITEM_NAME';
3708               g_token_tbl(2).token_value :=
3709                 p_rev_component_rec.revised_item_name;
3710                                 Error_Handler.Add_Error_Token
3711               (  p_Message_Name	=> 'BOM_BILL_COMMON'
3712                , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
3713                                  , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
3714                , p_Token_Tbl		=> g_Token_Tbl
3715               );
3716           END IF;
3717                 l_return_status := FND_API.G_RET_STS_ERROR;
3718   --       END IF;
3719            END IF;
3720                 EXCEPTION
3721                    WHEN NO_DATA_FOUND THEN
3722                    --if the acd type is update, check if its a valid common bom update
3723                    IF nvl(p_rev_component_rec.acd_type, 1) in (1,3)
3724                       OR (nvl(p_rev_component_rec.acd_type, 1) = 2
3725                          AND valid_common_bom_change( p_rev_component_rec => p_rev_component_rec
3726                                                 , p_Old_Rev_Component_Rec => p_Old_Rev_Component_Rec))
3727                       OR not Is_Bill_Common(p_bill_sequence_id =>
3728                                                  p_rev_comp_unexp_rec.bill_sequence_id)
3729                    THEN
3730                      NULL;
3731                    ELSE
3732                       IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3733                       THEN
3734                           g_token_tbl(2).token_name := 'REVISED_ITEM_NAME';
3735                           g_token_tbl(2).token_value :=
3736                             p_rev_component_rec.revised_item_name;
3737                                             Error_Handler.Add_Error_Token
3738                           (  p_Message_Name	=> 'BOM_BILL_COMMON'
3739                            , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
3740                                              , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
3741                            , p_Token_Tbl		=> g_Token_Tbl
3742                           );
3743                       END IF;
3744                       l_return_status := FND_API.G_RET_STS_ERROR;
3745                    END IF;
3746                    WHEN OTHERS THEN
3747                    	IF FND_MSG_PUB.Check_Msg_Level
3748 			   (FND_MSG_PUB.G_MSG_LVL_ERROR)
3749                         THEN
3750                         	Error_Handler.Add_Error_Token
3751 				(   p_message_name    => NULL
3752                                   , p_message_text    => 'Common Bill Check ' ||
3753 						 SUBSTR(SQLERRM, 1, 30) || ' '||
3754 						 TO_CHAR(SQLCODE)
3755 				  , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
3756 				  , x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
3757 				 );
3758                         END IF;
3759 			x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
3760                         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3761 
3762       	END; -- Check if parent Common Ends
3763 
3764 	/*****************************************************************
3765 	--
3766 	-- Verify that the component item and revised item are not the same
3767 	--
3768 	******************************************************************/
3769 	IF p_rev_comp_unexp_rec.revised_item_id =
3770 	   p_rev_comp_unexp_rec.component_item_id
3771 	THEN
3772                IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3773                THEN
3774 		   g_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
3775                    g_token_tbl(1).token_value :=
3776                                         g_rev_component_rec.revised_item_name;
3777 
3778                    Error_Handler.Add_Error_Token
3779                    (  x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
3780                     , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
3781                     , p_Message_name    => 'BOM_COMP_SAME_AS_BILL'
3782                     , p_token_tbl       => g_token_tbl
3783                     );
3784                END IF;
3785                l_return_status := FND_API.G_RET_STS_ERROR;
3786 	       g_token_tbl(1).token_name  := 'REVISED_COMPONENT_NAME';
3787                g_token_tbl(1).token_value :=
3788                                         p_rev_component_rec.component_item_name;
3789 
3790 	END IF;
3791 
3792          /*****************************************************************
3793  	         -- bug 14351192
3794  	         -- Verify that the component item does not exist under the same revised item
3795  	         -- in bom_components_b
3796  	   --
3797  	         ******************************************************************/
3798  	 IF p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_CREATE
3799  	 AND NVL(p_rev_component_rec.acd_type,1) = 1 THEN
3800 
3801  	 select count(*) into l_RC_Duplicate_Comps
3802  	 from bom_components_b bcb
3803  	 where bcb.component_item_id = p_rev_comp_unexp_rec.component_item_id
3804  	 and bcb.bill_sequence_id = p_rev_comp_unexp_rec.bill_sequence_id
3805  	 and bcb.operation_seq_num = p_rev_component_rec.Operation_Sequence_Number
3806  	 and ((bcb.disable_date is null and p_rev_component_rec.disable_date is null) or
3807  	 (bcb.disable_date is null and bcb.effectivity_date < p_rev_component_rec.disable_date) or
3808  	 (p_rev_component_rec.disable_date is null and p_rev_component_rec.start_effective_date < bcb.disable_date) or
3809  	 (bcb.effectivity_date < p_rev_component_rec.start_effective_date and p_rev_component_rec.start_effective_date < bcb.disable_date) or
3810  	 (p_rev_component_rec.start_effective_date < bcb.effectivity_date and bcb.effectivity_date < p_rev_component_rec.disable_date));
3811 
3812  	 IF l_RC_Duplicate_Comps >= 1 THEN
3813  	  g_token_tbl(1).token_name  := 'COMPONENT_ITEM_NAME';
3814  	  g_token_tbl(1).token_value := p_rev_component_rec.component_item_name;
3815  	  g_token_tbl(2).token_name  := 'OPERATION_SEQUENCE';
3816  	  g_token_tbl(2).token_value := p_rev_component_rec.Operation_Sequence_Number;
3817  	  g_token_tbl(3).token_name  := 'EFFECTIVE_FROM';
3818 
3819  	  select effectivity_date into g_token_tbl(3).token_value
3820  	  from bom_components_b
3821  	  where bill_sequence_id = p_rev_comp_unexp_rec.bill_sequence_id
3822  	  and component_item_id = p_rev_comp_unexp_rec.component_item_id
3823  	  and operation_seq_num = p_rev_component_rec.Operation_Sequence_Number
3824  	  and rownum=1
3825  	  order by effectivity_date asc;
3826 
3827  	  Error_Handler.Add_Error_Token
3828  	                    (  x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
3829  	                     , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
3830  	                     , p_Message_name    => 'BOM_COMPONENT_OVERLAPS'
3831  	                     , p_token_tbl       => g_token_tbl
3832  	                     );
3833 
3834  	 l_return_status := FND_API.G_RET_STS_ERROR;
3835  	 END IF;
3836  	 END IF;
3837 
3838 	/*************************************************************
3839 	--
3840 	-- Verify BOM_Enabled_Flag of the component being added.
3841 	-- Only components with value Yes can be added.
3842 	--
3843 	**************************************************************/
3844 /* This validation will not be required anymore as items which are not BOM allowed can
3845    be components, but will just not be able to have BOMs  --- Deepu
3846 	*/
3847   /*Uncommented for bug 5925020*/
3848 
3849 	IF g_Comp_Bom_Enabled_Flag = 'N' THEN
3850                -- Bom_Enabled is N, so cannot add a component .
3851 		-- Check if ACD type is not Disable or Update
3852           IF( nvl(p_rev_component_rec.acd_type, 1)  NOT IN (2 , 3)) THEN -- Change or Disable
3853                IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3854                THEN
3855                    Error_Handler.Add_Error_Token
3856 		   (  x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
3857 		    , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
3858                     , p_Message_name	=> 'BOM_COMP_ITEM_BOM_NOT_ENABLED'
3859                     , p_token_tbl	=> g_token_tbl
3860 		    );
3861                END IF;
3862                l_return_status := FND_API.G_RET_STS_ERROR;
3863 	  END IF;
3864    	END IF;
3865 
3866 
3867 	/*******************************************************************
3868 	--
3869 	-- Item Num Check
3870 	--
3871 	********************************************************************/
3872 	IF p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_CREATE
3873 	   AND
3874 	   ( NVL(p_rev_component_rec.acd_type,1) = 1  OR
3875 	     ( p_rev_component_rec.acd_type = 2 AND
3876 	       p_rev_component_rec.item_sequence_number <>
3877 	       p_old_rev_component_rec.item_sequence_number
3878 	     )
3879 	   )
3880            AND
3881            ((p_Control_rec.caller_type = 'FORM' AND
3882              p_control_rec.validation_controller = 'ITEM_SEQUENCE_NUMBER')
3883              OR
3884              p_control_rec.caller_type <> 'FORM')
3885    	THEN
3886              -- Verify if a component is already added using this item_num
3887 	     -- If there is, log a WARNING.
3888 
3889                 item_num_for_bill := 0;
3890 		g_Token_Tbl.Delete;
3891                 g_token_tbl(1).token_name  := 'ITEM_SEQUENCE_NUMBER';
3892                 g_token_tbl(1).token_value := p_rev_component_rec.item_sequence_number;
3893                 g_token_tbl(2).token_name  := 'REVISED_COMPONENT_NAME';
3894                 g_token_tbl(2).token_value := p_rev_component_rec.component_item_name;
3895 
3896                 IF NOT l_is_item_unit_controlled
3897 		THEN
3898 			FOR Item_Num in c_ItemDateNum LOOP
3899                         	item_num_for_bill := 1;
3900                 	END LOOP;
3901 		ELSE
3902                         FOR Item_Num in c_ItemUnitNum LOOP
3903                                 item_num_for_bill := 1;
3904                         END LOOP;
3905 		END IF;
3906 
3907                 IF item_num_for_bill = 1 THEN
3908                 	Error_Handler.Add_Error_Token
3909 			(  x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
3910 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
3911                          , p_message_name	=> 'BOM_ITEM_NUM_NOT_UNIQUE'
3912 			 , p_Token_Tbl		=> g_Token_Tbl
3913                          , p_message_type 	=> 'W'
3914 			);
3915                 END IF;
3916 
3917 	END IF; -- Item Num Check ends
3918 
3919 
3920 	/********************************************************************
3921 	--
3922         -- Also verify that the component being added is not a Product Family
3923         --
3924 	*********************************************************************/
3925 
3926 	g_token_tbl.delete;
3927         g_token_tbl(1).token_name  := 'REVISED_COMPONENT_NAME';
3928         g_token_tbl(1).token_value :=
3929                                         g_rev_component_rec.component_item_name;
3930 
3931 	IF g_Comp_Item_Type = 5
3932 	THEN
3933         	IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
3934                 THEN
3935                         Error_Handler.Add_Error_Token
3936 			(  p_message_name	=> 'BOM_ITEM_PRODUCT_FAMILY'
3937 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
3938 			 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
3939                          , p_token_tbl		=> g_token_tbl
3940 			 );
3941                 END IF;
3942 
3943         END IF ; -- Product Family Check Ends
3944        IF NOT Verify_Item_Attributes(  p_Mesg_token_Tbl => l_Mesg_Token_Tbl
3945 		 		     , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3946 				     )
3947        THEN
3948               l_return_status := FND_API.G_RET_STS_ERROR;
3949        END IF;
3950 
3951 IF BOM_Globals.get_debug = 'Y' THEN
3952      error_handler.write_debug('Check Item Attribute Validation. . .' || l_Return_Status  );
3953 END IF;
3954 
3955 	-- Verify if the revised item is being referenced as common in
3956 	-- other orgs then it satisfies all the criteria required for the
3957 	-- component to be on the bill.
3958 	--
3959 
3960 	-- Bug 10094436 - pim-ait integration: provide custom hook to ait for item org assignment
3961 	--- custom hook API called for sun-integration
3962   IF BOM_Globals.get_debug = 'Y' THEN
3963 	  error_handler.write_debug(' Check if custom hook enabled: ' || BOM_PUB_COMMON_COMP.GET_CUSTOM_MODE(1.0) );
3964   END IF;
3965 
3966 	if BOM_PUB_COMMON_COMP.GET_CUSTOM_MODE(1.0) = 'Y' then
3967 		IF BOM_Globals.get_debug = 'Y' THEN
3968 		  error_handler.write_debug(' Before calling custom hook BOM_PUB_COMMON_COMP.ASSIGN_COMP_TO_ORGS assign component ' || g_rev_comp_Unexp_rec.component_item_id || ' - ' || to_char(sysdate, 'YYYY-MM-DD hh24:mi:ss') );
3969 	  END IF;
3970 
3971 	 BOM_PUB_COMMON_COMP.ASSIGN_COMP_TO_ORGS(
3972 	      p_api_version                 => 1.0,
3973         p_revised_item_id             => g_Rev_Comp_Unexp_Rec.revised_item_id,
3974         p_organization_id             => g_Rev_Comp_Unexp_Rec.organization_id,
3975         p_bill_sequence_id            => g_Rev_Comp_Unexp_Rec.bill_sequence_id,
3976         p_alt_bom_designator          => g_rev_component_rec.alternate_bom_code,
3977         p_component_item_id           => g_rev_comp_Unexp_rec.component_item_id,
3978         p_eco_name                    => g_rev_component_rec.eco_name,
3979         x_return_status               => l_return_status,
3980         x_Mesg_Token_Tbl              => l_Mesg_Token_Tbl) ;
3981 
3982     IF BOM_Globals.get_debug = 'Y' THEN
3983 		   error_handler.write_debug('After calling custom hook BOM_PUB_COMMON_COMP.ASSIGN_COMP_TO_ORGS - ' || to_char(sysdate, 'YYYY-MM-DD hh24:mi:ss') );
3984 	  END IF;
3985 	 end if;
3986 
3987 
3988 	l_result := Check_Common_Other_Orgs;
3989 
3990 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Check Common_Other_Orgs returned with result ' || to_char(l_result)); END IF;
3991 
3992 	IF l_result <> 0
3993   THEN
3994 	  IF l_result = 1
3995     THEN
3996 		  l_err_text := 'BOM_COMP_NOTEXIST_IN_OTHER_ORG';
3997     ELSIF l_result = 2 THEN
3998 		  l_err_text := 'BOM_COMP_NOT_BOMENABLED';
3999     ELSIF l_result = 3 THEN
4000   		l_err_text := 'BOM_COMP_NOT_ENG_IN_OTHER_ORGS';
4001     /*ELSIF l_result = 4 THEN
4002       l_err_text := 'BOM_COMMON_OP_SEQ_INVALID';*/
4003     END IF;
4004 
4005              IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4006              THEN
4007                 Error_Handler.Add_Error_Token
4008 		(  p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
4009 		 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
4010 		 , p_message_name	=> l_err_text
4011                  , p_token_tbl		=> g_token_tbl
4012 		 );
4013              END IF;
4014              l_return_status := FND_API.G_RET_STS_ERROR;
4015 	END IF;  -- Check if exists in other orgs if common Ends
4016 
4017    END IF; -- End of Operation Type CREATE
4018 
4019    /**************************************************************************
4020    --
4021    -- Operations specific to the Transaction Type of Update
4022    --
4023    **************************************************************************/
4024 
4025    IF p_control_rec.caller_type <> 'FORM' AND
4026       p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_UPDATE
4027    THEN
4028 
4029 	--
4030 	-- Verify that the user is not trying to Update non-updateable columns
4031 	--
4032 	IF p_Old_Rev_Component_Rec.Shipping_Allowed <>
4033 	   p_rev_component_rec.shipping_allowed
4034 	THEN
4035 		IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4036                 THEN
4037                 	Error_Handler.Add_Error_Token
4038                         ( p_message_name    => 'BOM_SHIP_ALLOWED_NOT_UPDATE'
4039                         , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4040                         , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4041                         , p_token_tbl      => g_token_tbl
4042                         );
4043                 END IF;
4044                 l_return_status := FND_API.G_RET_STS_ERROR;
4045 	END IF;
4046 
4047 --Since now we can update some attributes of common bills as well,
4048 --ensure that:
4049 --1. These updates on common bills are allowed
4050 --2. No other attribute other than material conrol attrs gets updated in common bills
4051 
4052 
4053 	       IF dereferenced_bom(p_rev_comp_unexp_rec.bill_sequence_id)
4054                THEN
4055 	         IF valid_common_bom_change(p_rev_component_rec => p_rev_component_rec,
4056 					                             p_Old_Rev_Component_Rec=>p_Old_Rev_Component_Rec)
4057 		          AND p_rev_component_rec.transaction_type = BOM_Globals.G_OPR_UPDATE
4058 	         THEN
4059            --if the change on common bom is only in the wip attributes,
4060 	         --allow it.
4061 		        NULL;
4062 	         ELSE
4063              Error_Handler.Add_Error_Token
4064              (  p_message_name	=> 'BOM_INVALID_COMMON_BOM_CHANGE'
4065              , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
4066              , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
4067              , p_token_tbl		=> g_token_tbl
4068              );
4069             l_return_status := FND_API.G_RET_STS_ERROR;
4070          	 END IF;
4071          END IF;
4072 
4073 	/*******************************************************************
4074 	--  Bug:4240031
4075 	-- Checks whether component operations exist when changing Optional
4076 	-- from Yes to No
4077 	--
4078 	*******************************************************************/
4079        IF Check_Optional_For_Comp_Ops
4080        THEN
4081            g_token_tbl(1).token_name := 'COMPONENT_ITEM_NAME';
4082            g_token_tbl(1).token_value := p_rev_component_rec.component_item_name;
4083            Error_Handler.Add_Error_Token
4084 			(  p_message_name	=> 'BOM_COMP_OPERATION_EXIST'
4085 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
4086 			 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
4087                          , p_token_tbl		=> g_token_tbl
4088 			 );
4089 	   l_return_status := FND_API.G_RET_STS_ERROR;
4090 	END IF;
4091 
4092 
4093 	/*******************bug:4240031 ends here***********************************/
4094 
4095 	IF p_rev_component_rec.old_effectivity_date IS NOT NULL AND
4096 	   p_rev_component_rec.old_effectivity_date <> FND_API.G_MISS_DATE AND
4097 	   Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_ECO_BO
4098 	THEN
4099                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4100                 THEN
4101                         Error_Handler.Add_Error_Token
4102                         ( p_message_name    => 'BOM_OLD_EFFECTIVITY_GIVEN'
4103                         , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4104                         , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4105                         , p_token_tbl      => g_token_tbl
4106                         );
4107                 END IF;
4108                 l_return_status := FND_API.G_RET_STS_ERROR;
4109 
4110 	END IF;
4111 
4112         IF p_rev_component_rec.old_operation_sequence_number IS NOT NULL AND
4113            p_rev_component_rec.old_operation_sequence_number <>
4114 							FND_API.G_MISS_NUM AND
4115 	   Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_ECO_BO
4116         THEN
4117                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4118                 THEN
4119                         Error_Handler.Add_Error_Token
4120                         ( p_message_name    => 'BOM_OLD_OP_SEQ_NUM_GIVEN'
4121                         , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4122                         , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4123                         , p_token_tbl      => g_token_tbl
4124                         );
4125                 END IF;
4126                 l_return_status := FND_API.G_RET_STS_ERROR;
4127 
4128         END IF;
4129 	--
4130 	-- ACD Type not updateable
4131 	--
4132 	IF p_rev_component_rec.acd_type <>
4133 	   p_old_rev_component_rec.acd_type AND
4134 	   Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_ECO_BO
4135 	THEN
4136 		IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4137                 THEN
4138                         Error_Handler.Add_Error_Token
4139                         ( p_message_name    => 'BOM_ACD_TYPE_NOT_UPDATEABLE'
4140                         , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4141                         , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4142                         , p_token_tbl      => g_token_tbl
4143                         );
4144                 END IF;
4145                 l_return_status := FND_API.G_RET_STS_ERROR;
4146 	END IF;
4147 
4148 	--
4149 	-- Verify that the user is not trying to update a component which
4150 	-- is Disabled on the ECO
4151 	--
4152 	IF p_old_rev_component_rec.acd_type = 3 AND
4153 	   Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_ECO_BO
4154 	THEN
4155                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4156                 THEN
4157                         Error_Handler.Add_Error_Token
4158                         ( p_message_name    => 'BOM_COMPONENT_DISABLED'
4159                         , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4160                         , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4161                         , p_token_tbl      => g_token_tbl
4162                         );
4163                 END IF;
4164                 l_return_status := FND_API.G_RET_STS_ERROR;
4165 	END IF;
4166 
4167 	-- User cannot update to_end_item_unit_number when the component
4168 	-- is disabled.
4169 
4170 	IF NVL(p_rev_component_rec.acd_type, 1) = 3 AND
4171 	   p_rev_component_rec.to_end_item_unit_number <>
4172 		p_old_rev_component_rec.to_end_item_unit_number
4173 	THEN
4174 		IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4175                 THEN
4176                         Error_Handler.Add_Error_Token
4177                         ( p_message_name    => 'BOM_DISABLE_TOUNIT_NONUPD'
4178                         , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4179                         , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4180                         , p_token_tbl      => g_token_tbl
4181                         );
4182                 END IF;
4183                 l_return_status := FND_API.G_RET_STS_ERROR;
4184         END IF;
4185 
4186    END IF;  /* Operation UPDATE ENDS */
4187 
4188    /*************************************************************************
4189    --
4190    -- All operations that would be common for Create and Update with slight
4191    --variation in
4192    -- checks.
4193    --
4194    **************************************************************************/
4195    IF p_rev_component_rec.Transaction_Type IN
4196       (BOM_GLOBALS.G_OPR_CREATE, BOM_GLOBALS.G_OPR_UPDATE)
4197    THEN
4198         /*********************************************************************
4199         --
4200         -- Verify yield factor
4201         -- IF Component is Option Class or bill is planning
4202         -- then yield must be 1
4203         -- If yield is >0 and less than 1 then give a warning.
4204         --
4205         *********************************************************************/
4206         IF ((p_control_rec.caller_type = 'FORM' AND
4207              p_control_rec.validation_controller = 'YIELD')
4208             OR
4209              p_control_rec.caller_type <> 'FORM')
4210            AND
4211            p_rev_component_rec.projected_yield <> 1 THEN
4212                 IF g_assy_item_type     = 3 -- Planning parent
4213                    OR
4214                    g_comp_item_type     = 2  -- Option Class component
4215                 THEN
4216                         IF FND_MSG_PUB.Check_Msg_Level
4217                            (FND_MSG_PUB.G_MSG_LVL_ERROR)
4218                         THEN
4219                                 g_token_tbl(2).token_name  :=
4220                                                 'REVISED_ITEM_NAME';
4221                                 g_token_tbl(2).token_value :=
4222                                         g_rev_component_Rec.revised_item_name;
4223                                 Error_Handler.Add_Error_Token
4224                                 (  p_Message_Name    => 'BOM_COMP_YIELD_NOT_ONE'
4225                                  , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4226                                  , x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4227                                  , p_Token_Tbl       => g_Token_Tbl
4228                                  );
4229                                 g_token_tbl.delete(2);
4230                         END IF;
4231                         l_return_status := FND_API.G_RET_STS_ERROR;
4232                 END IF;
4233 
4234                 IF p_rev_component_rec.projected_yield <=0
4235                 THEN
4236                         IF FND_MSG_PUB.Check_Msg_Level
4237                            (FND_MSG_PUB.G_MSG_LVL_ERROR)
4238                         THEN
4239                                 g_token_tbl(2).token_name  :=
4240                                                 'REVISED_ITEM_NAME';
4241                                 g_token_tbl(2).token_value :=
4242                                         g_rev_component_Rec.revised_item_name;
4243                                 Error_Handler.Add_Error_Token
4244                                 (  p_Message_Name    => 'BOM_COMP_YIELD_NOT_NEGATIVE'
4245                                  , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4246                                  , x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4247                                  , p_Token_Tbl       => g_Token_Tbl
4248                                  );
4249                                 g_token_tbl.delete(2);
4250                         END IF;
4251                         l_return_status := FND_API.G_RET_STS_ERROR;
4252                 END IF;
4253 
4254                 IF p_rev_component_rec.projected_yield > 1
4255                 THEN
4256                         IF FND_MSG_PUB.Check_Msg_Level
4257                            (FND_MSG_PUB.G_MSG_LVL_ERROR)
4258                         THEN
4259                                 -- Log warning
4260 
4261                                 Error_Handler.Add_Error_Token
4262                                 (  p_Message_Name    => 'BOM_YIELD_WARNING'
4263                                  , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4264                                  , x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4265                                  , p_message_type    => 'W'
4266                                 );
4267                         END IF;
4268                 END IF;
4269         END IF;
4270 
4271        -- BASIS type should be 2 or null
4272 
4273        IF not(p_rev_component_rec.BASIS_TYPE is null or  p_rev_component_rec.BASIS_TYPE=2
4274             or p_rev_component_rec.BASIS_TYPE =FND_API.G_MISS_NUM)
4275          THEN
4276                Error_Handler.Add_Error_Token
4277                (  p_Message_Name    => 'BOM_BASIS_TYPE_INVALID'
4278                 , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4279                 , x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4280                 , p_message_type    => 'E'
4281                );
4282             l_return_status := FND_API.G_RET_STS_ERROR;
4283        END IF;
4284 
4285       -- Validations Related to Basis Type : Basis_type can not be lot if the
4286       -- WIP supply type is Phantom.  Basis_type can not be lot for Model/OC items
4287 
4288        IF (p_rev_component_rec.WIP_SUPPLY_TYPE =6 AND p_rev_component_rec.BASIS_TYPE=2)
4289          THEN
4290                Error_Handler.Add_Error_Token
4291                (  p_Message_Name    => 'BOM_LOT_BASED_PHANTOM'
4292                 , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4293                 , x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4294                 , p_message_type    => 'E'
4295                );
4296             l_return_status := FND_API.G_RET_STS_ERROR;
4297        END IF;
4298 
4299       -- For Components of PTO Kits, Models, Option Classes, Basis type should be item.
4300    	IF(g_Assy_PTO_flag ='Y' and  p_rev_component_rec.BASIS_TYPE=2) then
4301                Error_Handler.Add_Error_Token
4302                (  p_Message_Name    => 'BOM_LOT_BASED_PTO'
4303                 , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4304                 , x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4305                 , p_message_type    => 'E'
4306                );
4307             l_return_status := FND_API.G_RET_STS_ERROR;
4308    	END IF;
4309 
4310      --For ATO model, option class bills, optional,model,option class
4311      -- components should not be lot based.
4312    	IF ( p_rev_component_rec.BASIS_TYPE=2
4313      	    and (p_rev_component_rec.OPTIONAL=1
4314                or g_Comp_Item_Type in (Bom_Globals.G_MODEL, Bom_Globals.G_OPTION_CLASS) )) THEN
4315                Error_Handler.Add_Error_Token
4316                (  p_Message_Name    => 'BOM_LOT_BASED_ATO'
4317                 , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4318                 , x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4319                 , p_message_type    => 'E'
4320                );
4321             l_return_status := FND_API.G_RET_STS_ERROR;
4322    	END IF;
4323 
4324      /* Validations for OPM convergence Project, Dual UOM tracking items should not be allowed
4325         for updates and creates */
4326        IF (G_Assy_Tracking_Quantity_Ind <>'P' or G_Comp_Tracking_Quantity_Ind <>'P') then
4327                Error_Handler.Add_Error_Token
4328                (  p_Message_Name    => 'BOM_DUAL_UOM_ITEMS'
4329                 , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4330                 , x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
4331                 , p_message_type    => 'E'
4332                );
4333             l_return_status := FND_API.G_RET_STS_ERROR;
4334        END IF;
4335 
4336      IF p_control_rec.caller_type <> 'FORM'
4337      THEN
4338 	--
4339 	-- Verify that the disable date is greater than effectivity date
4340 	-- for both operations Create and Update
4341 	--
4342 
4343 	-- If the transaction type is CREATE, then the new_effective_date column is
4344 	-- ignored.
4345 	-- but if the transaction type is update, then the new_effectivity_date can be
4346 	-- used to update the effectivity date of a future effective component to bring it closer
4347 	-- in its effectivity cyle. In this the validation for Insert and Update will differ
4348 	-- If the new_effectivity_date col is not null and missing then it must be greater or =
4349 	-- to SYSDATE.
4350 	-- Also, disable_date must be greater or equal to the new_effective_date
4351 	IF p_rev_component_rec.transaction_type in (BOM_GLOBALS.G_OPR_CREATE,
4352 						   BOM_GLOBALS.G_OPR_UPDATE) AND
4353 	   p_rev_component_rec.disable_date <
4354 	   	p_rev_component_rec.start_effective_date THEN
4355 		IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4356                 THEN
4357                 	Error_Handler.Add_Error_Token
4358 			(  p_message_name	=> 'BOM_COMP_DIS_DATE_INVALID'
4359 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
4360 			 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
4361 			 , p_Token_Tbl		=> g_Token_Tbl
4362                          );
4363                 END IF;
4364                 l_return_status := FND_API.G_RET_STS_ERROR;
4365 
4366 	ELSIF p_rev_component_rec.transaction_type = BOM_GLOBALS.G_OPR_UPDATE AND
4367 	      p_rev_component_rec.new_effectivity_date IS NOT NULL AND
4368 	      p_rev_component_rec.new_effectivity_date <> FND_API.G_MISS_DATE AND
4369 	      (
4370    --  p_rev_component_rec.new_effectivity_date < SYSDATE  OR    -- Bug3281414
4371 		 p_rev_component_rec.disable_date < p_rev_component_rec.new_effectivity_date
4372 	       )
4373 	THEN
4374                  Error_Handler.Add_Error_Token
4375                  (  p_message_name       => 'BOM_COMP_DIS_DATE_INVALID'
4376                   , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4377                   , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4378                   , p_Token_Tbl          => g_Token_Tbl
4379                   );
4380                   l_return_status := FND_API.G_RET_STS_ERROR;
4381 	END IF;
4382 
4383 --	dbms_output.put_line('Verified disable date . . . ' || l_return_status);
4384 
4385 	/********************************************************************
4386 	--
4387 	-- Verify that the number of reference designators equals the component
4388 	-- quantity if quantity related = 1
4389 	--
4390 	**********************************************************************/
4391   /* -- Bug No: 3522842. Quantity Related checks will be done in BOM_Bo_Pvt package.
4392 	IF p_rev_component_rec.quantity_related = 1
4393 	THEN
4394 		FOR cnt_desg IN c_RefDesgs
4395 		LOOP
4396 		   	IF cnt_desg.number_of_desgs <>
4397 			   p_rev_component_rec.quantity_per_assembly
4398 			THEN
4399 				-- GIVE A WARNING
4400                                 --
4401 				Error_Handler.Add_Error_Token
4402                                 ( p_message_name  => 'BOM_QTY_REL_QTY_REF_DESG'
4403                                 , p_Mesg_Token_Tbl=> l_Mesg_Token_Tbl
4404                                 , x_Mesg_Token_Tbl=> l_Mesg_Token_Tbl
4405                                 , p_Token_Tbl     => g_Token_Tbl
4406                                 , p_message_type  => 'W'
4407 				);
4408 			END IF;
4409 		END LOOP;
4410 	END IF;
4411   */
4412 
4413 	/********************************************************************
4414 	--
4415 	-- Verify that if the user is trying to create or update rev. comp
4416 	-- to quantity related when the quantity_per_assembly is fractional
4417 	--
4418 	*********************************************************************/
4419 	IF round(p_rev_component_rec.quantity_per_assembly) <>
4420 	   p_rev_component_rec.quantity_per_assembly AND
4421 	   p_rev_component_rec.quantity_related = 1
4422 	THEN
4423 		Error_Handler.Add_Error_Token
4424                 ( p_message_name  => 'BOM_QTY_REL_QTY_FRACTIONAL'
4425                 , p_Mesg_Token_Tbl=> l_Mesg_Token_Tbl
4426                 , x_Mesg_Token_Tbl=> l_Mesg_Token_Tbl
4427                 , p_Token_Tbl     => g_Token_Tbl
4428                  );
4429 
4430 		l_return_status := FND_API.G_RET_STS_ERROR;
4431 	END IF;
4432 
4433 	/********************************************************************
4434    	--
4435 	-- If the Operation is Create with an Acd_Type of Change or Disable
4436 	-- then component pointed to by old_component_sequence_id should
4437 	-- already be implemented
4438 	--
4439 	*********************************************************************/
4440 
4441 	/** This allowed thru the form and should be allowed thru the BO
4442 	    as well
4443 
4444 	IF   p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_CREATE AND
4445        	   p_rev_component_rec.acd_type  IN (2, 3)
4446    	THEN
4447 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Old sequence: ' || to_char(p_rev_comp_Unexp_rec.old_component_sequence_id)); END IF;
4448 		BEGIN
4449 			SELECT 'Component Implemented'
4450 		  	  INTO l_dummy
4451 		  	  FROM bom_inventory_components
4452 		 	 WHERE component_sequence_id =
4453 			       p_rev_comp_Unexp_rec.old_component_sequence_id
4454 		   	   AND implementation_date IS NOT NULL;
4455 
4456 		EXCEPTION
4457 		WHEN NO_DATA_FOUND THEN
4458 			-- component is yet not implemented
4459 	        	IF FND_MSG_PUB.Check_Msg_Level
4460 			   (FND_MSG_PUB.G_MSG_LVL_ERROR)
4461         		THEN
4462             		    Error_Handler.Add_Error_Token
4463 			    (  p_message_name   => 'BOM_OLD_COMP_SEQ_ID_INVALID'
4464 			     , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4465 			     , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4466 			     , p_Token_Tbl	=> g_Token_Tbl
4467                              );
4468         		END IF;
4469         		l_return_status := FND_API.G_RET_STS_ERROR;
4470 		WHEN OTHERS THEN
4471 --			dbms_output.put_line(SQLERRM);
4472                       Error_Handler.Add_Error_Token
4473 		      (  p_message_name	=> NULL
4474                        , p_message_text	=> 'ERROR Rev Cmp entity validate ' ||
4475 					   SUBSTR(SQLERRM, 1, 30) || ' '    ||
4476 					   TO_CHAR(SQLCODE)
4477 		       , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4478 		       , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4479                        );
4480 			RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4481 		END;
4482    	END IF;
4483 
4484 	** End of Comment **/
4485 
4486         -- If the user is attempting to change the from_end_item_unit number or to_end_item_unit_number
4487         -- then verify that the change is not creating a component with overlapping dates
4488         IF (p_rev_component_rec.from_end_item_unit_number IS NOT NULL AND
4489             p_rev_component_rec.new_from_end_item_unit_number IS NOT NULL AND
4490             p_rev_component_rec.new_from_end_item_unit_number <> FND_API.G_MISS_CHAR
4491            )
4492         THEN
4493                 l_result := Check_Unit_Number();
4494 
4495                 IF (l_result = 1)
4496                 THEN
4497                         g_Token_Tbl(1).Token_Name := 'REVISED_ITEM_NAME';
4498                         g_Token_Tbl(1).Token_Value :=
4499                         g_Rev_Component_rec.revised_item_name;
4500                         g_Token_Tbl(1).Token_Name := 'NEW_FROM_UNIT_NUMBER';
4501                         g_Token_Tbl(1).Token_Value := g_Rev_Component_rec.new_from_end_item_unit_number;
4502 
4503                         Error_Handler.Add_Error_Token
4504                         (  p_Message_Name   => 'BOM_NEW_FROM_UNIT_NUM_OVERLAP'
4505                          , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4506                          , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4507                          , p_Token_Tbl      => g_Token_Tbl
4508                          );
4509                         --
4510                         -- reset the first token to revised component name.
4511                         --
4512                         g_Token_Tbl(1).Token_Name := 'REVISED_COMPONENT_NAME';
4513                         g_Token_Tbl(1).Token_Value :=
4514                                         g_Rev_Component_rec.component_item_name;
4515                         l_return_status := FND_API.G_RET_STS_ERROR;
4516                 END IF;
4517         END IF;
4518 
4519 
4520         /********************************************************************
4521         -- Added by MK on 02/02/2001
4522         -- If the rev component is Create with an Acd_Type of Change or Disable
4523         -- then component pointed to by old_component_sequence_id should
4524         -- be valid against cusror old_comp_csr's conditions.
4525         *********************************************************************/
4526         IF p_rev_component_rec.transaction_type = BOM_GLOBALS.G_OPR_CREATE AND
4527            p_rev_component_rec.acd_type  IN (2, 3)
4528         THEN
4529 
4530 IF Bom_Globals.Get_Debug = 'Y' THEN
4531     Error_Handler.Write_Debug('Checking old component : '|| to_char(p_rev_comp_unexp_rec.old_component_sequence_id));
4532 END IF;
4533 
4534              l_eco_for_production  := NVL(Bom_Globals.Get_Eco_For_Production,2)  ;
4535 
4536              FOR old_comp_rec IN old_comp_csr
4537                      (p_rev_comp_unexp_rec.old_component_sequence_id,
4538                       l_eco_for_production)
4539              LOOP
4540                  -- component is invalid
4541                  IF FND_MSG_PUB.Check_Msg_Level
4542                            (FND_MSG_PUB.G_MSG_LVL_ERROR)
4543                  THEN
4544                             Error_Handler.Add_Error_Token
4545                             (  p_message_name   => 'BOM_OLD_COMP_SEQ_ID_INVALID'
4546                              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4547                              , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4548                              , p_Token_Tbl      => g_Token_Tbl
4549                              );
4550                  END IF;
4551                  l_return_status := FND_API.G_RET_STS_ERROR;
4552              END LOOP ;
4553 
4554 IF Bom_Globals.Get_Debug = 'Y' THEN
4555     Error_Handler.Write_Debug('After checking old component. Return status is  '|| l_return_status);
4556 END IF;
4557 
4558         END IF;
4559 
4560       --IF Nvl(Bom_Globals.Get_Validate_For_Plm,'N') = 'N'
4561       --THEN
4562         -- Modified by MK on 11/13/00
4563         IF ( p_rev_component_rec.operation_sequence_number <> 1 AND
4564 --             NVL(p_rev_Component_rec.ACD_Type, 1) = 1
4565              p_rev_Component_rec.ACD_Type = 1
4566             ) OR  -- bug 5386719
4567            ( p_rev_component_rec.operation_sequence_number <> 1 AND
4568              p_rev_Component_rec.ACD_Type is NULL and
4569               p_rev_component_rec.transaction_type = BOM_Globals.G_OPR_CREATE
4570             ) OR
4571            ( p_rev_component_rec.operation_sequence_number <> 1 AND
4572              NVL(p_rev_Component_rec.ACD_Type, 1) = 2           AND
4573              NVL(p_rev_component_rec.new_operation_sequence_number,FND_API.G_MISS_NUM)
4574                  = FND_API.G_MISS_NUM
4575              AND (NVL(p_old_rev_component_rec.operation_sequence_number, 1) <>
4576  	                NVL(p_rev_component_rec.operation_sequence_number, 1) ) --added for bug 12329790
4577             ) OR
4578            ( NVL(p_rev_component_rec.new_operation_sequence_number,1) <> 1 AND
4579              ( ( p_rev_component_rec.ACD_Type = 2 AND
4580                  p_rev_component_rec.transaction_type =
4581                   BOM_Globals.G_OPR_CREATE
4582                 ) OR
4583                  p_rev_component_rec.transaction_type =
4584                   BOM_Globals.G_OPR_UPDATE
4585               ) AND
4586 	      (
4587                NVL(p_old_rev_component_rec.operation_sequence_number, 1) <>
4588                NVL(p_rev_component_rec.new_operation_sequence_number, 1) AND
4589 	       p_rev_component_rec.new_operation_sequence_number <> FND_API.G_MISS_NUM
4590 	      )
4591             )
4592 	THEN
4593 
4594         	/*************************************************************
4595         	--
4596         	-- If Operation_Seq_Num is not 1 then there must be a routing
4597         	-- for the revised item.
4598         	-- Added by AS on 08/20/99 to accomodate calls from the
4599 		-- ECO form to perform this validation.
4600         	*************************************************************/
4601    --Bug 9076970 changes begin
4602     IF  Check_Routing_Exists THEN
4603 		/*IF NOT Check_Routing_Exists
4604 		THEN
4605                         IF FND_MSG_PUB.Check_Msg_Level
4606                            (FND_MSG_PUB.G_MSG_LVL_ERROR)
4607                         THEN
4608                             Error_Handler.Add_Error_Token
4609                             (  p_message_name   => 'BOM_ONLY_ONE'
4610                              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4611                              , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4612                              , p_Token_Tbl      => g_Token_Tbl
4613                              );
4614                         END IF;
4615                         l_return_status := FND_API.G_RET_STS_ERROR;
4616 		ELSE */
4617 		 --Bug 9076970 changes end
4618 		/*************************************************************
4619 		--
4620 		-- If Operation_Seq_Num is not NULL then it must be unique in
4621 		-- case of Creates and in Case of Updates new_operation_sequence
4622 		-- must be valid if the user is trying to update
4623 		-- operation_sequence_number
4624 		**************************************************************/
4625 
4626 		   l_result := Check_Op_Seq(l_is_item_unit_controlled);
4627        --arudresh_debug('Result after check_op_seq '||l_result);
4628 
4629 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Check_Op_Seq returned with : ' || l_result); END IF;
4630 		   IF l_result = 1
4631 		   THEN
4632 				g_Token_Tbl(1).Token_Name := 'REVISED_ITEM_NAME';
4633 				g_Token_Tbl(1).Token_Value :=
4634 					g_Rev_Component_rec.revised_item_name;
4635                         	Error_Handler.Add_Error_Token
4636 				(  p_Message_Name   => 'BOM_OP_SEQ_NUM_INVALID'
4637 			 	 , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4638 				 , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4639 				 , p_Token_Tbl	    => g_Token_Tbl
4640                                 );
4641 				--
4642 				-- reset the first token to revised component name.
4643 				--
4644 				g_Token_Tbl(1).Token_Name := 'REVISED_COMPONENT_NAME';
4645                                 g_Token_Tbl(1).Token_Value :=
4646                                         g_Rev_Component_rec.component_item_name;
4647                 	l_return_status := FND_API.G_RET_STS_ERROR;
4648 		/* bug:4240031 If there are comp ops then op seq num can not be
4649 		 * changed to that
4650 		*/
4651 		   ELSIF l_result = 3 THEN
4652 		               g_Token_Tbl(1).Token_Name := 'REVISED_COMPONENT_NAME';
4653                                g_Token_Tbl(1).Token_Value := g_Rev_Component_rec.component_item_name;
4654 			       Error_Handler.Add_Error_Token
4655 				(  p_Message_Name   => 'BOM_COMP_OPS_OP_SEQ'
4656 			 	 , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4657 				 , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4658 				 , p_Token_Tbl	    => g_Token_Tbl
4659                                 );
4660                                l_return_status := FND_API.G_RET_STS_ERROR;
4661 		   ELSIF l_result = 2 THEN
4662         IF Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_BOM_BO THEN
4663              g_Token_Tbl(2).Token_Name := 'OP_SEQ_NUM';
4664                                g_Token_Tbl(2).Token_Value :=
4665                                to_char
4666                                (g_Rev_Component_rec.operation_sequence_number);
4667                               Error_Handler.Add_Error_Token
4668             (  p_message_name	=> 'BOM_OP_SEQ_NUM_NOT_UNIQUE'
4669              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4670              , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4671              , p_Token_Tbl	=> g_Token_Tbl
4672                               );
4673             g_Token_Tbl.DELETE(2);
4674                               l_return_status := FND_API.G_RET_STS_ERROR;
4675         ELSE
4676              g_Token_Tbl(2).Token_Name := 'OP_SEQ_NUM';
4677                                g_Token_Tbl(2).Token_Value :=
4678                                to_char
4679                                (g_Rev_Component_rec.operation_sequence_number);
4680                               Error_Handler.Add_Error_Token
4681             (  p_message_name	=> 'BOM_OP_SEQ_NUM_NOT_UNIQUE'
4682              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4683              , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4684              , p_Token_Tbl	=> g_Token_Tbl
4685              , p_message_type   => 'W'
4686                               );
4687             g_Token_Tbl.DELETE(2);
4688         END IF;
4689 		   ELSIF l_result = 4 THEN
4690 			       Error_Handler.Add_Error_Token
4691 				(  p_Message_Name   => 'BOM_COMMON_OP_SEQ_INVALID'
4692 			 	 , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4693 				 , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4694 				 , p_Token_Tbl	    => g_Token_Tbl
4695                             );
4696          l_return_status := FND_API.G_RET_STS_ERROR;
4697 		   ELSIF l_result = 0 AND
4698 		      p_Rev_Component_rec.old_operation_sequence_number
4699 		      IS NOT NULL AND
4700 		      p_Rev_Component_rec.old_operation_sequence_number <>
4701 			FND_API.G_MISS_NUM AND Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_BOM_BO
4702 		   THEN
4703 			BEGIN
4704 			     SELECT operation_seq_num
4705 			       INTO l_result
4706 			       FROM bom_inventory_components
4707 			      WHERE component_sequence_id =
4708 			       p_rev_comp_unexp_rec.old_component_sequence_id
4709 			        AND operation_seq_num =
4710 			      p_Rev_Component_rec.old_operation_sequence_number;
4711 
4712 			    EXCEPTION
4713 				WHEN OTHERS THEN
4714 					l_result := 0;
4715 			END;
4716 
4717 			IF l_result = 0
4718                         THEN
4719                              g_Token_Tbl(2).Token_Name := 'OLD_OP_SEQUENCE_NUM';
4720                              g_Token_Tbl(2).Token_Value :=
4721                              to_char
4722                             (g_Rev_Component_rec.old_operation_sequence_number);
4723                             Error_Handler.Add_Error_Token
4724                             (  p_message_name   => 'BOM_OLD_OP_SEQ_NUM_GIVEN'
4725                              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4726                              , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
4727                              , p_Token_Tbl      => g_Token_Tbl
4728                             );
4729                             g_Token_Tbl.DELETE(2);
4730                             l_return_status := FND_API.G_RET_STS_ERROR;
4731 			END IF;
4732 		   END IF;
4733 		END IF;
4734 	END IF; -- Operation_seq_Num Check Ends.
4735       --END IF; -- Validate for plm ends
4736     END IF;
4737 
4738 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Op seq num validation completed with ' || l_return_status); END IF;
4739 
4740 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('BO identifier is '||Bom_Globals.Get_Bo_Identifier); END IF;
4741 
4742   IF Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_ECO_BO AND NVL(p_rev_Component_rec.ACD_Type,1) <> 3 THEN
4743     IF Nvl(Bom_Globals.Get_Validate_For_Plm,'N') = 'N'
4744     THEN
4745      IF (p_control_rec.caller_type = 'FORM' AND
4746 	 p_control_rec.write_to_db)
4747         OR
4748 	p_control_rec.caller_type <> 'FORM'
4749      THEN
4750 
4751 	IF NOT l_is_item_unit_controlled
4752 	THEN
4753 
4754            /********************************************************************
4755            --
4756            -- Check for Overlapping dates for the component being inserted.
4757            --
4758            *********************************************************************/
4759 
4760 	   IF Check_Overlap_Dates
4761 	       (X_Effectivity_date	=> p_rev_component_rec.start_effective_date,
4762 	    	X_Disable_date	=> p_rev_component_rec.disable_date,
4763 	    	X_Member_Item_Id	=> p_rev_comp_unexp_rec.component_item_id,
4764 	    	X_Bill_Sequence_id  => p_rev_comp_unexp_rec.bill_sequence_id,
4765 	    	X_Rowid		=> NULL,
4766             	X_Comp_Seq_id       => p_rev_comp_unexp_rec.old_component_sequence_id,  --Fixed for Bug No 6688502
4767             	X_Operation_Seq_Num => p_rev_component_rec.operation_sequence_number)
4768       	   THEN
4769            	--if function return true then component dates overlapp
4770 
4771 	   	IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_SUCCESS)
4772            	THEN
4773                 --added for bug 9647673 (begin)
4774                 g_token_tbl.delete;
4775                 g_token_tbl(1).token_name  := 'REVISED_COMPONENT_NAME';
4776                 g_token_tbl(1).token_value := p_rev_component_rec.Component_Item_Name;
4777 
4778                 g_token_tbl(2).token_name  := 'REVISED_ITEM_NAME';
4779                 g_token_tbl(2).token_value := p_rev_component_rec.Revised_Item_Name;
4780 
4781                --added for bug 9647673 (end)
4782 
4783            		Error_Handler.Add_Error_Token
4784 			(  p_Message_Name	=> 'BOM_COMP_OPSEQ_DATE_OVERLAP'
4785 		 	, p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
4786 			, p_token_tbl		=> g_token_tbl
4787 		 	, x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
4788 			, p_message_type	=> 'W' --Changed from W to E for bug 8839091; changed back to W for bug 9780939
4789                  	);
4790 		--l_return_status := FND_API.G_RET_STS_ERROR; --Added line, bug 9737140; commented out for bug 9780939
4791            	END IF;
4792                 -- Since Open Interface allows for Dates to be
4793 	   	-- overlapping do set the error status.
4794       	   END IF;
4795 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Verified overlapping dates . . . ' || l_return_status); END IF;
4796 
4797 	ELSE
4798 
4799            /********************************************************************
4800            --
4801            -- Check for Overlapping numbers for the component being inserted.
4802            --
4803            *********************************************************************/
4804            IF 	Check_Overlap_Numbers
4805            	(X_From_end_item_number
4806 			=> p_rev_component_rec.from_end_item_unit_number,
4807             	 X_to_end_item_number
4808 			=> p_rev_component_rec.to_end_item_unit_number,
4809             	 X_Member_Item_Id    => p_rev_comp_unexp_rec.component_item_id,
4810             	 X_Bill_Sequence_id  => p_rev_comp_unexp_rec.bill_sequence_id,
4811             	 X_Rowid             => NULL,
4812             	 X_Comp_Seq_id	=> p_rev_comp_unexp_rec.component_sequence_id,
4813 	    	 X_Operation_Seq_Num	=>
4814 			p_rev_component_rec.operation_sequence_number)
4815 	   THEN
4816            	--if function return true then component dates overlapp
4817 
4818            	IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_SUCCESS)
4819            	THEN
4820                 	Error_Handler.Add_Error_Token
4821                 	(  p_Message_Name       => 'BOM_COMP_OPSEQ_UNIT_OVERLAP'
4822                  	, p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4823                  	, x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4824                         , p_token_tbl           => g_token_tbl
4825                         , p_message_type        => 'W'
4826                  	);
4827            	END IF;
4828            	-- Since Open Interface allows for Dates to be
4829            	-- overlapping do set the error status.
4830 	   END IF;
4831         END IF;
4832       END IF;
4833      END IF; -- Validate for PLM check ends
4834   ELSIF Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_BOM_BO THEN
4835         --begin changes for bug 9920911
4836  	      IF p_rev_component_rec.transaction_type = BOM_GLOBALS.G_OPR_CREATE THEN
4837  	           l_new_op_seq_num := p_rev_component_rec.operation_sequence_number;
4838  	      ELSIF p_rev_component_rec.transaction_type = BOM_GLOBALS.G_OPR_UPDATE THEN
4839  	           l_new_op_seq_num := nvl(p_rev_component_rec.new_operation_sequence_number, p_rev_component_rec.operation_sequence_number);
4840  	      END IF;
4841  	 --end changes for bug 9920911
4842       IF Nvl(Bom_Globals.Get_Validate_For_Plm,'N') = 'N'
4843       THEN
4844 
4845 	IF NOT l_is_item_unit_controlled
4846 	THEN
4847 
4848 
4849            /********************************************************************
4850            --
4851            -- Check for Overlapping dates for the component being inserted.
4852            --
4853            *********************************************************************/
4854 
4855   /* Fix for bug 4585076 - While calling check_overlap_dates function, if txn type is create then pass start_effective_date
4856               else if txn type is update then pass new_effectivity_date.
4857            */
4858      IF p_rev_component_rec.transaction_type = BOM_GLOBALS.G_OPR_CREATE THEN
4859           l_new_compare_date := p_rev_component_rec.start_effective_date;
4860      ELSIF p_rev_component_rec.transaction_type = BOM_GLOBALS.G_OPR_UPDATE THEN
4861           l_new_compare_date := p_rev_component_rec.new_effectivity_date;
4862      END IF;
4863 
4864 	   IF Bom_Validate_Comp_Operation.Check_Overlap_Dates
4865 	       (p_Effectivity_date	=> l_new_compare_date, /*p_rev_component_rec.start_effective_date,*/
4866 	    	p_Disable_date	=> p_rev_component_rec.disable_date,
4867 	    	p_Component_Item_Id	=> p_rev_comp_unexp_rec.component_item_id,
4868 	    	p_Bill_Sequence_id  => p_rev_comp_unexp_rec.bill_sequence_id,
4869                 p_Component_Sequence_id => p_rev_comp_unexp_rec.component_sequence_id,
4870 	    	p_Rowid		=> p_rev_comp_unexp_rec.rowid,
4871             	p_Operation_Seq_Num =>  l_new_op_seq_num, --p_rev_component_rec.operation_sequence_number, --9920911
4872                 p_entity   => 'RC')
4873       	   THEN
4874            	--if function return true then component dates overlapp
4875 
4876 	   	IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_SUCCESS)
4877            	THEN
4878                 --added for bug 9647673 (begin)
4879                 g_token_tbl.delete;
4880                 g_token_tbl(1).token_name  := 'REVISED_COMPONENT_NAME';
4881                 g_token_tbl(1).token_value := p_rev_component_rec.Component_Item_Name;
4882 
4883                 g_token_tbl(2).token_name  := 'REVISED_ITEM_NAME';
4884                 g_token_tbl(2).token_value := p_rev_component_rec.Revised_Item_Name;
4885 
4886                --added for bug 9647673 (end)
4887 
4888            		Error_Handler.Add_Error_Token
4889 			(  p_Message_Name	=> 'BOM_COMP_OPSEQ_DATE_OVERLAP'
4890 		 	, p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
4891 			, p_token_tbl		=> g_token_tbl
4892 		 	, x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
4893 			, p_message_type	=> 'E'
4894                  	);
4895            	END IF;
4896              	l_return_status := FND_API.G_RET_STS_ERROR;
4897       	   END IF;
4898 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Verified overlapping dates . . . ' || l_return_status); END IF;
4899 
4900 	ELSE
4901 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('I am here Inside Unit Eff'); END IF;
4902 
4903            /********************************************************************
4904            --
4905            -- Check for Overlapping numbers for the component being inserted.
4906            --
4907            *********************************************************************/
4908            IF 	Bom_Validate_Comp_Operation.Check_Overlap_Numbers
4909            	(p_From_end_item_number
4910 			=> p_rev_component_rec.from_end_item_unit_number,
4911             	 p_to_end_item_number
4912 			=> p_rev_component_rec.to_end_item_unit_number,
4913             	 p_Component_Item_Id    => p_rev_comp_unexp_rec.component_item_id,
4914             	 p_Bill_Sequence_id  => p_rev_comp_unexp_rec.bill_sequence_id,
4915             	 p_Rowid             => p_rev_comp_unexp_rec.rowid,
4916                  p_Component_Sequence_id => p_rev_comp_unexp_rec.component_sequence_id,
4917 	    	 p_Operation_Seq_Num	=>  l_new_op_seq_num,
4918 			--p_rev_component_rec.operation_sequence_number, --9920911
4919                  p_entity     => 'RC')
4920 	   THEN
4921            	--if function return true then component unit numbers overlapp
4922 
4923            	IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_SUCCESS)
4924            	THEN
4925                 	Error_Handler.Add_Error_Token
4926                 	(  p_Message_Name       => 'BOM_COMP_OPSEQ_UNIT_OVERLAP'
4927                  	, p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4928                  	, x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
4929                         , p_token_tbl           => g_token_tbl
4930                         , p_message_type        => 'E'
4931                  	);
4932            	END IF;
4933              	l_return_status := FND_API.G_RET_STS_ERROR;
4934 	   END IF;
4935         END IF;
4936       END IF; -- Validate for Plm check ends
4937      END IF;
4938 
4939 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Verified overlapping unit numbers. . .' || l_return_status); END IF;
4940 
4941 
4942 	If (p_rev_component_rec.Transaction_Type=BOM_GLOBALS.G_OPR_CREATE AND g_Assy_Item_Type = Bom_Globals.G_PRODUCT_FAMILY) THEN
4943 		l_Result := CheckUnique_PF_Member;
4944 		IF l_Result = 1 Then
4945 		   IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4946                    THEN
4947 			g_Token_Tbl(2).Token_Name := 'pf_item';
4948 			g_Token_Tbl(2).Token_Value :=
4949 			g_rev_component_rec.revised_item_name;
4950                         Error_Handler.Add_Error_Token
4951                         ( p_message_name        => 'BOM_PF_MEMBER_ALREADY_EXISTS'
4952                         , p_Mesg_Token_Tbl      => l_Mesg_Token_Tbl
4953                         , x_Mesg_Token_Tbl      => l_Mesg_Token_Tbl
4954                         , p_Token_Tbl           => g_Token_Tbl
4955                         );
4956                    END IF;
4957                    l_return_status := FND_API.G_RET_STS_ERROR;
4958 		END IF;
4959 	End if;
4960 
4961 	/*********************************************************************
4962 	--
4963 	-- Check whether the entered attributes match with the current
4964 	-- component attributes
4965 	--
4966 	**********************************************************************/
4967 	IF (( p_rev_component_rec.Transaction_Type=BOM_GLOBALS.G_OPR_CREATE AND
4968 	      NVL(p_rev_component_rec.acd_type, 1) = 1
4969 	    ) OR
4970 	   (((p_rev_component_rec.Transaction_Type=BOM_GLOBALS.G_OPR_CREATE AND
4971                p_rev_component_rec.acd_type = 2
4972 	      ) OR
4973 	       p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_UPDATE
4974 	     )
4975 	      AND
4976 	      NVL(p_Old_rev_component_rec.optional, 0) <>
4977 	      p_rev_component_rec.optional
4978 	    )
4979 	   )
4980 	THEN
4981 	     l_Result := Check_PTO_ATO_for_Optional;
4982 	     IF l_Result = 1 THEN
4983              	IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4984              	THEN
4985                 	Error_Handler.Add_Error_Token
4986 			( p_message_name	=> 'BOM_COMP_OPTIONAL'
4987 		 	, p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
4988 		 	, x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
4989 		 	, p_Token_Tbl		=> g_Token_Tbl
4990                  	);
4991                 END IF;
4992              	l_return_status := FND_API.G_RET_STS_ERROR;
4993 	     ELSIF l_Result = 2
4994 	     THEN
4995                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
4996                 THEN
4997                         Error_Handler.Add_Error_Token
4998                         ( p_message_name        => 'BOM_COMP_NOT_OPTIONAL'
4999                         , p_Mesg_Token_Tbl      => l_Mesg_Token_Tbl
5000                         , x_Mesg_Token_Tbl      => l_Mesg_Token_Tbl
5001                         );
5002 		END IF;
5003 		l_return_status := FND_API.G_RET_STS_ERROR;
5004 	     END IF;
5005         END IF;
5006 
5007 --	dbms_output.put_line('Verified PTO / ATO . . .' || l_return_status);
5008 
5009 	/*********************************************************************
5010 	--
5011         -- Planning Percent can be other than 100 for only some combination of
5012         -- Assembly and component_types.
5013 	--
5014 	**********************************************************************/
5015 	--
5016 	IF p_control_rec.caller_type <> 'FORM' AND
5017 	  (( p_rev_component_rec.Transaction_Type=BOM_GLOBALS.G_OPR_CREATE AND
5018               NVL(p_rev_component_rec.acd_type, 1) = 1 AND
5019               p_rev_component_rec.planning_percent <> 100
5020             ) OR
5021            (((p_rev_component_rec.Transaction_Type=BOM_GLOBALS.G_OPR_CREATE AND
5022                p_rev_component_rec.acd_type = 2
5023               ) OR
5024                p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_UPDATE
5025              )
5026               AND
5027               NVL(p_Old_rev_component_rec.planning_percent, 0) <>
5028               p_rev_component_rec.planning_percent
5029             )
5030            )
5031 	THEN
5032         	l_Result := Check_Planning_Percent;
5033 		IF l_Result = 1 THEN
5034 		   IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5035              	   THEN
5036 			g_Token_Tbl(2).Token_Name := 'REVISED_ITEM_NAME';
5037 			g_Token_Tbl(2).Token_Value :=
5038 			g_rev_component_rec.revised_item_name;
5039                 	Error_Handler.Add_Error_Token
5040 			(  p_Message_Name	=> 'BOM_NOT_A_PLANNING_PARENT'
5041 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
5042 			 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
5043 			 , p_Token_Tbl		=> g_Token_Tbl
5044                         );
5045 			g_Token_Tbl.DELETE(2);
5046              	    END IF;
5047              	    l_return_status := FND_API.G_RET_STS_ERROR;
5048 		ELSIF l_Result = 2 THEN
5049                    IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5050                    THEN
5051 			g_Token_Tbl(2).Token_Name := 'REVISED_ITEM_NAME';
5052 			g_Token_Tbl(2).Token_Value :=
5053 			g_rev_component_rec.revised_item_name;
5054 			g_Token_Tbl(3).Token_Name := 'ITEM_TYPE';
5055 			IF g_Assy_Item_Type = Bom_Globals.G_MODEL
5056 			THEN
5057 				g_Token_Tbl(3).Token_Value := 'BOM_MODEL_TYPE';
5058 			ELSIF g_Assy_Item_Type = Bom_Globals.G_OPTION_CLASS THEN
5059 				g_Token_Tbl(3).Token_Value :=
5060 				'BOM_OPTION_CLASS_TYPE';
5061 			END IF;
5062 			g_Token_Tbl(3).Translate := TRUE;
5063                         Error_Handler.Add_Error_Token
5064                         (  p_Message_Name       => 'BOM_COMP_MODEL_OC_OPTIONAL'
5065                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5066                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5067                          , p_Token_Tbl          => g_Token_Tbl
5068                         );
5069 			g_Token_Tbl.DELETE(2);
5070 			g_Token_Tbl.DELETE(3);
5071 			l_return_status := FND_API.G_RET_STS_ERROR;
5072                     END IF;
5073 	--Commented condition below for bug 7392603
5074   /*	ELSIF l_Result = 3 THEN
5075                    IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5076                    THEN
5077 			g_Token_Tbl(1).Token_Name := 'REVISED_ITEM_NAME';
5078                         g_Token_Tbl(1).Token_Value :=
5079                         g_rev_component_rec.revised_item_name;
5080 
5081                         Error_Handler.Add_Error_Token
5082                         (  p_Message_Name       =>
5083 						'BOM_COMP_OPTIONAL_ATO_FORECAST'
5084                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5085                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5086                          , p_Token_Tbl          => g_Token_Tbl
5087                         );
5088 			g_Token_Tbl(1).Token_Name := 'REVISED_COMPONENT_NAME';
5089                         g_Token_Tbl(1).Token_Value :=
5090                         g_rev_component_rec.component_item_name;
5091 
5092                     END IF;
5093 		    l_return_status := FND_API.G_RET_STS_ERROR;*/
5094      		END IF;  -- If Result Ends
5095         END IF; -- If Plannng <> 100 Ends
5096 
5097 --	dbms_output.put_line('Verified Planning % . . .' || l_return_status);
5098 
5099 	/*********************************************************************
5100 	--
5101         -- Check Required for Revenue / Required to Ship
5102 	--
5103 	**********************************************************************/
5104         IF (( p_rev_component_rec.Transaction_Type=BOM_GLOBALS.G_OPR_CREATE AND
5105               NVL(p_rev_component_rec.acd_type, 1) = 1 AND
5106 	      ( p_rev_component_rec.required_for_revenue = 1 OR
5107 		p_rev_component_rec.required_to_ship = 1
5108 	       )
5109             ) OR
5110            (((p_rev_component_rec.Transaction_Type=BOM_GLOBALS.G_OPR_CREATE AND
5111                p_rev_component_rec.acd_type = 2
5112               ) OR
5113                p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_UPDATE
5114              )
5115               AND
5116               ( NVL(p_Old_rev_component_rec.required_for_revenue, 0) <>
5117                     p_rev_component_rec.required_for_revenue OR
5118 		NVL(p_old_rev_component_rec.required_to_ship, 0) <>
5119 		    p_rev_component_rec.required_to_ship
5120 	       )
5121             )
5122            )
5123 	THEN
5124 
5125 	     l_Result := Chk_Req_For_Rev_Or_Shp;
5126 	     IF l_Result = 1 THEN
5127 	        IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5128                 THEN
5129 			g_Token_Tbl(2).Token_Name := 'REVISED_ITEM_NAME';
5130 			g_Token_Tbl(2).Token_Value :=
5131 				g_rev_component_rec.revised_item_name;
5132                 	Error_Handler.Add_Error_Token
5133 			( p_message_name     => 'BOM_COMP_REQ_FOR_REV_INVALID'
5134 		 	, p_Mesg_Token_Tbl   => l_Mesg_Token_Tbl
5135 		 	, x_Mesg_Token_Tbl   => l_Mesg_Token_Tbl
5136 		 	, p_Token_Tbl	     => g_Token_Tbl
5137                  	);
5138 			g_Token_Tbl.DELETE(2);
5139                 END IF;
5140                 l_return_status := FND_API.G_RET_STS_ERROR;
5141 	     ELSIF l_Result = 2 THEN
5142 			g_Token_Tbl(2).Token_Name := 'REVISED_ITEM_NAME';
5143                         g_Token_Tbl(2).Token_Value :=
5144 				g_rev_component_rec.revised_item_name;
5145                         Error_Handler.Add_Error_Token
5146                         ( p_message_name     => 'BOM_COMP_REQ_TO_SHIP_INVALID'
5147                         , p_Mesg_Token_Tbl   => l_Mesg_Token_Tbl
5148                         , x_Mesg_Token_Tbl   => l_Mesg_Token_Tbl
5149                         , p_Token_Tbl        => g_Token_Tbl
5150                         );
5151 			g_Token_Tbl.DELETE(2);
5152 			l_return_status := FND_API.G_RET_STS_ERROR;
5153 	     ELSIF l_Result = 3 THEN
5154                         g_Token_Tbl(2).Token_Name := 'REVISED_ITEM_NAME';
5155                         g_Token_Tbl(2).Token_Value :=
5156                                 g_rev_component_rec.revised_item_name;
5157                         Error_Handler.Add_Error_Token
5158                         ( p_message_name     => 'BOM_COMP_REQ_TO_SHIP_INVALID'
5159                         , p_Mesg_Token_Tbl   => l_Mesg_Token_Tbl
5160                         , x_Mesg_Token_Tbl   => l_Mesg_Token_Tbl
5161                         , p_Token_Tbl        => g_Token_Tbl
5162                         );
5163 
5164                         g_Token_Tbl(2).Token_Name := 'REVISED_ITEM_NAME';
5165                         g_Token_Tbl(2).Token_Value :=
5166                                 g_rev_component_rec.revised_item_name;
5167                         Error_Handler.Add_Error_Token
5168                         ( p_message_name     => 'BOM_COMP_REQ_FOR_REV_INVALID'
5169                         , p_Mesg_Token_Tbl   => l_Mesg_Token_Tbl
5170                         , x_Mesg_Token_Tbl   => l_Mesg_Token_Tbl
5171                         , p_Token_Tbl        => g_Token_Tbl
5172                         );
5173 
5174 			g_Token_Tbl.DELETE(2);
5175 			l_return_status := FND_API.G_RET_STS_ERROR;
5176 	     END IF;
5177         END IF;
5178 
5179 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Verified Req for Rev and Shipping . . . ' || l_return_status); END IF;
5180 
5181 	/*********************************************************************
5182 	--
5183 	-- Verify the value of SO_Basis
5184 	-- first conditon is removed by MK on 11/13/00
5185 	*********************************************************************/
5186 	IF -- p_control_rec.caller_type = 'FORM' AND
5187 	   p_rev_component_rec.so_basis = 1 AND
5188 	   g_Comp_Item_Type <> Bom_Globals.G_OPTION_CLASS
5189 	THEN
5190                  Error_Handler.Add_Error_Token
5191                  (  p_message_name     => 'BOM_SO_BASIS_ONE'
5192                   , p_Mesg_Token_Tbl   => l_Mesg_Token_Tbl
5193                   , x_Mesg_Token_Tbl   => l_Mesg_Token_Tbl
5194                   , p_Token_Tbl        => g_Token_Tbl
5195                   );
5196 		l_Return_Status := FND_API.G_RET_STS_ERROR;
5197 	END IF;
5198 
5199 	/********************************************************************
5200         -- ATP Validation for components is changed and now there is no restriction
5201         -- Comment out by MK on 06/05/2001
5202 	--
5203         -- Check Check_ATP Flag. Check_ATP can be True only if Assembly has
5204 	-- Atp Components flag = Y and the Component has a Check_ATP.
5205 	--
5206 
5207         IF (( p_rev_component_rec.Transaction_Type=BOM_GLOBALS.G_OPR_CREATE AND
5208               NVL(p_rev_component_rec.acd_type, 1) = 1 AND
5209               p_rev_component_rec.check_atp = 1
5210              ) OR
5211              ( ( ( p_rev_component_rec.Transaction_Type =
5212 		   BOM_GLOBALS.G_OPR_CREATE AND
5213                	   p_rev_component_rec.acd_type = 2
5214                  ) OR
5215                   p_rev_component_rec.Transaction_Type =
5216 		  BOM_GLOBALS.G_OPR_UPDATE
5217                ) AND
5218                NVL(p_old_rev_component_rec.check_atp, 0) <>
5219                p_rev_component_rec.check_atp
5220                AND p_rev_component_rec.check_atp = 1 -- Added by MK on 11/13/00
5221              )
5222            )
5223 	THEN
5224             l_result := Check_ATP;
5225 		--  We will not be using the result of the check_atp procedure
5226 		--   to decide the translatable token since the message text
5227 		--   is now changed. Please refer to text for BOM_ATP_CHECK_NOT_NO
5228 
5229             --  Modified by MK on 11/13/00
5230             --  IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR) AND
5231             --     l_result <> 0
5232             --  THEN
5233 
5234             IF  l_result <> 0
5235             THEN
5236                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5237                 THEN
5238                     Error_Handler.Add_Error_Token
5239 	            (  p_message_name	=> 'BOM_ATP_CHECK_NOT_NO'
5240 		     , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
5241 		     , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
5242 		     , p_Token_Tbl		=> g_Token_Tbl
5243                      );
5244 		    g_Token_Tbl.DELETE(2);
5245 		-- l_return_status := FND_API.G_RET_STS_ERROR;
5246                 END IF;
5247 		l_return_status := FND_API.G_RET_STS_ERROR;
5248             END IF ;
5249         END IF;
5250 
5251 IF Bom_Globals.Get_Debug = 'Y' THEN
5252    Error_Handler.Write_Debug('After verification of Check ATP . . . ' || l_return_status);
5253 END IF;
5254 --	dbms_output.put_line('After verification of Check ATP, Req for Rev' );
5255 	********************************************************************/
5256 
5257 	/********************************************************************
5258 	--
5259         -- Check Mutually Exclusive, which can be set only if the
5260         -- Component is an Option Class and BOM is installed.
5261 	--
5262 	*********************************************************************/
5263 
5264         IF ( p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_CREATE OR
5265              p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_UPDATE
5266 	    )
5267            AND
5268 	   NVL(p_rev_component_rec.mutually_exclusive, 2) = 1
5269 	THEN
5270 	     l_result := Check_Mutually_Exclusive;
5271              IF l_result <> 0 THEN
5272 	        IF l_result = 1 THEN
5273                    IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5274                    THEN
5275                       Error_Handler.Add_Error_Token
5276                       (  p_message_name    => 'BOM_MUT_EXCL_BOM_NOT_INST'
5277                        , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
5278                        , x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
5279                        );
5280                    END IF;
5281 	        ELSIF l_result = 2 THEN
5282                    IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5283                    THEN
5284                       Error_Handler.Add_Error_Token
5285                       (  p_message_name    => 'BOM_MUT_EXCL_NOT_MDL_OPTCLASS'
5286                        , p_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
5287                        , x_Mesg_Token_Tbl  => l_Mesg_Token_Tbl
5288                        , p_Token_Tbl       => g_Token_Tbl
5289                        );
5290                    END IF;
5291 	        END IF;
5292 
5293                 l_return_status := FND_API.G_RET_STS_ERROR;
5294 	     END IF;
5295         END IF;
5296 
5297 --	dbms_output.put_line('After verification of Mutually exclusive . . .' ||
5298 --			l_return_status);
5299 
5300         -- So process can continue in case of a warning. Since it has
5301         -- indecisive o/p to continue or not, the function will
5302         -- log the error or warning and return TRUE if warning
5303         -- so the process can continue or will return an FALSE if
5304         -- process needs to return
5305         IF ((p_control_rec.caller_type = 'FORM' AND
5306              p_control_rec.validation_controller = 'SUPPLY_TYPE')
5307             OR
5308             p_control_rec.caller_type <> 'FORM')
5309 	   AND
5310 	   ((( p_rev_component_rec.Transaction_Type=BOM_GLOBALS.G_OPR_CREATE AND
5311               NVL(p_rev_component_rec.acd_type, 1) = 1 AND
5312               p_rev_component_rec.wip_supply_type IS NOT NULL
5313              ) OR
5314             ((p_rev_component_rec.Transaction_Type=BOM_GLOBALS.G_OPR_CREATE AND
5315                p_rev_component_rec.acd_type = 2
5316               ) OR
5317                p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_UPDATE
5318              ))
5319               AND
5320               NVL(p_Old_rev_component_rec.wip_supply_type, 0) <>
5321               p_rev_component_rec.wip_supply_type
5322             )
5323 	   AND
5324             NOT Check_Supply_Type
5325 	    (  p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
5326 	     , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl )
5327 	THEN
5328                 l_return_status := FND_API.G_RET_STS_ERROR;
5329         END IF;
5330 
5331 --	dbms_output.put_line
5332 --	('After verification of Supply Type . . .' || l_return_status);
5333 
5334         IF (p_control_rec.caller_type = 'FORM' AND
5335 	    p_control_rec.validation_controller IN
5336 				('MINIMUM_QUANTITY', 'MAXIMUM_QUANTITY'))
5337 	   OR
5338 	   p_control_rec.caller_type <> 'FORM'
5339 	THEN
5340             -- Check Minimum Quantity which must be <= Component Quantity
5341             IF ( p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_CREATE OR
5342                  p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_UPDATE
5343 	        ) AND
5344                  p_rev_component_rec.minimum_allowed_quantity is not null
5345                AND
5346                NOT Check_Min_Quantity THEN
5347                  IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5348                  THEN
5349                     Error_Handler.Add_Error_Token
5350 		    (  p_message_name	=> 'BOM_MIN_QUANTITY_INVALID'
5351 		     , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
5352 		     , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
5353 		     , p_Token_Tbl		=> g_Token_Tbl
5354                      );
5355                  END IF;
5356                  l_return_status := FND_API.G_RET_STS_ERROR;
5357             END IF;
5358 
5359             -- Check Maximun Quantity which must be >= Component Quantity or
5360 	    -- should be NULL if the minimum quantity is NULL.
5361             IF ( p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_CREATE OR
5362                  p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_UPDATE
5363 	        ) AND
5364                 p_rev_component_rec.maximum_allowed_quantity IS NOT NULL
5365                AND
5366                NOT Check_Max_Quantity THEN
5367                  IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5368                  THEN
5369                     Error_Handler.Add_Error_Token
5370 		    (  p_message_name	=> 'BOM_MAX_QUANTITY_INVALID'
5371 		     , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
5372 		     , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
5373 		     , p_Token_Tbl		=> g_Token_Tbl
5374                      );
5375                  END IF;
5376                  l_return_status := FND_API.G_RET_STS_ERROR;
5377             END IF;
5378 	END IF;
5379 
5380 --	dbms_output.put_line('After verification of Min / Max quantity . . .');
5381 
5382         -------------------------------------------------
5383         -- Required since quantity cannot be fractional
5384         -- if OE is installed and revised item is
5385         -- ATO/PTO.
5386         -- Fix made by AS 04/27/98
5387         -- Bug 651689
5388 	-- Fractional qty allowed for ATO revised items
5389 	-- fix made by skagarwa 11/27/00
5390 	-- Bug 1490837
5391         -------------------------------------------------
5392       /* commenting for bug 5011929
5393 	 OPEN c_OE_Installed;
5394 	 FETCH c_OE_Installed INTO Is_OE_Installed;
5395 	 CLOSE c_OE_Installed;
5396 
5397 	 Is_Item_ATO := 'N';
5398 	 IS_Item_PTO := 'N';
5399 
5400 	 FOR Is_Item_ATO_PTO IN c_ATO_PTO
5401 	 LOOP
5402 	 	Is_Item_ATO := Is_Item_ATO_PTO.replenish_to_order_flag;
5403 	 	Is_Item_PTO := Is_Item_ATO_PTO.pick_components_flag;
5404          END LOOP;
5405 
5406 	 IF ( p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_CREATE OR
5407               p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_UPDATE
5408              ) AND
5409            (Is_OE_Installed = 'I'
5410             AND ( (  Is_Item_PTO = 'Y'
5411 		   ) AND
5412                    (round(p_rev_component_rec.quantity_per_assembly)
5413              	    <> p_rev_component_rec.quantity_per_assembly)
5414 		 )
5415 	   )
5416          THEN
5417              IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5418              THEN
5419                 Error_Handler.Add_Error_Token
5420 		(  p_message_name	=> 'BOM_COMP_QTY_FRACTIONAL'
5421 		 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
5422 		 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
5423 		 , p_Token_Tbl		=> g_Token_Tbl
5424                 );
5425              END IF;
5426              l_return_status := FND_API.G_RET_STS_ERROR;
5427 	 END IF;
5428           commented for bug 5011929 */
5429 --	dbms_output.put_line('Checked if fractional quantity is valid . . .' ||
5430 --		l_return_status);
5431 
5432 
5433 	/********************************************************************
5434 	--
5435 	-- Verify if the Check_Atp is Yes and the Component quantity is
5436 	-- negative. If it is then give out an error.
5437 	--
5438 	********************************************************************/
5439 
5440 	IF p_rev_component_rec.check_atp = 1 AND -- Bug Fix 3688325
5441 	   p_rev_component_rec.quantity_per_assembly < 0
5442 	THEN
5443 	     IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5444              THEN
5445                 Error_Handler.Add_Error_Token
5446                 (  p_message_name       => 'BOM_COMP_QTY_NEGATIVE'
5447                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5448                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5449                  , p_Token_Tbl          => g_Token_Tbl
5450                 );
5451              END IF;
5452              l_return_status := FND_API.G_RET_STS_ERROR;
5453 	END IF;
5454 
5455 	/********************************************************************
5456 	--
5457 	-- If component is a PTO Option Class, then component quantity cannot
5458 	-- be negative
5459 	--
5460 	********************************************************************/
5461 	IF g_Comp_PTO_Flag = 'Y' AND
5462            p_rev_component_rec.quantity_per_assembly < 0
5463         THEN
5464              IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5465              THEN
5466                 Error_Handler.Add_Error_Token
5467                 (  p_message_name       => 'BOM_COMP_PTO_QTY_NEGATIVE'
5468                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5469                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5470                  , p_Token_Tbl          => g_Token_Tbl
5471                 );
5472              END IF;
5473              l_return_status := FND_API.G_RET_STS_ERROR;
5474         END IF;
5475 
5476 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Checking Supply Subinventory . . . ' || p_rev_component_rec.Supply_SubInventory); END IF;
5477 
5478 	/*******************************************************************
5479 	--
5480         -- Check Supply Subinventory
5481 	--
5482 	********************************************************************/
5483 
5484         IF -- p_control_rec.caller_type = 'FORM' -- Comment out by MK on 11/13/00
5485 	   -- AND
5486 	  p_rev_component_rec.Supply_SubInventory <> FND_API.G_MISS_CHAR AND
5487 	  (( p_rev_component_rec.Transaction_Type=BOM_GLOBALS.G_OPR_CREATE AND
5488               NVL(p_rev_component_rec.acd_type, 1) = 1 AND
5489               p_rev_component_rec.Supply_SubInventory IS NOT NULL
5490             ) OR
5491            (((p_rev_component_rec.Transaction_Type=BOM_GLOBALS.G_OPR_CREATE AND
5492                p_rev_component_rec.acd_type = 2
5493               ) OR
5494                p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_UPDATE
5495              )
5496               AND
5497               NVL(p_Old_rev_component_rec.supply_subinventory, 'NONE') <>
5498               NVL(p_rev_component_rec.supply_subinventory, 'NONE')
5499             )
5500            )
5501 	   AND
5502 	   NOT Check_Supply_SubInventory THEN
5503 
5504              IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5505              THEN
5506                 Error_Handler.Add_Error_Token
5507 		(  p_message_name	=> 'BOM_SUBINV_INVALID'
5508 		 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
5509 		 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
5510                  );
5511              END IF;
5512              l_return_status := FND_API.G_RET_STS_ERROR;
5513         END IF;
5514 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('After checking Subinventory . . . ' || l_return_status); END IF;
5515 
5516 --	dbms_output.put_line('Checking Locators . . . .');
5517 	/********************************************************************
5518 	--
5519         -- Check Locators
5520 	--
5521 	********************************************************************/
5522         IF p_control_rec.caller_type <> 'FORM'
5523           AND (Bom_globals.Get_Caller_Type <> BOM_GLOBALS.G_MASS_CHANGE)  -- Bug2739314
5524           AND
5525 	   (( p_rev_component_rec.Transaction_Type=BOM_GLOBALS.G_OPR_CREATE AND
5526               NVL(p_rev_component_rec.acd_type, 1) = 1 AND
5527               p_rev_component_rec.Supply_SubInventory IS NOT NULL AND
5528 	      p_rev_component_rec.Supply_SubInventory <> FND_API.G_MISS_CHAR
5529             ) OR
5530            ((( p_rev_component_rec.Transaction_Type=BOM_GLOBALS.G_OPR_CREATE AND
5531                p_rev_component_rec.acd_type = 2
5532              ) OR
5533                p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_UPDATE
5534             )
5535               AND
5536               NVL(p_Old_rev_comp_unexp_rec.supply_locator_id, 0) <>
5537               NVL(p_rev_comp_unexp_rec.supply_locator_id, 0)
5538            )
5539           )
5540            AND
5541 	   NOT Check_Locators
5542 	THEN
5543 --		dbms_output.put_line('Locators check returned with an error-' ||
5544 --		to_char(l_locator_control));
5545 
5546 	     IF l_locator_control = 4 THEN
5547 	         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5548                 THEN
5549                       Error_Handler.Add_Error_Token
5550                       (  p_message_name       => 'BOM_LOCATOR_REQUIRED'
5551                        , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5552                        , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5553                        , p_Token_Tbl          => g_Token_Tbl
5554                       );
5555                 END IF;
5556 	     /*  Error message should be proper.  Since dynamic locators are supported
5557 		 same validation for pre-specified can be used.  Bug 5032528
5558 	     ELSIF l_locator_control = 3 THEN
5559 	     	-- Log the Dynamic locator control message.
5560 		IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5561                 THEN
5562 		      g_Token_Tbl(1).token_name := 'REVISED_COMPONENT_NAME';
5563 	              g_Token_Tbl(1).token_value:= p_rev_component_rec.component_item_name;
5564 
5565                       Error_Handler.Add_Error_Token
5566 		      (  p_message_name	      => 'BOM_LOCATOR_CANNOT_BE_DYNAMIC'
5567 		       , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5568                        , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5569                        , p_Token_Tbl          => g_Token_Tbl
5570                       );
5571                 END IF;
5572 		 */
5573        -- Added OR l_locator_control = 3 for bug 5032528
5574 	   ELSIF (l_locator_control = 2 OR l_locator_control = 3 ) THEN
5575 		IF  l_item_loc_restricted  = 1 THEN
5576 
5577 			-- if error occured when item_locator_control was
5578 			-- restrcited
5579 
5580              		IF FND_MSG_PUB.Check_Msg_Level
5581 			   (FND_MSG_PUB.G_MSG_LVL_ERROR)
5582              		THEN
5583                             -- Added Token by MK on 12/06/00
5584                             g_Token_Tbl(2).Token_Name  := 'SUPPLY_SUBINVENTORY';
5585 	                    g_Token_Tbl(2).Token_Value := p_rev_component_rec.Supply_SubInventory ;
5586 
5587                 	     Error_Handler.Add_Error_Token
5588 			     (  p_message_name  => 'BOM_ITEM_LOCATOR_RESTRICTED'
5589 			      , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5590                  	      , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5591                  	      , p_Token_Tbl      => g_Token_Tbl
5592                               );
5593 
5594                              g_Token_Tbl.DELETE(2);
5595 
5596              		END IF;
5597 		ELSE
5598 			IF FND_MSG_PUB.Check_Msg_Level
5599 			(FND_MSG_PUB.G_MSG_LVL_ERROR)
5600                         THEN
5601 			      g_Token_Tbl(2).token_name := 'REVISED_COMPONENT_NAME';
5602 			      g_Token_Tbl(2).token_value:= p_rev_component_rec.component_item_name;
5603                               Error_Handler.Add_Error_Token
5604 			      (  p_message_name	  => 'BOM_LOCATOR_NOT_IN_SUBINV'
5605 			       , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5606                  	       , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5607                  	       , p_Token_Tbl      => g_Token_Tbl
5608                               );
5609 
5610                         END IF;
5611 		END IF;
5612 	     ELSIF l_locator_control = 1 THEN
5613 			IF FND_MSG_PUB.Check_Msg_Level
5614                            (FND_MSG_PUB.G_MSG_LVL_ERROR)
5615                         THEN
5616                              Error_Handler.Add_Error_Token
5617                              (  p_message_name  => 'BOM_ITEM_NO_LOCATOR_CONTROL'
5618                               , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5619                               , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5620                               , p_Token_Tbl      => g_Token_Tbl
5621                               );
5622                         END IF;
5623 
5624 	     END IF;
5625              l_return_status := FND_API.G_RET_STS_ERROR;
5626 	ELSIF p_rev_component_rec.location_name IS NOT NULL AND
5627 	      p_rev_component_rec.supply_subinventory IS NULL
5628 	THEN
5629 		IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
5630              	THEN
5631                 Error_Handler.Add_Error_Token
5632 		(  p_message_name	=> 'BOM_LOCATOR_MUST_BE_NULL'
5633 		 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5634                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5635                  , p_Token_Tbl          => g_Token_Tbl
5636                 );
5637              	END IF;
5638              	l_return_status := FND_API.G_RET_STS_ERROR;
5639         END IF;
5640 
5641 --	dbms_output.put_line('Operation CREATE ENDS . . .' || l_return_status);
5642 
5643   /*The following item num check introduced by bug 5053977 has been commented
5644   out because users get two error messages when they add a component with
5645   the same item seq as an already existing component in the ECO revised
5646   item components form. This is for bug 8423042*/
5647   /*******************************************************************
5648 	--
5649 	-- Item Num Check (Commented out for bug 8423042)
5650 	--
5651 	********************************************************************/
5652 
5653   /* Begin commenting out item num check for bug 8423042
5654 
5655     --Fix for bug 5053977- This validation should be done from ECO form.
5656 	  --It is not done for BOM/ECO BO because it is performance intensive.
5657 
5658 
5659   IF  (p_Control_rec.caller_type = 'FORM' AND
5660              p_control_rec.validation_controller = 'ITEM_SEQUENCE_NUMBER')
5661 	   AND
5662 	   ( NVL(p_rev_component_rec.acd_type,1) = 1  OR
5663 	     ( p_rev_component_rec.acd_type = 2 AND
5664 	       ( p_rev_component_rec.item_sequence_number <>
5665 	         p_old_rev_component_rec.item_sequence_number)
5666 	     )
5667 	   )
5668    	THEN
5669              -- Verify if a component is already added using this item_num
5670 	     -- If there is, log a WARNING.
5671 
5672                 item_num_for_bill := 0;
5673 		g_Token_Tbl.Delete;
5674                 g_token_tbl(1).token_name  := 'ITEM_SEQUENCE_NUMBER';
5675                 g_token_tbl(1).token_value := p_rev_component_rec.item_sequence_number;
5676                 g_token_tbl(2).token_name  := 'REVISED_COMPONENT_NAME';
5677                 g_token_tbl(2).token_value := p_rev_component_rec.component_item_name;
5678 
5679                 IF NOT l_is_item_unit_controlled
5680 		THEN
5681 			FOR Item_Num in c_ItemDateNum LOOP
5682                         	item_num_for_bill := 1;
5683                 	END LOOP;
5684 		ELSE
5685                         FOR Item_Num in c_ItemUnitNum LOOP
5686                                 item_num_for_bill := 1;
5687                         END LOOP;
5688 		END IF;
5689 
5690                 IF item_num_for_bill = 1 THEN
5691                 	Error_Handler.Add_Error_Token
5692 			(  x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
5693 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
5694                          , p_message_name	=> 'BOM_ITEM_NUM_NOT_UNIQUE'
5695 			 , p_Token_Tbl		=> g_Token_Tbl
5696                          , p_message_type 	=> 'W'
5697 			);
5698                 END IF;
5699 
5700 	END IF; -- Item Num Check ends
5701 
5702   --Fix for bug 5053977 ends here.
5703 
5704   End commenting out of item num check for bug 8423042 */
5705 
5706    END IF; -- Operation in UPDATE or CREATE
5707 
5708 
5709    -- Added by MK on 06/04/2001
5710    IF BOM_Globals.Get_Bo_Identifier = BOM_Globals.G_BOM_BO AND
5711       p_rev_component_rec.transaction_type = BOM_Globals.G_OPR_DELETE
5712    THEN
5713        IF p_rev_comp_unexp_rec.Delete_Group_Name IS NULL OR
5714           p_rev_comp_unexp_rec.Delete_Group_Name = FND_API.G_MISS_CHAR
5715        THEN
5716 
5717             Error_Handler.Add_Error_Token
5718              (  p_message_name       => 'BOM_DG_NAME_MISSING'
5719               , p_mesg_token_tbl     => l_mesg_token_tbl
5720               , x_mesg_token_tbl     => l_mesg_token_tbl
5721              );
5722 
5723              l_return_status := FND_API.G_RET_STS_ERROR;
5724 
5725        END IF;
5726 
5727 IF BOM_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
5728     ('Check if Delete Group is missing . . . ' || l_return_status) ;
5729 END IF ;
5730 
5731 
5732    END IF ;
5733 
5734   /********************************************************************
5735   -- If the structure type is Packaging Hierarchy the we will do the
5736   -- following validations
5737   ********************************************************************/
5738   IF p_Control_rec.caller_type <> 'FORM' THEN
5739 -- Bug 8874286 begin
5740 --  SELECT STRUCTURE_TYPE_NAME
5741 --      INTO
5742 --      l_Structure_Type_Name
5743 --      FROM BOM_STRUCTURE_TYPES_B STRUCT_TYPE,
5744 --           BOM_STRUCTURES_B  BOM_STRUCT
5745 --  WHERE  BOM_STRUCT.STRUCTURE_TYPE_ID = STRUCT_TYPE.STRUCTURE_TYPE_ID
5746 --  AND BOM_STRUCT.BILL_SEQUENCE_ID = g_Rev_Comp_Unexp_Rec.BILL_SEQUENCE_ID;
5747   l_Structure_Type_Name :=  Get_Structure_Type_Name(p_bill_sequence_id =>
5748                                                     g_Rev_Comp_Unexp_Rec.BILL_SEQUENCE_ID);
5749 
5750 -- Bug 8874286 end
5751 
5752   IF (l_Structure_Type_Name ='Packaging Hierarchy') THEN
5753     IF p_rev_component_rec.quantity_per_assembly < 0
5754     THEN
5755       Error_Handler.Add_Error_Token
5756                   ( p_message_name  => 'BOM_PKG_HIER_NEGATIVE_QTY'
5757                   , p_Mesg_Token_Tbl=> l_Mesg_Token_Tbl
5758                   , x_Mesg_Token_Tbl=> l_Mesg_Token_Tbl
5759                   , p_Token_Tbl     => g_Token_Tbl
5760                   );
5761 
5762       l_return_status := FND_API.G_RET_STS_ERROR;
5763     END IF;
5764     IF round(p_rev_component_rec.quantity_per_assembly) <> p_rev_component_rec.quantity_per_assembly
5765     THEN
5766       Error_Handler.Add_Error_Token
5767                   ( p_message_name  => 'BOM_PKG_HIER_FRACTIONAL_QTY'
5768                   , p_Mesg_Token_Tbl=> l_Mesg_Token_Tbl
5769                   , x_Mesg_Token_Tbl=> l_Mesg_Token_Tbl
5770                   , p_Token_Tbl     => g_Token_Tbl
5771                   );
5772 
5773       l_return_status := FND_API.G_RET_STS_ERROR;
5774     END IF;
5775   END IF;
5776  END IF;
5777 
5778 -- Component Type Rule Validations.
5779 -- Bug No: 4397973. Check Component types only when the current retrun status is success.
5780 IF (l_return_status = FND_API.G_RET_STS_SUCCESS)
5781 THEN
5782   IF ( p_rev_component_rec.Transaction_Type = BOM_GLOBALS.G_OPR_CREATE )
5783   THEN
5784  	Bom_Validate_Bom_Component.Check_Component_Type_Rule
5785    	(  x_return_status       => l_return_status
5786    	 , x_error_message       => l_debug_error_mesg
5787          , p_init_msg_list       => FALSE
5788    	 , p_parent_item_id      => p_Rev_Comp_Unexp_Rec.Revised_Item_Id
5789    	 , p_child_item_id       => p_Rev_Comp_Unexp_Rec.Component_Item_Id
5790    	 , p_organization_id     => p_Rev_Comp_Unexp_Rec.Organization_Id
5791    	);
5792 
5793    	IF (l_return_status = FND_API.G_RET_STS_ERROR)
5794 	THEN
5795 	  	Error_Handler.Add_Error_Token
5796 	        ( p_Message_Text   => l_debug_error_mesg
5797 	        , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5798 	        , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5799                );
5800    	END IF;
5801   END IF;
5802 END IF;
5803 
5804 	IF BOM_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
5805 	    ('Check Component Type Rule . . . ' || l_return_status) ;
5806 	END IF ;
5807 
5808     x_return_status := l_return_status;
5809     x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
5810 
5811 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Entity Validation done . . . Return Status is ' || l_return_status); END IF;
5812 
5813 		EXCEPTION
5814 
5815     		WHEN FND_API.G_EXC_ERROR THEN
5816 
5817 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Expected Error in Rev. Comp. Entity Validation . . .'); END IF;
5818 
5819         		x_return_status := FND_API.G_RET_STS_ERROR;
5820 			x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
5821 
5822     		WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5823 
5824 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('UNExpected Error in Rev. Comp. Entity Validation . . .'); END IF;
5825 
5826         		x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5827         		IF FND_MSG_PUB.Check_Msg_Level
5828 				(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5829         		THEN
5830             			l_err_text := G_PKG_NAME ||
5831 						' : (Entity Validation) ' ||
5832 						substrb(SQLERRM,1,200);
5833             			Error_Handler.Add_Error_Token
5834                                 ( p_Message_Text => l_err_text
5835                                 , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5836                                 , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5837                                 );
5838 			END IF;
5839 			x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
5840 
5841     		WHEN OTHERS THEN
5842 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug(SQLERRM || ' ' || TO_CHAR(SQLCODE)); END IF;
5843         		x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5844                         IF FND_MSG_PUB.Check_Msg_Level
5845                                 (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
5846                         THEN
5847                                 l_err_text := G_PKG_NAME ||
5848                                                 ' : (Entity Validation) ' ||
5849                                                 substrb(SQLERRM,1,200);
5850                                 Error_Handler.Add_Error_Token
5851                                 ( p_Message_Text => l_err_text
5852                                 , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5853                                 , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5854 				);
5855                         END IF;
5856  			x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
5857 
5858 	END Check_Entity;
5859 
5860 	/***************************************************************
5861 	* Procedure	: Check_Attribute (Validation)
5862 	* Parameters IN	: Revised Component Record of exposed columns
5863 	* Parameters OUT: Mesg_Token_Tbl
5864 	*		  Return_Status
5865 	* Purpose	: Attribute validation procedure will validate each
5866 	*		  attribute of Revised component in its entirety. If
5867 	*		  the validation of a column requires looking at some
5868 	*		  other columns value then the validation is done at
5869 	*		  the Entity level instead.
5870 	*		  All errors in the attribute validation are accumulated
5871 	*		  before the procedure returns with a Return_Status
5872 	*		  of 'E'.
5873 	*********************************************************************/
5874 	PROCEDURE Check_Attributes
5875 	( x_return_status	IN OUT NOCOPY VARCHAR2
5876 	, x_Mesg_Token_Tbl	IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
5877 	, p_rev_component_rec	IN  Bom_Bo_Pub.Rev_Component_Rec_Type
5878 	, p_Rev_Comp_Unexp_Rec	IN  Bom_Bo_Pub.Rev_Comp_Unexposed_Rec_Type
5879 	)
5880 	IS
5881 
5882 	l_return_status VARCHAR2(1);
5883 	l_err_text	VARCHAR2(2000);
5884         l_assembly_item_id  NUMBER;
5885         l_org_id            NUMBER;
5886 	l_Mesg_Token_Tbl	Error_Handler.Mesg_Token_Tbl_Type;
5887 
5888         CURSOR c_Geteffcontrol IS SELECT effectivity_control FROM mtl_system_items
5889          WHERE inventory_item_id = p_rev_comp_unexp_rec.component_item_id AND
5890          organization_id   = l_org_id;
5891 
5892 	BEGIN
5893 
5894     		x_return_status := FND_API.G_RET_STS_SUCCESS;
5895     		l_return_status := FND_API.G_RET_STS_SUCCESS;
5896 
5897     		g_rev_component_rec := p_rev_component_rec;
5898 
5899     		-- Set the first token to be equal to the component_name
5900     		g_Token_Tbl(1).Token_Name  := 'REVISED_COMPONENT_NAME';
5901     		g_Token_Tbl(1).Token_Value :=
5902 				p_rev_component_rec.component_item_name;
5903 
5904                l_assembly_item_id :=  Bom_Globals.Get_Assembly_item_Id;
5905                l_org_id           :=  Bom_Globals.Get_Org_Id;
5906 
5907     		--
5908     		-- Check if the user is trying to create/update a record with
5909 		-- missing value when the column value is required.
5910     		--
5911     		IF p_rev_component_rec.item_sequence_number = FND_API.G_MISS_NUM
5912     		THEN
5913 			Error_Handler.Add_Error_Token
5914         		(  p_Message_Name       => 'BOM_ITEM_NUM_MISSING'
5915         		 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5916         		 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5917         		 , p_Token_Tbl          => g_Token_Tbl
5918         		 );
5919         		l_return_status := FND_API.G_RET_STS_ERROR;
5920     		END IF;
5921 
5922     		IF p_rev_component_rec.quantity_per_assembly =
5923 					FND_API.G_MISS_NUM
5924     		THEN
5925         		Error_Handler.Add_Error_Token
5926         		(  p_Message_Name       => 'BOM_COMP_QUANTITY_MISSING'
5927         		 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5928         		 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5929         		 , p_Token_Tbl          => g_Token_Tbl
5930         		 );
5931         		l_return_status := FND_API.G_RET_STS_ERROR;
5932     		END IF;
5933 
5934     		IF p_rev_component_rec.projected_yield = FND_API.G_MISS_NUM
5935     		THEN
5936         		Error_Handler.Add_Error_Token
5937         		(  p_Message_Name       => 'BOM_COMP_YIELD_MISSING'
5938         		 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5939         		 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5940         		 , p_Token_Tbl          => g_Token_Tbl
5941         		 );
5942         		l_return_status := FND_API.G_RET_STS_ERROR;
5943     		END IF;
5944 
5945     		IF p_rev_component_rec.planning_percent = FND_API.G_MISS_NUM
5946     		THEN
5947         		Error_Handler.Add_Error_Token
5948         		(  p_Message_Name       => 'BOM_PLAN_PERCENT_MISSING'
5949         		 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5950         		 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5951         		 , p_Token_Tbl          => g_Token_Tbl
5952         		 );
5953         		l_return_status := FND_API.G_RET_STS_ERROR;
5954     		END IF;
5955 
5956     		IF p_rev_component_rec.quantity_related = FND_API.G_MISS_NUM
5957     		THEN
5958         		Error_Handler.Add_Error_Token
5959         		(  p_Message_Name       => 'BOM_QUANTITY_RELATED_MISSING'
5960         		 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5961         		 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5962         		 , p_Token_Tbl          => g_Token_Tbl
5963          		);
5964         		l_return_status := FND_API.G_RET_STS_ERROR;
5965     		END IF;
5966 
5967     		IF p_rev_component_rec.include_in_cost_rollup = FND_API.G_MISS_NUM
5968     		THEN
5969         		Error_Handler.Add_Error_Token
5970         		(  p_Message_Name       => 'BOM_INCL_IN_CST_ROLLUP_MISSING'
5971         		                        -- 'BOM_INCL_IN_COST_ROLLUP_MISSING'
5972         		 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5973         		 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5974         		 , p_Token_Tbl          => g_Token_Tbl
5975          		);
5976         		l_return_status := FND_API.G_RET_STS_ERROR;
5977     		END IF;
5978 
5979     		IF p_rev_component_rec.check_atp = FND_API.G_MISS_NUM
5980     		THEN
5981         		Error_Handler.Add_Error_Token
5982         		(  p_Message_Name       => 'BOM_CHECK_ATP_MISSING'
5983         		 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5984         		 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5985         		 , p_Token_Tbl          => g_Token_Tbl
5986          		);
5987         		l_return_status := FND_API.G_RET_STS_ERROR;
5988     		END IF;
5989 
5990 
5991     		IF p_rev_component_rec.acd_type IS NOT NULL AND
5992        		   p_rev_component_rec.acd_type NOT IN (1, 2, 3) AND
5993 	 	   Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_ECO_BO
5994     		THEN
5995 			g_token_tbl(2).token_name  := 'ACD_TYPE';
5996 			g_token_tbl(2).token_value := p_rev_component_rec.acd_type;
5997 
5998 			Error_Handler.Add_Error_Token
5999         		(  p_Message_Name       => 'BOM_ACD_TYPE_INVALID'
6000         		 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6001         		 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6002         		 , p_Token_Tbl          => g_Token_Tbl
6003          		);
6004 			l_return_status := FND_API.G_RET_STS_ERROR;
6005     		END IF;
6006 
6007     		--  Validate rev_component attributes
6008 
6009                   -- The following validation should not be done for serial effective items
6010 
6011           --     Validate from_end_item_unit_number  5482117
6012 
6013           IF  p_rev_component_rec.transaction_type =  BOM_GLOBALS.G_OPR_CREATE
6014              AND (p_rev_component_rec.from_end_item_unit_number IS NOT NULL AND  p_rev_component_rec.from_end_item_unit_number <>  FND_API.G_MISS_CHAR)
6015              AND BOM_EAMUTIL.Asset_group_Item(item_id => l_assembly_item_id, org_id  => l_org_Id) = 'N'
6016           THEN
6017             IF NOT  Bom_Validate.End_Item_Unit_Number
6018                 ( p_from_end_item_unit_number => p_rev_component_rec.from_end_item_unit_number
6019                 , p_revised_item_id => p_rev_comp_unexp_rec.component_item_id
6020                 , x_err_text => l_err_text
6021                 )
6022             THEN
6023               g_token_tbl(1).token_name  := 'FROM_END_ITEM_UNIT_NUMBER';
6024               g_token_tbl(1).token_value := p_rev_component_rec.from_end_item_unit_number;
6025               g_token_tbl(2).token_name  := 'REVISED_COMPONENT_NAME';
6026               g_token_tbl(2).token_value := p_rev_component_rec.component_item_name;
6027               g_token_tbl(3).token_name  := 'ORGANIZATION_CODE';
6028               g_token_tbl(3).token_value := p_rev_component_rec.organization_code;
6029               Error_Handler.Add_Error_Token
6030               ( p_Message_Name=> 'BOM_CMP_FROM_UNIT_NUM_INVALID'
6031                , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6032                , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6033                , p_Token_Tbl          => g_Token_Tbl
6034               );
6035               l_return_status := FND_API.G_RET_STS_ERROR;
6036             END IF;
6037           END IF;
6038 
6039     		IF  p_rev_component_rec.transaction_type =
6040 			BOM_GLOBALS.G_OPR_CREATE AND
6041         	    (p_rev_component_rec.to_end_item_unit_number IS NOT NULL
6042          	     AND
6043          	      p_rev_component_rec.to_end_item_unit_number <>
6044 			FND_API.G_MISS_CHAR) AND
6045                      BOM_EAMUTIL.Asset_group_Item(
6046                                        item_id => l_assembly_item_id,
6047                                        org_id  => l_org_Id) = 'N'
6048     		THEN
6049         		IF NOT  Bom_Validate.End_Item_Unit_Number
6050                 		( p_from_end_item_unit_number =>
6051                         	  p_rev_component_rec.to_end_item_unit_number
6052                 		, p_revised_item_id =>
6053                         	  p_rev_comp_unexp_rec.component_item_id
6054                 		, x_err_text => l_err_text
6055                 		 )
6056         		THEN
6057             			l_return_status := FND_API.G_RET_STS_ERROR;
6058                      		g_token_tbl(1).token_name  :=
6059 					'FROM_END_ITEM_UNIT_NUMBER';
6060                      		g_token_tbl(1).token_value :=
6061                                     p_rev_component_rec.to_end_item_unit_number;
6062                      		g_token_tbl(2).token_name  :=
6063 						'REVISED_COMPONENT_NAME';
6064 		     		g_token_tbl(2).token_value :=
6065                                     p_rev_component_rec.component_item_name;
6066 		     		g_token_tbl(3).token_name  :=
6067 						'ORGANIZATION_CODE';
6068 		     		g_token_tbl(3).token_value :=
6069                                     p_rev_component_rec.organization_code;
6070 		     		Error_Handler.Add_Error_Token
6071                      		( p_Message_Name=> 'BOM_CMP_TO_UNIT_NUM_INVALID'
6072                     		 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6073                     		 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6074                     		 , p_Token_Tbl          => g_Token_Tbl
6075                      		);
6076             		END IF;
6077         	END IF;
6078 
6079 
6080  --   	END IF;
6081 
6082 	-- Added in 11.5.9 by ADEY
6083 	IF p_rev_component_rec.auto_request_material IS NOT NULL AND
6084        	   UPPER(p_rev_component_rec.auto_request_material) NOT IN ('Y','N')
6085  	THEN
6086 		g_token_tbl(2).token_name  := 'AUTO_REQ_MATERIAL';
6087 		g_token_tbl(2).token_value := p_rev_component_rec.auto_request_material;
6088 
6089 		Error_Handler.Add_Error_Token
6090         		(  p_Message_Name       => 'BOM_AUTO_REQ_MAT_INVALID'
6091         		 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6092         		 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6093         		 , p_Token_Tbl          => g_Token_Tbl
6094          		);
6095 		l_return_status := FND_API.G_RET_STS_ERROR;
6096     	END IF;
6097 
6098 
6099       /* Comment Out by MK on 11/20/00
6100         -- This validation is not required
6101         -- Modified condition by MK on 11/08/00
6102     	IF p_rev_component_rec.transaction_type = BOM_GLOBALS.G_OPR_CREATE AND
6103            ( p_rev_component_rec.from_end_item_unit_number <> FND_API.G_MISS_CHAR OR
6104              p_rev_component_rec.from_end_item_unit_number IS NOT NULL ) AND
6105        	   ( p_rev_component_rec.to_end_item_unit_number = FND_API.G_MISS_CHAR OR
6106              p_rev_component_rec.to_end_item_unit_number IS NULL )
6107     	THEN
6108         	Error_Handler.Add_Error_Token
6109         	(  p_Message_Name       => 'BOM_CMP_TO_UNIT_NUM_NULL'
6110         	 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6111         	 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6112         	 , p_Token_Tbl          => g_Token_Tbl
6113          	);
6114         	l_return_status := FND_API.G_RET_STS_ERROR;
6115     	END IF;
6116       */
6117 
6118       -- Validations specific to EAM items (Asset Groups and Asset Activities)
6119 
6120       IF BOM_EAMUTIL.Enabled = 'Y' THEN
6121 
6122         IF BOM_EAMUTIL.Asset_group_Item( item_id => l_assembly_item_id,
6123                                          org_id  => l_org_id ) = 'Y' THEN
6124 
6125           -- An asset group can have only date effective components
6126 
6127           FOR effctrlrec IN c_Geteffcontrol
6128           LOOP
6129             IF effctrlrec.effectivity_control <> 1 THEN
6130               Error_Handler.Add_Error_Token
6131 			(  p_Message_Name	=> 'BOM_EFFCONTROL_INVALID'
6132 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6133 			 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6134 			 , p_Token_Tbl		=> g_Token_Tbl
6135 			);
6136               l_return_status := FND_API.G_RET_STS_ERROR;
6137             END IF;
6138           END LOOP;
6139 
6140           -- Validate the from_end_item_unit_number
6141 
6142           IF NOT Bom_Validate.Asset_Group_Serial_Number
6143                           ( p_assembly_item_id => l_assembly_item_id,
6144                             p_organization_id           => l_org_id,
6145                             p_serial_number    => p_rev_component_rec.from_end_item_unit_number,
6146                             X_err_text         => l_err_text ) THEN
6147             g_token_tbl(2).token_name  := 'FROM_END_ITEM_UNIT_NUMBER';
6148  	    g_token_tbl(2).token_value :=
6149 		p_rev_component_rec.from_end_item_unit_number;
6150             Error_Handler.Add_Error_Token
6151 			(  p_Message_Name	=> 'BOM_INVALID_FROM_SERIAL_NO'
6152 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6153 			 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6154 			 , p_Token_Tbl		=> g_Token_Tbl
6155                          , p_message_text       => l_err_text
6156 			);
6157             l_return_status := FND_API.G_RET_STS_ERROR;
6158           END IF;
6159 
6160           -- Validate the to_end_item_unit_number
6161 
6162           IF p_rev_component_rec.to_end_item_unit_number IS NOT NULL AND
6163              p_rev_component_rec.to_end_item_unit_number <> FND_API.G_MISS_CHAR
6164           THEN
6165 
6166             IF NOT Bom_Validate.Asset_Group_Serial_Number
6167                           ( p_assembly_item_id => l_assembly_item_id,
6168                             p_organization_id           => l_org_id,
6169                             p_serial_number    => p_rev_component_rec.to_end_item_unit_number,
6170                             X_err_text         => l_err_text ) THEN
6171               g_token_tbl(2).token_name  := 'TO_END_ITEM_UNIT_NUMBER';
6172  	      g_token_tbl(2).token_value :=
6173 		p_rev_component_rec.to_end_item_unit_number;
6174               Error_Handler.Add_Error_Token
6175 			(  p_Message_Name	=> 'BOM_INVALID_TO_SERIAL_NO'
6176 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6177 			 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6178 			 , p_Token_Tbl		=> g_Token_Tbl
6179                          , p_message_text       => l_err_text
6180 			);
6181               l_return_status := FND_API.G_RET_STS_ERROR;
6182             END IF;
6183           END IF;
6184 
6185           -- An asset group or activity cannnot be a component of another asset group
6186 
6187           IF BOM_EAMUTIL.Asset_Activity_Item(
6188                item_id => p_rev_comp_unexp_rec.component_item_id,
6189                org_id  => l_org_id )= 'Y'
6190              OR
6191              BOM_EAMUTIL.Asset_Group_Item(
6192                item_id => p_rev_comp_unexp_rec.component_item_id,
6193                org_id  => l_org_id ) = 'Y' THEN
6194 
6195               g_token_tbl(2).token_name  := 'COMPONENT_ITEM_NAME';
6196  	      g_token_tbl(2).token_value :=
6197 		p_rev_component_rec.component_item_name;
6198               Error_Handler.Add_Error_Token
6199 			(  p_Message_Name	=> 'BOM_COMP_CANNOT_BE_AN_AG'
6200 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6201 			 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6202 			 , p_Token_Tbl		=> g_Token_Tbl
6203 			);
6204               l_return_status := FND_API.G_RET_STS_ERROR;
6205            END IF;
6206 
6207         END IF;
6208 
6209         -- Asset activity items cannot have any supply types other than Push
6210         -- and Bulk
6211 
6212         IF BOM_EAMUTIL.Asset_Activity_Item( item_id => l_assembly_item_id,
6213                                             org_id  => l_org_id ) = 'Y' THEN
6214           IF p_rev_component_rec.wip_supply_type NOT IN (1,4) THEN
6215             g_token_tbl(2).token_name  := 'WIP_SUPPLY_TYPE';
6216  	    g_token_tbl(2).token_value :=
6217 		p_rev_component_rec.wip_supply_type;
6218             Error_Handler.Add_Error_Token
6219 			(  p_Message_Name	=> 'BOM_INVALID_AA_SUPTYPES'
6220 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6221 			 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6222 			 , p_Token_Tbl		=> g_Token_Tbl
6223 			);
6224             l_return_status := FND_API.G_RET_STS_ERROR;
6225           END IF;
6226 
6227           -- An asset group cannnot be a component for an asset activity
6228 
6229           IF BOM_EAMUTIL.Asset_Group_Item(
6230                item_id => p_rev_comp_unexp_rec.component_item_id,
6231                org_id  => l_org_id ) = 'Y' THEN
6232 
6233               g_token_tbl(2).token_name  := 'COMPONENT_ITEM_NAME';
6234  	      g_token_tbl(2).token_value :=
6235 		p_rev_component_rec.component_item_name;
6236               Error_Handler.Add_Error_Token
6237 			(  p_Message_Name	=> 'BOM_COMP_CANNOT_BE_AN_AG'
6238 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6239 			 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6240 			 , p_Token_Tbl		=> g_Token_Tbl
6241 			);
6242               l_return_status := FND_API.G_RET_STS_ERROR;
6243            END IF;
6244 
6245         END IF;
6246 
6247       END IF; -- End of attribute validations for EAM items
6248 
6249 
6250       IF  p_rev_component_rec.wip_supply_type IS NOT NULL  AND
6251 		p_rev_component_rec.wip_supply_type = 7
6252     	THEN
6253     		IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
6254         	THEN
6255 			g_token_tbl(2).token_name  := 'WIP_SUPPLY_TYPE';
6256 			g_token_tbl(2).token_value :=
6257 				p_rev_component_rec.wip_supply_type;
6258         		Error_Handler.Add_Error_Token
6259 			(  p_Message_Name	=> 'BOM_WIP_SUPPLY_TYPE_7'
6260 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6261 			 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6262 			 , p_Token_Tbl		=> g_Token_Tbl
6263 			);
6264 			g_token_tbl.delete(2);
6265        		END IF;
6266        		l_return_status := FND_API.G_RET_STS_ERROR;
6267 
6268     	ELSIF p_rev_component_rec.wip_supply_type IS NOT NULL AND
6269 	  	p_rev_component_rec.wip_supply_type <> 7 AND
6270           	NOT Bom_Validate.Wip_Supply_Type
6271 	      	(  p_wip_supply_type	=> p_rev_component_rec.wip_supply_type
6272 	         , x_err_text		=> l_err_text
6273 	         )
6274     	THEN
6275         	IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_SUCCESS)
6276         	THEN
6277 			g_token_tbl(1).token_name  := 'WIP_SUPPLY_TYPE';
6278                 	g_token_tbl(1).token_value :=
6279                                 p_rev_component_rec.wip_supply_type;
6280 
6281                 	Error_Handler.Add_Error_Token
6282                 	(  p_Message_Name       => 'BOM_WIP_SUPPLY_TYPE_INVALID'
6283                 	 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6284                 	 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6285                 	 , p_Token_Tbl          => g_Token_Tbl
6286                 	);
6287                 	g_token_tbl(1).token_name  := 'REVISED_COMPONENT_NAME';
6288                 	g_token_tbl(1).token_value :=
6289                                 p_rev_component_rec.component_item_name;
6290 
6291         	END IF;
6292         	l_return_status := FND_API.G_RET_STS_ERROR;
6293     	END IF;
6294 
6295     	IF  p_rev_component_rec.operation_sequence_number IS NOT NULL AND
6296 		p_rev_component_rec.operation_sequence_number <= 0
6297     	THEN
6298 		IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
6299         	THEN
6300 			Error_Handler.Add_Error_Token
6301 			(  p_Message_Name	=> 'BOM_OPSEQ_LESS_THAN_ZERO'
6302 		  	 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6303 		 	 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6304 			 , p_Token_Tbl		=> g_Token_Tbl
6305 		 	);
6306 		END IF;
6307             	l_return_status := FND_API.G_RET_STS_ERROR;
6308     	END IF;
6309 
6310 -- 	dbms_output.put_line('After Operation Sequence Num . . . ' || l_return_status);
6311 
6312     	IF  p_rev_component_rec.item_sequence_number IS NOT NULL AND
6313 		( p_rev_component_rec.item_sequence_number < 0 OR
6314 	  	/* p_rev_component_rec.item_sequence_number > 9999999 */
6315 	  	 p_rev_component_rec.item_sequence_number > (power(10,38)-1) /*
6316 bug 7437710 */
6317 	)
6318     	THEN
6319 		IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
6320         	THEN
6321 			Error_Handler.Add_Error_Token
6322 			(  p_Message_Name	=> 'BOM_ITEM_NUM_INVALID'
6323 			 , p_Mesg_token_Tbl	=> l_Mesg_token_Tbl
6324                 	 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6325 			 , p_token_tbl		=> g_Token_Tbl
6326 			);
6327         	END IF;
6328 		l_return_status := FND_API.G_RET_STS_ERROR;
6329     	END IF;
6330 
6331     	IF  p_rev_component_rec.projected_yield IS NOT NULL AND
6332 		p_rev_component_rec.projected_yield < 0 OR
6333 		p_rev_component_rec.projected_yield > 1
6334     	THEN
6335 		IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_SUCCESS)
6336 		THEN
6337 			g_token_tbl(1).token_name := 'REVISED_COMPONENT_NAME';
6338 			g_token_tbl(1).token_value := p_rev_component_rec.component_item_name;
6339 			Error_Handler.Add_Error_Token
6340 			(  p_Message_Name	=> 'BOM_COMPYIELD_OUT_OF_RANGE'
6341                 	 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6342 			 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6343 			 , p_token_tbl		=> g_token_tbl
6344 			 , p_message_type       => 'W' -- Bug 3226917
6345 			);
6346         	END IF;
6347 		--l_return_status := FND_API.G_RET_STS_ERROR;
6348     	END IF;
6349 
6350     	IF p_rev_component_rec.include_in_cost_rollup IS NOT NULL AND
6351        		p_rev_component_rec.include_in_cost_rollup NOT IN (1,2)
6352     	THEN
6353 		IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_SUCCESS)
6354         	THEN
6355                 	Error_Handler.Add_Error_Token
6356                 	(  p_Message_Name       => 'BOM_INCL_IN_COST_ROLL_INVALID'
6357                 	 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6358                 	 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6359                 	 , p_Token_Tbl          => g_Token_Tbl
6360                 	);
6361         	END IF;
6362 		l_return_status := FND_API.G_RET_STS_ERROR;
6363     	END IF;
6364 
6365     	IF p_rev_component_rec.SO_Basis IS NOT NULL AND
6366        		p_rev_component_rec.SO_Basis NOT IN (1, 2)
6367     	THEN
6368         	 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_SUCCESS)
6369         	THEN
6370                 	Error_Handler.Add_Error_Token
6371                 	(  p_Message_Name       => 'BOM_SO_BASIS_INVALID'
6372                 	 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6373                 	 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6374                 	 , p_Token_Tbl          => g_Token_Tbl
6375                 	);
6376         	END IF;
6377         	l_return_status := FND_API.G_RET_STS_ERROR;
6378     	END IF;
6379 
6380     	IF p_rev_component_rec.optional IS NOT NULL AND
6381        		p_rev_component_rec.optional NOT IN (1, 2)
6382     	THEN
6383          	IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_SUCCESS)
6384         	THEN
6385                 	Error_Handler.Add_Error_Token
6386                 	(  p_Message_Name       => 'BOM_OPTIONAL_INVALID'
6387                 	 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6388                 	 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6389                 	 , p_Token_Tbl          => g_Token_Tbl
6390                 	);
6391         	END IF;
6392         	l_return_status := FND_API.G_RET_STS_ERROR;
6393     	END IF;
6394 
6395     	IF p_rev_component_rec.mutually_exclusive IS NOT NULL AND
6396        		p_rev_component_rec.mutually_exclusive NOT IN (1, 2)
6397     	THEN
6398         	 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_SUCCESS)
6399         	THEN
6400                 	Error_Handler.Add_Error_Token
6401                 	(  p_Message_Name       => 'BOM_MUTUALLY_EXCLUSIVE_INVALID'
6402                 	 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6403                 	 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6404                 	 , p_Token_Tbl          => g_Token_Tbl
6405                 	);
6406         	END IF;
6407         	l_return_status := FND_API.G_RET_STS_ERROR;
6408     	END IF;
6409 
6410     	IF p_rev_component_rec.check_atp IS NOT NULL AND
6411        		p_rev_component_rec.check_atp NOT IN (1, 2)
6412     	THEN
6413         	 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_SUCCESS)
6414         	THEN
6415                 	Error_Handler.Add_Error_Token
6416                 	(  p_Message_Name       => 'BOM_CHECK_ATP_INVALID'
6417                 	 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6418                 	 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6419                 	 , p_Token_Tbl          => g_Token_Tbl
6420                 	);
6421         	END IF;
6422         	l_return_status := FND_API.G_RET_STS_ERROR;
6423     	END IF;
6424 
6425     	IF p_rev_component_rec.shipping_allowed IS NOT NULL AND
6426        		p_rev_component_rec.shipping_allowed NOT IN (1, 2)
6427     	THEN
6428          	IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_SUCCESS)
6429         	THEN
6430                 	Error_Handler.Add_Error_Token
6431                 	(  p_Message_Name       => 'BOM_SHIPPING_ALLOWED_INVALID'
6432                 	 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6433                 	 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6434                 	 , p_Token_Tbl          => g_Token_Tbl
6435                		 );
6436         	END IF;
6437         	l_return_status := FND_API.G_RET_STS_ERROR;
6438     	END IF;
6439 
6440     IF p_rev_component_rec.required_to_ship IS NOT NULL AND
6441        p_rev_component_rec.required_to_ship NOT IN (1, 2)
6442     THEN
6443          IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_SUCCESS)
6444         THEN
6445                 Error_Handler.Add_Error_Token
6446                 (  p_Message_Name       => 'BOM_REQUIRED_TO_SHIP_INVALID'
6447                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6448                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6449                  , p_Token_Tbl          => g_Token_Tbl
6450                 );
6451         END IF;
6452         l_return_status := FND_API.G_RET_STS_ERROR;
6453     END IF;
6454 
6455     IF p_rev_component_rec.required_for_revenue IS NOT NULL AND
6456        p_rev_component_rec.required_for_revenue NOT IN (1, 2)
6457     THEN
6458          IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_SUCCESS)
6459         THEN
6460                 Error_Handler.Add_Error_Token
6461                 (  p_Message_Name       => 'BOM_REQ_FOR_REVENUE_INVALID'
6462                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6463                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6464                  , p_Token_Tbl          => g_Token_Tbl
6465                 );
6466         END IF;
6467         l_return_status := FND_API.G_RET_STS_ERROR;
6468     END IF;
6469 
6470     IF p_rev_component_rec.include_on_ship_docs IS NOT NULL AND
6471        p_rev_component_rec.include_on_ship_docs NOT IN (1, 2)
6472     THEN
6473          IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_SUCCESS)
6474         THEN
6475                 Error_Handler.Add_Error_Token
6476                 (  p_Message_Name       => 'BOM_INCL_ON_SHIP_DOCS_INVALID'
6477                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6478                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6479                  , p_Token_Tbl          => g_Token_Tbl
6480                 );
6481         END IF;
6482         l_return_status := FND_API.G_RET_STS_ERROR;
6483     END IF;
6484 
6485     IF p_rev_component_rec.quantity_related IS NOT NULL AND
6486        p_rev_component_rec.quantity_related NOT IN (1, 2)
6487     THEN
6488          IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_SUCCESS)
6489         THEN
6490                 Error_Handler.Add_Error_Token
6491                 (  p_Message_Name       => 'BOM_QTY_RELATED_INVALID'
6492                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6493                  , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6494                  , p_Token_Tbl          => g_Token_Tbl
6495                 );
6496         END IF;
6497         l_return_status := FND_API.G_RET_STS_ERROR;
6498     END IF;
6499 
6500     -- Validation specific to unimplemented BOM
6501     Error_handler.write_debug ('BOM Implementation date is '||p_rev_comp_unexp_rec.bom_implementation_date);
6502 
6503     IF p_rev_comp_unexp_rec.bom_implementation_date IS NULL
6504     /* added a dummy condition to make sure this validation happens for any BOM, no matter whether the BOM is fluid or not */
6505     OR 1=1
6506     THEN
6507       IF p_rev_component_rec.new_effectivity_date IS NOT NULL AND
6508        p_rev_component_rec.new_effectivity_date <> FND_API.G_MISS_DATE AND
6509        Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_BOM_BO
6510       THEN
6511 	/* Check revision exists for revised item */
6512 	IF NOT Item_Revision_Exists(p_rev_comp_unexp_rec.revised_item_id,
6513 				p_rev_comp_unexp_rec.organization_id,
6514 				p_rev_component_rec.new_effectivity_date)
6515 	THEN
6516           g_token_tbl(1).token_name := 'ITEM_NAME';
6517           g_token_tbl(1).token_value := p_rev_component_rec.revised_item_name;
6518           g_token_tbl(2).token_name := 'EFFECTIVITY_DATE';
6519           g_token_tbl(2).token_value := p_rev_component_rec.start_effective_date;
6520           g_token_tbl(3).token_name := 'NEW_EFFECTIVE_DATE';
6521           g_token_tbl(3).token_value := p_rev_component_rec.new_effectivity_date;
6522 
6523           Error_Handler.Add_Error_Token
6524           (  p_Message_Name       => 'BOM_DATE_LESS_ITEMREV'
6525            , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6526            , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6527            , p_Token_Tbl          => g_Token_Tbl
6528            );
6529           l_return_status := FND_API.G_RET_STS_ERROR;
6530 	END IF;
6531 
6532 	/* Check revision exists for component item */
6533 
6534         IF NOT Item_Revision_Exists(p_rev_comp_unexp_rec.component_item_id,
6535                                 p_rev_comp_unexp_rec.organization_id,
6536                                 p_rev_component_rec.new_effectivity_date)
6537         THEN
6538           g_token_tbl(1).token_name := 'ITEM_NAME';
6539           g_token_tbl(1).token_value := p_rev_component_rec.component_item_name;
6540           g_token_tbl(2).token_name := 'EFFECTIVITY_DATE';
6541           g_token_tbl(2).token_value := p_rev_component_rec.start_effective_date;
6542           g_token_tbl(3).token_name := 'NEW_EFFECTIVE_DATE';
6543           g_token_tbl(3).token_value := p_rev_component_rec.new_effectivity_date;
6544 
6545           Error_Handler.Add_Error_Token
6546           (  p_Message_Name       => 'BOM_DATE_LESS_ITEMREV'
6547            , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6548            , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6549            , p_Token_Tbl          => g_Token_Tbl
6550            );
6551           l_return_status := FND_API.G_RET_STS_ERROR;
6552         END IF;
6553       END IF;
6554 
6555     ELSE
6556         /* The validation to check the new effective date < sysdate has been commented since the business objects should be able to support migrating the old data from legacy system into apps. The new date validation is always done
6557 in the UI   */
6558 
6559       Null;
6560 
6561    /*  commented for bug 3281414
6562       IF p_rev_component_rec.new_effectivity_date IS NOT NULL AND
6563        p_rev_component_rec.new_effectivity_date <> FND_API.G_MISS_DATE AND
6564        p_rev_component_rec.new_effectivity_date < SYSDATE AND
6565        Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_BOM_BO
6566       THEN
6567         g_token_tbl(1).token_name := 'COMPONENT_ITEM_NAME';
6568         g_token_tbl(1).token_value := p_rev_component_rec.component_item_name;
6569         g_token_tbl(2).token_name := 'EFFECTIVITY_DATE';
6570         g_token_tbl(2).token_value := p_rev_component_rec.start_effective_date;
6571         g_token_tbl(3).token_name := 'NEW_EFFECTIVE_DATE';
6572         g_token_tbl(3).token_value := p_rev_component_rec.new_effectivity_date;
6573 
6574         Error_Handler.Add_Error_Token
6575         (  p_Message_Name       => 'BOM_NEW_DATE_LESS_CURR'
6576          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6577          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6578          , p_Token_Tbl          => g_Token_Tbl
6579          );
6580         l_return_status := FND_API.G_RET_STS_ERROR;
6581 
6582       END IF;
6583    */
6584     END IF;
6585 
6586     /* added a condition to make sure this validation happens during create for any BOM, no matter whether the BOM is fluid or not */
6587     IF (p_rev_comp_unexp_rec.bom_implementation_date IS NULL )
6588      /*  OR (p_rev_component_rec.transaction_type = BOM_GLOBALS.G_OPR_CREATE)*/
6589    --Commented for bug 5702625.
6590     THEN
6591       IF p_rev_component_rec.start_effective_date IS NOT NULL AND
6592        p_rev_component_rec.start_effective_date <> FND_API.G_MISS_DATE AND
6593        Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_BOM_BO
6594       THEN
6595         /* Check revision exists for revised item */
6596     	Error_handler.write_debug ('Checking for item revision start date');
6597         IF NOT Item_Revision_Exists(p_rev_comp_unexp_rec.revised_item_id,
6598                                 p_rev_comp_unexp_rec.organization_id,
6599                                 p_rev_component_rec.start_effective_date)
6600         THEN
6601     	  Error_handler.write_debug ('Checking for item revision start date error');
6602           g_token_tbl(1).token_name := 'ITEM_NAME';
6603           g_token_tbl(1).token_value := p_rev_component_rec.revised_item_name;
6604           --g_token_tbl(1).token_value := to_char(p_rev_comp_unexp_rec.revised_item_id)||':'||to_char(p_rev_comp_unexp_rec.organization_id)||':'||to_char(p_rev_component_rec.start_effective_date,'dd-mon-yyyy hh24:mi:ss');
6605           g_token_tbl(2).token_name := 'EFFECTIVITY_DATE';
6606           g_token_tbl(2).token_value := p_rev_component_rec.start_effective_date;
6607 
6608           Error_Handler.Add_Error_Token(
6609             p_Message_Name       => 'BOM_SDATE_LESS_ITEMREV'
6610            , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6611            , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6612            , p_Token_Tbl          => g_Token_Tbl
6613            );
6614           l_return_status := FND_API.G_RET_STS_ERROR;
6615         END IF;
6616 
6617         /* Check revision exists for component item */
6618 
6619         IF NOT Item_Revision_Exists(p_rev_comp_unexp_rec.component_item_id,
6620                                 p_rev_comp_unexp_rec.organization_id,
6621                                 p_rev_component_rec.start_effective_date)
6622         THEN
6623           g_token_tbl(1).token_name := 'ITEM_NAME';
6624           g_token_tbl(1).token_value := p_rev_component_rec.component_item_name;
6625           --g_token_tbl(1).token_value := to_char(p_rev_comp_unexp_rec.component_item_id)||':'||to_char(p_rev_comp_unexp_rec.organization_id)||':'||to_char(p_rev_component_rec.start_effective_date,'dd-mon-yyyy hh24:mi:ss');
6626           g_token_tbl(2).token_name := 'EFFECTIVITY_DATE';
6627           g_token_tbl(2).token_value := p_rev_component_rec.start_effective_date;
6628 
6629           Error_Handler.Add_Error_Token
6630           (  p_Message_Name       => 'BOM_SDATE_LESS_ITEMREV'
6631            , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6632            , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6633            , p_Token_Tbl          => g_Token_Tbl
6634            );
6635           l_return_status := FND_API.G_RET_STS_ERROR;
6636         END IF;
6637       END IF;
6638 
6639     ELSE
6640 
6641       /* The validation to check the start effective date > sysdate has been commented
6642 	 since the business objects should be able to support migrating the old data
6643          from legacy system into apps. The start date validation is always done in the UI*/
6644 
6645 	Null;
6646 
6647       /*
6648       IF p_rev_component_rec.start_effective_date IS NOT NULL AND
6649        p_rev_component_rec.start_effective_date <> FND_API.G_MISS_DATE AND
6650        trunc(p_rev_component_rec.start_effective_date) < trunc(SYSDATE) AND
6651        Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_BOM_BO
6652       THEN
6653         g_token_tbl(1).token_name := 'COMPONENT_ITEM_NAME';
6654         g_token_tbl(1).token_value := p_rev_component_rec.component_item_name;
6655         g_token_tbl(2).token_name := 'EFFECTIVITY_DATE';
6656         g_token_tbl(2).token_value := p_rev_component_rec.start_effective_date;
6657 
6658         Error_Handler.Add_Error_Token
6659         (  p_Message_Name       => 'BOM_START_DATE_LESS_CURR'
6660          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6661          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6662          , p_Token_Tbl          => g_Token_Tbl
6663          );
6664         l_return_status := FND_API.G_RET_STS_ERROR;
6665 
6666       END IF;
6667       */
6668 
6669     END IF;
6670 
6671     -- Validation specific to enforce integer requirements
6672 
6673     IF p_rev_comp_unexp_rec.enforce_int_requirements_code = 1 /* If the enforce int req is 'Up' */
6674     THEN
6675 
6676       BEGIN
6677 		/* Enforce_Integer can be UP only if the component item's rounding control type allows
6678 		   to round order quantities */
6679 
6680            SELECT 'x' INTO l_dummy FROM mtl_system_items WHERE
6681             inventory_item_id = p_rev_comp_unexp_rec.component_item_id
6682             AND organization_id = p_rev_comp_unexp_rec.organization_id
6683             AND rounding_control_type = 1;
6684 
6685 	    EXCEPTION WHEN NO_DATA_FOUND THEN
6686 		      g_token_tbl.DELETE;
6687         	Error_Handler.Add_Error_Token
6688         	(  p_Message_Name       => 'BOM_ENFORCE_INT_INVALID'
6689          	, p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6690          	, x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6691          	, p_Token_Tbl          => g_Token_Tbl
6692          	);
6693         	l_return_status := FND_API.G_RET_STS_ERROR;
6694 	    END;
6695 
6696     END IF;
6697 
6698    --Validation to ensure that a pending structure header cannot be modified without an ECO
6699       IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Checking if the BOM header is implemented . . .'); END IF;
6700 
6701    IF BOM_GLOBALS.Get_Bill_Header_ECN(p_rev_comp_unexp_rec.bill_Sequence_id) IS NOT NULL
6702       AND (p_rev_component_rec.eco_name IS NULL OR p_rev_component_rec.eco_name = FND_API.G_MISS_CHAR)
6703    THEN
6704       g_token_tbl(1).token_name := 'ALTERNATE';
6705       g_token_tbl(1).token_value := nvl(p_rev_component_rec.Alternate_BOM_Code, bom_globals.retrieve_message('BOM', 'BOM_PRIMARY'));
6706       g_token_tbl(2).token_name := 'ASSY_ITEM';
6707       g_token_tbl(2).token_value := p_rev_component_rec.Revised_Item_Name;
6708       g_token_tbl(3).token_name := 'CHANGE_NOTICE';
6709       g_token_tbl(3).token_value := BOM_GLOBALS.Get_Bill_Header_ECN(p_rev_comp_unexp_rec.bill_Sequence_id);
6710 
6711       Error_Handler.Add_Error_Token
6712       (  p_Message_Name       => 'BOM_HEADER_UNIMPLEMENTED'
6713        , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6714        , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6715        , p_Token_Tbl          => g_Token_Tbl
6716        );
6717       l_return_status := FND_API.G_RET_STS_ERROR;
6718 
6719    END IF;
6720 
6721     --  Done validating attributes
6722 
6723     x_return_status := l_return_status;
6724     x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
6725 
6726 		EXCEPTION
6727 
6728     		WHEN OTHERS THEN
6729 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Some unknown error in Attribute Validation . . .' || SQLERRM ); END IF;
6730 
6731 			Error_Handler.Add_Error_Token
6732 			(  p_Message_Name	=> NULL
6733                  	 , p_Message_Text	=>
6734 					'Error in Rev Comp Attr. Validation '
6735 					   || SUBSTR(SQLERRM, 1, 30) || ' ' ||
6736 					   to_char(SQLCODE)
6737                  	 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
6738 			 , p_Mesg_Token_Tbl	=> l_Mesg_token_Tbl
6739 		 	);
6740 			x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
6741 			x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6742 
6743 	END Check_Attributes;
6744 
6745 
6746 	/*******************************************************************
6747 	* Procedure	: Check_Entity_Delete
6748 	* Parameters IN	: Revised Component Exposed Column Record
6749 	*		  Revised Component unexposed column record
6750 	* Parameters OUT: Message Token Table
6751 	*		  Return Status
6752 	* Procedure	: Will check if a component can be deleted.
6753 	*******************************************************************/
6754 	PROCEDURE Check_Entity_Delete
6755 	( x_return_status          IN OUT NOCOPY VARCHAR2
6756 	, x_Mesg_Token_Tbl         IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
6757 	, p_rev_component_rec      IN  Bom_Bo_Pub.Rev_Component_Rec_Type
6758 	, p_Rev_Comp_Unexp_Rec     IN  Bom_Bo_Pub.Rev_Comp_Unexposed_Rec_Type
6759 	)
6760 	IS
6761 	l_return_status         VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
6762 	l_Mesg_Token_Tbl	Error_Handler.Mesg_Token_Tbl_Type;
6763 
6764 	BEGIN
6765 
6766     		g_Token_Tbl(1).Token_Name := 'REVISED_COMPONENT_NAME';
6767     		g_Token_Tbl(1).Token_Value :=
6768 				p_rev_component_rec.component_item_name;
6769 
6770    		--
6771    		-- Verify that the component is not already cancelled.
6772    		--
6773    		IF p_rev_component_rec.Transaction_Type =
6774 			BOM_GLOBALS.G_OPR_DELETE
6775 		THEN
6776     			BEGIN
6777         			SELECT 'Component cancelled'
6778           			INTO l_dummy
6779           			FROM sys.dual
6780          			WHERE NOT EXISTS
6781 	       			(SELECT 1 from bom_inventory_components
6782                  		  WHERE component_sequence_id =
6783 		       		     p_rev_comp_Unexp_rec.component_sequence_id
6784 				)
6785            			AND EXISTS (SELECT 1 from eng_revised_components
6786                         		     WHERE component_sequence_id =
6787 			      	    p_rev_comp_Unexp_rec.component_sequence_id);
6788 
6789         		--
6790         		-- if not exception is raised then record is deleted.
6791 			-- so raise an error.
6792         		--
6793         			IF FND_MSG_PUB.Check_Msg_Level
6794 				(FND_MSG_PUB.G_MSG_LVL_ERROR)
6795         			THEN
6796              				Error_Handler.Add_Error_Token
6797 	     				(  p_Message_Name=> 'BOM_COMP_CANCELLED'
6798 	     		 		, p_Mesg_Token_Tbl=> l_Mesg_Token_Tbl
6799 	     		 		, x_Mesg_Token_Tbl=> l_Mesg_Token_Tbl
6800 	     				 , p_Token_Tbl	=> g_Token_Tbl
6801 	      				);
6802         			END IF;
6803         			l_return_status := FND_API.G_RET_STS_ERROR;
6804         			EXCEPTION
6805                 			WHEN NO_DATA_FOUND THEN
6806                         		null; -- do nothing the record is valid.
6807      			END;
6808     	END IF;
6809 
6810    	x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
6811    	x_return_status := l_return_status;
6812 
6813 	EXCEPTION
6814 
6815     		WHEN FND_API.G_EXC_ERROR THEN
6816 
6817 		x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
6818         	x_return_status := FND_API.G_RET_STS_ERROR;
6819 
6820     		WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6821 		x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
6822         	x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6823 
6824     		WHEN OTHERS THEN
6825 		x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
6826         	x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
6827 
6828 	END Check_Entity_Delete;
6829 
6830 	/******************************************************************
6831 	* Procedure     : Check_Existence
6832 	* Parameters IN : Revised component exposed column record
6833 	*                 Revised component unexposed column record
6834 	* Parameters OUT: Old Revised component exposed column record
6835 	*                 Old Revised component unexposed column record
6836 	*                 Mesg Token Table
6837 	*                 Return Status
6838 	* Purpose       : Check_Existence will query using the primary key
6839 	*                 information and return a success if the operation is
6840 	*                 CREATE and the record EXISTS or will return an
6841 	*                 error if the operation is UPDATE and record DOES NOT
6842 	*                 EXIST.
6843 	*                 In case of UPDATE if record exists, then the procedure
6844 	*                 will return old record in the old entity parameters
6845 	*                 with a success status.
6846 	*********************************************************************/
6847 	PROCEDURE Check_Existence
6848 	(  p_rev_component_rec      IN  Bom_Bo_Pub.Rev_Component_Rec_Type
6849 	 , p_rev_comp_unexp_rec     IN  Bom_Bo_Pub.Rev_Comp_Unexposed_Rec_Type
6850 	 , x_old_rev_component_rec  IN OUT NOCOPY Bom_Bo_Pub.Rev_Component_Rec_Type
6851 	 , x_old_rev_comp_unexp_rec IN OUT NOCOPY Bom_Bo_Pub.Rev_Comp_Unexposed_Rec_Type
6852 	 , x_Mesg_Token_Tbl         IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
6853 	 , x_return_status          IN OUT NOCOPY VARCHAR2
6854 	)
6855 	IS
6856         	l_token_tbl      Error_Handler.Token_Tbl_Type;
6857         	l_Mesg_Token_Tbl Error_Handler.Mesg_Token_Tbl_Type;
6858         	l_return_status  VARCHAR2(1);
6859 	BEGIN
6860         	l_Token_Tbl(1).Token_Name  := 'REVISED_COMPONENT_NAME';
6861         	l_Token_Tbl(1).Token_Value :=
6862 				p_rev_component_rec.component_item_name;
6863 		l_Token_Tbl(2).Token_Name  := 'REVISED_ITEM_NAME';
6864         	l_Token_Tbl(2).Token_Value :=
6865 				p_rev_component_rec.revised_item_name;
6866 
6867         	Bom_Bom_Component_Util.Query_Row
6868 		( p_Component_Item_Id => p_rev_comp_unexp_rec.component_item_id
6869 		, p_Operation_Sequence_Number =>
6870 				p_rev_component_rec.operation_sequence_number
6871 		, p_Effectivity_Date	=>
6872 				p_rev_component_rec.start_effective_date
6873 		, p_Bill_Sequence_Id	=> p_rev_comp_unexp_rec.bill_sequence_id
6874 		, p_from_end_item_number=>
6875 				p_rev_component_rec.from_end_item_unit_number
6876 		, p_mesg_Token_tbl	=> l_mesg_token_tbl
6877 		, x_Rev_Component_Rec	=> x_old_rev_component_rec
6878 		, x_Rev_Comp_Unexp_Rec  => x_old_rev_comp_unexp_rec
6879 		, x_mesg_Token_tbl 	=> l_mesg_token_tbl
6880 		, x_Return_Status	=> l_return_status
6881 		);
6882 
6883         	IF l_return_status = BOM_Globals.G_RECORD_FOUND AND
6884            	p_rev_component_rec.transaction_type = BOM_Globals.G_OPR_CREATE
6885         	THEN
6886                 	Error_Handler.Add_Error_Token
6887                 	(  x_Mesg_token_tbl => l_Mesg_Token_Tbl
6888                 	 , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
6889                 	 , p_message_name  => 'BOM_REV_COMP_ALREADY_EXISTS'
6890                 	 , p_token_tbl     => l_token_tbl
6891                 	 );
6892                  	l_return_status := FND_API.G_RET_STS_ERROR;
6893         	ELSIF l_return_status = BOM_Globals.G_RECORD_NOT_FOUND AND
6894               		p_rev_component_rec.transaction_type IN
6895                 	(BOM_Globals.G_OPR_UPDATE, BOM_Globals.G_OPR_DELETE)
6896         	THEN
6897                 	Error_Handler.Add_Error_Token
6898                 	(  x_Mesg_token_tbl => l_Mesg_Token_Tbl
6899                 	 , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
6900                 	 , p_message_name  => 'BOM_REV_COMP_DOESNOT_EXIST'
6901                 	 , p_token_tbl     => l_token_tbl
6902                  	);
6903                  	l_return_status := FND_API.G_RET_STS_ERROR;
6904         	ELSIF l_Return_status = FND_API.G_RET_STS_UNEXP_ERROR
6905         	THEN
6906                 	Error_Handler.Add_Error_Token
6907                 	(  x_Mesg_token_tbl     => l_Mesg_Token_Tbl
6908                 	 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
6909                 	 , p_message_name       => NULL
6910                 	 , p_message_text       =>
6911                   	 'Unexpected error while existence verification of ' ||
6912                   	 'Revised component '||
6913 		  	 p_rev_component_rec.component_item_name
6914                 	 , p_token_tbl          => l_token_tbl
6915                 	 );
6916         	ELSE
6917 
6918 
6919                   /* Assign the relevant transaction type for SYNC operations */
6920 
6921                   IF p_rev_component_rec.transaction_type = 'SYNC' THEN
6922                     IF l_return_status = Bom_Globals.G_RECORD_FOUND THEN
6923                       x_old_rev_component_rec.transaction_type :=
6924                                                    Bom_Globals.G_OPR_UPDATE;
6925                     ELSE
6926                       x_old_rev_component_rec.transaction_type :=
6927                                                    Bom_Globals.G_OPR_CREATE;
6928                     END IF;
6929                   END IF;
6930                   l_return_status := FND_API.G_RET_STS_SUCCESS;
6931 
6932         	END IF;
6933 
6934         	x_return_status := l_return_status;
6935         	x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
6936 
6937 	END Check_Existence;
6938 
6939 	/******************************************************************
6940 	* Prcoedure	: Check_Lineage
6941 	* Parameters IN	: Revised Component exposed column record
6942 	*		  Revised Component unexposed column record
6943 	* Parameters OUT: Mesg_Token_Tbl
6944 	*		  Return_Status
6945 	* Purpose	: Check_Lineage procedure will verify that the entity
6946 	*		  record that the user has passed is for the right
6947 	*		  parent and that the parent exists.
6948 	*********************************************************************/
6949 	PROCEDURE Check_Lineage
6950 	(  p_rev_component_rec	IN  Bom_Bo_Pub.Rev_Component_Rec_Type
6951 	 , p_rev_comp_unexp_rec	IN  Bom_Bo_Pub.Rev_Comp_Unexposed_Rec_Type
6952 	 , x_Mesg_Token_Tbl	IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
6953 	 , x_Return_Status	IN OUT NOCOPY VARCHAR2
6954 	)
6955 	IS
6956 		CURSOR c_GetComponent IS
6957 		SELECT revised_item_sequence_id
6958 	  	FROM bom_inventory_components
6959 	 	WHERE component_item_id = p_rev_comp_unexp_rec.component_item_id
6960 	   	AND bill_sequence_id  = p_rev_comp_unexp_rec.bill_sequence_id
6961 	   	AND operation_seq_num =
6962 				p_rev_component_rec.operation_sequence_number
6963 	   	AND effectivity_date = p_rev_component_rec.start_effective_date;
6964 
6965 		l_Token_Tbl		Error_Handler.Token_Tbl_Type;
6966 		l_return_status 	VARCHAR2(1);
6967 		l_Mesg_Token_Tbl	Error_Handler.Mesg_Token_Tbl_Type;
6968 
6969 	BEGIN
6970 		l_return_status := FND_API.G_RET_STS_SUCCESS;
6971 
6972 		/*************************************************************
6973 		--
6974 		-- In case of an update, based on the revised item information
6975 		-- Bill Sequence Id and Revised Item Sequence Id is queried from
6976 		-- the database. The revised item sequence id can however be
6977 		-- different from that in the database and should be checked
6978 		-- and given an error.
6979 		*************************************************************/
6980 
6981 		IF p_rev_component_rec.transaction_type IN
6982 	   	   (BOM_Globals.G_OPR_UPDATE, BOM_Globals.G_OPR_DELETE,
6983 	    	    BOM_Globals.G_OPR_CANCEL)
6984 		THEN
6985 			FOR Component IN c_GetComponent LOOP
6986 			 IF NVL(Component.revised_item_sequence_id, 0) <>
6987 			    NVL(p_rev_comp_unexp_rec.revised_item_sequence_id,0)
6988 			 THEN
6989 					l_Token_Tbl(1).token_name  :=
6990 						'REVISED_COMPONENT_NAME';
6991 					l_Token_Tbl(1).token_value :=
6992 					p_rev_component_rec.component_item_name;
6993 					l_Token_Tbl(2).token_name  :=
6994 						'REVISED_ITEM_NAME';
6995 					l_Token_Tbl(2).token_value :=
6996 					p_rev_component_rec.revised_item_name;
6997 					l_token_tbl(3).token_name := 'ECO_NAME';
6998 					l_token_tbl(3).token_value :=
6999 					p_rev_component_rec.eco_name;
7000 
7001 					Error_Handler.Add_Error_Token
7002 					(  p_Message_Name =>
7003 						'BOM_REV_ITEM_MISMATCH'
7004 					 , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
7005 					 , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
7006 					 , p_Token_Tbl	    => l_Token_Tbl
7007 					 );
7008 					l_return_status :=
7009 						FND_API.G_RET_STS_ERROR;
7010 			  END IF;
7011 			END LOOP;
7012 		END IF;
7013 
7014 		x_return_status := l_return_status;
7015 		x_mesg_token_tbl := l_mesg_token_tbl;
7016 
7017 	END Check_Lineage;
7018 
7019 	/*************************************************************
7020 	* Procedure	: Check_Access
7021 	* Parameters IN	: Revised Item Unique Key
7022 	*		  Revised Component unique key
7023 	* Parameters OUT: Mesg_Token_Tbl
7024 	*		  Return_Status
7025 	* Purpose	: Procedure will verify that the revised item and the
7026 	*		  revised component is accessible to the user.
7027 	********************************************************************/
7028 	PROCEDURE Check_Access
7029 	(  p_revised_item_name		IN  VARCHAR2
7030 	 , p_revised_item_id		IN  NUMBER
7031 	 , p_organization_id		IN  NUMBER
7032 	 , p_change_notice		IN  VARCHAR2
7033 	 , p_new_item_revision		IN  VARCHAR2
7034 	 , p_effectivity_date		IN  DATE
7035          , p_new_routing_revsion        IN  VARCHAR2 := NULL -- Added by MK on 11/02/00
7036          , p_from_end_item_number       IN  VARCHAR2 := NULL -- Added by MK on 11/02/00
7037 	 , p_component_item_id		IN  NUMBER
7038 	 , p_operation_seq_num		IN  NUMBER
7039 	 , p_bill_sequence_id		IN  NUMBER
7040 	 , p_component_name		IN  VARCHAR2
7041 	 , p_Mesg_Token_Tbl		IN  Error_Handler.Mesg_Token_Tbl_Type :=
7042 				    Error_Handler.G_MISS_MESG_TOKEN_TBL
7043 	 , p_entity_processed		IN  VARCHAR2 := 'RC'
7044 	 , p_rfd_sbc_name		IN  VARCHAR2 := NULL
7045 	 , x_Mesg_Token_Tbl		IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
7046 	 , x_Return_Status		IN OUT NOCOPY VARCHAR2
7047 	)
7048 	IS
7049 		l_Token_Tbl		Error_Handler.Token_Tbl_Type;
7050 		l_Mesg_Token_Tbl	Error_Handler.Mesg_Token_Tbl_Type :=
7051 				p_Mesg_Token_Tbl;
7052 		l_return_status		VARCHAR2(1);
7053 		l_Rev_Comp_Item_Type	NUMBER;
7054 		l_error_name		VARCHAR2(30);
7055         	l_is_comp_unit_controlled BOOLEAN := FALSE;
7056 		l_is_item_unit_controlled BOOLEAN := FALSE;
7057 
7058 		CURSOR c_CheckCancelled IS
7059 		SELECT 1
7060 	  	FROM sys.dual
7061 	 	WHERE NOT EXISTS
7062 			( SELECT component_sequence_id
7063 		    	FROM bom_inventory_components
7064 		   	WHERE component_item_id = p_component_item_id
7065 		     	AND bill_sequence_id  = p_bill_sequence_id
7066 		     	AND effectivity_date  = p_effectivity_date
7067 		     	AND operation_seq_num = p_operation_seq_num
7068 		 	) AND
7069 			EXISTS
7070 			( SELECT component_sequence_id
7071 		    	    FROM eng_revised_components
7072 		   	   WHERE component_item_id = p_component_item_id
7073                      	   AND bill_sequence_id  = p_bill_sequence_id
7074                      	   AND effectivity_date  = p_effectivity_date
7075                      	   AND operation_sequence_num = p_operation_seq_num
7076 			   );
7077 
7078 		CURSOR c_CheckDisabled IS
7079 		SELECT component_item_id
7080 	  	FROM bom_inventory_components
7081 	 	WHERE component_item_id = p_component_item_id
7082            	AND bill_sequence_id  = p_bill_sequence_id
7083            	AND effectivity_date  = p_effectivity_date
7084            	AND operation_seq_num = p_operation_seq_num
7085 	   	AND acd_type = 3;
7086 
7087         	CURSOR c_Check_Unit_Effective IS
7088         	SELECT effectivity_control
7089           	FROM mtl_system_items
7090          	WHERE inventory_item_id = p_component_item_id
7091            	AND organization_id   = p_organization_id;
7092 
7093 
7094 	BEGIN
7095 		l_return_status := FND_API.G_RET_STS_SUCCESS;
7096 
7097 		/**********************************************************
7098 		--
7099 		-- Check if the user has access to the revised component's
7100 		-- bom_item_type
7101 		--
7102 		***********************************************************/
7103 		SELECT bom_item_type
7104 	  	INTO l_rev_comp_item_type
7105 	  	FROM mtl_system_items
7106 	 	WHERE inventory_item_id = p_component_item_id
7107 	   	AND organization_id   = p_organization_id;
7108 
7109 		IF l_rev_comp_item_type NOT IN
7110 	   	   (NVL(BOM_Globals.Get_MDL_Item_Access,0),
7111 	   	    NVL(BOM_Globals.Get_OC_Item_Access,0),
7112 	   	    NVL(BOM_Globals.Get_PLN_Item_Access,0),
7113 	   	    NVL(BOM_Globals.Get_STD_Item_Access,0)
7114 	  	    )
7115 		THEN
7116 			l_token_tbl(1).token_name  := 'REVISED_COMPONENT_NAME';
7117 			l_token_tbl(1).token_value := p_component_name;
7118 			l_token_tbl(2).token_name  := 'BOM_ITEM_TYPE';
7119 			l_token_tbl(2).translate   := TRUE;
7120 
7121                 	IF l_rev_comp_Item_Type = 1
7122                 	THEN
7123                       		l_Token_Tbl(2).Token_Value := 'BOM_MODEL';
7124                 	ELSIF l_rev_comp_Item_Type = 2
7125                 	THEN
7126                       		l_Token_Tbl(2).Token_Value:='BOM_OPTION_CLASS';
7127                 	ELSIF l_rev_comp_Item_Type = 3
7128                 	THEN
7129                       		l_Token_Tbl(2).Token_Value := 'BOM_PLANNING';
7130                 	ELSIF l_rev_comp_Item_Type = 4
7131                 	THEN
7132                       		l_Token_Tbl(2).Token_Value := 'BOM_STANDARD';
7133                 	END IF;
7134 
7135 			Error_Handler.Add_Error_Token
7136                 	(  p_Message_Name       => 'BOM_REV_COMP_ACCESS_DENIED'
7137                 	 , p_Mesg_Token_Tbl     => l_mesg_token_tbl
7138                 	 , x_Mesg_Token_Tbl     => l_mesg_token_tbl
7139                 	 , p_Token_Tbl          => l_token_tbl
7140                  	);
7141 		 	l_token_tbl.DELETE(2);
7142                  	l_return_status := FND_API.G_RET_STS_ERROR;
7143 		END IF;
7144 
7145 	IF l_rev_comp_item_type = 5 /* Product Family */
7146 	THEN
7147 		Error_Handler.Add_Error_Token
7148                 (  p_Message_Name       => 'BOM_REV_COMP_PRODUCT_FAMILY'
7149                  , p_Mesg_Token_Tbl     => l_mesg_token_tbl
7150                  , x_Mesg_Token_Tbl     => l_mesg_token_tbl
7151                  , p_Token_Tbl          => l_token_tbl
7152                  );
7153                  l_return_status := FND_API.G_RET_STS_ERROR;
7154 	END IF;
7155 
7156 	/****************************************************************
7157 	--
7158 	-- If revised item check is successful, then check if the revised
7159 	-- component is not cancelled. This check will not prove useful for
7160 	-- the revised item itself, since the check existence for a cancelled
7161 	-- component would fail. But this procedure can be called by the
7162 	-- child records of the revised component and make sure that the
7163 	-- parent record is not cancelled.
7164 	--
7165 	********************************************************************/
7166 
7167 	IF BOM_Globals.Is_RComp_Cancl IS NULL THEN
7168 		FOR RevComp IN c_CheckCancelled
7169 		LOOP
7170 			l_token_tbl.DELETE;
7171 			l_Token_Tbl(1).Token_Name  := 'REVISED_COMPONENT_NAME';
7172 			l_Token_Tbl(1).Token_value := p_component_name;
7173 			Error_Handler.Add_Error_Token
7174 			(  p_Message_Name	=> 'BOM_REV_COMP_CANCELLED'
7175 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
7176 			 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
7177 			 , p_Token_Tbl		=> l_token_tbl
7178 			);
7179 			l_return_status := FND_API.G_RET_STS_ERROR;
7180 		END LOOP;
7181 	END IF;
7182 
7183         /*********************************************************************
7184          -- Added by AS on 07/06/99
7185          -- Checks that unit effective items are allowed only if the profile
7186          -- value allows them (profile value stored in system_information)
7187         *********************************************************************/
7188 
7189         IF NOT BOM_Globals.Get_Unit_Effectivity
7190 	THEN
7191            	IF BOM_Globals.Get_Unit_Controlled_Component
7192 		THEN
7193                 	l_token_tbl(1).token_name := 'REVISED_COMPONENT_NAME';
7194 			l_token_tbl(1).token_value :=
7195                                     	p_component_name;
7196 			l_token_tbl(2).token_name := 'ECO_NAME';
7197 			l_token_tbl(2).token_value :=
7198                                     	p_change_notice;
7199 			Error_Handler.Add_Error_Token
7200                 	( p_Message_Name   => 'BOM_REV_COMP_UNIT_CONTROL'
7201                 	, p_Mesg_Token_Tbl => l_mesg_token_tbl
7202                 	, x_Mesg_Token_Tbl => l_mesg_token_tbl
7203                 	, p_Token_Tbl      => l_token_tbl
7204                 	);
7205                 	l_return_status := FND_API.G_RET_STS_ERROR;
7206 		END IF;
7207         ELSE
7208 		IF NOT BOM_Globals.Get_Unit_Controlled_Item AND
7209 		   BOM_Globals.Get_Unit_Controlled_Component
7210 		THEN
7211                         l_token_tbl(1).token_name := 'REVISED_COMPONENT_NAME';
7212                         l_token_tbl(1).token_value :=
7213                                         p_component_name;
7214                         l_token_tbl(2).token_name := 'ECO_NAME';
7215                         l_token_tbl(2).token_value :=
7216                                         p_change_notice;
7217                         Error_Handler.Add_Error_Token
7218                         ( p_Message_Name   => 'BOM_REV_ITEM_NOT_UNIT_CONTROL'
7219                         , p_Mesg_Token_Tbl => l_mesg_token_tbl
7220                         , x_Mesg_Token_Tbl => l_mesg_token_tbl
7221                         , p_Token_Tbl      => l_token_tbl
7222                         );
7223                         l_return_status := FND_API.G_RET_STS_ERROR;
7224                 END IF;
7225 	END IF;
7226 
7227 
7228         /**************************************************************
7229         -- Added by MK on 11/01/2000
7230         -- If bill sequence id is null(Trans Type : CREATE) and this revised
7231         --  item does not have primary bill, verify that parent revised
7232         -- item does not have routing sequence id which has alternate code.
7233         -- (Verify this eco is not only for alternate routing)
7234         --
7235         -- Moved to Engineering space to reslove ECO dependency
7236         -- by MK on 12/03/00
7237         IF p_bill_sequence_id IS NULL
7238         AND Not Check_RevItem_Alternate
7239                                     (  p_revised_item_id   =>  p_revised_item_id
7240                                      , p_organization_id   =>  p_organization_id
7241                                      , p_change_notice     =>  p_change_notice
7242                                      , p_new_item_revision =>  p_new_item_revision
7243                                      , p_new_routing_revsion => p_new_routing_revsion
7244                                      , p_effective_date    =>  p_effectivity_date
7245                                      , p_from_end_item_number => p_from_end_item_number
7246                                      )
7247 
7248         THEN
7249 
7250                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
7251                 THEN
7252                         l_token_tbl.delete;
7253                         l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
7254                         l_token_tbl(1).token_value := p_revised_item_name ;
7255 
7256                         Error_Handler.Add_Error_Token
7257                         (  p_Message_Name       => 'ENG_CANNOT_ADD_ALTERNATE'
7258                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
7259                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
7260                          , p_Token_Tbl          => l_Token_Tbl
7261                          );
7262 
7263                 END IF;
7264                 l_return_status := FND_API.G_RET_STS_ERROR;
7265         END IF;
7266         **************************************************************/
7267 
7268 
7269 
7270 	/**************************************************************
7271 	--
7272 	-- If the Entity being processed is Reference Designator
7273 	-- or subsitute component then check if the parent component is
7274 	-- disabled. If it is then Error this record and also all the
7275 	-- siblings
7276 	--
7277 	**************************************************************/
7278 	IF p_entity_processed IN ('RFD', 'SBC')
7279 	THEN
7280 		FOR isdisabled IN c_CheckDisabled LOOP
7281 			IF p_entity_processed = 'RFD'
7282 			THEN
7283 				l_error_name := 'BOM_RFD_COMP_ACD_TYPE_DISABLE';
7284 				l_token_tbl(1).token_name  :=
7285 					'REFERENCE_DESIGNATOR_NAME';
7286 				l_token_tbl(1).token_value := p_rfd_sbc_name;
7287 			ELSE
7288 				l_error_name := 'BOM_SBC_COMP_ACD_TYPE_DISABLE';
7289 				l_token_tbl(1).token_name  :=
7290                                         'SUBSTITUTE_ITEM_NAME';
7291                                 l_token_tbl(1).token_value := p_rfd_sbc_name;
7292 			END IF;
7293 
7294 			l_token_tbl(2).token_name  := 'REVISED_COMPONENT_NAME';
7295 			l_token_tbl(2).token_value := p_component_name;
7296 
7297 			l_return_status := FND_API.G_RET_STS_ERROR;
7298 
7299 			 Error_Handler.Add_Error_Token
7300                         (  p_Message_Name       => l_error_name
7301                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
7302                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
7303                          , p_Token_Tbl          => l_token_tbl
7304                         );
7305 		END LOOP;
7306 	END IF;
7307 
7308 	x_Return_Status := l_return_status;
7309 	x_Mesg_Token_Tbl := l_mesg_token_tbl;
7310 
7311 END Check_Access;
7312 
7313 	/*************************************************************
7314 	* Procedure	: Check_Direct_item_comps
7315 	* Parameters IN	: Component Record
7316 	* Parameters OUT: Component Record
7317 	*		  Mesg_Token_Tbl
7318 	*		  Return_Status
7319 	* Purpose	: Procedure will verify that the component record, if
7320 	*		  is a direct item component, is for EAM BOMs only,
7321 	*		  has correct values for direct item specific attributes,
7322 	*		  for normal item components, these attributes should
7323 	*		  be ignored.
7324 	********************************************************************/
7325 PROCEDURE Check_Direct_item_comps
7326 (    p_bom_component_rec       IN  Bom_Bo_Pub.Bom_Comps_Rec_Type
7327    , p_bom_comp_unexp_rec      IN  Bom_Bo_Pub.Bom_Comps_Unexposed_Rec_Type
7328    , x_bom_component_rec       IN OUT NOCOPY Bom_Bo_Pub.Bom_Comps_Rec_Type
7329    , x_Mesg_Token_Tbl          IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
7330    , x_Return_Status           IN OUT NOCOPY VARCHAR2
7331 ) IS
7332 --	l_bom_component_rec	Bom_Bo_Pub.Bom_Comps_Rec_Type;
7333 	l_Token_Tbl		Error_Handler.Token_Tbl_Type;
7334 	l_Mesg_Token_Tbl	Error_Handler.Mesg_Token_Tbl_Type;
7335 	l_return_status		VARCHAR2(1);
7336 BEGIN
7337 	l_return_status := FND_API.G_RET_STS_SUCCESS;
7338 	IF BOM_EAMUTIL.Direct_Item ( item_id => p_bom_comp_unexp_rec.Component_Item_Id,
7339                                      org_id  => p_bom_comp_unexp_rec.Organization_Id ) = 'N' THEN
7340 		IF (p_bom_component_rec.Suggested_Vendor_Name IS NOT NULL
7341 		 OR p_bom_component_rec.Suggested_Vendor_Name <> FND_API.G_MISS_CHAR)
7342 		THEN
7343 			x_bom_component_rec.Suggested_Vendor_Name := '';
7344 --			x_bom_component_rec.Vendor_Id := '';
7345 			Error_Handler.Add_Error_Token
7346                         (  p_Message_Name       => 'BOM_COMP_SUPPLIER_IGNORED'
7347                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
7348                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
7349                          , p_Token_Tbl          => l_token_tbl
7350                         );
7351 		END IF;
7352 		IF (p_bom_component_rec.Unit_Price IS NOT NULL
7353 		 OR p_bom_component_rec.Unit_Price <> FND_API.G_MISS_NUM)
7354 		THEN
7355 			x_bom_component_rec.Unit_Price := '';
7356 			Error_Handler.Add_Error_Token
7357                         (  p_Message_Name       => 'BOM_COMP_PRICE_IGNORED'
7358                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
7359                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
7360                          , p_Token_Tbl          => l_token_tbl
7361                         );
7362 		END IF;
7363         /*  Commented as part of bug fix 3741040
7364 	ELSE
7365 		IF BOM_EAMUTIL.Asset_Group_Item ( item_id => p_bom_comp_unexp_rec.Assembly_Item_Id,
7366                                                   org_id  => p_bom_comp_unexp_rec.Organization_Id ) = 'N'
7367 		AND BOM_EAMUTIL.Asset_Activity_Item ( item_id => p_bom_comp_unexp_rec.Assembly_Item_Id,
7368                                                       org_id  => p_bom_comp_unexp_rec.Organization_Id ) = 'N'
7369 		THEN
7370 			l_return_status := FND_API.G_RET_STS_ERROR;
7371 		END IF;
7372 	*/
7373 	END IF;
7374 --	l_bom_component_rec := x_bom_component_rec;
7375 	x_Return_Status := l_return_status;
7376 	x_Mesg_Token_Tbl := l_mesg_token_tbl;
7377 
7378 END Check_Direct_item_comps;
7379 
7380 PROCEDURE Validate_All_Attributes
7381 (       p_bo_identifier                   IN VARCHAR2 := 'BOM',
7382         p_transaction_type                IN  VARCHAR2,
7383         p_revised_item_id                 IN  NUMBER,
7384         p_organization_id                 IN  NUMBER,
7385         p_organization_code               IN  VARCHAR2,
7386         p_alternate_bom_code              IN  VARCHAR2,
7387         p_bill_sequence_id                IN  NUMBER,
7388         p_bom_implementation_date         IN  DATE,
7389         p_component_sequence_id           IN  NUMBER,
7390         p_item_sequence_number            IN  NUMBER,
7391         p_operation_sequence_number       IN  NUMBER,
7392         p_new_operation_sequence_num      IN  NUMBER := NULL,
7393         p_component_item_id               IN  NUMBER,
7394         p_from_end_item_unit_number       IN  VARCHAR2 := NULL,
7395         p_to_end_item_unit_number         IN  VARCHAR2 := NULL,
7396         p_new_from_end_item_unit_num      IN  VARCHAR2 := NULL,
7397         p_start_effective_date            IN  DATE,
7398         p_new_effectivity_date            IN  DATE := NULL,
7399         p_disable_date                    IN  DATE := NULL,
7400         p_basis_type			  IN  NUMBER := NULL,
7401         p_quantity_per_assembly           IN  NUMBER := NULL,
7402         p_projected_yield                 IN  NUMBER := NULL,
7403         p_planning_percent                IN  NUMBER := NULL,
7404         p_quantity_related                IN  NUMBER := NULL,
7405         p_include_in_cost_rollup          IN  NUMBER := NULL,
7406         p_check_atp                       IN  NUMBER := NULL,
7407         p_acd_type                        IN  NUMBER := NULL,
7408         p_auto_request_material           IN  VARCHAR2 := NULL,
7409         p_wip_supply_type                 IN  NUMBER := NULL,
7410         p_Supply_SubInventory             IN  VARCHAR2 := NULL,
7411         p_supply_locator_id               IN  NUMBER := NULL,
7412         p_location_name                   IN  VARCHAR2 := NULL,
7413         p_SO_Basis                        IN  NUMBER := NULL,
7414         p_Optional                        IN  NUMBER := NULL,
7415         p_mutually_exclusive              IN  NUMBER := NULL,
7416         p_shipping_allowed                IN  NUMBER := NULL,
7417         p_required_to_ship                IN  NUMBER := NULL,
7418         p_required_for_revenue            IN  NUMBER := NULL,
7419         p_include_on_ship_docs            IN  NUMBER := NULL,
7420         p_enforce_int_reqs_code           IN  NUMBER := NULL,
7421         p_revised_item_name               IN  VARCHAR2 := NULL,
7422         p_component_item_name             IN  VARCHAR2 := NULL,
7423         p_minimum_allowed_quantity        IN  NUMBER := NULL,
7424         p_maximum_allowed_quantity        IN  NUMBER := NULL,
7425         p_Delete_Group_Name               IN  VARCHAR2 := NULL,
7426         p_eco_name                        IN  VARCHAR2 := NULL,
7427         p_comments                        IN  VARCHAR2 := NULL,
7428         p_pick_components                 IN  NUMBER := NULL,
7429         p_revised_item_sequence_id        IN  NUMBER := NULL,
7430         p_old_operation_sequence_num      IN  NUMBER := NULL,
7431         p_old_component_sequence_id       IN  NUMBER := NULL,
7432         p_old_effectivity_date            IN  DATE := NULL,
7433         p_old_rec_item_sequence_number    IN  NUMBER := NULL,
7434         p_Old_Rec_shipping_Allowed        IN  NUMBER := NULL,
7435         p_Old_rec_supply_locator_id       IN  NUMBER := NULL,
7436         p_Old_rec_supply_subinventory     IN  VARCHAR2 := NULL,
7437         p_old_rec_check_atp               IN  NUMBER := NULL,
7438         p_old_rec_acd_type                IN  NUMBER := NULL,
7439         p_old_rec_to_end_item_unit_num    IN  VARCHAR2 := NULL,
7440         p_original_system_reference       IN  VARCHAR2 := NULL,
7441         p_rowid                           IN  VARCHAR2 := NULL,
7442         x_return_status                  IN OUT NOCOPY /* file.sql.39 change */  VARCHAR2,
7443         x_error_message                  IN OUT NOCOPY /* file.sql.39 change */  VARCHAR2) IS
7444 
7445 l_rev_component_rec      Bom_Bo_Pub.Rev_Component_Rec_Type;
7446 l_rev_comp_unexp_rec     Bom_Bo_Pub.Rev_Comp_Unexposed_Rec_Type;
7447 l_old_rev_component_rec  Bom_Bo_Pub.Rev_Component_Rec_Type;
7448 l_old_rev_comp_unexp_rec Bom_Bo_Pub.Rev_Comp_Unexposed_Rec_Type;
7449 l_return_status          VARCHAR2(1);
7450 l_mesg_token_tbl         Error_Handler.Mesg_Token_Tbl_Type;
7451 
7452 l_message_list           Error_Handler.Error_Tbl_Type;
7453 l_debug_error_status     VARCHAR2(1);
7454 l_debug_error_mesg       VARCHAR2(2000);
7455 l_debug_filename         VARCHAR2(20) := 'compjbo'||to_char(sysdate,'MISS');
7456 l_Assembly_Item_Name     VARCHAR2(2000);
7457 l_Component_Item_Name    VARCHAR2(2000);
7458 
7459 
7460 EXC_ERR_PVT_API_MAIN          EXCEPTION;
7461 
7462 BEGIN
7463 
7464   /* Construct the exposed and unexposed records for
7465      component and call check_attributes. check_entity */
7466 
7467   Error_Handler.Initialize;
7468   Error_Handler.Set_Debug ('Y');
7469   Bom_Globals.Set_Debug ('Y');
7470 
7471 
7472   Error_Handler.Open_Debug_Session
7473         (  p_debug_filename    => l_debug_filename
7474          , p_output_dir        =>'/appslog/bis_top/utl/plm115dv/out'
7475          , x_return_status     => l_debug_error_status
7476          , x_error_mesg        => l_debug_error_mesg
7477   );
7478 
7479   if x_return_status <> 'S'
7480   then
7481     x_return_status := 'E';
7482     x_error_message := l_debug_error_mesg;
7483     return;
7484   end if;
7485 
7486   --Load environment information into the SYSTEM_INFORMATION record
7487   -- (USER_ID, LOGIN_ID, PROG_APPID, PROG_ID)
7488 
7489   Bom_Globals.Init_System_Info_Rec
7490                         (  x_mesg_token_tbl => l_mesg_token_tbl
7491                         ,  x_return_status  => l_return_status
7492                         );
7493 
7494   -- Initialize System_Information Unit_Effectivity flag
7495 
7496   IF (FND_PROFILE.DEFINED('PJM:PJM_UNITEFF_NO_EFFECT') AND
7497       FND_PROFILE.VALUE('PJM:PJM_UNITEFF_NO_EFFECT') = 'Y')
7498       OR (BOM_EAMUTIL.Enabled = 'Y')
7499   THEN
7500     Bom_Globals.Set_Unit_Effectivity (TRUE);
7501   ELSE
7502     Bom_Globals.Set_Unit_Effectivity (FALSE);
7503   END IF;
7504 
7505   IF l_return_status <> FND_API.G_RET_STS_SUCCESS
7506   THEN
7507     RAISE EXC_ERR_PVT_API_MAIN;
7508   END IF;
7509 
7510   Error_Handler.Write_Debug('After open debug  ');
7511 
7512   Error_Handler.Set_BO_Identifier(p_bo_identifier);
7513   Bom_Globals.Set_BO_Identifier(p_bo_identifier);
7514 
7515   /* Set the system information record values for assembly_item_id
7516      and org_id. These values will be used for validating serial effective
7517      assemblies */
7518 
7519   Bom_Globals.Set_Org_Id (p_organization_id);
7520   Bom_Globals.Set_Assembly_Item_Id (p_revised_item_id);
7521 
7522   Error_Handler.Write_Debug('after set org  ');
7523 
7524   x_return_status := 'S';
7525 
7526    /*Added code to get the parent name
7527    as the parent name is passed null
7528    BOM_VALIDATE_BOM_COMPONENT.Validate_All_Attributes from
7529    java call.*/
7530    IF (p_revised_item_name IS NULL)
7531    THEN
7532    	l_Assembly_Item_Name := Bom_Globals.Get_Item_Name(p_revised_item_id,
7533    	 		     	        	            p_organization_id);
7534    ELSE
7535       l_Assembly_Item_Name := p_revised_item_name;
7536    END IF;
7537 
7538    IF (p_component_item_name IS NULL)
7539    THEN
7540    	l_Component_Item_Name := Bom_Globals.Get_Item_Name(p_component_item_id,
7541    	 		     	        	            p_organization_id);
7542    ELSE
7543 	l_Component_Item_Name := p_component_item_name;
7544    END IF;
7545 
7546 
7547   l_rev_component_rec.eco_name := p_eco_name;  -- ECO Specific
7548 
7549   l_rev_component_rec.organization_code :=
7550                                 p_organization_code;
7551   l_rev_component_rec.revised_item_name :=
7552                                 l_Assembly_Item_Name;
7553   l_rev_component_rec.new_revised_item_revision := NULL;
7554   Error_Handler.Write_Debug('0 ');
7555   Error_Handler.Write_Debug('p_start_Effective_date '||to_char(p_start_Effective_date,'YYYY-MM-DD HH24:MI:SS'));
7556   l_rev_component_rec.start_effective_date := p_start_Effective_date;
7557 --  l_rev_component_rec.start_effective_date :=
7558 --                                to_date(p_start_Effective_date,'YYYY-MM-DD HH24:MI:SS');
7559 
7560   l_rev_component_rec.new_effectivity_date :=
7561                                 p_new_effectivity_date;
7562 
7563   l_rev_component_rec.disable_date :=
7564                                 p_disable_date;
7565 
7566   Error_Handler.Write_Debug('1 ');
7567   l_rev_component_rec.operation_sequence_number :=
7568                                 p_operation_sequence_number;
7569   l_rev_component_rec.component_item_name :=
7570                                 l_Component_Item_Name;
7571   l_rev_component_rec.alternate_bom_code :=
7572                                 p_alternate_bom_code;
7573 
7574   l_rev_component_rec.acd_type := p_acd_type; -- ECO Specific
7575 
7576   l_rev_component_rec.old_effectivity_date :=
7577                                 p_old_effectivity_date; -- ECO Specific
7578 
7579   Error_Handler.Write_Debug('2 ');
7580   l_rev_component_rec.old_operation_sequence_number := p_old_operation_sequence_num; -- ECO Specific
7581 
7582   l_rev_component_rec.new_operation_sequence_number :=
7583                         p_new_operation_sequence_num;
7584   l_rev_component_rec.item_sequence_number :=
7585                                 p_item_sequence_number;
7586   l_rev_component_rec.basis_type:=
7587                                 p_basis_type;
7588   l_rev_component_rec.quantity_per_assembly :=
7589                                 p_quantity_per_assembly;
7590   l_rev_component_rec.Planning_Percent :=
7591                                 p_Planning_Percent;
7592   l_rev_component_rec.projected_yield :=
7593                                 p_projected_yield;
7594 
7595   l_rev_component_rec.include_in_cost_rollup :=
7596                                 p_include_in_cost_rollup;
7597   l_rev_component_rec.wip_supply_type :=
7598                                 p_wip_supply_type;
7599   l_rev_component_rec.so_basis :=
7600                                 p_so_basis;
7601   l_rev_component_rec.optional :=
7602                                 p_optional;
7603   l_rev_component_rec.mutually_exclusive :=
7604                                 p_mutually_exclusive;
7605   l_rev_component_rec.check_atp :=
7606                                 p_check_atp;
7607   l_rev_component_Rec.shipping_allowed :=
7608                                 p_shipping_allowed;
7609   l_rev_component_rec.required_to_ship :=
7610                                 p_required_to_ship;
7611   l_rev_component_rec.required_for_revenue :=
7612                                 p_required_for_revenue;
7613   l_rev_component_rec.include_on_ship_docs :=
7614                                 p_include_on_ship_docs;
7615   l_rev_component_rec.quantity_related :=
7616                                 p_quantity_related;
7617   l_rev_component_rec.supply_subinventory :=
7618                                 p_supply_subinventory;
7619   l_rev_component_rec.location_name :=
7620                                 p_location_name;
7621   l_rev_component_rec.minimum_allowed_quantity :=
7622                                 p_minimum_allowed_quantity;
7623   l_rev_component_rec.maximum_allowed_quantity :=
7624                                 p_maximum_allowed_quantity;
7625   l_rev_component_rec.comments :=
7626                                 p_comments;
7627   /*
7628   l_rev_component_rec.attribute_category :=
7629                                 p_attribute_category;
7630   l_rev_component_rec.attribute1 :=
7631                                 p_attribute1;
7632   l_rev_component_rec.attribute2 :=
7633                                 p_attribute2;
7634   l_rev_component_rec.attribute3 :=
7635                                 p_attribute3;
7636   l_rev_component_rec.attribute4 :=
7637                                 p_attribute4;
7638   l_rev_component_rec.attribute5 :=
7639                                 p_attribute5;
7640   l_rev_component_rec.attribute6 :=
7641                                 p_attribute6;
7642   l_rev_component_rec.attribute7 :=
7643                                 p_attribute7;
7644   l_rev_component_rec.attribute8 :=
7645                                 p_attribute8;
7646   l_rev_component_rec.attribute9 :=
7647                                 p_attribute9;
7648   l_rev_component_rec.attribute10 :=
7649                                 p_attribute10;
7650   l_rev_component_rec.attribute11 :=
7651                                 p_attribute11;
7652   l_rev_component_rec.attribute12 :=
7653                                 p_attribute12;
7654   l_rev_component_rec.attribute13 :=
7655                                 p_attribute13;
7656   l_rev_component_rec.attribute14 :=
7657                                 p_attribute14;
7658   l_rev_component_rec.attribute15 :=
7659                                 p_attribute15;
7660   */
7661   l_rev_component_rec.original_system_reference :=
7662                                 p_original_system_reference;
7663   l_rev_component_rec.transaction_type :=
7664                                 p_transaction_type;
7665   Error_Handler.Write_Debug('3 ');
7666   l_rev_component_rec.From_End_Item_Unit_Number :=
7667                                 p_From_End_Item_Unit_Number;
7668   l_rev_component_rec.To_End_Item_Unit_Number :=
7669                                 p_To_End_Item_Unit_Number;
7670   l_rev_component_rec.New_From_End_Item_Unit_Number :=
7671                                 p_New_From_End_Item_Unit_Num;
7672   l_rev_component_rec.New_Routing_Revision    := NULL ;
7673   l_rev_component_rec.auto_request_material :=
7674           p_auto_request_material;
7675 
7676   l_rev_comp_unexp_rec.organization_id :=
7677                                 p_organization_id;
7678   l_rev_comp_unexp_rec.component_item_id :=
7679                                 p_component_item_id;
7680   l_rev_comp_unexp_rec.component_sequence_id :=
7681                                 p_component_sequence_id;
7682   l_rev_comp_unexp_rec.old_component_sequence_id :=
7683                                 p_old_component_sequence_id;
7684   l_rev_comp_unexp_rec.revised_item_id :=
7685                                 p_revised_item_id;
7686   l_rev_comp_unexp_rec.bill_sequence_id :=
7687                                 p_bill_sequence_id;
7688 
7689   l_rev_comp_unexp_rec.pick_components :=
7690                                 p_pick_components;
7691   l_rev_comp_unexp_rec.supply_locator_id :=
7692                                 p_supply_locator_id;
7693 
7694   Error_Handler.Write_Debug('Rowid is '||p_rowid);
7695   l_rev_comp_unexp_rec.Rowid   :=
7696                                 p_rowid ;
7697   /*
7698   l_rev_comp_unexp_rec.bom_item_type :=
7699                                 p_bom_comp_unexp_rec.bom_item_type;
7700   l_rev_comp_unexp_rec.Delete_Group_Name :=
7701                                 p_Delete_Group_Name ;
7702   l_rev_comp_unexp_rec.DG_Description    :=
7703                                 p_DG_Description ;
7704   l_rev_comp_unexp_rec.DG_Sequence_Id    :=
7705                                 p_bom_comp_unexp_rec.DG_Sequence_Id ;
7706   l_rev_component_rec.Enforce_Int_Requirements :=
7707                                 p_Enforce_Int_Requirements;
7708   l_rev_component_rec.Row_Identifier := p_Row_Identifier;
7709   l_rev_component_rec.return_status :=
7710                                 p_return_status;
7711   */
7712 
7713   l_rev_comp_unexp_rec.revised_item_sequence_id := p_revised_item_sequence_id; -- ECO Specific
7714 
7715   l_rev_comp_unexp_rec.Enforce_Int_Requirements_Code :=
7716                                 p_Enforce_Int_Reqs_Code;
7717   Error_Handler.Write_Debug('4 ');
7718 
7719   l_rev_comp_unexp_rec.bom_implementation_date   :=
7720                                 p_bom_implementation_date;
7721 
7722   /* Assign the values for teh OLD record */
7723 
7724    l_old_rev_component_rec.item_sequence_number :=
7725                 p_old_rec_item_sequence_number;
7726    l_old_rev_component_rec.shipping_allowed :=
7727                 p_Old_Rec_shipping_Allowed;
7728    l_old_rev_comp_unexp_rec.supply_locator_id :=
7729                 p_Old_rec_supply_locator_id;
7730    l_old_rev_component_rec.supply_subinventory :=
7731                 p_Old_rec_supply_subinventory;
7732    l_old_rev_component_rec.check_atp :=
7733                 p_old_rec_check_atp;
7734    l_old_rev_component_rec.acd_type :=
7735                 p_old_rec_acd_type;
7736    l_old_rev_component_rec.to_end_item_unit_number :=
7737                 p_old_rec_to_end_item_unit_num;
7738 
7739   Error_Handler.Write_Debug('after assignement  ');
7740   /* validate parent access */
7741 
7742   Bom_Validate_Bom_Header.Check_Access
7743                 ( p_assembly_item_id   => p_revised_item_id
7744                 , p_organization_id    => p_organization_id
7745                 , p_alternate_bom_code => p_alternate_bom_code
7746                 , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
7747                 , x_Return_Status      => x_return_status
7748                 );
7749 
7750   Error_Handler.Write_Debug('after check access  ');
7751   IF x_return_status <> 'S'
7752   THEN
7753     Error_Handler.Translate_And_Insert_Messages
7754         (  p_mesg_token_tbl     => l_mesg_token_tbl
7755          , p_application_id     => 'BOM'
7756          );
7757 
7758     Error_Handler.Get_Message_List( x_message_list => l_message_list);
7759     x_error_message := l_message_list(1).Message_Text;
7760     Error_Handler.Write_To_DebugFile;
7761     Error_Handler.Close_Debug_Session;
7762 
7763     Return;
7764   END IF;
7765 
7766   /* validate component access */
7767 
7768   Bom_Validate_Bom_Component.Check_Access
7769         (  p_organization_id         => p_organization_id
7770          , p_component_item_id       => p_component_item_id
7771          , p_component_name          => p_component_item_name
7772          , p_Mesg_Token_Tbl          => l_mesg_token_tbl
7773          , x_Mesg_Token_Tbl          => l_mesg_token_tbl
7774          , x_Return_Status           => x_return_status
7775         );
7776 
7777   Error_Handler.Write_Debug('after component access  ');
7778   IF x_return_status <> 'S'
7779   THEN
7780     Error_Handler.Translate_And_Insert_Messages
7781         (  p_mesg_token_tbl     => l_mesg_token_tbl
7782          , p_application_id     => 'BOM'
7783          );
7784 
7785     Error_Handler.Get_Message_List( x_message_list => l_message_list);
7786     x_error_message := l_message_list(1).Message_Text;
7787     Error_Handler.Write_To_DebugFile;
7788     Error_Handler.Close_Debug_Session;
7789 
7790     Return;
7791   END IF;
7792 
7793   /* Set the value for unit controlled item in system information record*/
7794 
7795   Bom_Globals.Set_Unit_Controlled_Item (
7796               p_inventory_item_id => p_revised_item_id,
7797               p_organization_id   => p_organization_id);
7798 
7799   /* Perform the attribute validation */
7800 
7801   Bom_Validate_Bom_Component.Check_Attributes
7802      ( x_return_status              => x_return_status
7803         , x_Mesg_Token_Tbl             => l_Mesg_Token_Tbl
7804         , p_rev_component_rec          => l_rev_component_rec
7805         , p_rev_comp_unexp_rec         => l_rev_comp_unexp_rec
7806      );
7807 
7808   IF x_return_status <> 'S'
7809   THEN
7810     Error_Handler.Translate_And_Insert_Messages
7811         (  p_mesg_token_tbl     => l_mesg_token_tbl
7812          , p_application_id     => 'BOM'
7813          );
7814 
7815     Error_Handler.Get_Message_List( x_message_list => l_message_list);
7816     x_error_message := l_message_list(1).Message_Text;
7817     Error_Handler.Write_To_DebugFile;
7818     Error_Handler.Close_Debug_Session;
7819 
7820     Return;
7821   END IF;
7822 
7823   /* Mark the Validate plm flag in BOM Globals to 'Y' to avoid the
7824      following validations
7825      1. Overlap
7826      2. Check Operation sequence number uniqueness
7827      3. Checking ACD TYPE when there is no primary bill
7828   */
7829   Bom_Globals.Set_Validate_For_Plm('Y');
7830 
7831   /* Perform the entity validation */
7832 
7833   Bom_Validate_Bom_Component.Check_Entity
7834                 (  p_rev_component_rec          => l_rev_component_rec
7835                 ,  p_rev_comp_unexp_rec         => l_rev_comp_unexp_rec
7836                 ,  p_old_rev_component_rec      => l_old_rev_component_rec
7837                 ,  p_old_rev_comp_unexp_rec     => l_old_rev_comp_unexp_rec
7838                 ,  x_Mesg_Token_Tbl             => l_Mesg_Token_Tbl
7839                 ,  x_return_status              => x_Return_Status
7840                 );
7841 
7842   Error_Handler.Write_Debug('after check entity  ');
7843   IF x_return_status <> 'S'
7844   THEN
7845     Error_Handler.Translate_And_Insert_Messages
7846         (  p_mesg_token_tbl     => l_mesg_token_tbl
7847          , p_application_id     => 'BOM'
7848          );
7849 
7850     Error_Handler.Get_Message_List( x_message_list => l_message_list);
7851     x_error_message := l_message_list(1).Message_Text;
7852 
7853     Error_Handler.Write_To_DebugFile;
7854     Error_Handler.Close_Debug_Session;
7855 
7856   END IF;
7857   EXCEPTION WHEN OTHERS THEN
7858     x_error_message := SQLCODE||'/'||SQLERRM;
7859     Error_Handler.Write_To_DebugFile;
7860     Error_Handler.Close_Debug_Session;
7861 
7862 END;
7863 
7864 -- add for bug 8639519
7865 /********************************************************************
7866 * Function      : Check_PTO_ATO_For_Optional (Local Function)
7867 * Returns       : 0 if Success
7868 *                 1 if Optional value is incorrect for ATO/PTO Model/OC
7869 *                 2 if Optional value is incorrect for Plan/Stdd Bill
7870 * Purpose       : Function will verify the following things:
7871 *                 1. Optional must be NO (2) if Bill if Pln or Standard
7872 *                 2. If Bill is PTO Model or OC and component is
7873 *                    ATO Std with no base mdl then Optional must be Yes
7874 *                     (1)
7875 *                       -1. Error
7876 ***********************************************************************/
7877 -- Check if the PTO and ATO flags of Assembly and Component for the
7878 -- Optional flag to be correct.
7879 --
7880 FUNCTION Check_PTOATO_For_Optional( p_assembly_org_id IN NUMBER,
7881 				     p_assembly_item_id IN NUMBER,
7882 				     p_comp_org_id IN NUMBER,
7883 				     p_comp_item_id IN NUMBER)
7884         RETURN NUMBER
7885 IS
7886         l_Comp_Item_Type        NUMBER; -- Bom_Item_Type of Component
7887         l_Assy_Item_Type        NUMBER; -- Bom_Item_Type of Assembly
7888         l_Comp_ATO_flag         CHAR;   -- ATO flag for Component
7889         l_Assy_PTO_flag         CHAR;   -- PTO flag for Assembly
7890         l_Comp_Config           CHAR;   -- Is component a config item
7891 BEGIN
7892          SELECT assy.bom_item_type,
7893           assy.pick_components_flag,
7894           comp.bom_item_type,
7895           comp.replenish_to_order_flag,
7896           DECODE(NVL(comp.base_item_id, 0), 0 , 'N', 'Y')
7897           INTO  l_Assy_Item_Type,
7898                 l_Assy_PTO_flag,
7899                 l_Comp_Item_Type,
7900                 l_Comp_ATO_flag,
7901                 l_Comp_Config
7902           FROM  mtl_system_items assy,
7903                 mtl_system_items comp
7904          WHERE  assy.organization_id   = p_assembly_org_id
7905            AND  assy.inventory_item_id = p_assembly_item_id
7906            AND  comp.organization_id   = p_comp_org_id
7907            AND  comp.inventory_item_id = p_comp_item_id;
7908 
7909      IF ( l_Assy_PTO_flag = 'Y'
7910              AND l_Assy_Item_Type IN ( Bom_Globals.G_MODEL, Bom_Globals.G_OPTION_CLASS)
7911              AND l_Comp_ATO_flag = 'Y'
7912              AND l_Comp_Item_Type = Bom_Globals.G_STANDARD
7913              AND l_Comp_Config = 'N'
7914             )
7915                 THEN
7916                         RETURN 1;
7917                 ELSIF ( l_Assy_Item_Type IN (Bom_Globals.G_STANDARD, Bom_Globals.G_PLANNING) )
7918                 THEN
7919                         RETURN 2;
7920                 ELSE
7921                         RETURN 0;
7922                 END IF;
7923         EXCEPTION WHEN OTHERS THEN
7924                 RETURN -1;
7925 END;
7926 
7927 
7928 
7929 
7930 
7931 END BOM_VALIDATE_BOM_COMPONENT;