DBA Data[Home] [Help]

PACKAGE BODY: APPS.EAM_PROCESS_WO_PVT

Source


1 PACKAGE BODY EAM_PROCESS_WO_PVT AS
2 /* $Header: EAMVWOPB.pls 120.77.12010000.3 2008/11/18 13:13:01 vchidura ship $ */
3 /***************************************************************************
4 --
5 --  Copyright (c) 2002 Oracle Corporation, Redwood Shores, CA, USA
6 --  All rights reserved.
7 --
8 --  FILENAME
9 --
10 --      EAMVWOPB.pls
11 --
12 --  DESCRIPTION
13 --
14 --      Body of package EAM_PROCESS_WO_PVT
15 --
16 --  NOTES
17 --
18 --  HISTORY
19 --
20 --  30-JUN-2002    Kenichi Nagumo     Initial Creation
21 --  15-May-2005	   Anju Gupta		  R12 changes for CAR/Transactable Assets
22 --  15-Aug-2006    Anju Gupta         Modified the call to Bottom up Scheduler
23 									  for bug 5408720
24 ***************************************************************************/
25 
26 G_PKG_NAME              CONSTANT VARCHAR2(30) := 'EAM_PROCESS_WO_PVT';
27 
28 G_EXC_QUIT_IMPORT       EXCEPTION;
29 
30 EXC_SEV_QUIT_RECORD     EXCEPTION;
31 EXC_SEV_QUIT_BRANCH     EXCEPTION;
32 EXC_SEV_SKIP_BRANCH     EXCEPTION;
33 EXC_FAT_QUIT_OBJECT     EXCEPTION;
34 EXC_SEV_QUIT_OBJECT     EXCEPTION;
35 EXC_UNEXP_SKIP_OBJECT   EXCEPTION;
36 EXC_SEV_QUIT_SIBLINGS   EXCEPTION;
37 EXC_FAT_QUIT_SIBLINGS   EXCEPTION;
38 EXC_FAT_QUIT_BRANCH     EXCEPTION;
39 
40 G_FIRM_WORKORDER        CONSTANT NUMBER := 1;
41 G_SCHEDULE_WO           CONSTANT NUMBER := 2;
42 G_NOT_SCHEDULE_WO       CONSTANT NUMBER := 3;
43 G_NOT_BU_SCHEDULE_WO    CONSTANT NUMBER := 4;
44 G_BU_SCHEDULE_WO        CONSTANT NUMBER := 5;
45 G_NON_FIRM_WORKORDER    CONSTANT NUMBER := 6;
46 G_UPDATE_RES_USAGE	CONSTANT NUMBER := 7;
47 G_MATERIAL_UPDATE	CONSTANT NUMBER := 8;
48 
49 
50 FUNCTION IS_WORKFLOW_ENABLED
51 (p_maint_obj_source    IN   NUMBER,
52   p_organization_id         IN    NUMBER
53 ) RETURN VARCHAR2
54 IS
55     l_workflow_enabled      VARCHAR2(1);
56 BEGIN
57 
58   BEGIN
59               SELECT enable_workflow
60 	      INTO   l_workflow_enabled
61 	      FROM EAM_ENABLE_WORKFLOW
62 	      WHERE MAINTENANCE_OBJECT_SOURCE =p_maint_obj_source;
63      EXCEPTION
64           WHEN NO_DATA_FOUND   THEN
65 	      l_workflow_enabled    :=         'N';
66    END;
67 
68   --IF EAM workorder,check if workflow is enabled for this organization or not
69   IF(l_workflow_enabled ='Y'   AND   p_maint_obj_source=1) THEN
70        BEGIN
71                SELECT eam_wo_workflow_enabled
72 	       INTO l_workflow_enabled
73 	       FROM WIP_EAM_PARAMETERS
74 	       WHERE organization_id =p_organization_id;
75        EXCEPTION
76                WHEN NO_DATA_FOUND THEN
77 		       l_workflow_enabled := 'N';
78        END;
79 
80 
81      RETURN l_workflow_enabled;
82 
83   END IF;  --check for workflow enabled at org level
84 
85     RETURN l_workflow_enabled;
86 
87 END IS_WORKFLOW_ENABLED;
88 
89 /********************************************************************
90     * Procedure: Raise_Workflow_Events
91     * Parameters IN:
92     *         p_api_version_number    API version
93     *         p_validation_level             Validation Level
94     *         p_eam_wo_rec                  Workorder rec
95     *         p_raise_release_approval_event    Whether the Release Approval event has to be raised or not
96     *         p_old_eam_wo_rec         Old workorder record
97     * Parameters OUT:
98     *         x_return_status                  Return Status
99     *         x_mesg_token_tbl              Message token table
100     * Purpose:
101     *         This procedure raises the workflow events for workorder creation, workorder release,
102     *          release approval and status change. Whether the Release Approval event has to be raised
103     *           or not is determined by p_raise_release_approval_event parameter
104     *********************************************************************/
105  PROCEDURE RAISE_WORKFLOW_EVENTS
106  ( p_api_version      IN  NUMBER
107  , p_validation_level        IN  NUMBER
108  , p_eam_wo_rec              IN  EAM_PROCESS_WO_PUB.eam_wo_rec_type
109   ,p_old_eam_wo_rec      IN  EAM_PROCESS_WO_PUB.eam_wo_rec_type
110   ,p_approval_required      IN    BOOLEAN
111   ,p_new_system_status    IN    NUMBER
112  , p_workflow_name    IN    VARCHAR2
113  , p_workflow_process      IN   VARCHAR2
114  , x_mesg_token_tbl          IN OUT NOCOPY EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type
115  , x_return_status           IN OUT NOCOPY VARCHAR2
116  )
117  IS
118 	l_create_event VARCHAR2(240);
119 	l_status_changed_event VARCHAR2(240);
120 	l_status_pending_event VARCHAR2(240);
121 	l_event_name VARCHAR2(240);
122 	l_parameter_list   wf_parameter_list_t;
123 	 l_event_key VARCHAR2(200);
124 	 l_wf_event_seq NUMBER;
125 	 l_estimation_status NUMBER;
126 	 l_cost_estimate NUMBER;
127 	 l_return_status    VARCHAR2(1);
128 	 l_err_text      VARCHAR2(2000);
129 	 l_msg_count     NUMBER;
130  BEGIN
131 
132     l_create_event := 'oracle.apps.eam.workorder.created';
133     l_status_pending_event := 'oracle.apps.eam.workorder.status.change.pending';
134     l_status_changed_event := 'oracle.apps.eam.workorder.status.changed';
135 
136 
137 			--if workorder created and create event enabled
138 			IF(p_eam_wo_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_CREATE AND (WF_EVENT.TEST(l_create_event) <> 'NONE')) THEN
139 										      SELECT EAM_WORKFLOW_EVENT_S.NEXTVAL
140 										      INTO l_wf_event_seq
141 										      FROM DUAL;
142 
143 										      l_parameter_list := wf_parameter_list_t();
144 										      l_event_name := l_create_event;
145 
146 										    l_event_key := TO_CHAR(l_wf_event_seq);
147 										    WF_CORE.CONTEXT('Enterprise Asset Management...','Work Order Creation event','Building parameter list');
148 										    -- Add Parameters
149 										    Wf_Event.AddParameterToList(p_name =>'WIP_ENTITY_ID',
150 													    p_value => TO_CHAR(p_eam_wo_rec.wip_entity_id),
151 													    p_parameterlist => l_parameter_list);
152 										    Wf_Event.AddParameterToList(p_name =>'WIP_ENTITY_NAME',
153 													    p_value =>p_eam_wo_rec.wip_entity_name,
154 													    p_parameterlist => l_parameter_list);
155 										    Wf_Event.AddParameterToList(p_name =>'ORGANIZATION_ID',
156 													    p_value => TO_CHAR(p_eam_wo_rec.organization_id),
157 													    p_parameterlist => l_parameter_list);
158 										    Wf_Event.AddParameterToList(p_name =>'NEW_SYSTEM_STATUS',
159 													    p_value => TO_CHAR(p_eam_wo_rec.status_type),
160 													    p_parameterlist => l_parameter_list);
161 										    Wf_Event.AddParameterToList(p_name =>'NEW_WO_STATUS',
162 													    p_value => TO_CHAR(p_eam_wo_rec.user_defined_status_id),
163 													    p_parameterlist => l_parameter_list);
164 										      Wf_Event.AddParameterToList(p_name =>'WORKFLOW_TYPE',
165 													    p_value => TO_CHAR(p_eam_wo_rec.workflow_type),
166 													    p_parameterlist => l_parameter_list);
167 										      Wf_Event.AddParameterToList(p_name =>'REQUESTOR',
168 													    p_value =>FND_GLOBAL.USER_NAME ,
169 													    p_parameterlist => l_parameter_list);
170 										    Wf_Core.Context('Enterprise Asset Management...','Work Order Creation Event','Raising event');
171 
172 										    Wf_Event.Raise(	p_event_name => l_event_name,
173 													p_event_key => l_event_key,
174 													p_parameters => l_parameter_list);
175 										    l_parameter_list.DELETE;
176 										     WF_CORE.CONTEXT('Enterprise Asset Management...','Work Order Creation Event','After raising event');
177 
178 			END IF;  --end of check for create event enabled
179 
180 			--if workorder created or user-defined status modified  or chaged from pending to non-pending
181 			IF(     (NVL(p_eam_wo_rec.pending_flag,'N')='N' )
182 			      AND
183 			    (  (p_eam_wo_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_CREATE )  --created
184 				OR (p_eam_wo_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_UPDATE  --workorder updated
185 						     --and old status is not same as new status
186 						    AND (p_old_eam_wo_rec.user_defined_status_id <>p_eam_wo_rec.user_defined_status_id       OR    NVL(p_old_eam_wo_rec.pending_flag,'N')='Y' )
187 			    ))
188 			     AND (WF_EVENT.TEST(l_status_changed_event) <> 'NONE')  --if status change event enabled
189 			  ) THEN
190 										      SELECT EAM_WORKFLOW_EVENT_S.NEXTVAL
191 										      INTO l_wf_event_seq
192 										      FROM DUAL;
193 
194 										      l_parameter_list := wf_parameter_list_t();
195 										      l_event_name := l_status_changed_event;
196 
197 										    l_event_key := TO_CHAR(l_wf_event_seq);
198 										    WF_CORE.CONTEXT('Enterprise Asset Management...','Work Order Status change event','Building parameter list');
199 										    -- Add Parameters
200 										    Wf_Event.AddParameterToList(p_name =>'WIP_ENTITY_ID',
201 													    p_value => TO_CHAR(p_eam_wo_rec.wip_entity_id),
202 													    p_parameterlist => l_parameter_list);
203 										    Wf_Event.AddParameterToList(p_name =>'WIP_ENTITY_NAME',
204 													    p_value =>p_eam_wo_rec.wip_entity_name,
205 													    p_parameterlist => l_parameter_list);
206 										    Wf_Event.AddParameterToList(p_name =>'ORGANIZATION_ID',
207 													    p_value => TO_CHAR(p_eam_wo_rec.organization_id),
208 													    p_parameterlist => l_parameter_list);
209 										    Wf_Event.AddParameterToList(p_name =>'NEW_SYSTEM_STATUS',
210 													    p_value => TO_CHAR(p_eam_wo_rec.status_type),
211 													    p_parameterlist => l_parameter_list);
212 										    Wf_Event.AddParameterToList(p_name =>'NEW_WO_STATUS',
213 													    p_value => TO_CHAR(p_eam_wo_rec.user_defined_status_id),
214 													    p_parameterlist => l_parameter_list);
215 										   Wf_Event.AddParameterToList(p_name =>'OLD_SYSTEM_STATUS',
216 													    p_value => TO_CHAR(p_old_eam_wo_rec.status_type),
217 													    p_parameterlist => l_parameter_list);
218 										    Wf_Event.AddParameterToList(p_name =>'OLD_WO_STATUS',
219 													    p_value => TO_CHAR(p_old_eam_wo_rec.user_defined_status_id),
220 													    p_parameterlist => l_parameter_list);
221 										      Wf_Event.AddParameterToList(p_name =>'WORKFLOW_TYPE',
222 													    p_value => TO_CHAR(p_eam_wo_rec.workflow_type),
223 													    p_parameterlist => l_parameter_list);
224 										      Wf_Event.AddParameterToList(p_name =>'REQUESTOR',
225 													    p_value =>FND_GLOBAL.USER_NAME ,
226 													    p_parameterlist => l_parameter_list);
227 										    Wf_Core.Context('Enterprise Asset Management...','Work Order Staus Changed Event','Raising event');
228 
229 										    Wf_Event.Raise(	p_event_name => l_event_name,
230 													p_event_key => l_event_key,
231 													p_parameters => l_parameter_list);
232 										    l_parameter_list.DELETE;
233 										     WF_CORE.CONTEXT('Enterprise Asset Management..','Work Order Status Changed Event','After raising event');
234 			END IF;   --end of check for status change event
235 
236 			--if status change needs approval
237 			IF( p_approval_required
238 			    AND (WF_EVENT.TEST(l_status_pending_event) <> 'NONE')  --event is enabled
239 			   ) THEN
240 
241 			                                                                 --Find the total estimated cost of workorder
242 											   BEGIN
243 												 SELECT NVL((SUM(system_estimated_mat_cost) + SUM(system_estimated_lab_cost) + SUM(system_estimated_eqp_cost)),0)
244 												 INTO l_cost_estimate
245 												 FROM WIP_EAM_PERIOD_BALANCES
246 												 WHERE wip_entity_id = p_eam_wo_rec.wip_entity_id;
247 											   EXCEPTION
248 											      WHEN NO_DATA_FOUND THEN
249 												  l_cost_estimate := 0;
250 											   END;
251 
252 
253 										      SELECT EAM_WORKFLOW_EVENT_S.NEXTVAL
254 										      INTO l_wf_event_seq
255 										      FROM DUAL;
256 
257 										      l_parameter_list := wf_parameter_list_t();
258 										      l_event_name := l_status_pending_event;
259 
260 										     l_event_key := TO_CHAR(l_wf_event_seq);
261 
262 
263 										      INSERT INTO EAM_WO_WORKFLOWS
264 										     (WIP_ENTITY_ID,WF_ITEM_TYPE,WF_ITEM_KEY,LAST_UPDATE_DATE,LAST_UPDATED_BY,
265 										     CREATION_DATE,CREATED_BY,LAST_UPDATE_LOGIN)
266 										     VALUES
267 										     (p_eam_wo_rec.wip_entity_id,p_workflow_name,l_event_key,SYSDATE,FND_GLOBAL.user_id,
268 										     SYSDATE,FND_GLOBAL.user_id,FND_GLOBAL.login_id
269 										     );
270 
271 
272 										    WF_CORE.CONTEXT('Enterprise Asset Management...','Work Order Released change event','Building parameter list');
273 										    -- Add Parameters
274 										    Wf_Event.AddParameterToList(p_name =>'WIP_ENTITY_ID',
275 													    p_value => TO_CHAR(p_eam_wo_rec.wip_entity_id),
276 													    p_parameterlist => l_parameter_list);
277 										    Wf_Event.AddParameterToList(p_name =>'WIP_ENTITY_NAME',
278 													    p_value =>p_eam_wo_rec.wip_entity_name,
279 													    p_parameterlist => l_parameter_list);
280 										     Wf_Event.AddParameterToList(p_name =>'DESCRIPTION',
281 													    p_value =>p_eam_wo_rec.description,
282 													    p_parameterlist => l_parameter_list);
283 										    Wf_Event.AddParameterToList(p_name =>'ORGANIZATION_ID',
284 													    p_value => TO_CHAR(p_eam_wo_rec.organization_id),
285 													    p_parameterlist => l_parameter_list);
286 										    Wf_Event.AddParameterToList(p_name =>'NEW_WO_STATUS',
287 													    p_value => TO_CHAR(p_eam_wo_rec.user_defined_status_id),
288 													    p_parameterlist => l_parameter_list);
289 										   Wf_Event.AddParameterToList(p_name =>'OLD_SYSTEM_STATUS',
290 													    p_value => TO_CHAR(p_old_eam_wo_rec.status_type),
291 													    p_parameterlist => l_parameter_list);
292 										    Wf_Event.AddParameterToList(p_name =>'OLD_WO_STATUS',
293 													    p_value => TO_CHAR(p_old_eam_wo_rec.user_defined_status_id),
294 													    p_parameterlist => l_parameter_list);
295 										    Wf_Event.AddParameterToList(p_name =>'NEW_SYSTEM_STATUS',
296 													    p_value => TO_CHAR(p_new_system_status),
297 													    p_parameterlist => l_parameter_list);
298 										     Wf_Event.AddParameterToList(p_name =>'WORKFLOW_TYPE',
299 													    p_value => TO_CHAR(p_eam_wo_rec.workflow_type),
300 													    p_parameterlist => l_parameter_list);
301 										     Wf_Event.AddParameterToList(p_name =>'REQUESTOR',
302 													    p_value =>FND_GLOBAL.USER_NAME ,
303 													    p_parameterlist => l_parameter_list);
304 										     Wf_Event.AddParameterToList(p_name =>'WARRANTY_STATUS',
305 													    p_value => TO_CHAR(p_eam_wo_rec.warranty_claim_status),
306 													    p_parameterlist => l_parameter_list);
307 										     Wf_Event.AddParameterToList(p_name =>'WORKFLOW_NAME',
308 													    p_value => p_workflow_name,
309 													    p_parameterlist => l_parameter_list);
310 										     Wf_Event.AddParameterToList(p_name =>'WORKFLOW_PROCESS',
311 													    p_value => p_workflow_process,
312 													    p_parameterlist => l_parameter_list);
313 										     Wf_Event.AddParameterToList(p_name =>'ESTIMATED_COST',
314 													    p_value => TO_CHAR(l_cost_estimate),
315 													    p_parameterlist => l_parameter_list);
316 										    Wf_Core.Context('Enterprise Asset Management...','Work Order Released Event','Raising event');
317 
318 										    Wf_Event.Raise(	p_event_name => l_event_name,
319 													p_event_key => l_event_key,
320 													p_parameters => l_parameter_list);
321 										    l_parameter_list.DELETE;
322 										     WF_CORE.CONTEXT('Enterprise Asset Management...','Work Order Released Event','After raising event');
323 
324 
325 
326 
327 			END IF;  --end of check for status change pending event
328 
329  EXCEPTION
330 WHEN OTHERS THEN
331 		WF_CORE.CONTEXT('Enterprise Asset Management...',l_event_name,'Exception during event construction and raise: ' || SQLERRM);
332 		x_return_status := FND_API.G_RET_STS_ERROR;
333  END RAISE_WORKFLOW_EVENTS;
334 
335 
336 
337 PROCEDURE UPDATE_INTERMEDIA_INDEX
338 (
339    p_eam_wo_rec             IN     EAM_PROCESS_WO_PUB.eam_wo_rec_type,
340    p_old_eam_wo_rec     IN     EAM_PROCESS_WO_PUB.eam_wo_rec_type,
341    p_eam_op_tbl               IN     EAM_PROCESS_WO_PUB.eam_op_tbl_type,
342    p_eam_res_tbl              IN      EAM_PROCESS_WO_PUB.eam_res_tbl_type,
343    p_eam_res_inst_tbl      IN       EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
344 )
345 IS
346     l_update_index     BOOLEAN;
347 BEGIN
348      l_update_index := FALSE;
349 
350 
351      IF(p_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PUB.G_OPR_CREATE)
352         THEN
353 
354 										     EAM_TEXT_UTIL.PROCESS_WO_EVENT
355 										     (
356 										          p_event  => 'INSERT',
357 											  p_wip_entity_id =>p_eam_wo_rec.wip_entity_id,
358 											  p_organization_id =>p_eam_wo_rec.organization_id,
359 											  p_last_update_date  => SYSDATE,
360 											  p_last_updated_by  => FND_GLOBAL.user_id,
361 											  p_last_update_login =>FND_GLOBAL.login_id
362 										     );
363 		RETURN;
364      END IF;
365 
366          IF (p_eam_wo_rec.transaction_type = G_OPR_UPDATE AND
367 	     ((NVL(p_eam_wo_rec.description,'') <> NVL(p_old_eam_wo_rec.description,''))  OR
368 	         (p_eam_wo_rec.maintenance_object_id <> p_old_eam_wo_rec.maintenance_object_id) OR
369 		 (p_eam_wo_rec.user_defined_status_id <> p_old_eam_wo_rec.user_defined_status_id) OR
370 		 (NVL(p_eam_wo_rec.asset_activity_id,-1) <> NVL(p_old_eam_wo_rec.asset_activity_id,-1))
371 		 OR (NVL(p_eam_wo_rec.owning_department,-1) <> NVL(p_old_eam_wo_rec.owning_department,-1))
372 		 OR (NVL(p_eam_wo_rec.project_id,-1) <> NVL(p_old_eam_wo_rec.project_id,-1))
373 		 OR (NVL(p_eam_wo_rec.task_id,-1) <> NVL(p_old_eam_wo_rec.task_id,-1))
374 		 OR (NVL(p_eam_wo_rec.priority,-1) <> NVL(p_old_eam_wo_rec.priority,-1))
375 		 OR (NVL(p_eam_wo_rec.work_order_type,'') <> NVL(p_old_eam_wo_rec.work_order_type,''))
376 		 OR (NVL(p_eam_wo_rec.activity_type,'') <> NVL(p_old_eam_wo_rec.activity_type,''))
377 		 OR (NVL(p_eam_wo_rec.activity_cause,'') <> NVL(p_old_eam_wo_rec.activity_cause,''))
378 		 OR (NVL(p_eam_wo_rec.activity_source,'') <> NVL(p_old_eam_wo_rec.activity_source,''))
379 	     )
380 	 ) THEN
381 	    l_update_index := TRUE;
382       END IF;
383 
384       IF(l_update_index = FALSE) THEN
385             IF(p_eam_op_tbl IS NOT NULL AND p_eam_op_tbl.COUNT>0) THEN
386                         FOR i IN  p_eam_op_tbl.FIRST ..  p_eam_op_tbl.LAST LOOP
387                                     IF(p_eam_op_tbl(i).transaction_type = EAM_PROCESS_WO_PUB.G_OPR_CREATE
388 				                            OR p_eam_op_tbl(i).transaction_type = EAM_PROCESS_WO_PUB.G_OPR_DELETE) THEN
389 							    l_update_index:=TRUE;
390 							    EXIT;
391                                     END IF;
392                          END LOOP;
393          END IF;
394       END IF;
395 
396        IF(l_update_index = FALSE) THEN
397             IF(p_eam_res_tbl IS NOT NULL AND p_eam_res_tbl.COUNT>0) THEN
398                         FOR i IN  p_eam_res_tbl.FIRST ..  p_eam_res_tbl.LAST LOOP
399                                     IF(p_eam_res_tbl(i).transaction_type = EAM_PROCESS_WO_PUB.G_OPR_CREATE
400 				                            OR p_eam_res_tbl(i).transaction_type = EAM_PROCESS_WO_PUB.G_OPR_DELETE) THEN
401 							    l_update_index:=TRUE;
402 							    EXIT;
403                                     END IF;
404                          END LOOP;
405          END IF;
406       END IF;
407 
408        IF(l_update_index = FALSE) THEN
409             IF(p_eam_res_inst_tbl IS NOT NULL AND p_eam_res_inst_tbl.COUNT>0) THEN
410                         FOR i IN  p_eam_res_inst_tbl.FIRST ..  p_eam_res_inst_tbl.LAST LOOP
411                                     IF(p_eam_res_inst_tbl(i).transaction_type = EAM_PROCESS_WO_PUB.G_OPR_CREATE
412 				                            OR p_eam_res_inst_tbl(i).transaction_type = EAM_PROCESS_WO_PUB.G_OPR_DELETE) THEN
413 							    l_update_index:=TRUE;
414 							    EXIT;
415                                     END IF;
416                          END LOOP;
417          END IF;
418       END IF;
419 
420       IF(l_update_index = TRUE) THEN
421 										     EAM_TEXT_UTIL.PROCESS_WO_EVENT
422 										     (
423 										          p_event  => 'UPDATE',
424 											  p_wip_entity_id =>p_eam_wo_rec.wip_entity_id,
425 											  p_organization_id =>p_eam_wo_rec.organization_id,
426 											  p_last_update_date  => SYSDATE,
427 											  p_last_updated_by  => FND_GLOBAL.user_id,
428 											  p_last_update_login =>FND_GLOBAL.login_id
429 										     );
430       END IF;
431 
432 END UPDATE_INTERMEDIA_INDEX;
433 
434 
435 
436 
437 PROCEDURE RESOURCE_USAGES
438         (  p_validation_level        IN  NUMBER
439         ,  p_wip_entity_id           IN  NUMBER := NULL
440         ,  p_organization_id         IN  NUMBER := NULL
441         ,  p_operation_seq_num       IN  NUMBER := NULL
442 	,  p_resource_seq_num        IN  NUMBER := NULL
443         ,  p_eam_res_usage_tbl       IN EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
444 	,  x_bottomup_scheduled      IN OUT NOCOPY NUMBER
445         ,  x_eam_res_usage_tbl       OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
446         ,  x_mesg_token_tbl          OUT NOCOPY EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type
447         ,  x_return_status           OUT NOCOPY VARCHAR2
448         )
449 IS
450 
451 l_eam_res_usage_rec     EAM_PROCESS_WO_PUB.eam_res_usage_rec_type ;
452 l_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type ;
453 
454 l_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type ;
455 l_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type ;
456 l_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type ;
457 l_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type ;
458 l_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type ;
459 l_eam_sub_res_rec      EAM_PROCESS_WO_PUB.eam_sub_res_rec_type ;
460 l_eam_sub_res_tbl      EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type ;
461 l_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type ;
462 l_eam_direct_items_tbl  EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type ;
463 
464         l_out_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type;
465         l_out_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type;
466         l_out_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
467         l_out_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type;
468         l_out_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
469         l_out_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
470         l_out_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
471         l_out_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
472         l_out_eam_direct_items_tbl  EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
473         l_out_mesg_token_tbl        EAM_ERROR_MESSAGE_PVT.mesg_token_tbl_type;
474 
475 /* Error Handling Variables */
476 l_token_tbl             EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
477 l_mesg_token_tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
478 l_other_token_tbl       EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
479 l_other_message         VARCHAR2(2000);
480 l_err_text              VARCHAR2(2000);
481 
482 /* Others */
483 l_return_status         VARCHAR2(1) ;
484 l_bo_return_status      VARCHAR2(1) ;
485 l_parent_exists         BOOLEAN := FALSE ;
486 l_process_children      BOOLEAN := TRUE ;
487 l_valid_transaction     BOOLEAN := TRUE ;
488 
489 
490 BEGIN
491 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(p_eam_res_usage_tbl.COUNT ||' records passed') ; END IF ;
492 
493    x_return_status := FND_API.G_RET_STS_SUCCESS;
494 
495 --  Init local table variables.
496    l_return_status    := 'S' ;
497    l_bo_return_status := 'S' ;
498    l_eam_res_usage_tbl:= p_eam_res_usage_tbl ;
499 
500 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Starting RESOURCE_USAGES') ; END IF ;
501 
502 
503    FOR I IN 1..l_eam_res_usage_tbl.COUNT LOOP
504    BEGIN
505 
506 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Processing '|| I || ' record') ; END IF ;
507 
508       --  Load local records.
509       l_eam_res_usage_rec := l_eam_res_usage_tbl(I);
510 
511       -- make sure to set process_children to false at the start of every iteration
512 
513       l_process_children := FALSE;
514 
515 
516       IF l_eam_res_usage_rec.wip_entity_id is NULL
517          AND (l_eam_res_usage_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
518              OR l_eam_res_usage_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_SYNC)
519       THEN
520           l_eam_res_usage_rec.wip_entity_id := p_wip_entity_id;
521       END IF;
522 
523       IF p_wip_entity_id IS NOT NULL AND
524          p_organization_id IS NOT NULL AND
525          p_operation_seq_num IS NOT NULL AND
526 	 p_resource_seq_num IS NOT NULL
527       THEN
528          l_parent_exists := TRUE;
529       END IF;
530 
531       -- Check if record has not yet been processed and that it is the child of the parent that called this procedure
532 
533       IF (l_eam_res_usage_rec.return_status IS NULL OR l_eam_res_usage_rec.return_status = FND_API.G_MISS_CHAR)
534            AND
535            (NOT l_parent_exists
536             OR
537              (l_parent_exists AND
538               l_eam_res_usage_rec.wip_entity_id = p_wip_entity_id AND
539               l_eam_res_usage_rec.organization_id = p_organization_id AND
540               l_eam_res_usage_rec.operation_seq_num = p_operation_seq_num AND
541 	      l_eam_res_usage_rec.resource_seq_num = p_resource_seq_num
542              )
543            )
544       THEN
545 
546 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Return status validation passed') ; END IF ;
547 
548 
549          l_return_status := FND_API.G_RET_STS_SUCCESS;
550          l_eam_res_usage_rec.return_status := FND_API.G_RET_STS_SUCCESS;
551 
552         VALIDATE_TRANSACTION_TYPE
553         (   p_transaction_type  => l_eam_res_usage_rec.transaction_type
554         ,   p_entity_name       => 'RESOURCE_SEQ_NUM'
555         ,   p_entity_id         => to_char(l_eam_res_usage_rec.resource_seq_num)
556         ,   X_valid_transaction => l_valid_transaction
557         ,   x_mesg_token_tbl    => l_mesg_token_tbl
558         );
559 
560          IF NOT l_valid_transaction
561          THEN
562              l_return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
563              RAISE EXC_SEV_QUIT_RECORD ;
564          END IF ;
565 
566 
567          EAM_RES_USAGE_VALIDATE_PVT.Check_Required
568          ( p_eam_res_usage_rec          => l_eam_res_usage_rec
569          , x_return_status              => l_return_status
570          , x_mesg_token_tbl             => l_mesg_token_tbl
571          ) ;
572 
573 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check required completed with return_status: ' || l_return_status) ; END IF ;
574 
575          IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
576          THEN
577             IF l_eam_res_usage_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
578             THEN
579                l_other_message := 'EAM_RU_REQ_CSEV_SKIP';
580                l_other_token_tbl(1).token_name  := 'RESOURCE_SEQ_NUM';
581                l_other_token_tbl(1).token_value := l_eam_res_usage_rec.resource_seq_num ;
582                RAISE EXC_SEV_SKIP_BRANCH ;
583             ELSE
584                RAISE EXC_SEV_QUIT_RECORD ;
585             END IF;
586          ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
587          THEN
588             l_other_message := 'EAM_RU_REQ_UNEXP_SKIP';
589             l_other_token_tbl(1).token_name  := 'RESOURCE_SEQ_NUM';
590             l_other_token_tbl(1).token_value := l_eam_res_usage_rec.resource_seq_num ;
591             RAISE EXC_UNEXP_SKIP_OBJECT ;
592          END IF;
593 
594 
595             EAM_RES_USAGE_VALIDATE_PVT.Check_Attributes
596             ( p_eam_res_usage_rec    => l_eam_res_usage_rec
597             , x_return_status        => l_return_status
598             , x_mesg_token_tbl       => l_mesg_token_tbl
599             );
600 
601 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Attribute validation completed with return_status: ' || l_return_status) ; END IF ;
602 
603             IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
604             THEN
605                IF l_eam_res_usage_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
606                THEN
607                   l_other_message := 'EAM_RU_ATTVAL_CSEV_SKIP';
608                   l_other_token_tbl(1).token_name := 'RESOURCE_SEQ_NUM';
609                   l_other_token_tbl(1).token_value := l_eam_res_usage_rec.resource_seq_num ;
610                   RAISE EXC_SEV_SKIP_BRANCH ;
611                   ELSE
612                      RAISE EXC_SEV_QUIT_RECORD ;
613                END IF;
614             ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
615             THEN
616                l_other_message := 'EAM_RU_ATTVAL_UNEXP_SKIP';
617                l_other_token_tbl(1).token_name := 'RESOURCE_SEQ_NUM';
618                l_other_token_tbl(1).token_value := l_eam_res_usage_rec.resource_seq_num ;
619                RAISE EXC_UNEXP_SKIP_OBJECT ;
620             ELSIF l_return_status ='S' AND l_mesg_token_tbl .COUNT <> 0
621             THEN
622               l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
623               EAM_ERROR_MESSAGE_PVT.Log_Error
624                (  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
625                ,  p_mesg_token_tbl         => l_mesg_token_tbl
626                ,  p_error_status           => 'W'
627                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_USAGE_LEVEL
628                ,  p_entity_index           => I
629                ,  x_eam_wo_rec             => l_eam_wo_rec
630                ,  x_eam_op_tbl             => l_eam_op_tbl
631                ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
632                ,  x_eam_res_tbl            => l_eam_res_tbl
633                ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
634                ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
635                ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
636                ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
637                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
638                );
639               l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
640 
641            END IF;
642 
643 	/* Bug 5224748. Call Add_usage only for non firm work orders. For firm wos, Bottom Up should handle the insertions*/
644 	IF ( x_bottomup_scheduled = G_NON_FIRM_WORKORDER ) THEN
645 
646           EAM_RES_USAGE_UTILITY_PVT.Add_Usage
647           (  p_eam_res_usage_rec   => l_eam_res_usage_rec
648           ,  x_mesg_token_tbl      => l_mesg_token_tbl
649           ,  x_return_status       => l_return_status
650           );
651 
652 
653        IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
654        THEN
655           l_other_message := 'EAM_RU_WRITES_UNEXP_SKIP';
656           l_other_token_tbl(1).token_name := 'RESOURCE_SEQ_NUM';
657           l_other_token_tbl(1).token_value := l_eam_res_usage_rec.resource_seq_num ;
658           RAISE EXC_UNEXP_SKIP_OBJECT ;
659        ELSIF l_return_status ='S' AND
660           l_mesg_token_tbl.COUNT <>0
661        THEN
662             l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
663             EAM_ERROR_MESSAGE_PVT.Log_Error
664                (  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
665                ,  p_mesg_token_tbl         => l_mesg_token_tbl
666                ,  p_error_status           => 'W'
667                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_USAGE_LEVEL
668                ,  p_entity_index           => I
669                ,  x_eam_wo_rec             => l_eam_wo_rec
670                ,  x_eam_op_tbl             => l_eam_op_tbl
671                ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
672                ,  x_eam_res_tbl            => l_eam_res_tbl
673                ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
674                ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
675                ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
676                ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
677                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
678                );
679             l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
680        END IF;
681 
682 	IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Resources Database writes completed with status  ' || l_return_status); END IF;
683    END IF ; -- bug 5224748. end of check for x_bottomup_scheduled = G_NON_FIRM_WORKORDER
684 
685  ELSE
686 
687 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Skipping '|| I || ' record') ; END IF ;
688 
689     END IF; -- END IF statement that checks RETURN STATUS
690 
691     --find if bottom up scheduler is to be called or not
692 
693 	     IF(l_eam_res_usage_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE   -- is resource usage is added
694 	             OR (l_eam_res_usage_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_DELETE ) --deleted
695 		     OR (l_eam_res_usage_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_UPDATE AND  --updating the resource usage
696 
697 		       (
698 		       --NVL(l_eam_res_rec.schedule_seq_num,l_eam_res_rec.resource_seq_num)<>NVL(l_old_eam_res_rec.schedule_seq_num,l_old_eam_res_rec.resource_seq_num)
699 		        -- OR
700 			l_eam_res_usage_rec.start_date <> l_eam_res_usage_rec.old_start_date   --shedule_seq_num,start_date,completion_date
701 			OR l_eam_res_usage_rec.completion_date <> l_eam_res_usage_rec.old_completion_date
702 		--	OR l_eam_res_rec.resource_id <> l_old_eam_res_rec.resource_id    --resource_code,usage_rate_or_amount,scheduled_flag,assigned_units
703 		--	OR l_eam_res_rec.usage_rate_or_amount <> l_old_eam_res_rec.usage_rate_or_amount
704 		--	OR l_eam_res_rec.scheduled_flag <> l_old_eam_res_rec.scheduled_flag
705 		--	OR NVL(l_eam_res_rec.assigned_units,0) <> NVL(l_old_eam_res_rec.assigned_units,0)
706 			)
707 		    )
708 		) THEN
709 		     x_bottomup_scheduled := G_UPDATE_RES_USAGE;
710 	     END IF;
711 
712     --  Load tables.
713     l_eam_res_usage_tbl(I)          := l_eam_res_usage_rec;
714 
715 
716     -- Indicate that children need to be processed
717     l_process_children := TRUE;
718 
719     --  For loop exception handler.
720 
721     EXCEPTION
722        WHEN EXC_SEV_QUIT_RECORD THEN
723         l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
724         EAM_ERROR_MESSAGE_PVT.Log_Error
725         (  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
726         ,  p_mesg_token_tbl         => l_mesg_token_tbl
727         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
728         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
729         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_USAGE_LEVEL
730         ,  p_entity_index           => I
731         ,  x_eam_wo_rec             => l_eam_wo_rec
732         ,  x_eam_op_tbl             => l_eam_op_tbl
733         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
734         ,  x_eam_res_tbl            => l_eam_res_tbl
735         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
736         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
737         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
738         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
739         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
740         );
741         l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
742 
743          l_process_children             := FALSE;
744 
745          IF l_bo_return_status = 'S'
746          THEN
747              l_bo_return_status  := l_return_status ;
748          END IF;
749 
750          x_return_status                := l_bo_return_status;
751          x_mesg_token_tbl               := l_mesg_token_tbl ;
752          x_eam_res_usage_tbl              := l_eam_res_usage_tbl;
753 
754 
755       WHEN EXC_SEV_QUIT_BRANCH THEN
756        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
757        EAM_ERROR_MESSAGE_PVT.Log_Error
758         (  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
759         ,  p_mesg_token_tbl         => l_mesg_token_tbl
760         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
761         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
762         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
763         ,  p_other_message          => l_other_message
764         ,  p_other_token_tbl        => l_other_token_tbl
765         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_USAGE_LEVEL
766         ,  p_entity_index           => I
767         ,  x_eam_wo_rec             => l_eam_wo_rec
768         ,  x_eam_op_tbl             => l_eam_op_tbl
769         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
770         ,  x_eam_res_tbl            => l_eam_res_tbl
771         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
772         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
773         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
774         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
775         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
776         );
777        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
778 
779          l_process_children             := FALSE ;
780 
781          IF l_bo_return_status = 'S'
782          THEN
783              l_bo_return_status  := l_return_status ;
784          END IF;
785 
786          x_return_status                := l_bo_return_status;
787          x_mesg_token_tbl               := l_mesg_token_tbl ;
788          x_eam_res_usage_tbl              := l_eam_res_usage_tbl;
789 
790 
791       WHEN EXC_SEV_SKIP_BRANCH THEN
792        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
793        EAM_ERROR_MESSAGE_PVT.Log_Error
794         (  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
795         ,  p_mesg_token_tbl         => l_mesg_token_tbl
796         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
797         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
798         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_NOT_PICKED
799         ,  p_other_message          => l_other_message
800         ,  p_other_token_tbl        => l_other_token_tbl
801         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_USAGE_LEVEL
802         ,  p_entity_index           => I
803         ,  x_eam_wo_rec             => l_eam_wo_rec
804         ,  x_eam_op_tbl             => l_eam_op_tbl
805         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
806         ,  x_eam_res_tbl            => l_eam_res_tbl
807         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
808         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
809         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
810         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
811         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
812         );
813        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
814 
815 
816          l_process_children             := FALSE ;
817 
818          IF l_bo_return_status = 'S'
819          THEN
820              l_bo_return_status  := l_return_status ;
821          END IF;
822 
823          x_return_status                := l_bo_return_status;
824          x_mesg_token_tbl               := l_mesg_token_tbl ;
825          x_eam_res_usage_tbl              := l_eam_res_usage_tbl;
826 
827 
828       WHEN EXC_SEV_QUIT_SIBLINGS THEN
829        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
830        EAM_ERROR_MESSAGE_PVT.Log_Error
831         (  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
832         ,  p_mesg_token_tbl         => l_mesg_token_tbl
833         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
834         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_SIBLINGS
835         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
836         ,  p_other_message          => l_other_message
837         ,  p_other_token_tbl        => l_other_token_tbl
838         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_USAGE_LEVEL
839         ,  p_entity_index           => I
840         ,  x_eam_wo_rec             => l_eam_wo_rec
841         ,  x_eam_op_tbl             => l_eam_op_tbl
842         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
843         ,  x_eam_res_tbl            => l_eam_res_tbl
844         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
845         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
846         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
847         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
848         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
849         );
850        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
851 
852          l_process_children             := FALSE ;
853 
854          IF l_bo_return_status = 'S'
855          THEN
856              l_bo_return_status  := l_return_status ;
857          END IF;
858 
859          x_return_status                := l_bo_return_status;
860          x_mesg_token_tbl               := l_mesg_token_tbl ;
861          x_eam_res_USAGE_tbl              := l_eam_res_USAGE_tbl;
862 
863 
864       WHEN EXC_FAT_QUIT_BRANCH THEN
865        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
866        EAM_ERROR_MESSAGE_PVT.Log_Error
867         (  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
868         ,  p_mesg_token_tbl         => l_mesg_token_tbl
869         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
870         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
871         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
872         ,  p_other_message          => l_other_message
873         ,  p_other_token_tbl        => l_other_token_tbl
874         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_USAGE_LEVEL
875         ,  p_entity_index           => I
876         ,  x_eam_wo_rec             => l_eam_wo_rec
877         ,  x_eam_op_tbl             => l_eam_op_tbl
878         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
879         ,  x_eam_res_tbl            => l_eam_res_tbl
880         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
881         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
882         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
883         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
884         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
885         );
886        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
887 
888          l_process_children             := FALSE ;
889          x_return_status                := EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL;
890          x_mesg_token_tbl               := l_mesg_token_tbl ;
891          x_eam_res_usage_tbl              := l_eam_res_usage_tbl;
892 
893 
894       WHEN EXC_FAT_QUIT_SIBLINGS THEN
895        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
896        EAM_ERROR_MESSAGE_PVT.Log_Error
897         (  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
898         ,  p_mesg_token_tbl         => l_mesg_token_tbl
899         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
900         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_SIBLINGS
901         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
902         ,  p_other_message          => l_other_message
903         ,  p_other_token_tbl        => l_other_token_tbl
904         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_USAGE_LEVEL
905         ,  p_entity_index           => I
906         ,  x_eam_wo_rec             => l_eam_wo_rec
907         ,  x_eam_op_tbl             => l_eam_op_tbl
908         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
909         ,  x_eam_res_tbl            => l_eam_res_tbl
910         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
911         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
912         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
913         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
914         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
915         );
916         l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
917 
918          l_process_children             := FALSE ;
919          x_return_status                := EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL;
920          x_mesg_token_tbl               := l_mesg_token_tbl ;
921          x_eam_res_usage_tbl              := l_eam_res_usage_tbl;
922 
923 
924       WHEN EXC_UNEXP_SKIP_OBJECT THEN
925        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
926        EAM_ERROR_MESSAGE_PVT.Log_Error
927         (  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
928         ,  p_mesg_token_tbl         => l_mesg_token_tbl
929         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
930         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_NOT_PICKED
931         ,  p_other_message          => l_other_message
932         ,  p_other_token_tbl        => l_other_token_tbl
933         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_USAGE_LEVEL
934         ,  x_eam_wo_rec             => l_eam_wo_rec
935         ,  x_eam_op_tbl             => l_eam_op_tbl
936         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
937         ,  x_eam_res_tbl            => l_eam_res_tbl
938         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
939         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
940         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
941         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
942         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
943         );
944        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
945 
946 
947          l_return_status                := 'U';
948          x_mesg_token_tbl               := l_mesg_token_tbl ;
949          x_eam_res_usage_tbl              := l_eam_res_usage_tbl;
950 
951    END ; -- END block
952 
953    IF l_return_status in ('Q', 'U')
954    THEN
955       x_return_status := l_return_status;
956       RETURN ;
957    END IF;
958 
959 
960    END LOOP; -- END Resources processing loop
961 
962 
963 
964    --  Load OUT parameters
965    IF NVL(l_return_status, 'S') <> 'S'
966    THEN
967       x_return_status     := l_return_status;
968    END IF;
969 
970 
971         x_Mesg_Token_Tbl               := l_Mesg_Token_Tbl;
972         x_eam_res_usage_tbl              := l_eam_res_usage_tbl;
973 
974 END RESOURCE_USAGES;
975 
976 
977 
978 
979 
980 
981 
982 
983 
984 
985 
986 
987 
988 
989 PROCEDURE SUB_RESOURCES
990         (  p_validation_level        IN  NUMBER
991         ,  p_wip_entity_id           IN  NUMBER := NULL
992         ,  p_organization_id         IN  NUMBER := NULL
993         ,  p_operation_seq_num       IN  NUMBER := NULL
994         ,  p_eam_sub_res_tbl         IN EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
995         ,  p_eam_res_usage_tbl       IN EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
996 	,  x_bottomup_scheduled      IN OUT NOCOPY NUMBER
997         ,  x_eam_sub_res_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
998         ,  x_eam_res_usage_tbl       OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
999         ,  x_mesg_token_tbl          OUT NOCOPY EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type
1000         ,  x_return_status           OUT NOCOPY VARCHAR2
1001         )
1002 IS
1003 
1004 l_eam_sub_res_rec      EAM_PROCESS_WO_PUB.eam_sub_res_rec_type ;
1005 l_eam_sub_res_tbl      EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type ;
1006 l_old_eam_sub_res_rec  EAM_PROCESS_WO_PUB.eam_sub_res_rec_type ;
1007 
1008 l_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type ;
1009 l_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type ;
1010 l_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type ;
1011 l_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type ;
1012 l_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type ;
1013 l_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type ;
1014 l_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type ;
1015 l_eam_direct_items_tbl  EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type ;
1016 
1017 l_out_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1018 l_out_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1019 l_out_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1020 l_out_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1021 l_out_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1022 l_out_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1023 l_out_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1024 l_out_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1025 l_out_mesg_token_tbl        EAM_ERROR_MESSAGE_PVT.mesg_token_tbl_type;
1026 l_out_eam_sub_res_rec   EAM_PROCESS_WO_PUB.eam_sub_res_rec_type;
1027 
1028 /* Error Handling Variables */
1029 l_token_tbl             EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
1030 l_mesg_token_tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
1031 l_other_token_tbl       EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
1032 l_other_message         VARCHAR2(2000);
1033 l_err_text              VARCHAR2(2000);
1034 
1035 /* Others */
1036 l_return_status         VARCHAR2(1) ;
1037 l_bo_return_status      VARCHAR2(1) ;
1038 l_parent_exists         BOOLEAN := FALSE ;
1039 l_process_children      BOOLEAN := TRUE ;
1040 l_valid_transaction     BOOLEAN := TRUE ;
1041 
1042 
1043 BEGIN
1044 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(p_eam_sub_res_tbl.COUNT ||' records passed') ; END IF ;
1045 
1046    x_return_status := FND_API.G_RET_STS_SUCCESS;
1047 
1048 --  Init local table variables.
1049    l_return_status    := 'S' ;
1050    l_bo_return_status := 'S' ;
1051    l_eam_sub_res_tbl  := p_eam_sub_res_tbl ;
1052 
1053 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Starting SUB_RESOURCE') ; END IF ;
1054 
1055    FOR I IN 1..l_eam_sub_res_tbl.COUNT LOOP
1056    BEGIN
1057 
1058 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Processing '|| I || ' record') ; END IF ;
1059 
1060       --  Load local records.
1061       l_eam_sub_res_rec := l_eam_sub_res_tbl(I);
1062 
1063       -- make sure to set process_children to false at the start of every iteration
1064 
1065       l_process_children := FALSE;
1066 
1067 
1068 
1069       IF l_eam_sub_res_rec.wip_entity_id is NULL
1070          AND (l_eam_sub_res_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
1071              OR l_eam_sub_res_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_SYNC)
1072       THEN
1073           l_eam_sub_res_rec.wip_entity_id := p_wip_entity_id;
1074       END IF;
1075 
1076       IF p_wip_entity_id IS NOT NULL AND
1077          p_organization_id IS NOT NULL AND
1078          p_operation_seq_num IS NOT NULL
1079       THEN
1080          l_parent_exists := TRUE;
1081       END IF;
1082 
1083       -- Check if record has not yet been processed and that it is the child of the parent that called this procedure
1084 
1085       IF (l_eam_sub_res_rec.return_status IS NULL OR l_eam_sub_res_rec.return_status = FND_API.G_MISS_CHAR)
1086            AND
1087            (NOT l_parent_exists
1088             OR
1089              (l_parent_exists AND
1090               l_eam_sub_res_rec.wip_entity_id = p_wip_entity_id AND
1091               l_eam_sub_res_rec.organization_id = p_organization_id AND
1092               l_eam_sub_res_rec.operation_seq_num = p_operation_seq_num
1093              )
1094            )
1095       THEN
1096 
1097 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Return status validation passed') ; END IF ;
1098 
1099 
1100          l_return_status := FND_API.G_RET_STS_SUCCESS;
1101          l_eam_sub_res_rec.return_status := FND_API.G_RET_STS_SUCCESS;
1102 
1103         VALIDATE_TRANSACTION_TYPE
1104         (   p_transaction_type  => l_eam_sub_res_rec.transaction_type
1105         ,   p_entity_name       => 'RESOURCE_SEQ_NUM'
1106         ,   p_entity_id         => to_char(l_eam_sub_res_rec.resource_seq_num)
1107         ,   X_valid_transaction => l_valid_transaction
1108         ,   x_mesg_token_tbl    => l_mesg_token_tbl
1109         );
1110 
1111          IF NOT l_valid_transaction
1112          THEN
1113              l_return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
1114              RAISE EXC_SEV_QUIT_RECORD ;
1115          END IF ;
1116 
1117          EAM_SUB_RESOURCE_VALIDATE_PVT.Check_Existence
1118          (  p_eam_sub_res_rec       => l_eam_sub_res_rec
1119          ,  x_old_eam_sub_res_rec   => l_old_eam_sub_res_rec
1120          ,  x_mesg_token_tbl             => l_mesg_token_tbl
1121          ,  x_return_status              => l_return_status
1122          ) ;
1123 
1124 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check Existence completed with return_status: ' || l_return_status) ;  END IF ;
1125 
1126          IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1127          THEN
1128             l_other_message := 'EAM_SR_EXS_SEV_SKIP';
1129             l_other_token_tbl(1).token_name  := 'RESOURCE_SEQ_NUM';
1130             l_other_token_tbl(1).token_value := l_eam_sub_res_rec.resource_seq_num;
1131             l_other_token_tbl(2).token_name  := 'WIP_ENTITY_ID';
1132             l_other_token_tbl(2).token_value := l_eam_sub_res_rec.wip_entity_id;
1133             RAISE EXC_SEV_QUIT_BRANCH;
1134          ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
1135          THEN
1136             l_other_message := 'EAM_SR_EXS_UNEXP_SKIP';
1137             l_other_token_tbl(1).token_name  := 'RESOURCE_SEQ_NUM';
1138             l_other_token_tbl(1).token_value := l_eam_sub_res_rec.resource_seq_num ;
1139             l_other_token_tbl(2).token_name  := 'WIP_ENTITY_ID';
1140             l_other_token_tbl(2).token_value := l_eam_sub_res_rec.wip_entity_id ;
1141             RAISE EXC_UNEXP_SKIP_OBJECT;
1142          END IF;
1143 
1144         /* Assign the correct transaction type for SYNC operations */
1145 
1146         IF l_eam_sub_res_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_SYNC THEN
1147            l_eam_sub_res_rec.transaction_type := l_old_eam_sub_res_rec.transaction_type;
1148         END IF;
1149 
1150 
1151         IF l_eam_sub_res_rec.transaction_type IN (EAM_PROCESS_WO_PVT.G_OPR_UPDATE, EAM_PROCESS_WO_PVT.G_OPR_DELETE)
1152         THEN
1153 
1154            IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Populate NULL columns') ;
1155            END IF ;
1156 
1157            l_out_eam_sub_res_rec := l_eam_sub_res_rec;
1158 
1159            EAM_SUB_RESOURCE_DEFAULT_PVT.Populate_Null_Columns
1160            (   p_eam_sub_res_rec        => l_eam_sub_res_rec
1161            ,   p_old_eam_sub_res_Rec    => l_old_eam_sub_res_rec
1162            ,   x_eam_sub_res_rec     => l_out_eam_sub_res_rec
1163            ) ;
1164 
1165            l_eam_sub_res_rec := l_out_eam_sub_res_rec;
1166 
1167 
1168         ELSIF l_eam_sub_res_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
1169         THEN
1170 
1171            l_out_eam_sub_res_rec := l_eam_sub_res_rec;
1172 
1173            EAM_SUB_RESOURCE_DEFAULT_PVT.Attribute_Defaulting
1174            (   p_eam_sub_res_rec   => l_eam_sub_res_rec
1175            ,   x_eam_sub_res_rec   => l_out_eam_sub_res_rec
1176            ,   x_mesg_token_tbl  => l_mesg_token_tbl
1177            ,   x_return_status   => l_return_status
1178            ) ;
1179 
1180            l_eam_sub_res_rec := l_out_eam_sub_res_rec;
1181 
1182            IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug
1183            ('Attribute Defaulting completed with return_status: ' || l_return_status) ;
1184            END IF ;
1185 
1186 
1187            IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1188            THEN
1189               l_other_message := 'EAM_SR_ATTDEF_CSEV_SKIP';
1190               l_other_token_tbl(1).token_name  := 'RESOURCE_SEQ_NUM';
1191               l_other_token_tbl(1).token_value := l_eam_sub_res_rec.resource_seq_num ;
1192               RAISE EXC_SEV_SKIP_BRANCH ;
1193 
1194            ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
1195            THEN
1196               l_other_message := 'EAM_SR_ATTDEF_UNEXP_SKIP';
1197               l_other_token_tbl(1).token_name := 'RESOURCE_SEQ_NUM';
1198               l_other_token_tbl(1).token_value := l_eam_sub_res_rec.resource_seq_num ;
1199               RAISE EXC_UNEXP_SKIP_OBJECT ;
1200            ELSIF l_return_status ='S' AND l_mesg_token_tbl .COUNT <> 0
1201            THEN
1202               l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
1203               l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
1204               EAM_ERROR_MESSAGE_PVT.Log_Error
1205                (  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
1206                ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
1207                ,  p_mesg_token_tbl         => l_mesg_token_tbl
1208                ,  p_error_status           => 'W'
1209                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_SUB_RES_LEVEL
1210                ,  p_entity_index           => I
1211                ,  x_eam_wo_rec             => l_eam_wo_rec
1212                ,  x_eam_op_tbl             => l_eam_op_tbl
1213                ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
1214                ,  x_eam_res_tbl            => l_eam_res_tbl
1215                ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
1216                ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
1217                ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
1218                ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
1219                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
1220                );
1221               l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
1222               l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
1223           END IF;
1224        END IF;
1225 
1226 
1227          EAM_SUB_RESOURCE_VALIDATE_PVT.Check_Required
1228          ( p_eam_sub_res_rec           => l_eam_sub_res_rec
1229          , x_return_status              => l_return_status
1230          , x_mesg_token_tbl             => l_mesg_token_tbl
1231          ) ;
1232 
1233 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check required completed with return_status: ' || l_return_status) ; END IF ;
1234 
1235 
1236          IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1237          THEN
1238             IF l_eam_sub_res_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
1239             THEN
1240                l_other_message := 'EAM_SR_REQ_CSEV_SKIP';
1241                l_other_token_tbl(1).token_name  := 'RESOURCE_SEQ_NUM';
1242                l_other_token_tbl(1).token_value := l_eam_sub_res_rec.resource_seq_num ;
1243                RAISE EXC_SEV_SKIP_BRANCH ;
1244             ELSE
1245                RAISE EXC_SEV_QUIT_RECORD ;
1246             END IF;
1247          ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
1248          THEN
1249             l_other_message := 'EAM_SR_REQ_UNEXP_SKIP';
1250             l_other_token_tbl(1).token_name  := 'RESOURCE_SEQ_NUM';
1251             l_other_token_tbl(1).token_value := l_eam_sub_res_rec.resource_seq_num ;
1252             RAISE EXC_UNEXP_SKIP_OBJECT ;
1253          END IF;
1254 
1255 
1256             EAM_SUB_RESOURCE_VALIDATE_PVT.Check_Attributes
1257             ( p_eam_sub_res_rec     => l_eam_sub_res_rec
1258             , p_old_eam_sub_res_rec => l_old_eam_sub_res_rec
1259             , x_return_status        => l_return_status
1260             , x_mesg_token_tbl       => l_mesg_token_tbl
1261             ) ;
1262 
1263 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Attribute validation completed with return_status: ' || l_return_status) ; END IF ;
1264 
1265             IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1266             THEN
1267                IF l_eam_sub_res_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
1268                THEN
1269                   l_other_message := 'EAM_SR_ATTVAL_CSEV_SKIP';
1270                   l_other_token_tbl(1).token_name := 'RESOURCE_SEQ_NUM';
1271                   l_other_token_tbl(1).token_value := l_eam_sub_res_rec.resource_seq_num ;
1272                   RAISE EXC_SEV_SKIP_BRANCH ;
1273                   ELSE
1274                      RAISE EXC_SEV_QUIT_RECORD ;
1275                END IF;
1276             ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
1277             THEN
1278                l_other_message := 'EAM_SR_ATTVAL_UNEXP_SKIP';
1279                l_other_token_tbl(1).token_name := 'RESOURCE_SEQ_NUM';
1280                l_other_token_tbl(1).token_value := l_eam_sub_res_rec.resource_seq_num ;
1281                RAISE EXC_UNEXP_SKIP_OBJECT ;
1282             ELSIF l_return_status ='S' AND l_mesg_token_tbl .COUNT <> 0
1283             THEN
1284               l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
1285               l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
1286               EAM_ERROR_MESSAGE_PVT.Log_Error
1287                (  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
1288                ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
1289                ,  p_mesg_token_tbl         => l_mesg_token_tbl
1290                ,  p_error_status           => 'W'
1291                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_SUB_RES_LEVEL
1292                ,  p_entity_index           => I
1293                ,  x_eam_wo_rec             => l_eam_wo_rec
1294                ,  x_eam_op_tbl             => l_eam_op_tbl
1295                ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
1296                ,  x_eam_res_tbl            => l_eam_res_tbl
1297                ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
1298                ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
1299                ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
1300                ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
1301                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
1302                );
1303               l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
1304               l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
1305 
1306            END IF;
1307 
1308           EAM_SUB_RESOURCE_UTILITY_PVT.Perform_Writes
1309           (   p_eam_sub_res_rec          => l_eam_sub_res_rec
1310           ,   x_mesg_token_tbl      => l_mesg_token_tbl
1311           ,   x_return_status       => l_return_status
1312           ) ;
1313 
1314 
1315        IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
1316        THEN
1317           l_other_message := 'EAM_SR_WRITES_UNEXP_SKIP';
1318           l_other_token_tbl(1).token_name := 'RESOURCE_SEQ_NUM';
1319           l_other_token_tbl(1).token_value := l_eam_sub_res_rec.resource_seq_num ;
1320           RAISE EXC_UNEXP_SKIP_OBJECT ;
1321        ELSIF l_return_status ='S' AND
1322           l_mesg_token_tbl.COUNT <>0
1323        THEN
1324             l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
1325             l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
1326             EAM_ERROR_MESSAGE_PVT.Log_Error
1327                (  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
1328                ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
1329                ,  p_mesg_token_tbl         => l_mesg_token_tbl
1330                ,  p_error_status           => 'W'
1331                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_SUB_RES_LEVEL
1332                ,  p_entity_index           => I
1333                ,  x_eam_wo_rec             => l_eam_wo_rec
1334                ,  x_eam_op_tbl             => l_eam_op_tbl
1335                ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
1336                ,  x_eam_res_tbl            => l_eam_res_tbl
1337                ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
1338                ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
1339                ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
1340                ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
1341                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
1342                );
1343             l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
1344             l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
1345        END IF;
1346 
1347 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Resources Database writes completed with status  ' || l_return_status); END IF;
1348 
1349     ELSE
1350 
1351 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Skipping '|| I || ' record') ; END IF ;
1352 
1353     END IF; -- END IF statement that checks RETURN STATUS
1354 
1355     --  Load tables.
1356     l_eam_sub_res_tbl(I)          := l_eam_sub_res_rec;
1357 
1358 
1359     -- Indicate that children need to be processed
1360     l_process_children := TRUE;
1361 
1362     --  For loop exception handler.
1363 
1364     EXCEPTION
1365        WHEN EXC_SEV_QUIT_RECORD THEN
1366         l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
1367         l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
1368         EAM_ERROR_MESSAGE_PVT.Log_Error
1369         (  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
1370         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
1371         ,  p_mesg_token_tbl         => l_mesg_token_tbl
1372         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1373         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
1374         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_SUB_RES_LEVEL
1375         ,  p_entity_index           => I
1376         ,  x_eam_wo_rec             => l_eam_wo_rec
1377         ,  x_eam_op_tbl             => l_eam_op_tbl
1378         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
1379         ,  x_eam_res_tbl            => l_eam_res_tbl
1380         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
1381         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
1382         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
1383         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
1384         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
1385         );
1386         l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
1387         l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
1388 
1389          l_process_children             := FALSE;
1390 
1391          IF l_bo_return_status = 'S'
1392          THEN
1393              l_bo_return_status  := l_return_status ;
1394          END IF;
1395 
1396          x_return_status                := l_bo_return_status;
1397          x_mesg_token_tbl               := l_mesg_token_tbl ;
1398          x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
1399 
1400 
1401       WHEN EXC_SEV_QUIT_BRANCH THEN
1402        l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
1403        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
1404        EAM_ERROR_MESSAGE_PVT.Log_Error
1405         (  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
1406         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
1407         ,  p_mesg_token_tbl         => l_mesg_token_tbl
1408         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1409         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
1410         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1411         ,  p_other_message          => l_other_message
1412         ,  p_other_token_tbl        => l_other_token_tbl
1413         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_SUB_RES_LEVEL
1414         ,  p_entity_index           => I
1415         ,  x_eam_wo_rec             => l_eam_wo_rec
1416         ,  x_eam_op_tbl             => l_eam_op_tbl
1417         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
1418         ,  x_eam_res_tbl            => l_eam_res_tbl
1419         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
1420         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
1421         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
1422         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
1423         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
1424         );
1425        l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
1426        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
1427 
1428          l_process_children             := FALSE ;
1429 
1430          IF l_bo_return_status = 'S'
1431          THEN
1432              l_bo_return_status  := l_return_status ;
1433          END IF;
1434 
1435          x_return_status                := l_bo_return_status;
1436          x_mesg_token_tbl               := l_mesg_token_tbl ;
1437          x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
1438 
1439 
1440       WHEN EXC_SEV_SKIP_BRANCH THEN
1441        l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
1442        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
1443        EAM_ERROR_MESSAGE_PVT.Log_Error
1444         (  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
1445         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
1446         ,  p_mesg_token_tbl         => l_mesg_token_tbl
1447         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1448         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
1449         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_NOT_PICKED
1450         ,  p_other_message          => l_other_message
1451         ,  p_other_token_tbl        => l_other_token_tbl
1452         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_SUB_RES_LEVEL
1453         ,  p_entity_index           => I
1454         ,  x_eam_wo_rec             => l_eam_wo_rec
1455         ,  x_eam_op_tbl             => l_eam_op_tbl
1456         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
1457         ,  x_eam_res_tbl            => l_eam_res_tbl
1458         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
1459         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
1460         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
1461         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
1462         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
1463         );
1464        l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
1465        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
1466 
1467 
1468          l_process_children             := FALSE ;
1469 
1470          IF l_bo_return_status = 'S'
1471          THEN
1472              l_bo_return_status  := l_return_status ;
1473          END IF;
1474 
1475          x_return_status                := l_bo_return_status;
1476          x_mesg_token_tbl               := l_mesg_token_tbl ;
1477          x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
1478 
1479 
1480       WHEN EXC_SEV_QUIT_SIBLINGS THEN
1481        l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
1482        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
1483        EAM_ERROR_MESSAGE_PVT.Log_Error
1484         (  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
1485         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
1486         ,  p_mesg_token_tbl         => l_mesg_token_tbl
1487         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1488         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_SIBLINGS
1489         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1490         ,  p_other_message          => l_other_message
1491         ,  p_other_token_tbl        => l_other_token_tbl
1492         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_SUB_RES_LEVEL
1493         ,  p_entity_index           => I
1494         ,  x_eam_wo_rec             => l_eam_wo_rec
1495         ,  x_eam_op_tbl             => l_eam_op_tbl
1496         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
1497         ,  x_eam_res_tbl            => l_eam_res_tbl
1498         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
1499         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
1500         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
1501         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
1502         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
1503         );
1504        l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
1505        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
1506 
1507          l_process_children             := FALSE ;
1508 
1509          IF l_bo_return_status = 'S'
1510          THEN
1511              l_bo_return_status  := l_return_status ;
1512          END IF;
1513 
1514          x_return_status                := l_bo_return_status;
1515          x_mesg_token_tbl               := l_mesg_token_tbl ;
1516          x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
1517 
1518 
1519       WHEN EXC_FAT_QUIT_BRANCH THEN
1520        l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
1521        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
1522        EAM_ERROR_MESSAGE_PVT.Log_Error
1523         (  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
1524         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
1525         ,  p_mesg_token_tbl         => l_mesg_token_tbl
1526         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
1527         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
1528         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
1529         ,  p_other_message          => l_other_message
1530         ,  p_other_token_tbl        => l_other_token_tbl
1531         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_SUB_RES_LEVEL
1532         ,  p_entity_index           => I
1533         ,  x_eam_wo_rec             => l_eam_wo_rec
1534         ,  x_eam_op_tbl             => l_eam_op_tbl
1535         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
1536         ,  x_eam_res_tbl            => l_eam_res_tbl
1537         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
1538         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
1539         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
1540         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
1541         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
1542         );
1543        l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
1544        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
1545 
1546          l_process_children             := FALSE ;
1547          x_return_status                := EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL;
1548          x_mesg_token_tbl               := l_mesg_token_tbl ;
1549          x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
1550 
1551 
1552       WHEN EXC_FAT_QUIT_SIBLINGS THEN
1553        l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
1554        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
1555        EAM_ERROR_MESSAGE_PVT.Log_Error
1556         (  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
1557         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
1558         ,  p_mesg_token_tbl         => l_mesg_token_tbl
1559         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
1560         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_SIBLINGS
1561         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
1562         ,  p_other_message          => l_other_message
1563         ,  p_other_token_tbl        => l_other_token_tbl
1564         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_SUB_RES_LEVEL
1565         ,  p_entity_index           => I
1566         ,  x_eam_wo_rec             => l_eam_wo_rec
1567         ,  x_eam_op_tbl             => l_eam_op_tbl
1568         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
1569         ,  x_eam_res_tbl            => l_eam_res_tbl
1570         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
1571         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
1572         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
1573         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
1574         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
1575         );
1576        l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
1577        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
1578 
1579          l_process_children             := FALSE ;
1580          x_return_status                := EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL;
1581          x_mesg_token_tbl               := l_mesg_token_tbl ;
1582          x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
1583 
1584 
1585       WHEN EXC_UNEXP_SKIP_OBJECT THEN
1586        l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
1587        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
1588        EAM_ERROR_MESSAGE_PVT.Log_Error
1589         (  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
1590         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
1591         ,  p_mesg_token_tbl         => l_mesg_token_tbl
1592         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
1593         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_NOT_PICKED
1594         ,  p_other_message          => l_other_message
1595         ,  p_other_token_tbl        => l_other_token_tbl
1596         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_SUB_RES_LEVEL
1597         ,  x_eam_wo_rec             => l_eam_wo_rec
1598         ,  x_eam_op_tbl             => l_eam_op_tbl
1599         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
1600         ,  x_eam_res_tbl            => l_eam_res_tbl
1601         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
1602         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
1603         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
1604         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
1605         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
1606         );
1607        l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
1608        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
1609 
1610 
1611          l_return_status                := 'U';
1612          x_mesg_token_tbl               := l_mesg_token_tbl ;
1613          x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
1614 
1615    END ; -- END block
1616 
1617    IF l_return_status in ('Q', 'U')
1618    THEN
1619       x_return_status := l_return_status;
1620       RETURN ;
1621    END IF;
1622 
1623 
1624 
1625    IF l_process_children
1626    THEN
1627 
1628 
1629       -- Process Resource Usage that are direct children of this
1630       -- operation
1631 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling RESOURCE_USAGES from SUB_RESOURCE') ; END IF ;
1632 
1633         l_out_eam_res_usage_tbl := l_eam_res_usage_tbl;
1634 
1635         RESOURCE_USAGES
1636         (  p_validation_level              =>  p_validation_level
1637         ,  p_wip_entity_id                 =>  l_eam_sub_res_rec.wip_entity_id
1638         ,  p_organization_id               =>  l_eam_sub_res_rec.organization_id
1639         ,  p_operation_seq_num             =>  l_eam_sub_res_rec.operation_seq_num
1640         ,  p_resource_seq_num              =>  l_eam_sub_res_rec.resource_seq_num
1641         ,  p_eam_res_usage_tbl             =>  l_eam_res_usage_tbl
1642         ,  x_eam_res_usage_tbl             =>  l_out_eam_res_usage_tbl
1643 	,  x_bottomup_scheduled		   =>  x_bottomup_scheduled
1644 	,  x_mesg_token_tbl                =>  l_mesg_token_tbl
1645         ,  x_return_status                 =>  l_return_status
1646         );
1647 
1648         l_eam_res_usage_tbl := l_out_eam_res_usage_tbl;
1649 
1650    IF l_return_status in ('Q', 'U')
1651    THEN
1652       x_return_status := l_return_status;
1653       RETURN ;
1654    ELSIF NVL(l_return_status, 'S') <> 'S'
1655    THEN
1656       x_return_status     := l_return_status;
1657    END IF;
1658 
1659    END IF;   -- Process children
1660 
1661 
1662    END LOOP; -- END Resources processing loop
1663 
1664 
1665 
1666    --  Load OUT parameters
1667    IF NVL(l_return_status, 'S') <> 'S'
1668    THEN
1669       x_return_status     := l_return_status;
1670    END IF;
1671 
1672 
1673         x_Mesg_Token_Tbl               := l_Mesg_Token_Tbl;
1674         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
1675 
1676 END SUB_RESOURCES;
1677 
1678 
1679 
1680 
1681 
1682 
1683 
1684 
1685 
1686 
1687 
1688 
1689 
1690 
1691 
1692 
1693 
1694 
1695 
1696 
1697 PROCEDURE RESOURCE_INSTANCES
1698         (  p_validation_level        IN  NUMBER
1699         ,  p_wip_entity_id           IN  NUMBER := NULL
1700         ,  p_organization_id         IN  NUMBER := NULL
1701         ,  p_operation_seq_num       IN  NUMBER := NULL
1702         ,  p_resource_seq_num        IN  NUMBER := NULL
1703         ,  p_eam_res_inst_tbl        IN EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
1704         ,  x_eam_res_inst_tbl        OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
1705         ,  x_mesg_token_tbl          OUT NOCOPY EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type
1706         ,  x_return_status           OUT NOCOPY VARCHAR2
1707 	,  x_schedule_wo              IN OUT NOCOPY NUMBER
1708 	,  x_bottomup_scheduled      IN OUT NOCOPY NUMBER
1709         )
1710 IS
1711 
1712 l_eam_res_inst_rec      EAM_PROCESS_WO_PUB.eam_res_inst_rec_type ;
1713 l_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type ;
1714 l_old_eam_res_inst_rec  EAM_PROCESS_WO_PUB.eam_res_inst_rec_type ;
1715 
1716 l_out_eam_res_inst_rec      EAM_PROCESS_WO_PUB.eam_res_inst_rec_type ;
1717 l_out_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1718 l_out_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1719 l_out_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1720 l_out_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1721 l_out_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1722 l_out_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1723 l_out_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1724 l_out_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1725 l_out_mesg_token_tbl        EAM_ERROR_MESSAGE_PVT.mesg_token_tbl_type;
1726 
1727 l_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type ;
1728 l_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type ;
1729 l_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type ;
1730 l_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type ;
1731 l_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type ;
1732 l_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type ;
1733 l_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type ;
1734 l_eam_direct_items_tbl  EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type ;
1735 
1736 /* Error Handling Variables */
1737 l_token_tbl             EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
1738 l_mesg_token_tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
1739 l_other_token_tbl       EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
1740 l_other_message         VARCHAR2(2000);
1741 l_err_text              VARCHAR2(2000);
1742 
1743 /* Others */
1744 l_return_status         VARCHAR2(1) ;
1745 l_bo_return_status      VARCHAR2(1) ;
1746 l_parent_exists         BOOLEAN := FALSE ;
1747 l_process_children      BOOLEAN := TRUE ;
1748 l_valid_transaction     BOOLEAN := TRUE ;
1749 
1750 l_eam_res_usage_rec	EAM_PROCESS_WO_PUB.eam_res_usage_rec_type;
1751 
1752 
1753 BEGIN
1754 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(p_eam_res_inst_tbl.COUNT ||' records passed') ; END IF ;
1755 
1756    x_return_status := FND_API.G_RET_STS_SUCCESS;
1757 
1758 	IF x_bottomup_scheduled = G_NON_FIRM_WORKORDER THEN
1759 		  x_schedule_wo := G_SCHEDULE_WO;
1760 	END IF;
1761 
1762 --  Init local table variables.
1763    l_return_status    := 'S' ;
1764    l_bo_return_status := 'S' ;
1765    l_eam_res_inst_tbl    := p_eam_res_inst_tbl ;
1766 
1767 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Starting RESOURCE_INSTANCES') ; END IF ;
1768 
1769    FOR I IN 1..l_eam_res_inst_tbl.COUNT LOOP
1770    BEGIN
1771 
1772 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Processing '|| I || ' record') ; END IF ;
1773 
1774       --  Load local records.
1775       l_eam_res_inst_rec := l_eam_res_inst_tbl(I);
1776 
1777       -- make sure to set process_children to false at the start of every iteration
1778 
1779       l_process_children := FALSE;
1780 
1781 
1782       IF l_eam_res_inst_rec.wip_entity_id is NULL
1783          AND (l_eam_res_inst_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
1784              OR l_eam_res_inst_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_SYNC)
1785       THEN
1786           l_eam_res_inst_rec.wip_entity_id := p_wip_entity_id;
1787       END IF;
1788 
1789       IF p_wip_entity_id IS NOT NULL AND
1790          p_organization_id IS NOT NULL AND
1791          p_operation_seq_num IS NOT NULL AND
1792          p_resource_seq_num IS NOT NULL
1793       THEN
1794          l_parent_exists := TRUE;
1795       END IF;
1796 
1797       -- Check if record has not yet been processed and that it is the child of the parent that called this procedure
1798 
1799       IF (l_eam_res_inst_rec.return_status IS NULL OR l_eam_res_inst_rec.return_status = FND_API.G_MISS_CHAR)
1800            AND
1801            (NOT l_parent_exists
1802             OR
1803              (l_parent_exists AND
1804               l_eam_res_inst_rec.wip_entity_id = p_wip_entity_id AND
1805               l_eam_res_inst_rec.organization_id = p_organization_id AND
1806               l_eam_res_inst_rec.operation_seq_num = p_operation_seq_num AND
1807               l_eam_res_inst_rec.resource_seq_num = p_resource_seq_num
1808              )
1809            )
1810       THEN
1811 
1812 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Return status validation passed') ; END IF ;
1813 
1814          l_return_status := FND_API.G_RET_STS_SUCCESS;
1815          l_eam_res_inst_rec.return_status := FND_API.G_RET_STS_SUCCESS;
1816 
1817         VALIDATE_TRANSACTION_TYPE
1818         (   p_transaction_type  => l_eam_res_inst_rec.transaction_type
1819         ,   p_entity_name       => 'RESOURCE_INSTANCE'
1820         ,   p_entity_id         => to_char(l_eam_res_inst_rec.instance_id)
1821         ,   X_valid_transaction => l_valid_transaction
1822         ,   x_mesg_token_tbl    => l_mesg_token_tbl
1823         );
1824 
1825          IF NOT l_valid_transaction
1826          THEN
1827              l_return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
1828              RAISE EXC_SEV_QUIT_RECORD ;
1829          END IF ;
1830 
1831          EAM_RES_INST_VALIDATE_PVT.Check_Existence
1832          (  p_eam_res_inst_rec       => l_eam_res_inst_rec
1833          ,  x_old_eam_res_inst_rec   => l_old_eam_res_inst_rec
1834          ,  x_mesg_token_tbl         => l_mesg_token_tbl
1835          ,  x_return_status          => l_return_status
1836          ) ;
1837 
1838 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check Existence completed with return_status: ' || l_return_status) ;  END IF ;
1839 
1840          IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1841          THEN
1842             l_other_message := 'EAM_RI_EXS_SEV_SKIP';
1843             l_other_token_tbl(1).token_name  := 'INSTANCE_ID';
1844             l_other_token_tbl(1).token_value := l_eam_res_inst_rec.instance_id;
1845             l_other_token_tbl(2).token_name  := 'WIP_ENTITY_ID';
1846             l_other_token_tbl(2).token_value := l_eam_res_inst_rec.wip_entity_id;
1847             RAISE EXC_SEV_QUIT_BRANCH;
1848          ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
1849          THEN
1850             l_other_message := 'EAM_RI_EXS_UNEXP_SKIP';
1851             l_other_token_tbl(1).token_name  := 'INSTANCE_ID';
1852             l_other_token_tbl(1).token_value := l_eam_res_inst_rec.instance_id ;
1853             l_other_token_tbl(2).token_name  := 'WIP_ENTITY_ID';
1854             l_other_token_tbl(2).token_value := l_eam_res_inst_rec.wip_entity_id ;
1855             RAISE EXC_UNEXP_SKIP_OBJECT;
1856          END IF;
1857 
1858         /* Assign the correct transaction type for SYNC operations */
1859 
1860         IF l_eam_res_inst_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_SYNC THEN
1861            l_eam_res_inst_rec.transaction_type := l_old_eam_res_inst_rec.transaction_type;
1862         END IF;
1863 
1864 
1865         IF l_eam_res_inst_rec.transaction_type IN (EAM_PROCESS_WO_PVT.G_OPR_UPDATE, EAM_PROCESS_WO_PVT.G_OPR_DELETE)
1866         THEN
1867 
1868            IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Populate NULL columns') ;
1869            END IF ;
1870 
1871 
1872            l_out_eam_res_inst_rec := l_eam_res_inst_rec;
1873            EAM_RES_INST_DEFAULT_PVT.Populate_Null_Columns
1874            (   p_eam_res_inst_rec        => l_eam_res_inst_rec
1875            ,   p_old_eam_res_inst_Rec    => l_old_eam_res_inst_rec
1876            ,   x_eam_res_inst_rec     => l_out_eam_res_inst_rec
1877            ) ;
1878            l_eam_res_inst_rec := l_out_eam_res_inst_rec;
1879 
1880 
1881         ELSIF l_eam_res_inst_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
1882         THEN
1883 
1884            l_out_eam_res_inst_rec := l_eam_res_inst_rec;
1885            EAM_RES_INST_DEFAULT_PVT.Attribute_Defaulting
1886            (   p_eam_res_inst_rec   => l_eam_res_inst_rec
1887            ,   x_eam_res_inst_rec   => l_out_eam_res_inst_rec
1888            ,   x_mesg_token_tbl  => l_mesg_token_tbl
1889            ,   x_return_status   => l_return_status
1890            ) ;
1891            l_eam_res_inst_rec := l_out_eam_res_inst_rec;
1892 
1893            IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug
1894            ('Attribute Defaulting completed with return_status: ' || l_return_status) ;
1895            END IF ;
1896 
1897 
1898            IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1899            THEN
1900               l_other_message := 'EAM_RI_ATTDEF_CSEV_SKIP';
1901               l_other_token_tbl(1).token_name  := 'INSTANCE_ID';
1902               l_other_token_tbl(1).token_value := l_eam_res_inst_rec.instance_id ;
1903               RAISE EXC_SEV_SKIP_BRANCH ;
1904 
1905            ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
1906            THEN
1907               l_other_message := 'EAM_RI_ATTDEF_UNEXP_SKIP';
1908               l_other_token_tbl(1).token_name := 'INSTANCE_ID';
1909               l_other_token_tbl(1).token_value := l_eam_res_inst_rec.instance_id ;
1910               RAISE EXC_UNEXP_SKIP_OBJECT ;
1911            ELSIF l_return_status ='S' AND l_mesg_token_tbl .COUNT <> 0
1912            THEN
1913               l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
1914               EAM_ERROR_MESSAGE_PVT.Log_Error
1915                (  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
1916                ,  p_mesg_token_tbl         => l_mesg_token_tbl
1917                ,  p_error_status           => 'W'
1918                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_INST_LEVEL
1919                ,  p_entity_index           => I
1920                ,  x_eam_wo_rec             => l_eam_wo_rec
1921                ,  x_eam_op_tbl             => l_eam_op_tbl
1922                ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
1923                ,  x_eam_res_tbl            => l_eam_res_tbl
1924                ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
1925                ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
1926                ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
1927                ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
1928                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
1929                );
1930               l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
1931           END IF;
1932        END IF;
1933 
1934 
1935          EAM_RES_INST_VALIDATE_PVT.Check_Required
1936          ( p_eam_res_inst_rec           => l_eam_res_inst_rec
1937          , x_return_status              => l_return_status
1938          , x_mesg_token_tbl             => l_mesg_token_tbl
1939          ) ;
1940 
1941 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check required completed with return_status: ' || l_return_status) ; END IF ;
1942 
1943 
1944          IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1945          THEN
1946             IF l_eam_res_inst_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
1947             THEN
1948                l_other_message := 'EAM_RI_REQ_CSEV_SKIP';
1949                l_other_token_tbl(1).token_name  := 'INSTANCE_ID';
1950                l_other_token_tbl(1).token_value := l_eam_res_inst_rec.instance_id ;
1951                RAISE EXC_SEV_SKIP_BRANCH ;
1952             ELSE
1953                RAISE EXC_SEV_QUIT_RECORD ;
1954             END IF;
1955          ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
1956          THEN
1957             l_other_message := 'EAM_RI_REQ_UNEXP_SKIP';
1958             l_other_token_tbl(1).token_name  := 'INSTANCE_ID';
1959             l_other_token_tbl(1).token_value := l_eam_res_inst_rec.instance_id ;
1960             RAISE EXC_UNEXP_SKIP_OBJECT ;
1961          END IF;
1962 
1963 
1964             EAM_RES_INST_VALIDATE_PVT.Check_Attributes
1965             ( p_eam_res_inst_rec     => l_eam_res_inst_rec
1966             , p_old_eam_res_inst_rec => l_old_eam_res_inst_rec
1967             , x_return_status        => l_return_status
1968             , x_mesg_token_tbl       => l_mesg_token_tbl
1969             ) ;
1970 
1971 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Attribute validation completed with return_status: ' || l_return_status) ; END IF ;
1972 
1973             IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
1974             THEN
1975                IF l_eam_res_inst_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
1976                THEN
1977                   l_other_message := 'EAM_RI_ATTVAL_CSEV_SKIP';
1978                   l_other_token_tbl(1).token_name := 'INSTANCE_ID';
1979                   l_other_token_tbl(1).token_value := l_eam_res_inst_rec.instance_id ;
1980                   RAISE EXC_SEV_SKIP_BRANCH ;
1981                   ELSE
1982                      RAISE EXC_SEV_QUIT_RECORD ;
1983                END IF;
1984             ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
1985             THEN
1986                l_other_message := 'EAM_RI_ATTVAL_UNEXP_SKIP';
1987                l_other_token_tbl(1).token_name := 'INSTANCE_ID';
1988                l_other_token_tbl(1).token_value := l_eam_res_inst_rec.instance_id ;
1989                RAISE EXC_UNEXP_SKIP_OBJECT ;
1990             ELSIF l_return_status ='S' AND l_mesg_token_tbl .COUNT <> 0
1991             THEN
1992               l_out_eam_res_inst_tbl := l_eam_res_inst_tbl;
1993               EAM_ERROR_MESSAGE_PVT.Log_Error
1994                (  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
1995                ,  p_mesg_token_tbl         => l_mesg_token_tbl
1996                ,  p_error_status           => 'W'
1997                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_INST_LEVEL
1998                ,  p_entity_index           => I
1999                ,  x_eam_wo_rec             => l_eam_wo_rec
2000                ,  x_eam_op_tbl             => l_eam_op_tbl
2001                ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
2002                ,  x_eam_res_tbl            => l_eam_res_tbl
2003                ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
2004                ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2005                ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2006                ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2007                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2008                );
2009               l_eam_res_inst_tbl := l_out_eam_res_inst_tbl;
2010 
2011            END IF;
2012 
2013 
2014           EAM_RES_INST_UTILITY_PVT.Perform_Writes
2015           (   p_eam_res_inst_rec    => l_eam_res_inst_rec
2016           ,   x_mesg_token_tbl      => l_mesg_token_tbl
2017           ,   x_return_status       => l_return_status
2018           ) ;
2019 
2020 /*	  IF l_eam_res_inst_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
2021 	  AND x_bottomup_scheduled <> G_NON_FIRM_WORKORDER
2022 	  THEN
2023 
2024 
2025 	l_eam_res_usage_rec.header_id		:=	l_eam_res_inst_rec.header_id;
2026 	l_eam_res_usage_rec.batch_id		:=	l_eam_res_inst_rec.batch_id;
2027 	l_eam_res_usage_rec.row_id		:=	l_eam_res_inst_rec.row_id;
2028 	l_eam_res_usage_rec.wip_entity_id	:=	l_eam_res_inst_rec.wip_entity_id;
2029 	l_eam_res_usage_rec.operation_seq_num	:=	l_eam_res_inst_rec.operation_seq_num;
2030 	l_eam_res_usage_rec.resource_seq_num	:=	l_eam_res_inst_rec.resource_seq_num;
2031 	l_eam_res_usage_rec.organization_id	:=	l_eam_res_inst_rec.organization_id;
2032 	l_eam_res_usage_rec.start_date		:=	l_eam_res_inst_rec.start_date;
2033 	l_eam_res_usage_rec.assigned_units	:=      1;
2034 	l_eam_res_usage_rec.completion_date	:=	l_eam_res_inst_rec.completion_date;
2035 	l_eam_res_usage_rec.instance_id         :=      l_eam_res_inst_rec.instance_id;
2036 	l_eam_res_usage_rec.serial_number	:=      l_eam_res_inst_rec.serial_number;
2037 	l_eam_res_usage_rec.return_status	:=      l_eam_res_inst_rec.return_status;
2038 	l_eam_res_usage_rec.transaction_type    :=      l_eam_res_inst_rec.transaction_type;
2039 
2040 		 EAM_RES_USAGE_UTILITY_PVT.Add_Usage
2041 		  (  p_eam_res_usage_rec   => l_eam_res_usage_rec
2042 		  ,  x_mesg_token_tbl      => l_mesg_token_tbl
2043 		  ,  x_return_status       => l_return_status
2044 		  );
2045 	  END IF;
2046 
2047 
2048        IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
2049        THEN
2050           l_other_message := 'EAM_RI_WRITES_UNEXP_SKIP';
2051           l_other_token_tbl(1).token_name := 'INSTANCE_ID';
2052           l_other_token_tbl(1).token_value := l_eam_res_inst_rec.instance_id ;
2053           RAISE EXC_UNEXP_SKIP_OBJECT ;
2054        ELSIF l_return_status ='S' AND
2055           l_mesg_token_tbl.COUNT <>0
2056        THEN
2057             l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
2058             EAM_ERROR_MESSAGE_PVT.Log_Error
2059                (  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
2060                ,  p_mesg_token_tbl         => l_mesg_token_tbl
2061                ,  p_error_status           => 'W'
2062                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_INST_LEVEL
2063                ,  p_entity_index           => I
2064                ,  x_eam_wo_rec             => l_eam_wo_rec
2065                ,  x_eam_op_tbl             => l_eam_op_tbl
2066                ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
2067                ,  x_eam_res_tbl            => l_eam_res_tbl
2068                ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
2069                ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2070                ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2071                ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2072                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2073                );
2074               l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
2075        END IF;
2076        */
2077 
2078 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Resources Database writes completed with status  ' || l_return_status); END IF;
2079 
2080     ELSE
2081 
2082 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Skipping '|| I || ' record') ; END IF ;
2083 
2084     END IF; -- END IF statement that checks RETURN STATUS
2085 
2086      --find if bottom up scheduler is to be called or not
2087 
2088 	 IF(x_bottomup_scheduled = G_NOT_BU_SCHEDULE_WO)THEN    --not yet set to schedule
2089 	     IF(l_eam_res_inst_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE   -- is resource iinstance is added
2090 	    --    OR (l_eam_res_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_DELETE AND l_eam_res_rec.scheduled_flag=1) --deleted and was scheduled
2091 		OR (l_eam_res_inst_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_UPDATE AND  --updating the resource iinstance
2092 		       (
2093 		       --NVL(l_eam_res_rec.schedule_seq_num,l_eam_res_rec.resource_seq_num)<>NVL(l_old_eam_res_rec.schedule_seq_num,l_old_eam_res_rec.resource_seq_num)
2094 		        -- OR
2095 			l_eam_res_inst_rec.start_date <> l_old_eam_res_inst_rec.start_date   --shedule_seq_num,start_date,completion_date
2096 			OR l_eam_res_inst_rec.completion_date <> l_old_eam_res_inst_rec.completion_date
2097 		--	OR l_eam_res_rec.resource_id <> l_old_eam_res_rec.resource_id    --resource_code,usage_rate_or_amount,scheduled_flag,assigned_units
2098 		--	OR l_eam_res_rec.usage_rate_or_amount <> l_old_eam_res_rec.usage_rate_or_amount
2099 		--	OR l_eam_res_rec.scheduled_flag <> l_old_eam_res_rec.scheduled_flag
2100 		--	OR NVL(l_eam_res_rec.assigned_units,0) <> NVL(l_old_eam_res_rec.assigned_units,0)
2101 			)
2102 		    )
2103 		) THEN
2104 		    x_bottomup_scheduled := G_UPDATE_RES_USAGE;
2105 	     END IF;
2106 	 END IF;
2107 
2108 
2109     --  Load tables.
2110     l_eam_res_inst_tbl(I)          := l_eam_res_inst_rec;
2111 
2112 
2113     -- Indicate that children need to be processed
2114     l_process_children := TRUE;
2115 
2116     --  For loop exception handler.
2117 
2118     EXCEPTION
2119        WHEN EXC_SEV_QUIT_RECORD THEN
2120         l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
2121         EAM_ERROR_MESSAGE_PVT.Log_Error
2122         (  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
2123         ,  p_mesg_token_tbl         => l_mesg_token_tbl
2124         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2125         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
2126         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_INST_LEVEL
2127         ,  p_entity_index           => I
2128         ,  x_eam_wo_rec             => l_eam_wo_rec
2129         ,  x_eam_op_tbl             => l_eam_op_tbl
2130         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
2131         ,  x_eam_res_tbl            => l_eam_res_tbl
2132         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
2133         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2134         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2135         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2136         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2137         );
2138         l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
2139 
2140          l_process_children             := FALSE;
2141          IF l_bo_return_status = 'S'
2142          THEN
2143              l_bo_return_status  := l_return_status ;
2144          END IF;
2145          x_return_status                := l_bo_return_status;
2146          x_mesg_token_tbl               := l_mesg_token_tbl ;
2147          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
2148 
2149 
2150       WHEN EXC_SEV_QUIT_BRANCH THEN
2151        l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
2152        EAM_ERROR_MESSAGE_PVT.Log_Error
2153         (  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
2154         ,  p_mesg_token_tbl         => l_mesg_token_tbl
2155         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2156         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
2157         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2158         ,  p_other_message          => l_other_message
2159         ,  p_other_token_tbl        => l_other_token_tbl
2160         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_INST_LEVEL
2161         ,  p_entity_index           => I
2162         ,  x_eam_wo_rec             => l_eam_wo_rec
2163         ,  x_eam_op_tbl             => l_eam_op_tbl
2164         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
2165         ,  x_eam_res_tbl            => l_eam_res_tbl
2166         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
2167         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2168         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2169         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2170         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2171         );
2172        l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
2173 
2174 
2175          l_process_children             := FALSE ;
2176          IF l_bo_return_status = 'S'
2177          THEN
2178              l_bo_return_status  := l_return_status ;
2179          END IF;
2180          x_return_status                := l_bo_return_status;
2181          x_mesg_token_tbl               := l_mesg_token_tbl ;
2182          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
2183 
2184 
2185       WHEN EXC_SEV_SKIP_BRANCH THEN
2186        l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
2187        EAM_ERROR_MESSAGE_PVT.Log_Error
2188         (  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
2189         ,  p_mesg_token_tbl         => l_mesg_token_tbl
2190         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2191         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
2192         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_NOT_PICKED
2193         ,  p_other_message          => l_other_message
2194         ,  p_other_token_tbl        => l_other_token_tbl
2195         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_INST_LEVEL
2196         ,  p_entity_index           => I
2197         ,  x_eam_wo_rec             => l_eam_wo_rec
2198         ,  x_eam_op_tbl             => l_eam_op_tbl
2199         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
2200         ,  x_eam_res_tbl            => l_eam_res_tbl
2201         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
2202         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2203         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2204         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2205         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2206         );
2207        l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
2208 
2209 
2210          l_process_children             := FALSE ;
2211          IF l_bo_return_status = 'S'
2212          THEN
2213              l_bo_return_status  := l_return_status ;
2214          END IF;
2215          x_return_status                := l_bo_return_status;
2216          x_mesg_token_tbl               := l_mesg_token_tbl ;
2217          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
2218 
2219 
2220       WHEN EXC_SEV_QUIT_SIBLINGS THEN
2221        l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
2222        EAM_ERROR_MESSAGE_PVT.Log_Error
2223         (  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
2224         ,  p_mesg_token_tbl         => l_mesg_token_tbl
2225         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2226         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_SIBLINGS
2227         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2228         ,  p_other_message          => l_other_message
2229         ,  p_other_token_tbl        => l_other_token_tbl
2230         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_INST_LEVEL
2231         ,  p_entity_index           => I
2232         ,  x_eam_wo_rec             => l_eam_wo_rec
2233         ,  x_eam_op_tbl             => l_eam_op_tbl
2234         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
2235         ,  x_eam_res_tbl            => l_eam_res_tbl
2236         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
2237         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2238         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2239         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2240         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2241         );
2242        l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
2243 
2244 
2245          l_process_children             := FALSE ;
2246          IF l_bo_return_status = 'S'
2247          THEN
2248              l_bo_return_status  := l_return_status ;
2249          END IF;
2250          x_return_status                := l_bo_return_status;
2251          x_mesg_token_tbl               := l_mesg_token_tbl ;
2252          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
2253 
2254 
2255       WHEN EXC_FAT_QUIT_BRANCH THEN
2256        l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
2257        EAM_ERROR_MESSAGE_PVT.Log_Error
2258         (  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
2259         ,  p_mesg_token_tbl         => l_mesg_token_tbl
2260         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
2261         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
2262         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
2263         ,  p_other_message          => l_other_message
2264         ,  p_other_token_tbl        => l_other_token_tbl
2265         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_INST_LEVEL
2266         ,  p_entity_index           => I
2267         ,  x_eam_wo_rec             => l_eam_wo_rec
2268         ,  x_eam_op_tbl             => l_eam_op_tbl
2269         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
2270         ,  x_eam_res_tbl            => l_eam_res_tbl
2271         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
2272         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2273         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2274         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2275         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2276         );
2277        l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
2278 
2279 
2280          l_process_children             := FALSE ;
2281          x_return_status                := EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL;
2282          x_mesg_token_tbl               := l_mesg_token_tbl ;
2283          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
2284 
2285 
2286       WHEN EXC_FAT_QUIT_SIBLINGS THEN
2287        l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
2288        EAM_ERROR_MESSAGE_PVT.Log_Error
2289         (  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
2290         ,  p_mesg_token_tbl         => l_mesg_token_tbl
2291         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
2292         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_SIBLINGS
2293         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
2294         ,  p_other_message          => l_other_message
2295         ,  p_other_token_tbl        => l_other_token_tbl
2296         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_INST_LEVEL
2297         ,  p_entity_index           => I
2298         ,  x_eam_wo_rec             => l_eam_wo_rec
2299         ,  x_eam_op_tbl             => l_eam_op_tbl
2300         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
2301         ,  x_eam_res_tbl            => l_eam_res_tbl
2302         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
2303         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2304         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2305         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2306         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2307         );
2308        l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
2309 
2310 
2311          l_process_children             := FALSE ;
2312          x_return_status                := EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL;
2313          x_mesg_token_tbl               := l_mesg_token_tbl ;
2314          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
2315 
2316 
2317 
2318       WHEN EXC_UNEXP_SKIP_OBJECT THEN
2319        l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
2320        EAM_ERROR_MESSAGE_PVT.Log_Error
2321         (  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
2322         ,  p_mesg_token_tbl         => l_mesg_token_tbl
2323         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
2324         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_NOT_PICKED
2325         ,  p_other_message          => l_other_message
2326         ,  p_other_token_tbl        => l_other_token_tbl
2327         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_INST_LEVEL
2328         ,  x_eam_wo_rec             => l_eam_wo_rec
2329         ,  x_eam_op_tbl             => l_eam_op_tbl
2330         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
2331         ,  x_eam_res_tbl            => l_eam_res_tbl
2332         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
2333         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2334         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2335         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2336         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2337         );
2338        l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
2339 
2340 
2341          l_return_status                := 'U';
2342          x_mesg_token_tbl               := l_mesg_token_tbl ;
2343          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
2344 
2345    END ; -- END block
2346 
2347    IF l_return_status in ('Q', 'U')
2348    THEN
2349       x_return_status := l_return_status;
2350       RETURN ;
2351    END IF;
2352 
2353 
2354    END LOOP; -- END Resources processing loop
2355 
2356 
2357 
2358    --  Load OUT parameters
2359    IF NVL(l_return_status, 'S') <> 'S'
2360    THEN
2361    x_return_status     := l_return_status;
2362    END IF;
2363    x_Mesg_Token_Tbl               := l_Mesg_Token_Tbl;
2364    x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
2365 
2366 
2367 END RESOURCE_INSTANCES;
2368 
2369 
2370 
2371 
2372 
2373 
2374 
2375 
2376 
2377 
2378 
2379 
2380 
2381 
2382 
2383 PROCEDURE OPERATION_NETWORKS
2384         (  p_validation_level        IN  NUMBER
2385         ,  p_wip_entity_id           IN  NUMBER := NULL
2386         ,  p_organization_id         IN  NUMBER := NULL
2387         ,  p_eam_op_network_tbl      IN  EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
2388         ,  x_eam_op_network_tbl      OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
2389 	,  x_schedule_wo              IN OUT NOCOPY NUMBER
2390 	,  x_bottomup_scheduled      IN OUT NOCOPY NUMBER
2391         ,  x_mesg_token_tbl          OUT NOCOPY EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type
2392         ,  x_return_status           OUT NOCOPY VARCHAR2
2393         )
2394 IS
2395 
2396 l_eam_op_network_rec       EAM_PROCESS_WO_PUB.eam_op_network_rec_type ;
2397 l_eam_op_network_tbl       EAM_PROCESS_WO_PUB.eam_op_network_tbl_type ;
2398 l_old_eam_op_network_rec   EAM_PROCESS_WO_PUB.eam_op_network_rec_type ;
2399 
2400 l_out_eam_op_network_rec       EAM_PROCESS_WO_PUB.eam_op_network_rec_type ;
2401 l_out_eam_op_network_tbl       EAM_PROCESS_WO_PUB.eam_op_network_tbl_type ;
2402 
2403 l_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type ;
2404 l_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type ;
2405 l_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type ;
2406 l_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type ;
2407 l_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type ;
2408 l_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type ;
2409 l_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type ;
2410 l_eam_direct_items_tbl  EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type ;
2411 
2412 /* Error Handling Variables */
2413 l_token_tbl             EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
2414 l_mesg_token_tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
2415 l_other_token_tbl       EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
2416 l_other_message         VARCHAR2(2000);
2417 l_err_text              VARCHAR2(2000);
2418 
2419 /* Others */
2420 l_return_status         VARCHAR2(1) ;
2421 l_bo_return_status      VARCHAR2(1) ;
2422 l_parent_exists         BOOLEAN := FALSE ;
2423 l_process_children      BOOLEAN := TRUE ;
2424 l_valid_transaction     BOOLEAN := TRUE ;
2425 
2426 
2427 BEGIN
2428 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(p_eam_op_network_tbl.COUNT ||' records passed') ; END IF ;
2429 
2430    x_return_status := FND_API.G_RET_STS_SUCCESS;
2431 
2432 --  Init local table variables.
2433    l_return_status    := 'S' ;
2434    l_bo_return_status := 'S' ;
2435    l_eam_op_network_tbl    := p_eam_op_network_tbl ;
2436 
2437 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Starting OPERATION_NETWORK') ; END IF ;
2438 
2439    FOR I IN 1..l_eam_op_network_tbl.COUNT LOOP
2440    BEGIN
2441 
2442 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Processing '|| I || ' record') ; END IF ;
2443 
2444       --  Load local records.
2445 
2446       l_eam_op_network_rec := l_eam_op_network_tbl(I);
2447 
2448       -- make sure to set process_children to false at the start of every iteration
2449 
2450       l_process_children := FALSE;
2451 
2452       IF l_eam_op_network_rec.wip_entity_id is NULL
2453          AND (l_eam_op_network_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE)
2454       THEN
2455           l_eam_op_network_rec.wip_entity_id := p_wip_entity_id;
2456       END IF;
2457 
2458       IF p_wip_entity_id IS NOT NULL AND
2459          p_organization_id IS NOT NULL
2460       THEN
2461          l_parent_exists := TRUE;
2462       END IF;
2463 
2464       -- Check if record has not yet been processed and that it is the child of the parent that called this procedure
2465 
2466       IF (l_eam_op_network_rec.return_status IS NULL OR l_eam_op_network_rec.return_status = FND_API.G_MISS_CHAR)
2467            AND
2468            (NOT l_parent_exists
2469             OR
2470              (l_parent_exists AND
2471               l_eam_op_network_rec.wip_entity_id = p_wip_entity_id AND
2472               l_eam_op_network_rec.organization_id = p_organization_id
2473              )
2474            )
2475       THEN
2476 
2477 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Return status validation passed') ; END IF ;
2478 
2479          l_return_status := FND_API.G_RET_STS_SUCCESS;
2480          l_eam_op_network_rec.return_status := FND_API.G_RET_STS_SUCCESS;
2481 
2482         VALIDATE_TRANSACTION_TYPE
2483         (   p_transaction_type  => l_eam_op_network_rec.transaction_type
2484         ,   p_entity_name       => 'OPERATION_NETWORK'
2485         ,   p_entity_id         => to_char(l_eam_op_network_rec.prior_operation)
2486         ,   X_valid_transaction => l_valid_transaction
2487         ,   x_mesg_token_tbl    => l_mesg_token_tbl
2488         );
2489 
2490          IF NOT l_valid_transaction
2491          THEN
2492              l_return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
2493              RAISE EXC_SEV_QUIT_RECORD ;
2494          END IF ;
2495 
2496          EAM_OP_NETWORK_VALIDATE_PVT.Check_Existence
2497          (  p_eam_op_network_rec     => l_eam_op_network_rec
2498          ,  x_old_eam_op_network_rec => l_old_eam_op_network_rec
2499          ,  x_mesg_token_tbl         => l_mesg_token_tbl
2500          ,  x_return_status          => l_return_status
2501          ) ;
2502 
2503 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check Existence completed with return_status: ' || l_return_status) ;  END IF ;
2504 
2505          IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2506          THEN
2507             l_other_message := 'EAM_OPN_EXS_SEV_SKIP';
2508             l_other_token_tbl(1).token_name  := 'PRIOR_OPERATION';
2509             l_other_token_tbl(1).token_value := l_eam_op_network_rec.prior_operation;
2510             l_other_token_tbl(2).token_name  := 'WIP_ENTITY_ID';
2511             l_other_token_tbl(2).token_value := l_eam_op_network_rec.wip_entity_id;
2512             RAISE EXC_SEV_QUIT_BRANCH;
2513          ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
2514          THEN
2515             l_other_message := 'EAM_OPN_EXS_UNEXP_SKIP';
2516             l_other_token_tbl(1).token_name  := 'PRIOR_OPERATION';
2517             l_other_token_tbl(1).token_value := l_eam_op_network_rec.prior_operation ;
2518             l_other_token_tbl(2).token_name  := 'WIP_ENTITY_ID';
2519             l_other_token_tbl(2).token_value := l_eam_op_network_rec.wip_entity_id ;
2520             RAISE EXC_UNEXP_SKIP_OBJECT;
2521          END IF;
2522 
2523         /* Assign the correct transaction type for SYNC operations */
2524 
2525         IF l_eam_op_network_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_SYNC THEN
2526            l_eam_op_network_rec.transaction_type := l_old_eam_op_network_rec.transaction_type;
2527         END IF;
2528 
2529 
2530         IF l_eam_op_network_rec.transaction_type IN (EAM_PROCESS_WO_PVT.G_OPR_UPDATE, EAM_PROCESS_WO_PVT.G_OPR_DELETE)
2531         THEN
2532 
2533            IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Populate NULL columns') ;
2534            END IF ;
2535 
2536            l_out_eam_op_network_rec := l_eam_op_network_rec;
2537 
2538            EAM_OP_NETWORK_DEFAULT_PVT.Populate_Null_Columns
2539            (   p_eam_op_network_rec        => l_eam_op_network_rec
2540            ,   p_old_eam_op_network_rec    => l_old_eam_op_network_rec
2541            ,   x_eam_op_network_rec     => l_out_eam_op_network_rec
2542            ) ;
2543 
2544            l_eam_op_network_rec := l_out_eam_op_network_rec;
2545 
2546 
2547         ELSIF l_eam_op_network_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
2548         THEN
2549 
2550            l_out_eam_op_network_rec := l_eam_op_network_rec;
2551 
2552            EAM_OP_NETWORK_DEFAULT_PVT.Attribute_Defaulting
2553            (   p_eam_op_network_rec   => l_eam_op_network_rec
2554            ,   x_eam_op_network_rec   => l_out_eam_op_network_rec
2555            ,   x_mesg_token_tbl  => l_mesg_token_tbl
2556            ,   x_return_status   => l_return_status
2557            ) ;
2558 
2559            l_eam_op_network_rec := l_out_eam_op_network_rec;
2560 
2561            IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug
2562            ('Attribute Defaulting completed with return_status: ' || l_return_status) ;
2563            END IF ;
2564 
2565 
2566            IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2567            THEN
2568               l_other_message := 'EAM_OPN_ATTDEF_CSEV_SKIP';
2569               l_other_token_tbl(1).token_name  := 'PRIOR_OPERATION';
2570               l_other_token_tbl(1).token_value := l_eam_op_network_rec.prior_operation ;
2571               RAISE EXC_SEV_SKIP_BRANCH ;
2572 
2573            ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
2574            THEN
2575               l_other_message := 'EAM_OPN_ATTDEF_UNEXP_SKIP';
2576               l_other_token_tbl(1).token_name  := 'PRIOR_OPERATION';
2577               l_other_token_tbl(1).token_value := l_eam_op_network_rec.prior_operation ;
2578               RAISE EXC_UNEXP_SKIP_OBJECT ;
2579            ELSIF l_return_status ='S' AND l_mesg_token_tbl .COUNT <> 0
2580            THEN
2581               l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
2582               EAM_ERROR_MESSAGE_PVT.Log_Error
2583                (  p_eam_op_network_tbl     => l_eam_op_network_tbl
2584                ,  p_mesg_token_tbl         => l_mesg_token_tbl
2585                ,  p_error_status           => 'W'
2586                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_NETWORK_LEVEL
2587                ,  p_entity_index           => I
2588                ,  x_eam_wo_rec             => l_eam_wo_rec
2589                ,  x_eam_op_tbl             => l_eam_op_tbl
2590                ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
2591                ,  x_eam_res_tbl            => l_eam_res_tbl
2592                ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
2593                ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2594                ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2595                ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2596                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2597                );
2598               l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
2599           END IF;
2600        END IF;
2601 
2602 
2603          EAM_OP_NETWORK_VALIDATE_PVT.Check_Required
2604          ( p_eam_op_network_rec         => l_eam_op_network_rec
2605          , x_return_status              => l_return_status
2606          , x_mesg_token_tbl             => l_mesg_token_tbl
2607          ) ;
2608 
2609 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check required completed with return_status: ' || l_return_status) ; END IF ;
2610 
2611 
2612          IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2613          THEN
2614             IF l_eam_op_network_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
2615             THEN
2616                l_other_message := 'EAM_OPN_REQ_CSEV_SKIP';
2617                l_other_token_tbl(1).token_name  := 'PRIOR_OPERATION';
2618                l_other_token_tbl(1).token_value := l_eam_op_network_rec.prior_operation ;
2619                RAISE EXC_SEV_SKIP_BRANCH ;
2620             ELSE
2621                RAISE EXC_SEV_QUIT_RECORD ;
2622             END IF;
2623          ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
2624          THEN
2625             l_other_message := 'EAM_OPN_REQ_UNEXP_SKIP';
2626             l_other_token_tbl(1).token_name  := 'PRIOR_OPERATION';
2627             l_other_token_tbl(1).token_value := l_eam_op_network_rec.prior_operation ;
2628             RAISE EXC_UNEXP_SKIP_OBJECT ;
2629          END IF;
2630 
2631 
2632             EAM_OP_NETWORK_VALIDATE_PVT.Check_Attributes
2633             ( p_eam_op_network_rec        => l_eam_op_network_rec
2634             , p_old_eam_op_network_rec    => l_old_eam_op_network_rec
2635             , x_return_status     => l_return_status
2636             , x_mesg_token_tbl    => l_mesg_token_tbl
2637             ) ;
2638 
2639 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Attribute validation completed with return_status: ' || l_return_status) ; END IF ;
2640 
2641             IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2642             THEN
2643                IF l_eam_op_network_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
2644                THEN
2645                   l_other_message := 'EAM_OPN_ATTVAL_CSEV_SKIP';
2646                   l_other_token_tbl(1).token_name  := 'PRIOR_OPERATION';
2647                   l_other_token_tbl(1).token_value := l_eam_op_network_rec.prior_operation ;
2648                   RAISE EXC_SEV_SKIP_BRANCH ;
2649                   ELSE
2650                      RAISE EXC_SEV_QUIT_RECORD ;
2651                END IF;
2652             ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
2653             THEN
2654                l_other_message := 'EAM_OPN_ATTVAL_UNEXP_SKIP';
2655                l_other_token_tbl(1).token_name  := 'PRIOR_OPERATION';
2656                l_other_token_tbl(1).token_value := l_eam_op_network_rec.prior_operation ;
2657                RAISE EXC_UNEXP_SKIP_OBJECT ;
2658             ELSIF l_return_status ='S' AND l_mesg_token_tbl .COUNT <> 0
2659             THEN
2660               l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
2661               EAM_ERROR_MESSAGE_PVT.Log_Error
2662                (  p_eam_op_network_tbl     => l_eam_op_network_tbl
2663                ,  p_mesg_token_tbl         => l_mesg_token_tbl
2664                ,  p_error_status           => 'W'
2665                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_NETWORK_LEVEL
2666                ,  p_entity_index           => I
2667                ,  x_eam_wo_rec             => l_eam_wo_rec
2668                ,  x_eam_op_tbl             => l_eam_op_tbl
2669                ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
2670                ,  x_eam_res_tbl            => l_eam_res_tbl
2671                ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
2672                ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2673                ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2674                ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2675                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2676                );
2677               l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
2678 
2679            END IF;
2680 
2681 
2682           EAM_OP_NETWORK_UTILITY_PVT.Perform_Writes
2683           (   p_eam_op_network_rec  => l_eam_op_network_rec
2684           ,   x_mesg_token_tbl      => l_mesg_token_tbl
2685           ,   x_return_status       => l_return_status
2686           ) ;
2687 
2688 
2689        IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
2690        THEN
2691           l_other_message := 'EAM_OPN_WRITES_UNEXP_SKIP';
2692           l_other_token_tbl(1).token_name := 'PRIOR_OPERATION';
2693           l_other_token_tbl(1).token_value := l_eam_op_network_rec.prior_operation ;
2694           RAISE EXC_UNEXP_SKIP_OBJECT ;
2695        ELSIF l_return_status ='S' AND
2696           l_mesg_token_tbl.COUNT <>0
2697        THEN
2698             l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
2699             EAM_ERROR_MESSAGE_PVT.Log_Error
2700                (  p_eam_op_network_tbl     => l_eam_op_network_tbl
2701                ,  p_mesg_token_tbl         => l_mesg_token_tbl
2702                ,  p_error_status           => 'W'
2703                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_NETWORK_LEVEL
2704                ,  p_entity_index           => I
2705                ,  x_eam_wo_rec             => l_eam_wo_rec
2706                ,  x_eam_op_tbl             => l_eam_op_tbl
2707                ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
2708                ,  x_eam_res_tbl            => l_eam_res_tbl
2709                ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
2710                ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2711                ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2712                ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2713                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2714                );
2715             l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
2716        END IF;
2717 
2718 	--find if scheduler is to be called or not
2719 	      IF(x_schedule_wo = G_NOT_SCHEDULE_WO
2720 		 AND l_eam_op_network_rec.transaction_type IN (EAM_PROCESS_WO_PVT.G_OPR_CREATE,EAM_PROCESS_WO_PVT.G_OPR_DELETE)
2721 		 ) THEN     -- if op dependency is added or deleted
2722 		    x_schedule_wo := G_SCHEDULE_WO;
2723 	      END IF;
2724 
2725 	--find if bottum up scheduler is to be called or not
2726 	      IF(x_bottomup_scheduled = G_NOT_BU_SCHEDULE_WO
2727 		 AND l_eam_op_network_rec.transaction_type IN (EAM_PROCESS_WO_PVT.G_OPR_CREATE,EAM_PROCESS_WO_PVT.G_OPR_DELETE)
2728 		 ) THEN     -- if op dependency is added or deleted
2729 		    x_bottomup_scheduled := G_BU_SCHEDULE_WO;
2730 	      END IF;
2731 
2732 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Operation Networks Database writes completed with status  ' || l_return_status); END IF;
2733 
2734     ELSE
2735 
2736 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Skipping '|| I || ' record') ; END IF ;
2737 
2738     END IF; -- END IF statement that checks RETURN STATUS
2739 
2740     --  Load tables.
2741     l_eam_op_network_tbl(I)          := l_eam_op_network_rec;
2742 
2743 
2744     -- Indicate that children need to be processed
2745     l_process_children := TRUE;
2746 
2747     --  For loop exception handler.
2748 
2749     EXCEPTION
2750        WHEN EXC_SEV_QUIT_RECORD THEN
2751         l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
2752         EAM_ERROR_MESSAGE_PVT.Log_Error
2753         (  p_eam_op_network_tbl     => l_eam_op_network_tbl
2754         ,  p_mesg_token_tbl         => l_mesg_token_tbl
2755         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2756         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
2757         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_NETWORK_LEVEL
2758         ,  p_entity_index           => I
2759         ,  x_eam_wo_rec             => l_eam_wo_rec
2760         ,  x_eam_op_tbl             => l_eam_op_tbl
2761         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
2762         ,  x_eam_res_tbl            => l_eam_res_tbl
2763         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
2764         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2765         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2766         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2767         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2768         );
2769         l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
2770 
2771          l_process_children             := FALSE;
2772          IF l_bo_return_status = 'S'
2773          THEN
2774              l_bo_return_status  := l_return_status ;
2775          END IF;
2776          x_return_status                := l_bo_return_status;
2777          x_mesg_token_tbl               := l_mesg_token_tbl ;
2778          x_eam_op_network_tbl           := l_eam_op_network_tbl;
2779 
2780 
2781       WHEN EXC_SEV_QUIT_BRANCH THEN
2782        l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
2783        EAM_ERROR_MESSAGE_PVT.Log_Error
2784         (  p_eam_op_network_tbl     => l_eam_op_network_tbl
2785         ,  p_mesg_token_tbl         => l_mesg_token_tbl
2786         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2787         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
2788         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2789         ,  p_other_message          => l_other_message
2790         ,  p_other_token_tbl        => l_other_token_tbl
2791         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_NETWORK_LEVEL
2792         ,  p_entity_index           => I
2793         ,  x_eam_wo_rec             => l_eam_wo_rec
2794         ,  x_eam_op_tbl             => l_eam_op_tbl
2795         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
2796         ,  x_eam_res_tbl            => l_eam_res_tbl
2797         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
2798         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2799         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2800         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2801         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2802         );
2803        l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
2804 
2805 
2806          l_process_children             := FALSE ;
2807          IF l_bo_return_status = 'S'
2808          THEN
2809              l_bo_return_status  := l_return_status ;
2810          END IF;
2811          x_return_status                := l_bo_return_status;
2812          x_mesg_token_tbl               := l_mesg_token_tbl ;
2813          x_eam_op_network_tbl           := l_eam_op_network_tbl;
2814 
2815 
2816       WHEN EXC_SEV_SKIP_BRANCH THEN
2817        l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
2818        EAM_ERROR_MESSAGE_PVT.Log_Error
2819         (  p_eam_op_network_tbl     => l_eam_op_network_tbl
2820         ,  p_mesg_token_tbl         => l_mesg_token_tbl
2821         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2822         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
2823         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_NOT_PICKED
2824         ,  p_other_message          => l_other_message
2825         ,  p_other_token_tbl        => l_other_token_tbl
2826         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_NETWORK_LEVEL
2827         ,  p_entity_index           => I
2828         ,  x_eam_wo_rec             => l_eam_wo_rec
2829         ,  x_eam_op_tbl             => l_eam_op_tbl
2830         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
2831         ,  x_eam_res_tbl            => l_eam_res_tbl
2832         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
2833         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2834         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2835         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2836         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2837         );
2838        l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
2839 
2840 
2841          l_process_children             := FALSE ;
2842          IF l_bo_return_status = 'S'
2843          THEN
2844              l_bo_return_status  := l_return_status ;
2845          END IF;
2846          x_return_status                := l_bo_return_status;
2847          x_mesg_token_tbl               := l_mesg_token_tbl ;
2848          x_eam_op_network_tbl           := l_eam_op_network_tbl;
2849 
2850 
2851       WHEN EXC_SEV_QUIT_SIBLINGS THEN
2852        l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
2853        EAM_ERROR_MESSAGE_PVT.Log_Error
2854         (  p_eam_op_network_tbl     => l_eam_op_network_tbl
2855         ,  p_mesg_token_tbl         => l_mesg_token_tbl
2856         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2857         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_SIBLINGS
2858         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
2859         ,  p_other_message          => l_other_message
2860         ,  p_other_token_tbl        => l_other_token_tbl
2861         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_NETWORK_LEVEL
2862         ,  p_entity_index           => I
2863         ,  x_eam_wo_rec             => l_eam_wo_rec
2864         ,  x_eam_op_tbl             => l_eam_op_tbl
2865         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
2866         ,  x_eam_res_tbl            => l_eam_res_tbl
2867         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
2868         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2869         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2870         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2871         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2872         );
2873        l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
2874 
2875 
2876          l_process_children             := FALSE ;
2877          IF l_bo_return_status = 'S'
2878          THEN
2879              l_bo_return_status  := l_return_status ;
2880          END IF;
2881          x_return_status                := l_bo_return_status;
2882          x_mesg_token_tbl               := l_mesg_token_tbl ;
2883          x_eam_op_network_tbl           := l_eam_op_network_tbl;
2884 
2885 
2886       WHEN EXC_FAT_QUIT_BRANCH THEN
2887        l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
2888        EAM_ERROR_MESSAGE_PVT.Log_Error
2889         (  p_eam_op_network_tbl     => l_eam_op_network_tbl
2890         ,  p_mesg_token_tbl         => l_mesg_token_tbl
2891         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
2892         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
2893         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
2894         ,  p_other_message          => l_other_message
2895         ,  p_other_token_tbl        => l_other_token_tbl
2896         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_NETWORK_LEVEL
2897         ,  p_entity_index           => I
2898         ,  x_eam_wo_rec             => l_eam_wo_rec
2899         ,  x_eam_op_tbl             => l_eam_op_tbl
2900         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
2901         ,  x_eam_res_tbl            => l_eam_res_tbl
2902         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
2903         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2904         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2905         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2906         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2907         );
2908        l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
2909 
2910 
2911          l_process_children             := FALSE ;
2912          x_return_status                := EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL;
2913          x_mesg_token_tbl               := l_mesg_token_tbl ;
2914          x_eam_op_network_tbl           := l_eam_op_network_tbl;
2915 
2916 
2917 
2918       WHEN EXC_FAT_QUIT_SIBLINGS THEN
2919        l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
2920        EAM_ERROR_MESSAGE_PVT.Log_Error
2921         (  p_eam_op_network_tbl     => l_eam_op_network_tbl
2922         ,  p_mesg_token_tbl         => l_mesg_token_tbl
2923         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
2924         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_SIBLINGS
2925         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
2926         ,  p_other_message          => l_other_message
2927         ,  p_other_token_tbl        => l_other_token_tbl
2928         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_NETWORK_LEVEL
2929         ,  p_entity_index           => I
2930         ,  x_eam_wo_rec             => l_eam_wo_rec
2931         ,  x_eam_op_tbl             => l_eam_op_tbl
2932         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
2933         ,  x_eam_res_tbl            => l_eam_res_tbl
2934         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
2935         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2936         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2937         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2938         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2939         );
2940        l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
2941 
2942 
2943          l_process_children             := FALSE ;
2944          x_return_status                := EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL;
2945          x_mesg_token_tbl               := l_mesg_token_tbl ;
2946          x_eam_op_network_tbl           := l_eam_op_network_tbl;
2947 
2948 
2949       WHEN EXC_UNEXP_SKIP_OBJECT THEN
2950        l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
2951        EAM_ERROR_MESSAGE_PVT.Log_Error
2952         (  p_eam_op_network_tbl     => l_eam_op_network_tbl
2953         ,  p_mesg_token_tbl         => l_mesg_token_tbl
2954         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
2955         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_NOT_PICKED
2956         ,  p_other_message          => l_other_message
2957         ,  p_other_token_tbl        => l_other_token_tbl
2958         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_NETWORK_LEVEL
2959         ,  x_eam_wo_rec             => l_eam_wo_rec
2960         ,  x_eam_op_tbl             => l_eam_op_tbl
2961         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
2962         ,  x_eam_res_tbl            => l_eam_res_tbl
2963         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
2964         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
2965         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
2966         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
2967         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
2968         );
2969        l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
2970 
2971 
2972          l_return_status                := 'U';
2973          x_mesg_token_tbl               := l_mesg_token_tbl ;
2974          x_eam_op_network_tbl           := l_eam_op_network_tbl;
2975 
2976    END ; -- END block
2977 
2978    IF l_return_status in ('Q', 'U')
2979    THEN
2980       x_return_status := l_return_status;
2981       RETURN ;
2982    END IF;
2983 
2984 
2985    END LOOP; -- END Operation Networks processing loop
2986 
2987 
2988    --  Load OUT parameters
2989    IF NVL(l_return_status, 'S') <> 'S'
2990    THEN
2991       x_return_status     := l_return_status;
2992    END IF;
2993 
2994         x_Mesg_Token_Tbl               := l_Mesg_Token_Tbl;
2995         x_eam_op_network_tbl           := l_eam_op_network_tbl;
2996 
2997 END OPERATION_NETWORKS;
2998 
2999 
3000 
3001 
3002 
3003 
3004 PROCEDURE MATERIAL_REQUIREMENTS
3005         (  p_validation_level        IN  NUMBER
3006         ,  p_wip_entity_id           IN  NUMBER := NULL
3007         ,  p_organization_id         IN  NUMBER := NULL
3008         ,  p_operation_seq_num       IN  NUMBER := NULL
3009         ,  p_department_id           IN  NUMBER := NULL
3010         ,  p_eam_mat_req_tbl         IN EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
3011 	,  x_material_shortage       IN OUT NOCOPY NUMBER
3012         ,  x_eam_mat_req_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
3013         ,  x_mesg_token_tbl          OUT NOCOPY EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type
3014         ,  x_return_status           OUT NOCOPY VARCHAR2
3015         )
3016 IS
3017 
3018 l_eam_mat_req_rec       EAM_PROCESS_WO_PUB.eam_mat_req_rec_type ;
3019 l_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type ;
3020 l_old_eam_mat_req_rec   EAM_PROCESS_WO_PUB.eam_mat_req_rec_type ;
3021 
3022 l_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type ;
3023 l_old_eam_wo_rec        EAM_PROCESS_WO_PUB.eam_wo_rec_type ;
3024 l_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type ;
3025 l_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type ;
3026 l_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type ;
3027 l_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type ;
3028 l_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type ;
3029 l_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type ;
3030 l_eam_direct_items_tbl  EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
3031 
3032 l_out_eam_mat_req_rec   EAM_PROCESS_WO_PUB.eam_mat_req_rec_type;
3033 l_out_eam_mat_req_tbl   EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
3034 
3035 /* Error Handling Variables */
3036 l_token_tbl             EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
3037 l_mesg_token_tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
3038 l_other_token_tbl       EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
3039 l_other_message         VARCHAR2(2000);
3040 l_err_text              VARCHAR2(2000);
3041 
3042 /* Others */
3043 l_return_status         VARCHAR2(1) ;
3044 l_pick_return_status    VARCHAR2(1) ;
3045 l_msg_count             NUMBER := 0;
3046 l_bo_return_status      VARCHAR2(1) ;
3047 l_parent_exists         BOOLEAN := FALSE ;
3048 l_process_children      BOOLEAN := TRUE ;
3049 l_valid_transaction     BOOLEAN := TRUE ;
3050 l_organization_id        NUMBER := p_organization_id ;
3051 l_wip_entity_id           NUMBER := p_wip_entity_id ;
3052 l_operation_seq_num    NUMBER := p_operation_seq_num ;
3053 l_wo_status            NUMBER;
3054 l_api_return_status    VARCHAR2(1);
3055 l_api_msg_count        NUMBER;
3056 l_api_msg_data         VARCHAR2(100);
3057 
3058 l_uom_code             VARCHAR2(10);
3059 l_description          VARCHAR2(240);
3060 l_non_stock_flag       VARCHAR2(2);
3061 l_purch_flag           VARCHAR2(2);
3062 l_purch_cat_id         NUMBER;
3063 l_req_number           NUMBER;
3064 l_total_req_qty        NUMBER;
3065 l_po_ordered_qty        NUMBER;
3066 l_req_qty        NUMBER;
3067 
3068 
3069 
3070 BEGIN
3071 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(p_eam_mat_req_tbl.COUNT ||' records passed') ; END IF ;
3072 
3073    x_return_status := FND_API.G_RET_STS_SUCCESS;
3074 
3075 --  Init local table variables.
3076    l_return_status    := 'S' ;
3077    l_bo_return_status := 'S' ;
3078    l_eam_mat_req_tbl    := p_eam_mat_req_tbl ;
3079 
3080 
3081 
3082 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Starting MATERIAL_REQUIREMENTS') ; END IF ;
3083 
3084 
3085 	/* Get the materials in the Operation 1 and append to the table l_eam_mat_req_tbl */
3086    IF ( p_operation_seq_num IS NOT NULL
3087       and EAM_MAT_REQ_UTILITY_PVT.NUM_OF_ROW
3088        (  p_organization_id   => l_organization_id
3089         , p_wip_entity_id     => l_wip_entity_id
3090         , p_operation_seq_num => 1
3091        )  in  (TRUE)) THEN
3092 
3093        l_out_eam_mat_req_tbl := l_eam_mat_req_tbl ;
3094        EAM_MAT_REQ_DEFAULT_PVT.GetMaterials_In_Op1
3095 	   (  p_eam_mat_req_tbl => l_eam_mat_req_tbl
3096 	    , p_organization_id => l_organization_id
3097 		, p_wip_entity_id => l_wip_entity_id
3098 		, x_eam_mat_req_tbl => l_out_eam_mat_req_tbl
3099        );
3100 	   l_eam_mat_req_tbl := l_out_eam_mat_req_tbl ;
3101 
3102 
3103   END IF;
3104 
3105 
3106    FOR I IN 1..l_eam_mat_req_tbl.COUNT LOOP
3107    BEGIN
3108 
3109 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Processing '|| I || ' record') ; END IF ;
3110 
3111       --  Load local records.
3112       l_eam_mat_req_rec := l_eam_mat_req_tbl(I);
3113 
3114       -- make sure to set process_children to false at the start of every iteration
3115 
3116       l_process_children := FALSE;
3117 
3118 
3119       IF l_eam_mat_req_rec.wip_entity_id is NULL
3120          AND (l_eam_mat_req_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
3121              OR l_eam_mat_req_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_SYNC)
3122       THEN
3123           l_eam_mat_req_rec.wip_entity_id := p_wip_entity_id;
3124       END IF;
3125 
3126       IF p_wip_entity_id IS NOT NULL AND
3127          p_organization_id IS NOT NULL AND
3128          p_operation_seq_num IS NOT NULL AND
3129          p_department_id IS NOT NULL
3130       THEN
3131          l_parent_exists := TRUE;
3132          l_eam_mat_req_rec.department_id := p_department_id;
3133       END IF;
3134 
3135       -- Check if record has not yet been processed and that it is the child of the parent that called this procedure
3136 
3137       IF (l_eam_mat_req_rec.return_status IS NULL OR l_eam_mat_req_rec.return_status = FND_API.G_MISS_CHAR)
3138            AND
3139            (NOT l_parent_exists
3140             OR
3141              (l_parent_exists AND
3142               l_eam_mat_req_rec.wip_entity_id = p_wip_entity_id AND
3143               l_eam_mat_req_rec.organization_id = p_organization_id AND
3144               (l_eam_mat_req_rec.operation_seq_num = p_operation_seq_num OR
3145                l_eam_mat_req_rec.operation_seq_num = 1
3146               )
3147              )
3148            )
3149       THEN
3150 
3151 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Return status validation passed') ; END IF ;
3152 
3153          l_return_status := FND_API.G_RET_STS_SUCCESS;
3154          l_eam_mat_req_rec.return_status := FND_API.G_RET_STS_SUCCESS;
3155 
3156 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Validating Transaction Type') ; END IF ;
3157 
3158         VALIDATE_TRANSACTION_TYPE
3159         (   p_transaction_type  => l_eam_mat_req_rec.transaction_type
3160         ,   p_entity_name       => 'MATERIAL_REQUIREMENTS'
3161         ,   p_entity_id         => to_char(l_eam_mat_req_rec.inventory_item_id)
3162         ,   X_valid_transaction => l_valid_transaction
3163         ,   x_mesg_token_tbl    => l_mesg_token_tbl
3164         );
3165 
3166          IF NOT l_valid_transaction
3167          THEN
3168              l_return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
3169              RAISE EXC_SEV_QUIT_RECORD ;
3170          END IF ;
3171 
3172 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Checking Existence of Record') ; END IF ;
3173 
3174          EAM_MAT_REQ_VALIDATE_PVT.Check_Existence
3175          (  p_eam_mat_req_rec            => l_eam_mat_req_rec
3176          ,  x_old_eam_mat_req_rec        => l_old_eam_mat_req_rec
3177          ,  x_mesg_token_tbl         => l_mesg_token_tbl
3178          ,  x_return_status          => l_return_status
3179          ) ;
3180 
3181 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check Existence completed with return_status: ' || l_return_status) ;  END IF ;
3182 
3183          IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
3184          THEN
3185             l_other_message := 'EAM_MR_EXS_SEV_SKIP';
3186             l_other_token_tbl(1).token_name  := 'INV_ITEM_ID';
3187             l_other_token_tbl(1).token_value := l_eam_mat_req_rec.inventory_item_id;
3188             l_other_token_tbl(2).token_name  := 'WIP_ENTITY_ID';
3189             l_other_token_tbl(2).token_value := l_eam_mat_req_rec.wip_entity_id;
3190             RAISE EXC_SEV_QUIT_BRANCH;
3191          ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
3192          THEN
3193             l_other_message := 'EAM_MR_EXS_UNEXP_SKIP';
3194             l_other_token_tbl(1).token_name  := 'INV_ITEM_ID';
3195             l_other_token_tbl(1).token_value := l_eam_mat_req_rec.inventory_item_id ;
3196             l_other_token_tbl(2).token_name  := 'WIP_ENTITY_ID';
3197             l_other_token_tbl(2).token_value := l_eam_mat_req_rec.wip_entity_id ;
3198             RAISE EXC_UNEXP_SKIP_OBJECT;
3199          END IF;
3200 
3201         /* Assign the correct transaction type for SYNC operations */
3202 
3203         IF l_eam_mat_req_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_SYNC THEN
3204            l_eam_mat_req_rec.transaction_type := l_old_eam_mat_req_rec.transaction_type;
3205         END IF;
3206 
3207 
3208         IF l_eam_mat_req_rec.transaction_type IN (EAM_PROCESS_WO_PVT.G_OPR_UPDATE, EAM_PROCESS_WO_PVT.G_OPR_DELETE)
3209         THEN
3210 
3211   	   IF l_eam_mat_req_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_DELETE THEN
3212 		   x_material_shortage := G_MATERIAL_UPDATE;
3213 	   END IF;
3214 
3215            IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Populate NULL columns') ;
3216            END IF ;
3217 
3218            l_out_eam_mat_req_rec := l_eam_mat_req_rec;
3219 
3220            EAM_MAT_REQ_DEFAULT_PVT.Populate_Null_Columns
3221            (   p_eam_mat_req_rec        => l_eam_mat_req_rec
3222            ,   p_old_eam_mat_req_Rec    => l_old_eam_mat_req_rec
3223            ,   x_eam_mat_req_rec     => l_out_eam_mat_req_rec
3224            ) ;
3225 
3226            l_eam_mat_req_rec := l_out_eam_mat_req_rec;
3227 
3228 
3229 		    IF ( p_operation_seq_num IS NOT NULL
3230 	              and l_eam_mat_req_rec.operation_seq_num = 1 ) THEN
3231 
3232                  l_out_eam_mat_req_rec := l_eam_mat_req_rec;
3233 
3234                  EAM_MAT_REQ_DEFAULT_PVT.Change_OpSeqNum1
3235                  (    p_eam_mat_req_rec    => l_eam_mat_req_rec
3236                     , p_operation_seq_num  =>  p_operation_seq_num
3237                     , p_department_id => p_department_id
3238                     , x_eam_mat_req_rec =>  l_out_eam_mat_req_rec
3239                  ) ;
3240 
3241                  l_eam_mat_req_rec := l_out_eam_mat_req_rec;
3242             END IF;
3243 
3244         ELSIF l_eam_mat_req_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
3245         THEN
3246 
3247 	   x_material_shortage := G_MATERIAL_UPDATE;
3248 
3249            l_out_eam_mat_req_rec := l_eam_mat_req_rec;
3250 
3251            EAM_MAT_REQ_DEFAULT_PVT.Attribute_Defaulting
3252            (   p_eam_mat_req_rec   => l_eam_mat_req_rec
3253            ,   x_eam_mat_req_rec   => l_out_eam_mat_req_rec
3254            ,   x_mesg_token_tbl    => l_mesg_token_tbl
3255            ,   x_return_status     => l_return_status
3256            ) ;
3257 
3258            l_eam_mat_req_rec := l_out_eam_mat_req_rec;
3259 
3260            IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug
3261            ('Attribute Defaulting completed with return_status: ' || l_return_status) ;
3262            END IF ;
3263 
3264 
3265            IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
3266            THEN
3267               l_other_message := 'EAM_MR_ATTDEF_CSEV_SKIP';
3268               l_other_token_tbl(1).token_name  := 'Inventory_Item';
3269 --              l_other_token_tbl(1).token_value := l_eam_mat_req_rec.inventory_item_id ;
3270 
3271 	 SELECT concatenated_segments into l_token_tbl(1).token_value
3272 	 FROM  mtl_system_items_kfv msik
3273 	 WHERE 	 msik.inventory_item_id = l_eam_mat_req_rec.inventory_item_id
3274  	 AND     msik.organization_id   = l_eam_mat_req_rec.organization_id;
3275 
3276               RAISE EXC_SEV_SKIP_BRANCH ;
3277 
3278            ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
3279            THEN
3280               l_other_message := 'EAM_MR_ATTDEF_UNEXP_SKIP';
3281               l_other_token_tbl(1).token_name := 'INV_ITEM_ID';
3282               l_other_token_tbl(1).token_value := l_eam_mat_req_rec.inventory_item_id ;
3283               RAISE EXC_UNEXP_SKIP_OBJECT ;
3284            ELSIF l_return_status ='S' AND l_mesg_token_tbl .COUNT <> 0
3285            THEN
3286               l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3287               EAM_ERROR_MESSAGE_PVT.Log_Error
3288                (  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
3289                ,  p_mesg_token_tbl         => l_mesg_token_tbl
3290                ,  p_error_status           => 'W'
3291                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_MAT_REQ_LEVEL
3292                ,  p_entity_index           => I
3293                ,  x_eam_wo_rec             => l_eam_wo_rec
3294                ,  x_eam_op_tbl             => l_eam_op_tbl
3295                ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
3296                ,  x_eam_res_tbl            => l_eam_res_tbl
3297                ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
3298                ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
3299                ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
3300                ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
3301                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
3302                );
3303               l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
3304           END IF;
3305        END IF;
3306 
3307 
3308          EAM_MAT_REQ_VALIDATE_PVT.Check_Required
3309          ( p_eam_mat_req_rec                => l_eam_mat_req_rec
3310          , x_return_status              => l_return_status
3311          , x_mesg_token_tbl             => l_mesg_token_tbl
3312          ) ;
3313 
3314 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check required completed with return_status: ' || l_return_status) ; END IF ;
3315 
3316 
3317          IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
3318          THEN
3319             IF l_eam_mat_req_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
3320             THEN
3321                l_other_message := 'EAM_MR_REQ_CSEV_SKIP';
3322                l_other_token_tbl(1).token_name  := 'INV_ITEM_ID';
3323                l_other_token_tbl(1).token_value := l_eam_mat_req_rec.inventory_item_id ;
3324                RAISE EXC_SEV_SKIP_BRANCH ;
3325             ELSE
3326                RAISE EXC_SEV_QUIT_RECORD ;
3327             END IF;
3328          ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
3329          THEN
3330             l_other_message := 'EAM_MR_REQ_UNEXP_SKIP';
3331             l_other_token_tbl(1).token_name  := 'INV_ITEM_ID';
3332             l_other_token_tbl(1).token_value := l_eam_mat_req_rec.inventory_item_id ;
3333             RAISE EXC_UNEXP_SKIP_OBJECT ;
3334          END IF;
3335 
3336 
3337             EAM_MAT_REQ_VALIDATE_PVT.Check_Attributes
3338             ( p_eam_mat_req_rec        => l_eam_mat_req_rec
3339             , p_old_eam_mat_req_rec    => l_old_eam_mat_req_rec
3340             , x_return_status     => l_return_status
3341             , x_mesg_token_tbl    => l_mesg_token_tbl
3342             ) ;
3343 
3344 	IF l_old_eam_mat_req_rec.REQUIRED_QUANTITY <> l_eam_mat_req_rec.REQUIRED_QUANTITY THEN
3345 		x_material_shortage := G_MATERIAL_UPDATE;
3346 	END IF;
3347 
3348 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Attribute validation completed with return_status: ' || l_return_status) ; END IF ;
3349 
3350             IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
3351             THEN
3352                IF l_eam_mat_req_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
3353                THEN
3354                   l_other_message := 'EAM_MR_ATTVAL_CSEV_SKIP';
3355                   l_other_token_tbl(1).token_name := 'INV_ITEM_ID';
3356                   l_other_token_tbl(1).token_value := l_eam_mat_req_rec.inventory_item_id ;
3357                   RAISE EXC_SEV_SKIP_BRANCH ;
3358                   ELSE
3359                      RAISE EXC_SEV_QUIT_RECORD ;
3360                END IF;
3361             ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
3362             THEN
3363                l_other_message := 'EAM_MR_ATTVAL_UNEXP_SKIP';
3364                l_other_token_tbl(1).token_name := 'INV_ITEM_ID';
3365                l_other_token_tbl(1).token_value := l_eam_mat_req_rec.inventory_item_id ;
3366                RAISE EXC_UNEXP_SKIP_OBJECT ;
3367             ELSIF l_return_status ='S' AND l_mesg_token_tbl .COUNT <> 0
3368             THEN
3369               l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3370               EAM_ERROR_MESSAGE_PVT.Log_Error
3371                ( p_eam_mat_req_tbl        => l_eam_mat_req_tbl
3372                ,  p_mesg_token_tbl         => l_mesg_token_tbl
3373                ,  p_error_status           => 'W'
3374                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_MAT_REQ_LEVEL
3375                ,  p_entity_index           => I
3376                ,  x_eam_wo_rec             => l_eam_wo_rec
3377                ,  x_eam_op_tbl             => l_eam_op_tbl
3378                ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
3379                ,  x_eam_res_tbl            => l_eam_res_tbl
3380                ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
3381                ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
3382                ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
3383                ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
3384                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
3385                );
3386               l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
3387 
3388            END IF;
3389 
3390 
3391 
3392           EAM_MAT_REQ_UTILITY_PVT.Perform_Writes
3393           (   p_eam_mat_req_rec          => l_eam_mat_req_rec
3394           ,   x_mesg_token_tbl      => l_mesg_token_tbl
3395           ,   x_return_status       => l_return_status
3396           ) ;
3397 
3398 
3399        IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
3400        THEN
3401           l_other_message := 'EAM_MR_WRITES_UNEXP_SKIP';
3402           l_other_token_tbl(1).token_name := 'INV_ITEM_ID';
3403           l_other_token_tbl(1).token_value :=
3404                           l_eam_mat_req_rec.inventory_item_id ;
3405           RAISE EXC_UNEXP_SKIP_OBJECT ;
3406        ELSIF l_return_status ='S' AND
3407           l_mesg_token_tbl.COUNT <>0
3408        THEN
3409             l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3410             EAM_ERROR_MESSAGE_PVT.Log_Error
3411                ( p_eam_mat_req_tbl        => l_eam_mat_req_tbl
3412                ,  p_mesg_token_tbl         => l_mesg_token_tbl
3413                ,  p_error_status           => 'W'
3414                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_MAT_REQ_LEVEL
3415                ,  p_entity_index           => I
3416                ,  x_eam_wo_rec             => l_eam_wo_rec
3417                ,  x_eam_op_tbl             => l_eam_op_tbl
3418                ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
3419                ,  x_eam_res_tbl            => l_eam_res_tbl
3420                ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
3421                ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
3422                ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
3423                ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
3424                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
3425                );
3426               l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
3427        END IF;
3428 
3429 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Material Requirements Database writes completed with status  ' || l_return_status); END IF;
3430 
3431 
3432        -- Stock Issue requirements
3433        EAM_WO_UTILITY_PVT.Query_Row(
3434            p_wip_entity_id       => l_eam_mat_req_rec.wip_entity_id
3435          , p_organization_id     => l_eam_mat_req_rec.organization_id
3436          , x_eam_wo_rec          => l_old_eam_wo_rec
3437          , x_Return_status       => l_return_status
3438        );
3439 --Bug4188160:pass item description instead of item name
3440        select primary_uom_code, stock_enabled_flag,
3441          purchasing_item_flag, description
3442          into l_uom_code, l_non_stock_flag,
3443          l_purch_flag, l_description
3444          from mtl_system_items_b_kfv
3445          where inventory_item_id = l_eam_mat_req_rec.inventory_item_id
3446          and organization_id = l_eam_mat_req_rec.organization_id;
3447 
3448       IF l_non_stock_flag = 'Y' then
3449          --fix for 3550864.allocate requested_quantity if passed
3450 					   IF(l_eam_mat_req_rec.requested_quantity IS NOT NULL) THEN
3451 
3452 							 EAM_MATERIAL_REQUEST_PVT.allocate
3453 												 (p_api_version        => 1.0,
3454 												 p_init_msg_list      => fnd_api.g_false,
3455 												 p_commit             => fnd_api.g_false,
3456 												 p_wip_entity_id      => l_eam_mat_req_rec.wip_entity_id,
3457 												 p_organization_id    => l_eam_mat_req_rec.organization_id,
3458 												 p_operation_seq_num  => l_eam_mat_req_rec.operation_seq_num,
3459 												 p_inventory_item_id  => l_eam_mat_req_rec.inventory_item_id,
3460 												 p_wip_entity_type    => wip_constants.discrete,
3461 												 p_requested_quantity =>l_eam_mat_req_rec.requested_quantity,
3462 												 p_source_subinventory => l_eam_mat_req_rec.supply_subinventory,
3463                                                                                                  p_source_locator      => l_eam_mat_req_rec.supply_locator_id,
3464 												 x_request_number     => l_req_number,
3465 												 x_return_status      => l_pick_return_status,
3466 												 x_msg_data           => l_err_text,
3467 												 x_msg_count          => l_msg_count);
3468 
3469 					  ELSE
3470 
3471 
3472 											   IF l_old_eam_wo_rec.status_type in (3,4) -- released, complete
3473 											   and l_old_eam_wo_rec.material_issue_by_mo = 'Y'
3474 											   and l_old_eam_wo_rec.maintenance_object_source = 1 -- Only for EAM
3475 											   and l_eam_mat_req_rec.wip_supply_type =1   --only for 'push' type items..allocations shud not be done for bulk items
3476 											   and
3477 											   ((l_eam_mat_req_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UPDATE
3478 												 and l_old_eam_mat_req_rec.auto_request_material = 'N'
3479 												 and l_eam_mat_req_rec.auto_request_material = 'Y'  -- AUTO_REQUEST_MATERIAL flag turned on
3480 												) OR
3481 												(l_eam_mat_req_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UPDATE
3482 												 and l_old_eam_mat_req_rec.required_quantity <> l_eam_mat_req_rec.required_quantity -- reqd qty updating
3483 												) OR
3484 												(l_eam_mat_req_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
3485 												 and l_eam_mat_req_rec.auto_request_material = 'Y' -- new mtl line adding with auto req flag on.
3486 												)
3487 											   )
3488 											   THEN
3489 
3490 														l_eam_mat_req_rec.invoke_allocations_api := 'Y';
3491 
3492 											   END IF;
3493 					 END IF;--end of check for requested_quantity
3494 	      END IF;
3495 
3496 
3497 
3498        -- create requisitions if the quantity has changed and wo is in released status
3499        -- and item is non-stockable/purchasable item.
3500        select status_type into l_wo_status from
3501          wip_discrete_jobs
3502          where wip_entity_id = l_eam_mat_req_rec.wip_entity_id
3503          and organization_id = l_eam_mat_req_rec.organization_id;
3504 
3505 
3506 --fix for 3550864.create requisitions for  requested_quantity if passed
3507        IF(l_non_stock_flag = 'N' and l_eam_mat_req_rec.requested_quantity IS NOT NULL) THEN
3508 
3509 
3510 
3511 		select mic.category_id into l_purch_cat_id
3512 		from mtl_item_categories mic,
3513 		mtl_default_category_sets mdcs where
3514 		mic.inventory_item_id = l_eam_mat_req_rec.inventory_item_id
3515 		and mic.organization_id = l_eam_mat_req_rec.organization_id
3516 		and mic.category_set_id = mdcs.category_set_id
3517 		and mdcs.functional_area_id = 2;
3518 
3519 
3520                 EAM_PROCESS_WO_UTIL_PVT.create_requisition
3521                   (  p_api_version                 => 1.0
3522                     ,p_init_msg_list               => FND_API.G_FALSE
3523                     ,p_commit                      => FND_API.G_FALSE
3524                     ,p_validate_only               => FND_API.G_TRUE
3525                     ,x_return_status               => l_api_return_status
3526                     ,x_msg_count                   => l_api_msg_count
3527                     ,x_msg_data                    => l_api_msg_data
3528                     ,p_wip_entity_id               => l_eam_mat_req_rec.wip_entity_id
3529                     ,p_operation_seq_num           => l_eam_mat_req_rec.operation_seq_num
3530                     ,p_organization_id             => l_eam_mat_req_rec.organization_id
3531                     ,p_user_id                     => fnd_global.user_id
3532                     ,p_responsibility_id           => fnd_global.resp_id
3533                     ,p_quantity                    => l_eam_mat_req_rec.requested_quantity
3534                     ,p_unit_price                  => l_eam_mat_req_rec.unit_price
3535                     ,p_category_id                 => l_purch_cat_id
3536                     ,p_item_description            => l_description
3537                     ,p_uom_code                    => l_uom_code
3538                     ,p_need_by_date                => l_eam_mat_req_rec.date_required
3539                     ,p_inventory_item_id           => l_eam_mat_req_rec.inventory_item_id
3540                     ,p_direct_item_id              => null
3541 		    , p_suggested_vendor_id        => l_eam_mat_req_rec.vendor_id
3542                     ,p_suggested_vendor_name       => l_eam_mat_req_rec.suggested_vendor_name
3543                     ,p_suggested_vendor_site       => null
3544                     ,p_suggested_vendor_phone      => null
3545                     ,p_suggested_vendor_item_num   => null
3546                  );
3547 
3548 
3549    IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('create requisitions for non-stockable direct items'); END IF;
3550 
3551        ELSE
3552 
3553 
3554        if l_wo_status = 3
3555          and l_eam_mat_req_rec.auto_request_material = 'Y'
3556          and l_non_stock_flag = 'N'
3557          and l_purch_flag = 'Y'
3558          and (l_eam_mat_req_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
3559               OR (l_eam_mat_req_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UPDATE
3560                   /*and l_old_eam_mat_req_rec.required_quantity < l_eam_mat_req_rec.required_quantity commented for #6118897*/)
3561               OR (l_eam_mat_req_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UPDATE
3562                   and nvl(l_old_eam_mat_req_rec.auto_request_material,'N')='N')
3563        )then
3564 
3565 		select mic.category_id into l_purch_cat_id
3566 		from mtl_item_categories mic,
3567 		mtl_default_category_sets mdcs where
3568 		mic.inventory_item_id = l_eam_mat_req_rec.inventory_item_id
3569 		and mic.organization_id = l_eam_mat_req_rec.organization_id
3570 		and mic.category_set_id = mdcs.category_set_id
3571 		and mdcs.functional_area_id = 2;
3572 
3573 
3574 -- query modified for bug# 3691325.
3575 -- query modified for bug# 4862404 (Performance).
3576 /*union added for #6118897 to avoid duplicate requisition creation -- start*/
3577        SELECT SUM(nvl(req_qty,0)) INTO l_req_qty
3578    		FROM
3579 		(SELECT SUM(nvl(quantity,0)) req_qty
3580 		  FROM po_requisitions_interface_all pria
3581 		  WHERE  pria.wip_entity_id = l_eam_mat_req_rec.wip_entity_id
3582 		       AND pria.destination_organization_id = l_eam_mat_req_rec.organization_id
3583 		       AND pria.wip_operation_seq_num = l_eam_mat_req_rec.operation_seq_num
3584 		       AND pria.item_id = l_eam_mat_req_rec.inventory_item_id
3585 		       AND ((process_flag is null) or (Upper(Trim(process_flag)) = 'IN PROCESS'))
3586 		UNION ALL
3587 	          SELECT sum(rql.quantity) req_qty
3588         	   FROM po_requisition_lines_all rql,   po_requisition_headers_all rqh
3589 	           WHERE rql.wip_entity_id = l_eam_mat_req_rec.wip_entity_id
3590         	   AND rql.destination_organization_id = l_eam_mat_req_rec.organization_id
3591 	           AND rql.wip_operation_seq_num = l_eam_mat_req_rec.operation_seq_num
3592         	   AND rql.requisition_header_id = rqh.requisition_header_id(+)
3593 	           AND upper(NVL(rqh.authorization_status, 'APPROVED') ) not in ('CANCELLED', 'REJECTED','SYSTEM_SAVED')
3594         	   AND rql.wip_resource_seq_num is null
3595 	           AND rql.item_id = l_eam_mat_req_rec.inventory_item_id
3596 	        );
3597 /*  6118897 ---- end */
3598 
3599 
3600 	SELECT sum(pda.quantity_ordered) INTO l_po_ordered_qty
3601 	  FROM po_lines_all poa, po_distributions_all pda
3602 	 WHERE poa.po_line_id = pda.po_line_id
3603 	   AND pda.wip_entity_id = l_eam_mat_req_rec.wip_entity_id
3604 	   AND pda.destination_organization_id= l_eam_mat_req_rec.organization_id
3605 	   AND pda.wip_operation_seq_num = l_eam_mat_req_rec.operation_seq_num
3606 	   AND upper(nvl(poa.cancel_flag, 'N')) <> 'Y'
3607 	   AND pda.wip_resource_seq_num is null
3608 	   AND poa.item_id = l_eam_mat_req_rec.inventory_item_id;
3609 
3610         IF (l_req_qty > l_po_ordered_qty) THEN
3611 	   l_total_req_qty := l_req_qty ;
3612 	ELSE
3613 	   l_total_req_qty := l_po_ordered_qty ;
3614 	END IF;
3615 
3616 
3617 --   IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('creating reqs for quantity'||l_total_req_qty ||' required qty :'||l_eam_mat_req_rec.required_quantity); END IF;
3618 
3619 	     EAM_PROCESS_WO_UTIL_PVT.create_requisition
3620                (  p_api_version                 => 1.0
3621                  ,p_init_msg_list               => FND_API.G_FALSE
3622                  ,p_commit                      => FND_API.G_FALSE
3623                  ,p_validate_only               => FND_API.G_TRUE
3624                  ,x_return_status               => l_api_return_status
3625                  ,x_msg_count                   => l_api_msg_count
3626                  ,x_msg_data                    => l_api_msg_data
3627                  ,p_wip_entity_id               => l_eam_mat_req_rec.wip_entity_id
3628                  ,p_operation_seq_num           => l_eam_mat_req_rec.operation_seq_num
3629                  ,p_organization_id             => l_eam_mat_req_rec.organization_id
3630                  ,p_user_id                     => fnd_global.user_id
3631                  ,p_responsibility_id           => fnd_global.resp_id
3632                  ,p_quantity                    => (l_eam_mat_req_rec.required_quantity
3633                                                    -nvl(l_total_req_qty,0))
3634                  ,p_unit_price                  => l_eam_mat_req_rec.unit_price
3635                  ,p_category_id                 => l_purch_cat_id
3636                  ,p_item_description            => l_description
3637                  ,p_uom_code                    => l_uom_code
3638                  ,p_need_by_date                => l_eam_mat_req_rec.date_required
3639                  ,p_inventory_item_id           => l_eam_mat_req_rec.inventory_item_id
3640                  ,p_direct_item_id              => null
3641 		 , p_suggested_vendor_id        => l_eam_mat_req_rec.vendor_id
3642                  ,p_suggested_vendor_name       => l_eam_mat_req_rec.suggested_vendor_name
3643                  ,p_suggested_vendor_site       => null
3644                  ,p_suggested_vendor_phone      => null
3645                  ,p_suggested_vendor_item_num   => null
3646               );
3647 
3648        end if;
3649 
3650      END IF;   --end of check for requested_quantity
3651 
3652     ELSE
3653 
3654 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Skipping '|| I || ' record') ; END IF ;
3655 
3656     END IF; -- END IF statement that checks RETURN STATUS
3657 
3658 
3659 
3660     --  Load tables.
3661     l_eam_mat_req_tbl(I)          := l_eam_mat_req_rec;
3662 
3663 
3664     -- Indicate that children need to be processed
3665     l_process_children := TRUE;
3666 
3667     --  For loop exception handler.
3668 
3669     EXCEPTION
3670        WHEN EXC_SEV_QUIT_RECORD THEN
3671         l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3672         EAM_ERROR_MESSAGE_PVT.Log_Error
3673         (  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
3674         ,  p_mesg_token_tbl         => l_mesg_token_tbl
3675         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
3676         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
3677         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_MAT_REQ_LEVEL
3678         ,  p_entity_index           => I
3679         ,  x_eam_wo_rec             => l_eam_wo_rec
3680         ,  x_eam_op_tbl             => l_eam_op_tbl
3681         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
3682         ,  x_eam_res_tbl            => l_eam_res_tbl
3683         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
3684         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
3685         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
3686         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
3687         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
3688         );
3689         l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
3690 
3691          l_process_children             := FALSE;
3692          IF l_bo_return_status = 'S'
3693          THEN
3694              l_bo_return_status  := l_return_status ;
3695          END IF;
3696          x_return_status                := l_bo_return_status;
3697          x_mesg_token_tbl               := l_mesg_token_tbl ;
3698          x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
3699 
3700 
3701       WHEN EXC_SEV_QUIT_BRANCH THEN
3702        l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3703        EAM_ERROR_MESSAGE_PVT.Log_Error
3704         (  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
3705         ,  p_mesg_token_tbl         => l_mesg_token_tbl
3706         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
3707         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
3708         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
3709         ,  p_other_message          => l_other_message
3710         ,  p_other_token_tbl        => l_other_token_tbl
3711         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_MAT_REQ_LEVEL
3712         ,  p_entity_index           => I
3713         ,  x_eam_wo_rec             => l_eam_wo_rec
3714         ,  x_eam_op_tbl             => l_eam_op_tbl
3715         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
3716         ,  x_eam_res_tbl            => l_eam_res_tbl
3717         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
3718         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
3719         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
3720         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
3721         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
3722         );
3723        l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
3724 
3725 
3726          l_process_children             := FALSE ;
3727          IF l_bo_return_status = 'S'
3728          THEN
3729              l_bo_return_status  := l_return_status ;
3730          END IF;
3731          x_return_status                := l_bo_return_status;
3732          x_mesg_token_tbl               := l_mesg_token_tbl ;
3733          x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
3734 
3735 
3736       WHEN EXC_SEV_SKIP_BRANCH THEN
3737        l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3738        EAM_ERROR_MESSAGE_PVT.Log_Error
3739         (  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
3740         ,  p_mesg_token_tbl         => l_mesg_token_tbl
3741         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
3742         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
3743         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_NOT_PICKED
3744         ,  p_other_message          => l_other_message
3745         ,  p_other_token_tbl        => l_other_token_tbl
3746         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_MAT_REQ_LEVEL
3747         ,  p_entity_index           => I
3748         ,  x_eam_wo_rec             => l_eam_wo_rec
3749         ,  x_eam_op_tbl             => l_eam_op_tbl
3750         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
3751         ,  x_eam_res_tbl            => l_eam_res_tbl
3752         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
3753         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
3754         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
3755         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
3756         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
3757         );
3758        l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
3759 
3760          l_process_children             := FALSE ;
3761          IF l_bo_return_status = 'S'
3762          THEN
3763              l_bo_return_status  := l_return_status ;
3764          END IF;
3765          x_return_status                := l_bo_return_status;
3766          x_mesg_token_tbl               := l_mesg_token_tbl ;
3767          x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
3768 
3769 
3770       WHEN EXC_SEV_QUIT_SIBLINGS THEN
3771        l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3772        EAM_ERROR_MESSAGE_PVT.Log_Error
3773         (  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
3774         ,  p_mesg_token_tbl         => l_mesg_token_tbl
3775         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
3776         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_SIBLINGS
3777         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
3778         ,  p_other_message          => l_other_message
3779         ,  p_other_token_tbl        => l_other_token_tbl
3780         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_MAT_REQ_LEVEL
3781         ,  p_entity_index           => I
3782         ,  x_eam_wo_rec             => l_eam_wo_rec
3783         ,  x_eam_op_tbl             => l_eam_op_tbl
3784         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
3785         ,  x_eam_res_tbl            => l_eam_res_tbl
3786         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
3787         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
3788         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
3789         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
3790         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
3791         );
3792        l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
3793 
3794          l_process_children             := FALSE ;
3795          IF l_bo_return_status = 'S'
3796          THEN
3797              l_bo_return_status  := l_return_status ;
3798          END IF;
3799          x_return_status                := l_bo_return_status;
3800          x_mesg_token_tbl               := l_mesg_token_tbl ;
3801          x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
3802 
3803 
3804       WHEN EXC_FAT_QUIT_BRANCH THEN
3805        l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3806        EAM_ERROR_MESSAGE_PVT.Log_Error
3807         (  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
3808         ,  p_mesg_token_tbl         => l_mesg_token_tbl
3809         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
3810         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
3811         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
3812         ,  p_other_message          => l_other_message
3813         ,  p_other_token_tbl        => l_other_token_tbl
3814         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_MAT_REQ_LEVEL
3815         ,  p_entity_index           => I
3816         ,  x_eam_wo_rec             => l_eam_wo_rec
3817         ,  x_eam_op_tbl             => l_eam_op_tbl
3818         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
3819         ,  x_eam_res_tbl            => l_eam_res_tbl
3820         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
3821         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
3822         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
3823         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
3824         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
3825         );
3826        l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
3827 
3828          l_process_children             := FALSE ;
3829          x_return_status                := EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL;
3830          x_mesg_token_tbl               := l_mesg_token_tbl ;
3831          x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
3832 
3833 
3834       WHEN EXC_FAT_QUIT_SIBLINGS THEN
3835        l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3836        EAM_ERROR_MESSAGE_PVT.Log_Error
3837         (  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
3838         ,  p_mesg_token_tbl         => l_mesg_token_tbl
3839         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
3840         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_SIBLINGS
3841         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
3842         ,  p_other_message          => l_other_message
3843         ,  p_other_token_tbl        => l_other_token_tbl
3844         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_MAT_REQ_LEVEL
3845         ,  p_entity_index           => I
3846         ,  x_eam_wo_rec             => l_eam_wo_rec
3847         ,  x_eam_op_tbl             => l_eam_op_tbl
3848         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
3849         ,  x_eam_res_tbl            => l_eam_res_tbl
3850         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
3851         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
3852         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
3853         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
3854         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
3855         );
3856        l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
3857 
3858 
3859          l_process_children             := FALSE ;
3860          x_return_status                := EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL;
3861          x_mesg_token_tbl               := l_mesg_token_tbl ;
3862          x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
3863 
3864       WHEN EXC_UNEXP_SKIP_OBJECT THEN
3865        l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
3866        EAM_ERROR_MESSAGE_PVT.Log_Error
3867         (  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
3868         ,  p_mesg_token_tbl         => l_mesg_token_tbl
3869         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
3870         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_NOT_PICKED
3871         ,  p_other_message          => l_other_message
3872         ,  p_other_token_tbl        => l_other_token_tbl
3873         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_MAT_REQ_LEVEL
3874         ,  x_eam_wo_rec             => l_eam_wo_rec
3875         ,  x_eam_op_tbl             => l_eam_op_tbl
3876         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
3877         ,  x_eam_res_tbl            => l_eam_res_tbl
3878         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
3879         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
3880         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
3881         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
3882         ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
3883         );
3884        l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
3885 
3886 
3887          l_return_status                := 'U';
3888          x_mesg_token_tbl               := l_mesg_token_tbl ;
3889          x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
3890 
3891    END ; -- END block
3892 
3893    IF l_return_status in ('Q', 'U')
3894    THEN
3895       x_return_status := l_return_status;
3896       RETURN ;
3897    END IF;
3898 
3899 
3900    END LOOP; -- END Material Requirements processing loop
3901 
3902 
3903    --  Load OUT parameters
3904    IF NVL(l_return_status, 'S') <> 'S'
3905    THEN
3906    x_return_status     := l_return_status;
3907    END IF;
3908 
3909    x_Mesg_Token_Tbl               := l_Mesg_Token_Tbl;
3910    x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
3911 
3912 END MATERIAL_REQUIREMENTS;
3913 
3914 
3915 
3916 
3917 
3918 
3919 
3920 
3921 
3922 
3923 
3924 
3925 
3926 
3927 
3928 
3929 
3930 
3931 PROCEDURE DIRECT_ITEMS
3932         (  p_validation_level        IN  NUMBER
3933         ,  p_wip_entity_id           IN  NUMBER := NULL
3934         ,  p_organization_id         IN  NUMBER := NULL
3935         ,  p_operation_seq_num       IN  NUMBER := NULL
3936         ,  p_department_id           IN  NUMBER := NULL
3937         ,  p_eam_direct_items_tbl         IN EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
3938 	,  x_material_shortage       IN OUT NOCOPY NUMBER
3939         ,  x_eam_direct_items_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
3940         ,  x_mesg_token_tbl          OUT NOCOPY EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type
3941         ,  x_return_status           OUT NOCOPY VARCHAR2
3942         )
3943 IS
3944 
3945 l_eam_direct_items_rec       EAM_PROCESS_WO_PUB.eam_direct_items_rec_type ;
3946 l_eam_direct_items_tbl       EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type ;
3947 l_old_eam_direct_items_rec   EAM_PROCESS_WO_PUB.eam_direct_items_rec_type ;
3948 
3949 l_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type ;
3950 l_old_eam_wo_rec        EAM_PROCESS_WO_PUB.eam_wo_rec_type ;
3951 l_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type ;
3952 l_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type ;
3953 l_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type ;
3954 l_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type ;
3955 l_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type ;
3956 l_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type ;
3957 l_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type ;
3958 
3959 l_out_eam_direct_items_rec   EAM_PROCESS_WO_PUB.eam_direct_items_rec_type;
3960 l_out_eam_direct_items_tbl   EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
3961 
3962 /* Error Handling Variables */
3963 l_token_tbl             EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
3964 l_mesg_token_tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
3965 l_other_token_tbl       EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
3966 l_other_message         VARCHAR2(2000);
3967 l_err_text              VARCHAR2(2000);
3968 
3969 /* Others */
3970 l_return_status         VARCHAR2(1) ;
3971 l_pick_return_status    VARCHAR2(1) ;
3972 l_msg_count             NUMBER := 0;
3973 l_bo_return_status      VARCHAR2(1) ;
3974 l_parent_exists         BOOLEAN := FALSE ;
3975 l_process_children      BOOLEAN := TRUE ;
3976 l_valid_transaction     BOOLEAN := TRUE ;
3977 l_organization_id        NUMBER := p_organization_id ;
3978 l_wip_entity_id           NUMBER := p_wip_entity_id ;
3979 l_operation_seq_num    NUMBER := p_operation_seq_num ;
3980 l_wo_status            NUMBER := 0;
3981 
3982 l_api_return_status    VARCHAR2(1) := '';
3983 l_api_msg_count        NUMBER;
3984 l_api_msg_data         VARCHAR2(80);
3985 l_total_req_qty		NUMBER;
3986 
3987 BEGIN
3988 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(p_eam_direct_items_tbl.COUNT ||' records passed') ; END IF ;
3989 
3990    x_return_status := FND_API.G_RET_STS_SUCCESS;
3991 
3992 --  Init local table variables.
3993    l_return_status    := 'S' ;
3994    l_bo_return_status := 'S' ;
3995    l_eam_direct_items_tbl    := p_eam_direct_items_tbl ;
3996 
3997 
3998 
3999 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Starting DIRECT_ITEMS') ; END IF ;
4000 
4001 
4002 	/* Get the materials in the Operation 1 and append to the table l_eam_direct_items_tbl */
4003    IF ( p_operation_seq_num IS NOT NULL
4004       and EAM_DIRECT_ITEMS_UTILITY_PVT.NUM_OF_ROW
4005        (  p_organization_id   => l_organization_id
4006         , p_wip_entity_id     => l_wip_entity_id
4007         , p_operation_seq_num => 1
4008        )  in  (TRUE)) THEN
4009 
4010        l_out_eam_direct_items_tbl := l_eam_direct_items_tbl ;
4011        EAM_DIRECT_ITEMS_DEFAULT_PVT.GetDI_In_Op1
4012 	   (  p_eam_direct_items_tbl => l_eam_direct_items_tbl
4013 	    , p_organization_id => l_organization_id
4014 		, p_wip_entity_id => l_wip_entity_id
4015 		, x_eam_direct_items_tbl => l_out_eam_direct_items_tbl
4016        );
4017 	   l_eam_direct_items_tbl := l_out_eam_direct_items_tbl ;
4018 
4019 
4020   END IF;
4021 
4022 
4023    FOR I IN 1..l_eam_direct_items_tbl.COUNT LOOP
4024    BEGIN
4025 
4026 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Processing '|| I || ' record') ; END IF ;
4027 
4028       --  Load local records.
4029       l_eam_direct_items_rec := l_eam_direct_items_tbl(I);
4030 
4031       -- make sure to set process_children to false at the start of every iteration
4032 
4033       l_process_children := FALSE;
4034 
4035 
4036       IF l_eam_direct_items_rec.wip_entity_id is NULL
4037          AND (l_eam_direct_items_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
4038              OR l_eam_direct_items_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_SYNC)
4039       THEN
4040           l_eam_direct_items_rec.wip_entity_id := p_wip_entity_id;
4041       END IF;
4042 
4043       IF p_wip_entity_id IS NOT NULL AND
4044          p_organization_id IS NOT NULL AND
4045          p_operation_seq_num IS NOT NULL AND
4046          p_department_id IS NOT NULL
4047       THEN
4048          l_parent_exists := TRUE;
4049          l_eam_direct_items_rec.department_id := p_department_id;
4050       END IF;
4051 
4052       -- Check if record has not yet been processed and that it is the child of the parent that called this procedure
4053 
4054       IF (l_eam_direct_items_rec.return_status IS NULL OR l_eam_direct_items_rec.return_status = FND_API.G_MISS_CHAR)
4055            AND
4056            (NOT l_parent_exists
4057             OR
4058              (l_parent_exists AND
4059               l_eam_direct_items_rec.wip_entity_id = p_wip_entity_id AND
4060               l_eam_direct_items_rec.organization_id = p_organization_id AND
4061               (l_eam_direct_items_rec.operation_seq_num = p_operation_seq_num OR
4062                l_eam_direct_items_rec.operation_seq_num = 1
4063               )
4064              )
4065            )
4066       THEN
4067 
4068 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Return status validation passed') ; END IF ;
4069 
4070          l_return_status := FND_API.G_RET_STS_SUCCESS;
4071          l_eam_direct_items_rec.return_status := FND_API.G_RET_STS_SUCCESS;
4072 
4073 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Validating Transaction Type') ; END IF ;
4074 
4075         VALIDATE_TRANSACTION_TYPE
4076         (   p_transaction_type  => l_eam_direct_items_rec.transaction_type
4077         ,   p_entity_name       => 'DIRECT_ITEMS'
4078         ,   p_entity_id         => to_char(l_eam_direct_items_rec.direct_item_sequence_id)
4079         ,   X_valid_transaction => l_valid_transaction
4080         ,   x_mesg_token_tbl    => l_mesg_token_tbl
4081         );
4082 
4083          IF NOT l_valid_transaction
4084          THEN
4085              l_return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
4086              RAISE EXC_SEV_QUIT_RECORD ;
4087          END IF ;
4088 
4089 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Checking Existence of Record') ; END IF ;
4090 
4091          EAM_DIRECT_ITEMS_VALIDATE_PVT.Check_Existence
4092          (  p_eam_direct_items_rec            => l_eam_direct_items_rec
4093          ,  x_old_eam_direct_items_rec        => l_old_eam_direct_items_rec
4094          ,  x_mesg_token_tbl         => l_mesg_token_tbl
4095          ,  x_return_status          => l_return_status
4096          ) ;
4097 
4098 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check Existence completed with return_status: ' || l_return_status) ;  END IF ;
4099 
4100          IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
4101          THEN
4102             l_other_message := 'EAM_DI_EXS_SEV_SKIP';
4103             l_other_token_tbl(1).token_name  := 'DI_SEQ_ID';
4104             l_other_token_tbl(1).token_value := l_eam_direct_items_rec.direct_item_sequence_id;
4105             l_other_token_tbl(2).token_name  := 'WIP_ENTITY_ID';
4106             l_other_token_tbl(2).token_value := l_eam_direct_items_rec.wip_entity_id;
4107             RAISE EXC_SEV_QUIT_BRANCH;
4108          ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
4109          THEN
4110             l_other_message := 'EAM_DI_EXS_UNEXP_SKIP';
4111             l_other_token_tbl(1).token_name  := 'DI_SEQ_ID';
4112             l_other_token_tbl(1).token_value := l_eam_direct_items_rec.direct_item_sequence_id ;
4113             l_other_token_tbl(2).token_name  := 'WIP_ENTITY_ID';
4114             l_other_token_tbl(2).token_value := l_eam_direct_items_rec.wip_entity_id ;
4115             RAISE EXC_UNEXP_SKIP_OBJECT;
4116          END IF;
4117 
4118         /* Assign the correct transaction type for SYNC operations */
4119 
4120         IF l_eam_direct_items_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_SYNC THEN
4121            l_eam_direct_items_rec.transaction_type := l_old_eam_direct_items_rec.transaction_type;
4122         END IF;
4123 
4124 
4125         IF l_eam_direct_items_rec.transaction_type IN (EAM_PROCESS_WO_PVT.G_OPR_UPDATE, EAM_PROCESS_WO_PVT.G_OPR_DELETE)
4126         THEN
4127 
4128 	IF l_eam_direct_items_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_DELETE THEN
4129 		x_material_shortage := G_MATERIAL_UPDATE;
4130 	END IF;
4131 
4132            IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Populate NULL columns') ;
4133            END IF ;
4134 
4135            l_out_eam_direct_items_rec := l_eam_direct_items_rec;
4136 
4137            EAM_DIRECT_ITEMS_DEFAULT_PVT.Populate_Null_Columns
4138            (   p_eam_direct_items_rec        => l_eam_direct_items_rec
4139            ,   p_old_eam_direct_items_Rec    => l_old_eam_direct_items_rec
4140            ,   x_eam_direct_items_rec     => l_out_eam_direct_items_rec
4141            ) ;
4142 
4143            l_eam_direct_items_rec := l_out_eam_direct_items_rec;
4144 
4145 
4146 		    IF ( p_operation_seq_num IS NOT NULL
4147 	              and l_eam_direct_items_rec.operation_seq_num = 1 ) THEN
4148 
4149                  l_out_eam_direct_items_rec := l_eam_direct_items_rec;
4150 
4151                  EAM_DIRECT_ITEMS_DEFAULT_PVT.Change_OpSeqNum1
4152                  (    p_eam_direct_items_rec    => l_eam_direct_items_rec
4153                     , p_operation_seq_num  =>  p_operation_seq_num
4154                     , p_department_id => p_department_id
4155                     , x_eam_direct_items_rec =>  l_out_eam_direct_items_rec
4156                  ) ;
4157 
4158                  l_eam_direct_items_rec := l_out_eam_direct_items_rec;
4159             END IF;
4160 
4161         ELSIF l_eam_direct_items_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
4162         THEN
4163 
4164   	   x_material_shortage := G_MATERIAL_UPDATE;
4165            l_out_eam_direct_items_rec := l_eam_direct_items_rec;
4166 
4167            EAM_DIRECT_ITEMS_DEFAULT_PVT.Attribute_Defaulting
4168            (   p_eam_direct_items_rec   => l_eam_direct_items_rec
4169            ,   x_eam_direct_items_rec   => l_out_eam_direct_items_rec
4170            ,   x_mesg_token_tbl    => l_mesg_token_tbl
4171            ,   x_return_status     => l_return_status
4172            ) ;
4173 
4174            l_eam_direct_items_rec := l_out_eam_direct_items_rec;
4175 
4176            IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug
4177            ('Attribute Defaulting completed with return_status: ' || l_return_status) ;
4178            END IF ;
4179 
4180 
4181            IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
4182            THEN
4183               l_other_message := 'EAM_DI_ATTDEF_CSEV_SKIP';
4184               l_other_token_tbl(1).token_name  := 'DI_SEQ_ID';
4185               l_other_token_tbl(1).token_value := l_eam_direct_items_rec.direct_item_sequence_id ;
4186               RAISE EXC_SEV_SKIP_BRANCH ;
4187 
4188            ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
4189            THEN
4190               l_other_message := 'EAM_DI_ATTDEF_UNEXP_SKIP';
4191               l_other_token_tbl(1).token_name := 'DI_SEQ_ID';
4192               l_other_token_tbl(1).token_value := l_eam_direct_items_rec.direct_item_sequence_id ;
4193               RAISE EXC_UNEXP_SKIP_OBJECT ;
4194            ELSIF l_return_status ='S' AND l_mesg_token_tbl .COUNT <> 0
4195            THEN
4196               l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
4197               EAM_ERROR_MESSAGE_PVT.Log_Error
4198                (  p_eam_direct_items_tbl        => l_eam_direct_items_tbl
4199                ,  p_mesg_token_tbl         => l_mesg_token_tbl
4200                ,  p_error_status           => 'W'
4201                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_DIRECT_ITEMS_LEVEL
4202                ,  p_entity_index           => I
4203                ,  x_eam_wo_rec             => l_eam_wo_rec
4204                ,  x_eam_op_tbl             => l_eam_op_tbl
4205                ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
4206                ,  x_eam_res_tbl            => l_eam_res_tbl
4207                ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
4208                ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
4209                ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
4210                ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
4211                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
4212                );
4213               l_eam_direct_items_tbl       := l_out_eam_direct_items_tbl;
4214           END IF;
4215        END IF;
4216 
4217 
4218          EAM_DIRECT_ITEMS_VALIDATE_PVT.Check_Required
4219          ( p_eam_direct_items_rec                => l_eam_direct_items_rec
4220          , x_return_status              => l_return_status
4221          , x_mesg_token_tbl             => l_mesg_token_tbl
4222          ) ;
4223 
4224 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check required completed with return_status: ' || l_return_status) ; END IF ;
4225 
4226 
4227          IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
4228          THEN
4229             IF l_eam_direct_items_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
4230             THEN
4231                l_other_message := 'EAM_DI_REQ_CSEV_SKIP';
4232                l_other_token_tbl(1).token_name  := 'DI_SEQ_ID';
4233                l_other_token_tbl(1).token_value := l_eam_direct_items_rec.direct_item_sequence_id ;
4234                RAISE EXC_SEV_SKIP_BRANCH ;
4235             ELSE
4236                RAISE EXC_SEV_QUIT_RECORD ;
4237             END IF;
4238          ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
4239          THEN
4240             l_other_message := 'EAM_DI_REQ_UNEXP_SKIP';
4241             l_other_token_tbl(1).token_name  := 'DI_SEQ_ID';
4242             l_other_token_tbl(1).token_value := l_eam_direct_items_rec.direct_item_sequence_id ;
4243             RAISE EXC_UNEXP_SKIP_OBJECT ;
4244          END IF;
4245 
4246 
4247             EAM_DIRECT_ITEMS_VALIDATE_PVT.Check_Attributes
4248             ( p_eam_direct_items_rec        => l_eam_direct_items_rec
4249             , p_old_eam_direct_items_rec    => l_old_eam_direct_items_rec
4250             , x_return_status     => l_return_status
4251             , x_mesg_token_tbl    => l_mesg_token_tbl
4252             ) ;
4253 
4254 	IF l_old_eam_direct_items_rec.REQUIRED_QUANTITY <> l_eam_direct_items_rec.REQUIRED_QUANTITY THEN
4255 		x_material_shortage := G_MATERIAL_UPDATE;
4256 	END IF;
4257 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Attribute validation completed with return_status: ' || l_return_status) ; END IF ;
4258 
4259             IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
4260             THEN
4261                IF l_eam_direct_items_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
4262                THEN
4263                   l_other_message := 'EAM_DI_ATTVAL_CSEV_SKIP';
4264                   l_other_token_tbl(1).token_name := 'DI_SEQ_ID';
4265                   l_other_token_tbl(1).token_value := l_eam_direct_items_rec.direct_item_sequence_id ;
4266                   RAISE EXC_SEV_SKIP_BRANCH ;
4267                   ELSE
4268                      RAISE EXC_SEV_QUIT_RECORD ;
4269                END IF;
4270             ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
4271             THEN
4272                l_other_message := 'EAM_DI_ATTVAL_UNEXP_SKIP';
4273                l_other_token_tbl(1).token_name := 'DI_SEQ_ID';
4274                l_other_token_tbl(1).token_value := l_eam_direct_items_rec.direct_item_sequence_id ;
4275                RAISE EXC_UNEXP_SKIP_OBJECT ;
4276             ELSIF l_return_status ='S' AND l_mesg_token_tbl .COUNT <> 0
4277             THEN
4278               l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
4279               EAM_ERROR_MESSAGE_PVT.Log_Error
4280                ( p_eam_direct_items_tbl        => l_eam_direct_items_tbl
4281                ,  p_mesg_token_tbl         => l_mesg_token_tbl
4282                ,  p_error_status           => 'W'
4283                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_DIRECT_ITEMS_LEVEL
4284                ,  p_entity_index           => I
4285                ,  x_eam_wo_rec             => l_eam_wo_rec
4286                ,  x_eam_op_tbl             => l_eam_op_tbl
4287                ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
4288                ,  x_eam_res_tbl            => l_eam_res_tbl
4289                ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
4290                ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
4291                ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
4292                ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
4293                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
4294                );
4295               l_eam_direct_items_tbl       := l_out_eam_direct_items_tbl;
4296 
4297            END IF;
4298 
4299 
4300 
4301           EAM_DIRECT_ITEMS_UTILITY_PVT.Perform_Writes
4302           (   p_eam_direct_items_rec          => l_eam_direct_items_rec
4303           ,   x_mesg_token_tbl      => l_mesg_token_tbl
4304           ,   x_return_status       => l_return_status
4305           ) ;
4306 
4307 
4308        IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
4309        THEN
4310           l_other_message := 'EAM_DI_WRITES_UNEXP_SKIP';
4311           l_other_token_tbl(1).token_name := 'DI_SEQ_ID';
4312           l_other_token_tbl(1).token_value :=
4313                           l_eam_direct_items_rec.direct_item_sequence_id ;
4314           RAISE EXC_UNEXP_SKIP_OBJECT ;
4315        ELSIF l_return_status ='S' AND
4316           l_mesg_token_tbl.COUNT <>0
4317        THEN
4318             l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
4319             EAM_ERROR_MESSAGE_PVT.Log_Error
4320                ( p_eam_direct_items_tbl        => l_eam_direct_items_tbl
4321                ,  p_mesg_token_tbl         => l_mesg_token_tbl
4322                ,  p_error_status           => 'W'
4323                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_DIRECT_ITEMS_LEVEL
4324                ,  p_entity_index           => I
4325                ,  x_eam_wo_rec             => l_eam_wo_rec
4326                ,  x_eam_op_tbl             => l_eam_op_tbl
4327                ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
4328                ,  x_eam_res_tbl            => l_eam_res_tbl
4329                ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
4330                ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
4331                ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
4332                ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
4333                ,  x_eam_direct_items_tbl        => l_out_eam_direct_items_tbl
4334                );
4335               l_eam_direct_items_tbl       := l_out_eam_direct_items_tbl;
4336        END IF;
4337 
4338 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Direct Items Database writes completed with status  ' || l_return_status); END IF;
4339 
4340 
4341 
4342 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('create requisitions for description direct items'); END IF;
4343 
4344 --fix for 3550864.create requisitions for  requested_quantity if passed
4345      IF(l_eam_direct_items_rec.requested_quantity IS NOT NULL) THEN
4346 
4347    IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('create requisitions for description direct items'); END IF;
4348 
4349        EAM_PROCESS_WO_UTIL_PVT.create_requisition
4350                   (  p_api_version                 => 1.0
4351                     ,p_init_msg_list               => FND_API.G_FALSE
4352                     ,p_commit                      => FND_API.G_FALSE
4353                     ,p_validate_only               => FND_API.G_TRUE
4354                     ,x_return_status               => l_api_return_status
4355                     ,x_msg_count                   => l_api_msg_count
4356                     ,x_msg_data                    => l_api_msg_data
4357                     ,p_wip_entity_id               => l_eam_direct_items_rec.wip_entity_id
4358                     ,p_operation_seq_num           => l_eam_direct_items_rec.operation_seq_num
4359                     ,p_organization_id             => l_eam_direct_items_rec.organization_id
4360                     ,p_user_id                     => fnd_global.user_id
4361                     ,p_responsibility_id           => fnd_global.resp_id
4362                     ,p_quantity                    => l_eam_direct_items_rec.requested_quantity
4363                     ,p_unit_price                  => l_eam_direct_items_rec.unit_price
4364                     ,p_category_id                 => l_eam_direct_items_rec.purchasing_category_id
4365                     ,p_item_description            => l_eam_direct_items_rec.description
4366                     ,p_uom_code                    => l_eam_direct_items_rec.uom
4367                     ,p_need_by_date                => l_eam_direct_items_rec.need_by_date
4368                     ,p_inventory_item_id           => null
4369                     ,p_direct_item_id              => l_eam_direct_items_rec.direct_item_sequence_id
4370 		    , p_suggested_vendor_id        => l_eam_direct_items_rec.suggested_vendor_id
4371                     ,p_suggested_vendor_name       => l_eam_direct_items_rec.suggested_vendor_name
4372                     ,p_suggested_vendor_site       => l_eam_direct_items_rec.suggested_vendor_site
4373                     ,p_suggested_vendor_phone      => l_eam_direct_items_rec.suggested_vendor_phone
4374                     ,p_suggested_vendor_item_num   => l_eam_direct_items_rec.suggested_vendor_item_num);
4375 
4376      ELSE
4377 
4378        -- create requisitions if the quantity has changed and wo is in released status
4379        select status_type into l_wo_status from
4380          wip_discrete_jobs
4381          where wip_entity_id = l_eam_direct_items_rec.wip_entity_id
4382          and organization_id = l_eam_direct_items_rec.organization_id;
4383        if l_wo_status = 3
4384          and l_eam_direct_items_rec.auto_request_material = 'Y'
4385          and (l_eam_direct_items_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
4386               OR (l_eam_direct_items_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UPDATE
4387                   /*and l_old_eam_direct_items_rec.required_quantity < l_eam_direct_items_rec.required_quantity commented for # 6118897*/)
4388               OR (l_eam_direct_items_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UPDATE
4389                   and nvl(l_old_eam_direct_items_rec.auto_request_material,'N')='N'
4390                   and nvl(l_eam_direct_items_rec.auto_request_material,'N')='Y')
4391        ) then
4392 
4393 -- query modified for bug# 3691325.
4394 
4395      /*Added Union for #6118897 to avoid duplicate req creation -- start --*/
4396        SELECT SUM(nvl(req_qty,0)) INTO l_total_req_qty
4397 	FROM
4398 	(SELECT SUM(nvl(quantity,0)) req_qty
4399 	FROM po_requisitions_interface_all pria
4400 	WHERE  pria.wip_entity_id = l_eam_direct_items_rec.wip_entity_id
4401 	AND pria.destination_organization_id = l_eam_direct_items_rec.organization_id
4402 	AND pria.wip_operation_seq_num = l_eam_direct_items_rec.operation_seq_num
4403 	AND pria.item_id is null
4404 	AND pria.wip_resource_seq_num = l_eam_direct_items_rec.direct_item_sequence_id
4405         AND ((process_flag is null) or (Upper(Trim(process_flag)) = 'IN PROCESS'))
4406 	UNION ALL
4407 	select greatest(nvl(po_quantity_ordered-po_quantity_cancelled,0), nvl(rql_quantity_ordered,0), nvl(quantity_received,0)) req_qty
4408 	from    eam_work_order_direct_items_v ewodi
4409 	where   ewodi.wip_entity_id = l_eam_direct_items_rec.wip_entity_id
4410 	and     ewodi.organization_id = l_eam_direct_items_rec.organization_id
4411 	and     ewodi.operation_seq_num = l_eam_direct_items_rec.operation_seq_num
4412 	and     ewodi.direct_item_sequence_id = l_eam_direct_items_rec.direct_item_sequence_id
4413         );
4414       /*Added union, 6118897-- end---*/
4415 
4416              EAM_PROCESS_WO_UTIL_PVT.create_requisition
4417                (  p_api_version                 => 1.0
4418                  ,p_init_msg_list               => FND_API.G_FALSE
4419                  ,p_commit                      => FND_API.G_FALSE
4420                  ,p_validate_only               => FND_API.G_TRUE
4421                  ,x_return_status               => l_api_return_status
4422                  ,x_msg_count                   => l_api_msg_count
4423                  ,x_msg_data                    => l_api_msg_data
4424                  ,p_wip_entity_id               => l_eam_direct_items_rec.wip_entity_id
4425                  ,p_operation_seq_num           => l_eam_direct_items_rec.operation_seq_num
4426                  ,p_organization_id             => l_eam_direct_items_rec.organization_id
4427                  ,p_user_id                     => fnd_global.user_id
4428                  ,p_responsibility_id           => fnd_global.resp_id
4429                  ,p_quantity                    => (l_eam_direct_items_rec.required_quantity
4430                                                    -nvl(l_total_req_qty,0))
4431                  ,p_unit_price                  => l_eam_direct_items_rec.unit_price
4432                  ,p_category_id                 => l_eam_direct_items_rec.purchasing_category_id
4433                  ,p_item_description            => l_eam_direct_items_rec.description
4434                  ,p_uom_code                    => l_eam_direct_items_rec.uom
4435                  ,p_need_by_date                => l_eam_direct_items_rec.need_by_date
4436                  ,p_inventory_item_id           => null
4437                  ,p_direct_item_id              => l_eam_direct_items_rec.direct_item_sequence_id
4438 		 , p_suggested_vendor_id        => l_eam_direct_items_rec.suggested_vendor_id
4439                  ,p_suggested_vendor_name       => l_eam_direct_items_rec.suggested_vendor_name
4440                  ,p_suggested_vendor_site       => l_eam_direct_items_rec.suggested_vendor_site
4441                  ,p_suggested_vendor_phone      => l_eam_direct_items_rec.suggested_vendor_phone
4442                  ,p_suggested_vendor_item_num   => l_eam_direct_items_rec.suggested_vendor_item_num);
4443 
4444        end if;
4445     END IF;  --end of check for requested_quantity
4446 
4447     ELSE
4448 
4449 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Skipping '|| I || ' record') ; END IF ;
4450 
4451     END IF; -- END IF statement that checks RETURN STATUS
4452 
4453     --  Load tables.
4454     l_eam_direct_items_tbl(I)          := l_eam_direct_items_rec;
4455 
4456 
4457     -- Indicate that children need to be processed
4458     l_process_children := TRUE;
4459 
4460     --  For loop exception handler.
4461 
4462     EXCEPTION
4463        WHEN EXC_SEV_QUIT_RECORD THEN
4464         l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
4465         EAM_ERROR_MESSAGE_PVT.Log_Error
4466         (  p_eam_direct_items_tbl        => l_eam_direct_items_tbl
4467         ,  p_mesg_token_tbl         => l_mesg_token_tbl
4468         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
4469         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
4470         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_DIRECT_ITEMS_LEVEL
4471         ,  p_entity_index           => I
4472         ,  x_eam_wo_rec             => l_eam_wo_rec
4473         ,  x_eam_op_tbl             => l_eam_op_tbl
4474         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
4475         ,  x_eam_res_tbl            => l_eam_res_tbl
4476         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
4477         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
4478         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
4479         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
4480         ,  x_eam_direct_items_tbl        => l_out_eam_direct_items_tbl
4481         );
4482         l_eam_direct_items_tbl       := l_out_eam_direct_items_tbl;
4483 
4484          l_process_children             := FALSE;
4485          IF l_bo_return_status = 'S'
4486          THEN
4487              l_bo_return_status  := l_return_status ;
4488          END IF;
4489          x_return_status                := l_bo_return_status;
4490          x_mesg_token_tbl               := l_mesg_token_tbl ;
4491          x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
4492 
4493 
4494       WHEN EXC_SEV_QUIT_BRANCH THEN
4495        l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
4496        EAM_ERROR_MESSAGE_PVT.Log_Error
4497         (  p_eam_direct_items_tbl        => l_eam_direct_items_tbl
4498         ,  p_mesg_token_tbl         => l_mesg_token_tbl
4499         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
4500         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
4501         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
4502         ,  p_other_message          => l_other_message
4503         ,  p_other_token_tbl        => l_other_token_tbl
4504         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_DIRECT_ITEMS_LEVEL
4505         ,  p_entity_index           => I
4506         ,  x_eam_wo_rec             => l_eam_wo_rec
4507         ,  x_eam_op_tbl             => l_eam_op_tbl
4508         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
4509         ,  x_eam_res_tbl            => l_eam_res_tbl
4510         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
4511         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
4512         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
4513         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
4514         ,  x_eam_direct_items_tbl        => l_out_eam_direct_items_tbl
4515         );
4516        l_eam_direct_items_tbl       := l_out_eam_direct_items_tbl;
4517 
4518 
4519          l_process_children             := FALSE ;
4520          IF l_bo_return_status = 'S'
4521          THEN
4522              l_bo_return_status  := l_return_status ;
4523          END IF;
4524          x_return_status                := l_bo_return_status;
4525          x_mesg_token_tbl               := l_mesg_token_tbl ;
4526          x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
4527 
4528 
4529       WHEN EXC_SEV_SKIP_BRANCH THEN
4530        l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
4531        EAM_ERROR_MESSAGE_PVT.Log_Error
4532         (  p_eam_direct_items_tbl        => l_eam_direct_items_tbl
4533         ,  p_mesg_token_tbl         => l_mesg_token_tbl
4534         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
4535         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
4536         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_NOT_PICKED
4537         ,  p_other_message          => l_other_message
4538         ,  p_other_token_tbl        => l_other_token_tbl
4539         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_DIRECT_ITEMS_LEVEL
4540         ,  p_entity_index           => I
4541         ,  x_eam_wo_rec             => l_eam_wo_rec
4542         ,  x_eam_op_tbl             => l_eam_op_tbl
4543         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
4544         ,  x_eam_res_tbl            => l_eam_res_tbl
4545         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
4546         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
4547         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
4548         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
4549         ,  x_eam_direct_items_tbl        => l_out_eam_direct_items_tbl
4550         );
4551        l_eam_direct_items_tbl       := l_out_eam_direct_items_tbl;
4552 
4553          l_process_children             := FALSE ;
4554          IF l_bo_return_status = 'S'
4555          THEN
4556              l_bo_return_status  := l_return_status ;
4557          END IF;
4558          x_return_status                := l_bo_return_status;
4559          x_mesg_token_tbl               := l_mesg_token_tbl ;
4560          x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
4561 
4562 
4563       WHEN EXC_SEV_QUIT_SIBLINGS THEN
4564        l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
4565        EAM_ERROR_MESSAGE_PVT.Log_Error
4566         (  p_eam_direct_items_tbl        => l_eam_direct_items_tbl
4567         ,  p_mesg_token_tbl         => l_mesg_token_tbl
4568         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
4569         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_SIBLINGS
4570         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
4571         ,  p_other_message          => l_other_message
4572         ,  p_other_token_tbl        => l_other_token_tbl
4573         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_DIRECT_ITEMS_LEVEL
4574         ,  p_entity_index           => I
4575         ,  x_eam_wo_rec             => l_eam_wo_rec
4576         ,  x_eam_op_tbl             => l_eam_op_tbl
4577         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
4578         ,  x_eam_res_tbl            => l_eam_res_tbl
4579         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
4580         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
4581         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
4582         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
4583         ,  x_eam_direct_items_tbl        => l_out_eam_direct_items_tbl
4584         );
4585        l_eam_direct_items_tbl       := l_out_eam_direct_items_tbl;
4586 
4587          l_process_children             := FALSE ;
4588          IF l_bo_return_status = 'S'
4589          THEN
4590              l_bo_return_status  := l_return_status ;
4591          END IF;
4592          x_return_status                := l_bo_return_status;
4593          x_mesg_token_tbl               := l_mesg_token_tbl ;
4594          x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
4595 
4596 
4597       WHEN EXC_FAT_QUIT_BRANCH THEN
4598        l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
4599        EAM_ERROR_MESSAGE_PVT.Log_Error
4600         (  p_eam_direct_items_tbl        => l_eam_direct_items_tbl
4601         ,  p_mesg_token_tbl         => l_mesg_token_tbl
4602         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
4603         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
4604         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
4605         ,  p_other_message          => l_other_message
4606         ,  p_other_token_tbl        => l_other_token_tbl
4607         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_DIRECT_ITEMS_LEVEL
4608         ,  p_entity_index           => I
4609         ,  x_eam_wo_rec             => l_eam_wo_rec
4610         ,  x_eam_op_tbl             => l_eam_op_tbl
4611         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
4612         ,  x_eam_res_tbl            => l_eam_res_tbl
4613         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
4614         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
4615         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
4616         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
4617         ,  x_eam_direct_items_tbl        => l_out_eam_direct_items_tbl
4618         );
4619        l_eam_direct_items_tbl       := l_out_eam_direct_items_tbl;
4620 
4621          l_process_children             := FALSE ;
4622          x_return_status                := EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL;
4623          x_mesg_token_tbl               := l_mesg_token_tbl ;
4624          x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
4625 
4626 
4627       WHEN EXC_FAT_QUIT_SIBLINGS THEN
4628        l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
4629        EAM_ERROR_MESSAGE_PVT.Log_Error
4630         (  p_eam_direct_items_tbl        => l_eam_direct_items_tbl
4631         ,  p_mesg_token_tbl         => l_mesg_token_tbl
4632         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
4633         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_SIBLINGS
4634         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
4635         ,  p_other_message          => l_other_message
4636         ,  p_other_token_tbl        => l_other_token_tbl
4637         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_DIRECT_ITEMS_LEVEL
4638         ,  p_entity_index           => I
4639         ,  x_eam_wo_rec             => l_eam_wo_rec
4640         ,  x_eam_op_tbl             => l_eam_op_tbl
4641         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
4642         ,  x_eam_res_tbl            => l_eam_res_tbl
4643         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
4644         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
4645         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
4646         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
4647         ,  x_eam_direct_items_tbl        => l_out_eam_direct_items_tbl
4648         );
4649        l_eam_direct_items_tbl       := l_out_eam_direct_items_tbl;
4650 
4651 
4652          l_process_children             := FALSE ;
4653          x_return_status                := EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL;
4654          x_mesg_token_tbl               := l_mesg_token_tbl ;
4655          x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
4656 
4657       WHEN EXC_UNEXP_SKIP_OBJECT THEN
4658        l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
4659        EAM_ERROR_MESSAGE_PVT.Log_Error
4660         (  p_eam_direct_items_tbl        => l_eam_direct_items_tbl
4661         ,  p_mesg_token_tbl         => l_mesg_token_tbl
4662         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
4663         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_NOT_PICKED
4664         ,  p_other_message          => l_other_message
4665         ,  p_other_token_tbl        => l_other_token_tbl
4666         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_DIRECT_ITEMS_LEVEL
4667         ,  x_eam_wo_rec             => l_eam_wo_rec
4668         ,  x_eam_op_tbl             => l_eam_op_tbl
4669         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
4670         ,  x_eam_res_tbl            => l_eam_res_tbl
4671         ,  x_eam_res_inst_tbl       => l_eam_res_inst_tbl
4672         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
4673         ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
4674         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
4675         ,  x_eam_direct_items_tbl        => l_out_eam_direct_items_tbl
4676         );
4677        l_eam_direct_items_tbl       := l_out_eam_direct_items_tbl;
4678 
4679 
4680          l_return_status                := 'U';
4681          x_mesg_token_tbl               := l_mesg_token_tbl ;
4682          x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
4683 
4684    END ; -- END block
4685 
4686    IF l_return_status in ('Q', 'U')
4687    THEN
4688       x_return_status := l_return_status;
4689       RETURN ;
4690    END IF;
4691 
4692 
4693    END LOOP; -- END Material Requirements processing loop
4694 
4695 
4696    --  Load OUT parameters
4697    IF NVL(l_return_status, 'S') <> 'S'
4698    THEN
4699    x_return_status     := l_return_status;
4700    END IF;
4701 
4702    x_Mesg_Token_Tbl               := l_Mesg_Token_Tbl;
4703    x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
4704 
4705 END DIRECT_ITEMS;
4706 
4707 
4708 
4709 
4710 
4711 
4712 
4713 
4714 
4715 
4716 
4717 
4718 
4719 
4720 
4721 
4722 
4723 
4724 
4725 
4726 PROCEDURE OPERATION_RESOURCES
4727         (  p_validation_level        IN  NUMBER
4728         ,  p_wip_entity_id           IN  NUMBER := NULL
4729         ,  p_organization_id         IN  NUMBER := NULL
4730         ,  p_operation_seq_num       IN  NUMBER := NULL
4731         ,  p_eam_res_tbl             IN EAM_PROCESS_WO_PUB.eam_res_tbl_type
4732         ,  p_eam_res_inst_tbl        IN EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
4733         ,  p_eam_res_usage_tbl       IN EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
4734         ,  x_eam_res_tbl             OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_tbl_type
4735         ,  x_eam_res_inst_tbl        OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
4736         ,  x_eam_res_usage_tbl       OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
4737 	,  x_schedule_wo              IN OUT NOCOPY NUMBER
4738 	,  x_bottomup_scheduled       IN OUT NOCOPY NUMBER
4739         ,  x_mesg_token_tbl          OUT NOCOPY EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type
4740         ,  x_return_status           OUT NOCOPY VARCHAR2
4741         )
4742 IS
4743 
4744 l_eam_res_rec            EAM_PROCESS_WO_PUB.eam_res_rec_type ;
4745 l_eam_res_tbl            EAM_PROCESS_WO_PUB.eam_res_tbl_type ;
4746 l_old_eam_res_rec        EAM_PROCESS_WO_PUB.eam_res_rec_type ;
4747 
4748 l_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type ;
4749 l_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type ;
4750 l_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type   :=p_eam_res_inst_tbl;
4751 l_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
4752 l_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type := p_eam_res_usage_tbl;
4753 l_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type ;
4754 l_eam_direct_items_tbl  EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type ;
4755 l_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type ;
4756 
4757         -- baroy - added for making the NOCOPY changes
4758         l_out_eam_res_rec                EAM_PROCESS_WO_PUB.eam_res_rec_type;
4759         l_out_eam_res_tbl                EAM_PROCESS_WO_PUB.eam_res_tbl_type;
4760         l_out_eam_res_inst_tbl           EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
4761         l_out_eam_res_usage_tbl          EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
4762 
4763 /* Error Handling Variables */
4764 l_token_tbl             EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
4765 l_mesg_token_tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
4766 l_other_token_tbl       EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
4767 l_other_message         VARCHAR2(2000);
4768 l_err_text              VARCHAR2(2000);
4769 
4770 /* Others */
4771 l_return_status         VARCHAR2(1) ;
4772 l_bo_return_status      VARCHAR2(1) ;
4773 l_parent_exists         BOOLEAN := FALSE ;
4774 l_process_children      BOOLEAN := TRUE ;
4775 l_valid_transaction     BOOLEAN := TRUE ;
4776 
4777 
4778 BEGIN
4779 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(p_eam_res_tbl.COUNT ||' records passed') ; END IF ;
4780 
4781    x_return_status := FND_API.G_RET_STS_SUCCESS;
4782 
4783 --  Init local table variables.
4784    l_return_status    := 'S' ;
4785    l_bo_return_status := 'S' ;
4786    l_eam_res_tbl    := p_eam_res_tbl ;
4787 
4788 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Starting OPERATION_RESOURCES') ; END IF ;
4789 
4790    FOR I IN 1..l_eam_res_tbl.COUNT LOOP
4791    BEGIN
4792 
4793 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Processing '|| I || ' record') ; END IF ;
4794 
4795       --  Load local records.
4796       l_eam_res_rec := l_eam_res_tbl(I);
4797 
4798       -- make sure to set process_children to false at the start of every iteration
4799       l_process_children := FALSE;
4800 
4801 
4802       IF l_eam_res_rec.wip_entity_id is NULL
4803          AND (l_eam_res_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
4804              OR l_eam_res_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_SYNC)
4805       THEN
4806           l_eam_res_rec.wip_entity_id := p_wip_entity_id;
4807       END IF;
4808 
4809       IF p_wip_entity_id IS NOT NULL AND
4810          p_organization_id IS NOT NULL AND
4811          p_operation_seq_num IS NOT NULL
4812       THEN
4813 	l_parent_exists := TRUE;
4814       END IF;
4815 
4816       IF (l_eam_res_rec.return_status IS NULL OR l_eam_res_rec.return_status = FND_API.G_MISS_CHAR)
4817            AND
4818            (NOT l_parent_exists
4819             OR
4820              (l_parent_exists AND
4821               l_eam_res_rec.wip_entity_id = p_wip_entity_id AND
4822               l_eam_res_rec.organization_id = p_organization_id AND
4823               l_eam_res_rec.operation_seq_num = p_operation_seq_num
4824              )
4825            )
4826       THEN
4827 
4828 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Return status validation passed') ; END IF ;
4829 
4830          l_return_status := FND_API.G_RET_STS_SUCCESS;
4831          l_eam_res_rec.return_status := FND_API.G_RET_STS_SUCCESS;
4832 
4833         VALIDATE_TRANSACTION_TYPE
4834         (   p_transaction_type  => l_eam_res_rec.transaction_type
4835         ,   p_entity_name       => 'OPERATION_RESOURCE'
4836         ,   p_entity_id         => to_char(l_eam_res_rec.resource_seq_num)
4837         ,   X_valid_transaction => l_valid_transaction
4838         ,   x_mesg_token_tbl    => l_mesg_token_tbl
4839         );
4840 
4841          IF NOT l_valid_transaction
4842          THEN
4843              l_return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
4844              RAISE EXC_SEV_QUIT_RECORD ;
4845          END IF ;
4846 
4847         EAM_RES_VALIDATE_PVT.Check_Existence
4848          (  p_eam_res_rec            => l_eam_res_rec
4849          ,  x_old_eam_res_rec        => l_old_eam_res_rec
4850          ,  x_mesg_token_tbl         => l_mesg_token_tbl
4851          ,  x_return_status          => l_return_status
4852          ) ;
4853 
4854 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check Existence completed with return_status: ' || l_return_status) ;  END IF ;
4855 
4856          IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
4857          THEN
4858             l_other_message := 'EAM_RES_EXS_SEV_SKIP';
4859             l_other_token_tbl(1).token_name  := 'RES_SEQ_NUMBER';
4860             l_other_token_tbl(1).token_value := l_eam_res_rec.resource_seq_num;
4861             l_other_token_tbl(2).token_name  := 'WIP_ENTITY_ID';
4862             l_other_token_tbl(2).token_value := l_eam_res_rec.wip_entity_id;
4863             RAISE EXC_SEV_QUIT_BRANCH;
4864          ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
4865          THEN
4866             l_other_message := 'EAM_RES_EXS_UNEXP_SKIP';
4867             l_other_token_tbl(1).token_name  := 'RES_SEQ_NUMBER';
4868             l_other_token_tbl(1).token_value := l_eam_res_rec.resource_seq_num ;
4869             l_other_token_tbl(2).token_name  := 'WIP_ENTITY_ID';
4870             l_other_token_tbl(2).token_value := l_eam_res_rec.wip_entity_id ;
4871             RAISE EXC_UNEXP_SKIP_OBJECT;
4872          END IF;
4873 
4874         /* Assign the correct transaction type for SYNC operations */
4875 
4876         IF l_eam_res_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_SYNC THEN
4877            l_eam_res_rec.transaction_type := l_old_eam_res_rec.transaction_type;
4878         END IF;
4879 
4880 
4881         IF l_eam_res_rec.transaction_type IN (EAM_PROCESS_WO_PVT.G_OPR_UPDATE, EAM_PROCESS_WO_PVT.G_OPR_DELETE)
4882         THEN
4883 
4884            IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Populate NULL columns') ;
4885            END IF ;
4886 
4887            l_out_eam_res_rec           := l_eam_res_rec;
4888            EAM_RES_DEFAULT_PVT.Populate_Null_Columns
4889            (   p_eam_res_rec        => l_eam_res_rec
4890            ,   p_old_eam_res_Rec    => l_old_eam_res_rec
4891            ,   x_eam_res_rec     => l_out_eam_res_rec
4892            ) ;
4893            l_eam_res_rec           := l_out_eam_res_rec;
4894 
4895         END IF;
4896 
4897 
4898            l_out_eam_res_rec           := l_eam_res_rec;
4899            EAM_RES_DEFAULT_PVT.Attribute_Defaulting
4900            (   p_eam_res_rec   => l_eam_res_rec
4901            ,   x_eam_res_rec   => l_out_eam_res_rec
4902            ,   x_mesg_token_tbl  => l_mesg_token_tbl
4903            ,   x_return_status   => l_return_status
4904            ) ;
4905            l_eam_res_rec           := l_out_eam_res_rec;
4906 
4907            IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug
4908            ('Attribute Defaulting completed with return_status: ' || l_return_status) ;
4909            END IF ;
4910 
4911 
4912            IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
4913            THEN
4914               l_other_message := 'EAM_RES_ATTDEF_CSEV_SKIP';
4915               l_other_token_tbl(1).token_name := 'RES_SEQ_NUMBER';
4916               l_other_token_tbl(1).token_value :=
4917                           l_eam_res_rec.resource_seq_num ;
4918               RAISE EXC_SEV_SKIP_BRANCH ;
4919 
4920            ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
4921            THEN
4922               l_other_message := 'EAM_RES_ATTDEF_UNEXP_SKIP';
4923               l_other_token_tbl(1).token_name := 'RES_SEQ_NUMBER';
4924               l_other_token_tbl(1).token_value := l_eam_res_rec.resource_seq_num ;
4925               RAISE EXC_UNEXP_SKIP_OBJECT ;
4926            ELSIF l_return_status ='S' AND l_mesg_token_tbl .COUNT <> 0
4927            THEN
4928               l_out_eam_res_tbl           := l_eam_res_tbl;
4929               l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
4930               l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
4931               EAM_ERROR_MESSAGE_PVT.Log_Error
4932                (  p_eam_res_tbl            => l_eam_res_tbl
4933                ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
4934                ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
4935                ,  p_mesg_token_tbl         => l_mesg_token_tbl
4936                ,  p_error_status           => 'W'
4937                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_LEVEL
4938                ,  p_entity_index           => I
4939                ,  x_eam_wo_rec             => l_eam_wo_rec
4940                ,  x_eam_op_tbl             => l_eam_op_tbl
4941                ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
4942                ,  x_eam_res_tbl            => l_out_eam_res_tbl
4943                ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
4944                ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
4945                ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
4946                ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
4947                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
4948                );
4949               l_eam_res_tbl           := l_out_eam_res_tbl;
4950               l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
4951               l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
4952           END IF;
4953 
4954 
4955          EAM_RES_VALIDATE_PVT.Check_Required
4956          ( p_eam_res_rec                => l_eam_res_rec
4957          , x_return_status              => l_return_status
4958          , x_mesg_token_tbl             => l_mesg_token_tbl
4959          ) ;
4960 
4961 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check required completed with return_status: ' || l_return_status) ; END IF ;
4962 
4963 
4964          IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
4965          THEN
4966             IF l_eam_res_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
4967             THEN
4968                l_other_message := 'EAM_RES_REQ_CSEV_SKIP';
4969                l_other_token_tbl(1).token_name  := 'RES_SEQ_NUMBER';
4970                l_other_token_tbl(1).token_value := l_eam_res_rec.resource_seq_num ;
4971                RAISE EXC_SEV_SKIP_BRANCH ;
4972             ELSE
4973                RAISE EXC_SEV_QUIT_RECORD ;
4974             END IF;
4975          ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
4976          THEN
4977             l_other_message := 'EAM_RES_REQ_UNEXP_SKIP';
4978             l_other_token_tbl(1).token_name  := 'RES_SEQ_NUMBER';
4979             l_other_token_tbl(1).token_value := l_eam_res_rec.resource_seq_num ;
4980             RAISE EXC_UNEXP_SKIP_OBJECT ;
4981          END IF;
4982 
4983             EAM_RES_VALIDATE_PVT.Check_Attributes
4984             ( p_eam_res_rec        => l_eam_res_rec
4985             , p_old_eam_res_rec    => l_old_eam_res_rec
4986             , x_return_status     => l_return_status
4987             , x_mesg_token_tbl    => l_mesg_token_tbl
4988             ) ;
4989 
4990 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Attribute validation completed with return_status: ' || l_return_status) ; END IF ;
4991 
4992             IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
4993             THEN
4994                IF l_eam_res_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
4995                THEN
4996                   l_other_message := 'EAM_RES_ATTVAL_CSEV_SKIP';
4997                   l_other_token_tbl(1).token_name := 'RES_SEQ_NUMBER';
4998                   l_other_token_tbl(1).token_value := l_eam_res_rec.resource_seq_num ;
4999                   RAISE EXC_SEV_SKIP_BRANCH ;
5000                   ELSE
5001                      RAISE EXC_SEV_QUIT_RECORD ;
5002                END IF;
5003             ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
5004             THEN
5005                l_other_message := 'EAM_RES_ATTVAL_UNEXP_SKIP';
5006                l_other_token_tbl(1).token_name := 'RES_SEQ_NUMBER';
5007                l_other_token_tbl(1).token_value := l_eam_res_rec.resource_seq_num ;
5008                RAISE EXC_UNEXP_SKIP_OBJECT ;
5009             ELSIF l_return_status ='S' AND l_mesg_token_tbl .COUNT <> 0
5010             THEN
5011               l_out_eam_res_tbl           := l_eam_res_tbl;
5012               l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
5013               l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
5014               EAM_ERROR_MESSAGE_PVT.Log_Error
5015                (  p_eam_res_tbl            => l_eam_res_tbl
5016                ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
5017                ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
5018                ,  p_mesg_token_tbl         => l_mesg_token_tbl
5019                ,  p_error_status           => 'W'
5020                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_LEVEL
5021                ,  p_entity_index           => I
5022                ,  x_eam_wo_rec             => l_eam_wo_rec
5023                ,  x_eam_op_tbl             => l_eam_op_tbl
5024                ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
5025                ,  x_eam_res_tbl            => l_out_eam_res_tbl
5026                ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
5027                ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
5028                ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
5029                ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
5030                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
5031                );
5032               l_eam_res_tbl           := l_out_eam_res_tbl;
5033               l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
5034               l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
5035 
5036            END IF;
5037 
5038           EAM_RES_UTILITY_PVT.Perform_Writes
5039           (   p_eam_res_rec         => l_eam_res_rec
5040           ,   x_mesg_token_tbl      => l_mesg_token_tbl
5041           ,   x_return_status       => l_return_status
5042           ) ;
5043 
5044 
5045        IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
5046        THEN
5047           l_other_message := 'EAM_RES_WRITES_UNEXP_SKIP';
5048           l_other_token_tbl(1).token_name := 'RES_SEQ_NUMBER';
5049           l_other_token_tbl(1).token_value :=
5050                           l_eam_res_rec.resource_seq_num ;
5051           RAISE EXC_UNEXP_SKIP_OBJECT ;
5052        ELSIF l_return_status ='S' AND
5053           l_mesg_token_tbl.COUNT <>0
5054        THEN
5055             l_out_eam_res_tbl           := l_eam_res_tbl;
5056             l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
5057             l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
5058             EAM_ERROR_MESSAGE_PVT.Log_Error
5059                (  p_eam_res_tbl            => l_eam_res_tbl
5060                ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
5061                ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
5062                ,  p_mesg_token_tbl         => l_mesg_token_tbl
5063                ,  p_error_status           => 'W'
5064                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_LEVEL
5065                ,  p_entity_index           => I
5066                ,  x_eam_wo_rec             => l_eam_wo_rec
5067                ,  x_eam_op_tbl             => l_eam_op_tbl
5068                ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
5069                ,  x_eam_res_tbl            => l_out_eam_res_tbl
5070                ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
5071                ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
5072                ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
5073                ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
5074                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
5075                );
5076             l_eam_res_tbl           := l_out_eam_res_tbl;
5077             l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
5078             l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
5079 
5080        END IF;
5081 
5082 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Resources Database writes completed with status  ' || l_return_status); END IF;
5083 
5084      --find if scheduler is to be called or not
5085          IF(x_schedule_wo = G_NOT_SCHEDULE_WO)THEN    --not yet set to schedule
5086 	     IF(l_eam_res_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE   -- is resource is added
5087 	        OR (l_eam_res_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_DELETE AND l_eam_res_rec.scheduled_flag=1) --deleted and was scheduled
5088 		OR (l_eam_res_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_UPDATE AND  --updating the resource
5089 		       (NVL(l_eam_res_rec.schedule_seq_num,l_eam_res_rec.resource_seq_num)<>NVL(l_old_eam_res_rec.schedule_seq_num,l_old_eam_res_rec.resource_seq_num)
5090 		        OR l_eam_res_rec.start_date <> l_old_eam_res_rec.start_date   --shedule_seq_num,start_date,completion_date
5091 			OR l_eam_res_rec.completion_date <> l_old_eam_res_rec.completion_date
5092 			OR l_eam_res_rec.resource_id <> l_old_eam_res_rec.resource_id    --resource_code,usage_rate_or_amount,scheduled_flag,assigned_units
5093 			OR l_eam_res_rec.usage_rate_or_amount <> l_old_eam_res_rec.usage_rate_or_amount
5094 			OR l_eam_res_rec.scheduled_flag <> l_old_eam_res_rec.scheduled_flag
5095 			OR NVL(l_eam_res_rec.assigned_units,0) <> NVL(l_old_eam_res_rec.assigned_units,0))
5096 		    )
5097 		) THEN
5098 		    x_schedule_wo := G_SCHEDULE_WO;
5099 	     END IF;
5100 	 END IF;
5101 
5102      --find if bottom up scheduler is to be called or not
5103 
5104 
5105 	-- IF(x_bottomup_scheduled = G_NOT_BU_SCHEDULE_WO)THEN    --not yet set to schedule
5106 	     IF(l_eam_res_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE   -- is resource is added
5107 	    --    OR (l_eam_res_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_DELETE AND l_eam_res_rec.scheduled_flag=1) --deleted and was scheduled
5108 		OR (l_eam_res_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_UPDATE AND  --updating the resource
5109 		       (
5110 		       --NVL(l_eam_res_rec.schedule_seq_num,l_eam_res_rec.resource_seq_num)<>NVL(l_old_eam_res_rec.schedule_seq_num,l_old_eam_res_rec.resource_seq_num)
5111 		        -- OR
5112 			l_eam_res_rec.start_date <> l_old_eam_res_rec.start_date   --shedule_seq_num,start_date,completion_date
5113 			OR l_eam_res_rec.completion_date <> l_old_eam_res_rec.completion_date
5114 		--	OR l_eam_res_rec.resource_id <> l_old_eam_res_rec.resource_id    --resource_code,usage_rate_or_amount,scheduled_flag,assigned_units
5115 		--	OR l_eam_res_rec.usage_rate_or_amount <> l_old_eam_res_rec.usage_rate_or_amount
5116 		--	OR l_eam_res_rec.scheduled_flag <> l_old_eam_res_rec.scheduled_flag
5117 		--	OR NVL(l_eam_res_rec.assigned_units,0) <> NVL(l_old_eam_res_rec.assigned_units,0)
5118 			)
5119 		    )
5120 		) THEN
5121 		    x_bottomup_scheduled := G_UPDATE_RES_USAGE;
5122 	     END IF;
5123 	-- END IF;
5124 
5125   -- Indicate that children need to be processed
5126     l_process_children := TRUE;
5127 
5128        IF l_process_children
5129        THEN
5130 
5131 							      -- Process Resource Instance that are direct children of this operation
5132 							IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling RESOURCE_INSTANCES from OPERATION_RESOURCES') ; END IF ;
5133 
5134 								l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
5135 								RESOURCE_INSTANCES
5136 								(  p_validation_level              =>  p_validation_level
5137 								,  p_wip_entity_id                 =>  l_eam_res_rec.wip_entity_id
5138 								,  p_organization_id               =>  l_eam_res_rec.organization_id
5139 								,  p_operation_seq_num             =>  l_eam_res_rec.operation_seq_num
5140 								,  p_resource_seq_num              =>  l_eam_res_rec.resource_seq_num
5141 								,  p_eam_res_inst_tbl              =>  l_eam_res_inst_tbl
5142 								,  x_eam_res_inst_tbl              =>  l_out_eam_res_inst_tbl
5143 								,  x_mesg_token_tbl                =>  l_mesg_token_tbl
5144 								,  x_return_status                 =>  l_return_status
5145 								,  x_schedule_wo		   =>  x_schedule_wo
5146 								,  x_bottomup_scheduled		   =>  x_bottomup_scheduled
5147 								);
5148 								l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
5149 
5150 							   IF l_return_status in ('Q', 'U')
5151 							   THEN
5152 							      x_return_status := l_return_status;
5153 							      RETURN ;
5154 							   ELSIF NVL(l_return_status, 'S') <> 'S'
5155 							   THEN
5156 							      x_return_status     := l_return_status;
5157 							   END IF;
5158 
5159 
5160 
5161 							      -- Process Resource Usage that are direct children of this operation
5162 							IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling RESOURCE_USAGES from OPERATION_RESOURCES') ; END IF ;
5163 
5164 
5165 								l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
5166 								RESOURCE_USAGES
5167 								(  p_validation_level              =>  p_validation_level
5168 								,  p_wip_entity_id                 =>  l_eam_res_rec.wip_entity_id
5169 								,  p_organization_id               =>  l_eam_res_rec.organization_id
5170 								,  p_operation_seq_num             =>  l_eam_res_rec.operation_seq_num
5171 								,  p_resource_seq_num             =>  l_eam_res_rec.resource_seq_num
5172 								,  p_eam_res_usage_tbl             =>  l_eam_res_usage_tbl
5173 								,  x_bottomup_scheduled		   =>  x_bottomup_scheduled
5174 								,  x_eam_res_usage_tbl             =>  l_out_eam_res_usage_tbl
5175 								,  x_mesg_token_tbl                =>  l_mesg_token_tbl
5176 								,  x_return_status                 =>  l_return_status
5177 								);
5178 								l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
5179 
5180 
5181 							   IF l_return_status in ('Q', 'U')
5182 							   THEN
5183 							      x_return_status := l_return_status;
5184 							      RETURN ;
5185 							   ELSIF NVL(l_return_status, 'S') <> 'S'
5186 							   THEN
5187 							      x_return_status     := l_return_status;
5188 							   END IF;
5189 
5190 
5191    END IF;   -- Process children
5192 
5193 
5194 
5195     ELSE
5196 
5197 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Skipping '|| I || ' record') ; END IF ;
5198 
5199     END IF; -- END IF statement that checks RETURN STATUS
5200 
5201     --  Load tables.
5202     l_eam_res_tbl(I)          := l_eam_res_rec;
5203 
5204 
5205 
5206     --  For loop exception handler.
5207 
5208     EXCEPTION
5209        WHEN EXC_SEV_QUIT_RECORD THEN
5210         l_out_eam_res_tbl           := l_eam_res_tbl;
5211         l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
5212         l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
5213         EAM_ERROR_MESSAGE_PVT.Log_Error
5214         (  p_eam_res_tbl            => l_eam_res_tbl
5215         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
5216         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
5217         ,  p_mesg_token_tbl         => l_mesg_token_tbl
5218         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
5219         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
5220         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_LEVEL
5221         ,  p_entity_index           => I
5222         ,  x_eam_wo_rec             => l_eam_wo_rec
5223         ,  x_eam_op_tbl             => l_eam_op_tbl
5224         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
5225         ,  x_eam_res_tbl            => l_out_eam_res_tbl
5226         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
5227         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
5228         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
5229         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
5230                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
5231         );
5232        l_eam_res_tbl           := l_out_eam_res_tbl;
5233        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
5234        l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
5235 
5236          l_process_children             := FALSE;
5237          IF l_bo_return_status = 'S'
5238          THEN
5239              l_bo_return_status  := l_return_status ;
5240          END IF;
5241          x_return_status                := l_bo_return_status;
5242          x_mesg_token_tbl               := l_mesg_token_tbl ;
5243          x_eam_res_tbl                  := l_eam_res_tbl;
5244 
5245 
5246       WHEN EXC_SEV_QUIT_BRANCH THEN
5247        l_out_eam_res_tbl           := l_eam_res_tbl;
5248        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
5249        l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
5250        EAM_ERROR_MESSAGE_PVT.Log_Error
5251         (  p_eam_res_tbl            => l_eam_res_tbl
5252         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
5253         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
5254         ,  p_mesg_token_tbl         => l_mesg_token_tbl
5255         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
5256         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
5257         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
5258         ,  p_other_message          => l_other_message
5259         ,  p_other_token_tbl        => l_other_token_tbl
5260         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_LEVEL
5261         ,  p_entity_index           => I
5262         ,  x_eam_wo_rec             => l_eam_wo_rec
5263         ,  x_eam_op_tbl             => l_eam_op_tbl
5264         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
5265         ,  x_eam_res_tbl            => l_out_eam_res_tbl
5266         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
5267         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
5268         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
5269         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
5270                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
5271         );
5272        l_eam_res_tbl           := l_out_eam_res_tbl;
5273        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
5274        l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
5275 
5276 
5277          l_process_children             := FALSE ;
5278          IF l_bo_return_status = 'S'
5279          THEN
5280              l_bo_return_status  := l_return_status ;
5281          END IF;
5282          x_return_status                := l_bo_return_status;
5283          x_mesg_token_tbl               := l_mesg_token_tbl ;
5284          x_eam_res_tbl                  := l_eam_res_tbl;
5285 
5286       WHEN EXC_SEV_SKIP_BRANCH THEN
5287        l_out_eam_res_tbl           := l_eam_res_tbl;
5288        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
5289        l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
5290        EAM_ERROR_MESSAGE_PVT.Log_Error
5291         (  p_eam_res_tbl            => l_eam_res_tbl
5292         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
5293         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
5294         ,  p_mesg_token_tbl         => l_mesg_token_tbl
5295         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
5296         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
5297         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_NOT_PICKED
5298         ,  p_other_message          => l_other_message
5299         ,  p_other_token_tbl        => l_other_token_tbl
5300         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_LEVEL
5301         ,  p_entity_index           => I
5302         ,  x_eam_wo_rec             => l_eam_wo_rec
5303         ,  x_eam_op_tbl             => l_eam_op_tbl
5304         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
5305         ,  x_eam_res_tbl            => l_out_eam_res_tbl
5306         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
5307         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
5308         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
5309         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
5310                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
5311         );
5312        l_eam_res_tbl           := l_out_eam_res_tbl;
5313        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
5314        l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
5315 
5316 
5317          l_process_children             := FALSE ;
5318          IF l_bo_return_status = 'S'
5319          THEN
5320              l_bo_return_status  := l_return_status ;
5321          END IF;
5322          x_return_status                := l_bo_return_status;
5323          x_mesg_token_tbl               := l_mesg_token_tbl ;
5324          x_eam_res_tbl                  := l_eam_res_tbl;
5325          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
5326 
5327 
5328       WHEN EXC_SEV_QUIT_SIBLINGS THEN
5329        l_out_eam_res_tbl           := l_eam_res_tbl;
5330        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
5331        l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
5332        EAM_ERROR_MESSAGE_PVT.Log_Error
5333         (  p_eam_res_tbl            => l_eam_res_tbl
5334         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
5335         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
5336         ,  p_mesg_token_tbl         => l_mesg_token_tbl
5337         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
5338         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_SIBLINGS
5339         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
5340         ,  p_other_message          => l_other_message
5341         ,  p_other_token_tbl        => l_other_token_tbl
5342         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_LEVEL
5343         ,  p_entity_index           => I
5344         ,  x_eam_wo_rec             => l_eam_wo_rec
5345         ,  x_eam_op_tbl             => l_eam_op_tbl
5346         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
5347         ,  x_eam_res_tbl            => l_out_eam_res_tbl
5348         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
5349         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
5350         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
5351         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
5352                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
5353         );
5354        l_eam_res_tbl           := l_out_eam_res_tbl;
5355        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
5356        l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
5357 
5358 
5359          l_process_children             := FALSE ;
5360          IF l_bo_return_status = 'S'
5361          THEN
5362              l_bo_return_status  := l_return_status ;
5363          END IF;
5364          x_return_status                := l_bo_return_status;
5365          x_mesg_token_tbl               := l_mesg_token_tbl ;
5366          x_eam_res_tbl                  := l_eam_res_tbl;
5367          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
5368 
5369 
5370       WHEN EXC_FAT_QUIT_BRANCH THEN
5371        l_out_eam_res_tbl           := l_eam_res_tbl;
5372        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
5373        l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
5374        EAM_ERROR_MESSAGE_PVT.Log_Error
5375         (  p_eam_res_tbl            => l_eam_res_tbl
5376         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
5377         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
5378         ,  p_mesg_token_tbl         => l_mesg_token_tbl
5379         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
5380         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
5381         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
5382         ,  p_other_message          => l_other_message
5383         ,  p_other_token_tbl        => l_other_token_tbl
5384         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_LEVEL
5385         ,  p_entity_index           => I
5386         ,  x_eam_wo_rec             => l_eam_wo_rec
5387         ,  x_eam_op_tbl             => l_eam_op_tbl
5388         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
5389         ,  x_eam_res_tbl            => l_out_eam_res_tbl
5390         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
5391         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
5392         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
5393         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
5394                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
5395         );
5396        l_eam_res_tbl           := l_out_eam_res_tbl;
5397        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
5398        l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
5399 
5400 
5401 
5402          l_process_children             := FALSE ;
5403          x_return_status                := EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL;
5404          x_mesg_token_tbl               := l_mesg_token_tbl ;
5405          x_eam_res_tbl                  := l_eam_res_tbl;
5406          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
5407 
5408 
5409 
5410       WHEN EXC_FAT_QUIT_SIBLINGS THEN
5411        l_out_eam_res_tbl           := l_eam_res_tbl;
5412        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
5413        l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
5414        EAM_ERROR_MESSAGE_PVT.Log_Error
5415         (  p_eam_res_tbl            => l_eam_res_tbl
5416         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
5417         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
5418         ,  p_mesg_token_tbl         => l_mesg_token_tbl
5419         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
5420         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_SIBLINGS
5421         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
5422         ,  p_other_message          => l_other_message
5423         ,  p_other_token_tbl        => l_other_token_tbl
5424         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_LEVEL
5425         ,  p_entity_index           => I
5426         ,  x_eam_wo_rec             => l_eam_wo_rec
5427         ,  x_eam_op_tbl             => l_eam_op_tbl
5428         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
5429         ,  x_eam_res_tbl            => l_out_eam_res_tbl
5430         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
5431         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
5432         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
5433         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
5434                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
5435         );
5436        l_eam_res_tbl           := l_out_eam_res_tbl;
5437        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
5438        l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
5439 
5440 
5441          l_process_children             := FALSE ;
5442          x_return_status                := EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL;
5443          x_mesg_token_tbl               := l_mesg_token_tbl ;
5444          x_eam_res_tbl                  := l_eam_res_tbl;
5445          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
5446 
5447 
5448 
5449       WHEN EXC_UNEXP_SKIP_OBJECT THEN
5450        l_out_eam_res_tbl           := l_eam_res_tbl;
5451        l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
5452        l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
5453        EAM_ERROR_MESSAGE_PVT.Log_Error
5454         (  p_eam_res_tbl            => l_eam_res_tbl
5455         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
5456         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
5457         ,  p_mesg_token_tbl         => l_mesg_token_tbl
5458         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
5459         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_NOT_PICKED
5460         ,  p_other_message          => l_other_message
5461         ,  p_other_token_tbl        => l_other_token_tbl
5462         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_RES_LEVEL
5463         ,  x_eam_wo_rec             => l_eam_wo_rec
5464         ,  x_eam_op_tbl             => l_eam_op_tbl
5465         ,  x_eam_op_network_tbl     => l_eam_op_network_tbl
5466         ,  x_eam_res_tbl            => l_out_eam_res_tbl
5467         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
5468         ,  x_eam_sub_res_tbl        => l_eam_sub_res_tbl
5469         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
5470         ,  x_eam_mat_req_tbl        => l_eam_mat_req_tbl
5471                ,  x_eam_direct_items_tbl   => l_eam_direct_items_tbl
5472         );
5473        l_eam_res_tbl           := l_out_eam_res_tbl;
5474        l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
5475        l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
5476 
5477 
5478          l_return_status                := 'U';
5479          x_mesg_token_tbl               := l_mesg_token_tbl ;
5480          x_eam_res_tbl                  := l_eam_res_tbl;
5481          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
5482 
5483    END ; -- END block
5484 
5485    IF l_return_status in ('Q', 'U')
5486    THEN
5487       x_return_status := l_return_status;
5488       RETURN ;
5489    END IF;
5490 
5491 
5492 
5493    END LOOP; -- END Resources processing loop
5494 
5495 
5496 
5497    --  Load OUT parameters
5498    IF NVL(l_return_status, 'S') <> 'S'
5499    THEN
5500       x_return_status     := l_return_status;
5501    END IF;
5502 
5503 
5504         x_Mesg_Token_Tbl               := l_Mesg_Token_Tbl;
5505         x_eam_res_tbl                  := l_eam_res_tbl;
5506         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
5507 	x_eam_res_usage_tbl	       := l_eam_res_usage_tbl;
5508 
5509 END OPERATION_RESOURCES;
5510 
5511 
5512 
5513 
5514 
5515 
5516 
5517 
5518 
5519 
5520 
5521 
5522 PROCEDURE WO_OPERATIONS
5523         (  p_validation_level        IN  NUMBER
5524         ,  p_wip_entity_id           IN  NUMBER := NULL
5525         ,  p_organization_id         IN  NUMBER
5526         ,  p_eam_op_tbl              IN EAM_PROCESS_WO_PUB.eam_op_tbl_type
5527         ,  p_eam_op_network_tbl      IN EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
5528         ,  p_eam_res_tbl             IN EAM_PROCESS_WO_PUB.eam_res_tbl_type
5529         ,  p_eam_res_inst_tbl        IN EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
5530         ,  p_eam_sub_res_tbl         IN EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
5531         ,  p_eam_res_usage_tbl       IN EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
5532         ,  p_eam_mat_req_tbl         IN EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
5533         ,  p_eam_direct_items_tbl         IN EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
5534         ,  x_eam_op_tbl              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_tbl_type
5535         ,  x_eam_op_network_tbl      OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
5536         ,  x_eam_res_tbl             OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_tbl_type
5537         ,  x_eam_res_inst_tbl        OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
5538         ,  x_eam_sub_res_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
5539         ,  x_eam_res_usage_tbl       OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
5540         ,  x_eam_mat_req_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
5541         ,  x_eam_direct_items_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
5542 	,  x_schedule_wo              IN OUT NOCOPY NUMBER
5543 	,  x_bottomup_scheduled      IN OUT NOCOPY NUMBER
5544 	,  x_material_shortage       IN OUT NOCOPY NUMBER
5545         ,  x_mesg_token_tbl          OUT NOCOPY EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type
5546         ,  x_return_status           OUT NOCOPY VARCHAR2
5547         )
5548 IS
5549 
5550 l_eam_op_rec            EAM_PROCESS_WO_PUB.eam_op_rec_type ;
5551 l_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type ;
5552 l_old_eam_op_rec        EAM_PROCESS_WO_PUB.eam_op_rec_type ;
5553 
5554 l_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type ;
5555 l_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type :=p_eam_op_network_tbl;
5556 l_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type        :=p_eam_res_tbl;
5557 l_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type   :=p_eam_res_inst_tbl;
5558 l_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type    :=p_eam_sub_res_tbl;
5559 l_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type  :=p_eam_res_usage_tbl;
5560 l_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type    :=p_eam_mat_req_tbl;
5561 l_eam_direct_items_tbl  EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type    :=p_eam_direct_items_tbl;
5562 
5563 
5564         -- baroy - added for making the NOCOPY changes
5565         l_out_eam_wo_rec                 EAM_PROCESS_WO_PUB.eam_wo_rec_type;
5566         l_out_eam_op_rec                 EAM_PROCESS_WO_PUB.eam_op_rec_type;
5567         l_out_eam_op_tbl                 EAM_PROCESS_WO_PUB.eam_op_tbl_type;
5568         l_out_eam_op_network_tbl         EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
5569         l_out_eam_res_tbl                EAM_PROCESS_WO_PUB.eam_res_tbl_type;
5570         l_out_eam_res_inst_tbl           EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
5571         l_out_eam_sub_res_tbl            EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
5572         l_out_eam_res_usage_tbl          EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
5573         l_out_eam_mat_req_tbl            EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
5574         l_out_eam_direct_items_tbl            EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
5575 
5576 /* Error Handling Variables */
5577 l_token_tbl             EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
5578 l_mesg_token_tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
5579 l_other_token_tbl       EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
5580 l_other_message         VARCHAR2(2000);
5581 l_err_text              VARCHAR2(2000);
5582 l_out_Mesg_Token_Tbl EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
5583 
5584 /* Others */
5585 l_return_status         VARCHAR2(1) ;
5586 l_bo_return_status      VARCHAR2(1) ;
5587 l_parent_exists         BOOLEAN := FALSE ;
5588 l_process_children      BOOLEAN := TRUE ;
5589 l_valid_transaction     BOOLEAN := TRUE ;
5590 
5591 
5592 BEGIN
5593 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(p_eam_op_tbl.COUNT ||' records passed') ; END IF ;
5594 
5595    x_return_status := FND_API.G_RET_STS_SUCCESS;
5596 
5597    --  Init local table variables.
5598    l_return_status    := 'S' ;
5599    l_bo_return_status := 'S' ;
5600    l_eam_op_tbl    := p_eam_op_tbl ;
5601 
5602 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Starting WO_OPERATIONS') ; END IF ;
5603 
5604    FOR I IN 1..l_eam_op_tbl.COUNT LOOP
5605    BEGIN
5606 
5607 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Processing '|| I || ' record') ; END IF ;
5608 
5609       --  Load local records.
5610       l_eam_op_rec := l_eam_op_tbl(I);
5611 
5612 
5613       -- make sure to set process_children to false at the start of every iteration
5614 
5615       l_process_children := FALSE;
5616 
5617 
5618       IF l_eam_op_rec.wip_entity_id is NULL
5619          AND (l_eam_op_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
5620              OR l_eam_op_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_SYNC)
5621       THEN
5622           l_eam_op_rec.wip_entity_id := p_wip_entity_id;
5623       END IF;
5624 
5625 
5626       IF p_wip_entity_id IS NOT NULL AND
5627          p_organization_id IS NOT NULL
5628       THEN
5629          l_parent_exists := TRUE;
5630       END IF;
5631 
5632       IF (l_eam_op_rec.return_status IS NULL OR l_eam_op_rec.return_status = FND_API.G_MISS_CHAR)
5633            AND
5634            (NOT l_parent_exists
5635             OR
5636              (l_parent_exists AND
5637               l_eam_op_rec.wip_entity_id = p_wip_entity_id AND
5638               l_eam_op_rec.organization_id = p_organization_id
5639              )
5640            )
5641       THEN
5642 
5643 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Return status validation passed') ; END IF ;
5644 
5645          l_return_status := FND_API.G_RET_STS_SUCCESS;
5646          l_eam_op_rec.return_status := FND_API.G_RET_STS_SUCCESS;
5647 
5648         VALIDATE_TRANSACTION_TYPE
5649         (   p_transaction_type  => l_eam_op_rec.transaction_type
5650         ,   p_entity_name       => 'OPERATION'
5651         ,   p_entity_id         => to_char(l_eam_op_rec.operation_seq_num)
5652         ,   X_valid_transaction => l_valid_transaction
5653         ,   x_mesg_token_tbl    => l_mesg_token_tbl
5654         );
5655 
5656          IF NOT l_valid_transaction
5657          THEN
5658              l_return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
5659              RAISE EXC_SEV_QUIT_RECORD ;
5660          END IF ;
5661 
5662          EAM_OP_VALIDATE_PVT.Check_Existence
5663          (  p_eam_op_rec             => l_eam_op_rec
5664          ,  x_old_eam_op_rec         => l_old_eam_op_rec
5665          ,  x_mesg_token_tbl         => l_mesg_token_tbl
5666          ,  x_return_status          => l_return_status
5667          ) ;
5668 
5669 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check Existence completed with return_status: ' || l_return_status) ;  END IF ;
5670 
5671          IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
5672          THEN
5673             l_other_message := 'EAM_OP_EXS_SEV_SKIP';
5674             l_other_token_tbl(1).token_name  := 'OP_SEQ_NUMBER';
5675             l_other_token_tbl(1).token_value := l_eam_op_rec.operation_seq_num;
5676             l_other_token_tbl(2).token_name  := 'WIP_ENTITY_ID';
5677             l_other_token_tbl(2).token_value := l_eam_op_rec.wip_entity_id;
5678             RAISE EXC_SEV_QUIT_BRANCH;
5679          ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
5680          THEN
5681             l_other_message := 'EAM_OP_EXS_UNEXP_SKIP';
5682             l_other_token_tbl(1).token_name  := 'OP_SEQ_NUMBER';
5683             l_other_token_tbl(1).token_value := l_eam_op_rec.operation_seq_num ;
5684             l_other_token_tbl(2).token_name  := 'WIP_ENTITY_ID';
5685             l_other_token_tbl(2).token_value := l_eam_op_rec.wip_entity_id ;
5686             RAISE EXC_UNEXP_SKIP_OBJECT;
5687          END IF;
5688 
5689         /* Assign the correct transaction type for SYNC operations */
5690 
5691         IF l_eam_op_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_SYNC THEN
5692            l_eam_op_rec.transaction_type := l_old_eam_op_rec.transaction_type;
5693         END IF;
5694 
5695         IF l_eam_op_rec.transaction_type IN (EAM_PROCESS_WO_PVT.G_OPR_UPDATE, EAM_PROCESS_WO_PVT.G_OPR_DELETE)
5696         THEN
5697 
5698            IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Populate NULL columns') ;
5699            END IF ;
5700 
5701            l_out_eam_op_rec := l_eam_op_rec;
5702            EAM_OP_DEFAULT_PVT.Populate_Null_Columns
5703            (   p_eam_op_rec        => l_eam_op_rec
5704            ,   p_old_eam_op_Rec    => l_old_eam_op_rec
5705            ,   x_eam_op_rec     => l_out_eam_op_rec
5706            ) ;
5707            l_eam_op_rec := l_out_eam_op_rec;
5708 
5709 
5710         ELSIF l_eam_op_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
5711         THEN
5712 
5713            l_out_eam_op_rec := l_eam_op_rec;
5714            EAM_OP_DEFAULT_PVT.Attribute_Defaulting
5715            (   p_eam_op_rec   => l_eam_op_rec
5716            ,   x_eam_op_rec   => l_out_eam_op_rec
5717            ,   x_mesg_token_tbl  => l_mesg_token_tbl
5718            ,   x_return_status   => l_return_status
5719            ) ;
5720            l_eam_op_rec := l_out_eam_op_rec;
5721 
5722            IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug
5723            ('Attribute Defaulting completed with return_status: ' || l_return_status) ;
5724            END IF ;
5725 
5726 
5727            IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
5728            THEN
5729               l_other_message := 'EAM_OP_ATTDEF_CSEV_SKIP';
5730               l_other_token_tbl(1).token_name := 'OP_SEQ_NUMBER';
5731               l_other_token_tbl(1).token_value :=
5732                           l_eam_op_rec.OPERATION_SEQ_NUM ;
5733               RAISE EXC_SEV_SKIP_BRANCH ;
5734 
5735            ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
5736            THEN
5737               l_other_message := 'EAM_OP_ATTDEF_UNEXP_SKIP';
5738               l_other_token_tbl(1).token_name := 'OP_SEQ_NUMBER';
5739               l_other_token_tbl(1).token_value :=
5740                            l_eam_op_rec.OPERATION_SEQ_NUM ;
5741               RAISE EXC_UNEXP_SKIP_OBJECT ;
5742            ELSIF l_return_status ='S' AND l_mesg_token_tbl .COUNT <> 0
5743            THEN
5744              l_out_eam_op_tbl            := l_eam_op_tbl;
5745              l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
5746              l_out_eam_res_tbl           := l_eam_res_tbl;
5747              l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
5748              l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
5749              l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
5750              l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
5751               EAM_ERROR_MESSAGE_PVT.Log_Error
5752                (  p_eam_op_tbl             => l_eam_op_tbl
5753                ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
5754                ,  p_eam_res_tbl            => l_eam_res_tbl
5755                ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
5756                ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
5757                ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
5758                ,  p_eam_direct_items_tbl        => l_eam_direct_items_tbl
5759                ,  p_mesg_token_tbl         => l_mesg_token_tbl
5760                ,  p_error_status           => 'W'
5761                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_LEVEL
5762                ,  p_entity_index           => I
5763                ,  x_eam_wo_rec             => l_eam_wo_rec
5764                ,  x_eam_op_tbl             => l_out_eam_op_tbl
5765                ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
5766                ,  x_eam_res_tbl            => l_out_eam_res_tbl
5767                ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
5768                ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
5769                ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
5770                ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
5771                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
5772                );
5773              l_eam_op_tbl                := l_out_eam_op_tbl;
5774              l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
5775              l_eam_res_tbl               := l_out_eam_res_tbl;
5776              l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
5777              l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
5778              l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
5779              l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
5780           END IF;
5781        END IF;
5782 
5783 
5784          EAM_OP_VALIDATE_PVT.Check_Required
5785          ( p_eam_op_rec                 => l_eam_op_rec
5786          , x_return_status              => l_return_status
5787          , x_mesg_token_tbl             => l_mesg_token_tbl
5788          ) ;
5789 
5790 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check required completed with return_status: ' || l_return_status) ; END IF ;
5791 
5792 
5793          IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
5794          THEN
5795             IF l_eam_op_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
5796             THEN
5797                l_other_message := 'EAM_OP_REQ_CSEV_SKIP';
5798                l_other_token_tbl(1).token_name  := 'OP_SEQ_NUMBER';
5799                l_other_token_tbl(1).token_value := l_eam_op_rec.OPERATION_SEQ_NUM ;
5800                RAISE EXC_SEV_SKIP_BRANCH ;
5801             ELSE
5802                RAISE EXC_SEV_QUIT_RECORD ;
5803             END IF;
5804          ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
5805          THEN
5806             l_other_message := 'EAM_OP_REQ_UNEXP_SKIP';
5807             l_other_token_tbl(1).token_name  := 'OP_SEQ_NUMBER';
5808             l_other_token_tbl(1).token_value := l_eam_op_rec.OPERATION_SEQ_NUM ;
5809             RAISE EXC_UNEXP_SKIP_OBJECT ;
5810          END IF;
5811 
5812 
5813             EAM_OP_VALIDATE_PVT.Check_Attributes
5814             ( p_eam_op_rec        => l_eam_op_rec
5815             , p_old_eam_op_rec    => l_old_eam_op_rec
5816             , x_return_status     => l_return_status
5817             , x_mesg_token_tbl    => l_mesg_token_tbl
5818             ) ;
5819 
5820 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Attribute validation completed with return_status: ' || l_return_status) ; END IF ;
5821 
5822             IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
5823             THEN
5824                IF l_eam_op_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
5825                THEN
5826                   l_other_message := 'EAM_OP_ATTVAL_CSEV_SKIP';
5827                   l_other_token_tbl(1).token_name := 'OP_SEQ_NUMBER';
5828                   l_other_token_tbl(1).token_value :=
5829                            l_eam_op_rec.OPERATION_SEQ_NUM ;
5830                   RAISE EXC_SEV_SKIP_BRANCH ;
5831                   ELSE
5832                      RAISE EXC_SEV_QUIT_RECORD ;
5833                END IF;
5834             ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
5835             THEN
5836                l_other_message := 'EAM_OP_ATTVAL_UNEXP_SKIP';
5837                l_other_token_tbl(1).token_name := 'OP_SEQ_NUMBER';
5838                l_other_token_tbl(1).token_value :=
5839                            l_eam_op_rec.OPERATION_SEQ_NUM ;
5840                RAISE EXC_UNEXP_SKIP_OBJECT ;
5841             ELSIF l_return_status ='S' AND l_mesg_token_tbl .COUNT <> 0
5842             THEN
5843              l_out_eam_op_tbl            := l_eam_op_tbl;
5844              l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
5845              l_out_eam_res_tbl           := l_eam_res_tbl;
5846              l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
5847              l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
5848              l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
5849              l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
5850               EAM_ERROR_MESSAGE_PVT.Log_Error
5851                (  p_eam_op_tbl             => l_eam_op_tbl
5852                ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
5853                ,  p_eam_res_tbl            => l_eam_res_tbl
5854                ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
5855                ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
5856                ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
5857                ,  p_eam_direct_items_tbl        => l_eam_direct_items_tbl
5858                ,  p_mesg_token_tbl         => l_mesg_token_tbl
5859                ,  p_error_status           => 'W'
5860                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_LEVEL
5861                ,  p_entity_index           => I
5862                ,  x_eam_wo_rec             => l_eam_wo_rec
5863                ,  x_eam_op_tbl             => l_out_eam_op_tbl
5864                ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
5865                ,  x_eam_res_tbl            => l_out_eam_res_tbl
5866                ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
5867                ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
5868                ,  x_eam_res_usage_tbl      => l_eam_res_usage_tbl
5869                ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
5870                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
5871                );
5872              l_eam_op_tbl                := l_out_eam_op_tbl;
5873              l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
5874              l_eam_res_tbl               := l_out_eam_res_tbl;
5875              l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
5876              l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
5877              l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
5878              l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
5879 
5880            END IF;
5881 
5882           IF(x_schedule_wo = G_NOT_SCHEDULE_WO) THEN   --not firm and not yet set to schedule
5883 	    IF (l_eam_op_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_UPDATE AND
5884                          (l_eam_op_rec.start_date<>l_old_eam_op_rec.start_date
5885                            OR l_eam_op_rec.completion_date<>l_old_eam_op_rec.completion_date)) THEN
5886 			     l_eam_op_rec.start_date := l_old_eam_op_rec.start_date;      --set op dates to prev. dates
5887 			     l_eam_op_rec.completion_date := l_old_eam_op_rec.completion_date;
5888 	    END IF;
5889 	  END IF;
5890 
5891           IF(x_bottomup_scheduled = G_NOT_BU_SCHEDULE_WO) THEN   --not firm and not yet set to schedule for bottom up
5892 	    IF (l_eam_op_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_UPDATE AND
5893                          (l_eam_op_rec.start_date<>l_old_eam_op_rec.start_date
5894                            OR l_eam_op_rec.completion_date<>l_old_eam_op_rec.completion_date)) THEN
5895 			 --    l_eam_op_rec.start_date := l_old_eam_op_rec.start_date;      --set op dates to prev. dates
5896 			 --    l_eam_op_rec.completion_date := l_old_eam_op_rec.completion_date;
5897 			 x_bottomup_scheduled := G_BU_SCHEDULE_WO;
5898 	    END IF;
5899 	  END IF;
5900 
5901 
5902           EAM_OP_UTILITY_PVT.Perform_Writes
5903           (   p_eam_op_rec          => l_eam_op_rec
5904           ,   x_mesg_token_tbl      => l_mesg_token_tbl
5905           ,   x_return_status       => l_return_status
5906           ) ;
5907 
5908 
5909        IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
5910        THEN
5911           l_other_message := 'EAM_OP_WRITES_UNEXP_SKIP';
5912           l_other_token_tbl(1).token_name := 'OP_SEQ_NUMBER';
5913           l_other_token_tbl(1).token_value :=
5914                           l_eam_op_rec.OPERATION_SEQ_NUM ;
5915           RAISE EXC_UNEXP_SKIP_OBJECT ;
5916        ELSIF l_return_status ='S' AND
5917           l_mesg_token_tbl.COUNT <>0
5918        THEN
5919             l_out_eam_op_tbl            := l_eam_op_tbl;
5920             l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
5921             l_out_eam_res_tbl           := l_eam_res_tbl;
5922             l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
5923             l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
5924             l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
5925             l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
5926             l_out_eam_direct_items_tbl     := l_eam_direct_items_tbl;
5927             EAM_ERROR_MESSAGE_PVT.Log_Error
5928                (  p_eam_op_tbl             => l_eam_op_tbl
5929                ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
5930                ,  p_eam_res_tbl            => l_eam_res_tbl
5931                ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
5932                ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
5933                ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
5934                ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
5935                ,  p_eam_direct_items_tbl        => l_eam_direct_items_tbl
5936                ,  p_mesg_token_tbl         => l_mesg_token_tbl
5937                ,  p_error_status           => 'W'
5938                ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_LEVEL
5939                ,  p_entity_index           => I
5940                ,  x_eam_wo_rec             => l_eam_wo_rec
5941                ,  x_eam_op_tbl             => l_out_eam_op_tbl
5942                ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
5943                ,  x_eam_res_tbl            => l_out_eam_res_tbl
5944                ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
5945                ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
5946                ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
5947                ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
5948                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
5949                );
5950 	      l_eam_op_tbl                := l_out_eam_op_tbl;
5951 	      l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
5952 	      l_eam_res_tbl               := l_out_eam_res_tbl;
5953 	      l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
5954 	      l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
5955 	      l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
5956 	      l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
5957 	      l_eam_direct_items_tbl         := l_out_eam_direct_items_tbl;
5958        END IF;
5959 
5960 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Operations Database writes completed with status  ' || l_return_status); END IF;
5961 
5962 
5963           --find if scheduler is to be called or not
5964           IF(x_schedule_wo = G_NOT_SCHEDULE_WO) THEN
5965 		     IF(l_eam_op_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_CREATE)
5966 		      THEN   --if operation is added
5967 			x_schedule_wo := G_SCHEDULE_WO;
5968 		     END IF;
5969 	   END IF;
5970 
5971 	    --find if bottom up scheduler is to be called or not
5972           IF(x_bottomup_scheduled = G_NOT_BU_SCHEDULE_WO) THEN
5973 		     IF(l_eam_op_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_CREATE)
5974 		      THEN   --if operation is added
5975 			  x_bottomup_scheduled := G_BU_SCHEDULE_WO;
5976 		     END IF;
5977 	   END IF;
5978 
5979     ELSE
5980 
5981 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Skipping '|| I || ' record') ; END IF ;
5982 
5983     END IF; -- END IF statement that checks RETURN STATUS
5984 
5985     --  Load tables.
5986     l_eam_op_tbl(I)          := l_eam_op_rec;
5987 
5988     -- Indicate that children need to be processed
5989     l_process_children := TRUE;
5990 
5991     --  For loop exception handler.
5992 
5993     EXCEPTION
5994        WHEN EXC_SEV_QUIT_RECORD THEN
5995 	         l_out_eam_op_tbl            := l_eam_op_tbl;
5996 	  	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
5997 	         l_out_eam_res_tbl           := l_eam_res_tbl;
5998 	         l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
5999 		 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
6000 	         l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
6001 	         l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
6002 	         l_out_eam_direct_items_tbl     := l_eam_direct_items_tbl;
6003         EAM_ERROR_MESSAGE_PVT.Log_Error
6004         (  p_eam_op_tbl             => l_eam_op_tbl
6005         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
6006         ,  p_eam_res_tbl            => l_eam_res_tbl
6007         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
6008         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
6009         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
6010         ,  p_eam_direct_items_tbl      => l_eam_direct_items_tbl
6011         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
6012         ,  p_mesg_token_tbl         => l_mesg_token_tbl
6013         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
6014         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
6015         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_LEVEL
6016         ,  p_entity_index           => I
6017         ,  x_eam_wo_rec             => l_eam_wo_rec
6018         ,  x_eam_op_tbl             => l_out_eam_op_tbl
6019         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
6020         ,  x_eam_res_tbl            => l_out_eam_res_tbl
6021         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
6022         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
6023         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
6024         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
6025                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
6026         );
6027 	         l_eam_op_tbl                := l_out_eam_op_tbl;
6028 	         l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
6029 	         l_eam_res_tbl               := l_out_eam_res_tbl;
6030 	         l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
6031 	         l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
6032 	         l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
6033   	         l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
6034   	         l_eam_direct_items_tbl         := l_out_eam_direct_items_tbl;
6035 
6036          l_process_children             := FALSE;
6037          IF l_bo_return_status = 'S'
6038          THEN
6039              l_bo_return_status  := l_return_status ;
6040          END IF;
6041          x_return_status                := l_bo_return_status;
6042          x_mesg_token_tbl               := l_mesg_token_tbl ;
6043          x_eam_op_tbl                   := l_eam_op_tbl;
6044          x_eam_op_network_tbl           := l_eam_op_network_tbl;
6045          x_eam_res_tbl                  := l_eam_res_tbl;
6046          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
6047          x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
6048          x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
6049          x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
6050          x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
6051 
6052 
6053       WHEN EXC_SEV_QUIT_BRANCH THEN
6054 	         l_out_eam_op_tbl            := l_eam_op_tbl;
6055 	  	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
6056 	         l_out_eam_res_tbl           := l_eam_res_tbl;
6057 	         l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
6058 		 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
6059 	         l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
6060 	         l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
6061 	         l_out_eam_direct_items_tbl     := l_eam_direct_items_tbl;
6062        EAM_ERROR_MESSAGE_PVT.Log_Error
6063         (  p_eam_op_tbl             => l_eam_op_tbl
6064         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
6065         ,  p_eam_res_tbl            => l_eam_res_tbl
6066         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
6067         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
6068         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
6069         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
6070         ,  p_eam_direct_items_tbl        => l_eam_direct_items_tbl
6071         ,  p_mesg_token_tbl         => l_mesg_token_tbl
6072         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
6073         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
6074         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
6075         ,  p_other_message          => l_other_message
6076         ,  p_other_token_tbl        => l_other_token_tbl
6077         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_LEVEL
6078         ,  p_entity_index           => I
6079         ,  x_eam_wo_rec             => l_eam_wo_rec
6080         ,  x_eam_op_tbl             => l_out_eam_op_tbl
6081         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
6082         ,  x_eam_res_tbl            => l_out_eam_res_tbl
6083         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
6084         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
6085         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
6086         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
6087                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
6088         );
6089 	         l_eam_op_tbl                := l_out_eam_op_tbl;
6090 	         l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
6091 	         l_eam_res_tbl               := l_out_eam_res_tbl;
6092 	         l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
6093 	         l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
6094 	         l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
6095   	         l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
6096   	         l_eam_direct_items_tbl         := l_out_eam_direct_items_tbl;
6097 
6098 
6099          l_process_children             := FALSE ;
6100          IF l_bo_return_status = 'S'
6101          THEN
6102              l_bo_return_status  := l_return_status ;
6103          END IF;
6104          x_return_status                := l_bo_return_status;
6105          x_mesg_token_tbl               := l_mesg_token_tbl ;
6106          x_eam_op_tbl                   := l_eam_op_tbl;
6107          x_eam_op_network_tbl           := l_eam_op_network_tbl;
6108          x_eam_res_tbl                  := l_eam_res_tbl;
6109          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
6110          x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
6111          x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
6112          x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
6113          x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
6114 
6115 
6116       WHEN EXC_SEV_SKIP_BRANCH THEN
6117 	         l_out_eam_op_tbl            := l_eam_op_tbl;
6118 	  	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
6119 	         l_out_eam_res_tbl           := l_eam_res_tbl;
6120 	         l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
6121 		 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
6122 	         l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
6123 	         l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
6124 	         l_out_eam_direct_items_tbl     := l_eam_direct_items_tbl;
6125        EAM_ERROR_MESSAGE_PVT.Log_Error
6126         (  p_eam_op_tbl             => l_eam_op_tbl
6127         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
6128         ,  p_eam_res_tbl            => l_eam_res_tbl
6129         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
6130         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
6131         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
6132         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
6133         ,  p_eam_direct_items_tbl        => l_eam_direct_items_tbl
6134         ,  p_mesg_token_tbl         => l_mesg_token_tbl
6135         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
6136         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
6137         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_NOT_PICKED
6138         ,  p_other_message          => l_other_message
6139         ,  p_other_token_tbl        => l_other_token_tbl
6140         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_LEVEL
6141         ,  p_entity_index           => I
6142         ,  x_eam_wo_rec             => l_eam_wo_rec
6143         ,  x_eam_op_tbl             => l_out_eam_op_tbl
6144         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
6145         ,  x_eam_res_tbl            => l_out_eam_res_tbl
6146         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
6147         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
6148         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
6149         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
6150                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
6151         );
6152 	         l_eam_op_tbl                := l_out_eam_op_tbl;
6153 	         l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
6154 	         l_eam_res_tbl               := l_out_eam_res_tbl;
6155 	         l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
6156 	         l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
6157 	         l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
6158   	         l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
6159   	         l_eam_direct_items_tbl         := l_out_eam_direct_items_tbl;
6160 
6161 
6162          l_process_children             := FALSE ;
6163          IF l_bo_return_status = 'S'
6164          THEN
6165              l_bo_return_status  := l_return_status ;
6166          END IF;
6167          x_return_status                := l_bo_return_status;
6168          x_mesg_token_tbl               := l_mesg_token_tbl ;
6169          x_eam_op_tbl                   := l_eam_op_tbl;
6170          x_eam_op_network_tbl           := l_eam_op_network_tbl;
6171          x_eam_res_tbl                  := l_eam_res_tbl;
6172          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
6173          x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
6174          x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
6175          x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
6176          x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
6177 
6178 
6179       WHEN EXC_SEV_QUIT_SIBLINGS THEN
6180 	         l_out_eam_op_tbl            := l_eam_op_tbl;
6181 	  	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
6182 	         l_out_eam_res_tbl           := l_eam_res_tbl;
6183 	         l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
6184 		 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
6185 	         l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
6186 	         l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
6187 	         l_out_eam_direct_items_tbl     := l_eam_direct_items_tbl;
6188        EAM_ERROR_MESSAGE_PVT.Log_Error
6189         (  p_eam_op_tbl             => l_eam_op_tbl
6190         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
6191         ,  p_eam_res_tbl            => l_eam_res_tbl
6192         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
6193         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
6194         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
6195         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
6196         ,  p_eam_direct_items_tbl        => l_eam_direct_items_tbl
6197         ,  p_mesg_token_tbl         => l_mesg_token_tbl
6198         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
6199         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_SIBLINGS
6200         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
6201         ,  p_other_message          => l_other_message
6202         ,  p_other_token_tbl        => l_other_token_tbl
6203         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_LEVEL
6204         ,  p_entity_index           => I
6205         ,  x_eam_wo_rec             => l_eam_wo_rec
6206         ,  x_eam_op_tbl             => l_out_eam_op_tbl
6207         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
6208         ,  x_eam_res_tbl            => l_out_eam_res_tbl
6209         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
6210         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
6211         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
6212         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
6213                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
6214         );
6215 	         l_eam_op_tbl                := l_out_eam_op_tbl;
6216 	         l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
6217 	         l_eam_res_tbl               := l_out_eam_res_tbl;
6218 	         l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
6219 	         l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
6220 	         l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
6221   	         l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
6222   	         l_eam_direct_items_tbl         := l_out_eam_direct_items_tbl;
6223 
6224 
6225          l_process_children             := FALSE ;
6226          IF l_bo_return_status = 'S'
6227          THEN
6228              l_bo_return_status  := l_return_status ;
6229          END IF;
6230          x_return_status                := l_bo_return_status;
6231          x_mesg_token_tbl               := l_mesg_token_tbl ;
6232          x_eam_op_tbl                   := l_eam_op_tbl;
6233          x_eam_op_network_tbl           := l_eam_op_network_tbl;
6234          x_eam_res_tbl                  := l_eam_res_tbl;
6235          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
6236          x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
6237          x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
6238          x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
6239          x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
6240 
6241 
6242       WHEN EXC_FAT_QUIT_BRANCH THEN
6243 	         l_out_eam_op_tbl            := l_eam_op_tbl;
6244 	  	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
6245 	         l_out_eam_res_tbl           := l_eam_res_tbl;
6246 	         l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
6247 		 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
6248 	         l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
6249 	         l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
6250 	         l_out_eam_direct_items_tbl     := l_eam_direct_items_tbl;
6251        EAM_ERROR_MESSAGE_PVT.Log_Error
6252         (  p_eam_op_tbl             => l_eam_op_tbl
6253         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
6254         ,  p_eam_res_tbl            => l_eam_res_tbl
6255         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
6256         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
6257         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
6258         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
6259         ,  p_eam_direct_items_tbl        => l_eam_direct_items_tbl
6260         ,  p_mesg_token_tbl         => l_mesg_token_tbl
6261         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
6262         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_CHILDREN
6263         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
6264         ,  p_other_message          => l_other_message
6265         ,  p_other_token_tbl        => l_other_token_tbl
6266         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_LEVEL
6267         ,  p_entity_index           => I
6268         ,  x_eam_wo_rec             => l_eam_wo_rec
6269         ,  x_eam_op_tbl             => l_out_eam_op_tbl
6270         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
6271         ,  x_eam_res_tbl            => l_out_eam_res_tbl
6272         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
6273         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
6274         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
6275         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
6276                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
6277         );
6278 	         l_eam_op_tbl                := l_out_eam_op_tbl;
6279 	         l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
6280 	         l_eam_res_tbl               := l_out_eam_res_tbl;
6281 	         l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
6282 	         l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
6283 	         l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
6284   	         l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
6285   	         l_eam_direct_items_tbl         := l_out_eam_direct_items_tbl;
6286 
6287 
6288          l_process_children             := FALSE ;
6289          x_return_status                := EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL;
6290          x_mesg_token_tbl               := l_mesg_token_tbl ;
6291          x_eam_op_tbl                   := l_eam_op_tbl;
6292          x_eam_op_network_tbl           := l_eam_op_network_tbl;
6293          x_eam_res_tbl                  := l_eam_res_tbl;
6294          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
6295          x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
6296          x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
6297          x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
6298          x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
6299 
6300 
6301 
6302       WHEN EXC_FAT_QUIT_SIBLINGS THEN
6303 	         l_out_eam_op_tbl            := l_eam_op_tbl;
6304 	  	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
6305 	         l_out_eam_res_tbl           := l_eam_res_tbl;
6306 	         l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
6307 		 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
6308 	         l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
6309 	         l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
6310 	         l_out_eam_direct_items_tbl     := l_eam_direct_items_tbl;
6311        EAM_ERROR_MESSAGE_PVT.Log_Error
6312         (  p_eam_op_tbl             => l_eam_op_tbl
6313         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
6314         ,  p_eam_res_tbl            => l_eam_res_tbl
6315         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
6316         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
6317         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
6318         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
6319         ,  p_eam_direct_items_tbl        => l_eam_direct_items_tbl
6320         ,  p_mesg_token_tbl         => l_mesg_token_tbl
6321         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
6322         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_SIBLINGS
6323         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL
6324         ,  p_other_message          => l_other_message
6325         ,  p_other_token_tbl        => l_other_token_tbl
6326         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_LEVEL
6327         ,  p_entity_index           => I
6328         ,  x_eam_wo_rec             => l_eam_wo_rec
6329         ,  x_eam_op_tbl             => l_out_eam_op_tbl
6330         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
6331         ,  x_eam_res_tbl            => l_out_eam_res_tbl
6332         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
6333         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
6334         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
6335         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
6336                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
6337         );
6338 	         l_eam_op_tbl                := l_out_eam_op_tbl;
6339 	         l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
6340 	         l_eam_res_tbl               := l_out_eam_res_tbl;
6341 	         l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
6342 	         l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
6343 	         l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
6344   	         l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
6345   	         l_eam_direct_items_tbl         := l_out_eam_direct_items_tbl;
6346 
6347 
6348          l_process_children             := FALSE ;
6349          x_return_status                := EAM_ERROR_MESSAGE_PVT.G_STATUS_FATAL;
6350          x_mesg_token_tbl               := l_mesg_token_tbl ;
6351          x_eam_op_tbl                   := l_eam_op_tbl;
6352          x_eam_op_network_tbl           := l_eam_op_network_tbl;
6353          x_eam_res_tbl                  := l_eam_res_tbl;
6354          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
6355          x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
6356          x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
6357          x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
6358          x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
6359 
6360 
6361       WHEN EXC_UNEXP_SKIP_OBJECT THEN
6362 	         l_out_eam_op_tbl            := l_eam_op_tbl;
6363 	  	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
6364 	         l_out_eam_res_tbl           := l_eam_res_tbl;
6365 	         l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
6366 		 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
6367 	         l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
6368 	         l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
6369 	         l_out_eam_direct_items_tbl     := l_eam_direct_items_tbl;
6370        EAM_ERROR_MESSAGE_PVT.Log_Error
6371         (  p_eam_op_tbl             => l_eam_op_tbl
6372         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
6373         ,  p_eam_res_tbl            => l_eam_res_tbl
6374         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
6375         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
6376         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
6377         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
6378         ,  p_eam_direct_items_tbl        => l_eam_direct_items_tbl
6379         ,  p_mesg_token_tbl         => l_mesg_token_tbl
6380         ,  p_error_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
6381         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_NOT_PICKED
6382         ,  p_other_message          => l_other_message
6383         ,  p_other_token_tbl        => l_other_token_tbl
6384         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_OP_LEVEL
6385         ,  x_eam_wo_rec             => l_eam_wo_rec
6386         ,  x_eam_op_tbl             => l_out_eam_op_tbl
6387         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
6388         ,  x_eam_res_tbl            => l_out_eam_res_tbl
6389         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
6390         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
6391         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
6392         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
6393                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
6394         );
6395 	         l_eam_op_tbl                := l_out_eam_op_tbl;
6396 	         l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
6397 	         l_eam_res_tbl               := l_out_eam_res_tbl;
6398 	         l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
6399 	         l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
6400 	         l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
6401   	         l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
6402   	         l_eam_direct_items_tbl         := l_out_eam_direct_items_tbl;
6403 
6404 
6405          l_return_status                := 'U';
6406          x_mesg_token_tbl               := l_mesg_token_tbl ;
6407          x_eam_op_tbl                   := l_eam_op_tbl;
6408          x_eam_op_network_tbl           := l_eam_op_network_tbl;
6409          x_eam_res_tbl                  := l_eam_res_tbl;
6410          x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
6411          x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
6412          x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
6413          x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
6414          x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
6415 
6416    END ; -- END block
6417 
6418    IF l_return_status in ('Q', 'U')
6419    THEN
6420       x_return_status := l_return_status;
6421       RETURN ;
6422    END IF;
6423 
6424 
6425    IF l_process_children
6426    THEN
6427 
6428       -- Process Resources that are direct children of this Operation
6429 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling OPERATION_RESOURCES from WO_OPERATIONS') ; END IF ;
6430 
6431         l_out_eam_res_tbl           := l_eam_res_tbl;
6432         l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
6433         l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
6434 
6435 
6436 
6437         OPERATION_RESOURCES
6438         (  p_validation_level              =>  p_validation_level
6439         ,  p_wip_entity_id                 =>  l_eam_op_rec.wip_entity_id
6440         ,  p_organization_id               =>  l_eam_op_rec.organization_id
6441         ,  p_operation_seq_num             =>  l_eam_op_rec.operation_seq_num
6442         ,  p_eam_res_tbl                   =>  l_eam_res_tbl
6443         ,  p_eam_res_inst_tbl              =>  l_eam_res_inst_tbl
6444         ,  p_eam_res_usage_tbl             =>  l_eam_res_usage_tbl
6445         ,  x_eam_res_tbl                   =>  l_out_eam_res_tbl
6446         ,  x_eam_res_inst_tbl              =>  l_out_eam_res_inst_tbl
6447         ,  x_eam_res_usage_tbl             =>  l_out_eam_res_usage_tbl
6448 	,  x_schedule_wo                   =>  x_schedule_wo
6449 	,  x_bottomup_scheduled		   =>  x_bottomup_scheduled
6450         ,  x_mesg_token_tbl                =>  l_mesg_token_tbl
6451         ,  x_return_status                 =>  l_return_status
6452         );
6453 
6454         l_eam_res_tbl           := l_out_eam_res_tbl;
6455         l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
6456         l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
6457 
6458    IF l_return_status in ('Q', 'U')
6459    THEN
6460       x_return_status := l_return_status;
6461       RETURN ;
6462    ELSIF NVL(l_return_status, 'S') <> 'S'
6463    THEN
6464       x_return_status     := l_return_status;
6465    END IF;
6466 
6467 
6468       -- Process Sub Resource that are direct children of this operation
6469 
6470 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling SUB_RESOURCES from WO_OPERATIONS') ; END IF ;
6471 
6472         l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
6473         l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
6474 
6475       /*  SUB_RESOURCES
6476         (  p_validation_level              =>  p_validation_level
6477         ,  p_wip_entity_id                 =>  l_eam_op_rec.wip_entity_id
6478         ,  p_organization_id               =>  l_eam_op_rec.organization_id
6479         ,  p_operation_seq_num             =>  l_eam_op_rec.operation_seq_num
6480         ,  p_eam_sub_res_tbl               =>  l_eam_sub_res_tbl
6481         ,  p_eam_res_usage_tbl             =>  l_eam_res_usage_tbl
6482 	,  x_bottomup_scheduled		   =>  x_bottomup_scheduled
6483         ,  x_eam_sub_res_tbl               =>  l_out_eam_sub_res_tbl
6484         ,  x_eam_res_usage_tbl             =>  l_out_eam_res_usage_tbl
6485         ,  x_mesg_token_tbl                =>  l_mesg_token_tbl
6486         ,  x_return_status                 =>  l_return_status
6487         ); */
6488 
6489         l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
6490         l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
6491 
6492    IF l_return_status in ('Q', 'U')
6493    THEN
6494       x_return_status := l_return_status;
6495       RETURN ;
6496    ELSIF NVL(l_return_status, 'S') <> 'S'
6497    THEN
6498       x_return_status     := l_return_status;
6499    END IF;
6500 
6501 
6502       -- Process Material requirements that are direct children of this Operation
6503 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling MATERIAL_REQUIREMENTS from WO_OPERATIONS') ; END IF ;
6504 
6505         l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
6506 
6507         MATERIAL_REQUIREMENTS
6508         (  p_validation_level              =>  p_validation_level
6509         ,  p_wip_entity_id                 =>  l_eam_op_rec.wip_entity_id
6510         ,  p_organization_id               =>  l_eam_op_rec.organization_id
6511         ,  p_operation_seq_num             =>  l_eam_op_rec.operation_seq_num
6512         ,  p_department_id                 =>  l_eam_op_rec.department_id
6513         ,  p_eam_mat_req_tbl               =>  l_eam_mat_req_tbl
6514 	,  x_material_shortage		   =>  x_material_shortage
6515         ,  x_eam_mat_req_tbl               =>  l_out_eam_mat_req_tbl
6516         ,  x_mesg_token_tbl                =>  l_mesg_token_tbl
6517         ,  x_return_status                 =>  l_return_status
6518         );
6519 
6520         l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
6521 
6522 
6523    IF l_return_status in ('Q', 'U')
6524    THEN
6525       x_return_status := l_return_status;
6526       RETURN ;
6527    ELSIF NVL(l_return_status, 'S') <> 'S'
6528    THEN
6529       x_return_status     := l_return_status;
6530    END IF;
6531 
6532 
6533 
6534 
6535       -- Process Direct Items that are direct children of this Operation
6536 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling DIRECT_ITEMS
6537 from WO_OPERATIONS') ; END IF ;
6538 
6539         l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
6540 
6541         DIRECT_ITEMS
6542         (  p_validation_level              =>  p_validation_level
6543         ,  p_wip_entity_id                 =>  l_eam_op_rec.wip_entity_id
6544         ,  p_organization_id               =>  l_eam_op_rec.organization_id
6545         ,  p_operation_seq_num             =>  l_eam_op_rec.operation_seq_num
6546         ,  p_department_id                 =>  l_eam_op_rec.department_id
6547         ,  p_eam_direct_items_tbl          =>  l_eam_direct_items_tbl
6548         ,  x_eam_direct_items_tbl          =>  l_out_eam_direct_items_tbl
6549         ,  x_mesg_token_tbl                =>  l_mesg_token_tbl
6550         ,  x_return_status                 =>  l_return_status
6551 	,  x_material_shortage		   =>  x_material_shortage
6552         );
6553 
6554         l_eam_direct_items_tbl       := l_out_eam_direct_items_tbl;
6555 
6556 
6557    IF l_return_status in ('Q', 'U')
6558    THEN
6559       x_return_status := l_return_status;
6560       RETURN ;
6561    ELSIF NVL(l_return_status, 'S') <> 'S'
6562    THEN
6563       x_return_status     := l_return_status;
6564    END IF;
6565 
6566 
6567 
6568    END IF;   -- Process children
6569 
6570 
6571    END LOOP; -- END Operation processing loop
6572 
6573 
6574    --  Load OUT parameters
6575    IF NVL(l_return_status, 'S') <> 'S'
6576    THEN
6577       x_return_status     := l_return_status;
6578    END IF;
6579 
6580         x_Mesg_Token_Tbl               := l_Mesg_Token_Tbl;
6581         x_eam_op_tbl                   := l_eam_op_tbl;
6582         x_eam_op_network_tbl           := l_eam_op_network_tbl;
6583         x_eam_res_tbl                  := l_eam_res_tbl;
6584         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
6585         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
6586         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
6587         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
6588         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
6589 
6590 END WO_OPERATIONS;
6591 
6592 
6593 
6594 
6595 
6596 
6597 
6598 
6599 
6600 
6601 
6602 
6603 
6604 
6605 PROCEDURE WORK_ORDER
6606          ( p_validation_level        IN  NUMBER
6607          , p_eam_wo_rec              IN EAM_PROCESS_WO_PUB.eam_wo_rec_type
6608 	 , p_wip_entity_id           IN  NUMBER
6609          , p_eam_op_tbl              IN EAM_PROCESS_WO_PUB.eam_op_tbl_type
6610          , p_eam_op_network_tbl      IN EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
6611          , p_eam_res_tbl             IN EAM_PROCESS_WO_PUB.eam_res_tbl_type
6612          , p_eam_res_inst_tbl        IN EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
6613          , p_eam_sub_res_tbl         IN EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
6614          , p_eam_res_usage_tbl       IN EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
6615          , p_eam_mat_req_tbl         IN EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
6616          , p_eam_direct_items_tbl         IN EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
6617          , x_eam_wo_rec              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_rec_type
6618          , x_eam_op_tbl              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_tbl_type
6619          , x_eam_op_network_tbl      OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
6620          , x_eam_res_tbl             OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_tbl_type
6621          , x_eam_res_inst_tbl        OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
6622          , x_eam_sub_res_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
6623          , x_eam_res_usage_tbl       OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
6624          , x_eam_mat_req_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
6625          , x_eam_direct_items_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
6626 	 , x_schedule_wo             IN OUT NOCOPY NUMBER
6627  	 , x_bottomup_scheduled      IN OUT NOCOPY NUMBER
6628   	 , x_material_shortage       IN OUT NOCOPY NUMBER
6629          , x_mesg_token_tbl          OUT NOCOPY EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type
6630          , x_return_status           OUT NOCOPY VARCHAR2
6631          )
6632 IS
6633         l_api_version_number    CONSTANT NUMBER := 1.0;
6634         l_api_name              CONSTANT VARCHAR2(30):= 'EAM_PROCESS_WO_PVT';
6635         l_err_text              VARCHAR2(240);
6636 
6637         l_eam_wo_rec            EAM_PROCESS_WO_PUB.eam_wo_rec_type;
6638         l_old_eam_wo_rec        EAM_PROCESS_WO_PUB.eam_wo_rec_type;
6639         l_eam_op_tbl            EAM_PROCESS_WO_PUB.eam_op_tbl_type         :=p_eam_op_tbl;
6640         l_eam_op_network_tbl    EAM_PROCESS_WO_PUB.eam_op_network_tbl_type :=p_eam_op_network_tbl;
6641         l_eam_res_tbl           EAM_PROCESS_WO_PUB.eam_res_tbl_type        :=p_eam_res_tbl;
6642         l_eam_res_inst_tbl      EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type   :=p_eam_res_inst_tbl;
6643         l_eam_sub_res_tbl       EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type    :=p_eam_sub_res_tbl;
6644         l_eam_res_usage_tbl     EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type  :=p_eam_res_usage_tbl;
6645         l_eam_mat_req_tbl       EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type    :=p_eam_mat_req_tbl;
6646         l_eam_direct_items_tbl       EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type    :=p_eam_direct_items_tbl;
6647 
6648         -- baroy - added for making the NOCOPY changes
6649         l_out_eam_wo_rec                 EAM_PROCESS_WO_PUB.eam_wo_rec_type;
6650         l_out_eam_op_tbl                 EAM_PROCESS_WO_PUB.eam_op_tbl_type;
6651         l_out_eam_op_network_tbl         EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
6652         l_out_eam_res_tbl                EAM_PROCESS_WO_PUB.eam_res_tbl_type;
6653         l_out_eam_res_inst_tbl           EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
6654         l_out_eam_sub_res_tbl            EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
6655         l_out_eam_res_usage_tbl          EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
6656         l_out_eam_mat_req_tbl            EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
6657         l_out_eam_direct_items_tbl            EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
6658 
6659 
6660         l_mesg_token_tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
6661         l_out_mesg_token_tbl             EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
6662         l_other_message         VARCHAR2(20000);
6663         l_other_token_tbl       EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type;
6664 
6665         l_error_text            VARCHAR2(2000);
6666         l_valid_transaction     BOOLEAN := TRUE;
6667         l_return_status         VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
6668         l_pick_return_status    VARCHAR2(1) := FND_API.G_RET_STS_SUCCESS;
6669         l_msg_count             NUMBER := 0;
6670 
6671         l_bo_return_status      VARCHAR2(1) := 'S';
6672         l_return_value          NUMBER;
6673         l_token_tbl             EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type;
6674 
6675         EXC_ERR_PVT_API_MAIN    EXCEPTION;
6676         POPULATE_RELEASE_ERR         EXCEPTION;
6677         G_ERR_STATUS_CHANGE          EXCEPTION;
6678 
6679         l_start_date		date;
6680         l_completion_date	date;
6681 	l_firm_planned_flag     NUMBER;
6682 	l_wip_entity_id		NUMBER;
6683 	l_request_id		NUMBER;
6684 	l_errbuf		VARCHAR2(2000) ;
6685 	l_retcode		NUMBER := 0;
6686 	l_workflow_enabled VARCHAR2(1);
6687 	l_status_pending_event VARCHAR2(240);
6688 	l_approval_required     BOOLEAN;
6689 	l_pending_workflow_name              VARCHAR2(100);
6690 	l_pending_workflow_process           VARCHAR2(200);
6691 	 l_pending_flag   VARCHAR2(1);
6692 	 l_new_system_status         NUMBER;
6693 	l_msg_data		VARCHAR2(2000);
6694 	x_shortage_exists	VARCHAR2(1);
6695         l_current_status        NUMBER;
6696 	l_serial_number         VARCHAR2(30);
6697 	l_inv_item_id           NUMBER;
6698 	l_org_id                NUMBER;
6699 	l_eam_wo_comp_rebuild_tbl EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type;
6700 
6701 	l_count number :=0;
6702 	l_min_open_period_date         DATE;
6703 
6704 BEGIN
6705 
6706    x_return_status := FND_API.G_RET_STS_SUCCESS;
6707    l_wip_entity_id:=p_wip_entity_id;
6708 
6709    -- baroy - Skip the header validations if header is null
6710    -- If condition #101
6711    IF p_eam_wo_rec.transaction_type is not null then
6712 
6713     -- Begin block that processes header.
6714     -- This block holds the exception handlers for header errors.
6715 
6716 
6717    l_status_pending_event               :=      'oracle.apps.eam.workorder.status.change.pending';
6718    l_approval_required := FALSE;      --set the flag to 'false' initially
6719 
6720 
6721     BEGIN
6722 
6723         --  Load entity and record-specific details into system_information record
6724 
6725         l_eam_wo_rec            := p_eam_wo_rec;
6726 
6727         IF l_eam_wo_rec.return_status IS NOT NULL AND
6728            l_eam_wo_rec.return_status <> FND_API.G_MISS_CHAR
6729         THEN
6730                 x_return_status                := l_return_status;
6731                 x_eam_wo_rec                   := l_eam_wo_rec;
6732                 x_eam_op_tbl                   := l_eam_op_tbl;
6733                 x_eam_op_network_tbl           := l_eam_op_network_tbl;
6734                 x_eam_res_tbl                  := l_eam_res_tbl;
6735                 x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
6736                 x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
6737                 x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
6738                 x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
6739                 x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
6740                 RETURN;
6741         END IF;
6742 
6743         l_return_status := FND_API.G_RET_STS_SUCCESS;
6744         l_eam_wo_rec.return_status := FND_API.G_RET_STS_SUCCESS;
6745 
6746 
6747 IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Work Order: Transaction Type Validity . . . ');  END IF;
6748 
6749         VALIDATE_TRANSACTION_TYPE
6750         (   p_transaction_type  => l_eam_wo_rec.transaction_type
6751         ,   p_entity_name       => 'WORK_ORDER'
6752         ,   p_entity_id         => l_eam_wo_rec.wip_entity_name
6753         ,   x_valid_transaction => l_valid_transaction
6754         ,   x_mesg_token_tbl    => l_Mesg_Token_Tbl
6755         );
6756 
6757         IF NOT l_valid_transaction
6758         THEN
6759             l_return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
6760             RAISE EXC_SEV_QUIT_RECORD;
6761         END IF;
6762 
6763 IF GET_DEBUG = 'Y' THEN   EAM_ERROR_MESSAGE_PVT.Write_Debug('EAM WO: Check Existence . . .');  END IF;
6764 
6765             EAM_WO_VALIDATE_PVT.Check_Existence
6766             ( p_eam_wo_rec             => l_eam_wo_rec
6767             , x_old_eam_wo_rec         => l_old_eam_wo_rec
6768             , x_Mesg_Token_Tbl         => l_Mesg_Token_Tbl
6769             , x_return_status          => l_Return_Status
6770              );
6771 
6772         IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
6773         THEN
6774             l_other_message := 'EAM_WO_EXS_SEV_ERROR';
6775             l_other_token_tbl(1).token_name := 'WIP_ENTITY_NAME';
6776             l_other_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_name;
6777             RAISE EXC_SEV_QUIT_BRANCH;
6778         ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
6779         THEN
6780             l_other_message := 'EAM_WO_EXS_UNEXP_SKIP';
6781             l_other_token_tbl(1).token_name := 'WIP_ENTITY_NAME';
6782             l_other_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_name;
6783             RAISE EXC_UNEXP_SKIP_OBJECT;
6784         END IF;
6785 
6786         /* Assign the correct transaction type for SYNC operations */
6787 
6788         IF l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_SYNC THEN
6789            l_eam_wo_rec.transaction_type := l_old_eam_wo_rec.transaction_type;
6790         END IF;
6791 
6792               --Changes for IB
6793        --If this is a work order on a predefined rebuild, create an instance for it NOW
6794        --If this is a automatic rebuild work order and the serial number has just been provided, update NOW
6795 
6796           IF ((l_eam_wo_rec.rebuild_serial_number is not null and l_eam_wo_rec.rebuild_serial_number <> FND_API.G_MISS_CHAR )or l_eam_wo_rec.asset_number is not null ) then
6797                 select msn.current_status
6798                 into l_current_status
6799                 from mtl_serial_numbers msn
6800                 where inventory_item_id = nvl(l_eam_wo_rec.rebuild_item_id, l_eam_wo_rec.asset_group_id)
6801                 and serial_number = nvl(l_eam_wo_rec.rebuild_serial_number, l_eam_wo_rec.asset_number);
6802 
6803                 IF (l_current_status = 1 OR l_eam_wo_rec.maintenance_object_type = 2) THEN
6804 IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('EAM WO:  Calling CREATE_ASSET procedure . . .'); END IF;
6805                         EAM_COMMON_UTILITIES_PVT.CREATE_ASSET(
6806                          P_API_VERSION              => 1.0
6807                         ,P_INIT_MSG_LIST            => fnd_api.g_false
6808                         ,P_COMMIT                   => fnd_api.g_false
6809                         ,P_VALIDATION_LEVEL        => fnd_api.g_valid_level_full
6810                         ,X_EAM_WO_REC               => l_eam_wo_rec
6811                         ,X_RETURN_STATUS            => l_return_status
6812                         ,X_MSG_COUNT                => l_msg_count
6813                         ,X_MSG_DATA                 => l_error_text
6814                );
6815 
6816                IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) then
6817                 l_other_message := 'EAM_IB_INST_FAILED';
6818             	l_other_token_tbl(1).token_name := 'WIP_ENTITY_NAME';
6819             	l_other_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_name;
6820             	RAISE EXC_UNEXP_SKIP_OBJECT;
6821 
6822                END IF;
6823 
6824                 END IF;
6825 
6826        END IF;
6827 
6828 
6829         IF l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE THEN
6830 	      x_material_shortage := G_MATERIAL_UPDATE;
6831 	END IF;
6832 
6833         IF l_eam_wo_rec.Transaction_Type IN (EAM_PROCESS_WO_PVT.G_OPR_UPDATE)
6834         THEN
6835 
6836 IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('EAM WO:  Populate Null Columns . . .'); END IF;
6837              l_out_eam_wo_rec := l_eam_wo_rec;
6838              EAM_WO_DEFAULT_PVT.Populate_NULL_Columns
6839                 (   p_eam_wo_rec         => l_eam_wo_rec
6840                 ,   p_old_eam_wo_rec     => l_old_eam_wo_rec
6841                 ,   x_eam_wo_rec         => l_out_eam_wo_rec
6842                 );
6843               l_eam_wo_rec := l_out_eam_wo_rec;
6844 
6845 	      IF l_eam_wo_rec.STATUS_TYPE <> l_old_eam_wo_rec.STATUS_TYPE THEN
6846 		      x_material_shortage := G_MATERIAL_UPDATE;
6847 	      END IF;
6848 
6849         END IF;
6850 
6851 
6852 IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('EAM WO: Check_Attributes_Before_Defauting ... '); END IF;
6853 
6854         EAM_WO_VALIDATE_PVT.Check_Attributes_b4_Defaulting
6855                 (   x_return_status     => l_return_status
6856                 ,   x_Mesg_Token_Tbl    => l_Mesg_Token_Tbl
6857                 ,   p_eam_wo_rec        => l_eam_wo_rec
6858                 );
6859 
6860         IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
6861         THEN
6862 
6863             IF l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
6864             THEN
6865                 l_other_message := 'EAM_WO_ATTVAL_CSEV_SKIP';
6866                 l_other_token_tbl(1).token_name := 'WIP_ENTITY_NAME';
6867                 l_other_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_name;
6868                 RAISE EXC_SEV_SKIP_BRANCH;
6869             ELSE
6870                 RAISE EXC_SEV_QUIT_RECORD;
6871             END IF;
6872 
6873         ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
6874         THEN
6875             l_other_message := 'EAM_WO_ATTVAL_UNEXP_SKIP';
6876             l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
6877             l_other_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_name;
6878             RAISE EXC_UNEXP_SKIP_OBJECT;
6879 
6880         ELSIF l_return_status ='S' AND l_Mesg_Token_Tbl.COUNT <>0
6881         THEN
6882 
6883 	    l_out_eam_wo_rec            := l_eam_wo_rec;
6884 	    l_out_eam_op_tbl            := l_eam_op_tbl;
6885 	    l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
6886 	    l_out_eam_res_tbl           := l_eam_res_tbl;
6887 	    l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
6888 	    l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
6889 	    l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
6890 	    l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
6891 	    l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
6892 	    l_out_eam_direct_items_tbl     := l_eam_direct_items_tbl;
6893             EAM_ERROR_MESSAGE_PVT.Log_Error
6894             (  p_eam_wo_rec             => l_eam_wo_rec
6895             ,  p_eam_op_tbl             => l_eam_op_tbl
6896             ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
6897             ,  p_eam_res_tbl            => l_eam_res_tbl
6898             ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
6899             ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
6900             ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
6901             ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
6902                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
6903             ,  p_mesg_token_tbl         => l_mesg_token_tbl
6904             ,  p_error_status           => 'W'
6905             ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
6906             ,  x_eam_wo_rec             => l_out_eam_wo_rec
6907             ,  x_eam_op_tbl             => l_out_eam_op_tbl
6908             ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
6909             ,  x_eam_res_tbl            => l_out_eam_res_tbl
6910             ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
6911             ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
6912             ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
6913             ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
6914                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
6915             );
6916 	    l_eam_wo_rec                := l_out_eam_wo_rec;
6917 	    l_eam_op_tbl                := l_out_eam_op_tbl;
6918 	    l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
6919 	    l_eam_res_tbl               := l_out_eam_res_tbl;
6920 	    l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
6921 	    l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
6922 	    l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
6923 	    l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
6924   	    l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
6925 
6926         END IF;
6927 
6928 IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('EAM WO: Conditional Defaulting . . .'); END IF;
6929         l_out_eam_wo_rec := l_eam_wo_rec;
6930         EAM_WO_DEFAULT_PVT.Conditional_Defaulting
6931                 (   p_eam_wo_rec        => l_eam_wo_rec
6932                 ,   x_eam_wo_rec        => l_out_eam_wo_rec
6933                 ,   x_Mesg_Token_Tbl    => l_Mesg_Token_Tbl
6934                 ,   x_return_status     => l_Return_Status
6935                 );
6936         l_eam_wo_rec := l_out_eam_wo_rec;
6937 
6938         IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
6939         THEN
6940                 IF l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
6941                 THEN
6942                     l_other_message := 'EAM_WO_CONDDEF_CSEV_SKIP';
6943                     l_other_token_tbl(1).token_name := 'WIP_ENTITY_NAME';
6944                     l_other_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_name;
6945                     RAISE EXC_SEV_SKIP_BRANCH;
6946                 ELSE
6947                     RAISE EXC_SEV_QUIT_RECORD;
6948                 END IF;
6949 
6950         ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
6951         THEN
6952                 l_other_message := 'EAM_WO_CONDDEF_UNEXP_SKIP';
6953                 l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
6954                 l_other_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_name;
6955                 RAISE EXC_UNEXP_SKIP_OBJECT;
6956         ELSIF l_return_status ='S' AND l_Mesg_Token_Tbl.COUNT <>0
6957         THEN
6958 
6959 	        l_out_eam_wo_rec            := l_eam_wo_rec;
6960                 l_out_eam_op_tbl            := l_eam_op_tbl;
6961   	        l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
6962                 l_out_eam_res_tbl           := l_eam_res_tbl;
6963                 l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
6964 	        l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
6965                 l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
6966                 l_out_eam_direct_items_tbl  := l_eam_direct_items_tbl;
6967                 l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
6968                 EAM_ERROR_MESSAGE_PVT.Log_Error
6969                 (  p_eam_wo_rec             => l_eam_wo_rec
6970                 ,  p_eam_op_tbl             => l_eam_op_tbl
6971                 ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
6972                 ,  p_eam_res_tbl            => l_eam_res_tbl
6973                 ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
6974                 ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
6975                 ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
6976                 ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
6977                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
6978                 ,  p_mesg_token_tbl         => l_mesg_token_tbl
6979                 ,  p_error_status           => 'W'
6980                 ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
6981                 ,  x_eam_wo_rec             => l_out_eam_wo_rec
6982                 ,  x_eam_op_tbl             => l_out_eam_op_tbl
6983                 ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
6984                 ,  x_eam_res_tbl            => l_out_eam_res_tbl
6985                 ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
6986                 ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
6987                 ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
6988                 ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
6989                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
6990                 );
6991 	        l_eam_wo_rec                := l_out_eam_wo_rec;
6992                 l_eam_op_tbl                := l_out_eam_op_tbl;
6993                 l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
6994                 l_eam_res_tbl               := l_out_eam_res_tbl;
6995                 l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
6996                 l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
6997                 l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
6998                 l_eam_direct_items_tbl      := l_out_eam_direct_items_tbl;
6999                 l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
7000 
7001         END IF;
7002 
7003 IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('EAM WO: Attribute Defaulting . . .'); END IF;
7004 
7005         l_out_eam_wo_rec := l_eam_wo_rec;
7006 	/* Bug # 4597756 : Store firm_planned_flag, needed if Approval is required */
7007 	l_firm_planned_flag := l_eam_wo_rec.firm_planned_flag;
7008         EAM_WO_DEFAULT_PVT.Attribute_Defaulting
7009                 (   p_eam_wo_rec        => l_eam_wo_rec
7010 		,    p_old_eam_wo_rec   =>    l_old_eam_wo_rec
7011                 ,   x_eam_wo_rec        => l_out_eam_wo_rec
7012                 ,   x_Mesg_Token_Tbl    => l_Mesg_Token_Tbl
7013                 ,   x_return_status     => l_Return_Status
7014                 );
7015              l_eam_wo_rec := l_out_eam_wo_rec;
7016 
7017         IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
7018         THEN
7019 
7020                 IF l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
7021                 THEN
7022                     l_other_message := 'EAM_WO_ATTDEF_CSEV_SKIP';
7023                     l_other_token_tbl(1).token_name := 'WIP_ENTITY_NAME';
7024                     l_other_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_name;
7025                     RAISE EXC_SEV_SKIP_BRANCH;
7026                 ELSE
7027                     RAISE EXC_SEV_QUIT_RECORD;
7028                 END IF;
7029 
7030         ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
7031         THEN
7032                 l_other_message := 'EAM_WO_ATTDEF_UNEXP_SKIP';
7033                 l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
7034                 l_other_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_name;
7035                 RAISE EXC_UNEXP_SKIP_OBJECT;
7036         ELSIF l_return_status ='S' AND l_Mesg_Token_Tbl.COUNT <>0
7037         THEN
7038 
7039 	        l_out_eam_wo_rec            := l_eam_wo_rec;
7040                 l_out_eam_op_tbl            := l_eam_op_tbl;
7041   	        l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
7042                 l_out_eam_res_tbl           := l_eam_res_tbl;
7043                 l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
7044 	        l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
7045                 l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
7046                 l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
7047                 l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
7048                 EAM_ERROR_MESSAGE_PVT.Log_Error
7049                 (  p_eam_wo_rec             => l_eam_wo_rec
7050                 ,  p_eam_op_tbl             => l_eam_op_tbl
7051                 ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
7052                 ,  p_eam_res_tbl            => l_eam_res_tbl
7053                 ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
7054                 ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
7055                 ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
7056                 ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
7057                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
7058                 ,  p_mesg_token_tbl         => l_mesg_token_tbl
7059                 ,  p_error_status           => 'W'
7060                 ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
7061                 ,  x_eam_wo_rec             => l_out_eam_wo_rec
7062                 ,  x_eam_op_tbl             => l_out_eam_op_tbl
7063                 ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
7064                 ,  x_eam_res_tbl            => l_out_eam_res_tbl
7065                 ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
7066                 ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
7067                 ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
7068                 ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
7069                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
7070                 );
7071 	       l_eam_wo_rec                := l_out_eam_wo_rec;
7072                l_eam_op_tbl                := l_out_eam_op_tbl;
7073                l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
7074                l_eam_res_tbl               := l_out_eam_res_tbl;
7075                l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
7076                l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
7077                l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
7078                l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
7079                l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
7080 
7081         END IF;
7082 
7083         EAM_WO_VALIDATE_PVT.Check_Required
7084         (  p_eam_wo_rec        => l_eam_wo_rec
7085         ,  x_return_status     => l_return_status
7086         ,  x_Mesg_Token_Tbl    => l_Mesg_Token_Tbl
7087          );
7088 
7089         IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
7090         THEN
7091 
7092             IF l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
7093             THEN
7094                 l_other_message := 'EAM_WO_CONREQ_CSEV_SKIP';
7095                 l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
7096                 l_other_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_name;
7097                 RAISE EXC_SEV_SKIP_BRANCH;
7098 
7099             ELSE
7100                 RAISE EXC_SEV_QUIT_RECORD;
7101             END IF;
7102 
7103         ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
7104         THEN
7105 
7106         l_other_message := 'EAM_WO_CONREQ_UNEXP_SKIP';
7107         l_other_token_tbl(1).token_name := 'WIP_ENTITY_NAME';
7108         l_other_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_name;
7109         RAISE EXC_UNEXP_SKIP_OBJECT;
7110 
7111         ELSIF l_return_status ='S' AND l_Mesg_Token_Tbl.COUNT <>0
7112         THEN
7113 
7114 	 l_out_eam_wo_rec            := l_eam_wo_rec;
7115          l_out_eam_op_tbl            := l_eam_op_tbl;
7116   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
7117          l_out_eam_res_tbl           := l_eam_res_tbl;
7118          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
7119 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
7120          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
7121          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
7122          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
7123             EAM_ERROR_MESSAGE_PVT.Log_Error
7124             (  p_eam_wo_rec             => l_eam_wo_rec
7125             ,  p_eam_op_tbl             => l_eam_op_tbl
7126             ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
7127             ,  p_eam_res_tbl            => l_eam_res_tbl
7128             ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
7129             ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
7130             ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
7131             ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
7132                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
7133             ,  p_mesg_token_tbl         => l_mesg_token_tbl
7134             ,  p_error_status           => 'W'
7135             ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
7136             ,  x_eam_wo_rec             => l_out_eam_wo_rec
7137             ,  x_eam_op_tbl             => l_out_eam_op_tbl
7138             ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
7139             ,  x_eam_res_tbl            => l_out_eam_res_tbl
7140             ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
7141             ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
7142             ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
7143             ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
7144                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
7145              );
7146 	 l_eam_wo_rec                := l_out_eam_wo_rec;
7147          l_eam_op_tbl                := l_out_eam_op_tbl;
7148          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
7149          l_eam_res_tbl               := l_out_eam_res_tbl;
7150          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
7151          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
7152          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
7153          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
7154          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
7155         END IF;
7156 
7157 IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('WO Header: Check Attributes . . .'); END IF;
7158 
7159         EAM_WO_VALIDATE_PVT.Check_Attributes
7160             (   x_return_status            => l_return_status
7161             ,   x_Mesg_Token_Tbl           => l_Mesg_Token_Tbl
7162             ,   p_eam_wo_rec               => l_eam_wo_rec
7163             ,   p_old_eam_wo_rec           => l_old_eam_wo_rec
7164             );
7165      IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
7166         THEN
7167 
7168             IF l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
7169             THEN
7170                 l_other_message := 'EAM_WO_ATTVAL_CSEV_SKIP';
7171                 l_other_token_tbl(1).token_name := 'WIP_ENTITY_NAME';
7172                 l_other_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_name;
7173                 RAISE EXC_SEV_SKIP_BRANCH;
7174             ELSE
7175                 RAISE EXC_SEV_QUIT_RECORD;
7176             END IF;
7177 
7178         ELSIF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
7179         THEN
7180             l_other_message := 'EAM_WO_ATTVAL_UNEXP_SKIP';
7181             l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
7182             l_other_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_name;
7183             RAISE EXC_UNEXP_SKIP_OBJECT;
7184 
7185         ELSIF l_return_status ='S' AND l_Mesg_Token_Tbl.COUNT <>0
7186         THEN
7187 
7188 	 l_out_eam_wo_rec            := l_eam_wo_rec;
7189          l_out_eam_op_tbl            := l_eam_op_tbl;
7190   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
7191          l_out_eam_res_tbl           := l_eam_res_tbl;
7192          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
7193 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
7194          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
7195          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
7196          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
7197             EAM_ERROR_MESSAGE_PVT.Log_Error
7198             (  p_eam_wo_rec             => l_eam_wo_rec
7199             ,  p_eam_op_tbl             => l_eam_op_tbl
7200             ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
7201             ,  p_eam_res_tbl            => l_eam_res_tbl
7202             ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
7203             ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
7204             ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
7205             ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
7206                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
7207             ,  p_mesg_token_tbl         => l_mesg_token_tbl
7208             ,  p_error_status           => 'W'
7209             ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
7210             ,  x_eam_wo_rec             => l_out_eam_wo_rec
7211             ,  x_eam_op_tbl             => l_out_eam_op_tbl
7212             ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
7213             ,  x_eam_res_tbl            => l_out_eam_res_tbl
7214             ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
7215             ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
7216             ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
7217             ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
7218                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
7219             );
7220 	 l_eam_wo_rec                := l_out_eam_wo_rec;
7221          l_eam_op_tbl                := l_out_eam_op_tbl;
7222          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
7223          l_eam_res_tbl               := l_out_eam_res_tbl;
7224          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
7225          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
7226          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
7227          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
7228          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
7229 
7230         END IF;
7231 
7232 --      Explode Activity
7233 
7234         IF (l_eam_wo_rec.asset_activity_id IS NOT NULL) and
7235            ((l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE) or
7236            (l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UPDATE and
7237   --fix for 3296919.added following condition so that activity is updateable
7238             (l_old_eam_wo_rec.asset_activity_id is null OR l_old_eam_wo_rec.asset_activity_id<>l_eam_wo_rec.asset_activity_id)))
7239         THEN
7240 
7241           IF EAM_OP_UTILITY_PVT.NUM_OF_ROW
7242              ( p_eam_op_tbl         => l_eam_op_tbl
7243              , p_wip_entity_id      => p_eam_wo_rec.wip_entity_id
7244              , p_organization_id    => p_eam_wo_rec.organization_id
7245              )
7246           THEN
7247 
7248             l_out_eam_wo_rec            := l_eam_wo_rec;
7249             l_out_eam_op_tbl            := l_eam_op_tbl;
7250             l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
7251             l_out_eam_res_tbl           := l_eam_res_tbl;
7252             l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
7253             l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
7254             l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
7255             l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
7256 
7257             EAM_EXPLODE_ACTIVITY_PVT.EXPLODE_ACTIVITY
7258             (  p_validation_level         =>  p_validation_level
7259             ,  p_eam_wo_rec               =>  l_eam_wo_rec
7260             ,  p_eam_op_tbl               =>  l_eam_op_tbl
7261             ,  p_eam_op_network_tbl       =>  l_eam_op_network_tbl
7262             ,  p_eam_res_tbl              =>  l_eam_res_tbl
7263             ,  p_eam_res_inst_tbl         =>  l_eam_res_inst_tbl
7264             ,  p_eam_sub_res_tbl          =>  l_eam_sub_res_tbl
7265             ,  p_eam_res_usage_tbl        =>  l_eam_res_usage_tbl
7266             ,  p_eam_mat_req_tbl          =>  l_eam_mat_req_tbl
7267             ,  x_eam_wo_rec               =>  l_out_eam_wo_rec
7268             ,  x_eam_op_tbl               =>  l_out_eam_op_tbl
7269             ,  x_eam_op_network_tbl       =>  l_out_eam_op_network_tbl
7270             ,  x_eam_res_tbl              =>  l_out_eam_res_tbl
7271             ,  x_eam_res_inst_tbl         =>  l_out_eam_res_inst_tbl
7272             ,  x_eam_sub_res_tbl          =>  l_out_eam_sub_res_tbl
7273             ,  x_eam_res_usage_tbl        =>  l_out_eam_res_usage_tbl
7274             ,  x_eam_mat_req_tbl          =>  l_out_eam_mat_req_tbl
7275             ,  x_mesg_token_tbl           =>  l_mesg_token_tbl
7276             ,  x_return_status            =>  l_return_status
7277             );
7278 
7279             l_eam_wo_rec            := l_out_eam_wo_rec;
7280             l_eam_op_tbl            := l_out_eam_op_tbl;
7281             l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
7282             l_eam_res_tbl           := l_out_eam_res_tbl;
7283             l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
7284             l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
7285             l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
7286             l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
7287 
7288             -- if the explosion nullified the values of activity type,
7289             -- source and cause, then use the user provided values.
7290             if l_eam_wo_rec.activity_cause is null then
7291               l_eam_wo_rec.activity_cause := p_eam_wo_rec.activity_cause;
7292             end if;
7293             if l_eam_wo_rec.activity_type is null then
7294               l_eam_wo_rec.activity_type := p_eam_wo_rec.activity_type;
7295             end if;
7296             if l_eam_wo_rec.activity_source is null then
7297               l_eam_wo_rec.activity_source := p_eam_wo_rec.activity_source;
7298             end if;
7299 
7300 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug ('Calling api to update material shortage flag') ; END IF;
7301 
7302 
7303             IF nvl(l_return_status,'S') <> 'S' THEN
7304               x_return_status := l_return_status;
7305             END IF;
7306 
7307           ELSE
7308 
7309                 IF l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE
7310                 THEN
7311                     l_other_message := 'EAM_WO_ACTEXP_CSEV_SKIP';
7312                     l_other_token_tbl(1).token_name := 'WIP_ENTITY_NAME';
7313                     l_other_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_name;
7314                     RAISE EXC_SEV_SKIP_BRANCH;
7315                 ELSE
7316                     RAISE EXC_SEV_QUIT_RECORD;
7317                 END IF;
7318 
7319           END IF;
7320 
7321         END IF;
7322 
7323 
7324 --Handle status change approval
7325 
7326       l_workflow_enabled := Is_Workflow_Enabled(l_eam_wo_rec.maintenance_object_source,
7327                                                                                          l_eam_wo_rec.organization_id);
7328 
7329        IF(l_workflow_enabled = 'Y') THEN
7330                 IF((l_eam_wo_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_CREATE )  --created
7331 		    OR (l_eam_wo_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_UPDATE  --workorder updated
7332 			     AND NVL(l_old_eam_wo_rec.pending_flag,'N') = 'N'   --old status is not pending
7333 			     --and old status is not same as new status
7334 		            AND (l_old_eam_wo_rec.status_type <>l_eam_wo_rec.status_type)
7335 			    )
7336 		    ) THEN
7337 		           IF(WF_EVENT.TEST(l_status_pending_event) <> 'NONE') THEN
7338 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug ('Calling Wkflow required check API...') ; END IF;
7339 							 EAM_WORKFLOW_DETAILS_PUB.Eam_Wf_Is_Approval_Required(p_old_wo_rec =>  l_old_eam_wo_rec,
7340 															   p_new_wo_rec  =>  l_eam_wo_rec,
7341 															   p_wip_entity_id              => NULL,
7342 															   p_new_system_status   =>   NULL,
7343 															   p_new_wo_status           =>   NULL,
7344 															   p_old_system_status      =>   NULL,
7345 															    p_old_wo_status             =>   NULL,
7346 															   x_approval_required  =>  l_approval_required,
7347 															   x_workflow_name   =>   l_pending_workflow_name,
7348 															   x_workflow_process    =>   l_pending_workflow_process
7349 															   );
7350 
7351 						IF(l_approval_required) THEN
7352 							    l_eam_wo_rec.pending_flag:='Y';   --if approval required set the pending flag and system status to previous status
7353 							    l_new_system_status :=    l_eam_wo_rec.status_type;
7354 							    l_eam_wo_rec.status_type := NVL(l_old_eam_wo_rec.status_type,17);
7355 							    /* Bug # 4597756 : revert back the firm_planned_flag */
7356 							    IF l_firm_planned_flag IS NULL OR l_firm_planned_flag = FND_API.G_MISS_NUM THEN
7357 							       l_eam_wo_rec.firm_planned_flag := 2;
7358 							    ELSE
7359 							       l_eam_wo_rec.firm_planned_flag := l_firm_planned_flag;
7360 							    END IF;
7361 						END IF;
7362 			   END IF; --end of check for status event enabled
7363 
7364 		 END IF;
7365        END IF; -- end of check for workflow enabled
7366 
7367 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug ('Writing the WO Record to database...') ; END IF;
7368 
7369         if ((l_eam_wo_rec.pm_suggested_start_date is null or
7370 		     l_eam_wo_rec.pm_suggested_start_date = FND_API.G_MISS_DATE)
7371 		    and (l_eam_wo_rec.pm_suggested_end_date is null or
7372 				 l_eam_wo_rec.pm_suggested_end_date = FND_API.G_MISS_DATE)
7373 			and l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UPDATE
7374 			) then
7375 	      select pm_suggested_start_date, pm_suggested_end_date into
7376 		    l_eam_wo_rec.pm_suggested_start_date,
7377 			l_eam_wo_rec.pm_suggested_end_date
7378 			from eam_work_order_details
7379 			where wip_entity_id = l_eam_wo_rec.wip_entity_id;
7380 	    end if;
7381 
7382         EAM_WO_UTILITY_PVT.PERFORM_WRITES
7383         (   p_eam_wo_rec            => l_eam_wo_rec
7384         ,   x_Mesg_Token_Tbl        => l_Mesg_Token_Tbl
7385         ,   x_return_status         => l_return_status
7386          );
7387 
7388         IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
7389         THEN
7390 
7391             l_other_message := 'EAM_WO_WRITES_UNEXP_SKIP';
7392             l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
7393             l_other_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_name;
7394 
7395         RAISE EXC_UNEXP_SKIP_OBJECT;
7396 
7397         ELSIF l_return_status ='S' AND l_Mesg_Token_Tbl.COUNT <>0
7398         THEN
7399 
7400 	 l_out_eam_wo_rec            := l_eam_wo_rec;
7401          l_out_eam_op_tbl            := l_eam_op_tbl;
7402   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
7403          l_out_eam_res_tbl           := l_eam_res_tbl;
7404          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
7405 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
7406          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
7407          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
7408          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
7409             EAM_ERROR_MESSAGE_PVT.Log_Error
7410             (  p_eam_wo_rec             => l_eam_wo_rec
7411             ,  p_eam_op_tbl             => l_eam_op_tbl
7412             ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
7413             ,  p_eam_res_tbl            => l_eam_res_tbl
7414             ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
7415             ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
7416             ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
7417             ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
7418                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
7419             ,  p_mesg_token_tbl         => l_mesg_token_tbl
7420             ,  p_error_status           => 'W'
7421             ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
7422             ,  x_eam_wo_rec             => l_out_eam_wo_rec
7423             ,  x_eam_op_tbl             => l_out_eam_op_tbl
7424             ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
7425             ,  x_eam_res_tbl            => l_out_eam_res_tbl
7426             ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
7427             ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
7428             ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
7429             ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
7430                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
7431             );
7432 	 l_eam_wo_rec                := l_out_eam_wo_rec;
7433          l_eam_op_tbl                := l_out_eam_op_tbl;
7434          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
7435          l_eam_res_tbl               := l_out_eam_res_tbl;
7436          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
7437          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
7438          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
7439          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
7440          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
7441 	 x_return_status := FND_API.G_RET_STS_SUCCESS;
7442 
7443         END IF;
7444 
7445 	/* Bug # 4926626 : Disable hiearchy if automatic (replaced) rebuild WO is updated
7446 	   with the Asset Number and parent WO is completed */
7447         IF (l_eam_wo_rec.parent_wip_entity_id IS NOT NULL AND
7448 	    l_eam_wo_rec.manual_rebuild_flag = 'N' AND
7449 	     l_eam_wo_rec.maintenance_object_type = 3 ) THEN
7450 
7451           IF (l_old_eam_wo_rec.maintenance_object_type = 2 AND
7452 	      l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UPDATE) THEN
7453 
7454              SELECT serial_number, inventory_item_id, last_vld_organization_id
7455   	       INTO l_serial_number, l_inv_item_id, l_org_id
7456 	       FROM csi_item_instances
7457 	      WHERE instance_id = l_eam_wo_rec.maintenance_object_id;
7458 
7459             IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug ('Calling api to endate eam genealogy') ; END IF;
7460 
7461 	     wip_eam_genealogy_pvt.update_eam_genealogy
7462 	     (
7463 		p_api_version => 1.0,
7464 		p_object_type => 2,
7465 		p_serial_number => l_serial_number,
7466 		p_inventory_item_id => l_inv_item_id,
7467 		p_organization_id => l_org_id,
7468 		p_genealogy_type => 5,
7469 		p_end_date_active => sysdate,
7470 		x_return_status => l_return_status,
7471 		x_msg_count => l_msg_count,
7472 		x_msg_data => l_msg_data
7473 	     );
7474             IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug ('Update Genealogy completed with status '||l_return_status) ; END IF;
7475 
7476 	     IF l_return_status <> 'S' THEN
7477                   IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN
7478 	            EAM_ERROR_MESSAGE_PVT.Write_Debug ('api for endating eam genealogy has errored') ;
7479 	          END IF;
7480 	 	  l_other_message := 'EAM_UPDATE_GENEALOGY_FAIL';
7481 		  RAISE EXC_SEV_QUIT_RECORD;
7482              END IF;
7483 
7484           END IF;
7485 
7486 	  IF ((l_old_eam_wo_rec.maintenance_object_type = 2 AND l_eam_wo_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_UPDATE) OR
7487 	        (l_eam_wo_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_CREATE )) THEN
7488 
7489              /* If the parent WO is complete, disable meter hierarchy and IB hierarchy */
7490 	     SELECT status_type INTO l_current_status
7491 	       FROM wip_discrete_jobs
7492 	      WHERE wip_entity_id = l_eam_wo_rec.parent_wip_entity_id;
7493 
7494              IF (l_current_status in (4, 5, 12) ) THEN
7495 
7496 		IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug ('Calling api to disable counter hierarchy') ; END IF;
7497 
7498 	        eam_meterreading_utility_pvt.disable_counter_hierarchy
7499 	        (
7500 		  p_eam_wo_comp_rebuild_tbl => l_eam_wo_comp_rebuild_tbl ,
7501 		  p_subinventory_id	  => null,
7502 		  p_wip_entity_id           => l_eam_wo_rec.parent_wip_entity_id,
7503 		  x_eam_wo_comp_rebuild_tbl => l_eam_wo_comp_rebuild_tbl,
7504 		  x_return_status           => l_return_status ,
7505 		  x_mesg_token_tbl	  => l_mesg_token_tbl
7506 	        );
7507 		IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug (' disable counter hierarchy API completed with status '||l_return_status) ; END IF;
7508 
7509 	        IF l_return_status <> 'S' THEN
7510 
7511 		  IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN
7512   	             EAM_ERROR_MESSAGE_PVT.Write_Debug ('The api to disable counter hierarchy has errored out') ;
7513    	          END IF;
7514 		  l_other_message := 'EAM_WOCMPL_DIS_COUNTER_HIER';
7515 		  l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
7516 		  l_other_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_name;
7517 		  RAISE EXC_SEV_QUIT_RECORD;
7518                 END IF;
7519 
7520                 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug ('Calling CSI api for wip completion ') ; END IF;
7521 
7522 	        csi_eam_interface_grp.wip_completion
7523 	        (
7524 		 p_wip_entity_id   => l_eam_wo_rec.parent_wip_entity_id,
7525 		 p_organization_id => l_eam_wo_rec.organization_id,
7526 		 x_return_status   => l_return_status,
7527 		 x_error_message   => l_msg_data
7528   	        );
7529                 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug ('CSI api for wip completion completed with status '||l_return_status) ; END IF;
7530 
7531 	        IF l_return_status <> 'S' THEN
7532 
7533 		  IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN
7534 	            EAM_ERROR_MESSAGE_PVT.Write_Debug ('The CSI api for wip completion has errored out') ;
7535 	          END IF;
7536 
7537 		  l_other_message := 'EAM_WOCMPL_IB_WIP_CMPL';
7538 		  l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
7539 		  l_other_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_name;
7540 		  RAISE EXC_SEV_QUIT_RECORD;
7541                 END IF;
7542 	     END IF;
7543 
7544           END IF;
7545 
7546 
7547         END IF;
7548 
7549 
7550     EXCEPTION
7551 
7552     WHEN EXC_SEV_QUIT_RECORD THEN
7553 
7554 	 l_out_eam_wo_rec            := l_eam_wo_rec;
7555          l_out_eam_op_tbl            := l_eam_op_tbl;
7556   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
7557          l_out_eam_res_tbl           := l_eam_res_tbl;
7558          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
7559 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
7560          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
7561          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
7562          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
7563         EAM_ERROR_MESSAGE_PVT.Log_Error
7564         (  p_eam_wo_rec             => l_eam_wo_rec
7565         ,  p_eam_op_tbl             => l_eam_op_tbl
7566         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
7567         ,  p_eam_res_tbl            => l_eam_res_tbl
7568         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
7569         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
7570         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
7571         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
7572                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
7573         ,  p_mesg_token_tbl         => l_mesg_token_tbl
7574         ,  p_error_status           => FND_API.G_RET_STS_ERROR
7575         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
7576         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
7577         ,  x_eam_wo_rec             => l_out_eam_wo_rec
7578         ,  x_eam_op_tbl             => l_out_eam_op_tbl
7579         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
7580         ,  x_eam_res_tbl            => l_out_eam_res_tbl
7581         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
7582         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
7583         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
7584         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
7585                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
7586         );
7587 	 l_eam_wo_rec                := l_out_eam_wo_rec;
7588          l_eam_op_tbl                := l_out_eam_op_tbl;
7589          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
7590          l_eam_res_tbl               := l_out_eam_res_tbl;
7591          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
7592          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
7593          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
7594          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
7595          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
7596 
7597 
7598         x_return_status                := l_return_status;
7599         x_mesg_token_tbl               := l_mesg_token_tbl;
7600         x_eam_wo_rec                   := l_eam_wo_rec;
7601         x_eam_op_tbl                   := l_eam_op_tbl;
7602         x_eam_op_network_tbl           := l_eam_op_network_tbl;
7603         x_eam_res_tbl                  := l_eam_res_tbl;
7604         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
7605         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
7606         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
7607         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
7608         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
7609 	RETURN;
7610 
7611     WHEN EXC_SEV_QUIT_BRANCH THEN
7612 
7613 	 l_out_eam_wo_rec            := l_eam_wo_rec;
7614          l_out_eam_op_tbl            := l_eam_op_tbl;
7615   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
7616          l_out_eam_res_tbl           := l_eam_res_tbl;
7617          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
7618 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
7619          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
7620          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
7621          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
7622         EAM_ERROR_MESSAGE_PVT.Log_Error
7623         (  p_eam_wo_rec             => l_eam_wo_rec
7624         ,  p_eam_op_tbl             => l_eam_op_tbl
7625         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
7626         ,  p_eam_res_tbl            => l_eam_res_tbl
7627         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
7628         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
7629         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
7630         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
7631                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
7632         ,  p_mesg_token_tbl         => l_mesg_token_tbl
7633         ,  p_error_status           => FND_API.G_RET_STS_ERROR
7634         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
7635         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
7636         ,  p_other_message          => l_other_message
7637         ,  p_other_token_tbl        => l_other_token_tbl
7638         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
7639         ,  x_eam_wo_rec             => l_out_eam_wo_rec
7640         ,  x_eam_op_tbl             => l_out_eam_op_tbl
7641         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
7642         ,  x_eam_res_tbl            => l_out_eam_res_tbl
7643         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
7644         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
7645         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
7646         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
7647                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
7648         );
7649 	 l_eam_wo_rec                := l_out_eam_wo_rec;
7650          l_eam_op_tbl                := l_out_eam_op_tbl;
7651          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
7652          l_eam_res_tbl               := l_out_eam_res_tbl;
7653          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
7654          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
7655          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
7656          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
7657          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
7658 
7659         x_return_status                := l_return_status;
7660         x_mesg_token_tbl               := l_mesg_token_tbl;
7661         x_eam_wo_rec                   := l_eam_wo_rec;
7662         x_eam_op_tbl                   := l_eam_op_tbl;
7663         x_eam_op_network_tbl           := l_eam_op_network_tbl;
7664         x_eam_res_tbl                  := l_eam_res_tbl;
7665         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
7666         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
7667         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
7668         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
7669         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
7670 
7671     RETURN;
7672 
7673     WHEN EXC_SEV_SKIP_BRANCH THEN
7674 
7675 	 l_out_eam_wo_rec            := l_eam_wo_rec;
7676          l_out_eam_op_tbl            := l_eam_op_tbl;
7677   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
7678          l_out_eam_res_tbl           := l_eam_res_tbl;
7679          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
7680 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
7681          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
7682          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
7683          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
7684         EAM_ERROR_MESSAGE_PVT.Log_Error
7685         (  p_eam_wo_rec             => l_eam_wo_rec
7686         ,  p_eam_op_tbl             => l_eam_op_tbl
7687         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
7688         ,  p_eam_res_tbl            => l_eam_res_tbl
7689         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
7690         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
7691         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
7692         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
7693                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
7694         ,  p_mesg_token_tbl         => l_mesg_token_tbl
7695         ,  p_error_status           => FND_API.G_RET_STS_ERROR
7696         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
7697         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
7698         ,  p_other_message          => l_other_message
7699         ,  p_other_token_tbl        => l_other_token_tbl
7700         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
7701         ,  x_eam_wo_rec             => l_out_eam_wo_rec
7702         ,  x_eam_op_tbl             => l_out_eam_op_tbl
7703         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
7704         ,  x_eam_res_tbl            => l_out_eam_res_tbl
7705         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
7706         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
7707         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
7708         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
7709                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
7710         );
7711 	 l_eam_wo_rec                := l_out_eam_wo_rec;
7712          l_eam_op_tbl                := l_out_eam_op_tbl;
7713          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
7714          l_eam_res_tbl               := l_out_eam_res_tbl;
7715          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
7716          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
7717          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
7718          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
7719          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
7720 
7721         x_return_status                := l_return_status;
7722         x_mesg_token_tbl               := l_mesg_token_tbl;
7723         x_eam_wo_rec                   := l_eam_wo_rec;
7724         x_eam_op_tbl                   := l_eam_op_tbl;
7725         x_eam_op_network_tbl           := l_eam_op_network_tbl;
7726         x_eam_res_tbl                  := l_eam_res_tbl;
7727         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
7728         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
7729         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
7730         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
7731         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
7732 
7733     RETURN;
7734 
7735 
7736     WHEN EXC_FAT_QUIT_OBJECT THEN
7737 
7738 	 l_out_eam_wo_rec            := l_eam_wo_rec;
7739          l_out_eam_op_tbl            := l_eam_op_tbl;
7740   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
7741          l_out_eam_res_tbl           := l_eam_res_tbl;
7742          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
7743 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
7744          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
7745          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
7746          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
7747         EAM_ERROR_MESSAGE_PVT.Log_Error
7748         (  p_eam_wo_rec             => l_eam_wo_rec
7749         ,  p_eam_op_tbl             => l_eam_op_tbl
7750         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
7751         ,  p_eam_res_tbl            => l_eam_res_tbl
7752         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
7753         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
7754         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
7755                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
7756         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
7757         ,  p_mesg_token_tbl         => l_mesg_token_tbl
7758         ,  p_error_status           => FND_API.G_RET_STS_ERROR
7759         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
7760         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
7761         ,  p_other_message          => l_other_message
7762         ,  p_other_token_tbl        => l_other_token_tbl
7763         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
7764         ,  x_eam_wo_rec             => l_out_eam_wo_rec
7765         ,  x_eam_op_tbl             => l_out_eam_op_tbl
7766         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
7767         ,  x_eam_res_tbl            => l_out_eam_res_tbl
7768         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
7769         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
7770         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
7771         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
7772                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
7773         );
7774 	 l_eam_wo_rec                := l_out_eam_wo_rec;
7775          l_eam_op_tbl                := l_out_eam_op_tbl;
7776          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
7777          l_eam_res_tbl               := l_out_eam_res_tbl;
7778          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
7779          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
7780          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
7781          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
7782          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
7783 
7784         x_return_status                := l_return_status;
7785         x_mesg_token_tbl               := l_mesg_token_tbl;
7786         x_eam_wo_rec                   := l_eam_wo_rec;
7787         x_eam_op_tbl                   := l_eam_op_tbl;
7788         x_eam_op_network_tbl           := l_eam_op_network_tbl;
7789         x_eam_res_tbl                  := l_eam_res_tbl;
7790         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
7791         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
7792         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
7793         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
7794         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
7795 
7796     l_return_status := 'Q';
7797     	RETURN;
7798 
7799     WHEN EXC_UNEXP_SKIP_OBJECT THEN
7800 
7801 	 l_out_eam_wo_rec            := l_eam_wo_rec;
7802          l_out_eam_op_tbl            := l_eam_op_tbl;
7803   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
7804          l_out_eam_res_tbl           := l_eam_res_tbl;
7805          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
7806 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
7807          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
7808          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
7809          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
7810         EAM_ERROR_MESSAGE_PVT.Log_Error
7811         (  p_eam_wo_rec             => l_eam_wo_rec
7812         ,  p_eam_op_tbl             => l_eam_op_tbl
7813         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
7814         ,  p_eam_res_tbl            => l_eam_res_tbl
7815         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
7816         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
7817         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
7818         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
7819                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
7820         ,  p_mesg_token_tbl         => l_mesg_token_tbl
7821         ,  p_error_status           => FND_API.G_RET_STS_ERROR
7822         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
7823         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
7824         ,  p_other_message          => l_other_message
7825         ,  p_other_token_tbl        => l_other_token_tbl
7826         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
7827         ,  x_eam_wo_rec             => l_out_eam_wo_rec
7828         ,  x_eam_op_tbl             => l_out_eam_op_tbl
7829         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
7830         ,  x_eam_res_tbl            => l_out_eam_res_tbl
7831         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
7832         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
7833         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
7834         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
7835                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
7836         );
7837 	 l_eam_wo_rec                := l_out_eam_wo_rec;
7838          l_eam_op_tbl                := l_out_eam_op_tbl;
7839          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
7840          l_eam_res_tbl               := l_out_eam_res_tbl;
7841          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
7842          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
7843          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
7844          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
7845          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
7846 
7847         x_return_status                := l_return_status;
7848         x_mesg_token_tbl               := l_mesg_token_tbl;
7849         x_eam_wo_rec                   := l_eam_wo_rec;
7850         x_eam_op_tbl                   := l_eam_op_tbl;
7851         x_eam_op_network_tbl           := l_eam_op_network_tbl;
7852         x_eam_res_tbl                  := l_eam_res_tbl;
7853         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
7854         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
7855         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
7856         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
7857         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
7858         	RETURN;
7859 
7860     END;
7861 
7862     END IF;
7863     -- baroy - end
7864     -- End of IF condition #101 - Skipping header level validations
7865 
7866 --  END Header processing block
7867 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('WORK_ORDER MAIN Routine compelted with status of '||l_return_status) ; END IF ;
7868 
7869     IF NVL(l_return_status,'S') <> 'S'
7870     THEN
7871         x_return_status := l_return_status;
7872         RETURN;
7873     END IF;
7874 
7875     l_bo_return_status := l_return_status;
7876 
7877 --Added to find if workorder is firm or not
7878   IF(l_wip_entity_id IS NULL) THEN     --get wip_entity_id from workorder record as it is defaulted while creating
7879      l_wip_entity_id:= l_eam_wo_rec.wip_entity_id;
7880   END IF;
7881 
7882    SELECT firm_planned_flag
7883    INTO l_firm_planned_flag
7884    FROM WIP_DISCRETE_JOBS
7885    WHERE wip_entity_id = l_wip_entity_id;
7886 
7887    IF(l_firm_planned_flag=1) OR (nvl(l_eam_wo_rec.ds_scheduled_flag,'N')='Y')THEN
7888 	--if firm set the scheduled flag as firm
7889        x_schedule_wo := G_FIRM_WORKORDER;
7890 
7891        IF l_eam_res_usage_tbl.count > 0 THEN
7892          x_bottomup_scheduled := G_UPDATE_RES_USAGE;
7893        END IF;
7894 
7895    ELSE
7896        x_bottomup_scheduled := G_NON_FIRM_WORKORDER;
7897    END IF;
7898 
7899 
7900     -- Process operations that are orphans but are indirect children of this header
7901 
7902 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling WO_OPERATIONS from WORK_ORDER') ; END IF ;
7903 
7904         l_out_eam_wo_rec            := l_eam_wo_rec;
7905         l_out_eam_op_tbl            := l_eam_op_tbl;
7906         l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
7907         l_out_eam_res_tbl           := l_eam_res_tbl;
7908         l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
7909         l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
7910         l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
7911         l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
7912         l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
7913 
7914 
7915 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Checking for standard operation from WORK_ORDER') ; END IF ;
7916 
7917 	if (l_eam_wo_rec.asset_activity_id IS NOT NULL and
7918 		(l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PUB.G_OPR_CREATE
7919 		or
7920 		l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PUB.G_OPR_UPDATE and
7921 		((l_eam_wo_rec.asset_activity_id <> l_old_eam_wo_rec.asset_activity_id) or l_old_eam_wo_rec.asset_activity_id is null)
7922 		))
7923 		then
7924 			null ;
7925 	else
7926 
7927 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Exploding standard operation from WORK_ORDER') ; END IF ;
7928 
7929 	-- Need to explode standard operations
7930 
7931 		IF l_eam_op_tbl.COUNT > 0 THEN
7932 			FOR J IN l_eam_op_tbl.FIRST..l_eam_op_tbl.LAST LOOP
7933 				IF l_eam_op_tbl(J).standard_operation_id IS NOT NULL THEN
7934 					declare
7935 
7936 						CURSOR resOP IS
7937 							select
7938 							 l_eam_op_tbl(J).wip_entity_id,
7939 							 l_eam_op_tbl(J).operation_seq_num,
7940 							 bsor.resource_seq_num,
7941 							 bso.organization_id,
7942 							 bsor.LAST_UPDATE_DATE,
7943 							 bsor.LAST_UPDATED_BY,
7944 							 bsor.CREATION_DATE,
7945 							 bsor.CREATED_BY,
7946 							 bsor.LAST_UPDATE_LOGIN,
7947 							 bsor.REQUEST_ID,
7948 							 bsor.PROGRAM_APPLICATION_ID,
7949 							 bsor.PROGRAM_ID,
7950 							 bsor.PROGRAM_UPDATE_DATE,
7951 							 bsor.RESOURCE_ID,
7952 							 br.unit_of_measure,
7953 							 bsor.BASIS_TYPE,
7954 							 bsor.USAGE_RATE_OR_AMOUNT,
7955 							 bsor.ACTIVITY_ID,
7956 							 bsor.SCHEDULE_FLAG,
7957 							 bsor.ASSIGNED_UNITS,
7958 							 DECODE(bsor.autocharge_type,1,2,4,3,2,2,3,3,2) autocharge_type,
7959 							 bsor.STANDARD_RATE_FLAG,
7960 							 0 APPLIED_RESOURCE_UNITS,
7961 							 0 APPLIED_RESOURCE_VALUE,
7962 							 nvl(l_eam_op_tbl(J).start_date,sysdate) start_date,
7963 							 nvl(l_eam_op_tbl(J).completion_date,sysdate) completion_date,
7964 							 bsor.ATTRIBUTE_CATEGORY,
7965 							 bsor.ATTRIBUTE1,
7966 							 bsor.ATTRIBUTE2,
7967 							 bsor.ATTRIBUTE3,
7968 							 bsor.ATTRIBUTE4,
7969 							 bsor.ATTRIBUTE5,
7970 							 bsor.ATTRIBUTE6,
7971 							 bsor.ATTRIBUTE7,
7972 							 bsor.ATTRIBUTE8,
7973 							 bsor.ATTRIBUTE9,
7974 							 bsor.ATTRIBUTE10,
7975 							 bsor.ATTRIBUTE11,
7976 							 bsor.ATTRIBUTE12,
7977 							 bsor.ATTRIBUTE13,
7978 							 bsor.ATTRIBUTE14,
7979 							 bsor.ATTRIBUTE15,
7980 							 bso.DEPARTMENT_ID,
7981 							 decode(bsor.SCHEDULE_FLAG,2,null,bsor.resource_seq_num)  ,
7982 							 bsor.SUBSTITUTE_GROUP_NUM
7983 							 from bom_standard_operations bso,
7984 							      bom_std_op_resources bsor,
7985 							      bom_resources br
7986 							 where bso.standard_operation_id = bsor.standard_operation_id
7987 							 and br.resource_id = bsor.resource_id
7988 							 and bso.standard_operation_id = l_eam_op_tbl(J).standard_operation_id
7989 							 and bso.organization_id = l_eam_op_tbl(J).organization_id;
7990 
7991 							l_res_cnt NUMBER ;
7992 							begin
7993 
7994 								l_res_cnt:= l_eam_res_tbl.COUNT;
7995 
7996 								  FOR resrec IN resOP LOOP
7997 
7998 									l_res_cnt:=l_res_cnt+1; --counter for resources
7999 									 l_eam_res_tbl(l_res_cnt).BATCH_ID			:= l_eam_op_tbl(J).BATCH_ID;
8000 									 l_eam_res_tbl(l_res_cnt).HEADER_ID			:= l_eam_op_tbl(J).HEADER_ID;
8001 									 l_eam_res_tbl(l_res_cnt).WIP_ENTITY_ID			:= l_eam_op_tbl(J).WIP_ENTITY_ID;
8002 									 l_eam_res_tbl(l_res_cnt).ORGANIZATION_ID		:= l_eam_op_tbl(J).ORGANIZATION_ID;
8003 									 l_eam_res_tbl(l_res_cnt).OPERATION_SEQ_NUM		:= l_eam_op_tbl(J).OPERATION_SEQ_NUM;
8004 									 l_eam_res_tbl(l_res_cnt).DEPARTMENT_ID			:= resrec.DEPARTMENT_ID;
8005 									 l_eam_res_tbl(l_res_cnt).RESOURCE_SEQ_NUM		:= resrec.RESOURCE_SEQ_NUM;
8006 									 l_eam_res_tbl(l_res_cnt).RESOURCE_ID 			:= resrec.RESOURCE_ID;
8007 									 l_eam_res_tbl(l_res_cnt).UOM_CODE 			:= resrec.UNIT_OF_MEASURE;
8008 									 l_eam_res_tbl(l_res_cnt).BASIS_TYPE 			:= resrec.BASIS_TYPE;
8009 									 l_eam_res_tbl(l_res_cnt).USAGE_RATE_OR_AMOUNT		:= resrec.USAGE_RATE_OR_AMOUNT;
8010 									 l_eam_res_tbl(l_res_cnt).ACTIVITY_ID 			:= resrec.ACTIVITY_ID;
8011 									 l_eam_res_tbl(l_res_cnt).SCHEDULED_FLAG		:= resrec.SCHEDULE_FLAG;
8012 									 l_eam_res_tbl(l_res_cnt).ASSIGNED_UNITS 		:= resrec.ASSIGNED_UNITS;
8013 									 l_eam_res_tbl(l_res_cnt).AUTOCHARGE_TYPE 		:= resrec.AUTOCHARGE_TYPE;
8014 									 l_eam_res_tbl(l_res_cnt).STANDARD_RATE_FLAG		:= resrec.STANDARD_RATE_FLAG;
8015 									 l_eam_res_tbl(l_res_cnt).APPLIED_RESOURCE_UNITS	:= resrec.APPLIED_RESOURCE_UNITS;
8016 									 l_eam_res_tbl(l_res_cnt).APPLIED_RESOURCE_VALUE	:= resrec.APPLIED_RESOURCE_VALUE;
8017 									 l_eam_res_tbl(l_res_cnt).START_DATE			:= resrec.START_DATE;
8018 									 l_eam_res_tbl(l_res_cnt).COMPLETION_DATE 		:= resrec.COMPLETION_DATE;
8019 									-- l_eam_res_tbl(l_res_cnt).SCHEDULE_SEQ_NUM 		:= resrec.SCHEDULE_SEQ_NUM;
8020 									 l_eam_res_tbl(l_res_cnt).SUBSTITUTE_GROUP_NUM		:= resrec.SUBSTITUTE_GROUP_NUM;
8021 									-- l_eam_res_tbl(l_res_cnt).REPLACEMENT_GROUP_NUM		:= resrec.REPLACEMENT_GROUP_NUM;
8022 									 l_eam_res_tbl(l_res_cnt).ATTRIBUTE_CATEGORY		:= resrec.ATTRIBUTE_CATEGORY;
8023 									 l_eam_res_tbl(l_res_cnt).ATTRIBUTE1			:= resrec.ATTRIBUTE1;
8024 									 l_eam_res_tbl(l_res_cnt).ATTRIBUTE2 			:= resrec.ATTRIBUTE2 ;
8025 									 l_eam_res_tbl(l_res_cnt).ATTRIBUTE3 			:= resrec.ATTRIBUTE3 ;
8026 									 l_eam_res_tbl(l_res_cnt).ATTRIBUTE4 			:= resrec.ATTRIBUTE4 ;
8027 									 l_eam_res_tbl(l_res_cnt).ATTRIBUTE5 			:= resrec.ATTRIBUTE5 ;
8028 									 l_eam_res_tbl(l_res_cnt).ATTRIBUTE6 			:= resrec.ATTRIBUTE6 ;
8029 									 l_eam_res_tbl(l_res_cnt).ATTRIBUTE7			:= resrec.ATTRIBUTE7 ;
8030 									 l_eam_res_tbl(l_res_cnt).ATTRIBUTE8 			:= resrec.ATTRIBUTE8 ;
8031 									 l_eam_res_tbl(l_res_cnt).ATTRIBUTE9 			:= resrec.ATTRIBUTE9 ;
8032 									 l_eam_res_tbl(l_res_cnt).ATTRIBUTE10			:= resrec.ATTRIBUTE10 ;
8033 									 l_eam_res_tbl(l_res_cnt).ATTRIBUTE11			:= resrec.ATTRIBUTE11 ;
8034 									 l_eam_res_tbl(l_res_cnt).ATTRIBUTE12			:= resrec.ATTRIBUTE12 ;
8035 									 l_eam_res_tbl(l_res_cnt).ATTRIBUTE13			:= resrec.ATTRIBUTE13 ;
8036 									 l_eam_res_tbl(l_res_cnt).ATTRIBUTE14			:= resrec.ATTRIBUTE14	;
8037 									 l_eam_res_tbl(l_res_cnt).ATTRIBUTE15			:= resrec.ATTRIBUTE15	;
8038 									 l_eam_res_tbl(l_res_cnt).RETURN_STATUS 		:= l_eam_op_tbl(J).RETURN_STATUS ;
8039 									 l_eam_res_tbl(l_res_cnt).TRANSACTION_TYPE 		:= l_eam_op_tbl(J).TRANSACTION_TYPE ;
8040 								END LOOP;
8041 							END;
8042 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Completed Exploding standard operation from WORK_ORDER') ; END IF ;
8043 
8044 				END IF;
8045 
8046 			END LOOP;
8047 		END IF;
8048 	END IF;
8049 
8050         l_out_eam_res_tbl           := l_eam_res_tbl;
8051 
8052 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling WO_OPERATIONS from WORK_ORDER') ; END IF ;
8053 
8054         WO_OPERATIONS
8055         (  p_validation_level              =>  p_validation_level
8056         ,  p_wip_entity_id                 =>  l_eam_wo_rec.wip_entity_id
8057         ,  p_organization_id               =>  l_eam_wo_rec.organization_id
8058         ,  p_eam_op_tbl                    =>  l_eam_op_tbl
8059         ,  p_eam_op_network_tbl            =>  l_eam_op_network_tbl
8060         ,  p_eam_res_tbl                   =>  l_eam_res_tbl
8061         ,  p_eam_res_inst_tbl              =>  l_eam_res_inst_tbl
8062         ,  p_eam_sub_res_tbl               =>  l_eam_sub_res_tbl
8063         ,  p_eam_res_usage_tbl             =>  l_eam_res_usage_tbl
8064         ,  p_eam_mat_req_tbl               =>  l_eam_mat_req_tbl
8065         ,  p_eam_direct_items_tbl               =>  l_eam_direct_items_tbl
8066         ,  x_eam_op_tbl                    =>  l_out_eam_op_tbl
8067         ,  x_eam_op_network_tbl            =>  l_out_eam_op_network_tbl
8068         ,  x_eam_res_tbl                   =>  l_out_eam_res_tbl
8069         ,  x_eam_res_inst_tbl              =>  l_out_eam_res_inst_tbl
8070         ,  x_eam_sub_res_tbl               =>  l_out_eam_sub_res_tbl
8071         ,  x_eam_res_usage_tbl             =>  l_out_eam_res_usage_tbl
8072         ,  x_eam_mat_req_tbl               =>  l_out_eam_mat_req_tbl
8073         ,  x_eam_direct_items_tbl               =>  l_out_eam_direct_items_tbl
8074 	,  x_schedule_wo                   =>  x_schedule_wo
8075 	,  x_bottomup_scheduled		   =>  x_bottomup_scheduled
8076 	,  x_material_shortage		   => x_material_shortage
8077         ,  x_mesg_token_tbl                =>  l_mesg_token_tbl
8078         ,  x_return_status                 =>  l_return_status
8079         );
8080 
8081         l_eam_wo_rec            := l_out_eam_wo_rec;
8082         l_eam_op_tbl            := l_out_eam_op_tbl;
8083         l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
8084         l_eam_res_tbl           := l_out_eam_res_tbl;
8085         l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
8086         l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
8087         l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
8088         l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
8089         l_eam_direct_items_tbl       := l_out_eam_direct_items_tbl;
8090 
8091 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('WO_OPERATIONS compelted with status of '||l_return_status) ; END IF ;
8092 
8093     IF l_return_status <> 'S'
8094     THEN
8095         l_bo_return_status := l_return_status;
8096     END IF;
8097 
8098 
8099         -- Process Resources
8100 
8101         IF l_eam_res_tbl.count <> 0 then
8102 
8103 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling OPERATION_RESOURCES from WORK_ORDER') ; END IF ;
8104 
8105         l_out_eam_res_tbl           := l_eam_res_tbl;
8106         l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
8107         l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
8108 
8109         OPERATION_RESOURCES
8110         (  p_validation_level              =>  p_validation_level
8111         ,  p_wip_entity_id                 =>  l_eam_wo_rec.wip_entity_id
8112         ,  p_organization_id               =>  l_eam_wo_rec.organization_id
8113         ,  p_eam_res_tbl                   =>  l_eam_res_tbl
8114         ,  p_eam_res_inst_tbl              =>  l_eam_res_inst_tbl
8115         ,  p_eam_res_usage_tbl             =>  l_eam_res_usage_tbl
8116         ,  x_eam_res_tbl                   =>  l_out_eam_res_tbl
8117         ,  x_eam_res_inst_tbl              =>  l_out_eam_res_inst_tbl
8118         ,  x_eam_res_usage_tbl             =>  l_out_eam_res_usage_tbl
8119 	,  x_schedule_wo                   =>  x_schedule_wo
8120 	,  x_bottomup_scheduled		   =>  x_bottomup_scheduled
8121         ,  x_mesg_token_tbl                =>  l_mesg_token_tbl
8122         ,  x_return_status                 =>  l_return_status
8123         );
8124 
8125         l_eam_res_tbl           := l_out_eam_res_tbl;
8126         l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
8127         l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
8128 
8129 
8130     IF l_return_status <> 'S'
8131     THEN
8132         l_bo_return_status := l_return_status;
8133     END IF;
8134 
8135 
8136 
8137 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('OPERATION_RESOURCE completed with status of '||l_return_status) ; END IF ;
8138 
8139         END IF;
8140 
8141         -- Process Material Requirements
8142 
8143         IF l_eam_mat_req_tbl.count <> 0 then
8144 
8145 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling MATERIAL_REQUIREMENTS from WORK_ORDER') ; END IF ;
8146 
8147         l_out_eam_mat_req_tbl := l_eam_mat_req_tbl;
8148 
8149         MATERIAL_REQUIREMENTS
8150         (  p_validation_level              =>  p_validation_level
8151         ,  p_wip_entity_id                 =>  l_eam_wo_rec.wip_entity_id
8152         ,  p_organization_id               =>  l_eam_wo_rec.organization_id
8153         ,  p_eam_mat_req_tbl               =>  l_eam_mat_req_tbl
8154 	,  x_material_shortage		   =>  x_material_shortage
8155         ,  x_eam_mat_req_tbl               =>  l_out_eam_mat_req_tbl
8156         ,  x_mesg_token_tbl                =>  l_mesg_token_tbl
8157         ,  x_return_status                 =>  l_return_status
8158         );
8159 
8160         l_eam_mat_req_tbl := l_out_eam_mat_req_tbl;
8161 
8162 
8163     IF l_return_status <> 'S'
8164     THEN
8165         l_bo_return_status := l_return_status;
8166     END IF;
8167 
8168 
8169 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('MATERIAL_REQUIREMENTS completed with status of '||l_return_status) ; END IF ;
8170 
8171         END IF;
8172 
8173 
8174         -- Process Direct Items
8175 
8176         IF l_eam_direct_items_tbl.count <> 0 then
8177 
8178 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling DIRECT ITEMS from WORK_ORDER') ; END IF ;
8179 
8180         l_out_eam_direct_items_tbl := l_eam_direct_items_tbl;
8181 
8182         DIRECT_ITEMS
8183         (  p_validation_level              =>  p_validation_level
8184         ,  p_wip_entity_id                 =>  l_eam_wo_rec.wip_entity_id
8185         ,  p_organization_id               =>  l_eam_wo_rec.organization_id
8186         ,  p_eam_direct_items_tbl          =>  l_eam_direct_items_tbl
8187 	,  x_material_shortage		   =>  x_material_shortage
8188         ,  x_eam_direct_items_tbl          =>  l_out_eam_direct_items_tbl
8189         ,  x_mesg_token_tbl                =>  l_mesg_token_tbl
8190         ,  x_return_status                 =>  l_return_status
8191         );
8192 
8193         l_eam_direct_items_tbl := l_out_eam_direct_items_tbl;
8194 
8195 
8196     IF l_return_status <> 'S'
8197     THEN
8198         l_bo_return_status := l_return_status;
8199     END IF;
8200 
8201 
8202 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('DIRECT_ITEMS completed with status of '||l_return_status) ; END IF ;
8203 
8204         END IF;
8205 
8206 
8207         -- Process Operation Networks
8208 
8209         IF l_eam_op_network_tbl.count <> 0 then
8210 
8211 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling OPERATION_NETWORKS from WORK_ORDER') ; END IF ;
8212 
8213         l_out_eam_op_network_tbl := l_eam_op_network_tbl;
8214 
8215         OPERATION_NETWORKS
8216         (  p_validation_level              =>  p_validation_level
8217         ,  p_wip_entity_id                 =>  l_eam_wo_rec.wip_entity_id
8218         ,  p_organization_id               =>  l_eam_wo_rec.organization_id
8219         ,  p_eam_op_network_tbl            =>  l_eam_op_network_tbl
8220         ,  x_eam_op_network_tbl            =>  l_out_eam_op_network_tbl
8221 	,  x_schedule_wo                   =>  x_schedule_wo
8222 	,  x_bottomup_scheduled		   =>  x_bottomup_scheduled
8223         ,  x_mesg_token_tbl                =>  l_mesg_token_tbl
8224         ,  x_return_status                 =>  l_return_status
8225         );
8226 
8227         l_eam_op_network_tbl := l_out_eam_op_network_tbl;
8228 
8229     IF l_return_status <> 'S'
8230     THEN
8231         l_bo_return_status := l_return_status;
8232     END IF;
8233 
8234 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('OPERATION_NETWORKS completed with status of '||l_return_status) ; END IF ;
8235 
8236         END IF;
8237 
8238 
8239     -- Process resource instance that are orphans
8240       IF l_eam_res_inst_tbl.count <> 0 then
8241 
8242         l_out_eam_res_inst_tbl := l_eam_res_inst_tbl;
8243 
8244         RESOURCE_INSTANCES
8245         (  p_validation_level              =>  p_validation_level
8246         ,  p_wip_entity_id                 =>  l_eam_wo_rec.wip_entity_id
8247         ,  p_organization_id               =>  l_eam_wo_rec.organization_id
8248         ,  p_eam_res_inst_tbl              =>  l_eam_res_inst_tbl
8249         ,  x_eam_res_inst_tbl              =>  l_out_eam_res_inst_tbl
8250         ,  x_mesg_token_tbl                =>  l_mesg_token_tbl
8251         ,  x_return_status                 =>  l_return_status
8252 	,  x_schedule_wo		   =>  x_schedule_wo
8253 	,  x_bottomup_scheduled		   =>  x_bottomup_scheduled
8254         );
8255 
8256         l_eam_res_inst_tbl := l_out_eam_res_inst_tbl;
8257 
8258 
8259     IF l_return_status <> 'S'
8260     THEN
8261         l_bo_return_status := l_return_status;
8262     END IF;
8263 
8264     END IF;
8265 
8266 
8267     -- Process substitue resource that are orphans
8268     IF l_eam_sub_res_tbl.count <> 0 then
8269 
8270         l_out_eam_sub_res_tbl   := l_eam_sub_res_tbl;
8271         l_out_eam_res_usage_tbl := l_eam_res_usage_tbl;
8272 
8273       /*  SUB_RESOURCES
8274         (  p_validation_level              =>  p_validation_level
8275         ,  p_wip_entity_id                 =>  l_eam_wo_rec.wip_entity_id
8276         ,  p_eam_sub_res_tbl               =>  l_eam_sub_res_tbl
8277         ,  p_eam_res_usage_tbl             =>  l_eam_res_usage_tbl
8278 	,  x_bottomup_scheduled		   =>  x_bottomup_scheduled
8279         ,  x_eam_sub_res_tbl               =>  l_out_eam_sub_res_tbl
8280         ,  x_eam_res_usage_tbl             =>  l_out_eam_res_usage_tbl
8281         ,  x_mesg_token_tbl                =>  l_mesg_token_tbl
8282         ,  x_return_status                 =>  l_return_status
8283         ); */
8284 
8285         l_eam_sub_res_tbl   := l_out_eam_sub_res_tbl;
8286         l_eam_res_usage_tbl := l_out_eam_res_usage_tbl;
8287 
8288     IF l_return_status <> 'S'
8289     THEN
8290         l_bo_return_status := l_return_status;
8291     END IF;
8292 
8293     END IF;
8294 
8295 BEGIN   --begin of processing workorder entity
8296     IF(nvl(l_bo_return_status,'S') = 'S'    --if successful
8297        AND l_eam_wo_rec.transaction_type IS NOT NULL) THEN    --process workorder record
8298 
8299 	   -- baroy - If wo rec is null, then don't do status change
8300            -- If condition #100
8301            IF (l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PUB.G_OPR_CREATE OR
8302                (l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PUB.G_OPR_UPDATE and
8303                 l_eam_wo_rec.status_type <> l_old_eam_wo_rec.status_type
8304                )
8305               ) then
8306 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling Change_Status API') ; END IF ;
8307 
8308               -- Defaulting the date_released only when workflow is approved /no workflow and work order is actually released.
8309 	      --Removed following code from EAMVWODB.pls and added it here
8310 
8311                IF ( (l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE and
8312                       l_eam_wo_rec.status_type = 3 ) OR
8313                      (l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UPDATE and
8314                       l_old_eam_wo_rec.status_type <> 3 and l_eam_wo_rec.status_type = 3)
8315                    )
8316                 THEN
8317 
8318 		                      IF(l_eam_wo_rec.date_released IS NULL OR
8319                                                         l_eam_wo_rec.date_released = FND_API.G_MISS_DATE) THEN
8320 
8321 									     /*Bug#4425025 - set date_released to greatest of min open period start date
8322 									      *and scheduled start date if scheduled start date is in past*/
8323 
8324 									     IF (l_eam_wo_rec.scheduled_start_date < sysdate)
8325 									     THEN
8326 																	       select nvl(min(period_start_date),l_eam_wo_rec.scheduled_start_date)
8327 																	       into l_min_open_period_date
8328 																	       from org_acct_periods
8329 																	       where organization_id=l_eam_wo_rec.organization_id
8330 																		 and open_flag = 'Y'
8331 																		 and period_close_date is null;
8332 
8333 																	       l_eam_wo_rec.date_released := greatest (l_min_open_period_date,l_eam_wo_rec.scheduled_start_date);
8334 									     ELSE
8335 																			l_eam_wo_rec.date_released := sysdate;
8336 									   END IF;
8337 					 END IF; --end of check for date_released is null
8338 
8339 		                        UPDATE WIP_DISCRETE_JOBS
8340                                                 SET date_released = l_eam_wo_rec.date_released,
8341                                                          last_update_date = SYSDATE,
8342                                                          last_updated_by = FND_GLOBAL.User_Id,
8343                                                          last_update_login = FND_GLOBAL.Login_Id
8344                                                 WHERE wip_entity_id=l_eam_wo_rec.wip_entity_id
8345                                                AND organization_id=l_eam_wo_rec.organization_id;
8346 
8347                 END IF;  --end of check for work order being released
8348 
8349 			      EAM_WO_CHANGE_STATUS_PVT.Change_Status
8350 			      (  p_api_version            => 1.0
8351 			      ,  p_init_msg_list          => null
8352 			      ,  p_commit                 => null
8353 			      ,  p_validation_level       => null
8354 			      ,  p_wip_entity_id          => l_eam_wo_rec.wip_entity_id
8355 			      ,  p_organization_id        => l_eam_wo_rec.organization_id
8356 			      ,  p_to_status_type         => l_eam_wo_rec.status_type
8357 			      ,  p_user_id                => l_eam_wo_rec.user_id
8358 			      ,  p_responsibility_id      => l_eam_wo_rec.responsibility_id
8359 			      ,  p_date_released          => l_eam_wo_rec.date_released
8360 			      ,   p_report_type              =>    l_eam_wo_rec.report_type
8361                               ,   p_actual_close_date   =>   l_eam_wo_rec.actual_close_date
8362                               , p_submission_date      =>    l_eam_wo_rec.submission_date
8363  			      ,  p_work_order_mode        => l_eam_wo_rec.transaction_type
8364 			      ,  x_request_id             => l_request_id
8365 			      ,  x_return_status          => l_return_status
8366 			      ,  x_msg_count              => l_error_text
8367 			      ,  x_msg_data               => l_other_message
8368 			      ,  x_Mesg_Token_Tbl         => l_mesg_token_tbl
8369 			      );
8370 
8371 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Status Change WO completed with status ' || l_return_status) ; END IF ;
8372 				IF NVL(l_return_status, 'S') <> 'S' THEN
8373 				       l_return_status := FND_API.G_RET_STS_ERROR;
8374 				       RAISE G_ERR_STATUS_CHANGE;
8375 
8376 				END IF;
8377 
8378 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Status Change WO completed with status ' || l_return_status) ; END IF ;
8379 
8380 
8381 	       END IF;
8382 	       -- baroy - End if for condition #100
8383 
8384 
8385 
8386 	--fix for 3572280.populate the released_quantity in the materials records from the required_quantity
8387 	BEGIN
8388 	   IF(
8389 	     (l_eam_wo_rec.transaction_type=EAM_PROCESS_WO_PUB.G_OPR_CREATE and
8390              l_eam_wo_rec.status_type = 3)
8391 	     OR
8392 	     (l_eam_wo_rec.transaction_type=EAM_PROCESS_WO_PUB.G_OPR_UPDATE and
8393 	      l_eam_wo_rec.status_type = 3 and
8394 	      ((l_old_eam_wo_rec.date_released is null and l_old_eam_wo_rec.status_type IN (17,6,7)) OR (l_old_eam_wo_rec.status_type=1)))
8395 	     )
8396 	     THEN
8397 			update wip_requirement_operations
8398 			set released_quantity=required_quantity,
8399 			       last_update_date = SYSDATE,
8400 			       last_updated_by = FND_GLOBAL.User_Id,
8401 			       last_update_login = FND_GLOBAL.Login_Id
8402 			where wip_entity_id=l_eam_wo_rec.wip_entity_id
8403 			and organization_id=l_eam_wo_rec.organization_id
8404 			and required_quantity > 0;
8405 
8406            END IF;
8407 	  EXCEPTION
8408 		     WHEN OTHERS THEN
8409 			l_return_status:='U';
8410 			RAISE POPULATE_RELEASE_ERR;
8411           END;   --end of block for populating released_quantity
8412 
8413 	-- 3521842
8414 	-- If the Auto firm on release flag = Y or user manually firms a flag while creating a Work Order
8415 	-- then if activity is associated then call schedular
8416 
8417         --if activity is added/updated/deleted for firm/non-firm workorder call scheduler
8418 	if (x_schedule_wo <> G_SCHEDULE_WO and l_eam_wo_rec.asset_activity_id IS NOT NULL and
8419 		(l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PUB.G_OPR_CREATE
8420 		or
8421 		l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PUB.G_OPR_UPDATE and
8422 		((l_eam_wo_rec.asset_activity_id <> l_old_eam_wo_rec.asset_activity_id) or l_old_eam_wo_rec.asset_activity_id is null)
8423 		))
8424 		then
8425 
8426 		x_schedule_wo := G_SCHEDULE_WO;
8427 	end if;
8428 
8429 	-- if activity is deleted then also scheduler should get call
8430 	if (x_schedule_wo <> G_SCHEDULE_WO and  l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PUB.G_OPR_UPDATE
8431 		 and l_old_eam_wo_rec.asset_activity_id is not null
8432 		 and (l_eam_wo_rec.asset_activity_id is null or l_eam_wo_rec.asset_activity_id = FND_API.G_MISS_NUM)) then
8433 		 x_schedule_wo := G_SCHEDULE_WO;
8434 	end if;
8435 
8436 
8437 
8438         IF (l_request_id is null and x_bottomup_scheduled=G_NOT_BU_SCHEDULE_WO) then  --if non-firm and not yet set to schedule
8439 
8440 			   IF(l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PUB.G_OPR_CREATE
8441 				OR
8442 				(l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PUB.G_OPR_UPDATE
8443 --				  AND l_eam_wo_rec.status_type <> 6    --status not equal to on-hold
8444 				  AND
8445 				  ((l_eam_wo_rec.requested_start_date IS NULL AND l_old_eam_wo_rec.requested_start_date IS NOT NULL) --changing from forward to backward sched
8446 				   OR (l_eam_wo_rec.requested_start_date IS NOT NULL AND l_old_eam_wo_rec.requested_start_date IS NULL) --changing from b/w to f/w sched
8447 				   OR l_eam_wo_rec.requested_start_date <> l_old_eam_wo_rec.requested_start_date  --changing dates
8448 				   OR l_eam_wo_rec.due_date <> l_old_eam_wo_rec.due_date
8449 				   OR l_eam_wo_rec.scheduled_start_date <> l_old_eam_wo_rec.scheduled_start_date
8450 				   OR l_eam_wo_rec.scheduled_completion_date <> l_old_eam_wo_rec.scheduled_completion_date
8451 				   OR (l_eam_wo_rec.firm_planned_flag=1 AND l_old_eam_wo_rec.firm_planned_flag=2 ))  --changing from firm to non-firm
8452 				)) THEN
8453 				     x_bottomup_scheduled := G_BU_SCHEDULE_WO;
8454 			    END IF;  --end of check for conditons to call bottom up scheduler
8455 
8456          END IF;
8457 
8458 
8459 	IF (l_request_id is null and x_schedule_wo=G_NOT_SCHEDULE_WO) then  --if non-firm and not yet set to schedule
8460             IF(l_eam_wo_rec.transaction_type=EAM_PROCESS_WO_PUB.G_OPR_UPDATE AND
8461 	    --if changing status to cancelled,complete-no-chrg,close do not call scheduler
8462 	        (l_eam_wo_rec.status_type IN (7,5,12,14,15)) AND (l_old_eam_wo_rec.status_type <> l_eam_wo_rec.status_type)) THEN
8463                         NULL;
8464 	    ELSIF(l_eam_wo_rec.transaction_type=EAM_PROCESS_WO_PUB.G_OPR_UPDATE AND
8465 	     --if changing status from on-hold,cancelled,complete-no-chrg,close to something else .call scheduler
8466 	        (l_old_eam_wo_rec.status_type IN (6,7,5,12,14,15)) AND (l_eam_wo_rec.status_type NOT IN (6,7,5,12,14,15))) THEN
8467 		   x_schedule_wo := G_SCHEDULE_WO;
8468             ELSE
8469 			   IF(l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PUB.G_OPR_CREATE
8470 				OR
8471 				(l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PUB.G_OPR_UPDATE
8472 				  --AND l_eam_wo_rec.status_type <> 6    --status not equal to on-hold
8473 				  AND
8474 				  ((l_eam_wo_rec.requested_start_date IS NULL AND l_old_eam_wo_rec.requested_start_date IS NOT NULL) --changing from forward to backward sched
8475 				   OR (l_eam_wo_rec.requested_start_date IS NOT NULL AND l_old_eam_wo_rec.requested_start_date IS NULL) --changing from b/w to f/w sched
8476 				   OR l_eam_wo_rec.requested_start_date <> l_old_eam_wo_rec.requested_start_date  --changing dates
8477 				   OR l_eam_wo_rec.due_date <> l_old_eam_wo_rec.due_date
8478 				   OR l_eam_wo_rec.scheduled_start_date <> l_old_eam_wo_rec.scheduled_start_date
8479 				   OR l_eam_wo_rec.scheduled_completion_date <> l_old_eam_wo_rec.scheduled_completion_date
8480 				   OR (l_eam_wo_rec.firm_planned_flag=2 AND l_old_eam_wo_rec.firm_planned_flag=1 ))  --changing from firm to non-firm
8481 				)) THEN
8482 				     x_schedule_wo := G_SCHEDULE_WO;   --3521842
8483 			    END IF;  --end of check for conditons to call scheduler
8484 
8485 
8486               END IF;
8487          END IF;
8488 
8489      /* call for cost estimator to estimate work orders created with activity */
8490 
8491         IF (  l_eam_wo_rec.asset_activity_id IS NOT NULL and l_eam_wo_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_CREATE) THEN
8492 
8493         /* Verify if there are departments, before launching cost estimation */
8494 
8495 	   Begin
8496         select 1
8497 		into l_count
8498 		from wip_operations
8499 		where wip_entity_id =  l_eam_wo_rec.wip_entity_id
8500 		and department_id is null;
8501        Exception
8502          When no_data_found then
8503             l_count := 1;
8504        End;
8505 
8506 		if l_count >=1 then
8507 		   if (l_eam_wo_rec.owning_department is null) then
8508 		   		select count(*)
8509 		   		into l_count
8510 		   		from wip_eam_parameters
8511 		   		where organization_id = l_eam_wo_rec.organization_id
8512 		   		and default_department_id is null;
8513 		   	else
8514 		   	   l_count := 0;
8515 		    end if;
8516 		end if;
8517 
8518 		if l_count >= 1 then
8519 				EAM_ERROR_MESSAGE_PVT.Write_Debug('No department on Work Order or at organization level. Skipping Estimation ') ;
8520 		else
8521 
8522 
8523 
8524                                 --Set the workorder's estimation status to 'Running' and call online cost estimation API CSTPECEP.Estimate_WorkOrder_Grp
8525                                                 UPDATE WIP_DISCRETE_JOBS
8526                                                 SET estimation_status = 2,
8527                                                          last_update_date = SYSDATE,
8528                                                          last_updated_by = FND_GLOBAL.User_Id,
8529                                                          last_update_login = FND_GLOBAL.Login_Id
8530                                                 WHERE wip_entity_id=l_eam_wo_rec.wip_entity_id
8531                                                AND organization_id=l_eam_wo_rec.organization_id;
8532 
8533                                           BEGIN
8534 		IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling the Estimate_Workorder_Grp procedure ...') ; END IF ;
8535                                                CSTPECEP.Estimate_WorkOrder_Grp(
8536                                                                  p_api_version => 1.0,
8537                                                                  p_init_msg_list => fnd_api.g_false,
8538                                                                  p_commit  =>  fnd_api.g_false,
8539                                                                  p_validation_level  => fnd_api.g_valid_level_full,
8540                                                                  p_wip_entity_id => l_eam_wo_rec.wip_entity_id,
8541                                                                  p_organization_id => l_eam_wo_rec.organization_id,
8542                                                                  x_return_status      => l_return_status,
8543                                                                  x_msg_data           => l_err_text,
8544                                                                  x_msg_count          => l_msg_count );
8545 		IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Estimate_Workorder_Grp procedure completed with status '||l_return_status) ; END IF ;
8546 
8547                                                   IF (l_return_status <> 'S') THEN
8548                                                          l_bo_return_status := l_return_status;
8549                                                   END IF;
8550                                       EXCEPTION
8551                                              WHEN OTHERS THEN
8552                                                     l_bo_return_status := FND_API.G_RET_STS_ERROR;
8553                                          END;
8554         END IF;--end of department check
8555         END IF;--end of check for activity present
8556 
8557 
8558 	--Raise workflow events
8559 	IF(l_workflow_enabled = 'Y') THEN        --if workflow is enabled
8560 		IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling the Raise_Workflow_Events procedure ...') ; END IF ;
8561 				Raise_Workflow_Events
8562 				(
8563 				     p_api_version   =>   1.0,
8564 				     p_validation_level => p_validation_level,
8565 				     p_eam_wo_rec => l_eam_wo_rec,
8566 				     p_old_eam_wo_rec => l_old_eam_wo_rec,
8567 				     p_approval_required   =>  l_approval_required,
8568 				     p_new_system_status     =>    l_new_system_status,
8569 				     p_workflow_name    =>   l_pending_workflow_name,
8570 				     p_workflow_process   =>   l_pending_workflow_process,
8571 				     x_return_status => l_return_status,
8572 				     x_mesg_token_tbl => l_mesg_token_tbl
8573 				);
8574 
8575 		IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Raise_Workflow_Events procedure completed with status '||l_return_status) ; END IF ;
8576 				IF(l_return_status <> 'S') THEN
8577 					l_bo_return_status := l_return_status;
8578 				END IF;
8579 	END IF;  --end of check for workflow enabled
8580 
8581 
8582     END IF;  --end of check for l_bo_return_status and 'S'
8583 EXCEPTION
8584    WHEN POPULATE_RELEASE_ERR THEN
8585 
8586             l_token_tbl(1).token_name  := 'WORKORDER';
8587             l_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_id;
8588 
8589             l_out_mesg_token_tbl  := l_mesg_token_tbl;
8590             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
8591             (  x_Mesg_token_tbl => l_out_Mesg_Token_Tbl
8592              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
8593              , p_message_name   => 'EAM_POPULATE_REL_ERR'
8594              , p_token_tbl      => l_token_tbl
8595              );
8596             l_mesg_token_tbl      := l_out_mesg_token_tbl;
8597 
8598             l_return_status := FND_API.G_RET_STS_ERROR;
8599 
8600          l_out_eam_wo_rec            := l_eam_wo_rec;
8601          l_out_eam_op_tbl            := l_eam_op_tbl;
8602          l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
8603          l_out_eam_res_tbl           := l_eam_res_tbl;
8604          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
8605          l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
8606          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
8607          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
8608          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
8609         EAM_ERROR_MESSAGE_PVT.Log_Error
8610         (  p_eam_wo_rec             => l_eam_wo_rec
8611         ,  p_eam_op_tbl             => l_eam_op_tbl
8612         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
8613         ,  p_eam_res_tbl            => l_eam_res_tbl
8614         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
8615         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
8616         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
8617         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
8618                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
8619         ,  p_mesg_token_tbl         => l_mesg_token_tbl
8620         ,  p_error_status           => FND_API.G_RET_STS_ERROR
8621         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
8622         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
8623         ,  p_other_message          => l_other_message
8624         ,  p_other_token_tbl        => l_other_token_tbl
8625         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
8626         ,  x_eam_wo_rec             => l_out_eam_wo_rec
8627         ,  x_eam_op_tbl             => l_out_eam_op_tbl
8628         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
8629         ,  x_eam_res_tbl            => l_out_eam_res_tbl
8630         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
8631         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
8632         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
8633         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
8634                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
8635         );
8636          l_eam_wo_rec                := l_out_eam_wo_rec;
8637          l_eam_op_tbl                := l_out_eam_op_tbl;
8638          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
8639          l_eam_res_tbl               := l_out_eam_res_tbl;
8640          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
8641          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
8642          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
8643          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
8644          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
8645 
8646         x_return_status                := l_return_status;
8647 	x_mesg_token_tbl               := l_mesg_token_tbl;
8648         x_eam_wo_rec                   := l_eam_wo_rec;
8649         x_eam_op_tbl                   := l_eam_op_tbl;
8650         x_eam_op_network_tbl           := l_eam_op_network_tbl;
8651         x_eam_res_tbl                  := l_eam_res_tbl;
8652         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
8653         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
8654         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
8655         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
8656         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
8657 	RETURN;
8658 
8659    WHEN G_ERR_STATUS_CHANGE THEN
8660 
8661 
8662             l_token_tbl(1).token_name  := 'Wip Entity Id';
8663             l_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_id;
8664 
8665             l_out_mesg_token_tbl  := l_mesg_token_tbl;
8666             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
8667             (  x_Mesg_token_tbl => l_out_Mesg_Token_Tbl
8668              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
8669              , p_message_name   => 'EAM_WO_STATUS_CHG_ERR'
8670              , p_token_tbl      => l_token_tbl
8671              );
8672             l_mesg_token_tbl      := l_out_mesg_token_tbl;
8673 
8674             l_return_status := FND_API.G_RET_STS_ERROR;
8675 
8676          l_out_eam_wo_rec            := l_eam_wo_rec;
8677          l_out_eam_op_tbl            := l_eam_op_tbl;
8678          l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
8679          l_out_eam_res_tbl           := l_eam_res_tbl;
8680          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
8681          l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
8682          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
8683          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
8684          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
8685         EAM_ERROR_MESSAGE_PVT.Log_Error
8686         (  p_eam_wo_rec             => l_eam_wo_rec
8687         ,  p_eam_op_tbl             => l_eam_op_tbl
8688         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
8689         ,  p_eam_res_tbl            => l_eam_res_tbl
8690         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
8691         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
8692         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
8693         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
8694                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
8695         ,  p_mesg_token_tbl         => l_mesg_token_tbl
8696         ,  p_error_status           => FND_API.G_RET_STS_ERROR
8697         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
8698         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
8699         ,  p_other_message          => l_other_message
8700         ,  p_other_token_tbl        => l_other_token_tbl
8701         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
8702         ,  x_eam_wo_rec             => l_out_eam_wo_rec
8703         ,  x_eam_op_tbl             => l_out_eam_op_tbl
8704         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
8705         ,  x_eam_res_tbl            => l_out_eam_res_tbl
8706         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
8707         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
8708         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
8709         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
8710                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
8711         );
8712          l_eam_wo_rec                := l_out_eam_wo_rec;
8713          l_eam_op_tbl                := l_out_eam_op_tbl;
8714          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
8715          l_eam_res_tbl               := l_out_eam_res_tbl;
8716          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
8717          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
8718          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
8719          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
8720          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
8721 
8722         x_return_status                := l_return_status;
8723 	x_mesg_token_tbl               := l_mesg_token_tbl;
8724         x_eam_wo_rec                   := l_eam_wo_rec;
8725         x_eam_op_tbl                   := l_eam_op_tbl;
8726         x_eam_op_network_tbl           := l_eam_op_network_tbl;
8727         x_eam_res_tbl                  := l_eam_res_tbl;
8728         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
8729         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
8730         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
8731         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
8732         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
8733 	RETURN;
8734 
8735 
8736 
8737 END;   --end of block for processing workorder entity
8738 
8739     --  Load OUT parameters
8740         IF nvl(l_bo_return_status,'S') <> 'S' THEN
8741           x_return_status 	       := l_bo_return_status;
8742         END IF;
8743 
8744         x_eam_wo_rec                   := l_eam_wo_rec;
8745         x_eam_op_tbl                   := l_eam_op_tbl;
8746         x_eam_op_network_tbl           := l_eam_op_network_tbl;
8747         x_eam_res_tbl                  := l_eam_res_tbl;
8748         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
8749         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
8750         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
8751         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
8752         x_eam_direct_items_tbl         := l_eam_direct_items_tbl;
8753         x_Mesg_Token_Tbl               := l_Mesg_Token_Tbl;
8754 
8755 
8756 
8757 END WORK_ORDER;
8758 
8759 
8760 
8761 
8762     /********************************************************************
8763     * Procedure: Process_WO
8764     * Parameters IN:
8765     *         EAM Work Order column record
8766     *         Operation column table
8767     *         Operation Networks column Table
8768     *         Resource column Table
8769     *         Substitute Resource column table
8770     *         Resource Usage column table
8771     *         Material Requirements column table
8772     * Parameters OUT:
8773     *         EAM Work Order column record
8774     *         Operation column table
8775     *         Operation Networks column Table
8776     *         Resource column Table
8777     *         Substitute Resource column table
8778     *         Resource Usage column table
8779     *         Material Requirements column table
8780     * Purpose:
8781     *         This procedure is the driving procedure of the EAM
8782     *         business Obect. It will verify the integrity of the
8783     *         business object and will call the private API which
8784     *         further drive the business object to perform business
8785     *         logic validations.
8786     *********************************************************************/
8787 
8788 PROCEDURE PROCESS_WO
8789          ( p_api_version_number      IN  NUMBER := 1.0
8790          , p_validation_level        IN  NUMBER := FND_API.G_VALID_LEVEL_FULL
8791          , x_return_status           OUT NOCOPY VARCHAR2
8792          , x_msg_count               OUT NOCOPY NUMBER
8793          , p_eam_wo_rec              IN EAM_PROCESS_WO_PUB.eam_wo_rec_type
8794          , p_eam_op_tbl              IN EAM_PROCESS_WO_PUB.eam_op_tbl_type
8795          , p_eam_op_network_tbl      IN EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
8796          , p_eam_res_tbl             IN EAM_PROCESS_WO_PUB.eam_res_tbl_type
8797          , p_eam_res_inst_tbl        IN EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
8798          , p_eam_sub_res_tbl         IN EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
8799          , p_eam_res_usage_tbl       IN EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
8800          , p_eam_mat_req_tbl         IN EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
8801          , p_eam_direct_items_tbl         IN EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
8802          , x_eam_wo_rec              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_rec_type
8803          , x_eam_op_tbl              OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_tbl_type
8804          , x_eam_op_network_tbl      OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_network_tbl_type
8805          , x_eam_res_tbl             OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_tbl_type
8806          , x_eam_res_inst_tbl        OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
8807          , x_eam_sub_res_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type
8808          , x_eam_res_usage_tbl       OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type
8809          , x_eam_mat_req_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
8810          , x_eam_direct_items_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type
8811          )
8812 IS
8813         l_api_version_number         CONSTANT NUMBER := 1.0;
8814         l_api_name                   CONSTANT VARCHAR2(30):= 'EAM_PROCESS_WO_PVT';
8815         l_err_text                   VARCHAR2(240);
8816         l_return_status              VARCHAR2(1);
8817 
8818         l_eam_return_status          VARCHAR2(1);
8819 
8820         l_eam_wo_rec                 EAM_PROCESS_WO_PUB.eam_wo_rec_type;
8821         l_eam_op_tbl                 EAM_PROCESS_WO_PUB.eam_op_tbl_type;
8822         l_eam_op_network_tbl         EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
8823         l_eam_res_tbl                EAM_PROCESS_WO_PUB.eam_res_tbl_type;
8824         l_eam_res_inst_tbl           EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
8825         l_eam_sub_res_tbl            EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
8826         l_eam_res_usage_tbl          EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
8827         l_eam_mat_req_tbl            EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
8828         l_eam_direct_items_tbl            EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
8829 
8830         -- baroy - added for making the NOCOPY changes
8831         l_out_eam_wo_rec                 EAM_PROCESS_WO_PUB.eam_wo_rec_type;
8832         l_out_eam_op_tbl                 EAM_PROCESS_WO_PUB.eam_op_tbl_type;
8833         l_out_eam_op_network_tbl         EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
8834         l_out_eam_res_tbl                EAM_PROCESS_WO_PUB.eam_res_tbl_type;
8835         l_out_eam_res_inst_tbl           EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
8836         l_out_eam_sub_res_tbl            EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
8837         l_out_eam_res_usage_tbl          EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
8838         l_out_eam_mat_req_tbl            EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
8839         l_out_eam_direct_items_tbl            EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
8840         l_out_mesg_token_tbl             EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
8841 
8842         l_old_eam_wo_rec                 EAM_PROCESS_WO_PUB.eam_wo_rec_type;
8843         l_scheduled                      NUMBER;
8844 		l_bottomup_scheduled             NUMBER;
8845         l_wip_entity_id                  NUMBER;
8846         l_organization_id                NUMBER;
8847 
8848         l_mesg_token_tbl             EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
8849         l_token_tbl                  EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type;
8850         l_other_message              VARCHAR2(2000);
8851         l_other_token_tbl            EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type;
8852         l_msg_count                  NUMBER := 0;
8853 
8854         EXC_ERR_PVT_API_MAIN         EXCEPTION;
8855         CHECK_WO_DATES_ERR           EXCEPTION;
8856 		CHECK_WO_RES_DATES_ERR	     EXCEPTION;
8857 		CHECK_WO_NEGATIVE_DATES_ERR  EXCEPTION;
8858      	VALIDATE_NETWORK_ERR         EXCEPTION;
8859 		OSP_REQ_ERR                  EXCEPTION;
8860 		CHECK_OP_NETWORK_DATES_ERR   EXCEPTION;
8861 		SCHEDULE_BOTTOM_UP_ERR	     EXCEPTION;
8862 		UPDATE_RES_USAGE_BU_ERR      EXCEPTION;
8863 		ALLOC_CREATION_ERR           EXCEPTION;
8864 
8865 
8866 		l_msg_data					VARCHAR2(2000);
8867 		x_shortage_exists			VARCHAR2(1);
8868         l_start_date                DATE;
8869         l_completion_date           DATE;
8870         l_error_text                NUMBER;
8871 
8872 		l_prior_op_no		       NUMBER;
8873 		l_next_op_no		       NUMBER;
8874 		l_wo_relationship_exc_tbl    EAM_PROCESS_WO_PUB.wo_relationship_exc_tbl_type;
8875 		l_material_shortage	    NUMBER;
8876 
8877 		TYPE wkorder_op_tbl_type     is TABLE OF number INDEX BY BINARY_INTEGER;
8878         TYPE wkorder_op_dt_tbl_type  is TABLE OF DATE INDEX BY BINARY_INTEGER;
8879 
8880 		l_wkorder_old_op_tbl	     wkorder_op_tbl_type;
8881 		l_wkorder_old_op_dt_tbl      wkorder_op_dt_tbl_type;
8882 
8883 		l_wkorder_new_op_tbl	     wkorder_op_tbl_type;
8884 		l_wkorder_new_op_dt_tbl      wkorder_op_dt_tbl_type;
8885 
8886   		no_of_days NUMBER;
8887 		l_wo_old_sch_start_date		DATE;
8888 		l_wo_new_sch_start_date		DATE;
8889 		l_emp_assignment		BOOLEAN;
8890 
8891 		l_res_usage_tbl_index                NUMBER;
8892                 l_woru_modified                 VARCHAR2(3);
8893                 CURSOR        get_opresource_csr( c_wip_entity_id NUMBER) IS
8894                 SELECT    start_date,
8895                           completion_date,
8896                           operation_seq_num,
8897                           resource_seq_num
8898                 FROM      wip_operation_resources
8899                 WHERE      wip_entity_id = c_wip_entity_id;
8900 
8901 
8902 BEGIN
8903 
8904 		l_wkorder_old_op_tbl.delete;
8905 		l_wkorder_old_op_dt_tbl.delete;
8906 
8907 		l_wkorder_new_op_tbl.delete;
8908 		l_wkorder_new_op_dt_tbl.delete;
8909 
8910         -- Initialize local variables
8911 
8912         l_eam_wo_rec            := p_eam_wo_rec;
8913         l_eam_op_tbl            := p_eam_op_tbl;
8914         l_eam_op_network_tbl    := p_eam_op_network_tbl;
8915         l_eam_res_tbl           := p_eam_res_tbl;
8916         l_eam_res_inst_tbl      := p_eam_res_inst_tbl;
8917         l_eam_sub_res_tbl       := p_eam_sub_res_tbl;
8918         l_eam_res_usage_tbl     := p_eam_res_usage_tbl;
8919         l_eam_mat_req_tbl       := p_eam_mat_req_tbl;
8920         l_eam_direct_items_tbl  := p_eam_direct_items_tbl;
8921 
8922 
8923         -- Business Object Starts with a status of Success
8924 
8925         l_eam_return_status     := 'S';
8926         x_return_status         := FND_API.G_RET_STS_SUCCESS;
8927 
8928 
8929         -- baroy - query the old row for use in scheduling decisions later on
8930         -- in this procedure.
8931         IF l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UPDATE THEN
8932 			  EAM_WO_UTILITY_PVT.Query_Row
8933 			  ( p_wip_entity_id       => p_eam_wo_rec.wip_entity_id
8934 			  , p_organization_id     => p_eam_wo_rec.organization_id
8935 			  , x_eam_wo_rec          => l_old_eam_wo_rec
8936 			  , x_Return_status       => l_return_status
8937 			  );
8938         END IF;
8939 
8940        -- Find out the wip_entity_id and organization_id of this BO
8941 
8942 		if l_eam_wo_rec.transaction_type is not null then
8943 				NULL;    --find wip_entity_id later after processing workorder coz it is defaulted when creating workorder
8944 		elsif l_eam_op_tbl.count <> 0 then
8945 				l_wip_entity_id   := l_eam_op_tbl(l_eam_op_tbl.first).wip_entity_id;
8946 				l_organization_id := l_eam_op_tbl(l_eam_op_tbl.first).organization_id;
8947 		elsif l_eam_op_network_tbl.count <> 0 then
8948 				l_wip_entity_id   := l_eam_op_network_tbl(l_eam_op_network_tbl.first).wip_entity_id;
8949 				l_organization_id := l_eam_op_network_tbl(l_eam_op_network_tbl.first).organization_id;
8950 		elsif l_eam_res_tbl.count <> 0 then
8951 				l_wip_entity_id   := l_eam_res_tbl(l_eam_res_tbl.first).wip_entity_id;
8952 				l_organization_id := l_eam_res_tbl(l_eam_res_tbl.first).organization_id;
8953 		elsif l_eam_mat_req_tbl.count <> 0 then
8954 				l_wip_entity_id   := l_eam_mat_req_tbl(l_eam_mat_req_tbl.first).wip_entity_id;
8955 				l_organization_id := l_eam_mat_req_tbl(l_eam_mat_req_tbl.first).organization_id;
8956 		elsif l_eam_direct_items_tbl.count <> 0 then
8957 				l_wip_entity_id   := l_eam_direct_items_tbl(l_eam_direct_items_tbl.first).wip_entity_id;
8958 				l_organization_id := l_eam_direct_items_tbl(l_eam_direct_items_tbl.first).organization_id;
8959 		elsif l_eam_res_inst_tbl.count <> 0 then
8960 				l_wip_entity_id   := l_eam_res_inst_tbl(l_eam_res_inst_tbl.first).wip_entity_id;
8961 				l_organization_id := l_eam_res_inst_tbl(l_eam_res_inst_tbl.first).organization_id;
8962 		elsif l_eam_sub_res_tbl.count <> 0 then
8963 				l_wip_entity_id   := l_eam_sub_res_tbl(l_eam_sub_res_tbl.first).wip_entity_id;
8964 				l_organization_id := l_eam_sub_res_tbl(l_eam_sub_res_tbl.first).organization_id;
8965 		elsif l_eam_res_usage_tbl.count <> 0 then
8966 				l_wip_entity_id   := l_eam_res_usage_tbl(l_eam_res_usage_tbl.first).wip_entity_id;
8967 				l_organization_id := l_eam_res_usage_tbl(l_eam_res_usage_tbl.first).organization_id;
8968 		end if;
8969 
8970 
8971 		if l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UPDATE then
8972 				l_wip_entity_id   := l_eam_wo_rec.wip_entity_id;
8973 				l_organization_id := l_eam_wo_rec.organization_id;
8974 		end if;
8975 
8976 		if l_eam_wo_rec.wip_entity_id is not  null and l_eam_wo_rec.organization_id is not null then
8977 				l_wip_entity_id   := l_eam_wo_rec.wip_entity_id;
8978 				l_organization_id := l_eam_wo_rec.organization_id;
8979 		end if;
8980 
8981 		IF l_wip_entity_id IS NOT NULL THEN
8982 				select SCHEDULED_START_DATE into l_wo_old_sch_start_date
8983 				from wip_discrete_jobs
8984 				where wip_entity_id = l_wip_entity_id;
8985 		END IF;
8986 
8987         -- Start with processing of the EAM Work Order Header
8988 
8989 		IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling WORK_ORDER from PROCESS_WO') ; END IF ;
8990 
8991 
8992 		l_out_eam_wo_rec            := l_eam_wo_rec;
8993 		l_out_eam_op_tbl            := l_eam_op_tbl;
8994 		l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
8995 		l_out_eam_res_tbl           := l_eam_res_tbl;
8996 		l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
8997 		l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
8998 		l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
8999 		l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
9000 		l_out_eam_direct_items_tbl  := l_eam_direct_items_tbl;
9001 
9002 		l_scheduled		:= G_NOT_SCHEDULE_WO;    --initialise to not calling scheduler
9003 		l_bottomup_scheduled    := G_NOT_BU_SCHEDULE_WO;    --initialise for bottom up schedular
9004 
9005 		begin
9006 				select operation_seq_num,first_unit_start_date
9007 				bulk collect into l_wkorder_old_op_tbl,l_wkorder_old_op_dt_tbl
9008 				from wip_operations
9009 				where  organization_id = l_organization_id
9010 				and  wip_entity_id = l_wip_entity_id ;
9011 		exception when others then
9012 				null;
9013 		end;
9014 
9015 		IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling the WORK_ORDER procedure...') ; END IF ;
9016 
9017 		WORK_ORDER
9018 				(  p_validation_level              =>  p_validation_level
9019 				,  p_wip_entity_id                 =>  l_wip_entity_id
9020 				,  p_eam_wo_rec                    =>  l_eam_wo_rec
9021 				,  p_eam_op_tbl                    =>  l_eam_op_tbl
9022 				,  p_eam_op_network_tbl            =>  l_eam_op_network_tbl
9023 				,  p_eam_res_tbl                   =>  l_eam_res_tbl
9024 				,  p_eam_res_inst_tbl              =>  l_eam_res_inst_tbl
9025 				,  p_eam_sub_res_tbl               =>  l_eam_sub_res_tbl
9026 				,  p_eam_res_usage_tbl             =>  l_eam_res_usage_tbl
9027 				,  p_eam_mat_req_tbl               =>  l_eam_mat_req_tbl
9028 				,  p_eam_direct_items_tbl          =>  l_eam_direct_items_tbl
9029 				,  x_eam_wo_rec                    =>  l_out_eam_wo_rec
9030 				,  x_eam_op_tbl                    =>  l_out_eam_op_tbl
9031 				,  x_eam_op_network_tbl            =>  l_out_eam_op_network_tbl
9032 				,  x_eam_res_tbl                   =>  l_out_eam_res_tbl
9033 				,  x_eam_res_inst_tbl              =>  l_out_eam_res_inst_tbl
9034 				,  x_eam_sub_res_tbl               =>  l_out_eam_sub_res_tbl
9035 				,  x_eam_res_usage_tbl             =>  l_out_eam_res_usage_tbl
9036 				,  x_eam_mat_req_tbl               =>  l_out_eam_mat_req_tbl
9037 				,  x_eam_direct_items_tbl          =>  l_out_eam_direct_items_tbl
9038 				,  x_schedule_wo                   =>  l_scheduled
9039 				,  x_bottomup_scheduled            =>  l_bottomup_scheduled
9040 				,  x_material_shortage		   =>  l_material_shortage
9041 				,  x_mesg_token_tbl                =>  l_mesg_token_tbl
9042 				,  x_return_status                 =>  l_return_status
9043 		);
9044 
9045 		l_eam_wo_rec            := l_out_eam_wo_rec;
9046 		l_eam_op_tbl            := l_out_eam_op_tbl;
9047 		l_eam_op_network_tbl    := l_out_eam_op_network_tbl;
9048 		l_eam_res_tbl           := l_out_eam_res_tbl;
9049 		l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
9050 		l_eam_sub_res_tbl       := l_out_eam_sub_res_tbl;
9051 		l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
9052 		l_eam_mat_req_tbl       := l_out_eam_mat_req_tbl;
9053 		l_eam_direct_items_tbl       := l_out_eam_direct_items_tbl;
9054 
9055 		IF NVL(l_return_status, 'S') = 'Q' THEN
9056 			l_return_status := 'F';
9057 			RAISE G_EXC_QUIT_IMPORT;
9058 
9059 		ELSIF NVL(l_return_status, 'S') = 'U' THEN
9060 			RAISE G_EXC_QUIT_IMPORT;
9061 
9062 		ELSIF NVL(l_return_status, 'S') <> 'S' THEN
9063 			l_eam_return_status := l_return_status;
9064 
9065 		END IF;
9066 
9067 
9068 		IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('WORK_ORDER completed with status of '||l_eam_return_status) ; END IF ;
9069 
9070 		if nvl(l_eam_return_status,'S') = 'S' then
9071 
9072 				IF(l_eam_wo_rec.transaction_type IS NOT NULL) THEN    -- wip_entity_id will be defaulted when creating workorder
9073 						l_wip_entity_id   := l_eam_wo_rec.wip_entity_id;
9074 						l_organization_id := l_eam_wo_rec.organization_id;
9075 				END IF;
9076 
9077 				if l_eam_wo_rec.transaction_type is null then
9078 						EAM_WO_UTILITY_PVT.Query_Row
9079 								( p_wip_entity_id       => l_wip_entity_id
9080 								, p_organization_id     => l_organization_id
9081 								, x_eam_wo_rec          => l_old_eam_wo_rec
9082 								, x_Return_status       => l_return_status
9083 								);
9084 						l_eam_wo_rec := l_old_eam_wo_rec;
9085 				end if;
9086 
9087 				--fix for 3550864.create the requisitions for newly added osp items for a workorder already in released status
9088 				if( l_eam_wo_rec.status_type = 3
9089 				and l_old_eam_wo_rec.status_type = 3
9090 				and nvl(l_eam_wo_rec.po_creation_time,2)=WIP_CONSTANTS.AT_JOB_SCHEDULE_RELEASE
9091 				) then
9092 						IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Call code to create requisitions for osp item for  already released workorder'); END IF;
9093 						EAM_RES_UTILITY_PVT.CREATE_OSP_REQ
9094 						(
9095 								p_eam_res_tbl => p_eam_res_tbl,
9096 								x_return_status => l_return_status
9097 						);
9098 
9099 						if(nvl(l_return_status,'S') <> 'S') then
9100 								l_eam_return_status := l_return_status;
9101 								RAISE OSP_REQ_ERR;
9102 						end if;
9103 				end if;
9104                                 -- flag l_woru_modified will check if resource usage records have modified or not.
9105 
9106                                 l_woru_modified := 'N' ;
9107                                 l_res_usage_tbl_index := l_eam_res_usage_tbl.FIRST ;
9108 
9109                                 WHILE  l_res_usage_tbl_index IS NOT NULL LOOP
9110 
9111                                            IF (l_eam_res_usage_tbl( l_res_usage_tbl_index ).old_start_date <> l_eam_res_usage_tbl( l_res_usage_tbl_index ).start_date  OR
9112 
9113                                               l_eam_res_usage_tbl( l_res_usage_tbl_index ).old_completion_date <> l_eam_res_usage_tbl( l_res_usage_tbl_index ).completion_date )
9114                                            THEN
9115                                            l_woru_modified := 'Y' ;
9116                                            END IF;
9117                                            l_res_usage_tbl_index := l_eam_res_usage_tbl.NEXT(l_res_usage_tbl_index);
9118                                 END LOOP;
9119 
9120 				-- WO Scheduling
9121 
9122 				--3521842   --if set to call the scheduler
9123 				-- 3780116  Change done for DS
9124 				-- do not call material shortage for CMRO
9125 				IF l_eam_wo_rec.maintenance_object_source = 1 THEN
9126 
9127 						IF l_material_shortage = G_MATERIAL_UPDATE THEN
9128 								IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling teh Check_Shortage procedure for materials ...'); END IF;
9129 								eam_material_validate_pub.Check_Shortage
9130 										(
9131 												p_api_version		=>  1.0
9132 												, x_return_status	=> l_return_status
9133 												, x_msg_count		=>  l_msg_count
9134 												, x_msg_data		=> l_msg_data
9135 												, p_wip_entity_id	=> l_eam_wo_rec.wip_entity_id
9136 												, x_shortage_exists	=> x_shortage_exists
9137 												, p_source_api		=> 'EAMVWOPB.pls'
9138 										);
9139 								begin
9140 										select material_shortage_check_date,
9141 										material_shortage_flag
9142 										into l_eam_wo_rec.material_shortage_check_date ,
9143 										l_eam_wo_rec.material_shortage_flag
9144 										from EAM_WORK_ORDER_DETAILS
9145 										where wip_entity_id = l_eam_wo_rec.wip_entity_id;
9146 								exception
9147 										when no_data_found then
9148 										null;
9149 								end ;
9150 
9151 						END IF;
9152 				END IF;
9153 
9154 				IF l_scheduled=G_SCHEDULE_WO AND NVL(l_eam_wo_rec.ds_scheduled_flag,'N')='N' THEN
9155 
9156 						IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Scheduling WO') ; END IF ;
9157 						EAM_WO_SCHEDULE_PVT.SCHEDULE_WO
9158 								(  p_organization_id               =>  l_eam_wo_rec.organization_id
9159 								,  p_wip_entity_id                 =>  l_eam_wo_rec.wip_entity_id
9160 								,  p_start_date                    =>  l_eam_wo_rec.requested_start_date
9161 								,  p_completion_date               =>  l_eam_wo_rec.due_date
9162 								,  p_validation_level              =>  null
9163 								,  p_commit                        =>  'N'
9164 								,  x_error_message                 =>  l_err_text
9165 								,  x_return_status                 =>  l_return_status
9166 								);
9167 						IF NVL(l_return_status, 'S') = 'Q' THEN
9168 								l_return_status := 'F';
9169 								RAISE G_EXC_QUIT_IMPORT;
9170 
9171 						ELSIF NVL(l_return_status, 'S') = 'U' THEN
9172 								RAISE G_EXC_QUIT_IMPORT;
9173 
9174 						ELSIF NVL(l_return_status, 'S') <> 'S' THEN
9175 								l_eam_return_status := l_return_status;
9176 
9177 						END IF;
9178 				ELSE IF    l_bottomup_scheduled IN ( G_BU_SCHEDULE_WO, G_UPDATE_RES_USAGE ) THEN
9179 
9180 						IF ( l_bottomup_scheduled = G_UPDATE_RES_USAGE ) THEN
9181 								l_out_eam_res_tbl           := l_eam_res_tbl;
9182 								l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
9183 								l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
9184 
9185 								IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling update_resource_usage for firm work orders') ; END IF ;
9186 
9187 								EAM_SCHED_BOTTOM_UP_PVT.update_resource_usage(
9188 										p_eam_res_tbl		=> l_eam_res_tbl
9189 										, p_eam_res_inst_tbl    => l_eam_res_inst_tbl
9190 										, p_eam_res_usage_tbl   => l_eam_res_usage_tbl
9191 										, x_eam_res_tbl		=> l_out_eam_res_tbl
9192 										, x_eam_res_usage_tbl   => l_out_eam_res_usage_tbl
9193 										, x_eam_res_inst_tbl    => l_out_eam_res_inst_tbl
9194 										, x_return_status       => l_return_status
9195 										, x_message_name	=> l_err_text
9196 										) ;
9197 
9198 								IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(' update_resource_usage for firm work orders returned status is ' || l_return_status ) ; END IF ;
9199 								IF NVL(l_return_status, 'T') <> 'S' THEN
9200 										l_eam_return_status := l_return_status;
9201 										l_return_status := 'E';
9202 										RAISE UPDATE_RES_USAGE_BU_ERR;
9203 								END IF;
9204 
9205 								l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl;
9206 								l_eam_res_tbl		:= l_out_eam_res_tbl;
9207 								l_eam_res_usage_tbl     := l_out_eam_res_usage_tbl;
9208 
9209 						END IF;
9210 				END IF;
9211 		END IF;
9212 
9213 		if l_scheduled = G_FIRM_WORKORDER or NVL(l_eam_wo_rec.ds_scheduled_flag,'N')= 'Y' then
9214 
9215 				IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Checking WO dates to see whether they are correctly encompassed...') ; END IF ;
9216 
9217 				EAM_WO_NETWORK_DEFAULT_PVT.Check_Wo_Dates
9218 				(
9219 						p_api_version                   => 1.0,
9220 						p_init_msg_list                 => FND_API.G_FALSE,
9221 						p_commit                        => FND_API.G_FALSE,
9222 						p_validation_level              => FND_API.G_VALID_LEVEL_FULL,
9223 
9224 						p_wip_entity_id                 => l_eam_wo_rec.wip_entity_id,
9225 
9226 						x_return_status                 => l_return_status,
9227 						x_msg_count                     => l_msg_count,
9228 						x_msg_data                      => l_err_text
9229 				);
9230 
9231 				IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check_Wo_Dates completed with status of '||l_return_status) ; END IF ;
9232 
9233 				IF NVL(l_return_status, 'T') <> 'S' THEN
9234 
9235 
9236 						IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling schedule_bottom_up_pvt for firm work orders') ; END IF ;
9237 
9238 				--Added parameter p_woru_modified to the procedure. This is done to ensure that dates are changed correctly from summary tab in Create Update WO page
9239 
9240 						EAM_SCHED_BOTTOM_UP_PVT.schedule_bottom_up_pvt (
9241 								p_api_version_number    => 1.0
9242 								, p_commit		   => FND_API.G_FALSE
9243 								, p_wip_entity_id         => l_eam_wo_rec.wip_entity_id
9244 								, p_org_id                => l_eam_wo_rec.organization_id
9245 								, p_woru_modified         => l_woru_modified
9246 								, x_return_status         => l_return_status
9247 								, x_message_name	   => l_err_text
9248 						) ;
9249 
9250 						  /*7570880 start -Fp of 7003588 for eAM Reconcilation */
9251  	             l_token_tbl(1).token_name  := 'WORK_ORDER_NAME';
9252  	             l_token_tbl(1).token_value :=  l_eam_wo_rec.wip_entity_name;
9253 
9254  	             l_out_mesg_token_tbl  := l_mesg_token_tbl;
9255  	             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
9256  	             (  x_Mesg_token_tbl => l_out_Mesg_Token_Tbl
9257  	              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
9258  	              , p_message_name   => 'EAM_SCHED_BOTTOMUP_MSG'
9259  	              , p_token_tbl      => l_token_tbl
9260  	              );
9261  	             l_mesg_token_tbl      := l_out_mesg_token_tbl;
9262 
9263  	            -- l_return_status := FND_API.G_RET_STS_ERROR;
9264 
9265  	              l_out_eam_wo_rec            := l_eam_wo_rec;
9266  	          l_out_eam_op_tbl            := l_eam_op_tbl;
9267  	          l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
9268  	          l_out_eam_res_tbl           := l_eam_res_tbl;
9269  	          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
9270  	          l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
9271  	          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
9272  	          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
9273  	          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
9274  	         EAM_ERROR_MESSAGE_PVT.Log_Error
9275  	         (  p_eam_wo_rec             => l_eam_wo_rec
9276  	         ,  p_eam_op_tbl             => l_eam_op_tbl
9277  	         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
9278  	         ,  p_eam_res_tbl            => l_eam_res_tbl
9279  	         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
9280  	         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
9281  	         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
9282  	         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
9283  	         ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
9284  	         ,  p_mesg_token_tbl         => l_mesg_token_tbl
9285  	         ,  p_error_status           => FND_API.G_RET_STS_ERROR
9286  	         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
9287  	         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
9288  	         ,  p_other_message          => l_other_message
9289  	         ,  p_other_token_tbl        => l_other_token_tbl
9290  	         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
9291  	         ,  x_eam_wo_rec             => l_out_eam_wo_rec
9292  	         ,  x_eam_op_tbl             => l_out_eam_op_tbl
9293  	         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
9294  	         ,  x_eam_res_tbl            => l_out_eam_res_tbl
9295  	         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
9296  	         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
9297  	         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
9298  	         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
9299  	         ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
9300  	         );
9301  	         /* l_eam_wo_rec                := l_out_eam_wo_rec;
9302  	          l_eam_op_tbl                := l_out_eam_op_tbl;
9303  	          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
9304  	          l_eam_res_tbl               := l_out_eam_res_tbl;
9305  	          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
9306  	          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
9307  	          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
9308  	          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
9309  	          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;         */
9310 
9311 
9312  	         l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
9313 
9314  	         x_msg_count                    := l_msg_count;
9315  	       /*  x_return_status                := l_return_status;
9316  	         x_eam_wo_rec                   := l_eam_wo_rec;
9317  	         x_eam_op_tbl                   := l_eam_op_tbl;
9318  	         x_eam_op_network_tbl           := l_eam_op_network_tbl;
9319  	         x_eam_res_tbl                  := l_eam_res_tbl;
9320  	         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
9321  	         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
9322  	         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
9323  	         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
9324  	         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;         */
9325 
9326 
9327  	             fnd_message.set_name('EAM','EAM_SCHED_BOTTOMUP_MSG');
9328 
9329 
9330  	                                                /*7570880 end -Fp of 7003588 for eAM Reconcilation */
9331 
9332 						IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(' schedule_bottom_up_pvt for firm work orders returned status is ' || l_return_status ) ; END IF ;
9333 						IF NVL(l_return_status, 'T') <> 'S' THEN
9334 								l_eam_return_status := l_return_status;
9335 								l_return_status := 'E';
9336 								RAISE SCHEDULE_BOTTOM_UP_ERR;
9337 						END IF;
9338 				END IF;
9339 		END IF;
9340 
9341 		/*l_eam_wo_rec            := l_out_eam_wo_rec;
9342 		l_eam_op_tbl            := l_out_eam_op_tbl;
9343 		l_eam_res_tbl           := l_out_eam_res_tbl;
9344 		l_eam_res_inst_tbl      := l_out_eam_res_inst_tbl; */
9345 
9346 
9347 
9348 		--find out if the assignment status has to be calculated again or not
9349 		IF((l_scheduled=G_SCHEDULE_WO) OR (l_bottomup_scheduled IN ( G_BU_SCHEDULE_WO, G_UPDATE_RES_USAGE ))
9350 		OR (l_eam_res_tbl.COUNT > 0) OR (l_eam_res_usage_tbl.COUNT > 0) OR (l_eam_res_inst_tbl.COUNT > 0)
9351 		) THEN
9352 				l_emp_assignment := TRUE;
9353 		END IF;
9354 
9355 		IF ( l_emp_assignment = TRUE ) THEN
9356 
9357 				IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Updating assignment details of an employee ') ; END IF ;
9358 
9359 				Update eam_work_order_details
9360 				set  ASSIGNMENT_COMPLETE = EAM_ASSIGN_EMP_PUB.Get_Emp_Assignment_Status(l_eam_wo_rec.wip_entity_id,l_eam_wo_rec.organization_id)
9361 				where wip_entity_id = l_eam_wo_rec.wip_entity_id;
9362 		END IF;
9363 
9364 		IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Checking Operation Network Dates... ') ; END IF ;
9365 
9366 		EAM_OP_VALIDATE_PVT.Check_Operation_Netwrok_Dates
9367 		(
9368 				p_api_version                   => 1.0,
9369 				p_init_msg_list                 => FND_API.G_FALSE,
9370 				p_commit                        => FND_API.G_FALSE,
9371 				p_validation_level              => FND_API.G_VALID_LEVEL_FULL,
9372 				p_wip_entity_id                 => l_eam_wo_rec.wip_entity_id,
9373 				x_return_status                 => l_return_status,
9374 				x_pri_operation_no              => l_prior_op_no,
9375 				x_next_operation_no             => l_next_op_no
9376 		);
9377 
9378 		IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check_Operation_Netwrok_Dates completed with status of '||l_return_status) ; END IF ;
9379 
9380 		IF NVL(l_return_status, 'T') <> 'S' THEN
9381 				l_eam_return_status := l_return_status;
9382 				l_return_status := 'E';
9383 				RAISE CHECK_OP_NETWORK_DATES_ERR;
9384 		END IF;
9385 
9386 
9387 		IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Scheduling WO completed with status ' || l_return_status) ; END IF ;
9388 
9389         -- Even for firm work orders, make sure that the work order dates
9390         -- encompass the operation dates and that the operation dates
9391         -- encompass the resource dates and that the resource dates
9392         -- encompass the resource instance dates.
9393 
9394         if l_scheduled = G_FIRM_WORKORDER then
9395 
9396 				IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling Check_Resource_Dates procedure ...') ; END IF ;
9397 
9398 				EAM_WO_NETWORK_DEFAULT_PVT.Check_Resource_Dates
9399 				(
9400 						p_api_version                   => 1.0,
9401 						p_init_msg_list                 => FND_API.G_FALSE,
9402 						p_commit                        => FND_API.G_FALSE,
9403 						p_validation_level              => FND_API.G_VALID_LEVEL_FULL,
9404 
9405 						p_wip_entity_id                 => l_eam_wo_rec.wip_entity_id,
9406 
9407 						x_return_status                 => l_return_status,
9408 						x_msg_count                     => l_msg_count,
9409 						x_msg_data                      => l_err_text
9410 				);
9411 				IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check_Resource_Dates completed with status of '||l_return_status) ; END IF ;
9412 
9413 				IF NVL(l_return_status, 'T') <> 'S' THEN
9414 						l_eam_return_status := l_return_status;
9415 						l_return_status := 'E';
9416 						RAISE CHECK_WO_RES_DATES_ERR;
9417 				END IF;
9418 
9419 		end if;
9420 
9421 		begin
9422 				IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling Check_Wo_Negative_Dates procedure ... ') ; END IF ;
9423 				EAM_WO_NETWORK_DEFAULT_PVT.Check_Wo_Negative_Dates
9424 				(
9425 						p_api_version                   => 1.0,
9426 						p_init_msg_list                 => FND_API.G_FALSE,
9427 						p_commit                        => FND_API.G_FALSE,
9428 						p_validation_level              => FND_API.G_VALID_LEVEL_FULL,
9429 						p_wip_entity_id                 => l_eam_wo_rec.wip_entity_id,
9430 						p_organization_id               => l_eam_wo_rec.organization_id,
9431 						x_return_status                 => l_return_status,
9432 						x_msg_count                     => l_msg_count,
9433 						x_msg_data                      => l_err_text
9434 				);
9435 
9436 				IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Check_Wo_Negative_Dates completed with status of '||l_return_status) ; END IF ;
9437 
9438 				IF NVL(l_return_status, 'T') <> 'S' THEN
9439 						l_eam_return_status := l_return_status;
9440 						l_return_status := 'E';
9441 						RAISE CHECK_WO_NEGATIVE_DATES_ERR;
9442 				END IF;
9443 
9444 		end;
9445 
9446 
9447 		if NVL(l_eam_wo_rec.validate_structure,'N') <> 'Y' then -- check added for bug# 3544860
9448 
9449 				IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling Validate_Structure API'); END IF;
9450 
9451 				EAM_WO_NETWORK_VALIDATE_PVT.Validate_Structure
9452 				(
9453 						p_api_version                   => 1.0,
9454 						p_init_msg_list                 => FND_API.G_FALSE,
9455 						p_commit                        => FND_API.G_FALSE,
9456 						p_validation_level              => FND_API.G_VALID_LEVEL_FULL,
9457 
9458 						p_work_object_id                => l_eam_wo_rec.wip_entity_id,
9459 						p_work_object_type_id           => 1,
9460 						p_exception_logging             => 'Y',
9461 
9462 						p_validate_status		=> 'N',
9463 						p_output_errors			=> 'N',
9464 
9465 						x_return_status                 => l_return_status,
9466 						x_msg_count                     => l_msg_count,
9467 						x_msg_data                      => l_err_text,
9468 						x_wo_relationship_exc_tbl	=> l_wo_relationship_exc_tbl
9469 				);
9470 
9471 				--call the validate structure.
9472 				IF nvl(l_return_status,'T') <> 'S' THEN
9473 						l_eam_return_status := l_return_status;
9474 						l_return_status := 'E';
9475 						RAISE VALIDATE_NETWORK_ERR;
9476 				END IF;
9477 		end if;
9478 
9479 		IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('enters inside update'); END IF;
9480 		UPDATE_DATES(l_eam_wo_rec,
9481 				l_eam_op_tbl,
9482 				l_eam_res_tbl,
9483 				l_eam_res_inst_tbl);
9484 		end if;    --end of check for l_eam_return_status and 'S'
9485 
9486         l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
9487 
9488         -- Load out parameters
9489 		IF nvl(l_eam_return_status,'S') <> 'S' THEN
9490 				x_return_status                := l_eam_return_status;
9491 		END IF;
9492 
9493 		IF l_eam_return_status = 'S' THEN
9494 
9495 				IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Updating WIP_REQUIREMENT_OPERATIONS'); END IF;
9496 
9497 				begin
9498 						select operation_seq_num,first_unit_start_date
9499 								bulk collect into l_wkorder_new_op_tbl,l_wkorder_new_op_dt_tbl
9500 								from wip_operations
9501 								where  organization_id = l_organization_id
9502 								and  wip_entity_id = l_wip_entity_id;
9503 				exception when others then
9504 								null;
9505 				end;
9506 
9507 				IF l_wkorder_old_op_tbl.COUNT > 0 THEN
9508 
9509 						FOR ii in l_wkorder_old_op_tbl.FIRST..l_wkorder_old_op_tbl.LAST LOOP
9510 								IF l_wkorder_new_op_tbl.COUNT > 0 THEN
9511 										FOR jj in l_wkorder_new_op_tbl.FIRST..l_wkorder_new_op_tbl.LAST LOOP
9512 												IF l_wkorder_old_op_tbl(ii) = l_wkorder_new_op_tbl(jj) THEN
9513 														IF l_wkorder_old_op_dt_tbl(ii) <> l_wkorder_new_op_dt_tbl(jj) THEN
9514 
9515 																no_of_days := l_wkorder_new_op_dt_tbl(jj)-l_wkorder_old_op_dt_tbl(ii);
9516 																update WIP_REQUIREMENT_OPERATIONS
9517 																set date_required = date_required + no_of_days
9518 																where organization_id = l_organization_id
9519 																and wip_entity_id = l_wip_entity_id
9520 																and operation_seq_num = l_wkorder_old_op_tbl(ii);
9521 														END IF;
9522 												END IF;
9523 										END LOOP;
9524 								END IF;
9525 						END LOOP;
9526 				-- condition for bug 5258151
9527 				ELSE IF l_eam_wo_rec.transaction_type = G_OPR_CREATE and l_wkorder_new_op_tbl.count > 0 THEN
9528 								FOR jj in l_wkorder_new_op_tbl.FIRST..l_wkorder_new_op_tbl.LAST LOOP
9529 										update WIP_REQUIREMENT_OPERATIONS
9530 										set date_required = l_wkorder_new_op_dt_tbl(jj)
9531 										where organization_id = l_organization_id
9532 										and wip_entity_id = l_wip_entity_id
9533 										and operation_seq_num = l_wkorder_new_op_tbl(jj);
9534 								END LOOP;
9535 						END IF;
9536 				END IF;			--- end of l_wkorder_old_op_tbl.COUNT
9537 
9538 				IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Updating date required columns for WIP_REQUIREMENT_OPERATIONS'); END IF;
9539 
9540 				IF l_wip_entity_id IS NOT NULL THEN
9541 						select SCHEDULED_START_DATE into l_wo_new_sch_start_date
9542 						from wip_discrete_jobs
9543 						where wip_entity_id = l_wip_entity_id;
9544 				END IF;
9545 
9546 				IF l_wo_old_sch_start_date <> l_wo_new_sch_start_date THEN
9547 						update wip_requirement_operations
9548 						set date_required = date_required + (l_wo_new_sch_start_date-l_wo_old_sch_start_date)
9549 						where operation_seq_num = 1
9550 						and organization_id = l_organization_id
9551 						and wip_entity_id = l_wip_entity_id ;
9552 				END IF;
9553 
9554 				 --Code added to sync up WORI with WOR when resource dates are modified from summary tab
9555                                    IF l_woru_modified ='N' THEN
9556 
9557                                                    FOR c_opresource_rec IN get_opresource_csr(l_eam_wo_rec.wip_entity_id) LOOP
9558 
9559                                                    UPDATE        wip_op_resource_instances
9560                                                    SET        start_date = c_opresource_rec.start_date,
9561                                                            completion_date=c_opresource_rec.completion_date
9562                                                    WHERE        wip_entity_id = l_wip_entity_id
9563                                                    AND        operation_seq_num = c_opresource_rec.operation_seq_num
9564                                                    AND        resource_seq_num = c_opresource_rec.resource_seq_num;
9565 
9566                                                    END LOOP;
9567 
9568                                    END IF;
9569 
9570 
9571 
9572 				--added code for bug 5449296 from EAMPWOPB.pls
9573 
9574 				/* Failure Entry Project Start*/
9575 				IF( l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PUB.G_OPR_CREATE
9576 						AND l_eam_wo_rec.eam_failure_entry_record.failure_date is not null
9577 						) THEN
9578 						l_eam_wo_rec.eam_failure_entry_record.source_id := l_eam_wo_rec.wip_entity_id;
9579 				END IF;
9580 
9581 				If( l_eam_wo_rec.eam_failure_entry_record.transaction_type is not null) then
9582 
9583 						EAM_Process_Failure_Entry_PUB.Process_Failure_Entry
9584 						(
9585 								p_eam_failure_entry_record   => l_eam_wo_rec.eam_failure_entry_record
9586 								, p_eam_failure_codes_tbl      => l_eam_wo_rec.eam_failure_codes_tbl
9587 								, x_return_status              => l_return_status
9588 								, x_msg_count                  => l_msg_count
9589 								, x_msg_data                   => l_msg_data
9590 								, x_eam_failure_entry_record   => x_eam_wo_rec.eam_failure_entry_record
9591 								, x_eam_failure_codes_tbl      => x_eam_wo_rec.eam_failure_codes_tbl
9592 						);
9593 
9594 						IF NVL(l_return_status, 'T') <> 'S' THEN
9595 								l_eam_return_status := 'E';
9596 								RAISE EXC_ERR_PVT_API_MAIN;
9597 						END IF;
9598 
9599 						l_eam_wo_rec.eam_failure_entry_record   := x_eam_wo_rec.eam_failure_entry_record ;   --copy output variables back to local
9600 						l_eam_wo_rec.eam_failure_codes_tbl      := x_eam_wo_rec.eam_failure_codes_tbl;
9601 				END IF;
9602 				/* Failure Entry Project End */
9603 
9604 				-- Stock Issue requirements
9605 				If l_eam_wo_rec.material_issue_by_mo = 'Y' and
9606 						l_eam_wo_rec.maintenance_object_source = 1 and -- Only for EAM
9607 						((l_eam_wo_rec.status_type in (3,7) and    --release or cancel a workorder
9608 						l_eam_wo_rec.status_type <> l_old_eam_wo_rec.status_type) OR
9609 						(l_eam_wo_rec.transaction_type = EAM_PROCESS_WO_PUB.G_OPR_CREATE and
9610 						l_eam_wo_rec.status_type = 3)
9611 						) then
9612 
9613 						IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling material Allocation procedure at wo release/cancel ... ') ; END IF ;
9614 
9615 						EAM_MATERIALISSUE_PVT.alloc_at_release_cancel (
9616 								p_api_version        => 1.0,
9617 								p_init_msg_list      => fnd_api.g_false,
9618 								p_commit             => fnd_api.g_false,
9619 								p_validation_level   => fnd_api.g_valid_level_full,
9620 								p_wip_entity_id      => l_eam_wo_rec.wip_entity_id,
9621 								p_organization_id    => l_eam_wo_rec.organization_id,
9622 								p_status_type        => l_eam_wo_rec.status_type,
9623 								x_return_status      => l_return_status,
9624 								x_msg_data           => l_err_text,
9625 								x_msg_count          => l_msg_count
9626 						);
9627 
9628 
9629 						IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Allocation creation at wo release/cancel completed with status of '||l_return_status) ; END IF ;
9630 
9631 						IF NVL(l_return_status, 'T') <> 'S' THEN
9632 								l_eam_return_status := 'E';
9633 								RAISE ALLOC_CREATION_ERR;
9634 						END IF;
9635 
9636 				End if;     --end of if for stock issue enhancements
9637 
9638 
9639 				IF l_out_eam_mat_req_tbl.COUNT > 0 THEN
9640 
9641 						FOR kk in l_out_eam_mat_req_tbl.FIRST..l_out_eam_mat_req_tbl.LAST LOOP
9642 								IF(NVL(l_out_eam_mat_req_tbl(kk).invoke_allocations_api,'N') ='Y') THEN
9643 
9644 										EAM_MATERIALISSUE_PVT.comp_alloc_chng_qty
9645 										(
9646 												p_api_version        => 1.0,
9647 												p_init_msg_list      => fnd_api.g_false,
9648 												p_commit             => fnd_api.g_false,
9649 												p_validation_level   => fnd_api.g_valid_level_full,
9650 												p_wip_entity_id      => l_out_eam_mat_req_tbl(kk).wip_entity_id,
9651 												p_organization_id    => l_out_eam_mat_req_tbl(kk).organization_id,
9652 												p_operation_seq_num  => l_out_eam_mat_req_tbl(kk).operation_seq_num,
9653 												p_inventory_item_id  => l_out_eam_mat_req_tbl(kk).inventory_item_id,
9654 												p_qty_required       => l_out_eam_mat_req_tbl(kk).required_quantity,
9655                                                                                                 p_supply_subinventory => l_out_eam_mat_req_tbl(kk).supply_subinventory,
9656                                                                                                 p_supply_locator_id  => l_out_eam_mat_req_tbl(kk).supply_locator_id,
9657 												x_return_status      => l_return_status,
9658 												x_msg_data           => l_err_text,
9659 												x_msg_count          => l_msg_count
9660 										);
9661 
9662 								END IF;
9663 
9664 								IF l_old_eam_wo_rec.status_type in (3,4) -- released, complete
9665 										and l_out_eam_mat_req_tbl(kk).transaction_type = EAM_PROCESS_WO_PVT.G_OPR_DELETE
9666 										THEN
9667 										EAM_MATERIALISSUE_PVT.cancel_alloc_matl_del
9668 										(
9669 												p_api_version           => 1.0,
9670 												p_init_msg_list         => fnd_api.g_false,
9671 												p_commit                => fnd_api.g_false,
9672 												p_validation_level      => fnd_api.g_valid_level_full,
9673 												p_wip_entity_id         => l_out_eam_mat_req_tbl(kk).wip_entity_id,
9674 												p_operation_seq_num     => l_out_eam_mat_req_tbl(kk).operation_seq_num,
9675 												p_inventory_item_id     => l_out_eam_mat_req_tbl(kk).inventory_item_id,
9676 												p_wip_entity_type       => WIP_CONSTANTS.EAM,
9677 												p_repetitive_schedule_id => null,
9678 												x_return_status         => l_return_status,
9679 												x_msg_data              => l_err_text,
9680 												x_msg_count             => l_msg_count
9681 										);
9682 
9683 								END IF;
9684 						END LOOP;
9685 
9686 				END IF;		--end of if l_out_eam_mat_req_tbl.COUNT
9687 
9688 				IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling UPDATE_INTERMEDIA_INDEX'); END IF;
9689 
9690 				IF(l_eam_wo_rec.maintenance_object_source =1 ) THEN   --update intermedia index only for EAM workorders
9691 				UPDATE_INTERMEDIA_INDEX
9692 				(
9693 						l_eam_wo_rec,
9694 						l_old_eam_wo_rec,
9695 						l_eam_op_tbl,
9696 						l_eam_res_tbl,
9697 						l_eam_res_inst_tbl
9698 				);
9699 				END IF;     --end of check for maint. object source...
9700 
9701 		END IF;		--end of l_eam_return_status='S'
9702 
9703 		IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Assigning Out Parameters'); END IF;
9704 
9705 		x_msg_count                    := l_msg_count;
9706 		x_eam_wo_rec                   := l_eam_wo_rec;
9707 		x_eam_op_tbl                   := l_eam_op_tbl;
9708 		x_eam_op_network_tbl           := l_eam_op_network_tbl;
9709 		x_eam_res_tbl                  := l_eam_res_tbl;
9710 		x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
9711 		x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
9712 		x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
9713 		x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
9714 		x_eam_direct_items_tbl         := l_eam_direct_items_tbl;
9715 		x_return_status                := l_eam_return_status;
9716 
9717 
9718 EXCEPTION
9719 
9720      WHEN ALLOC_CREATION_ERR THEN
9721 
9722             l_token_tbl(1).token_name  := 'Wip_Entity_Id';
9723             l_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_id;
9724 
9725             l_out_mesg_token_tbl  := l_mesg_token_tbl;
9726             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
9727             (  x_Mesg_token_tbl => l_out_Mesg_Token_Tbl
9728              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
9729              , p_message_name   => 'EAM_WO_ALLOC_CR_ERR'
9730              , p_token_tbl      => l_token_tbl
9731              );
9732             l_mesg_token_tbl      := l_out_mesg_token_tbl;
9733 
9734             l_return_status := FND_API.G_RET_STS_ERROR;
9735 
9736          l_out_eam_wo_rec            := l_eam_wo_rec;
9737          l_out_eam_op_tbl            := l_eam_op_tbl;
9738          l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
9739          l_out_eam_res_tbl           := l_eam_res_tbl;
9740          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
9741          l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
9742          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
9743          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
9744          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
9745         EAM_ERROR_MESSAGE_PVT.Log_Error
9746         (  p_eam_wo_rec             => l_eam_wo_rec
9747         ,  p_eam_op_tbl             => l_eam_op_tbl
9748         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
9749         ,  p_eam_res_tbl            => l_eam_res_tbl
9750         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
9751         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
9752         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
9753         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
9754                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
9755         ,  p_mesg_token_tbl         => l_mesg_token_tbl
9756         ,  p_error_status           => FND_API.G_RET_STS_ERROR
9757         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
9758         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
9759         ,  p_other_message          => l_other_message
9760         ,  p_other_token_tbl        => l_other_token_tbl
9761         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
9762         ,  x_eam_wo_rec             => l_out_eam_wo_rec
9763         ,  x_eam_op_tbl             => l_out_eam_op_tbl
9764         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
9765         ,  x_eam_res_tbl            => l_out_eam_res_tbl
9766         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
9767         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
9768         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
9769         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
9770                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
9771         );
9772          l_eam_wo_rec                := l_out_eam_wo_rec;
9773          l_eam_op_tbl                := l_out_eam_op_tbl;
9774          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
9775          l_eam_res_tbl               := l_out_eam_res_tbl;
9776          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
9777          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
9778          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
9779          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
9780          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
9781 
9782        l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
9783 
9784         x_msg_count                    := l_msg_count;
9785         x_return_status                := l_return_status;
9786         x_eam_wo_rec                   := l_eam_wo_rec;
9787         x_eam_op_tbl                   := l_eam_op_tbl;
9788         x_eam_op_network_tbl           := l_eam_op_network_tbl;
9789         x_eam_res_tbl                  := l_eam_res_tbl;
9790         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
9791         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
9792         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
9793         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
9794         x_eam_direct_items_tbl         := l_eam_direct_items_tbl;
9795 
9796     WHEN EXC_ERR_PVT_API_MAIN THEN
9797 
9798 	 l_out_eam_wo_rec            := l_eam_wo_rec;
9799          l_out_eam_op_tbl            := l_eam_op_tbl;
9800   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
9801          l_out_eam_res_tbl           := l_eam_res_tbl;
9802          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
9803 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
9804          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
9805          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
9806          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
9807         EAM_ERROR_MESSAGE_PVT.Log_Error
9808         (  p_eam_wo_rec             => l_eam_wo_rec
9809         ,  p_eam_op_tbl             => l_eam_op_tbl
9810         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
9811         ,  p_eam_res_tbl            => l_eam_res_tbl
9812         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
9813         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
9814         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
9815         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
9816                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
9817         ,  p_mesg_token_tbl         => l_mesg_token_tbl
9818         ,  p_error_status           => FND_API.G_RET_STS_ERROR
9819         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
9820         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
9821         ,  p_other_message          => l_other_message
9822         ,  p_other_token_tbl        => l_other_token_tbl
9823         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
9824         ,  x_eam_wo_rec             => l_out_eam_wo_rec
9825         ,  x_eam_op_tbl             => l_out_eam_op_tbl
9826         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
9827         ,  x_eam_res_tbl            => l_out_eam_res_tbl
9828         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
9829         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
9830         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
9831         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
9832         ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
9833         );
9834 	 l_eam_wo_rec                := l_out_eam_wo_rec;
9835          l_eam_op_tbl                := l_out_eam_op_tbl;
9836          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
9837          l_eam_res_tbl               := l_out_eam_res_tbl;
9838          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
9839          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
9840          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
9841          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
9842          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
9843 
9844         l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
9845 
9846         x_msg_count                    := l_msg_count;
9847         x_return_status                := l_return_status;
9848         x_eam_wo_rec                   := l_eam_wo_rec;
9849         x_eam_op_tbl                   := l_eam_op_tbl;
9850         x_eam_op_network_tbl           := l_eam_op_network_tbl;
9851         x_eam_res_tbl                  := l_eam_res_tbl;
9852         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
9853         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
9854         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
9855         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
9856         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
9857 
9858 
9859     WHEN OSP_REQ_ERR THEN
9860 
9861            l_token_tbl(1).token_name  := 'WIPENTITYID';
9862             l_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_id;
9863 
9864             l_out_mesg_token_tbl  := l_mesg_token_tbl;
9865             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
9866             (  x_Mesg_token_tbl => l_out_Mesg_Token_Tbl
9867              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
9868              , p_message_name   => 'EAM_WO_OSP_REQ_ERR'
9869              , p_token_tbl      => l_token_tbl
9870              );
9871             l_mesg_token_tbl      := l_out_mesg_token_tbl;
9872 
9873             l_return_status := FND_API.G_RET_STS_ERROR;
9874 
9875 	 l_out_eam_wo_rec            := l_eam_wo_rec;
9876          l_out_eam_op_tbl            := l_eam_op_tbl;
9877   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
9878          l_out_eam_res_tbl           := l_eam_res_tbl;
9879          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
9880 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
9881          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
9882          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
9883          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
9884         EAM_ERROR_MESSAGE_PVT.Log_Error
9885         (  p_eam_wo_rec             => l_eam_wo_rec
9886         ,  p_eam_op_tbl             => l_eam_op_tbl
9887         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
9888         ,  p_eam_res_tbl            => l_eam_res_tbl
9889         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
9890         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
9891         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
9892         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
9893         ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
9894         ,  p_mesg_token_tbl         => l_mesg_token_tbl
9895         ,  p_error_status           => FND_API.G_RET_STS_ERROR
9896         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
9897         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
9898         ,  p_other_message          => l_other_message
9899         ,  p_other_token_tbl        => l_other_token_tbl
9900         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
9901         ,  x_eam_wo_rec             => l_out_eam_wo_rec
9902         ,  x_eam_op_tbl             => l_out_eam_op_tbl
9903         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
9904         ,  x_eam_res_tbl            => l_out_eam_res_tbl
9905         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
9906         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
9907         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
9908         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
9909         ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
9910         );
9911 	 l_eam_wo_rec                := l_out_eam_wo_rec;
9912          l_eam_op_tbl                := l_out_eam_op_tbl;
9913          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
9914          l_eam_res_tbl               := l_out_eam_res_tbl;
9915          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
9916          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
9917          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
9918          l_eam_direct_items_tbl      := l_out_eam_direct_items_tbl;
9919          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
9920 
9921         l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
9922 
9923         x_msg_count                    := l_msg_count;
9924         x_return_status                := l_return_status;
9925         x_eam_wo_rec                   := l_eam_wo_rec;
9926         x_eam_op_tbl                   := l_eam_op_tbl;
9927         x_eam_op_network_tbl           := l_eam_op_network_tbl;
9928         x_eam_res_tbl                  := l_eam_res_tbl;
9929         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
9930         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
9931         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
9932         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
9933         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
9934 
9935 WHEN UPDATE_RES_USAGE_BU_ERR THEN
9936 
9937      l_token_tbl(1).token_name  := 'WORK_ORDER_NAME';
9938      l_token_tbl(1).token_value :=  l_eam_wo_rec.wip_entity_name;
9939 
9940             l_out_mesg_token_tbl  := l_mesg_token_tbl;
9941             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
9942             (  x_Mesg_token_tbl => l_out_Mesg_Token_Tbl
9943              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
9944              , p_message_name   => l_err_text
9945              , p_token_tbl      => l_token_tbl
9946              );
9947             l_mesg_token_tbl      := l_out_mesg_token_tbl;
9948 
9949             l_return_status := FND_API.G_RET_STS_ERROR;
9950 
9951 	 l_out_eam_wo_rec            := l_eam_wo_rec;
9952          l_out_eam_op_tbl            := l_eam_op_tbl;
9953   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
9954          l_out_eam_res_tbl           := l_eam_res_tbl;
9955          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
9956 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
9957          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
9958          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
9959          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
9960         EAM_ERROR_MESSAGE_PVT.Log_Error
9961         (  p_eam_wo_rec             => l_eam_wo_rec
9962         ,  p_eam_op_tbl             => l_eam_op_tbl
9963         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
9964         ,  p_eam_res_tbl            => l_eam_res_tbl
9965         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
9966         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
9967         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
9968         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
9969         ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
9970         ,  p_mesg_token_tbl         => l_mesg_token_tbl
9971         ,  p_error_status           => FND_API.G_RET_STS_ERROR
9972         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
9973         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
9974         ,  p_other_message          => l_other_message
9975         ,  p_other_token_tbl        => l_other_token_tbl
9976         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
9977         ,  x_eam_wo_rec             => l_out_eam_wo_rec
9978         ,  x_eam_op_tbl             => l_out_eam_op_tbl
9979         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
9980         ,  x_eam_res_tbl            => l_out_eam_res_tbl
9981         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
9982         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
9983         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
9984         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
9985 	,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
9986         );
9987 	 l_eam_wo_rec                := l_out_eam_wo_rec;
9988          l_eam_op_tbl                := l_out_eam_op_tbl;
9989          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
9990          l_eam_res_tbl               := l_out_eam_res_tbl;
9991          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
9992          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
9993          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
9994          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
9995          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
9996 
9997 
9998         l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
9999 
10000         x_msg_count                    := l_msg_count;
10001         x_return_status                := l_return_status;
10002         x_eam_wo_rec                   := l_eam_wo_rec;
10003         x_eam_op_tbl                   := l_eam_op_tbl;
10004         x_eam_op_network_tbl           := l_eam_op_network_tbl;
10005         x_eam_res_tbl                  := l_eam_res_tbl;
10006         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
10007         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
10008         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
10009         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
10010         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
10011 
10012 WHEN SCHEDULE_BOTTOM_UP_ERR THEN
10013 
10014      l_token_tbl(1).token_name  := 'WORK_ORDER_NAME';
10015      l_token_tbl(1).token_value :=  l_eam_wo_rec.wip_entity_name;
10016 
10017             l_out_mesg_token_tbl  := l_mesg_token_tbl;
10018             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10019             (  x_Mesg_token_tbl => l_out_Mesg_Token_Tbl
10020              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
10021              , p_message_name   => l_err_text
10022              , p_token_tbl      => l_token_tbl
10023              );
10024             l_mesg_token_tbl      := l_out_mesg_token_tbl;
10025 
10026             l_return_status := FND_API.G_RET_STS_ERROR;
10027 
10028 	 l_out_eam_wo_rec            := l_eam_wo_rec;
10029          l_out_eam_op_tbl            := l_eam_op_tbl;
10030   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
10031          l_out_eam_res_tbl           := l_eam_res_tbl;
10032          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
10033 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
10034          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
10035          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
10036          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
10037         EAM_ERROR_MESSAGE_PVT.Log_Error
10038         (  p_eam_wo_rec             => l_eam_wo_rec
10039         ,  p_eam_op_tbl             => l_eam_op_tbl
10040         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
10041         ,  p_eam_res_tbl            => l_eam_res_tbl
10042         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
10043         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
10044         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
10045         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
10046         ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
10047         ,  p_mesg_token_tbl         => l_mesg_token_tbl
10048         ,  p_error_status           => FND_API.G_RET_STS_ERROR
10049         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
10050         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
10051         ,  p_other_message          => l_other_message
10052         ,  p_other_token_tbl        => l_other_token_tbl
10053         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
10054         ,  x_eam_wo_rec             => l_out_eam_wo_rec
10055         ,  x_eam_op_tbl             => l_out_eam_op_tbl
10056         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
10057         ,  x_eam_res_tbl            => l_out_eam_res_tbl
10058         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
10059         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
10060         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
10061         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
10062 	,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
10063         );
10064 	 l_eam_wo_rec                := l_out_eam_wo_rec;
10065          l_eam_op_tbl                := l_out_eam_op_tbl;
10066          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
10067          l_eam_res_tbl               := l_out_eam_res_tbl;
10068          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
10069          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
10070          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
10071          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
10072          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
10073 
10074 
10075         l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
10076 
10077         x_msg_count                    := l_msg_count;
10078         x_return_status                := l_return_status;
10079         x_eam_wo_rec                   := l_eam_wo_rec;
10080         x_eam_op_tbl                   := l_eam_op_tbl;
10081         x_eam_op_network_tbl           := l_eam_op_network_tbl;
10082         x_eam_res_tbl                  := l_eam_res_tbl;
10083         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
10084         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
10085         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
10086         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
10087         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
10088 
10089  WHEN CHECK_OP_NETWORK_DATES_ERR THEN
10090 
10091      l_token_tbl(1).token_name  := 'OP_SEQ_NO';
10092      l_token_tbl(1).token_value :=  l_prior_op_no || ',' || l_next_op_no;
10093 
10094             l_out_mesg_token_tbl  := l_mesg_token_tbl;
10095             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10096             (  x_Mesg_token_tbl => l_out_Mesg_Token_Tbl
10097              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
10098              , p_message_name   => 'EAM_OP_NETWRK_DATES_ERR'
10099              , p_token_tbl      => l_token_tbl
10100              );
10101             l_mesg_token_tbl      := l_out_mesg_token_tbl;
10102 
10103             l_return_status := FND_API.G_RET_STS_ERROR;
10104 
10105 	 l_out_eam_wo_rec            := l_eam_wo_rec;
10106          l_out_eam_op_tbl            := l_eam_op_tbl;
10107   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
10108          l_out_eam_res_tbl           := l_eam_res_tbl;
10109          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
10110 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
10111          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
10112          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
10113          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
10114         EAM_ERROR_MESSAGE_PVT.Log_Error
10115         (  p_eam_wo_rec             => l_eam_wo_rec
10116         ,  p_eam_op_tbl             => l_eam_op_tbl
10117         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
10118         ,  p_eam_res_tbl            => l_eam_res_tbl
10119         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
10120         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
10121         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
10122         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
10123         ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
10124         ,  p_mesg_token_tbl         => l_mesg_token_tbl
10125         ,  p_error_status           => FND_API.G_RET_STS_ERROR
10126         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
10127         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
10128         ,  p_other_message          => l_other_message
10129         ,  p_other_token_tbl        => l_other_token_tbl
10130         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
10131         ,  x_eam_wo_rec             => l_out_eam_wo_rec
10132         ,  x_eam_op_tbl             => l_out_eam_op_tbl
10133         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
10134         ,  x_eam_res_tbl            => l_out_eam_res_tbl
10135         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
10136         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
10137         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
10138         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
10139         ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
10140         );
10141 	 l_eam_wo_rec                := l_out_eam_wo_rec;
10142          l_eam_op_tbl                := l_out_eam_op_tbl;
10143          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
10144          l_eam_res_tbl               := l_out_eam_res_tbl;
10145          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
10146          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
10147          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
10148          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
10149          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
10150 
10151 
10152         l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
10153 
10154         x_msg_count                    := l_msg_count;
10155         x_return_status                := l_return_status;
10156         x_eam_wo_rec                   := l_eam_wo_rec;
10157         x_eam_op_tbl                   := l_eam_op_tbl;
10158         x_eam_op_network_tbl           := l_eam_op_network_tbl;
10159         x_eam_res_tbl                  := l_eam_res_tbl;
10160         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
10161         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
10162         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
10163         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
10164         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
10165 
10166 
10167     WHEN CHECK_WO_DATES_ERR THEN
10168 
10169             l_token_tbl(1).token_name  := 'WorkOrder';
10170 --            l_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_id;
10171 
10172     SELECT wip_entity_name into l_token_tbl(1).token_value
10173 	 FROM  WIP_ENTITIES we
10174 	 WHERE we.wip_entity_id = l_eam_wo_rec.wip_entity_id
10175 	 AND   we.organization_id = l_eam_wo_rec.organization_id;
10176 
10177 
10178             l_out_mesg_token_tbl  := l_mesg_token_tbl;
10179             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10180             (  x_Mesg_token_tbl => l_out_Mesg_Token_Tbl
10181              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
10182              , p_message_name   => 'EAM_WO_CHK_DATES_ERR'
10183              , p_token_tbl      => l_token_tbl
10184              );
10185             l_mesg_token_tbl      := l_out_mesg_token_tbl;
10186 
10187             l_return_status := FND_API.G_RET_STS_ERROR;
10188 
10189 	 l_out_eam_wo_rec            := l_eam_wo_rec;
10190          l_out_eam_op_tbl            := l_eam_op_tbl;
10191   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
10192          l_out_eam_res_tbl           := l_eam_res_tbl;
10193          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
10194 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
10195          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
10196          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
10197          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
10198         EAM_ERROR_MESSAGE_PVT.Log_Error
10199         (  p_eam_wo_rec             => l_eam_wo_rec
10200         ,  p_eam_op_tbl             => l_eam_op_tbl
10201         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
10202         ,  p_eam_res_tbl            => l_eam_res_tbl
10203         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
10204         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
10205         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
10206         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
10207                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
10208         ,  p_mesg_token_tbl         => l_mesg_token_tbl
10209         ,  p_error_status           => FND_API.G_RET_STS_ERROR
10210         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
10211         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
10212         ,  p_other_message          => l_other_message
10213         ,  p_other_token_tbl        => l_other_token_tbl
10214         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
10215         ,  x_eam_wo_rec             => l_out_eam_wo_rec
10216         ,  x_eam_op_tbl             => l_out_eam_op_tbl
10217         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
10218         ,  x_eam_res_tbl            => l_out_eam_res_tbl
10219         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
10220         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
10221         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
10222         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
10223                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
10224         );
10225 	 l_eam_wo_rec                := l_out_eam_wo_rec;
10226          l_eam_op_tbl                := l_out_eam_op_tbl;
10227          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
10228          l_eam_res_tbl               := l_out_eam_res_tbl;
10229          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
10230          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
10231          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
10232          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
10233          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
10234 
10235 
10236         l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
10237 
10238         x_msg_count                    := l_msg_count;
10239         x_return_status                := l_return_status;
10240         x_eam_wo_rec                   := l_eam_wo_rec;
10241         x_eam_op_tbl                   := l_eam_op_tbl;
10242         x_eam_op_network_tbl           := l_eam_op_network_tbl;
10243         x_eam_res_tbl                  := l_eam_res_tbl;
10244         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
10245         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
10246         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
10247         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
10248         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
10249 
10250     WHEN CHECK_WO_RES_DATES_ERR THEN
10251 
10252             l_token_tbl(1).token_name  := 'WorkOrder';
10253 --            l_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_id;
10254 
10255     SELECT wip_entity_name into l_token_tbl(1).token_value
10256 	 FROM  WIP_ENTITIES we
10257 	 WHERE we.wip_entity_id = l_eam_wo_rec.wip_entity_id
10258 	 AND   we.organization_id = l_eam_wo_rec.organization_id;
10259 
10260 
10261             l_out_mesg_token_tbl  := l_mesg_token_tbl;
10262             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10263             (  x_Mesg_token_tbl => l_out_Mesg_Token_Tbl
10264              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
10265              , p_message_name   => 'CHECK_WO_RES_DATES_ERR'
10266              , p_token_tbl      => l_token_tbl
10267              );
10268             l_mesg_token_tbl      := l_out_mesg_token_tbl;
10269 
10270             l_return_status := FND_API.G_RET_STS_ERROR;
10271 
10272 	 l_out_eam_wo_rec            := l_eam_wo_rec;
10273          l_out_eam_op_tbl            := l_eam_op_tbl;
10274   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
10275          l_out_eam_res_tbl           := l_eam_res_tbl;
10276          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
10277 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
10278          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
10279          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
10280          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
10281         EAM_ERROR_MESSAGE_PVT.Log_Error
10282         (  p_eam_wo_rec             => l_eam_wo_rec
10283         ,  p_eam_op_tbl             => l_eam_op_tbl
10284         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
10285         ,  p_eam_res_tbl            => l_eam_res_tbl
10286         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
10287         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
10288         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
10289         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
10290                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
10291         ,  p_mesg_token_tbl         => l_mesg_token_tbl
10292         ,  p_error_status           => FND_API.G_RET_STS_ERROR
10293         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
10294         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
10295         ,  p_other_message          => l_other_message
10296         ,  p_other_token_tbl        => l_other_token_tbl
10297         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
10298         ,  x_eam_wo_rec             => l_out_eam_wo_rec
10299         ,  x_eam_op_tbl             => l_out_eam_op_tbl
10300         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
10301         ,  x_eam_res_tbl            => l_out_eam_res_tbl
10302         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
10303         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
10304         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
10305         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
10306                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
10307         );
10308 	 l_eam_wo_rec                := l_out_eam_wo_rec;
10309          l_eam_op_tbl                := l_out_eam_op_tbl;
10310          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
10311          l_eam_res_tbl               := l_out_eam_res_tbl;
10312          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
10313          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
10314          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
10315          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
10316          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
10317 
10318 
10319         l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
10320 
10321         x_msg_count                    := l_msg_count;
10322         x_return_status                := l_return_status;
10323         x_eam_wo_rec                   := l_eam_wo_rec;
10324         x_eam_op_tbl                   := l_eam_op_tbl;
10325         x_eam_op_network_tbl           := l_eam_op_network_tbl;
10326         x_eam_res_tbl                  := l_eam_res_tbl;
10327         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
10328         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
10329         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
10330         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
10331         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
10332 
10333     WHEN CHECK_WO_NEGATIVE_DATES_ERR THEN
10334          l_token_tbl(1).token_name  := 'Wip Entity Id';
10335             l_token_tbl(1).token_value := l_eam_wo_rec.wip_entity_id;
10336 
10337             l_out_mesg_token_tbl  := l_mesg_token_tbl;
10338             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10339             (  x_Mesg_token_tbl => l_out_Mesg_Token_Tbl
10340              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
10341              , p_message_name   => 'EAM_WO_CHK_NEGATIVE_DATES_ERR'
10342              , p_token_tbl      => l_token_tbl
10343              );
10344             l_mesg_token_tbl      := l_out_mesg_token_tbl;
10345 
10346             l_return_status := FND_API.G_RET_STS_ERROR;
10347 
10348 	 l_out_eam_wo_rec            := l_eam_wo_rec;
10349          l_out_eam_op_tbl            := l_eam_op_tbl;
10350   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
10351          l_out_eam_res_tbl           := l_eam_res_tbl;
10352          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
10353 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
10354          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
10355          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
10356          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
10357         EAM_ERROR_MESSAGE_PVT.Log_Error
10358 		(  p_eam_wo_rec             => l_eam_wo_rec
10359 		,  p_eam_op_tbl             => l_eam_op_tbl
10360 		,  p_eam_op_network_tbl     => l_eam_op_network_tbl
10361 		,  p_eam_res_tbl            => l_eam_res_tbl
10362 		,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
10363 		,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
10364 		,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
10365 		,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
10366 		       ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
10367 		,  p_mesg_token_tbl         => l_mesg_token_tbl
10368 		,  p_error_status           => FND_API.G_RET_STS_ERROR
10369 		,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
10370 		,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
10371 		,  p_other_message          => l_other_message
10372 		,  p_other_token_tbl        => l_other_token_tbl
10373 		,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
10374 		,  x_eam_wo_rec             => l_out_eam_wo_rec
10375 		,  x_eam_op_tbl             => l_out_eam_op_tbl
10376 		,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
10377 		,  x_eam_res_tbl            => l_out_eam_res_tbl
10378 		,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
10379 		,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
10380 		,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
10381 		,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
10382 		       ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
10383 		);
10384 		 l_eam_wo_rec                := l_out_eam_wo_rec;
10385 		 l_eam_op_tbl                := l_out_eam_op_tbl;
10386 		 l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
10387 		 l_eam_res_tbl               := l_out_eam_res_tbl;
10388 		 l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
10389 		 l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
10390 		 l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
10391 		 l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
10392 		 l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
10393 
10394 
10395 		l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
10396 
10397 		x_msg_count                    := l_msg_count;
10398 		x_return_status                := l_return_status;
10399 		x_eam_wo_rec                   := l_eam_wo_rec;
10400 		x_eam_op_tbl                   := l_eam_op_tbl;
10401 		x_eam_op_network_tbl           := l_eam_op_network_tbl;
10402 		x_eam_res_tbl                  := l_eam_res_tbl;
10403 		x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
10404 		x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
10405 		x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
10406 		x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
10407 		x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
10408     WHEN VALIDATE_NETWORK_ERR THEN
10409 
10410             l_out_mesg_token_tbl  := l_mesg_token_tbl;
10411             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10412             (  x_Mesg_token_tbl => l_out_Mesg_Token_Tbl
10413              , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
10414              , p_message_name   => 'EAM_WN_MAIN_VALIDATE_STRUCT'
10415              , p_token_tbl      => l_token_tbl
10416              );
10417             l_mesg_token_tbl      := l_out_mesg_token_tbl;
10418 
10419             l_return_status := FND_API.G_RET_STS_ERROR;
10420 
10421 	 l_out_eam_wo_rec            := l_eam_wo_rec;
10422          l_out_eam_op_tbl            := l_eam_op_tbl;
10423   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
10424          l_out_eam_res_tbl           := l_eam_res_tbl;
10425          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
10426 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
10427          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
10428          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
10429          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
10430         EAM_ERROR_MESSAGE_PVT.Log_Error
10431         (  p_eam_wo_rec             => l_eam_wo_rec
10432         ,  p_eam_op_tbl             => l_eam_op_tbl
10433         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
10434         ,  p_eam_res_tbl            => l_eam_res_tbl
10435         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
10436         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
10437         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
10438         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
10439                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
10440         ,  p_mesg_token_tbl         => l_mesg_token_tbl
10441         ,  p_error_status           => FND_API.G_RET_STS_ERROR
10442         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
10443         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
10444         ,  p_other_message          => l_other_message
10445         ,  p_other_token_tbl        => l_other_token_tbl
10446         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
10447         ,  x_eam_wo_rec             => l_out_eam_wo_rec
10448         ,  x_eam_op_tbl             => l_out_eam_op_tbl
10449         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
10450         ,  x_eam_res_tbl            => l_out_eam_res_tbl
10451         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
10452         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
10453         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
10454         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
10455                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
10456         );
10457 	 l_eam_wo_rec                := l_out_eam_wo_rec;
10458          l_eam_op_tbl                := l_out_eam_op_tbl;
10459          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
10460          l_eam_res_tbl               := l_out_eam_res_tbl;
10461          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
10462          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
10463          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
10464          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
10465          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
10466 
10467 
10468         l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
10469 
10470         x_msg_count                    := l_msg_count;
10471         x_return_status                := l_return_status;
10472         x_eam_wo_rec                   := l_eam_wo_rec;
10473         x_eam_op_tbl                   := l_eam_op_tbl;
10474         x_eam_op_network_tbl           := l_eam_op_network_tbl;
10475         x_eam_res_tbl                  := l_eam_res_tbl;
10476         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
10477         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
10478         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
10479         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
10480         x_eam_direct_items_tbl         := l_eam_direct_items_tbl;
10481 
10482 
10483     WHEN G_EXC_QUIT_IMPORT THEN
10484 
10485         l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
10486 
10487         x_msg_count                    := l_msg_count;
10488         x_return_status                := l_return_status;
10489         x_eam_wo_rec                   := l_eam_wo_rec;
10490         x_eam_op_tbl                   := l_eam_op_tbl;
10491         x_eam_op_network_tbl           := l_eam_op_network_tbl;
10492         x_eam_res_tbl                  := l_eam_res_tbl;
10493         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
10494         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
10495         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
10496         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
10497         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
10498 
10499 
10500     WHEN OTHERS THEN
10501 
10502     IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
10503         THEN
10504                 l_err_text := G_PKG_NAME || ' : Process WO ' || substrb(SQLERRM,1,200);
10505                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
10506                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10507                 ( p_Message_Text => l_err_text
10508                 , p_Mesg_Token_Tbl => l_Mesg_Token_Tbl
10509                 , x_Mesg_Token_Tbl => l_out_Mesg_Token_Tbl
10510                  );
10511                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
10512     END IF;
10513 
10514 
10515 	 l_out_eam_wo_rec            := l_eam_wo_rec;
10516          l_out_eam_op_tbl            := l_eam_op_tbl;
10517   	 l_out_eam_op_network_tbl    := l_eam_op_network_tbl;
10518          l_out_eam_res_tbl           := l_eam_res_tbl;
10519          l_out_eam_res_inst_tbl      := l_eam_res_inst_tbl;
10520 	 l_out_eam_sub_res_tbl       := l_eam_sub_res_tbl;
10521          l_out_eam_mat_req_tbl       := l_eam_mat_req_tbl;
10522          l_out_eam_direct_items_tbl       := l_eam_direct_items_tbl;
10523          l_out_eam_res_usage_tbl     := l_eam_res_usage_tbl;
10524         EAM_ERROR_MESSAGE_PVT.Log_Error
10525         (  p_eam_wo_rec             => l_eam_wo_rec
10526         ,  p_eam_op_tbl             => l_eam_op_tbl
10527         ,  p_eam_op_network_tbl     => l_eam_op_network_tbl
10528         ,  p_eam_res_tbl            => l_eam_res_tbl
10529         ,  p_eam_res_inst_tbl       => l_eam_res_inst_tbl
10530         ,  p_eam_sub_res_tbl        => l_eam_sub_res_tbl
10531         ,  p_eam_res_usage_tbl      => l_eam_res_usage_tbl
10532         ,  p_eam_mat_req_tbl        => l_eam_mat_req_tbl
10533                ,  p_eam_direct_items_tbl   => l_eam_direct_items_tbl
10534         ,  p_mesg_token_tbl         => l_mesg_token_tbl
10535         ,  p_error_status           => FND_API.G_RET_STS_ERROR
10536         ,  p_error_scope            => EAM_ERROR_MESSAGE_PVT.G_SCOPE_RECORD
10537         ,  p_other_status           => EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
10538         ,  p_other_message          => l_other_message
10539         ,  p_other_token_tbl        => l_other_token_tbl
10540         ,  p_error_level            => EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
10541         ,  x_eam_wo_rec             => l_out_eam_wo_rec
10542         ,  x_eam_op_tbl             => l_out_eam_op_tbl
10543         ,  x_eam_op_network_tbl     => l_out_eam_op_network_tbl
10544         ,  x_eam_res_tbl            => l_out_eam_res_tbl
10545         ,  x_eam_res_inst_tbl       => l_out_eam_res_inst_tbl
10546         ,  x_eam_sub_res_tbl        => l_out_eam_sub_res_tbl
10547         ,  x_eam_res_usage_tbl      => l_out_eam_res_usage_tbl
10548         ,  x_eam_mat_req_tbl        => l_out_eam_mat_req_tbl
10549                ,  x_eam_direct_items_tbl   => l_out_eam_direct_items_tbl
10550         );
10551 	 l_eam_wo_rec                := l_out_eam_wo_rec;
10552          l_eam_op_tbl                := l_out_eam_op_tbl;
10553          l_eam_op_network_tbl        := l_out_eam_op_network_tbl;
10554          l_eam_res_tbl               := l_out_eam_res_tbl;
10555          l_eam_res_inst_tbl          := l_out_eam_res_inst_tbl;
10556          l_eam_sub_res_tbl           := l_out_eam_sub_res_tbl;
10557          l_eam_mat_req_tbl           := l_out_eam_mat_req_tbl;
10558          l_eam_direct_items_tbl           := l_out_eam_direct_items_tbl;
10559          l_eam_res_usage_tbl         := l_out_eam_res_usage_tbl;
10560 
10561         l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
10562 
10563         x_msg_count                    := l_msg_count;
10564         x_return_status                := l_return_status;
10565         x_eam_wo_rec                   := l_eam_wo_rec;
10566         x_eam_op_tbl                   := l_eam_op_tbl;
10567         x_eam_op_network_tbl           := l_eam_op_network_tbl;
10568         x_eam_res_tbl                  := l_eam_res_tbl;
10569         x_eam_res_inst_tbl             := l_eam_res_inst_tbl;
10570         x_eam_sub_res_tbl              := l_eam_sub_res_tbl;
10571         x_eam_res_usage_tbl            := l_eam_res_usage_tbl;
10572         x_eam_mat_req_tbl              := l_eam_mat_req_tbl;
10573         x_eam_direct_items_tbl              := l_eam_direct_items_tbl;
10574 
10575 
10576 END PROCESS_WO;
10577 
10578 
10579 /**************************************************************************
10580 * Procedure :     Validate_Transaction_Type
10581 * Parameters IN : Transaction Type
10582 *                 Entity Name
10583 *                 Entity ID, so that it can be used in a meaningful message
10584 * Parameters OUT NOCOPY: Valid flag
10585 *                 Message Token Table
10586 * Purpose :       This procedure will check if the transaction type is valid
10587 *                 for a particular entity.
10588 ***************************************************************************/
10589 PROCEDURE Validate_Transaction_Type
10590 (   p_transaction_type              IN  NUMBER
10591 ,   p_entity_name                   IN  VARCHAR2
10592 ,   p_entity_id                     IN  VARCHAR2
10593 ,   x_valid_transaction             OUT NOCOPY BOOLEAN
10594 ,   x_Mesg_Token_Tbl                OUT NOCOPY EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type
10595 )
10596 IS
10597 l_mesg_token_tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
10598 l_out_mesg_token_tbl    EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
10599 l_token_tbl             EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type;
10600 
10601 BEGIN
10602     l_token_tbl(1).token_name := 'WIP_ENTITY_ID';
10603     l_token_tbl(1).token_value := p_entity_id;
10604 
10605     x_valid_transaction := TRUE;
10606 
10607 
10608     IF (p_entity_name IN ('WORK_ORDER')
10609         AND NVL(p_transaction_type, FND_API.G_MISS_NUM) NOT IN (EAM_PROCESS_WO_PVT.G_OPR_SYNC, EAM_PROCESS_WO_PVT.G_OPR_CREATE, EAM_PROCESS_WO_PVT.G_OPR_UPDATE)
10610        )
10611        OR
10612        (p_entity_name IN ('OPERATION','OPERATION_RESOURCE','RESOURCE_INSTANCE','SUB_RESOURCE','DIRECT_ITEMS','MATERIAL_REQUIREMENTS')
10613         AND NVL(p_transaction_type, FND_API.G_MISS_NUM) NOT IN (EAM_PROCESS_WO_PVT.G_OPR_SYNC, EAM_PROCESS_WO_PVT.G_OPR_CREATE, EAM_PROCESS_WO_PVT.G_OPR_UPDATE, EAM_PROCESS_WO_PVT.G_OPR_DELETE)
10614        )
10615        OR
10616        (p_entity_name IN ('OPERATION_NETWORK', 'RESOURCE_USAGE')
10617         AND NVL(p_transaction_type, FND_API.G_MISS_NUM) NOT IN (EAM_PROCESS_WO_PVT.G_OPR_CREATE, EAM_PROCESS_WO_PVT.G_OPR_DELETE)
10618        )
10619        OR
10620        (p_entity_name IN ('WORK_ORDER_COMPLETEION','OPERATION_COMPLETEION')
10621         AND NVL(p_transaction_type, FND_API.G_MISS_NUM) NOT IN (EAM_PROCESS_WO_PVT.G_OPR_COMPLETE, EAM_PROCESS_WO_PVT.G_OPR_UNCOMPLETE)
10622 	)
10623        OR
10624        (p_entity_name IN ('QUALITY_ENTRY','METER_READING')
10625         AND NVL(p_transaction_type, FND_API.G_MISS_NUM) NOT IN (EAM_PROCESS_WO_PVT.G_OPR_CREATE)
10626 	)
10627        OR
10628        (p_entity_name IN ('WORK_ORDER_COMPL_REBUILD','W_ORDER_COMPL_METER_READING')
10629         AND NVL(p_transaction_type, FND_API.G_MISS_NUM) NOT IN (EAM_PROCESS_WO_PVT.G_OPR_UPDATE)
10630         )
10631        OR
10632        (p_entity_name IN ('WORK_SERVICE_REQUEST')
10633         AND NVL(p_transaction_type, FND_API.G_MISS_NUM) NOT IN (EAM_PROCESS_WO_PVT.G_OPR_CREATE,EAM_PROCESS_WO_PVT.G_OPR_UPDATE)
10634 	)
10635 
10636     THEN
10637 
10638         IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_ERROR)
10639         THEN
10640             IF p_entity_name = 'WORK_ORDER'
10641             THEN
10642                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
10643                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10644                 ( p_Message_Name       => 'EAM_WO_TXN_TYPE_INVALID'
10645                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
10646                 , x_Mesg_Token_Tbl     => l_out_Mesg_Token_Tbl
10647                 );
10648                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
10649             ELSIF p_entity_name = 'OPERATION'
10650             THEN
10651                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
10652                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10653                 ( p_Message_Name       => 'EAM_OP_TXN_TYPE_INVALID'
10654                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
10655                 , x_Mesg_Token_Tbl     => l_out_Mesg_Token_Tbl
10656                 );
10657                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
10658             ELSIF p_entity_name = 'OPERATION_NETWORK'
10659             THEN
10660                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
10661                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10662                 ( p_Message_Name       => 'EAM_OPN_TXN_TYPE_INVALID'
10663                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
10664                 , x_Mesg_Token_Tbl     => l_out_Mesg_Token_Tbl
10665                 );
10666                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
10667             ELSIF p_entity_name = 'OPERATION_RESOURCE'
10668             THEN
10669                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
10670                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10671                 ( p_Message_Name       => 'EAM_RES_TXN_TYPE_INVALID'
10672                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
10673                 , x_Mesg_Token_Tbl     => l_out_Mesg_Token_Tbl
10674                 );
10675                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
10676             ELSIF p_entity_name = 'SUB_RESOURCE'
10677             THEN
10678                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
10679                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10680                 ( p_Message_Name       => 'EAM_SR_TXN_TYPE_INVALID'
10681                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
10682                 , x_Mesg_Token_Tbl     => l_out_Mesg_Token_Tbl
10683                 );
10684                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
10685             ELSIF p_entity_name = 'RESOURCE_INSTANCE'
10686             THEN
10687                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
10688                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10689                 ( p_Message_Name       => 'EAM_RI_TXN_TYPE_INVALID'
10690                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
10691                 , x_Mesg_Token_Tbl     => l_out_Mesg_Token_Tbl
10692                 );
10693                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
10694             ELSIF p_entity_name = 'RESOURCE_USAGE'
10695             THEN
10696                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
10697                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10698                 ( p_Message_Name       => 'EAM_RU_TXN_TYPE_INVALID'
10699                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
10700                 , x_Mesg_Token_Tbl     => l_out_Mesg_Token_Tbl
10701                 );
10702                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
10703             ELSIF p_entity_name = 'MATERIAL_REQUIREMENTS'
10704             THEN
10705                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
10706                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10707                 ( p_Message_Name       => 'EAM_MR_TXN_TYPE_INVALID'
10708                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
10709                 , x_Mesg_Token_Tbl     => l_out_Mesg_Token_Tbl
10710                 );
10711                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
10712             ELSIF p_entity_name = 'DIRECT_ITEMS'
10713             THEN
10714                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
10715                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10716                 ( p_Message_Name       => 'EAM_DI_TXN_TYPE_INVALID'
10717                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
10718                 , x_Mesg_Token_Tbl     => l_out_Mesg_Token_Tbl
10719                 );
10720                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
10721 	    ELSIF p_entity_name = 'WORK_ORDER_COMPLETEION'
10722             THEN
10723                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
10724                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10725                 ( p_Message_Name       => 'EAM_WOCOMPL_TXN_TYPE_INVALID'
10726                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
10727                 , x_Mesg_Token_Tbl     => l_out_Mesg_Token_Tbl
10728                 );
10729                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
10730 	    ELSIF p_entity_name = 'OPERATION_COMPLETEION'
10731             THEN
10732                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
10733                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10734                 ( p_Message_Name       => 'EAM_OPCOMPL_TXN_TYPE_INVALID'
10735                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
10736                 , x_Mesg_Token_Tbl     => l_out_Mesg_Token_Tbl
10737                 );
10738                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
10739 	    ELSIF p_entity_name = 'QUALITY_ENTRY'
10740             THEN
10741                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
10742                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10743                 ( p_Message_Name       => 'EAM_QA_TXN_TYPE_INVALID'
10744                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
10745                 , x_Mesg_Token_Tbl     => l_out_Mesg_Token_Tbl
10746                 );
10747                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
10748 	    ELSIF p_entity_name = 'METER_READING'
10749             THEN
10750                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
10751                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10752                 ( p_Message_Name       => 'EAM_MR_TXN_TYPE_INVALID'
10753                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
10754                 , x_Mesg_Token_Tbl     => l_out_Mesg_Token_Tbl
10755                 );
10756                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
10757 	    ELSIF p_entity_name = 'WORK_ORDER_COMPL_REBUILD'
10758             THEN
10759                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
10760                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10761                 ( p_Message_Name       => 'EAM_WOCOMRB_TXN_TYPE_INVALID'
10762                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
10763                 , x_Mesg_Token_Tbl     => l_out_Mesg_Token_Tbl
10764                 );
10765                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
10766 	    ELSIF p_entity_name = 'W_ORDER_COMPL_METER_READING'
10767             THEN
10768                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
10769                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10770                 ( p_Message_Name       => 'EAM_WOCOMMR_TXN_TYPE_INVALID'
10771                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
10772                 , x_Mesg_Token_Tbl     => l_out_Mesg_Token_Tbl
10773                 );
10774                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
10775 	    ELSIF p_entity_name = 'WORK_SERVICE_REQUEST'
10776             THEN
10777                 l_out_mesg_token_tbl  := l_mesg_token_tbl;
10778                 EAM_ERROR_MESSAGE_PVT.Add_Error_Token
10779                 ( p_Message_Name       => 'EAM_WORSER_TXN_TYPE_INVALID'
10780                 , p_Mesg_Token_Tbl     => l_Mesg_Token_Tbl
10781                 , x_Mesg_Token_Tbl     => l_out_Mesg_Token_Tbl
10782                 );
10783                 l_mesg_token_tbl      := l_out_mesg_token_tbl;
10784             END IF;
10785         END IF;
10786 
10787         x_mesg_token_tbl := l_Mesg_Token_Tbl;
10788         x_valid_transaction := FALSE;
10789 
10790     END IF;
10791 
10792 END Validate_Transaction_Type;
10793 
10794 
10795 PROCEDURE Set_Debug
10796     (  p_debug_flag     IN  VARCHAR2 )
10797     IS
10798 BEGIN
10799           EAM_PROCESS_WO_PUB.g_debug_flag := p_debug_flag;
10800 END Set_Debug;
10801 
10802 
10803 FUNCTION Get_Debug RETURN VARCHAR2
10804     IS
10805 BEGIN
10806           RETURN EAM_PROCESS_WO_PUB.g_debug_flag;
10807 END;
10808 
10809 --Fix for 3360801.the following procedure will update the records returned by the api with the correct dates
10810 
10811 PROCEDURE UPDATE_DATES
10812         (x_eam_wo_rec IN OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_rec_type,
10813 	 x_eam_op_tbl IN OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_tbl_type,
10814 	 x_eam_res_tbl IN OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_tbl_type,
10815 	 x_eam_res_inst_tbl IN OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type
10816 )
10817 IS
10818 CURSOR operations
10819 (l_wip_entity_id NUMBER,l_org_id NUMBER,l_op_seq_num NUMBER)
10820 IS
10821    SELECT first_unit_start_date,
10822           last_unit_completion_date
10823    FROM wip_operations
10824    WHERE wip_entity_id=l_wip_entity_id
10825    AND organization_id=l_org_id
10826    AND operation_seq_num=l_op_seq_num;
10827 
10828  l_operations operations%ROWTYPE;
10829 
10830 CURSOR resources
10831 (l_wip_entity_id NUMBER,l_org_id NUMBER,l_op_seq_num NUMBER,l_res_seq_num NUMBER)
10832 IS
10833    SELECT start_date,
10834           completion_date
10835    FROM wip_operation_resources
10836    WHERE wip_entity_id=l_wip_entity_id
10837    AND organization_id=l_org_id
10838    AND operation_seq_num=l_op_seq_num
10839    AND resource_seq_num=l_res_seq_num;
10840 
10841  l_resources resources%ROWTYPE;
10842 
10843  CURSOR resource_instances
10844 (l_wip_entity_id NUMBER,l_org_id NUMBER,l_op_seq_num NUMBER,l_res_seq_num NUMBER,l_instance_id NUMBER,l_serial_number NUMBER)
10845 IS
10846    SELECT start_date,
10847           completion_date
10848    FROM wip_op_resource_instances
10849    WHERE wip_entity_id=l_wip_entity_id
10850    AND organization_id=l_org_id
10851    AND operation_seq_num=l_op_seq_num
10852    AND resource_seq_num=l_res_seq_num
10853    AND instance_id=l_instance_id
10854    AND serial_number(+)=l_serial_number;
10855 
10856  l_resource_instances resource_instances%ROWTYPE;
10857 
10858     i   NUMBER := 0;
10859     l_start_date  DATE;
10860     l_completion_date  DATE;
10861 BEGIN
10862 
10863 --start of populating workorder dates
10864 IF(x_eam_wo_rec.TRANSACTION_TYPE IN (EAM_PROCESS_WO_PUB.G_OPR_CREATE,EAM_PROCESS_WO_PUB.G_OPR_UPDATE)) THEN
10865    SELECT scheduled_start_date,scheduled_completion_date
10866    INTO l_start_date,l_completion_date
10867    FROM WIP_DISCRETE_JOBS
10868    WHERE wip_entity_id=x_eam_wo_rec.wip_entity_id
10869    AND organization_id=x_eam_wo_rec.organization_id;
10870 
10871    x_eam_wo_rec.scheduled_start_date := l_start_date;
10872    x_eam_wo_rec.scheduled_completion_date := l_completion_date;
10873 END IF;
10874 --end of populating workorder dates
10875 
10876 --start of populating operation dates
10877 IF(x_eam_op_tbl.COUNT > 0) THEN
10878   i:=x_eam_op_tbl.FIRST;
10879   LOOP
10880        IF( x_eam_op_tbl(i).TRANSACTION_TYPE IN (EAM_PROCESS_WO_PUB.G_OPR_CREATE,EAM_PROCESS_WO_PUB.G_OPR_UPDATE)) THEN
10881               OPEN operations(x_eam_wo_rec.wip_entity_id,x_eam_wo_rec.organization_id
10882 			     ,x_eam_op_tbl(i).operation_seq_num);
10883 
10884 		FETCH operations INTO l_operations;
10885 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('op'||to_char(l_operations.last_unit_completion_date,'DD HH24:MI:SS')); END IF;
10886                     IF(operations%FOUND) THEN
10887 		        x_eam_op_tbl(i).start_date := l_operations.first_unit_start_date;
10888 			x_eam_op_tbl(i).completion_date := l_operations.last_unit_completion_date;
10889                     END IF;
10890 
10891               CLOSE operations;
10892 
10893          END IF;
10894      EXIT WHEN i=x_eam_op_tbl.LAST;
10895      i:=i+1;
10896   END LOOP;
10897 END IF;
10898 --end of populating operation dates
10899 
10900 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug(x_eam_res_tbl.COUNT); END IF;
10901 --start of populating resource dates
10902 IF(x_eam_res_tbl.COUNT > 0) THEN
10903   i:=x_eam_res_tbl.FIRST;
10904   LOOP
10905       IF( x_eam_res_tbl(i).TRANSACTION_TYPE IN (EAM_PROCESS_WO_PUB.G_OPR_CREATE,EAM_PROCESS_WO_PUB.G_OPR_UPDATE)) THEN
10906               OPEN resources(x_eam_wo_rec.wip_entity_id,x_eam_wo_rec.organization_id
10907 			     ,x_eam_res_tbl(i).operation_seq_num,x_eam_res_tbl(i).resource_seq_num);
10908 
10909 			FETCH resources INTO l_resources;
10910 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('resources dates passed'||to_char(l_resources.completion_date,'DD HH24:MI:SS')); END IF;
10911                     IF(resources%FOUND) THEN
10912 			x_eam_res_tbl(i).start_date := l_resources.start_date;
10913 			x_eam_res_tbl(i).completion_date := l_resources.completion_date;
10914                     END IF;
10915 
10916               CLOSE resources;
10917        END IF;
10918 
10919      EXIT WHEN i=x_eam_res_tbl.LAST;
10920      i:=i+1;
10921   END LOOP;
10922 END IF;
10923 --end of populating resource dates
10924 
10925 --start of populating resource instance dates
10926 IF(x_eam_res_inst_tbl.COUNT > 0) THEN
10927   i:=x_eam_res_inst_tbl.FIRST;
10928   LOOP
10929         IF( x_eam_res_inst_tbl(i).TRANSACTION_TYPE IN (EAM_PROCESS_WO_PUB.G_OPR_CREATE,EAM_PROCESS_WO_PUB.G_OPR_UPDATE)) THEN
10930               OPEN resource_instances(x_eam_wo_rec.wip_entity_id,x_eam_wo_rec.organization_id
10931 			     ,x_eam_res_inst_tbl(i).operation_seq_num,x_eam_res_inst_tbl(i).resource_seq_num
10932 			     ,x_eam_res_inst_tbl(i).instance_id,x_eam_res_inst_tbl(i).serial_number);
10933 
10934 			FETCH resource_instances INTO l_resource_instances;
10935 IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('resource instances  dates passed'||to_char(l_resource_instances.completion_date,'DD HH24:MI:SS')); END IF;
10936                    IF(resource_instances%FOUND) THEN
10937 			x_eam_res_inst_tbl(i).start_date := l_resource_instances.start_date;
10938 			x_eam_res_inst_tbl(i).completion_date := l_resource_instances.completion_date;
10939                    END IF;
10940 
10941               CLOSE resource_instances;
10942 
10943 	 END IF;
10944      EXIT WHEN i=x_eam_res_inst_tbl.LAST;
10945      i:=i+1;
10946   END LOOP;
10947 END IF;
10948 --end  of populating resource instance dates
10949 
10950 EXCEPTION
10951   WHEN OTHERS THEN
10952      IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Dates could not be populated back to the records') ; END IF ;
10953 END UPDATE_DATES;
10954 
10955 
10956 
10957 
10958 
10959 
10960 
10961  PROCEDURE COMP_UNCOMP_WORKORDER
10962 	(
10963 	   p_eam_wo_comp_rec             IN  EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type
10964 	 , p_eam_wo_quality_tbl          IN  EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type
10965 	 , p_eam_meter_reading_tbl       IN  EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type
10966  	 , p_eam_counter_prop_tbl        IN  EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type
10967 	 , p_eam_wo_comp_rebuild_tbl     IN  EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type
10968 	 , p_eam_wo_comp_mr_read_tbl     IN  EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type
10969 	 , x_eam_wo_comp_rec             OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type
10970 	 , x_eam_wo_quality_tbl          OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type
10971 	 , x_eam_meter_reading_tbl       OUT NOCOPY EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type
10972  	 , x_eam_counter_prop_tbl        OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type
10973 	 , x_eam_wo_comp_rebuild_tbl     OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type
10974 	 , x_eam_wo_comp_mr_read_tbl     OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type
10975 	 , x_return_status               OUT NOCOPY VARCHAR2
10976 	 , x_msg_count                   OUT NOCOPY NUMBER
10977 	)IS
10978 
10979 	l_valid_transaction		BOOLEAN := TRUE ;
10980 	l_eam_wo_comp_rec		EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
10981 	l_eam_out_wo_comp_rec		EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
10982 
10983 	l_mesg_token_tbl		EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
10984 	l_return_status			VARCHAR2(1) ;
10985 	l_other_message			VARCHAR2(2000);
10986 	l_other_token_tbl		EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
10987 	msg_index			NUMBER;
10988 	temp_err_mesg			VARCHAR2(4000);
10989 	l_msg_count			NUMBER;
10990 
10991 	l_eam_wo_quality_tbl            EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type	:= p_eam_wo_quality_tbl;
10992 	l_eam_meter_reading_tbl         EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type	:= p_eam_meter_reading_tbl;
10993 	l_eam_wo_comp_rebuild_tbl       EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type := p_eam_wo_comp_rebuild_tbl;
10994 	l_eam_wo_comp_mr_read_tbl       EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type := p_eam_wo_comp_mr_read_tbl;
10995 	l_eam_counter_prop_tbl			EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type	:= p_eam_counter_prop_tbl;
10996 	l_eam_op_comp_tbl               EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
10997 	l_eam_request_tbl               EAM_PROCESS_WO_PUB.eam_request_tbl_type;
10998 
10999 	l_out_eam_wo_comp_rec			EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
11000 	l_out_eam_wo_quality_tbl        EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type;
11001 	l_out_eam_meter_reading_tbl     EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type;
11002 	l_out_eam_counter_prop_tbl		EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type;
11003 	l_out_eam_wo_comp_rebuild_tbl   EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type;
11004 	l_out_eam_wo_comp_mr_read_tbl   EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type;
11005 	l_out_eam_op_comp_tbl           EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
11006 	l_out_eam_request_tbl           EAM_PROCESS_WO_PUB.eam_request_tbl_type;
11007 
11008 	l_transaction_number		NUMBER;
11009 	l_eam_wo_quality_rec		EAM_PROCESS_WO_PUB.eam_wo_quality_rec_type;
11010 	colllection_id_temp			NUMBER;
11011 	l_org_id				NUMBER;
11012 	l_asset_group_id		NUMBER;
11013 	l_asset_number			VARCHAR2(30);
11014 	l_asset_instance_id		NUMBER;
11015 	l_asset_activity_id		NUMBER;
11016 	l_asset_activity		VARCHAR2(240);
11017 	l_asset_group_name		VARCHAR2(240);
11018 	l_wip_entity_name		VARCHAR2(240);
11019 	mandatory_qua_plan		VARCHAR2(1);
11020 	contextStr				VARCHAR2(2000);
11021 	l_wip_entity_id			NUMBER;
11022 	l_out_mesg_token_tbl	EAM_ERROR_MESSAGE_PVT.mesg_token_tbl_type;
11023 	l_msg_data				VARCHAR2(2000);
11024 	l_token_tbl				EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
11025 	l_man_reading_enter		BOOLEAN;
11026 	l_maint_object_type		NUMBER;
11027 	l_maint_object_id		NUMBER;
11028 	l_error_message			VARCHAR2(2000);
11029 	l_instance_number		VARCHAR2(30);  -- From CII table
11030 	l_maint_obj_source              NUMBER;
11031 	l_pending_flag                  VARCHAR2(1);
11032 	l_workflow_enabled              VARCHAR2(1);
11033 	l_approval_required             BOOLEAN;
11034 	l_workflow_name                 VARCHAR2(200);
11035 	l_workflow_process              VARCHAR2(200);
11036 	l_status_pending_event          VARCHAR2(240);
11037 	l_status_changed_event          VARCHAR2(240);
11038 	l_new_eam_status                NUMBER;
11039 	l_new_system_status             NUMBER;
11040 	l_old_eam_status                NUMBER;
11041         l_old_system_status         NUMBER;
11042 	l_workflow_type                 NUMBER;
11043 	l_event_name			VARCHAR2(240);
11044 	l_parameter_list		wf_parameter_list_t;
11045 	l_event_key				VARCHAR2(200);
11046 	l_wf_event_seq			NUMBER;
11047 	l_cost_estimate         NUMBER;
11048 	l_asset_instance_number	VARCHAR2(30);
11049 	l_instance_id			NUMBER;
11050 
11051 	l_asset_ops_msg_count	        NUMBER;
11052 	l_asset_ops_msg_data		VARCHAR2(2000);
11053 	l_asset_ops_return_status	VARCHAR2(1);
11054 	l_eam_location_id		NUMBER;
11055 	l_department_id			NUMBER;
11056 
11057 	l_comments_exists         VARCHAR2(1);
11058 
11059 	CURSOR cur_work_order_details IS
11060 	SELECT  cii.inventory_item_id,
11061 	        cii.instance_number,
11062 		cii.instance_id,
11063 		cii.serial_number,
11064 		wdj.primary_item_id,
11065 		wdj.maintenance_object_type,
11066 		wdj.maintenance_object_id,
11067 		wdj.maintenance_object_source,
11068                 NVL(ewod.pending_flag,'N'),
11069 		ewod.user_defined_status_id,
11070 		wdj.status_type,
11071 		ewod.workflow_type,
11072 		eam_linear_location_id,
11073 		owning_department
11074 	  FROM  wip_discrete_jobs wdj,csi_item_instances cii,eam_work_order_details ewod
11075 	 WHERE  wdj.wip_entity_id = l_eam_wo_comp_rec.wip_entity_id
11076 	   AND  wdj.maintenance_object_type = 3
11077 	   AND  wdj.maintenance_object_id = cii.instance_id
11078 	   AND  wdj.wip_entity_id = ewod.wip_entity_id(+)
11079 	 UNION
11080         SELECT  wdj.maintenance_object_id,
11081 		null,
11082 		null,
11083 		null,
11084 		wdj.primary_item_id,
11085 		wdj.maintenance_object_type,
11086 		wdj.maintenance_object_id,
11087 		wdj.maintenance_object_source,
11088                 NVL(ewod.pending_flag,'N'),
11089 		ewod.user_defined_status_id,
11090 		wdj.status_type,
11091 		ewod.workflow_type,
11092 		eam_linear_location_id,
11093 		owning_department
11094 	  FROM  wip_discrete_jobs wdj,eam_work_order_details ewod
11095 	 WHERE  wdj.wip_entity_id = l_eam_wo_comp_rec.wip_entity_id
11096 	   AND  wdj.maintenance_object_type = 2
11097 	   AND  wdj.wip_entity_id = ewod.wip_entity_id(+);
11098 
11099 	   l_eam_failure_entry_record Eam_Process_Failure_Entry_PUB.eam_failure_entry_record_typ;
11100        l_eam_failure_codes_tbl Eam_Process_Failure_Entry_PUB.eam_failure_codes_tbl_typ;
11101 
11102        x_out_eam_failure_entry_record Eam_Process_Failure_Entry_PUB.eam_failure_entry_record_typ;
11103       x_out_eam_failure_codes_tbl    Eam_Process_Failure_Entry_PUB.eam_failure_codes_tbl_typ;
11104 
11105 
11106 
11107 BEGIN
11108 		 SAVEPOINT sv_wo_compl ;
11109 
11110 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Inside COMP_UNCOMP_WORKORDER procedure . . . ');  END IF;
11111 
11112 		 l_eam_failure_entry_record := p_eam_wo_comp_rec.eam_failure_entry_record;
11113 	         l_eam_failure_codes_tbl    := p_eam_wo_comp_rec.eam_failure_codes_tbl;
11114 
11115 		x_return_status		     := FND_API.G_RET_STS_SUCCESS;
11116 	        l_eam_wo_comp_rec            := p_eam_wo_comp_rec;
11117 
11118 		SELECT wip_entity_name INTO l_wip_entity_name
11119 		  FROM wip_entities
11120 		 WHERE wip_entity_id = l_eam_wo_comp_rec.wip_entity_id;
11121 
11122 		l_org_id		:= l_eam_wo_comp_rec.organization_id;
11123 		l_wip_entity_id		:= l_eam_wo_comp_rec.wip_entity_id;
11124 
11125 		 OPEN cur_work_order_details;
11126 
11127 		 FETCH cur_work_order_details INTO
11128 		       l_asset_group_id,
11129 		       l_instance_number,
11130 		       l_instance_id,
11131 		       l_asset_number,
11132 		       l_asset_activity_id,
11133 		       l_maint_object_type,
11134 		       l_maint_object_id,
11135 		       l_maint_obj_source,
11136 		       l_pending_flag,
11137 		       l_old_eam_status,
11138 		       l_old_system_status,
11139 		       l_workflow_type,
11140 		       l_eam_location_id,
11141 		       l_department_id;
11142 
11143 		CLOSE cur_work_order_details;
11144 
11145 		SELECT msi.concatenated_segments
11146 		   INTO l_asset_group_name
11147 	           FROM mtl_system_items_kfv msi
11148 		  WHERE msi.inventory_item_id = l_asset_group_id
11149 		   AND rownum = 1;
11150 
11151 		Begin
11152 	  	  SELECT msi.concatenated_segments
11153 		   INTO l_asset_activity
11154 	           FROM mtl_system_items_kfv msi
11155 		  WHERE msi.inventory_item_id = l_asset_activity_id
11156 		   AND rownum = 1;
11157 	        Exception
11158 		  When NO_DATA_FOUND Then
11159 		    l_asset_activity := null;
11160 		End;
11161 
11162 		l_workflow_enabled := Is_Workflow_Enabled(l_maint_obj_source, l_eam_wo_comp_rec.organization_id);
11163 		l_status_changed_event := 'oracle.apps.eam.workorder.status.changed';
11164 		l_status_pending_event := 'oracle.apps.eam.workorder.status.change.pending';
11165 
11166 	        IF(l_eam_wo_comp_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_COMPLETE) THEN
11167 		    l_new_system_status  := 4;           --can be complete/complete-no-charges...get from completion record
11168 		    l_new_eam_status   := 4;         --get value from completion record
11169 	        ELSE
11170 		    l_new_system_status := 3;
11171 		    l_new_eam_status := 3;
11172 	        END IF;
11173 
11174 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Work Order Completeion: Transaction Type Validity . . . ');  END IF;
11175 
11176 		VALIDATE_TRANSACTION_TYPE
11177 		(   p_transaction_type  => l_eam_wo_comp_rec.transaction_type
11178 		,   p_entity_name       => 'WORK_ORDER_COMPLETEION'
11179 		,   p_entity_id         => l_eam_wo_comp_rec.wip_entity_id
11180 		,   x_valid_transaction => l_valid_transaction
11181 		,   x_mesg_token_tbl    => l_Mesg_Token_Tbl
11182 		);
11183 
11184 		IF NOT l_valid_transaction
11185 		THEN
11186 		    l_return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
11187 		    l_other_message := 'EAM_WOCMPL_INV_TXN_TYPE';
11188 		    l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11189 		    l_other_token_tbl(1).token_value := l_wip_entity_name;
11190 
11191 		    RAISE EXC_SEV_QUIT_RECORD;
11192 		END IF;
11193 
11194 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('EAM WO Completeion:  Populate Null Columns . . .'); END IF;
11195 
11196 		EAM_WO_COMP_DEFAULT_PVT.Populate_NULL_Columns
11197 		(   p_eam_wo_comp_rec         => p_eam_wo_comp_rec
11198 		,   x_eam_wo_comp_rec         => l_eam_wo_comp_rec
11199 		,   x_return_status           => l_return_status
11200 		);
11201 
11202 		IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
11203 		THEN
11204 			l_other_message := 'EAM_WOCMPL_POPULATE_NULL';
11205 			l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11206 			l_other_token_tbl(1).token_value := l_wip_entity_name;
11207 			RAISE EXC_SEV_QUIT_RECORD;
11208 
11209 		END IF;
11210 
11211 
11212 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('WO Completeion : Check Attributes b4 Defaulting . . .'); END IF;
11213 		EAM_WO_COMP_VALIDATE_PVT.Check_Attributes_b4_Defaulting
11214 		 ( p_eam_wo_comp_rec            => l_eam_wo_comp_rec
11215 		 , x_mesg_token_tbl             => l_mesg_token_tbl
11216 		 , x_return_status              => l_return_status
11217 		 ) ;
11218 
11219 
11220 		IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
11221 		THEN
11222 			l_other_message := 'EAM_WOCMPL_CHK_ATTR_DEF';
11223 			l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11224 			l_other_token_tbl(1).token_value := l_wip_entity_name;
11225 			RAISE EXC_SEV_QUIT_RECORD;
11226 		END IF;
11227 
11228 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('WO Completeion : Check Required . . .'); END IF;
11229 		EAM_WO_COMP_VALIDATE_PVT.Check_Required
11230 		 ( p_eam_wo_comp_rec            => l_eam_wo_comp_rec
11231 		 , x_return_status              => l_return_status
11232 		 , x_mesg_token_tbl             => l_mesg_token_tbl
11233 		 ) ;
11234 		IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
11235 		THEN
11236 			l_other_message := 'EAM_WOCMPL_CHK_REQUIRED';
11237 			l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11238 			l_other_token_tbl(1).token_value := l_wip_entity_name;
11239 			RAISE EXC_SEV_QUIT_RECORD;
11240 		END IF;
11241 
11242 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('WO Completeion Header: Check Attributes . . .'); END IF;
11243 
11244 		EAM_WO_COMP_VALIDATE_PVT.Check_Attributes
11245 		    (
11246 			p_eam_wo_comp_rec          => l_eam_wo_comp_rec
11247 		    ,   x_eam_wo_comp_rec          => l_eam_out_wo_comp_rec
11248 		    ,   x_return_status            => l_return_status
11249 		    ,   x_Mesg_Token_Tbl           => l_Mesg_Token_Tbl
11250 		    );
11251 
11252 		l_eam_wo_comp_rec := l_eam_out_wo_comp_rec;
11253 		x_return_status := l_return_status;
11254 
11255 		IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
11256 		THEN
11257 			l_other_message := 'EAM_WOCMPL_CHK_ATTR';
11258 			l_other_token_tbl(1).token_name := 'WIP_ENTITY_NAME';
11259 			l_other_token_tbl(1).token_value := l_wip_entity_name;
11260 			RAISE EXC_SEV_QUIT_RECORD;
11261 		END IF;
11262 
11263 
11264 	IF(l_workflow_enabled='Y'  AND    l_eam_wo_comp_rec.transaction_type=EAM_PROCESS_WO_PVT.G_OPR_UNCOMPLETE
11265 	                  AND (WF_EVENT.TEST(l_status_pending_event) <> 'NONE') )THEN
11266 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Checking WF Approval mandatory . . . ');  END IF;
11267 							 EAM_WORKFLOW_DETAILS_PUB.Eam_Wf_Is_Approval_Required(p_old_wo_rec =>  NULL,
11268 															   p_new_wo_rec  =>  NULL,
11269 															    p_wip_entity_id        =>    l_eam_wo_comp_rec.wip_entity_id,
11270 															    p_new_system_status  =>  l_new_system_status,
11271 															    p_new_wo_status           =>  l_new_eam_status,
11272 															    p_old_system_status     =>   l_old_system_status,
11273 															    p_old_wo_status             =>   l_old_eam_status,
11274 															   x_approval_required  =>  l_approval_required,
11275 															   x_workflow_name   =>   l_workflow_name,
11276 															   x_workflow_process    =>   l_workflow_process
11277 															   );
11278 
11279 						IF(l_approval_required) THEN
11280 								   UPDATE EAM_WORK_ORDER_DETAILS
11281 								   SET user_defined_status_id=3,
11282 									    pending_flag='Y',
11283 									    last_update_date=SYSDATE,
11284 									    last_update_login=FND_GLOBAL.login_id,
11285 									    last_updated_by=FND_GLOBAL.user_id
11286 								   WHERE wip_entity_id= l_eam_wo_comp_rec.wip_entity_id;
11287 
11288 
11289 
11290                                                             --Find the total estimated cost of workorder
11291 											   BEGIN
11292 												 SELECT NVL((SUM(system_estimated_mat_cost) + SUM(system_estimated_lab_cost) + SUM(system_estimated_eqp_cost)),0)
11293 												 INTO l_cost_estimate
11294 												 FROM WIP_EAM_PERIOD_BALANCES
11295 												 WHERE wip_entity_id = l_eam_wo_comp_rec.wip_entity_id;
11296 											   EXCEPTION
11297 											      WHEN NO_DATA_FOUND THEN
11298 												  l_cost_estimate := 0;
11299 											   END;
11300 
11301 
11302 										      SELECT EAM_WORKFLOW_EVENT_S.NEXTVAL
11303 										      INTO l_wf_event_seq
11304 										      FROM DUAL;
11305 
11306 										      l_parameter_list := wf_parameter_list_t();
11307 										      l_event_name := l_status_pending_event;
11308 
11309 										    l_event_key := TO_CHAR(l_wf_event_seq);
11310 
11311 
11312 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Inserting into EAM_WO_WORKFLOWS ...');  END IF;
11313 										     INSERT INTO EAM_WO_WORKFLOWS
11314 										     (WIP_ENTITY_ID,WF_ITEM_TYPE,WF_ITEM_KEY,LAST_UPDATE_DATE,LAST_UPDATED_BY,
11315 										     CREATION_DATE,CREATED_BY,LAST_UPDATE_LOGIN)
11316 										     VALUES
11317 										     (l_eam_wo_comp_rec.wip_entity_id,l_workflow_name,l_event_key,SYSDATE,FND_GLOBAL.user_id,
11318 										     SYSDATE,FND_GLOBAL.user_id,FND_GLOBAL.login_id
11319 										     );
11320 
11321 
11322 										    WF_CORE.CONTEXT('Enterprise Asset Management...','Work Order Released change event','Building parameter list');
11323 										    -- Add Parameters
11324 										    Wf_Event.AddParameterToList(p_name =>'WIP_ENTITY_ID',
11325 													    p_value => TO_CHAR(l_eam_wo_comp_rec.wip_entity_id),
11326 													    p_parameterlist => l_parameter_list);
11327 										    Wf_Event.AddParameterToList(p_name =>'WIP_ENTITY_NAME',
11328 													    p_value =>l_wip_entity_name,
11329 													    p_parameterlist => l_parameter_list);
11330 										    Wf_Event.AddParameterToList(p_name =>'ORGANIZATION_ID',
11331 													    p_value => TO_CHAR(l_eam_wo_comp_rec.organization_id),
11332 													    p_parameterlist => l_parameter_list);
11333 										    Wf_Event.AddParameterToList(p_name =>'NEW_WO_STATUS',
11334 													    p_value =>TO_CHAR(l_new_eam_status) ,
11335 													    p_parameterlist => l_parameter_list);
11336 										   Wf_Event.AddParameterToList(p_name =>'OLD_SYSTEM_STATUS',
11337 													    p_value => TO_CHAR(l_old_system_status),
11338 													    p_parameterlist => l_parameter_list);
11339 										    Wf_Event.AddParameterToList(p_name =>'OLD_WO_STATUS',
11340 													    p_value => TO_CHAR(l_old_eam_status),
11341 													    p_parameterlist => l_parameter_list);
11342 										    Wf_Event.AddParameterToList(p_name =>'NEW_SYSTEM_STATUS',
11343 													    p_value => TO_CHAR(l_new_system_status),
11344 													    p_parameterlist => l_parameter_list);
11345 										     Wf_Event.AddParameterToList(p_name =>'WORKFLOW_TYPE',
11346 													    p_value => TO_CHAR(l_workflow_type),
11347 													    p_parameterlist => l_parameter_list);
11348 										     Wf_Event.AddParameterToList(p_name =>'REQUESTOR',
11349 													    p_value =>FND_GLOBAL.USER_NAME ,
11350 													    p_parameterlist => l_parameter_list);
11351 										     Wf_Event.AddParameterToList(p_name =>'WORKFLOW_NAME',
11352 													    p_value => l_workflow_name,
11353 													    p_parameterlist => l_parameter_list);
11354 										     Wf_Event.AddParameterToList(p_name =>'WORKFLOW_PROCESS',
11355 													    p_value => l_workflow_process,
11356 													    p_parameterlist => l_parameter_list);
11357 										     Wf_Event.AddParameterToList(p_name =>'ESTIMATED_COST',
11358 													    p_value => TO_CHAR(l_cost_estimate),
11359 													    p_parameterlist => l_parameter_list);
11360 										    Wf_Core.Context('Enterprise Asset Management...','Work Order Released Event','Raising event');
11361 
11362 										    Wf_Event.Raise(	p_event_name => l_event_name,
11363 													p_event_key => l_event_key,
11364 													p_parameters => l_parameter_list);
11365 										    l_parameter_list.DELETE;
11366 										     WF_CORE.CONTEXT('Enterprise Asset Management...','Work Order Released Event','After raising event');
11367 
11368 
11369 										   IF(l_maint_obj_source =1 ) THEN     --modify intermedia index only for EAM workorders
11370 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling intermedia procedure from WO API ...');  END IF;
11371 													     EAM_TEXT_UTIL.PROCESS_WO_EVENT
11372 													     (
11373 														  p_event  => 'UPDATE',
11374 														  p_wip_entity_id =>l_eam_wo_comp_rec.wip_entity_id,
11375 														  p_organization_id =>l_eam_wo_comp_rec.organization_id,
11376 														  p_last_update_date  => SYSDATE,
11377 														  p_last_updated_by  => FND_GLOBAL.user_id,
11378 														  p_last_update_login =>FND_GLOBAL.login_id
11379 													     );
11380 										   END IF;   --end of check for maint. obj. source
11381 
11382                                                           RETURN;
11383 						END IF;
11384        END IF; -- end of check for workflow enabled
11385 
11386 
11387 		--Invoke Update_Pm_When_Uncomplete to reverse last service dates and last service reading if this is the last work order
11388 		--This should be called before Perform_Writes as the logic to calculate if this is the last work order or not will not work if record
11389 		-- will be inserted into Eam_Job_Completion_Txns for uncompletion transaction.
11390 		IF l_eam_wo_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UNCOMPLETE THEN
11391 			   if( l_maint_obj_source = 1) then -- added to check whether work order is of 'EAM' or 'CRMO'.'EAM=1'
11392 			           eam_pm_utils.update_pm_when_uncomplete(l_eam_wo_comp_rec.organization_id, l_eam_wo_comp_rec.wip_entity_id);
11393 			   end if; -- end of source entity check
11394 		END IF;
11395 
11396 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Writing WO Completion record to database ...');  END IF;
11397 		 EAM_WO_COMP_UTILITY_PVT.PERFORM_WRITES
11398 		(      p_eam_wo_comp_rec       => l_eam_wo_comp_rec
11399 		    ,   x_Mesg_Token_Tbl        => l_Mesg_Token_Tbl
11400 		    ,   x_return_status         => l_return_status
11401 		 );
11402 
11403 		IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
11404 		THEN
11405 		    l_other_message := 'EAM_WOCMPL_WRITES_UNEXP_SKIP';
11406 		    l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11407 		    l_other_token_tbl(1).token_value := l_wip_entity_name;
11408 		    RAISE EXC_SEV_QUIT_RECORD;
11409 		END IF;
11410 
11411 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling WO Completion update_row ...');  END IF;
11412 
11413 		 EAM_WO_COMP_UTILITY_PVT.update_row
11414 		(   p_eam_wo_comp_rec       => l_eam_wo_comp_rec
11415 		,   x_Mesg_Token_Tbl        => l_Mesg_Token_Tbl
11416 		,   x_return_status         => l_return_status
11417 		 );
11418 
11419 		IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_UNEXPECTED
11420 		THEN
11421 		    l_other_message := 'EAM_WOCMPL_WRITES_UNEXP_SKIP';
11422 		    l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11423 		    l_other_token_tbl(1).token_value := l_wip_entity_name;
11424 		    RAISE EXC_SEV_QUIT_RECORD;
11425 		END IF;
11426 
11427 		IF p_eam_wo_quality_tbl.COUNT > 0 AND l_eam_wo_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE THEN
11428 
11429 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Processing quality records...') ; END IF ;
11430 
11431 		    FOR I IN l_eam_wo_quality_tbl.FIRST..l_eam_wo_quality_tbl.LAST LOOP
11432 		      BEGIN
11433 
11434 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Processing '|| I || ' record') ; END IF ;
11435 
11436 				l_eam_wo_quality_rec := l_eam_wo_quality_tbl(I);
11437 				colllection_id_temp := l_eam_wo_quality_rec.collection_id;
11438 
11439 				VALIDATE_TRANSACTION_TYPE
11440 				(   p_transaction_type  => l_eam_wo_quality_rec.transaction_type
11441 				,   p_entity_name       => 'QUALITY_ENTRY'
11442 				,   p_entity_id         => to_char(l_eam_wo_quality_rec.plan_id)
11443 				,   X_valid_transaction => l_valid_transaction
11444 				,   x_mesg_token_tbl    => l_mesg_token_tbl
11445 				);
11446 
11447 				IF NOT l_valid_transaction
11448 				 THEN
11449 					l_other_message := 'EAM_WOCMP_QA_INV_TXN';
11450 					l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11451 					l_other_token_tbl(1).token_value := l_wip_entity_name;
11452 
11453 				     l_return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
11454 				     RAISE EXC_SEV_QUIT_RECORD;
11455 				 END IF ;
11456 
11457 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Quality : Check_Required...') ; END IF ;
11458 
11459 				 EAM_WO_QUA_VALIDATE_PVT.Check_Required
11460 				 (
11461 					p_eam_wo_quality_rec => l_eam_wo_quality_rec
11462 					, x_return_status    => l_return_status
11463 					, x_mesg_token_tbl   => l_mesg_token_tbl
11464 				 );
11465 
11466 				 IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR THEN
11467 					l_other_message := 'EAM_WOCMP_QA_CHK_REQ';
11468 					l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11469 					l_other_token_tbl(1).token_value := l_wip_entity_name;
11470 					RAISE EXC_SEV_QUIT_RECORD;
11471 				 END IF;
11472 
11473                      EXCEPTION
11474 
11475 		     WHEN EXC_SEV_SKIP_BRANCH THEN
11476 
11477 			l_out_eam_wo_quality_tbl	:= l_eam_wo_quality_tbl;
11478 			EAM_ERROR_MESSAGE_PVT.Log_Error
11479 		         (
11480 				p_eam_wo_quality_tbl		=>	l_eam_wo_quality_tbl
11481 
11482 			     , x_eam_wo_comp_rec		=>	l_out_eam_wo_comp_rec
11483 			     , x_eam_wo_quality_tbl		=>	l_out_eam_wo_quality_tbl
11484 			     , x_eam_meter_reading_tbl		=>	l_out_eam_meter_reading_tbl
11485 			     , x_eam_counter_prop_tbl		=>      l_out_eam_counter_prop_tbl
11486 			     , x_eam_wo_comp_rebuild_tbl	=>	l_out_eam_wo_comp_rebuild_tbl
11487 			     , x_eam_wo_comp_mr_read_tbl	=>	l_out_eam_wo_comp_mr_read_tbl
11488 			     , x_eam_op_comp_tbl		=>	l_out_eam_op_comp_tbl
11489 			     , x_eam_request_tbl		=>	l_out_eam_request_tbl
11490 
11491 			     , p_mesg_token_tbl			=>	l_mesg_token_tbl
11492 			     , p_error_status			=>	FND_API.G_RET_STS_ERROR
11493 			     , p_error_scope			=>	EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
11494 			     , p_other_message			=>	l_other_message
11495 			     , p_other_status			=>	EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
11496 			     , p_other_token_tbl		=>	l_other_token_tbl
11497 
11498 			     , p_error_level			=>	EAM_ERROR_MESSAGE_PVT.G_WO_COMP_LEVEL
11499 		         );
11500 
11501 				l_eam_wo_quality_tbl		:= l_out_eam_wo_quality_tbl;
11502 
11503 				l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
11504 
11505 				 x_eam_wo_quality_tbl		:=	l_eam_wo_quality_tbl;
11506 				 x_return_status          	:=	l_return_status;
11507 				 x_msg_count              	:=	l_msg_count;
11508 
11509 	              END ;
11510 
11511 		      IF l_return_status in ('Q', 'U','E')
11512 			   THEN
11513 			      x_return_status := l_return_status;
11514 			      RETURN ;
11515 		      END IF;
11516 
11517                     END LOOP;  -- End loop for p_eam_wo_quality_tbl.count > 0
11518 
11519 
11520 	            BEGIN
11521 
11522 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Quality : Insert_Row...') ; END IF ;
11523 
11524 			 EAM_WO_QUA_UTILITY_PVT.insert_row
11525 			   (
11526 				   p_collection_id	=> colllection_id_temp
11527 				 , p_eam_wo_quality_tbl  => p_eam_wo_quality_tbl
11528 				 , x_eam_wo_quality_tbl  => l_eam_wo_quality_tbl
11529 				 , x_return_status       => l_return_status
11530 				 , x_mesg_token_tbl      => l_mesg_token_tbl
11531 			   );
11532 			 IF l_return_status  <> 'S' THEN
11533 					l_other_message := 'EAM_WOCMP_QA_INSERT_REC';
11534 					l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11535 					l_other_token_tbl(1).token_value := l_wip_entity_name;
11536 					RAISE EXC_SEV_QUIT_RECORD;
11537 			 END IF;
11538 	            EXCEPTION
11539 		       WHEN EXC_SEV_QUIT_RECORD THEN
11540 				l_out_eam_wo_quality_tbl	:= l_eam_wo_quality_tbl;
11541 
11542 				EAM_ERROR_MESSAGE_PVT.Log_Error
11543 				 (
11544 					p_eam_wo_quality_tbl		=>	l_eam_wo_quality_tbl
11545 
11546 				     , x_eam_wo_comp_rec		=>	l_out_eam_wo_comp_rec
11547 				     , x_eam_wo_quality_tbl		=>	l_out_eam_wo_quality_tbl
11548 				     , x_eam_meter_reading_tbl		=>	l_out_eam_meter_reading_tbl
11549 				     , x_eam_counter_prop_tbl		=>      l_out_eam_counter_prop_tbl
11550 				     , x_eam_wo_comp_rebuild_tbl	=>	l_out_eam_wo_comp_rebuild_tbl
11551 				     , x_eam_wo_comp_mr_read_tbl	=>	l_out_eam_wo_comp_mr_read_tbl
11552 				     , x_eam_op_comp_tbl		=>	l_out_eam_op_comp_tbl
11553 				     , x_eam_request_tbl		=>	l_out_eam_request_tbl
11554 
11555 				     , p_mesg_token_tbl			=>	l_mesg_token_tbl
11556 				     , p_error_status			=>	FND_API.G_RET_STS_ERROR
11557 				     , p_error_scope			=>	EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
11558 				     , p_other_message			=>	l_other_message
11559 				     , p_other_status			=>	EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
11560 				     , p_other_token_tbl		=>	l_other_token_tbl
11561 
11562 				     , p_error_level			=>	EAM_ERROR_MESSAGE_PVT.G_WO_COMP_LEVEL
11563 			       );
11564 
11565 				l_eam_wo_quality_tbl		:= l_out_eam_wo_quality_tbl;
11566 
11567 				l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
11568 
11569 				 x_eam_wo_quality_tbl		:=	l_eam_wo_quality_tbl;
11570 				 x_return_status          	:=	l_return_status;
11571 				 x_msg_count              	:=	l_msg_count;
11572 	            END ; -- END For Quality Insert row
11573 
11574 	        END IF; -- END FOR Quality records.COUNT > 0
11575 
11576 		IF l_eam_wo_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE THEN
11577 			BEGIN
11578 
11579 			IF l_asset_number IS NOT NULL THEN
11580 
11581 				SELECT  cii.instance_number,cii.instance_id
11582 				  into l_asset_instance_number,
11583 				  l_asset_instance_id
11584 				  FROM  wip_discrete_jobs wdj,csi_item_instances cii
11585 				 WHERE  wdj.wip_entity_id = l_eam_wo_comp_rec.wip_entity_id
11586 				   AND  wdj.maintenance_object_type = 3
11587 				   AND  wdj.maintenance_object_id = cii.instance_id
11588 				   AND  cii.serial_number = l_asset_number;
11589 			END IF;
11590 
11591 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN
11592 			EAM_ERROR_MESSAGE_PVT.Write_Debug('Quality : Checking whether mandatory quality plans remain...') ; END IF ;
11593 				mandatory_qua_plan :=qa_web_txn_api.quality_mandatory_plans_remain(
11594 					p_txn_number       => 31 ,
11595 					p_organization_id  => l_org_id ,
11596 					pk1                => l_asset_group_name ,    -- Asset Grp
11597 					pk2                => l_asset_number  ,    -- Asset no
11598 					pk3                => l_asset_activity  ,    -- Asset Act
11599 					pk4                => l_wip_entity_name  ,    -- Work ordrr name
11600 				--	pk5		   => l_eam_op_comp_rec.operation_seq_num ,
11601 					pk6		   => l_asset_instance_number ,
11602 					p_wip_entity_id    => l_wip_entity_id  ,     -- work order id
11603 					p_collection_id    => l_eam_wo_comp_rec.qa_collection_id
11604 				 );
11605 
11606 				IF mandatory_qua_plan = 'Y' THEN
11607 
11608 					l_other_message := 'EAM_WOCMPL_MAND_PLAN';
11609 					l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11610 					l_other_token_tbl(1).token_value := l_wip_entity_name;
11611 
11612 					l_return_status := FND_API.G_RET_STS_ERROR;
11613 
11614 					RAISE EXC_SEV_QUIT_RECORD;
11615 
11616 				    /* l_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11617 				    l_token_tbl(1).token_value :=  l_wip_entity_name;
11618 
11619 				    l_out_mesg_token_tbl  := l_mesg_token_tbl;
11620 
11621 				    EAM_ERROR_MESSAGE_PVT.Add_Error_Token
11622 				    (  p_message_name	=> 'EAM_WOCMPL_MAND_PLAN'
11623 				     , p_token_tbl	=> l_Token_tbl
11624 				     , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
11625 				     , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
11626 				     );
11627 
11628 				    x_return_status := FND_API.G_RET_STS_ERROR;
11629 
11630 				   raise EXC_SEV_QUIT_RECORD; */
11631 
11632 				END IF;
11633 			END;
11634 		END IF;
11635 		IF l_eam_wo_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE  THEN
11636 		 /* Failure Analysis Project Start */
11637 	         --Failure Entry data to be processed at work order completion
11638                  --For Normal EAM Work Orders and Serialized rebuildable work orders
11639 
11640        IF (    l_asset_number   IS NOT NULL
11641           ) THEN
11642 
11643           l_comments_exists := 'N';
11644 
11645           FOR i in 1..l_eam_failure_codes_tbl.count
11646           LOOP
11647 
11648 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Processing failure entry records...') ; END IF ;
11649 
11650             IF l_eam_failure_codes_tbl(i).comments IS NOT NULL THEN
11651                l_comments_exists := 'Y';
11652             END IF;
11653 
11654             l_eam_failure_codes_tbl(i).failure_id      := l_eam_failure_entry_record.failure_id;
11655             IF l_eam_failure_codes_tbl(i).failure_entry_id IS NULL THEN
11656                l_eam_failure_codes_tbl(i).transaction_type:= Eam_Process_Failure_Entry_PUB.G_FE_CREATE;
11657             ELSE
11658                l_eam_failure_codes_tbl(i).transaction_type:= Eam_Process_Failure_Entry_PUB.G_FE_UPDATE;
11659             END IF;
11660 
11661             IF (    l_eam_failure_codes_tbl(i).failure_entry_id IS NULL
11662                 AND l_eam_failure_codes_tbl(i).failure_code IS NULL
11663                 AND l_eam_failure_codes_tbl(i).cause_code IS NULL
11664                 AND l_eam_failure_codes_tbl(i).resolution_code IS NULL
11665                 AND l_eam_failure_codes_tbl(i).COMMENTS IS NULL
11666                )
11667             THEN
11668               l_eam_failure_codes_tbl.delete(i);
11669             END IF;
11670           END LOOP;
11671 
11672 	  /* Failure Entry Project */
11673           IF (l_department_id IS NULL) THEN
11674 	    BEGIN
11675                 SELECT OWNING_DEPARTMENT_ID
11676                   INTO l_department_id
11677                   FROM eam_org_maint_defaults
11678                  WHERE object_id = l_maint_object_id
11679 		   AND object_type = 60 AND organization_id = l_org_id ;
11680             EXCEPTION
11681 	        WHEN NO_DATA_FOUND THEN
11682                     null;
11683             END;
11684           END IF;
11685 
11686 	  /* Failure Entry Project */
11687           IF (l_eam_location_id IS NULL) THEN
11688 	    BEGIN
11689                 SELECT area_id
11690                   INTO l_eam_location_id
11691                   FROM eam_org_maint_defaults
11692                  WHERE object_id = l_maint_object_id
11693 		   AND object_type = 60 AND organization_id = l_org_id ;
11694             EXCEPTION
11695 	        WHEN NO_DATA_FOUND THEN
11696                     null;
11697             END;
11698           END IF;
11699 
11700 
11701              /* Failure Entry Project */
11702 
11703           IF (    l_eam_failure_entry_record.failure_id IS NULL
11704               AND (   l_comments_exists = 'Y'
11705                    OR l_eam_failure_entry_record.failure_date IS NOT NULL
11706                   )
11707              )
11708           THEN
11709              l_eam_failure_entry_record.transaction_type:= Eam_Process_Failure_Entry_PUB.G_FE_CREATE;
11710              l_eam_failure_entry_record.source_type             := 1;
11711              l_eam_failure_entry_record.source_id               := l_wip_entity_id;
11712              l_eam_failure_entry_record.object_type             := l_maint_object_type;
11713              l_eam_failure_entry_record.object_id               := l_maint_object_id;
11714              l_eam_failure_entry_record.maint_organization_id   := l_org_id;
11715              l_eam_failure_entry_record.current_organization_id := l_org_id;
11716              l_eam_failure_entry_record.department_id           := l_department_id;
11717              l_eam_failure_entry_record.area_id                 := l_eam_location_id;
11718           ELSIF l_eam_failure_entry_record.failure_id IS NOT NULL THEN
11719              l_eam_failure_entry_record.transaction_type := Eam_Process_Failure_Entry_PUB.G_FE_UPDATE;
11720              l_eam_failure_entry_record.maint_organization_id   := l_org_id;
11721              l_eam_failure_entry_record.current_organization_id := l_org_id;
11722              l_eam_failure_entry_record.department_id           := l_department_id;
11723              l_eam_failure_entry_record.area_id                 := l_eam_location_id;
11724           END IF;
11725 
11726           IF (   l_eam_failure_entry_record.failure_date IS NOT NULL
11727               OR l_comments_exists = 'Y'
11728               OR l_eam_failure_entry_record.failure_id IS NOT NULL
11729              )
11730           THEN
11731 		IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling process_failure_entry procedure...') ; END IF ;
11732                   Eam_Process_Failure_Entry_PUB.process_failure_entry
11733                   (
11734                      p_eam_failure_entry_record     => l_eam_failure_entry_record
11735                    , p_eam_failure_codes_tbl        => l_eam_failure_codes_tbl
11736                    , x_return_status                => l_return_status
11737                    , x_msg_count                    => l_msg_count
11738                    , x_msg_data                     => l_msg_data
11739                    , x_eam_failure_entry_record     => l_eam_wo_comp_rec.eam_failure_entry_record
11740                    , x_eam_failure_codes_tbl        => l_eam_wo_comp_rec.eam_failure_codes_tbl
11741                   );
11742 
11743                   /* IF l_return_status <> 'S' THEN
11744                      errCode := 1;
11745                      errMsg := Fnd_Msg_Pub.Get(1,Fnd_Api.G_FALSE);
11746                      return;
11747                   END IF; */
11748 		IF NVL(l_return_status, 'T') <> 'S' THEN
11749 			l_return_status := 'E';
11750 			RAISE EXC_SEV_QUIT_RECORD;
11751 		END IF;
11752 
11753           END IF;
11754 
11755        END IF;
11756        /* Failure Analysis Project End */
11757 
11758       END IF;
11759 
11760 		IF l_eam_wo_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE  THEN
11761 
11762 		        BEGIN
11763 			    contextStr := '162='||l_asset_group_id||'@163='
11764 			    ||l_asset_number||'@2147483550='||l_asset_instance_id||'@165='||l_wip_entity_id
11765 			    ||'@164='||l_asset_activity_id;
11766 
11767 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling post_background_results procedure...') ; END IF ;
11768 			    qa_web_txn_api.post_background_results(
11769 				p_txn_number         =>  31 ,
11770 				p_org_id             => l_org_id  ,
11771 				p_context_values     => contextStr ,
11772 				p_collection_id      => l_eam_wo_comp_rec.qa_collection_id
11773 			    );
11774 		        EXCEPTION WHEN OTHERS THEN
11775 			    l_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11776 			    l_token_tbl(1).token_value :=  l_wip_entity_name;
11777 
11778 			    l_out_mesg_token_tbl  := l_mesg_token_tbl;
11779 
11780 			    EAM_ERROR_MESSAGE_PVT.Add_Error_Token
11781 			    (  p_message_name	=> 'EAM_WO_CMPL_BACK_ERR'
11782 			     , p_token_tbl	=> l_Token_tbl
11783 			     , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
11784 			     , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
11785 			     );
11786 
11787 			    x_return_status := FND_API.G_RET_STS_ERROR;
11788 
11789 			   RAISE EXC_SEV_QUIT_RECORD;
11790 		        END ;
11791 
11792 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling enable_and_fire_action procedure...') ; END IF ;
11793 
11794 			qa_result_grp.enable_and_fire_action(
11795 			 p_api_version         => 1.0  ,
11796 			 p_collection_id       => l_eam_wo_comp_rec.qa_collection_id   ,
11797 			 x_return_status       => l_return_status  ,
11798 			 x_msg_count           => l_msg_count   ,
11799 			 x_msg_data            => l_msg_data
11800 		         );
11801 
11802 			IF l_return_status = 'Y' THEN
11803 			    l_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11804 			    l_token_tbl(1).token_value :=  l_wip_entity_name;
11805 
11806 			    l_out_mesg_token_tbl  := l_mesg_token_tbl;
11807 
11808 			    EAM_ERROR_MESSAGE_PVT.Add_Error_Token
11809 			    (  p_message_name	=> 'EAM_WOCMPL_QUALITY_COMMMIT'
11810 			     , p_token_tbl	=> l_Token_tbl
11811 			     , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
11812 			     , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
11813 			     );
11814 
11815 			    x_return_status := FND_API.G_RET_STS_ERROR;
11816 
11817 			   RAISE EXC_SEV_QUIT_RECORD;
11818 			END IF;
11819 
11820 		END IF; -- end if for p_eam_wo_quality_tbl.COUNT > 0
11821 
11822 		IF l_eam_wo_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE and l_maint_object_type =3  THEN
11823 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling EAM_METERREADING_VALIDATE_PVT.MANDATORY_ENTERED procedure...') ; END IF ;
11824 		   EAM_METERREADING_VALIDATE_PVT.MANDATORY_ENTERED
11825 			(
11826 			     p_wip_entity_id 		=> l_eam_wo_comp_rec.wip_entity_id
11827 			   , p_instance_id		=> l_maint_object_id
11828 			   , p_eam_meter_reading_tbl    => p_eam_meter_reading_tbl
11829 			   , p_work_order_cmpl_date     => l_eam_wo_comp_rec.actual_end_date
11830 			   , x_return_status            => l_return_status
11831 			   , x_man_reading_enter        => l_man_reading_enter
11832 			);
11833 
11834 			IF l_return_status <> 'S' THEN
11835 					l_other_message := 'EAM_WOCMPL_MAN_METER_ENTER';
11836 					l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11837 					l_other_token_tbl(1).token_value := l_wip_entity_name;
11838 					RAISE EXC_SEV_QUIT_RECORD;
11839 			END IF;
11840 		END IF;
11841 
11842 		IF l_eam_wo_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE  and p_eam_meter_reading_tbl.COUNT > 0 THEN
11843 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling EAM_METERREADING_VALIDATE_PVT.insert_row procedure...') ; END IF ;
11844 			EAM_METERREADING_UTILITY_PVT.INSERT_ROW
11845 			(
11846 				 p_eam_meter_reading_tbl  => p_eam_meter_reading_tbl
11847 				, p_eam_counter_prop_tbl  => p_eam_counter_prop_tbl
11848 				, x_eam_meter_reading_tbl => x_eam_meter_reading_tbl
11849 				, x_eam_counter_prop_tbl  => x_eam_counter_prop_tbl
11850 				, x_return_status         => l_return_status
11851 				, x_mesg_token_tbl	  => l_mesg_token_tbl
11852 			);
11853 
11854 			IF l_return_status <> 'S' THEN
11855 					l_other_message := 'EAM_WOCMPL_METER_ENTER';
11856 					l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11857 					l_other_token_tbl(1).token_value := l_wip_entity_name;
11858 					RAISE EXC_SEV_QUIT_RECORD;
11859 			END IF;
11860 
11861 		END IF;
11862 
11863 		/* Bug # 5255459 : call DISABLE_COUNTER_HIERARCHY every time */
11864 
11865 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling EAM_METERREADING_UTILITY_PVT.DISABLE_COUNTER_HIERARCHY procedure...') ; END IF ;
11866 		EAM_METERREADING_UTILITY_PVT.DISABLE_COUNTER_HIERARCHY
11867 		(
11868 			p_eam_wo_comp_rebuild_tbl => p_eam_wo_comp_rebuild_tbl ,
11869 			p_subinventory_id	  => l_eam_wo_comp_rec.completion_subinventory ,
11870 			p_wip_entity_id           => l_eam_wo_comp_rec.wip_entity_id,
11871 			x_eam_wo_comp_rebuild_tbl => x_eam_wo_comp_rebuild_tbl ,
11872 			x_return_status           => l_return_status ,
11873 			x_mesg_token_tbl	  => l_mesg_token_tbl
11874 		);
11875 		IF l_return_status <> 'S' THEN
11876 			l_other_message := 'EAM_WOCMPL_DIS_COUNTER_HIER';
11877 			l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11878 			l_other_token_tbl(1).token_value := l_wip_entity_name;
11879 			RAISE EXC_SEV_QUIT_RECORD;
11880 		END IF;
11881 
11882 		IF p_eam_wo_comp_rebuild_tbl.COUNT > 0 THEN
11883 
11884 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling AM_METERREADING_UTILITY_PVT.Update_Genealogy procedure...') ; END IF ;
11885 			EAM_METERREADING_UTILITY_PVT.UPDATE_GENEALOGY
11886 			(
11887 				p_eam_wo_comp_rebuild_tbl => p_eam_wo_comp_rebuild_tbl ,
11888 				x_eam_wo_comp_rebuild_tbl => x_eam_wo_comp_rebuild_tbl ,
11889 				x_return_status           => l_return_status ,
11890 				x_mesg_token_tbl	  => l_mesg_token_tbl
11891 			);
11892 
11893 			IF l_return_status <> 'S' THEN
11894 					l_other_message := 'EAM_WOCMPL_UPDATE_GEN';
11895 					l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11896 					l_other_token_tbl(1).token_value := l_wip_entity_name;
11897 					RAISE EXC_SEV_QUIT_RECORD;
11898 			END IF;
11899 
11900 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling AM_METERREADING_UTILITY_PVT.UPDATE_REBUILD_WORK_ORDER procedure...') ; END IF ;
11901 			EAM_METERREADING_UTILITY_PVT.UPDATE_REBUILD_WORK_ORDER
11902 			(
11903 				p_eam_wo_comp_rebuild_tbl => p_eam_wo_comp_rebuild_tbl ,
11904 				x_eam_wo_comp_rebuild_tbl => x_eam_wo_comp_rebuild_tbl ,
11905 				x_return_status           => l_return_status ,
11906 				x_mesg_token_tbl	  => l_mesg_token_tbl
11907 			);
11908 			IF l_return_status <> 'S' THEN
11909 					l_other_message := 'EAM_WOCMPL_UPDATE_WORK';
11910 					l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11911 					l_other_token_tbl(1).token_value := l_wip_entity_name;
11912 					RAISE EXC_SEV_QUIT_RECORD;
11913 			END IF;
11914 
11915 
11916 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling EAM_METERREADING_UTILITY_PVT.UPDATE_ACTIVITY procedure...') ; END IF ;
11917 			EAM_METERREADING_UTILITY_PVT.UPDATE_ACTIVITY
11918 			(
11919 				p_eam_wo_comp_rebuild_tbl => p_eam_wo_comp_rebuild_tbl ,
11920 				x_eam_wo_comp_rebuild_tbl => x_eam_wo_comp_rebuild_tbl ,
11921 				x_return_status           => l_return_status ,
11922 				x_mesg_token_tbl	  => l_mesg_token_tbl
11923 			);
11924 			IF l_return_status <> 'S' THEN
11925 					l_other_message := 'EAM_WOCMPL_UPDATE_ACT';
11926 					l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11927 					l_other_token_tbl(1).token_value := l_wip_entity_name;
11928 					RAISE EXC_SEV_QUIT_RECORD;
11929 			END IF;
11930 
11931 		END IF;
11932 
11933 		IF p_eam_wo_comp_mr_read_tbl.COUNT > 0 THEN
11934 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling EAM_METERREADING_UTILITY_PVT.ENABLE_SOURCE_METER procedure...') ; END IF ;
11935 			EAM_METERREADING_UTILITY_PVT.ENABLE_SOURCE_METER
11936 			(
11937 				p_eam_wo_comp_mr_read_tbl => p_eam_wo_comp_mr_read_tbl ,
11938 				x_eam_wo_comp_mr_read_tbl => x_eam_wo_comp_mr_read_tbl ,
11939 				x_return_status           => l_return_status ,
11940 				x_mesg_token_tbl	  => l_mesg_token_tbl
11941 			);
11942 			IF l_return_status <> 'S' THEN
11943 					l_other_message := 'EAM_WOCMPL_ENABLE_COUNTER_HIER';
11944 					l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11945 					l_other_token_tbl(1).token_value := l_wip_entity_name;
11946 					RAISE EXC_SEV_QUIT_RECORD;
11947 			END IF;
11948 		END IF;
11949 
11950 		/* -- For work order completeion call Eam_Meters_util. Update_Last_Service_Reading_Dates
11951 
11952 		IF l_eam_wo_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE  AND	p_eam_meter_reading_tbl.COUNT > 0 THEN
11953 
11954 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling EAM_METERREADING_UTILITY_PVT.UPDATE_LAST_SERVICE_READING procedure...') ; END IF ;
11955 			EAM_METERREADING_UTILITY_PVT.UPDATE_LAST_SERVICE_READING
11956 			(
11957 			   p_eam_meter_reading_tbl   => p_eam_meter_reading_tbl
11958 			 , x_eam_meter_reading_tbl   => x_eam_meter_reading_tbl
11959 			 , x_return_status           => l_return_status
11960 			 , x_mesg_token_tbl          => l_mesg_token_tbl
11961 			);
11962 			IF l_return_status <> 'S' THEN
11963 					l_other_message := 'EAM_WOCMPL_LAST_SER_READ';
11964 					l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11965 					l_other_token_tbl(1).token_value := l_wip_entity_name;
11966 					RAISE EXC_SEV_QUIT_RECORD;
11967 			END IF;
11968 		END IF; */
11969 
11970 	IF l_eam_wo_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE AND
11971 	   l_eam_wo_comp_rec.completion_subinventory IS NULL THEN
11972 
11973 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling csi_eam_interface_grp.wip_completion procedure...') ; END IF ;
11974 		csi_eam_interface_grp.wip_completion
11975 		 (
11976 			 p_wip_entity_id   => l_eam_wo_comp_rec.wip_entity_id,
11977 			 p_organization_id => l_eam_wo_comp_rec.organization_id,
11978 			 x_return_status   => l_return_status,
11979 			 x_error_message   => l_error_message
11980 		 );
11981 
11982 		 IF l_return_status <> 'S' THEN
11983 					l_other_message := 'EAM_WOCMPL_IB_WIP_CMPL';
11984 					l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
11985 					l_other_token_tbl(1).token_value := l_wip_entity_name;
11986 					RAISE EXC_SEV_QUIT_RECORD;
11987 		END IF;
11988 	END IF;
11989 
11990 	IF l_eam_wo_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE THEN
11991 		declare
11992 
11993 			TYPE plan_id_tbl     is TABLE OF number INDEX BY BINARY_INTEGER;
11994 			TYPE plan_name_tbl   is TABLE OF varchar2(30) INDEX BY BINARY_INTEGER;
11995 			l_plan_id_tbl	     plan_id_tbl;
11996 			l_plan_name_tbl	     plan_name_tbl;
11997 			l_asset_ops_msg_count	  NUMBER;
11998 			l_asset_ops_msg_data	  VARCHAR2(2000);
11999 			l_asset_ops_return_status VARCHAR2(1);
12000 		begin
12001 
12002 			select qp.plan_id,name bulk collect into l_plan_id_tbl,l_plan_name_tbl
12003 			from qa_results qr,qa_plans qp
12004 			where qr.plan_id = qp.plan_id
12005 			and collection_id = l_eam_wo_comp_rec.qa_collection_id;
12006 
12007 			IF l_plan_id_tbl.COUNT  > 0 THEN
12008 				FOR N IN l_plan_id_tbl.FIRST..l_plan_id_tbl.LAST LOOP
12009 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling EAM_ASSET_LOG_PVT.INSERT_ROW procedure...') ; END IF ;
12010 					EAM_ASSET_LOG_PVT.INSERT_ROW
12011 					 (
12012 						p_api_version		=> 1.0,
12013 						p_event_date		=> sysdate,
12014 						p_event_type		=> 'EAM_SYSTEM_EVENTS',
12015 						p_event_id		=> 12,
12016 						p_organization_id	=> l_eam_wo_comp_rec.organization_id,
12017 						p_instance_id		=> l_maint_object_id,
12018 						p_comments		=> null,
12019 						p_reference		=> l_plan_name_tbl(N),
12020 						p_ref_id		=> l_plan_id_tbl(N),
12021 						p_operable_flag		=> null,
12022 						p_reason_code		=> null,
12023 						x_return_status		=> l_asset_ops_return_status,
12024 						x_msg_count		=> l_asset_ops_msg_count,
12025 						x_msg_data		=> l_asset_ops_msg_data
12026 					 );
12027 				END LOOP;
12028 			END IF;
12029 
12030 		end;
12031 	END IF;
12032 	--Raise status changed event when a workorder is completed/uncompleted
12033 
12034 	                 IF(l_workflow_enabled='Y'  AND (WF_EVENT.TEST(l_status_changed_event) <> 'NONE')  --if status change event enabled
12035 					) THEN
12036 
12037 										      SELECT EAM_WORKFLOW_EVENT_S.NEXTVAL
12038 										      INTO l_wf_event_seq
12039 										      FROM DUAL;
12040 
12041 										      l_parameter_list := wf_parameter_list_t();
12042 										      l_event_name := l_status_changed_event;
12043 
12044 										    l_event_key := TO_CHAR(l_wf_event_seq);
12045 										    WF_CORE.CONTEXT('Enterprise Asset Management...','Work Order Status change event','Building parameter list');
12046 										    -- Add Parameters
12047 										    Wf_Event.AddParameterToList(p_name =>'WIP_ENTITY_ID',
12048 													    p_value => TO_CHAR(l_eam_wo_comp_rec.wip_entity_id),
12049 													    p_parameterlist => l_parameter_list);
12050 										    Wf_Event.AddParameterToList(p_name =>'WIP_ENTITY_NAME',
12051 													    p_value =>l_wip_entity_name,
12052 													    p_parameterlist => l_parameter_list);
12053 										    Wf_Event.AddParameterToList(p_name =>'ORGANIZATION_ID',
12054 													    p_value => TO_CHAR(l_eam_wo_comp_rec.organization_id),
12055 													    p_parameterlist => l_parameter_list);
12056 										    Wf_Event.AddParameterToList(p_name =>'NEW_SYSTEM_STATUS',
12057 													    p_value => TO_CHAR(l_new_system_status),
12058 													    p_parameterlist => l_parameter_list);
12059 										    Wf_Event.AddParameterToList(p_name =>'NEW_WO_STATUS',
12060 													    p_value => TO_CHAR(l_new_eam_status),
12061 													    p_parameterlist => l_parameter_list);
12062 										   Wf_Event.AddParameterToList(p_name =>'OLD_SYSTEM_STATUS',
12063 													    p_value => TO_CHAR(l_old_system_status),
12064 													    p_parameterlist => l_parameter_list);
12065 										    Wf_Event.AddParameterToList(p_name =>'OLD_WO_STATUS',
12066 													    p_value => TO_CHAR(l_old_eam_status),
12067 													    p_parameterlist => l_parameter_list);
12068 										      Wf_Event.AddParameterToList(p_name =>'WORKFLOW_TYPE',
12069 													    p_value => TO_CHAR(l_workflow_type),
12070 													    p_parameterlist => l_parameter_list);
12071 										      Wf_Event.AddParameterToList(p_name =>'REQUESTOR',
12072 													    p_value =>FND_GLOBAL.USER_NAME ,
12073 													    p_parameterlist => l_parameter_list);
12074 										    Wf_Core.Context('Enterprise Asset Management...','Work Order Staus Changed Event','Raising event');
12075 
12076 										    Wf_Event.Raise(	p_event_name => l_event_name,
12077 													p_event_key => l_event_key,
12078 													p_parameters => l_parameter_list);
12079 										    l_parameter_list.DELETE;
12080 										     WF_CORE.CONTEXT('Enterprise Asset Management...','Work Order Status Changed Event','After raising event');
12081 			END IF;   --end of check for status change event
12082 
12083 										 IF(l_maint_obj_source =1 ) THEN     --modify intermedia index only for EAM workorders
12084 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling EAM_TEXT_UTIL.PROCESS_WO_EVENT procedure...') ; END IF ;
12085 													     EAM_TEXT_UTIL.PROCESS_WO_EVENT
12086 													     (
12087 														  p_event  => 'UPDATE',
12088 														  p_wip_entity_id =>l_eam_wo_comp_rec.wip_entity_id,
12089 														  p_organization_id =>l_eam_wo_comp_rec.organization_id,
12090 														  p_last_update_date  => SYSDATE,
12091 														  p_last_updated_by  => FND_GLOBAL.user_id,
12092 														  p_last_update_login =>FND_GLOBAL.login_id
12093 													     );
12094 										END IF; --end of check for EAM workorders
12095 
12096 
12097 		IF l_eam_wo_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE THEN
12098 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling EAM_ASSET_LOG_PVT.INSERT_ROW procedure...') ; END IF ;
12099 			 EAM_ASSET_LOG_PVT.INSERT_ROW
12100 				 (
12101 					p_api_version		=> 1.0,
12102 					p_event_date		=> sysdate,
12103 					p_event_type		=> 'EAM_SYSTEM_EVENTS',
12104 					p_event_id		=> 8,
12105 					p_organization_id	=> l_eam_wo_comp_rec.organization_id,
12106 					p_instance_id		=> l_maint_object_id,
12107 					p_comments		=> null,
12108 					p_reference		=> l_wip_entity_name,
12109 					p_ref_id		=> l_eam_wo_comp_rec.wip_entity_id,
12110 					p_operable_flag		=> null,
12111 					p_reason_code		=> null,
12112 					x_return_status		=> l_asset_ops_return_status,
12113 					x_msg_count		=> l_asset_ops_msg_count,
12114 					x_msg_data		=> l_asset_ops_msg_data
12115 				 );
12116 		ELSE
12117 			IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Calling EAM_ASSET_LOG_PVT.INSERT_ROW procedure...') ; END IF ;
12118 			 EAM_ASSET_LOG_PVT.INSERT_ROW
12119 				 (
12120 					p_api_version		=> 1.0,
12121 					p_event_date		=> sysdate,
12122 					p_event_type		=> 'EAM_SYSTEM_EVENTS',
12123 					p_event_id		=> 9,
12124 					p_organization_id	=> l_eam_wo_comp_rec.organization_id,
12125 					p_instance_id		=> l_maint_object_id,
12126 					p_comments		=> null,
12127 					p_reference		=> l_wip_entity_name,
12128 					p_ref_id		=> l_eam_wo_comp_rec.wip_entity_id,
12129 					p_operable_flag		=> null,
12130 					p_reason_code		=> null,
12131 					x_return_status		=> l_asset_ops_return_status,
12132 					x_msg_count		=> l_asset_ops_msg_count,
12133 					x_msg_data		=> l_asset_ops_msg_data
12134 				 );
12135 		END IF;
12136 
12137 		 x_eam_wo_comp_rec		:=	l_eam_wo_comp_rec;
12138 		 x_eam_wo_quality_tbl		:=	l_eam_wo_quality_tbl;
12139 		 x_eam_meter_reading_tbl  	:=	l_eam_meter_reading_tbl;
12140 		 x_eam_counter_prop_tbl         :=      l_eam_counter_prop_tbl;
12141 		 x_eam_wo_comp_rebuild_tbl	:=	l_eam_wo_comp_rebuild_tbl;
12142 		 x_eam_wo_comp_mr_read_tbl	:=	l_eam_wo_comp_mr_read_tbl;
12143 
12144 
12145 	EXCEPTION -- Excepetion handler for begin
12146 
12147 	    WHEN EXC_SEV_QUIT_RECORD THEN
12148 
12149 	    rollback to sv_wo_compl;
12150 		l_out_eam_wo_comp_rec           := l_eam_wo_comp_rec;
12151 		l_out_eam_wo_quality_tbl	:= l_eam_wo_quality_tbl;
12152 		l_out_eam_meter_reading_tbl	:= l_eam_meter_reading_tbl;
12153 		l_out_eam_counter_prop_tbl      := l_eam_counter_prop_tbl;
12154 		l_out_eam_wo_comp_rebuild_tbl	:= l_eam_wo_comp_rebuild_tbl;
12155 		l_out_eam_wo_comp_mr_read_tbl	:= l_eam_wo_comp_mr_read_tbl;
12156 		l_out_eam_op_comp_tbl		:= l_eam_op_comp_tbl;
12157 		l_out_eam_request_tbl		:= l_eam_request_tbl;
12158 
12159 	      EAM_ERROR_MESSAGE_PVT.Log_Error
12160 	      (
12161 	       p_eam_wo_comp_rec		=>	l_eam_wo_comp_rec
12162 	     , p_eam_wo_quality_tbl		=>	l_eam_wo_quality_tbl
12163 	     , p_eam_meter_reading_tbl		=>	l_eam_meter_reading_tbl
12164 	     , p_eam_counter_prop_tbl		=>      l_eam_counter_prop_tbl
12165 	     , p_eam_wo_comp_rebuild_tbl	=>	l_eam_wo_comp_rebuild_tbl
12166 	     , p_eam_wo_comp_mr_read_tbl	=>	l_eam_wo_comp_mr_read_tbl
12167 	     , p_eam_op_comp_tbl		=>	l_eam_op_comp_tbl
12168 	     , p_eam_request_tbl		=>	l_eam_request_tbl
12169 
12170 	     , x_eam_wo_comp_rec		=>	l_out_eam_wo_comp_rec
12171 	     , x_eam_wo_quality_tbl		=>	l_out_eam_wo_quality_tbl
12172 	     , x_eam_meter_reading_tbl		=>	l_out_eam_meter_reading_tbl
12173 	     , x_eam_counter_prop_tbl		=>      l_out_eam_counter_prop_tbl
12174 	     , x_eam_wo_comp_rebuild_tbl	=>	l_out_eam_wo_comp_rebuild_tbl
12175 	     , x_eam_wo_comp_mr_read_tbl	=>	l_out_eam_wo_comp_mr_read_tbl
12176 	     , x_eam_op_comp_tbl		=>	l_out_eam_op_comp_tbl
12177 	     , x_eam_request_tbl		=>	l_out_eam_request_tbl
12178 
12179 	     , p_mesg_token_tbl			=>	l_mesg_token_tbl
12180 	     , p_error_status			=>	FND_API.G_RET_STS_ERROR
12181 	     , p_error_scope			=>	EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
12182 	     , p_other_message			=>	l_other_message
12183 	     , p_other_status			=>	EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
12184 	     , p_other_token_tbl		=>	l_other_token_tbl
12185 
12186 	     , p_error_level			=>	EAM_ERROR_MESSAGE_PVT.G_WO_COMP_LEVEL
12187 	     );
12188 
12189 		l_eam_wo_comp_rec		:= l_out_eam_wo_comp_rec;
12190 		l_eam_wo_quality_tbl		:= l_out_eam_wo_quality_tbl;
12191 		l_eam_meter_reading_tbl		:= l_out_eam_meter_reading_tbl;
12192 		l_eam_counter_prop_tbl		:= l_out_eam_counter_prop_tbl;
12193 		l_eam_wo_comp_rebuild_tbl	:= l_out_eam_wo_comp_rebuild_tbl;
12194 		l_eam_wo_comp_mr_read_tbl	:= l_out_eam_wo_comp_mr_read_tbl;
12195 
12196 		l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
12197 
12198 		 x_eam_wo_comp_rec		:=	l_eam_wo_comp_rec;
12199 		 x_eam_wo_quality_tbl		:=	l_eam_wo_quality_tbl;
12200 		 x_eam_meter_reading_tbl  	:=	l_eam_meter_reading_tbl;
12201 		 x_eam_counter_prop_tbl         :=      l_eam_counter_prop_tbl;
12202 		 x_eam_wo_comp_rebuild_tbl	:=	l_eam_wo_comp_rebuild_tbl;
12203 		 x_eam_wo_comp_mr_read_tbl	:=	l_eam_wo_comp_mr_read_tbl;
12204 		 x_return_status          	:=	l_return_status;
12205 		 x_msg_count              	:=	l_msg_count;
12206 
12207 		 RETURN;
12208 
12209  END COMP_UNCOMP_WORKORDER;
12210 
12211 
12212 
12213 
12214 
12215 
12216 
12217 
12218 
12219 
12220 
12221 
12222 
12223 
12224 
12225  PROCEDURE COMP_UNCOMP_OPERATION
12226 	(
12227 	  p_eam_op_compl_tbl	    IN EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type
12228 	, p_eam_wo_quality_tbl      IN EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type
12229 	, x_eam_op_comp_tbl         OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type
12230 	, x_eam_wo_quality_tbl      OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type
12231 	, x_return_status           OUT NOCOPY VARCHAR2
12232 	, x_msg_count               OUT NOCOPY NUMBER
12233 	)IS
12234 
12235 	l_eam_op_comp_rec		EAM_PROCESS_WO_PUB.eam_op_comp_rec_type;
12236 	l_eam_out_op_comp_rec		EAM_PROCESS_WO_PUB.eam_op_comp_rec_type;
12237 	l_valid_transaction		BOOLEAN := TRUE ;
12238 	l_mesg_token_tbl		EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
12239 	l_return_status			VARCHAR2(1);
12240 
12241 	l_eam_wo_quality_tbl            EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type	;
12242 	l_eam_meter_reading_tbl         EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type	;
12243 	l_eam_wo_comp_rebuild_tbl       EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type ;
12244 	l_eam_wo_comp_mr_read_tbl       EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type ;
12245 	l_eam_counter_prop_tbl		EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type	;
12246 	l_eam_op_comp_tbl               EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
12247 	l_eam_request_tbl               EAM_PROCESS_WO_PUB.eam_request_tbl_type;
12248 
12249 	l_out_eam_wo_comp_rec		EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
12250 	l_out_eam_wo_quality_tbl        EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type;
12251 	l_out_eam_meter_reading_tbl     EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type;
12252 	l_out_eam_counter_prop_tbl	EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type;
12253 	l_out_eam_wo_comp_rebuild_tbl   EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type;
12254 	l_out_eam_wo_comp_mr_read_tbl   EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type;
12255 	l_out_eam_op_comp_tbl           EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
12256 	l_out_eam_request_tbl           EAM_PROCESS_WO_PUB.eam_request_tbl_type;
12257 
12258 	l_other_message			VARCHAR2(2000);
12259 	l_other_token_tbl		EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
12260 	l_token_tbl			EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
12261 	l_msg_count			NUMBER;
12262 
12263 	l_eam_wo_quality_temp_tbl       EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type;
12264 	l_eam_wo_quality_rec            EAM_PROCESS_WO_PUB.eam_wo_quality_rec_type;
12265 	colllection_id_temp		NUMBER;
12266 	mandatory_qua_plan		VARCHAR2(1);
12267 	l_org_id			NUMBER;
12268 	l_asset_group_id		NUMBER;
12269 	l_asset_number			VARCHAR2(30);
12270 	l_asset_instance_id		NUMBER;
12271 	l_asset_activity		VARCHAR2(240);
12272 	l_asset_group_name		VARCHAR2(240);
12273 	l_wip_entity_name		VARCHAR2(240);
12274 	l_wip_entity_id			NUMBER;
12275 	l_asset_activity_id		NUMBER;
12276 	l_out_mesg_token_tbl		EAM_ERROR_MESSAGE_PVT.mesg_token_tbl_type;
12277 	l_msg_data			VARCHAR2(2000);
12278 	contextStr			VARCHAR2(2000);
12279 	l_maint_obj_source		NUMBER;
12280 	l_workflow_enabled		VARCHAR2(1);
12281 	l_op_completed_event		VARCHAR2(240);
12282 	l_workflow_type                 NUMBER;
12283 	l_is_last_operation             VARCHAR2(1);
12284 	l_parameter_list		wf_parameter_list_t;
12285 	l_event_key			VARCHAR2(200);
12286 	l_wf_event_seq			NUMBER;
12287 	l_op_sched_end_date             DATE;
12288 	l_asset_instance_number		VARCHAR2(30);
12289 
12290 	BEGIN
12291 
12292 	IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Operation Completeion procedure begin ');  END IF;
12293 
12294 	x_return_status := FND_API.G_RET_STS_SUCCESS;
12295 	l_return_status	:= FND_API.G_RET_STS_SUCCESS;
12296 
12297 	l_eam_wo_quality_tbl	:= p_eam_wo_quality_tbl;
12298 	l_eam_op_comp_rec	:= p_eam_op_compl_tbl(p_eam_op_compl_tbl.FIRST);
12299 	l_org_id		:= l_eam_op_comp_rec.organization_id;
12300 	l_wip_entity_id		:= l_eam_op_comp_rec.wip_entity_id;
12301 
12302 	SELECT wip_entity_name INTO l_wip_entity_name
12303 	  FROM wip_entities
12304 	 WHERE wip_entity_id = l_eam_op_comp_rec.wip_entity_id;
12305 
12306 	SELECT nvl(wdj.asset_group_id,wdj.rebuild_item_id),
12307 	       nvl(wdj.asset_number,wdj.rebuild_serial_number),
12308 	       wdj.primary_item_id,
12309 	       wdj.maintenance_object_source,
12310                ewod.workflow_type
12311 	  INTO l_asset_group_id,
12312 	       l_asset_number,
12313 	       l_asset_activity_id,
12314 	       l_maint_obj_source,
12315 	       l_workflow_type
12316           FROM wip_discrete_jobs wdj,eam_work_order_details ewod
12317 	 WHERE wdj.wip_entity_id = l_eam_op_comp_rec.wip_entity_id
12318 	   AND wdj.wip_entity_id = ewod.wip_entity_id(+);
12319 
12320 	SELECT msi.concatenated_segments
12321 	   INTO l_asset_group_name
12322            FROM mtl_system_items_kfv msi
12323 	  WHERE msi.inventory_item_id = l_asset_group_id
12324 	   AND rownum = 1;
12325 	Begin
12326   	  SELECT msi.concatenated_segments
12327 	   INTO l_asset_activity
12328            FROM mtl_system_items_kfv msi
12329 	  WHERE msi.inventory_item_id = l_asset_activity_id
12330 	   AND rownum = 1;
12331 
12332         Exception
12333 	  When NO_DATA_FOUND Then
12334 	    l_asset_activity := null;
12335 	End;
12336 
12337 	 l_workflow_enabled:= Is_Workflow_Enabled(l_maint_obj_source,l_org_id);
12338 	 l_op_completed_event := 'oracle.apps.eam.workorder.operation.completed';
12339 
12340 	FOR i IN p_eam_op_compl_tbl.FIRST..p_eam_op_compl_tbl.LAST LOOP
12341 	BEGIN
12342 		l_eam_op_comp_rec := p_eam_op_compl_tbl(i);
12343 		l_org_id	  := l_eam_op_comp_rec.organization_id;
12344 
12345 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Work Order Completeion: Transaction Type Validity . . . ');  END IF;
12346 
12347 		VALIDATE_TRANSACTION_TYPE
12348 		(   p_transaction_type  => l_eam_op_comp_rec.transaction_type
12349 		,   p_entity_name       => 'OPERATION_COMPLETEION'
12350 		,   p_entity_id         => l_eam_op_comp_rec.wip_entity_id
12351 		,   x_valid_transaction => l_valid_transaction
12352 		,   x_mesg_token_tbl    => l_Mesg_Token_Tbl
12353 		);
12354 
12355 		IF NOT l_valid_transaction
12356 		THEN
12357 		    x_eam_op_comp_tbl(i).return_status	:= EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
12358 		    l_other_message := 'EAM_OP_CMPL_INV_TXN';
12359 		    l_other_token_tbl(1).token_name  := 'OP_SEQ';
12360 		    l_other_token_tbl(1).token_value := l_eam_op_comp_rec.operation_seq_num ;
12361 		    RAISE EXC_SEV_QUIT_RECORD;
12362 		END IF;
12363 
12364 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Operation Completeion : Check Required . . .'); END IF;
12365 
12366 		EAM_OP_COMP_VALIDATE_PVT.Check_Required
12367 		 ( p_eam_op_comp_rec            => l_eam_op_comp_rec
12368 		 , x_return_status              => l_return_status
12369 		 , x_mesg_token_tbl             => l_mesg_token_tbl
12370 		 ) ;
12371 		IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Operation Order Completeion Check required completed with return_status: ' || l_return_status) ; END IF ;
12372 
12373 	        IF l_return_status <> 'S'
12374 		 THEN
12375  		       x_eam_op_comp_tbl(i).return_status	:= EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
12376 		       l_other_message := 'EAM_OP_CHKREQ_CSEV_SKIP';
12377 		       l_other_token_tbl(1).token_name  := 'OP_SEQ';
12378 		       l_other_token_tbl(1).token_value := l_eam_op_comp_rec.operation_seq_num ;
12379 		       RAISE EXC_SEV_QUIT_RECORD ;
12380 	        END IF;
12381 
12382 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('EAM Operation Completeion:  Populate Null Columns . . .'); END IF;
12383 		l_eam_out_op_comp_rec := l_eam_op_comp_rec;
12384 		EAM_OP_COMP_DEFAULT_PVT.Populate_NULL_Columns
12385 			(   p_eam_op_comp_rec         => l_eam_op_comp_rec
12386 			,   x_eam_op_comp_rec         => l_eam_out_op_comp_rec
12387 			,   x_return_status           => l_return_status
12388 		);
12389 		l_eam_op_comp_rec := l_eam_out_op_comp_rec;
12390 
12391 		IF l_return_status <> 'S'
12392 		   THEN
12393 		       x_eam_op_comp_tbl(i).return_status	:= EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
12394 		       l_other_message := 'EAM_OP_CMPL_POPULATE_NULL';
12395 		       l_other_token_tbl(1).token_name  := 'OP_SEQ';
12396 		       l_other_token_tbl(1).token_value := l_eam_op_comp_rec.operation_seq_num ;
12397 			RAISE EXC_SEV_QUIT_RECORD;
12398 		END IF;
12399 
12400 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Operation Completeion : Check Attributes . . .'); END IF;
12401 		EAM_OP_COMP_VALIDATE_PVT.Check_Attributes
12402 		    (
12403 			p_eam_op_comp_rec          => l_eam_op_comp_rec
12404 		    ,   x_return_status            => l_return_status
12405 		    ,   x_Mesg_Token_Tbl           => l_Mesg_Token_Tbl
12406 		    );
12407 
12408 		IF l_return_status <> 'S'
12409 		THEN
12410 		       x_eam_op_comp_tbl(i).return_status	:= EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
12411 		       l_other_message := 'EAM_OP_CHKATTR_CSEV_SKIP';
12412 	               l_other_token_tbl(1).token_name  := 'OP_SEQ';
12413 		       l_other_token_tbl(1).token_value := l_eam_op_comp_rec.operation_seq_num ;
12414 	               RAISE EXC_SEV_QUIT_RECORD ;
12415 		END IF;
12416 
12417 
12418 
12419 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Operation Completeion : Perform Writes . . .'); END IF;
12420 		 EAM_OP_COMP_UTILITY_PVT.PERFORM_WRITES
12421 		(   p_eam_op_comp_rec       => l_eam_op_comp_rec
12422 	        ,   x_Mesg_Token_Tbl        => l_Mesg_Token_Tbl
12423 	        ,   x_return_status         => l_return_status
12424 	         );
12425 
12426 		 IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
12427 		 THEN
12428 		       x_eam_op_comp_tbl(i).return_status	:= EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
12429 		       l_other_message := 'EAM_OP_CMPL_WRITE_REC';
12430 		       l_other_token_tbl(1).token_name  := 'WIP_ENTITY_NAME';
12431 		       l_other_token_tbl(1).token_value := l_eam_op_comp_rec.operation_seq_num ;
12432 		       RAISE EXC_SEV_QUIT_RECORD ;
12433 		END IF;
12434 
12435 		x_eam_op_comp_tbl(i) := l_eam_op_comp_rec;
12436 
12437 
12438 		IF l_eam_wo_quality_tbl.COUNT > 0 AND l_eam_op_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE THEN
12439 			FOR J IN l_eam_wo_quality_tbl.FIRST..l_eam_wo_quality_tbl.LAST LOOP
12440 				IF l_eam_wo_quality_tbl(j).operation_seq_number = p_eam_op_compl_tbl(i).operation_seq_num THEN
12441 					l_eam_wo_quality_temp_tbl(j) := l_eam_wo_quality_tbl(j);
12442 				END IF;
12443 			END LOOP;
12444 
12445 			 FOR K IN l_eam_wo_quality_temp_tbl.FIRST..l_eam_wo_quality_temp_tbl.LAST LOOP
12446 			   BEGIN
12447 
12448 				IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Processing '|| I || ' record') ; END IF ;
12449 
12450 				--  Load local records.
12451 				l_eam_wo_quality_rec := l_eam_wo_quality_temp_tbl(K);
12452 
12453 				colllection_id_temp := l_eam_wo_quality_rec.collection_id;
12454 
12455 				IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Operation Completeion validating Quality Record Transaction Type . . .'); END IF;
12456 
12457 				VALIDATE_TRANSACTION_TYPE
12458 				(   p_transaction_type  => l_eam_wo_quality_rec.transaction_type
12459 				,   p_entity_name       => 'QUALITY_ENTRY'
12460 				,   p_entity_id         => to_char(l_eam_wo_quality_rec.plan_id)
12461 				,   X_valid_transaction => l_valid_transaction
12462 				,   x_mesg_token_tbl    => l_mesg_token_tbl
12463 				);
12464 
12465 				IF NOT l_valid_transaction
12466 				 THEN
12467 					l_other_message := 'EAM_QA_INV_TXN';
12468 					l_other_token_tbl(1).token_name  := 'OP_SEQ';
12469 					l_other_token_tbl(1).token_value := l_eam_wo_quality_rec.operation_seq_number;
12470 					RAISE EXC_SEV_QUIT_RECORD ;
12471 				 END IF ;
12472 
12473 				 IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Operation Completeion validating Quality Record Check Required . . .'); END IF;
12474 
12475 				 EAM_WO_QUA_VALIDATE_PVT.Check_Required
12476 				 (
12477 					p_eam_wo_quality_rec => l_eam_wo_quality_rec
12478 					, x_return_status    => l_return_status
12479 					, x_mesg_token_tbl   => l_mesg_token_tbl
12480 				 );
12481 
12482 				 IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR THEN
12483 					l_other_message := 'EAM_QA_CHECK_REQ';
12484 					l_other_token_tbl(1).token_name  := 'OP_SEQ';
12485 					l_other_token_tbl(1).token_value := l_eam_wo_quality_rec.operation_seq_number;
12486 					RAISE EXC_SEV_QUIT_RECORD;
12487 				 END IF;
12488 
12489 		         END ;  -- End for begin K
12490 
12491 
12492 		        END LOOP; -- FOR K
12493 
12494 			BEGIN
12495 
12496 				   IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Operation Completeion validating Quality Record Insert Row . . .'); END IF;
12497 				   EAM_WO_QUA_UTILITY_PVT.insert_row
12498 				   (
12499 					   p_collection_id	=> colllection_id_temp
12500 					 , p_eam_wo_quality_tbl  => p_eam_wo_quality_tbl
12501 					 , x_eam_wo_quality_tbl  => l_eam_wo_quality_temp_tbl
12502 					 , x_return_status       => l_return_status
12503 					 , x_mesg_token_tbl      => l_mesg_token_tbl
12504 				  );
12505 
12506 
12507 				IF l_return_status  <> 'S' THEN
12508 					x_return_status:=FND_API.G_RET_STS_ERROR;
12509 					l_other_message := 'EAM_OP_QUAINSERT_CSEV_SKIP';
12510 					l_other_token_tbl(1).token_name  := 'OP_SEQ';
12511 					l_other_token_tbl(1).token_value := l_eam_wo_quality_rec.operation_seq_number;
12512 					RAISE EXC_SEV_QUIT_RECORD;
12513 				END IF;
12514 			END ;
12515 		END IF; -- END FOR Quality records > 0
12516 
12517 		IF l_eam_op_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE THEN
12518 		   BEGIN
12519 
12520 			IF l_asset_number IS NOT NULL THEN
12521 
12522 				SELECT  cii.instance_number,cii.instance_id into l_asset_instance_number,
12523 				  l_asset_instance_id
12524 				  FROM  wip_discrete_jobs wdj,csi_item_instances cii
12525 				 WHERE  wdj.wip_entity_id = l_eam_op_comp_rec.wip_entity_id
12526 				   AND  wdj.maintenance_object_type = 3
12527 				   AND  wdj.maintenance_object_id = cii.instance_id
12528 				   AND  cii.serial_number = l_asset_number;
12529 			END IF;
12530 
12531 
12532 
12533 				IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Operation Completeion Checking quality mandatory plans remain . . .'); END IF;
12534 				mandatory_qua_plan :=qa_web_txn_api.quality_mandatory_plans_remain(
12535 					p_txn_number       => 33 ,
12536 					p_organization_id  => l_org_id ,
12537 					pk1                => l_asset_group_name ,    -- Asset Grp
12538 					pk2                => l_asset_number  ,    -- Asset no
12539 					pk3                => l_asset_activity  ,    -- Asset Act
12540 					pk4                => l_wip_entity_name  ,    -- Work ordrr name
12541 					pk5		   => l_eam_op_comp_rec.operation_seq_num ,
12542 					pk6		   => l_asset_instance_number ,
12543 					p_wip_entity_id    => l_wip_entity_id  ,     -- work order id
12544 					p_collection_id    => l_eam_op_comp_rec.qa_collection_id
12545 				 );
12546 
12547 				IF mandatory_qua_plan = 'Y' THEN
12548 
12549 					l_other_message := 'EAM_OPCMPL_MAND_PLAN';
12550 					l_other_token_tbl(1).token_name  := 'OP_SEQ';
12551 					l_other_token_tbl(1).token_value := l_eam_op_comp_rec.operation_seq_num;
12552 
12553 					x_return_status := FND_API.G_RET_STS_ERROR;
12554 
12555 					raise EXC_SEV_QUIT_RECORD;
12556 				END IF;
12557 		   END;
12558 		END IF;
12559 
12560 		IF p_eam_wo_quality_tbl.COUNT > 0 AND
12561 			l_eam_op_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE  THEN
12562 
12563 		    BEGIN
12564 		    	   contextStr := '162='||l_asset_group_id||'@163='
12565 			    ||l_asset_number||'@2147483550='||l_asset_instance_id||'@165='
12566 			    ||l_wip_entity_id||'@199='||l_eam_op_comp_rec.operation_seq_num||'@164='||l_asset_activity_id;
12567 		        IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Operation Completeion Calling qa_web_txn_api.post_background_results. . .'); END IF;
12568 			qa_web_txn_api.post_background_results(
12569 				p_txn_number         =>  33 ,
12570 				p_org_id             => l_org_id  ,
12571 				p_context_values     => contextStr ,
12572 				p_collection_id      => l_eam_op_comp_rec.qa_collection_id
12573 			);
12574 
12575 		        EXCEPTION WHEN OTHERS THEN
12576 			    l_token_tbl(1).token_name  := 'OP_SEQ';
12577 			    l_token_tbl(1).token_value :=  l_eam_op_comp_rec.operation_seq_num;
12578 
12579 			    l_out_mesg_token_tbl  := l_mesg_token_tbl;
12580 
12581 			    EAM_ERROR_MESSAGE_PVT.Add_Error_Token
12582 			    (  p_message_name	=> 'EAM_OP_CMPL_BACK_ERR'
12583 			     , p_token_tbl	=> l_Token_tbl
12584 			     , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
12585 			     , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
12586 			     );
12587 
12588 			    x_return_status := FND_API.G_RET_STS_ERROR;
12589 
12590 			   raise EXC_SEV_QUIT_RECORD;
12591 		    END ;
12592 
12593 			IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Operation Completeion Calling qa_results_pub.enable_and_fire_action . . .'); END IF;
12594 
12595 			qa_result_grp.enable_and_fire_action(
12596 			 p_api_version         => 1.0  ,
12597 			 p_collection_id       => l_eam_op_comp_rec.qa_collection_id   ,
12598 		         x_return_status       => l_return_status  ,
12599 			 x_msg_count           => l_msg_count   ,
12600 			 x_msg_data            => l_msg_data
12601 		         );
12602 
12603 			IF l_return_status <> 'S' THEN
12604 			    l_token_tbl(1).token_name  := 'OP_SEQ';
12605 			    l_token_tbl(1).token_value :=  l_eam_op_comp_rec.operation_seq_num;
12606 
12607 			    l_out_mesg_token_tbl  := l_mesg_token_tbl;
12608 
12609 			    EAM_ERROR_MESSAGE_PVT.Add_Error_Token
12610 			    (  p_message_name	=> 'EAM_OP_QUALITY_COMMMIT'
12611 			     , p_token_tbl	=> l_Token_tbl
12612 			     , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
12613 			     , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
12614 			     );
12615 
12616 			    x_return_status := FND_API.G_RET_STS_ERROR;
12617 
12618 			   raise EXC_SEV_QUIT_RECORD;
12619 			END IF;
12620 
12621 		END IF;
12622 
12623 
12624 
12625 		IF(l_workflow_enabled='Y' AND (l_eam_op_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE)
12626 		            AND (Wf_Event.TEST(l_op_completed_event)<>'NONE' )   ) THEN
12627 
12628 			                                                            SELECT last_unit_completion_date
12629 										    INTO l_op_sched_end_date
12630 										    FROM WIP_OPERATIONS
12631 										    WHERE wip_entity_id= l_eam_op_comp_rec.wip_entity_id
12632 										    AND operation_seq_num = l_eam_op_comp_rec.operation_seq_num;
12633 
12634                                                                                     l_is_last_operation := 'N';
12635 										    select DECODE(count(won.next_operation),0,'Y','N')
12636 										    INTO l_is_last_operation
12637 										    from wip_operation_networks won
12638 										    where won.wip_entity_id =  l_eam_op_comp_rec.wip_entity_id and
12639 										    won.prior_operation = l_eam_op_comp_rec.operation_seq_num;
12640 
12641 										      SELECT EAM_WORKFLOW_EVENT_S.NEXTVAL
12642 										      INTO l_wf_event_seq
12643 										      FROM DUAL;
12644 
12645 										      l_parameter_list := wf_parameter_list_t();
12646 
12647 										    l_event_key := TO_CHAR(l_wf_event_seq);
12648 										    WF_CORE.CONTEXT('Enterprise Asset Management...','Work Order Op Completed  event','Building parameter list');
12649 										    -- Add Parameters
12650 										    Wf_Event.AddParameterToList(p_name =>'WIP_ENTITY_ID',
12651 													    p_value => TO_CHAR( l_eam_op_comp_rec.wip_entity_id),
12652 													    p_parameterlist => l_parameter_list);
12653 										    Wf_Event.AddParameterToList(p_name =>'WIP_ENTITY_NAME',
12654 													    p_value =>l_wip_entity_name,
12655 													    p_parameterlist => l_parameter_list);
12656 										    Wf_Event.AddParameterToList(p_name =>'ORGANIZATION_ID',
12657 													    p_value => TO_CHAR(l_org_id),
12658 													    p_parameterlist => l_parameter_list);
12659 										    Wf_Event.AddParameterToList(p_name =>'ACTUAL_COMPLETION_DATE',
12660 													    p_value => TO_CHAR(l_eam_op_comp_rec.actual_end_date),
12661 													    p_parameterlist => l_parameter_list);
12662 										   Wf_Event.AddParameterToList(p_name =>'SCHEDULED_COMPLETION_DATE',
12663 													    p_value => TO_CHAR(l_op_sched_end_date),
12664 													    p_parameterlist => l_parameter_list);
12665 										    Wf_Event.AddParameterToList(p_name =>'IS_LAST_OPERATION',
12666 													    p_value => l_is_last_operation,
12667 													    p_parameterlist => l_parameter_list);
12668 										     Wf_Event.AddParameterToList(p_name =>'WORKFLOW_TYPE',
12669 													    p_value => TO_CHAR(l_workflow_type),
12670 													    p_parameterlist => l_parameter_list);
12671 										     Wf_Event.AddParameterToList(p_name =>'REQUESTOR',
12672 													    p_value =>FND_GLOBAL.USER_NAME ,
12673 													    p_parameterlist => l_parameter_list);
12674 
12675 										    Wf_Event.Raise(	p_event_name => l_op_completed_event,
12676 													p_event_key => l_event_key,
12677 													p_parameters => l_parameter_list);
12678 										    l_parameter_list.DELETE;
12679 										    WF_CORE.CONTEXT('Enterprise Asset Management...','Work Order Operation Completed Event','After raising event');
12680 
12681 		END IF;   --end of check for raising op complete event
12682 
12683 
12684 	EXCEPTION -- Exception handler for main Operation records
12685 
12686 		    WHEN EXC_SEV_QUIT_RECORD THEN
12687 
12688 		      l_out_eam_op_comp_tbl		:= l_eam_op_comp_tbl;
12689 
12690 		      EAM_ERROR_MESSAGE_PVT.Log_Error
12691 		      (
12692 			      p_eam_op_comp_tbl			=>	l_eam_op_comp_tbl
12693 
12694 			     , x_eam_wo_comp_rec		=>	l_out_eam_wo_comp_rec
12695 			     , x_eam_wo_quality_tbl		=>	l_out_eam_wo_quality_tbl
12696 			     , x_eam_meter_reading_tbl		=>	l_out_eam_meter_reading_tbl
12697 			     , x_eam_counter_prop_tbl		=>      l_out_eam_counter_prop_tbl
12698 			     , x_eam_wo_comp_rebuild_tbl	=>	l_out_eam_wo_comp_rebuild_tbl
12699 			     , x_eam_wo_comp_mr_read_tbl	=>	l_out_eam_wo_comp_mr_read_tbl
12700 			     , x_eam_op_comp_tbl		=>	l_out_eam_op_comp_tbl
12701 			     , x_eam_request_tbl		=>	l_out_eam_request_tbl
12702 
12703 			     , p_mesg_token_tbl			=>	l_mesg_token_tbl
12704 			     , p_error_status			=>	FND_API.G_RET_STS_ERROR
12705 			     , p_error_scope			=>	EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
12706 			     , p_other_message			=>	l_other_message
12707 			     , p_other_status			=>	EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
12708 			     , p_other_token_tbl		=>	l_other_token_tbl
12709 
12710 			     , p_error_level			=>	EAM_ERROR_MESSAGE_PVT.G_WO_COMP_LEVEL
12711 		     );
12712 
12713 			l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
12714 
12715 			 x_return_status		:=	FND_API.G_RET_STS_ERROR;
12716 			 x_msg_count              	:=	l_msg_count;
12717 
12718 		    RETURN;
12719 	END ; -- End for op count > 0
12720 
12721 	END LOOP;
12722 
12723 END COMP_UNCOMP_OPERATION;
12724 
12725 
12726 
12727 
12728 
12729 
12730 
12731 
12732 
12733 
12734 
12735 
12736 
12737 PROCEDURE SERVICE_WORKREQUEST_ASSO
12738 	(
12739 	  p_eam_request_tbl	    IN EAM_PROCESS_WO_PUB.eam_request_tbl_type
12740 	, x_eam_request_tbl	    OUT NOCOPY EAM_PROCESS_WO_PUB.eam_request_tbl_type
12741 	, x_return_status           OUT NOCOPY VARCHAR2
12742 	, x_msg_count               OUT NOCOPY NUMBER
12743 	)
12744 	IS
12745 	l_mesg_token_tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
12746 	l_return_status         VARCHAR2(1) ;
12747 
12748 	l_eam_request_tbl	EAM_PROCESS_WO_PUB.eam_request_tbl_type;
12749 	l_eam_request_rec	EAM_PROCESS_WO_PUB.eam_request_rec_type;
12750 	l_out_eam_request_rec	EAM_PROCESS_WO_PUB.eam_request_rec_type;
12751 
12752 	l_org_id		NUMBER;
12753 	l_wip_entity_id		NUMBER;
12754 	l_valid_transaction     BOOLEAN := TRUE ;
12755 	l_other_token_tbl       EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
12756 	l_other_message         VARCHAR2(2000);
12757 	l_token_tbl             EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type ;
12758 	l_msg_count		NUMBER;
12759 	L_OUT_EAM_REQUEST_TBL	EAM_PROCESS_WO_PUB.eam_request_tbl_type;
12760 
12761 	l_out_eam_wo_comp_rec		EAM_PROCESS_WO_PUB.eam_wo_comp_rec_type;
12762 	l_out_eam_meter_reading_tbl     EAM_PROCESS_WO_PUB.eam_meter_reading_tbl_type;
12763 	l_out_eam_counter_prop_tbl	EAM_PROCESS_WO_PUB.eam_counter_prop_tbl_type;
12764 	l_out_eam_wo_comp_rebuild_tbl   EAM_PROCESS_WO_PUB.eam_wo_comp_rebuild_tbl_type;
12765 	l_out_eam_wo_comp_mr_read_tbl   EAM_PROCESS_WO_PUB.eam_wo_comp_mr_read_tbl_type;
12766 	l_out_eam_op_comp_tbl           EAM_PROCESS_WO_PUB.eam_op_comp_tbl_type;
12767 	l_out_eam_wo_quality_tbl	EAM_PROCESS_WO_PUB.eam_wo_quality_tbl_type;
12768 
12769 	BEGIN
12770 
12771 	IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Work Request Service Request association procedure begin ');  END IF;
12772 
12773 	x_return_status := FND_API.G_RET_STS_SUCCESS;
12774 	l_return_status	:= FND_API.G_RET_STS_SUCCESS;
12775 
12776 	l_eam_request_tbl := p_eam_request_tbl;
12777 
12778 	l_eam_request_rec := p_eam_request_tbl(p_eam_request_tbl.FIRST);
12779 
12780 	l_org_id	:= l_eam_request_rec.organization_id;
12781 	l_wip_entity_id := l_eam_request_rec.wip_entity_id;
12782 
12783 	FOR i IN p_eam_request_tbl.FIRST..p_eam_request_tbl.LAST LOOP
12784 	begin
12785 		l_eam_request_rec := p_eam_request_tbl(i);
12786 
12787 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Work Request Service Request association: Transaction Type Validity . . . ');  END IF;
12788 
12789 		VALIDATE_TRANSACTION_TYPE
12790 		(   p_transaction_type  => l_eam_request_rec.transaction_type
12791 		,   p_entity_name       => 'WORK_SERVICE_REQUEST'
12792 		,   p_entity_id         => l_eam_request_rec.wip_entity_id
12793 		,   x_valid_transaction => l_valid_transaction
12794 		,   x_mesg_token_tbl    => l_Mesg_Token_Tbl
12795 		);
12796 		IF NOT l_valid_transaction
12797 		THEN
12798 		    x_eam_request_tbl(i).return_status	:= EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
12799 		    l_other_message := 'EAM_WR_INVALID_TXN_TYPE';
12800 		    l_other_token_tbl(1).token_name  := 'REQUEST_ID';
12801 		    l_other_token_tbl(1).token_value := l_eam_request_rec.request_id;
12802 		    RAISE EXC_SEV_QUIT_RECORD;
12803 		END IF;
12804 
12805 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Work Request Service Request association: : Check Required . . .'); END IF;
12806 
12807 		EAM_REQUEST_VALIDATE_PVT.CHECK_REQUIRED
12808 		(
12809 		  p_eam_request_rec	=> l_eam_request_rec
12810 		 , x_return_status	=> l_return_status
12811 		 , x_mesg_token_tbl	=> l_Mesg_Token_Tbl
12812 		 );
12813 
12814 		  IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR THEN
12815 		  			x_eam_request_tbl(i).return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
12816 					l_other_message := 'EAM_WR_CHK_REQUIRED';
12817 					l_other_token_tbl(1).token_name  := 'REQUEST_ID';
12818 					l_other_token_tbl(1).token_value := l_eam_request_rec.request_id;
12819 					RAISE EXC_SEV_QUIT_RECORD;
12820 		  END IF;
12821 
12822 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Work Request Service Request association: : Attribute Defaulting . . .'); END IF;
12823 
12824 		EAM_REQUEST_DEFAULT_PVT.Attribute_Defaulting
12825 		(
12826 			 p_eam_request_rec    => l_eam_request_rec ,
12827 			 x_eam_request_rec    => l_out_eam_request_rec ,
12828 			 x_return_status      => l_return_status
12829 		);
12830 
12831 		l_eam_request_rec := l_out_eam_request_rec;
12832 
12833 		IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR THEN
12834 		  			x_eam_request_tbl(i).return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
12835 					l_other_message := 'EAM_WR_ATTR_DEFAULT';
12836 					l_other_token_tbl(1).token_name  := 'REQUEST_ID';
12837 					l_other_token_tbl(1).token_value := l_eam_request_rec.request_id;
12838 					RAISE EXC_SEV_QUIT_RECORD;
12839 		END IF;
12840 
12841 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Work Request Service Request association: : Check Attributes . . .'); END IF;
12842 
12843 		EAM_REQUEST_VALIDATE_PVT.CHECK_ATTRIBUTES
12844 		(
12845 			 p_eam_request_rec      => l_eam_request_rec
12846 			 , x_return_status      => l_return_status
12847 			 , x_mesg_token_tbl     => l_mesg_token_tbl
12848 		);
12849 
12850 		IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR THEN
12851 		  			x_eam_request_tbl(i).return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
12852 					l_other_message := 'EAM_WR_CHECK_ATTR';
12853 					l_other_token_tbl(1).token_name  := 'REQUEST_ID';
12854 					l_other_token_tbl(1).token_value := l_eam_request_rec.request_id;
12855 					RAISE EXC_SEV_QUIT_RECORD;
12856 		END IF;
12857 
12858 		IF GET_DEBUG = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Work Request Service Request association: : Associating/Disassociating Work /Service Request. . .'); END IF;
12859 
12860 			IF l_eam_request_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_CREATE THEN
12861 				EAM_REQUEST_UTILITY_PVT.INSERT_ROW
12862 				(  p_eam_request_rec   => l_eam_request_rec
12863 				 , x_return_status     => l_return_status
12864 				 , x_mesg_token_tbl    => l_mesg_token_tbl
12865 				 );
12866 			END IF;
12867 
12868 			IF l_eam_request_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UPDATE THEN
12869 				EAM_REQUEST_UTILITY_PVT.DELETE_ROW
12870 				(  p_eam_request_rec   => l_eam_request_rec
12871 				 , x_return_status     => l_return_status
12872 				 , x_mesg_token_tbl    => l_mesg_token_tbl
12873 				 );
12874 
12875 			END IF;
12876 
12877 			IF l_return_status = EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR THEN
12878 		  			x_eam_request_tbl(i).return_status := EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
12879 					l_other_message := 'EAM_WR_INSERT_REC';
12880 					l_other_token_tbl(1).token_name  := 'REQUEST_ID';
12881 					l_other_token_tbl(1).token_value := l_eam_request_rec.request_id;
12882 					RAISE EXC_SEV_QUIT_RECORD;
12883 			END IF;
12884 
12885 			x_eam_request_tbl(i).return_status := FND_API.G_RET_STS_SUCCESS;
12886 	END;
12887 	END LOOP;
12888 
12889 	EXCEPTION
12890 
12891 		    WHEN EXC_SEV_QUIT_RECORD THEN
12892 
12893 		      l_out_eam_request_tbl		:= l_eam_request_tbl;
12894 
12895 		      EAM_ERROR_MESSAGE_PVT.Log_Error
12896 		      (
12897 			      p_eam_request_tbl			=>	l_eam_request_tbl
12898 
12899 			     , x_eam_wo_comp_rec		=>	l_out_eam_wo_comp_rec
12900 			     , x_eam_wo_quality_tbl		=>	l_out_eam_wo_quality_tbl
12901 			     , x_eam_meter_reading_tbl		=>	l_out_eam_meter_reading_tbl
12902 			     , x_eam_counter_prop_tbl		=>      l_out_eam_counter_prop_tbl
12903 			     , x_eam_wo_comp_rebuild_tbl	=>	l_out_eam_wo_comp_rebuild_tbl
12904 			     , x_eam_wo_comp_mr_read_tbl	=>	l_out_eam_wo_comp_mr_read_tbl
12905 			     , x_eam_op_comp_tbl		=>	l_out_eam_op_comp_tbl
12906 			     , x_eam_request_tbl		=>	l_out_eam_request_tbl
12907 
12908 			     , p_mesg_token_tbl			=>	l_mesg_token_tbl
12909 			     , p_error_status			=>	FND_API.G_RET_STS_ERROR
12910 			     , p_error_scope			=>	EAM_ERROR_MESSAGE_PVT.G_WO_LEVEL
12911 			     , p_other_message			=>	l_other_message
12912 			     , p_other_status			=>	EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR
12913 			     , p_other_token_tbl		=>	l_other_token_tbl
12914 
12915 			     , p_error_level			=>	EAM_ERROR_MESSAGE_PVT.G_WO_COMP_LEVEL
12916 		     );
12917 
12918 			l_msg_count := EAM_ERROR_MESSAGE_PVT.GET_MESSAGE_COUNT();
12919 			x_return_status          	:=	EAM_ERROR_MESSAGE_PVT.G_STATUS_ERROR;
12920 			x_msg_count              	:=	l_msg_count;
12921 
12922 		    RETURN;
12923 
12924 	END SERVICE_WORKREQUEST_ASSO;
12925 
12926 
12927 END EAM_PROCESS_WO_PVT;