DBA Data[Home] [Help]

PACKAGE BODY: APPS.AHL_EAM_JOB_PVT

Source


1 PACKAGE BODY AHL_EAM_JOB_PVT AS
2 /* $Header: AHLVEAMB.pls 120.8.12020000.2 2012/12/14 09:36:02 shnatu ship $ */
3 
4 G_PKG_NAME VARCHAR2(30) := 'AHL_EAM_JOB_PVT';
5 G_DEBUG    VARCHAR2(1)  := AHL_DEBUG_PUB.is_log_enabled;
6 
7 --Modified By Srini July 01, 2004
8  PROCEDURE log_path(
9   x_output_dir      OUT NOCOPY VARCHAR2
10 
11 	  )
12 	IS
13 		        l_full_path     VARCHAR2(512);
14 			l_new_full_path         VARCHAR2(512);
15 			l_file_dir      VARCHAR2(512);
16 
17 			fileHandler     UTL_FILE.FILE_TYPE;
18 			fileName        VARCHAR2(50);
19 
20 			l_flag          NUMBER;
21 	BEGIN
22 	           fileName:='test.log';--this is only a dummy filename to check if directory is valid or not
23 
24 
25         	   /* get output directory path from database */
26 			SELECT value
27 			INTO   l_full_path
28 			FROM   v$parameter
29 			WHERE  name = 'utl_file_dir';
30 
31 			l_flag := 0;
32 			--l_full_path contains a list of comma-separated directories
33 			WHILE(TRUE)
34 			LOOP
35 					    --get the first dir in the list
36 					    SELECT trim(substr(l_full_path, 1, decode(instr(l_full_path,',')-1,
37 											  -1, length(l_full_path),
38 											  instr(l_full_path, ',')-1
39 											 )
40 								  )
41 							   )
42 					    INTO  l_file_dir
43 					    FROM  dual;
44 
45 					    -- check if the dir is valid
46 					    BEGIN
47 						    fileHandler := UTL_FILE.FOPEN(l_file_dir , filename, 'w');
48 						    l_flag := 1;
49 					    EXCEPTION
50 						    WHEN utl_file.invalid_path THEN
51 							l_flag := 0;
52 						    WHEN utl_file.invalid_operation THEN
53 							l_flag := 0;
54 					    END;
55 
56 					    IF l_flag = 1 THEN --got a valid directory
57 						utl_file.fclose(fileHandler);
58 						EXIT;
59 					    END IF;
60 
61 					    --earlier found dir was not a valid dir,
62 					    --so remove that from the list, and get the new list
63 					    l_new_full_path := trim(substr(l_full_path, instr(l_full_path, ',')+1, length(l_full_path)));
64 
65 					    --if the new list has not changed, there are no more valid dirs left
66 					    IF l_full_path = l_new_full_path THEN
67 						    l_flag:=0;
68 						    EXIT;
69 					    END IF;
70 					     l_full_path := l_new_full_path;
71 			 END LOOP;
72 
73 
74 			 IF(l_flag=1) THEN --found a valid directory
75 			     x_output_dir := l_file_dir;
76 
77 			  ELSE
78 			      x_output_dir:= null;
79 
80 			  END IF;
81          EXCEPTION
82               WHEN OTHERS THEN
83                   x_output_dir := null;
84 
85 	END log_path;
86 
87 PROCEDURE set_eam_debug_params
88 (
89   x_debug           OUT NOCOPY VARCHAR2,
90   x_output_dir      OUT NOCOPY VARCHAR2,
91   x_debug_file_name OUT NOCOPY VARCHAR2,
92   x_debug_file_mode OUT NOCOPY VARCHAR2
93 )
94 AS
95 l_output_dir  VARCHAR2(512);
96 
97 BEGIN
98   x_debug := 'Y';
99 
100 --  SELECT trim(substr(VALUE, 1, DECODE( instr( VALUE, ','), 0, length( VALUE), instr( VALUE, ',') -1 ) ) )
101 --  INTO   x_output_dir
102 --  FROM   V$PARAMETER
103 --  WHERE  NAME = 'utl_file_dir';
104   --Call log path
105  log_path( x_output_dir => l_output_dir);
106   --
107   x_output_dir := l_output_dir;
108   x_debug_file_name := 'EAMDEBUG.log';
109   x_debug_file_mode := 'a';
110 
111   IF ( G_DEBUG = 'Y' ) THEN
112     AHL_DEBUG_PUB.debug( 'Debug Log Directory Path:'||x_output_dir );
113     AHL_DEBUG_PUB.debug( 'Debug Log File Name:'||x_debug_file_name );
114   END IF;
115 
116 END set_eam_debug_params;
117 -- End of Modification
118 
119 -- Procedure for getting appropriate workorder type which corresponds to work_order_type in
120 -- in WIP and set the workorder name based on profiles.
121 
122 PROCEDURE get_workorder_details(
123   p_visit_task_id         IN  NUMBER,
124   p_master_workorder_flag IN VARCHAR2,
125   x_workorder_type        OUT NOCOPY VARCHAR2,
126   x_workorder_prefix      OUT NOCOPY VARCHAR2)
127 
128 IS
129 
130  -- cursor to get the Unit_eff ID from task ID
131  CURSOR get_ue_id_csr (p_task_id IN NUMBER) IS
132    SELECT unit_effectivity_id
133    FROM ahl_visit_tasks_b vst
134    WHERE visit_task_id = p_task_id;
135 
136 
137  -- Cursor to get UE details only for a top UE ID.
138  CURSOR get_ue_detail_csr(p_ue_id IN NUMBER)
139  IS
140  SELECT
141     cs_incident_id, nvl(manually_planned_flag,'N')
142  FROM
143     AHL_UNIT_EFFECTIVITIES_B UE
144  WHERE
145     UE.unit_effectivity_id = p_ue_id
146     AND NOT EXISTS (SELECT 'x'
147                     FROM AHL_UE_RELATIONSHIPS UER
148                     WHERE UER.related_ue_id = UE.unit_effectivity_id
149                    );
150 
151  -- get originator UE details for a child UE.
152  CURSOR get_uer_detail_csr(p_ue_id IN NUMBER)
153  IS
154  SELECT
155     cs_incident_id, nvl(manually_planned_flag,'N')
156  FROM
157     AHL_UNIT_EFFECTIVITIES_B UE
158  WHERE
159     UE.unit_effectivity_id IN (SELECT originator_ue_id
160                                FROM AHL_UE_RELATIONSHIPS UER
161                                WHERE UER.related_ue_id = p_ue_id
162                                );
163 
164  -- Define local variables here
165  l_cs_incident_id         NUMBER;
166  l_manually_planned_flag  VARCHAR2(1);
167  l_ue_id                  NUMBER;
168 
169  --profiles for workorder types.
170  l_DEFAULT_WORKORDER_TYPE    VARCHAR2(30)    := fnd_profile.value('AHL_WORKORDER_TYPE_DEFAULT');
171  l_NONROUTINE_WORKORDER_TYPE VARCHAR2(30) := fnd_profile.value('AHL_WORKORDER_TYPE_NONROUTINE');
172  l_PLANNED_WORKORDER_TYPE    VARCHAR2(30)    := fnd_profile.value('AHL_WORKORDER_TYPE_PLANNED');
173  l_UNPLANNED_WORKORDER_TYPE  VARCHAR2(30)  := fnd_profile.value('AHL_WORKORDER_TYPE_UNPLANNED');
174 
175  -- profiles for workorder name.
176  l_MR_prefix  VARCHAR2(30) := fnd_profile.value('AHL_MR_WORKORDER_PREFIX');
177  l_NR_prefix  VARCHAR2(30) := fnd_profile.value('AHL_NR_WORKORDER_PREFIX');
178 
179 BEGIN
180    -- initialize out parameters.
181    x_workorder_type := NULL;
182    x_workorder_prefix := NULL;
183 
184    -- Log Input Values
185    IF ( G_DEBUG = 'Y' ) THEN
186       AHL_DEBUG_PUB.debug('Default Workorder Type profile: ' || l_DEFAULT_WORKORDER_TYPE);
187       AHL_DEBUG_PUB.debug('Planned Workorder Type profile: ' || l_PLANNED_WORKORDER_TYPE);
188       AHL_DEBUG_PUB.debug('Unplanned Workorder Type profile: ' || l_UNPLANNED_WORKORDER_TYPE);
189       AHL_DEBUG_PUB.debug('NonRoutine Workorder Type profile: ' || l_NONROUTINE_WORKORDER_TYPE);
190 
191       AHL_DEBUG_PUB.debug('NonRoutine Workorder Prefix profile: ' || l_MR_prefix);
192       AHL_DEBUG_PUB.debug('MR workorder prefix profile: ' || l_NR_prefix);
193 
194 
195       AHL_DEBUG_PUB.debug('Input Visit Task: ' || p_visit_task_id);
196       AHL_DEBUG_PUB.debug('Input Master_workorder_flag: ' || p_master_workorder_flag);
197 
198    END IF;
199 
200    -- Check whether default profile has been set up or not
201    -- throw error "Please set up the profile value for AHL : Default WorkorderType".
202    IF l_DEFAULT_WORKORDER_TYPE IS NULL
203    THEN
204       FND_MESSAGE.set_name('AHL','AHL_PRD_NO_WORKORDER_TYPE');
205       FND_MSG_PUB.add;
206       RAISE FND_API.G_EXC_ERROR;
207    END IF;
208 
209    IF (p_visit_task_id IS NULL AND p_master_workorder_flag = 'Y' )
210    --************************Visit Master Workorder *******************--
211    THEN
212      x_workorder_type:=  l_DEFAULT_WORKORDER_TYPE;
213    ELSE
214       -- Get unit effectivity ID for the visit task.
215       OPEN get_ue_id_csr(p_visit_task_id);
216       FETCH get_ue_id_csr INTO l_ue_id;
217       IF (get_ue_id_csr%NOTFOUND) THEN
218          CLOSE get_ue_id_csr;
219          FND_MESSAGE.set_name('AHL','AHL_PRD_VISIT_TASK_NULL');
220          FND_MSG_PUB.add;
221          RAISE FND_API.G_EXC_ERROR;
222       END IF;
223       CLOSE get_ue_id_csr;
224 
225       IF (l_ue_id IS NULL) THEN
226           -- unassociated task.
227           IF (l_UNPLANNED_WORKORDER_TYPE IS NOT NULL) THEN
228              x_workorder_type:= l_UNPLANNED_WORKORDER_TYPE;
229           END IF;
230       ELSE
231           -- planned/unplanned MR /non-routine case.
232           -- get unit effectivity details.
233           OPEN get_ue_detail_csr (l_ue_id);
234           FETCH get_ue_detail_csr INTO l_cs_incident_id, l_manually_planned_flag;
235           IF (get_ue_detail_csr%NOTFOUND) THEN
236             -- Check for child UE.
237             OPEN get_uer_detail_csr(l_ue_id);
238             FETCH get_uer_detail_csr INTO l_cs_incident_id, l_manually_planned_flag;
239             CLOSE get_uer_detail_csr;
240           END IF; -- ahl_ue_detail_csr.
241           CLOSE get_ue_detail_csr;
242 
243           -- Check non-Routine.
244           IF (l_cs_incident_id IS NOT NULL) THEN
245             x_workorder_type := l_NONROUTINE_WORKORDER_TYPE;
246             -- set workorder prefix.
247             IF (p_master_workorder_flag = 'Y') THEN
248               x_workorder_prefix := l_NR_prefix;
249             END IF;
250           ELSIF (l_manually_planned_flag = 'Y') THEN
251             x_workorder_type:= l_UNPLANNED_WORKORDER_TYPE;
252             -- set workorder prefix.
253             IF (p_master_workorder_flag = 'Y') THEN
254               x_workorder_prefix := l_MR_prefix;
255             END IF;
256           ELSIF (l_manually_planned_flag = 'N') THEN
257             x_workorder_type:= l_PLANNED_WORKORDER_TYPE;
258             IF (p_master_workorder_flag = 'Y') THEN
259               x_workorder_prefix := l_MR_prefix;
260             END IF;
261           END IF;
262       END IF;  -- l_ue_id is null.
263 
264    END IF; -- p_visit_task_id IS NULL AND p_master_workorder_flag = 'Y'
265 
266    -- Check if x_workorder_type is null;
267    IF (x_workorder_type IS NULL) THEN
268       x_workorder_type := l_DEFAULT_WORKORDER_TYPE;
269    END IF;
270 
271    IF ( G_DEBUG = 'Y' ) THEN
272       AHL_DEBUG_PUB.debug('Workorder Type : ' || x_workorder_type);
273       AHL_DEBUG_PUB.debug('Workorder Prefix : ' || x_workorder_prefix);
274    END IF;
275 
276 END get_workorder_details;
277 
278 PROCEDURE map_ahl_eam_wo_rec
279 (
280   p_workorder_rec  IN          AHL_PRD_WORKORDER_PVT.prd_workorder_rec,
281   x_eam_wo_rec     OUT NOCOPY  EAM_PROCESS_WO_PUB.eam_wo_rec_type
282 )
283 AS
284 
285 CURSOR Get_Job_Dates_Cur (c_wip_entity_id IN NUMBER)
286  IS
287 SELECT SCHEDULED_START_DATE,
288        SCHEDULED_COMPLETION_DATE, DATE_RELEASED
289   FROM WIP_DISCRETE_JOBS
290 WHERE WIP_ENTITY_ID = c_wip_entity_id;
291 --
292 Get_Job_Dates_Rec  Get_Job_Dates_Cur%ROWTYPE;
293 l_workorder_type   VARCHAR2(30);
294 l_workorder_prefix VARCHAR2(30);
295 
296 BEGIN
297 
298   -- Log Input Values
299   IF ( G_DEBUG = 'Y' ) THEN
300     AHL_DEBUG_PUB.debug( 'dml_operation: ' || p_workorder_rec.dml_operation );
301     AHL_DEBUG_PUB.debug( 'batch_id: ' || TO_CHAR( p_workorder_rec.batch_id ) );
302     AHL_DEBUG_PUB.debug( 'header_id: ' || TO_CHAR( p_workorder_rec.header_id ) );
303     AHL_DEBUG_PUB.debug( 'workorder_id: ' || TO_CHAR( p_workorder_rec.workorder_id ) );
304     AHL_DEBUG_PUB.debug( 'organization_id: ' || TO_CHAR( p_workorder_rec.organization_id ) );
305     AHL_DEBUG_PUB.debug( 'wip_entity_id: ' || TO_CHAR( p_workorder_rec.wip_entity_id ) );
306     AHL_DEBUG_PUB.debug( 'job_number: ' || p_workorder_rec.job_number );
307     AHL_DEBUG_PUB.debug( 'job_description: ' || p_workorder_rec.job_description );
308     AHL_DEBUG_PUB.debug( 'inventory_item_id: ' || TO_CHAR( p_workorder_rec.inventory_item_id ) );
309     AHL_DEBUG_PUB.debug( 'item_instance_id: ' || TO_CHAR( p_workorder_rec.item_instance_id ) );
310     AHL_DEBUG_PUB.debug( 'class_code: ' || p_workorder_rec.class_code );
311     AHL_DEBUG_PUB.debug( 'status_code: ' || p_workorder_rec.status_code );
312     AHL_DEBUG_PUB.debug( 'department_id: ' || TO_CHAR( p_workorder_rec.department_id ) );
313     AHL_DEBUG_PUB.debug( 'job_priority: ' || TO_CHAR( p_workorder_rec.job_priority ) );
314     AHL_DEBUG_PUB.debug( 'firm_planned_flag: ' || TO_CHAR( p_workorder_rec.firm_planned_flag ) );
315     AHL_DEBUG_PUB.debug( 'project_id: ' || TO_CHAR( p_workorder_rec.project_id ) );
316     AHL_DEBUG_PUB.debug( 'project_task_id: ' || TO_CHAR( p_workorder_rec.project_task_id ) );
317     AHL_DEBUG_PUB.debug( 'wip_supply_type: ' || TO_CHAR( p_workorder_rec.wip_supply_type ) );
318     AHL_DEBUG_PUB.debug( 'scheduled_start_date: ' || TO_CHAR( p_workorder_rec.scheduled_start_date, 'DD-MON-YYYY hh24:mi') );
319     AHL_DEBUG_PUB.debug( 'scheduled_end_date: ' || TO_CHAR( p_workorder_rec.scheduled_end_date, 'DD-MON-YYYY hh24:mi') );
320   END IF;
321 
322   get_workorder_details (p_visit_task_id => p_workorder_rec.visit_task_id,
323                          p_master_workorder_flag =>  p_workorder_rec.master_workorder_flag,
324                          x_workorder_type        =>  l_workorder_type,
325                          x_workorder_prefix      =>  l_workorder_prefix);
326   -- Populate EAM Record attributes from input record
327   x_eam_wo_rec.batch_id := p_workorder_rec.batch_id;
328   x_eam_wo_rec.header_id := p_workorder_rec.header_id;
329   x_eam_wo_rec.wip_entity_id := p_workorder_rec.wip_entity_id;
330   x_eam_wo_rec.organization_id := p_workorder_rec.organization_id;
331   x_eam_wo_rec.wip_entity_name := substrb(l_workorder_prefix || p_workorder_rec.job_number,1,80);
332   x_eam_wo_rec.description := p_workorder_rec.job_description;
333   x_eam_wo_rec.rebuild_item_id := p_workorder_rec.inventory_item_id;
334   x_eam_wo_rec.maintenance_object_id := p_workorder_rec.item_instance_id;
335   x_eam_wo_rec.class_code := p_workorder_rec.class_code;
336 
337   -- CMRO contains more status codes than WIP. Map each status to WIP Status
338   IF ( p_workorder_rec.status_code = '19' OR
339        p_workorder_rec.status_code = '21' ) THEN
340     x_eam_wo_rec.status_type := 6;
341   ELSIF ( p_workorder_rec.status_code = '20' ) THEN
342     x_eam_wo_rec.status_type := 3;
343   ELSIF ( p_workorder_rec.status_code = '22' ) THEN
344     x_eam_wo_rec.status_type := 7;
345   ELSE
346     x_eam_wo_rec.status_type := TO_NUMBER( p_workorder_rec.status_code );
347   END IF;
348 
349   x_eam_wo_rec.owning_department := p_workorder_rec.department_id;
350   x_eam_wo_rec.priority := p_workorder_rec.job_priority;
351   x_eam_wo_rec.firm_planned_flag := p_workorder_rec.firm_planned_flag;
352   x_eam_wo_rec.project_id := p_workorder_rec.project_id;
353   x_eam_wo_rec.task_id := p_workorder_rec.project_task_id;
354   x_eam_wo_rec.wip_supply_type := p_workorder_rec.wip_supply_type;
355   x_eam_wo_rec.scheduled_start_date := p_workorder_rec.scheduled_start_date;
356   x_eam_wo_rec.scheduled_completion_date := p_workorder_rec.scheduled_end_date;
357 
358   -- Intialize EAM Record attributes with Constants
359   x_eam_wo_rec.maintenance_object_type := 3;
360   x_eam_wo_rec.maintenance_object_source := 2;
361   x_eam_wo_rec.job_quantity := 1;
362   --x_eam_wo_rec.work_order_type := 10;
363   x_eam_wo_rec.work_order_type := l_workorder_type;
364   x_eam_wo_rec.requested_start_date := NULL;
365   x_eam_wo_rec.due_date := NULL;
366   x_eam_wo_rec.notification_required := 'N';
367   x_eam_wo_rec.tagout_required := 'N';
368   x_eam_wo_rec.manual_rebuild_flag := 'Y';
369 
370   --Changes made by srini not to create project and task for Draft or Cancelled workorders
371   IF p_workorder_rec.status_code IN ('17','22') THEN
372   x_eam_wo_rec.project_id := NULL;
373   x_eam_wo_rec.task_id := NULL;
374   END IF;
375 
376   -- Do not pass
377   /**
378   x_eam_wo_rec.asset_number := NULL;
379   x_eam_wo_rec.asset_group_id := NULL;
380   x_eam_wo_rec.rebuild_serial_number := NULL;
381   x_eam_wo_rec.asset_activity_id := NULL;
382   x_eam_wo_rec.activity_type := NULL;
383   x_eam_wo_rec.activity_cause := NULL;
384   x_eam_wo_rec.activity_source := NULL;
385   x_eam_wo_rec.shutdown_type := NULL;
386   x_eam_wo_rec.bom_revision_date := NULL;
387   x_eam_wo_rec.routing_revision_date := NULL;
388   x_eam_wo_rec.alternate_routing_designator := NULL;
389   x_eam_wo_rec.alternate_bom_designator := NULL;
390   x_eam_wo_rec.routing_revision := NULL;
391   x_eam_wo_rec.bom_revision := NULL;
392   x_eam_wo_rec.pm_schedule_id := NULL;
393   x_eam_wo_rec.material_account := NULL;
394   x_eam_wo_rec.material_overhead_account := NULL;
395   x_eam_wo_rec.resource_account := NULL;
396   x_eam_wo_rec.outside_processing_account := NULL;
397   x_eam_wo_rec.material_variance_account := NULL;
398   x_eam_wo_rec.resource_variance_account := NULL;
399   x_eam_wo_rec.outside_proc_variance_account := NULL;
400   x_eam_wo_rec.std_cost_adjustment_account := NULL;
401   x_eam_wo_rec.overhead_account := NULL;
402   x_eam_wo_rec.overhead_variance_account := NULL;
403   x_eam_wo_rec.common_bom_sequence_id := NULL;
404   x_eam_wo_rec.common_routing_sequence_id := NULL;
405   x_eam_wo_rec.po_creation_time := NULL;
406   x_eam_wo_rec.plan_maintenance := ??;
407   x_eam_wo_rec.project_costed := ??;
408   x_eam_wo_rec.end_item_unit_number := ??;
409   x_eam_wo_rec.schedule_group_id := ??;
410   x_eam_wo_rec.parent_wip_entity_id := ??;
411   x_eam_wo_rec.gen_object_id := ??;
412   x_eam_wo_rec.source_line_id := ??;
413   x_eam_wo_rec.material_issue_by_mo := ??;
414   x_eam_wo_rec.user_id := ??;
415   x_eam_wo_rec.responsibility_id := ??;
416   x_eam_wo_rec.date_released := ??;
417   **/
418 
419   -- USAF ER: Integration to PS
420   -- Bypass EAM schedular.
421   x_eam_wo_rec.source_code := 'AHL';
422 
423   -- Set the DML Operation for the Job Header Record
424   IF ( p_workorder_rec.dml_operation = 'C' ) THEN
425     x_eam_wo_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_CREATE;
426   ELSIF ( p_workorder_rec.dml_operation = 'U' ) THEN
427     x_eam_wo_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_UPDATE;
428     --Srini
429 	OPEN Get_Job_Dates_Cur(x_eam_wo_rec.wip_entity_id);
430 	FETCH Get_Job_Dates_Cur INTO Get_Job_Dates_Rec;
431 	CLOSE Get_Job_Dates_Cur;
432 	-- we need to pass the requested start date for forward scheduling
433 
434         -- If the scheduled start date is changed, then pass requested start date
435         -- If the scheduled end date is changed, then pass due date
436         -- If both are changed then pass requested_start_date because if
437         -- both due date and requested start date are passed then EAM throws an error
438         IF (Get_Job_Dates_Rec.Scheduled_start_Date <> x_eam_wo_rec.scheduled_start_date) THEN
439            x_eam_wo_rec.requested_start_date  := x_eam_wo_rec.scheduled_start_date;
440         ELSIF (Get_Job_Dates_Rec.Scheduled_completion_Date <> x_eam_wo_rec.scheduled_completion_date) THEN
441            x_eam_wo_rec.due_date := x_eam_wo_rec.scheduled_completion_date;
442            --Due date should be passed for backward scheduling
443         END IF;
444 
445 	/*IF (Get_Job_Dates_Rec.Scheduled_completion_Date <> x_eam_wo_rec.scheduled_completion_date
446 	  AND  Get_Job_Dates_Rec.Scheduled_completion_Date < x_eam_wo_rec.scheduled_completion_date )
447 	  THEN
448 	   x_eam_wo_rec.requested_start_date  := x_eam_wo_rec.scheduled_completion_date;
449 	   --Due date should be passsed for backward scheduling
450 	 ELSIF  (Get_Job_Dates_Rec.Scheduled_completion_Date <> x_eam_wo_rec.scheduled_completion_date
451 	  AND  Get_Job_Dates_Rec.Scheduled_completion_Date > x_eam_wo_rec.scheduled_completion_date )
452 	  THEN
453 	   x_eam_wo_rec.due_date  := x_eam_wo_rec.scheduled_completion_date;
454 	END IF;
455         */
456   END IF;
457   -- rroy
458 		-- workorder backdating fix
459 		-- set the date_released parameter
460 		-- of the eam workorder record to
461 		-- min(scheduled_start_date, sysdate)
462 		-- if the new status code is 3(Released) or 6 (On Hold)
463 		-- This is being done for statuses 3 and 6 because
464 		-- the EAM code updates the p_release_date parameter
465 		-- for the above statuses in the call to WIP_CHANGE_STATUS.Release
466 		--
467                 /*IF p_workorder_rec.status_code IN ('3', '6') THEN
468 		  x_eam_wo_rec.date_released := least(Get_Job_Dates_Rec.date_released, p_workorder_rec.scheduled_start_date, sysdate);
469 		END IF;
470 		*/
471 
472 
473   IF ( G_DEBUG = 'Y' ) THEN
474 
475     AHL_DEBUG_PUB.debug( 'Requested Start Date: ' || TO_CHAR( x_eam_wo_rec.requested_start_date, 'DD-MON-YYYY hh24:mi') );
476     AHL_DEBUG_PUB.debug( 'Due Date: ' || TO_CHAR( x_eam_wo_rec.due_date, 'DD-MON-YYYY hh24:mi') );
477   END IF;
478 
479   x_eam_wo_rec.return_status := NULL;
480 
481 END map_ahl_eam_wo_rec;
482 --
483 
484 PROCEDURE map_ahl_eam_wo_rel_rec
485 (
486   p_workorder_rel_rec    IN         AHL_PRD_WORKORDER_PVT.prd_workorder_rel_rec,
487   x_eam_wo_relations_rec OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_relations_rec_type
488 )
489 AS
490 
491 BEGIN
492 
493   -- Log Input Values
494   IF ( G_DEBUG = 'Y' ) THEN
495     AHL_DEBUG_PUB.debug( 'dml_operation: ' || p_workorder_rel_rec.dml_operation );
496     AHL_DEBUG_PUB.debug( 'batch_id: ' || TO_CHAR( p_workorder_rel_rec.batch_id ) );
497     AHL_DEBUG_PUB.debug( 'wo_relationship_id: ' || TO_CHAR( p_workorder_rel_rec.wo_relationship_id ) );
498     AHL_DEBUG_PUB.debug( 'parent_header_id: ' || TO_CHAR( p_workorder_rel_rec.parent_header_id ) );
499     AHL_DEBUG_PUB.debug( 'parent_wip_entity_id: ' || TO_CHAR( p_workorder_rel_rec.parent_wip_entity_id ) );
500     AHL_DEBUG_PUB.debug( 'child_header_id: ' || TO_CHAR( p_workorder_rel_rec.child_header_id ) );
501     AHL_DEBUG_PUB.debug( 'child_wip_entity_id: ' || TO_CHAR( p_workorder_rel_rec.child_wip_entity_id ) );
502     AHL_DEBUG_PUB.debug( 'relationship_type: ' || TO_CHAR( p_workorder_rel_rec.relationship_type ) );
503   END IF;
504 
505   -- Populate EAM Record attributes from input record
506   x_eam_wo_relations_rec.batch_id := p_workorder_rel_rec.batch_id;
507   x_eam_wo_relations_rec.wo_relationship_id := p_workorder_rel_rec.wo_relationship_id;
508   x_eam_wo_relations_rec.parent_header_id := p_workorder_rel_rec.parent_header_id;
509   x_eam_wo_relations_rec.parent_object_type_id := 1;
510   x_eam_wo_relations_rec.parent_object_id := p_workorder_rel_rec.parent_wip_entity_id;
511   x_eam_wo_relations_rec.child_header_id := p_workorder_rel_rec.child_header_id;
512   x_eam_wo_relations_rec.child_object_type_id := 1;
513   x_eam_wo_relations_rec.child_object_id := p_workorder_rel_rec.child_wip_entity_id;
514   x_eam_wo_relations_rec.parent_relationship_type := p_workorder_rel_rec.relationship_type;
515   x_eam_wo_relations_rec.relationship_status := 0;
516 
517   -- Set the DML Operation for the Job Header Record
518   IF ( p_workorder_rel_rec.dml_operation = 'C' ) THEN
519     x_eam_wo_relations_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_CREATE;
520   ELSIF ( p_workorder_rel_rec.dml_operation = 'D' ) THEN
521     x_eam_wo_relations_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_DELETE;
522   END IF;
523 
524   x_eam_wo_relations_rec.return_status := NULL;
525 
526 END map_ahl_eam_wo_rel_rec;
527 
528 PROCEDURE map_ahl_eam_op_rec
529 (
530   p_operation_rec  IN         AHL_PRD_OPERATIONS_PVT.prd_workoperation_rec,
531   x_eam_op_rec     OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_rec_type
532 )
533 AS
534 
535 BEGIN
536 
537   -- Log Input Values
538   IF ( G_DEBUG = 'Y' ) THEN
539     AHL_DEBUG_PUB.debug( 'dml_operation: ' || p_operation_rec.dml_operation );
540     AHL_DEBUG_PUB.debug( 'workorder_id: ' || TO_CHAR( p_operation_rec.workorder_id ) );
541     AHL_DEBUG_PUB.debug( 'wip_entity_id: ' || TO_CHAR( p_operation_rec.wip_entity_id ) );
542     AHL_DEBUG_PUB.debug( 'organization_id: ' || TO_CHAR( p_operation_rec.organization_id ) );
543     AHL_DEBUG_PUB.debug( 'operation_sequence_num: ' || TO_CHAR( p_operation_rec.operation_sequence_num) );
544     AHL_DEBUG_PUB.debug( 'department_id: ' || TO_CHAR( p_operation_rec.department_id) );
545     AHL_DEBUG_PUB.debug( 'operation_description: ' || p_operation_rec.operation_description );
546     AHL_DEBUG_PUB.debug( 'minimum_transfer_quantity: ' || TO_CHAR( p_operation_rec.minimum_transfer_quantity) );
547     AHL_DEBUG_PUB.debug( 'count_point_type: ' || TO_CHAR( p_operation_rec.count_point_type) );
548     AHL_DEBUG_PUB.debug( 'scheduled_start_date: ' || TO_CHAR( p_operation_rec.scheduled_start_date, 'DD-MON-YYYY hh24:mi') );
549     AHL_DEBUG_PUB.debug( 'scheduled_end_date: ' || TO_CHAR( p_operation_rec.scheduled_end_date, 'DD-MON-YYYY hh24:mi') );
550   END IF;
551 
552   -- Populate EAM Record attributes from input table
553   x_eam_op_rec.wip_entity_id := p_operation_rec.wip_entity_id;
554   x_eam_op_rec.organization_id := p_operation_rec.organization_id;
555   x_eam_op_rec.operation_seq_num := p_operation_rec.operation_sequence_num;
556   x_eam_op_rec.department_id := p_operation_rec.department_id;
557   x_eam_op_rec.long_description := p_operation_rec.operation_description;
558   -- Bug # 8323205 (FP For Bug # 8257536) -- start
559   x_eam_op_rec.description := SUBSTRB(RTRIM(p_operation_rec.operation_description),1,240);
560   -- Bug # 8323205 (FP For Bug # 8257536) -- end
561 
562   IF ( p_operation_rec.dml_operation = 'C' ) THEN
563     x_eam_op_rec.minimum_transfer_quantity := 1;
564   ELSIF ( p_operation_rec.dml_operation = 'U' ) THEN
565     x_eam_op_rec.minimum_transfer_quantity := p_operation_rec.minimum_transfer_quantity;
566   END IF;
567 
568   IF ( p_operation_rec.dml_operation = 'C' ) THEN
569     x_eam_op_rec.count_point_type := 2;
570   ELSIF ( p_operation_rec.dml_operation = 'U' ) THEN
571     x_eam_op_rec.count_point_type := p_operation_rec.count_point_type;
572   END IF;
573 
574   -- Missing in AHL
575   IF ( p_operation_rec.dml_operation = 'C' ) THEN
576     x_eam_op_rec.backflush_flag := 2;
577   END IF;
578 
579   x_eam_op_rec.start_date := p_operation_rec.scheduled_start_date;
580   x_eam_op_rec.completion_date := p_operation_rec.scheduled_end_date;
581 
582   -- Do not Pass
583   /**
584   x_eam_op_rec.standard_operation_id := ??;
585   x_eam_op_rec.operation_sequence_id := ??;
586   x_eam_op_rec.shutdown_type := ??;
587   **/
588 
589   -- Set the DML Operation for the Record
590   IF ( p_operation_rec.dml_operation = 'C' ) THEN
591     x_eam_op_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_CREATE;
592   ELSIF ( p_operation_rec.dml_operation = 'U' ) THEN
593     x_eam_op_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_UPDATE;
594   END IF;
595 
596   x_eam_op_rec.return_status := NULL;
597 
598 END map_ahl_eam_op_rec;
599 
600 PROCEDURE map_ahl_eam_mat_rec
601 (
602   p_material_req_rec IN         AHL_PP_MATERIALS_PVT.req_material_rec_type,
603   x_eam_mat_req_rec  OUT NOCOPY EAM_PROCESS_WO_PUB.eam_mat_req_rec_type
604 )
605 AS
606 
607 BEGIN
608 
609   -- Log Input Values
610   IF ( G_DEBUG = 'Y' ) THEN
611     AHL_DEBUG_PUB.debug( 'operation_flag : ' || p_material_req_rec.operation_flag );
612     AHL_DEBUG_PUB.debug( 'workorder_id: ' || TO_CHAR( p_material_req_rec.workorder_id ) );
613     AHL_DEBUG_PUB.debug( 'wip_entity_id: ' || TO_CHAR( p_material_req_rec.wip_entity_id ) );
614     AHL_DEBUG_PUB.debug( 'organization_id: ' || TO_CHAR( p_material_req_rec.organization_id ) );
615     AHL_DEBUG_PUB.debug( 'operation_sequence: ' || TO_CHAR( p_material_req_rec.operation_sequence) );
616     AHL_DEBUG_PUB.debug( 'inventory_item_id: ' || TO_CHAR( p_material_req_rec.inventory_item_id) );
617     AHL_DEBUG_PUB.debug( 'requested_quantity: ' || TO_CHAR( p_material_req_rec.requested_quantity) );
618     AHL_DEBUG_PUB.debug( 'department_id: ' || TO_CHAR( p_material_req_rec.department_id) );
619     AHL_DEBUG_PUB.debug( 'requested_date: ' || TO_CHAR( p_material_req_rec.requested_date, 'DD-MON-YYYY hh24:mi') );
620   END IF;
621 
622   -- Populate EAM Record attributes from input table
623   x_eam_mat_req_rec.wip_entity_id := p_material_req_rec.wip_entity_id;
624   x_eam_mat_req_rec.organization_id := p_material_req_rec.organization_id;
625   x_eam_mat_req_rec.operation_seq_num := p_material_req_rec.operation_sequence;
626   x_eam_mat_req_rec.inventory_item_id := p_material_req_rec.inventory_item_id;
627   x_eam_mat_req_rec.quantity_per_assembly := p_material_req_rec.requested_quantity;
628   x_eam_mat_req_rec.department_id := p_material_req_rec.department_id;
629   x_eam_mat_req_rec.date_required := p_material_req_rec.requested_date;
630   x_eam_mat_req_rec.required_quantity := p_material_req_rec.requested_quantity;
631   --x_eam_mat_req_rec.quantity_issued := p_material_req_rec.requested_quantity;
632   x_eam_mat_req_rec.mrp_net_flag := p_material_req_rec.mrp_net_flag;
633 
634   -- Intialize EAM Record attributes with Constants
635   x_eam_mat_req_rec.wip_supply_type := 1;
636   -- fix for bug# 7217613. Pass quantity issued to EAM only when creating the requirement.
637   IF ( p_material_req_rec.operation_flag = 'C' ) THEN
638     x_eam_mat_req_rec.quantity_issued := 0;
639   END IF;
640 
641   -- Do not Pass
642   /**
643   x_eam_mat_req_rec.supply_subinventory := ??;
644   x_eam_mat_req_rec.supply_locator_id := ??;
645   x_eam_mat_req_rec.mps_required_quantity := ??;
646   x_eam_mat_req_rec.mps_date_required := ??;
647   x_eam_mat_req_rec.component_sequence_id := ??;
648   x_eam_mat_req_rec.comments := ??;
649   **/
650 
651   -- Set the DML Operation for the Record
652   IF ( p_material_req_rec.operation_flag = 'C' ) THEN
653     x_eam_mat_req_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_CREATE;
654   ELSIF ( p_material_req_rec.operation_flag = 'U' ) THEN
655     x_eam_mat_req_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_UPDATE;
656   ELSIF ( p_material_req_rec.operation_flag = 'D' ) THEN
657     x_eam_mat_req_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_DELETE;
658   END IF;
659 
660   x_eam_mat_req_rec.return_status := NULL;
661 
662 END map_ahl_eam_mat_rec;
663 
664 PROCEDURE map_ahl_eam_res_rec
665 (
666   p_resource_req_rec IN       AHL_PP_RESRC_REQUIRE_PVT.resrc_require_rec_type,
667   x_eam_res_rec    OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_rec_type
668 )
669 AS
670 
671 BEGIN
672   -- Log Input Values
673   IF ( G_DEBUG = 'Y' ) THEN
674     AHL_DEBUG_PUB.debug( 'operation_flag : ' || p_resource_req_rec.operation_flag );
675     AHL_DEBUG_PUB.debug( 'workorder_id: ' || TO_CHAR( p_resource_req_rec.workorder_id ) );
676     AHL_DEBUG_PUB.debug( 'wip_entity_id: ' || TO_CHAR( p_resource_req_rec.wip_entity_id ) );
677     AHL_DEBUG_PUB.debug( 'organization_id: ' || TO_CHAR( p_resource_req_rec.organization_id ) );
678     AHL_DEBUG_PUB.debug( 'operation_sequence: ' || TO_CHAR( p_resource_req_rec.operation_seq_number) );
679     AHL_DEBUG_PUB.debug( 'resource_seq_number: ' || TO_CHAR( p_resource_req_rec.resource_seq_number) );
680     AHL_DEBUG_PUB.debug( 'resource_id: ' || TO_CHAR( p_resource_req_rec.resource_id) );
681     AHL_DEBUG_PUB.debug( 'uom_code: ' || p_resource_req_rec.uom_code );
682     AHL_DEBUG_PUB.debug( 'cost_basis_code: ' || TO_CHAR( p_resource_req_rec.cost_basis_code ) );
683     AHL_DEBUG_PUB.debug( 'charge_type_code: ' || TO_CHAR( p_resource_req_rec.charge_type_code) );
684     AHL_DEBUG_PUB.debug( 'std_rate_flag_code: ' || TO_CHAR( p_resource_req_rec.std_rate_flag_code) );
685     AHL_DEBUG_PUB.debug( 'scheduled_type_code: ' || TO_CHAR( p_resource_req_rec.scheduled_type_code) );
686     AHL_DEBUG_PUB.debug( 'applied_num: ' || TO_CHAR( p_resource_req_rec.applied_num) );
687     AHL_DEBUG_PUB.debug( 'open_num: ' || TO_CHAR( p_resource_req_rec.open_num) );
688     AHL_DEBUG_PUB.debug( 'req_start_date: ' || TO_CHAR( p_resource_req_rec.req_start_date, 'DD-MON-YYYY hh24:mi') );
689     AHL_DEBUG_PUB.debug( 'req_end_date: ' || TO_CHAR( p_resource_req_rec.req_end_date, 'DD-MON-YYYY hh24:mi') );
690     AHL_DEBUG_PUB.debug( 'quantity: ' || TO_CHAR( p_resource_req_rec.quantity) );
691     AHL_DEBUG_PUB.debug( 'duration: ' || TO_CHAR( p_resource_req_rec.duration) );
692   END IF;
693 
694   -- Populate EAM Record attributes from input table
695   x_eam_res_rec.wip_entity_id := p_resource_req_rec.wip_entity_id;
696   x_eam_res_rec.organization_id := p_resource_req_rec.organization_id;
697   x_eam_res_rec.operation_seq_num := p_resource_req_rec.operation_seq_number;
698   x_eam_res_rec.resource_seq_num := p_resource_req_rec.resource_seq_number;
699   x_eam_res_rec.resource_id := p_resource_req_rec.resource_id;
700   x_eam_res_rec.uom_code := p_resource_req_rec.uom_code;
701   x_eam_res_rec.basis_type := p_resource_req_rec.cost_basis_code;
702   x_eam_res_rec.autocharge_type := p_resource_req_rec.charge_type_code;
703   x_eam_res_rec.standard_rate_flag := p_resource_req_rec.std_rate_flag_code;
704   x_eam_res_rec.scheduled_flag := p_resource_req_rec.scheduled_type_code;
705   x_eam_res_rec.start_date := p_resource_req_rec.req_start_date;
706   x_eam_res_rec.completion_date := p_resource_req_rec.req_end_date;
707   x_eam_res_rec.usage_rate_or_amount := p_resource_req_rec.duration;
708   x_eam_res_rec.assigned_units := p_resource_req_rec.quantity;
709 -- JKJAIN US space FP for ER # 6998882 -- start
710   x_eam_res_rec.schedule_seq_num := p_resource_req_rec.schedule_seq_num;
711 -- JKJAIN US space FP for ER # 6998882 -- end
712   --  Do not Pass
713   /**
714   x_eam_res_rec.activity_id := p_resource_req_rec.activity_code;
715   x_eam_res_rec.applied_resource_units := p_resource_req_rec.applied_num;
716   x_eam_res_rec.applied_resource_value := p_resource_req_rec.open_num;
717   x_eam_res_rec.assigned_units := ??
718   x_eam_res_rec.substitute_group_num := ??
719   x_eam_res_rec.replacement_group_num := ??
720   x_eam_res_rec.schedule_seq_num := ??
721   **/
722 
723   -- Set the DML Operation for the Record
724   IF ( p_resource_req_rec.operation_flag = 'C' ) THEN
725     x_eam_res_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_CREATE;
726   ELSIF ( p_resource_req_rec.operation_flag = 'U' ) THEN
727     x_eam_res_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_UPDATE;
728   ELSIF ( p_resource_req_rec.operation_flag = 'D' ) THEN
729     x_eam_res_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_DELETE;
730   END IF;
731 
732   x_eam_res_rec.return_status := NULL;
733 
734 END map_ahl_eam_res_rec;
735 
736 PROCEDURE map_ahl_eam_res_inst_rec
737 (
738   p_resource_assign_rec IN       AHL_PP_RESRC_ASSIGN_PVT.resrc_assign_rec_type,
739   x_eam_res_inst_rec  OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_inst_rec_type
740 )
741 AS
742 
743 BEGIN
744   -- Log Input Values
745   IF ( G_DEBUG = 'Y' ) THEN
746     AHL_DEBUG_PUB.debug( 'operation_flag : ' || p_resource_assign_rec.operation_flag );
747     AHL_DEBUG_PUB.debug( 'workorder_id: ' || TO_CHAR( p_resource_assign_rec.workorder_id ) );
748     AHL_DEBUG_PUB.debug( 'wip_entity_id: ' || TO_CHAR( p_resource_assign_rec.wip_entity_id ) );
749     AHL_DEBUG_PUB.debug( 'organization_id: ' || TO_CHAR( p_resource_assign_rec.organization_id ) );
750     AHL_DEBUG_PUB.debug( 'operation_seq_number: ' || TO_CHAR( p_resource_assign_rec.operation_seq_number) );
751     AHL_DEBUG_PUB.debug( 'resource_seq_number: ' || TO_CHAR( p_resource_assign_rec.resource_seq_number) );
752     AHL_DEBUG_PUB.debug( 'instance_id: ' || TO_CHAR( p_resource_assign_rec.instance_id) );
753     AHL_DEBUG_PUB.debug( 'serial_number: ' || p_resource_assign_rec.serial_number );
754     AHL_DEBUG_PUB.debug( 'assign_start_date: ' || TO_CHAR( p_resource_assign_rec.assign_start_date, 'DD-MON-YYYY hh24:mi') );
755     AHL_DEBUG_PUB.debug( 'assign_end_date: ' || TO_CHAR( p_resource_assign_rec.assign_end_date, 'DD-MON-YYYY hh24:mi') );
756   END IF;
757 
758   -- Populate EAM Record attributes from input table
759   x_eam_res_inst_rec.wip_entity_id := p_resource_assign_rec.wip_entity_id;
760   x_eam_res_inst_rec.organization_id := p_resource_assign_rec.organization_id;
761   x_eam_res_inst_rec.operation_seq_num := p_resource_assign_rec.operation_seq_number;
762   x_eam_res_inst_rec.resource_seq_num := p_resource_assign_rec.resource_seq_number;
763   x_eam_res_inst_rec.instance_id := p_resource_assign_rec.instance_id;
764   x_eam_res_inst_rec.serial_number := p_resource_assign_rec.serial_number;
765   x_eam_res_inst_rec.start_date := p_resource_assign_rec.assign_start_date;
766   x_eam_res_inst_rec.completion_date := p_resource_assign_rec.assign_end_date;
767 
768   -- Do not Pass
769   /**
770   x_eam_res_inst_rec.batch_id := ??;
771   **/
772 
773   -- Set the DML Operation for the Record
774   IF ( p_resource_assign_rec.operation_flag = 'C' ) THEN
775     x_eam_res_inst_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_CREATE;
776   ELSIF ( p_resource_assign_rec.operation_flag = 'U' ) THEN
777     x_eam_res_inst_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_UPDATE;
778   ELSIF ( p_resource_assign_rec.operation_flag = 'D' ) THEN
779     x_eam_res_inst_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_DELETE;
780   END IF;
781 
782   x_eam_res_inst_rec.return_status := NULL;
783 
784 END map_ahl_eam_res_inst_rec;
785 
786 PROCEDURE create_eam_workorder
787 (
788   p_api_version        IN   NUMBER     := 1.0,
789   p_init_msg_list      IN   VARCHAR2   := FND_API.G_TRUE,
790   p_commit             IN   VARCHAR2   := FND_API.G_FALSE,
791   p_validation_level   IN   NUMBER     := FND_API.G_VALID_LEVEL_FULL,
792   p_default            IN   VARCHAR2   := FND_API.G_FALSE,
793   p_module_type        IN   VARCHAR2   := NULL,
794   x_return_status      OUT  NOCOPY  VARCHAR2,
795   x_msg_count          OUT  NOCOPY  NUMBER,
796   x_msg_data           OUT  NOCOPY  VARCHAR2,
797   p_x_workorder_rec    IN OUT NOCOPY AHL_PRD_WORKORDER_PVT.prd_workorder_rec,
798   p_operation_tbl      IN   AHL_PRD_OPERATIONS_PVT.prd_operation_tbl,
799   p_material_req_tbl   IN   AHL_PP_MATERIALS_PVT.req_material_tbl_type,
800   p_resource_req_tbl   IN   AHL_PP_RESRC_REQUIRE_PVT.resrc_require_tbl_type
801 )
802 IS
803 
804 l_api_name                 VARCHAR2(30) := 'create_eam_workorder';
805 
806 -- Declare EAM API parameters
807 l_bo_identifier            VARCHAR2(10) := 'AHL';
808 l_init_msg_list            BOOLEAN := TRUE;
809 l_debug                    VARCHAR2(1)  := 'N';
810 l_output_dir               VARCHAR2(80);
811 l_debug_filename           VARCHAR2(80);
812 l_debug_file_mode          VARCHAR2(1);
813 l_return_status            VARCHAR2(1);
814 l_msg_count                NUMBER;
815 l_eam_wo_rec               EAM_PROCESS_WO_PUB.eam_wo_rec_type;
816 l_eam_op_tbl               EAM_PROCESS_WO_PUB.eam_op_tbl_type;
817 l_eam_op_network_tbl       EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
818 l_eam_res_tbl              EAM_PROCESS_WO_PUB.eam_res_tbl_type;
819 l_eam_res_inst_tbl         EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
820 l_eam_sub_res_tbl          EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
821 l_eam_res_usage_tbl        EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
822 l_eam_mat_req_tbl          EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
823 l_eam_direct_items_tbl     EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
824 l_out_eam_wo_rec           EAM_PROCESS_WO_PUB.eam_wo_rec_type;
825 l_out_eam_op_tbl           EAM_PROCESS_WO_PUB.eam_op_tbl_type;
826 l_out_eam_op_network_tbl   EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
827 l_out_eam_res_tbl          EAM_PROCESS_WO_PUB.eam_res_tbl_type;
828 l_out_eam_res_inst_tbl     EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
829 l_out_eam_sub_res_tbl      EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
830 l_out_eam_res_usage_tbl    EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
831 l_out_eam_mat_req_tbl      EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
832 l_out_eam_direct_items_tbl EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
833 
834 BEGIN
835 
836   -- Enable Debug
837   IF ( G_DEBUG = 'Y' ) THEN
838     AHL_DEBUG_PUB.enable_debug;
839   END IF;
840 
841   -- Initialize API return status to success
842   x_return_status := FND_API.G_RET_STS_SUCCESS;
843 
844   -- Standard Start of API savepoint
845   SAVEPOINT create_eam_workorder_PVT;
846 
847   IF ( G_DEBUG = 'Y' ) THEN
848     AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
849     AHL_DEBUG_PUB.debug( 'Job Header Record: ' );
850   END IF;
851 
852   -- Map all input AHL Job Header record attributes to the
853   -- corresponding EAM Job Header record attributes.
854   map_ahl_eam_wo_rec
855   (
856     p_workorder_rec    => p_x_workorder_rec,
857     x_eam_wo_rec       => l_eam_wo_rec
858   );
859 
860   IF ( G_DEBUG = 'Y' ) THEN
861     AHL_DEBUG_PUB.debug( 'Job Header Record Mapping Complete' );
862   END IF;
863 
864   -- Map all input AHL Operation record attributes to the
865   -- corresponding EAM Operation record attributes.
866   FOR i IN p_operation_tbl.FIRST..p_operation_tbl.LAST LOOP
867 
868     IF ( G_DEBUG = 'Y' ) THEN
869       AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
870       AHL_DEBUG_PUB.debug( 'Operation Record Number : ' || i );
871     END IF;
872 
873     map_ahl_eam_op_rec
874     (
875       p_operation_rec    => p_operation_tbl(i),
876       x_eam_op_rec       => l_eam_op_tbl(i)
877     );
878 
879   END LOOP;
880 
881   IF ( G_DEBUG = 'Y' ) THEN
882     AHL_DEBUG_PUB.debug( 'Operations Record Mapping Complete' );
883   END IF;
884 
885   -- Map all input AHL Material Requirement record attributes to the
886   -- corresponding EAM Material Requirement record attributes.
887   IF ( p_material_req_tbl.COUNT > 0 ) THEN
888     FOR i IN p_material_req_tbl.FIRST..p_material_req_tbl.LAST LOOP
889       IF ( G_DEBUG = 'Y' ) THEN
890         AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
891         AHL_DEBUG_PUB.debug( 'Material Requirement Record Number : ' || i );
892       END IF;
893 
894       map_ahl_eam_mat_rec
895       (
896         p_material_req_rec    => p_material_req_tbl(i),
897         x_eam_mat_req_rec     => l_eam_mat_req_tbl(i)
898       );
899 
900     END LOOP;
901 
902     IF ( G_DEBUG = 'Y' ) THEN
903       AHL_DEBUG_PUB.debug( 'Material Requirements Record Mapping Complete' );
904     END IF;
905 
906   END IF;
907 
908   -- Map all input AHL Resource Requirement record attributes to the
909   -- corresponding EAM Resource Requirement record attributes.
910   IF ( p_resource_req_tbl.COUNT > 0 ) THEN
911     FOR i IN p_resource_req_tbl.FIRST..p_resource_req_tbl.LAST LOOP
912 
913       IF ( G_DEBUG = 'Y' ) THEN
914         AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
915         AHL_DEBUG_PUB.debug( 'Resource Requirement Record Number : ' || i );
916       END IF;
917 
918       map_ahl_eam_res_rec
919       (
920         p_resource_req_rec    => p_resource_req_tbl(i),
921         x_eam_res_rec         => l_eam_res_tbl(i)
922       );
923 
924     END LOOP;
925 
926     IF ( G_DEBUG = 'Y' ) THEN
927       AHL_DEBUG_PUB.debug( 'Resource Requirement Record Mapping Complete' );
928     END IF;
929 
930   END IF;
931 
932   -- Set Debug Parameters for the EAM API
933   IF ( G_DEBUG = 'Y' ) THEN
934     set_eam_debug_params
935     (
936       x_debug           => l_debug,
937       x_output_dir      => l_output_dir,
938       x_debug_file_name => l_debug_filename,
939       x_debug_file_mode => l_debug_file_mode
940     );
941   END IF;
942 
943   IF ( G_DEBUG = 'Y' ) THEN
944     AHL_DEBUG_PUB.debug( 'Invoking EAM process_wo API' );
945   END IF;
946 
947   -- Invoke EAM BO API for Updating the Job
948   EAM_PROCESS_WO_PUB.process_wo
949   (
950     p_bo_identifier             => l_bo_identifier,
951     p_api_version_number        => 1.0,
952     p_init_msg_list             => l_init_msg_list,
953     p_commit                    => FND_API.G_FALSE,
954     p_eam_wo_rec                => l_eam_wo_rec,
955     p_eam_op_tbl                => l_eam_op_tbl,
956     p_eam_op_network_tbl        => l_eam_op_network_tbl,
957     p_eam_res_tbl               => l_eam_res_tbl,
958     p_eam_res_inst_tbl          => l_eam_res_inst_tbl,
959     p_eam_sub_res_tbl           => l_eam_sub_res_tbl,
960     p_eam_res_usage_tbl         => l_eam_res_usage_tbl,
961     p_eam_mat_req_tbl           => l_eam_mat_req_tbl,
962     p_eam_direct_items_tbl      => l_eam_direct_items_tbl,
963     x_eam_wo_rec                => l_out_eam_wo_rec,
964     x_eam_op_tbl                => l_out_eam_op_tbl,
965     x_eam_op_network_tbl        => l_out_eam_op_network_tbl,
966     x_eam_res_tbl               => l_out_eam_res_tbl,
967     x_eam_res_inst_tbl          => l_out_eam_res_inst_tbl,
968     x_eam_sub_res_tbl           => l_out_eam_sub_res_tbl,
969     x_eam_res_usage_tbl         => l_out_eam_res_usage_tbl,
970     x_eam_mat_req_tbl           => l_out_eam_mat_req_tbl,
971     x_eam_direct_items_tbl      => l_out_eam_direct_items_tbl,
972     x_return_status             => l_return_status,
973     x_msg_count                 => l_msg_count,
974     p_debug                     => l_debug,
975     p_output_dir                => l_output_dir,
976     p_debug_filename            => l_debug_filename,
977     p_debug_file_mode           => l_debug_file_mode
978   );
979 
980   IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
981     IF ( G_DEBUG = 'Y' ) THEN
982       AHL_DEBUG_PUB.debug( 'Error Count from EAM API : ' || l_msg_count );
983       AHL_DEBUG_PUB.debug( 'Error Count from Error Stack : ' || FND_MSG_PUB.count_msg );
984     END IF;
985 
986     RAISE FND_API.G_EXC_ERROR;
987   ELSE
988     IF ( G_DEBUG = 'Y' ) THEN
989       AHL_DEBUG_PUB.debug( 'EAM process_wo API Successful' );
990     END IF;
991 
992     p_x_workorder_rec.wip_entity_id := l_out_eam_wo_rec.wip_entity_id;
993 
994     IF ( G_DEBUG = 'Y' ) THEN
995       AHL_DEBUG_PUB.debug( 'New wip_entity_id:' || TO_CHAR( p_x_workorder_rec.wip_entity_id ) );
996     END IF;
997 
998     -- Perform the Commit (if requested)
999     IF FND_API.to_boolean( p_commit ) THEN
1000       COMMIT WORK;
1001     END IF;
1002   END IF;
1003 
1004   -- Disable debug (if enabled)
1005   IF ( G_DEBUG = 'Y' ) THEN
1006     AHL_DEBUG_PUB.disable_debug;
1007   END IF;
1008 
1009 EXCEPTION
1010 
1011   WHEN FND_API.G_EXC_ERROR THEN
1012     ROLLBACK TO create_eam_workorder_PVT;
1013     x_return_status := FND_API.G_RET_STS_ERROR;
1014     FND_MSG_PUB.count_and_get
1015     (
1016       p_encoded  => FND_API.G_FALSE,
1017       p_count    => x_msg_count,
1018       p_data     => x_msg_data
1019     );
1020 
1021     IF ( G_DEBUG = 'Y' ) THEN
1022       AHL_DEBUG_PUB.disable_debug;
1023     END IF;
1024 
1025   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1026     ROLLBACK TO create_eam_workorder_PVT;
1027     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1028     FND_MSG_PUB.count_and_get
1029     (
1030       p_encoded  => FND_API.G_FALSE,
1031       p_count    => x_msg_count,
1032       p_data     => x_msg_data
1033     );
1034 
1035     IF ( G_DEBUG = 'Y' ) THEN
1036       AHL_DEBUG_PUB.disable_debug;
1037     END IF;
1038 
1039   WHEN OTHERS THEN
1040     ROLLBACK TO create_eam_workorder_PVT;
1041     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1042     IF FND_MSG_PUB.check_msg_level( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )
1043     THEN
1044       FND_MSG_PUB.add_exc_msg
1045       (
1046         p_pkg_name         => G_PKG_NAME,
1047         p_procedure_name   => l_api_name,
1048         p_error_text       => SUBSTRB(SQLERRM,1,240)
1049       );
1050     END IF;
1051     FND_MSG_PUB.count_and_get
1052     (
1053       p_encoded  => FND_API.G_FALSE,
1054       p_count    => x_msg_count,
1055       p_data     => x_msg_data
1056     );
1057 
1058     IF ( G_DEBUG = 'Y' ) THEN
1059       AHL_DEBUG_PUB.disable_debug;
1060     END IF;
1061 END create_eam_workorder;
1062 
1063 PROCEDURE update_job_operations
1064 (
1065   p_api_version            IN   NUMBER     := 1.0,
1066   p_init_msg_list          IN   VARCHAR2   := FND_API.G_TRUE,
1067   p_commit                 IN   VARCHAR2   := FND_API.G_FALSE,
1068   p_validation_level       IN   NUMBER     := FND_API.G_VALID_LEVEL_FULL,
1069   p_default                IN   VARCHAR2   := FND_API.G_FALSE,
1070   p_module_type            IN   VARCHAR2   := NULL,
1071   x_return_status          OUT  NOCOPY  VARCHAR2,
1072   x_msg_count              OUT  NOCOPY  NUMBER,
1073   x_msg_data               OUT  NOCOPY  VARCHAR2,
1074   p_workorder_rec          IN   AHL_PRD_WORKORDER_PVT.prd_workorder_rec,
1075   p_operation_tbl          IN   AHL_PRD_OPERATIONS_PVT.prd_operation_tbl,
1076   p_material_req_tbl       IN   AHL_PP_MATERIALS_PVT.req_material_tbl_type,
1077   p_resource_req_tbl       IN   AHL_PP_RESRC_REQUIRE_PVT.resrc_require_tbl_type
1078 )
1079 IS
1080 
1081 l_api_name                 VARCHAR2(30) := 'update_job_operations';
1082 
1083 -- Declare EAM API parameters
1084 l_bo_identifier            VARCHAR2(10) := 'AHL';
1085 l_init_msg_list            BOOLEAN := TRUE;
1086 l_debug                    VARCHAR2(1)  := 'N';
1087 l_output_dir               VARCHAR2(80);
1088 l_debug_filename           VARCHAR2(80);
1089 l_debug_file_mode          VARCHAR2(1);
1090 l_return_status            VARCHAR2(1);
1091 l_msg_count                NUMBER;
1092 l_eam_wo_rec               EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1093 l_eam_op_tbl               EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1094 l_eam_op_network_tbl       EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1095 l_eam_res_tbl              EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1096 l_eam_res_inst_tbl         EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1097 l_eam_sub_res_tbl          EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1098 l_eam_res_usage_tbl        EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1099 l_eam_mat_req_tbl          EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1100 l_eam_direct_items_tbl     EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1101 l_out_eam_wo_rec           EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1102 l_out_eam_op_tbl           EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1103 l_out_eam_op_network_tbl   EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1104 l_out_eam_res_tbl          EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1105 l_out_eam_res_inst_tbl     EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1106 l_out_eam_sub_res_tbl      EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1107 l_out_eam_res_usage_tbl    EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1108 l_out_eam_mat_req_tbl      EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1109 l_out_eam_direct_items_tbl EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1110 
1111 BEGIN
1112 
1113   -- Enable Debug
1114   IF ( G_DEBUG = 'Y' ) THEN
1115     AHL_DEBUG_PUB.enable_debug;
1116   END IF;
1117 
1118   -- Initialize API return status to success
1119   x_return_status := FND_API.G_RET_STS_SUCCESS;
1120 
1121   -- Standard Start of API savepoint
1122   SAVEPOINT update_job_operations_PVT;
1123 
1124   -- Map all input AHL Job Header record attributes to the
1125   -- corresponding EAM Job Header record attributes.
1126   IF ( p_workorder_rec.workorder_id IS NOT NULL ) THEN
1127 
1128     IF ( G_DEBUG = 'Y' ) THEN
1129       AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
1130       AHL_DEBUG_PUB.debug( 'Job Header Record: ' );
1131     END IF;
1132 
1133     map_ahl_eam_wo_rec
1134     (
1135       p_workorder_rec    => p_workorder_rec,
1136       x_eam_wo_rec       => l_eam_wo_rec
1137     );
1138 
1139   END IF;
1140 
1141   -- Map all input AHL Operation record attributes to the
1142   -- corresponding EAM Operation record attributes.
1143   IF ( p_operation_tbl.COUNT > 0 ) THEN
1144     FOR i IN p_operation_tbl.FIRST..p_operation_tbl.LAST LOOP
1145 
1146       IF ( G_DEBUG = 'Y' ) THEN
1147         AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
1148         AHL_DEBUG_PUB.debug( 'Operation Record Number : ' || i );
1149       END IF;
1150 
1151       map_ahl_eam_op_rec
1152       (
1153         p_operation_rec    => p_operation_tbl(i),
1154         x_eam_op_rec       => l_eam_op_tbl(i)
1155       );
1156 
1157     END LOOP;
1158   END IF;
1159 
1160   -- Map all input AHL Material Requirement record attributes to the
1161   -- corresponding EAM Material Requirement record attributes.
1162   IF ( p_material_req_tbl.COUNT > 0 ) THEN
1163     FOR i IN p_material_req_tbl.FIRST..p_material_req_tbl.LAST LOOP
1164 
1165       IF ( G_DEBUG = 'Y' ) THEN
1166         AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
1167         AHL_DEBUG_PUB.debug( 'Material Requirement Record Number : ' || i );
1168       END IF;
1169 
1170       map_ahl_eam_mat_rec
1171       (
1172         p_material_req_rec    => p_material_req_tbl(i),
1173         x_eam_mat_req_rec     => l_eam_mat_req_tbl(i)
1174       );
1175 
1176     END LOOP;
1177   END IF;
1178 
1179   -- Map all input AHL Resource Requirement record attributes to the
1180   -- corresponding EAM Resource Requirement record attributes.
1181   IF ( p_resource_req_tbl.COUNT > 0 ) THEN
1182     FOR i IN p_resource_req_tbl.FIRST..p_resource_req_tbl.LAST LOOP
1183 
1184       IF ( G_DEBUG = 'Y' ) THEN
1185         AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
1186         AHL_DEBUG_PUB.debug( 'Resource Requirement Record Number : ' || i );
1187       END IF;
1188 
1189       map_ahl_eam_res_rec
1190       (
1191         p_resource_req_rec    => p_resource_req_tbl(i),
1192         x_eam_res_rec         => l_eam_res_tbl(i)
1193       );
1194 
1195     END LOOP;
1196   END IF;
1197 
1198   -- Set Debug Parameters for the EAM API
1199   IF ( G_DEBUG = 'Y' ) THEN
1200     set_eam_debug_params
1201     (
1202       x_debug           => l_debug,
1203       x_output_dir      => l_output_dir,
1204       x_debug_file_name => l_debug_filename,
1205       x_debug_file_mode => l_debug_file_mode
1206     );
1207   END IF;
1208 
1209   IF ( G_DEBUG = 'Y' ) THEN
1210     AHL_DEBUG_PUB.debug( 'Invoking EAM process_wo API' );
1211   END IF;
1212 
1213   -- Invoke EAM BO API for Updating the Job
1214   EAM_PROCESS_WO_PUB.process_wo
1215   (
1216     p_bo_identifier             => l_bo_identifier,
1217     p_api_version_number        => 1.0,
1218     p_init_msg_list             => l_init_msg_list,
1219     p_commit                    => FND_API.G_FALSE,
1220     p_eam_wo_rec                => l_eam_wo_rec,
1221     p_eam_op_tbl                => l_eam_op_tbl,
1222     p_eam_op_network_tbl        => l_eam_op_network_tbl,
1223     p_eam_res_tbl               => l_eam_res_tbl,
1224     p_eam_res_inst_tbl          => l_eam_res_inst_tbl,
1225     p_eam_sub_res_tbl           => l_eam_sub_res_tbl,
1226     p_eam_res_usage_tbl         => l_eam_res_usage_tbl,
1227     p_eam_mat_req_tbl           => l_eam_mat_req_tbl,
1228     p_eam_direct_items_tbl      => l_eam_direct_items_tbl,
1229     x_eam_wo_rec                => l_out_eam_wo_rec,
1230     x_eam_op_tbl                => l_out_eam_op_tbl,
1231     x_eam_op_network_tbl        => l_out_eam_op_network_tbl,
1232     x_eam_res_tbl               => l_out_eam_res_tbl,
1233     x_eam_res_inst_tbl          => l_out_eam_res_inst_tbl,
1234     x_eam_sub_res_tbl           => l_out_eam_sub_res_tbl,
1235     x_eam_res_usage_tbl         => l_out_eam_res_usage_tbl,
1236     x_eam_mat_req_tbl           => l_out_eam_mat_req_tbl,
1237     x_eam_direct_items_tbl      => l_out_eam_direct_items_tbl,
1238     x_return_status             => l_return_status,
1239     x_msg_count                 => l_msg_count,
1240     p_debug                     => l_debug,
1241     p_output_dir                => l_output_dir,
1242     p_debug_filename            => l_debug_filename,
1243     p_debug_file_mode           => l_debug_file_mode
1244   );
1245 
1246   IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
1247     IF ( G_DEBUG = 'Y' ) THEN
1248       AHL_DEBUG_PUB.debug( 'Error Count from EAM API : ' || l_msg_count );
1249       AHL_DEBUG_PUB.debug( 'Error Count from Error Stack : ' || FND_MSG_PUB.count_msg );
1250     END IF;
1251 
1252     RAISE FND_API.G_EXC_ERROR;
1253 
1254   ELSE
1255     -- Perform the Commit (if requested)
1256     IF FND_API.to_boolean( p_commit ) THEN
1257       COMMIT WORK;
1258     END IF;
1259   END IF;
1260 
1261   -- Disable debug (if enabled)
1262   IF ( G_DEBUG = 'Y' ) THEN
1263     AHL_DEBUG_PUB.disable_debug;
1264   END IF;
1265 
1266 EXCEPTION
1267 
1268   WHEN FND_API.G_EXC_ERROR THEN
1269     ROLLBACK TO update_job_operations_PVT;
1270     x_return_status := FND_API.G_RET_STS_ERROR;
1271     FND_MSG_PUB.count_and_get
1272     (
1273       p_encoded  => FND_API.G_FALSE,
1274       p_count    => x_msg_count,
1275       p_data     => x_msg_data
1276     );
1277 
1278     IF ( G_DEBUG = 'Y' ) THEN
1279       AHL_DEBUG_PUB.disable_debug;
1280     END IF;
1281 
1282   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1283     ROLLBACK TO update_job_operations_PVT;
1284     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1285     FND_MSG_PUB.count_and_get
1286     (
1287       p_encoded  => FND_API.G_FALSE,
1288       p_count    => x_msg_count,
1289       p_data     => x_msg_data
1290     );
1291 
1292     IF ( G_DEBUG = 'Y' ) THEN
1293       AHL_DEBUG_PUB.disable_debug;
1294     END IF;
1295 
1296   WHEN OTHERS THEN
1297     ROLLBACK TO update_job_operations_PVT;
1298     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1299     IF FND_MSG_PUB.check_msg_level( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )
1300     THEN
1301       FND_MSG_PUB.add_exc_msg
1302       (
1303         p_pkg_name         => G_PKG_NAME,
1304         p_procedure_name   => l_api_name,
1305         p_error_text       => SUBSTRB(SQLERRM,1,240)
1306       );
1307     END IF;
1308     FND_MSG_PUB.count_and_get
1309     (
1310       p_encoded  => FND_API.G_FALSE,
1311       p_count    => x_msg_count,
1312       p_data     => x_msg_data
1313     );
1314 
1315     IF ( G_DEBUG = 'Y' ) THEN
1316       AHL_DEBUG_PUB.disable_debug;
1317     END IF;
1318 
1319 END update_job_operations;
1320 
1321 PROCEDURE process_material_req
1322 (
1323   p_api_version            IN   NUMBER     := 1.0,
1324   p_init_msg_list          IN   VARCHAR2   := FND_API.G_TRUE,
1325   p_commit                 IN   VARCHAR2   := FND_API.G_FALSE,
1326   p_validation_level       IN   NUMBER     := FND_API.G_VALID_LEVEL_FULL,
1327   p_default                IN   VARCHAR2   := FND_API.G_FALSE,
1328   p_module_type            IN   VARCHAR2   := NULL,
1329   x_return_status          OUT  NOCOPY  VARCHAR2,
1330   x_msg_count              OUT  NOCOPY  NUMBER,
1331   x_msg_data               OUT  NOCOPY  VARCHAR2,
1332   p_material_req_tbl       IN   AHL_PP_MATERIALS_PVT.req_material_tbl_type
1333 )
1334 IS
1335 
1336 l_api_name                 VARCHAR2(30) := 'process_material_req';
1337 
1338 -- Declare EAM API parameters
1339 l_bo_identifier            VARCHAR2(10) := 'AHL';
1340 l_init_msg_list            BOOLEAN := TRUE;
1341 l_debug                    VARCHAR2(1)  := 'N';
1342 l_output_dir               VARCHAR2(80);
1343 l_debug_filename           VARCHAR2(80);
1344 l_debug_file_mode          VARCHAR2(1);
1345 l_return_status            VARCHAR2(1);
1346 l_msg_count                NUMBER;
1347 l_eam_wo_rec               EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1348 l_eam_op_tbl               EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1349 l_eam_op_network_tbl       EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1350 l_eam_res_tbl              EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1351 l_eam_res_inst_tbl         EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1352 l_eam_sub_res_tbl          EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1353 l_eam_res_usage_tbl        EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1354 l_eam_mat_req_tbl          EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1355 l_eam_direct_items_tbl     EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1356 l_out_eam_wo_rec           EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1357 l_out_eam_op_tbl           EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1358 l_out_eam_op_network_tbl   EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1359 l_out_eam_res_tbl          EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1360 l_out_eam_res_inst_tbl     EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1361 l_out_eam_sub_res_tbl      EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1362 l_out_eam_res_usage_tbl    EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1363 l_out_eam_mat_req_tbl      EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1364 l_out_eam_direct_items_tbl EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1365 
1366 BEGIN
1367 
1368   -- Enable Debug
1369   IF ( G_DEBUG = 'Y' ) THEN
1370     AHL_DEBUG_PUB.enable_debug;
1371   END IF;
1372 
1373   -- Initialize API return status to success
1374   x_return_status := FND_API.G_RET_STS_SUCCESS;
1375 
1376   -- Standard Start of API savepoint
1377   SAVEPOINT process_material_req_PVT;
1378 
1379   -- Map all input AHL Material Requirement record attributes to the
1380   -- corresponding EAM Material Requirement record attributes.
1381   FOR i IN p_material_req_tbl.FIRST..p_material_req_tbl.LAST LOOP
1382 
1383     IF ( G_DEBUG = 'Y' ) THEN
1384       AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
1385       AHL_DEBUG_PUB.debug( 'Material Requirement Record Number : ' || i );
1386     END IF;
1387 
1388     map_ahl_eam_mat_rec
1389     (
1390       p_material_req_rec    => p_material_req_tbl(i),
1391       x_eam_mat_req_rec     => l_eam_mat_req_tbl(i)
1392     );
1393 
1394   END LOOP;
1395 
1396   -- Set Debug Parameters for the EAM API
1397   IF ( G_DEBUG = 'Y' ) THEN
1398     set_eam_debug_params
1399     (
1400       x_debug           => l_debug,
1401       x_output_dir      => l_output_dir,
1402       x_debug_file_name => l_debug_filename,
1403       x_debug_file_mode => l_debug_file_mode
1404     );
1405   END IF;
1406 
1407   IF ( G_DEBUG = 'Y' ) THEN
1408     AHL_DEBUG_PUB.debug( 'Invoking EAM process_wo API' );
1409   END IF;
1410 
1411   -- Invoke EAM BO API for Updating the Job
1412   EAM_PROCESS_WO_PUB.process_wo
1413   (
1414     p_bo_identifier             => l_bo_identifier,
1415     p_api_version_number        => 1.0,
1416     p_init_msg_list             => l_init_msg_list,
1417     p_commit                    => FND_API.G_FALSE,
1418     p_eam_wo_rec                => l_eam_wo_rec,
1419     p_eam_op_tbl                => l_eam_op_tbl,
1420     p_eam_op_network_tbl        => l_eam_op_network_tbl,
1421     p_eam_res_tbl               => l_eam_res_tbl,
1422     p_eam_res_inst_tbl          => l_eam_res_inst_tbl,
1423     p_eam_sub_res_tbl           => l_eam_sub_res_tbl,
1424     p_eam_res_usage_tbl         => l_eam_res_usage_tbl,
1425     p_eam_mat_req_tbl           => l_eam_mat_req_tbl,
1426     p_eam_direct_items_tbl      => l_eam_direct_items_tbl,
1427     x_eam_wo_rec                => l_out_eam_wo_rec,
1428     x_eam_op_tbl                => l_out_eam_op_tbl,
1429     x_eam_op_network_tbl        => l_out_eam_op_network_tbl,
1430     x_eam_res_tbl               => l_out_eam_res_tbl,
1431     x_eam_res_inst_tbl          => l_out_eam_res_inst_tbl,
1432     x_eam_sub_res_tbl           => l_out_eam_sub_res_tbl,
1433     x_eam_res_usage_tbl         => l_out_eam_res_usage_tbl,
1434     x_eam_mat_req_tbl           => l_out_eam_mat_req_tbl,
1435     x_eam_direct_items_tbl      => l_out_eam_direct_items_tbl,
1436     x_return_status             => l_return_status,
1437     x_msg_count                 => l_msg_count,
1438     p_debug                     => l_debug,
1439     p_output_dir                => l_output_dir,
1440     p_debug_filename            => l_debug_filename,
1441     p_debug_file_mode           => l_debug_file_mode
1442   );
1443 
1444   IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
1445     IF ( G_DEBUG = 'Y' ) THEN
1446       AHL_DEBUG_PUB.debug( 'Error Count from EAM API : ' || l_msg_count );
1447       AHL_DEBUG_PUB.debug( 'Error Count from Error Stack : ' || FND_MSG_PUB.count_msg );
1448     END IF;
1449 
1450     RAISE FND_API.G_EXC_ERROR;
1451   END IF;
1452 
1453   -- Perform the Commit (if requested)
1454   IF FND_API.to_boolean( p_commit ) THEN
1455     COMMIT WORK;
1456   END IF;
1457 
1458   -- Disable debug (if enabled)
1459   IF ( G_DEBUG = 'Y' ) THEN
1460     AHL_DEBUG_PUB.disable_debug;
1461   END IF;
1462 
1463 EXCEPTION
1464 
1465   WHEN FND_API.G_EXC_ERROR THEN
1466     ROLLBACK TO process_material_req_PVT;
1467     x_return_status := FND_API.G_RET_STS_ERROR;
1468     FND_MSG_PUB.count_and_get
1469     (
1470       p_encoded  => FND_API.G_FALSE,
1471       p_count    => x_msg_count,
1472       p_data     => x_msg_data
1473     );
1474 
1475     IF ( G_DEBUG = 'Y' ) THEN
1476       AHL_DEBUG_PUB.disable_debug;
1477     END IF;
1478 
1479   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1480     ROLLBACK TO process_material_req_PVT;
1481     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1482     FND_MSG_PUB.count_and_get
1483     (
1484       p_encoded  => FND_API.G_FALSE,
1485       p_count    => x_msg_count,
1486       p_data     => x_msg_data
1487     );
1488 
1489     IF ( G_DEBUG = 'Y' ) THEN
1490       AHL_DEBUG_PUB.disable_debug;
1491     END IF;
1492 
1493   WHEN OTHERS THEN
1494     ROLLBACK TO process_material_req_PVT;
1495     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1496     IF FND_MSG_PUB.check_msg_level( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )
1497     THEN
1498       FND_MSG_PUB.add_exc_msg
1499       (
1500         p_pkg_name         => G_PKG_NAME,
1501         p_procedure_name   => l_api_name,
1502         p_error_text       => SUBSTRB(SQLERRM,1,240)
1503       );
1504     END IF;
1505     FND_MSG_PUB.count_and_get
1506     (
1507       p_encoded  => FND_API.G_FALSE,
1508       p_count    => x_msg_count,
1509       p_data     => x_msg_data
1510     );
1511 
1512     IF ( G_DEBUG = 'Y' ) THEN
1513       AHL_DEBUG_PUB.disable_debug;
1514     END IF;
1515 
1516 END process_material_req;
1517 
1518 PROCEDURE process_resource_req
1519 (
1520   p_api_version            IN   NUMBER     := 1.0,
1521   p_init_msg_list          IN   VARCHAR2   := FND_API.G_TRUE,
1522   p_commit                 IN   VARCHAR2   := FND_API.G_FALSE,
1523   p_validation_level       IN   NUMBER     := FND_API.G_VALID_LEVEL_FULL,
1524   p_default                IN   VARCHAR2   := FND_API.G_FALSE,
1525   p_module_type            IN   VARCHAR2   := NULL,
1526   x_return_status          OUT  NOCOPY  VARCHAR2,
1527   x_msg_count              OUT  NOCOPY  NUMBER,
1528   x_msg_data               OUT  NOCOPY  VARCHAR2,
1529   p_resource_req_tbl       IN   AHL_PP_RESRC_REQUIRE_PVT.resrc_require_tbl_type
1530 )
1531 IS
1532 --Fix for Bug 9388148
1533 CURSOR get_wo_details(p_wip_entity_id NUMBER)
1534 IS
1535 SELECT organization_id,scheduled_start_date,scheduled_completion_date,requested_start_date
1536 FROM wip_discrete_jobs
1537 WHERE wip_entity_id = p_wip_entity_id;
1538 
1539 l_wo_details		   get_wo_details%ROWTYPE;
1540 --End of changes for #9388148
1541 
1542 l_api_name                 VARCHAR2(30) := 'process_resource_req';
1543 
1544 -- Declare EAM API parameters
1545 l_bo_identifier            VARCHAR2(10) := 'AHL';
1546 l_init_msg_list            BOOLEAN := TRUE;
1547 l_debug                    VARCHAR2(1)  := 'N';
1548 l_output_dir               VARCHAR2(80);
1549 l_debug_filename           VARCHAR2(80);
1550 l_debug_file_mode          VARCHAR2(1);
1551 l_return_status            VARCHAR2(1);
1552 l_msg_count                NUMBER;
1553 l_eam_wo_rec               EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1554 l_eam_op_tbl               EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1555 l_eam_op_network_tbl       EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1556 l_eam_res_tbl              EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1557 l_eam_res_inst_tbl         EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1558 l_eam_sub_res_tbl          EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1559 l_eam_res_usage_tbl        EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1560 l_eam_mat_req_tbl          EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1561 l_eam_direct_items_tbl     EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1562 l_out_eam_wo_rec           EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1563 l_out_eam_op_tbl           EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1564 l_out_eam_op_network_tbl   EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1565 l_out_eam_res_tbl          EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1566 l_out_eam_res_inst_tbl     EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1567 l_out_eam_sub_res_tbl      EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1568 l_out_eam_res_usage_tbl    EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1569 l_out_eam_mat_req_tbl      EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1570 l_out_eam_direct_items_tbl EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1571 
1572 BEGIN
1573 
1574   -- Enable Debug
1575   IF ( G_DEBUG = 'Y' ) THEN
1576     AHL_DEBUG_PUB.enable_debug;
1577   END IF;
1578 
1579   -- Initialize API return status to success
1580   x_return_status := FND_API.G_RET_STS_SUCCESS;
1581 
1582   -- Standard Start of API savepoint
1583   SAVEPOINT process_resource_req_PVT;
1584 
1585   -- Map all input AHL Resource Requirement record attributes to the
1586   -- corresponding EAM Resource Requirement record attributes.
1587   FOR i IN p_resource_req_tbl.FIRST..p_resource_req_tbl.LAST LOOP
1588 
1589     IF ( G_DEBUG = 'Y' ) THEN
1590       AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
1591       AHL_DEBUG_PUB.debug( 'Resource Requirement Record Number : ' || i );
1592     END IF;
1593 
1594     map_ahl_eam_res_rec
1595     (
1596       p_resource_req_rec    => p_resource_req_tbl(i),
1597       x_eam_res_rec         => l_eam_res_tbl(i)
1598     );
1599 
1600   END LOOP;
1601 
1602   -- Set Debug Parameters for the EAM API
1603   IF ( G_DEBUG = 'Y' ) THEN
1604     set_eam_debug_params
1605     (
1606       x_debug           => l_debug,
1607       x_output_dir      => l_output_dir,
1608       x_debug_file_name => l_debug_filename,
1609       x_debug_file_mode => l_debug_file_mode
1610     );
1611   END IF;
1612 
1613   IF ( G_DEBUG = 'Y' ) THEN
1614     AHL_DEBUG_PUB.debug( 'Invoking EAM process_wo API' );
1615   END IF;
1616   --Changes for #9388148 --start
1617   --As per EAM Update, if requested start date is null then for adding the resource requirement, work order start date is changed to
1618   --Visit Master Work order start date.So we get an 'scheduling hierarchy...' error.Because the child work order expands beyond the parent
1619   --work order.To avoid this, requested start date should not be null. For this, we need to pass the work order record for update along with the
1620   --resource requirement table, during the EAM api call.
1621 
1622   IF (p_resource_req_tbl.COUNT >=1) THEN
1623 	  OPEN get_wo_details(p_resource_req_tbl(1).wip_entity_id);
1624 	  FETCH get_wo_details INTO l_wo_details;
1625 	  CLOSE get_wo_details;
1626 	  IF (l_wo_details.requested_start_date IS NULL) THEN
1627 		l_eam_wo_rec.wip_entity_id        := p_resource_req_tbl(1).wip_entity_id;
1628 		l_eam_wo_rec.organization_id      := l_wo_details.organization_id;
1629 		l_eam_wo_rec.transaction_type     := EAM_PROCESS_WO_PUB.G_OPR_UPDATE;
1630 		l_eam_wo_rec.requested_start_date := l_wo_details.scheduled_start_date;
1631 	  END IF;
1632   END IF;
1633 
1634   --Changes For 9388148 --end
1635   -- Invoke EAM BO API for Updating the Job
1636   EAM_PROCESS_WO_PUB.process_wo
1637   (
1638     p_bo_identifier             => l_bo_identifier,
1639     p_api_version_number        => 1.0,
1640     p_init_msg_list             => l_init_msg_list,
1641     p_commit                    => FND_API.G_FALSE,
1642     p_eam_wo_rec                => l_eam_wo_rec,
1643     p_eam_op_tbl                => l_eam_op_tbl,
1644     p_eam_op_network_tbl        => l_eam_op_network_tbl,
1645     p_eam_res_tbl               => l_eam_res_tbl,
1646     p_eam_res_inst_tbl          => l_eam_res_inst_tbl,
1647     p_eam_sub_res_tbl           => l_eam_sub_res_tbl,
1648     p_eam_res_usage_tbl         => l_eam_res_usage_tbl,
1649     p_eam_mat_req_tbl           => l_eam_mat_req_tbl,
1650     p_eam_direct_items_tbl      => l_eam_direct_items_tbl,
1651     x_eam_wo_rec                => l_out_eam_wo_rec,
1652     x_eam_op_tbl                => l_out_eam_op_tbl,
1653     x_eam_op_network_tbl        => l_out_eam_op_network_tbl,
1654     x_eam_res_tbl               => l_out_eam_res_tbl,
1655     x_eam_res_inst_tbl          => l_out_eam_res_inst_tbl,
1656     x_eam_sub_res_tbl           => l_out_eam_sub_res_tbl,
1657     x_eam_res_usage_tbl         => l_out_eam_res_usage_tbl,
1658     x_eam_mat_req_tbl           => l_out_eam_mat_req_tbl,
1659     x_eam_direct_items_tbl      => l_out_eam_direct_items_tbl,
1660     x_return_status             => l_return_status,
1661     x_msg_count                 => l_msg_count,
1662     p_debug                     => l_debug,
1663     p_output_dir                => l_output_dir,
1664     p_debug_filename            => l_debug_filename,
1665     p_debug_file_mode           => l_debug_file_mode
1666   );
1667 
1668   IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
1669     IF ( G_DEBUG = 'Y' ) THEN
1670       AHL_DEBUG_PUB.debug( 'Error Count from EAM API : ' || l_msg_count );
1671       AHL_DEBUG_PUB.debug( 'Error Count from Error Stack : ' || FND_MSG_PUB.count_msg );
1672     END IF;
1673 
1674     RAISE FND_API.G_EXC_ERROR;
1675   END IF;
1676 
1677   -- Perform the Commit (if requested)
1678   IF FND_API.to_boolean( p_commit ) THEN
1679     COMMIT WORK;
1680   END IF;
1681 
1682   -- Disable debug (if enabled)
1683   IF ( G_DEBUG = 'Y' ) THEN
1684     AHL_DEBUG_PUB.disable_debug;
1685   END IF;
1686 
1687 EXCEPTION
1688 
1689   WHEN FND_API.G_EXC_ERROR THEN
1690     ROLLBACK TO process_resource_req_PVT;
1691     x_return_status := FND_API.G_RET_STS_ERROR;
1692     FND_MSG_PUB.count_and_get
1693     (
1694       p_encoded  => FND_API.G_FALSE,
1695       p_count    => x_msg_count,
1696       p_data     => x_msg_data
1697     );
1698 
1699     IF ( G_DEBUG = 'Y' ) THEN
1700       AHL_DEBUG_PUB.disable_debug;
1701     END IF;
1702 
1703   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1704     ROLLBACK TO process_resource_req_PVT;
1705     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1706     FND_MSG_PUB.count_and_get
1707     (
1708       p_encoded  => FND_API.G_FALSE,
1709       p_count    => x_msg_count,
1710       p_data     => x_msg_data
1711     );
1712 
1713     IF ( G_DEBUG = 'Y' ) THEN
1714       AHL_DEBUG_PUB.disable_debug;
1715     END IF;
1716 
1717   WHEN OTHERS THEN
1718     ROLLBACK TO process_resource_req_PVT;
1719     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1720     IF FND_MSG_PUB.check_msg_level( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )
1721     THEN
1722       FND_MSG_PUB.add_exc_msg
1723       (
1724         p_pkg_name         => G_PKG_NAME,
1725         p_procedure_name   => l_api_name,
1726         p_error_text       => SUBSTRB(SQLERRM,1,240)
1727       );
1728     END IF;
1729     FND_MSG_PUB.count_and_get
1730     (
1731       p_encoded  => FND_API.G_FALSE,
1732       p_count    => x_msg_count,
1733       p_data     => x_msg_data
1734     );
1735 
1736     IF ( G_DEBUG = 'Y' ) THEN
1737       AHL_DEBUG_PUB.disable_debug;
1738     END IF;
1739 
1740 END process_resource_req;
1741 
1742 PROCEDURE process_resource_assign
1743 (
1744   p_api_version            IN   NUMBER     := 1.0,
1745   p_init_msg_list          IN   VARCHAR2   := FND_API.G_TRUE,
1746   p_commit                 IN   VARCHAR2   := FND_API.G_FALSE,
1747   p_validation_level       IN   NUMBER     := FND_API.G_VALID_LEVEL_FULL,
1748   p_default                IN   VARCHAR2   := FND_API.G_FALSE,
1749   p_module_type            IN   VARCHAR2   := NULL,
1750   x_return_status          OUT  NOCOPY  VARCHAR2,
1751   x_msg_count              OUT  NOCOPY  NUMBER,
1752   x_msg_data               OUT  NOCOPY  VARCHAR2,
1753   p_resource_assign_tbl    IN   AHL_PP_RESRC_ASSIGN_PVT.resrc_assign_tbl_type
1754 )
1755 IS
1756 
1757 l_api_name                 VARCHAR2(30) := 'process_resource_assign';
1758 
1759 -- Declare EAM API parameters
1760 l_bo_identifier            VARCHAR2(10) := 'AHL';
1761 l_init_msg_list            BOOLEAN := TRUE;
1762 l_debug                    VARCHAR2(1)  := 'N';
1763 l_output_dir               VARCHAR2(80);
1764 l_debug_filename           VARCHAR2(80);
1765 l_debug_file_mode          VARCHAR2(1);
1766 l_return_status            VARCHAR2(1);
1767 l_msg_count                NUMBER;
1768 l_eam_wo_rec               EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1769 l_eam_op_tbl               EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1770 l_eam_op_network_tbl       EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1771 l_eam_res_tbl              EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1772 l_eam_res_inst_tbl         EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1773 l_eam_sub_res_tbl          EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1774 l_eam_res_usage_tbl        EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1775 l_eam_mat_req_tbl          EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1776 l_eam_direct_items_tbl     EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1777 l_out_eam_wo_rec           EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1778 l_out_eam_op_tbl           EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1779 l_out_eam_op_network_tbl   EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1780 l_out_eam_res_tbl          EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1781 l_out_eam_res_inst_tbl     EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1782 l_out_eam_sub_res_tbl      EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1783 l_out_eam_res_usage_tbl    EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1784 l_out_eam_mat_req_tbl      EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1785 l_out_eam_direct_items_tbl EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1786 
1787 BEGIN
1788 
1789   -- Enable Debug
1790   IF ( G_DEBUG = 'Y' ) THEN
1791     AHL_DEBUG_PUB.enable_debug;
1792   END IF;
1793 
1794   -- Initialize API return status to success
1795   x_return_status := FND_API.G_RET_STS_SUCCESS;
1796 
1797   -- Standard Start of API savepoint
1798   SAVEPOINT process_resource_assign_PVT;
1799 
1800   -- Map all input AHL Material Requirement record attributes to the
1801   -- corresponding EAM Material Requirement record attributes.
1802   FOR i IN p_resource_assign_tbl.FIRST..p_resource_assign_tbl.LAST LOOP
1803 
1804     IF ( G_DEBUG = 'Y' ) THEN
1805       AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
1806       AHL_DEBUG_PUB.debug( 'Resource Assignment Record Number : ' || i );
1807     END IF;
1808 
1809     map_ahl_eam_res_inst_rec
1810     (
1811       p_resource_assign_rec    => p_resource_assign_tbl(i),
1812       x_eam_res_inst_rec       => l_eam_res_inst_tbl(i)
1813     );
1814 
1815   END LOOP;
1816 
1817   -- Set Debug Parameters for the EAM API
1818   IF ( G_DEBUG = 'Y' ) THEN
1819     set_eam_debug_params
1820     (
1821       x_debug           => l_debug,
1822       x_output_dir      => l_output_dir,
1823       x_debug_file_name => l_debug_filename,
1824       x_debug_file_mode => l_debug_file_mode
1825     );
1826   END IF;
1827 
1828   IF ( G_DEBUG = 'Y' ) THEN
1829     AHL_DEBUG_PUB.debug( 'Invoking EAM process_wo API' );
1830   END IF;
1831 
1832   -- Invoke EAM BO API for Updating the Job
1833   EAM_PROCESS_WO_PUB.process_wo
1834   (
1835     p_bo_identifier             => l_bo_identifier,
1836     p_api_version_number        => 1.0,
1837     p_init_msg_list             => l_init_msg_list,
1838     p_commit                    => FND_API.G_FALSE,
1839     p_eam_wo_rec                => l_eam_wo_rec,
1840     p_eam_op_tbl                => l_eam_op_tbl,
1841     p_eam_op_network_tbl        => l_eam_op_network_tbl,
1842     p_eam_res_tbl               => l_eam_res_tbl,
1843     p_eam_res_inst_tbl          => l_eam_res_inst_tbl,
1844     p_eam_sub_res_tbl           => l_eam_sub_res_tbl,
1845     p_eam_res_usage_tbl         => l_eam_res_usage_tbl,
1846     p_eam_mat_req_tbl           => l_eam_mat_req_tbl,
1847     p_eam_direct_items_tbl      => l_eam_direct_items_tbl,
1848     x_eam_wo_rec                => l_out_eam_wo_rec,
1849     x_eam_op_tbl                => l_out_eam_op_tbl,
1850     x_eam_op_network_tbl        => l_out_eam_op_network_tbl,
1851     x_eam_res_tbl               => l_out_eam_res_tbl,
1852     x_eam_res_inst_tbl          => l_out_eam_res_inst_tbl,
1853     x_eam_sub_res_tbl           => l_out_eam_sub_res_tbl,
1854     x_eam_res_usage_tbl         => l_out_eam_res_usage_tbl,
1855     x_eam_mat_req_tbl           => l_out_eam_mat_req_tbl,
1856     x_eam_direct_items_tbl      => l_out_eam_direct_items_tbl,
1857     x_return_status             => l_return_status,
1858     x_msg_count                 => l_msg_count,
1859     p_debug                     => l_debug,
1860     p_output_dir                => l_output_dir,
1861     p_debug_filename            => l_debug_filename,
1862     p_debug_file_mode           => l_debug_file_mode
1863   );
1864 
1865   IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
1866     IF ( G_DEBUG = 'Y' ) THEN
1867       AHL_DEBUG_PUB.debug( 'Error Count from EAM API : ' || l_msg_count );
1868       AHL_DEBUG_PUB.debug( 'Error Count from Error Stack : ' || FND_MSG_PUB.count_msg );
1869     END IF;
1870 
1871     RAISE FND_API.G_EXC_ERROR;
1872   END IF;
1873 
1874   -- Perform the Commit (if requested)
1875   IF FND_API.to_boolean( p_commit ) THEN
1876     COMMIT WORK;
1877   END IF;
1878 
1879   -- Disable debug (if enabled)
1880   IF ( G_DEBUG = 'Y' ) THEN
1881     AHL_DEBUG_PUB.disable_debug;
1882   END IF;
1883 
1884 EXCEPTION
1885 
1886   WHEN FND_API.G_EXC_ERROR THEN
1887     ROLLBACK TO process_resource_assign_PVT;
1888     x_return_status := FND_API.G_RET_STS_ERROR;
1889     FND_MSG_PUB.count_and_get
1890     (
1891       p_encoded  => FND_API.G_FALSE,
1892       p_count    => x_msg_count,
1893       p_data     => x_msg_data
1894     );
1895 
1896     IF ( G_DEBUG = 'Y' ) THEN
1897       AHL_DEBUG_PUB.disable_debug;
1898     END IF;
1899 
1900   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1901     ROLLBACK TO process_resource_assign_PVT;
1902     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1903     FND_MSG_PUB.count_and_get
1904     (
1905       p_encoded  => FND_API.G_FALSE,
1906       p_count    => x_msg_count,
1907       p_data     => x_msg_data
1908     );
1909 
1910     IF ( G_DEBUG = 'Y' ) THEN
1911       AHL_DEBUG_PUB.disable_debug;
1912     END IF;
1913 
1914   WHEN OTHERS THEN
1915     ROLLBACK TO process_resource_assign_PVT;
1916     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1917     IF FND_MSG_PUB.check_msg_level( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )
1918     THEN
1919       FND_MSG_PUB.add_exc_msg
1920       (
1921         p_pkg_name         => G_PKG_NAME,
1922         p_procedure_name   => l_api_name,
1923         p_error_text       => SUBSTRB(SQLERRM,1,240)
1924       );
1925     END IF;
1926     FND_MSG_PUB.count_and_get
1927     (
1928       p_encoded  => FND_API.G_FALSE,
1929       p_count    => x_msg_count,
1930       p_data     => x_msg_data
1931     );
1932 
1933     IF ( G_DEBUG = 'Y' ) THEN
1934       AHL_DEBUG_PUB.disable_debug;
1935     END IF;
1936 
1937 END process_resource_assign;
1938 
1939 PROCEDURE process_eam_workorders
1940 (
1941   p_api_version          IN   NUMBER     := 1.0,
1942   p_init_msg_list        IN   VARCHAR2   := FND_API.G_TRUE,
1943   p_commit               IN   VARCHAR2   := FND_API.G_FALSE,
1944   p_validation_level     IN   NUMBER     := FND_API.G_VALID_LEVEL_FULL,
1945   p_default              IN   VARCHAR2   := FND_API.G_FALSE,
1946   p_module_type          IN   VARCHAR2   := NULL,
1947   x_return_status        OUT  NOCOPY  VARCHAR2,
1948   x_msg_count            OUT  NOCOPY  NUMBER,
1949   x_msg_data             OUT  NOCOPY  VARCHAR2,
1950   p_x_eam_wo_tbl         IN OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_tbl_type,
1951   p_eam_wo_relations_tbl IN    EAM_PROCESS_WO_PUB.eam_wo_relations_tbl_type,
1952   p_eam_op_tbl           IN    EAM_PROCESS_WO_PUB.eam_op_tbl_type,
1953   p_eam_res_req_tbl      IN    EAM_PROCESS_WO_PUB.eam_res_tbl_type,
1954   p_eam_mat_req_tbl      IN    EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
1955 )
1956 IS
1957 
1958 l_api_name                 VARCHAR2(30) := 'process_eam_workorders';
1959 
1960 -- Declare EAM API parameters
1961 l_bo_identifier            VARCHAR2(10) := 'AHL';
1962 l_init_msg_list            BOOLEAN := TRUE;
1963 l_debug                    VARCHAR2(1)  := 'N';
1964 l_output_dir               VARCHAR2(80);
1965 l_debug_filename           VARCHAR2(80);
1966 l_debug_file_mode          VARCHAR2(1);
1967 l_return_status            VARCHAR2(1);
1968 l_msg_count                NUMBER;
1969 l_eam_op_network_tbl       EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1970 l_eam_res_inst_tbl         EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1971 l_eam_sub_res_tbl          EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1972 l_eam_direct_items_tbl     EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1973 l_out_eam_wo_tbl           EAM_PROCESS_WO_PUB.eam_wo_tbl_type;
1974 l_out_eam_wo_rel_tbl       EAM_PROCESS_WO_PUB.eam_wo_relations_tbl_type;
1975 l_out_eam_op_tbl           EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1976 l_out_eam_op_network_tbl   EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1977 l_out_eam_res_tbl          EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1978 l_out_eam_res_inst_tbl     EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1979 l_out_eam_sub_res_tbl      EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1980 l_out_eam_mat_req_tbl      EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1981 l_out_eam_direct_items_tbl EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1982 
1983 BEGIN
1984 
1985   -- Enable Debug
1986   IF ( G_DEBUG = 'Y' ) THEN
1987     AHL_DEBUG_PUB.enable_debug;
1988   END IF;
1989 
1990   -- Initialize API return status to success
1991   x_return_status := FND_API.G_RET_STS_SUCCESS;
1992 
1993   -- Standard Start of API savepoint
1994   SAVEPOINT process_eam_workorders_PVT;
1995 
1996   -- Set Debug Parameters for the EAM API
1997   IF ( G_DEBUG = 'Y' ) THEN
1998     set_eam_debug_params
1999     (
2000       x_debug           => l_debug,
2001       x_output_dir      => l_output_dir,
2002       x_debug_file_name => l_debug_filename,
2003       x_debug_file_mode => l_debug_file_mode
2004     );
2005   END IF;
2006 
2007   IF ( G_DEBUG = 'Y' ) THEN
2008     AHL_DEBUG_PUB.debug( 'Invoking EAM process_master_child_wo API' );
2009 
2010 				IF(p_x_eam_wo_tbl.COUNT > 0) THEN
2011     FOR i IN p_x_eam_wo_tbl.FIRST..p_x_eam_wo_tbl.LAST LOOP
2012       AHL_DEBUG_PUB.debug( 'Workorder('||i||') batch_id : '||p_x_eam_wo_tbl(i).batch_id );
2013       AHL_DEBUG_PUB.debug( 'Workorder('||i||') header_id : '||p_x_eam_wo_tbl(i).header_id );
2014     END LOOP;
2015 				END IF;
2016 
2017     IF ( p_eam_op_tbl.COUNT > 0 ) THEN
2018       FOR i IN p_eam_op_tbl.FIRST..p_eam_op_tbl.LAST LOOP
2019         AHL_DEBUG_PUB.debug( 'Operation('||i||') batch_id : '||p_eam_op_tbl(i).batch_id );
2020         AHL_DEBUG_PUB.debug( 'Operation('||i||') header_id : '||p_eam_op_tbl(i).header_id );
2021       END LOOP;
2022     END IF;
2023 
2024     IF ( p_eam_res_req_tbl.COUNT > 0 ) THEN
2025       FOR i IN p_eam_res_req_tbl.FIRST..p_eam_res_req_tbl.LAST LOOP
2026         AHL_DEBUG_PUB.debug( 'Resource('||i||') batch_id : '||p_eam_res_req_tbl(i).batch_id );
2027         AHL_DEBUG_PUB.debug( 'Resource('||i||') header_id : '||p_eam_res_req_tbl(i).header_id );
2028       END LOOP;
2029     END IF;
2030 
2031     IF ( p_eam_mat_req_tbl.COUNT > 0 ) THEN
2032       FOR i IN p_eam_mat_req_tbl.FIRST..p_eam_mat_req_tbl.LAST LOOP
2033         AHL_DEBUG_PUB.debug( 'Material('||i||') batch_id : '||p_eam_mat_req_tbl(i).batch_id );
2034         AHL_DEBUG_PUB.debug( 'Material('||i||') header_id : '||p_eam_mat_req_tbl(i).header_id );
2035       END LOOP;
2036     END IF;
2037 
2038   END IF;
2039 
2040   EAM_PROCESS_WO_PUB.process_master_child_wo
2041   (
2042    p_bo_identifier             => l_bo_identifier,
2043    p_api_version_number        => 1.0,
2044    p_init_msg_list             => l_init_msg_list,
2045    p_eam_wo_relations_tbl      => p_eam_wo_relations_tbl,
2046    p_eam_wo_tbl                => p_x_eam_wo_tbl,
2047    p_eam_op_tbl                => p_eam_op_tbl,
2048    p_eam_op_network_tbl        => l_eam_op_network_tbl,
2049    p_eam_res_tbl               => p_eam_res_req_tbl,
2050    p_eam_res_inst_tbl          => l_eam_res_inst_tbl,
2051    p_eam_sub_res_tbl           => l_eam_sub_res_tbl,
2052    p_eam_mat_req_tbl           => p_eam_mat_req_tbl,
2053    p_eam_direct_items_tbl      => l_eam_direct_items_tbl,
2054    x_eam_wo_tbl                => l_out_eam_wo_tbl,
2055    x_eam_wo_relations_tbl      => l_out_eam_wo_rel_tbl,
2056    x_eam_op_tbl                => l_out_eam_op_tbl,
2057    x_eam_op_network_tbl        => l_out_eam_op_network_tbl,
2058    x_eam_res_tbl               => l_out_eam_res_tbl,
2059    x_eam_res_inst_tbl          => l_out_eam_res_inst_tbl,
2060    x_eam_sub_res_tbl           => l_out_eam_sub_res_tbl,
2061    x_eam_mat_req_tbl           => l_out_eam_mat_req_tbl,
2062    x_eam_direct_items_tbl      => l_out_eam_direct_items_tbl,
2063    x_return_status             => l_return_status,
2064    x_msg_count                 => l_msg_count,
2065    p_commit                    => FND_API.G_FALSE,
2066    p_debug                     => l_debug,
2067    p_output_dir                => l_output_dir,
2068    p_debug_filename            => l_debug_filename,
2069    p_debug_file_mode           => l_debug_file_mode
2070   );
2071 
2072   IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
2073     IF ( G_DEBUG = 'Y' ) THEN
2074       AHL_DEBUG_PUB.debug( 'Error Count from EAM API : ' || l_msg_count );
2075       AHL_DEBUG_PUB.debug( 'Error Count from Error Stack : ' || FND_MSG_PUB.count_msg );
2076     END IF;
2077 
2078     RAISE FND_API.G_EXC_ERROR;
2079 
2080   ELSE
2081     --Change made on Nov 17, 2005 by jeli due to bug 4742895.
2082     --Ignore messages in stack if return status is S after calls to EAM APIs.
2083     FND_MSG_PUB.initialize;
2084 
2085     IF ( G_DEBUG = 'Y' ) THEN
2086       AHL_DEBUG_PUB.debug( 'EAM process_master_child_wo API Successful' );
2087       AHL_DEBUG_PUB.debug( 'Input Workorder Table count : ' || p_x_eam_wo_tbl.COUNT );
2088       AHL_DEBUG_PUB.debug( 'Output Workorder Table count : ' || l_out_eam_wo_tbl.COUNT );
2089     END IF;
2090 
2091     FOR i IN 1..l_out_eam_wo_tbl.COUNT LOOP
2092       IF ( l_out_eam_wo_tbl(i).wip_entity_id IS NULL ) THEN
2093         FND_MESSAGE.set_name('AHL','AHL_PRD_CREATE_WIP_JOB_FAILED');
2094         FND_MESSAGE.set_token('HEADER', l_out_eam_wo_tbl(i).header_id );
2095         FND_MSG_PUB.add;
2096 
2097         IF ( G_DEBUG = 'Y' ) THEN
2098           AHL_DEBUG_PUB.debug( 'No wip_entity_id generated for header_id:' || l_out_eam_wo_tbl(i).header_id );
2099         END IF;
2100       ELSE
2101 
2102         IF ( G_DEBUG = 'Y' ) THEN
2103           AHL_DEBUG_PUB.debug( 'wip_entity_id(' || i || '):' || TO_CHAR( l_out_eam_wo_tbl(i).wip_entity_id ) );
2104         END IF;
2105 
2106         p_x_eam_wo_tbl(i).wip_entity_id := l_out_eam_wo_tbl(i).wip_entity_id;
2107 
2108       END IF;
2109     END LOOP;
2110 
2111     l_msg_count := FND_MSG_PUB.count_msg;
2112     IF l_msg_count > 0 THEN
2113       RAISE FND_API.G_EXC_ERROR;
2114     END IF;
2115 
2116     -- Perform the Commit (if requested)
2117     IF FND_API.to_boolean( p_commit ) THEN
2118       COMMIT WORK;
2119     END IF;
2120   END IF;
2121 
2122   -- Disable debug (if enabled)
2123   IF ( G_DEBUG = 'Y' ) THEN
2124     AHL_DEBUG_PUB.disable_debug;
2125   END IF;
2126 
2127 EXCEPTION
2128 
2129   WHEN FND_API.G_EXC_ERROR THEN
2130     ROLLBACK TO process_eam_workorders_PVT;
2131     x_return_status := FND_API.G_RET_STS_ERROR;
2132     FND_MSG_PUB.count_and_get
2133     (
2134       p_encoded  => FND_API.G_FALSE,
2135       p_count    => x_msg_count,
2136       p_data     => x_msg_data
2137     );
2138 
2139     IF ( G_DEBUG = 'Y' ) THEN
2140       AHL_DEBUG_PUB.disable_debug;
2141     END IF;
2142 
2143   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2144     ROLLBACK TO process_eam_workorders_PVT;
2145     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2146     FND_MSG_PUB.count_and_get
2147     (
2148       p_encoded  => FND_API.G_FALSE,
2149       p_count    => x_msg_count,
2150       p_data     => x_msg_data
2151     );
2152 
2153     IF ( G_DEBUG = 'Y' ) THEN
2154       AHL_DEBUG_PUB.disable_debug;
2155     END IF;
2156 
2157   WHEN OTHERS THEN
2158     ROLLBACK TO process_eam_workorders_PVT;
2159     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2160     IF FND_MSG_PUB.check_msg_level( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )
2161     THEN
2162       FND_MSG_PUB.add_exc_msg
2163       (
2164         p_pkg_name         => G_PKG_NAME,
2165         p_procedure_name   => l_api_name,
2166         p_error_text       => SUBSTRB(SQLERRM,1,240)
2167       );
2168     END IF;
2169     FND_MSG_PUB.count_and_get
2170     (
2171       p_encoded  => FND_API.G_FALSE,
2172       p_count    => x_msg_count,
2173       p_data     => x_msg_data
2174     );
2175 
2176     IF ( G_DEBUG = 'Y' ) THEN
2177       AHL_DEBUG_PUB.disable_debug;
2178     END IF;
2179 END process_eam_workorders;
2180 
2181 --pekambar added new procedure for ER # 9410221 -- start
2182 PROCEDURE move_workorder
2183 (
2184   p_api_version                       IN   NUMBER     := 1.0,
2185   p_init_msg_list                     IN   VARCHAR2   := FND_API.G_TRUE,
2186   p_commit                             IN   VARCHAR2   := FND_API.G_FALSE,
2187   p_validation_level                 IN   NUMBER     := FND_API.G_VALID_LEVEL_FULL,
2188   p_default                             IN   VARCHAR2   := FND_API.G_FALSE,
2189   p_module_type                     IN   VARCHAR2   := NULL,
2190   x_return_status                    OUT  NOCOPY  VARCHAR2,
2191   x_msg_count			    OUT  NOCOPY  NUMBER,
2192   x_msg_data			    OUT  NOCOPY  VARCHAR2,
2193   p_wip_entity_id                  IN      NUMBER,
2194   p_work_object_type_id          IN      NUMBER,
2195   p_offset_days                      IN      NUMBER,	-- 1 Day Default
2196   p_offset_direction                 IN      NUMBER,	-- Forward
2197   p_scheduled_start_date                        IN      DATE  ,		--p_x_scheduled_start_date,
2198   p_scheduled_end_date               IN      DATE  ,		--l_scheduled_end_date,
2199   p_schedule_method              IN      NUMBER  ,
2200   p_ignore_firm_flag		   IN	    VARCHAR2
2201 )
2202 IS
2203 
2204 l_api_name                       VARCHAR2(30) := 'move_workorder';
2205 l_work_object_id                  NUMBER;
2206 l_work_object_type_id        NUMBER;
2207 l_offset_days                     NUMBER;
2208 l_offset_direction               NUMBER;
2209 l_start_date                      DATE;
2210 l_completion_date              DATE;
2211 l_schedule_method             NUMBER;
2212 l_ignore_firm_flag	       VARCHAR2(1);
2213 l_return_status            VARCHAR2(1);
2214 l_msg_count                NUMBER;
2215 l_msg_data           VARCHAR2(240);
2216 
2217 BEGIN
2218 
2219   -- Enable Debug
2220   IF ( G_DEBUG = 'Y' ) THEN
2221     AHL_DEBUG_PUB.enable_debug;
2222   END IF;
2223 
2224   -- Initialize API return status to success
2225   x_return_status := FND_API.G_RET_STS_SUCCESS;
2226 
2227   -- Standard Start of API savepoint
2228   SAVEPOINT move_workorder_PVT;
2229 
2230 
2231     IF ( G_DEBUG = 'Y' ) THEN
2232       AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
2233       AHL_DEBUG_PUB.debug('Before call to EAM_WO_NETWORK_UTIL_PVT.Move_WO: ');
2234       AHL_DEBUG_PUB.debug('WIP Enitity ID : p_work_object_id' || p_wip_entity_id);
2235       AHL_DEBUG_PUB.debug('p_scheduled_start_date   ' || p_scheduled_start_date);
2236       AHL_DEBUG_PUB.debug('p_scheduled_end_date  ' || p_scheduled_end_date);
2237     END IF;
2238 
2239     -- Mapping attriburtes for EAM
2240 
2241 	l_work_object_id                  := p_wip_entity_id;
2242 	l_work_object_type_id          := p_work_object_type_id ;
2243 	l_offset_days                      := p_offset_days;
2244 	l_offset_direction                 := p_offset_direction;
2245 	l_start_date                        := p_scheduled_start_date;
2246 	l_completion_date               := p_scheduled_end_date;
2247 	l_schedule_method              := p_schedule_method;
2248 	l_ignore_firm_flag	         := p_ignore_firm_flag;
2249 
2250    EAM_WO_NETWORK_UTIL_PVT.Move_WO
2251         (
2252         p_api_version                => p_api_version,
2253         p_init_msg_list              => p_init_msg_list,
2254         p_commit                      => p_commit,
2255         p_validation_level          => p_validation_level,
2256         p_work_object_id           =>  l_work_object_id,
2257         p_work_object_type_id   => l_work_object_type_id,
2258         p_offset_days               => l_offset_days,  -- 1 Day Default
2259         p_offset_direction          => l_offset_direction, -- Forward
2260         p_start_date                 => l_start_date,
2261         p_completion_date        => l_completion_date,
2262         p_schedule_method       => l_schedule_method,
2263 	p_ignore_firm_flag	  => l_ignore_firm_flag,
2264         x_return_status            => l_return_status,
2265         x_msg_count                => l_msg_count,
2266         x_msg_data                 => l_msg_data
2267    );
2268 
2269     IF ( G_DEBUG = 'Y' ) THEN
2270       AHL_DEBUG_PUB.debug('After call to EAM_WO_NETWORK_UTIL_PVT.Move_WO: ');
2271     END IF;
2272 
2273   IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
2274     IF ( G_DEBUG = 'Y' ) THEN
2275       AHL_DEBUG_PUB.debug( 'Error Count from EAM API : ' || l_msg_count );
2276       AHL_DEBUG_PUB.debug( 'Error Count from Error Stack : ' || FND_MSG_PUB.count_msg );
2277     END IF;
2278 
2279     RAISE FND_API.G_EXC_ERROR;
2280 
2281   ELSE
2282     -- Perform the Commit (if requested)
2283     IF FND_API.to_boolean( p_commit ) THEN
2284       COMMIT WORK;
2285     END IF;
2286   END IF;
2287 
2288   -- Disable debug (if enabled)
2289   IF ( G_DEBUG = 'Y' ) THEN
2290     AHL_DEBUG_PUB.disable_debug;
2291   END IF;
2292 
2293 EXCEPTION
2294 
2295   WHEN FND_API.G_EXC_ERROR THEN
2296     ROLLBACK TO move_workorder_PVT;
2297     x_return_status := FND_API.G_RET_STS_ERROR;
2298     FND_MSG_PUB.count_and_get
2299     (
2300       p_encoded  => FND_API.G_FALSE,
2301       p_count    => x_msg_count,
2302       p_data     => x_msg_data
2303     );
2304 
2305     IF ( G_DEBUG = 'Y' ) THEN
2306       AHL_DEBUG_PUB.disable_debug;
2307     END IF;
2308 
2309   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2310     ROLLBACK TO move_workorder_PVT;
2311     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2312     FND_MSG_PUB.count_and_get
2313     (
2314       p_encoded  => FND_API.G_FALSE,
2315       p_count    => x_msg_count,
2316       p_data     => x_msg_data
2317     );
2318 
2319     IF ( G_DEBUG = 'Y' ) THEN
2320       AHL_DEBUG_PUB.disable_debug;
2321     END IF;
2322 
2323   WHEN OTHERS THEN
2324     ROLLBACK TO move_workorder_PVT;
2325     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2326     IF FND_MSG_PUB.check_msg_level( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )
2327     THEN
2328       FND_MSG_PUB.add_exc_msg
2329       (
2330         p_pkg_name         => G_PKG_NAME,
2331         p_procedure_name   => l_api_name,
2332         p_error_text       => SUBSTRB(SQLERRM,1,240)
2333       );
2334     END IF;
2335     FND_MSG_PUB.count_and_get
2336     (
2337       p_encoded  => FND_API.G_FALSE,
2338       p_count    => x_msg_count,
2339       p_data     => x_msg_data
2340     );
2341 
2342     IF ( G_DEBUG = 'Y' ) THEN
2343       AHL_DEBUG_PUB.disable_debug;
2344     END IF;
2345 
2346 END move_workorder;
2347 
2348 --pekambar added new procedure for ER # 9410221 -- End
2349 
2350 
2351 
2352 END AHL_EAM_JOB_PVT;