1 PACKAGE BODY Bom_Default_Bom_Header AS
2 /* $Header: BOMDBOMB.pls 120.2 2006/07/14 04:25:32 bbpatel noship $ */
3 /****************************************************************************
4 --
5 -- Copyright (c) 1996 Oracle Corporation, Redwood Shores, CA, USA
6 -- All rights reserved.
7 --
8 -- FILENAME
9 --
10 -- BOMDBOMB.pls
11 --
12 -- DESCRIPTION
13 --
14 -- Body of package Bom_Default_Bom_Header
15 --
16 -- NOTES
17 --
18 -- HISTORY
19 -- 07-JUL-1999 Rahul Chitko Initial Creation
20 -- 13-JUL-06 Bhavnesh Patel Added support for Structure Type
21 ****************************************************************************/
22 G_PKG_NAME CONSTANT VARCHAR2(30) := 'Bom_Default_Bom_Header';
23
24
25 /********************************************************************
26 * Function : Get_Bill_Sequence
27 * Return : NUMBER
28 * Purpose : Function will return the bill_sequence_id.
29 *
30 **********************************************************************/
31 FUNCTION Get_Bill_Sequence
32 RETURN NUMBER
33 IS
34 l_bill_sequence_id NUMBER := NULL;
35 BEGIN
36
37 SELECT bom_inventory_components_s.nextval
38 INTO l_bill_sequence_id
39 FROM sys.dual;
40
41 RETURN l_bill_sequence_id;
42
43 EXCEPTION
44
45 WHEN OTHERS THEN
46 RETURN NULL;
47
48 END Get_Bill_Sequence;
49
50 PROCEDURE Get_Flex_Bom_Header
51 ( p_bom_header_rec IN Bom_Bo_Pub.Bom_Head_Rec_Type
52 , x_bom_header_rec IN OUT NOCOPY Bom_Bo_Pub.Bom_Head_Rec_Type
53 )
54 IS
55 BEGIN
56
57 -- In the future call Flex APIs for defaults
58 x_bom_header_rec := p_bom_header_rec;
59
60 IF p_bom_header_rec.attribute_category =FND_API.G_MISS_CHAR THEN
61 x_bom_header_rec.attribute_category := NULL;
62 END IF;
63
64 IF p_bom_header_rec.attribute2 = FND_API.G_MISS_CHAR THEN
65 x_bom_header_rec.attribute2 := NULL;
66 END IF;
67
68 IF p_bom_header_rec.attribute3 = FND_API.G_MISS_CHAR THEN
69 x_bom_header_rec.attribute3 := NULL;
70 END IF;
71
72 IF p_bom_header_rec.attribute4 = FND_API.G_MISS_CHAR THEN
73 x_bom_header_rec.attribute4 := NULL;
74 END IF;
75
76 IF p_bom_header_rec.attribute5 = FND_API.G_MISS_CHAR THEN
77 x_bom_header_rec.attribute5 := NULL;
78 END IF;
79
80 IF p_bom_header_rec.attribute7 = FND_API.G_MISS_CHAR THEN
81 x_bom_header_rec.attribute7 := NULL;
82 END IF;
83
84 IF p_bom_header_rec.attribute8 = FND_API.G_MISS_CHAR THEN
85 x_bom_header_rec.attribute8 := NULL;
86 END IF;
87
88 IF p_bom_header_rec.attribute9 = FND_API.G_MISS_CHAR THEN
89 x_bom_header_rec.attribute9 := NULL;
90 END IF;
91
92 IF p_bom_header_rec.attribute11 = FND_API.G_MISS_CHAR THEN
93 x_bom_header_rec.attribute11 := NULL;
94 END IF;
95
96 IF p_bom_header_rec.attribute12 = FND_API.G_MISS_CHAR THEN
97 x_bom_header_rec.attribute12 := NULL;
98 END IF;
99
100 IF p_bom_header_rec.attribute13 = FND_API.G_MISS_CHAR THEN
101 x_bom_header_rec.attribute13 := NULL;
102 END IF;
103
104 IF p_bom_header_rec.attribute14 = FND_API.G_MISS_CHAR THEN
105 x_bom_header_rec.attribute14 := NULL;
106 END IF;
107
108 IF p_bom_header_rec.attribute15 = FND_API.G_MISS_CHAR THEN
109 x_bom_header_rec.attribute15 := NULL;
110 END IF;
111
112 IF p_bom_header_rec.attribute1 = FND_API.G_MISS_CHAR THEN
113 x_bom_header_rec.attribute1 := NULL;
114 END IF;
115
116 IF p_bom_header_rec.attribute6 = FND_API.G_MISS_CHAR THEN
117 x_bom_header_rec.attribute6 := NULL;
118 END IF;
119
120 IF p_bom_header_rec.attribute10 = FND_API.G_MISS_CHAR THEN
121 x_bom_header_rec.attribute10 := NULL;
122 END IF;
123
124 END Get_Flex_Bom_Header;
125
126
127
128 /*********************************************************************
129 * Procedure : Attribute_Defaulting
130 * Parameters IN : Bom Header exposed record
131 * Bom Header unexposed record
132 * Parameters OUT: Bom Header exposed record after defaulting
133 * Bom Header unexposed record after defaulting
134 * Mesg_Token_Table
135 * Return_Status
136 * Purpose : Attribute Defaulting will default the necessary null
137 * attribute with appropriate values.
138 **********************************************************************/
139 PROCEDURE Attribute_Defaulting
140 ( p_bom_header_rec IN Bom_Bo_Pub.Bom_Head_Rec_Type
141 , p_bom_head_unexp_rec IN Bom_Bo_Pub.Bom_Head_Unexposed_Rec_Type
142 , x_bom_header_rec IN OUT NOCOPY Bom_Bo_Pub.Bom_Head_Rec_Type
143 , x_bom_head_unexp_rec IN OUT NOCOPY Bom_Bo_Pub.Bom_Head_Unexposed_Rec_Type
144 , x_mesg_token_tbl IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
145 , x_return_status IN OUT NOCOPY VARCHAR2
146 )
147 IS
148 l_token_tbl Error_Handler.Token_Tbl_Type;
149 BEGIN
150
151 x_bom_header_rec := p_bom_header_rec;
152 x_bom_head_unexp_rec := p_bom_head_unexp_rec;
153 x_return_status := FND_API.G_RET_STS_SUCCESS;
154
155 IF p_bom_head_unexp_rec.bill_sequence_id IS NULL OR
156 p_bom_head_unexp_rec.bill_sequence_id = FND_API.G_MISS_NUM
157 THEN
158 x_bom_head_unexp_rec.bill_sequence_id :=
159 Get_Bill_Sequence;
160 END IF;
161
162 Get_Flex_Bom_Header( p_bom_header_rec => p_bom_header_rec
163 , x_bom_header_rec => x_bom_header_rec
164 );
165
166 IF(x_bom_header_rec.assembly_type is null)
167 THEN
168 SELECT decode(eng_item_flag, 'N', 1, 2)
169 INTO x_bom_header_rec.assembly_type
170 FROM mtl_system_items
171 WHERE inventory_item_id = p_bom_head_unexp_rec.assembly_item_id
172 AND organization_id = p_bom_head_unexp_rec.organization_id;
173 END IF;
174
175 -- Default implementation date. for bug3550305
176 IF(x_bom_header_rec.bom_implementation_date is null)
177 THEN
178 x_bom_header_rec.bom_implementation_date := sysdate;
179 ELSIF (x_bom_header_rec.bom_implementation_date =
180 FND_API.G_MISS_DATE) THEN
181 x_bom_header_rec.bom_implementation_date := null;
182 END IF;
183
184
185 /* Get the structure type information */
186
187 Error_Handler.Write_Debug ('Get the structure type id');
188 BEGIN
189 IF x_bom_head_unexp_rec.structure_type_id IS NULL THEN
190 SELECT structure_type_id,
191 enable_unimplemented_boms
192 INTO x_bom_head_unexp_rec.structure_type_id,
193 x_bom_head_unexp_rec.enable_unimplemented_boms
194 FROM bom_alt_designators_val_v
195 WHERE ( (x_bom_header_rec.alternate_bom_code IS NULL AND
196 alternate_designator_code IS NULL
197 AND organization_id = -1)
198 OR
199 (x_bom_header_rec.alternate_bom_code IS NOT NULL AND
200 x_bom_header_rec.alternate_bom_code = alternate_designator_code AND
201 x_bom_head_unexp_rec.organization_id = organization_id)
202 );
203 ELSE
204 SELECT ENABLE_UNIMPLEMENTED_BOMS
205 INTO x_bom_head_unexp_rec.enable_unimplemented_boms
206 FROM BOM_ALT_DESIGNATORS_VAL_V
207 WHERE ( ( x_bom_header_rec.alternate_bom_code IS NULL
208 AND ALTERNATE_DESIGNATOR_CODE IS NULL
209 AND ORGANIZATION_ID = -1 )
210 OR
211 ( x_bom_header_rec.alternate_bom_code IS NOT NULL
212 AND x_bom_header_rec.alternate_bom_code = ALTERNATE_DESIGNATOR_CODE
213 AND x_bom_head_unexp_rec.organization_id = ORGANIZATION_ID )
214 );
215 END IF; --end IF x_bom_head_unexp_rec.structure_type_id
216 EXCEPTION
217 WHEN NO_DATA_FOUND THEN
218 -- This stage is reached only when the BO is called from EAM due to the VPD security policy.
219 -- If any new security policy is later on added, post 11.5.10... we need to get the correct
220 -- context here and then take care of selecting the correct structure_type_id
221 IF x_bom_header_rec.alternate_bom_code IS NULL THEN
222 SELECT structure_type_id, nvl(enable_unimplemented_boms, 'N')
223 INTO x_bom_head_unexp_rec.structure_type_id,
224 x_bom_head_unexp_rec.enable_unimplemented_boms
225 FROM bom_structure_types_b
226 WHERE structure_type_name = 'Asset BOM';
227 ELSE
228 -- If we come here, then there is some other unexpected error
229 -- The alternate code given is incorrect and is currently not being handled
230 -- as any other error.
231 x_return_status := Error_Handler.G_STATUS_UNEXPECTED;
232 END IF;
233 END;
234
235 /* If the structure allows unimplemented BOMS and the BO is for BOM
236 and also the assembly is ENGG, create the BOM as unimplemented BOM */
237
238 Error_Handler.Write_Debug ('Checking for unimplemented BOM');
239 IF x_bom_header_rec.bom_implementation_date IS NULL
240 THEN
241 Error_Handler.Write_Debug ('IS NULL' || 'BO: ' || Bom_Globals.Get_Bo_Identifier || 'unimpl: ' || x_bom_head_unexp_rec.enable_unimplemented_boms || ' assembly type: ' || x_bom_header_rec.assembly_type);
242 IF x_bom_header_rec.assembly_type <> 2 OR
243 --Bom_Globals.Get_Bo_Identifier <> 'BOM' OR
244 x_bom_head_unexp_rec.enable_unimplemented_boms <> 'Y' THEN
245 l_token_tbl(1).token_name := 'ASSEMBLY_ITEM_NAME';
246 l_token_tbl(1).token_value :=
247 x_bom_header_rec.assembly_item_name;
248 l_token_tbl(1).token_name := 'ALTERNATE';
249 l_token_tbl(1).token_value :=
250 x_bom_header_rec.alternate_bom_code;
251 Error_Handler.Add_Error_Token
252 ( p_message_name => 'BOM_CANNOT_CREATE_UNIMPBOM'
253 , p_Mesg_Token_Tbl => x_Mesg_Token_Tbl
254 , x_Mesg_Token_Tbl => x_Mesg_Token_Tbl
255 , p_Token_Tbl => l_Token_Tbl
256 );
257 x_return_status := FND_API.G_RET_STS_ERROR;
258 END IF;
259 END IF;
260 Error_Handler.Write_Debug ('After the unimplemented check');
261
262 END Attribute_Defaulting;
263
264 /******************************************************************
265 * Procedure : Populate_Null_Columns
266 * Parameters IN : Bom Header Exposed column record
267 * Bom Header Unexposed column record
268 * Old Bom Header Exposed Column Record
269 * Old Bom Header Unexposed Column Record
270 * Parameters OUT: Bom Header Exposed column record after populating
271 * Bom Header Unexposed Column record after populating
272 * Purpose : This procedure will look at the columns that the user * has not filled in and will assign those columns a
273 * value from the old record.
274 * This procedure is not called CREATE
275 ********************************************************************/
276 PROCEDURE Populate_Null_Columns
277 ( p_bom_header_rec IN Bom_Bo_Pub.Bom_Head_Rec_Type
278 , p_bom_head_unexp_rec IN Bom_Bo_Pub.Bom_Head_Unexposed_Rec_Type
279 , p_old_bom_header_rec IN Bom_Bo_Pub.Bom_Head_Rec_Type
280 , p_old_bom_head_unexp_rec IN Bom_Bo_Pub.Bom_Head_Unexposed_Rec_Type
281 , x_bom_header_rec IN OUT NOCOPY Bom_Bo_Pub.Bom_Head_Rec_Type
282 , x_bom_head_unexp_rec IN OUT NOCOPY Bom_Bo_Pub.Bom_Head_Unexposed_Rec_Type
283 )
284 IS
285 l_bom_header_rec Bom_Bo_Pub.Bom_Head_Rec_Type; -- Bug 4909882
286 BEGIN
287 x_bom_header_rec := p_bom_header_rec;
288 x_bom_head_unexp_rec := p_bom_head_unexp_rec;
289
290 /* Assign NULL if the values are MISSING */
291
292 /* Bug 4909882. This should be called at the end after assigning
293 OLD values
294 Get_Flex_Bom_Header( p_bom_header_rec => p_bom_header_rec
295 , x_bom_header_rec => x_bom_header_rec
296 ); */
297
298 /* Assign OLD values if the values are NULL */
299
300 IF p_bom_header_rec.attribute_category IS NULL
301 THEN
302 x_bom_header_rec.attribute_category :=
303 p_old_bom_header_rec.attribute_category;
304
305 END IF;
306
307 IF p_bom_header_rec.attribute2 IS NULL
308 THEN
309 x_bom_header_rec.attribute2 :=
310 p_old_bom_header_rec.attribute2;
311 END IF;
312
313 IF p_bom_header_rec.attribute3 IS NULL
314 THEN
315 x_bom_header_rec.attribute3 :=
316 p_old_bom_header_rec.attribute3;
317 END IF;
318
319 IF p_bom_header_rec.attribute4 IS NULL THEN
320 x_bom_header_rec.attribute4 :=
321 p_old_bom_header_rec.attribute4;
322 END IF;
323
324 IF p_bom_header_rec.attribute5 IS NULL
325 THEN
326 x_bom_header_rec.attribute5 :=
327 p_old_bom_header_rec.attribute5;
328 END IF;
329
330 IF p_bom_header_rec.attribute7 IS NULL
331 THEN
332 x_bom_header_rec.attribute7 :=
333 p_old_bom_header_rec.attribute7;
334 END IF;
335
336 IF p_bom_header_rec.attribute8 IS NULL
337 THEN
338 x_bom_header_rec.attribute8 :=
339 p_old_bom_header_rec.attribute8;
340 END IF;
341
342 IF p_bom_header_rec.attribute9 IS NULL
343 THEN
344 x_bom_header_rec.attribute9 :=
345 p_old_bom_header_rec.attribute9;
346 END IF;
347
348 IF p_bom_header_rec.attribute11 IS NULL
349 THEN
350 x_bom_header_rec.attribute11 :=
351 p_old_bom_header_rec.attribute11;
352 END IF;
353
354 IF p_bom_header_rec.attribute12 IS NULL
355 THEN
356 x_bom_header_rec.attribute12 :=
357 p_old_bom_header_rec.attribute12;
358 END IF;
359
360 IF p_bom_header_rec.attribute13 IS NULL
361 THEN
362 x_bom_header_rec.attribute13 :=
363 p_old_bom_header_rec.attribute13;
364 END IF;
365
366 IF p_bom_header_rec.attribute14 IS NULL
367 THEN
368 x_bom_header_rec.attribute14 :=
369 p_old_bom_header_rec.attribute14;
370 END IF;
371
372 IF p_bom_header_rec.attribute15 IS NULL
373 THEN
374 x_bom_header_rec.attribute15 :=
375 p_old_bom_header_rec.attribute15;
376 END IF;
377
378 IF p_bom_header_rec.attribute1 IS NULL
379 THEN
380 x_bom_header_rec.attribute1 :=
381 p_old_bom_header_rec.attribute1;
382 END IF;
383
384 IF p_bom_header_rec.attribute6 IS NULL
385 THEN
386 x_bom_header_rec.attribute6 :=
387 p_old_bom_header_rec.attribute6;
388 END IF;
389
390 IF p_bom_header_rec.attribute10 IS NULL
391 THEN
392 x_bom_header_rec.attribute10 :=
393 p_old_bom_header_rec.attribute10;
394 END IF;
395
396 -- Bug 4909882
397 l_bom_header_rec := x_bom_header_rec;
398 Get_Flex_Bom_Header( p_bom_header_rec => l_bom_header_rec
399 , x_bom_header_rec => x_bom_header_rec
400 );
401 IF p_bom_header_rec.assembly_type = FND_API.G_MISS_NUM OR
402 p_bom_header_rec.assembly_type IS NULL
403 THEN
404 x_bom_header_rec.assembly_type :=
405 p_old_bom_header_rec.assembly_type;
406 END IF;
407
408 x_bom_header_rec.bom_implementation_date :=
409 p_old_bom_header_rec.bom_implementation_date;
410 --
411 -- Get the unexposed columns from the database and return
412 -- them as the unexposed columns for the current record.
413 --
414 x_bom_head_unexp_rec.bill_sequence_id := p_old_bom_head_unexp_rec.bill_sequence_id;
415
416 --structure type id can not be updated to null, so ignore FND_API.G_MISS_NUM
417 IF ( p_bom_head_unexp_rec.structure_type_id IS NULL
418 OR p_bom_head_unexp_rec.structure_type_id = FND_API.G_MISS_NUM )
419 THEN
420 x_bom_head_unexp_rec.structure_type_id :=
421 p_old_bom_head_unexp_rec.structure_type_id;
422 END IF;
423
424
425 END Populate_Null_Columns;
426
427 END Bom_Default_Bom_Header;