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