DBA Data[Home] [Help]

PACKAGE BODY: APPS.ENGPKIMP

Source


1 package body ENGPKIMP as
2 /* $Header: ENGEIMPB.pls 120.51 2007/09/20 21:57:24 sdarbha noship $ */
3 
4 --##########################################################################
5 --  HISTORY :
6 --
7 -- Sept-2003     odaboval  ERES_Project.
8 --                     Raise child events of ERES parent event ecoImplement:
9 --                     - copyToManufacturing
10 --                     - transferToManufacturing
11 --                     - billCreate or billUpdate
12 --                     - routingCreate or routingC=Update.
13 --                     These event are not attached to the parent if
14 --                     it doesn't exist.
15 --                     Created local procedure event_acknowledgement for
16 --                      acknowledging the events in case of error.
17 --
18 -- Oct-2003      odaboval set the ERES calls as 8i Compliant.
19 -- 06/29/04               Added parameter p_revised_item_seq_id to Procedure
20 --                        LOG_IMPLEMENT_FAILURE
21 --
22 -- Jul-2004      odaboval bug 3741444, added flag bERES_Flag_for_BOM.
23 -- Dec-2004      odaboval bug 3908563, added flag bERES_Flag_for_Routing.
24 
25 --##########################################################################
26 
27         cancelled_status constant number(1) := 5;
28         implemented_status constant number(1) := 6;
29 
30 --
31 --  From domain ECG_ACTION.
32 --
33         acd_add constant number(1) := 1;
34         acd_change constant number(1) := 2;
35         acd_delete constant number(1) := 3;
36 
37 --  Oracle Order Entry
38 
39         G_OrderEntry constant number(3) := 300;
40 -- set new wip job name used in creating wip_job_schedule_interface
41 
42         rev_op_disable_date_tbl      Rev_Op_Disable_Date_Tbl_Type;
43         rev_comp_disable_date_tbl    Rev_Comp_Disable_Date_Tbl_Type;
44 
45 ------------------------------------------------------------------
46 -- Added for bug 3448857                                        --
47 -- Defining Exception if package is not found when they are     --
48 -- called using dynamic sql                                     --
49 ------------------------------------------------------------------
50 PLSQL_COMPILE_ERROR EXCEPTION;
51 PRAGMA EXCEPTION_INIT(PLSQL_COMPILE_ERROR, -6550);
52 
53 ------------------------------------------------------
54 -- R12: Type declaration for Common BOM Enhancement --
55 ------------------------------------------------------
56 TYPE Common_Rev_Comp_Rec_Type IS RECORD (
57     Revised_Item_Sequence_Id     NUMBER
58   , dest_bill_sequence_id        NUMBER
59   , dest_old_comp_sequence_id    NUMBER
60   , Component_sequence_id        NUMBER
61   , common_component_sequence_id NUMBER
62   , prev_common_comp_sequence_id NUMBER
63  );
64 TYPE Common_Rev_Comp_Tbl_Type IS TABLE OF Common_Rev_Comp_Rec_Type
65     INDEX BY BINARY_INTEGER ;
66 -----------------------------------------------------------------
67 -- R12: Global variable declaration for Common BOM Enhancement --
68 -----------------------------------------------------------------
69 g_Common_Rev_Comp_Tbl    Common_Rev_Comp_Tbl_Type;
70 g_common_rev_comps_cnt   NUMBER;
71 isCommonedBOM            VARCHAR2(1);
72 -----------------------------------------------------------------
73 -- Procedures Begin                                            --
74 -----------------------------------------------------------------
75 
76 -- Added private procedure for bug 3584193
77 -- Description: The bill with unapproved items should not be allowed to be transferred through ECO.
78 /********************************************************************
79  * API Name      : UNAPPROVED_COMPONENTS_EXISTS
80  * Parameters IN : L_NEW_ASSEMBLY_ITEM_ID, VAR_ORGANIZATION_ID, VAR_SELECTION_OPTION, VAR_ALTERNATE_BOM_DESIGNATOR
81  * Parameters OUT: None
82  * Returns       : Boolean 'TRUE' or 'FALSE' depending on whether bill contains any un-approved items.
83  * Purpose       : For an Engineering BOM to transfer to Manufacturing, the BOM should not contain any un-approved items.
84  *                      This API will find if the BOM contains any un-approved items.
85  *********************************************************************/
86 FUNCTION UNAPPROVED_COMPONENTS_EXISTS (L_NEW_ASSEMBLY_ITEM_ID IN NUMBER,
87         VAR_ORGANIZATION_ID IN NUMBER,
88         VAR_SELECTION_OPTION IN NUMBER,
89         VAR_ALTERNATE_BOM_DESIGNATOR IN VARCHAR2)
90         RETURN BOOLEAN IS
91           CURSOR check_components IS
92           SELECT count(1)
93           FROM DUAL
94           WHERE EXISTS (
95           SELECT 1
96           FROM bom_bill_of_materials bbom,
97                bom_inventory_components bic,
98          mtl_system_items msi
99           WHERE bbom.assembly_item_id   = L_NEW_ASSEMBLY_ITEM_ID
100           AND   bbom.organization_id    = VAR_ORGANIZATION_ID
101           AND ((VAR_SELECTION_OPTION = 2 AND
102                 bBOM.ALTERNATE_BOM_DESIGNATOR IS NULL)
103             OR (VAR_SELECTION_OPTION = 3 AND
104                   bBOM.ALTERNATE_BOM_DESIGNATOR = VAR_ALTERNATE_BOM_DESIGNATOR)
105             OR (VAR_SELECTION_OPTION = 1))
106           AND   bic.bill_Sequence_id  = bbom.bill_sequence_id
107           AND   msi.inventory_item_id  = bic.component_item_id
108           AND   msi.organization_id    = VAR_ORGANIZATION_ID
109           AND   nvl(msi.approval_status,'A') <> 'A');
110           l_dummy number;
111         BEGIN
112         --FND_FILE.PUT_LINE(FND_FILE.LOG, 'ENGEIMPB.pls - in method UNAPPROVED_COMPONENTS_EXISTS');
113         OPEN check_components;
114         FETCH check_components INTO l_dummy;
115         CLOSE check_components;
116         IF l_dummy = 1 THEN
117           RETURN TRUE; -- This means that there is atleast one unapproved item as component
118         END IF;
119         RETURN FALSE;
120 END UNAPPROVED_COMPONENTS_EXISTS;
121 
122   -- Added for bug 3482152
123 /********************************************************************
124  * API Name      : check_header_impl_allowed
125  * Parameters IN : p_change_id, p_status_code
126  * Parameters OUT: None
127  * Returns       : 'T' or 'F' depending on whether header can be promoted
128  * Purpose       : For PLM ECOs checks the following to determine
129  * whether header can be promoted.
130  * a) Valid status
131  * b) Workflow status
132  * c) Mandatory tasks
133  *********************************************************************/
134 FUNCTION check_header_impl_allowed
135 ( p_change_id   IN NUMBER
136 , p_change_notice IN VARCHAR2
137 , p_status_code IN NUMBER
138 , p_curr_status_code IN NUMBER
139 , p_plm_or_erp_change IN VARCHAR2
140 , p_request_id  IN NUMBER
141 ) RETURN VARCHAR2 IS
142 
143         l_mandatory_task_count  NUMBER;
144         l_implement_header      VARCHAR2(1) := 'F';
145         l_valid_phase           NUMBER;
146         l_eco_impl_mode NUMBER := 0; -- implementation trigger point header
147 
148         -- cursor to check if the implementation trigger point is not the eco header
149         -- i.e., either auto-implement or revised items promote action
150         CURSOR c_eco_impl_mode_header IS
151         SELECT 1
152         FROM fnd_concurrent_requests
153         WHERE request_id = p_request_id
154         AND ARGUMENT4 IS NOT NULL
155         AND ARGUMENT5 IS NULL;
156 
157         -- Cursor to check --
158         -- if current phase of the header is the second last phase of the lifecycle of the change
159         -- and if workflow is associated to the phase then , it is in completed or approved phase
160         CURSOR  c_check_phase IS
161         SELECT 1
162         FROM eng_lifecycle_statuses els
163         WHERE els.entity_id1 = p_change_id
164         AND els.entity_name = 'ENG_CHANGE'
165         AND els.status_code = p_curr_status_code
166         AND els.active_flag = 'Y'
167         AND (   1 = l_eco_impl_mode
168                 OR (    1 = (   SELECT count(*)
169                                 FROM eng_lifecycle_statuses els_in
170                                 WHERE els_in.entity_id1 = p_change_id
171                                 AND els_in.entity_name = 'ENG_CHANGE'
172                                 AND els_in.active_flag = 'Y'
173                                 AND els_in.sequence_number > els.sequence_number)
174                         AND ((  els.change_wf_route_id IS NOT NULL
175                                 AND (   els.workflow_status = 'APPROVED'
176                                         OR els.workflow_status = 'COMPLETED')
177                              )
178                              OR (       els.change_wf_route_id IS NULL
179                                         AND els.CHANGE_WF_ROUTE_TEMPLATE_ID IS NULL)
180                            )
181                    )
182             );
183 
184 
185 BEGIN
186 
187         IF (p_plm_or_erp_change =  'ERP')
188         THEN
189                 l_implement_header := 'T';
190                 RETURN l_implement_header;
191         ELSE
192 
193                 OPEN c_eco_impl_mode_header;
194                 FETCH c_eco_impl_mode_header INTO l_eco_impl_mode;
195                 CLOSE c_eco_impl_mode_header;
196 
197                 OPEN c_check_phase;
198                 FETCH c_check_phase INTO l_valid_phase;
199                 IF c_check_phase%NOTFOUND
200                 THEN
201                         l_implement_header := 'F';
202                         FND_FILE.NEW_LINE(FND_FILE.LOG);
203                         FND_FILE.PUT_LINE(FND_FILE.LOG, 'The header of ECO '|| p_change_notice||' will not be implemented.');
204                 ELSE
205 
206                         l_implement_header := 'T';
207                         -- check if there are any pending mandatory tasks in the ECO
208                         SELECT count(1)
209                         INTO l_mandatory_task_count
210                         FROM eng_change_lines l,
211                              eng_change_statuses s
212                         WHERE l.change_id = p_change_id
213                         AND s.status_code = l.status_code
214                         AND l.complete_before_status_code IS NOT NULL
215                         AND s.status_type NOT IN (5, 6, 11)
216                         AND nvl(l.required_flag , 'Y') = 'Y';
217 
218                         IF(l_mandatory_task_count <> 0)
219                         THEN
220                                 l_implement_header := 'F';
221                                 FND_FILE.NEW_LINE(FND_FILE.LOG);
222                                 FND_FILE.PUT_LINE(FND_FILE.LOG, 'The header of ECO '|| p_change_notice||' will not be implemented as '||
223                                                                 'there is at least one mandatory task which must be completed/cancelled.');
224                         END IF;
225                 END IF;
226                 CLOSE c_check_phase;
227                 RETURN l_implement_header;
228         END IF;
229 EXCEPTION
230 WHEN OTHERS THEN
231         FND_FILE.NEW_LINE(FND_FILE.LOG);
232         FND_FILE.PUT_LINE(FND_FILE.LOG,' Error in check_header_impl_allowed .. ' ||SQLERRM);
233 	--do not implement the header if validation errors out
234         CLOSE c_check_phase;
235         l_implement_header := 'F';
236         RETURN l_implement_header;
237 END check_header_impl_allowed;
238 -- End changes for bug 3482152
239 
240 --   Added for bug 6157001
241 PROCEDURE Chk_GDSN_SingleRow_Chgs_Exist ( p_change_line_id IN NUMBER,
242                                      p_attr_group_id IN NUMBER,
243                                      x_can_implement_status OUT NOCOPY VARCHAR2
244                                         )
245 IS
246   l_single_changes_count NUMBER;
247   l_multi_changes_count NUMBER;
248   l_inventory_item_id NUMBER;
249   l_org_id NUMBER;
250   l_single_gdsn_item_prod_rec EGO_ITEM_GTN_ATTRS_VL%ROWTYPE;
251   l_single_gdsn_item_pend_rec EGO_GTN_ATTR_CHG_VL%ROWTYPE;
252   l_multi_gdsn_item_prod_rec EGO_ITEM_GTN_ATTRS_VL%ROWTYPE;
253   l_multi_gdsn_item_pend_rec EGO_GTN_MUL_ATTR_CHG_VL%ROWTYPE;
254   abort_implementation exception;
255 
256   CURSOR cur_gdsn_singlerow_attr_grps IS
257      SELECT attr_group_id, attr_group_name FROM ego_attr_groups_v WHERE attr_group_type='EGO_ITEM_GTIN_ATTRS' AND application_id=431;
258 
259 BEGIN
260   l_single_changes_count := 0;
261   l_multi_changes_count := 0;
262 
263   -- First Check if there are any pending changes for gdsn single or multi row attrs done through the change order.
264   SELECT count(*) INTO l_single_changes_count FROM ego_gtn_attr_chg_vl WHERE change_line_id = p_change_line_id AND implementation_date IS NULL;
265   SELECT count(*) INTO l_multi_changes_count FROM ego_gtn_mul_attr_chg_vl WHERE change_line_id = p_change_line_id AND implementation_date IS NULL;
266   -- If there are no gdsn single or multi row attrs changes return
267   IF l_single_changes_count = 0 AND l_multi_changes_count = 0 THEN
268      x_can_implement_status := 'YES';
269      RETURN;
270   END IF;
271 
272   SELECT revised_item_id, organization_id
273   INTO l_inventory_item_id, l_org_id
274   FROM eng_revised_items
275   WHERE revised_item_sequence_id = p_change_line_id;
276 
277   -- If gdsn single row changes exists
278   IF l_single_changes_count > 0 THEN
279        -- Get the pending and production rows for comparision
280        SELECT * INTO l_single_gdsn_item_pend_rec FROM ego_gtn_attr_chg_vl WHERE change_line_id = p_change_line_id;
281        SELECT * INTO l_single_gdsn_item_prod_rec FROM ego_item_gtn_attrs_vl WHERE inventory_item_id = l_inventory_item_id AND organization_id = l_org_id;
282 
283        FOR single_attr_grps_cur IN cur_gdsn_singlerow_attr_grps
284        LOOP
285 
286           --   Check if there are any pending changes done for this attribute group
287           --   Trade_Item_Description   GDSN Single Row Attribute Group
288           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'Trade_Item_Description' THEN
289                IF (NVL(l_single_gdsn_item_pend_rec.BRAND_NAME, NVL(l_single_gdsn_item_prod_rec.BRAND_NAME,'!')) <> NVL(l_single_gdsn_item_prod_rec.BRAND_NAME,'!'))
290                OR (NVL(l_single_gdsn_item_pend_rec.BRAND_OWNER_GLN, NVL(l_single_gdsn_item_prod_rec.BRAND_OWNER_GLN,'!')) <> NVL(l_single_gdsn_item_prod_rec.BRAND_OWNER_GLN,'!'))
291                OR (NVL(l_single_gdsn_item_pend_rec.BRAND_OWNER_NAME, NVL(l_single_gdsn_item_prod_rec.BRAND_OWNER_NAME,'!')) <> NVL(l_single_gdsn_item_prod_rec.BRAND_OWNER_NAME,'!'))
292                OR (NVL(l_single_gdsn_item_pend_rec.DESCRIPTION_SHORT, NVL(l_single_gdsn_item_prod_rec.DESCRIPTION_SHORT,'!')) <> NVL(l_single_gdsn_item_prod_rec.DESCRIPTION_SHORT,'!'))
293                OR (NVL(l_single_gdsn_item_pend_rec.EANUCC_CODE, NVL(l_single_gdsn_item_prod_rec.EANUCC_CODE,'!')) <> NVL(l_single_gdsn_item_prod_rec.EANUCC_CODE,'!'))
294                OR (NVL(l_single_gdsn_item_pend_rec.EANUCC_TYPE, NVL(l_single_gdsn_item_prod_rec.EANUCC_TYPE,'!')) <> NVL(l_single_gdsn_item_prod_rec.EANUCC_TYPE,'!'))
295                OR (NVL(l_single_gdsn_item_pend_rec.FUNCTIONAL_NAME, NVL(l_single_gdsn_item_prod_rec.FUNCTIONAL_NAME,'!')) <> NVL(l_single_gdsn_item_prod_rec.FUNCTIONAL_NAME,'!'))
296                OR (NVL(l_single_gdsn_item_pend_rec.INVOICE_NAME, NVL(l_single_gdsn_item_prod_rec.INVOICE_NAME,'!')) <> NVL(l_single_gdsn_item_prod_rec.INVOICE_NAME,'!'))
297                OR (NVL(l_single_gdsn_item_pend_rec.IS_BARCODE_SYMBOLOGY_DERIVABLE, NVL(l_single_gdsn_item_prod_rec.IS_BARCODE_SYMBOLOGY_DERIVABLE,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_BARCODE_SYMBOLOGY_DERIVABLE,'!'))
298                OR (NVL(l_single_gdsn_item_pend_rec.SUB_BRAND, NVL(l_single_gdsn_item_prod_rec.SUB_BRAND,'!')) <> NVL(l_single_gdsn_item_prod_rec.SUB_BRAND,'!'))
299                OR (NVL(l_single_gdsn_item_pend_rec.TRADE_ITEM_COUPON, NVL(l_single_gdsn_item_prod_rec.TRADE_ITEM_COUPON,-999999)) <> NVL(l_single_gdsn_item_prod_rec.TRADE_ITEM_COUPON,-999999))
300                OR (NVL(l_single_gdsn_item_pend_rec.TRADE_ITEM_DESCRIPTOR, NVL(l_single_gdsn_item_prod_rec.TRADE_ITEM_DESCRIPTOR,-999999)) <> NVL(l_single_gdsn_item_prod_rec.TRADE_ITEM_DESCRIPTOR,-999999))
301                OR (NVL(l_single_gdsn_item_pend_rec.TRADE_ITEM_FINISH_DESCRIPTION, NVL(l_single_gdsn_item_prod_rec.TRADE_ITEM_FINISH_DESCRIPTION,'!')) <> NVL(l_single_gdsn_item_prod_rec.TRADE_ITEM_FINISH_DESCRIPTION,'!'))
302                OR (NVL(l_single_gdsn_item_pend_rec.TRADE_ITEM_FORM_DESCRIPTION, NVL(l_single_gdsn_item_prod_rec.TRADE_ITEM_FORM_DESCRIPTION,'!')) <> NVL(l_single_gdsn_item_prod_rec.TRADE_ITEM_FORM_DESCRIPTION,'!'))
303                THEN
304                     x_can_implement_status := 'NO';
305                     EXIT;
306                END IF;
307           END IF;   --   Trade_Item_Description
308 
309           --   Trade_Item_Measurements   GDSN Single Row Attribute Group
310           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'Trade_Item_Measurements' THEN
311                IF (NVL(l_single_gdsn_item_pend_rec.DIAMETER, NVL(l_single_gdsn_item_prod_rec.DIAMETER,-999999)) <> NVL(l_single_gdsn_item_prod_rec.DIAMETER,-999999))
312                OR (NVL(l_single_gdsn_item_pend_rec.DRAINED_WEIGHT, NVL(l_single_gdsn_item_prod_rec.DRAINED_WEIGHT,-999999)) <> NVL(l_single_gdsn_item_prod_rec.DRAINED_WEIGHT,-999999))
313                OR (NVL(l_single_gdsn_item_pend_rec.GENERIC_INGREDIENT, NVL(l_single_gdsn_item_prod_rec.GENERIC_INGREDIENT,'!')) <> NVL(l_single_gdsn_item_prod_rec.GENERIC_INGREDIENT,'!'))
314                OR (NVL(l_single_gdsn_item_pend_rec.GENERIC_INGREDIENT_STRGTH, NVL(l_single_gdsn_item_prod_rec.GENERIC_INGREDIENT_STRGTH,-999999)) <> NVL(l_single_gdsn_item_prod_rec.GENERIC_INGREDIENT_STRGTH,-999999))
315                OR (NVL(l_single_gdsn_item_pend_rec.GROSS_WEIGHT, NVL(l_single_gdsn_item_prod_rec.GROSS_WEIGHT,-999999)) <> NVL(l_single_gdsn_item_prod_rec.GROSS_WEIGHT,-999999))
316                OR (NVL(l_single_gdsn_item_pend_rec.INGREDIENT_STRENGTH, NVL(l_single_gdsn_item_prod_rec.INGREDIENT_STRENGTH,'!')) <> NVL(l_single_gdsn_item_prod_rec.INGREDIENT_STRENGTH,'!'))
317                OR (NVL(l_single_gdsn_item_pend_rec.IS_NET_CONTENT_DEC_FLAG, NVL(l_single_gdsn_item_prod_rec.IS_NET_CONTENT_DEC_FLAG,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_NET_CONTENT_DEC_FLAG,'!'))
318                OR (NVL(l_single_gdsn_item_pend_rec.NET_CONTENT, NVL(l_single_gdsn_item_prod_rec.NET_CONTENT,-999999)) <> NVL(l_single_gdsn_item_prod_rec.NET_CONTENT,-999999))
319                OR (NVL(l_single_gdsn_item_pend_rec.PEG_HORIZONTAL, NVL(l_single_gdsn_item_prod_rec.PEG_HORIZONTAL,-999999)) <> NVL(l_single_gdsn_item_prod_rec.PEG_HORIZONTAL,-999999))
320                OR (NVL(l_single_gdsn_item_pend_rec.PEG_VERTICAL, NVL(l_single_gdsn_item_prod_rec.PEG_VERTICAL,-999999)) <> NVL(l_single_gdsn_item_prod_rec.PEG_VERTICAL,-999999))
321                OR (NVL(l_single_gdsn_item_pend_rec.UOM_NET_CONTENT, NVL(l_single_gdsn_item_prod_rec.UOM_NET_CONTENT,'!')) <> NVL(l_single_gdsn_item_prod_rec.UOM_NET_CONTENT,'!'))
322                THEN
323                     x_can_implement_status := 'NO';
324                     EXIT;
325                END IF;
326           END IF;   --   Trade_Item_Measurements
327 
328           --   Gtin_Unit_Indicator   GDSN Single Row Attribute Group
329           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'Gtin_Unit_Indicator' THEN
330                IF (NVL(l_single_gdsn_item_pend_rec.IS_TRADE_ITEM_A_CONSUMER_UNIT, NVL(l_single_gdsn_item_prod_rec.IS_TRADE_ITEM_A_CONSUMER_UNIT,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_TRADE_ITEM_A_CONSUMER_UNIT,'!'))
331                OR (NVL(l_single_gdsn_item_pend_rec.IS_TRADE_ITEM_A_CONSUMER_UNIT, NVL(l_single_gdsn_item_prod_rec.IS_TRADE_ITEM_A_CONSUMER_UNIT,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_TRADE_ITEM_A_CONSUMER_UNIT,'!'))
332                OR (NVL(l_single_gdsn_item_pend_rec.IS_TRADE_ITEM_A_VARIABLE_UNIT, NVL(l_single_gdsn_item_prod_rec.IS_TRADE_ITEM_A_VARIABLE_UNIT,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_TRADE_ITEM_A_VARIABLE_UNIT,'!'))
333                OR (NVL(l_single_gdsn_item_pend_rec.IS_TRADE_ITEM_INFO_PRIVATE, NVL(l_single_gdsn_item_prod_rec.IS_TRADE_ITEM_INFO_PRIVATE,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_TRADE_ITEM_INFO_PRIVATE,'!'))
334                THEN
335                     x_can_implement_status := 'NO';
336                     EXIT;
337                END IF;
338           END IF;   --   Gtin_Unit_Indicator
339 
340           --   Price_Date_Information   GDSN Single Row Attribute Group
341           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'Price_Date_Information' THEN
342                IF (NVL(l_single_gdsn_item_pend_rec.CATALOG_PRICE, NVL(l_single_gdsn_item_prod_rec.CATALOG_PRICE,-999999)) <> NVL(l_single_gdsn_item_prod_rec.CATALOG_PRICE,-999999))
343                OR (NVL(l_single_gdsn_item_pend_rec.SUGGESTED_RETAIL_PRICE, NVL(l_single_gdsn_item_prod_rec.SUGGESTED_RETAIL_PRICE,-999999)) <> NVL(l_single_gdsn_item_prod_rec.SUGGESTED_RETAIL_PRICE,-999999))
344                OR (NVL(l_single_gdsn_item_pend_rec.EFFECTIVE_END_DATE, NVL(l_single_gdsn_item_prod_rec.EFFECTIVE_END_DATE,to_date('''1''','''j'''))) <> NVL(l_single_gdsn_item_prod_rec.EFFECTIVE_END_DATE,to_date('''1''','''j''')))
345                OR (NVL(l_single_gdsn_item_pend_rec.EFFECTIVE_START_DATE, NVL(l_single_gdsn_item_prod_rec.EFFECTIVE_START_DATE,to_date('''1''','''j'''))) <> NVL(l_single_gdsn_item_prod_rec.EFFECTIVE_START_DATE,to_date('''1''','''j''')))
346                THEN
347                     x_can_implement_status := 'NO';
348                     EXIT;
349                END IF;
350           END IF;   --   Price_Date_Information
351 
352           --   Trade_Item_Hierarchy   GDSN Single Row Attribute Group
353           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'Trade_Item_Hierarchy' THEN
354                IF (NVL(l_single_gdsn_item_pend_rec.QUANITY_OF_ITEM_IN_LAYER, NVL(l_single_gdsn_item_prod_rec.QUANITY_OF_ITEM_IN_LAYER,-999999)) <> NVL(l_single_gdsn_item_prod_rec.QUANITY_OF_ITEM_IN_LAYER,-999999))
355                OR (NVL(l_single_gdsn_item_pend_rec.QUANTITY_OF_COMP_LAY_ITEM, NVL(l_single_gdsn_item_prod_rec.QUANTITY_OF_COMP_LAY_ITEM,-999999)) <> NVL(l_single_gdsn_item_prod_rec.QUANTITY_OF_COMP_LAY_ITEM,-999999))
356                OR (NVL(l_single_gdsn_item_pend_rec.QUANTITY_OF_INNER_PACK, NVL(l_single_gdsn_item_prod_rec.QUANTITY_OF_INNER_PACK,-999999)) <> NVL(l_single_gdsn_item_prod_rec.QUANTITY_OF_INNER_PACK,-999999))
357                OR (NVL(l_single_gdsn_item_pend_rec.QUANTITY_OF_ITEM_INNER_PACK, NVL(l_single_gdsn_item_prod_rec.QUANTITY_OF_ITEM_INNER_PACK,-999999)) <> NVL(l_single_gdsn_item_prod_rec.QUANTITY_OF_ITEM_INNER_PACK,-999999))
358                THEN
359                     x_can_implement_status := 'NO';
360                     EXIT;
361                END IF;
362           END IF;   --   Trade_Item_Hierarchy
363 
364           --   Trade_Item_Marking   GDSN Single Row Attribute Group
365           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'Trade_Item_Marking' THEN
366                IF (NVL(l_single_gdsn_item_pend_rec.HAS_BATCH_NUMBER, NVL(l_single_gdsn_item_prod_rec.HAS_BATCH_NUMBER,'!')) <> NVL(l_single_gdsn_item_prod_rec.HAS_BATCH_NUMBER,'!'))
367                OR (NVL(l_single_gdsn_item_pend_rec.IS_NON_SOLD_TRADE_RET_FLAG, NVL(l_single_gdsn_item_prod_rec.IS_NON_SOLD_TRADE_RET_FLAG,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_NON_SOLD_TRADE_RET_FLAG,'!'))
368                OR (NVL(l_single_gdsn_item_pend_rec.IS_TRADE_ITEM_MAR_REC_FLAG, NVL(l_single_gdsn_item_prod_rec.IS_TRADE_ITEM_MAR_REC_FLAG,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_TRADE_ITEM_MAR_REC_FLAG,'!'))
369                THEN
370                     x_can_implement_status := 'NO';
371                     EXIT;
372                END IF;
373           END IF;   --   Trade_Item_Marking
374 
375           --   Handling_Information   GDSN Single Row Attribute Group
376           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'Handling_Information' THEN
377                IF (NVL(l_single_gdsn_item_pend_rec.STACKING_FACTOR, NVL(l_single_gdsn_item_prod_rec.STACKING_FACTOR,-999999)) <> NVL(l_single_gdsn_item_prod_rec.STACKING_FACTOR,-999999))
378                OR (NVL(l_single_gdsn_item_pend_rec.STACKING_WEIGHT_MAXIMUM, NVL(l_single_gdsn_item_prod_rec.STACKING_WEIGHT_MAXIMUM,-999999)) <> NVL(l_single_gdsn_item_prod_rec.STACKING_WEIGHT_MAXIMUM,-999999))
379                THEN
380                     x_can_implement_status := 'NO';
381                     EXIT;
382                END IF;
383           END IF;   --   Handling_Information
384 
385           --   Packaging_Marking   GDSN Single Row Attribute Group
386           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'Packaging_Marking' THEN
387                IF (NVL(l_single_gdsn_item_pend_rec.IS_PACKAGE_MARKED_AS_REC, NVL(l_single_gdsn_item_prod_rec.IS_PACKAGE_MARKED_AS_REC,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_PACKAGE_MARKED_AS_REC,'!'))
388                OR (NVL(l_single_gdsn_item_pend_rec.IS_PACKAGE_MARKED_RET, NVL(l_single_gdsn_item_prod_rec.IS_PACKAGE_MARKED_RET,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_PACKAGE_MARKED_RET,'!'))
389                OR (NVL(l_single_gdsn_item_pend_rec.IS_PACK_MARKED_WITH_EXP_DATE, NVL(l_single_gdsn_item_prod_rec.IS_PACK_MARKED_WITH_EXP_DATE,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_PACK_MARKED_WITH_EXP_DATE,'!'))
390                OR (NVL(l_single_gdsn_item_pend_rec.IS_PACK_MARKED_WITH_GREEN_DOT, NVL(l_single_gdsn_item_prod_rec.IS_PACK_MARKED_WITH_GREEN_DOT,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_PACK_MARKED_WITH_GREEN_DOT,'!'))
391                OR (NVL(l_single_gdsn_item_pend_rec.IS_PACK_MARKED_WITH_INGRED, NVL(l_single_gdsn_item_prod_rec.IS_PACK_MARKED_WITH_INGRED,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_PACK_MARKED_WITH_INGRED,'!'))
392                THEN
393                     x_can_implement_status := 'NO';
394                     EXIT;
395                END IF;
396           END IF;   --   Packaging_Marking
397 
398           --   Temperature_Information   GDSN Single Row Attribute Group
399           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'Temperature_Information' THEN
400                IF (NVL(l_single_gdsn_item_pend_rec.DELIVERY_TO_MRKT_TEMP_MAX, NVL(l_single_gdsn_item_prod_rec.DELIVERY_TO_MRKT_TEMP_MAX,-999999)) <> NVL(l_single_gdsn_item_prod_rec.DELIVERY_TO_MRKT_TEMP_MAX,-999999))
401                OR (NVL(l_single_gdsn_item_pend_rec.DELIVERY_TO_MRKT_TEMP_MIN, NVL(l_single_gdsn_item_prod_rec.DELIVERY_TO_MRKT_TEMP_MIN,-999999)) <> NVL(l_single_gdsn_item_prod_rec.DELIVERY_TO_MRKT_TEMP_MIN,-999999))
402                OR (NVL(l_single_gdsn_item_pend_rec.DEL_TO_DIST_CNTR_TEMP_MAX, NVL(l_single_gdsn_item_prod_rec.DEL_TO_DIST_CNTR_TEMP_MAX,-999999)) <> NVL(l_single_gdsn_item_prod_rec.DEL_TO_DIST_CNTR_TEMP_MAX,-999999))
403                OR (NVL(l_single_gdsn_item_pend_rec.DEL_TO_DIST_CNTR_TEMP_MIN, NVL(l_single_gdsn_item_prod_rec.DEL_TO_DIST_CNTR_TEMP_MIN,-999999)) <> NVL(l_single_gdsn_item_prod_rec.DEL_TO_DIST_CNTR_TEMP_MIN,-999999))
404                OR (NVL(l_single_gdsn_item_pend_rec.STORAGE_HANDLING_TEMP_MAX, NVL(l_single_gdsn_item_prod_rec.STORAGE_HANDLING_TEMP_MAX,-999999)) <> NVL(l_single_gdsn_item_prod_rec.STORAGE_HANDLING_TEMP_MAX,-999999))
405                OR (NVL(l_single_gdsn_item_pend_rec.STORAGE_HANDLING_TEMP_MIN, NVL(l_single_gdsn_item_prod_rec.STORAGE_HANDLING_TEMP_MIN,-999999)) <> NVL(l_single_gdsn_item_prod_rec.STORAGE_HANDLING_TEMP_MIN,-999999))
406                OR (NVL(l_single_gdsn_item_pend_rec.UOM_DELIVERY_TO_MRKT_TEMP_MAX, NVL(l_single_gdsn_item_prod_rec.UOM_DELIVERY_TO_MRKT_TEMP_MAX,'!')) <> NVL(l_single_gdsn_item_prod_rec.UOM_DELIVERY_TO_MRKT_TEMP_MAX,'!'))
407                OR (NVL(l_single_gdsn_item_pend_rec.UOM_DELIVERY_TO_MRKT_TEMP_MIN, NVL(l_single_gdsn_item_prod_rec.UOM_DELIVERY_TO_MRKT_TEMP_MIN,'!')) <> NVL(l_single_gdsn_item_prod_rec.UOM_DELIVERY_TO_MRKT_TEMP_MIN,'!'))
408                OR (NVL(l_single_gdsn_item_pend_rec.UOM_DEL_TO_DIST_CNTR_TEMP_MAX, NVL(l_single_gdsn_item_prod_rec.UOM_DEL_TO_DIST_CNTR_TEMP_MAX,'!')) <> NVL(l_single_gdsn_item_prod_rec.UOM_DEL_TO_DIST_CNTR_TEMP_MAX,'!'))
409                OR (NVL(l_single_gdsn_item_pend_rec.UOM_DEL_TO_DIST_CNTR_TEMP_MIN, NVL(l_single_gdsn_item_prod_rec.UOM_DEL_TO_DIST_CNTR_TEMP_MIN,'!')) <> NVL(l_single_gdsn_item_prod_rec.UOM_DEL_TO_DIST_CNTR_TEMP_MIN,'!'))
410                OR (NVL(l_single_gdsn_item_pend_rec.UOM_STORAGE_HANDLING_TEMP_MAX, NVL(l_single_gdsn_item_prod_rec.UOM_STORAGE_HANDLING_TEMP_MAX,'!')) <> NVL(l_single_gdsn_item_prod_rec.UOM_STORAGE_HANDLING_TEMP_MAX,'!'))
411                OR (NVL(l_single_gdsn_item_pend_rec.UOM_STORAGE_HANDLING_TEMP_MIN, NVL(l_single_gdsn_item_prod_rec.UOM_STORAGE_HANDLING_TEMP_MIN,'!')) <> NVL(l_single_gdsn_item_prod_rec.UOM_STORAGE_HANDLING_TEMP_MIN,'!'))
412                THEN
413                     x_can_implement_status := 'NO';
414                     EXIT;
415                END IF;
416           END IF;   --   Temperature_Information
417 
418           --   Price_Information   GDSN Single Row Attribute Group
419           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'Price_Information' THEN
420                IF (NVL(l_single_gdsn_item_pend_rec.RETAIL_PRICE_ON_TRADE_ITEM, NVL(l_single_gdsn_item_prod_rec.RETAIL_PRICE_ON_TRADE_ITEM,-999999)) <> NVL(l_single_gdsn_item_prod_rec.RETAIL_PRICE_ON_TRADE_ITEM,-999999))
421                THEN
422                     x_can_implement_status := 'NO';
423                     EXIT;
424                END IF;
425           END IF;   --   Price_Information
426 
427           --   Material_Safety_Data   GDSN Single Row Attribute Group
428           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'Material_Safety_Data' THEN
429                IF (NVL(l_single_gdsn_item_pend_rec.MATERIAL_SAFETY_DATA_SHEET_NO, NVL(l_single_gdsn_item_prod_rec.MATERIAL_SAFETY_DATA_SHEET_NO,'!')) <> NVL(l_single_gdsn_item_prod_rec.MATERIAL_SAFETY_DATA_SHEET_NO,'!'))
430                THEN
431                     x_can_implement_status := 'NO';
432                     EXIT;
433                END IF;
434           END IF;   --   Material_Safety_Data
435 
436           --   Date_Information   GDSN Single Row Attribute Group
437           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'Date_Information' THEN
438                IF (NVL(l_single_gdsn_item_pend_rec.CANCELED_DATE, NVL(l_single_gdsn_item_prod_rec.CANCELED_DATE,to_date('''1''','''j'''))) <> NVL(l_single_gdsn_item_prod_rec.CANCELED_DATE,to_date('''1''','''j''')))
439                OR (NVL(l_single_gdsn_item_pend_rec.CONSUMER_AVAIL_DATE_TIME, NVL(l_single_gdsn_item_prod_rec.CONSUMER_AVAIL_DATE_TIME,to_date('''1''','''j'''))) <> NVL(l_single_gdsn_item_prod_rec.CONSUMER_AVAIL_DATE_TIME,to_date('''1''','''j''')))
440                OR (NVL(l_single_gdsn_item_pend_rec.DISCONTINUED_DATE, NVL(l_single_gdsn_item_prod_rec.DISCONTINUED_DATE,to_date('''1''','''j'''))) <> NVL(l_single_gdsn_item_prod_rec.DISCONTINUED_DATE,to_date('''1''','''j''')))
441                OR (NVL(l_single_gdsn_item_pend_rec.EFFECTIVE_DATE, NVL(l_single_gdsn_item_prod_rec.EFFECTIVE_DATE,to_date('''1''','''j'''))) <> NVL(l_single_gdsn_item_prod_rec.EFFECTIVE_DATE,to_date('''1''','''j''')))
442                OR (NVL(l_single_gdsn_item_pend_rec.END_AVAILABILITY_DATE_TIME, NVL(l_single_gdsn_item_prod_rec.END_AVAILABILITY_DATE_TIME,to_date('''1''','''j'''))) <> NVL(l_single_gdsn_item_prod_rec.END_AVAILABILITY_DATE_TIME,to_date('''1''','''j''')))
443                OR (NVL(l_single_gdsn_item_pend_rec.START_AVAILABILITY_DATE_TIME, NVL(l_single_gdsn_item_prod_rec.START_AVAILABILITY_DATE_TIME,to_date('''1''','''j'''))) <>
444                     NVL(l_single_gdsn_item_prod_rec.START_AVAILABILITY_DATE_TIME,to_date('''1''','''j''')))
445                THEN
446                     x_can_implement_status := 'NO';
447                     EXIT;
448                END IF;
449           END IF;   --   Date_Information
450 
451           --   Order_Information   GDSN Single Row Attribute Group
452           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'Order_Information' THEN
453                IF (NVL(l_single_gdsn_item_pend_rec.ORDERING_LEAD_TIME, NVL(l_single_gdsn_item_prod_rec.ORDERING_LEAD_TIME,-999999)) <> NVL(l_single_gdsn_item_prod_rec.ORDERING_LEAD_TIME,-999999))
454                OR (NVL(l_single_gdsn_item_pend_rec.ORDER_QUANTITY_MAX, NVL(l_single_gdsn_item_prod_rec.ORDER_QUANTITY_MAX,-999999)) <> NVL(l_single_gdsn_item_prod_rec.ORDER_QUANTITY_MAX,-999999))
455                OR (NVL(l_single_gdsn_item_pend_rec.ORDER_QUANTITY_MIN, NVL(l_single_gdsn_item_prod_rec.ORDER_QUANTITY_MIN,-999999)) <> NVL(l_single_gdsn_item_prod_rec.ORDER_QUANTITY_MIN,-999999))
456                OR (NVL(l_single_gdsn_item_pend_rec.ORDER_QUANTITY_MULTIPLE, NVL(l_single_gdsn_item_prod_rec.ORDER_QUANTITY_MULTIPLE,-999999)) <> NVL(l_single_gdsn_item_prod_rec.ORDER_QUANTITY_MULTIPLE,-999999))
457                OR (NVL(l_single_gdsn_item_pend_rec.ORDER_SIZING_FACTOR, NVL(l_single_gdsn_item_prod_rec.ORDER_SIZING_FACTOR,-999999)) <> NVL(l_single_gdsn_item_prod_rec.ORDER_SIZING_FACTOR,-999999))
458                THEN
459                     x_can_implement_status := 'NO';
460                     EXIT;
461                END IF;
462           END IF;   --   Order_Information
463 
464           --   Uccnet_Size_Description   GDSN Single Row Attribute Group
465           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'Uccnet_Size_Description' THEN
466                IF (NVL(l_single_gdsn_item_pend_rec.DESCRIPTIVE_SIZE, NVL(l_single_gdsn_item_prod_rec.DESCRIPTIVE_SIZE,'!')) <> NVL(l_single_gdsn_item_prod_rec.DESCRIPTIVE_SIZE,'!'))
467                THEN
468                     x_can_implement_status := 'NO';
469                     EXIT;
470                END IF;
471           END IF;   --   Uccnet_Size_Description
472 
473           --   FMCG_Measurements   GDSN Single Row Attribute Group
474           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'FMCG_Measurements' THEN
475                IF (NVL(l_single_gdsn_item_pend_rec.DEGREE_OF_ORIGINAL_WORT, NVL(l_single_gdsn_item_prod_rec.DEGREE_OF_ORIGINAL_WORT,'!')) <> NVL(l_single_gdsn_item_prod_rec.DEGREE_OF_ORIGINAL_WORT,'!'))
476                OR (NVL(l_single_gdsn_item_pend_rec.FAT_PERCENT_IN_DRY_MATTER, NVL(l_single_gdsn_item_prod_rec.FAT_PERCENT_IN_DRY_MATTER,-999999)) <> NVL(l_single_gdsn_item_prod_rec.FAT_PERCENT_IN_DRY_MATTER,-999999))
477                OR (NVL(l_single_gdsn_item_pend_rec.PERCENT_OF_ALCOHOL_BY_VOL, NVL(l_single_gdsn_item_prod_rec.PERCENT_OF_ALCOHOL_BY_VOL,-999999)) <> NVL(l_single_gdsn_item_prod_rec.PERCENT_OF_ALCOHOL_BY_VOL,-999999))
478                THEN
479                     x_can_implement_status := 'NO';
480                     EXIT;
481                END IF;
482           END IF;   --   FMCG_Measurements
483 
484           --   FMCG_Measurements   GDSN Single Row Attribute Group
485           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'FMCG_Measurements' THEN
486                IF (NVL(l_single_gdsn_item_pend_rec.DEGREE_OF_ORIGINAL_WORT, NVL(l_single_gdsn_item_prod_rec.DEGREE_OF_ORIGINAL_WORT,'!')) <> NVL(l_single_gdsn_item_prod_rec.DEGREE_OF_ORIGINAL_WORT,'!'))
487                OR (NVL(l_single_gdsn_item_pend_rec.FAT_PERCENT_IN_DRY_MATTER, NVL(l_single_gdsn_item_prod_rec.FAT_PERCENT_IN_DRY_MATTER,-999999)) <> NVL(l_single_gdsn_item_prod_rec.FAT_PERCENT_IN_DRY_MATTER,-999999))
488                OR (NVL(l_single_gdsn_item_pend_rec.PERCENT_OF_ALCOHOL_BY_VOL, NVL(l_single_gdsn_item_prod_rec.PERCENT_OF_ALCOHOL_BY_VOL,-999999)) <> NVL(l_single_gdsn_item_prod_rec.PERCENT_OF_ALCOHOL_BY_VOL,-999999))
489                THEN
490                     x_can_implement_status := 'NO';
491                     EXIT;
492                END IF;
493           END IF;   --   FMCG_Measurements
494 
495           --   FMCG_Identification   GDSN Single Row Attribute Group
496           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'FMCG_Identification' THEN
497                IF (NVL(l_single_gdsn_item_pend_rec.ISBN_NUMBER, NVL(l_single_gdsn_item_prod_rec.ISBN_NUMBER,'!')) <> NVL(l_single_gdsn_item_prod_rec.ISBN_NUMBER,'!'))
498                OR (NVL(l_single_gdsn_item_pend_rec.ISSN_NUMBER, NVL(l_single_gdsn_item_prod_rec.ISSN_NUMBER,'!')) <> NVL(l_single_gdsn_item_prod_rec.ISSN_NUMBER,'!'))
499                THEN
500                     x_can_implement_status := 'NO';
501                     EXIT;
502                END IF;
503           END IF;   --   FMCG_Identification
504 
505           --   FMCG_MARKING   GDSN Single Row Attribute Group
506           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'FMCG_MARKING' THEN
507                IF (NVL(l_single_gdsn_item_pend_rec.IS_INGREDIENT_IRRADIATED, NVL(l_single_gdsn_item_prod_rec.IS_INGREDIENT_IRRADIATED,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_INGREDIENT_IRRADIATED,'!'))
508                OR (NVL(l_single_gdsn_item_pend_rec.IS_RAW_MATERIAL_IRRADIATED, NVL(l_single_gdsn_item_prod_rec.IS_RAW_MATERIAL_IRRADIATED,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_RAW_MATERIAL_IRRADIATED,'!'))
509                OR (NVL(l_single_gdsn_item_pend_rec.IS_TRADE_ITEM_GENETICALLY_MOD, NVL(l_single_gdsn_item_prod_rec.IS_TRADE_ITEM_GENETICALLY_MOD,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_TRADE_ITEM_GENETICALLY_MOD,'!'))
510                OR (NVL(l_single_gdsn_item_pend_rec.IS_TRADE_ITEM_IRRADIATED, NVL(l_single_gdsn_item_prod_rec.IS_TRADE_ITEM_IRRADIATED,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_TRADE_ITEM_IRRADIATED,'!'))
511                THEN
512                     x_can_implement_status := 'NO';
513                     EXIT;
514                END IF;
515           END IF;   --   FMCG_MARKING
516 
517           --   Uccnet_Hardlines   GDSN Single Row Attribute Group
518           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'Uccnet_Hardlines' THEN
519                IF (NVL(l_single_gdsn_item_pend_rec.DEPT_OF_TRNSPRT_DANG_GOODS_NUM, NVL(l_single_gdsn_item_prod_rec.DEPT_OF_TRNSPRT_DANG_GOODS_NUM,'!')) <> NVL(l_single_gdsn_item_prod_rec.DEPT_OF_TRNSPRT_DANG_GOODS_NUM,'!'))
520                OR (NVL(l_single_gdsn_item_pend_rec.IS_OUT_OF_BOX_PROVIDED, NVL(l_single_gdsn_item_prod_rec.IS_OUT_OF_BOX_PROVIDED,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_OUT_OF_BOX_PROVIDED,'!'))
521                OR (NVL(l_single_gdsn_item_pend_rec.IS_TRADE_ITEM_RECALLED, NVL(l_single_gdsn_item_prod_rec.IS_TRADE_ITEM_RECALLED,'!')) <> NVL(l_single_gdsn_item_prod_rec.IS_TRADE_ITEM_RECALLED,'!'))
522                OR (NVL(l_single_gdsn_item_pend_rec.MODEL_NUMBER, NVL(l_single_gdsn_item_prod_rec.MODEL_NUMBER,'!')) <> NVL(l_single_gdsn_item_prod_rec.MODEL_NUMBER,'!'))
523                OR (NVL(l_single_gdsn_item_pend_rec.RETURN_GOODS_POLICY, NVL(l_single_gdsn_item_prod_rec.RETURN_GOODS_POLICY,'!')) <> NVL(l_single_gdsn_item_prod_rec.RETURN_GOODS_POLICY,'!'))
524                OR (NVL(l_single_gdsn_item_pend_rec.URL_FOR_WARRANTY, NVL(l_single_gdsn_item_prod_rec.URL_FOR_WARRANTY,'!')) <> NVL(l_single_gdsn_item_prod_rec.URL_FOR_WARRANTY,'!'))
525                OR (NVL(l_single_gdsn_item_pend_rec.WARRANTY_DESCRIPTION, NVL(l_single_gdsn_item_prod_rec.WARRANTY_DESCRIPTION,'!')) <> NVL(l_single_gdsn_item_prod_rec.WARRANTY_DESCRIPTION,'!'))
526                OR (NVL(l_single_gdsn_item_pend_rec.NESTING_INCREMENT, NVL(l_single_gdsn_item_prod_rec.NESTING_INCREMENT,-999999)) <> NVL(l_single_gdsn_item_prod_rec.NESTING_INCREMENT,-999999))
527                OR (NVL(l_single_gdsn_item_pend_rec.PIECES_PER_TRADE_ITEM, NVL(l_single_gdsn_item_prod_rec.PIECES_PER_TRADE_ITEM,-999999)) <> NVL(l_single_gdsn_item_prod_rec.PIECES_PER_TRADE_ITEM,-999999))
528                THEN
529                     x_can_implement_status := 'NO';
530                     EXIT;
531                END IF;
532           END IF;   --   Uccnet_Hardlines
533 
534           --   Security_Tag   GDSN Single Row Attribute Group
535           IF single_attr_grps_cur.attr_group_id = p_attr_group_id AND single_attr_grps_cur.attr_group_name = 'Security_Tag' THEN
536                IF (NVL(l_single_gdsn_item_pend_rec.SECURITY_TAG_LOCATION, NVL(l_single_gdsn_item_prod_rec.SECURITY_TAG_LOCATION,'!')) <> NVL(l_single_gdsn_item_prod_rec.SECURITY_TAG_LOCATION,'!'))
537                THEN
538                     x_can_implement_status := 'NO';
539                     EXIT;
540                END IF;
541           END IF;   --   Security_Tag
542 
543        END LOOP;    --   single row attr groups cursor loop
544   END IF;
545   IF x_can_implement_status = 'NO' THEN
546      RETURN;
547   END IF;
548 
549 EXCEPTION
550   WHEN OTHERS THEN
551      x_can_implement_status := 'NO';
552      RAISE abort_implementation;
553 
554 END Chk_GDSN_SingleRow_Chgs_Exist;
555 
556 PROCEDURE Can_Implement_Item ( p_change_line_id IN NUMBER,
557                                x_implementation_status OUT NOCOPY VARCHAR2
558                              )
559 IS
560   l_org_id NUMBER;
561   l_inventory_item_id NUMBER;
562   l_item_catalog_cat_id NUMBER;
563   l_item_lifecycle_id NUMBER;
564   l_item_current_phase_id NUMBER;
565   l_current_attr_group_id NUMBER;
566   l_can_implement_status VARCHAR2(30);
567   l_pending_changes_count NUMBER;
568   l_attribute_group_type VARCHAR2(50);
569   l_concatenated_segments VARCHAR2(100);
570   abort_implementation exception;
571 
572      Cursor cur_item_change_not_allowed IS
573           SELECT pv.policy_char_value, r.attribute_number_value, ra.attribute_code
574           FROM eng_change_policies p, eng_change_policy_values pv, eng_change_rules r, eng_change_rule_attributes_vl ra
575           WHERE p.policy_object_pk1_value = l_item_catalog_cat_id
576           and p.policy_object_pk2_value = l_item_lifecycle_id
577           and p.policy_object_pk3_value = l_item_current_phase_id
578           AND pv.POLICY_CHAR_VALUE='NOT_ALLOWED'
579           and pv.change_rule_id = r.change_rule_id
580           and r.attribute_object_name = ra.attribute_object_name
581           and r.attribute_code = ra.attribute_code
582           AND p.change_policy_id = pv.change_policy_id
583           AND p.policy_object_name = 'CATALOG_LIFECYCLE_PHASE'
584           and p.policy_code= 'CHANGE_POLICY'
585           and ra.attribute_object_name = 'EGO_CATALOG_GROUP';
586 BEGIN
587   l_can_implement_status := 'YES';
588 /*
589 PROMOTE_DEMOTE      1
590 PROMOTE_DEMOTE      2
591 PROMOTE_DEMOTE      3
592 AML_RULE            1    AML
593 AML_RULE            2    Related Documents        ENG_RELATIONSHIP_CHANGES
594 STRUCTURE_TYPE
595 ATTRIBUTE_GROUP     id   Attr Group Id
596 ATTACHMENT
597 */
598 
599   -- First get the item information
600   SELECT revised_item_id, organization_id
601   INTO l_inventory_item_id, l_org_id
602   FROM eng_revised_items
603   WHERE revised_item_sequence_id = p_change_line_id;
604   -- Get the item details
605   SELECT item_catalog_group_id, lifecycle_id, current_phase_id , concatenated_segments
606   INTO l_item_catalog_cat_id, l_item_lifecycle_id, l_item_current_phase_id, l_concatenated_segments
607   FROM mtl_system_items_kfv
608   WHERE inventory_item_id = l_inventory_item_id
609   AND organization_id = l_org_id;
610 
611   -- Check whether there are any change policies for the current phase of item at any level which are not allowed
612   FOR rev_items IN cur_item_change_not_allowed
613   LOOP
614 
615       IF 'ATTRIBUTE_GROUP' = rev_items.attribute_code THEN       --   Attribute Groups
616           --   Get the attribute group id
617           l_current_attr_group_id := rev_items.attribute_number_value;
618           SELECT attr_group_type INTO l_attribute_group_type FROM ego_attr_groups_v WHERE attr_group_id = l_current_attr_group_id;
619 
620           IF l_attribute_group_type = 'EGO_ITEMMGMT_GROUP' THEN
621                --   Check if there are any UDA pending changes done through this Change Order for this attribute group
622                SELECT count(*) INTO l_pending_changes_count
623                FROM ego_items_attrs_changes_b
624                WHERE change_line_id = p_change_line_id
625                AND attr_group_id = l_current_attr_group_id
626 	       AND data_level_id not in (43103,43104,43105);	--  Bug 6439100 Supplier datalevels change policy not supported
627 
628                IF l_pending_changes_count > 0 THEN
629 FND_FILE.PUT_LINE(FND_FILE.LOG, 'Cannot Implement the Revised Item '|| l_concatenated_segments || ' because there is a change policy NOT_ALLOWED on User Defined Attribute Group with Id ' || l_current_attr_group_id);
630                     l_can_implement_status := 'NO';
631                     EXIT;
632                 END IF;
633           END IF;
634 /*
635           --   Not required to check here. EGO_ITEM_PUB.process_item() API will do the change policy check
636           IF l_attribute_group_type = 'EGO_MASTER_ITEMS' THEN
637           END IF;
638 */
639           -- Check if there are item GDSN Singlerow attribute group changes
640           IF l_attribute_group_type = 'EGO_ITEM_GTIN_ATTRS' THEN
641                Chk_GDSN_SingleRow_Chgs_Exist(p_change_line_id => p_change_line_id,
642                                         p_attr_group_id => l_current_attr_group_id,
643                                         x_can_implement_status => l_can_implement_status);
644 
645                IF l_can_implement_status = 'NO' THEN
646 FND_FILE.PUT_LINE(FND_FILE.LOG, 'Cannot Implement the Revised Item '|| l_concatenated_segments || ' because there is a change policy NOT_ALLOWED on GDSN Singlerow Attribute Group with Id ' || l_current_attr_group_id);
647                     EXIT;
648                 END IF;
649           END IF;
650 
651           -- Check if there are item GDSN Multirow attribute group changes
652           IF l_attribute_group_type = 'EGO_ITEM_GTIN_MULTI_ATTRS' THEN
653                SELECT count(*) INTO l_pending_changes_count
654                FROM ego_gtn_mul_attr_chg_vl
655                WHERE change_line_id = p_change_line_id
656                AND attr_group_id = l_current_attr_group_id
657                AND implementation_date IS NULL;
658 
659                IF l_pending_changes_count > 0 THEN
660 FND_FILE.PUT_LINE(FND_FILE.LOG, 'Cannot Implement the Revised Item '|| l_concatenated_segments || ' because there is a change policy NOT_ALLOWED on GDSN Multirow Attribute Group with Id ' || l_current_attr_group_id);
661                     l_can_implement_status := 'NO';
662                     EXIT;
663                 END IF;
664           END IF;
665 
666       END IF;  --   All Attribute groups
667 
668       --  Promote/Demote change policy check should be done for revision creation
669       IF 'PROMOTE_DEMOTE' = rev_items.attribute_code AND rev_items.attribute_number_value = 3 THEN       --    New Revision for item
670           --   Check whether a new revision is created with this change order for the item
671           SELECT count(*) INTO l_pending_changes_count
672           FROM mtl_item_revisions
673           WHERE inventory_item_id = l_inventory_item_id
674           AND organization_id = l_org_id
675           AND revised_item_sequence_id = p_change_line_id
676           AND change_notice = ( SELECT change_notice FROM eng_engineering_changes
677                                    WHERE change_id in (SELECT change_id FROM eng_revised_items
678                                                        WHERE revised_item_sequence_id = p_change_line_id))
679           AND implementation_date IS NULL;
680 
681           IF l_pending_changes_count > 0 THEN
682 FND_FILE.PUT_LINE(FND_FILE.LOG, 'Cannot Implement the Revised Item '|| l_concatenated_segments || ' because there is a change policy NOT_ALLOWED on New Revision creation for the item.' );
683                l_can_implement_status := 'NO';
684                EXIT;
685           END IF;
686       END IF;
687 
688       IF 'AML_RULE' = rev_items.attribute_code AND rev_items.attribute_number_value = 1 THEN   --   AML Changes
689 
690           SELECT count(*) INTO l_pending_changes_count
691           FROM ego_mfg_part_num_chgs
692           WHERE change_line_id = p_change_line_id
693           AND implmentation_date IS NULL;
694 
695           IF l_pending_changes_count > 0 THEN
696 FND_FILE.PUT_LINE(FND_FILE.LOG, 'Cannot Implement the Revised Item '|| l_concatenated_segments || ' because there is a change policy NOT_ALLOWED on AML Associations.');
697                l_can_implement_status := 'NO';
698                EXIT;
699            END IF;
700       END IF;
701 
702       IF 'AML_RULE' = rev_items.attribute_code AND rev_items.attribute_number_value = 2 THEN   --   Related Documents Changes
703 
704           SELECT count(*) INTO l_pending_changes_count
705           FROM eng_relationship_changes
706           WHERE entity_id = p_change_line_id;
707 
708           IF l_pending_changes_count > 0 THEN
709 FND_FILE.PUT_LINE(FND_FILE.LOG, 'Cannot Implement the Revised Item '|| l_concatenated_segments || ' because there is a change policy NOT_ALLOWED on Related Document Changes.');
710                l_can_implement_status := 'NO';
711                EXIT;
712           END IF;
713       END IF;
714 
715       IF 'STRUCTURE_TYPE' = rev_items.attribute_code THEN        --   Structure Changes
716 
717           l_current_attr_group_id := rev_items.attribute_number_value;
718 
719           --   Check whether there are any structures created for the item with this change order ..
720           SELECT count(*) INTO l_pending_changes_count
721           FROM bom_bill_of_materials
722           WHERE assembly_item_id = l_inventory_item_id
723           AND organization_id = l_org_id
724           AND structure_type_id = l_current_attr_group_id
725           AND pending_from_ecn = ( SELECT change_notice FROM eng_engineering_changes
726                                    WHERE change_id in (SELECT change_id FROM eng_revised_items
727                                                        WHERE revised_item_sequence_id = p_change_line_id));
728 
729           IF l_pending_changes_count > 0 THEN
730 FND_FILE.PUT_LINE(FND_FILE.LOG, 'Cannot Implement the Revised Item '|| l_concatenated_segments || ' because there is a change policy NOT_ALLOWED on Structure Changes with structure type id ' || l_current_attr_group_id);
731                l_can_implement_status := 'NO';
732                EXIT;
733           END IF;
734 
735           --   Check whether there are any component changes created for the item with this change order ..
736           SELECT count(*) INTO l_pending_changes_count
737           FROM bom_components_b comp, bom_bill_of_materials bom
738           WHERE revised_item_sequence_id = p_change_line_id
739           AND comp.implementation_date IS NULL
740           AND comp.bill_sequence_id = bom.bill_sequence_id
741           AND bom.structure_type_id = l_current_attr_group_id
742           AND comp.change_notice = ( SELECT change_notice FROM eng_engineering_changes
743                                    WHERE change_id in (SELECT change_id FROM eng_revised_items
744                                                        WHERE revised_item_sequence_id = p_change_line_id));
745 
746           IF l_pending_changes_count > 0 THEN
747 FND_FILE.PUT_LINE(FND_FILE.LOG, 'Cannot Implement the Revised Item '|| l_concatenated_segments || ' because there is a change policy NOT_ALLOWED on Component Changes with structure type id ' || l_current_attr_group_id);
748                l_can_implement_status := 'NO';
749                EXIT;
750           END IF;
751 
752           --   Check whether there are any operations changes created for the item with this change order ..
753           SELECT count(st.structure_type_id) INTO l_pending_changes_count
754           FROM bom_operation_sequences op, eng_revised_items ri , bom_structure_types_vl st
755           WHERE op.revised_item_sequence_id = p_change_line_id
756           AND op.revised_item_sequence_id = ri.revised_item_sequence_id
757           AND op.implementation_date IS NULL
758           AND st.structure_type_id = ( SELECT bbom.structure_type_id
759                                     FROM bom_bill_of_materials bbom
760                                     WHERE bbom.bill_sequence_id = ri.bill_sequence_id )
761           AND st.structure_type_id = l_current_attr_group_id
762           AND op.change_notice = ( SELECT change_notice FROM eng_engineering_changes
763                                    WHERE change_id in (SELECT change_id FROM eng_revised_items
764                                                        WHERE revised_item_sequence_id = p_change_line_id));
765 
766           IF l_pending_changes_count > 0 THEN
767 FND_FILE.PUT_LINE(FND_FILE.LOG, 'Cannot Implement the Revised Item '|| l_concatenated_segments || ' because there is a change policy NOT_ALLOWED on Operations Changes with structure type id ' || l_current_attr_group_id);
768                l_can_implement_status := 'NO';
769                EXIT;
770           END IF;
771 
772       END IF;
773 
774       IF 'ATTACHMENT' = rev_items.attribute_code THEN            --   Attachment Changes
775           l_current_attr_group_id := rev_items.attribute_number_value;
776 
777           SELECT count(*) INTO l_pending_changes_count
778           FROM eng_attachment_changes
779           WHERE revised_item_sequence_id = p_change_line_id
780           AND category_id = l_current_attr_group_id;   --   ?
781 
782           IF l_pending_changes_count > 0 THEN
783 FND_FILE.PUT_LINE(FND_FILE.LOG, 'Cannot Implement the Revised Item '|| l_concatenated_segments || ' because there is a change policy NOT_ALLOWED on Attachment Changes with Category type id ' || l_current_attr_group_id);
784                l_can_implement_status := 'NO';
785                EXIT;
786           END IF;
787       END IF;
788 
789   END LOOP;
790 
791   x_implementation_status := l_can_implement_status;
792 EXCEPTION
793   WHEN OTHERS THEN
794      x_implementation_status := 'NO';
795      RAISE abort_implementation;
796 
797 END Can_Implement_Item;
798 
799 -- Added procedure for bug 3402607
800 /********************************************************************
801  * API Name      : LOG_IMPLEMENT_FAILURE
802  * Parameters IN : p_change_id, p_revised_item_seq_id
803  * Parameters OUT: None
804  * Purpose       : Used to update the lifecycle states of the header
805  * and create a log in header Action Log if implementation fails.
806  * In case of revised item implementation failure, updates the revised
807  * item status_type
808  *********************************************************************/
809 PROCEDURE LOG_IMPLEMENT_FAILURE(p_change_id IN NUMBER
810                               , p_revised_item_seq_id IN NUMBER) IS
811         l_plsql_block           VARCHAR2(1000);
812         l_api_caller            VARCHAR2(3) := 'CP';
813         l_msg_count             NUMBER := 0;
814         l_return_status         VARCHAR2(1);
815         l_msg_data              VARCHAR2(2000);
816 
817     -- Changes for bug 4642163
818    l_rev_item_sts_type  eng_revised_items.status_type%TYPE;
819    l_plm_or_erp_change  eng_engineering_changes.plm_or_erp_change%TYPE;
820 
821    CURSOR c_get_rev_item_status_type
822    IS
823    SELECT ecs.status_type
824       FROM eng_change_statuses ecs, eng_revised_items eri
825       WHERE ecs.status_code = eri.status_code
826       AND eri.revised_item_sequence_id = p_revised_item_seq_id;
827 
828    CURSOR c_plm_or_erp
829    IS
830    SELECT nvl(plm_or_erp_change, 'PLM') plm_or_erp
831       FROM eng_engineering_changes
832       WHERE change_id = p_change_id;
833    -- End changes for bug 4642163
834 
835 BEGIN
836     -- Changes for bug 3720341
837     -- If p_revised_item_seq_id is null, then the implementation failure is
838     -- logged at the header level. Affects the status_type and change header lifecycle
839     IF (p_revised_item_seq_id IS NULL OR p_revised_item_seq_id = 0)
840     THEN
841         -- Using dynamic sql as the package has call to workflow apis which are not included in the
842         -- ENG patchset
843         l_plsql_block := 'begin ENG_CHANGE_LIFECYCLE_UTIL.Update_Lifecycle_States('
844                         || 'p_api_version       => 1.0  '
845                         || ',p_change_id        => :1   ' -- l_change_id
846                         || ',p_status_code      => 10   '
847                         || ',p_api_caller       => :2   ' -- 'CP'
848                         || ',p_wf_route_id      => NULL '
849                         || ',p_route_status     => NULL '
850                         || ',x_return_status    => :3   ' -- l_return_status
851                         || ',x_msg_count        => :4   ' -- l_msg_count
852                         || ',x_msg_data         => :5   );'  -- l_msg_data
853                         || 'end;';
854 
855         EXECUTE IMMEDIATE l_plsql_block USING IN p_change_id, IN l_api_caller,
856         OUT l_return_status, OUT l_msg_count, OUT l_msg_data;
857     ELSE
858     /* IF p_revised_item_seq_id is  not null, then the implementation failure is
859      logged at the revised item level. Affects the status_type (set to 10)
860         l_plsql_block := 'begin ENG_CHANGE_LIFECYCLE_UTIL.Update_RevItem_Lifecycle('
861                         || 'p_api_version       => 1.0  '
862                         || ',p_rev_item_seq_id  => :1   ' -- p_revised_item_seq_id
863                         || ',p_status_type      => 10   '
864                         || ',p_api_caller       => :2   ' -- 'CP'
865                         || ',x_return_status    => :3   ' -- l_return_status
866                         || ',x_msg_count        => :4   ' -- l_msg_count
867                         || ',x_msg_data         => :5   );'  -- l_msg_data
868                         || 'end;';
869 
870        EXECUTE IMMEDIATE l_plsql_block USING IN p_revised_item_seq_id, IN l_api_caller,
871         OUT l_return_status, OUT l_msg_count, OUT l_msg_data;
872    END IF;*/
873    -- Changes for bug 4642163
874     OPEN c_plm_or_erp;
875     FETCH c_plm_or_erp INTO l_plm_or_erp_change;
876     CLOSE c_plm_or_erp;
877     -- Fetch the correct status type if it is ERP ECO else
878     -- set the status type as implementation failed
879     IF (l_plm_or_erp_change = 'PLM')
880     THEN
881       l_rev_item_sts_type := 10;
882     ELSE
883       OPEN c_get_rev_item_status_type;
884       FETCH c_get_rev_item_status_type INTO l_rev_item_sts_type;
885       CLOSE c_get_rev_item_status_type;
886     END IF;
887     -- IF p_revised_item_seq_id is  not null, then the implementation failure is
888     -- logged at the revised item level. Affects the status_type (set to 10)
889     l_plsql_block := 'begin ENG_CHANGE_LIFECYCLE_UTIL.Update_RevItem_Lifecycle('
890             || 'p_api_version       => 1.0  '
891             || ',p_rev_item_seq_id  => :1   ' -- p_revised_item_seq_id
892             || ',p_status_type      => :2   '
893             || ',p_api_caller       => :3   ' -- 'CP'
894             || ',x_return_status    => :4   ' -- l_return_status
895             || ',x_msg_count        => :5   ' -- l_msg_count
896             || ',x_msg_data         => :6 );'  -- l_msg_data
897             || 'end;';
898 
899     EXECUTE IMMEDIATE l_plsql_block
900             USING IN  p_revised_item_seq_id
901                 , IN  l_rev_item_sts_type
902                 , IN  l_api_caller
903                 , OUT l_return_status
904                 , OUT l_msg_count
905                 , OUT l_msg_data;
906     -- End changes for 4642163
907      END IF;
908     commit;
909 EXCEPTION
910 WHEN PLSQL_COMPILE_ERROR THEN
911     -- changes for 4642163
912     IF c_plm_or_erp%ISOPEN THEN
913       CLOSE c_plm_or_erp;
914     END IF;
915     IF c_get_rev_item_status_type%ISOPEN THEN
916       CLOSE c_get_rev_item_status_type;
917     END IF;
918         -- package is not found when called using dynamic sql
919         -- ok to proceed
920         -- null;
921 WHEN OTHERS THEN
922     -- changes for 4642163
923     IF c_plm_or_erp%ISOPEN THEN
924       CLOSE c_plm_or_erp;
925     END IF;
926     IF c_get_rev_item_status_type%ISOPEN THEN
927       CLOSE c_get_rev_item_status_type;
928     END IF;
929         -- Nothing is required to be done
930         -- logging fails
931         --  null;
932 END LOG_IMPLEMENT_FAILURE;
933 
934 -- ERES change begins
935 PROCEDURE event_acknowledgement (p_event_status IN VARCHAR2) IS
936 
937 CURSOR Get_Parent_Child_Events IS
938 SELECT parent_event_name
939 , parent_event_key
940 , parent_erecord_id
941 , event_name
942 , event_key
943 , erecord_id
944 , event_status
945 FROM eng_parent_child_events_temp;
946 
947 l_erecord_id            NUMBER;
948 l_parent_child_count    NUMBER;
949 l_return_status         VARCHAR2(2);
950 l_msg_data              VARCHAR2(240);
951 l_msg_count             NUMBER;
952 l_dummy_cnt             NUMBER;
953 l_trans_status          VARCHAR2(10);
954 l_ackn_by               VARCHAR2(200);
955 SEND_ACKN_ERROR         EXCEPTION;
956 
957 BEGIN
958 -- Acknowledgement part :
959 -- for all the events raised in the process.
960 
961 -- Get message that will be send to SEND_ACKN :
962 FND_MESSAGE.SET_NAME('ENG', 'ENG_ERES_ACKN_ECO_IMPLEMENT');
963 l_ackn_by := FND_MESSAGE.GET;
964 
965 FOR my_events IN Get_Parent_Child_Events
966 LOOP
967 
968   IF (p_event_status = 'SUCCESS')
969   THEN
970      l_trans_status := 'SUCCESS';
971   ELSE
972      l_trans_status := 'ERROR';
973   END IF;
974   l_erecord_id := my_events.erecord_id;
975   FND_FILE.PUT_LINE(FND_FILE.LOG, 'Acknowledgement for ev_name='||my_events.event_name||', key='||my_events.event_key||', erec_id='||my_events.erecord_id||', stat='||l_trans_status);
976 
977   IF l_erecord_id IS NOT NULL
978   THEN
979     -- In case of error, autonomousCommit = TRUE
980     QA_EDR_STANDARD.SEND_ACKN
981           ( p_api_version       => 1.0
982           , p_init_msg_list     => FND_API.G_FALSE
983           , x_return_status     => l_return_status
984           , x_msg_count         => l_msg_count
985           , x_msg_data          => l_msg_data
986           , p_event_name        => my_events.event_name
987           , p_event_key         => my_events.event_key
988           , p_erecord_id        => my_events.erecord_id
989           , p_trans_status      => l_trans_status
990           , p_ackn_by           => l_ackn_by
991           , p_ackn_note         => my_events.event_name||', '||my_events.event_key
992           , p_autonomous_commit => FND_API.G_TRUE);
993 
994     FND_FILE.PUT_LINE(FND_FILE.LOG, 'After QA_EDR_STANDARD.SEND_ACKN msg='||l_msg_count);
995     IF (NVL(l_return_status, FND_API.G_FALSE) <> FND_API.G_TRUE)
996       AND (l_msg_count > 0)
997     THEN
998        RAISE SEND_ACKN_ERROR;
999     END IF;
1000   END IF;
1001 
1002   DELETE FROM eng_parent_child_events_temp
1003   WHERE erecord_id = my_events.erecord_id
1004   AND parent_erecord_id = my_events.parent_erecord_id;
1005 
1006 --  select count(*) INTO l_parent_child_count from eng_parent_child_events_temp;
1007 --  FND_FILE.PUT_LINE(FND_FILE.LOG, 'eng_parent_child_events_temp count='||l_parent_child_count);
1008 END LOOP;
1009 FND_FILE.PUT_LINE(FND_FILE.LOG, 'Normal end of acknowledgement part ');
1010 
1011 EXCEPTION
1012 WHEN SEND_ACKN_ERROR THEN
1013    FND_MSG_PUB.Get(
1014      p_msg_index  => 1,
1015      p_data       => l_msg_data,
1016      p_encoded    => FND_API.G_FALSE,
1017      p_msg_index_out => l_dummy_cnt);
1018    FND_FILE.PUT_LINE(FND_FILE.LOG, 'ACKN Error: '||l_msg_data);
1019 
1020 WHEN OTHERS THEN
1021    l_msg_data := 'ACKN Others Error='||SQLERRM;
1022    FND_FILE.PUT_LINE(FND_FILE.LOG, l_msg_data);
1023 
1024 END event_acknowledgement;
1025 -- ERES change ends
1026 
1027 
1028 /***********************************************************************************
1029 
1030 procedure       CHECK_ONHAND
1031  This procedure checks if there is any onhand qty available
1032  If onhand qty is found it returns FND_API.G_TRUE
1033 
1034 arguments
1035  p_inventory_item_id :config item id
1036  p_org_id            : given org id
1037  x_return_status     : FND_API.G_TRUE
1038 
1039 **********************************************************************************/
1040 PROCEDURE CHECK_ONHAND(
1041                              p_inventory_item_id     IN     NUMBER,
1042                              p_org_id                IN     NUMBER,
1043                              x_return_status         OUT NOCOPY    VARCHAR2
1044                       )
1045 IS
1046       xdummy   number;
1047 BEGIN
1048       x_return_status := FND_API.G_FALSE;
1049 
1050       select transaction_quantity into xdummy
1051       from  mtl_onhand_quantities
1052       where inventory_item_id = p_inventory_item_id
1053       and   organization_id = p_org_id
1054       and   transaction_quantity > 0;
1055 
1056       raise TOO_MANY_ROWS;      -- single row treated as too many rows
1057 
1058 EXCEPTION
1059       when no_data_found then
1060            null;        -- no onhand. ok to proceed.
1061 
1062       when too_many_rows then
1063            x_return_status := FND_API.G_TRUE;
1064 
1065       when others then
1066            x_return_status := FND_API.G_TRUE;
1067 
1068 
1069 END;
1070 
1071 
1072 
1073 
1074 -- 11.5.10 changes This function checks if there is any onhand qty available
1075 --If onhand qty is found it returns 1 else 0
1076 
1077 Function inv_onhand(p_item_id IN NUMBER,
1078                      p_org_id IN NUMBER) RETURN NUMBER IS
1079 l_return_status VARCHAR2(1);
1080 BEGIN
1081 
1082      CHECK_ONHAND(p_inventory_item_id =>p_item_id,
1083                        p_org_id      =>p_org_id,
1084                        x_return_status     =>l_return_status);
1085 
1086      if  (l_return_status     = FND_API.G_TRUE )
1087       then
1088         return 1;
1089      else
1090        return 0;
1091        end if;
1092 
1093 END;
1094 
1095 
1096 PROCEDURE CHANGE_ITEM_LIFECYCLE_PHASE (
1097           p_rev_item_seq_id             IN      NUMBER
1098         , p_organization_id             IN      NUMBER
1099         , p_inventory_item_id           IN      NUMBER
1100         , p_scheduled_date              IN      DATE
1101         , p_new_lifecycle_phase_id      IN      NUMBER
1102         , x_return_status       OUT NOCOPY      VARCHAR2)
1103 IS
1104 
1105   l_project_id                  NUMBER;
1106   l_lifecycle_id                NUMBER;
1107   l_lifecycle_project_id        NUMBER;
1108   l_lifecycle_project_number    VARCHAR2(30);
1109   l_return_status               VARCHAR2(1);
1110   l_error_code                  NUMBER;
1111   l_msg_count                   NUMBER;
1112   l_msg_data                    VARCHAR2(4000);
1113   l_project_assoc_type          VARCHAR2(24) := 'EGO_ITEM_PROJ_ASSOC_TYPE';
1114   l_lifecycle_tracking_code     VARCHAR2(18) := 'LIFECYCLE_TRACKING';
1115   l_api_version                 VARCHAR2(3) := '1.0';
1116   l_sql_stmt                    VARCHAR2(1000);
1117   l_plsql_block                 VARCHAR2(1000);
1118   l_new_lifecycle_phase         VARCHAR2(240);
1119   l_object_name                 VARCHAR2(30):= 'EGO_ITEM';
1120 
1121 BEGIN
1122         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Processing lifecycle phase change .. ');
1123         l_sql_stmt := ' SELECT eip.project_id, ppa.name                 '
1124                         || 'FROM EGO_ITEM_PROJECTS eip, PA_PROJECTS_ALL ppa '
1125                         || 'WHERE eip.project_id = ppa.project_id               '
1126                         || 'AND eip.INVENTORY_ITEM_ID = :1              '
1127                         || 'AND eip.ORGANIZATION_ID = :2                '
1128                         || 'AND eip.REVISION IS NULL                    '
1129                         || 'AND eip.ASSOCIATION_TYPE = :3               '
1130                         || 'AND eip.ASSOCIATION_CODE = :4               '
1131                         || 'AND ROWNUM = 1                              ';
1132         BEGIN
1133                 EXECUTE IMMEDIATE l_sql_stmt INTO l_lifecycle_project_id , l_lifecycle_project_number
1134                 USING p_inventory_item_id, p_organization_id, l_project_assoc_type, l_lifecycle_tracking_code;
1135 
1136                 l_sql_stmt := ' SELECT  name                            '
1137                                 || 'FROM PA_EGO_PHASES_V     '
1138                                 || 'WHERE PROJ_ELEMENT_ID = :1;         ';
1139                 EXECUTE IMMEDIATE l_sql_stmt INTO l_new_lifecycle_phase
1140                 USING p_new_lifecycle_phase_id;
1141 
1142                 /* call the Projects api */
1143                 l_plsql_block := 'begin PA_PROJ_TASK_STRUC_PUB.Update_Current_Phase '
1144                                 || ' ( p_project_id                     => :1 '
1145                                 || ' , p_project_name                   => :2 '
1146                                 || ' , p_current_lifecycle_phase_id     => :3 '
1147                                 || ' , p_current_lifecycle_phase        => :4 '
1148                                 || ' , x_return_status                  => :5 '
1149                                 || ' , x_msg_count                      => :6 '
1150                                 || ' , x_msg_data                       => :7 '
1151                                 || ' ); '
1152                                 || 'end; ';
1153                 EXECUTE IMMEDIATE l_plsql_block USING
1154                         IN l_lifecycle_project_id, IN l_lifecycle_project_number, IN p_new_lifecycle_phase_id, IN l_new_lifecycle_phase,
1155                         OUT l_return_status, OUT l_msg_count, OUT l_msg_data;
1156         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Processing lifecycle phase change for project '|| l_lifecycle_project_number || '.. ');
1157 
1158         EXCEPTION
1159         WHEN NO_DATA_FOUND THEN
1160                 l_sql_stmt := ' SELECT lifecycle_id                             '
1161                                 || '  FROM mtl_system_items_b                   '
1162                                 || '  WHERE inventory_item_id = :1              '
1163                                 || '  AND organization_id = :2                  ' ;
1164 
1165                 BEGIN
1166                         EXECUTE IMMEDIATE l_sql_stmt INTO l_lifecycle_id USING p_inventory_item_id, p_organization_id;
1167                 EXCEPTION
1168                 WHEN NO_DATA_FOUND THEN
1169                         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Lifecycle phase change Error: No lifecycle associated to the item ');
1170                         l_return_status := 'U';
1171                 END;
1172                 IF (l_lifecycle_id IS NOT NULL)
1173                 THEN
1174                         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Processing lifecycle phase change for item.. ');
1175 
1176                         /*l_plsql_block := 'begin '
1177                                 || 'ego_lifecycle_user_pub.Sync_Phase_Change '
1178                                 || '( p_api_version     => :1   '
1179                                 || ', p_organization_id => :2   '
1180                                 || ', p_inventory_item_id => :3 '
1181                                 || ', p_revision        => null '
1182                                 || ', p_lifecycle_id    => :4   '
1183                                 || ', p_phase_id        => :5   '
1184                                 || ', p_effective_date  => :6   '
1185                                 || ', x_return_status   => :7   '
1186                                 || ', x_errorcode       => :8   '
1187                                 || ', x_msg_count       => :9   '
1188                                 || ', x_msg_data        => :10  '
1189                                 || '); '
1190                                 || 'end; ';
1191 
1192                         EXECUTE IMMEDIATE  l_plsql_block USING
1193                         IN l_api_version, IN p_organization_id, IN p_inventory_item_id, IN l_lifecycle_id, IN p_new_lifecycle_phase_id, IN p_scheduled_date,
1194                         OUT l_return_status, OUT l_error_code,OUT l_msg_count, OUT l_msg_data;*/
1195                         l_plsql_block := 'begin '
1196                                 || 'EGO_ITEM_LC_IMP_PC_PUB.Implement_Pending_Changes  '
1197                                 || '( p_api_version     => 1.0  '
1198                                 || ', p_commit          => :1   '
1199                                 || ', p_change_id       => null '
1200                                 || ', p_change_line_id  => :2   '
1201                                 || ', x_return_status   => :3   '
1202                                 || ', x_errorcode       => :4   '
1203                                 || ', x_msg_count       => :5   '
1204                                 || ', x_msg_data        => :6   '
1205                                 || '); '
1206                                 || 'end; ';
1207 
1208                         EXECUTE IMMEDIATE  l_plsql_block USING IN l_return_status, IN p_rev_item_seq_id,
1209                         OUT l_return_status, OUT l_error_code,OUT l_msg_count, OUT l_msg_data;
1210 
1211                         FOR I IN 1..l_msg_count
1212                         LOOP
1213                                 FND_FILE.PUT_LINE(FND_FILE.LOG, FND_MSG_PUB.get(I, 'F'));
1214                         END LOOP;
1215 
1216                 END IF;
1217         END;
1218         x_return_status := l_return_status;
1219 
1220         EXCEPTION
1221         WHEN OTHERS THEN
1222 
1223                 FND_FILE.PUT_LINE(FND_FILE.LOG, 'Lifecycle phase change Error: ' ||SQLERRM);
1224                 x_return_status := 'U';
1225 
1226 END CHANGE_ITEM_LIFECYCLE_PHASE;
1227 
1228 ------------------------------------------------------------------------
1229 --           R12: Changes for Common BOM Enhancement                  --
1230 --             Begin Private Procedures Definition                    --
1231 ------------------------------------------------------------------------
1232 ------------------------------------------------------------------------
1233 --  API name    : Move_Pending_Dest_Components                        --
1234 --  Type        : Private                                             --
1235 --  Pre-reqs    : None.                                               --
1236 --  Procedure   : Propagates the specified ECO                        --
1237 --  Parameters  :                                                     --
1238 --       IN     : p_src_old_comp_seq_id  NUMBER Required              --
1239 --                p_src_comp_seq_id      NUMBER Required              --
1240 --                p_change_notice        vARCHAR2 Required            --
1241 --                p_revised_item_sequence_id  NUMBER Required         --
1242 --                p_effectivity_date     NUMBER Required              --
1243 --       OUT    : x_return_status            VARCHAR2(1)              --
1244 --  Version     : Current version       1.0                           --
1245 --                Initial version       1.0                           --
1246 --                                                                    --
1247 --  Notes       : This API is invoked only when a common bill has     --
1248 --                pending changes associated for its WIP supply type  --
1249 --                attributes and the common component in the source   --
1250 --                bill is being implemented.                          --
1251 --                All the destination pending changes are then moved  --
1252 --                to this new component with the effectivity range of --
1253 --                the component being implemented.                    --
1254 ------------------------------------------------------------------------
1255 PROCEDURE Move_Pending_Dest_Components (
1256     p_src_old_comp_seq_id IN NUMBER
1257   , p_src_comp_seq_id     IN NUMBER
1258   , p_change_notice       IN VARCHAR2
1259   , p_revised_item_sequence_id IN NUMBER
1260   , p_effectivity_date    IN DATE
1261   , p_eco_for_production  IN NUMBER
1262   , x_return_status       OUT NOCOPY VARCHAR2
1263 ) IS
1264 
1265     --
1266     -- Cursor to fetch the component being implemented wrt the detination bill
1267     -- for the change in the soruce bill
1268     --
1269     CURSOR c_related_components IS
1270     SELECT bcb.component_sequence_id, old_component_sequence_id, bill_sequence_id
1271     FROM bom_components_b bcb
1272     WHERE bcb.change_notice = p_change_notice
1273     AND bcb.revised_item_sequence_id = p_revised_item_sequence_id
1274     AND bcb.common_component_sequence_id = p_src_comp_seq_id
1275     AND bcb.common_component_sequence_id <> bcb.component_sequence_id
1276     AND bcb.implementation_date IS NULL;
1277 
1278 BEGIN
1279     --
1280     -- Initialize
1281     --
1282     x_return_status :=  FND_API.G_RET_STS_SUCCESS;
1283     IF p_eco_for_production = 2
1284     -- Do not reset the value of old component sequence_id when only
1285     -- WIPs have to be updated and the BOM changes are to be reversed.
1286     -- This is actually done for normal bills post implemntation
1287     -- of the new component for update of the old_component_sequence_id
1288     -- Here, Doing it in one go for all the pending changes of the common
1289     -- referenced component being implemented.
1290     THEN
1291 
1292         -- For each destination component record that will be implemented
1293         FOR c_dest_comp_rec IN c_related_components
1294         LOOP
1295             UPDATE bom_components_b bcb
1296                SET bcb.old_component_sequence_id = c_dest_comp_rec.component_sequence_id
1297                  , bcb.common_component_sequence_id = p_src_comp_seq_id
1298                  , bcb.last_update_date = sysdate
1299                  , bcb.last_updated_by = FND_PROFILE.value('USER_ID')
1300                  , bcb.last_update_login = FND_PROFILE.value('LOGIN_ID')
1301                  , bcb.request_id = FND_PROFILE.value('REQUEST_ID')
1302                  , bcb.program_application_id = FND_PROFILE.value('RESP_APPL_ID')
1303                  , bcb.program_id = FND_PROFILE.value('PROGRAM_ID')
1304                  , bcb.program_update_date = sysdate
1305              WHERE bcb.old_component_sequence_id = c_dest_comp_rec.old_component_sequence_id
1306                AND bcb.bill_sequence_id = c_dest_comp_rec.bill_sequence_id
1307                AND bcb.common_component_sequence_id = p_src_old_comp_seq_id
1308                AND bcb.implementation_date IS NULL
1309                -- The following exists clause is to ensure that the pending component is not a source
1310                -- referenced component but the one actually created for the destination bill itself
1311                AND EXISTS (SELECT 1 FROM eng_revised_items eri
1312                           WHERE eri.revised_item_sequence_id = bcb.revised_item_sequence_id
1313                             AND eri.change_notice= bcb.change_notice
1314                             AND eri.bill_sequence_id = bcb.bill_sequence_id);
1315         END LOOP;
1316     ELSE
1317         -- For each destination component record that will be implemented
1318         FOR c_dest_comp_rec IN c_related_components
1319         LOOP
1320             -- set the values being updated into the global table to revert it
1321             -- when reverse standard bom is called .
1322             -- Here only common component sequence id is being updated to
1323             -- point to the new referenced component that is going to be implemented
1324             --
1325             g_common_rev_comps_cnt := g_common_rev_comps_cnt+1;
1326             g_Common_Rev_Comp_Tbl(g_common_rev_comps_cnt).revised_item_sequence_id := p_revised_item_sequence_id;
1327             g_Common_Rev_Comp_Tbl(g_common_rev_comps_cnt).dest_bill_sequence_id := c_dest_comp_rec.bill_sequence_id;
1328             g_Common_Rev_Comp_Tbl(g_common_rev_comps_cnt).dest_old_comp_sequence_id := c_dest_comp_rec.old_component_sequence_id;
1329             g_Common_Rev_Comp_Tbl(g_common_rev_comps_cnt).component_sequence_id := c_dest_comp_rec.component_sequence_id;
1330             g_Common_Rev_Comp_Tbl(g_common_rev_comps_cnt).common_component_sequence_id := p_src_comp_seq_id;
1331             g_Common_Rev_Comp_Tbl(g_common_rev_comps_cnt).prev_common_comp_sequence_id := p_src_old_comp_seq_id;
1332 
1333             UPDATE bom_components_b bcb
1334                SET bcb.common_component_sequence_id = p_src_comp_seq_id
1335                  , bcb.last_update_date = sysdate
1336                  , bcb.last_updated_by = FND_PROFILE.value('USER_ID')
1337                  , bcb.last_update_login = FND_PROFILE.value('LOGIN_ID')
1338                  , bcb.request_id = FND_PROFILE.value('REQUEST_ID')
1339                  , bcb.program_application_id = FND_PROFILE.value('RESP_APPL_ID')
1340                  , bcb.program_id = FND_PROFILE.value('PROGRAM_ID')
1341                  , bcb.program_update_date = sysdate
1342              WHERE bcb.old_component_sequence_id = c_dest_comp_rec.old_component_sequence_id
1343                AND bcb.bill_sequence_id = c_dest_comp_rec.bill_sequence_id
1344                AND bcb.common_component_sequence_id = p_src_old_comp_seq_id
1345                AND bcb.implementation_date IS NULL
1346                -- The following exists clause is to ensure that the pending component is not a source
1347                -- referenced component but the one actually created for the destination bill itself
1348                AND EXISTS (SELECT 1 FROM eng_revised_items eri
1349                           WHERE eri.revised_item_sequence_id = bcb.revised_item_sequence_id
1350                             AND eri.change_notice= bcb.change_notice
1351                             AND eri.bill_sequence_id = bcb.bill_sequence_id);
1352         END LOOP;
1353     END IF;
1354 EXCEPTION
1355 WHEN OTHERS THEN
1356     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1357 END Move_Pending_Dest_Components;
1358 
1359 PROCEDURE Reset_Common_Comp_Details (
1360   x_Mesg_Token_Tbl   OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
1361 , x_return_status    OUT NOCOPY VARCHAR2
1362 ) IS
1363 
1364 BEGIN
1365     --
1366     -- Initialize
1367     --
1368     x_return_status :=  FND_API.G_RET_STS_SUCCESS;
1369     -- For each component thats been
1370     FOR i IN 1..g_common_rev_comps_cnt
1371     LOOP
1372         UPDATE bom_components_b bcb
1373            SET bcb.common_component_sequence_id = g_Common_Rev_Comp_Tbl(i).prev_common_comp_sequence_id
1374              , bcb.last_update_date = sysdate
1375              , bcb.last_updated_by = FND_PROFILE.value('USER_ID')
1376              , bcb.last_update_login = FND_PROFILE.value('LOGIN_ID')
1377              , bcb.request_id = FND_PROFILE.value('REQUEST_ID')
1378              , bcb.program_application_id = FND_PROFILE.value('RESP_APPL_ID')
1379              , bcb.program_id = FND_PROFILE.value('PROGRAM_ID')
1380              , bcb.program_update_date = sysdate
1381          WHERE bcb.old_component_sequence_id = g_Common_Rev_Comp_Tbl(i).dest_old_comp_sequence_id
1382            AND bcb.bill_sequence_id = g_Common_Rev_Comp_Tbl(i).dest_bill_sequence_id
1383            AND bcb.common_component_sequence_id = g_Common_Rev_Comp_Tbl(i).common_component_sequence_id
1384            AND bcb.implementation_date IS NULL
1385            -- The following exists clause is to ensure that the pending component is not a source
1386            -- referenced component but the one actually created for the destination bill itself
1387            AND EXISTS (SELECT 1 FROM eng_revised_items eri
1388                       WHERE eri.revised_item_sequence_id = bcb.revised_item_sequence_id
1389                         AND eri.change_notice= bcb.change_notice
1390                         AND eri.bill_sequence_id = bcb.bill_sequence_id);
1391 
1392         BOMPCMBM.Update_Related_Components(
1393             p_src_comp_seq_id => g_Common_Rev_Comp_Tbl(i).prev_common_comp_sequence_id
1394           , x_Mesg_Token_Tbl  => x_Mesg_Token_Tbl
1395           , x_Return_Status   => x_return_status);
1396     END LOOP;
1397 EXCEPTION
1398 WHEN OTHERS THEN
1399     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
1400 
1401 END Reset_Common_Comp_Details;
1402 
1403 
1404 -- PROCEDURE ENTER_WIP_DETAILS_FOR_COMPS
1405 -- Bug No: 5285282
1406 -- Procedure to populate the WIP_JOB_DETAILS_INTERFACE table.
1407 -- This procedure is called only if 'Update Job Only' is ticked for revised items.
1408 -- For 'Update Job Only' changes are not visible in the BOM explosion, hence to
1409 -- make these changes visible to the WIP jobs, we need to explicitly enter the
1410 -- data in the WIP interface table WIP_JOB_DETAILS_INTERFACE
1411 --
1412 
1413 PROCEDURE ENTER_WIP_DETAILS_FOR_COMPS ( p_revised_item_sequence_id IN NUMBER,
1414                                         p_group_id                 IN NUMBER,
1415                                         p_parent_header_id         IN NUMBER,
1416                                         p_mrp_active               IN NUMBER,
1417                                         p_user_id                  IN NUMBER,
1418                                         p_login_id                 IN NUMBER,
1419                                         p_request_id               IN NUMBER,
1420                                         p_program_id               IN NUMBER,
1421                                         p_program_application_id   IN NUMBER
1422                                         )
1423 IS
1424   CURSOR c_comps IS
1425   SELECT component_item_id,
1426          operation_seq_num,
1427          component_quantity,
1428          supply_locator_id,
1429          supply_subinventory,
1430          wip_supply_type,
1431          acd_type
1432   FROM bom_components_b
1433   WHERE revised_item_sequence_id = p_revised_item_sequence_id;
1434 
1435 BEGIN
1436   FOR comp_details IN c_comps
1437   LOOP
1438     INSERT INTO WIP_JOB_DTLS_INTERFACE
1439       (created_by,
1440        creation_date,
1441        last_update_date,
1442        last_updated_by,
1443        last_update_login,
1444        request_id,
1445        program_id,
1446        program_application_id,
1447        program_update_date,
1448        group_id,
1449        load_type,
1450        parent_header_id,
1451        process_phase,
1452        process_status,
1453        substitution_type,
1454        inventory_item_id_new,
1455        inventory_item_id_old,
1456        operation_seq_num,
1457        quantity_per_assembly,
1458        supply_locator_id,
1459        supply_subinventory,
1460        wip_supply_type,
1461        mrp_net_flag)
1462     VALUES
1463       (p_user_id,
1464        sysdate,
1465        sysdate,
1466        p_user_id,
1467        p_login_id,
1468        p_request_id,
1469        p_program_id,
1470        p_program_application_id,
1471        sysdate,
1472        p_group_id,
1473        2,                                        -- Load Type is 2 for components
1474        p_parent_header_id,
1475        2,                                        -- process_phase 2 for validation
1476        1,                                        -- process_status 1 for pending
1477        decode(comp_details.acd_type, 1, 2,
1478                                      2, 3,
1479                                      1),         -- substitution_type 1->Delete, 2->Add, 3->Change
1480        decode(comp_details.acd_type, 1,
1481                  comp_details.component_item_id, -- inventory_item_id_new populated only for component add
1482                  null),
1483        decode(comp_details.acd_type, 1,          -- inventory_item_id_old populated only for component change/delete
1484                  null,
1485                  comp_details.component_item_id),
1486        comp_details.operation_seq_num,
1487        comp_details.component_quantity,
1488        comp_details.supply_locator_id,
1489        comp_details.supply_subinventory,
1490        comp_details.wip_supply_type,
1491        p_mrp_active);
1492 
1493   END LOOP;
1494 END ENTER_WIP_DETAILS_FOR_COMPS;
1495 
1496 ------------------------------------------------------------------------
1497 --           R12: Changes for Common BOM Enhancement                  --
1498 --             END Private Procedures Definition                      --
1499 ------------------------------------------------------------------------
1500 
1501 Procedure implement_revised_item(
1502         revised_item in eng_revised_items.revised_item_sequence_id%type,
1503         trial_mode in number,
1504         max_messages in number, -- size of host arrays
1505         userid  in number,  -- user id
1506         reqstid in number,  -- concurrent request id
1507         appid   in number,  -- application id
1508         progid  in number,  -- program id
1509         loginid in number,  -- login id
1510         bill_sequence_id        OUT NOCOPY eng_revised_items.bill_sequence_id%type ,
1511         routing_sequence_id     OUT NOCOPY eng_revised_items.routing_sequence_id%type ,
1512         eco_for_production      OUT NOCOPY eng_revised_items.eco_for_production%type ,
1513         revision_high_date      OUT NOCOPY mtl_item_revisions.effectivity_date%type,
1514         rtg_revision_high_date  OUT NOCOPY mtl_rtg_item_revisions.effectivity_date%type,
1515         update_wip              OUT NOCOPY eng_revised_items.update_wip%type ,
1516         group_id1               OUT NOCOPY wip_job_schedule_interface.group_id%type,
1517         group_id2               OUT NOCOPY wip_job_schedule_interface.group_id%type,
1518         wip_job_name1           OUT NOCOPY wip_entities.wip_entity_name%type,
1519         wip_job_name2           OUT NOCOPY wip_entities.wip_entity_name%type,
1520         wip_job_name2_org_id    OUT NOCOPY wip_entities.organization_id%type,
1521         message_names OUT NOCOPY NameArray,
1522         token1 OUT NOCOPY NameArray,
1523         value1 OUT NOCOPY StringArray,
1524         translate1 OUT NOCOPY BooleanArray,
1525         token2 OUT NOCOPY NameArray,
1526         value2 OUT NOCOPY StringArray,
1527         translate2 OUT NOCOPY BooleanArray,
1528         msg_qty in OUT NOCOPY binary_integer,
1529         warnings in OUT NOCOPY number,
1530         p_is_lifecycle_phase_change     IN      NUMBER,
1531         p_now                           IN      DATE,
1532         p_status_code                   IN      NUMBER)
1533 IS
1534 
1535 -- ERES change begins
1536 bERES_Flag_for_BOM     BOOLEAN := FALSE;        -- bug 3741444.
1537 bERES_Flag_for_Routing BOOLEAN := FALSE;        -- bug 3908563.
1538 l_eres_enabled         VARCHAR2(10);
1539 l_child_record         QA_EDR_STANDARD.ERECORD_ID_TBL_TYPE;
1540 l_event                QA_EDR_STANDARD.ERES_EVENT_REC_TYPE;
1541 -- l_payload              FND_WF_EVENT.PARAM_TABLE;
1542 -- ll_payload             FND_WF_EVENT.PARAM_TABLE;
1543 l_msg_count            NUMBER;
1544 l_msg_data             VARCHAR2(2000);
1545 l_message              VARCHAR2(2000);
1546 l_dummy_cnt            NUMBER;
1547 l_erecord_id           NUMBER;
1548 l_trans_status         VARCHAR2(20);
1549 l_event_status         VARCHAR2(20);
1550 i                      PLS_INTEGER;
1551 l_child_event_name     VARCHAR2(200);
1552 l_temp_id              VARCHAR2(200);
1553 l_parent_record_id     NUMBER;
1554 l_pending_from_ecn     VARCHAR2(10);
1555 l_alternate_designator VARCHAR2(10);
1556 l_send_ackn            BOOLEAN;
1557 l_plsql_block           VARCHAR2(1000);
1558 l_api_caller VARCHAR2(3)        := 'CP';
1559 l_err_tbl Error_Handler.Mesg_Token_Tbl_Type;
1560 
1561 
1562 -- Item Attribute and AML changes support
1563 plsql_block VARCHAR2(5000);
1564 -- Item Attribute and AML changes support
1565 
1566 ERES_EVENT_ERROR       EXCEPTION;
1567 
1568 CURSOR Get_Bill_of_Materials_Info( bill_id IN NUMBER) IS
1569 SELECT pending_from_ecn
1570 , alternate_bom_designator
1571 FROM bom_bill_of_materials
1572 WHERE bill_sequence_id = bill_id;
1573 
1574 CURSOR Get_Operational_Routing_Info( routing_id IN NUMBER) IS
1575 SELECT pending_from_ecn
1576 , alternate_routing_designator
1577 FROM bom_operational_routings
1578 WHERE routing_sequence_id = routing_id ;
1579 -- ERES change ends
1580 
1581         abort_implementation exception;
1582         dummy varchar2(1);
1583         eco_rev_warning_flag varchar2(1);
1584         today  date;  -- implementation date
1585         now    date;  -- effectivity date and time
1586         eff_date    date;  -- effectivity date and time
1587         count_op_disable   number:=0;      --  count for table rev_op_disable_date_tbl
1588         count_comp_disable number:=0;      --  count for table rev_comp_disable_date_tbl
1589         l_disable_date  date;              --  variable for disable date
1590         l_current_revision varchar2(3);
1591         l_current_rev_eff_date date;
1592         l_current_rtg_revision varchar2(3);
1593         l_current_rtg_rev_eff_date date;
1594 
1595         -- Local variables for update routings
1596         l_routing_sequence_id NUMBER;
1597         l_cfm_routing_flag    NUMBER;
1598         l_completion_subinventory  VARCHAR2(10);
1599         l_completion_locator_id NUMBER;
1600         l_mixed_model_map_flag  NUMBER;
1601         l_common_assembly_item_id NUMBER;
1602         l_common_routing_sequence_id NUMBER;
1603         l_ctp_flag                   NUMBER;
1604         l_priority                   NUMBER;
1605         l_routing_comment            VARCHAR2(240);
1606         l_bom_assembly_type          NUMBER;
1607 
1608         l_old_disable_date date;
1609         -- Bug 5657390
1610 	l_update_all_jobs     NUMBER := nvl(fnd_profile.value('ENG:UPDATE_UNRELEASED_WIP_JOBS'),2);
1611 
1612         -- ERES change
1613         -- odab added columns change_id, organization_code
1614         -- , organization_name, concatenated_segments, description
1615         -- last_update_date, last_updated_by, creation_date, created_by
1616         -- replaced mtl_system_items by mtl_system_items_vl
1617         -- added joint tables mtl_parameters, hr_all_organization_units_tl
1618         Cursor get_item_info is
1619                 Select  i.change_notice,
1620                         i.change_id,                         -- ERES change
1621                         i.organization_id,
1622                         mp1.organization_code,               -- ERES change
1623                         hou.name organization_name,          -- ERES change
1624                         i.revised_item_id,
1625                         si.concatenated_segments,            -- ERES change
1626                         si.description,                      -- ERES change
1627 			si.bom_enabled_flag,                 -- Bug 5846248
1628                         i.new_item_revision,
1629                         i.bill_sequence_id,
1630                         i.update_wip,
1631                         si.pick_components_flag,
1632                         i.revised_item_sequence_id,
1633                         i.scheduled_date,
1634                         si.inventory_item_status_code,
1635                         si.eng_item_flag,
1636                         i.mrp_active,
1637                         i.from_wip_entity_id,
1638                         i.to_wip_entity_id,
1639                         i.from_cum_qty,
1640                         i.lot_number,
1641                         i.new_routing_revision,
1642                         i.routing_sequence_id,
1643                         i.cfm_routing_flag,
1644                         i.completion_locator_id ,
1645                         i.completion_subinventory,
1646                         i.mixed_model_map_flag,
1647                         i.eco_for_production,
1648                         i.ctp_flag,
1649                         i.priority,
1650                         i.routing_comment,
1651                         i.designator_selection_type,
1652                         i.alternate_bom_designator,
1653                         i.transfer_or_copy,
1654                         i.transfer_or_copy_item,
1655                         i.transfer_or_copy_bill,
1656                         i.transfer_or_copy_routing,
1657                         i.copy_to_item,
1658                         i.copy_to_item_desc,
1659                         i.implemented_only,
1660                         i.selection_option,
1661                         i.selection_date,
1662                         i.selection_unit_number,             -- ERES change
1663                         i.last_update_date,                  -- ERES change
1664                         i.last_updated_by,                   -- ERES change
1665                         i.creation_date,                     -- ERES change
1666                         i.created_by          ,               -- ERES change
1667                         i.new_item_revision_id,
1668                         i.current_item_revision_id ,
1669                         i.new_lifecycle_state_id,
1670                         i.use_up_item_id ,
1671                         i.disposition_type,
1672                         i.new_structure_revision,
1673                         i.current_lifecycle_state_id,
1674                         i.enable_item_in_local_org,
1675                         i.from_end_item_id,
1676                         i.from_end_item_rev_id
1677                 from    eng_revised_items i,
1678                         mtl_system_items_vl si,              -- ERES change
1679                         mtl_parameters mp1,                  -- ERES change
1680                         hr_all_organization_units_tl hou     -- ERES change
1681                 where i.revised_item_sequence_id = revised_item
1682                 and   si.inventory_item_id = i.revised_item_id
1683                 and   si.organization_id = i.organization_id
1684                 AND hou.organization_id = i.organization_id
1685                 AND hou.language(+) = USERENV('LANG')
1686                 AND mp1.organization_id = i.organization_id
1687                 for update of i.implementation_date,
1688                               i.status_type,
1689                               i.last_update_date,
1690                               i.last_updated_by,
1691                               i.last_update_login,
1692                               i.request_id,
1693                               i.program_application_id,
1694                               i.program_id,
1695                               i.program_update_date,
1696                               i.status_code;
1697 
1698         item get_item_info%rowtype;
1699         Cursor check_rev_item_inactive is
1700                 Select 'x'
1701                 from   bom_parameters
1702                 where  organization_id = item.organization_id
1703                 and    bom_delete_status_code = item.inventory_item_status_code;
1704         Cursor check_for_unimp_items is
1705                 Select 'x'
1706                 from    eng_revised_items
1707                 where   organization_id = item.organization_id
1708                 and     change_notice = item.change_notice
1709                 and     status_type not in
1710                         (cancelled_status, implemented_status);
1711         Cursor unimplemented_rev is
1712                 Select eri.new_item_revision
1713                 from eng_engineering_changes eec,
1714                      eng_revised_items eri
1715                 where eec.change_notice = eri.change_notice
1716                 and  eec.organization_id = eri.organization_id
1717                 and  eri.organization_id = item.organization_id
1718                 and  eri.revised_item_id = item.revised_item_id
1719                 and  eec.status_type not in
1720                         (cancelled_status, implemented_status)
1721                 and  eri.status_type not in
1722                         (cancelled_status, implemented_status)
1723                 and  nlssort(eri.new_item_revision) <
1724                      nlssort(item.new_item_revision);
1725 
1726         unimp_rec  unimplemented_rev%rowtype;
1727 
1728         Cursor get_current_rev is
1729                 Select r.revision, r.effectivity_date
1730                 from   mtl_item_revisions r
1731                 where  r.inventory_item_id = item.revised_item_id
1732                 and    r.organization_id = item.organization_id
1733                 and    r.effectivity_date = (
1734                         select max(cr.effectivity_date)
1735                         from   mtl_item_revisions cr
1736                         where  cr.inventory_item_id = item.revised_item_id
1737                         and    cr.organization_id = item.organization_id
1738                         and    cr.implementation_date is not null
1739                         and    cr.effectivity_date <= eff_date);
1740         current_revision get_current_rev%rowtype;
1741         ----added r.effectivity_date >= eff_date for bug 5496417
1742         Cursor check_high_date_low_rev is
1743                 Select 'x'
1744                 from   mtl_item_revisions r
1745                 where  r.inventory_item_id = item.revised_item_id
1746                 and    r.organization_id = item.organization_id
1747                 and    r.effectivity_date >= eff_date
1748                 and    r.revision < item.new_item_revision
1749                 and    r.implementation_date is not null;
1750 
1751         Cursor get_common_bills is
1752                 Select b.organization_id, b.assembly_item_id,
1753                        b.bill_sequence_id
1754                 from   bom_bill_of_materials b
1755                 where  b.common_assembly_item_id = item.revised_item_id
1756                 and    b.common_organization_id = item.organization_id
1757                 AND    b.source_bill_sequence_id = item.bill_sequence_id; -- R12: Common BOM changes
1758                 --and    b.common_bill_sequence_id = item.bill_sequence_id;
1759         common get_common_bills%rowtype;
1760         Cursor get_common_current_rev(common_assembly_item_id IN NUMBER,
1761                                 common_org_id IN NUMBER) is
1762                 Select r.revision
1763                 from   mtl_item_revisions r
1764                 where  r.inventory_item_id = common_assembly_item_id
1765                 and    r.organization_id = common_org_id
1766                 and    r.effectivity_date = (
1767                         select max(cr.effectivity_date)
1768                         from   mtl_item_revisions cr
1769                         where  cr.inventory_item_id = common_assembly_item_id
1770                         and    cr.organization_id = common_org_id
1771                         and    cr.implementation_date is not null
1772                         and    cr.effectivity_date <= eff_date);
1773         common_current_rev  mtl_item_revisions.revision%type;
1774 
1775         --* Added for Bug 4366583
1776         Cursor revision_exists(common_assembly_item_id IN NUMBER,
1777                                common_org_id IN NUMBER,
1778                                common_revision IN VARCHAR2) is
1779                 select count(*)
1780                 from mtl_item_revisions_b
1781                 where inventory_item_id = common_assembly_item_id
1782                 and organization_id = common_org_id
1783                 and revision = common_revision;
1784         l_revision_exists NUMBER;
1785         --* End of Bug 4366583
1786 
1787         Cursor chng_component_rows(cp_bill_sequence_id IN NUMBER) is
1788             Select c.component_sequence_id,
1789                    f.concatenated_segments item_number,
1790                    c.component_item_id,
1791                    c.operation_seq_num,
1792                    c.acd_type,
1793                    c.quantity_related,
1794                    c.component_quantity,
1795                    c.old_component_sequence_id,
1796                    c.disable_date,
1797                    c.from_end_item_unit_number,
1798                    c.to_end_item_unit_number,
1799                    c.from_object_revision_id,
1800                    c.to_object_revision_id,
1801                    c.overlapping_changes,
1802                    f.eng_item_flag,
1803                    c.from_end_item_rev_id,
1804                    c.to_end_item_rev_id,
1805                    c.component_item_revision_id,
1806                    c.obj_name,
1807                    c.component_remarks
1808             from bom_components_b c,  --bom_inventory_components c,
1809                  mtl_system_items_b_kfv f
1810             where c.revised_item_sequence_id = revised_item
1811             AND   c.bill_sequence_id = cp_bill_sequence_id -- R12: Added for common bom changes
1812             and   f.inventory_item_id = c.component_item_id
1813             and   f.organization_id = item.organization_id
1814             AND   c.obj_name IS NULL -- added for bom_components_b
1815             for update of c.implementation_date,
1816                           c.change_notice,
1817                           c.disable_date,
1818                           c.from_end_item_unit_number,
1819                           c.to_end_item_unit_number,
1820                           c.from_object_revision_id,
1821                           c.overlapping_changes,
1822                           c.effectivity_date,
1823                           c.last_update_date,
1824                           c.last_updated_by,
1825                           c.last_update_login,
1826                           c.request_id,
1827                           c.program_application_id,
1828                           c.program_id,
1829                           c.program_update_date;
1830 /*According to new where condition of this cursor  union Query has commented out
1831    case 1: S1 => C1 (Q= 1 ,eff= D1) changed to S1 => C1 (Q= 10 ,eff= D1)  [D1 = future date] is supported.
1832    initailly overlapping error used to come in both cases .
1833    case 2: S1 => C1(eff = D1 ,disb =D3)  C1 (eff = D3 ) now make changes from C1(eff = D2 ,disb =D3) supported
1834    Initially disable adte 1 sec less than eff date was required now 1 sec gap won't be check.*/
1835 
1836         Cursor check_existing_component(X_bill number, X_component number,
1837             X_operation number, X_comp_seq_id number, X_disable_date date,X_old_comp_seq_id number
1838 	    ,X_old_rec_disable_date  date) is
1839             Select 'x' -- overlapping effectivity
1840             from bom_components_b c --bom_inventory_components c
1841             where c.bill_sequence_id = X_bill
1842             and c.component_item_id = X_component
1843             and c.operation_seq_num = X_operation
1844             and c.implementation_date is not null
1845             AND   c.obj_name IS NULL -- added for bom_components_b
1846 	     /* Bug: 2307923 Date filter logic has been modified to prevent
1847                the duplicate creation of components through ECO */
1848            and ( (eff_date < c.effectivity_date
1849                    and nvl(X_disable_date,c.effectivity_date + 1) > c.effectivity_date)
1850                    or
1851 		   (eff_date < c.effectivity_date
1852                    and nvl(X_disable_date,c.effectivity_date ) <>  c.effectivity_date
1853 		   and nvl(X_old_rec_disable_date,c.effectivity_date) = c.effectivity_date )
1854 		   or
1855 		   /*Bug no:2867564 Eco is implementing and allowing duplicate item, and seqs. */
1856                   /*and eff_date <= nvl(c.disable_date,eff_date-1)*/
1857                   (eff_date > c.effectivity_date
1858                    and eff_date <  nvl(c.disable_date,eff_date+1) )
1859                    or
1860 		  (eff_date = c.effectivity_date
1861                    and  c.component_sequence_id <> X_old_comp_seq_id
1862 		   and  c.disable_date <> c.effectivity_date ) );
1863 	 /*
1864 	    union
1865             select 'x' -- duplicate value on unique index
1866             from bom_components_b c --bom_inventory_components c
1867             where c.bill_sequence_id = X_bill
1868             and c.component_item_id = X_component
1869             and c.operation_seq_num = X_operation
1870             and c.effectivity_date = eff_date
1871             AND   c.obj_name IS NULL -- added for bom_components_b
1872             and c.component_sequence_id <> X_comp_seq_id; */
1873 
1874         Cursor check_existing_unit(X_bill number, X_component number,
1875         X_operation number, X_comp_seq_id number, X_from_unit_number varchar2,
1876         X_to_unit_number varchar2) is
1877             Select 'x' -- overlapping effectivity
1878             from bom_components_b c--bom_inventory_components c
1879             where c.bill_sequence_id = X_bill
1880             and c.component_item_id = X_component
1881             and c.operation_seq_num = X_operation
1882             and c.implementation_date is not null
1883             AND   c.obj_name IS NULL -- added for bom_components_b
1884             and c.disable_date is NULL
1885             and (X_To_Unit_Number IS NULL
1886                  or (X_To_Unit_Number >= c.from_end_item_unit_number))
1887             and ((X_From_Unit_Number <=  c.to_end_item_unit_number)
1888                  or c.to_end_item_unit_number IS NULL);
1889 
1890         Cursor old_component(old_id number) is
1891             select o.change_notice,
1892                    o.implementation_date,
1893                    o.disable_date,
1894                    o.effectivity_date,
1895                    o.from_end_item_unit_number,
1896                    o.to_end_item_unit_number,
1897                    o.from_object_revision_id,
1898                    o.to_object_revision_id,
1899                    o.overlapping_changes,
1900                    o.component_sequence_id,
1901                    o.from_end_item_rev_id,
1902                    o.to_end_item_rev_id
1903             FROM bom_components_b o -- bom_inventory_components o
1904             where o.component_sequence_id = old_id
1905             for update of o.change_notice,
1906                           o.disable_date,
1907                           o.to_object_revision_id,
1908                           o.overlapping_changes,
1909                           o.last_update_date,
1910                           o.last_updated_by,
1911                           o.last_update_login,
1912                           o.request_id,
1913                           o.program_application_id,
1914                           o.program_id,
1915                           o.program_update_date;
1916         old_comp_rec  old_component%rowtype;
1917         Cursor count_ref_designators(comp_id number) is
1918             Select count(*)
1919             from   bom_reference_designators r
1920             where  r.component_sequence_id = comp_id
1921             and    nvl(r.acd_type, acd_add) = acd_add;
1922         ref_designator_count  number;
1923         X_GetInstallStatus boolean;
1924         X_InstallStatus varchar2(1) := 'N';
1925         X_Industry varchar2(1);
1926         X_prev_unit_number varchar2(30);
1927         X_UnitEff_RevItem varchar2(1) := 'N';
1928         X_new_structure_revision_id number := null;
1929         X_prev_structure_revision_id number := null;
1930 
1931 -----------------------------------------------------------------
1932 -- For ECO cumulative/ECO wip job/ECO lot  ---------8/2/2000----
1933 -----------------------------------------------------------------
1934 CURSOR check_job_valid_for_cum
1935    ( p_from_wip_entity_id NUMBER)
1936  IS
1937             SELECT wdj.scheduled_start_date,
1938                    wdj.scheduled_completion_date,
1939                    wdj.start_quantity,
1940                    wdj.net_quantity,
1941                    we.wip_entity_name,
1942                    wdj.bom_revision,
1943                    wdj.routing_revision,
1944                    wdj.bom_revision_date,
1945                    wdj.routing_revision_date
1946             FROM  wip_discrete_jobs wdj, wip_entities we
1947             WHERE wdj.wip_entity_id = p_from_wip_entity_id
1948             AND   we.wip_entity_id = wdj.wip_entity_id
1949             AND   wdj.status_type = 1;
1950 
1951 cum_job_rec check_job_valid_for_cum%rowtype;
1952 
1953 CURSOR check_job_valid_for_job
1954      ( p_from_wip_entity_id NUMBER,
1955        p_to_wip_entity_id   NUMBER,
1956        p_organization_id    NUMBER,
1957        p_effective_date     DATE )
1958 IS
1959             SELECT 'X'
1960             FROM  DUAL
1961             WHERE  EXISTS (
1962                             SELECT 1
1963                             FROM wip_discrete_jobs wdj,
1964                                  wip_entities we,
1965                                  wip_entities we1,
1966                                  wip_entities we2
1967                              WHERE we1.wip_entity_id = p_from_wip_entity_id
1968                              AND  we2.wip_entity_id = p_to_wip_entity_id
1969                              AND  we.wip_entity_name >= we1.wip_entity_name
1970                              AND  we.wip_entity_name <= we2.wip_entity_name
1971                              AND  we.organization_id = p_organization_id
1972                              AND  wdj.wip_entity_id = we.wip_entity_id
1973                              AND (  wdj.status_type <> 1
1974                                   OR
1975 				  (
1976 				  wdj.scheduled_start_date < p_effective_date
1977 				  and l_update_all_jobs = 2 -- Bug 5657390
1978 				  )
1979 		                 )
1980                          );
1981 
1982 CURSOR check_job_valid_for_lot
1983        ( p_wip_lot_number VARCHAR2
1984        , p_effective_date DATE)
1985  IS
1986             SELECT 'X'
1987             FROM  DUAL
1988             WHERE  EXISTS (
1989                             SELECT 1
1990                             FROM   wip_discrete_jobs wdj, wip_entities we
1991                             WHERE  wdj.lot_number = p_wip_lot_number
1992                              AND   wdj.wip_entity_id = we.wip_entity_id
1993                              AND   wdj.primary_item_id = item.revised_item_id
1994                              AND   wdj.organization_Id = item.organization_id
1995                              AND (  status_type <> 1
1996                                   OR  (	wdj.scheduled_start_date < p_effective_date
1997 	                                and l_update_all_jobs = 2 ) -- Bug 5662105
1998 				  )
1999               );
2000 
2001 CURSOR check_chng_rounting_existing( revised_item NUMBER) IS
2002             SELECT 'X'
2003             FROM bom_operation_sequences
2004             WHERE revised_item_sequence_id = revised_item;
2005 
2006 
2007 CURSOR chng_operation_rows  IS
2008        SELECT change_notice
2009      , operation_seq_num
2010      , operation_sequence_id
2011      , old_operation_sequence_id
2012      , routing_sequence_id
2013      , acd_type
2014      , revised_item_sequence_id
2015      , disable_date
2016      , effectivity_date
2017  FROM bom_operation_sequences
2018  WHERE revised_item_sequence_id = revised_item
2019  AND    change_notice = item.change_notice
2020  FOR UPDATE OF change_notice
2021     , implementation_date
2022     , old_operation_sequence_id
2023     , acd_type
2024     , revised_item_sequence_id
2025     , effectivity_date
2026     , disable_date
2027     , last_update_date
2028     , last_updated_by
2029     , last_update_login
2030     , request_id
2031     , program_application_id
2032     , program_id
2033     , program_update_date
2034 order by operation_sequence_id;
2035 
2036 chng_operation_rec chng_operation_rows%rowtype;
2037 
2038 
2039 CURSOR check_op_seq_num_exists IS
2040  SELECT 'X'
2041  FROM   bom_operation_sequences
2042  WHERE  operation_sequence_id = chng_operation_rec.old_operation_sequence_id
2043  AND    operation_seq_num = chng_operation_rec.operation_seq_num;
2044 
2045 CURSOR unimplemented_rtg_rev
2046   IS
2047   SELECT  eri.new_routing_revision
2048   FROM   eng_engineering_changes eec,
2049          eng_revised_items eri
2050   WHERE  eec.change_notice = eri.change_notice
2051   AND     eec.organization_id = eri.organization_id
2052   AND     eri.organization_id = item.organization_id
2053   AND     eri.revised_item_id = item.revised_item_id
2054   AND     eec.status_type NOT IN
2055           ( cancelled_status, implemented_status)
2056   AND     eri.status_type NOT IN
2057           (cancelled_status, implemented_status)
2058   AND     nlssort(eri.new_routing_revision) <
2059           nlssort(item.new_routing_revision);
2060 
2061  unimp_ref_rec unimplemented_rtg_rev%ROWTYPE;
2062 
2063 CURSOR check_highEffDate_lowRtgRev IS
2064 SELECT   'x'
2065 FROM   mtl_rtg_item_revisions r
2066 WHERE    r.inventory_item_id = item.revised_item_id
2067   AND    r.organization_id = item.organization_id
2068   AND    r.effectivity_date > eff_date
2069   AND    r.process_revision < item.new_routing_revision --bug 3476154
2070   AND    r.implementation_date IS NOT null;
2071 
2072 
2073 CURSOR get_common_routing  IS
2074   SELECT r.organization_id,
2075          r.assembly_item_id,
2076          r.routing_sequence_id
2077   FROM bom_operational_routings r
2078   WHERE  r.common_assembly_item_id = item.revised_item_id
2079   AND    r.common_routing_sequence_id = item.routing_sequence_id;
2080 
2081 common_routing get_common_routing%ROWTYPE;
2082 
2083 CURSOR get_common_current_routing_rev(common_assembly_item_id IN NUMBER,
2084                                 common_org_id IN NUMBER) is
2085                 Select r.process_revision
2086                 from   mtl_rtg_item_revisions r
2087                 where  r.inventory_item_id = common_assembly_item_id
2088                 and    r.organization_id = common_org_id
2089                 and    r.effectivity_date = (
2090                         select max(cr.effectivity_date)
2091                         from   mtl_rtg_item_revisions cr
2092                         where  cr.inventory_item_id = common_assembly_item_id
2093                         and    cr.organization_id = common_org_id
2094                         and    cr.implementation_date is not null
2095                         and    cr.effectivity_date <= eff_date);
2096 common_current_rtg_rev  mtl_rtg_item_revisions.process_revision%type;
2097 
2098 --* Added for Bug 4366583
2099 Cursor routing_revision_exists(common_assembly_item_id IN NUMBER,
2100                        common_org_id IN NUMBER,
2101                        common_revision IN VARCHAR2) is
2102         select count(*)
2103         from mtl_rtg_item_revisions
2104         where inventory_item_id = common_assembly_item_id
2105         and organization_id = common_org_id
2106         and process_revision = common_revision;
2107 l_rtg_revision_exists NUMBER;
2108 --* End of Bug 4366583
2109 
2110 CURSOR get_current_routing_rev  IS
2111 SELECT r.process_revision,
2112        r.effectivity_date
2113 FROM mtl_rtg_item_revisions r
2114 WHERE  r.inventory_item_id = item.revised_item_id
2115 AND   r.organization_id = item.organization_id
2116 AND   r.effectivity_date = (
2117       SELECT max(cr.effectivity_date)
2118       FROM   mtl_rtg_item_revisions cr
2119       WHERE  cr.inventory_item_id = item.revised_item_id
2120       AND   cr.organization_id = item.organization_id
2121       AND   cr.implementation_date is not null
2122       AND   cr.effectivity_date <= eff_date);
2123 
2124 current_routing_revision get_current_routing_rev%rowtype;
2125 
2126 CURSOR check_not_existing_op_cum
2127     (p_from_wip_entity_id NUMBER,
2128      p_operation_seq_num NUMBER,
2129      p_organization_id NUMBER)
2130  IS
2131     SELECT 'X'
2132     FROM    wip_operations o,
2133             wip_discrete_jobs w
2134     WHERE  w.wip_entity_id  = p_from_wip_entity_id
2135     AND    w.status_type    = 1
2136     AND    o.wip_entity_id  = w.wip_entity_id
2137     AND    o.operation_seq_num = p_operation_seq_num
2138     AND    o.organization_id   = p_organization_id;
2139 
2140 CURSOR check_not_existing_op_job
2141   (  p_from_wip_entity_id NUMBER,
2142      p_to_wip_entity_id   NUMBER,
2143      p_operation_seq_num      NUMBER,
2144      p_organization_id    NUMBER )
2145  IS
2146             SELECT 'X'
2147             FROM  DUAL
2148             WHERE  EXISTS (
2149                             SELECT 1
2150                             FROM wip_discrete_jobs wdj,
2151                                  wip_entities we,
2152                                  wip_entities we1,
2153                                  wip_entities we2
2154                             WHERE we1.wip_entity_id = p_from_wip_entity_id
2155                              AND  we2.wip_entity_id = p_to_wip_entity_id
2156                              AND  we.wip_entity_name >= we1.wip_entity_name
2157                              AND  we.wip_entity_name <= we2.wip_entity_name
2158                              AND  wdj.wip_entity_id = we.wip_entity_id
2159                              AND  we.organization_id = p_organization_id
2160                              AND  status_type = 1
2161                              AND  NOT EXISTS (
2162                                     SELECT 1
2163                                     FROM wip_operations wo
2164                                     WHERE wo.wip_entity_id = we.wip_entity_id
2165                                     AND operation_seq_num = p_operation_seq_num
2166                               )
2167               );
2168 
2169  CURSOR check_not_existing_op_lot
2170   ( p_wip_lot_number VARCHAR2,
2171     p_operation_seq_num  NUMBER
2172    )
2173  IS
2174             SELECT 'X'
2175             FROM  DUAL
2176             WHERE  EXISTS (
2177                             SELECT 1
2178                             FROM wip_discrete_jobs wdj
2179                             WHERE  wdj.lot_number= p_wip_lot_number
2180                              AND  wdj.status_type = 1
2181                              AND   wdj.primary_item_id = item.revised_item_id
2182                              AND   wdj.organization_Id = item.organization_id
2183                              AND  NOT EXISTS (
2184                                      SELECT 1
2185                                      FROM wip_operations wo
2186                                      WHERE wo.wip_entity_id = wdj.wip_entity_id
2187                                      AND operation_seq_num = p_operation_seq_num
2188                               )
2189  );
2190 
2191  Cursor old_operation(old_id number) is
2192             select o.change_notice,
2193                    o.implementation_date,
2194                    o.disable_date,
2195                    o.effectivity_date,
2196                    o.operation_sequence_id
2197             from bom_operation_sequences o
2198             where o.operation_sequence_id = old_id
2199             for update of o.change_notice,
2200                           o.disable_date,
2201                           o.last_update_date,
2202                           o.last_updated_by,
2203                           o.last_update_login,
2204                           o.request_id,
2205                           o.program_application_id,
2206                           o.program_id,
2207                           o.program_update_date;
2208  old_op_rec  old_operation%rowtype;
2209 
2210  CURSOR chng_resource_rows is
2211   SELECT  acd_type,
2212           operation_sequence_id,
2213           resource_seq_num,
2214           resource_id
2215   FROM    bom_operation_resources
2216   WHERE   operation_sequence_id= chng_operation_rec.operation_sequence_id;
2217 
2218   chng_resource_rec chng_resource_rows%rowtype;
2219 
2220  CURSOR check_overlapping_operation ( routing_seq_id NUMBER,
2221        operation_num NUMBER, operation_seq_id NUMBER, eff_date DATE)  IS
2222           Select 'x' -- overlapping effectivity
2223             from bom_operation_sequences b
2224             where b.routing_sequence_id= routing_seq_id
2225           --  and b.operation_sequence_id = operation_seq_id
2226             and b.operation_seq_num = operation_num
2227             and b.implementation_date is not null
2228             and b.effectivity_date <= eff_date
2229             and nvl(b.disable_date, eff_date + 1) > eff_date
2230             union
2231             select 'x' -- duplicate value on unique index
2232             from bom_operation_sequences b
2233             where b.routing_sequence_id= routing_seq_id
2234             and b.operation_seq_num = operation_num
2235             and b.effectivity_date = eff_date
2236             and b.operation_sequence_id <> operation_seq_id;
2237 
2238 --for resources conflict check
2239 
2240 CURSOR check_not_existing_res_cum
2241     ( p_from_wip_entity_id NUMBER,
2242       p_operation_seq_num  NUMBER,
2243       p_resource_seq_num   NUMBER,
2244       p_organization_id    NUMBER
2245      )
2246  IS
2247     SELECT 'X'
2248     FROM   wip_operation_resources wor,
2249            wip_discrete_jobs w
2250     WHERE  w.wip_entity_id = p_from_wip_entity_id
2251     AND    w.status_type = 1
2252     AND    wor.wip_entity_id = p_from_wip_entity_id
2253     AND    wor.operation_seq_num = p_operation_seq_num
2254     AND    wor.organization_id = p_organization_id
2255     AND    wor.resource_seq_num = p_resource_seq_num;
2256 
2257 CURSOR check_not_existing_res_job
2258   (  p_from_wip_entity_id NUMBER,
2259      p_to_wip_entity_id   NUMBER,
2260      p_operation_seq_num  NUMBER,
2261      p_resource_seq_num   NUMBER,
2262      p_organization_id    NUMBER
2263   )
2264  IS
2265             SELECT 'X'
2266             FROM  DUAL
2267             WHERE  EXISTS (
2268                             SELECT 1
2269                             FROM wip_discrete_jobs wdj,
2270                                  wip_entities we,
2271                                  wip_entities we1,
2272                                  wip_entities we2
2273                              WHERE we1.wip_entity_id = p_from_wip_entity_id
2274                              AND  we2.wip_entity_id = p_to_wip_entity_id
2275                              AND  we.wip_entity_name >= we1.wip_entity_name
2276                              AND  we.wip_entity_name <= we2.wip_entity_name
2277                              AND  wdj.wip_entity_id = we.wip_entity_id
2278                              AND  we.organization_id = p_organization_id
2279                              AND  status_type = 1
2280                              AND  NOT EXISTS (
2281                                  SELECT 1
2282                                  FROM wip_operation_resources wor
2283                                  WHERE wor.wip_entity_id = we.wip_entity_id
2284                                  AND wor.operation_seq_num = p_operation_seq_num
2285                                  AND wor.resource_seq_num = p_resource_seq_num
2286                                  AND wor.organization_id = p_organization_id
2287                               )
2288               );
2289 
2290 CURSOR check_not_existing_res_lot
2291   ( p_wip_lot_number    VARCHAR2,
2292     p_operation_seq_num NUMBER,
2293     p_resource_seq_num  NUMBER,
2294     p_organization_id   NUMBER
2295   )
2296 IS
2297             SELECT 'X'
2298             FROM  DUAL
2299             WHERE  EXISTS (
2300                             SELECT 1
2301                             FROM wip_discrete_jobs wdj
2302                             WHERE  wdj.lot_number= p_wip_lot_number
2303                             AND   wdj.primary_item_id = item.revised_item_id
2304                             AND   wdj.organization_Id = item.organization_id
2305                             AND  wdj.status_type = 1
2306                             AND  NOT EXISTS (
2307                                  SELECT 1
2308                                  FROM wip_operation_resources wor
2309                                  WHERE wor.wip_entity_id = wdj.wip_entity_id
2310                                  AND wor.operation_seq_num = p_operation_seq_num
2311                                  AND wor.resource_seq_num = p_resource_seq_num
2312                                  AND wor.organization_id = p_organization_id
2313                               )
2314  );
2315 
2316 
2317 -- for components
2318 CURSOR check_not_existing_comp_cum
2319     (p_from_wip_entity_id  NUMBER,
2320      p_operation_seq_num   NUMBER,
2321      p_inventory_item_id   NUMBER,
2322      p_organization_id     NUMBER
2323      )
2324  IS
2325     SELECT 'X'
2326           FROM    wip_requirement_operations ro,
2327                  wip_discrete_jobs w
2328           WHERE  w.wip_entity_id = p_from_wip_entity_id
2329           AND    w.status_type = 1
2330           AND    ro.wip_entity_id       = p_from_wip_entity_id
2331           AND    ro.operation_seq_num   = p_operation_seq_num
2332           AND    ro.organization_id     = p_organization_id
2333           AND    ro.inventory_item_id   = p_inventory_item_id
2334            ;
2335 
2336 CURSOR check_not_existing_comp_job
2337   (  p_from_wip_entity_id NUMBER,
2338      p_to_wip_entity_id   NUMBER,
2339      p_operation_seq_num  NUMBER,
2340      p_inventory_item_id  NUMBER,
2341      p_organization_id    NUMBER
2342    )
2343  IS
2344             SELECT 'X'
2345             FROM  DUAL
2346             WHERE  EXISTS (
2347                             SELECT 1
2348                             FROM wip_discrete_jobs wdj,
2349                                  wip_entities we,
2350                                  wip_entities we1,
2351                                  wip_entities we2
2352                              WHERE we1.wip_entity_id = p_from_wip_entity_id
2353                              AND  we2.wip_entity_id = p_to_wip_entity_id
2354                              AND  we.wip_entity_name >= we1.wip_entity_name
2355                              AND  we.wip_entity_name <= we2.wip_entity_name
2356                              AND  wdj.wip_entity_id = we.wip_entity_id
2357                              AND  we.organization_id = p_organization_id
2358                              AND  status_type = 1
2359                              AND  NOT EXISTS (
2360                                   SELECT 1
2361                                   FROM wip_requirement_operations ro
2362                                   WHERE ro.wip_entity_id = we.wip_entity_id
2363                                   AND ro.operation_seq_num = p_operation_seq_num
2364                                   AND ro.inventory_item_id= p_inventory_item_id
2365                                   AND ro.organization_id = p_organization_id
2366                               )
2367               );
2368 
2369 CURSOR check_not_existing_comp_lot
2370   ( p_wip_lot_number    VARCHAR2,
2371     p_operation_seq_num NUMBER,
2372     p_inventory_item_id NUMBER,
2373     p_organization_id   NUMBER
2374   )
2375 IS
2376             SELECT 'X'
2377             FROM  DUAL
2378             WHERE  EXISTS (
2379                             SELECT 1
2380                             FROM wip_discrete_jobs wdj
2381                             WHERE  wdj.lot_number= p_wip_lot_number
2382                             AND   wdj.primary_item_id = item.revised_item_id
2383                             AND   wdj.organization_Id = item.organization_id
2384                             AND    wdj.status_type = 1
2385                             AND    NOT EXISTS (
2386                                SELECT 1
2387                                FROM wip_requirement_operations ro
2388                                WHERE ro.wip_entity_id = wdj.wip_entity_id
2389                                AND ro.operation_seq_num = p_operation_seq_num
2390                                AND ro.inventory_item_id = p_inventory_item_id
2391                                AND ro.organization_id = p_organization_id
2392                               )
2393  );
2394 
2395 -- Variables for ECO Enhancement
2396 -- l_rtg_header_rec        BOM_Rtg_Pub.rtg_header_Rec_Type;
2397 -- l_rtg_header_unexp_rec  BOM_Rtg_Pub.rtg_header_unexposed_Rec_Type;
2398 -- l_mesg_token_Tbl        Error_Handler.Mesg_Token_Tbl_Type;
2399  l_alternate_routing_designator    VARCHAR2(10);
2400  l_return_status         VARCHAR2(1);
2401 
2402 -- Vairables for update wip
2403   l_wip_group_id1               NUMBER ;
2404   l_wip_group_id2               NUMBER ;
2405   l_wip_header_id               NUMBER ;
2406   l_wip_organization_id         NUMBER;
2407   l_wip_load_type               NUMBER :=1;
2408   l_wip_status_type             NUMBER :=1;
2409   l_wip_primary_item_id         NUMBER;
2410   l_wip_bom_revision_date1      DATE;
2411   l_wip_routing_revision_date1  DATE;
2412   l_wip_bom_revision_date2      DATE;
2413   l_wip_routing_revision_date2  DATE;
2414   l_wip_job_name                VARCHAR2(240):=NULL;
2415   l_wip_job_name1               VARCHAR2(240):=NULL;
2416   l_wip_job_name2               VARCHAR2(240):=NULL;
2417   l_wip_start_quantity1         NUMBER;
2418   l_wip_start_quantity2         NUMBER;
2419   l_wip_process_phase           NUMBER :=2;
2420   l_wip_process_status          NUMBER :=1;
2421   l_wip_last_u_compl_date1      DATE;
2422   l_wip_last_u_compl_date2      DATE;
2423   l_wip_completion_locator_id   NUMBER;
2424   l_wip_routing_revision1       VARCHAR2(3):=NULL;
2425   l_wip_routing_revision2       VARCHAR2(3):=NULL;
2426   l_wip_bom_revision1           VARCHAR2(3):=NULL;
2427   l_wip_bom_revision2           VARCHAR2(3):=NULL;
2428   l_wip_completion_subinventory VARCHAR2(10):=NULL;
2429   l_wip_net_quantity1           NUMBER :=0;
2430   l_wip_net_quantity2           NUMBER :=0;
2431   l_wip_allow_explosion         VARCHAR2(1) := 'Y';
2432   l_wip_jsi_insert_flag         NUMBER :=0;
2433   l_old_op_seq_num              NUMBER :=0;    -- bug2722280
2434 
2435   l_update_wip                  NUMBER;
2436   l_wip_from_cum_qty            NUMBER;
2437   l_from_wip_entity_id          NUMBER;
2438   l_to_wip_entity_id            NUMBER;
2439   l_lot_number                  VARCHAR2(30):=NULL;
2440   --l_effective_date              date;
2441   --l_update_all_jobs             NUMBER := 2 ;     Bug 5657390 declared in the beginning
2442   l_eco_for_production          NUMBER := 2 ;
2443 
2444   -- Bug 4455543
2445   -- Added the following flag to check if routing details have been updated
2446   -- for the revised item. Only then the routing details are set on the
2447   -- wip_job_schedules_interface. Otherwise they are not set.
2448   -- This is done so that WIP does not explode routings when there has been
2449   -- no changes for them as part of the revised item.
2450   l_WIP_Flag_for_Routing   VARCHAR2(1);
2451 
2452 -- for inserting rows to wip schedule interface
2453 
2454 --  Cursor was added to resolve the bug 2722280
2455 CURSOR get_old_operation_seq_num
2456   (  p_old_component_sequence_id NUMBER
2457    )
2458  IS
2459 
2460    SELECT operation_seq_num
2461    FROM   bom_components_b --bom_inventory_components
2462    WHERE  component_sequence_id = p_old_component_sequence_id ;
2463 -- Cursor completed Bug 2722280
2464 
2465 CURSOR l_wip_name_for_job_cur
2466  IS
2467          SELECT we.wip_entity_name,
2468                 we.organization_id,
2469                 wdj.start_quantity,
2470                 wdj.scheduled_start_date,
2471                 wdj.scheduled_completion_date,
2472                 wdj.primary_item_id,
2473                 wdj.alternate_bom_designator,           --2964588
2474                 wdj.alternate_routing_designator,           --2964588
2475                 wdj.bom_revision_date,
2476                 wdj.routing_revision_date,
2477                 null bom_revision,              -- Bug 3381547
2478                 null routing_revision           -- Bug 3381547
2479          FROM wip_discrete_jobs wdj,
2480               wip_entities we,
2481               wip_entities we1,
2482               wip_entities we2
2483          WHERE we1.wip_entity_id = l_from_wip_entity_id
2484          AND  we2.wip_entity_id = l_to_wip_entity_id
2485          AND  ( (we.wip_entity_name >= we1.wip_entity_name
2486                 and we.wip_entity_name <= we2.wip_entity_name)
2487               )
2488          AND  we.organization_id = l_wip_organization_id
2489          AND  wdj.wip_entity_id = we.wip_entity_id
2490          AND  wdj.status_type = 1
2491          AND  wdj.job_type = 1                -- 2986915
2492          AND  (( wdj.scheduled_start_date >= eff_date
2493                 OR wdj.scheduled_completion_date >= eff_date)       --1900068
2494                 OR l_update_all_jobs =1)                --bug 2327582.
2495  /* Modified for Bug 2883762 */
2496    UNION
2497           SELECT we.wip_entity_name,
2498                 we.organization_id,
2499                 wdj.start_quantity,
2500                 wdj.scheduled_start_date,
2501                 wdj.scheduled_completion_date,
2502                 wdj.primary_item_id,
2503                 wdj.alternate_bom_designator,           --2964588
2504                 wdj.alternate_routing_designator,           --2964588
2505                 wdj.bom_revision_date,
2506                 wdj.routing_revision_date,
2507                 wdj.bom_revision  bom_revision,               -- Bug 3381547
2508                 wdj.routing_revision routing_revision         -- Bug 3381547
2509          FROM wip_discrete_jobs wdj,
2510               wip_entities we,
2511               wip_requirement_operations o,
2512               wip_entities we1,
2513               wip_entities we2
2514          WHERE wdj.wip_entity_id = we.wip_entity_id
2515            AND   we1.wip_entity_id = l_from_wip_entity_id
2516            AND  we2.wip_entity_id = l_to_wip_entity_id
2517            AND  ( (we.wip_entity_name >= we1.wip_entity_name
2518                 and we.wip_entity_name <= we2.wip_entity_name)
2519               )
2520 
2521            AND  wdj.status_type = 1
2522          AND  wdj.job_type = 1                -- 2986915
2523            AND (( wdj.scheduled_start_date >= eff_date
2524              or wdj.scheduled_completion_date >= eff_date )          --1900068
2525              OR l_update_all_jobs =1)                         --bug 2327582
2526           AND wdj.organization_id = we.organization_id
2527           AND we.organization_id = o.organization_id
2528           AND we.wip_entity_id = o.wip_entity_id
2529           AND o.inventory_item_id = l_wip_primary_item_id
2530           AND o.organization_id = l_wip_organization_id
2531           AND o.repetitive_schedule_id is NULL
2532           AND o.wip_supply_type = 6 ;
2533 
2534 wip_name_for_job_rec l_wip_name_for_job_cur%ROWTYPE;
2535 
2536 
2537 CURSOR  l_wip_name_for_lot_cur
2538  IS
2539          SELECT we.wip_entity_name,
2540                 we.organization_id,
2541                 wdj.start_quantity,
2542                 wdj.scheduled_start_date,
2543                 wdj.scheduled_completion_date,
2544                 wdj.primary_item_id,
2545                 wdj.alternate_bom_designator,           --2964588
2546                 wdj.alternate_routing_designator,           --2964588
2547                 wdj.bom_revision_date,
2548                 wdj.routing_revision_date,
2549                 null bom_revision,            -- Bug 3381547
2550                 null routing_revision         -- Bug 3381547
2551          FROM wip_discrete_jobs wdj,
2552               wip_entities we,
2553               bom_bill_of_materials b         --3412747
2554          WHERE we.organization_id = wdj.organization_id
2555          AND  we.wip_entity_id = wdj.wip_entity_id
2556          AND  wdj.status_type = 1
2557          AND  wdj.job_type = 1                -- 2986915
2558          AND (( wdj.scheduled_start_date >= eff_date
2559               or wdj.scheduled_completion_date >= eff_date)           --1900068
2560                OR l_update_all_jobs =1)             --bug 2327582
2561          AND  wdj.lot_number = l_lot_number
2562          --AND   wdj.primary_item_id = item.revised_item_id  --3412747
2563          AND  wdj.primary_item_id = b.assembly_item_id
2564          AND  wdj.organization_id = b.organization_id
2565          AND nvl(wdj.alternate_bom_designator,'NO ALTERNATE') =
2566                 nvl(b.alternate_bom_designator,'NO ALTERNATE')
2567          --AND b.common_bill_sequence_id = item.bill_sequence_id
2568          AND b.source_bill_sequence_id = item.bill_sequence_id
2569           /* Modified for Bug 2883762 */
2570    UNION
2571           SELECT we.wip_entity_name,
2572                 we.organization_id,
2573                 wdj.start_quantity,
2574                 wdj.scheduled_start_date,
2575                 wdj.scheduled_completion_date,
2576                 wdj.primary_item_id,
2577                 wdj.alternate_bom_designator,           --2964588
2578                 wdj.alternate_routing_designator,           --2964588
2579                 wdj.bom_revision_date,
2580                 wdj.routing_revision_date,
2581                 wdj.bom_revision  bom_revision,               -- Bug 3381547
2582                 wdj.routing_revision routing_revision         -- Bug 3381547
2583          FROM wip_discrete_jobs wdj,
2584               wip_entities we,
2585               wip_requirement_operations o
2586          WHERE wdj.wip_entity_id = we.wip_entity_id
2587            AND  wdj.status_type = 1
2588          AND  wdj.job_type = 1                -- 2986915
2589            AND (( wdj.scheduled_start_date >= eff_date
2590              or wdj.scheduled_completion_date >= eff_date )          --1900068
2591              OR l_update_all_jobs =1)                         --bug 2327582
2592           AND wdj.organization_id = we.organization_id
2593           AND we.organization_id = o.organization_id
2594           AND we.wip_entity_id = o.wip_entity_id
2595           AND o.inventory_item_id = l_wip_primary_item_id
2596           AND o.organization_id = l_wip_organization_id
2597           AND o.repetitive_schedule_id is NULL
2598           AND o.wip_supply_type = 6
2599           AND wdj.lot_number = l_lot_number;
2600 
2601 
2602 wip_name_for_lot_rec l_wip_name_for_lot_cur%ROWTYPE;
2603 
2604 CURSOR  l_wip_name_for_common_cur
2605  IS
2606          SELECT we.wip_entity_name,
2607                 we.organization_id,
2608                 wdj.start_quantity,
2609                 wdj.scheduled_start_date,
2610                 wdj.scheduled_completion_date,
2611                 wdj.primary_item_id,
2612                 wdj.alternate_bom_designator,           --2964588
2613                 wdj.alternate_routing_designator,           --2964588
2614                 wdj.bom_revision_date,
2615                 wdj.routing_revision_date,
2616                 null bom_revision,                         -- Bug 3381547
2617                 null routing_revision                      -- Bug 3381547
2618          FROM wip_discrete_jobs wdj,
2619               wip_entities we,
2620               bom_bill_of_materials b                         --3412747
2621          WHERE we.organization_id = wdj.organization_id
2622          --WHERE we.organization_id = l_wip_organization_id
2623          AND  wdj.wip_entity_id = we.wip_entity_id
2624          AND  wdj.status_type = 1
2625          AND  wdj.job_type = 1                -- 2986915
2626          AND (( wdj.scheduled_start_date >= eff_date
2627               or wdj.scheduled_completion_date >= eff_date )          --1900068
2628              OR l_update_all_jobs =1)                         --bug 2327582
2629          --AND  wdj.primary_item_id = l_wip_primary_item_id   --3412747
2630          AND  wdj.primary_item_id = b.assembly_item_id
2631          AND  wdj.organization_id = b.organization_id
2632          AND nvl(wdj.alternate_bom_designator,'NO ALTERNATE') =
2633              nvl(b.alternate_bom_designator,'NO ALTERNATE')
2634          --AND b.common_bill_sequence_id = item.bill_sequence_id
2635          AND b.source_bill_sequence_id = item.bill_sequence_id
2636          AND  l_lot_number IS NULL
2637          AND  l_from_wip_entity_id IS NULL
2638          AND  l_to_wip_entity_id IS NULL
2639         /* Modified for Bug 2883762 */
2640          UNION
2641           SELECT we.wip_entity_name,
2642                 we.organization_id,
2643                 wdj.start_quantity,
2644                 wdj.scheduled_start_date,
2645                 wdj.scheduled_completion_date,
2646                 wdj.primary_item_id,
2647                 wdj.alternate_bom_designator,           --2964588
2648                 wdj.alternate_routing_designator,           --2964588
2649                 wdj.bom_revision_date,
2650                 wdj.routing_revision_date,
2651                 wdj.bom_revision  bom_revision,               -- Bug 3381547
2652                 wdj.routing_revision routing_revision         -- Bug 3381547
2653          FROM wip_discrete_jobs wdj,
2654               wip_entities we,
2655               bom_bill_of_materials b,                        --3412747
2656               wip_requirement_operations o
2657          WHERE wdj.wip_entity_id = we.wip_entity_id
2658            AND  wdj.status_type = 1
2659          AND  wdj.job_type = 1                -- 2986915
2660            AND (( wdj.scheduled_start_date >= eff_date
2661              or wdj.scheduled_completion_date >= eff_date )          --1900068
2662              OR l_update_all_jobs =1)                         --bug 2327582
2663           AND wdj.organization_id = we.organization_id
2664           AND we.organization_id = o.organization_id
2665           AND we.wip_entity_id = o.wip_entity_id
2666           --AND o.inventory_item_id = l_wip_primary_item_id   --3412747
2667           --AND o.organization_id = l_wip_organization_id
2668           AND o.inventory_item_id = b.assembly_item_id
2669           AND o.organization_id = b.organization_id
2670           AND (nvl(wdj.alternate_bom_designator,'NO ALTERNATE') =
2671                nvl(b.alternate_bom_designator,'NO ALTERNATE')
2672                or
2673                (wdj.alternate_bom_designator is not null
2674                 and
2675                 b.alternate_bom_designator is null
2676                 and not exists (select null
2677                                 from bom_bill_of_materials b2
2678                                 where b2.organization_id = b.organization_id
2679                                 and b2.assembly_item_id = b.assembly_item_id
2680                                 and b2.alternate_bom_designator =
2681                                     wdj.alternate_bom_designator)
2682                )
2683               )
2684           AND b.source_bill_sequence_id = item.bill_sequence_id -- r12 common bom changes
2685           --AND b.common_bill_sequence_id = item.bill_sequence_id
2686           AND o.repetitive_schedule_id is NULL
2687           AND o.wip_supply_type = 6 ;
2688 
2689 wip_name_for_common_rec l_wip_name_for_common_cur%ROWTYPE;
2690 
2691     CURSOR mfgitem_already_exists(p_tomfg_item IN VARCHAR2)
2692     IS
2693         SELECT 1
2694         FROM mtl_system_items_kfv
2695         WHERE concatenated_segments = p_tomfg_item;
2696 
2697     CURSOR Get_starting_revision (p_org_id IN NUMBER)
2698     IS
2699             select starting_revision
2700             from mtl_parameters where
2701             organization_id = p_org_id;
2702 
2703     Cursor Check_Item(p_item_id  IN NUMBER,
2704                       p_org_id   IN NUMBER) is
2705     Select 'x' dummy
2706     From mtl_system_items msi
2707     Where msi.inventory_item_id = p_item_id
2708     And   msi.organization_id = p_org_id
2709     And   msi.eng_item_flag = 'N';
2710 
2711     Cursor Check_Bill(p_item_id   IN NUMBER,
2712                       p_org_id    IN NUMBER,
2713                       p_alternate IN VARCHAR2) is
2714     Select 'x' dummy
2715     From bom_bill_of_materials bbom
2716     Where bbom.assembly_item_id = p_item_id
2717     And   bbom.organization_id = p_org_id
2718     And   nvl(bbom.alternate_bom_designator, 'PRIMARY ALTERNATE') =
2719           nvl(p_alternate, 'PRIMARY ALTERNATE')
2720     And   bbom.assembly_type = 1;
2721 
2722     Cursor Check_Routing(p_item_id   IN NUMBER,
2723                          p_org_id    IN NUMBER,
2724                          p_alternate IN VARCHAR2) is
2725     Select 'x' dummy
2726     From bom_operational_routings bor
2727     Where bor.assembly_item_id = p_item_id
2728     And   bor.organization_id = p_org_id
2729     And   nvl(bor.alternate_routing_designator, 'PRIMARY ALTERNATE') =
2730           nvl(p_alternate, 'PRIMARY ALTERNATE')
2731     And   bor.routing_type = 1;
2732 
2733     l_item_revision               VARCHAR2(3);
2734     l_routing_revision            VARCHAR2(3);
2735     l_new_assembly_item_id        NUMBER;
2736     l_concatenated_copy_segments  VARCHAR2(2000);
2737 
2738     TYPE SEGMENTARRAY IS table of VARCHAR2(150) index by BINARY_INTEGER;
2739 
2740     copy_segments SEGMENTARRAY;
2741     l_language_code     VARCHAR2(10);  --Bug 2963301
2742 
2743     l_impl_date                         DATE;
2744     l_max_scheduled_date                DATE;
2745     l_implement_revised_item            NUMBER := 1;
2746     l_Item_rec_in                       INV_ITEM_GRP.Item_Rec_Type;
2747     l_revision_rec                      INV_ITEM_GRP.Item_Revision_Rec_Type;
2748     l_Item_rec_out                      INV_ITEM_GRP.Item_Rec_Type;
2749     l_inv_return_status                 VARCHAR2(1);
2750     l_Error_tbl                         INV_ITEM_GRP.Error_Tbl_Type;
2751     l_item_lifecycle_changed            NUMBER := 0;
2752     l_lc_return_status                  VARCHAR2(1);
2753 
2754     CURSOR c_local_org_rev_items (p_change_id                   NUMBER,
2755                                   p_revised_item_sequence_id    NUMBER
2756     ) IS
2757         SELECT scheduled_date, implementation_date
2758         FROM eng_revised_items
2759         WHERE revised_item_sequence_id IN
2760                 (SELECT local_revised_item_sequence_id
2761                 FROM eng_change_logs_vl
2762                 WHERE (local_change_id, local_organization_id) IN
2763                         (SELECT object_to_id1, object_to_id3 -- local_change_id, local_org_id
2764                         From Eng_Change_Obj_Relationships
2765                         Where object_to_name = 'ENG_CHANGE'
2766                         and   change_id = p_change_id
2767                         And   relationship_code = 'PROPAGATED_TO')
2768                 AND local_change_id IS NOT NULL
2769                 AND local_revised_item_sequence_id IS NOT NULL
2770                 AND log_classification_code = 'PROPAGATN'
2771                 AND change_id = p_change_id
2772                 AND revised_item_sequence_id =  p_revised_item_sequence_id
2773                 AND log_type_code = 'INFO')
2774         AND status_type <> 5
2775         AND transfer_or_copy = 'O'
2776         AND parent_revised_item_seq_id IS NULL;
2777 
2778   -- Fix for bug 3463308
2779   l_item_key    VARCHAR2(240) := NULL;
2780   l_action_id   NUMBER := NULL;
2781 
2782   -- Added for bug 3482152
2783   l_curr_status_code            NUMBER;
2784   l_implement_header            VARCHAR2(1);
2785   l_plm_or_erp_change           VARCHAR2(3);
2786   l_wf_route_id                 NUMBER; -- Bug 3479509
2787   l_overlap_found               NUMBER;
2788 
2789   -- Added For 11510+ Enhancement
2790 
2791   l_effectivity_control         NUMBER;
2792   l_revision_eff_bill           VARCHAR2(1);
2793   l_from_rev_eff_date           DATE;
2794   l_to_rev_eff_date             DATE;
2795   l_old_from_rev_eff_date       DATE;
2796   l_old_to_rev_eff_date         DATE;
2797   l_from_revision               VARCHAR2(3);
2798   l_current_end_item_revision   VARCHAR2(3);
2799   l_to_revision                 VARCHAR2(3);
2800   l_from_end_item_id            NUMBER;
2801   l_disabled_old_comp           NUMBER;
2802   l_valid_from_to_revision      NUMBER;
2803   l_prev_end_item_rev_id        NUMBER;
2804   l_prev_end_item_eff           DATE;
2805 
2806   Cursor get_bill_effectivity_control (cp_bill_id NUMBER)
2807   Is
2808   SELECT effectivity_control
2809   FROM bom_structures_b
2810   WHERE bill_sequence_id = cp_bill_id;
2811 
2812   Cursor check_impl_revision ( cp_revision_id NUMBER
2813                              , cp_item_id     NUMBER
2814                              , cp_org_id      NUMBER)
2815   Is
2816   select effectivity_date, revision
2817   from mtl_item_revisions_b
2818   where revision_id = cp_revision_id
2819   and inventory_item_id = cp_item_id
2820   and organization_id = cp_org_id
2821   and implementation_date is not null;
2822 
2823   Cursor check_from_to_revision ( cp_from_rev_eff      DATE
2824                                 , cp_comp_sequence_id  NUMBER)
2825   Is
2826   SELECT -1
2827   FROM bom_components_b bcb
2828   where bcb.component_sequence_id = cp_comp_sequence_id
2829   AND cp_from_rev_eff >= (SELECT mirb1.effectivity_date FROM mtl_item_revisions_b mirb1
2830                           WHERE mirb1.revision_id = bcb.from_end_item_rev_id)
2831   AND (bcb.to_end_item_rev_id is null
2832        OR cp_from_rev_eff <= (SELECT mirb2.effectivity_date FROM mtl_item_revisions_b mirb2
2833                               WHERE mirb2.revision_id = bcb.to_end_item_rev_id)
2834       );
2835 
2836   Cursor get_prev_impl_revision ( cp_item_id NUMBER
2837                                 , cp_org_id NUMBER
2838                                 , cp_effec_date DATE)
2839   Is
2840   Select mirb1.revision_id, mirb1.effectivity_date
2841   from mtl_item_revisions_b mirb1
2842   where mirb1.inventory_item_id =  cp_item_id
2843   and mirb1.organization_id = cp_org_id
2844   and mirb1.effectivity_date < cp_effec_date
2845   and mirb1.implementation_date is not null
2846   and rownum < 2
2847   order by mirb1.revision desc;
2848 
2849   Cursor check_existing_rev_eff_comp( cp_bill_id           NUMBER
2850                                     , cp_component_item_id NUMBER
2851                                     , cp_operation_seq_num NUMBER
2852                                     , cp_end_item_id       NUMBER
2853                                     , cp_org_id            NUMBER
2854                                     , cp_from_rev_eff      DATE
2855                                     , cp_to_rev_eff        DATE)
2856   Is
2857   SELECT 1
2858   FROM bom_components_b bcb
2859   where bcb.bill_sequence_id = cp_bill_id
2860   and bcb.component_item_id = cp_component_item_id
2861   and bcb.operation_seq_num = cp_operation_seq_num
2862   and bcb.implementation_date is not null
2863   and bcb.disable_date is NULL
2864   AND EXISTS (SELECT null FROM mtl_item_revisions_b mirb1 WHERE
2865               mirb1.inventory_item_id = cp_end_item_id AND mirb1.organization_id  = cp_org_id
2866               AND mirb1.revision_id = bcb.from_end_item_rev_id)
2867   AND ( cp_to_rev_eff IS NULL
2868         OR cp_to_rev_eff >= (SELECT mirb2.effectivity_date FROM mtl_item_revisions_b mirb2
2869                              WHERE mirb2.revision_id = bcb.from_end_item_rev_id)
2870       )
2871   AND ( bcb.to_end_item_rev_id IS NULL
2872         OR cp_from_rev_eff <= (SELECT mirb3.effectivity_date FROM mtl_item_revisions_b mirb3
2873                                WHERE mirb3.revision_id = bcb.to_end_item_rev_id)
2874       );
2875   -- End Changes: 11510+ Enhancement
2876 
2877   -- Added for bug 4150069
2878   -- Cusrsor to fetch the revision given the revision id.
2879   Cursor c_get_revision (cp_revision_id NUMBER)
2880   Is
2881   select revision, implementation_date
2882   from mtl_item_revisions_b
2883   where revision_id = cp_revision_id;
2884 
2885   l_revitem_from_rev    mtl_item_revisions_b.revision%TYPE;
2886   l_rev_impl_date       DATE;
2887   -- End Changes For bug 4150069
2888   -- Bug 4213886
2889   l_compitem_rev        mtl_item_revisions_b.revision%TYPE;
2890   l_compitem_rev_impldate DATE;
2891 
2892   -- R12 : Changes for common BOM
2893   CURSOR check_if_commoned_bom( cp_bill_id IN NUMBER) IS
2894   SELECT nvl(bsb.SOURCE_BILL_SEQUENCE_ID, bsb.BILL_SEQUENCE_ID) SOURCE_BILL_SEQUENCE_ID
2895   FROM bom_structures_b bsb
2896   WHERE bsb.source_bill_sequence_id = cp_bill_id
2897     AND bsb.bill_sequence_id <> bsb.source_bill_sequence_id;
2898   -- Cursor to fetch the valid value of effectivity date when the
2899   -- effectivity date is in the future.
2900   -- For common bom the component change made are to be immediately effective
2901   CURSOR get_common_bom_eff_date( cp_bill_id IN NUMBER, cp_rev_seq_id IN NUMBER ) IS
2902   SELECT bcb.effectivity_date
2903     FROM bom_components_b bcb
2904    WHERE bcb.revised_item_sequence_id = cp_rev_seq_id
2905      AND bcb.bill_sequence_id = cp_bill_id
2906      AND EXISTS
2907          (SELECT 1
2908             FROM bom_structures_b bsb
2909            WHERE bsb.bill_sequence_id = cp_bill_id
2910              AND bsb.bill_sequence_id <> bsb.source_bill_sequence_id)
2911      AND ROWNUM < 2;
2912 
2913   commoned_bom           check_if_commoned_bom%rowtype;
2914   l_common_bom_eff_date  DATE;
2915   l_comn_return_status   VARCHAR2(1);
2916   l_comn_Mesg_Token_Tbl  Error_Handler.Mesg_Token_Tbl_Type;
2917   -- R12 : End Changes for common BOM
2918 
2919   -- Bug 4584490 : Changes for BOM Business Events
2920   l_Comp_Child_Entity_Modified NUMBER;
2921   l_BOMEvents_Comps_ACD        NUMBER;
2922   l_BOMEvents_Bill_Event_Name  VARCHAR2(240);
2923   CURSOR c_Comp_Child_Entity_Modified(cp_component_sequence_id IN NUMBER)
2924   IS
2925   SELECT 1 FROM dual
2926    WHERE EXISTS (SELECT 1 FROM bom_substitute_components
2927                   WHERE component_sequence_id = cp_component_sequence_id
2928                     AND acd_type IS NOT NULL)
2929       OR EXISTS (SELECT 1 FROM bom_substitute_components
2930                   WHERE component_sequence_id = cp_component_sequence_id
2931                     AND acd_type IS NOT NULL);
2932   -- End Changes for bug 4584490
2933 
2934 -- Bug 5854437 Start
2935         rec_exist               NUMBER := 0;
2936         l_error_msg_count       NUMBER := 0;
2937 
2938         Cursor chng_sub_component_rows is
2939         SELECT a.component_sequence_id,
2940                      b.old_component_sequence_id,
2941                      a.acd_type,
2942                      a.substitute_component_id,
2943                      f.concatenated_segments item_number
2944         FROM bom_substitute_components a,
2945                   bom_inventory_components b,
2946                   mtl_system_items_b_kfv f
2947         WHERE a.component_sequence_id = b.component_sequence_id
2948                   and b.revised_item_sequence_id = revised_item
2949                   and f.inventory_item_id = a.substitute_component_id
2950 --                  and f.organization_id = item.organization_id
2951                   and f.organization_id = b.pk2_value
2952                   and nvl(a.acd_type,acd_add) = acd_add;
2953 
2954            Cursor check_existing_substitutes(X_old_comp_seq_id number,X_sub_comp_id number,X_change_notice varchar2) is
2955        select 'x'
2956             from bom_substitute_components a, bom_inventory_components b
2957                where a.component_sequence_id = b.component_sequence_id
2958                and b.component_sequence_id = X_old_comp_seq_id
2959                and nvl(a.acd_type, acd_add) = acd_add
2960                and b.change_notice = X_change_notice
2961                and a.substitute_component_id = X_sub_comp_id;
2962 -- Bug 5854437 End
2963 
2964 Begin
2965 
2966 msg_qty := 0;
2967 warnings := 0;
2968 rev_op_disable_date_tbl.delete;
2969 rev_comp_disable_date_tbl.delete;
2970 
2971 -- Bug 4455543: Initialize l_WIP_Flag_for_Routing
2972 l_WIP_Flag_for_Routing := 'N';
2973 --
2974 
2975 -- Get item information
2976 Open get_item_info;
2977 Fetch get_item_info into item;
2978 /* -- changed for bug 2827313
2979 Select trunc(sysdate, 'MI')
2980 into   now
2981 from dual;
2982 today := trunc(now, 'DD');
2983 */
2984 now := p_now;
2985 today := now;
2986 
2987 --Code changes for bug 5846248 starts
2988 --If this is a transfer operation (or copy operation also--)
2989 IF (Nvl(item.transfer_or_copy,'N') = 'T'  OR Nvl(item.transfer_or_copy,'N') = 'C') THEN
2990 BEGIN
2991   IF(item.bom_enabled_flag = 'N' ) THEN
2992       -- The user cannot try to transfer/copy a bill or routings when the bom_enabled flag of the item is false..
2993       IF( item.transfer_or_copy_bill = 1 OR item.transfer_or_copy_routing = 1) THEN
2994 
2995             msg_qty := msg_qty + 1;
2996             message_names(msg_qty) :=
2997                       'ENG_CANNOT_TRANSFER_OR_COPY';
2998             token1(msg_qty) := 'ITEM_NAME';
2999             value1(msg_qty) := item.concatenated_segments;
3000             translate1(msg_qty) := 0;
3001             IF trial_mode = no THEN
3002                   Raise abort_implementation;
3003             END IF;
3004 
3005       END IF;
3006   END IF;
3007 END;
3008 END IF;
3009 
3010 IF (Nvl(item.transfer_or_copy,'N') = 'T'  OR Nvl(item.transfer_or_copy,'N') = 'C') THEN
3011 DECLARE
3012 l_no_bom_dis_comps NUMBER;
3013 l_no_bom_dis_sub_comps NUMBER;
3014 BEGIN
3015 
3016       IF(item.transfer_or_copy_bill = 1 OR item.transfer_or_copy_routing = 1)  then
3017         IF(item.implemented_only = 1) THEN
3018             --if it's implemented only then check if it's already implemented or going to be implemented as a part of this change...
3019             select count(*) into l_no_bom_dis_comps from dual where exists(
3020               select 1 from mtl_system_items_b where inventory_item_id in
3021               (
3022                 select COMPONENT_ITEM_ID from bom_components_b WHERE bill_sequence_id IN
3023                 (
3024                   select bill_sequence_id from bom_bill_of_materials where
3025                   ASSEMBLY_ITEM_ID = item.revised_item_id AND
3026                   ORGANIZATION_ID = item.organization_id AND
3027                   (
3028                     (item.designator_selection_type = 1) --select everything
3029                     OR  (item.designator_selection_type =2 AND ALTERNATE_BOM_DESIGNATOR IS NULL) --select only primary BOM
3030                     OR (item.designator_selection_type = 3 AND ALTERNATE_BOM_DESIGNATOR = item.alternate_bom_designator) --select that particular  BOM
3031                   )
3032                 )
3033                 AND (CHANGE_NOTICE IS NULL OR IMPLEMENTATION_DATE IS NOT NULL OR  revised_item_sequence_id = revised_item)
3034               ) and organization_id = item.organization_id and bom_enabled_flag = 'N'
3035             );
3036         ELSE
3037             -- If implemented only is not set then check everything even other pending ECOS
3038             select count(*) into l_no_bom_dis_comps from dual where exists(
3039               select 1 from mtl_system_items_b where inventory_item_id in
3040               (
3041                 select COMPONENT_ITEM_ID from bom_components_b WHERE bill_sequence_id IN
3042                 (
3043                   select bill_sequence_id from bom_bill_of_materials where
3044                   ASSEMBLY_ITEM_ID = item.revised_item_id AND
3045                   ORGANIZATION_ID = item.organization_id   AND
3046                   (
3047                     (item.designator_selection_type = 1) --select everything
3048                     OR  (item.designator_selection_type =2 AND ALTERNATE_BOM_DESIGNATOR IS NULL) --select only primary BOM
3049                     OR (item.designator_selection_type = 3 AND ALTERNATE_BOM_DESIGNATOR = item.alternate_bom_designator) --select that particular  BOM
3050                   )
3051                 )
3052              ) and organization_id = item.organization_id and bom_enabled_flag = 'N'
3053             );
3054         END IF;
3055 
3056         -- throw error if l_no_bom_dis_comps is greater than 0
3057         IF(l_no_bom_dis_comps >0) THEN
3058           msg_qty := msg_qty + 1;
3059           message_names(msg_qty) :=
3060                     'ENG_COMP_NOT_BOM_ENABLED';
3061           token1(msg_qty) := 'OPERATION_NAME';
3062           value1(msg_qty) := 'Implement';
3063           translate1(msg_qty) := 0;
3064           token2(msg_qty) :=  'RI_NAME';
3065           value2(msg_qty) :=  item.concatenated_segments;
3066           translate2(msg_qty) := 0;
3067           translate2(msg_qty) := 0;
3068           IF trial_mode = no THEN
3069                 Raise abort_implementation;
3070           END IF;
3071         END IF;
3072 
3073 
3074         --Get all the sub components for which bom_enabled_flag is false...
3075         IF(item.implemented_only = 1) THEN
3076               select count(*) into l_no_bom_dis_sub_comps from dual where exists(
3077                 select 1 from mtl_system_items_b WHERE  inventory_item_id IN
3078                 (
3079                   --Get all the sub components for all the components for this item
3080                   select SUBSTITUTE_COMPONENT_ID from bom_substitute_components where COMPONENT_SEQUENCE_ID in(
3081                             -- Get all the components for this item
3082                             select COMPONENT_SEQUENCE_ID from bom_components_b WHERE bill_sequence_id IN
3083                             (
3084                               select bill_sequence_id from bom_bill_of_materials where
3085                               ASSEMBLY_ITEM_ID = item.revised_item_id AND
3086                               ORGANIZATION_ID = item.organization_id  AND
3087                               (
3088                                 (item.designator_selection_type = 1) --select everything
3089                                 OR  (item.designator_selection_type =2 AND ALTERNATE_BOM_DESIGNATOR IS NULL) --select only primary BOM
3090                                 OR (item.designator_selection_type = 3 AND ALTERNATE_BOM_DESIGNATOR = item.alternate_bom_designator) --select that particular  BOM
3091                               )
3092 
3093                             ) AND (CHANGE_NOTICE IS NULL OR IMPLEMENTATION_DATE IS NOT NULL OR  revised_item_sequence_id = revised_item)
3094                   )
3095                 )  and organization_id = item.organization_id and bom_enabled_flag = 'N'
3096               );
3097         ELSE
3098              select count(*) into l_no_bom_dis_sub_comps from dual where exists(
3099               select 1 from mtl_system_items_b WHERE  inventory_item_id IN
3100                 (
3101                   --Get all the sub components for all the components for this item
3102                   select SUBSTITUTE_COMPONENT_ID from bom_substitute_components where COMPONENT_SEQUENCE_ID in(
3103                             -- Get all the components for this item
3104                             select COMPONENT_SEQUENCE_ID from bom_components_b WHERE bill_sequence_id IN
3105                             (
3106                               select bill_sequence_id from bom_bill_of_materials where
3107                               ASSEMBLY_ITEM_ID = item.revised_item_id AND
3108                               ORGANIZATION_ID = item.organization_id  AND
3109                               (
3110                                 (item.designator_selection_type = 1) --select everything
3111                                 OR  (item.designator_selection_type =2 AND ALTERNATE_BOM_DESIGNATOR IS NULL) --select only primary BOM
3112                                 OR (item.designator_selection_type = 3 AND ALTERNATE_BOM_DESIGNATOR = item.alternate_bom_designator) --select that particular  BOM
3113                               )
3114                             )
3115                   )
3116                )  and organization_id = item.organization_id and bom_enabled_flag = 'N'
3117               );
3118 
3119         END IF;
3120 
3121         -- throw error if   l_no_bom_dis_sub_comps is greater than 0..
3122         IF(l_no_bom_dis_sub_comps > 0 ) THEN
3123             msg_qty := msg_qty + 1;
3124             message_names(msg_qty) :=
3125                       'ENG_SUB_COMP_NOT_BOM_ENABLED';
3126             token1(msg_qty) := 'OPERATION_NAME';
3127             value1(msg_qty) := 'Implement';
3128             translate1(msg_qty) := 0;
3129             token2(msg_qty) :=  'RI_NAME';
3130             value2(msg_qty) :=  item.concatenated_segments;
3131             translate2(msg_qty) := 0;
3132             translate2(msg_qty) := 0;
3133             IF trial_mode = no THEN
3134                 Raise abort_implementation;
3135             END IF;
3136         END IF;
3137       END IF;
3138 END;
3139 END IF;
3140 
3141 
3142 IF (Nvl(item.transfer_or_copy,'N') <> 'T'  AND Nvl(item.transfer_or_copy,'N') <> 'C') THEN
3143   -- This is not transfer or copy...
3144 IF(item.bom_enabled_flag = 'N') THEN
3145   --check if there are any components for this tiem
3146   -- bug 5846248
3147    --If bom_enabled_flag is false.. there should be no components or sub components for this revised item...
3148 
3149   DECLARE
3150     l_no_components NUMBER;
3151     l_no_operations NUMBER;
3152   BEGIN
3153     --Note that in implementation we check only if there are any compoenents. Empty BOMs will be implemented
3154     --This is done because.. BOMs are created the first item we add a component in ECO.. but there is no way
3155     -- to delete that BOM, if the user wants to implement it by deleting the components and proceeding with other
3156     -- changes...
3157     SELECT Count(*) INTO l_no_components FROM dual WHERE EXISTS(
3158       select 1 from bom_components_b where bill_sequence_id in
3159       (
3160         select bill_sequence_id from bom_bill_of_materials where
3161         ASSEMBLY_ITEM_ID = item.revised_item_id AND
3162         ORGANIZATION_ID = item.organization_id
3163       ) AND revised_item_sequence_id = revised_item  AND acd_type <> acd_delete
3164     );
3165 
3166     IF(l_no_components <> 0) THEN
3167               msg_qty := msg_qty + 1;
3168               message_names(msg_qty) :=
3169                         'ENG_RI_NOT_BOM_ENABLED_COMP';
3170               token1(msg_qty) := 'OPERATION_NAME';
3171               value1(msg_qty) := 'Implement';
3172               translate1(msg_qty) := 0;
3173               token2(msg_qty) :=  'RI_NAME';
3174               value2(msg_qty) :=  item.concatenated_segments;
3175               translate2(msg_qty) := 0;
3176               IF trial_mode = no THEN
3177                   Raise abort_implementation;
3178               END IF;
3179             -- Need not code for substitute components in this flow because if there are components itself we are throwing an error
3180             -- so there is not way that there are substitute components, if we pass this condition
3181     END IF;
3182 
3183     --Check if there are any operations for this item ..
3184     --Again, we allow empty routings to get implemented for the same reason for which we allowe empty BOMs
3185     SELECT Count(*) INTO l_no_operations FROM dual WHERE EXISTS(
3186       select 1 FROM bom_operation_sequences WHERE routing_sequence_id IN
3187       (
3188         SELECT routing_sequence_id FROM BOM_OPERATIONAL_ROUTINGS WHERE
3189         ASSEMBLY_ITEM_ID = item.revised_item_id and
3190         ORGANIZATION_ID = item.organization_id
3191       ) AND revised_item_sequence_id = item.revised_item_sequence_id  AND acd_type <> acd_delete
3192     );
3193 
3194     IF(l_no_operations <> 0) THEN
3195               msg_qty := msg_qty + 1;
3196               message_names(msg_qty) :=
3197                         'ENG_RI_NOT_BOM_ENABLED_ROUT';
3198               token1(msg_qty) := 'OPERATION_NAME';
3199               value1(msg_qty) := 'Implement';
3200               translate1(msg_qty) := 0;
3201               token2(msg_qty) :=  'RI_NAME';
3202               value2(msg_qty) :=  item.concatenated_segments;
3203               translate2(msg_qty) := 0;
3204                 translate2(msg_qty) := 0;
3205                 IF trial_mode = no THEN
3206                     Raise abort_implementation;
3207                 END IF;
3208     end if;
3209   END;
3210 END IF;
3211 -- bug 5846248
3212 -- for any one of the components or substitue components have bom_enabled_flag as 'N' then throw an error,
3213 -- even if the bom_enabled_flag of this revised item is 'Y'
3214 
3215   DECLARE
3216 
3217       no_bom_disabled_comps NUMBER;
3218       no_bom_disabled_sub_comps NUMBER;
3219   BEGIN
3220    --Check if there is atleast one component such that it's bom_enabled_flag is false for this Revised Item
3221    SELECT Count(*) INTO no_bom_disabled_comps FROM dual WHERE EXISTS(
3222       select 1 from mtl_system_items_b where inventory_item_id in
3223       (
3224         select COMPONENT_ITEM_ID from bom_components_b WHERE bill_sequence_id IN
3225         (
3226           select bill_sequence_id from bom_bill_of_materials where
3227           ASSEMBLY_ITEM_ID = item.revised_item_id AND
3228           ORGANIZATION_ID = item.organization_id
3229         )
3230         AND  revised_item_sequence_id = revised_item   AND acd_type <> acd_delete
3231      ) and organization_id = item.organization_id and bom_enabled_flag = 'N'
3232     );
3233 
3234 
3235     IF( no_bom_disabled_comps <> 0) THEN
3236         msg_qty := msg_qty + 1;
3237               message_names(msg_qty) :=
3238                         'ENG_COMP_NOT_BOM_ENABLED';
3239               token1(msg_qty) := 'OPERATION_NAME';
3240               value1(msg_qty) := 'Implement';
3241               translate1(msg_qty) := 0;
3242               token2(msg_qty) :=  'RI_NAME';
3243               value2(msg_qty) :=  item.concatenated_segments;
3244               translate2(msg_qty) := 0;
3245                 translate2(msg_qty) := 0;
3246         IF trial_mode = no THEN
3247           Raise abort_implementation;
3248         END IF;
3249     END IF;
3250 
3251        --Check if there is atleast one sub component such that it's bom_enabled_flag is false for this Revised Item
3252     SELECT Count(*) INTO no_bom_disabled_sub_comps FROM dual WHERE EXISTS(
3253       select 1 from mtl_system_items_b WHERE  inventory_item_id IN
3254       (
3255         --Get all the sub components for all the components for this item
3256         select SUBSTITUTE_COMPONENT_ID from bom_substitute_components where COMPONENT_SEQUENCE_ID in(
3257           -- Get all the components for this item
3258           select COMPONENT_SEQUENCE_ID from bom_components_b WHERE bill_sequence_id IN
3259           (
3260             select bill_sequence_id from bom_bill_of_materials where
3261             ASSEMBLY_ITEM_ID = item.revised_item_id AND
3262             ORGANIZATION_ID = item.organization_id
3263           ) AND revised_item_sequence_id = revised_item  AND acd_type <> acd_delete
3264         ) AND acd_type <> acd_delete
3265       )  and organization_id = item.organization_id and bom_enabled_flag = 'N'
3266     );
3267 
3268     IF( no_bom_disabled_sub_comps <> 0) THEN
3269              msg_qty := msg_qty + 1;
3270               message_names(msg_qty) :=
3271                         'ENG_SUB_COMP_NOT_BOM_ENABLED';
3272               token1(msg_qty) := 'OPERATION_NAME';
3273               value1(msg_qty) := 'Implement';
3274               translate1(msg_qty) := 0;
3275               token2(msg_qty) :=  'RI_NAME';
3276               value2(msg_qty) :=  item.concatenated_segments;
3277               translate2(msg_qty) := 0;
3278                 translate2(msg_qty) := 0;
3279           IF trial_mode = no then
3280             Raise abort_implementation;
3281           END IF;
3282     END IF;
3283   END;
3284 END IF;
3285 
3286 --Code changes for bug 5846248 ends
3287 
3288 -- ERES change begins
3289 -- First Get the parent event details (ECO Implementation)
3290 -- If the call fails or returns and error, the exception is not catched.
3291 l_eres_enabled := FND_PROFILE.VALUE('EDR_ERES_ENABLED');
3292 IF ( NVL( l_eres_enabled, 'N') = 'Y')
3293 THEN
3294   QA_EDR_STANDARD.GET_ERECORD_ID
3295        ( p_api_version   => 1.0
3296        , p_init_msg_list => FND_API.G_TRUE
3297        , x_return_status => l_return_status
3298        , x_msg_count     => l_msg_count
3299        , x_msg_data      => l_msg_data
3300        , p_event_name    => 'oracle.apps.eng.ecoImplement'
3301        , p_event_key     => TO_CHAR(item.change_id)
3302        , x_erecord_id    => l_parent_record_id);
3303 
3304   -- When MassChangeBill, then an ECO Create is created.
3305   -- So, when procedure implement_revised_item is called,
3306   -- there is either an ECO implement event,
3307   -- or an ECO Create event created before.
3308   IF (l_parent_record_id IS NULL)
3309   THEN
3310     QA_EDR_STANDARD.GET_ERECORD_ID
3311        ( p_api_version   => 1.0
3312        , p_init_msg_list => FND_API.G_TRUE
3313        , x_return_status => l_return_status
3314        , x_msg_count     => l_msg_count
3315        , x_msg_data      => l_msg_data
3316        , p_event_name    => 'oracle.apps.eng.ecoCreate'
3317        , p_event_key     => TO_CHAR(item.change_id)
3318        , x_erecord_id    => l_parent_record_id);
3319   END IF;
3320 
3321   FND_FILE.PUT_LINE(FND_FILE.LOG, 'in Implement Revised Item. After Getting Parent Id, parent_erecord_id='||l_parent_record_id||', msg_cnt='||l_msg_count);
3322 ELSE
3323   -- set the value to N in case it is NULL.
3324   l_eres_enabled := 'N';
3325 END IF;
3326 FND_FILE.PUT_LINE(FND_FILE.LOG, 'Info: EDR_ERES_ENABLED='||l_eres_enabled);
3327 
3328 -- ERES change ends
3329 
3330 IF (Nvl(item.transfer_or_copy,'N') = 'T'  OR Nvl(item.transfer_or_copy,'N') = 'C') -- Check for Transfer/Copy OR Revised Item Change
3331 THEN
3332 
3333   l_item_revision         := item.new_item_revision;
3334   l_routing_revision      := item.new_routing_revision;
3335   l_new_assembly_item_id  := item.revised_item_id;
3336 
3337   FOR i IN 1..20
3338   LOOP
3339     copy_segments(i) := Null;
3340   END LOOP;
3341 
3342   IF item.transfer_or_copy = 'C' THEN
3343     /* Check for the non existence of mfg item before copy */
3344     FOR r1 IN mfgitem_already_exists(item.copy_to_item)
3345     LOOP
3346             IF msg_qty < max_messages then
3347                         msg_qty := msg_qty + 1;
3348                         message_names(msg_qty) :=
3349                                   'ENG_COPYTO_MFGITEM_EXISTS';
3350                         token1(msg_qty) :=  null;
3351                         value1(msg_qty) :=  null;
3352                         translate1(msg_qty) := 0;
3353                         token2(msg_qty) := null;
3354                         value2(msg_qty) := null;
3355                         translate2(msg_qty) := 0;
3356             END IF;
3357             IF trial_mode = no then
3358                         Raise abort_implementation;
3359             END IF;
3360     END LOOP;
3361 
3362     IF l_item_revision IS NULL
3363     THEN
3364       FOR r1 IN get_starting_revision(item.organization_id)
3365       LOOP
3366         l_item_revision := r1.starting_revision;
3367       END LOOP;
3368     END IF;
3369 
3370     IF l_routing_revision IS NULL
3371     THEN
3372       FOR r1 IN get_starting_revision(item.organization_id)
3373       LOOP
3374         l_routing_revision := r1.starting_revision;
3375       END LOOP;
3376     END IF;
3377 
3378     SELECT mtl_system_items_s.NEXTVAL INTO l_new_assembly_item_id FROM dual;
3379 
3380     SELECT concatenated_copy_segments INTO l_concatenated_copy_segments
3381        FROM eng_revised_items WHERE revised_item_sequence_id = item.revised_item_sequence_id;
3382 
3383     FOR i IN 1..20
3384     LOOP
3385       copy_segments(i) := substr(l_concatenated_copy_segments,
3386                                  to_number(instr(l_concatenated_copy_segments,fnd_global.local_chr(1),1,i))+1,
3387                                  ( to_number( instr(l_concatenated_copy_segments,fnd_global.local_chr(1),1,i+1) ) -
3388                                    to_number(instr(l_concatenated_copy_segments,fnd_global.local_chr(1),1,i)+1)) );
3389     END LOOP;
3390 
3391   END IF;
3392 
3393   -- ERES change begins
3394   -- Create child event Transfer or Copy ToManufacturing:
3395   IF (l_eres_enabled = 'Y')
3396   THEN
3397    FND_FILE.PUT_LINE(FND_FILE.LOG, 'Preparing ERES. parent_erecord_id='||l_parent_record_id);
3398 
3399    l_event.param_name_1  := 'DEFERRED';
3400    l_event.param_value_1 := 'Y';
3401 
3402    l_event.param_name_2  := 'POST_OPERATION_API';
3403    l_event.param_value_2 := 'NONE';
3404 
3405    l_event.param_name_3  := 'PSIG_USER_KEY_LABEL';
3406    -- see later ... l_event.param_value_3 := '... ';
3407 
3408    l_event.param_name_4  := 'PSIG_USER_KEY_VALUE';
3409    -- see later ... l_event.param_value_4 := '... ';
3410 
3411    l_event.param_name_5  := 'PSIG_TRANSACTION_AUDIT_ID';
3412    l_event.param_value_5 := -1;
3413 
3414    l_event.param_name_6  := '#WF_SOURCE_APPLICATION_TYPE';
3415    l_event.param_value_6 := 'DB';
3416 
3417    l_event.param_name_7  := '#WF_SIGN_REQUESTER';
3418    l_event.param_value_7 := FND_GLOBAL.USER_NAME;
3419 
3420    IF (item.transfer_or_copy = 'C')
3421    THEN
3422     l_child_event_name := 'oracle.apps.eng.copyToManufacturing';
3423     FND_MESSAGE.SET_NAME('ENG', 'ENG_ERES_CPY2MANUF_USER_KEY');
3424     l_event.param_value_3 := FND_MESSAGE.GET;
3425 
3426     l_event.param_value_4 := item.concatenated_segments||'-'||item.organization_code||'-'||item.copy_to_item;
3427 
3428     l_temp_id := TO_CHAR(item.revised_item_id)||'-'||TO_CHAR(item.organization_id)||'-'||TO_CHAR(l_new_assembly_item_id);
3429 
3430   ELSIF (item.transfer_or_copy = 'T')
3431   THEN
3432     l_child_event_name := 'oracle.apps.eng.transferToManufacturing';
3433     FND_MESSAGE.SET_NAME('ENG', 'ENG_ERES_XFER2MANUF_USER_KEY');
3434     l_event.param_value_3 := FND_MESSAGE.GET;
3435 
3436     -- bug 3741224 : odaboval changed the userkey order:
3437     -- l_event.param_value_4 := item.concatenated_segments||'-'||item.organization_code;
3438     l_event.param_value_4 := item.organization_code||'-'||item.concatenated_segments;
3439 
3440     l_temp_id := TO_CHAR(item.revised_item_id)||'-'||TO_CHAR(item.organization_id);
3441   ELSE
3442     l_child_event_name := NULL;
3443     l_event.param_value_3 := 'NOT_FOUND';
3444     l_event.param_value_4 := 'NOT_FOUND';
3445     l_temp_id := '-1';
3446   END IF;
3447 
3448   FND_FILE.PUT_LINE(FND_FILE.LOG, 'Creating event='||l_child_event_name);
3449   FND_FILE.PUT_LINE(FND_FILE.LOG, 'for event_key='||l_temp_id);
3450   FND_FILE.PUT_LINE(FND_FILE.LOG, 'for user_event_key='||l_event.param_value_4);
3451 
3452   IF (NVL(l_parent_record_id, -1) > 0)
3453   THEN
3454     --additional parameters for the child event
3455     l_event.param_name_8 := 'PARENT_EVENT_NAME';
3456     l_event.param_value_8 := 'oracle.apps.eng.ecoImplement';
3457     l_event.param_name_9 := 'PARENT_EVENT_KEY';
3458     l_event.param_value_9 := TO_CHAR(item.change_id);
3459     l_event.param_name_10 := 'PARENT_ERECORD_ID';
3460     l_event.param_value_10 := TO_CHAR(l_parent_record_id);
3461   END IF;
3462 
3463   -- Part 2 of preparation of child event :
3464   l_event.event_name   := l_child_event_name;
3465   l_event.event_key    := l_temp_id;
3466   -- l_event.payload      := l_payload;
3467   l_event.erecord_id   := l_erecord_id;
3468   l_event.event_status := l_event_status;
3469 
3470   -- populate the temporary table
3471   INSERT INTO eng_revised_items_temp
3472           ( temp_id
3473           , organization_id
3474           , organization_code
3475           , organization_name
3476           , inventory_item_id
3477           , item_number
3478           , item_description
3479           , transfer_or_copy_item
3480           , transfer_or_copy_bill
3481           , transfer_or_copy_routing
3482           , new_item_revision
3483           , new_routing_revision
3484           , designator_selection_type
3485           , alternate_bom_designator
3486           , change_notice
3487           , copy_to_item
3488           , copy_to_item_desc
3489           , transfer_or_copy
3490           , last_update_date
3491           , last_updated_by
3492           , creation_date
3493           , created_by)
3494    VALUES ( l_temp_id
3495           , item.organization_id
3496           , item.organization_code
3497           , item.organization_name
3498           , item.revised_item_id
3499           , item.concatenated_segments
3500           , item.description
3501           , item.transfer_or_copy_item
3502           , item.transfer_or_copy_bill
3503           , item.transfer_or_copy_routing
3504           , item.new_item_revision
3505           , item.new_routing_revision
3506           , item.designator_selection_type
3507           , item.alternate_bom_designator
3508           , item.change_notice
3509           , item.copy_to_item
3510           , item.copy_to_item_desc
3511           , item.transfer_or_copy
3512           , item.last_update_date
3513           , item.last_updated_by
3514           , item.creation_date
3515           , item.created_by);
3516 
3517     QA_EDR_STANDARD.RAISE_ERES_EVENT
3518            ( p_api_version      => 1.0
3519            , p_init_msg_list    => FND_API.G_FALSE
3520            , p_validation_level => FND_API.G_VALID_LEVEL_FULL
3521            , x_return_status    => l_return_status
3522            , x_msg_count        => l_msg_count
3523            , x_msg_data         => l_msg_data
3524            , p_child_erecords   => l_child_record
3525            , x_event            => l_event);
3526 
3527     IF (NVL(l_return_status, FND_API.G_FALSE) <> FND_API.G_TRUE)
3528       AND (l_msg_count > 0)
3529     THEN
3530        RAISE ERES_EVENT_ERROR;
3531     END IF;
3532 
3533     -- Keep the eRecord id :
3534     IF (NVL(l_event.erecord_id, -1) > 0)
3535     THEN
3536       INSERT INTO ENG_PARENT_CHILD_EVENTS_TEMP(parent_event_name
3537          , parent_event_key, parent_erecord_id
3538          , event_name, event_key, erecord_id
3539          , event_status)
3540       VALUES ( 'oracle.apps.eng.ecoImplement', TO_CHAR(item.change_id)
3541          , l_parent_record_id
3542          , l_event.event_name, l_event.event_key, l_event.erecord_id
3543          , l_event.event_status);
3544 
3545       FND_FILE.PUT_LINE(FND_FILE.LOG, 'After event='||l_child_event_name||', eRecord_id='||l_event.erecord_id||', status='||l_event.event_status||', ev_key='||l_event.event_key);
3546     ELSE
3547      FND_FILE.PUT_LINE(FND_FILE.LOG, 'No eRecord generated for '||l_event.event_name||'. This is normal. Please check your rules or other setups');
3548     END IF;
3549   END IF;   -- l_eres_enabled
3550   -- ERES change ends
3551 
3552 -- Added procedure for bug 3584193
3553 -- Description: The bill with unapproved items should not be allowed to be transferred through ECO.
3554 
3555 -- If the Transfer/Copy Bill option is selected, then check for the unapproved items. Log error message if unapproved items found.
3556  IF item.transfer_or_copy_bill = 1 AND UNAPPROVED_COMPONENTS_EXISTS (item.revised_item_id, item.organization_id, item.designator_selection_type, item.alternate_bom_designator) THEN
3557         IF msg_qty < max_messages THEN
3558                 msg_qty := msg_qty + 1;
3559                 token1(msg_qty) := null;
3560                 value1(msg_qty) := null;
3561                 translate1(msg_qty) := 0;
3562                 token2(msg_qty) := null;
3563                 value2(msg_qty) := null;
3564                 translate2(msg_qty) := 0;
3565                 message_names(msg_qty) := 'ENG_UNAPPROVED_COMP_IN_BILL';
3566                 IF trial_mode = no THEN
3567                         Raise abort_implementation;
3568                 END IF;
3569         END IF;
3570  ELSE
3571                 ENG_BOM_RTG_TRANSFER_PKG.ENG_BOM_RTG_TRANSFER(
3572                 X_org_id                          => item.organization_id,
3573                 X_eng_item_id                     => item.revised_item_id,
3574                 X_mfg_item_id                     => l_new_assembly_item_id,
3575                 X_transfer_option                 => item.selection_option,
3576                 X_designator_option               => item.designator_selection_type,
3577                 X_alt_bom_designator              => item.alternate_bom_designator,
3578                 X_alt_rtg_designator              => item.alternate_bom_designator,
3579                 X_effectivity_date                => item.selection_date,
3580                 X_last_login_id                   => loginid,
3581                 X_bom_rev_starting                => l_item_revision,
3582                 X_rtg_rev_starting                => l_routing_revision,
3583                 X_ecn_name                        => item.change_notice,
3584                 X_item_code                       => item.transfer_or_copy_item,
3585                 X_bom_code                        => item.transfer_or_copy_bill,
3586                 X_rtg_code                        => item.transfer_or_copy_routing,
3587                 X_mfg_description                 => item.copy_to_item_desc,
3588                 X_segment1                        => copy_segments(1),
3589                 X_segment2                        => copy_segments(2),
3590                 X_segment3                        => copy_segments(3),
3591                 X_segment4                        => copy_segments(4),
3592                 X_segment5                        => copy_segments(5),
3593                 X_segment6                        => copy_segments(6),
3594                 X_segment7                        => copy_segments(7),
3595                 X_segment8                        => copy_segments(8),
3596                 X_segment9                        => copy_segments(9),
3597                 X_segment10                       => copy_segments(10),
3598                 X_segment11                       => copy_segments(11),
3599                 X_segment12                       => copy_segments(12),
3600                 X_segment13                       => copy_segments(13),
3601                 X_segment14                       => copy_segments(14),
3602                 X_segment15                       => copy_segments(15),
3603                 X_segment16                       => copy_segments(16),
3604                 X_segment17                       => copy_segments(17),
3605                 X_segment18                       => copy_segments(18),
3606                 X_segment19                       => copy_segments(19),
3607                 X_segment20                       => copy_segments(20),
3608                 X_implemented_only                => item.implemented_only,
3609                 X_unit_number                   => item.selection_unit_number);
3610  END IF;
3611 
3612         IF (item.new_lifecycle_state_id IS NOT NULL AND item.new_lifecycle_state_id <> item.current_lifecycle_state_id )
3613         THEN
3614 
3615                 CHANGE_ITEM_LIFECYCLE_PHASE (
3616                           p_rev_item_seq_id             => revised_item
3617                         , p_organization_id             => item.organization_id
3618                         , p_inventory_item_id           => item.revised_item_id
3619                         , p_scheduled_date              => item.scheduled_date
3620                         , p_new_lifecycle_phase_id      => item.new_lifecycle_state_id
3621                         , x_return_status               => l_lc_return_status);
3622                 IF (l_lc_return_status <> 'S')
3623                 THEN
3624                         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Change Item phase for transfer line Failed');
3625                         RAISE abort_implementation;
3626                 END IF;
3627         END IF;
3628 
3629 
3630         IF ( p_is_lifecycle_phase_change = 2)
3631         THEN
3632 
3633   Update eng_revised_items
3634     set implementation_date = today,
3635         status_type = 6,
3636         last_update_date = sysdate,
3637         last_updated_by = userid,
3638         last_update_login = loginid,
3639         request_id = reqstid,
3640         program_application_id = appid,
3641         program_id = progid,
3642         program_update_date = sysdate,
3643         status_code = p_status_code
3644    where revised_item_sequence_id = item.revised_item_sequence_id;
3645 
3646         END IF;
3647 
3648 
3649  END IF;
3650 
3651  IF (item.transfer_or_copy = 'O')               -- if the item is obsoleted
3652  THEN
3653         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Processing obsolete Item .. ');
3654 
3655         l_max_scheduled_date := item.scheduled_date;
3656         l_implement_revised_item := 1;
3657         FOR li IN c_local_org_rev_items (item.change_id, item.revised_item_sequence_id)
3658         LOOP
3659                 IF (li.implementation_date IS NULL )
3660                 THEN
3661                         FND_FILE.PUT_LINE(FND_FILE.LOG, 'This item cannot be obsoleted since revised items propagated to the local organizations have not been implemented');
3662                         Raise abort_implementation;
3663                 END IF;
3664                 IF li.scheduled_date > l_max_scheduled_date THEN
3665                         l_max_scheduled_date := li.scheduled_date;
3666                 END IF;
3667 
3668         END LOOP;
3669         /* reschedule the revised item if l_max_scheduled_date > item.scheduled_date*/
3670         IF ( l_max_scheduled_date > item.scheduled_date)
3671         THEN
3672                 UPDATE eng_revised_items
3673                 SET    scheduled_date = l_max_scheduled_date
3674                 WHERE  revised_item_sequence_id = item.revised_item_sequence_id;
3675         END IF;
3676 
3677         IF (item.new_lifecycle_state_id IS NOT NULL AND item.new_lifecycle_state_id <> item.current_lifecycle_state_id )
3678         THEN
3679                 CHANGE_ITEM_LIFECYCLE_PHASE (
3680                           p_rev_item_seq_id             => revised_item
3681                         , p_organization_id             => item.organization_id
3682                         , p_inventory_item_id           => item.revised_item_id
3683                         , p_scheduled_date              => l_max_scheduled_date
3684                         , p_new_lifecycle_phase_id      => item.new_lifecycle_state_id
3685                         , x_return_status               => l_lc_return_status);
3686 
3687                 IF (l_lc_return_status <> 'S')
3688                 THEN
3689                         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Change Item phase for obsolete item line Failed');
3690                         RAISE abort_implementation;
3691                 END IF;
3692         END IF;
3693 
3694         l_Item_rec_in.INVENTORY_ITEM_ID :=  item.revised_item_id;
3695         l_Item_rec_in.ORGANIZATION_ID :=  item.Organization_Id;
3696         l_Item_rec_in.INVENTORY_ITEM_STATUS_CODE := 'Inactive';
3697 
3698         INV_Item_GRP.Update_Item (
3699                   p_Item_rec         =>  l_Item_rec_in
3700                 , p_Revision_rec     =>  l_revision_rec
3701                 , p_Template_Id      =>  NULL
3702                 , p_Template_Name    =>  NULL
3703                 , x_Item_rec         =>  l_Item_rec_out
3704                 , x_return_status    =>  l_inv_return_status
3705                 , x_Error_tbl        =>  l_Error_tbl );
3706 
3707         IF (l_inv_return_status <> 'S' )
3708         THEN
3709                 FND_FILE.PUT_LINE(FND_FILE.LOG, 'Change Item status to inactive Failed');
3710                 Raise abort_implementation;
3711         END IF;
3712 
3713         IF (p_is_lifecycle_phase_change = 2 )
3714         THEN
3715                 Update eng_revised_items
3716                 set implementation_date = today,
3717                    status_type = 6,
3718                    last_update_date = sysdate,
3719                    last_updated_by = userid,
3720                    last_update_login = loginid,
3721                    request_id = reqstid,
3722                    program_application_id = appid,
3723                    program_id = progid,
3724                    program_update_date = sysdate,
3725                    status_code = p_status_code
3726                 where revised_item_sequence_id = item.revised_item_sequence_id;
3727         END IF;
3728 
3729  ELSIF item.transfer_or_copy = 'L' THEN   --life cycle phase chnage
3730 
3731         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Processing phase change Item .. ');
3732         IF (item.new_lifecycle_state_id IS NOT NULL AND item.new_lifecycle_state_id <> item.current_lifecycle_state_id )
3733         THEN
3734                 CHANGE_ITEM_LIFECYCLE_PHASE (
3735                           p_rev_item_seq_id             => revised_item
3736                         , p_organization_id             => item.organization_id
3737                         , p_inventory_item_id           => item.revised_item_id
3738                         , p_scheduled_date              => item.scheduled_date
3739                         , p_new_lifecycle_phase_id      => item.new_lifecycle_state_id
3740                         , x_return_status               => l_lc_return_status);
3741                 IF (l_lc_return_status <> 'S')
3742                 THEN
3743                         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Change Item phase for phase change line Failed');
3744                         RAISE abort_implementation;
3745                 END IF;
3746         END IF;
3747 
3748         IF (p_is_lifecycle_phase_change = 2)
3749         THEN
3750 
3751                 Update eng_revised_items
3752                 set implementation_date = today,
3753                    status_type = 6,
3754                    last_update_date = sysdate,
3755                    last_updated_by = userid,
3756                    last_update_login = loginid,
3757                    request_id = reqstid,
3758                    program_application_id = appid,
3759                    program_id = progid,
3760                    program_update_date = sysdate,
3761                    status_code = p_status_code
3762                 where revised_item_sequence_id = item.revised_item_sequence_id;
3763 
3764         END IF;
3765 END IF;
3766 
3767 IF (p_is_lifecycle_phase_change = 1) THEN
3768 
3769 
3770   /* Implement Revised Item Change */
3771 
3772 
3773 -- Effectivity date should be sysdate, if scheduled_date < sysdate
3774 -- New eff_date included to fix bug #777353.
3775 
3776 if (item.scheduled_date < now)
3777 then
3778         eff_date := now;
3779         revision_high_date := now;
3780         rtg_revision_high_date := now;
3781 else
3782         eff_date := item.scheduled_date;
3783         revision_high_date := item.scheduled_date;
3784         rtg_revision_high_date := item.scheduled_date;
3785 end if;
3786 
3787 
3788 /*** Added by 11.5.10 ***/
3789 if (item.use_up_item_id is not null and item.disposition_type = 8) then
3790     --- 8 use_up =Exhaust WIP and Inventory
3791   if (inv_onhand(item.use_up_item_id, item.organization_id) <> 0) then
3792        	/* Fix for bug 5962435 - Added nvl around the profile,
3793 	otherwise eff_date becomes null when that profile value is left blank.*/
3794         eff_date := eff_date + nvl(FND_PROFILE.VALUE('ENG:ENG_RESCHEDULE_DAYS_BY'),0);
3795   end if;
3796 end if;
3797 /***   ***/
3798 
3799 Open get_current_rev;
3800 Fetch get_current_rev into current_revision;
3801 l_current_revision := current_revision.revision;
3802 l_current_rev_eff_date := current_revision.effectivity_date;
3803 Close get_current_rev;
3804 
3805 
3806 Open get_current_routing_rev;
3807 Fetch get_current_routing_rev into current_routing_revision;
3808 l_current_rtg_revision := current_routing_revision.process_revision;
3809 l_current_rtg_rev_eff_date := current_routing_revision.effectivity_date;
3810 Close get_current_routing_rev;
3811 
3812 
3813 bill_sequence_id    := nvl(item.bill_sequence_id,-1)   ;
3814 routing_sequence_id := nvl(item.routing_sequence_id,-1);
3815 update_wip          := item.update_wip;
3816 eco_for_production  := item.eco_for_production;
3817 l_wip_organization_id := item.organization_id;
3818 l_wip_completion_subinventory := item.completion_subinventory;  -- Bug 5896479
3819 l_wip_completion_locator_id   := item.completion_locator_id;    -- Bug 5896479
3820 
3821    -----------------------------------------------------------
3822    -- R12: Changes for Common BOM Enhancement
3823    -- Step 1: Initialization
3824    -----------------------------------------------------------
3825    g_Common_Rev_Comp_Tbl.delete;
3826    g_common_rev_comps_cnt := 0;
3827    isCommonedBOM := 'N';
3828    l_common_bom_eff_date := NULL;
3829    OPEN check_if_commoned_bom( item.bill_sequence_id);
3830    FETCH check_if_commoned_bom into commoned_bom;
3831    IF  check_if_commoned_bom%FOUND
3832    THEN
3833        isCommonedBOM := 'Y';
3834    END IF;
3835    CLOSE check_if_commoned_bom;
3836    IF isCommonedBOM = 'N' AND eff_date > sysdate
3837    THEN
3838        -- check if it is a common bom and fetch its effectivity date
3839        -- from the components records if the effectivity date is not now
3840        OPEN get_common_bom_eff_date( item.bill_sequence_id, item.revised_item_sequence_id);
3841        FETCH get_common_bom_eff_date into l_common_bom_eff_date;
3842        CLOSE get_common_bom_eff_date;
3843    END IF;
3844    -----------------------------------------------------------
3845    -- R12: End Step 1: Changes for Common BOM Enhancement --
3846    -----------------------------------------------------------
3847    -- Initialize For Business events
3848    l_BOMEvents_Comps_ACD := NULL;
3849    l_BOMEvents_Bill_Event_Name := NULL;
3850    -- End Initialize For Bom Business Events
3851 
3852 -- Is Unit Effective Revised Item?
3853 
3854    If (PJM_UNIT_EFF.Enabled = 'Y' AND
3855             PJM_UNIT_EFF.Unit_Effective_Item(
3856                     X_Item_ID => item.revised_item_id,
3857                     X_Organization_ID => item.organization_id) = 'Y')
3858    then
3859         X_UnitEff_RevItem := 'Y';
3860    end if;
3861 -- Is Order Entry Installed?
3862 
3863    X_GetInstallStatus := Fnd_Installation.get(
3864         appl_id => G_OrderEntry,
3865         dep_appl_id => G_OrderEntry,
3866         status => X_InstallStatus,
3867         industry => X_Industry);
3868 
3869    If not X_GetInstallStatus then
3870         X_InstallStatus := 'N';
3871    End if;
3872 
3873    -- Added validation for bug 4150069
3874    -- Check for revised items with unimplemented "From Revision".
3875    -- The value of "From revision" is saved in current_item_revision_id.
3876    -- In case of ECO Form the value of the current_item_revision_id will be:
3877    -- the current implemented revision of the item at the time of creation of the revised item.
3878    Open c_get_revision(item.current_item_revision_id);
3879    Fetch c_get_revision into l_revitem_from_rev, l_rev_impl_date;
3880    IF c_get_revision%FOUND AND l_rev_impl_date IS NULL
3881    THEN
3882        If msg_qty < max_messages
3883        Then
3884            msg_qty := msg_qty + 1;
3885            token1(msg_qty) := 'REVISION';
3886            value1(msg_qty) := l_revitem_from_rev;
3887            translate1(msg_qty) := 0;
3888            token2(msg_qty) := null;
3889            value2(msg_qty) := null;
3890            translate2(msg_qty) := 0;
3891            message_names(msg_qty) := 'ENG_REV_ITM_FROMREV_UNIMPL';
3892            IF trial_mode = no
3893            THEN
3894                Close c_get_revision;
3895                RAISE abort_implementation;
3896            END IF;
3897        End If;
3898    END IF;
3899    Close c_get_revision;
3900    -- End changes for bug 4150069
3901 
3902 -- Check for rev items which are not active. Fix for bug 835813.
3903    Open check_rev_item_inactive;
3904    Fetch check_rev_item_inactive into dummy;
3905    If check_rev_item_inactive%found then
3906         If msg_qty < max_messages then
3907                 msg_qty := msg_qty + 1;
3908                 token1(msg_qty) := null;
3909                 value1(msg_qty) := null;
3910                 translate1(msg_qty) := 0;
3911                 token2(msg_qty) := null;
3912                 value2(msg_qty) := null;
3913                 translate2(msg_qty) := 0;
3914                 message_names(msg_qty) := 'ENG_REV_ITEM_INACTIVE';
3915                 If trial_mode = no then
3916                         Raise abort_implementation;
3917                 end if;
3918         end if;
3919    end if;
3920    Close check_rev_item_inactive;
3921 
3922 If item.new_item_revision is not null then
3923 
3924 --
3925 -- Check if there exists an unimplemented ECO having the same
3926 -- item and a new revision less than the new revision of this ECO.
3927 -- if found, issue a warning only.
3928 --
3929 
3930     Open unimplemented_rev;
3931     Fetch unimplemented_rev into unimp_rec;
3932     If unimplemented_rev%found then
3933         If msg_qty < max_messages then
3934 
3935         begin
3936                 SELECT  substrb(profile_option_value,1,1)
3937                 INTO    eco_rev_warning_flag
3938                 FROM    fnd_profile_options opt,
3939                         fnd_application appl,
3940                         fnd_profile_option_values val
3941                 WHERE   opt.application_id = val.application_id
3942                 AND     opt.profile_option_id = val.profile_option_id
3943                 AND     opt.application_id = appl.application_id
3944                 AND     appl.application_short_name = 'ENG'
3945                 AND     opt.profile_option_name = 'ENG:ECO_REV_WARNING'
3946                 AND     val.level_id = 10001;
3947         exception
3948                 when OTHERS then
3949                         eco_rev_warning_flag := 'Y';
3950         end;
3951                 msg_qty := msg_qty + 1;
3952                 token1(msg_qty) := null;
3953                 value1(msg_qty) := null;
3954                 translate1(msg_qty) := 0;
3955                 token2(msg_qty) := null;
3956                 value2(msg_qty) := null;
3957                 translate2(msg_qty) := 0;
3958 
3959                 if eco_rev_warning_flag = 'Y' then
3960 
3961                         warnings := warnings + 1;
3962                         message_names(msg_qty) := 'ENG_REV_PENDING';
3963                 else
3964                         message_names(msg_qty) := 'ENG_REV_IMPL_ORDER';
3965                         If trial_mode = no then
3966                                 Raise abort_implementation;
3967                         end if;
3968                 end if;
3969 
3970 
3971         end if;
3972     end if;
3973     Close unimplemented_rev;
3974 
3975 --
3976 --   Check if there is a revision lower than new revision with higher eff date.
3977 --   bug #737239.
3978 
3979      Open check_high_date_low_rev;
3980      Fetch check_high_date_low_rev into dummy;
3981      If check_high_date_low_rev%found then
3982         If msg_qty < max_messages then
3983                 msg_qty := msg_qty + 1;
3984                 token1(msg_qty) := null;
3985                 value1(msg_qty) := null;
3986                 translate1(msg_qty) := 0;
3987                 token2(msg_qty) := null;
3988                 value2(msg_qty) := null;
3989                 translate2(msg_qty) := 0;
3990                 message_names(msg_qty) := 'ENG_REVISION_ORDER';
3991                 If trial_mode = no then
3992                         Raise abort_implementation;
3993                 end if;
3994         end if;
3995      end if;
3996      Close check_high_date_low_rev;
3997 
3998 --
3999 --   Check if current revision is higher than new revision.
4000 --
4001 
4002     If nlssort(l_current_revision) > nlssort(item.new_item_revision) then
4003                 If msg_qty < max_messages then
4004                         msg_qty := msg_qty + 1;
4005                         message_names(msg_qty) := 'ENG_CUR_REV_HIGHER';
4006                         token1(msg_qty) := 'ENTITY1';
4007                         value1(msg_qty) := item.new_item_revision;
4008                         translate1(msg_qty) := 0;
4009                         token2(msg_qty) := 'ENTITY2';
4010                         value2(msg_qty) := l_current_revision;
4011                         translate2(msg_qty) := 0;
4012                 end if;
4013                 If trial_mode = no then
4014                         Raise abort_implementation;
4015                 end if;
4016     elsif nlssort(l_current_revision) < nlssort(item.new_item_revision) then
4017 
4018 --
4019 --   Implement the new revision.
4020 --
4021         Update mtl_item_revisions_b   --changed mtl_item_revisions to mtl_item_revisions_b
4022         set implementation_date = today,
4023                 effectivity_date = eff_date,
4024                 last_update_date = sysdate,
4025                 last_updated_by = userid,
4026                 last_update_login = loginid,
4027                 request_id = reqstid,
4028                 program_application_id = appid,
4029                 program_id = progid,
4030                 program_update_date = sysdate
4031         where inventory_item_id = item.revised_item_id
4032         and   organization_id   = item.organization_id
4033         and   revision          = item.new_item_revision;
4034 
4035         -- R12: Business Event Enhancement:
4036         -- Raise Event if Revision got Updated successfully
4037         BEGIN
4038             INV_ITEM_EVENTS_PVT.Raise_Events(
4039              p_event_name        => 'EGO_WF_WRAPPER_PVT.G_REV_CHANGE_EVENT'
4040             ,p_dml_type          => 'UPDATE'
4041             ,p_inventory_item_id => item.revised_item_id
4042             ,p_organization_id   => item.organization_id
4043             ,p_revision_id       => item.new_item_revision_id );
4044         EXCEPTION
4045             WHEN OTHERS THEN
4046                 NULL;
4047         END;
4048         -- R12: Business Event Enhancement:
4049         -- Raise Event if Revision got Updated successfully
4050 
4051 
4052 --
4053 --   Implement the new revision in common bills also.
4054 --   Fixed bug #747439.
4055 --
4056         OPEN get_common_bills;
4057         LOOP
4058                 FETCH get_common_bills into common;
4059                 EXIT WHEN get_common_bills%NOTFOUND;
4060 
4061                 OPEN get_common_current_rev(
4062                         common_assembly_item_id=>common.assembly_item_id,
4063                         common_org_id          =>common.organization_id);
4064                 FETCH get_common_current_rev into common_current_rev;
4065                 CLOSE get_common_current_rev;
4066 
4067                 --* Added for Bug 4366583
4068                 OPEN revision_exists(
4069                              common_assembly_item_id=>common.assembly_item_id,
4070                              common_org_id          =>common.organization_id,
4071                      common_revision        =>item.new_item_revision);
4072                      FETCH revision_exists into l_revision_exists;
4073                 CLOSE revision_exists;
4074                 --* End of Bug 4366583
4075 
4076                 if (( nlssort(common_current_rev) < nlssort(item.new_item_revision))
4077                     and  ( l_revision_exists = 0)) --* AND condition added for Bug 4366583
4078                 then
4079                         ENG_COPY_TABLE_ROWS_PKG.C_MTL_ITEM_REVISIONS(
4080                                 X_inventory_item_id => common.assembly_item_id,
4081                                 X_organization_id => common.organization_id,
4082                                 X_revision => item.new_item_revision,
4083                                 X_last_update_date => SYSDATE,
4084                                 X_last_updated_by => userid,
4085                                 X_creation_date => SYSDATE,
4086                                 X_created_by => userid,
4087                                 X_last_update_login => loginid,
4088                                 X_effectivity_date => eff_date,
4089                                 X_change_notice => item.change_notice,
4090                                 X_implementation_date => today);
4091                --Start of changes Bug 2963301
4092                 Begin
4093                   SELECT userenv('LANG') INTO l_language_code FROM dual;
4094                       Update mtl_item_revisions_tl MIR
4095                        set description =
4096                           (select MIR1.description
4097                             from   mtl_item_revisions_tl MIR1
4098                             where revision_id IN (SELECT revision_id
4099                                                   FROM   MTL_ITEM_REVISIONS_B
4100                                                   WHERE
4101                                                           inventory_item_id  = item.revised_item_id
4102                                                 and       organization_id = item.organization_id
4103                                                 and       revision = item.new_item_revision)
4104                             and language    =   l_language_code
4105                           )
4106                        where inventory_item_id = common.assembly_item_id
4107                        and   organization_id = common.organization_id
4108                        and   revision_id  in  (SELECT revision_id
4109                                                   FROM   MTL_ITEM_REVISIONS_B
4110                                                   WHERE
4111                                                           inventory_item_id  = common.assembly_item_id
4112                                                 and       organization_id =    common.organization_id
4113                                                 and       revision = item.new_item_revision);
4114 
4115                 Exception
4116                         When Others then
4117                                 NULL;
4118                 End;
4119                 --End of changes Bug 2963301
4120                 end if;
4121         END LOOP;
4122         CLOSE get_common_bills ;   -- Closed this Cursor for Bug #3102887
4123 --   end fix #747439.
4124 
4125     end if;
4126 
4127 end if; -- end of "if new_item_revision is not null"
4128 
4129    --- as there is no updation of description ,updation to mtl_item_revisions_tl is not required
4130    -- Moved this code here so that  if new revision gets implemented rev effective structure will get implement successfully 	5243333
4131    -- Added For 11510+ Enhancement
4132    -- Fetch the effectivity control of the bill
4133    Open get_bill_effectivity_control(bill_sequence_id);
4134    Fetch get_bill_effectivity_control into l_effectivity_control;
4135    Close get_bill_effectivity_control;
4136    -- Is the effectivity control End-item-revision Effectivity
4137    l_revision_eff_bill := 'N';
4138    If (l_effectivity_control = 4)
4139    Then
4140        l_revision_eff_bill := 'Y';
4141        Open check_impl_revision(item.from_end_item_rev_id, item.from_end_item_id, item.organization_id);
4142        Fetch check_impl_revision into l_from_rev_eff_date, l_from_revision;
4143        Close check_impl_revision;
4144        l_from_end_item_id := item.from_end_item_id;
4145        l_current_end_item_revision :=
4146           BOM_REVISIONS.GET_ITEM_REVISION_FN('ALL', 'IMPL_ONLY', item.organization_id, item.from_end_item_id, now);
4147    End If;
4148    -- End 11510+ Enhancement
4149 
4150 	-- Added to support structure revision
4151 	If item.new_structure_revision is not null then
4152 		-- Call BOM API to create new BOM revision
4153 		X_new_structure_revision_id := null;
4154 		X_prev_structure_revision_id := null;
4155 	End if;
4156 
4157 
4158 
4159 --
4160 --  Implement Item Pending Changes
4161 --  In R12
4162 --  ENG_IMPL_ITEM_CHANGES_PKG.impl_item_changes API
4163 --  implement all Item Pending Changes
4164 BEGIN
4165 
4166 --    SAVEPOINT ITEM_CHG ;
4167 
4168     FND_FILE.NEW_LINE(FND_FILE.LOG);
4169     FND_FILE.PUT_LINE(FND_FILE.LOG,'Implement Item Pending Changes ');
4170     FND_FILE.PUT_LINE(FND_FILE.LOG,'==================================================');
4171     FND_FILE.PUT_LINE(FND_FILE.LOG,'Before: ENG_IMPL_ITEM_CHANGES_PKG.impl_item_changes ');
4172 
4173     l_return_status := FND_API.G_RET_STS_SUCCESS;
4174     plsql_block := 'BEGIN
4175                       FND_MSG_PUB.initialize ;
4176                       ENG_IMPL_ITEM_CHANGES_PKG.impl_item_changes
4177                       ( p_api_version    => 1.0
4178                       , p_change_id      => :a
4179                       , p_change_line_id => :b
4180                       , x_return_status  => :c
4181                       , x_msg_count      => :d
4182                       , x_msg_data       => :e );
4183                     END ; ' ;
4184 
4185     EXECUTE IMMEDIATE plsql_block USING
4186                     '',                   -- p_change_id
4187                     revised_item,         -- p_change_line_id
4188                     OUT l_return_status,  -- x_return_status
4189                     OUT l_msg_count,      -- x_msg_count
4190                     OUT l_msg_data;       -- x_msg_data
4191 
4192     FND_FILE.PUT_LINE(FND_FILE.LOG,'After: ENG_IMPL_ITEM_CHANGES_PKG.impl_item_changes: Return Status=' || l_return_status);
4193 
4194     IF l_return_status <> FND_API.G_RET_STS_SUCCESS
4195     THEN
4196         FND_MESSAGE.Set_Name('ENG','ENG_ERROR_CALLING_PS_API');
4197         FND_MESSAGE.Set_Token('OBJECT_NAME'
4198                               ,'ENG_IMPL_ITEM_CHANGES_PKG.impl_item_changes') ;
4199         FND_MSG_PUB.Add;
4200 
4201         RAISE FND_API.G_EXC_ERROR;
4202     END IF;
4203 
4204     FND_FILE.PUT_LINE(FND_FILE.LOG,'==================================================');
4205 
4206 EXCEPTION
4207     WHEN PLSQL_COMPILE_ERROR THEN
4208         null;
4209 
4210     WHEN FND_API.G_EXC_ERROR THEN
4211 
4212 FND_FILE.PUT_LINE(FND_FILE.LOG,'ENG_IMPL_ITEM_CHANGES_PKG.impl_item_changes failed ');
4213 FND_FILE.PUT_LINE(FND_FILE.LOG,'--------------------------------------------------');
4214 --        ROLLBACK TO SAVEPOINT ITEM_CHG ;
4215 
4216         FOR I IN 1..FND_MSG_PUB.Count_Msg LOOP
4217 
4218 FND_FILE.PUT_LINE(FND_FILE.LOG,'Message Number : '|| I );
4219 FND_FILE.PUT_LINE(FND_FILE.LOG,'DATA = '||replace(substr(FND_MSG_PUB.Get(I), 1, 200), chr(0), ' '));
4220 
4221             IF msg_qty < max_messages
4222             then
4223                 msg_qty := msg_qty + 1;
4224                 message_names(msg_qty) := 'ENG_IMPL_ITEM_CHANGE_FAIL' ;
4225                 token1(msg_qty) :=  'MSG_TEXT';
4226                 value1(msg_qty) := replace(substr(FND_MSG_PUB.Get(I), 1, 80), chr(0), ' ');
4227                 translate1(msg_qty) := 0;
4228                 token2(msg_qty) := null;
4229                 value2(msg_qty) := null;
4230                 translate2(msg_qty) := 0;
4231             END IF;
4232 
4233 
4234         END LOOP;
4235 
4236 
4237 FND_FILE.PUT_LINE(FND_FILE.LOG,'==================================================');
4238 
4239         IF trial_mode = no then
4240              Raise abort_implementation;
4241         END IF;
4242 
4243 
4244 
4245     WHEN OTHERS THEN
4246         FND_FILE.PUT_LINE(FND_FILE.LOG,'Other Unexpected Error: '|| substr(SQLERRM,1,200));
4247 
4248 FND_FILE.PUT_LINE(FND_FILE.LOG,'--------------------------------------------------');
4249 FND_FILE.PUT_LINE(FND_FILE.LOG,'ROLL BACK TO ITEM_CHG');
4250 --        ROLLBACK TO SAVEPOINT ITEM_CHG ;
4251 
4252 
4253         IF msg_qty < max_messages
4254         then
4255             msg_qty := msg_qty + 1;
4256             message_names(msg_qty) := 'ENG_IMPL_ITEM_CHANGE_FAIL' ;
4257             token1(msg_qty) :=  'MSG_TEXT';
4258             value1(msg_qty) := substr(SQLERRM, 1, 80);
4259             translate1(msg_qty) := 0;
4260             token2(msg_qty) := null;
4261             value2(msg_qty) := null;
4262             translate2(msg_qty) := 0;
4263         END IF;
4264 
4265 FND_FILE.PUT_LINE(FND_FILE.LOG,'--------------------------------------------------');
4266 
4267 
4268 FND_FILE.PUT_LINE(FND_FILE.LOG,'==================================================');
4269 
4270         IF trial_mode = no then
4271              Raise abort_implementation;
4272         END IF;
4273 
4274 END;
4275 
4276 -----------------------------------------------------------------
4277 -- For ECO cumulative/ECO wip job/ECO lot   ---------8/2/2000----
4278  IF  item.eco_for_production =1
4279  THEN
4280    IF item.from_wip_entity_id IS NULL
4281    AND item.to_wip_entity_id IS  NULL
4282    AND item.from_cum_qty IS NULL
4283    AND item.lot_number IS  NULL
4284    THEN
4285             IF msg_qty < max_messages then
4286                         msg_qty := msg_qty + 1;
4287                         message_names(msg_qty) :=
4288                                   'ENG_IMP_ECO_JOB_ONLY_CHECKED';
4289                         token1(msg_qty) :=  null;
4290                         value1(msg_qty) :=  null;
4291                         translate1(msg_qty) := 0;
4292                         token2(msg_qty) := null;
4293                         value2(msg_qty) := null;
4294                         translate2(msg_qty) := 0;
4295             END IF;
4296             IF trial_mode = no then
4297                         Raise abort_implementation;
4298             END IF;
4299    END IF;
4300 
4301    IF item.new_item_revision IS NOT NULL
4302    OR item.new_routing_revision IS NOT  NULL
4303    THEN
4304             IF msg_qty < max_messages then
4305                         msg_qty := msg_qty + 1;
4306                         message_names(msg_qty) :=
4307                                   'ENG_IMP_INVALID_REVISION';
4308                         token1(msg_qty) :=  null;
4309                         value1(msg_qty) :=  null;
4310                         translate1(msg_qty) := 0;
4311                         token2(msg_qty) := null;
4312                         value2(msg_qty) := null;
4313                         translate2(msg_qty) := 0;
4314             END IF;
4315             IF trial_mode = no then
4316                         Raise abort_implementation;
4317             END IF;
4318    END IF;
4319 
4320    IF  NOT (  item.from_wip_entity_id IS NOT NULL
4321                   and item.to_wip_entity_id IS NOT NULL
4322                   and item.from_cum_qty IS NULL
4323                   and item.lot_number is NULL
4324                OR item.from_wip_entity_id IS NOT NULL
4325                   and item.to_wip_entity_id IS NULL
4326                   and item.from_cum_qty IS NOT NULL
4327                   and item.lot_number is NULL
4328                OR item.from_wip_entity_id IS  NULL
4329                   and item.to_wip_entity_id IS NULL
4330                   and item.from_cum_qty IS  NULL
4331                   and item.lot_number IS NOT NULL
4332                 )
4333    THEN
4334             IF msg_qty < max_messages then
4335                         msg_qty := msg_qty + 1;
4336                         message_names(msg_qty) :=
4337                                   'ENG_IMP_INVALID_JOB_SPEC';
4338                         token1(msg_qty) :=  null;
4339                         value1(msg_qty) :=  null;
4340                         translate1(msg_qty) := 0;
4341                         token2(msg_qty) := null;
4342                         value2(msg_qty) := null;
4343                         translate2(msg_qty) := 0;
4344             END IF;
4345             IF trial_mode = no then
4346                         Raise abort_implementation;
4347             END IF;
4348 
4349    END IF;
4350   END IF;
4351 
4352   IF  item.eco_for_production =2
4353   AND ( item.from_wip_entity_id IS NOT NULL
4354        or item.to_wip_entity_id IS NOT NULL
4355        or item.from_cum_qty IS NOT NULL
4356        or item.lot_number is NOT NULL )
4357   THEN
4358             IF msg_qty < max_messages then
4359                         msg_qty := msg_qty + 1;
4360                         message_names(msg_qty) :=
4361                                   'ENG_IMP_ECO_JOB_ONLY_UNCHECKED';
4362                         token1(msg_qty) :=  null;
4363                         value1(msg_qty) :=  null;
4364                         translate1(msg_qty) := 0;
4365                         token2(msg_qty) := null;
4366                         value2(msg_qty) := null;
4367                         translate2(msg_qty) := 0;
4368             END IF;
4369             IF trial_mode = no then
4370                         Raise abort_implementation;
4371             END IF;
4372 
4373   END IF;
4374 
4375 
4376  IF item.update_wip = 1 and item.mrp_active = 2
4377  THEN
4378      -- For ECO cumulative type
4379      IF  NVL(item.from_cum_qty, 0) > 0
4380      THEN
4381         OPEN check_job_valid_for_cum
4382          ( p_from_wip_entity_id => item.from_wip_entity_id);
4383         FETCH check_job_valid_for_cum INTO cum_job_rec;
4384         IF check_job_valid_for_cum %NOTFOUND
4385         THEN
4386             IF msg_qty < max_messages then
4387                         msg_qty := msg_qty + 1;
4388                         message_names(msg_qty) :=
4389                                   'ENG_NO_VALID_WO_FOR_ECO_CUM';
4390                         token1(msg_qty) :=  null;
4391                         value1(msg_qty) :=  null;
4392                         translate1(msg_qty) := 0;
4393                         token2(msg_qty) := null;
4394                         value2(msg_qty) := null;
4395                         translate2(msg_qty) := 0;
4396             END IF;
4397             IF trial_mode = no then
4398                         Raise abort_implementation;
4399             END IF;
4400         ELSIF  (item.from_cum_qty >  cum_job_rec.start_quantity  )
4401            THEN  IF msg_qty < max_messages then
4402                         msg_qty := msg_qty + 1;
4403                         message_names(msg_qty) :=
4404                                   'ENG_INVALID_START_QTY_ECO_CUM';
4405                         token1(msg_qty) :=  null;
4406                         value1(msg_qty) :=  null;
4407                         translate1(msg_qty) := 0;
4408                         token2(msg_qty) := null;
4409                         value2(msg_qty) := null;
4410                         translate2(msg_qty) := 0;
4411                 END IF;
4412                 IF trial_mode = no then
4413                         Raise abort_implementation;
4414                 END IF;
4415         ELSIF  eff_date >  cum_job_rec.scheduled_start_date
4416              THEN  IF msg_qty < max_messages then
4417                         msg_qty := msg_qty + 1;
4418                         message_names(msg_qty) :=
4419                                   'ENG_INVALID_EFF_DATE_ECO_CUM';
4420                         token1(msg_qty) :=  null;
4421                         value1(msg_qty) :=  null;
4422                         translate1(msg_qty) := 0;
4423                         token2(msg_qty) := null;
4424                         value2(msg_qty) := null;
4425                         translate2(msg_qty) := 0;
4426                 END IF;
4427                 IF trial_mode = no then
4428                         Raise abort_implementation;
4429                 END IF;
4430 
4431       END IF;   --  end of check_job_valid_for_cum %NOTFOUND
4432 
4433 
4434       -- set the following variables used in insert WIP schedule interface.
4435      l_wip_start_quantity1       := item.from_cum_qty - 1;
4436      l_wip_start_quantity2       := cum_job_rec.start_quantity-item.from_cum_qty + 1;
4437      IF  cum_job_rec.start_quantity = cum_job_rec.net_quantity
4438      THEN
4439        l_wip_net_quantity1         :=  l_wip_start_quantity1;
4440        l_wip_net_quantity2         :=  l_wip_start_quantity2;
4441      ELSE
4442        l_wip_net_quantity1         :=
4443           round(cum_job_rec.net_quantity*l_wip_start_quantity1/cum_job_rec.start_quantity+0.5);
4444        l_wip_net_quantity2         :=
4445           round(cum_job_rec.net_quantity*l_wip_start_quantity2/cum_job_rec.start_quantity+0.5);
4446      END IF;
4447      l_wip_job_name              := cum_job_rec.wip_entity_name;
4448      l_wip_bom_revision1         := cum_job_rec.bom_revision;
4449      l_wip_routing_revision1     := cum_job_rec.routing_revision;
4450 
4451 /*     select effectivity_date into l_wip_bom_revision_date1
4452      from mtl_item_revisions
4453      where inventory_item_id = item.revised_item_id
4454      and revision = l_wip_bom_revision1
4455      and organization_id = item.organization_id;
4456 
4457      select effectivity_date into l_wip_routing_revision_date1
4458      from mtl_rtg_item_revisions
4459      where inventory_item_id = item.revised_item_id
4460      and process_revision = l_wip_routing_revision1
4461      and organization_id = item.organization_id;
4462 */
4463 
4464 
4465 --     l_wip_bom_revision_date1    := cum_job_rec.bom_revision_date;
4466 --     l_wip_routing_revision_date1:= cum_job_rec.routing_revision_date;
4467      l_wip_last_u_compl_date2    :=  cum_job_rec.scheduled_completion_date;
4468 
4469       Generate_New_Wip_Name(
4470        p_wip_entity_name => l_wip_job_name
4471       ,p_organization_id => item.organization_id
4472       ,x_wip_entity_name1   => l_wip_job_name1
4473       ,x_wip_entity_name2   => l_wip_job_name2
4474       ,x_return_status   => l_return_status
4475      );
4476 
4477      -- set the values for out type parameters
4478      wip_job_name1 := l_wip_job_name1;
4479      wip_job_name2 :=  l_wip_job_name2;
4480      wip_job_name2_org_id := item.organization_id;
4481 
4482 
4483      IF l_return_status <>0
4484      THEN IF msg_qty < max_messages then
4485                         msg_qty := msg_qty + 1;
4486                         message_names(msg_qty) :=
4487                                   'ENG_NEW_WIP_JOB_NAMES_ERROR';
4488                         token1(msg_qty) :=  'WIP_JOB_NAME';
4489                         value1(msg_qty) :=  l_wip_job_name;
4490                         translate1(msg_qty) := 0;
4491                         token2(msg_qty) := null;
4492                         value2(msg_qty) := null;
4493                         translate2(msg_qty) := 0;
4494           END IF;
4495           IF trial_mode = no then
4496                 Raise abort_implementation;
4497           END IF;
4498       END IF;   --  end of l_return_status <>0
4499 
4500       CLOSE check_job_valid_for_cum;
4501   ELSIF NVL(item.from_cum_qty,0) < 0
4502      THEN
4503                IF msg_qty < max_messages then
4504                         msg_qty := msg_qty + 1;
4505                         message_names(msg_qty) :=
4506                                   'ENG_INVALID_START_QTY_ECO_CUM';
4507                         token1(msg_qty) :=  null;
4508                         value1(msg_qty) :=  null;
4509                         translate1(msg_qty) := 0;
4510                         token2(msg_qty) := null;
4511                         value2(msg_qty) := null;
4512                         translate2(msg_qty) := 0;
4513                 END IF;
4514                 IF trial_mode = no then
4515                         Raise abort_implementation;
4516                 END IF;
4517   END IF;       --  end of NVL(item.start_quantity,0) > 0
4518 
4519  -- For ECO job type
4520  IF nvl(item.to_wip_entity_id, 0) <> 0
4521  THEN
4522 
4523    /*  IF nvl(item.from_wip_entity_id, 0 ) > nvl(item.to_wip_entity_id, 0 )
4524      THEN
4525         IF msg_qty < max_messages then
4526                         msg_qty := msg_qty + 1;
4527                         message_names(msg_qty) :=
4528                                   'ENG_INVALID_EFF_WIP_JOB_IN_ECO_JOB';
4529                         token1(msg_qty) :=  null;
4530                         value1(msg_qty) :=  null;
4531                         translate1(msg_qty) := 0;
4532                         token2(msg_qty) := null;
4533                         value2(msg_qty) := null;
4534                         translate2(msg_qty) := 0;
4535          END IF;
4536          IF trial_mode = no then
4537           Raise abort_implementation;
4538          END IF;
4539        END IF;            -- IF nvl(item.to_wip_entity_id, 0 )
4540    */
4541 
4542 
4543      OPEN check_job_valid_for_job
4544       ( p_from_wip_entity_id => item.from_wip_entity_id,
4545        p_to_wip_entity_id   => item.to_wip_entity_id,
4546        p_effective_date     => eff_date,
4547        p_organization_id    => item.organization_id
4548       );
4549      FETCH check_job_valid_for_job  INTO dummy;
4550      IF check_job_valid_for_job%FOUND
4551      THEN
4552 
4553          IF msg_qty < max_messages then
4554                         msg_qty := msg_qty + 1;
4555                         message_names(msg_qty) :=
4556                                   'ENG_INVALID_WO_ECO_JOB';
4557                         token1(msg_qty) :=  null;
4558                         value1(msg_qty) :=  null;
4559                         translate1(msg_qty) := 0;
4560                         token2(msg_qty) := null;
4561                         value2(msg_qty) := null;
4562                         translate2(msg_qty) := 0;
4563          END IF;
4564          IF trial_mode = no then
4565                         Raise abort_implementation;
4566          END IF;
4567      END IF;          --  check_job_valid_for_job
4568 
4569      l_from_wip_entity_id := item.from_wip_entity_id;
4570      l_to_wip_entity_id   := item.to_wip_entity_id;
4571 
4572      CLOSE check_job_valid_for_job;
4573 
4574    END IF;            -- IF nvl(item.to_wip_entity_id, 0) <> 0
4575 
4576   -- For ECO lot type
4577 IF item.lot_number IS NOT NULL
4578 THEN
4579     OPEN check_job_valid_for_lot
4580      ( p_wip_lot_number => item.lot_number,
4581        p_effective_date => eff_date);
4582     FETCH check_job_valid_for_lot  INTO dummy;
4583     IF check_job_valid_for_lot%FOUND
4584     THEN  IF msg_qty < max_messages then
4585                         msg_qty := msg_qty + 1;
4586                         message_names(msg_qty) :=
4587                                   'ENG_INVALID_WO_EXITS_ECO_LOT';
4588                         token1(msg_qty) :=  null;
4589                         value1(msg_qty) :=  null;
4590                         translate1(msg_qty) := 0;
4591                         token2(msg_qty) := null;
4592                         value2(msg_qty) := null;
4593                         translate2(msg_qty) := 0;
4594          END IF;
4595          IF trial_mode = no then
4596            Raise abort_implementation;
4597          END IF;
4598      END IF;            --  check_job_valid_for_lot
4599      l_lot_number := item.lot_number;
4600 
4601      CLOSE check_job_valid_for_lot;
4602   END IF;                  --  IF item.lot_number IS NOT NULL
4603  END IF;
4604                   -- update_wip = 1
4605 
4606 
4607 
4608 -- Validate the new routing revision
4609 -- If new routing revision is not null, check the followings.
4610 
4611    IF item.new_routing_revision IS NOT NULL
4612    THEN
4613      -- Check if there exists an unimplemented  ECO having the same revised
4614      -- item and a  routing revision less than the new revision of this
4615      --   routing. If found, issue a warning only
4616 
4617       OPEN unimplemented_rtg_rev;
4618       FETCH unimplemented_rtg_rev INTO unimp_ref_rec;
4619       IF unimplemented_rtg_rev%FOUND
4620       THEN
4621         If msg_qty < max_messages then
4622 
4623         begin
4624                 SELECT  substrb(profile_option_value,1,1)
4625                 INTO    eco_rev_warning_flag
4626                 FROM    fnd_profile_options opt,
4627                         fnd_application appl,
4628                         fnd_profile_option_values val
4629                 WHERE   opt.application_id = val.application_id
4630                 AND     opt.profile_option_id = val.profile_option_id
4631                 AND     opt.application_id = appl.application_id
4632                 AND     appl.application_short_name = 'ENG'
4633                 AND     opt.profile_option_name = 'ENG:ECO_REV_WARNING'
4634                 AND     val.level_id = 10001;
4635         exception
4636                 when OTHERS then
4637                         eco_rev_warning_flag := 'Y';
4638         end;
4639                 msg_qty := msg_qty + 1;
4640                 token1(msg_qty) := null;
4641                 value1(msg_qty) := null;
4642                 translate1(msg_qty) := 0;
4643                 token2(msg_qty) := null;
4644                 value2(msg_qty) := null;
4645                 translate2(msg_qty) := 0;
4646 
4647                 if eco_rev_warning_flag = 'Y' then
4648 
4649                         warnings := warnings + 1;
4650                         message_names(msg_qty) := 'ENG_RTG_REV_PENDING';
4651                 else
4652                         message_names(msg_qty) := 'ENG_RTG_REV_IMPL_ORDER';
4653                         If trial_mode = no then
4654                                 Raise abort_implementation;
4655                         end if;
4656                 end if;
4657        END IF;       -- end of check_existing_diff_rev
4658      END IF;         -- end of check_existing_diff_rev %FOUND
4659 
4660      CLOSE unimplemented_rtg_rev;
4661 
4662      -- Check if there is a routing revision lower than new routing revision
4663      -- with  higher effective date.
4664      --   OPEN check_high_eff_date_low_rtg_rev;
4665      OPEN check_highEffDate_lowRtgRev;
4666      FETCH check_highEffDate_lowRtgRev INTO dummy;
4667      IF check_highEffDate_lowRtgRev%FOUND
4668      THEN
4669        If msg_qty < max_messages then
4670                 msg_qty := msg_qty + 1;
4671                 token1(msg_qty) := null;
4672                 value1(msg_qty) := null;
4673                 translate1(msg_qty) := 0;
4674                 token2(msg_qty) := null;
4675                 value2(msg_qty) := null;
4676                 translate2(msg_qty) := 0;
4677                 message_names(msg_qty) := 'ENG_RTG_REVISION_ORDER';
4678                 If trial_mode = no then
4679                         Raise abort_implementation;
4680                 end if;
4681         end if;
4682 
4683 
4684      END IF;
4685      CLOSE check_highEffDate_lowRtgRev;
4686 
4687 
4688      -- Check if the current revision is higher than new revision
4689   /*   OPEN get_current_routing_rev;
4690      FETCH get_current_routing_rev into current_routing_revision  ;
4691      CLOSE get_current_routing_rev;
4692   */
4693      IF nlssort(l_current_rtg_revision) >
4694                 nlssort(item.new_routing_revision)
4695      THEN
4696      If msg_qty < max_messages then
4697                         msg_qty := msg_qty + 1;
4698                         message_names(msg_qty) := 'ENG_CUR_RTG_REV_HIGHER';
4699                         token1(msg_qty) := 'ENTITY1';
4700                         value1(msg_qty) := item.new_item_revision;
4701                         translate1(msg_qty) := 0;
4702                         token2(msg_qty) := 'ENTITY2';
4703                         value2(msg_qty) := l_current_revision;
4704                         translate2(msg_qty) := 0;
4705                 end if;
4706                 If trial_mode = no then
4707                         Raise abort_implementation;
4708         end if;
4709 
4710        /*Bug 5256284    Added below IF condition to check whether the current rtg rev is less than new rtg rev.
4711        Implement the new rtg rev only if it is greater than (and not equal to) the current rtg rev.
4712        This is done to prevent the updation of the effectivity_date of the current rtg rev.*/
4713 
4714       ELSIF nlssort(l_current_rtg_revision) < nlssort(item.new_routing_revision)  THEN
4715      -- implement the new routing revision
4716      UPDATE mtl_rtg_item_revisions
4717      SET        implementation_date = today,
4718                 effectivity_date = eff_date,
4719                 last_update_date = sysdate,
4720                 last_updated_by = userid,
4721                 last_update_login = loginid,
4722                 request_id = reqstid,
4723                 program_application_id = appid,
4724                 program_id = progid,
4725                 program_update_date = sysdate
4726      WHERE  inventory_item_id = item.revised_item_id
4727      AND   organization_id   = item.organization_id
4728      AND   process_revision  = item.new_routing_revision;
4729 
4730      -- ERES changes begin : bug 3908563
4731      IF SQL%ROWCOUNT > 0
4732      THEN
4733        -- ERES flag to be set for triggering Routing Event:
4734        bERES_Flag_for_Routing := TRUE;
4735        -- Bug 4455543: Set l_WIP_Flag_for_Routing when routing revision is being updated by revised item
4736        l_WIP_Flag_for_Routing := 'Y';
4737        FND_FILE.PUT_LINE(FND_FILE.LOG, 'in mtl_rtg_item_revisions... bERES_Flag_for_Routing=TRUE');
4738      END IF;
4739      -- ERES changes end.
4740 
4741     END IF;   -- end of nlssort(current_routing_revision)
4742 
4743     -- implement the new revision in common routing too
4744 
4745     OPEN get_common_routing;
4746         LOOP
4747                 FETCH get_common_routing into common_routing;
4748                 EXIT WHEN get_common_routing %NOTFOUND;
4749 
4750                 OPEN get_common_current_routing_rev
4751                 (common_assembly_item_id => common_routing.assembly_item_id,
4752    --2809431        common_org_id  => common.organization_id
4753                  common_org_id           => common_routing.organization_id
4754                 ) ;
4755 
4756 
4757                 FETCH get_common_current_routing_rev into
4758                         common_current_rtg_rev;
4759                 CLOSE get_common_current_routing_rev;
4760 
4761                 --* Added for Bug 4366583
4762                 OPEN routing_revision_exists(
4763                              common_assembly_item_id=>common_routing.assembly_item_id,
4764                              common_org_id          =>common_routing.organization_id,
4765                     common_revision        =>item.new_routing_revision);
4766                      FETCH routing_revision_exists into l_rtg_revision_exists;
4767                 CLOSE routing_revision_exists;
4768                 --* End of Bug 4366583
4769 
4770    -- 2809431   IF nlssort(common_current_rev)
4771                 IF nlssort(common_current_rtg_rev)   -- added for BUG 2809431
4772                             < nlssort( item.new_routing_revision)
4773                    AND l_rtg_revision_exists = 0 --* AND condition added for bug 4366583
4774                 THEN
4775                     --- Update the revision to new revision
4776                     --- See if existing API can be used here
4777                   --- 2809431 NULL;
4778          -- 2809431 ( added the below API to Populate common routing revision)
4779 
4780 
4781                      ENG_COPY_TABLE_ROWS_PKG.C_MTL_RTG_ITEM_REVISIONS(
4782                          X_inventory_item_id => common_routing.assembly_item_id,
4783                          X_organization_id => common_routing.organization_id,
4784                          X_process_revision => item.new_routing_revision,
4785                          X_last_update_date => SYSDATE,
4786                          X_last_updated_by => userid,
4787                          X_creation_date => SYSDATE,
4788                          X_created_by => userid,
4789                          X_last_update_login => loginid,
4790                          X_effectivity_date => eff_date,
4791                          X_change_notice => item.change_notice,
4792                          X_implementation_date => today);
4793 
4794          -- 2809431 ( added the above API to Populate common routing revision)
4795               END IF;
4796         END LOOP;
4797     CLOSE get_common_routing;
4798 
4799   END IF;            -- IF item.new_routing_revision IS NOT NULL
4800 
4801   --If routing  change exists, Update routing header.
4802   --A new routing header should be generated from Form.
4803   -- Using RTG BO
4804   IF item.routing_sequence_id IS NOT NULL
4805   THEN
4806     SELECT alternate_routing_designator
4807     INTO  l_alternate_routing_designator
4808     FROM  bom_operational_routings
4809     WHERE routing_sequence_id  = item.routing_sequence_id;
4810 /*
4811     BOM_Rtg_Header_Util.Query_Row
4812         (  p_assembly_item_id       => item.revised_item_id
4813          , p_organization_id        => item.organization_id
4814          , p_alternate_routing_code => l_alternate_routing_designator
4815          , x_rtg_header_rec         => l_rtg_header_rec
4816          , x_rtg_header_unexp_rec   => l_rtg_header_unexp_rec
4817          , x_Return_status          => l_Return_status
4818         );
4819 
4820    l_rtg_header_rec.cfm_routing_flag :=
4821           NVL(item.cfm_routing_flag, l_rtg_header_rec.cfm_routing_flag);
4822    l_rtg_header_rec.completion_subinventory :=
4823    NVL(item.completion_subinventory, l_rtg_header_rec.completion_subinventory);
4824    l_rtg_header_unexp_rec.completion_locator_id:=
4825    NVL(item.completion_locator_id, l_rtg_header_unexp_rec.completion_locator_id);
4826    l_rtg_header_rec.mixed_model_map_flag :=
4827          NVL(item.mixed_model_map_flag, l_rtg_header_rec.mixed_model_map_flag);
4828 */
4829 
4830    SELECT
4831      routing_sequence_id
4832     ,cfm_routing_flag
4833     ,completion_subinventory
4834     ,completion_locator_id
4835     ,mixed_model_map_flag
4836     ,common_assembly_item_id
4837     ,common_routing_sequence_id
4838     ,ctp_flag
4839     ,priority
4840     ,routing_comment
4841    INTO
4842      l_routing_sequence_id
4843     ,l_cfm_routing_flag
4844     ,l_completion_subinventory
4845     ,l_completion_locator_id
4846     ,l_mixed_model_map_flag
4847     ,l_common_assembly_item_id
4848     ,l_common_routing_sequence_id
4849     ,l_ctp_flag
4850     ,l_priority
4851     ,l_routing_comment
4852    FROM  bom_operational_routings
4853    WHERE  assembly_item_id = item.revised_item_id
4854    AND  organization_id  = item.organization_id
4855    AND  NVL(alternate_routing_designator, 'NULL_ALTERNATE_DESIGNATOR' )
4856                     = NVL(l_alternate_routing_designator,  'NULL_ALTERNATE_DESIGNATOR')
4857     ;
4858 
4859  --start of bugfix 3234628
4860     IF item.completion_subinventory IS NOT NULL OR
4861        item.completion_locator_id IS NOT NULL OR
4862        item.ctp_flag = 1 OR
4863        item.priority IS NOT NULL OR
4864        item.routing_comment IS NOT NULL
4865     THEN
4866 
4867                    UPDATE bom_operational_routings
4868                    SET common_assembly_item_id =
4869                              l_common_assembly_item_id
4870                      , common_routing_sequence_id =
4871                              l_common_routing_sequence_id
4872                      , ctp_flag = NVL(item.ctp_flag,l_ctp_flag)
4873                      , priority = NVL(item.priority,l_priority)
4874                      , cfm_routing_flag =
4875                          NVL(item.cfm_routing_flag, l_cfm_routing_flag)
4876                      , routing_comment =
4877                          NVL(item.routing_comment, l_routing_comment)
4878                      , mixed_model_map_flag =
4879                           NVL(item.mixed_model_map_flag, l_mixed_model_map_flag)
4880                      , completion_subinventory =
4881                           NVL(item.completion_subinventory, l_completion_subinventory)
4882                      , completion_locator_id =
4883                           NVL(item.completion_locator_id, l_completion_locator_id)
4884                      , last_update_date =  SYSDATE
4885                      , last_updated_by =    userid
4886                      , last_update_login =  loginid
4887                   WHERE routing_sequence_id =
4888                              l_routing_sequence_id;
4889 
4890          -- ERES changes begin : bug 3908563
4891          IF SQL%ROWCOUNT > 0
4892          THEN
4893            -- ERES flag to be set for triggering Routing Event:
4894            bERES_Flag_for_Routing := TRUE;
4895            -- Bug 4455543: Set l_WIP_Flag_for_Routing when routing header is being updated by revised item
4896            l_WIP_Flag_for_Routing := 'Y';
4897            FND_FILE.PUT_LINE(FND_FILE.LOG, 'in bom_operational_routings ... bERES_Flag_for_Routing=TRUE');
4898          END IF;
4899          -- ERES changes end.
4900     END IF;
4901  --end of bugfix 3234628
4902  END IF;      -- enf of IF item.routing_sequence_id IS NOT NULL
4903 
4904 
4905 --Check if there are revised operations or events for the routing.
4906 
4907  OPEN chng_operation_rows;
4908  LOOP
4909     FETCH chng_operation_rows  into chng_operation_rec;
4910     EXIT WHEN chng_operation_rows %NOTFOUND;
4911 
4912 
4913     --check the ECO operation conflict
4914     IF item.update_wip = 1
4915     AND chng_operation_rec.acd_type IN (acd_change, acd_delete)
4916     THEN
4917 
4918        -- For ECO Cumulative type record
4919        -- Check if the current operation is not existing in
4920        -- the specified WIP discrete job.
4921      IF  NVL(item.from_cum_qty, 0) > 0
4922      THEN
4923        OPEN check_not_existing_op_cum
4924        ( p_from_wip_entity_id => item.from_wip_entity_id,
4925          p_operation_seq_num  => chng_operation_rec.operation_seq_num,
4926          p_organization_id    => item.organization_id ) ;
4927        FETCH check_not_existing_op_cum INTO dummy;
4928        IF check_not_existing_op_cum%NOTFOUND
4929        THEN If msg_qty < max_messages then
4930                         msg_qty := msg_qty + 1;
4931                         message_names(msg_qty) := 'ENG_OP_ECO_CUM_CONFLICT';
4932                         token1(msg_qty) := 'REVISED_ITEM';
4933                         value1(msg_qty) := item.revised_item_id;
4934                         translate1(msg_qty) := 0;
4935                         token2(msg_qty) := 'OPERATION_SEQ_NUM';
4936                         value2(msg_qty) :=
4937                               chng_operation_rec.operation_seq_num;
4938                         translate2(msg_qty) := 0;
4939              end if;
4940              If trial_mode = no then
4941                         Raise abort_implementation;
4942              end if;
4943        END IF;
4944        CLOSE check_not_existing_op_cum;
4945       END IF;        -- end of IF NVL(item.from_cum_qty, 0) > 0
4946 
4947        -- For ECO Discrete Job type record
4948        -- At the WIP job range ( from_wip_job_name, to_wip_job_name),
4949        -- check if there is a WIP discrete job,  in which the current
4950        -- operation has already disabled or changed.
4951       IF nvl(item.to_wip_entity_id, 0) <> 0
4952       THEN
4953         OPEN check_not_existing_op_job
4954         (  p_from_wip_entity_id => item.from_wip_entity_id,
4955           p_to_wip_entity_id   => item.to_wip_entity_id,
4956           p_operation_seq_num  => chng_operation_rec.operation_seq_num,
4957           p_organization_id    => item.organization_id) ;
4958         FETCH check_not_existing_op_job INTO dummy;
4959         IF check_not_existing_op_job%FOUND
4960         THEN If msg_qty < max_messages then
4961                         msg_qty := msg_qty + 1;
4962                         message_names(msg_qty) := 'ENG_OP_ECO_JOB_CONFLICT';
4963                         token1(msg_qty) := 'REVISED_ITEM';
4964                         value1(msg_qty) := item.revised_item_id;
4965                         translate1(msg_qty) := 0;
4966                         token2(msg_qty) := 'OPERATION_SEQ_NUM';
4967                         value2(msg_qty) :=
4968                               chng_operation_rec.operation_seq_num;
4969                         translate2(msg_qty) := 0;
4970              end if;
4971              If trial_mode = no then
4972                         Raise abort_implementation;
4973              end if;
4974 
4975         END IF;
4976         CLOSE check_not_existing_op_job ;
4977        END IF;    -- nvl(item.to_wip_entity_id, 0) <> 0
4978 
4979 
4980        -- For ECO Lot type record
4981        -- Among WIP discrete jobs with  same specified lot number, check
4982        -- if there is a WIP discrete job,  in which the current opertion has
4983        -- already been disabled or changed.
4984       IF item.lot_number IS NOT NULL
4985       THEN
4986         OPEN check_not_existing_op_lot
4987         (  p_wip_lot_number     => item.lot_number,
4988            p_operation_seq_num  =>  chng_operation_rec.operation_seq_num);
4989         FETCH check_not_existing_op_lot INTO dummy;
4990         IF check_not_existing_op_lot%FOUND
4991         THEN If msg_qty < max_messages then
4992                         msg_qty := msg_qty + 1;
4993                         message_names(msg_qty) := 'ENG_OP_ECO_LOT_CONFLICT';
4994                         token1(msg_qty) := 'REVISED_ITEM';
4995                         value1(msg_qty) := item.revised_item_id;
4996                         translate1(msg_qty) := 0;
4997                         token2(msg_qty) := 'OPERATION_SEQ_NUM';
4998                         value2(msg_qty) :=
4999                               chng_operation_rec.operation_seq_num;
5000                         translate2(msg_qty) := 0;
5001              end if;
5002              If trial_mode = no then
5003                         Raise abort_implementation;
5004              end if;
5005         END IF;
5006         CLOSE  check_not_existing_op_lot;
5007       END IF;     -- item.lot_number IS NOT NULL
5008     END IF;       -- end of IF item.update_wip = 1
5009 
5010 
5011     -- For operation ADD/Change type records, check the effectivity of
5012     -- operation
5013 
5014     IF chng_operation_rec.acd_type IN (acd_change, acd_add)
5015     THEN
5016 
5017         IF NVL(chng_operation_rec.disable_date, eff_date)  < eff_date
5018         THEN If msg_qty < max_messages then
5019                 msg_qty := msg_qty + 1;
5020                 message_names(msg_qty) := 'ENG_OP_INVALID_DISABLE_DATE';
5021                 token1(msg_qty) := 'OPERATION_SEQ_NUM';
5022                 value1(msg_qty) := chng_operation_rec.operation_seq_num;
5023                 translate1(msg_qty) := 0;
5024                 token2(msg_qty) := 'DISABLE_DATE';
5025                 value2(msg_qty) :=
5026                               chng_operation_rec.disable_date;
5027                         translate2(msg_qty) := 0;
5028              end if;
5029              If trial_mode = no then
5030                         Raise abort_implementation;
5031              end if;
5032         END IF;
5033 
5034 
5035    END IF;             -- end of IF chng_operation_rec.acd_type IN (acd_add, acd_change)
5036 
5037 
5038    IF chng_operation_rec.acd_type IN ( acd_change, acd_delete)
5039    THEN
5040 
5041             Open old_operation(chng_operation_rec.old_operation_sequence_id);
5042             Fetch old_operation into old_op_rec;
5043 
5044             If old_op_rec.implementation_date is null then
5045                         If msg_qty < max_messages then
5046                                 msg_qty := msg_qty + 1;
5047                                 message_names(msg_qty) :=
5048                                         'ENG_OLD_OP_UNIMPLEMENTED';
5049                                 token1(msg_qty) := 'ITEM';
5050                                 value1(msg_qty) := item.revised_item_id;
5051                                 translate1(msg_qty) := 0;
5052                                 token2(msg_qty) := 'OPERATION';
5053                                 value2(msg_qty) := chng_operation_rec.operation_seq_num;
5054                                 translate2(msg_qty) := 0;
5055                         end if;
5056                         If trial_mode = no then
5057                                 Close old_operation;
5058                                 Raise abort_implementation;
5059                         end if;
5060             elsif nvl(old_op_rec.disable_date,eff_date) < eff_date then
5061                         If msg_qty < max_messages then
5062                                 msg_qty := msg_qty + 1;
5063                                 message_names(msg_qty) :=
5064                                         'ENG_OLD_OP_DISABLED';
5065                                 token1(msg_qty) := 'ITEM';
5066                                 value1(msg_qty) := item.revised_item_id;
5067                                 translate1(msg_qty) := 0;
5068                                 token2(msg_qty) := 'OPERATION';
5069                                 value2(msg_qty) := chng_operation_rec.operation_seq_num;
5070                                 translate2(msg_qty) := 0;
5071                         end if;
5072                         If trial_mode = no then
5073                                 Close old_operation;
5074                                 Raise abort_implementation;
5075                         end if;
5076             elsif old_op_rec.effectivity_date > eff_date then
5077                         If msg_qty < max_messages then
5078                                 msg_qty := msg_qty + 1;
5079                                 message_names(msg_qty) :=
5080                                         'ENG_OLD_OP_INEFFECTIVE';
5081                                 token1(msg_qty) := 'ITEM';
5082                                 value1(msg_qty) := item.revised_item_id;
5083                                 translate1(msg_qty) := 0;
5084                                 token2(msg_qty) :=  'OPERATION';
5085                                 value2(msg_qty) := chng_operation_rec.operation_seq_num;
5086                                 translate2(msg_qty) := 0;
5087                         end if;
5088                         If trial_mode = no then
5089                                 Close old_operation;
5090                                 Raise abort_implementation;
5091                         end if;
5092 
5093             else
5094 
5095                count_op_disable := count_op_disable + 1;
5096                rev_op_disable_date_tbl(count_op_disable).revised_item_id  := item.revised_item_id;
5097                rev_op_disable_date_tbl(count_op_disable).operation_seq_id :=
5098                                         chng_operation_rec.old_operation_sequence_id;
5099                rev_op_disable_date_tbl(count_op_disable).disable_date     :=  old_op_rec.disable_date;
5100 
5101                old_op_rec.disable_date := eff_date;
5102                IF item.eco_for_production = 2
5103                THEN old_op_rec.change_notice := item.change_notice;
5104                END IF;
5105             end if;
5106 
5107             If  chng_operation_rec.acd_type = acd_delete then
5108                 chng_operation_rec.disable_date := eff_date;
5109             end if;
5110 
5111             -- Disalbe the old operation record
5112             UPDATE bom_operation_sequences
5113             SET
5114                       change_notice = old_op_rec.change_notice,
5115                       implementation_date = today,
5116                       disable_date = old_op_rec.disable_date,
5117     --bug 5622459     disable_date = old_op_rec.disable_date - 1/(60*60*24),
5118                       last_update_date = sysdate,
5119                       last_updated_by = userid,
5120                       last_update_login = loginid,
5121                       request_id = reqstid,
5122                       program_application_id = appid,
5123                       program_id = progid,
5124                       program_update_date = sysdate
5125            WHERE operation_sequence_id=
5126                   old_op_rec.operation_sequence_id;
5127 
5128            Close  old_operation;
5129 
5130     IF chng_operation_rec.acd_type IN (acd_change, acd_add)
5131     THEN
5132 
5133     --  Check operation verlapping for date effective
5134         OPEN check_overlapping_operation
5135          ( chng_operation_rec.routing_sequence_id,
5136            chng_operation_rec.operation_seq_num,
5137            chng_operation_rec.operation_sequence_id,
5138 --           chng_operation_rec.effectivity_date -- changed for bug 2827313
5139            eff_date -- this is the date that will eventually be the effective date of the new operation
5140          );
5141          FETCH check_overlapping_operation  INTO dummy;
5142    --      IF check_overlapping_operation%NOTFOUND
5143          IF check_overlapping_operation%FOUND
5144          THEN If msg_qty < max_messages then
5145                 msg_qty := msg_qty + 1;
5146                 message_names(msg_qty) := 'ENG_IMP_OP_INVALID_EFF_DATE';
5147                 token1(msg_qty) := 'OPERATION_SEQ_NUM';
5148                 value1(msg_qty) := chng_operation_rec.operation_seq_num;
5149                 translate1(msg_qty) := 0;
5150                 token2(msg_qty) := 'EFFECTIVE_DATE';
5151                 value2(msg_qty) :=
5152                               chng_operation_rec.effectivity_date;
5153                         translate2(msg_qty) := 0;
5154              end if;
5155              If trial_mode = no then
5156                         Raise abort_implementation;
5157              end if;
5158          END IF;
5159         CLOSE check_overlapping_operation;
5160      END IF;
5161 
5162 
5163           IF  chng_operation_rec.acd_type = acd_change
5164           -- Copy attached resources in the old operation to the new operation,
5165           -- except the disabled resource.
5166           THEN
5167               INSERT INTO  bom_operation_resources
5168                  (
5169                    operation_sequence_id
5170                    , resource_seq_num
5171                    , resource_id
5172                    , activity_id
5173                    , standard_rate_flag
5174                    , assigned_units
5175                    , usage_rate_or_amount
5176                    , usage_rate_or_amount_inverse
5177                    , basis_type
5178                    , schedule_flag
5179                    , last_update_date
5180                    , last_updated_by
5181                    , creation_date
5182                    , created_by
5183                    , last_update_login
5184                    , resource_offset_percent
5185                    , autocharge_type
5186                    , attribute_category
5187                    , attribute1
5188                    , attribute2
5189                    , attribute3
5190                    , attribute4
5191                    , attribute5
5192                    , attribute6
5193                    , attribute7
5194                    , attribute8
5195                    , attribute9
5196                    , attribute10
5197                    , attribute11
5198                    , attribute12
5199                    , attribute13
5200                    , attribute14
5201                    , attribute15
5202                    , request_id
5203                    , program_application_id
5204                    , program_id
5205                    , program_update_date
5206                    , schedule_seq_num
5207                    , substitute_group_num
5208                    , principle_flag
5209                    , change_notice
5210                    , acd_type
5211                    , original_system_reference
5212                  )
5213               SELECT
5214                    chng_operation_rec.operation_sequence_id
5215                    , resource_seq_num
5216                    , resource_id
5217                    , activity_id
5218                    , standard_rate_flag
5219                    , assigned_units
5220                    , usage_rate_or_amount
5221                    , usage_rate_or_amount_inverse
5222                    , basis_type
5223                    , schedule_flag
5224                    , sysdate
5225                    , userid
5226                    , sysdate
5227                    , userid
5228                    , loginid
5229                    , resource_offset_percent
5230                    , autocharge_type
5231                    , attribute_category
5232                    , attribute1
5233                    , attribute2
5234                    , attribute3
5235                    , attribute4
5236                    , attribute5
5237                    , attribute6
5238                    , attribute7
5239                    , attribute8
5240                    , attribute9
5241                    , attribute10
5242                    , attribute11
5243                    , attribute12
5244                    , attribute13
5245                    , attribute14
5246                    , attribute15
5247                    , reqstid
5248                    , appid
5249                    , progid
5250                    , sysdate
5251                    , schedule_seq_num
5252                    , substitute_group_num
5253                    , principle_flag
5254                    , change_notice
5255                    , acd_type
5256                    , original_system_reference
5257              FROM  bom_operation_resources a
5258              WHERE operation_sequence_id =
5259                    chng_operation_rec.old_operation_sequence_id
5260              --* Commented following line for Bug 3520302
5261              --* AND nvl(acd_type, acd_add)  = acd_add
5262              --* Added for Bug 3520302
5263              AND nvl(acd_type, acd_add) in (acd_add,acd_change)
5264 	     AND resource_seq_num  NOT IN (
5265                  SELECT b.resource_seq_num
5266                  FROM  bom_operation_resources b
5267                  WHERE b.operation_sequence_id =
5268                             chng_operation_rec.operation_sequence_id);
5269 
5270 /* Fix for bug 4606950  - In the above select query, modified the sub-query in the where clause.
5271    Replaced the resource_id with resource_seq_num. The old sub-query was commented as below*/
5272 /*
5273              AND resource_id NOT IN (
5274                  SELECT b.resource_id
5275                  FROM  bom_operation_resources b
5276                  WHERE b.operation_sequence_id =
5277                             chng_operation_rec.operation_sequence_id
5278                        and b.resource_seq_num = a.resource_seq_num);
5279 */
5280 -- Bug 2641382
5281 -- The above filter condition was modified to search the valid
5282 -- resources based on operation_sequence_id and resource_seq_num
5283 
5284              -- Copy attached substitute resources in the old operation to the new operation,
5285              -- except the disabled substitute resource.
5286 
5287              INSERT INTO bom_sub_operation_resources
5288                         (
5289                            operation_sequence_id
5290                          , substitute_group_num
5291                          , resource_id
5292                          , replacement_group_num
5293                          , activity_id
5294                          , standard_rate_flag
5295                          , assigned_units
5296                          , usage_rate_or_amount
5297                          , usage_rate_or_amount_inverse
5298                          , basis_type
5299                          , schedule_flag
5300                          , last_update_date
5301                          , last_updated_by
5302                          , creation_date
5303                          , created_by
5304                          , last_update_login
5305                          , resource_offset_percent
5306                          , autocharge_type
5307                          , principle_flag
5308                          , attribute_category
5309                          , attribute1
5310                          , attribute2
5311                          , attribute3
5312                          , attribute4
5313                          , attribute5
5314                          , attribute6
5315                          , attribute7
5316                          , attribute8
5317                          , attribute9
5318                          , attribute10
5319                          , attribute11
5320                          , attribute12
5321                          , attribute13
5322                          , attribute14
5323                          , attribute15
5324                          , request_id
5325                          , program_application_id
5326                          , program_id
5327                          , program_update_date
5328                          , schedule_seq_num
5329                          , change_notice
5330                          , acd_type
5331                          , original_system_reference
5332                          )
5333                      select
5334                            chng_operation_rec.operation_sequence_id
5335                          , substitute_group_num
5336                          , resource_id
5337                          , replacement_group_num
5338                          , activity_id
5339                          , standard_rate_flag
5340                          , assigned_units
5341                          , usage_rate_or_amount
5342                          , usage_rate_or_amount_inverse
5343                          , basis_type
5344                          , schedule_flag
5345                          , sysdate
5346                          , userid
5347                          , sysdate
5348                          , userid
5349                          , loginid
5350                          , resource_offset_percent
5351                          , autocharge_type
5352                          , principle_flag
5353                          , attribute_category
5354                          , attribute1
5355                          , attribute2
5356                          , attribute3
5357                          , attribute4
5358                          , attribute5
5359                          , attribute6
5360                          , attribute7
5361                          , attribute8
5362                          , attribute9
5363                          , attribute10
5364                          , attribute11
5365                          , attribute12
5366                          , attribute13
5367                          , attribute14
5368                          , attribute15
5369                          , reqstid
5370                          , appid
5371                          , progid
5372                          , sysdate
5373                          , schedule_seq_num
5374                          , change_notice
5375                          , acd_type
5376                          , original_system_reference
5377                      FROM bom_sub_operation_resources
5378                      WHERE operation_sequence_id =
5379                        chng_operation_rec.old_operation_sequence_id
5380                      AND nvl(acd_type, acd_add) = acd_add
5381                      AND resource_id NOT IN (
5382                      SELECT resource_id
5383                      FROM bom_sub_operation_resources
5384                      WHERE operation_sequence_id =
5385                             chng_operation_rec.operation_sequence_id );
5386 
5387              -- Copy attachment of the Operation Sequences
5388              -- Added for Bug 3701023
5389              FND_ATTACHED_DOCUMENTS2_PKG.copy_attachments(
5390                     X_from_entity_name         => 'BOM_OPERATION_SEQUENCES'
5391                   , X_from_pk1_value           => to_char(chng_operation_rec.old_operation_sequence_id)
5392                   , X_from_pk2_value           => null
5393                   , X_from_pk3_value           => null
5394                   , X_from_pk4_value           => null
5395                   , X_from_pk5_value           => null
5396                   , X_to_entity_name           => 'BOM_OPERATION_SEQUENCES'
5397                   , X_to_pk1_value             => to_char(chng_operation_rec.operation_sequence_id)
5398                   , X_to_pk2_value             => null
5399                   , X_to_pk3_value             => null
5400                   , X_to_pk4_value             => null
5401                   , X_to_pk5_value             => null
5402                   , X_created_by               => userid
5403                   , X_last_update_login        => loginid
5404                   , X_program_application_id   => appid
5405                   , X_program_id               => progid
5406                   , X_request_id               => reqstid);
5407 
5408              -- End Changes for Bug 3701023
5409 
5410 
5411          END IF;    --   IF  chng_operation_rec.acd_type = acd_change
5412 
5413 
5414 
5415       END IF;      -- end of  IF chng_operation_rec.acd_type in ( acd_change, acd_delete )
5416 
5417       IF chng_operation_rec.acd_type =  acd_change
5418       THEN
5419 
5420        -- The following is for resource process
5421        --Check resource Add/Disable record existing
5422         OPEN chng_resource_rows;
5423         LOOP
5424                 FETCH chng_resource_rows  into chng_resource_rec;
5425                 EXIT  WHEN chng_resource_rows%NOTFOUND;
5426 
5427                -- Resource conflict check
5428                IF  item.update_wip = 1
5429                AND chng_resource_rec.acd_type IN ( acd_change, acd_delete)
5430                THEN
5431 
5432                  --For ECO Cumulative type record
5433                  --Check if the current  resource is not existing in the
5434                  --specified WIP discrete job'operation.
5435                  IF  NVL(item.from_cum_qty, 0) > 0
5436                  THEN
5437 
5438                  OPEN check_not_existing_res_cum
5439                   (p_from_wip_entity_id => item.from_wip_entity_id,
5440                    p_operation_seq_num  => chng_operation_rec.operation_seq_num,
5441                    p_resource_seq_num   => chng_resource_rec.resource_seq_num,
5442                    p_organization_id    => item.organization_id
5443                   )  ;
5444                  FETCH check_not_existing_res_cum  INTO dummy;
5445                  IF check_not_existing_res_cum%NOTFOUND
5446                  THEN If msg_qty < max_messages then
5447                         msg_qty := msg_qty + 1;
5448                         message_names(msg_qty) := 'ENG_RES_ECO_CUM_CONFLICT';
5449                         token1(msg_qty) := 'OPERATION_SEQ_NUM';
5450                         value1(msg_qty) :=
5451                               to_char(chng_operation_rec.operation_seq_num);
5452                         translate1(msg_qty) := 0;
5453                         token2(msg_qty) := 'RESOURCE_SEQ_NUM';
5454                         value2(msg_qty) :=
5455                               to_char(chng_resource_rec.resource_seq_num);
5456                         translate2(msg_qty) := 0;
5457                       end if;
5458                       If trial_mode = no then
5459                         Raise abort_implementation;
5460                       end if;
5461 
5462                  END IF; -- end of check_not_existing_res_cum%NOTFOUND
5463                  CLOSE check_not_existing_res_cum;
5464                END IF;   -- end of NVL(item.from_cum_qty, 0) > 0
5465 
5466 
5467                  --For ECO Discrete Job type record
5468                  --At the WIP job range ( from_wip_job_name, to_wip_job_name),
5469                  --check if there is a WIP discrete job,  in which the current
5470                  --resouce has already been disabled or changed.
5471                IF nvl(item.to_wip_entity_id, 0) <> 0
5472                THEN
5473                  OPEN check_not_existing_res_job
5474                  ( p_from_wip_entity_id=> item.from_wip_entity_id,
5475                    p_to_wip_entity_id  => item.to_wip_entity_id,
5476                    p_operation_seq_num => chng_operation_rec.operation_seq_num,
5477                    p_resource_seq_num  => chng_resource_rec.resource_seq_num,
5478                    p_organization_id   =>  item.organization_id
5479                  ) ;
5480                  FETCH check_not_existing_res_job INTO dummy;
5481                  IF check_not_existing_res_job%FOUND
5482                  THEN If msg_qty < max_messages then
5483                         msg_qty := msg_qty + 1;
5484                         message_names(msg_qty) := 'ENG_RES_ECO_JOB_CONFLICT';
5485                         token1(msg_qty) := 'OPERATION_SEQ_NUM';
5486                         value1(msg_qty) :=
5487                               to_char(chng_operation_rec.operation_seq_num);
5488                         translate1(msg_qty) := 0;
5489                         token2(msg_qty) := 'RESOURCE_SEQ_NUM';
5490                         value2(msg_qty) :=
5491                               to_char(chng_resource_rec.resource_seq_num);
5492                         translate2(msg_qty) := 0;
5493 
5494                      end if;
5495                       If trial_mode = no then
5496                         Raise abort_implementation;
5497                       end if;
5498 
5499                   END IF; -- end ofcheck_not_existing_res_job%FOUND
5500                   CLOSE check_not_existing_res_job;
5501                 END IF; -- envl(item.to_wip_entity_id, 0) <> 0
5502 
5503                  --For ECO Lot type record
5504                  --Among WIP discrete jobs with same specified lot number,
5505                  -- check if there is a WIP discrete job,  in which the
5506                  -- current component has already been disabled or changed.
5507                 IF item.lot_number IS NOT NULL
5508                 THEN
5509                  OPEN check_not_existing_res_lot
5510                  ( p_wip_lot_number    => item.lot_number,
5511                    p_operation_seq_num => chng_operation_rec.operation_seq_num,
5512                    p_resource_seq_num  => chng_resource_rec.resource_seq_num,
5513                    p_organization_id   =>  item.organization_id
5514                  );
5515                  FETCH check_not_existing_res_lot INTO dummy;
5516                  IF check_not_existing_res_lot%FOUND
5517                  THEN If msg_qty < max_messages then
5518                         msg_qty := msg_qty + 1;
5519                         message_names(msg_qty) := 'ENG_RES_ECO_LOT_CONFLICT';
5520                         token1(msg_qty) := 'OPERATION_SEQ_NUM';
5521                         value1(msg_qty) :=
5522                               to_char(chng_operation_rec.operation_seq_num);
5523                         translate1(msg_qty) := 0;
5524                         token2(msg_qty) := 'RESOURCE_SEQ_NUM';
5525                         value2(msg_qty) :=
5526                               to_char(chng_resource_rec.resource_seq_num);
5527                         translate2(msg_qty) := 0;
5528                       end if;
5529                       If trial_mode = no then
5530                         Raise abort_implementation;
5531                       end if;
5532                   END IF; -- check_not_existing_res_lot%FOUND
5533                   CLOSE check_not_existing_res_lot;
5534                 END IF;   -- end of  IF item.lot_number IS NOT NULL
5535 
5536            END IF;  -- end of IF item.update_wip = 1 and chng_resource_rec
5537                --
5538                -- Check whether all resources in same resource group have been
5539                -- disabled, if so, delete the sub resources too.
5540 	       /* Commented the below delete st for bug 4577459 . This delete st deletes all rows from the table
5541    that have been created through the routing form irrespective of which routing they belong to.
5542    As while implementing the ECO we do not delete the bom_operation_resources data the sub resources
5543    associated need not be deleted */
5544               /* DELETE
5545                FROM bom_sub_operation_resources sr
5546                WHERE   NOT EXISTS (
5547                SELECT 1
5548                FROM bom_operation_resources bor
5549                WHERE   bor.operation_sequence_id  =  sr.operation_sequence_id
5550                AND        bor.substitute_group_num = sr.substitute_group_num
5551                AND        bor.acd_type  <> 3
5552                );*/
5553 
5554 
5555         END LOOP;       -- end of OPEN chng_resource_rows Loop
5556 
5557         CLOSE chng_resource_rows;
5558 
5559       END IF;           -- end of IF chng_operation_rec.acd_type = acd_change
5560 
5561 -- Implement the current operation row.
5562             UPDATE bom_operation_sequences
5563             SET
5564                       change_notice       = item.change_notice,
5565                       implementation_date = today,
5566                       disable_date        = chng_operation_rec.disable_date,
5567                       effectivity_date = eff_date,
5568                       last_update_date    = sysdate,
5569                       last_updated_by     = userid,
5570                       last_update_login   = loginid,
5571                       request_id          = reqstid,
5572                       program_application_id = appid,
5573                       program_id          = progid,
5574                       program_update_date = sysdate
5575            WHERE operation_sequence_id    =
5576                   chng_operation_rec.operation_sequence_id;
5577 
5578 
5579 --
5580 -- Update all unimplemented rows that point to the old row, so that they now
5581 -- point to the new operation row.
5582 --
5583 
5584         If  chng_operation_rec.acd_type = acd_change then
5585 --fix for bug 1607851
5586           IF item.eco_for_production = 2  THEN
5587             Update bom_operation_sequences
5588             set    old_operation_sequence_id = chng_operation_rec.operation_sequence_id,
5589                    last_update_date = sysdate,
5590                    last_updated_by = userid,
5591                    last_update_login = loginid,
5592                    request_id = reqstid,
5593                    program_application_id = appid,
5594                    program_id = progid,
5595                    program_update_date = sysdate
5596             where  old_operation_sequence_id =
5597                    chng_operation_rec.old_operation_sequence_id
5598             and    implementation_date is null;
5599          END IF;
5600         end if; -- reset pointers
5601 
5602  -- Copy all implemented operations to eng_revised_operations.
5603 
5604   INSERT into eng_revised_operations(
5605     operation_sequence_id ,
5606     routing_sequence_id ,
5607     operation_seq_num ,
5608     last_update_date ,
5609     last_updated_by ,
5610     creation_date ,
5611     created_by ,
5612     last_update_login ,
5613     standard_operation_id ,
5614     department_id ,
5615     operation_lead_time_percent ,
5616     minimum_transfer_quantity ,
5617     count_point_type ,
5618     operation_description ,
5619     effectivity_date ,
5620     disable_date ,
5621     backflush_flag ,
5622     option_dependent_flag ,
5623     attribute_category ,
5624     attribute1 ,
5625     attribute2 ,
5626     attribute3 ,
5627     attribute4 ,
5628     attribute5 ,
5629     attribute6 ,
5630     attribute7 ,
5631     attribute8 ,
5632     attribute9 ,
5633     attribute10 ,
5634     attribute11 ,
5635     attribute12 ,
5636     attribute13 ,
5637     attribute14 ,
5638     attribute15 ,
5639     request_id ,
5640     program_application_id ,
5641     program_id ,
5642     program_update_date ,
5643     operation_type ,
5644     reference_flag ,
5645     process_op_seq_id ,
5646     line_op_seq_id ,
5647     yield ,
5648     cumulative_yield ,
5649     reverse_cumulative_yield ,
5650     labor_time_calc ,
5651     machine_time_calc ,
5652     total_time_calc ,
5653     labor_time_user ,
5654     machine_time_user ,
5655     total_time_user ,
5656     net_planning_percent ,
5657     --x_coodinate,
5658     --y_coordinate,
5659     include_in_rollup ,
5660     operation_yield_enabled ,
5661     change_notice ,
5662     implementation_date ,
5663     old_operation_sequence_id ,
5664     acd_type  ,
5665     revised_item_sequence_id ,
5666     original_system_reference,
5667     eco_for_production
5668    )
5669    SELECT
5670     operation_sequence_id ,
5671     routing_sequence_id ,
5672     operation_seq_num ,
5673     last_update_date ,
5674     last_updated_by ,
5675     creation_date ,
5676     created_by ,
5677     last_update_login ,
5678     standard_operation_id ,
5679     department_id ,
5680     operation_lead_time_percent ,
5681     minimum_transfer_quantity ,
5682     count_point_type ,
5683     operation_description ,
5684     effectivity_date ,
5685     disable_date ,
5686     backflush_flag ,
5687     option_dependent_flag ,
5688     attribute_category ,
5689     attribute1 ,
5690     attribute2 ,
5691     attribute3 ,
5692     attribute4 ,
5693     attribute5 ,
5694     attribute6 ,
5695     attribute7 ,
5696     attribute8 ,
5697     attribute9 ,
5698     attribute10 ,
5699     attribute11 ,
5700     attribute12 ,
5701     attribute13 ,
5702     attribute14 ,
5703     attribute15 ,
5704     request_id ,
5705     program_application_id ,
5706     program_id ,
5707     program_update_date ,
5708     operation_type ,
5709     reference_flag ,
5710     process_op_seq_id ,
5711     line_op_seq_id ,
5712     yield ,
5713     cumulative_yield ,
5714     reverse_cumulative_yield ,
5715     labor_time_calc ,
5716     machine_time_calc ,
5717     total_time_calc ,
5718     labor_time_user ,
5719     machine_time_user ,
5720     total_time_user ,
5721     net_planning_percent ,
5722     --x_coodinate,
5723     --y_coordinate,
5724     include_in_rollup ,
5725     operation_yield_enabled ,
5726     change_notice ,
5727     implementation_date ,
5728     old_operation_sequence_id ,
5729     acd_type  ,
5730     revised_item_sequence_id ,
5731     original_system_reference,
5732     eco_for_production
5733    FROM bom_operation_sequences b
5734    WHERE operation_sequence_id
5735             = chng_operation_rec.operation_sequence_id;
5736 
5737    IF  chng_operation_rec.acd_type = acd_delete then
5738      Delete from bom_operation_sequences
5739      where operation_sequence_id =  chng_operation_rec.operation_sequence_id;
5740    END IF;
5741 
5742    -- ERES changes begin : bug 3908563
5743    -- ERES flag to be set for triggering Routing Event:
5744    bERES_Flag_for_Routing := TRUE;
5745    -- Bug 4455543: Set l_WIP_Flag_for_Routing when routing details is being updated by revised item
5746    l_WIP_Flag_for_Routing := 'Y';
5747    FND_FILE.PUT_LINE(FND_FILE.LOG, 'in chng_operation_rows loop... bERES_Flag_for_Routing=TRUE');
5748    -- ERES changes end.
5749 
5750  END LOOP;
5751 
5752  CLOSE chng_operation_rows;
5753 
5754 -- For ECO cumulative/ECO wip job/ECO lot  ---------8/2/2000----
5755 -----------------------------------------------------------------
5756 
5757 -- ECO for Bills implementation process
5758 --
5759 -- Select all component rows for the assembly and change notice in
5760 -- question from bom_inventory_components
5761 --
5762   -- if the common bom has a diiferent effectivity from the scheduled date then
5763   -- reset the eff_date value used for processing
5764   -- assuming that the components with the same effectivity are grouped together
5765   IF l_common_bom_eff_date IS NOT NULL
5766   THEN
5767       eff_date := l_common_bom_eff_date;
5768   END IF;
5769 
5770   For component in chng_component_rows(item.bill_sequence_id) loop
5771 
5772 	--   Get pending from ecn to check if structure created through this revised item or not.
5773 	--   Mark the BOM header as no longer pending from ECO
5774 	--
5775 	-- ERES Change begins
5776 	-- Decision for BillCreate or Update depends on pending_from_ecn:
5777 	    OPEN Get_Bill_of_Materials_Info( item.bill_sequence_id);
5778 	    FETCH Get_Bill_of_Materials_Info
5779 	     INTO l_pending_from_ecn
5780 		, l_alternate_designator;
5781 	    CLOSE Get_Bill_of_Materials_Info;
5782 	-- ERES change ends
5783 
5784 	IF( l_pending_from_ecn IS NOT NULL AND l_pending_from_ecn <> item.change_notice ) then
5785               If msg_qty < max_messages then
5786                         msg_qty := msg_qty + 1;
5787                         message_names(msg_qty) := 'ENG_PENDING_BILL_EXIST';
5788                         token1(msg_qty) := 'ECO_NAME';
5789                         value1(msg_qty) := l_pending_from_ecn;
5790                         translate1(msg_qty) := 0;
5791                 end if;
5792                 If trial_mode = no then
5793                         Raise abort_implementation;
5794                 end if;
5795         end if;
5796 
5797         If component.acd_type in (acd_change, acd_add) and
5798         component.disable_date < eff_date then
5799                 If msg_qty < max_messages then
5800                         msg_qty := msg_qty + 1;
5801                         message_names(msg_qty) := 'ENG_COMPONENT_ACD_DISABLED';
5802                         token1(msg_qty) := 'ITEM';
5803                         value1(msg_qty) := component.item_number;
5804                         translate1(msg_qty) := 0;
5805                         token2(msg_qty) := null;
5806                         value2(msg_qty) := null;
5807                         translate2(msg_qty) := 0;
5808                 end if;
5809                 If trial_mode = no then
5810                         Raise abort_implementation;
5811                 end if;
5812         end if;
5813 
5814         -- Check for mfg assemblies with eng components.
5815 
5816 /*bug 2264654
5817   Changed the condition to check for mfg assemblies instead of mfg items*/
5818 
5819         begin
5820 
5821            select assembly_type
5822            into l_bom_assembly_type
5823            from bom_bill_of_materials
5824            where bill_sequence_id = item.bill_sequence_id;
5825 
5826         end;
5827 
5828 --        If item.eng_item_flag = 'N' and
5829 
5830          If l_bom_assembly_type = 1 and
5831             component.eng_item_flag = 'Y' then
5832                 If msg_qty < max_messages then
5833                         msg_qty := msg_qty + 1;
5834                         token1(msg_qty) := null;
5835                         value1(msg_qty) := null;
5836                         translate1(msg_qty) := 0;
5837                         token2(msg_qty) := null;
5838                         value2(msg_qty) := null;
5839                         translate2(msg_qty) := 0;
5840                         message_names(msg_qty) := 'ENG_ENG_COMPONENTS';
5841                 end if;
5842                 If trial_mode = no then
5843                         Raise abort_implementation;
5844                 end if;
5845         end if;
5846 
5847         -- Added validation for bug 4213886
5848         -- Check for component items with unimplemented component item revision.
5849         IF (component.component_item_revision_id IS NOT null)
5850         THEN
5851             l_compitem_rev_impldate := null;
5852             Open c_get_revision(component.component_item_revision_id);
5853             Fetch c_get_revision into l_compitem_rev, l_compitem_rev_impldate;
5854             IF c_get_revision%NOTFOUND
5855             THEN
5856                 If msg_qty < max_messages
5857                 Then
5858                     msg_qty := msg_qty + 1;
5859                     token1(msg_qty) := 'ITEM';
5860                     value1(msg_qty) := component.item_number;
5861                     translate1(msg_qty) := 0;
5862                     token2(msg_qty) := 'OP_SEQ_NUM';
5863                     value2(msg_qty) := to_char(component.operation_seq_num);
5864                     translate2(msg_qty) := 0;
5865                     message_names(msg_qty) := 'ENG_COMP_ITM_REV_INVALID';
5866                     IF trial_mode = no
5867                     THEN
5868                         Close c_get_revision;
5869                         RAISE abort_implementation;
5870                     END IF;
5871                 END IF;
5872             ELSIF c_get_revision%FOUND AND l_compitem_rev_impldate IS NULL
5873             THEN
5874                 If msg_qty < max_messages
5875                 Then
5876                     msg_qty := msg_qty + 1;
5877                     token1(msg_qty) := 'ITEM';
5878                     value1(msg_qty) := component.item_number;
5879                     translate1(msg_qty) := 0;
5880                     token2(msg_qty) := 'OP_SEQ_NUM';
5881                     value2(msg_qty) := to_char(component.operation_seq_num);
5882                     translate2(msg_qty) := 0;
5883                     message_names(msg_qty) := 'ENG_COMP_ITM_REV_UNIMPL';
5884                     IF trial_mode = no
5885                     THEN
5886                         Close c_get_revision;
5887                         RAISE abort_implementation;
5888                     END IF;
5889                 End If;
5890             END IF;
5891             Close c_get_revision;
5892         END IF;
5893         -- End changes for bug 4213886
5894 
5895         -- check from and to unit numbers.
5896         -- Unit Effectivity implementation
5897         If (X_UnitEff_RevItem = 'Y')
5898         then
5899                 if (component.from_end_item_unit_number is NULL)
5900                 then
5901                         If msg_qty < max_messages then
5902                                 msg_qty := msg_qty + 1;
5903                                 token1(msg_qty) := null;
5904                                 value1(msg_qty) := null;
5905                                 translate1(msg_qty) := 0;
5906                                 token2(msg_qty) := null;
5907                                 value2(msg_qty) := null;
5908                                 translate2(msg_qty) := 0;
5909                                 message_names(msg_qty) :=
5910                                         'ENG_RCOMP_UNIT_KEYCOL_NULL';
5911                         end if;
5912                         If trial_mode = no then
5913                                 Raise abort_implementation;
5914                         end if;
5915                 end if;
5916 
5917                 if (component.to_end_item_unit_number is not null AND
5918                     component.to_end_item_unit_number < component.from_end_item_unit_number)
5919                 then
5920                         If msg_qty < max_messages then
5921                                 msg_qty := msg_qty + 1;
5922                                 message_names(msg_qty) :=
5923                                         'ENG_TOUNIT_LESSTHAN_FROMUNIT';
5924                                 token1(msg_qty) := 'ITEM';
5925                                 value1(msg_qty) := component.item_number;
5926                                 translate1(msg_qty) := 0;
5927                                 token2(msg_qty) := 'OP_SEQ_NUM';
5928                                 value2(msg_qty) :=
5929                                         to_char(component.operation_seq_num);
5930                                 translate2(msg_qty) := 0;
5931                         end if;
5932                         If trial_mode = no then
5933                                 Raise abort_implementation;
5934                         end if;
5935                 end if;
5936         end if;
5937 
5938 --------------------------------------------------------------------------
5939 --For ECO cumulative/ECO WIP job/ECO lot              8/2/2000 ---------
5940 --IFACD type =  CHANGE or DISABLE, check the followings.
5941 
5942 
5943                -- Component conflict check
5944             IF item.update_wip = 1
5945             AND component.acd_type IN (2, 3)
5946             THEN
5947                  --For ECO Cumulative type record
5948                  --Check if the current  compoment is not existing in the
5949                  --specified WIP discrete job'operation.
5950                IF  NVL(item.from_cum_qty, 0) > 0
5951                THEN
5952                  OPEN check_not_existing_comp_cum
5953                   (p_from_wip_entity_id => item.from_wip_entity_id,
5954                    p_operation_seq_num  => component.operation_seq_num,
5955                    p_inventory_item_id  => component.component_item_id,
5956                    p_organization_id    => item.organization_id
5957                   ) ;
5958                  FETCH check_not_existing_comp_cum  INTO dummy;
5959                  IF check_not_existing_comp_cum%NOTFOUND
5960                  THEN If msg_qty < max_messages then
5961                         msg_qty := msg_qty + 1;
5962                         message_names(msg_qty) := 'ENG_COMP_ECO_CUM_CONFLICT';
5963                         token1(msg_qty) := 'COMPONENT';
5964                         value1(msg_qty) :=component.component_item_id;
5965                         translate1(msg_qty) := 0;
5966                         token2(msg_qty) := 'OP_SEQ_NUM';
5967                         value2(msg_qty) :=
5968                                        to_char(component.operation_seq_num);
5969                         translate2(msg_qty) := 0;
5970                       end if;
5971                       If trial_mode = no then
5972                         Raise abort_implementation;
5973                       end if;
5974 
5975                  END IF;  -- end of check_not_existing_res_cum%NOTFOUND
5976                  CLOSE  check_not_existing_comp_cum;
5977 
5978                END IF;    -- end of NVL(item.from_cum_qty, 0) > 0
5979 
5980 
5981                  --For ECO Discrete Job type record
5982                  --At the WIP job range ( from_wip_job_name, to_wip_job_name),
5983                  --check if there is a WIP discrete job,  in which the current
5984                  --comp has already been disabled or changed.
5985                IF nvl(item.to_wip_entity_id, 0) <> 0
5986                THEN
5987 
5988 -- code to resolve the bug 2722280 begin
5989               if (component.acd_type = 2) then
5990                     OPEN get_old_operation_seq_num
5991                     ( p_old_component_sequence_id => component.old_component_sequence_id );
5992 
5993                     FETCH   get_old_operation_seq_num INTO l_old_op_seq_num;
5994                     CLOSE get_old_operation_seq_num;
5995               else
5996                     l_old_op_seq_num :=  component.operation_seq_num;
5997               end if;
5998 -- 2722280 completed
5999 
6000              if (l_old_op_seq_num <> 1) then              --2974766
6001 
6002                  OPEN check_not_existing_comp_job
6003                  (   p_from_wip_entity_id => item.from_wip_entity_id,
6004                      p_to_wip_entity_id   => item.to_wip_entity_id,
6005 -- 2722280             p_operation_seq_num  => component.operation_seq_num,
6006                      p_operation_seq_num  => l_old_op_seq_num,
6007                      p_inventory_item_id  => component.component_item_id,
6008                      p_organization_id    => item.organization_id
6009                  );
6010 
6011                  FETCH check_not_existing_comp_job INTO dummy;
6012                  IF check_not_existing_comp_job%FOUND
6013                  THEN If msg_qty < max_messages then
6014                         msg_qty := msg_qty + 1;
6015                         message_names(msg_qty) := 'ENG_COMP_ECO_JOB_CONFLICT';
6016                         token1(msg_qty) := 'COMPONENT';
6017                         value1(msg_qty) :=component.component_item_id;
6018                         translate1(msg_qty) := 0;
6019                         token2(msg_qty) := 'OP_SEQ_NUM';
6020                         value2(msg_qty) :=
6021                               to_char(component.operation_seq_num);
6022                         translate2(msg_qty) := 0;
6023                       end if;
6024                       If trial_mode = no then
6025                         Raise abort_implementation;
6026                       end if;
6027 
6028                  END IF; -- end of check_not_existing_comp_job%FOUND
6029                  CLOSE check_not_existing_comp_job;
6030                 End if;                        --2974766
6031                END IF;
6032 
6033                  -- For ECO Lot type record
6034                  -- Among WIP discrete jobs with same specified lot number,
6035                  -- check if there is a WIP discrete job,  in which the
6036                  -- current component has already been disabled or changed.
6037                IF item.lot_number IS NOT NULL
6038                THEN
6039                  OPEN check_not_existing_comp_lot
6040                   (   p_wip_lot_number     => item.lot_number,
6041                       p_operation_seq_num  => component.operation_seq_num,
6042                       p_inventory_item_id  => component.component_item_id,
6043                       p_organization_id    => item.organization_id
6044                   );
6045                  FETCH check_not_existing_comp_lot INTO dummy;
6046                  IF check_not_existing_comp_lot%FOUND
6047                  THEN If msg_qty < max_messages then
6048                         msg_qty := msg_qty + 1;
6049                         message_names(msg_qty) := 'ENG_COMP_ECO_LOT_CONFLICT';
6050                         token1(msg_qty) := 'COMPONENT';
6051                         value1(msg_qty) :=component.component_item_id;
6052                         translate1(msg_qty) := 0;
6053                         token2(msg_qty) := 'OP_SEQ_NUM';
6054                         value2(msg_qty) :=
6055                               to_char(component.operation_seq_num);
6056                         translate2(msg_qty) := 0;
6057                       end if;
6058                       If trial_mode = no then
6059                         Raise abort_implementation;
6060                       end if;
6061                   END IF; -- check_not_existing_comp_lot%FOUND
6062                   CLOSE check_not_existing_comp_lot;
6063                  END IF;  -- item.lot_number IS NOT NULL
6064                END IF;  -- end of IF item.update_wip = 1
6065 
6066 --For ECO cumulative/ECO WIP job/ECO lot              8/2/2000 ---------
6067 -------------------------------------------------------------------------
6068         --
6069         -- Added For 11510+ Enhancement
6070         -- Begin Validations For End-Item-Revision Effectivity
6071         --
6072         If (l_revision_eff_bill = 'Y')
6073         then
6074             -- Validate that from_end_item_revision_id is not null
6075             if (component.from_end_item_rev_id is NULL or component.from_end_item_rev_id <> item.from_end_item_rev_id)
6076             then
6077                 If msg_qty < max_messages
6078                 then
6079                     msg_qty := msg_qty + 1;
6080                     token1(msg_qty) := null;
6081                     value1(msg_qty) := null;
6082                     translate1(msg_qty) := 0;
6083                     token2(msg_qty) := null;
6084                     value2(msg_qty) := null;
6085                     translate2(msg_qty) := 0;
6086                     message_names(msg_qty) := 'ENG_RCOMP_REV_KEYCOL_INVALID';
6087                 end if;
6088                 If trial_mode = no
6089                 then
6090                     Raise abort_implementation;
6091                 end if;
6092             end if;
6093 
6094             -- Validate that from_end_item_revision_id is implemented
6095             if (l_from_revision is NULL)
6096             then
6097                 If msg_qty < max_messages
6098                 then
6099                     msg_qty := msg_qty + 1;
6100                     token1(msg_qty) :=  'ITEM';
6101                     value1(msg_qty) := component.item_number;
6102                     translate1(msg_qty) := 0;
6103                     token2(msg_qty) := 'OP_SEQ_NUM';
6104                     value2(msg_qty) :=  to_char(component.operation_seq_num);
6105                     translate2(msg_qty) := 0;
6106                     message_names(msg_qty) := 'ENG_RCOMP_FROM_REV_UNIMPL';
6107                 end if;
6108                 If trial_mode = no
6109                 then
6110                     Raise abort_implementation;
6111                 end if;
6112             end if;
6113             -- Validate that  to_end_item_revision_id is implemented
6114             l_to_rev_eff_date := null;
6115             l_to_revision := null;
6116             If(component.to_end_item_rev_id is not null)
6117             Then
6118                 Open check_impl_revision(component.to_end_item_rev_id, l_from_end_item_id, item.organization_id);
6119                 Fetch check_impl_revision into l_to_rev_eff_date, l_to_revision;
6120                 Close check_impl_revision;
6121                 if (l_to_revision is NULL)
6122                 then
6123                     If msg_qty < max_messages then
6124                             msg_qty := msg_qty + 1;
6125                             token1(msg_qty) :=  'ITEM';
6126                             value1(msg_qty) := component.item_number;
6127                             translate1(msg_qty) := 0;
6128                             token2(msg_qty) := 'OP_SEQ_NUM';
6129                             value2(msg_qty) :=  to_char(component.operation_seq_num);
6130                             translate2(msg_qty) := 0;
6131                             message_names(msg_qty) := 'ENG_RCOMP_TO_REV_UNIMPL';
6132                     end if;
6133                     If trial_mode = no
6134                     then
6135                         Raise abort_implementation;
6136                     end if;
6137                 end if;
6138             End If;
6139 
6140             -- Validate that Effectivity_date of from_end_item_revision_id is less than the the
6141             -- Effectivity_date of to_end_item_revision_id of the component
6142             If(l_from_revision is not null and l_to_revision is not null
6143                and l_from_revision > l_to_revision)
6144             Then
6145                 If msg_qty < max_messages
6146                 then
6147                     msg_qty := msg_qty + 1;
6148                     token1(msg_qty) :='ITEM';
6149                     value1(msg_qty) := component.item_number;
6150                     translate1(msg_qty) := 0;
6151                     token2(msg_qty) := 'OP_SEQ_NUM';
6152                     value2(msg_qty) := to_char(component.operation_seq_num);
6153                     translate2(msg_qty) := 0;
6154                     message_names(msg_qty) := 'ENG_TOREV_LESSTHAN_FROMREV';
6155                 end if;
6156                 If trial_mode = no
6157                 then
6158                     Raise abort_implementation;
6159                 end if;
6160             End If;
6161 
6162             -- Validate that from_end_item_revision_id is effective i.e its effectivity_date
6163             -- is current or in future
6164 
6165             If(l_current_end_item_revision > l_from_revision)
6166             Then
6167                 If msg_qty < max_messages
6168                 then
6169                     msg_qty := msg_qty + 1;
6170                     token1(msg_qty) := 'ITEM';
6171                     value1(msg_qty) :=  component.item_number;
6172                     translate1(msg_qty) := 0;
6173                     token2(msg_qty) := 'OP_SEQ_NUM';
6174                     value2(msg_qty) :=  to_char(component.operation_seq_num);
6175                     translate2(msg_qty) := 0;
6176                     message_names(msg_qty) := 'ENG_RCOMP_CURRREV_GREATER';
6177                 end if;
6178                 If trial_mode = no
6179                 then
6180                     Raise abort_implementation;
6181                 end if;
6182             End If;
6183         End If;
6184         -- End Validations For End-Item-Revision Effectivity
6185         -- End Changes: 11510+ Enhancement
6186         --
6187 
6188         If component.acd_type in (acd_change, acd_delete)
6189         then
6190             -- Fetch The Old component Details For Validations
6191             Open old_component(component.old_component_sequence_id);
6192             Fetch old_component into old_comp_rec;
6193 
6194 
6195             -- Case 1: Check if old component is implemented
6196             If old_comp_rec.implementation_date is null
6197             then
6198                 If msg_qty < max_messages
6199                 then
6200                     msg_qty := msg_qty + 1;
6201                     message_names(msg_qty) := 'ENG_OLD_COMP_UNIMPLEMENTED';
6202                     token1(msg_qty) := 'ITEM';
6203                     value1(msg_qty) := component.item_number;
6204                     translate1(msg_qty) := 0;
6205                     token2(msg_qty) := null;
6206                     value2(msg_qty) := null;
6207                     translate2(msg_qty) := 0;
6208                 end if;
6209                 If trial_mode = no
6210                 then
6211                     Close old_component;
6212                     Raise abort_implementation;
6213                 end if;
6214 
6215             -- Case 2: Check that the old component is effective for CHANGE/DISABLE
6216             --         that is, the old component has not been disabled
6217             -- Changes Done For : 11510+ Enhancement
6218             elsif old_comp_rec.disable_date is not null
6219             then
6220                 l_disabled_old_comp := 2;
6221                 If (X_UnitEff_RevItem = 'Y' or l_revision_eff_bill = 'Y')
6222                 Then
6223                     l_disabled_old_comp := 1;
6224                 Elsif (old_comp_rec.disable_date < eff_date)
6225                 Then
6226                     l_disabled_old_comp := 1;
6227                 End If;
6228                 If( l_disabled_old_comp = 1)
6229                 Then
6230                     If msg_qty < max_messages
6231                     then
6232                         msg_qty := msg_qty + 1;
6233                         message_names(msg_qty) := 'ENG_OLD_COMP_DISABLED';
6234                         token1(msg_qty) := 'ITEM';
6235                         value1(msg_qty) := component.item_number;
6236                         translate1(msg_qty) := 0;
6237                         token2(msg_qty) := null;
6238                         value2(msg_qty) := null;
6239                         translate2(msg_qty) := 0;
6240                     end if;
6241                     If trial_mode = no
6242                     then
6243                         Close old_component;
6244                         Raise abort_implementation;
6245                     end if;
6246                 End If;
6247             -- Case 3: Check the effectivity for date effective structures
6248             elsif (old_comp_rec.effectivity_date > eff_date and X_UnitEff_RevItem = 'N' AND l_revision_eff_bill = 'N')
6249             then
6250                 If msg_qty < max_messages
6251                 then
6252                     msg_qty := msg_qty + 1;
6253                     message_names(msg_qty) := 'ENG_OLD_COMP_INEFFECTIVE';
6254                     token1(msg_qty) := 'ITEM';
6255                     value1(msg_qty) := component.item_number;
6256                     translate1(msg_qty) := 0;
6257                     token2(msg_qty) := null;
6258                     value2(msg_qty) := null;
6259                     translate2(msg_qty) := 0;
6260                 end if;
6261                 If trial_mode = no
6262                 then
6263                     Close old_component;
6264                     Raise abort_implementation;
6265                 end if;
6266 
6267             -- Changes Done For : 11510+ Enhancement
6268             -- Case 4: Validate that the from_end_item_revision of revised component
6269             --                         > from_end_item_revision of the old component
6270             --                     and < to_end_item_revision of the old component
6271             elsIf(l_revision_eff_bill = 'Y')
6272             Then
6273                 l_valid_from_to_revision := 2;
6274                 Open check_from_to_revision (l_from_rev_eff_date, old_comp_rec.component_sequence_id);
6275                 Fetch check_from_to_revision into l_valid_from_to_revision;
6276                 Close check_from_to_revision;
6277                 If (l_valid_from_to_revision = 2)
6278                 Then
6279                     If msg_qty < max_messages
6280                     then
6281                         msg_qty := msg_qty + 1;
6282                         message_names(msg_qty) := 'ENG_RCOMP_REV_NOTIN_OLDRANGE';
6283                         token1(msg_qty) := 'ITEM';
6284                         value1(msg_qty) := component.item_number;
6285                         translate1(msg_qty) := 0;
6286                         token2(msg_qty) := null;
6287                         value2(msg_qty) := null;
6288                         translate2(msg_qty) := 0;
6289                     end if;
6290                     If trial_mode = no
6291                     then
6292                         Close old_component;
6293                         Raise abort_implementation;
6294                     end if;
6295                 End If;
6296 
6297             -- If all validations passed, then set the old component record details
6298             ELSE
6299                 -- added for eco enhancement
6300                 count_comp_disable := count_comp_disable + 1;
6301                 rev_comp_disable_date_tbl(count_comp_disable).revised_item_id  := item.revised_item_id;
6302                 rev_comp_disable_date_tbl(count_comp_disable).component_seq_id :=
6303                                                            component.old_component_sequence_id;
6304                 rev_comp_disable_date_tbl(count_comp_disable).disable_date     := old_comp_rec.disable_date;
6305 
6306 
6307                 old_comp_rec.disable_date := eff_date;
6308                 /* Bug 2441062. disable_date should be a second lesser than eff_date
6309                    to avoid overlapping effectivity within the same component
6310 		   The above change has been reverted for this bug 5622459
6311 		   */
6312                 IF component.acd_type = acd_change
6313                 THEN
6314                     -- Set disable_date
6315                      /*bug 5622459
6316 		     old_comp_rec.disable_date := eff_date-((1/1440)/60);
6317 		     */
6318                     -- Set overlapping_changes
6319                     IF component.overlapping_changes = 1
6320                     THEN
6321                         old_comp_rec.overlapping_changes := 1;
6322                     END IF;
6323                 ELSE
6324                     old_comp_rec.disable_date := eff_date;
6325                 END IF;
6326                 -- Added for structure revision
6327                 -- Set to_object_revision_id
6328                 IF (old_comp_rec.from_object_revision_id is not null
6329                     AND item.new_structure_revision is not null
6330                     AND old_comp_rec.to_object_revision_id is NULL)
6331                 THEN
6332                      old_comp_rec.to_object_revision_id := X_prev_structure_revision_id;
6333                 END IF;
6334                 -- Set change_notice
6335                 IF item.eco_for_production = 2
6336                 THEN
6337                     old_comp_rec.change_notice := item.change_notice;
6338                 END IF;
6339             end if;
6340             -- End of Validations
6341 
6342             If component.acd_type = acd_delete
6343             then
6344                 component.disable_date := eff_date;
6345             end if;
6346             -- Unit Effectivity implementation
6347             If (X_UnitEff_RevItem = 'Y')
6348             then
6349                 -- Disable the old component by populating disable_date, if
6350                 -- the change/disable is for whole range starting from the
6351                 -- from_unit_number of the old component.
6352                 -- Else, update the to_unit_number of the old comp with the prev
6353                 -- unit number of the new comp's from_unit_number.
6354                 -- Need to be enhanced for spliting.
6355                 if (component.from_end_item_unit_number = old_comp_rec.from_end_item_unit_number)
6356                 then
6357                     /*bug 5622459
6358 		    IF component.acd_type = acd_change
6359                     THEN
6360                         old_comp_rec.disable_date := eff_date-((1/1440)/60);
6361                     ELSE*/
6362                     old_comp_rec.disable_date := eff_date;
6363                     --END IF;
6364 
6365                     Update bom_components_b --bom_inventory_components
6366                     set disable_date = old_comp_rec.disable_date,
6367                     to_object_revision_id = old_comp_rec.to_object_revision_id,
6368                     overlapping_changes = old_comp_rec.overlapping_changes,
6369                     change_notice = old_comp_rec.change_notice,
6370                     implementation_date = today,
6371                     last_update_date = sysdate,
6372                     last_updated_by = userid,
6373                     last_update_login = loginid,
6374                     request_id = reqstid,
6375                     program_application_id = appid,
6376                     program_id = progid,
6377                     program_update_date = sysdate
6378                     where component_sequence_id = old_comp_rec.component_sequence_id;
6379                 else
6380                     X_prev_unit_number := PJM_UNIT_EFF.Prev_unit_number(X_unit_number => component.from_end_item_unit_number);
6381                     if (X_prev_unit_number is NULL)
6382                     then
6383                         X_prev_unit_number := component.from_end_item_unit_number;
6384                     end if;
6385                     if (X_prev_unit_number < old_comp_rec.from_end_item_unit_number)
6386                     then
6387                         If msg_qty < max_messages
6388                         then
6389                             msg_qty := msg_qty + 1;
6390                             message_names(msg_qty) := 'ENG_TOUNIT_LESSTHAN_FROMUNIT';
6391                             token1(msg_qty) := 'ITEM';
6392                             value1(msg_qty) := component.item_number;
6393                             translate1(msg_qty) := 0;
6394                             token2(msg_qty) := 'OP_SEQ_NUM';
6395                             value2(msg_qty) := to_char(component.operation_seq_num);
6396                             translate2(msg_qty) := 0;
6397                         end if;
6398                         If trial_mode = no
6399                         then
6400                             Raise abort_implementation;
6401                         end if;
6402                     end if;
6403 
6404                     Update bom_components_b --bom_inventory_components
6405                     set to_end_item_unit_number = X_prev_unit_number,
6406                     to_object_revision_id = old_comp_rec.to_object_revision_id,
6407                     overlapping_changes = old_comp_rec.overlapping_changes,
6408                     change_notice = old_comp_rec.change_notice,
6409                     implementation_date = today,
6410                     last_update_date = sysdate,
6411                     last_updated_by = userid,
6412                     last_update_login = loginid,
6413                     request_id = reqstid,
6414                     program_application_id = appid,
6415                     program_id = progid,
6416                     program_update_date = sysdate
6417                     where component_sequence_id =
6418                           old_comp_rec.component_sequence_id;
6419                 end if;
6420             ELSIF (l_revision_eff_bill = 'Y')
6421             THEN
6422                 -- Disable the old component by populating disable_date, if
6423                 -- the change/disable is for whole range starting from the
6424                 -- from_unit_number of the old component.
6425                 -- Else, update the to_unit_number of the old comp with the prev
6426                 -- unit number of the new comp's from_unit_number.
6427                 -- Need to be enhanced for spliting.
6428                 if (component.from_end_item_rev_id = old_comp_rec.from_end_item_rev_id)
6429                 then
6430 		/* bug 5622459. 1 sec difference is removed
6431                     IF component.acd_type = acd_change
6432                     THEN
6433                         old_comp_rec.disable_date := eff_date-((1/1440)/60);
6434                     ELSE*/
6435                     old_comp_rec.disable_date := eff_date;
6436                     --END IF;
6437 
6438                     Update bom_components_b --bom_inventory_components
6439                     set disable_date = old_comp_rec.disable_date,
6440                     to_object_revision_id = old_comp_rec.to_object_revision_id,
6441                     overlapping_changes = old_comp_rec.overlapping_changes,
6442                     change_notice = old_comp_rec.change_notice,
6443                     implementation_date = today,
6444                     last_update_date = sysdate,
6445                     last_updated_by = userid,
6446                     last_update_login = loginid,
6447                     request_id = reqstid,
6448                     program_application_id = appid,
6449                     program_id = progid,
6450                     program_update_date = sysdate
6451                     where component_sequence_id = old_comp_rec.component_sequence_id;
6452                 else
6453                     l_prev_end_item_rev_id := NULL;
6454                     OPEN get_prev_impl_revision(l_from_end_item_id,
6455                                                 item.organization_id,
6456                                                 l_from_rev_eff_date);
6457                     FETCH get_prev_impl_revision INTO l_prev_end_item_rev_id, l_prev_end_item_eff;
6458                     CLOSE get_prev_impl_revision;
6459                     IF (l_prev_end_item_rev_id is NULL)
6460                     THEN
6461                         l_prev_end_item_rev_id := component.from_end_item_rev_id;
6462                         l_prev_end_item_eff := l_from_rev_eff_date;
6463                     END IF;
6464                     l_valid_from_to_revision := 2;
6465                     Open check_from_to_revision (l_prev_end_item_eff, old_comp_rec.component_sequence_id);
6466                     Fetch check_from_to_revision into l_valid_from_to_revision;
6467                     Close check_from_to_revision;
6468                     IF (l_valid_from_to_revision = 2)
6469                     Then
6470                         If msg_qty < max_messages
6471                         then
6472                             msg_qty := msg_qty + 1;
6473                             message_names(msg_qty) := 'ENG_TOREV_LESSTHAN_FROMREV';
6474                             token1(msg_qty) := 'ITEM';
6475                             value1(msg_qty) := component.item_number;
6476                             translate1(msg_qty) := 0;
6477                             token2(msg_qty) := 'OP_SEQ_NUM';
6478                             value2(msg_qty) := to_char(component.operation_seq_num);
6479                             translate2(msg_qty) := 0;
6480                         end if;
6481                         If trial_mode = no
6482                         then
6483                             Raise abort_implementation;
6484                         end if;
6485                     end if;
6486 
6487                     Update bom_components_b --bom_inventory_components
6488                     set to_end_item_rev_id = l_prev_end_item_rev_id,
6489                     to_object_revision_id = old_comp_rec.to_object_revision_id,
6490                     overlapping_changes = old_comp_rec.overlapping_changes,
6491                     change_notice = old_comp_rec.change_notice,
6492                     implementation_date = today,
6493                     last_update_date = sysdate,
6494                     last_updated_by = userid,
6495                     last_update_login = loginid,
6496                     request_id = reqstid,
6497                     program_application_id = appid,
6498                     program_id = progid,
6499                     program_update_date = sysdate
6500                     where component_sequence_id = old_comp_rec.component_sequence_id;
6501                 end if;
6502             else
6503              --Added to reflect correct disable date in old component.
6504 	     /*added case
6505 	     case 1: S1 => C1 (Q= 1 ,eff= D1) changed to S1 => C1 (Q= 10 ,eff= D1)  [D1 = future date] is supported.
6506 	     in this case while implemention put disable date same as eff date in old comp.
6507 	     initailly overlapping error used to come*/
6508 
6509 	     /* --bug 5622459 1 sec difference is removed
6510 		  IF component.acd_type = acd_change
6511                   THEN
6512 			IF old_comp_rec.effectivity_date =  eff_date
6513 			THEN
6514 			old_comp_rec.disable_date := eff_date;
6515 			 ELSE
6516                             old_comp_rec.disable_date := eff_date-((1/1440)/60);
6517 			 END IF;
6518                   ELSE
6519                         old_comp_rec.disable_date := eff_date;
6520                   END IF;*/
6521 		old_comp_rec.disable_date := eff_date; --bug 5622459
6522                 l_old_disable_date  :=   old_comp_rec.disable_date;
6523                 -- Date effectivity implementation
6524                 Update bom_components_b --bom_inventory_components
6525                 set disable_date = old_comp_rec.disable_date,
6526                 to_object_revision_id = old_comp_rec.to_object_revision_id,
6527                 overlapping_changes = old_comp_rec.overlapping_changes,
6528                 change_notice = old_comp_rec.change_notice,
6529                 last_update_date = sysdate,
6530                 last_updated_by = userid,
6531                 last_update_login = loginid,
6532                 request_id = reqstid,
6533                 program_application_id = appid,
6534                 program_id = progid,
6535                 program_update_date = sysdate
6536                 -- where current of old_component;
6537                 where component_sequence_id = old_comp_rec.component_sequence_id;
6538             end if;
6539             -----------------------------------------------------------
6540             -- R12: Changes for Common BOM Enhancement
6541             -- Step 2: Update related old components
6542             --         Move/Copy pending changes on old component to new.
6543             -- Pending changes for WIP attributes could have been created
6544             -- on the implemented old component on the destination bill
6545             -- These need to be updated to reference the new component
6546             -- Since the effectivity date is not a modifiable attribute on
6547             -- the destination bill's component change records , the pending
6548             -- changes derive their old components effectivities only.
6549             -- So if the oldcomponent is disable date is future effective, then
6550             -- pending changes are copied from the old to the new refenced
6551             -- component in the destination bill
6552             -- They are copied otherwise.
6553             -----------------------------------------------------------
6554             IF isCommonedBOM = 'Y'
6555             THEN
6556                 IF component.acd_type = acd_change
6557                 THEN
6558                     -- if the old component is being disabled as of not
6559                     -- or the old component was future effective but is being disabled as of the
6560                     -- same date then we move the pending changes to the new component.
6561                     IF eff_date <= SYSDATE OR old_comp_rec.disable_date <= old_comp_rec.effectivity_date
6562                     THEN
6563                         Move_Pending_Dest_Components(
6564                             p_src_old_comp_seq_id      => old_comp_rec.component_sequence_id
6565                           , p_src_comp_seq_id          => component.component_sequence_id
6566                           , p_change_notice            => item.change_notice
6567                           , p_revised_item_sequence_id => item.revised_item_sequence_id
6568                           , p_effectivity_date         => eff_date
6569                           , p_eco_for_production       => item.eco_for_production
6570                           , x_return_status            => l_comn_return_status);
6571                     ELSE
6572                         BOMPCMBM.Copy_Pending_Dest_Components(
6573                             p_src_old_comp_seq_id      => old_comp_rec.component_sequence_id
6574                           , p_src_comp_seq_id          => component.component_sequence_id
6575                           , p_change_notice            => item.change_notice
6576                           , p_organization_id          => item.organization_id
6577                           , p_revised_item_sequence_id => item.revised_item_sequence_id
6578                           , p_effectivity_date         => eff_date
6579                           , x_return_status            => l_comn_return_status);
6580                     END IF;
6581                     If ( l_comn_return_status <> 'S')
6582                     Then
6583                         If msg_qty < max_messages
6584                         then
6585                             msg_qty := msg_qty + 1;
6586                             message_names(msg_qty) := 'ENG_COM_COMP_UPDATE_FAILED';
6587                             token1(msg_qty) := 'ITEM';
6588                             value1(msg_qty) := component.item_number;
6589                             translate1(msg_qty) := 0;
6590                             token2(msg_qty) := null;
6591                             value2(msg_qty) := null;
6592                             translate2(msg_qty) := 0;
6593                         end if;
6594                         If trial_mode = no
6595                         then
6596                             Close old_component;
6597                             Raise abort_implementation;
6598                         end if;
6599                     End If;
6600                 END IF;
6601 
6602                 BOMPCMBM.Update_Related_Components(
6603                     p_src_comp_seq_id => old_comp_rec.component_sequence_id
6604                   , x_Mesg_Token_Tbl  => l_comn_mesg_token_tbl
6605                   , x_Return_Status   => l_comn_return_status);
6606                 If ( l_comn_return_status <> 'S')
6607                 Then
6608                     If msg_qty < max_messages
6609                     then
6610                         msg_qty := msg_qty + 1;
6611                         message_names(msg_qty) := 'ENG_COM_COMP_UPDATE_FAILED';
6612                         token1(msg_qty) := 'ITEM';
6613                         value1(msg_qty) := component.item_number;
6614                         translate1(msg_qty) := 0;
6615                         token2(msg_qty) := null;
6616                         value2(msg_qty) := null;
6617                         translate2(msg_qty) := 0;
6618                     end if;
6619                     If trial_mode = no
6620                     then
6621                         Close old_component;
6622                         Raise abort_implementation;
6623                     end if;
6624                 End If;
6625                 -- added here, for the R12 change management for common  bom
6626             END IF;
6627             -----------------------------------------------------------
6628             -- R12: End Step 2: End Changes for Common BOM Enhancement --
6629             -----------------------------------------------------------
6630 
6631             Close old_component;
6632         end if; -- old components
6633 
6634         --
6635         --  Check for duplicate value on unique index (avoid overlapping effectivity)
6636         --
6637         /* No need to perform the overlap check for the component row which has acd_type as
6638            delete since this row will be deleted from the inventory_components table at the
6639            end if implementation */
6640         IF component.acd_type <> acd_delete
6641         THEN
6642             -- Initialize
6643             l_overlap_found := 2;
6644 
6645             -- Check for Unit Effectivity implementation
6646             If (X_UnitEff_RevItem = 'Y')
6647             then
6648                 Open check_existing_unit(
6649                         X_bill => item.bill_sequence_id,
6650                         X_component => component.component_item_id,
6651                         X_operation => component.operation_seq_num,
6652                         X_comp_seq_id => component.component_sequence_id,
6653                         X_from_unit_number => component.from_end_item_unit_number,
6654                         X_to_unit_number   => component.to_end_item_unit_number);
6655                 Fetch check_existing_unit into dummy;
6656                 If check_existing_unit%found
6657                 then
6658                     l_overlap_found := 1;
6659                 end if;
6660                 Close check_existing_unit;
6661             -- Check For End-Item-Revision Effectivity
6662             -- 11510+ Enhancement
6663             elsIf(l_revision_eff_bill = 'Y')
6664             Then
6665                 Open check_existing_rev_eff_comp
6666                         ( cp_bill_id           => item.bill_sequence_id
6667                         , cp_component_item_id => component.component_item_id
6668                         , cp_operation_seq_num => component.operation_seq_num
6669                         , cp_end_item_id       => l_from_end_item_id
6670                         , cp_org_id            => item.organization_id
6671                         , cp_from_rev_eff      => l_from_rev_eff_date
6672                         , cp_to_rev_eff        => l_to_rev_eff_date );
6673                 Fetch check_existing_rev_eff_comp into l_overlap_found;
6674                 Close check_existing_rev_eff_comp;
6675             else
6676             -- Check for Date effectivity implementation
6677                 Open check_existing_component(
6678                         X_bill => item.bill_sequence_id,
6679                         X_component => component.component_item_id,
6680                         X_operation => component.operation_seq_num,
6681                         X_comp_seq_id => component.component_sequence_id,
6682                         X_disable_date => component.disable_date,
6683 			X_old_comp_seq_id => component.old_component_sequence_id,
6684 			X_old_rec_disable_date => l_old_disable_date );
6685                 Fetch check_existing_component into dummy;
6686                 If check_existing_component%found
6687                 then
6688                     l_overlap_found := 1;
6689                 end if;
6690                 Close check_existing_component;
6691             end if;
6692             -- If overlapping Effectivity Found then Raise Error
6693             If l_overlap_found = 1
6694             Then
6695                 If msg_qty < max_messages
6696                 then
6697                     msg_qty := msg_qty + 1;
6698                     message_names(msg_qty) := 'ENG_COMPONENT_ALREADY_EXISTS';
6699                     token1(msg_qty) := 'ITEM';
6700                     value1(msg_qty) := component.item_number;
6701                     translate1(msg_qty) := 0;
6702                     token2(msg_qty) := 'OP';
6703                     value2(msg_qty) := to_char(component.operation_seq_num);
6704                     translate2(msg_qty) := 0;
6705                 end if;
6706                 If trial_mode = no then
6707                         Raise abort_implementation;
6708                 end if;
6709             End If;
6710         END IF;
6711         -- End of Check for duplicate values on unique Index (Overlapping Effectivities)
6712 
6713         If component.acd_type = acd_change then
6714           -- Bug 4584490: Changes for Bom Business Events
6715           -- Check if there exists and substitue comps/ ref desigs
6716           -- on the component
6717           BEGIN
6718               IF item.eco_for_production = 2
6719               THEN
6720                   l_Comp_Child_Entity_Modified := NULL;
6721                   OPEN c_Comp_Child_Entity_Modified(component.component_sequence_id);
6722                   FETCH c_Comp_Child_Entity_Modified INTO l_Comp_Child_Entity_Modified;
6723                   CLOSE c_Comp_Child_Entity_Modified;
6724                   IF l_Comp_Child_Entity_Modified IS NOT NULL
6725                   THEN
6726                       Bom_Business_Event_PKG.Raise_Component_Event(
6727                           p_bill_sequence_Id => item.bill_sequence_id
6728                         , p_pk1_value        => component.component_item_id
6729                         , p_pk2_value        => item.organization_id
6730                         , p_obj_name         => component.obj_name
6731                         , p_organization_id  => item.organization_id
6732                         , p_comp_item_name   => component.item_number
6733                         , p_comp_description => component.component_remarks
6734                         , p_Event_Name       => Bom_Business_Event_PKG.G_COMPONENT_MODIFIED_EVENT
6735                         );
6736                   END IF;
6737               END IF;
6738           EXCEPTION
6739           WHEN OTHERS THEN
6740               null;
6741               -- nothing is required to be done, process continues
6742           END;
6743           -- End changes for Bug 4584490
6744 
6745  -- Bug 5854437 Start
6746   For sub_component in chng_sub_component_rows loop
6747                 Open check_existing_substitutes(X_old_comp_seq_id => sub_component.old_component_sequence_id,
6748                                                                      X_sub_comp_id => sub_component.substitute_component_id,
6749                                                                      X_change_notice => item.change_notice);
6750                 Fetch check_existing_substitutes into dummy;
6751 
6752                 If check_existing_substitutes%found then
6753               rec_exist:=0;
6754               BEGIN
6755                 SELECT bsc.acd_type into rec_exist
6756                 FROM   Bom_Inventory_Components bic,
6757                            BOM_SUBSTITUTE_COMPONENTS bsc
6758                 WHERE  bic.Old_Component_Sequence_Id = sub_component.old_component_sequence_id
6759                         AND    bic.Change_Notice = item.change_notice
6760                         AND    bic.Implementation_Date IS NULL
6761                         AND    bsc.component_sequence_id = bic.component_sequence_id
6762                         AND    bsc.substitute_component_id =  sub_component.substitute_component_id
6763                         AND    bsc. ACD_TYPE = acd_delete;
6764               EXCEPTION
6765                         WHEN NO_DATA_FOUND THEN
6766                                 NULL;
6767               END;
6768                    If rec_exist <> acd_delete then
6769                            rec_exist := 0;
6770                         If msg_qty < max_messages then
6771                                msg_qty := msg_qty + 1;
6772                                 message_names(msg_qty) :=
6773                                         'ENG_SUB_COMP_ALREADY_EXISTS';
6774                                 token1(msg_qty) := 'SUBSTITUTE_ITEM_NAME';
6775                                 value1(msg_qty) := sub_component.item_number;
6776                                 translate1(msg_qty) := 0;
6777                                 token2(msg_qty) := 'REVISED_COMPONENT_NAME';
6778                                 value2(msg_qty) := component.item_number;
6779                                 translate2(msg_qty) := 0;
6780 
6781                         end if;
6782         FND_MESSAGE.Set_Name('ENG','ENG_SUB_COMP_ALREADY_EXISTS');
6783         FND_MESSAGE.Set_Token('SUBSTITUTE_ITEM_NAME',sub_component.item_number) ;
6784         FND_MESSAGE.Set_Token('REVISED_COMPONENT_NAME',component.item_number) ;
6785         FND_MSG_PUB.Add;
6786         FND_MSG_PUB.Count_And_Get(p_encoded => FND_API.G_FALSE, p_count => l_error_msg_count , p_data => l_message);
6787 FND_FILE.put_line(FND_FILE.LOG, l_message);
6788                         If trial_mode = no then
6789                                 Close check_existing_substitutes;
6790                                 Raise abort_implementation;
6791                         end if;
6792                    end if;
6793                 end if;
6794              Close check_existing_substitutes;
6795   end loop;
6796 
6797 -- Bug 5854437 End
6798 
6799 
6800                -- Copy substitute components
6801                Insert into bom_substitute_components(
6802                    substitute_component_id,
6803                    last_update_date,
6804                    last_updated_by,
6805                    creation_date,
6806                    created_by,
6807                    last_update_login,
6808                    substitute_item_quantity,
6809                    component_sequence_id,
6810                    acd_type,
6811                    change_notice,
6812                    request_id,
6813                    program_application_id,
6814                    program_id,
6815                    program_update_date,
6816                    attribute_category,
6817                    attribute1,
6818                    attribute2,
6819                    attribute3,
6820                    attribute4,
6821                    attribute5,
6822                    attribute6,
6823                    attribute7,
6824                    attribute8,
6825                    attribute9,
6826                    attribute10,
6827                    attribute11,
6828                    attribute12,
6829                    attribute13,
6830                    attribute14,
6831                    attribute15)
6832                select
6833                    substitute_component_id,
6834                    last_update_date,
6835                    last_updated_by,
6836                    creation_date,
6837                    created_by,
6838                    last_update_login,
6839                    substitute_item_quantity,
6840                    component.component_sequence_id, -- new component
6841                    acd_type,
6842                    change_notice, --null, bug 5174519
6843                    request_id,
6844                    program_application_id,
6845                    program_id,
6846                    program_update_date,
6847                    attribute_category,
6848                    attribute1,
6849                    attribute2,
6850                    attribute3,
6851                    attribute4,
6852                    attribute5,
6853                    attribute6,
6854                    attribute7,
6855                    attribute8,
6856                    attribute9,
6857                    attribute10,
6858                    attribute11,
6859                    attribute12,
6860                    attribute13,
6861                    attribute14,
6862                    attribute15
6863                from bom_substitute_components
6864                where component_sequence_id =
6865                         component.old_component_sequence_id
6866                and   nvl(acd_type, acd_add) = acd_add
6867                and   substitute_component_id not in (
6868                         select substitute_component_id
6869                         from bom_substitute_components
6870                         where component_sequence_id =
6871                               component.component_sequence_id);
6872            -- Copy reference designators
6873               Insert into bom_reference_designators (
6874                  component_reference_designator,
6875                  last_update_date,
6876                  last_updated_by,
6877                  creation_date,
6878                  created_by,
6879                  last_update_login,
6880                  ref_designator_comment,
6881                  change_notice,
6882                  component_sequence_id,
6883                  acd_type,
6884                  request_id,
6885                  program_application_id,
6886                  program_id,
6887                  program_update_date,
6888                  attribute_category,
6889                  attribute1,
6890                  attribute2,
6891                  attribute3,
6892                  attribute4,
6893                  attribute5,
6894                  attribute6,
6895                  attribute7,
6896                  attribute8,
6897                  attribute9,
6898                  attribute10,
6899                  attribute11,
6900                  attribute12,
6901                  attribute13,
6902                  attribute14,
6903                  attribute15)
6904               select
6905                  component_reference_designator,
6906                  last_update_date,
6907                  last_updated_by,
6908                  creation_date,
6909                  created_by,
6910                  last_update_login,
6911                  ref_designator_comment,
6912                  change_notice, --null, bug 5174519
6913                  component.component_sequence_id, -- new component
6914                  acd_type,
6915                  request_id,
6916                  program_application_id,
6917                  program_id,
6918                  program_update_date,
6919                  attribute_category,
6920                  attribute1,
6921                  attribute2,
6922                  attribute3,
6923                  attribute4,
6924                  attribute5,
6925                  attribute6,
6926                  attribute7,
6927                  attribute8,
6928                  attribute9,
6929                  attribute10,
6930                  attribute11,
6931                  attribute12,
6932                  attribute13,
6933                  attribute14,
6934                  attribute15
6935             from bom_reference_designators
6936             where component_sequence_id =
6937                      component.old_component_sequence_id
6938             and   nvl(acd_type, acd_add) = acd_add -- adds only
6939             and   component_reference_designator not in (
6940                   select component_reference_designator
6941                   from bom_reference_designators
6942                   where component_sequence_id =
6943                         component.component_sequence_id);
6944         end if; -- Copy component's children
6945 
6946         If component.acd_type in (acd_add, acd_change) and
6947         component.quantity_related = yes then
6948             Open count_ref_designators(component.component_sequence_id);
6949             Fetch count_ref_designators into ref_designator_count;
6950             Close count_ref_designators;
6951             If component.component_quantity <> ref_designator_count then
6952                 If msg_qty < max_messages then
6953                         msg_qty := msg_qty + 1;
6954                         message_names(msg_qty) := 'ENG_QUANTITY_RELATED_2';
6955                         token1(msg_qty) := 'ITEM';
6956                         value1(msg_qty) := component.item_number;
6957                         translate1(msg_qty) := 0;
6958                         token2(msg_qty) := null;
6959                         value2(msg_qty) := null;
6960                         translate2(msg_qty) := 0;
6961                 end if;
6962                 If trial_mode = no then
6963                         Raise abort_implementation;
6964                 end if;
6965             end if;
6966         end if; -- reference designator count
6967 
6968         -- Check fractional component quantities if OE is installed
6969         -- and the revised item is PTO
6970 
6971         If component.acd_type in (acd_add, acd_change) and
6972            X_InstallStatus = 'I' and
6973            item.pick_components_flag = 'Y' and
6974            component.component_quantity <> trunc(component.component_quantity)
6975         then
6976                 If msg_qty < max_messages then
6977                         msg_qty := msg_qty + 1;
6978                         message_names(msg_qty) := 'ENG_FRACTIONAL_QTY';
6979                         token1(msg_qty) := 'ITEM';
6980                         value1(msg_qty) := component.item_number;
6981                         translate1(msg_qty) := 0;
6982                         token2(msg_qty) := null;
6983                         value2(msg_qty) := null;
6984                         translate2(msg_qty) := 0;
6985                 end if;
6986                 If trial_mode = no then
6987                         Raise abort_implementation;
6988                 end if;
6989         end if;
6990 
6991         -- added for structure revision
6992         If component.acd_type in (acd_add, acd_change) then
6993                 IF item.new_structure_revision is not null THEN
6994                           component.from_object_revision_id := X_new_structure_revision_id;
6995                 END IF;
6996                 IF component.overlapping_changes = 1 THEN
6997                           component.overlapping_changes := null;
6998                 END IF;
6999         end if;
7000 
7001         Update bom_components_b--bom_inventory_components
7002         set implementation_date = today,
7003             change_notice = item.change_notice,
7004             disable_date = component.disable_date,
7005             effectivity_date = eff_date,
7006             from_object_revision_id = component.from_object_revision_id,
7007             overlapping_changes = component.overlapping_changes,
7008             last_update_date = sysdate,
7009             last_updated_by = userid,
7010             last_update_login = loginid,
7011             request_id = reqstid,
7012             program_application_id = appid,
7013             program_id = progid,
7014             program_update_date = sysdate
7015         -- where current of chng_component_rows;
7016         where component_sequence_id = component.component_sequence_id;
7017         -----------------------------------------------------------
7018         -- R12: Changes for Common BOM Enhancement
7019         -- Step 3: Implementing Referenced Pending Destination Components
7020         --         And Copy the Component's children to the Implemented Component
7021         -- Whether update attributes is requred from src to destination again ?
7022         -- Not done as any UI updates will maintain the attrs in sync
7023         -----------------------------------------------------------
7024         IF isCommonedBOM = 'Y'
7025         THEN
7026             UPDATE bom_components_b--bom_inventory_components
7027                SET implementation_date = today,
7028                    change_notice       = item.change_notice,
7029                    disable_date        = component.disable_date,
7030                    effectivity_date    = eff_date,
7031                    overlapping_changes = component.overlapping_changes,
7032                    last_update_date    = sysdate,
7033                    last_updated_by     = userid,
7034                    last_update_login   = loginid,
7035                    request_id          = reqstid,
7036                    program_application_id = appid,
7037                    program_id          = progid,
7038                    program_update_date = sysdate
7039              WHERE common_component_sequence_id = component.component_sequence_id
7040                AND common_component_sequence_id <> component_sequence_id
7041                AND implementation_date IS NULL
7042                AND change_notice = item.change_notice
7043                AND revised_item_sequence_id = item.revised_item_sequence_id;
7044 
7045             -- Update related components to set the effectivity and the disable date attributes
7046             -- as set above.
7047             -- This is a repitition of the move/copy related pending destination changes
7048             -- in the destination bill to the newly implemented component that is created
7049             -- as a reference in the destination bills.
7050             BOMPCMBM.Update_Related_Components(
7051                 p_src_comp_seq_id => component.component_sequence_id
7052               , x_Mesg_Token_Tbl  => l_comn_mesg_token_tbl
7053               , x_Return_Status   => l_comn_return_status);
7054             If ( l_comn_return_status <> 'S')
7055             Then
7056                 If msg_qty < max_messages
7057                 then
7058                     msg_qty := msg_qty + 1;
7059                     message_names(msg_qty) := 'ENG_COM_COMP_UPDATE_FAILED';
7060                     token1(msg_qty) := 'ITEM';
7061                     value1(msg_qty) := component.item_number;
7062                     translate1(msg_qty) := 0;
7063                     token2(msg_qty) := null;
7064                     value2(msg_qty) := null;
7065                     translate2(msg_qty) := 0;
7066                 end if;
7067                 If trial_mode = no
7068                 then
7069                     Close old_component;
7070                     Raise abort_implementation;
7071                 end if;
7072             End If;
7073 
7074             -- Copy the components children to the referneced components
7075             -- implemented just above statement
7076             BOMPCMBM.Replicate_Ref_Desg(
7077                 p_component_sequence_id => component.component_sequence_id
7078               , x_Mesg_Token_Tbl        => l_comn_mesg_token_tbl
7079               , x_Return_Status         => l_comn_return_status);
7080             BOMPCMBM.Replicate_Sub_Comp(
7081                 p_component_sequence_id => component.component_sequence_id
7082               , x_Mesg_Token_Tbl        => l_comn_mesg_token_tbl
7083               , x_Return_Status         => l_comn_return_status);
7084         END IF;
7085         -----------------------------------------------------------
7086         -- R12: End Step 3: Changes for Common BOM Enhancement --
7087         -----------------------------------------------------------
7088 
7089 --
7090 -- Update all unimplemented rows that point to the old row, so that they now
7091 -- point to the new component row.
7092 --
7093 
7094         If component.acd_type = acd_change then
7095            IF item.eco_for_production = 2 Then
7096             Update bom_components_b--bom_inventory_components
7097             set    old_component_sequence_id = component.component_sequence_id,
7098                    last_update_date = sysdate,
7099                    last_updated_by = userid,
7100                    last_update_login = loginid,
7101                    request_id = reqstid,
7102                    program_application_id = appid,
7103                    program_id = progid,
7104                    program_update_date = sysdate
7105             where  old_component_sequence_id =
7106                    component.old_component_sequence_id
7107             and    implementation_date is null;
7108             --
7109             -- Here , the common Components are NOT being updated as they have been
7110             -- taken care of in the Step 1 of updation of pending desination changes.
7111             --
7112           END IF;
7113         end if; -- reset pointers
7114 
7115 --
7116 --  Copy all implemented components to eng_revised_components.
7117 --
7118 
7119         Insert into eng_revised_components(
7120                 component_sequence_id,
7121                 component_item_id,
7122                 operation_sequence_num,
7123                 bill_sequence_id,
7124                 change_notice,
7125                 effectivity_date,
7126                 component_quantity,
7127                 component_yield_factor,
7128                 last_update_date,
7129                 last_updated_by,
7130                 creation_date,
7131                 created_by,
7132                 last_update_login,
7133                 old_component_sequence_id,
7134                 item_num,
7135                 wip_supply_type,
7136                 component_remarks,
7137                 supply_subinventory,
7138                 supply_locator_id,
7139                 implementation_date,
7140                 disable_date,
7141                 acd_type,
7142                 planning_factor,
7143                 quantity_related,
7144                 so_basis,
7145                 optional,
7146                 mutually_exclusive_options,
7147                 include_in_cost_rollup,
7148                 check_atp,
7149                 shipping_allowed,
7150                 required_to_ship,
7151                 required_for_revenue,
7152                 include_on_ship_docs,
7153                 include_on_bill_docs,
7154                 low_quantity,
7155                 high_quantity,
7156                 attribute_category,
7157                 attribute1,
7158                 attribute2,
7159                 attribute3,
7160                 attribute4,
7161                 attribute5,
7162                 attribute6,
7163                 attribute7,
7164                 attribute8,
7165                 attribute9,
7166                 attribute10,
7167                 attribute11,
7168                 attribute12,
7169                 attribute13,
7170                 attribute14,
7171                 attribute15,
7172                 request_id,
7173                 program_application_id,
7174                 program_id,
7175                 program_update_date,
7176                 revised_item_sequence_id,
7177                 from_end_item_unit_number,
7178                 to_end_item_unit_number,
7179                 eco_for_production,
7180                 FROM_END_ITEM_REV_ID,
7181                 TO_END_ITEM_REV_ID,
7182                 FROM_OBJECT_REVISION_ID,
7183                 TO_OBJECT_REVISION_ID,
7184                 FROM_END_ITEM_MINOR_REV_ID,
7185                 TO_END_ITEM_MINOR_REV_ID,
7186                 COMPONENT_ITEM_REVISION_ID,
7187                 COMMON_COMPONENT_SEQUENCE_ID,
7188                 BASIS_TYPE)
7189          select
7190                 component_sequence_id,
7191                 component_item_id,
7192                 operation_seq_num,
7193                 bill_sequence_id,
7194                 change_notice,
7195                 effectivity_date,
7196                 component_quantity,
7197                 component_yield_factor,
7198                 last_update_date,
7199                 last_updated_by,
7200                 creation_date,
7201                 created_by,
7202                 last_update_login,
7203                 old_component_sequence_id,
7204                 item_num,
7205                 wip_supply_type,
7206                 component_remarks,
7207                 supply_subinventory,
7208                 supply_locator_id,
7209                 implementation_date,
7210                 disable_date,
7211                 acd_type,
7212                 planning_factor,
7213                 quantity_related,
7214                 so_basis,
7215                 optional,
7216                 mutually_exclusive_options,
7217                 include_in_cost_rollup,
7218                 check_atp,
7219                 shipping_allowed,
7220                 required_to_ship,
7221                 required_for_revenue,
7222                 include_on_ship_docs,
7223                 include_on_bill_docs,
7224                 low_quantity,
7225                 high_quantity,
7226                 attribute_category,
7227                 attribute1,
7228                 attribute2,
7229                 attribute3,
7230                 attribute4,
7231                 attribute5,
7232                 attribute6,
7233                 attribute7,
7234                 attribute8,
7235                 attribute9,
7236                 attribute10,
7237                 attribute11,
7238                 attribute12,
7239                 attribute13,
7240                 attribute14,
7241                 attribute15,
7242                 request_id,
7243                 program_application_id,
7244                 program_id,
7245                 program_update_date,
7246                 revised_item_sequence_id,
7247                 from_end_item_unit_number,
7248                 to_end_item_unit_number,
7249                 eco_for_production,
7250                 FROM_END_ITEM_REV_ID,
7251                 TO_END_ITEM_REV_ID,
7252                 FROM_OBJECT_REVISION_ID,
7253                 TO_OBJECT_REVISION_ID,
7254                 FROM_END_ITEM_MINOR_REV_ID,
7255                 TO_END_ITEM_MINOR_REV_ID,
7256                 COMPONENT_ITEM_REVISION_ID,
7257                 COMMON_COMPONENT_SEQUENCE_ID,
7258                 BASIS_TYPE
7259         from bom_components_b --bom_inventory_components
7260         where component_sequence_id = component.component_sequence_id;
7261         If component.acd_type = acd_delete then
7262             Delete from bom_components_b --bom_inventory_components
7263             -- where current of chng_component_rows;
7264                where component_sequence_id = component.component_sequence_id;
7265 
7266             -----------------------------------------------------------
7267             -- R12: Changes for Common BOM Enhancement
7268             -- Step 4: Deleting Related Disabled Components
7269             -- When the disabled component is deleted from the bill,
7270             -- and it is a commoned bill, it will have referenced components
7271             -- in the common (destination) bills which also have to be deleted
7272             -- This record will have a reference to the change_notice and
7273             -- revised_item_sequence_id of the commoned component.
7274             -----------------------------------------------------------
7275             IF isCommonedBOM = 'Y'
7276             THEN
7277                 DELETE FROM bom_components_b bcb
7278                  WHERE bcb.common_component_sequence_id = component.component_sequence_id
7279                    AND bcb.common_component_sequence_id <> bcb.component_sequence_id
7280                    AND bcb.implementation_date IS null
7281                    AND bcb.change_notice = item.change_notice
7282                    AND bcb.revised_item_sequence_id = item.revised_item_sequence_id
7283                    AND bcb.acd_type = acd_delete;
7284             END IF;
7285             -----------------------------------------------------------
7286             -- R12: End Step 4: Changes for Common BOM Enhancement --
7287             -----------------------------------------------------------
7288         end if;
7289 
7290     -- ERES changes begin : bug 3741444
7291     bERES_Flag_for_BOM := TRUE;
7292     FND_FILE.PUT_LINE(FND_FILE.LOG, 'in component loop... bERES_Flag_for_BOM=TRUE');
7293     -- ERES changes end.
7294 
7295     -- Bug 4584490: Changes for Bom Business Events
7296     -- l_BOMEvents_Comps_ACD:
7297     -- Setting as add when the components are only added to this bill
7298     -- Setting it as change if components are changed or disabled in this bill.
7299     -- Removed l_BOMEvents_Comps_ACD clause so that component quantity change will raise an event.
7300     IF (component.acd_type = acd_add AND l_BOMEvents_Comps_ACD IS NULL)
7301     THEN
7302         l_BOMEvents_Comps_ACD := acd_add;
7303     ELSIF (component.acd_type IN (acd_change, acd_delete) )
7304     THEN
7305         l_BOMEvents_Comps_ACD := acd_change;
7306     END IF;
7307     -- End changes for 4584490
7308     end loop; -- all components
7309 
7310 
7311 
7312     Update bom_bill_of_materials
7313     set last_update_date = sysdate,
7314         last_updated_by = userid,
7315         last_update_login = loginid,
7316         request_id = reqstid,
7317         program_application_id = appid,
7318         program_id = progid,
7319         program_update_date = sysdate,
7320         pending_from_ecn = null
7321     where bill_sequence_id = item.bill_sequence_id
7322     AND pending_from_ecn = item.change_notice; -- Fixed for bug 3646438
7323 
7324     -- Bug 4584490: Changes for Bom Business Events
7325     BEGIN
7326         IF item.eco_for_production = 2
7327         THEN
7328             IF (l_pending_from_ecn = item.change_notice AND l_BOMEvents_Comps_ACD = acd_add)
7329             THEN
7330                 l_BOMEvents_Bill_Event_Name := Bom_Business_Event_PKG.G_STRUCTURE_CREATION_EVENT;
7331             ELSIF l_BOMEvents_Comps_ACD IS NOT NULL
7332             THEN
7333                 l_BOMEvents_Bill_Event_Name := Bom_Business_Event_PKG.G_STRUCTURE_MODIFIED_EVENT;
7334             END IF;
7335             IF (l_BOMEvents_Bill_Event_Name IS NOT NULL)
7336             THEN
7337                 Bom_Business_Event_PKG.Raise_Bill_Event(
7338                     p_pk1_value         => item.revised_item_id
7339                   , p_pk2_value         => item.organization_id
7340                   , p_obj_name          => null
7341                   , p_structure_name    => l_alternate_designator
7342                   , p_organization_id   => item.organization_id
7343                   , p_structure_comment => NULL
7344                   , p_Event_Name        => l_BOMEvents_Bill_Event_Name
7345                   );
7346             END IF;
7347         END IF;
7348     EXCEPTION
7349     WHEN OTHERS THEN
7350         null;
7351         -- nothing is required to be done, process continues
7352     END;
7353     -- End changes for 4584490
7354 
7355 -- ERES change begins
7356 --#######################################################
7357 -- Call the billCreate / billUpdate ERES event:
7358 -- BillCreate or billUpdate are children of event ecoImplementation
7359 -- Create or Update is decided on the value of
7360 --   column pending_from_ecn.
7361 --#######################################################
7362 IF (l_eres_enabled = 'Y')
7363 THEN
7364  -- bug 3234628, May-2004:
7365  -- odaboval added this test in order to only raise an ERES event
7366  --          when a row in bom_bill_of_materials has been updated:
7367  -- bug 3741444 : added bERES_Flag_for_BOM in the condition
7368  --               and removed ROWCOUNT>0 from the condition.
7369  IF (bERES_Flag_for_BOM)
7370  THEN
7371   -- First: Preparing child event BillCreate/Update
7372   IF (NVL(item.bill_sequence_id, -1) > 0)
7373   THEN
7374     l_event.param_name_1  := 'DEFERRED';
7375     l_event.param_value_1 := 'Y';
7376 
7377     l_event.param_name_2  := 'POST_OPERATION_API';
7378     l_event.param_value_2 := 'NONE';
7379 
7380     l_event.param_name_3  := 'PSIG_USER_KEY_LABEL';
7381     FND_MESSAGE.SET_NAME('BOM', 'BOM_ERES_BILL_USER_KEY');
7382     l_event.param_value_3 := FND_MESSAGE.GET;
7383 
7384     l_event.param_name_4  := 'PSIG_USER_KEY_VALUE';
7385     IF (l_alternate_designator IS NOT NULL)
7386     THEN
7387       l_event.param_value_4 := item.concatenated_segments||' - '||item.organization_code||' - '||l_alternate_designator;
7388     ELSE
7389       l_event.param_value_4 := item.concatenated_segments||' - '||item.organization_code;
7390     END IF;
7391 
7392     l_event.param_name_5  := 'PSIG_TRANSACTION_AUDIT_ID';
7393     l_event.param_value_5 := -1;
7394 
7395     l_event.param_name_6  := '#WF_SOURCE_APPLICATION_TYPE';
7396     l_event.param_value_6 := 'DB';
7397 
7398     l_event.param_name_7  := '#WF_SIGN_REQUESTER';
7399     l_event.param_value_7 := FND_GLOBAL.USER_NAME;
7400 
7401     IF (l_pending_from_ecn IS NULL)
7402     THEN
7403        l_child_event_name := 'oracle.apps.bom.billUpdate';
7404     ELSE
7405        l_child_event_name := 'oracle.apps.bom.billCreate';
7406     END IF;
7407 
7408     IF (NVL(l_parent_record_id, -1) > 0)
7409     THEN
7410       --additional parameters for the child event
7411       l_event.param_name_8 := 'PARENT_EVENT_NAME';
7412       l_event.param_value_8 := 'oracle.apps.eng.ecoImplement';
7413       l_event.param_name_9 := 'PARENT_EVENT_KEY';
7414       l_event.param_value_9 := TO_CHAR(item.change_id);
7415       l_event.param_name_10 := 'PARENT_ERECORD_ID';
7416       l_event.param_value_10 := TO_CHAR(l_parent_record_id);
7417     END IF;
7418 
7419     -- Part 2 of preparation of child event :
7420     l_event.event_name   := l_child_event_name;
7421     l_event.event_key    := TO_CHAR(item.bill_sequence_id);
7422     -- l_event.payload      := l_payload;
7423     l_event.erecord_id   := l_erecord_id;
7424     l_event.event_status := l_event_status;
7425 
7426     QA_EDR_STANDARD.RAISE_ERES_EVENT
7427            ( p_api_version      => 1.0
7428            , p_init_msg_list    => FND_API.G_FALSE
7429            , p_validation_level => FND_API.G_VALID_LEVEL_FULL
7430            , x_return_status    => l_return_status
7431            , x_msg_count        => l_msg_count
7432            , x_msg_data         => l_msg_data
7433            , p_child_erecords   => l_child_record
7434            , x_event            => l_event);
7435 
7436     IF (NVL(l_return_status, FND_API.G_FALSE) <> FND_API.G_TRUE)
7437       AND (l_msg_count > 0)
7438     THEN
7439        RAISE ERES_EVENT_ERROR;
7440     END IF;
7441 
7442     -- Keep the eRecord id :
7443     IF (NVL(l_event.erecord_id, -1) > 0)
7444     THEN
7445       INSERT INTO ENG_PARENT_CHILD_EVENTS_TEMP(parent_event_name
7446          , parent_event_key, parent_erecord_id
7447          , event_name, event_key, erecord_id
7448          , event_status)
7449       VALUES ( 'oracle.apps.eng.ecoImplement', TO_CHAR(item.change_id)
7450          , l_parent_record_id
7451          , l_event.event_name, l_event.event_key, l_event.erecord_id
7452          , l_event.event_status);
7453 
7454       FND_FILE.PUT_LINE(FND_FILE.LOG, 'After event='||l_child_event_name||', eRecord_id='||l_event.erecord_id||', status='||l_event.event_status||', bill='||item.bill_sequence_id);
7455     ELSE
7456       FND_FILE.PUT_LINE(FND_FILE.LOG, 'No eRecord generated for '||l_event.event_name||'. This is normal. Please check your rules or other setups');
7457     END IF;
7458   END IF;    -- (NVL(item.bill_sequence_id, -1) > 0)
7459 
7460  ELSE
7461    FND_FILE.PUT_LINE(FND_FILE.LOG, 'bERES_Flag_for_BOM=FALSE, then, NO ERES event for BOM .');
7462  END IF;   -- SQL%ROWCOUNT > 0
7463 END IF;   -- l_eres_enabled
7464 -- ERES change ends
7465 
7466 --
7467 --   Mark the RTG header as no longer pending from ECO
7468 --   added for eco enhancement
7469 -- ERES Change begins
7470 -- Decision for RoutingCreate or Update depends on pending_from_ecn:
7471     OPEN Get_Operational_Routing_Info( item.routing_sequence_id);
7472     FETCH Get_Operational_Routing_Info
7473      INTO l_pending_from_ecn
7474         , l_alternate_designator;
7475     CLOSE Get_Operational_Routing_Info;
7476 -- ERES change ends
7477 
7478     Update bom_operational_routings
7479     set last_update_date = sysdate,
7480         last_updated_by = userid,
7481         last_update_login = loginid,
7482         request_id = reqstid,
7483         program_application_id = appid,
7484         program_id = progid,
7485         program_update_date = sysdate,
7486         pending_from_ecn = null
7487     where routing_sequence_id = item.routing_sequence_id
7488     and pending_from_ecn is not null; --for bugfix 3234628
7489 
7490 -- ERES change begins
7491 --#######################################################
7492 -- Call the routingUpdate ERES event:
7493 -- RoutingCreate or RoutingUpdate are children of event ecoImplementation
7494 -- Create or Update is decided on the value of
7495 --   column pending_from_ecn.
7496 --######################################################
7497 IF (l_eres_enabled = 'Y')
7498 THEN
7499  -- bug 3234628, May-2004:
7500  -- odaboval added this test in order to only raise an ERES event
7501  --          when a row in bom_operational_routings has been updated:
7502  -- bug 3908563 : added bERES_Flag_for_Routing in the condition
7503  --               and removed ROWCOUNT>0 from the condition.
7504  IF (bERES_Flag_for_Routing)
7505  THEN
7506   -- Preparing child event RoutingCreate/Update
7507   IF (NVL(item.routing_sequence_id, -1) > 0)
7508   THEN
7509     l_event.param_name_1  := 'DEFERRED';
7510     l_event.param_value_1 := 'Y';
7511 
7512     l_event.param_name_2  := 'POST_OPERATION_API';
7513     l_event.param_value_2 := 'NONE';
7514 
7515     l_event.param_name_3  := 'PSIG_USER_KEY_LABEL';
7516     FND_MESSAGE.SET_NAME('BOM', 'BOM_ERES_ROUTING_USER_KEY');
7517     l_event.param_value_3 := FND_MESSAGE.GET;
7518 
7519     l_event.param_name_4  := 'PSIG_USER_KEY_VALUE';
7520     IF (l_alternate_designator IS NOT NULL)
7521     THEN
7522       l_event.param_value_4 := item.concatenated_segments||' - '||item.organization_code||' - '||l_alternate_designator;
7523     ELSE
7524       l_event.param_value_4 := item.concatenated_segments||' - '||item.organization_code;
7525     END IF;
7526 
7527     l_event.param_name_5  := 'PSIG_TRANSACTION_AUDIT_ID';
7528     l_event.param_value_5 := -1;
7529 
7530     l_event.param_name_6  := '#WF_SOURCE_APPLICATION_TYPE';
7531     l_event.param_value_6 := 'DB';
7532 
7533     l_event.param_name_7  := '#WF_SIGN_REQUESTER';
7534     l_event.param_value_7 := FND_GLOBAL.USER_NAME;
7535 
7536     IF (l_pending_from_ecn IS NULL)
7537     THEN
7538        l_child_event_name := 'oracle.apps.bom.routingUpdate';
7539     ELSE
7540        l_child_event_name := 'oracle.apps.bom.routingCreate';
7541     END IF;
7542 
7543     IF (NVL(l_parent_record_id, -1) > 0)
7544     THEN
7545       --additional parameters for the child event
7546       l_event.param_name_8 := 'PARENT_EVENT_NAME';
7547       l_event.param_value_8 := 'oracle.apps.eng.ecoImplement';
7548       l_event.param_name_9 := 'PARENT_EVENT_KEY';
7549       l_event.param_value_9 := TO_CHAR(item.change_id);
7550       l_event.param_name_10 := 'PARENT_ERECORD_ID';
7551       l_event.param_value_10 := TO_CHAR(l_parent_record_id);
7552     END IF;
7553 
7554     -- Part 2 of preparation of child event :
7555     l_event.event_name   := l_child_event_name;
7556     l_event.event_key    := TO_CHAR(item.routing_sequence_id);
7557     -- l_event.payload      := l_payload;
7558     l_event.erecord_id   := l_erecord_id;
7559     l_event.event_status := l_event_status;
7560 
7561     QA_EDR_STANDARD.RAISE_ERES_EVENT
7562            ( p_api_version      => 1.0
7563            , p_init_msg_list    => FND_API.G_FALSE
7564            , p_validation_level => FND_API.G_VALID_LEVEL_FULL
7565            , x_return_status    => l_return_status
7566            , x_msg_count        => l_msg_count
7567            , x_msg_data         => l_msg_data
7568            , p_child_erecords   => l_child_record
7569            , x_event            => l_event);
7570 
7571     IF (NVL(l_return_status, FND_API.G_FALSE) <> FND_API.G_TRUE)
7572       AND (l_msg_count > 0)
7573     THEN
7574        RAISE ERES_EVENT_ERROR;
7575     END IF;
7576 
7577     -- Keep the eRecord id :
7578     IF (NVL(l_event.erecord_id, -1) > 0)
7579     THEN
7580       INSERT INTO ENG_PARENT_CHILD_EVENTS_TEMP(parent_event_name
7581          , parent_event_key, parent_erecord_id
7582          , event_name, event_key, erecord_id
7583          , event_status)
7584       VALUES ( 'oracle.apps.eng.ecoImplement', TO_CHAR(item.change_id)
7585          , l_parent_record_id
7586          , l_event.event_name, l_event.event_key, l_event.erecord_id
7587          , l_event.event_status);
7588 
7589       FND_FILE.PUT_LINE(FND_FILE.LOG, 'After event='||l_child_event_name||', eRecord_id='||l_event.erecord_id||', status='||l_event.event_status||', routing='||item.routing_sequence_id);
7590     ELSE
7591       FND_FILE.PUT_LINE(FND_FILE.LOG, 'No eRecord generated for '||l_event.event_name||'. This is normal. Please check your rules or other setups');
7592     END IF;
7593 
7594   END IF;    -- (NVL(item.routing_sequence_id, -1) > 0)
7595    FND_FILE.PUT_LINE(FND_FILE.LOG, 'Normal end of ERES Calls for procedure implement_revised_item.');
7596 
7597  ELSE
7598    FND_FILE.PUT_LINE(FND_FILE.LOG, 'bERES_Flag_for_Routing=FALSE, then, NO ERES event for Routing.');
7599  END IF;   -- SQL%ROWCOUNT > 0
7600 END IF;   -- l_eres_enabled
7601 -- ERES change ends
7602 
7603 Update eng_revised_items
7604 set     implementation_date = today,
7605         scheduled_date = eff_date,
7606         status_type = 6,
7607         last_update_date = sysdate,
7608         last_updated_by = userid,
7609         last_update_login = loginid,
7610         request_id = reqstid,
7611         program_application_id = appid,
7612         program_id = progid,
7613         program_update_date = sysdate,
7614         status_code = p_status_code
7615 -- where current of get_item_info;
7616    where revised_item_sequence_id = item.revised_item_sequence_id;
7617 
7618 
7619 -- set values for inserting rows into wip schedule interface
7620    l_wip_primary_item_id := item.revised_item_id;
7621    l_wip_from_cum_qty    := item.from_cum_qty;
7622    l_from_wip_entity_id  := item.from_wip_entity_id;
7623    l_to_wip_entity_id    := item.to_wip_entity_id;
7624 
7625    IF item.new_item_revision IS NOT NULL
7626    THEN
7627       l_wip_bom_revision2          := item.new_item_revision;
7628       l_wip_bom_revision_date2     := revision_high_date + 1/60/24;
7629    ELSE
7630       l_wip_bom_revision2          := l_current_revision;
7631   /*    IF l_current_rev_eff_date <= now
7632       THEN
7633          l_wip_bom_revision_date2     := revision_high_date;
7634       ELSE
7635           IF l_current_rev_eff_date < revision_high_date
7636          THEN
7637            l_wip_bom_revision_date2     := revision_high_date;
7638          ELSE
7639            l_wip_bom_revision_date2     := l_current_rev_eff_date;
7640          END IF;
7641       END IF;
7642    */
7643      IF l_current_rev_eff_date <=  revision_high_date
7644       THEN
7645          l_wip_bom_revision_date2     := revision_high_date + 1/60/24;
7646       ELSE
7647          l_wip_bom_revision_date2     := l_current_rev_eff_date;
7648       END IF;
7649 
7650    END IF;
7651 
7652    IF item.new_routing_revision IS NOT NULL
7653    THEN
7654       l_wip_routing_revision2      := item.new_routing_revision;
7655       l_wip_routing_revision_date2 := rtg_revision_high_date + 1/60/24;
7656    ELSE
7657       l_wip_routing_revision2          := l_current_rtg_revision;
7658   /*    IF l_current_rtg_rev_eff_date <= now
7659       THEN
7660          l_wip_routing_revision_date2  := now;
7661       ELSE
7662          IF l_current_rtg_rev_eff_date < rtg_revision_high_date
7663          THEN
7664            l_wip_routing_revision_date2     := rtg_revision_high_date;
7665          ELSE
7666            l_wip_routing_revision_date2     := l_current_rtg_rev_eff_date;
7667          END IF;
7668       END IF;
7669    */
7670       IF l_current_rtg_rev_eff_date <= rtg_revision_high_date
7671       THEN
7672          l_wip_routing_revision_date2  := rtg_revision_high_date + 1/60/24;
7673       ELSE
7674            l_wip_routing_revision_date2  := l_current_rtg_rev_eff_date;
7675       END IF;
7676 
7677    END IF;
7678 
7679    l_wip_bom_revision_date1 := l_wip_bom_revision_date2- 1/3600/24;         -- minus 1 second
7680    l_wip_routing_revision_date1 := l_wip_bom_revision_date2- 1;             -- minus 1 day
7681 
7682    l_update_wip                 := NVL(item.update_wip,2);
7683    l_eco_for_production         := NVL(item.eco_for_production, 2);
7684 
7685 END IF; -- Check for Transfer/Copy OR Revised Item Change
7686 
7687 Close get_item_info;
7688 
7689 Open check_for_unimp_items;
7690 Fetch check_for_unimp_items into dummy;
7691 If check_for_unimp_items%notfound then
7692         -- old code before 11.5.10 lifecycle enhancement
7693         /*
7694         Update eng_engineering_changes
7695         set    implementation_date = today,
7696                status_type = 6,
7697                last_update_date = sysdate,
7698                last_updated_by = userid,
7699                last_update_login = loginid,
7700                request_id = reqstid,
7701                program_application_id = appid,
7702                program_id = progid,
7703                program_update_date = sysdate
7704         where  organization_id = item.organization_id
7705         and    change_notice = item.change_notice;
7706         */
7707 
7708         -- New code: begin
7709     -- Check if implementation of header is allowed or not for the current phase
7710     -- added for bug 3482152
7711     select nvl(plm_or_erp_change, 'PLM') , status_code
7712     into l_plm_or_erp_change, l_curr_status_code
7713     from eng_engineering_changes where
7714     change_id = item.change_id;
7715 
7716     l_implement_header := 'T';
7717     l_implement_header := check_header_impl_allowed(
7718                                 p_change_id => item.change_id
7719                               , p_change_notice => item.change_notice
7720                               , p_status_code => p_status_code
7721                               , p_curr_status_code => l_curr_status_code
7722                               , p_plm_or_erp_change => l_plm_or_erp_change
7723                               , p_request_id => reqstid);
7724 
7725     IF (l_implement_header = 'T')
7726     THEN
7727         -- setting the end-date to the current phase if null
7728         -- added for bug 3482152
7729         UPDATE eng_lifecycle_statuses
7730         SET completion_date = sysdate,
7731             last_update_date = sysdate,
7732             last_updated_by = userid,
7733             last_update_login = loginid
7734         WHERE entity_name = 'ENG_CHANGE'
7735           AND entity_id1 = item.change_id
7736           AND status_code = l_curr_status_code
7737           AND active_flag = 'Y'
7738           AND completion_date IS NULL;
7739 
7740         -- First set header phase to implement
7741         Update eng_engineering_changes
7742         set implementation_date = today,
7743             status_type = 6,
7744             status_code = p_status_code,
7745             last_update_date = sysdate,
7746             last_updated_by = userid,
7747             last_update_login = loginid,
7748             request_id = reqstid,
7749             program_application_id = appid,
7750             program_id = progid,
7751             program_update_date = sysdate
7752         where organization_id = item.organization_id
7753           and change_notice = item.change_notice;
7754 
7755         -- Reset promote_status_code
7756         Update eng_engineering_changes
7757         set promote_status_code = null
7758         where organization_id = item.organization_id
7759           and change_notice = item.change_notice;
7760 
7761         -- Complete the last phase in the lifecycle
7762         UPDATE eng_lifecycle_statuses
7763         SET start_date  = nvl(start_date,sysdate),      -- set the start date on implemented phase after promoting the header to implemented phase
7764                                         -- added for bug 3482152
7765             completion_date = sysdate,
7766             last_update_date = sysdate,
7767             last_updated_by = userid,
7768             last_update_login = loginid
7769         WHERE entity_name = 'ENG_CHANGE'
7770           AND entity_id1 = (SELECT change_id
7771                             FROM eng_engineering_changes
7772                             WHERE organization_id = item.organization_id
7773                               AND change_notice = item.change_notice
7774                             )
7775           AND active_flag = 'Y'
7776           AND sequence_number = (SELECT max(sequence_number)
7777                                  FROM eng_lifecycle_statuses
7778                                  WHERE entity_name = 'ENG_CHANGE'
7779                                    AND entity_id1 = (SELECT change_id
7780                                                      FROM eng_engineering_changes
7781                                                      WHERE organization_id = item.organization_id
7782                                                        AND change_notice = item.change_notice
7783                                                      )
7784                                  );
7785         -- New code: end
7786 
7787         -- Fix for bug: 3463308
7788         /* does not work for some reason, but do not delete
7789         FND_FILE.PUT_NAMES('CP.impECO.wf.log',
7790                            'CP.impECO.wf.out',
7791                            '/appslog/bis_top/utl/plm115dt/log'
7792                            );
7793         FND_FILE.PUT_LINE(fnd_file.log, 'Before: calling startWorkflow');
7794         FND_FILE.PUT_LINE(fnd_file.log, '  item.change_id = ' || item.change_id);
7795         */
7796                     -- using dynamic sql to launch status_change workflow API for implement phase
7797         BEGIN
7798           -- Log action for promotion to implement phase
7799           l_plsql_block :=
7800             'BEGIN '
7801             || ' ENG_CHANGE_ACTIONS_UTIL.Create_Change_Action('
7802             || ' p_api_version        => 1.0 '
7803             || ',x_return_status      => :1     '
7804             || ',x_msg_count          => :2     '
7805             || ',x_msg_data           => :3     '
7806             || ',p_action_type        => ''PROMOTE'' '
7807             || ',p_object_name        => ''ENG_CHANGE'' '
7808             || ',p_object_id1         => :4 '
7809             || ',p_parent_action_id   => -1 '
7810             || ',p_status_code        => :5 '  -- seeded value for implement phase
7811             || ',p_action_date        => SYSDATE '
7812             || ',p_change_description => NULL '
7813             || ',p_user_id            => -10000 '
7814             || ',p_api_caller         => ''WF'' '
7815             || ',x_change_action_id   => :6 '
7816             /*
7817             || ',p_init_msg_list      => FND_API.G_TRUE '
7818             || ',p_validation_level   => FND_API.G_VALID_LEVEL_FULL '
7819             || ',p_debug              => FND_API.G_TRUE '
7820             || ',p_output_dir         => ''/appslog/bis_top/utl/plm115dt/log'' '
7821             || ',p_debug_filename     => ''engact.createAct4Imp.log'' '
7822             */
7823             || '); END;';
7824           EXECUTE IMMEDIATE l_plsql_block USING
7825             OUT l_return_status,  -- :1
7826             OUT l_msg_count,      -- :2
7827             OUT l_msg_data,       -- :3
7828             IN  item.change_id,   -- :4
7829             IN  p_status_code,    -- :5
7830             OUT l_action_id;      -- :6
7831 
7832           -- Bug Fix: 5023201
7833           -- Should not start workflow if it's MFG Change Order
7834           IF ( l_plm_or_erp_change = 'PLM' )
7835           THEN
7836               -- Start workflow for phase change
7837               l_plsql_block :=
7838               'BEGIN '
7839               || ' Eng_Workflow_Util.StartWorkflow('
7840               || ' p_api_version        => 1.0 '
7841               || ',x_return_status      => :1	'
7842               || ',x_msg_count          => :2	'
7843               || ',x_msg_data           => :3	'
7844               || ',p_item_type          => Eng_Workflow_Util.G_CHANGE_ACTION_ITEM_TYPE '
7845               || ',x_item_key           => :4	'
7846               || ',p_process_name       => Eng_Workflow_Util.G_STATUS_CHANGE_PROC '
7847               || ',p_change_id          => :5	'
7848               || ',p_action_id          => :6	'
7849               || ',p_wf_user_id         => -10000	'
7850               || ',p_route_id           => 0 '
7851               /*
7852               || ',p_init_msg_list      => FND_API.G_TRUE '
7853               || ',p_validation_level   => FND_API.G_VALID_LEVEL_FULL '
7854               || ',p_debug              => FND_API.G_TRUE '
7855               || ',p_output_dir         => ''/appslog/bis_top/utl/plm115dt/log'' '
7856               || ',p_debug_filename     => ''engact.startWF4Imp.log'' '
7857               */
7858             || '); END;';
7859             EXECUTE IMMEDIATE l_plsql_block USING
7860               OUT l_return_status,  -- :1
7861               OUT l_msg_count,      -- :2
7862               OUT l_msg_data,       -- :3
7863               IN OUT l_item_key,    -- :4
7864               IN  item.change_id,   -- :5
7865               IN  l_action_id;      -- :6
7866 
7867             -- Bug: 3479509
7868   	    -- Starting the workflow associated to implemented status
7869 	    SELECT change_wf_route_id
7870             INTO l_wf_route_id
7871             FROM eng_lifecycle_statuses
7872             WHERE entity_name = 'ENG_CHANGE'
7873             AND entity_id1 = item.change_id
7874             AND status_code = p_status_code
7875             AND active_flag = 'Y'
7876             AND rownum = 1;
7877 
7878             IF (l_wf_route_id IS NOT NULL) THEN
7879                 l_plsql_block :=
7880                 'BEGIN '
7881                 || ' Eng_Workflow_Util.StartWorkflow('
7882                 || ' p_api_version        => 1.0 '
7883                 || ',x_return_status      => :1	'
7884                 || ',x_msg_count          => :2	'
7885                 || ',x_msg_data           => :3	'
7886                 || ',p_item_type          => Eng_Workflow_Util.G_CHANGE_ROUTE_ITEM_TYPE '
7887                 || ',x_item_key           => :4	'
7888                 || ',p_process_name       => Eng_Workflow_Util.G_ROUTE_AGENT_PROC '
7889                 || ',p_change_id          => :5	'
7890                 || ',p_wf_user_id         => -10000	'
7891                 || ',p_route_id           => :6 '
7892                 || '); END;';
7893               EXECUTE IMMEDIATE l_plsql_block USING
7894                 OUT l_return_status,  -- :1
7895                 OUT l_msg_count,      -- :2
7896                 OUT l_msg_data,       -- :3
7897                 IN OUT l_item_key,    -- :4
7898                 IN  item.change_id,   -- :5
7899                 IN  l_wf_route_id;    -- :6
7900             END IF;
7901 
7902           END IF ; --  ( l_plm_or_erp_change = 'PLM' )
7903 
7904         EXCEPTION
7905           WHEN OTHERS THEN
7906             null;
7907         END;
7908         /* does not work for some reason, but do not delete
7909         FND_FILE.PUT_LINE(fnd_file.log, 'After: calling startWorkflow');
7910         FND_FILE.PUT_LINE(fnd_file.log, '  l_return_status = ' || l_return_status);
7911         FND_FILE.PUT_LINE(fnd_file.log, '  l_msg_count     = ' || to_char( nvl(l_msg_count, 0) ) );
7912         FND_FILE.PUT_LINE(fnd_file.log, '  l_msg_data      = ' || nvl(l_msg_data, 'no msg data') );
7913         FND_FILE.PUT_LINE(fnd_file.log, '  l_item_key      = ' || nvl(l_item_key, 'no item key') );
7914         FND_FILE.CLOSE;
7915         */
7916     END IF;
7917 end if;
7918 Close check_for_unimp_items;
7919 
7920 -----------------------------------------------------------------
7921 -- For ECO cumulative/ECO wip job/ECO lot  ---------9/07/2000----
7922 -----------------------------------------------------------------
7923 -- IF item.update_wip = 1 and  NVL(item.start_quantity,0) > 0
7924  IF l_update_wip = 1
7925  THEN
7926 
7927     SELECT wip_job_schedule_interface_s.NEXTVAL INTO  l_wip_group_id1
7928     FROM DUAL;
7929     group_id1 :=  l_wip_group_id1;  --- set out type value
7930 
7931     --bug 2327582
7932     l_update_all_jobs := fnd_profile.value('ENG:UPDATE_UNRELEASED_WIP_JOBS');
7933 
7934     l_wip_jsi_insert_flag :=  0;
7935     IF NVL(l_wip_from_cum_qty, 0) > 0
7936     THEN
7937       IF l_wip_start_quantity1 <> 0
7938       THEN
7939         SELECT wip_job_schedule_interface_s.NEXTVAL INTO  l_wip_group_id2
7940         FROM DUAL;
7941         group_id2 :=  l_wip_group_id2;  --- set out type value
7942       ELSE group_id2 := -1;
7943       END IF;
7944 
7945       --WIP job gets split into 2 based on the CUM quantity
7946       -- delete the original wip job
7947       INSERT INTO wip_job_schedule_interface
7948        (
7949          last_update_date
7950        , last_updated_by
7951        , creation_date
7952        , created_by
7953        , request_id
7954        , program_application_id
7955        , program_id
7956        , program_update_date
7957        , group_id
7958        , process_phase
7959        , process_status
7960        , organization_id
7961        , load_type
7962        , status_type
7963        , wip_entity_id
7964        )
7965        VALUES
7966        (
7967         sysdate
7968        , userid
7969        , sysdate
7970        , userid
7971        , reqstid
7972        , appid
7973        , progid
7974        , sysdate
7975        , l_wip_group_id1
7976        , l_wip_process_phase
7977        , l_wip_process_status
7978        , item.organization_id
7979        , 3    -- update or delete wip
7980        , 7    -- cancel wip order
7981        , item.from_wip_entity_id
7982       );
7983 
7984       -- Create first new order
7985       IF l_wip_start_quantity1 <> 0
7986       THEN
7987         INSERT INTO wip_job_schedule_interface
7988         (
7989           last_update_date
7990         , last_updated_by
7991         , creation_date
7992         , created_by
7993         , last_update_login
7994         , request_id
7995         , program_id
7996         , program_application_id
7997         , program_update_date
7998         , group_id
7999         , organization_id
8000         , load_type
8001         , status_type
8002         , primary_item_id
8003         , bom_revision_date
8004         , routing_revision_date
8005         , job_name
8006         , start_quantity
8007         , net_quantity
8008         , process_phase
8009         , process_status
8010         , last_unit_completion_date
8011         -- , routing_revision
8012         -- , bom_revision
8013         , completion_subinventory
8014         , completion_locator_id
8015         , allow_explosion
8016         , header_id
8017         )
8018         values
8019         ( sysdate
8020           , userid
8021           , sysdate
8022           , userid
8023           , loginid
8024           , reqstid
8025           , progid
8026           , appid
8027           , sysdate
8028           , l_wip_group_id2
8029           , l_wip_organization_id
8030           , l_wip_load_type
8031           , l_wip_status_type
8032           , l_wip_primary_item_id
8033           , l_wip_bom_revision_date1
8034           , decode(l_WIP_Flag_for_routing,'Y', l_wip_routing_revision_date1, NULL) -- Bug 4455543
8035           , l_wip_job_name1
8036           , l_wip_start_quantity1
8037           , l_wip_net_quantity1
8038           , l_wip_process_phase
8039           , l_wip_process_status
8040           , l_wip_last_u_compl_date1
8041           --, l_wip_routing_revision1
8042           --, l_wip_bom_revision1
8043           , l_wip_completion_subinventory
8044           , l_wip_completion_locator_id
8045           , l_wip_allow_explosion
8046           , l_wip_group_id2
8047         );
8048 
8049         -- Add components for 'Update Job Only' case
8050         -- Bug No: 5285282
8051         IF l_eco_for_production = 1
8052         THEN
8053           ENTER_WIP_DETAILS_FOR_COMPS ( p_revised_item_sequence_id => item.revised_item_sequence_id,
8054                                         p_group_id                 => l_wip_group_id2,
8055                                         p_parent_header_id         => l_wip_group_id2,
8056                                         p_mrp_active               => item.mrp_active,
8057                                         p_user_id                  => userid,
8058                                         p_login_id                 => loginid,
8059                                         p_request_id               => reqstid,
8060                                         p_program_id               => progid,
8061                                         p_program_application_id   => appid);
8062         END IF;
8063       END IF; -- IF l_wip_start_quantity1 <> 0
8064 
8065       -- Create second new records
8066       INSERT INTO wip_job_schedule_interface (
8067         last_update_date
8068        , last_updated_by
8069        , creation_date
8070        , created_by
8071        , last_update_login
8072        , request_id
8073        , program_id
8074        , program_application_id
8075        , program_update_date
8076        , group_id
8077        , organization_id
8078        , load_type
8079        , status_type
8080        , primary_item_id
8081        , bom_revision_date
8082        , routing_revision_date
8083        , job_name
8084        , start_quantity
8085        , net_quantity
8086        , process_phase
8087        , process_status
8088        , last_unit_completion_date
8089       -- , routing_revision
8090       -- , bom_revision
8091        , completion_subinventory
8092        , completion_locator_id
8093        , allow_explosion
8094        , header_id
8095        )
8096        values
8097        (
8098              sysdate
8099            , userid
8100            , sysdate
8101            , userid
8102            , loginid
8103            , reqstid
8104            , progid
8105            , appid
8106            , sysdate
8107            , l_wip_group_id1
8108            , l_wip_organization_id
8109            , l_wip_load_type
8110            , l_wip_status_type
8111            , l_wip_primary_item_id
8112            , l_wip_bom_revision_date2
8113            , decode(l_WIP_Flag_for_routing,'Y', l_wip_routing_revision_date2, NULL) -- Bug 4455543
8114            , l_wip_job_name2
8115            , l_wip_start_quantity2
8116            , l_wip_net_quantity2
8117            , l_wip_process_phase
8118            , l_wip_process_status
8119            , decode(l_WIP_Flag_for_routing,'Y',l_wip_last_u_compl_date2, NULL) -- Bug 4455543
8120       --     , l_wip_routing_revision2
8121       --     , l_wip_bom_revision2
8122            , l_wip_completion_subinventory
8123            , l_wip_completion_locator_id
8124            , l_wip_allow_explosion
8125            , l_wip_group_id1
8126       );
8127 
8128       -- Add components for 'Update Job Only' case
8129       -- Bug No: 5285282
8130       IF l_eco_for_production = 1
8131       THEN
8132         ENTER_WIP_DETAILS_FOR_COMPS ( p_revised_item_sequence_id => item.revised_item_sequence_id,
8133                                       p_group_id                 => l_wip_group_id1,
8134                                       p_parent_header_id         => l_wip_group_id1,
8135                                       p_mrp_active               => item.mrp_active,
8136                                       p_user_id                  => userid,
8137                                       p_login_id                 => loginid,
8138                                       p_request_id               => reqstid,
8139                                       p_program_id               => progid,
8140                                       p_program_application_id   => appid);
8141       END IF;
8142 
8143       l_wip_jsi_insert_flag := 1;
8144 
8145     ELSIF  NVL(l_to_wip_entity_id, 0) <> 0
8146     THEN
8147       FOR wip_name_for_job_rec in l_wip_name_for_job_cur
8148       LOOP
8149         l_wip_job_name2 := wip_name_for_job_rec.wip_entity_name;
8150         l_wip_last_u_compl_date2 :=  wip_name_for_job_rec.scheduled_completion_date;
8151 
8152 	SELECT wip_job_schedule_interface_s.NEXTVAL INTO  l_wip_header_id
8153         FROM DUAL; --fix bug 5667398 cannot have duplicate header id from same group id
8154         /* Added for Bug2970539, Bug 3076067 */
8155 
8156         --if (l_wip_bom_revision_date2 > today) then          -- 3412747
8157         if (wip_name_for_job_rec.bom_revision_date > today)
8158         then
8159           l_wip_bom_revision_date2  := wip_name_for_job_rec.bom_revision_date;
8160         end if;
8161         --if (l_wip_routing_revision_date2 > today) then       -- 3412747
8162         if (wip_name_for_job_rec.routing_revision_date > today)
8163         then
8164           l_wip_routing_revision_date2 := wip_name_for_job_rec.routing_revision_date;
8165         end if;
8166 
8167         --Update existing WIP headers
8168         INSERT INTO wip_job_schedule_interface
8169         (
8170            last_update_date
8171          , last_updated_by
8172          , creation_date
8173          , created_by
8174          , last_update_login
8175          , request_id
8176          , program_id
8177          , program_application_id
8178          , program_update_date
8179          , group_id
8180          , organization_id
8181          , load_type
8182          , status_type
8183          , primary_item_id
8184          , bom_revision_date
8185          , routing_revision_date
8186          , job_name
8187          , process_phase
8188          , process_status
8189          , last_unit_completion_date
8190          , routing_revision
8191          , bom_revision
8192          , bom_reference_id
8193          , routing_reference_id
8194          , allow_explosion
8195          , alternate_bom_designator
8196          , alternate_routing_designator
8197 	 , completion_subinventory
8198  	 , completion_locator_id
8199          , header_id
8200         )
8201         values
8202         (
8203            sysdate
8204          , userid
8205          , sysdate
8206          , userid
8207          , loginid
8208          , reqstid
8209          , progid
8210          , appid
8211          , sysdate
8212          , l_wip_group_id1
8213          , l_wip_organization_id
8214          , 3          --l_wip_load_type
8215          , l_wip_status_type
8216          , wip_name_for_job_rec.primary_item_id
8217          --, l_wip_primary_item_id
8218          , l_wip_bom_revision_date2
8219          , decode(l_WIP_Flag_for_routing,'Y',l_wip_routing_revision_date2, NULL) -- Bug 4455543
8220          , l_wip_job_name2
8221          , l_wip_process_phase
8222          , l_wip_process_status
8223          , decode(l_WIP_Flag_for_routing,'Y', l_wip_last_u_compl_date2, NULL) -- Bug 4455543
8224          , decode(l_WIP_Flag_for_routing,'Y', nvl(wip_name_for_job_rec.routing_revision, l_wip_routing_revision2)   -- Bug 3381547
8225                                       , NULL) -- Bug 4455543
8226          , nvl(wip_name_for_job_rec.bom_revision, l_wip_bom_revision2)              -- Bug 3381547
8227          , wip_name_for_job_rec.primary_item_id
8228          , decode(l_WIP_Flag_for_routing,'Y',wip_name_for_job_rec.primary_item_id, NULL) -- Bug 4455543
8229          --, l_wip_primary_item_id
8230          --, l_wip_primary_item_id
8231          , l_wip_allow_explosion
8232          ,wip_name_for_job_rec.alternate_bom_designator    --2964588
8233          ,wip_name_for_job_rec.alternate_routing_designator    --2964588
8234          , l_wip_completion_subinventory   -- Bug 5896479
8235          , l_wip_completion_locator_id     -- Bug 5896479
8236          , l_wip_header_id
8237         );
8238 
8239         -- Add components for 'Update Job Only' case
8240         -- Bug No: 5285282
8241         IF l_eco_for_production = 1
8242         THEN
8243           ENTER_WIP_DETAILS_FOR_COMPS ( p_revised_item_sequence_id => item.revised_item_sequence_id,
8244                                         p_group_id                 => l_wip_group_id1,
8245                                         p_parent_header_id         => l_wip_header_id,
8246                                         p_mrp_active               => item.mrp_active,
8247                                         p_user_id                  => userid,
8248                                         p_login_id                 => loginid,
8249                                         p_request_id               => reqstid,
8250                                         p_program_id               => progid,
8251                                         p_program_application_id   => appid);
8252         END IF;
8253 
8254         IF l_wip_jsi_insert_flag = 0
8255         THEN
8256           l_wip_jsi_insert_flag := 1;
8257         END IF ;
8258       END LOOP;
8259 
8260     ELSIF  NVL(l_lot_number,'NULL') <> 'NULL'
8261     THEN
8262 
8263       FOR wip_name_for_lot_rec in l_wip_name_for_lot_cur
8264       LOOP
8265         l_wip_job_name2 := wip_name_for_lot_rec.wip_entity_name;
8266         l_wip_last_u_compl_date2 :=  wip_name_for_lot_rec.scheduled_completion_date;
8267 
8268 	SELECT wip_job_schedule_interface_s.NEXTVAL INTO  l_wip_header_id
8269         FROM DUAL; --fix bug 5667398 cannot have duplicate header id from same group id
8270 
8271         /* Added for Bug2970539, Bug 3076067 */
8272 
8273         --if (l_wip_bom_revision_date2 > today) then                             --3412747
8274         if (wip_name_for_lot_rec.bom_revision_date > today
8275             OR l_wip_bom_revision_date2 IS NULL      -- Added 'OR' condition for Bug #3988681
8276            )
8277         then
8278           l_wip_bom_revision_date2  := wip_name_for_lot_rec.bom_revision_date;
8279         end if;
8280         --if (l_wip_routing_revision_date2 > today) then                         --3412747
8281         if (wip_name_for_lot_rec.routing_revision_date > today
8282             OR l_wip_routing_revision_date2 IS NULL    -- Added 'OR' condition for Bug #3988681
8283             )
8284         then
8285           l_wip_routing_revision_date2 := wip_name_for_lot_rec.routing_revision_date;
8286         end if;
8287 
8288         INSERT INTO wip_job_schedule_interface
8289         (
8290           last_update_date
8291         , last_updated_by
8292         , creation_date
8293         , created_by
8294         , last_update_login
8295         , request_id
8296         , program_id
8297         , program_application_id
8298         , program_update_date
8299         , group_id
8300         , organization_id
8301         , load_type
8302         , status_type
8303         , primary_item_id
8304         , bom_revision_date
8305         , routing_revision_date
8306         , job_name
8307         , process_phase
8308         , process_status
8309         , last_unit_completion_date
8310         , routing_revision
8311         , bom_revision
8312         , bom_reference_id
8313         , routing_reference_id
8314         , allow_explosion
8315         , alternate_bom_designator
8316         , alternate_routing_designator
8317 	, completion_subinventory
8318 	, completion_locator_id
8319         , header_id
8320         )
8321         values
8322         (
8323            sysdate
8324            , userid
8325            , sysdate
8326            , userid
8327            , loginid
8328            , reqstid
8329            , progid
8330            , appid
8331            , sysdate
8332            , l_wip_group_id1
8333            --, l_wip_organization_id                    --3412747
8334            , wip_name_for_lot_rec.organization_id
8335            , 3      --l_wip_load_type
8336            , l_wip_status_type
8337            , wip_name_for_lot_rec.primary_item_id
8338       --     , l_wip_primary_item_id
8339            , l_wip_bom_revision_date2
8340            , decode(l_WIP_Flag_for_routing,'Y',l_wip_routing_revision_date2, null) -- Bug 4455543
8341            , l_wip_job_name2
8342            , l_wip_process_phase
8343            , l_wip_process_status
8344            , decode(l_WIP_Flag_for_routing,'Y',l_wip_last_u_compl_date2, null) -- Bug 4455543
8345            , decode(l_WIP_Flag_for_routing,'Y',nvl(wip_name_for_lot_rec.routing_revision, l_wip_routing_revision2) -- Bug 3381547
8346                       , null) -- Bug 4455543
8347            , nvl(wip_name_for_lot_rec.bom_revision, l_wip_bom_revision2) -- Bug 3381547
8348            , wip_name_for_lot_rec.primary_item_id
8349            , decode(l_WIP_Flag_for_routing,'Y',wip_name_for_lot_rec.primary_item_id, null) -- Bug 4455543
8350       --     , l_wip_primary_item_id
8351       --     , l_wip_primary_item_id
8352            , l_wip_allow_explosion
8353            ,wip_name_for_lot_rec.alternate_bom_designator    --2964588
8354            ,wip_name_for_lot_rec.alternate_routing_designator    --2964588
8355      	   , l_wip_completion_subinventory   -- Bug 5896479
8356 	   , l_wip_completion_locator_id     -- Bug 5896479
8357            , l_wip_header_id
8358         );
8359 
8360         -- Add components for 'Update Job Only' case
8361         -- Bug No: 5285282
8362         IF l_eco_for_production = 1
8363         THEN
8364           ENTER_WIP_DETAILS_FOR_COMPS ( p_revised_item_sequence_id => item.revised_item_sequence_id,
8365                                         p_group_id                 => l_wip_group_id1,
8366                                         p_parent_header_id         => l_wip_header_id,
8367                                         p_mrp_active               => item.mrp_active,
8368                                         p_user_id                  => userid,
8369                                         p_login_id                 => loginid,
8370                                         p_request_id               => reqstid,
8371                                         p_program_id               => progid,
8372                                         p_program_application_id   => appid);
8373         END IF;
8374 
8375         IF l_wip_jsi_insert_flag = 0
8376         THEN
8377           l_wip_jsi_insert_flag := 1;
8378         END IF ;
8379       END LOOP;
8380     ELSE
8381     -- for updating other common wip discrete jobs
8382 
8383       FOR wip_name_for_common_rec in l_wip_name_for_common_cur
8384       LOOP
8385         l_wip_job_name2 := wip_name_for_common_rec.wip_entity_name;
8386         l_wip_last_u_compl_date2 :=  wip_name_for_common_rec.scheduled_completion_date;
8387 
8388 	SELECT wip_job_schedule_interface_s.NEXTVAL INTO  l_wip_header_id
8389         FROM DUAL; --fix bug 5667398 cannot have duplicate header id from same group id
8390 
8391         /* Added for Bug2970539, Bug 3076067 */
8392 
8393         --if (l_wip_bom_revision_date2 > today) then                        --3412747
8394         if (wip_name_for_common_rec.bom_revision_date > today
8395             OR l_wip_bom_revision_date2 IS NULL      -- Added 'OR' condition for Bug #3988681
8396            )
8397         then
8398           l_wip_bom_revision_date2 := wip_name_for_common_rec.bom_revision_date;
8399         end if;
8400         --if (l_wip_routing_revision_date2 > today) then                    --3412747
8401         if (wip_name_for_common_rec.routing_revision_date > today
8402             OR l_wip_routing_revision_date2 IS NULL    -- Added 'OR' condition for Bug #3988681
8403            )
8404         then
8405           l_wip_routing_revision_date2 := wip_name_for_common_rec.routing_revision_date;
8406         end if;
8407 
8408 
8409         INSERT INTO wip_job_schedule_interface
8410            (
8411              last_update_date
8412            , last_updated_by
8413            , creation_date
8414            , created_by
8415            , last_update_login
8416            , request_id
8417            , program_id
8418            , program_application_id
8419            , program_update_date
8420            , group_id
8421            , organization_id
8422            , load_type
8423            , status_type
8424            , primary_item_id
8425            , bom_revision_date
8426            , routing_revision_date
8427            , job_name
8428            , process_phase
8429            , process_status
8430            , last_unit_completion_date
8431            , routing_revision
8432            , bom_revision
8433            , bom_reference_id
8434            , routing_reference_id
8435            , allow_explosion
8436            , alternate_bom_designator
8437            , alternate_routing_designator
8438  	   , completion_subinventory
8439 	   , completion_locator_id
8440            , header_id
8441         )
8442         values
8443         (
8444           sysdate
8445           , userid
8446           , sysdate
8447           , userid
8448           , loginid
8449           , reqstid
8450           , progid
8451           , appid
8452           , sysdate
8453           , l_wip_group_id1
8454           --, l_wip_organization_id                      --3412747
8455           , wip_name_for_common_rec.organization_id
8456           , 3      --l_wip_load_type
8457           , l_wip_status_type
8458           , wip_name_for_common_rec.primary_item_id
8459           --, l_wip_primary_item_id
8460           , l_wip_bom_revision_date2
8461           , decode(l_WIP_Flag_for_routing,'Y',l_wip_routing_revision_date2, null) -- Bug 4455543
8462           , l_wip_job_name2
8463           , l_wip_process_phase
8464           , l_wip_process_status
8465           , decode(l_WIP_Flag_for_routing,'Y',l_wip_last_u_compl_date2, null) -- Bug 4455543
8466           , decode(l_WIP_Flag_for_routing,'Y', nvl(wip_name_for_common_rec.routing_revision,l_wip_routing_revision2) -- Bug 3381547
8467                , null) -- Bug 4455543
8468           , nvl(wip_name_for_common_rec.bom_revision,l_wip_bom_revision2)            -- Bug 3381547
8469           , wip_name_for_common_rec.primary_item_id
8470           , decode(l_WIP_Flag_for_routing,'Y',wip_name_for_common_rec.primary_item_id, null) -- Bug 4455543
8471           --, l_wip_primary_item_id
8472           --, l_wip_primary_item_id
8473           , l_wip_allow_explosion
8474           ,wip_name_for_common_rec.alternate_bom_designator    --2964588
8475           ,wip_name_for_common_rec.alternate_routing_designator    --2964588
8476 	  , l_wip_completion_subinventory   -- Bug 5896479
8477 	  , l_wip_completion_locator_id     -- Bug 5896479
8478           , l_wip_header_id
8479         );
8480 
8481         -- Add components for 'Update Job Only' case
8482         -- Bug No: 5285282
8483         IF l_eco_for_production = 1
8484         THEN
8485           ENTER_WIP_DETAILS_FOR_COMPS ( p_revised_item_sequence_id => item.revised_item_sequence_id,
8486                                         p_group_id                 => l_wip_group_id1,
8487                                         p_parent_header_id         => l_wip_header_id,
8488                                         p_mrp_active               => item.mrp_active,
8489                                         p_user_id                  => userid,
8490                                         p_login_id                 => loginid,
8491                                         p_request_id               => reqstid,
8492                                         p_program_id               => progid,
8493                                         p_program_application_id   => appid);
8494         END IF;
8495 
8496         IF l_wip_jsi_insert_flag = 0
8497         THEN
8498           l_wip_jsi_insert_flag := 1;
8499         END IF ;
8500       END LOOP;
8501     END IF;          -- end of IF NVL(item.start_quantity,0)
8502 
8503   END IF;   -- end of item.update_wip = 1 and NVL...
8504   IF l_wip_jsi_insert_flag = 0
8505   THEN  group_id1 :=  -1;  --- reset out type value
8506     group_id2 :=  -1;  --- reset out type value
8507   END IF;
8508 
8509 
8510 
8511 Exception
8512         When abort_implementation then
8513                 Close get_item_info;
8514 
8515         -- ERES change begins
8516         WHEN ERES_EVENT_ERROR THEN
8517 
8518           FND_MSG_PUB.Get(
8519             p_msg_index  => 1,
8520             p_data       => l_message,
8521             p_encoded    => FND_API.G_FALSE,
8522             p_msg_index_out => l_dummy_cnt);
8523 
8524           FND_FILE.PUT_LINE(FND_FILE.LOG, 'Error while creating event='||l_child_event_name||', key='||l_event.event_key);
8525           FND_FILE.PUT_LINE(FND_FILE.LOG, 'ERES_EVENT_ERROR: '||l_message);
8526           event_acknowledgement('FAILURE');
8527 
8528           IF (msg_qty < max_messages)
8529           THEN
8530             msg_qty := msg_qty + 1;
8531             message_names(msg_qty) := 'ERES_EVENT_ERROR';
8532             token1(msg_qty) := 'CHANGE_ID';
8533             value1(msg_qty) := item.change_id;
8534             translate1(msg_qty) := 0;
8535             token2(msg_qty) := null;
8536             value2(msg_qty) := null;
8537             translate2(msg_qty) := 0;
8538 
8539             msg_qty := msg_qty + 1;
8540             message_names(msg_qty) := l_message;
8541             token1(msg_qty) := 'CHANGE_ID';
8542             value1(msg_qty) := item.change_id;
8543             translate1(msg_qty) := 0;
8544             token2(msg_qty) := null;
8545             value2(msg_qty) := null;
8546             translate2(msg_qty) := 0;
8547           END IF;
8548         -- ERES change ends
8549 
8550         When others then
8551           -- ERES change begins
8552           FND_FILE.PUT_LINE(FND_FILE.LOG, 'Others Error: '||SQLERRM);
8553           event_acknowledgement('FAILURE');
8554           -- ERES change ends
8555 
8556           -- Added for bug 4150069
8557           If c_get_revision%ISOPEN
8558           Then
8559               Close c_get_revision;
8560           End If;
8561           -- End changes for bug 4150069
8562 
8563 
8564                 If msg_qty < max_messages then
8565                         msg_qty := msg_qty + 1;
8566                         message_names(msg_qty) := 'ENG_ORA_ERROR';
8567                         token1(msg_qty) := 'ROUTINE';
8568                         value1(msg_qty) := 'ENGPKLIMP';
8569                         translate1(msg_qty) := 0;
8570                         token2(msg_qty) := 'SQLERRM';
8571                         value2(msg_qty) := substrb(sqlerrm, 1, 80);
8572                         translate2(msg_qty) := 0;
8573                 end if;
8574 
8575 end;
8576 Procedure reverse_standard_bom(
8577         revised_item in eng_revised_items.revised_item_sequence_id%type,
8578         userid  in number,  -- user id
8579         reqstid in number,  -- concurrent request id
8580         appid   in number,  -- application id
8581         progid  in number,  -- program id
8582         loginid in number,  -- login id
8583         bill_sequence_id     in  eng_revised_items.bill_sequence_id%type,
8584         routing_sequence_id  in  eng_revised_items.routing_sequence_id%type,
8585         return_message OUT NOCOPY VARCHAR2,
8586         return_status in OUT NOCOPY NUMBER
8587 
8588      )
8589 IS
8590      i NUMBER := 0;
8591      p_bill_sequence_id           number := bill_sequence_id;
8592      p_routing_sequence_id        number := routing_sequence_id;
8593      p_revised_item_sequence_id   number := revised_item;
8594      l_return_status         VARCHAR2(1);
8595 --     l_mesg_token_Tbl        Error_Handler.Mesg_Token_Tbl_Type;
8596     l_comn_return_status     VARCHAR2(1);
8597     l_comn_Mesg_Token_Tbl    Error_Handler.Mesg_Token_Tbl_Type;
8598 begin
8599 
8600 
8601 
8602  return_status := 0;
8603  return_message:= NULL;
8604 
8605  -- Reverse standard bom is called from ENCACN.opp,
8606  -- If bill sequence id is null, p_bill_sequence_id = -1
8607  IF p_bill_sequence_id <> -1 THEN
8608   --  Delete the related bom_reference_designators  records
8609   --  those records are still expected to show on the window after implementation
8610   --
8611  /* DELETE FROM bom_reference_designators
8612   WHERE component_sequence_id  IN
8613      ( SELECT  component_sequence_id
8614        FROM  bom_inventory_components
8615        WHERE
8616        --fixed  for bug 1870813
8617         revised_item_sequence_id = p_revised_item_sequence_id
8618         ) ;
8619 */
8620  --  Delete the related bom_substitute_components
8621 /*  DELETE FROM bom_substitute_components
8622   WHERE component_sequence_id  IN
8623      ( SELECT  component_sequence_id
8624        FROM  bom_inventory_components
8625        -- fixed  for bug 1870813
8626        WHERE  revised_item_sequence_id = p_revised_item_sequence_id
8627      ) ;
8628 */
8629  -- before delete the related bom_inventory_components records,
8630  -- make the old conponents active again.
8631   FOR i in 1..rev_comp_disable_date_tbl.count
8632   LOOP
8633 
8634     UPDATE bom_components_b--bom_inventory_components
8635     SET
8636                 disable_date = rev_comp_disable_date_tbl(i).disable_date,
8637                 last_update_date = sysdate,
8638                 last_updated_by = userid,
8639                 last_update_login = loginid,
8640                 request_id = reqstid,
8641                 program_application_id = appid,
8642                 program_id = progid,
8643                 program_update_date = sysdate
8644     WHERE component_sequence_id = rev_comp_disable_date_tbl(i).component_seq_id;
8645   END LOOP;
8646   -----------------------------------------------------------
8647   -- R12: Changes for Common BOM Enhancement
8648   -- Step 2.1: Reset Common Component Details that had been updated
8649   -- when implementing the revised item
8650   -----------------------------------------------------------
8651   IF isCommonedBom = 'Y'
8652   THEN
8653       -- For moved pending destination components
8654       Reset_Common_Comp_Details(
8655           x_Mesg_Token_Tbl => l_comn_Mesg_Token_Tbl
8656         , x_return_status  => l_comn_return_status);
8657       -- For copied pending destination components
8658       DELETE FROM bom_components_b
8659       WHERE implementation_date IS NULL -- as pending changes were copied to the new component
8660         AND (bill_sequence_id, old_component_sequence_id) IN
8661                 (SELECT bsb.bill_sequence_id, rbcb.component_sequence_id
8662                    FROM bom_components_b rbcb, bom_structures_b bsb
8663                   WHERE bsb.bill_sequence_id <> p_bill_sequence_id
8664                     AND bsb.source_bill_sequence_id = p_bill_sequence_id
8665                     AND rbcb.bill_sequence_id = bsb.bill_sequence_id
8666                     AND rbcb.revised_item_sequence_id = p_revised_item_sequence_id);
8667   END IF;
8668   -----------------------------------------------------------
8669   -- R12: End Step 2.1: Changes for Common BOM Enhancement --
8670   -----------------------------------------------------------
8671  -- Delete the related bom_inventory_components whose
8672  --  eco_for_production   =  1.
8673   DELETE FROM bom_components_b--bom_inventory_components
8674   WHERE  revised_item_sequence_id = p_revised_item_sequence_id ;
8675 
8676  -- Delete the related eng revised _components whose
8677  --  eco_for_production   =  1.
8678  /* DELETE FROM eng_revised_components
8679   WHERE bill_sequence_id = p_bill_sequence_id
8680   AND   eco_for_production   =  1;
8681 */
8682 
8683 END IF;
8684 
8685   IF p_bill_sequence_id <> -1 THEN
8686  -- Delete all the substitute resources assigned to the operations
8687  -- whose eco_for_production   =  1.
8688 /*  DELETE FROM bom_sub_operation_resources
8689   WHERE operation_sequence_id IN
8690     (  SELECT operation_sequence_id
8691        FROM bom_operation_sequences
8692        WHERE  revised_item_sequence_id = p_revised_item_sequence_id
8693             );
8694 */
8695  -- Delete all the resources assigned to the operations whose
8696  -- eco_for_production   =  1.
8697  /*
8698   DELETE FROM bom_operation_resources
8699   WHERE operation_sequence_id IN
8700     (  SELECT operation_sequence_id
8701        FROM bom_operation_sequences
8702        WHERE  revised_item_sequence_id = p_revised_item_sequence_id
8703          );
8704  */
8705  -- before delete the related operation sequence records,
8706  -- make the old operation active again
8707 
8708   FOR i in 1..rev_op_disable_date_tbl.count
8709   LOOP
8710     UPDATE bom_operation_sequences
8711     SET
8712                 disable_date = rev_op_disable_date_tbl(i).disable_date,
8713                 last_update_date = sysdate,
8714                 last_updated_by = userid,
8715                 last_update_login = loginid,
8716                 request_id = reqstid,
8717                 program_application_id = appid,
8718                 program_id = progid,
8719                 program_update_date = sysdate
8720     WHERE operation_sequence_id = rev_op_disable_date_tbl(i).operation_seq_id;
8721   END LOOP;
8722 
8723  -- Delete the related operation sequence records
8724   DELETE FROM bom_operation_sequences
8725   WHERE  revised_item_sequence_id = p_revised_item_sequence_id;
8726 
8727  -- Delete the related revised operation sequence records
8728  /* DELETE FROM eng_revised_operations
8729   WHERE routing_sequence_id = p_routing_sequence_id
8730   AND   eco_for_production   =  1;
8731 */
8732  END IF;
8733 
8734 
8735 --Delete the related routing revision record
8736 --  DELETE FROM mtl_rtg_item_revisions
8737 --  WHERE  inventory_item_id = p_revised_item
8738 --  AND    organization_id   = p_organization_id
8739 --  AND    process_revision  = p_new_routing_revision;
8740 
8741 
8742  Exception
8743       When others then
8744                         return_status := 1;
8745                         return_message  :=  substrb(sqlerrm, 1, 80);
8746      end;
8747 
8748  -- Generate new wip job names
8749  PROCEDURE Generate_New_Wip_Name
8750       (
8751        p_wip_entity_name   IN VARCHAR2
8752       ,p_organization_id   IN NUMBER
8753       ,x_wip_entity_name1  OUT NOCOPY VARCHAR2
8754       ,x_wip_entity_name2  OUT NOCOPY VARCHAR2
8755       ,x_return_status     OUT NOCOPY NUMBER
8756      )
8757   IS
8758   l_wip_entity_name  VARCHAR2(240);
8759   l_dummy VARCHAR2(1);
8760   i NUMBER :=0;
8761   l_count  NUMBER := 0;
8762 
8763   CURSOR wip_job_name_cur
8764      (  l_wip_entity_name IN VARCHAR2,
8765         l_organization_id IN NUMBER
8766      )
8767   IS
8768   SELECT '1'
8769   FROM DUAL
8770   WHERE NOT EXISTS
8771   (SELECT 1
8772    FROM  WIP_ENTITIES
8773    WHERE organization_id = l_organization_id
8774    AND   wip_entity_name = l_wip_entity_name)
8775   ;
8776 
8777   wip_job_name_rec wip_job_name_cur%rowtype;
8778 
8779 BEGIN
8780 
8781     WHILE l_count <> 2
8782     LOOP
8783        i := i + 1;
8784        l_wip_entity_name := p_wip_entity_name ||'_' ||  to_char(i);
8785        l_dummy := 0;
8786        OPEN wip_job_name_cur
8787             (  l_wip_entity_name,
8788                p_organization_id
8789             );
8790 
8791        FETCH wip_job_name_cur INTO l_dummy;
8792        IF wip_job_name_cur%FOUND
8793        THEN
8794           l_count := l_count + 1;
8795           IF l_count = 1
8796           THEN x_wip_entity_name1 :=  l_wip_entity_name ;
8797           ELSIF  l_count = 2
8798           THEN x_wip_entity_name2 :=  l_wip_entity_name ;
8799           END IF;
8800        END IF;
8801 
8802        CLOSE  wip_job_name_cur;
8803     END LOOP;
8804 
8805     x_return_status := 0;
8806 
8807  END generate_new_wip_name;
8808 
8809 Procedure implement_revised_item(
8810         revised_item in eng_revised_items.revised_item_sequence_id%type,
8811         trial_mode in number,
8812         max_messages in number, -- size of host arrays
8813         userid  in number,  -- user id
8814         reqstid in number,  -- concurrent request id
8815         appid   in number,  -- application id
8816         progid  in number,  -- program id
8817         loginid in number,  -- login id
8818         bill_sequence_id        OUT NOCOPY eng_revised_items.bill_sequence_id%type ,
8819         routing_sequence_id     OUT NOCOPY eng_revised_items.routing_sequence_id%type ,
8820         eco_for_production      OUT NOCOPY eng_revised_items.eco_for_production%type ,
8821         revision_high_date      OUT NOCOPY mtl_item_revisions.effectivity_date%type,
8822         rtg_revision_high_date  OUT NOCOPY mtl_rtg_item_revisions.effectivity_date%type,
8823         update_wip              OUT NOCOPY eng_revised_items.update_wip%type ,
8824         group_id1               OUT NOCOPY wip_job_schedule_interface.group_id%type,
8825         group_id2               OUT NOCOPY wip_job_schedule_interface.group_id%type,
8826         wip_job_name1           OUT NOCOPY wip_entities.wip_entity_name%type,
8827         wip_job_name2           OUT NOCOPY wip_entities.wip_entity_name%type,
8828         wip_job_name2_org_id    OUT NOCOPY wip_entities.organization_id%type,
8829         message_names OUT NOCOPY NameArray,
8830         token1 OUT NOCOPY NameArray,
8831         value1 OUT NOCOPY StringArray,
8832         translate1 OUT NOCOPY BooleanArray,
8833         token2 OUT NOCOPY NameArray,
8834         value2 OUT NOCOPY StringArray,
8835         translate2 OUT NOCOPY BooleanArray,
8836         msg_qty in OUT NOCOPY binary_integer,
8837         warnings in OUT NOCOPY number) is
8838 
8839   l_is_revised_item_change      NUMBER;
8840   l_now                         DATE;
8841   l_status_code                 NUMBER := 6;
8842   l_plm_or_erp_change           VARCHAR2(3);
8843   l_return_status               VARCHAR2(2000);
8844   l_msg_data                    VARCHAR2(2000);
8845   l_change_type_id              NUMBER;
8846   l_change_id                   NUMBER;
8847   l_approval_status             NUMBER;
8848   l_msg_count                   NUMBER := 0;
8849   l_message_name                VARCHAR2(50);
8850   l_message_desc                VARCHAR2(100);
8851   /*
8852   Cursor to fetch all the sub revised items diven the revised item sequence id
8853   In ERP, only one revised item exists.
8854   In PLM, sub revised items may exist given a parent revised item sequence id
8855   */
8856 
8857   CURSOR c_revised_items_all is
8858   SELECT *
8859   FROM eng_revised_items
8860   WHERE (revised_item_sequence_id = revised_item
8861   /*OR parent_revised_item_seq_id = revised_item*/)
8862   AND status_type <> 5; -- to remove cancelled revised items
8863 
8864   l_plsql_block VARCHAR2(2000);
8865   l_implementation_status VARCHAR2(30);
8866 
8867   abort_implementation exception;
8868 
8869 BEGIN
8870         l_now := sysdate;
8871 
8872         -- Get the change id
8873         SELECT change_id
8874         INTO l_change_id
8875         FROM eng_revised_items
8876         WHERE revised_item_sequence_id = revised_item;
8877 
8878         -- Get whether it is a plm or erp change
8879         SELECT  nvl(plm_or_erp_change, 'PLM')
8880         INTO l_plm_or_erp_change
8881         FROM eng_engineering_changes
8882         WHERE change_id = l_change_id;
8883 
8884         -- Bug : 3446554 Determine the status code for PLM records
8885         IF(l_plm_or_erp_change = 'PLM')
8886         THEN
8887                 -- In the PLM change lifecycle - 11.5.10 - the last phase will be implemented
8888                 -- there will be only one implemented phase
8889                 -- and scheduled phase is always followed by implemented
8890                 -- All scheduled revised items will be picked for implementation on auto-implement
8891 
8892                 SELECT els1.status_code
8893                 INTO l_status_code
8894                 FROM eng_lifecycle_statuses els1
8895                 WHERE els1.entity_id1 = l_change_id
8896                 AND els1.entity_name = 'ENG_CHANGE'
8897                 AND els1.active_flag = 'Y' -- added for bug 3553682
8898                 AND els1.sequence_number = (SELECT max(els2.sequence_number)
8899                                         FROM eng_lifecycle_statuses els2
8900                                         WHERE els2.entity_id1 = l_change_id
8901                                         AND els2.entity_name = 'ENG_CHANGE'
8902                                         AND els2.active_flag = 'Y');  -- added for bug 3553682
8903 
8904         END IF;
8905 
8906         FOR ri IN c_revised_items_all
8907         LOOP
8908                --   Check if change policy allows change order / revised item to be implemented
8909                Can_Implement_Item( p_change_line_id => ri.revised_item_sequence_id,
8910                                    x_implementation_status => l_implementation_status);
8911 
8912                IF l_implementation_status = 'NO' THEN
8913                     Raise abort_implementation;
8914                END IF;
8915 
8916 
8917                 IF (ri.transfer_or_copy IS NULL)
8918                 THEN
8919                         l_is_revised_item_change := 1;
8920                 ELSE
8921                         l_is_revised_item_change := 2;
8922                 END IF;
8923 
8924                 --
8925                 -- For PLM
8926                 -- Check if the revised item is the parent
8927                 -- then it has lifecycle phase change associalted with it
8928                 --
8929                 IF (ri.parent_revised_item_seq_id IS NULL
8930                         AND ri.transfer_or_copy IS NOT NULL
8931                         AND ri.enable_item_in_local_org IS NOT NULL)
8932                 THEN
8933                         l_is_revised_item_change := 1;
8934                 END IF;
8935 
8936                 select approval_status_type into l_approval_status
8937                 from   eng_engineering_changes
8938                 where  change_id = l_change_id;
8939 
8940                 -- First trying to implement the revised item attachment changes
8941                 -- Changes For bug 3402607
8942                 BEGIN
8943                 l_return_status := FND_API.G_RET_STS_SUCCESS;
8944                 /*ENG_ATTACHMENT_IMPLEMENTATION.Implement_Attachment_Change(
8945                         p_api_version   => 1.0
8946                         ,p_change_id    => l_change_id
8947                         ,p_rev_item_seq_id      =>revised_item
8948                         ,x_return_status        => l_return_status
8949                         ,x_msg_count            => l_msg_count
8950                         ,x_msg_data             => l_msg_data
8951                         ,P_APPROVAL_STATUS      => l_approval_status);*/
8952                     l_plsql_block := 'begin ENG_ATTACHMENT_IMPLEMENTATION.Implement_Attachment_Change('
8953                                     || '   p_api_version     => 1.0  '
8954                                     || ' , p_change_id       => :1   '
8955                                     || ' , p_rev_item_seq_id => :2   '
8956                                     || ' , x_return_status   => :3   '
8957                                     || ' , x_msg_count       => :4   '
8958                                     || ' , x_msg_data        => :5   '
8959                                     || ' , p_approval_status => :6); '
8960                                     || ' end;';
8961                     EXECUTE IMMEDIATE l_plsql_block USING IN l_change_id, IN revised_item, OUT l_return_status
8962                                                         , OUT l_msg_count, OUT l_msg_data, IN  l_approval_status;
8963 
8964                 IF l_return_status = 'E' THEN
8965                   l_message_name := 'ENG_ATTACHMENT_IMP_ERROR';
8966                   l_message_desc := 'Attachment Changes implementation failed';
8967                   FND_FILE.PUT_LINE(FND_FILE.LOG, l_msg_data);
8968                 END IF;
8969 
8970                 EXCEPTION
8971                 WHEN OTHERS THEN
8972                     FND_FILE.PUT_LINE(FND_FILE.LOG, 'Attachment Changes Implementation Failed'||SQLERRM);
8973                     l_message_name := 'ENG_ATTACHMENT_IMP_ERROR';
8974                     l_message_desc := 'Attachment Changes implementation failed';
8975                     goto error_block;
8976                 END;
8977 
8978                 -- Also implement item related document here. Both attachment changes and item related document
8979                 -- changes do not have any date effectivity, that is why it is added here..only when attachment impl is successfull
8980                 BEGIN
8981 		IF (NVL(l_return_status, FND_API.G_RET_STS_ERROR) = FND_API.G_RET_STS_SUCCESS)
8982                   THEN
8983 			  l_return_status := FND_API.G_RET_STS_SUCCESS;
8984 
8985 			  l_plsql_block := 'begin ENG_RELATED_ENTITY_PKG.Implement_Relationship_Changes('
8986 					    || '   p_api_version     => 1.0  '
8987 					    || ' , p_change_id       => :1   '
8988 					    || ' , p_entity_id       => :2   '
8989 					    || ' , x_return_status   => :3   '
8990 					    || ' , x_msg_count       => :4   '
8991 					    || ' , x_msg_data        => :5); '
8992 					    || ' end;';
8993 			    EXECUTE IMMEDIATE l_plsql_block
8994 			     USING IN l_change_id, IN revised_item,
8995 			       OUT l_return_status, OUT l_msg_count, OUT l_msg_data;
8996 
8997 			IF l_return_status = 'E' THEN
8998 			  l_message_name := 'ENG_RELATED_ENTITY_IMP_ERROR';
8999 			  l_message_desc := 'Related Entity Changes implementation failed';
9000 			  FND_FILE.PUT_LINE(FND_FILE.LOG, l_msg_data);
9001 			END IF;
9002                 END IF;
9003                 EXCEPTION
9004 		-- Don't throw an exception when package not found.
9005 		WHEN PLSQL_COMPILE_ERROR THEN
9006 		    null;
9007 		WHEN OTHERS THEN
9008                     FND_FILE.PUT_LINE(FND_FILE.LOG, 'Related Entity Changes Implementation Failed'||SQLERRM);
9009                     l_message_name := 'ENG_RELATED_ENTITY_IMP_ERROR';
9010                     l_message_desc := 'Related Entity Changes implementation failed';
9011                     goto error_block;
9012                 END;
9013 
9014                 << error_block >>
9015                   null;
9016 
9017                 BEGIN
9018                   IF (NVL(l_return_status, FND_API.G_RET_STS_ERROR) <> FND_API.G_RET_STS_SUCCESS)
9019                   THEN
9020                         msg_qty := msg_qty + 1;
9021                         token1(msg_qty) := null;
9022                         value1(msg_qty) := null;
9023                         translate1(msg_qty) := 0;
9024                         token2(msg_qty) := null;
9025                         value2(msg_qty) := null;
9026                         translate2(msg_qty) := 0;
9027                         message_names(msg_qty) := l_message_name;
9028                         FOR I IN 1..l_msg_count
9029                         LOOP
9030                                 FND_FILE.NEW_LINE(FND_FILE.LOG);
9031                                 FND_FILE.PUT_LINE(FND_FILE.LOG, l_message_desc);
9032                                 FND_FILE.PUT_LINE(FND_FILE.LOG, FND_MSG_PUB.get(I, 'F'));
9033 
9034                         END LOOP;
9035                   ELSE
9036 
9037                         implement_revised_item(
9038                          revised_item           => ri.revised_item_sequence_id
9039                         , trial_mode            => trial_mode
9040                         , max_messages          => max_messages
9041                         , userid                => userid
9042                         , reqstid               => reqstid
9043                         , appid                 => appid
9044                         , progid                => progid
9045                         , loginid               => loginid
9046                         , bill_sequence_id      => bill_sequence_id
9047                         , routing_sequence_id   => routing_sequence_id
9048                         , eco_for_production    => eco_for_production
9049                         , revision_high_date    => revision_high_date
9050                         , rtg_revision_high_date => rtg_revision_high_date
9051                         , update_wip            => update_wip
9052                         , group_id1             => group_id1
9053                         , group_id2             => group_id2
9054                         , wip_job_name1         => wip_job_name1
9055                         , wip_job_name2         => wip_job_name2
9056                         , wip_job_name2_org_id  => wip_job_name2_org_id
9057                         , message_names         => message_names
9058                         , token1                => token1
9059                         , value1                => value1
9060                         , translate1            => translate1
9061                         , token2                => token2
9062                         , value2                => value2
9063                         , translate2            => translate2
9064                         , msg_qty               => msg_qty
9065                         , warnings              => warnings
9066                         , p_is_lifecycle_phase_change => l_is_revised_item_change
9067                         , p_now                 => l_now
9068                         , p_status_code         => l_status_code) ;
9069 
9070                 END IF;
9071                 IF (msg_qty > warnings)
9072                 THEN
9073                         exit;
9074                 END IF;
9075              END;
9076         END LOOP;
9077 
9078 END implement_revised_item;
9079 
9080 --Bug No: 4767315 starts procedure to implement ecos wo any unimplemented revised items
9081 --(deviating from basebug by putting procedure in pls file for easier maintenance. )
9082 Procedure implement_eco_wo_revised_item(
9083 		p_change_notice in varchar2,
9084 		temp_organization_id in varchar2)
9085 is
9086 l_implement_header varchar2(1);
9087 
9088 -- cursor for finding the ecos which can be implemented as all revised items are implemented
9089 -- or to return values corresponding to the eco that is being manually implemented.
9090 
9091 CURSOR C_IMPL_CUR IS
9092 	select change_notice,change_id,organization_id,
9093 	       nvl(plm_or_erp_change, 'PLM') l_plm_or_erp_change,
9094 	       status_code curr_status_code
9095 	    from eng_engineering_changes e
9096 	    where to_char(e.organization_id) = temp_organization_id
9097 	    AND ((p_change_notice IS NULL  and e.STATUS_TYPE = 4 )  -- scheduled
9098                 OR (p_change_notice IS NOT NULL AND E.CHANGE_NOTICE = p_change_notice))
9099 	    AND   e.APPROVAL_STATUS_TYPE <> 4 --eco rejected
9100 	    and e.status_type not in (5,6)
9101 	    and not exists (select 1 from eng_revised_items r
9102                    where r.change_notice = e.change_notice
9103                    and r.organization_id = e.organization_id
9104                    and r.status_type not in (5,6))
9105 	    and exists (select 1 from eng_revised_items r1
9106                    where r1.change_notice = e.change_notice
9107                    and r1.organization_id = e.organization_id
9108                    and r1.status_type = 6);
9109 
9110 IMPL C_IMPL_CUR%rowtype;
9111 
9112 BEGIN
9113 savepoint implement_eco_wo_revised_item;
9114 -- Check if implementation of header is allowed or not for the current phase
9115 OPEN C_IMPL_CUR;
9116 loop
9117 FETCH C_IMPL_CUR INTO IMPL;
9118 EXIT WHEN C_IMPL_CUR%NOTFOUND;
9119 l_implement_header:='T';
9120 l_implement_header := check_header_impl_allowed(
9121 		p_change_id => IMPL.change_id,
9122 		p_change_notice => IMPL.change_notice,
9123 		p_status_code => 6,
9124 		p_curr_status_code => IMPL.curr_status_code,
9125 		p_plm_or_erp_change => IMPL.l_plm_or_erp_change,
9126 		p_request_id => fnd_global.conc_request_id);
9127 
9128 -- If Header can be implemented, then go ahead.
9129 
9130 IF (l_implement_header = 'T')
9131 THEN
9132  -- update eco to status implemented
9133 UPDATE
9134     ENG_ENGINEERING_CHANGES
9135     SET STATUS_TYPE = 6,
9136     STATUS_CODE=6,
9137     IMPLEMENTATION_DATE = SYSDATE,
9138     LAST_UPDATE_DATE = SYSDATE,
9139     LAST_UPDATED_BY = fnd_global.user_id,
9140     LAST_UPDATE_LOGIN = fnd_global.login_id,
9141     REQUEST_ID = fnd_global.conc_request_id,
9142     PROGRAM_APPLICATION_ID = fnd_global.prog_appl_id,
9143     PROGRAM_ID = fnd_global.conc_program_id,
9144     PROGRAM_UPDATE_DATE = SYSDATE,
9145     promote_status_code = null
9146 WHERE CHANGE_NOTICE = IMPL.change_notice
9147     AND ORGANIZATION_ID = IMPL.organization_id;
9148 
9149 -- Complete the last phase in the lifecycle
9150 
9151 UPDATE
9152     eng_lifecycle_statuses
9153     SET start_date = nvl(start_date,sysdate), -- set the start date on implemented phase after promoting the header to implemented phase
9154     completion_date = sysdate,
9155     last_update_date = sysdate,
9156     last_updated_by = fnd_global.user_id,
9157     last_update_login = fnd_global.login_id
9158 WHERE entity_name = 'ENG_CHANGE'
9159     AND entity_id1 =
9160     (
9161     SELECT
9162         change_id
9163     FROM eng_engineering_changes
9164     WHERE organization_id = IMPL.organization_id
9165         AND change_notice = IMPL.change_notice
9166     )
9167     AND active_flag = 'Y'
9168     AND sequence_number =
9169     (
9170     SELECT
9171         max(sequence_number)
9172     FROM eng_lifecycle_statuses
9173     WHERE entity_name = 'ENG_CHANGE'
9174         AND entity_id1 =
9175         (
9176         SELECT
9177             change_id
9178         FROM eng_engineering_changes
9179         WHERE organization_id = IMPL.organization_id
9180             AND change_notice = IMPL.change_notice
9181         ) );
9182 
9183 END IF;
9184 end loop;
9185 close C_IMPL_CUR;
9186 EXCEPTION
9187 WHEN OTHERS THEN
9188     IF C_IMPL_CUR%ISOPEN THEN
9189       CLOSE C_IMPL_CUR;
9190     END IF;
9191 rollback to savepoint implement_eco_wo_revised_item;
9192 END implement_eco_wo_revised_item;
9193 
9194 --Bug No: 4767315 fix ends
9195 end ENGPKIMP;