DBA Data[Home] [Help]

PACKAGE BODY: APPS.BOM_VALIDATE_BOM_HEADER

Source


1 PACKAGE BODY BOM_Validate_Bom_Header AS
2 /* $Header: BOMLBOMB.pls 120.20 2011/02/05 00:02:06 vbrobbey ship $ */
3 /****************************************************************************
4 --
5 --  Copyright (c) 1996 Oracle Corporation, Redwood Shores, CA, USA
6 --  All rights reserved.
7 --
8 --  FILENAME
9 --
10 --      BOMLBOMB.pls
11 --
12 --  DESCRIPTION
13 --
14 --      Body of package BOM_Validate_Bom_Header
15 --
16 --  NOTES
17 --
18 --  HISTORY
19 --
20 --  01-JUL-99   Rahul Chitko    Initial Creation
21 --
22 --  08-MAY-2001 Refai Farook    EAM related changes
23 --
24 --  06-May-05   Abhishek Rudresh     Common BOM Attr Updates
25 
26 --  20-Jun-05	Vani Hymavathi	     Validations for to OPM convergence project
27 --  13-JUL-06   Bhavnesh Patel     Added support for Structure Type
28 ****************************************************************************/
29         G_Pkg_Name      VARCHAR2(30) := 'BOM_Validate_Bom_Header';
30         g_token_tbl     Error_Handler.Token_Tbl_Type;
31 
32 
33 	/*******************************************************************
34 	* Procedure	: Check_Existence
35 	* Returns	: None
36 	* Parameters IN	: Bom Header Exposed Record
37 	*		  Bom Header Unexposed Record
38 	* Parameters OUT: Old BOM Header exposed Record
39 	*		  Old BOM Header Unexposed Record
40 	*		  Mesg Token Table
41 	*		  Return Status
42 	* Purpose	: Procedure will query the old bill of materials header
43 	*		  record and return it in old record variables. If the
44 	* 		  Transaction Type is Create and the record already
45 	*		  exists the return status would be error or if the
46 	*		  transaction type is Update or Delete and the record
47 	*		  does not exist then the return status would be an
48 	*		  error as well. Mesg_Token_Table will carry the
49 	*		  error messsage and the tokens associated with the
50 	*		  message.
51 	*********************************************************************/
52         PROCEDURE Check_Existence
53         (  p_bom_header_rec         IN  Bom_Bo_Pub.Bom_Head_Rec_Type
54          , p_bom_head_unexp_rec   IN  Bom_Bo_Pub.Bom_Head_Unexposed_Rec_Type
55          , x_old_bom_header_rec     IN OUT NOCOPY Bom_Bo_Pub.Bom_Head_Rec_Type
56          , x_old_bom_head_unexp_rec IN OUT NOCOPY Bom_Bo_Pub.Bom_Head_Unexposed_Rec_Type
57          , x_Mesg_Token_Tbl         IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
58          , x_return_status          IN OUT NOCOPY VARCHAR2
59         )
60 	IS
61         	l_token_tbl      Error_Handler.Token_Tbl_Type;
62         	l_Mesg_Token_Tbl Error_Handler.Mesg_Token_Tbl_Type;
63         	l_return_status  VARCHAR2(1);
64 	BEGIN
65 
66 If Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Quering Assembly item ' || to_char(p_bom_head_unexp_rec.assembly_item_id)); END IF;
67 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug(' Org: ' || to_char(p_bom_head_unexp_rec.organization_id) || ' Alt: ' || p_bom_header_rec.alternate_bom_code ); END IF;
68 
69  /* bug 4133037, For creates we need to check for existance in bom_structures_b */
70 
71         If(p_bom_header_rec.transaction_type = BOM_Globals.G_OPR_CREATE) then
72              Bom_Bom_Header_Util.Query_Table_Row
73                 (  p_assembly_item_id   =>
74                         p_bom_head_unexp_rec.assembly_item_id
75                  , p_alternate_bom_code =>
76                         p_bom_header_rec.alternate_bom_code
77                  , p_organization_id    =>
78                         p_bom_head_unexp_rec.organization_id
79                  , x_bom_header_rec     => x_old_bom_header_rec
80                  , x_bom_head_unexp_rec => x_old_bom_head_unexp_rec
81                  , x_return_status      => l_return_status
82                  );
83         else
84 		Bom_Bom_Header_Util.Query_Row
85 		(  p_assembly_item_id	=>
86 			p_bom_head_unexp_rec.assembly_item_id
87 		 , p_alternate_bom_code	=>
88 			p_bom_header_rec.alternate_bom_code
89 		 , p_organization_id	=>
90 			p_bom_head_unexp_rec.organization_id
91 		 , x_bom_header_rec	=> x_old_bom_header_rec
92 		 , x_bom_head_unexp_rec => x_old_bom_head_unexp_rec
93 		 , x_return_status	=> l_return_status
94 		 );
95         end if;
96 
97 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Query Row Returned with : ' || l_return_status); END IF;
98 
99 		IF l_return_status = BOM_Globals.G_RECORD_FOUND AND
100 		   p_bom_header_rec.transaction_type = BOM_Globals.G_OPR_CREATE
101 		THEN
102 			l_token_tbl(1).token_name  := 'ASSEMBLY_ITEM_NAME';
103 			l_token_tbl(1).token_value :=
104 					p_bom_header_rec.assembly_item_name;
105 			Error_Handler.Add_Error_Token
106                 	(  x_Mesg_token_tbl => l_Mesg_Token_Tbl
107                  	 , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
108                  	 , p_message_name  => 'BOM_ASSY_ITEM_ALREADY_EXISTS'
109                  	 , p_token_tbl     => l_token_tbl
110                  	 );
111 			l_return_status := FND_API.G_RET_STS_ERROR;
112 		ELSIF l_return_status = BOM_Globals.G_RECORD_NOT_FOUND AND
113 		      p_bom_header_rec.transaction_type IN
114 			 (BOM_Globals.G_OPR_UPDATE, BOM_Globals.G_OPR_DELETE)
115 		THEN
116 			l_token_tbl(1).token_name  := 'ASSEMBLY_ITEM_NAME';
117                         l_token_tbl(1).token_value :=
118                                         p_bom_header_rec.assembly_item_name;
119 			Error_Handler.Add_Error_Token
120                         (  x_Mesg_token_tbl => l_Mesg_Token_Tbl
121                          , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
122                          , p_message_name  => 'BOM_ASSY_ITEM_DOESNOT_EXISTS'
123                          , p_token_tbl     => l_token_tbl
124                          );
125 			l_return_status := FND_API.G_RET_STS_ERROR;
126 		ELSIF l_Return_status = FND_API.G_RET_STS_UNEXP_ERROR
127         	THEN
128                 	Error_Handler.Add_Error_Token
129                 	(  x_Mesg_token_tbl     => l_Mesg_Token_Tbl
130                 	 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
131                 	 , p_message_name       => NULL
132                 	 , p_message_text       =>
133                   	 'Unexpected error while existence verification of ' ||
134                   	 'Assembly item '||
135                   	 p_bom_header_rec.assembly_item_name
136                 	 , p_token_tbl          => l_token_tbl
137                 	 );
138 			l_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
139         	ELSE
140 
141                  /* Assign the relevant transaction type for SYNC operations */
142 
143                   IF p_bom_header_rec.transaction_type = 'SYNC' THEN
144                     IF l_return_status = Bom_Globals.G_RECORD_FOUND THEN
145                       x_old_bom_header_rec.transaction_type :=
146                                                    Bom_Globals.G_OPR_UPDATE;
147                     ELSE
148                       x_old_bom_header_rec.transaction_type :=
149                                                    Bom_Globals.G_OPR_CREATE;
150                     END IF;
151                   END IF;
152                   l_return_status := FND_API.G_RET_STS_SUCCESS;
153 
154         	END IF;
155 
156 		x_return_status := l_return_status;
157 		x_mesg_token_tbl := l_mesg_token_tbl;
158 	END Check_Existence;
159 
160 
161 	/*******************************************************************
162 	* Procedure	: Check_Access
163 	* Returns	: None
164 	* Parameters IN	: Assembly_Item_Id
165 	*		  Organization_Id
166 	*		  Alternate_Bom_Designator
167 	* Parameters OUT: Return Status
168 	*		  Message Token Table
169 	* Purpose	: This procedure will check if the user has access
170 	*		  to the Assembly Item's BOM Item Type.
171 	* 		  If not then an appropriate message and a error status
172 	*		  will be returned back.
173 	*********************************************************************/
174 	PROCEDURE Check_Access
175 		  (  p_assembly_item_id	  IN  NUMBER
176 		   , p_alternate_bom_code IN  VARCHAR2
177 		   , p_organization_id	  IN  NUMBER
178 		   , p_mesg_token_tbl	  IN  Error_Handler.Mesg_Token_Tbl_Type
179 					 := Error_Handler.G_MISS_MESG_TOKEN_TBL
180 		   , x_mesg_token_tbl	  IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
181 		   , x_return_status      IN OUT NOCOPY VARCHAR2
182 		   )
183 	IS
184 		l_return_status	   VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
185 		l_Mesg_Token_Tbl   Error_Handler.Mesg_Token_Tbl_Type :=
186 					p_mesg_token_tbl;
187 		l_bom_item_type	   NUMBER;
188 		l_assembly_type	   NUMBER;
189                 l_tracking_qty_ind VARCHAR2(30);
190                 l_OPM_org	   VARCHAR2(1);
191 		l_token_tbl	   Error_Handler.Token_Tbl_Type;
192 
193 	BEGIN
194 
195 		SELECT bom_item_type, decode(eng_item_flag, 'N', 1, 2)
196                         ,tracking_quantity_ind
197                   INTO l_bom_item_type, l_assembly_type,l_tracking_qty_ind
198                   FROM mtl_system_items
199                  WHERE inventory_item_id = p_assembly_item_id
200                    AND organization_id   = p_organization_id;
201 
202                 SELECT process_enabled_flag
203                   INTO  l_OPM_org
204                   FROM mtl_parameters
205                  WHERE  organization_id   = p_organization_id;
206 
207 		--
208 		-- If user is trying to update an Engineering Item from BOM
209 		-- Business Object, the user should not be allowed.
210 		--
211 
212 		/*IF l_assembly_type = 2 -- Engineering Item
213 		THEN
214 			Error_Handler.Add_Error_Token
215 			(  p_Message_name	=> 'BOM_ASSEMBLY_TYPE_ENG'
216 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
217 			 , x_mesg_token_tbl	=> l_mesg_token_tbl
218 			 );
219 			l_return_status := FND_API.G_RET_STS_ERROR;
220 		END IF;*/
221 
222                 /* Validations for OPM Convergence Project
223                    Model/Option class bills are not allowed in OPM organizations*/
224 
225                  IF (l_OPM_org='Y' and l_bom_item_type in (1,2))THEN
226                         Error_Handler.Add_Error_Token
227                         (  p_Message_name       => 'BOM_OPM_ORG_MODEL_OC'
228                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
229                          , x_mesg_token_tbl     => l_mesg_token_tbl
230                          );
231                         l_return_status := FND_API.G_RET_STS_ERROR;
232                  END IF;
233 
234                 /* Validations for OPM Convergence Project
235                    Dual UOM controlled items should not be allowed*/
236 
237                  IF (l_tracking_qty_ind<>'P' )THEN
238                         Error_Handler.Add_Error_Token
239                         (  p_Message_name       => 'BOM_DUAL_UOM_ITEMS'
240                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
241                          , x_mesg_token_tbl     => l_mesg_token_tbl
242                          );
243                         l_return_status := FND_API.G_RET_STS_ERROR;
244                  END IF;
245 
246 
247 		IF BOM_Globals.Get_STD_Item_Access IS NULL AND
248            	   BOM_Globals.Get_PLN_Item_Access IS NULL AND
249            	   BOM_Globals.Get_MDL_Item_Access IS NULL AND
250 		   BOM_Globals.Get_OC_Item_Access  IS NULL
251         	THEN
252                 	--
253                 	-- Get respective profile values
254                 	--
255 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Checking item type access . . . '); END IF;
256 
257 			IF fnd_profile.value('BOM:STANDARD_ITEM_ACCESS') = '1'
258                 	THEN
259                         	BOM_Globals.Set_STD_Item_Access
260                         	( p_std_item_access     => 4);
261                 	ELSE
262 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('no access to standard items'); END IF;
263 			BOM_Globals.Set_STD_Item_Access
264 			(p_std_item_access      => NULL);
265                 	END IF;
266 
267                 	IF fnd_profile.value('BOM:MODEL_ITEM_ACCESS') = '1'
268                 	THEN
269                         	BOM_Globals.Set_MDL_Item_Access
270                         	( p_mdl_item_access     => 1);
271                         	BOM_Globals.Set_OC_Item_Access
272                         	( p_oc_item_access      => 2);
273 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Model/OC items are accessible. . . '); END IF;
274                 	ELSE
275                         	BOM_Globals.Set_MDL_Item_Access
276                         	( p_mdl_item_access     => NULL);
277                         	BOM_Globals.Set_OC_Item_Access
278                         	( p_oc_item_access      => NULL);
279 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug(' Model/OC item access denied . . . '); END IF;
280                 	END IF;
281 
282                 	IF fnd_profile.value('BOM:PLANNING_ITEM_ACCESS') = '1'
283                 	THEN
284                         	BOM_Globals.Set_PLN_Item_Access
285                         	( p_pln_item_access     => 3);
286 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Planning item accessible. . . '); END IF;
287                 	ELSE
288                         	BOM_Globals.Set_PLN_Item_Access
289                         	( p_pln_item_access     => NULL);
290 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Planning item access denied. . . '); END IF;
291                 	END IF;
292 		END IF;
293 
294 		--
295 		-- Use BOM Item Type of the Assembly Item that is queried above
296 		-- to check if user has access to it.
297 		--
298 		IF l_Bom_Item_Type NOT IN
299                       ( NVL(BOM_Globals.Get_STD_Item_Access, 0),
300                         NVL(BOM_Globals.Get_PLN_Item_Access, 0),
301                         NVL(BOM_Globals.Get_OC_Item_Access, 0) ,
302                         NVL(BOM_Globals.Get_MDL_Item_Access, 0),
303 			BOM_Globals.G_PRODUCT_FAMILY
304                        )
305                 THEN
306                         l_Token_Tbl(1).Token_Name := 'BOM_ITEM_TYPE';
307                         l_Token_Tbl(1).Translate  := TRUE;
308                         IF l_Bom_Item_Type = 1
309                         THEN
310                                 l_Token_Tbl(1).Token_Value := 'BOM_MODEL';
311                         ELSIF l_Bom_Item_Type = 2
312                         THEN
313                                 l_Token_Tbl(1).Token_Value:='BOM_OPTION_CLASS';
314                         ELSIF l_Bom_Item_Type = 3
315                         THEN
316                                 l_Token_Tbl(1).Token_Value := 'BOM_PLANNING';
317                         ELSIF l_Bom_Item_Type = 4
318                         THEN
319                                 l_Token_Tbl(1).Token_Value := 'BOM_STANDARD';
320                         END IF;
321 
322                         Error_Handler.Add_Error_Token
323                         (  p_Message_Name       => 'BOM_ASSY_ITEM_ACCESS_DENIED'
324                          , p_Mesg_Token_Tbl     => l_mesg_token_tbl
325                          , x_Mesg_Token_Tbl     => l_mesg_token_tbl
326                          , p_Token_Tbl          => l_token_tbl
327                         );
328                         l_return_status := FND_API.G_RET_STS_ERROR;
329                 END IF;
330 
331 		x_return_status	  := l_return_status;
332 		x_mesg_token_tbl  := l_mesg_token_tbl;
333 
334 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Check Access returning with ' || l_return_status ); END IF;
335 
336 	END Check_Access;
337 
338 
339 	/********************************************************************
340 	* Procedure     : Check_Attributes
341 	* Parameters IN : Revised Item Exposed Column record
342 	*                 Revised Item Unexposed Column record
343 	*                 Old Revised Item Exposed Column record
344 	*                 Old Revised Item unexposed column record
345 	* Parameters OUT: Return Status
346 	*                 Mesg Token Table
347 	* Purpose       : Check_Attrbibutes procedure will validate every
348 	*		  revised item attrbiute in its entirety.
349 	**********************************************************************/
350 	PROCEDURE Check_Attributes
351 	(  x_return_status           IN OUT NOCOPY VARCHAR2
352 	 , x_Mesg_Token_Tbl          IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
353 	 , p_bom_header_Rec	     IN  Bom_Bo_Pub.Bom_Head_Rec_Type
354 	 , p_bom_head_unexp_rec	     IN  Bom_Bo_Pub.Bom_Head_Unexposed_Rec_Type
355 	 , p_old_bom_header_rec      IN  Bom_Bo_Pub.Bom_Head_Rec_Type
356 	 , p_old_bom_head_unexp_rec  IN  Bom_Bo_Pub.Bom_Head_Unexposed_Rec_Type
357 	)
358 	IS
359 	l_err_text              VARCHAR2(2000) := NULL;
360 	l_Mesg_Token_Tbl        Error_Handler.Mesg_Token_Tbl_Type;
361 	l_Token_Tbl             Error_Handler.Token_Tbl_Type;
362 
363 	BEGIN
364 
365     		x_return_status := FND_API.G_RET_STS_SUCCESS;
366 
367 		IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Within Bom Header Check Attributes . . . '); END IF;
368 
369 		IF p_bom_header_rec.alternate_bom_code IS NOT NULL AND
370 		   p_bom_header_rec.alternate_bom_code <> FND_API.G_MISS_CHAR
371 		   AND
372 		   (  p_bom_header_rec.alternate_bom_code <>
373 		      p_old_bom_header_rec.alternate_bom_code OR
374 		      p_old_bom_header_rec.alternate_bom_code IS NULL
375 		    )
376 		THEN
377 			IF NOT BOM_Validate.Alternate_Designator
378 				(  p_alternate_bom_code	=>
379 					p_bom_header_rec.alternate_bom_code
380 				 , p_organization_id	=>
381 					p_bom_head_unexp_rec.organization_id
382 				)
383 			THEN
384 				l_token_tbl(1).token_name :=
385 						'ALTERNATE_BOM_CODE';
386 				l_token_tbl(1).token_value :=
387 					p_bom_header_rec.alternate_bom_code;
388 				Error_Handler.Add_Error_Token
389 				(  p_token_tbl		=> l_token_tbl
390 				 , p_message_name	=>
391 						'BOM_ALTERNATE_DESG_INVALID'
392 				 , p_mesg_token_tbl	=> l_mesg_token_tbl
393 				 , x_mesg_token_tbl	=> l_mesg_token_tbl
394 				 );
395 				x_return_status := FND_API.G_RET_STS_ERROR;
396 			END IF;
397 		END IF;
398 
399                 IF p_bom_header_rec.assembly_type IS NOT NULL AND
400                    p_bom_header_rec.assembly_type <> FND_API.G_MISS_NUM AND
401                    p_bom_header_rec.assembly_type NOT IN (1,2)
402                 THEN
403                         l_token_tbl(1).token_name  := 'ASSEMBLY_ITEM_NAME';
404                         l_token_tbl(1).token_value :=
405                                         p_bom_header_rec.assembly_item_name;
406                         l_token_tbl(2).token_name  := 'ASSEMBLY_TYPE';
407                         l_token_tbl(2).token_value :=
408                                         p_bom_header_rec.assembly_type;
409                         Error_Handler.Add_Error_Token
410                         (  p_message_name       => 'BOM_ASSEMBLY_TYPE_INVALID'
411                          , p_token_tbl          => l_token_tbl
412                          , p_mesg_token_tbl     => l_mesg_token_tbl
413                          , x_mesg_token_tbl     => l_mesg_token_tbl
414                          );
415                         x_return_status := FND_API.G_RET_STS_ERROR;
416                 END IF;
417 
418 		x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
419 
420 	END Check_Attributes;
421 
422 	/*********************************************************************
423 	* Procedure     : Check_Required
424 	* Parameters IN : BOM Header Exposed column record
425 	* Parameters OUT: Mesg Token Table
426 	*                 Return_Status
427 	* Purpose	:
428 	**********************************************************************/
429 	PROCEDURE Check_Required
430 	(  x_return_status      IN OUT NOCOPY VARCHAR2
431 	 , x_Mesg_Token_Tbl     IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
432 	 , p_bom_header_Rec	IN  Bom_Bo_Pub.Bom_Head_Rec_Type
433 	 )
434 	IS
435         	l_Mesg_Token_Tbl        Error_Handler.Mesg_Token_Tbl_Type;
436         	l_Token_Tbl             Error_Handler.Token_Tbl_Type;
437 	BEGIN
438         	x_return_status := FND_API.G_RET_STS_SUCCESS;
439 
440 		IF (  p_bom_header_rec.common_organization_code IS NOT NULL AND
441 		      p_bom_header_rec.common_organization_code <>
442 							FND_API.G_MISS_CHAR
443 		    ) AND
444 		    (  p_bom_header_rec.common_assembly_item_name IS NULL OR
445 		       p_bom_header_rec.common_assembly_item_name =
446 							FND_API.G_MISS_CHAR
447 		     )
448 		THEN
449 			--
450 			-- If the common org code is given the common assembly
451 			-- name is required.
452 			--
453 			l_token_tbl(1).token_name := 'ASSEMBLY_ITEM_NAME';
454 			l_token_tbl(1).token_value :=
455 				p_bom_header_rec.assembly_item_name;
456 
457 			Error_Handler.Add_Error_Token
458 			(  p_message_name	=> 'BOM_COMMON_ASSY_REQUIRED'
459 			 , p_token_tbl		=> l_Token_tbl
460 			 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
461 			 , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
462 			 );
463 
464 			x_return_status := FND_API.G_RET_STS_ERROR;
465 		END IF;
466 
467 		x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
468 
469 	END Check_Required;
470 
471 
472 	/********************************************************************
473 	* Procedure	: Check_Entity
474 	* Parameters IN	: Bom Header Exposed column record
475 	*		  Bom Header Unexposed column record
476 	*		  Old Bom Header exposed column record
477 	*		  Old Bom Header unexposed column record
478 	* Parameters OUT: Message Token Table
479 	*		  Return Status
480 	* Purpose	: This procedure will perform the business logic
481 	*		  validation for the BOM Header Entity. It will perform
482 	*		  any cross entity validations and make sure that the
483 	*		  user is not entering values which may disturb the
484 	*		  integrity of the data.
485 	*********************************************************************/
486 	PROCEDURE Check_Entity
487 	(  p_bom_header_rec	IN  Bom_Bo_Pub.Bom_Head_Rec_Type
488 	 , p_bom_head_unexp_rec	IN  Bom_Bo_Pub.Bom_Head_Unexposed_Rec_Type
489 	 , p_old_bom_head_rec	IN  Bom_Bo_Pub.Bom_Head_Rec_Type
490 	 , p_old_bom_head_unexp_rec  IN Bom_Bo_Pub.Bom_Head_Unexposed_Rec_Type
491 	 , x_mesg_token_tbl	IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
492 	 , x_return_status	IN OUT NOCOPY VARCHAR2
493 	 )
494 	IS
495 		l_return_status  VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
496 		l_mesg_token_tbl Error_Handler.Mesg_Token_Tbl_Type;
497 		l_Token_Tbl	 Error_Handler.Token_Tbl_Type;
498 		l_dummy		 VARCHAR2(1);
499     		l_valid_op_seq   VARCHAR2(1);
500 		bit		 NUMBER;
501 		base_id		 NUMBER;
502 		struct_type_id   NUMBER;
503 		ato              VARCHAR2(1);
504     		pto              VARCHAR2(1);
505 		assmtype	 NUMBER;
506 		l_count		 NUMBER;
507                 bom_enabled      VARCHAR2(1);
508     l_mater_org_id NUMBER;
509 		l_comp_rev_status VARCHAR2(1); --Bug 7526867
510 
511                  /* Commented out for bug: 8208327
512          Changes to the header of a bom with a common bom reference should be
513          allowed. However, modifications to components should not. This check
514          was moved to procedure bom_components */
515 
516              /*   CURSOR c_CheckCommon IS
517                 SELECT NVL(common_bill_sequence_id,bill_sequence_id) common_bill_seq,
518 		       bill_sequence_id
519                   FROM bom_bill_of_materials
520                  WHERE assembly_item_id = p_bom_head_unexp_rec.assembly_item_id
521                    AND organization_id  = p_bom_head_unexp_rec.organization_id
522                    AND NVL(alternate_bom_designator, 'XXXX') =
523                        NVL(p_bom_header_rec.alternate_bom_code, 'XXXX'); */
524 
525   l_existing_str_type BOM_STRUCTURE_TYPES_B.STRUCTURE_TYPE_NAME%TYPE;
526 
527 	BEGIN
528 
529                   --
530                   -- Verify that the Parent has BOM Enabled
531 		  -- Bug:8359043 Matching eng_item_flag with assembly_type
532                   --
533                   select bom_enabled_flag,
534 			decode(eng_item_flag,
535 			       'Y',decode(p_bom_header_rec.assembly_type,1,'E',null) --Eng item with manufacturing bill
536 			       --commented line below because MFG item is allowed on an ENG bill, bug 10429605
537              --'N',decode(p_bom_header_rec.assembly_type,2,'M',null)  --Manufacturing item with Eng bill
538 		 	) into bom_enabled,l_dummy from mtl_system_items
539                   where inventory_item_id = p_bom_head_unexp_rec.assembly_item_id
540                    AND organization_id  = p_bom_head_unexp_rec.organization_id;
541 
542                   IF bom_enabled <> 'Y'
543                   THEN
544                   g_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
545                   g_token_tbl(1).token_value :=
546                          p_bom_header_rec.assembly_item_name;
547 
548                   Error_Handler.Add_Error_Token
549                   (  p_message_name       => 'BOM_REV_ITEM_BOM_NOT_ENABLED'
550                   , p_mesg_token_tbl     => l_Mesg_Token_Tbl
551                   , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
552                   , p_token_tbl          => g_token_tbl
553                   );
554 
555                   l_return_status := FND_API.G_RET_STS_ERROR;
556 
557                 END IF;
558 
559 		--
560 		-- Bug:8359043
561 		-- Verify that engineering bill is created for engineering assy
562 		-- and manufacturing bill is created for manufacturing assy
563 		--
564 		IF l_dummy IS NOT NULL THEN
565 	           l_return_status := FND_API.G_RET_STS_ERROR;
566         	   l_token_tbl(1).token_name := 'ASSEMBLY_ITEM_NAME';
567 	           l_token_tbl(1).token_value := p_bom_header_rec.assembly_item_name;
568 	           IF l_dummy = 'E' THEN
569         		Error_Handler.Add_Error_Token
570 	                   (  p_message_name        => 'BOM_ENG_ITEM_MANF_BILL'
571 	                     , p_token_tbl                => l_token_tbl
572 	                     , p_mesg_token_tbl        => l_mesg_token_tbl
573 	                     , x_mesg_token_tbl        => l_mesg_token_tbl
574 	                   );
575         	  /* ELSE
576                 	Error_Handler.Add_Error_Token
577 	                   (  p_message_name        => 'BOM_MANF_ITEM_ENG_BILL'
578         	             , p_token_tbl                => l_token_tbl
579 	                     , p_mesg_token_tbl        => l_mesg_token_tbl
580         	             , x_mesg_token_tbl        => l_mesg_token_tbl
581                 	   );  */ --MFG item is allowed on an ENG bill, commented, bug 10429605
582 	           END IF;
583 		END IF;
584 
585                 --  PackBom Related validations ..
586 
587     SELECT structure_type_id INTO struct_type_id FROM bom_structure_types_b
588 		  WHERE structure_type_name = 'Packaging Hierarchy';
589 
590      IF p_bom_head_unexp_rec.structure_type_id = struct_type_id
591      THEN
592 
593                 --
594                 -- Verify If PIM_PDS profiles are enabled to create a Packaging Hierarchy
595 	 IF Bom_Globals.IS_PIM_PDS_ENABLED = 'N'
596 	 THEN
597         Error_Handler.Add_Error_Token
598         (  p_message_name	=> 'BOM_CREATE_PACK_HIER_NOT_ALLOW'
599          , p_mesg_token_tbl	=> l_Mesg_Token_Tbl
600          , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
601          );
602         l_return_status := FND_API.G_RET_STS_ERROR;
603 	    END IF;
604 
605       ---
606       -- Packaging BOM creation is allowed only with the prefered structure name for the
607       -- structure type 'Packaging Hierarchy'
608       ---
609       SELECT Count(1) INTO l_count FROM bom_alternate_designators
610         WHERE structure_type_id = struct_type_id and alternate_designator_code = p_bom_header_rec.alternate_bom_code
611           AND organization_id = p_bom_head_unexp_rec.organization_id AND is_preferred = 'Y';
612 
613       IF l_count < 1 THEN
614         l_token_tbl(1).token_name  := 'STRUCTURE_NAME';
615         l_token_tbl(1).token_value := p_bom_header_rec.alternate_bom_code;
616         l_token_tbl(2).token_name  := 'STRUCTURE_TYPE';
617         l_token_tbl(2).token_value := p_bom_header_rec.Structure_Type_Name;
618 
619         Error_Handler.Add_Error_Token
620           (  p_Message_Name       => 'BOM_STRUCTNAMEANDTYPE_INVALID'
621           , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
622           , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
623           , p_Token_Tbl          => l_token_tbl
624           );
625         l_return_status := FND_API.G_RET_STS_ERROR;
626       END IF;
627 
628       ---
629       -- Do not allow packaging hierarchies to be created in child orgs.
630       -- Pkg Hiers cannonly be commoned from the master org.
631       ---
632       IF p_bom_header_rec.transaction_type = Bom_Globals.G_OPR_CREATE AND
633 		     p_bom_head_unexp_rec.source_bill_sequence_id IS NULL
634       THEN
635         SELECT master_organization_id INTO l_mater_org_id FROM mtl_parameters
636           WHERE organization_id = p_bom_head_unexp_rec.organization_id;
637         IF (p_bom_head_unexp_rec.organization_id <> l_mater_org_id) THEN
638           Error_Handler.Add_Error_Token
639           (  p_message_name	=> 'BOM_PKG_HIERARCHY_IN_CHILD_ORG'
640            , p_mesg_token_tbl	=> l_Mesg_Token_Tbl
641            , x_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
642            );
643           l_return_status := FND_API.G_RET_STS_ERROR;
644         END IF;
645       END IF;
646     END IF;
647 
648 
649 		--
650 		-- If alternate designator is NOT NULL, then Primary Bill
651 		-- must exist if the user is trying to create an Alternate
652 		--
653 		IF p_bom_header_rec.alternate_bom_code IS NOT NULL AND
654 		   p_bom_header_rec.alternate_bom_code <> FND_API.G_MISS_CHAR
655 		THEN
656 	            BEGIN
657 			SELECT '1'
658 			  INTO l_dummy
659 		  	  FROM bom_bill_of_materials
660 			 WHERE alternate_bom_designator IS NULL
661 			   AND assembly_item_id =
662 					p_bom_head_unexp_rec.assembly_item_id
663 			   AND organization_id =
664 					p_bom_head_unexp_rec.organization_id
665 			   AND ((p_bom_header_rec.assembly_type= 2)
666                   		OR
667                    		(p_bom_header_rec.assembly_type =1
668 				  and assembly_type = 1));
669 
670 			EXCEPTION
671 				WHEN NO_DATA_FOUND THEN
672 					l_return_status :=
673 							FND_API.G_RET_STS_ERROR;
674 					l_token_tbl(1).token_name :=
675 						'ASSEMBLY_ITEM_NAME';
676 					l_token_tbl(1).token_value :=
677 					    p_bom_header_rec.assembly_item_name;
678 					Error_Handler.Add_Error_Token
679 					(  p_message_name    =>
680 						'BOM_CANNOT_ADD_ALTERNATE'
681 					 , p_token_tbl	     => l_token_tbl
682 					 , p_mesg_token_tbl  => l_mesg_token_tbl
683 					 , x_mesg_token_tbl  => l_mesg_token_tbl
684 					 );
685 		    END;
686 		END IF;
687 
688     --validate structure type
689     --The value of structure type in the case of null or FND_API.MISS_CHAR
690     --will be ignored.
691 
692 		IF (    p_bom_header_rec.alternate_bom_code IS NOT NULL
693         AND p_bom_header_rec.alternate_bom_code <> FND_API.G_MISS_CHAR
694         AND p_bom_head_unexp_rec.structure_type_id IS NOT NULL
695         AND p_bom_head_unexp_rec.structure_type_id <> FND_API.G_MISS_NUM )
696 		THEN
697       SELECT  COUNT(1)
698       INTO    l_count
699       FROM    BOM_ALTERNATE_DESIGNATORS BAD
700       WHERE
701           BAD.ORGANIZATION_ID = p_bom_head_unexp_rec.organization_id
702       AND BAD.ALTERNATE_DESIGNATOR_CODE = p_bom_header_rec.alternate_bom_code
703       AND BAD.STRUCTURE_TYPE_ID IN
704             ( SELECT  BST.STRUCTURE_TYPE_ID
705               FROM    BOM_STRUCTURE_TYPES_B BST
706               START WITH BST.STRUCTURE_TYPE_ID = p_bom_head_unexp_rec.structure_type_id
707               CONNECT BY PRIOR BST.PARENT_STRUCTURE_TYPE_ID = BST.STRUCTURE_TYPE_ID
708             );
709 
710       IF ( l_count = 0 ) THEN
711         l_return_status := FND_API.G_RET_STS_ERROR;
712 
713         l_token_tbl(1).token_name  := 'STRUCTURE_NAME';
714         l_token_tbl(1).token_value := p_bom_header_rec.alternate_bom_code;
715         l_token_tbl(2).token_name  := 'STRUCTURE_TYPE';
716         l_token_tbl(2).token_value := p_bom_header_rec.Structure_Type_Name;
717 
718         Error_Handler.Add_Error_Token
719           (  p_Message_Name       => 'BOM_STRUCTNAMEANDTYPE_INVALID'
720           , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
721           , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
722           , p_Token_Tbl          => l_token_tbl
723           );
724       END IF; -- end if l_count = 0
725     END IF; -- end if p_bom_header_rec.alternate_bom_code IS NOT NULL
726 
727     -- In update case, the new structure type must be a child of the existing one
728     IF (    p_bom_header_rec.transaction_type = Bom_Globals.G_OPR_UPDATE
729         AND p_bom_head_unexp_rec.structure_type_id IS NOT NULL
730         AND p_bom_head_unexp_rec.structure_type_id <> FND_API.G_MISS_NUM
731         AND p_bom_head_unexp_rec.structure_type_id <> p_old_bom_head_unexp_rec.structure_type_id )
732     THEN
733       SELECT  COUNT(1)
734       INTO    l_count
735       FROM    BOM_STRUCTURE_TYPES_B BST
736       WHERE   BST.STRUCTURE_TYPE_ID = p_bom_head_unexp_rec.structure_type_id
737       START WITH BST.STRUCTURE_TYPE_ID = p_old_bom_head_unexp_rec.structure_type_id
738       CONNECT BY PRIOR BST.STRUCTURE_TYPE_ID = BST.PARENT_STRUCTURE_TYPE_ID;
739 
740       IF ( l_count = 0 ) THEN
741         l_return_status := FND_API.G_RET_STS_ERROR;
742 
743         --existing structure type is not populated in the BO record
744         l_token_tbl(1).token_name  := 'OLD_STRTYPE';
745         BEGIN
746           SELECT  STRUCTURE_TYPE_NAME
747           INTO    l_existing_str_type
748           FROM    BOM_STRUCTURE_TYPES_B
749           WHERE   STRUCTURE_TYPE_ID = p_old_bom_head_unexp_rec.structure_type_id;
750 
751           l_token_tbl(1).token_value := l_existing_str_type;
752         EXCEPTION
753           WHEN NO_DATA_FOUND THEN
754             l_token_tbl(1).token_value := '';
755         END;
756 
757         l_token_tbl(2).token_name  := 'NEW_STRTYPE';
758         l_token_tbl(2).token_value := p_bom_header_rec.structure_type_name;
759 
760         Error_Handler.Add_Error_Token
761           (  p_Message_Name       => 'BOM_UPDATE_STRTYPE_INVALID'
762           , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
763           , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
764           , p_Token_Tbl          => l_token_tbl
765           );
766       END IF; -- end if l_count = 0
767     END IF; -- end if p_bom_header_rec.transaction_type = Bom_Globals.G_OPR_UPDATE
768 
769 
770 		/** -------------------------------------------------------------
771 		** When commoning a bill, either creating or updating an existing
772 		** one, the following validations are performed
773 		** 1. Common_bill_Sequence_Id is non-updateable. So once a common
774 		**    bom is created user can only delete it and cannot simply
775 		**    update it to piont to another bom as common
776 		** 2. Manufactuing BOM's cannot refer to an Engineering BOM as common
777 		** 3. If the BOM being updated already has components, then it cannot
778 		**    refer to another BOM as common
779 		** 4. If a BOM is referencing another bill as common, then only the
780 		**    parent BOM is updateable
781 		** 5. If a BOM is already referencing another bill as common, then
782 		**    this BOM cannot be used as common for another BOM. i.e it is
783 		**    not permitted to create a chain of common BOM's
784 		** 6. The current BOM and the bill being referenced as common must have the
785 		**    same master org
786 		** 7. If a BOM in one org is referening a BOM in another org as common, then
787 		**    make sure that then all the components that exist under the parent org
788 		**    must exist both the orgs
789 		** 8. If a BOM in one org is referencing a BOM in another org as common, then
790 		**    any substitute components under the components must also exist in both
791 		**    orgs
792 		** 9. When referencing another bom as common, the items must have the same
793 		**    bom_item_type, pick_components_flag, replenish_to_order_flag and
794 		**    bom_enabled_flag
795 		** --------------------------------------------------------------------**/
796 
797 		--
798 		-- If the user is performing an update operation, then the user
799 		-- must not enter the value for common organization code and
800 		-- common assembly item name. Providing these values would mean that
801 		-- the user is attempting to update these non-updateable columns
802 		--
803 		IF p_bom_header_rec.transaction_type = Bom_Globals.G_OPR_UPDATE
804 		   AND
805 		   ( ( p_bom_header_rec.common_organization_code IS NOT NULL
806 		       AND p_bom_header_rec.common_organization_code <>
807 						FND_API.G_MISS_CHAR
808 		       AND NVL(p_bom_header_rec.common_organization_code, 'XXX') <>
809 			   NVL(p_old_bom_head_rec.common_organization_code,'XXX')
810 		      )
811 		      OR
812 		      ( p_bom_header_rec.common_assembly_item_name IS NOT NULL
813 			AND p_bom_header_rec.common_assembly_item_name <>
814 						FND_API.G_MISS_CHAR
815 			AND NVL(p_bom_header_rec.common_assembly_item_name, 'NONE') <>
816 			    NVL(p_old_bom_head_rec.common_assembly_item_name, 'NONE')
817 		       )
818 		     )
819 		THEN
820 
821 			l_token_tbl(1).token_name := 'ASSEMBLY_ITEM_NAME';
822 			l_token_tbl(1).token_value :=
823 					p_bom_header_rec.assembly_item_name;
824                       Error_Handler.Add_Error_Token
825                       (  p_message_name       =>
826                                         'BOM_COMMON_ORG_ASSY_NONUPD'
827                        , p_token_tbl          => l_token_tbl
828                        , p_mesg_token_tbl     => l_mesg_token_tbl
829                        , x_mesg_token_tbl     => l_mesg_token_tbl
830                        );
831                        l_return_status := FND_API.G_RET_STS_ERROR;
832 		END IF;
833 
834 		--
835 		-- If the user is trying to perform an update, and the bill is
836 		-- referencing another bill as common, then this bill is not
837 		-- updateable. Only the parent bill is
838 		--
839         		/* Commented out for bug: 8208327
840                    Changes to the header of a bom with a common bom reference should be
841                    allowed. However, modifications to components should not. This check
842                    was moved to procedure bom_components */
843 		/* FOR CheckCommon IN c_CheckCommon
844 		LOOP
845 			IF CheckCommon.common_bill_seq <>
846 			   CheckCommon.bill_sequence_id
847 			THEN
848 				l_token_tbl(1).token_name := 'ASSEMBLY_ITEM_NAME';
849 				l_token_tbl(1).token_value :=
850 					p_bom_header_rec.assembly_item_name;
851 				Error_Handler.Add_Error_Token
852                         	(  p_message_name       =>
853                                 	'BOM_ASSY_COMMON_REF_COMMON'
854                         	 , p_token_tbl          => l_token_tbl
855                         	 , p_mesg_token_tbl     => l_mesg_token_tbl
856                         	 , x_mesg_token_tbl     => l_mesg_token_tbl
857                         	 );
858                         	l_return_status := FND_API.G_RET_STS_ERROR;
859 			END IF;
860 
861 		END LOOP;	*/
862 		--
863 		--
864 		-- If the user is assigning a common assembly to the current
865 		-- bill then the common assembly must already have a common
866 		-- assembly. i.e User cannot create a chain of common bills
867 		--
868 		-- Using the common bill sequence_id check if the record for the
869 		-- common bill has a common bill sequence id.
870 		IF p_bom_head_unexp_rec.source_bill_sequence_id IS NOT NULL AND
871 		   p_bom_head_unexp_rec.source_bill_sequence_id <>
872 							FND_API.G_MISS_NUM
873 		THEN
874 		BEGIN
875 			SELECT '1'
876 		  	  INTO l_dummy
877 		          FROM bom_bill_of_materials
878 		 	 WHERE bill_sequence_id =
879 				p_bom_head_unexp_rec.source_bill_sequence_id
880 			   AND NVL(source_bill_sequence_id, bill_sequence_id) <>
881 					bill_sequence_id;
882 
883 			l_token_tbl.delete;
884 			l_token_tbl(1).token_name := 'COMMON_ASSEMBLY_ITEM_NAME';
885 			l_token_tbl(1).token_value :=
886 				p_bom_header_rec.common_assembly_item_name;
887 			l_token_tbl(2).token_name := 'ASSEMBLY_ITEM_NAME';
888 			l_token_tbl(2).token_value :=
889 				p_bom_header_rec.assembly_item_name;
890 			Error_Handler.Add_Error_Token
891 			(  p_message_name	=>
892 				'BOM_ASSY_COMMON_OTHER_ASSY'
893 			 , p_token_tbl		=> l_token_tbl
894 			 , p_mesg_token_tbl	=> l_mesg_token_tbl
895 			 , x_mesg_token_tbl	=> l_mesg_token_tbl
896 			 );
897 			l_return_status := FND_API.G_RET_STS_ERROR;
898 
899 			EXCEPTION
900 				WHEN NO_DATA_FOUND THEN
901 					NULL;
902 
903 		END;
904 		--
905 		-- If the current bill is a manufacturing bill then the
906 		-- common bill must also be a manufactuing bill
907 		--
908 		BEGIN
909 			SELECT '1'
910 			  INTO l_dummy
911 			  FROM mtl_system_items assy,
912 			       mtl_system_items common
913 			 WHERE assy.inventory_item_id =
914 				p_bom_head_unexp_rec.assembly_item_id
915 			   AND assy.organization_id =
916 				p_bom_head_unexp_rec.organization_id
917 			   AND common.inventory_item_id =
918 				p_bom_head_unexp_rec.common_assembly_item_id
919 			   AND common.organization_id =
920 				p_bom_head_unexp_rec.common_organization_id
921 			   AND  ((common.eng_item_flag = 'N' and
922 				assy.eng_item_flag = common.eng_item_flag)
923 				  OR
924 				  common.eng_item_flag <> 'N');
925 
926 			EXCEPTION
927 				WHEN NO_DATA_FOUND THEN
928 					l_token_tbl(1).token_name :=
929 				  'ASSEMBLY_ITEM_NAME';
930 					l_token_tbl(1).token_value :=
931 				   p_bom_header_rec.assembly_item_name;
932 					l_token_tbl(2).token_name :=
933 				   'COMMON_ASSEMBLY_ITEM_NAME';
934 				   	l_token_tbl(2).token_value :=
935 				   p_bom_header_rec.common_assembly_item_name;
936 				Error_Handler.Add_Error_Token
937 				(  p_message_name	=>
938 						'BOM_COMMON_ASSY_TYPE_MISMATCH'
939 				 , p_token_tbl		=> l_token_tbl
940 				 , p_mesg_token_tbl	=> l_mesg_token_tbl
941 				 , x_mesg_token_tbl	=> l_mesg_token_tbl
942 				 );
943 				l_return_status := FND_API.G_RET_STS_ERROR;
944 		END;
945 		END IF;
946 
947     IF p_bom_header_Rec.ENABLE_ATTRS_UPDATE = 'Y'
948     THEN
949       -- Add operation sequence number validation here
950       --call bompcmbm.validate_operation_sequence_id
951       BOMPCMBM.Validate_Operation_Sequence_Id(p_src_bill_sequence_id => p_bom_head_unexp_rec.source_bill_sequence_id
952                                      , p_assembly_item_id => p_bom_head_unexp_rec.assembly_item_id
953                                      , p_organization_id => p_bom_head_unexp_rec.organization_id
954                                      , p_alt_desg => p_bom_header_rec.alternate_bom_code
955                                      , x_Return_Status  => l_valid_op_seq);
956       IF l_valid_op_seq = FND_API.G_RET_STS_ERROR
957       THEN
958         --BOM_COMMON_OPN_INVALID
959             l_token_tbl(1).token_name := 'ASSEMBLY_ITEM_NAME';
960             l_token_tbl(1).token_value := p_bom_header_rec.assembly_item_name;
961             l_token_tbl(2).token_name := 'COMMON_ASSY_ITEM_NAME';
962             l_token_tbl(2).token_value :=	p_bom_header_rec.common_assembly_item_name;
963             l_token_tbl(3).token_name := 'SOURCE_ORG';
964             l_token_tbl(3).token_value := p_bom_header_rec.common_organization_code;
965             l_token_tbl(4).token_name := 'DEST_ORG';
966             l_token_tbl(4).token_value := p_bom_header_rec.organization_code;
967             l_token_tbl(5).token_name := 'ASSEMBLY_ITEM_NAME1';
968             l_token_tbl(5).token_value := p_bom_header_rec.assembly_item_name;
969 
970             Error_Handler.Add_Error_Token
971             (  p_message_name       =>
972                           'BOM_COMMON_OPN_INVALID'
973              , p_token_tbl          => l_token_tbl
974              , p_mesg_token_tbl     => l_mesg_token_tbl
975              , x_mesg_token_tbl     => l_mesg_token_tbl
976              );
977             l_return_status := FND_API.G_RET_STS_ERROR;
978       END IF;
979     END IF;
980 
981 
982 
983 		--
984 		-- Validation for inter-org common
985 		--
986 		IF ( p_bom_header_rec.transaction_type = Bom_Globals.G_OPR_UPDATE AND
987 		     p_bom_head_unexp_rec.source_bill_sequence_id IS NOT NULL AND
988 		     p_bom_head_unexp_rec.source_bill_sequence_id <> FND_API.G_MISS_NUM AND
989 		     p_old_bom_head_unexp_rec.source_bill_sequence_id IS NULL AND
990 		     p_old_bom_head_unexp_rec.organization_id <>
991 			p_bom_head_unexp_rec.common_organization_id
992 		    )
993 		   OR
994 		   ( p_bom_header_rec.transaction_type = Bom_Globals.G_OPR_CREATE AND
995 		     p_bom_head_unexp_rec.source_bill_sequence_id IS NOT NULL AND
996 		     p_bom_head_unexp_rec.source_bill_sequence_id <> FND_API.G_MISS_NUM AND
997 		     p_bom_head_unexp_rec.common_organization_id <>
998 				p_bom_head_unexp_rec.organization_id
999 		    )
1000 		THEN
1001 		   BEGIN
1002       			SELECT '1'
1003         		  INTO l_dummy
1004         	          FROM mtl_parameters mp1, mtl_parameters mp2
1005        			 WHERE mp1.organization_id = p_bom_head_unexp_rec.organization_id
1006          		   AND mp2.organization_id =
1007 			       DECODE(p_bom_header_rec.transaction_type, Bom_Globals.G_OPR_CREATE,
1008 				      p_bom_head_unexp_rec.common_organization_id,
1009 				      Bom_Globals.G_OPR_UPDATE,
1010 				      p_old_bom_head_unexp_rec.common_organization_id
1011 				      )
1012          		   AND mp1.master_organization_id = mp2.master_organization_id;
1013 
1014    			EXCEPTION
1015       				WHEN no_data_found THEN
1016                                         l_token_tbl(1).token_name :=
1017                                   		'ASSEMBLY_ITEM_NAME';
1018                                         l_token_tbl(1).token_value :=
1019                                    	p_bom_header_rec.assembly_item_name;
1020                                         l_token_tbl(2).token_name :=
1021                                    		'COMMON_ASSEMBLY_ITEM_NAME';
1022                                         l_token_tbl(2).token_value :=
1023                                    		p_bom_header_rec.common_assembly_item_name;
1024 					l_token_tbl(3).token_name := 'ORG_CODE';
1025 					l_token_tbl(3).token_value :=
1026 						p_bom_header_rec.organization_code;
1027 					l_token_tbl(4).token_name := 'COMMON_ORG_CODE';
1028 					l_token_tbl(4).token_value :=
1029 						p_bom_header_rec.common_organization_code;
1030 
1031                                 	Error_Handler.Add_Error_Token
1032                                 	(  p_message_name       =>
1033                                                 'BOM_COMMON_MASTER_ORG_MISMATCH'
1034                                 	 , p_token_tbl          => l_token_tbl
1035                                 	 , p_mesg_token_tbl     => l_mesg_token_tbl
1036                                 	 , x_mesg_token_tbl     => l_mesg_token_tbl
1037                                 	 );
1038 
1039          				l_return_status := FND_API.G_RET_STS_ERROR;
1040    		    END; -- if master org same ends
1041 
1042           -- Add operation sequence number validation here
1043           --call bompcmbm.validate_operation_sequence_id
1044           /*BOMPCMBM.Validate_Operation_Sequence_Id(p_src_bill_sequence_id => p_bom_head_unexp_rec.source_bill_sequence_id
1045                                          , p_assembly_item_id => p_bom_head_unexp_rec.assembly_item_id
1046                                          , p_organization_id => p_bom_head_unexp_rec.organization_id
1047                                          , p_alt_desg => p_bom_header_rec.alternate_bom_code
1048                                          , x_Return_Status  => l_valid_op_seq);
1049           IF l_valid_op_seq = FND_API.G_RET_STS_UNEXP_ERROR
1050           THEN
1051             --BOM_COMMON_OPN_INVALID
1052                 l_token_tbl(1).token_name := 'ALT_DESG';
1053                 l_token_tbl(1).token_value := p_bom_header_rec.alternate_bom_code;
1054                 l_token_tbl(2).token_name := 'COMMON_ASSY_ITEM_NAME';
1055                 l_token_tbl(2).token_value :=	p_bom_header_rec.common_assembly_item_name;
1056                 l_token_tbl(3).token_name := 'SOURCE_ORG';
1057                 l_token_tbl(3).token_value := p_bom_header_rec.common_organization_code;
1058 		      			l_token_tbl(4).token_name := 'DEST_ORG';
1059 					      l_token_tbl(4).token_value := p_bom_header_rec.organization_code;
1060 
1061                 Error_Handler.Add_Error_Token
1062                 (  p_message_name       =>
1063                               'BOM_COMMON_OPN_INVALID'
1064                  , p_token_tbl          => l_token_tbl
1065                  , p_mesg_token_tbl     => l_mesg_token_tbl
1066                  , x_mesg_token_tbl     => l_mesg_token_tbl
1067                  );
1068         				l_return_status := FND_API.G_RET_STS_ERROR;
1069           END IF;*/
1070 
1071                 -- If the current bom and the bom being referenced as common are not in the
1072                 -- same org, then make sure that the components of the parent BOM exist in
1073                 -- both the organizations
1074                    BEGIN
1075                         SELECT bom_item_type, base_item_id, replenish_to_order_flag,
1076                                pick_components_flag--, DECODE(eng_item_flag, 'Y', 2, 1)
1077                           INTO bit, base_id, ato, pto--, assmtype
1078                           FROM mtl_system_items
1079                          WHERE inventory_item_id = p_bom_head_unexp_rec.assembly_item_id
1080                            AND organization_id = p_bom_head_unexp_rec.organization_id;
1081 
1082 
1083 
1084                         SELECT assembly_type
1085                         INTO assmtype
1086                         FROM bom_structures_b
1087                         WHERE bill_sequence_id = p_bom_head_unexp_rec.source_bill_sequence_id;
1088 
1089                         SELECT count(*)
1090                           INTO l_count
1091                           FROM bom_inventory_components bic
1092                          WHERE bic.bill_sequence_id = p_bom_head_unexp_rec.source_bill_sequence_id
1093                            AND nvl(bic.disable_date, sysdate + 1) >= sysdate --- Bug: 3448641
1094                            AND not exists
1095                                (SELECT 'x'
1096                                   FROM mtl_system_items s
1097                                  WHERE s.organization_id = p_bom_head_unexp_rec.organization_id
1098                                    AND s.inventory_item_id = bic.component_item_id
1099                                    AND ((assmtype = 1 AND s.eng_item_flag = 'N')
1100                                           OR (assmtype = 2)
1101                                         )
1102 /* Commented the following for Bug2984763 */
1103                                    AND s.bom_enabled_flag = 'Y' /* Uncommented for bug 5925020 */
1104                                    AND s.inventory_item_id <> p_bom_head_unexp_rec.assembly_item_id
1105                                    AND ((bit = 1 AND s.bom_item_type <> 3)
1106                                          OR (bit = 2 AND s.bom_item_type <> 3)
1107                                          OR (bit = 3)
1108                                          OR (bit = 4
1109                                              AND (s.bom_item_type = 4
1110                                                   OR
1111                                                   ( s.bom_item_type IN (2, 1)
1112                                                     AND s.replenish_to_order_flag = 'Y'
1113                                                     AND base_id IS NOT NULL
1114                                                     AND ato = 'Y'
1115                                                    )
1116                                                  )
1117                                               )
1118                                           )
1119                                    AND (bit = 3
1120                                          OR
1121                                         pto = 'Y'
1122                                         OR
1123                                         s.pick_components_flag = 'N'
1124                                         )
1125                                    AND (bit = 3
1126                                          OR
1127                                         NVL(s.bom_item_type, 4) <> 2
1128                                                 OR
1129                                            (s.bom_item_type = 2
1130                                             AND (( pto = 'Y'
1131                                                    AND s.pick_components_flag = 'Y'
1132                                                   )
1133                                                   OR ( ato = 'Y'
1134                                                        AND s.replenish_to_order_flag = 'Y'
1135                                                       )
1136                                                  )
1137                                             )
1138                                          )
1139                                    AND (
1140                                         (
1141                                           (nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) <> 1)
1142                                            and
1143                                           (not( bit = 4
1144                                                 AND pto = 'Y'
1145                                                 AND s.bom_item_type = 4
1146                                                 AND s.replenish_to_order_flag = 'Y'
1147                                                )
1148                                           )
1149                                          ) OR
1150                                          (nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) = 1)
1151                                         )  /* BOM ER 9904085 */
1152                                    AND (
1153                                         (
1154                                           (nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) <> 1)
1155                                            and
1156                                           (not( bit = 1
1157                                                 AND pto = 'Y'
1158                                                 AND nvl(bic.optional, 1) = 2
1159                                                 AND s.bom_item_type = 4
1160                                                 AND s.replenish_to_order_flag = 'Y'
1161                                                )
1162                                            )
1163                                           ) OR
1164                                          (nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) = 1)
1165                                          )   /* BOM ER 9904085 */
1166                         );
1167 
1168 
1169 
1170                         IF l_Count > 0
1171                         THEN
1172                                 l_token_tbl.DELETE;
1173                                 l_token_tbl(1).token_name :=
1174                                                 'ASSEMBLY_ITEM_NAME';
1175                                 l_token_tbl(1).token_value :=
1176                                         p_bom_header_rec.assembly_item_name;
1177                                 l_token_tbl(2).token_name := 'ORG_CODE';
1178                                 l_token_tbl(2).token_value :=
1179                                                 p_bom_header_rec.organization_code;
1180                                 l_token_tbl(3).token_name := 'COMMON_ORG_CODE';
1181                                 l_token_tbl(3).token_value :=
1182 						p_bom_header_rec.common_organization_code;
1183 
1184                                 Error_Handler.Add_Error_Token
1185                                 (  p_message_name   => 'BOM_COMMON_COMP_PROP_MISMATCH'
1186                                  , p_token_tbl      => l_token_tbl
1187                                  , p_mesg_token_tbl => l_mesg_token_tbl
1188                                  , x_mesg_token_tbl => l_mesg_token_tbl
1189                                  );
1190 
1191                                  l_return_status := FND_API.G_RET_STS_ERROR;
1192                        END IF;
1193                    END;
1194 
1195     --If the source bom comtains fixed rev components, make sure the same revisions exist in the
1196     --destination org.
1197     BOMPCMBM.check_comp_rev_in_local_org(p_src_bill_seq_id => p_bom_head_unexp_rec.source_bill_sequence_id,
1198                                          p_org_id => p_bom_head_unexp_rec.organization_id,
1199                                          x_return_status => l_comp_rev_status); --Bug 7526867
1200 
1201     IF l_comp_rev_status <> FND_API.G_RET_STS_SUCCESS --Bug 7526867
1202     THEN
1203 
1204       l_token_tbl.DELETE;
1205       l_token_tbl(1).token_name := 'ASSY_ITEM';
1206       l_token_tbl(1).token_value := p_bom_header_rec.assembly_item_name;
1207       l_token_tbl(2).token_name := 'ORG_CODE';
1208       l_token_tbl(2).token_value := p_bom_header_rec.organization_code;
1209 
1210       Error_Handler.Add_Error_Token
1211       (  p_message_name   => 'BOM_SRC_COMP_FIXED_REV'
1212        , p_token_tbl      => l_token_tbl
1213        , p_mesg_token_tbl => l_mesg_token_tbl
1214        , x_mesg_token_tbl => l_mesg_token_tbl
1215        );
1216 
1217        l_return_status := FND_API.G_RET_STS_ERROR;  --Bug 7526867
1218 
1219     END IF;
1220 
1221                    --
1222                    -- Make sure that the substitute components exist in both the organizations
1223                    --
1224 		  BEGIN
1225 			SELECT count(*)
1226 			  INTO l_count
1227         	          FROM bom_inventory_components bic,
1228              		       bom_substitute_components bsc
1229        			 WHERE bic.bill_sequence_id =p_bom_head_unexp_rec.source_bill_sequence_id
1230          		   AND bic.component_sequence_id = bsc.component_sequence_id
1231          		   AND bsc.substitute_component_id not in
1232                		       (select msi1.inventory_item_id
1233                   		  from mtl_system_items msi1, mtl_system_items msi2
1234                  		 where msi1.organization_id = p_bom_head_unexp_rec.organization_id
1235                    		   and msi1.inventory_item_id = bsc.substitute_component_id
1236                          and msi1.bom_enabled_flag = 'Y'
1237                    		   and msi2.organization_id = p_bom_head_unexp_rec.common_organization_id
1238                    		   and msi2.inventory_item_id = msi1.inventory_item_id
1239                          AND ((assmtype = 1 AND msi1.eng_item_flag = 'N')
1240                                OR (assmtype = 2)
1241                              )
1242                                    AND msi1.inventory_item_id <> p_bom_head_unexp_rec.assembly_item_id
1243                                    AND ((bit = 1 AND msi1.bom_item_type <> 3)
1244                                          OR (bit = 2 AND msi1.bom_item_type <> 3)
1245                                          OR (bit = 3)
1246                                          OR (bit = 4
1247                                              AND (msi1.bom_item_type = 4
1248                                                   OR
1249                                                   ( msi1.bom_item_type IN (2, 1)
1250                                                     AND msi1.replenish_to_order_flag = 'Y'
1251                                                     AND base_id IS NOT NULL
1252                                                     AND ato = 'Y'
1253                                                    )
1254                                                  )
1255                                               )
1256                                           )
1257                                    AND (bit = 3
1258                                          OR
1259                                         pto = 'Y'
1260                                         OR
1261                                         msi1.pick_components_flag = 'N'
1262                                         )
1263                                    AND (bit = 3
1264                                          OR
1265                                         NVL(msi1.bom_item_type, 4) <> 2
1266                                                 OR
1267                                            (msi1.bom_item_type = 2
1268                                             AND (( pto = 'Y'
1269                                                    AND msi1.pick_components_flag = 'Y'
1270                                                   )
1271                                                   OR ( ato = 'Y'
1272                                                        AND msi1.replenish_to_order_flag = 'Y'
1273                                                       )
1274                                                  )
1275                                             )
1276                                          )
1277                                    AND /* not( bit = 4
1278                                             AND pto = 'Y'
1279                                             AND msi1.bom_item_type = 4
1280                                             AND msi1.replenish_to_order_flag = 'Y'
1281                                            ) */
1282                                        (
1283                                         (
1284                                           (nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) <> 1)
1285                                            and
1286                                           (not( bit = 4
1287                                                 AND pto = 'Y'
1288                                                 AND msi1.bom_item_type = 4
1289                                                 AND msi1.replenish_to_order_flag = 'Y'
1290                                                )
1291                                           )
1292                                          ) OR
1293                                          (nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) = 1)
1294                                         )  /* BOM ER 9904085 */
1295                          );
1296       			  IF (l_count > 0) THEN
1297 				l_token_tbl.DELETE;
1298                                 l_token_tbl(1).token_name :=
1299                                                 'COMPONENT_ITEM_NAME';
1300                                 l_token_tbl(1).token_value :=
1301                                         p_bom_header_rec.assembly_item_name;
1302                                 l_token_tbl(2).token_name := 'ASSEMBLY_ITEM_NAME';
1303                                 l_token_tbl(2).token_value :=
1304                                                 p_bom_header_rec.organization_code;
1305                                 l_token_tbl(3).token_name := 'COMMON_ORG_CODE';
1306                                 l_token_tbl(3).token_value :=
1307 						p_bom_header_rec.common_organization_code;
1308 
1309                                 Error_Handler.Add_Error_Token
1310                                 (  p_message_name   => 'BOM_COMMON_SCOMP_NOTINALLORG'
1311                                  , p_token_tbl      => l_token_tbl
1312                                  , p_mesg_token_tbl => l_mesg_token_tbl
1313                                  , x_mesg_token_tbl => l_mesg_token_tbl
1314                                  );
1315 
1316                                  l_return_status := FND_API.G_RET_STS_ERROR;
1317 
1318       			  END IF;
1319  	   	END; -- Check if all the substitutes exist ends
1320     END IF;  -- User creating a common or updating the common info Ends
1321 
1322 /* BOM ER 9904085 */
1323 --begin
1324 IF ( p_bom_header_rec.transaction_type = Bom_Globals.G_OPR_UPDATE AND
1325 		     p_bom_head_unexp_rec.source_bill_sequence_id IS NOT NULL AND
1326 		     p_bom_head_unexp_rec.source_bill_sequence_id <> FND_API.G_MISS_NUM AND
1327 		     p_old_bom_head_unexp_rec.source_bill_sequence_id IS NULL AND
1328 		     p_old_bom_head_unexp_rec.organization_id =
1329 			p_bom_head_unexp_rec.common_organization_id
1330 		    )
1331 		   OR
1332 		   ( p_bom_header_rec.transaction_type = Bom_Globals.G_OPR_CREATE AND
1333 		     p_bom_head_unexp_rec.source_bill_sequence_id IS NOT NULL AND
1334 		     p_bom_head_unexp_rec.source_bill_sequence_id <> FND_API.G_MISS_NUM AND
1335 		     p_bom_head_unexp_rec.common_organization_id =
1336 				p_bom_head_unexp_rec.organization_id
1337 		    )
1338 			THEN
1339  BEGIN
1340 
1341 						SELECT bom_item_type, base_item_id, replenish_to_order_flag,
1342                                pick_components_flag--, DECODE(eng_item_flag, 'Y', 2, 1)
1343                           INTO bit, base_id, ato, pto--, assmtype
1344                           FROM mtl_system_items
1345                          WHERE inventory_item_id = p_bom_head_unexp_rec.assembly_item_id
1346                            AND organization_id = p_bom_head_unexp_rec.organization_id;
1347 
1348 						    SELECT assembly_type
1349                         INTO assmtype
1350                         FROM bom_structures_b
1351                         WHERE bill_sequence_id = p_bom_head_unexp_rec.source_bill_sequence_id;
1352 
1353 						SELECT count(*)
1354                           INTO l_count
1355                           FROM bom_inventory_components bic
1356                          WHERE bic.bill_sequence_id = p_bom_head_unexp_rec.source_bill_sequence_id
1357                            AND nvl(bic.disable_date, sysdate + 1) >= sysdate
1358                            AND not exists
1359                                (SELECT 'x'
1360                                   FROM mtl_system_items s
1361                                  WHERE s.organization_id = p_bom_head_unexp_rec.organization_id
1362                                    AND s.inventory_item_id = bic.component_item_id
1363                                    AND ((assmtype = 1 AND s.eng_item_flag = 'N')
1364                                           OR (assmtype = 2)
1365                                         )
1366                                    AND s.bom_enabled_flag = 'Y'
1367                                    AND s.inventory_item_id <> p_bom_head_unexp_rec.assembly_item_id
1368 								   AND (
1369                                         (
1370                                           (nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) <> 1)
1371                                            and
1372                                           (not( bit = 4
1373                                                 AND pto = 'Y'
1374                                                 AND s.bom_item_type = 4
1375                                                 AND s.replenish_to_order_flag = 'Y'
1376                                                )
1377                                           )
1378                                          ) OR
1379                                          (nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) = 1)
1380                                         )
1381                                    AND (
1382                                           (
1383                                             (nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) <> 1)
1384                                             and
1385                                             (not( bit = 1
1386                                                 AND pto = 'Y'
1387                                                 AND nvl(bic.optional, 1) = 2
1388                                                 AND s.bom_item_type = 4
1389                                                 AND s.replenish_to_order_flag = 'Y'
1390                                                 )
1391                                             )
1392                                            ) OR
1393                                             (nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) = 1)
1394                                          )
1395                         );
1396 
1397 						IF l_Count > 0
1398                         THEN
1399                                 l_token_tbl.DELETE;
1400                                 l_token_tbl(1).token_name :=
1401                                                 'ASSEMBLY_ITEM_NAME';
1402                                 l_token_tbl(1).token_value :=
1403                                         p_bom_header_rec.assembly_item_name;
1404                                 l_token_tbl(2).token_name := 'COMMON_ORG_CODE';
1405                                 l_token_tbl(2).token_value :=
1406 						p_bom_header_rec.common_organization_code;
1407 
1408                                 Error_Handler.Add_Error_Token
1409                                 (  p_message_name   => 'BOM_SAME_ORG_COMMON_PROP_MIS'
1410                                  , p_token_tbl      => l_token_tbl
1411                                  , p_mesg_token_tbl => l_mesg_token_tbl
1412                                  , x_mesg_token_tbl => l_mesg_token_tbl
1413                                  );
1414 
1415                                  l_return_status := FND_API.G_RET_STS_ERROR;
1416                        END IF;
1417                    END;
1418 
1419 
1420 
1421 
1422                    -- Make sure that the substitute components properties are allowed as well
1423                    --
1424 		  BEGIN
1425 			SELECT count(*)
1426 			  INTO l_count
1427         	          FROM bom_inventory_components bic,
1428              		       bom_substitute_components bsc
1429        			 WHERE bic.bill_sequence_id =p_bom_head_unexp_rec.source_bill_sequence_id
1430          		   AND bic.component_sequence_id = bsc.component_sequence_id
1431          		   AND bsc.substitute_component_id not in
1432                		       (select msi1.inventory_item_id
1433                   		  from mtl_system_items msi1, mtl_system_items msi2
1434                  		 where msi1.organization_id = p_bom_head_unexp_rec.organization_id
1435                    		   and msi1.inventory_item_id = bsc.substitute_component_id
1436                          and msi1.bom_enabled_flag = 'Y'
1437                    		   and msi2.organization_id = p_bom_head_unexp_rec.common_organization_id
1438                    		   and msi2.inventory_item_id = msi1.inventory_item_id
1439                          AND ((assmtype = 1 AND msi1.eng_item_flag = 'N')
1440                                OR (assmtype = 2)
1441                              )
1442                                    AND msi1.inventory_item_id <> p_bom_head_unexp_rec.assembly_item_id
1443 
1444                                    AND
1445                                        (
1446                                         (
1447                                           (nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) <> 1)
1448                                            and
1449                                           (not( bit = 4
1450                                                 AND pto = 'Y'
1451                                                 AND msi1.bom_item_type = 4
1452                                                 AND msi1.replenish_to_order_flag = 'Y'
1453                                                )
1454                                           )
1455                                          ) OR
1456                                          (nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) = 1)
1457                                         )
1458                          );
1459       			  IF (l_count > 0) THEN
1460 				l_token_tbl.DELETE;
1461                                 l_token_tbl(1).token_name :=
1462                                                 'COMPONENT_ITEM_NAME';
1463                                 l_token_tbl(1).token_value :=
1464                                         p_bom_header_rec.assembly_item_name;
1465                                 l_token_tbl(2).token_name := 'COMMON_ORG_CODE';
1466                                 l_token_tbl(2).token_value :=
1467 						p_bom_header_rec.common_organization_code;
1468 
1469                                 Error_Handler.Add_Error_Token
1470                                 (  p_message_name   => 'BOM_COMMON_SCOMP_PROP_MIS'
1471                                  , p_token_tbl      => l_token_tbl
1472                                  , p_mesg_token_tbl => l_mesg_token_tbl
1473                                  , x_mesg_token_tbl => l_mesg_token_tbl
1474                                  );
1475 
1476                                  l_return_status := FND_API.G_RET_STS_ERROR;
1477 
1478       			  END IF;
1479  	   	END; -- Check if all the substitutes exist ends
1480     END IF;  -- User creating a common or updating the common info Ends
1481 	/* BOM ER 9904085 */
1482     --end
1483 
1484 
1485 		-- check to see if bill item and common item have same bom_item_type,
1486 		-- pick_components_flag and replenish_to_order_flag
1487 		-- Common item must have bom_enabled_flag = 'Y'
1488 		--
1489         IF ( p_bom_header_rec.transaction_type = Bom_Globals.G_OPR_UPDATE AND
1490              p_bom_head_unexp_rec.source_bill_sequence_id IS NOT NULL AND
1491              p_bom_head_unexp_rec.source_bill_sequence_id <> FND_API.G_MISS_NUM AND
1492              p_old_bom_head_unexp_rec.source_bill_sequence_id IS NULL
1493             )
1494            OR
1495            ( p_bom_header_rec.transaction_type = Bom_Globals.G_OPR_CREATE AND
1496              p_bom_head_unexp_rec.source_bill_sequence_id IS NOT NULL AND
1497              p_bom_head_unexp_rec.source_bill_sequence_id <> FND_API.G_MISS_NUM
1498            )
1499         THEN
1500            BEGIN
1501                  SELECT 1
1502          		 INTO l_count
1503          		 FROM mtl_system_items msi1, mtl_system_items msi2
1504         	        WHERE
1505 --Bug 2217522             msi1.organization_id = p_bom_head_unexp_rec.common_organization_id
1506                           msi1.organization_id = p_bom_head_unexp_rec.organization_id   --Bug 2217522
1507           		  AND msi1.inventory_item_id = p_bom_head_unexp_rec.assembly_item_id
1508           		  AND msi2.organization_id = p_bom_head_unexp_rec.common_organization_id
1509           		  AND msi2.inventory_item_id=p_bom_head_unexp_rec.common_assembly_item_id
1510           		  AND msi2.bom_enabled_flag = 'Y'
1511           		  AND msi1.bom_item_type = msi2.bom_item_type
1512           		  AND msi1.pick_components_flag = msi2.pick_components_flag
1513           		  AND msi1.replenish_to_order_flag = msi2.replenish_to_order_flag
1514                           AND msi1.effectivity_control = msi2.effectivity_control;
1515                           --Commoning should happen within the eff ctrl.
1516     			EXCEPTION
1517        			   WHEN no_data_found THEN
1518 			       l_return_status := FND_API.G_RET_STS_ERROR;
1519 				l_token_tbl.DELETE;
1520                                 l_token_tbl(1).token_name := 'ASSEMBLY_ITEM_NAME';
1521                                 l_token_tbl(1).token_value := p_bom_header_rec.assembly_item_name;
1522                                 l_token_tbl(2).token_name := 'COMMON_ORG_CODE';
1523                                 l_token_tbl(2).token_value :=
1524 						p_bom_header_rec.common_organization_code;
1525 				l_token_tbl(3).token_name := 'ORG_CODE';
1526 				l_token_tbl(3).token_value := p_bom_header_rec.organization_code;
1527 
1528                                 Error_Handler.Add_Error_Token
1529                                 (  p_message_name   => 'BOM_COMMON_ATOPTO_MISMATCH'
1530                                  , p_token_tbl      => l_token_tbl
1531                                  , p_mesg_token_tbl => l_mesg_token_tbl
1532                                  , x_mesg_token_tbl => l_mesg_token_tbl
1533                                  );
1534 		   END;
1535         END IF;
1536 
1537 
1538 		x_return_status := l_return_status;
1539 		x_mesg_token_tbl := l_mesg_token_tbl;
1540 
1541 	END Check_Entity;
1542 
1543 
1544 	PROCEDURE Check_Entity_Delete
1545         ( x_return_status       IN OUT NOCOPY VARCHAR2
1546         , x_Mesg_Token_Tbl      IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
1547         , p_bom_header_rec	IN  Bom_Bo_Pub.Bom_Head_Rec_Type
1548         , p_bom_head_Unexp_Rec  IN  Bom_Bo_Pub.Bom_Head_Unexposed_Rec_Type
1549 	, x_bom_head_unexp_rec	IN OUT NOCOPY Bom_Bo_Pub.Bom_Head_Unexposed_Rec_Type
1550         )
1551         IS
1552 		l_mesg_token_tbl	Error_Handler.Mesg_Token_Tbl_Type;
1553 		l_bom_head_unexp_rec	Bom_Bo_Pub.Bom_Head_Unexposed_Rec_Type
1554 				:= p_bom_head_Unexp_Rec;
1555 		Cursor CheckGroup is
1556 		SELECT description,
1557            	       delete_group_sequence_id,
1558            	       delete_type
1559           	  FROM bom_delete_groups
1560     	         WHERE delete_group_name = p_bom_header_rec.Delete_Group_Name
1561     		   AND organization_id = p_bom_head_Unexp_Rec.organization_id;
1562 
1563         BEGIN
1564 		x_return_status := FND_API.G_RET_STS_SUCCESS;
1565 		x_bom_head_unexp_rec := p_bom_head_unexp_rec;
1566 
1567         	IF p_bom_header_rec.Delete_Group_Name IS NULL OR
1568 		   p_bom_header_rec.Delete_Group_Name = FND_API.G_MISS_CHAR
1569 		THEN
1570 			Error_Handler.Add_Error_Token
1571 			(  p_message_name	=> 'BOM_DG_NAME_MISSING'
1572 			 , p_mesg_token_tbl	=> l_mesg_token_tbl
1573 			 , x_mesg_token_tbl	=> x_mesg_token_tbl
1574 			 );
1575 			x_return_status := FND_API.G_RET_STS_ERROR;
1576 			RETURN;
1577 		END IF;
1578 
1579 		For c_CheckGroup in CheckGroup
1580 		LOOP
1581        			If c_CheckGroup.delete_type <> 2  /* Bill */ then
1582          			Error_Handler.Add_Error_Token
1583 			     (  p_message_name => 'BOM_DUPLICATE_DELETE_GROUP'
1584 			      , p_mesg_token_tbl=>l_mesg_token_tbl
1585 			      , x_mesg_token_tbl=>x_mesg_token_tbl
1586 			      );
1587 			      x_return_status := FND_API.G_RET_STS_ERROR;
1588 			      RETURN;
1589        			End if;
1590 
1591 
1592        			l_bom_head_unexp_rec.DG_description :=
1593 					c_Checkgroup.description;
1594        			l_bom_head_unexp_rec.DG_sequence_id :=
1595 					c_Checkgroup.delete_group_sequence_id;
1596 
1597 			RETURN;
1598 
1599 		END LOOP;
1600 
1601 		IF l_bom_head_unexp_rec.DG_sequence_id IS NULL
1602 		THEN
1603 			Error_Handler.Add_Error_Token
1604 			(  p_message_name	=> 'NEW_DELETE_GROUP'
1605 			 , p_message_type	=> 'W'
1606 			 , p_mesg_token_tbl	=> l_mesg_token_tbl
1607 			 , x_mesg_token_tbl	=> x_mesg_token_tbl
1608 			 );
1609 
1610 			l_bom_head_unexp_rec.DG_new := TRUE;
1611 			l_bom_head_unexp_rec.DG_description :=
1612 				p_bom_header_rec.DG_description;
1613 		END IF;
1614 
1615 
1616 		-- Return the unexposed record
1617 		x_bom_head_unexp_rec := l_bom_head_unexp_rec;
1618 
1619         END Check_Entity_Delete;
1620 
1621 
1622 END Bom_Validate_Bom_Header;