[Home] [Help]
PACKAGE BODY: APPS.CTO_CONFIG_ITEM_PK
Source
1 package body CTO_CONFIG_ITEM_PK as
2 /* $Header: CTOCITMB.pls 120.19.12010000.2 2008/08/11 16:04:38 abhissri ship $ */
3
4 /*----------------------------------------------------------------------------+
5 | Copyright (c) 1993 Oracle Corporation Belmont, California, USA
6 | All rights reserved.
7 | Oracle Manufacturing
8 |
9 |FILE NAME : CTOCITMB.pls
10 |
11 |DESCRIPTION : Creates new inventory item for CTO orders. Performs
12 | the same functions as BOMLDCIB.pls and INVPRCIB.pls
13 | for streamlined CTO supported with new OE architecture.
14 |
15 |HISTORY : Created based on BOMLDCIB.pls and INVPRCIB.pls
16 | Created on 09-JUL-1999 by Usha Arora
17 | 01-31-2000 James Chiu Modify mandatory components APIs
18 | 02-14-2000 Sajani Sheth Code changes for visible demand flag update
19 | 02-15-2000 Sajani Sheth Added code to support WIP parameter
20 | "Respond to sales order changes"
21 | 06-01-2000 Sajani Sheth Added code to support
22 | Multilevel/Multi-org CTO functionality
23 | 11-06-2000 Kiran Konada Added code to support
24 | Multilevel/Multi-org CTO functionality
25 | of changing visible demand flag IN
26 | BOM_CTO_ORDER_DEMAND table while creation
27 | of Configuration item
28 | 01/03/2001 Renga Kannan Removed the raise statements in the
29 | exception block. This fix is done as
30 | part of the bug fix #1509712
31 | 02/02/2001 Renga Kannan Added code to work for Change order
32 | In the case of model cancelation delink should not
33 | check for workflow status. Code is changed on 02/02/2001
34 | 02/03/2001 Renga Kannan Modifed the code in delink_item.
35 | 03/13/2001 Renga Kannan Added code for the notification part
36 | This change is part of the Change order project
37 | 04/04/2001 Renga Kannan Modified the link_item code for the performance issue.
38 | This is part of the bug fix # 1690095. The process order call in
39 | in link_item code is replaced with direct update statement.
40 | 05/30/2001 Sushant Sawant Modified the load_mandatory_comps and
41 | load_mandatory_components procedure
42 | for bug fix 1518894.
43 | 06-10-2001 SBhaskar Bugfix 1811007
44 | Added code to calculate weight/volume
45 | of the configuration item in the shipping org.
46 | 07-18-2001 Kundan Sarkar Bugfix 1876997 .
47 | Add code to improve performance.
48 | Modify query to replace an expensive view
49 | (wsh_delivery_line_status_v) with its base tables.
50 |
51 | 08-24-2001 Sushant Sawant: BUG #1957336
52 | Added a new functionality for preconfigure bom.
53 |
54 | 08-31-01 Renga Kannan
55 | Modified the create_item procedure to call
56 | CTO_CUSTOM_LIST_PRICE_PK.get_list_price to calculate
57 | the price list for configuration items.
58 | For More details please look at Procuring config Phse I
59 | Design document.
60 |
61 | 09-05-2001 Kundan Sarkar Bugfix 1988939 ( Base Bug 1962820 ).
62 | Truncate effectivity_date for correct selection of
63 | eligible rows during bom_explosion.
64 |
65 | 09-11-2001 Kundan Sarkar Bugfix 1988946 ( Base bug 1968318 ).
66 | No longer checking activity_label while selecting
67 | activity_status_code of an item.
68 |
69 | 09-25-2001 Kundan Sarkar Bugfix 2034342 ( Base bug 1985793 ).
70 | Checking greater of sysdate and calendar date while
71 | checking for item effectivity so that planning will get
72 | components effective till sysdate.
73 |
74 | 09-27-2001 Kundan Sarkar Bugfix 2034342 ( Base bug 1998386 ).
75 | Passing PRIMARY_QUANTITY_UOM to ATP
76 |
77 | 10-02-2001 Kundan Sarkar Bugfix 2041612 ( Base bugs 2034419 and 1997355)
78 | Calling MRP API MRP_OM_API_PK to insert the config items
79 | line id during linking and delinking of config item.
80 |
81 | 10-29-2001 Kundan Sarkar Bugfix 2133816 ( Base bug 2047428 ).
82 | Loading Mandatory components even if Top Model ATP components
83 | flag is set to 'N'.Christine of Planning team has confirmed
84 | that we should honor the ATP components flag of top model and
85 | explosion need not take place if the ATP components flag on
86 | model is set to 'N'. Fixed the code accordingly .
87 |
88 | Modified on 08-JAN-2002 by Sushant Sawant: BUG #2172057
89 | Added a restriction for numbering method to be used while creating
90 | configuration due to preconfigure bom limitation.
91 |
92 | 01-28-2002 Kundan Sarkar Bugfix 2202633 ( Base bug 2197842 ).
93 | Config item created is not assigned to Purchasing default
94 | category and hence cannot be entered in a purchase order.
95 |
96 | 01-28-2002 Kundan Sarkar Bugfix 2186114 ( Base bug 2162912 ).
97 | In load_mandatory_comps and load_mandatory_components :
98 | 1) Truncate disable_date to correctly compare it with calendar_date.
99 | 2) Replace >= with > while comparing disable_date and calendar_date.
100 | 3) Replace to_date and to_char conversion functions for eff_date and
101 | disable_date check since they are compared with calendar_date which
102 | does not have timestamp.
103 |
104 | 03-08-2002 Sushant Sawant BUG#2234858
105 | Added new functionality for Drop Shipment
106 | Changed functions link_item
107 | Changed functions delink_item
108 |
109 |
110 | 03-25-2002 Renga Kannan Removed the custom API call for list price.
111 | This custom API will be called as part of List price rollup
112 |
113 |
114 |
115 | 03/31/2002 Renga Kannan Bugfix 2288258 : Make the update visible_demand_flag statement more restrictive
116 while it is performing update during delink action of ML/MO or BUY Model.
117 |
118 | 04/08/2002 Sushant Sawant BugFix 2300006 : Multiple Instantiation Usability Issues.
119 | This fix will align each configuration next to the model
120 | it corresponds to.
121 |
122 | 04-09-2002 Kundan Sarkar Bugfix 2292466 ( Base bug 2267646 ).
123 | Added NVL function .
124 |
125 | 04-18-2002 Kundan Sarkar Bugfix 2337353 ( Base bug 2157740 ).
126 | Copying Base Model attachement to Config item.
127 |
128 |
129 | 05-14-2002 Renga Kannan Removed the attribute list_price_per_unit
130 | from copying it to config item in mtl_system_items
131 | Look at the bug details 2370307
132 |
133 |
134 | 06-03-2002 Sushant Sawant Bugfix 2401654 [duplicate of 2400948
135 | and bug 2378556 ]
136 | Changed query in load_mandatory_components
137 | made changes to get only standard
138 | mandatory components.
139 |
140 | 06-20-2002 Sushant Sawant Bugfix 2420865(a.k.a.BUG2428214)
141 | get_mandatory_components was fixed to
142 | handle arrival sets. In case of Arrival Sets
143 | requested_arrival_date is populated instead of
144 | requested_ship_date.
145 |
146 | 08-29-2002 Kundan Sarkar Bugfix 2458338 ( Base bug 2395525 ).
147 | Not copying sales and Mktg category set
148 | from base model to config item.
149 |
150 | 08-29-2002 Kundan Sarkar Bugfix 2454401 ( Base bug 2425667 ).
151 | Infinite Loops in load_mandatory_comps and
152 | load_mandatory_components during splitting of
153 | an ATO model within a PTO with Tools - Debug
154 | set to off.
155 |
156 | 08-29-2002 Kundan Sarkar Bugfix 2541088 ( Base bug 2457514 ).
157 | Config item description picks up model desc.
158 | of base language instead of base and installed
159 | languages.
160 |
161 | 09-05-2002 Kundan Sarkar Bugfix 2547219 ( Base bug 2461574 ).
162 | Configured items are not inheriting transaction
163 | defaults subinventory location from the model.
164 |
165 | 09-25-2002 Kundan Sarkar Bugfix 2587307 ( Base bug 2576422 ).
166 | Configured item weights are incorrect for MLMO
167 | structure.
168 |
169 | 11-27-2002 Kundan Sarkar Bugfix 2503104
170 | Passing model's user_item_description to config
171 | item .
172 |
173 | 12-09-2002 Kundan Sarkar Bugfix 2701338 ( Base bug 2652379 )
174 | Incorrect numbering sequence of configured items
175 | in a multi - level structure.
176 |
177 | 12-26-2002 Kiran Konada bugfix 2727983
178 | web_status filed is being copied for configuration item
179 | from its base model.This field is a mandatory one for
180 inventory from 11.5.9 onwards
181 |
182 |
183 | 12-31-2002 Kiran Konada bugfix2730055
184 | insert into MTL_ITEM_REVISIONS was changed to MTL_ITEM_REVISIONS_B
185 |
186 |
187 | 01-23-2003 Kundan Sarkar Bugfix 2503104
188 | Revert fix as OM will populate user_item_description
189 | of config item
190 | Bugfix 2764811 ( In branch 2745590 )
191 | Remove reference on flow schedule when config item
192 | is delinked.
193 |
194 | 02-03-2003 Kundan Sarkar Bugfix 2781022 ( In branch 2663450 )
195 | New custom hook to generate custom item numbers for
196 | pre configured items and autocreated configurations.
197 |
198 | Bugfix 2784045 ( no bug logged for main ...
199 | Propagate this fix to main with fix of 2781022 )
200 | Error in delink configuration when no routing is
201 | defined for the model.
202 |
203 |
204 | 02/04/2003 Kiran Konada
205 | Added a new paramter to pass conifg/ato item id
206 | to start_work_flow
207 | bugfix 2782394
208 |
209 | Modified on 14-FEB-2003 By Kundan Sarkar
210 | Bugfix 2804321 : Propagating customer bugfix 2774570
211 | and 2786934 to main.
212 |
213 | Modified on 24-MAR-2003 By Kundan Sarkar
214 | Bugfix 2867676 : Propagating customer bugfix 2858080
215 | to main.
216 |
217 | Modified on 14-APR-2003 By Kundan Sarkar
218 | Bugfix 2904203 : Propagating customer bugfix 2898851
219 | to main.
220 |
221 | 08-JUL-2003 Sushant Sawant Replicated Bugfix 2897132
222 | (a.k.a. 2913695[actual aru]) to J Main as 3037613
223 | Fixed bug related to get_mandatory_components
224 | Following scenarios were addressed
225 | 1) pass correct line id for mandatory components
226 | 2) handle cancel case properly
227 | 3) handle delete case properly (respect params)
228 | 4) handle reschedule case properly
229 |
230 |
231 | Modified on 14-MAR-2003 By Sushant Sawant
232 | Decimal-Qty Support for Option Items.
233 | Replicated 3037613 for mandatory
234 | components
235 | ( a.k.a 2913695, 2897132)
236 |
237 | 17-JUL-2003 Sushant Sawant Replicated Bugfix 2483920
238 | using 3056491
239 |
240 | 30-DEC-2003 Kiran Konada Bugfix
241 | 3340844
242 | inserted value into revision_label
243 | of mtl_item_revisions_b
244 |
245 | 3338108
246 | a) In 11.5.9 in the dynamic sql part
247 | of inserting into mtl_item_revisions_b
248 | we were inserting same revision_id for
249 | an item in all orgs. Revision_id was a
250 | null column
251 |
252 | As items team has decide to create a
253 | unique index on it, the revision_id needs
254 | to be different in each org
255 |
256 | b) where condition for insert into mtl_item_revisions_tl
257 | is also changed to get the corresponding revisionId
258 | info from table mtl_item_revisions_b table
259 |
260 | c) fixed by sawant
261 | it is decided to leave blank the uom_code and revision_id
262 | in mtl_cross_references
263 |
264 | 30-DEC-2003 Sushant Sawant Fixed Bug# 3358194
265 | Weight/Vol calculations were not updated if model has no base uom.
266 |
267 |
268 | ssawant 15-JAN-04 Bugfix 3379296
269 | changes evaluate_atp_attributes for model attribute Y, N scenario.
270 |
271 | KKONADA 02-03-2004 bugfix 2828588
272 | Inserted the configuration data into table MTL_ABC_ASSIGNMENTS
273 |
274 |
275 |
276 | KKONADA 03-02-2004 front port bugfix#3473737
277 |
278 | branch Bugfix 3463999 : Updating config_id in bcol to null
279 | if config is matched.
280 |
281 |
282 | KKONADA 03-15-2004 Corrected the comments
283 | bug#3340844 was entered for 3338108 at few places , corrected
284 | the error
285 |
286 |
287 | Kkkonada 03-26-2004 Kiran Konada
288 | Bugfix 3536085
289 | assignment_group_id and inventory_item_id should be unique
290 |
291 |
292 | Modified on 26-Mar-2004 By Sushant Sawant
293 | Fixed Bug#3484511
294 | all queries referencing oe_system_parameters_all
295 | should be replaced with a function call to oe_sys_parameters.value
296 |
297 |
298 | Modified on 23-Jun-2006 by Kiran Konada
299 | Revreted bugfix 3473737, branch fix 3463999
300 |
301 | modified on 01-jul-2004 kiran konada
302 | aru 3737772 (for FP 3473737)
303 | added pconfigid parameter to ATO_WEIGHT_VOL api
304 | and changed the de_code statment in wt_vol api
305 |
306 |
307 |
308 | Modified on 18-APR-2005 By Sushant Sawant
309 | Fixed Bug#4172300
310 | Cost in validation org is not copied properly from model to config item.
311 |
312 | Modified on 05-Jul-2005 by Renga Kannan
313 | Change for MOAC
314 | As per OM
315 s recommendation changing the process order Public API call to Group API call
316 for Link item
317 |
318 |
319 | Modified on 08-Aug-2005 Kiran Konada
320 | bug# 4539578
321 | In R12, mtl_cross_references datamodel has been changed to
322 | mtl_cross_references_b and mtl_cross_references_tl
323 |
324 | Modified on 15-Sep-2005 Renga Kannan
325 | Made Code changes for ATG Performance
326 | Project
327 |
328 | Modified on 03-feb-2006 Kiran Konada
329 | bugfix FP 4861996
330 | should check if a specific item is present
331 | in specificy category set
332 |
333 | 07-Mar-2006 Kiran Konada
334 | performance bug#4905845
335 | Removed comments to reduce shared memory
336 |
337 +-----------------------------------------------------------------------------*/
338
339
340 PG_DEBUG Number := NVL(FND_PROFILE.value('ONT_DEBUG_LEVEL'), 0);
341
342 g_atp_flag varchar2(1) := 'N' ;
343
344 TYPE ATTRIB_NAME_TAB_TYPE is table of mtl_item_attributes.attribute_name%type index by binary_integer ;
345
346 TYPE CONTROL_LEVEL_TAB_TYPE is table of mtl_item_attributes.control_level%type index by binary_integer ;
347
348 g_attribute_name_tab ATTRIB_NAME_TAB_TYPE ;
349 g_control_level_tab CONTROL_LEVEL_TAB_TYPE ;
350
351
352 procedure create_preconfigured_item( p_line_id in number
353 , p_model_id in number
354 , p_config_id in number
355 , p_lItemType in varchar2 );
356
357
358 -- bugfix 2706981: forward declaration
359 FUNCTION check_dup_item(
360 pSegment1 varchar2,
361 pSegment2 varchar2,
362 pSegment3 varchar2,
363 pSegment4 varchar2,
364 pSegment5 varchar2,
365 pSegment6 varchar2,
366 pSegment7 varchar2,
367 pSegment8 varchar2,
368 pSegment9 varchar2,
369 pSegment10 varchar2,
370 pSegment11 varchar2,
371 pSegment12 varchar2,
372 pSegment13 varchar2,
373 pSegment14 varchar2,
374 pSegment15 varchar2,
375 pSegment16 varchar2,
376 pSegment17 varchar2,
377 pSegment18 varchar2,
378 pSegment19 varchar2,
379 pSegment20 varchar2)
380 RETURN number;
381
382 -- bugfix 3026929: forward declaration
383 PROCEDURE populate_item_revision(pConfigId number,
384 pModelId number,
385 pLineId number,
386 xReturnStatus OUT NOCOPY varchar2);
387
388
389
390
391 function get_attribute_control( p_attribute_name in varchar2)
392 return number
393 is
394 v_attribute_name varchar2(100);
395 begin
396 v_attribute_name := UPPER( p_attribute_name );
397
398 for i in 1..g_attribute_name_tab.count
399 loop
400 if( g_attribute_name_tab(i) = v_attribute_name ) then
401 return g_control_level_tab(i);
402 end if;
403
404 end loop ;
405
406 return 0;
407 end get_attribute_control;
408
409
410
411 function get_atp_flag
412 return char
413 is
414 v_atp_flag Varchar2(1);
415 begin
416 v_atp_flag := g_atp_flag;
417 g_atp_flag := null;
418 return v_atp_flag ;
419
420 /*
421 ** g_atp_flag has to be returned in a tricky way to avoid the sql statement from
422 ** using the value before evaluate_atp_attributes call
423 */
424
425 end get_atp_flag;
426
427
428 function evaluate_atp_attributes( p_atp_flag in mtl_system_items_b.atp_flag%type
429 , p_atp_components_flag in mtl_system_items_b.atp_components_flag%type )
430 return char
431 is
432 v_atp_components_flag mtl_system_items_b.atp_components_flag%type ;
433 begin
434
435 /* Note: Although a lot of similarity exists for some combination of flag values
436 the results are bound to change based on new functionality/bug fix issues.
437 This code will be easier to maintain if the logic appears more like a
438 truth table
439 The variable g_atp_flag is set to avoid making another call to get the
440 value for the second column.
441 */
442
443 if( p_atp_flag = 'N' ) then
444
445 if( p_atp_components_flag = 'N' ) then
446
447 g_atp_flag := 'N' ;
448 v_atp_components_flag := 'N' ;
449
450 elsif( p_atp_components_flag = 'Y' ) then
451
452 g_atp_flag := 'Y' ;
453 v_atp_components_flag := 'Y' ;
454
455 elsif( p_atp_components_flag = 'R' ) then
456
457 g_atp_flag := 'Y' ;
458 v_atp_components_flag := 'R' ;
459
460 elsif( p_atp_components_flag = 'C' ) then
461
462 g_atp_flag := 'Y' ;
463 v_atp_components_flag := 'C' ;
464
465 end if;
466
467 elsif( p_atp_flag = 'Y') then
468
469 if( p_atp_components_flag = 'N' ) then
470
471 g_atp_flag := 'Y' ;
472 v_atp_components_flag := 'N' ; -- fixed bug 3379296
473
474 elsif( p_atp_components_flag = 'Y' ) then
475
476 g_atp_flag := 'Y' ;
477 v_atp_components_flag := 'Y' ;
478
479 elsif( p_atp_components_flag = 'R' ) then
480
481 g_atp_flag := 'Y' ;
482 v_atp_components_flag := 'R' ;
483
484 elsif( p_atp_components_flag = 'C' ) then
485
486 g_atp_flag := 'Y' ;
487 v_atp_components_flag := 'C' ;
488
489 end if;
490
491
492
493 elsif( p_atp_flag = 'R' ) then
494
495 if( p_atp_components_flag = 'N' ) then
496
497 g_atp_flag := 'N' ;
498 v_atp_components_flag := 'N' ; /* Doubtful please check again */
499
500 elsif( p_atp_components_flag = 'Y' ) then
501
502 g_atp_flag := 'Y' ;
503 v_atp_components_flag := 'Y' ;
504
505 elsif( p_atp_components_flag = 'R' ) then
506
507 g_atp_flag := 'Y' ;
508 v_atp_components_flag := 'R' ;
509
510 elsif( p_atp_components_flag = 'C' ) then
511
512 g_atp_flag := 'Y' ;
513 v_atp_components_flag := 'C' ;
514
515 end if;
516
517
518
519
520 elsif( p_atp_flag = 'C' ) then
521
522 if( p_atp_components_flag = 'N' ) then
523
524 g_atp_flag := 'Y' ;
525 v_atp_components_flag := 'N' ;
526
527 elsif( p_atp_components_flag = 'Y' ) then
528
529 g_atp_flag := 'Y' ;
530 v_atp_components_flag := 'Y' ;
531
532 elsif( p_atp_components_flag = 'R' ) then
533
534 g_atp_flag := 'Y' ;
535 v_atp_components_flag := 'R' ;
536
537 elsif( p_atp_components_flag = 'C' ) then
538
539 g_atp_flag := 'Y' ;
540 v_atp_components_flag := 'C' ;
541
542 end if;
543
544
545 end if ;
546
547
548
549 oe_debug_pub.add( ' ************* EVALUATE_ATP_ATTRIBUTES *** p_atp_flag ' || p_atp_flag
550 || ' p_atp_components_flag ' || p_atp_components_flag
551 || ' result ' || ' g_atp_flag ' || g_atp_flag
552 || ' v_atp_components_flag ' || v_atp_components_flag , 1 ) ;
553
554
555
556
557 return v_atp_components_flag ;
558
559
560
561 end evaluate_atp_attributes ;
562
563
564
565
566
567 function get_cost_group( pOrgId in number,
568 pLineID in number)
569 return integer is
570
571 l_cst_grp number;
572
573 begin
574
575 /*--------------------------------------------+
576 This is a function to get cost_group_id
577 for using in insert to cst_quantity_layers
578 +---------------------------------------------*/
579
580 select nvl(costing_group_id,1)
581 into l_cst_grp
582 from pjm_project_parameters ppp
583 where ppp.project_id = ( select project_id
584 from oe_order_lines_all ol
585 where ol.line_id = pLineId )
586 and ppp.organization_id = pOrgId;
587
588 return(l_cst_grp);
589
590 exception
591 when no_data_found then
592 IF PG_DEBUG <> 0 THEN
593 oe_debug_pub.add('get_cost_group: ' || 'ERROR: Could not fetch the cost_group_id from pjm_project_parameters (NDF)',1);
594 END IF;
595 return(0);
596
597 end get_cost_group;
598
599
600 function get_validation_org ( opunit in number,
601 profile_val in number)
602 return integer
603 is
604
605 lValue fnd_profile_option_values.profile_option_value%type;
606 loldvalue fnd_profile_option_values.profile_option_value%type;
607 lValidOrg number;
608
609
610 cursor validation_org is
611 select distinct POV.profile_option_value
612 from fnd_profile_options PO ,
613 fnd_profile_option_values POV,
614 fnd_responsibility FR,
615 fnd_profile_options PO2,
616 fnd_profile_option_values POV2
617 where PO.profile_option_name = 'SO_ORGANIZATION_ID'
618 and POV.application_id = PO.application_id
619 and POV.profile_option_id = PO.profile_option_id
620 and POV.level_id = 10003
621 and FR.application_id = POV.level_value_application_id
622 and FR.responsibility_id = POV.level_value
623 and PO2.profile_option_name = 'ORG_ID'
624 and POV2.application_id = PO2.application_id
625 and POV2.profile_option_id = PO2.profile_option_id
626 and POV2.level_id = 10003
627 and POV2.profile_option_value = to_char(opunit)
628 and POV2.level_value_Application_id = 660 -- ONT
629 and FR.application_id = POV2.level_value_application_id
630 and FR.responsibility_id = POV2.level_value;
631
632 multiorg_error EXCEPTION;
633
634 begin
635
636 lOldValue := 0;
637 /*------------------------------------------------------+
638 Get the site level values for so_organization_id
639 for the OE responsibility of operating unit opunit.
640 Only one row should be returned. If no row is returned,
641 use the profile value (so_organization_id) of this
642 responsibility.
643 +-------------------------------------------------------*/
644
645 open validation_org;
646
647 fetch validation_org into lvalue;
648 lOldValue := lValue;
649
650 while validation_org%found
651 loop
652 fetch validation_org into lvalue;
653 if validation_org%rowcount > 1 then
654 if lOldValue <> lvalue then
655 raise multiorg_error;
656 end if;
657 end if;
658 end loop;
659 if validation_org%rowcount = 0 then
660 lValidOrg := profile_val;
661 else
662 lValidOrg := to_number(lOldvalue);
663 end if;
664 close validation_org;
665 return (lValidOrg);
666
667 exception
668 when others then
669 return(0);
670
671 end get_validation_org;
672
673
674
675 function flow_schedule_exists(
676 pLineId in number ,
677 xErrorMessage out NOCOPY varchar2 ,
678 xMessageName out NOCOPY varchar2 ,
679 xTableName out NOCOPY varchar2 )
680 return boolean
681 is
682
683 lWipEntityId number;
684
685 begin
686
687 select wip_entity_id
688 into lWipEntityId
689 from wip_flow_schedules wfs,
690 oe_order_lines_all oel,
691 oe_order_headers_all oeh,
692 oe_transaction_types_all ota,
693 oe_transaction_types_tl otl,
694 mtl_sales_orders mso
695 where wfs.demand_source_line = oel.line_id --config line id
696 and oel.line_id = pLineId
697 and oeh.header_id = oel.header_id
698 and oeh.order_type_id = ota.transaction_type_id
699 and ota.transaction_type_code='ORDER'
700 and ota.transaction_type_id = otl.transaction_type_id
701 and oeh.order_number = mso.segment1
702 and otl.name = mso.segment2
703 and otl.language = (select language_code
704 from fnd_languages
705 where installed_flag = 'B')
706 and mso.sales_order_id = wfs.demand_source_header_id
707 and oel.inventory_item_id = wfs.primary_item_id
708 and rownum = 1;
709
710 IF PG_DEBUG <> 0 THEN
711 oe_debug_pub.add ('flow_schedule_exists: ' || 'Flow Schedule Exists!', 1);
712 END IF;
713
714 return(true); -- Flow Schedule exists
715
716 exception
717 when no_data_found then
718
719 IF PG_DEBUG <> 0 THEN
720 oe_debug_pub.add ('flow_schedule_exists: ' || 'Flow Schedules does not exist ', 1);
721 END IF;
722 return(false); -- Flow Schedule does not exist
723
724 when others then
725 xErrorMessage := 'ERROR: Flow Schedule exists for this line, Cannot delink';
726 xMessageName := 'CTO_DELINK_ITEM_ERROR';
727 xTableName := 'WIP_FLOW_SCHEDULES';
728 return(false);
729
730 end flow_schedule_exists;
731
732 ----------------------------------------
733
734 function work_orders_exist (
735 pLineId in number ,
736 xErrorMessage out NOCOPY varchar2 ,
737 xMessageName out NOCOPY varchar2 ,
738 xTableName out NOCOPY varchar2 )
739 return boolean
740 is
741
742 lReserveId number;
743
744 begin
745
746 select reservation_id
747 into lReserveId
748 from mtl_reservations mr,
749 oe_order_lines_all oel,
750 oe_order_headers_all oeh,
751 oe_transaction_types_all ota,
752 oe_transaction_types_tl otl,
753 mtl_sales_orders mso
754 where mr.demand_source_line_id = oel.line_id --config line id
755 and oel.line_id = pLineId
756 and oeh.header_id = oel.header_id
757 and oeh.order_type_id = ota.transaction_type_id
758 and ota.transaction_type_code = 'ORDER'
759 and ota.transaction_type_id = otl.transaction_type_id
760 and oeh.order_number = mso.segment1
761 and otl.name = mso.segment2
762 and otl.language = (select language_code
763 from fnd_languages
764 where installed_flag = 'B')
765 and mso.sales_order_id = mr.demand_source_header_id
766 and mr.demand_source_type_id = decode(oeh.source_document_type_id, 10,
767 INV_RESERVATION_GLOBAL.g_source_type_internal_ord,
768 INV_RESERVATION_GLOBAL.g_source_type_oe) --bugfix 1799874
769 and mr.reservation_quantity > 0
770 and supply_source_type_id = INV_RESERVATION_GLOBAL.g_source_type_wip
771 and rownum = 1;
772
773 IF PG_DEBUG <> 0 THEN
774 oe_debug_pub.add ('work_orders_exist: ' || 'Work orders exist! Call wip_holds api', 2);
775 END IF;
776
777 return(true); -- reservation exists
778
779 exception
780 when no_data_found then
781
782 IF PG_DEBUG <> 0 THEN
783 oe_debug_pub.add ('work_orders_exist: ' || 'Work orders do not exist, do not call wip holds api ', 2);
784 END IF;
785 return(false); -- Reservation does not exist
786
787 when others then
788 xErrorMessage := 'ERROR: Failed in work_orders_exist ';
789 xMessageName := 'CTO_DELINK_ITEM_ERROR';
790 xTableName := 'MTL_RESERVATIONS';
791 return(false);
792
793 end work_orders_exist;
794
795
796
797 function delink_item (
798 pModelLineId in number ,
799 pConfigId in number ,
800 xErrorMessage out NOCOPY varchar2 ,
801 xMessageName out NOCOPY varchar2 ,
802 xTableName out NOCOPY varchar2 )
803 return integer
804 is
805
806 lStmtNumber number;
807 lConfigLineId number;
808 lreserveId number;
809 lWfStat varchar2(80);
810 lCancel_flag varchar2(1) := 'N';
811 lCount number;
812 l_source_type number;
813
814 -- The following flag is added by Renga Kannan on 03/13/2001
815
816 l_resv_flag varchar2(1) := 'N';
817 pchgtype CTO_CHANGE_ORDER_PK.change_table_type;
818 l_order_number OE_ORDER_HEADERS_ALL.order_number%TYPE;
819 l_ml_mo_flag varchar2(1) := 'N';
820
821 pAutoUnreserve varchar2(1);
822
823 l_return_status varchar2(1) := FND_API.G_RET_STS_SUCCESS;
824 l_msg_count number;
825 l_msg_data varchar2(2000);
826 l_option_line_id number;
827
828 i number;
829 x number;
830 y varchar(1);
831 z varchar(30);
832
833 lOrgId number;
834 lSalesOrderId number;
835 lHeaderId number;
836 lSourceCode varchar2(30);
837
838 l_rsv INV_RESERVATION_GLOBAL.mtl_reservation_rec_type;
839 l_rsv_id number;
840 l_dummy_sn INV_RESERVATION_GLOBAL.serial_number_tbl_type;
841 l_status varchar2(1);
842 lShipConfirmed varchar2(10);
843
844 --Begin Bugfix 1997355
845
846 index_counter_delink number;
847 p_config_line_arr_delink MRP_OM_API_PK.line_id_tbl;
848 l_return_status_delink varchar2(1);
849 vLineId number;
850
851 --End Bugfix 1997355
852
853 -- begin bugfix 2745590
854 lcfm_routing_flag number;
855 lflow_schedule_exist number;
856 -- end bugfix 2745590
857
858 CURSOR reservations IS
859 select distinct reservation_id
860 from mtl_reservations mr,
861 oe_order_lines_all oel,
862 oe_order_headers_all oeh,
863 oe_transaction_types_all ota,
864 oe_transaction_types_tl otl,
865 mtl_sales_orders mso
866 where mr.demand_source_line_id = oel.line_id --config line id
867 and oel.line_id = lConfigLineId
868 and oeh.header_id = oel.header_id
869 and oeh.order_type_id = ota.transaction_type_id
870 and ota.transaction_type_code='ORDER'
871 and ota.transaction_type_id = otl.transaction_type_id
872 and oeh.order_number = mso.segment1
873 and otl.name = mso.segment2
874 and otl.language = (select language_code
875 from fnd_languages
876 where installed_flag = 'B')
877 and mso.sales_order_id = mr.demand_source_header_id
878 and mr.demand_source_type_id = decode(oeh.source_document_type_id, 10,
879 INV_RESERVATION_GLOBAL.g_source_type_internal_ord,
880 INV_RESERVATION_GLOBAL.g_source_type_oe) --bugfix 1799874
881 and mr.reservation_quantity > 0;
882
883 --Begin Bugfix 1997355
884
885 CURSOR delink_lines IS
886 select line_id
887 from oe_order_lines_all
888 where ato_line_id = pModelLineId;
889
890 --End Bugfix 1997355
891
892 v_source_type_code oe_order_lines_all.source_type_code%type ; /* BUG#2234858 */
893
894 -- Added by Renga Kannan on 05/13/02
895 -- for bug fix 2366241
896
897 l_header_id oe_order_lines_all.header_id%type;
898
899 v_aps_version number := 0;
900
901
902 v_model_line_activity varchar2(100) ;
903
904
905 v_appl_name varchar2(200) ;
906 v_error_name varchar2(2000) ;
907
908 BEGIN
909
910 lShipConfirmed := 'FALSE';
911
912
913
914 lStmtNumber := 400;
915 -- BUG#2234858
916 -- Modified by Sushant Sawant 02/14/2002. The source type for the model
917 -- needs to be retrieved to distinguish between drop shipped orders(external)
918 -- and regular orders( internal )
919
920 select source_type_code into v_source_type_code
921 from oe_order_lines_all
922 where line_id = pModelLineId ;
923
924
925
926
927 lStmtNumber := 500;
928 -- Modified by Renga Kannan 02/03/2001. The condition checking for
929 -- Cancelled_flag is removed . because delink is called even in the case of
930 -- Cancelled lines.
931
932 select line_id, ship_from_org_id,header_id
933 into lConfigLineId, lOrgId,l_header_id
934 from oe_order_lines_all oel
935 where ato_line_id = pModelLineId
936 and inventory_item_id = pConfigid
937 and item_type_code = 'CONFIG';
938
939 BEGIN
940 --
941 -- Do not allow delink if config line is ship confirmed
942 -- A shipment line can be in 'open','packed','confirmed','in-transit'
943 -- or 'closed' status. Allow delink only if 'OPEN'
944 --
945 lStmtNumber := 505;
946
947 -- begin bugfix 2001824:
948 -- To check if something has been "shipped" , we should check for released_status.
949 -- If the released_status is either 'Y' (staged) or 'C' (closed), we should consider
950 -- the line as shipped (partial or fully)
951
952 select distinct 'TRUE'
953 into lShipConfirmed
954 from wsh_delivery_details_ob_grp_v wdd -- Added By Renga Kannan on 11/03/03 for wsh data model changes
955 where wdd.source_line_id = lConfigLineId
956 and wdd.source_code = 'OE'
957 and wdd.released_status in ('Y', 'C'); -- Staged [Y], Closed [C]
958
959 if (lShipConfirmed = 'TRUE' ) then
960 IF PG_DEBUG <> 0 THEN
961 oe_debug_pub.add ('delink_item: ' || 'Error : Config Line has been ship confirmed. Can not delink',1);
962 END IF;
963 xMessageName := 'CTO_DELINK_SHIPPING_ERROR';
964 raise FND_API.G_EXC_ERROR;
965 end if;
966
967 EXCEPTION
968 when no_data_found then
969 IF PG_DEBUG <> 0 THEN
970 oe_debug_pub.add ('delink_item: ' || 'Config Line does not exist in shipping yet. Delink allowed',2);
971 END IF;
972
973 END;
974 -- end bugfix 2001824
975
976
977 lStmtNumber := 510;
978 lSourceCode := fnd_profile.value('ONT_SOURCE_CODE');
979 IF PG_DEBUG <> 0 THEN
980 oe_debug_pub.add ('delink_item: ' || 'lSourceCode is '||lSourceCode, 2);
981 END IF;
982
983 --
984 -- Get header id, other info for calling Reservation API
985 --
986
987 select mso.sales_order_id,
988 oel.ship_from_org_id,
989 oeh.header_id
990 into lSalesOrderId, --header id fro rsv api
991 lOrgId, --ship from org id
992 lHeaderId -- header id in oeh, for wip api
993 from oe_order_lines_all oel,
994 oe_order_headers_all oeh,
995 oe_transaction_types_tl oet,
996 mtl_sales_orders mso,
997 mtl_system_items msi
998 where oel.line_id = lConfigLineId
999 and item_type_code = 'CONFIG'
1000 and oeh.header_id = oel.header_id
1001 and oet.transaction_type_id = oeh.order_type_id
1002 and mso.segment1 = to_char(oeh.order_number)
1003 and mso.segment2 = oet.name
1004 and oet.language = (select language_code
1005 from fnd_languages
1006 where installed_flag = 'B')
1007 and mso.segment3 = lSourceCode
1008 and oel.inventory_item_id = pConfigId
1009 and msi.inventory_item_id = oel.inventory_item_id
1010 and msi.organization_id = oel.ship_from_org_id
1011 and msi.base_item_id is not NULL;
1012
1013 IF PG_DEBUG <> 0 THEN
1014 oe_debug_pub.add ('delink_item: ' || 'Before WIP parameter check', 2);
1015
1016 oe_debug_pub.add ('delink_item: ' || 'Config Line_id is ' || lConfigLineId, 2);
1017
1018 oe_debug_pub.add ('delink_item: ' || 'Config item_id is ' || pConfigId, 2);
1019
1020 oe_debug_pub.add ('delink_item: ' || 'org id is ' || lOrgId, 2);
1021
1022 oe_debug_pub.add ('delink_item: ' || 'Sales Order id is ' || lSalesOrderId, 2);
1023 END IF;
1024
1025 -- begin bugfix 2745590 : Check for routing flag : 1 = Flow Routing
1026
1027 lStmtNumber := 511;
1028 -- 2784045 : Select stmt is enclosed in block to handle exception
1029 begin
1030 select nvl(cfm_routing_flag, 2)
1031 into lcfm_routing_flag
1032 from bom_operational_routings
1033 where assembly_item_id = pConfigid
1034 and organization_id = lOrgId
1035 and alternate_routing_designator is NULL;
1036 exception
1037 when no_data_found then
1038 lcfm_routing_flag :=2;
1039 end;
1040 IF PG_DEBUG <> 0 THEN
1041 oe_debug_pub.add ('delink_item: Routing flag ( if 1, flow routing ) = '||to_char(lcfm_routing_flag), 2);
1042 END IF;
1043
1044 -- Check if flow schedule exist
1045 -- 2784045 : This 'if' condition is decoupled from flow_sch_exist to make the code more efficient
1046 if ( lcfm_routing_flag = 1 ) then
1047 select count(*)
1048 into lflow_schedule_exist
1049 from wip_flow_schedules
1050 where demand_source_line = to_char(lConfigLineId)
1051 and primary_item_id = pConfigid
1052 and demand_source_type = 2 ;
1053
1054 IF PG_DEBUG <> 0 THEN
1055 oe_debug_pub.add ('delink_item: Flow Schedule exist ( if > 0 ) = '||to_char(lflow_schedule_exist), 2);
1056 END IF;
1057
1058 -- Call MRP API unlink_order_line if flow schedule exist and routing is flow_routing
1059 -- 2784045 if ( lcfm_routing_flag = 1 ) and ( lflow_schedule_exist > 0 ) then
1060 if ( lflow_schedule_exist > 0 ) then
1061 MRP_Flow_Schedule_PUB.unlink_order_line
1062 (
1063 p_api_version_number => 1.0,
1064 x_return_status => l_status,
1065 x_msg_count => l_msg_count,
1066 x_msg_data => l_msg_data,
1067 p_assembly_item_id => pConfigid ,
1068 p_line_id => lConfigLineId
1069 );
1070
1071 if l_status = FND_API.G_RET_STS_ERROR then
1072 IF PG_DEBUG <> 0 THEN
1073 oe_debug_pub.add ('delink_item: ' || 'Error: Failed in MRP_Flow_Schedule_PUB.unlink_order_line with expected error.', 1);
1074 END IF;
1075
1076 /* Bugfix 2454788 */
1077 raise FND_API.G_EXC_ERROR;
1078
1079 elsif l_status = FND_API.G_RET_STS_UNEXP_ERROR then
1080 IF PG_DEBUG <> 0 THEN
1081 oe_debug_pub.add ('delink_item: ' || 'Error: Failed in MRP_Flow_Schedule_PUB.unlink_order_line with unexpected error.', 1);
1082 END IF;
1083 xMessageName := 'CTO_DELINK_ITEM_ERROR';
1084 raise FND_API.G_EXC_UNEXPECTED_ERROR;
1085
1086 elsif l_status = fnd_api.g_ret_sts_success then
1087 IF PG_DEBUG <> 0 THEN
1088 oe_debug_pub.add ('delink_item: ' || 'Removed config line reference from flow schedule', 2);
1089 END IF;
1090 -- Check for l_resv_flag. If it is "N" , set it to "Y" .
1091 -- The Flag is set to Yes, so that we can call the notification later.
1092 If l_resv_flag = 'N' then
1093 l_resv_flag := 'Y';
1094 end if;
1095 end if;
1096 end if; -- flow_sch > 0
1097 end if; -- 2784045 cfm_routing_flag = 1
1098
1099 -- end bugfix 2745590
1100
1101 lStmtNumber := 515;
1102
1103 --
1104 -- will allow delink even if flow schedules exist
1105 --
1106
1107
1108 /*--------------------------------------------------------+
1109 Get the Auto Unreserve flag
1110 +--------------------------------------------------------*/
1111 --
1112 -- The auto unreserve flag was being passed by OE in 11.0.
1113 -- Auto Unrsv flag = 'N' => do not delink
1114 -- Auto Unrsv flag = 'Y' => perform delink
1115 -- The flag was always being passed as 'Y', so there is no
1116 -- purpose of having a flag
1117 --
1118
1119 /*----------------------------------+
1120 Get the WIP parameter
1121 "Respond to sales order changes"
1122 +-----------------------------------*/
1123 lStmtNumber := 517;
1124
1125
1126 /* BUG#2234858 Sushant Added this condition for drop ship project */
1127
1128 if( v_source_type_code = 'INTERNAL' ) then
1129
1130 --call wip api if there are no work orders
1131 if work_orders_exist( lConfigLineId,
1132 xErrorMessage,
1133 xMessageName,
1134 xTableName)
1135 then
1136 IF PG_DEBUG <> 0 THEN
1137 oe_debug_pub.add ('delink_item: ' || 'work orders exist', 2);
1138 END IF;
1139
1140 -- Added by Renga Kannan on 03/13/2001
1141 -- The Flag is to Yes, So that we can call the notification later in this
1142 -- Function.
1143 l_resv_flag := 'Y';
1144
1145 WIP_SO_RESERVATIONS.respond_to_change_order(
1146 p_org_id => lOrgId,
1147 p_header_id => lSalesOrderId,
1148 p_line_id => lConfigLineId,
1149 x_status => l_return_status,
1150 x_msg_count => l_msg_count,
1151 x_msg_data => l_msg_data);
1152
1153 if l_return_status = FND_API.G_RET_STS_ERROR then
1154 IF PG_DEBUG <> 0 THEN
1155 oe_debug_pub.add ('delink_item: ' || 'Error: Failed in wip_so_reservations.respond_to_change_order with expected error.', 1);
1156 END IF;
1157
1158 /* Bugfix 2454788 */
1159 raise FND_API.G_EXC_ERROR;
1160
1161 elsif l_return_status = FND_API.G_RET_STS_UNEXP_ERROR then
1162 IF PG_DEBUG <> 0 THEN
1163 oe_debug_pub.add ('delink_item: ' || 'Error: Failed in wip_so_reservations.respond_to_change_order with unexpected error.', 1);
1164 END IF;
1165 xMessageName := 'CTO_DELINK_ITEM_ERROR';
1166 raise FND_API.G_EXC_UNEXPECTED_ERROR;
1167 end if;
1168
1169 else
1170 IF PG_DEBUG <> 0 THEN
1171 oe_debug_pub.add ('delink_item: ' || 'WOS does not exist', 2);
1172 END IF;
1173 l_return_status := FND_API.G_RET_STS_SUCCESS;
1174 end if;
1175
1176 IF PG_DEBUG <> 0 THEN
1177 oe_debug_pub.add ('delink_item: ' || 'Resp to SO changes returned' || l_return_status, 2);
1178
1179 oe_debug_pub.add ('delink_item: ' || 'Resp to SO changes returned with msg : ' || l_msg_data, 2);
1180 END IF;
1181
1182 lStmtNumber := 518;
1183 if (l_return_status = FND_API.G_RET_STS_SUCCESS) then
1184
1185 OPEN reservations;
1186 LOOP
1187 FETCH reservations into l_rsv.reservation_id;
1188 EXIT when reservations%NOTFOUND;
1189
1190 -- call INV delete_reservations API
1191 INV_RESERVATION_PUB.delete_reservation
1192 (
1193 p_api_version_number => 1.0
1194 , p_init_msg_lst => fnd_api.g_true
1195 , x_return_status => l_status
1196 , x_msg_count => l_msg_count
1197 , x_msg_data => l_msg_data
1198 , p_rsv_rec => l_rsv
1199 , p_serial_number => l_dummy_sn
1200 );
1201
1202 IF PG_DEBUG <> 0 THEN
1203 oe_debug_pub.add ('delink_item: ' || 'After deleting rsv, rsv_id = '||to_char(l_rsv.reservation_id)||', l_status = '||l_status, 2);
1204 END IF;
1205 IF l_status = fnd_api.g_ret_sts_success THEN
1206 IF PG_DEBUG <> 0 THEN
1207 oe_debug_pub.add ('delink_item: ' || 'reservations deleted', 2);
1208 END IF;
1209 -- Added by Renga Kannan on 03/13/2001
1210 -- The Flag is to Yes, So that we can call the notification later in this
1211 -- Function.
1212 l_resv_flag := 'Y';
1213
1214 ELSE
1215 IF l_msg_count = 1 THEN
1216 IF PG_DEBUG <> 0 THEN
1217 oe_debug_pub.add ('delink_item: ' || 'Error in rsv delete', 1);
1218
1219 oe_debug_pub.add ('delink_item: ' || 'l_msg_data ='||l_msg_data, 1);
1220 END IF;
1221
1222 CLOSE reservations;
1223
1224 xMessageName := 'CTO_DELINK_ITEM_ERROR';
1225 raise FND_API.G_EXC_ERROR;
1226
1227 ELSE
1228 FOR l_index IN 1..l_msg_count LOOP
1229 IF PG_DEBUG <> 0 THEN
1230 oe_debug_pub.add ('delink_item: ' || 'Error in rsv delete', 1);
1231
1232 oe_debug_pub.add ('delink_item: ' || 'l_msg_data ='||l_msg_data, 1);
1233 END IF;
1234 END LOOP;
1235
1236 CLOSE reservations;
1237
1238 xMessageName := 'CTO_DELINK_ITEM_ERROR';
1239 raise FND_API.G_EXC_ERROR;
1240 END IF;
1241 END IF;
1242 END LOOP;
1243 CLOSE reservations;
1244 IF PG_DEBUG <> 0 THEN
1245 oe_debug_pub.add ('delink_item: ' || 'After reservations cursor loop', 2);
1246 END IF;
1247
1248 end if; /* end check l_return_status */
1249
1250 -- rkaza. ireq project. 05/13/2005.
1251 -- Delete any records in req interface for this config line.
1252
1253 cto_change_order_pk.delete_from_req_interface(
1254 p_line_id => lConfigLineId,
1255 p_item_id => pConfigId,
1256 x_return_status => l_return_status ) ;
1257
1258 if l_Return_Status = FND_API.G_RET_STS_UNEXP_ERROR then
1259 raise FND_API.G_EXC_UNEXPECTED_ERROR;
1260 elsif l_Return_Status = FND_API.G_RET_STS_ERROR then
1261 raise FND_API.G_EXC_ERROR;
1262 end if;
1263
1264 end if ; /* source_type_code = 'INTERNAL' */
1265
1266
1267
1268
1269
1270
1271 /* BUG#2234858 Sushant added the end if statement for drop ship project */
1272
1273
1274 --delink
1275
1276 -- Added by Renga Kannan on 02/02/2001
1277 -- Before Checking for workflow status for model check if the
1278 -- the model line is canceled. If canceled we should not check the
1279 -- work flow status as the status is already modified by OM.
1280
1281 /*-----------------------------------------+
1282 Getting the activity status code
1283 +-----------------------------------------*/
1284 SELECT nvl(cancelled_flag,'N')
1285 INTO lcancel_flag --- Reusing the variable
1286 FROM OE_ORDER_LINES_ALL
1287 WHERE line_id = pModelLineId;
1288
1289 lStmtNumber := 520;
1290
1291 IF lcancel_flag <> 'Y' THEN
1292 IF PG_DEBUG <> 0 THEN
1293 oe_debug_pub.add('delink_item: ' || 'The model line is not cancelled',2);
1294 END IF;
1295
1296
1297 begin
1298
1299
1300 select activity_status
1301 into lWfStat
1302 from wf_item_activity_statuses was
1303 where was.item_type = 'OEOL'
1304 and was.item_key = to_char(pModelLineId)
1305 and was.activity_status = 'NOTIFIED'
1306 and was.process_activity in
1307 (SELECT wpa.instance_id
1308 FROM wf_process_activities wpa
1309 WHERE wpa.activity_name = 'WAIT_FOR_CTO');
1310
1311
1312 v_model_line_activity := 'WAIT_FOR_CTO' ;
1313
1314
1315 exception
1316 when no_data_found then
1317
1318
1319 v_aps_version := msc_atp_global.get_aps_version ;
1320
1321 oe_debug_pub.add('link_config: ' || 'APS version::'|| v_aps_version , 2);
1322
1323 if( v_aps_version <> 10 ) then
1324
1325 raise no_data_found ;
1326
1327 else
1328
1329 oe_debug_pub.add('link_config: ' || 'Model Line workflow need not be at WAIT_FOR_CTO as APS version::'|| v_aps_version , 2);
1330
1331 v_model_line_activity := 'NOT_AT_WAIT_FOR_CTO' ;
1332
1333
1334 end if ;
1335
1336 when others then
1337
1338 raise ;
1339
1340 end ;
1341
1342
1343 ELSE
1344 IF PG_DEBUG <> 0 THEN
1345 oe_debug_pub.add('delink_item: ' || 'Model Line is cancelled..',2);
1346 END IF;
1347 END IF;
1348
1349 IF PG_DEBUG <> 0 THEN
1350 oe_debug_pub.add ('delink_item: ' || 'calling OE_CONFIG_UTIL.delink_config',2);
1351 END IF;
1352
1353 /*------------------------------------------------------+
1354 We are not calling prcess_order api directly because
1355 OM needs to differentiate a delink request by this
1356 function and a delete line request from form and
1357 over-ride or honor security constraints accordingly.
1358 That can be done by the private api but not with
1359 the public process order api
1360 +------------------------------------------------------*/
1361
1362 lstmtNumber := 523;
1363
1364 -- This Part of the code is added by Renga Kannan on 03/13/2001
1365 -- This needs to be passed to the notification
1366 -- procedure later in this function.
1367
1368 l_ml_mo_flag := 'Y' ; /* Notifications should be sent for delink configuration in all scenarios */
1369
1370 lStmtNumber := 530;
1371
1372
1373
1374
1375
1376 OE_CONFIG_UTIL.delink_config(
1377 p_line_id => lConfigLineId,
1378 x_return_status => l_return_status);
1379
1380 IF PG_DEBUG <> 0 THEN
1381 oe_debug_pub.add ('delink_item: ' || 'oe_config_util.delink_config returned' || l_return_status ,1);
1382 END IF;
1383
1384 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
1385
1386 IF PG_DEBUG <> 0 THEN
1387 oe_debug_pub.add('delink_item: ' || 'Expected error in OE_CONFIG_UTIL.delink_config procedure....',3);
1388 END IF;
1389
1390 /* Bugfix 2454788 */
1391 raise FND_API.G_EXC_ERROR;
1392
1393
1394 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1395 IF PG_DEBUG <> 0 THEN
1396 oe_debug_pub.add ('delink_item: ' || 'Unexpected Error in oe_config_util.delink_config.');
1397 END IF;
1398
1399 xMessageName := 'CTO_DELINK_ITEM_ERROR';
1400 raise FND_API.G_EXC_UNEXPECTED_ERROR;
1401
1402 END IF;
1403
1404
1405
1406 oe_globals.g_cascading_request_logged := TRUE;
1407
1408
1409 /* BUG#2234858
1410 ** Need to allow the following functionality for non drop shipped items
1411 */
1412
1413 if( v_source_type_code = 'INTERNAL' ) then
1414
1415
1416
1417 --
1418 -- update visible demand flag to 'Y' for model and options
1419 --
1420
1421 IF PG_DEBUG <> 0 THEN
1422 oe_debug_pub.add ('delink_item: ' || 'delink : visible demand flag : before selecting options ', 2);
1423 END IF;
1424
1425 lStmtNumber := 533;
1426
1427 --- Added by Renga Kannan on 02/02/2001
1428 --- We have decided not to call process order API to change
1429 --- Flag setting. Instead we will update the flags in OE_ORDER_LINES_ALL
1430 --- directly. This decision is taken during change order project.
1431 --- Updating OE_ORDE_LINES_ALL directly instead of calling Process order
1432 --- API was recommended by Rajeev Bellamkonda from OM team. Date 02/02/2001
1433
1434
1435 IF PG_DEBUG <> 0 THEN
1436 oe_debug_pub.add ('delink_item: ' || 'l_ml_mo_flag = '|| l_ml_mo_flag, 2);
1437 END IF;
1438
1439
1440
1441 /* Changes related to Patchset J */
1442 -- Fixed bug 5470466
1443 -- We should not update visible demand flag to 'Y' for
1444 -- unscheduled orders. Added a condition to check
1445 -- if the line is scheduled or not
1446
1447 UPDATE OE_ORDER_LINES_ALL
1448 SET visible_demand_flag = 'Y'
1449 WHERE ato_line_id = pModelLineId
1450 and header_id = l_header_id
1451 and open_flag = 'Y'
1452 and schedule_status_code is not null; -- 5470466
1453
1454
1455 end if ; /* source_type_code = 'INTERNAL' */
1456
1457 /* BUG#2234858 Modified by Sushant for Drop SHip project */
1458
1459
1460
1461
1462
1463 lStmtNumber := 540;
1464 -- What do we do in case of cancellation
1465
1466
1467 oe_debug_pub.add( 'model line status ' || v_model_line_activity , 1 ) ;
1468
1469
1470
1471
1472 IF lcancel_flag <> 'Y' and v_model_line_activity = 'WAIT_FOR_CTO' THEN --- If it is not cancellation
1473 wf_engine.CompleteActivityInternalName('OEOL',
1474 to_char(pModelLineId),
1475 'WAIT_FOR_CTO',
1476 'DE_LINK');
1477 END IF;
1478
1479
1480
1481
1482
1483
1484
1485 --
1486 -- deleting from bom_cto_order_lines and bom_cto_src_orgs
1487 -- for this top ato line id
1488 --
1489
1490 lStmtNumber := 550;
1491
1492 /* BUG#2234858 Sushant Modified this code for Drop Ship Project */
1493
1494 /* Changes for Patchset J
1495 added reference to package msc_atp_global
1496 pre-req aru 3111677
1497 */
1498
1499 v_aps_version := msc_atp_global.get_aps_version ;
1500
1501 if( v_aps_version <> 10) then
1502 oe_debug_pub.add('delink_item: ' || 'APS version::'|| v_aps_version , 2);
1503
1504 if( v_source_Type_code = 'INTERNAL') then
1505
1506
1507
1508 IF lcancel_flag <> 'Y' THEN --- If it is not cancellation
1509
1510 lStmtNumber := 570;
1511
1512 --to delete the row corresponding to CID in BCOD table
1513 delete from bom_cto_order_demand
1514 where ato_line_id=pModelLineId
1515 and inventory_item_id=pConfigId;
1516
1517 --updating the demand_visible flag to yes in BCOD table CID removal
1518 lStmtNumber := 580;
1519
1520 update bom_cto_order_demand
1521 set demand_visible = 'Y'
1522 where ato_line_id =pModelLineId;
1523
1524 END IF;
1525
1526
1527
1528 end if ;
1529
1530 else
1531
1532 oe_debug_pub.add('delink_item: ' || 'APS version::'|| v_aps_version , 2);
1533
1534 end if; /* reference to get_aps_version */
1535
1536
1537
1538
1539 /* BUG#2234858 Sushant Modified this code for Drop Ship Project */
1540
1541 -- The following block of code is added by Renga Kannan on 03/13/2001.
1542 -- When Customer delinks an config item that needs to be notified to the
1543 -- Planner if Reservation exists for this item. But this de-link code
1544 -- Can be get called from the change_order package itself. In this case the
1545 -- Change order pkg will send the notification. This procedure need not do anything.
1546 -- This will be accomplished by the following logic. Whenever Delink_function is called
1547 -- from CTO_CHANGE_ORDER_PK the package variable CHANGE_ORDER_PK_STATE is set to 1. Otherwise
1548 -- it is defaulted to 0. So in this function we will call the notification only if this
1549 -- Pkg variable value is zero and l_resv_flag is set to 'Y'. This flag is set to 'Y' in the
1550 -- Begining part of this function.
1551
1552 lStmtNumber := 590;
1553
1554 /* BUG#2234858 Sushant Modified this code for Drop Ship Project
1555 ** No notifications should be sent for drop shipped items
1556 */
1557 IF ( CTO_CHANGE_ORDER_PK.change_order_pk_state = 0
1558 and ( l_resv_flag = 'Y' or l_ml_mo_flag = 'Y')
1559 and v_source_type_code = 'INTERNAL' )
1560 THEN
1561
1562 IF PG_DEBUG <> 0 THEN
1563 oe_debug_pub.add('delink_item: ' || 'Delink Action performed, Need to call notification...',2);
1564 END IF;
1565 lStmtNumber := 600;
1566 SELECT Order_number
1567 INTO l_order_number
1568 FROM OE_ORDER_HEADERS_ALL A,
1569 OE_ORDER_LINES_ALL B
1570 WHERE B.line_id = pModelLineId
1571 AND A.Header_id = B.Header_Id;
1572
1573 IF PG_DEBUG <> 0 THEN
1574 oe_debug_pub.add('delink_item: ' || 'Calling Notification Pkg',2);
1575
1576 oe_debug_pub.add('delink_item: ' || 'Order Number = '||to_char(l_order_number),3);
1577
1578 oe_debug_pub.add('delink_item: ' || 'Line id = '||to_char(pModelLineId),3);
1579 END IF;
1580
1581 pchgtype(1).change_type := CTO_CHANGE_ORDER_PK.DELINK_ACTION;
1582 pchgtype(1).old_value := null;
1583 pchgtype(1).new_value := null;
1584
1585 lStmtNumber := 610;
1586 CTO_CHANGE_ORDER_PK.Start_work_flow(
1587 porder_no => l_order_number,
1588 pline_no => pModelLineId,
1589 pchgtype => pchgtype,
1590 pmlmo_flag => l_ml_mo_flag,
1591 pConfig_Id => pConfigId, --bugfix 2782394
1592 x_return_status => l_return_status,
1593 x_msg_count => l_msg_count,
1594 x_msg_data => l_msg_data);
1595
1596
1597 IF l_return_status = FND_API.G_RET_STS_ERROR THEN
1598 IF PG_DEBUG <> 0 THEN
1599 oe_debug_pub.add('delink_item: ' || 'Expected error in change_notify procedure....',1);
1600 END IF;
1601
1602
1603 /* Bugfix 2454788 */
1604 raise FND_API.G_EXC_ERROR;
1605
1606 ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
1607 IF PG_DEBUG <> 0 THEN
1608 oe_debug_pub.add('delink_item: ' || 'Unexpected error occurred in change_notify...',1);
1609 END IF;
1610 xMessageName := 'CTO_DELINK_ITEM_ERROR';
1611 raise FND_API.G_EXC_UNEXPECTED_ERROR;
1612
1613 END IF;
1614
1615 END IF;
1616
1617 --Begin Bugfix 1997355
1618
1619 lStmtNumber := 611;
1620
1621 index_counter_delink := 1;
1622 OPEN delink_lines;
1623 /* creating array of lines where ato_line_id = model line id */
1624 LOOP
1625 FETCH delink_lines into vLineId;
1626 EXIT WHEN delink_lines%NOTFOUND;
1627 p_config_line_arr_delink(index_counter_delink) := vLineId ;
1628 index_counter_delink := index_counter_delink + 1 ;
1629 END LOOP;
1630
1631
1632
1633 /* Since oe_config_util.delink_config deleted lConfigLineId from oe_order_lines_all before
1634 opening delink_lines cursor , lConfigLineId needs to be passed explicitely */
1635
1636 p_config_line_arr_delink(index_counter_delink) := lConfigLineId;
1637 CLOSE delink_lines;
1638
1639 MRP_OM_API_PK.MRP_OM_Interface
1640 (p_line_tbl => p_config_line_arr_delink,
1641 x_return_status => l_return_status_delink);
1642
1643 IF PG_DEBUG <> 0 THEN
1644 oe_debug_pub.add ('delink_item: ' || 'Return status from MRP_OM_Interface - Delink: '||l_return_status_delink,2);
1645 END IF;
1646
1647 if l_return_status_delink = FND_API.G_RET_STS_ERROR then
1648 IF PG_DEBUG <> 0 THEN
1649 oe_debug_pub.add ('delink_item: ' || 'Failed in MRP_OM_API_PK.mrp_om_interface with expected error.', 1);
1650 END IF;
1651
1652 /* Bugfix 2454788 */
1653
1654 raise FND_API.G_EXC_ERROR;
1655
1656 elsif l_return_status_delink = FND_API.G_RET_STS_UNEXP_ERROR then
1657 IF PG_DEBUG <> 0 THEN
1658 oe_debug_pub.add ('delink_item: ' || 'Failed in MRP_OM_API_PK.mrp_om_interface with unexpected error.', 1);
1659 END IF;
1660
1661
1662 xMessageName := 'CTO_DELINK_ITEM_ERROR';
1663 raise FND_API.G_EXC_UNEXPECTED_ERROR;
1664
1665 end if;
1666
1667 --End Bugfix 1997355
1668
1669 return(1);
1670
1671 EXCEPTION
1672
1673 when NO_DATA_FOUND then
1674 IF PG_DEBUG <> 0 THEN
1675 oe_debug_pub.add('delink_item: ' || 'ERROR: CTOCITMB delink::ndf::'||to_char(lStmtNumber)||sqlerrm, 1);
1676 END IF;
1677 if lStmtNumber = 520 then
1678 xMessageName := 'CTO_DELINK_ITEM_ERROR';
1679 xErrorMessage := 'ERROR: CTOCITMB.delink:'||to_char(lStmtNumber)||
1680 ':' || 'WAIT_FOR_CTO activity is not Notified' ;
1681 else
1682 xErrorMessage := 'ERROR: CTOCITMB.delink:'||to_char(lStmtNumber)||
1683 ':' || 'Can not find Config Line';
1684 xMessageName := 'CTO_DELINK_ITEM_ERROR';
1685 end if;
1686 return(0);
1687
1688
1689 when FND_API.G_EXC_ERROR then
1690
1691 if( xMessageName is null ) then /* xMessageName can be not null in case of CTO_DELINK_SHIPPING_ERROR */
1692 /* Bugfix 2454788 */
1693 CTO_MSG_PUB.Count_And_Get(
1694 p_msg_count => lCount,
1695 p_msg_data => xErrorMessage
1696 );
1697 IF PG_DEBUG <> 0 THEN
1698 oe_debug_pub.add ('delink_item: ' || 'ERROR: CTOCITMB.delink:' || to_char(lStmtNumber)|| xErrorMessage,1);
1699 END IF;
1700
1701
1702 /* Bugfix 2454788 */
1703 /* The current Delink Architecture is dependent on passing the error message in the xMessageName variable.*/
1704
1705 if( xErrorMessage is not null ) then
1706 fnd_message.parse_encoded( xErrorMessage , v_appl_name, v_error_name ) ;
1707
1708
1709 IF PG_DEBUG <> 0 THEN
1710 oe_debug_pub.add ('delink_item: ' || 'ERROR: CTOCITMB.delink: appl_name ' || v_appl_name ,1);
1711 oe_debug_pub.add ('delink_item: ' || 'ERROR: CTOCITMB.delink: error_name ' || v_error_name ,1);
1712 END IF;
1713
1714
1715 xErrorMessage := v_error_name;
1716 xMessageName := v_error_name;
1717
1718 else
1719
1720
1721 xMessageName := 'CTO_DELINK_ITEM_ERROR' ;
1722 IF PG_DEBUG <> 0 THEN
1723 oe_debug_pub.add ('delink_item: ' || 'ERROR: CTOCITMB.delink: xErrorMessage is null ' ,1);
1724 oe_debug_pub.add ('delink_item: ' || 'ERROR: CTOCITMB.delink: xMessageName is now ' || xMessageName,1);
1725 END IF;
1726
1727
1728 end if ;
1729
1730 else
1731 IF PG_DEBUG <> 0 THEN
1732 oe_debug_pub.add ('delink_item: ' || 'ERROR: CTOCITMB.delink: xMessageName was already set ' || xMessageName,1);
1733 END IF;
1734 end if;
1735
1736 return(0);
1737
1738
1739 when FND_API.G_EXC_UNEXPECTED_ERROR then
1740 CTO_MSG_PUB.Count_And_Get(
1741 p_msg_count => lCount,
1742 p_msg_data => xErrorMessage
1743 );
1744 IF PG_DEBUG <> 0 THEN
1745 oe_debug_pub.add ('delink_item: ' || 'ERROR: CTOCITMB.delink:' || to_char(lStmtNumber)|| xErrorMessage,1);
1746 END IF;
1747 return(0);
1748
1749
1750 when OTHERS then
1751 IF PG_DEBUG <> 0 THEN
1752 oe_debug_pub.add('delink_item: ' || 'delink::others::'||sqlerrm, 1);
1753 END IF;
1754 xMessageName := 'CTO_DELINK_ITEM_ERROR';
1755 xErrorMessage := 'ERROR: CTOCITMB.delink:'||to_char(lStmtNumber)||
1756 ':' || substrb(sqlerrm,1,150);
1757 CTO_MSG_PUB.Count_And_Get(
1758 p_msg_count => lCount,
1759 p_msg_data => xErrorMessage
1760 );
1761 return(0);
1762
1763 end delink_item;
1764
1765
1766 function load_mandatory_comps(
1767 pLineId in number,
1768 pReqDate in oe_order_lines_all.schedule_ship_date%type,
1769 xGrpId out NOCOPY number,
1770 xErrorMessage out NOCOPY varchar2 ,
1771 xMessageName out NOCOPY varchar2 ,
1772 xTableName out NOCOPY varchar2 )
1773 return integer
1774 is
1775
1776 level_number number := 0;
1777 v_max_level_number number := 0;
1778 lStmtNumber number := 0;
1779 lGrpId number;
1780 rowcount number := 1;
1781 proc_error exception ;
1782
1783 v_msi_fixed_lead_time mtl_system_items.fixed_lead_time%type ;
1784 v_msi_variable_lead_time mtl_system_items.variable_lead_time%type ;
1785
1786 /*Bugfix 2047428 */
1787 latpcompflag mtl_system_items.atp_components_flag%type;
1788 /* End Bugfix 2047428 */
1789
1790 -- Bugfix 2425667
1791 lrowcount number;
1792 -- Bugfix 2425667
1793
1794 -- 3893281 : New debug cursor and variables
1795 cursor debug_bet is
1796 select bet.top_bill_sequence_id,
1797 bet.bill_sequence_id,
1798 bet.organization_id,
1799 bet.sort_order,
1800 bet.plan_level,
1801 bet.line_id,
1802 substrb(msi.concatenated_segments,1,50)
1803 from bom_explosion_temp bet,mtl_system_items_kfv msi
1804 where bet.group_id = xGrpId
1805 and bet.organization_id = msi.organization_id
1806 and bet.component_item_id = msi.inventory_item_id;
1807
1808 d_top_bseq_id number;
1809 d_bseq_id number;
1810 d_org_id number;
1811 d_sort_order varchar2(240);
1812 d_plan_level number;
1813 d_line_id number;
1814 d_item varchar2(50);
1815
1816 -- 3893281
1817
1818 begin
1819
1820 /*---------------------------------------------------+
1821 Insert the Model row details from oe_order_lines
1822 with plan_level =0
1823 The lines have a common group_id, have line_id reference
1824 of oe_order_lines. Top_bill_sequence_id and bill_sequence_id
1825 are not needed however, as they are not null coloumns,
1826 all rows have model's bill_sequence_id in these fields.
1827 +----------------------------------------------------*/
1828
1829
1830
1831 IF PG_DEBUG <> 0 THEN
1832 oe_debug_pub.add ('load_mandatory_comps: ' || ' load mandatory comps ' ,1);
1833 END IF;
1834
1835 if( pReqDate is not null ) then
1836 IF PG_DEBUG <> 0 THEN
1837 oe_debug_pub.add ('load_mandatory_comps: ' || 'parameters passed ' || pLineId || ' date ' || to_char( pReqDate ) ,1);
1838 END IF;
1839 else
1840 IF PG_DEBUG <> 0 THEN
1841 oe_debug_pub.add ('load_mandatory_comps: ' || 'parameters passed date null ' || pLineId ,1);
1842 END IF;
1843 end if ;
1844
1845
1846
1847 /* Bugfix 2047428 */
1848 lStmtNumber := 599;
1849 select NVL(msi.atp_components_flag,'N')
1850 into latpcompflag
1851 from mtl_system_items msi , oe_order_lines_all oel
1852 where oel.inventory_item_id = msi.inventory_item_id
1853 and oel.ship_from_org_id = msi.organization_id
1854 and oel.line_id = pLineId
1855 and oel.ordered_quantity > 0;
1856
1857 If latpcompflag in ('N' , 'R' ) then -- bugfix 3779636
1858 IF PG_DEBUG <> 0 THEN
1859 oe_debug_pub.add ('load_mandatory_comps: ' || 'Exiting Load Mandatory Comps at model level as ATP Component flag is N or R ',1); -- bugfix 3779636
1860 END IF;
1861 return(1);
1862 else
1863
1864 /* End Bugfix 2047428 */
1865 select bom_explosion_temp_s.nextval
1866 into xGrpId
1867 from dual;
1868
1869 -- bugfix 1902818: Added nvl to oel.component_sequence_id.
1870 -- For ATO items, this will be null.
1871
1872 lStmtNumber := 600;
1873 -- Bugfix 1998386 This function multiplies the ordered quantity
1874 -- with conversion factor and returns converted quantity
1875 -- if the order UOM is different from primary UOM of the item.
1876 -- If ordered UOM and primary UOM are same , the function
1877 -- returns the ordered quantity.
1878
1879
1880 insert into bom_explosion_temp(
1881 top_bill_sequence_id,
1882 bill_sequence_id,
1883 organization_id,
1884 sort_order,
1885 component_sequence_id,
1886 component_item_id,
1887 plan_level,
1888 extended_quantity,
1889 primary_uom_code, -- 1998386
1890 top_item_id,
1891 line_id,
1892 group_id)
1893 select
1894 nvl(oel.component_sequence_id,1), -- Top bill sequence id --1902818
1895 nvl(oel.component_sequence_id,1), -- Bill_sequence_id --1902818
1896 oel.ship_from_org_id,
1897 2, -- Sort Order --BUG no 1288823 modification
1898 nvl(oel.component_sequence_id,1), --1902818
1899 oel.inventory_item_id,
1900 0, -- Plan level
1901 -- 1998386
1902 CTO_UTILITY_PK.convert_uom(
1903 oel.order_quantity_uom,
1904 msi.primary_uom_code,
1905 oel.ordered_quantity,
1906 oel.inventory_item_id),
1907 msi.primary_uom_code,
1908 oel.inventory_item_id,
1909 oel.Line_Id,
1910 xGrpId
1911 from
1912 oe_order_lines_all oel,
1913 mtl_system_items msi
1914 where oel.line_id = pLineId
1915 and oel.inventory_item_id = msi.inventory_item_id
1916 and oel.ship_from_org_id = msi.organization_id
1917 and oel.ordered_quantity > 0;
1918
1919 if sql%rowcount = 0 then
1920 IF PG_DEBUG <> 0 THEN
1921 oe_debug_pub.add ('load_mandatory_comps: ' || 'Model Row not found',1);
1922 END IF;
1923 raise proc_error;
1924 end if;
1925
1926 IF PG_DEBUG <> 0 THEN
1927 oe_debug_pub.add('load_mandatory_comps: ' || 'Model Rows : ' || sql%rowcount, 2);
1928 END IF;
1929
1930 /*------------------------------------------------+
1931 Insert all oe_order_lines row for this model
1932 with corrosponding plan_levels
1933 +------------------------------------------------*/
1934 rowcount := 1 ;
1935 while rowcount > 0 LOOP
1936
1937 level_number := level_number + 1;
1938
1939 lStmtNumber := 610;
1940 insert into bom_explosion_temp(
1941 top_bill_sequence_id,
1942 bill_sequence_id,
1943 organization_id,
1944 sort_order,
1945 component_sequence_id,
1946 component_item_id,
1947 plan_level,
1948 extended_quantity,
1949 primary_uom_code, -- Bugfix 1998386
1950 top_item_id,
1951 line_id,
1952 group_id)
1953 -- 3893281 : Commenting Old SELECT
1954 /*
1955 select
1956 bet.top_bill_sequence_id,
1957 bet.bill_sequence_id,
1958 oel.ship_from_org_id, --changed from org_id,
1959 2, -- BUG no 1288823 modification
1960 oel.component_sequence_id,
1961 oel.inventory_item_id,
1962 level_number,
1963
1964 -- Bugfix 1998386 This function multiplies the ordered quantity
1965 -- with conversion factor and returns converted quantity
1966 -- if the order UOM is different from primary UOM of the item .
1967 -- If ordered UOM and primary UOM are same,the function
1968 -- returns the ordered quantity.
1969
1970 CTO_UTILITY_PK.convert_uom(
1971 oel.order_quantity_uom,
1972 msi.primary_uom_code,
1973 oel.ordered_quantity,
1974 oel.inventory_item_id),
1975 msi.primary_uom_code,
1976 bet.top_item_id,
1977 oel.line_id,
1978 xGrpId
1979 from
1980 oe_order_lines_all oel,
1981 bom_explosion_temp bet,
1982 mtl_system_items msi
1983 where oel.ato_line_id = pLineId
1984 and oel.line_id <> pLineId
1985 and oel.inventory_item_id = msi.inventory_item_id
1986 and oel.ship_from_org_id = msi.organization_id
1987 and oel.ordered_quantity > 0
1988 and nvl(oel.cancelled_flag,'N') <> 'Y'
1989 and oel.link_to_line_id = bet.line_id
1990 and oel.item_type_code <> 'CONFIG'
1991 and bet.group_id = xGrpId
1992 and bet.plan_level = level_number -1 ;
1993 */
1994 select
1995 bet.top_bill_sequence_id,
1996 bet.bill_sequence_id,
1997 oel.ship_from_org_id, --changed from org_id,
1998 2, -- BUG no 1288823 modification
1999 oel.component_sequence_id,
2000 oel.inventory_item_id,
2001 level_number,
2002
2003 -- Bugfix 1998386 This function multiplies the ordered quantity
2004 -- with conversion factor and returns converted quantity
2005 -- if the order UOM is different from primary UOM of the item .
2006 -- If ordered UOM and primary UOM are same,the function
2007 -- returns the ordered quantity.
2008
2009 CTO_UTILITY_PK.convert_uom(
2010 oel.order_quantity_uom,
2011 msi.primary_uom_code,
2012 oel.ordered_quantity,
2013 oel.inventory_item_id),
2014 msi.primary_uom_code,
2015 bet.top_item_id,
2016 oel.line_id,
2017 xGrpId
2018 from
2019 oe_order_lines_all oel,
2020 bom_explosion_temp bet,
2021 mtl_system_items msi,
2022 bom_bill_of_materials bbm,
2023 bom_inventory_components bic
2024 where oel.ato_line_id = pLineId
2025 and oel.line_id <> pLineId
2026 and oel.inventory_item_id = msi.inventory_item_id
2027 and oel.ship_from_org_id = msi.organization_id
2028 and oel.ordered_quantity > 0
2029 and nvl(oel.cancelled_flag,'N') <> 'Y'
2030 and oel.link_to_line_id = bet.line_id
2031 and oel.item_type_code <> 'CONFIG' /* BUG 2483920 */
2032 and bet.group_id = xGrpId
2033 and bet.plan_level = level_number -1
2034 and bet.component_item_id = bbm.assembly_item_id
2035 and bet.organization_id = bbm.organization_id
2036 and bbm.alternate_bom_designator is null
2037 and bbm.common_bill_sequence_id = bic.bill_sequence_id
2038 and bic.component_item_id = msi.inventory_item_id
2039 and bic.optional = 1
2040 and ( msi.bom_item_type in (1,2)
2041 OR (msi.bom_item_type = 4 and bic.wip_supply_type = 6 )
2042 OR (msi.bom_item_type = 4 and msi.replenish_to_order_flag = 'Y' ));
2043 -- 3893281
2044 rowcount := SQL%ROWCOUNT;
2045
2046 IF PG_DEBUG <> 0 THEN
2047 oe_debug_pub.add ('load_mandatory_comps: ' || 'Row Count : ' || rowcount, 2);
2048 END IF;
2049
2050 END LOOP;
2051
2052 -- 3893281 following code is to debug BET at this point
2053 open debug_bet;
2054 oe_debug_pub.add ('BET picture after Model and its children are inserted ..' ,1);
2055 loop
2056 fetch debug_bet
2057 into d_top_bseq_id,
2058 d_bseq_id,
2059 d_org_id,
2060 d_sort_order,
2061 d_plan_level,
2062 d_line_id,
2063 d_item;
2064 exit when debug_bet%NOTFOUND;
2065 IF PG_DEBUG <> 0 THEN
2066 oe_debug_pub.add (' Top Bill Seq id '||d_top_bseq_id|| ' Bill Seq Id '||d_bseq_id
2067 ||' Org '||d_org_id ||' Sort Order '||d_sort_order
2068 || ' Plan level '||d_plan_level||' Line Id '||d_line_id
2069 || ' Item '||d_item,1);
2070 END IF;
2071 end loop;
2072 close debug_bet;
2073 -- 3893281
2074
2075 v_max_level_number := level_number ; /* added by sushant to track max level number */
2076
2077 IF PG_DEBUG <> 0 THEN
2078 oe_debug_pub.add ('load_mandatory_comps: ' || 'Group_id : '|| xGrpId, 2);
2079 END IF;
2080
2081
2082
2083 /*
2084 ** BUG no 1288823, new query block added
2085 */
2086
2087 begin
2088
2089 select msi.fixed_lead_time , nvl(msi.variable_lead_time,0)
2090 into v_msi_fixed_lead_time, v_msi_variable_lead_time
2091 from mtl_system_items msi , bom_explosion_temp be
2092 where be.organization_id = msi.organization_id
2093 and be.component_item_id = msi.inventory_item_id
2094 and be.line_id = pLineId
2095 and be.group_id = xGrpId; -- bugfix 1876997
2096
2097 exception
2098
2099 when no_data_found then
2100 xErrorMessage := 'CTOCITMB:'||to_char(lStmtNumber)||': No Data Found ';
2101 return(0);
2102
2103 when others then
2104 xErrorMessage := 'ERROR: CTOCITMB:'||to_char(lStmtNumber)||': other error ';
2105 IF PG_DEBUG <> 0 THEN
2106 oe_debug_pub.add('load_mandatory_comps: ' || 'ERROR: others exception while executing stmt ' ||to_char(lStmtNumber),1);
2107
2108 oe_debug_pub.add('load_mandatory_comps: ' || 'ERROR message : '||sqlerrm,1);
2109 END IF;
2110 return(0);
2111
2112 end ;
2113
2114
2115 /*------------------------------------------------------------+
2116 Start Explosion of all items copied above.
2117 +-----------------------------------------------------------*/
2118
2119 level_number := 0;
2120 IF PG_DEBUG <> 0 THEN
2121 oe_debug_pub.add('load_mandatory_comps: ' || 'Explosion loop' , 2);
2122 END IF;
2123
2124 << Explode_loop >>
2125 LOOP
2126
2127 lStmtNumber := 620;
2128 -- Bug 1985793 Selecting greater of sysdate and calendar date
2129 -- while checking for item effectivity so that planning will get
2130 -- components effective till sysdate.
2131 --apps performance bugfix 4905845, sql id 16103327
2132 insert into bom_explosion_temp(
2133 top_bill_sequence_id,
2134 bill_sequence_id,
2135 organization_id,
2136 sort_order,
2137 component_sequence_id,
2138 component_item_id,
2139 plan_level,
2140 extended_quantity,
2141 primary_uom_code, -- 1998386
2142 top_item_id,
2143 component_quantity,
2144 check_atp,
2145 atp_components_flag,
2146 atp_flag,
2147 bom_item_type,
2148 assembly_item_id,
2149 parent_bom_item_type,
2150 line_id,
2151 wip_supply_type, -- 3254039
2152 group_id)
2153 select
2154 -1 , -- 2897132
2155 bic.bill_sequence_id,
2156 be.organization_id,
2157 evaluate_order( msi2.atp_flag, msi2.atp_components_flag , msi2.bom_item_type ) , /* BUG # 1518894, 1288823 */
2158 -- 1288823
2159 bic.component_sequence_id,
2160 bic.component_item_id,
2161 level_number + 1,
2162 be.extended_quantity * bic.component_quantity,
2163 msi2.primary_uom_code, -- 1998386
2164 be.top_item_id,
2165 bic.component_quantity,
2166 bic.check_atp,
2167 -- 2378556
2168 msi2.atp_components_flag,
2169 msi2.atp_flag,
2170 msi2.bom_item_type,
2171
2172 bom.assembly_item_id,
2173 msi.bom_item_type,
2174 be.line_id , -- 2897132
2175 nvl(bic.wip_supply_type, msi2.wip_supply_type), -- 3254039 , 3298244
2176 xGrpId
2177 from
2178 bom_calendar_dates cal,
2179 mtl_system_items msi, /* PARENT */
2180 mtl_system_items msi2, /* CHILD */
2181 bom_inventory_components bic,
2182 eng_revised_items eri,
2183 bom_bill_of_materials bom,
2184 mtl_parameters mp,
2185 bom_explosion_temp be
2186 where be.sort_order <> 3 -- 1288823
2187 and be.group_id = xGrpId
2188 and nvl(be.plan_level,0) = level_number
2189 and be.organization_id = bom.organization_id
2190 and be.component_item_id = bom.assembly_item_id
2191 and bic.component_quantity <> 0
2192 and bic.revised_item_sequence_id = eri.revised_item_sequence_id (+)
2193 and bic.component_item_id = msi2.inventory_item_id -- 1518894
2194 and bom.organization_id = msi2.organization_id -- 1518894
2195 and bom.alternate_bom_designator is null
2196 and bic.bill_sequence_id = bom.common_bill_sequence_id
2197 and be.organization_id = msi.organization_id
2198 and be.component_item_id = msi.inventory_item_id --BUG#2378556
2199 and mp.organization_id = be.organization_id
2200 and cal.calendar_code = mp.calendar_code
2201 and cal.exception_set_id = mp.calendar_exception_set_id
2202 and cal.calendar_date =
2203 ( select c.calendar_date
2204 from bom_calendar_dates C
2205 where C.calendar_code = mp.calendar_code
2206 and c.exception_set_id = mp.calendar_exception_set_id
2207 and C.seq_num =
2208 (select c2.prior_seq_num -
2209 ceil( nvl( v_msi_fixed_lead_time,0)+
2210 (be.extended_quantity *
2211 v_msi_variable_lead_time ))
2212 from bom_calendar_dates c2
2213 where c2.calendar_code = mp.calendar_code
2214 and c2.exception_set_id = mp.calendar_exception_set_id
2215 and c2.calendar_date = trunc(pReqDate)
2216 )
2217 )
2218
2219 -- 2162912
2220 and TRUNC(bic.effectivity_date) <= greatest(nvl(cal.calendar_date,sysdate),sysdate)
2221 and nvl(TRUNC(bic.disable_date),(nvl(cal.calendar_date,sysdate) + 1)) > nvl(cal.calendar_date,sysdate)
2222
2223 and bic.effectivity_date =
2224 (select
2225 max(effectivity_date)
2226 from bom_inventory_components bic1,
2227 eng_revised_items eri
2228 where bic1.bill_sequence_id = bic.bill_sequence_id
2229 and bic1.component_item_id = bic.component_item_id
2230 and bic1.revised_item_sequence_id =
2231 eri.revised_item_sequence_id (+)
2232 and (decode(bic1.implementation_date, NULL,
2233 bic1.old_component_sequence_id,
2234 bic1.component_sequence_id) =
2235 decode(bic.implementation_date, NULL,
2236 bic.old_component_sequence_id,
2237 bic.component_sequence_id)
2238 OR
2239 bic1.operation_seq_num = bic.operation_seq_num)
2240
2241 -- 2162912
2242 and TRUNC(bic1.effectivity_date) <= greatest(nvl(cal.calendar_date,sysdate),sysdate)
2243 and nvl(TRUNC(bic1.disable_date),(nvl(cal.calendar_date,sysdate) + 1)) > nvl(cal.calendar_date,sysdate)
2244 -- 2162912
2245 and ( nvl(eri.status_type,6) IN (4,6,7))
2246 and not exists
2247 (select
2248 'X'
2249 from bom_inventory_components bicn, eng_revised_items eri1
2250 where bicn.bill_sequence_id + 0 = bic.bill_sequence_id
2251 and bicn.old_component_sequence_id =
2252 bic.component_sequence_id
2253 and bicn.acd_type in (2,3)
2254 and eri1.revised_item_sequence_id = bicn.revised_item_sequence_id
2255 and trunc(bicn.disable_date) <= cal.calendar_date
2256 and ( nvl(eri1.status_type,6) in (4,6,7))
2257 )
2258 )
2259 and bic.optional = 2 /* NOT OPTIONAL */
2260 and msi2.bom_item_type = 4 /* 2400948 */
2261 -- Model or Option Class or ATO ITEM * * BUG#2378556 commented for bug 3314297 mandatory comps should be
2262 -- exploded for standard items
2263
2264 and msi.pick_components_flag <> 'Y' ;
2265
2266 -- start bugfix 2425667
2267 lrowcount := SQL%ROWCOUNT;
2268 IF PG_DEBUG <> 0 THEN
2269 oe_debug_pub.add ('load_mandatory_comps: ' || 'Row Count : ' || lrowcount, 2);
2270 END IF;
2271 -- oe_debug_pub.add('Row Count : ' || SQL%ROWCOUNT);
2272 -- end bugfix 2425667
2273
2274
2275 /* continue exploding atleast till max level number */
2276 -- start bugfix 2425667
2277 -- IF SQL%ROWCOUNT = 0
2278 IF lrowcount = 0
2279 -- end bugfix 2425667
2280 AND level_number >= v_max_level_number THEN
2281 EXIT Explode_loop;
2282 END IF;
2283
2284 level_number := level_number + 1;
2285
2286 END LOOP;
2287 END IF; -- bugfix 2047428
2288
2289
2290 return(1);
2291
2292
2293 exception
2294
2295 when no_data_found then
2296 xErrorMessage := 'CTOCITMB:'||to_char(lStmtNumber)||': No Data Found ';
2297 return(0);
2298 when proc_error then
2299 xErrorMessage := 'CTOCITMB:'||to_char(lStmtNumber)||': Model row not found ';
2300 return(0);
2301 when others then --bugfix 1902818: added others excpn
2302 xErrorMessage := 'load_mandatory_comps:(others excepn)::'||to_char(lStmtNumber)||'::'||substrb(sqlerrm,1,150);
2303 return(0);
2304
2305 end load_mandatory_comps;
2306
2307
2308 -- 3779636
2309 function load_mandatory_comps_pds(
2310 pLineId in number,
2311 pReqDate in oe_order_lines_all.schedule_ship_date%type,
2312 xGrpId out NOCOPY number,
2313 xErrorMessage out NOCOPY varchar2 ,
2314 xMessageName out NOCOPY varchar2 ,
2315 xTableName out NOCOPY varchar2 )
2316 return integer
2317 is
2318
2319 level_number number := 0;
2320 v_max_level_number number := 0;
2321 lStmtNumber number := 0;
2322 lGrpId number;
2323 rowcount number := 1;
2324 proc_error exception ;
2325
2326 v_msi_fixed_lead_time mtl_system_items.fixed_lead_time%type ;
2327 v_msi_variable_lead_time mtl_system_items.variable_lead_time%type ;
2328 latpcompflag mtl_system_items.atp_components_flag%type;
2329 lrowcount number;
2330 begin
2331
2332 /*---------------------------------------------------+
2333 Insert the Model row details from oe_order_lines
2334 with plan_level =0
2335 The lines have a common group_id, have line_id reference
2336 of oe_order_lines. Top_bill_sequence_id and bill_sequence_id
2337 are not needed however, as they are not null coloumns,
2338 all rows have model's bill_sequence_id in these fields.
2339 +----------------------------------------------------*/
2340
2341
2342
2343 IF PG_DEBUG <> 0 THEN
2344 oe_debug_pub.add ('load_mandatory_comps_pds: ' || ' load mandatory comps PDS ' ,1);
2345 END IF;
2346
2347 if( pReqDate is not null ) then
2348 IF PG_DEBUG <> 0 THEN
2349 oe_debug_pub.add ('load_mandatory_comps_pds: ' || 'parameters passed ' || pLineId || ' date ' || to_char( pReqDate ) ,1);
2350 END IF;
2351 else
2352 IF PG_DEBUG <> 0 THEN
2353 oe_debug_pub.add ('load_mandatory_comps_pds: ' || 'parameters passed date null ' || pLineId ,1);
2354 END IF;
2355 end if ;
2356
2357 lStmtNumber := 599;
2358 select NVL(msi.atp_components_flag,'N')
2359 into latpcompflag
2360 from mtl_system_items msi , oe_order_lines_all oel
2361 where oel.inventory_item_id = msi.inventory_item_id
2362 and oel.ship_from_org_id = msi.organization_id
2363 and oel.line_id = pLineId
2364 and oel.ordered_quantity > 0;
2365
2366 If latpcompflag in ( 'N' , 'R' ) then -- 3779636
2367 IF PG_DEBUG <> 0 THEN
2368 oe_debug_pub.add ('load_mandatory_comps_pds: ' || 'Exiting Load Mandatory Comps PDS at model level as ATP Component flag is N or R',1); -- 3779636
2369 END IF;
2370 return(1);
2371 else
2372
2373 select bom_explosion_temp_s.nextval
2374 into xGrpId
2375 from dual;
2376
2377
2378 lStmtNumber := 600;
2379 insert into bom_explosion_temp(
2380 top_bill_sequence_id,
2381 bill_sequence_id,
2382 organization_id,
2383 sort_order,
2384 component_sequence_id,
2385 component_item_id,
2386 plan_level,
2387 extended_quantity,
2388 primary_uom_code,
2389 top_item_id,
2390 line_id,
2391 group_id)
2392 select
2393 nvl(oel.component_sequence_id,1),
2394 nvl(oel.component_sequence_id,1),
2395 oel.ship_from_org_id,
2396 2,
2397 nvl(oel.component_sequence_id,1),
2398 oel.inventory_item_id,
2399 0,
2400 CTO_UTILITY_PK.convert_uom(
2401 oel.order_quantity_uom,
2402 msi.primary_uom_code,
2403 oel.ordered_quantity,
2404 oel.inventory_item_id),
2405 msi.primary_uom_code,
2406 oel.inventory_item_id,
2407 oel.Line_Id,
2408 xGrpId
2409 from
2410 oe_order_lines_all oel,
2411 mtl_system_items msi
2412 where oel.line_id = pLineId
2413 and oel.inventory_item_id = msi.inventory_item_id
2414 and oel.ship_from_org_id = msi.organization_id
2415 and oel.ordered_quantity > 0;
2416
2417 if sql%rowcount = 0 then
2418 IF PG_DEBUG <> 0 THEN
2419 oe_debug_pub.add ('load_mandatory_comps_pds: ' || 'Model Row not found',1);
2420 END IF;
2421 raise proc_error;
2422 end if;
2423
2424 IF PG_DEBUG <> 0 THEN
2425 oe_debug_pub.add('load_mandatory_comps_pds: ' || 'Model Rows : ' || sql%rowcount, 2);
2426 END IF;
2427
2428 /*------------------------------------------------+
2429 Insert all oe_order_lines row for this model
2430 with corrosponding plan_levels
2431 +------------------------------------------------*/
2432 rowcount := 1 ;
2433 while rowcount > 0 LOOP
2434
2435 level_number := level_number + 1;
2436
2437 lStmtNumber := 610;
2438 insert into bom_explosion_temp(
2439 top_bill_sequence_id,
2440 bill_sequence_id,
2441 organization_id,
2442 sort_order,
2443 component_sequence_id,
2444 component_item_id,
2445 plan_level,
2446 extended_quantity,
2447 primary_uom_code,
2448 top_item_id,
2449 line_id,
2450 group_id)
2451 select
2452 bet.top_bill_sequence_id,
2453 bet.bill_sequence_id,
2454 oel.ship_from_org_id,
2455 2,
2456 oel.component_sequence_id,
2457 oel.inventory_item_id,
2458 level_number,
2459 CTO_UTILITY_PK.convert_uom(
2460 oel.order_quantity_uom,
2461 msi.primary_uom_code,
2462 oel.ordered_quantity,
2463 oel.inventory_item_id),
2464 msi.primary_uom_code,
2465 bet.top_item_id,
2466 oel.line_id,
2467 xGrpId
2468 from
2469 oe_order_lines_all oel,
2470 bom_explosion_temp bet,
2471 mtl_system_items msi
2472 where oel.ato_line_id = pLineId
2473 and oel.line_id <> pLineId
2474 and oel.inventory_item_id = msi.inventory_item_id
2475 and oel.ship_from_org_id = msi.organization_id
2476 and msi.bom_item_type in ( 1, 2 ) -- only sub-models and option classes
2477 and oel.ordered_quantity > 0
2478 and nvl(oel.cancelled_flag,'N') <> 'Y'
2479 and oel.link_to_line_id = bet.line_id
2480 and oel.item_type_code <> 'CONFIG'
2481 and bet.group_id = xGrpId
2482 and bet.plan_level = level_number -1 ;
2483
2484 rowcount := SQL%ROWCOUNT;
2485
2486 IF PG_DEBUG <> 0 THEN
2487 oe_debug_pub.add ('load_mandatory_comps_pds: ' || 'Row Count : ' || rowcount, 2);
2488 END IF;
2489
2490 END LOOP;
2491
2492 v_max_level_number := level_number ;
2493
2494 IF PG_DEBUG <> 0 THEN
2495 oe_debug_pub.add ('load_mandatory_comps_pds: ' || 'Group_id : '|| xGrpId, 2);
2496 END IF;
2497
2498
2499 begin
2500
2501 select msi.fixed_lead_time , nvl(msi.variable_lead_time,0)
2502 into v_msi_fixed_lead_time, v_msi_variable_lead_time
2503 from mtl_system_items msi , bom_explosion_temp be
2504 where be.organization_id = msi.organization_id
2505 and be.component_item_id = msi.inventory_item_id
2506 and be.line_id = pLineId
2507 and be.group_id = xGrpId;
2508
2509 exception
2510
2511 when no_data_found then
2512 xErrorMessage := 'CTOCITMB:'||to_char(lStmtNumber)||': No Data Found ';
2513 return(0);
2514
2515 when others then
2516 xErrorMessage := 'ERROR: CTOCITMB:'||to_char(lStmtNumber)||': other error ';
2517 IF PG_DEBUG <> 0 THEN
2518 oe_debug_pub.add('load_mandatory_comps_pds: ' || 'ERROR: others exception while executing stmt ' ||to_char(lStmtNumber),1);
2519
2520 oe_debug_pub.add('load_mandatory_comps_pds: ' || 'ERROR message : '||sqlerrm,1);
2521 END IF;
2522 return(0);
2523
2524 end ;
2525
2526
2527 /*------------------------------------------------------------+
2528 Start Explosion of all items copied above.
2529 +-----------------------------------------------------------*/
2530
2531 level_number := 0;
2532 IF PG_DEBUG <> 0 THEN
2533 oe_debug_pub.add('load_mandatory_comps_pds: ' || 'Explosion loop' , 2);
2534 END IF;
2535
2536 << Explode_loop >>
2537 LOOP
2538
2539 lStmtNumber := 620;
2540 --apps perf bug#4905845,sql id 16103462
2541 --reduce comments to decrease shared memory
2542 insert into bom_explosion_temp(
2543 top_bill_sequence_id,
2544 bill_sequence_id,
2545 organization_id,
2546 sort_order,
2547 component_sequence_id,
2548 component_item_id,
2549 plan_level,
2550 extended_quantity,
2551 primary_uom_code,
2552 top_item_id,
2553 component_quantity,
2554 check_atp,
2555 atp_components_flag,
2556 atp_flag,
2557 bom_item_type,
2558 assembly_item_id,
2559 parent_bom_item_type,
2560 line_id,
2561 wip_supply_type,
2562 group_id)
2563 select
2564 -1 ,
2565 bic.bill_sequence_id,
2566 be.organization_id,
2567 evaluate_order( msi2.atp_flag, msi2.atp_components_flag , msi2.bom_item_type ) ,
2568 bic.component_sequence_id,
2569 bic.component_item_id,
2570 level_number + 1,
2571 be.extended_quantity * bic.component_quantity,
2572 msi2.primary_uom_code,
2573 be.top_item_id,
2574 bic.component_quantity,
2575 bic.check_atp,
2576 msi2.atp_components_flag,
2577 msi2.atp_flag,
2578 msi2.bom_item_type,
2579 bom.assembly_item_id,
2580 msi.bom_item_type,
2581 be.line_id ,
2582 nvl(bic.wip_supply_type, msi2.wip_supply_type),
2583 xGrpId
2584 from
2585 bom_calendar_dates cal,
2586 mtl_system_items msi,
2587 mtl_system_items msi2,
2588 bom_inventory_components bic,
2589 eng_revised_items eri,
2590 bom_bill_of_materials bom,
2591 mtl_parameters mp,
2592 bom_explosion_temp be
2593 where be.sort_order <> 3
2594 and be.group_id = xGrpId
2595 and nvl(be.plan_level,0) = level_number
2596 and be.organization_id = bom.organization_id
2597 and be.component_item_id = bom.assembly_item_id
2598 and bic.component_quantity <> 0
2599 and bic.revised_item_sequence_id = eri.revised_item_sequence_id (+)
2600 and bic.component_item_id = msi2.inventory_item_id
2601 and bom.organization_id = msi2.organization_id
2602 and bom.alternate_bom_designator is null
2603 and bic.bill_sequence_id = bom.common_bill_sequence_id
2604 and be.organization_id = msi.organization_id
2605 and be.component_item_id = msi.inventory_item_id
2606 and mp.organization_id = be.organization_id
2607 and cal.calendar_code = mp.calendar_code
2608 and cal.exception_set_id = mp.calendar_exception_set_id
2609 and cal.calendar_date =
2610 ( select c.calendar_date
2611 from bom_calendar_dates C
2612 where C.calendar_code = mp.calendar_code
2613 and c.exception_set_id = mp.calendar_exception_set_id
2614 and C.seq_num =
2615 (select c2.prior_seq_num -
2616 ceil( nvl( v_msi_fixed_lead_time,0)+
2617 (be.extended_quantity *
2618 v_msi_variable_lead_time ))
2619 from bom_calendar_dates c2
2620 where c2.calendar_code = mp.calendar_code
2621 and c2.exception_set_id = mp.calendar_exception_set_id
2622 and c2.calendar_date = trunc(pReqDate)
2623 )
2624 )
2625 and TRUNC(bic.effectivity_date) <= greatest(nvl(cal.calendar_date,sysdate),sysdate)
2626 and nvl(TRUNC(bic.disable_date),(nvl(cal.calendar_date,sysdate) + 1)) > nvl(cal.calendar_date,sysdate)
2627 and bic.effectivity_date =
2628 (select
2629 max(effectivity_date)
2630 from bom_inventory_components bic1,
2631 eng_revised_items eri
2632 where bic1.bill_sequence_id = bic.bill_sequence_id
2633 and bic1.component_item_id = bic.component_item_id
2634 and bic1.revised_item_sequence_id =
2635 eri.revised_item_sequence_id (+)
2636 and (decode(bic1.implementation_date, NULL,
2637 bic1.old_component_sequence_id,
2638 bic1.component_sequence_id) =
2639 decode(bic.implementation_date, NULL,
2640 bic.old_component_sequence_id,
2641 bic.component_sequence_id)
2642 OR
2643 bic1.operation_seq_num = bic.operation_seq_num)
2644 and TRUNC(bic1.effectivity_date) <= greatest(nvl(cal.calendar_date,sysdate),sysdate)
2645 and nvl(TRUNC(bic1.disable_date),(nvl(cal.calendar_date,sysdate) + 1)) > nvl(cal.calendar_date,sysdate)
2646 and ( nvl(eri.status_type,6) IN (4,6,7))
2647 and not exists
2648 (select
2649 'X'
2650 from bom_inventory_components bicn, eng_revised_items eri1
2651 where bicn.bill_sequence_id + 0 = bic.bill_sequence_id
2652 and bicn.old_component_sequence_id =
2653 bic.component_sequence_id
2654 and bicn.acd_type in (2,3)
2655 and eri1.revised_item_sequence_id = bicn.revised_item_sequence_id
2656 and trunc(bicn.disable_date) <= cal.calendar_date
2657 and ( nvl(eri1.status_type,6) in (4,6,7))
2658 )
2659 )
2660 and bic.optional = 2
2661 and msi2.bom_item_type = 4
2662 and msi.bom_item_type in (1,2) /*Model or Option Class */
2663 and msi.pick_components_flag <> 'Y' ;
2664
2665
2666 lrowcount := SQL%ROWCOUNT;
2667 IF PG_DEBUG <> 0 THEN
2668 oe_debug_pub.add ('load_mandatory_comps_pds: ' || 'Row Count : ' || lrowcount, 2);
2669 END IF;
2670
2671
2672
2673
2674 /* continue exploding atleast till max level number */
2675
2676 IF lrowcount = 0
2677 AND level_number >= v_max_level_number THEN
2678 EXIT Explode_loop;
2679 END IF;
2680
2681 level_number := level_number + 1;
2682
2683 END LOOP;
2684 END IF;
2685
2686
2687 return(1);
2688
2689
2690 exception
2691
2692 when no_data_found then
2693 xErrorMessage := 'CTOCITMB:'||to_char(lStmtNumber)||': No Data Found ';
2694 return(0);
2695 when proc_error then
2696 xErrorMessage := 'CTOCITMB:'||to_char(lStmtNumber)||': Model row not found ';
2697 return(0);
2698 when others then --bugfix 1902818: added others excpn
2699 xErrorMessage := 'load_mandatory_comps_pds:(others excepn)::'||to_char(lStmtNumber)||'::'||substrb(sqlerrm,1,150);
2700 return(0);
2701
2702 end load_mandatory_comps_pds;
2703
2704 -- 3779636
2705
2706
2707 function evaluate_order( p_atp_flag mtl_system_items.atp_flag%type
2708 , p_atp_comp mtl_system_items.atp_components_flag%type
2709 , p_item_type mtl_system_items.bom_item_type%type )
2710 return number
2711 is
2712 begin
2713 if( p_atp_comp in ( 'C' , 'Y' ) AND p_atp_flag in ( 'R' , 'C')) then
2714 return 1 ; /* do explode and required */
2715
2716 elsif( p_atp_comp = 'Y' AND p_atp_flag = 'N' and p_item_type = '4') then
2717 return 2 ; /* do explode and not required */
2718
2719 else
2720 return 3 ; /* do not explode and required */
2721
2722 end if ;
2723
2724 end evaluate_order ;
2725
2726
2727 function load_mandatory_components(
2728 p_ship_set in MRP_ATP_PUB.ATP_Rec_Typ,
2729 p_model_index in number,
2730 pReqDate in oe_order_lines_all.schedule_ship_date%type,
2731 xGrpId out NOCOPY number,
2732 xErrorMessage out NOCOPY varchar2 ,
2733 xMessageName out NOCOPY varchar2 ,
2734 xTableName out NOCOPY varchar2 )
2735 return integer
2736 is
2737
2738 level_number number := 0;
2739 v_max_level_number number := 0;
2740 lStmtNumber number := 0;
2741 lGrpId number;
2742 lGroupid2 number;
2743 rowcount number := 1;
2744 proc_error exception ;
2745 i number;
2746
2747 v_msi_fixed_lead_time mtl_system_items.fixed_lead_time%type ;
2748 v_msi_variable_lead_time mtl_system_items.variable_lead_time%type ;
2749
2750 /*Bugfix 2047428 */
2751 latpcompflag mtl_system_items.atp_components_flag%type;
2752 /* End Bugfix 2047428 */
2753
2754 -- 3893281 : New debug cursor and variables
2755 cursor debug_bet is
2756 select bet.top_bill_sequence_id,
2757 bet.bill_sequence_id,
2758 bet.organization_id,
2759 bet.sort_order,
2760 bet.plan_level,
2761 bet.line_id,
2762 substrb(msi.concatenated_segments,1,50)
2763 from bom_explosion_temp bet,mtl_system_items_kfv msi
2764 where bet.group_id = xGrpId
2765 and bet.organization_id = msi.organization_id
2766 and bet.component_item_id = msi.inventory_item_id;
2767
2768 d_top_bseq_id number;
2769 d_bseq_id number;
2770 d_org_id number;
2771 d_sort_order varchar2(240);
2772 d_plan_level number;
2773 d_line_id number;
2774 d_item varchar2(50);
2775
2776 -- 3893281
2777
2778 begin
2779
2780
2781
2782
2783 IF PG_DEBUG <> 0 THEN
2784 oe_debug_pub.add ('load_mandatory_components: ' || ' load mandatory components ' ,1);
2785 END IF;
2786
2787 if( pReqDate is not null ) then
2788 IF PG_DEBUG <> 0 THEN
2789 oe_debug_pub.add ('load_mandatory_components: ' || 'parameters passed index ' || p_model_index || ' date ' || to_char( pReqDate ) ,1);
2790 END IF;
2791 else
2792 IF PG_DEBUG <> 0 THEN
2793 oe_debug_pub.add ('load_mandatory_components: ' || 'parameters passed index date null ' || p_model_index ,1);
2794 END IF;
2795 end if ;
2796
2797
2798
2799 /* Bugfix 2047428 */
2800 lStmtNumber := 599;
2801 select NVL(msi.atp_components_flag,'N')
2802 into latpcompflag
2803 from mtl_system_items msi
2804 where msi.inventory_item_id = p_ship_set.inventory_item_id(p_model_index)
2805 and msi.organization_id = p_ship_set.source_organization_id(p_model_index);
2806
2807
2808 If latpcompflag in ( 'N' , 'R' ) then -- bugfix 3779636
2809 IF PG_DEBUG <> 0 THEN
2810 oe_debug_pub.add ('load_mandatory_components: ' || 'Exiting Load Mandatory Components at model level as ATP Component flag is N or R ',1); -- bugfix 3779636
2811 END IF;
2812 return(1);
2813
2814 else
2815
2816 /* End Bugfix 2047428 */
2817 select bom_explosion_temp_s.nextval
2818 into lGroupid2
2819 from dual;
2820
2821 select bom_explosion_temp_s.nextval
2822 into xGrpId
2823 from dual;
2824
2825 lStmtNumber := 600;
2826
2827
2828 i := p_ship_set.inventory_item_id.FIRST;
2829
2830 -- use bom_explosion_temp table to store the ship set for later join
2831 while i is not null
2832 loop
2833 insert into bom_explosion_temp(
2834 top_bill_sequence_id,
2835 bill_sequence_id,
2836 organization_id,
2837 component_item_id,
2838 plan_level,
2839 extended_quantity,
2840 primary_uom_code, -- Bugfix 1998386
2841 sort_order,
2842 group_id)
2843 -- Bugfix 1998386 Change this to select statement to select
2844 -- primary_uom_code from mtl_system_items.
2845 -- Also CONVERT_UOM function is used to convert
2846 -- p_ship_set.quantity_ordered(i) if the ordered UOM
2847 -- is different from primary UOM.
2848 /*values (
2849 1,
2850 1,
2851 p_ship_set.source_organization_id(i),
2852 p_ship_set.inventory_item_id(i),
2853 1,
2854 p_ship_set.quantity_ordered(i),
2855 2, -- BUG no 1288823 modification
2856 lGroupid2);*/
2857 select
2858 1,
2859 1,
2860 p_ship_set.source_organization_id(i),
2861 p_ship_set.inventory_item_id(i),
2862 1,
2863 CTO_UTILITY_PK.convert_uom(
2864 p_ship_set.quantity_uom(i),
2865 msi.primary_uom_code,
2866 p_ship_set.quantity_ordered(i),
2867 p_ship_set.inventory_item_id(i)),
2868 msi.primary_uom_code,
2869 2, -- BUG no 1288823 modification
2870 lGroupid2
2871 from mtl_system_items msi
2872 where msi.inventory_item_id = p_ship_set.inventory_item_id(i)
2873 and msi.organization_id = p_ship_set.source_organization_id(i);
2874
2875 i := p_ship_set.inventory_item_id.NEXT(i);
2876
2877 end loop;
2878
2879
2880
2881 -- insert the top model into bom_explosion_temp
2882 insert into bom_explosion_temp(
2883 top_bill_sequence_id,
2884 bill_sequence_id,
2885 organization_id,
2886 sort_order,
2887 component_item_id,
2888 plan_level,
2889 extended_quantity,
2890 primary_uom_code, -- Bugfix 1998386
2891 top_item_id,
2892 line_id,
2893 group_id)
2894
2895 -- Bugfix 1998386 Change this to select statement to
2896 -- select primary_uom_code from mtl_system_items.
2897 -- Also CONVERT_UOM function is used to convert
2898 -- p_ship_set.quantity_ordered(i) if the ordered UOM is
2899 -- different from primary UOM.
2900
2901 select
2902 1,
2903 1,
2904 p_ship_set.source_organization_id(p_model_index),
2905 2, -- BUG no 1288823 modification
2906 p_ship_set.inventory_item_id(p_model_index),
2907 0,
2908 CTO_UTILITY_PK.convert_uom(
2909 p_ship_set.quantity_uom(p_model_index),
2910 msi.primary_uom_code,
2911 p_ship_set.quantity_ordered(p_model_index),
2912 p_ship_set.inventory_item_id(p_model_index)),
2913 msi.primary_uom_code,
2914 p_ship_set.inventory_item_id(p_model_index),
2915 1,
2916 xGrpId
2917 from mtl_system_items msi
2918 where msi.inventory_item_id = p_ship_set.inventory_item_id(p_model_index)
2919 and msi.organization_id = p_ship_set.source_organization_id(p_model_index);
2920
2921
2922 /*------------------------------------------------+
2923 Insert all selections for the top model
2924 with corrosponding plan_levels
2925 +------------------------------------------------*/
2926 rowcount := 1 ;
2927
2928 while rowcount > 0
2929 LOOP
2930
2931 level_number := level_number + 1;
2932
2933 lStmtNumber := 610;
2934 insert into bom_explosion_temp(
2935 top_bill_sequence_id,
2936 bill_sequence_id,
2937 organization_id,
2938 sort_order,
2939 component_item_id,
2940 plan_level,
2941 extended_quantity,
2942 primary_uom_code, -- Bugfix 1998386
2943 top_item_id,
2944 line_id,
2945 group_id)
2946 select
2947 1,
2948 1,
2949 bet.organization_id,
2950 2, -- BUG no 1288823 modification
2951 bic.component_item_id,
2952 level_number,
2953 /* bet2.extended_quantity,*/
2954
2955 -- Bugfix 1998386 This function multiplies the ordered quantity
2956 -- with conversion factor and returns the converted
2957 -- quantity if the order UOM is different from primary UOM of the item.
2958 -- If ordered UOM and primary UOM are same
2959 -- the function returns the ordered quantity.
2960
2961 CTO_UTILITY_PK.convert_uom(
2962 bet2.primary_uom_code,
2963 msi.primary_uom_code,
2964 bet2.extended_quantity,
2965 bic.component_item_id),
2966 msi.primary_uom_code,
2967 bet.top_item_id,
2968 1,
2969 xGrpId
2970 from
2971 bom_bill_of_materials bom,
2972 bom_inventory_components bic,
2973 mtl_system_items msi, -- bugfix 1998386
2974 bom_explosion_temp bet,
2975 bom_explosion_temp bet2 /* ship set */
2976 where bet.group_id = xGrpId
2977 and bet.plan_level = level_number -1
2978 and bic.component_item_id = msi.inventory_item_id -- bugfix 1998386
2979 and bet.component_item_id = bom.assembly_item_id
2980 and bet.organization_id = bom.organization_id
2981 and bet.organization_id = msi.organization_id -- bugfix 1998386
2982 and bom.alternate_bom_designator is null
2983 and bom.common_bill_sequence_id = bic.bill_sequence_id
2984 and bic.component_item_id = bet2.component_item_id
2985 and bet2.group_id = lGroupid2
2986 -- bugfix 3893281 : Add following filter conditions to get
2987 -- sub models , option classes , ato items and phantom option items
2988 and bic.optional = 1
2989 and ( msi.bom_item_type in (1,2)
2990 OR (msi.bom_item_type = 4 and bic.wip_supply_type = 6 )
2991 OR (msi.bom_item_type = 4 and msi.replenish_to_order_flag = 'Y' ));
2992 -- end bugfix 3893281
2993
2994 rowcount := SQL%ROWCOUNT;
2995
2996 IF PG_DEBUG <> 0 THEN
2997 oe_debug_pub.add ('load_mandatory_components: ' || 'Row Count : ' || rowcount, 2);
2998 END IF;
2999
3000 END LOOP;
3001
3002 -- 3893281 following code is to debug BET at this point
3003 open debug_bet;
3004 oe_debug_pub.add ('BET picture after Model and its children are inserted ..' ,1);
3005 loop
3006 fetch debug_bet
3007 into d_top_bseq_id,
3008 d_bseq_id,
3009 d_org_id,
3010 d_sort_order,
3011 d_plan_level,
3012 d_line_id,
3013 d_item;
3014 exit when debug_bet%NOTFOUND;
3015 IF PG_DEBUG <> 0 THEN
3016 oe_debug_pub.add (' Top Bill Seq id '||d_top_bseq_id|| ' Bill Seq Id '||d_bseq_id
3017 ||' Org '||d_org_id ||' Sort Order '||d_sort_order
3018 || ' Plan level '||d_plan_level||' Line Id '||d_line_id
3019 || ' Item '||d_item,1);
3020 END IF;
3021 end loop;
3022 close debug_bet;
3023 -- 3893281
3024
3025
3026
3027 v_max_level_number := level_number ; /* change made by sushant to track max level number */
3028
3029 IF PG_DEBUG <> 0 THEN
3030 oe_debug_pub.add ('load_mandatory_components: ' || 'Group_id : '|| xGrpId, 2);
3031 END IF;
3032
3033 delete from bom_explosion_temp
3034 where group_id = lGroupid2;
3035
3036 /*
3037 ** BUG no 1288823, new query block added
3038 */
3039
3040 begin
3041 select msi.fixed_lead_time , nvl(msi.variable_lead_time,0)
3042 into v_msi_fixed_lead_time, v_msi_variable_lead_time
3043 from mtl_system_items msi , bom_explosion_temp be
3044 where be.organization_id = msi.organization_id
3045 and be.component_item_id = msi.inventory_item_id
3046 and be.component_item_id = p_ship_set.inventory_item_id(p_model_index);
3047
3048 exception
3049
3050 when no_data_found then
3051 xErrorMessage := 'CTOCITMB:'||to_char(lStmtNumber)||': No Data Found ';
3052 return(0);
3053 when others then
3054 xErrorMessage := 'CTOCITMB:'||to_char(lStmtNumber)||': other error ';
3055 return(0);
3056 end ;
3057
3058 /*------------------------------------------------------------+
3059 Start Explosion of all items copied above.
3060 +-----------------------------------------------------------*/
3061
3062 level_number := 0;
3063 IF PG_DEBUG <> 0 THEN
3064 oe_debug_pub.add('load_mandatory_components: ' || 'Explosion loop' , 2);
3065 END IF;
3066
3067 << Explode_loop >>
3068 LOOP
3069
3070 lStmtNumber := 620;
3071 -- Bug 1985793 Selecting greater of sysdate and calendar date
3072 -- while checking for item effectivity so that planning will get
3073 -- components effective till sysdate.
3074 --apps performance bug#4905845, sql id 16103671
3075 insert into bom_explosion_temp(
3076 top_bill_sequence_id,
3077 bill_sequence_id,
3078 organization_id,
3079 sort_order,
3080 component_sequence_id,
3081 component_item_id,
3082 plan_level,
3083 extended_quantity,
3084 primary_uom_code, -- 1998386
3085 top_item_id,
3086 component_quantity,
3087 check_atp,
3088 atp_components_flag,
3089 atp_flag,
3090 bom_item_type,
3091 assembly_item_id,
3092 parent_bom_item_type,
3093 line_id,
3094 group_id)
3095 select
3096 be.top_bill_sequence_id,
3097 bic.bill_sequence_id,
3098 be.organization_id,
3099 evaluate_order( msi2.atp_flag, msi2.atp_components_flag , msi2.bom_item_type ) , /* BUG# 1518894 , 1288823 */
3100 bic.component_sequence_id,
3101 bic.component_item_id,
3102 level_number + 1,
3103 be.extended_quantity * bic.component_quantity,
3104 msi2.primary_uom_code,
3105 be.top_item_id,
3106 bic.component_quantity,
3107 bic.check_atp,
3108 --2378556
3109 msi2.atp_components_flag,
3110 msi2.atp_flag,
3111 msi2.bom_item_type,
3112
3113 bom.assembly_item_id,
3114 msi.bom_item_type,
3115 NULL,
3116 xGrpId
3117 from
3118 bom_calendar_dates cal,
3119 mtl_system_items msi, /* PARENT */
3120 mtl_system_items msi2, /* CHILD [BUG#1518894] */
3121 bom_inventory_components bic,
3122 eng_revised_items eri,
3123 bom_bill_of_materials bom,
3124 mtl_parameters mp,
3125 bom_explosion_temp be
3126 where be.sort_order <> 3
3127 and be.group_id = xGrpId
3128 and nvl(be.plan_level,0) = level_number
3129 and be.organization_id = bom.organization_id
3130 and be.component_item_id = bom.assembly_item_id
3131 and bic.component_quantity <> 0
3132 and bic.revised_item_sequence_id = eri.revised_item_sequence_id (+)
3133 and bic.component_item_id = msi2.inventory_item_id -- 1518894
3134 and bom.organization_id = msi2.organization_id --1518894
3135 and be.organization_id = msi.organization_id
3136 and be.component_item_id = msi.inventory_item_id
3137 and bom.alternate_bom_designator is null
3138 and bic.bill_sequence_id = bom.common_bill_sequence_id
3139 and mp.organization_id = be.organization_id
3140 and cal.calendar_code = mp.calendar_code
3141 and cal.exception_set_id = mp.calendar_exception_set_id
3142 and cal.calendar_date =
3143 ( select c.calendar_date
3144 from bom_calendar_dates C
3145 where C.calendar_code = mp.calendar_code
3146 and c.exception_set_id = mp.calendar_exception_set_id
3147 and C.seq_num =
3148 (select c2.prior_seq_num -
3149 ceil(nvl(v_msi_fixed_lead_time,0)+
3150 (be.extended_quantity *
3151 nvl(v_msi_variable_lead_time,0)))
3152 from bom_calendar_dates c2
3153 where c2.calendar_code = mp.calendar_code
3154 and c2.exception_set_id = mp.calendar_exception_set_id
3155 and c2.calendar_date = trunc(pReqDate)
3156 )
3157 )
3158 -- 2162912
3159 and TRUNC(bic.effectivity_date) <= greatest(nvl(cal.calendar_date,sysdate),sysdate)
3160 and nvl(TRUNC(bic.disable_date),(nvl(cal.calendar_date,sysdate) + 1)) > nvl(cal.calendar_date,sysdate)
3161
3162 and bic.effectivity_date =
3163 (select
3164 max(effectivity_date)
3165 from bom_inventory_components bic1,
3166 eng_revised_items eri
3167 where bic1.bill_sequence_id = bic.bill_sequence_id
3168 and bic1.component_item_id = bic.component_item_id
3169 and bic1.revised_item_sequence_id =
3170 eri.revised_item_sequence_id (+)
3171 and (decode(bic1.implementation_date, NULL,
3172 bic1.old_component_sequence_id,
3173 bic1.component_sequence_id) =
3174 decode(bic.implementation_date, NULL,
3175 bic.old_component_sequence_id,
3176 bic.component_sequence_id)
3177 OR
3178 bic1.operation_seq_num = bic.operation_seq_num)
3179 -- 2162912
3180 and TRUNC(bic1.effectivity_date) <= greatest(nvl(cal.calendar_date,sysdate),sysdate)
3181 and nvl(TRUNC(bic1.disable_date),(nvl(cal.calendar_date,sysdate) + 1)) > nvl(cal.calendar_date,sysdate)
3182
3183 and ( nvl(eri.status_type,6) IN (4,6,7))
3184 and not exists
3185 (select
3186 'X'
3187 from bom_inventory_components bicn, eng_revised_items eri1
3188 where bicn.bill_sequence_id + 0 = bic.bill_sequence_id
3189 and bicn.old_component_sequence_id =
3190 bic.component_sequence_id
3191 and bicn.acd_type in (2,3)
3192 and eri1.revised_item_sequence_id =
3193 bicn.revised_item_sequence_id
3194 and trunc(bicn.disable_date) <= cal.calendar_date
3195 and ( nvl(eri1.status_type,6) in (4,6,7))
3196 )
3197 )
3198 and bic.optional = 2 /* NOT OPTIONAL */
3199 and msi2.bom_item_type = 4 /* BUGFIX 2400948 */
3200 -- Model or Option Class or ATO ITEM * * BUG#2378556 bug 3314297 mandatory comps should be exploded for
3201 -- standard items
3202 and msi.pick_components_flag <> 'Y' ;
3203
3204 IF PG_DEBUG <> 0 THEN
3205 oe_debug_pub.add('load_mandatory_components: ' || 'Row Count : ' || SQL%ROWCOUNT);
3206 END IF;
3207
3208 /* continue exploding atleast till max level number */
3209 IF SQL%ROWCOUNT = 0 AND level_number >= v_max_level_number THEN
3210 EXIT Explode_loop;
3211 END IF;
3212
3213 level_number := level_number + 1;
3214 END LOOP;
3215 END IF; -- Bugfix 2047428
3216
3217 return(1);
3218
3219 exception
3220
3221 when no_data_found then
3222 xErrorMessage := 'CTOCITMB:'||to_char(lStmtNumber)||': No Data Found ';
3223 return(0);
3224 when proc_error then
3225 xErrorMessage := 'CTOCITMB:'||to_char(lStmtNumber)||': Model row not found ';
3226 return(0);
3227 when others then --bugfix 1902818: added others excpn
3228 xErrorMessage := 'load_mandatory_components:(others excepn)::'||to_char(lStmtNumber)||'::'||substrb(sqlerrm,1,150);
3229 return(0);
3230
3231 end load_mandatory_components;
3232
3233
3234
3235
3236 -- 3779636
3237 function load_mandatory_components_pds(
3238 p_ship_set in MRP_ATP_PUB.ATP_Rec_Typ,
3239 p_model_index in number,
3240 pReqDate in oe_order_lines_all.schedule_ship_date%type,
3241 xGrpId out NOCOPY number,
3242 xErrorMessage out NOCOPY varchar2 ,
3243 xMessageName out NOCOPY varchar2 ,
3244 xTableName out NOCOPY varchar2 )
3245 return integer
3246 is
3247
3248 level_number number := 0;
3249 v_max_level_number number := 0;
3250 lStmtNumber number := 0;
3251 lGrpId number;
3252 lGroupid2 number;
3253 rowcount number := 1;
3254 proc_error exception ;
3255 i number;
3256
3257 v_msi_fixed_lead_time mtl_system_items.fixed_lead_time%type ;
3258 v_msi_variable_lead_time mtl_system_items.variable_lead_time%type ;
3259 latpcompflag mtl_system_items.atp_components_flag%type;
3260
3261
3262 begin
3263
3264
3265
3266
3267 IF PG_DEBUG <> 0 THEN
3268 oe_debug_pub.add ('load_mandatory_components_pds: ' || ' load mandatory components PDS ' ,1);
3269 END IF;
3270
3271 if( pReqDate is not null ) then
3272 IF PG_DEBUG <> 0 THEN
3273 oe_debug_pub.add ('load_mandatory_components_pds: ' || 'parameters passed index ' || p_model_index || ' date ' || to_char( pReqDate ) ,1);
3274 END IF;
3275 else
3276 IF PG_DEBUG <> 0 THEN
3277 oe_debug_pub.add ('load_mandatory_components_pds: ' || 'parameters passed index date null ' || p_model_index ,1);
3278 END IF;
3279 end if ;
3280
3281
3282 lStmtNumber := 599;
3283 select NVL(msi.atp_components_flag,'N')
3284 into latpcompflag
3285 from mtl_system_items msi
3286 where msi.inventory_item_id = p_ship_set.inventory_item_id(p_model_index)
3287 and msi.organization_id = p_ship_set.source_organization_id(p_model_index);
3288
3289
3290 If latpcompflag in ( 'N' , 'R' ) then -- 3779636
3291 IF PG_DEBUG <> 0 THEN
3292 oe_debug_pub.add ('load_mandatory_components_pds: ' || 'Exiting Load Mandatory Components at model level as ATP Component flag is N or R',1); -- 3779636
3293 END IF;
3294 return(1);
3295
3296 else
3297 select bom_explosion_temp_s.nextval
3298 into lGroupid2
3299 from dual;
3300
3301 select bom_explosion_temp_s.nextval
3302 into xGrpId
3303 from dual;
3304
3305 lStmtNumber := 600;
3306
3307
3308 i := p_ship_set.inventory_item_id.FIRST;
3309
3310 -- use bom_explosion_temp table to store the ship set for later join
3311 while i is not null
3312 loop
3313 insert into bom_explosion_temp(
3314 top_bill_sequence_id,
3315 bill_sequence_id,
3316 organization_id,
3317 component_item_id,
3318 plan_level,
3319 extended_quantity,
3320 primary_uom_code,
3321 sort_order,
3322 group_id)
3323 select
3324 1,
3325 1,
3326 p_ship_set.source_organization_id(i),
3327 p_ship_set.inventory_item_id(i),
3328 1,
3329 CTO_UTILITY_PK.convert_uom(
3330 p_ship_set.quantity_uom(i),
3331 msi.primary_uom_code,
3332 p_ship_set.quantity_ordered(i),
3333 p_ship_set.inventory_item_id(i)),
3334 msi.primary_uom_code,
3335 2,
3336 lGroupid2
3337 from mtl_system_items msi
3338 where msi.inventory_item_id = p_ship_set.inventory_item_id(i)
3339 and msi.organization_id = p_ship_set.source_organization_id(i);
3340
3341 i := p_ship_set.inventory_item_id.NEXT(i);
3342
3343 end loop;
3344
3345
3346
3347 -- insert the top model into bom_explosion_temp
3348 insert into bom_explosion_temp(
3349 top_bill_sequence_id,
3350 bill_sequence_id,
3351 organization_id,
3352 sort_order,
3353 component_item_id,
3354 plan_level,
3355 extended_quantity,
3356 primary_uom_code,
3357 top_item_id,
3358 line_id,
3359 group_id)
3360 select
3361 1,
3362 1,
3363 p_ship_set.source_organization_id(p_model_index),
3364 2, -- BUG no 1288823 modification
3365 p_ship_set.inventory_item_id(p_model_index),
3366 0,
3367 CTO_UTILITY_PK.convert_uom(
3368 p_ship_set.quantity_uom(p_model_index),
3369 msi.primary_uom_code,
3370 p_ship_set.quantity_ordered(p_model_index),
3371 p_ship_set.inventory_item_id(p_model_index)),
3372 msi.primary_uom_code,
3373 p_ship_set.inventory_item_id(p_model_index),
3374 1,
3375 xGrpId
3376 from mtl_system_items msi
3377 where msi.inventory_item_id = p_ship_set.inventory_item_id(p_model_index)
3378 and msi.organization_id = p_ship_set.source_organization_id(p_model_index);
3379
3380
3381 /*------------------------------------------------+
3382 Insert all selections for the top model
3383 with corrosponding plan_levels
3384 +------------------------------------------------*/
3385 rowcount := 1 ;
3386
3387 while rowcount > 0
3388 LOOP
3389
3390 level_number := level_number + 1;
3391
3392 lStmtNumber := 610;
3393 insert into bom_explosion_temp(
3394 top_bill_sequence_id,
3395 bill_sequence_id,
3396 organization_id,
3397 sort_order,
3398 component_item_id,
3399 plan_level,
3400 extended_quantity,
3401 primary_uom_code,
3402 top_item_id,
3403 line_id,
3404 group_id)
3405 select
3406 1,
3407 1,
3408 bet.organization_id,
3409 2,
3410 bic.component_item_id,
3411 level_number,
3412 CTO_UTILITY_PK.convert_uom(
3413 bet2.primary_uom_code,
3414 msi.primary_uom_code,
3415 bet2.extended_quantity,
3416 bic.component_item_id),
3417 msi.primary_uom_code,
3418 bet.top_item_id,
3419 1,
3420 xGrpId
3421 from
3422 bom_bill_of_materials bom,
3423 bom_inventory_components bic,
3424 mtl_system_items msi,
3425 bom_explosion_temp bet,
3426 bom_explosion_temp bet2
3427 where bet.group_id = xGrpId
3428 and bet.plan_level = level_number -1
3429 and bic.component_item_id = msi.inventory_item_id
3430 and msi.bom_item_type in ( 1, 2 ) /* Only Sub-models and Option Classes */
3431 and bet.component_item_id = bom.assembly_item_id
3432 and bet.organization_id = bom.organization_id
3433 and bet.organization_id = msi.organization_id
3434 and bom.alternate_bom_designator is null
3435 and bom.common_bill_sequence_id = bic.bill_sequence_id
3436 and bic.component_item_id = bet2.component_item_id
3437 and bet2.group_id = lGroupid2;
3438
3439 rowcount := SQL%ROWCOUNT;
3440
3441 IF PG_DEBUG <> 0 THEN
3442 oe_debug_pub.add ('load_mandatory_components_pds: ' || 'Row Count : ' || rowcount, 2);
3443 END IF;
3444
3445 END LOOP;
3446
3447
3448
3449 v_max_level_number := level_number ;
3450
3451 IF PG_DEBUG <> 0 THEN
3452 oe_debug_pub.add ('load_mandatory_components_pds: ' || 'Group_id : '|| xGrpId, 2);
3453 END IF;
3454
3455 delete from bom_explosion_temp
3456 where group_id = lGroupid2;
3457
3458 begin
3459 select msi.fixed_lead_time , nvl(msi.variable_lead_time,0)
3460 into v_msi_fixed_lead_time, v_msi_variable_lead_time
3461 from mtl_system_items msi , bom_explosion_temp be
3462 where be.organization_id = msi.organization_id
3463 and be.component_item_id = msi.inventory_item_id
3464 and be.component_item_id = p_ship_set.inventory_item_id(p_model_index);
3465
3466 exception
3467
3468 when no_data_found then
3469 xErrorMessage := 'CTOCITMB:'||to_char(lStmtNumber)||': No Data Found ';
3470 return(0);
3471 when others then
3472 xErrorMessage := 'CTOCITMB:'||to_char(lStmtNumber)||': other error ';
3473 return(0);
3474 end ;
3475
3476 /*------------------------------------------------------------+
3477 Start Explosion of all items copied above.
3478 +-----------------------------------------------------------*/
3479
3480 level_number := 0;
3481 IF PG_DEBUG <> 0 THEN
3482 oe_debug_pub.add('load_mandatory_components_pds: ' || 'Explosion loop' , 2);
3483 END IF;
3484
3485 << Explode_loop >>
3486 LOOP
3487
3488 lStmtNumber := 620;
3489 --appsperf bug#4905845, sql id 16103821
3490 --removed comments to reduce shared memory
3491 insert into bom_explosion_temp(
3492 top_bill_sequence_id,
3493 bill_sequence_id,
3494 organization_id,
3495 sort_order,
3496 component_sequence_id,
3497 component_item_id,
3498 plan_level,
3499 extended_quantity,
3500 primary_uom_code,
3501 top_item_id,
3502 component_quantity,
3503 check_atp,
3504 atp_components_flag,
3505 atp_flag,
3506 bom_item_type,
3507 assembly_item_id,
3508 parent_bom_item_type,
3509 line_id,
3510 group_id)
3511 select
3512 be.top_bill_sequence_id,
3513 bic.bill_sequence_id,
3514 be.organization_id,
3515 evaluate_order( msi2.atp_flag, msi2.atp_components_flag , msi2.bom_item_type ) ,
3516 bic.component_sequence_id,
3517 bic.component_item_id,
3518 level_number + 1,
3519 be.extended_quantity * bic.component_quantity,
3520 msi2.primary_uom_code,
3521 be.top_item_id,
3522 bic.component_quantity,
3523 bic.check_atp,
3524 msi2.atp_components_flag,
3525 msi2.atp_flag,
3526 msi2.bom_item_type,
3527 bom.assembly_item_id,
3528 msi.bom_item_type,
3529 NULL,
3530 xGrpId
3531 from
3532 bom_calendar_dates cal,
3533 mtl_system_items msi,
3534 mtl_system_items msi2,
3535 bom_inventory_components bic,
3536 eng_revised_items eri,
3537 bom_bill_of_materials bom,
3538 mtl_parameters mp,
3539 bom_explosion_temp be
3540 where be.sort_order <> 3
3541 and be.group_id = xGrpId
3542 and nvl(be.plan_level,0) = level_number
3543 and be.organization_id = bom.organization_id
3544 and be.component_item_id = bom.assembly_item_id
3545 and bic.component_quantity <> 0
3546 and bic.revised_item_sequence_id = eri.revised_item_sequence_id (+)
3547 and bic.component_item_id = msi2.inventory_item_id
3548 and bom.organization_id = msi2.organization_id
3549 and be.organization_id = msi.organization_id
3550 and be.component_item_id = msi.inventory_item_id
3551 and bom.alternate_bom_designator is null
3552 and bic.bill_sequence_id = bom.common_bill_sequence_id
3553 and mp.organization_id = be.organization_id
3554 and cal.calendar_code = mp.calendar_code
3555 and cal.exception_set_id = mp.calendar_exception_set_id
3556 and cal.calendar_date =
3557 ( select c.calendar_date
3558 from bom_calendar_dates C
3559 where C.calendar_code = mp.calendar_code
3560 and c.exception_set_id = mp.calendar_exception_set_id
3561 and C.seq_num =
3562 (select c2.prior_seq_num -
3563 ceil(nvl(v_msi_fixed_lead_time,0)+
3564 (be.extended_quantity *
3565 nvl(v_msi_variable_lead_time,0)))
3566 from bom_calendar_dates c2
3567 where c2.calendar_code = mp.calendar_code
3568 and c2.exception_set_id = mp.calendar_exception_set_id
3569 and c2.calendar_date = trunc(pReqDate)
3570 )
3571 )
3572 and TRUNC(bic.effectivity_date) <= greatest(nvl(cal.calendar_date,sysdate),sysdate)
3573 and nvl(TRUNC(bic.disable_date),(nvl(cal.calendar_date,sysdate) + 1)) > nvl(cal.calendar_date,sysdate)
3574 and bic.effectivity_date =
3575 (select
3576 max(effectivity_date)
3577 from bom_inventory_components bic1,
3578 eng_revised_items eri
3579 where bic1.bill_sequence_id = bic.bill_sequence_id
3580 and bic1.component_item_id = bic.component_item_id
3581 and bic1.revised_item_sequence_id =
3582 eri.revised_item_sequence_id (+)
3583 and (decode(bic1.implementation_date, NULL,
3584 bic1.old_component_sequence_id,
3585 bic1.component_sequence_id) =
3586 decode(bic.implementation_date, NULL,
3587 bic.old_component_sequence_id,
3588 bic.component_sequence_id)
3589 OR
3590 bic1.operation_seq_num = bic.operation_seq_num)
3591 and TRUNC(bic1.effectivity_date) <= greatest(nvl(cal.calendar_date,sysdate),sysdate)
3592 and nvl(TRUNC(bic1.disable_date),(nvl(cal.calendar_date,sysdate) + 1)) > nvl(cal.calendar_date,sysdate)
3593 and ( nvl(eri.status_type,6) IN (4,6,7))
3594 and not exists
3595 (select
3596 'X'
3597 from bom_inventory_components bicn, eng_revised_items eri1
3598 where bicn.bill_sequence_id + 0 = bic.bill_sequence_id
3599 and bicn.old_component_sequence_id =
3600 bic.component_sequence_id
3601 and bicn.acd_type in (2,3)
3602 and eri1.revised_item_sequence_id =
3603 bicn.revised_item_sequence_id
3604 and trunc(bicn.disable_date) <= cal.calendar_date
3605 and ( nvl(eri1.status_type,6) in (4,6,7))
3606 )
3607 )
3608 and bic.optional = 2
3609 and msi2.bom_item_type = 4
3610 and msi.bom_item_type in (1,2) /*Model or Option Class */
3611 and msi.pick_components_flag <> 'Y' ;
3612
3613 IF PG_DEBUG <> 0 THEN
3614 oe_debug_pub.add('load_mandatory_components_pds: ' || 'Row Count : ' || SQL%ROWCOUNT);
3615 END IF;
3616
3617
3618 IF SQL%ROWCOUNT = 0 AND level_number >= v_max_level_number THEN
3619 EXIT Explode_loop;
3620 END IF;
3621
3622 level_number := level_number + 1;
3623 END LOOP;
3624 END IF;
3625
3626 return(1);
3627
3628 exception
3629
3630 when no_data_found then
3631 xErrorMessage := 'CTOCITMB:'||to_char(lStmtNumber)||': No Data Found ';
3632 return(0);
3633 when proc_error then
3634 xErrorMessage := 'CTOCITMB:'||to_char(lStmtNumber)||': Model row not found ';
3635 return(0);
3636 when others then --bugfix 1902818: added others excpn
3637 xErrorMessage := 'load_mandatory_components_pds:(others excepn)::'||to_char(lStmtNumber)||'::'||substrb(sqlerrm,1,150);
3638 return(0);
3639
3640 end load_mandatory_components_pds;
3641
3642 function Get_Mandatory_Components(
3643 p_ship_set in MRP_ATP_PUB.ATP_Rec_Typ,
3644 p_organization_id in number,
3645 p_inventory_item_id in number,
3646 x_smc_rec out NOCOPY MRP_ATP_PUB.ATP_Rec_Typ,
3647 xErrorMessage out NOCOPY varchar2,
3648 xMessageName out NOCOPY varchar2,
3649 xTableName out NOCOPY varchar2 )
3650 return integer
3651 is
3652
3653 lStatus varchar2(1);
3654 lGrpId number;
3655 lLineId number;
3656 lAtpLt number;
3657 lFixedLt number;
3658 lVarLt number;
3659 i number;
3660 chk number;
3661 lStmtNumber number;
3662 lItem_id number;
3663 lOrg_id number;
3664 lItem_type number;
3665 lModelIndex number;
3666
3667 proc_error exception;
3668
3669 -- query mandatory comps by group id and null line id
3670 cursor mandatory_comps is
3671 select component_item_id cid,
3672 component_sequence_id cseq,
3673 component_quantity cq,
3674 extended_quantity eq,
3675 primary_uom_code uom, -- Bugfix 1998386
3676 plan_level pl,
3677 line_id, -- Bugfix 2897132
3678 wip_supply_type -- Bugfix 3254039
3679 from bom_explosion_temp be
3680 where be.group_id = lGrpId
3681 and ( be.line_id is null or top_bill_sequence_id = -1 ) -- Bugfix 2897132
3682 and be.sort_order <> 2 ;
3683 --BUG 1288823 modification to send restricted components to atp
3684
3685 v_request_date DATE ;
3686
3687
3688 l_inv_ctp varchar2(1); -- bugfix 3779636
3689
3690
3691 begin
3692
3693 IF PG_DEBUG <> 0 THEN
3694 oe_debug_pub.add('Get_Mandatory_Components: ' || ' Entered Get Mandatory Components ',1);
3695 END IF;
3696
3697
3698 -- Bugfix 3779636
3699
3700 lStmtNumber := 699;
3701
3702 l_inv_ctp := fnd_profile.value('INV_CTP');
3703
3704 IF PG_DEBUG <> 0 THEN
3705 oe_debug_pub.add('Get_Mandatory_Components: INV_CTP ( 4 = PDS ): ' || l_inv_ctp,1);
3706 END IF;
3707
3708
3709
3710 lStmtNumber := 700;
3711
3712
3713
3714 lModelIndex := 1;
3715
3716 if ( p_organization_id is null and p_inventory_item_id is null) then
3717 -- the calling application is OM
3718
3719
3720 if( p_ship_set.requested_ship_date.exists(lModelIndex)) then
3721
3722 IF PG_DEBUG <> 0 THEN
3723 oe_debug_pub.add('Get_Mandatory_Components: ' || ' requested ship date exists ',1);
3724 END IF;
3725
3726
3727 if( p_ship_set.requested_ship_date(lModelIndex) is not null ) then
3728 IF PG_DEBUG <> 0 THEN
3729 oe_debug_pub.add('Get_Mandatory_Components: ' || ' requested ship date exists ' || p_ship_set.requested_ship_date(lModelIndex) ,1);
3730 END IF;
3731
3732 else
3733
3734 IF PG_DEBUG <> 0 THEN
3735 oe_debug_pub.add('Get_Mandatory_Components: ' || ' requested ship date is null ' ,1);
3736 END IF;
3737 end if ;
3738
3739 end if ;
3740
3741
3742
3743 if( p_ship_set.requested_arrival_date.exists(lModelIndex)) then
3744
3745 IF PG_DEBUG <> 0 THEN
3746 oe_debug_pub.add('Get_Mandatory_Components: ' || ' requested arrival date exists ',1);
3747 END IF;
3748
3749
3750 if( p_ship_set.requested_arrival_date(lModelIndex) is not null ) then
3751 IF PG_DEBUG <> 0 THEN
3752 oe_debug_pub.add('Get_Mandatory_Components: ' || ' requested arrival date exists ' || p_ship_set.requested_arrival_date(lModelIndex) ,1);
3753 END IF;
3754
3755 else
3756
3757 IF PG_DEBUG <> 0 THEN
3758 oe_debug_pub.add('Get_Mandatory_Components: ' || ' requested arrival date is null ' ,1);
3759 END IF;
3760 end if ;
3761
3762 end if ;
3763
3764
3765 v_request_date := nvl( p_ship_set.requested_ship_date(lModelIndex),
3766 p_ship_set.requested_arrival_date(lModelIndex)) ;
3767
3768
3769 -- Bugfix 2897132
3770 if( p_ship_set.quantity_ordered(lModelIndex) <> 0 ) then
3771
3772 -- Bugfix 3779636
3773 if l_inv_ctp = 4 then
3774
3775 lStatus := load_mandatory_comps_pds(p_ship_set.identifier(lModelIndex),
3776 v_request_date,
3777 lGrpId,
3778 xErrorMessage,
3779 xMessageName,
3780 xTableName);
3781 if lStatus <> 1 then
3782 IF PG_DEBUG <> 0 THEN
3783 oe_debug_pub.add('Get_Mandatory_Components: ' ||
3784 ' Load_mandatory_comps_pds returned with Error ',1);
3785 END IF;
3786 raise proc_error;
3787 end if;
3788
3789 else
3790
3791
3792
3793
3794 lStatus := load_mandatory_comps(p_ship_set.identifier(lModelIndex),
3795 v_request_date,
3796 lGrpId,
3797 xErrorMessage,
3798 xMessageName,
3799 xTableName);
3800
3801 if lStatus <> 1 then
3802 IF PG_DEBUG <> 0 THEN
3803 oe_debug_pub.add('Get_Mandatory_Components: ' || ' Load_mandatory_comps returned with Error ',1);
3804 END IF;
3805
3806 raise proc_error;
3807 end if;
3808
3809
3810 end if ; -- INV_CTP chk
3811
3812 -- bugfix 3779636
3813
3814
3815
3816 else
3817
3818
3819 oe_debug_pub.add(' Load_mandatory_comps returned without processing
3820 as model qty is 0 ',1);
3821 return 1 ;
3822
3823 end if;
3824
3825
3826
3827 else
3828 -- the calling application is Configurator
3829 i := p_ship_set.inventory_item_id.FIRST;
3830
3831 while i is not null
3832 loop
3833 -- find the top model record
3834 if p_ship_set.source_organization_id(i) = p_organization_id and
3835 p_ship_set.inventory_item_id(i) = p_inventory_item_id then
3836 lModelIndex := i;
3837 exit;
3838 end if;
3839 i := p_ship_set.inventory_item_id.NEXT(i);
3840 end loop;
3841
3842
3843
3844
3845 IF PG_DEBUG <> 0 THEN
3846 oe_debug_pub.add('Get_Mandatory_Components: ' || ' will be calling load_mandatory_components ' , 2);
3847 END IF;
3848
3849 v_request_date := nvl( p_ship_set.requested_ship_date(lModelIndex),
3850 p_ship_set.requested_arrival_date(lModelIndex)) ;
3851
3852
3853 -- Bugfix 2897132
3854 if( p_ship_set.quantity_ordered(lModelIndex) <> 0 ) then
3855
3856
3857 -- Bugfix 3779636
3858 if l_inv_ctp = 4 then
3859
3860 IF PG_DEBUG <> 0 THEN
3861 oe_debug_pub.add('Get_Mandatory_Components: ' ||
3862 ' now calling load_mandatory_components_pds ' , 2);
3863 END IF;
3864
3865 lStatus := load_mandatory_components_pds(p_ship_set,
3866 lModelIndex,
3867 v_request_date,
3868 lGrpId,
3869 xErrorMessage,
3870 xMessageName,
3871 xTableName);
3872 IF PG_DEBUG <> 0 THEN
3873 oe_debug_pub.add('Get_Mandatory_Components: ' ||
3874 'Returned from load_mandatory_components_pds with '||lStatus, 2);
3875 END IF;
3876
3877 if lStatus <> 1 then
3878 IF PG_DEBUG <> 0 THEN
3879 oe_debug_pub.add('Get_Mandatory_Components: ' ||
3880 ' Load_mandatory_components_pds returned with Error ',1);
3881 END IF;
3882 raise proc_error;
3883 end if;
3884
3885 else
3886
3887
3888
3889
3890 IF PG_DEBUG <> 0 THEN
3891 oe_debug_pub.add('Get_Mandatory_Components: ' || ' now calling load_mandatory_components ' , 2);
3892 END IF;
3893
3894
3895
3896 lStatus := load_mandatory_components(p_ship_set,
3897 lModelIndex,
3898 v_request_date,
3899 lGrpId,
3900 xErrorMessage,
3901 xMessageName,
3902 xTableName);
3903 IF PG_DEBUG <> 0 THEN
3904 oe_debug_pub.add('Get_Mandatory_Components: ' || 'Returned from load_mand_comps with '||lStatus, 2);
3905 END IF;
3906 if lStatus <> 1 then
3907 IF PG_DEBUG <> 0 THEN
3908 oe_debug_pub.add('Get_Mandatory_Components: ' || ' Load_mandatory_components returned with Error ',1);
3909 END IF;
3910 raise proc_error;
3911 end if;
3912
3913 end if ; -- INV_CTP chk
3914
3915 -- bugfix 3779636
3916
3917
3918
3919
3920 else
3921
3922
3923 oe_debug_pub.add(' Load_mandatory_components returned without processing
3924 as model qty is 0 ',1);
3925 return 1 ;
3926
3927 end if;
3928
3929
3930 end if;
3931
3932 -- for calculating ATP lead time
3933 lOrg_id := p_ship_set.source_organization_id(lModelIndex);
3934 lItem_id := p_ship_set.inventory_item_id(lModelIndex);
3935 select nvl(fixed_lead_time,0),
3936 nvl(variable_lead_time,0)
3937 into lFixedLt,
3938 lVarLt
3939 from mtl_system_items msi
3940 where msi.inventory_item_id = lItem_id
3941 and msi.organization_id = lOrg_id;
3942
3943 lStmtNumber := 710;
3944
3945 lAtpLt := ceil( lFixedLt + (p_ship_set.Quantity_Ordered(lModelIndex) * lVarLt));
3946
3947
3948 select count(*)
3949 into chk
3950 from bom_explosion_temp
3951 where group_id = lGrpId
3952 and ( Line_id is null or top_bill_sequence_id = -1) ; /* BugFix 2897132 */
3953
3954 IF PG_DEBUG <> 0 THEN
3955 oe_debug_pub.add ('Get_Mandatory_Components: ' || ' Lines exploded ' || chk, 1);
3956 END IF;
3957
3958 lStmtNumber := 730;
3959
3960 IF PG_DEBUG <> 0 THEN
3961 oe_debug_pub.add ('Get_Mandatory_Components: ' || 'Going to Print Mandatory Comps ', 1);
3962 END IF;
3963
3964
3965 i := 1;
3966 for nxtrec in mandatory_comps
3967 loop
3968 /*-------------------------------------------+
3969 Call MRP's API to extend x_smc_rec and copy
3970 p_model_rec as default
3971 *-------------------------------------------*/
3972
3973
3974 lStmtNumber := 740;
3975 IF PG_DEBUG <> 0 THEN
3976 oe_debug_pub.add ('Get_Mandatory_Components: ' || ' Before calling MRP API::i='||to_char(i),1);
3977 END IF;
3978 MRP_ATP_PVT.assign_Atp_input_rec(p_ship_set,
3979 lModelIndex,
3980 x_smc_rec,
3981 lStatus );
3982 IF PG_DEBUG <> 0 THEN
3983 oe_debug_pub.add ('Get_Mandatory_Components: ' || ' MRP API returns with '||lStatus, 2);
3984 END IF;
3985
3986 if lStatus <> FND_API.G_RET_STS_SUCCESS then
3987 xErrorMessage := 'assign_Atp_input_rec returned with Error';
3988 raise proc_error;
3989 end if;
3990
3991 x_smc_rec.inventory_item_id(i) := nxtrec.cid ;
3992 x_smc_rec.quantity_ordered(i) := nxtrec.eq ;
3993 x_smc_rec.quantity_uom(i) := nxtrec.uom ; -- Bugfix 1998386
3994 x_smc_rec.atp_lead_time(i) := lAtpLt;
3995
3996 -- Bugfix 2897132
3997 if( nxtrec.line_id is not null ) then
3998 x_smc_rec.identifier(i) := nxtrec.line_id;
3999 end if ;
4000
4001 x_smc_rec.attribute_01(i) := nxtrec.wip_supply_type; -- bugfix 3254039
4002
4003
4004 IF PG_DEBUG <> 0 THEN
4005 oe_debug_pub.add('Get_Mandatory_Components: ' || 'Mand comp ' || i ||
4006 ' inv ' || x_smc_rec.inventory_item_id(i) ||
4007 ' eq ' || x_smc_rec.quantity_ordered(i) ||
4008 ' id ' || x_smc_rec.identifier(i) ||
4009 ' wip supply type ' || x_smc_rec.attribute_01(i) , 1 ) ; -- bugfix 3254039
4010
4011 END IF;
4012
4013
4014
4015
4016 i := i + 1;
4017 end loop;
4018
4019
4020 IF PG_DEBUG <> 0 THEN
4021 oe_debug_pub.add ('Get_Mandatory_Components: ' || 'Done Print Mandatory Comps ', 1);
4022 END IF;
4023
4024
4025 /*------------------------------------+
4026 Clean up bom_explosion_temp table
4027 +------------------------------------*/
4028 lStmtNumber := 750;
4029
4030 delete from bom_explosion_temp
4031 where group_id = lGrpId;
4032
4033 return(1);
4034
4035 exception
4036 when no_data_found then
4037 xErrorMessage := 'CTOCITMB:'||to_char(lStmtNumber)||': No Data Found ' ;
4038 return (0);
4039 when proc_error then
4040 xErrorMessage := 'CTOCITMB :'|| to_char(lStmtNumber) || ': ' || xErrorMessage;
4041 return(0);
4042 when others then
4043 IF PG_DEBUG <> 0 THEN
4044 oe_debug_pub.add ('Get_Mandatory_Components: ' || 'Others exception is get_mand_comp::'||substrb(sqlerrm,1,150));
4045 END IF;
4046 return(0);
4047
4048 end Get_Mandatory_Components;
4049
4050
4051
4052 /*-----------------------------------------------------+
4053 Creates configuration item in mtl_system_items.
4054 This function does not check the validity of
4055 data in oe_order_lines. The validity checks
4056 like 'check that config row does not exists already'
4057 are implemented in activity wrapper / batch program
4058 +-----------------------------------------------------*/
4059
4060 --- The following procedure is modified by Renga Kannan on 08/31/01
4061 --- While instering the rows into MTL_SYSTEM_ITEMS one new function
4062 --- is called for list_price field. CTO_CUSTOM_LIST_PRICE_PK.get_list_price
4063 --- is called to get the list price thru custom calculation. if it is null then
4064 --- it will be copied from its model list price. This change is doen as part of
4065 --- Procuring config Phase I -- Patchset G
4066
4067 -- We are removing the custom API call as part of patchset H. Instead this API will get called
4068 -- from list price rollup. List price rollup will be called in later part of the program.
4069 -- We don't copy the list price from Patchset H. It will be done by list price rollup program.
4070 -- Fixed by Renga Kannan on 05/14/02
4071
4072
4073 FUNCTION Create_Item(
4074 pModelId in number,
4075 pLineId in number,
4076 pConfigId in out NOCOPY number, /* NOCOPY Project */
4077 xMsgCount out NOCOPY number,
4078 xMsgData out NOCOPY varchar2,
4079 p_mode in varchar2 default 'AUTOCONFIG' )
4080 RETURN integer
4081 IS
4082
4083 lCiDel varchar2(1) ;
4084 lItemType varchar2(30);
4085
4086 lNumberMethod number ;
4087 lStmtNumber number ;
4088 lFndSize number ;
4089 app_col_ind number ;
4090 lNextNum number ;
4091 lOrderNum number ;
4092 lLineNum number ;
4093 lDeliveryNum number ;
4094 lValidationOrg number ;
4095 lTempvar number ;
4096 lProfileVal number ;
4097 lOpUnit number ;
4098 lRcvOrg number;
4099
4100 lReturnStatus varchar2(1);
4101
4102 lConfigSegName fnd_id_flex_segments.segment_name%type;
4103 app_column fnd_id_flex_segments.segment_name%type;
4104 new_item_num mtl_system_items.segment1%Type ;
4105
4106 lCreateRules varchar2(1);
4107 lStatus number;
4108
4109 type lSegType is table of
4110 mtl_system_items_interface.segment1%type
4111 index by binary_integer;
4112
4113 seg lSegType ;
4114
4115 l_model_tab oe_order_pub.Line_tbl_type;
4116
4117 -- Start Bugfix 2157740
4118 cursor c_get_org_id is
4119 select msi.organization_id src_org_id
4120 from mtl_system_items msi
4121 where msi.inventory_item_id = pConfigId
4122 and not exists
4123 (SELECT 'x'
4124 FROM FND_ATTACHED_DOCUMENTS
4125 WHERE pk1_value = to_char(msi.organization_id) -- 2774571
4126 AND pk2_value = to_char(msi.inventory_item_id) -- 2774571
4127 AND entity_name = 'MTL_SYSTEM_ITEMS');
4128
4129
4130 v_src_org_id mtl_system_items.organization_id%type;
4131 l_document_id Number;
4132
4133
4134 -- End bugfix 2157740
4135
4136 /* Sushant removed declaration of lDupItem cursor as it is not used anymore .
4137 bug 2706981 was used to provide an alternate logic
4138 */
4139
4140
4141 v_program_id bom_cto_order_lines.program_id%type ;
4142 x_return_status varchar2(1);
4143
4144 lOptionNum number ; -- 2652379 : new variable
4145 v_ato_line_id number ;
4146 BEGIN
4147
4148 lReturnStatus := fnd_api.G_RET_STS_SUCCESS;
4149
4150 gUserId := nvl(Fnd_Global.USER_ID, -1);
4151 gLoginId := nvl(Fnd_Global.LOGIN_ID, -1);
4152 lCiDel := FND_PROFILE.Value('BOM:CONFIG_ITEM_DELIMITER');
4153
4154
4155
4156 /* BUG #1957336 Change for preconfigure bom by Sushant Sawant */
4157 /* Added by Sushant for checking preconfigure bom module populated records */
4158 -- bugfix 2267646 Added nvl
4159
4160 select NVL(program_id,0) , ato_line_id into v_program_id , v_ato_line_id
4161 from bom_cto_order_lines where line_id = pLineId ;
4162
4163
4164 /* BUG #1957336 Change for preconfigure bom by Sushant Sawant */
4165 /* Changes for patchset J
4166 if( v_program_id = CTO_UTILITY_PK.PC_BOM_PROGRAM_ID ) then
4167 */
4168
4169
4170 oe_debug_pub.add('Create_Item: ' || 'p_mode ' || p_mode ,2);
4171
4172 if( p_mode = 'PRECONFIG' ) then
4173
4174 lValidationOrg := CTO_UTILITY_PK.PC_BOM_VALIDATION_ORG ;
4175
4176 else
4177
4178 IF PG_DEBUG <> 0 THEN
4179 oe_debug_pub.add('Create_Item: ' || 'Before getting validation org',2);
4180 END IF;
4181
4182 /*
4183 BUG:3484511
4184 ------------------------
4185 select nvl(master_organization_id,-99) -- bugfix 2646849: master_organization_id can be 0
4186 into lValidationOrg
4187 from oe_order_lines_all oel,
4188 oe_system_parameters_all ospa
4189 where oel.line_id = pLineid
4190 and nvl(oel.org_id, -1) = nvl(ospa.org_id, -1) --bug 1531691
4191 and oel.inventory_item_id = pModelId;
4192 */
4193
4194
4195
4196 IF PG_DEBUG <> 0 THEN
4197 oe_debug_pub.add('Create_Item: ' || 'Going to fetch Validation Org ' ,2);
4198 END IF;
4199
4200
4201 select nvl( oe_sys_parameters.value( 'MASTER_ORGANIZATION_ID' , oel.org_id) , -99)
4202 into lValidationOrg from oe_order_lines_all oel
4203 where oel.line_id = pLineId ;
4204
4205
4206 end if ;
4207
4208
4209 if lVAlidationOrg = -99 then -- bugfix 2646849
4210 cto_msg_pub.cto_message('BOM','CTO_VALIDATION_ORG_NOT_SET');
4211 raise FND_API.G_EXC_ERROR;
4212 end if;
4213
4214 IF PG_DEBUG <> 0 THEN
4215 oe_debug_pub.add('Create_Item: ' || 'Validation Org is :' || lValidationOrg,2);
4216 END IF;
4217
4218
4219 --
4220 -- If the config item is a matched item, enable the matched item
4221 -- in all orgs. If it is a new item, create a new item in all orgs
4222 --
4223
4224 IF PG_DEBUG <> 0 THEN
4225 oe_debug_pub.add('Create_Item: ' || 'config_item_id::'||to_char(pConfigId),2);
4226 END IF;
4227
4228 IF (pConfigId is NULL) THEN
4229
4230 -- config id is not populated in config_item_id
4231 -- generate a new config item
4232
4233 /*--------------------------------------------------+
4234 Check to see if the config_segment_name exists in
4235 bom_parameters for the given organization.
4236 BOM_parameters are organization dependent, we will use
4237 BOM_parameter settings in the OE validation org.
4238 +---------------------------------------------------*/
4239
4240 lStmtNumber := 15;
4241 select config_segment_name,
4242 config_number_method_type
4243 into lConfigSegName,
4244 lNumberMethod
4245 from bom_parameters
4246 where organization_id = lValidationOrg;
4247
4248
4249 if lConfigSegName is NULL then
4250 cto_msg_pub.cto_message('BOM','CTO_CONFIG_SEGMENT_ERROR');
4251 raise FND_API.G_EXC_ERROR;
4252 end if;
4253
4254 IF PG_DEBUG <> 0 THEN
4255 oe_debug_pub.add('Create_Item: ' || 'config Segment is : ' || lConfigSegName,2 );
4256
4257 oe_debug_pub.add('Create_Item: ' || 'Number Method is : ' || lNumberMethod,2 );
4258 END IF;
4259
4260 /* BUG #2172057 Change for preconfigure bom by Sushant Sawant */
4261 if( v_program_id = CTO_UTILITY_PK.PC_BOM_PROGRAM_ID ) then
4262 -- 2663450 : Change the NumberMethod only when it is <> 4.
4263 if lNumberMethod <> 4 then
4264 lNumberMethod := 1 ;
4265 end if;
4266
4267 IF PG_DEBUG <> 0 THEN
4268 oe_debug_pub.add('Create_Item: ' || 'Number Method Changed due to preconfigure bom restriction of append with sequence number: ' ||
4269 lNumberMethod,2 );
4270 END IF;
4271
4272 end if ;
4273
4274 lStmtNumber := 20;
4275 -- Bugfix 1736339 : sql%notfound will not be raised in case of SELECT, instead NO_DATA_FOUND
4276 -- exception is raised.
4277 -- Added outer join to the query so that we'll default the maximum_size to 40
4278 -- Merged stmt# 40 in the same query.
4279 -- Since lConfigSegName is available, we will use this instead of joining bom_parameters.
4280
4281 select nvl(fv.maximum_size,40), fs.application_column_name
4282 into lFndSize, app_column
4283 from -- bom_parameters p,
4284 fnd_id_flex_segments fs,
4285 fnd_flex_value_sets fv
4286 where --p.organization_id = lValidationOrg and
4287 fs.id_flex_code = 'MSTK'
4288 and fs.id_flex_num = 101
4289 and fs.segment_name = lConfigSegName --p.config_segment_name
4290 and fs.application_id = 401 -- INV
4291 and fs.flex_value_set_id = fv.flex_value_set_id(+);
4292
4293
4294 app_col_ind := to_number( substrb(app_column,8,length( app_column) -7 ));
4295
4296 lStmtNumber := 30;
4297
4298 select
4299 segment1,
4300 segment2,
4301 segment3,
4302 segment4,
4303 segment5,
4304 segment6,
4305 segment7,
4306 segment8,
4307 segment9,
4308 segment10,
4309 segment11,
4310 segment12,
4311 segment13,
4312 segment14,
4313 segment15,
4314 segment16,
4315 segment17,
4316 segment18,
4317 segment19,
4318 segment20
4319 into
4320 seg(1),
4321 seg(2),
4322 seg(3),
4323 seg(4),
4324 seg(5),
4325 seg(6),
4326 seg(7),
4327 seg(8),
4328 seg(9),
4329 seg(10),
4330 seg(11),
4331 seg(12),
4332 seg(13),
4333 seg(14),
4334 seg(15),
4335 seg(16),
4336 seg(17),
4337 seg(18),
4338 seg(19),
4339 seg(20)
4340 from mtl_system_items msi
4341 where inventory_item_id = pModelId
4342 and organization_id = lValidationOrg;
4343
4344 lStmtNumber := 50;
4345
4346 if lNumberMethod = 1 then
4347 select mtl_system_items_B_S.nextval
4348 into lNextNum
4349 from dual;
4350
4351 -- bugfix 1933740 : Replaced seg(1) with seg(app_col_ind)
4352
4353 select ( substrb(seg(app_col_ind),1, decode(greatest(lFndSize,40),40,lFndSize -1-length(lNextNum),39 - length(lNextNum))) || lCiDel || to_char(lNextNum))
4354 into new_item_num
4355 from dual;
4356
4357 elsif lNumberMethod = 2 then
4358 select to_char(mtl_system_items_B_S.nextval)
4359 into new_item_num
4360 from dual;
4361
4362 -- 2652379 : When numbering method is 3 , i.e Replace with order num, line num;
4363 -- item numbering segment ( Part num , item num , etc. ) is replaced with order
4364 -- number + line_number + shipment number. For model under model , item number gets
4365 -- appended with a sequence since child and parent model are having same number
4366 -- ( i.e. same order# + line# + shipment# ) . As we select model with plan level
4367 -- descending to create corresponding config items , the model at lowest level
4368 -- ( i.e. having highest plan level ) will get order# + line# + shipment# as its
4369 -- config item number while for all higher level models it will be seq. appended
4370 -- ( i.e. order# + line# + shipment# + seq ).
4371 -- E.g. For an order # 1000 , line# 1 , shipment# 1 a Bill structure like
4372 -- M1
4373 -- .. M2
4374 -- ....M3
4375 -- will get 1000*1*1 for M3 , 1000*1*1*seq1 for M2 and 1000*1*1*seq2 for M1
4376 -- After this fix , a new column option_number will be appended so that config
4377 -- items at different plan level will have unique config item number.
4378 -- Also this will eliminate the need for checking duplicate config items while
4379 -- traversing the bill as long as option_number is NOT NULL. Under new numbering
4380 -- scheme , for the above example , config items will have following numbers :
4381 -- 1000*1*1 for M1 , 1000*1*1*1 for M2 and 1000*1*1*2 for M3
4382 -- where M1 , being at top level does not have option number , while M2 and M3
4383 -- have option# 1 and 2 resp.
4384 -- Also , in this fix decode on lDeliveryNum to check NULL condition is removed
4385 -- since this column is defined as NOT NULL in database.
4386
4387
4388 elsif lNumberMethod = 3 then
4389 lStmtNumber := 60;
4390 select oeh.order_number,
4391 oel.line_number,
4392 oel.shipment_number,
4393 oel.option_number -- 2652379 : new column
4394 into lOrderNum,
4395 lLineNum,
4396 lDeliveryNum,
4397 lOptionNum -- 2652379 : new variable
4398 from oe_order_lines_all oel,
4399 oe_order_headers_all oeh
4400 where oel.line_id = pLineId
4401 and oel.header_id = oeh.header_id;
4402
4403 -- 2652379 Changed decode
4404 /*
4405 select decode(lDeliveryNum, NULL, lOrderNum || lCiDel || lLineNum,
4406 lOrderNum || lCiDel || lLineNum || lCiDel|| lDeliveryNum )
4407 into new_item_num
4408 from dual;
4409 */
4410 select decode (lOptionNum, NULL, lOrderNum || lCiDel || lLineNum || lCiDel|| lDeliveryNum,
4411 lOrderNum || lCiDel || lLineNum || lCiDel|| lDeliveryNum || lCiDel || lOptionNum )
4412 into new_item_num
4413 from dual;
4414 -- end fix 2652379
4415 else
4416 /*--------------------------+
4417 Call to user Defined Method
4418 +--------------------------*/
4419 -- bugfix 2663450: call custom api ..
4420
4421 if( v_program_id = CTO_UTILITY_PK.PC_BOM_PROGRAM_ID ) then
4422 new_item_num := CTO_CUSTOM_CONFIG_NUMBER.user_item_number
4423 ( model_item_id => pModelId,
4424 model_line_id => NULL,
4425 param1 => NULL,
4426 param2 => NULL,
4427 param3 => NULL,
4428 param4 => NULL,
4429 param5 => NULL
4430 );
4431 IF PG_DEBUG <> 0 THEN
4432 oe_debug_pub.add( 'Precfg case - Custom Item number is ' || new_item_num ,2 );
4433 END IF;
4434 else
4435 new_item_num := BOMPCFGI.user_item_number(pLineId);
4436 IF PG_DEBUG <> 0 THEN
4437 oe_debug_pub.add('Create_Item: ' || 'Item number is ' || new_item_num ,2 );
4438 END IF;
4439 end if;
4440 end if; -- End check for number method
4441
4442 seg(app_col_ind) := new_item_num;
4443
4444 lStmtNumber := 70;
4445 /*-------------------------------------------------+
4446 if a item with name new_item_num already exists in
4447 table, append it with a sequence_number to make it
4448 unique
4449 +--------------------------------------------------*/
4450
4451 -- bugfix 2706981
4452 -- Replaced the loop (commented below) with function check_dup_item
4453 -- which dynamically builts the query to check duplicate item names.
4454 --
4455
4456 if check_dup_item(seg(1), seg(2), seg(3), seg(4), seg(5),
4457 seg(6), seg(7), seg(8), seg(9), seg(10),
4458 seg(11), seg(12), seg(13), seg(14), seg(15),
4459 seg(16), seg(17), seg(18), seg(19), seg(20)) = 1
4460 then
4461 IF PG_DEBUG <> 0 THEN
4462 oe_debug_pub.add( 'Create_Item: '|| 'generating unique name' ,2 );
4463 END IF;
4464 select to_char(mtl_system_items_B_S.nextval)
4465 into lNextNum
4466 from dual;
4467 seg(app_col_ind) := new_item_num || lCiDel || lNextNum;
4468 end if;
4469
4470 /* bugfix 2706981: commented out and replaced with above check_dup_item
4471 see above.
4472
4473 for nxt_rec in lDupItem
4474 loop
4475
4476 IF PG_DEBUG <> 0 THEN
4477 oe_debug_pub.add('Create_Item: ' || 'generating unique name' ,2 );
4478 END IF;
4479 select to_char(mtl_system_items_B_S.nextval)
4480 into lNextNum
4481 from dual;
4482 seg(app_col_ind) := new_item_num || lCiDel || lNextNum;
4483 exit;
4484 end loop;
4485 */
4486
4487 IF PG_DEBUG <> 0 THEN
4488 oe_debug_pub.add('Create_Item: ' || 'item numbering segment is '|| app_col_ind ,2 );
4489
4490 oe_debug_pub.add('Create_Item: ' || 'new_item number is ' || seg(app_col_ind) ,2 );
4491 END IF;
4492
4493 select to_char(mtl_system_items_b_S.nextval) into pConfigId from dual;
4494
4495 IF PG_DEBUG <> 0 THEN
4496 oe_debug_pub.add('Create_Item: ' || 'new pConfigId is '||to_char(pConfigId),2);
4497 END IF;
4498
4499 ELSE
4500 -- config id is populated in config_item_id
4501 -- use the matched item
4502
4503 select distinct
4504 segment1,
4505 segment2,
4506 segment3,
4507 segment4,
4508 segment5,
4509 segment6,
4510 segment7,
4511 segment8,
4512 segment9,
4513 segment10,
4514 segment11,
4515 segment12,
4516 segment13,
4517 segment14,
4518 segment15,
4519 segment16,
4520 segment17,
4521 segment18,
4522 segment19,
4523 segment20
4524 into
4525 seg(1),
4526 seg(2),
4527 seg(3),
4528 seg(4),
4529 seg(5),
4530 seg(6),
4531 seg(7),
4532 seg(8),
4533 seg(9),
4534 seg(10),
4535 seg(11),
4536 seg(12),
4537 seg(13),
4538 seg(14),
4539 seg(15),
4540 seg(16),
4541 seg(17),
4542 seg(18),
4543 seg(19),
4544 seg(20)
4545 from mtl_system_items msi
4546 where inventory_item_id = pConfigId;
4547
4548 IF PG_DEBUG <> 0 THEN
4549 oe_debug_pub.add('Create_Item: ' || 'matched pConfigId is '||to_char(pConfigId),2);
4550 END IF;
4551
4552 END IF; -- matched/new item
4553
4554
4555
4556 -- rkaza. 10/21/2004. bug 3860077. Item type should be null if profile is null.
4557 lItemType := FND_PROFILE.Value('BOM:CONFIG_ITEM_TYPE');
4558
4559 /*-----------------------------------------------------------+
4560 Insert a row into the mtl_system_items table.
4561 +------------------------------------------------------------*/
4562
4563 --xTableName := 'MTL_SYSTEM_ITEMS';
4564 lStmtNumber := 80;
4565
4566 /* need to add attribute controlled statement for preconfigured item */
4567 oe_debug_pub.add('Create_Item: ' || 'p_mode is '|| p_mode ,2);
4568
4569 if( p_mode = 'AUTOCONFIG' OR pLineId <> v_ato_line_id ) then
4570
4571 oe_debug_pub.add('Create_Item: ' || 'came into AUTOCONFIG ' ,2);
4572 /*
4573 tracking_quantity_ind TRACK,
4574 4 ont_pricing_qty_source PRCQTY, approval_status
4575 */
4576
4577 --appsperf bug# 4905845, sql id 16104136
4578 --decrease comments within sql to max extent to reduce shared memory
4579
4580 insert into mtl_system_items_b
4581 (inventory_item_id,
4582 organization_id,
4583 last_update_date,
4584 last_updated_by,
4585 creation_date,
4586 created_by,
4587 last_update_login,
4588 summary_flag,
4589 enabled_flag,
4590 start_date_active,
4591 end_date_active,
4592 description,
4593 buyer_id,
4594 accounting_rule_id,
4595 invoicing_rule_id,
4596 segment1,
4597 segment2,
4598 segment3,
4599 segment4,
4600 segment5,
4601 segment6,
4602 segment7,
4603 segment8,
4604 segment9,
4605 segment10,
4606 segment11,
4607 segment12,
4608 segment13,
4609 segment14,
4610 segment15,
4611 segment16,
4612 segment17,
4613 segment18,
4614 segment19,
4615 segment20,
4616 attribute_category,
4617 attribute1,
4618 attribute2,
4619 attribute3,
4620 attribute4,
4621 attribute5,
4622 attribute6,
4623 attribute7,
4624 attribute8,
4625 attribute9,
4626 attribute10,
4627 attribute11,
4628 attribute12,
4629 attribute13,
4630 attribute14,
4631 attribute15,
4632 purchasing_item_flag,
4633 shippable_item_flag,
4634 customer_order_flag,
4635 internal_order_flag,
4636 service_item_flag,
4637 inventory_item_flag,
4638 eng_item_flag,
4639 inventory_asset_flag,
4640 purchasing_enabled_flag,
4641 customer_order_enabled_flag,
4642 internal_order_enabled_flag,
4643 so_transactions_flag,
4644 mtl_transactions_enabled_flag,
4645 stock_enabled_flag,
4646 bom_enabled_flag,
4647 build_in_wip_flag,
4648 revision_qty_control_code,
4649 item_catalog_group_id,
4650 catalog_status_flag,
4651 returnable_flag,
4652 default_shipping_org,
4653 collateral_flag,
4654 taxable_flag,
4655 allow_item_desc_update_flag,
4656 inspection_required_flag,
4657 receipt_required_flag,
4658 market_price,
4659 hazard_class_id,
4660 rfq_required_flag,
4661 qty_rcv_tolerance,
4662 un_number_id,
4663 price_tolerance_percent,
4664 asset_category_id,
4665 rounding_factor,
4666 unit_of_issue,
4667 enforce_ship_to_location_code,
4668 allow_substitute_receipts_flag,
4669 allow_unordered_receipts_flag,
4670 allow_express_delivery_flag,
4671 days_early_receipt_allowed,
4672 days_late_receipt_allowed,
4673 receipt_days_exception_code,
4674 receiving_routing_id,
4675 invoice_close_tolerance,
4676 receive_close_tolerance,
4677 auto_lot_alpha_prefix,
4678 start_auto_lot_number,
4679 lot_control_code,
4680 shelf_life_code,
4681 shelf_life_days,
4682 serial_number_control_code,
4683 start_auto_serial_number,
4684 auto_serial_alpha_prefix,
4685 source_type,
4686 source_organization_id,
4687 source_subinventory,
4688 expense_account,
4689 encumbrance_account,
4690 restrict_subinventories_code,
4691 unit_weight,
4692 weight_uom_code,
4693 volume_uom_code,
4694 unit_volume,
4695 restrict_locators_code,
4696 location_control_code,
4697 shrinkage_rate,
4698 acceptable_early_days,
4699 planning_time_fence_code,
4700 demand_time_fence_code,
4701 lead_time_lot_size,
4702 std_lot_size,
4703 cum_manufacturing_lead_time,
4704 overrun_percentage,
4705 acceptable_rate_increase,
4706 acceptable_rate_decrease,
4707 cumulative_total_lead_time,
4708 planning_time_fence_days,
4709 demand_time_fence_days,
4710 end_assembly_pegging_flag,
4711 planning_exception_set,
4712 bom_item_type,
4713 pick_components_flag,
4714 replenish_to_order_flag,
4715 base_item_id,
4716 atp_components_flag,
4717 atp_flag,
4718 fixed_lead_time,
4719 variable_lead_time,
4720 wip_supply_locator_id,
4721 wip_supply_type,
4722 wip_supply_subinventory,
4723 primary_uom_code,
4724 primary_unit_of_measure,
4725 allowed_units_lookup_code,
4726 cost_of_sales_account,
4727 sales_account,
4728 default_include_in_rollup_flag,
4729 inventory_item_status_code,
4730 inventory_planning_code,
4731 planner_code,
4732 planning_make_buy_code,
4733 fixed_lot_multiplier,
4734 rounding_control_type,
4735 carrying_cost,
4736 postprocessing_lead_time,
4737 preprocessing_lead_time,
4738 full_lead_time,
4739 order_cost,
4740 mrp_safety_stock_percent,
4741 mrp_safety_stock_code,
4742 min_minmax_quantity,
4743 max_minmax_quantity,
4744 minimum_order_quantity,
4745 fixed_order_quantity,
4746 fixed_days_supply,
4747 maximum_order_quantity,
4748 atp_rule_id,
4749 picking_rule_id,
4750 reservable_type,
4751 positive_measurement_error,
4752 negative_measurement_error,
4753 engineering_ecn_code,
4754 engineering_item_id,
4755 engineering_date,
4756 service_starting_delay,
4757 vendor_warranty_flag,
4758 serviceable_component_flag,
4759 serviceable_product_flag,
4760 base_warranty_service_id,
4761 payment_terms_id,
4762 preventive_maintenance_flag,
4763 primary_specialist_id,
4764 secondary_specialist_id,
4765 serviceable_item_class_id,
4766 time_billable_flag,
4767 material_billable_flag,
4768 expense_billable_flag,
4769 prorate_service_flag,
4770 coverage_schedule_id,
4771 service_duration_period_code,
4772 service_duration,
4773 max_warranty_amount,
4774 response_time_period_code,
4775 response_time_value,
4776 new_revision_code,
4777 tax_code,
4778 must_use_approved_vendor_flag,
4779 safety_stock_bucket_days,
4780 auto_reduce_mps,
4781 costing_enabled_flag,
4782 invoiceable_item_flag,
4783 invoice_enabled_flag,
4784 outside_operation_flag,
4785 outside_operation_uom_type,
4786 auto_created_config_flag,
4787 cycle_count_enabled_flag,
4788 item_type,
4789 model_config_clause_name,
4790 ship_model_complete_flag,
4791 mrp_planning_code,
4792 repetitive_planning_flag,
4793 return_inspection_requirement,
4794 effectivity_control,
4795 request_id,
4796 program_application_id,
4797 program_id,
4798 program_update_date,
4799 comms_nl_trackable_flag, -- bugfix 2200256
4800 default_so_source_type,
4801 create_supply_flag,
4802 -- 2336548
4803 lot_status_enabled,
4804 default_lot_status_id,
4805 serial_status_enabled,
4806 default_serial_status_id,
4807 lot_split_enabled,
4808 lot_merge_enabled,
4809 bulk_picked_flag,
4810
4811 -- 2400609
4812 FINANCING_ALLOWED_FLAG,
4813 EAM_ITEM_TYPE ,
4814 EAM_ACTIVITY_TYPE_CODE,
4815 EAM_ACTIVITY_CAUSE_CODE,
4816 EAM_ACT_NOTIFICATION_FLAG,
4817 EAM_ACT_SHUTDOWN_STATUS,
4818 SUBSTITUTION_WINDOW_CODE,
4819 SUBSTITUTION_WINDOW_DAYS,
4820 PRODUCT_FAMILY_ITEM_ID,
4821 CHECK_SHORTAGES_FLAG,
4822 PLANNED_INV_POINT_FLAG,
4823 OVER_SHIPMENT_TOLERANCE,
4824 UNDER_SHIPMENT_TOLERANCE,
4825 OVER_RETURN_TOLERANCE,
4826 UNDER_RETURN_TOLERANCE,
4827 PURCHASING_TAX_CODE,
4828 OVERCOMPLETION_TOLERANCE_TYPE,
4829 OVERCOMPLETION_TOLERANCE_VALUE,
4830 INVENTORY_CARRY_PENALTY,
4831 OPERATION_SLACK_PENALTY,
4832 UNIT_LENGTH,
4833 UNIT_WIDTH,
4834 UNIT_HEIGHT,
4835 LOT_TRANSLATE_ENABLED,
4836 CONTAINER_ITEM_FLAG,
4837 VEHICLE_ITEM_FLAG,
4838 DIMENSION_UOM_CODE,
4839 SECONDARY_UOM_CODE,
4840 MAXIMUM_LOAD_WEIGHT,
4841 MINIMUM_FILL_PERCENT,
4842 CONTAINER_TYPE_CODE,
4843 INTERNAL_VOLUME,
4844 EQUIPMENT_TYPE,
4845 INDIVISIBLE_FLAG,
4846 GLOBAL_ATTRIBUTE_CATEGORY,
4847 GLOBAL_ATTRIBUTE1,
4848 GLOBAL_ATTRIBUTE2,
4849 GLOBAL_ATTRIBUTE3,
4850 GLOBAL_ATTRIBUTE4,
4851 GLOBAL_ATTRIBUTE5,
4852 GLOBAL_ATTRIBUTE6,
4853 GLOBAL_ATTRIBUTE7,
4854 GLOBAL_ATTRIBUTE8,
4855 GLOBAL_ATTRIBUTE9,
4856 GLOBAL_ATTRIBUTE10,
4857 DUAL_UOM_CONTROL,
4858 DUAL_UOM_DEVIATION_HIGH,
4859 DUAL_UOM_DEVIATION_LOW,
4860 CONTRACT_ITEM_TYPE_CODE,
4861 SUBSCRIPTION_DEPEND_FLAG,
4862 SERV_REQ_ENABLED_CODE,
4863 SERV_BILLING_ENABLED_FLAG,
4864 RELEASE_TIME_FENCE_CODE, -- 2898851
4865 RELEASE_TIME_FENCE_DAYS, -- 2898851
4866 DEFECT_TRACKING_ON_FLAG, -- 2858080
4867 SERV_IMPORTANCE_LEVEL,
4868
4869 WEB_STATUS , --2727983
4870 tracking_quantity_ind, --Attribute for Item in patchset J
4871 ont_pricing_qty_source,
4872 approval_status ,
4873 vmi_minimum_units,
4874 vmi_minimum_days,
4875 vmi_maximum_units,
4876 vmi_maximum_days,
4877 vmi_fixed_order_quantity,
4878 so_authorization_flag,
4879 consigned_flag,
4880 asn_autoexpire_flag,
4881 vmi_forecast_type,
4882 forecast_horizon,
4883 days_tgt_inv_supply,
4884 days_tgt_inv_window,
4885 days_max_inv_supply,
4886 days_max_inv_window,
4887 critical_component_flag,
4888 drp_planned_flag,
4889 exclude_from_budget_flag,
4890 convergence,
4891 continous_transfer,
4892 divergence,
4893
4894 --r12 4574899
4895 lot_divisible_flag,
4896 grade_control_flag,
4897 child_lot_flag,
4898 child_lot_validation_flag,
4899 copy_lot_attribute_flag,
4900 recipe_enabled_flag,
4901 process_quality_enabled_flag,
4902 process_execution_enabled_flag,
4903 process_costing_enabled_flag,
4904 hazardous_material_flag,
4905 preposition_point,
4906 repair_program,
4907 outsourced_assembly
4908
4909
4910 )
4911 select distinct
4912 pConfigId,
4913 m.organization_id,
4914 sysdate,
4915 gUserId,
4916 sysdate,
4917 gUserId,
4918 gLoginId ,
4919 m.summary_flag,
4920 m.enabled_flag,
4921 m.start_date_active,
4922 m.end_date_active,
4923 m.description,
4924 m.buyer_id,
4925 m.accounting_rule_id,
4926 m.invoicing_rule_id,
4927 seg(1),
4928 seg(2),
4929 seg(3),
4930 seg(4),
4931 seg(5),
4932 seg(6),
4933 seg(7),
4934 seg(8),
4935 seg(9),
4936 seg(10),
4937 seg(11),
4938 seg(12),
4939 seg(13),
4940 seg(14),
4941 seg(15),
4942 seg(16),
4943 seg(17),
4944 seg(18),
4945 seg(19),
4946 seg(20),
4947 m.attribute_category,
4948 m.attribute1,
4949 m.attribute2,
4950 m.attribute3,
4951 m.attribute4,
4952 m.attribute5,
4953 m.attribute6,
4954 m.attribute7,
4955 m.attribute8,
4956 m.attribute9,
4957 m.attribute10,
4958 m.attribute11,
4959 m.attribute12,
4960 m.attribute13,
4961 m.attribute14,
4962 m.attribute15,
4963 'Y',
4964 'Y',
4965 'Y',
4966 'Y',
4967 m.service_item_flag,
4968 'Y',
4969 m.eng_item_flag,
4970 m.inventory_asset_flag,
4971 'Y',
4972 'Y',
4973 'Y',
4974 'Y',
4975 'Y',
4976 'Y',
4977 'Y',
4978 'Y',
4979 m.revision_qty_control_code,
4980 m.item_catalog_group_id,
4981 m.catalog_status_flag,
4982 m.returnable_flag,
4983 m.default_shipping_org,
4984 m.collateral_flag,
4985 m.taxable_flag,
4986 m.allow_item_desc_update_flag,
4987 m.inspection_required_flag,
4988 m.receipt_required_flag,
4989 m.market_price,
4990 m.hazard_class_id,
4991 m.rfq_required_flag,
4992 m.qty_rcv_tolerance,
4993 m.un_number_id,
4994 m.price_tolerance_percent,
4995 m.asset_category_id,
4996 m.rounding_factor,
4997 m.unit_of_issue,
4998 m.enforce_ship_to_location_code,
4999 m.allow_substitute_receipts_flag,
5000 m.allow_unordered_receipts_flag,
5001 m.allow_express_delivery_flag,
5002 m.days_early_receipt_allowed,
5003 m.days_late_receipt_allowed,
5004 m.receipt_days_exception_code,
5005 m.receiving_routing_id,
5006 m.invoice_close_tolerance,
5007 m.receive_close_tolerance,
5008 m.auto_lot_alpha_prefix,
5009 m.start_auto_lot_number,
5010 m.lot_control_code,
5011 m.shelf_life_code,
5012 m.shelf_life_days,
5013 m.serial_number_control_code,
5014 m.start_auto_serial_number,
5015 m.auto_serial_alpha_prefix,
5016 m.source_type,
5017 m.source_organization_id,
5018 m.source_subinventory,
5019 m.expense_account,
5020 m.encumbrance_account,
5021 m.restrict_subinventories_code,
5022 -- 2301167 : we will calculate the unit weight/vol later..
5023 null,
5024 null,
5025 null,
5026 null,
5027
5028 m.restrict_locators_code,
5029 m.location_control_code,
5030 m.shrinkage_rate,
5031 m.acceptable_early_days,
5032 m.planning_time_fence_code,
5033 m.demand_time_fence_code,
5034 m.lead_time_lot_size,
5035 m.std_lot_size,
5036 m.cum_manufacturing_lead_time,
5037 m.overrun_percentage,
5038 m.acceptable_rate_increase,
5039 m.acceptable_rate_decrease,
5040 m.cumulative_total_lead_time,
5041 m.planning_time_fence_days,
5042 m.demand_time_fence_days,
5043 m.end_assembly_pegging_flag,
5044 m.planning_exception_set,
5045 4, -- BOM_ITEM_TYPE : standard
5046 'N',
5047 'Y',
5048 pModelId,
5049 evaluate_atp_attributes( m.atp_flag, m.atp_components_flag ),
5050 get_atp_flag,
5051 m.fixed_lead_time,
5052 m.variable_lead_time,
5053 m.wip_supply_locator_id,
5054 m.wip_supply_type,
5055 m.wip_supply_subinventory,
5056 m.primary_uom_code,
5057 m.primary_unit_of_measure,
5058 m.allowed_units_lookup_code,
5059 m.cost_of_sales_account,
5060 m.sales_account,
5061 'Y',
5062 m.inventory_item_status_code,
5063 m.inventory_planning_code,
5064 m.planner_code,
5065 m.planning_make_buy_code,
5066 m.fixed_lot_multiplier,
5067 m.rounding_control_type,
5068 m.carrying_cost,
5069 m.postprocessing_lead_time,
5070 m.preprocessing_lead_time,
5071 m.full_lead_time,
5072 m.order_cost,
5073 m.mrp_safety_stock_percent,
5074 m.mrp_safety_stock_code,
5075 m.min_minmax_quantity,
5076 m.max_minmax_quantity,
5077 m.minimum_order_quantity,
5078 m.fixed_order_quantity,
5079 m.fixed_days_supply,
5080 m.maximum_order_quantity,
5081 m.atp_rule_id,
5082 m.picking_rule_id,
5083 1,
5084 m.positive_measurement_error,
5085 m.negative_measurement_error,
5086 m.engineering_ecn_code,
5087 m.engineering_item_id,
5088 m.engineering_date,
5089 m.service_starting_delay,
5090 m.vendor_warranty_flag,
5091 m.serviceable_component_flag,
5092 m.serviceable_product_flag,
5093 m.base_warranty_service_id,
5094 m.payment_terms_id,
5095 m.preventive_maintenance_flag,
5096 m.primary_specialist_id,
5097 m.secondary_specialist_id,
5098 m.serviceable_item_class_id,
5099 m.time_billable_flag,
5100 m.material_billable_flag,
5101 m.expense_billable_flag,
5102 m.prorate_service_flag,
5103 m.coverage_schedule_id,
5104 m.service_duration_period_code,
5105 m.service_duration,
5106 m.max_warranty_amount,
5107 m.response_time_period_code,
5108 m.response_time_value,
5109 m.new_revision_code,
5110 m.tax_code,
5111 m.must_use_approved_vendor_flag,
5112 m.safety_stock_bucket_days,
5113 m.auto_reduce_mps,
5114 m.costing_enabled_flag,
5115 m.invoiceable_item_flag, -- 'N' Changed for international dropship
5116 m.invoice_enabled_flag, -- 'N' Changed on OM's request
5117 m.outside_operation_flag,
5118 m.outside_operation_uom_type,
5119 'Y',
5120 m.cycle_count_enabled_flag,
5121 lItemType,
5122 m.model_config_clause_name,
5123 m.ship_model_complete_flag,
5124 m.mrp_planning_code, -- earlier it was always from one org only
5125 m.repetitive_planning_flag, -- earlier it was always from one org only
5126 m.return_inspection_requirement,
5127 nvl(m.effectivity_control, 1),
5128 null,
5129 null,
5130 null,
5131 sysdate,
5132 m.comms_nl_trackable_flag, -- 2200256
5133 nvl(m.default_so_source_type,'INTERNAL'),
5134 nvl(m.create_supply_flag, 'Y'),
5135 -- begin bugfix 2336548
5136 m.lot_status_enabled,
5137 m.default_lot_status_id,
5138 m.serial_status_enabled,
5139 m.default_serial_status_id,
5140 m.lot_split_enabled,
5141 m.lot_merge_enabled,
5142 m.bulk_picked_flag,
5143 -- end bugfix 2336548
5144 -- begin bugfix 2400609
5145 m.FINANCING_ALLOWED_FLAG,
5146 m.EAM_ITEM_TYPE ,
5147 m.EAM_ACTIVITY_TYPE_CODE,
5148 m.EAM_ACTIVITY_CAUSE_CODE,
5149 m.EAM_ACT_NOTIFICATION_FLAG,
5150 m.EAM_ACT_SHUTDOWN_STATUS,
5151 m.SUBSTITUTION_WINDOW_CODE,
5152 m.SUBSTITUTION_WINDOW_DAYS,
5153 null, --m.PRODUCT_FAMILY_ITEM_ID, 5385901
5154 m.CHECK_SHORTAGES_FLAG,
5155 m.PLANNED_INV_POINT_FLAG,
5156 m.OVER_SHIPMENT_TOLERANCE,
5157 m.UNDER_SHIPMENT_TOLERANCE,
5158 m.OVER_RETURN_TOLERANCE,
5159 m.UNDER_RETURN_TOLERANCE,
5160 m.PURCHASING_TAX_CODE,
5161 m.OVERCOMPLETION_TOLERANCE_TYPE,
5162 m.OVERCOMPLETION_TOLERANCE_VALUE,
5163 m.INVENTORY_CARRY_PENALTY,
5164 m.OPERATION_SLACK_PENALTY,
5165 m.UNIT_LENGTH,
5166 m.UNIT_WIDTH,
5167 m.UNIT_HEIGHT,
5168 m.LOT_TRANSLATE_ENABLED,
5169 m.CONTAINER_ITEM_FLAG,
5170 m.VEHICLE_ITEM_FLAG,
5171 m.DIMENSION_UOM_CODE,
5172 m.SECONDARY_UOM_CODE,
5173 m.MAXIMUM_LOAD_WEIGHT,
5174 m.MINIMUM_FILL_PERCENT,
5175 m.CONTAINER_TYPE_CODE,
5176 m.INTERNAL_VOLUME,
5177 m.EQUIPMENT_TYPE,
5178 m.INDIVISIBLE_FLAG,
5179 m.GLOBAL_ATTRIBUTE_CATEGORY,
5180 m.GLOBAL_ATTRIBUTE1,
5181 m.GLOBAL_ATTRIBUTE2,
5182 m.GLOBAL_ATTRIBUTE3,
5183 m.GLOBAL_ATTRIBUTE4,
5184 m.GLOBAL_ATTRIBUTE5,
5185 m.GLOBAL_ATTRIBUTE6,
5186 m.GLOBAL_ATTRIBUTE7,
5187 m.GLOBAL_ATTRIBUTE8,
5188 m.GLOBAL_ATTRIBUTE9,
5189 m.GLOBAL_ATTRIBUTE10,
5190 m.DUAL_UOM_CONTROL,
5191 m.DUAL_UOM_DEVIATION_HIGH,
5192 m.DUAL_UOM_DEVIATION_LOW,
5193 m.CONTRACT_ITEM_TYPE_CODE,
5194 m.SUBSCRIPTION_DEPEND_FLAG,
5195 m.SERV_REQ_ENABLED_CODE,
5196 m.SERV_BILLING_ENABLED_FLAG,
5197 m.RELEASE_TIME_FENCE_CODE, -- 2898851
5198 m.RELEASE_TIME_FENCE_DAYS, -- 2898851
5199 m.DEFECT_TRACKING_ON_FLAG, -- 2858080
5200 m.SERV_IMPORTANCE_LEVEL,
5201 -- end bugfix 2400609
5202 m.web_status , -- 2727983
5203 nvl( tracking_quantity_ind , 'P' ),
5204 nvl( m.ont_pricing_qty_source, 'P') ,
5205 m.approval_status,
5206 m.vmi_minimum_units,
5207 m.vmi_minimum_days,
5208 m.vmi_maximum_units,
5209 m.vmi_maximum_days,
5210 m.vmi_fixed_order_quantity,
5211 m.so_authorization_flag,
5212 m.consigned_flag,
5213 m.asn_autoexpire_flag,
5214 m.vmi_forecast_type,
5215 m.forecast_horizon,
5216 m.days_tgt_inv_supply,
5217 m.days_tgt_inv_window,
5218 m.days_max_inv_supply,
5219 m.days_max_inv_window,
5220 m.critical_component_flag,
5221 m.drp_planned_flag,
5222 m.exclude_from_budget_flag,
5223 m.convergence,
5224 m.continous_transfer,
5225 m.divergence,
5226 -- r12,4574899
5227 nvl(m.lot_divisible_flag, 'N'), --Bugfix 6343429
5228 'N',
5229 'N',
5230 'N',
5231 'N',
5232 'N',
5233 'N',
5234 'N',
5235 'N',
5236 'N',
5237 'N',
5238 3,
5239 2
5240
5241 from
5242 mtl_system_items_b m, -- Model
5243 bom_cto_src_orgs bcso,
5244 bom_cto_order_lines bcol
5245 where m.inventory_item_id = pModelId
5246 and bcso.model_item_id = pModelId
5247 and bcso.line_id = pLineId
5248 and bcol.line_id = bcso.line_id
5249 and m.organization_id = bcso.organization_id
5250 and NOT EXISTS
5251 (select NULL
5252 from mtl_system_items_b
5253 where inventory_item_id = pConfigId
5254 and organization_id = m.organization_id);
5255
5256
5257
5258 IF PG_DEBUG <> 0 THEN
5259 oe_debug_pub.add('Create_Item: ' || 'after insert:mtl_system_items_b',2);
5260
5261 oe_debug_pub.add('Create_Item: ' || 'Inserted '||sql%rowcount||' rows in mtl_system_items_b',2);
5262 END IF;
5263 -- added as part of bugfix 1811007
5264
5265
5266
5267
5268 else
5269
5270 oe_debug_pub.add('Create_Item: ' || 'going to call create_precon figured item ' || ' line ' || pLineId ||
5271 ' Model ' || pModelId ||
5272 ' Config ' || pConfigId ||
5273 ' item type ' || lItemType ,2);
5274
5275
5276 create_preconfigured_item( pLineId, pModelId, pConfigId , lItemType ) ;
5277
5278 end if;
5279
5280
5281 -- start bugfix 2157740
5282
5283 lStmtNumber := 81;
5284
5285 IF PG_DEBUG <> 0 THEN
5286 oe_debug_pub.add('Create_Item: ' || 'Opening cursor c_get_org_id.. ' ,3);
5287 END IF;
5288
5289 BEGIN
5290 FOR v_get_org_id in c_get_org_id
5291 LOOP
5292 IF PG_DEBUG <> 0 THEN
5293 oe_debug_pub.add('Create_Item: ' || 'Fetched Org Id '|| v_get_org_id.src_org_id,3);
5294 END IF;
5295 fnd_attached_documents2_pkg.copy_attachments (
5296 X_from_entity_name => 'MTL_SYSTEM_ITEMS',
5297 X_from_pk1_value => v_get_org_id.src_org_id,
5298 X_from_pk2_value => pModelId,
5299 X_from_pk3_value => NULL,
5300 X_from_pk4_value => NULL,
5301 X_from_pk5_value => NULL,
5302 X_to_entity_name => 'MTL_SYSTEM_ITEMS',
5303 X_to_pk1_value => v_get_org_id.src_org_id,
5304 X_to_pk2_value => pConfigId,
5305 X_to_pk3_value => NULL,
5306 X_to_pk4_value => NULL,
5307 X_to_pk5_value => NULL,
5308 X_created_by => fnd_global.USER_ID,
5309 X_last_update_login => fnd_global.USER_ID,
5310 X_program_application_id => fnd_global.PROG_APPL_ID,
5311 X_program_id => fnd_global.CONC_REQUEST_ID,
5312 X_request_id => fnd_global.USER_ID,
5313 X_automatically_added_flag => NULL
5314 );
5315 IF PG_DEBUG <> 0 THEN
5316 oe_debug_pub.add('Create_Item: ' || 'Done copy_attachment ',3);
5317 END IF;
5318 END LOOP;
5319 END;
5320 -- End bugfix 2157740
5321
5322
5323 --
5324 -- Modified the weight/volume calculation logic for supporting MLMO
5325 --
5326
5327 -- bugfix 2301167: Added the global status check (gWtStatus and gVolStatus)
5328 -- This is done to prevent calculation of upper level config's if lower level
5329 -- configs have errored out.
5330
5331 IF PG_DEBUG <> 0 THEN
5332 oe_debug_pub.add ('Create_Item: ' || 'gWtStatus = '||CTO_CONFIG_ITEM_PK.gWtStatus|| ' and gVolStatus = '||CTO_CONFIG_ITEM_PK.gVolStatus,1);
5333 END IF;
5334
5335 if CTO_CONFIG_ITEM_PK.gWtStatus = 0 or -- 0 means success
5336 CTO_CONFIG_ITEM_PK.gVolStatus = 0
5337 then
5338
5339 -- begin bugfix 1811007
5340
5341 DECLARE
5342
5343 o_weight_uom MTL_SYSTEM_ITEMS.weight_uom_code%TYPE;
5344 o_volume_uom MTL_SYSTEM_ITEMS.weight_uom_code%TYPE;
5345 o_weight number := 0;
5346 o_volume number := 0;
5347 x_status number := 0;
5348 lShippingOrg number ;
5349
5350 BEGIN
5351
5352 lStmtNumber := 90.1;
5353
5354 -- Get the weight and volume UOM of the model from the OE:Validation org.
5355
5356 select i.weight_uom_code, i.volume_uom_code
5357 into o_weight_uom, o_volume_uom
5358 from mtl_system_items i,
5359 bom_cto_order_lines l
5360 where l.line_id = pLineId -- model line id
5361 and l.inventory_item_id = i.inventory_item_id
5362 and i.organization_id = lValidationOrg;
5363
5364
5365
5366 -- If weight UOM is not defined for the base model, then we will get the
5367 -- base UOM of the uom class of the components.
5368 -- Assumption is that weight of all the options belong to the same class.
5369 -- Eg. C_OPTION 7 (kg) and C_OPTION 9 (Lbs).
5370
5371 IF o_weight_uom IS NULL THEN
5372 IF PG_DEBUG <> 0 THEN
5373 oe_debug_pub.add('Create_Item: ' || '=>Weight UOM is null for the base model.',2);
5374
5375 oe_debug_pub.add('Create_Item: ' || '=>Trying to get the base UOM ...',2);
5376 END IF;
5377
5378 begin
5379 select uom_code
5380 into o_weight_uom
5381 from mtl_units_of_measure
5382 where uom_class = (select uom1.uom_class
5383 from mtl_units_of_measure uom1,
5384 mtl_system_items i,
5385 bom_cto_order_lines l
5386 where l.parent_ato_line_id = pLineId
5387 -- mbsk: replaced ato_line_id with parent_ato_line_id
5388 and l.item_type_code not in ('INCLUDED', 'CONFIG')
5389 and l.inventory_item_id = i.inventory_item_id
5390 and i.organization_id = lValidationOrg
5391 and i.weight_uom_code is not null
5392 and i.weight_uom_code = uom1.uom_code
5393 and rownum = 1 )
5394 and base_uom_flag = 'Y';
5395 exception
5396 when no_data_found then
5397 null;
5398 end;
5399 END IF;
5400
5401 -- If volume UOM is not defined for the base model, then we will get the
5402 -- base UOM for the uom class of the components.
5403 -- Assumption is that volume of all the options belong to the same class.
5404 -- Eg. C_OPTION 7 (cubic meter) and C_OPTION 9 (cubic feet).
5405
5406 IF o_volume_uom IS NULL THEN
5407 IF PG_DEBUG <> 0 THEN
5408 oe_debug_pub.add('Create_Item: ' || '=>Volume UOM is null for the base model.',2);
5409
5410 oe_debug_pub.add('Create_Item: ' || '=>Trying to get the base UOM ...',2);
5411 END IF;
5412
5413 begin
5414 select uom_code
5415 into o_volume_uom
5416 from mtl_units_of_measure
5417 where uom_class = (select uom1.uom_class
5418 from mtl_units_of_measure uom1,
5419 mtl_system_items i,
5420 bom_cto_order_lines l
5421 where l.parent_ato_line_id = pLineId
5422 -- mbsk: replaced ato_line_id with parent_ato_line_id
5423 and l.item_type_code not in ('INCLUDED', 'CONFIG')
5424 and l.inventory_item_id = i.inventory_item_id
5425 and i.organization_id = lValidationOrg
5426 and i.volume_uom_code is not null
5427 and i.volume_uom_code = uom1.uom_code
5428 and rownum = 1 )
5429 and base_uom_flag = 'Y';
5430 exception
5431 when no_data_found then
5432 null;
5433 end;
5434 END IF;
5435
5436
5437
5438 -- We need to call Ato_Weight_Volume API only once because Weight/Vol will be
5439 -- calculated on the basis of Shipping Orgn. It will be same for all other organizations.
5440 -- We will update the wt/vol for other orgs after the IF clause.
5441
5442 -- If the lower level config's wt or vol was not calculated, then, we should not calculate
5443 -- the wt or vol for the top level config.
5444
5445
5446 IF PG_DEBUG <> 0 THEN
5447 oe_debug_pub.add('Create_Item: ' || 'Calling Ato_Weight_Volume API with following parameters..',2);
5448
5449 oe_debug_pub.add('Create_Item: ' || '=>Line Id : '||pLineId,2);
5450
5451 oe_debug_pub.add('Create_Item: ' || '=>OE Validn Orgn Id : '||lValidationOrg,2);
5452
5453 oe_debug_pub.add('Create_Item: ' || '=>Weight UOM: '||o_weight_uom,2);
5454
5455 oe_debug_pub.add('Create_Item: ' || '=>Volume UOM: '||o_volume_uom,2);
5456 END IF;
5457
5458 Ato_Weight_Volume(
5459 p_ato_line_id => pLineId,
5460 p_orgn_id => lValidationOrg,
5461 weight_uom => o_weight_uom,
5462 weight => o_weight,
5463 volume_uom => o_volume_uom,
5464 volume => o_volume,
5465 status => x_status,
5466 pConfigId => pConfigId);--3737772 (FP 3473737)
5467
5468 if x_status <> 0 then
5469 raise FND_API.G_EXC_ERROR;
5470 end if;
5471
5472 IF PG_DEBUG <> 0 THEN
5473 oe_debug_pub.add('Create_Item: ' || 'Successfully executed Ato_Weight_Volume API with following outputs..',2);
5474
5475 oe_debug_pub.add('Create_Item: ' || '=>Weight : '||o_weight||' '||o_weight_uom,2);
5476
5477 oe_debug_pub.add('Create_Item: ' || '=>Volume : '||o_volume||' '||o_volume_uom,2);
5478 END IF;
5479
5480
5481 -- Update the config's weight and volume.
5482
5483 -- begin bugfix 2905835: Before updating the weight in other organizations, we will convert
5484 -- the weight of the config in the model's weight UOM in that organization.
5485
5486 lStmtNumber := 95;
5487
5488 -- bugfix 4143695: Update MSI only if the weight UOM is not null.
5489 -- Added IF clause
5490 -- bugfix 5623437:
5491 -- Added "and a.unit_weight is null" condition so that weight/vol is updated
5492 -- only if it is not already calculated.
5493
5494 if (o_weight_uom is not null) then
5495 update mtl_system_items a
5496 set (unit_weight, weight_uom_code) =
5497 (select CTO_UTILITY_PK.convert_uom(
5498 o_weight_uom,
5499 nvl( b.weight_uom_code, o_weight_uom) , -- bug# 3358194
5500 o_weight,
5501 b.inventory_item_id)
5502 ,nvl(b.weight_uom_code, o_weight_uom) -- bug# 3358194
5503 from mtl_system_items b
5504 where b.inventory_item_id = a.base_item_id
5505 and b.organization_id = a.organization_id)
5506 where a.inventory_item_id = pConfigId
5507 and a.unit_weight is null; -- bugfix 5623437
5508 end if;
5509
5510 if (o_volume_uom is not null) then -- begin bugfix 4143695
5511 update mtl_system_items a
5512 set (unit_volume, volume_uom_code) =
5513 (select CTO_UTILITY_PK.convert_uom(
5514 o_volume_uom,
5515 nvl(b.volume_uom_code, o_volume_uom), -- bug# 3358194
5516 o_volume,
5517 b.inventory_item_id)
5518 ,nvl(b.volume_uom_code, o_volume_uom) -- bug# 3358194
5519 from mtl_system_items b
5520 where b.inventory_item_id = a.base_item_id
5521 and b.organization_id = a.organization_id)
5522 where a.inventory_item_id = pConfigId
5523 and a.unit_volume is null; -- bugfix 5623437;
5524 end if;
5525
5526
5527 -- end bugfix 2905835
5528
5529 END;
5530 end if; /* end check CTO_CONFIG_ITEM_PK.gWtStatus */
5531
5532 -- end bugfix 1811007
5533
5534
5535 oe_debug_pub.add('Create_Item: ' || 'going to insert:mtl_system_items_tl',2);
5536
5537 /*----------------------------------------+
5538 R11.5 MLS
5539 +----------------------------------------*/
5540
5541 lStmtNumber := 90;
5542
5543 insert into mtl_system_items_tl (
5544 inventory_item_id,
5545 organization_id,
5546 language,
5547 source_lang,
5548 description,
5549 last_update_date,
5550 last_updated_by,
5551 creation_date,
5552 created_by,
5553 last_update_login
5554 )
5555 select distinct
5556 pConfigId,
5557 m.organization_id,
5558 l.language_code,
5559 userenv('LANG'),
5560 m.description,
5561 sysdate,
5562 gUserId, --last_updated_by
5563 sysdate,
5564 gUserId, --created_by
5565 gLoginId --last_update_login
5566 /*
5567 commented for reintroduction of bcso
5568 from
5569 mtl_system_items_tl m, -- 2457514
5570 fnd_languages l
5571 where m.inventory_item_id = pModelId
5572 and l.installed_flag In ('I', 'B')
5573 and l.language_code = m.language -- 2457514
5574 and NOT EXISTS
5575 (select NULL
5576 from mtl_system_items_tl t
5577 where t.inventory_item_id = pConfigId
5578 and t.organization_id = m.organization_id
5579 and t.language = m.language );
5580 */
5581 from
5582 -- bugfix 2457514 mtl_system_items_b m, -- Model
5583 mtl_system_items_tl m, -- 2457514
5584 bom_cto_src_orgs bcso,
5585 fnd_languages l
5586 where m.inventory_item_id = pModelId
5587 and bcso.model_item_id = pModelId
5588 and bcso.line_id = pLineId
5589 and m.organization_id = bcso.organization_id
5590 and l.installed_flag In ('I', 'B')
5591 and l.language_code = m.language -- 2457514
5592 and NOT EXISTS
5593 (select NULL
5594 from mtl_system_items_tl t
5595 where t.inventory_item_id = pConfigId
5596 and t.organization_id = m.organization_id
5597 and t.language = l.language_code );
5598
5599
5600 IF PG_DEBUG <> 0 THEN
5601 oe_debug_pub.add('Create_Item: ' || 'after insert:mtl_system_items_tl',2);
5602 END IF;
5603
5604
5605
5606
5607
5608 /*
5609 **
5610 ** This section has been moved to CTO_ITEM_PK
5611 **
5612
5613
5614
5615 --
5616 -- create sourcing rules if necessary
5617 --
5618
5619 lStmtNumber := 100;
5620
5621 FOR v_src_rule IN c_copy_src_rules LOOP
5622 --
5623 -- call API to copy sourcing rules from model item
5624 -- to config item
5625 --
5626 IF PG_DEBUG <> 0 THEN
5627 oe_debug_pub.add ('Create_Item: ' || 'Copying src rule for cfg item '||to_char(pConfigId)||' in org '||to_char(v_src_rule.rcv_org_id), 2);
5628 END IF;
5629 CTO_UTILITY_PK.Create_Sourcing_Rules(
5630 pModelItemId => pModelId,
5631 pConfigId => pConfigId,
5632 pRcvOrgId => v_src_rule.rcv_org_id,
5633 x_return_status => lReturnStatus,
5634 x_msg_count => xMsgCount,
5635 x_msg_data => xMsgData);
5636
5637 IF (lReturnStatus = fnd_api.G_RET_STS_ERROR) THEN
5638 IF PG_DEBUG <> 0 THEN
5639 oe_debug_pub.add ('Create_Item: ' || 'Create_Sourcing_Rules returned with expected error.');
5640 END IF;
5641 raise FND_API.G_EXC_ERROR;
5642
5643 ELSIF (lReturnStatus = fnd_api.G_RET_STS_UNEXP_ERROR) THEN
5644 IF PG_DEBUG <> 0 THEN
5645 oe_debug_pub.add ('Create_Item: ' || 'Create_Sourcing_Rules returned with unexp error.');
5646 END IF;
5647 raise FND_API.G_EXC_UNEXPECTED_ERROR;
5648
5649 END IF;
5650
5651 END LOOP;
5652
5653
5654 --
5655 -- update bom_cto_order_lines with new config item
5656 --
5657
5658 lStmtNumber := 120;
5659 lStatus := CTO_UTILITY_PK.Update_Order_Lines(
5660 pLineId => pLineId,
5661 pModelId => pModelId,
5662 pConfigId => pConfigId);
5663
5664 IF lStatus <> 1 THEN
5665 IF PG_DEBUG <> 0 THEN
5666 oe_debug_pub.add ('Create_Item: ' || 'Failed in Update_Order_Lines function',1);
5667 END IF;
5668 raise FND_API.G_EXC_ERROR;
5669 END IF;
5670
5671
5672
5673 --
5674 -- update bom_cto_src_orgs with new config item
5675 --
5676
5677 lStmtNumber := 130;
5678 lStatus := CTO_UTILITY_PK.Update_Src_Orgs(
5679 pLineId => pLineId,
5680 pModelId => pModelId,
5681 pConfigId => pConfigId);
5682
5683 IF lStatus <> 1 THEN
5684 IF PG_DEBUG <> 0 THEN
5685 oe_debug_pub.add ('Create_Item: ' || 'Failed in Update_Src_Orgs function',1);
5686 END IF;
5687 raise FND_API.G_EXC_ERROR;
5688 END IF;
5689
5690
5691
5692
5693
5694 */
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704 --
5705 -- create item data in related tables
5706 --
5707
5708 lStmtNumber := 140;
5709 lStatus := create_item_data(
5710 pModelId,
5711 pConfigId,
5712 pLineId,
5713 p_mode );
5714
5715 if lStatus <> 1 then
5716 IF PG_DEBUG <> 0 THEN
5717 oe_debug_pub.add ('Create_Item: ' || 'Failed in create_data function',1);
5718 END IF;
5719 raise FND_API.G_EXC_ERROR;
5720 end if;
5721
5722 IF PG_DEBUG <> 0 THEN
5723 oe_debug_pub.add ('Create_Item: ' || 'Success in create_data function',1);
5724 END IF;
5725
5726 return(1);
5727
5728 EXCEPTION
5729
5730 WHEN NO_DATA_FOUND THEN
5731 IF PG_DEBUG <> 0 THEN
5732 oe_debug_pub.add ('Create_Item: ' || 'ERROR: create_item::ndf::'||to_char(lStmtNumber)||sqlerrm,1);
5733 END IF;
5734 CTO_MSG_PUB.Count_And_Get(
5735 p_msg_count => xMsgCount,
5736 p_msg_data => xMsgData
5737 );
5738 return(0);
5739
5740 WHEN FND_API.G_EXC_ERROR THEN
5741 IF PG_DEBUG <> 0 THEN
5742 oe_debug_pub.add ('Create_Item: ' || 'ERROR: create_item::exp error::'||to_char(lStmtNumber)||sqlerrm,1);
5743 END IF;
5744 CTO_MSG_PUB.Count_And_Get(
5745 p_msg_count => xMsgCount,
5746 p_msg_data => xMsgData
5747 );
5748 return(0);
5749
5750 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5751 IF PG_DEBUG <> 0 THEN
5752 oe_debug_pub.add ('Create_Item: ' || 'ERROR: create_item::unexp error::'||to_char(lStmtNumber)||sqlerrm,1);
5753 END IF;
5754 CTO_MSG_PUB.Count_And_Get(
5755 p_msg_count => xMsgCount,
5756 p_msg_data => xMsgData
5757 );
5758 return(0);
5759
5760 WHEN OTHERS THEN
5761 IF PG_DEBUG <> 0 THEN
5762 oe_debug_pub.add ('Create_Item: ' || 'ERROR: create_item::others::'||to_char(lStmtNumber)||sqlerrm,1);
5763 END IF;
5764 CTO_MSG_PUB.Count_And_Get(
5765 p_msg_count => xMsgCount,
5766 p_msg_data => xMsgData
5767 );
5768 return(0);
5769
5770 END Create_Item;
5771
5772 --begin bugfix 1811007
5773
5774 PROCEDURE Ato_Weight_Volume(
5775 p_ato_line_id IN NUMBER,
5776 p_orgn_id IN NUMBER,
5777 weight_uom IN OUT NOCOPY VARCHAR2, /* NOCOPY Project */
5778 weight OUT NOCOPY NUMBER,
5779 volume_uom IN OUT NOCOPY VARCHAR2, /* NOCOPY Project */
5780 volume OUT NOCOPY NUMBER,
5781 status IN OUT NOCOPY NUMBER, /* NOCOPY Project */
5782 pConfigId IN NUMBER)--3737772 (FP 3473737)
5783 is
5784
5785 -- The two cursors ato_weight and ato_volume have the
5786 -- same WHERE clause. The only difference is weight vs. volume.
5787 -- CTO_UTILITY_PK.convert_uom is a wrapper for INV_CONVERT.inv_um_convert to translate
5788 -- -9999 (error value) into 0 (no weight/volume).
5789
5790
5791 -- We need to figure out qty-per and then weight of each component in the shipping org,
5792 -- and that's why l.ordered_quantity/l_model.ordered_quantity which gives us qty-per.
5793 -- Weight and Volume calculation is calculated on the basis of Shipping Org.
5794
5795 -- This API is called for each ATO model in a multi-level ATO configuration starting from the bottom most.
5796 -- The line-Id passed is the line id of each ATO model.
5797 -- The weight of the each independent ATO configuration is calculated starting from bottom to determine the
5798 -- weight of that configuration. This then is added to the next higher level ATO to calculate the weight
5799 -- of the next higher configuration and so on until the weight of the top model ATO is calculated.
5800
5801 -- bugfix 2301167: added inventory_item_id in the select list as well as in group by clause.
5802 -- This will make sure that item specific conversions take precedence over standard conversions.
5803 -- Also, for inter-class conversions, item-id is required.
5804 -- Also added "weight_uom_code is not null" and "unit_weight is not null" condition to filter out
5805 -- items for which these have not been defined.
5806
5807
5808 CURSOR ato_weight(x_a_line_id NUMBER) IS
5809 SELECT SUM( NVL(msi.unit_weight, 0) *
5810 CTO_UTILITY_PK.convert_uom(l.order_quantity_uom,
5811 msi.primary_uom_code,
5812 Round( ( l.ordered_quantity / l_model.ordered_quantity), 7) , /* Support Decimal-Qty for Option Items */
5813 l.inventory_item_id) ) weight,
5814 msi.weight_uom_code uom,
5815 msi.inventory_item_id
5816 FROM bom_cto_order_lines l,
5817 bom_cto_order_lines l_model,
5818 mtl_system_items msi
5819 WHERE (l.parent_ato_line_id = x_a_line_id
5820 -- MLMO:replaced ato_line_id with parent_ato_line_id and added OR condn
5821 or
5822 l.line_id = x_a_line_id)
5823 -- Bugfix 2576422
5824 -- joining l_model.line_id to l.parent_ato_line_id so that
5825 -- qty per will be calculated correctly for multi-level configuration
5826 -- AND l_model.line_id = l.top_model_line_id
5827 -- MLMO:replaced x_a_line_id with l.top_model_line_id
5828 AND l_model.line_id = l.parent_ato_line_id
5829 -- End bugfix 2576422
5830 AND l.item_type_code not in ('INCLUDED', 'CONFIG')
5831 AND msi.inventory_item_id = decode(l.config_item_id, null,l.inventory_item_id,
5832 --3737772 (FP 3473737)
5833 pConfigId,l.inventory_item_id, l.config_item_id )
5834 -- MLMO: added decode/config_item_id condn
5835 AND msi.organization_id = p_orgn_id
5836 AND msi.weight_uom_code is not null
5837 AND nvl(msi.unit_weight, 0) <> 0 -- bugfix 2905835: changed "is not null" to <> 0
5838 GROUP BY msi.inventory_item_id,
5839 msi.weight_uom_code;
5840
5841
5842
5843 CURSOR ato_volume(x_a_line_id NUMBER) IS
5844 SELECT SUM( NVL(msi.unit_volume, 0) *
5845 CTO_UTILITY_PK.convert_uom(l.order_quantity_uom,
5846 msi.primary_uom_code,
5847 Round( ( l.ordered_quantity / l_model.ordered_quantity) , 7) , /* Support Decimal-Qty for Option Items */
5848 l.inventory_item_id) ) volume,
5849 msi.volume_uom_code uom,
5850 msi.inventory_item_id
5851 FROM bom_cto_order_lines l,
5852 bom_cto_order_lines l_model,
5853 mtl_system_items msi
5854 WHERE (l.parent_ato_line_id = x_a_line_id -- MLMO: replaced ato_line_id with parent_ato_line_id
5855 or
5856 l.line_id = x_a_line_id)
5857 -- Bugfix 2576422
5858 -- joining l_model.line_id to l.parent_ato_line_id so that
5859 -- qty per will be calculated correctly for multi-level configuration
5860 -- AND l_model.line_id = l.top_model_line_id
5861 -- MLMO:replaced x_a_line_id with l.top_model_line_id
5862 AND l_model.line_id = l.parent_ato_line_id
5863 -- End bugfix 2576422
5864 AND l.item_type_code not in ('INCLUDED', 'CONFIG')
5865 AND msi.inventory_item_id = decode(l.config_item_id, null, l.inventory_item_id,
5866 --3737772 (FP 3473737)
5867 pConfigId,l.inventory_item_id,l.config_item_id )
5868 -- MLMO: added decode/config_item_id condn
5869 AND msi.organization_id = p_orgn_id
5870 AND msi.volume_uom_code is not null
5871 AND nvl(msi.unit_volume,0) <> 0 -- bugfix 2905835 : changed "is not null" to <> 0
5872 GROUP BY msi.inventory_item_id,
5873 msi.volume_uom_code;
5874
5875 lStmtNumber number := 0;
5876 lMsgCount number;
5877 lMsgData varchar2(2000);
5878 lweight number := 0;
5879 lvolume number := 0;
5880
5881
5882 BEGIN
5883
5884 weight := 0;
5885 volume := 0;
5886 status := 0;
5887
5888
5889 IF PG_DEBUG <> 0 THEN
5890 oe_debug_pub.add ('Create_Item: ' || 'Inside Ato_Weight_Volume API with p_ato_line_id = '||p_ato_line_id,1);
5891 oe_debug_pub.add ('Create_Item: ' || 'Inside Ato_Weight_Volume API with pConfigId = '||pConfigId,1);
5892
5893 END IF;
5894
5895 lStmtNumber := 1205;
5896
5897 -- bugfix 2301167: Calculate the config's wt if the previous calculation of lower level config was
5898 -- successful. gWtStatus would be set to -1 if calculation was not successful.
5899
5900 if CTO_CONFIG_ITEM_PK.gWtStatus = 0 then
5901
5902 IF PG_DEBUG <> 0 THEN
5903 oe_debug_pub.add ('Create_Item: ' || '===>weight_uom = '||weight_uom,1);
5904 END IF;
5905
5906 FOR aw IN ato_weight(p_ato_line_id)
5907 loop
5908
5909 IF PG_DEBUG <> 0 THEN
5910 oe_debug_pub.add ('Create_Item: ' || '===>aw.weight = '||aw.weight||' uom = '||aw.uom||' for item_id '||aw.inventory_item_id,1);
5911 END IF;
5912 -- Bugfix 2301167: Added item_id as a parameter so that item specific conversions take precedence if defined.
5913 lweight := CTO_UTILITY_PK.convert_uom(
5914 from_uom => aw.uom,
5915 to_uom => weight_uom,
5916 quantity => aw.weight,
5917 item_id => aw.inventory_item_id);
5918 if lweight = 0 then
5919 IF PG_DEBUG <> 0 THEN
5920 oe_debug_pub.add ('Create_Item: ' || '===>convert_uom returned 0(error). Not calculating weight. Check if all conversions have been defined.', 1);
5921 END IF;
5922 -- we don't want to update the weight of the config incorrectly, so set it to 0.
5923 weight := 0;
5924
5925 -- Also, we shouldn't calculate the wt for the top config since the lower level's config
5926 -- weight has been updated to 0
5927 CTO_CONFIG_ITEM_PK.gWtStatus := -1; -- -1 means error
5928 exit;
5929 end if;
5930 weight := weight + lweight;
5931
5932 end loop;
5933 end if;
5934
5935
5936 IF PG_DEBUG <> 0 THEN
5937 oe_debug_pub.add ('Create_Item: ' || '---------------------',1);
5938 END IF;
5939
5940 lStmtNumber := 1210;
5941
5942 -- bugfix 2301167: Calculate the config's wt if the previous calculation of lower level config was
5943 -- successful. gWtStatus would be set to -1 if calculation was not successful.
5944
5945 if CTO_CONFIG_ITEM_PK.gVolStatus = 0 then
5946
5947 IF PG_DEBUG <> 0 THEN
5948 oe_debug_pub.add ('Create_Item: ' || '===>volume_uom = '||volume_uom,1);
5949 END IF;
5950
5951 FOR av IN ato_volume(p_ato_line_id)
5952 loop
5953 IF PG_DEBUG <> 0 THEN
5954 oe_debug_pub.add ('Create_Item: ' || '===>av.volume = '||av.volume||' uom = '||av.uom||' for item_id '||av.inventory_item_id,1);
5955 END IF;
5956 -- Bugfix 2301167: Added item_id as a parameter so that item specific conversions take precedence if defined.
5957 lvolume := CTO_UTILITY_PK.convert_uom(
5958 from_uom => av.uom,
5959 to_uom => volume_uom,
5960 quantity => av.volume,
5961 item_id => av.inventory_item_id);
5962 if lvolume = 0 then
5963 IF PG_DEBUG <> 0 THEN
5964 oe_debug_pub.add ('Create_Item: ' || '===>convert_uom returned 0(error). Not calculating volume. Check if all conversions have been defined.', 1);
5965 END IF;
5966 -- we don't want to update the volume of the config incorrectly, so set it to 0.
5967 volume := 0;
5968
5969 -- Also, we shouldn't calculate the vol for the top config since the lower level's config
5970 -- volume has been updated to 0
5971 CTO_CONFIG_ITEM_PK.gVolStatus := -1; -- -1 means error
5972 exit;
5973 end if;
5974 volume := volume + lvolume;
5975
5976 end loop;
5977 end if;
5978
5979 EXCEPTION
5980 WHEN OTHERS THEN
5981 IF PG_DEBUG <> 0 THEN
5982 oe_debug_pub.add ('Create_Item: ' || 'ERROR: Ato_Weight_Volume::others::'||to_char(lStmtNumber)||':-'||sqlerrm,1);
5983 END IF;
5984 CTO_MSG_PUB.Count_And_Get(
5985 p_msg_count => lMsgCount,
5986 p_msg_data => lMsgData
5987 );
5988 status := -1;
5989
5990 End Ato_Weight_Volume;
5991
5992 --end bugfix 1811007
5993
5994
5995
5996 FUNCTION Create_Item_Data(
5997 pModelId in number,
5998 pConfigId in number,
5999 pLineId in number,
6000 p_mode in varchar2 default 'AUTOCONFIG' )
6001 return integer
6002 is
6003
6004 lValidationOrg number;
6005 lShipFromOrg number;
6006 lStmtNumber number;
6007 l_cost_group_id number;
6008 lProfileVal number;
6009 lOpUnit number;
6010 l_layer_id number;
6011 lMsgCount number;
6012 lMsgData varchar2(2000);
6013 x_err_num number;
6014 x_msg_name varchar2(240);
6015 xReturnStatus VARCHAR2(1); --Bugfix 6063990
6016
6017 -- x_item_rev_seq number; bugfix 3026929
6018
6019 multiorg_error exception;
6020 v_program_id bom_cto_order_lines.program_id%type ;
6021
6022 l_cto_cost_type_id number;
6023
6024 lCnt number; --Bugfix 6717614
6025
6026 CURSOR c_layer IS
6027 select distinct
6028 MP1.organization_id org_id,
6029 DECODE(MP1.ORGANIZATION_ID, lShipFromOrg ,l_cost_group_id,1) cost_group_id
6030 /*
6031 commented due to reintroduction of bcso
6032 from mtl_parameters mp1,
6033 cst_item_costs c,
6034 mtl_system_items msi
6035 where c.organization_id = mp1.organization_id
6036 and c.inventory_item_id = pModelId
6037 and C.COST_TYPE_ID = 2 -- Average Costing
6038 and msi.organization_id = mp1.organization_id
6039 and MP1.Primary_cost_method = 2 -- Create only in Avg costing org
6040 and NOT EXISTS
6041 (select NULL
6042 from cst_quantity_layers
6043 where inventory_item_id = pConfigId
6044 and organization_id = mp1.organization_id);
6045 */
6046 from mtl_parameters mp1,
6047 mtl_parameters mp2,
6048 cst_item_costs c,
6049 bom_cto_src_orgs bcso
6050 where c.organization_id = mp1.organization_id
6051 and c.inventory_item_id = pModelId
6052 and C.COST_TYPE_ID = 2 -- Average Costing
6053 and bcso.model_item_id = pModelId
6054 and bcso.line_id = pLineId
6055 and MP2.organization_id = bcso.organization_id
6056 and ((mp1.organization_id = bcso.organization_id) OR
6057 (mp1.organization_id = mp2.master_organization_id))
6058 and MP1.Primary_cost_method = 2 -- Create only in Avg costing org
6059 and NOT EXISTS
6060 (select NULL
6061 from cst_quantity_layers
6062 where inventory_item_id = pConfigId
6063 and organization_id = mp1.organization_id);
6064
6065
6066 v_material_cost cst_item_costs.material_cost%type := 0 ;
6067 v_material_overhead_cost cst_item_costs.material_overhead_cost%type := 0 ;
6068 v_resource_cost cst_item_costs.resource_cost%type := 0 ;
6069 v_outside_processing_cost cst_item_costs.outside_processing_cost%type := 0 ;
6070 v_overhead_cost cst_item_costs.overhead_cost%type := 0 ;
6071
6072
6073 v_item_cost cst_item_costs.item_cost%type := 0 ;
6074 v_cto_cost_type_name cst_cost_types.cost_type%type;
6075 v_item_cost_frozen cst_item_costs.item_cost%type; --Bugfix 6363308
6076 l_cost_update number; --Bugfix 6363308
6077
6078 --Bugfix 6363308
6079 CURSOR get_orgs_with_frozen_cost ( p_config_item_id NUMBER)
6080 IS
6081 SELECT organization_id
6082 , item_cost
6083 FROM cst_item_costs
6084 WHERE inventory_item_id = p_config_item_id
6085 AND cost_type_id = 1;
6086
6087 v_organization_id NUMBER;
6088 --Bugfix 6363308
6089
6090
6091 Type number_tbl_type IS TABLE OF number INDEX BY BINARY_INTEGER;
6092
6093
6094 TYPE cicd_summary_rec_tab is record (
6095 cost_organization_id number_tbl_type,
6096 cost_type_id number_tbl_type,
6097 material_cost number_tbl_type,
6098 material_overhead_cost number_tbl_type,
6099 resource_cost number_tbl_type,
6100 outside_processing_cost number_tbl_type,
6101 overhead_cost number_tbl_type,
6102 item_cost number_tbl_type ) ;
6103
6104
6105
6106
6107 l_rt_cicd_summary cicd_summary_rec_tab ;
6108
6109 --kkonada R12
6110 --for mtl_cross_references_b
6111 --bug# 4539578
6112
6113 TYPE org_id IS TABLE OF mtl_cross_references_b.organization_id%type;
6114 TYPE cross_reference_type IS TABLE OF mtl_cross_references_b.cross_reference_type%type;
6115 TYPE cross_reference IS TABLE OF mtl_cross_references_b.cross_reference%type;
6116 TYPE org_independent_flag IS TABLE OF mtl_cross_references_b.org_independent_flag%type;
6117
6118
6119 t_organization_id org_id;
6120 t_cross_ref_type cross_reference_type;
6121 t_cross_ref cross_reference;
6122 t_org_independent_flag org_independent_flag;
6123
6124
6125 BEGIN
6126
6127
6128 /* added by Sushant to check preconfigure bom populated records */
6129 select nvl( program_id , 0 ) into v_program_id
6130 from bom_cto_order_lines
6131 where line_id = pLineId ;
6132
6133
6134 lStmtNumber := 200;
6135
6136 if ( v_program_id = CTO_UTILITY_PK.PC_BOM_PROGRAM_ID ) then
6137
6138 lValidationOrg := CTO_UTILITY_PK.PC_BOM_VALIDATION_ORG ;
6139
6140 else
6141
6142 /*
6143 BUG:3484511
6144 -------------
6145
6146 select nvl(master_organization_id, -99) --bugfix 2646849: added nvl.
6147 into lValidationOrg
6148 from oe_order_lines_all oel,
6149 oe_system_parameters_all ospa
6150 where oel.line_id = pLineid
6151 and nvl(oel.org_id, -1) = nvl(ospa.org_id, -1) --bug 1531691
6152 and oel.inventory_item_id = pModelId;
6153 */
6154
6155
6156 IF PG_DEBUG <> 0 THEN
6157 oe_debug_pub.add('Create_Item: ' || 'Going to fetch Validation Org ' ,2);
6158 END IF;
6159
6160
6161 select nvl( oe_sys_parameters.value( 'MASTER_ORGANIZATION_ID' , oel.org_id) , -99)
6162 into lValidationOrg from oe_order_lines_all oel
6163 where oel.line_id = pLineId ;
6164
6165
6166 end if ;
6167
6168
6169 IF PG_DEBUG <> 0 THEN
6170 oe_debug_pub.add('Create_Item: ' || 'After getting validation org',2);
6171 END IF;
6172
6173 if lVAlidationOrg = -99 then -- bugfix 2646849
6174 cto_msg_pub.cto_message('BOM','CTO_VALIDATION_ORG_NOT_SET');
6175 RAISE FND_API.G_EXC_ERROR;
6176 end if;
6177
6178
6179 /*------------------------------------------+
6180 Create rows for config items
6181 in the MTL_PENDING_ITEM_STATUS
6182 +------------------------------------------*/
6183
6184 lStmtNumber := 205;
6185
6186 IF PG_DEBUG <> 0 THEN
6187 oe_debug_pub.add ('Create_Item: ' || 'Validation Org is :' || lValidationOrg ,2);
6188 END IF;
6189
6190 insert into MTL_PENDING_ITEM_STATUS (
6191 inventory_item_id,
6192 organization_id,
6193 status_code,
6194 effective_date,
6195 pending_flag,
6196 last_update_date,
6197 last_updated_by,
6198 creation_date,
6199 created_by,
6200 last_update_login,
6201 program_application_id,
6202 program_id,
6203 program_update_date,
6204 request_id)
6205 select distinct
6206 pConfigId,
6207 m.organization_id,
6208 m.inventory_item_status_code,
6209 sysdate,
6210 'N',
6211 sysdate,
6212 gUserId,
6213 sysdate,
6214 gUserId,
6215 gLoginId,
6216 null,
6217 null,
6218 sysdate,
6219 null -- req_id
6220 from mtl_system_items m,
6221 bom_cto_src_orgs bcso
6222 where m.inventory_item_id = pModelId
6223 and bcso.model_item_id = pModelId
6224 and bcso.line_id = pLineId
6225 and m.organization_id = bcso.organization_id
6226 and NOT EXISTS
6227 (select NULL
6228 from MTL_PENDING_ITEM_STATUS
6229 where inventory_item_id = pConfigId
6230 and organization_id = m.organization_id);
6231
6232
6233
6234 IF PG_DEBUG <> 0 THEN
6235 oe_debug_pub.add('Create_Item: ' || 'after insert:MTL_PENDING_ITEM_STATUS',2);
6236 END IF;
6237
6238 /*-------------------------------------------+
6239 Insert Item revision information
6240 +-------------------------------------------*/
6241
6242 lStmtNumber := 210;
6243
6244 /* Begin Bugfix 6063990: Commenting out this part as this will no longer be used.
6245 We will call populate_item_revision procedure directly
6246
6247 --
6248 -- bugfix 3026929 : To avoid dependencies with INV/BOM, we made this code change.
6249 -- We will first try to insert into MIR. If this fails, we will insert into MIR_b and _tl using dynamic stmt.
6250 -- We need to use dynamic stmt to avoid compilation errors in pre-I instances.
6251 -- We did not use ALL_OBJECTS since this *may* not accessible from APPS schema.
6252 -- This change supersedes bugfix 2730055
6253 --
6254
6255 DECLARE
6256 non_key_preserved_error EXCEPTION;
6257 PRAGMA exception_init (non_key_preserved_error, -1779);
6258 xReturnStatus VARCHAR2(1);
6259 BEGIN
6260
6261 insert into mtl_item_revisions
6262 (inventory_item_id,
6263 organization_id,
6264 revision,
6265 last_update_date,
6266 last_updated_by,
6267 creation_date,
6268 created_by,
6269 last_update_login,
6270 implementation_date,
6271 effectivity_date
6272 )
6273 select distinct
6274 pConfigId,
6275 m.organization_id,
6276 mp1.starting_revision,
6277 sysdate,
6278 gUserId, -- last_updated_by
6279 sysdate,
6280 gUserId, -- created_by
6281 gLoginId, -- last_update_login
6282 sysdate,
6283 sysdate
6284 from
6285 mtl_system_items m,
6286 bom_cto_src_orgs bcso,
6287 mtl_parameters mp1
6288 where m.inventory_item_id = pModelId
6289 and bcso.model_item_id = pModelId
6290 and bcso.line_id = pLineId
6291 and m.organization_id = bcso.organization_id
6292 and mp1.organization_id = bcso.organization_id
6293 and NOT EXISTS
6294 (select NULL
6295 from MTL_ITEM_REVISIONS
6296 where inventory_item_id = pConfigId
6297 and organization_id = m.organization_id);
6298
6299
6300
6301 IF PG_DEBUG <> 0 THEN
6302 oe_debug_pub.add('Create_Item_Data: ' || 'after insert:MTL_ITEM_REVISIONS',2);
6303 END IF;
6304
6305 EXCEPTION
6306 when NON_KEY_PRESERVED_ERROR then
6307
6308 IF PG_DEBUG <> 0 THEN
6309 oe_debug_pub.add('Create_item_data: NON_KEY_PRESERVED_ERROR exception. Hence, calling populate_item_revision.. ',2);
6310 oe_debug_pub.add('Create_item_data: NON_KEY_PRESERVED_ERROR exception. model Model ' || pModelId ,2);
6311 oe_debug_pub.add('Create_item_data: NON_KEY_PRESERVED_ERROR exception. model Line ' || pLineId ,2);
6312 oe_debug_pub.add('Create_item_data: NON_KEY_PRESERVED_ERROR exception. model Config ' || pConfigId ,2);
6313 END IF;
6314
6315 populate_item_revision (pConfigId, pModelId, pLineId, xReturnStatus);
6316
6317 IF (xReturnStatus <> fnd_api.G_RET_STS_SUCCESS) THEN
6318 oe_debug_pub.add('Create_item_data : failed in populate_item_revision : '||substrb(sqlerrm,1,60),2);
6319 raise FND_API.G_EXC_UNEXPECTED_ERROR;
6320
6321 ELSE
6322 IF PG_DEBUG <> 0 THEN
6323 oe_debug_pub.add('Create_item_data: done populate_item_revision successfully.',2);
6324 END IF;
6325 END IF;
6326
6327 when OTHERS then
6328 oe_debug_pub.add('Create_item_data: Failed while inserting into MTL_ITEM_REVISIONS: '||substrb(sqlerrm,1,60),2);
6329 raise FND_API.G_EXC_UNEXPECTED_ERROR;
6330 END;*/
6331
6332 populate_item_revision (pConfigId, pModelId, pLineId, xReturnStatus); --Bugfix 6063990
6333
6334 IF (xReturnStatus <> fnd_api.G_RET_STS_SUCCESS) THEN
6335 oe_debug_pub.add('Create_item_data : failed in populate_item_revision : '||substrb(sqlerrm,1,60),2);
6336 raise FND_API.G_EXC_UNEXPECTED_ERROR;
6337
6338 ELSE
6339 IF PG_DEBUG <> 0 THEN
6340 oe_debug_pub.add('Create_item_data: done populate_item_revision successfully.',2);
6341 END IF;
6342 END IF;
6343 --End Bugfix 6063990.
6344
6345 /*----------------------------------------------------------+
6346 Insert cost records for config items
6347 The cost organization id is either the organization id
6348 or the master organization id
6349 +----------------------------------------------------------*/
6350
6351
6352 lStmtNumber := 213;
6353
6354 /* FIX to avoid rolled up cost of model from being included during cost rollup */
6355 /* Fix for bug 4172300. cost in validation org is not copied properly from model to config item */
6356
6357 --apps perf bug# 4905845, sql id 16104498
6358 select C.organization_id,
6359 C.cost_type_id,
6360 nvl(sum(decode( cicd.cost_element_id, 1 , nvl(cicd.item_cost, 0 ) )) , 0 ),
6361 nvl( sum(decode( cicd.cost_element_id,2 , nvl( cicd.item_cost, 0 ) )) , 0 ),
6362 nvl( sum(decode( cicd.cost_element_id,3 , nvl( cicd.item_cost, 0 ) )) , 0 ),
6363 nvl( sum(decode( cicd.cost_element_id,4 , nvl( cicd.item_cost, 0 ) )) , 0 ),
6364 nvl( sum(decode( cicd.cost_element_id,5 , nvl( cicd.item_cost, 0 ) )) , 0 )
6365 BULK COLLECT INTO
6366 l_rt_cicd_summary.cost_organization_id,
6367 l_rt_cicd_summary.cost_type_id,
6368 l_rt_cicd_summary.material_cost,
6369 l_rt_cicd_summary.material_overhead_cost,
6370 l_rt_cicd_summary.resource_cost,
6371 l_rt_cicd_summary.outside_processing_cost,
6372 l_rt_cicd_summary.overhead_cost
6373 from
6374 mtl_parameters MP1,
6375 cst_item_costs C,
6376 cst_item_cost_details CICD,
6377 mtl_system_items S -- 4172300
6378 where S.organization_id = C.organization_id
6379 and S.inventory_item_id = C.inventory_item_id
6380 and C.organization_id = MP1.organization_id
6381 and C.inventory_item_id = pModelId
6382 and C.inventory_item_id = S.inventory_item_id
6383 and C.COST_TYPE_ID IN ( MP1.primary_cost_method, MP1.avg_rates_cost_type_id)
6384 and C.inventory_item_id = CICD.inventory_item_id(+)
6385 and C.organization_id = CICD.organization_id(+)
6386 and C.cost_type_id = CICD.cost_type_id(+)
6387 and CICD.rollup_source_type(+) = 1 -- User Defined
6388 --4172300
6389 and MP1.organization_id in ( select distinct MP2.cost_organization_id
6390 from mtl_parameters mp2, mtl_parameters mp3, bom_cto_src_orgs bcso
6391 where bcso.model_item_id = pModelId
6392 and bcso.line_id = pLineId
6393 and MP3.organization_id = bcso.organization_id
6394 and ((mp2.organization_id = bcso.organization_id) OR
6395 (mp2.organization_id = mp3.master_organization_id))
6396 )
6397 and NOT EXISTS
6398 (select NULL
6399 from CST_ITEM_COSTS
6400 where inventory_item_id = pConfigId
6401 and organization_id = mp1.cost_organization_id
6402 and cost_type_id in (mp1.primary_cost_method, mp1.avg_rates_cost_type_id))
6403 group by C.organization_id, C.cost_type_id; -- 4172300
6404
6405
6406 lStmtNumber := 214;
6407
6408
6409
6410 if( l_rt_cicd_summary.cost_organization_id.count > 0 ) then
6411 for i in l_rt_cicd_summary.cost_organization_id.first..l_rt_cicd_summary.cost_organization_id.last
6412 loop
6413
6414 oe_debug_pub.add( i || ') ' || 'Cost Header Info: ' ||
6415 ' cst org ' || l_rt_cicd_summary.cost_organization_id(i) ||
6416 ' cst id ' || l_rt_cicd_summary.cost_type_id(i) ||
6417 ' m cost ' || l_rt_cicd_summary.material_cost(i) ||
6418 ' moh cost ' || l_rt_cicd_summary.material_overhead_cost(i) ||
6419 ' rsc cost ' || l_rt_cicd_summary.resource_cost(i) ||
6420 ' osp cost ' || l_rt_cicd_summary.outside_processing_cost(i) ||
6421 ' ovh cost ' || l_rt_cicd_summary.overhead_cost(i) , 1 );
6422
6423
6424
6425 l_rt_cicd_summary.item_cost(i) := l_rt_cicd_summary.material_cost(i) + l_rt_cicd_summary.material_overhead_cost(i)
6426 + l_rt_cicd_summary.resource_cost(i) + l_rt_cicd_summary.outside_processing_cost(i)
6427 + l_rt_cicd_summary.overhead_cost(i) ;
6428
6429
6430
6431 oe_debug_pub.add( ' item cost ' || l_rt_cicd_summary.item_cost(i) , 1 );
6432
6433
6434 end loop ;
6435
6436
6437 else
6438
6439
6440 oe_debug_pub.add( ' no new item cost records for ' || pConfigId , 1 );
6441
6442 end if;
6443
6444 /*-------------------------------------------------------+
6445 Insert a row into the cst_item_costs_table
6446 +------------------------------------------------------- */
6447
6448 lStmtNumber := 220;
6449
6450 insert into CST_ITEM_COSTS
6451 (inventory_item_id,
6452 organization_id,
6453 cost_type_id,
6454 last_update_date,
6455 last_updated_by,
6456 creation_date,
6457 created_by,
6458 last_update_login,
6459 inventory_asset_flag,
6460 lot_size,
6461 based_on_rollup_flag,
6462 shrinkage_rate,
6463 defaulted_flag,
6464 cost_update_id,
6465 pl_material,
6466 pl_material_overhead,
6467 pl_resource,
6468 pl_outside_processing,
6469 pl_overhead,
6470 tl_material,
6471 tl_material_overhead,
6472 tl_resource,
6473 tl_outside_processing,
6474 tl_overhead,
6475 material_cost,
6476 material_overhead_cost,
6477 resource_cost,
6478 outside_processing_cost ,
6479 overhead_cost,
6480 pl_item_cost,
6481 tl_item_cost,
6482 item_cost,
6483 unburdened_cost ,
6484 burden_cost,
6485 attribute_category,
6486 attribute1,
6487 attribute2,
6488 attribute3,
6489 attribute4,
6490 attribute5,
6491 attribute6,
6492 attribute7,
6493 attribute8,
6494 attribute9,
6495 attribute10,
6496 attribute11,
6497 attribute12,
6498 attribute13,
6499 attribute14,
6500 attribute15
6501 )
6502 select distinct
6503 pConfigId, -- INVENTORY_ITEM_ID
6504 mp1.cost_organization_id,
6505 c.cost_type_id,
6506 sysdate, -- last_update_date
6507 -1, -- last_updated_by
6508 sysdate, -- creation_date
6509 -1, -- created_by
6510 -1, -- last_update_login
6511 C.inventory_asset_flag,
6512 C.lot_size,
6513 C.based_on_rollup_flag,
6514 C.shrinkage_rate,
6515 C.defaulted_flag,
6516 NULL, -- cost_update_id
6517 0, -- C.pl_material,
6518 0, -- C.pl_material_overhead,
6519 0, -- C.pl_resource,
6520 0, -- C.pl_outside_processing,
6521 0, -- C.pl_overhead,
6522 v_material_cost, -- C.tl_material,
6523 v_material_overhead_cost, -- C.tl_material_overhead,
6524 v_resource_cost, -- C.tl_resource,
6525 v_outside_processing_cost, -- C.tl_outside_processing,
6526 v_overhead_cost, --C.tl_overhead,
6527 v_material_cost, -- material_cost
6528 v_material_overhead_cost, -- material_overhead_cost
6529 v_resource_cost, -- resource_cost
6530 v_outside_processing_cost, -- outside_processing_cost
6531 v_overhead_cost, -- overhead_cost
6532 0, -- C.pl_item_cost,
6533 v_item_cost, -- C.tl_item_cost,
6534 v_item_cost, -- C.item_cost,
6535 0, -- C.unburdened_cost ,
6536 v_material_overhead_cost, -- C.burden_cost, /* check with rixin */
6537 C.attribute_category,
6538 C.attribute1,
6539 C.attribute2,
6540 C.attribute3,
6541 C.attribute4,
6542 C.attribute5,
6543 C.attribute6,
6544 C.attribute7,
6545 C.attribute8,
6546 C.attribute9,
6547 C.attribute10,
6548 C.attribute11,
6549 C.ATTRIBUTE12,
6550 C.attribute13,
6551 C.attribute14,
6552 C.attribute15
6553 from
6554 mtl_parameters MP1,
6555 cst_item_costs C,
6556 mtl_system_items S,
6557 bom_cto_src_orgs bcso
6558 where S.organization_id = C.organization_id
6559 and S.inventory_item_id = C.inventory_item_id
6560 and C.inventory_item_id = pModelId
6561 and C.inventory_item_id = S.inventory_item_id
6562 and bcso.model_item_id = pModelId
6563 and bcso.line_id = pLineId
6564 and C.cost_type_id in ( mp1.primary_cost_method, mp1.avg_rates_cost_type_id)
6565 and C.organization_id = MP1.organization_id
6566 and mp1.organization_id = bcso.organization_id
6567 and NOT EXISTS
6568 (select NULL
6569 from CST_ITEM_COSTS
6570 where inventory_item_id = pConfigId
6571 and organization_id = mp1.organization_id
6572 and cost_type_id in (mp1.primary_cost_method, mp1.avg_rates_cost_type_id));
6573
6574
6575 --Bugfix 6717614
6576 lCnt := sql%rowcount;
6577 --Bugfix 6717614
6578
6579 IF PG_DEBUG <> 0 THEN
6580 oe_debug_pub.add('Create_Item: ' || ' config item ' || pConfigId || ' after insert:CST_ITEM_COSTS inserted '|| to_char(lCnt),2);
6581 END IF;
6582
6583
6584 if( l_rt_cicd_summary.cost_type_id.count> 0 ) then
6585 FORALL j IN 1..l_rt_cicd_summary.cost_type_id.last
6586 UPDATE cst_item_costs
6587 set material_cost = l_rt_cicd_summary.material_cost(j),
6588 material_overhead_cost = l_rt_cicd_summary.material_overhead_cost(j),
6589 resource_cost = l_rt_cicd_summary.resource_cost(j),
6590 outside_processing_cost = l_rt_cicd_summary.outside_processing_cost(j),
6591 overhead_cost = l_rt_cicd_summary.overhead_cost(j),
6592 tl_material = l_rt_cicd_summary.material_cost(j),
6593 tl_material_overhead = l_rt_cicd_summary.material_overhead_cost(j),
6594 tl_resource = l_rt_cicd_summary.resource_cost(j),
6595 tl_outside_processing = l_rt_cicd_summary.outside_processing_cost(j),
6596 tl_overhead = l_rt_cicd_summary.overhead_cost(j),
6597 tl_item_cost = l_rt_cicd_summary.item_cost(j),
6598 item_cost = l_rt_cicd_summary.item_cost(j),
6599 burden_cost = l_rt_cicd_summary.material_overhead_cost(j)
6600 where inventory_item_id = pConfigId
6601 and organization_id = l_rt_cicd_summary.cost_organization_id(j)
6602 and cost_type_id = l_rt_cicd_summary.cost_type_id(j) ;
6603
6604
6605 IF PG_DEBUG <> 0 THEN
6606 oe_debug_pub.add('Create_Item: ' || 'after update:CST_ITEM_COSTS '|| to_char(sql%rowcount),2);
6607 END IF;
6608 else
6609
6610 oe_debug_pub.add( 'No update required to CST_ITEM_COSTS as no new records inserted ' , 1 ) ;
6611
6612 end if;
6613
6614
6615
6616
6617
6618
6619
6620 /* For standard costing orgs, we will copy model's user-defined
6621 cost in Frozen to the config in CTO cost type. */
6622
6623 /* begin bugfix 4057651, default CTO cost type id = 7 if it does not exist */
6624 begin
6625
6626 select cost_type_id into l_cto_cost_type_id
6627 from cst_cost_types
6628 where cost_type = 'CTO' ;
6629
6630 exception
6631 when no_data_found then
6632
6633 IF PG_DEBUG <> 0 THEN
6634 oe_debug_pub.add('Create_Item: ' || ' no_data_found error CTO cost type id does not exist',2);
6635 oe_debug_pub.add('Create_Item: ' || ' defaulting CTO cost type id = 7 ',2);
6636 END IF;
6637
6638 l_cto_cost_type_id := 7 ;
6639
6640 begin
6641 select cost_type into v_cto_cost_type_name
6642 from cst_cost_types
6643 where cost_type_id = l_cto_cost_type_id ;
6644
6645 IF PG_DEBUG <> 0 THEN
6646 oe_debug_pub.add('Create_Item: ' || ' cost type id = ' || l_cto_cost_type_id ||
6647 ' has cost_type = -' || v_cto_cost_type_name || '- delimiter(-cost-)' ,2);
6648 END IF;
6649 exception
6650 when no_data_found then
6651 IF PG_DEBUG <> 0 THEN
6652 oe_debug_pub.add('Create_Item: ' || ' no_data_found error for cost type id = 7 ',2);
6653 END IF;
6654 cto_msg_pub.cto_message('BOM','CTO_COST_NOT_FOUND');
6655 raise FND_API.G_EXC_ERROR;
6656 when others then
6657
6658 raise FND_API.G_EXC_UNEXPECTED_ERROR;
6659 end ;
6660
6661 when others then
6662 raise FND_API.G_EXC_UNEXPECTED_ERROR;
6663 end ;
6664 /* end bugfix 4057651, default CTO cost type id = 7 if it does not exist */
6665
6666
6667
6668 insert into CST_ITEM_COSTS
6669 (inventory_item_id,
6670 organization_id,
6671 cost_type_id,
6672 last_update_date,
6673 last_updated_by,
6674 creation_date,
6675 created_by,
6676 last_update_login,
6677 inventory_asset_flag,
6678 lot_size,
6679 based_on_rollup_flag,
6680 shrinkage_rate,
6681 defaulted_flag,
6682 cost_update_id,
6683 pl_material,
6684 pl_material_overhead,
6685 pl_resource,
6686 pl_outside_processing,
6687 pl_overhead,
6688 tl_material,
6689 tl_material_overhead,
6690 tl_resource,
6691 tl_outside_processing,
6692 tl_overhead,
6693 material_cost,
6694 material_overhead_cost,
6695 resource_cost,
6696 outside_processing_cost ,
6697 overhead_cost,
6698 pl_item_cost,
6699 tl_item_cost,
6700 item_cost,
6701 unburdened_cost ,
6702 burden_cost,
6703 attribute_category,
6704 attribute1,
6705 attribute2,
6706 attribute3,
6707 attribute4,
6708 attribute5,
6709 attribute6,
6710 attribute7,
6711 attribute8,
6712 attribute9,
6713 attribute10,
6714 attribute11,
6715 attribute12,
6716 attribute13,
6717 attribute14,
6718 attribute15
6719 )
6720 select distinct
6721 pConfigId, -- INVENTORY_ITEM_ID
6722 mp1.cost_organization_id,
6723 l_cto_cost_type_id, -- CTO cost_type_id,
6724 sysdate, -- last_update_date
6725 -1, -- last_updated_by
6726 sysdate, -- creation_date
6727 -1, -- created_by
6728 -1, -- last_update_login
6729 C.inventory_asset_flag,
6730 C.lot_size,
6731 C.based_on_rollup_flag,
6732 C.shrinkage_rate,
6733 C.defaulted_flag,
6734 NULL, -- cost_update_id
6735 0, -- C.pl_material,
6736 0, -- C.pl_material_overhead,
6737 0, -- C.pl_resource,
6738 0, -- C.pl_outside_processing,
6739 0, -- C.pl_overhead,
6740 v_material_cost, -- C.tl_material,
6741 v_material_overhead_cost, -- C.tl_material_overhead,
6742 v_resource_cost, -- C.tl_resource,
6743 v_outside_processing_cost, -- C.tl_outside_processing,
6744 v_overhead_cost, -- C.tl_overhead,
6745 v_material_cost, -- material cost
6746 v_material_overhead_cost, -- material overhead cost
6747 v_resource_cost, -- resource cost
6748 v_outside_processing_cost, -- outside processing cost
6749 v_overhead_cost, -- overhead cost
6750 0, -- C.pl_item_cost,
6751 v_item_cost, -- C.tl_item_cost,
6752 v_item_cost, -- total item cost
6753 0, -- C.unburdened_cost ,
6754 v_material_overhead_cost, -- C.burden_cost,
6755 C.attribute_category,
6756 C.attribute1,
6757 C.attribute2,
6758 C.attribute3,
6759 C.attribute4,
6760 C.attribute5,
6761 C.attribute6,
6762 C.attribute7,
6763 C.attribute8,
6764 C.attribute9,
6765 C.attribute10,
6766 C.attribute11,
6767 C.ATTRIBUTE12,
6768 C.attribute13,
6769 C.attribute14,
6770 C.attribute15
6771 from
6772 mtl_parameters MP1,
6773 cst_item_costs C,
6774 mtl_system_items S,
6775 bom_cto_src_orgs bcso
6776 where S.organization_id = C.organization_id
6777 and S.inventory_item_id = C.inventory_item_id
6778 and C.inventory_item_id = pModelId
6779 and C.inventory_item_id = S.inventory_item_id
6780 and bcso.model_item_id = pModelId
6781 and bcso.line_id = pLineId
6782 and C.cost_type_id = mp1.primary_cost_method
6783 and C.cost_type_id = 1
6784 and C.organization_id = MP1.organization_id
6785 and mp1.organization_id = bcso.organization_id
6786 and NOT EXISTS
6787 (select NULL
6788 from CST_ITEM_COSTS
6789 where inventory_item_id = pConfigId
6790 and organization_id = mp1.organization_id
6791 and cost_type_id = l_cto_cost_type_id);
6792
6793
6794
6795 IF PG_DEBUG <> 0 THEN
6796 oe_debug_pub.add('Create_Item: ' || ' config item ' || pConfigId || ' after insert UD cost into CTO cost type inserted '|| to_char(sql%rowcount),2);
6797
6798 END IF;
6799
6800
6801 if( l_rt_cicd_summary.cost_type_id.count > 0 ) then
6802 FORALL j IN 1..l_rt_cicd_summary.cost_type_id.last
6803 UPDATE cst_item_costs
6804 set material_cost = l_rt_cicd_summary.material_cost(j),
6805 material_overhead_cost = l_rt_cicd_summary.material_overhead_cost(j),
6806 resource_cost = l_rt_cicd_summary.resource_cost(j),
6807 outside_processing_cost = l_rt_cicd_summary.outside_processing_cost(j),
6808 overhead_cost = l_rt_cicd_summary.overhead_cost(j),
6809 tl_material = l_rt_cicd_summary.material_cost(j),
6810 tl_material_overhead = l_rt_cicd_summary.material_overhead_cost(j),
6811 tl_resource = l_rt_cicd_summary.resource_cost(j),
6812 tl_outside_processing = l_rt_cicd_summary.outside_processing_cost(j),
6813 tl_overhead = l_rt_cicd_summary.overhead_cost(j),
6814 tl_item_cost = l_rt_cicd_summary.item_cost(j),
6815 item_cost = l_rt_cicd_summary.item_cost(j),
6816 burden_cost = l_rt_cicd_summary.material_overhead_cost(j)
6817 where inventory_item_id = pConfigId
6818 and organization_id = l_rt_cicd_summary.cost_organization_id(j)
6819 and cost_type_id = l_cto_cost_type_id ;
6820
6821
6822 IF PG_DEBUG <> 0 THEN
6823 oe_debug_pub.add('Create_Item: ' || 'after update:cst_item_costs for CTO cost type '||to_char(sql%rowcount),2);
6824 END IF;
6825
6826 else
6827
6828 oe_debug_pub.add( 'No update required to CST_ITEM_COSTS for CTO cost type as no new records inserted ' , 1 ) ;
6829
6830 end if;
6831
6832
6833
6834
6835
6836 /*------ ----------------------------------------------+
6837 Insert rows into the cst_item_cost_details table
6838 +-----------------------------------------------------*/
6839
6840 lStmtNumber := 230;
6841
6842 insert into cst_item_cost_details
6843 (inventory_item_id,
6844 cost_type_id,
6845 last_update_date,
6846 last_updated_by,
6847 creation_date,
6848 created_by,
6849 last_update_login,
6850 organization_id,
6851 operation_sequence_id,
6852 operation_seq_num,
6853 department_id,
6854 level_type,
6855 activity_id,
6856 resource_seq_num,
6857 resource_id,
6858 resource_rate,
6859 item_units,
6860 activity_units,
6861 usage_rate_or_amount,
6862 basis_type,
6863 basis_resource_id,
6864 basis_factor,
6865 net_yield_or_shrinkage_factor,
6866 item_cost,
6867 cost_element_id,
6868 rollup_source_type,
6869 activity_context,
6870 attribute_category,
6871 attribute1,
6872 attribute2,
6873 attribute3,
6874 attribute4,
6875 attribute5,
6876 attribute6,
6877 attribute7,
6878 attribute8,
6879 attribute9,
6880 attribute10,
6881 attribute11,
6882 attribute12,
6883 attribute13,
6884 attribute14,
6885 attribute15
6886 )
6887 select distinct
6888 pConfigId, -- inventory_item_id
6889 c.cost_type_id,
6890 sysdate, -- last_update_date
6891 -1, -- last_updated_by
6892 sysdate, -- creation_date
6893 -1, -- created_by
6894 -1, -- last_update_login
6895 mp1.cost_organization_id,
6896 c.operation_sequence_id,
6897 c.operation_seq_num,
6898 c.department_id,
6899 c.level_type,
6900 c.activity_id,
6901 c.resource_seq_num,
6902 c.resource_id,
6903 c.resource_rate,
6904 c.item_units,
6905 c.activity_units,
6906 c.usage_rate_or_amount,
6907 c.basis_type,
6908 c.basis_resource_id,
6909 c.basis_factor,
6910 c.net_yield_or_shrinkage_factor,
6911 c.item_cost,
6912 c.cost_element_id,
6913 C.rollup_source_type,
6914 C.activity_context,
6915 C.attribute_category,
6916 C.attribute1,
6917 C.attribute2,
6918 C.attribute3,
6919 C.attribute4,
6920 C.attribute5,
6921 C.attribute6,
6922 C.attribute7,
6923 C.attribute8,
6924 C.attribute9,
6925 C.attribute10,
6926 C.attribute11,
6927 C.attribute12,
6928 C.attribute13,
6929 C.attribute14,
6930 C.attribute15
6931 from
6932 mtl_parameters MP1,
6933 cst_item_cost_details C,
6934 mtl_system_items S,
6935 bom_cto_src_orgs bcso
6936 where S.organization_id = C.organization_id
6937 and S.inventory_item_id = C.inventory_item_id
6938 and bcso.model_item_id = pModelId
6939 and bcso.line_id = pLineId
6940 and C.organization_id = MP1.organization_id
6941 and C.inventory_item_id = pModelId
6942 and C.inventory_item_id = S.inventory_item_id
6943 and C.rollup_source_type = 1 -- User Defined
6944 and C.COST_TYPE_ID IN ( MP1.primary_cost_method, MP1.avg_rates_cost_type_id)
6945 and mp1.organization_id = bcso.organization_id
6946 and NOT EXISTS
6947 (select NULL
6948 from cst_item_cost_details
6949 where inventory_item_id = pConfigId
6950 and organization_id = mp1.organization_id
6951 and COST_TYPE_ID IN (MP1.primary_cost_method, MP1.avg_rates_cost_type_id));
6952
6953
6954
6955 IF PG_DEBUG <> 0 THEN
6956 oe_debug_pub.add('Create_Item: ' || 'after insert:cst_item_cost_details inserted '||to_char(sql%rowcount),2);
6957 END IF;
6958
6959
6960
6961
6962
6963 /* For standard costing orgs, we will copy model's user-defined
6964 cost in Frozen to the config in CTO cost type. */
6965
6966 insert into cst_item_cost_details
6967 (inventory_item_id,
6968 cost_type_id,
6969 last_update_date,
6970 last_updated_by,
6971 creation_date,
6972 created_by,
6973 last_update_login,
6974 organization_id,
6975 operation_sequence_id,
6976 operation_seq_num,
6977 department_id,
6978 level_type,
6979 activity_id,
6980 resource_seq_num,
6981 resource_id,
6982 resource_rate,
6983 item_units,
6984 activity_units,
6985 usage_rate_or_amount,
6986 basis_type,
6987 basis_resource_id,
6988 basis_factor,
6989 net_yield_or_shrinkage_factor,
6990 item_cost,
6991 cost_element_id,
6992 rollup_source_type,
6993 activity_context,
6994 attribute_category,
6995 attribute1,
6996 attribute2,
6997 attribute3,
6998 attribute4,
6999 attribute5,
7000 attribute6,
7001 attribute7,
7002 attribute8,
7003 attribute9,
7004 attribute10,
7005 attribute11,
7006 attribute12,
7007 attribute13,
7008 attribute14,
7009 attribute15
7010 )
7011 select distinct
7012 pConfigId, -- inventory_item_id
7013 l_cto_cost_type_id, -- CTO cost_type_id,
7014 sysdate, -- last_update_date
7015 -1, -- last_updated_by
7016 sysdate, -- creation_date
7017 -1, -- created_by
7018 -1, -- last_update_login
7019 mp1.cost_organization_id,
7020 c.operation_sequence_id,
7021 c.operation_seq_num,
7022 c.department_id,
7023 c.level_type,
7024 c.activity_id,
7025 c.resource_seq_num,
7026 c.resource_id,
7027 c.resource_rate,
7028 c.item_units,
7029 c.activity_units,
7030 c.usage_rate_or_amount,
7031 c.basis_type,
7032 c.basis_resource_id,
7033 c.basis_factor,
7034 c.net_yield_or_shrinkage_factor,
7035 c.item_cost,
7036 c.cost_element_id,
7037 C.rollup_source_type,
7038 C.activity_context,
7039 C.attribute_category,
7040 C.attribute1,
7041 C.attribute2,
7042 C.attribute3,
7043 C.attribute4,
7044 C.attribute5,
7045 C.attribute6,
7046 C.attribute7,
7047 C.attribute8,
7048 C.attribute9,
7049 C.attribute10,
7050 C.attribute11,
7051 C.attribute12,
7052 C.attribute13,
7053 C.attribute14,
7054 C.attribute15
7055 from
7056 mtl_parameters MP1,
7057 cst_item_cost_details C,
7058 mtl_system_items S,
7059 bom_cto_src_orgs bcso
7060 where S.organization_id = C.organization_id
7061 and S.inventory_item_id = C.inventory_item_id
7062 and bcso.model_item_id = pModelId
7063 and bcso.line_id = pLineId
7064 and C.organization_id = MP1.organization_id
7065 and C.inventory_item_id = pModelId
7066 and C.inventory_item_id = S.inventory_item_id
7067 and C.rollup_source_type = 1 -- User Defined
7068 and C.COST_TYPE_ID = MP1.primary_cost_method
7069 and C.cost_type_id = 1
7070 and mp1.organization_id = bcso.organization_id
7071 and NOT EXISTS
7072 (select NULL
7073 from cst_item_cost_details
7074 where inventory_item_id = pConfigId
7075 and organization_id = mp1.organization_id
7076 and COST_TYPE_ID = l_cto_cost_type_id);
7077
7078
7079
7080
7081 IF PG_DEBUG <> 0 THEN
7082 oe_debug_pub.add('Create_Item: ' || 'after insert UD cost into CICD for CTO cost type inserted '||to_char(sql%rowcount),2);
7083 END IF;
7084
7085
7086 --Bugfix 6717614
7087 if lCnt = 0 then
7088 IF PG_DEBUG <> 0 THEN
7089 oe_debug_pub.add('Create_Item: ' || 'No need to populate csc and cec as no new record inserted in cic and cicd',2);
7090 END IF;
7091 else
7092
7093 --begin Bugfix 6363308
7094 lStmtNumber := 231;
7095 IF PG_DEBUG <> 0 THEN
7096 oe_debug_pub.add('Create_Item: ' || 'going to populate data in csc and cec if frozen cost of config is not zero',2);
7097 END IF;
7098
7099 OPEN get_orgs_with_frozen_cost(pconfigId);
7100 loop
7101
7102 FETCH get_orgs_with_frozen_cost INTO v_organization_id
7103 , v_item_cost_frozen;
7104 EXIT WHEN get_orgs_with_frozen_cost%NOTFOUND;
7105
7106 IF PG_DEBUG <> 0 THEN
7107 oe_debug_pub.add('Create_Item: ' || 'fetched org '||to_char(v_organization_id),2);
7108 oe_debug_pub.add('Create_Item: ' || 'frozen cost for config '||to_char(pConfigId) || 'is: ' || to_char(v_item_cost_frozen),2);
7109 END IF;
7110
7111 IF (v_item_cost_frozen <> 0) THEN
7112
7113 lStmtNumber := 232;
7114 IF PG_DEBUG <> 0 THEN
7115 oe_debug_pub.add('Create_Item: ' || 'Came inside if. v_item_cost_frozen is not zero',2);
7116 oe_debug_pub.add('Create_Item: ' || 'Fetching value from sequence',2);
7117 END IF;
7118
7119 Select cst_lists_s.nextval
7120 into l_cost_update
7121 From DUAL;
7122
7123 lStmtNumber := 233;
7124
7125 UPDATE CST_ITEM_COSTS
7126 SET cost_update_id = l_cost_update
7127 WHERE ORGANIZATION_ID = v_organization_id
7128 AND INVENTORY_ITEM_ID = pConfigId
7129 AND COST_TYPE_ID = 1;
7130
7131 IF PG_DEBUG <> 0 THEN
7132 oe_debug_pub.add('Create_Item: ' || 'Updated cost_update_id to value ' || to_char(l_cost_update),2);
7133 END IF;
7134
7135 lStmtNumber := 234;
7136 IF PG_DEBUG <> 0 THEN
7137 oe_debug_pub.add('Create_Item: ' || 'Inserting records in csc and cec',2);
7138 END IF;
7139
7140 INSERT INTO cst_standard_costs
7141 (cost_update_id,
7142 organization_id,
7143 inventory_item_id,
7144 last_update_date,
7145 last_updated_by,
7146 creation_date,
7147 created_by,
7148 last_update_login,
7149 standard_cost_revision_date,
7150 standard_cost
7151 )
7152 SELECT l_cost_update,
7153 v_organization_id,
7154 pConfigId,
7155 SYSDATE,
7156 -1,
7157 SYSDATE,
7158 -1,
7159 -1,
7160 SYSDATE,
7161 NVL(SUM(item_cost),0)
7162 FROM cst_item_cost_details
7163 WHERE ORGANIZATION_ID = v_organization_id
7164 AND INVENTORY_ITEM_ID = pConfigId
7165 AND COST_TYPE_ID = 1;
7166
7167 IF PG_DEBUG <> 0 THEN
7168 oe_debug_pub.add('Create_Item: ' || 'after insert:cst_standard_costs ' || sql%rowcount ,2);
7169 END IF;
7170
7171 lStmtNumber := 235;
7172
7173 INSERT INTO cst_elemental_costs
7174 (cost_update_id,
7175 organization_id,
7176 inventory_item_id,
7177 cost_element_id,
7178 last_update_date,
7179 last_updated_by,
7180 creation_date,
7181 created_by,
7182 last_update_login,
7183 standard_cost
7184 )
7185 SELECT l_cost_update,
7186 v_organization_id,
7187 pConfigId,
7188 cost_element_id,
7189 SYSDATE,
7190 -1,
7191 SYSDATE,
7192 -1,
7193 -1,
7194 NVL(SUM(item_cost),0)
7195 FROM cst_item_cost_details
7196 WHERE ORGANIZATION_ID = v_organization_id
7197 AND INVENTORY_ITEM_ID = pConfigId
7198 AND COST_TYPE_ID = 1
7199 GROUP BY cost_element_id;
7200
7201 IF PG_DEBUG <> 0 THEN
7202 oe_debug_pub.add('Create_Item: ' || 'after insert:cst_elemental_costs ' || sql%rowcount ,2);
7203 END IF;
7204 END IF; -- v_item_cost_frozen <> 0
7205 end loop;
7206
7207 CLOSE get_orgs_with_frozen_cost;
7208 --End Bugfix 6363308
7209 end if; --lCnt = 0
7210
7211
7212 /*------------------------------------------------+
7213 check the following statement
7214 If the project id is not specified on the line,
7215 l_cost_group_id should be 1
7216 +-------------------------------------------------*/
7217
7218 lStmtNumber := 240;
7219
7220 --
7221 -- Currently, project mfg is not fully supported for ML ATO
7222 -- Currently, if a project is specified on the model line,
7223 -- we get the cost group id for this project in the ship-from-org
7224 -- This may not work correctly for mulit-sourcing, if different
7225 -- projects are assigned to different orgs.
7226 --
7227 select ship_from_org_id
7228 into lShipFromOrg
7229 from bom_cto_order_lines bcol
7230 where line_id = pLineID;
7231
7232 l_cost_group_id := get_cost_group(lShipFromOrg, pLineID);
7233
7234 if (l_cost_group_id = 0) then
7235 l_cost_group_id := 1;
7236 end if;
7237
7238
7239 -- Bugfix 1573941 : Added IF condition to check the profile : "CST:Average costing option"
7240 -- Only when this profile is set to "Inventory and WIP", should the records be inserted in CQL.
7241 -- 1 = Inventory Only
7242 -- 2 = Inventory and WIP
7243
7244 IF ( nvl(fnd_profile.value('CST_AVG_COSTING_OPTION'), '1') = '2' ) THEN
7245 FOR v_layer in c_layer
7246 LOOP
7247
7248 --
7249 -- This costing API will insert a row into cst_quantity_layers
7250 -- for a unique layer_id and the given parameters.
7251 -- It will return 0 if failed, layer_id if succeeded
7252 --
7253 l_layer_id := cstpaclm.create_layer (
7254 i_org_id => v_layer.org_id,
7255 i_item_id => pConfigId,
7256 i_cost_group_id => v_layer.cost_group_id,
7257 i_user_id => gUserId,
7258 i_request_id => NULL,
7259 i_prog_id => NULL,
7260 i_prog_appl_id => NULL,
7261 i_txn_id => -1,
7262 o_err_num => x_err_num,
7263 o_err_code => x_msg_name,
7264 o_err_msg => lMsgData
7265 );
7266
7267 IF (l_layer_id = 0) THEN
7268 IF PG_DEBUG <> 0 THEN
7269 oe_debug_pub.add('Create_Item: ' || 'CST function create_layer returned with error '||to_char(x_err_num)||', '||x_msg_name||', '||
7270 lMsgData||'for '||to_char(v_layer.org_id)||', '||to_char(v_layer.cost_group_id),1);
7271 END IF;
7272 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7273 ELSE
7274 IF PG_DEBUG <> 0 THEN
7275 oe_debug_pub.add('Create_Item: ' || 'Inserted row into cql for '||to_char(l_layer_id)||', '||to_char(v_layer.org_id)||', '||
7276 to_char(v_layer.cost_group_id),1);
7277 END IF;
7278 END IF;
7279
7280 END LOOP;
7281 END IF; /* End bugfix 1573941 */
7282
7283 IF PG_DEBUG <> 0 THEN
7284 oe_debug_pub.add('Create_Item: ' || 'after insert:cst_quantity_layers ',2);
7285 END IF;
7286
7287
7288 /*--------------------------------------------------------+
7289 Insert rows into the mtl_desc_elem_val_interface table
7290 Descriptive elements are not organization controlled
7291 Using validation org to get values
7292 +---------------------------------------------------------*/
7293
7294 lStmtNumber := 250;
7295
7296 insert into MTL_DESCR_ELEMENT_VALUES
7297 (inventory_item_id,
7298 element_name,
7299 last_update_date,
7300 last_updated_by,
7301 last_update_login,
7302 creation_date,
7303 created_by,
7304 element_value,
7305 default_element_flag,
7306 element_sequence,
7307 program_application_id,
7308 program_id,
7309 program_update_date,
7310 request_id
7311 )
7312 select distinct
7313 pConfigId, -- Inventory_item_id
7314 E.element_name, -- element_name
7315 sysdate, -- last_update_date
7316 gUserId, -- last_updated_by
7317 gLoginId, -- last_update_login
7318 sysdate, -- creation_date
7319 gUserId, -- created_by
7320 D.element_value, -- element_value
7321 E.default_element_flag, -- default_element_flag
7322 E.element_sequence, -- element_sequence
7323 NULL, -- program_application_id
7324 NULL, -- program_id
7325 SYSDATE, -- program_update_date
7326 NULL -- request_id
7327 from mtl_system_items s,
7328 mtl_descr_element_values D,
7329 mtl_descriptive_elements E
7330 where D.inventory_item_id = S.inventory_item_id
7331 and s.inventory_item_id = pModelid
7332 and s.organization_id = lValidationOrg
7333 and E.item_catalog_group_id = S.item_catalog_group_id
7334 and E.element_name = D.element_name
7335 and NOT EXISTS
7336 (select NULL
7337 from mtl_descr_element_values
7338 where inventory_item_id = pConfigId
7339 and organization_id = lValidationOrg);
7340
7341 IF PG_DEBUG <> 0 THEN
7342 oe_debug_pub.add('Create_Item: ' || 'after insert: MTL_DESCR_ELEMENT_VALUES',2);
7343 END IF;
7344
7345
7346 /*--------------------------------------+
7347 Insert into mtl_item_categories
7348 +--------------------------------------*/
7349
7350 lStmtNumber := 260;
7351
7352 --bugfix 4861996
7353 --added ic1.category_set_id = ic.category_set_id condition
7354
7355 insert into MTL_ITEM_CATEGORIES
7356 (inventory_item_id,
7357 category_set_id,
7358 category_id,
7359 last_update_date,
7360 last_updated_by,
7361 creation_date,
7362 created_by,
7363 last_update_login,
7364 request_id,
7365 program_application_id,
7366 program_id,
7367 program_update_date,
7368 organization_id
7369 )
7370 select distinct
7371 pConfigId,
7372 ic.category_set_id,
7373 ic.category_id,
7374 sysdate, -- last_update_date
7375 gUserId, -- last_updated_by
7376 sysdate, --creation_date
7377 gUserId, -- created_by
7378 gLoginId, -- last_update_login
7379 NULL, -- request_id
7380 NULL, -- program_application_id
7381 NULL, -- program_id
7382 SYSDATE, -- program_update_date
7383 ic.organization_id
7384 from
7385 mtl_item_categories ic,
7386 bom_cto_src_orgs bcso
7387 where ic.inventory_item_id = pModelId --bugfix 2706981: swapped the positions
7388 and ic.organization_id = bcso.organization_id
7389 and bcso.model_item_id = ic.inventory_item_id --bugfix 2706981: replaced pModelId with col join
7390 and bcso.line_id = pLineId -- as in bugfix 2215274
7391 --
7392 -- bugfix 2619501 (butler mfg):
7393 -- We will call custom hook to see which category_set needs to be inserted.
7394 -- If the custom hook returns 1 for a particular category_set_id, then, we will insert that category set.
7395 -- By default, the custom hook will return 1 for all category sets except sales and mktg category set.
7396 --
7397 -- and ic.category_set_id <> 5 -- bugfix 2395525
7398 and CTO_CUSTOM_CATEGORY_PK.Copy_Category (ic.category_set_id , ic.organization_id) = 1
7399 --
7400 -- end bugfix 2619501:
7401 --
7402 and NOT EXISTS
7403 (select NULL
7404 from MTL_ITEM_CATEGORIES ic1 -- bugfix 2706981: added alias
7405 where ic1.inventory_item_id = pConfigId
7406 and ic1.organization_id = bcso.organization_id
7407 and ic1.category_set_id = ic.category_set_id
7408 );
7409
7410
7411
7412
7413
7414
7415
7416 IF PG_DEBUG <> 0 THEN
7417 oe_debug_pub.add('Create_Item: ' || 'after insert: MTL_ITEM_CATEGORIES',2);
7418 END IF;
7419
7420 -- Start Bugfix 2197842
7421
7422 lStmtNumber := 261;
7423
7424 insert into MTL_ITEM_CATEGORIES
7425 (inventory_item_id,
7426 category_set_id,
7427 category_id,
7428 last_update_date,
7429 last_updated_by,
7430 creation_date,
7431 created_by,
7432 last_update_login,
7433 request_id,
7434 program_application_id,
7435 program_id,
7436 program_update_date,
7437 organization_id
7438 )
7439 select distinct
7440 pConfigId,
7441 mcsb.category_set_id,
7442 mcsb.default_category_id,
7443 sysdate, -- last_update_date
7444 gUserId, -- last_updated_by
7445 sysdate, --creation_date
7446 gUserId, -- created_by
7447 gLoginId, -- last_update_login
7448 NULL, -- request_id
7449 NULL, -- program_application_id
7450 NULL, -- program_id
7451 SYSDATE, -- program_update_date
7452 ic.organization_id
7453 from
7454 mtl_item_categories ic,
7455 mtl_category_sets_b mcsb,
7456 mtl_default_category_sets mdcs,
7457 bom_cto_src_orgs bcso
7458 where pModelId = ic.inventory_item_id
7459 and ic.organization_id = bcso.organization_id
7460 and bcso.model_item_id = pModelId
7461 and bcso.line_id = pLineId
7462 and mcsb.category_set_id = mdcs.category_set_id
7463 and mdcs.functional_area_id = 2
7464 and NOT EXISTS
7465 (
7466 select NULL
7467 from MTL_ITEM_CATEGORIES
7468 where inventory_item_id = pConfigId
7469 and organization_id = bcso.organization_id
7470 and category_set_id = mcsb.category_set_id
7471 );
7472
7473
7474
7475
7476
7477 IF PG_DEBUG <> 0 THEN
7478 oe_debug_pub.add('Create_Item: ' || 'after insert: MTL_ITEM_CATEGORIES FOR DEFAULT CATEGORIES',2);
7479 END IF;
7480
7481 -- End Bugfix 2197842
7482
7483 /*----------------------------------------------------+
7484 Copy related items into MTL_RELATED_ITEMS table
7485 +----------------------------------------------------*/
7486
7487 lStmtNumber := 270;
7488
7489 insert into MTL_RELATED_ITEMS
7490 (
7491 inventory_item_id,
7492 related_item_id,
7493 relationship_type_id,
7494 reciprocal_flag,
7495 last_update_date,
7496 last_updated_by,
7497 creation_date,
7498 created_by,
7499 last_update_login,
7500 request_id,
7501 program_application_id,
7502 program_id,
7503 program_update_date,
7504 organization_id
7505 )
7506 select distinct
7507 pConfigId,
7508 ri.related_item_id,
7509 ri.relationship_type_id,
7510 ri.reciprocal_flag,
7511 sysdate, -- last_update_date
7512 gUserId, -- last_updated_by
7513 sysdate, --creation_date
7514 gUserId, -- created_by
7515 gLoginId, -- last_update_login
7516 NULL, -- request_id
7517 NULL, -- program_application_id
7518 NULL, -- program_id
7519 SYSDATE, -- program_update_date
7520 ri.organization_id
7521 from mtl_related_items ri,
7522 bom_cto_src_orgs bcso
7523 where ri.inventory_item_id = pModelId
7524 and bcso.model_item_id = pModelId
7525 and bcso.line_id = pLineId
7526 and ri.organization_id = bcso.organization_id
7527 and NOT EXISTS
7528 (select NULL
7529 from mtl_related_items
7530 where inventory_item_id = pConfigId
7531 and organization_id = bcso.organization_id);
7532
7533
7534
7535
7536
7537 IF PG_DEBUG <> 0 THEN
7538 oe_debug_pub.add('Create_Item: ' || 'after insert:mtl_related_items',2);
7539 END IF;
7540
7541 /*--------------------------------------------------+
7542 Copy substitute inventories
7543 +--------------------------------------------------*/
7544
7545 lStmtNumber := 280;
7546
7547 insert into mtl_item_sub_inventories
7548 (
7549 inventory_item_id,
7550 organization_id,
7551 secondary_inventory,
7552 last_update_date,
7553 last_updated_by,
7554 creation_date,
7555 created_by,
7556 last_update_login,
7557 primary_subinventory_flag ,
7558 picking_order,
7559 min_minmax_quantity,
7560 max_minmax_quantity,
7561 inventory_planning_code,
7562 fixed_lot_multiple,
7563 minimum_order_quantity,
7564 maximum_order_quantity,
7565 source_type,
7566 source_organization_id,
7567 source_subinventory,
7568 attribute_category,
7569 attribute1,
7570 attribute2,
7571 attribute3,
7572 attribute4,
7573 attribute5,
7574 attribute6,
7575 attribute7,
7576 attribute8,
7577 attribute9,
7578 attribute10,
7579 attribute11,
7580 attribute12,
7581 attribute13,
7582 attribute14,
7583 attribute15,
7584 request_id,
7585 program_application_id ,
7586 program_id,
7587 program_update_date,
7588 encumbrance_account
7589 )
7590 select distinct
7591 pConfigId,
7592 isi.ORGANIZATION_ID,
7593 isi.SECONDARY_INVENTORY,
7594 sysdate, -- last_update_date
7595 gUserId, -- last_updated_by
7596 sysdate, -- creation_date
7597 gUserId, -- created_by
7598 gLoginId, -- last_update_login
7599 isi.PRIMARY_SUBINVENTORY_FLAG ,
7600 isi.PICKING_ORDER,
7601 isi.MIN_MINMAX_QUANTITY,
7602 isi.MAX_MINMAX_QUANTITY,
7603 isi.INVENTORY_PLANNING_CODE,
7604 isi.FIXED_LOT_MULTIPLE,
7605 isi.MINIMUM_ORDER_QUANTITY,
7606 isi.MAXIMUM_ORDER_QUANTITY,
7607 isi.SOURCE_TYPE,
7608 isi.SOURCE_ORGANIZATION_ID,
7609 isi.SOURCE_SUBINVENTORY,
7610 isi.ATTRIBUTE_CATEGORY,
7611 isi.ATTRIBUTE1,
7612 isi.ATTRIBUTE2,
7613 isi.ATTRIBUTE3,
7614 isi.ATTRIBUTE4,
7615 isi.ATTRIBUTE5,
7616 isi.ATTRIBUTE6,
7617 isi.ATTRIBUTE7,
7618 isi.ATTRIBUTE8,
7619 isi.ATTRIBUTE9,
7620 isi.ATTRIBUTE10,
7621 isi.ATTRIBUTE11,
7622 isi.ATTRIBUTE12,
7623 isi.ATTRIBUTE13,
7624 isi.ATTRIBUTE14,
7625 isi.ATTRIBUTE15,
7626 NULL, -- request_id
7627 NULL, -- program_application_id
7628 NULL, -- program_id
7629 SYSDATE, -- program_update_date
7630 isi.ENCUMBRANCE_ACCOUNT
7631 from
7632 mtl_item_sub_inventories isi,
7633 bom_cto_src_orgs bcso
7634 where isi.organization_id = bcso.organization_id
7635 and isi.inventory_item_id = pModelId
7636 and bcso.model_item_id = pModelId
7637 and bcso.line_id = pLineId
7638 and NOT EXISTS
7639 (select NULL
7640 from mtl_item_sub_inventories
7641 where inventory_item_id = pConfigId
7642 and organization_id = bcso.organization_id);
7643
7644
7645
7646
7647 IF PG_DEBUG <> 0 THEN
7648 oe_debug_pub.add('Create_Item: ' || 'after insert:mtl_item_sub_inventories',2);
7649 END IF;
7650
7651 /*--------------------------------------+
7652 Copy secondary locators
7653 +--------------------------------------*/
7654
7655 lStmtNumber := 290;
7656
7657 insert into mtl_secondary_locators
7658 (
7659 inventory_item_id,
7660 organization_id,
7661 secondary_locator,
7662 primary_locator_flag,
7663 picking_order,
7664 subinventory_code,
7665 last_update_date,
7666 last_updated_by,
7667 creation_date,
7668 created_by,
7669 last_update_login,
7670 request_id,
7671 program_application_id,
7672 program_id,
7673 program_update_date
7674 )
7675 select distinct
7676 pConfigId,
7677 sl.organization_id,
7678 sl.secondary_locator,
7679 sl.primary_locator_flag,
7680 sl.picking_order,
7681 sl.subinventory_code,
7682 sysdate, -- last_update_date
7683 gUserId, -- last_updated_by
7684 sysdate, -- creation_date
7685 gUserId, -- created_by
7686 gLoginId, -- last_update_login
7687 NULL, -- request_id
7688 NULL, -- program_application_id
7689 NULL, -- program_id
7690 SYSDATE -- program_update_date
7691 from
7692 mtl_secondary_locators sl,
7693 bom_cto_src_orgs bcso
7694 where sl.organization_id = bcso.organization_id
7695 and pModelId = sl.inventory_item_id
7696 and bcso.model_item_id = pModelId
7697 and bcso.line_id = pLineId
7698 and NOT EXISTS
7699 (select NULL
7700 from mtl_secondary_locators
7701 where inventory_item_id = pConfigId
7702 and organization_id = bcso.organization_id);
7703
7704
7705
7706
7707 IF PG_DEBUG <> 0 THEN
7708 oe_debug_pub.add('Create_Item: ' || 'after insert: mtl_secondary_locators',2);
7709 END IF;
7710
7711 /*----------------------------------------+
7712 Copy cross references
7713 +----------------------------------------*/
7714
7715 lStmtNumber := 300;
7716
7717 --start bugfix 4539578
7718
7719
7720 SELECT DISTINCT
7721 CR.ORGANIZATION_ID
7722 ,CR.CROSS_REFERENCE_TYPE
7723 ,CR.CROSS_REFERENCE
7724 ,CR.ORG_INDEPENDENT_FLAG
7725 BULK COLLECT INTO
7726 t_organization_id,
7727 t_cross_ref_type,
7728 t_cross_ref,
7729 t_org_independent_flag
7730 FROM MTL_CROSS_REFERENCES_B CR,
7731 BOM_CTO_SRC_ORGS BCSO
7732 WHERE (CR.ORGANIZATION_ID = bcso.ORGANIZATION_ID OR CR.ORGANIZATION_ID IS NULL)
7733 AND CR.INVENTORY_ITEM_ID = PMODELID
7734 AND BCSO.MODEL_ITEM_ID = PMODELID
7735 AND BCSO.LINE_ID = PLINEID
7736 AND NOT EXISTS
7737 ( SELECT NULL
7738 FROM MTL_CROSS_REFERENCES_B
7739 WHERE INVENTORY_ITEM_ID = PCONFIGID
7740 AND ( ORGANIZATION_ID = bcso.ORGANIZATION_ID OR ORGANIZATION_ID IS NULL) -- bugfix 1960994: added OR condition
7741 );
7742
7743 IF t_cross_ref_type.count <> 0 THEN
7744
7745 FORALL i IN 1..t_cross_ref_type.count
7746 INSERT INTO MTL_CROSS_REFERENCES_B
7747 (
7748 INVENTORY_ITEM_ID
7749 ,ORGANIZATION_ID
7750 ,CROSS_REFERENCE_TYPE
7751 ,CROSS_REFERENCE
7752 ,ORG_INDEPENDENT_FLAG
7753 ,LAST_UPDATE_DATE
7754 ,LAST_UPDATED_BY
7755 ,CREATION_DATE
7756 ,CREATED_BY
7757 ,LAST_UPDATE_LOGIN
7758 ,REQUEST_ID
7759 ,PROGRAM_APPLICATION_ID
7760 ,PROGRAM_ID
7761 ,PROGRAM_UPDATE_DATE
7762 ,SOURCE_SYSTEM_ID
7763 ,OBJECT_VERSION_NUMBER
7764 ,UOM_CODE
7765 ,REVISION_ID
7766 ,CROSS_REFERENCE_ID
7767 ,EPC_GTIN_SERIAL
7768 ,ATTRIBUTE1
7769 ,ATTRIBUTE2
7770 ,ATTRIBUTE3
7771 ,ATTRIBUTE4
7772 ,ATTRIBUTE5
7773 ,ATTRIBUTE6
7774 ,ATTRIBUTE7
7775 ,ATTRIBUTE8
7776 ,ATTRIBUTE9
7777 ,ATTRIBUTE10
7778 ,ATTRIBUTE11
7779 ,ATTRIBUTE12
7780 ,ATTRIBUTE13
7781 ,ATTRIBUTE14
7782 ,ATTRIBUTE15
7783 ,ATTRIBUTE_CATEGORY
7784 )
7785 VALUES
7786 (
7787 pConfigId
7788 ,t_organization_id(i)
7789 ,t_cross_ref_type(i)
7790 ,t_cross_ref(i)
7791 ,t_org_independent_flag(i)
7792 ,SYSDATE
7793 ,GUSERID
7794 ,SYSDATE
7795 ,GUSERID
7796 ,GLOGINID
7797 ,NULL --REQUEST_ID
7798 ,NULL --PROGRAM_APPLICATION_ID
7799 ,NULL --PROGRAM_ID
7800 ,SYSDATE --PROGRAM_UPDATE_DATE
7801 ,NULL --SOURCE_SYSTEM_ID
7802 ,1 --OBJECT_VERSION_NUMBER
7803 ,NULL --UOM_CODE due to ER#3215422. do not copy uom_code and revision_id attribute for mtl_cross_references
7804 ,NULL --REVISION_ID due to ER#3215422. do not copy uom_code and revision_id attribute for mtl_cross_references
7805 ,MTL_CROSS_REFERENCES_B_S.NEXTVAL --CROSS_REFERENCE_ID
7806 ,0 --EPC_GTIN_SERIAL
7807 ,NULL --ATTRIBUTE1
7808 ,NULL --ATTRIBUTE2
7809 ,NULL --ATTRIBUTE3
7810 ,NULL --ATTRIBUTE4
7811 ,NULL --ATTRIBUTE5
7812 ,NULL --ATTRIBUTE6
7813 ,NULL --ATTRIBUTE7
7814 ,NULL --ATTRIBUTE8
7815 ,NULL --ATTRIBUTE9
7816 ,NULL --ATTRIBUTE10
7817 ,NULL --ATTRIBUTE11
7818 ,NULL --ATTRIBUTE12
7819 ,NULL --ATTRIBUTE13
7820 ,NULL --ATTRIBUTE14
7821 ,NULL --ATTRIBUTE15
7822 ,NULL --ATTRIBUTE_CATEGORY
7823 );
7824
7825 IF PG_DEBUG <> 0 THEN
7826 oe_debug_pub.add('Create_Item: ' || 'after insert:mtl_cross_references_b',2);
7827 oe_debug_pub.add('Create_Item: ' || '# of inserted rows mtl_cross_references_b'||sql%rowcount,2);
7828
7829 END IF;
7830
7831 INSERT INTO mtl_cross_references_tl (
7832 last_update_login
7833 ,description
7834 ,creation_date
7835 ,created_by
7836 ,last_update_date
7837 ,last_updated_by
7838 ,cross_reference_id
7839 ,language
7840 ,source_lang)
7841 SELECT
7842 gloginid,
7843 mtl.description,
7844 sysdate,
7845 guserid,
7846 sysdate,
7847 guserid,
7848 mtl_cross.cross_reference_id,
7849 l.language_code,
7850 userenv('lang')
7851 FROM fnd_languages l,
7852 mtl_cross_references_b mtl_cross,
7853 mtl_system_items_tl mtl
7854 WHERE mtl_cross.inventory_item_id = pConfigId
7855 AND mtl_cross.inventory_item_id = mtl.inventory_item_id
7856 AND mtl_cross.organization_id = mtl.organization_id
7857 AND l.language_code = mtl.language
7858 AND l.installed_flag in ('I', 'B')
7859 AND NOT EXISTS (SELECT null
7860 FROM mtl_cross_references_tl t
7861 WHERE t.cross_reference_id = mtl_cross.cross_reference_id
7862 AND t.language = l.language_code);
7863
7864
7865
7866 IF PG_DEBUG <> 0 THEN
7867 oe_debug_pub.add('Create_Item: ' || 'after insert:mtl_cross_references_tl',2);
7868 oe_debug_pub.add('Create_Item: ' || '# of inserted rows mtl_cross_references_tl'||sql%rowcount,2);
7869
7870 END IF;
7871
7872
7873 END IF;--cross_reference_type
7874
7875 --end bugfix 4539578
7876
7877 -- start bugfix 2461574
7878
7879 /*--------------------------------------+
7880 Copy Subinventory Defaults
7881 +--------------------------------------*/
7882
7883 lStmtNumber := 301;
7884
7885 insert into mtl_item_sub_defaults
7886 (
7887 inventory_item_id,
7888 organization_id,
7889 subinventory_code,
7890 default_type,
7891 last_update_date,
7892 last_updated_by,
7893 creation_date,
7894 created_by,
7895 last_update_login,
7896 request_id,
7897 program_application_id,
7898 program_id,
7899 program_update_date
7900 )
7901 select distinct
7902 pConfigId,
7903 sd.organization_id,
7904 sd.subinventory_code,
7905 sd.default_type,
7906 sysdate, -- last_update_date
7907 gUserId, -- last_updated_by
7908 sysdate, -- creation_date
7909 gUserId, -- created_by
7910 gLoginId, -- last_update_login
7911 NULL, -- request_id
7912 NULL, -- program_application_id
7913 NULL, -- program_id
7914 SYSDATE -- program_update_date
7915 from
7916 mtl_item_sub_defaults sd,
7917 bom_cto_src_orgs bcso
7918 where sd.organization_id = bcso.organization_id
7919 and sd.inventory_item_id = pModelId
7920 and bcso.model_item_id = pModelId
7921 and bcso.line_id = pLineId
7922 and NOT EXISTS
7923 (select NULL
7924 from mtl_item_sub_defaults
7925 where inventory_item_id = pConfigId
7926 and organization_id = bcso.organization_id);
7927
7928
7929 IF PG_DEBUG <> 0 THEN
7930 oe_debug_pub.add('Create_Item: ' || 'after insert: mtl_item_sub_defaults',2);
7931 END IF;
7932
7933 -- end 2461574
7934 -- start 2786934
7935
7936 /*--------------------------------------+
7937 Copy Locator Defaults
7938 +--------------------------------------*/
7939
7940 lStmtNumber := 302;
7941 insert into mtl_item_loc_defaults
7942 (
7943 inventory_item_id,
7944 organization_id,
7945 locator_id,
7946 default_type,
7947 subinventory_code,
7948 last_update_date,
7949 last_updated_by,
7950 creation_date,
7951 created_by,
7952 last_update_login,
7953 request_id,
7954 program_application_id,
7955 program_id,
7956 program_update_date
7957 )
7958 select distinct
7959 pConfigId,
7960 ld.organization_id,
7961 ld.locator_id,
7962 ld.default_type,
7963 ld.subinventory_code,
7964 sysdate, -- last_update_date
7965 gUserId, -- last_updated_by
7966 sysdate, -- creation_date
7967 gUserId, -- created_by
7968 gLoginId, -- last_update_login
7969 NULL, -- request_id
7970 NULL, -- program_application_id
7971 NULL, -- program_id
7972 SYSDATE -- program_update_date
7973 from
7974 mtl_item_loc_defaults ld,
7975 bom_cto_src_orgs bcso
7976 where ld.organization_id = bcso.organization_id
7977 and ld.inventory_item_id = bcso.model_item_id
7978 and bcso.model_item_id = pModelId
7979 and bcso.line_id = pLineId
7980 and NOT EXISTS
7981 (select NULL
7982 from mtl_item_loc_defaults
7983 where inventory_item_id = pConfigId
7984 and organization_id = ld.organization_id);
7985
7986
7987
7988 IF PG_DEBUG <> 0 THEN
7989 oe_debug_pub.add('Create_Item: ' || 'after insert: mtl_item_loc_defaults',2);
7990 END IF;
7991
7992 -- end 2786934
7993
7994 --satrt bugfix 2828588
7995 --added for 11.5.10 , patchset-J
7996 lStmtNumber := 310;
7997 INSERT INTO mtl_abc_assignments
7998 (
7999 inventory_item_id,
8000 assignment_group_id,
8001 abc_class_id,
8002 last_update_date,
8003 last_updated_by,
8004 creation_date,
8005 created_by
8006 )
8007 select pConfigId,
8008 maa.assignment_group_id,
8009 maa.abc_class_id,
8010 sysdate,
8011 gUserId,
8012 sysdate,
8013 gUserId
8014 FROM mtl_abc_assignments maa
8015 WHERE maa.inventory_item_id = pModelId
8016 --bugfix3536085 not exists condition
8017 AND NOT EXISTS
8018 (SELECT 'X'
8019 FROM mtl_abc_assignments
8020 WHERE inventory_item_id = pConfigId
8021 AND assignment_group_id = maa.assignment_group_id );
8022
8023
8024
8025
8026
8027
8028 IF PG_DEBUG <> 0 THEN
8029
8030 oe_debug_pub.add('Create_Item: ' || 'inserted '||sql%rowcount||' in mtl_abc_assignments',2);
8031
8032 oe_debug_pub.add('Create_Item: ' || 'after insert: mtl_abc_assignments',2);
8033 END IF;
8034
8035 --end bugfix 2828588
8036
8037
8038 return(1);
8039
8040 EXCEPTION
8041
8042 WHEN NO_DATA_FOUND THEN
8043 IF PG_DEBUG <> 0 THEN
8044 oe_debug_pub.add ('Create_Item: ' || 'ERROR: create_item_data::ndf::'||to_char(lStmtNumber)||sqlerrm,1);
8045 END IF;
8046 CTO_MSG_PUB.Count_And_Get(
8047 p_msg_count => lMsgCount,
8048 p_msg_data => lMsgData
8049 );
8050 return(0);
8051
8052 WHEN FND_API.G_EXC_ERROR THEN
8053 IF PG_DEBUG <> 0 THEN
8054 oe_debug_pub.add ('Create_Item: ' || 'ERROR: create_item_data::exp error::'||to_char(lStmtNumber)||sqlerrm,1);
8055 END IF;
8056 CTO_MSG_PUB.Count_And_Get(
8057 p_msg_count => lMsgCount,
8058 p_msg_data => lMsgData
8059 );
8060 return(0);
8061
8062 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8063 IF PG_DEBUG <> 0 THEN
8064 oe_debug_pub.add ('Create_Item: ' || 'ERROR: create_item_data::unexp error::'||to_char(lStmtNumber)||sqlerrm,1);
8065 END IF;
8066 CTO_MSG_PUB.Count_And_Get(
8067 p_msg_count => lMsgCount,
8068 p_msg_data => lMsgData
8069 );
8070 return(0);
8071
8072
8073 WHEN OTHERS THEN
8074 IF PG_DEBUG <> 0 THEN
8075 oe_debug_pub.add ('Create_Item: ' || 'create_item_data::others::'||to_char(lStmtNumber)||sqlerrm,1);
8076 END IF;
8077 CTO_MSG_PUB.Count_And_Get(
8078 p_msg_count => lMsgCount,
8079 p_msg_data => lMsgData
8080 );
8081 return(0);
8082
8083 END create_item_data;
8084
8085
8086 FUNCTION link_item(
8087 pOrgId in number ,
8088 pModelId in number ,
8089 pConfigId in number ,
8090 pLineId in number ,
8091 xMsgCount out NOCOPY number,
8092 xMsgData out NOCOPY varchar2)
8093 RETURN integer
8094 is
8095
8096 lStmtNumber number;
8097 lItemName Varchar2(2000);
8098 l_model_tab oe_order_pub.Line_Tbl_Type;
8099 l_line_rec oe_order_pub.Line_Rec_type;
8100
8101 l_msg_count number;
8102 l_msg_data varchar2(2000);
8103 l_return_status varchar2(1) := FND_API.G_RET_STS_SUCCESS;
8104 l_header_rec oe_order_pub.Header_Rec_Type;
8105 l_header_val_rec oe_order_pub.Header_Val_Rec_Type ;
8106 l_Header_Adj_tbl oe_order_pub.Header_Adj_Tbl_Type;
8107 l_Header_Adj_val_tbl oe_order_pub.Header_Adj_Val_Tbl_Type;
8108 l_Header_price_Att_tbl oe_order_pub.Header_Price_Att_Tbl_Type;
8109 l_Header_Adj_Att_tbl oe_order_pub.Header_Adj_Att_Tbl_Type;
8110 l_Header_Adj_Assoc_tbl oe_order_pub.Header_Adj_Assoc_Tbl_Type;
8111 l_Header_Scredit_tbl oe_order_pub.Header_Scredit_Tbl_Type;
8112 l_Header_Scredit_val_tbl oe_order_pub.Header_Scredit_Val_Tbl_Type;
8113 l_line_tbl oe_order_pub.Line_Tbl_Type;
8114 l_line_val_tbl oe_order_pub.Line_Val_Tbl_Type;
8115 l_Line_Adj_tbl oe_order_pub.Line_Adj_Tbl_Type;
8116 l_Line_Adj_val_tbl oe_order_pub.Line_Adj_Val_Tbl_Type;
8117 l_Line_price_Att_tbl oe_order_pub.Line_Price_Att_Tbl_Type;
8118 l_Line_Adj_Att_tbl oe_order_pub.Line_Adj_Att_Tbl_Type;
8119 l_Line_Adj_Assoc_tbl oe_order_pub.Line_Adj_Assoc_Tbl_Type;
8120 l_Line_Scredit_tbl oe_order_pub.Line_Scredit_Tbl_Type ;
8121 l_Line_Scredit_val_tbl oe_order_pub.Line_Scredit_Val_Tbl_Type;
8122 l_Lot_Serial_tbl oe_order_pub.Lot_Serial_Tbl_Type;
8123 l_Lot_Serial_val_tbl oe_order_pub.Lot_Serial_Val_Tbl_Type;
8124 l_action_request_tbl oe_order_pub.Request_Tbl_Type;
8125
8126 l_config_line_id number;
8127 l_config_id number;
8128 lLinkLineId number;
8129 l_stat number;
8130
8131 --Begin Bugfix 1997355
8132
8133 index_counter_link number;
8134 p_config_line_arr_link MRP_OM_API_PK.line_id_tbl;
8135 l_return_status_link varchar2(1);
8136
8137 --End Bugfix 1997355
8138
8139
8140 gUserId number;
8141 gLoginId number;
8142
8143 l_upd_line_tbl oe_order_pub.Line_Tbl_Type;
8144 l_upd_line_rec oe_order_pub.Line_Rec_type;
8145 l_option_line_id number;
8146 i number;
8147 x number;
8148 y varchar(1);
8149 z varchar(30);
8150 l_vdflag varchar(1);
8151 l_header_id oe_order_lines_all.header_id%type;
8152
8153 --
8154 --bugfix 2840801
8155 --
8156 l_x_hold_result_out Varchar2(30);
8157 l_x_hold_return_status Varchar2(30);
8158 l_x_error_msg_count Number;
8159 l_x_error_msg Varchar2(2000);
8160 l_hold_source_rec OE_Holds_PVT.Hold_Source_REC_type;
8161
8162 v_schedule_status_code oe_order_lines_all.schedule_status_code%type ;
8163 v_booked_flag oe_order_lines_all.booked_flag%type ;
8164 v_hold_id number ;
8165
8166 BEGIN
8167
8168 gUserId := nvl(Fnd_Global.USER_ID,-1);
8169 gLoginId := nvl(Fnd_Global.LOGIN_ID,-1);
8170
8171
8172 --
8173 -- check if config item already exists
8174 --
8175 IF (CTO_MATCH_AND_RESERVE.config_line_exists(
8176 p_model_line_id => pLineId,
8177 x_config_line_id => l_config_line_id,
8178 x_config_item_id => l_config_id) = TRUE)
8179 THEN
8180 IF PG_DEBUG <> 0 THEN
8181 oe_debug_pub.add('link_item: ' || 'Config Line Exists, do not link', 1);
8182 END IF;
8183 return(1);
8184 END IF;
8185
8186
8187 IF PG_DEBUG <> 0 THEN
8188 oe_debug_pub.add ('link_item: ' || 'calling oe_line_util.query_row , 2');
8189 END IF;
8190
8191 Select concatenated_segments
8192 into l_model_tab(1).ordered_item
8193 from mtl_system_items_b_kfv
8194 where inventory_item_id = pConfigId
8195 and organization_id = pOrgId;
8196
8197 lStmtNumber := 395;
8198 l_line_rec := oe_line_util.query_row(pLineId);
8199
8200 /*-----------------------------------------------------------+
8201 Setting visible demand flag to 'N' for the selected model and options.
8202 +-----------------------------------------------------------*/
8203 --
8204 -- selecting all rows to be updated into l_upd_line_tbl
8205 --
8206 IF PG_DEBUG <> 0 THEN
8207 oe_debug_pub.add ('link_item: ' || 'link : visible demand flag : before selecting options ', 2);
8208 END IF;
8209
8210
8211 /* BUG#2234858 Sushant added this for Drop Ship project
8212 ** Need to provide this functionality for non drop shipped items only
8213 */
8214
8215 IF PG_DEBUG <> 0 THEN
8216 oe_debug_pub.add('link_item: ' || 'Before visible demand flag souce type code = '||l_line_rec.source_type_code,1);
8217 END IF;
8218 if( l_line_rec.source_type_code = 'INTERNAL') then
8219
8220
8221
8222 lStmtNumber := 380;
8223
8224 -- The following update statement is added by Renga Kannan on 04/04/2001.
8225 -- The previous process order API is replaced with this update statement for performance purpose.
8226
8227
8228 IF PG_DEBUG <> 0 THEN
8229 oe_debug_pub.add('link_item: ' || 'Before updating visible demand Flag...',1);
8230
8231 oe_debug_pub.add('link_item: ' || ' ATO line id = '||to_char(plineid),1);
8232 END IF;
8233
8234 UPDATE OE_ORDER_LINES_ALL
8235 SET visible_demand_flag = 'N'
8236 WHERE ato_line_id = pLineId;
8237
8238 IF PG_DEBUG <> 0 THEN
8239 oe_debug_pub.add('link_item: ' || 'after updating visible demand flag..',1);
8240
8241 oe_debug_pub.add('link_item: ' || 'No of rows updated = '||sql%rowcount,1);
8242 END IF;
8243
8244 -- End of adition on 04/04/2001
8245
8246 end if ;
8247 /* BUG#2234858 Sushant added this for Drop Ship project */
8248
8249 l_model_tab(1) := OE_ORDER_PUB.G_MISS_LINE_REC;
8250 l_model_tab(1).operation := OE_Globals.G_OPR_CREATE;
8251 l_model_tab(1).inventory_item_id := pConfigId;
8252 l_model_tab(1).item_type_code := OE_Globals.G_ITEM_CONFIG;
8253 l_model_tab(1).ordered_quantity := l_line_rec.ordered_quantity;
8254 l_model_tab(1).order_quantity_uom := l_line_rec.order_quantity_uom;
8255 l_model_tab(1).ship_from_org_id := l_line_rec.ship_from_org_id ;
8256 l_model_tab(1).org_id := l_line_rec.org_id ;
8257 l_model_tab(1).source_type_code := l_line_rec.source_type_code;
8258 l_model_tab(1).request_date := l_line_rec.request_date;
8259 l_model_tab(1).schedule_status_code := l_line_rec.schedule_status_code;
8260 l_model_tab(1).schedule_ship_date := l_line_rec.schedule_ship_date;
8261
8262
8263 /* BUG#2234858 Sushant added this for Drop Ship project */
8264 if( l_line_rec.source_type_code = 'INTERNAL' ) then
8265 l_model_tab(1).visible_demand_flag := 'Y';
8266
8267 else
8268
8269 l_model_tab(1).visible_demand_flag := 'N';
8270 end if ;
8271 /* BUG#2234858 Sushant added this for Drop Ship project */
8272
8273
8274 l_model_tab(1).header_id := l_line_rec.header_id;
8275 /*
8276 commented as per gayatri
8277 l_model_tab(1).config_header_id := l_line_rec.config_header_id;
8278 l_model_tab(1).config_rev_nbr := l_line_rec.config_rev_nbr;
8279 */
8280 l_model_tab(1).model_group_number := l_line_rec.model_group_number;
8281 l_model_tab(1).line_number := l_line_rec.line_number;
8282 l_model_tab(1).shipment_number := l_line_rec.shipment_number;
8283 l_model_tab(1).link_to_line_id := l_line_rec.line_id;
8284 l_model_tab(1).ato_line_id := l_line_rec.line_id;
8285 l_model_tab(1).top_model_line_id := l_line_rec.top_model_line_id;
8286 --changed to top_model_line_id from line_id to support Pto-ATO models
8287 l_model_tab(1).component_code := l_line_rec.component_code || pConfigId;
8288 l_model_tab(1).option_flag := 'Y';
8289 --l_model_tab(1).ordered_item := lItemName;
8290 l_model_tab(1).item_identifier_type := 'INT'; -- Must pass for validation
8291
8292 l_model_tab(1).change_reason := 'SYSTEM'; -- bug 3854182 for order versioning
8293
8294 /* bugfix 2887782 : copy the context and attribute cols from base model */
8295 l_model_tab(1).context := l_line_rec.context;
8296 l_model_tab(1).attribute1 := l_line_rec.attribute1;
8297 l_model_tab(1).attribute2 := l_line_rec.attribute2;
8298 l_model_tab(1).attribute3 := l_line_rec.attribute3;
8299 l_model_tab(1).attribute4 := l_line_rec.attribute4;
8300 l_model_tab(1).attribute5 := l_line_rec.attribute5;
8301 l_model_tab(1).attribute6 := l_line_rec.attribute6;
8302 l_model_tab(1).attribute7 := l_line_rec.attribute7;
8303 l_model_tab(1).attribute8 := l_line_rec.attribute8;
8304 l_model_tab(1).attribute9 := l_line_rec.attribute9;
8305 l_model_tab(1).attribute10 := l_line_rec.attribute10;
8306 l_model_tab(1).attribute11 := l_line_rec.attribute11;
8307 l_model_tab(1).attribute12 := l_line_rec.attribute12;
8308 l_model_tab(1).attribute13 := l_line_rec.attribute13;
8309 l_model_tab(1).attribute14 := l_line_rec.attribute14;
8310 l_model_tab(1).attribute15 := l_line_rec.attribute15;
8311 --Bugfix 6633913: Copying these attributes to config line
8312 l_model_tab(1).attribute16 := l_line_rec.attribute16;
8313 l_model_tab(1).attribute17 := l_line_rec.attribute17;
8314 l_model_tab(1).attribute18 := l_line_rec.attribute18;
8315 l_model_tab(1).attribute19 := l_line_rec.attribute19;
8316 l_model_tab(1).attribute20 := l_line_rec.attribute20;
8317
8318 /*
8319 l_model_tab(1).option_number := '0';
8320 This line commented as per gayatri to fix bug#2300006 to handle usability issues for multiple
8321 instantiation.
8322 */
8323 l_model_tab(1).option_number := l_line_rec.option_number ; /* Fix for BUG#2300006 */
8324
8325 l_model_tab(1).component_number := '0';/* Fix for BUG#2300006 added later on 04-16-2002 after talking to gayatri*/
8326
8327
8328
8329 l_model_tab(1).dep_plan_required_flag := l_line_rec.dep_plan_required_flag;
8330
8331
8332 IF PG_DEBUG <> 0 THEN
8333 oe_debug_pub.add ('link_item: ' || 'linking item ' || l_model_tab(1).ordered_item, 2);
8334 END IF;
8335
8336 lStmtNumber := 400;
8337 /*
8338 -- bugfix 2503104: Get the user_item_description information also
8339
8340 select nvl(component_code, oel.inventory_item_id) || '-'|| to_char(pConfigId),
8341 substrb(user_item_Description,1,240)
8342 into l_model_tab(1).component_code,
8343 l_model_tab(1).user_item_description
8344 from oe_order_lines_all oel
8345 where oel.line_id = pLineId
8346 and oel.ship_from_org_id = pOrgId;
8347 */
8348 -- bugfix 2503104: Revert this fix as OM will now populate
8349 -- user_item_description of config item. This will eliminate
8350 -- any compile time dependency between OM and CTO for this issue.
8351
8352 select nvl(component_code, oel.inventory_item_id) || '-'|| to_char(pConfigId)
8353 into l_model_tab(1).component_code
8354 from oe_order_lines_all oel
8355 where oel.line_id = pLineId
8356 and oel.ship_from_org_id = pOrgId;
8357
8358 lStmtNumber := 410;
8359
8360 IF PG_DEBUG <> 0 THEN
8361 oe_debug_pub.add ('link_item: ' || 'calling oe_order_grp.Process_order', 2);
8362 END IF;
8363 -- Change for MOAC
8364 -- Changing the public process order API to group API
8365 oe_order_grp.Process_Order (
8366 p_api_version_number =>1.0,
8367 x_return_status => l_return_status,
8368 x_msg_count => l_msg_count,
8369 x_msg_data => l_msg_data,
8370 p_line_tbl => l_model_tab,
8371 x_header_rec => l_header_rec,
8372 x_header_val_rec => l_header_val_rec,
8373 x_Header_Adj_tbl => l_header_Adj_tbl,
8374 x_Header_Adj_val_tbl => l_header_Adj_val_tbl,
8375 x_Header_price_Att_tbl => l_header_price_att_tbl,
8376 x_Header_Adj_Att_tbl => l_header_adj_att_tbl,
8377 x_Header_Adj_Assoc_tbl => l_header_adj_Assoc_tbl,
8378 x_Header_Scredit_tbl => l_header_Scredit_tbl,
8379 x_Header_Scredit_val_tbl => l_header_scredit_val_tbl,
8380 x_line_tbl => l_line_tbl,
8381 x_line_val_tbl => l_line_val_tbl,
8382 x_Line_Adj_tbl => l_line_adj_tbl,
8383 x_Line_Adj_val_tbl => l_line_adj_val_tbl,
8384 x_Line_price_Att_tbl => l_line_price_Att_tbl,
8385 x_Line_Adj_Att_tbl => l_line_adj_att_tbl,
8386 x_Line_Adj_Assoc_tbl => l_line_adj_Assoc_tbl,
8387 x_Line_Scredit_tbl => l_line_scredit_tbl,
8388 x_Line_Scredit_val_tbl => l_line_scredit_val_tbl,
8389 x_Lot_Serial_tbl => l_lot_serial_tbl,
8390 x_Lot_Serial_val_tbl => l_lot_serial_val_tbl,
8391 x_action_request_tbl => l_action_request_tbl
8392 );
8393
8394 IF PG_DEBUG <> 0 THEN
8395 oe_debug_pub.add ('link_item: ' || 'Process_order returned ' || l_return_status, 1);
8396
8397 oe_debug_pub.add ('link_item: ' || 'Process_order returned ' || l_msg_data, 2);
8398 END IF;
8399
8400 if (l_return_status = FND_API.G_RET_STS_ERROR) then
8401 IF PG_DEBUG <> 0 THEN
8402 oe_debug_pub.add ('link_item: ' || 'Process_order returned expected error :'||l_msg_data,1);
8403 END IF;
8404 raise FND_API.G_EXC_ERROR;
8405
8406 elsif (l_return_status = FND_API.G_RET_STS_ERROR) then
8407 IF PG_DEBUG <> 0 THEN
8408 oe_debug_pub.add ('link_item: ' || 'Process_order returned unexpected error :'||l_msg_data,1);
8409 END IF;
8410 raise FND_API.G_EXC_UNEXPECTED_ERROR;
8411
8412 end if;
8413
8414 oe_globals.g_cascading_request_logged := TRUE;
8415
8416
8417
8418 /* BUG#2234858 Sushant added this for Drop Ship project */
8419 if( l_line_rec.source_type_code = 'INTERNAL' ) then
8420
8421
8422
8423
8424 lStmtNumber := 420;
8425 l_stat := chk_model_in_bcod(pLineId);
8426
8427 --set demand_visible flag in BCOD to 'N' so that only CID demand is visible to
8428 --planning and not of BOM
8429
8430 if(l_stat = 1)then
8431
8432
8433
8434
8435
8436 /* Not Required for Patcshet J */
8437 /*
8438 lStmtNumber := 430;
8439 update bom_cto_order_demand
8440 set demand_visible = 'N'
8441 where ato_line_id =pLineId;
8442
8443 --adding the CID row to BCOD table
8444
8445 lStmtNumber := 440;
8446 insert into bom_cto_order_demand(
8447 bcod_line_id,
8448 oe_line_id,
8449 ato_line_id,
8450 inventory_item_id,
8451 organization_id,
8452 required_date,
8453 required_qty,
8454 order_quantity_uom,
8455 parent_demand_type,
8456 header_id,
8457 forecast_visible,
8458 demand_visible,
8459 created_by,
8460 last_updated_by,
8461 last_updated_date,
8462 last_update_login,
8463 program_application_id,
8464 program_update_date
8465 )
8466 select
8467 BOM_CTO_ORDER_DEMAND_S1.nextval,
8468 line_id,
8469 pLineId,
8470 pConfigId,
8471 pOrgId,
8472 schedule_ship_date,
8473 ordered_quantity,
8474 order_quantity_uom,
8475 1,
8476 header_id,
8477 'N',
8478 'Y',
8479 gUserId,
8480 gUserId,
8481 sysdate,
8482 gLoginId,
8483 null,
8484 sysdate
8485 from oe_order_lines_all
8486 where ato_line_id=pLineId
8487 and inventory_item_id=pConfigId;
8488
8489 */
8490
8491 null ;
8492
8493
8494 elsif(l_stat =0) then
8495 -- do nothing
8496 IF PG_DEBUG <> 0 THEN
8497 oe_debug_pub.add ('link_item: ' || 'no model line present in bcod table to create a CID,not an error', 3);
8498 END IF;
8499
8500 end if;
8501
8502
8503
8504 end if ;
8505 /* BUG#2234858 Sushant added this for Drop Ship project */
8506
8507
8508
8509 --Begin Bugfix 1997355
8510
8511 lStmtNumber := 450;
8512 select line_id, header_id -- bugfix 2840801 : added header_id
8513 into l_config_line_id, l_header_id
8514 from oe_order_lines_all oel
8515 where ato_line_id = pLineId
8516 and inventory_item_id = pConfigId
8517 and item_type_code = 'CONFIG';
8518
8519 index_counter_link:= 1;
8520 p_config_line_arr_link(index_counter_link) := l_config_line_id ;
8521
8522 IF PG_DEBUG <> 0 THEN
8523 oe_debug_pub.add('link_item: ' || 'Start MRP package for link', 1);
8524 END IF;
8525
8526 MRP_OM_API_PK.MRP_OM_Interface
8527 (p_line_tbl => p_config_line_arr_link,
8528 x_return_status => l_return_status_link);
8529
8530 IF PG_DEBUG <> 0 THEN
8531 oe_debug_pub.add ('link_item: ' || 'Return status from MRP_OM_Interface - Link: '||l_return_status_link,2);
8532 END IF;
8533
8534 if l_return_status_link = FND_API.G_RET_STS_ERROR then
8535 IF PG_DEBUG <> 0 THEN
8536 oe_debug_pub.add ('link_item: ' || 'Failed in MRP_OM_API_PK.mrp_om_interface with expected error.', 1);
8537 END IF;
8538 raise FND_API.G_EXC_ERROR;
8539
8540 elsif l_return_status_link = FND_API.G_RET_STS_UNEXP_ERROR then
8541 IF PG_DEBUG <> 0 THEN
8542 oe_debug_pub.add ('link_item: ' || 'Failed in MRP_OM_API_PK.mrp_om_interface with unexpected error.', 1);
8543 END IF;
8544 raise FND_API.G_EXC_UNEXPECTED_ERROR;
8545 end if;
8546
8547 -- End Bugfix 1997355
8548
8549 --
8550 -- Begin bugfix 2840801
8551 -- If any optional components are dropped while creating bill for config item,
8552 -- we will put a hold on the config-line.
8553 -- The global variable gApplyHold is set in CTOCBOMB.pls
8554 --
8555
8556 if (CTO_CONFIG_BOM_PK.gApplyHold = 'Y') then
8557 IF PG_DEBUG <> 0 THEN
8558 oe_debug_pub.add ('CTOCITMB:Need to put hold on config line '||l_config_line_id);
8559 END IF;
8560
8561 /* Put the config line on Hold. But first, check to see if a hold already exists
8562 on this line */
8563
8564 OE_HOLDS_PUB.Check_Holds (
8565 p_api_version => 1.0
8566 ,p_line_id => l_config_line_id
8567 ,x_result_out => l_x_hold_result_out
8568 ,x_return_status => l_x_hold_return_status
8569 ,x_msg_count => l_x_error_msg_count
8570 ,x_msg_data => l_x_error_msg);
8571
8572 IF (l_x_hold_return_status = FND_API.G_RET_STS_ERROR) THEN
8573 IF PG_DEBUG <> 0 THEN
8574 oe_debug_pub.add('CTOCITMB:Failed in Check Holds with expected error.' ,1);
8575 END IF;
8576 raise FND_API.G_EXC_ERROR;
8577
8578 ELSIF (l_x_hold_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
8579 IF PG_DEBUG <> 0 THEN
8580 oe_debug_pub.add('CTOCITMB:Failed in Check Holds with unexpected error.' ,1);
8581 END IF;
8582 raise FND_API.G_EXC_UNEXPECTED_ERROR;
8583
8584 ELSE
8585 IF PG_DEBUG <> 0 THEN
8586 oe_debug_pub.add('CTOCITMB:Success in Check Holds.' ,1);
8587 END IF;
8588 if l_x_hold_result_out = FND_API.G_FALSE then
8589
8590
8591
8592 select schedule_status_code , booked_flag into v_schedule_Status_code , v_booked_flag
8593 from oe_order_lines_all
8594 where line_id = pLineId ;
8595
8596
8597
8598 if( v_schedule_status_code = 'SCHEDULED' and v_booked_flag = 'Y' ) then
8599
8600 v_hold_id := 55 ;
8601
8602 IF PG_DEBUG <> 0 THEN
8603 oe_debug_pub.add('CTOCITMB: Going to apply normal hold .' ,1);
8604 END IF;
8605
8606 else
8607
8608 v_hold_id := 61 ; /* New Hold Id for Create Supply Activity Hold , Should be changed from 1063 to 61 after Gayatri gives the script*/
8609
8610 IF PG_DEBUG <> 0 THEN
8611 oe_debug_pub.add('CTOCITMB: Going to apply create supply activity hold .' ,1);
8612 END IF;
8613
8614 end if;
8615
8616
8617
8618
8619 IF PG_DEBUG <> 0 THEN
8620 oe_debug_pub.add('CTOCITMB:Calling OM api to apply hold.' ,1);
8621 END IF;
8622
8623 l_hold_source_rec.hold_entity_code := 'O';
8624 l_hold_source_rec.hold_id := v_hold_id ;
8625 l_hold_source_rec.hold_entity_id := l_header_id;
8626 l_hold_source_rec.header_id := l_header_id;
8627 l_hold_source_rec.line_id := l_config_line_id;
8628
8629 OE_Holds_PUB.Apply_Holds (
8630 p_api_version => 1.0
8631 , p_hold_source_rec => l_hold_source_rec
8632 , x_return_status => l_return_status
8633 , x_msg_count => l_msg_count
8634 , x_msg_data => l_msg_data);
8635
8636 IF (l_return_status = FND_API.G_RET_STS_ERROR) THEN
8637 IF PG_DEBUG <> 0 THEN
8638 oe_debug_pub.add('CTOCITMB:Failed in Apply Holds with expected error.' ,1);
8639 END IF;
8640 raise FND_API.G_EXC_ERROR;
8641
8642 ELSIF (l_return_status = FND_API.G_RET_STS_UNEXP_ERROR) THEN
8643 IF PG_DEBUG <> 0 THEN
8644 oe_debug_pub.add('CTOCITMB:Failed in Apply Holds with unexpected error.' ,1);
8645 END IF;
8646 raise FND_API.G_EXC_UNEXPECTED_ERROR;
8647 END IF;
8648
8649 IF PG_DEBUG <> 0 THEN
8650 oe_debug_pub.add('CTOCITMB: An Exception Hold applied to config line.' ,1);
8651 END IF;
8652 cto_msg_pub.cto_message('BOM','CTO_ORDER_LINE_EXCPN_HOLD');
8653
8654 else
8655 IF PG_DEBUG <> 0 THEN
8656 oe_debug_pub.add('CTOCITMB: Line is already on Hold.' ,1);
8657 END IF;
8658 end if;
8659 END IF;
8660 end if;
8661 --
8662 -- End bugfix 2840801
8663 --
8664
8665
8666 return (1);
8667
8668 EXCEPTION
8669
8670 WHEN NO_DATA_FOUND THEN
8671 IF PG_DEBUG <> 0 THEN
8672 oe_debug_pub.add ('link_item: ' || 'ERROR: link_item::ndf::'||to_char(lStmtNumber)||'::'||sqlerrm, 1);
8673 END IF;
8674 CTO_MSG_PUB.Count_And_Get(
8675 p_msg_count => l_Msg_Count,
8676 p_msg_data => l_Msg_Data
8677 );
8678 return(0);
8679
8680 WHEN FND_API.G_EXC_ERROR THEN
8681 IF PG_DEBUG <> 0 THEN
8682 oe_debug_pub.add ('link_item: ' || 'ERROR: link_item::exp error::'||to_char(lStmtNumber)||sqlerrm, 1);
8683 END IF;
8684 CTO_MSG_PUB.Count_And_Get(
8685 p_msg_count => l_Msg_Count,
8686 p_msg_data => l_Msg_Data
8687 );
8688 return(0);
8689
8690 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8691 IF PG_DEBUG <> 0 THEN
8692 oe_debug_pub.add ('link_item: ' || 'ERROR: link_item::unexp error::'||to_char(lStmtNumber)||sqlerrm, 1);
8693 END IF;
8694 CTO_MSG_PUB.Count_And_Get(
8695 p_msg_count => l_Msg_Count,
8696 p_msg_data => l_Msg_Data
8697 );
8698 return(0);
8699
8700 WHEN OTHERS THEN
8701 IF PG_DEBUG <> 0 THEN
8702 oe_debug_pub.add ('link_item: ' || 'ERROR: link_item::others::'||to_char(lStmtNumber)||'::'||sqlerrm, 1);
8703 END IF;
8704 CTO_MSG_PUB.Count_And_Get(
8705 p_msg_count => l_Msg_Count,
8706 p_msg_data => l_Msg_Data
8707 );
8708 return(0);
8709 END link_item;
8710
8711 /*****************************************************************************
8712 chk_model_in_bcod
8713 bcod implies BOM CTO ORDER DEMAND
8714 checks if model is there in BOM CTO ORDER DEMAND table before the creation of row for configured item in the BOM CTO ORDER DEMAND table. This function is being called from link_item()function
8715 *****************************************************************************/
8716
8717 FUNCTION chk_model_in_bcod(
8718 pLineId in number)
8719 RETURN integer
8720 is
8721 l_dummy number;
8722 BEGIN
8723 select oe_line_id into l_dummy
8724 from bom_cto_order_demand
8725 where oe_line_id=pLineId;
8726 return (1);
8727 EXCEPTION
8728 when no_data_found then
8729 return (0);
8730 END chk_model_in_bcod;
8731
8732
8733 --
8734 -- bugfix 2706981: Created a new API for performance reasons.
8735 -- This API would check if a duplicate item name exists.
8736 -- It returns 1 if duplicate exists. Else, it returns 0.
8737 --
8738
8739 FUNCTION check_dup_item(
8740 pSegment1 varchar2,
8741 pSegment2 varchar2,
8742 pSegment3 varchar2,
8743 pSegment4 varchar2,
8744 pSegment5 varchar2,
8745 pSegment6 varchar2,
8746 pSegment7 varchar2,
8747 pSegment8 varchar2,
8748 pSegment9 varchar2,
8749 pSegment10 varchar2,
8750 pSegment11 varchar2,
8751 pSegment12 varchar2,
8752 pSegment13 varchar2,
8753 pSegment14 varchar2,
8754 pSegment15 varchar2,
8755 pSegment16 varchar2,
8756 pSegment17 varchar2,
8757 pSegment18 varchar2,
8758 pSegment19 varchar2,
8759 pSegment20 varchar2)
8760 RETURN number is
8761
8762 sql_str varchar2(2000);
8763 lcursor integer;
8764 xdummy number;
8765 rows_processed number;
8766
8767 BEGIN
8768
8769 IF PG_DEBUG <> 0 THEN
8770 oe_debug_pub.add( 'Check_dup_item: '|| 'Checking for duplicate item name.. ' ,2 );
8771 END IF;
8772
8773 sql_str := 'select 1 from mtl_system_items msi where 1=1 ';
8774
8775 if pSegment1 is not null then
8776 sql_str := sql_str||' and msi.segment1 = :pSegment1';
8777 end if;
8778
8779 if pSegment2 is not null then
8780 sql_str := sql_str||' and msi.segment2 = :pSegment2';
8781 end if;
8782
8783 if pSegment3 is not null then
8784 sql_str := sql_str||' and msi.segment3 = :pSegment3';
8785 end if;
8786
8787 if pSegment4 is not null then
8788 sql_str := sql_str||' and msi.segment4 = :pSegment4';
8789 end if;
8790
8791 if pSegment5 is not null then
8792 sql_str := sql_str||' and msi.segment5 = :pSegment5';
8793 end if;
8794
8795 if pSegment6 is not null then
8796 sql_str := sql_str||' and msi.segment6 = :pSegment6';
8797 end if;
8798
8799 if pSegment7 is not null then
8800 sql_str := sql_str||' and msi.segment7 = :pSegment7';
8801 end if;
8802
8803 if pSegment8 is not null then
8804 sql_str := sql_str||' and msi.segment8 = :pSegment8';
8805 end if;
8806
8807 if pSegment9 is not null then
8808 sql_str := sql_str||' and msi.segment9 = :pSegment9';
8809 end if;
8810
8811 if pSegment10 is not null then
8812 sql_str := sql_str||' and msi.segment10 = :pSegment10';
8813 end if;
8814
8815 if pSegment11 is not null then
8816 sql_str := sql_str||' and msi.segment11 = :pSegment11';
8817 end if;
8818
8819 if pSegment12 is not null then
8820 sql_str := sql_str||' and msi.segment12 = :pSegment12';
8821 end if;
8822
8823 if pSegment13 is not null then
8824 sql_str := sql_str||' and msi.segment13 = :pSegment13';
8825 end if;
8826
8827 if pSegment14 is not null then
8828 sql_str := sql_str||' and msi.segment14 = :pSegment14';
8829 end if;
8830
8831 if pSegment15 is not null then
8832 sql_str := sql_str||' and msi.segment15 = :pSegment15';
8833 end if;
8834
8835 if pSegment16 is not null then
8836 sql_str := sql_str||' and msi.segment16 = :pSegment16';
8837 end if;
8838
8839 if pSegment17 is not null then
8840 sql_str := sql_str||' and msi.segment17 = :pSegment17';
8841 end if;
8842
8843 if pSegment18 is not null then
8844 sql_str := sql_str||' and msi.segment18 = :pSegment18';
8845 end if;
8846
8847 if pSegment19 is not null then
8848 sql_str := sql_str||' and msi.segment19 = :pSegment19';
8849 end if;
8850
8851 if pSegment20 is not null then
8852 sql_str := sql_str||' and msi.segment20 = :pSegment20';
8853 end if;
8854
8855
8856 IF PG_DEBUG <> 0 THEN
8857 oe_debug_pub.add( 'Check_dup_item: '||'sql_str : '||sql_str, 3);
8858 END IF;
8859
8860 lcursor := dbms_sql.open_cursor;
8861
8862 dbms_sql.parse(lcursor, sql_str, dbms_sql.native);
8863
8864 if pSegment1 is not null then
8865 dbms_sql.bind_variable(lcursor,'pSegment1', pSegment1);
8866 end if;
8867 if pSegment2 is not null then
8868 dbms_sql.bind_variable(lcursor,'pSegment2', pSegment2);
8869 end if;
8870 if pSegment3 is not null then
8871 dbms_sql.bind_variable(lcursor,'pSegment3', pSegment3);
8872 end if;
8873 if pSegment4 is not null then
8874 dbms_sql.bind_variable(lcursor,'pSegment4', pSegment4);
8875 end if;
8876 if pSegment5 is not null then
8877 dbms_sql.bind_variable(lcursor,'pSegment5', pSegment5);
8878 end if;
8879 if pSegment6 is not null then
8880 dbms_sql.bind_variable(lcursor,'pSegment6', pSegment6);
8881 end if;
8882 if pSegment7 is not null then
8883 dbms_sql.bind_variable(lcursor,'pSegment7', pSegment7);
8884 end if;
8885 if pSegment8 is not null then
8886 dbms_sql.bind_variable(lcursor,'pSegment8', pSegment8);
8887 end if;
8888 if pSegment9 is not null then
8889 dbms_sql.bind_variable(lcursor,'pSegment9', pSegment9);
8890 end if;
8891 if pSegment10 is not null then
8892 dbms_sql.bind_variable(lcursor,'pSegment10', pSegment10);
8893 end if;
8894 if pSegment11 is not null then
8895 dbms_sql.bind_variable(lcursor,'pSegment11', pSegment11);
8896 end if;
8897 if pSegment12 is not null then
8898 dbms_sql.bind_variable(lcursor,'pSegment12', pSegment12);
8899 end if;
8900 if pSegment13 is not null then
8901 dbms_sql.bind_variable(lcursor,'pSegment13', pSegment13);
8902 end if;
8903 if pSegment14 is not null then
8904 dbms_sql.bind_variable(lcursor,'pSegment14', pSegment14);
8905 end if;
8906 if pSegment15 is not null then
8907 dbms_sql.bind_variable(lcursor,'pSegment15', pSegment15);
8908 end if;
8909 if pSegment16 is not null then
8910 dbms_sql.bind_variable(lcursor,'pSegment16', pSegment16);
8911 end if;
8912 if pSegment17 is not null then
8913 dbms_sql.bind_variable(lcursor,'pSegment17', pSegment17);
8914 end if;
8915 if pSegment18 is not null then
8916 dbms_sql.bind_variable(lcursor,'pSegment18', pSegment18);
8917 end if;
8918 if pSegment19 is not null then
8919 dbms_sql.bind_variable(lcursor,'pSegment19', pSegment19);
8920 end if;
8921 if pSegment20 is not null then
8922 dbms_sql.bind_variable(lcursor,'pSegment20', pSegment20);
8923 end if;
8924
8925 dbms_sql.define_column(lcursor, 1, xdummy);
8926
8927 rows_processed := dbms_sql.execute_and_fetch(lcursor);
8928
8929 dbms_sql.close_cursor(lcursor);
8930
8931 if rows_processed > 0 then
8932 IF PG_DEBUG <> 0 THEN
8933 oe_debug_pub.add( 'Check_dup_item: '||'Duplicate item name found.');
8934 END IF;
8935 return 1;
8936 else
8937 IF PG_DEBUG <> 0 THEN
8938 oe_debug_pub.add( 'Check_dup_item: '||'Duplicate item name NOT found.');
8939 END IF;
8940 return 0;
8941 end if;
8942
8943 END check_dup_item;
8944
8945
8946 --
8947 -- bugfix 3026929: local API for dynamic insert.
8948 --
8949
8950 PROCEDURE populate_item_revision(pConfigId number,
8951 pModelId number,
8952 pLineId number,
8953 xReturnStatus OUT NOCOPY varchar2) is
8954
8955 --sql_stmt varchar2(4000); Bugfix 6063990
8956 stmtnum number;
8957 x_item_rev_seq number ;
8958
8959 BEGIN
8960 xReturnStatus := fnd_api.G_RET_STS_SUCCESS;
8961
8962 stmtnum := 1;
8963
8964 IF PG_DEBUG <> 0 THEN --Bugfix 6063990
8965 oe_debug_pub.add('Inside populate_item_revision');
8966 END IF;
8967 --sql_stmt := 'SELECT MTL_ITEM_REVISIONS_B_S.nextval FROM dual';
8968
8969 --IF PG_DEBUG <> 0 THEN
8970 -- oe_debug_pub.add(sql_stmt,3);
8971 --END IF;
8972
8973 --EXECUTE IMMEDIATE sql_stmt INTO x_item_rev_seq ;
8974
8975 --IF PG_DEBUG <> 0 THEN
8976 -- oe_debug_pub.add(' x_item_rev_seq = '|| x_item_rev_seq ,1);
8977
8978 -- END IF;
8979
8980 --3340844 joing to mp2 and distinct has been removed
8981 stmtnum := 2;
8982 /*Bugfix 5851244: As Release 11.5.10 was shipped as one SCM patch,
8983 we are assuming that customers will always be on ITEMS 11.5.10 data model i.e. they will have tables _B and _TL.
8984 So changing dynamic sql into static sql */
8985
8986 --sql_stmt :=
8987 insert into mtl_item_revisions_b
8988 (inventory_item_id,
8989 organization_id,
8990 revision,
8991 last_update_date,
8992 last_updated_by,
8993 creation_date,
8994 created_by,
8995 last_update_login,
8996 implementation_date,
8997 effectivity_date,
8998 OBJECT_VERSION_NUMBER,
8999 REVISION_ID,
9000 REVISION_LABEL --3340844
9001 )
9002 select -- distinct
9003 pConfigId, --Bugfix 5851244: Removing bind variables to make sql static
9004 mp1.organization_id,
9005 mp1.starting_revision,
9006 sysdate,
9007 gUserId, -- last_updated_by
9008 sysdate,
9009 gUserId, -- created_by
9010 gLoginId, -- last_update_login
9011 sysdate,
9012 sysdate,
9013 1, --would be 1 for initial creation of item
9014 MTL_ITEM_REVISIONS_B_S.nextval, -- 3338108 --:x_item_rev_seq --revision_id is generated from sequence
9015 mp1.starting_revision --3340844
9016 from
9017 mtl_parameters mp1,
9018 mtl_system_items m
9019 where m.inventory_item_id = pConfigId
9020 and m.organization_id = mp1.organization_id
9021 and NOT EXISTS
9022 (select NULL
9023 from MTL_ITEM_REVISIONS_B
9024 where inventory_item_id = pConfigId
9025 and organization_id = mp1.organization_id);
9026
9027
9028
9029 /*IF PG_DEBUG <> 0 THEN
9030 oe_debug_pub.add(sql_stmt,3);
9031 END IF;*/ --Bugfix 6063990
9032
9033 --EXECUTE IMMEDIATE sql_stmt USING pConfigId, gUserId, gUserId, gLoginId, x_item_rev_seq, pModelId, pLineId, pConfigId;
9034 --EXECUTE IMMEDIATE sql_stmt USING pConfigId, gUserId, gUserId, gLoginId,pModelId, pLineId, pConfigId;
9035 --EXECUTE IMMEDIATE sql_stmt USING pConfigId, gUserId, gUserId, gLoginId,pConfigId,pConfigId; Bugfix 6063990
9036
9037 IF PG_DEBUG <> 0 THEN
9038 oe_debug_pub.add('Inserted into mtl_item_revisions_b for item ' || pConfigId || ' rows ' || SQL%ROWCOUNT );
9039 END IF;
9040
9041
9042
9043 --insert into _tl table so that item is visible in revisions form
9044 --for multi-lingual support
9045
9046 stmtnum := 3;
9047
9048
9049 --sql_stmt :=
9050 insert into mtl_item_revisions_tl (
9051 inventory_item_id,
9052 organization_id,
9053 revision_id,
9054 language,
9055 source_lang,
9056 description,
9057 last_update_date,
9058 last_updated_by,
9059 creation_date,
9060 created_by,
9061 last_update_login
9062 )
9063 select distinct pConfigId, --Bugfix 6063990: Removing bind variables to make sql static
9064 mp1.organization_id,
9065 mr.revision_id,
9066 l.language_code,
9067 userenv('LANG'),
9068 m.description,
9069 sysdate,
9070 gUserId, --last_updated_by
9071 sysdate,
9072 gUserId, --created_by
9073 gLoginId --last_update_login
9074 from
9075 mtl_parameters mp1,
9076 mtl_system_items_tl m,
9077 bom_cto_src_orgs bcso,
9078 fnd_languages l,
9079 mtl_item_revisions_b mr, --3338108
9080 mtl_parameters mp2 --4109427
9081 where m.inventory_item_id = pModelId
9082 and bcso.model_item_id = m.inventory_item_id
9083 and bcso.line_id = pLineId
9084 and m.organization_id = mp1.organization_id
9085 and mp2.organization_id = bcso.organization_id --4109427
9086 and ((mp1.organization_id = bcso.organization_id) --4109427
9087 or (mp1.organization_id = mp2.master_organization_id)) --4109427
9088 and l.installed_flag In ('I', 'B')
9089 and l.language_code = m.language
9090 and mr.inventory_item_id = pConfigId --3338108
9091 and mr.organization_id = mp1.organization_id --3338108
9092 and NOT EXISTS
9093 (select NULL
9094 from mtl_item_revisions_tl t
9095 where t.inventory_item_id = pConfigId
9096 and t.organization_id = mp1.organization_id
9097 and t.revision_id = mr.revision_id --3338108
9098 and t.language = l.language_code );
9099
9100
9101
9102 /*IF PG_DEBUG <> 0 THEN
9103 oe_debug_pub.add(sql_stmt,3);
9104 END IF;*/ --Bugfix 6063990
9105
9106 --EXECUTE IMMEDIATE sql_stmt USING pConfigId, x_item_rev_seq, gUserId, gUserId, gLoginId, pModelId, pLineId, pConfigId, x_item_rev_seq;
9107
9108 --EXECUTE IMMEDIATE sql_stmt USING pConfigId,gUserId, gUserId, gLoginId, pModelId, pLineId, pConfigId,pConfigId; Bugfix 6063990
9109
9110 IF PG_DEBUG <> 0 THEN
9111 oe_debug_pub.add('Inserted into mtl_system_items_tl.');
9112 END IF;
9113
9114 EXCEPTION
9115 when OTHERS then
9116 oe_debug_pub.add ('Failed in dynamic query : '||sqlerrm);
9117 xReturnStatus := fnd_api.G_RET_STS_UNEXP_ERROR;
9118
9119 END populate_item_revision;
9120
9121
9122
9123
9124
9125 procedure create_preconfigured_item( p_line_id in number
9126 , p_model_id in number
9127 , p_config_id in number
9128 , p_lItemtype in varchar2 )
9129 is
9130
9131
9132 BEGIN
9133
9134 oe_debug_pub.add( 'Entered Create Preconfigured Item ' , 1 ) ;
9135
9136
9137 select substr( attribute_name, instr( attribute_name, '.' )+ 1 ) , control_level
9138 BULK COLLECT
9139 INTO g_attribute_name_tab, g_control_level_tab
9140 from mtl_item_attributes
9141 where control_level = 1 ;
9142
9143
9144 if( get_attribute_control( 'atp_flag' ) = 1 ) then
9145 oe_debug_pub.add( 'ATP flag is master controlled ' , 1 );
9146 else
9147 oe_debug_pub.add( 'ATP flag is org controlled ' , 1 );
9148
9149 end if;
9150
9151 if( get_attribute_control( 'atp_components_flag' ) = 1 ) then
9152 oe_debug_pub.add( 'ATP components flag is master controlled ' , 1 );
9153 else
9154 oe_debug_pub.add( 'ATP components flag is org controlled ' , 1 );
9155
9156 end if;
9157
9158
9159 if( get_attribute_control( 'market_price' ) = 1 ) then
9160 oe_debug_pub.add( 'market_price is master controlled ' , 1 );
9161 else
9162 oe_debug_pub.add( 'market_price flag is org controlled ' , 1 );
9163
9164 end if;
9165
9166
9167
9168
9169 oe_debug_pub.add( 'Entered Create Preconfigured Item ' , 1 ) ;
9170
9171 insert into mtl_system_items_b
9172 (inventory_item_id,
9173 organization_id,
9174 last_update_date,
9175 last_updated_by,
9176 creation_date,
9177 created_by,
9178 last_update_login,
9179 summary_flag,
9180 enabled_flag,
9181 start_date_active,
9182 end_date_active,
9183 description,
9184 buyer_id,
9185 accounting_rule_id,
9186 invoicing_rule_id,
9187 segment1,
9188 segment2,
9189 segment3,
9190 segment4,
9191 segment5,
9192 segment6,
9193 segment7,
9194 segment8,
9195 segment9,
9196 segment10,
9197 segment11,
9198 segment12,
9199 segment13,
9200 segment14,
9201 segment15,
9202 segment16,
9203 segment17,
9204 segment18,
9205 segment19,
9206 segment20,
9207 attribute_category,
9208 attribute1,
9209 attribute2,
9210 attribute3,
9211 attribute4,
9212 attribute5,
9213 attribute6,
9214 attribute7,
9215 attribute8,
9216 attribute9,
9217 attribute10,
9218 attribute11,
9219 attribute12,
9220 attribute13,
9221 attribute14,
9222 attribute15,
9223 purchasing_item_flag,
9224 shippable_item_flag,
9225 customer_order_flag,
9226 internal_order_flag,
9227 service_item_flag,
9228 inventory_item_flag,
9229 eng_item_flag,
9230 inventory_asset_flag,
9231 purchasing_enabled_flag,
9232 customer_order_enabled_flag,
9233 internal_order_enabled_flag,
9234 so_transactions_flag,
9235 mtl_transactions_enabled_flag,
9236 stock_enabled_flag,
9237 bom_enabled_flag,
9238 build_in_wip_flag,
9239 revision_qty_control_code,
9240 item_catalog_group_id,
9241 catalog_status_flag,
9242 returnable_flag,
9243 default_shipping_org,
9244 collateral_flag,
9245 taxable_flag,
9246 allow_item_desc_update_flag,
9247 inspection_required_flag,
9248 receipt_required_flag,
9249 market_price,
9250 hazard_class_id,
9251 rfq_required_flag,
9252 qty_rcv_tolerance,
9253 un_number_id,
9254 price_tolerance_percent,
9255 asset_category_id,
9256 rounding_factor,
9257 unit_of_issue,
9258 enforce_ship_to_location_code,
9259 allow_substitute_receipts_flag,
9260 allow_unordered_receipts_flag,
9261 allow_express_delivery_flag,
9262 days_early_receipt_allowed,
9263 days_late_receipt_allowed,
9264 receipt_days_exception_code,
9265 receiving_routing_id,
9266 invoice_close_tolerance,
9267 receive_close_tolerance,
9268 auto_lot_alpha_prefix,
9269 start_auto_lot_number,
9270 lot_control_code,
9271 shelf_life_code,
9272 shelf_life_days,
9273 serial_number_control_code,
9274 start_auto_serial_number,
9275 auto_serial_alpha_prefix,
9276 source_type,
9277 source_organization_id,
9278 source_subinventory,
9279 expense_account,
9280 encumbrance_account,
9281 restrict_subinventories_code,
9282 unit_weight,
9283 weight_uom_code,
9284 volume_uom_code,
9285 unit_volume,
9286 restrict_locators_code,
9287 location_control_code,
9288 shrinkage_rate,
9289 acceptable_early_days,
9290 planning_time_fence_code,
9291 demand_time_fence_code,
9292 lead_time_lot_size,
9293 std_lot_size,
9294 cum_manufacturing_lead_time,
9295 overrun_percentage,
9296 acceptable_rate_increase,
9297 acceptable_rate_decrease,
9298 cumulative_total_lead_time,
9299 planning_time_fence_days,
9300 demand_time_fence_days,
9301 end_assembly_pegging_flag,
9302 planning_exception_set,
9303 bom_item_type,
9304 pick_components_flag,
9305 replenish_to_order_flag,
9306 base_item_id,
9307 atp_components_flag,
9308 atp_flag,
9309 fixed_lead_time,
9310 variable_lead_time,
9311 wip_supply_locator_id,
9312 wip_supply_type,
9313 wip_supply_subinventory,
9314 primary_uom_code,
9315 primary_unit_of_measure,
9316 allowed_units_lookup_code,
9317 cost_of_sales_account,
9318 sales_account,
9319 default_include_in_rollup_flag,
9320 inventory_item_status_code,
9321 inventory_planning_code,
9322 planner_code,
9323 planning_make_buy_code,
9324 fixed_lot_multiplier,
9325 rounding_control_type,
9326 carrying_cost,
9327 postprocessing_lead_time,
9328 preprocessing_lead_time,
9329 full_lead_time,
9330 order_cost,
9331 mrp_safety_stock_percent,
9332 mrp_safety_stock_code,
9333 min_minmax_quantity,
9334 max_minmax_quantity,
9335 minimum_order_quantity,
9336 fixed_order_quantity,
9337 fixed_days_supply,
9338 maximum_order_quantity,
9339 atp_rule_id,
9340 picking_rule_id,
9341 reservable_type,
9342 positive_measurement_error,
9343 negative_measurement_error,
9344 engineering_ecn_code,
9345 engineering_item_id,
9346 engineering_date,
9347 service_starting_delay,
9348 vendor_warranty_flag,
9349 serviceable_component_flag,
9350 serviceable_product_flag,
9351 base_warranty_service_id,
9352 payment_terms_id,
9353 preventive_maintenance_flag,
9354 primary_specialist_id,
9355 secondary_specialist_id,
9356 serviceable_item_class_id,
9357 time_billable_flag,
9358 material_billable_flag,
9359 expense_billable_flag,
9360 prorate_service_flag,
9361 coverage_schedule_id,
9362 service_duration_period_code,
9363 service_duration,
9364 max_warranty_amount,
9365 response_time_period_code,
9366 response_time_value,
9367 new_revision_code,
9368 tax_code,
9369 must_use_approved_vendor_flag,
9370 safety_stock_bucket_days,
9371 auto_reduce_mps,
9372 costing_enabled_flag,
9373 invoiceable_item_flag,
9374 invoice_enabled_flag,
9375 outside_operation_flag,
9376 outside_operation_uom_type,
9377 auto_created_config_flag,
9378 cycle_count_enabled_flag,
9379 item_type,
9380 model_config_clause_name,
9381 ship_model_complete_flag,
9382 mrp_planning_code,
9383 repetitive_planning_flag,
9384 return_inspection_requirement,
9385 effectivity_control,
9386 request_id,
9387 program_application_id,
9388 program_id,
9389 program_update_date,
9390 comms_nl_trackable_flag, -- bugfix 2200256
9391 default_so_source_type,
9392 create_supply_flag,
9393 -- begin bugfix 2336548
9394 lot_status_enabled,
9395 default_lot_status_id,
9396 serial_status_enabled,
9397 default_serial_status_id,
9398 lot_split_enabled,
9399 lot_merge_enabled,
9400 bulk_picked_flag,
9401 -- end bugfix 2336548
9402 -- begin bugfix 2400609
9403 FINANCING_ALLOWED_FLAG,
9404 EAM_ITEM_TYPE ,
9405 EAM_ACTIVITY_TYPE_CODE,
9406 EAM_ACTIVITY_CAUSE_CODE,
9407 EAM_ACT_NOTIFICATION_FLAG,
9408 EAM_ACT_SHUTDOWN_STATUS,
9409 SUBSTITUTION_WINDOW_CODE,
9410 SUBSTITUTION_WINDOW_DAYS,
9411 PRODUCT_FAMILY_ITEM_ID,
9412 CHECK_SHORTAGES_FLAG,
9413 PLANNED_INV_POINT_FLAG,
9414 OVER_SHIPMENT_TOLERANCE,
9415 UNDER_SHIPMENT_TOLERANCE,
9416 OVER_RETURN_TOLERANCE,
9417 UNDER_RETURN_TOLERANCE,
9418 PURCHASING_TAX_CODE,
9419 OVERCOMPLETION_TOLERANCE_TYPE,
9420 OVERCOMPLETION_TOLERANCE_VALUE,
9421 INVENTORY_CARRY_PENALTY,
9422 OPERATION_SLACK_PENALTY,
9423 UNIT_LENGTH,
9424 UNIT_WIDTH,
9425 UNIT_HEIGHT,
9426 LOT_TRANSLATE_ENABLED,
9427 CONTAINER_ITEM_FLAG,
9428 VEHICLE_ITEM_FLAG,
9429 DIMENSION_UOM_CODE,
9430 SECONDARY_UOM_CODE,
9431 MAXIMUM_LOAD_WEIGHT,
9432 MINIMUM_FILL_PERCENT,
9433 CONTAINER_TYPE_CODE,
9434 INTERNAL_VOLUME,
9435 EQUIPMENT_TYPE,
9436 INDIVISIBLE_FLAG,
9437 GLOBAL_ATTRIBUTE_CATEGORY,
9438 GLOBAL_ATTRIBUTE1,
9439 GLOBAL_ATTRIBUTE2,
9440 GLOBAL_ATTRIBUTE3,
9441 GLOBAL_ATTRIBUTE4,
9442 GLOBAL_ATTRIBUTE5,
9443 GLOBAL_ATTRIBUTE6,
9444 GLOBAL_ATTRIBUTE7,
9445 GLOBAL_ATTRIBUTE8,
9446 GLOBAL_ATTRIBUTE9,
9447 GLOBAL_ATTRIBUTE10,
9448 DUAL_UOM_CONTROL,
9449 DUAL_UOM_DEVIATION_HIGH,
9450 DUAL_UOM_DEVIATION_LOW,
9451 CONTRACT_ITEM_TYPE_CODE,
9452 SUBSCRIPTION_DEPEND_FLAG,
9453 SERV_REQ_ENABLED_CODE,
9454 SERV_BILLING_ENABLED_FLAG,
9455 RELEASE_TIME_FENCE_CODE, -- 2898851
9456 RELEASE_TIME_FENCE_DAYS, -- 2898851
9457 DEFECT_TRACKING_ON_FLAG, -- 2858080
9458 SERV_IMPORTANCE_LEVEL,
9459 -- end bugfix 2400609
9460 WEB_STATUS , --bugfix 2727983
9461 tracking_quantity_ind, /* Additional Attributes for Item in patchset J */
9462 ont_pricing_qty_source,
9463 approval_status ,
9464 vmi_minimum_units,
9465 vmi_minimum_days,
9466 vmi_maximum_units,
9467 vmi_maximum_days,
9468 vmi_fixed_order_quantity,
9469 so_authorization_flag,
9470 consigned_flag,
9471 asn_autoexpire_flag,
9472 vmi_forecast_type,
9473 forecast_horizon,
9474 days_tgt_inv_supply,
9475 days_tgt_inv_window,
9476 days_max_inv_supply,
9477 days_max_inv_window,
9478 critical_component_flag,
9479 drp_planned_flag,
9480 exclude_from_budget_flag,
9481 convergence,
9482 continous_transfer,
9483 divergence,
9484 --begin r12,4574899
9485 lot_divisible_flag,
9486 grade_control_flag,
9487 child_lot_flag,
9488 child_lot_validation_flag,
9489 copy_lot_attribute_flag,
9490 recipe_enabled_flag,
9491 process_quality_enabled_flag,
9492 process_execution_enabled_flag,
9493 process_costing_enabled_flag,
9494 hazardous_material_flag,
9495 preposition_point,
9496 repair_program,
9497 outsourced_assembly
9498 -- end rl2,4574899
9499
9500 )
9501 select /*+ USE_NL(MP1) */
9502 distinct
9503 p_config_id,
9504 m.organization_id,
9505 sysdate,
9506 gUserId, -- last_updated_by
9507 sysdate,
9508 gUserId, -- created_by
9509 gLoginId , -- last_update_login
9510 decode( get_attribute_control( 'summary_flag') , 1 , config.summary_flag, m.summary_flag),
9511 decode( get_attribute_control( 'enabled_flag' ) , 1 , config.enabled_flag , m.enabled_flag),
9512 decode( get_attribute_control( 'start_date_active'), 1 , config.start_date_active, m.start_date_active) ,
9513 decode( get_attribute_control( 'end_date_active'), 1 , config.end_date_active, m.end_date_active) ,
9514 decode( get_attribute_control( 'description' ) , 1 , config.description, m.description) ,
9515 decode( get_attribute_control( 'buyer_id') , 1 , config.buyer_id, m.buyer_id) ,
9516 decode( get_attribute_control( 'accounting_rule_id' ) , 1 , config.accounting_rule_id, m.accounting_rule_id) ,
9517 decode( get_attribute_control( 'invoicing_rule_id' ) , 1 , config.invoicing_rule_id, m.invoicing_rule_id) ,
9518 config.segment1,
9519 config.segment2,
9520 config.segment3,
9521 config.segment4,
9522 config.segment5,
9523 config.segment6,
9524 config.segment7,
9525 config.segment8,
9526 config.segment9,
9527 config.segment10,
9528 config.segment11,
9529 config.segment12,
9530 config.segment13,
9531 config.segment14,
9532 config.segment15,
9533 config.segment16,
9534 config.segment17,
9535 config.segment18,
9536 config.segment19,
9537 config.segment20,
9538 decode( get_attribute_control( 'attribute_category'), 1 , config.attribute_category, m.attribute_category),
9539 m.attribute1,
9540 m.attribute2,
9541 m.attribute3,
9542 m.attribute4,
9543 m.attribute5,
9544 m.attribute6,
9545 m.attribute7,
9546 m.attribute8,
9547 m.attribute9,
9548 m.attribute10,
9549 m.attribute11,
9550 m.attribute12,
9551 m.attribute13,
9552 m.attribute14,
9553 m.attribute15,
9554 'Y', -- purchasing_item_flag,
9555 'Y', -- Shippable Flag
9556 'Y', -- CUSTOMER_ORDER_FLAG
9557 'Y', -- INTERNAL_ORDER_FLAG
9558 decode( get_attribute_control( 'service_item_flag' ), 1, config.service_item_flag , m.service_item_flag) ,
9559 'Y', -- INVENTORY_ITEM_FLAG
9560 decode( get_attribute_control( 'eng_item_flag' ) , 1 , config.eng_item_flag , m.eng_item_flag) ,
9561 decode( get_attribute_control( 'inventory_asset_flag' ) , 1 , config.inventory_asset_flag , m.inventory_asset_flag) ,
9562 'Y', -- purchasing_enabled_flag,
9563 'Y', -- CUSTOMER_ORDER_ENABLED_FLAG
9564 'Y', -- INTERNAL_ORDER_ENABLED_FLAG
9565 'Y', -- SO_TRANSACTIONS_FLAG
9566 'Y', -- MTL_TRANSACTIONS_ENABLED_FLAG
9567 'Y', -- STOCK_ENABLED_FLAG
9568 'Y', -- BOM_ENABLED_FLAG
9569 'Y', -- BUILD_IN_WIP_FLAG
9570 decode( get_attribute_control( 'revision_qty_control_code' ) , 1 , config.revision_qty_control_code , m.revision_qty_control_code) ,
9571 decode( get_attribute_control( 'item_catalog_group_id' ) , 1 , config.item_catalog_group_id, m.item_catalog_group_id) , -- check, earlier it was always from mfg org
9572 decode( get_attribute_control( 'catalog_status_flag' ) , 1 , config.catalog_status_flag, m.catalog_status_flag) ,
9573 decode( get_attribute_control( 'returnable_flag' ) , 1 , config.returnable_flag, m.returnable_flag) ,
9574 decode( get_attribute_control( 'default_shipping_org' ) , 1, config.default_shipping_org, m.default_shipping_org),
9575 decode( get_attribute_control( 'collateral_flag') , 1 , config.collateral_flag , m.collateral_flag) ,
9576 decode( get_attribute_control( 'taxable_flag' ) , 1 , config.taxable_flag, m.taxable_flag) ,
9577 decode( get_attribute_control( 'allow_item_desc_update_flag' ) , 1, config.allow_item_desc_update_flag, m.allow_item_desc_update_flag),
9578 decode( get_attribute_control( 'inspection_required_flag' ), 1 , config.inspection_required_flag , m.inspection_required_flag),
9579 decode( get_attribute_control( 'receipt_required_flag' ), 1, config.receipt_required_flag, m.receipt_required_flag) ,
9580 decode( get_attribute_control( 'market_price' ) , 1 , config.market_price, m.market_price) ,
9581 decode( get_attribute_control( 'hazard_class_id' ), 1 , config.hazard_class_id, m.hazard_class_id),
9582 decode( get_attribute_control( 'rfq_required_flag'), 1 , config.rfq_required_flag, m.rfq_required_flag),
9583 decode( get_attribute_control( 'qty_rcv_tolerance'), 1, config.qty_rcv_tolerance, m.qty_rcv_tolerance),
9584 decode( get_attribute_control( 'un_number_id' ), 1 , config.un_number_id, m.un_number_id),
9585 decode( get_attribute_control( 'price_tolerance_percent'), 1 , config.price_tolerance_percent, m.price_tolerance_percent) ,
9586 decode( get_attribute_control( 'asset_category_id') , 1 , config.asset_category_id, m.asset_category_id) ,
9587 decode( get_attribute_control( 'rounding_factor' ) , 1 , config.rounding_factor, m.rounding_factor) ,
9588 decode( get_attribute_control( 'unit_of_issue') , 1 , config.unit_of_issue, m.unit_of_issue) ,
9589 decode( get_attribute_control( 'enforce_ship_to_location_code' ) , 1 , config.enforce_ship_to_location_code , m.enforce_ship_to_location_code),
9590 decode( get_attribute_control( 'allow_substitute_receipts_flag' ) , 1 , config.allow_substitute_receipts_flag, m.allow_substitute_receipts_flag) ,
9591 decode( get_attribute_control( 'allow_unordered_receipts_flag' ) , 1 , config.allow_unordered_receipts_flag, m.allow_unordered_receipts_flag) ,
9592 decode( get_attribute_control( 'allow_express_delivery_flag' ) ,1 , config.allow_express_delivery_flag, m.allow_express_delivery_flag) ,
9593 decode( get_attribute_control( 'days_early_receipt_allowed') , 1, config.days_early_receipt_allowed, m.days_early_receipt_allowed) ,
9594 decode( get_attribute_control( 'days_late_receipt_allowed' ) , 1 , config.days_late_receipt_allowed , m.days_late_receipt_allowed) ,
9595 decode( get_attribute_control( 'receipt_days_exception_code') , 1 , config.receipt_days_exception_code, m.receipt_days_exception_code) ,
9596 decode( get_attribute_control( 'receiving_routing_id' ) , 1 , config.receiving_routing_id, m.receiving_routing_id),
9597 decode( get_attribute_control( 'invoice_close_tolerance'), 1, config.invoice_close_tolerance, m.invoice_close_tolerance) ,
9598 decode( get_attribute_control( 'receive_close_tolerance') , 1 , config.receive_close_tolerance , m.receive_close_tolerance) ,
9599 decode( get_attribute_control( 'auto_lot_alpha_prefix') , 1, config.auto_lot_alpha_prefix, m.auto_lot_alpha_prefix) ,
9600 decode( get_attribute_control( 'start_auto_lot_number') , 1, config.start_auto_lot_number, m.start_auto_lot_number) ,
9601 decode( get_attribute_control( 'lot_control_code') ,1 , config.lot_control_code, m.lot_control_code) ,
9602 decode( get_attribute_control( 'shelf_life_code'), 1 , config.shelf_life_code, m.shelf_life_code) ,
9603 decode( get_attribute_control( 'shelf_life_days') , 1, config.shelf_life_days, m.shelf_life_days) ,
9604 decode( get_attribute_control( 'serial_number_control_code' ) ,1, config.serial_number_control_code, m.serial_number_control_code) ,
9605 decode( get_attribute_control( 'start_auto_serial_number' ) , 1 , config.start_auto_serial_number, m.start_auto_serial_number) ,
9606 decode( get_attribute_control( 'auto_serial_alpha_prefix') ,1 , config.auto_serial_alpha_prefix, m.auto_serial_alpha_prefix) ,
9607 decode( get_attribute_control( 'source_type' ) ,1 , config.source_type, m.source_type) ,
9608 decode( get_attribute_control( 'source_organization_id') , 1 , config.source_organization_id, m.source_organization_id) ,
9609 decode( get_attribute_control( 'source_subinventory') ,1 , config.source_subinventory, m.source_subinventory) ,
9610 decode( get_attribute_control( 'expense_account') , 1, config.expense_account, m.expense_account) ,
9611 decode( get_attribute_control( 'encumbrance_account') , 1 , config.encumbrance_account, m.encumbrance_account) ,
9612 decode( get_attribute_control( 'restrict_subinventories_code' ) , 1 , config.restrict_subinventories_code, m.restrict_subinventories_code) ,
9613 -- bugfix 2301167 : we will calculate the unit weight/vol later..
9614 null, -- m.unit_weight,
9615 null, -- m.weight_uom_code,
9616 null, -- m.volume_uom_code,
9617 null, -- m.unit_volume,
9618 -- end bugfix 2301167
9619 decode( get_attribute_control( 'restrict_locators_code'), 1, config.restrict_locators_code, m.restrict_locators_code) ,
9620 decode( get_attribute_control( 'location_control_code') , 1 , config.location_control_code, m.location_control_code) ,
9621 decode( get_attribute_control( 'shrinkage_rate' ) , 1, config.shrinkage_rate, m.shrinkage_rate) ,
9622 decode( get_attribute_control( 'acceptable_early_days') , 1 , config.acceptable_early_days, m.acceptable_early_days) ,
9623 decode( get_attribute_control( 'planning_time_fence_code' ) , 1 , config.planning_time_fence_code, m.planning_time_fence_code) ,
9624 decode( get_attribute_control( 'demand_time_fence_code') , 1 , config.demand_time_fence_code, m.demand_time_fence_code) ,
9625 decode( get_attribute_control( 'lead_time_lot_size') ,1, config.lead_time_lot_size, m.lead_time_lot_size) ,
9626 decode( get_attribute_control( 'std_lot_size' ) , 1, config.std_lot_size, m.std_lot_size) ,
9627 decode( get_attribute_control( 'cum_manufacturing_lead_time' ) , 1 , config.cum_manufacturing_lead_time, m.cum_manufacturing_lead_time) ,
9628 decode( get_attribute_control( 'overrun_percentage') , 1, config.overrun_percentage, m.overrun_percentage) ,
9629 decode( get_attribute_control( 'acceptable_rate_increase'), 1, config.acceptable_rate_increase, m.acceptable_rate_increase) ,
9630 decode( get_attribute_control( 'acceptable_rate_decrease') , 1 , config.acceptable_rate_decrease, m.acceptable_rate_decrease) ,
9631 decode( get_attribute_control( 'cumulative_total_lead_time' ) , 1 , config.cumulative_total_lead_time, m.cumulative_total_lead_time) ,
9632 decode( get_attribute_control( 'planning_time_fence_days' ) , 1, config.planning_time_fence_days, m.planning_time_fence_days) ,
9633 decode( get_attribute_control( 'demand_time_fence_days') , 1, config.demand_time_fence_days, m.demand_time_fence_days) ,
9634 decode( get_attribute_control( 'end_assembly_pegging_flag') ,1 , config.end_assembly_pegging_flag , m.end_assembly_pegging_flag) ,
9635 decode( get_attribute_control( 'planning_exception_set' ) , 1 , config.planning_exception_set, m.planning_exception_set) ,
9636 4, -- BOM_ITEM_TYPE : standard
9637 'N', -- PICK_COMPONENTS_FLAG
9638 'Y', -- REPLENISH_TO_ORDER_FLAG
9639 p_model_id, -- Base Model ID
9640 decode( get_attribute_control( 'atp_components_flag') , 1, config.atp_components_flag, evaluate_atp_attributes( m.atp_flag, m.atp_components_flag )) ,
9641 decode( get_attribute_control( 'atp_flag') , 1, config.atp_flag, get_atp_flag) ,
9642 decode( get_attribute_control( 'fixed_lead_time') ,1 , config.fixed_lead_time, m.fixed_lead_time) ,
9643 decode( get_attribute_control( 'variable_lead_time') , 1 , config.variable_lead_time, m.variable_lead_time) ,
9644 decode( get_attribute_control( 'wip_supply_locator_id' ) , 1, config.wip_supply_locator_id, m.wip_supply_locator_id) ,
9645 decode( get_attribute_control( 'wip_supply_type' ) , 1 , config.wip_supply_type , m.wip_supply_type) ,
9646 decode( get_attribute_control( 'wip_supply_subinventory' ) , 1 , config.wip_supply_subinventory, m.wip_supply_subinventory) ,
9647 decode( get_attribute_control( 'primary_uom_code' ) , 1 , config.primary_uom_code, m.primary_uom_code) ,
9648 decode( get_attribute_control( 'primary_unit_of_measure' ) , 1 , config.primary_unit_of_measure, m.primary_unit_of_measure) ,
9649 decode( get_attribute_control( 'allowed_units_lookup_code' ) , 1 , config.allowed_units_lookup_code, m.allowed_units_lookup_code) ,
9650 decode( get_attribute_control( 'cost_of_sales_account' ) , 1 , config.cost_of_sales_account, m.cost_of_sales_account) ,
9651 decode( get_attribute_control( 'sales_account' ) , 1, config.sales_account, m.sales_account) ,
9652 'Y', -- DEFAULT_INCLUDE_IN_ROLLUP_FLAG
9653 decode( get_attribute_control( 'inventory_item_status_code' ) , 1 , config.inventory_item_status_code, m.inventory_item_status_code) ,
9654 decode( get_attribute_control( 'inventory_planning_code') , 1, config.inventory_planning_code, m.inventory_planning_code) ,
9655 decode( get_attribute_control( 'planner_code') , 1 , config.planner_code, m.planner_code) ,
9656 decode( get_attribute_control( 'planning_make_buy_code' ) , 1 , config.planning_make_buy_code, m.planning_make_buy_code) ,
9657 decode( get_attribute_control( 'fixed_lot_multiplier' ) , 1 , config.fixed_lot_multiplier, m.fixed_lot_multiplier) ,
9658 decode( get_attribute_control( 'rounding_control_type' ) , 1, config.rounding_control_type, m.rounding_control_type) ,
9659 decode( get_attribute_control( 'carrying_cost' ) ,1 , config.carrying_cost, m.carrying_cost) ,
9660 decode( get_attribute_control( 'postprocessing_lead_time') , 1, config.postprocessing_lead_time, m.postprocessing_lead_time) ,
9661 decode( get_attribute_control( 'preprocessing_lead_time' ) , 1 , config.preprocessing_lead_time, m.preprocessing_lead_time) ,
9662 decode( get_attribute_control( 'full_lead_time') , 1, config.full_lead_time, m.full_lead_time) ,
9663 decode( get_attribute_control( 'order_cost') , 1, config.order_cost, m.order_cost) ,
9664 decode( get_attribute_control( 'mrp_safety_stock_percent') , 1, config.mrp_safety_stock_percent, m.mrp_safety_stock_percent) ,
9665 decode( get_attribute_control( 'mrp_safety_stock_code' ) , 1, config.mrp_safety_stock_code, m.mrp_safety_stock_code) ,
9666 decode( get_attribute_control( 'min_minmax_quantity' ) , 1, config.min_minmax_quantity, m.min_minmax_quantity) ,
9667 decode( get_attribute_control( 'max_minmax_quantity' ) , 1 , config.max_minmax_quantity, m.max_minmax_quantity) ,
9668 decode( get_attribute_control( 'minimum_order_quantity' ) , 1 , config.minimum_order_quantity , m.minimum_order_quantity) ,
9669 decode( get_attribute_control( 'fixed_order_quantity' ) , 1 , config.fixed_order_quantity, m.fixed_order_quantity) ,
9670 decode( get_attribute_control( 'fixed_days_supply' ) , 1 , config.fixed_days_supply, m.fixed_days_supply) ,
9671 decode( get_attribute_control( 'maximum_order_quantity' ) , 1, config.maximum_order_quantity, m.maximum_order_quantity) ,
9672 decode( get_attribute_control( 'atp_rule_id' ) , 1, config.atp_rule_id, m.atp_rule_id) ,
9673 decode( get_attribute_control( 'picking_rule_id' ) , 1, config.picking_rule_id, m.picking_rule_id) ,
9674 1, -- m.reservable_type
9675 decode( get_attribute_control( 'positive_measurement_error' ) , 1, config.positive_measurement_error, m.positive_measurement_error) ,
9676 decode( get_attribute_control( 'negative_measurement_error' ) , 1, config.negative_measurement_error, m.negative_measurement_error) ,
9677 decode( get_attribute_control( 'engineering_ecn_code' ) , 1 , config.engineering_ecn_code, m.engineering_ecn_code) ,
9678 decode( get_attribute_control( 'engineering_item_id' ) , 1 , config.engineering_item_id, m.engineering_item_id) ,
9679 decode( get_attribute_control( 'engineering_date' ) , 1, config.engineering_date, m.engineering_date) ,
9680 decode( get_attribute_control( 'service_starting_delay') , 1 , config.service_starting_delay, m.service_starting_delay) ,
9681 decode( get_attribute_control( 'vendor_warranty_flag') , 1 , config.vendor_warranty_flag, m.vendor_warranty_flag) ,
9682 decode( get_attribute_control( 'serviceable_component_flag' ) , 1, config.serviceable_component_flag , m.serviceable_component_flag) ,
9683 decode( get_attribute_control( 'serviceable_product_flag' ) , 1, config.serviceable_product_flag , m.serviceable_product_flag) ,
9684 decode( get_attribute_control( 'base_warranty_service_id' ) ,1 , config.base_warranty_service_id, m.base_warranty_service_id) ,
9685 decode( get_attribute_control( 'payment_terms_id' ) , 1 , config.payment_terms_id, m.payment_terms_id) ,
9686 decode( get_attribute_control( 'preventive_maintenance_flag') , 1, config.preventive_maintenance_flag, m.preventive_maintenance_flag) ,
9687 decode( get_attribute_control( 'primary_specialist_id') , 1 , config.primary_specialist_id, m.primary_specialist_id),
9688 decode( get_attribute_control( 'secondary_specialist_id') , 1 , config.secondary_specialist_id, m.secondary_specialist_id) ,
9689 decode( get_attribute_control( 'serviceable_item_class_id') , 1, config.serviceable_item_class_id, m.serviceable_item_class_id) ,
9690 decode( get_attribute_control( 'time_billable_flag' ) , 1 , config.time_billable_flag, m.time_billable_flag) ,
9691 decode( get_attribute_control( 'material_billable_flag' ) , 1, config.material_billable_flag, m.material_billable_flag) ,
9692 decode( get_attribute_control( 'expense_billable_flag' ) , 1 , config.expense_billable_flag , m.expense_billable_flag) ,
9693 decode( get_attribute_control( 'prorate_service_flag' ) , 1, config.prorate_service_flag, m.prorate_service_flag) ,
9694 decode( get_attribute_control( 'coverage_schedule_id' ) , 1, config.coverage_schedule_id, m.coverage_schedule_id) ,
9695 decode( get_attribute_control( 'service_duration_period_code' ) , 1, config.service_duration_period_code, m.service_duration_period_code) ,
9696 decode( get_attribute_control( 'service_duration') , 1, config.service_duration, m.service_duration) ,
9697 decode( get_attribute_control( 'max_warranty_amount' ) , 1 , config.max_warranty_amount, m.max_warranty_amount) ,
9698 decode( get_attribute_control( 'response_time_period_code' ) , 1, config.response_time_period_code, m.response_time_period_code) ,
9699 decode( get_attribute_control( 'response_time_value') , 1, config.response_time_value, m.response_time_value) ,
9700 decode( get_attribute_control( 'new_revision_code' ) , 1 , config.new_revision_code, m.new_revision_code) ,
9701 decode( get_attribute_control( 'tax_code') , 1, config.tax_code, m.tax_code) ,
9702 decode( get_attribute_control( 'must_use_approved_vendor_flag' ) , 1, config.must_use_approved_vendor_flag, m.must_use_approved_vendor_flag) ,
9703 decode( get_attribute_control( 'safety_stock_bucket_days' ) , 1, config.safety_stock_bucket_days, m.safety_stock_bucket_days) ,
9704 decode( get_attribute_control( 'auto_reduce_mps') , 1, config.auto_reduce_mps, m.auto_reduce_mps) ,
9705 decode( get_attribute_control( 'costing_enabled_flag' ) , 1, config.costing_enabled_flag, m.costing_enabled_flag) ,
9706 decode( get_attribute_control( 'invoiceable_item_flag' ) , 1, config.invoiceable_item_flag, m.invoiceable_item_flag ) ,
9707 decode( get_attribute_control( 'invoice_enabled_flag' ) , 1 , config.invoice_enabled_flag, m.invoice_enabled_flag ) ,
9708 decode( get_attribute_control( 'outside_operation_flag') , 1, config.outside_operation_flag, m.outside_operation_flag) ,
9709 decode( get_attribute_control( 'outside_operation_uom_type' ) , 1, config.outside_operation_uom_type, m.outside_operation_uom_type) ,
9710 'Y', -- auto created config flag
9711 decode( get_attribute_control( 'cycle_count_enabled_flag') , 1 , config.cycle_count_enabled_flag, m.cycle_count_enabled_flag) ,
9712 p_lItemType,
9713 decode( get_attribute_control( 'model_config_clause_name') ,1 , config.model_config_clause_name, m.model_config_clause_name) ,
9714 decode( get_attribute_control( 'ship_model_complete_flag') ,1 , config.ship_model_complete_flag, m.ship_model_complete_flag) ,
9715 decode( get_attribute_control( 'mrp_planning_code' ) , 1 , config.mrp_planning_code, m.mrp_planning_code) , -- earlier it was always from one org only
9716 decode( get_attribute_control( 'repetitive_planning_flag' ) , 1, config.repetitive_planning_flag, m.repetitive_planning_flag) , -- earlier it was always from one org only
9717 decode( get_attribute_control( 'return_inspection_requirement' ) , 1 , config.return_inspection_requirement, m.return_inspection_requirement) ,
9718 nvl( decode( get_attribute_control( 'effectivity_control') , 1, config.effectivity_control, m.effectivity_control) , 1),
9719 null, -- req_id
9720 null, -- prg_appid
9721 null, -- prg_id
9722 sysdate,
9723 decode( get_attribute_control( 'comms_nl_trackable_flag') , 1, config.comms_nl_trackable_flag, m.comms_nl_trackable_flag) , -- bugfix 2200256
9724 nvl( decode( get_attribute_control( 'default_so_source_type') , 1 , config.default_so_source_type, m.default_so_source_type) ,'INTERNAL'),
9725 nvl( decode( get_attribute_control( 'create_supply_flag') , 1, config.create_supply_flag, m.create_supply_flag) , 'Y'),
9726 -- begin bugfix 2336548
9727 decode( get_attribute_control( 'lot_status_enabled') , 1, config.lot_status_enabled, m.lot_status_enabled) ,
9728 decode( get_attribute_control( 'default_lot_status_id' ) , 1, config.default_lot_status_id, m.default_lot_status_id) ,
9729 decode( get_attribute_control( 'serial_status_enabled') , 1, config.serial_status_enabled, m.serial_status_enabled) ,
9730 decode( get_attribute_control( 'default_serial_status_id') ,1 , config.default_serial_status_id, m.default_serial_status_id) ,
9731 decode( get_attribute_control( 'lot_split_enabled') , 1, config.lot_split_enabled, m.lot_split_enabled) ,
9732 decode( get_attribute_control( 'lot_merge_enabled') ,1 , config.lot_merge_enabled, m.lot_merge_enabled) ,
9733 decode( get_attribute_control( 'bulk_picked_flag' ) , 1 , config.bulk_picked_flag, m.bulk_picked_flag) ,
9734 -- end bugfix 2336548
9735 -- begin bugfix 2400609
9736 decode( get_attribute_control( 'financing_allowed_flag') , 1, config.financing_allowed_flag, m.FINANCING_ALLOWED_FLAG) ,
9737 decode( get_attribute_control( 'eam_item_type') , 1 , config.eam_item_type, m.EAM_ITEM_TYPE ) ,
9738 decode( get_attribute_control( 'eam_activity_type_code') , 1 , config.eam_activity_type_code, m.EAM_ACTIVITY_TYPE_CODE) ,
9739 decode( get_attribute_control( 'eam_activity_cause_code') , 1, config.eam_activity_cause_code, m.EAM_ACTIVITY_CAUSE_CODE) ,
9740 decode( get_attribute_control( 'eam_act_notification_flag') , 1, config.eam_act_notification_flag, m.EAM_ACT_NOTIFICATION_FLAG) ,
9741 decode( get_attribute_control( 'eam_act_shutdown_status') , 1, config.eam_act_shutdown_status, m.EAM_ACT_SHUTDOWN_STATUS) ,
9742 decode( get_attribute_control( 'substitution_window_code') , 1, config.substitution_window_code, m.SUBSTITUTION_WINDOW_CODE) ,
9743 decode( get_attribute_control( 'substitution_window_days') , 1, config.substitution_window_days, m.SUBSTITUTION_WINDOW_DAYS) ,
9744 null, --5385901 decode( get_attribute_control( 'product_family_item_id') , 1, config.product_family_item_id, m.PRODUCT_FAMILY_ITEM_ID) ,
9745 decode( get_attribute_control( 'check_shortages_flag') , 1, config.check_shortages_flag, m.CHECK_SHORTAGES_FLAG) ,
9746 decode( get_attribute_control( 'planned_inv_point_flag') , 1, config.planned_inv_point_flag, m.PLANNED_INV_POINT_FLAG) ,
9747 decode( get_attribute_control( 'over_shipment_tolerance') , 1, config.over_shipment_tolerance, m.OVER_SHIPMENT_TOLERANCE) ,
9748 decode( get_attribute_control( 'under_shipment_tolerance') , 1, config.under_shipment_tolerance, m.UNDER_SHIPMENT_TOLERANCE) ,
9749 decode( get_attribute_control( 'over_return_tolerance') , 1, config.over_return_tolerance, m.OVER_RETURN_TOLERANCE) ,
9750 decode( get_attribute_control( 'under_return_tolerance') , 1, config.under_return_tolerance, m.UNDER_RETURN_TOLERANCE) ,
9751 decode( get_attribute_control( 'purchasing_tax_code') , 1, config.purchasing_tax_code, m.PURCHASING_TAX_CODE) ,
9752 decode( get_attribute_control( 'overcompletion_tolerance_type') , 1, config.overcompletion_tolerance_type, m.OVERCOMPLETION_TOLERANCE_TYPE) ,
9753 decode( get_attribute_control( 'overcompletion_tolerance_value') , 1, config.overcompletion_tolerance_value, m.OVERCOMPLETION_TOLERANCE_VALUE) ,
9754 decode( get_attribute_control( 'inventory_carry_penalty'), 1, config.inventory_carry_penalty, m.INVENTORY_CARRY_PENALTY) ,
9755 decode( get_attribute_control( 'operation_slack_penalty') ,1, config.operation_slack_penalty, m.OPERATION_SLACK_PENALTY) ,
9756 decode( get_attribute_control( 'unit_length') , 1, config.unit_length, m.UNIT_LENGTH) ,
9757 decode( get_attribute_control( 'unit_width' ) , 1, config.unit_width, m.UNIT_WIDTH) ,
9758 decode( get_attribute_control( 'unit_height') , 1, config.unit_height, m.UNIT_HEIGHT) ,
9759 decode( get_attribute_control( 'lot_translate_enabled') , 1, config.lot_translate_enabled, m.LOT_TRANSLATE_ENABLED) ,
9760 decode( get_attribute_control( 'container_item_flag') , 1, config.container_item_flag, m.CONTAINER_ITEM_FLAG) ,
9761 decode( get_attribute_control( 'vehicle_item_flag') , 1, config.vehicle_item_flag, m.VEHICLE_ITEM_FLAG) ,
9762 decode( get_attribute_control( 'dimension_uom_code') , 1, config.dimension_uom_code, m.DIMENSION_UOM_CODE) ,
9763 decode( get_attribute_control( 'secondary_uom_code') , 1, config.secondary_uom_code, m.SECONDARY_UOM_CODE) ,
9764 decode( get_attribute_control( 'maximum_load_weight') , 1, config.maximum_load_weight, m.MAXIMUM_LOAD_WEIGHT) ,
9765 decode( get_attribute_control( 'minimum_fill_percent') , 1, config.minimum_fill_percent, m.MINIMUM_FILL_PERCENT) ,
9766 decode( get_attribute_control( 'container_type_code') , 1, config.container_type_code, m.CONTAINER_TYPE_CODE) ,
9767 decode( get_attribute_control( 'internal_volume') , 1, config.internal_volume, m.INTERNAL_VOLUME) ,
9768 decode( get_attribute_control( 'equipment_type') , 1, config.equipment_type , m.EQUIPMENT_TYPE) ,
9769 decode( get_attribute_control( 'indivisible_flag') , 1, config.indivisible_flag, m.INDIVISIBLE_FLAG) ,
9770 decode( get_attribute_control( 'global_attribute_category'), 1, config.global_attribute_category, m.GLOBAL_ATTRIBUTE_CATEGORY) ,
9771 m.GLOBAL_ATTRIBUTE1,
9772 m.GLOBAL_ATTRIBUTE2,
9773 m.GLOBAL_ATTRIBUTE3,
9774 m.GLOBAL_ATTRIBUTE4,
9775 m.GLOBAL_ATTRIBUTE5,
9776 m.GLOBAL_ATTRIBUTE6,
9777 m.GLOBAL_ATTRIBUTE7,
9778 m.GLOBAL_ATTRIBUTE8,
9779 m.GLOBAL_ATTRIBUTE9,
9780 m.GLOBAL_ATTRIBUTE10,
9781 decode( get_attribute_control( 'dual_uom_control') , 1, config.dual_uom_control, m.DUAL_UOM_CONTROL) ,
9782 decode( get_attribute_control( 'dual_uom_deviation_high') , 1, config.dual_uom_deviation_high, m.DUAL_UOM_DEVIATION_HIGH) ,
9783 decode( get_attribute_control( 'dual_uom_deviation_low') , 1, config.dual_uom_deviation_low, m.DUAL_UOM_DEVIATION_LOW) ,
9784 decode( get_attribute_control( 'contract_item_type_code') , 1, config.contract_item_type_code, m.CONTRACT_ITEM_TYPE_CODE) ,
9785 decode( get_attribute_control( 'subscription_depend_flag') , 1 , config.subscription_depend_flag, m.SUBSCRIPTION_DEPEND_FLAG) ,
9786 decode( get_attribute_control( 'serv_req_enabled_code' ) , 1, config.serv_req_enabled_code, m.SERV_REQ_ENABLED_CODE) ,
9787 decode( get_attribute_control( 'serv_billing_enabled_flag') , 1, config.serv_billing_enabled_flag, m.SERV_BILLING_ENABLED_FLAG) ,
9788 decode( get_attribute_control( 'release_time_fence_code') , 1, config.release_time_fence_code, m.RELEASE_TIME_FENCE_CODE) ,
9789 decode( get_attribute_control( 'release_time_fence_days' ) ,1, config.release_time_fence_days, m.RELEASE_TIME_FENCE_DAYS) ,
9790 decode( get_attribute_control( 'defect_tracking_on_flag') , 1, config.defect_tracking_on_flag, m.DEFECT_TRACKING_ON_FLAG) ,
9791 decode( get_attribute_control( 'serv_importance_level'), 1, config.serv_importance_level, m.SERV_IMPORTANCE_LEVEL) ,
9792 decode( get_attribute_control( 'web_status') , 1, config.web_status, m.web_status) , -- bugfix 2727983
9793 decode( get_attribute_control( 'tracking_quantity_ind' ) , 1 , config.tracking_quantity_ind, nvl( m.tracking_quantity_ind , 'P' )),
9794 decode( get_attribute_control( 'ont_pricing_qty_source' ) , 1 , config.ont_pricing_qty_source, nvl( m.ont_pricing_qty_source, 'P')) ,
9795 decode( get_attribute_control( 'approval_status' ) , 1 , config.approval_status, m.approval_status) ,
9796 decode( get_attribute_control( 'vmi_minimum_units' ) , 1, config.vmi_minimum_units, m.vmi_minimum_units) ,
9797 decode( get_attribute_control( 'vmi_minimum_days' ) ,1 , config.vmi_minimum_days, m.vmi_minimum_days) ,
9798 decode( get_attribute_control( 'vmi_maximum_units' ) , 1 , config.vmi_maximum_units, m.vmi_maximum_units) ,
9799 decode( get_attribute_control( 'vmi_maximum_days' ) , 1 , config.vmi_maximum_days, m.vmi_maximum_days ) ,
9800 decode( get_attribute_control( 'vmi_fixed_order_quantity' ) , 1 , config.vmi_fixed_order_quantity, m.vmi_fixed_order_quantity) ,
9801 decode( get_attribute_control( 'so_authorization_flag' ) , 1, config.so_authorization_flag, m.so_authorization_flag ) ,
9802 decode( get_attribute_control( 'consigned_flag' ) , 1, config.consigned_flag, m.consigned_flag) ,
9803 decode( get_attribute_control( 'asn_autoexpire_flag' ) , 1 , config.asn_autoexpire_flag, m.asn_autoexpire_flag ) ,
9804 decode( get_attribute_control( 'vmi_forecast_type' ) , 1 , config.vmi_forecast_type, m.vmi_forecast_type) ,
9805 decode( get_attribute_control( 'forecast_horizon' ) , 1, config.forecast_horizon, m.forecast_horizon ) ,
9806 decode( get_attribute_control( 'days_tgt_inv_supply' ) , 1, config.days_tgt_inv_supply, m.days_tgt_inv_supply ) ,
9807 decode( get_attribute_control( 'days_tgt_inv_window' ) , 1 , config.days_tgt_inv_window, m.days_tgt_inv_window ) ,
9808 decode( get_attribute_control( 'days_max_inv_supply' ) , 1, config.days_max_inv_supply, m.days_max_inv_supply ) ,
9809 decode( get_attribute_control( 'days_max_inv_window' ) , 1 , config.days_max_inv_window, m.days_max_inv_window ) ,
9810 decode( get_attribute_control( 'critical_component_flag' ) , 1, config.critical_component_flag, m.critical_component_flag) ,
9811 decode( get_attribute_control( 'drp_planned_flag' ) ,1 , config.drp_planned_flag, m.drp_planned_flag ) ,
9812 decode( get_attribute_control( 'exclude_from_budget_flag' ) , 1 , config.exclude_from_budget_flag, m.exclude_from_budget_flag) ,
9813 decode( get_attribute_control( 'convergence' ) , 1 , config.convergence, m.convergence ) ,
9814 decode( get_attribute_control( 'continous_transfer' ) , 1, config.continous_transfer, m.continous_transfer ) ,
9815 decode( get_attribute_control( 'divergence' ) , 1 , config.divergence, m.divergence ),
9816 --begin r12,4574899
9817 nvl(m.lot_divisible_flag, 'N'), --Bugfix 6343429
9818 'N',
9819 'N',
9820 'N',
9821 'N',
9822 'N',
9823 'N',
9824 'N',
9825 'N',
9826 'N',
9827 'N',
9828 3, --repair_program
9829 2 --outsourced_assembly
9830 --end r12,4574899
9831 from
9832 mtl_system_items_b m, -- Model
9833 mtl_system_items_b config,
9834 bom_cto_order_lines bcol,
9835 bom_cto_src_orgs bcso
9836 where m.inventory_item_id = p_model_id
9837 and bcso.model_item_id = p_model_id
9838 and bcso.line_id = p_line_id
9839 and bcso.line_id = bcol.line_id
9840 and bcol.config_item_id = config.inventory_item_id
9841 and config.organization_id = bcol.ship_from_org_id
9842 and m.organization_id = bcso.organization_id
9843 and NOT EXISTS
9844 (select NULL
9845 from mtl_system_items_b
9846 where inventory_item_id = p_config_id
9847 and organization_id = bcso.organization_id);
9848
9849
9850
9851
9852
9853
9854
9855 exception
9856 when others then
9857 null ;
9858
9859 end create_preconfigured_item ;
9860
9861
9862
9863
9864
9865 end CTO_CONFIG_ITEM_PK;
9866