DBA Data[Home] [Help]

PACKAGE BODY: APPS.BOM_COPY_BILL

Source


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