[Home] [Help]
PACKAGE BODY: APPS.BOM_COPY_BILL
Source
1 PACKAGE BODY bom_copy_bill AS
2 -- $Header: BOMCPYBB.pls 120.50.12020000.3 2012/08/13 13:44:16 rambkond ship $
3 -- +==============================================================================+
4 -- | Copyright (c) 1995 Oracle Corporation, California, USA |
5 -- | All rights reserved. |
6 -- +==============================================================================+
7 -- | |
8 -- | File Name : BOMCPYBB.pls |
9 -- | Description : Bill copy package [BODY] |
10 -- | Created By : Manu Chadha |
11 -- | Updatded By : Refai Farook (13-SEP-01) Copy the additional operations |
12 -- | also along with other entities (one to many changes) |
13 -- | |
14 -- | from_org_id Copy from org id |
15 -- | to_org_id Copy to org id |
16 -- | from_sequence_id Copy from bill sequence id |
17 -- | to_sequence_id Copy to bill sequence id |
18 -- | display_option copy option |
19 -- | 1 - all (not supported from form) |
20 -- | 2 - current |
21 -- | 3 - current + future |
22 -- | user_id user id |
23 -- | to_item_id Copy to item id |
24 -- | direction direction of copy |
25 -- | 1 - BOM to BOM |
26 -- | 2 - BOM to ENG |
27 -- | 3 - ENG to ENG |
28 -- | 4 - ENG to BOM |
29 -- | to_alternate Copy to alternate designator |
30 -- | rev_date Revision date to copy |
31 -- | |
32 -- | 01/09/2003 kIRAN kONADA |
33 -- | BUGFIX 2740820 |
34 -- | NEW COLUMNS ADDED IN BOM_INVENTORY_COMPONENTS |
35 -- | FOR CTO NEED TO COPIED DURING COPY_BILL PROCESS |
36 -- | 01/10/2003 Kiran Konada |
37 -- | bugfix 2740820 |
38 -- | cpoying another attribute plan_level |
39 -- | |
40 -- | 15-SEP-2003 Ezhilarasan Added overloaded copy_bill |
41 -- | procedure for specific components, |
42 -- | reference designators, substitute components |
43 -- | copy etc., |
44 -- | 11-MAY-2004 Ezhilarasan R12 ENH Transfer To Multiple Orgs (TTM) |
45 -- | |
46 -- +==============================================================================+
47 PROCEDURE bill_get_msg_info (
48 total_inventory_components OUT NOCOPY NUMBER,
49 total_assembly_comments OUT NOCOPY NUMBER,
50 total_reference_designators OUT NOCOPY NUMBER,
51 total_substitute_components OUT NOCOPY NUMBER,
52 from_bill_seq_id IN NUMBER,
53 revision_date IN DATE,
54 display_option IN NUMBER,
55 unit_number IN VARCHAR2 DEFAULT NULL,
56 from_org_id IN NUMBER,
57 from_item_id IN NUMBER,
58 unit_assembly IN VARCHAR2
59 )
60 IS
61 sql_stmt_num NUMBER;
62 err_msg VARCHAR2 (2000);
63 x_unit_assembly VARCHAR2 (2) := unit_assembly;
64 BEGIN
65 sql_stmt_num := 1;
66
67 SELECT COUNT (*)
68 INTO total_inventory_components
69 FROM bom_inventory_components
70 WHERE bill_sequence_id = from_bill_seq_id
71 AND NVL (eco_for_production, 2) = 2
72 AND ((x_unit_assembly = 'N'
73 AND ((display_option = 1) -- ALL
74 OR (display_option = 2
75 AND (effectivity_date <= revision_date
76 AND (disable_date > revision_date
77 OR disable_date IS NULL
78 )
79 )
80 )
81 OR -- CURRENT
82 (display_option = 3
83 AND (disable_date > revision_date
84 OR disable_date IS NULL
85 )
86 )
87 ) -- CURRENT + FUTURE
88 )
89 OR (x_unit_assembly = 'Y'
90 AND ((display_option = 1) -- ALL
91 OR (display_option = 2
92 AND disable_date IS NULL
93 AND (from_end_item_unit_number <= unit_number
94 AND (to_end_item_unit_number >= unit_number
95 OR to_end_item_unit_number IS NULL
96 )
97 )
98 )
99 OR -- CURRENT
100 (display_option = 3
101 AND disable_date IS NULL
102 AND (to_end_item_unit_number >= unit_number
103 OR to_end_item_unit_number IS NULL
104 )
105 )
106 ) -- CURRENT + FUTURE
107 )
108 );
109
110 sql_stmt_num := 2;
111
112 SELECT COUNT (*)
113 INTO total_assembly_comments
114 FROM fnd_attached_documents
115 WHERE entity_name = 'BOM_BILL_OF_MATERIALS'
116 AND pk1_value = to_char(from_bill_seq_id);
117
118 sql_stmt_num := 3;
119
120 SELECT COUNT (*)
121 INTO total_reference_designators
122 FROM bom_reference_designators brd,
123 bom_inventory_components bic
124 WHERE bic.bill_sequence_id = from_bill_seq_id
125 AND NVL (bic.eco_for_production, 2) = 2
126 AND bic.component_sequence_id = brd.component_sequence_id
127 AND ((x_unit_assembly = 'N'
128 AND ((display_option = 1) -- ALL
129 OR (display_option = 2
130 AND (bic.effectivity_date <= revision_date
131 AND (bic.disable_date > revision_date
132 OR bic.disable_date IS NULL
133 )
134 )
135 )
136 OR -- CURRENT
137 (display_option = 3
138 AND (bic.disable_date > revision_date
139 OR bic.disable_date IS NULL
140 )
141 ) -- CURRENT + FUTURE
142 )
143 )
144 OR (x_unit_assembly = 'Y'
145 AND ((display_option = 1) -- ALL
146 OR (display_option = 2
147 AND bic.disable_date IS NULL
148 AND (bic.from_end_item_unit_number <= unit_number
149 AND (bic.to_end_item_unit_number >=
150 unit_number
151 OR bic.to_end_item_unit_number IS NULL
152 )
153 )
154 )
155 OR -- CURRENT
156 (display_option = 3
157 AND bic.disable_date IS NULL
158 AND (bic.to_end_item_unit_number >= unit_number
159 OR bic.to_end_item_unit_number IS NULL
160 )
161 )
162 ) -- CURRENT + FUTURE
163 )
164 );
165
166 sql_stmt_num := 4;
167
168 SELECT COUNT (*)
169 INTO total_substitute_components
170 FROM bom_substitute_components bsc,
171 bom_inventory_components bic
172 WHERE bic.bill_sequence_id = from_bill_seq_id
173 AND NVL (bic.eco_for_production, 2) = 2
174 AND bic.component_sequence_id = bsc.component_sequence_id
175 AND ((x_unit_assembly = 'N'
176 AND ((display_option = 1) -- ALL
177 OR (display_option = 2
178 AND (bic.effectivity_date <= revision_date
179 AND (bic.disable_date > revision_date
180 OR bic.disable_date IS NULL
181 )
182 )
183 )
184 OR -- CURRENT
185 (display_option = 3
186 AND (bic.disable_date > revision_date
187 OR bic.disable_date IS NULL
188 )
189 )
190 ) -- CURRENT + FUTURE
191 )
192 OR (x_unit_assembly = 'Y'
193 AND ((display_option = 1) -- ALL
194 OR (display_option = 2
195 AND bic.disable_date IS NULL
196 AND (bic.from_end_item_unit_number <= unit_number
197 AND (bic.to_end_item_unit_number >=
198 unit_number
199 OR bic.to_end_item_unit_number IS NULL
200 )
201 )
202 )
203 OR -- CURRENT
204 (display_option = 3
205 AND bic.disable_date IS NULL
206 AND (bic.to_end_item_unit_number >= unit_number
207 OR bic.to_end_item_unit_number IS NULL
208 )
209 )
210 ) -- CURRENT + FUTURE
211 )
212 );
213 EXCEPTION
214 WHEN OTHERS
215 THEN
216 err_msg := 'BILL_GET_MSG_INFO (' || sql_stmt_num || ') ' || SQLERRM;
217 fnd_message.set_name ('BOM', 'BOM_SQL_ERR');
218 fnd_message.set_token ('ENTITY', err_msg);
219 ROLLBACK TO begin_bill_copy;
220 app_exception.raise_exception;
221 END bill_get_msg_info;
222
223 PROCEDURE bill_get_msg_info_compops (
224 total_component_operations OUT NOCOPY NUMBER,
225 from_bill_seq_id IN NUMBER,
226 revision_date IN DATE,
227 display_option IN NUMBER,
228 unit_number IN VARCHAR2 DEFAULT NULL,
229 from_org_id IN NUMBER,
230 from_item_id IN NUMBER,
231 unit_assembly IN VARCHAR2
232 )
233 IS
234 sql_stmt_num NUMBER;
235 err_msg VARCHAR2 (2000);
236 x_unit_assembly VARCHAR2 (2) := unit_assembly;
237 BEGIN
238 sql_stmt_num := 1;
239
240 SELECT COUNT (*)
241 INTO total_component_operations
242 FROM bom_inventory_components bic,
243 bom_component_operations bco
244 WHERE bic.bill_sequence_id = from_bill_seq_id
245 AND NVL (bic.eco_for_production, 2) = 2
246 AND bic.component_sequence_id = bco.component_sequence_id
247 AND ((x_unit_assembly = 'N'
248 AND ((display_option = 1) -- ALL
249 OR (display_option = 2
250 AND (bic.effectivity_date <= revision_date
251 AND (bic.disable_date > revision_date
252 OR bic.disable_date IS NULL
253 )
254 )
255 )
256 OR -- CURRENT
257 (display_option = 3
258 AND (bic.disable_date > revision_date
259 OR bic.disable_date IS NULL
260 )
261 )
262 ) -- CURRENT + FUTURE
263 )
264 OR (x_unit_assembly = 'Y'
265 AND ((display_option = 1) -- ALL
266 OR (display_option = 2
267 AND bic.disable_date IS NULL
268 AND (bic.from_end_item_unit_number <= unit_number
269 AND (bic.to_end_item_unit_number >=
270 unit_number
271 OR bic.to_end_item_unit_number IS NULL
272 )
273 )
274 )
275 OR -- CURRENT
276 (display_option = 3
277 AND bic.disable_date IS NULL
278 AND (bic.to_end_item_unit_number >= unit_number
279 OR bic.to_end_item_unit_number IS NULL
280 )
281 )
282 ) -- CURRENT + FUTURE
283 )
284 );
285 EXCEPTION
286 WHEN OTHERS
287 THEN
288 err_msg :=
289 'BILL_GET_MSG_INFO_COMPOPS (' || sql_stmt_num || ') ' || SQLERRM;
290 fnd_message.set_name ('BOM', 'BOM_SQL_ERR');
291 fnd_message.set_token ('ENTITY', err_msg);
292 ROLLBACK TO begin_bill_copy;
293 app_exception.raise_exception;
294 END bill_get_msg_info_compops;
295
296 PROCEDURE copy_bill (
297 to_sequence_id IN NUMBER,
298 from_sequence_id IN NUMBER,
299 from_org_id IN NUMBER,
300 to_org_id IN NUMBER,
301 display_option IN NUMBER DEFAULT 2,
302 user_id IN NUMBER DEFAULT -1,
303 to_item_id IN NUMBER,
304 direction IN NUMBER DEFAULT 1,
305 to_alternate IN VARCHAR2,
306 rev_date IN DATE,
307 e_change_notice IN VARCHAR2,
308 rev_item_seq_id IN NUMBER,
309 bill_or_eco IN NUMBER,
310 eco_eff_date IN DATE,
311 eco_unit_number IN VARCHAR2 DEFAULT NULL,
312 unit_number IN VARCHAR2 DEFAULT NULL,
313 from_item_id IN NUMBER
314 )
315 IS
316 BEGIN
317 /*
318 * Call the over loaded procedure with the default values for parameters
319 * in the over loaded procedure.
320 */
321 copy_bill (to_sequence_id => to_sequence_id,
322 from_sequence_id => from_sequence_id,
323 from_org_id => from_org_id,
324 to_org_id => to_org_id,
325 display_option => display_option,
326 user_id => user_id,
327 to_item_id => to_item_id,
328 direction => direction,
329 to_alternate => to_alternate,
330 rev_date => rev_date,
331 e_change_notice => e_change_notice,
332 rev_item_seq_id => rev_item_seq_id,
333 bill_or_eco => bill_or_eco,
334 eco_eff_date => eco_eff_date,
335 eco_unit_number => eco_unit_number,
336 unit_number => unit_number,
337 from_item_id => from_item_id,
338 specific_copy_flag => 'N',
339 copy_attach_flag => 'Y',
340 p_copy_request_id => NULL,
341 eco_end_item_rev_id => NULL,
342 context_eco => NULL,
343 p_end_item_rev_id => NULL,
344 trgt_comps_eff_date => NULL,
345 trgt_comps_unit_number => NULL,
346 trgt_comps_end_item_rev_id => NULL,
347 p_parent_sort_order => NULL,
348 p_cpy_disable_fields => 'N'
349 );
350 END copy_bill;
351
352 FUNCTION get_current_item_rev (
353 p_item_id IN NUMBER,
354 p_org_id IN NUMBER,
355 p_rev_date IN DATE
356 )
357 RETURN VARCHAR2
358 IS
359 l_current_rev VARCHAR2 (10);
360
361 CURSOR item_rev_cursor (
362 p_item_id IN NUMBER,
363 p_org_id IN NUMBER,
364 p_rev_date IN DATE
365 )
366 IS
367 SELECT REVISION
368 FROM (
369 SELECT revision
370 FROM mtl_item_revisions_b mir
371 WHERE mir.inventory_item_id = p_item_id
372 AND mir.organization_id = p_org_id
373 AND mir.effectivity_date <= p_rev_date
374 ORDER BY mir.effectivity_date DESC)
375 WHERE ROWNUM < 2;
376
377 no_item_rev_exists EXCEPTION;
378 BEGIN
379 OPEN item_rev_cursor (p_item_id, p_org_id, p_rev_date);
380
381 LOOP
382 FETCH item_rev_cursor
383 INTO l_current_rev;
384
385 EXIT WHEN item_rev_cursor%NOTFOUND;
386 END LOOP;
387
388 IF l_current_rev IS NULL
389 OR '' = l_current_rev
390 THEN
391 CLOSE item_rev_cursor;
392
393 RAISE no_item_rev_exists;
394 END IF;
395
396 IF item_rev_cursor%ISOPEN THEN
397 CLOSE item_rev_cursor;
398 END IF;
399
400 RETURN l_current_rev;
401 END get_current_item_rev;
402
403 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
404 ** Function: revision_exists
405 ** Scope : Local
406 ** Purpose : This function was added to get around 8i compatibility issues
407 ** This function replaces the CASE statement with a decode and a call
408 ** to this function
409 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
410 FUNCTION revision_exists (
411 p_from_item_id IN NUMBER,
412 p_from_org_id IN NUMBER,
413 p_revision_id IN NUMBER
414 )
415 RETURN VARCHAR2
416 IS
417 l_return VARCHAR2 (1);
418 BEGIN
419 l_return := 'T';
420
421 SELECT 'T'
422 INTO l_return
423 FROM DUAL
424 WHERE EXISTS (
425 SELECT revision_id
426 FROM mtl_item_revisions_b
427 WHERE inventory_item_id = p_from_item_id
428 AND organization_id = p_from_org_id
429 AND revision_id = p_revision_id);
430
431 RETURN l_return;
432 END revision_exists;
433
434 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
435 ** Function: Get_Max_Revision
436 ** Scope : Local
437 ** Purpose: This function was added to get around the 8i compatibility issues.
438 **
439 *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
440 FUNCTION get_max_minorrev (
441 p_item_id IN NUMBER,
442 p_org_id IN NUMBER,
443 p_revision_id IN NUMBER
444 )
445 RETURN NUMBER
446 IS
447 l_minor_rev_id NUMBER;
448 BEGIN
449 SELECT NVL (MAX (minor_revision_id), 0)
450 INTO l_minor_rev_id
451 FROM ego_minor_revisions
452 WHERE obj_name = 'EGO_ITEM'
453 AND pk1_value = p_item_id
454 AND NVL (pk2_value, '-1') = NVL (p_org_id, '-1')
455 AND NVL (pk3_value, '-1') = NVL (p_revision_id, '-1');
456
457 RETURN l_minor_rev_id;
458 EXCEPTION
459 WHEN OTHERS
460 THEN
461 RETURN NULL;
462 END get_max_minorrev;
463
464 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
465 ** Function: Get_Revision
466 ** Scope : Local
467 ** Purpiose: This function was added to get around the 8i compatibility issues.
468 **
469 *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
470 FUNCTION get_revision (
471 p_item_id IN NUMBER,
472 p_org_id IN NUMBER,
473 p_revision_id IN NUMBER
474 )
475 RETURN NUMBER
476 IS
477 l_revision_id NUMBER;
478 BEGIN
479 SELECT tmirb.revision_id
480 INTO l_revision_id
481 FROM mtl_item_revisions_b fmirb,
482 mtl_item_revisions_b tmirb
483 WHERE tmirb.inventory_item_id = p_item_id
484 AND tmirb.organization_id = p_org_id
485 AND tmirb.revision = fmirb.revision
486 AND fmirb.revision_id = p_revision_id;
487
488 RETURN l_revision_id;
489 EXCEPTION
490 WHEN NO_DATA_FOUND
491 THEN
492 RETURN NULL;
493 END get_revision;
494
495 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
496 ** Function: Get_Minor_Rev_Code
497 ** Scope : Local
498 ** Purpose: This function was added to get around the 8i compatibility issues.
499 **
500 *++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
501 FUNCTION get_minor_rev_code (
502 p_end_item_rev_id IN NUMBER,
503 p_end_item_minor_rev_id IN NUMBER
504 )
505 RETURN VARCHAR2
506 IS
507 l_rev_code NUMBER;
508 BEGIN
509 SELECT CONCAT (TO_CHAR (effectivity_date, 'yyyymmddhh24miss'),
510 TO_CHAR (NVL (p_end_item_minor_rev_id, 9999999999999999))
511 )
512 INTO l_rev_code
513 FROM mtl_item_revisions_b
514 WHERE revision_id = p_end_item_rev_id;
515
516 RETURN l_rev_code;
517 EXCEPTION
518 WHEN NO_DATA_FOUND
519 THEN
520 RETURN NULL;
521 END get_minor_rev_code;
522
523 /* This procedure can be used in following scenarios:
524 * i) Specific components, reference designators and substitute components have to be copied.
525 * ii) Where attachments have to be copied for the bill.
526 * iii) If some of the components in the destination bill has to be replaced with some other components.
527 * iv) If only components, reference designators or substitute components needs to be copied.
528 * specific_copy_flag -- This flag species whether we need to copy all components or specific.
529 * copy_all_comps_flag -- Flag specifies whether all the components needs to be copied.
530 * copy_all_rfds_flag -- Flag specifies whether all the reference designators for the components needs to be copied.
531 * copy_all_sub_comps_flag -- Flag specifies whether all the substitute components for the components needs to be copied.
532 * copy_attach_flag -- Specifies whether attachments needs to be copied.
533 */
534 PROCEDURE copy_bill (
535 to_sequence_id IN NUMBER,
536 from_sequence_id IN NUMBER,
537 from_org_id IN NUMBER,
538 to_org_id IN NUMBER,
539 display_option IN NUMBER DEFAULT 2,
540 user_id IN NUMBER DEFAULT -1,
541 to_item_id IN NUMBER,
542 direction IN NUMBER DEFAULT 1,
543 to_alternate IN VARCHAR2,
544 rev_date IN DATE,
545 e_change_notice IN VARCHAR2,
546 rev_item_seq_id IN NUMBER,
547 bill_or_eco IN NUMBER,
548 eco_eff_date IN DATE,
549 eco_unit_number IN VARCHAR2 DEFAULT NULL,
550 unit_number IN VARCHAR2 DEFAULT NULL,
551 from_item_id IN NUMBER,
552 -- to_minor_rev_id IN NUMBER DEFAULT NULL,
553 -- Flag, which specifies the type of copy. Default value takes care of the existing API call
554 -- from ERP. 'Y' Selective copy 'N' Copy all components
555 specific_copy_flag IN VARCHAR2,
556 copy_all_comps_flag IN VARCHAR2 DEFAULT 'N',
557 copy_all_rfds_flag IN VARCHAR2 DEFAULT 'N',
558 copy_all_subcomps_flag IN VARCHAR2 DEFAULT 'N',
559 -- copy_all_compops_flag IN VARCHAR2 DEFAULT 'N',
560 copy_attach_flag IN VARCHAR2 DEFAULT 'Y',
561 -- Request Id for this copy operation. Value from BOM_COPY_STRUCTURE_REQUEST_S
562 -- To populate the errors in MTL_INTERFACE_ERRORS with this transaction id
563 p_copy_request_id IN NUMBER,
564 -- Unit number for copy to item
565 eco_end_item_rev_id IN NUMBER DEFAULT NULL,
566 -- Structure has been exploded in context of this ECO for copying
567 context_eco IN VARCHAR2 DEFAULT NULL,
568 p_end_item_rev_id IN NUMBER DEFAULT NULL,
569 -- Effectivity Date, End Item Unit Number and End Item Rev Id
570 -- for the components which are getting copied. Components from effectivity boundary.
571 trgt_comps_eff_date IN DATE DEFAULT NULL,
572 trgt_comps_unit_number IN VARCHAR2 DEFAULT NULL,
573 trgt_comps_end_item_rev_id IN NUMBER DEFAULT NULL,
574 -- Since the JOIN occurs with bom_copy_explosions_v, there could be multiple
575 -- sub-assemblies (items) in the exploded structure at different levels
576 -- but if we copy once that will be suffice
577 p_parent_sort_order IN VARCHAR2 DEFAULT NULL,
578 p_cpy_disable_fields IN VARCHAR2 DEFAULT 'N',
579 p_trgt_str_eff_ctrl IN NUMBER DEFAULT 1,
580 p_trgt_str_type_id IN NUMBER DEFAULT NULL
581 )
582 IS
583 bom_to_bom CONSTANT NUMBER := 1;
584 bom_to_eng CONSTANT NUMBER := 2;
585 eng_to_eng CONSTANT NUMBER := 3;
586 eng_to_bom CONSTANT NUMBER := 4;
587 model CONSTANT NUMBER := 1;
588 option_class CONSTANT NUMBER := 2;
589 planning CONSTANT NUMBER := 3;
590 STANDARD CONSTANT NUMBER := 4;
591 phantom CONSTANT NUMBER := 6;
592 x_from_sequence_id NUMBER := from_sequence_id;
593 x_from_org_id NUMBER := from_org_id;
594 to_rtg_seq_id NUMBER;
595 itm_cat_grp_id NUMBER;
596 dummy NUMBER;
597 sql_stmt_num NUMBER;
598 base_item_flag NUMBER;
599 itm_type NUMBER;
600 copy_comps NUMBER;
601 copy_comts NUMBER;
602 copy_subs NUMBER;
603 copy_desgs NUMBER;
604 copy_compops NUMBER;
605 copy_atts NUMBER;
606 err_msg VARCHAR (2000);
607 atp_comp_flag VARCHAR2 (1);
608 rto_flag VARCHAR2 (1);
609 old_max NUMBER := 0;
610 new_seq_num NUMBER := 0;
611 processed NUMBER := 0;
612 tmp_var NUMBER := 0;
613 total_inventory_components NUMBER := 0;
614 total_assembly_comments NUMBER := 0;
615 total_reference_designators NUMBER := 0;
616 total_substitute_components NUMBER := 0;
617 total_component_operations NUMBER := 0;
618 l_to_item_rev_id NUMBER := -1;
619 l_to_item_minor_rev_id NUMBER := 0;
620 error_status VARCHAR2 (1) := 'F';
621 msg_count NUMBER := 0;
622 item_rev VARCHAR2 (3) := NULL;
623 l_item_rev_date DATE := SYSDATE;
624 l_from_item_rev_id NUMBER;
625 l_from_item_rev VARCHAR2 (3) := NULL;
626 l_return_status VARCHAR2 (1) := 'S';
627 l_item_number VARCHAR2 (80) := NULL;
628 l_org_code VARCHAR2 (3) := NULL;
629 l_uom_code VARCHAR2 (3) := NULL;
630 p_commit VARCHAR2 (8) := 'FALSE';
631 l_msg_count NUMBER := 0;
632 l_item_rec_in inv_item_grp.item_rec_type;
633 l_item_rec_out inv_item_grp.item_rec_type;
634 l_error_tbl inv_item_grp.error_tbl_type;
635 l_dest_pk_col_name_val_pairs ego_col_name_value_pair_array;
636 l_src_pk_col_name_val_pairs ego_col_name_value_pair_array;
637 l_new_str_type ego_col_name_value_pair_array;
638 l_str_type NUMBER;
639 l_errorcode NUMBER;
640 l_msg_data VARCHAR2 (100);
641 x_acd_type NUMBER;
642 x_rev_item_seq_id NUMBER;
643 x_e_change_notice VARCHAR2 (10);
644 x_effectivity_date DATE;
645 x_unit_number VARCHAR2 (30);
646 x_end_item_rev_id NUMBER;
647 x_unit_assembly VARCHAR2 (2) := 'N';
648 overlap_error EXCEPTION;
649 common_error EXCEPTION;
650 no_item_rev_exists EXCEPTION;
651 no_minor_rev_exists EXCEPTION;
652 no_minor_rev_code_exists EXCEPTION;
653 l_count1 NUMBER;
654 l_count2 NUMBER;
655 l_count3 NUMBER;
656 l_comp_ctr NUMBER;
657 /*
658 l_copied_comp_seq num_varray := num_varray
659 ();
660 l_copied_comp_item_id num_varray := num_varray
661 ();
662 l_copied_op_seq_num num_varray := num_varray
663 ();
664 l_mapped_comp_seq num_varray := num_varray
665 ();
666 */
667 -- l_from_end_item_minor_rev_code VARCHAR2(30);
668 -- l_from_bom_item_minor_rev_code VARCHAR2 (30);
669 l_from_eff_ctrl bom_structures_b.effectivity_control%TYPE;
670 l_to_eff_ctrl bom_structures_b.effectivity_control%TYPE;
671 l_no_access_comp_cnt NUMBER;
672 l_fixed_rev mtl_item_revisions_b.revision%TYPE;
673 l_current_item_rev mtl_item_revisions_b.revision%TYPE;
674 l_current_item_rev_id mtl_item_revisions_b.revision_id%TYPE;
675 l_use_eco_flag varchar2(1) := 'N';
676 l_error_msg_tbl Error_Handler.Error_Tbl_Type;
677
678 l_default_wip_params NUMBER;
679 -- l_from_end_item_id NUMBER;
680 -- l_to_end_item_min_revision_id NUMBER;
681 ---- Bug Fix 4279959 Install testing issue
682 /*
683 ();
684 copy_rfds_arr num_varray := num_varray
685 ();
686 copy_subcomps_arr num_varray := num_varray
687 ();
688 */
689 l_from_comps num_varray := num_varray
690 ();
691 l_to_comps num_varray := num_varray
692 ();
693 l_data_level_name_comp VARCHAR2(30) := 'COMPONENTS_LEVEL';
694 l_data_level_id_comp NUMBER;
695 l_old_dtlevel_col_value_pairs EGO_COL_NAME_VALUE_PAIR_ARRAY;
696 l_new_dtlevel_col_value_pairs EGO_COL_NAME_VALUE_PAIR_ARRAY;
697
698
699 CURSOR l_common_csr
700 IS
701 SELECT 1
702 FROM DUAL
703 WHERE EXISTS (
704 SELECT NULL
705 FROM bom_structures_b bom,
706 bom_inventory_components bic
707 WHERE bom.organization_id <> to_org_id
708 AND bom.common_bill_sequence_id = to_sequence_id
709 AND bic.bill_sequence_id = to_sequence_id
710 AND NOT EXISTS (
711 SELECT NULL
712 FROM mtl_system_items cmsi,
713 mtl_system_items bmsi
714 WHERE cmsi.organization_id = bom.organization_id
715 AND cmsi.inventory_item_id =
716 bic.component_item_id
717 AND bmsi.organization_id = bom.organization_id
718 AND bmsi.inventory_item_id =
719 bom.assembly_item_id
720 AND cmsi.eng_item_flag =
721 DECODE (bom.assembly_type,
722 1, 'N',
723 2, cmsi.eng_item_flag
724 )
725 AND cmsi.bom_enabled_flag = 'Y'
726 AND cmsi.inventory_item_id <>
727 bom.assembly_item_id
728 AND ((bmsi.bom_item_type = 1
729 AND cmsi.bom_item_type <> 3
730 )
731 OR (bmsi.bom_item_type = 2
732 AND cmsi.bom_item_type <> 3
733 )
734 OR (bmsi.bom_item_type = 3)
735 OR (bmsi.bom_item_type = 4
736 AND (cmsi.bom_item_type = 4
737 OR (cmsi.bom_item_type IN (1, 2)
738 AND cmsi.replenish_to_order_flag =
739 'Y'
740 AND bmsi.base_item_id IS NOT NULL
741 AND bmsi.replenish_to_order_flag =
742 'Y'
743 )
744 )
745 )
746 )
747 AND (bmsi.bom_item_type = 3
748 OR bmsi.pick_components_flag = 'Y'
749 OR cmsi.pick_components_flag = 'N'
750 )
751 AND (bmsi.bom_item_type = 3
752 OR NVL (cmsi.bom_item_type, 4) <> 2
753 OR (cmsi.bom_item_type = 2
754 AND ((bmsi.pick_components_flag = 'Y'
755 AND cmsi.pick_components_flag =
756 'Y'
757 )
758 OR (bmsi.replenish_to_order_flag =
759 'Y'
760 AND cmsi.replenish_to_order_flag =
761 'Y'
762 )
763 )
764 )
765 )
766 AND NOT (bmsi.bom_item_type = 4
767 AND bmsi.pick_components_flag = 'Y'
768 AND cmsi.bom_item_type = 4
769 AND cmsi.replenish_to_order_flag = 'Y'
770 )));
771
772 CURSOR item_rev_cursor (
773 p_item_id IN NUMBER,
774 p_org_id IN NUMBER,
775 p_rev_date IN DATE
776 -- , P_IMPL_FLAG IN NUMBER
777 )
778 IS
779 SELECT revision_id,
780 revision
781 FROM mtl_item_revisions_b mir
782 WHERE mir.inventory_item_id = p_item_id
783 AND mir.organization_id = p_org_id
784 AND mir.effectivity_date <= p_rev_date
785 AND ROWNUM < 2
786 -- AND (P_IMPL_FLAG = 2 OR (P_IMPL_FLAG = 1 AND mir.implementation_date IS NOT NULL) )
787 ORDER BY mir.effectivity_date DESC;
788
789 CURSOR item_minor_rev_cursor (
790 p_pk1_value IN VARCHAR2,
791 p_pk2_value IN VARCHAR2,
792 p_pk3_value IN VARCHAR2
793 )
794 IS
795 SELECT NVL (MAX (minor_revision_id), 0) minor_revision_id
796 FROM ego_minor_revisions
797 WHERE obj_name = 'EGO_ITEM'
798 AND pk1_value = p_pk1_value
799 AND NVL (pk2_value, '-1') = NVL (p_pk2_value, '-1')
800 AND NVL (pk3_value, '-1') = NVL (p_pk3_value, '-1');
801
802 CURSOR l_org_item_csr (p_item_id IN NUMBER, p_org_id IN NUMBER)
803 IS
804 SELECT concatenated_segments,
805 primary_uom_code
806 FROM mtl_system_items_b_kfv
807 WHERE inventory_item_id = p_item_id
808 AND organization_id = p_org_id;
809
810 CURSOR getcurrentminorrevcode (
811 p_item_rev_id IN NUMBER,
812 -- p_obj_name IN VARCHAR2,
813 p_pk1_value IN VARCHAR2,
814 p_pk2_value IN VARCHAR2
815 )
816 IS
817 SELECT CONCAT (TO_CHAR (r.effectivity_date, 'yyyymmddhh24miss'),
818 maxr.minor_rev_id
819 ) mrev_code
820 FROM mtl_item_revisions_b r,
821 (SELECT NVL (MAX (minor_revision_id), 0) minor_rev_id
822 FROM ego_minor_revisions
823 WHERE obj_name = 'EGO_ITEM' --p_obj_name
824 AND pk1_value = p_pk1_value
825 AND NVL (pk2_value, '-1') = NVL (p_pk2_value, '-1')
826 AND NVL (pk3_value, '-1') =
827 NVL (TO_CHAR (p_item_rev_id), '-1')) maxr
828 WHERE revision_id = p_item_rev_id;
829
830 /*
831 * This cursor returns the coponent_item_id, comp_seq_id and op_seq_num
832 * of the copied components.
833 */
834 CURSOR get_copied_comps (
835 p_comp_seq_num NUMBER,
836 p_display_option NUMBER,
837 p_direction NUMBER,
838 p_unit_assembly VARCHAR2,
839 p_itm_type NUMBER,
840 p_base_item_flag NUMBER,
841 p_from_sequence_id NUMBER,
842 p_to_item_id NUMBER,
843 p_to_org_id NUMBER,
844 p_rev_date DATE,
845 p_unit_number VARCHAR2
846 )
847 IS
848 SELECT bic.component_sequence_id,
849 bic.component_item_id,
850 bic.operation_seq_num
851 FROM bom_inventory_components bic,
852 mtl_system_items msi
853 WHERE bic.bill_sequence_id = p_from_sequence_id
854 AND bic.component_item_id = msi.inventory_item_id
855 AND bic.component_item_id <> p_to_item_id
856 AND NVL (bic.eco_for_production, 2) = 2
857 AND msi.organization_id = p_to_org_id
858 -- AND MSI.BOM_ENABLED_FLAG = 'Y'
859 AND ((p_direction = eng_to_bom
860 AND msi.eng_item_flag = 'N')
861 OR (p_direction <> eng_to_bom)
862 )
863 AND ((p_unit_assembly = 'N'
864 AND ((p_display_option = 1) -- ALL
865 OR (p_display_option = 2
866 AND (effectivity_date <= p_rev_date
867 AND
868 -- Added condition of sysdate for Bug 2161841
869 ( (disable_date > p_rev_date
870 AND disable_date > SYSDATE
871 )
872 OR disable_date IS NULL
873 )
874 )
875 )
876 OR -- CURRENT
877 (p_display_option = 3
878 AND
879 -- Added condition of sysdate for Bug 2161841
880 ( (disable_date > p_rev_date
881 AND disable_date > SYSDATE
882 )
883 OR disable_date IS NULL
884 )
885 )
886 ) -- CURRENT + FUTURE
887 )
888 OR (p_unit_assembly = 'Y'
889 AND ((p_display_option = 1) -- ALL
890 OR (p_display_option = 2
891 AND disable_date IS NULL
892 AND (from_end_item_unit_number <= p_unit_number
893 AND (to_end_item_unit_number >=
894 p_unit_number
895 OR to_end_item_unit_number IS NULL
896 )
897 )
898 )
899 OR -- CURRENT
900 (p_display_option = 3
901 AND disable_date IS NULL
902 AND (to_end_item_unit_number >= p_unit_number
903 OR to_end_item_unit_number IS NULL
904 )
905 )
906 ) -- CURRENT + FUTURE
907 )
908 )
909 AND ((p_base_item_flag = -1
910 AND p_itm_type = 4
911 AND msi.bom_item_type = 4
912 )
913 OR p_base_item_flag <> -1
914 OR p_itm_type <> 4
915 )
916 AND implementation_date IS NOT NULL
917 AND component_sequence_id = p_comp_seq_num;
918
919 /*
920 * This cursor gets the component in the dest structure
921 * copied from a particular source component.
922 */
923 CURSOR get_mapped_components (
924 p_to_bill_sequence_id NUMBER,
925 p_copied_comp_item_id NUMBER,
926 p_copied_op_seq_num NUMBER
927 )
928 IS
929 /*Ideally we should be doing an effectivity check here as well
930 Left for later*/
931 SELECT component_sequence_id
932 FROM bom_inventory_components bic
933 WHERE bill_sequence_id = p_to_bill_sequence_id
934 AND component_item_id = p_copied_comp_item_id
935 AND operation_seq_num = p_copied_op_seq_num;
936
937 CURSOR l_from_to_comps_csr (
938 p_from_seq_id IN NUMBER,
939 p_to_seq_id IN NUMBER
940 )
941 IS
942 SELECT bcb1.component_sequence_id from_component_seq_id,
943 bcb2.component_sequence_id to_sequence_id
944 FROM bom_components_b bcb1,
945 bom_components_b bcb2
946 WHERE bcb1.bill_sequence_id = p_from_seq_id
947 AND bcb1.component_sequence_id = bcb2.created_by
948 AND bcb2.bill_sequence_id = p_to_seq_id;
949 l_index NUMBER := 0;
950
951 CURSOR l_mark_components_csr (
952 p_change_notice IN VARCHAR2,
953 p_local_org_id IN NUMBER,
954 p_bill_seq_id IN NUMBER
955 )
956 IS
957 SELECT eec.change_id,
958 bcb.component_sequence_id
959 FROM eng_engineering_changes eec,
960 bom_components_b bcb
961 WHERE eec.change_notice = p_change_notice
962 AND eec.organization_id = p_local_org_id
963 AND bcb.bill_sequence_id = p_bill_seq_id;
964 CURSOR l_fixed_rev_comp_csr (
965 p_parent_sort_order IN VARCHAR2
966 )
967 IS
968 SELECT bev.comp_fixed_rev_code
969 FROM bom_copy_explosions_v bev
970 WHERE bev.sort_order = p_parent_sort_order;
971 CURSOR l_eff_date_for_rev_csr (
972 p_inventory_item_id IN NUMBER,
973 p_organization_id IN NUMBER,
974 p_revision IN VARCHAR2
975 )
976 IS
977 SELECT effectivity_date
978 FROM mtl_item_revisions_b
979 WHERE inventory_item_id = p_inventory_item_id
980 AND organization_id = p_organization_id
981 AND revision = p_revision;
982
983 CURSOR C_DATA_LEVEL(p_data_level_name VARCHAR2) IS
984 SELECT DATA_LEVEL_ID
985 FROM EGO_DATA_LEVEL_B
986 WHERE DATA_LEVEL_NAME = p_data_level_name;
987
988 --added for bug 10078346 (begin)
989 l_app_id number;
990 l_context varchar2(200);
991 l_context_column varchar2(30);
992 l_prof_check varchar2(15);
993 l_prof_name varchar2(200);
994 l_prof_val varchar2(30) :=null;
995 --added for bug 9725474 (end)
996
997
998
999 BEGIN
1000 SAVEPOINT begin_bill_copy;
1001
1002
1003
1004 -- dbms_profiler.start_profiler(' COPY BILL CALL ' || to_char(sysdate,'dd-mm-yyyy hh24:mi:ss'));
1005 /*
1006 Debug values
1007 a_debug('to_sequence_id '|| to_sequence_id);
1008 a_debug('from_sequence_id '|| from_sequence_id);
1009 a_debug('from_org_id '|| from_org_id);
1010 a_debug('to_org_id '||to_org_id);
1011 a_debug('display option ' || display_option);
1012 a_debug('user_id '|| user_id);
1013 a_debug('direction '||direction);
1014 a_debug('rev_date ' || to_char(rev_date,'DD-MON-YYYY HH24:MI:SS'));
1015 a_debug('change notice ' || e_change_notice);
1016 a_debug('bill_or_eco ' || bill_or_eco);
1017 a_debug('from item id '||from_item_id);
1018 a_debug('specific copy flag '||specific_copy_flag);
1019 a_debug(' copy_all_comps_flag '|| copy_all_comps_flag);
1020 a_debug('unit number '|| unit_number);
1021 -- a_debug('from_end_item_id ' || from_end_item_id);
1022 -- a_debug('from_end_item_revision_id '||from_end_item_revision_id);
1023 -- a_debug('from_end_item_min_revision_id '|| from_end_item_min_revision_id);
1024 -- a_debug('to_end_item_id '|| to_end_item_id);
1025 -- a_debug('to_end_item_revision_id '||to_end_item_revision_id);
1026 -- a_debug('to_end_item_min_revision_id '||to_end_item_min_revision_id);
1027
1028 */
1029
1030 /* End Item Rev Eff components are not supported as of now.
1031 IF to_end_item_min_revision_id IS NOT NULL THEN
1032 l_to_end_item_min_revision_id := to_end_item_min_revision_id;
1033 ELSE
1034 OPEN item_minor_rev_cursor(to_char(to_end_item_id), to_char(to_org_id),to_char(to_end_item_revision_id));
1035
1036 LOOP
1037 FETCH item_minor_rev_cursor INTO l_to_end_item_min_revision_id;
1038 EXIT WHEN item_minor_rev_cursor%NOTFOUND;
1039 END LOOP;
1040 IF l_to_end_item_min_revision_id IS NULL OR '' = l_to_end_item_min_revision_id THEN
1041 CLOSE item_minor_rev_cursor;
1042 RAISE NO_MINOR_REV_EXISTS;
1043 END IF;
1044
1045 CLOSE item_minor_rev_cursor;
1046 END IF;
1047 */
1048
1049 --bug:5364225 When copying across orgs, wip supply type will be copied from
1050 --component/component operation. If Default Wip Values profile is set to Yes, then
1051 --supply subinventory and supply locator will be defaulted from item otherwise they
1052 --will be nulled out. When copying within same org, the values will be copied from comp/comp operation.
1053 FND_PROFILE.GET('BOM:DEFAULT_WIP_VALUES', l_default_wip_params);
1054
1055 -- reset from_sequence_id to common_bill_sequence_id
1056 sql_stmt_num := 10;
1057
1058 SELECT common_bill_sequence_id,
1059 NVL (common_organization_id, organization_id)
1060 INTO x_from_sequence_id,
1061 x_from_org_id
1062 FROM bom_structures_b
1063 WHERE bill_sequence_id = x_from_sequence_id;
1064
1065 SELECT structure_type_id, effectivity_control
1066 INTO l_str_type, l_from_eff_ctrl
1067 FROM bom_structures_b
1068 WHERE bill_sequence_id = from_sequence_id;
1069
1070 FOR c_comp_level IN C_DATA_LEVEL(l_data_level_name_comp) LOOP
1071 l_data_level_id_comp := c_comp_level.DATA_LEVEL_ID;
1072 END LOOP;
1073
1074
1075 l_to_eff_ctrl := p_trgt_str_eff_ctrl;
1076
1077 /* End Item Rev Eff components are not supported as of now.
1078 IF from_end_item_id IS NULL THEN
1079 l_from_end_item_id := from_item_id;
1080 ELSE
1081 l_from_end_item_id := from_end_item_id;
1082 END IF;
1083 */
1084
1085 /* Serial Effectivity Implementation */
1086 IF (bom_eamutil.enabled = 'Y'
1087 AND bom_eamutil.serial_effective_item (item_id => from_item_id,
1088 org_id => x_from_org_id
1089 ) = 'Y'
1090 )
1091 OR (pjm_unit_eff.enabled = 'Y'
1092 AND pjm_unit_eff.unit_effective_item
1093 (x_item_id => from_item_id,
1094 x_organization_id => x_from_org_id
1095 ) = 'Y'
1096 )
1097 THEN
1098 x_unit_assembly := 'Y';
1099 ELSE
1100 x_unit_assembly := 'N';
1101 END IF;
1102
1103 --if interorg copy then fetch values for max rows to copy
1104 -- if (X_from_org_id <> to_org_id) then -Bug 1825873
1105 bill_get_msg_info (total_inventory_components,
1106 total_assembly_comments,
1107 total_reference_designators,
1108 total_substitute_components,
1109 x_from_sequence_id,
1110 rev_date,
1111 display_option,
1112 unit_number,
1113 x_from_org_id,
1114 from_item_id,
1115 x_unit_assembly
1116 );
1117 -- end if; -Bug 1825873
1118 -- find out the max rows ro copy for component operations. This is done seperately
1119 -- from the previous procedure since we need the max rows for
1120 -- component operations though the from_org_id and to_org_id are same
1121 bill_get_msg_info_compops (total_component_operations,
1122 x_from_sequence_id,
1123 rev_date,
1124 display_option,
1125 unit_number,
1126 x_from_org_id,
1127 from_item_id,
1128 x_unit_assembly
1129 );
1130 --Load host variables, bill_atp_comps_flag and bill_rto_flag
1131 sql_stmt_num := 15;
1132
1133 SELECT atp_components_flag,
1134 replenish_to_order_flag,
1135 DECODE (base_item_id, NULL, -1, 0),
1136 bom_item_type,
1137 item_catalog_group_id
1138 INTO atp_comp_flag,
1139 rto_flag,
1140 base_item_flag,
1141 itm_type,
1142 itm_cat_grp_id
1143 FROM mtl_system_items
1144 WHERE organization_id = to_org_id
1145 AND inventory_item_id = to_item_id;
1146
1147 sql_stmt_num := 18;
1148
1149 -- These lines were added for the eco form
1150 IF bill_or_eco = 2
1151 THEN -- 2 is from eco
1152 x_acd_type := 1;
1153 x_e_change_notice := e_change_notice;
1154 x_rev_item_seq_id := rev_item_seq_id;
1155 x_effectivity_date := eco_eff_date;
1156 x_unit_number := eco_unit_number;
1157 x_end_item_rev_id := eco_end_item_rev_id;
1158 ELSIF bill_or_eco <> 2
1159 THEN
1160 x_e_change_notice := NULL;
1161 x_acd_type := NULL;
1162 x_rev_item_seq_id := NULL;
1163 x_effectivity_date := NULL;
1164 x_unit_number := NULL;
1165 x_end_item_rev_id := NULL;
1166 END IF;
1167
1168 IF specific_copy_flag = 'Y'
1169 THEN
1170 OPEN l_fixed_rev_comp_csr(p_parent_sort_order);
1171 l_fixed_rev := NULL;
1172 LOOP
1173 FETCH l_fixed_rev_comp_csr
1174 INTO l_fixed_rev;
1175 EXIT WHEN l_fixed_rev_comp_csr%NOTFOUND;
1176 END LOOP;
1177 IF l_fixed_rev_comp_csr%ISOPEN THEN
1178 CLOSE l_fixed_rev_comp_csr;
1179 END IF;
1180
1181 END IF;
1182
1183 IF bill_or_eco = 1 THEN
1184 OPEN item_rev_cursor (to_item_id, to_org_id, trgt_comps_eff_date);
1185
1186 LOOP
1187 FETCH item_rev_cursor
1188 INTO l_current_item_rev_id,
1189 l_current_item_rev;
1190
1191 EXIT WHEN item_rev_cursor%NOTFOUND;
1192 END LOOP;
1193 ELSE
1194 OPEN item_rev_cursor (to_item_id, to_org_id, x_effectivity_date);
1195
1196 LOOP
1197 FETCH item_rev_cursor
1198 INTO l_current_item_rev_id,
1199 l_current_item_rev;
1200
1201 EXIT WHEN item_rev_cursor%NOTFOUND;
1202 END LOOP;
1203 END IF;
1204
1205 IF item_rev_cursor%ISOPEN THEN
1206 CLOSE item_rev_cursor;
1207 END IF;
1208
1209 IF l_fixed_rev IS NOT NULL AND trgt_comps_eff_date IS NOT NULL
1210 THEN
1211 OPEN l_eff_date_for_rev_csr( to_item_id, to_org_id, l_fixed_rev);
1212 LOOP
1213 FETCH l_eff_date_for_rev_csr
1214 INTO l_item_rev_date;
1215 EXIT WHEN l_eff_date_for_rev_csr%NOTFOUND;
1216 END LOOP;
1217 IF l_eff_date_for_rev_csr%ISOPEN THEN
1218 CLOSE l_eff_date_for_rev_csr;
1219 END IF;
1220 END IF;
1221 OPEN item_rev_cursor (to_item_id, to_org_id, l_item_rev_date);
1222
1223 LOOP
1224 FETCH item_rev_cursor
1225 INTO l_to_item_rev_id,
1226 item_rev;
1227
1228 EXIT WHEN item_rev_cursor%NOTFOUND;
1229 END LOOP;
1230
1231 IF item_rev IS NULL
1232 OR '' = item_rev
1233 THEN
1234 CLOSE item_rev_cursor;
1235
1236 RAISE no_item_rev_exists;
1237 END IF;
1238
1239 IF item_rev_cursor%ISOPEN THEN
1240 CLOSE item_rev_cursor;
1241 END IF;
1242
1243 OPEN item_rev_cursor (from_item_id, from_org_id, rev_date);
1244
1245 LOOP
1246 FETCH item_rev_cursor
1247 INTO l_from_item_rev_id,
1248 l_from_item_rev;
1249
1250 EXIT WHEN item_rev_cursor%NOTFOUND;
1251 END LOOP;
1252
1253 IF l_from_item_rev IS NULL
1254 OR '' = l_from_item_rev
1255 THEN
1256 CLOSE item_rev_cursor;
1257
1258 RAISE no_item_rev_exists;
1259 END IF;
1260
1261 IF item_rev_cursor%ISOPEN THEN
1262 CLOSE item_rev_cursor;
1263 END IF;
1264
1265 OPEN item_minor_rev_cursor (TO_CHAR (to_item_id),
1266 TO_CHAR (to_org_id),
1267 TO_CHAR (l_to_item_rev_id)
1268 );
1269
1270 LOOP
1271 FETCH item_minor_rev_cursor
1272 INTO l_to_item_minor_rev_id;
1273
1274 EXIT WHEN item_minor_rev_cursor%NOTFOUND;
1275 END LOOP;
1276
1277 IF l_to_item_minor_rev_id IS NULL
1278 OR '' = l_to_item_minor_rev_id
1279 THEN
1280 CLOSE item_minor_rev_cursor;
1281
1282 RAISE no_minor_rev_exists;
1283 END IF;
1284
1285 IF item_minor_rev_cursor%ISOPEN THEN
1286 CLOSE item_minor_rev_cursor;
1287 END IF;
1288
1289 /* Not Required Commented on Oct 14 2005
1290 IF (l_eff_ctrl = 4)
1291 THEN
1292 OPEN GetCurrentMinorRevCode(from_end_item_revision_id,
1293 to_char(l_from_end_item_id),
1294 to_char(from_org_id)
1295 );
1296
1297 LOOP
1298 FETCH GetCurrentMinorRevCode INTO l_from_end_item_minor_rev_code;
1299 EXIT WHEN GetCurrentMinorRevCode%NOTFOUND;
1300 END LOOP;
1301 IF l_from_end_item_minor_rev_code IS NULL OR '' = l_from_end_item_minor_rev_code THEN
1302 CLOSE GetCurrentMinorRevCode;
1303 RAISE NO_MINOR_REV_CODE_EXISTS;
1304 END IF;
1305
1306 CLOSE GetCurrentMinorRevCode;
1307 OPEN getcurrentminorrevcode (l_from_item_rev_id,
1308 TO_CHAR (from_item_id),
1309 TO_CHAR (from_org_id)
1310 );
1311
1312 LOOP
1313 FETCH getcurrentminorrevcode
1314 INTO l_from_bom_item_minor_rev_code;
1315
1316 EXIT WHEN getcurrentminorrevcode%NOTFOUND;
1317 END LOOP;
1318
1319 IF l_from_bom_item_minor_rev_code IS NULL
1320 OR '' = l_from_bom_item_minor_rev_code
1321 THEN
1322 CLOSE getcurrentminorrevcode;
1323
1324 RAISE no_minor_rev_code_exists;
1325 END IF;
1326
1327 CLOSE getcurrentminorrevcode;
1328 END IF;
1329 */
1330
1331 --changes bug 10078346 begin
1332 --get application_id first
1333 SELECT application_id INTO l_app_id
1334 FROM fnd_application WHERE application_short_name = 'BOM';
1335
1336 --get context field name
1337 select default_context_field_name, context_column_name into l_context, l_context_column
1338 from FND_DESCRIPTIVE_FLEXS where application_id = l_app_id and
1339 descriptive_flexfield_name = 'BOM_INVENTORY_COMPONENTS';
1340
1341 --process further only when reference field is set
1342 if ((l_context_column = 'ATTRIBUTE_CATEGORY') and (l_context is not null)) then
1343 --update attribute category only when reference field has a value of $PROFILE.profile_name
1344 l_prof_check := substr(l_context, 1, 12);
1345
1346 if (l_prof_check = ':$PROFILES$.') then
1347 l_prof_name := ltrim(l_context, ':$PROFILES$.');
1348 l_prof_val := fnd_profile.value(l_prof_name);
1349
1350 end if;
1351 end if;
1352 --changes bug 10078346 end
1353
1354
1355
1356
1357 -- Copies the components if the API is called for selective component copy.
1358 sql_stmt_num := 20;
1359
1360 IF specific_copy_flag = 'Y'
1361 THEN
1362
1363 /* Bug : 4185500 Structure Level Attribute copy */
1364 l_src_pk_col_name_val_pairs :=
1365 ego_col_name_value_pair_array
1366 (ego_col_name_value_pair_obj ('BILL_SEQUENCE_ID',
1367 TO_CHAR (from_sequence_id)
1368 )
1369 );
1370 l_dest_pk_col_name_val_pairs :=
1371 ego_col_name_value_pair_array
1372 (ego_col_name_value_pair_obj ('BILL_SEQUENCE_ID',
1373 TO_CHAR (to_sequence_id)
1374 )
1375 );
1376 l_new_str_type :=
1377 ego_col_name_value_pair_array
1378 (ego_col_name_value_pair_obj ('STRUCTURE_TYPE_ID',
1379 TO_CHAR (l_str_type)
1380 )
1381 );
1382 ego_user_attrs_data_pub.copy_user_attrs_data
1383 (p_api_version => 1.0,
1384 p_application_id => bom_application_id,
1385 p_object_name => 'BOM_STRUCTURE',
1386 p_old_pk_col_value_pairs => l_src_pk_col_name_val_pairs,
1387 p_new_pk_col_value_pairs => l_dest_pk_col_name_val_pairs,
1388 p_new_cc_col_value_pairs => l_new_str_type,
1389 x_return_status => l_return_status,
1390 x_errorcode => l_errorcode,
1391 x_msg_count => l_msg_count,
1392 x_msg_data => l_msg_data
1393 );
1394 IF l_return_status <> fnd_api.g_ret_sts_success THEN
1395 error_handler.get_message_list(l_error_msg_tbl);
1396 IF l_error_msg_tbl.FIRST IS NOT NULL THEN
1397 l_msg_count := l_error_msg_tbl.FIRST;
1398 WHILE l_msg_count IS NOT NULL
1399 LOOP
1400 INSERT INTO mtl_interface_errors
1401 (unique_id,
1402 organization_id,
1403 transaction_id,
1404 table_name,
1405 column_name,
1406 error_message,
1407 bo_identifier,
1408 last_update_date,
1409 last_updated_by,
1410 creation_date,
1411 created_by,
1412 message_type,
1413 request_id,
1414 program_application_id,
1415 program_id,
1416 program_update_date
1417 )
1418 SELECT from_item_id,
1419 to_org_id,
1420 p_copy_request_id,
1421 NULL,
1422 get_current_item_rev (from_item_id,
1423 from_org_id,
1424 rev_date
1425 ),
1426 l_error_msg_tbl(l_msg_count).message_text,
1427 'BOM_COPY',
1428 SYSDATE,
1429 user_id,
1430 SYSDATE,
1431 user_id,
1432 'E',
1433 fnd_global.conc_request_id,
1434 NULL,
1435 fnd_global.conc_program_id,
1436 sysdate
1437 FROM dual;
1438 l_msg_count := l_error_msg_tbl.next(l_msg_count);
1439 END LOOP;
1440 END IF;
1441 END IF;
1442 --turn off the trigger BOMTBICX
1443 bom_globals.g_skip_bomtbicx := 'Y';
1444
1445 IF l_from_eff_ctrl = 1 AND l_to_eff_ctrl = 1 THEN -- Date - Date
1446
1447
1448 INSERT INTO bom_components_b
1449 (shipping_allowed,
1450 required_to_ship,
1451 required_for_revenue,
1452 include_on_ship_docs,
1453 include_on_bill_docs,
1454 low_quantity,
1455 high_quantity,
1456 acd_type,
1457 component_sequence_id,
1458 old_component_sequence_id,
1459 bill_sequence_id,
1460 request_id,
1461 program_application_id,
1462 program_id,
1463 program_update_date,
1464 wip_supply_type,
1465 pick_components,
1466 supply_subinventory,
1467 supply_locator_id,
1468 operation_lead_time_percent,
1469 revised_item_sequence_id,
1470 cost_factor,
1471 operation_seq_num,
1472 component_item_id,
1473 last_update_date,
1474 last_updated_by,
1475 creation_date,
1476 created_by,
1477 last_update_login,
1478 item_num,
1479 component_quantity,
1480 component_yield_factor,
1481 component_remarks,
1482 effectivity_date,
1483 change_notice,
1484 implementation_date,
1485 disable_date,
1486 attribute_category,
1487 attribute1,
1488 attribute2,
1489 attribute3,
1490 attribute4,
1491 attribute5,
1492 attribute6,
1493 attribute7,
1494 attribute8,
1495 attribute9,
1496 attribute10,
1497 attribute11,
1498 attribute12,
1499 attribute13,
1500 attribute14,
1501 attribute15,
1502 planning_factor,
1503 quantity_related,
1504 so_basis,
1505 optional,
1506 mutually_exclusive_options,
1507 include_in_cost_rollup,
1508 check_atp,
1509 bom_item_type,
1510 from_end_item_unit_number,
1511 to_end_item_unit_number,
1512 optional_on_model,
1513 --BUGFIX 2740820
1514 parent_bill_seq_id, --BUGFIX 2740820
1515 model_comp_seq_id, --BUGFIX 2740820
1516 plan_level,
1517 --BUGFIX 2740820
1518 enforce_int_requirements, --BUGFIX 2991472
1519 from_object_revision_id,
1520 from_minor_revision_id,
1521 pk1_value,
1522 pk2_value,
1523 auto_request_material,
1524 -- Bug 3662214 : Added following 4 fields
1525 suggested_vendor_name,
1526 vendor_id,
1527 unit_price,
1528 from_end_item_rev_id,
1529 to_end_item_rev_id,
1530 from_end_item_minor_rev_id,
1531 to_end_item_minor_rev_id,
1532 component_item_revision_id,
1533 component_minor_revision_id,
1534 basis_type,
1535 to_object_revision_id,
1536 to_minor_revision_id
1537 )
1538 SELECT bic.shipping_allowed,
1539 bic.required_to_ship,
1540 bic.required_for_revenue,
1541 bic.include_on_ship_docs,
1542 bic.include_on_bill_docs,
1543 --bic.low_quantity,
1544 --bic.high_quantity,
1545 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
1546 AA.primary_unit_of_measure,BIC.low_quantity,
1547 DECODE(BIC.low_quantity,null,null, --Added this inner Deocde for Bug 6847530
1548 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
1549 NULL,
1550 BIC.low_quantity,
1551 NULL,
1552 NULL,
1553 AA.primary_unit_of_measure,
1554 MSI.primary_unit_of_measure))) Comp_low_qty,
1555 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
1556 AA.primary_unit_of_measure,BIC.high_quantity,
1557 DECODE(BIC.high_quantity,null,null, --Added this inner Deocde for Bug 6847530
1558 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
1559 NULL,
1560 BIC.high_quantity,
1561 NULL,
1562 NULL,
1563 AA.primary_unit_of_measure,
1564 MSI.primary_unit_of_measure))) Comp_high_qty,
1565 x_acd_type,
1566 bom_inventory_components_s.NEXTVAL,
1567 DECODE (x_acd_type,
1568 NULL, NULL,
1569 bom_inventory_components_s.CURRVAL
1570 ),
1571 to_sequence_id,
1572 fnd_global.conc_request_id,
1573 NULL,
1574 fnd_global.conc_program_id,
1575 sysdate,
1576 bic.wip_supply_type,
1577 DECODE (rto_flag, 'Y', 2, bic.pick_components),
1578 DECODE (x_from_org_id,
1579 to_org_id, bic.supply_subinventory,
1580 DECODE( l_default_wip_params, 1, msi.wip_supply_subinventory, NULL )
1581 ),
1582 DECODE (x_from_org_id,
1583 to_org_id, bic.supply_locator_id,
1584 DECODE( l_default_wip_params, 1, msi.wip_supply_locator_id, NULL )
1585 ),
1586 bic.operation_lead_time_percent,
1587 x_rev_item_seq_id,
1588 bic.cost_factor,
1589 bic.operation_seq_num,
1590 bic.component_item_id,
1591 SYSDATE,
1592 user_id,
1593 SYSDATE,
1594 bic.component_sequence_id,
1595 /*NULL comment for bug8431772,change NULL to user_id*/user_id,
1596 bic.item_num,
1597 --bic.component_quantity,
1598 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
1599 AA.primary_unit_of_measure,BIC.component_quantity,
1600 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
1601 NULL,
1602 BIC.component_quantity,
1603 NULL,
1604 NULL,
1605 AA.primary_unit_of_measure,
1606 MSI.primary_unit_of_measure)) Comp_qty,
1607 bic.component_yield_factor,
1608 bic.component_remarks,
1609 -- R12 TTM ENH
1610 CASE
1611 -- The WHEN sequence is important
1612 -- For When display option is set to 2 then what ever comps are target date we need to
1613 -- take that
1614 -- ECO conditions should be in sync with BomCopyStructureAM
1615 -- for creating revised item by grouping based on effectivity
1616 WHEN display_option = 2 AND bill_or_eco = 2
1617 THEN x_effectivity_date
1618 WHEN display_option = 2
1619 THEN trgt_comps_eff_date
1620 WHEN bill_or_eco = 1 -- Inline and explosion date is past
1621 AND ( bic.effectivity_date < trgt_comps_eff_date AND rev_date < trgt_comps_eff_date )
1622 -- Explosion in the Past and Effectivity Date is also in the past, then the components
1623 -- which are past effective will be effective from trgt_comps_eff_date
1624 THEN trgt_comps_eff_date
1625 WHEN bill_or_eco = 1 -- Inline and explosion date is future
1626 AND ( bic.effectivity_date = rev_date AND rev_date > trgt_comps_eff_date )
1627 -- Explosion in the future and Effectivity Date is also in the future, then the components
1628 -- which are effective at the explosion time alone will be effective from trgt_comps_eff_date
1629 THEN trgt_comps_eff_date
1630 -- Past effective components should be target data effective
1631 WHEN bill_or_eco = 1
1632 AND bic.effectivity_date < trgt_comps_eff_date
1633 THEN trgt_comps_eff_date
1634 ELSE
1635 bic.effectivity_date
1636 END AS effectivity_date,
1637 x_e_change_notice,
1638 -- Implementation date will be NULL for ECO flow and SYSDATE for inline copy
1639 DECODE (bill_or_eco, 2, TO_DATE (NULL), SYSDATE),
1640 CASE
1641 -- For current never disable the components
1642 WHEN display_option = 2
1643 THEN TO_DATE (NULL)
1644 -- Past disabled components will be copied with disable date as null
1645 WHEN bill_or_eco = 2 AND ( bic.disable_date < x_effectivity_date )
1646 THEN TO_DATE (NULL)
1647 -- Past disabled components will be copied with disable date as null
1648 WHEN bill_or_eco = 1 AND ( bic.disable_date < trgt_comps_eff_date )
1649 THEN TO_DATE (NULL)
1650 ELSE
1651 -- Future disabled components should be disabled as per the disable date of component
1652 bic.disable_date
1653 END AS disable_date,
1654 decode(l_prof_val, null, bic.attribute_category, l_prof_val), --introduced for bug 10078346 --bic.attribute_category,
1655 bic.attribute1,
1656 bic.attribute2,
1657 bic.attribute3,
1658 bic.attribute4,
1659 bic.attribute5,
1660 bic.attribute6,
1661 bic.attribute7,
1662 bic.attribute8,
1663 bic.attribute9,
1664 bic.attribute10,
1665 bic.attribute11,
1666 bic.attribute12,
1667 bic.attribute13,
1668 bic.attribute14,
1669 bic.attribute15,
1670 bic.planning_factor,
1671 bic.quantity_related,
1672 bic.so_basis,
1673 bic.optional,
1674 bic.mutually_exclusive_options,
1675 bic.include_in_cost_rollup,
1676 bic.check_atp,
1677 msi.bom_item_type,
1678 to_char(NULL) AS from_end_item_unit_number, -- Date Eff Bill will not have from_end_item_unit_numbers
1679 to_char(NULL) AS to_end_item_unit_number, -- Date Eff Bill will not have to_end_item_unit_numbers
1680 bic.optional_on_model,
1681 --BUGFIX 2740820
1682 bic.parent_bill_seq_id, --BUGFIX 2740820
1683 bic.model_comp_seq_id,
1684 --BUGFIX 2740820
1685 bic.plan_level, --BUGFIX 2740820
1686 bic.enforce_int_requirements,
1687 -- Either Fixed or Floating rev, the components will be from when its created, current item rev
1688 l_current_item_rev_id,
1689 -- Minor rev is not supported. Populated the first minor rev
1690 0,
1691 bic.component_item_id,
1692 to_org_id,
1693 bic.auto_request_material,
1694 -- Bug 3662214 : Added following 4 fields
1695 bic.suggested_vendor_name,
1696 bic.vendor_id,
1697 bic.unit_price,
1698 to_number(NULL) AS from_end_item_rev_id, -- From End Item Rev Ids won't be set for Date Eff Bill
1699 to_number(NULL) AS to_end_item_rev_id, -- To End Item Rev Ids won't be set for Date Eff Bill
1700 -- For Minor rev Ids
1701 0 AS from_end_item_minor_rev_id,
1702 0 AS to_end_item_minor_rev_id,
1703 (
1704 SELECT tmirb.revision_id
1705 FROM mtl_item_revisions_b fmirb,
1706 mtl_item_revisions_b tmirb
1707 WHERE tmirb.inventory_item_id = bic.component_item_id
1708 AND tmirb.organization_id = to_org_id
1709 AND tmirb.revision = fmirb.revision
1710 AND fmirb.revision_id = bic.component_item_revision_id
1711 ) AS component_item_revision_id,
1712 CASE
1713 WHEN bic.component_item_revision_id IS NULL
1714 THEN to_number(NULL)
1715 ELSE
1716 -- Minor revision is not supported
1717 0
1718 END AS component_minor_revision_id,
1719 bic.basis_type,
1720 CASE
1721 WHEN l_fixed_rev IS NOT NULL
1722 -- For fixed rev copy the components as fixed rev
1723 THEN l_to_item_rev_id
1724 ELSE
1725 to_number(NULL)
1726 END AS to_object_revision_id,
1727 CASE
1728 WHEN l_fixed_rev IS NOT NULL
1729 THEN 0
1730 ELSE
1731 to_number(NULL)
1732 END AS to_minor_revision_id
1733 FROM bom_components_b bic,
1734 mtl_system_items msi,
1735 MTL_SYSTEM_ITEMS AA , -- Added corresponding to Bug 6510185
1736 bom_copy_explosions_v bev
1737 WHERE bic.bill_sequence_id = x_from_sequence_id
1738 AND bic.component_item_id = msi.inventory_item_id
1739 AND bic.component_item_id <> to_item_id
1740 AND NVL (bic.eco_for_production, 2) = 2
1741 AND msi.organization_id = to_org_id
1742 AND msi.bom_enabled_flag = 'Y' -- Added for the bug 13963236
1743 AND MSI.inventory_item_id = AA.inventory_item_id -- Added corresponding to Bug 6510185
1744 AND AA.organization_id = from_org_id -- Added corresponding to Bug 6510185
1745 AND ((direction = eng_to_bom
1746 AND msi.eng_item_flag = 'N')
1747 OR (direction <> eng_to_bom)
1748 )
1749 AND ((base_item_flag = -1
1750 AND itm_type = 4
1751 AND msi.bom_item_type = 4
1752 )
1753 OR base_item_flag <> -1
1754 OR itm_type <> 4
1755 )
1756 AND ((bic.implementation_date IS NOT NULL)
1757 OR (bic.implementation_date IS NULL
1758 AND bic.change_notice = context_eco
1759 AND ( bic.acd_type = 1 OR bic.acd_type = 2 )
1760 )
1761 )
1762 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
1763 (
1764 SELECT 1
1765 FROM bom_components_b bcb
1766 WHERE bcb.old_component_sequence_id = bic.component_sequence_id
1767 AND bcb.change_notice = context_eco
1768 AND bcb.acd_type = 3
1769 AND bcb.effectivity_date <= trgt_comps_eff_date
1770 AND bcb.implementation_date IS NULL
1771 AND bcb.bill_sequence_id = bic.bill_sequence_id
1772 )
1773 AND 'T' = bev.access_flag
1774 AND 'T' =
1775 bom_security_pub.check_item_privilege
1776 ('EGO_VIEW_ITEM',
1777 TO_CHAR (bic.component_item_id),
1778 TO_CHAR (to_org_id),
1779 bom_exploder_pub.get_ego_user
1780 )
1781 AND bic.component_sequence_id = bev.component_sequence_id
1782 AND bev.bill_sequence_id = from_sequence_id
1783 AND bev.parent_sort_order = p_parent_sort_order
1784 AND NOT EXISTS (
1785 SELECT 1
1786 FROM bom_copy_structure_actions bcsa
1787 WHERE bcsa.component_sequence_id =
1788 bic.component_sequence_id
1789 AND bcsa.copy_request_id = p_copy_request_id
1790 AND bcsa.organization_id = to_org_id
1791 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
1792 -- Component Action is exclude or enable
1793 -- we need not copy.
1794 )
1795 AND EXISTS
1796 (
1797 SELECT 1
1798 FROM fnd_lookup_values_vl flv,
1799 ego_criteria_templates_v ectv,
1800 ego_criteria_v ecv,
1801 mtl_system_items_b msibs -- to assembly item
1802 WHERE ecv.customization_application_id = 702
1803 AND ecv.region_application_id = 702
1804 AND ecv.region_code = 'BOM_ITEM_TYPE_REGION'
1805 AND ecv.customization_code = ectv.customization_code
1806 AND flv.lookup_type = 'ITEM_TYPE'
1807 AND flv.enabled_flag = 'Y'
1808 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
1809 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
1810 AND flv.lookup_code = ectv.classification1
1811 AND ectv.customization_application_id = 702
1812 AND ectv.region_application_id = 702
1813 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
1814 AND flv.lookup_code = msibs.item_type
1815 AND msibs.inventory_item_id = to_item_id
1816 AND msibs.organization_id = to_org_id
1817 AND ecv.value_varchar2 = msi.item_type -- Component
1818 UNION ALL
1819 SELECT 1
1820 FROM DUAL
1821 WHERE NOT EXISTS
1822 (
1823 SELECT 1
1824 FROM fnd_lookup_values_vl flv,
1825 ego_criteria_templates_v ectv,
1826 mtl_system_items_b msibs -- to assembly item
1827 WHERE flv.lookup_type = 'ITEM_TYPE'
1828 AND flv.enabled_flag = 'Y'
1829 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
1830 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
1831 AND flv.lookup_code = ectv.classification1
1832 AND ectv.customization_application_id = 702
1833 AND ectv.region_application_id = 702
1834 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
1835 AND flv.lookup_code = msibs.item_type
1836 AND msibs.inventory_item_id = to_item_id
1837 AND msibs.organization_id = to_org_id
1838 )
1839 );
1840 ELSIF ( ( l_from_eff_ctrl = 2 AND l_to_eff_ctrl = 2 ) -- Unit
1841 OR ( l_from_eff_ctrl = 3 AND l_to_eff_ctrl = 3 ) -- Serial
1842 ) THEN
1843
1844
1845 INSERT INTO bom_components_b
1846 (shipping_allowed,
1847 required_to_ship,
1848 required_for_revenue,
1849 include_on_ship_docs,
1850 include_on_bill_docs,
1851 low_quantity,
1852 high_quantity,
1853 acd_type,
1854 component_sequence_id,
1855 old_component_sequence_id,
1856 bill_sequence_id,
1857 request_id,
1858 program_application_id,
1859 program_id,
1860 program_update_date,
1861 wip_supply_type,
1862 pick_components,
1863 supply_subinventory,
1864 supply_locator_id,
1865 operation_lead_time_percent,
1866 revised_item_sequence_id,
1867 cost_factor,
1868 operation_seq_num,
1869 component_item_id,
1870 last_update_date,
1871 last_updated_by,
1872 creation_date,
1873 created_by,
1874 last_update_login,
1875 item_num,
1876 component_quantity,
1877 component_yield_factor,
1878 component_remarks,
1879 effectivity_date,
1880 change_notice,
1881 implementation_date,
1882 disable_date,
1883 attribute_category,
1884 attribute1,
1885 attribute2,
1886 attribute3,
1887 attribute4,
1888 attribute5,
1889 attribute6,
1890 attribute7,
1891 attribute8,
1892 attribute9,
1893 attribute10,
1894 attribute11,
1895 attribute12,
1896 attribute13,
1897 attribute14,
1898 attribute15,
1899 planning_factor,
1900 quantity_related,
1901 so_basis,
1902 optional,
1903 mutually_exclusive_options,
1904 include_in_cost_rollup,
1905 check_atp,
1906 bom_item_type,
1907 from_end_item_unit_number,
1908 to_end_item_unit_number,
1909 optional_on_model,
1910 --BUGFIX 2740820
1911 parent_bill_seq_id, --BUGFIX 2740820
1912 model_comp_seq_id, --BUGFIX 2740820
1913 plan_level,
1914 --BUGFIX 2740820
1915 enforce_int_requirements, --BUGFIX 2991472
1916 from_object_revision_id,
1917 from_minor_revision_id,
1918 pk1_value,
1919 pk2_value,
1920 auto_request_material,
1921 -- Bug 3662214 : Added following 4 fields
1922 suggested_vendor_name,
1923 vendor_id,
1924 unit_price,
1925 from_end_item_rev_id,
1926 to_end_item_rev_id,
1927 from_end_item_minor_rev_id,
1928 to_end_item_minor_rev_id,
1929 component_item_revision_id,
1930 component_minor_revision_id,
1931 basis_type,
1932 to_object_revision_id,
1933 to_minor_revision_id
1934 )
1935 SELECT bic.shipping_allowed,
1936 bic.required_to_ship,
1937 bic.required_for_revenue,
1938 bic.include_on_ship_docs,
1939 bic.include_on_bill_docs,
1940 --bic.low_quantity, -- Commented for bug-6510185
1941 --bic.high_quantity, -- Commented for bug-6510185
1942 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
1943 AA.primary_unit_of_measure,BIC.low_quantity,
1944 DECODE(BIC.low_quantity,null,null, --Added this inner Deocde for Bug 6847530
1945 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
1946 NULL,
1947 BIC.low_quantity,
1948 NULL,
1949 NULL,
1950 AA.primary_unit_of_measure,
1951 MSI.primary_unit_of_measure))) Comp_low_qty,
1952 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
1953 AA.primary_unit_of_measure,BIC.high_quantity,
1954 DECODE(BIC.high_quantity,null,null, --Added this inner Deocde for Bug 6847530
1955 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
1956 NULL,
1957 BIC.high_quantity,
1958 NULL,
1959 NULL,
1960 AA.primary_unit_of_measure,
1961 MSI.primary_unit_of_measure))) Comp_high_qty,
1962 x_acd_type,
1963 bom_inventory_components_s.NEXTVAL,
1964 DECODE (x_acd_type,
1965 NULL, NULL,
1966 bom_inventory_components_s.CURRVAL
1967 ),
1968 to_sequence_id,
1969 fnd_global.conc_request_id,
1970 NULL,
1971 fnd_global.conc_program_id,
1972 sysdate,
1973 bic.wip_supply_type,
1974 DECODE (rto_flag, 'Y', 2, bic.pick_components),
1975 DECODE (x_from_org_id,
1976 to_org_id, bic.supply_subinventory,
1977 DECODE( l_default_wip_params, 1, msi.wip_supply_subinventory, NULL )
1978 ),
1979 DECODE (x_from_org_id,
1980 to_org_id, bic.supply_locator_id,
1981 DECODE( l_default_wip_params, 1, msi.wip_supply_locator_id, NULL )
1982 ),
1983 bic.operation_lead_time_percent,
1984 x_rev_item_seq_id,
1985 bic.cost_factor,
1986 bic.operation_seq_num,
1987 bic.component_item_id,
1988 SYSDATE,
1989 user_id,
1990 SYSDATE,
1991 bic.component_sequence_id,
1992 /*NULL comment for bug8431772,change NULL to user_id*/user_id,
1993 bic.item_num,
1994 --bic.component_quantity,
1995 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
1996 AA.primary_unit_of_measure,BIC.component_quantity,
1997 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
1998 NULL,
1999 BIC.component_quantity,
2000 NULL,
2001 NULL,
2002 AA.primary_unit_of_measure,
2003 MSI.primary_unit_of_measure)) Comp_qty,
2004 bic.component_yield_factor,
2005 bic.component_remarks,
2006 -- R12 TTM ENH
2007 -- For Unit/Serial it eff date will be sysdate
2008 sysdate AS effectivity_date,
2009 x_e_change_notice,
2010 -- Implementation date will be NULL for ECO flow and SYSDATE for inline copy
2011 DECODE (bill_or_eco, 2, TO_DATE (NULL), SYSDATE),
2012 -- For Unit/Serial Eff disable date will be null
2013 to_date(NULL) AS disable_date,
2014 -- Bug 4208139 Currently only CURRENT components are copied.(11.5.10-E)
2015 decode(l_prof_val, null, bic.attribute_category, l_prof_val), --introduced for bug 10078346 bic.attribute_category,
2016 bic.attribute1,
2017 bic.attribute2,
2018 bic.attribute3,
2019 bic.attribute4,
2020 bic.attribute5,
2021 bic.attribute6,
2022 bic.attribute7,
2023 bic.attribute8,
2024 bic.attribute9,
2025 bic.attribute10,
2026 bic.attribute11,
2027 bic.attribute12,
2028 bic.attribute13,
2029 bic.attribute14,
2030 bic.attribute15,
2031 bic.planning_factor,
2032 bic.quantity_related,
2033 bic.so_basis,
2034 bic.optional,
2035 bic.mutually_exclusive_options,
2036 bic.include_in_cost_rollup,
2037 --DECODE(atp_comp_flag, 'Y', CHECK_ATP, 2), fixed bug 2249375
2038 bic.check_atp,
2039 msi.bom_item_type,
2040 CASE
2041 WHEN bic.from_end_item_unit_number IS NULL
2042 THEN to_char(NULL)
2043 -- ECO conditions should be in sync with BomCopyStructureAM
2044 -- for creating revised item by grouping based on effectivity
2045 WHEN display_option = 2 AND bill_or_eco = 2
2046 THEN x_unit_number
2047 WHEN display_option = 2
2048 THEN trgt_comps_unit_number
2049 WHEN bill_or_eco = 1 -- Inline and explosion unit number is smaller
2050 AND ( bic.from_end_item_unit_number < trgt_comps_unit_number AND unit_number < trgt_comps_unit_number )
2051 -- Explosion unit number is smaller and from_end_item_unit_number is also smaller, then the components
2052 -- which are with smaller unit number effective will be effective from trgt_comps_unit_number
2053 THEN trgt_comps_unit_number
2054 WHEN bill_or_eco = 1 -- Inline explosion unit number is greater
2055 AND ( bic.from_end_item_unit_number = unit_number AND unit_number > trgt_comps_unit_number )
2056 -- Explosion unit number it greater and from_end_item_unit_number is also greater, then the components
2057 -- which are effective on explosion unit number will be effective from trgt_comps_unit_number
2058 THEN trgt_comps_unit_number
2059 -- Past effective should be effective from the target unit number
2060 WHEN bill_or_eco = 2
2061 AND bic.from_end_item_unit_number < x_unit_number
2062 THEN trgt_comps_unit_number
2063 ELSE
2064 bic.from_end_item_unit_number
2065 END AS from_end_item_unit_number,
2066 CASE
2067 -- For current never disable components
2068 WHEN display_option = 2
2069 THEN to_char(NULL)
2070 WHEN bill_or_eco = 2 AND ( bic.to_end_item_unit_number < x_unit_number )
2071 -- Disabled components should be copied with to end item unit number as null
2072 THEN to_char(NULL)
2073 WHEN bill_or_eco = 1 AND ( bic.to_end_item_unit_number < trgt_comps_unit_number )
2074 -- Disabled components should be copied with to end item unit number as null
2075 THEN to_char(NULL)
2076 ELSE
2077 -- Future disabled components should be disabled as per the to_end_item_unit_number of component
2078 bic.to_end_item_unit_number
2079 END AS to_end_item_unit_number,
2080 bic.optional_on_model,
2081 --BUGFIX 2740820
2082 bic.parent_bill_seq_id, --BUGFIX 2740820
2083 bic.model_comp_seq_id,
2084 --BUGFIX 2740820
2085 bic.plan_level, --BUGFIX 2740820
2086 bic.enforce_int_requirements,
2087 -- Either Fixed or Floating rev, the components will be from when its created, current item rev
2088 l_current_item_rev_id,
2089 -- Minor rev is not supported. Populated the first minor rev
2090 0,
2091 bic.component_item_id,
2092 to_org_id,
2093 bic.auto_request_material,
2094 -- Bug 3662214 : Added following 4 fields
2095 bic.suggested_vendor_name,
2096 bic.vendor_id,
2097 bic.unit_price,
2098 to_number(NULL) AS from_end_item_rev_id,
2099 to_number(NULL) AS to_end_item_rev_id,
2100 -- For Minor rev Ids
2101 0 AS from_end_item_minor_rev_id,
2102 0 AS to_end_item_minor_rev_id,
2103 (
2104 SELECT tmirb.revision_id
2105 FROM mtl_item_revisions_b fmirb,
2106 mtl_item_revisions_b tmirb
2107 WHERE tmirb.inventory_item_id = bic.component_item_id
2108 AND tmirb.organization_id = to_org_id
2109 AND tmirb.revision = fmirb.revision
2110 AND fmirb.revision_id = bic.component_item_revision_id
2111 ) AS component_item_revision_id,
2112 CASE
2113 WHEN bic.component_item_revision_id IS NULL
2114 THEN to_number(NULL)
2115 ELSE
2116 -- Minor revision is not supported
2117 0
2118 END AS component_minor_revision_id,
2119 bic.basis_type,
2120 CASE
2121 WHEN l_fixed_rev IS NOT NULL
2122 -- For fixed rev copy the components as fixed rev
2123 THEN l_to_item_rev_id
2124 ELSE
2125 to_number(NULL)
2126 END AS to_object_revision_id,
2127 CASE
2128 WHEN l_fixed_rev IS NOT NULL
2129 THEN 0
2130 ELSE
2131 to_number(NULL)
2132 END AS to_minor_revision_id
2133 FROM bom_components_b bic,
2134 mtl_system_items msi,
2135 MTL_SYSTEM_ITEMS AA , -- Added corresponding to Bug 6510185
2136 bom_copy_explosions_v bev
2137 WHERE bic.bill_sequence_id = x_from_sequence_id
2138 AND bic.component_item_id = msi.inventory_item_id
2139 AND bic.component_item_id <> to_item_id
2140 AND NVL (bic.eco_for_production, 2) = 2
2141 AND msi.organization_id = to_org_id
2142 AND MSI.BOM_ENABLED_FLAG = 'Y' -- Bug 3595979 -- Uncommented for the bug 13963236
2143 AND MSI.inventory_item_id = AA.inventory_item_id -- Added corresponding to Bug 6510185
2144 AND AA.organization_id = from_org_id -- Added corresponding to Bug 6510185
2145 AND ((direction = eng_to_bom
2146 AND msi.eng_item_flag = 'N')
2147 OR (direction <> eng_to_bom)
2148 )
2149 AND ((base_item_flag = -1
2150 AND itm_type = 4
2151 AND msi.bom_item_type = 4
2152 )
2153 OR base_item_flag <> -1
2154 OR itm_type <> 4
2155 )
2156 AND ((bic.implementation_date IS NOT NULL)
2157 OR (bic.implementation_date IS NULL
2158 AND bic.change_notice = context_eco
2159 AND ( bic.acd_type = 1 OR bic.acd_type = 2 )
2160 )
2161 )
2162 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
2163 (
2164 SELECT 1
2165 FROM bom_components_b bcb
2166 WHERE bcb.old_component_sequence_id = bic.component_sequence_id
2167 AND bcb.change_notice = context_eco
2168 AND bcb.acd_type = 3
2169 AND bcb.effectivity_date <= trgt_comps_eff_date
2170 AND bcb.implementation_date IS NULL
2171 AND bcb.bill_sequence_id = bic.bill_sequence_id
2172 )
2173 AND 'T' = bev.access_flag
2174 AND 'T' =
2175 bom_security_pub.check_item_privilege
2176 ('EGO_VIEW_ITEM',
2177 TO_CHAR (bic.component_item_id),
2178 TO_CHAR (to_org_id),
2179 bom_exploder_pub.get_ego_user
2180 )
2181 AND bic.component_sequence_id = bev.component_sequence_id
2182 AND bev.bill_sequence_id = from_sequence_id
2183 AND bev.parent_sort_order = p_parent_sort_order
2184 AND NOT EXISTS (
2185 SELECT 1
2186 FROM bom_copy_structure_actions bcsa
2187 WHERE bcsa.component_sequence_id =
2188 bic.component_sequence_id
2189 AND bcsa.copy_request_id = p_copy_request_id
2190 AND bcsa.organization_id = to_org_id
2191 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
2192 -- Component Action is exclude or enable
2193 -- we need not copy.
2194 )
2195 AND EXISTS
2196 (
2197 SELECT 1
2198 FROM fnd_lookup_values_vl flv,
2199 ego_criteria_templates_v ectv,
2200 ego_criteria_v ecv,
2201 mtl_system_items_b msibs -- to assembly item
2202 WHERE ecv.customization_application_id = 702
2203 AND ecv.region_application_id = 702
2204 AND ecv.region_code = 'BOM_ITEM_TYPE_REGION'
2205 AND ecv.customization_code = ectv.customization_code
2206 AND flv.lookup_type = 'ITEM_TYPE'
2207 AND flv.enabled_flag = 'Y'
2208 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
2209 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
2210 AND flv.lookup_code = ectv.classification1
2211 AND ectv.customization_application_id = 702
2212 AND ectv.region_application_id = 702
2213 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
2214 AND flv.lookup_code = msibs.item_type
2215 AND msibs.inventory_item_id = to_item_id
2216 AND msibs.organization_id = to_org_id
2217 AND ecv.value_varchar2 = msi.item_type -- Component
2218 UNION ALL
2219 SELECT 1
2220 FROM DUAL
2221 WHERE NOT EXISTS
2222 (
2223 SELECT 1
2224 FROM fnd_lookup_values_vl flv,
2225 ego_criteria_templates_v ectv,
2226 mtl_system_items_b msibs -- to assembly item
2227 WHERE flv.lookup_type = 'ITEM_TYPE'
2228 AND flv.enabled_flag = 'Y'
2229 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
2230 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
2231 AND flv.lookup_code = ectv.classification1
2232 AND ectv.customization_application_id = 702
2233 AND ectv.region_application_id = 702
2234 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
2235 AND flv.lookup_code = msibs.item_type
2236 AND msibs.inventory_item_id = to_item_id
2237 AND msibs.organization_id = to_org_id
2238 )
2239 );
2240
2241
2242 ELSIF l_from_eff_ctrl = 4 AND l_to_eff_ctrl = 4 THEN -- Rev - Rev
2243
2244
2245 INSERT INTO bom_components_b
2246 (shipping_allowed,
2247 required_to_ship,
2248 required_for_revenue,
2249 include_on_ship_docs,
2250 include_on_bill_docs,
2251 low_quantity,
2252 high_quantity,
2253 acd_type,
2254 component_sequence_id,
2255 old_component_sequence_id,
2256 bill_sequence_id,
2257 request_id,
2258 program_application_id,
2259 program_id,
2260 program_update_date,
2261 wip_supply_type,
2262 pick_components,
2263 supply_subinventory,
2264 supply_locator_id,
2265 operation_lead_time_percent,
2266 revised_item_sequence_id,
2267 cost_factor,
2268 operation_seq_num,
2269 component_item_id,
2270 last_update_date,
2271 last_updated_by,
2272 creation_date,
2273 created_by,
2274 last_update_login,
2275 item_num,
2276 component_quantity,
2277 component_yield_factor,
2278 component_remarks,
2279 effectivity_date,
2280 change_notice,
2281 implementation_date,
2282 disable_date,
2283 attribute_category,
2284 attribute1,
2285 attribute2,
2286 attribute3,
2287 attribute4,
2288 attribute5,
2289 attribute6,
2290 attribute7,
2291 attribute8,
2292 attribute9,
2293 attribute10,
2294 attribute11,
2295 attribute12,
2296 attribute13,
2297 attribute14,
2298 attribute15,
2299 planning_factor,
2300 quantity_related,
2301 so_basis,
2302 optional,
2303 mutually_exclusive_options,
2304 include_in_cost_rollup,
2305 check_atp,
2306 bom_item_type,
2307 from_end_item_unit_number,
2308 to_end_item_unit_number,
2309 optional_on_model,
2310 --BUGFIX 2740820
2311 parent_bill_seq_id, --BUGFIX 2740820
2312 model_comp_seq_id, --BUGFIX 2740820
2313 plan_level,
2314 --BUGFIX 2740820
2315 enforce_int_requirements, --BUGFIX 2991472
2316 from_object_revision_id,
2317 from_minor_revision_id,
2318 pk1_value,
2319 pk2_value,
2320 auto_request_material,
2321 -- Bug 3662214 : Added following 4 fields
2322 suggested_vendor_name,
2323 vendor_id,
2324 unit_price,
2325 from_end_item_rev_id,
2326 to_end_item_rev_id,
2327 from_end_item_minor_rev_id,
2328 to_end_item_minor_rev_id,
2329 component_item_revision_id,
2330 component_minor_revision_id,
2331 basis_type,
2332 to_object_revision_id,
2333 to_minor_revision_id
2334 )
2335 SELECT bic.shipping_allowed,
2336 bic.required_to_ship,
2337 bic.required_for_revenue,
2338 bic.include_on_ship_docs,
2339 bic.include_on_bill_docs,
2340 --bic.low_quantity, -- Commented for bug-6510185
2341 --bic.high_quantity, -- Commented for bug-6510185
2342 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
2343 AA.primary_unit_of_measure,BIC.low_quantity,
2344 DECODE(BIC.low_quantity,null,null, --Added this inner Deocde for Bug 6847530
2345 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
2346 NULL,
2347 BIC.low_quantity,
2348 NULL,
2349 NULL,
2350 AA.primary_unit_of_measure,
2351 MSI.primary_unit_of_measure))) Comp_low_qty,
2352 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
2353 AA.primary_unit_of_measure,BIC.high_quantity,
2354 DECODE(BIC.high_quantity,null,null, --Added this inner Deocde for Bug 6847530
2355 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
2356 NULL,
2357 BIC.high_quantity,
2358 NULL,
2359 NULL,
2360 AA.primary_unit_of_measure,
2361 MSI.primary_unit_of_measure))) Comp_high_qty,
2362
2363 x_acd_type,
2364 bom_inventory_components_s.NEXTVAL,
2365 DECODE (x_acd_type,
2366 NULL, NULL,
2367 bom_inventory_components_s.CURRVAL
2368 ),
2369 to_sequence_id,
2370 fnd_global.conc_request_id,
2371 NULL,
2372 fnd_global.conc_program_id,
2373 sysdate,
2374 bic.wip_supply_type,
2375 DECODE (rto_flag, 'Y', 2, bic.pick_components),
2376 DECODE (x_from_org_id,
2377 to_org_id, bic.supply_subinventory,
2378 DECODE( l_default_wip_params, 1, msi.wip_supply_subinventory, NULL )
2379 ),
2380 DECODE (x_from_org_id,
2381 to_org_id, bic.supply_locator_id,
2382 DECODE( l_default_wip_params, 1, msi.wip_supply_locator_id, NULL )
2383 ),
2384 bic.operation_lead_time_percent,
2385 x_rev_item_seq_id,
2386 bic.cost_factor,
2387 bic.operation_seq_num,
2388 bic.component_item_id,
2389 SYSDATE,
2390 user_id,
2391 SYSDATE,
2392 bic.component_sequence_id,
2393 /*NULL comment for bug8431772,change NULL to user_id*/user_id,
2394 bic.item_num,
2395 --bic.component_quantity,
2396 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
2397 AA.primary_unit_of_measure,BIC.component_quantity,
2398 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
2399 NULL,
2400 BIC.component_quantity,
2401 NULL,
2402 NULL,
2403 AA.primary_unit_of_measure,
2404 MSI.primary_unit_of_measure)) Comp_qty,
2405 bic.component_yield_factor,
2406 bic.component_remarks,
2407 -- R12 TTM ENH
2408 -- For Rev Eff Structure the eff date will be sysdate
2409 sysdate AS effectivity_date,
2410 x_e_change_notice,
2411 -- Implementation date will be NULL for ECO flow and SYSDATE for inline copy
2412 DECODE (bill_or_eco, 2, TO_DATE (NULL), SYSDATE),
2413 -- For Rev Eff structure the disable date will be null
2414 to_date(NULL) AS disable_date,
2415 -- Bug 4208139 Currently only CURRENT components are copied.(11.5.10-E)
2416 --DECODE(bill_or_eco,2,to_date(NULL),GREATEST(IMPLEMENTATION_DATE,SYSDATE)),
2417 --DECODE(bill_or_eco,2,to_date(NULL), DECODE(GREATEST(DISABLE_DATE,SYSDATE),SYSDATE, NULL, DISABLE_DATE)),
2418 decode(l_prof_val, null, bic.attribute_category, l_prof_val), --introduced for bug 10078346 bic.attribute_category,
2419 bic.attribute1,
2420 bic.attribute2,
2421 bic.attribute3,
2422 bic.attribute4,
2423 bic.attribute5,
2424 bic.attribute6,
2425 bic.attribute7,
2426 bic.attribute8,
2427 bic.attribute9,
2428 bic.attribute10,
2429 bic.attribute11,
2430 bic.attribute12,
2431 bic.attribute13,
2432 bic.attribute14,
2433 bic.attribute15,
2434 bic.planning_factor,
2435 bic.quantity_related,
2436 bic.so_basis,
2437 bic.optional,
2438 bic.mutually_exclusive_options,
2439 bic.include_in_cost_rollup,
2440 bic.check_atp,
2441 msi.bom_item_type,
2442 to_char(NULL) AS from_end_item_unit_number,
2443 to_char(NULL) AS to_end_item_unit_number,
2444 bic.optional_on_model,
2445 --BUGFIX 2740820
2446 bic.parent_bill_seq_id, --BUGFIX 2740820
2447 bic.model_comp_seq_id,
2448 --BUGFIX 2740820
2449 bic.plan_level, --BUGFIX 2740820
2450 bic.enforce_int_requirements,
2451 -- Either Fixed or Floating rev, the components will be from when its created, current item rev
2452 l_current_item_rev_id,
2453 -- Minor rev is not supported. Populated the first minor rev
2454 0,
2455 bic.component_item_id,
2456 to_org_id,
2457 bic.auto_request_material,
2458 -- Bug 3662214 : Added following 4 fields
2459 bic.suggested_vendor_name,
2460 bic.vendor_id,
2461 bic.unit_price,
2462 CASE
2463 WHEN bic.from_end_item_rev_id IS NULL
2464 THEN NULL
2465 -- ECO conditions should be in sync with BomCopyStructureAM
2466 -- for creating revised item by grouping based on effectivity
2467 WHEN display_option = 2 AND bill_or_eco = 2
2468 THEN eco_end_item_rev_id
2469 WHEN display_option = 2
2470 THEN trgt_comps_end_item_rev_id
2471 WHEN bill_or_eco = 1 -- Inline and explosion rev is past or smaller
2472 -- Explosion rev is smaller and from_end_item_rev is also smaller, then the components
2473 -- which are with smaller revision effective will be effective from eco_end_item_rev_id
2474 AND bic.from_end_item_rev_id IS NOT NULL
2475 AND trgt_comps_end_item_rev_id IS NOT NULL
2476 AND p_end_item_rev_id IS NOT NULL
2477 AND ( (
2478 SELECT REVISION
2479 FROM MTL_ITEM_REVISIONS_B
2480 WHERE REVISION_ID = bic.from_end_item_rev_id
2481 ) < (
2482 SELECT REVISION
2483 FROM MTL_ITEM_REVISIONS_B
2484 WHERE REVISION_ID = trgt_comps_end_item_rev_id
2485 )
2486 AND
2487 (
2488 SELECT REVISION
2489 FROM MTL_ITEM_REVISIONS_B
2490 WHERE REVISION_ID = p_end_item_rev_id
2491 ) < (
2492 SELECT REVISION
2493 FROM MTL_ITEM_REVISIONS_B
2494 WHERE REVISION_ID = trgt_comps_end_item_rev_id
2495 )
2496 )
2497 THEN trgt_comps_end_item_rev_id
2498 WHEN bill_or_eco = 1 -- Inline and explosion rev is future and greater
2499 AND bic.from_end_item_rev_id IS NOT NULL
2500 -- Explosion rev is greater and from_end_item_rev is also greater, then the components
2501 -- which are effective on exploded revision will be effective from trgt_comps_end_item_rev_id
2502 AND trgt_comps_end_item_rev_id IS NOT NULL
2503 AND p_end_item_rev_id IS NOT NULL
2504 AND ( (
2505 SELECT REVISION
2506 FROM MTL_ITEM_REVISIONS_B
2507 WHERE REVISION_ID = bic.from_end_item_rev_id
2508 ) = (
2509 SELECT REVISION
2510 FROM MTL_ITEM_REVISIONS_B
2511 WHERE REVISION_ID = trgt_comps_end_item_rev_id
2512 )
2513 AND
2514 (
2515 SELECT REVISION
2516 FROM MTL_ITEM_REVISIONS_B
2517 WHERE REVISION_ID = p_end_item_rev_id
2518 ) > (
2519 SELECT REVISION
2520 FROM MTL_ITEM_REVISIONS_B
2521 WHERE REVISION_ID = trgt_comps_end_item_rev_id
2522 )
2523 )
2524 THEN trgt_comps_end_item_rev_id
2525 -- Past Revision Effective should be effective from target revision
2526 WHEN bill_or_eco = 1
2527 AND eco_end_item_rev_id IS NOT NULL
2528 AND (
2529 SELECT REVISION
2530 FROM MTL_ITEM_REVISIONS_B
2531 WHERE REVISION_ID = bic.from_end_item_rev_id
2532 ) < (
2533 SELECT REVISION
2534 FROM MTL_ITEM_REVISIONS_B
2535 WHERE REVISION_ID = eco_end_item_rev_id
2536 )
2537 THEN trgt_comps_end_item_rev_id
2538 ELSE
2539 NVL((
2540 SELECT tmirb.revision_id
2541 FROM mtl_item_revisions_b fmirb,
2542 mtl_item_revisions_b tmirb
2543 WHERE tmirb.inventory_item_id = to_item_id
2544 AND tmirb.organization_id = to_org_id
2545 AND tmirb.revision = fmirb.revision
2546 AND fmirb.revision_id = bic.from_end_item_rev_id
2547 ),trgt_comps_end_item_rev_id)
2548 END AS from_end_item_rev_id,
2549 CASE
2550 WHEN ( bic.to_end_item_rev_id IS NULL OR display_option = 2)
2551 THEN NULL
2552 WHEN bill_or_eco = 1
2553 AND
2554 (
2555 SELECT REVISION
2556 FROM MTL_ITEM_REVISIONS_B
2557 WHERE REVISION_ID = bic.to_end_item_rev_id
2558 ) <
2559 (
2560 SELECT REVISION
2561 FROM MTL_ITEM_REVISIONS_B
2562 WHERE REVISION_ID = trgt_comps_end_item_rev_id
2563 )
2564 THEN NULL
2565 ELSE
2566 (
2567 SELECT tmirb.revision_id
2568 FROM mtl_item_revisions_b fmirb,
2569 mtl_item_revisions_b tmirb
2570 WHERE tmirb.inventory_item_id = to_item_id
2571 AND tmirb.organization_id = to_org_id
2572 AND tmirb.revision = fmirb.revision
2573 AND fmirb.revision_id = bic.to_end_item_rev_id
2574 )
2575 -- When No Item Rev Exists for the to item then populate to item rev as also null
2576 END AS to_end_item_rev_id,
2577 -- For Minor rev Ids
2578 0 AS from_end_item_minor_rev_id,
2579 0 AS to_end_item_minor_rev_id,
2580 (
2581 SELECT tmirb.revision_id
2582 FROM mtl_item_revisions_b fmirb,
2583 mtl_item_revisions_b tmirb
2584 WHERE tmirb.inventory_item_id = bic.component_item_id
2585 AND tmirb.organization_id = to_org_id
2586 AND tmirb.revision = fmirb.revision
2587 AND fmirb.revision_id = bic.component_item_revision_id
2588 ) AS component_item_revision_id,
2589 CASE
2590 WHEN bic.component_item_revision_id IS NULL
2591 THEN to_number(NULL)
2592 ELSE
2593 -- Minor revision is not supported
2594 0
2595 END AS component_minor_revision_id,
2596 bic.basis_type,
2597 CASE
2598 WHEN l_fixed_rev IS NOT NULL
2599 -- For fixed rev copy the components as fixed rev
2600 THEN l_to_item_rev_id
2601 ELSE
2602 to_number(NULL)
2603 END AS to_object_revision_id,
2604 CASE
2605 WHEN l_fixed_rev IS NOT NULL
2606 THEN 0
2607 ELSE
2608 to_number(NULL)
2609 END AS to_minor_revision_id
2610 FROM bom_components_b bic,
2611 mtl_system_items msi,
2612 MTL_SYSTEM_ITEMS AA , -- Added corresponding to Bug 6510185
2613 bom_copy_explosions_v bev
2614 WHERE bic.bill_sequence_id = x_from_sequence_id
2615 AND bic.component_item_id = msi.inventory_item_id
2616 AND bic.component_item_id <> to_item_id
2617 AND NVL (bic.eco_for_production, 2) = 2
2618 AND msi.organization_id = to_org_id
2619 AND MSI.inventory_item_id = AA.inventory_item_id -- Added corresponding to Bug 6510185
2620 AND AA.organization_id = from_org_id -- Added corresponding to Bug 6510185
2621 AND MSI.BOM_ENABLED_FLAG = 'Y' --Bug 3595979 -- Uncommented for the bug 13963236
2622 AND ((direction = eng_to_bom
2623 AND msi.eng_item_flag = 'N')
2624 OR (direction <> eng_to_bom)
2625 )
2626 AND ((base_item_flag = -1
2627 AND itm_type = 4
2628 AND msi.bom_item_type = 4
2629 )
2630 OR base_item_flag <> -1
2631 OR itm_type <> 4
2632 )
2633 AND ((bic.implementation_date IS NOT NULL)
2634 OR (bic.implementation_date IS NULL
2635 AND bic.change_notice = context_eco
2636 AND ( bic.acd_type = 1 OR bic.acd_type = 2 )
2637 )
2638 )
2639 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
2640 (
2641 SELECT 1
2642 FROM bom_components_b bcb
2643 WHERE bcb.old_component_sequence_id = bic.component_sequence_id
2644 AND bcb.change_notice = context_eco
2645 AND bcb.acd_type = 3
2646 AND bcb.effectivity_date <= trgt_comps_eff_date
2647 AND bcb.implementation_date IS NULL
2648 AND bcb.bill_sequence_id = bic.bill_sequence_id
2649 )
2650 AND 'T' = bev.access_flag
2651 AND 'T' =
2652 bom_security_pub.check_item_privilege
2653 ('EGO_VIEW_ITEM',
2654 TO_CHAR (bic.component_item_id),
2655 TO_CHAR (to_org_id),
2656 bom_exploder_pub.get_ego_user
2657 )
2658 AND bic.component_sequence_id = bev.component_sequence_id
2659 AND bev.bill_sequence_id = from_sequence_id
2660 AND bev.parent_sort_order = p_parent_sort_order
2661 AND NOT EXISTS (
2662 SELECT 1
2663 FROM bom_copy_structure_actions bcsa
2664 WHERE bcsa.component_sequence_id =
2665 bic.component_sequence_id
2666 AND bcsa.copy_request_id = p_copy_request_id
2667 AND bcsa.organization_id = to_org_id
2668 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
2669 -- Component Action is exclude or enable
2670 -- we need not copy.
2671 )
2672 AND EXISTS
2673 (
2674 SELECT 1
2675 FROM fnd_lookup_values_vl flv,
2676 ego_criteria_templates_v ectv,
2677 ego_criteria_v ecv,
2678 mtl_system_items_b msibs -- to assembly item
2679 WHERE ecv.customization_application_id = 702
2680 AND ecv.region_application_id = 702
2681 AND ecv.region_code = 'BOM_ITEM_TYPE_REGION'
2682 AND ecv.customization_code = ectv.customization_code
2683 AND flv.lookup_type = 'ITEM_TYPE'
2684 AND flv.enabled_flag = 'Y'
2685 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
2686 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
2687 AND flv.lookup_code = ectv.classification1
2688 AND ectv.customization_application_id = 702
2689 AND ectv.region_application_id = 702
2690 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
2691 AND flv.lookup_code = msibs.item_type
2692 AND msibs.inventory_item_id = to_item_id
2693 AND msibs.organization_id = to_org_id
2694 AND ecv.value_varchar2 = msi.item_type -- Component
2695 UNION ALL
2696 SELECT 1
2697 FROM DUAL
2698 WHERE NOT EXISTS
2699 (
2700 SELECT 1
2701 FROM fnd_lookup_values_vl flv,
2702 ego_criteria_templates_v ectv,
2703 mtl_system_items_b msibs -- to assembly item
2704 WHERE flv.lookup_type = 'ITEM_TYPE'
2705 AND flv.enabled_flag = 'Y'
2706 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
2707 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
2708 AND flv.lookup_code = ectv.classification1
2709 AND ectv.customization_application_id = 702
2710 AND ectv.region_application_id = 702
2711 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
2712 AND flv.lookup_code = msibs.item_type
2713 AND msibs.inventory_item_id = to_item_id
2714 AND msibs.organization_id = to_org_id
2715 )
2716 );
2717 ELSIF l_from_eff_ctrl = 4 AND l_to_eff_ctrl = 1 THEN -- Rev - Date
2718
2719
2720
2721 INSERT INTO bom_components_b
2722 (shipping_allowed,
2723 required_to_ship,
2724 required_for_revenue,
2725 include_on_ship_docs,
2726 include_on_bill_docs,
2727 low_quantity,
2728 high_quantity,
2729 acd_type,
2730 component_sequence_id,
2731 old_component_sequence_id,
2732 bill_sequence_id,
2733 request_id,
2734 program_application_id,
2735 program_id,
2736 program_update_date,
2737 wip_supply_type,
2738 pick_components,
2739 supply_subinventory,
2740 supply_locator_id,
2741 operation_lead_time_percent,
2742 revised_item_sequence_id,
2743 cost_factor,
2744 operation_seq_num,
2745 component_item_id,
2746 last_update_date,
2747 last_updated_by,
2748 creation_date,
2749 created_by,
2750 last_update_login,
2751 item_num,
2752 component_quantity,
2753 component_yield_factor,
2754 component_remarks,
2755 effectivity_date,
2756 change_notice,
2757 implementation_date,
2758 disable_date,
2759 attribute_category,
2760 attribute1,
2761 attribute2,
2762 attribute3,
2763 attribute4,
2764 attribute5,
2765 attribute6,
2766 attribute7,
2767 attribute8,
2768 attribute9,
2769 attribute10,
2770 attribute11,
2771 attribute12,
2772 attribute13,
2773 attribute14,
2774 attribute15,
2775 planning_factor,
2776 quantity_related,
2777 so_basis,
2778 optional,
2779 mutually_exclusive_options,
2780 include_in_cost_rollup,
2781 check_atp,
2782 bom_item_type,
2783 from_end_item_unit_number,
2784 to_end_item_unit_number,
2785 optional_on_model,
2786 --BUGFIX 2740820
2787 parent_bill_seq_id, --BUGFIX 2740820
2788 model_comp_seq_id, --BUGFIX 2740820
2789 plan_level,
2790 --BUGFIX 2740820
2791 enforce_int_requirements, --BUGFIX 2991472
2792 from_object_revision_id,
2793 from_minor_revision_id,
2794 pk1_value,
2795 pk2_value,
2796 auto_request_material,
2797 -- Bug 3662214 : Added following 4 fields
2798 suggested_vendor_name,
2799 vendor_id,
2800 unit_price,
2801 from_end_item_rev_id,
2802 to_end_item_rev_id,
2803 from_end_item_minor_rev_id,
2804 to_end_item_minor_rev_id,
2805 component_item_revision_id,
2806 component_minor_revision_id,
2807 basis_type,
2808 to_object_revision_id,
2809 to_minor_revision_id
2810 )
2811 SELECT bic.shipping_allowed,
2812 bic.required_to_ship,
2813 bic.required_for_revenue,
2814 bic.include_on_ship_docs,
2815 bic.include_on_bill_docs,
2816 --bic.low_quantity,
2817 --bic.high_quantity,
2818 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
2819 AA.primary_unit_of_measure,BIC.low_quantity,
2820 DECODE(BIC.low_quantity,null,null, --Added this inner Deocde for Bug 6847530
2821 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
2822 NULL,
2823 BIC.low_quantity,
2824 NULL,
2825 NULL,
2826 AA.primary_unit_of_measure,
2827 MSI.primary_unit_of_measure))) Comp_low_qty,
2828 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
2829 AA.primary_unit_of_measure,BIC.high_quantity,
2830 DECODE(BIC.high_quantity,null,null, --Added this inner Deocde for Bug 6847530
2831 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
2832 NULL,
2833 BIC.high_quantity,
2834 NULL,
2835 NULL,
2836 AA.primary_unit_of_measure,
2837 MSI.primary_unit_of_measure))) Comp_high_qty,
2838 x_acd_type,
2839 bom_inventory_components_s.NEXTVAL,
2840 DECODE (x_acd_type,
2841 NULL, NULL,
2842 bom_inventory_components_s.CURRVAL
2843 ),
2844 to_sequence_id,
2845 fnd_global.conc_request_id,
2846 NULL,
2847 fnd_global.conc_program_id,
2848 sysdate,
2849 bic.wip_supply_type,
2850 DECODE (rto_flag, 'Y', 2, bic.pick_components),
2851 DECODE (x_from_org_id,
2852 to_org_id, bic.supply_subinventory,
2853 DECODE( l_default_wip_params, 1, msi.wip_supply_subinventory, NULL )
2854 ),
2855 DECODE (x_from_org_id,
2856 to_org_id, bic.supply_locator_id,
2857 DECODE( l_default_wip_params, 1, msi.wip_supply_locator_id, NULL )
2858 ),
2859 bic.operation_lead_time_percent,
2860 x_rev_item_seq_id,
2861 bic.cost_factor,
2862 bic.operation_seq_num,
2863 bic.component_item_id,
2864 SYSDATE,
2865 user_id,
2866 SYSDATE,
2867 bic.component_sequence_id,
2868 /*NULL comment for bug8431772,change NULL to user_id*/user_id,
2869 bic.item_num,
2870 -- bic.component_quantity,
2871 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
2872 AA.primary_unit_of_measure,BIC.component_quantity,
2873 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
2874 NULL,
2875 BIC.component_quantity,
2876 NULL,
2877 NULL,
2878 AA.primary_unit_of_measure,
2879 MSI.primary_unit_of_measure)) Comp_qty,
2880 bic.component_yield_factor,
2881 bic.component_remarks,
2882 -- R12 TTM ENH
2883 CASE
2884 -- The WHEN sequence is important
2885 -- For When display option is set to 2 then what ever comps are targer date we need to
2886 -- take that
2887 -- ECO conditions should be in sync with BomCopyStructureAM
2888 -- for creating revised item by grouping based on effectivity
2889 WHEN display_option = 2 AND bill_or_eco = 2
2890 THEN x_effectivity_date
2891 WHEN display_option = 2
2892 THEN trgt_comps_eff_date
2893 -- Rev to Date conversion with current and future option
2894 -- Convert the dates based on from item's revision
2895 WHEN bill_or_eco = 1 -- Inline and explosion date is past
2896 AND bic.from_end_item_rev_id IS NOT NULL
2897 AND p_end_item_rev_id IS NOT NULL
2898 AND (
2899 (
2900 SELECT fmirb.effectivity_date
2901 FROM mtl_item_revisions_b fmirb
2902 WHERE fmirb.revision_id = bic.from_end_item_rev_id
2903 ) < trgt_comps_eff_date
2904 AND (
2905 SELECT fmirb.effectivity_date
2906 FROM mtl_item_revisions_b fmirb
2907 WHERE fmirb.revision_id = p_end_item_rev_id
2908 ) < trgt_comps_eff_date
2909 )
2910 -- Explosion in the Past and Effectivity Date is also in the past, then the components
2911 -- which are past effective will be effective from trgt_comps_eff_date
2912 THEN trgt_comps_eff_date
2913 WHEN bill_or_eco = 1 -- Inline and explosion date is future
2914 AND bic.from_end_item_rev_id IS NOT NULL
2915 AND p_end_item_rev_id IS NOT NULL
2916 AND bic.from_end_item_rev_id = p_end_item_rev_id -- Future Exploded Rev
2917 AND (
2918 SELECT fmirb.effectivity_date
2919 FROM mtl_item_revisions_b fmirb
2920 WHERE fmirb.revision_id = p_end_item_rev_id
2921 ) > trgt_comps_eff_date
2922 -- Explosion in the future and Effectivity Rev is also in the future, then the components
2923 -- which are effective at the explosion rev alone will be effective from trgt_comps_eff_date
2924 THEN trgt_comps_eff_date
2925 -- Past effective components should be target data effective
2926 WHEN bill_or_eco = 1
2927 AND bic.from_end_item_rev_id IS NOT NULL
2928 AND (
2929 SELECT fmirb.effectivity_date
2930 FROM mtl_item_revisions_b fmirb
2931 WHERE fmirb.revision_id = bic.from_end_item_rev_id
2932 ) < trgt_comps_eff_date
2933 THEN trgt_comps_eff_date
2934 ELSE
2935 (
2936 SELECT fmirb.effectivity_date
2937 FROM mtl_item_revisions_b fmirb
2938 WHERE fmirb.revision_id = bic.from_end_item_rev_id
2939 )
2940 END AS effectivity_date,
2941 x_e_change_notice,
2942 -- Implementation date will be NULL for ECO flow and SYSDATE for inline copy
2943 DECODE (bill_or_eco, 2, TO_DATE (NULL), SYSDATE),
2944 CASE
2945 WHEN ( bic.to_end_item_rev_id IS NULL OR display_option = 2 )
2946 THEN TO_DATE (NULL)
2947 -- Past disabled components will be copied with disable date as null
2948 WHEN bill_or_eco = 2
2949 AND (
2950 ( SELECT fmirb.effectivity_date
2951 FROM mtl_item_revisions_b fmirb
2952 WHERE fmirb.revision_id = bic.to_end_item_rev_id
2953 ) < x_effectivity_date
2954 )
2955 THEN TO_DATE (NULL)
2956 -- Past disabled components will be copied with disable date as null
2957 WHEN bill_or_eco = 1
2958 AND (
2959 ( SELECT fmirb.effectivity_date
2960 FROM mtl_item_revisions_b fmirb
2961 WHERE fmirb.revision_id = bic.to_end_item_rev_id
2962 ) < trgt_comps_eff_date
2963 )
2964 THEN TO_DATE (NULL)
2965 -- Future disabled components should be disabled as per the disable date of component
2966 ELSE
2967 (
2968 SELECT fmirb.effectivity_date
2969 FROM mtl_item_revisions_b fmirb
2970 WHERE fmirb.revision_id = bic.to_end_item_rev_id
2971 )
2972 END AS disable_date,
2973 decode(l_prof_val, null, bic.attribute_category, l_prof_val), --introduced for bug 10078346 bic.attribute_category,
2974 bic.attribute1,
2975 bic.attribute2,
2976 bic.attribute3,
2977 bic.attribute4,
2978 bic.attribute5,
2979 bic.attribute6,
2980 bic.attribute7,
2981 bic.attribute8,
2982 bic.attribute9,
2983 bic.attribute10,
2984 bic.attribute11,
2985 bic.attribute12,
2986 bic.attribute13,
2987 bic.attribute14,
2988 bic.attribute15,
2989 bic.planning_factor,
2990 bic.quantity_related,
2991 bic.so_basis,
2992 bic.optional,
2993 bic.mutually_exclusive_options,
2994 bic.include_in_cost_rollup,
2995 bic.check_atp,
2996 msi.bom_item_type,
2997 to_char(NULL) AS from_end_item_unit_number, -- Date Eff Bill will not have from_end_item_unit_numbers
2998 to_char(NULL) AS to_end_item_unit_number, -- Date Eff Bill will not have to_end_item_unit_numbers
2999 bic.optional_on_model,
3000 --BUGFIX 2740820
3001 bic.parent_bill_seq_id, --BUGFIX 2740820
3002 bic.model_comp_seq_id,
3003 --BUGFIX 2740820
3004 bic.plan_level, --BUGFIX 2740820
3005 bic.enforce_int_requirements,
3006 -- Either Fixed or Floating rev, the components will be from when its created, current item rev
3007 l_current_item_rev_id,
3008 -- Minor rev is not supported. Populated the first minor rev
3009 0,
3010 bic.component_item_id,
3011 to_org_id,
3012 bic.auto_request_material,
3013 -- Bug 3662214 : Added following 4 fields
3014 bic.suggested_vendor_name,
3015 bic.vendor_id,
3016 bic.unit_price,
3017 to_number(NULL) AS from_end_item_rev_id, -- From End Item Rev Ids won't be set for Date Eff Bill
3018 to_number(NULL) AS to_end_item_rev_id, -- To End Item Rev Ids won't be set for Date Eff Bill
3019 -- For Minor rev Ids
3020 0 AS from_end_item_minor_rev_id,
3021 0 AS to_end_item_minor_rev_id,
3022 (
3023 SELECT tmirb.revision_id
3024 FROM mtl_item_revisions_b fmirb,
3025 mtl_item_revisions_b tmirb
3026 WHERE tmirb.inventory_item_id = bic.component_item_id
3027 AND tmirb.organization_id = to_org_id
3028 AND tmirb.revision = fmirb.revision
3029 AND fmirb.revision_id = bic.component_item_revision_id
3030 ) AS component_item_revision_id,
3031 CASE
3032 WHEN bic.component_item_revision_id IS NULL
3033 THEN to_number(NULL)
3034 ELSE
3035 -- Minor revision is not supported
3036 0
3037 END AS component_minor_revision_id,
3038 bic.basis_type,
3039 CASE
3040 WHEN l_fixed_rev IS NOT NULL
3041 -- For fixed rev copy the components as fixed rev
3042 THEN l_to_item_rev_id
3043 ELSE
3044 to_number(NULL)
3045 END AS to_object_revision_id,
3046 CASE
3047 WHEN l_fixed_rev IS NOT NULL
3048 THEN 0
3049 ELSE
3050 to_number(NULL)
3051 END AS to_minor_revision_id
3052 FROM bom_components_b bic,
3053 mtl_system_items msi,
3054 MTL_SYSTEM_ITEMS AA , -- Added corresponding to Bug 6510185
3055 bom_copy_explosions_v bev
3056 WHERE bic.bill_sequence_id = x_from_sequence_id
3057 AND bic.component_item_id = msi.inventory_item_id
3058 AND bic.component_item_id <> to_item_id
3059 AND NVL (bic.eco_for_production, 2) = 2
3060 AND msi.organization_id = to_org_id
3061 AND msi.bom_enabled_flag = 'Y' -- Added for the bug 13963236
3062 AND MSI.inventory_item_id = AA.inventory_item_id -- Added corresponding to Bug 6510185
3063 AND AA.organization_id = from_org_id -- Added corresponding to Bug 6510185
3064 AND ((direction = eng_to_bom
3065 AND msi.eng_item_flag = 'N')
3066 OR (direction <> eng_to_bom)
3067 )
3068 AND ((base_item_flag = -1
3069 AND itm_type = 4
3070 AND msi.bom_item_type = 4
3071 )
3072 OR base_item_flag <> -1
3073 OR itm_type <> 4
3074 )
3075 AND ((bic.implementation_date IS NOT NULL)
3076 OR (bic.implementation_date IS NULL
3077 AND bic.change_notice = context_eco
3078 AND ( bic.acd_type = 1 OR bic.acd_type = 2 )
3079 )
3080 )
3081 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
3082 (
3083 SELECT 1
3084 FROM bom_components_b bcb
3085 WHERE bcb.old_component_sequence_id = bic.component_sequence_id
3086 AND bcb.change_notice = context_eco
3087 AND bcb.acd_type = 3
3088 AND bcb.effectivity_date <= trgt_comps_eff_date
3089 AND bcb.implementation_date IS NULL
3090 AND bcb.bill_sequence_id = bic.bill_sequence_id
3091 )
3092 AND 'T' = bev.access_flag
3093 AND 'T' =
3094 bom_security_pub.check_item_privilege
3095 ('EGO_VIEW_ITEM',
3096 TO_CHAR (bic.component_item_id),
3097 TO_CHAR (to_org_id),
3098 bom_exploder_pub.get_ego_user
3099 )
3100 AND bic.component_sequence_id = bev.component_sequence_id
3101 AND bev.bill_sequence_id = from_sequence_id
3102 AND bev.parent_sort_order = p_parent_sort_order
3103 AND NOT EXISTS (
3104 SELECT 1
3105 FROM bom_copy_structure_actions bcsa
3106 WHERE bcsa.component_sequence_id =
3107 bic.component_sequence_id
3108 AND bcsa.copy_request_id = p_copy_request_id
3109 AND bcsa.organization_id = to_org_id
3110 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
3111 -- Component Action is exclude or enable
3112 -- we need not copy.
3113 )
3114 AND EXISTS
3115 (
3116 SELECT 1
3117 FROM fnd_lookup_values_vl flv,
3118 ego_criteria_templates_v ectv,
3119 ego_criteria_v ecv,
3120 mtl_system_items_b msibs -- to assembly item
3121 WHERE ecv.customization_application_id = 702
3122 AND ecv.region_application_id = 702
3123 AND ecv.region_code = 'BOM_ITEM_TYPE_REGION'
3124 AND ecv.customization_code = ectv.customization_code
3125 AND flv.lookup_type = 'ITEM_TYPE'
3126 AND flv.enabled_flag = 'Y'
3127 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
3128 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
3129 AND flv.lookup_code = ectv.classification1
3130 AND ectv.customization_application_id = 702
3131 AND ectv.region_application_id = 702
3132 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
3133 AND flv.lookup_code = msibs.item_type
3134 AND msibs.inventory_item_id = to_item_id
3135 AND msibs.organization_id = to_org_id
3136 AND ecv.value_varchar2 = msi.item_type -- Component
3137 UNION ALL
3138 SELECT 1
3139 FROM DUAL
3140 WHERE NOT EXISTS
3141 (
3142 SELECT 1
3143 FROM fnd_lookup_values_vl flv,
3144 ego_criteria_templates_v ectv,
3145 mtl_system_items_b msibs -- to assembly item
3146 WHERE flv.lookup_type = 'ITEM_TYPE'
3147 AND flv.enabled_flag = 'Y'
3148 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
3149 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
3150 AND flv.lookup_code = ectv.classification1
3151 AND ectv.customization_application_id = 702
3152 AND ectv.region_application_id = 702
3153 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
3154 AND flv.lookup_code = msibs.item_type
3155 AND msibs.inventory_item_id = to_item_id
3156 AND msibs.organization_id = to_org_id
3157 )
3158 );
3159 ELSIF l_from_eff_ctrl = 1 AND l_to_eff_ctrl = 4 THEN -- Date - Rev
3160
3161
3162 INSERT INTO bom_components_b
3163 (shipping_allowed,
3164 required_to_ship,
3165 required_for_revenue,
3166 include_on_ship_docs,
3167 include_on_bill_docs,
3168 low_quantity,
3169 high_quantity,
3170 acd_type,
3171 component_sequence_id,
3172 old_component_sequence_id,
3173 bill_sequence_id,
3174 request_id,
3175 program_application_id,
3176 program_id,
3177 program_update_date,
3178 wip_supply_type,
3179 pick_components,
3180 supply_subinventory,
3181 supply_locator_id,
3182 operation_lead_time_percent,
3183 revised_item_sequence_id,
3184 cost_factor,
3185 operation_seq_num,
3186 component_item_id,
3187 last_update_date,
3188 last_updated_by,
3189 creation_date,
3190 created_by,
3191 last_update_login,
3192 item_num,
3193 component_quantity,
3194 component_yield_factor,
3195 component_remarks,
3196 effectivity_date,
3197 change_notice,
3198 implementation_date,
3199 disable_date,
3200 attribute_category,
3201 attribute1,
3202 attribute2,
3203 attribute3,
3204 attribute4,
3205 attribute5,
3206 attribute6,
3207 attribute7,
3208 attribute8,
3209 attribute9,
3210 attribute10,
3211 attribute11,
3212 attribute12,
3213 attribute13,
3214 attribute14,
3215 attribute15,
3216 planning_factor,
3217 quantity_related,
3218 so_basis,
3219 optional,
3220 mutually_exclusive_options,
3221 include_in_cost_rollup,
3222 check_atp,
3223 bom_item_type,
3224 from_end_item_unit_number,
3225 to_end_item_unit_number,
3226 optional_on_model,
3227 --BUGFIX 2740820
3228 parent_bill_seq_id, --BUGFIX 2740820
3229 model_comp_seq_id, --BUGFIX 2740820
3230 plan_level,
3231 --BUGFIX 2740820
3232 enforce_int_requirements, --BUGFIX 2991472
3233 -- COMPONENT_ITEM_REVISION_ID,
3234 from_object_revision_id,
3235 from_minor_revision_id,
3236 -- FROM_BILL_REVISION_ID,
3237 pk1_value,
3238 pk2_value,
3239 auto_request_material,
3240 -- Bug 3662214 : Added following 4 fields
3241 suggested_vendor_name,
3242 vendor_id,
3243 unit_price,
3244 from_end_item_rev_id,
3245 to_end_item_rev_id,
3246 from_end_item_minor_rev_id,
3247 to_end_item_minor_rev_id,
3248 component_item_revision_id,
3249 component_minor_revision_id,
3250 basis_type,
3251 to_object_revision_id,
3252 to_minor_revision_id
3253 )
3254 SELECT bic.shipping_allowed,
3255 bic.required_to_ship,
3256 bic.required_for_revenue,
3257 bic.include_on_ship_docs,
3258 bic.include_on_bill_docs,
3259 -- bic.low_quantity,
3260 -- bic.high_quantity,
3261 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
3262 AA.primary_unit_of_measure,BIC.low_quantity,
3263 DECODE(BIC.low_quantity,null,null, --Added this inner Deocde for Bug 6847530
3264 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
3265 NULL,
3266 BIC.low_quantity,
3267 NULL,
3268 NULL,
3269 AA.primary_unit_of_measure,
3270 MSI.primary_unit_of_measure))) Comp_low_qty,
3271 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
3272 AA.primary_unit_of_measure,BIC.high_quantity,
3273 DECODE(BIC.high_quantity,null,null, --Added this inner Deocde for Bug 6847530
3274 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
3275 NULL,
3276 BIC.high_quantity,
3277 NULL,
3278 NULL,
3279 AA.primary_unit_of_measure,
3280 MSI.primary_unit_of_measure))) Comp_high_qty,
3281 x_acd_type,
3282 bom_inventory_components_s.NEXTVAL,
3283 DECODE (x_acd_type,
3284 NULL, NULL,
3285 bom_inventory_components_s.CURRVAL
3286 ),
3287 to_sequence_id,
3288 fnd_global.conc_request_id,
3289 NULL,
3290 fnd_global.conc_program_id,
3291 sysdate,
3292 bic.wip_supply_type,
3293 DECODE (rto_flag, 'Y', 2, bic.pick_components),
3294 DECODE (x_from_org_id,
3295 to_org_id, bic.supply_subinventory,
3296 DECODE( l_default_wip_params, 1, msi.wip_supply_subinventory, NULL )
3297 ),
3298 DECODE (x_from_org_id,
3299 to_org_id, bic.supply_locator_id,
3300 DECODE( l_default_wip_params, 1, msi.wip_supply_locator_id, NULL )
3301 ),
3302 bic.operation_lead_time_percent,
3303 x_rev_item_seq_id,
3304 bic.cost_factor,
3305 bic.operation_seq_num,
3306 bic.component_item_id,
3307 SYSDATE,
3308 user_id,
3309 SYSDATE,
3310 bic.component_sequence_id,
3311 /*NULL comment for bug8431772,change NULL to user_id*/user_id,
3312 bic.item_num,
3313 --bic.component_quantity,
3314 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
3315 AA.primary_unit_of_measure,BIC.component_quantity,
3316 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
3317 NULL,
3318 BIC.component_quantity,
3319 NULL,
3320 NULL,
3321 AA.primary_unit_of_measure,
3322 MSI.primary_unit_of_measure)) Comp_qty,
3323 bic.component_yield_factor,
3324 bic.component_remarks,
3325 -- R12 TTM ENH
3326 -- For Rev Eff Structure the eff date will be sysdate
3327 sysdate AS effectivity_date,
3328 x_e_change_notice,
3329 -- Implementation date will be NULL for ECO flow and SYSDATE for inline copy
3330 DECODE (bill_or_eco, 2, TO_DATE (NULL), SYSDATE),
3331 -- For Rev Eff structure the disable date will be null
3332 to_date(NULL) AS disable_date,
3333 decode(l_prof_val, null, bic.attribute_category, l_prof_val), --introduced for bug 10078346 bic.attribute_category,
3334 bic.attribute1,
3335 bic.attribute2,
3336 bic.attribute3,
3337 bic.attribute4,
3338 bic.attribute5,
3339 bic.attribute6,
3340 bic.attribute7,
3341 bic.attribute8,
3342 bic.attribute9,
3343 bic.attribute10,
3344 bic.attribute11,
3345 bic.attribute12,
3346 bic.attribute13,
3347 bic.attribute14,
3348 bic.attribute15,
3349 bic.planning_factor,
3350 bic.quantity_related,
3351 bic.so_basis,
3352 bic.optional,
3353 bic.mutually_exclusive_options,
3354 bic.include_in_cost_rollup,
3355 bic.check_atp,
3356 msi.bom_item_type,
3357 to_char(NULL) AS from_end_item_unit_number,
3358 to_char(NULL) AS to_end_item_unit_number,
3359 bic.optional_on_model,
3360 --BUGFIX 2740820
3361 bic.parent_bill_seq_id, --BUGFIX 2740820
3362 bic.model_comp_seq_id,
3363 --BUGFIX 2740820
3364 bic.plan_level, --BUGFIX 2740820
3365 bic.enforce_int_requirements,
3366 -- Either Fixed or Floating rev, the components will be from when its created, current item rev
3367 l_current_item_rev_id,
3368 -- Minor rev is not supported. Populated the first minor rev
3369 0,
3370 bic.component_item_id,
3371 to_org_id,
3372 bic.auto_request_material,
3373 -- Bug 3662214 : Added following 4 fields
3374 bic.suggested_vendor_name,
3375 bic.vendor_id,
3376 bic.unit_price,
3377 CASE
3378 -- ECO conditions should be in sync with BomCopyStructureAM
3379 -- for creating revised item by grouping based on effectivity
3380 WHEN display_option = 2 AND bill_or_eco = 2
3381 THEN eco_end_item_rev_id
3382 WHEN display_option = 2
3383 THEN trgt_comps_end_item_rev_id
3384 WHEN bill_or_eco = 1 -- Inline and explosion rev is past or smaller
3385 -- Explosion Date is past
3386 -- which are with smaller revision effective will be effective from eco_end_item_rev_id
3387 AND EXISTS
3388 (
3389 SELECT tmirb.REVISION
3390 FROM MTL_ITEM_REVISIONS_B tmirb
3391 WHERE tmirb.REVISION_ID = trgt_comps_end_item_rev_id
3392 AND tmirb.revision > get_current_item_rev(from_item_id, from_org_id, bic.effectivity_date)
3393 )
3394 AND EXISTS
3395 (
3396 SELECT tmirb.REVISION
3397 FROM MTL_ITEM_REVISIONS_B tmirb
3398 WHERE tmirb.REVISION_ID = trgt_comps_end_item_rev_id
3399 AND tmirb.revision > get_current_item_rev(from_item_id, from_org_id, rev_date)
3400 )
3401 THEN trgt_comps_end_item_rev_id
3402 WHEN bill_or_eco = 1 -- Inline and explosion Date is future
3403 -- Explosion rev is greater and from_end_item_rev is also greater, then the components
3404 -- which are effective on exploded revision will be effective from trgt_comps_end_item_rev_id
3405 AND trgt_comps_end_item_rev_id IS NOT NULL
3406 AND bic.effectivity_date = rev_date
3407 AND EXISTS
3408 (
3409 SELECT tmirb.REVISION
3410 FROM MTL_ITEM_REVISIONS_B tmirb
3411 WHERE tmirb.REVISION_ID = trgt_comps_end_item_rev_id
3412 AND tmirb.revision < get_current_item_rev(from_item_id, from_org_id, rev_date)
3413 )
3414 THEN trgt_comps_end_item_rev_id
3415 -- Past Effective should be effective from target revision
3416 WHEN bill_or_eco = 1
3417 AND EXISTS
3418 (
3419 SELECT tmirb.REVISION
3420 FROM MTL_ITEM_REVISIONS_B tmirb
3421 WHERE tmirb.REVISION_ID = trgt_comps_end_item_rev_id
3422 AND tmirb.revision > get_current_item_rev(from_item_id, from_org_id, bic.effectivity_date)
3423 )
3424 THEN trgt_comps_end_item_rev_id
3425 ELSE
3426 (
3427 SELECT tmirb.revision_id
3428 FROM mtl_item_revisions_b tmirb
3429 WHERE tmirb.inventory_item_id = to_item_id
3430 AND tmirb.organization_id = to_org_id
3431 AND tmirb.revision = get_current_item_rev(from_item_id, from_org_id, bic.effectivity_date)
3432 )
3433 END AS from_end_item_rev_id,
3434 CASE
3435 WHEN ( bic.disable_date IS NULL OR display_option = 2)
3436 THEN to_number(NULL)
3437 WHEN bill_or_eco = 1
3438 AND bic.disable_date IS NOT NULL
3439 AND EXISTS
3440 (
3441 SELECT tmirb.revision_id
3442 FROM mtl_item_revisions_b tmirb
3443 WHERE tmirb.inventory_item_id = to_item_id
3444 AND tmirb.organization_id = to_org_id
3445 AND tmirb.revision = get_current_item_rev( from_item_id, from_org_id, bic.disable_date)
3446 )
3447 AND EXISTS
3448 (
3449 SELECT mirb.REVISION
3450 FROM MTL_ITEM_REVISIONS_B mirb
3451 WHERE mirb.REVISION_ID = trgt_comps_end_item_rev_id
3452 AND mirb.revision > get_current_item_rev( from_item_id, from_org_id, bic.disable_date)
3453 )
3454 THEN to_number(NULL)
3455 WHEN
3456 bic.disable_date IS NOT NULL
3457 THEN
3458 (
3459 SELECT tmirb.revision_id
3460 FROM mtl_item_revisions_b tmirb
3461 WHERE tmirb.inventory_item_id = to_item_id
3462 AND tmirb.organization_id = to_org_id
3463 AND tmirb.revision = get_current_item_rev( from_item_id, from_org_id, bic.disable_date)
3464 )
3465 -- When No Item Rev Exists for the to item then populate to item rev as also null
3466 ELSE
3467 to_number(NULL)
3468 END AS to_end_item_rev_id,
3469 -- For Minor rev Ids
3470 0 AS from_end_item_minor_rev_id,
3471 0 AS to_end_item_minor_rev_id,
3472 (
3473 SELECT tmirb.revision_id
3474 FROM mtl_item_revisions_b fmirb,
3475 mtl_item_revisions_b tmirb
3476 WHERE tmirb.inventory_item_id = bic.component_item_id
3477 AND tmirb.organization_id = to_org_id
3478 AND tmirb.revision = fmirb.revision
3479 AND fmirb.revision_id = bic.component_item_revision_id
3480 ) AS component_item_revision_id,
3481 CASE
3482 WHEN bic.component_item_revision_id IS NULL
3483 THEN to_number(NULL)
3484 ELSE
3485 -- Minor revision is not supported
3486 0
3487 END AS component_minor_revision_id,
3488 bic.basis_type,
3489 CASE
3490 WHEN l_fixed_rev IS NOT NULL
3491 -- For fixed rev copy the components as fixed rev
3492 THEN l_to_item_rev_id
3493 ELSE
3494 to_number(NULL)
3495 END AS to_object_revision_id,
3496 CASE
3497 WHEN l_fixed_rev IS NOT NULL
3498 THEN 0
3499 ELSE
3500 to_number(NULL)
3501 END AS to_minor_revision_id
3502 FROM bom_components_b bic,
3503 mtl_system_items msi,
3504 MTL_SYSTEM_ITEMS AA , -- Added corresponding to Bug 6510185
3505 bom_copy_explosions_v bev
3506 WHERE bic.bill_sequence_id = x_from_sequence_id
3507 AND bic.component_item_id = msi.inventory_item_id
3508 AND bic.component_item_id <> to_item_id
3509 AND NVL (bic.eco_for_production, 2) = 2
3510 AND msi.organization_id = to_org_id
3511 AND MSI.inventory_item_id = AA.inventory_item_id -- Added corresponding to Bug 6510185
3512 AND AA.organization_id = from_org_id -- Added corresponding to Bug 6510185
3513
3514 AND MSI.BOM_ENABLED_FLAG = 'Y' --Bug 3595979 -- Uncommented for the bug 13963236
3515 AND ((direction = eng_to_bom
3516 AND msi.eng_item_flag = 'N')
3517 OR (direction <> eng_to_bom)
3518 )
3519 AND ((base_item_flag = -1
3520 AND itm_type = 4
3521 AND msi.bom_item_type = 4
3522 )
3523 OR base_item_flag <> -1
3524 OR itm_type <> 4
3525 )
3526 AND ((bic.implementation_date IS NOT NULL)
3527 OR (bic.implementation_date IS NULL
3528 AND bic.change_notice = context_eco
3529 AND ( bic.acd_type = 1 OR bic.acd_type = 2 )
3530 )
3531 )
3532 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
3533 (
3534 SELECT 1
3535 FROM bom_components_b bcb
3536 WHERE bcb.old_component_sequence_id = bic.component_sequence_id
3537 AND bcb.change_notice = context_eco
3538 AND bcb.acd_type = 3
3539 AND bcb.effectivity_date <= trgt_comps_eff_date
3540 AND bcb.implementation_date IS NULL
3541 AND bcb.bill_sequence_id = bic.bill_sequence_id
3542 )
3543 AND 'T' = bev.access_flag
3544 AND 'T' =
3545 bom_security_pub.check_item_privilege
3546 ('EGO_VIEW_ITEM',
3547 TO_CHAR (bic.component_item_id),
3548 TO_CHAR (to_org_id),
3549 bom_exploder_pub.get_ego_user
3550 )
3551 AND bic.component_sequence_id = bev.component_sequence_id
3552 AND bev.bill_sequence_id = from_sequence_id
3553 AND bev.parent_sort_order = p_parent_sort_order
3554 AND NOT EXISTS (
3555 SELECT 1
3556 FROM bom_copy_structure_actions bcsa
3557 WHERE bcsa.component_sequence_id =
3558 bic.component_sequence_id
3559 AND bcsa.copy_request_id = p_copy_request_id
3560 AND bcsa.organization_id = to_org_id
3561 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
3562 -- Component Action is exclude or enable
3563 -- we need not copy.
3564 )
3565 AND EXISTS
3566 (
3567 SELECT 1
3568 FROM fnd_lookup_values_vl flv,
3569 ego_criteria_templates_v ectv,
3570 ego_criteria_v ecv,
3571 mtl_system_items_b msibs -- to assembly item
3572 WHERE ecv.customization_application_id = 702
3573 AND ecv.region_application_id = 702
3574 AND ecv.region_code = 'BOM_ITEM_TYPE_REGION'
3575 AND ecv.customization_code = ectv.customization_code
3576 AND flv.lookup_type = 'ITEM_TYPE'
3577 AND flv.enabled_flag = 'Y'
3578 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
3579 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
3580 AND flv.lookup_code = ectv.classification1
3581 AND ectv.customization_application_id = 702
3582 AND ectv.region_application_id = 702
3583 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
3584 AND flv.lookup_code = msibs.item_type
3585 AND msibs.inventory_item_id = to_item_id
3586 AND msibs.organization_id = to_org_id
3587 AND ecv.value_varchar2 = msi.item_type -- Component
3588 UNION ALL
3589 SELECT 1
3590 FROM DUAL
3591 WHERE NOT EXISTS
3592 (
3593 SELECT 1
3594 FROM fnd_lookup_values_vl flv,
3595 ego_criteria_templates_v ectv,
3596 mtl_system_items_b msibs -- to assembly item
3597 WHERE flv.lookup_type = 'ITEM_TYPE'
3598 AND flv.enabled_flag = 'Y'
3599 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
3600 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
3601 AND flv.lookup_code = ectv.classification1
3602 AND ectv.customization_application_id = 702
3603 AND ectv.region_application_id = 702
3604 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
3605 AND flv.lookup_code = msibs.item_type
3606 AND msibs.inventory_item_id = to_item_id
3607 AND msibs.organization_id = to_org_id
3608 )
3609 );
3610 END IF;
3611
3612
3613 --Turn on the trigger BOMTBICX
3614 bom_globals.g_skip_bomtbicx := 'N';
3615
3616 /*
3617 --find list of actually copied comps
3618 l_comp_ctr := 1;
3619
3620 FOR j IN 1 .. copy_comps_arr.COUNT
3621 LOOP
3622 l_copied_comp_seq.EXTEND ();
3623 l_copied_comp_item_id.EXTEND ();
3624 l_copied_op_seq_num.EXTEND ();
3625 l_copied_comp_seq (l_comp_ctr) := -1;
3626 l_copied_comp_item_id (l_comp_ctr) := -1;
3627 l_copied_op_seq_num (l_comp_ctr) := -1;
3628
3629 OPEN get_copied_comps (copy_comps_arr (j),
3630 display_option,
3631 direction,
3632 x_unit_assembly,
3633 itm_type,
3634 base_item_flag,
3635 x_from_sequence_id,
3636 to_item_id,
3637 to_org_id,
3638 rev_date,
3639 unit_number
3640 );
3641
3642 --if get_copied_comps%rowcount > 0 then
3643 FETCH get_copied_comps
3644 INTO l_copied_comp_seq (l_comp_ctr),
3645 l_copied_comp_item_id (l_comp_ctr),
3646 l_copied_op_seq_num (l_comp_ctr);
3647
3648 --end if;
3649 IF l_copied_comp_seq (l_comp_ctr) <> -1
3650 THEN
3651 l_comp_ctr := l_comp_ctr + 1;
3652 END IF;
3653
3654 --this should take care of the no_data_found
3655 CLOSE get_copied_comps;
3656 END LOOP;
3657
3658 --We have a contiguous list of all copied comps. Now get the destn str components.
3659 FOR i IN 1 .. l_comp_ctr - 1
3660 LOOP
3661 l_mapped_comp_seq.EXTEND ();
3662
3663 OPEN get_mapped_components (to_sequence_id,
3664 l_copied_comp_item_id (i),
3665 l_copied_op_seq_num (i)
3666 );
3667
3668 -- if get_mapped_components%rowcount > 0 then
3669 FETCH get_mapped_components
3670 INTO l_mapped_comp_seq (i);
3671
3672 -- end if;
3673 CLOSE get_mapped_components;
3674 END LOOP;
3675 */
3676 OPEN l_from_to_comps_csr (from_sequence_id, to_sequence_id);
3677
3678 FETCH l_from_to_comps_csr
3679 BULK COLLECT INTO l_from_comps,
3680 l_to_comps;
3681
3682 IF l_from_to_comps_csr%ISOPEN THEN
3683 CLOSE l_from_to_comps_csr;
3684 END IF;
3685
3686 -- X_Copied_comp_seq_id := l_copied_comp_seq;
3687 -- X_mapped_comp_seq := l_mapped_comp_seq;
3688
3689 --Start copying user attrs
3690 IF l_from_comps.FIRST IS NOT NULL
3691 THEN
3692 l_index := l_from_comps.FIRST;
3693 WHILE l_index IS NOT NULL
3694 LOOP
3695 l_src_pk_col_name_val_pairs :=
3696 ego_col_name_value_pair_array
3697 (ego_col_name_value_pair_obj ('COMPONENT_SEQUENCE_ID',
3698 TO_CHAR (l_from_comps (l_index))
3699 ),
3700 ego_col_name_value_pair_obj ('BILL_SEQUENCE_ID',
3701 TO_CHAR (from_sequence_id)
3702 )
3703 );
3704 l_dest_pk_col_name_val_pairs :=
3705 ego_col_name_value_pair_array
3706 (ego_col_name_value_pair_obj ('COMPONENT_SEQUENCE_ID',
3707 TO_CHAR (l_to_comps (l_index))
3708 ),
3709 ego_col_name_value_pair_obj ('BILL_SEQUENCE_ID',
3710 TO_CHAR (to_sequence_id)
3711 )
3712 );
3713 l_new_str_type :=
3714 ego_col_name_value_pair_array
3715 (ego_col_name_value_pair_obj ('STRUCTURE_TYPE_ID',
3716 TO_CHAR (l_str_type)
3717 )
3718 );
3719
3720 l_old_dtlevel_col_value_pairs := EGO_COL_NAME_VALUE_PAIR_ARRAY(EGO_COL_NAME_VALUE_PAIR_OBJ( 'CONTEXT_ID', ''));
3721 l_new_dtlevel_col_value_pairs := EGO_COL_NAME_VALUE_PAIR_ARRAY(EGO_COL_NAME_VALUE_PAIR_OBJ( 'CONTEXT_ID', ''));
3722
3723 ego_user_attrs_data_pvt.copy_user_attrs_data
3724 (p_api_version => 1.0,
3725 p_application_id => bom_application_id,
3726 p_object_name => 'BOM_COMPONENTS',
3727 p_old_pk_col_value_pairs => l_src_pk_col_name_val_pairs,
3728 p_new_pk_col_value_pairs => l_dest_pk_col_name_val_pairs,
3729 p_new_cc_col_value_pairs => l_new_str_type,
3730 p_old_data_level_id => l_data_level_id_comp,
3731 p_new_data_level_id => l_data_level_id_comp,
3732 p_old_dtlevel_col_value_pairs => l_old_dtlevel_col_value_pairs,
3733 p_new_dtlevel_col_value_pairs => l_new_dtlevel_col_value_pairs,
3734 x_return_status => l_return_status,
3735 x_errorcode => l_errorcode,
3736 x_msg_count => l_msg_count,
3737 x_msg_data => l_msg_data
3738 );
3739 IF l_return_status <> fnd_api.g_ret_sts_success THEN
3740 error_handler.get_message_list(l_error_msg_tbl);
3741 IF l_error_msg_tbl.FIRST IS NOT NULL THEN
3742 l_msg_count := l_error_msg_tbl.FIRST;
3743 WHILE l_msg_count IS NOT NULL
3744 LOOP
3745 INSERT INTO mtl_interface_errors
3746 (unique_id,
3747 organization_id,
3748 transaction_id,
3749 table_name,
3750 column_name,
3751 error_message,
3752 bo_identifier,
3753 last_update_date,
3754 last_updated_by,
3755 creation_date,
3756 created_by,
3757 message_type,
3758 request_id,
3759 program_application_id,
3760 program_id,
3761 program_update_date
3762 )
3763 SELECT bcb.component_item_id,
3764 to_org_id,
3765 p_copy_request_id,
3766 NULL,
3767 get_current_item_rev (bcb.component_item_id,
3768 from_org_id,
3769 rev_date
3770 ),
3771 l_error_msg_tbl(l_msg_count).message_text,
3772 'BOM_COPY',
3773 SYSDATE,
3774 user_id,
3775 SYSDATE,
3776 user_id,
3777 'E',
3778 fnd_global.conc_request_id,
3779 NULL,
3780 fnd_global.conc_program_id,
3781 sysdate
3782 FROM bom_components_b bcb
3783 WHERE bcb.component_sequence_id = l_from_comps(l_index);
3784 l_msg_count := l_error_msg_tbl.next(l_msg_count);
3785 END LOOP;
3786 END IF;
3787 END IF;
3788 l_index := l_from_comps.next(l_index);
3789 -- Mark the components as processed if the components are added to existing eco
3790 -- and the explosion is in context of that eco
3791 IF e_change_notice IS NOT NULL AND e_change_notice = context_eco
3792 THEN
3793 FOR l_mark_comp_rec IN l_mark_components_csr(e_change_notice, from_org_id, from_sequence_id)
3794 LOOP
3795 eng_propagation_log_util.mark_component_change_transfer
3796 (
3797 p_api_version => 1.0
3798 ,p_init_msg_list => FND_API.G_FALSE
3799 ,p_commit => FND_API.G_FALSE
3800 ,x_return_status => l_return_status
3801 ,x_msg_count => l_msg_count
3802 ,x_msg_data => l_msg_data
3803 ,p_change_id => l_mark_comp_rec.change_id
3804 ,p_revised_item_sequence_id => rev_item_seq_id
3805 ,p_component_sequence_id => l_mark_comp_rec.component_sequence_id
3806 ,p_local_organization_id => to_org_id
3807 );
3808 END LOOP;
3809 END IF; -- IF e_change_notice = context_eco
3810
3811 END LOOP;
3812 END IF;
3813
3814 SELECT COUNT (*)
3815 INTO l_no_access_comp_cnt
3816 FROM bom_components_b bcb,
3817 mtl_system_items_b_kfv msbk1,
3818 bom_copy_explosions_v bev
3819 WHERE bcb.bill_sequence_id = x_from_sequence_id
3820 AND bcb.component_item_id = msbk1.inventory_item_id
3821 AND bcb.component_item_id <> to_item_id
3822 AND 'T' <>
3823 bom_security_pub.check_item_privilege
3824 ('EGO_VIEW_ITEM',
3825 TO_CHAR (bcb.component_item_id),
3826 TO_CHAR (from_org_id),
3827 bom_exploder_pub.get_ego_user
3828 )
3829 AND msbk1.organization_id = from_org_id
3830 AND bcb.component_sequence_id = bev.component_sequence_id
3831 AND bev.bill_sequence_id = from_sequence_id
3832 AND bev.parent_sort_order = p_parent_sort_order
3833 AND ((bcb.implementation_date IS NOT NULL)
3834 OR (bcb.implementation_date IS NULL
3835 AND bcb.change_notice = context_eco
3836 AND ( bcb.acd_type = 1 OR bcb.acd_type = 2 )
3837 )
3838 )
3839 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
3840 (
3841 SELECT 1
3842 FROM bom_components_b bcb1
3843 WHERE bcb1.old_component_sequence_id = bcb.component_sequence_id
3844 AND bcb1.change_notice = context_eco
3845 AND bcb1.acd_type = 3
3846 AND bcb1.effectivity_date <= trgt_comps_eff_date
3847 AND bcb1.implementation_date IS NULL
3848 AND bcb1.bill_sequence_id = bcb.bill_sequence_id
3849 )
3850 AND NOT EXISTS (
3851 SELECT 1
3852 FROM bom_copy_structure_actions bcsa
3853 WHERE bcsa.component_sequence_id =
3854 bcb.component_sequence_id
3855 AND bcsa.copy_request_id = p_copy_request_id
3856 AND bcsa.organization_id = to_org_id
3857 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
3858 -- Component Action is exclude or enable
3859 -- we need not copy.
3860 );
3861
3862 IF l_no_access_comp_cnt > 0
3863 THEN
3864 INSERT INTO mtl_interface_errors
3865 (unique_id,
3866 organization_id,
3867 transaction_id,
3868 table_name,
3869 column_name,
3870 error_message,
3871 bo_identifier,
3872 last_update_date,
3873 last_updated_by,
3874 creation_date,
3875 created_by,
3876 message_type,
3877 request_id,
3878 program_application_id,
3879 program_id,
3880 program_update_date
3881 )
3882 SELECT from_item_id,
3883 to_org_id,
3884 p_copy_request_id,
3885 NULL,
3886 get_current_item_rev (from_item_id,
3887 from_org_id,
3888 rev_date
3889 ),
3890 get_cnt_message ('BOM_COPY_ERR_COMP_NO_ACCESS',
3891 msbk1.concatenated_segments,
3892 TO_NUMBER (l_no_access_comp_cnt)
3893 ),
3894 'BOM_COPY',
3895 SYSDATE,
3896 user_id,
3897 SYSDATE,
3898 user_id,
3899 'E',
3900 fnd_global.conc_request_id,
3901 NULL,
3902 fnd_global.conc_program_id,
3903 sysdate
3904 FROM mtl_system_items_b_kfv msbk1
3905 WHERE msbk1.inventory_item_id = from_item_id
3906 AND msbk1.organization_id = from_org_id;
3907 END IF;
3908
3909 IF (from_org_id <> to_org_id)
3910 THEN
3911 SELECT COUNT (*)
3912 INTO l_no_access_comp_cnt
3913 FROM bom_components_b bcb,
3914 mtl_system_items_b_kfv msbk1,
3915 bom_copy_explosions_v bev
3916 WHERE bcb.bill_sequence_id = x_from_sequence_id
3917 AND bcb.component_item_id = msbk1.inventory_item_id
3918 AND bcb.component_item_id <> to_item_id
3919 AND 'T' <>
3920 bom_security_pub.check_item_privilege
3921 ('EGO_VIEW_ITEM',
3922 TO_CHAR (bcb.component_item_id),
3923 TO_CHAR (to_org_id),
3924 bom_exploder_pub.get_ego_user
3925 )
3926 AND msbk1.organization_id = from_org_id
3927 AND bcb.component_sequence_id = bev.component_sequence_id
3928 AND bev.bill_sequence_id = from_sequence_id
3929 AND bev.parent_sort_order = p_parent_sort_order
3930 AND ((bcb.implementation_date IS NOT NULL)
3931 OR (bcb.implementation_date IS NULL
3932 AND bcb.change_notice = context_eco
3933 AND ( bcb.acd_type = 1 OR bcb.acd_type = 2 )
3934 )
3935 )
3936 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
3937 (
3938 SELECT 1
3939 FROM bom_components_b bcb1
3940 WHERE bcb1.old_component_sequence_id = bcb.component_sequence_id
3941 AND bcb1.change_notice = context_eco
3942 AND bcb1.acd_type = 3
3943 AND bcb1.effectivity_date <= trgt_comps_eff_date
3944 AND bcb1.implementation_date IS NULL
3945 AND bcb1.bill_sequence_id = bcb.bill_sequence_id
3946 )
3947 AND NOT EXISTS (
3948 SELECT 1
3949 FROM bom_copy_structure_actions bcsa
3950 WHERE bcsa.component_sequence_id =
3951 bcb.component_sequence_id
3952 AND bcsa.copy_request_id = p_copy_request_id
3953 AND bcsa.organization_id = to_org_id
3954 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
3955 -- Component Action is exclude or enable
3956 -- we need not copy.
3957 );
3958
3959 IF l_no_access_comp_cnt > 0
3960 THEN
3961 INSERT INTO mtl_interface_errors
3962 (unique_id,
3963 organization_id,
3964 transaction_id,
3965 table_name,
3966 column_name,
3967 error_message,
3968 bo_identifier,
3969 last_update_date,
3970 last_updated_by,
3971 creation_date,
3972 created_by,
3973 message_type,
3974 request_id,
3975 program_application_id,
3976 program_id,
3977 program_update_date
3978 )
3979 SELECT from_item_id,
3980 to_org_id,
3981 p_copy_request_id,
3982 NULL,
3983 get_current_item_rev (from_item_id,
3984 from_org_id,
3985 rev_date
3986 ),
3987 get_cnt_message ('BOM_COPY_ERR_CMPDEST_NO_ACCESS',
3988 msbk1.concatenated_segments,
3989 TO_NUMBER (l_no_access_comp_cnt)
3990 ),
3991 'BOM_COPY',
3992 SYSDATE,
3993 user_id,
3994 SYSDATE,
3995 user_id,
3996 'E',
3997 fnd_global.conc_request_id,
3998 NULL,
3999 fnd_global.conc_program_id,
4000 sysdate
4001 FROM mtl_system_items_b_kfv msbk1
4002 WHERE msbk1.inventory_item_id = from_item_id
4003 AND msbk1.organization_id = from_org_id;
4004 END IF;
4005 END IF;
4006
4007 -- Insert Error messages to MTL_INTERFACE_ERRORS for each error while copying
4008 INSERT INTO mtl_interface_errors
4009 (unique_id,
4010 organization_id,
4011 transaction_id,
4012 table_name,
4013 column_name,
4014 error_message,
4015 bo_identifier,
4016 last_update_date,
4017 last_updated_by,
4018 creation_date,
4019 created_by,
4020 message_type,
4021 request_id,
4022 program_application_id,
4023 program_id,
4024 program_update_date
4025 )
4026 SELECT bcb.component_item_id,
4027 to_org_id,
4028 p_copy_request_id,
4029 NULL,
4030 get_current_item_rev (bcb.component_item_id,
4031 from_org_id,
4032 rev_date
4033 ),
4034 GET_MESSAGE ('BOM_COPY_ERR_ENG_COMP_MFG_BILL',
4035 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
4036 bom_globals.get_item_name(to_item_id, from_org_id)
4037 ),
4038 'BOM_COPY',
4039 SYSDATE,
4040 user_id,
4041 SYSDATE,
4042 user_id,
4043 'E',
4044 fnd_global.conc_request_id,
4045 NULL,
4046 fnd_global.conc_program_id,
4047 sysdate
4048 FROM bom_components_b bcb,
4049 mtl_system_items_b msib, -- component
4050 bom_copy_explosions_v bev
4051 WHERE bcb.bill_sequence_id = x_from_sequence_id
4052 AND bcb.component_item_id = msib.inventory_item_id
4053 AND bcb.component_item_id <> to_item_id
4054 AND msib.organization_id = to_org_id
4055 AND (direction = eng_to_bom
4056 AND msib.eng_item_flag = 'Y')
4057 AND bcb.component_sequence_id = bev.component_sequence_id
4058 AND bev.bill_sequence_id = from_sequence_id
4059 AND bev.parent_sort_order = p_parent_sort_order
4060 AND ((bcb.implementation_date IS NOT NULL)
4061 OR (bcb.implementation_date IS NULL
4062 AND bcb.change_notice = context_eco
4063 AND ( bcb.acd_type = 1 OR bcb.acd_type = 2 )
4064 )
4065 )
4066 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
4067 (
4068 SELECT 1
4069 FROM bom_components_b bcb1
4070 WHERE bcb1.old_component_sequence_id = bcb.component_sequence_id
4071 AND bcb1.change_notice = context_eco
4072 AND bcb1.acd_type = 3
4073 AND bcb1.effectivity_date <= trgt_comps_eff_date
4074 AND bcb1.implementation_date IS NULL
4075 AND bcb1.bill_sequence_id = bcb.bill_sequence_id
4076 )
4077 AND 'T' = bev.access_flag
4078 AND 'T' =
4079 bom_security_pub.check_item_privilege
4080 ('EGO_VIEW_ITEM',
4081 TO_CHAR (bcb.component_item_id),
4082 TO_CHAR (to_org_id),
4083 bom_exploder_pub.get_ego_user
4084 )
4085 AND NOT EXISTS (
4086 SELECT 1
4087 FROM bom_copy_structure_actions bcsa
4088 WHERE bcsa.component_sequence_id =
4089 bcb.component_sequence_id
4090 AND bcsa.copy_request_id = p_copy_request_id
4091 AND bcsa.organization_id = to_org_id
4092 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
4093 -- Component Action is exclude or enable
4094 -- we need not copy.
4095 );
4096
4097 INSERT INTO mtl_interface_errors
4098 (unique_id,
4099 organization_id,
4100 transaction_id,
4101 table_name,
4102 column_name,
4103 error_message,
4104 bo_identifier,
4105 last_update_date,
4106 last_updated_by,
4107 creation_date,
4108 created_by,
4109 message_type,
4110 request_id,
4111 program_application_id,
4112 program_id,
4113 program_update_date
4114 )
4115 SELECT bcb.component_item_id,
4116 to_org_id,
4117 p_copy_request_id,
4118 NULL,
4119 get_current_item_rev (bcb.component_item_id,
4120 from_org_id,
4121 rev_date
4122 ),
4123 GET_MESSAGE ('BOM_COPY_ERR_COMP_FOR_WIP_JOB',
4124 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
4125 bom_globals.get_item_name(to_item_id, from_org_id)
4126 ),
4127 'BOM_COPY',
4128 SYSDATE,
4129 user_id,
4130 SYSDATE,
4131 user_id,
4132 'E',
4133 fnd_global.conc_request_id,
4134 NULL,
4135 fnd_global.conc_program_id,
4136 sysdate
4137 FROM bom_components_b bcb,
4138 bom_copy_explosions_v bev
4139 WHERE bcb.bill_sequence_id = x_from_sequence_id
4140 AND bcb.component_item_id <> to_item_id
4141 AND bcb.eco_for_production <> 2
4142 AND bcb.component_sequence_id = bev.component_sequence_id
4143 AND bev.bill_sequence_id = from_sequence_id
4144 AND bev.parent_sort_order = p_parent_sort_order
4145 AND ((bcb.implementation_date IS NOT NULL)
4146 OR (bcb.implementation_date IS NULL
4147 AND bcb.change_notice = context_eco
4148 AND ( bcb.acd_type = 1 OR bcb.acd_type = 2 )
4149 )
4150 )
4151 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
4152 (
4153 SELECT 1
4154 FROM bom_components_b bcb1
4155 WHERE bcb1.old_component_sequence_id = bcb.component_sequence_id
4156 AND bcb1.change_notice = context_eco
4157 AND bcb1.acd_type = 3
4158 AND bcb1.effectivity_date <= trgt_comps_eff_date
4159 AND bcb1.implementation_date IS NULL
4160 AND bcb1.bill_sequence_id = bcb.bill_sequence_id
4161 )
4162 AND 'T' = bev.access_flag
4163 AND 'T' =
4164 bom_security_pub.check_item_privilege
4165 ('EGO_VIEW_ITEM',
4166 TO_CHAR (bcb.component_item_id),
4167 TO_CHAR (to_org_id),
4168 bom_exploder_pub.get_ego_user
4169 )
4170 AND NOT EXISTS (
4171 SELECT 1
4172 FROM bom_copy_structure_actions bcsa
4173 WHERE bcsa.component_sequence_id =
4174 bcb.component_sequence_id
4175 AND bcsa.copy_request_id = p_copy_request_id
4176 AND bcsa.organization_id = to_org_id
4177 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
4178 -- Component Action is exclude or enable
4179 -- we need not copy.
4180 );
4181
4182 /* This message need not be logged at all. When impl only is selected there won't be
4183 any unimplemented component or if there is a context eco, we need not log the message, because
4184 unimplemented components will be copied as implemented components
4185 IF ( context_eco IS NULL AND bill_or_eco = 1 )
4186 THEN
4187 INSERT INTO mtl_interface_errors
4188 (unique_id,
4189 organization_id,
4190 transaction_id,
4191 table_name,
4192 column_name,
4193 error_message,
4194 bo_identifier,
4195 last_update_date,
4196 last_updated_by,
4197 creation_date,
4198 created_by,
4199 message_type
4200 )
4201 SELECT bcb.component_item_id,
4202 to_org_id,
4203 p_copy_request_id,
4204 NULL,
4205 get_current_item_rev (msbk1.inventory_item_id,
4206 from_org_id,
4207 rev_date
4208 ),
4209 GET_MESSAGE ('BOM_COPY_ERR_UNIMPL_COMP',
4210 msbk1.concatenated_segments,
4211 msbk2.concatenated_segments
4212 ),
4213 'BOM_COPY',
4214 SYSDATE,
4215 user_id,
4216 SYSDATE,
4217 user_id,
4218 'E'
4219 FROM bom_components_b bcb,
4220 mtl_system_items_b_kfv msbk1,
4221 mtl_system_items_b_kfv msbk2,
4222 bom_copy_explosions_v bev
4223 WHERE bcb.bill_sequence_id = x_from_sequence_id
4224 AND bcb.component_item_id = msbk1.inventory_item_id
4225 AND bcb.component_item_id <> to_item_id
4226 AND bcb.implementation_date IS NULL
4227 AND msbk1.organization_id = to_org_id
4228 AND bcb.component_sequence_id = bev.component_sequence_id
4229 AND bev.bill_sequence_id = from_sequence_id
4230 AND bev.parent_sort_order = p_parent_sort_order
4231 AND msbk2.inventory_item_id = to_item_id
4232 AND msbk2.organization_id = to_org_id;
4233 END IF;
4234 */
4235
4236 INSERT INTO mtl_interface_errors
4237 (unique_id,
4238 organization_id,
4239 transaction_id,
4240 table_name,
4241 column_name,
4242 error_message,
4243 bo_identifier,
4244 last_update_date,
4245 last_updated_by,
4246 creation_date,
4247 created_by,
4248 message_type,
4249 request_id,
4250 program_application_id,
4251 program_id,
4252 program_update_date
4253 )
4254 SELECT bcb.component_item_id,
4255 to_org_id,
4256 p_copy_request_id,
4257 NULL,
4258 get_current_item_rev (bcb.component_item_id,
4259 from_org_id,
4260 rev_date
4261 ),
4262 GET_MESSAGE ('BOM_COPY_ERR_COMP_NOT_STANDARD',
4263 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
4264 bom_globals.get_item_name(to_item_id, from_org_id)
4265 ),
4266 'BOM_COPY',
4267 SYSDATE,
4268 user_id,
4269 SYSDATE,
4270 user_id,
4271 'E',
4272 fnd_global.conc_request_id,
4273 NULL,
4274 fnd_global.conc_program_id,
4275 sysdate
4276 FROM bom_components_b bcb,
4277 mtl_system_items_b msib,
4278 bom_copy_explosions_v bev
4279 WHERE bcb.bill_sequence_id = x_from_sequence_id
4280 AND bcb.component_item_id = msib.inventory_item_id
4281 AND bcb.component_item_id <> to_item_id
4282 AND bcb.implementation_date IS NOT NULL
4283 AND msib.organization_id = to_org_id
4284 AND bcb.component_sequence_id = bev.component_sequence_id
4285 AND bev.bill_sequence_id = from_sequence_id
4286 AND bev.parent_sort_order = p_parent_sort_order
4287 AND (base_item_flag = -1
4288 AND itm_type = 4
4289 AND msib.bom_item_type <> 4
4290 )
4291 AND ((bcb.implementation_date IS NOT NULL)
4292 OR (bcb.implementation_date IS NULL
4293 AND bcb.change_notice = context_eco
4294 AND ( bcb.acd_type = 1 OR bcb.acd_type = 2 )
4295 )
4296 )
4297 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
4298 (
4299 SELECT 1
4300 FROM bom_components_b bcb1
4301 WHERE bcb1.old_component_sequence_id = bcb.component_sequence_id
4302 AND bcb1.change_notice = context_eco
4303 AND bcb1.acd_type = 3
4304 AND bcb1.effectivity_date <= trgt_comps_eff_date
4305 AND bcb1.implementation_date IS NULL
4306 AND bcb1.bill_sequence_id = bcb.bill_sequence_id
4307 )
4308 AND 'T' = bev.access_flag
4309 AND 'T' =
4310 bom_security_pub.check_item_privilege
4311 ('EGO_VIEW_ITEM',
4312 TO_CHAR (bcb.component_item_id),
4313 TO_CHAR (to_org_id),
4314 bom_exploder_pub.get_ego_user
4315 )
4316 AND NOT EXISTS (
4317 SELECT 1
4318 FROM bom_copy_structure_actions bcsa
4319 WHERE bcsa.component_sequence_id =
4320 bcb.component_sequence_id
4321 AND bcsa.copy_request_id = p_copy_request_id
4322 AND bcsa.organization_id = to_org_id
4323 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
4324 -- Component Action is exclude or enable
4325 -- we need not copy.
4326 );
4327
4328 INSERT INTO mtl_interface_errors
4329 (unique_id,
4330 organization_id,
4331 transaction_id,
4332 table_name,
4333 column_name,
4334 error_message,
4335 bo_identifier,
4336 last_update_date,
4337 last_updated_by,
4338 creation_date,
4339 created_by,
4340 message_type,
4341 request_id,
4342 program_application_id,
4343 program_id,
4344 program_update_date
4345 )
4346 SELECT bcb.component_item_id,
4347 to_org_id,
4348 p_copy_request_id,
4349 NULL, -- MSBK1.CONCATENATED_SEGMENTS,
4350 get_current_item_rev(bcb.component_item_id, from_org_id, rev_date),
4351 check_component_type_rules(bcb.component_item_id,
4352 to_item_id, to_org_id),
4353 'BOM_COPY',
4354 SYSDATE,
4355 user_id,
4356 SYSDATE,
4357 user_id,
4358 'E',
4359 fnd_global.conc_request_id,
4360 NULL,
4361 fnd_global.conc_program_id,
4362 sysdate
4363 FROM bom_components_b bcb,
4364 bom_copy_explosions_v bev
4365 WHERE bcb.bill_sequence_id = x_from_sequence_id
4366 AND bcb.component_item_id <> to_item_id
4367 AND bcb.implementation_date IS NOT NULL
4368 AND bcb.component_sequence_id = bev.component_sequence_id
4369 AND bev.bill_sequence_id = from_sequence_id
4370 AND bev.parent_sort_order = p_parent_sort_order
4371 AND ((bcb.implementation_date IS NOT NULL)
4372 OR (bcb.implementation_date IS NULL
4373 AND bcb.change_notice = context_eco
4374 AND ( bcb.acd_type = 1 OR bcb.acd_type = 2 )
4375 )
4376 )
4377 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
4378 (
4379 SELECT 1
4380 FROM bom_components_b bcb1
4381 WHERE bcb1.old_component_sequence_id = bcb.component_sequence_id
4382 AND bcb1.change_notice = context_eco
4383 AND bcb1.acd_type = 3
4384 AND bcb1.effectivity_date <= trgt_comps_eff_date
4385 AND bcb1.implementation_date IS NULL
4386 AND bcb1.bill_sequence_id = bcb.bill_sequence_id
4387 )
4388 AND 'T' = bev.access_flag
4389 AND 'T' =
4390 bom_security_pub.check_item_privilege
4391 ('EGO_VIEW_ITEM',
4392 TO_CHAR (bcb.component_item_id),
4393 TO_CHAR (to_org_id),
4394 bom_exploder_pub.get_ego_user
4395 )
4396 AND NOT EXISTS (
4397 SELECT 1
4398 FROM bom_copy_structure_actions bcsa
4399 WHERE bcsa.component_sequence_id =
4400 bcb.component_sequence_id
4401 AND bcsa.copy_request_id = p_copy_request_id
4402 AND bcsa.organization_id = to_org_id
4403 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
4404 -- Component Action is exclude or enable
4405 -- we need not copy.
4406 )
4407 AND check_component_type_rules(bcb.component_item_id,
4408 to_item_id, to_org_id) IS NOT NULL; -- Component Type validation fails
4409
4410 -- For Item Revision Change Policy throw the errors if the components change requires
4411 -- change order or not allowed
4412 IF bill_or_eco = 1 THEN
4413 l_use_eco_flag := 'N';
4414 ELSE
4415 l_use_eco_flag := 'Y';
4416 END IF;
4417 IF l_to_eff_ctrl = 1 THEN
4418 INSERT INTO mtl_interface_errors
4419 (unique_id,
4420 organization_id,
4421 transaction_id,
4422 table_name,
4423 column_name,
4424 error_message,
4425 bo_identifier,
4426 last_update_date,
4427 last_updated_by,
4428 creation_date,
4429 created_by,
4430 message_type,
4431 request_id,
4432 program_application_id,
4433 program_id,
4434 program_update_date
4435 )
4436 SELECT bcb.component_item_id,
4437 to_org_id,
4438 p_copy_request_id,
4439 NULL,
4440 get_current_item_rev (bcb.component_item_id,
4441 from_org_id,
4442 rev_date
4443 ),
4444 GET_MESSAGE (
4445 'BOM_CPY_REV_CHANGE_POLICY_ERR',
4446 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
4447 bom_globals.get_item_name(to_item_id, from_org_id)
4448 ),
4449 'BOM_COPY',
4450 SYSDATE,
4451 user_id,
4452 SYSDATE,
4453 user_id,
4454 'E',
4455 fnd_global.conc_request_id,
4456 NULL,
4457 fnd_global.conc_program_id,
4458 sysdate
4459 FROM bom_components_b bcb,
4460 mtl_system_items_b msib
4461 WHERE bcb.bill_sequence_id = to_sequence_id
4462 AND bcb.component_item_id = msib.inventory_item_id
4463 AND msib.organization_id = to_org_id
4464 AND 'Y' <>
4465 bom_globals.check_change_policy_range(
4466 to_item_id,
4467 to_org_id,
4468 NULL, -- p_start_revision
4469 NULL, -- p_end_revision
4470 NULL, -- p_start_rev_id
4471 NULL, -- p_end_rev_id
4472 bcb.effectivity_date, -- p_effective_date
4473 bcb.disable_date, -- p_disable_date
4474 bom_globals.get_change_policy_val(to_item_id, to_org_id,
4475 BOM_Revisions.Get_Item_Revision_Id_Fn('ALL','ALL',to_org_id,
4476 to_item_id, NVL(x_effectivity_date, trgt_comps_eff_date)),
4477 null, -- rev id
4478 p_trgt_str_type_id), -- p_current_chg_pol
4479 p_trgt_str_type_id, -- p_structure_type_id
4480 l_use_eco_flag -- p_use_eco
4481 );
4482 ELSIF l_to_eff_ctrl = 4 THEN
4483 INSERT INTO mtl_interface_errors
4484 (unique_id,
4485 organization_id,
4486 transaction_id,
4487 table_name,
4488 column_name,
4489 error_message,
4490 bo_identifier,
4491 last_update_date,
4492 last_updated_by,
4493 creation_date,
4494 created_by,
4495 message_type,
4496 request_id,
4497 program_application_id,
4498 program_id,
4499 program_update_date
4500 )
4501 SELECT bcb.component_item_id,
4502 to_org_id,
4503 p_copy_request_id,
4504 NULL,
4505 get_current_item_rev (bcb.component_item_id,
4506 from_org_id,
4507 rev_date
4508 ),
4509 GET_MESSAGE (
4510 'BOM_CPY_REV_CHANGE_POLICY_ERR',
4511 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
4512 bom_globals.get_item_name(to_item_id, from_org_id)
4513 ),
4514 'BOM_COPY',
4515 SYSDATE,
4516 user_id,
4517 SYSDATE,
4518 user_id,
4519 'E',
4520 fnd_global.conc_request_id,
4521 NULL,
4522 fnd_global.conc_program_id,
4523 sysdate
4524 FROM bom_components_b bcb,
4525 mtl_system_items_b msib
4526 WHERE bcb.bill_sequence_id = to_sequence_id
4527 AND bcb.component_item_id = msib.inventory_item_id
4528 AND msib.organization_id = to_org_id
4529 AND 'Y' <>
4530 bom_globals.check_change_policy_range(
4531 to_item_id,
4532 to_org_id,
4533 NULL, -- p_start_revision
4534 NULL, -- p_end_revision
4535 bcb.from_end_item_rev_id, -- p_start_rev_id
4536 bcb.to_end_item_rev_id, -- p_end_rev_id
4537 NULL, -- p_effective_date
4538 NULL, -- p_disable_date
4539 bom_globals.get_change_policy_val(to_item_id, to_org_id,
4540 NVL(eco_end_item_rev_id, trgt_comps_end_item_rev_id),
4541 null, -- rev id
4542 p_trgt_str_type_id), -- p_current_chg_pol
4543 p_trgt_str_type_id, -- p_structure_type_id
4544 l_use_eco_flag -- p_use_eco
4545 );
4546 END IF;
4547
4548 -- For Rev Eff structure and copy is across org then add the error message for fixed revision components
4549 -- if revision does not exist.
4550 IF l_from_eff_ctrl = 4 AND l_to_eff_ctrl = 4
4551 AND from_org_id <> to_org_id
4552 THEN
4553 INSERT INTO mtl_interface_errors
4554 (unique_id,
4555 organization_id,
4556 transaction_id,
4557 table_name,
4558 column_name,
4559 error_message,
4560 bo_identifier,
4561 last_update_date,
4562 last_updated_by,
4563 creation_date,
4564 created_by,
4565 message_type,
4566 request_id,
4567 program_application_id,
4568 program_id,
4569 program_update_date
4570 )
4571 SELECT bcb.component_item_id,
4572 to_org_id,
4573 p_copy_request_id,
4574 NULL,
4575 get_current_item_rev (bcb.component_item_id,
4576 from_org_id,
4577 rev_date
4578 ),
4579 GET_MESSAGE
4580 ('BOM_COPY_ERR_COMP_REV_DIFF',
4581 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
4582 bom_globals.get_item_name(to_item_id, from_org_id),
4583 get_current_item_rev (bcb.component_item_id,
4584 from_org_id,
4585 rev_date
4586 )
4587 ),
4588 'BOM_COPY',
4589 SYSDATE,
4590 user_id,
4591 SYSDATE,
4592 user_id,
4593 'E',
4594 fnd_global.conc_request_id,
4595 NULL,
4596 fnd_global.conc_program_id,
4597 sysdate
4598 FROM bom_components_b bcb,
4599 bom_copy_explosions_v bev
4600 WHERE bcb.bill_sequence_id = x_from_sequence_id
4601 AND bcb.component_item_id <> to_item_id
4602 AND bcb.implementation_date IS NOT NULL
4603 AND bcb.component_sequence_id = bev.component_sequence_id
4604 -- Error needs to be logged only for fixed revision components
4605 AND bcb.component_item_revision_id IS NOT NULL
4606 AND bev.bill_sequence_id = from_sequence_id
4607 AND bev.parent_sort_order = p_parent_sort_order
4608 AND ((bcb.implementation_date IS NOT NULL)
4609 OR (bcb.implementation_date IS NULL
4610 AND bcb.change_notice = context_eco
4611 AND ( bcb.acd_type = 1 OR bcb.acd_type = 2 )
4612 )
4613 )
4614 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
4615 (
4616 SELECT 1
4617 FROM bom_components_b bcb1
4618 WHERE bcb1.old_component_sequence_id = bcb.component_sequence_id
4619 AND bcb1.change_notice = context_eco
4620 AND bcb1.acd_type = 3
4621 AND bcb1.effectivity_date <= trgt_comps_eff_date
4622 AND bcb1.implementation_date IS NULL
4623 AND bcb1.bill_sequence_id = bcb.bill_sequence_id
4624 )
4625 AND 'T' = bev.access_flag
4626 AND 'T' =
4627 bom_security_pub.check_item_privilege
4628 ('EGO_VIEW_ITEM',
4629 TO_CHAR (bcb.component_item_id),
4630 TO_CHAR (to_org_id),
4631 bom_exploder_pub.get_ego_user
4632 )
4633 AND NOT EXISTS (
4634 SELECT 1
4635 FROM bom_copy_structure_actions bcsa
4636 WHERE bcsa.component_sequence_id =
4637 bcb.component_sequence_id
4638 AND bcsa.copy_request_id = p_copy_request_id
4639 AND bcsa.organization_id = to_org_id
4640 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
4641 -- Component Action is exclude or enable
4642 -- we need not copy.
4643 )
4644 AND NOT EXISTS (
4645 SELECT tmirb.revision_id
4646 FROM mtl_item_revisions_b fmirb,
4647 mtl_item_revisions_b tmirb
4648 WHERE tmirb.inventory_item_id = bcb.component_item_id
4649 AND tmirb.organization_id = to_org_id
4650 AND tmirb.revision = fmirb.revision
4651 AND fmirb.revision_id =
4652 bcb.component_item_revision_id);
4653 END IF;
4654 ELSIF (specific_copy_flag = 'N'
4655 OR (specific_copy_flag = 'Y'
4656 AND copy_all_comps_flag = 'Y')
4657 )
4658 THEN
4659
4660
4661 INSERT INTO bom_components_b
4662 (shipping_allowed,
4663 required_to_ship,
4664 required_for_revenue,
4665 include_on_ship_docs,
4666 include_on_bill_docs,
4667 low_quantity,
4668 high_quantity,
4669 acd_type,
4670 component_sequence_id,
4671 old_component_sequence_id,
4672 bill_sequence_id,
4673 request_id,
4674 program_application_id,
4675 program_id,
4676 program_update_date,
4677 wip_supply_type,
4678 pick_components,
4679 supply_subinventory,
4680 supply_locator_id,
4681 operation_lead_time_percent,
4682 revised_item_sequence_id,
4683 cost_factor,
4684 operation_seq_num,
4685 component_item_id,
4686 last_update_date,
4687 last_updated_by,
4688 creation_date,
4689 created_by,
4690 last_update_login,
4691 item_num,
4692 component_quantity,
4693 component_yield_factor,
4694 component_remarks,
4695 effectivity_date,
4696 change_notice,
4697 implementation_date,
4698 disable_date,
4699 attribute_category,
4700 attribute1,
4701 attribute2,
4702 attribute3,
4703 attribute4,
4704 attribute5,
4705 attribute6,
4706 attribute7,
4707 attribute8,
4708 attribute9,
4709 attribute10,
4710 attribute11,
4711 attribute12,
4712 attribute13,
4713 attribute14,
4714 attribute15,
4715 planning_factor,
4716 quantity_related,
4717 so_basis,
4718 optional,
4719 mutually_exclusive_options,
4720 include_in_cost_rollup,
4721 check_atp,
4722 bom_item_type,
4723 from_end_item_unit_number,
4724 to_end_item_unit_number,
4725 optional_on_model,
4726 --BUGFIX 2740820
4727 parent_bill_seq_id, --BUGFIX 2740820
4728 model_comp_seq_id, --BUGFIX 2740820
4729 plan_level,
4730 --BUGFIX 2740820
4731 enforce_int_requirements, --BUGFIX 2991472
4732 pk1_value,
4733 /* Added to prevent BOMTSTRC from */
4734 pk2_value,
4735 /* giving errors while defaulting */
4736 auto_request_material,
4737 -- Bug 3662214 : Added following 4 fields
4738 suggested_vendor_name,
4739 vendor_id,
4740 unit_price,
4741 basis_type
4742 )
4743 SELECT shipping_allowed,
4744 required_to_ship,
4745 required_for_revenue,
4746 include_on_ship_docs,
4747 include_on_bill_docs,
4748 -- low_quantity,
4749 -- high_quantity,
4750 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
4751 AA.primary_unit_of_measure,BIC.low_quantity,
4752 DECODE(BIC.low_quantity,null,null, --Added this inner Deocde for Bug 6847530
4753 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
4754 NULL,
4755 BIC.low_quantity,
4756 NULL,
4757 NULL,
4758 AA.primary_unit_of_measure,
4759 MSI.primary_unit_of_measure))) Comp_low_qty,
4760 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
4761 AA.primary_unit_of_measure,BIC.high_quantity,
4762 DECODE(BIC.high_quantity,null,null, --Added this inner Deocde for Bug 6847530
4763 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
4764 NULL,
4765 BIC.high_quantity,
4766 NULL,
4767 NULL,
4768 AA.primary_unit_of_measure,
4769 MSI.primary_unit_of_measure))) Comp_high_qty,
4770 x_acd_type,
4771 bom_inventory_components_s.NEXTVAL,
4772 DECODE (x_acd_type,
4773 NULL, NULL,
4774 bom_inventory_components_s.CURRVAL
4775 ),
4776 to_sequence_id,
4777 fnd_global.conc_request_id,
4778 NULL,
4779 fnd_global.conc_program_id,
4780 sysdate,
4781 bic.wip_supply_type,
4782 DECODE (rto_flag, 'Y', 2, pick_components),
4783 DECODE (x_from_org_id,
4784 to_org_id, supply_subinventory,
4785 DECODE( l_default_wip_params, 1, msi.wip_supply_subinventory, NULL )
4786 ),
4787 DECODE (x_from_org_id,
4788 to_org_id, supply_locator_id,
4789 DECODE( l_default_wip_params, 1, msi.wip_supply_locator_id, NULL )
4790 ),
4791 operation_lead_time_percent,
4792 x_rev_item_seq_id,
4793 cost_factor,
4794 operation_seq_num,
4795 component_item_id,
4796 SYSDATE,
4797 user_id,
4798 SYSDATE,
4799 component_sequence_id,
4800 /*NULL comment for bug8431772,change NULL to user_id*/user_id,
4801 item_num,
4802 -- component_quantity,
4803 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
4804 AA.primary_unit_of_measure,BIC.component_quantity,
4805 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
4806 NULL,
4807 BIC.component_quantity,
4808 NULL,
4809 NULL,
4810 AA.primary_unit_of_measure,
4811 MSI.primary_unit_of_measure)) Comp_qty,
4812 component_yield_factor,
4813 component_remarks,
4814 -- Bug 2161841
4815 DECODE (bill_or_eco,
4816 2, x_effectivity_date,
4817 GREATEST (effectivity_date, SYSDATE)
4818 ),
4819 --This is replaced by the next line to handle the bug 1636829
4820 --DECODE(bill_or_eco,2,X_EFFECTIVITY_DATE,EFFECTIVITY_DATE),
4821 -- Bug 2161841
4822 -- GREATEST(EFFECTIVITY_DATE,SYSDATE),This was the orig line, was modified for eco's as per bug 315166
4823 x_e_change_notice,
4824 DECODE (bill_or_eco,
4825 2, TO_DATE (NULL),
4826 implementation_date
4827 ),
4828 DECODE (bill_or_eco, 2, TO_DATE (NULL), disable_date),
4829 decode(l_prof_val, null, bic.attribute_category, l_prof_val), --introduced for bug 10078346 bic.attribute_category,
4830 bic.attribute1,
4831 bic.attribute2,
4832 bic.attribute3,
4833 bic.attribute4,
4834 bic.attribute5,
4835 bic.attribute6,
4836 bic.attribute7,
4837 bic.attribute8,
4838 bic.attribute9,
4839 bic.attribute10,
4840 bic.attribute11,
4841 bic.attribute12,
4842 bic.attribute13,
4843 bic.attribute14,
4844 bic.attribute15,
4845 planning_factor,
4846 quantity_related,
4847 so_basis,
4848 optional,
4849 mutually_exclusive_options,
4850 include_in_cost_rollup,
4851 --DECODE(atp_comp_flag, 'Y', CHECK_ATP, 2), fixed bug 2249375
4852 check_atp,
4853 msi.bom_item_type,
4854 DECODE (bill_or_eco,
4855 2, x_unit_number,
4856 bic.from_end_item_unit_number
4857 ),
4858 bic.to_end_item_unit_number,
4859 bic.optional_on_model,
4860 --BUGFIX 2740820
4861 bic.parent_bill_seq_id, --BUGFIX 2740820
4862 bic.model_comp_seq_id,
4863 --BUGFIX 2740820
4864 bic.plan_level, --BUGFIX 2740820
4865 bic.enforce_int_requirements,
4866 --BUGFIX 2991472
4867 bic.component_item_id,
4868 to_org_id,
4869 bic.auto_request_material,
4870 -- Bug 3662214 : Added following 4 fields
4871 bic.suggested_vendor_name,
4872 bic.vendor_id,
4873 bic.unit_price,
4874 bic.basis_type
4875 FROM bom_inventory_components bic,
4876 mtl_system_items msi,
4877 MTL_SYSTEM_ITEMS AA -- Added corresponding to Bug 6510185
4878 WHERE bic.bill_sequence_id = x_from_sequence_id
4879 AND bic.component_item_id = msi.inventory_item_id
4880 AND bic.component_item_id <> to_item_id
4881 AND NVL (bic.eco_for_production, 2) = 2
4882 AND msi.organization_id = to_org_id
4883 AND MSI.inventory_item_id = AA.inventory_item_id -- Added corresponding to Bug 6510185
4884 AND AA.organization_id = from_org_id -- Added corresponding to Bug 6510185
4885 AND MSI.BOM_ENABLED_FLAG = 'Y' --Bug 3595979 -- Uncommented for the bug 13963236
4886 AND ((direction = eng_to_bom
4887 AND msi.eng_item_flag = 'N')
4888 OR (direction <> eng_to_bom)
4889 )
4890 AND ((x_unit_assembly = 'N'
4891 AND ((display_option = 1) -- ALL
4892 OR (display_option = 2
4893 AND (effectivity_date <= rev_date
4894 AND
4895 -- Added condition of sysdate for Bug 2161841
4896 ( (disable_date > rev_date
4897 AND disable_date > SYSDATE
4898 )
4899 OR disable_date IS NULL
4900 )
4901 )
4902 )
4903 OR -- CURRENT
4904 (display_option = 3
4905 AND
4906 -- Added condition of sysdate for Bug 2161841
4907 ( (disable_date > rev_date
4908 AND disable_date > SYSDATE
4909 )
4910 OR disable_date IS NULL
4911 )
4912 )
4913 ) -- CURRENT + FUTURE
4914 )
4915 OR (x_unit_assembly = 'Y'
4916 AND ((display_option = 1) -- ALL
4917 OR (display_option = 2
4918 AND disable_date IS NULL
4919 AND (from_end_item_unit_number <= unit_number
4920 AND (to_end_item_unit_number >=
4921 unit_number
4922 OR to_end_item_unit_number IS NULL
4923 )
4924 )
4925 )
4926 OR -- CURRENT
4927 (display_option = 3
4928 AND disable_date IS NULL
4929 AND (to_end_item_unit_number >= unit_number
4930 OR to_end_item_unit_number IS NULL
4931 )
4932 )
4933 ) -- CURRENT + FUTURE
4934 )
4935 )
4936 AND ((base_item_flag = -1
4937 AND itm_type = 4
4938 AND msi.bom_item_type = 4
4939 )
4940 OR base_item_flag <> -1
4941 OR itm_type <> 4
4942 )
4943 AND implementation_date IS NOT NULL;
4944 END IF;
4945
4946 copy_comps := SQL%ROWCOUNT;
4947
4948 /*
4949 Uncomment this part of code when Enable in Org component action is supported.
4950 -- Replace the components in the destination bill with the list.
4951 IF specific_copy_flag = 'Y' THEN
4952 IF replace_comps_arr IS NOT NULL AND replacement_items_arr IS NOT NULL AND replacement_items_rev_ids_arr IS NOT NULL THEN
4953 l_count1 := replace_comps_arr.FIRST;
4954 l_count2 := replacement_items_arr.FIRST;
4955 l_count3 := replacement_items_rev_ids_arr.FIRST;
4956 IF (l_count1 IS NOT NULL AND l_count2 IS NOT NULL) THEN
4957 FORALL j IN replace_comps_arr.FIRST..replace_comps_arr.LAST
4958 UPDATE BOM_COMPONENTS_B
4959 SET COMPONENT_ITEM_ID = replacement_items_arr(j),
4960 COMPONENT_ITEM_REVISION_ID = replacement_items_rev_ids_arr(j)
4961 WHERE BILL_SEQUENCE_ID = to_sequence_id
4962 AND CREATED_BY = replace_comps_arr(j);
4963 END IF;
4964 END IF;
4965 END IF;
4966 */
4967
4968 -- Bug 1825873
4969 -- if(X_from_org_id = to_org_id) then
4970 -- total_inventory_components := SQL%ROWCOUNT;
4971 -- end if;
4972 -- Bug 1825873--determine if routing exists. If not exists, then reset--operation_sequence_num to 1. If exists then, reset only missing--operation_seq_num to 1
4973 BEGIN
4974 sql_stmt_num := 25;
4975
4976 SELECT common_routing_sequence_id
4977 INTO to_rtg_seq_id
4978 FROM bom_operational_routings
4979 WHERE organization_id = to_org_id
4980 AND assembly_item_id = to_item_id
4981 AND (NVL (alternate_routing_designator, 'NONE') =
4982 NVL (to_alternate, 'NONE')
4983 OR (to_alternate IS NOT NULL
4984 AND alternate_routing_designator IS NULL
4985 AND NOT EXISTS (
4986 SELECT NULL
4987 FROM bom_operational_routings bor2
4988 WHERE bor2.organization_id = to_org_id
4989 AND bor2.assembly_item_id = to_item_id
4990 AND bor2.alternate_routing_designator =
4991 to_alternate)
4992 )
4993 );
4994 EXCEPTION
4995 WHEN NO_DATA_FOUND
4996 THEN
4997 to_rtg_seq_id := -1;
4998 WHEN OTHERS
4999 THEN
5000 err_msg := 'COPY_BILL (' || sql_stmt_num || ') ' || SQLERRM;
5001 fnd_message.set_name ('BOM', 'BOM_SQL_ERR');
5002 fnd_message.set_token ('ENTITY', err_msg);
5003 ROLLBACK TO begin_bill_copy;
5004 app_exception.raise_exception;
5005 END;
5006
5007 BEGIN
5008 --Turn off trigger BOMTBICX
5009 bom_globals.g_skip_bomtbicx := 'Y';
5010
5011 IF (to_rtg_seq_id = -1)
5012 THEN
5013 sql_stmt_num := 30;
5014
5015 UPDATE bom_inventory_components
5016 SET operation_seq_num = 1
5017 WHERE bill_sequence_id = to_sequence_id;
5018 ELSE
5019 sql_stmt_num := 35;
5020
5021 UPDATE bom_inventory_components bic
5022 SET operation_seq_num = 1
5023 WHERE bill_sequence_id = to_sequence_id
5024 AND NOT EXISTS (
5025 SELECT NULL
5026 FROM bom_operation_sequences bos
5027 WHERE routing_sequence_id = to_rtg_seq_id
5028 AND bos.operation_seq_num = bic.operation_seq_num);
5029 END IF;
5030
5031 --Turn on trigger BOMTBICX
5032 bom_globals.g_skip_bomtbicx := 'N';
5033 EXCEPTION
5034 WHEN DUP_VAL_ON_INDEX
5035 THEN
5036 RAISE overlap_error;
5037 WHEN OTHERS
5038 THEN
5039 RAISE;
5040 END;
5041
5042 --check for overlapping rows if teh above updated any rows
5043 IF (SQL%FOUND)
5044 THEN
5045 BEGIN
5046 sql_stmt_num := 40;
5047
5048 /* Serial Effectivity Implementation */
5049 IF (bom_eamutil.enabled = 'Y'
5050 AND bom_eamutil.serial_effective_item (item_id => to_item_id,
5051 org_id => to_org_id
5052 ) = 'Y'
5053 )
5054 OR (pjm_unit_eff.enabled = 'Y'
5055 AND pjm_unit_eff.unit_effective_item
5056 (x_item_id => to_item_id,
5057 x_organization_id => to_org_id
5058 ) = 'Y'
5059 )
5060 THEN
5061 SELECT COUNT (*)
5062 INTO dummy
5063 FROM bom_inventory_components bic
5064 WHERE bic.bill_sequence_id = to_sequence_id
5065 AND EXISTS (
5066 SELECT NULL
5067 FROM bom_inventory_components bic2
5068 WHERE bic2.bill_sequence_id = to_sequence_id
5069 AND bic2.ROWID <> bic.ROWID
5070 AND bic2.operation_seq_num = bic.operation_seq_num
5071 AND bic2.component_item_id = bic.component_item_id
5072 AND bic2.disable_date IS NULL
5073 AND (bic.to_end_item_unit_number IS NULL
5074 OR (bic.to_end_item_unit_number >=
5075 bic2.from_end_item_unit_number
5076 )
5077 )
5078 AND (bic2.to_end_item_unit_number IS NULL
5079 OR (bic.from_end_item_unit_number <=
5080 bic2.to_end_item_unit_number
5081 )
5082 ));
5083 ELSIF l_to_eff_ctrl = 4
5084 THEN
5085 SELECT COUNT (*)
5086 INTO dummy
5087 FROM bom_components_b bcb
5088 WHERE bcb.bill_sequence_id = to_sequence_id
5089 AND EXISTS (
5090 SELECT NULL
5091 FROM bom_components_b bcb2
5092 WHERE bcb2.bill_sequence_id = to_sequence_id
5093 AND bcb2.ROWID <> bcb.ROWID
5094 AND bcb2.operation_seq_num = bcb.operation_seq_num
5095 AND bcb2.component_item_id = bcb.component_item_id
5096 AND bcb2.disable_date IS NULL
5097 AND (bcb.to_end_item_rev_id IS NULL
5098 OR (get_minor_rev_code
5099 (bcb.to_end_item_rev_id,
5100 bcb.to_end_item_minor_rev_id
5101 ) >=
5102 get_minor_rev_code
5103 (bcb2.from_end_item_rev_id,
5104 bcb2.from_end_item_minor_rev_id
5105 )
5106 )
5107 )
5108 AND (bcb2.to_end_item_rev_id IS NULL
5109 OR (get_minor_rev_code
5110 (bcb.from_end_item_rev_id,
5111 bcb.from_end_item_minor_rev_id
5112 ) >=
5113 get_minor_rev_code
5114 (bcb2.to_end_item_rev_id,
5115 bcb2.to_end_item_minor_rev_id
5116 )
5117 )
5118 ));
5119 ELSE
5120 SELECT COUNT (*)
5121 INTO dummy
5122 FROM bom_inventory_components bic
5123 WHERE bic.bill_sequence_id = to_sequence_id
5124 AND EXISTS (
5125 SELECT NULL
5126 FROM bom_inventory_components bic2
5127 WHERE bic2.bill_sequence_id = to_sequence_id
5128 AND bic2.ROWID <> bic.ROWID
5129 AND bic2.operation_seq_num = bic.operation_seq_num
5130 AND bic2.component_item_id = bic.component_item_id
5131 AND bic2.effectivity_date <= bic.effectivity_date
5132 AND NVL (bic2.disable_date,
5133 bic.effectivity_date + 1
5134 ) > bic.effectivity_date);
5135 END IF;
5136
5137 IF (dummy <> 0)
5138 THEN
5139 -- Added for bug 3801212: Check if rows fetched to raise overlap_error
5140 RAISE overlap_error;
5141 END IF;
5142 EXCEPTION
5143 WHEN overlap_error
5144 THEN
5145 RAISE;
5146 WHEN NO_DATA_FOUND
5147 THEN
5148 NULL;
5149 WHEN OTHERS
5150 THEN
5151 err_msg := 'COPY_BILL (' || sql_stmt_num || ') ' || SQLERRM;
5152 fnd_message.set_name ('BOM', 'BOM_SQL_ERR');
5153 fnd_message.set_token ('ENTITY', err_msg);
5154 ROLLBACK TO begin_bill_copy;
5155 app_exception.raise_exception;
5156 END;
5157 END IF;
5158
5159 -- Other organizations who use our bills as common bills must have the
5160 -- component items in their organization as well.
5161 --
5162 FOR l_common_rec IN l_common_csr
5163 LOOP
5164 RAISE common_error;
5165 END LOOP;
5166
5167 -- Ensure the following rule matrix is observed
5168 --
5169 -- Y = Allowed N = Not Allowed
5170 -- P = Must be Phantom O = Must be Optional
5171 -- Configured items are ATO standard items that have a base item id.
5172 -- ATO items have Replenish to Order flags set to "Y".
5173 -- PTO items have Pick Component flags set to "Y".
5174 --
5175 -- Parent
5176 -- Child |Config ATO Mdl ATO Opt ATO Std PTO Mdl PTO Opt PTO Std
5177 -- ---------------------------------------------------------------------------
5178 -- Planning | N N N N N N N
5179 -- Configured | Y Y Y Y Y Y Y
5180 -- ATO Model | P P P N P P N
5181 -- ATO Opt Class | P P P N N N N
5182 -- ATO Standard | Y Y Y Y O O N
5183 -- PTO Model | N N N N P P N
5184 -- PTO Opt Class | N N N N P P N
5185 -- PTO Standard | N N N N Y Y Y
5186 --
5187 --
5188 -- Log errors for multi level structure copy.
5189 IF specific_copy_flag = 'Y'
5190 THEN
5191 -- Planning bill should contain only planning components
5192 INSERT INTO mtl_interface_errors
5193 (unique_id,
5194 organization_id,
5195 transaction_id,
5196 table_name,
5197 column_name,
5198 error_message,
5199 bo_identifier,
5200 last_update_date,
5201 last_updated_by,
5202 creation_date,
5203 created_by,
5204 message_type,
5205 request_id,
5206 program_application_id,
5207 program_id,
5208 program_update_date
5209 )
5210 SELECT bcb.component_item_id,
5211 to_org_id,
5212 p_copy_request_id,
5213 NULL,
5214 get_current_item_rev (bcb.component_item_id,
5215 from_org_id,
5216 rev_date
5217 ),
5218 GET_MESSAGE ('BOM_COPY_ERR_NO_PLANNING_COMPS',
5219 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
5220 bom_globals.get_item_name(to_item_id, from_org_id)
5221 ),
5222 'BOM_COPY',
5223 SYSDATE,
5224 user_id,
5225 SYSDATE,
5226 user_id,
5227 'E',
5228 fnd_global.conc_request_id,
5229 NULL,
5230 fnd_global.conc_program_id,
5231 sysdate
5232 FROM bom_components_b bcb,
5233 mtl_system_items_b msib1,
5234 mtl_system_items_b msib2
5235 WHERE bcb.bill_sequence_id = to_sequence_id
5236 AND (msib1.bom_item_type = planning
5237 AND msib2.bom_item_type <> planning
5238 )
5239 AND msib2.inventory_item_id = to_item_id
5240 AND msib2.organization_id = to_org_id
5241 AND msib1.inventory_item_id = bcb.component_item_id
5242 AND msib1.organization_id = to_org_id;
5243
5244 -- Standard bill without base model cannot have Option class or Model components.
5245 INSERT INTO mtl_interface_errors
5246 (unique_id,
5247 organization_id,
5248 transaction_id,
5249 table_name,
5250 column_name,
5251 error_message,
5252 bo_identifier,
5253 last_update_date,
5254 last_updated_by,
5255 creation_date,
5256 created_by,
5257 message_type,
5258 request_id,
5259 program_application_id,
5260 program_id,
5261 program_update_date
5262 )
5263 SELECT bcb.component_item_id,
5264 to_org_id,
5265 p_copy_request_id,
5266 NULL,
5267 get_current_item_rev (bcb.component_item_id,
5268 from_org_id,
5269 rev_date
5270 ),
5271 GET_MESSAGE ('BOM_COPY_ERR_NO_OPT_MODEL_COMP',
5272 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
5273 bom_globals.get_item_name(to_item_id, from_org_id)
5274 ),
5275 'BOM_COPY',
5276 SYSDATE,
5277 user_id,
5278 SYSDATE,
5279 user_id,
5280 'E',
5281 fnd_global.conc_request_id,
5282 NULL,
5283 fnd_global.conc_program_id,
5284 sysdate
5285 FROM bom_components_b bcb,
5286 mtl_system_items_b msib1,
5287 mtl_system_items_b msib2
5288 WHERE bcb.bill_sequence_id = to_sequence_id
5289 AND (msib1.bom_item_type IN (model, option_class)
5290 AND msib2.bom_item_type = STANDARD
5291 AND msib2.base_item_id IS NULL
5292 )
5293 AND msib2.inventory_item_id = to_item_id
5294 AND msib2.organization_id = to_org_id
5295 AND msib1.inventory_item_id = bcb.component_item_id
5296 AND msib1.organization_id = to_org_id;
5297
5298 -- No ATO Optional components in PTO bill
5299 --modified the following for BOM ER 9904085
5300 if(nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) <> 1)
5301 then
5302 INSERT INTO mtl_interface_errors
5303 (unique_id,
5304 organization_id,
5305 transaction_id,
5306 table_name,
5307 column_name,
5308 error_message,
5309 bo_identifier,
5310 last_update_date,
5311 last_updated_by,
5312 creation_date,
5313 created_by,
5314 message_type,
5315 request_id,
5316 program_application_id,
5317 program_id,
5318 program_update_date
5319 )
5320 SELECT bcb.component_item_id,
5321 to_org_id,
5322 p_copy_request_id,
5323 NULL,
5324 get_current_item_rev (bcb.component_item_id,
5325 from_org_id,
5326 rev_date
5327 ),
5328 GET_MESSAGE ('BOM_COPY_ERR_NO_ATO_OPT_COMPS',
5329 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
5330 bom_globals.get_item_name(to_item_id, from_org_id)
5331 ),
5332 'BOM_COPY',
5333 SYSDATE,
5334 user_id,
5335 SYSDATE,
5336 user_id,
5337 'E',
5338 fnd_global.conc_request_id,
5339 NULL,
5340 fnd_global.conc_program_id,
5341 sysdate
5342 FROM bom_components_b bcb,
5343 mtl_system_items_b msib1, -- Comp
5344 mtl_system_items_b msib2 -- Structure
5345 WHERE bcb.bill_sequence_id = to_sequence_id
5346 AND (msib1.replenish_to_order_flag = 'Y'
5347 AND msib1.bom_item_type = option_class
5348 AND msib2.pick_components_flag = 'Y'
5349 )
5350 AND msib2.inventory_item_id = to_item_id
5351 AND msib2.organization_id = to_org_id
5352 AND msib1.inventory_item_id = bcb.component_item_id
5353 AND msib1.organization_id = to_org_id;
5354
5355 -- No ATO standard items for PTO standard bills
5356 INSERT INTO mtl_interface_errors
5357 (unique_id,
5358 organization_id,
5359 transaction_id,
5360 table_name,
5361 column_name,
5362 error_message,
5363 bo_identifier,
5364 last_update_date,
5365 last_updated_by,
5366 creation_date,
5367 created_by,
5368 message_type,
5369 request_id,
5370 program_application_id,
5371 program_id,
5372 program_update_date
5373 )
5374 SELECT bcb.component_item_id,
5375 to_org_id,
5376 p_copy_request_id,
5377 NULL,
5378 get_current_item_rev (bcb.component_item_id,
5379 from_org_id,
5380 rev_date
5381 ),
5382 GET_MESSAGE ('BOM_COPY_ERR_NO_ATO_STD_COMPS',
5383 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
5384 bom_globals.get_item_name(to_item_id, from_org_id)
5385 ),
5386 'BOM_COPY',
5387 SYSDATE,
5388 user_id,
5389 SYSDATE,
5390 user_id,
5391 'E',
5392 fnd_global.conc_request_id,
5393 NULL,
5394 fnd_global.conc_program_id,
5395 sysdate
5396 FROM bom_components_b bcb,
5397 mtl_system_items_b msib1, -- Comp
5398 mtl_system_items_b msib2 -- Structure
5399 WHERE bcb.bill_sequence_id = to_sequence_id
5400 AND (msib1.replenish_to_order_flag = 'Y'
5401 AND msib1.bom_item_type = STANDARD
5402 AND msib2.pick_components_flag = 'Y'
5403 AND msib2.bom_item_type = STANDARD
5404 )
5405 AND msib2.inventory_item_id = to_item_id
5406 AND msib2.organization_id = to_org_id
5407 AND msib1.inventory_item_id = bcb.component_item_id
5408 AND msib1.organization_id = to_org_id;
5409 end if;
5410 --end of BOM ER 9904085
5411
5412 -- No PTO components in ATO bill
5413 INSERT INTO mtl_interface_errors
5414 (unique_id,
5415 organization_id,
5416 transaction_id,
5417 table_name,
5418 column_name,
5419 error_message,
5420 bo_identifier,
5421 last_update_date,
5422 last_updated_by,
5423 creation_date,
5424 created_by,
5425 message_type,
5426 request_id,
5427 program_application_id,
5428 program_id,
5429 program_update_date
5430 )
5431 SELECT bcb.component_item_id,
5432 to_org_id,
5433 p_copy_request_id,
5434 NULL,
5435 get_current_item_rev (bcb.component_item_id,
5436 from_org_id,
5437 rev_date
5438 ),
5439 GET_MESSAGE ('BOM_COPY_ERR_NO_PTO_COMPS',
5440 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
5441 bom_globals.get_item_name(to_item_id, from_org_id)
5442 ),
5443 'BOM_COPY',
5444 SYSDATE,
5445 user_id,
5446 SYSDATE,
5447 user_id,
5448 'E',
5449 fnd_global.conc_request_id,
5450 NULL,
5451 fnd_global.conc_program_id,
5452 sysdate
5453 FROM bom_components_b bcb,
5454 mtl_system_items_b msib1, -- Comp
5455 mtl_system_items_b msib2 -- Structure
5456 WHERE bcb.bill_sequence_id = to_sequence_id
5457 AND (msib1.pick_components_flag = 'Y'
5458 AND msib2.replenish_to_order_flag = 'Y'
5459 )
5460 AND msib2.inventory_item_id = to_item_id
5461 AND msib2.organization_id = to_org_id
5462 AND msib1.inventory_item_id = bcb.component_item_id
5463 AND msib1.organization_id = to_org_id;
5464 END IF;
5465
5466 sql_stmt_num := 41;
5467
5468 DELETE FROM bom_inventory_components bic
5469 WHERE bic.bill_sequence_id = to_sequence_id
5470 AND EXISTS (
5471 SELECT NULL
5472 FROM mtl_system_items msi1, -- bom
5473 mtl_system_items msi2 -- component
5474 WHERE ((msi2.bom_item_type = planning
5475 AND msi1.bom_item_type <> planning
5476 )
5477 OR (msi2.bom_item_type IN (model, option_class)
5478 AND msi1.bom_item_type = STANDARD
5479 AND msi1.base_item_id IS NULL
5480 )
5481 OR (msi2.replenish_to_order_flag = 'Y'
5482 AND msi2.bom_item_type = option_class
5483 AND msi1.pick_components_flag = 'Y'
5484 )
5485 OR (
5486 (nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) <> 1)
5487 and
5488 (msi2.replenish_to_order_flag = 'Y'
5489 AND msi2.bom_item_type = STANDARD
5490 AND msi1.pick_components_flag = 'Y'
5491 AND msi1.bom_item_type = STANDARD
5492 )
5493 )--modified for BOM ER 9904085
5494 OR (msi2.pick_components_flag = 'Y'
5495 AND msi1.replenish_to_order_flag = 'Y'
5496 )
5497 )
5498 AND msi1.inventory_item_id = to_item_id
5499 AND msi1.organization_id = to_org_id
5500 AND msi2.inventory_item_id = bic.component_item_id
5501 AND msi2.organization_id = to_org_id);
5502
5503 copy_comps := copy_comps - SQL%ROWCOUNT;
5504 sql_stmt_num := 43;
5505 --Turn off trigger BOMTBICX
5506 bom_globals.g_skip_bomtbicx := 'Y';
5507
5508 UPDATE bom_components_b bic
5509 SET bic.wip_supply_type = phantom
5510 WHERE bic.bill_sequence_id = to_sequence_id
5511 AND EXISTS (
5512 SELECT NULL
5513 FROM mtl_system_items msi1, -- assembly
5514 mtl_system_items msi2 -- component
5515 WHERE msi2.bom_item_type IN (model, option_class)
5516 AND msi2.inventory_item_id = bic.component_item_id
5517 AND msi2.organization_id = to_org_id
5518 AND msi1.inventory_item_id = to_item_id
5519 AND msi1.organization_id = to_org_id);
5520
5521 bom_globals.g_skip_bomtbicx := 'N';
5522 sql_stmt_num := 44;
5523 bom_globals.g_skip_bomtbicx := 'Y';
5524
5525 UPDATE bom_components_b bic
5526 SET bic.optional = 1
5527 WHERE bic.bill_sequence_id = to_sequence_id
5528 AND nvl(fnd_profile.value('BOM:MANDATORY_ATO_IN_PTO'), 2) <> 1 --added for BOM ER 9904085
5529 AND EXISTS (
5530 SELECT NULL
5531 FROM mtl_system_items msi1, -- assembly
5532 mtl_system_items msi2 -- component
5533 WHERE msi2.base_item_id IS NULL
5534 AND msi2.replenish_to_order_flag = 'Y'
5535 AND msi2.bom_item_type = STANDARD
5536 AND msi1.pick_components_flag = 'Y'
5537 AND msi1.bom_item_type = model
5538 AND msi2.inventory_item_id = bic.component_item_id
5539 AND msi2.organization_id = to_org_id
5540 AND msi1.inventory_item_id = to_item_id
5541 AND msi1.organization_id = to_org_id);
5542
5543 --separated out model and option class sections
5544 UPDATE bom_components_b bic
5545 SET bic.optional = 1
5546 WHERE bic.bill_sequence_id = to_sequence_id
5547 AND EXISTS (
5548 SELECT NULL
5549 FROM mtl_system_items msi1, -- assembly
5550 mtl_system_items msi2 -- component
5551 WHERE msi2.base_item_id IS NULL
5552 AND msi2.replenish_to_order_flag = 'Y'
5553 AND msi2.bom_item_type = STANDARD
5554 AND msi1.pick_components_flag = 'Y'
5555 AND msi1.bom_item_type = option_class
5556 AND msi2.inventory_item_id = bic.component_item_id
5557 AND msi2.organization_id = to_org_id
5558 AND msi1.inventory_item_id = to_item_id
5559 AND msi1.organization_id = to_org_id);
5560
5561
5562 --Turn on trigger BOMTBICX
5563 bom_globals.g_skip_bomtbicx := 'N';
5564 sql_stmt_num := 46;
5565
5566 IF specific_copy_flag = 'Y'
5567 THEN
5568 INSERT INTO bom_reference_designators
5569 (component_reference_designator,
5570 last_update_date,
5571 last_updated_by,
5572 creation_date,
5573 created_by,
5574 last_update_login,
5575 ref_designator_comment,
5576 change_notice,
5577 component_sequence_id,
5578 acd_type,
5579 request_id,
5580 program_application_id,
5581 program_id,
5582 program_update_date,
5583 attribute_category,
5584 attribute1,
5585 attribute2,
5586 attribute3,
5587 attribute4,
5588 attribute5,
5589 attribute6,
5590 attribute7,
5591 attribute8,
5592 attribute9,
5593 attribute10,
5594 attribute11,
5595 attribute12,
5596 attribute13,
5597 attribute14,
5598 attribute15
5599 )
5600 SELECT component_reference_designator,
5601 SYSDATE,
5602 user_id,
5603 SYSDATE,
5604 user_id,
5605 user_id, /*NULL,bug fix:8639515*/
5606 ref_designator_comment,
5607 x_e_change_notice,
5608 bic.component_sequence_id,
5609 x_acd_type,
5610 fnd_global.conc_request_id,
5611 NULL,
5612 fnd_global.conc_program_id,
5613 sysdate,
5614 brd.attribute_category,
5615 brd.attribute1,
5616 brd.attribute2,
5617 brd.attribute3,
5618 brd.attribute4,
5619 brd.attribute5,
5620 brd.attribute6,
5621 brd.attribute7,
5622 brd.attribute8,
5623 brd.attribute9,
5624 brd.attribute10,
5625 brd.attribute11,
5626 brd.attribute12,
5627 brd.attribute13,
5628 brd.attribute14,
5629 brd.attribute15
5630 FROM bom_reference_designators brd,
5631 bom_components_b bic,
5632 bom_copy_explosions_v bev
5633 WHERE bic.bill_sequence_id = to_sequence_id
5634 AND NVL (bic.eco_for_production, 2) = 2
5635 AND brd.component_sequence_id = bic.created_by
5636 AND NVL (brd.acd_type, 1) <> 3
5637 AND bic.created_by = bev.component_sequence_id
5638 AND bev.bill_sequence_id = from_sequence_id
5639 AND bev.parent_sort_order = p_parent_sort_order;
5640 ELSIF (specific_copy_flag = 'N'
5641 OR (specific_copy_flag = 'Y'
5642 AND copy_all_rfds_flag = 'Y')
5643 )
5644 THEN
5645 INSERT INTO bom_reference_designators
5646 (component_reference_designator,
5647 last_update_date,
5648 last_updated_by,
5649 creation_date,
5650 created_by,
5651 last_update_login,
5652 ref_designator_comment,
5653 change_notice,
5654 component_sequence_id,
5655 acd_type,
5656 request_id,
5657 program_application_id,
5658 program_id,
5659 program_update_date,
5660 attribute_category,
5661 attribute1,
5662 attribute2,
5663 attribute3,
5664 attribute4,
5665 attribute5,
5666 attribute6,
5667 attribute7,
5668 attribute8,
5669 attribute9,
5670 attribute10,
5671 attribute11,
5672 attribute12,
5673 attribute13,
5674 attribute14,
5675 attribute15
5676 )
5677 SELECT component_reference_designator,
5678 SYSDATE,
5679 user_id,
5680 SYSDATE,
5681 user_id,
5682 user_id,/*NULL,Bugfix:8639515*/
5683 ref_designator_comment,
5684 x_e_change_notice,
5685 bic.component_sequence_id,
5686 x_acd_type,
5687 fnd_global.conc_request_id,
5688 NULL,
5689 fnd_global.conc_program_id,
5690 sysdate,
5691 brd.attribute_category,
5692 brd.attribute1,
5693 brd.attribute2,
5694 brd.attribute3,
5695 brd.attribute4,
5696 brd.attribute5,
5697 brd.attribute6,
5698 brd.attribute7,
5699 brd.attribute8,
5700 brd.attribute9,
5701 brd.attribute10,
5702 brd.attribute11,
5703 brd.attribute12,
5704 brd.attribute13,
5705 brd.attribute14,
5706 brd.attribute15
5707 FROM bom_reference_designators brd,
5708 bom_inventory_components bic
5709 WHERE bic.bill_sequence_id = to_sequence_id
5710 AND NVL (bic.eco_for_production, 2) = 2
5711 AND brd.component_sequence_id = bic.created_by
5712 AND NVL (brd.acd_type, 1) <> 3;
5713 END IF;
5714
5715 copy_desgs := SQL%ROWCOUNT;
5716
5717 IF (x_from_org_id = to_org_id)
5718 THEN
5719 total_reference_designators := SQL%ROWCOUNT;
5720 END IF;
5721
5722 sql_stmt_num := 50;
5723
5724 IF specific_copy_flag = 'Y'
5725 THEN
5726 INSERT INTO bom_substitute_components
5727 (substitute_component_id,
5728 last_update_date,
5729 last_updated_by,
5730 creation_date,
5731 created_by,
5732 last_update_login,
5733 substitute_item_quantity,
5734 component_sequence_id,
5735 acd_type,
5736 change_notice,
5737 request_id,
5738 program_application_id,
5739 program_id,
5740 program_update_date,
5741 attribute_category,
5742 attribute1,
5743 attribute2,
5744 attribute3,
5745 attribute4,
5746 attribute5,
5747 attribute6,
5748 attribute7,
5749 attribute8,
5750 attribute9,
5751 attribute10,
5752 attribute11,
5753 attribute12,
5754 attribute13,
5755 attribute14,
5756 attribute15,
5757 enforce_int_requirements
5758 )
5759 SELECT substitute_component_id,
5760 SYSDATE,
5761 user_id,
5762 SYSDATE,
5763 user_id,
5764 /*NULL comment for bug8431772,change NULL to user_id*/user_id,
5765 --substitute_item_quantity,
5766 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
5767 AA.primary_unit_of_measure,Bsc.substitute_item_quantity,
5768 inv_convert.INV_UM_CONVERT(bsc.substitute_component_id,
5769 NULL,
5770 Bsc.substitute_item_quantity,
5771 NULL,
5772 NULL,
5773 AA.primary_unit_of_measure,
5774 MSI.primary_unit_of_measure)) Sub_Comp_qty,
5775 bic.component_sequence_id,
5776 x_acd_type,
5777 x_e_change_notice,
5778 fnd_global.conc_request_id,
5779 NULL,
5780 fnd_global.conc_program_id,
5781 sysdate,
5782 bsc.attribute_category,
5783 bsc.attribute1,
5784 bsc.attribute2,
5785 bsc.attribute3,
5786 bsc.attribute4,
5787 bsc.attribute5,
5788 bsc.attribute6,
5789 bsc.attribute7,
5790 bsc.attribute8,
5791 bsc.attribute9,
5792 bsc.attribute10,
5793 bsc.attribute11,
5794 bsc.attribute12,
5795 bsc.attribute13,
5796 bsc.attribute14,
5797 bsc.attribute15,
5798 bsc.enforce_int_requirements
5799 FROM bom_substitute_components bsc,
5800 bom_components_b bic,
5801 mtl_system_items msi,
5802 MTL_SYSTEM_ITEMS AA , -- Added corresponding to Bug 6510185
5803 bom_copy_explosions_v bev
5804 WHERE bic.bill_sequence_id = to_sequence_id
5805 AND NVL (bic.eco_for_production, 2) = 2
5806 AND bsc.component_sequence_id = bic.created_by
5807 AND NVL (bsc.acd_type, 1) <> 3
5808 AND ((direction = eng_to_bom
5809 AND msi.eng_item_flag = 'N')
5810 OR (direction <> eng_to_bom)
5811 )
5812 AND msi.inventory_item_id = bsc.substitute_component_id
5813 AND msi.organization_id = to_org_id
5814 AND msi.bom_enabled_flag = 'Y' -- Added for the bug 13963236
5815 AND bic.created_by = bev.component_sequence_id
5816 AND bev.bill_sequence_id = from_sequence_id
5817 AND bev.parent_sort_order = p_parent_sort_order
5818 AND MSI.inventory_item_id = AA.inventory_item_id -- Added corresponding to Bug 6510185
5819 AND AA.organization_id = from_org_id -- Added corresponding to Bug 6510185
5820 AND EXISTS
5821 (
5822 SELECT 1
5823 FROM fnd_lookup_values_vl flv,
5824 ego_criteria_templates_v ectv,
5825 ego_criteria_v ecv,
5826 mtl_system_items_b msibs -- to assembly item
5827 WHERE ecv.customization_application_id = 702
5828 AND ecv.region_application_id = 702
5829 AND ecv.region_code = 'BOM_ITEM_TYPE_REGION'
5830 AND ecv.customization_code = ectv.customization_code
5831 AND flv.lookup_type = 'ITEM_TYPE'
5832 AND flv.enabled_flag = 'Y'
5833 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
5834 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
5835 AND flv.lookup_code = ectv.classification1
5836 AND ectv.customization_application_id = 702
5837 AND ectv.region_application_id = 702
5838 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
5839 AND flv.lookup_code = msibs.item_type
5840 AND msibs.inventory_item_id = to_item_id
5841 AND msibs.organization_id = to_org_id
5842 AND ecv.value_varchar2 = msi.item_type -- Substitute Component
5843 UNION ALL
5844 SELECT 1
5845 FROM DUAL
5846 WHERE NOT EXISTS
5847 (
5848 SELECT 1
5849 FROM fnd_lookup_values_vl flv,
5850 ego_criteria_templates_v ectv,
5851 mtl_system_items_b msibs -- to assembly item
5852 WHERE flv.lookup_type = 'ITEM_TYPE'
5853 AND flv.enabled_flag = 'Y'
5854 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
5855 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
5856 AND flv.lookup_code = ectv.classification1
5857 AND ectv.customization_application_id = 702
5858 AND ectv.region_application_id = 702
5859 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
5860 AND flv.lookup_code = msibs.item_type
5861 AND msibs.inventory_item_id = to_item_id
5862 AND msibs.organization_id = to_org_id
5863 )
5864 );
5865 ELSIF (specific_copy_flag = 'N'
5866 OR (specific_copy_flag = 'Y'
5867 AND copy_all_subcomps_flag = 'Y')
5868 )
5869 THEN
5870 INSERT INTO bom_substitute_components
5871 (substitute_component_id,
5872 last_update_date,
5873 last_updated_by,
5874 creation_date,
5875 created_by,
5876 last_update_login,
5877 substitute_item_quantity,
5878 component_sequence_id,
5879 acd_type,
5880 change_notice,
5881 request_id,
5882 program_application_id,
5883 program_id,
5884 program_update_date,
5885 attribute_category,
5886 attribute1,
5887 attribute2,
5888 attribute3,
5889 attribute4,
5890 attribute5,
5891 attribute6,
5892 attribute7,
5893 attribute8,
5894 attribute9,
5895 attribute10,
5896 attribute11,
5897 attribute12,
5898 attribute13,
5899 attribute14,
5900 attribute15,
5901 enforce_int_requirements
5902 )
5903 SELECT substitute_component_id,
5904 SYSDATE,
5905 user_id,
5906 SYSDATE,
5907 user_id,
5908 /*NULL comment for bug8431772,change NULL to user_id*/user_id,
5909 --substitute_item_quantity,
5910 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
5911 AA.primary_unit_of_measure,Bsc.substitute_item_quantity,
5912 inv_convert.INV_UM_CONVERT(bsc.substitute_component_id,
5913 NULL,
5914 Bsc.substitute_item_quantity,
5915 NULL,
5916 NULL,
5917 AA.primary_unit_of_measure,
5918 MSI.primary_unit_of_measure)) Sub_Comp_qty,
5919 bic.component_sequence_id,
5920 x_acd_type,
5921 x_e_change_notice,
5922 fnd_global.conc_request_id,
5923 NULL,
5924 fnd_global.conc_program_id,
5925 sysdate,
5926 bsc.attribute_category,
5927 bsc.attribute1,
5928 bsc.attribute2,
5929 bsc.attribute3,
5930 bsc.attribute4,
5931 bsc.attribute5,
5932 bsc.attribute6,
5933 bsc.attribute7,
5934 bsc.attribute8,
5935 bsc.attribute9,
5936 bsc.attribute10,
5937 bsc.attribute11,
5938 bsc.attribute12,
5939 bsc.attribute13,
5940 bsc.attribute14,
5941 bsc.attribute15,
5942 bsc.enforce_int_requirements
5943 FROM bom_substitute_components bsc,
5944 bom_inventory_components bic,
5945 mtl_system_items msi,
5946 MTL_SYSTEM_ITEMS AA -- Added corresponding to Bug 6510185
5947 WHERE bic.bill_sequence_id = to_sequence_id
5948 AND NVL (bic.eco_for_production, 2) = 2
5949 AND bsc.component_sequence_id = bic.created_by
5950 AND NVL (bsc.acd_type, 1) <> 3
5951 AND ((direction = eng_to_bom
5952 AND msi.eng_item_flag = 'N')
5953 OR (direction <> eng_to_bom)
5954 )
5955 AND msi.inventory_item_id = bsc.substitute_component_id
5956 AND msi.organization_id = to_org_id
5957 AND msi.bom_enabled_flag = 'Y' -- Added for the bug 13963236
5958 AND MSI.inventory_item_id = AA.inventory_item_id -- Added corresponding to Bug 6510185
5959 AND AA.organization_id = from_org_id; -- Added corresponding to Bug 6510185;
5960 END IF;
5961
5962 copy_subs := SQL%ROWCOUNT;
5963
5964 -- Commented out for bug 14364675
5965 /*
5966 IF (x_from_org_id = to_org_id)
5967 THEN
5968 total_substitute_components := SQL%ROWCOUNT;
5969 END IF;
5970 */
5971
5972 sql_stmt_num := 51;
5973
5974 /* Copy the component operations (One To Many changes) */
5975 IF specific_copy_flag = 'Y'
5976 THEN
5977 INSERT INTO bom_component_operations
5978 (comp_operation_seq_id,
5979 operation_seq_num,
5980 operation_sequence_id,
5981 last_update_date,
5982 last_updated_by,
5983 creation_date,
5984 created_by,
5985 last_update_login,
5986 component_sequence_id,
5987 bill_sequence_id,
5988 consuming_operation_flag,
5989 consumption_quantity,
5990 supply_subinventory,
5991 supply_locator_id,
5992 wip_supply_type,
5993 attribute_category,
5994 attribute1,
5995 attribute2,
5996 attribute3,
5997 attribute4,
5998 attribute5,
5999 attribute6,
6000 attribute7,
6001 attribute8,
6002 attribute9,
6003 attribute10,
6004 attribute11,
6005 attribute12,
6006 attribute13,
6007 attribute14,
6008 attribute15,
6009 request_id,
6010 program_application_id,
6011 program_id,
6012 program_update_date
6013 )
6014 SELECT bom_component_operations_s.NEXTVAL,
6015 bco.operation_seq_num,
6016 bos.operation_sequence_id,
6017 SYSDATE,
6018 user_id,
6019 SYSDATE,
6020 user_id,
6021 /*NULL comment for bug8431772,change NULL to user_id*/user_id,
6022 bic.component_sequence_id,
6023 bic.bill_sequence_id,
6024 bco.consuming_operation_flag,
6025 bco.consumption_quantity,
6026 DECODE (x_from_org_id,
6027 to_org_id, bco.supply_subinventory,
6028 DECODE( l_default_wip_params, 1, bic.supply_subinventory, NULL )
6029 ),
6030 DECODE (x_from_org_id,
6031 to_org_id, bco.supply_locator_id,
6032 DECODE( l_default_wip_params, 1, bic.supply_locator_id, NULL )
6033 ),
6034 bco.wip_supply_type,
6035 bco.attribute_category,
6036 bco.attribute1,
6037 bco.attribute2,
6038 bco.attribute3,
6039 bco.attribute4,
6040 bco.attribute5,
6041 bco.attribute6,
6042 bco.attribute7,
6043 bco.attribute8,
6044 bco.attribute9,
6045 bco.attribute10,
6046 bco.attribute11,
6047 bco.attribute12,
6048 bco.attribute13,
6049 bco.attribute14,
6050 bco.attribute15,
6051 fnd_global.conc_request_id,
6052 NULL,
6053 fnd_global.conc_program_id,
6054 sysdate
6055 FROM bom_component_operations bco,
6056 bom_components_b bic,
6057 bom_operation_sequences bos,
6058 bom_copy_explosions_v bev
6059 WHERE bic.bill_sequence_id = to_sequence_id
6060 AND NVL (bic.eco_for_production, 2) = 2
6061 AND bco.component_sequence_id = bic.created_by
6062 AND bos.routing_sequence_id = to_rtg_seq_id
6063 AND bos.operation_seq_num = bco.operation_seq_num
6064 AND bic.created_by = bev.component_sequence_id
6065 AND bev.bill_sequence_id = from_sequence_id
6066 AND bev.parent_sort_order = p_parent_sort_order;
6067 ELSIF (specific_copy_flag = 'N'
6068 OR (specific_copy_flag = 'Y'
6069 AND copy_all_comps_flag = 'Y')
6070 )
6071 THEN
6072 INSERT INTO bom_component_operations
6073 (comp_operation_seq_id,
6074 operation_seq_num,
6075 operation_sequence_id,
6076 last_update_date,
6077 last_updated_by,
6078 creation_date,
6079 created_by,
6080 last_update_login,
6081 component_sequence_id,
6082 bill_sequence_id,
6083 consuming_operation_flag,
6084 consumption_quantity,
6085 supply_subinventory,
6086 supply_locator_id,
6087 wip_supply_type,
6088 attribute_category,
6089 attribute1,
6090 attribute2,
6091 attribute3,
6092 attribute4,
6093 attribute5,
6094 attribute6,
6095 attribute7,
6096 attribute8,
6097 attribute9,
6098 attribute10,
6099 attribute11,
6100 attribute12,
6101 attribute13,
6102 attribute14,
6103 attribute15,
6104 request_id,
6105 program_application_id,
6106 program_id,
6107 program_update_date
6108 )
6109 SELECT bom_component_operations_s.NEXTVAL,
6110 bco.operation_seq_num,
6111 bos.operation_sequence_id,
6112 SYSDATE,
6113 user_id,
6114 SYSDATE,
6115 user_id,
6116 /*NULL comment for bug8431772,change NULL to user_id*/user_id,
6117 bic.component_sequence_id,
6118 bic.bill_sequence_id,
6119 bco.consuming_operation_flag,
6120 bco.consumption_quantity,
6121 DECODE (x_from_org_id,
6122 to_org_id, bco.supply_subinventory,
6123 DECODE( l_default_wip_params, 1, bic.supply_subinventory, NULL )
6124 ),
6125 DECODE (x_from_org_id,
6126 to_org_id, bco.supply_locator_id,
6127 DECODE( l_default_wip_params, 1, bic.supply_locator_id, NULL )
6128 ),
6129 bco.wip_supply_type,
6130 bco.attribute_category,
6131 bco.attribute1,
6132 bco.attribute2,
6133 bco.attribute3,
6134 bco.attribute4,
6135 bco.attribute5,
6136 bco.attribute6,
6137 bco.attribute7,
6138 bco.attribute8,
6139 bco.attribute9,
6140 bco.attribute10,
6141 bco.attribute11,
6142 bco.attribute12,
6143 bco.attribute13,
6144 bco.attribute14,
6145 bco.attribute15,
6146 fnd_global.conc_request_id,
6147 NULL,
6148 fnd_global.conc_program_id,
6149 sysdate
6150 FROM bom_component_operations bco,
6151 bom_inventory_components bic,
6152 bom_operation_sequences bos
6153 WHERE bic.bill_sequence_id = to_sequence_id
6154 AND NVL (bic.eco_for_production, 2) = 2
6155 AND bco.component_sequence_id = bic.created_by
6156 AND bos.routing_sequence_id = to_rtg_seq_id
6157 AND bos.operation_seq_num = bco.operation_seq_num;
6158 END IF;
6159
6160 copy_compops := SQL%ROWCOUNT;
6161
6162 IF (itm_type = model
6163 OR itm_type = option_class)
6164 THEN
6165 sql_stmt_num := 55;
6166
6167 INSERT INTO bom_dependent_desc_elements
6168 (bill_sequence_id,
6169 element_name,
6170 last_update_date,
6171 last_updated_by,
6172 creation_date,
6173 created_by,
6174 last_update_login,
6175 program_application_id,
6176 program_id,
6177 program_update_date,
6178 request_id
6179 )
6180 SELECT to_sequence_id,
6181 bdde.element_name,
6182 SYSDATE,
6183 user_id,
6184 SYSDATE,
6185 user_id,
6186 user_id,
6187 NULL,
6188 fnd_global.conc_program_id,
6189 sysdate,
6190 fnd_global.conc_request_id
6191 FROM bom_dependent_desc_elements bdde
6192 WHERE bdde.bill_sequence_id = x_from_sequence_id
6193 AND ((itm_type = model
6194 AND EXISTS (
6195 SELECT NULL
6196 FROM mtl_descriptive_elements mde
6197 WHERE mde.item_catalog_group_id = itm_cat_grp_id
6198 AND mde.element_name = bdde.element_name)
6199 )
6200 OR itm_type = option_class
6201 );
6202 END IF;
6203
6204 sql_stmt_num := 70;
6205
6206 IF (specific_copy_flag = 'N'
6207 OR (specific_copy_flag = 'Y'
6208 AND copy_attach_flag = 'Y')
6209 )
6210 THEN
6211 fnd_attached_documents2_pkg.copy_attachments
6212 (x_from_entity_name => 'BOM_BILL_OF_MATERIALS',
6213 x_from_pk1_value => x_from_sequence_id,
6214 x_from_pk2_value => '',
6215 x_from_pk3_value => '',
6216 x_from_pk4_value => '',
6217 x_from_pk5_value => '',
6218 x_to_entity_name => 'BOM_BILL_OF_MATERIALS',
6219 x_to_pk1_value => to_sequence_id,
6220 x_to_pk2_value => '',
6221 x_to_pk3_value => '',
6222 x_to_pk4_value => '',
6223 x_to_pk5_value => '',
6224 x_created_by => user_id,
6225 x_last_update_login => '',
6226 x_program_application_id => '',
6227 x_program_id => fnd_global.conc_program_id,
6228 x_request_id => fnd_global.conc_request_id
6229 );
6230 END IF;
6231
6232 sql_stmt_num := 80;
6233 -- Update the created by column only when specific copy flag is no..
6234 -- If specific copy flag is 'Y', then after copy_bill, call update_created_by.
6235 IF specific_copy_flag = 'N' THEN
6236 --Turn off trigger BOMTBICX
6237 bom_globals.g_skip_bomtbicx := 'Y';
6238
6239 UPDATE bom_components_b bic
6240 SET created_by = user_id
6241 WHERE bic.bill_sequence_id = to_sequence_id;
6242
6243 --Turn on trigger BOMTBICX
6244 bom_globals.g_skip_bomtbicx := 'N';
6245 END IF;
6246 sql_stmt_num := 85;
6247
6248 SELECT COUNT (*)
6249 INTO copy_comts
6250 FROM fnd_attached_documents
6251 WHERE entity_name = 'BOM_BILL_OF_MATERIALS'
6252 AND pk1_value = to_char(to_sequence_id); --Bug 12569030, Added to_char
6253
6254 IF (x_from_org_id = to_org_id)
6255 THEN
6256 sql_stmt_num := 87;
6257 total_assembly_comments := copy_comts;
6258 END IF;
6259
6260 fnd_message.set_name ('BOM', 'BOM_BILL_COPY_DONE');
6261 fnd_message.set_token ('ENTITY1', copy_comps);
6262 fnd_message.set_token ('ENTITY2', total_inventory_components);
6263 fnd_message.set_token ('ENTITY3', copy_comts);
6264 fnd_message.set_token ('ENTITY4', total_assembly_comments);
6265 fnd_message.set_token ('ENTITY5', copy_desgs);
6266 fnd_message.set_token ('ENTITY6', total_reference_designators);
6267 fnd_message.set_token ('ENTITY7', copy_subs);
6268 fnd_message.set_token ('ENTITY8', total_substitute_components);
6269 fnd_message.set_token ('ENTITY9', copy_compops);
6270 fnd_message.set_token ('ENTITY10', total_component_operations);
6271 -- dbms_profiler.stop_profiler();
6272 EXCEPTION
6273 WHEN overlap_error
6274 THEN
6275 bom_globals.g_skip_bomtbicx := 'N';
6276 fnd_message.set_name ('BOM', 'BOM_BAD_COPY_GUI');
6277
6278 IF specific_copy_flag = 'Y'
6279 THEN
6280 INSERT INTO mtl_interface_errors
6281 (unique_id,
6282 organization_id,
6283 transaction_id,
6284 table_name,
6285 column_name,
6286 error_message,
6287 bo_identifier,
6288 last_update_date,
6289 last_updated_by,
6290 creation_date,
6291 created_by,
6292 message_type,
6293 request_id,
6294 program_application_id,
6295 program_id,
6296 program_update_date
6297 )
6298 VALUES (to_item_id,
6299 to_org_id,
6300 p_copy_request_id,
6301 NULL,
6302 get_current_item_rev (to_item_id,
6303 from_org_id,
6304 SYSDATE
6305 ),
6306 fnd_message.get,
6307 'BOM_COPY',
6308 SYSDATE,
6309 user_id,
6310 SYSDATE,
6311 user_id,
6312 'E',
6313 fnd_global.conc_request_id,
6314 NULL,
6315 fnd_global.conc_program_id,
6316 sysdate
6317 );
6318 ELSE
6319 ROLLBACK TO begin_bill_copy;
6320 app_exception.raise_exception;
6321 END IF;
6322 WHEN common_error
6323 THEN
6324 bom_globals.g_skip_bomtbicx := 'N';
6325 fnd_message.set_name ('BOM', 'BOM_COMMON_OTHER_ORGS2');
6326
6327 IF specific_copy_flag = 'Y'
6328 THEN
6329 INSERT INTO mtl_interface_errors
6330 (unique_id,
6331 organization_id,
6332 transaction_id,
6333 table_name,
6334 column_name,
6335 error_message,
6336 bo_identifier,
6337 last_update_date,
6338 last_updated_by,
6339 creation_date,
6340 created_by,
6341 message_type,
6342 request_id,
6343 program_application_id,
6344 program_id,
6345 program_update_date
6346 )
6347 VALUES (to_item_id,
6348 to_org_id,
6349 p_copy_request_id,
6350 NULL,
6351 get_current_item_rev (to_item_id,
6352 from_org_id,
6353 SYSDATE
6354 ),
6355 fnd_message.get,
6356 'BOM_COPY',
6357 SYSDATE,
6358 user_id,
6359 SYSDATE,
6360 user_id,
6361 'E',
6362 fnd_global.conc_request_id,
6363 NULL,
6364 fnd_global.conc_program_id,
6365 sysdate
6366 );
6367 ELSE
6368 ROLLBACK TO begin_bill_copy;
6369 app_exception.raise_exception;
6370 END IF;
6371 WHEN OTHERS
6372 THEN
6373 bom_globals.g_skip_bomtbicx := 'N';
6374 err_msg := 'COPY_BILL (' || sql_stmt_num || ') ' || SQLERRM;
6375 fnd_message.set_name ('BOM', 'BOM_SQL_ERR');
6376 fnd_message.set_token ('ENTITY', err_msg);
6377 ROLLBACK TO begin_bill_copy;
6378 app_exception.raise_exception;
6379 END copy_bill;
6380
6381 /* This function is no longer required. 03-Jan-2006 Bug 4916826
6382 FUNCTION get_component_path (
6383 p_item_id IN NUMBER,
6384 p_org_id IN NUMBER,
6385 p_explode_grp_id IN NUMBER,
6386 p_sort_order IN VARCHAR2
6387 )
6388 RETURN VARCHAR2
6389 IS
6390 l_component_path VARCHAR2 (4820);
6391 l_component_name VARCHAR2 (240);
6392
6393 CURSOR c_component_cur (
6394 c_sort_order IN VARCHAR2,
6395 c_explode_group_id IN NUMBER
6396 )
6397 IS
6398 SELECT component_item_id
6399 FROM bom_copy_explosions_v bs
6400 WHERE bs.sort_order <> c_sort_order
6401 AND bs.GROUP_ID = c_explode_group_id
6402 START WITH bs.sort_order = c_sort_order
6403 AND bs.GROUP_ID = c_explode_group_id
6404 CONNECT BY PRIOR bs.parent_sort_order = bs.sort_order
6405 AND bs.GROUP_ID = c_explode_group_id;
6406 BEGIN
6407 l_component_path := '';
6408
6409 FOR component_rec IN c_component_cur (p_sort_order, p_explode_grp_id)
6410 LOOP
6411 SELECT concatenated_segments
6412 INTO l_component_name
6413 FROM mtl_system_items_b_kfv msbk
6414 WHERE msbk.inventory_item_id = component_rec.component_item_id
6415 AND msbk.organization_id = p_org_id;
6416
6417 IF (l_component_path IS NULL)
6418 THEN
6419 l_component_path := l_component_name;
6420 ELSE
6421 l_component_path := l_component_name || '>' || l_component_path;
6422 END IF;
6423 END LOOP;
6424
6425 RETURN l_component_path;
6426 END get_component_path;*/
6427
6428 FUNCTION GET_MESSAGE (p_msg_name IN VARCHAR2, p_comp_item IN VARCHAR2)
6429 RETURN VARCHAR2
6430 IS
6431 BEGIN
6432 fnd_message.set_name ('BOM', p_msg_name);
6433 fnd_message.set_token ('COMP_ITEM', p_comp_item);
6434 RETURN fnd_message.get;
6435 END;
6436
6437 FUNCTION GET_MESSAGE (
6438 p_msg_name IN VARCHAR2,
6439 p_comp_item IN VARCHAR2,
6440 p_assembly_item IN VARCHAR2
6441 )
6442 RETURN VARCHAR2
6443 IS
6444 BEGIN
6445 fnd_message.set_name ('BOM', p_msg_name);
6446 fnd_message.set_token ('COMP_ITEM', p_comp_item);
6447 fnd_message.set_token ('ASSEMBLY_ITEM', p_assembly_item);
6448 RETURN fnd_message.get;
6449 END;
6450
6451 FUNCTION GET_MESSAGE (
6452 p_msg_name IN VARCHAR2,
6453 p_comp_item IN VARCHAR2,
6454 p_assembly_item IN VARCHAR2,
6455 p_comp_rev IN VARCHAR2
6456 )
6457 RETURN VARCHAR2
6458 IS
6459 BEGIN
6460 fnd_message.set_name ('BOM', p_msg_name);
6461 fnd_message.set_token ('COMP_ITEM', p_comp_item);
6462 fnd_message.set_token ('ASSEMBLY_ITEM', p_assembly_item);
6463 fnd_message.set_token ('COMP_REV', p_comp_rev);
6464 RETURN fnd_message.get;
6465 END;
6466
6467 FUNCTION get_cnt_message (
6468 p_msg_name IN VARCHAR2,
6469 p_assembly_item IN VARCHAR2,
6470 p_comp_count IN NUMBER
6471 )
6472 RETURN VARCHAR2
6473 IS
6474 BEGIN
6475 fnd_message.set_name ('BOM', p_msg_name);
6476 fnd_message.set_token ('ASSEMBLY_ITEM', p_assembly_item);
6477 fnd_message.set_token ('COMP_CNT', p_comp_count);
6478 RETURN fnd_message.get;
6479 END;
6480
6481 PROCEDURE assign_items_to_copy_to_org (
6482 p_cp_request_id IN NUMBER,
6483 p_copy_request_id IN NUMBER,
6484 p_from_org_id IN NUMBER,
6485 p_to_org_id IN NUMBER,
6486 p_to_org_code IN VARCHAR2,
6487 p_usr_id IN NUMBER,
6488 p_context_eco IN VARCHAR2,
6489 p_to_item_id IN NUMBER,
6490 p_master_org_id IN NUMBER
6491 )
6492 IS
6493 TYPE item_table IS TABLE OF mtl_system_items_interface%ROWTYPE;
6494
6495 l_item_tbl item_table;
6496 l_set_process_id NUMBER := 0;
6497 x_item_table ego_item_pub.item_tbl_type;
6498 x_inventory_item_id mtl_system_items_b.inventory_item_id%TYPE;
6499 x_organization_id mtl_system_items_b.organization_id%TYPE;
6500 x_return_status VARCHAR2 (1);
6501 x_msg_count NUMBER (10);
6502 x_msg_data VARCHAR2 (2000);
6503 x_message_list error_handler.error_tbl_type;
6504 l_program_appl_id NUMBER;
6505 l_program_id NUMBER;
6506 l_program_update_date DATE;
6507 err_msg VARCHAR2 (2000);
6508 l_return_status VARCHAR2 (1) := 'S';
6509 l_item_rec_in inv_item_grp.item_rec_type;
6510 l_item_rec_out inv_item_grp.item_rec_type;
6511 l_error_tbl inv_item_grp.error_tbl_type;
6512 x_msg_list error_handler.error_tbl_type;
6513 l_item_org_assign_tbl system.EGO_ITEM_ORG_ASSIGN_TABLE := new system.EGO_ITEM_ORG_ASSIGN_TABLE();
6514 l_trgt_item_uom_code mtl_system_items_b.primary_uom_code%TYPE;
6515 l_trgt_item_name mtl_system_items_b_kfv.concatenated_segments%TYPE;
6516 l_secondary_uom_code mtl_system_items_b_kfv.secondary_uom_code%TYPE;
6517 l_dual_uom_deviation_high mtl_system_items_b_kfv.dual_uom_deviation_high%TYPE;
6518 l_dual_uom_deviation_low mtl_system_items_b_kfv.dual_uom_deviation_low%TYPE;
6519 l_secondary_default_ind mtl_system_items_b_kfv.secondary_default_ind%TYPE;
6520 l_tracking_quantity_ind mtl_system_items_b_kfv.tracking_quantity_ind%TYPE;
6521 l_ont_pricing_qty_source mtl_system_items_b_kfv.ont_pricing_qty_source%TYPE;
6522 l_not_exists NUMBER := 0;
6523 l_msg_count NUMBER := 0;
6524 l_item_count NUMBER := 1;
6525 l_index NUMBER := 0;
6526
6527 CURSOR l_item_org_csr (
6528 c_org_id IN NUMBER,
6529 c_org_code IN VARCHAR2,
6530 c_context_eco IN VARCHAR2
6531 )
6532 IS
6533 SELECT msibk.inventory_item_id,
6534 concatenated_segments item_number,
6535 -- c_org_id organization_id,
6536 -- c_org_code organization_code,
6537 msibk.primary_uom_code,
6538 msibk.secondary_uom_code,
6539 msibk.dual_uom_deviation_high,
6540 msibk.dual_uom_deviation_low,
6541 msibk.secondary_default_ind,
6542 msibk.tracking_quantity_ind,
6543 msibk.ont_pricing_qty_source
6544 FROM mtl_system_items_b_kfv msibk,
6545 bom_copy_explosions_v bev
6546 WHERE msibk.inventory_item_id = bev.component_item_id
6547 AND msibk.organization_id = bev.organization_id
6548 AND (bev.implementation_date IS NOT NULL
6549 OR (bev.implementation_date IS NULL
6550 AND bev.change_notice = c_context_eco
6551 AND bev.acd_type = 1
6552 )
6553 )
6554 /*
6555 Pass trgt_comps_eff_date and do this validation
6556 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
6557 (
6558 SELECT 1
6559 FROM bom_components_b bcb
6560 WHERE bcb.old_component_sequence_id = bev.component_sequence_id
6561 AND bcb.change_notice = context_eco
6562 AND bcb.acd_type = 3
6563 AND bcb.effectivity_date <= trgt_comps_eff_date
6564 AND bcb.implementation_date IS NULL
6565 AND bcb.bill_sequence_id = bic.bill_sequence_id
6566 )
6567 */
6568 AND NOT EXISTS (
6569 SELECT 1
6570 FROM mtl_system_items_b msib
6571 WHERE msib.inventory_item_id = bev.component_item_id
6572 AND msib.organization_id = c_org_id)
6573 AND ( NOT EXISTS (
6574 -- Direct Component Action is exclude
6575 SELECT 1
6576 FROM bom_copy_structure_actions bcsa
6577 WHERE bcsa.copy_request_id = p_copy_request_id
6578 AND bcsa.organization_id = p_to_org_id
6579 AND bcsa.component_sequence_id = bev.component_sequence_id
6580 AND bcsa.component_exception_action = 1
6581 )
6582 OR NOT EXISTS (
6583 -- Structure Action is exclude
6584 SELECT 1
6585 FROM bom_copy_structure_actions bcsa, bom_copy_explosions_v bcev
6586 WHERE bcsa.copy_request_id = p_copy_request_id
6587 AND bcsa.organization_id = p_to_org_id
6588 AND bcsa.structure_exception_action = 1
6589 AND bcsa.component_sequence_id = bcev.component_sequence_id
6590 START WITH bcev.bill_sequence_id = bev.bill_sequence_id
6591 CONNECT BY PRIOR bcev.bill_sequence_id = bcev.comp_bill_seq_id
6592 AND bcev.bill_sequence_id <> bev.top_bill_sequence_id
6593 )
6594 )
6595 ;
6596 -- This cursor will select primory uom only when Item does not exist in the destination organization
6597 CURSOR l_uom_in_master_org_csr
6598 ( p_item_id IN NUMBER,
6599 p_master_org_id IN NUMBER,
6600 p_org_id IN NUMBER )
6601 IS
6602 SELECT mmsib.primary_uom_code, 1 l_not_exists, concatenated_segments,
6603 mmsib.secondary_uom_code, mmsib.dual_uom_deviation_high, mmsib.dual_uom_deviation_low,
6604 mmsib.secondary_default_ind, mmsib.tracking_quantity_ind, mmsib.ont_pricing_qty_source
6605 FROM mtl_system_items_b_kfv mmsib
6606 WHERE mmsib.inventory_item_id = p_item_id
6607 AND mmsib.organization_id = p_master_org_id
6608 AND NOT EXISTS
6609 ( SELECT 1
6610 FROM mtl_system_items_b msib
6611 WHERE msib.inventory_item_id = mmsib.inventory_item_id
6612 AND msib.organization_id = p_org_id
6613 );
6614 BEGIN
6615 SAVEPOINT begin_assign_items_to_org;
6616
6617 IF p_cp_request_id IS NOT NULL
6618 THEN
6619 l_program_appl_id := -1;
6620 l_program_id := -1;
6621 l_program_update_date := SYSDATE;
6622 END IF;
6623
6624 -- First assign the top item and continue with other items if it is successful
6625 OPEN l_uom_in_master_org_csr (p_to_item_id, p_master_org_id, p_to_org_id);
6626
6627 LOOP
6628 FETCH l_uom_in_master_org_csr
6629 INTO l_trgt_item_uom_code, l_not_exists, l_trgt_item_name,
6630 l_secondary_uom_code, l_dual_uom_deviation_high, l_dual_uom_deviation_low,
6631 l_secondary_default_ind, l_tracking_quantity_ind, l_ont_pricing_qty_source;
6632
6633 EXIT WHEN l_uom_in_master_org_csr%NOTFOUND;
6634 END LOOP;
6635
6636 IF l_not_exists = 1
6637 THEN
6638
6639 l_item_org_assign_tbl.extend();
6640 l_item_org_assign_tbl(l_item_count) := system.EGO_ITEM_ORG_ASSIGN_REC(1,1,'1','1',1,'1','1',NULL,NULL,NULL,NULL,NULL,NULL);
6641 l_item_org_assign_tbl(l_item_count).master_organization_id := p_master_org_id;
6642 l_item_org_assign_tbl(l_item_count).organization_id := p_to_org_id;
6643 l_item_org_assign_tbl(l_item_count).organization_code := p_to_org_code;
6644 l_item_org_assign_tbl(l_item_count).primary_uom_code := l_trgt_item_uom_code;
6645 l_item_org_assign_tbl(l_item_count).inventory_item_id := p_to_item_id;
6646 l_item_org_assign_tbl(l_item_count).secondary_uom_code := l_secondary_uom_code;
6647 l_item_org_assign_tbl(l_item_count).dual_uom_deviation_high := l_dual_uom_deviation_high;
6648 l_item_org_assign_tbl(l_item_count).dual_uom_deviation_low := l_dual_uom_deviation_low;
6649 l_item_org_assign_tbl(l_item_count).secondary_default_ind := l_secondary_default_ind;
6650 l_item_org_assign_tbl(l_item_count).tracking_quantity_ind := l_tracking_quantity_ind;
6651 l_item_org_assign_tbl(l_item_count).ont_pricing_qty_source := l_ont_pricing_qty_source;
6652 -- l_item_org_assign_tbl(l_item_count).bom_api := 'Y'; -- Not Required. Need to pass p_context for API
6653 l_item_count := l_item_count + 1; -- As of now one item at a time
6654 END IF; -- l_not_exists = 1 l_item_rec_in.inventory_item_id := p_to_item_id;
6655 CLOSE l_uom_in_master_org_csr;
6656 -- As of now items API does not support grouping of error messages
6657 -- Once that API is ready we call assign item api in a single call till that time it will be
6658 -- one for each item.
6659 FOR item_rec IN l_item_org_csr (p_to_org_id,
6660 p_to_org_code,
6661 p_context_eco
6662 )
6663 LOOP
6664 l_item_org_assign_tbl.extend();
6665 l_item_org_assign_tbl(l_item_count) := system.EGO_ITEM_ORG_ASSIGN_REC(1,1,'1','1',1,'1','1',NULL,NULL,NULL,NULL,NULL,NULL);
6666 l_item_org_assign_tbl(l_item_count).master_organization_id := p_master_org_id;
6667 l_item_org_assign_tbl(l_item_count).organization_id := p_to_org_id;
6668 l_item_org_assign_tbl(l_item_count).organization_code := p_to_org_code;
6669 l_item_org_assign_tbl(l_item_count).primary_uom_code := item_rec.primary_uom_code;
6670 l_item_org_assign_tbl(l_item_count).inventory_item_id := item_rec.inventory_item_id;
6671 l_item_org_assign_tbl(l_item_count).secondary_uom_code := item_rec.secondary_uom_code;
6672 l_item_org_assign_tbl(l_item_count).dual_uom_deviation_high := item_rec.dual_uom_deviation_high;
6673 l_item_org_assign_tbl(l_item_count).dual_uom_deviation_low := item_rec.dual_uom_deviation_low;
6674 l_item_org_assign_tbl(l_item_count).secondary_default_ind := item_rec.secondary_default_ind;
6675 l_item_org_assign_tbl(l_item_count).tracking_quantity_ind := item_rec.tracking_quantity_ind;
6676 l_item_org_assign_tbl(l_item_count).ont_pricing_qty_source := item_rec.ont_pricing_qty_source;
6677 l_item_count := l_item_count + 1; -- As of now one item at a time
6678 END LOOP; -- FOR item_rec IN l_item_org_csr
6679 -- Call the Item's Org Assignment API for all the items together
6680 ego_item_org_assign_pvt.process_org_assignments
6681 ( p_item_org_assign_tab => l_item_org_assign_tbl
6682 ,p_commit => FND_API.G_FALSE
6683 ,p_context => 'BOM'
6684 ,x_return_status => l_return_status
6685 ,x_msg_count => l_msg_count
6686 );
6687
6688 IF l_return_status <> FND_API.G_RET_STS_SUCCESS
6689 THEN
6690 IF l_item_org_assign_tbl.FIRST IS NOT NULL
6691 THEN
6692 l_index := l_item_org_assign_tbl.FIRST;
6693 WHILE l_index IS NOT NULL
6694 LOOP
6695 IF l_item_org_assign_tbl(l_index).status <> FND_API.G_RET_STS_SUCCESS
6696 THEN
6697 INSERT INTO mtl_interface_errors
6698 ( unique_id,
6699 organization_id,
6700 transaction_id,
6701 table_name,
6702 column_name,
6703 error_message,
6704 bo_identifier,
6705 last_update_date,
6706 last_updated_by,
6707 creation_date,
6708 created_by,
6709 message_type,
6710 request_id,
6711 program_application_id,
6712 program_id,
6713 program_update_date
6714 )
6715 VALUES (l_item_org_assign_tbl(l_index).inventory_item_id,
6716 p_from_org_id,
6717 p_copy_request_id,
6718 NULL,
6719 get_current_item_rev(l_item_org_assign_tbl(l_index).inventory_item_id,
6720
6721 p_from_org_id,
6722 SYSDATE
6723 ),
6724 l_item_org_assign_tbl(l_index).error_code,
6725 'BOM_COPY',
6726 SYSDATE,
6727 p_usr_id,
6728 SYSDATE,
6729 p_usr_id,
6730 'E',
6731 fnd_global.conc_request_id,
6732 NULL,
6733 fnd_global.conc_program_id,
6734 sysdate
6735 );
6736 END IF; -- l_item_org_assign_rec.status <> FND_API.G_RET_STS_SUCCESS
6737 l_index := l_item_org_assign_tbl.NEXT(l_index);
6738 END LOOP; -- WHILE l_index IS NOT NULL End Loop for items
6739 END IF; -- l_item_org_assign_tbl.FIRST IS NOT NULL
6740 END IF; -- l_return_status <> FND_API.G_RET_STS_SUCCESS When API returns non-success status
6741
6742 -- Sync up the index after item creation
6743 inv_item_pvt.sync_im_index;
6744 EXCEPTION
6745 WHEN OTHERS
6746 THEN
6747 err_msg := 'COPY_BILL ( assign_items_to_org )' || SQLERRM;
6748 fnd_message.set_name ('BOM', 'BOM_SQL_ERR');
6749 fnd_message.set_token ('ENTITY', err_msg);
6750 ROLLBACK TO begin_assign_items_to_org;
6751 app_exception.raise_exception;
6752 END assign_items_to_copy_to_org;
6753
6754 PROCEDURE purge_processed_copy_requests (p_request_status IN VARCHAR2)
6755 IS
6756 BEGIN
6757 DELETE FROM bom_copy_structure_actions
6758 WHERE copy_request_id IN (
6759 SELECT copy_request_id
6760 FROM bom_copy_structure_request
6761 WHERE request_status = p_request_status);
6762
6763 DELETE FROM bom_copy_organization_list
6764 WHERE copy_request_id IN (SELECT copy_request_id
6765 FROM bom_copy_structure_request
6766 WHERE request_status = p_request_status);
6767
6768 DELETE FROM bom_copy_structure_request
6769 WHERE request_status = p_request_status;
6770 END purge_processed_copy_requests;
6771
6772 PROCEDURE purge_processed_request_errors (p_request_status IN VARCHAR2)
6773 IS
6774 BEGIN
6775 DELETE FROM mtl_interface_errors mie
6776 WHERE EXISTS (
6777 SELECT 1
6778 FROM bom_copy_structure_request bscr
6779 WHERE bscr.copy_request_id = mie.transaction_id
6780 AND bscr.request_status = p_request_status
6781 AND mie.bo_identifier = 'BOM_COPY');
6782 END purge_processed_request_errors;
6783
6784 PROCEDURE get_org_list_for_hierarchy (
6785 p_hierarchy_name IN VARCHAR2,
6786 p_org_id IN NUMBER,
6787 p_item_id IN NUMBER,
6788 p_structure_name IN VARCHAR2,
6789 p_effectivity_date IN DATE,
6790 x_org_list_tbl OUT NOCOPY num_varray,
6791 x_org_code_tbl OUT NOCOPY varchar2_varray,
6792 x_org_name_tbl OUT NOCOPY varchar2_varray,
6793 x_org_structure_tbl OUT NOCOPY num_varray,
6794 x_assembly_type_tbl OUT NOCOPY num_varray,
6795 x_item_rev_tbl OUT NOCOPY varchar2_varray,
6796 x_item_rev_id_tbl OUT NOCOPY num_varray,
6797 x_item_rev_lbl_tbl OUT NOCOPY varchar2_varray,
6798 x_item_exists_tbl OUT NOCOPY varchar2_varray,
6799 x_return_status OUT NOCOPY VARCHAR2,
6800 x_error_msg OUT NOCOPY VARCHAR2
6801 )
6802 IS
6803 x_org_id_tbl INV_ORGHIERARCHY_PVT.orgID_tbl_type;
6804 l_count NUMBER := 0;
6805 l_index NUMBER := 0;
6806 l_effectivity_date DATE;
6807 BEGIN
6808 x_return_status := fnd_api.G_RET_STS_SUCCESS;
6809 IF p_effectivity_date < sysdate THEN
6810 l_effectivity_date := sysdate;
6811 ELSE
6812 l_effectivity_date := p_effectivity_date;
6813 END IF;
6814 INV_ORGHIERARCHY_PVT.ORG_HIERARCHY_LIST
6815 ( p_org_hierarchy_name => p_hierarchy_name,
6816 p_org_hier_level_id => p_org_id,
6817 x_org_code_list => x_org_id_tbl
6818 );
6819 IF x_org_id_tbl.FIRST IS NOT NULL THEN
6820 x_org_list_tbl := new num_varray();
6821 x_org_code_tbl := new varchar2_varray();
6822 x_org_name_tbl := new varchar2_varray();
6823 x_org_structure_tbl := new num_varray();
6824 x_assembly_type_tbl := new num_varray();
6825 x_item_rev_tbl := new varchar2_varray();
6826 x_item_rev_id_tbl := new num_varray();
6827 x_item_rev_lbl_tbl := new varchar2_varray();
6828 x_item_exists_tbl := new varchar2_varray();
6829 l_index := x_org_id_tbl.FIRST;
6830 WHILE l_index IS NOT NULL
6831 LOOP
6832 x_org_list_tbl.extend();
6833 x_org_code_tbl.extend();
6834 x_org_name_tbl.extend();
6835 x_org_structure_tbl.extend();
6836 x_assembly_type_tbl.extend();
6837 x_item_rev_tbl.extend();
6838 x_item_rev_id_tbl.extend();
6839 x_item_rev_lbl_tbl.extend();
6840 x_item_exists_tbl.extend();
6841 x_org_list_tbl(l_index) := x_org_id_tbl(l_index);
6842 l_index := x_org_id_tbl.next(l_index);
6843 -- a_debug(' org id ' || i || ' is ' ||x_org_id_tbl(i) || ' list ' || x_org_list_tbl(i));
6844 l_count := l_count + 1;
6845 END LOOP;
6846 IF x_org_list_tbl.FIRST IS NOT NULL THEN
6847 l_index := x_org_list_tbl.FIRST;
6848 WHILE l_index IS NOT NULL
6849 LOOP
6850 BEGIN
6851 SELECT oav.organization_code, oav.organization_name,
6852 CASE
6853 WHEN EXISTS ( SELECT 1
6854 FROM bom_structures_b bsb
6855 WHERE bsb.organization_id = oav.organization_id
6856 AND bsb.assembly_item_id = p_item_id
6857 AND NVL(bsb.alternate_bom_designator,bom_globals.get_primary_ui) = NVL(p_structure_name,bom_globals.get_primary_ui)
6858 AND bsb.bill_sequence_id = bsb.common_bill_sequence_id
6859 ) THEN
6860 1 -- Structure already exists
6861 WHEN EXISTS ( SELECT 1
6862 FROM bom_structures_b bsb
6863 WHERE bsb.organization_id = oav.organization_id
6864 AND bsb.assembly_item_id = p_item_id
6865 AND NVL(bsb.alternate_bom_designator,bom_globals.get_primary_ui) = NVL(p_structure_name,bom_globals.get_primary_ui)
6866 AND bsb.bill_sequence_id <> bsb.common_bill_sequence_id
6867 ) THEN
6868 2 -- Structure already exists and it is common structure
6869 ELSE
6870 0 -- Structure does not exist
6871 END AS structure_exists,
6872 NVL((SELECT assembly_type
6873 FROM bom_structures_b bsb
6874 WHERE bsb.organization_id = x_org_list_tbl(l_index)
6875 AND bsb.assembly_item_id = p_item_id
6876 AND NVL(bsb.alternate_bom_designator,bom_globals.get_primary_ui) = NVL(p_structure_name,bom_globals.get_primary_ui)
6877 ),2) AS assembly_type,
6878 (SELECT revision
6879 FROM (SELECT revision
6880 FROM mtl_item_revisions_b mir
6881 WHERE inventory_item_id = p_item_id
6882 AND organization_id = x_org_list_tbl(l_index)
6883 AND mir.effectivity_date <= p_effectivity_date
6884 ORDER BY effectivity_date DESC, revision DESC)
6885 WHERE rownum < 2) AS current_item_rev,
6886 (SELECT revision_id
6887 FROM (SELECT revision_id
6888 FROM mtl_item_revisions_b mir
6889 WHERE inventory_item_id = p_item_id
6890 AND organization_id = x_org_list_tbl(l_index)
6891 AND mir.effectivity_date <= p_effectivity_date
6892 ORDER BY effectivity_date DESC, revision DESC)
6893 WHERE rownum < 2) AS current_item_rev_id,
6894 (SELECT revision_label
6895 FROM (SELECT revision_label
6896 FROM mtl_item_revisions_b mir
6897 WHERE inventory_item_id = p_item_id
6898 AND organization_id = x_org_list_tbl(l_index)
6899 AND mir.effectivity_date <= p_effectivity_date
6900 ORDER BY effectivity_date DESC, revision DESC)
6901 WHERE rownum < 2) AS current_item_rev_label,
6902 CASE
6903 WHEN EXISTS
6904 (
6905 SELECT 1
6906 FROM mtl_system_items_b msib
6907 WHERE msib.inventory_item_id = p_item_id
6908 AND msib.organization_id = x_org_list_tbl(l_index)
6909 ) THEN
6910 'Y'
6911 ELSE
6912 'N'
6913 END AS item_exists
6914 INTO x_org_code_tbl(l_index), x_org_name_tbl(l_index),
6915 x_org_structure_tbl(l_index), x_assembly_type_tbl(l_index),
6916 x_item_rev_tbl(l_index), x_item_rev_id_tbl(l_index),
6917 x_item_rev_lbl_tbl(l_index), x_item_exists_tbl(l_index)
6918 FROM org_access_view oav
6919 WHERE oav.organization_id = x_org_list_tbl(l_index)
6920 AND oav.responsibility_id = fnd_profile.value('RESP_ID')
6921 AND oav.resp_application_id = fnd_profile.value('RESP_APPL_ID');
6922 l_index := x_org_list_tbl.next(l_index);
6923 x_return_status := fnd_api.G_RET_STS_SUCCESS;
6924 EXCEPTION
6925 WHEN NO_DATA_FOUND THEN
6926 fnd_message.set_name ('BOM', 'BOM_CPY_IP_NO_ORG_IN_HRCHY');
6927 x_return_status := fnd_api.G_RET_STS_ERROR;
6928 x_error_msg := fnd_message.get;
6929 RETURN;
6930 END;
6931 END LOOP;
6932 END IF;
6933 END IF;
6934 END get_org_list_for_hierarchy;
6935
6936
6937 FUNCTION get_item_exists_in (
6938 p_item_id IN NUMBER,
6939 p_copy_request_id IN NUMBER
6940 )
6941 RETURN VARCHAR2
6942 IS
6943 ret_value VARCHAR2 (1000);
6944
6945 CURSOR c1 (cp_item_id IN NUMBER, cp_copy_request_id IN NUMBER)
6946 IS
6947 SELECT mp.organization_code
6948 FROM mtl_system_items_b msib,
6949 mtl_parameters mp,
6950 bom_copy_organization_list bcol
6951 WHERE msib.inventory_item_id = cp_item_id
6952 AND msib.organization_id = mp.organization_id
6953 AND bcol.copy_request_id = cp_copy_request_id
6954 AND bcol.organization_id = mp.organization_id;
6955
6956 l_count NUMBER := 0;
6957 BEGIN
6958 FOR c1_rec IN c1 (p_item_id, p_copy_request_id)
6959 LOOP
6960 IF l_count = 0
6961 THEN
6962 ret_value := c1_rec.organization_code;
6963 ELSE
6964 ret_value := ret_value || ',' || c1_rec.organization_code;
6965 END IF;
6966
6967 l_count := l_count + 1;
6968 END LOOP;
6969
6970 RETURN ret_value;
6971 END get_item_exists_in;
6972
6973 FUNCTION get_structure_exists_in (
6974 p_item_id IN NUMBER,
6975 p_copy_request_id IN NUMBER
6976 )
6977 RETURN VARCHAR2
6978 IS
6979 ret_value VARCHAR2 (1000);
6980
6981 CURSOR c1 (cp_item_id IN NUMBER, cp_copy_request_id IN NUMBER)
6982 IS
6983 SELECT mp.organization_code
6984 FROM mtl_parameters mp,
6985 bom_copy_organization_list bcol,
6986 bom_structures_b bsb,
6987 bom_copy_structure_request bcsr
6988 WHERE bsb.assembly_item_id = cp_item_id
6989 AND bcsr.copy_request_id = cp_copy_request_id
6990 AND bsb.organization_id = bcol.organization_id
6991 AND NVL (bsb.alternate_bom_designator, bom_globals.get_primary_ui) =
6992 NVL (bcsr.trgt_structure_name, bom_globals.get_primary_ui)
6993 AND bcol.copy_request_id = bcsr.copy_request_id
6994 AND bcol.organization_id = mp.organization_id;
6995
6996 l_count NUMBER := 0;
6997 BEGIN
6998 FOR c1_rec IN c1 (p_item_id, p_copy_request_id)
6999 LOOP
7000 IF l_count = 0
7001 THEN
7002 ret_value := c1_rec.organization_code;
7003 ELSE
7004 ret_value := ret_value || ',' || c1_rec.organization_code;
7005 END IF;
7006
7007 l_count := l_count + 1;
7008 END LOOP;
7009
7010 RETURN ret_value;
7011 END get_structure_exists_in;
7012
7013 /*
7014 * This function is not required. We can display one column for the structure exists info.
7015 * If we need to provide the common information we may need to provide the other details.
7016 */
7017 FUNCTION get_common_structure_exists_in (
7018 p_item_id IN NUMBER,
7019 p_copy_request_id IN NUMBER
7020 )
7021 RETURN VARCHAR2
7022 IS
7023 ret_value VARCHAR2 (1000);
7024
7025 CURSOR c1 (cp_item_id IN NUMBER, cp_copy_request_id IN NUMBER)
7026 IS
7027 SELECT mp.organization_code
7028 FROM mtl_parameters mp,
7029 bom_copy_organization_list bcol,
7030 bom_structures_b bsb,
7031 bom_copy_structure_request bcsr
7032 WHERE bsb.bill_sequence_id <> bsb.source_bill_sequence_id
7033 AND bsb.assembly_item_id = cp_item_id
7034 AND bcsr.copy_request_id = cp_copy_request_id
7035 AND bsb.organization_id = bcol.organization_id
7036 AND NVL (bsb.alternate_bom_designator, bom_globals.get_primary_ui) =
7037 NVL (bcsr.trgt_structure_name, bom_globals.get_primary_ui)
7038 AND bcol.copy_request_id = bcsr.copy_request_id
7039 AND bcol.organization_id = mp.organization_id;
7040
7041 l_count NUMBER := 0;
7042 BEGIN
7043 FOR c1_rec IN c1 (p_item_id, p_copy_request_id)
7044 LOOP
7045 IF l_count = 0
7046 THEN
7047 ret_value := c1_rec.organization_code;
7048 ELSE
7049 ret_value := ret_value || ',' || c1_rec.organization_code;
7050 END IF;
7051
7052 l_count := l_count + 1;
7053 END LOOP;
7054
7055 RETURN ret_value;
7056 END get_common_structure_exists_in;
7057
7058 FUNCTION get_assign_items_in (
7059 p_item_id IN NUMBER,
7060 p_copy_request_id IN NUMBER
7061 )
7062 RETURN VARCHAR2
7063 IS
7064 ret_value VARCHAR2 (1000);
7065
7066 CURSOR c1 (cp_item_id IN NUMBER, cp_copy_request_id IN NUMBER)
7067 IS
7068 SELECT mp.organization_code
7069 FROM mtl_parameters mp,
7070 bom_copy_organization_list bcol
7071 WHERE bcol.copy_request_id = cp_copy_request_id
7072 AND bcol.organization_id = mp.organization_id
7073 AND NOT EXISTS (
7074 SELECT 1
7075 FROM mtl_system_items_b msib
7076 WHERE msib.inventory_item_id = cp_item_id
7077 AND msib.organization_id = bcol.organization_id);
7078
7079 l_count NUMBER := 0;
7080 BEGIN
7081
7082 FOR c1_rec IN c1 (p_item_id, p_copy_request_id)
7083 LOOP
7084 IF l_count = 0
7085 THEN
7086 ret_value := c1_rec.organization_code;
7087 ELSE
7088 ret_value := ret_value || ',' || c1_rec.organization_code;
7089 END IF;
7090
7091 l_count := l_count + 1;
7092 END LOOP;
7093
7094 RETURN ret_value;
7095 END get_assign_items_in;
7096
7097 FUNCTION get_copy_structures_in (
7098 p_item_id IN NUMBER,
7099 p_copy_request_id IN NUMBER
7100 )
7101 RETURN VARCHAR2
7102 IS
7103 ret_value VARCHAR2 (1000);
7104
7105 CURSOR c1 (cp_item_id IN NUMBER, cp_copy_request_id IN NUMBER)
7106 IS
7107 SELECT mp.organization_code
7108 FROM mtl_parameters mp,
7109 bom_copy_organization_list bcol
7110 WHERE bcol.copy_request_id = cp_copy_request_id
7111 AND bcol.organization_id = mp.organization_id
7112 AND bcol.common_structure = 'N'
7113 AND NOT EXISTS (
7114 SELECT 1
7115 FROM bom_copy_structure_request bcsr,
7116 bom_structures_b bsb
7117 WHERE bsb.assembly_item_id = cp_item_id
7118 AND bcsr.copy_request_id = bcol.copy_request_id
7119 AND bsb.organization_id = bcol.organization_id
7120 AND NVL (bsb.alternate_bom_designator, bom_globals.get_primary_ui) =
7121 NVL (bcsr.trgt_structure_name, bom_globals.get_primary_ui));
7122
7123 l_count NUMBER := 0;
7124 BEGIN
7125 FOR c1_rec IN c1 (p_item_id, p_copy_request_id)
7126 LOOP
7127 IF l_count = 0
7128 THEN
7129 ret_value := c1_rec.organization_code;
7130 ELSE
7131 ret_value := ret_value || ',' || c1_rec.organization_code;
7132 END IF;
7133
7134 l_count := l_count + 1;
7135 END LOOP;
7136
7137 RETURN ret_value;
7138 END get_copy_structures_in;
7139
7140 FUNCTION get_common_structures_in (
7141 p_item_id IN NUMBER,
7142 p_copy_request_id IN NUMBER
7143 )
7144 RETURN VARCHAR2
7145 IS
7146 ret_value VARCHAR2 (1000);
7147
7148 CURSOR c1 (cp_item_id IN NUMBER, cp_copy_request_id IN NUMBER)
7149 IS
7150 SELECT mp.organization_code
7151 FROM mtl_parameters mp,
7152 bom_copy_organization_list bcol
7153 WHERE bcol.copy_request_id = cp_copy_request_id
7154 AND bcol.organization_id = mp.organization_id
7155 AND bcol.common_structure = 'Y'
7156 AND NOT EXISTS (
7157 SELECT 1
7158 FROM bom_copy_structure_request bcsr,
7159 bom_structures_b bsb
7160 WHERE bcsr.copy_request_id = bcol.copy_request_id
7161 AND bsb.organization_id = bcol.organization_id
7162 AND bsb.assembly_item_id = cp_item_id
7163 AND NVL (bsb.alternate_bom_designator, bom_globals.get_primary_ui) =
7164 NVL (bcsr.trgt_structure_name, bom_globals.get_primary_ui));
7165
7166 l_count NUMBER := 0;
7167 BEGIN
7168 FOR c1_rec IN c1 (p_item_id, p_copy_request_id)
7169 LOOP
7170 IF l_count = 0
7171 THEN
7172 ret_value := c1_rec.organization_code;
7173 ELSE
7174 ret_value := ret_value || ',' || c1_rec.organization_code;
7175 END IF;
7176
7177 l_count := l_count + 1;
7178 END LOOP;
7179
7180 RETURN ret_value;
7181 END get_common_structures_in;
7182
7183 PROCEDURE update_created_by (
7184 p_user_id IN NUMBER
7185 ,p_to_bill_sequence_id IN NUMBER )
7186 IS
7187 BEGIN
7188 bom_globals.g_skip_bomtbicx := 'Y';
7189
7190 UPDATE bom_components_b bic
7191 SET created_by = p_user_id
7192 WHERE bic.bill_sequence_id = p_to_bill_sequence_id;
7193
7194 --Turn on trigger BOMTBICX
7195 bom_globals.g_skip_bomtbicx := 'N';
7196
7197 END;
7198
7199 /* This procedure can be used in following scenario
7200 * When the copy operation creates the new eco or revised items are added to existing eco
7201 * with current and future option. In that flow we need to create separate revised items
7202 * for different effectivity dates
7203 */
7204 PROCEDURE copy_bill_for_revised_item
7205 (
7206 to_sequence_id IN NUMBER,
7207 from_sequence_id IN NUMBER,
7208 from_org_id IN NUMBER,
7209 to_org_id IN NUMBER,
7210 user_id IN NUMBER DEFAULT -1,
7211 to_item_id IN NUMBER,
7212 direction IN NUMBER DEFAULT 1,
7213 to_alternate IN VARCHAR2,
7214 rev_date IN DATE,
7215 e_change_notice IN VARCHAR2,
7216 rev_item_seq_id IN NUMBER,
7217 eco_eff_date IN DATE,
7218 eco_unit_number IN VARCHAR2 DEFAULT NULL,
7219 unit_number IN VARCHAR2 DEFAULT NULL,
7220 from_item_id IN NUMBER,
7221 -- Request Id for this copy operation. Value from BOM_COPY_STRUCTURE_REQUEST_S
7222 -- To populate the errors in MTL_INTERFACE_ERRORS with this transaction id
7223 p_copy_request_id IN NUMBER,
7224 -- Unit number for copy to item
7225 eco_end_item_rev_id IN NUMBER DEFAULT NULL,
7226 -- Structure has been exploded in context of this ECO for copying
7227 context_eco IN VARCHAR2 DEFAULT NULL,
7228 p_end_item_rev_id IN NUMBER DEFAULT NULL,
7229 -- Since the JOIN occurs with bom_copy_explosions_v, there could be multiple
7230 -- sub-assemblies (items) in the exploded structure at different levels
7231 -- but if we copy once that will be suffice
7232 p_parent_sort_order IN VARCHAR2 DEFAULT NULL,
7233 p_trgt_str_eff_ctrl IN NUMBER DEFAULT 1,
7234 -- Flag which specifies whether past effective component needs to be copied
7235 -- This will be 'Y' only for first revised item created
7236 p_cpy_past_eff_comps IN VARCHAR2 DEFAULT 'Y',
7237 p_trgt_str_type_id IN NUMBER DEFAULT NULL
7238 )
7239 IS
7240 bom_to_bom CONSTANT NUMBER := 1;
7241 bom_to_eng CONSTANT NUMBER := 2;
7242 eng_to_eng CONSTANT NUMBER := 3;
7243 eng_to_bom CONSTANT NUMBER := 4;
7244 model CONSTANT NUMBER := 1;
7245 option_class CONSTANT NUMBER := 2;
7246 planning CONSTANT NUMBER := 3;
7247 STANDARD CONSTANT NUMBER := 4;
7248 phantom CONSTANT NUMBER := 6;
7249 x_from_sequence_id NUMBER := from_sequence_id;
7250 x_from_org_id NUMBER := from_org_id;
7251 to_rtg_seq_id NUMBER;
7252 itm_cat_grp_id NUMBER;
7253 dummy NUMBER;
7254 sql_stmt_num NUMBER;
7255 base_item_flag NUMBER;
7256 itm_type NUMBER;
7257 copy_comps NUMBER;
7258 copy_comts NUMBER;
7259 copy_subs NUMBER;
7260 copy_desgs NUMBER;
7261 copy_compops NUMBER;
7262 copy_atts NUMBER;
7263 err_msg VARCHAR (2000);
7264 atp_comp_flag VARCHAR2 (1);
7265 rto_flag VARCHAR2 (1);
7266 old_max NUMBER := 0;
7267 new_seq_num NUMBER := 0;
7268 processed NUMBER := 0;
7269 tmp_var NUMBER := 0;
7270 l_to_item_rev_id NUMBER := -1;
7271 l_to_item_minor_rev_id NUMBER := 0;
7272 error_status VARCHAR2 (1) := 'F';
7273 msg_count NUMBER := 0;
7274 item_rev VARCHAR2 (3) := NULL;
7275 l_item_rev_date DATE := SYSDATE;
7276 l_from_item_rev_id NUMBER;
7277 l_from_item_rev VARCHAR2 (3) := NULL;
7278 l_return_status VARCHAR2 (1) := 'S';
7279 l_item_number VARCHAR2 (80) := NULL;
7280 l_org_code VARCHAR2 (3) := NULL;
7281 l_uom_code VARCHAR2 (3) := NULL;
7282 p_commit VARCHAR2 (8) := 'FALSE';
7283 l_msg_count NUMBER := 0;
7284 l_item_rec_in inv_item_grp.item_rec_type;
7285 l_item_rec_out inv_item_grp.item_rec_type;
7286 l_error_tbl inv_item_grp.error_tbl_type;
7287 l_dest_pk_col_name_val_pairs ego_col_name_value_pair_array;
7288 l_src_pk_col_name_val_pairs ego_col_name_value_pair_array;
7289 l_new_str_type ego_col_name_value_pair_array;
7290 l_str_type NUMBER;
7291 l_errorcode NUMBER;
7292 l_msg_data VARCHAR2 (100);
7293 x_acd_type NUMBER;
7294 x_rev_item_seq_id NUMBER;
7295 x_e_change_notice VARCHAR2 (10);
7296 x_effectivity_date DATE;
7297 x_unit_number VARCHAR2 (30);
7298 x_end_item_rev_id NUMBER;
7299 x_unit_assembly VARCHAR2 (2) := 'N';
7300 overlap_error EXCEPTION;
7301 common_error EXCEPTION;
7302 no_item_rev_exists EXCEPTION;
7303 no_minor_rev_exists EXCEPTION;
7304 no_minor_rev_code_exists EXCEPTION;
7305 l_count1 NUMBER;
7306 l_count2 NUMBER;
7307 l_count3 NUMBER;
7308 l_comp_ctr NUMBER;
7309 l_from_eff_ctrl bom_structures_b.effectivity_control%TYPE;
7310 l_to_eff_ctrl bom_structures_b.effectivity_control%TYPE;
7311 l_no_access_comp_cnt NUMBER;
7312 l_fixed_rev mtl_item_revisions_b.revision%TYPE;
7313 l_current_item_rev mtl_item_revisions_b.revision%TYPE;
7314 l_current_item_rev_id mtl_item_revisions_b.revision_id%TYPE;
7315 l_from_comps num_varray := num_varray();
7316 l_to_comps num_varray := num_varray();
7317 l_last_copied_comp_seq_id NUMBER := -1;
7318 l_default_wip_params NUMBER;
7319 l_data_level_name_comp VARCHAR2(30) := 'COMPONENTS_LEVEL';
7320 l_data_level_id_comp NUMBER;
7321 l_old_dtlevel_col_value_pairs EGO_COL_NAME_VALUE_PAIR_ARRAY;
7322 l_new_dtlevel_col_value_pairs EGO_COL_NAME_VALUE_PAIR_ARRAY;
7323
7324
7325 CURSOR l_common_csr
7326 IS
7327 SELECT 1
7328 FROM DUAL
7329 WHERE EXISTS (
7330 SELECT NULL
7331 FROM bom_structures_b bom,
7332 bom_inventory_components bic
7333 WHERE bom.organization_id <> to_org_id
7334 AND bom.common_bill_sequence_id = to_sequence_id
7335 AND bic.bill_sequence_id = to_sequence_id
7336 AND NOT EXISTS (
7337 SELECT NULL
7338 FROM mtl_system_items cmsi,
7339 mtl_system_items bmsi
7340 WHERE cmsi.organization_id = bom.organization_id
7341 AND cmsi.inventory_item_id =
7342 bic.component_item_id
7343 AND bmsi.organization_id = bom.organization_id
7344 AND bmsi.inventory_item_id =
7345 bom.assembly_item_id
7346 AND cmsi.eng_item_flag =
7347 DECODE (bom.assembly_type,
7348 1, 'N',
7349 2, cmsi.eng_item_flag
7350 )
7351 AND cmsi.bom_enabled_flag = 'Y'
7352 AND cmsi.inventory_item_id <>
7353 bom.assembly_item_id
7354 AND ((bmsi.bom_item_type = 1
7355 AND cmsi.bom_item_type <> 3
7356 )
7357 OR (bmsi.bom_item_type = 2
7358 AND cmsi.bom_item_type <> 3
7359 )
7360 OR (bmsi.bom_item_type = 3)
7361 OR (bmsi.bom_item_type = 4
7362 AND (cmsi.bom_item_type = 4
7363 OR (cmsi.bom_item_type IN (1, 2)
7364 AND cmsi.replenish_to_order_flag =
7365 'Y'
7366 AND bmsi.base_item_id IS NOT NULL
7367 AND bmsi.replenish_to_order_flag =
7368 'Y'
7369 )
7370 )
7371 )
7372 )
7373 AND (bmsi.bom_item_type = 3
7374 OR bmsi.pick_components_flag = 'Y'
7375 OR cmsi.pick_components_flag = 'N'
7376 )
7377 AND (bmsi.bom_item_type = 3
7378 OR NVL (cmsi.bom_item_type, 4) <> 2
7379 OR (cmsi.bom_item_type = 2
7380 AND ((bmsi.pick_components_flag = 'Y'
7381 AND cmsi.pick_components_flag =
7382 'Y'
7383 )
7384 OR (bmsi.replenish_to_order_flag =
7385 'Y'
7386 AND cmsi.replenish_to_order_flag =
7387 'Y'
7388 )
7389 )
7390 )
7391 )
7392 AND NOT (bmsi.bom_item_type = 4
7393 AND bmsi.pick_components_flag = 'Y'
7394 AND cmsi.bom_item_type = 4
7395 AND cmsi.replenish_to_order_flag = 'Y'
7396 )));
7397
7398 CURSOR item_rev_cursor (
7399 p_item_id IN NUMBER,
7400 p_org_id IN NUMBER,
7401 p_rev_date IN DATE
7402 )
7403 IS
7404 SELECT revision_id,
7405 revision
7406 FROM mtl_item_revisions_b mir
7407 WHERE mir.inventory_item_id = p_item_id
7408 AND mir.organization_id = p_org_id
7409 AND mir.effectivity_date <= p_rev_date
7410 AND ROWNUM < 2
7411 ORDER BY mir.effectivity_date DESC;
7412
7413 CURSOR item_minor_rev_cursor (
7414 p_pk1_value IN VARCHAR2,
7415 p_pk2_value IN VARCHAR2,
7416 p_pk3_value IN VARCHAR2
7417 )
7418 IS
7419 SELECT NVL (MAX (minor_revision_id), 0) minor_revision_id
7420 FROM ego_minor_revisions
7421 WHERE obj_name = 'EGO_ITEM'
7422 AND pk1_value = p_pk1_value
7423 AND NVL (pk2_value, '-1') = NVL (p_pk2_value, '-1')
7424 AND NVL (pk3_value, '-1') = NVL (p_pk3_value, '-1');
7425
7426 CURSOR l_org_item_csr (p_item_id IN NUMBER, p_org_id IN NUMBER)
7427 IS
7428 SELECT concatenated_segments,
7429 primary_uom_code
7430 FROM mtl_system_items_b_kfv
7431 WHERE inventory_item_id = p_item_id
7432 AND organization_id = p_org_id;
7433
7434 CURSOR l_from_to_comps_csr (
7435 p_from_seq_id IN NUMBER,
7436 p_to_seq_id IN NUMBER,
7437 p_last_copied_comp_seq_id IN NUMBER
7438 )
7439 IS
7440 SELECT bcb1.component_sequence_id from_component_seq_id,
7441 bcb2.component_sequence_id to_sequence_id
7442 FROM bom_components_b bcb1,
7443 bom_components_b bcb2
7444 WHERE bcb1.bill_sequence_id = p_from_seq_id
7445 AND bcb1.component_sequence_id = bcb2.created_by
7446 AND bcb2.bill_sequence_id = p_to_seq_id
7447 AND bcb2.component_sequence_id > p_last_copied_comp_seq_id;
7448 l_index NUMBER := 0;
7449
7450 CURSOR l_mark_components_csr (
7451 p_change_notice IN VARCHAR2,
7452 p_local_org_id IN NUMBER,
7453 p_bill_seq_id IN NUMBER
7454 )
7455 IS
7456 SELECT eec.change_id,
7457 bcb.component_sequence_id
7458 FROM eng_engineering_changes eec,
7459 bom_components_b bcb
7460 WHERE eec.change_notice = p_change_notice
7461 AND eec.organization_id = p_local_org_id
7462 AND bcb.bill_sequence_id = p_bill_seq_id;
7463 CURSOR l_fixed_rev_comp_csr (
7464 p_parent_sort_order IN VARCHAR2
7465 )
7466 IS
7467 SELECT bev.comp_fixed_rev_code
7468 FROM bom_copy_explosions_v bev
7469 WHERE bev.sort_order = p_parent_sort_order;
7470 CURSOR l_eff_date_for_rev_csr (
7471 p_inventory_item_id IN NUMBER,
7472 p_organization_id IN NUMBER,
7473 p_revision IN VARCHAR2
7474 )
7475 IS
7476 SELECT effectivity_date
7477 FROM mtl_item_revisions_b
7478 WHERE inventory_item_id = p_inventory_item_id
7479 AND organization_id = p_organization_id
7480 AND revision = p_revision;
7481
7482 CURSOR l_last_copied_comp_seq_id_csr (
7483 p_bill_seq_id IN NUMBER
7484 )
7485 IS
7486 SELECT max(bcb.component_sequence_id)
7487 FROM bom_components_b bcb
7488 WHERE bcb.bill_sequence_id = p_bill_seq_id;
7489
7490 CURSOR C_DATA_LEVEL(p_data_level_name VARCHAR2) IS
7491 SELECT DATA_LEVEL_ID
7492 FROM EGO_DATA_LEVEL_B
7493 WHERE DATA_LEVEL_NAME = p_data_level_name;
7494
7495 --added for bug 10078346 (begin)
7496 l_app_id number;
7497 l_context varchar2(200);
7498 l_context_column varchar2(30);
7499 l_prof_check varchar2(15);
7500 l_prof_name varchar2(200);
7501 l_prof_val varchar2(30) :=null;
7502 --added for bug 10078346 (end)
7503
7504 BEGIN
7505 SAVEPOINT begin_revised_item_bill_copy;
7506
7507 FND_PROFILE.GET('BOM:DEFAULT_WIP_VALUES', l_default_wip_params);
7508
7509 -- reset from_sequence_id to common_bill_sequence_id
7510 sql_stmt_num := 10;
7511
7512 SELECT common_bill_sequence_id,
7513 NVL (common_organization_id, organization_id)
7514 INTO x_from_sequence_id,
7515 x_from_org_id
7516 FROM bom_structures_b
7517 WHERE bill_sequence_id = x_from_sequence_id;
7518
7519 SELECT structure_type_id, effectivity_control
7520 INTO l_str_type, l_from_eff_ctrl
7521 FROM bom_structures_b
7522 WHERE bill_sequence_id = from_sequence_id;
7523
7524 l_to_eff_ctrl := p_trgt_str_eff_ctrl;
7525
7526 /* Serial Effectivity Implementation */
7527 IF (bom_eamutil.enabled = 'Y'
7528 AND bom_eamutil.serial_effective_item (item_id => from_item_id,
7529 org_id => x_from_org_id
7530 ) = 'Y'
7531 )
7532 OR (pjm_unit_eff.enabled = 'Y'
7533 AND pjm_unit_eff.unit_effective_item
7534 (x_item_id => from_item_id,
7535 x_organization_id => x_from_org_id
7536 ) = 'Y'
7537 )
7538 THEN
7539 x_unit_assembly := 'Y';
7540 ELSE
7541 x_unit_assembly := 'N';
7542 END IF;
7543
7544 --Load host variables, bill_atp_comps_flag and bill_rto_flag
7545 sql_stmt_num := 15;
7546
7547 SELECT atp_components_flag,
7548 replenish_to_order_flag,
7549 DECODE (base_item_id, NULL, -1, 0),
7550 bom_item_type,
7551 item_catalog_group_id
7552 INTO atp_comp_flag,
7553 rto_flag,
7554 base_item_flag,
7555 itm_type,
7556 itm_cat_grp_id
7557 FROM mtl_system_items
7558 WHERE organization_id = to_org_id
7559 AND inventory_item_id = to_item_id;
7560
7561 sql_stmt_num := 18;
7562
7563 x_acd_type := 1;
7564 x_e_change_notice := e_change_notice;
7565 x_rev_item_seq_id := rev_item_seq_id;
7566 x_effectivity_date := eco_eff_date;
7567 x_unit_number := eco_unit_number;
7568 x_end_item_rev_id := eco_end_item_rev_id;
7569
7570 OPEN l_fixed_rev_comp_csr(p_parent_sort_order);
7571 l_fixed_rev := NULL;
7572 LOOP
7573 FETCH l_fixed_rev_comp_csr
7574 INTO l_fixed_rev;
7575 EXIT WHEN l_fixed_rev_comp_csr%NOTFOUND;
7576 END LOOP;
7577 IF l_fixed_rev_comp_csr%ISOPEN THEN
7578 CLOSE l_fixed_rev_comp_csr;
7579 END IF;
7580
7581
7582 OPEN l_last_copied_comp_seq_id_csr (to_sequence_id);
7583
7584 LOOP
7585 FETCH l_last_copied_comp_seq_id_csr
7586 INTO l_last_copied_comp_seq_id;
7587
7588 EXIT WHEN l_last_copied_comp_seq_id_csr%NOTFOUND;
7589 END LOOP;
7590
7591 IF l_last_copied_comp_seq_id_csr%ISOPEN THEN
7592 CLOSE l_last_copied_comp_seq_id_csr;
7593 END IF;
7594
7595 IF l_last_copied_comp_seq_id IS NULL THEN
7596 l_last_copied_comp_seq_id := -1;
7597 END IF;
7598
7599 FOR c_comp_level IN C_DATA_LEVEL(l_data_level_name_comp) LOOP
7600 l_data_level_id_comp := c_comp_level.DATA_LEVEL_ID;
7601 END LOOP;
7602
7603
7604 OPEN item_rev_cursor (to_item_id, to_org_id, x_effectivity_date);
7605
7606 LOOP
7607 FETCH item_rev_cursor
7608 INTO l_current_item_rev_id,
7609 l_current_item_rev;
7610
7611 EXIT WHEN item_rev_cursor%NOTFOUND;
7612 END LOOP;
7613
7614 IF item_rev_cursor%ISOPEN THEN
7615 CLOSE item_rev_cursor;
7616 END IF;
7617
7618 /*
7619 IF l_fixed_rev IS NOT NULL AND trgt_comps_eff_date IS NOT NULL
7620 THEN
7621 OPEN l_eff_date_for_rev_csr( to_item_id, to_org_id, l_fixed_rev);
7622 LOOP
7623 FETCH l_eff_date_for_rev_csr
7624 INTO l_item_rev_date;
7625 EXIT WHEN l_eff_date_for_rev_csr%NOTFOUND;
7626 END LOOP;
7627 END IF;
7628 */
7629 OPEN item_rev_cursor (to_item_id, to_org_id, l_item_rev_date);
7630
7631 LOOP
7632 FETCH item_rev_cursor
7633 INTO l_to_item_rev_id,
7634 item_rev;
7635
7636 EXIT WHEN item_rev_cursor%NOTFOUND;
7637 END LOOP;
7638
7639 IF item_rev IS NULL
7640 OR '' = item_rev
7641 THEN
7642 CLOSE item_rev_cursor;
7643
7644 RAISE no_item_rev_exists;
7645 END IF;
7646
7647 IF item_rev_cursor%ISOPEN THEN
7648 CLOSE item_rev_cursor;
7649 END IF;
7650
7651 OPEN item_rev_cursor (from_item_id, from_org_id, rev_date);
7652
7653 LOOP
7654 FETCH item_rev_cursor
7655 INTO l_from_item_rev_id,
7656 l_from_item_rev;
7657
7658 EXIT WHEN item_rev_cursor%NOTFOUND;
7659 END LOOP;
7660
7661 IF l_from_item_rev IS NULL
7662 OR '' = l_from_item_rev
7663 THEN
7664 CLOSE item_rev_cursor;
7665
7666 RAISE no_item_rev_exists;
7667 END IF;
7668
7669 IF item_rev_cursor%ISOPEN THEN
7670 CLOSE item_rev_cursor;
7671 END IF;
7672
7673 OPEN item_minor_rev_cursor (TO_CHAR (to_item_id),
7674 TO_CHAR (to_org_id),
7675 TO_CHAR (l_to_item_rev_id)
7676 );
7677
7678 LOOP
7679 FETCH item_minor_rev_cursor
7680 INTO l_to_item_minor_rev_id;
7681
7682 EXIT WHEN item_minor_rev_cursor%NOTFOUND;
7683 END LOOP;
7684
7685 IF l_to_item_minor_rev_id IS NULL
7686 OR '' = l_to_item_minor_rev_id
7687 THEN
7688 CLOSE item_minor_rev_cursor;
7689
7690 RAISE no_minor_rev_exists;
7691 END IF;
7692
7693 IF item_minor_rev_cursor%ISOPEN THEN
7694 CLOSE item_minor_rev_cursor;
7695 END IF;
7696
7697 --changes bug 10078346 begin
7698 --get application_id first
7699 SELECT application_id INTO l_app_id
7700 FROM fnd_application WHERE application_short_name = 'BOM';
7701
7702 --get context field name
7703 select default_context_field_name, context_column_name into l_context, l_context_column
7704 from FND_DESCRIPTIVE_FLEXS where application_id = l_app_id and
7705 descriptive_flexfield_name = 'BOM_INVENTORY_COMPONENTS';
7706
7707 --process further only when reference field is set
7708 if ((l_context_column = 'ATTRIBUTE_CATEGORY') and (l_context is not null)) then
7709 --update attribute category only when reference field has a value of $PROFILE.profile_name
7710 l_prof_check := substr(l_context, 1, 12);
7711
7712 if (l_prof_check = ':$PROFILES$.') then
7713 l_prof_name := ltrim(l_context, ':$PROFILES$.');
7714 l_prof_val := fnd_profile.value(l_prof_name);
7715
7716 end if;
7717 end if;
7718 --changes bug 10078346 end
7719
7720
7721 -- Copies the components if the API is called for selective component copy.
7722 sql_stmt_num := 20;
7723
7724 /* Bug : 4185500 Structure Level Attribute copy */
7725 l_src_pk_col_name_val_pairs :=
7726 ego_col_name_value_pair_array
7727 (ego_col_name_value_pair_obj ('BILL_SEQUENCE_ID',
7728 TO_CHAR (from_sequence_id)
7729 )
7730 );
7731 l_dest_pk_col_name_val_pairs :=
7732 ego_col_name_value_pair_array
7733 (ego_col_name_value_pair_obj ('BILL_SEQUENCE_ID',
7734 TO_CHAR (to_sequence_id)
7735 )
7736 );
7737 l_new_str_type :=
7738 ego_col_name_value_pair_array
7739 (ego_col_name_value_pair_obj ('STRUCTURE_TYPE_ID',
7740 TO_CHAR (l_str_type)
7741 )
7742 );
7743 ego_user_attrs_data_pub.copy_user_attrs_data
7744 (p_api_version => 1.0,
7745 p_application_id => bom_application_id,
7746 p_object_name => 'BOM_STRUCTURE',
7747 p_old_pk_col_value_pairs => l_src_pk_col_name_val_pairs,
7748 p_new_pk_col_value_pairs => l_dest_pk_col_name_val_pairs,
7749 p_new_cc_col_value_pairs => l_new_str_type,
7750 x_return_status => l_return_status,
7751 x_errorcode => l_errorcode,
7752 x_msg_count => l_msg_count,
7753 x_msg_data => l_msg_data
7754 );
7755 --turn off the trigger BOMTBICX
7756 bom_globals.g_skip_bomtbicx := 'Y';
7757
7758 IF l_from_eff_ctrl = 1 AND l_to_eff_ctrl = 1 THEN -- Date - Date
7759
7760
7761 INSERT INTO bom_components_b
7762 (shipping_allowed,
7763 required_to_ship,
7764 required_for_revenue,
7765 include_on_ship_docs,
7766 include_on_bill_docs,
7767 low_quantity,
7768 high_quantity,
7769 acd_type,
7770 component_sequence_id,
7771 old_component_sequence_id,
7772 bill_sequence_id,
7773 request_id,
7774 program_application_id,
7775 program_id,
7776 program_update_date,
7777 wip_supply_type,
7778 pick_components,
7779 supply_subinventory,
7780 supply_locator_id,
7781 operation_lead_time_percent,
7782 revised_item_sequence_id,
7783 cost_factor,
7784 operation_seq_num,
7785 component_item_id,
7786 last_update_date,
7787 last_updated_by,
7788 creation_date,
7789 created_by,
7790 last_update_login,
7791 item_num,
7792 component_quantity,
7793 component_yield_factor,
7794 component_remarks,
7795 effectivity_date,
7796 change_notice,
7797 implementation_date,
7798 disable_date,
7799 attribute_category,
7800 attribute1,
7801 attribute2,
7802 attribute3,
7803 attribute4,
7804 attribute5,
7805 attribute6,
7806 attribute7,
7807 attribute8,
7808 attribute9,
7809 attribute10,
7810 attribute11,
7811 attribute12,
7812 attribute13,
7813 attribute14,
7814 attribute15,
7815 planning_factor,
7816 quantity_related,
7817 so_basis,
7818 optional,
7819 mutually_exclusive_options,
7820 include_in_cost_rollup,
7821 check_atp,
7822 bom_item_type,
7823 from_end_item_unit_number,
7824 to_end_item_unit_number,
7825 optional_on_model,
7826 --BUGFIX 2740820
7827 parent_bill_seq_id, --BUGFIX 2740820
7828 model_comp_seq_id, --BUGFIX 2740820
7829 plan_level,
7830 --BUGFIX 2740820
7831 enforce_int_requirements, --BUGFIX 2991472
7832 from_object_revision_id,
7833 from_minor_revision_id,
7834 pk1_value,
7835 pk2_value,
7836 auto_request_material,
7837 -- Bug 3662214 : Added following 4 fields
7838 suggested_vendor_name,
7839 vendor_id,
7840 unit_price,
7841 from_end_item_rev_id,
7842 to_end_item_rev_id,
7843 from_end_item_minor_rev_id,
7844 to_end_item_minor_rev_id,
7845 component_item_revision_id,
7846 component_minor_revision_id,
7847 basis_type,
7848 to_object_revision_id,
7849 to_minor_revision_id
7850 )
7851 SELECT bic.shipping_allowed,
7852 bic.required_to_ship,
7853 bic.required_for_revenue,
7854 bic.include_on_ship_docs,
7855 bic.include_on_bill_docs,
7856 -- bic.low_quantity,
7857 -- bic.high_quantity,
7858 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
7859 AA.primary_unit_of_measure,BIC.low_quantity,
7860 DECODE(BIC.low_quantity,null,null, --Added this inner Deocde for Bug 6847530
7861 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
7862 NULL,
7863 BIC.low_quantity,
7864 NULL,
7865 NULL,
7866 AA.primary_unit_of_measure,
7867 MSI.primary_unit_of_measure))) Comp_low_qty,
7868 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
7869 AA.primary_unit_of_measure,BIC.high_quantity,
7870 DECODE(BIC.high_quantity,null,null, --Added this inner Deocde for Bug 6847530
7871 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
7872 NULL,
7873 BIC.high_quantity,
7874 NULL,
7875 NULL,
7876 AA.primary_unit_of_measure,
7877 MSI.primary_unit_of_measure))) Comp_high_qty,
7878 x_acd_type,
7879 bom_inventory_components_s.NEXTVAL,
7880 DECODE (x_acd_type,
7881 NULL, NULL,
7882 bom_inventory_components_s.CURRVAL
7883 ),
7884 to_sequence_id,
7885 fnd_global.conc_request_id,
7886 NULL,
7887 fnd_global.conc_program_id,
7888 sysdate,
7889 bic.wip_supply_type,
7890 DECODE (rto_flag, 'Y', 2, bic.pick_components),
7891 DECODE (x_from_org_id,
7892 to_org_id, bic.supply_subinventory,
7893 DECODE( l_default_wip_params, 1, msi.wip_supply_subinventory, NULL )
7894 ),
7895 DECODE (x_from_org_id,
7896 to_org_id, bic.supply_locator_id,
7897 DECODE( l_default_wip_params, 1, msi.wip_supply_locator_id, NULL )
7898 ),
7899 bic.operation_lead_time_percent,
7900 x_rev_item_seq_id,
7901 bic.cost_factor,
7902 bic.operation_seq_num,
7903 bic.component_item_id,
7904 SYSDATE,
7905 user_id,
7906 SYSDATE,
7907 bic.component_sequence_id,
7908 /*NULL comment for bug8431772,change NULL to user_id*/user_id,
7909 bic.item_num,
7910 -- bic.component_quantity,
7911 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
7912 AA.primary_unit_of_measure,BIC.component_quantity,
7913 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
7914 NULL,
7915 BIC.component_quantity,
7916 NULL,
7917 NULL,
7918 AA.primary_unit_of_measure,
7919 MSI.primary_unit_of_measure)) Comp_qty,
7920 bic.component_yield_factor,
7921 bic.component_remarks,
7922 -- R12 TTM ENH
7923 x_effectivity_date,
7924 x_e_change_notice,
7925 -- Implementation date will be NULL for ECO flow
7926 TO_DATE (NULL),
7927 CASE
7928 -- This flag will be set when current and future option is selected with
7929 -- copy through ECO
7930 WHEN bic.disable_date IS NOT NULL
7931 AND bic.disable_date > x_effectivity_date
7932 THEN bic.disable_date
7933 ELSE
7934 TO_DATE (NULL)
7935 END AS disable_date,
7936 decode(l_prof_val, null, bic.attribute_category, l_prof_val), --changed for bug 10078346 --bic.attribute_category,
7937 bic.attribute1,
7938 bic.attribute2,
7939 bic.attribute3,
7940 bic.attribute4,
7941 bic.attribute5,
7942 bic.attribute6,
7943 bic.attribute7,
7944 bic.attribute8,
7945 bic.attribute9,
7946 bic.attribute10,
7947 bic.attribute11,
7948 bic.attribute12,
7949 bic.attribute13,
7950 bic.attribute14,
7951 bic.attribute15,
7952 bic.planning_factor,
7953 bic.quantity_related,
7954 bic.so_basis,
7955 bic.optional,
7956 bic.mutually_exclusive_options,
7957 bic.include_in_cost_rollup,
7958 bic.check_atp,
7959 msi.bom_item_type,
7960 to_char(NULL) AS from_end_item_unit_number, -- Date Eff Bill will not have from_end_item_unit_numbers
7961 to_char(NULL) AS to_end_item_unit_number, -- Date Eff Bill will not have to_end_item_unit_numbers
7962 bic.optional_on_model,
7963 --BUGFIX 2740820
7964 bic.parent_bill_seq_id, --BUGFIX 2740820
7965 bic.model_comp_seq_id,
7966 --BUGFIX 2740820
7967 bic.plan_level, --BUGFIX 2740820
7968 bic.enforce_int_requirements,
7969 -- Either Fixed or Floating rev, the components will be from when its created, current item rev
7970 l_current_item_rev_id,
7971 -- Minor rev is not supported. Populated the first minor rev
7972 0,
7973 bic.component_item_id,
7974 to_org_id,
7975 bic.auto_request_material,
7976 -- Bug 3662214 : Added following 4 fields
7977 bic.suggested_vendor_name,
7978 bic.vendor_id,
7979 bic.unit_price,
7980 to_number(NULL) AS from_end_item_rev_id, -- From End Item Rev Ids won't be set for Date Eff Bill
7981 to_number(NULL) AS to_end_item_rev_id, -- To End Item Rev Ids won't be set for Date Eff Bill
7982 -- For Minor rev Ids
7983 0 AS from_end_item_minor_rev_id,
7984 0 AS to_end_item_minor_rev_id,
7985 (
7986 SELECT tmirb.revision_id
7987 FROM mtl_item_revisions_b fmirb,
7988 mtl_item_revisions_b tmirb
7989 WHERE tmirb.inventory_item_id = bic.component_item_id
7990 AND tmirb.organization_id = to_org_id
7991 AND tmirb.revision = fmirb.revision
7992 AND fmirb.revision_id = bic.component_item_revision_id
7993 ) AS component_item_revision_id,
7994 CASE
7995 WHEN bic.component_item_revision_id IS NULL
7996 THEN to_number(NULL)
7997 ELSE
7998 -- Minor revision is not supported
7999 0
8000 END AS component_minor_revision_id,
8001 bic.basis_type,
8002 CASE
8003 WHEN l_fixed_rev IS NOT NULL
8004 -- For fixed rev copy the components as fixed rev
8005 THEN l_to_item_rev_id
8006 ELSE
8007 to_number(NULL)
8008 END AS to_object_revision_id,
8009 CASE
8010 WHEN l_fixed_rev IS NOT NULL
8011 THEN 0
8012 ELSE
8013 to_number(NULL)
8014 END AS to_minor_revision_id
8015 FROM bom_components_b bic,
8016 mtl_system_items msi,
8017 MTL_SYSTEM_ITEMS AA , -- Added corresponding to Bug 6510185
8018 bom_copy_explosions_v bev
8019 WHERE bic.bill_sequence_id = x_from_sequence_id
8020 AND bic.component_item_id = msi.inventory_item_id
8021 AND bic.component_item_id <> to_item_id
8022 AND NVL (bic.eco_for_production, 2) = 2
8023 AND msi.organization_id = to_org_id
8024 AND MSI.inventory_item_id = AA.inventory_item_id -- Added corresponding to Bug 6510185
8025 AND AA.organization_id = from_org_id -- Added corresponding to Bug 6510185
8026 AND msi.bom_enabled_flag = 'Y' -- Added for the bug 14238677
8027 AND ((direction = eng_to_bom
8028 AND msi.eng_item_flag = 'N')
8029 OR (direction <> eng_to_bom)
8030 )
8031 AND ((base_item_flag = -1
8032 AND itm_type = 4
8033 AND msi.bom_item_type = 4
8034 )
8035 OR base_item_flag <> -1
8036 OR itm_type <> 4
8037 )
8038 AND ((bic.implementation_date IS NOT NULL)
8039 OR (bic.implementation_date IS NULL
8040 AND bic.change_notice = context_eco
8041 AND ( bic.acd_type = 1 OR bic.acd_type = 2 )
8042 )
8043 )
8044 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
8045 (
8046 SELECT 1
8047 FROM bom_components_b bcb
8048 WHERE bcb.old_component_sequence_id = bic.component_sequence_id
8049 AND bcb.change_notice = context_eco
8050 AND bcb.acd_type = 3
8051 AND bcb.effectivity_date <= x_effectivity_date
8052 AND bcb.implementation_date IS NULL
8053 AND bcb.bill_sequence_id = bic.bill_sequence_id
8054 )
8055 AND 'T' = bev.access_flag
8056 AND 'T' =
8057 bom_security_pub.check_item_privilege
8058 ('EGO_VIEW_ITEM',
8059 TO_CHAR (bic.component_item_id),
8060 TO_CHAR (to_org_id),
8061 bom_exploder_pub.get_ego_user
8062 )
8063 AND bic.component_sequence_id = bev.component_sequence_id
8064 AND bev.bill_sequence_id = from_sequence_id
8065 AND bev.parent_sort_order = p_parent_sort_order
8066 AND NOT EXISTS (
8067 SELECT 1
8068 FROM bom_copy_structure_actions bcsa
8069 WHERE bcsa.component_sequence_id =
8070 bic.component_sequence_id
8071 AND bcsa.copy_request_id = p_copy_request_id
8072 AND bcsa.organization_id = to_org_id
8073 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
8074 -- Component Action is exclude or enable
8075 -- we need not copy.
8076 )
8077 AND ( ( p_cpy_past_eff_comps = 'Y' AND bev.effectivity_date <= rev_date) -- For first revised item we can have past eff comps as eff on the target date
8078 OR ( p_cpy_past_eff_comps = 'N' AND bev.effectivity_date = rev_date )
8079 )
8080 AND EXISTS
8081 (
8082 SELECT 1
8083 FROM fnd_lookup_values_vl flv,
8084 ego_criteria_templates_v ectv,
8085 ego_criteria_v ecv,
8086 mtl_system_items_b msibs -- to assembly item
8087 WHERE ecv.customization_application_id = 702
8088 AND ecv.region_application_id = 702
8089 AND ecv.region_code = 'BOM_ITEM_TYPE_REGION'
8090 AND ecv.customization_code = ectv.customization_code
8091 AND flv.lookup_type = 'ITEM_TYPE'
8092 AND flv.enabled_flag = 'Y'
8093 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
8094 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
8095 AND flv.lookup_code = ectv.classification1
8096 AND ectv.customization_application_id = 702
8097 AND ectv.region_application_id = 702
8098 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
8099 AND flv.lookup_code = msibs.item_type
8100 AND msibs.inventory_item_id = to_item_id
8101 AND msibs.organization_id = to_org_id
8102 AND ecv.value_varchar2 = msi.item_type -- Component
8103 UNION ALL
8104 SELECT 1
8105 FROM DUAL
8106 WHERE NOT EXISTS
8107 (
8108 SELECT 1
8109 FROM fnd_lookup_values_vl flv,
8110 ego_criteria_templates_v ectv,
8111 mtl_system_items_b msibs -- to assembly item
8112 WHERE flv.lookup_type = 'ITEM_TYPE'
8113 AND flv.enabled_flag = 'Y'
8114 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
8115 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
8116 AND flv.lookup_code = ectv.classification1
8117 AND ectv.customization_application_id = 702
8118 AND ectv.region_application_id = 702
8119 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
8120 AND flv.lookup_code = msibs.item_type
8121 AND msibs.inventory_item_id = to_item_id
8122 AND msibs.organization_id = to_org_id
8123 )
8124 );
8125 ELSIF ( ( l_from_eff_ctrl = 2 AND l_to_eff_ctrl = 2 ) -- Unit
8126 OR ( l_from_eff_ctrl = 3 AND l_to_eff_ctrl = 3 ) -- Serial
8127 ) THEN
8128
8129
8130 INSERT INTO bom_components_b
8131 (shipping_allowed,
8132 required_to_ship,
8133 required_for_revenue,
8134 include_on_ship_docs,
8135 include_on_bill_docs,
8136 low_quantity,
8137 high_quantity,
8138 acd_type,
8139 component_sequence_id,
8140 old_component_sequence_id,
8141 bill_sequence_id,
8142 request_id,
8143 program_application_id,
8144 program_id,
8145 program_update_date,
8146 wip_supply_type,
8147 pick_components,
8148 supply_subinventory,
8149 supply_locator_id,
8150 operation_lead_time_percent,
8151 revised_item_sequence_id,
8152 cost_factor,
8153 operation_seq_num,
8154 component_item_id,
8155 last_update_date,
8156 last_updated_by,
8157 creation_date,
8158 created_by,
8159 last_update_login,
8160 item_num,
8161 component_quantity,
8162 component_yield_factor,
8163 component_remarks,
8164 effectivity_date,
8165 change_notice,
8166 implementation_date,
8167 disable_date,
8168 attribute_category,
8169 attribute1,
8170 attribute2,
8171 attribute3,
8172 attribute4,
8173 attribute5,
8174 attribute6,
8175 attribute7,
8176 attribute8,
8177 attribute9,
8178 attribute10,
8179 attribute11,
8180 attribute12,
8181 attribute13,
8182 attribute14,
8183 attribute15,
8184 planning_factor,
8185 quantity_related,
8186 so_basis,
8187 optional,
8188 mutually_exclusive_options,
8189 include_in_cost_rollup,
8190 check_atp,
8191 bom_item_type,
8192 from_end_item_unit_number,
8193 to_end_item_unit_number,
8194 optional_on_model,
8195 --BUGFIX 2740820
8196 parent_bill_seq_id, --BUGFIX 2740820
8197 model_comp_seq_id, --BUGFIX 2740820
8198 plan_level,
8199 --BUGFIX 2740820
8200 enforce_int_requirements, --BUGFIX 2991472
8201 from_object_revision_id,
8202 from_minor_revision_id,
8203 pk1_value,
8204 pk2_value,
8205 auto_request_material,
8206 -- Bug 3662214 : Added following 4 fields
8207 suggested_vendor_name,
8208 vendor_id,
8209 unit_price,
8210 from_end_item_rev_id,
8211 to_end_item_rev_id,
8212 from_end_item_minor_rev_id,
8213 to_end_item_minor_rev_id,
8214 component_item_revision_id,
8215 component_minor_revision_id,
8216 basis_type,
8217 to_object_revision_id,
8218 to_minor_revision_id
8219 )
8220 SELECT bic.shipping_allowed,
8221 bic.required_to_ship,
8222 bic.required_for_revenue,
8223 bic.include_on_ship_docs,
8224 bic.include_on_bill_docs,
8225 --bic.low_quantity,
8226 --bic.high_quantity,
8227 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
8228 AA.primary_unit_of_measure,BIC.low_quantity,
8229 DECODE(BIC.low_quantity,null,null, --Added this inner Deocde for Bug 6847530
8230 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
8231 NULL,
8232 BIC.low_quantity,
8233 NULL,
8234 NULL,
8235 AA.primary_unit_of_measure,
8236 MSI.primary_unit_of_measure))) Comp_low_qty,
8237 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
8238 AA.primary_unit_of_measure,BIC.high_quantity,
8239 DECODE(BIC.high_quantity,null,null, --Added this inner Deocde for Bug 6847530
8240 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
8241 NULL,
8242 BIC.high_quantity,
8243 NULL,
8244 NULL,
8245 AA.primary_unit_of_measure,
8246 MSI.primary_unit_of_measure))) Comp_high_qty,
8247 x_acd_type,
8248 bom_inventory_components_s.NEXTVAL,
8249 DECODE (x_acd_type,
8250 NULL, NULL,
8251 bom_inventory_components_s.CURRVAL
8252 ),
8253 to_sequence_id,
8254 fnd_global.conc_request_id,
8255 NULL,
8256 fnd_global.conc_program_id,
8257 sysdate,
8258 bic.wip_supply_type,
8259 DECODE (rto_flag, 'Y', 2, bic.pick_components),
8260 DECODE (x_from_org_id,
8261 to_org_id, bic.supply_subinventory,
8262 DECODE( l_default_wip_params, 1, msi.wip_supply_subinventory, NULL )
8263 ),
8264 DECODE (x_from_org_id,
8265 to_org_id, bic.supply_locator_id,
8266 DECODE( l_default_wip_params, 1, msi.wip_supply_locator_id, NULL )
8267 ),
8268 bic.operation_lead_time_percent,
8269 x_rev_item_seq_id,
8270 bic.cost_factor,
8271 bic.operation_seq_num,
8272 bic.component_item_id,
8273 SYSDATE,
8274 user_id,
8275 SYSDATE,
8276 bic.component_sequence_id,
8277 /*NULL comment for bug8431772,change NULL to user_id*/user_id,
8278 bic.item_num,
8279 -- bic.component_quantity,
8280 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
8281 AA.primary_unit_of_measure,BIC.component_quantity,
8282 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
8283 NULL,
8284 BIC.component_quantity,
8285 NULL,
8286 NULL,
8287 AA.primary_unit_of_measure,
8288 MSI.primary_unit_of_measure)) Comp_qty,
8289 bic.component_yield_factor,
8290 bic.component_remarks,
8291 -- R12 TTM ENH
8292 -- For Unit/Serial it eff date will be sysdate
8293 sysdate AS effectivity_date,
8294 x_e_change_notice,
8295 -- Implementation date will be NULL for ECO flow and SYSDATE for inline copy
8296 TO_DATE (NULL),
8297 -- For Unit/Serial Eff disable date will be null
8298 to_date(NULL) AS disable_date,
8299 decode(l_prof_val, null, bic.attribute_category, l_prof_val), --changed for bug 10078346 --bic.attribute_category,
8300 bic.attribute1,
8301 bic.attribute2,
8302 bic.attribute3,
8303 bic.attribute4,
8304 bic.attribute5,
8305 bic.attribute6,
8306 bic.attribute7,
8307 bic.attribute8,
8308 bic.attribute9,
8309 bic.attribute10,
8310 bic.attribute11,
8311 bic.attribute12,
8312 bic.attribute13,
8313 bic.attribute14,
8314 bic.attribute15,
8315 bic.planning_factor,
8316 bic.quantity_related,
8317 bic.so_basis,
8318 bic.optional,
8319 bic.mutually_exclusive_options,
8320 bic.include_in_cost_rollup,
8321 bic.check_atp,
8322 msi.bom_item_type,
8323 x_unit_number,
8324 CASE
8325 WHEN bic.to_end_item_unit_number IS NOT NULL
8326 AND bic.to_end_item_unit_number > x_unit_number
8327 THEN bic.to_end_item_unit_number
8328 ELSE
8329 to_char(NULL)
8330 END AS to_end_item_unit_number,
8331 bic.optional_on_model,
8332 --BUGFIX 2740820
8333 bic.parent_bill_seq_id, --BUGFIX 2740820
8334 bic.model_comp_seq_id,
8335 --BUGFIX 2740820
8336 bic.plan_level, --BUGFIX 2740820
8337 bic.enforce_int_requirements,
8338 -- Either Fixed or Floating rev, the components will be from when its created, current item rev
8339 l_current_item_rev_id,
8340 -- Minor rev is not supported. Populated the first minor rev
8341 0,
8342 bic.component_item_id,
8343 to_org_id,
8344 bic.auto_request_material,
8345 -- Bug 3662214 : Added following 4 fields
8346 bic.suggested_vendor_name,
8347 bic.vendor_id,
8348 bic.unit_price,
8349 to_number(NULL) AS from_end_item_rev_id,
8350 to_number(NULL) AS to_end_item_rev_id,
8351 -- For Minor rev Ids
8352 0 AS from_end_item_minor_rev_id,
8353 0 AS to_end_item_minor_rev_id,
8354 (
8355 SELECT tmirb.revision_id
8356 FROM mtl_item_revisions_b fmirb,
8357 mtl_item_revisions_b tmirb
8358 WHERE tmirb.inventory_item_id = bic.component_item_id
8359 AND tmirb.organization_id = to_org_id
8360 AND tmirb.revision = fmirb.revision
8361 AND fmirb.revision_id = bic.component_item_revision_id
8362 ) AS component_item_revision_id,
8363 CASE
8364 WHEN bic.component_item_revision_id IS NULL
8365 THEN to_number(NULL)
8366 ELSE
8367 -- Minor revision is not supported
8368 0
8369 END AS component_minor_revision_id,
8370 bic.basis_type,
8371 CASE
8372 WHEN l_fixed_rev IS NOT NULL
8373 -- For fixed rev copy the components as fixed rev
8374 THEN l_to_item_rev_id
8375 ELSE
8376 to_number(NULL)
8377 END AS to_object_revision_id,
8378 CASE
8379 WHEN l_fixed_rev IS NOT NULL
8380 THEN 0
8381 ELSE
8382 to_number(NULL)
8383 END AS to_minor_revision_id
8384 FROM bom_components_b bic,
8385 mtl_system_items msi,
8386 MTL_SYSTEM_ITEMS AA , -- Added corresponding to Bug 6510185
8387 bom_copy_explosions_v bev
8388 WHERE bic.bill_sequence_id = x_from_sequence_id
8389 AND bic.component_item_id = msi.inventory_item_id
8390 AND bic.component_item_id <> to_item_id
8391 AND NVL (bic.eco_for_production, 2) = 2
8392 AND msi.organization_id = to_org_id
8393 AND MSI.inventory_item_id = AA.inventory_item_id -- Added corresponding to Bug 6510185
8394 AND AA.organization_id = from_org_id -- Added corresponding to Bug 6510185
8395 AND msi.bom_enabled_flag = 'Y' -- Added for the bug 14238677
8396 AND ((direction = eng_to_bom
8397 AND msi.eng_item_flag = 'N')
8398 OR (direction <> eng_to_bom)
8399 )
8400 AND ((base_item_flag = -1
8401 AND itm_type = 4
8402 AND msi.bom_item_type = 4
8403 )
8404 OR base_item_flag <> -1
8405 OR itm_type <> 4
8406 )
8407 AND ((bic.implementation_date IS NOT NULL)
8408 OR (bic.implementation_date IS NULL
8409 AND bic.change_notice = context_eco
8410 AND ( bic.acd_type = 1 OR bic.acd_type = 2 )
8411 )
8412 )
8413 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
8414 (
8415 SELECT 1
8416 FROM bom_components_b bcb
8417 WHERE bcb.old_component_sequence_id = bic.component_sequence_id
8418 AND bcb.change_notice = context_eco
8419 AND bcb.acd_type = 3
8420 AND bcb.effectivity_date <= x_effectivity_date
8421 AND bcb.implementation_date IS NULL
8422 AND bcb.bill_sequence_id = bic.bill_sequence_id
8423 )
8424 AND 'T' = bev.access_flag
8425 AND 'T' =
8426 bom_security_pub.check_item_privilege
8427 ('EGO_VIEW_ITEM',
8428 TO_CHAR (bic.component_item_id),
8429 TO_CHAR (to_org_id),
8430 bom_exploder_pub.get_ego_user
8431 )
8432 AND bic.component_sequence_id = bev.component_sequence_id
8433 AND bev.bill_sequence_id = from_sequence_id
8434 AND bev.parent_sort_order = p_parent_sort_order
8435 AND NOT EXISTS (
8436 SELECT 1
8437 FROM bom_copy_structure_actions bcsa
8438 WHERE bcsa.component_sequence_id =
8439 bic.component_sequence_id
8440 AND bcsa.copy_request_id = p_copy_request_id
8441 AND bcsa.organization_id = to_org_id
8442 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
8443 -- Component Action is exclude or enable
8444 -- we need not copy.
8445 )
8446 AND ( ( p_cpy_past_eff_comps = 'Y' AND bev.from_end_item_unit_number <= unit_number) -- For first revised item we can have past eff comps as eff on the target date
8447 OR ( p_cpy_past_eff_comps = 'N' AND bev.from_end_item_unit_number = unit_number )
8448 )
8449 AND EXISTS
8450 (
8451 SELECT 1
8452 FROM fnd_lookup_values_vl flv,
8453 ego_criteria_templates_v ectv,
8454 ego_criteria_v ecv,
8455 mtl_system_items_b msibs -- to assembly item
8456 WHERE ecv.customization_application_id = 702
8457 AND ecv.region_application_id = 702
8458 AND ecv.region_code = 'BOM_ITEM_TYPE_REGION'
8459 AND ecv.customization_code = ectv.customization_code
8460 AND flv.lookup_type = 'ITEM_TYPE'
8461 AND flv.enabled_flag = 'Y'
8462 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
8463 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
8464 AND flv.lookup_code = ectv.classification1
8465 AND ectv.customization_application_id = 702
8466 AND ectv.region_application_id = 702
8467 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
8468 AND flv.lookup_code = msibs.item_type
8469 AND msibs.inventory_item_id = to_item_id
8470 AND msibs.organization_id = to_org_id
8471 AND ecv.value_varchar2 = msi.item_type -- Component
8472 UNION ALL
8473 SELECT 1
8474 FROM DUAL
8475 WHERE NOT EXISTS
8476 (
8477 SELECT 1
8478 FROM fnd_lookup_values_vl flv,
8479 ego_criteria_templates_v ectv,
8480 mtl_system_items_b msibs -- to assembly item
8481 WHERE flv.lookup_type = 'ITEM_TYPE'
8482 AND flv.enabled_flag = 'Y'
8483 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
8484 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
8485 AND flv.lookup_code = ectv.classification1
8486 AND ectv.customization_application_id = 702
8487 AND ectv.region_application_id = 702
8488 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
8489 AND flv.lookup_code = msibs.item_type
8490 AND msibs.inventory_item_id = to_item_id
8491 AND msibs.organization_id = to_org_id
8492 )
8493 );
8494 ELSIF l_from_eff_ctrl = 4 AND l_to_eff_ctrl = 4 THEN -- Rev - Rev
8495
8496
8497 INSERT INTO bom_components_b
8498 (shipping_allowed,
8499 required_to_ship,
8500 required_for_revenue,
8501 include_on_ship_docs,
8502 include_on_bill_docs,
8503 low_quantity,
8504 high_quantity,
8505 acd_type,
8506 component_sequence_id,
8507 old_component_sequence_id,
8508 bill_sequence_id,
8509 request_id,
8510 program_application_id,
8511 program_id,
8512 program_update_date,
8513 wip_supply_type,
8514 pick_components,
8515 supply_subinventory,
8516 supply_locator_id,
8517 operation_lead_time_percent,
8518 revised_item_sequence_id,
8519 cost_factor,
8520 operation_seq_num,
8521 component_item_id,
8522 last_update_date,
8523 last_updated_by,
8524 creation_date,
8525 created_by,
8526 last_update_login,
8527 item_num,
8528 component_quantity,
8529 component_yield_factor,
8530 component_remarks,
8531 effectivity_date,
8532 change_notice,
8533 implementation_date,
8534 disable_date,
8535 attribute_category,
8536 attribute1,
8537 attribute2,
8538 attribute3,
8539 attribute4,
8540 attribute5,
8541 attribute6,
8542 attribute7,
8543 attribute8,
8544 attribute9,
8545 attribute10,
8546 attribute11,
8547 attribute12,
8548 attribute13,
8549 attribute14,
8550 attribute15,
8551 planning_factor,
8552 quantity_related,
8553 so_basis,
8554 optional,
8555 mutually_exclusive_options,
8556 include_in_cost_rollup,
8557 check_atp,
8558 bom_item_type,
8559 from_end_item_unit_number,
8560 to_end_item_unit_number,
8561 optional_on_model,
8562 --BUGFIX 2740820
8563 parent_bill_seq_id, --BUGFIX 2740820
8564 model_comp_seq_id, --BUGFIX 2740820
8565 plan_level,
8566 --BUGFIX 2740820
8567 enforce_int_requirements, --BUGFIX 2991472
8568 from_object_revision_id,
8569 from_minor_revision_id,
8570 pk1_value,
8571 pk2_value,
8572 auto_request_material,
8573 -- Bug 3662214 : Added following 4 fields
8574 suggested_vendor_name,
8575 vendor_id,
8576 unit_price,
8577 from_end_item_rev_id,
8578 to_end_item_rev_id,
8579 from_end_item_minor_rev_id,
8580 to_end_item_minor_rev_id,
8581 component_item_revision_id,
8582 component_minor_revision_id,
8583 basis_type,
8584 to_object_revision_id,
8585 to_minor_revision_id
8586 )
8587 SELECT bic.shipping_allowed,
8588 bic.required_to_ship,
8589 bic.required_for_revenue,
8590 bic.include_on_ship_docs,
8591 bic.include_on_bill_docs,
8592 --bic.low_quantity,
8593 --bic.high_quantity,
8594 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
8595 AA.primary_unit_of_measure,BIC.low_quantity,
8596 DECODE(BIC.low_quantity,null,null, --Added this inner Deocde for Bug 6847530
8597 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
8598 NULL,
8599 BIC.low_quantity,
8600 NULL,
8601 NULL,
8602 AA.primary_unit_of_measure,
8603 MSI.primary_unit_of_measure))) Comp_low_qty,
8604 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
8605 AA.primary_unit_of_measure,BIC.high_quantity,
8606 DECODE(BIC.high_quantity,null,null, --Added this inner Deocde for Bug 6847530
8607 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
8608 NULL,
8609 BIC.high_quantity,
8610 NULL,
8611 NULL,
8612 AA.primary_unit_of_measure,
8613 MSI.primary_unit_of_measure))) Comp_high_qty,
8614 x_acd_type,
8615 bom_inventory_components_s.NEXTVAL,
8616 DECODE (x_acd_type,
8617 NULL, NULL,
8618 bom_inventory_components_s.CURRVAL
8619 ),
8620 to_sequence_id,
8621 fnd_global.conc_request_id,
8622 NULL,
8623 fnd_global.conc_program_id,
8624 sysdate,
8625 bic.wip_supply_type,
8626 DECODE (rto_flag, 'Y', 2, bic.pick_components),
8627 DECODE (x_from_org_id,
8628 to_org_id, bic.supply_subinventory,
8629 DECODE( l_default_wip_params, 1, msi.wip_supply_subinventory, NULL )
8630 ),
8631 DECODE (x_from_org_id,
8632 to_org_id, bic.supply_locator_id,
8633 DECODE( l_default_wip_params, 1, msi.wip_supply_locator_id, NULL )
8634 ),
8635 bic.operation_lead_time_percent,
8636 x_rev_item_seq_id,
8637 bic.cost_factor,
8638 bic.operation_seq_num,
8639 bic.component_item_id,
8640 SYSDATE,
8641 user_id,
8642 SYSDATE,
8643 bic.component_sequence_id,
8644 /*NULL comment for bug8431772,change NULL to user_id*/user_id,
8645 bic.item_num,
8646 --bic.component_quantity,
8647 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
8648 AA.primary_unit_of_measure,BIC.component_quantity,
8649 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
8650 NULL,
8651 BIC.component_quantity,
8652 NULL,
8653 NULL,
8654 AA.primary_unit_of_measure,
8655 MSI.primary_unit_of_measure)) Comp_qty,
8656 bic.component_yield_factor,
8657 bic.component_remarks,
8658 -- R12 TTM ENH
8659 -- For Rev Eff Structure the eff date will be sysdate
8660 sysdate AS effectivity_date,
8661 x_e_change_notice,
8662 -- Implementation date will be NULL for ECO flow and SYSDATE for inline copy
8663 TO_DATE (NULL),
8664 -- For Rev Eff structure the disable date will be null
8665 to_date(NULL) AS disable_date,
8666 decode(l_prof_val, null, bic.attribute_category, l_prof_val), --changed for bug 10078346 --bic.attribute_category,
8667 bic.attribute1,
8668 bic.attribute2,
8669 bic.attribute3,
8670 bic.attribute4,
8671 bic.attribute5,
8672 bic.attribute6,
8673 bic.attribute7,
8674 bic.attribute8,
8675 bic.attribute9,
8676 bic.attribute10,
8677 bic.attribute11,
8678 bic.attribute12,
8679 bic.attribute13,
8680 bic.attribute14,
8681 bic.attribute15,
8682 bic.planning_factor,
8683 bic.quantity_related,
8684 bic.so_basis,
8685 bic.optional,
8686 bic.mutually_exclusive_options,
8687 bic.include_in_cost_rollup,
8688 --DECODE(atp_comp_flag, 'Y', CHECK_ATP, 2), fixed bug 2249375
8689 bic.check_atp,
8690 msi.bom_item_type,
8691 to_char(NULL) AS from_end_item_unit_number,
8692 to_char(NULL) AS to_end_item_unit_number,
8693 bic.optional_on_model,
8694 --BUGFIX 2740820
8695 bic.parent_bill_seq_id, --BUGFIX 2740820
8696 bic.model_comp_seq_id,
8697 --BUGFIX 2740820
8698 bic.plan_level, --BUGFIX 2740820
8699 bic.enforce_int_requirements,
8700 -- Either Fixed or Floating rev, the components will be from when its created, current item rev
8701 l_current_item_rev_id,
8702 -- Minor rev is not supported. Populated the first minor rev
8703 0,
8704 bic.component_item_id,
8705 to_org_id,
8706 bic.auto_request_material,
8707 -- Bug 3662214 : Added following 4 fields
8708 bic.suggested_vendor_name,
8709 bic.vendor_id,
8710 bic.unit_price,
8711 x_end_item_rev_id,
8712 -- This release we are not supporting transformation -- 14 Mar 2005
8713 -- This case is to handle the revised item creation from TTM flow
8714 -- This is the first case
8715 CASE
8716 WHEN bic.to_end_item_rev_id IS NOT NULL
8717 AND (
8718 EXISTS
8719 (
8720 SELECT tmirb.revision_id
8721 FROM mtl_item_revisions_b fmirb,
8722 mtl_item_revisions_b tmirb
8723 WHERE tmirb.inventory_item_id = to_item_id
8724 AND tmirb.organization_id = to_org_id
8725 AND tmirb.revision = fmirb.revision
8726 AND fmirb.revision_id = bic.to_end_item_rev_id
8727 )
8728 AND
8729 (
8730 SELECT REVISION
8731 FROM MTL_ITEM_REVISIONS_B
8732 WHERE REVISION_ID = bic.to_end_item_rev_id
8733 ) >
8734 (
8735 SELECT REVISION
8736 FROM MTL_ITEM_REVISIONS_B
8737 WHERE REVISION_ID = x_end_item_rev_id
8738 )
8739 )
8740 THEN
8741 (
8742 SELECT tmirb.revision_id
8743 FROM mtl_item_revisions_b fmirb,
8744 mtl_item_revisions_b tmirb
8745 WHERE tmirb.inventory_item_id = to_item_id
8746 AND tmirb.organization_id = to_org_id
8747 AND tmirb.revision = fmirb.revision
8748 AND fmirb.revision_id = bic.to_end_item_rev_id
8749 )
8750 ELSE
8751 to_number(NULL)
8752 END AS to_end_item_rev_id,
8753 -- For Minor rev Ids
8754 0 AS from_end_item_minor_rev_id,
8755 0 AS to_end_item_minor_rev_id,
8756 (
8757 SELECT tmirb.revision_id
8758 FROM mtl_item_revisions_b fmirb,
8759 mtl_item_revisions_b tmirb
8760 WHERE tmirb.inventory_item_id = bic.component_item_id
8761 AND tmirb.organization_id = to_org_id
8762 AND tmirb.revision = fmirb.revision
8763 AND fmirb.revision_id = bic.component_item_revision_id
8764 ) AS component_item_revision_id,
8765 CASE
8766 WHEN bic.component_item_revision_id IS NULL
8767 THEN to_number(NULL)
8768 ELSE
8769 -- Minor revision is not supported
8770 0
8771 END AS component_minor_revision_id,
8772 bic.basis_type,
8773 CASE
8774 WHEN l_fixed_rev IS NOT NULL
8775 -- For fixed rev copy the components as fixed rev
8776 THEN l_to_item_rev_id
8777 ELSE
8778 to_number(NULL)
8779 END AS to_object_revision_id,
8780 CASE
8781 WHEN l_fixed_rev IS NOT NULL
8782 THEN 0
8783 ELSE
8784 to_number(NULL)
8785 END AS to_minor_revision_id
8786 FROM bom_components_b bic,
8787 mtl_system_items msi,
8788 MTL_SYSTEM_ITEMS AA , -- Added corresponding to Bug 6510185
8789 bom_copy_explosions_v bev
8790 WHERE bic.bill_sequence_id = x_from_sequence_id
8791 AND bic.component_item_id = msi.inventory_item_id
8792 AND bic.component_item_id <> to_item_id
8793 AND NVL (bic.eco_for_production, 2) = 2
8794 AND msi.organization_id = to_org_id
8795 AND MSI.inventory_item_id = AA.inventory_item_id -- Added corresponding to Bug 6510185
8796 AND AA.organization_id = from_org_id -- Added corresponding to Bug 6510185
8797 AND msi.bom_enabled_flag = 'Y' -- Added for the bug 14238677
8798 AND ((direction = eng_to_bom
8799 AND msi.eng_item_flag = 'N')
8800 OR (direction <> eng_to_bom)
8801 )
8802 AND ((base_item_flag = -1
8803 AND itm_type = 4
8804 AND msi.bom_item_type = 4
8805 )
8806 OR base_item_flag <> -1
8807 OR itm_type <> 4
8808 )
8809 AND ((bic.implementation_date IS NOT NULL)
8810 OR (bic.implementation_date IS NULL
8811 AND bic.change_notice = context_eco
8812 AND ( bic.acd_type = 1 OR bic.acd_type = 2 )
8813 )
8814 )
8815 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
8816 (
8817 SELECT 1
8818 FROM bom_components_b bcb
8819 WHERE bcb.old_component_sequence_id = bic.component_sequence_id
8820 AND bcb.change_notice = context_eco
8821 AND bcb.acd_type = 3
8822 AND bcb.effectivity_date <= x_effectivity_date
8823 AND bcb.implementation_date IS NULL
8824 AND bcb.bill_sequence_id = bic.bill_sequence_id
8825 )
8826 AND 'T' = bev.access_flag
8827 AND 'T' =
8828 bom_security_pub.check_item_privilege
8829 ('EGO_VIEW_ITEM',
8830 TO_CHAR (bic.component_item_id),
8831 TO_CHAR (to_org_id),
8832 bom_exploder_pub.get_ego_user
8833 )
8834 AND bic.component_sequence_id = bev.component_sequence_id
8835 AND bev.bill_sequence_id = from_sequence_id
8836 AND bev.parent_sort_order = p_parent_sort_order
8837 AND NOT EXISTS (
8838 SELECT 1
8839 FROM bom_copy_structure_actions bcsa
8840 WHERE bcsa.component_sequence_id =
8841 bic.component_sequence_id
8842 AND bcsa.copy_request_id = p_copy_request_id
8843 AND bcsa.organization_id = to_org_id
8844 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
8845 -- Component Action is exclude or enable
8846 -- we need not copy.
8847 )
8848 AND ( p_cpy_past_eff_comps = 'Y' AND ( ( SELECT mirb.revision
8849 FROM mtl_item_revisions_b mirb
8850 WHERE mirb.revision_id = bev.from_end_item_rev_id
8851 )
8852 <=
8853 (
8854 SELECT mirb.revision
8855 FROM mtl_item_revisions_b mirb
8856 WHERE mirb.revision_id = p_end_item_rev_id
8857 )
8858 ) -- For first revised item we can have past eff comps as eff on the target date
8859 OR ( p_cpy_past_eff_comps = 'N' AND bev.from_end_item_rev_id = p_end_item_rev_id )
8860 )
8861 AND EXISTS
8862 (
8863 SELECT 1
8864 FROM fnd_lookup_values_vl flv,
8865 ego_criteria_templates_v ectv,
8866 ego_criteria_v ecv,
8867 mtl_system_items_b msibs -- to assembly item
8868 WHERE ecv.customization_application_id = 702
8869 AND ecv.region_application_id = 702
8870 AND ecv.region_code = 'BOM_ITEM_TYPE_REGION'
8871 AND ecv.customization_code = ectv.customization_code
8872 AND flv.lookup_type = 'ITEM_TYPE'
8873 AND flv.enabled_flag = 'Y'
8874 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
8875 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
8876 AND flv.lookup_code = ectv.classification1
8877 AND ectv.customization_application_id = 702
8878 AND ectv.region_application_id = 702
8879 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
8880 AND flv.lookup_code = msibs.item_type
8881 AND msibs.inventory_item_id = to_item_id
8882 AND msibs.organization_id = to_org_id
8883 AND ecv.value_varchar2 = msi.item_type -- Component
8884 UNION ALL
8885 SELECT 1
8886 FROM DUAL
8887 WHERE NOT EXISTS
8888 (
8889 SELECT 1
8890 FROM fnd_lookup_values_vl flv,
8891 ego_criteria_templates_v ectv,
8892 mtl_system_items_b msibs -- to assembly item
8893 WHERE flv.lookup_type = 'ITEM_TYPE'
8894 AND flv.enabled_flag = 'Y'
8895 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
8896 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
8897 AND flv.lookup_code = ectv.classification1
8898 AND ectv.customization_application_id = 702
8899 AND ectv.region_application_id = 702
8900 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
8901 AND flv.lookup_code = msibs.item_type
8902 AND msibs.inventory_item_id = to_item_id
8903 AND msibs.organization_id = to_org_id
8904 )
8905 );
8906 ELSIF l_from_eff_ctrl = 4 AND l_to_eff_ctrl = 1 THEN -- Rev - Date
8907
8908
8909 INSERT INTO bom_components_b
8910 (shipping_allowed,
8911 required_to_ship,
8912 required_for_revenue,
8913 include_on_ship_docs,
8914 include_on_bill_docs,
8915 low_quantity,
8916 high_quantity,
8917 acd_type,
8918 component_sequence_id,
8919 old_component_sequence_id,
8920 bill_sequence_id,
8921 request_id,
8922 program_application_id,
8923 program_id,
8924 program_update_date,
8925 wip_supply_type,
8926 pick_components,
8927 supply_subinventory,
8928 supply_locator_id,
8929 operation_lead_time_percent,
8930 revised_item_sequence_id,
8931 cost_factor,
8932 operation_seq_num,
8933 component_item_id,
8934 last_update_date,
8935 last_updated_by,
8936 creation_date,
8937 created_by,
8938 last_update_login,
8939 item_num,
8940 component_quantity,
8941 component_yield_factor,
8942 component_remarks,
8943 effectivity_date,
8944 change_notice,
8945 implementation_date,
8946 disable_date,
8947 attribute_category,
8948 attribute1,
8949 attribute2,
8950 attribute3,
8951 attribute4,
8952 attribute5,
8953 attribute6,
8954 attribute7,
8955 attribute8,
8956 attribute9,
8957 attribute10,
8958 attribute11,
8959 attribute12,
8960 attribute13,
8961 attribute14,
8962 attribute15,
8963 planning_factor,
8964 quantity_related,
8965 so_basis,
8966 optional,
8967 mutually_exclusive_options,
8968 include_in_cost_rollup,
8969 check_atp,
8970 bom_item_type,
8971 from_end_item_unit_number,
8972 to_end_item_unit_number,
8973 optional_on_model,
8974 --BUGFIX 2740820
8975 parent_bill_seq_id, --BUGFIX 2740820
8976 model_comp_seq_id, --BUGFIX 2740820
8977 plan_level,
8978 --BUGFIX 2740820
8979 enforce_int_requirements, --BUGFIX 2991472
8980 from_object_revision_id,
8981 from_minor_revision_id,
8982 pk1_value,
8983 pk2_value,
8984 auto_request_material,
8985 -- Bug 3662214 : Added following 4 fields
8986 suggested_vendor_name,
8987 vendor_id,
8988 unit_price,
8989 from_end_item_rev_id,
8990 to_end_item_rev_id,
8991 from_end_item_minor_rev_id,
8992 to_end_item_minor_rev_id,
8993 component_item_revision_id,
8994 component_minor_revision_id,
8995 basis_type,
8996 to_object_revision_id,
8997 to_minor_revision_id
8998 )
8999 SELECT bic.shipping_allowed,
9000 bic.required_to_ship,
9001 bic.required_for_revenue,
9002 bic.include_on_ship_docs,
9003 bic.include_on_bill_docs,
9004 --bic.low_quantity,
9005 --bic.high_quantity,
9006 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
9007 AA.primary_unit_of_measure,BIC.low_quantity,
9008 DECODE(BIC.low_quantity,null,null, --Added this inner Deocde for Bug 6847530
9009 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
9010 NULL,
9011 BIC.low_quantity,
9012 NULL,
9013 NULL,
9014 AA.primary_unit_of_measure,
9015 MSI.primary_unit_of_measure))) Comp_low_qty,
9016 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
9017 AA.primary_unit_of_measure,BIC.high_quantity,
9018 DECODE(BIC.high_quantity,null,null, --Added this inner Deocde for Bug 6847530
9019 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
9020 NULL,
9021 BIC.high_quantity,
9022 NULL,
9023 NULL,
9024 AA.primary_unit_of_measure,
9025 MSI.primary_unit_of_measure))) Comp_high_qty,
9026
9027 x_acd_type,
9028 bom_inventory_components_s.NEXTVAL,
9029 DECODE (x_acd_type,
9030 NULL, NULL,
9031 bom_inventory_components_s.CURRVAL
9032 ),
9033 to_sequence_id,
9034 fnd_global.conc_request_id,
9035 NULL,
9036 fnd_global.conc_program_id,
9037 sysdate,
9038 bic.wip_supply_type,
9039 DECODE (rto_flag, 'Y', 2, bic.pick_components),
9040 DECODE (x_from_org_id,
9041 to_org_id, bic.supply_subinventory,
9042 DECODE( l_default_wip_params, 1, msi.wip_supply_subinventory, NULL )
9043 ),
9044 DECODE (x_from_org_id,
9045 to_org_id, bic.supply_locator_id,
9046 DECODE( l_default_wip_params, 1, msi.wip_supply_locator_id, NULL )
9047 ),
9048 bic.operation_lead_time_percent,
9049 x_rev_item_seq_id,
9050 bic.cost_factor,
9051 bic.operation_seq_num,
9052 bic.component_item_id,
9053 SYSDATE,
9054 user_id,
9055 SYSDATE,
9056 bic.component_sequence_id,
9057 /*NULL comment for bug8431772,change NULL to user_id*/user_id,
9058 bic.item_num,
9059 --bic.component_quantity,
9060 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
9061 AA.primary_unit_of_measure,BIC.component_quantity,
9062 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
9063 NULL,
9064 BIC.component_quantity,
9065 NULL,
9066 NULL,
9067 AA.primary_unit_of_measure,
9068 MSI.primary_unit_of_measure)) Comp_qty,
9069 bic.component_yield_factor,
9070 bic.component_remarks,
9071 x_effectivity_date,
9072 x_e_change_notice,
9073 -- Implementation date will be NULL for ECO flow and SYSDATE for inline copy
9074 TO_DATE (NULL),
9075 CASE
9076 WHEN bic.to_end_item_rev_id IS NULL
9077 THEN to_date(NULL)
9078 -- This flag will be set when current and future option is selected with
9079 -- copy through ECO
9080 WHEN bic.to_end_item_rev_id IS NOT NULL
9081 AND (
9082 (
9083 SELECT fmirb.effectivity_date
9084 FROM mtl_item_revisions_b fmirb
9085 WHERE fmirb.revision_id = bic.to_end_item_rev_id
9086 ) > x_effectivity_date
9087 )
9088 THEN (
9089 SELECT fmirb.effectivity_date
9090 FROM mtl_item_revisions_b fmirb
9091 WHERE fmirb.revision_id = bic.to_end_item_rev_id
9092 )
9093 -- Past disabled components will be copied with disable date as null
9094 WHEN (
9095 ( SELECT fmirb.effectivity_date
9096 FROM mtl_item_revisions_b fmirb
9097 WHERE fmirb.revision_id = bic.to_end_item_rev_id
9098 ) < x_effectivity_date
9099 )
9100 THEN TO_DATE (NULL)
9101 -- Past disabled components will be copied with disable date as null
9102 ELSE
9103 -- Future disabled components should be disabled as per the disable date of component
9104 bic.disable_date
9105 END AS disable_date,
9106 decode(l_prof_val, null, bic.attribute_category, l_prof_val), --changed for bug 10078346 --bic.attribute_category,
9107 bic.attribute1,
9108 bic.attribute2,
9109 bic.attribute3,
9110 bic.attribute4,
9111 bic.attribute5,
9112 bic.attribute6,
9113 bic.attribute7,
9114 bic.attribute8,
9115 bic.attribute9,
9116 bic.attribute10,
9117 bic.attribute11,
9118 bic.attribute12,
9119 bic.attribute13,
9120 bic.attribute14,
9121 bic.attribute15,
9122 bic.planning_factor,
9123 bic.quantity_related,
9124 bic.so_basis,
9125 bic.optional,
9126 bic.mutually_exclusive_options,
9127 bic.include_in_cost_rollup,
9128 bic.check_atp,
9129 msi.bom_item_type,
9130 to_char(NULL) AS from_end_item_unit_number, -- Date Eff Bill will not have from_end_item_unit_numbers
9131 to_char(NULL) AS to_end_item_unit_number, -- Date Eff Bill will not have to_end_item_unit_numbers
9132 bic.optional_on_model,
9133 --BUGFIX 2740820
9134 bic.parent_bill_seq_id, --BUGFIX 2740820
9135 bic.model_comp_seq_id,
9136 --BUGFIX 2740820
9137 bic.plan_level, --BUGFIX 2740820
9138 bic.enforce_int_requirements,
9139 -- Either Fixed or Floating rev, the components will be from when its created, current item rev
9140 l_current_item_rev_id,
9141 -- Minor rev is not supported. Populated the first minor rev
9142 0,
9143 bic.component_item_id,
9144 to_org_id,
9145 bic.auto_request_material,
9146 -- Bug 3662214 : Added following 4 fields
9147 bic.suggested_vendor_name,
9148 bic.vendor_id,
9149 bic.unit_price,
9150 to_number(NULL) AS from_end_item_rev_id, -- From End Item Rev Ids won't be set for Date Eff Bill
9151 to_number(NULL) AS to_end_item_rev_id, -- To End Item Rev Ids won't be set for Date Eff Bill
9152 -- For Minor rev Ids
9153 0 AS from_end_item_minor_rev_id,
9154 0 AS to_end_item_minor_rev_id,
9155 (
9156 SELECT tmirb.revision_id
9157 FROM mtl_item_revisions_b fmirb,
9158 mtl_item_revisions_b tmirb
9159 WHERE tmirb.inventory_item_id = bic.component_item_id
9160 AND tmirb.organization_id = to_org_id
9161 AND tmirb.revision = fmirb.revision
9162 AND fmirb.revision_id = bic.component_item_revision_id
9163 ) AS component_item_revision_id,
9164 CASE
9165 WHEN bic.component_item_revision_id IS NULL
9166 THEN to_number(NULL)
9167 ELSE
9168 -- Minor revision is not supported
9169 0
9170 END AS component_minor_revision_id,
9171 bic.basis_type,
9172 CASE
9173 WHEN l_fixed_rev IS NOT NULL
9174 -- For fixed rev copy the components as fixed rev
9175 THEN l_to_item_rev_id
9176 ELSE
9177 to_number(NULL)
9178 END AS to_object_revision_id,
9179 CASE
9180 WHEN l_fixed_rev IS NOT NULL
9181 THEN 0
9182 ELSE
9183 to_number(NULL)
9184 END AS to_minor_revision_id
9185 FROM bom_components_b bic,
9186 mtl_system_items msi,
9187 MTL_SYSTEM_ITEMS AA , -- Added corresponding to Bug 6510185
9188 bom_copy_explosions_v bev
9189 WHERE bic.bill_sequence_id = x_from_sequence_id
9190 AND bic.component_item_id = msi.inventory_item_id
9191 AND bic.component_item_id <> to_item_id
9192 AND NVL (bic.eco_for_production, 2) = 2
9193 AND msi.organization_id = to_org_id
9194 AND MSI.inventory_item_id = AA.inventory_item_id -- Added corresponding to Bug 6510185
9195 AND AA.organization_id = from_org_id -- Added corresponding to Bug 6510185
9196 AND msi.bom_enabled_flag = 'Y' -- Added for the bug 14238677
9197 AND ((direction = eng_to_bom
9198 AND msi.eng_item_flag = 'N')
9199 OR (direction <> eng_to_bom)
9200 )
9201 AND ((base_item_flag = -1
9202 AND itm_type = 4
9203 AND msi.bom_item_type = 4
9204 )
9205 OR base_item_flag <> -1
9206 OR itm_type <> 4
9207 )
9208 AND ((bic.implementation_date IS NOT NULL)
9209 OR (bic.implementation_date IS NULL
9210 AND bic.change_notice = context_eco
9211 AND ( bic.acd_type = 1 OR bic.acd_type = 2 )
9212 )
9213 )
9214 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
9215 (
9216 SELECT 1
9217 FROM bom_components_b bcb
9218 WHERE bcb.old_component_sequence_id = bic.component_sequence_id
9219 AND bcb.change_notice = context_eco
9220 AND bcb.acd_type = 3
9221 AND bcb.effectivity_date <= x_effectivity_date
9222 AND bcb.implementation_date IS NULL
9223 AND bcb.bill_sequence_id = bic.bill_sequence_id
9224 )
9225 AND 'T' = bev.access_flag
9226 AND 'T' =
9227 bom_security_pub.check_item_privilege
9228 ('EGO_VIEW_ITEM',
9229 TO_CHAR (bic.component_item_id),
9230 TO_CHAR (to_org_id),
9231 bom_exploder_pub.get_ego_user
9232 )
9233 AND bic.component_sequence_id = bev.component_sequence_id
9234 AND bev.bill_sequence_id = from_sequence_id
9235 AND bev.parent_sort_order = p_parent_sort_order
9236 AND NOT EXISTS (
9237 SELECT 1
9238 FROM bom_copy_structure_actions bcsa
9239 WHERE bcsa.component_sequence_id =
9240 bic.component_sequence_id
9241 AND bcsa.copy_request_id = p_copy_request_id
9242 AND bcsa.organization_id = to_org_id
9243 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
9244 -- Component Action is exclude or enable
9245 -- we need not copy.
9246 )
9247 AND ( ( p_cpy_past_eff_comps = 'Y' AND ( SELECT mirb.effectivity_date
9248 FROM mtl_item_revisions_b mirb
9249 WHERE mirb.revision_id = bev.from_end_item_rev_id
9250 ) <= ( SELECT mirb.effectivity_date
9251 FROM mtl_item_revisions_b mirb
9252 WHERE mirb.revision_id = p_end_item_rev_id
9253 )) -- For first revised item we can have past eff comps as eff on the target date
9254 OR ( p_cpy_past_eff_comps = 'N' AND ( SELECT mirb.effectivity_date
9255 FROM mtl_item_revisions_b mirb
9256 WHERE mirb.revision_id = bev.from_end_item_rev_id
9257 ) = ( SELECT mirb.effectivity_date
9258 FROM mtl_item_revisions_b mirb
9259 WHERE mirb.revision_id = p_end_item_rev_id
9260 ) )
9261 )
9262 AND EXISTS
9263 (
9264 SELECT 1
9265 FROM fnd_lookup_values_vl flv,
9266 ego_criteria_templates_v ectv,
9267 ego_criteria_v ecv,
9268 mtl_system_items_b msibs -- to assembly item
9269 WHERE ecv.customization_application_id = 702
9270 AND ecv.region_application_id = 702
9271 AND ecv.region_code = 'BOM_ITEM_TYPE_REGION'
9272 AND ecv.customization_code = ectv.customization_code
9273 AND flv.lookup_type = 'ITEM_TYPE'
9274 AND flv.enabled_flag = 'Y'
9275 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
9276 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
9277 AND flv.lookup_code = ectv.classification1
9278 AND ectv.customization_application_id = 702
9279 AND ectv.region_application_id = 702
9280 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
9281 AND flv.lookup_code = msibs.item_type
9282 AND msibs.inventory_item_id = to_item_id
9283 AND msibs.organization_id = to_org_id
9284 AND ecv.value_varchar2 = msi.item_type -- Component
9285 UNION ALL
9286 SELECT 1
9287 FROM DUAL
9288 WHERE NOT EXISTS
9289 (
9290 SELECT 1
9291 FROM fnd_lookup_values_vl flv,
9292 ego_criteria_templates_v ectv,
9293 mtl_system_items_b msibs -- to assembly item
9294 WHERE flv.lookup_type = 'ITEM_TYPE'
9295 AND flv.enabled_flag = 'Y'
9296 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
9297 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
9298 AND flv.lookup_code = ectv.classification1
9299 AND ectv.customization_application_id = 702
9300 AND ectv.region_application_id = 702
9301 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
9302 AND flv.lookup_code = msibs.item_type
9303 AND msibs.inventory_item_id = to_item_id
9304 AND msibs.organization_id = to_org_id
9305 )
9306 );
9307 ELSIF l_from_eff_ctrl = 1 AND l_to_eff_ctrl = 4 THEN -- Date - Rev
9308
9309
9310 INSERT INTO bom_components_b
9311 (shipping_allowed,
9312 required_to_ship,
9313 required_for_revenue,
9314 include_on_ship_docs,
9315 include_on_bill_docs,
9316 low_quantity,
9317 high_quantity,
9318 acd_type,
9319 component_sequence_id,
9320 old_component_sequence_id,
9321 bill_sequence_id,
9322 request_id,
9323 program_application_id,
9324 program_id,
9325 program_update_date,
9326 wip_supply_type,
9327 pick_components,
9328 supply_subinventory,
9329 supply_locator_id,
9330 operation_lead_time_percent,
9331 revised_item_sequence_id,
9332 cost_factor,
9333 operation_seq_num,
9334 component_item_id,
9335 last_update_date,
9336 last_updated_by,
9337 creation_date,
9338 created_by,
9339 last_update_login,
9340 item_num,
9341 component_quantity,
9342 component_yield_factor,
9343 component_remarks,
9344 effectivity_date,
9345 change_notice,
9346 implementation_date,
9347 disable_date,
9348 attribute_category,
9349 attribute1,
9350 attribute2,
9351 attribute3,
9352 attribute4,
9353 attribute5,
9354 attribute6,
9355 attribute7,
9356 attribute8,
9357 attribute9,
9358 attribute10,
9359 attribute11,
9360 attribute12,
9361 attribute13,
9362 attribute14,
9363 attribute15,
9364 planning_factor,
9365 quantity_related,
9366 so_basis,
9367 optional,
9368 mutually_exclusive_options,
9369 include_in_cost_rollup,
9370 check_atp,
9371 bom_item_type,
9372 from_end_item_unit_number,
9373 to_end_item_unit_number,
9374 optional_on_model,
9375 --BUGFIX 2740820
9376 parent_bill_seq_id, --BUGFIX 2740820
9377 model_comp_seq_id, --BUGFIX 2740820
9378 plan_level,
9379 --BUGFIX 2740820
9380 enforce_int_requirements, --BUGFIX 2991472
9381 from_object_revision_id,
9382 from_minor_revision_id,
9383 pk1_value,
9384 pk2_value,
9385 auto_request_material,
9386 -- Bug 3662214 : Added following 4 fields
9387 suggested_vendor_name,
9388 vendor_id,
9389 unit_price,
9390 from_end_item_rev_id,
9391 to_end_item_rev_id,
9392 from_end_item_minor_rev_id,
9393 to_end_item_minor_rev_id,
9394 component_item_revision_id,
9395 component_minor_revision_id,
9396 basis_type,
9397 to_object_revision_id,
9398 to_minor_revision_id
9399 )
9400 SELECT bic.shipping_allowed,
9401 bic.required_to_ship,
9402 bic.required_for_revenue,
9403 bic.include_on_ship_docs,
9404 bic.include_on_bill_docs,
9405 -- bic.low_quantity,
9406 -- bic.high_quantity,
9407 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
9408 AA.primary_unit_of_measure,BIC.low_quantity,
9409 DECODE(BIC.low_quantity,null,null, --Added this inner Deocde for Bug 6847530
9410 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
9411 NULL,
9412 BIC.low_quantity,
9413 NULL,
9414 NULL,
9415 AA.primary_unit_of_measure,
9416 MSI.primary_unit_of_measure))) Comp_low_qty,
9417 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
9418 AA.primary_unit_of_measure,BIC.high_quantity,
9419 DECODE(BIC.high_quantity,null,null, --Added this inner Deocde for Bug 6847530
9420 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
9421 NULL,
9422 BIC.high_quantity,
9423 NULL,
9424 NULL,
9425 AA.primary_unit_of_measure,
9426 MSI.primary_unit_of_measure))) Comp_high_qty,
9427 x_acd_type,
9428 bom_inventory_components_s.NEXTVAL,
9429 DECODE (x_acd_type,
9430 NULL, NULL,
9431 bom_inventory_components_s.CURRVAL
9432 ),
9433 to_sequence_id,
9434 fnd_global.conc_request_id,
9435 NULL,
9436 fnd_global.conc_program_id,
9437 sysdate,
9438 bic.wip_supply_type,
9439 DECODE (rto_flag, 'Y', 2, bic.pick_components),
9440 DECODE (x_from_org_id,
9441 to_org_id, bic.supply_subinventory,
9442 DECODE( l_default_wip_params, 1, msi.wip_supply_subinventory, NULL )
9443 ),
9444 DECODE (x_from_org_id,
9445 to_org_id, bic.supply_locator_id,
9446 DECODE( l_default_wip_params, 1, msi.wip_supply_locator_id, NULL )
9447 ),
9448 bic.operation_lead_time_percent,
9449 x_rev_item_seq_id,
9450 bic.cost_factor,
9451 bic.operation_seq_num,
9452 bic.component_item_id,
9453 SYSDATE,
9454 user_id,
9455 SYSDATE,
9456 bic.component_sequence_id,
9457 /*NULL comment for bug8431772,change NULL to user_id*/user_id,
9458 bic.item_num,
9459 --bic.component_quantity,
9460 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
9461 AA.primary_unit_of_measure,BIC.component_quantity,
9462 inv_convert.INV_UM_CONVERT(BIC.component_item_id,
9463 NULL,
9464 BIC.component_quantity,
9465 NULL,
9466 NULL,
9467 AA.primary_unit_of_measure,
9468 MSI.primary_unit_of_measure)) Comp_qty,
9469 bic.component_yield_factor,
9470 bic.component_remarks,
9471 -- R12 TTM ENH
9472 -- For Rev Eff Structure the eff date will be sysdate
9473 sysdate AS effectivity_date,
9474 x_e_change_notice,
9475 -- Implementation date will be NULL for ECO flow
9476 TO_DATE (NULL),
9477 -- For Rev Eff structure the disable date will be null
9478 to_date(NULL) AS disable_date,
9479 decode(l_prof_val, null, bic.attribute_category, l_prof_val), --changed for bug 10078346 --bic.attribute_category,
9480 bic.attribute1,
9481 bic.attribute2,
9482 bic.attribute3,
9483 bic.attribute4,
9484 bic.attribute5,
9485 bic.attribute6,
9486 bic.attribute7,
9487 bic.attribute8,
9488 bic.attribute9,
9489 bic.attribute10,
9490 bic.attribute11,
9491 bic.attribute12,
9492 bic.attribute13,
9493 bic.attribute14,
9494 bic.attribute15,
9495 bic.planning_factor,
9496 bic.quantity_related,
9497 bic.so_basis,
9498 bic.optional,
9499 bic.mutually_exclusive_options,
9500 bic.include_in_cost_rollup,
9501 bic.check_atp,
9502 msi.bom_item_type,
9503 to_char(NULL) AS from_end_item_unit_number,
9504 to_char(NULL) AS to_end_item_unit_number,
9505 bic.optional_on_model,
9506 --BUGFIX 2740820
9507 bic.parent_bill_seq_id, --BUGFIX 2740820
9508 bic.model_comp_seq_id,
9509 --BUGFIX 2740820
9510 bic.plan_level, --BUGFIX 2740820
9511 bic.enforce_int_requirements,
9512 -- Either Fixed or Floating rev, the components will be from when its created, current item rev
9513 l_current_item_rev_id,
9514 -- Minor rev is not supported. Populated the first minor rev
9515 0,
9516 bic.component_item_id,
9517 to_org_id,
9518 bic.auto_request_material,
9519 -- Bug 3662214 : Added following 4 fields
9520 bic.suggested_vendor_name,
9521 bic.vendor_id,
9522 bic.unit_price,
9523 eco_end_item_rev_id,
9524 CASE
9525 WHEN bic.disable_date IS NOT NULL
9526 AND EXISTS
9527 (
9528 SELECT tmirb.revision_id
9529 FROM mtl_item_revisions_b tmirb
9530 WHERE tmirb.inventory_item_id = to_item_id
9531 AND tmirb.organization_id = to_org_id
9532 AND tmirb.revision = get_current_item_rev(from_item_id, from_org_id, bic.disable_date)
9533 )
9534 AND EXISTS
9535 (
9536 SELECT mirb.REVISION
9537 FROM MTL_ITEM_REVISIONS_B mirb
9538 WHERE mirb.REVISION_ID = eco_end_item_rev_id
9539 AND mirb.revision < get_current_item_rev(from_item_id, from_org_id, bic.disable_date)
9540 )
9541 THEN
9542 (
9543 SELECT tmirb.revision_id
9544 FROM mtl_item_revisions_b tmirb
9545 WHERE tmirb.inventory_item_id = to_item_id
9546 AND tmirb.organization_id = to_org_id
9547 AND tmirb.revision = get_current_item_rev(from_item_id, from_org_id, bic.disable_date)
9548 )
9549 ELSE
9550 to_number(NULL)
9551 END AS to_end_item_rev_id,
9552 -- For Minor rev Ids
9553 0 AS from_end_item_minor_rev_id,
9554 0 AS to_end_item_minor_rev_id,
9555 (
9556 SELECT tmirb.revision_id
9557 FROM mtl_item_revisions_b fmirb,
9558 mtl_item_revisions_b tmirb
9559 WHERE tmirb.inventory_item_id = bic.component_item_id
9560 AND tmirb.organization_id = to_org_id
9561 AND tmirb.revision = fmirb.revision
9562 AND fmirb.revision_id = bic.component_item_revision_id
9563 ) AS component_item_revision_id,
9564 CASE
9565 WHEN bic.component_item_revision_id IS NULL
9566 THEN to_number(NULL)
9567 ELSE
9568 -- Minor revision is not supported
9569 0
9570 END AS component_minor_revision_id,
9571 bic.basis_type,
9572 CASE
9573 WHEN l_fixed_rev IS NOT NULL
9574 -- For fixed rev copy the components as fixed rev
9575 THEN l_to_item_rev_id
9576 ELSE
9577 to_number(NULL)
9578 END AS to_object_revision_id,
9579 CASE
9580 WHEN l_fixed_rev IS NOT NULL
9581 THEN 0
9582 ELSE
9583 to_number(NULL)
9584 END AS to_minor_revision_id
9585 FROM bom_components_b bic,
9586 mtl_system_items msi,
9587 MTL_SYSTEM_ITEMS AA , -- Added corresponding to Bug 6510185
9588 bom_copy_explosions_v bev
9589 WHERE bic.bill_sequence_id = x_from_sequence_id
9590 AND bic.component_item_id = msi.inventory_item_id
9591 AND bic.component_item_id <> to_item_id
9592 AND NVL (bic.eco_for_production, 2) = 2
9593 AND msi.organization_id = to_org_id
9594 AND MSI.inventory_item_id = AA.inventory_item_id -- Added corresponding to Bug 6510185
9595 AND AA.organization_id = from_org_id -- Added corresponding to Bug 6510185
9596 AND msi.bom_enabled_flag = 'Y' -- Added for the bug 14238677
9597 AND ((direction = eng_to_bom
9598 AND msi.eng_item_flag = 'N')
9599 OR (direction <> eng_to_bom)
9600 )
9601 AND ((base_item_flag = -1
9602 AND itm_type = 4
9603 AND msi.bom_item_type = 4
9604 )
9605 OR base_item_flag <> -1
9606 OR itm_type <> 4
9607 )
9608 AND ((bic.implementation_date IS NOT NULL)
9609 OR (bic.implementation_date IS NULL
9610 AND bic.change_notice = context_eco
9611 AND ( bic.acd_type = 1 OR bic.acd_type = 2 )
9612 )
9613 )
9614 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
9615 (
9616 SELECT 1
9617 FROM bom_components_b bcb
9618 WHERE bcb.old_component_sequence_id = bic.component_sequence_id
9619 AND bcb.change_notice = context_eco
9620 AND bcb.acd_type = 3
9621 AND bcb.effectivity_date <= x_effectivity_date
9622 AND bcb.implementation_date IS NULL
9623 AND bcb.bill_sequence_id = bic.bill_sequence_id
9624 )
9625 AND 'T' = bev.access_flag
9626 AND 'T' =
9627 bom_security_pub.check_item_privilege
9628 ('EGO_VIEW_ITEM',
9629 TO_CHAR (bic.component_item_id),
9630 TO_CHAR (to_org_id),
9631 bom_exploder_pub.get_ego_user
9632 )
9633 AND bic.component_sequence_id = bev.component_sequence_id
9634 AND bev.bill_sequence_id = from_sequence_id
9635 AND bev.parent_sort_order = p_parent_sort_order
9636 AND NOT EXISTS (
9637 SELECT 1
9638 FROM bom_copy_structure_actions bcsa
9639 WHERE bcsa.component_sequence_id =
9640 bic.component_sequence_id
9641 AND bcsa.copy_request_id = p_copy_request_id
9642 AND bcsa.organization_id = to_org_id
9643 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
9644 -- Component Action is exclude or enable
9645 -- we need not copy.
9646 )
9647 AND ( ( p_cpy_past_eff_comps = 'Y' AND bev.effectivity_date <= rev_date) -- For first revised item we can have past eff comps as eff on the target date
9648 OR ( p_cpy_past_eff_comps = 'N' AND bev.effectivity_date = rev_date )
9649 )
9650 AND EXISTS
9651 (
9652 SELECT 1
9653 FROM fnd_lookup_values_vl flv,
9654 ego_criteria_templates_v ectv,
9655 ego_criteria_v ecv,
9656 mtl_system_items_b msibs -- to assembly item
9657 WHERE ecv.customization_application_id = 702
9658 AND ecv.region_application_id = 702
9659 AND ecv.region_code = 'BOM_ITEM_TYPE_REGION'
9660 AND ecv.customization_code = ectv.customization_code
9661 AND flv.lookup_type = 'ITEM_TYPE'
9662 AND flv.enabled_flag = 'Y'
9663 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
9664 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
9665 AND flv.lookup_code = ectv.classification1
9666 AND ectv.customization_application_id = 702
9667 AND ectv.region_application_id = 702
9668 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
9669 AND flv.lookup_code = msibs.item_type
9670 AND msibs.inventory_item_id = to_item_id
9671 AND msibs.organization_id = to_org_id
9672 AND ecv.value_varchar2 = msi.item_type -- Component
9673 UNION ALL
9674 SELECT 1
9675 FROM DUAL
9676 WHERE NOT EXISTS
9677 (
9678 SELECT 1
9679 FROM fnd_lookup_values_vl flv,
9680 ego_criteria_templates_v ectv,
9681 mtl_system_items_b msibs -- to assembly item
9682 WHERE flv.lookup_type = 'ITEM_TYPE'
9683 AND flv.enabled_flag = 'Y'
9684 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
9685 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
9686 AND flv.lookup_code = ectv.classification1
9687 AND ectv.customization_application_id = 702
9688 AND ectv.region_application_id = 702
9689 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
9690 AND flv.lookup_code = msibs.item_type
9691 AND msibs.inventory_item_id = to_item_id
9692 AND msibs.organization_id = to_org_id
9693 )
9694 );
9695 END IF;
9696
9697
9698 --Turn on the trigger BOMTBICX
9699 bom_globals.g_skip_bomtbicx := 'N';
9700
9701 OPEN l_from_to_comps_csr (from_sequence_id, to_sequence_id, l_last_copied_comp_seq_id);
9702
9703 FETCH l_from_to_comps_csr
9704 BULK COLLECT INTO l_from_comps,
9705 l_to_comps;
9706
9707 IF l_from_to_comps_csr%ISOPEN THEN
9708 CLOSE l_from_to_comps_csr;
9709 END IF;
9710
9711 --Start copying user attrs
9712 IF l_from_comps.FIRST IS NOT NULL
9713 THEN
9714 l_index := l_from_comps.FIRST;
9715 WHILE l_index IS NOT NULL
9716 LOOP
9717 l_src_pk_col_name_val_pairs :=
9718 ego_col_name_value_pair_array
9719 (ego_col_name_value_pair_obj ('COMPONENT_SEQUENCE_ID',
9720 TO_CHAR (l_from_comps (l_index))
9721 ),
9722 ego_col_name_value_pair_obj ('BILL_SEQUENCE_ID',
9723 TO_CHAR (from_sequence_id)
9724 )
9725 );
9726 l_dest_pk_col_name_val_pairs :=
9727 ego_col_name_value_pair_array
9728 (ego_col_name_value_pair_obj ('COMPONENT_SEQUENCE_ID',
9729 TO_CHAR (l_to_comps (l_index))
9730 ),
9731 ego_col_name_value_pair_obj ('BILL_SEQUENCE_ID',
9732 TO_CHAR (to_sequence_id)
9733 )
9734 );
9735 l_new_str_type :=
9736 ego_col_name_value_pair_array
9737 (ego_col_name_value_pair_obj ('STRUCTURE_TYPE_ID',
9738 TO_CHAR (l_str_type)
9739 )
9740 );
9741
9742 l_old_dtlevel_col_value_pairs := EGO_COL_NAME_VALUE_PAIR_ARRAY(EGO_COL_NAME_VALUE_PAIR_OBJ( 'CONTEXT_ID', ''));
9743 l_new_dtlevel_col_value_pairs := EGO_COL_NAME_VALUE_PAIR_ARRAY(EGO_COL_NAME_VALUE_PAIR_OBJ( 'CONTEXT_ID', ''));
9744
9745 ego_user_attrs_data_pvt.copy_user_attrs_data
9746 (p_api_version => 1.0,
9747 p_application_id => bom_application_id,
9748 p_object_name => 'BOM_COMPONENTS',
9749 p_old_pk_col_value_pairs => l_src_pk_col_name_val_pairs,
9750 p_new_pk_col_value_pairs => l_dest_pk_col_name_val_pairs,
9751 p_new_cc_col_value_pairs => l_new_str_type,
9752 p_old_data_level_id => l_data_level_id_comp,
9753 p_new_data_level_id => l_data_level_id_comp,
9754 p_old_dtlevel_col_value_pairs => l_old_dtlevel_col_value_pairs,
9755 p_new_dtlevel_col_value_pairs => l_new_dtlevel_col_value_pairs,
9756 x_return_status => l_return_status,
9757 x_errorcode => l_errorcode,
9758 x_msg_count => l_msg_count,
9759 x_msg_data => l_msg_data
9760 );
9761 l_index := l_from_comps.next(l_index);
9762 -- Mark the components as processed if the components are added to existing eco
9763 -- and the explosion is in context of that eco
9764 IF e_change_notice IS NOT NULL AND e_change_notice = context_eco
9765 THEN
9766 FOR l_mark_comp_rec IN l_mark_components_csr(e_change_notice, from_org_id, from_sequence_id)
9767 LOOP
9768 eng_propagation_log_util.mark_component_change_transfer
9769 (
9770 p_api_version => 1.0
9771 ,p_init_msg_list => FND_API.G_FALSE
9772 ,p_commit => FND_API.G_FALSE
9773 ,x_return_status => l_return_status
9774 ,x_msg_count => l_msg_count
9775 ,x_msg_data => l_msg_data
9776 ,p_change_id => l_mark_comp_rec.change_id
9777 ,p_revised_item_sequence_id => rev_item_seq_id
9778 ,p_component_sequence_id => l_mark_comp_rec.component_sequence_id
9779 ,p_local_organization_id => to_org_id
9780 );
9781 END LOOP;
9782 END IF; -- IF e_change_notice = context_eco
9783
9784 END LOOP;
9785 END IF;
9786
9787 SELECT COUNT (*)
9788 INTO l_no_access_comp_cnt
9789 FROM bom_components_b bcb,
9790 mtl_system_items_b_kfv msbk1,
9791 bom_copy_explosions_v bev
9792 WHERE bcb.bill_sequence_id = x_from_sequence_id
9793 AND bcb.component_item_id = msbk1.inventory_item_id
9794 AND bcb.component_item_id <> to_item_id
9795 AND 'T' <>
9796 bom_security_pub.check_item_privilege
9797 ('EGO_VIEW_ITEM',
9798 TO_CHAR (bcb.component_item_id),
9799 TO_CHAR (from_org_id),
9800 bom_exploder_pub.get_ego_user
9801 )
9802 AND msbk1.organization_id = from_org_id
9803 AND bcb.component_sequence_id = bev.component_sequence_id
9804 AND bev.bill_sequence_id = from_sequence_id
9805 AND bev.parent_sort_order = p_parent_sort_order
9806 AND ((bcb.implementation_date IS NOT NULL)
9807 OR (bcb.implementation_date IS NULL
9808 AND bcb.change_notice = context_eco
9809 AND ( bcb.acd_type = 1 OR bcb.acd_type = 2 )
9810 )
9811 )
9812 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
9813 (
9814 SELECT 1
9815 FROM bom_components_b bcb1
9816 WHERE bcb1.old_component_sequence_id = bcb.component_sequence_id
9817 AND bcb1.change_notice = context_eco
9818 AND bcb1.acd_type = 3
9819 AND bcb1.effectivity_date <= x_effectivity_date
9820 AND bcb1.implementation_date IS NULL
9821 AND bcb1.bill_sequence_id = bcb.bill_sequence_id
9822 )
9823 AND NOT EXISTS (
9824 SELECT 1
9825 FROM bom_copy_structure_actions bcsa
9826 WHERE bcsa.component_sequence_id =
9827 bcb.component_sequence_id
9828 AND bcsa.copy_request_id = p_copy_request_id
9829 AND bcsa.organization_id = to_org_id
9830 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
9831 -- Component Action is exclude or enable
9832 -- we need not copy.
9833 )
9834 AND ( ( l_from_eff_ctrl = 1
9835 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.effectivity_date <= rev_date) -- For first revised item we can have past eff comps as eff on the target date
9836 OR ( p_cpy_past_eff_comps = 'N' AND bcb.effectivity_date = rev_date ) )
9837 ) OR
9838 ( ( l_from_eff_ctrl = 2 OR l_from_eff_ctrl = 3 )
9839 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.from_end_item_unit_number <= unit_number)
9840 OR ( p_cpy_past_eff_comps = 'N' AND bcb.from_end_item_unit_number = unit_number ) )
9841 ) OR
9842 ( l_from_eff_ctrl = 4
9843 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.from_end_item_rev_id <= p_end_item_rev_id)
9844 OR ( p_cpy_past_eff_comps = 'N' AND bcb.from_end_item_rev_id = p_end_item_rev_id ) )
9845 )
9846 );
9847
9848 IF l_no_access_comp_cnt > 0
9849 THEN
9850 INSERT INTO mtl_interface_errors
9851 (unique_id,
9852 organization_id,
9853 transaction_id,
9854 table_name,
9855 column_name,
9856 error_message,
9857 bo_identifier,
9858 last_update_date,
9859 last_updated_by,
9860 creation_date,
9861 created_by,
9862 message_type,
9863 request_id,
9864 program_application_id,
9865 program_id,
9866 program_update_date
9867 )
9868 SELECT from_item_id,
9869 to_org_id,
9870 p_copy_request_id,
9871 NULL,
9872 get_current_item_rev (from_item_id,
9873 from_org_id,
9874 rev_date
9875 ),
9876 get_cnt_message ('BOM_COPY_ERR_COMP_NO_ACCESS',
9877 msbk1.concatenated_segments,
9878 TO_NUMBER (l_no_access_comp_cnt)
9879 ),
9880 'BOM_COPY',
9881 SYSDATE,
9882 user_id,
9883 SYSDATE,
9884 user_id,
9885 'E',
9886 fnd_global.conc_request_id,
9887 NULL,
9888 fnd_global.conc_program_id,
9889 sysdate
9890 FROM bom_components_b bcb,
9891 mtl_system_items_b_kfv msbk1,
9892 bom_copy_explosions_v bev
9893 WHERE msbk1.inventory_item_id = from_item_id
9894 AND msbk1.organization_id = from_org_id
9895 AND bcb.component_sequence_id = bev.component_sequence_id
9896 AND bev.bill_sequence_id = from_sequence_id
9897 AND bev.parent_sort_order = p_parent_sort_order
9898 AND ( ( l_from_eff_ctrl = 1
9899 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.effectivity_date <= rev_date) -- For first revised item we can have past eff comps as eff on the target date
9900 OR ( p_cpy_past_eff_comps = 'N' AND bcb.effectivity_date = rev_date ) )
9901 ) OR
9902 ( ( l_from_eff_ctrl = 2 OR l_from_eff_ctrl = 3 )
9903 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.from_end_item_unit_number <= unit_number)
9904 OR ( p_cpy_past_eff_comps = 'N' AND bcb.from_end_item_unit_number = unit_number ) )
9905 ) OR
9906 ( l_from_eff_ctrl = 4
9907 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.from_end_item_rev_id <= p_end_item_rev_id)
9908 OR ( p_cpy_past_eff_comps = 'N' AND bcb.from_end_item_rev_id = p_end_item_rev_id ) )
9909 )
9910 );
9911
9912 END IF;
9913
9914 IF (from_org_id <> to_org_id)
9915 THEN
9916 SELECT COUNT (*)
9917 INTO l_no_access_comp_cnt
9918 FROM bom_components_b bcb,
9919 mtl_system_items_b_kfv msbk1,
9920 bom_copy_explosions_v bev
9921 WHERE bcb.bill_sequence_id = x_from_sequence_id
9922 AND bcb.component_item_id = msbk1.inventory_item_id
9923 AND bcb.component_item_id <> to_item_id
9924 AND 'T' <>
9925 bom_security_pub.check_item_privilege
9926 ('EGO_VIEW_ITEM',
9927 TO_CHAR (bcb.component_item_id),
9928 TO_CHAR (to_org_id),
9929 bom_exploder_pub.get_ego_user
9930 )
9931 AND msbk1.organization_id = from_org_id
9932 AND bcb.component_sequence_id = bev.component_sequence_id
9933 AND bev.bill_sequence_id = from_sequence_id
9934 AND bev.parent_sort_order = p_parent_sort_order
9935 AND ((bcb.implementation_date IS NOT NULL)
9936 OR (bcb.implementation_date IS NULL
9937 AND bcb.change_notice = context_eco
9938 AND ( bcb.acd_type = 1 OR bcb.acd_type = 2 )
9939 )
9940 )
9941 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
9942 (
9943 SELECT 1
9944 FROM bom_components_b bcb1
9945 WHERE bcb1.old_component_sequence_id = bcb.component_sequence_id
9946 AND bcb1.change_notice = context_eco
9947 AND bcb1.acd_type = 3
9948 AND bcb1.effectivity_date <= x_effectivity_date
9949 AND bcb1.implementation_date IS NULL
9950 AND bcb1.bill_sequence_id = bcb.bill_sequence_id
9951 )
9952 AND NOT EXISTS (
9953 SELECT 1
9954 FROM bom_copy_structure_actions bcsa
9955 WHERE bcsa.component_sequence_id =
9956 bcb.component_sequence_id
9957 AND bcsa.copy_request_id = p_copy_request_id
9958 AND bcsa.organization_id = to_org_id
9959 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
9960 -- Component Action is exclude or enable
9961 -- we need not copy.
9962 )
9963 AND ( ( l_from_eff_ctrl = 1
9964 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.effectivity_date <= rev_date) -- For first revised item we can have past eff comps as eff on the target date
9965 OR ( p_cpy_past_eff_comps = 'N' AND bcb.effectivity_date = rev_date ) )
9966 ) OR
9967 ( ( l_from_eff_ctrl = 2 OR l_from_eff_ctrl = 3 )
9968 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.from_end_item_unit_number <= unit_number)
9969 OR ( p_cpy_past_eff_comps = 'N' AND bcb.from_end_item_unit_number = unit_number ) )
9970 ) OR
9971 ( l_from_eff_ctrl = 4
9972 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.from_end_item_rev_id <= p_end_item_rev_id)
9973 OR ( p_cpy_past_eff_comps = 'N' AND bcb.from_end_item_rev_id = p_end_item_rev_id ) )
9974 )
9975 );
9976
9977 IF l_no_access_comp_cnt > 0
9978 THEN
9979 INSERT INTO mtl_interface_errors
9980 (unique_id,
9981 organization_id,
9982 transaction_id,
9983 table_name,
9984 column_name,
9985 error_message,
9986 bo_identifier,
9987 last_update_date,
9988 last_updated_by,
9989 creation_date,
9990 created_by,
9991 message_type,
9992 request_id,
9993 program_application_id,
9994 program_id,
9995 program_update_date
9996 )
9997 SELECT from_item_id,
9998 to_org_id,
9999 p_copy_request_id,
10000 NULL,
10001 get_current_item_rev (from_item_id,
10002 from_org_id,
10003 rev_date
10004 ),
10005 get_cnt_message ('BOM_COPY_ERR_CMPDEST_NO_ACCESS',
10006 msbk1.concatenated_segments,
10007 TO_NUMBER (l_no_access_comp_cnt)
10008 ),
10009 'BOM_COPY',
10010 SYSDATE,
10011 user_id,
10012 SYSDATE,
10013 user_id,
10014 'E',
10015 fnd_global.conc_request_id,
10016 NULL,
10017 fnd_global.conc_program_id,
10018 sysdate
10019 FROM bom_components_b bcb,
10020 mtl_system_items_b_kfv msbk1,
10021 bom_copy_explosions_v bev
10022 WHERE msbk1.inventory_item_id = from_item_id
10023 AND msbk1.organization_id = from_org_id
10024 AND bcb.component_sequence_id = bev.component_sequence_id
10025 AND bev.bill_sequence_id = from_sequence_id
10026 AND bev.parent_sort_order = p_parent_sort_order
10027 AND ( ( l_from_eff_ctrl = 1
10028 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.effectivity_date <= rev_date) -- For first revised item we can have past eff comps as eff on the target date
10029 OR ( p_cpy_past_eff_comps = 'N' AND bcb.effectivity_date = rev_date ) )
10030 ) OR
10031 ( ( l_from_eff_ctrl = 2 OR l_from_eff_ctrl = 3 )
10032 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.from_end_item_unit_number <= unit_number)
10033 OR ( p_cpy_past_eff_comps = 'N' AND bcb.from_end_item_unit_number = unit_number ) )
10034 ) OR
10035 ( l_from_eff_ctrl = 4
10036 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.from_end_item_rev_id <= p_end_item_rev_id)
10037 OR ( p_cpy_past_eff_comps = 'N' AND bcb.from_end_item_rev_id = p_end_item_rev_id ) )
10038 )
10039 );
10040 END IF;
10041 END IF;
10042
10043 -- Insert Error messages to MTL_INTERFACE_ERRORS for each error while copying
10044 INSERT INTO mtl_interface_errors
10045 (unique_id,
10046 organization_id,
10047 transaction_id,
10048 table_name,
10049 column_name,
10050 error_message,
10051 bo_identifier,
10052 last_update_date,
10053 last_updated_by,
10054 creation_date,
10055 created_by,
10056 message_type,
10057 request_id,
10058 program_application_id,
10059 program_id,
10060 program_update_date
10061 )
10062 SELECT bcb.component_item_id,
10063 to_org_id,
10064 p_copy_request_id,
10065 NULL,
10066 get_current_item_rev (bcb.component_item_id,
10067 from_org_id,
10068 rev_date
10069 ),
10070 GET_MESSAGE ('BOM_COPY_ERR_ENG_COMP_MFG_BILL',
10071 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
10072 bom_globals.get_item_name(to_item_id, from_org_id)
10073 ),
10074 'BOM_COPY',
10075 SYSDATE,
10076 user_id,
10077 SYSDATE,
10078 user_id,
10079 'E',
10080 fnd_global.conc_request_id,
10081 NULL,
10082 fnd_global.conc_program_id,
10083 sysdate
10084 FROM bom_components_b bcb,
10085 mtl_system_items_b msib1, -- component
10086 bom_copy_explosions_v bev
10087 WHERE bcb.bill_sequence_id = x_from_sequence_id
10088 AND bcb.component_item_id = msib1.inventory_item_id
10089 AND bcb.component_item_id <> to_item_id
10090 AND msib1.organization_id = to_org_id
10091 AND (direction = eng_to_bom
10092 AND msib1.eng_item_flag = 'Y')
10093 AND bcb.component_sequence_id = bev.component_sequence_id
10094 AND bev.bill_sequence_id = from_sequence_id
10095 AND bev.parent_sort_order = p_parent_sort_order
10096 AND ((bcb.implementation_date IS NOT NULL)
10097 OR (bcb.implementation_date IS NULL
10098 AND bcb.change_notice = context_eco
10099 AND ( bcb.acd_type = 1 OR bcb.acd_type = 2 )
10100 )
10101 )
10102 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
10103 (
10104 SELECT 1
10105 FROM bom_components_b bcb1
10106 WHERE bcb1.old_component_sequence_id = bcb.component_sequence_id
10107 AND bcb1.change_notice = context_eco
10108 AND bcb1.acd_type = 3
10109 AND bcb1.effectivity_date <= x_effectivity_date
10110 AND bcb1.implementation_date IS NULL
10111 AND bcb1.bill_sequence_id = bcb.bill_sequence_id
10112 )
10113 AND 'T' = bev.access_flag
10114 AND 'T' =
10115 bom_security_pub.check_item_privilege
10116 ('EGO_VIEW_ITEM',
10117 TO_CHAR (bcb.component_item_id),
10118 TO_CHAR (to_org_id),
10119 bom_exploder_pub.get_ego_user
10120 )
10121 AND NOT EXISTS (
10122 SELECT 1
10123 FROM bom_copy_structure_actions bcsa
10124 WHERE bcsa.component_sequence_id =
10125 bcb.component_sequence_id
10126 AND bcsa.copy_request_id = p_copy_request_id
10127 AND bcsa.organization_id = to_org_id
10128 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
10129 -- Component Action is exclude or enable
10130 -- we need not copy.
10131 )
10132 AND ( ( l_from_eff_ctrl = 1
10133 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.effectivity_date <= rev_date) -- For first revised item we can have past eff comps as eff on the target date
10134 OR ( p_cpy_past_eff_comps = 'N' AND bcb.effectivity_date = rev_date ) )
10135 ) OR
10136 ( ( l_from_eff_ctrl = 2 OR l_from_eff_ctrl = 3 )
10137 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.from_end_item_unit_number <= unit_number)
10138 OR ( p_cpy_past_eff_comps = 'N' AND bcb.from_end_item_unit_number = unit_number ) )
10139 ) OR
10140 ( l_from_eff_ctrl = 4
10141 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.from_end_item_rev_id <= p_end_item_rev_id)
10142 OR ( p_cpy_past_eff_comps = 'N' AND bcb.from_end_item_rev_id = p_end_item_rev_id ) )
10143 )
10144 );
10145
10146 INSERT INTO mtl_interface_errors
10147 (unique_id,
10148 organization_id,
10149 transaction_id,
10150 table_name,
10151 column_name,
10152 error_message,
10153 bo_identifier,
10154 last_update_date,
10155 last_updated_by,
10156 creation_date,
10157 created_by,
10158 message_type,
10159 request_id,
10160 program_application_id,
10161 program_id,
10162 program_update_date
10163 )
10164 SELECT bcb.component_item_id,
10165 to_org_id,
10166 p_copy_request_id,
10167 NULL,
10168 get_current_item_rev (bcb.component_item_id,
10169 from_org_id,
10170 rev_date
10171 ),
10172 GET_MESSAGE ('BOM_COPY_ERR_COMP_FOR_WIP_JOB',
10173 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
10174 bom_globals.get_item_name(to_item_id, from_org_id)
10175 ),
10176 'BOM_COPY',
10177 SYSDATE,
10178 user_id,
10179 SYSDATE,
10180 user_id,
10181 'E',
10182 fnd_global.conc_request_id,
10183 NULL,
10184 fnd_global.conc_program_id,
10185 sysdate
10186 FROM bom_components_b bcb,
10187 bom_copy_explosions_v bev
10188 WHERE bcb.bill_sequence_id = x_from_sequence_id
10189 AND bcb.component_item_id <> to_item_id
10190 AND bcb.eco_for_production <> 2
10191 AND bcb.component_sequence_id = bev.component_sequence_id
10192 AND bev.bill_sequence_id = from_sequence_id
10193 AND bev.parent_sort_order = p_parent_sort_order
10194 AND ((bcb.implementation_date IS NOT NULL)
10195 OR (bcb.implementation_date IS NULL
10196 AND bcb.change_notice = context_eco
10197 AND ( bcb.acd_type = 1 OR bcb.acd_type = 2 )
10198 )
10199 )
10200 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
10201 (
10202 SELECT 1
10203 FROM bom_components_b bcb1
10204 WHERE bcb1.old_component_sequence_id = bcb.component_sequence_id
10205 AND bcb1.change_notice = context_eco
10206 AND bcb1.acd_type = 3
10207 AND bcb1.effectivity_date <= x_effectivity_date
10208 AND bcb1.implementation_date IS NULL
10209 AND bcb1.bill_sequence_id = bcb.bill_sequence_id
10210 )
10211 AND 'T' = bev.access_flag
10212 AND 'T' =
10213 bom_security_pub.check_item_privilege
10214 ('EGO_VIEW_ITEM',
10215 TO_CHAR (bcb.component_item_id),
10216 TO_CHAR (to_org_id),
10217 bom_exploder_pub.get_ego_user
10218 )
10219 AND NOT EXISTS (
10220 SELECT 1
10221 FROM bom_copy_structure_actions bcsa
10222 WHERE bcsa.component_sequence_id =
10223 bcb.component_sequence_id
10224 AND bcsa.copy_request_id = p_copy_request_id
10225 AND bcsa.organization_id = to_org_id
10226 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
10227 -- Component Action is exclude or enable
10228 -- we need not copy.
10229 )
10230 AND ( ( l_from_eff_ctrl = 1
10231 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.effectivity_date <= rev_date) -- For first revised item we can have past eff comps as eff on the target date
10232 OR ( p_cpy_past_eff_comps = 'N' AND bcb.effectivity_date = rev_date ) )
10233 ) OR
10234 ( ( l_from_eff_ctrl = 2 OR l_from_eff_ctrl = 3 )
10235 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.from_end_item_unit_number <= unit_number)
10236 OR ( p_cpy_past_eff_comps = 'N' AND bcb.from_end_item_unit_number = unit_number ) )
10237 ) OR
10238 ( l_from_eff_ctrl = 4
10239 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.from_end_item_rev_id <= p_end_item_rev_id)
10240 OR ( p_cpy_past_eff_comps = 'N' AND bcb.from_end_item_rev_id = p_end_item_rev_id ) )
10241 )
10242 );
10243
10244
10245 INSERT INTO mtl_interface_errors
10246 (unique_id,
10247 organization_id,
10248 transaction_id,
10249 table_name,
10250 column_name,
10251 error_message,
10252 bo_identifier,
10253 last_update_date,
10254 last_updated_by,
10255 creation_date,
10256 created_by,
10257 message_type,
10258 request_id,
10259 program_application_id,
10260 program_id,
10261 program_update_date
10262 )
10263 SELECT bcb.component_item_id,
10264 to_org_id,
10265 p_copy_request_id,
10266 NULL,
10267 get_current_item_rev (bcb.component_item_id,
10268 from_org_id,
10269 rev_date
10270 ),
10271 GET_MESSAGE ('BOM_COPY_ERR_COMP_NOT_STANDARD',
10272 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
10273 bom_globals.get_item_name(to_item_id, from_org_id)
10274 ),
10275 'BOM_COPY',
10276 SYSDATE,
10277 user_id,
10278 SYSDATE,
10279 user_id,
10280 'E',
10281 fnd_global.conc_request_id,
10282 NULL,
10283 fnd_global.conc_program_id,
10284 sysdate
10285 FROM bom_components_b bcb,
10286 mtl_system_items_b msib1,
10287 bom_copy_explosions_v bev
10288 WHERE bcb.bill_sequence_id = x_from_sequence_id
10289 AND bcb.component_item_id = msib1.inventory_item_id
10290 AND bcb.component_item_id <> to_item_id
10291 AND bcb.implementation_date IS NOT NULL
10292 AND msib1.organization_id = to_org_id
10293 AND bcb.component_sequence_id = bev.component_sequence_id
10294 AND bev.bill_sequence_id = from_sequence_id
10295 AND bev.parent_sort_order = p_parent_sort_order
10296 AND ((bcb.implementation_date IS NOT NULL)
10297 OR (bcb.implementation_date IS NULL
10298 AND bcb.change_notice = context_eco
10299 AND ( bcb.acd_type = 1 OR bcb.acd_type = 2 )
10300 )
10301 )
10302 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
10303 (
10304 SELECT 1
10305 FROM bom_components_b bcb1
10306 WHERE bcb1.old_component_sequence_id = bcb.component_sequence_id
10307 AND bcb1.change_notice = context_eco
10308 AND bcb1.acd_type = 3
10309 AND bcb1.effectivity_date <= x_effectivity_date
10310 AND bcb1.implementation_date IS NULL
10311 AND bcb1.bill_sequence_id = bcb.bill_sequence_id
10312 )
10313 AND 'T' = bev.access_flag
10314 AND 'T' =
10315 bom_security_pub.check_item_privilege
10316 ('EGO_VIEW_ITEM',
10317 TO_CHAR (bcb.component_item_id),
10318 TO_CHAR (to_org_id),
10319 bom_exploder_pub.get_ego_user
10320 )
10321 AND NOT EXISTS (
10322 SELECT 1
10323 FROM bom_copy_structure_actions bcsa
10324 WHERE bcsa.component_sequence_id =
10325 bcb.component_sequence_id
10326 AND bcsa.copy_request_id = p_copy_request_id
10327 AND bcsa.organization_id = to_org_id
10328 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
10329 -- Component Action is exclude or enable
10330 -- we need not copy.
10331 )
10332 AND (base_item_flag = -1
10333 AND itm_type = 4
10334 AND msib1.bom_item_type <> 4
10335 )
10336 AND ( ( l_from_eff_ctrl = 1
10337 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.effectivity_date <= rev_date) -- For first revised item we can have past eff comps as eff on the target date
10338 OR ( p_cpy_past_eff_comps = 'N' AND bcb.effectivity_date = rev_date ) )
10339 ) OR
10340 ( ( l_from_eff_ctrl = 2 OR l_from_eff_ctrl = 3 )
10341 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.from_end_item_unit_number <= unit_number)
10342 OR ( p_cpy_past_eff_comps = 'N' AND bcb.from_end_item_unit_number = unit_number ) )
10343 ) OR
10344 ( l_from_eff_ctrl = 4
10345 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.from_end_item_rev_id <= p_end_item_rev_id)
10346 OR ( p_cpy_past_eff_comps = 'N' AND bcb.from_end_item_rev_id = p_end_item_rev_id ) )
10347 )
10348 );
10349
10350 INSERT INTO mtl_interface_errors
10351 (unique_id,
10352 organization_id,
10353 transaction_id,
10354 table_name,
10355 column_name,
10356 error_message,
10357 bo_identifier,
10358 last_update_date,
10359 last_updated_by,
10360 creation_date,
10361 created_by,
10362 message_type,
10363 request_id,
10364 program_application_id,
10365 program_id,
10366 program_update_date
10367 )
10368 SELECT bcb.component_item_id,
10369 to_org_id,
10370 p_copy_request_id,
10371 NULL,
10372 get_current_item_rev(bcb.component_item_id, from_org_id, rev_date),
10373 check_component_type_rules(bcb.component_item_id,
10374 to_item_id, to_org_id),
10375 'BOM_COPY',
10376 SYSDATE,
10377 user_id,
10378 SYSDATE,
10379 user_id,
10380 'E',
10381 fnd_global.conc_request_id,
10382 NULL,
10383 fnd_global.conc_program_id,
10384 sysdate
10385 FROM bom_components_b bcb,
10386 bom_copy_explosions_v bev
10387 WHERE bcb.bill_sequence_id = x_from_sequence_id
10388 AND bcb.component_item_id <> to_item_id
10389 AND bcb.implementation_date IS NOT NULL
10390 AND bcb.component_sequence_id = bev.component_sequence_id
10391 AND bev.bill_sequence_id = from_sequence_id
10392 AND bev.parent_sort_order = p_parent_sort_order
10393 AND ((bcb.implementation_date IS NOT NULL)
10394 OR (bcb.implementation_date IS NULL
10395 AND bcb.change_notice = context_eco
10396 AND ( bcb.acd_type = 1 OR bcb.acd_type = 2 )
10397 )
10398 )
10399 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
10400 (
10401 SELECT 1
10402 FROM bom_components_b bcb1
10403 WHERE bcb1.old_component_sequence_id = bcb.component_sequence_id
10404 AND bcb1.change_notice = context_eco
10405 AND bcb1.acd_type = 3
10406 AND bcb1.effectivity_date <= x_effectivity_date
10407 AND bcb1.implementation_date IS NULL
10408 AND bcb1.bill_sequence_id = bcb.bill_sequence_id
10409 )
10410 AND 'T' = bev.access_flag
10411 AND 'T' =
10412 bom_security_pub.check_item_privilege
10413 ('EGO_VIEW_ITEM',
10414 TO_CHAR (bcb.component_item_id),
10415 TO_CHAR (to_org_id),
10416 bom_exploder_pub.get_ego_user
10417 )
10418 AND NOT EXISTS (
10419 SELECT 1
10420 FROM bom_copy_structure_actions bcsa
10421 WHERE bcsa.component_sequence_id =
10422 bcb.component_sequence_id
10423 AND bcsa.copy_request_id = p_copy_request_id
10424 AND bcsa.organization_id = to_org_id
10425 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
10426 -- Component Action is exclude or enable
10427 -- we need not copy.
10428 )
10429 AND check_component_type_rules(bcb.component_item_id,
10430 to_item_id, to_org_id) IS NOT NULL -- Component Type validation fails
10431 AND ( ( l_from_eff_ctrl = 1
10432 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.effectivity_date <= rev_date) -- For first revised item we can have past eff comps as eff on the target date
10433 OR ( p_cpy_past_eff_comps = 'N' AND bcb.effectivity_date = rev_date ) )
10434 ) OR
10435 ( ( l_from_eff_ctrl = 2 OR l_from_eff_ctrl = 3 )
10436 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.from_end_item_unit_number <= unit_number)
10437 OR ( p_cpy_past_eff_comps = 'N' AND bcb.from_end_item_unit_number = unit_number ) )
10438 ) OR
10439 ( l_from_eff_ctrl = 4
10440 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.from_end_item_rev_id <= p_end_item_rev_id)
10441 OR ( p_cpy_past_eff_comps = 'N' AND bcb.from_end_item_rev_id = p_end_item_rev_id ) )
10442 )
10443 );
10444
10445 -- For Item Revision Change Policy throw the errors if the components change not allowed
10446 IF l_to_eff_ctrl = 1 THEN
10447 INSERT INTO mtl_interface_errors
10448 (unique_id,
10449 organization_id,
10450 transaction_id,
10451 table_name,
10452 column_name,
10453 error_message,
10454 bo_identifier,
10455 last_update_date,
10456 last_updated_by,
10457 creation_date,
10458 created_by,
10459 message_type,
10460 request_id,
10461 program_application_id,
10462 program_id,
10463 program_update_date
10464 )
10465 SELECT bcb.component_item_id,
10466 to_org_id,
10467 p_copy_request_id,
10468 NULL,
10469 get_current_item_rev (bcb.component_item_id,
10470 from_org_id,
10471 rev_date
10472 ),
10473 GET_MESSAGE (
10474 'BOM_CPY_REV_CHANGE_POLICY_ERR',
10475 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
10476 bom_globals.get_item_name(to_item_id, from_org_id)
10477 ),
10478 'BOM_COPY',
10479 SYSDATE,
10480 user_id,
10481 SYSDATE,
10482 user_id,
10483 'E',
10484 fnd_global.conc_request_id,
10485 NULL,
10486 fnd_global.conc_program_id,
10487 sysdate
10488 FROM bom_components_b bcb,
10489 mtl_system_items_b msib
10490 WHERE bcb.bill_sequence_id = to_sequence_id
10491 AND bcb.component_item_id = msib.inventory_item_id
10492 AND msib.organization_id = to_org_id
10493 AND 'Y' <>
10494 bom_globals.check_change_policy_range(
10495 to_item_id,
10496 to_org_id,
10497 NULL, -- p_start_revision
10498 NULL, -- p_end_revision
10499 NULL, -- p_start_rev_id
10500 NULL, -- p_end_rev_id
10501 bcb.effectivity_date, -- p_effective_date
10502 bcb.disable_date, -- p_disable_date
10503 bom_globals.get_change_policy_val(to_item_id, to_org_id,
10504 BOM_Revisions.Get_Item_Revision_Id_Fn('ALL','ALL',to_org_id,
10505 to_item_id,x_effectivity_date),
10506 null, -- rev id
10507 p_trgt_str_type_id), -- p_current_chg_pol
10508 p_trgt_str_type_id, -- p_structure_type_id
10509 'Y' -- p_use_eco
10510 );
10511 ELSIF l_to_eff_ctrl = 4 THEN
10512 INSERT INTO mtl_interface_errors
10513 (unique_id,
10514 organization_id,
10515 transaction_id,
10516 table_name,
10517 column_name,
10518 error_message,
10519 bo_identifier,
10520 last_update_date,
10521 last_updated_by,
10522 creation_date,
10523 created_by,
10524 message_type,
10525 request_id,
10526 program_application_id,
10527 program_id,
10528 program_update_date
10529 )
10530 SELECT bcb.component_item_id,
10531 to_org_id,
10532 p_copy_request_id,
10533 NULL,
10534 get_current_item_rev (bcb.component_item_id,
10535 from_org_id,
10536 rev_date
10537 ),
10538 GET_MESSAGE (
10539 'BOM_CPY_REV_CHANGE_POLICY_ERR',
10540 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
10541 bom_globals.get_item_name(to_item_id, from_org_id)
10542 ),
10543 'BOM_COPY',
10544 SYSDATE,
10545 user_id,
10546 SYSDATE,
10547 user_id,
10548 'E',
10549 fnd_global.conc_request_id,
10550 NULL,
10551 fnd_global.conc_program_id,
10552 sysdate
10553 FROM bom_components_b bcb,
10554 mtl_system_items_b msib
10555 WHERE bcb.bill_sequence_id = to_sequence_id
10556 AND bcb.component_item_id = msib.inventory_item_id
10557 AND msib.organization_id = to_org_id
10558 AND 'Y' <>
10559 bom_globals.check_change_policy_range(
10560 to_item_id,
10561 to_org_id,
10562 NULL, -- p_start_revision
10563 NULL, -- p_end_revision
10564 bcb.from_end_item_rev_id, -- p_start_rev_id
10565 bcb.to_end_item_rev_id, -- p_end_rev_id
10566 NULL, -- p_effective_date
10567 NULL, -- p_disable_date
10568 bom_globals.get_change_policy_val(to_item_id, to_org_id,
10569 eco_end_item_rev_id,
10570 null, -- rev id
10571 p_trgt_str_type_id), -- p_current_chg_pol
10572 p_trgt_str_type_id, -- p_structure_type_id
10573 'Y' -- p_use_eco
10574 );
10575 END IF;
10576
10577
10578 -- For Rev Eff structure and copy is across org then add the error message for fixed revision components
10579 -- if revision does not exist.
10580 IF l_from_eff_ctrl = 4 AND l_to_eff_ctrl = 4
10581 AND from_org_id <> to_org_id
10582 THEN
10583 INSERT INTO mtl_interface_errors
10584 (unique_id,
10585 organization_id,
10586 transaction_id,
10587 table_name,
10588 column_name,
10589 error_message,
10590 bo_identifier,
10591 last_update_date,
10592 last_updated_by,
10593 creation_date,
10594 created_by,
10595 message_type,
10596 request_id,
10597 program_application_id,
10598 program_id,
10599 program_update_date
10600 )
10601 SELECT bcb.component_item_id,
10602 to_org_id,
10603 p_copy_request_id,
10604 NULL,
10605 get_current_item_rev (bcb.component_item_id,
10606 from_org_id,
10607 rev_date
10608 ),
10609 GET_MESSAGE
10610 ('BOM_COPY_ERR_COMP_REV_DIFF',
10611 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
10612 bom_globals.get_item_name(to_item_id, from_org_id),
10613 get_current_item_rev (bcb.component_item_id,
10614 from_org_id,
10615 rev_date
10616 )
10617 ),
10618 'BOM_COPY',
10619 SYSDATE,
10620 user_id,
10621 SYSDATE,
10622 user_id,
10623 'E',
10624 fnd_global.conc_request_id,
10625 NULL,
10626 fnd_global.conc_program_id,
10627 sysdate
10628 FROM bom_components_b bcb,
10629 bom_copy_explosions_v bev
10630 WHERE bcb.bill_sequence_id = x_from_sequence_id
10631 AND bcb.component_item_id <> to_item_id
10632 AND bcb.implementation_date IS NOT NULL
10633 AND bcb.component_sequence_id = bev.component_sequence_id
10634 -- Error needs to be logged only for fixed revision components
10635 AND bcb.component_item_revision_id IS NOT NULL
10636 AND bev.bill_sequence_id = from_sequence_id
10637 AND bev.parent_sort_order = p_parent_sort_order
10638 AND ((bcb.implementation_date IS NOT NULL)
10639 OR (bcb.implementation_date IS NULL
10640 AND bcb.change_notice = context_eco
10641 AND ( bcb.acd_type = 1 OR bcb.acd_type = 2 )
10642 )
10643 )
10644 AND NOT EXISTS -- Bug 5151332 Disabled components should not get copied in ECO context
10645 (
10646 SELECT 1
10647 FROM bom_components_b bcb1
10648 WHERE bcb1.old_component_sequence_id = bcb.component_sequence_id
10649 AND bcb1.change_notice = context_eco
10650 AND bcb1.acd_type = 3
10651 AND bcb1.effectivity_date <= x_effectivity_date
10652 AND bcb1.implementation_date IS NULL
10653 AND bcb1.bill_sequence_id = bcb.bill_sequence_id
10654 )
10655 AND 'T' = bev.access_flag
10656 AND 'T' =
10657 bom_security_pub.check_item_privilege
10658 ('EGO_VIEW_ITEM',
10659 TO_CHAR (bcb.component_item_id),
10660 TO_CHAR (to_org_id),
10661 bom_exploder_pub.get_ego_user
10662 )
10663 AND NOT EXISTS (
10664 SELECT 1
10665 FROM bom_copy_structure_actions bcsa
10666 WHERE bcsa.component_sequence_id =
10667 bcb.component_sequence_id
10668 AND bcsa.copy_request_id = p_copy_request_id
10669 AND bcsa.organization_id = to_org_id
10670 AND ( bcsa.component_exception_action = 1 OR bcsa.component_exception_action = 3)
10671 -- Component Action is exclude or enable
10672 -- we need not copy.
10673 )
10674 AND NOT EXISTS (
10675 SELECT tmirb.revision_id
10676 FROM mtl_item_revisions_b fmirb,
10677 mtl_item_revisions_b tmirb
10678 WHERE tmirb.inventory_item_id = bcb.component_item_id
10679 AND tmirb.organization_id = to_org_id
10680 AND tmirb.revision = fmirb.revision
10681 AND fmirb.revision_id =
10682 bcb.component_item_revision_id)
10683 AND (
10684 ( l_from_eff_ctrl = 4
10685 AND ( ( p_cpy_past_eff_comps = 'Y' AND bcb.from_end_item_rev_id <= p_end_item_rev_id)
10686 OR ( p_cpy_past_eff_comps = 'N' AND bcb.from_end_item_rev_id = p_end_item_rev_id ) )
10687 )
10688 );
10689
10690 END IF;
10691 copy_comps := SQL%ROWCOUNT;
10692
10693
10694
10695 -- Bug 1825873--determine if routing exists. If not exists, then reset--operation_sequence_num to 1. If exists then, reset only missing--operation_seq_num to 1
10696 BEGIN
10697 sql_stmt_num := 25;
10698
10699 IF ( p_cpy_past_eff_comps = 'Y' ) THEN
10700
10701 SELECT common_routing_sequence_id
10702 INTO to_rtg_seq_id
10703 FROM bom_operational_routings
10704 WHERE organization_id = to_org_id
10705 AND assembly_item_id = to_item_id
10706 AND (NVL (alternate_routing_designator, 'NONE') =
10707 NVL (to_alternate, 'NONE')
10708 OR (to_alternate IS NOT NULL
10709 AND alternate_routing_designator IS NULL
10710 AND NOT EXISTS (
10711 SELECT NULL
10712 FROM bom_operational_routings bor2
10713 WHERE bor2.organization_id = to_org_id
10714 AND bor2.assembly_item_id = to_item_id
10715 AND bor2.alternate_routing_designator =
10716 to_alternate)
10717 )
10718 );
10719 END IF;
10720 EXCEPTION
10721 WHEN NO_DATA_FOUND
10722 THEN
10723 to_rtg_seq_id := -1;
10724 WHEN OTHERS
10725 THEN
10726 err_msg := 'COPY_BILL (' || sql_stmt_num || ') ' || SQLERRM;
10727 fnd_message.set_name ('BOM', 'BOM_SQL_ERR');
10728 fnd_message.set_token ('ENTITY', err_msg);
10729 ROLLBACK TO begin_revised_item_bill_copy;
10730 app_exception.raise_exception;
10731 END;
10732
10733 BEGIN
10734 --Turn off trigger BOMTBICX
10735 bom_globals.g_skip_bomtbicx := 'Y';
10736
10737 IF (to_rtg_seq_id = -1)
10738 THEN
10739 sql_stmt_num := 30;
10740
10741 UPDATE bom_inventory_components
10742 SET operation_seq_num = 1
10743 WHERE bill_sequence_id = to_sequence_id;
10744 ELSE
10745 sql_stmt_num := 35;
10746
10747 UPDATE bom_inventory_components bic
10748 SET operation_seq_num = 1
10749 WHERE bill_sequence_id = to_sequence_id
10750 AND NOT EXISTS (
10751 SELECT NULL
10752 FROM bom_operation_sequences bos
10753 WHERE routing_sequence_id = to_rtg_seq_id
10754 AND bos.operation_seq_num = bic.operation_seq_num);
10755 END IF;
10756
10757 --Turn on trigger BOMTBICX
10758 bom_globals.g_skip_bomtbicx := 'N';
10759 EXCEPTION
10760 WHEN DUP_VAL_ON_INDEX
10761 THEN
10762 RAISE overlap_error;
10763 WHEN OTHERS
10764 THEN
10765 RAISE;
10766 END;
10767
10768 --check for overlapping rows if teh above updated any rows
10769 IF (SQL%FOUND)
10770 THEN
10771 BEGIN
10772 sql_stmt_num := 40;
10773
10774 /* Serial Effectivity Implementation */
10775 IF (bom_eamutil.enabled = 'Y'
10776 AND bom_eamutil.serial_effective_item (item_id => to_item_id,
10777 org_id => to_org_id
10778 ) = 'Y'
10779 )
10780 OR (pjm_unit_eff.enabled = 'Y'
10781 AND pjm_unit_eff.unit_effective_item
10782 (x_item_id => to_item_id,
10783 x_organization_id => to_org_id
10784 ) = 'Y'
10785 )
10786 THEN
10787 SELECT COUNT (*)
10788 INTO dummy
10789 FROM bom_inventory_components bic
10790 WHERE bic.bill_sequence_id = to_sequence_id
10791 AND EXISTS (
10792 SELECT NULL
10793 FROM bom_inventory_components bic2
10794 WHERE bic2.bill_sequence_id = to_sequence_id
10795 AND bic2.ROWID <> bic.ROWID
10796 AND bic2.operation_seq_num = bic.operation_seq_num
10797 AND bic2.component_item_id = bic.component_item_id
10798 AND bic2.disable_date IS NULL
10799 AND (bic.to_end_item_unit_number IS NULL
10800 OR (bic.to_end_item_unit_number >=
10801 bic2.from_end_item_unit_number
10802 )
10803 )
10804 AND (bic2.to_end_item_unit_number IS NULL
10805 OR (bic.from_end_item_unit_number <=
10806 bic2.to_end_item_unit_number
10807 )
10808 ))
10809 AND bic.revised_item_sequence_id = rev_item_seq_id;
10810 ELSIF l_to_eff_ctrl = 4
10811 THEN
10812 SELECT COUNT (*)
10813 INTO dummy
10814 FROM bom_components_b bcb
10815 WHERE bcb.bill_sequence_id = to_sequence_id
10816 AND EXISTS (
10817 SELECT NULL
10818 FROM bom_components_b bcb2
10819 WHERE bcb2.bill_sequence_id = to_sequence_id
10820 AND bcb2.ROWID <> bcb.ROWID
10821 AND bcb2.operation_seq_num = bcb.operation_seq_num
10822 AND bcb2.component_item_id = bcb.component_item_id
10823 AND bcb2.disable_date IS NULL
10824 AND (bcb.to_end_item_rev_id IS NULL
10825 OR (get_minor_rev_code
10826 (bcb.to_end_item_rev_id,
10827 bcb.to_end_item_minor_rev_id
10828 ) >=
10829 get_minor_rev_code
10830 (bcb2.from_end_item_rev_id,
10831 bcb2.from_end_item_minor_rev_id
10832 )
10833 )
10834 )
10835 AND (bcb2.to_end_item_rev_id IS NULL
10836 OR (get_minor_rev_code
10837 (bcb.from_end_item_rev_id,
10838 bcb.from_end_item_minor_rev_id
10839 ) >=
10840 get_minor_rev_code
10841 (bcb2.to_end_item_rev_id,
10842 bcb2.to_end_item_minor_rev_id
10843 )
10844 )
10845 ))
10846 AND bcb.revised_item_sequence_id = rev_item_seq_id;
10847 ELSE
10848 SELECT COUNT (*)
10849 INTO dummy
10850 FROM bom_inventory_components bic
10851 WHERE bic.bill_sequence_id = to_sequence_id
10852 AND EXISTS (
10853 SELECT NULL
10854 FROM bom_inventory_components bic2
10855 WHERE bic2.bill_sequence_id = to_sequence_id
10856 AND bic2.ROWID <> bic.ROWID
10857 AND bic2.operation_seq_num = bic.operation_seq_num
10858 AND bic2.component_item_id = bic.component_item_id
10859 AND bic2.effectivity_date <= bic.effectivity_date
10860 AND NVL (bic2.disable_date,
10861 bic.effectivity_date + 1
10862 ) > bic.effectivity_date)
10863 AND bic.revised_item_sequence_id = rev_item_seq_id;
10864 END IF;
10865
10866 IF (dummy <> 0)
10867 THEN
10868 -- Added for bug 3801212: Check if rows fetched to raise overlap_error
10869 RAISE overlap_error;
10870 END IF;
10871 EXCEPTION
10872 WHEN overlap_error
10873 THEN
10874 RAISE;
10875 WHEN NO_DATA_FOUND
10876 THEN
10877 NULL;
10878 WHEN OTHERS
10879 THEN
10880 err_msg := 'COPY_BILL (' || sql_stmt_num || ') ' || SQLERRM;
10881 fnd_message.set_name ('BOM', 'BOM_SQL_ERR');
10882 fnd_message.set_token ('ENTITY', err_msg);
10883 ROLLBACK TO begin_bill_copy;
10884 app_exception.raise_exception;
10885 END;
10886 END IF;
10887
10888 -- Other organizations who use our bills as common bills must have the
10889 -- component items in their organization as well.
10890 --
10891 FOR l_common_rec IN l_common_csr
10892 LOOP
10893 RAISE common_error;
10894 END LOOP;
10895
10896 -- Ensure the following rule matrix is observed
10897 --
10898 -- Y = Allowed N = Not Allowed
10899 -- P = Must be Phantom O = Must be Optional
10900 -- Configured items are ATO standard items that have a base item id.
10901 -- ATO items have Replenish to Order flags set to "Y".
10902 -- PTO items have Pick Component flags set to "Y".
10903 --
10904 -- Parent
10905 -- Child |Config ATO Mdl ATO Opt ATO Std PTO Mdl PTO Opt PTO Std
10906 -- ---------------------------------------------------------------------------
10907 -- Planning | N N N N N N N
10908 -- Configured | Y Y Y Y Y Y Y
10909 -- ATO Model | P P P N P P N
10910 -- ATO Opt Class | P P P N N N N
10911 -- ATO Standard | Y Y Y Y O O N
10912 -- PTO Model | N N N N P P N
10913 -- PTO Opt Class | N N N N P P N
10914 -- PTO Standard | N N N N Y Y Y
10915 --
10916 --
10917 -- Log errors for multi level structure copy.
10918 -- Planning bill should contain only planning components
10919 INSERT INTO mtl_interface_errors
10920 (unique_id,
10921 organization_id,
10922 transaction_id,
10923 table_name,
10924 column_name,
10925 error_message,
10926 bo_identifier,
10927 last_update_date,
10928 last_updated_by,
10929 creation_date,
10930 created_by,
10931 message_type,
10932 request_id,
10933 program_application_id,
10934 program_id,
10935 program_update_date
10936 )
10937 SELECT bcb.component_item_id,
10938 to_org_id,
10939 p_copy_request_id,
10940 NULL,
10941 get_current_item_rev (bcb.component_item_id,
10942 from_org_id,
10943 rev_date
10944 ),
10945 GET_MESSAGE ('BOM_COPY_ERR_NO_PLANNING_COMPS',
10946 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
10947 bom_globals.get_item_name(to_item_id, from_org_id)
10948 ),
10949 'BOM_COPY',
10950 SYSDATE,
10951 user_id,
10952 SYSDATE,
10953 user_id,
10954 'E',
10955 fnd_global.conc_request_id,
10956 NULL,
10957 fnd_global.conc_program_id,
10958 sysdate
10959 FROM bom_components_b bcb,
10960 mtl_system_items_b msib1,
10961 mtl_system_items_b msib2
10962 WHERE bcb.bill_sequence_id = to_sequence_id
10963 AND (msib1.bom_item_type = planning
10964 AND msib2.bom_item_type <> planning
10965 )
10966 AND msib2.inventory_item_id = to_item_id
10967 AND msib2.organization_id = to_org_id
10968 AND msib1.inventory_item_id = bcb.component_item_id
10969 AND msib1.organization_id = to_org_id
10970 AND bcb.revised_item_sequence_id = rev_item_seq_id;
10971
10972 -- Standard bill without base model cannot have Option class or Model components.
10973 INSERT INTO mtl_interface_errors
10974 (unique_id,
10975 organization_id,
10976 transaction_id,
10977 table_name,
10978 column_name,
10979 error_message,
10980 bo_identifier,
10981 last_update_date,
10982 last_updated_by,
10983 creation_date,
10984 created_by,
10985 message_type,
10986 request_id,
10987 program_application_id,
10988 program_id,
10989 program_update_date
10990 )
10991 SELECT bcb.component_item_id,
10992 to_org_id,
10993 p_copy_request_id,
10994 NULL,
10995 get_current_item_rev (bcb.component_item_id,
10996 from_org_id,
10997 rev_date
10998 ),
10999 GET_MESSAGE ('BOM_COPY_ERR_NO_OPT_MODEL_COMP',
11000 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
11001 bom_globals.get_item_name(to_item_id, from_org_id)
11002 ),
11003 'BOM_COPY',
11004 SYSDATE,
11005 user_id,
11006 SYSDATE,
11007 user_id,
11008 'E',
11009 fnd_global.conc_request_id,
11010 NULL,
11011 fnd_global.conc_program_id,
11012 sysdate
11013 FROM bom_components_b bcb,
11014 mtl_system_items_b msib1,
11015 mtl_system_items_b msib2
11016 WHERE bcb.bill_sequence_id = to_sequence_id
11017 AND (msib1.bom_item_type IN (model, option_class)
11018 AND msib2.bom_item_type = STANDARD
11019 AND msib2.base_item_id IS NULL
11020 )
11021 AND msib2.inventory_item_id = to_item_id
11022 AND msib2.organization_id = to_org_id
11023 AND msib1.inventory_item_id = bcb.component_item_id
11024 AND msib1.organization_id = to_org_id
11025 AND bcb.revised_item_sequence_id = rev_item_seq_id;
11026
11027 -- No ATO Optional components in PTO bill
11028 INSERT INTO mtl_interface_errors
11029 (unique_id,
11030 organization_id,
11031 transaction_id,
11032 table_name,
11033 column_name,
11034 error_message,
11035 bo_identifier,
11036 last_update_date,
11037 last_updated_by,
11038 creation_date,
11039 created_by,
11040 message_type,
11041 request_id,
11042 program_application_id,
11043 program_id,
11044 program_update_date
11045 )
11046 SELECT bcb.component_item_id,
11047 to_org_id,
11048 p_copy_request_id,
11049 NULL,
11050 get_current_item_rev (bcb.component_item_id,
11051 from_org_id,
11052 rev_date
11053 ),
11054 GET_MESSAGE ('BOM_COPY_ERR_NO_ATO_OPT_COMPS',
11055 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
11056 bom_globals.get_item_name(to_item_id, from_org_id)
11057 ),
11058 'BOM_COPY',
11059 SYSDATE,
11060 user_id,
11061 SYSDATE,
11062 user_id,
11063 'E',
11064 fnd_global.conc_request_id,
11065 NULL,
11066 fnd_global.conc_program_id,
11067 sysdate
11068 FROM bom_components_b bcb,
11069 mtl_system_items_b msib1, -- Comp
11070 mtl_system_items_b msib2 -- Structure
11071 WHERE bcb.bill_sequence_id = to_sequence_id
11072 AND (msib1.replenish_to_order_flag = 'Y'
11073 AND msib1.bom_item_type = option_class
11074 AND msib2.pick_components_flag = 'Y'
11075 )
11076 AND msib2.inventory_item_id = to_item_id
11077 AND msib2.organization_id = to_org_id
11078 AND msib1.inventory_item_id = bcb.component_item_id
11079 AND msib1.organization_id = to_org_id
11080 AND bcb.revised_item_sequence_id = rev_item_seq_id;
11081
11082 -- No ATO standard items for PTO standard bills
11083 INSERT INTO mtl_interface_errors
11084 (unique_id,
11085 organization_id,
11086 transaction_id,
11087 table_name,
11088 column_name,
11089 error_message,
11090 bo_identifier,
11091 last_update_date,
11092 last_updated_by,
11093 creation_date,
11094 created_by,
11095 message_type,
11096 request_id,
11097 program_application_id,
11098 program_id,
11099 program_update_date
11100 )
11101 SELECT bcb.component_item_id,
11102 to_org_id,
11103 p_copy_request_id,
11104 NULL,
11105 get_current_item_rev (bcb.component_item_id,
11106 from_org_id,
11107 rev_date
11108 ),
11109 GET_MESSAGE ('BOM_COPY_ERR_NO_ATO_STD_COMPS',
11110 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
11111 bom_globals.get_item_name(to_item_id, from_org_id)
11112 ),
11113 'BOM_COPY',
11114 SYSDATE,
11115 user_id,
11116 SYSDATE,
11117 user_id,
11118 'E',
11119 fnd_global.conc_request_id,
11120 NULL,
11121 fnd_global.conc_program_id,
11122 sysdate
11123 FROM bom_components_b bcb,
11124 mtl_system_items_b msib1, -- Comp
11125 mtl_system_items_b msib2 -- Structure
11126 WHERE bcb.bill_sequence_id = to_sequence_id
11127 AND (msib1.replenish_to_order_flag = 'Y'
11128 AND msib1.bom_item_type = STANDARD
11129 AND msib2.pick_components_flag = 'Y'
11130 AND msib2.bom_item_type = STANDARD
11131 )
11132 AND msib2.inventory_item_id = to_item_id
11133 AND msib2.organization_id = to_org_id
11134 AND msib1.inventory_item_id = bcb.component_item_id
11135 AND msib1.organization_id = to_org_id
11136 AND bcb.revised_item_sequence_id = rev_item_seq_id;
11137
11138 -- No PTO components in ATO bill
11139 INSERT INTO mtl_interface_errors
11140 (unique_id,
11141 organization_id,
11142 transaction_id,
11143 table_name,
11144 column_name,
11145 error_message,
11146 bo_identifier,
11147 last_update_date,
11148 last_updated_by,
11149 creation_date,
11150 created_by,
11151 message_type,
11152 request_id,
11153 program_application_id,
11154 program_id,
11155 program_update_date
11156 )
11157 SELECT bcb.component_item_id,
11158 to_org_id,
11159 p_copy_request_id,
11160 NULL,
11161 get_current_item_rev (bcb.component_item_id,
11162 from_org_id,
11163 rev_date
11164 ),
11165 GET_MESSAGE ('BOM_COPY_ERR_NO_PTO_COMPS',
11166 bom_globals.get_item_name(bcb.component_item_id, from_org_id),
11167 bom_globals.get_item_name(to_item_id, from_org_id)
11168 ),
11169 'BOM_COPY',
11170 SYSDATE,
11171 user_id,
11172 SYSDATE,
11173 user_id,
11174 'E',
11175 fnd_global.conc_request_id,
11176 NULL,
11177 fnd_global.conc_program_id,
11178 sysdate
11179 FROM bom_components_b bcb,
11180 mtl_system_items_b msib1, -- Comp
11181 mtl_system_items_b msib2 -- Structure
11182 WHERE bcb.bill_sequence_id = to_sequence_id
11183 AND (msib1.pick_components_flag = 'Y'
11184 AND msib2.replenish_to_order_flag = 'Y'
11185 )
11186 AND msib2.inventory_item_id = to_item_id
11187 AND msib2.organization_id = to_org_id
11188 AND msib1.inventory_item_id = bcb.component_item_id
11189 AND msib1.organization_id = to_org_id
11190 AND bcb.revised_item_sequence_id = rev_item_seq_id;
11191
11192 sql_stmt_num := 41;
11193
11194 DELETE FROM bom_inventory_components bic
11195 WHERE bic.bill_sequence_id = to_sequence_id
11196 AND EXISTS (
11197 SELECT NULL
11198 FROM mtl_system_items msi1, -- bom
11199 mtl_system_items msi2 -- component
11200 WHERE ((msi2.bom_item_type = planning
11201 AND msi1.bom_item_type <> planning
11202 )
11203 OR (msi2.bom_item_type IN (model, option_class)
11204 AND msi1.bom_item_type = STANDARD
11205 AND msi1.base_item_id IS NULL
11206 )
11207 OR (msi2.replenish_to_order_flag = 'Y'
11208 AND msi2.bom_item_type = option_class
11209 AND msi1.pick_components_flag = 'Y'
11210 )
11211 OR (msi2.replenish_to_order_flag = 'Y'
11212 AND msi2.bom_item_type = STANDARD
11213 AND msi1.pick_components_flag = 'Y'
11214 AND msi1.bom_item_type = STANDARD
11215 )
11216 OR (msi2.pick_components_flag = 'Y'
11217 AND msi1.replenish_to_order_flag = 'Y'
11218 )
11219 )
11220 AND msi1.inventory_item_id = to_item_id
11221 AND msi1.organization_id = to_org_id
11222 AND msi2.inventory_item_id = bic.component_item_id
11223 AND msi2.organization_id = to_org_id)
11224 AND bic.revised_item_sequence_id = rev_item_seq_id;
11225
11226 copy_comps := copy_comps - SQL%ROWCOUNT;
11227 sql_stmt_num := 43;
11228 --Turn off trigger BOMTBICX
11229 bom_globals.g_skip_bomtbicx := 'Y';
11230
11231 UPDATE bom_components_b bic
11232 SET bic.wip_supply_type = phantom
11233 WHERE bic.bill_sequence_id = to_sequence_id
11234 AND EXISTS (
11235 SELECT NULL
11236 FROM mtl_system_items msi1, -- assembly
11237 mtl_system_items msi2 -- component
11238 WHERE msi2.bom_item_type IN (model, option_class)
11239 AND msi2.inventory_item_id = bic.component_item_id
11240 AND msi2.organization_id = to_org_id
11241 AND msi1.inventory_item_id = to_item_id
11242 AND msi1.organization_id = to_org_id)
11243 AND bic.revised_item_sequence_id = rev_item_seq_id;
11244
11245 bom_globals.g_skip_bomtbicx := 'N';
11246 sql_stmt_num := 44;
11247 bom_globals.g_skip_bomtbicx := 'Y';
11248
11249 UPDATE bom_components_b bic
11250 SET bic.optional = 1
11251 WHERE bic.bill_sequence_id = to_sequence_id
11252 AND EXISTS (
11253 SELECT NULL
11254 FROM mtl_system_items msi1, -- assembly
11255 mtl_system_items msi2 -- component
11256 WHERE msi2.base_item_id IS NULL
11257 AND msi2.replenish_to_order_flag = 'Y'
11258 AND msi2.bom_item_type = STANDARD
11259 AND msi1.pick_components_flag = 'Y'
11260 AND msi1.bom_item_type IN (model, option_class)
11261 AND msi2.inventory_item_id = bic.component_item_id
11262 AND msi2.organization_id = to_org_id
11263 AND msi1.inventory_item_id = to_item_id
11264 AND msi1.organization_id = to_org_id)
11265 AND bic.revised_item_sequence_id = rev_item_seq_id;
11266
11267 --Turn on trigger BOMTBICX
11268 bom_globals.g_skip_bomtbicx := 'N';
11269 sql_stmt_num := 46;
11270
11271 INSERT INTO bom_reference_designators
11272 (component_reference_designator,
11273 last_update_date,
11274 last_updated_by,
11275 creation_date,
11276 created_by,
11277 last_update_login,
11278 ref_designator_comment,
11279 change_notice,
11280 component_sequence_id,
11281 acd_type,
11282 request_id,
11283 program_application_id,
11284 program_id,
11285 program_update_date,
11286 attribute_category,
11287 attribute1,
11288 attribute2,
11289 attribute3,
11290 attribute4,
11291 attribute5,
11292 attribute6,
11293 attribute7,
11294 attribute8,
11295 attribute9,
11296 attribute10,
11297 attribute11,
11298 attribute12,
11299 attribute13,
11300 attribute14,
11301 attribute15
11302 )
11303 SELECT component_reference_designator,
11304 SYSDATE,
11305 user_id,
11306 SYSDATE,
11307 user_id,
11308 user_id,/*NULL,bugfix:8639515*/
11309 ref_designator_comment,
11310 x_e_change_notice,
11311 bic.component_sequence_id,
11312 x_acd_type,
11313 fnd_global.conc_request_id,
11314 NULL,
11315 fnd_global.conc_program_id,
11316 sysdate,
11317 brd.attribute_category,
11318 brd.attribute1,
11319 brd.attribute2,
11320 brd.attribute3,
11321 brd.attribute4,
11322 brd.attribute5,
11323 brd.attribute6,
11324 brd.attribute7,
11325 brd.attribute8,
11326 brd.attribute9,
11327 brd.attribute10,
11328 brd.attribute11,
11329 brd.attribute12,
11330 brd.attribute13,
11331 brd.attribute14,
11332 brd.attribute15
11333 FROM bom_reference_designators brd,
11334 bom_components_b bic,
11335 bom_copy_explosions_v bev
11336 WHERE bic.bill_sequence_id = to_sequence_id
11337 AND NVL (bic.eco_for_production, 2) = 2
11338 AND brd.component_sequence_id = bic.created_by
11339 AND NVL (brd.acd_type, 1) <> 3
11340 AND bic.created_by = bev.component_sequence_id
11341 AND bev.bill_sequence_id = from_sequence_id
11342 AND bev.parent_sort_order = p_parent_sort_order
11343 AND bic.revised_item_sequence_id = rev_item_seq_id;
11344
11345 copy_desgs := SQL%ROWCOUNT;
11346
11347
11348 sql_stmt_num := 50;
11349
11350 INSERT INTO bom_substitute_components
11351 (substitute_component_id,
11352 last_update_date,
11353 last_updated_by,
11354 creation_date,
11355 created_by,
11356 last_update_login,
11357 substitute_item_quantity,
11358 component_sequence_id,
11359 acd_type,
11360 change_notice,
11361 request_id,
11362 program_application_id,
11363 program_id,
11364 program_update_date,
11365 attribute_category,
11366 attribute1,
11367 attribute2,
11368 attribute3,
11369 attribute4,
11370 attribute5,
11371 attribute6,
11372 attribute7,
11373 attribute8,
11374 attribute9,
11375 attribute10,
11376 attribute11,
11377 attribute12,
11378 attribute13,
11379 attribute14,
11380 attribute15,
11381 enforce_int_requirements
11382 )
11383 SELECT substitute_component_id,
11384 SYSDATE,
11385 user_id,
11386 SYSDATE,
11387 user_id,
11388 NULL,
11389 --substitute_item_quantity,
11390 DECODE(MSI.primary_unit_of_measure, -- Added corresponding to Bug 6510185
11391 AA.primary_unit_of_measure,Bsc.substitute_item_quantity,
11392 inv_convert.INV_UM_CONVERT(bsc.substitute_component_id,
11393 NULL,
11394 Bsc.substitute_item_quantity,
11395 NULL,
11396 NULL,
11397 AA.primary_unit_of_measure,
11398 MSI.primary_unit_of_measure)) Sub_Comp_qty,
11399 bic.component_sequence_id,
11400 x_acd_type,
11401 x_e_change_notice,
11402 fnd_global.conc_request_id,
11403 NULL,
11404 fnd_global.conc_program_id,
11405 sysdate,
11406 bsc.attribute_category,
11407 bsc.attribute1,
11408 bsc.attribute2,
11409 bsc.attribute3,
11410 bsc.attribute4,
11411 bsc.attribute5,
11412 bsc.attribute6,
11413 bsc.attribute7,
11414 bsc.attribute8,
11415 bsc.attribute9,
11416 bsc.attribute10,
11417 bsc.attribute11,
11418 bsc.attribute12,
11419 bsc.attribute13,
11420 bsc.attribute14,
11421 bsc.attribute15,
11422 bsc.enforce_int_requirements
11423 FROM bom_substitute_components bsc,
11424 bom_components_b bic,
11425 mtl_system_items msi,
11426 MTL_SYSTEM_ITEMS AA , -- Added corresponding to Bug 6510185
11427 bom_copy_explosions_v bev
11428 WHERE bic.bill_sequence_id = to_sequence_id
11429 AND NVL (bic.eco_for_production, 2) = 2
11430 AND bsc.component_sequence_id = bic.created_by
11431 AND NVL (bsc.acd_type, 1) <> 3
11432 AND ((direction = eng_to_bom
11433 AND msi.eng_item_flag = 'N')
11434 OR (direction <> eng_to_bom)
11435 )
11436 AND msi.inventory_item_id = bsc.substitute_component_id
11437 AND msi.organization_id = to_org_id
11438 AND bic.created_by = bev.component_sequence_id
11439 AND bev.bill_sequence_id = from_sequence_id
11440 AND bev.parent_sort_order = p_parent_sort_order
11441 AND bic.revised_item_sequence_id = rev_item_seq_id
11442 AND MSI.inventory_item_id = AA.inventory_item_id -- Added corresponding to Bug 6510185
11443 AND AA.organization_id = from_org_id -- Added corresponding to Bug 6510185
11444 AND EXISTS
11445 (
11446 SELECT 1
11447 FROM fnd_lookup_values_vl flv,
11448 ego_criteria_templates_v ectv,
11449 ego_criteria_v ecv,
11450 mtl_system_items_b msibs -- to assembly item
11451 WHERE ecv.customization_application_id = 702
11452 AND ecv.region_application_id = 702
11453 AND ecv.region_code = 'BOM_ITEM_TYPE_REGION'
11454 AND ecv.customization_code = ectv.customization_code
11455 AND flv.lookup_type = 'ITEM_TYPE'
11456 AND flv.enabled_flag = 'Y'
11457 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
11458 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
11459 AND flv.lookup_code = ectv.classification1
11460 AND ectv.customization_application_id = 702
11461 AND ectv.region_application_id = 702
11462 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
11463 AND flv.lookup_code = msibs.item_type
11464 AND msibs.inventory_item_id = to_item_id
11465 AND msibs.organization_id = to_org_id
11466 AND ecv.value_varchar2 = msi.item_type -- Substitute Component
11467 UNION ALL
11468 SELECT 1
11469 FROM DUAL
11470 WHERE NOT EXISTS
11471 (
11472 SELECT 1
11473 FROM fnd_lookup_values_vl flv,
11474 ego_criteria_templates_v ectv,
11475 mtl_system_items_b msibs -- to assembly item
11476 WHERE flv.lookup_type = 'ITEM_TYPE'
11477 AND flv.enabled_flag = 'Y'
11478 AND (flv.start_date_active IS NULL OR flv.start_date_active < sysdate)
11479 AND (flv.end_date_active IS NULL OR flv.end_date_active > sysdate)
11480 AND flv.lookup_code = ectv.classification1
11481 AND ectv.customization_application_id = 702
11482 AND ectv.region_application_id = 702
11483 AND ectv.region_code = 'BOM_ITEM_TYPE_REGION'
11484 AND flv.lookup_code = msibs.item_type
11485 AND msibs.inventory_item_id = to_item_id
11486 AND msibs.organization_id = to_org_id
11487 )
11488 );
11489
11490 copy_subs := SQL%ROWCOUNT;
11491
11492 sql_stmt_num := 51;
11493
11494 /* Copy the component operations (One To Many changes) */
11495 INSERT INTO bom_component_operations
11496 (comp_operation_seq_id,
11497 operation_seq_num,
11498 operation_sequence_id,
11499 last_update_date,
11500 last_updated_by,
11501 creation_date,
11502 created_by,
11503 last_update_login,
11504 component_sequence_id,
11505 bill_sequence_id,
11506 consuming_operation_flag,
11507 consumption_quantity,
11508 supply_subinventory,
11509 supply_locator_id,
11510 wip_supply_type,
11511 attribute_category,
11512 attribute1,
11513 attribute2,
11514 attribute3,
11515 attribute4,
11516 attribute5,
11517 attribute6,
11518 attribute7,
11519 attribute8,
11520 attribute9,
11521 attribute10,
11522 attribute11,
11523 attribute12,
11524 attribute13,
11525 attribute14,
11526 attribute15,
11527 request_id,
11528 program_application_id,
11529 program_id,
11530 program_update_date
11531 )
11532 SELECT bom_component_operations_s.NEXTVAL,
11533 bco.operation_seq_num,
11534 bos.operation_sequence_id,
11535 SYSDATE,
11536 user_id,
11537 SYSDATE,
11538 user_id,
11539 /*NULL comment for bug8431772,change NULL to user_id*/user_id,
11540 bic.component_sequence_id,
11541 bic.bill_sequence_id,
11542 bco.consuming_operation_flag,
11543 bco.consumption_quantity,
11544 DECODE (x_from_org_id,
11545 to_org_id, bco.supply_subinventory,
11546 DECODE( l_default_wip_params, 1, bic.supply_subinventory, NULL )
11547 ),
11548 DECODE (x_from_org_id,
11549 to_org_id, bco.supply_locator_id,
11550 DECODE( l_default_wip_params, 1, bic.supply_locator_id, NULL )
11551 ),
11552 bco.wip_supply_type,
11553 bco.attribute_category,
11554 bco.attribute1,
11555 bco.attribute2,
11556 bco.attribute3,
11557 bco.attribute4,
11558 bco.attribute5,
11559 bco.attribute6,
11560 bco.attribute7,
11561 bco.attribute8,
11562 bco.attribute9,
11563 bco.attribute10,
11564 bco.attribute11,
11565 bco.attribute12,
11566 bco.attribute13,
11567 bco.attribute14,
11568 bco.attribute15,
11569 fnd_global.conc_request_id,
11570 NULL,
11571 fnd_global.conc_program_id,
11572 sysdate
11573 FROM bom_component_operations bco,
11574 bom_components_b bic,
11575 bom_operation_sequences bos,
11576 bom_copy_explosions_v bev
11577 WHERE bic.bill_sequence_id = to_sequence_id
11578 AND NVL (bic.eco_for_production, 2) = 2
11579 AND bco.component_sequence_id = bic.created_by
11580 AND bos.routing_sequence_id = to_rtg_seq_id
11581 AND bos.operation_seq_num = bco.operation_seq_num
11582 AND bic.created_by = bev.component_sequence_id
11583 AND bev.bill_sequence_id = from_sequence_id
11584 AND bev.parent_sort_order = p_parent_sort_order
11585 AND bic.revised_item_sequence_id = rev_item_seq_id;
11586
11587 copy_compops := SQL%ROWCOUNT;
11588
11589 IF (itm_type = model
11590 OR itm_type = option_class) AND p_cpy_past_eff_comps = 'Y' -- Copy desc elements only once
11591 THEN
11592 sql_stmt_num := 55;
11593
11594 INSERT INTO bom_dependent_desc_elements
11595 (bill_sequence_id,
11596 element_name,
11597 last_update_date,
11598 last_updated_by,
11599 creation_date,
11600 created_by,
11601 last_update_login,
11602 program_application_id,
11603 program_id,
11604 program_update_date,
11605 request_id
11606 )
11607 SELECT to_sequence_id,
11608 bdde.element_name,
11609 SYSDATE,
11610 user_id,
11611 SYSDATE,
11612 user_id,
11613 user_id,
11614 NULL,
11615 fnd_global.conc_program_id,
11616 sysdate,
11617 fnd_global.conc_request_id
11618 FROM bom_dependent_desc_elements bdde
11619 WHERE bdde.bill_sequence_id = x_from_sequence_id
11620 AND ((itm_type = model
11621 AND EXISTS (
11622 SELECT NULL
11623 FROM mtl_descriptive_elements mde
11624 WHERE mde.item_catalog_group_id = itm_cat_grp_id
11625 AND mde.element_name = bdde.element_name)
11626 )
11627 OR itm_type = option_class
11628 );
11629 END IF;
11630
11631 -- Update the created by column only when specific copy flag is no..
11632 -- If specific copy flag is 'Y', then after copy_bill, call update_created_by.
11633
11634
11635 EXCEPTION
11636 WHEN overlap_error
11637 THEN
11638 bom_globals.g_skip_bomtbicx := 'N';
11639 fnd_message.set_name ('BOM', 'BOM_BAD_COPY_GUI');
11640
11641 INSERT INTO mtl_interface_errors
11642 (unique_id,
11643 organization_id,
11644 transaction_id,
11645 table_name,
11646 column_name,
11647 error_message,
11648 bo_identifier,
11649 last_update_date,
11650 last_updated_by,
11651 creation_date,
11652 created_by,
11653 message_type,
11654 request_id,
11655 program_application_id,
11656 program_id,
11657 program_update_date
11658 )
11659 VALUES (to_item_id,
11660 to_org_id,
11661 p_copy_request_id,
11662 NULL,
11663 get_current_item_rev (to_item_id,
11664 from_org_id,
11665 SYSDATE
11666 ),
11667 fnd_message.get,
11668 'BOM_COPY',
11669 SYSDATE,
11670 user_id,
11671 SYSDATE,
11672 user_id,
11673 'E',
11674 fnd_global.conc_request_id,
11675 NULL,
11676 fnd_global.conc_program_id,
11677 sysdate
11678 );
11679 WHEN common_error
11680 THEN
11681 bom_globals.g_skip_bomtbicx := 'N';
11682 fnd_message.set_name ('BOM', 'BOM_COMMON_OTHER_ORGS2');
11683
11684 INSERT INTO mtl_interface_errors
11685 (unique_id,
11686 organization_id,
11687 transaction_id,
11688 table_name,
11689 column_name,
11690 error_message,
11691 bo_identifier,
11692 last_update_date,
11693 last_updated_by,
11694 creation_date,
11695 created_by,
11696 message_type,
11697 request_id,
11698 program_application_id,
11699 program_id,
11700 program_update_date
11701 )
11702 VALUES (to_item_id,
11703 to_org_id,
11704 p_copy_request_id,
11705 NULL,
11706 get_current_item_rev (to_item_id,
11707 from_org_id,
11708 SYSDATE
11709 ),
11710 fnd_message.get,
11711 'BOM_COPY',
11712 SYSDATE,
11713 user_id,
11714 SYSDATE,
11715 user_id,
11716 'E',
11717 fnd_global.conc_request_id,
11718 NULL,
11719 fnd_global.conc_program_id,
11720 sysdate
11721 );
11722 WHEN OTHERS
11723 THEN
11724 bom_globals.g_skip_bomtbicx := 'N';
11725 err_msg := 'copy_bill_for_revised_item (' || sql_stmt_num || ') ' || SQLERRM;
11726 fnd_message.set_name ('BOM', 'BOM_SQL_ERR');
11727 fnd_message.set_token ('ENTITY', err_msg);
11728 ROLLBACK TO begin_revised_item_bill_copy;
11729 app_exception.raise_exception;
11730 END copy_bill_for_revised_item;
11731
11732 PROCEDURE copy_attachments(p_from_sequence_id IN NUMBER,
11733 p_to_sequence_id IN NUMBER,
11734 p_user_id IN NUMBER)
11735 IS
11736 BEGIN
11737 fnd_attached_documents2_pkg.copy_attachments
11738 (x_from_entity_name => 'BOM_BILL_OF_MATERIALS',
11739 x_from_pk1_value => p_from_sequence_id,
11740 x_from_pk2_value => '',
11741 x_from_pk3_value => '',
11742 x_from_pk4_value => '',
11743 x_from_pk5_value => '',
11744 x_to_entity_name => 'BOM_BILL_OF_MATERIALS',
11745 x_to_pk1_value => p_to_sequence_id,
11746 x_to_pk2_value => '',
11747 x_to_pk3_value => '',
11748 x_to_pk4_value => '',
11749 x_to_pk5_value => '',
11750 x_created_by => p_user_id,
11751 x_last_update_login => '',
11752 x_program_application_id => '',
11753 x_program_id => fnd_global.conc_program_id,
11754 x_request_id => fnd_global.conc_request_id
11755 );
11756 END;
11757
11758 FUNCTION get_comp_type_rule_message(p_msg_name IN VARCHAR2,
11759 p_assembly_item IN VARCHAR2, p_parent_item_type IN VARCHAR2,
11760 p_component_item IN VARCHAR2, p_component_item_type IN VARCHAR2)
11761 RETURN VARCHAR2
11762 IS
11763 BEGIN
11764 fnd_message.set_name('BOM',p_msg_name);
11765 fnd_message.set_token('PARENT_ITEM_NAME',p_assembly_item);
11766 fnd_message.set_token('PARENT_ITEM_TYPE',p_parent_item_type);
11767 fnd_message.set_token('COMPONENT_ITEM_NAME',p_component_item);
11768 fnd_message.set_token('COMPONENT_ITEM_TYPE',p_component_item_type);
11769 RETURN fnd_message.get;
11770 END get_comp_type_rule_message;
11771
11772 -- Start of comments
11773 -- API name : check_component_type_rules
11774 -- Type : private
11775 -- Pre-reqs : None.
11776 -- Function : Checks the component type rules and returns the error msg
11777 -- if the validation fails
11778 -- Parameters :
11779 -- IN : p_component_item_id IN NUMBER Required
11780 -- Component Item Name
11781 -- p_assembly_item_id IN NUMBER Required
11782 -- Assembly Item Name
11783 -- p_organization_id IN NUMBER Required
11784 -- Organization Id
11785 -- Returns : Error Message if validation fails else null
11786 -- Purpose : To validate the components and insert error messages
11787 -- to errors table if required.
11788 -- End of comments
11789 FUNCTION check_component_type_rules(p_component_item_id IN NUMBER,
11790 p_assembly_item_id IN NUMBER,
11791 p_org_id IN NUMBER
11792 ) RETURN VARCHAR2
11793 IS
11794 l_return_status VARCHAR2(1);
11795 l_error_msg VARCHAR2(2000);
11796 BEGIN
11797 bom_validate_bom_component.check_component_type_rule(
11798 l_return_status,
11799 l_error_msg,
11800 TRUE,
11801 p_assembly_item_id,
11802 p_component_item_id,
11803 p_org_id );
11804 IF l_return_status = FND_API.G_RET_STS_SUCCESS THEN
11805 return NULL;
11806 ELSE
11807 return l_error_msg;
11808 END IF;
11809 END check_component_type_rules;
11810
11811 -- Bug 11868441 - sun: issue with bom commoning when any subassembly is on unimplemented eco
11812 PROCEDURE ASSIGN_ECO_COMP_TO_ORGS(
11813 p_api_version IN NUMBER,
11814 p_organization_id IN NUMBER,
11815 p_bill_sequence_id IN NUMBER DEFAULT NULL,
11816 x_return_status OUT NOCOPY VARCHAR2,
11817 x_msg_data OUT NOCOPY VARCHAR2)
11818 IS
11819 l_return_status VARCHAR2(1):= 'Y';
11820 l_msg_count number;
11821 l_item_org_assignment_tbl EGO_Item_PUB.Item_Org_Assignment_Tbl_Type;
11822
11823 l_conc_request_id number := FND_GLOBAL.CONC_REQUEST_ID;
11824
11825 CURSOR l_un_assign_eco_comps ( p_bill_seq_id NUMBER
11826 , p_org_id NUMBER)
11827 IS
11828 SELECT bic.component_item_id component_item_id
11829 , bic.change_notice change_notice
11830 , bic.implementation_date implementation_date
11831 FROM bom_inventory_components bic,
11832 bom_structures_b bsb
11833 WHERE bic.bill_sequence_id = bsb.bill_sequence_id
11834 AND bsb.bill_sequence_id = p_bill_seq_id
11835 --Bug 10331803. Should not validate currently disabled components.
11836 AND (bic.disable_date is null OR bic.disable_date > NVL(BOM_EXPLODER_PUB.Get_Explosion_Date, SYSDATE))
11837 AND not exists
11838 (
11839 SELECT 'x'
11840 FROM mtl_system_items s1,
11841 mtl_system_items s2
11842 WHERE s1.organization_id = p_org_id
11843 AND s1.inventory_item_id = bic.component_item_id
11844 and s2.organization_id = bsb.organization_id
11845 and s2.inventory_item_id = bsb.assembly_item_id
11846 AND ((bsb.assembly_type = 1 AND s1.eng_item_flag = 'N')
11847 OR (bsb.assembly_type = 2))
11848 AND s1.inventory_item_id <> bsb.assembly_item_id
11849 AND ((s2.bom_item_type = 1 AND s1.bom_item_type <> 3)
11850 OR (s2.bom_item_type = 2 AND s1.bom_item_type <> 3)
11851 OR (s2.bom_item_type = 3)
11852 OR (s2.bom_item_type = 4
11853 AND (s1.bom_item_type = 4
11854 OR
11855 ( s1.bom_item_type IN (2, 1)
11856 AND s1.replenish_to_order_flag = 'Y'
11857 AND s2.base_item_id IS NOT NULL
11858 AND s2.replenish_to_order_flag = 'Y' ))))
11859 AND (s2.bom_item_type = 3
11860 OR
11861 s2.pick_components_flag = 'Y'
11862 OR
11863 s1.pick_components_flag = 'N')
11864 AND (s2.bom_item_type = 3
11865 OR
11866 NVL(s1.bom_item_type, 4) <> 2
11867 OR
11868 (s1.bom_item_type = 2
11869 AND (( s2.pick_components_flag = 'Y'
11870 AND s1.pick_components_flag = 'Y')
11871 OR ( s2.replenish_to_order_flag = 'Y'
11872 AND s1.replenish_to_order_flag = 'Y'))))
11873 AND( (nvl(fnd_profile.VALUE('BOM:MANDATORY_ATO_IN_PTO'),2) <> 1
11874 AND
11875 NOT(s2.bom_item_type = 4 AND s2.pick_components_flag = 'Y' AND s1.bom_item_type = 4 AND s1.replenish_to_order_flag = 'Y')
11876 )
11877 OR
11878 (nvl(fnd_profile.VALUE('BOM:MANDATORY_ATO_IN_PTO'),2) = 1)
11879 )
11880 /* BOM ER 9904085,10175288,ATO Item under PTO Model*/
11881 AND( ((nvl(fnd_profile.VALUE('BOM:MANDATORY_ATO_IN_PTO'), 2) <> 1)
11882 AND
11883 (NOT(s2.bom_item_type = 1 AND s2.pick_components_flag = 'Y' AND nvl(bic.optional, 1) = 2 AND s1.bom_item_type = 4 AND s1.replenish_to_order_flag = 'Y'))
11884 )
11885 OR
11886 (nvl(fnd_profile.VALUE('BOM:MANDATORY_ATO_IN_PTO'), 2) = 1)
11887 )
11888 /* END BOM ER 9904085,10175288,ATO Item under PTO Model*/
11889 );
11890
11891
11892 BEGIN
11893 IF p_api_version = 1 then
11894 -- set request id -1 to avoid raising EGO_WF_WRAPPER_PVT.G_ITEM_BULKLOAD_EVENT event
11895 fnd_global.initialize(FND_CONST.CONC_REQUEST_ID, -1);
11896
11897 FOR comps_rec IN l_un_assign_eco_comps(p_bill_sequence_id, p_organization_id) LOOP
11898 IF ( comps_rec.change_notice is not null AND comps_rec.implementation_date is null) THEN
11899 l_item_org_assignment_tbl(1).Inventory_Item_Id := comps_rec.component_item_id;
11900 l_item_org_assignment_tbl(1).Organization_Id := p_organization_id ;
11901
11902 EGO_Item_PUB.Process_Item_Org_Assignments(
11903 p_api_version => 1.0
11904 , p_commit => FND_API.G_FALSE
11905 , p_Item_Org_Assignment_Tbl => l_item_org_assignment_tbl
11906 , x_msg_count => l_msg_count
11907 , x_return_status => l_return_status);
11908 END IF;
11909 END LOOP;
11910
11911 fnd_global.initialize(FND_CONST.CONC_REQUEST_ID, l_conc_request_id);
11912
11913 END IF; -- p_api_version = 1.0
11914
11915 x_return_status := l_return_status;
11916
11917 EXCEPTION
11918 WHEN OTHERS THEN
11919 FND_MSG_PUB.Count_And_Get
11920 ( p_count => l_msg_count
11921 ,p_data => x_msg_data );
11922 x_return_status := FND_API.G_RET_STS_ERROR;
11923 END ASSIGN_ECO_COMP_TO_ORGS;
11924
11925 END bom_copy_bill;