DBA Data[Home] [Help]

PACKAGE BODY: APPS.ENGECOBO

Source


1 PACKAGE BODY ENGECOBO AS
2 /* $Header: ENGECOBB.pls 120.26.12000000.5 2007/05/03 10:18:46 arattan ship $ */
3 
4 ---------------------------------------------------------------
5 --  Global constant holding the package name                 --
6 ---------------------------------------------------------------
7 G_PKG_NAME                  CONSTANT VARCHAR2(30) := 'ENGECOBO';
8 
9 ---------------------------------------------------------------
10 --  Global constants                                         --
11 ---------------------------------------------------------------
12 G_VAL_NOT_EXISTS CONSTANT NUMBER := 0;
13 G_VAL_EXISTS     CONSTANT NUMBER := 1;
14 
15 G_VAL_FALSE CONSTANT NUMBER := 0;
16 G_VAL_TRUE CONSTANT NUMBER := 1;
17 
18 ---------------------------------------------------------------
19 --  DB hardcoded values                                      --
20 ---------------------------------------------------------------
21  G_PROPAGATED_TO  CONSTANT VARCHAR2(15) := 'PROPAGATED_TO';
22  G_ENG_CHANGE     CONSTANT VARCHAR2(10) := 'ENG_CHANGE';
23  G_LOG_PROC       CONSTANT NUMBER := 2;
24  G_LOG_STMT       CONSTANT NUMBER := 1;
25 ---------------------------------------------------------------
26 --  Global variables                                         --
27 ---------------------------------------------------------------
28  g_global_change_id     NUMBER;
29  g_global_org_id        NUMBER;
30  G_STATUS_CONTROL_LEVEL NUMBER;
31 ---------------------------------------------------------------
32 -- User Defined Exception
33 ---------------------------------------------------------------
34 EXC_EXP_SKIP_OBJECT     EXCEPTION;
35 EXC_ERR_PVT_API_MAIN    EXCEPTION;
36 ---------------------------------------------------------------
37 --  Global Types Declaration                                 --
38 ---------------------------------------------------------------
39 TYPE Eco_Struc_Line_rec_Type IS RECORD
40  (
41     Revised_item_sequence_id    NUMBER
42   , bill_sequence_id        NUMBER
43   , alternate_bom_designator    VARCHAR2(10)
44   , local_bill_sequence_id  NUMBER
45   , comn_bill_sequence_id   NUMBER
46   , from_end_item_minor_rev_id   NUMBER
47   , from_end_item_rev_id    NUMBER
48  );
49 
50  TYPE Eco_Struc_Line_Tbl_Type IS TABLE OF Eco_Struc_Line_rec_Type
51     INDEX BY BINARY_INTEGER;
52 
53  /*TYPE Eco_Error_rec_Type IS RECORD
54  (
55     Revised_item_sequence_id   NUMBER
56   , revised_line_type          VARCHAR2(20)
57   , revised_line_id1           NUMBER
58   , log_text                VARCHAR2(2000)
59   , log_type                VARCHAR2(10)
60  );
61 
62 TYPE Eco_Error_Tbl_Type IS TABLE OF Eco_Error_rec_Type
63     INDEX BY BINARY_INTEGER;
64 
65 TYPE Prop_Rev_Items_Tbl_Type IS TABLE OF NUMBER
66     INDEX BY BINARY_INTEGER;*/
67 
68 ---------------------------------------------------------------
69 --  Start functions and Procedures Here                      --
70 ---------------------------------------------------------------
71 -- Bug : 5356082
72 /*
73 The problem is that the document_id for each attachment in the
74 master org and child org for the same item is not same.
75 The previous logic for propogation was written in such a way that the item
76 attachments will be queried in the child organization with the same
77 document_id as in master organization.
78 Since because of the document_id's are different it was not able to find the
79 attachments in the child organization.
80 Now, we need to somehow match the attachments in the master organization to
81 the attachment in the child organization.
82 Steps :
83      1. Get the media_id, node_id for the master org item attachments
84      2. Get the repository type
85      3. If repository type is web services, compare master org item attachment media id with that of child org item.
86      4. If repository is webdav, compare master org item attachment file and folder path with that of child org item.
87 This function should be called for item attachment changes other than Attach to get the correct existing document_id.
88 */
89 FUNCTION Get_Child_Org_Item_AttId
90 (
91    p_item_id                  IN   NUMBER
92  , p_item_revision_id         IN   NUMBER
93  , p_master_org_id            IN   NUMBER
94  , p_master_org_document_id   IN   NUMBER
95  , p_child_org_id             IN   NUMBER
96 )
97 RETURN NUMBER IS
98      l_master_item_media_id        FND_DOCUMENTS.MEDIA_ID%TYPE;
99      l_master_item_node_id         FND_DOCUMENTS.DM_NODE%TYPE;
100      l_master_item_folder_path     FND_DOCUMENTS.DM_FOLDER_PATH%TYPE;
101      l_master_item_file_name       FND_DOCUMENTS.FILE_NAME%TYPE;
102      l_master_item_dm_doc_id       FND_DOCUMENTS.DM_DOCUMENT_ID%TYPE;
103 
104      l_item_attachment_protocol    DOM_REPOSITORIES.PROTOCOL%TYPE;
105      l_child_item_media_id         FND_DOCUMENTS.MEDIA_ID%TYPE;
106      l_child_org_document_id       FND_DOCUMENTS.DOCUMENT_ID%TYPE;
107      l_child_item_folder_path      FND_DOCUMENTS.DM_FOLDER_PATH%TYPE;
108      l_child_item_file_name        FND_DOCUMENTS.FILE_NAME%TYPE;
109      l_master_folder_and_file      VARCHAR2(3500);     --   DM_FOLDER_PATH || '/' || FILE_NAME
110 BEGIN
111      --   Get the master item attachments information
112      SELECT dm_node, media_id, dm_folder_path, file_name, dm_document_id
113      INTO l_master_item_node_id, l_master_item_media_id, l_master_item_folder_path, l_master_item_file_name, l_master_item_dm_doc_id
114      FROM fnd_documents
115      WHERE document_id = p_master_org_document_id;
116      l_master_folder_and_file := l_master_item_folder_path || '/' || l_master_item_file_name;
117 
118      --   Get the Protocol
119      SELECT protocol INTO l_item_attachment_protocol FROM dom_repositories WHERE id = l_master_item_node_id;
120 
121      --   If web services, then we have to compare the media and node ids of master org item attachments
122      --   with child org item attachments
123      IF l_item_attachment_protocol = 'WEBSERVICES' THEN
124           BEGIN
125                SELECT b.document_id, nvl(a.media_id , a.dm_document_id)
126                INTO l_child_org_document_id, l_child_item_media_id
127                FROM fnd_documents a, fnd_attached_documents b
128                WHERE b.document_id = a.document_id AND
129                     b.pk2_value = p_item_id AND
130                     b.pk1_value = p_child_org_id AND
131                     b.pk3_value = p_item_revision_id AND
132                     ( (l_master_item_media_id IS NOT NULL AND a.media_id = l_master_item_media_id) OR      -- file
133                       (l_master_item_media_id IS NULL AND a.dm_document_id = l_master_item_dm_doc_id))AND  -- folder
134                     a.dm_node = l_master_item_node_id;
135 
136           EXCEPTION
137                WHEN OTHERS THEN
138                     l_child_org_document_id := -1;
139           END;
140      END IF;
141 
142      --   If web dav, then we have to compare the folder and file name of master org item attachments
143      --   with child org item attachments
144      IF l_item_attachment_protocol = 'WEBDAV' THEN
145           BEGIN
146                SELECT b.document_id, a.dm_folder_path, a.file_name
147                INTO l_child_org_document_id, l_child_item_folder_path, l_child_item_file_name
148                FROM fnd_documents a, fnd_attached_documents b
149                WHERE b.document_id = a.document_id AND
150                     b.pk2_value = p_item_id AND
151                     b.pk1_value = p_child_org_id AND
152                     b.pk3_value = p_item_revision_id AND
153                     (a.dm_folder_path || '/' || a.file_name) = l_master_folder_and_file AND
154                     a.dm_node = l_master_item_node_id;
155 --FND_FILE.PUT_LINE(FND_FILE.LOG, 'MMITC : WEBDAV : ' || l_child_org_document_id );
156                --   Only one row should be found
157                l_child_org_document_id := l_child_org_document_id;
158           EXCEPTION
159                WHEN OTHERS THEN    --   when no data found or if it returns more than one row
160 --FND_FILE.PUT_LINE(FND_FILE.LOG, 'MMITC : WEBDAV Exception : ' || SQLERRM );
161                     l_child_org_document_id := -1;
162           END;
163      END IF;
164 
165      RETURN l_child_org_document_id;
166 
167 EXCEPTION
168      WHEN OTHERS THEN
169           FND_FILE.PUT_LINE(FND_FILE.LOG, 'MMITC : Main Exception : ' ||SQLERRM );
170 
171 END Get_Child_Org_Item_AttId;
172 
173 PROCEDURE Propagated_Local_Change (
174     p_change_id             IN NUMBER
175   , p_local_organization_id IN NUMBER
176   , x_local_change_id       OUT NOCOPY NUMBER
177 ) IS
178 
179     CURSOR c_local_change_order IS
180     SELECT eec.change_id
181       FROM eng_engineering_changes eec
182          , eng_change_obj_relationships ecor
183      WHERE eec.change_id = ecor.object_to_id1
184        AND ecor.relationship_code IN ( 'PROPAGATED_TO', 'TRANSFERRED_TO' )
185        AND ecor.object_to_name ='ENG_CHANGE'
186        AND ecor.object_to_id3 = p_local_organization_id
187        AND ecor.change_id = p_change_id;
188 
189 BEGIN
190     OPEN c_local_change_order;
191     FETCH c_local_change_order INTO x_local_change_id;
192     CLOSE c_local_change_order;
193 EXCEPTION
194 WHEN OTHERS THEN
195     IF c_local_change_order%ISOPEN
196     THEN
197         CLOSE c_local_change_order;
198     END IF;
199     x_local_change_id := NULL;
200 
201 END Propagated_Local_Change;
202 
203 FUNCTION Get_local_org_attachment_id (
204     p_local_entity_name  IN VARCHAR2 -- MTL_ITEM_REVISIONS or MTL_SYSTEM_ITEMS
205   , p_local_pk1_value    IN VARCHAR2  -- Org_id
206   , p_local_pk2_value    IN VARCHAR2  -- item id
207   , p_local_pk3_value    IN VARCHAR2  -- current item_revision_id
208   , p_global_document_id IN NUMBER
209   , x_att_status         IN OUT NOCOPY VARCHAR2 -- Bug 3599366
210 ) RETURN NUMBER IS
211 
212   l_local_attachment_id NUMBER := -1;
213 
214   CURSOR c_local_attachment
215   IS
216   SELECT fad.attached_document_id, fad.status
217     FROM fnd_documents_vl fdv, fnd_attached_documents fad
218    WHERE fdv.document_id = fad.document_id
219      AND fad.entity_name = p_local_entity_name
220      AND fad.pk1_value= p_local_pk1_value
221      AND fad.pk2_value = p_local_pk2_value
222      AND fad.pk3_value = p_local_pk3_value
223      AND (fdv.document_id = p_global_document_id
224           OR
225           (fdv.document_id <> p_global_document_id
226            AND ( Nvl(fdv.dm_folder_path, '*NULL*'), fdv.dm_node, fdv.file_name)=
227                (SELECT Nvl(dm_folder_path, '*NULL*'), dm_node, file_name
228                   FROM fnd_documents_vl
229                  WHERE document_id = p_global_document_id)
230           )
231           OR
232           (fdv.document_id <> p_global_document_id
233            AND fdv.dm_node = 0
234            AND (fdv.file_name, fdv.datatype_id) =
235                (SELECT file_name, datatype_id
236                   FROM fnd_documents_vl
237                  WHERE document_id = p_global_document_id)
238           )
239          );
240 
241 BEGIN
242     OPEN c_local_attachment;
243     FETCH c_local_attachment INTO l_local_attachment_id
244                                 , x_att_status; -- Bug 3599366
245     CLOSE c_local_attachment;
246     RETURN l_local_attachment_id;
247 
248 EXCEPTION
249 WHEN OTHERS THEN
250     IF c_local_attachment%ISOPEN
251     THEN
252         CLOSE c_local_attachment;
253     END IF;
254     RETURN -1;
255 END Get_local_org_attachment_id;
256 
257 PROCEDURE Propagate_Attach_Lines (
258     p_change_id                IN NUMBER
259   , p_revised_item_sequence_id IN NUMBER
260   , p_revised_item_rec         IN Eng_Eco_Pub.Revised_Item_Rec_Type
261   , p_revised_item_unexp_rec   IN Eng_Eco_Pub.Rev_Item_Unexposed_Rec_Type
262   , p_local_organization_id    IN NUMBER
263   , p_local_line_rev_id        IN NUMBER
264   , x_return_status            OUT NOCOPY VARCHAR2
265   , x_mesg_token_tbl           IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
266 ) IS
267   l_msg_count           NUMBER;
268   l_msg_data            VARCHAR2(2000);
269   l_return_status       VARCHAR2(3);
270 
271   l_local_change_id     NUMBER;
272   l_local_attachment_id NUMBER := -1;
273   l_pk3_value           VARCHAR2(100);
274   l_change_document_id  NUMBER;
275   l_local_att_status    fnd_attached_documents.status%TYPE; -- Bug 3599366
276   l_temp_document_id    NUMBER;
277 
278   CURSOR c_attachment_changes (cp_revised_item_sequence_id NUMBER)
279   IS
280   SELECT eac.action_type, eac.attachment_id, eac.source_document_id, eac.SOURCE_VERSION_LABEL
281        , eac.SOURCE_PATH, eac.DEST_DOCUMENT_ID, eac.DEST_VERSION_LABEL, eac.DEST_PATH
282        , eac.CHANGE_DOCUMENT_ID, eac.entity_name, eac.pk1_value, eac.pk2_value, eac.pk3_value
283        , decode(eac.action_type, 'ATTACH', eac.source_document_id,fad.document_id) document_id
284        , eac.FAMILY_ID, eac.REPOSITORY_ID, eac.PK4_VALUE, eac.PK5_VALUE, eac.NEW_FILE_NAME
285        , eac.DESCRIPTIOn, eac.NEW_DESCRIPTIOn, eac.NEW_CATEGORY_ID
286   FROM eng_attachment_changes eac, fnd_attached_documents fad
287   WHERE eac.change_id = p_change_id -- 4517503
288   AND eac.revised_item_sequence_id = cp_revised_item_sequence_id
289   AND eac.attachment_id =  fad.attached_document_id(+)
290   AND (eac.entity_name = 'MTL_ITEM_REVISIONS'
291         OR (eac.entity_name = 'MTL_SYSTEM_ITEMS'
292         AND NOT EXISTS (SELECT 1 FROM MTL_PARAMETERS MP
293             WHERE MP.organization_id = g_global_org_id
294             AND MP.master_organization_id = MP.organization_id)
295     ))
296   AND NOT EXISTS (SELECT 1 FROM eng_change_propagation_maps ecpm
297                    WHERE ecpm.change_id = p_change_id
298                      AND ecpm.local_organization_id = p_local_organization_id
299                      AND ecpm.revised_line_type = Eng_Propagation_Log_Util.G_REV_LINE_ATCH_CHG
300                      AND ecpm.revised_line_id1 = eac.change_document_id
301                      AND ecpm.entity_action_status = 3);
302 
303   CURSOR c_attachment_details(cp_attached_document_id IN NUMBER
304                             , cp_attach_action_type   IN eng_attachment_changes.action_type%TYPE
305                             , cp_change_document_id   IN NUMBER)
306   IS
307   SELECT fad.category_id, fad.status, fad.document_id
308        , fad.attached_document_id, fdv.file_name, fad.last_updated_by
309        , fdv.dm_type, fdv.datatype_id, fdv.document_id source_document_id
310     FROM fnd_attached_documents fad, fnd_documents_vl fdv
311    WHERE fad.attached_document_id = cp_attached_document_id
312      AND fad.document_id = fdv.document_id
313      AND cp_attach_action_type <> 'ATTACH'
314   UNION ALL
315   SELECT eac.category_id, eac.previous_status, eac.source_document_id
316        , eac.attachment_id, eac.file_name, eac.last_updated_by
317        , eac.dm_type, eac.datatype_id, eac.source_document_id
318     FROM eng_attachment_changes eac, fnd_documents_vl fdv
319    WHERE eac.change_document_id =  cp_change_document_id
320      AND eac.source_document_id = fdv.document_id
321      AND cp_attach_action_type = 'ATTACH';
322 
323   l_attachment_details_rec c_attachment_details%ROWTYPE;
324 
325 BEGIN
326     Eng_Propagation_log_Util.Debug_Log(G_LOG_PROC, 'Propagate_Attach_Lines.BEGIN');
327     Eng_Propagation_log_Util.Debug_Log(G_LOG_STMT, 'Input Param: p_change_id               '||p_change_id);
328     Eng_Propagation_log_Util.Debug_Log(G_LOG_STMT, 'Input Param: p_revised_item_sequence_id'||p_revised_item_sequence_id );
329 
330     -- get the local change id
331     Propagated_Local_Change(
332         p_change_id             => p_change_id
333       , p_local_organization_id => p_local_organization_id
334       , x_local_change_id       => l_local_change_id);
335 
336     x_return_status := FND_API.G_RET_STS_SUCCESS;
337 
338     Eng_Propagation_log_Util.Debug_Log(G_LOG_STMT, 'Value: l_local_change_id'||l_local_change_id);
339     IF l_local_change_id IS null
340     THEN
341     Eng_Propagation_log_Util.Debug_Log(G_LOG_STMT, 'Value: l_local_change_id'||p_revised_item_unexp_rec.change_id);
342         l_local_change_id := p_revised_item_unexp_rec.change_id;
343     END IF;
344     Eng_Propagation_log_Util.Debug_Log(G_LOG_STMT, 'Value:  p_revised_item_unexp_rec.revised_item_sequence_id'|| p_revised_item_unexp_rec.revised_item_sequence_id);
345 
346     IF (l_local_change_id IS NOT NULL AND p_revised_item_unexp_rec.revised_item_sequence_id IS NOT NULL)
347     THEN
348         FOR ac in c_attachment_changes (p_revised_item_sequence_id) /* loop 2*/
349         LOOP
350             -- initialize pk value and local attachment id
351             l_pk3_value := NULL;
352             l_local_attachment_id := -1;
353             l_return_status := FND_API.G_RET_STS_SUCCESS;
354             -- set the pk3 value if the attachment belongs to item revision
355             IF (ac.entity_name = 'MTL_ITEM_REVISIONS')
356             THEN
357                 Eng_Propagation_log_Util.Debug_Log(G_LOG_STMT, 'Value:  p_revised_item_unexp_rec.new_item_revision_id'|| p_revised_item_unexp_rec.new_item_revision_id);
358                 Eng_Propagation_log_Util.Debug_Log(G_LOG_STMT, 'Value:  p_revised_item_unexp_rec.CURRENT_item_revision_id'|| p_revised_item_unexp_rec.CURRENT_item_revision_id);
359 
360                -- Bug : 5355614
361                -- For item attachment changes with new revisions we need to get the correct revision id (eng_attachment_changes.pk3_value)
362                BEGIN
363                     select revision_id
364                     into l_pk3_value from mtl_item_revisions
365                     where inventory_item_id = (select revised_item_id
366                                                from eng_revised_items
367                                                where revised_item_sequence_id = p_revised_item_unexp_rec.Revised_Item_Sequence_Id)
368                     and revised_item_sequence_id = p_revised_item_unexp_rec.Revised_Item_Sequence_Id;
369                EXCEPTION
370                     WHEN OTHERS THEN
371                          --   this will be called for item attachment changes with default revision
372                          l_pk3_value := nvl(p_revised_item_unexp_rec.new_item_revision_id,
373                                             p_revised_item_unexp_rec.CURRENT_item_revision_id);
374                END;
375             END IF;
376                 -- Bug : 5356082
377                 l_temp_document_id := ac.document_id;
378                      l_temp_document_id := Get_Child_Org_Item_AttId
379                                            (
380                                            p_item_id                => ac.pk2_value
381                                           ,p_item_revision_id       => l_pk3_value
382                                           ,p_master_org_id          => g_global_org_id
383                                           ,p_master_org_document_id => ac.document_id
384                                           ,p_child_org_id           => p_revised_item_unexp_rec.organization_id
385                                            );
386                 l_local_attachment_id := Get_local_org_attachment_id(
387                                              p_local_entity_name  => ac.entity_name
388                                            , p_local_pk1_value    => p_local_organization_id
389                                            , p_local_pk2_value    => ac.pk2_value
390                                            , p_local_pk3_value    => l_pk3_value
391                                            , p_global_document_id => l_temp_document_id
392                                            , x_att_status         => l_local_att_status); -- Bug 3599366
393             Eng_Propagation_log_Util.Debug_Log(G_LOG_STMT, 'Value: ac.action_type:'||ac.action_type);
394             Eng_Propagation_log_Util.Debug_Log(G_LOG_STMT, 'Value: l_local_attachment_id:'||l_local_attachment_id);
395             Eng_Propagation_log_Util.Debug_Log(G_LOG_STMT, 'Value: ac.change_document_id:'||ac.change_document_id);
396             IF (ac.action_type = 'ATTACH' OR l_local_attachment_id <> -1)
397             THEN
398                 FOR cad IN c_attachment_details(l_local_attachment_id, ac.action_type, ac.change_document_id)
399                 LOOP
400                     Eng_Propagation_log_Util.Debug_Log(G_LOG_STMT, 'Inserting into eng_attachment_changes..');
401                     SELECT ENG_ATTACHMENT_CHANGES_S.nextval
402                     INTO l_change_document_id
403                     FROM dual;
404 
405                     INSERT INTO eng_attachment_changes (
406                         CHANGE_ID
407                       , REVISED_ITEM_SEQUENCE_ID
408                       , ACTION_TYPE
409                       , ATTACHMENT_ID
410                       , SOURCE_document_ID
411                       , SOURCE_VERSION_LABEL
412                       , SOURCE_PATH
413                       , DEST_DOCUMENT_ID
414                       , DEST_VERSION_LABEL
415                       , DEST_PATH
416                       , CREATION_DATE
417                       , CREATED_BY
418                       , LAST_UPDATE_DATE
419                       , LAST_UPDATED_BY
420                       , LAST_UPDATE_LOGIN
421                       , CHANGE_DOCUMENT_ID
422                       , FILE_NAME
423                       , CATEGORY_ID
424                       , ATTACHED_USER_ID
425                       , PREVIOUS_STATUS
426                       , FAMILY_ID
427                       , REPOSITORY_ID
428                       , DM_TYPE
429                       , ENTITY_NAME
430                       , PK1_VALUE
431                       , PK2_VALUE
432                       , PK3_VALUE
433                       , PK4_VALUE
434                       , PK5_VALUE
435                       , NEW_FILE_NAME
436                       , DESCRIPTION
437                       , NEW_DESCRIPTION
438                       , NEW_CATEGORY_ID
439                       , DATATYPE_ID
440                       ) VALUES (
441                         l_local_change_id
442                       , p_revised_item_unexp_rec.revised_item_sequence_id
443                       , ac.action_type
444                       , decode(l_local_attachment_id, -1, ac.attachment_id, l_local_attachment_id)
445                       , cad.source_document_id
446                       , ac.SOURCE_VERSION_LABEL
447                       , ac.SOURCE_PATH
448                       , ac.DEST_DOCUMENT_ID
449                       , ac.DEST_VERSION_LABEL
450                       , ac.DEST_PATH
451                       , sysdate
452                       , FND_GLOBAL.USER_ID
453                       , sysdate
454                       , FND_GLOBAL.USER_ID
455                       , FND_GLOBAL.USER_ID
456                       , l_change_document_id
457                       , cad.file_name
458                       , cad.category_id
459                       , cad.last_updated_by
460                       , cad.status
461                       , ac.FAMILY_ID
462                       , ac.REPOSITORY_ID
463                       , cad.DM_TYPE
464                       , ac.ENTITY_NAME
465                       , p_revised_item_unexp_rec.organization_id
466                       , ac.PK2_VALUE
467                       , l_pk3_value
468                       , ac.PK4_VALUE
469                       , ac.PK5_VALUE
470                       , ac.NEW_FILE_NAME
471                       , ac.DESCRIPTION
472                       , ac.NEW_DESCRIPTION
473                       , ac.NEW_CATEGORY_ID
474                       , cad.DATATYPE_ID
475                       );
476                 END LOOP;
477             ELSE
478                 Eng_Propagation_log_Util.Debug_Log(G_LOG_STMT, 'Could not process attachment_changes..Add Error');
479                 Eng_Propagation_Log_Util.add_entity_map(
480                     p_change_id                 => p_change_id
481                   , p_revised_item_sequence_id  => p_revised_item_sequence_id
482                   , p_revised_line_type         => Eng_Propagation_Log_Util.G_REV_LINE_ATCH_CHG
483                   , p_revised_line_id1          => ac.CHANGE_DOCUMENT_ID
484                   , p_local_organization_id     => p_local_organization_id
485                   , p_entity_name               => Eng_Propagation_Log_Util.G_ENTITY_REVISED_LINE
486                   , p_entity_action_status      => Eng_Propagation_Log_Util.G_PRP_PRC_STS_ERROR
487                   , p_bo_entity_identifier      => 'ATCH'--Eco_Error_Handler.G_ATCH_LEVEL
488                  );
489                 l_return_status := FND_API.G_RET_STS_ERROR;
490                 -- this case should not be reached as validation of attachments has already been done.
491                 FND_FILE.PUT_LINE(FND_FILE.LOG, 'Attachment does not exist');
492             END IF;
493             Eng_Propagation_log_Util.Debug_Log(G_LOG_STMT, 'Processed attachment change with l_return_status'|| l_return_status);
494             IF l_return_status = FND_API.G_RET_STS_SUCCESS
495             THEN
496                 Eng_Propagation_Log_Util.add_entity_map(
497                     p_change_id                 => p_change_id
498                   , p_revised_item_sequence_id  => p_revised_item_sequence_id
499                   , p_revised_line_type         => Eng_Propagation_Log_Util.G_REV_LINE_ATCH_CHG
500                   , p_revised_line_id1          => ac.CHANGE_DOCUMENT_ID
501                   , p_local_organization_id     => p_local_organization_id
502                   , p_local_revised_item_seq_id => p_revised_item_unexp_rec.revised_item_sequence_id
503                   , p_local_revised_line_id1    => l_change_document_id
504                   , p_entity_name               => Eng_Propagation_Log_Util.G_ENTITY_REVISED_LINE
505                   , p_entity_action_status      => Eng_Propagation_Log_Util.G_PRP_PRC_STS_SUCCESS
506                   , p_bo_entity_identifier      => 'ATCH'--Eco_Error_Handler.G_ATCH_LEVEL
507                  );
508             END IF;
509             IF l_return_status = FND_API.G_RET_STS_ERROR
510             THEN
511                 x_return_status := l_return_status;
512             END IF;
513         END LOOP;   /* end loop 2 */
514     END IF;
515     Eng_Propagation_log_Util.Debug_Log(G_LOG_STMT, 'Processed All attachment change with x_return_status'||x_return_status);
516     IF x_return_status = FND_API.G_RET_STS_ERROR
517     THEN
518         Error_Handler.Add_Error_Token(
519             p_Message_Name       => 'ENG_PRP_ATT_REVITEM_ERR'
520           , p_Mesg_Token_Tbl     => x_mesg_token_tbl
521           , x_Mesg_Token_Tbl     => x_mesg_token_tbl
522          );
523     END IF;
524     Eng_Propagation_log_Util.Debug_Log(G_LOG_STMT, 'Propagate_Attach_Lines.END');
525 
526 EXCEPTION
527 WHEN OTHERS THEN
528     x_return_status := FND_API.G_RET_STS_ERROR;
529 
530     Error_Handler.Add_Error_Token(
531         p_Message_Name   => NULL
532       , p_Message_Text   => 'Unexpected Error Occurred when propagating attachment changes' ||SQLERRM
533       , p_Mesg_Token_Tbl => x_Mesg_Token_Tbl
534       , x_Mesg_Token_Tbl => x_Mesg_Token_Tbl
535      );
536     FND_FILE.PUT_LINE(FND_FILE.LOG, 'Error propagating attachment changes' ||SQLERRM);
537     Eng_Propagation_log_Util.Debug_Log(G_LOG_PROC, 'Propagate_Attach_Lines.END.ERROR');
538 END Propagate_Attach_Lines;
539 
540 PROCEDURE BREAK_COMMON_BOM (
541     p_to_sequence_id   IN NUMBER
542   , p_from_sequence_id IN NUMBER
543   , p_from_org_id      IN NUMBER
544   , p_to_org_id        IN NUMBER
545   , p_to_item_id       IN NUMBER
546   , p_to_alternate     IN VARCHAR2
547   , p_from_item_id     IN NUMBER
548 ) IS
549     l_null_val NUMBER;
550 
551 BEGIN
552     /* copy bom */
553     BOM_COPY_BILL.COPY_BILL(
554         to_sequence_id          => p_to_sequence_id
555       , from_sequence_id        => p_from_sequence_id
556       , from_org_id             => p_from_org_id
557       , to_org_id               => p_to_org_id
558       , display_option          => 1
559       , user_id                 => FND_PROFILE.value('USER_ID')
560       , to_item_id              => p_to_item_id
561       , direction               => 3
562       , to_alternate            => p_to_alternate
563       , rev_date                => sysdate
564       , e_change_notice         => NULL
565       , rev_item_seq_id         => NULL
566       , bill_or_eco             => 1
567       , eco_eff_date            => NULL
568       , eco_unit_number         => NULL
569       , unit_number             => NULL
570       , from_item_id            => p_from_item_id
571      );
572     /* update the commoned information in bom_bill_of_materials */
573     update bom_bill_of_materials set
574     common_bill_sequence_id = p_to_sequence_id,
575     common_organization_id = NULL,
576     common_assembly_item_id = NULL
577     where bill_sequence_id = p_to_sequence_id;
578 END BREAK_COMMON_BOM;
579 
580 
581 FUNCTION Check_Sourcing_Rules (
582     p_local_org_id    IN NUMBER
583   , p_revised_item_id IN NUMBER
584 ) RETURN NUMBER IS
585    l_item_sourced NUMBER := 2;
586 BEGIN
587     l_item_sourced := ENG_SOURCING_CHECK.IS_ITEM_SOURCED(p_revised_item_id, p_local_org_id, g_global_org_id);
588     IF(l_item_sourced = 3)  /* public api not overridden */
589     THEN
590         l_item_sourced := 2;
591         -- Scoped out
592         /*BEGIN
593             select 1 into l_item_sourced from dual
594             where exists (select 1 from mrp_sources_v
595             where assignment_set_id = FND_PROFILE.VALUE( 'MRP_DEFAULT_ASSIGNMENT_SET' )
596             and organization_id = g_global_org_id
597             and inventory_item_id = p_revised_item_id
598             and source_organization_id = p_local_org_id
599             and source_type = 2);
600         EXCEPTION
601         WHEN NO_DATA_FOUND THEN
602             l_item_sourced := 2;
603         END;*/
604     END IF;
605     RETURN l_item_sourced;
606 END Check_Sourcing_Rules;
607 
608 PROCEDURE Auto_Enable_Item_In_Org (
609     p_inventory_item_id  IN NUMBER
610   , p_organization_id    IN NUMBER
611   , x_error_table       OUT NOCOPY INV_ITEM_GRP.Error_Tbl_Type
612   , x_return_status     OUT NOCOPY VARCHAR2
613 ) IS
614     l_Item_rec_in        INV_ITEM_GRP.Item_Rec_Type;
615     l_revision_rec       INV_ITEM_GRP.Item_Revision_Rec_Type;
616     l_Item_rec_out       INV_ITEM_GRP.Item_Rec_Type;
617     l_return_status      VARCHAR2(1);
618     l_Error_tbl          INV_ITEM_GRP.Error_Tbl_Type;
619 BEGIN
620     l_Item_rec_in.INVENTORY_ITEM_ID :=  p_Inventory_Item_Id;
621     l_Item_rec_in.ORGANIZATION_ID :=  p_Organization_Id;
622 
623     INV_ITEM_GRP.Create_Item(
624         p_Item_rec         =>  l_Item_rec_in
625       , p_Revision_rec     =>  l_revision_rec
626       , p_Template_Id      =>  NULL
627       , p_Template_Name    =>  NULL
628       , x_Item_rec         =>  l_Item_rec_out
629       , x_return_status    =>  l_return_status
630       , x_Error_tbl        =>  l_Error_tbl
631      );
632     x_return_status :=  l_return_status;
633     x_error_table := l_Error_tbl;
634 
635 END Auto_Enable_Item_In_Org;
636 
637 PROCEDURE Auto_Enable_Item (
638     p_api_version           IN NUMBER
639   , p_init_msg_list         IN VARCHAR2
640   , p_commit                IN VARCHAR2
641   , x_return_status         OUT NOCOPY VARCHAR2
642   , x_msg_count             OUT NOCOPY NUMBER
643   , x_msg_data              OUT NOCOPY VARCHAR2
644   , p_inventory_item_id     IN NUMBER
645   , p_local_organization_id IN NUMBER
646 ) IS
647     l_api_name       CONSTANT VARCHAR2(30) := 'Auto_Enable_Item';
648     l_api_version    CONSTANT NUMBER := 1.0;
649     l_error_table    INV_ITEM_GRP.Error_Tbl_Type;
650 
651 BEGIN
652     x_return_status := FND_API.G_RET_STS_SUCCESS;
653     -- Standard Start of API savepoint
654     SAVEPOINT Auto_Enable_Item;
655 
656     -- Standard call to check for call compatibility
657     IF NOT FND_API.Compatible_API_Call ( l_api_version
658                                         ,p_api_version
659                                         ,l_api_name
660                                         ,G_PKG_NAME )
661     THEN
662       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
663     END IF;
664 
665     -- Initialize message list if p_init_msg_list is set to TRUE.
666     IF FND_API.to_Boolean( p_init_msg_list ) THEN
667        FND_MSG_PUB.initialize;
668     END IF ;
669 
670     AUTO_ENABLE_ITEM_IN_ORG(
671         p_inventory_item_id   => p_inventory_item_id
672       , p_organization_id     => p_local_organization_id
673       , X_error_table         =>  l_error_table
674       , x_return_status       => x_return_status);
675 
676     IF x_return_status <> FND_API.G_RET_STS_SUCCESS
677     THEN
678         FOR i IN 1..l_error_table.COUNT
679         LOOP
680            FND_MESSAGE.Set_Name('INV', l_error_table(i).message_name);
681            FND_MSG_PUB.Add;
682         END loop;
683         FND_MSG_PUB.Count_And_Get(
684             p_count => x_msg_count
685           , p_data  => x_msg_data);
686     END IF;
687     -- Standard ending code ------------------------------------------------
688     IF FND_API.To_Boolean ( p_commit ) THEN
689       COMMIT WORK;
690     END IF;
691 
692 EXCEPTION
693 WHEN OTHERS THEN
694     ROLLBACK TO Auto_Enable_Item;
695      x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
696      IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
697      THEN
698        FND_MSG_PUB.Add_Exc_Msg(G_PKG_NAME, l_api_name);
699      END IF;
700      FND_MSG_PUB.Count_And_Get(
701          p_count => x_msg_count
702        , p_data  => x_msg_data);
703 END Auto_Enable_Item;
704 
705 /* added this procedure to stop propogation of attachment having not allowed
706     change policy in child org.
707     added nvl condition for lifecycle  & phase id because if no lifecycle defined at revision level
708     it takes item level's by default. */
709 FUNCTION Check_Attachment_Policy (
710       p_inventory_item_id        IN            NUMBER,
711       p_organization_id     IN            NUMBER,
712       p_category_id     IN            VARCHAR2,
713       p_revision_id  IN NUMBER
714 ) RETURN NUMBER IS
715  l_strc_cp_not_allowed   NUMBER := 2;
716 
717   CURSOR c_check_attach_policy IS
718    SELECT 1
719    FROM (SELECT nvl(mir.lifecycle_id,msi.lifecycle_id) lifecycle_id,
720             nvl(mir.current_phase_id,msi.current_phase_id) current_phase_id, msi.item_catalog_group_id,
721             mir.inventory_item_id, mir.organization_id
722             FROM MTL_ITEM_REVISIONS mir ,MTL_SYSTEM_ITEMS msi
723             WHERE mir.INVENTORY_ITEM_ID = p_inventory_item_id
724             AND mir.ORGANIZATION_ID = p_organization_id
725             AND mir.revision_id = p_revision_id
726             AND  msi.INVENTORY_ITEM_ID = mir.INVENTORY_ITEM_ID
727             AND msi.ORGANIZATION_ID = mir.ORGANIZATION_ID) ITEM_DTLS, ENG_CHANGE_POLICIES_V ECP
728    WHERE ecp.policy_object_pk1_value =
729         (SELECT TO_CHAR(ic.item_catalog_group_id)
730          FROM mtl_item_catalog_groups_b ic
731          WHERE EXISTS
732            (SELECT olc.object_classification_code CatalogId
733             FROM EGO_OBJ_TYPE_LIFECYCLES olc
734             WHERE olc.object_id = (SELECT OBJECT_ID FROM fnd_objects WHERE obj_name = 'EGO_ITEM')
735             AND olc.lifecycle_id = ITEM_DTLS.lifecycle_id
736             AND olc.object_classification_code = ic.item_catalog_group_id)
737          AND ROWNUM = 1
738          CONNECT BY PRIOR parent_catalog_group_id = item_catalog_group_id
739          START WITH item_catalog_group_id = ITEM_DTLS.item_catalog_group_id)
740    AND ecp.policy_object_pk2_value = ITEM_DTLS.lifecycle_id
741    AND ecp.policy_object_pk3_value = ITEM_DTLS.current_phase_id
742    AND ecp.policy_object_name = 'CATALOG_LIFECYCLE_PHASE'
743    AND ecp.attribute_object_name = 'EGO_CATALOG_GROUP'
744    AND ecp.attribute_code = 'ATTACHMENT'
745    AND ecp.ATTRIBUTE_NUMBER_VALUE = p_category_id
746    AND ecp.policy_char_value = 'NOT_ALLOWED';
747 
748  BEGIN
749       l_strc_cp_not_allowed := 2;
750      OPEN c_check_attach_policy;
751      FETCH c_check_attach_policy INTO l_strc_cp_not_allowed;
752      CLOSE c_check_attach_policy;
753       RETURN  l_strc_cp_not_allowed;
754 
755  EXCEPTION
756  WHEN OTHERS THEN
757      IF c_check_attach_policy%ISOPEN THEN
758          CLOSE c_check_attach_policy;
759      END IF;
760      l_strc_cp_not_allowed := 2;
761      RETURN  l_strc_cp_not_allowed;
762  END Check_Attachment_Policy;
763 
764 PROCEDURE Validate_Attach_Lines (
765     p_change_id                   IN NUMBER
766   , p_rev_item_sequence_id        IN NUMBER
767   , p_global_organization_id      IN NUMBER
768   , p_global_new_item_rev         IN VARCHAR2
769   , p_global_current_item_rev_id  IN NUMBER
770   , p_local_organization_id       IN NUMBER
771   , p_local_line_rev_id           IN NUMBER
772   , p_revised_item_rec            IN Eng_Eco_Pub.Revised_Item_Rec_Type
773   , p_revised_item_unexp_rec      IN Eng_Eco_Pub.Rev_Item_Unexposed_Rec_Type
774   , x_return_status               OUT NOCOPY VARCHAR2
775   , x_mesg_token_tbl              IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
776 ) IS
777 
778    CURSOR c_attachment_changes IS
779    SELECT eac.action_type, eac.entity_name, eac.pk1_value, eac.pk2_value
780         , eac.pk3_value, eac.file_name, fad.status, eac.change_document_id
781         , decode(eac.action_type, 'ATTACH', eac.source_document_id,fad.document_id) document_id,eac.category_id
782    FROM eng_attachment_changes eac, fnd_attached_documents fad
783    WHERE eac.change_id = p_change_id
784    AND eac.revised_item_sequence_id = p_rev_item_sequence_id
785    AND eac.attachment_id =  fad.attached_document_id(+)
786    AND (eac.entity_name = 'MTL_ITEM_REVISIONS'
787         OR (eac.entity_name = 'MTL_SYSTEM_ITEMS'
788         AND NOT EXISTS (SELECT 1 FROM MTL_PARAMETERS MP
789             WHERE MP.organization_id = p_global_organization_id
790             AND MP.master_organization_id = MP.organization_id)
791     ))
792    AND NOT EXISTS (SELECT 1 FROM eng_change_propagation_maps ecpm
793                     WHERE ecpm.change_id = p_change_id
794                       AND ecpm.local_organization_id = p_local_organization_id
795                       AND ecpm.revised_line_type = Eng_Propagation_Log_Util.G_REV_LINE_ATCH_CHG
796                       AND ecpm.revised_line_id1 = eac.change_document_id
797                       AND ecpm.entity_action_status = 3);
798 
799    CURSOR c_check_item_level_changes IS
800    SELECT 1
801    FROM eng_attachment_changes eac
802    WHERE eac.change_id = p_change_id
803    AND eac.revised_item_sequence_id = p_rev_item_sequence_id
804    AND eac.entity_name = 'MTL_SYSTEM_ITEMS'
805    AND EXISTS(SELECT 1 FROM MTL_PARAMETERS MP
806               WHERE MP.organization_id = p_global_organization_id
807                 AND MP.master_organization_id = MP.organization_id)
808    AND NOT EXISTS (SELECT 1 FROM eng_change_propagation_maps ecpm
809                     WHERE ecpm.change_id = p_change_id
810                       AND ecpm.local_organization_id = p_local_organization_id
811                       AND ecpm.revised_line_type = Eng_Propagation_Log_Util.G_REV_LINE_ATCH_CHG
812                       AND ecpm.revised_line_id1 = eac.change_document_id
813                       AND ecpm.entity_action_status = 3);
814 
815 
816    l_current_revision_id NUMBER;
817    l_action_name         fnd_lookups.meaning%TYPE;
818    l_local_attachment_id NUMBER;
819    l_pk3_value           VARCHAR2(100);
820    l_status_name         fnd_lookups.meaning%TYPE;
821    l_check_item_changes  NUMBER;
822    l_local_att_status    fnd_attached_documents.status%TYPE; -- Bug 3599366
823    l_Mesg_token_Tbl      Error_Handler.Mesg_Token_Tbl_Type;
824    l_Token_Tbl           Error_Handler.Token_Tbl_Type;
825    l_error_logged        NUMBER;
826    l_cp_not_allowed      NUMBER;
827    l_temp_document_id    NUMBER;
828    l_local_revision      VARCHAR2(30);
829    l_global_revision     VARCHAR2(30);
830    l_rev_mismatch        NUMBER;
831 
832 BEGIN
833     Eng_Propagation_Log_Util.Debug_Log(G_LOG_PROC, 'Validate_Attach_Lines.BEGIN');
834     --
835     -- Initialize
836     l_error_logged := G_VAL_FALSE;
837     x_return_status := FND_API.G_RET_STS_SUCCESS;
838 
839     -- validate attachment changes propagation
840     FOR ac IN c_attachment_changes
841     LOOP
842         Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Processing attachment change record with change_document_id: '||ac.change_document_id);
843 
844         Error_Handler.Delete_Message(p_entity_id => Eco_Error_Handler.G_ATCH_LEVEL);
845 
846         l_mesg_token_tbl.delete;
847 
848         -- initialize pk value and local attachment id
849         l_pk3_value := NULL;
850         l_local_attachment_id := -1;
851         l_rev_mismatch := G_VAL_FALSE;
852 
853         -- set the pk3 value if the attachment belongs to item revision
854         IF (ac.entity_name = 'MTL_ITEM_REVISIONS')
855         THEN
856           l_pk3_value := p_local_line_rev_id;
857 
858           BEGIN
859             SELECT revision
860             INTO l_local_revision
861             FROM MTL_ITEM_REVISIONS
862             WHERE revision_id = p_local_line_rev_id;
863           EXCEPTION
864             WHEN NO_DATA_FOUND THEN
865               l_local_revision := NULL;
866           END;
867 
868           IF  p_global_new_item_rev IS NOT NULL AND
869               p_global_new_item_rev <> FND_API.G_MISS_CHAR AND
870               p_global_new_item_rev <> l_local_revision
871           THEN
872             l_Token_Tbl.delete;
873             l_Token_Tbl(1).Token_name := 'REVISION';
874             l_Token_Tbl(1).Token_Value := p_global_new_item_rev;
875 
876             Error_Handler.Add_Error_Token(
877                 p_Message_Name       => 'ENG_NEW_REV_PROP_ERROR'
878               , p_Mesg_Token_Tbl     => l_mesg_token_tbl
879               , x_Mesg_Token_Tbl     => l_mesg_token_tbl
880               , p_Token_Tbl          => l_token_tbl
881              );
882 
883             l_error_logged := G_VAL_TRUE;
884             l_rev_mismatch := G_VAL_TRUE;
885 
886           ELSIF p_global_new_item_rev IS NULL OR
887                 p_global_new_item_rev = FND_API.G_MISS_CHAR
888           THEN
889             BEGIN
890               SELECT revision
891               INTO l_global_revision
892               FROM MTL_ITEM_REVISIONS
893               WHERE revision_id = p_global_current_item_rev_id;
894             EXCEPTION
895               WHEN NO_DATA_FOUND THEN
896                 l_global_revision := NULL;
897             END;
898 
899             IF l_global_revision <> l_local_revision
900             THEN
901               l_Token_Tbl.delete;
902               l_Token_Tbl(1).Token_name := 'REVISION';
903               l_Token_Tbl(1).Token_Value := l_global_revision;
904 
905               Error_Handler.Add_Error_Token(
906                   p_Message_Name       => 'ENG_CUR_REV_PROP_ERROR'
907                 , p_Mesg_Token_Tbl     => l_mesg_token_tbl
908                 , x_Mesg_Token_Tbl     => l_mesg_token_tbl
909                 , p_Token_Tbl          => l_token_tbl
910                );
911 
912               l_error_logged := G_VAL_TRUE;
913               l_rev_mismatch := G_VAL_TRUE;
914             END IF;
915           END IF;
916 
917           Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Value: l_pk3_value '||l_pk3_value);
918         END IF;
919 
920         IF l_rev_mismatch = G_VAL_FALSE
921         THEN
922           --added for bug 5151075
923           l_cp_not_allowed := Check_Attachment_Policy( p_inventory_item_id   => ac.pk2_value
924                                                      , p_organization_id     => p_local_organization_id
925                                                      , p_category_id         => ac.category_id
926                                                      , p_revision_id         => l_pk3_value);
927           IF l_cp_not_allowed = 1
928           THEN
929             -- If revision level attachment has change allowed policy is set to 'NO'
930             l_Token_Tbl.delete;
931             Error_Handler.Add_Error_Token(p_Message_Name       => 'ENG_ATT_NO_ALLOW_CHG_POLICY'
932                                         , p_Mesg_Token_Tbl     => l_mesg_token_tbl
933                                         , x_Mesg_Token_Tbl     => l_mesg_token_tbl
934                                         , p_Token_Tbl          => l_token_tbl);
935             l_error_logged := G_VAL_TRUE;
936           END IF;
937 
938           -- Bug : 5356082
939           l_temp_document_id := Get_Child_Org_Item_AttId(p_item_id                => ac.pk2_value
940                                                         ,p_item_revision_id       => l_pk3_value
941                                                         ,p_master_org_id          => g_global_org_id
942                                                         ,p_master_org_document_id => ac.document_id
943                                                         ,p_child_org_id           => p_revised_item_unexp_rec.organization_id);
944           l_local_attachment_id := Get_local_org_attachment_id(p_local_entity_name   => ac.entity_name
945                                                              , p_local_pk1_value     => p_revised_item_unexp_rec.organization_id
946                                                              , p_local_pk2_value     => ac.pk2_value
947                                                              , p_local_pk3_value     => l_pk3_value
948                                                              , p_global_document_id  => l_temp_document_id
949                                                              , x_att_status          => l_local_att_status); -- Bug 3599366
950 
951           SELECT meaning
952           INTO l_action_name
953           FROM fnd_lookups
954           WHERE lookup_type = 'DOM_CHANGE_ACTION_TYPES'
955           AND lookup_code = ac.action_type;
956 
957           Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Value: l_local_attachment_id'||l_local_attachment_id||' l_local_att_status'||l_local_att_status);
958           Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Value: ac.action_type'||ac.action_type);
959 
960           IF (ac.action_type = 'ATTACH' AND l_local_attachment_id <> -1)
961           THEN
962               -- For attach action, if Attachment already exists log error
963               l_Token_Tbl.delete;
964               l_Token_Tbl(1).Token_name := 'FILE';
965               l_Token_Tbl(1).Token_Value := ac.file_name;
966 
967               Error_Handler.Add_Error_Token(
968                   p_Message_Name       => 'ENG_PRP_ATT_ADD_FAIL'
969                 , p_Mesg_Token_Tbl     => l_mesg_token_tbl
970                 , x_Mesg_Token_Tbl     => l_mesg_token_tbl
971                 , p_Token_Tbl          => l_token_tbl
972                );
973               l_error_logged := G_VAL_TRUE;
974 
975           ELSIF (ac.action_type <> 'ATTACH' AND l_local_attachment_id = -1)
976           THEN
977               -- For all actions except attach, if attachment does not exist in local org, log error
978               l_Token_Tbl.delete;
979               l_Token_Tbl(1).Token_name := 'ACTION';
980               l_Token_Tbl(1).Token_Value := l_action_name;
981               l_Token_Tbl(2).Token_name := 'FILE';
982               l_Token_Tbl(2).Token_Value := ac.file_name;
983 
984               Error_Handler.Add_Error_Token(
985                   p_Message_Name       => 'ENG_PRP_ATT_ACTION_FAIL'
986                 , p_Mesg_Token_Tbl     => l_mesg_token_tbl
987                 , x_Mesg_Token_Tbl     => l_mesg_token_tbl
988                 , p_Token_Tbl          => l_token_tbl
989                );
990               l_error_logged := G_VAL_TRUE;
991 
992           ELSIF (ac.action_type <> 'ATTACH' AND
993                  l_local_attachment_id <> -1 AND
994                  l_local_att_status IN ('PENDING', 'PENDING_CHANGE', 'SUBMITTED_FOR_APPROVAL')) -- Bug 3599366
995           THEN
996               SELECT meaning
997               INTO l_status_name
998               FROM fnd_lookups
999               WHERE lookup_type = 'DOM_ATTACHED_DOC_STATUS'
1000               AND lookup_code = l_local_att_status; -- Bug 3599366
1001 
1002               -- For all actions except attach, if attachment exists but it is not in a valid status for change, log error
1003               l_Token_Tbl.delete;
1004               l_Token_Tbl(1).Token_name := 'ACTION';
1005               l_Token_Tbl(1).Token_Value := l_action_name;
1006               l_Token_Tbl(2).Token_name := 'STATUS';
1007               l_Token_Tbl(2).Token_Value := l_status_name;
1008               l_Token_Tbl(3).Token_name := 'FILE';
1009               l_Token_Tbl(3).Token_Value := ac.file_name;
1010 
1011               Error_Handler.Add_Error_Token(
1012                   p_Message_Name       => 'ENG_PRP_ATT_STATUS_FAIL'
1013                 , p_Mesg_Token_Tbl     => l_mesg_token_tbl
1014                 , x_Mesg_Token_Tbl     => l_mesg_token_tbl
1015                 , p_Token_Tbl          => l_token_tbl
1016                );
1017 
1018               l_error_logged := G_VAL_TRUE;
1019 
1020           END IF;
1021         END IF;
1022 
1023         Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Value: l_error_logged'||l_error_logged);
1024 
1025         IF (l_error_logged = G_VAL_TRUE)
1026         THEN
1027             x_return_status := FND_API.G_RET_STS_ERROR;
1028             -- Log any messages that have been logged with the additional error
1029             -- message into error handler
1030             Eco_Error_Handler.Log_Error(
1031                 p_error_status         => FND_API.G_RET_STS_ERROR
1032               , p_mesg_token_tbl       => l_mesg_token_tbl
1033               , p_error_scope          => Error_Handler.G_SCOPE_ALL
1034               , p_error_level          => Eco_Error_Handler.G_ATCH_LEVEL
1035               , x_eco_rec              => ENG_Eco_PUB.G_MISS_ECO_REC
1036               , x_eco_revision_tbl     => ENG_Eco_PUB.G_MISS_ECO_REVISION_TBL
1037               , x_change_line_tbl      => ENG_Eco_PUB.G_MISS_CHANGE_LINE_TBL -- Eng Change
1038               , x_revised_item_tbl     => ENG_Eco_PUB.G_MISS_REVISED_ITEM_TBL
1039               , x_rev_component_tbl    => ENG_Eco_PUB.G_MISS_REV_COMPONENT_TBL
1040               , x_ref_designator_tbl   => ENG_Eco_PUB.G_MISS_REF_DESIGNATOR_TBL
1041               , x_sub_component_tbl    => ENG_Eco_PUB.G_MISS_SUB_COMPONENT_TBL
1042               , x_rev_operation_tbl    => ENG_Eco_PUB.G_MISS_REV_OPERATION_TBL
1043               , x_rev_op_resource_tbl  => ENG_Eco_PUB.G_MISS_REV_OP_RESOURCE_TBL
1044               , x_rev_sub_resource_tbl => ENG_Eco_PUB.G_MISS_REV_SUB_RESOURCE_TBL
1045              );
1046             -- local change id is set later
1047             -- if there are errors, based on the level they are not populated in the
1048             -- maps table.
1049             Eng_Propagation_Log_Util.add_entity_map(
1050                 p_change_id                 => p_change_id
1051               , p_revised_item_sequence_id  => p_rev_item_sequence_id
1052               , p_revised_line_type         => Eng_Propagation_Log_Util.G_REV_LINE_ATCH_CHG
1053               , p_revised_line_id1          => ac.change_document_id
1054               , p_local_organization_id     => p_local_organization_id
1055               , p_entity_name               => Eng_Propagation_Log_Util.G_ENTITY_REVISED_LINE
1056               , p_entity_action_status      => Eng_Propagation_Log_Util.G_PRP_PRC_STS_ERROR
1057               , p_bo_entity_identifier      => 'ATCH'--Eco_Error_Handler.G_ATCH_LEVEL
1058              );
1059         ELSE
1060             /*Eng_Propagation_Log_Util.add_entity_map(
1061                 p_change_id                 => p_change_id
1062               , p_revised_item_sequence_id  => p_rev_item_sequence_id
1063               , p_revised_line_type         => Eng_Propagation_Log_Util.G_REV_LINE_ATCH_CHG
1064               , p_revised_line_id1          => ac.change_document_id
1065               , p_local_organization_id     => p_local_organization_id
1066               , p_entity_name               => Eng_Propagation_Log_Util.G_ENTITY_REVISED_LINE
1067               , p_entity_action_status      => Eng_Propagation_Log_Util.G_PRP_PRC_STS_SUCCESS
1068               , p_bo_entity_identifier      => 'ATCH'--Eco_Error_Handler.G_ATCH_LEVEL
1069              );*/
1070              null;-- do nothing
1071         END IF;
1072 
1073     END LOOP;
1074 
1075     IF(l_error_logged <> G_VAL_TRUE)
1076     THEN
1077         OPEN c_check_item_level_changes;
1078         FETCH c_check_item_level_changes INTO l_check_item_changes;
1079         IF c_check_item_level_changes%FOUND
1080         THEN
1081             l_token_tbl.delete;
1082             Error_Handler.Add_Error_Token(
1083                 p_Message_Name       => 'ENG_PRP_ATT_ITEMCHG_INFO'
1084               , p_Mesg_Token_Tbl     => x_mesg_token_tbl -- to be passed as o/p to the RI log error
1085               , x_Mesg_Token_Tbl     => x_mesg_token_tbl
1086               , p_Token_Tbl          => l_token_tbl
1087               , p_message_type       => 'I'
1088              );
1089         END IF;
1090     ELSE
1091         l_token_tbl.delete;
1092         Error_Handler.Add_Error_Token(
1093             p_Message_Name       => 'ENG_PRP_ATT_REVITEM_ERR'
1094           , p_Mesg_Token_Tbl     => x_mesg_token_tbl
1095           , x_Mesg_Token_Tbl     => x_mesg_token_tbl
1096           , p_Token_Tbl          => l_token_tbl
1097          );
1098     END IF;
1099     Eng_Propagation_Log_Util.Debug_Log(G_LOG_PROC, 'Validate_Attach_Lines.END');
1100 
1101 EXCEPTION
1102 WHEN OTHERS THEN
1103     IF (c_check_item_level_changes%ISOPEN)
1104     THEN
1105         CLOSE c_check_item_level_changes;
1106     END IF;
1107     Eng_Propagation_Log_Util.Debug_Log(G_LOG_PROC, 'Validate_Attach_Lines.ERROR');
1108     FND_FILE.PUT_LINE(FND_FILE.LOG, 'Error in validation attachments ' || SQLERRM);
1109     l_error_logged := 1;
1110     x_return_status := FND_API.G_RET_STS_ERROR;
1111     Error_Handler.Add_Error_Token(
1112         p_Message_Name   => NULL
1113       , p_Message_Text   => 'Unexpected Error Occurred when validating attachment changes' ||SQLERRM
1114       , p_Mesg_Token_Tbl => x_Mesg_Token_Tbl
1115       , x_Mesg_Token_Tbl => x_Mesg_Token_Tbl
1116      );
1117 
1118 END Validate_Attach_Lines;
1119 
1120 PROCEDURE Check_Revised_Item_Errors (
1121     p_change_notice            IN VARCHAR2
1122   , p_global_org_id            IN NUMBER
1123   , p_local_org_id             IN NUMBER
1124   , p_rev_item_seq_id          IN NUMBER
1125   , p_revised_item_id          IN NUMBER
1126   , p_use_up_item_id           IN NUMBER
1127   , p_transfer_item_enable     IN NUMBER
1128   , p_transfer_or_copy         IN VARCHAR2
1129   , p_transfer_or_copy_item    IN NUMBER
1130   , p_status_master_controlled IN NUMBER
1131   , x_error_logged             OUT NOCOPY NUMBER
1132   , x_mesg_token_tbl           OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
1133   , x_propagate_strc_changes   OUT NOCOPY NUMBER
1134   , x_sourcing_rules_exists    OUT NOCOPY NUMBER
1135   , x_revised_item_name        OUT NOCOPY VARCHAR2
1136 ) IS
1137 
1138    CURSOR c_rev_item_struc_lines (v_rev_item_seq_id NUMBER)
1139    IS
1140    SELECT eri.revised_item_id, eri.revised_item_sequence_id, eri.alternate_bom_designator
1141         , eri.change_notice, eri.from_end_item_rev_id, eri.from_end_item_strc_rev_id
1142         , bsb.source_bill_sequence_id, eri.bill_sequence_id
1143      FROM eng_revised_items eri, bom_structures_b bsb
1144     WHERE eri.bill_sequence_id = bsb.bill_sequence_id
1145       AND ((eri.revised_item_sequence_id = v_rev_item_seq_id
1146            AND eri.bill_sequence_id IS NOT NULL
1147            AND (eri.transfer_or_copy IS NULL
1148                 OR (eri.transfer_or_copy IS NOT NULL
1149                     AND eri.enable_item_in_local_org IS NOT NULL
1150                     AND nvl(eri.transfer_or_copy_bill, 2) = 2
1151                     AND nvl(eri.transfer_or_copy_routing, 2) = 2)
1152                )
1153           )
1154           -- Commented for bug 4946796
1155           /*OR (eri.parent_revised_item_seq_id = v_rev_item_seq_id
1156               AND eri.transfer_or_copy is null)*/);
1157 
1158    -- Commented for bug 4946796
1159    /*CURSOR c_rev_items_for_enable (v_rev_item_seq_id NUMBER)
1160    IS
1161    select distinct eri.revised_item_id, msikfv.concatenated_segments item_name
1162    from eng_revised_items eri, mtl_system_items_b_kfv msikfv
1163    where eri.revised_item_id = msikfv.inventory_item_id
1164    and eri.organization_id = msikfv.organization_id
1165    and eri.parent_revised_item_seq_id = v_rev_item_seq_id
1166    and (eri.transfer_or_copy is not null and eri.transfer_or_copy = 'T')
1167    and eri.enable_item_in_local_org = 'Y'
1168    and eri.revised_item_id not in (SELECT inventory_item_id
1169     FROM   mtl_system_items_b_kfv
1170     WHERE  inventory_item_id = eri.revised_item_id
1171     AND    organization_id = p_local_org_id);*/
1172 
1173    -- Commented for bug 4946796
1174   /* Cursor for transfer, obsolete, lifecycle_phase_change , copy items */
1175 
1176   /*CURSOR c_tolc_items
1177   IS
1178   select *
1179   from eng_revised_items
1180   where (parent_revised_item_seq_id = p_rev_item_seq_id
1181   or revised_item_sequence_id = p_rev_item_seq_id)
1182   and transfer_or_copy is not null
1183   AND revised_item_sequence_id NOT IN (SELECT revised_item_sequence_id
1184       FROM eng_revised_items
1185       WHERE parent_revised_item_seq_id = p_rev_item_seq_id
1186       AND (transfer_or_copy = 'L' OR transfer_or_copy = 'O')
1187       AND 1 = p_status_master_controlled);*/
1188 
1189   l_item_exists_in_org_flag   NUMBER;
1190   l_check_invalid_objects     NUMBER;
1191   l_return_status             VARCHAR2(1);
1192 
1193   l_use_up_item_exists         NUMBER;
1194   l_item_sourced_flag          NUMBER := 2;
1195   l_structure_exists_flag      NUMBER;
1196   l_revised_item_number        mtl_system_items_kfv.concatenated_segments%TYPE;
1197   l_common_bom_flag            NUMBER;
1198   l_local_bill_sequence_id     NUMBER;
1199   l_comn_bill_sequence_id      NUMBER;
1200   l_eng_bill_flag              NUMBER;
1201   l_error_logged               NUMBER := 0;
1202 --  l_eco_error_tbl              Eco_Error_Tbl_Type;
1203 --  l_err_counter                NUMBER;
1204 --  l_eco_mesg_tbl               Eco_Error_Tbl_Type;
1205 --  l_mesg_counter               NUMBER;
1206   l_local_revised_item_exists  NUMBER := 0;
1207 
1208   l_struc_line_tbl             Eco_Struc_Line_Tbl_Type;
1209   l_struc_count                NUMBER := 1;
1210   l_component_not_available    NUMBER;
1211 
1212   l_fei_strc_revision          VARCHAR2(80);
1213   l_fei_bill_sequence_id       NUMBER;
1214   l_fei_strc_item_rev_id       NUMBER;
1215   --l_fei_alternate              VARCHAR2(80);
1216   l_fei_strc_item_id           NUMBER;
1217   l_dummy                      NUMBER;
1218   l_message_log_text           VARCHAR2(2000);
1219   l_temp_mesg                  VARCHAR2(2000);
1220   --l_temp_item_name              VARCHAR2(4000);
1221   l_transfer_item_sourced_flag NUMBER;
1222   --l_propagate_strc_changes     NUMBER
1223   l_item_error_table           INV_ITEM_GRP.Error_Tbl_Type;
1224   l_create_bill_for_item       NUMBER;
1225   l_from_end_item_minor_rev_id NUMBER;
1226   l_from_end_item_rev_id       NUMBER;
1227 
1228   l_Mesg_token_Tbl        Error_Handler.Mesg_Token_Tbl_Type;
1229   l_Token_Tbl             Error_Handler.Token_Tbl_Type;
1230 BEGIN
1231 
1232   Eng_Propagation_Log_Util.Debug_Log(G_LOG_PROC, '-------------------------------');
1233   Eng_Propagation_Log_Util.Debug_Log(G_LOG_PROC, 'CHECK_REVISED_ITEM_ERRORS.begin');
1234   Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Input Param:  p_change_notice    '|| p_change_notice);
1235   Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Input Param:  p_global_org_id    '|| p_global_org_id);
1236   Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Input Param:  p_local_org_id     '|| p_local_org_id);
1237   Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Input Param:  p_rev_item_seq_id  '|| p_rev_item_seq_id);
1238   Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Input Param:  p_transfer_item_enable'|| p_transfer_item_enable);
1239   Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Input Param:  p_use_up_item_id   '|| p_use_up_item_id);
1240   Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Input Param:  p_revised_item_id  '|| p_revised_item_id);
1241   Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Input Param:  p_transfer_or_copy  '|| p_transfer_or_copy);
1242   Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Input Param:  p_transfer_or_copy_item   '||  p_transfer_or_copy_item);
1243   Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Input Param:  p_status_master_controlled'|| p_status_master_controlled);
1244 
1245   BEGIN
1246 
1247     Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Validation: Checking if revised item already exists in local Change');
1248 
1249     SELECT G_VAL_TRUE
1250       into l_local_revised_item_exists
1251       FROM eng_revised_items eri1
1252      WHERE eri1.change_notice = p_change_notice
1253        AND eri1.organization_id = p_local_org_id
1254        AND EXISTS
1255           (SELECT 1
1256              FROM eng_revised_items eri2
1257             WHERE revised_item_sequence_id = p_rev_item_seq_id
1258               AND eri2.revised_item_id = eri1.revised_item_id
1259               AND eri2.scheduled_date = eri1.scheduled_date
1260               AND NVL(eri2.alternate_bom_designator, 'primary') = NVL(eri1.alternate_bom_designator, 'primary'))
1261        AND eri1.parent_revised_item_seq_id IS NULL
1262        AND eri1.status_type <> 5
1263        AND ROWNUM < 2;
1264   EXCEPTION
1265   WHEN NO_DATA_FOUND THEN
1266       l_local_revised_item_exists := G_VAL_FALSE;
1267   END;
1268   Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Value l_local_revised_item_exists: '||l_local_revised_item_exists);
1269 
1270   IF (l_local_revised_item_exists = G_VAL_TRUE)
1271   THEN
1272       Error_Handler.Add_Error_Token(
1273           p_Message_Name       => 'ENG_PRP_EXISTS_IN_CO'
1274         , p_Mesg_Token_Tbl     => l_mesg_token_tbl
1275         , x_Mesg_Token_Tbl     => l_mesg_token_tbl
1276         , p_Token_Tbl          => l_token_tbl
1277        );
1278        l_error_logged := G_VAL_TRUE;
1279   ELSE
1280     Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Validation: Checking if item exists in local Organization');
1281     BEGIN
1282         SELECT 1
1283         into l_item_exists_in_org_flag
1284         FROM   mtl_system_items_b_kfv
1285         WHERE  inventory_item_id = p_revised_item_id
1286         AND    organization_id = p_local_org_id;
1287     EXCEPTION
1288     WHEN NO_DATA_FOUND THEN
1289         l_item_exists_in_org_flag := 0;
1290     END;
1291 
1292     Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Value l_item_exists_in_org_flag: '||l_item_exists_in_org_flag);
1293 
1294     SELECT concatenated_segments
1295     into l_revised_item_number
1296     FROM   mtl_system_items_b_kfv
1297     WHERE  inventory_item_id = p_revised_item_id
1298     AND    organization_id = g_global_org_id;
1299 
1300     Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Value l_revised_item_number: '||l_revised_item_number);
1301 
1302     -- 11.5.10 Feature: Scoped Out
1303     -- If item does not exist in local organization but it is set to be enabled per organization
1304     -- at the change type level, then check if it is a transfer item and Auto Enable
1305     IF (l_item_exists_in_org_flag = 0 AND  p_transfer_item_enable = 1)
1306     THEN
1307         Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Item does not exist in Organization and it is supposed to be enabled for tranfer');
1308         -- Enable item in local org
1309         IF (p_transfer_or_copy = 'T' AND p_transfer_or_copy_item = 1 )
1310         THEN
1311             Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Transfer Item Enabling In Progress ..');
1312             AUTO_ENABLE_ITEM_IN_ORG(
1313                 p_inventory_item_id   => p_revised_item_id
1314               , p_organization_id => p_local_org_id
1315               , x_error_table     => l_item_error_table
1316               , x_return_status   => l_return_status);
1317 
1318             IF (l_return_status = 'S')
1319             THEN
1320                 Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Transfer Item Enabling Successful');
1321                 l_item_exists_in_org_flag := 1;
1322 
1323                 l_token_tbl.delete;
1324                 l_token_tbl(1).token_name  := 'ITEM';
1325                 l_token_tbl(1).token_value := l_revised_item_number;
1326                 Error_Handler.Add_Error_Token(
1327                     p_Message_Name       => 'ENG_PRP_TRNSMFG_ENABLED'
1328                   , p_Mesg_Token_Tbl     => l_mesg_token_tbl
1329                   , x_Mesg_Token_Tbl     => l_mesg_token_tbl
1330                   , p_Token_Tbl          => l_token_tbl
1331                   , p_message_type       => 'I' );
1332             ELSE
1333                 l_error_logged := G_VAL_TRUE;
1334                 Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Transfer Item Enabling Error');
1335                 FOR i IN 1..l_item_error_table.COUNT
1336                 LOOP
1337                     Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Transfer Item Enabling Error:'||l_item_error_table(i).message_name);
1338                     Error_Handler.Add_Error_Token(
1339                         p_Message_Name   => NULL
1340                       , p_Message_Text   => l_item_error_table(i).message_text
1341                       , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1342                       , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
1343                      );
1344                 END LOOP;
1345                 -- Resetting the item error table
1346                 l_item_error_table.delete;
1347             END IF;
1348         END IF;
1349     END IF;
1350 
1351     Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Value Post Auto Enable for transfer l_item_exists_in_org_flag: '||l_item_exists_in_org_flag);
1352 
1353     -- If Item does not exist in local organization throw an error
1354     IF (l_item_exists_in_org_flag = 0)
1355     THEN
1356         Error_Handler.Add_Error_Token(
1357             p_Message_Name       => 'ENG_PRP_DOES_NOT_EXIST'
1358           , p_Mesg_Token_Tbl     => l_mesg_token_tbl
1359           , x_Mesg_Token_Tbl     => l_mesg_token_tbl
1360           , p_Token_Tbl          => l_token_tbl
1361          );
1362         l_error_logged := 1;
1363     ELSIF (l_item_exists_in_org_flag = 1 AND p_use_up_item_id IS NOT NULL)
1364     THEN
1365         -- If item exists check for use up item
1366         Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Validation: Check if use up item Exists');
1367         BEGIN
1368             SELECT 1
1369               INTO l_use_up_item_exists
1370               FROM mtl_system_items
1371              WHERE inventory_item_id = p_use_up_item_id
1372                AND organization_id = p_local_org_id;
1373         EXCEPTION
1374         WHEN NO_DATA_FOUND THEN
1375             Error_Handler.Add_Error_Token(
1376                 p_Message_Name       => 'ENG_PRP_INVAL_USEUP'
1377               , p_Mesg_Token_Tbl     => l_mesg_token_tbl
1378               , x_Mesg_Token_Tbl     => l_mesg_token_tbl
1379               , p_Token_Tbl          => l_token_tbl);
1380             l_error_logged := 1;
1381             l_item_exists_in_org_flag := 0;
1382         END;
1383         Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Value l_use_up_item_exists'|| l_use_up_item_exists);
1384     END IF;
1385 
1386     --
1387     -- Proceed with processing only if item and Use up exists in local Organization
1388     IF (l_item_exists_in_org_flag = 1)
1389     THEN
1390         Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Proceed with processing as item and use up are valid for local Organization');
1391         x_propagate_strc_changes := G_VAL_TRUE;
1392         --
1393         -- Check if sourcing rules exist for item
1394         l_item_sourced_flag := CHECK_SOURCING_RULES(p_local_org_id , p_revised_item_id);
1395         Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Fetch sourcing rules for item in local organization Value: l_item_sourced_flag'||l_item_sourced_flag);
1396 
1397         --
1398         -- Check if structure line - bill exists
1399         FOR sl in c_rev_item_struc_lines(p_rev_item_seq_id)
1400         LOOP
1401             l_structure_exists_flag := 1;
1402             BEGIN
1403                 select bill_sequence_id, source_bill_sequence_id
1404                   into l_local_bill_sequence_id, l_comn_bill_sequence_id
1405                   FROM BOM_BILL_OF_MATERIALS
1406                  WHERE assembly_item_id = sl.revised_item_id
1407                    AND organization_id  = p_local_org_id
1408                    AND nvl(alternate_bom_designator, 'PRIMARY') = nvl(sl.alternate_bom_designator, 'PRIMARY');
1409             EXCEPTION
1410             WHEN NO_DATA_FOUND THEN
1411                 l_structure_exists_flag := 0;
1412             END;
1413 
1414             -- Bug 3503525:
1415             -- If all the components are of type add and stryctur does not exist,
1416             -- then the ECO BO create the primary bill.
1417             -- Hence should not throw error "Structute does not exist" in such a case.
1418             IF(l_structure_exists_flag = 0)
1419             THEN
1420                 l_create_bill_for_item := 0;
1421                 BEGIN
1422                     -- Check if all components are of type add the l_create_bill_for_item = 1
1423                     -- l_create_bill_for_item = 0 otherwise
1424                     SELECT 1, 1
1425                     INTO l_structure_exists_flag, l_create_bill_for_item
1426                     FROM dual
1427                     WHERE NOT EXISTS (SELECT 1
1428                         FROM bom_inventory_components
1429                         WHERE change_notice = sl.change_notice
1430                         AND revised_item_sequence_id = sl.revised_item_sequence_id
1431                         AND acd_type IN (2,3));
1432                 EXCEPTION
1433                 WHEN NO_DATA_FOUND THEN
1434                     null;
1435                 END;
1436             END IF;
1437             Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Value l_structure_exists_flag:' || l_structure_exists_flag);
1438             Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Value l_create_bill_for_item:' || l_create_bill_for_item);
1439 
1440             IF (l_item_sourced_flag = 1 AND l_structure_exists_flag = 1)
1441             THEN
1442                 -- Log a message and do not continue
1443                 Error_Handler.Add_Error_Token(
1444                     p_Message_Name       => 'ENG_PRP_SRC_RULES'
1445                   , p_Mesg_Token_Tbl     => l_mesg_token_tbl
1446                   , x_Mesg_Token_Tbl     => l_mesg_token_tbl
1447                   , p_Token_Tbl          => l_token_tbl
1448                   , p_message_type       => 'I');
1449 
1450                 EXIT; --  Exits Loop
1451             ELSIF (l_item_sourced_flag = 2)
1452             THEN
1453                 -- if this is an end item effective structure change
1454                 -- then it will not be propgated to the child organization
1455                 IF sl.from_end_item_rev_id IS NOT NULL
1456                 THEN
1457                     x_propagate_strc_changes := G_VAL_FALSE;
1458                     Error_Handler.Add_Error_Token(
1459                         p_Message_Name       => 'ENG_PRP_REVEFF_STRC_DISABLED'
1460                       , p_Mesg_Token_Tbl     => l_mesg_token_tbl
1461                       , x_Mesg_Token_Tbl     => l_mesg_token_tbl
1462                       , p_Token_Tbl          => l_token_tbl
1463                       , p_message_type       => 'I' );
1464 
1465                 ELSIF sl.bill_sequence_id <> nvl(sl.source_bill_sequence_id, sl.bill_sequence_id)
1466                 THEN
1467                     x_propagate_strc_changes := G_VAL_FALSE;
1468                     Error_Handler.Add_Error_Token(
1469                         p_Message_Name       => 'ENG_PRP_COMN_STRC_DISABLED'
1470                       , p_Mesg_Token_Tbl     => l_mesg_token_tbl
1471                       , x_Mesg_Token_Tbl     => l_mesg_token_tbl
1472                       , p_Token_Tbl          => l_token_tbl
1473                       , p_message_type       => 'I' );
1474                 ELSIF l_structure_exists_flag = 0
1475                 THEN
1476                     l_token_tbl.delete;
1477                     l_token_tbl(1).token_name  := 'STRUCTURE';
1478                     l_token_tbl(1).token_value := sl.alternate_bom_designator;
1479                     Error_Handler.Add_Error_Token(
1480                         p_Message_Name       => 'ENG_PRP_STRC_NOT_EXISTS'
1481                       , p_Mesg_Token_Tbl     => l_mesg_token_tbl
1482                       , x_Mesg_Token_Tbl     => l_mesg_token_tbl
1483                       , p_Token_Tbl          => l_token_tbl);
1484                     l_error_logged := 1;
1485                 ELSIF l_structure_exists_flag = 1
1486                 THEN
1487                     -- if all components are of type add,
1488                     -- initialize the structure line pl/sql table with defaults, so that they are not validated
1489                     IF (l_create_bill_for_item = 1)
1490                     THEN
1491                         l_local_bill_sequence_id := 0;
1492                         l_comn_bill_sequence_id := 0;
1493                         l_from_end_item_minor_rev_id := null;
1494                         l_from_end_item_rev_id := null;
1495                     ELSE
1496                         l_from_end_item_minor_rev_id := sl.from_end_item_strc_rev_id;
1497                         l_from_end_item_rev_id := sl.from_end_item_rev_id;
1498                     END IF;
1499 
1500                     l_struc_line_tbl(l_struc_count).revised_item_sequence_id := sl.revised_item_sequence_id;
1501                     l_struc_line_tbl(l_struc_count).alternate_bom_designator := sl.alternate_bom_designator;
1502                     l_struc_line_tbl(l_struc_count).bill_sequence_id := sl.bill_sequence_id;
1503                     l_struc_line_tbl(l_struc_count).local_bill_sequence_id := l_local_bill_sequence_id;
1504                     l_struc_line_tbl(l_struc_count).comn_bill_sequence_id := l_comn_bill_sequence_id;
1505                     l_struc_line_tbl(l_struc_count).from_end_item_minor_rev_id := l_from_end_item_minor_rev_id;
1506                     l_struc_line_tbl(l_struc_count).from_end_item_rev_id := l_from_end_item_rev_id;
1507 
1508                 END IF;
1509             END IF;
1510         END LOOP;
1511 
1512         --
1513         -- if all structures exist
1514         -- auto enable transfer items with enable item in local org -> 'Y'. Log Info
1515         -- auto enable comps and subs comps of acd_type add if item is not sourced. Log Info
1516         -- For all components and substitute comps not in local org, log error
1517         -- For invalid from_end_item dtls , log error
1518         /*IF (l_error_logged = 0)
1519         THEN
1520             -- get all items with enable item for transfer
1521             -- Scoped out
1522             FOR tle in c_rev_items_for_enable(p_rev_item_seq_id)
1523             LOOP
1524                 AUTO_ENABLE_ITEM_IN_ORG(
1525                     p_inventory_item_id   => tle.revised_item_id
1526                   , p_organization_id => p_local_org_id
1527                   , x_error_table     => l_item_error_table
1528                   , x_return_status   => l_return_status);
1529                 IF (l_return_status = 'S')
1530                 THEN
1531                     l_token_tbl.delete;
1532                     l_token_tbl(1).token_name  := 'ITEM';
1533                     l_token_tbl(1).token_value := tle.item_name;
1534                     Error_Handler.Add_Error_Token(
1535                         p_Message_Name       => 'ENG_PRP_TRNSMFG_ENABLED'
1536                       , p_Mesg_Token_Tbl     => l_mesg_token_tbl
1537                       , x_Mesg_Token_Tbl     => l_mesg_token_tbl
1538                       , p_Token_Tbl          => l_token_tbl
1539                       , p_message_type       => 'I' );
1540                 ELSE
1541                     FOR i IN 1..l_item_error_table.COUNT
1542                     LOOP
1543                         Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Transfer Item Enabling Error:'||l_item_error_table(i).message_name);
1544                         l_token_tbl.delete;
1545                         l_token_tbl(1).token_name  := 'MESSAGE';
1546                         l_token_tbl(1).token_value := l_item_error_table(i).message_name;
1547                         Error_Handler.Add_Error_Token(
1548                             p_Message_Name       => 'ENG_ERROR_MESSAGE'
1549                           , p_Mesg_Token_Tbl     => l_mesg_token_tbl
1550                           , x_Mesg_Token_Tbl     => l_mesg_token_tbl
1551                           , p_Token_Tbl          => l_token_tbl
1552                          );
1553 
1554                         l_error_logged := 1;
1555                     END LOOP;
1556                     l_item_error_table.delete;
1557                 END IF;
1558             END LOOP;
1559         END IF;*/
1560 
1561         IF (l_error_logged = 0)
1562         THEN
1563             -- If no errors logged so far then process Transfer components
1564             -- Currently scoped out , transfer/copy components are not propagated. Loop does not process
1565             /*FOR tolc IN c_tolc_items
1566             LOOP
1567 
1568                 BEGIN
1569                     select 1
1570                     into    l_item_exists_in_org_flag
1571                     FROM   mtl_system_items_b
1572                     WHERE  inventory_item_id = tolc.revised_item_id
1573                     AND    organization_id = p_local_org_id;
1574                 EXCEPTION
1575                 WHEN NO_DATA_FOUND THEN
1576                     l_item_exists_in_org_flag := 0;
1577                 END;
1578                 IF (l_item_exists_in_org_flag = 0)
1579                 THEN
1580                     select concatenated_segments
1581                     into l_temp_item_name
1582                     from mtl_system_items_b_kfv
1583                     where inventory_item_id = tolc.revised_item_id
1584                     and organization_id = p_global_org_id;
1585 
1586                     Fnd_message.set_name('ENG', 'ENG_PRP_ITM_NOT_EXISTS');
1587                     fnd_message.set_token('ITEM', l_temp_item_name);
1588                     l_message_log_text := fnd_message.get();
1589 
1590                     l_eco_error_tbl(l_err_counter).Revised_item_sequence_id := p_rev_item_seq_id;
1591                     l_eco_error_tbl(l_err_counter).log_text := l_message_log_text;
1592                     l_eco_error_tbl(l_err_counter).log_type := 'ERROR';
1593                     l_err_counter := l_err_counter + 1;
1594                     l_error_logged := 1;
1595 
1596                 ELSIF (l_item_exists_in_org_flag = 1 AND tolc.transfer_or_copy_bill = 1)
1597                 THEN
1598                         BEGIN
1599                         l_structure_exists_flag := 1;
1600                         select bill_sequence_id, common_bill_sequence_id, assembly_type
1601                         into l_local_bill_sequence_id, l_comn_bill_sequence_id, l_eng_bill_flag
1602                         FROM BOM_BILL_OF_MATERIALS
1603                         WHERE assembly_item_id = tolc.revised_item_id
1604                         AND   organization_id  = p_local_org_id
1605                         AND   nvl(alternate_bom_designator, 'PRIMARY') = nvl(tolc.alternate_bom_designator, 'PRIMARY');
1606                     EXCEPTION
1607                     WHEN NO_DATA_FOUND THEN
1608                         l_structure_exists_flag := 0;
1609                     END;
1610                     IF (l_structure_exists_flag = 0)
1611                     THEN
1612                         Fnd_message.set_name('ENG', 'ENG_ITEM_LC_PHASE_CHG_LINE');
1613                         l_temp_mesg := fnd_message.get();
1614                         Fnd_message.set_name('ENG', 'ENG_PRP_STRC_NOT_EXISTS');
1615                         fnd_message.set_token('STRUCTURE', tolc.alternate_bom_designator);
1616                         fnd_message.set_token('LINE', l_temp_mesg);
1617                         l_message_log_text := fnd_message.get();
1618 
1619                         l_error_logged := 1;
1620                         l_eco_error_tbl(l_err_counter).Revised_item_sequence_id := p_rev_item_seq_id;
1621                         l_eco_error_tbl(l_err_counter).log_text := l_message_log_text;
1622                         l_eco_error_tbl(l_err_counter).log_type := 'ERROR';
1623                         l_err_counter := l_err_counter + 1;
1624                     ELSE
1625                         l_transfer_item_sourced_flag := 2;
1626 
1627                         IF (l_comn_bill_sequence_id <> l_local_bill_sequence_id
1628                             AND tolc.transfer_or_copy = 'T'
1629                             AND tolc.create_bom_in_local_org = 'Y'
1630                             AND l_comn_bill_sequence_id = tolc.bill_sequence_id
1631                             AND l_eng_bill_flag <> 1)
1632                         THEN
1633 
1634                             -- check if sourcing rules exist for item
1635                             l_transfer_item_sourced_flag := CHECK_SOURCING_RULES(p_local_org_id, tolc.revised_item_id);
1636 
1637                             IF ( l_transfer_item_sourced_flag = 2)
1638                             THEN
1639                                 BREAK_COMMON_BOM(
1640                                     p_to_sequence_id    => l_local_bill_sequence_id
1641                                   , p_from_sequence_id  => tolc.bill_sequence_id
1642                                   , p_from_org_id       => p_global_org_id
1643                                   , p_to_org_id         => p_local_org_id
1644                                   , p_to_item_id        => tolc.revised_item_id
1645                                   , p_to_alternate      => tolc.alternate_bom_designator
1646                                   , p_from_item_id      => tolc.revised_item_id);
1647 
1648                                 l_comn_bill_sequence_id := l_local_bill_sequence_id;
1649 
1650                                 Fnd_message.set_name('ENG', 'ENG_PRP_COMN_BOM_BREAK');
1651                                 fnd_message.set_token('STRUCTURE', tolc.alternate_bom_designator);
1652                                 l_message_log_text := fnd_message.get();
1653                                 l_eco_mesg_tbl(l_mesg_counter).Revised_item_sequence_id := p_rev_item_seq_id;
1654                                 l_eco_mesg_tbl(l_mesg_counter).log_text := l_message_log_text;
1655                                 l_eco_mesg_tbl(l_mesg_counter).log_type := 'INFO';
1656                                 l_mesg_counter := l_mesg_counter + 1;
1657                             END IF;
1658 
1659                             IF (l_comn_bill_sequence_id <> l_local_bill_sequence_id
1660                                 AND l_transfer_item_sourced_flag = 2
1661                                 AND l_eng_bill_flag <> 1)
1662                             THEN
1663                                 Fnd_message.set_name('ENG', 'ENG_ITEM_LC_PHASE_CHG_LINE');
1664                                 l_temp_mesg := fnd_message.get();
1665                                 Fnd_message.set_name('ENG', 'ENG_PRP_COMMON_BOM');
1666                                 fnd_message.set_token('STRUCTURE', tolc.alternate_bom_designator);
1667                                 fnd_message.set_token('LINE', l_temp_mesg);
1668                                 l_message_log_text := fnd_message.get();
1669 
1670                                 l_error_logged := 1;
1671                                 l_eco_error_tbl(l_err_counter).Revised_item_sequence_id := p_rev_item_seq_id;
1672                                 l_eco_error_tbl(l_err_counter).log_text := l_message_log_text;
1673                                 l_eco_error_tbl(l_err_counter).log_type := 'ERROR';
1674                                 l_err_counter := l_err_counter + 1;
1675                             END IF;
1676                         END IF;
1677                     END IF;
1678                 END IF;
1679             END LOOP;*/
1680 
1681             -- Further Process structure changes
1682             -- Doing this validation after break common for tolc revised items
1683             -- Check if the structure is common an delete sturcture line from being processed.
1684             -- Only attachment changes should be processed for there revised items
1685             IF (l_item_sourced_flag = 2)
1686             THEN
1687                 -- check all structures lines for common bom
1688                 FOR i IN 1..l_struc_line_tbl.COUNT
1689                 LOOP
1690                     IF (l_struc_line_tbl(i).local_bill_sequence_id <> l_struc_line_tbl(i).comn_bill_sequence_id)
1691                     THEN
1692                         Fnd_message.set_name('ENG', 'ENG_STRUCTURE_CHG_LINE');
1693                         l_temp_mesg := fnd_message.get();
1694                         l_token_tbl.delete;
1695                         l_token_tbl(1).token_name  := 'STRUCTURE';
1696                         l_token_tbl(1).token_value := l_struc_line_tbl(i).alternate_bom_designator;
1697                         l_token_tbl(2).token_name  := 'LINE';
1698                         l_token_tbl(2).token_value := l_temp_mesg;
1699                         Error_Handler.Add_Error_Token(
1700                             p_Message_Name       => 'ENG_PRP_COMMON_BOM'
1701                           , p_Mesg_Token_Tbl     => l_mesg_token_tbl
1702                           , x_Mesg_Token_Tbl     => l_mesg_token_tbl
1703                           , p_Token_Tbl          => l_token_tbl);
1704                         l_error_logged := 1;
1705                         --l_struc_line_tbl(i).delete;
1706                     END IF;
1707                 END LOOP;
1708             END IF;
1709         END IF;
1710     END IF;
1711   END IF;
1712 
1713   x_sourcing_rules_exists := l_item_sourced_flag;
1714   x_error_logged := l_error_logged;
1715   x_revised_item_name := l_revised_item_number;
1716   x_Mesg_Token_Tbl := l_mesg_token_tbl;
1717 
1718   Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Output Param:  p_propagate_revised_item    '|| l_item_exists_in_org_flag);
1719   Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Output Param:  p_sourcing_rules_exists    '|| l_item_sourced_flag);
1720   Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Output Param:  p_error_logged     '|| l_error_logged);
1721   Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Output Param:  p_revised_item_name  '|| l_revised_item_number);
1722 
1723   Eng_Propagation_Log_Util.Debug_Log(G_LOG_PROC, 'CHECK_REVISED_ITEM_ERRORS.end');
1724   Eng_Propagation_Log_Util.Debug_Log(G_LOG_PROC, '-------------------------------');
1725 EXCEPTION
1726 WHEN OTHERS THEN
1727   Eng_Propagation_Log_Util.Debug_Log(Eng_Propagation_Log_Util.G_LOG_ERROR, 'CHECK_REVISED_ITEM_ERRORS.Unexpected error'|| SQLERRM);
1728 END Check_Revised_Item_Errors;
1729 
1730 PROCEDURE PROPAGATE_ECO_ERP
1731 (
1732    errbuf                 OUT NOCOPY   VARCHAR2,
1733    retcode                OUT NOCOPY    VARCHAR2,
1734    p_change_notice        IN     VARCHAR2,
1735    p_org_hierarchy_name   IN     VARCHAR2,
1736    p_org_hierarchy_level  IN     VARCHAR2
1737 )
1738 IS
1739    l_eco_rec                   Eng_Eco_Pub.Eco_Rec_Type;
1740    l_change_lines_tbl          Eng_Eco_Pub.Change_Line_Tbl_Type;
1741    l_eco_revision_tbl          Eng_Eco_Pub.Eco_Revision_Tbl_Type;
1742    l_revised_item_tbl          Eng_Eco_Pub.Revised_Item_Tbl_Type;
1743    l_rev_component_tbl         Bom_Bo_Pub.Rev_Component_Tbl_Type;
1744    l_sub_component_tbl         Bom_Bo_Pub.Sub_Component_Tbl_Type;
1745    l_ref_designator_tbl        Bom_Bo_Pub.Ref_Designator_Tbl_Type;
1746    l_rev_operation_tbl         Bom_Rtg_Pub.Rev_Operation_Tbl_Type;
1747    l_rev_op_resource_tbl       Bom_Rtg_Pub.Rev_Op_Resource_Tbl_Type;
1748    l_rev_sub_resource_tbl      Bom_Rtg_Pub.Rev_Sub_Resource_Tbl_Type;
1749 
1750    l_org_code_list             INV_OrgHierarchy_PVT.OrgID_tbl_type;
1751    l_org_hierarchy_level_id    NUMBER;
1752    l_org_code                  VARCHAR2(3);
1753    l_org_id                    NUMBER;
1754    l_change_type_code          VARCHAR2(80);
1755    l_requestor_name            VARCHAR2(30);
1756    l_assignee_name             VARCHAR2(30);
1757    l_Task_Number           VARCHAR2(25);
1758    /* changing for UTF8 Column Expansion */
1759    l_Project_Number        VARCHAR2(30);
1760    l_rev_description           VARCHAR2(240);
1761    l_approval_list_name        VARCHAR2(10);
1762    /* changing for UTF8 Column Expansion */
1763    l_department_name           VARCHAR2(240);
1764    l_revised_item_number       VARCHAR2(801);
1765    l_use_up_item_name          VARCHAR2(801);
1766    l_revised_item_name         VARCHAR2(801);
1767    l_new_item_revision         VARCHAR2(3);
1768    l_effectivity_date          DATE;
1769    l_revised_item_name1        VARCHAR2(801);
1770    l_revised_item_name2        VARCHAR2(801);
1771    l_component_item_name       VARCHAR2(801);
1772    l_component_item_name1      VARCHAR2(801);
1773    l_component_item_name2      VARCHAR2(801);
1774    l_location_name             VARCHAR2(81);
1775    l_substitute_component_name VARCHAR2(801);
1776    l_operation_seq_num         NUMBER;
1777    l_item_exits_in_org_flag    NUMBER;
1778    l_check_invalid_objects     NUMBER := 1;
1779 
1780    l_return_status             VARCHAR2(1);
1781    l_msg_count                 NUMBER;
1782    l_msg_data                  VARCHAR2(2000);
1783    l_Error_Table               Error_Handler.Error_Tbl_Type;
1784    l_Message_text              VARCHAR2(2000);
1785 
1786    l_org_count                 NUMBER;
1787    l_count                     NUMBER;
1788    temp_count                  NUMBER := 0;
1789    i                           NUMBER;
1790    item_id                     NUMBER;
1791    bill_id                     NUMBER;
1792    old_operation_seq_num       NUMBER;
1793    old_effectivity_date        DATE;
1794    l_old_effectivity_date        DATE;
1795    component_seq_id            NUMBER;
1796    St_Number               NUMBER;
1797 
1798    l_eco_status_name          eng_change_statuses_vl.status_name%TYPE; -- bug 3571079
1799 
1800 -- Added for Bug-5725081
1801 
1802    v_component_quantity_to     NUMBER ;
1803    v_component_low_quantity    NUMBER ;
1804    v_component_high_quantity   NUMBER ;
1805    v_substitute_item_quantity  NUMBER ;
1806 
1807 /* Cursor to Pick all ECO header for the Top Organization for the given Change N
1808 otice */
1809 
1810    CURSOR c_eco_rec IS
1811    SELECT *
1812    FROM   eng_changes_v
1813    WHERE  change_notice = p_change_notice
1814    AND    organization_id = l_org_hierarchy_level_id;
1815 
1816 /* Cursor to Pick all Revised Items for the Top Organization  for the given Chan
1817 ge Notice*/
1818 
1819    CURSOR c_eco_revision IS
1820    SELECT *
1821    FROM   eng_change_order_revisions
1822    WHERE  change_notice = p_change_notice
1823    AND    organization_id = l_org_hierarchy_level_id;
1824 
1825 /* Cursor to Pick all Revised Items for the Top Organization  for the given Chan
1826 ge Notice.Bug no 4327321  only revised items will get propagate.No transfer and copy items.*/
1827 
1828    CURSOR c_rev_items IS
1829    SELECT *
1830    FROM   eng_revised_items
1831    WHERE  change_notice = p_change_notice
1832    AND    organization_id = l_org_hierarchy_level_id
1833    AND  transfer_or_copy is NULL;
1834 
1835 
1836 /* cursor to pick up Revised component records for the top organization for
1837   the given change notice which have the ACD_type of Disable and have been
1838   implementedfrom eng_revised_items table. These records are not present in
1839   bom_inventory_components table hence this extra cursor. */
1840 
1841    CURSOR c_rev_comps_disable IS
1842    SELECT *
1843    FROM   eng_revised_components
1844    WHERE  change_notice = p_change_notice
1845    AND    ACD_TYPE = 3
1846    AND    revised_item_sequence_id in
1847       (SELECT revised_item_sequence_id
1848           FROM   eng_revised_items
1849           WHERE  change_notice = p_change_notice
1850           AND    organization_id = l_org_hierarchy_level_id);
1851 
1852 /* Cursor to Pick all Revised Component Items for the Top Organization  for the
1853 given Change Notice*/
1854 
1855    CURSOR c_rev_comps IS
1856    SELECT *
1857    FROM   bom_inventory_components
1858    WHERE  change_notice = p_change_notice
1859    AND    revised_item_sequence_id in
1860           (SELECT revised_item_sequence_id
1861           FROM   eng_revised_items
1862           WHERE  change_notice = p_change_notice
1863           AND    organization_id = l_org_hierarchy_level_id);
1864 
1865 /* Cursor to Pick all substitute Component Items for the Top Organization  for t
1866 he given Change Notice*/
1867 
1868    CURSOR c_sub_comps IS
1869    SELECT *
1870    FROM   bom_substitute_components
1871    WHERE  change_notice = p_change_notice
1872    AND    component_sequence_id in
1873           (SELECT component_sequence_id
1874           FROM   bom_inventory_components
1875           WHERE  change_notice = p_change_notice
1876           AND    revised_item_sequence_id in
1877                  (SELECT revised_item_sequence_id
1878                  FROM   eng_revised_items
1879                  WHERE  change_notice = p_change_notice
1880                  AND    organization_id = l_org_hierarchy_level_id));
1881 
1882 /* Cursor to Pick all reference designators for the Top Organization  for the gi
1883 ven Change Notice*/
1884 
1885    CURSOR c_ref_desgs IS
1886    SELECT *
1887    FROM   bom_reference_designators
1888    WHERE  change_notice = p_change_notice
1889    AND    component_sequence_id in
1890           (SELECT component_sequence_id
1891           FROM   bom_inventory_components
1892           WHERE  change_notice = p_change_notice
1893           AND    revised_item_sequence_id in
1894                  (SELECT revised_item_sequence_id
1895                  FROM   eng_revised_items
1896                  WHERE  change_notice = p_change_notice
1897                  AND    organization_id = l_org_hierarchy_level_id));
1898 
1899    -- Modified query for performance bug 4251776
1900    -- Bug No: 4327218
1901    -- Modified query to refer to 'person_party_id' instead of 'customer_id'
1902    CURSOR c_user_name(v_party_id IN NUMBER) IS
1903    SELECT us.user_name FROM fnd_user us, hz_parties pa
1904    WHERE ((us.employee_id IS NOT NULL AND us.employee_id = pa.person_identifier))
1905    AND pa.party_id = v_party_id
1906    union all
1907    SELECT us.user_name
1908    FROM fnd_user us, hz_parties pa
1909    WHERE (us.employee_id IS NULL AND (us.person_party_id= pa.party_id or (us.person_party_id is null and us.supplier_id = pa.party_id)))
1910    AND pa.party_id = v_party_id;
1911 
1912 /*   WHERE nvl(us.employee_id, nvl(us.customer_id, us.supplier_id)) = pa.person_identifier
1913      AND pa.party_id = v_party_id;*/
1914 
1915   -- Bug 4339626
1916   l_status_type     NUMBER;
1917 
1918 BEGIN
1919 
1920    FND_FILE.PUT_LINE(FND_FILE.LOG,'Starting PROPAGATE_ECO');
1921    FND_FILE.PUT_LINE(FND_FILE.LOG,'CHANGE_NOTICE '|| p_change_notice);
1922    FND_FILE.PUT_LINE(FND_FILE.LOG,'HIERARCHY_NAME '|| p_org_hierarchy_name);
1923    FND_FILE.PUT_LINE(FND_FILE.LOG,'HIERARCHY_LEVEL '|| p_org_hierarchy_level);
1924 
1925    /* Need the Organization Id to fetch the records */
1926       SELECT MP.organization_id
1927       INTO   l_org_hierarchy_level_id
1928       FROM HR_ORGANIZATION_UNITS HOU
1929       , HR_ORGANIZATION_INFORMATION HOI1
1930       , MTL_PARAMETERS MP
1931       WHERE HOU.ORGANIZATION_ID = HOI1.ORGANIZATION_ID
1932       AND HOU.ORGANIZATION_ID = MP.ORGANIZATION_ID
1933       AND HOI1.ORG_INFORMATION1 = 'INV'
1934       AND HOI1.ORG_INFORMATION2 = 'Y'
1935       AND HOU.NAME = p_org_hierarchy_level;
1936    /*SELECT organization_id
1937    INTO   l_org_hierarchy_level_id
1938    FROM   org_organization_definitions
1939    WHERE  organization_name = p_org_hierarchy_level;*/
1940 
1941    INV_ORGHIERARCHY_PVT.ORG_HIERARCHY_LIST(p_org_hierarchy_name,
1942                    l_org_hierarchy_level_id,l_org_code_list);
1943 
1944 
1945    IF (l_org_code_list.COUNT = 0) THEN
1946 
1947        FND_FILE.PUT_LINE(FND_FILE.LOG, 'No Organization exists under the Hierarchy Level '|| p_org_hierarchy_name||' and '||p_org_hierarchy_level);
1948 
1949       RETURN;
1950    END IF;
1951 
1952    IF (l_org_code_list.COUNT = 1) THEN
1953 
1954        FND_FILE.PUT_LINE(FND_FILE.LOG,'Only Organization '|| p_org_hierarchy_level|| ' exists under the Hierarchy Level'|| p_org_hierarchy_name||' and '||p_org_hierarchy_level);
1955 
1956       RETURN;
1957    END IF;
1958 
1959    FND_FILE.PUT_LINE(FND_FILE.LOG,'');
1960    FND_FILE.PUT_LINE(FND_FILE.LOG,'Organizations in Hierarchy ');
1961    FND_FILE.PUT_LINE(FND_FILE.LOG,'--------------------------');
1962    FND_FILE.PUT_LINE(FND_FILE.LOG, 'Total Orgs in Hierarchy = '||l_org_code_list.COUNT);
1963 
1964    FOR l_org_count in 1..l_org_code_list.COUNT
1965    Loop
1966        FND_FILE.PUT_LINE(FND_FILE.LOG,'Org : '||l_org_code_list(l_org_count));
1967    end loop;
1968 
1969    FND_FILE.PUT_LINE(FND_FILE.LOG,'');
1970 
1971    FOR l_org_count in 2..l_org_code_list.LAST
1972    LOOP                                                /* Loop 1 */
1973 
1974      l_org_id := l_org_code_list(l_org_count);
1975 
1976      /* Need the Organization Code for Populating PL/SQL table */
1977     -- Bug 4546616
1978     -- Check Organization is valid using exception handling
1979     BEGIN
1980 
1981      SELECT organization_code
1982      INTO   l_org_code
1983      FROM   mtl_parameters
1984      WHERE  organization_id = l_org_id;
1985     EXCEPTION
1986     WHEN NO_DATA_FOUND THEN
1987       NULL;
1988     END;
1989 
1990     IF l_org_code IS NOT NULL  /* Organization Check*/
1991     THEN
1992 
1993      FND_FILE.PUT_LINE(FND_FILE.LOG,'Processing Organization '|| l_org_code);
1994      FND_FILE.PUT_LINE(FND_FILE.LOG,'');
1995 
1996 
1997      SELECT count(*)
1998      into temp_count
1999      FROM   eng_engineering_changes
2000      WHERE  change_notice = p_change_notice
2001      AND    organization_id = l_org_id;
2002 
2003      -- Fetch ECO Masters
2004 
2005      IF temp_count > 0 THEN        /* ECO Check */
2006 
2007          FND_FILE.PUT_LINE(FND_FILE.LOG,'This ECO '||p_change_notice|| 'will not be processed as it already exists in Organization '|| l_org_code);
2008 
2009      ELSE
2010 
2011       FOR eco_rec IN c_eco_rec
2012       LOOP                                               /* Loop 2 */
2013 
2014          FND_FILE.PUT_LINE(FND_FILE.LOG,'Processing ECO Header ...');
2015 
2016          IF (eco_rec.change_order_type_id IS NOT NULL) THEN
2017 
2018             SELECT CHANGE_ORDER_TYPE
2019             INTO   l_change_type_code
2020             FROM   eng_change_order_types_v  --11.5.10 Changes
2021             WHERE  change_order_type_id = eco_rec.change_order_type_id;
2022 
2023          ELSE
2024 
2025             l_change_type_code := NULL;
2026 
2027          END IF;
2028 
2029          IF (eco_rec.responsible_organization_id IS NOT NULL) THEN
2030 
2031             SELECT name
2032             INTO   l_department_name
2033             FROM   hr_all_organization_units
2034             WHERE  organization_id = eco_rec.responsible_organization_id;
2035 
2036          ELSE
2037 
2038             l_department_name := NULL;
2039 
2040          END IF;
2041 
2042          IF (eco_rec.approval_list_id IS NOT NULL) THEN
2043 
2044             SELECT approval_list_name
2045             INTO   l_approval_list_name
2046             FROM   eng_ecn_approval_lists
2047             WHERE  approval_list_id = eco_rec.approval_list_id;
2048 
2049          ELSE
2050 
2051             l_approval_list_name := NULL;
2052 
2053          END IF;
2054 
2055          IF (eco_rec.requestor_id IS NOT NULL) THEN
2056            begin
2057              OPEN c_user_name(eco_rec.requestor_id);
2058              FETCH c_user_name INTO l_requestor_name;
2059              CLOSE c_user_name;
2060            exception
2061              When No_Data_found then
2062                FND_FILE.PUT_LINE(FND_FILE.LOG,'No_Data_found for requestor id ' || to_char( eco_rec.requestor_id) || ' in org ' || to_char(l_org_hierarchy_level_id));
2063                l_requestor_name := NULL;
2064            end;
2065 
2066 /*
2067     -- Replaced the before sql for performance.
2068        Begin
2069         SELECT employee_num
2070         INTO   l_requestor_name
2071         FROM   mtl_employees_view
2072         WHERE  organization_id = l_org_hierarchy_level_id
2073         AND    employee_id = eco_rec.requestor_id;
2074       Exception
2075         When No_Data_found then
2076          FND_FILE.PUT_LINE(FND_FILE.LOG,'No_Data_found for requestor id ' || to_char( eco_rec.requestor_id) || ' in org ' || to_char(l_org_hierarchy_level_id));
2077             l_requestor_name := NULL;
2078       End;
2079 */
2080          ELSE
2081 
2082             l_requestor_name := NULL;
2083 
2084          END IF;
2085 
2086          IF (eco_rec.assignee_id IS NOT NULL) THEN
2087            begin
2088              OPEN c_user_name(eco_rec.assignee_id);
2089              FETCH c_user_name INTO l_assignee_name;
2090              CLOSE c_user_name;
2091            exception
2092              When No_Data_found then
2093                FND_FILE.PUT_LINE(FND_FILE.LOG,'No_Data_found for assignee id ' || to_char( eco_rec.assignee_id) || ' in org ' || to_char(l_org_hierarchy_level_id));
2094                l_assignee_name := NULL;
2095            end;
2096          ELSE
2097             l_assignee_name := NULL;
2098          END IF;
2099 
2100 
2101     IF (eco_rec.PROJECT_ID IS NOT NULL) THEN
2102          Begin
2103         SELECT name
2104         into   l_Project_Number
2105         FROM   pa_projects_all
2106         WHERE  project_id = eco_rec.PROJECT_ID;
2107          Exception
2108         When No_Data_found then
2109          FND_FILE.PUT_LINE(FND_FILE.LOG,'No_Data_found for project id ' || to_char( eco_rec.PROJECT_ID));
2110             l_Project_Number := NULL;
2111       End;
2112     ELSE
2113         l_Project_Number := NULL;
2114     END IF;
2115 
2116     IF (eco_rec.TASK_ID IS NOT NULL) THEN
2117            Begin
2118         SELECT task_number
2119         into   l_Task_Number
2120         FROM   pa_tasks
2121         WHERE  TASK_ID = eco_rec.TASK_ID;
2122        Exception
2123                 When No_Data_found then
2124          FND_FILE.PUT_LINE(FND_FILE.LOG,'No_Data_found for task id ' || to_char( eco_rec.TASK_ID));
2125             l_Task_Number := NULL;
2126           End;
2127     ELSE
2128         l_Task_Number := NULL;
2129     END IF;
2130 
2131     --
2132     -- Bug 4339626
2133     -- Use the Eng_globals to initialize the details for the process associated to the type
2134     ENG_Globals.Init_Process_Name(
2135         p_change_order_type_id => eco_rec.change_order_type_id
2136       , p_priority_code        => eco_rec.priority_code
2137       , p_organization_id      => l_org_id);
2138     -- Setting the destination eco status as scheduled by default
2139     l_status_type := 4;
2140     -- If there is no process associated , then schedule the detination eco
2141     -- Create the destination ECO in Open otherwise.
2142     -- The following condition is to set the detinaion eco and revised items to open
2143     IF ENG_Globals.Get_Process_Name IS NOT NULL
2144     THEN
2145         l_status_type := 1;
2146     END IF;
2147     -- End of Bug 4339626
2148 
2149     -- Added for bug 3571079
2150     -- Fetch the status corresponding to status_code =4 i.e 'Scheduled'
2151     BEGIN
2152         SELECT status_name
2153         INTO l_eco_status_name
2154         FROM eng_change_statuses_vl
2155         WHERE status_code = l_status_type;
2156     EXCEPTION
2157     WHEN OTHERS THEN
2158         l_eco_status_name := eco_rec.eco_status;
2159     END;
2160     -- End changes for bug 3571079
2161 
2162 
2163     /*  Popuating PL/SQL record for ECO Header    */
2164 
2165 
2166          l_eco_rec.eco_name := eco_rec.change_notice;
2167          l_eco_rec.organization_code := l_org_code;
2168          l_eco_rec.change_type_code := l_change_type_code;
2169          l_eco_rec.status_name := l_eco_status_name; -- eco_rec.eco_status; -- bug 3571079
2170          l_eco_rec.eco_department_name := l_department_name;
2171          l_eco_rec.priority_code := eco_rec.priority_code;
2172          l_eco_rec.approval_list_name := l_approval_list_name;
2173          l_eco_rec.Approval_Status_Name := eco_rec.approval_status;
2174          l_eco_rec.reason_code := eco_rec.reason_code;
2175          l_eco_rec.eng_implementation_cost := eco_rec.estimated_eng_cost;
2176          l_eco_rec.mfg_implementation_cost := eco_rec.estimated_mfg_cost;
2177          l_eco_rec.cancellation_comments:=eco_rec.cancellation_comments;
2178          l_eco_rec.requestor :=  l_requestor_name;
2179          l_eco_rec.assignee :=  l_assignee_name;
2180          l_eco_rec.description := eco_rec.description;
2181      l_eco_rec.attribute_category := eco_rec.attribute_category;
2182          l_eco_rec.attribute1  := eco_rec.attribute1;
2183          l_eco_rec.attribute2  := eco_rec.attribute2;
2184          l_eco_rec.attribute3  := eco_rec.attribute3;
2185          l_eco_rec.attribute4  := eco_rec.attribute4;
2186          l_eco_rec.attribute5  := eco_rec.attribute5;
2187          l_eco_rec.attribute6  := eco_rec.attribute6;
2188          l_eco_rec.attribute7  := eco_rec.attribute7;
2189          l_eco_rec.attribute8  := eco_rec.attribute8;
2190          l_eco_rec.attribute9  := eco_rec.attribute9;
2191          l_eco_rec.attribute10  := eco_rec.attribute10;
2192          l_eco_rec.attribute11  := eco_rec.attribute11;
2193          l_eco_rec.attribute12  := eco_rec.attribute12;
2194          l_eco_rec.attribute13  := eco_rec.attribute13;
2195          l_eco_rec.attribute14  := eco_rec.attribute14;
2196          l_eco_rec.attribute15  := eco_rec.attribute15;
2197      --l_eco_rec.Original_System_Reference := eco_rec.Original_System_Reference;
2198          l_eco_rec.Project_Name := eco_rec.Project_Name;
2199          l_eco_rec.Task_Number := eco_rec.Task_Number;
2200          --l_eco_rec.hierarchy_flag := 2;
2201          l_eco_rec.organization_hierarchy := NULL;
2202          l_eco_rec.return_status := NULL;
2203          l_eco_rec.transaction_type := 'CREATE';
2204          --11.5.10
2205      l_eco_rec.plm_or_erp_change := eco_rec.plm_or_erp_change;
2206          -- Fetch ECO Revisions
2207 
2208          i := 1;
2209 
2210          FOR rev IN c_eco_revision
2211          LOOP                                            /* Loop 3 */
2212 
2213          FND_FILE.PUT_LINE(FND_FILE.LOG,'Processing ECO Revision ...');
2214 
2215             l_eco_revision_tbl(i).eco_name := rev.change_notice;
2216             l_eco_revision_tbl(i).organization_code:= l_org_code;
2217             l_eco_revision_tbl(i).revision := rev.revision;
2218        --     l_eco_revision_tbl(i).new_revision := rev.new_revision;
2219         l_eco_revision_tbl(i).new_revision := NULL;
2220         l_eco_revision_tbl(i).Attribute_category := rev.Attribute_category;
2221             l_eco_revision_tbl(i).attribute1  := rev.attribute1;
2222             l_eco_revision_tbl(i).attribute2  := rev.attribute2;
2223             l_eco_revision_tbl(i).attribute3  := rev.attribute3;
2224             l_eco_revision_tbl(i).attribute4  := rev.attribute4;
2225             l_eco_revision_tbl(i).attribute5  := rev.attribute5;
2226             l_eco_revision_tbl(i).attribute6  := rev.attribute6;
2227             l_eco_revision_tbl(i).attribute7  := rev.attribute7;
2228             l_eco_revision_tbl(i).attribute8  := rev.attribute8;
2229             l_eco_revision_tbl(i).attribute9  := rev.attribute9;
2230             l_eco_revision_tbl(i).attribute10  :=rev.attribute10;
2231             l_eco_revision_tbl(i).attribute11  :=rev.attribute11;
2232             l_eco_revision_tbl(i).attribute12  :=rev.attribute12;
2233             l_eco_revision_tbl(i).attribute13  := rev.attribute13;
2234             l_eco_revision_tbl(i).attribute14  := rev.attribute14;
2235             l_eco_revision_tbl(i).attribute15  := rev.attribute15;
2236         l_eco_revision_tbl(i).Original_System_Reference :=
2237                                  rev.Original_System_Reference;
2238             l_eco_revision_tbl(i).comments := rev.comments;
2239             l_eco_revision_tbl(i).return_status := NULL;
2240             l_eco_revision_tbl(i).transaction_type := 'CREATE';
2241 
2242             i := i + 1;
2243 
2244          END LOOP;                                     /* End Loop 3 */
2245 
2246          FND_FILE.PUT_LINE(FND_FILE.LOG,'');
2247 
2248          -- Fetch revised items
2249 
2250          i := 1;
2251 
2252          FOR ri IN c_rev_items
2253          LOOP                                         /* Loop 4 */
2254 
2255           FND_FILE.PUT_LINE(FND_FILE.LOG,'Processing Revised Items ...');
2256 
2257           BEGIN
2258 
2259              l_item_exits_in_org_flag := 1;
2260 
2261              SELECT concatenated_segments
2262              INTO   l_revised_item_number
2263              FROM   mtl_system_items_b_kfv
2264              WHERE  inventory_item_id = ri.revised_item_id
2265              AND    organization_id = l_org_id;
2266           EXCEPTION
2267              WHEN NO_DATA_FOUND THEN
2268           l_item_exits_in_org_flag := 0;
2269               l_check_invalid_objects := 0;
2270           END;
2271 
2272           IF (l_item_exits_in_org_flag = 1) THEN
2273 
2274              IF (ri.use_up_item_id IS NOT NULL) THEN
2275 
2276                BEGIN
2277                  SELECT concatenated_segments
2278                  INTO   l_use_up_item_name
2279                  FROM   mtl_system_items_b_kfv
2280                  WHERE  inventory_item_id = ri.use_up_item_id
2281                  AND    organization_id = l_org_id;
2282                EXCEPTION WHEN NO_DATA_FOUND THEN
2283                  l_item_exits_in_org_flag := 0;
2284                  l_check_invalid_objects := 0;
2285                END;
2286 
2287              ELSE
2288 
2289                l_use_up_item_name := NULL;
2290 
2291              END IF;
2292 
2293              FND_FILE.PUT_LINE(FND_FILE.LOG,'');
2294 
2295              IF (l_item_exits_in_org_flag = 1) THEN
2296                l_revised_item_tbl(i).eco_name := ri.change_notice;
2297                l_revised_item_tbl(i).organization_code := l_org_code;
2298                l_revised_item_tbl(i).revised_item_name := l_revised_item_number;
2299                IF ((ri.new_item_revision = FND_API.G_MISS_CHAR) OR
2300             (ri.new_item_revision IS NULL)) THEN
2301                   l_revised_item_tbl(i).new_revised_item_revision := NULL;
2302                ELSE
2303                   l_revised_item_tbl(i).new_revised_item_revision :=
2304                                    ri.new_item_revision;
2305               SELECT DESCRIPTION
2306           INTO   l_rev_description
2307           FROM   mtl_item_revisions
2308           WHERE  inventory_item_id = ri.revised_item_id
2309           AND    organization_id = ri.organization_id
2310           AND    revision    = ri.new_item_revision ;
2311               l_revised_item_tbl(i).New_Revised_Item_Rev_Desc :=
2312                     l_rev_description;
2313               l_revised_item_tbl(i).Updated_Revised_Item_Revision := NULL;
2314                END IF;
2315                l_revised_item_tbl(i).start_effective_date :=
2316             ri.scheduled_date;
2317            l_revised_item_tbl(i).New_Effective_Date := NULL;
2318                l_revised_item_tbl(i).alternate_bom_code :=
2319                                       NULL;
2320 
2321 /*    This is always NULL as we are not creating ALternate Bills in the
2322       Hierarchy */
2323 /*    Revised Item Status has to be Scheduled as the Propagated ECOs
2324       have to be scheduled automatically so that they will be picked
2325       by Auto Implement for Implementation
2326 */
2327                l_revised_item_tbl(i).status_type := l_status_type;
2328                l_revised_item_tbl(i).mrp_active := ri.mrp_active;
2329                l_revised_item_tbl(i).earliest_effective_date :=
2330                                    ri.early_schedule_date;
2331                l_revised_item_tbl(i).use_up_item_name := l_use_up_item_name;
2332                l_revised_item_tbl(i).use_up_plan_name := ri.use_up_plan_name;
2333            l_revised_item_tbl(i).Requestor := NULL;
2334                l_revised_item_tbl(i).disposition_type := ri.disposition_type;
2335                l_revised_item_tbl(i).update_wip := ri.update_wip;
2336                l_revised_item_tbl(i).cancel_comments := ri.cancel_comments;
2337 --             l_revised_item_tbl(i).cfm_routing_flag :=
2338 --          ri.cfm_routing_flag;
2339                l_revised_item_tbl(i).ctp_flag := ri.ctp_flag;
2340                l_revised_item_tbl(i).return_status := NULL;
2341                l_revised_item_tbl(i).change_description :=
2342             ri.descriptive_text;
2343            l_revised_item_tbl(i).Attribute_category :=
2344             ri.Attribute_category;
2345                l_revised_item_tbl(i).attribute1  := ri.attribute1;
2346                l_revised_item_tbl(i).attribute2  := ri.attribute2;
2347                l_revised_item_tbl(i).attribute3  := ri.attribute3;
2348                l_revised_item_tbl(i).attribute4  := ri.attribute4;
2349                l_revised_item_tbl(i).attribute5  := ri.attribute5;
2350                l_revised_item_tbl(i).attribute6  := ri.attribute6;
2351                l_revised_item_tbl(i).attribute7  := ri.attribute7;
2352                l_revised_item_tbl(i).attribute8  := ri.attribute8;
2353                l_revised_item_tbl(i).attribute9  := ri.attribute9;
2354                l_revised_item_tbl(i).attribute10  := ri.attribute10;
2355                l_revised_item_tbl(i).attribute11  := ri.attribute11;
2356                l_revised_item_tbl(i).attribute12  := ri.attribute12;
2357                l_revised_item_tbl(i).attribute13  := ri.attribute13;
2358                l_revised_item_tbl(i).attribute14  := ri.attribute14;
2359                l_revised_item_tbl(i).attribute15  := ri.attribute15;
2360            l_revised_item_tbl(i).From_End_Item_Unit_Number :=
2361                 ri.From_End_Item_Unit_Number;
2362            l_revised_item_tbl(i).New_From_End_Item_Unit_Number := NULL;
2363            l_revised_item_tbl(i).Original_System_Reference :=
2364                     ri.Original_System_Reference;
2365                l_revised_item_tbl(i).transaction_type := 'CREATE';
2366 --11.5.10 chnages
2367            l_revised_item_tbl(i).Transfer_Or_Copy          := ri.Transfer_Or_Copy;
2368            l_revised_item_tbl(i).Transfer_OR_Copy_Item     := ri.Transfer_OR_Copy_Item ;
2369            l_revised_item_tbl(i).Transfer_OR_Copy_Bill     := ri.Transfer_OR_Copy_Bill  ;
2370            l_revised_item_tbl(i).Transfer_OR_Copy_Routing  := ri.Transfer_OR_Copy_Routing;
2371            l_revised_item_tbl(i).Copy_To_Item              := ri.Copy_To_Item;
2372            l_revised_item_tbl(i).Copy_To_Item_Desc         := ri.Copy_To_Item_Desc;
2373 
2374 --11.5.10 changes
2375 
2376 
2377 
2378 
2379 
2380 
2381                i := i + 1;
2382 
2383             ELSE
2384 
2385                FND_FILE.PUT_LINE(FND_FILE.LOG,'Invalid Use_Up_Item_id = '||
2386                                ri.use_up_item_id||' for Org '||l_org_code);
2387 
2388             END IF;
2389 
2390          ELSE
2391 
2392             FND_FILE.PUT_LINE(FND_FILE.LOG,'Invalid revised_item_id = '||
2393                              ri.revised_item_id||' for Org '||l_org_code);
2394 
2395          END IF;
2396 
2397         END LOOP;                                          /* End Loop 4 */
2398 
2399     -- Fetch revised components for disable and implemented ECO
2400      i := 1;
2401 
2402      For rcd IN c_rev_comps_disable
2403      LOOP
2404 
2405           FND_FILE.PUT_LINE(FND_FILE.LOG,'Processing Revised Components For Implemented Ecos having ACD type as Disable for Components...');
2406 
2407       BEGIN
2408             l_item_exits_in_org_flag := 1;
2409             SELECT msi.concatenated_segments,eri.new_item_revision
2410             INTO   l_revised_item_name,l_new_item_revision
2411             FROM   mtl_system_items_b_kfv msi,
2412                    eng_revised_items eri
2413             WHERE  eri.revised_item_sequence_id = rcd.revised_item_sequence_id
2414             AND    eri.revised_item_id = msi.inventory_item_id
2415             AND    msi.organization_id = l_org_id;
2416 
2417           EXCEPTION WHEN NO_DATA_FOUND THEN
2418             l_item_exits_in_org_flag := 0;
2419             l_check_invalid_objects := 0;
2420       END;
2421       IF (l_item_exits_in_org_flag = 1) THEN
2422 
2423              BEGIN
2424                SELECT concatenated_segments
2425                INTO   l_component_item_name
2426                FROM   mtl_system_items_b_kfv
2427                WHERE  inventory_item_id = rcd.component_item_id
2428                AND    organization_id = l_org_id;
2429              EXCEPTION WHEN NO_DATA_FOUND THEN
2430                l_item_exits_in_org_flag := 0;
2431                l_check_invalid_objects := 0;
2432              END;
2433 
2434              IF (l_item_exits_in_org_flag = 1) THEN
2435 
2436                 IF (rcd.supply_locator_id is NOT NULL) THEN
2437 
2438                   SELECT CONCATENATED_SEGMENTS
2439                   INTO   l_location_name
2440                   FROM   mtl_item_locations_kfv
2441                   WHERE inventory_location_id = rcd.supply_locator_id;
2442                 ELSE
2443                   l_location_name := NULL;
2444                 END IF;
2445         BEGIN
2446                St_Number := 10;
2447                    select assembly_item_id
2448                    into   item_id
2449                    from   bom_bill_of_materials
2450                    where  bill_sequence_id = rcd.bill_sequence_id;
2451 
2452                    St_Number := 20;
2453                    select bill_sequence_id
2454                    into   bill_id
2455                    from   bom_bill_of_materials
2456                    where  assembly_item_id =  item_id
2457                    and    organization_id = l_org_id
2458                    and    ALTERNATE_BOM_DESIGNATOR IS NULL;
2459 
2460                    St_Number := 30;
2461                    select operation_seq_num,trunc(effectivity_date)
2462                    into   old_operation_seq_num,l_old_effectivity_date
2463                    from   bom_inventory_components
2464                    where  COMPONENT_SEQUENCE_ID = rcd.OLD_COMPONENT_SEQUENCE_ID;
2465 
2466                    St_Number := 40;
2467                    select max(component_sequence_id)
2468                    into   component_seq_id
2469                    from   bom_inventory_components
2470                    where ((trunc(effectivity_date) = l_old_effectivity_date) OR
2471                           (rcd.effectivity_date between
2472                             trunc(effectivity_date) and
2473                             NVL(disable_date, rcd.effectivity_date + 1)))
2474            -- Bug 3041105 : Commenting code to pick unimplemented components
2475            -- and    implementation_date IS NOT NULL
2476                    and    component_item_id = rcd.COMPONENT_ITEM_ID
2477                    and    bill_sequence_id = bill_id
2478                    and    operation_seq_num = old_operation_seq_num;
2479 
2480                    St_Number := 50;
2481                    select effectivity_date
2482                    into old_effectivity_date
2483                    from bom_inventory_components
2484                    where component_sequence_id = component_seq_id;
2485 
2486                  EXCEPTION
2487                         WHEN NO_DATA_FOUND THEN
2488                                 old_operation_seq_num := NULL;
2489                                 old_effectivity_date := NULL;
2490                                 FND_FILE.PUT_LINE(FND_FILE.LOG,'No_Data_found error in Disable After implementation for sql statement Number :' || to_char(St_Number));
2491                         WHEN OTHERS THEN
2492                                 FND_FILE.PUT_LINE(FND_FILE.LOG,'Sql error in Disable after implementation statement number: '|| to_char(St_Number) || ':' || TO_CHAR(SQLCODE) || ' ' || SUBSTR(SQLERRM, 1, 100));
2493                  END;
2494                 l_rev_component_tbl(i).eco_name := rcd.change_notice;
2495                 l_rev_component_tbl(i).organization_code:= l_org_code;
2496                 l_rev_component_tbl(i).revised_item_name :=
2497                     l_revised_item_name;
2498                 l_rev_component_tbl(i).new_revised_item_revision :=
2499                 l_new_item_revision;
2500                 l_rev_component_tbl(i).start_effective_date :=
2501                 rcd.effectivity_date;
2502         l_rev_component_tbl(i).new_effectivity_date := NULL;
2503         l_rev_component_tbl(i).COMMENTS := rcd.COMPONENT_REMARKS;
2504                 l_rev_component_tbl(i).disable_date := rcd.disable_date;
2505                 l_rev_component_tbl(i).operation_sequence_number :=
2506                 rcd.operation_sequence_num;
2507                 l_rev_component_tbl(i).component_item_name :=
2508                 l_component_item_name;
2509                 l_rev_component_tbl(i).alternate_bom_code :=
2510                                     NULL;
2511                 l_rev_component_tbl(i).acd_type := rcd.acd_type;
2512                 l_rev_component_tbl(i).old_effectivity_date :=
2513                                               old_effectivity_date;
2514                 l_rev_component_tbl(i).old_operation_sequence_number :=
2515                                                 old_operation_seq_num;
2516                 l_rev_component_tbl(i).new_operation_sequence_number :=
2517                                                 NULL;
2518                 l_rev_component_tbl(i).item_sequence_number := rcd.item_num;
2519                 l_rev_component_tbl(i).quantity_per_assembly :=
2520                        rcd.component_quantity;
2521                 l_rev_component_tbl(i).planning_percent := rcd.planning_factor;
2522                 l_rev_component_tbl(i).projected_yield :=
2523                 rcd.component_yield_factor;
2524                 l_rev_component_tbl(i).include_in_cost_rollup :=
2525                                  rcd.include_in_cost_rollup;
2526                 l_rev_component_tbl(i).wip_supply_type :=
2527                  rcd.wip_supply_type;
2528                 l_rev_component_tbl(i).so_basis :=  rcd.so_basis;
2529                 l_rev_component_tbl(i).basis_type :=  rcd.basis_type;
2530                 l_rev_component_tbl(i).optional := rcd.optional;
2531                 l_rev_component_tbl(i).mutually_exclusive :=
2532                                       rcd.mutually_exclusive_options;
2533                 l_rev_component_tbl(i).check_atp := rcd.check_atp;
2534                 l_rev_component_tbl(i).shipping_allowed :=
2535                 rcd.shipping_allowed;
2536                 l_rev_component_tbl(i).required_to_ship :=
2537             rcd.required_to_ship;
2538                 l_rev_component_tbl(i).required_for_revenue :=
2539                         rcd.required_for_revenue;
2540                 l_rev_component_tbl(i).include_on_ship_docs :=
2541                     rcd.include_on_ship_docs;
2542                 l_rev_component_tbl(i).quantity_related :=
2543                 rcd.quantity_related;
2544                 l_rev_component_tbl(i).supply_subinventory :=
2545                                 rcd.supply_subinventory;
2546                 l_rev_component_tbl(i).location_name := l_location_name;
2547                 l_rev_component_tbl(i).minimum_allowed_quantity :=
2548                                 rcd.low_quantity;
2549                 l_rev_component_tbl(i).maximum_allowed_quantity :=
2550                 rcd.high_quantity;
2551                 l_rev_component_tbl(i).attribute_category  :=
2552                                 rcd.attribute_category;
2553                 l_rev_component_tbl(i).attribute1  := rcd.attribute1;
2554                 l_rev_component_tbl(i).attribute2  := rcd.attribute2;
2555                 l_rev_component_tbl(i).attribute3  := rcd.attribute3;
2556                 l_rev_component_tbl(i).attribute4  := rcd.attribute4;
2557                 l_rev_component_tbl(i).attribute5  := rcd.attribute5;
2558                 l_rev_component_tbl(i).attribute6  := rcd.attribute6;
2559                 l_rev_component_tbl(i).attribute7  := rcd.attribute7;
2560                 l_rev_component_tbl(i).attribute8  := rcd.attribute8;
2561                 l_rev_component_tbl(i).attribute9  := rcd.attribute9;
2562                 l_rev_component_tbl(i).attribute10  := rcd.attribute10;
2563                 l_rev_component_tbl(i).attribute11  := rcd.attribute11;
2564                 l_rev_component_tbl(i).attribute12  := rcd.attribute12;
2565                 l_rev_component_tbl(i).attribute13  := rcd.attribute13;
2566                 l_rev_component_tbl(i).attribute14  := rcd.attribute14;
2567                 l_rev_component_tbl(i).attribute15  := rcd.attribute15;
2568                 l_rev_component_tbl(i).from_end_item_unit_number :=
2569                                 rcd.from_end_item_unit_number;
2570                 l_rev_component_tbl(i).to_end_item_unit_number  :=
2571                                 rcd.to_end_item_unit_number;
2572                 l_rev_component_tbl(i).original_system_reference :=
2573                                 rcd.original_system_reference;
2574                 l_rev_component_tbl(i).new_from_end_item_unit_number := NULL;
2575                 l_rev_component_tbl(i).old_from_end_item_unit_number := NULL;
2576                 l_rev_component_tbl(i).return_status := NULL;
2577                 l_rev_component_tbl(i).transaction_type := 'CREATE';
2578 
2579                 i := i + 1;
2580 
2581                ELSE
2582 
2583                    FND_FILE.PUT_LINE(FND_FILE.LOG,'Invalid Component_Item_id = '|| rcd.component_item_id||' for Org '||l_org_code);
2584         END IF;
2585              ELSE
2586 
2587                FND_FILE.PUT_LINE(FND_FILE.LOG,'Invalid revised_item_seq_id = '||rcd.revised_item_sequence_id||' for Org '||l_org_code);
2588              END IF;
2589      END LOOP;
2590 
2591          -- Fetch revised components
2592 
2593          FOR rc IN c_rev_comps
2594          LOOP                                             /* Loop 5 */
2595 
2596           FND_FILE.PUT_LINE(FND_FILE.LOG,'Processing Revised Components ...');
2597 
2598           BEGIN
2599 
2600 	    l_item_exits_in_org_flag := 1;
2601 
2602 
2603             SELECT msi.concatenated_segments,eri.new_item_revision
2604             INTO   l_revised_item_name,l_new_item_revision
2605             FROM   mtl_system_items_b_kfv msi,
2606                    eng_revised_items eri
2607             WHERE  eri.revised_item_sequence_id = rc.revised_item_sequence_id
2608             AND    eri.revised_item_id = msi.inventory_item_id
2609             AND    msi.organization_id = l_org_id;
2610 
2611 
2612 	  EXCEPTION WHEN NO_DATA_FOUND THEN
2613             l_item_exits_in_org_flag := 0;
2614             l_check_invalid_objects := 0;
2615           END;
2616 
2617           IF (l_item_exits_in_org_flag = 1) THEN
2618 
2619              BEGIN
2620 
2621 	      /*  SELECT concatenated_segments   -- Commented for bug-5725081
2622                   INTO   l_component_item_name
2623                   FROM   mtl_system_items_b_kfv
2624                   WHERE  inventory_item_id = rc.component_item_id
2625                   AND    organization_id = l_org_id;
2626 	      */
2627 
2628 	      -- Code added for bug number 5725081 starts here
2629 
2630 	       v_component_quantity_to := 0 ;
2631 	       v_component_low_quantity := 0 ;
2632 	       v_component_high_quantity := 0 ;
2633 
2634 	       SELECT msit.concatenated_segments,
2635   	              DECODE(msif.primary_unit_of_measure,
2636                              msit.primary_unit_of_measure,
2637 	   	             rc.component_quantity,
2638   		             inv_convert.INV_UM_CONVERT(rc.component_item_id,
2639  		                                        NULL,
2640 		                                        rc.component_quantity,
2641 		                                        NULL,
2642                                                         NULL,
2643  		                                        msif.primary_unit_of_measure,
2644 		                                        msit.primary_unit_of_measure
2645 							)
2646  		             ),
2647   	              DECODE(msif.primary_unit_of_measure,
2648                              msit.primary_unit_of_measure,
2649 	   	             rc.low_quantity,
2650   		             DECODE(rc.low_quantity, NULL, NULL,
2651                                         inv_convert.INV_UM_CONVERT(
2652 	    					       rc.component_item_id,
2653  	   	                                        NULL,
2654 		                                        rc.low_quantity,
2655 		                                        NULL,
2656                                                         NULL,
2657  		                                        msif.primary_unit_of_measure,
2658 		                                        msit.primary_unit_of_measure
2659 							           )
2660                                     )
2661 			      ),
2662   	              DECODE(msif.primary_unit_of_measure,
2663                              msit.primary_unit_of_measure,
2664 	   	             rc.high_quantity,
2665   		             DECODE(rc.high_quantity, NULL, NULL,
2666 			                  inv_convert.INV_UM_CONVERT(
2667 					                rc.component_item_id,
2668  		                                        NULL,
2669 		                                        rc.high_quantity,
2670 		                                        NULL,
2671                                                         NULL,
2672  		                                        msif.primary_unit_of_measure,
2673 		                                        msit.primary_unit_of_measure
2674 							             )
2675                                     )
2676   			     )
2677                INTO l_component_item_name,
2678                     v_component_quantity_to,
2679                     v_component_low_quantity,
2680 	            v_component_high_quantity
2681                FROM mtl_system_items_b_kfv MSIF ,
2682                     mtl_system_items_b_kfv MSIT
2683               WHERE msif.inventory_item_id = msit.inventory_item_id
2684                 AND msif.inventory_item_id = rc.component_item_id
2685                 AND msit.organization_id = l_org_id
2686                 AND msif.organization_id = l_org_hierarchy_level_id ;
2687 
2688 	          -- Code added for bug 5725081 ends here
2689 	     EXCEPTION WHEN NO_DATA_FOUND THEN
2690                l_item_exits_in_org_flag := 0;
2691                l_check_invalid_objects := 0;
2692              END;
2693 
2694              IF (l_item_exits_in_org_flag = 1) THEN
2695 
2696                 IF (rc.supply_locator_id is NOT NULL) THEN
2697 
2698                   SELECT CONCATENATED_SEGMENTS
2699                   INTO   l_location_name
2700                   FROM   mtl_item_locations_kfv
2701                   WHERE inventory_location_id = rc.supply_locator_id;
2702                 ELSE
2703                   l_location_name := NULL;
2704                 END IF;
2705         IF (rc.acd_type in (2,3)) then
2706          BEGIN
2707            St_Number := 10;
2708                    select assembly_item_id
2709                    into   item_id
2710                    from   bom_bill_of_materials
2711                    where  bill_sequence_id = rc.bill_sequence_id;
2712 
2713            St_Number := 20;
2714                    select bill_sequence_id
2715                    into   bill_id
2716                    from   bom_bill_of_materials
2717                    where  assembly_item_id =  item_id
2718                    and    organization_id = l_org_id
2719                    and    ALTERNATE_BOM_DESIGNATOR IS NULL;
2720 
2721            St_Number := 30;
2722                    select operation_seq_num,trunc(effectivity_date)
2723                    into   old_operation_seq_num,l_old_effectivity_date
2724                    from   bom_inventory_components
2725                    where  COMPONENT_SEQUENCE_ID = rc.OLD_COMPONENT_SEQUENCE_ID;
2726 
2727            St_Number := 40;
2728                    select max(component_sequence_id)
2729                    into   component_seq_id
2730                    from   bom_inventory_components
2731            where ((trunc(effectivity_date) = l_old_effectivity_date) OR
2732                           (rc.effectivity_date between
2733                     trunc(effectivity_date) and
2734                             NVL(disable_date, rc.effectivity_date + 1))
2735                          )
2736                    -- Bug 3041105 : Commenting code to pick unimplemented components
2737                    -- and    implementation_date IS NOT NULL
2738                    and    component_item_id = rc.COMPONENT_ITEM_ID
2739                    and    bill_sequence_id = bill_id
2740                    and    operation_seq_num = old_operation_seq_num;
2741 
2742 
2743            St_Number := 50;
2744                    select effectivity_date
2745                    into old_effectivity_date
2746                    from bom_inventory_components
2747                    where component_sequence_id = component_seq_id;
2748 
2749          EXCEPTION
2750             WHEN NO_DATA_FOUND THEN
2751                 old_operation_seq_num := NULL;
2752                 old_effectivity_date := NULL;
2753                 FND_FILE.PUT_LINE(FND_FILE.LOG,'No_Data_found error for sql statement Number :' || to_char(St_Number));
2754             WHEN OTHERS THEN
2755                 FND_FILE.PUT_LINE(FND_FILE.LOG,'Sql error in statement number: '|| to_char(St_Number) || ':' || TO_CHAR(SQLCODE) || ' ' || SUBSTR(SQLERRM, 1, 100));
2756          END;
2757             ELSE
2758                         old_operation_seq_num := NULL;
2759                         old_effectivity_date := NULL;
2760             END IF;
2761 
2762                 l_rev_component_tbl(i).eco_name := rc.change_notice;
2763                 l_rev_component_tbl(i).organization_code:= l_org_code;
2764                 l_rev_component_tbl(i).revised_item_name :=
2765                     l_revised_item_name;
2766                 l_rev_component_tbl(i).new_revised_item_revision :=
2767                 l_new_item_revision;
2768                 l_rev_component_tbl(i).start_effective_date :=
2769                 rc.effectivity_date;
2770                 l_rev_component_tbl(i).new_effectivity_date := NULL;
2771                 l_rev_component_tbl(i).COMMENTS := rc.COMPONENT_REMARKS;
2772                 l_rev_component_tbl(i).disable_date := rc.disable_date;
2773                 l_rev_component_tbl(i).operation_sequence_number :=
2774                 rc.operation_seq_num;
2775                 l_rev_component_tbl(i).component_item_name :=
2776                 l_component_item_name;
2777                 l_rev_component_tbl(i).alternate_bom_code :=
2778                                     NULL;
2779                 l_rev_component_tbl(i).acd_type := rc.acd_type;
2780                 l_rev_component_tbl(i).old_effectivity_date :=
2781                                               old_effectivity_date;
2782                 l_rev_component_tbl(i).old_operation_sequence_number :=
2783                                                 old_operation_seq_num;
2784                 l_rev_component_tbl(i).new_operation_sequence_number :=
2785                                                 NULL;
2786                 l_rev_component_tbl(i).item_sequence_number := rc.item_num;
2787 /*                l_rev_component_tbl(i).quantity_per_assembly :=    -- Commented for bug 5725081
2788                        rc.component_quantity;*/
2789 		l_rev_component_tbl(i).quantity_per_assembly :=      -- Added for bug 5725081
2790 		                v_component_quantity_to;
2791 
2792                 l_rev_component_tbl(i).planning_percent := rc.planning_factor;
2793                 l_rev_component_tbl(i).projected_yield :=
2794                 rc.component_yield_factor;
2795                 l_rev_component_tbl(i).include_in_cost_rollup :=
2796                                  rc.include_in_cost_rollup;
2797                 l_rev_component_tbl(i).wip_supply_type :=
2798                  rc.wip_supply_type;
2799                 l_rev_component_tbl(i).so_basis :=  rc.so_basis;
2800                  l_rev_component_tbl(i).basis_type :=  rc.basis_type;
2801                 l_rev_component_tbl(i).optional := rc.optional;
2802                 l_rev_component_tbl(i).mutually_exclusive :=
2803                                       rc.mutually_exclusive_options;
2804                 l_rev_component_tbl(i).check_atp := rc.check_atp;
2805                 l_rev_component_tbl(i).shipping_allowed :=
2806                 rc.shipping_allowed;
2807                 l_rev_component_tbl(i).required_to_ship :=
2808             rc.required_to_ship;
2809                 l_rev_component_tbl(i).required_for_revenue :=
2810                         rc.required_for_revenue;
2811                 l_rev_component_tbl(i).include_on_ship_docs :=
2812                     rc.include_on_ship_docs;
2813                 l_rev_component_tbl(i).quantity_related :=
2814                 rc.quantity_related;
2815                 l_rev_component_tbl(i).supply_subinventory :=
2816                 rc.supply_subinventory;
2817                 l_rev_component_tbl(i).location_name := l_location_name;
2818              /*   l_rev_component_tbl(i).minimum_allowed_quantity :=   -- Commented for bug 5725081
2819                 rc.low_quantity;
2820                 l_rev_component_tbl(i).maximum_allowed_quantity :=
2821                 rc.high_quantity;*/
2822    	        l_rev_component_tbl(i).minimum_allowed_quantity :=   -- Added for bug-5725081
2823 				            v_component_low_quantity;
2824 
2825 		l_rev_component_tbl(i).maximum_allowed_quantity :=   -- Added for bug-5725081
2826    				            v_component_high_quantity;
2827 
2828                 l_rev_component_tbl(i).attribute_category  :=
2829                                             rc.attribute_category;
2830                 l_rev_component_tbl(i).attribute1  := rc.attribute1;
2831                 l_rev_component_tbl(i).attribute2  := rc.attribute2;
2832                 l_rev_component_tbl(i).attribute3  := rc.attribute3;
2833                 l_rev_component_tbl(i).attribute4  := rc.attribute4;
2834                 l_rev_component_tbl(i).attribute5  := rc.attribute5;
2835                 l_rev_component_tbl(i).attribute6  := rc.attribute6;
2836                 l_rev_component_tbl(i).attribute7  := rc.attribute7;
2837                 l_rev_component_tbl(i).attribute8  := rc.attribute8;
2838                 l_rev_component_tbl(i).attribute9  := rc.attribute9;
2839                 l_rev_component_tbl(i).attribute10  := rc.attribute10;
2840                 l_rev_component_tbl(i).attribute11  := rc.attribute11;
2841                 l_rev_component_tbl(i).attribute12  := rc.attribute12;
2842                 l_rev_component_tbl(i).attribute13  := rc.attribute13;
2843                 l_rev_component_tbl(i).attribute14  := rc.attribute14;
2844                 l_rev_component_tbl(i).attribute15  := rc.attribute15;
2845         l_rev_component_tbl(i).from_end_item_unit_number :=
2846                 rc.from_end_item_unit_number;
2847         l_rev_component_tbl(i).to_end_item_unit_number  :=
2848                 rc.to_end_item_unit_number;
2849         l_rev_component_tbl(i).original_system_reference :=
2850                 rc.original_system_reference;
2851         l_rev_component_tbl(i).new_from_end_item_unit_number := NULL;
2852         l_rev_component_tbl(i).old_from_end_item_unit_number := NULL;
2853                 l_rev_component_tbl(i).return_status := NULL;
2854                 l_rev_component_tbl(i).transaction_type := 'CREATE';
2855 
2856                 i := i + 1;
2857 
2858                ELSE
2859 
2860                    FND_FILE.PUT_LINE(FND_FILE.LOG,'Invalid Component_Item_id = '|| rc.component_item_id||' for Org '||l_org_code);
2861 
2862                END IF;
2863 
2864              ELSE
2865 
2866                FND_FILE.PUT_LINE(FND_FILE.LOG,'Invalid revised_item_seq_id = '||
2867                                 rc.revised_item_sequence_id||' for Org '||l_org_code);
2868              END IF;
2869 
2870          END LOOP;                                      /* End Loop 5 */
2871 
2872          -- Fetch substitute component records
2873 
2874          i := 1;
2875 
2876          FOR sc IN c_sub_comps
2877          LOOP                                          /* Loop 6 */
2878 
2879          FND_FILE.PUT_LINE(FND_FILE.LOG,'Processing Substitute Components ...');
2880 
2881             BEGIN
2882 
2883            l_item_exits_in_org_flag := 1;
2884 
2885                SELECT msi.concatenated_segments,eri.new_item_revision
2886                INTO   l_revised_item_name1,l_new_item_revision
2887                FROM   mtl_system_items_b_kfv msi,
2888                       eng_revised_items eri,
2889                       bom_inventory_components bic
2890                WHERE  bic.component_sequence_id = sc.component_sequence_id
2891                AND  eri.revised_item_sequence_id = bic.revised_item_sequence_id
2892                AND    eri.revised_item_id = msi.inventory_item_id
2893                AND    msi.organization_id = l_org_id;
2894             EXCEPTION WHEN NO_DATA_FOUND THEN
2895                l_item_exits_in_org_flag := 0;
2896                l_check_invalid_objects := 0;
2897             END;
2898 
2899             IF (l_item_exits_in_org_flag = 1) THEN
2900 
2901                BEGIN
2902                   SELECT concatenated_segments,bic.effectivity_date,
2903                          bic.operation_seq_num
2904                   INTO   l_component_item_name1,l_effectivity_date,
2905                          l_operation_seq_num
2906                   FROM   mtl_system_items_b_kfv msi,
2907                          bom_inventory_components bic
2908                   WHERE  bic.component_sequence_id = sc.component_sequence_id
2909                   AND    msi.inventory_item_id = bic.component_item_id
2910                   AND    msi.organization_id = l_org_id;
2911                EXCEPTION WHEN NO_DATA_FOUND THEN
2912                   l_item_exits_in_org_flag := 0;
2913                   l_check_invalid_objects := 0;
2914                END;
2915 
2916                IF (l_item_exits_in_org_flag = 1) THEN
2917 
2918                   BEGIN
2919 
2920   		    v_substitute_item_quantity := 0;   -- Added for bug-5725081
2921 
2922 		   /*  SELECT concatenated_segments   -- Commented for bug-5725081
2923                      INTO   l_substitute_component_name
2924                      FROM   mtl_system_items_b_kfv
2925                      WHERE  inventory_item_id = sc.substitute_component_id
2926                      AND    organization_id = l_org_id;
2927              	     */
2928 
2929 		     SELECT msit.concatenated_segments,  -- Added for bug-5725081
2930                          DECODE(msif.primary_unit_of_measure,
2931                                 msit.primary_unit_of_measure,
2932                                 sc.substitute_item_quantity ,
2933   		                inv_convert.INV_UM_CONVERT(sc.substitute_component_id,
2934  		                                           NULL,
2935 		                                           sc.substitute_item_quantity,
2936 		                                           NULL,
2937                                                            NULL,
2938    		                                           msif.primary_unit_of_measure,
2939 		                                           msit.primary_unit_of_measure)
2940  		  				           )
2941   	              INTO  l_substitute_component_name,
2942        	                    v_substitute_item_quantity
2943                       FROM  mtl_system_items_b_kfv MSIF,
2944                             mtl_system_items_b_kfv MSIT
2945                      WHERE  msif.inventory_item_id = msit.inventory_item_id
2946                        AND  msif.inventory_item_id = sc.substitute_component_id
2947                        AND  msit.organization_id   = l_org_id
2948                        AND  msif.organization_id   = l_org_hierarchy_level_id;
2949 
2950 
2951                   EXCEPTION WHEN NO_DATA_FOUND THEN
2952                      l_item_exits_in_org_flag := 0;
2953                      l_check_invalid_objects := 0;
2954                   END;
2955 
2956                   IF (l_item_exits_in_org_flag = 1) THEN
2957 
2958                      l_sub_component_tbl(i).eco_name := sc.change_notice;
2959                      l_sub_component_tbl(i).organization_code:= l_org_code;
2960                      l_sub_component_tbl(i).revised_item_name :=
2961                         l_revised_item_name1;
2962                      l_sub_component_tbl(i).start_effective_date :=
2963                         l_effectivity_date;
2964                      l_sub_component_tbl(i).new_revised_item_revision :=
2965                         l_new_item_revision;
2966                      l_sub_component_tbl(i).component_item_name :=
2967                         l_component_item_name1;
2968                      l_sub_component_tbl(i).alternate_bom_code :=
2969                                                          NULL;
2970                      l_sub_component_tbl(i).substitute_component_name :=
2971                                                 l_substitute_component_name;
2972                      l_sub_component_tbl(i).acd_type := sc.acd_type;
2973                      l_sub_component_tbl(i).operation_sequence_number :=
2974                                                         l_operation_seq_num;
2975                  /*    l_sub_component_tbl(i).substitute_item_quantity :=
2976                                              sc.substitute_item_quantity;*/
2977 	            l_sub_component_tbl(i).substitute_item_quantity :=      -- Added for bug#5725081
2978                                              v_substitute_item_quantity;
2979                      l_sub_component_tbl(i).attribute_category  :=
2980                          sc.attribute_category;
2981                      l_sub_component_tbl(i).attribute1  := sc.attribute1;
2982                      l_sub_component_tbl(i).attribute2  := sc.attribute2;
2983                      l_sub_component_tbl(i).attribute3  := sc.attribute3;
2984                      l_sub_component_tbl(i).attribute4  := sc.attribute4;
2985                      l_sub_component_tbl(i).attribute5  := sc.attribute5;
2986                      l_sub_component_tbl(i).attribute6  := sc.attribute6;
2987                      l_sub_component_tbl(i).attribute7  := sc.attribute7;
2988                      l_sub_component_tbl(i).attribute8  := sc.attribute8;
2989                      l_sub_component_tbl(i).attribute9  := sc.attribute9;
2990                      l_sub_component_tbl(i).attribute10  := sc.attribute10;
2991                      l_sub_component_tbl(i).attribute11  := sc.attribute11;
2992                      l_sub_component_tbl(i).attribute12  := sc.attribute12;
2993                      l_sub_component_tbl(i).attribute13  := sc.attribute13;
2994                      l_sub_component_tbl(i).attribute14  := sc.attribute14;
2995                      l_sub_component_tbl(i).attribute15  := sc.attribute15;
2996                      l_sub_component_tbl(i).from_end_item_unit_number  := NULL;
2997              l_sub_component_tbl(i).Original_System_Reference :=
2998                     sc.Original_System_Reference;
2999                      l_sub_component_tbl(i).return_status := NULL;
3000                      l_sub_component_tbl(i).transaction_type := 'CREATE';
3001 
3002                      i := i + 1;
3003 
3004                   ELSE
3005 
3006                      FND_FILE.PUT_LINE(FND_FILE.LOG,'Invalid Substitute_Component_Id = '|| sc.substitute_component_id||' for Org '||l_org_code);
3007 
3008                   END IF;
3009 
3010                ELSE
3011 
3012                   FND_FILE.PUT_LINE(FND_FILE.LOG,'Invalid Component_seq_id = '|| sc.component_sequence_id||' for Org '||l_org_code);
3013 
3014                END IF;
3015 
3016             ELSE
3017 
3018                FND_FILE.PUT_LINE(FND_FILE.LOG,'Invalid revised_item_id for Component_Seq_Id = '|| sc.component_sequence_id||' for Org '||l_org_code);
3019 
3020             END IF;
3021 
3022          END LOOP;                                      /* End Loop 6 */
3023 
3024          -- Fetch reference designators
3025 
3026          i := 1;
3027 
3028          FOR rd IN c_ref_desgs
3029          LOOP                                          /* Loop 7 */
3030 
3031             FND_FILE.PUT_LINE(FND_FILE.LOG,'Processing Reference Designators ...');
3032             BEGIN
3033 
3034                l_item_exits_in_org_flag := 1;
3035 
3036                SELECT msi.concatenated_segments,eri.new_item_revision,
3037               bic.effectivity_date,bic.operation_seq_num
3038                INTO   l_revised_item_name2,l_new_item_revision,
3039               l_effectivity_date,l_operation_seq_num
3040                FROM   mtl_system_items_b_kfv msi,
3041                       eng_revised_items eri,
3042                       bom_inventory_components bic
3043                WHERE  bic.component_sequence_id = rd.component_sequence_id
3044                AND  eri.revised_item_sequence_id = bic.revised_item_sequence_id
3045                AND    eri.revised_item_id = msi.inventory_item_id
3046                AND    msi.organization_id = l_org_id;
3047             EXCEPTION
3048                WHEN NO_DATA_FOUND THEN
3049                   l_item_exits_in_org_flag := 0;
3050                   l_check_invalid_objects := 0;
3051             END;
3052 
3053             IF (l_item_exits_in_org_flag = 1) THEN
3054 
3055                BEGIN
3056                   SELECT concatenated_segments
3057                   INTO   l_component_item_name2
3058                   FROM   mtl_system_items_b_kfv msi,
3059                          bom_inventory_components bic
3060                   WHERE  bic.component_sequence_id = rd.component_sequence_id
3061                   AND    msi.inventory_item_id = bic.component_item_id
3062                   AND    msi.organization_id = l_org_id;
3063                EXCEPTION
3064                  WHEN NO_DATA_FOUND THEN
3065                      l_item_exits_in_org_flag := 0;
3066                      l_check_invalid_objects := 0;
3067                END;
3068 
3069                IF (l_item_exits_in_org_flag = 1) THEN
3070 
3071                   l_ref_designator_tbl(i).eco_name := rd.change_notice;
3072                   l_ref_designator_tbl(i).organization_code := l_org_code;
3073                   l_ref_designator_tbl(i).revised_item_name :=
3074                     l_revised_item_name2;
3075                   l_ref_designator_tbl(i).start_effective_date :=
3076                     l_effectivity_date;
3077                   l_ref_designator_tbl(i).new_revised_item_revision :=
3078                     l_new_item_revision;
3079                   l_ref_designator_tbl(i).operation_sequence_number :=
3080                                     l_operation_seq_num;
3081                   l_ref_designator_tbl(i).component_item_name :=
3082                     l_component_item_name2;
3083                   l_ref_designator_tbl(i).alternate_bom_code :=
3084                                         NULL;
3085                   l_ref_designator_tbl(i).reference_designator_name :=
3086                                         rd.component_reference_designator;
3087                   l_ref_designator_tbl(i).acd_type := rd.acd_type;
3088                   l_ref_designator_tbl(i).ref_designator_comment :=
3089                                         rd.ref_designator_comment;
3090                   l_ref_designator_tbl(i).attribute_category  :=
3091                     rd.attribute_category;
3092                   l_ref_designator_tbl(i).attribute1  := rd.attribute1;
3093                   l_ref_designator_tbl(i).attribute2  := rd.attribute2;
3094                   l_ref_designator_tbl(i).attribute3  := rd.attribute3;
3095                   l_ref_designator_tbl(i).attribute4  := rd.attribute4;
3096                   l_ref_designator_tbl(i).attribute5  := rd.attribute5;
3097                   l_ref_designator_tbl(i).attribute6  := rd.attribute6;
3098                   l_ref_designator_tbl(i).attribute7  := rd.attribute7;
3099                   l_ref_designator_tbl(i).attribute8  := rd.attribute8;
3100                   l_ref_designator_tbl(i).attribute9  := rd.attribute9;
3101                   l_ref_designator_tbl(i).attribute10  := rd.attribute10;
3102                   l_ref_designator_tbl(i).attribute11  := rd.attribute11;
3103                   l_ref_designator_tbl(i).attribute12  := rd.attribute12;
3104                   l_ref_designator_tbl(i).attribute13  := rd.attribute13;
3105                   l_ref_designator_tbl(i).attribute14  := rd.attribute14;
3106                   l_ref_designator_tbl(i).attribute15  := rd.attribute15;
3107               l_ref_designator_tbl(i).Original_System_Reference :=
3108                 rd.Original_System_Reference;
3109                   l_ref_designator_tbl(i).new_reference_designator := NULL;
3110                   l_ref_designator_tbl(i).from_end_item_unit_number := NULL;
3111                   l_ref_designator_tbl(i).return_status := NULL;
3112                   l_ref_designator_tbl(i).transaction_type := 'CREATE';
3113 
3114                   i:= i + 1;
3115 
3116                ELSE
3117 
3118                   FND_FILE.PUT_LINE(FND_FILE.LOG,'Invalid Component_seq_id = '||rd.component_sequence_id||' for Org '||l_org_code);
3119 
3120                END IF;
3121 
3122             ELSE
3123 
3124                FND_FILE.PUT_LINE(FND_FILE.LOG, 'Invalid revised_item_id for Component_Seq_Id = '|| rd.component_sequence_id||' for Org '||l_org_code);
3125 
3126             END IF;
3127          END LOOP;                                        /* End Loop 7 */
3128 
3129        IF l_check_invalid_objects = 1 THEN
3130          FND_FILE.PUT_LINE(FND_FILE.LOG,'');
3131 
3132          Eng_Globals.G_WHO_REC.org_id := l_org_id;
3133          Eng_Globals.G_WHO_REC.user_id := FND_PROFILE.value('USER_ID');
3134          Eng_Globals.G_WHO_REC.login_id :=  FND_PROFILE.value('LOGIN_ID');
3135          Eng_Globals.G_WHO_REC.prog_appid := FND_PROFILE.value('RESP_APPL_ID');
3136          Eng_Globals.G_WHO_REC.prog_id := NULL;
3137          Eng_Globals.G_WHO_REC.req_id := NULL;
3138 
3139          fnd_global.apps_initialize
3140          (user_id => Eng_Globals.G_WHO_REC.user_id,
3141           resp_id => FND_PROFILE.value('RESP_ID'),
3142           resp_appl_id =>  Eng_Globals.G_WHO_REC.prog_appid
3143          );
3144 
3145       /* Initializing the Error Handler */
3146 
3147       Error_Handler.Initialize;
3148 
3149           FND_FILE.PUT_LINE(FND_FILE.LOG,'Calling ECO Business Objects');
3150           ENG_GLOBALS.G_ENG_LAUNCH_IMPORT := 2 ;--Indicates call is from propagation
3151           Eng_Eco_Pub.Process_Eco
3152          (
3153            p_api_version_number => 1.0
3154           ,p_init_msg_list => FALSE
3155           ,x_return_status => l_return_status
3156           ,x_msg_count => l_msg_count
3157           ,p_bo_identifier => 'ECO'
3158           ,p_ECO_rec => l_eco_rec
3159           ,p_eco_revision_tbl => l_eco_revision_tbl
3160           ,p_change_line_tbl => l_change_lines_tbl
3161           ,p_revised_item_tbl => l_revised_item_tbl
3162           ,p_rev_component_tbl => l_rev_component_tbl
3163           ,p_sub_component_tbl => l_sub_component_tbl
3164           ,p_ref_designator_tbl => l_ref_designator_tbl
3165           ,p_rev_operation_tbl => l_rev_operation_tbl
3166           ,p_rev_op_resource_tbl => l_rev_op_resource_tbl
3167           ,p_rev_sub_resource_tbl => l_rev_sub_resource_tbl
3168           ,x_ECO_rec => l_eco_rec
3169           ,x_eco_revision_tbl => l_eco_revision_tbl
3170           ,x_change_line_tbl => l_change_lines_tbl
3171           ,x_revised_item_tbl => l_revised_item_tbl
3172           ,x_rev_component_tbl => l_rev_component_tbl
3173           ,x_sub_component_tbl => l_sub_component_tbl
3174           ,x_ref_designator_tbl => l_ref_designator_tbl
3175           ,x_rev_operation_tbl => l_rev_operation_tbl
3176           ,x_rev_op_resource_tbl => l_rev_op_resource_tbl
3177           ,x_rev_sub_resource_tbl => l_rev_sub_resource_tbl
3178           ,p_debug => 'N'
3179           ,p_output_dir => '/sqlcom/log/dom1151'
3180           ,p_debug_filename => 'ECO_BO_debug.log'
3181          );
3182          ENG_GLOBALS.G_ENG_LAUNCH_IMPORT :=0; --resetting values
3183          FND_FILE.PUT_LINE(FND_FILE.LOG,'ECO Business Object Processing Done');
3184          FND_FILE.PUT_LINE(FND_FILE.LOG,'');
3185          --
3186          -- On return from the PUB API
3187          -- Perform all the error handler operations to verify that the
3188          -- error or warning are displayed and all the error table interface
3189          -- function provided to the user work corrently;
3190          --
3191 
3192          /*if (l_return_status = 'S') THEN
3193            propagate_eco_lines
3194            (
3195              p_ECO_rec => l_eco_rec,
3196              p_source_org_id => l_org_hierarchy_level_id,
3197              p_dest_org_id => l_org_id,
3198              x_return_status => l_return_status
3199            );
3200          end if;*/
3201 
3202          if (l_return_status = 'S') THEN
3203            COMMIT;
3204          else
3205            ROLLBACK;
3206          Error_Handler.Get_Message_List( x_message_list  => l_error_table);
3207      i:=0;
3208          FOR i IN 1..l_error_table.COUNT
3209          LOOP
3210           FND_FILE.PUT_LINE(FND_FILE.LOG,'Entity Id: '||l_error_table(i).entity_id);
3211            FND_FILE.PUT_LINE(FND_FILE.LOG,'Index: '||l_error_table(i).entity_index);
3212            FND_FILE.PUT_LINE(FND_FILE.LOG,'Mesg: '||l_error_table(i).message_text);
3213          END LOOP;
3214 
3215         end if;
3216 
3217        ELSE
3218 
3219           FND_FILE.PUT_LINE(FND_FILE.LOG,'This ECO '||p_change_notice|| ' cannot be processed as there are invalid Items as listed above . Please correct these Items and re-run the propagate ECO');
3220 
3221         l_check_invalid_objects := 1;
3222 
3223        END IF;
3224 
3225       END LOOP;                                           /* End Loop 2 */
3226 
3227     END IF;                                               /* ECO Chack */
3228    END IF;     /*End of  IF l_org_code IS NOT NULL Organization Check */ -- Bug 4546616
3229   END LOOP;                                              /* End Loop 1 */
3230 
3231 END PROPAGATE_ECO_ERP;
3232 
3233 PROCEDURE Initialize_Business_Object (
3234     p_debug IN VARCHAR2
3235   , p_debug_filename IN VARCHAR2
3236   , p_output_dir IN VARCHAR2
3237   , p_bo_identifier IN VARCHAR2
3238   , p_organization_id IN NUMBER
3239   , x_return_status IN OUT NOCOPY VARCHAR2
3240 )
3241 IS
3242 l_Mesg_Token_Tbl        Error_Handler.Mesg_Token_Tbl_Type;
3243 l_other_message         VARCHAR2(50);
3244 l_Token_Tbl             Error_Handler.Token_Tbl_Type;
3245 l_err_text              VARCHAR2(2000);
3246 l_return_status         VARCHAR2(1);
3247 
3248 BEGIN
3249     IF p_debug = 'Y'
3250     THEN
3251         BOM_Globals.Set_Debug(p_debug);
3252         BOM_Rtg_Globals.Set_Debug(p_debug) ; -- Added by MK on 11/08/00
3253 
3254         Error_Handler.Open_Debug_Session
3255         (  p_debug_filename     => p_debug_filename
3256          , p_output_dir         => p_output_dir
3257          , x_return_status      => l_return_status
3258          , p_mesg_token_tbl     => l_mesg_token_tbl
3259          , x_mesg_token_tbl     => l_mesg_token_tbl
3260          );
3261 
3262         IF l_return_status <> FND_API.G_RET_STS_SUCCESS
3263         THEN
3264                 BOM_Globals.Set_Debug('N');
3265                 BOM_Rtg_Globals.Set_Debug('N'); -- Added by MK on 11/08/00
3266         END IF;
3267     END IF;
3268     --
3269     -- Set Business Object Idenfier in the System Information record.
3270     --
3271     Eng_Globals.Set_Bo_Identifier(p_bo_identifier  => p_bo_identifier);
3272     Eng_Globals.Set_Org_Id( p_org_id    => p_organization_id);
3273     -- Load environment information into the SYSTEM_INFORMATION record
3274     -- (USER_ID, LOGIN_ID, PROG_APPID, PROG_ID)
3275 
3276     l_return_status := FND_API.G_RET_STS_SUCCESS;
3277     ENG_GLOBALS.Init_System_Info_Rec(
3278         x_mesg_token_tbl => l_mesg_token_tbl
3279       , x_return_status  => l_return_status
3280      );
3281 
3282     -- Initialize System_Information Unit_Effectivity flag
3283     IF PJM_UNIT_EFF.Enabled = 'Y'
3284     THEN
3285         BOM_Globals.Set_Unit_Effectivity (TRUE);
3286         ENG_Globals.Set_Unit_Effectivity (TRUE);
3287     ELSE
3288         BOM_Globals.Set_Unit_Effectivity (FALSE);
3289         ENG_Globals.Set_Unit_Effectivity (FALSE);
3290     END IF;
3291     x_return_status := l_return_status;
3292     IF l_return_status <> FND_API.G_RET_STS_SUCCESS
3293     THEN
3294         RAISE EXC_ERR_PVT_API_MAIN;
3295     END IF;
3296 END Initialize_Business_Object;
3297 
3298 PROCEDURE Reset_Business_Object IS
3299 BEGIN
3300     -- Reset system_information business object flags
3301     ENG_GLOBALS.Set_ECO_Impl( p_eco_impl        => NULL);
3302     ENG_GLOBALS.Set_ECO_Cancl( p_eco_cancl      => NULL);
3303     ENG_GLOBALS.Set_Wkfl_Process( p_wkfl_process=> NULL);
3304     ENG_GLOBALS.Set_ECO_Access( p_eco_access    => NULL);
3305     ENG_GLOBALS.Set_STD_Item_Access( p_std_item_access => NULL);
3306     ENG_GLOBALS.Set_MDL_Item_Access( p_mdl_item_access => NULL);
3307     ENG_GLOBALS.Set_PLN_Item_Access( p_pln_item_access => NULL);
3308     ENG_GLOBALS.Set_OC_Item_Access( p_oc_item_access   => NULL);
3309     Eng_Globals.Set_Org_Id( p_org_id        => NULL);
3310     Eng_Globals.Set_Eco_Name( p_eco_name    => NULL);
3311 END Reset_Business_Object;
3312 
3313 PROCEDURE Propagate_Revised_Component (
3314     p_component_sequence_id     IN NUMBER
3315   , p_revised_item_sequence_id  IN NUMBER
3316   , p_change_id                 IN NUMBER
3317   , p_revised_item_rec          IN Eng_Eco_Pub.Revised_Item_Rec_Type
3318   , p_revised_item_unexp_rec    IN Eng_Eco_Pub.Rev_Item_Unexposed_Rec_Type
3319   , p_local_organization_id     IN NUMBER
3320   , x_Return_Status             OUT NOCOPY VARCHAR2
3321 ) IS
3322 
3323     l_rev_component_count       NUMBER := 1;
3324     l_sub_component_count       NUMBER := 1;
3325     l_ref_designator_count      NUMBER := 1;
3326 
3327     l_component_item_name       mtl_system_items_vl.concatenated_segments%type;
3328     l_location_name             mtl_item_locations_kfv.concatenated_segments%type;
3329     l_substitute_component_name mtl_system_items_vl.concatenated_segments%type;
3330     l_revised_item_name         mtl_system_items_vl.concatenated_segments%type;
3331     l_new_item_revision         VARCHAR2(3);
3332     l_effectivity_date          DATE;
3333     st_number                   NUMBER;
3334     item_id                     NUMBER;
3335     bill_id                     NUMBER;
3336     old_operation_seq_num       NUMBER;
3337     old_effectivity_date        DATE;
3338     l_old_effectivity_date      DATE;
3339     component_seq_id            NUMBER;
3340     l_item_exits_in_org_flag    NUMBER;
3341     l_has_invalid_objects       NUMBER := G_VAL_FALSE;
3342     l_entity_action_status      NUMBER;
3343     l_comp_exists_in_org        NUMBER;
3344 
3345     L_MSG_COUNT                 NUMBER;
3346     l_Mesg_token_Tbl            Error_Handler.Mesg_Token_Tbl_Type;
3347     l_bo_Mesg_Token_Tbl         Error_Handler.Mesg_Token_Tbl_Type;
3348     l_return_status             VARCHAR2(1);
3349     l_Token_Tbl                 Error_Handler.Token_Tbl_Type;
3350     l_item_error_table          INV_ITEM_GRP.Error_Tbl_Type;
3351     l_message_log_text          VARCHAR2(4000);
3352     l_temp_mesg                 VARCHAR2(4000);
3353 
3354     l_rev_component_tbl         Bom_Bo_Pub.Rev_Component_Tbl_Type;
3355     l_sub_component_tbl         Bom_Bo_Pub.Sub_Component_Tbl_Type;
3356     l_ref_designator_tbl        Bom_Bo_Pub.Ref_Designator_Tbl_Type;
3357     l_rev_comp_unexp_rec        BOM_BO_PUB.Rev_Comp_Unexposed_Rec_Type;
3358 
3359     CURSOR c_component_details IS
3360     SELECT component_item_id, supply_locator_id, bill_sequence_id, old_component_sequence_id
3361          , effectivity_date , attribute_category, ACD_TYPE, change_notice, disable_date
3362          , component_remarks, operation_seq_num, attribute1, attribute2, attribute3
3363          , attribute4, attribute5, attribute6, attribute7, attribute8, attribute9, attribute10
3364          , attribute11, attribute12, attribute13, attribute14, attribute15, item_num
3365          , component_quantity, planning_factor, component_yield_factor, include_in_cost_rollup
3366          , wip_supply_type, so_basis, basis_type, optional, mutually_exclusive_options
3367          , check_atp, shipping_allowed, required_to_ship, required_for_revenue, include_on_ship_docs
3368          , quantity_related, supply_subinventory, low_quantity, high_quantity, from_end_item_unit_number
3369          , TO_END_ITEM_UNIT_NUMBER, ORIGINAL_SYSTEM_REFERENCE
3370       FROM bom_components_b
3371     WHERE component_sequence_id = p_component_sequence_id
3372     UNION ALL
3373     SELECT  component_item_id, supply_locator_id, bill_sequence_id, old_component_sequence_id
3374          , effectivity_date , attribute_category, ACD_TYPE, change_notice, disable_date
3375          , component_remarks, OPERATION_SEQUENCE_NUM, attribute1, attribute2, attribute3
3376          , attribute4, attribute5, attribute6, attribute7, attribute8, attribute9, attribute10
3377          , attribute11, attribute12, attribute13, attribute14, attribute15, item_num
3378          , component_quantity, planning_factor, component_yield_factor, include_in_cost_rollup
3379          , wip_supply_type, so_basis, basis_type, optional, mutually_exclusive_options
3380          , check_atp, shipping_allowed, required_to_ship, required_for_revenue, include_on_ship_docs
3381          , quantity_related, supply_subinventory, low_quantity, high_quantity, from_end_item_unit_number
3382          , TO_END_ITEM_UNIT_NUMBER, ORIGINAL_SYSTEM_REFERENCE FROM eng_revised_components
3383      WHERE component_sequence_id = p_component_sequence_id
3384        AND acd_type = 3;
3385 
3386     -- Cursor to Pick all substitute Component Items for the Top Organization  for
3387     -- the given Change Notice
3388     CURSOR c_plm_sub_comps IS
3389     SELECT *
3390     FROM   bom_substitute_components
3391     WHERE  change_notice = p_revised_item_rec.eco_name
3392     AND    component_sequence_id = p_component_sequence_id;
3393 
3394     -- Cursor to Pick all reference designators for the Top Organization  for the
3395     -- given Change Notice
3396 
3397     CURSOR c_plm_ref_desgs IS
3398     SELECT *
3399     FROM   bom_reference_designators
3400     WHERE  change_notice = p_revised_item_rec.eco_name
3401     AND    component_sequence_id = p_component_sequence_id;
3402 
3403     CURSOR c_get_item_details(cp_inventory_item_id NUMBER, cp_organization_id NUMBER) IS
3404     SELECT concatenated_segments
3405       FROM mtl_system_items_kfv
3406      WHERE inventory_item_id = cp_inventory_item_id
3407        AND organization_id = cp_organization_id;
3408 BEGIN
3409   -- Initialize this API for error handling
3410   Eng_Propagation_Log_Util.Debug_Log(G_LOG_PROC, 'Propagate_Revised_Component.BEGIN');
3411   Error_Handler.Initialize;
3412 
3413   l_entity_action_status := Eng_Propagation_Log_Util.G_PRP_PRC_STS_SUCCESS;
3414   l_return_status := FND_API.G_RET_STS_SUCCESS;
3415   -- Strat processing for each component
3416   FOR rc in c_component_details
3417   LOOP
3418 
3419       l_revised_item_name := p_revised_item_rec.revised_item_name;
3420       l_new_item_revision := p_revised_item_rec.New_Revised_Item_Revision;
3421 
3422       -- Check if the component exists in the local organization
3423       l_comp_exists_in_org := G_VAL_TRUE;
3424       OPEN c_get_item_details(rc.component_item_id, p_local_organization_id);
3425       FETCH c_get_item_details INTO l_component_item_name;
3426       IF c_get_item_details%NOTFOUND
3427       THEN
3428           l_comp_exists_in_org := G_VAL_FALSE;
3429       END IF;
3430       CLOSE c_get_item_details;
3431 
3432 
3433       -- If component ACD type is ADD
3434       -- then it has to be auto enabled in the child organization
3435       -- Proceed to auto enable component
3436       IF rc.acd_type = 1 AND l_comp_exists_in_org = G_VAL_FALSE
3437       THEN
3438           Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Component Item Is being auto enabled. rc.component_item_id:'|| rc.component_item_id);
3439           Auto_enable_item_in_org(
3440               p_inventory_item_id => rc.component_item_id
3441             , p_organization_id  => p_local_organization_id
3442             , x_error_table      => l_item_error_table
3443             , x_return_status    => l_return_status);
3444           Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'After Component Item Is auto enabled. l_return_status'||l_return_status);
3445           IF (l_return_status = FND_API.G_RET_STS_SUCCESS)
3446           THEN
3447               OPEN c_get_item_details(rc.component_item_id, p_local_organization_id);
3448               FETCH c_get_item_details INTO l_component_item_name;
3449               IF c_get_item_details%NOTFOUND
3450               THEN
3451                   l_comp_exists_in_org := G_VAL_FALSE;
3452               ELSE
3453                   l_comp_exists_in_org := G_VAL_TRUE;
3454                   Fnd_message.set_name('ENG', 'ENG_PRP_COMP_NOT_ENABLED');
3455                   fnd_message.set_token('ITEM', l_component_item_name);
3456                   fnd_message.set_token('STRUCTURE', p_revised_item_rec.Alternate_Bom_Code);
3457                   l_message_log_text := fnd_message.get();
3458                   fnd_message.set_name('ENG', 'ENG_PRP_COMP_ENABLED');
3459                   l_temp_mesg := fnd_message.get();
3460                   Error_Handler.Add_Error_Token(
3461                       p_Message_Name   => NULL
3462                     , p_Message_Text   => l_message_log_text || l_temp_mesg
3463                     , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3464                     , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3465                     , p_message_type       => 'I'
3466                    );
3467               END IF;
3468               CLOSE c_get_item_details;
3469           ELSE
3470               FOR i IN 1..l_item_error_table.COUNT
3471               LOOP
3472                   Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Component Item Enabling Error:'||l_item_error_table(i).message_name);
3473                   Error_Handler.Add_Error_Token(
3474                       p_Message_Name   => NULL
3475                     , p_Message_Text   => l_item_error_table(i).message_text
3476                     , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3477                     , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3478                    );
3479               END LOOP;
3480 
3481           END IF;
3482       END IF;
3483 
3484       IF l_comp_exists_in_org = G_VAL_FALSE
3485       THEN
3486           OPEN c_get_item_details(rc.component_item_id, p_revised_item_unexp_rec.organization_id);
3487           FETCH c_get_item_details INTO l_component_item_name;
3488           CLOSE c_get_item_details;
3489 
3490           l_token_tbl.delete;
3491           l_token_tbl(1).token_name  := 'ITEM';
3492           l_token_tbl(1).token_value := l_component_item_name;
3493           l_token_tbl(1).token_name  := 'STRUCTURE';
3494           l_token_tbl(1).token_value := p_revised_item_rec.Alternate_Bom_Code;
3495 
3496           Error_Handler.Add_Error_Token(
3497               p_Message_Name       => 'ENG_PRP_COMP_NOT_EXIST'
3498             , p_Mesg_Token_Tbl     => l_mesg_token_tbl
3499             , x_Mesg_Token_Tbl     => l_mesg_token_tbl
3500             , p_Token_Tbl          => l_token_tbl
3501            );
3502           RAISE EXC_EXP_SKIP_OBJECT;
3503       END IF;
3504 
3505       IF (rc.supply_locator_id is NOT NULL)
3506       THEN
3507           SELECT CONCATENATED_SEGMENTS
3508           INTO   l_location_name
3509           FROM   mtl_item_locations_kfv
3510           WHERE inventory_location_id = rc.supply_locator_id;
3511       ELSE
3512           l_location_name := NULL;
3513       END IF;
3514 
3515       IF (rc.acd_type in (2,3))
3516       THEN
3517           BEGIN
3518               St_Number := 10;
3519               select assembly_item_id
3520               into   item_id
3521               from   bom_bill_of_materials
3522               where  bill_sequence_id = rc.bill_sequence_id;
3523 
3524               St_Number := 20;
3525               select bill_sequence_id
3526               into   bill_id
3527               from   bom_bill_of_materials
3528               where  assembly_item_id =  item_id
3529               and    organization_id = p_local_organization_id
3530               and    nvl(ALTERNATE_BOM_DESIGNATOR, 'primary') = nvl(p_revised_item_rec.alternate_bom_code,'primary');
3531 
3532               St_Number := 30;
3533               select operation_seq_num,trunc(effectivity_date)
3534               into   old_operation_seq_num,l_old_effectivity_date
3535               from   bom_inventory_components
3536               where  COMPONENT_SEQUENCE_ID = rc.OLD_COMPONENT_SEQUENCE_ID;
3537 
3538               St_Number := 40;
3539               select max(component_sequence_id)
3540               into   component_seq_id
3541               from   bom_inventory_components
3542               where ((trunc(effectivity_date) = l_old_effectivity_date) OR
3543                      (rc.effectivity_date between
3544                        trunc(effectivity_date) and
3545                            NVL(disable_date, rc.effectivity_date + 1))
3546                         )
3547               -- Bug 3041105 : Commenting code to pick unimplemented components
3548               -- and implementation_date IS NOT NULL
3549               and    component_item_id = rc.COMPONENT_ITEM_ID
3550               and    bill_sequence_id = bill_id
3551               and    operation_seq_num = old_operation_seq_num;
3552 
3553               St_Number := 50;
3554               select effectivity_date
3555               into old_effectivity_date
3556               from bom_inventory_components
3557               where component_sequence_id = component_seq_id;
3558 
3559           EXCEPTION
3560           WHEN NO_DATA_FOUND THEN
3561               old_operation_seq_num := NULL;
3562               old_effectivity_date := NULL;
3563           WHEN OTHERS THEN
3564               null;
3565           END;
3566       ELSE
3567           old_operation_seq_num := NULL;
3568           old_effectivity_date := NULL;
3569       END IF;
3570 
3571       /* Populate the revised components table for this revised item */
3572 
3573       l_rev_component_tbl(l_rev_component_count).eco_name := rc.change_notice;
3574       l_rev_component_tbl(l_rev_component_count).organization_code:= p_revised_item_rec.organization_code;
3575       l_rev_component_tbl(l_rev_component_count).revised_item_name := l_revised_item_name;
3576       l_rev_component_tbl(l_rev_component_count).new_revised_item_revision := l_new_item_revision;
3577       l_rev_component_tbl(l_rev_component_count).start_effective_date := rc.effectivity_date;
3578       l_rev_component_tbl(l_rev_component_count).new_effectivity_date := NULL;
3579       l_rev_component_tbl(l_rev_component_count).COMMENTS := rc.COMPONENT_REMARKS;
3580       l_rev_component_tbl(l_rev_component_count).disable_date := rc.disable_date;
3581       l_rev_component_tbl(l_rev_component_count).operation_sequence_number := rc.operation_seq_num;
3582       l_rev_component_tbl(l_rev_component_count).component_item_name := l_component_item_name;
3583       l_rev_component_tbl(l_rev_component_count).alternate_bom_code := p_revised_item_rec.alternate_bom_code;
3584       l_rev_component_tbl(l_rev_component_count).acd_type := rc.acd_type;
3585       l_rev_component_tbl(l_rev_component_count).old_effectivity_date := old_effectivity_date;
3586       l_rev_component_tbl(l_rev_component_count).old_operation_sequence_number := old_operation_seq_num;
3587       l_rev_component_tbl(l_rev_component_count).new_operation_sequence_number := NULL;
3588       l_rev_component_tbl(l_rev_component_count).item_sequence_number := rc.item_num;
3589       l_rev_component_tbl(l_rev_component_count).quantity_per_assembly := rc.component_quantity;
3590       l_rev_component_tbl(l_rev_component_count).planning_percent := rc.planning_factor;
3591       l_rev_component_tbl(l_rev_component_count).projected_yield := rc.component_yield_factor;
3592       l_rev_component_tbl(l_rev_component_count).include_in_cost_rollup := rc.include_in_cost_rollup;
3593       l_rev_component_tbl(l_rev_component_count).wip_supply_type := rc.wip_supply_type;
3594       l_rev_component_tbl(l_rev_component_count).so_basis :=  rc.so_basis;
3595       l_rev_component_tbl(l_rev_component_count).basis_type :=  rc.basis_type;
3596       l_rev_component_tbl(l_rev_component_count).optional := rc.optional;
3597       l_rev_component_tbl(l_rev_component_count).mutually_exclusive := rc.mutually_exclusive_options;
3598       l_rev_component_tbl(l_rev_component_count).check_atp := rc.check_atp;
3599       l_rev_component_tbl(l_rev_component_count).shipping_allowed := rc.shipping_allowed;
3600       l_rev_component_tbl(l_rev_component_count).required_to_ship := rc.required_to_ship;
3601       l_rev_component_tbl(l_rev_component_count).required_for_revenue := rc.required_for_revenue;
3602       l_rev_component_tbl(l_rev_component_count).include_on_ship_docs := rc.include_on_ship_docs;
3603       l_rev_component_tbl(l_rev_component_count).quantity_related := rc.quantity_related;
3604       l_rev_component_tbl(l_rev_component_count).supply_subinventory := rc.supply_subinventory;
3605       l_rev_component_tbl(l_rev_component_count).location_name := l_location_name;
3606       l_rev_component_tbl(l_rev_component_count).minimum_allowed_quantity := rc.low_quantity;
3607       l_rev_component_tbl(l_rev_component_count).maximum_allowed_quantity := rc.high_quantity;
3608       l_rev_component_tbl(l_rev_component_count).attribute_category  := rc.attribute_category;
3609       l_rev_component_tbl(l_rev_component_count).attribute1  := rc.attribute1;
3610       l_rev_component_tbl(l_rev_component_count).attribute2  := rc.attribute2;
3611       l_rev_component_tbl(l_rev_component_count).attribute3  := rc.attribute3;
3612       l_rev_component_tbl(l_rev_component_count).attribute4  := rc.attribute4;
3613       l_rev_component_tbl(l_rev_component_count).attribute5  := rc.attribute5;
3614       l_rev_component_tbl(l_rev_component_count).attribute6  := rc.attribute6;
3615       l_rev_component_tbl(l_rev_component_count).attribute7  := rc.attribute7;
3616       l_rev_component_tbl(l_rev_component_count).attribute8  := rc.attribute8;
3617       l_rev_component_tbl(l_rev_component_count).attribute9  := rc.attribute9;
3618       l_rev_component_tbl(l_rev_component_count).attribute10  := rc.attribute10;
3619       l_rev_component_tbl(l_rev_component_count).attribute11  := rc.attribute11;
3620       l_rev_component_tbl(l_rev_component_count).attribute12  := rc.attribute12;
3621       l_rev_component_tbl(l_rev_component_count).attribute13  := rc.attribute13;
3622       l_rev_component_tbl(l_rev_component_count).attribute14  := rc.attribute14;
3623       l_rev_component_tbl(l_rev_component_count).attribute15  := rc.attribute15;
3624       l_rev_component_tbl(l_rev_component_count).from_end_item_unit_number := rc.from_end_item_unit_number;
3625       l_rev_component_tbl(l_rev_component_count).to_end_item_unit_number := rc.to_end_item_unit_number;
3626       l_rev_component_tbl(l_rev_component_count).original_system_reference := rc.original_system_reference;
3627       l_rev_component_tbl(l_rev_component_count).new_from_end_item_unit_number := NULL;
3628       l_rev_component_tbl(l_rev_component_count).old_from_end_item_unit_number := NULL;
3629       l_rev_component_tbl(l_rev_component_count).return_status := NULL;
3630       l_rev_component_tbl(l_rev_component_count).transaction_type := 'CREATE';
3631 
3632       l_rev_component_count := l_rev_component_count + 1;
3633 
3634       /* Fetch all revised substitute component items of this structure of this component */
3635 
3636       FOR sc IN c_plm_sub_comps
3637       LOOP            /* Loop 6 */
3638 
3639           --FND_FILE.PUT_LINE(FND_FILE.LOG,'Processing Substitute Components ...');
3640           l_item_exits_in_org_flag := G_VAL_TRUE;
3641           OPEN c_get_item_details(sc.substitute_component_id, p_local_organization_id);
3642           FETCH c_get_item_details INTO l_substitute_component_name;
3643           IF c_get_item_details%NOTFOUND
3644           THEN
3645               l_item_exits_in_org_flag := G_VAL_FALSE;
3646           END IF;
3647           CLOSE c_get_item_details;
3648 
3649           IF sc.acd_type = 1 AND l_item_exits_in_org_flag = G_VAL_FALSE
3650           THEN
3651               l_item_error_table.delete;
3652 
3653               Auto_enable_item_in_org(
3654                   p_inventory_item_id => sc.substitute_component_id
3655                 , p_organization_id  => p_local_organization_id
3656                 , x_error_table      => l_item_error_table
3657                 , x_return_status    => l_return_status);
3658 
3659               IF (l_return_status = 'S')
3660               THEN
3661                   OPEN c_get_item_details(sc.substitute_component_id, p_local_organization_id);
3662                   FETCH c_get_item_details INTO l_substitute_component_name;
3663                   IF c_get_item_details%NOTFOUND
3664                   THEN
3665                       l_item_exits_in_org_flag := G_VAL_FALSE;
3666                   ELSE
3667                       l_item_exits_in_org_flag := G_VAL_TRUE;
3668 
3669                       Fnd_message.set_name('ENG', 'ENG_PRP_SUBS_NOT_ENABLED');
3670                       fnd_message.set_token('ITEM1', l_substitute_component_name);
3671                       fnd_message.set_token('ITEM2', l_component_item_name);
3672                       fnd_message.set_token('STRUCTURE', p_revised_item_rec.Alternate_Bom_Code);
3673                       l_message_log_text := fnd_message.get();
3674                       fnd_message.set_name('ENG', 'ENG_PRP_COMP_ENABLED');
3675                       l_temp_mesg := fnd_message.get();
3676                       Error_Handler.Add_Error_Token(
3677                           p_Message_Name   => NULL
3678                         , p_Message_Text   => l_message_log_text || l_temp_mesg
3679                         , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3680                         , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3681                        );
3682                   END IF;
3683                   CLOSE c_get_item_details;
3684               ELSE
3685                   FOR i IN 1..l_item_error_table.COUNT
3686                   LOOP
3687                       Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Component Item Enabling Error:'||l_item_error_table(i).message_name);
3688                       Error_Handler.Add_Error_Token(
3689                           p_Message_Name   => NULL
3690                         , p_Message_Text   => l_item_error_table(i).message_text
3691                         , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3692                         , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
3693                        );
3694                   END LOOP;
3695                   FND_FILE.PUT_LINE(FND_FILE.LOG, 'Component Enabling Failed ..');
3696                   l_item_error_table.delete;
3697               END IF;
3698           END IF;
3699           IF l_item_exits_in_org_flag = G_VAL_FALSE
3700           THEN
3701               l_has_invalid_objects := G_VAL_TRUE;
3702               OPEN c_get_item_details(sc.substitute_component_id, p_revised_item_unexp_rec.organization_id);
3703               FETCH c_get_item_details INTO l_substitute_component_name;
3704               CLOSE c_get_item_details;
3705 
3706               l_token_tbl.delete;
3707               l_token_tbl(1).token_name  := 'ITEM1';
3708               l_token_tbl(1).token_value := l_substitute_component_name;
3709               l_token_tbl(1).token_name  := 'ITEM2';
3710               l_token_tbl(1).token_value := l_component_item_name;
3711               l_token_tbl(3).token_name  := 'STRUCTURE';
3712               l_token_tbl(3).token_value := p_revised_item_rec.alternate_bom_code;
3713 
3714               Error_Handler.Add_Error_Token(
3715                   p_Message_Name       => 'ENG_PRP_SUBS_NOT_EXIST'
3716                 , p_Mesg_Token_Tbl     => l_mesg_token_tbl
3717                 , x_Mesg_Token_Tbl     => l_mesg_token_tbl
3718                 , p_Token_Tbl          => l_token_tbl
3719                );
3720           ELSE
3721               l_sub_component_tbl(l_sub_component_count).eco_name := sc.change_notice;
3722               l_sub_component_tbl(l_sub_component_count).organization_code:= p_revised_item_rec.organization_code;
3723               l_sub_component_tbl(l_sub_component_count).revised_item_name := l_revised_item_name;
3724               l_sub_component_tbl(l_sub_component_count).start_effective_date := rc.effectivity_date;
3725               l_sub_component_tbl(l_sub_component_count).new_revised_item_revision := l_new_item_revision;
3726               l_sub_component_tbl(l_sub_component_count).component_item_name := l_component_item_name;
3727               l_sub_component_tbl(l_sub_component_count).alternate_bom_code := p_revised_item_rec.alternate_bom_code;
3728               l_sub_component_tbl(l_sub_component_count).substitute_component_name := l_substitute_component_name;
3729               l_sub_component_tbl(l_sub_component_count).acd_type := sc.acd_type;
3730               l_sub_component_tbl(l_sub_component_count).operation_sequence_number := rc.operation_seq_num;
3731               l_sub_component_tbl(l_sub_component_count).substitute_item_quantity := sc.substitute_item_quantity;
3732               l_sub_component_tbl(l_sub_component_count).attribute_category  := sc.attribute_category;
3733               l_sub_component_tbl(l_sub_component_count).attribute1  := sc.attribute1;
3734               l_sub_component_tbl(l_sub_component_count).attribute2  := sc.attribute2;
3735               l_sub_component_tbl(l_sub_component_count).attribute3  := sc.attribute3;
3736               l_sub_component_tbl(l_sub_component_count).attribute4  := sc.attribute4;
3737               l_sub_component_tbl(l_sub_component_count).attribute5  := sc.attribute5;
3738               l_sub_component_tbl(l_sub_component_count).attribute6  := sc.attribute6;
3739               l_sub_component_tbl(l_sub_component_count).attribute7  := sc.attribute7;
3740               l_sub_component_tbl(l_sub_component_count).attribute8  := sc.attribute8;
3741               l_sub_component_tbl(l_sub_component_count).attribute9  := sc.attribute9;
3742               l_sub_component_tbl(l_sub_component_count).attribute10  := sc.attribute10;
3743               l_sub_component_tbl(l_sub_component_count).attribute11  := sc.attribute11;
3744               l_sub_component_tbl(l_sub_component_count).attribute12  := sc.attribute12;
3745               l_sub_component_tbl(l_sub_component_count).attribute13  := sc.attribute13;
3746               l_sub_component_tbl(l_sub_component_count).attribute14  := sc.attribute14;
3747               l_sub_component_tbl(l_sub_component_count).attribute15  := sc.attribute15;
3748               l_sub_component_tbl(l_sub_component_count).from_end_item_unit_number  := rc.from_end_item_unit_number;
3749               l_sub_component_tbl(l_sub_component_count).Original_System_Reference := sc.Original_System_Reference;
3750               l_sub_component_tbl(l_sub_component_count).return_status := NULL;
3751               l_sub_component_tbl(l_sub_component_count).transaction_type := 'CREATE';
3752 
3753               l_sub_component_count := l_sub_component_count + 1;
3754           END IF;
3755       END LOOP;                                               /* End Loop 6  */
3756       IF (l_has_invalid_objects = G_VAL_TRUE)
3757       THEN
3758           RAISE EXC_EXP_SKIP_OBJECT;
3759       END IF;
3760       /* Fetch all revised reference designators on this structure of this revised item */
3761       FOR rd IN c_plm_ref_desgs
3762       LOOP                                                    /* Loop 7 */
3763 
3764           --FND_FILE.PUT_LINE(FND_FILE.LOG,'Processing Reference Designators ...');
3765           l_ref_designator_tbl(l_ref_designator_count).eco_name := rd.change_notice;
3766           l_ref_designator_tbl(l_ref_designator_count).organization_code := p_revised_item_rec.organization_code;
3767           l_ref_designator_tbl(l_ref_designator_count).revised_item_name := l_revised_item_name;
3768           l_ref_designator_tbl(l_ref_designator_count).start_effective_date := rc.effectivity_date;
3769           l_ref_designator_tbl(l_ref_designator_count).new_revised_item_revision := l_new_item_revision;
3770           l_ref_designator_tbl(l_ref_designator_count).operation_sequence_number := rc.operation_seq_num;
3771           l_ref_designator_tbl(l_ref_designator_count).component_item_name := l_component_item_name;
3772           l_ref_designator_tbl(l_ref_designator_count).alternate_bom_code :=  p_revised_item_rec.alternate_bom_code;
3773           l_ref_designator_tbl(l_ref_designator_count).reference_designator_name := rd.component_reference_designator;
3774           l_ref_designator_tbl(l_ref_designator_count).acd_type := rd.acd_type;
3775           l_ref_designator_tbl(l_ref_designator_count).ref_designator_comment := rd.ref_designator_comment;
3776           l_ref_designator_tbl(l_ref_designator_count).attribute_category := rd.attribute_category;
3777           l_ref_designator_tbl(l_ref_designator_count).attribute1  := rd.attribute1;
3778           l_ref_designator_tbl(l_ref_designator_count).attribute2  := rd.attribute2;
3779           l_ref_designator_tbl(l_ref_designator_count).attribute3  := rd.attribute3;
3780           l_ref_designator_tbl(l_ref_designator_count).attribute4  := rd.attribute4;
3781           l_ref_designator_tbl(l_ref_designator_count).attribute5  := rd.attribute5;
3782           l_ref_designator_tbl(l_ref_designator_count).attribute6  := rd.attribute6;
3783           l_ref_designator_tbl(l_ref_designator_count).attribute7  := rd.attribute7;
3784           l_ref_designator_tbl(l_ref_designator_count).attribute8  := rd.attribute8;
3785           l_ref_designator_tbl(l_ref_designator_count).attribute9  := rd.attribute9;
3786           l_ref_designator_tbl(l_ref_designator_count).attribute10  := rd.attribute10;
3787           l_ref_designator_tbl(l_ref_designator_count).attribute11  := rd.attribute11;
3788           l_ref_designator_tbl(l_ref_designator_count).attribute12  := rd.attribute12;
3789           l_ref_designator_tbl(l_ref_designator_count).attribute13  := rd.attribute13;
3790           l_ref_designator_tbl(l_ref_designator_count).attribute14  := rd.attribute14;
3791           l_ref_designator_tbl(l_ref_designator_count).attribute15  := rd.attribute15;
3792           l_ref_designator_tbl(l_ref_designator_count).Original_System_Reference := rd.Original_System_Reference;
3793           l_ref_designator_tbl(l_ref_designator_count).new_reference_designator := NULL;
3794           l_ref_designator_tbl(l_ref_designator_count).from_end_item_unit_number := NULL;
3795           l_ref_designator_tbl(l_ref_designator_count).return_status := NULL;
3796           l_ref_designator_tbl(l_ref_designator_count).transaction_type := 'CREATE';
3797           l_ref_designator_count := l_ref_designator_count + 1;
3798       END LOOP;        /* End Loop 7 */
3799 
3800   END LOOP; -- End of loop of revised components Only one is selected
3801 
3802   Eng_Eco_Pvt.Process_Rev_Comp(
3803       p_validation_level   => FND_API.G_VALID_LEVEL_FULL
3804     , p_change_notice      => p_revised_item_rec.eco_name
3805     , p_organization_id    => p_local_organization_id
3806     , I                    => 1
3807     , p_rev_component_rec  => l_rev_component_tbl(1)
3808     , p_ref_designator_tbl => l_ref_designator_tbl
3809     , p_sub_component_tbl  => l_sub_component_tbl
3810     , x_rev_component_tbl  => l_rev_component_tbl
3811     , x_ref_designator_tbl => l_ref_designator_tbl
3812     , x_sub_component_tbl  => l_sub_component_tbl
3813     , x_rev_comp_unexp_rec => l_rev_comp_unexp_rec
3814     , x_Mesg_Token_Tbl     => l_bo_Mesg_Token_Tbl
3815     , x_return_status      => l_return_status
3816     , x_bill_sequence_id   => p_revised_item_unexp_rec.bill_sequence_id
3817    );
3818   IF (l_return_status <> FND_API.G_RET_STS_SUCCESS)
3819   THEN
3820       RAISE EXC_EXP_SKIP_OBJECT;
3821   END IF;
3822   --
3823   -- Add messages through propagation Maps
3824   -- Calling log_errors first as in case of successful propagation the messages are not being displayed
3825   --
3826   Eco_Error_Handler.Log_Error(
3827       p_error_status         => l_return_status
3828     , p_mesg_token_tbl       => l_mesg_token_tbl
3829     , p_error_scope          => Error_Handler.G_SCOPE_RECORD
3830     , p_error_level          => Eco_Error_Handler.G_RC_LEVEL
3831     , x_eco_rec              => ENG_Eco_PUB.G_MISS_ECO_REC
3832     , x_eco_revision_tbl     => ENG_Eco_PUB.G_MISS_ECO_REVISION_TBL
3833     , x_change_line_tbl      => ENG_Eco_PUB.G_MISS_CHANGE_LINE_TBL -- Eng Change
3834     , x_revised_item_tbl     => ENG_Eco_PUB.G_MISS_REVISED_ITEM_TBL
3835     , x_rev_component_tbl    => l_rev_component_tbl
3836     , x_ref_designator_tbl   => l_ref_designator_tbl
3837     , x_sub_component_tbl    => l_sub_component_tbl
3838     , x_rev_operation_tbl    => ENG_Eco_PUB.G_MISS_REV_OPERATION_TBL
3839     , x_rev_op_resource_tbl  => ENG_Eco_PUB.G_MISS_REV_OP_RESOURCE_TBL
3840     , x_rev_sub_resource_tbl => ENG_Eco_PUB.G_MISS_REV_SUB_RESOURCE_TBL
3841    );
3842 
3843   Eng_Propagation_Log_Util.Add_Entity_Map(
3844       p_change_id                 => p_change_id
3845     , p_revised_item_sequence_id  => p_revised_item_sequence_id
3846     , p_revised_line_type         => Eng_Propagation_Log_Util.G_REV_LINE_CMP_CHG
3847     , p_revised_line_id1          => p_component_sequence_id
3848     , p_local_organization_id     => p_local_organization_id
3849     , p_local_revised_item_seq_id => p_revised_item_unexp_rec.revised_item_sequence_id
3850     , p_local_revised_line_id1    => l_rev_comp_unexp_rec.component_sequence_id
3851     , p_entity_name               => Eng_Propagation_Log_Util.G_ENTITY_REVISED_LINE
3852     , p_entity_action_status      => l_entity_action_status
3853     , p_bo_entity_identifier      => 'RC'--Eco_Error_Handler.G_RC_LEVEL
3854    );
3855   -- TODO: How to handle substitue component and reference designator errors
3856 EXCEPTION
3857 WHEN EXC_EXP_SKIP_OBJECT THEN
3858     -- Set the return status
3859     l_return_status := FND_API.G_RET_STS_ERROR;
3860     -- Log any messages that have been logged with the additional error
3861     -- message into error handler
3862     Eco_Error_Handler.Log_Error(
3863         p_error_status         => l_return_status
3864       , p_mesg_token_tbl       => l_mesg_token_tbl
3865       , p_error_scope          => Error_Handler.G_SCOPE_RECORD
3866       , p_error_level          => Eco_Error_Handler.G_RC_LEVEL
3867       , x_eco_rec              => ENG_Eco_PUB.G_MISS_ECO_REC
3868       , x_eco_revision_tbl     => ENG_Eco_PUB.G_MISS_ECO_REVISION_TBL
3869       , x_change_line_tbl      => ENG_Eco_PUB.G_MISS_CHANGE_LINE_TBL -- Eng Change
3870       , x_revised_item_tbl     => ENG_Eco_PUB.G_MISS_REVISED_ITEM_TBL
3871       , x_rev_component_tbl    => l_rev_component_tbl
3872       , x_ref_designator_tbl   => l_ref_designator_tbl
3873       , x_sub_component_tbl    => l_sub_component_tbl
3874       , x_rev_operation_tbl    => ENG_Eco_PUB.G_MISS_REV_OPERATION_TBL
3875       , x_rev_op_resource_tbl  => ENG_Eco_PUB.G_MISS_REV_OP_RESOURCE_TBL
3876       , x_rev_sub_resource_tbl => ENG_Eco_PUB.G_MISS_REV_SUB_RESOURCE_TBL
3877      );
3878     -- local change id is set later
3879     -- if there are errors, based on the level they are not populated in the
3880     -- maps table.
3881     Eng_Propagation_Log_Util.add_entity_map(
3882         p_change_id                 => p_change_id
3883       , p_revised_item_sequence_id  => p_revised_item_sequence_id
3884       , p_revised_line_type         => Eng_Propagation_Log_Util.G_REV_LINE_CMP_CHG
3885       , p_revised_line_id1          => p_component_sequence_id
3886       , p_local_organization_id     => p_local_organization_id
3887       , p_entity_name               => Eng_Propagation_Log_Util.G_ENTITY_REVISED_LINE
3888       , p_entity_action_status      => Eng_Propagation_Log_Util.G_PRP_PRC_STS_ERROR
3889       , p_bo_entity_identifier      => 'RC'--Eco_Error_Handler.G_RC_LEVEL
3890      );
3891     x_return_status := l_return_status;
3892 END Propagate_Revised_Component;
3893 
3894 PROCEDURE Check_Change_Existance (
3895     p_change_notice       IN VARCHAR2
3896   , p_organization_id     IN NUMBER
3897   , x_Mesg_Token_Tbl      IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
3898   , x_Return_Status       OUT NOCOPY VARCHAR2
3899 ) IS
3900 
3901     CURSOR c_change_notice IS
3902     SELECT G_VAL_EXISTS
3903       FROM eng_engineering_changes
3904      WHERE change_notice = p_change_notice
3905        AND organization_id = p_organization_id;
3906 
3907     l_change_exists    NUMBER;
3908     l_Mesg_token_Tbl   Error_Handler.Mesg_Token_Tbl_Type;
3909     l_return_status    VARCHAR2(1);
3910     l_err_text         VARCHAR2(2000);
3911     l_Token_Tbl        Error_Handler.Token_Tbl_Type;
3912 
3913 BEGIN
3914     l_return_status := FND_API.G_RET_STS_SUCCESS;
3915 
3916     l_change_exists := G_VAL_NOT_EXISTS;
3917 
3918     OPEN c_change_notice;
3919     FETCH c_change_notice INTO l_change_exists;
3920     CLOSE c_change_notice;
3921 
3922     IF l_change_exists = G_VAL_EXISTS
3923     THEN
3924         l_return_status := FND_API.G_RET_STS_ERROR;
3925         Error_Handler.Add_Error_Token(
3926             p_Message_Name       => 'ENG_PRP_ECO_EXISTS'
3927           , p_Mesg_Token_Tbl     => l_mesg_token_tbl
3928           , x_Mesg_Token_Tbl     => l_mesg_token_tbl
3929           , p_Token_Tbl          => l_token_tbl
3930          );
3931     END IF;
3932 EXCEPTION
3933 WHEN OTHERS THEN
3934     IF c_change_notice%ISOPEN
3935     THEN
3936         CLOSE c_change_notice;
3937     END IF;
3938     l_return_status := FND_API.G_RET_STS_ERROR;
3939 END Check_Change_Existance;
3940 
3941 PROCEDURE Init_Local_Change_Lifecycle (
3942     p_local_change_id    IN NUMBER
3943   , p_organization_id    IN NUMBER
3944   , p_org_hierarchy_name IN VARCHAR2
3945   , x_return_status      OUT NOCOPY VARCHAR2
3946 ) IS
3947   l_status_code          NUMBER;
3948   l_msg_count            NUMBER;
3949   l_mesg_data            VARCHAR2(2000);
3950   l_schedule_immediately ENG_ORG_HIERARCHY_POLICIES.SCHEDULE_IMMEDIATELY_FLAG%TYPE;
3951   l_new_status_type      NUMBER;
3952   CURSOR c_get_schedule_enabled IS
3953   SELECT eohp.SCHEDULE_IMMEDIATELY_FLAG
3954     FROM ENG_ORG_HIERARCHY_POLICIES eohp, ENG_TYPE_ORG_HIERARCHIES etoh, eng_engineering_changes eec
3955    WHERE eec.change_id = p_local_change_id
3956      AND eohp.organization_id = eec.organization_id
3957      AND eohp.SCHEDULE_IMMEDIATELY_FLAG = 'Y'
3958      AND eohp.change_type_org_hierarchy_id = etoh.change_type_org_hierarchy_id
3959      AND etoh.change_type_id = eec.change_order_type_id
3960      AND etoh.organization_id = p_organization_id
3961      AND EXISTS (SELECT 1
3962                    FROM per_organization_structures hier
3963                   WHERE hier.name = p_org_hierarchy_name
3964                     AND etoh.hierarchy_id =  hier.organization_structure_id);
3965 
3966   -- cursor to fetch the status in which the change is to be initialized
3967   -- this cursor fetches the shduled status of the change if
3968   -- schedule immediately is set for the selected hierarchy at the change level
3969   -- for TTM case since the processing is per organization and the submit change
3970   -- would have been enabled this is not going to be called
3971   CURSOR c_get_init_status IS
3972   SELECT els.status_code
3973     FROM eng_lifecycle_statuses els
3974    WHERE els.entity_id1  = p_local_change_id
3975      AND els.entity_name = 'ENG_CHANGE'
3976      AND els.sequence_number =
3977                 (SELECT min(sequence_number)
3978                    FROM eng_lifecycle_statuses els1, eng_change_statuses_vl ecs1
3979                   WHERE els1.entity_id1  = p_local_change_id
3980                     AND els1.entity_name = 'ENG_CHANGE'
3981                     AND els1.status_code = ecs1.status_code
3982                     AND ((ecs1.status_type = 4 AND l_schedule_immediately = 'Y')
3983                          OR nvl(l_schedule_immediately, 'N') = 'N'))
3984      AND EXISTS (SELECT 1
3985                    FROM eng_engineering_changes
3986                   WHERE change_id = els.entity_id1
3987                     AND status_type = 0);
3988 BEGIN
3989     x_return_status := FND_API.G_RET_STS_SUCCESS;
3990     OPEN c_get_schedule_enabled;
3991     FETCH c_get_schedule_enabled INTO l_schedule_immediately;
3992     CLOSE c_get_schedule_enabled;
3993     OPEN c_get_init_status;
3994     FETCH c_get_init_status INTO l_status_code;
3995     IF c_get_init_status%FOUND
3996     THEN
3997         ENG_CHANGE_LIFECYCLE_UTIL.Init_Lifecycle(
3998             p_api_version       => 1.0
3999           , p_change_id         => p_local_change_id
4000           , x_return_status     => x_return_status
4001           , x_msg_count         => l_msg_count
4002           , x_msg_data          => l_mesg_data
4003           , p_api_caller        => 'CP'
4004           , p_init_status_code  => l_status_code
4005          );
4006 
4007         SELECT status_type
4008           INTO l_new_status_type
4009           FROM eng_change_statuses
4010          WHERE status_code = l_status_code
4011            AND rownum = 1;
4012         -- The following update should be moved to init lifecycle
4013         UPDATE eng_revised_items
4014            SET status_code = l_status_code,
4015                status_type = l_new_status_type,
4016                last_update_date = sysdate,
4017                last_updated_by = FND_PROFILE.VALUE('USER_ID'),
4018                last_update_login = FND_PROFILE.VALUE('LOGIN_ID')
4019          WHERE change_id = p_local_change_id;
4020     END IF;
4021     CLOSE c_get_init_status;
4022 EXCEPTION
4023 WHEN OTHERS THEN
4024     IF c_get_init_status%ISOPEN
4025     THEN
4026         CLOSE c_get_init_status;
4027     END IF;
4028     IF c_get_schedule_enabled%ISOPEN
4029     THEN
4030         CLOSE c_get_schedule_enabled;
4031     END IF;
4032     x_return_status := FND_API.G_RET_STS_ERROR;
4033 END Init_Local_Change_Lifecycle;
4034 
4035 PROCEDURE Propagate_Change_Header (
4036     p_change_id               IN NUMBER
4037   , p_change_notice           IN VARCHAR2
4038   , p_organization_code       IN VARCHAR2
4039   , p_organization_id         IN NUMBER
4040   , p_org_hierarchy_name      IN VARCHAR2
4041   , p_local_organization_code IN VARCHAR2
4042   , p_local_organization_id   IN NUMBER
4043   , x_Mesg_Token_Tbl          IN OUT NOCOPY Error_Handler.Mesg_Token_Tbl_Type
4044   , x_Return_Status           OUT NOCOPY VARCHAR2
4045 ) IS
4046     -- Local Identifiers
4047     l_local_change_id       NUMBER;
4048     -- Exposed Column Data
4049     l_change_type_code      VARCHAR2(80);
4050     l_change_mgmt_type      Eng_change_order_types_tl.type_name%TYPE; --Bug 3544760
4051     l_requestor_name        VARCHAR2(30);
4052     l_assignee_name         VARCHAR2(360);
4053     l_Task_Number           VARCHAR2(25);
4054     l_Project_Number        VARCHAR2(30);
4055     -- Some internl variables
4056     l_sched_immediately     NUMBER := 1;
4057     l_pk1_value             VARCHAR2(100);
4058     l_pk2_value             VARCHAR2(100);
4059     l_pk3_value             VARCHAR2(100);
4060     l_entity_name           VARCHAR2(30);
4061     l_header_subject_exists NUMBER := 1;
4062     i                       NUMBER;
4063     l_invalid_subject       NUMBER := 0;
4064     l_pk1_name              VARCHAR2(40);
4065     l_pk2_name              VARCHAR2(3);
4066     l_pk3_name              VARCHAR2(3);
4067     l_approval_status       VARCHAR2(80);
4068     l_task_number1          VARCHAR2(100);
4069     l_party_id              NUMBER;
4070     l_party_type            VARCHAR2(30);
4071     l_default_assignee_type eng_change_order_types.default_assignee_type%TYPE;
4072     l_assignee_role_id      NUMBER;
4073     l_status_name           eng_change_statuses_tl.status_name%TYPE;
4074     l_department_name           VARCHAR2(240);
4075     l_change_type_id        NUMBER;
4076     -- Variables for error handling
4077     l_msg_count             NUMBER;
4078     l_Mesg_token_Tbl        Error_Handler.Mesg_Token_Tbl_Type;
4079     l_return_status         VARCHAR2(1);
4080     l_err_text              VARCHAR2(2000);
4081     l_Token_Tbl             Error_Handler.Token_Tbl_Type;
4082     -- Variables for Call to Process ECO
4083     l_eco_rec               Eng_Eco_Pub.Eco_Rec_Type;
4084     l_change_lines_tbl      Eng_Eco_Pub.Change_Line_Tbl_Type;
4085     l_eco_revision_tbl      Eng_Eco_Pub.Eco_Revision_Tbl_Type;
4086     l_revised_item_tbl      Eng_Eco_Pub.Revised_Item_Tbl_Type;
4087     l_rev_component_tbl     Bom_Bo_Pub.Rev_Component_Tbl_Type;
4088     l_sub_component_tbl     Bom_Bo_Pub.Sub_Component_Tbl_Type;
4089     l_ref_designator_tbl    Bom_Bo_Pub.Ref_Designator_Tbl_Type;
4090     l_rev_operation_tbl     Bom_Rtg_Pub.Rev_Operation_Tbl_Type;
4091     l_rev_op_resource_tbl   Bom_Rtg_Pub.Rev_Op_Resource_Tbl_Type;
4092     l_rev_sub_resource_tbl  Bom_Rtg_Pub.Rev_Sub_Resource_Tbl_Type;
4093 
4094    --
4095    -- Cursor to Pick all ECO header for the Top Organization for the given
4096    -- Change Notice
4097    CURSOR c_eco_rec IS
4098    SELECT *
4099      FROM eng_engineering_changes
4100     WHERE change_notice = p_change_notice
4101       AND organization_id = p_organization_id;
4102 
4103    -- Cursor to Pick all Revised Items for the Top Organization for the given
4104    -- Change Notice
4105    CURSOR c_eco_revision IS
4106    SELECT *
4107      FROM eng_change_order_revisions
4108     WHERE change_notice = p_change_notice
4109       AND organization_id = p_organization_id
4110       AND nvl(start_date, sysdate) > sysdate; -- Added this condtion as only future revisions need to be fetched
4111    /* Cursor to fetch the group name given the party id */
4112    CURSOR c_group_name(cp_party_id NUMBER) IS
4113    SELECT party_name
4114    FROM hz_parties
4115    WHERE party_id = cp_party_id
4116    AND party_type = 'GROUP';
4117 
4118    /* Cursor to fetch the assignees with direct item roles at item level */
4119    CURSOR c_item_assignee(cp_assignee_role_id NUMBER, cp_item_id NUMBER, cp_org_id NUMBER) IS
4120    SELECT party.party_id, party.party_name, party.party_type
4121    FROM  HZ_PARTIES party, fnd_grants grants, fnd_objects obj
4122    WHERE obj.obj_name = 'EGO_ITEM'
4123    AND grants.object_id = obj.object_id
4124    AND grants.GRANTEE_ORIG_SYSTEM_ID =  party.party_id
4125    AND (
4126         (grants.GRANTEE_ORIG_SYSTEM = 'HZ_PARTY' AND grants.grantee_type ='USER' AND party.party_type= 'PERSON')
4127         OR (grants.GRANTEE_ORIG_SYSTEM = 'HZ_GROUP' AND grants.grantee_type ='GROUP' AND party.party_type= 'GROUP')
4128        )
4129    AND grants.start_date <= SYSDATE
4130    AND NVL(grants.end_date, SYSDATE+1) >= TRUNC(SYSDATE)
4131    AND grants.instance_type = 'INSTANCE'
4132    AND grants.menu_id = cp_assignee_role_id
4133    AND grants.instance_pk1_value = cp_item_id
4134    AND grants.instance_pk2_value = cp_org_id
4135    AND ROWNUM = 1;
4136 
4137    /* Cursor to fetch the assignees with item roles at catalog category level */
4138    CURSOR c_category_item_assignee(cp_assignee_role_id NUMBER, cp_item_id NUMBER, cp_org_id NUMBER) IS
4139    SELECT party.party_id, party.party_name, party.party_type
4140    FROM  HZ_PARTIES party, fnd_grants grants, fnd_objects obj
4141    WHERE obj.obj_name = 'EGO_ITEM'
4142    AND grants.object_id = obj.object_id
4143    AND grants.GRANTEE_ORIG_SYSTEM_ID =  party.party_id
4144    AND (
4145     (grants.GRANTEE_ORIG_SYSTEM = 'HZ_PARTY' AND grants.grantee_type ='USER' AND party.party_type= 'PERSON')
4146         OR (grants.GRANTEE_ORIG_SYSTEM = 'HZ_GROUP' AND grants.grantee_type ='GROUP' AND party.party_type= 'GROUP')
4147        )
4148    AND grants.start_date <= SYSDATE
4149    AND NVL(grants.end_date, SYSDATE+1) >= TRUNC(SYSDATE)
4150    AND grants.instance_type= 'SET'
4151    AND grants.menu_id = cp_assignee_role_id
4152    AND grants.instance_set_id IN ( SELECT instance_set.instance_set_id
4153                    FROM fnd_object_instance_sets instance_set, mtl_system_items_b item1
4154                    WHERE instance_set.object_id = grants.object_id
4155                    AND instance_set.instance_set_name = 'EGO_ORG_CAT_ITEM_' ||
4156                     to_char(item1.organization_id) || '_' || to_char(item1.ITEM_CATALOG_GROUP_ID)
4157                    AND item1.INVENTORY_ITEM_ID= cp_item_id
4158                    AND item1.ORGANIZATION_ID = cp_org_id  )
4159    AND ROWNUM = 1;
4160 
4161    /* Cursor to fetch the assignees with item roles at organization level */
4162    CURSOR  c_org_assignee(cp_assignee_role_id NUMBER, cp_org_id NUMBER) IS
4163    SELECT  party.party_id, party.party_name, party.party_type
4164    FROM  HZ_PARTIES party, fnd_grants grants, fnd_objects obj
4165    WHERE obj.obj_name = 'EGO_ITEM'
4166    AND grants.object_id = obj.object_id
4167    AND grants.GRANTEE_ORIG_SYSTEM_ID =  party.party_id
4168    AND (
4169     (grants.GRANTEE_ORIG_SYSTEM = 'HZ_PARTY' AND grants.grantee_type ='USER' AND party.party_type= 'PERSON')
4170         OR (grants.GRANTEE_ORIG_SYSTEM = 'HZ_GROUP' AND grants.grantee_type ='GROUP' AND party.party_type= 'GROUP')
4171        )
4172    AND grants.start_date <= SYSDATE
4173    AND NVL(grants.end_date, SYSDATE+1) >= TRUNC(SYSDATE)
4174    AND grants.instance_type= 'SET'
4175    AND grants.menu_id = cp_assignee_role_id
4176    AND grants.instance_set_id IN ( SELECT instance_set.instance_set_id
4177                    FROM fnd_object_instance_sets instance_set
4178                    WHERE instance_set.object_id = grants.object_id
4179                    AND instance_set.instance_set_name = 'EGO_ORG_ITEM_' ||cp_org_id)
4180    AND ROWNUM = 1;
4181 
4182    -- Bug No: 4327218
4183    -- Modified query to refer to 'person_party_id' instead of 'customer_id'
4184    CURSOR c_user_name(v_party_id IN NUMBER) IS
4185    SELECT us.user_name FROM fnd_user us, hz_parties pa
4186    WHERE ((us.employee_id IS NOT NULL AND us.employee_id = pa.person_identifier))
4187    AND pa.party_id = v_party_id
4188    union all
4189    SELECT us.user_name
4190    FROM fnd_user us, hz_parties pa
4191    WHERE (us.employee_id IS NULL AND (us.person_party_id = pa.party_id or (us.person_party_id is null and us.supplier_id = pa.party_id)))
4192    AND pa.party_id = v_party_id;
4193 
4194 BEGIN
4195     l_return_status := FND_API.G_RET_STS_SUCCESS;
4196     --
4197     -- Check if the change header has already been propagated
4198     --
4199     Propagated_Local_Change(
4200         p_change_id             => p_change_id
4201       , p_local_organization_id => p_local_organization_id
4202       , x_local_change_id       => l_local_change_id
4203      );
4204     --
4205     -- If propagated local change exists , then the header processing will
4206     -- not continue . Return control to calling program .
4207     --
4208     IF l_local_change_id IS NOT NULL
4209     THEN
4210         Error_Handler.Add_Error_Token(
4211             p_Message_Name       => 'ENG_PRP_ECO_PROPAGATED'
4212           , p_Mesg_Token_Tbl     => x_Mesg_Token_Tbl
4213           , x_Mesg_Token_Tbl     => x_Mesg_Token_Tbl
4214           , p_Token_Tbl          => l_token_tbl
4215           , p_message_type       => 'W'
4216          );
4217         RETURN;
4218     END IF;
4219 
4220     --
4221     -- Check if the change order already exists in the organization
4222     -- with the same change_notice value. Then raise an error
4223     --
4224     Check_Change_Existance(
4225         p_change_notice       => p_change_notice
4226       , p_organization_id     => p_local_organization_id
4227       , x_Mesg_Token_Tbl      => l_mesg_token_tbl
4228       , x_Return_Status       => l_return_status
4229      );
4230     IF l_return_status = FND_API.G_RET_STS_ERROR
4231     THEN
4232         RAISE EXC_EXP_SKIP_OBJECT;
4233     END IF;
4234 
4235     FOR eco_rec IN c_eco_rec  -- Loop 1
4236     LOOP
4237         IF (eco_rec.status_type IS NOT NULL AND eco_rec.status_type = 5)       /* Cancelled ECO check */
4238         THEN
4239             RAISE EXC_EXP_SKIP_OBJECT;
4240         END IF;
4241 
4242         IF (eco_rec.change_order_type_id IS NOT NULL)
4243         THEN
4244             -- Changes for bug 3544760
4245             -- Fetching the change category name also
4246             SELECT ecotv.CHANGE_ORDER_TYPE
4247                  , ecmtv.name
4248                  , ecotv.default_assignee_type
4249                  , ecotv.default_assignee_id
4250               INTO l_change_type_code
4251                  , l_change_mgmt_type
4252                  , l_default_assignee_type
4253                  , l_assignee_role_id
4254               FROM eng_change_order_types_v ecotv
4255                  , eng_change_mgmt_types_vl ecmtv
4256              WHERE ecotv.change_order_type_id = eco_rec.change_order_type_id
4257                AND ecotv.CHANGE_MGMT_TYPE_CODE = ecmtv.CHANGE_MGMT_TYPE_CODE;
4258         ELSE
4259             l_change_type_code := NULL;
4260             l_change_mgmt_type := NULL; -- bug 3544760
4261         END IF;
4262 
4263         IF (eco_rec.responsible_organization_id IS NOT NULL)
4264         THEN
4265             SELECT name
4266             INTO   l_department_name
4267             FROM   hr_all_organization_units
4268             WHERE  organization_id = eco_rec.responsible_organization_id;
4269         ELSE
4270             l_department_name := NULL;
4271         END IF;
4272 
4273         IF (eco_rec.requestor_id IS NOT NULL)
4274         THEN
4275             BEGIN
4276                 OPEN c_user_name(eco_rec.requestor_id);
4277                 FETCH c_user_name INTO l_requestor_name;
4278                 CLOSE c_user_name;
4279             EXCEPTION
4280             WHEN NO_DATA_FOUND THEN
4281                 FND_FILE.PUT_LINE(FND_FILE.LOG,
4282                                   'No_Data_found for requestor id '
4283                                   || to_char( eco_rec.requestor_id)
4284                                   || ' in org ' || to_char(p_organization_id));
4285                 l_requestor_name := NULL;
4286             END;
4287         ELSE
4288             l_requestor_name := NULL;
4289         END IF;
4290 
4291         IF (eco_rec.PROJECT_ID IS NOT NULL)
4292         THEN
4293             BEGIN
4294                 SELECT name
4295                 into   l_Project_Number
4296                 FROM   pa_projects_all
4297                 WHERE  project_id = eco_rec.PROJECT_ID;
4298             EXCEPTION
4299             WHEN NO_DATA_FOUND THEN
4300                 FND_FILE.PUT_LINE(FND_FILE.LOG,'No_Data_found for project id ' || to_char( eco_rec.PROJECT_ID));
4301                 l_Project_Number := NULL;
4302             END;
4303         ELSE
4304             l_Project_Number := NULL;
4305         END IF;
4306 
4307         IF (eco_rec.TASK_ID IS NOT NULL)
4308         THEN
4309             BEGIN
4310                 SELECT task_number
4311                 INTO   l_Task_Number
4312                 FROM   pa_tasks
4313                 WHERE  TASK_ID = eco_rec.TASK_ID;
4314             EXCEPTION
4315             WHEN NO_DATA_FOUND THEN
4316                 FND_FILE.PUT_LINE(FND_FILE.LOG,'No_Data_found for task id ' || to_char( eco_rec.TASK_ID));
4317                 l_Task_Number := NULL;
4318             END;
4319         ELSE
4320             l_Task_Number := NULL;
4321         END IF;
4322 
4323         IF(eco_rec.PROJECT_ID IS NOT NULL AND eco_rec.TASK_ID IS NOT NULL)
4324         THEN
4325             BEGIN
4326                 SELECT PPE.ELEMENT_NUMBER
4327                 INTO l_task_number1
4328                 FROM PA_PROJ_ELEMENTS PPE
4329                 WHERE PPE.PROJECT_ID = Eco_rec.PROJECT_ID
4330                 AND PPE.PROJ_ELEMENT_ID = Eco_rec.TASK_ID;
4331             EXCEPTION
4332             WHEN NO_DATA_FOUND THEN
4333                 l_task_number1 := NULL;
4334             END;
4335         ELSE
4336              l_task_number1 := NULL;
4337         END IF;
4338 
4339         /* check whether the local organization eco needs to be scheduled immediately */
4340         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Processing ECO Fetch status..' );
4341         BEGIN
4342             SELECT 1
4343             INTO l_sched_immediately
4344             FROM ENG_ORG_HIERARCHY_POLICIES
4345             WHERE organization_id = p_local_organization_id
4346             AND SCHEDULE_IMMEDIATELY_FLAG = 'Y'
4347             AND change_type_org_hierarchy_id =
4348                   (SELECT change_type_org_hierarchy_id
4349                    FROM ENG_TYPE_ORG_HIERARCHIES
4350                    WHERE change_type_id = l_change_type_id
4351                    AND organization_id = p_organization_id
4352                    AND hierarchy_id = (SELECT organization_structure_id
4353                            FROM per_organization_structures
4354                            WHERE name = p_org_hierarchy_name));
4355         EXCEPTION
4356         WHEN NO_DATA_FOUND THEN
4357             l_sched_immediately  := 0;
4358         END;
4359 
4360         IF (l_sched_immediately = 1)
4361         THEN
4362              --
4363              -- To be handled differently wrt init lifecycle
4364              -- The status to the BO for processing the header should be draft in all cases
4365              --
4366              null;
4367         END IF;
4368         -- Fetch status details
4369         SELECT ecs.status_name
4370           INTO l_status_name
4371           FROM eng_change_statuses_vl ecs
4372          WHERE ecs.status_code = 0;
4373 
4374         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Status = ' || l_status_name);
4375 
4376         ENGECOBO.GLOBAL_CHANGE_ID := p_change_id;
4377         ENGECOBO.GLOBAL_ORG_ID := eco_rec.organization_id;
4378 
4379         -- Fetch change subjects
4380         BEGIN
4381             FND_FILE.PUT_LINE(FND_FILE.LOG, 'Processing Subject .. ');
4382 
4383             l_header_subject_exists := 1;
4384 
4385             select sub1.pk1_value, sub1.pk2_value, sub2.pk3_value, sub2.entity_name
4386             INTO l_pk1_value, l_pk2_value, l_pk3_value, l_entity_name
4387             from eng_change_subjects sub1,eng_change_subjects sub2
4388             where sub1.change_id = sub2.change_id
4389             and sub1.change_id = p_change_id
4390             and sub1.change_line_id is null
4391             and sub2.change_line_id is null
4392             and sub1.entity_name = 'EGO_ITEM'
4393             and ((sub2.entity_name = 'EGO_ITEM_REVISION' and sub2.subject_level =1 and sub1.subject_level=2 )
4394             or (sub2.entity_name = sub1.entity_name and sub2.subject_level = sub1.subject_level and sub1.subject_level=1 ))
4395             and rownum =1;
4396         EXCEPTION
4397         WHEN NO_DATA_FOUND THEN
4398             l_header_subject_exists := 0;
4399         END;
4400 
4401         IF (l_header_subject_exists = 1)
4402         THEN
4403             FND_FILE.PUT_LINE(FND_FILE.LOG, 'Processing Subject 2.. ');
4404             --
4405             -- Setting Pk1 Value
4406             IF (l_pk1_value IS NOT NULL)
4407             THEN
4408                 BEGIN
4409                     SELECT concatenated_segments
4410                     INTO   l_pk1_name
4411                     FROM   mtl_system_items_b_kfv
4412                     WHERE  inventory_item_id = l_pk1_value
4413                     AND    organization_id   = p_local_organization_id;
4414                 EXCEPTION
4415                 WHEN NO_DATA_FOUND THEN
4416                     l_return_status := FND_API.G_RET_STS_ERROR;
4417                     Error_Handler.Add_Error_Token(
4418                         p_Message_Name       => 'ENG_PRP_SUBJECT_ITEM_INVALID'
4419                       , p_Mesg_Token_Tbl     => l_mesg_token_tbl
4420                       , x_Mesg_Token_Tbl     => l_mesg_token_tbl
4421                       , p_Token_Tbl          => l_token_tbl
4422                      );
4423                     RAISE EXC_EXP_SKIP_OBJECT;
4424                 END;
4425             END IF;
4426             --
4427             -- Setting Pk2 Value
4428             l_pk2_name := p_local_organization_code;
4429             --
4430             -- Setting Pk3 Value
4431             IF (l_entity_name = 'EGO_ITEM_REVISION' AND l_invalid_subject <> 1
4432                AND l_pk1_value IS NOT NULL AND l_pk3_value IS NOT NULL)
4433             THEN
4434                 BEGIN
4435                     select revision
4436                     into l_pk3_name
4437                     from mtl_item_revisions
4438                     where inventory_item_id = l_pk1_value
4439                     AND    organization_id = p_local_organization_id
4440                     and revision = ( select revision
4441                             from mtl_item_revisions
4442                             where revision_id = l_pk3_value);
4443                 EXCEPTION
4444                 WHEN NO_DATA_FOUND THEN
4445                     l_return_status := FND_API.G_RET_STS_ERROR;
4446 
4447                     l_token_tbl(1).token_name  := 'ITEM';
4448                     l_token_tbl(1).token_value := l_pk1_name;
4449 
4450                     Error_Handler.Add_Error_Token(
4451                         p_Message_Name       => 'ENG_PRP_SUBJECT_REV_INVALID'
4452                       , p_Mesg_Token_Tbl     => l_mesg_token_tbl
4453                       , x_Mesg_Token_Tbl     => l_mesg_token_tbl
4454                       , p_Token_Tbl          => l_token_tbl
4455                      );
4456                     RAISE EXC_EXP_SKIP_OBJECT;
4457                 END;
4458             END IF;
4459         END IF;
4460 
4461         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Processing Subject Status  ' || l_invalid_subject);
4462 
4463         -- Changes for bug 3547805
4464         -- Assignee Name Processing
4465         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Processing Assignee ..');
4466         l_party_id := eco_rec.assignee_id;
4467         l_assignee_name := NULL ;
4468         BEGIN
4469             -- if subject item is not null then process the role based assignee types
4470             IF (l_pk1_value IS NOT NULL AND l_assignee_role_id IS NOT NULL AND l_default_assignee_type IS NOT NULL)
4471             THEN
4472                 -- Process role based types
4473                 FND_FILE.PUT_LINE(FND_FILE.LOG, 'Processing Assignee Roles..');
4474                 IF (l_default_assignee_type = 'EGO_ITEM')
4475                 THEN
4476                     OPEN c_item_assignee(l_assignee_role_id , l_pk1_value , p_local_organization_id );
4477                     FETCH c_item_assignee INTO l_party_id, l_assignee_name, l_party_type;
4478                     CLOSE c_item_assignee;
4479                 ELSIF (l_default_assignee_type = 'EGO_CATALOG_GROUP')
4480                 THEN
4481                     OPEN c_category_item_assignee(l_assignee_role_id , l_pk1_value , p_local_organization_id );
4482                     FETCH c_category_item_assignee INTO l_party_id, l_assignee_name, l_party_type;
4483                     CLOSE c_category_item_assignee;
4484                 ELSIF (l_default_assignee_type = 'ENG_CHANGE')
4485                 THEN
4486                     OPEN c_org_assignee(l_assignee_role_id , p_local_organization_id );
4487                     FETCH c_org_assignee INTO l_party_id, l_assignee_name, l_party_type;
4488                     CLOSE c_org_assignee;
4489                 END IF;
4490             END IF;
4491 
4492             -- For all other cases and if role based type has person as assignee then
4493             -- Fetch the assignee name
4494             IF (l_party_id IS NOT NULL AND (l_party_type IS NULL OR l_party_type <> 'GROUP'))
4495             THEN
4496                 OPEN c_user_name(l_party_id);
4497                 FETCH c_user_name INTO l_assignee_name;
4498                 IF c_user_name%NOTFOUND
4499                 THEN
4500                     OPEN c_group_name(l_party_id);
4501                     FETCH c_group_name INTO l_assignee_name;
4502                     CLOSE c_group_name;
4503                 END IF;
4504                 CLOSE c_user_name;
4505             END IF;
4506         EXCEPTION
4507         WHEN OTHERS THEN
4508             IF c_item_assignee%ISOPEN THEN
4509                 CLOSE c_item_assignee;
4510             END IF;
4511             IF c_category_item_assignee%ISOPEN THEN
4512                 CLOSE c_category_item_assignee;
4513             END IF;
4514             IF c_org_assignee%ISOPEN THEN
4515                 CLOSE c_org_assignee;
4516             END IF;
4517             IF c_user_name%ISOPEN THEN
4518                 CLOSE c_user_name;
4519             END IF;
4520             IF c_user_name%ISOPEN THEN
4521                 CLOSE c_user_name;
4522             END IF;
4523             l_assignee_name := null;
4524         END;
4525          -- End changes for bug 3547805
4526 
4527         FND_FILE.PUT_LINE(FND_FILE.LOG, 'Population ECO Header Info.. ');
4528          /*  Popuating PL/SQL record for ECO Header    */
4529         l_eco_rec.eco_name := eco_rec.change_notice;
4530         l_eco_rec.organization_code := p_local_organization_code;
4531         l_eco_rec.change_type_code := l_change_type_code;
4532         l_eco_rec.status_name := l_status_name;
4533         l_eco_rec.eco_department_name := l_department_name;
4534         l_eco_rec.priority_code := eco_rec.priority_code;
4535         -- l_eco_rec.approval_list_name := l_approval_list_name;
4536         -- l_eco_rec.Approval_Status_Name := l_approval_status;
4537         -- Bug 3897954:For PLM records, the master org approval status will
4538         -- not be propagated as PLM ECOs are always created with an initialized
4539         -- lifecycle by ECO BO.
4540         l_eco_rec.reason_code := eco_rec.reason_code;
4541         l_eco_rec.eng_implementation_cost := eco_rec.estimated_eng_cost;
4542         l_eco_rec.mfg_implementation_cost := eco_rec.estimated_mfg_cost;
4543         l_eco_rec.cancellation_comments := eco_rec.cancellation_comments;
4544         l_eco_rec.requestor :=  l_requestor_name;
4545         l_eco_rec.assignee :=  l_assignee_name;
4546         l_eco_rec.description := eco_rec.description;
4547         l_eco_rec.attribute_category := eco_rec.attribute_category;
4548         l_eco_rec.attribute1  := eco_rec.attribute1;
4549         l_eco_rec.attribute2  := eco_rec.attribute2;
4550         l_eco_rec.attribute3  := eco_rec.attribute3;
4551         l_eco_rec.attribute4  := eco_rec.attribute4;
4552         l_eco_rec.attribute5  := eco_rec.attribute5;
4553         l_eco_rec.attribute6  := eco_rec.attribute6;
4554         l_eco_rec.attribute7  := eco_rec.attribute7;
4555         l_eco_rec.attribute8  := eco_rec.attribute8;
4556         l_eco_rec.attribute9  := eco_rec.attribute9;
4557         l_eco_rec.attribute10  := eco_rec.attribute10;
4558         l_eco_rec.attribute11  := eco_rec.attribute11;
4559         l_eco_rec.attribute12  := eco_rec.attribute12;
4560         l_eco_rec.attribute13  := eco_rec.attribute13;
4561         l_eco_rec.attribute14  := eco_rec.attribute14;
4562         l_eco_rec.attribute15  := eco_rec.attribute15;
4563          -- l_eco_rec.Original_System_Reference := eco_rec.Original_System_Reference;
4564         l_eco_rec.Project_Name := l_project_number;
4565         l_eco_rec.Task_Number := l_Task_Number1;
4566          --l_eco_rec.hierarchy_flag := 2;
4567         l_eco_rec.organization_hierarchy := NULL;
4568         l_eco_rec.return_status := NULL;
4569 
4570         --lkasturi: 11.5.10 changes
4571 
4572         l_eco_rec.plm_or_erp_change := 'PLM';
4573         l_eco_rec.pk1_name := l_pk1_name;
4574         l_eco_rec.pk2_name := l_pk2_name;
4575         l_eco_rec.pk3_name := l_pk3_name;
4576         l_eco_rec.change_management_type := l_change_mgmt_type; -- Bug 3544760
4577         --lkasturi: 11.5.10 end changes
4578         l_eco_rec.transaction_type := 'CREATE';
4579         -- Fetch ECO Revisions
4580         i := 1;
4581         FOR rev IN c_eco_revision
4582         LOOP
4583             FND_FILE.PUT_LINE(FND_FILE.LOG,'Processing ECO Revision ...');
4584             l_eco_revision_tbl(i).eco_name := rev.change_notice;
4585             l_eco_revision_tbl(i).organization_code:= p_local_organization_code;
4586             l_eco_revision_tbl(i).revision := rev.revision;
4587             -- l_eco_revision_tbl(i).new_revision := rev.new_revision;
4588             l_eco_revision_tbl(i).new_revision := NULL;
4589             l_eco_revision_tbl(i).Attribute_category := rev.Attribute_category;
4590             l_eco_revision_tbl(i).attribute1  := rev.attribute1;
4591             l_eco_revision_tbl(i).attribute2  := rev.attribute2;
4592             l_eco_revision_tbl(i).attribute3  := rev.attribute3;
4593             l_eco_revision_tbl(i).attribute4  := rev.attribute4;
4594             l_eco_revision_tbl(i).attribute5  := rev.attribute5;
4595             l_eco_revision_tbl(i).attribute6  := rev.attribute6;
4596             l_eco_revision_tbl(i).attribute7  := rev.attribute7;
4597             l_eco_revision_tbl(i).attribute8  := rev.attribute8;
4598             l_eco_revision_tbl(i).attribute9  := rev.attribute9;
4599             l_eco_revision_tbl(i).attribute10  :=rev.attribute10;
4600             l_eco_revision_tbl(i).attribute11  :=rev.attribute11;
4601             l_eco_revision_tbl(i).attribute12  :=rev.attribute12;
4602             l_eco_revision_tbl(i).attribute13  := rev.attribute13;
4603             l_eco_revision_tbl(i).attribute14  := rev.attribute14;
4604             l_eco_revision_tbl(i).attribute15  := rev.attribute15;
4605             l_eco_revision_tbl(i).Original_System_Reference := rev.Original_System_Reference;
4606             l_eco_revision_tbl(i).comments := rev.comments;
4607             l_eco_revision_tbl(i).return_status := NULL;
4608             l_eco_revision_tbl(i).transaction_type := 'CREATE';
4609             i := i + 1;
4610         END LOOP; -- End rev IN c_eco_revision
4611     END LOOP;
4612 
4613     -- Process Header and ECO Revisions
4614     Eng_Eco_Pub.Process_Eco(
4615         p_api_version_number   => 1.0
4616       , p_init_msg_list        => FALSE
4617       , x_return_status        => l_return_status
4618       , x_msg_count            => l_msg_count
4619       , p_bo_identifier        => 'ECO'
4620       , p_ECO_rec              => l_eco_rec
4621       , p_eco_revision_tbl     => l_eco_revision_tbl
4622       , x_ECO_rec              => l_eco_rec
4623       , x_eco_revision_tbl     => l_eco_revision_tbl
4624       , x_change_line_tbl      => l_change_lines_tbl
4625       , x_revised_item_tbl     => l_revised_item_tbl
4626       , x_rev_component_tbl    => l_rev_component_tbl
4627       , x_sub_component_tbl    => l_sub_component_tbl
4628       , x_ref_designator_tbl   => l_ref_designator_tbl
4629       , x_rev_operation_tbl    => l_rev_operation_tbl
4630       , x_rev_op_resource_tbl  => l_rev_op_resource_tbl
4631       , x_rev_sub_resource_tbl => l_rev_sub_resource_tbl
4632      );
4633     Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'After Propagation ECO l_return_status'|| l_return_status);
4634 
4635     IF l_return_status = FND_API.G_RET_STS_SUCCESS
4636     THEN
4637 
4638         Eco_Error_Handler.Log_Error(
4639             p_error_status         => FND_API.G_RET_STS_SUCCESS
4640           , p_error_scope          => Error_Handler.G_SCOPE_RECORD
4641           , p_error_level          => Eco_Error_Handler.G_ECO_LEVEL
4642           , p_other_message        => 'ENG_PRP_CHG_ORDER_SUCC'
4643           , p_other_status         => l_return_status
4644           , p_other_token_tbl      => l_token_tbl
4645           , x_eco_rec              => l_eco_rec
4646           , x_eco_revision_tbl     => l_eco_revision_tbl
4647           , x_change_line_tbl      => l_change_lines_tbl -- Eng Change
4648           , x_revised_item_tbl     => l_revised_item_tbl
4649           , x_rev_component_tbl    => l_rev_component_tbl
4650           , x_ref_designator_tbl   => l_ref_designator_tbl
4651           , x_sub_component_tbl    => l_sub_component_tbl
4652           , x_rev_operation_tbl    => l_rev_operation_tbl         --L1
4653           , x_rev_op_resource_tbl  => l_rev_op_resource_tbl  --L1
4654           , x_rev_sub_resource_tbl => l_rev_sub_resource_tbl --L1
4655          );
4656         COMMIT;
4657     ELSE
4658         RAISE EXC_EXP_SKIP_OBJECT;
4659     END IF;
4660 
4661 EXCEPTION
4662 WHEN EXC_EXP_SKIP_OBJECT THEN
4663     --
4664     -- Rollback any changes that may have been made to the DB
4665     --
4666     ROLLBACK;
4667     -- Set the return status
4668     l_return_status := FND_API.G_RET_STS_ERROR;
4669     -- Log any messages that have been logged with the additional error
4670     -- message into error handler
4671     Eco_Error_Handler.Log_Error(
4672         p_error_status         => l_return_status
4673       , p_mesg_token_tbl       => l_mesg_token_tbl
4674       , p_error_scope          => Error_Handler.G_SCOPE_RECORD
4675       , p_error_level          => Eco_Error_Handler.G_ECO_LEVEL
4676       , p_other_message        => 'ENG_PRP_CHG_ORDER_ERR'
4677       , p_other_status         => l_return_status
4678       , p_other_token_tbl      => l_token_tbl
4679       , x_eco_rec              => l_eco_rec
4680       , x_eco_revision_tbl     => l_eco_revision_tbl
4681       , x_change_line_tbl      => l_change_lines_tbl -- Eng Change
4682       , x_revised_item_tbl     => l_revised_item_tbl
4683       , x_rev_component_tbl    => l_rev_component_tbl
4684       , x_ref_designator_tbl   => l_ref_designator_tbl
4685       , x_sub_component_tbl    => l_sub_component_tbl
4686       , x_rev_operation_tbl    => l_rev_operation_tbl         --L1
4687       , x_rev_op_resource_tbl  => l_rev_op_resource_tbl  --L1
4688       , x_rev_sub_resource_tbl => l_rev_sub_resource_tbl --L1
4689      );
4690 
4691     Eng_Propagation_Log_Util.add_entity_map(
4692         p_change_id                 => p_change_id
4693       , p_local_organization_id     => p_local_organization_id
4694       , p_entity_name               => Eng_Propagation_Log_Util.G_ENTITY_CHANGE
4695       , p_entity_action_status      => Eng_Propagation_Log_Util.G_PRP_PRC_STS_ERROR
4696       , p_bo_entity_identifier      => 'ECO'--Eco_Error_Handler.G_ECO_LEVEL
4697      );
4698 
4699 -- WHEN OTHERS THEN
4700 -- LK: Do we need to handle this here ?
4701 END Propagate_Change_Header;
4702 
4703 FUNCTION Inventory_Status_Control_Level
4704 RETURN NUMBER
4705 IS
4706     CURSOR c_status_control_attribute IS
4707     SELECT control_level
4708       FROM MTL_ITEM_ATTRIBUTES
4709      WHERE ATTRIBUTE_NAME = 'MTL_SYSTEM_ITEMS.INVENTORY_ITEM_STATUS_CODE';
4710 BEGIN
4711 
4712    IF G_STATUS_CONTROL_LEVEL IS NULL
4713    THEN
4714        OPEN c_status_control_attribute;
4715        FETCH c_status_control_attribute INTO G_STATUS_CONTROL_LEVEL;
4716        CLOSE c_status_control_attribute;
4717    END IF;
4718    RETURN G_STATUS_CONTROL_LEVEL;
4719 
4720 END Inventory_Status_Control_Level;
4721 
4722 
4723 PROCEDURE Propagate_Revised_Item (
4724     p_revised_item_sequence_id IN NUMBER
4725   , p_change_id                IN NUMBER
4726   , p_change_notice            IN VARCHAR2
4727   , p_organization_code        IN VARCHAR2
4728   , p_organization_id          IN NUMBER
4729   , p_local_organization_code  IN VARCHAR2
4730   , p_local_organization_id    IN NUMBER
4731   , p_commit                   IN VARCHAR2
4732   , x_Return_Status            OUT NOCOPY VARCHAR2
4733 ) IS
4734 
4735     l_transfer_item_enable  NUMBER;
4736     l_error_logged          NUMBER;
4737     --l_attach_error_logged   NUMBER;
4738     l_sourcing_rules_exists NUMBER;
4739     --l_propagated_rev_items_tbl  Prop_Rev_Items_Tbl_Type;
4740     --l_prop_rev_items_count      NUMBER;
4741     l_propagate_revised_item    NUMBER;
4742     l_parent_revised_item_name  mtl_system_items_vl.concatenated_segments%TYPE;
4743     l_use_up_plan_name          mrp_bom_plan_name_lov_v.plan_name%TYPE;
4744     l_revised_item_number       mtl_system_items_vl.concatenated_segments%TYPE;
4745     l_use_up_item_name          mtl_system_items_vl.concatenated_segments%TYPE;
4746     l_revised_item_name         mtl_system_items_vl.concatenated_segments%TYPE;
4747     l_new_item_revision         mtl_item_revisions.revision%TYPE;
4748     l_new_struc_revision        VARCHAR2(3);
4749     l_current_struc_revision    VARCHAR2(3);
4750     l_from_end_item_name        mtl_system_items_vl.concatenated_segments%TYPE;
4751     l_from_end_item_alternate   VARCHAR2(10);
4752     l_from_end_item_revision    mtl_item_revisions.revision%TYPE;
4753     l_current_local_revision_id NUMBER;
4754     l_current_local_revision    VARCHAR2(3);
4755     l_current_lifecycle_seq     NUMBER;
4756     l_current_lifecycle_name    VARCHAR2(150);
4757     l_new_lifecycle_seq         NUMBER;
4758     l_new_lifecycle_name        VARCHAR2(150);
4759     l_new_revision_exists       NUMBER;
4760     l_status_master_controlled  NUMBER;
4761     l_sql_stmt                  VARCHAR2(2000);
4762     l_revised_item_count        NUMBER := 1;
4763     l_local_bill_sequence_id    NUMBER;
4764     l_rev_description           mtl_item_revisions.description%type;
4765     l_structure_exists_flag     NUMBER;
4766     l_rev_item_status_type      NUMBER;
4767     l_new_item_revision_exists  NUMBER;
4768     l_from_end_item_minor_rev   VARCHAR2(3);
4769     l_disable_revision          NUMBER;
4770     l_propagate_strc_changes    NUMBER;
4771     l_structure_type_name       VARCHAR2(80);
4772     l_local_line_rev_id       NUMBER;
4773 
4774     l_attach_return_status  VARCHAR2(1);
4775     l_Mesg_token_Tbl        Error_Handler.Mesg_Token_Tbl_Type;
4776     l_bo_mesg_token_tbl     Error_Handler.Mesg_Token_Tbl_Type;
4777     l_return_status         VARCHAR2(1);
4778     l_err_text              VARCHAR2(2000);
4779     l_Token_Tbl             Error_Handler.Token_Tbl_Type;
4780     l_msg_count             NUMBER;
4781 
4782     l_eco_rec               Eng_Eco_Pub.Eco_Rec_Type;
4783     l_change_lines_tbl      Eng_Eco_Pub.Change_Line_Tbl_Type;
4784     l_eco_revision_tbl      Eng_Eco_Pub.Eco_Revision_Tbl_Type;
4785     l_revised_item_tbl      Eng_Eco_Pub.Revised_Item_Tbl_Type;
4786     l_rev_component_tbl     Bom_Bo_Pub.Rev_Component_Tbl_Type;
4787     l_sub_component_tbl     Bom_Bo_Pub.Sub_Component_Tbl_Type;
4788     l_ref_designator_tbl    Bom_Bo_Pub.Ref_Designator_Tbl_Type;
4789     l_rev_operation_tbl     Bom_Rtg_Pub.Rev_Operation_Tbl_Type;
4790     l_rev_op_resource_tbl   Bom_Rtg_Pub.Rev_Op_Resource_Tbl_Type;
4791     l_rev_sub_resource_tbl  Bom_Rtg_Pub.Rev_Sub_Resource_Tbl_Type;
4792     l_revised_item_unexp_rec  Eng_Eco_Pub.Rev_Item_Unexposed_Rec_Type;
4793 
4794     CURSOR c_revised_items_data IS
4795     SELECT use_up_item_id
4796          , revised_item_id
4797          , enable_item_in_local_org
4798          , transfer_or_copy
4799          , transfer_or_copy_item
4800          , alternate_bom_designator
4801          , revised_item_sequence_id
4802       FROM eng_revised_items
4803      WHERE revised_item_sequence_id = p_revised_item_sequence_id;
4804 
4805     l_ris c_revised_items_data%ROWTYPE;
4806 
4807    -- The following cursor will return only one revised item
4808    -- Changes to design of handling component changes
4809    -- will have to be done otherwise
4810    CURSOR c_rev_items_all (cp_revised_item_sequence_id NUMBER)
4811    IS
4812    SELECT *
4813      FROM eng_revised_items
4814     WHERE (revised_item_sequence_id = cp_revised_item_sequence_id)
4815            /*OR parent_revised_item_seq_id = cp_revised_item_sequence_id)
4816       AND revised_item_sequence_id NOT IN
4817                (SELECT revised_item_sequence_id
4818                   FROM eng_revised_items
4819                  WHERE parent_revised_item_seq_id = cp_revised_item_sequence_id
4820                    AND (transfer_or_copy = 'L' OR transfer_or_copy = 'O')
4821                    AND 1 = l_status_master_controlled
4822                 )
4823    ORDER BY parent_revised_item_seq_id DESC*/;
4824 
4825   -- Cursor to pick up Revised component records for the top organization for
4826   -- the given change notice which have the ACD_type of Disable and have been
4827   -- implemented from eng_revised_items table. These records are not present in
4828   -- bom_inventory_components table hence this extra cursor.
4829 
4830    CURSOR c_plm_rev_comps_disable (cp_revised_item_sequence_id NUMBER)
4831    IS
4832    SELECT *
4833    FROM   eng_revised_components erc
4834    WHERE  erc.change_notice = p_change_notice
4835    AND    erc.ACD_TYPE = 3
4836    AND    erc.revised_item_sequence_id = cp_revised_item_sequence_id
4837    AND    NOT EXISTS (SELECT 1 FROM eng_change_propagation_maps ecpm
4838                       WHERE ecpm.change_id = p_change_id
4839                       AND ecpm.local_organization_id = p_local_organization_id
4840                       AND ecpm.revised_line_type = Eng_Propagation_Log_Util.G_REV_LINE_CMP_CHG
4841                       AND ecpm.revised_line_id1 = erc.component_sequence_id
4842                       AND ecpm.entity_action_status IN (3,4))
4843    AND EXISTS (SELECT 1 FROM eng_revised_items eri
4844                 WHERE eri.revised_item_sequence_id = erc.revised_item_sequence_id
4845                   AND eri.bill_sequence_id = erc.bill_sequence_id);
4846 
4847 
4848    -- Cursor to Pick all Revised Component Items for the Top Organization  for the
4849    -- given Change Notice
4850 
4851    CURSOR c_plm_rev_comps (cp_revised_item_sequence_id NUMBER)  IS
4852    SELECT *
4853    FROM   bom_components_b bcb
4854    WHERE  change_notice = p_change_notice
4855    AND    revised_item_sequence_id = cp_revised_item_sequence_id
4856    AND    NOT EXISTS (SELECT 1 FROM eng_change_propagation_maps ecpm
4857                       WHERE ecpm.change_id = p_change_id
4858                       AND ecpm.local_organization_id = p_local_organization_id
4859                       AND ecpm.revised_line_type = Eng_Propagation_Log_Util.G_REV_LINE_CMP_CHG
4860                       AND ecpm.revised_line_id1 = bcb.component_sequence_id
4861                       AND ecpm.entity_action_status IN (3,4))
4862    AND EXISTS (SELECT 1 FROM eng_revised_items eri
4863                 WHERE eri.revised_item_sequence_id = bcb.revised_item_sequence_id
4864                   AND eri.bill_sequence_id = bcb.bill_sequence_id);
4865 
4866 BEGIN
4867     Eng_Propagation_Log_Util.Debug_Log(G_LOG_PROC, 'Propagate_Revised_Item.BEGIN');
4868     -- Step 1:
4869     -- Initialize
4870     l_propagate_revised_item := G_VAL_TRUE;
4871     l_transfer_item_enable := G_VAL_FALSE;
4872     l_sourcing_rules_exists := 2;
4873     -- Set Savepoint
4874     SAVEPOINT BEGIN_REV_ITEM_PROCESSING;
4875     -- Error Handling
4876     l_return_status := FND_API.G_RET_STS_SUCCESS;
4877     l_error_logged := G_VAL_FALSE;
4878     l_attach_return_status := FND_API.G_RET_STS_SUCCESS;
4879 
4880     Error_Handler.Initialize;
4881 
4882     IF (l_ris.enable_item_in_local_org = 'Y')
4883     THEN
4884         l_transfer_item_enable := G_VAL_TRUE;
4885         FND_FILE.PUT_LINE(FND_FILE.LOG, ' Enable item in local org .. ' || l_transfer_item_enable);
4886     END IF;
4887     l_status_master_controlled := Inventory_Status_Control_Level;
4888 
4889     OPEN c_revised_items_data;
4890     FETCH c_revised_items_data INTO l_ris;
4891 
4892     -- Step 2:
4893     -- Preprocess Revised Item
4894     -- If Errors then RAISE EXC_EXP_SKIP_OBJECT
4895     Check_Revised_Item_Errors (
4896         p_change_notice          => p_change_notice
4897       , p_global_org_id          => p_organization_id
4898       , p_local_org_id           => p_local_organization_id
4899       , p_rev_item_seq_id        => p_revised_item_sequence_id
4900       , p_revised_item_id        => l_ris.revised_item_id
4901       , p_use_up_item_id         => l_ris.use_up_item_id
4902       , p_transfer_item_enable   => l_transfer_item_enable
4903       , p_transfer_or_copy       => l_ris.transfer_or_copy
4904       , p_transfer_or_copy_item  => l_ris.transfer_or_copy_item
4905       , p_status_master_controlled => l_status_master_controlled
4906       , x_error_logged           => l_error_logged
4907       , x_mesg_token_tbl         => l_mesg_token_tbl
4908       , x_propagate_strc_changes => l_propagate_strc_changes
4909       , x_sourcing_rules_exists  => l_sourcing_rules_exists
4910       , x_revised_item_name      => l_parent_revised_item_name
4911      );
4912     IF l_error_logged = G_VAL_TRUE
4913     THEN
4914         RAISE EXC_EXP_SKIP_OBJECT;
4915     END IF;
4916 
4917     -- Step 3:
4918     -- Populating the l_propagated_rev_items_tbl
4919     --l_prop_rev_items_count := l_prop_rev_items_count + 1;
4920     --l_propagated_rev_items_tbl(l_prop_rev_items_count) := p_revised_item_sequence_id;
4921     -- Step 4: Processing
4922     -- Now get all revised items for this revised item sequence id.
4923     -- This will be used only when the functionality of parent_revised_item_seq_id
4924     -- gets defined. Currently not been scoped.
4925     FOR ri in c_rev_items_all (p_revised_item_sequence_id)
4926     LOOP
4927         Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Start revised item processing p_revised_item_sequence_id'|| p_revised_item_sequence_id);
4928         IF (l_sourcing_rules_exists = 2
4929             OR (l_sourcing_rules_exists = 1 AND ri.parent_revised_item_seq_id IS NULL)
4930             OR (l_sourcing_rules_exists = 1 AND ri.parent_revised_item_seq_id IS NOT NULL AND ri.transfer_or_copy IS NOT NULL))
4931         THEN
4932             -- get the item name, use up item name and plan name
4933             SELECT concatenated_segments
4934               INTO l_revised_item_number
4935               FROM mtl_system_items_b_kfv
4936              WHERE inventory_item_id = ri.revised_item_id
4937                AND organization_id = p_local_organization_id;
4938 
4939             l_use_up_item_name := null;
4940             IF (ri.use_up_item_id IS NOT NULL)
4941             THEN
4942                 SELECT concatenated_segments
4943                 INTO   l_use_up_item_name
4944                 FROM   mtl_system_items_b_kfv
4945                 WHERE  inventory_item_id = ri.use_up_item_id
4946                 AND    organization_id = p_local_organization_id;
4947             END IF;
4948 
4949             IF (ri.use_up_plan_name IS NOT NULL)
4950             THEN
4951                 BEGIN
4952                     SELECT pl.plan_name
4953                     INTO   l_use_up_plan_name
4954                     FROM   mrp_bom_plan_name_lov_v pl
4955                     WHERE  pl.item_id = ri.use_up_item_id
4956                     AND    pl.organization_id = p_local_organization_id
4957                     AND    pl.plan_name = ri.use_up_plan_name;
4958                 EXCEPTION
4959                 WHEN NO_DATA_FOUND THEN
4960                     l_use_up_plan_name := NULL;
4961                 END;
4962             ELSE
4963                 l_use_up_plan_name := NULL;
4964             END IF;
4965 
4966             /* Get current and new item revisions of the item in the local org */
4967             BEGIN
4968                 SELECT BOM_REVISIONS.get_item_revision_fn('ALL', 'ALL', p_local_organization_id,
4969                                                         ri.revised_item_id, SYSDATE) revision ,
4970                        BOM_REVISIONS.get_item_revision_id_fn('ALL', 'ALL', p_local_organization_id,
4971                                                         ri.revised_item_id, SYSDATE) revision_id
4972                 INTO l_current_local_revision, l_current_local_revision_id
4973                 FROM dual;
4974             EXCEPTION
4975             WHEN NO_DATA_FOUND THEN
4976                 l_current_local_revision := NULL;
4977             END;
4978 
4979             l_new_item_revision := ri.new_item_revision;
4980 
4981             IF (l_new_item_revision IS NOT NULL AND l_new_item_revision <> FND_API.G_MISS_CHAR)
4982             THEN
4983                 BEGIN
4984                     select 1
4985                     into l_new_revision_exists
4986                     from mtl_item_revisions
4987                     where revision = l_new_item_revision
4988                     and inventory_item_id = ri.revised_item_id
4989                     and organization_id = p_local_organization_id;
4990                 EXCEPTION
4991                 WHEN NO_DATA_FOUND THEN
4992                     l_new_revision_exists := 0;
4993                 END;
4994 
4995                 IF ((l_new_revision_exists = 1 )
4996                     OR (l_current_local_revision IS NOT NULL AND
4997                         l_new_revision_exists = 0 AND
4998                         l_current_local_revision > l_new_item_revision))
4999                 THEN
5000                     l_new_item_revision := NULL;
5001                 END IF;
5002 
5003             ELSE
5004                 l_new_item_revision := NULL;
5005             END IF;
5006 
5007             IF (FND_PROFILE.VALUE('ENG:ECO_REVISED_ITEM_REVISION') = '1') AND
5008                 (l_new_item_revision IS NULL OR l_new_item_revision = FND_API.G_MISS_CHAR) AND
5009                 ri.new_item_revision IS NOT NULL
5010             THEN
5011               l_token_tbl.delete;
5012 
5013               l_token_tbl(1).token_name  := 'REVISION';
5014               l_token_tbl(1).token_value := ri.new_item_revision;
5015               Error_Handler.Add_Error_Token
5016                         (  p_Message_Name       => 'ENG_NEW_REV_PROP_MISS'
5017                          , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5018                          , x_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
5019                          , p_Token_Tbl          => l_Token_Tbl);
5020 
5021               RAISE EXC_EXP_SKIP_OBJECT;
5022             END IF;
5023 
5024             /* Get current and new item revisions of the structure in the local org */
5025 
5026             l_new_struc_revision := ri.new_structure_revision;
5027             l_current_struc_revision := NULL;
5028 
5029 
5030             IF (ri.CURRENT_STRUCTURE_REV_ID IS NOT NULL)
5031             THEN
5032                 select bill_sequence_id
5033                 into l_local_bill_sequence_id
5034                 FROM BOM_BILL_OF_MATERIALS
5035                 WHERE assembly_item_id = ri.revised_item_id
5036                 AND   organization_id  = p_local_organization_id
5037                 AND   nvl(alternate_bom_designator, 'PRIMARY') = nvl(ri.alternate_bom_designator, 'PRIMARY');
5038 
5039                 l_current_struc_revision := NULL;
5040                 /* not supported in 11.5.10
5041                 BEGIN
5042                     select bsr.revision
5043                     into l_current_struc_revision
5044                     from should use minor revision table  bsr
5045                     where bsr.bill_sequence_id = l_local_bill_sequence_id
5046                     and bsr.object_revision_id = l_current_local_revision_id
5047                     and bsr.effective_date = (select max(effective_date)
5048                             from should use minor revision table
5049                             where structure_revision_id = bsr.structure_revision_id
5050                             and bsr.effective_date < sysdate);
5051                 EXCEPTION
5052                 WHEN NO_DATA_FOUND THEN
5053                     l_current_struc_revision := NULL;
5054                 END;*/
5055                 IF (l_new_struc_revision IS NOT NULL AND l_new_struc_revision <> FND_API.G_MISS_CHAR)
5056                 THEN
5057                     l_new_revision_exists := 0;
5058                     /* not supported in 11.5.10
5059                     BEGIN
5060                         select 1
5061                         into l_new_revision_exists
5062                         from should use minor revision table
5063                         where bill_sequence_id = l_local_bill_sequence_id
5064                         and object_revision_id = l_current_local_revision_id
5065                         and revision = l_new_struc_revision;
5066 
5067                     EXCEPTION
5068                     WHEN NO_DATA_FOUND THEN
5069                         l_new_revision_exists := 0;
5070                     END;*/
5071 
5072                     IF ((l_new_revision_exists = 1 )
5073                         OR (l_current_struc_revision IS NOT NULL AND l_new_revision_exists = 0
5074                             AND l_current_struc_revision > l_new_struc_revision))
5075                     THEN
5076                             l_new_struc_revision := NULL;
5077                     END IF;
5078                 ELSE
5079                     l_new_struc_revision := NULL;
5080                 END IF;
5081             END IF;
5082 
5083             /* get the from end item details */
5084             IF (ri.from_end_item_rev_id IS NOT NULL)
5085             THEN
5086                 select msikfv.concatenated_segments, mir.revision
5087                 into  l_from_end_item_name, l_from_end_item_revision
5088                 from mtl_system_items_b_kfv msikfv, mtl_item_revisions mir
5089                 where mir.revision_id = ri.from_end_item_rev_id
5090                 and mir.inventory_item_id = msikfv.inventory_item_id
5091                 and mir.organization_id = msikfv.organization_id;
5092             END IF;
5093 
5094             /* not supported in 11.5.10
5095             IF (ri.from_end_item_strc_rev_id IS NOT NULL)
5096             THEN
5097                 select bsr.revision, bbm.alternate_bom_designator
5098                 into l_from_end_item_minor_rev, l_from_end_item_alternate
5099                 from should use minor revision table  bsr, bom_bill_of_materials bbm
5100                 where bsr.structure_revision_id = ri.from_end_item_strc_rev_id
5101                 and bsr.bill_sequence_id = bbm.bill_sequence_id;
5102             END IF;*/
5103 
5104             /* Get the current and new item lifecycle phases of the item in the local org */
5105             l_current_lifecycle_name := NULL;
5106             l_new_lifecycle_name := NULL;
5107 
5108             BEGIN
5109                 -- Bug 3311072: Made the query dynamic
5110                 -- Modified By LKASTURI
5111                 l_sql_stmt := 'SELECT LP.DISPLAY_SEQUENCE, LP.NAME      '
5112                 || 'FROM pa_ego_phases_v LP, MTL_System_items_vl msiv        '
5113                 || 'WHERE  LP.PROJ_ELEMENT_ID = msiv.CURRENT_PHASE_ID   '
5114                 || 'AND msiv.INVENTORY_ITEM_ID = :1                     '
5115                 || 'AND msiv.ORGANIZATION_ID =  :2                      ';
5116                 -- End Changes 3311072
5117                 EXECUTE IMMEDIATE l_sql_stmt
5118                 INTO l_current_lifecycle_seq , l_current_lifecycle_name
5119                 USING ri.revised_item_id, p_local_organization_id;
5120 
5121             EXCEPTION
5122             WHEN NO_DATA_FOUND THEN
5123                 l_current_lifecycle_seq := NULL;
5124                 l_current_lifecycle_name := NULL;
5125             END;
5126 
5127             IF (ri.transfer_or_copy IS NOT NULL and ri.transfer_or_copy <> 'C' AND l_status_master_controlled = 2)
5128             THEN
5129                 IF (ri.new_lifecycle_state_id IS NOT NULL)
5130                 THEN
5131                     -- Bug 3311072: Made the query dynamic
5132                     -- Modified By LKASTURI
5133                     l_sql_stmt := 'SELECT LP.DISPLAY_SEQUENCE, LP.NAME      '
5134                     || 'FROM pa_ego_phases_v LP                  '
5135                     || 'WHERE  LP.PROJ_ELEMENT_ID = :1                      ';
5136                     -- End Changes 3311072
5137 
5138                     EXECUTE IMMEDIATE l_sql_stmt
5139                     INTO l_new_lifecycle_seq , l_new_lifecycle_name
5140                     USING ri.new_lifecycle_state_id;
5141 
5142                 ELSE
5143                     l_new_lifecycle_seq := l_current_lifecycle_seq;
5144                     l_new_lifecycle_name := l_current_lifecycle_name;
5145                 END IF;
5146             END IF;
5147 
5148             --Defaulting the structure type name (propagation)
5149             l_structure_type_name := NULL;
5150             BEGIN
5151               SELECT BSTV.structure_type_name
5152               INTO l_structure_type_name
5153               FROM bom_structures_b BSB,
5154                 bom_structure_types_vl BSTV
5155               WHERE BSB.structure_type_id = BSTV.structure_type_id
5156                 AND BSB.bill_sequence_id = ri.bill_sequence_id;
5157 
5158             EXCEPTION
5159             WHEN NO_DATA_FOUND THEN
5160               NULL;
5161             END;
5162 
5163 
5164             l_revised_item_tbl(l_revised_item_count).eco_name := ri.change_notice;
5165             l_revised_item_tbl(l_revised_item_count).organization_code := p_local_organization_code;
5166             l_revised_item_tbl(l_revised_item_count).revised_item_name := l_revised_item_number;
5167             IF (l_new_item_revision IS NULL)
5168             THEN
5169                 l_revised_item_tbl(l_revised_item_count).new_revised_item_revision := NULL;
5170             ELSE
5171                 l_revised_item_tbl(l_revised_item_count).new_revised_item_revision := l_new_item_revision;
5172                 SELECT DESCRIPTION
5173                 INTO   l_rev_description
5174                 FROM   mtl_item_revisions
5175                 WHERE  inventory_item_id = ri.revised_item_id
5176                 AND    organization_id = ri.organization_id
5177                 AND    revision  = l_new_item_revision ;
5178                 l_revised_item_tbl(l_revised_item_count).New_Revised_Item_Rev_Desc := l_rev_description;
5179                 l_revised_item_tbl(l_revised_item_count).Updated_Revised_Item_Revision := NULL;
5180             END IF;
5181             l_revised_item_tbl(l_revised_item_count).start_effective_date := ri.scheduled_date;
5182             l_revised_item_tbl(l_revised_item_count).New_Effective_Date := NULL;
5183             l_revised_item_tbl(l_revised_item_count).alternate_bom_code := ri.alternate_bom_designator;
5184             l_revised_item_tbl(l_revised_item_count).status_type := l_rev_item_status_type;
5185             l_revised_item_tbl(l_revised_item_count).mrp_active := ri.mrp_active;
5186             l_revised_item_tbl(l_revised_item_count).earliest_effective_date := ri.early_schedule_date;
5187             l_revised_item_tbl(l_revised_item_count).use_up_item_name := l_use_up_item_name;
5188             l_revised_item_tbl(l_revised_item_count).use_up_plan_name := l_use_up_plan_name;
5189             l_revised_item_tbl(l_revised_item_count).Requestor := NULL;
5190             l_revised_item_tbl(l_revised_item_count).disposition_type := ri.disposition_type;
5191             l_revised_item_tbl(l_revised_item_count).update_wip := ri.update_wip;
5192             l_revised_item_tbl(l_revised_item_count).cancel_comments := ri.cancel_comments;
5193             --l_revised_item_tbl(l_revised_item_count).cfm_routing_flag := ri.cfm_routing_flag;
5194             l_revised_item_tbl(l_revised_item_count).ctp_flag := ri.ctp_flag;
5195             l_revised_item_tbl(l_revised_item_count).return_status := NULL;
5196             l_revised_item_tbl(l_revised_item_count).change_description := ri.descriptive_text;
5197             l_revised_item_tbl(l_revised_item_count).Attribute_category := ri.Attribute_category;
5198             l_revised_item_tbl(l_revised_item_count).attribute1  := ri.attribute1;
5199             l_revised_item_tbl(l_revised_item_count).attribute2  := ri.attribute2;
5200             l_revised_item_tbl(l_revised_item_count).attribute3  := ri.attribute3;
5201             l_revised_item_tbl(l_revised_item_count).attribute4  := ri.attribute4;
5202             l_revised_item_tbl(l_revised_item_count).attribute5  := ri.attribute5;
5203             l_revised_item_tbl(l_revised_item_count).attribute6  := ri.attribute6;
5204             l_revised_item_tbl(l_revised_item_count).attribute7  := ri.attribute7;
5205             l_revised_item_tbl(l_revised_item_count).attribute8  := ri.attribute8;
5206             l_revised_item_tbl(l_revised_item_count).attribute9  := ri.attribute9;
5207             l_revised_item_tbl(l_revised_item_count).attribute10  := ri.attribute10;
5208             l_revised_item_tbl(l_revised_item_count).attribute11  := ri.attribute11;
5209             l_revised_item_tbl(l_revised_item_count).attribute12  := ri.attribute12;
5210             l_revised_item_tbl(l_revised_item_count).attribute13  := ri.attribute13;
5211             l_revised_item_tbl(l_revised_item_count).attribute14  := ri.attribute14;
5212             l_revised_item_tbl(l_revised_item_count).attribute15  := ri.attribute15;
5213             l_revised_item_tbl(l_revised_item_count).From_End_Item_Unit_Number := ri.From_End_Item_Unit_Number;
5214             l_revised_item_tbl(l_revised_item_count).New_From_End_Item_Unit_Number := NULL;
5215             l_revised_item_tbl(l_revised_item_count).Original_System_Reference := ri.Original_System_Reference;
5216             -- lkasturi: new columns in 11.5.10 changes
5217 
5218             l_revised_item_tbl(l_revised_item_count).Transfer_Or_Copy := ri.transfer_or_copy;
5219             l_revised_item_tbl(l_revised_item_count).Transfer_OR_Copy_Item := ri.transfer_or_copy_item;
5220             l_revised_item_tbl(l_revised_item_count).Transfer_OR_Copy_Bill := ri.transfer_or_copy_bill;
5221             l_revised_item_tbl(l_revised_item_count).Copy_To_Item := ri.Copy_To_Item;
5222             l_revised_item_tbl(l_revised_item_count).Copy_To_Item_Desc := ri.Copy_To_Item_Desc;
5223 
5224             l_revised_item_tbl(l_revised_item_count).parent_revised_item_name := l_parent_revised_item_name;
5225             l_revised_item_tbl(l_revised_item_count).parent_alternate_name := l_ris.alternate_bom_designator;
5226 
5227             l_revised_item_tbl(l_revised_item_count).selection_option := ri.selection_option;
5228             l_revised_item_tbl(l_revised_item_count).selection_date := ri.selection_date;
5229             l_revised_item_tbl(l_revised_item_count).selection_unit_number := ri.selection_unit_number;
5230             l_revised_item_tbl(l_revised_item_count).current_lifecycle_phase_name := l_current_lifecycle_name;
5231             l_revised_item_tbl(l_revised_item_count).new_lifecycle_phase_name := l_new_lifecycle_name;
5232 
5233             l_revised_item_tbl(l_revised_item_count).enable_item_in_local_org := ri.enable_item_in_local_org;
5234             l_revised_item_tbl(l_revised_item_count).new_structure_revision :=  l_new_struc_revision;
5235             l_revised_item_tbl(l_revised_item_count).current_structure_rev_name := l_current_struc_revision;
5236 
5237             l_revised_item_tbl(l_revised_item_count).plan_level := ri.plan_level;
5238             l_revised_item_tbl(l_revised_item_count).from_end_item_name := l_from_end_item_name;
5239             l_revised_item_tbl(l_revised_item_count).FROM_END_ITEM_ALTERNATE := l_from_end_item_alternate;
5240             l_revised_item_tbl(l_revised_item_count).from_end_item_revision := l_from_end_item_revision;
5241             l_revised_item_tbl(l_revised_item_count).from_end_item_strc_rev := l_from_end_item_minor_rev;
5242 
5243              -- lkasturi: new columns in 11.5.10    end changes
5244             l_revised_item_tbl(l_revised_item_count).transaction_type := 'CREATE';
5245             l_revised_item_tbl(l_revised_item_count).structure_type_name := l_structure_type_name;
5246 
5247             Eng_Eco_Pvt.Process_Rev_Item(
5248                 p_validation_level        => FND_API.G_VALID_LEVEL_FULL
5249               , p_change_notice           => p_change_notice
5250               , p_organization_id         => p_local_organization_id
5251               , I                         => l_revised_item_count
5252               , p_revised_item_rec        => l_revised_item_tbl(l_revised_item_count)
5253               , p_rev_component_tbl       => l_rev_component_tbl
5254               , p_ref_designator_tbl      => l_ref_designator_tbl
5255               , p_sub_component_tbl       => l_sub_component_tbl
5256               , p_rev_operation_tbl       => l_rev_operation_tbl
5257               , p_rev_op_resource_tbl     => l_rev_op_resource_tbl
5258               , p_rev_sub_resource_tbl    => l_rev_sub_resource_tbl
5259               , x_revised_item_tbl        => l_revised_item_tbl
5260               , x_rev_component_tbl       => l_rev_component_tbl
5261               , x_ref_designator_tbl      => l_ref_designator_tbl
5262               , x_sub_component_tbl       => l_sub_component_tbl
5263               , x_rev_operation_tbl       => l_rev_operation_tbl
5264               , x_rev_op_resource_tbl     => l_rev_op_resource_tbl
5265               , x_rev_sub_resource_tbl    => l_rev_sub_resource_tbl
5266               , x_revised_item_unexp_rec  => l_revised_item_unexp_rec
5267               , x_Mesg_Token_Tbl          => l_bo_mesg_token_tbl -- Using another message token table as these are logged by BO itself
5268               , x_return_status           => l_return_status
5269               , x_disable_revision        => l_disable_revision
5270              );
5271 
5272             Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'After processing revised item through BO return status is '||l_return_status);
5273             IF l_return_status <> FND_API.G_RET_STS_SUCCESS
5274             THEN
5275                 RAISE EXC_EXP_SKIP_OBJECT;
5276             END IF;
5277 
5278             IF (l_sourcing_rules_exists = 2 AND l_propagate_strc_changes = G_VAL_TRUE)
5279             THEN
5280                 FOR rcd in c_plm_rev_comps_disable(p_revised_item_sequence_id)
5281                 LOOP
5282                     Propagate_Revised_Component (
5283                         p_component_sequence_id    => rcd.component_sequence_id
5284                       , p_revised_item_sequence_id => rcd.revised_item_sequence_id
5285                       , p_change_id                => p_change_id
5286                       , p_revised_item_rec         => l_revised_item_tbl(l_revised_item_count)
5287                       , p_revised_item_unexp_rec   => l_revised_item_unexp_rec
5288                       , p_local_organization_id    => p_local_organization_id
5289                       , x_Return_Status            => l_return_status
5290                      );
5291                     IF l_return_status <> FND_API.G_RET_STS_SUCCESS
5292                     THEN
5293                         l_propagate_revised_item := G_VAL_FALSE;
5294                     END IF;
5295                 END LOOP;
5296 
5297                 FOR rc in c_plm_rev_comps(p_revised_item_sequence_id)
5298                 LOOP
5299                     Propagate_Revised_Component (
5300                         p_component_sequence_id    => rc.component_sequence_id
5301                       , p_revised_item_sequence_id => rc.revised_item_sequence_id
5302                       , p_change_id                => p_change_id
5303                       , p_revised_item_rec         => l_revised_item_tbl(l_revised_item_count)
5304                       , p_revised_item_unexp_rec   => l_revised_item_unexp_rec
5305                       , p_local_organization_id    => p_local_organization_id
5306                       , x_Return_Status            => l_return_status
5307                      );
5308                     IF l_return_status <> FND_API.G_RET_STS_SUCCESS
5309                     THEN
5310                         l_propagate_revised_item := G_VAL_FALSE;
5311                     END IF;
5312                 END LOOP;
5313             END IF;
5314 
5315             -- Getting the revision id for the items attachment lines context.
5316             -- This is the revision id to which the revision specific lines would be added
5317             BEGIN
5318               select revision_id
5319               into l_local_line_rev_id
5320               from mtl_item_revisions
5321               where inventory_item_id = (select revised_item_id
5322                                          from eng_revised_items
5323                                          where revised_item_sequence_id = l_revised_item_unexp_rec.revised_item_sequence_id)
5324               and revised_item_sequence_id = l_revised_item_unexp_rec.revised_item_sequence_id;
5325             EXCEPTION
5326               WHEN OTHERS THEN
5327                 --this will be called for item attachment changes with default revision
5328                 l_local_line_rev_id := nvl(l_revised_item_unexp_rec.new_item_revision_id,
5329                                            l_revised_item_unexp_rec.current_item_revision_id);
5330             END;
5331 
5332 
5333             Validate_Attach_Lines(
5334                 p_change_id                  => p_change_id
5335               , p_rev_item_sequence_id       => p_revised_item_sequence_id
5336               , p_global_organization_id     => p_organization_id
5337               , p_global_new_item_rev        => ri.new_item_revision
5338               , p_global_current_item_rev_id => ri.current_item_revision_id
5339               , p_local_organization_id      => p_local_organization_id
5340               , p_local_line_rev_id          => l_local_line_rev_id
5341               , p_revised_item_rec           => l_revised_item_tbl(l_revised_item_count)
5342               , p_revised_item_unexp_rec     => l_revised_item_unexp_rec
5343               , x_return_status              => l_attach_return_status
5344               , x_mesg_token_tbl             => l_mesg_token_tbl
5345              );
5346 
5347             IF l_attach_return_status <> FND_API.G_RET_STS_SUCCESS
5348             THEN
5349                 l_propagate_revised_item := G_VAL_FALSE;
5350             END IF;
5351             IF l_propagate_revised_item = G_VAL_TRUE
5352             THEN
5353                 Propagate_Attach_Lines(
5354                     p_change_id                => p_change_id
5355                   , p_revised_item_sequence_id => p_revised_item_sequence_id
5356                   , p_revised_item_rec         => l_revised_item_tbl(l_revised_item_count)
5357                   , p_revised_item_unexp_rec   => l_revised_item_unexp_rec
5358                   , p_local_organization_id    => p_local_organization_id
5359                   , p_local_line_rev_id        => l_local_line_rev_id
5360                   , x_Return_Status            => l_attach_return_status
5361                   , x_mesg_token_tbl           => l_mesg_token_tbl
5362                  );
5363                 IF l_attach_return_status <> FND_API.G_RET_STS_SUCCESS
5364                 THEN
5365                     l_propagate_revised_item := G_VAL_FALSE;
5366                 END IF;
5367             END IF;
5368             IF l_propagate_revised_item = G_VAL_FALSE
5369             THEN
5370                 RAISE EXC_EXP_SKIP_OBJECT;
5371             END IF;
5372 
5373             l_revised_item_count := l_revised_item_count + 1;
5374         END IF;
5375 
5376     END LOOP;
5377 
5378     -- Commit the changes if the api hasnt exit so far
5379     IF (p_commit = FND_API.G_TRUE)
5380     THEN
5381         COMMIT;
5382     END IF;
5383     Eco_Error_Handler.Log_Error(
5384         p_error_status         => l_return_status
5385       , p_mesg_token_tbl       => l_mesg_token_tbl
5386       , p_error_scope          => Error_Handler.G_SCOPE_RECORD
5387       , p_error_level          => Eco_Error_Handler.G_RI_LEVEL
5388       , x_eco_rec              => l_eco_rec
5389       , x_eco_revision_tbl     => l_eco_revision_tbl
5390       , x_change_line_tbl      => l_change_lines_tbl -- Eng Change
5391       , x_revised_item_tbl     => l_revised_item_tbl
5392       , x_rev_component_tbl    => l_rev_component_tbl
5393       , x_ref_designator_tbl   => l_ref_designator_tbl
5394       , x_sub_component_tbl    => l_sub_component_tbl
5395       , x_rev_operation_tbl    => l_rev_operation_tbl         --L1
5396       , x_rev_op_resource_tbl  => l_rev_op_resource_tbl  --L1
5397       , x_rev_sub_resource_tbl => l_rev_sub_resource_tbl --L1
5398      );
5399     Eng_Propagation_Log_Util.add_entity_map(
5400         p_change_id                 => p_change_id
5401       , p_revised_item_sequence_id  => p_revised_item_sequence_id
5402       , p_local_organization_id     => p_local_organization_id
5403       , p_local_revised_item_seq_id => l_revised_item_unexp_rec.revised_item_sequence_id
5404       , p_entity_name               => Eng_Propagation_Log_Util.G_ENTITY_REVISED_ITEM
5405       , p_entity_action_status      => Eng_Propagation_Log_Util.G_PRP_PRC_STS_SUCCESS
5406       , p_bo_entity_identifier      => 'RI'--Eco_Error_Handler.G_RI_LEVEL
5407      );
5408     CLOSE c_revised_items_data;
5409 
5410     x_return_status := l_return_status;
5411 
5412     Eng_Propagation_Log_Util.Debug_Log(G_LOG_PROC, 'Propagate_Revised_Item.END');
5413 EXCEPTION
5414 WHEN EXC_EXP_SKIP_OBJECT THEN
5415     IF c_revised_items_data%ISOPEN
5416     THEN
5417         CLOSE c_revised_items_data;
5418     End IF;
5419 
5420     -- Set the return status
5421     l_return_status := FND_API.G_RET_STS_ERROR;
5422     -- Log any messages that have been logged with the additional error
5423     -- message into error handler
5424     Eco_Error_Handler.Log_Error(
5425         p_error_status         => l_return_status
5426       , p_mesg_token_tbl       => l_mesg_token_tbl
5427       , p_error_scope          => Error_Handler.G_SCOPE_RECORD
5428       , p_error_level          => Eco_Error_Handler.G_RI_LEVEL
5429       , p_other_message        => 'ENG_PRP_REV_ITEM_ERR'
5430       , p_other_status         => l_return_status
5431       , p_other_token_tbl      => l_token_tbl
5432       , x_eco_rec              => l_eco_rec
5433       , x_eco_revision_tbl     => l_eco_revision_tbl
5434       , x_change_line_tbl      => l_change_lines_tbl -- Eng Change
5435       , x_revised_item_tbl     => l_revised_item_tbl
5436       , x_rev_component_tbl    => l_rev_component_tbl
5437       , x_ref_designator_tbl   => l_ref_designator_tbl
5438       , x_sub_component_tbl    => l_sub_component_tbl
5439       , x_rev_operation_tbl    => l_rev_operation_tbl         --L1
5440       , x_rev_op_resource_tbl  => l_rev_op_resource_tbl  --L1
5441       , x_rev_sub_resource_tbl => l_rev_sub_resource_tbl --L1
5442      );
5443     Eng_Propagation_Log_Util.add_entity_map(
5444         p_change_id                 => p_change_id
5445       , p_revised_item_sequence_id  => p_revised_item_sequence_id
5446       , p_local_organization_id     => p_local_organization_id
5447       , p_entity_name               => Eng_Propagation_Log_Util.G_ENTITY_REVISED_ITEM
5448       , p_entity_action_status      => Eng_Propagation_Log_Util.G_PRP_PRC_STS_ERROR
5449       , p_bo_entity_identifier      => 'RI'--Eco_Error_Handler.G_RI_LEVEL
5450      );
5451     x_return_status := l_return_status;
5452     --
5453     -- Rollback any changes that may have been made to the DB
5454     --
5455     ROLLBACK TO BEGIN_REV_ITEM_PROCESSING;
5456     Eng_Propagation_Log_Util.Debug_Log(G_LOG_PROC, 'Propagate_Revised_Item.END');
5457 WHEN OTHERS THEN
5458     IF c_revised_items_data%ISOPEN
5459     THEN
5460         CLOSE c_revised_items_data;
5461     End IF;
5462     -- Set the return status
5463     l_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
5464     l_err_text := G_PKG_NAME || ' : (Revised Item Propagation) ' || substrb(SQLERRM,1,200);
5465 
5466     Error_Handler.Add_Error_Token(
5467         p_Message_Name   => NULL
5468       , p_Message_Text   => l_Err_Text
5469       , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5470       , x_Mesg_Token_Tbl => l_Mesg_Token_Tbl
5471      );
5472     -- Log any messages that have been logged with the additional error
5473     -- message into error handler
5474     Eco_Error_Handler.Log_Error(
5475         p_error_status         => l_return_status
5476       , p_mesg_token_tbl       => l_mesg_token_tbl
5477       , p_error_scope          => Error_Handler.G_SCOPE_RECORD
5478       , p_error_level          => Eco_Error_Handler.G_RI_LEVEL
5479       , p_other_message        => 'ENG_PRP_REV_ITEM_ERR'
5480       , p_other_status         => l_return_status
5481       , p_other_token_tbl      => l_token_tbl
5482       , x_eco_rec              => l_eco_rec
5483       , x_eco_revision_tbl     => l_eco_revision_tbl
5484       , x_change_line_tbl      => l_change_lines_tbl -- Eng Change
5485       , x_revised_item_tbl     => l_revised_item_tbl
5486       , x_rev_component_tbl    => l_rev_component_tbl
5487       , x_ref_designator_tbl   => l_ref_designator_tbl
5488       , x_sub_component_tbl    => l_sub_component_tbl
5489       , x_rev_operation_tbl    => l_rev_operation_tbl         --L1
5490       , x_rev_op_resource_tbl  => l_rev_op_resource_tbl  --L1
5491       , x_rev_sub_resource_tbl => l_rev_sub_resource_tbl --L1
5492      );
5493 
5494     Eng_Propagation_Log_Util.add_entity_map(
5495         p_change_id                 => p_change_id
5496       , p_revised_item_sequence_id  => p_revised_item_sequence_id
5497       , p_local_organization_id     => p_local_organization_id
5498       , p_entity_name               => Eng_Propagation_Log_Util.G_ENTITY_REVISED_ITEM
5499       , p_entity_action_status      => Eng_Propagation_Log_Util.G_PRP_PRC_STS_ERROR
5500       , p_bo_entity_identifier      => 'RI'--Eco_Error_Handler.G_RI_LEVEL
5501      );
5502     x_return_status := l_return_status;
5503     --
5504     -- Rollback any changes that may have been made to the DB
5505     --
5506     ROLLBACK TO BEGIN_REV_ITEM_PROCESSING;
5507 END Propagate_Revised_Item;
5508 
5509 -- ****************************************************************** --
5510 --  API name    : Propagate_ECO_PLM                                   --
5511 --  Type        : Private                                              --
5512 --  Pre-reqs    : None.                                               --
5513 --  Procedure   : Propagates the specified ECO                        --
5514 --  Parameters  :                                                     --
5515 --       IN     : p_api_version              NUMBER     Required      --
5516 --                p_change_id                VARCHAR2   Required      --
5517 --                p_organization_id          NUMBER     Required      --
5518 --                p_org_hierarchy_id         VARCHAR2                 --
5519 --                p_local_organization_id    NUMBER := NULL           --
5520 --                p_calling_api NUMBER := NULL           --
5521 --       OUT    : x_return_status            VARCHAR2(1)              --
5522 --                x_error_buf                VARCHAR2(30)             --
5523 --  Version     :                                                     --
5524 --                Current version       1.0                           --
5525 --                Initial version       1.0                           --
5526 --                                                                    --
5527 --  Notes       :                                                     --
5528 --                if org hierarchy id is -1 then the list of orgs     --
5529 --                associated to the change are picked for propagation --
5530 --                if p_org_hierarchy_id is null, check that the value --
5531 --                local_organization_id has been specified            --
5532 --                Validate that the local organization id either      --
5533 --                belongs to the hierarchy or to the list of local    --
5534 --                 orgs of thesource change order                     --
5535 --                 p_calling API is TTM then the change header        --
5536 --                 relation is checked first 'TRANSFERRED_TO'        --
5537 -- ****************************************************************** --
5538 
5539 PROCEDURE Propagate_ECO_PLM (
5540     p_api_version              IN NUMBER           := 1.0
5541   , x_error_buf                OUT NOCOPY VARCHAR2
5542   , x_return_status            OUT NOCOPY VARCHAR2
5543   , p_change_notice            IN VARCHAR2
5544   , p_organization_id          IN NUMBER
5545   , p_org_hierarchy_name       IN VARCHAR2
5546   , p_local_organization_id    IN NUMBER           := NULL
5547   , p_calling_api              IN VARCHAR2         := NULL
5548 ) IS
5549 
5550     l_api_name        CONSTANT VARCHAR2(30) := 'PROPAGATE_ECO_PLM';
5551     l_api_version     CONSTANT NUMBER := 1.0;
5552 
5553     l_org_code        mtl_parameters.organization_code%TYPE;
5554     l_global_org_code mtl_parameters.organization_code%TYPE;
5555     l_global_change_id NUMBER;
5556     l_local_change_id NUMBER;
5557     -- this corresponds to the processing status that will have to be updated to the change
5558     l_top_entity_process_status NUMBER;
5559 
5560     l_Mesg_Token_Tbl   Error_Handler.Mesg_Token_Tbl_Type;
5561     l_return_status    VARCHAR2(1);
5562 
5563     CURSOR c_fetch_org_code(cp_organization_id NUMBER) IS
5564     SELECT organization_code
5565       FROM mtl_parameters
5566      WHERE organization_id = cp_organization_id;
5567 
5568     CURSOR c_change_header IS
5569     SELECT change_id
5570       FROM eng_engineering_changes
5571      WHERE change_notice = p_change_notice
5572        AND organization_id = p_organization_id;
5573 ---added Bug no 4327321  only revised items will get propagate.No transfer and copy items
5574    CURSOR c_prp_revised_item IS
5575    SELECT eri.revised_item_sequence_id
5576      FROM eng_revised_items eri
5577     WHERE eri.change_id = l_global_change_id
5578     AND  transfer_or_copy is NULL
5579       AND NOT EXISTS
5580          (SELECT 1
5581             FROM eng_change_propagation_maps ecpm
5582            WHERE ecpm.change_id = eri.change_id
5583              AND ecpm.local_organization_id = p_local_organization_id
5584              AND ecpm.revised_item_sequence_id = eri.revised_item_sequence_id
5585              AND ecpm.entity_name = Eng_Propagation_Log_Util.G_ENTITY_REVISED_ITEM
5586              AND ecpm.entity_action_status IN (Eng_Propagation_Log_Util.G_PRP_PRC_STS_SUCCESS, Eng_Propagation_Log_Util.G_PRP_PRC_STS_EXCL_TTM));
5587 
5588 BEGIN
5589     Eng_Propagation_Log_Util.Debug_Log(G_LOG_PROC, 'PROPAGATE_ECO_PLM.Begin For Organization: '|| l_org_code);
5590     -- Standard call to check for call compatibility
5591     IF NOT FND_API.Compatible_API_Call (  l_api_version
5592                                         , p_api_version
5593                                         , l_api_name
5594                                         , G_PKG_NAME )
5595     THEN
5596         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5597     END IF;
5598 
5599     --
5600     -- Initialize return status
5601     l_return_status := FND_API.G_RET_STS_SUCCESS;
5602     Error_Handler.Initialize;
5603     ENG_GLOBALS.G_ENG_LAUNCH_IMPORT := 2 ;--Indicates call is from propagation
5604     -- Removed check for local orgs same master org when propagating change orders
5605     -- as if required this can be added to the Business Object ---- 6/15/2005
5606 
5607     --
5608     -- Fetch Organization Code for further processing
5609     OPEN c_fetch_org_code(p_organization_id);
5610     FETCH c_fetch_org_code INTO l_global_org_code;
5611     CLOSE c_fetch_org_code;
5612 
5613     OPEN c_fetch_org_code(p_local_organization_id);
5614     FETCH c_fetch_org_code INTO l_org_code;
5615     CLOSE c_fetch_org_code;
5616     --
5617     -- Fetch change_id for further processing
5618     OPEN c_change_header;
5619     FETCH c_change_header INTO l_global_change_id;
5620     CLOSE c_change_header;
5621 
5622     IF p_calling_API IS NULL
5623     THEN
5624         -- Progress with call to propagate the change header when
5625         -- calling api is not TTM
5626         -- Currently this is the only case possible
5627 
5628         Propagate_Change_Header(
5629             p_change_id               => l_global_change_id
5630           , p_change_notice           => p_change_notice
5631           , p_organization_code       => l_global_org_code
5632           , p_organization_id         => p_organization_id
5633           , p_org_hierarchy_name      => p_org_hierarchy_name
5634           , p_local_organization_code => l_org_code
5635           , p_local_organization_id   => p_local_organization_id
5636           , x_Mesg_Token_Tbl          => l_Mesg_Token_Tbl
5637           , x_Return_Status           => l_return_status
5638          );
5639         IF (l_return_status <> FND_API.G_RET_STS_SUCCESS)
5640         THEN
5641             l_top_entity_process_status := Eng_Propagation_Log_Util.G_PRP_PRC_STS_ERROR;
5642             RAISE EXC_EXP_SKIP_OBJECT;
5643         END IF;
5644     END IF; -- **** END of p_calling_API <> 'TTM' **** --
5645 
5646         -- p_calling_API = 'TTM' and even after normal processing check if the ecdo already exists
5647         -- if the calling api is TTM then check if the change has already
5648         -- been propagated , only then continue processing
5649         -- if local change does not already exist , then the organization
5650         -- need not be propagated.
5651         -- calling api will be TTM only when the automatic change prpagation
5652         -- request has been triggered off by the BOM COPY process from
5653         -- Product Workbench
5654         Propagated_Local_Change(
5655             p_change_id             => l_global_change_id
5656           , p_local_organization_id => p_local_organization_id
5657           , x_local_change_id       => l_local_change_id
5658          );
5659         IF (l_local_change_id IS NULL)
5660         THEN
5661             Eng_Propagation_Log_Util.Debug_Log(G_LOG_PROC, 'PROPAGATE_ECO_PLM.End For Organization: '|| l_org_code);
5662             RETURN;
5663         END IF;
5664     Eng_Propagation_Log_Util.Debug_Log(G_LOG_STMT, 'Value x_local_change_id: '|| l_local_change_id);
5665     Initialize_Business_object(
5666         p_debug           => 'N'
5667       , p_debug_filename  => ''
5668       , p_output_dir      => ''
5669       , p_bo_identifier   => 'ECO'
5670       , p_organization_id => p_local_organization_id
5671       , x_return_status   => l_return_status
5672      );
5673     FOR eri IN c_prp_revised_item
5674     LOOP
5675         Propagate_Revised_Item(
5676             p_revised_item_sequence_id => eri.revised_item_sequence_id
5677           , p_change_id                => l_global_change_id
5678           , p_change_notice            => p_change_notice
5679           , p_organization_code        => l_global_org_code
5680           , p_organization_id          => p_organization_id
5681           , p_local_organization_code  => l_org_code
5682           , p_local_organization_id    => p_local_organization_id
5683           , p_commit                   => FND_API.G_TRUE
5684           , x_Return_Status            => l_return_status
5685         );
5686         IF (l_return_status <> FND_API.G_RET_STS_SUCCESS)
5687         THEN
5688             l_top_entity_process_status := Eng_Propagation_Log_Util.G_PRP_PRC_STS_ERROR;
5689         END IF;
5690     END LOOP;
5691     Reset_Business_Object;
5692     IF l_top_entity_process_status = Eng_Propagation_Log_Util.G_PRP_PRC_STS_ERROR
5693     THEN
5694         RAISE EXC_EXP_SKIP_OBJECT;
5695     END IF;
5696 
5697     Init_Local_Change_Lifecycle (
5698         p_local_change_id    => l_local_change_id
5699       , p_organization_id    => p_organization_id
5700       , p_org_hierarchy_name => p_org_hierarchy_name
5701       , x_return_status      => l_return_status
5702      );
5703     -- Not doing anythig for processing the Init_Local_Change_Lifecycle return status as
5704     -- the changes to the change order in local org can go through .user can then
5705     -- manually init the lifecycle if required
5706     Eng_Propagation_Log_Util.add_entity_map(
5707         p_change_id                 => l_global_change_id
5708       , p_local_organization_id     => p_local_organization_id
5709       , p_entity_name               => Eng_Propagation_Log_Util.G_ENTITY_CHANGE
5710       , p_entity_action_status      => Eng_Propagation_Log_Util.G_PRP_PRC_STS_SUCCESS
5711       , p_bo_entity_identifier      => 'ECO'--Eco_Error_Handler.G_ECO_LEVEL
5712      );
5713 EXCEPTION
5714 WHEN EXC_EXP_SKIP_OBJECT THEN
5715     Eng_Propagation_Log_Util.add_entity_map(
5716         p_change_id                 => l_global_change_id
5717       , p_local_organization_id     => p_local_organization_id
5718       , p_entity_name               => Eng_Propagation_Log_Util.G_ENTITY_CHANGE
5719       , p_entity_action_status      => Eng_Propagation_Log_Util.G_PRP_PRC_STS_ERROR
5720       , p_bo_entity_identifier      => 'ECO'--Eco_Error_Handler.G_ECO_LEVEL
5721      );
5722     ROLLBACK;
5723 WHEN OTHERS THEN
5724     ROLLBACK;
5725 END Propagate_ECO_PLM;
5726 
5727 PROCEDURE Get_Local_Orgs_List (
5728     p_change_notice         IN VARCHAR2
5729   , p_organization_id       IN NUMBER
5730   , p_hierarchy_name        IN VARCHAR2
5731   , p_local_organization_id IN NUMBER
5732   , x_organizations_list    OUT NOCOPY INV_OrgHierarchy_PVT.OrgID_tbl_type
5733   , x_return_status         OUT NOCOPY VARCHAR2
5734 ) IS
5735 
5736   CURSOR c_local_orgs IS
5737   SELECT eclo.local_organization_id
5738     FROM eng_engineering_changes eec
5739        , eng_change_local_orgs eclo
5740        , hr_all_organization_units  org
5741        , hr_organization_information hoi
5742        , mtl_parameters mp
5743    WHERE eec.change_notice = p_change_notice
5744      AND eec.organization_id = p_organization_id
5745      AND eclo.change_id = eec.change_id
5746      AND org.organization_id  = hoi.organization_id
5747      AND org.organization_id  = mp.organization_id
5748      AND hoi.org_information1 = 'INV'
5749      AND hoi.org_information2 = 'Y' -- inventory enabled flag
5750      AND hoi.org_information_context = 'CLASS'
5751      -- expiration check
5752      AND org.organization_id  =  eclo.local_organization_id
5753      AND (org.date_to >= SYSDATE OR org.date_to IS NULL)
5754      -- inv security access check
5755      AND (NOT EXISTS(SELECT 1 FROM ORG_ACCESS  acc
5756                       WHERE acc.organization_id =  eclo.local_organization_id )
5757           OR  EXISTS(SELECT 1 FROM ORG_ACCESS  acc
5758                       WHERE acc.organization_id =  eclo.local_organization_id
5759                         AND acc.responsibility_id = TO_NUMBER(fnd_profile.value('RESP_ID'))));
5760   l_org_Idx NUMBER;
5761   l_orgs_Cnt NUMBER;
5762 
5763 BEGIN
5764     x_return_status := FND_API.G_RET_STS_SUCCESS;
5765     IF p_local_organization_id IS NOT NULL
5766     THEN
5767         x_organizations_list(1) := p_organization_id;
5768         x_organizations_list(2) := p_local_organization_id;
5769     ELSIF p_hierarchy_name IS NOT NULL
5770     THEN
5771         -- Fetch the list of organizations from hierarchy if specified
5772         Inv_OrgHierarchy_Pvt.Org_Hierarchy_List(p_hierarchy_name, p_organization_id, x_organizations_list);
5773     ELSE
5774         -- from eng_change_local_organizations for TTM
5775         -- The following APIs fetch the list of all organizations for which the user has access
5776         -- by responsibility and by business group.
5777         l_org_Idx := 1;
5778         x_organizations_list(l_org_Idx) := p_organization_id;
5779         x_organizations_list(l_org_Idx+1) := 209;
5780         FOR c_org IN c_local_orgs
5781         LOOP
5782             l_org_Idx := l_org_Idx+1;
5783             x_organizations_list(l_org_Idx) := c_org.local_organization_id;
5784         END LOOP;
5785     END IF;
5786 
5787     l_orgs_Cnt := x_organizations_list.COUNT;
5788     IF (l_orgs_Cnt IN  (0, 1))
5789     THEN
5790         FND_FILE.PUT_LINE(FND_FILE.LOG, 'No Organization exists for propagating changes');
5791          x_return_status := FND_API.G_RET_STS_ERROR;
5792     END IF;
5793 END Get_Local_Orgs_List;
5794 
5795 -- ****************************************************************** --
5796 --  API name    : Propagate_ECO                                       --
5797 --  Type        : Public                                              --
5798 --  Pre-reqs    : None.                                               --
5799 --  Procedure   : Propagates the specified ECO                        --
5800 --  Parameters  :                                                     --
5801 --       IN     :                                                     --
5802 --                p_change_notice            VARCHAR2   Required      --
5803 --                p_org_hierarchy_name       varchar2                 --
5804 --                p_org_hierarchy_level      VARCHAR2                 --
5805 --                p_local_organization_id    NUMBER := NULL           --
5806 --                p_calling_api              NUMBER := NULL           --
5807 --       OUT    : retcode                    VARCHAR2(1)              --
5808 --                error_buf                  VARCHAR2(30)             --
5809 --  Version     :                                                     --
5810 --                Current version       1.0                           --
5811 --                Initial version       1.0                           --
5812 --                                                                    --
5813 --  Notes       :                                                     --
5814 --                if org hierarchy id is -1 then the list of orgs     --
5815 --                associated to the change are picked for propagation --
5816 --                if p_org_hierarchy_id is null, check that the value --
5817 --                local_organization_id has been specified            --
5818 --                Validate that the local organization id either      --
5819 --                belongs to the hierarchy or to the list of local    --
5820 --                 orgs of thesource change order                     --
5821 --                 p_calling API is TTM then the change header        --
5822 --                 relation is checked first 'TRANSFERRED_TO'         --
5823 -- ****************************************************************** --
5824 PROCEDURE PROPAGATE_ECO (
5825    errbuf                 OUT NOCOPY    VARCHAR2
5826  , retcode                OUT NOCOPY    VARCHAR2
5827  , p_change_notice        IN            VARCHAR2
5828  , p_org_hierarchy_name   IN            VARCHAR2
5829  , p_org_hierarchy_level  IN            VARCHAR2
5830  , p_local_organization_id IN           NUMBER := NULL
5831  , p_calling_API           IN           VARCHAR2 := NULL
5832 ) IS
5833 
5834     l_plm_or_erp_flag               VARCHAR2(3);
5835     l_org_hierarchy_level_id        NUMBER;
5836     l_org_code_list                 INV_OrgHierarchy_PVT.OrgID_tbl_type;
5837 
5838     CURSOR c_organization_details IS
5839     SELECT MP.organization_id
5840     FROM HR_ORGANIZATION_UNITS HOU
5841     , HR_ORGANIZATION_INFORMATION HOI1
5842     , MTL_PARAMETERS MP
5843     WHERE HOU.ORGANIZATION_ID = HOI1.ORGANIZATION_ID
5844     AND HOU.ORGANIZATION_ID = MP.ORGANIZATION_ID
5845     AND HOI1.ORG_INFORMATION1 = 'INV'
5846     AND HOI1.ORG_INFORMATION2 = 'Y'
5847     AND HOU.NAME = p_org_hierarchy_level;
5848       /*FROM org_organization_definitions
5849      WHERE organization_name = p_org_hierarchy_level;*/
5850 
5851     l_return_status VARCHAR2(1);
5852 BEGIN
5853     -- Fetch the global organization id
5854     OPEN c_organization_details;
5855     FETCH c_organization_details INTO l_org_hierarchy_level_id;
5856     CLOSE c_organization_details;
5857     -- Fetch the value of plm_or_erp_change
5858     -- The processing will be routed differently for PLM ECOs and ERP ECOs
5859     l_plm_or_erp_flag := Eng_Globals.Get_PLM_Or_ERP_Change(
5860                               p_change_notice  => p_change_notice
5861                             , p_organization_id => l_org_hierarchy_level_id);
5862     -- Begin Processing for PLM
5863     IF (l_plm_or_erp_flag = 'PLM')
5864     THEN
5865          --   Bug : 5326333 ECO Propagation was failing because validations not required from PLM flow are happening from BOM API.
5866          --   If we set the following flag, then bom validations will be skipped for PLM flow.
5867         Bom_Globals.Set_Validate_For_Plm('Y');
5868         -- Set OrganizationId as global variable
5869         g_global_org_id := l_org_hierarchy_level_id;
5870         -- This following validation needs to be done for all orgs in the list
5871         -- Eng_Validate.Organization_Id(p_organization_id => l_org_id);
5872         Get_Local_Orgs_List(
5873             p_change_notice         => p_change_notice
5874           , p_organization_id       => l_org_hierarchy_level_id
5875           , p_hierarchy_name        => p_org_hierarchy_name
5876           , p_local_organization_id => p_local_organization_id
5877           , x_organizations_list    => l_org_code_list
5878           , x_return_status         => l_return_status);
5879 
5880         IF l_return_status = FND_API.G_RET_STS_ERROR
5881         THEN
5882             RETURN;
5883         END IF;
5884 
5885         FOR l_org_count IN 2..l_org_code_list.LAST
5886         LOOP
5887             Eng_Propagation_Log_Util.Initialize;
5888             Propagate_ECO_PLM(
5889                 x_error_buf             => errbuf
5890               , x_return_status         => retcode
5891               , p_change_notice         => p_change_notice
5892               , p_organization_id       => l_org_hierarchy_level_id
5893               , p_org_hierarchy_name    => p_org_hierarchy_name
5894               , p_local_organization_id => l_org_code_list(l_org_count)
5895               , p_calling_API           => p_calling_API
5896              );
5897             Eng_Propagation_Log_Util.Write_Propagation_Log;
5898             commit;
5899 
5900         END LOOP; -- end FOR l_org_count IN 2..l_org_code_list.LAST
5901     ELSE
5902         PROPAGATE_ECO_ERP(
5903           errbuf                 => errbuf ,
5904           retcode                => retcode,
5905           p_change_notice        => p_change_notice,
5906           p_org_hierarchy_name   => p_org_hierarchy_name,
5907           p_org_hierarchy_level  => p_org_hierarchy_level
5908         );
5909 
5910     END IF;  -- end l_plm_or_erp_flag = 'PLM'
5911 
5912 END PROPAGATE_ECO;
5913 
5914 -- ****************************************************************** --
5915 --  API name    : PreProcess_Propagate_Request                        --
5916 --  Type        : Public                                              --
5917 --  Pre-reqs    : None.                                               --
5918 --  Procedure   : Adds a row into the Propagation maps table          --
5919 --  Parameters  :                                                     --
5920 --       IN     :  p_api_version               IN   NUMBER            --
5921 --                   p_init_msg_list             IN   VARCHAR2        --
5922 --                   p_commit                    IN   VARCHAR2        --
5923 --                   p_request_id                IN   NUMBER          --
5924 --                   p_change_id                 IN   VARCHAR2        --
5925 --                   p_org_hierarchy_name        IN   VARCHAR2        --
5926 --                   p_local_organization_id     IN   NUMBER          --
5927 --                   p_calling_API               IN   VARCHAR2        --
5928 --                                                                    --
5929 --       OUT    : x_msg_count                 OUT NOCOPY  NUMBER      --
5930 --                x_msg_data                  OUT NOCOPY  VARCHAR2    --
5931 --                x_return_status                    VARCHAR2(1)      --
5932 --                                                                    --
5933 --  Version     :                                                     --
5934 --                Current version       1.0                           --
5935 --                Initial version       1.0                           --
5936 --                                                                    --
5937 --  Notes       :                                                     --
5938 -- ****************************************************************** --
5939 PROCEDURE PreProcess_Propagate_Request (
5940    p_api_version               IN   NUMBER                             --
5941  , p_init_msg_list             IN   VARCHAR2                           --
5942  , p_commit                    IN   VARCHAR2                           --
5943  , p_request_id                IN   NUMBER
5944  , p_change_id                 IN   VARCHAR2
5945  , p_org_hierarchy_name        IN   VARCHAR2
5946  , p_local_organization_id     IN   NUMBER
5947  , p_calling_API               IN   VARCHAR2
5948  , x_return_status             OUT NOCOPY  VARCHAR2                    --
5949  , x_msg_count                 OUT NOCOPY  NUMBER                      --
5950  , x_msg_data                  OUT NOCOPY  VARCHAR2                    --
5951 ) IS
5952 
5953     l_org_hierarchy_level_id        NUMBER;
5954     l_change_notice                 eng_engineering_changes.change_notice%TYPE;
5955     l_org_code_list                 INV_OrgHierarchy_PVT.OrgID_tbl_type;
5956 
5957     CURSOR c_change_details IS
5958     SELECT change_notice, organization_id
5959       FROM eng_engineering_changes
5960      WHERE change_id = p_change_id;
5961 
5962     l_api_name        CONSTANT VARCHAR2(30) := 'PreProcess_Propagate_Request';
5963     l_api_version     CONSTANT NUMBER := 1.0;
5964     l_return_status            VARCHAR2(1);
5965     l_change_map_id   NUMBER;
5966 BEGIN
5967     --
5968     -- Standard Start of API savepoint
5969     SAVEPOINT PreProcess_Propagate_Request;
5970     --
5971     -- Standard call to check for call compatibility
5972     IF NOT FND_API.Compatible_API_Call ( l_api_version
5973                                         ,p_api_version
5974                                         ,l_api_name
5975                                         ,G_PKG_NAME )
5976     THEN
5977       RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5978     END IF;
5979     --
5980     -- Initialize message list if p_init_msg_list is set to TRUE.
5981     IF FND_API.to_Boolean( p_init_msg_list ) THEN
5982        FND_MSG_PUB.initialize;
5983     END IF ;
5984     --
5985     -- Fetch the change details
5986     OPEN c_change_details;
5987     FETCH c_change_details INTO l_change_notice, l_org_hierarchy_level_id;
5988     CLOSE c_change_details;
5989     --
5990     -- Fetch the list of organizations that are going to be processed
5991     -- by the request submitted
5992     Get_Local_Orgs_List(p_change_notice         => l_change_notice
5993                       , p_organization_id       => l_org_hierarchy_level_id
5994                       , p_hierarchy_name        => p_org_hierarchy_name
5995                       , p_local_organization_id => p_local_organization_id
5996                       , x_organizations_list    => l_org_code_list
5997                       , x_return_status         => l_return_status);
5998     --
5999     -- If successful , then proceed
6000     IF l_return_status = FND_API.G_RET_STS_SUCCESS
6001     THEN
6002         --
6003         -- For each organization, check if propagation process had already been
6004         -- initiated for the change in that organization
6005         -- If the map does not exist then create a new map entry with entity action status
6006         -- as G_PRP_PRC_STS_NOACTION CONSTANT NUMBER := 0 => Meaning: No action yet
6007         -- if the map already exists , then update just the value of request id on the
6008         -- change map, so that the UI can reference to the latest reqeust as soon as
6009         -- it is submitted.
6010         FOR l_org_count IN 2..l_org_code_list.LAST
6011         LOOP
6012             --
6013             -- Check for header map existance for the change and specific local org
6014             Eng_Propagation_Log_Util.Check_Entity_Map_Existance (
6015                 p_change_id             => p_change_id
6016               , p_entity_name           => Eng_Propagation_Log_Util.G_ENTITY_CHANGE--'ENG_CHANGE'
6017               , p_local_organization_id => l_org_code_list(l_org_count)
6018               , x_change_map_id         => l_change_map_id
6019             );
6020             --
6021             -- If it deoes not exist, INSERT
6022             IF l_change_map_id IS NULL
6023             THEN
6024                 SELECT eng_change_propagation_maps_s.nextval
6025                 INTO l_change_map_id
6026                 FROM DUAL;
6027 
6028                 INSERT INTO eng_change_propagation_maps(
6029                     change_propagation_map_id
6030                   , change_id
6031                   , request_id
6032                   , local_organization_id
6033                   , entity_name
6034                   , creation_date
6035                   , created_by
6036                   , last_update_date
6037                   , last_updated_by
6038                   , last_update_login
6039                   , entity_action_status
6040                   )
6041                 VALUES(
6042                     l_CHANGE_MAP_ID
6043                   , p_CHANGE_ID
6044                   , p_request_id
6045                   , l_org_code_list(l_org_count)
6046                   , Eng_Propagation_Log_Util.G_ENTITY_CHANGE--'ENG_CHANGE'
6047                   , SYSDATE
6048                   , FND_GLOBAL.USER_ID
6049                   , SYSDATE
6050                   , FND_GLOBAL.USER_ID
6051                   , FND_GLOBAL.LOGIN_ID
6052                   , Eng_Propagation_Log_Util.G_PRP_PRC_STS_NOACTION
6053                  );
6054             --
6055             -- Else UPDATE
6056             ELSE
6057                 UPDATE eng_change_propagation_maps
6058                    SET request_id        = p_request_id
6059                      , creation_date     = SYSDATE
6060                      , created_by        = FND_GLOBAL.USER_ID
6061                      , last_update_date  = SYSDATE
6062                      , last_updated_by   = FND_GLOBAL.USER_ID
6063                      , last_update_login = FND_GLOBAL.LOGIN_ID
6064                  WHERE change_propagation_map_id = l_change_map_id;
6065             END IF; -- IF l_change_map_id IS NULL
6066         END LOOP; -- FOR l_org_count IN 2..l_org_code_list.LAST
6067     END IF; -- IF l_return_status = FND_API.G_RET_STS_SUCCESS
6068 
6069     -- Standard ending code ------------------------------------------------
6070     IF FND_API.To_Boolean ( p_commit ) THEN
6071       COMMIT WORK;
6072     END IF;
6073 
6074 EXCEPTION
6075 WHEN OTHERS THEN
6076     IF c_change_details%ISOPEN THEN
6077         CLOSE c_change_details;
6078     END IF;
6079     -- Begin Exception handling
6080     ROLLBACK TO PreProcess_Propagate_Request;
6081 
6082     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
6083     IF FND_MSG_PUB.Check_Msg_Level( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
6084     THEN
6085       FND_MSG_PUB.Add_Exc_Msg( G_PKG_NAME, l_api_name );
6086     END IF;
6087     FND_MSG_PUB.Count_And_Get(
6088         p_count => x_msg_count
6089       , p_data  => x_msg_data );
6090     -- End Exception handling
6091 END PreProcess_Propagate_Request;
6092 
6093 END ENGECOBO;
6094