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.3.12010000.3 2008/12/28 00:22:24 sracha 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.source_code := ??;
414   x_eam_wo_rec.material_issue_by_mo := ??;
415   x_eam_wo_rec.user_id := ??;
416   x_eam_wo_rec.responsibility_id := ??;
417   x_eam_wo_rec.date_released := ??;
418   **/
419 
420   -- Set the DML Operation for the Job Header Record
421   IF ( p_workorder_rec.dml_operation = 'C' ) THEN
422     x_eam_wo_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_CREATE;
423   ELSIF ( p_workorder_rec.dml_operation = 'U' ) THEN
424     x_eam_wo_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_UPDATE;
425     --Srini
426 	OPEN Get_Job_Dates_Cur(x_eam_wo_rec.wip_entity_id);
427 	FETCH Get_Job_Dates_Cur INTO Get_Job_Dates_Rec;
428 	CLOSE Get_Job_Dates_Cur;
429 	-- we need to pass the requested start date for forward scheduling
430 
431         -- If the scheduled start date is changed, then pass requested start date
432         -- If the scheduled end date is changed, then pass due date
433         -- If both are changed then pass requested_start_date because if
434         -- both due date and requested start date are passed then EAM throws an error
435         IF (Get_Job_Dates_Rec.Scheduled_start_Date <> x_eam_wo_rec.scheduled_start_date) THEN
436            x_eam_wo_rec.requested_start_date  := x_eam_wo_rec.scheduled_start_date;
437         ELSIF (Get_Job_Dates_Rec.Scheduled_completion_Date <> x_eam_wo_rec.scheduled_completion_date) THEN
438            x_eam_wo_rec.due_date := x_eam_wo_rec.scheduled_completion_date;
439            --Due date should be passed for backward scheduling
440         END IF;
441 
442 	/*IF (Get_Job_Dates_Rec.Scheduled_completion_Date <> x_eam_wo_rec.scheduled_completion_date
443 	  AND  Get_Job_Dates_Rec.Scheduled_completion_Date < x_eam_wo_rec.scheduled_completion_date )
444 	  THEN
445 	   x_eam_wo_rec.requested_start_date  := x_eam_wo_rec.scheduled_completion_date;
446 	   --Due date should be passsed for backward scheduling
447 	 ELSIF  (Get_Job_Dates_Rec.Scheduled_completion_Date <> x_eam_wo_rec.scheduled_completion_date
451 	END IF;
448 	  AND  Get_Job_Dates_Rec.Scheduled_completion_Date > x_eam_wo_rec.scheduled_completion_date )
449 	  THEN
450 	   x_eam_wo_rec.due_date  := x_eam_wo_rec.scheduled_completion_date;
452         */
453   END IF;
454   -- rroy
455 		-- workorder backdating fix
456 		-- set the date_released parameter
457 		-- of the eam workorder record to
458 		-- min(scheduled_start_date, sysdate)
459 		-- if the new status code is 3(Released) or 6 (On Hold)
460 		-- This is being done for statuses 3 and 6 because
461 		-- the EAM code updates the p_release_date parameter
462 		-- for the above statuses in the call to WIP_CHANGE_STATUS.Release
463 		--
464                 /*IF p_workorder_rec.status_code IN ('3', '6') THEN
465 		  x_eam_wo_rec.date_released := least(Get_Job_Dates_Rec.date_released, p_workorder_rec.scheduled_start_date, sysdate);
466 		END IF;
467 		*/
468 
469 
470   IF ( G_DEBUG = 'Y' ) THEN
471 
472     AHL_DEBUG_PUB.debug( 'Requested Start Date: ' || TO_CHAR( x_eam_wo_rec.requested_start_date, 'DD-MON-YYYY hh24:mi') );
473     AHL_DEBUG_PUB.debug( 'Due Date: ' || TO_CHAR( x_eam_wo_rec.due_date, 'DD-MON-YYYY hh24:mi') );
474   END IF;
475 
476   x_eam_wo_rec.return_status := NULL;
477 
478 END map_ahl_eam_wo_rec;
479 --
480 
481 PROCEDURE map_ahl_eam_wo_rel_rec
482 (
483   p_workorder_rel_rec    IN         AHL_PRD_WORKORDER_PVT.prd_workorder_rel_rec,
484   x_eam_wo_relations_rec OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_relations_rec_type
485 )
486 AS
487 
488 BEGIN
489 
490   -- Log Input Values
491   IF ( G_DEBUG = 'Y' ) THEN
492     AHL_DEBUG_PUB.debug( 'dml_operation: ' || p_workorder_rel_rec.dml_operation );
493     AHL_DEBUG_PUB.debug( 'batch_id: ' || TO_CHAR( p_workorder_rel_rec.batch_id ) );
494     AHL_DEBUG_PUB.debug( 'wo_relationship_id: ' || TO_CHAR( p_workorder_rel_rec.wo_relationship_id ) );
495     AHL_DEBUG_PUB.debug( 'parent_header_id: ' || TO_CHAR( p_workorder_rel_rec.parent_header_id ) );
496     AHL_DEBUG_PUB.debug( 'parent_wip_entity_id: ' || TO_CHAR( p_workorder_rel_rec.parent_wip_entity_id ) );
497     AHL_DEBUG_PUB.debug( 'child_header_id: ' || TO_CHAR( p_workorder_rel_rec.child_header_id ) );
498     AHL_DEBUG_PUB.debug( 'child_wip_entity_id: ' || TO_CHAR( p_workorder_rel_rec.child_wip_entity_id ) );
499     AHL_DEBUG_PUB.debug( 'relationship_type: ' || TO_CHAR( p_workorder_rel_rec.relationship_type ) );
500   END IF;
501 
502   -- Populate EAM Record attributes from input record
503   x_eam_wo_relations_rec.batch_id := p_workorder_rel_rec.batch_id;
504   x_eam_wo_relations_rec.wo_relationship_id := p_workorder_rel_rec.wo_relationship_id;
505   x_eam_wo_relations_rec.parent_header_id := p_workorder_rel_rec.parent_header_id;
506   x_eam_wo_relations_rec.parent_object_type_id := 1;
507   x_eam_wo_relations_rec.parent_object_id := p_workorder_rel_rec.parent_wip_entity_id;
508   x_eam_wo_relations_rec.child_header_id := p_workorder_rel_rec.child_header_id;
509   x_eam_wo_relations_rec.child_object_type_id := 1;
510   x_eam_wo_relations_rec.child_object_id := p_workorder_rel_rec.child_wip_entity_id;
511   x_eam_wo_relations_rec.parent_relationship_type := p_workorder_rel_rec.relationship_type;
512   x_eam_wo_relations_rec.relationship_status := 0;
513 
514   -- Set the DML Operation for the Job Header Record
515   IF ( p_workorder_rel_rec.dml_operation = 'C' ) THEN
516     x_eam_wo_relations_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_CREATE;
517   ELSIF ( p_workorder_rel_rec.dml_operation = 'D' ) THEN
518     x_eam_wo_relations_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_DELETE;
519   END IF;
520 
521   x_eam_wo_relations_rec.return_status := NULL;
522 
523 END map_ahl_eam_wo_rel_rec;
524 
525 PROCEDURE map_ahl_eam_op_rec
526 (
527   p_operation_rec  IN         AHL_PRD_OPERATIONS_PVT.prd_workoperation_rec,
528   x_eam_op_rec     OUT NOCOPY EAM_PROCESS_WO_PUB.eam_op_rec_type
529 )
530 AS
531 
532 BEGIN
533 
534   -- Log Input Values
535   IF ( G_DEBUG = 'Y' ) THEN
536     AHL_DEBUG_PUB.debug( 'dml_operation: ' || p_operation_rec.dml_operation );
537     AHL_DEBUG_PUB.debug( 'workorder_id: ' || TO_CHAR( p_operation_rec.workorder_id ) );
538     AHL_DEBUG_PUB.debug( 'wip_entity_id: ' || TO_CHAR( p_operation_rec.wip_entity_id ) );
539     AHL_DEBUG_PUB.debug( 'organization_id: ' || TO_CHAR( p_operation_rec.organization_id ) );
540     AHL_DEBUG_PUB.debug( 'operation_sequence_num: ' || TO_CHAR( p_operation_rec.operation_sequence_num) );
541     AHL_DEBUG_PUB.debug( 'department_id: ' || TO_CHAR( p_operation_rec.department_id) );
542     AHL_DEBUG_PUB.debug( 'operation_description: ' || p_operation_rec.operation_description );
543     AHL_DEBUG_PUB.debug( 'minimum_transfer_quantity: ' || TO_CHAR( p_operation_rec.minimum_transfer_quantity) );
544     AHL_DEBUG_PUB.debug( 'count_point_type: ' || TO_CHAR( p_operation_rec.count_point_type) );
545     AHL_DEBUG_PUB.debug( 'scheduled_start_date: ' || TO_CHAR( p_operation_rec.scheduled_start_date, 'DD-MON-YYYY hh24:mi') );
546     AHL_DEBUG_PUB.debug( 'scheduled_end_date: ' || TO_CHAR( p_operation_rec.scheduled_end_date, 'DD-MON-YYYY hh24:mi') );
547   END IF;
548 
549   -- Populate EAM Record attributes from input table
550   x_eam_op_rec.wip_entity_id := p_operation_rec.wip_entity_id;
551   x_eam_op_rec.organization_id := p_operation_rec.organization_id;
552   x_eam_op_rec.operation_seq_num := p_operation_rec.operation_sequence_num;
553   x_eam_op_rec.department_id := p_operation_rec.department_id;
554   x_eam_op_rec.long_description := p_operation_rec.operation_description;
555   x_eam_op_rec.description := SUBSTR(RTRIM(p_operation_rec.operation_description),1,240);
556 
560     x_eam_op_rec.minimum_transfer_quantity := p_operation_rec.minimum_transfer_quantity;
557   IF ( p_operation_rec.dml_operation = 'C' ) THEN
558     x_eam_op_rec.minimum_transfer_quantity := 1;
559   ELSIF ( p_operation_rec.dml_operation = 'U' ) THEN
561   END IF;
562 
563   IF ( p_operation_rec.dml_operation = 'C' ) THEN
564     x_eam_op_rec.count_point_type := 2;
565   ELSIF ( p_operation_rec.dml_operation = 'U' ) THEN
566     x_eam_op_rec.count_point_type := p_operation_rec.count_point_type;
567   END IF;
568 
569   -- Missing in AHL
570   IF ( p_operation_rec.dml_operation = 'C' ) THEN
571     x_eam_op_rec.backflush_flag := 2;
572   END IF;
573 
574   x_eam_op_rec.start_date := p_operation_rec.scheduled_start_date;
575   x_eam_op_rec.completion_date := p_operation_rec.scheduled_end_date;
576 
577   -- Do not Pass
578   /**
579   x_eam_op_rec.standard_operation_id := ??;
580   x_eam_op_rec.operation_sequence_id := ??;
581   x_eam_op_rec.shutdown_type := ??;
582   **/
583 
584   -- Set the DML Operation for the Record
585   IF ( p_operation_rec.dml_operation = 'C' ) THEN
586     x_eam_op_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_CREATE;
587   ELSIF ( p_operation_rec.dml_operation = 'U' ) THEN
588     x_eam_op_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_UPDATE;
589   END IF;
590 
591   x_eam_op_rec.return_status := NULL;
592 
593 END map_ahl_eam_op_rec;
594 
595 PROCEDURE map_ahl_eam_mat_rec
596 (
597   p_material_req_rec IN         AHL_PP_MATERIALS_PVT.req_material_rec_type,
598   x_eam_mat_req_rec  OUT NOCOPY EAM_PROCESS_WO_PUB.eam_mat_req_rec_type
599 )
600 AS
601 
602 BEGIN
603 
604   -- Log Input Values
605   IF ( G_DEBUG = 'Y' ) THEN
606     AHL_DEBUG_PUB.debug( 'operation_flag : ' || p_material_req_rec.operation_flag );
607     AHL_DEBUG_PUB.debug( 'workorder_id: ' || TO_CHAR( p_material_req_rec.workorder_id ) );
608     AHL_DEBUG_PUB.debug( 'wip_entity_id: ' || TO_CHAR( p_material_req_rec.wip_entity_id ) );
609     AHL_DEBUG_PUB.debug( 'organization_id: ' || TO_CHAR( p_material_req_rec.organization_id ) );
610     AHL_DEBUG_PUB.debug( 'operation_sequence: ' || TO_CHAR( p_material_req_rec.operation_sequence) );
611     AHL_DEBUG_PUB.debug( 'inventory_item_id: ' || TO_CHAR( p_material_req_rec.inventory_item_id) );
612     AHL_DEBUG_PUB.debug( 'requested_quantity: ' || TO_CHAR( p_material_req_rec.requested_quantity) );
613     AHL_DEBUG_PUB.debug( 'department_id: ' || TO_CHAR( p_material_req_rec.department_id) );
614     AHL_DEBUG_PUB.debug( 'requested_date: ' || TO_CHAR( p_material_req_rec.requested_date, 'DD-MON-YYYY hh24:mi') );
615   END IF;
616 
617   -- Populate EAM Record attributes from input table
618   x_eam_mat_req_rec.wip_entity_id := p_material_req_rec.wip_entity_id;
619   x_eam_mat_req_rec.organization_id := p_material_req_rec.organization_id;
620   x_eam_mat_req_rec.operation_seq_num := p_material_req_rec.operation_sequence;
621   x_eam_mat_req_rec.inventory_item_id := p_material_req_rec.inventory_item_id;
622   x_eam_mat_req_rec.quantity_per_assembly := p_material_req_rec.requested_quantity;
623   x_eam_mat_req_rec.department_id := p_material_req_rec.department_id;
624   x_eam_mat_req_rec.date_required := p_material_req_rec.requested_date;
625   x_eam_mat_req_rec.required_quantity := p_material_req_rec.requested_quantity;
626   --x_eam_mat_req_rec.quantity_issued := p_material_req_rec.requested_quantity;
627   x_eam_mat_req_rec.mrp_net_flag := p_material_req_rec.mrp_net_flag;
628 
629   -- Intialize EAM Record attributes with Constants
630   x_eam_mat_req_rec.wip_supply_type := 1;
631   -- fix for bug# 7217613. Pass quantity issued to EAM only when creating the requirement.
632   IF ( p_material_req_rec.operation_flag = 'C' ) THEN
633     x_eam_mat_req_rec.quantity_issued := 0;
634   END IF;
635 
636   -- Do not Pass
637   /**
638   x_eam_mat_req_rec.supply_subinventory := ??;
639   x_eam_mat_req_rec.supply_locator_id := ??;
640   x_eam_mat_req_rec.mps_required_quantity := ??;
641   x_eam_mat_req_rec.mps_date_required := ??;
642   x_eam_mat_req_rec.component_sequence_id := ??;
643   x_eam_mat_req_rec.comments := ??;
644   **/
645 
646   -- Set the DML Operation for the Record
647   IF ( p_material_req_rec.operation_flag = 'C' ) THEN
648     x_eam_mat_req_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_CREATE;
649   ELSIF ( p_material_req_rec.operation_flag = 'U' ) THEN
650     x_eam_mat_req_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_UPDATE;
651   ELSIF ( p_material_req_rec.operation_flag = 'D' ) THEN
652     x_eam_mat_req_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_DELETE;
653   END IF;
654 
655   x_eam_mat_req_rec.return_status := NULL;
656 
657 END map_ahl_eam_mat_rec;
658 
659 PROCEDURE map_ahl_eam_res_rec
660 (
661   p_resource_req_rec IN       AHL_PP_RESRC_REQUIRE_PVT.resrc_require_rec_type,
662   x_eam_res_rec    OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_rec_type
663 )
664 AS
665 
666 BEGIN
667   -- Log Input Values
668   IF ( G_DEBUG = 'Y' ) THEN
669     AHL_DEBUG_PUB.debug( 'operation_flag : ' || p_resource_req_rec.operation_flag );
670     AHL_DEBUG_PUB.debug( 'workorder_id: ' || TO_CHAR( p_resource_req_rec.workorder_id ) );
671     AHL_DEBUG_PUB.debug( 'wip_entity_id: ' || TO_CHAR( p_resource_req_rec.wip_entity_id ) );
672     AHL_DEBUG_PUB.debug( 'organization_id: ' || TO_CHAR( p_resource_req_rec.organization_id ) );
673     AHL_DEBUG_PUB.debug( 'operation_sequence: ' || TO_CHAR( p_resource_req_rec.operation_seq_number) );
677     AHL_DEBUG_PUB.debug( 'cost_basis_code: ' || TO_CHAR( p_resource_req_rec.cost_basis_code ) );
674     AHL_DEBUG_PUB.debug( 'resource_seq_number: ' || TO_CHAR( p_resource_req_rec.resource_seq_number) );
675     AHL_DEBUG_PUB.debug( 'resource_id: ' || TO_CHAR( p_resource_req_rec.resource_id) );
676     AHL_DEBUG_PUB.debug( 'uom_code: ' || p_resource_req_rec.uom_code );
678     AHL_DEBUG_PUB.debug( 'charge_type_code: ' || TO_CHAR( p_resource_req_rec.charge_type_code) );
679     AHL_DEBUG_PUB.debug( 'std_rate_flag_code: ' || TO_CHAR( p_resource_req_rec.std_rate_flag_code) );
680     AHL_DEBUG_PUB.debug( 'scheduled_type_code: ' || TO_CHAR( p_resource_req_rec.scheduled_type_code) );
681     AHL_DEBUG_PUB.debug( 'applied_num: ' || TO_CHAR( p_resource_req_rec.applied_num) );
682     AHL_DEBUG_PUB.debug( 'open_num: ' || TO_CHAR( p_resource_req_rec.open_num) );
683     AHL_DEBUG_PUB.debug( 'req_start_date: ' || TO_CHAR( p_resource_req_rec.req_start_date, 'DD-MON-YYYY hh24:mi') );
684     AHL_DEBUG_PUB.debug( 'req_end_date: ' || TO_CHAR( p_resource_req_rec.req_end_date, 'DD-MON-YYYY hh24:mi') );
685     AHL_DEBUG_PUB.debug( 'quantity: ' || TO_CHAR( p_resource_req_rec.quantity) );
686     AHL_DEBUG_PUB.debug( 'duration: ' || TO_CHAR( p_resource_req_rec.duration) );
687   END IF;
688 
689   -- Populate EAM Record attributes from input table
690   x_eam_res_rec.wip_entity_id := p_resource_req_rec.wip_entity_id;
691   x_eam_res_rec.organization_id := p_resource_req_rec.organization_id;
692   x_eam_res_rec.operation_seq_num := p_resource_req_rec.operation_seq_number;
693   x_eam_res_rec.resource_seq_num := p_resource_req_rec.resource_seq_number;
694   x_eam_res_rec.resource_id := p_resource_req_rec.resource_id;
695   x_eam_res_rec.uom_code := p_resource_req_rec.uom_code;
696   x_eam_res_rec.basis_type := p_resource_req_rec.cost_basis_code;
697   x_eam_res_rec.autocharge_type := p_resource_req_rec.charge_type_code;
698   x_eam_res_rec.standard_rate_flag := p_resource_req_rec.std_rate_flag_code;
699   x_eam_res_rec.scheduled_flag := p_resource_req_rec.scheduled_type_code;
700   x_eam_res_rec.start_date := p_resource_req_rec.req_start_date;
701   x_eam_res_rec.completion_date := p_resource_req_rec.req_end_date;
702   x_eam_res_rec.usage_rate_or_amount := p_resource_req_rec.duration;
703   x_eam_res_rec.assigned_units := p_resource_req_rec.quantity;
704 -- JKJAIN US space FP for ER # 6998882 -- start
705   x_eam_res_rec.schedule_seq_num := p_resource_req_rec.schedule_seq_num;
706 -- JKJAIN US space FP for ER # 6998882 -- end
707   --  Do not Pass
708   /**
709   x_eam_res_rec.activity_id := p_resource_req_rec.activity_code;
710   x_eam_res_rec.applied_resource_units := p_resource_req_rec.applied_num;
711   x_eam_res_rec.applied_resource_value := p_resource_req_rec.open_num;
712   x_eam_res_rec.assigned_units := ??
713   x_eam_res_rec.substitute_group_num := ??
714   x_eam_res_rec.replacement_group_num := ??
715   x_eam_res_rec.schedule_seq_num := ??
716   **/
717 
718   -- Set the DML Operation for the Record
719   IF ( p_resource_req_rec.operation_flag = 'C' ) THEN
720     x_eam_res_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_CREATE;
721   ELSIF ( p_resource_req_rec.operation_flag = 'U' ) THEN
722     x_eam_res_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_UPDATE;
723   ELSIF ( p_resource_req_rec.operation_flag = 'D' ) THEN
724     x_eam_res_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_DELETE;
725   END IF;
726 
727   x_eam_res_rec.return_status := NULL;
728 
729 END map_ahl_eam_res_rec;
730 
731 PROCEDURE map_ahl_eam_res_inst_rec
732 (
733   p_resource_assign_rec IN       AHL_PP_RESRC_ASSIGN_PVT.resrc_assign_rec_type,
734   x_eam_res_inst_rec  OUT NOCOPY EAM_PROCESS_WO_PUB.eam_res_inst_rec_type
735 )
736 AS
737 
738 BEGIN
739   -- Log Input Values
740   IF ( G_DEBUG = 'Y' ) THEN
741     AHL_DEBUG_PUB.debug( 'operation_flag : ' || p_resource_assign_rec.operation_flag );
742     AHL_DEBUG_PUB.debug( 'workorder_id: ' || TO_CHAR( p_resource_assign_rec.workorder_id ) );
743     AHL_DEBUG_PUB.debug( 'wip_entity_id: ' || TO_CHAR( p_resource_assign_rec.wip_entity_id ) );
744     AHL_DEBUG_PUB.debug( 'organization_id: ' || TO_CHAR( p_resource_assign_rec.organization_id ) );
745     AHL_DEBUG_PUB.debug( 'operation_seq_number: ' || TO_CHAR( p_resource_assign_rec.operation_seq_number) );
746     AHL_DEBUG_PUB.debug( 'resource_seq_number: ' || TO_CHAR( p_resource_assign_rec.resource_seq_number) );
747     AHL_DEBUG_PUB.debug( 'instance_id: ' || TO_CHAR( p_resource_assign_rec.instance_id) );
748     AHL_DEBUG_PUB.debug( 'serial_number: ' || p_resource_assign_rec.serial_number );
749     AHL_DEBUG_PUB.debug( 'assign_start_date: ' || TO_CHAR( p_resource_assign_rec.assign_start_date, 'DD-MON-YYYY hh24:mi') );
750     AHL_DEBUG_PUB.debug( 'assign_end_date: ' || TO_CHAR( p_resource_assign_rec.assign_end_date, 'DD-MON-YYYY hh24:mi') );
751   END IF;
752 
753   -- Populate EAM Record attributes from input table
754   x_eam_res_inst_rec.wip_entity_id := p_resource_assign_rec.wip_entity_id;
755   x_eam_res_inst_rec.organization_id := p_resource_assign_rec.organization_id;
756   x_eam_res_inst_rec.operation_seq_num := p_resource_assign_rec.operation_seq_number;
757   x_eam_res_inst_rec.resource_seq_num := p_resource_assign_rec.resource_seq_number;
758   x_eam_res_inst_rec.instance_id := p_resource_assign_rec.instance_id;
759   x_eam_res_inst_rec.serial_number := p_resource_assign_rec.serial_number;
760   x_eam_res_inst_rec.start_date := p_resource_assign_rec.assign_start_date;
761   x_eam_res_inst_rec.completion_date := p_resource_assign_rec.assign_end_date;
762 
763   -- Do not Pass
764   /**
765   x_eam_res_inst_rec.batch_id := ??;
766   **/
767 
768   -- Set the DML Operation for the Record
772     x_eam_res_inst_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_UPDATE;
769   IF ( p_resource_assign_rec.operation_flag = 'C' ) THEN
770     x_eam_res_inst_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_CREATE;
771   ELSIF ( p_resource_assign_rec.operation_flag = 'U' ) THEN
773   ELSIF ( p_resource_assign_rec.operation_flag = 'D' ) THEN
774     x_eam_res_inst_rec.transaction_type := EAM_PROCESS_WO_PUB.G_OPR_DELETE;
775   END IF;
776 
777   x_eam_res_inst_rec.return_status := NULL;
778 
779 END map_ahl_eam_res_inst_rec;
780 
781 PROCEDURE create_eam_workorder
782 (
783   p_api_version        IN   NUMBER     := 1.0,
784   p_init_msg_list      IN   VARCHAR2   := FND_API.G_TRUE,
785   p_commit             IN   VARCHAR2   := FND_API.G_FALSE,
786   p_validation_level   IN   NUMBER     := FND_API.G_VALID_LEVEL_FULL,
787   p_default            IN   VARCHAR2   := FND_API.G_FALSE,
788   p_module_type        IN   VARCHAR2   := NULL,
789   x_return_status      OUT  NOCOPY  VARCHAR2,
790   x_msg_count          OUT  NOCOPY  NUMBER,
791   x_msg_data           OUT  NOCOPY  VARCHAR2,
792   p_x_workorder_rec    IN OUT NOCOPY AHL_PRD_WORKORDER_PVT.prd_workorder_rec,
793   p_operation_tbl      IN   AHL_PRD_OPERATIONS_PVT.prd_operation_tbl,
794   p_material_req_tbl   IN   AHL_PP_MATERIALS_PVT.req_material_tbl_type,
795   p_resource_req_tbl   IN   AHL_PP_RESRC_REQUIRE_PVT.resrc_require_tbl_type
796 )
797 IS
798 
799 l_api_name                 VARCHAR2(30) := 'create_eam_workorder';
800 
801 -- Declare EAM API parameters
802 l_bo_identifier            VARCHAR2(10) := 'AHL';
803 l_init_msg_list            BOOLEAN := TRUE;
804 l_debug                    VARCHAR2(1)  := 'N';
805 l_output_dir               VARCHAR2(80);
806 l_debug_filename           VARCHAR2(80);
807 l_debug_file_mode          VARCHAR2(1);
808 l_return_status            VARCHAR2(1);
809 l_msg_count                NUMBER;
810 l_eam_wo_rec               EAM_PROCESS_WO_PUB.eam_wo_rec_type;
811 l_eam_op_tbl               EAM_PROCESS_WO_PUB.eam_op_tbl_type;
812 l_eam_op_network_tbl       EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
813 l_eam_res_tbl              EAM_PROCESS_WO_PUB.eam_res_tbl_type;
814 l_eam_res_inst_tbl         EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
815 l_eam_sub_res_tbl          EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
816 l_eam_res_usage_tbl        EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
817 l_eam_mat_req_tbl          EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
818 l_eam_direct_items_tbl     EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
819 l_out_eam_wo_rec           EAM_PROCESS_WO_PUB.eam_wo_rec_type;
820 l_out_eam_op_tbl           EAM_PROCESS_WO_PUB.eam_op_tbl_type;
821 l_out_eam_op_network_tbl   EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
822 l_out_eam_res_tbl          EAM_PROCESS_WO_PUB.eam_res_tbl_type;
823 l_out_eam_res_inst_tbl     EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
824 l_out_eam_sub_res_tbl      EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
825 l_out_eam_res_usage_tbl    EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
826 l_out_eam_mat_req_tbl      EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
827 l_out_eam_direct_items_tbl EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
828 
829 BEGIN
830 
831   -- Enable Debug
832   IF ( G_DEBUG = 'Y' ) THEN
833     AHL_DEBUG_PUB.enable_debug;
834   END IF;
835 
836   -- Initialize API return status to success
837   x_return_status := FND_API.G_RET_STS_SUCCESS;
838 
839   -- Standard Start of API savepoint
840   SAVEPOINT create_eam_workorder_PVT;
841 
842   IF ( G_DEBUG = 'Y' ) THEN
843     AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
844     AHL_DEBUG_PUB.debug( 'Job Header Record: ' );
845   END IF;
846 
847   -- Map all input AHL Job Header record attributes to the
848   -- corresponding EAM Job Header record attributes.
849   map_ahl_eam_wo_rec
850   (
851     p_workorder_rec    => p_x_workorder_rec,
852     x_eam_wo_rec       => l_eam_wo_rec
853   );
854 
855   IF ( G_DEBUG = 'Y' ) THEN
856     AHL_DEBUG_PUB.debug( 'Job Header Record Mapping Complete' );
857   END IF;
858 
859   -- Map all input AHL Operation record attributes to the
860   -- corresponding EAM Operation record attributes.
861   FOR i IN p_operation_tbl.FIRST..p_operation_tbl.LAST LOOP
862 
863     IF ( G_DEBUG = 'Y' ) THEN
864       AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
865       AHL_DEBUG_PUB.debug( 'Operation Record Number : ' || i );
866     END IF;
867 
868     map_ahl_eam_op_rec
869     (
870       p_operation_rec    => p_operation_tbl(i),
871       x_eam_op_rec       => l_eam_op_tbl(i)
872     );
873 
874   END LOOP;
875 
876   IF ( G_DEBUG = 'Y' ) THEN
877     AHL_DEBUG_PUB.debug( 'Operations Record Mapping Complete' );
878   END IF;
879 
880   -- Map all input AHL Material Requirement record attributes to the
881   -- corresponding EAM Material Requirement record attributes.
882   IF ( p_material_req_tbl.COUNT > 0 ) THEN
883     FOR i IN p_material_req_tbl.FIRST..p_material_req_tbl.LAST LOOP
884       IF ( G_DEBUG = 'Y' ) THEN
885         AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
886         AHL_DEBUG_PUB.debug( 'Material Requirement Record Number : ' || i );
887       END IF;
888 
889       map_ahl_eam_mat_rec
890       (
891         p_material_req_rec    => p_material_req_tbl(i),
892         x_eam_mat_req_rec     => l_eam_mat_req_tbl(i)
893       );
894 
895     END LOOP;
896 
900 
897     IF ( G_DEBUG = 'Y' ) THEN
898       AHL_DEBUG_PUB.debug( 'Material Requirements Record Mapping Complete' );
899     END IF;
901   END IF;
902 
903   -- Map all input AHL Resource Requirement record attributes to the
904   -- corresponding EAM Resource Requirement record attributes.
905   IF ( p_resource_req_tbl.COUNT > 0 ) THEN
906     FOR i IN p_resource_req_tbl.FIRST..p_resource_req_tbl.LAST LOOP
907 
908       IF ( G_DEBUG = 'Y' ) THEN
909         AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
910         AHL_DEBUG_PUB.debug( 'Resource Requirement Record Number : ' || i );
911       END IF;
912 
913       map_ahl_eam_res_rec
914       (
915         p_resource_req_rec    => p_resource_req_tbl(i),
916         x_eam_res_rec         => l_eam_res_tbl(i)
917       );
918 
919     END LOOP;
920 
921     IF ( G_DEBUG = 'Y' ) THEN
922       AHL_DEBUG_PUB.debug( 'Resource Requirement Record Mapping Complete' );
923     END IF;
924 
925   END IF;
926 
927   -- Set Debug Parameters for the EAM API
928   IF ( G_DEBUG = 'Y' ) THEN
929     set_eam_debug_params
930     (
931       x_debug           => l_debug,
932       x_output_dir      => l_output_dir,
933       x_debug_file_name => l_debug_filename,
934       x_debug_file_mode => l_debug_file_mode
935     );
936   END IF;
937 
938   IF ( G_DEBUG = 'Y' ) THEN
939     AHL_DEBUG_PUB.debug( 'Invoking EAM process_wo API' );
940   END IF;
941 
942   -- Invoke EAM BO API for Updating the Job
943   EAM_PROCESS_WO_PUB.process_wo
944   (
945     p_bo_identifier             => l_bo_identifier,
946     p_api_version_number        => 1.0,
947     p_init_msg_list             => l_init_msg_list,
948     p_commit                    => FND_API.G_FALSE,
949     p_eam_wo_rec                => l_eam_wo_rec,
950     p_eam_op_tbl                => l_eam_op_tbl,
951     p_eam_op_network_tbl        => l_eam_op_network_tbl,
952     p_eam_res_tbl               => l_eam_res_tbl,
953     p_eam_res_inst_tbl          => l_eam_res_inst_tbl,
954     p_eam_sub_res_tbl           => l_eam_sub_res_tbl,
955     p_eam_res_usage_tbl         => l_eam_res_usage_tbl,
956     p_eam_mat_req_tbl           => l_eam_mat_req_tbl,
957     p_eam_direct_items_tbl      => l_eam_direct_items_tbl,
958     x_eam_wo_rec                => l_out_eam_wo_rec,
959     x_eam_op_tbl                => l_out_eam_op_tbl,
960     x_eam_op_network_tbl        => l_out_eam_op_network_tbl,
961     x_eam_res_tbl               => l_out_eam_res_tbl,
962     x_eam_res_inst_tbl          => l_out_eam_res_inst_tbl,
963     x_eam_sub_res_tbl           => l_out_eam_sub_res_tbl,
964     x_eam_res_usage_tbl         => l_out_eam_res_usage_tbl,
965     x_eam_mat_req_tbl           => l_out_eam_mat_req_tbl,
966     x_eam_direct_items_tbl      => l_out_eam_direct_items_tbl,
967     x_return_status             => l_return_status,
968     x_msg_count                 => l_msg_count,
969     p_debug                     => l_debug,
970     p_output_dir                => l_output_dir,
971     p_debug_filename            => l_debug_filename,
972     p_debug_file_mode           => l_debug_file_mode
973   );
974 
975   IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
976     IF ( G_DEBUG = 'Y' ) THEN
977       AHL_DEBUG_PUB.debug( 'Error Count from EAM API : ' || l_msg_count );
978       AHL_DEBUG_PUB.debug( 'Error Count from Error Stack : ' || FND_MSG_PUB.count_msg );
979     END IF;
980 
981     RAISE FND_API.G_EXC_ERROR;
982   ELSE
983     IF ( G_DEBUG = 'Y' ) THEN
984       AHL_DEBUG_PUB.debug( 'EAM process_wo API Successful' );
985     END IF;
986 
987     p_x_workorder_rec.wip_entity_id := l_out_eam_wo_rec.wip_entity_id;
988 
989     IF ( G_DEBUG = 'Y' ) THEN
990       AHL_DEBUG_PUB.debug( 'New wip_entity_id:' || TO_CHAR( p_x_workorder_rec.wip_entity_id ) );
991     END IF;
992 
993     -- Perform the Commit (if requested)
994     IF FND_API.to_boolean( p_commit ) THEN
995       COMMIT WORK;
996     END IF;
997   END IF;
998 
999   -- Disable debug (if enabled)
1000   IF ( G_DEBUG = 'Y' ) THEN
1001     AHL_DEBUG_PUB.disable_debug;
1002   END IF;
1003 
1004 EXCEPTION
1005 
1006   WHEN FND_API.G_EXC_ERROR THEN
1007     ROLLBACK TO create_eam_workorder_PVT;
1008     x_return_status := FND_API.G_RET_STS_ERROR;
1009     FND_MSG_PUB.count_and_get
1010     (
1011       p_encoded  => FND_API.G_FALSE,
1012       p_count    => x_msg_count,
1013       p_data     => x_msg_data
1014     );
1015 
1016     IF ( G_DEBUG = 'Y' ) THEN
1017       AHL_DEBUG_PUB.disable_debug;
1018     END IF;
1019 
1020   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1021     ROLLBACK TO create_eam_workorder_PVT;
1022     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1023     FND_MSG_PUB.count_and_get
1024     (
1025       p_encoded  => FND_API.G_FALSE,
1026       p_count    => x_msg_count,
1027       p_data     => x_msg_data
1028     );
1029 
1030     IF ( G_DEBUG = 'Y' ) THEN
1031       AHL_DEBUG_PUB.disable_debug;
1032     END IF;
1033 
1034   WHEN OTHERS THEN
1035     ROLLBACK TO create_eam_workorder_PVT;
1036     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1037     IF FND_MSG_PUB.check_msg_level( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )
1038     THEN
1042         p_procedure_name   => l_api_name,
1039       FND_MSG_PUB.add_exc_msg
1040       (
1041         p_pkg_name         => G_PKG_NAME,
1043         p_error_text       => SUBSTRB(SQLERRM,1,240)
1044       );
1045     END IF;
1046     FND_MSG_PUB.count_and_get
1047     (
1048       p_encoded  => FND_API.G_FALSE,
1049       p_count    => x_msg_count,
1050       p_data     => x_msg_data
1051     );
1052 
1053     IF ( G_DEBUG = 'Y' ) THEN
1054       AHL_DEBUG_PUB.disable_debug;
1055     END IF;
1056 END create_eam_workorder;
1057 
1058 PROCEDURE update_job_operations
1059 (
1060   p_api_version            IN   NUMBER     := 1.0,
1061   p_init_msg_list          IN   VARCHAR2   := FND_API.G_TRUE,
1062   p_commit                 IN   VARCHAR2   := FND_API.G_FALSE,
1063   p_validation_level       IN   NUMBER     := FND_API.G_VALID_LEVEL_FULL,
1064   p_default                IN   VARCHAR2   := FND_API.G_FALSE,
1065   p_module_type            IN   VARCHAR2   := NULL,
1066   x_return_status          OUT  NOCOPY  VARCHAR2,
1067   x_msg_count              OUT  NOCOPY  NUMBER,
1068   x_msg_data               OUT  NOCOPY  VARCHAR2,
1069   p_workorder_rec          IN   AHL_PRD_WORKORDER_PVT.prd_workorder_rec,
1070   p_operation_tbl          IN   AHL_PRD_OPERATIONS_PVT.prd_operation_tbl,
1071   p_material_req_tbl       IN   AHL_PP_MATERIALS_PVT.req_material_tbl_type,
1072   p_resource_req_tbl       IN   AHL_PP_RESRC_REQUIRE_PVT.resrc_require_tbl_type
1073 )
1074 IS
1075 
1076 l_api_name                 VARCHAR2(30) := 'update_job_operations';
1077 
1078 -- Declare EAM API parameters
1079 l_bo_identifier            VARCHAR2(10) := 'AHL';
1080 l_init_msg_list            BOOLEAN := TRUE;
1081 l_debug                    VARCHAR2(1)  := 'N';
1082 l_output_dir               VARCHAR2(80);
1083 l_debug_filename           VARCHAR2(80);
1084 l_debug_file_mode          VARCHAR2(1);
1085 l_return_status            VARCHAR2(1);
1086 l_msg_count                NUMBER;
1087 l_eam_wo_rec               EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1088 l_eam_op_tbl               EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1089 l_eam_op_network_tbl       EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1090 l_eam_res_tbl              EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1091 l_eam_res_inst_tbl         EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1092 l_eam_sub_res_tbl          EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1093 l_eam_res_usage_tbl        EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1094 l_eam_mat_req_tbl          EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1095 l_eam_direct_items_tbl     EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1096 l_out_eam_wo_rec           EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1097 l_out_eam_op_tbl           EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1098 l_out_eam_op_network_tbl   EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1099 l_out_eam_res_tbl          EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1100 l_out_eam_res_inst_tbl     EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1101 l_out_eam_sub_res_tbl      EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1102 l_out_eam_res_usage_tbl    EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1103 l_out_eam_mat_req_tbl      EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1104 l_out_eam_direct_items_tbl EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1105 
1106 BEGIN
1107 
1108   -- Enable Debug
1109   IF ( G_DEBUG = 'Y' ) THEN
1110     AHL_DEBUG_PUB.enable_debug;
1111   END IF;
1112 
1113   -- Initialize API return status to success
1114   x_return_status := FND_API.G_RET_STS_SUCCESS;
1115 
1116   -- Standard Start of API savepoint
1117   SAVEPOINT update_job_operations_PVT;
1118 
1119   -- Map all input AHL Job Header record attributes to the
1120   -- corresponding EAM Job Header record attributes.
1121   IF ( p_workorder_rec.workorder_id IS NOT NULL ) THEN
1122 
1123     IF ( G_DEBUG = 'Y' ) THEN
1124       AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
1125       AHL_DEBUG_PUB.debug( 'Job Header Record: ' );
1126     END IF;
1127 
1128     map_ahl_eam_wo_rec
1129     (
1130       p_workorder_rec    => p_workorder_rec,
1131       x_eam_wo_rec       => l_eam_wo_rec
1132     );
1133 
1134   END IF;
1135 
1136   -- Map all input AHL Operation record attributes to the
1137   -- corresponding EAM Operation record attributes.
1138   IF ( p_operation_tbl.COUNT > 0 ) THEN
1139     FOR i IN p_operation_tbl.FIRST..p_operation_tbl.LAST LOOP
1140 
1141       IF ( G_DEBUG = 'Y' ) THEN
1142         AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
1143         AHL_DEBUG_PUB.debug( 'Operation Record Number : ' || i );
1144       END IF;
1145 
1146       map_ahl_eam_op_rec
1147       (
1148         p_operation_rec    => p_operation_tbl(i),
1149         x_eam_op_rec       => l_eam_op_tbl(i)
1150       );
1151 
1152     END LOOP;
1153   END IF;
1154 
1155   -- Map all input AHL Material Requirement record attributes to the
1156   -- corresponding EAM Material Requirement record attributes.
1157   IF ( p_material_req_tbl.COUNT > 0 ) THEN
1158     FOR i IN p_material_req_tbl.FIRST..p_material_req_tbl.LAST LOOP
1159 
1160       IF ( G_DEBUG = 'Y' ) THEN
1161         AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
1162         AHL_DEBUG_PUB.debug( 'Material Requirement Record Number : ' || i );
1163       END IF;
1164 
1165       map_ahl_eam_mat_rec
1166       (
1170 
1167         p_material_req_rec    => p_material_req_tbl(i),
1168         x_eam_mat_req_rec     => l_eam_mat_req_tbl(i)
1169       );
1171     END LOOP;
1172   END IF;
1173 
1174   -- Map all input AHL Resource Requirement record attributes to the
1175   -- corresponding EAM Resource Requirement record attributes.
1176   IF ( p_resource_req_tbl.COUNT > 0 ) THEN
1177     FOR i IN p_resource_req_tbl.FIRST..p_resource_req_tbl.LAST LOOP
1178 
1179       IF ( G_DEBUG = 'Y' ) THEN
1180         AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
1181         AHL_DEBUG_PUB.debug( 'Resource Requirement Record Number : ' || i );
1182       END IF;
1183 
1184       map_ahl_eam_res_rec
1185       (
1186         p_resource_req_rec    => p_resource_req_tbl(i),
1187         x_eam_res_rec         => l_eam_res_tbl(i)
1188       );
1189 
1190     END LOOP;
1191   END IF;
1192 
1193   -- Set Debug Parameters for the EAM API
1194   IF ( G_DEBUG = 'Y' ) THEN
1195     set_eam_debug_params
1196     (
1197       x_debug           => l_debug,
1198       x_output_dir      => l_output_dir,
1199       x_debug_file_name => l_debug_filename,
1200       x_debug_file_mode => l_debug_file_mode
1201     );
1202   END IF;
1203 
1204   IF ( G_DEBUG = 'Y' ) THEN
1205     AHL_DEBUG_PUB.debug( 'Invoking EAM process_wo API' );
1206   END IF;
1207 
1208   -- Invoke EAM BO API for Updating the Job
1209   EAM_PROCESS_WO_PUB.process_wo
1210   (
1211     p_bo_identifier             => l_bo_identifier,
1212     p_api_version_number        => 1.0,
1213     p_init_msg_list             => l_init_msg_list,
1214     p_commit                    => FND_API.G_FALSE,
1215     p_eam_wo_rec                => l_eam_wo_rec,
1216     p_eam_op_tbl                => l_eam_op_tbl,
1217     p_eam_op_network_tbl        => l_eam_op_network_tbl,
1218     p_eam_res_tbl               => l_eam_res_tbl,
1219     p_eam_res_inst_tbl          => l_eam_res_inst_tbl,
1220     p_eam_sub_res_tbl           => l_eam_sub_res_tbl,
1221     p_eam_res_usage_tbl         => l_eam_res_usage_tbl,
1222     p_eam_mat_req_tbl           => l_eam_mat_req_tbl,
1223     p_eam_direct_items_tbl      => l_eam_direct_items_tbl,
1224     x_eam_wo_rec                => l_out_eam_wo_rec,
1225     x_eam_op_tbl                => l_out_eam_op_tbl,
1226     x_eam_op_network_tbl        => l_out_eam_op_network_tbl,
1227     x_eam_res_tbl               => l_out_eam_res_tbl,
1228     x_eam_res_inst_tbl          => l_out_eam_res_inst_tbl,
1229     x_eam_sub_res_tbl           => l_out_eam_sub_res_tbl,
1230     x_eam_res_usage_tbl         => l_out_eam_res_usage_tbl,
1231     x_eam_mat_req_tbl           => l_out_eam_mat_req_tbl,
1232     x_eam_direct_items_tbl      => l_out_eam_direct_items_tbl,
1233     x_return_status             => l_return_status,
1234     x_msg_count                 => l_msg_count,
1235     p_debug                     => l_debug,
1236     p_output_dir                => l_output_dir,
1237     p_debug_filename            => l_debug_filename,
1238     p_debug_file_mode           => l_debug_file_mode
1239   );
1240 
1241   IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
1242     IF ( G_DEBUG = 'Y' ) THEN
1243       AHL_DEBUG_PUB.debug( 'Error Count from EAM API : ' || l_msg_count );
1244       AHL_DEBUG_PUB.debug( 'Error Count from Error Stack : ' || FND_MSG_PUB.count_msg );
1245     END IF;
1246 
1247     RAISE FND_API.G_EXC_ERROR;
1248 
1249   ELSE
1250     -- Perform the Commit (if requested)
1251     IF FND_API.to_boolean( p_commit ) THEN
1252       COMMIT WORK;
1253     END IF;
1254   END IF;
1255 
1256   -- Disable debug (if enabled)
1257   IF ( G_DEBUG = 'Y' ) THEN
1258     AHL_DEBUG_PUB.disable_debug;
1259   END IF;
1260 
1261 EXCEPTION
1262 
1263   WHEN FND_API.G_EXC_ERROR THEN
1264     ROLLBACK TO update_job_operations_PVT;
1265     x_return_status := FND_API.G_RET_STS_ERROR;
1266     FND_MSG_PUB.count_and_get
1267     (
1268       p_encoded  => FND_API.G_FALSE,
1269       p_count    => x_msg_count,
1270       p_data     => x_msg_data
1271     );
1272 
1273     IF ( G_DEBUG = 'Y' ) THEN
1274       AHL_DEBUG_PUB.disable_debug;
1275     END IF;
1276 
1277   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1278     ROLLBACK TO update_job_operations_PVT;
1279     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1280     FND_MSG_PUB.count_and_get
1281     (
1282       p_encoded  => FND_API.G_FALSE,
1283       p_count    => x_msg_count,
1284       p_data     => x_msg_data
1285     );
1286 
1287     IF ( G_DEBUG = 'Y' ) THEN
1288       AHL_DEBUG_PUB.disable_debug;
1289     END IF;
1290 
1291   WHEN OTHERS THEN
1292     ROLLBACK TO update_job_operations_PVT;
1293     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1294     IF FND_MSG_PUB.check_msg_level( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )
1295     THEN
1296       FND_MSG_PUB.add_exc_msg
1297       (
1298         p_pkg_name         => G_PKG_NAME,
1299         p_procedure_name   => l_api_name,
1300         p_error_text       => SUBSTRB(SQLERRM,1,240)
1301       );
1302     END IF;
1303     FND_MSG_PUB.count_and_get
1304     (
1305       p_encoded  => FND_API.G_FALSE,
1306       p_count    => x_msg_count,
1307       p_data     => x_msg_data
1308     );
1309 
1310     IF ( G_DEBUG = 'Y' ) THEN
1314 END update_job_operations;
1311       AHL_DEBUG_PUB.disable_debug;
1312     END IF;
1313 
1315 
1316 PROCEDURE process_material_req
1317 (
1318   p_api_version            IN   NUMBER     := 1.0,
1319   p_init_msg_list          IN   VARCHAR2   := FND_API.G_TRUE,
1320   p_commit                 IN   VARCHAR2   := FND_API.G_FALSE,
1321   p_validation_level       IN   NUMBER     := FND_API.G_VALID_LEVEL_FULL,
1322   p_default                IN   VARCHAR2   := FND_API.G_FALSE,
1323   p_module_type            IN   VARCHAR2   := NULL,
1324   x_return_status          OUT  NOCOPY  VARCHAR2,
1325   x_msg_count              OUT  NOCOPY  NUMBER,
1326   x_msg_data               OUT  NOCOPY  VARCHAR2,
1327   p_material_req_tbl       IN   AHL_PP_MATERIALS_PVT.req_material_tbl_type
1328 )
1329 IS
1330 
1331 l_api_name                 VARCHAR2(30) := 'process_material_req';
1332 
1333 -- Declare EAM API parameters
1334 l_bo_identifier            VARCHAR2(10) := 'AHL';
1335 l_init_msg_list            BOOLEAN := TRUE;
1336 l_debug                    VARCHAR2(1)  := 'N';
1337 l_output_dir               VARCHAR2(80);
1338 l_debug_filename           VARCHAR2(80);
1339 l_debug_file_mode          VARCHAR2(1);
1340 l_return_status            VARCHAR2(1);
1341 l_msg_count                NUMBER;
1342 l_eam_wo_rec               EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1343 l_eam_op_tbl               EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1344 l_eam_op_network_tbl       EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1345 l_eam_res_tbl              EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1346 l_eam_res_inst_tbl         EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1347 l_eam_sub_res_tbl          EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1348 l_eam_res_usage_tbl        EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1349 l_eam_mat_req_tbl          EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1350 l_eam_direct_items_tbl     EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1351 l_out_eam_wo_rec           EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1352 l_out_eam_op_tbl           EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1353 l_out_eam_op_network_tbl   EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1354 l_out_eam_res_tbl          EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1355 l_out_eam_res_inst_tbl     EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1356 l_out_eam_sub_res_tbl      EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1357 l_out_eam_res_usage_tbl    EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1358 l_out_eam_mat_req_tbl      EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1359 l_out_eam_direct_items_tbl EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1360 
1361 BEGIN
1362 
1363   -- Enable Debug
1364   IF ( G_DEBUG = 'Y' ) THEN
1365     AHL_DEBUG_PUB.enable_debug;
1366   END IF;
1367 
1368   -- Initialize API return status to success
1369   x_return_status := FND_API.G_RET_STS_SUCCESS;
1370 
1371   -- Standard Start of API savepoint
1372   SAVEPOINT process_material_req_PVT;
1373 
1374   -- Map all input AHL Material Requirement record attributes to the
1375   -- corresponding EAM Material Requirement record attributes.
1376   FOR i IN p_material_req_tbl.FIRST..p_material_req_tbl.LAST LOOP
1377 
1378     IF ( G_DEBUG = 'Y' ) THEN
1379       AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
1380       AHL_DEBUG_PUB.debug( 'Material Requirement Record Number : ' || i );
1381     END IF;
1382 
1383     map_ahl_eam_mat_rec
1384     (
1385       p_material_req_rec    => p_material_req_tbl(i),
1386       x_eam_mat_req_rec     => l_eam_mat_req_tbl(i)
1387     );
1388 
1389   END LOOP;
1390 
1391   -- Set Debug Parameters for the EAM API
1392   IF ( G_DEBUG = 'Y' ) THEN
1393     set_eam_debug_params
1394     (
1395       x_debug           => l_debug,
1396       x_output_dir      => l_output_dir,
1397       x_debug_file_name => l_debug_filename,
1398       x_debug_file_mode => l_debug_file_mode
1399     );
1400   END IF;
1401 
1402   IF ( G_DEBUG = 'Y' ) THEN
1403     AHL_DEBUG_PUB.debug( 'Invoking EAM process_wo API' );
1404   END IF;
1405 
1406   -- Invoke EAM BO API for Updating the Job
1407   EAM_PROCESS_WO_PUB.process_wo
1408   (
1409     p_bo_identifier             => l_bo_identifier,
1410     p_api_version_number        => 1.0,
1411     p_init_msg_list             => l_init_msg_list,
1412     p_commit                    => FND_API.G_FALSE,
1413     p_eam_wo_rec                => l_eam_wo_rec,
1414     p_eam_op_tbl                => l_eam_op_tbl,
1415     p_eam_op_network_tbl        => l_eam_op_network_tbl,
1416     p_eam_res_tbl               => l_eam_res_tbl,
1417     p_eam_res_inst_tbl          => l_eam_res_inst_tbl,
1418     p_eam_sub_res_tbl           => l_eam_sub_res_tbl,
1419     p_eam_res_usage_tbl         => l_eam_res_usage_tbl,
1420     p_eam_mat_req_tbl           => l_eam_mat_req_tbl,
1421     p_eam_direct_items_tbl      => l_eam_direct_items_tbl,
1422     x_eam_wo_rec                => l_out_eam_wo_rec,
1423     x_eam_op_tbl                => l_out_eam_op_tbl,
1424     x_eam_op_network_tbl        => l_out_eam_op_network_tbl,
1425     x_eam_res_tbl               => l_out_eam_res_tbl,
1426     x_eam_res_inst_tbl          => l_out_eam_res_inst_tbl,
1427     x_eam_sub_res_tbl           => l_out_eam_sub_res_tbl,
1428     x_eam_res_usage_tbl         => l_out_eam_res_usage_tbl,
1429     x_eam_mat_req_tbl           => l_out_eam_mat_req_tbl,
1430     x_eam_direct_items_tbl      => l_out_eam_direct_items_tbl,
1431     x_return_status             => l_return_status,
1432     x_msg_count                 => l_msg_count,
1436     p_debug_file_mode           => l_debug_file_mode
1433     p_debug                     => l_debug,
1434     p_output_dir                => l_output_dir,
1435     p_debug_filename            => l_debug_filename,
1437   );
1438 
1439   IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
1440     IF ( G_DEBUG = 'Y' ) THEN
1441       AHL_DEBUG_PUB.debug( 'Error Count from EAM API : ' || l_msg_count );
1442       AHL_DEBUG_PUB.debug( 'Error Count from Error Stack : ' || FND_MSG_PUB.count_msg );
1443     END IF;
1444 
1445     RAISE FND_API.G_EXC_ERROR;
1446   END IF;
1447 
1448   -- Perform the Commit (if requested)
1449   IF FND_API.to_boolean( p_commit ) THEN
1450     COMMIT WORK;
1451   END IF;
1452 
1453   -- Disable debug (if enabled)
1454   IF ( G_DEBUG = 'Y' ) THEN
1455     AHL_DEBUG_PUB.disable_debug;
1456   END IF;
1457 
1458 EXCEPTION
1459 
1460   WHEN FND_API.G_EXC_ERROR THEN
1461     ROLLBACK TO process_material_req_PVT;
1462     x_return_status := FND_API.G_RET_STS_ERROR;
1463     FND_MSG_PUB.count_and_get
1464     (
1465       p_encoded  => FND_API.G_FALSE,
1466       p_count    => x_msg_count,
1467       p_data     => x_msg_data
1468     );
1469 
1470     IF ( G_DEBUG = 'Y' ) THEN
1471       AHL_DEBUG_PUB.disable_debug;
1472     END IF;
1473 
1474   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1475     ROLLBACK TO process_material_req_PVT;
1476     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1477     FND_MSG_PUB.count_and_get
1478     (
1479       p_encoded  => FND_API.G_FALSE,
1480       p_count    => x_msg_count,
1481       p_data     => x_msg_data
1482     );
1483 
1484     IF ( G_DEBUG = 'Y' ) THEN
1485       AHL_DEBUG_PUB.disable_debug;
1486     END IF;
1487 
1488   WHEN OTHERS THEN
1489     ROLLBACK TO process_material_req_PVT;
1490     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1491     IF FND_MSG_PUB.check_msg_level( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )
1492     THEN
1493       FND_MSG_PUB.add_exc_msg
1494       (
1495         p_pkg_name         => G_PKG_NAME,
1496         p_procedure_name   => l_api_name,
1497         p_error_text       => SUBSTRB(SQLERRM,1,240)
1498       );
1499     END IF;
1500     FND_MSG_PUB.count_and_get
1501     (
1502       p_encoded  => FND_API.G_FALSE,
1503       p_count    => x_msg_count,
1504       p_data     => x_msg_data
1505     );
1506 
1507     IF ( G_DEBUG = 'Y' ) THEN
1508       AHL_DEBUG_PUB.disable_debug;
1509     END IF;
1510 
1511 END process_material_req;
1512 
1513 PROCEDURE process_resource_req
1514 (
1515   p_api_version            IN   NUMBER     := 1.0,
1516   p_init_msg_list          IN   VARCHAR2   := FND_API.G_TRUE,
1517   p_commit                 IN   VARCHAR2   := FND_API.G_FALSE,
1518   p_validation_level       IN   NUMBER     := FND_API.G_VALID_LEVEL_FULL,
1519   p_default                IN   VARCHAR2   := FND_API.G_FALSE,
1520   p_module_type            IN   VARCHAR2   := NULL,
1521   x_return_status          OUT  NOCOPY  VARCHAR2,
1522   x_msg_count              OUT  NOCOPY  NUMBER,
1523   x_msg_data               OUT  NOCOPY  VARCHAR2,
1524   p_resource_req_tbl       IN   AHL_PP_RESRC_REQUIRE_PVT.resrc_require_tbl_type
1525 )
1526 IS
1527 
1528 l_api_name                 VARCHAR2(30) := 'process_resource_req';
1529 
1530 -- Declare EAM API parameters
1531 l_bo_identifier            VARCHAR2(10) := 'AHL';
1532 l_init_msg_list            BOOLEAN := TRUE;
1533 l_debug                    VARCHAR2(1)  := 'N';
1534 l_output_dir               VARCHAR2(80);
1535 l_debug_filename           VARCHAR2(80);
1536 l_debug_file_mode          VARCHAR2(1);
1537 l_return_status            VARCHAR2(1);
1538 l_msg_count                NUMBER;
1539 l_eam_wo_rec               EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1540 l_eam_op_tbl               EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1541 l_eam_op_network_tbl       EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1542 l_eam_res_tbl              EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1543 l_eam_res_inst_tbl         EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1544 l_eam_sub_res_tbl          EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1545 l_eam_res_usage_tbl        EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1546 l_eam_mat_req_tbl          EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1547 l_eam_direct_items_tbl     EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1548 l_out_eam_wo_rec           EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1549 l_out_eam_op_tbl           EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1550 l_out_eam_op_network_tbl   EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1551 l_out_eam_res_tbl          EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1552 l_out_eam_res_inst_tbl     EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1553 l_out_eam_sub_res_tbl      EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1554 l_out_eam_res_usage_tbl    EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1555 l_out_eam_mat_req_tbl      EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1556 l_out_eam_direct_items_tbl EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1557 
1558 BEGIN
1559 
1560   -- Enable Debug
1561   IF ( G_DEBUG = 'Y' ) THEN
1562     AHL_DEBUG_PUB.enable_debug;
1563   END IF;
1564 
1565   -- Initialize API return status to success
1566   x_return_status := FND_API.G_RET_STS_SUCCESS;
1567 
1568   -- Standard Start of API savepoint
1569   SAVEPOINT process_resource_req_PVT;
1570 
1571   -- Map all input AHL Resource Requirement record attributes to the
1572   -- corresponding EAM Resource Requirement record attributes.
1576       AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
1573   FOR i IN p_resource_req_tbl.FIRST..p_resource_req_tbl.LAST LOOP
1574 
1575     IF ( G_DEBUG = 'Y' ) THEN
1577       AHL_DEBUG_PUB.debug( 'Resource Requirement Record Number : ' || i );
1578     END IF;
1579 
1580     map_ahl_eam_res_rec
1581     (
1582       p_resource_req_rec    => p_resource_req_tbl(i),
1583       x_eam_res_rec         => l_eam_res_tbl(i)
1584     );
1585 
1586   END LOOP;
1587 
1588   -- Set Debug Parameters for the EAM API
1589   IF ( G_DEBUG = 'Y' ) THEN
1590     set_eam_debug_params
1591     (
1592       x_debug           => l_debug,
1593       x_output_dir      => l_output_dir,
1594       x_debug_file_name => l_debug_filename,
1595       x_debug_file_mode => l_debug_file_mode
1596     );
1597   END IF;
1598 
1599   IF ( G_DEBUG = 'Y' ) THEN
1600     AHL_DEBUG_PUB.debug( 'Invoking EAM process_wo API' );
1601   END IF;
1602 
1603   -- Invoke EAM BO API for Updating the Job
1604   EAM_PROCESS_WO_PUB.process_wo
1605   (
1606     p_bo_identifier             => l_bo_identifier,
1607     p_api_version_number        => 1.0,
1608     p_init_msg_list             => l_init_msg_list,
1609     p_commit                    => FND_API.G_FALSE,
1610     p_eam_wo_rec                => l_eam_wo_rec,
1611     p_eam_op_tbl                => l_eam_op_tbl,
1612     p_eam_op_network_tbl        => l_eam_op_network_tbl,
1613     p_eam_res_tbl               => l_eam_res_tbl,
1614     p_eam_res_inst_tbl          => l_eam_res_inst_tbl,
1615     p_eam_sub_res_tbl           => l_eam_sub_res_tbl,
1616     p_eam_res_usage_tbl         => l_eam_res_usage_tbl,
1617     p_eam_mat_req_tbl           => l_eam_mat_req_tbl,
1618     p_eam_direct_items_tbl      => l_eam_direct_items_tbl,
1619     x_eam_wo_rec                => l_out_eam_wo_rec,
1620     x_eam_op_tbl                => l_out_eam_op_tbl,
1621     x_eam_op_network_tbl        => l_out_eam_op_network_tbl,
1622     x_eam_res_tbl               => l_out_eam_res_tbl,
1623     x_eam_res_inst_tbl          => l_out_eam_res_inst_tbl,
1624     x_eam_sub_res_tbl           => l_out_eam_sub_res_tbl,
1625     x_eam_res_usage_tbl         => l_out_eam_res_usage_tbl,
1626     x_eam_mat_req_tbl           => l_out_eam_mat_req_tbl,
1627     x_eam_direct_items_tbl      => l_out_eam_direct_items_tbl,
1628     x_return_status             => l_return_status,
1629     x_msg_count                 => l_msg_count,
1630     p_debug                     => l_debug,
1631     p_output_dir                => l_output_dir,
1632     p_debug_filename            => l_debug_filename,
1633     p_debug_file_mode           => l_debug_file_mode
1634   );
1635 
1636   IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
1637     IF ( G_DEBUG = 'Y' ) THEN
1638       AHL_DEBUG_PUB.debug( 'Error Count from EAM API : ' || l_msg_count );
1639       AHL_DEBUG_PUB.debug( 'Error Count from Error Stack : ' || FND_MSG_PUB.count_msg );
1640     END IF;
1641 
1642     RAISE FND_API.G_EXC_ERROR;
1643   END IF;
1644 
1645   -- Perform the Commit (if requested)
1646   IF FND_API.to_boolean( p_commit ) THEN
1647     COMMIT WORK;
1648   END IF;
1649 
1650   -- Disable debug (if enabled)
1651   IF ( G_DEBUG = 'Y' ) THEN
1652     AHL_DEBUG_PUB.disable_debug;
1653   END IF;
1654 
1655 EXCEPTION
1656 
1657   WHEN FND_API.G_EXC_ERROR THEN
1658     ROLLBACK TO process_resource_req_PVT;
1659     x_return_status := FND_API.G_RET_STS_ERROR;
1660     FND_MSG_PUB.count_and_get
1661     (
1662       p_encoded  => FND_API.G_FALSE,
1663       p_count    => x_msg_count,
1664       p_data     => x_msg_data
1665     );
1666 
1667     IF ( G_DEBUG = 'Y' ) THEN
1668       AHL_DEBUG_PUB.disable_debug;
1669     END IF;
1670 
1671   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1672     ROLLBACK TO process_resource_req_PVT;
1673     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1674     FND_MSG_PUB.count_and_get
1675     (
1676       p_encoded  => FND_API.G_FALSE,
1677       p_count    => x_msg_count,
1678       p_data     => x_msg_data
1679     );
1680 
1681     IF ( G_DEBUG = 'Y' ) THEN
1682       AHL_DEBUG_PUB.disable_debug;
1683     END IF;
1684 
1685   WHEN OTHERS THEN
1686     ROLLBACK TO process_resource_req_PVT;
1687     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1688     IF FND_MSG_PUB.check_msg_level( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )
1689     THEN
1690       FND_MSG_PUB.add_exc_msg
1691       (
1692         p_pkg_name         => G_PKG_NAME,
1693         p_procedure_name   => l_api_name,
1694         p_error_text       => SUBSTRB(SQLERRM,1,240)
1695       );
1696     END IF;
1697     FND_MSG_PUB.count_and_get
1698     (
1699       p_encoded  => FND_API.G_FALSE,
1700       p_count    => x_msg_count,
1701       p_data     => x_msg_data
1702     );
1703 
1704     IF ( G_DEBUG = 'Y' ) THEN
1705       AHL_DEBUG_PUB.disable_debug;
1706     END IF;
1707 
1708 END process_resource_req;
1709 
1710 PROCEDURE process_resource_assign
1711 (
1712   p_api_version            IN   NUMBER     := 1.0,
1713   p_init_msg_list          IN   VARCHAR2   := FND_API.G_TRUE,
1714   p_commit                 IN   VARCHAR2   := FND_API.G_FALSE,
1715   p_validation_level       IN   NUMBER     := FND_API.G_VALID_LEVEL_FULL,
1716   p_default                IN   VARCHAR2   := FND_API.G_FALSE,
1717   p_module_type            IN   VARCHAR2   := NULL,
1721   p_resource_assign_tbl    IN   AHL_PP_RESRC_ASSIGN_PVT.resrc_assign_tbl_type
1718   x_return_status          OUT  NOCOPY  VARCHAR2,
1719   x_msg_count              OUT  NOCOPY  NUMBER,
1720   x_msg_data               OUT  NOCOPY  VARCHAR2,
1722 )
1723 IS
1724 
1725 l_api_name                 VARCHAR2(30) := 'process_resource_assign';
1726 
1727 -- Declare EAM API parameters
1728 l_bo_identifier            VARCHAR2(10) := 'AHL';
1729 l_init_msg_list            BOOLEAN := TRUE;
1730 l_debug                    VARCHAR2(1)  := 'N';
1731 l_output_dir               VARCHAR2(80);
1732 l_debug_filename           VARCHAR2(80);
1733 l_debug_file_mode          VARCHAR2(1);
1734 l_return_status            VARCHAR2(1);
1735 l_msg_count                NUMBER;
1736 l_eam_wo_rec               EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1737 l_eam_op_tbl               EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1738 l_eam_op_network_tbl       EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1739 l_eam_res_tbl              EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1740 l_eam_res_inst_tbl         EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1741 l_eam_sub_res_tbl          EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1742 l_eam_res_usage_tbl        EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1743 l_eam_mat_req_tbl          EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1744 l_eam_direct_items_tbl     EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1745 l_out_eam_wo_rec           EAM_PROCESS_WO_PUB.eam_wo_rec_type;
1746 l_out_eam_op_tbl           EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1747 l_out_eam_op_network_tbl   EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1748 l_out_eam_res_tbl          EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1749 l_out_eam_res_inst_tbl     EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1750 l_out_eam_sub_res_tbl      EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1751 l_out_eam_res_usage_tbl    EAM_PROCESS_WO_PUB.eam_res_usage_tbl_type;
1752 l_out_eam_mat_req_tbl      EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1753 l_out_eam_direct_items_tbl EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1754 
1755 BEGIN
1756 
1757   -- Enable Debug
1758   IF ( G_DEBUG = 'Y' ) THEN
1759     AHL_DEBUG_PUB.enable_debug;
1760   END IF;
1761 
1762   -- Initialize API return status to success
1763   x_return_status := FND_API.G_RET_STS_SUCCESS;
1764 
1765   -- Standard Start of API savepoint
1766   SAVEPOINT process_resource_assign_PVT;
1767 
1768   -- Map all input AHL Material Requirement record attributes to the
1769   -- corresponding EAM Material Requirement record attributes.
1770   FOR i IN p_resource_assign_tbl.FIRST..p_resource_assign_tbl.LAST LOOP
1771 
1772     IF ( G_DEBUG = 'Y' ) THEN
1773       AHL_DEBUG_PUB.debug( 'Inputs for API: ' || G_PKG_NAME||'.'||l_api_name );
1774       AHL_DEBUG_PUB.debug( 'Resource Assignment Record Number : ' || i );
1775     END IF;
1776 
1777     map_ahl_eam_res_inst_rec
1778     (
1779       p_resource_assign_rec    => p_resource_assign_tbl(i),
1780       x_eam_res_inst_rec       => l_eam_res_inst_tbl(i)
1781     );
1782 
1783   END LOOP;
1784 
1785   -- Set Debug Parameters for the EAM API
1786   IF ( G_DEBUG = 'Y' ) THEN
1787     set_eam_debug_params
1788     (
1789       x_debug           => l_debug,
1790       x_output_dir      => l_output_dir,
1791       x_debug_file_name => l_debug_filename,
1792       x_debug_file_mode => l_debug_file_mode
1793     );
1794   END IF;
1795 
1796   IF ( G_DEBUG = 'Y' ) THEN
1797     AHL_DEBUG_PUB.debug( 'Invoking EAM process_wo API' );
1798   END IF;
1799 
1800   -- Invoke EAM BO API for Updating the Job
1801   EAM_PROCESS_WO_PUB.process_wo
1802   (
1803     p_bo_identifier             => l_bo_identifier,
1804     p_api_version_number        => 1.0,
1805     p_init_msg_list             => l_init_msg_list,
1806     p_commit                    => FND_API.G_FALSE,
1807     p_eam_wo_rec                => l_eam_wo_rec,
1808     p_eam_op_tbl                => l_eam_op_tbl,
1809     p_eam_op_network_tbl        => l_eam_op_network_tbl,
1810     p_eam_res_tbl               => l_eam_res_tbl,
1811     p_eam_res_inst_tbl          => l_eam_res_inst_tbl,
1812     p_eam_sub_res_tbl           => l_eam_sub_res_tbl,
1813     p_eam_res_usage_tbl         => l_eam_res_usage_tbl,
1814     p_eam_mat_req_tbl           => l_eam_mat_req_tbl,
1815     p_eam_direct_items_tbl      => l_eam_direct_items_tbl,
1816     x_eam_wo_rec                => l_out_eam_wo_rec,
1817     x_eam_op_tbl                => l_out_eam_op_tbl,
1818     x_eam_op_network_tbl        => l_out_eam_op_network_tbl,
1819     x_eam_res_tbl               => l_out_eam_res_tbl,
1820     x_eam_res_inst_tbl          => l_out_eam_res_inst_tbl,
1821     x_eam_sub_res_tbl           => l_out_eam_sub_res_tbl,
1822     x_eam_res_usage_tbl         => l_out_eam_res_usage_tbl,
1823     x_eam_mat_req_tbl           => l_out_eam_mat_req_tbl,
1824     x_eam_direct_items_tbl      => l_out_eam_direct_items_tbl,
1825     x_return_status             => l_return_status,
1826     x_msg_count                 => l_msg_count,
1827     p_debug                     => l_debug,
1828     p_output_dir                => l_output_dir,
1829     p_debug_filename            => l_debug_filename,
1830     p_debug_file_mode           => l_debug_file_mode
1831   );
1832 
1833   IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
1834     IF ( G_DEBUG = 'Y' ) THEN
1835       AHL_DEBUG_PUB.debug( 'Error Count from EAM API : ' || l_msg_count );
1836       AHL_DEBUG_PUB.debug( 'Error Count from Error Stack : ' || FND_MSG_PUB.count_msg );
1837     END IF;
1841 
1838 
1839     RAISE FND_API.G_EXC_ERROR;
1840   END IF;
1842   -- Perform the Commit (if requested)
1843   IF FND_API.to_boolean( p_commit ) THEN
1844     COMMIT WORK;
1845   END IF;
1846 
1847   -- Disable debug (if enabled)
1848   IF ( G_DEBUG = 'Y' ) THEN
1849     AHL_DEBUG_PUB.disable_debug;
1850   END IF;
1851 
1852 EXCEPTION
1853 
1854   WHEN FND_API.G_EXC_ERROR THEN
1855     ROLLBACK TO process_resource_assign_PVT;
1856     x_return_status := FND_API.G_RET_STS_ERROR;
1857     FND_MSG_PUB.count_and_get
1858     (
1859       p_encoded  => FND_API.G_FALSE,
1860       p_count    => x_msg_count,
1861       p_data     => x_msg_data
1862     );
1863 
1864     IF ( G_DEBUG = 'Y' ) THEN
1865       AHL_DEBUG_PUB.disable_debug;
1866     END IF;
1867 
1868   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1869     ROLLBACK TO process_resource_assign_PVT;
1870     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1871     FND_MSG_PUB.count_and_get
1872     (
1873       p_encoded  => FND_API.G_FALSE,
1874       p_count    => x_msg_count,
1875       p_data     => x_msg_data
1876     );
1877 
1878     IF ( G_DEBUG = 'Y' ) THEN
1879       AHL_DEBUG_PUB.disable_debug;
1880     END IF;
1881 
1882   WHEN OTHERS THEN
1883     ROLLBACK TO process_resource_assign_PVT;
1884     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
1885     IF FND_MSG_PUB.check_msg_level( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )
1886     THEN
1887       FND_MSG_PUB.add_exc_msg
1888       (
1889         p_pkg_name         => G_PKG_NAME,
1890         p_procedure_name   => l_api_name,
1891         p_error_text       => SUBSTRB(SQLERRM,1,240)
1892       );
1893     END IF;
1894     FND_MSG_PUB.count_and_get
1895     (
1896       p_encoded  => FND_API.G_FALSE,
1897       p_count    => x_msg_count,
1898       p_data     => x_msg_data
1899     );
1900 
1901     IF ( G_DEBUG = 'Y' ) THEN
1902       AHL_DEBUG_PUB.disable_debug;
1903     END IF;
1904 
1905 END process_resource_assign;
1906 
1907 PROCEDURE process_eam_workorders
1908 (
1909   p_api_version          IN   NUMBER     := 1.0,
1910   p_init_msg_list        IN   VARCHAR2   := FND_API.G_TRUE,
1911   p_commit               IN   VARCHAR2   := FND_API.G_FALSE,
1912   p_validation_level     IN   NUMBER     := FND_API.G_VALID_LEVEL_FULL,
1913   p_default              IN   VARCHAR2   := FND_API.G_FALSE,
1914   p_module_type          IN   VARCHAR2   := NULL,
1915   x_return_status        OUT  NOCOPY  VARCHAR2,
1916   x_msg_count            OUT  NOCOPY  NUMBER,
1917   x_msg_data             OUT  NOCOPY  VARCHAR2,
1918   p_x_eam_wo_tbl         IN OUT NOCOPY EAM_PROCESS_WO_PUB.eam_wo_tbl_type,
1919   p_eam_wo_relations_tbl IN    EAM_PROCESS_WO_PUB.eam_wo_relations_tbl_type,
1920   p_eam_op_tbl           IN    EAM_PROCESS_WO_PUB.eam_op_tbl_type,
1921   p_eam_res_req_tbl      IN    EAM_PROCESS_WO_PUB.eam_res_tbl_type,
1922   p_eam_mat_req_tbl      IN    EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type
1923 )
1924 IS
1925 
1926 l_api_name                 VARCHAR2(30) := 'process_eam_workorders';
1927 
1928 -- Declare EAM API parameters
1929 l_bo_identifier            VARCHAR2(10) := 'AHL';
1930 l_init_msg_list            BOOLEAN := TRUE;
1931 l_debug                    VARCHAR2(1)  := 'N';
1932 l_output_dir               VARCHAR2(80);
1933 l_debug_filename           VARCHAR2(80);
1934 l_debug_file_mode          VARCHAR2(1);
1935 l_return_status            VARCHAR2(1);
1936 l_msg_count                NUMBER;
1937 l_eam_op_network_tbl       EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1938 l_eam_res_inst_tbl         EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1939 l_eam_sub_res_tbl          EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1940 l_eam_direct_items_tbl     EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1941 l_out_eam_wo_tbl           EAM_PROCESS_WO_PUB.eam_wo_tbl_type;
1942 l_out_eam_wo_rel_tbl       EAM_PROCESS_WO_PUB.eam_wo_relations_tbl_type;
1943 l_out_eam_op_tbl           EAM_PROCESS_WO_PUB.eam_op_tbl_type;
1944 l_out_eam_op_network_tbl   EAM_PROCESS_WO_PUB.eam_op_network_tbl_type;
1945 l_out_eam_res_tbl          EAM_PROCESS_WO_PUB.eam_res_tbl_type;
1946 l_out_eam_res_inst_tbl     EAM_PROCESS_WO_PUB.eam_res_inst_tbl_type;
1947 l_out_eam_sub_res_tbl      EAM_PROCESS_WO_PUB.eam_sub_res_tbl_type;
1948 l_out_eam_mat_req_tbl      EAM_PROCESS_WO_PUB.eam_mat_req_tbl_type;
1949 l_out_eam_direct_items_tbl EAM_PROCESS_WO_PUB.eam_direct_items_tbl_type;
1950 
1951 BEGIN
1952 
1953   -- Enable Debug
1954   IF ( G_DEBUG = 'Y' ) THEN
1955     AHL_DEBUG_PUB.enable_debug;
1956   END IF;
1957 
1958   -- Initialize API return status to success
1959   x_return_status := FND_API.G_RET_STS_SUCCESS;
1960 
1961   -- Standard Start of API savepoint
1962   SAVEPOINT process_eam_workorders_PVT;
1963 
1964   -- Set Debug Parameters for the EAM API
1965   IF ( G_DEBUG = 'Y' ) THEN
1966     set_eam_debug_params
1967     (
1968       x_debug           => l_debug,
1969       x_output_dir      => l_output_dir,
1970       x_debug_file_name => l_debug_filename,
1971       x_debug_file_mode => l_debug_file_mode
1972     );
1973   END IF;
1974 
1975   IF ( G_DEBUG = 'Y' ) THEN
1976     AHL_DEBUG_PUB.debug( 'Invoking EAM process_master_child_wo API' );
1977 
1978 				IF(p_x_eam_wo_tbl.COUNT > 0) THEN
1979     FOR i IN p_x_eam_wo_tbl.FIRST..p_x_eam_wo_tbl.LAST LOOP
1980       AHL_DEBUG_PUB.debug( 'Workorder('||i||') batch_id : '||p_x_eam_wo_tbl(i).batch_id );
1984 
1981       AHL_DEBUG_PUB.debug( 'Workorder('||i||') header_id : '||p_x_eam_wo_tbl(i).header_id );
1982     END LOOP;
1983 				END IF;
1985     IF ( p_eam_op_tbl.COUNT > 0 ) THEN
1986       FOR i IN p_eam_op_tbl.FIRST..p_eam_op_tbl.LAST LOOP
1987         AHL_DEBUG_PUB.debug( 'Operation('||i||') batch_id : '||p_eam_op_tbl(i).batch_id );
1988         AHL_DEBUG_PUB.debug( 'Operation('||i||') header_id : '||p_eam_op_tbl(i).header_id );
1989       END LOOP;
1990     END IF;
1991 
1992     IF ( p_eam_res_req_tbl.COUNT > 0 ) THEN
1993       FOR i IN p_eam_res_req_tbl.FIRST..p_eam_res_req_tbl.LAST LOOP
1994         AHL_DEBUG_PUB.debug( 'Resource('||i||') batch_id : '||p_eam_res_req_tbl(i).batch_id );
1995         AHL_DEBUG_PUB.debug( 'Resource('||i||') header_id : '||p_eam_res_req_tbl(i).header_id );
1996       END LOOP;
1997     END IF;
1998 
1999     IF ( p_eam_mat_req_tbl.COUNT > 0 ) THEN
2000       FOR i IN p_eam_mat_req_tbl.FIRST..p_eam_mat_req_tbl.LAST LOOP
2001         AHL_DEBUG_PUB.debug( 'Material('||i||') batch_id : '||p_eam_mat_req_tbl(i).batch_id );
2002         AHL_DEBUG_PUB.debug( 'Material('||i||') header_id : '||p_eam_mat_req_tbl(i).header_id );
2003       END LOOP;
2004     END IF;
2005 
2006   END IF;
2007 
2008   EAM_PROCESS_WO_PUB.process_master_child_wo
2009   (
2010    p_bo_identifier             => l_bo_identifier,
2011    p_api_version_number        => 1.0,
2012    p_init_msg_list             => l_init_msg_list,
2013    p_eam_wo_relations_tbl      => p_eam_wo_relations_tbl,
2014    p_eam_wo_tbl                => p_x_eam_wo_tbl,
2015    p_eam_op_tbl                => p_eam_op_tbl,
2016    p_eam_op_network_tbl        => l_eam_op_network_tbl,
2017    p_eam_res_tbl               => p_eam_res_req_tbl,
2018    p_eam_res_inst_tbl          => l_eam_res_inst_tbl,
2019    p_eam_sub_res_tbl           => l_eam_sub_res_tbl,
2020    p_eam_mat_req_tbl           => p_eam_mat_req_tbl,
2021    p_eam_direct_items_tbl      => l_eam_direct_items_tbl,
2022    x_eam_wo_tbl                => l_out_eam_wo_tbl,
2023    x_eam_wo_relations_tbl      => l_out_eam_wo_rel_tbl,
2024    x_eam_op_tbl                => l_out_eam_op_tbl,
2025    x_eam_op_network_tbl        => l_out_eam_op_network_tbl,
2026    x_eam_res_tbl               => l_out_eam_res_tbl,
2027    x_eam_res_inst_tbl          => l_out_eam_res_inst_tbl,
2028    x_eam_sub_res_tbl           => l_out_eam_sub_res_tbl,
2029    x_eam_mat_req_tbl           => l_out_eam_mat_req_tbl,
2030    x_eam_direct_items_tbl      => l_out_eam_direct_items_tbl,
2031    x_return_status             => l_return_status,
2032    x_msg_count                 => l_msg_count,
2033    p_commit                    => FND_API.G_FALSE,
2034    p_debug                     => l_debug,
2035    p_output_dir                => l_output_dir,
2036    p_debug_filename            => l_debug_filename,
2037    p_debug_file_mode           => l_debug_file_mode
2038   );
2039 
2040   IF ( l_return_status <> FND_API.G_RET_STS_SUCCESS ) THEN
2041     IF ( G_DEBUG = 'Y' ) THEN
2042       AHL_DEBUG_PUB.debug( 'Error Count from EAM API : ' || l_msg_count );
2043       AHL_DEBUG_PUB.debug( 'Error Count from Error Stack : ' || FND_MSG_PUB.count_msg );
2044     END IF;
2045 
2046     RAISE FND_API.G_EXC_ERROR;
2047 
2048   ELSE
2049     --Change made on Nov 17, 2005 by jeli due to bug 4742895.
2050     --Ignore messages in stack if return status is S after calls to EAM APIs.
2051     FND_MSG_PUB.initialize;
2052 
2053     IF ( G_DEBUG = 'Y' ) THEN
2054       AHL_DEBUG_PUB.debug( 'EAM process_master_child_wo API Successful' );
2055       AHL_DEBUG_PUB.debug( 'Input Workorder Table count : ' || p_x_eam_wo_tbl.COUNT );
2056       AHL_DEBUG_PUB.debug( 'Output Workorder Table count : ' || l_out_eam_wo_tbl.COUNT );
2057     END IF;
2058 
2059     FOR i IN 1..l_out_eam_wo_tbl.COUNT LOOP
2060       IF ( l_out_eam_wo_tbl(i).wip_entity_id IS NULL ) THEN
2061         FND_MESSAGE.set_name('AHL','AHL_PRD_CREATE_WIP_JOB_FAILED');
2062         FND_MESSAGE.set_token('HEADER', l_out_eam_wo_tbl(i).header_id );
2063         FND_MSG_PUB.add;
2064 
2065         IF ( G_DEBUG = 'Y' ) THEN
2066           AHL_DEBUG_PUB.debug( 'No wip_entity_id generated for header_id:' || l_out_eam_wo_tbl(i).header_id );
2067         END IF;
2068       ELSE
2069 
2070         IF ( G_DEBUG = 'Y' ) THEN
2071           AHL_DEBUG_PUB.debug( 'wip_entity_id(' || i || '):' || TO_CHAR( l_out_eam_wo_tbl(i).wip_entity_id ) );
2072         END IF;
2073 
2074         p_x_eam_wo_tbl(i).wip_entity_id := l_out_eam_wo_tbl(i).wip_entity_id;
2075 
2076       END IF;
2077     END LOOP;
2078 
2079     l_msg_count := FND_MSG_PUB.count_msg;
2080     IF l_msg_count > 0 THEN
2081       RAISE FND_API.G_EXC_ERROR;
2082     END IF;
2083 
2084     -- Perform the Commit (if requested)
2085     IF FND_API.to_boolean( p_commit ) THEN
2086       COMMIT WORK;
2087     END IF;
2088   END IF;
2089 
2090   -- Disable debug (if enabled)
2091   IF ( G_DEBUG = 'Y' ) THEN
2092     AHL_DEBUG_PUB.disable_debug;
2093   END IF;
2094 
2095 EXCEPTION
2096 
2097   WHEN FND_API.G_EXC_ERROR THEN
2098     ROLLBACK TO process_eam_workorders_PVT;
2099     x_return_status := FND_API.G_RET_STS_ERROR;
2100     FND_MSG_PUB.count_and_get
2101     (
2102       p_encoded  => FND_API.G_FALSE,
2103       p_count    => x_msg_count,
2104       p_data     => x_msg_data
2105     );
2106 
2107     IF ( G_DEBUG = 'Y' ) THEN
2108       AHL_DEBUG_PUB.disable_debug;
2109     END IF;
2110 
2111   WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2112     ROLLBACK TO process_eam_workorders_PVT;
2113     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2114     FND_MSG_PUB.count_and_get
2115     (
2116       p_encoded  => FND_API.G_FALSE,
2117       p_count    => x_msg_count,
2118       p_data     => x_msg_data
2119     );
2120 
2121     IF ( G_DEBUG = 'Y' ) THEN
2122       AHL_DEBUG_PUB.disable_debug;
2123     END IF;
2124 
2125   WHEN OTHERS THEN
2126     ROLLBACK TO process_eam_workorders_PVT;
2127     x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
2128     IF FND_MSG_PUB.check_msg_level( FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR )
2129     THEN
2130       FND_MSG_PUB.add_exc_msg
2131       (
2132         p_pkg_name         => G_PKG_NAME,
2133         p_procedure_name   => l_api_name,
2134         p_error_text       => SUBSTRB(SQLERRM,1,240)
2135       );
2136     END IF;
2137     FND_MSG_PUB.count_and_get
2138     (
2139       p_encoded  => FND_API.G_FALSE,
2140       p_count    => x_msg_count,
2141       p_data     => x_msg_data
2142     );
2143 
2144     IF ( G_DEBUG = 'Y' ) THEN
2145       AHL_DEBUG_PUB.disable_debug;
2146     END IF;
2147 END process_eam_workorders;
2148 
2149 END AHL_EAM_JOB_PVT;