DBA Data[Home] [Help]

PACKAGE BODY: APPS.BOM_VALIDATE_SUB_COMPONENT

Source


1 PACKAGE BODY BOM_Validate_Sub_Component AS
2 /* $Header: BOMLSBCB.pls 120.3.12000000.3 2007/02/27 11:14:30 arudresh ship $ */
3 /*============================================================================
4 |  Copyright (c) 1996 Oracle Corporation, Redwood Shores, CA, USA
5 |  All rights reserved.
6 |=============================================================================
7 |
8 |  FILENAME
9 |      BOMLSBCB.pls
10 |
11 |  DESCRIPTION
12 |       Body of package BOM_Validate_Sub_Component
13 |
14 |  NOTES
15 |
16 |  HISTORY
17 |       17-JUL-1999	Rahul Chitko	Initial Creation
18 |       08-MAY-2001     Refai Farook    EAM related changes
19 |
20 |  20-Jun-05   Vani Hymavathi       Validations for to OPM convergence project
21 =============================================================================*/
22 --  +------------------------------------------+
23 --  | Global constant holding the package name |
24 --  +------------------------------------------+
25 
26 G_PKG_NAME               CONSTANT VARCHAR2(30) := 'Bom_Validate_Sub_Component';
27 G_RET_CODE       NUMBER;
28 
29 /*********************** Entity **********************************************/
30 
31 PROCEDURE CHECK_REQUIRED(  x_return_status	IN OUT NOCOPY VARCHAR2
32 			 , p_sub_component_rec	 IN
33 			   Bom_Bo_Pub.Sub_Component_Rec_Type
34 			 , x_Mesg_Token_tbl	IN OUT NOCOPY
35 			   Error_Handler.Mesg_Token_Tbl_Type
36 			 )
37 IS
38 l_Mesg_Token_Tbl	Error_Handler.Mesg_Token_Tbl_Type;
39 BEGIN
40 	IF p_sub_component_rec.Revised_Item_Name IS NULL OR
41 	   p_sub_component_rec.Revised_Item_Name = FND_API.G_MISS_CHAR OR
42 	   p_sub_component_rec.Start_Effective_Date IS NULL OR
43 	   p_sub_component_rec.Start_Effective_Date = FND_API.G_MISS_DATE OR
44 	   p_sub_component_rec.Operation_Sequence_Number IS NULL OR
45 	   p_sub_component_rec.Operation_Sequence_Number = FND_API.G_MISS_NUM OR
46 	   p_sub_component_rec.Component_Item_Name IS NULL OR
47 	   p_sub_component_rec.Component_Item_Name = FND_API.G_MISS_CHAR OR
48 	   p_sub_component_rec.Alternate_BOM_Code IS NULL OR
49 	   p_sub_component_rec.Alternate_BOM_Code = FND_API.G_MISS_CHAR OR
50 	   p_sub_component_rec.Substitute_Component_Name IS NULL OR
51 	   p_sub_component_rec.Substitute_Component_Name = FND_API.G_MISS_CHAR OR
52 	   ( ( p_sub_component_rec.acd_type	IS NULL OR
53 	       p_sub_component_rec.acd_type	= FND_API.G_MISS_NUM OR
54                p_sub_component_rec.New_Revised_Item_Revision IS NULL OR
55                p_sub_component_rec.New_Revised_Item_Revision =
56 						FND_API.G_MISS_CHAR
57 	      ) AND
58 	      Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_ECO_BO
59 	    )
60 	THEN
61 		x_return_status := FND_API.G_RET_STS_ERROR;
62 		Error_Handler.Add_Error_Token
63 		(  x_Mesg_Token_Tbl	=> x_Mesg_Token_Tbl
64 		,  p_Message_Name	=> 'BOM_SUB_COMP_REQ'
65 		,  p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
66 		);
67 		-- Log an error indicating that one of the required columns is
68 		-- missing with scope of 'R'
69 		RETURN;
70 	END IF;
71 
72 	x_return_status := FND_API.G_RET_STS_SUCCESS;
73 
74 END CHECK_REQUIRED;
75 
76 /*******************************************************************
77 * Procedure	: Entity
78 * Parameter IN	: Substitute Component Record
79 *		  Substitute component Record of Unexposed Columns
80 * Parameter OUT	: Return_Status - Indicating status of the process.
81 *		  Mesg_Token_Tbl - Table of Errors and their tokens
82 *
83 * Purpose	: Entity procedure will validate the entity record by
84 *		  verfying the business logic for Substitute Components
85 *
86 *********************************************************************/
87 PROCEDURE Check_Entity
88 (   x_return_status         IN OUT NOCOPY VARCHAR2
89 ,   x_Mesg_Token_Tbl	    IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
90 ,   p_sub_component_rec     IN  Bom_Bo_Pub.Sub_Component_Rec_Type
91 ,   p_Sub_Comp_Unexp_Rec    IN  Bom_Bo_Pub.Sub_Comp_Unexposed_Rec_Type
92 ,   p_control_rec	    IN  BOM_BO_PUB.Control_Rec_Type
93 				:= BOM_BO_PUB.G_DEFAULT_CONTROL_REC
94 )
95 IS
96     l_temp_var		NUMBER :=0;
97     l_return_status     VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
98     l_sub_comp_unique   VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
99     l_dummy             NUMBER :=0;
100     l_dummy2            NUMBER :=0;
101     l_parent_acd_type   NUMBER :=0;
102     l_parent_BIT        NUMBER;
103     l_rec_BSI           NUMBER;
104     l_rec_AST           NUMBER;
105     l_rec_BIT           NUMBER;
106     l_rec_AII           NUMBER;
107     l_rec_CII           NUMBER;
108     l_rec_ID            DATE;
109     l_processed         BOOLEAN;
110     l_err_text          VARCHAR2(200);
111     stmt_num            NUMBER := 0;
112     l_token_tbl		Error_Handler.Token_Tbl_Type;
113     l_Mesg_Token_Tbl	Error_Handler.Mesg_Token_Tbl_Type;
114     l_sbc_item_type	NUMBER;
115     l_sbc_bom_enabled_flag VARCHAR2(1);
116     l_sbc_eng_item_flag	   VARCHAR2(1);
117     l_sbc_tracking_qty_ind VARCHAR2(30);
118     l_assy_bom_enabled     VARCHAR2(1);
119 BEGIN
120 
121     BEGIN
122        ------------------------------------------------------------------
123        -- Select Bill_Sequence_Id, Assembly_Type, Assembly_Item_Id,     |
124        -- ACD_TYPE, Component_Item_Id and Implementation_Date           |
125        -- from bom_inventory_component and bom_bill_of_materials tables |
126        ------------------------------------------------------------------
127 
128        SELECT   bbom.bill_sequence_id ,
129                 bbom.assembly_type,
130                 bbom.assembly_item_id,
131                 bic.ACD_TYPE,
132                 bic.bom_item_type,
133                 bic.component_item_id,
134                 bic.implementation_date,
135                 msi.bom_item_type
136          INTO   l_rec_BSI,
137                 l_rec_AST,
138                 l_rec_AII,
139                 l_parent_acd_type,
140                 l_rec_BIT,
141                 l_rec_CII,
142                 l_rec_ID,
143                 l_parent_BIT
144          FROM   mtl_system_items msi,
145                 bom_inventory_components bic,
146                 bom_bill_of_materials bbom
147         WHERE   msi.inventory_item_id = bbom.assembly_item_id
148         AND     msi.organization_id = bbom.organization_id
149         AND     bic.component_sequence_id =
150 		p_Sub_Comp_Unexp_Rec.component_sequence_id
151         AND     bic.bill_sequence_id = bbom.bill_sequence_id;
152     EXCEPTION
153         WHEN OTHERS THEN
154             NULL;
155     END;
156 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Bill SequenceId : ' || to_char(l_rec_BSI)); END IF;
157 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Assembly Type   : ' || to_char(l_rec_AST)); END IF;
158 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Comp SequenceId : ' || to_char(p_Sub_Comp_Unexp_Rec.component_sequence_id)); END IF;
159 
160 if bom_globals.get_debug = 'Y' then Error_Handler.write_debug('Sub Comp:  Checking for editable common bill...'); END IF;
161 
162 BEGIN
163   SELECT 1
164   INTO l_dummy
165   FROM bom_bill_of_materials
166   WHERE bill_sequence_id = source_bill_sequence_id
167   AND bill_sequence_id = l_rec_BSI; --p_sub_comp_unexp_rec.bill_Sequence_id; --Bug 5726557
168 EXCEPTION
169   WHEN NO_DATA_FOUND THEN
170     Error_Handler.Add_Error_Token
171     (  p_Message_Name       => 'BOM_COMMON_SUB_COMP'
172     , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
173     , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
174     , p_Token_Tbl          => l_Token_Tbl
175     );
176     l_Return_Status := FND_API.G_RET_STS_ERROR;
177 END;
178 
179 SELECT msi.bom_enabled_flag
180 INTO l_assy_bom_enabled
181 FROM mtl_system_items_b msi,
182 bom_bill_of_materials bbom
183 WHERE bbom.bill_sequence_id = l_rec_BSI
184 AND bbom.assembly_item_id = msi.inventory_item_id
185 AND bbom.organization_id = msi.organization_id;
186 
187 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Assy Bom Enabled flag : ' || l_assy_bom_enabled); END IF;
188 
189 IF l_assy_bom_enabled <> 'Y'
190 THEN
191       IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
192 			l_token_tbl(1).token_name  := 'REVISED_ITEM_NAME';
193 			l_token_tbl(1).token_value :=
194 				p_sub_component_rec.Revised_Item_Name;
195                         Error_Handler.Add_Error_Token
196                         (  x_Mesg_Token_tbl => l_Mesg_Token_Tbl
197                          , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
198                          , p_message_name   => 'BOM_REV_ITEM_BOM_NOT_ENABLED'
199 			 , p_token_tbl	    => l_token_tbl
200                          );
201                 END IF;
202 		l_return_status := FND_API.G_RET_STS_ERROR;
203 END IF;
204 
205 IF p_control_rec.caller_type <> 'FORM'
206 THEN
207 
208     ---------------------------------------------------------------------
209     -- If the Transaction Type is CREATE and the ACD_type is ADD        |
210     -- then check the type of item to which a sub component is being    |
211     -- added. Planning bills cannot have sub comps esgs and also        |
212     -- components which are not Standard cannot have sub comps. This    |
213     --  OR so even if either exists sub comp cannot be added.           |
214     ---------------------------------------------------------------------
215     IF p_sub_component_rec.Transaction_Type = Bom_Globals.G_OPR_CREATE THEN
216 
217         BEGIN
218 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Checking for planning bill or non-std. component . . . '); END IF;
219 
220 	    IF l_rec_bit IN (1, 2, 3, 5)
221 	    THEN
222              l_err_text := 'BOM_SBC_NON_STD_PARENT';
223 	     l_return_status := FND_API.G_RET_STS_ERROR;
224              IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
225 --		dbms_output.put_line
226 --      	('Expected Error. non-standard component . . . ');
227 
228                 Error_Handler.Add_Error_Token
229                 (  x_Mesg_Token_tbl     => l_Mesg_Token_tbl
230                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
231                  , p_message_name       => l_err_text
232                  );
233               END IF;
234 
235 	    END IF;
236 
237 	    IF l_parent_bit = 3 THEN
238 		l_Err_text := 'BOM_SBC_PLANNING_BILL';
239 		l_return_status := FND_API.G_RET_STS_ERROR;
240 
241              IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
242 --                dbms_output.put_line
243 --              ('Expected Error. planning parent. . . ');
244 
245                 Error_Handler.Add_Error_Token
246                 (  x_Mesg_Token_tbl     => l_Mesg_Token_tbl
247                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
248                  , p_message_name       => l_err_text
249                  );
250               END IF;
251 	    END IF;
252 
253             -----------------------------------------------------------------
254             -- If a record is found, then log an error because of the above |
255             -- mentioned comment.                                           |
256             -----------------------------------------------------------------
257 
258         EXCEPTION
259             WHEN NO_DATA_FOUND THEN
260                 NULL; -- Do nothing
261             WHEN OTHERS THEN
262 --                dbms_output.put_line('Unexpected error in Checking Planning Item
263 --                  ' || SQLERRM);
264                 Error_Handler.Add_Error_Token
265 		(  x_Mesg_Token_tbl => l_Mesg_Token_tbl
266 		 , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
267                  , p_message_name  => NULL
268                  , p_message_text  => 'ERROR in Entity validation ' ||
269                         	      substr(SQLERRM, 1, 240) || ' ' ||
270 				      to_char(SQLCODE)
271                  );
272                 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
273         END;
274 
275     END IF;
276 
277     ------------------------------------------------------------------
278     -- When update an ECO that has (a process and Approval Status of |
279     -- 'Approval approved') we should change status to not submitted |
280     -- for Approval                                                  |
281     ------------------------------------------------------------------
282     stmt_num := 2;
283     IF (p_sub_component_rec.Transaction_Type = Bom_Globals.G_OPR_UPDATE OR
284         p_sub_component_rec.Transaction_Type = Bom_Globals.G_OPR_CREATE)
285 	AND
286 	Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_ECO_BO
287     THEN
288        Bom_Globals.Check_Approved_For_Process
289                     ( p_change_notice => p_sub_component_rec.Eco_Name
290                     , p_organization_id => p_Sub_Comp_Unexp_Rec.Organization_Id
291                     , x_processed       =>l_processed
292                     , x_err_text        =>l_err_text
293                         );
294        IF (l_processed) THEN
295             Bom_Globals.Set_Request_For_Approval(
296                 p_change_notice     => p_sub_component_rec.Eco_Name
297                 ,p_organization_id  =>  p_Sub_Comp_Unexp_Rec.Organization_Id
298                 ,x_err_text     => l_err_text);
299        END IF;
300     END IF;
301 
302     -----------------------------------------------------------------------
303     -- Check new substitute component item (for create or update) already |
304     -- exists in MTL_SYSTEM_ITEMS and has the correct item attributes     |
305     -----------------------------------------------------------------------
306 
307     stmt_num := 7;
308     BEGIN
309 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Verify sub. comp. exists in MTL_System_Item with correct attributes . . .'); END IF;
310 
311             SELECT bom_item_type, bom_enabled_flag, eng_item_flag ,tracking_quantity_ind
312             INTO l_sbc_item_type, l_sbc_bom_enabled_flag, l_sbc_eng_item_flag,l_sbc_tracking_qty_ind
313             FROM mtl_system_items
314             WHERE organization_id = p_Sub_Comp_Unexp_Rec.Organization_Id
315             AND inventory_item_id = decode(p_Sub_Comp_Unexp_Rec.new_substitute_component_id,
316                               		NULL,
317                               		p_Sub_Comp_Unexp_Rec.substitute_component_id,
318                               		FND_API.G_MISS_NUM,
319                               		p_Sub_Comp_Unexp_Rec.substitute_component_id,
320                               		p_Sub_Comp_Unexp_Rec.new_substitute_component_id
321                               		);
322 
323 
324 	    IF l_sbc_item_type <> 4 THEN
325 	        IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
326             		Error_Handler.Add_Error_Token
327                         (  x_Mesg_Token_tbl => l_Mesg_Token_Tbl
328                          , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
329                          , p_message_name   => 'BOM_SUB_COMP_NOT_STD'
330                          );
331 		END IF;
332 		l_return_status := FND_API.G_RET_STS_ERROR;
333              END IF;
334                  /* Validations for OPM Convergence Project
335                     Dual UOM controlled items should not be allowed*/
336 
337                IF (l_sbc_tracking_qty_ind='Y' )THEN
338                         Error_Handler.Add_Error_Token
339                         (  p_Message_name       => 'BOM_DUAL_UOM_ITEMS'
340                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
341                          , x_mesg_token_tbl     => l_mesg_token_tbl
342                          );
343                          l_return_status := FND_API.G_RET_STS_ERROR;
344                 END IF;
345 
346 	/* IF l_sbc_bom_enabled_flag <> 'Y'
347 	THEN
348                 IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
349 			l_token_tbl(1).token_name  := 'SUBSTITUTE_ITEM_NAME';
350 			l_token_tbl(1).token_value :=
351 				p_sub_component_rec.substitute_component_name;
352                         Error_Handler.Add_Error_Token
353                         (  x_Mesg_Token_tbl => l_Mesg_Token_Tbl
354                          , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
355                          , p_message_name   => 'BOM_SUB_COMP_NOT_BOM_ENABLED'
356 			 , p_token_tbl	    => l_token_tbl
357                          );
358                 END IF;
359 		l_return_status := FND_API.G_RET_STS_ERROR;
360 	END IF; */ -- Commented as part of bug 3420657.
361 
362 --	IF ((l_rec_AST = 2) OR (l_rec_AST = 1 AND l_sbc_eng_item_flag = 'Y')) -- Bug No: 3561608
363 	IF (l_rec_AST = 1 AND l_sbc_eng_item_flag = 'Y')
364 	THEN
365                IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
366                         Error_Handler.Add_Error_Token
367                         (  x_Mesg_Token_tbl => l_Mesg_Token_Tbl
368                          , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
369                          , p_message_name   => 'BOM_SUB_COMP_ASSEMBLY_MFG'
370                          );
371                 END IF;
372                 l_return_status := FND_API.G_RET_STS_ERROR;
373 	END IF;
374 
375     EXCEPTION
376         WHEN no_data_found THEN
377 		NULL;
378     END;
379 
380 END IF; -- end of code that executes if caller is not ECO form.
381 
382     -------------------------------------------------------------------
383     -- If bill is a Common for other bills, then make sure Substitute |
384     --  Component Item exists in those orgs                           |
385     -------------------------------------------------------------------
386     stmt_num := 8;
387     BEGIN
388 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Verfying component for other common orgs . . . '); END IF;
389 
390             SELECT 1
391             INTO l_dummy
392             FROM bom_bill_of_materials bbom
393             WHERE rownum =1
394             AND bbom.common_bill_sequence_id = l_rec_BSI
395             AND bbom.organization_id <> bbom.common_organization_id
396             AND not exists
397                 (SELECT null
398                  FROM mtl_system_items msi
399                  WHERE msi.organization_id = bbom.organization_id
400                  AND msi.inventory_item_id =
401                        decode(p_Sub_Comp_Unexp_Rec.new_substitute_component_id,
402                               NULL,
403                               p_Sub_Comp_Unexp_Rec.substitute_component_id,
404                               FND_API.G_MISS_NUM,
405                               p_Sub_Comp_Unexp_Rec.substitute_component_id,
406                               p_Sub_Comp_Unexp_Rec.new_substitute_component_id
407                               )
408              	 AND msi.bom_enabled_flag = 'Y'
409              	 AND msi.bom_item_type = 4
410              	 AND (bbom.assembly_type = 2 OR
411                  	(bbom.assembly_type = 1 AND msi.eng_item_flag = 'N')));
412 
413              IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
414 		l_token_tbl.DELETE;
415 		l_Token_tbl(1).token_name := 'SUBSTITUTE_ITEM_NAME';
416 		l_token_tbl(1).token_value :=
417 		  p_sub_component_rec.substitute_component_name;
418                 Error_Handler.Add_Error_Token
419 		(  x_Mesg_Token_tbl 	=> l_Mesg_Token_tbl
420 		 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
421                  , p_message_name  	=> 'BOM_SBC_COMBILL_DOES_NOT_EXIST'
422                  , p_token_tbl	=> l_token_tbl
423 		);
424              END IF;
425                 l_return_status := FND_API.G_RET_STS_ERROR;
426     EXCEPTION
427         WHEN no_data_found THEN
428             null;
429     END;
430 
431 IF p_control_rec.caller_type <> 'FORM'
432 THEN
433 
434     ---------------------------------------------------------
435     -- Verify sub comp is not the same as bill or component |
436     ---------------------------------------------------------
437     stmt_num := 9;
438 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Verifying sub. comp not same as parent . . . '); END IF;
439 
440     IF (p_Sub_Component_Rec.Transaction_Type = Bom_Globals.G_OPR_UPDATE AND
441         p_Sub_Comp_Unexp_Rec.New_Substitute_Component_Id IN
442        (l_rec_AII, l_rec_CII))
443        OR
444        (p_Sub_Component_Rec.Transaction_Type = Bom_Globals.G_OPR_CREATE AND
445         p_Sub_Comp_Unexp_Rec.Substitute_Component_Id IN
446        (l_rec_AII,l_rec_CII))
447     THEN
448         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
449             Error_Handler.Add_Error_Token
450 	    (  x_Mesg_Token_tbl	=> l_Mesg_Token_tbl
451 	     , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
452              , p_message_name  	=> 'BOM_SUBCOMP_SAMEAS_ITEM_COMP'
453              , p_token_tbl	=> l_token_tbl
454 	     );
455         END IF;
456         l_return_status := FND_API.G_RET_STS_ERROR;
457     END IF;
458 
459     ------------------------------------------
460     --  Validate attribute dependencies here.|
461     ------------------------------------------
462     -----------------------------------------
463     -- substitute quantity couldn't be zero |
464     -----------------------------------------
465 
466     stmt_num := 10;
467     -----------------------------------------------------------------------
468     -- If parent component acd_type is disabled, we can't do anything for |
469     -- child component.                                                   |
470     -----------------------------------------------------------------------
471     stmt_num := 11;
472 	--
473 	-- Peform this set of validations only if the ECO BO is calling the
474 	-- validation package
475 	--
476 	IF Bom_Globals.Get_Bo_Identifier = Bom_Globals.G_ECO_BO
477 	THEN
478         IF l_parent_acd_type = 3 THEN
479             l_return_status := FND_API.G_RET_STS_ERROR;
480             IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR) THEN
481                 Error_Handler.Add_Error_Token
482 		(  x_Mesg_Token_tbl	=> l_Mesg_Token_tbl
483 		 , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
484                  , p_message_name	=> 'BOM_SBC_COMP_ACD_TYPE_DISABLE'
485                  );
486             END IF;
487         END IF;
488 
489     -------------------------------------------------------------------
490     -- if parent's acd_type is add, child acd_type should also be add |
491     -------------------------------------------------------------------
492     stmt_num := 12;
493         IF ((l_parent_acd_type = 1 )  and ( p_Sub_Component_Rec.ACD_Type <> 1))
494 	THEN
495             l_return_status := FND_API.G_RET_STS_ERROR;
496             l_token_tbl(1).token_name  := 'REVISED_COMPONENT_NAME';
497             l_token_tbl(1).token_value := p_sub_component_rec.component_item_name;
498             Error_Handler.Add_Error_Token
499 	    (  x_Mesg_Token_tbl => l_Mesg_Token_tbl
500 	     , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
501              , p_message_name  => 'BOM_SBC_ACD_NOT_COMPATIBLE'
502 	     , p_token_tbl	=> l_token_tbl
503              );
504         END IF;
505 
506     ------------------------------------------------------------------------
507     -- if acd_type is disable, sub comp must belong to revisd comp already |
508     -- if acd_type is not disable, sub comp must be unique for that        |
509     -- revised component                                                   |
510     ------------------------------------------------------------------------
511     stmt_num := 13;
512 /*
513     IF p_sub_component_rec.acd_type <> 3
514        AND ( p_Sub_Component_Rec.Transaction_Type = Bom_Globals.G_OPR_CREATE OR
515              p_Sub_Component_Rec.Transaction_Type = Bom_Globals.G_OPR_UPDATE
516 	    )
517     THEN
518 
519 
520         l_sub_comp_unique:= Verify_Unique_Substitute(	p_sub_component_rec
521                                 		     ,	p_sub_comp_Unexp_rec
522 						     );
523 
524     END IF;
525 
526 */
527 
528     stmt_num := 14;
529     -------------------------------------------------------------------------
530     -- if acd_type is disable, sub comp must belong to revised comp already |
531     -------------------------------------------------------------------------
532 
533     IF p_sub_component_rec.acd_type = 3 THEN
534         BEGIN
535 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Verifying if component is not disable type  . . . '); END IF;
536 
537 	    SELECT count(*)
538 	      INTO l_dummy
539               FROM bom_substitute_components sub_comp,
540 		   bom_inventory_components  rev_comp
541 	     WHERE rev_comp.component_sequence_id =
542 		   	p_Sub_Comp_Unexp_Rec.Component_Sequence_Id
543 	       AND sub_comp.component_sequence_id =
544 			rev_comp.old_component_Sequence_id
545 	       AND sub_comp.Substitute_Component_Id =
546 				p_Sub_Comp_Unexp_Rec.Substitute_Component_Id;
547 
548             IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug
549                         ( 'Sub Components found: ' || l_dummy);
550             END IF;
551 
552               IF (l_dummy = 0)
553 	      THEN
554 		l_token_tbl(1).token_name  := 'SUBSTITUTE_ITEM_NAME';
555 		l_token_tbl(1).token_value :=
556 				p_sub_component_rec.substitute_component_name;
557 		l_token_tbl(2).token_name  := 'REVISED_COMPONENT_NAME';
558 		l_token_tbl(2).token_value :=
559 				p_sub_component_rec.component_item_name;
560                 Error_Handler.Add_Error_Token
561 		(  x_Mesg_Token_tbl => l_Mesg_Token_tbl
562 		 , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
563                  , p_message_name   => 'BOM_DISABLE_SCOMP_NOT_FOUND'
564 		 , p_token_tbl	    => l_token_tbl
565                  );
566             	l_return_status := FND_API.G_RET_STS_ERROR;
567 	      END IF;
568          END;
569     END IF;
570     END IF; -- ECO BO only validations ends
571 
572 END IF; -- end of code that executes when ECO form has not called package.
573 
574 --    dbms_output.put_line('l_return_status : '|| l_return_status);
575 
576     IF ( l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) then
577         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
578     END IF;
579 
580     ----------------------------
581     --  Done validating entity |
582     ----------------------------
583 
584     x_return_status := l_return_status;
585     x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
586 
587 /* When the Substitute component is updated with new Substitute Component, It should be checked that the
588 New Substitute Component does not exists already */
589 
590      IF ( p_Sub_Comp_Unexp_Rec.new_substitute_component_id is not null
591          and  p_Sub_Comp_Unexp_Rec.new_substitute_component_id <> FND_API.G_MISS_NUM
592             and p_sub_component_rec.transaction_type = Bom_Globals.G_OPR_UPDATE) THEN
593 
594         select count(*) into l_temp_var
595           FROM    BOM_SUBSTITUTE_COMPONENTS
596           WHERE   substitute_component_id = p_Sub_Comp_Unexp_Rec.new_substitute_component_id
597           AND     COMPONENT_SEQUENCE_ID = p_Sub_Comp_Unexp_Rec.component_sequence_id
598           AND     NVL(DECODE(ACD_TYPE, FND_API.G_MISS_NUM, null, acd_type), 0) =
599           NVL(DECODE(p_sub_component_rec.acd_type, FND_API.G_MISS_NUM, null, p_sub_component_rec.acd_type), 0) ;
600 
601         IF (l_temp_var <>0) then
602 
603                 l_Token_Tbl(1).Token_Name  := 'SUBSTITUTE_ITEM_NAME';
604                 l_Token_Tbl(1).Token_Value :=
605                         p_sub_component_rec.new_substitute_component_name;
606                 l_token_tbl(2).token_name  := 'REVISED_COMPONENT_NAME';
607                 l_token_tbl(2).token_value := p_sub_component_rec.component_item_name;
608 
609                 Error_Handler.Add_Error_Token
610                 (  x_Mesg_token_tbl => l_Mesg_Token_Tbl
611                  , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
612                  , p_message_name  => 'BOM_SUB_COMP_ALREADY_EXISTS'
613                  , p_token_tbl     => l_token_tbl
614                  );
615           RAISE FND_API.G_EXC_ERROR;
616         END IF;
617     END IF;
618 
619 IF Bom_Globals.Get_Debug = 'Y' THEN Error_Handler.Write_Debug('Verified New Substitute Component ...'); END IF;
620 
621 
622 
623 EXCEPTION
624     WHEN FND_API.G_EXC_ERROR THEN
625 --        dbms_output.put_line('expected Error : stmt_num  -'
626 --          || to_char(stmt_num));
627 	x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
628         x_return_status := FND_API.G_RET_STS_ERROR;
629     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
630 	x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
631         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
632 --        dbms_output.put_line('unexpected Error : stmt_num  -'
633 --          || to_char(stmt_num));
634     WHEN OTHERS THEN
635 	x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
636         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
637 --        dbms_output.put_line('other unexpected Error :
638 --          stmt_num  -' || to_char(stmt_num));
639         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
640         THEN
641 	    l_err_text := G_PKG_NAME ||
642                 'Validation (Substitute Component Entity)' ||
643                 SUBSTR(SQLERRM, 1, 100);
644             Error_Handler.Add_Error_Token(  x_Mesg_Token_tbl => x_Mesg_Token_tbl
645 					, p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
646                                         , p_message_name  => NULL
647                                         , p_message_text  => l_err_text
648                                         );
649 
650         END IF;
651 END Check_Entity;
652 
653 
654 /*******************************************************************
655 * Procedure     : Check_Attributes
656 * Parameter IN  : Substitute Component Record
657 * Parameter IN OUT NOCOPY : Return_Status - Indicating status of the process.
658 *                 Mesg_Token_Tbl - Table of Errors and their tokens
659 *
660 * Purpose       : Procedure Attributes will verify the validity of
661 *                 all exposed columns to check if the user has given
662 *		  values that the columns can actually hold.
663 *********************************************************************/
664 
665 PROCEDURE Check_Attributes
666 (   x_return_status             IN OUT NOCOPY VARCHAR2
667 ,   x_Mesg_Token_tbl		IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
668 ,   p_sub_component_rec         IN  Bom_Bo_Pub.Sub_Component_Rec_Type
669 ,   p_Sub_Comp_Unexp_Rec	    IN  Bom_Bo_Pub.Sub_Comp_Unexposed_Rec_Type
670 )
671 IS
672 l_dummy         VARCHAR2(1);
673 l_return_status VARCHAR2(1);
674 l_err_text      VARCHAR2(255);
675 l_token_tbl	Error_Handler.Token_Tbl_Type;
676 l_Mesg_Token_Tbl Error_Handler.Mesg_Token_Tbl_Type;
677 BEGIN
678 
679     l_return_status := FND_API.G_RET_STS_SUCCESS;
680 
681     /**************************************************************************
682 		With patch to bug 728002, this is not valid now
683 
684     IF p_sub_component_rec.substitute_item_quantity IS NOT NULL AND
685        p_sub_component_rec.substitute_item_quantity = 0
686     THEN
687 	IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
688         THEN
689 		l_token_tbl(1).token_name  := 'SUBSITUTE_ITEM_NAME';
690 		l_token_tbl(1).token_value :=
691 			p_sub_component_rec.substitute_component_name;
692                 Error_Handler.Add_Error_Token
693 		(  x_Mesg_Token_tbl   => x_Mesg_Token_tbl
694                  , p_message_name     => 'BOM_SUB_COMP_QTY_ZERO'
695 		 , p_token_tbl	      => l_token_tbl
696 		);
697         END IF;
698         x_return_status := FND_API.G_RET_STS_ERROR;
699 
700     END IF;
701     **************************************************************************/
702 
703     -- Validation specific to enforce integer requirements
704 
705     IF p_sub_comp_unexp_rec.enforce_int_requirements_code = 1 /* If the enforce int req is 'Up' */
706     THEN
707 
708       BEGIN
709                 /* Enforce_Integer can be UP only if the component item's rounding control type allows
710                    to round order quantities */
711 
712            SELECT 'x' INTO l_dummy FROM mtl_system_items WHERE
713             inventory_item_id = p_sub_comp_unexp_rec.component_item_id
714             AND organization_id = p_sub_comp_unexp_rec.organization_id
715             AND rounding_control_type = 1;
716 
717            EXCEPTION WHEN NO_DATA_FOUND THEN
718                 Error_Handler.Add_Error_Token
719                 (  p_Message_Name       => 'BOM_ENFORCE_INT_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                 l_return_status := FND_API.G_RET_STS_ERROR;
725 
726            WHEN OTHERS THEN
727 
728                         Error_Handler.Add_Error_Token
729                         (  p_Message_Name       => NULL
730                          , p_Message_Text       =>
731                                         'Error in Subs.Comp Attr. Validation '
732                                            || SUBSTR(SQLERRM, 1, 30) || ' ' ||
733                                            to_char(SQLCODE)
734                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
735                          , p_Mesg_Token_Tbl     => l_Mesg_token_Tbl
736                         );
737                         l_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
738          END;
739 
740 	 x_return_status := l_return_status;
741 	 x_mesg_token_tbl := l_mesg_token_tbl;
742 
743     END IF;
744 
745 END Check_Attributes;
746 
747 /*******************************************************************
748 * Procedure     : Check_Entity_Delete
749 * Parameter IN  : Substitute Component Record
750 *                 Substitute component Record of Unexposed Columns
751 * Parameter OUT : Return_Status - Indicating status of the process.
752 *                 Mesg_Token_Tbl - Table of Errors and their tokens
753 *
754 * Purpose       : Entity_Delete procedure will verify if the record
755 *                 can be delete without violating any dependency rules
756 *********************************************************************/
757 
758 PROCEDURE Check_Entity_Delete
759 (   x_return_status                 IN OUT NOCOPY VARCHAR2
760 ,   x_Mesg_Token_Tbl		    IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
761 ,   p_sub_component_rec             IN  Bom_Bo_Pub.Sub_Component_Rec_Type
762 ,   p_Sub_Comp_Unexp_Rec	    IN  Bom_Bo_Pub.Sub_Comp_Unexposed_Rec_Type
763 )
764 IS
765 l_return_status               VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
766 l_err_text                    VARCHAR2(255);
767 l_rec_ID            DATE := NULL;
768 l_Mesg_Token_Tbl	Error_Handler.Mesg_Token_Tbl_Type;
769 BEGIN
770 
771     --  Validate entity delete.
772     x_return_status := l_return_status;
773 
774 END Check_Entity_Delete;
775 
776 /**************************************************************************
777 * Procedure	: Check_Existence
778 * Parameters IN	: Substitute Component exposed column record
779 *		  Substitute Component unexposed column record
780 * Parameters OUT: Old Substitute Component exposed column record
781 *		  Old substitute component unexposed column record
782 *		  Return status
783 *		  Mesg Token Table
784 * Purpose	: This procedure will verify if the user given record exists
785 *		  when the operation is Update/Delete and does not exist when
786 *		  the operation is Create. If the operation is Update/Delete
787 *		  the procedure will query the existing record and return them
788 *		  as old records.
789 ***************************************************************************/
790 PROCEDURE Check_Existence
791 (  p_sub_component_rec          IN  Bom_Bo_Pub.Sub_Component_Rec_Type
792  , p_sub_comp_unexp_rec         IN  Bom_Bo_Pub.Sub_Comp_Unexposed_Rec_Type
793  , x_old_sub_component_rec      IN OUT NOCOPY Bom_Bo_Pub.Sub_Component_Rec_Type
794  , x_old_sub_comp_unexp_rec     IN OUT NOCOPY Bom_Bo_Pub.Sub_Comp_Unexposed_Rec_Type
795  , x_Mesg_Token_Tbl             IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
796  , x_Return_Status              IN OUT NOCOPY VARCHAR2
797 )
798 IS
799         l_token_tbl      Error_Handler.Token_Tbl_Type;
800         l_Mesg_Token_Tbl Error_Handler.Mesg_Token_Tbl_Type;
801         l_return_status  VARCHAR2(1);
802 BEGIN
803         l_Token_Tbl(1).Token_Name  := 'SUBSTITUTE_ITEM_NAME';
804         l_Token_Tbl(1).Token_Value :=
805 				p_sub_component_rec.substitute_component_name;
806 	l_token_tbl(2).token_name  := 'REVISED_COMPONENT_NAME';
807 	l_token_tbl(2).token_value :=
808 				p_sub_component_rec.component_item_name;
809 
810         Error_Handler.Write_Debug('In SCOMP Check Exist before query row...'||p_sub_component_rec.transaction_type);
811         BOM_Sub_Component_Util.Query_Row
812 	(   p_substitute_component_id	=>
813 				p_sub_comp_unexp_rec.substitute_component_id
814 	,   p_component_sequence_id	=>
815 				p_sub_comp_unexp_rec.component_sequence_id
816 	,   p_acd_type			=>
817 				p_sub_component_rec.acd_type
818 	,   x_Sub_Component_Rec		=> x_old_sub_component_rec
819 	,   x_Sub_Comp_Unexp_Rec	=> x_old_sub_comp_unexp_rec
820 	,   x_return_status		=> l_return_status
821 	);
822 
823         IF p_sub_component_rec.transaction_type IS NULL THEN
824           Error_Handler.Write_Debug ('In SCOMP Check Exist ...is NULL');
825         ELSIF p_sub_component_rec.transaction_type = FND_API.G_MISS_CHAR THEN
826           Error_Handler.Write_Debug ('In SCOMP Check Exist ...is MISSING');
827         ELSE
828           Error_Handler.Write_Debug('In SCOMP Check Exist...'||p_sub_component_rec.transaction_type);
829         END IF;
830 
831         IF l_return_status = Bom_Globals.G_RECORD_FOUND AND
832            p_sub_component_rec.transaction_type = Bom_Globals.G_OPR_CREATE
833         THEN
834                 Error_Handler.Add_Error_Token
835                 (  x_Mesg_token_tbl => l_Mesg_Token_Tbl
836                  , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
837                  , p_message_name  => 'BOM_SUB_COMP_ALREADY_EXISTS'
838                  , p_token_tbl     => l_token_tbl
839                  );
840                  l_return_status := FND_API.G_RET_STS_ERROR;
841         ELSIF l_return_status = Bom_Globals.G_RECORD_NOT_FOUND AND
842               p_sub_component_rec.transaction_type IN
843                 (Bom_Globals.G_OPR_UPDATE, Bom_Globals.G_OPR_DELETE)
844         THEN
845                 Error_Handler.Add_Error_Token
846                 (  x_Mesg_token_tbl => l_Mesg_Token_Tbl
847                  , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
848                  , p_message_name  => 'BOM_SUB_COMP_DOESNOT_EXIST'
849                  , p_token_tbl     => l_token_tbl
850                  );
851                  l_return_status := FND_API.G_RET_STS_ERROR;
852         ELSIF l_Return_status = FND_API.G_RET_STS_UNEXP_ERROR
853         THEN
854                 Error_Handler.Add_Error_Token
855                 (  x_Mesg_token_tbl     => l_Mesg_Token_Tbl
856                  , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
857                  , p_message_name       => NULL
858                  , p_message_text       =>
859                    'Unexpected error while existence verification of ' ||
860                    'Substitute component '||
861                    p_sub_component_rec.substitute_component_name
862                  , p_token_tbl          => l_token_tbl
863                  );
864         ELSE
865 
866                  /* Assign the relevant transaction type for SYNC operations */
867 
868                  IF p_sub_component_rec.transaction_type = 'SYNC' THEN
869                    IF l_return_status = Bom_Globals.G_RECORD_FOUND THEN
870                      x_old_sub_component_rec.transaction_type :=
871                                                    Bom_Globals.G_OPR_UPDATE;
872                    ELSE
873                      x_old_sub_component_rec.transaction_type :=
874                                                    Bom_Globals.G_OPR_CREATE;
875                    END IF;
876                  END IF;
877                  l_return_status := FND_API.G_RET_STS_SUCCESS;
878         END IF;
879 
880         x_return_status := l_return_status;
881         x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
882 
883 END Check_Existence;
884 
885 /****************************************************************************
886 * Procedure	: Check_Lineage
887 * Parameters IN	: Substitute Component exposed column record
888 *		  Substitute Component unexposed column record
889 * Parameters OUT: Mesg Token Table
890 *		  Return Status
891 * Purpose	: Procedure will verify that the parent-child relationship
892 *		  hold good in the production tables based on the data that
893 *	    	  the user has given.
894 *****************************************************************************/
895 PROCEDURE Check_Lineage
896 (  p_sub_component_rec          IN  Bom_Bo_Pub.Sub_Component_Rec_Type
897  , p_sub_comp_unexp_rec         IN  Bom_Bo_Pub.Sub_Comp_Unexposed_Rec_Type
898  , x_Mesg_Token_Tbl             IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
899  , x_Return_Status              IN OUT NOCOPY VARCHAR2
900 )
901 IS
902         l_token_tbl             Error_Handler.Token_Tbl_Type;
903         l_Mesg_Token_Tbl        Error_Handler.Mesg_Token_Tbl_Type;
904 
905         CURSOR c_GetComponent IS
906         SELECT revised_item_sequence_id
907           FROM bom_inventory_components
908          WHERE component_item_id = p_sub_comp_unexp_rec.component_item_id
909            AND operation_seq_num = p_sub_component_rec.operation_sequence_number
910            AND effectivity_date  = p_sub_component_rec.start_effective_date
911            AND bill_sequence_id  = p_sub_comp_unexp_rec.bill_sequence_id;
912 BEGIN
913         x_return_status := FND_API.G_RET_STS_SUCCESS;
914 
915         FOR Component IN c_GetComponent LOOP
916                 IF NVL(Component.revised_item_sequence_id, 0) <>
917                         NVL(p_sub_comp_unexp_rec.revised_item_sequence_id, 0)
918                 THEN
919                                 l_Token_Tbl(1).token_name  :=
920 					'REVISED_COMPONENT_NAME';
921                                 l_Token_Tbl(1).token_value :=
922                                      p_sub_component_rec.component_item_name;
923                                 l_Token_Tbl(2).token_name  :=
924 					'REVISED_ITEM_NAME';
925                                 l_Token_Tbl(2).token_value :=
926                                      p_sub_component_rec.revised_item_name;
927 				l_Token_tbl(3).token_name  :=
928 					'SUBSTITUTE_ITEM_NAME';
929 				l_token_tbl(3).token_value :=
930 				  p_sub_component_rec.substitute_component_name;
931 
932                                 Error_Handler.Add_Error_Token
933                                 (  p_Message_Name => 'BOM_SBC_REV_ITEM_MISMATCH'
934                                  , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
935                                  , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
936                                  , p_Token_Tbl      => l_Token_Tbl
937                                  );
938                                 x_return_status := FND_API.G_RET_STS_ERROR;
939                 END IF;
940         END LOOP;
941 
942 	x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
943 
944 END CHECK_LINEAGE;
945 
946 /****************************************************************************
947 * Procedure	: Check_Access
948 * Parameters IN	: Substitute Component exposed column record
949 *		  Substitute Component unexposed column record
950 * Prameters OUT : Mesg Token Table
951 *		  Return Status
952 * Purpose	: If the System Information record values are not already filled
953 *		  the process will query the appropriate profile values and
954 *		  verify that the user has access to the Revised Item, the
955 *		  parent component item and the item type of the substitute
956 *		  Component. It will also verify that the revised item is not
957 *		  already implemented or canceled.
958 ****************************************************************************/
959 PROCEDURE Check_Access
960 (  p_sub_component_rec          IN  Bom_Bo_Pub.Sub_Component_Rec_Type
961  , p_sub_comp_unexp_rec         IN  Bom_Bo_Pub.Sub_Comp_Unexposed_Rec_Type
962  , x_Mesg_Token_Tbl             IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
963  , x_Return_Status              IN OUT NOCOPY VARCHAR2
964 )
965 IS
966         l_OPM_org 		VARCHAR2(1);
967         l_Mesg_Token_Tbl        Error_Handler.Mesg_Token_Tbl_Type;
968         l_Token_Tbl             Error_Handler.Token_Tbl_Type;
969         l_Return_Status         VARCHAR2(1);
970 	CURSOR c_GetSubCompType IS
971 	SELECT bom_item_type
972 	  FROM mtl_system_items
973 	 WHERE inventory_item_id = p_sub_comp_unexp_rec.substitute_component_id
974 	   AND organization_id   = p_sub_comp_unexp_rec.organization_id;
975 
976 BEGIN
977         l_return_status := FND_API.G_RET_STS_SUCCESS;
978 
979                  SELECT process_enabled_flag
980                    INTO  l_OPM_org
981                    FROM mtl_parameters
982                   WHERE  organization_id   = p_sub_comp_unexp_rec.organization_id;
983 
984 
985 	FOR SubCompType IN c_GetSubCompType
986 	LOOP
987 
988                  /* Validations for OPM Convergence Project
989                     Model/Option class items are not allowed in OPM organizations*/
990 
991                 IF (l_OPM_org='Y' and SubCompType.bom_item_type in ( Bom_Globals.G_MODEL, Bom_Globals.G_OPTION_CLASS))THEN
992                          Error_Handler.Add_Error_Token
993                          (  p_Message_name       => 'BOM_OPM_ORG_MODEL_OC'
994                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
995                           , x_mesg_token_tbl     => l_mesg_token_tbl
996                           );
997                          l_return_status := FND_API.G_RET_STS_ERROR;
998 		ELSIF SubCompType.bom_item_type = Bom_Globals.G_PRODUCT_FAMILY
999 		THEN
1000 			Error_Handler.Add_Error_Token
1001 			(  p_Message_Name	=> 'BOM_SUB_COMP_PF'
1002 			 , p_mesg_token_tbl	=> l_mesg_token_tbl
1003 			 , x_mesg_token_tbl	=> l_mesg_token_tbl
1004 			 , p_token_tbl		=> l_token_tbl
1005 			);
1006 			l_return_status := FND_API.G_RET_STS_ERROR;
1007 		ELSIF SubCompType.bom_item_type NOT IN
1008 		      (NVL(Bom_Globals.Get_MDL_Item_Access,0),
1009             	       NVL(Bom_Globals.Get_OC_Item_Access,0),
1010             	       NVL(Bom_Globals.Get_PLN_Item_Access,0),
1011             	       NVL(Bom_Globals.Get_STD_Item_Access,0)
1012            	       )
1013         	THEN
1014                 	l_token_tbl(1).token_name  := 'REV_COMP';
1015                 	l_token_tbl(1).token_value :=
1016 				p_sub_component_rec.substitute_component_name;
1017                		l_token_tbl(2).token_name  := 'BOM_ITEM_TYPE';
1018                 	l_token_tbl(2).translate   := TRUE;
1019 
1020                 	IF SubCompType.bom_item_type = 1
1021                 	THEN
1022                       		l_Token_Tbl(2).Token_Value := 'BOM_MODEL';
1023                 	ELSIF SubCompType.bom_item_type = 2
1024                 	THEN
1025                       		l_Token_Tbl(2).Token_Value:='BOM_OPTION_CLASS';
1026                 	ELSIF SubCompType.bom_item_type = 3
1027                 	THEN
1028                       		l_Token_Tbl(2).Token_Value := 'BOM_PLANNING';
1029                 	ELSIF SubCompType.bom_item_type = 4
1030                 	THEN
1031                       		l_Token_Tbl(2).Token_Value := 'BOM_STANDARD';
1032                 	END IF;
1033 
1034                 	Error_Handler.Add_Error_Token
1035                 	(  p_Message_Name       => 'BOM_SUB_COMP_ACCESS_DENIED'
1036                  	 , p_Mesg_Token_Tbl     => l_mesg_token_tbl
1037                 	 , x_Mesg_Token_Tbl     => l_mesg_token_tbl
1038                  	 , p_Token_Tbl          => l_token_tbl
1039                  	 );
1040                  	l_token_tbl.DELETE(2);
1041                  	l_return_status := FND_API.G_RET_STS_ERROR;
1042 		END IF;
1043 	END LOOP;
1044         x_return_status := l_return_status;
1045 
1046         x_Mesg_Token_Tbl := l_Mesg_Token_Tbl;
1047 END Check_Access;
1048 
1049 /*
1050 ** Procedures for BOM Business Object
1051 */
1052 PROCEDURE Check_Required
1053 (  x_return_status              IN OUT NOCOPY VARCHAR2
1054  , p_bom_sub_component_rec      IN  Bom_Bo_Pub.Bom_Sub_Component_Rec_Type
1055  , x_Mesg_Token_tbl             IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
1056  )
1057 IS
1058 	l_sub_component_rec	Bom_Bo_Pub.Sub_Component_Rec_Type;
1059 	l_sub_comp_unexp_rec	Bom_Bo_Pub.Sub_Comp_Unexposed_Rec_Type;
1060 BEGIN
1061 	--
1062 	-- Convert the BOM Record
1063 	--
1064 	Bom_Bo_Pub.Convert_BomSComp_To_EcoSComp
1065 	(  p_bom_sub_component_rec	=> p_bom_sub_component_rec
1066 	 , x_sub_component_rec		=> l_sub_component_rec
1067 	 , x_sub_comp_unexp_rec		=> l_sub_comp_unexp_rec
1068 	);
1069 
1070 	--
1071 	-- Call Check Required.
1072 	--
1073 
1074 	Check_Required
1075 	(  p_sub_component_rec	=> l_sub_component_rec
1076 	 , x_return_Status	=> x_return_status
1077 	 , x_mesg_token_tbl	=> x_mesg_token_tbl
1078 	 );
1079 
1080 END Check_Required;
1081 
1082 --  Procedure Entity
1083 
1084 PROCEDURE Check_Entity
1085 (   x_return_status                 IN OUT NOCOPY VARCHAR2
1086 ,   x_Mesg_Token_Tbl                IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
1087 ,   p_bom_sub_component_rec         IN  Bom_Bo_Pub.Bom_Sub_Component_Rec_Type
1088 ,   p_bom_Sub_Comp_Unexp_Rec        IN  Bom_Bo_Pub.Bom_Sub_Comp_Unexp_Rec_Type
1089 )
1090 IS
1091         l_sub_component_rec     Bom_Bo_Pub.Sub_Component_Rec_Type;
1092         l_sub_comp_unexp_rec    Bom_Bo_Pub.Sub_Comp_Unexposed_Rec_Type;
1093 BEGIN
1094         --
1095         -- Convert the BOM Record
1096         --
1097         Bom_Bo_Pub.Convert_BomSComp_To_EcoSComp
1098         (  p_bom_sub_component_rec      => p_bom_sub_component_rec
1099          , p_bom_sub_comp_unexp_rec     => p_bom_sub_comp_unexp_rec
1100          , x_sub_component_rec          => l_sub_component_rec
1101          , x_sub_comp_unexp_rec         => l_sub_comp_unexp_rec
1102         );
1103 
1104         --
1105         -- Call Check Entity.
1106         --
1107 	Check_Entity
1108 	(  p_sub_component_rec		=> l_sub_component_rec
1109 	 , p_sub_comp_unexp_rec		=> l_sub_comp_unexp_rec
1110 	 , x_return_status		=> x_return_status
1111 	 , x_mesg_token_tbl		=> x_mesg_token_tbl
1112 	 );
1113 
1114 END Check_Entity;
1115 
1116 --  Procedure Attributes
1117 
1118 PROCEDURE Check_Attributes
1119 (   x_return_status                 IN OUT NOCOPY VARCHAR2
1120 ,   x_Mesg_Token_Tbl                IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
1121 ,   p_bom_sub_component_rec          IN  Bom_Bo_Pub.Bom_Sub_Component_Rec_Type
1122 ,   p_bom_Sub_Comp_Unexp_Rec	    IN  Bom_Bo_Pub.Bom_Sub_Comp_Unexp_Rec_Type
1123 )
1124 IS
1125         l_sub_component_rec     Bom_Bo_Pub.Sub_Component_Rec_Type;
1126         l_sub_comp_unexp_rec    Bom_Bo_Pub.Sub_Comp_Unexposed_Rec_Type;
1127 BEGIN
1128 
1129         --
1130         -- Convert the BOM Record
1131         --
1132         Bom_Bo_Pub.Convert_BomSComp_To_EcoSComp
1133         (  p_bom_sub_component_rec      => p_bom_sub_component_rec
1134          , p_bom_sub_comp_unexp_rec     => p_bom_sub_comp_unexp_rec
1135          , x_sub_component_rec          => l_sub_component_rec
1136          , x_sub_comp_unexp_rec         => l_sub_comp_unexp_rec
1137         );
1138 
1139 
1140 	-- Call Check Attributes
1141 
1142 	Check_Attributes
1143 	(  p_sub_component_rec		=> l_sub_component_rec
1144 	 , p_sub_comp_unexp_rec		=> l_sub_comp_unexp_rec
1145 	 , x_return_Status		=> x_return_Status
1146 	 , x_mesg_token_tbl		=> x_mesg_token_tbl
1147 	 );
1148 END Check_Attributes;
1149 
1150 --  Procedure Entity_Delete
1151 
1152 PROCEDURE Check_Entity_Delete
1153 (   x_return_status                 IN OUT NOCOPY VARCHAR2
1154 ,   x_Mesg_Token_Tbl                IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
1155 ,   p_bom_sub_component_rec          IN Bom_Bo_Pub.Bom_Sub_Component_Rec_Type
1156 ,   p_bom_Sub_Comp_Unexp_Rec         IN Bom_Bo_Pub.Bom_Sub_Comp_Unexp_Rec_Type
1157 )
1158 IS
1159         l_sub_component_rec     Bom_Bo_Pub.Sub_Component_Rec_Type;
1160         l_sub_comp_unexp_rec    Bom_Bo_Pub.Sub_Comp_Unexposed_Rec_Type;
1161 BEGIN
1162 
1163         --
1164         -- Convert the BOM Record
1165         --
1166         Bom_Bo_Pub.Convert_BomSComp_To_EcoSComp
1167         (  p_bom_sub_component_rec      => p_bom_sub_component_rec
1168          , x_sub_component_rec          => l_sub_component_rec
1169          , x_sub_comp_unexp_rec         => l_sub_comp_unexp_rec
1170         );
1171 
1172 	-- Call Check Entity Delete
1173 
1174 	Check_Entity_Delete
1175 	(  p_sub_component_rec		=> l_sub_component_rec
1176 	 , p_sub_comp_unexp_rec		=> l_sub_comp_unexp_rec
1177 	 , x_return_status		=> x_return_status
1178 	 , x_mesg_token_tbl		=> x_mesg_token_tbl
1179 	 );
1180 
1181 END Check_Entity_Delete;
1182 
1183 PROCEDURE Check_Existence
1184 (  p_bom_sub_component_rec          IN  Bom_Bo_Pub.Bom_Sub_Component_Rec_Type
1185  , p_bom_sub_comp_unexp_rec         IN  Bom_Bo_Pub.Bom_Sub_Comp_Unexp_Rec_Type
1186  , x_old_bom_sub_component_rec      IN OUT NOCOPY Bom_Bo_Pub.Bom_Sub_Component_Rec_Type
1187  , x_old_bom_sub_comp_unexp_rec     IN OUT NOCOPY Bom_Bo_Pub.Bom_Sub_Comp_Unexp_Rec_Type
1188  , x_Mesg_Token_Tbl                 IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
1189  , x_Return_Status                  IN OUT NOCOPY VARCHAR2
1190 )
1191 IS
1192         l_sub_component_rec     Bom_Bo_Pub.Sub_Component_Rec_Type;
1193         l_sub_comp_unexp_rec    Bom_Bo_Pub.Sub_Comp_Unexposed_Rec_Type;
1194         l_old_sub_component_rec     Bom_Bo_Pub.Sub_Component_Rec_Type;
1195         l_old_sub_comp_unexp_rec    Bom_Bo_Pub.Sub_Comp_Unexposed_Rec_Type;
1196 BEGIN
1197 
1198         --
1199         -- Convert the BOM Record
1200         --
1201         Bom_Bo_Pub.Convert_BomSComp_To_EcoSComp
1202         (  p_bom_sub_component_rec      => p_bom_sub_component_rec
1203 	 , p_bom_sub_comp_unexp_rec	=> p_bom_sub_comp_unexp_rec
1204          , x_sub_component_rec          => l_sub_component_rec
1205          , x_sub_comp_unexp_rec         => l_sub_comp_unexp_rec
1206         );
1207 
1208 	Check_Existence
1209 	(  p_sub_component_rec		=> l_sub_component_rec
1210 	 , p_sub_comp_unexp_rec		=> l_sub_comp_unexp_rec
1211 	 , x_old_sub_component_rec	=> l_old_sub_component_rec
1212 	 , x_old_sub_comp_unexp_rec	=> l_old_sub_comp_unexp_rec
1213 	 , x_return_status		=> x_return_status
1214 	 , x_mesg_token_tbl		=> x_mesg_token_tbl
1215 	 );
1216 
1217 	--
1218 	-- Convert the Old record received from Check Existence
1219 	--
1220 
1221 	Bom_Bo_Pub.Convert_EcoSComp_To_BomSComp
1222 	(  p_sub_component_rec		=> l_old_sub_component_rec
1223 	 , p_sub_comp_unexp_rec		=> l_old_sub_comp_unexp_rec
1224 	 , x_bom_sub_component_rec	=> x_old_bom_sub_component_rec
1225 	 , x_bom_sub_comp_unexp_rec	=> x_old_bom_sub_comp_unexp_rec
1226 	);
1227 
1228 END Check_Existence;
1229 
1230 PROCEDURE Check_Lineage
1231 (  p_bom_sub_component_rec      IN  Bom_Bo_Pub.Bom_Sub_Component_Rec_Type
1232  , p_bom_sub_comp_unexp_rec     IN  Bom_Bo_Pub.Bom_Sub_Comp_Unexp_Rec_Type
1233  , x_Mesg_Token_Tbl             IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
1234  , x_Return_Status              IN OUT NOCOPY VARCHAR2
1235 )
1236 IS
1237         l_sub_component_rec     Bom_Bo_Pub.Sub_Component_Rec_Type;
1238         l_sub_comp_unexp_rec    Bom_Bo_Pub.Sub_Comp_Unexposed_Rec_Type;
1239 BEGIN
1240 
1241         --
1242         -- Convert the BOM Record
1243         --
1244         Bom_Bo_Pub.Convert_BomSComp_To_EcoSComp
1245         (  p_bom_sub_component_rec      => p_bom_sub_component_rec
1246          , x_sub_component_rec          => l_sub_component_rec
1247          , x_sub_comp_unexp_rec         => l_sub_comp_unexp_rec
1248         );
1249 
1250 	Check_Lineage
1251 	(  p_sub_component_rec		=> l_sub_component_rec
1252 	 , p_sub_comp_unexp_rec		=> l_sub_comp_unexp_rec
1253 	 , x_return_status		=> x_return_status
1254 	 , x_mesg_token_tbl		=> x_mesg_token_tbl
1255 	);
1256 
1257 END Check_Lineage;
1258 
1259 PROCEDURE Check_Access
1260 (  p_bom_sub_component_rec      IN  Bom_Bo_Pub.Bom_Sub_Component_Rec_Type
1261  , p_bom_sub_comp_unexp_rec     IN  Bom_Bo_Pub.Bom_Sub_Comp_Unexp_Rec_Type
1262  , x_Mesg_Token_Tbl             IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
1263  , x_Return_Status              IN OUT NOCOPY VARCHAR2
1264 )
1265 IS
1266         l_sub_component_rec     Bom_Bo_Pub.Sub_Component_Rec_Type;
1267         l_sub_comp_unexp_rec    Bom_Bo_Pub.Sub_Comp_Unexposed_Rec_Type;
1268 BEGIN
1269 
1270         --
1271         -- Convert the BOM Record
1272         --
1273         Bom_Bo_Pub.Convert_BomSComp_To_EcoSComp
1274         (  p_bom_sub_component_rec      => p_bom_sub_component_rec
1275          , p_bom_sub_comp_unexp_rec     => p_bom_sub_comp_unexp_rec
1276          , x_sub_component_rec          => l_sub_component_rec
1277          , x_sub_comp_unexp_rec         => l_sub_comp_unexp_rec
1278         );
1279 
1280 
1281 	--
1282 	-- Call Check Access
1283 	--
1284 	Check_Access
1285 	(  p_sub_component_rec	=> l_sub_component_rec
1286 	 , p_sub_comp_unexp_rec => l_sub_comp_unexp_rec
1287 	 , x_return_Status	=> x_return_status
1288 	 , x_mesg_token_tbl	=> x_mesg_token_tbl
1289 	);
1290 
1291 END Check_Access;
1292 
1293 END BOM_Validate_Sub_Component;