DBA Data[Home] [Help]

PACKAGE BODY: APPS.EAM_OP_COMP_VALIDATE_PVT

Source


1 PACKAGE BODY EAM_OP_COMP_VALIDATE_PVT AS
2 /* $Header: EAMVOCVB.pls 120.7 2012/01/27 10:54:22 vchidura ship $ */
3 /***************************************************************************
4 --
5 --  Copyright (c) 2002 Oracle Corporation, Redwood Shores, CA, USA
6 --  All rights reserved.
7 --
8 --  FILENAME
9 --
10 --      EAMVOCVB.pls
11 --
12 --  DESCRIPTION
13 --
14 --      Body of package EAM_OP_COMP_VALIDATE_PVT
15 --
16 --  NOTES
17 --
18 --  HISTORY
19 --
20 --  14-FEB-2005    mmaduska     Initial Creation
21 ***************************************************************************/
22 
23 
24 PROCEDURE Check_Required
25    (
26 	  p_eam_op_comp_rec         IN  EAM_PROCESS_WO_PUB.eam_op_comp_rec_type
27         , x_return_status           OUT NOCOPY  VARCHAR2
28         , x_mesg_token_tbl          OUT NOCOPY EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type
29     )IS
30 
31       l_Mesg_Token_Tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
32       l_out_Mesg_Token_Tbl    EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
33       l_Token_Tbl             EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type;
34       l_shutdown_type	      varchar2(30);
35     BEGIN
36 
37         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Operation Completeion Populate null columns'); END IF;
38 
39         x_return_status := FND_API.G_RET_STS_SUCCESS;
40 
41 
42 	IF p_eam_op_comp_rec.operation_seq_num IS NULL
43         THEN
44         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Op Comp : operation_seq_num ...'); END IF;
45             l_token_tbl(1).token_name  := 'WIP_ENTITY_ID';
46             l_token_tbl(1).token_value :=  p_eam_op_comp_rec.wip_entity_id;
47 
48             l_out_mesg_token_tbl  := l_mesg_token_tbl;
49             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
50             (  p_message_name	=> 'EAM_OPCL_OP_REQUIRED'
51              , p_token_tbl	=> l_Token_tbl
52              , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
53              , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
54              );
55             x_mesg_token_tbl      := l_out_mesg_token_tbl;
56 
57             x_return_status := FND_API.G_RET_STS_ERROR;
58 
59         END IF;
60 
61 	IF p_eam_op_comp_rec.actual_start_date IS NULL
62         THEN
63         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Op Comp : actual_start_date ...'); END IF;
64             l_token_tbl(1).token_name  := 'OP_SEQ_NO';
65             l_token_tbl(1).token_value :=  p_eam_op_comp_rec.operation_seq_num;
66 
67             l_out_mesg_token_tbl  := l_mesg_token_tbl;
68             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
69             (  p_message_name	=> 'EAM_OPCL_ACTSTD_REQUIRED'
70              , p_token_tbl	=> l_Token_tbl
71              , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
72              , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
73              );
74             x_mesg_token_tbl      := l_out_mesg_token_tbl;
75 
76             x_return_status := FND_API.G_RET_STS_ERROR;
77 
78         END IF;
79 
80 	IF p_eam_op_comp_rec.actual_end_date IS NULL
81         THEN
82         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Op Comp : Actual end date ...'); END IF;
83             l_token_tbl(1).token_name  := 'OP_SEQ_NO';
84             l_token_tbl(1).token_value :=  p_eam_op_comp_rec.operation_seq_num;
85 
86             l_out_mesg_token_tbl  := l_mesg_token_tbl;
87             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
88             (  p_message_name	=> 'EAM_OPCL_ACTEND_REQUIRED'
89              , p_token_tbl	=> l_Token_tbl
90              , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
91              , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
92              );
93             x_mesg_token_tbl      := l_out_mesg_token_tbl;
94 
95             x_return_status := FND_API.G_RET_STS_ERROR;
96 
97         END IF;
98 
99 	IF p_eam_op_comp_rec.actual_duration IS NULL
100         THEN
101         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Op Comp : Actual duration ...'); END IF;
102             l_token_tbl(1).token_name  := 'OP_SEQ_NO';
103             l_token_tbl(1).token_value :=  p_eam_op_comp_rec.operation_seq_num;
104 
105             l_out_mesg_token_tbl  := l_mesg_token_tbl;
106             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
107             (  p_message_name	=> 'EAM_OPCL_ACTDUR_REQUIRED'
108              , p_token_tbl	=> l_Token_tbl
109              , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
110              , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
111              );
112             x_mesg_token_tbl      := l_out_mesg_token_tbl;
113 
114             x_return_status := FND_API.G_RET_STS_ERROR;
115 
116         END IF;
117 
118 
119 	IF p_eam_op_comp_rec.transaction_type IS NULL
120         THEN
121         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Op Comp : transaction_type  ...'); END IF;
122             l_token_tbl(1).token_name  := 'OP_SEQ_NO';
123             l_token_tbl(1).token_value :=  p_eam_op_comp_rec.operation_seq_num;
124 
125             l_out_mesg_token_tbl  := l_mesg_token_tbl;
126             EAM_ERROR_MESSAGE_PVT.Add_Error_Token
127             (  p_message_name	=> 'EAM_OPCL_TRANX_REQUIRED'
128              , p_token_tbl	=> l_Token_tbl
129              , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
130              , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
131              );
132             x_mesg_token_tbl      := l_out_mesg_token_tbl;
133 
134             x_return_status := FND_API.G_RET_STS_ERROR;
135 
136         END IF;
137 
138 	IF p_eam_op_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE
139         THEN
140 		--commented for bug 12843159
141 		/*SELECT shutdown_type into l_shutdown_type
142 		  FROM wip_discrete_jobs
143                  WHERE wip_entity_id =    p_eam_op_comp_rec.wip_entity_id;
144 		IF l_shutdown_type IS NOT NULL THEN*/
145 
146 		--Added for bug 12843159
147 		SELECT shutdown_type
148 	     INTO l_shutdown_type
149 	     FROM wip_operations
150 	     WHERE wip_entity_id    = p_eam_op_comp_rec.wip_entity_id
151 	     AND operation_seq_num = p_eam_op_comp_rec.operation_seq_num;
152 
153      IF nvl(to_number(l_shutdown_type),1) = 2 THEN
154 		  IF p_eam_op_comp_rec.shutdown_start_date IS NULL  OR p_eam_op_comp_rec.shutdown_end_date IS NULL THEN
155         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Op Comp : shutdown information  ...'); END IF;
156 
157 	            l_token_tbl(1).token_name  := 'OP_SEQ_NO';
158 	            l_token_tbl(1).token_value :=  p_eam_op_comp_rec.operation_seq_num;
159 
160 		    l_out_mesg_token_tbl  := l_mesg_token_tbl;
161 		    EAM_ERROR_MESSAGE_PVT.Add_Error_Token
162 		    (  p_message_name	=> 'EAM_OPCL_SHUTDOWN_REQUIRED'
163 		     , p_token_tbl		=> l_Token_tbl
164 		     , p_Mesg_Token_Tbl	=> l_Mesg_Token_Tbl
165 		     , x_Mesg_Token_Tbl	=> l_out_Mesg_Token_Tbl
166 		     );
167 		    x_mesg_token_tbl      := l_out_mesg_token_tbl;
168 
169 		    x_return_status := FND_API.G_RET_STS_ERROR;
170 		END IF;
171               END IF;
172         END IF;
173 
174 END Check_Required;
175 
176 
177 
178 PROCEDURE Check_Attributes
179    (
180 	p_eam_op_comp_rec      IN  EAM_PROCESS_WO_PUB. eam_op_comp_rec_type
181       , x_return_status        OUT NOCOPY  VARCHAR2
182       , x_mesg_token_tbl       OUT NOCOPY EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type
183    )IS
184         l_err_text              VARCHAR2(2000) := NULL;
185 	l_Mesg_Token_Tbl        EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
186 	l_out_Mesg_Token_Tbl    EAM_ERROR_MESSAGE_PVT.Mesg_Token_Tbl_Type;
187 	l_Token_Tbl             EAM_ERROR_MESSAGE_PVT.Token_Tbl_Type;
188 	l_open_acct_per_date    DATE;
189 	l_reconciliation_code   VARCHAR2(30);
190 	l_prev_uncomplete	NUMBER	:= 0;
191 	l_prev_completed_after  NUMBER  := 0;
192 	l_job_status		NUMBER;
193 	l_max_prior_end_date    DATE;
194 	l_shutdown_type		VARCHAR2(30);
195 
196 	CURSOR CON IS
197 	    select count(won.prior_operation)
198 	    from wip_operation_networks won
199 	    where
200 		won.wip_entity_id  = p_eam_op_comp_rec.wip_entity_id and
201 		won.next_operation = p_eam_op_comp_rec.operation_seq_num and
202 		exists (
203 			select 1 from wip_operations
204 			where
205 			    wip_entity_id = p_eam_op_comp_rec.wip_entity_id and
206 			    operation_seq_num = won.prior_operation and
207 			    nvl(operation_completed,'N') <> 'Y'
208 		);
209 
210 	CURSOR CON1 IS
211 	    select count(won.next_operation)
212 	    from wip_operation_networks won
213 	    where
214 		won.wip_entity_id = p_eam_op_comp_rec.wip_entity_id and
215 		won.prior_operation = p_eam_op_comp_rec.operation_seq_num and
216 		exists (
217 			select 1 from wip_operations
218 			where
219 			    wip_entity_id = p_eam_op_comp_rec.wip_entity_id and
220 			    operation_seq_num = won.next_operation and
221 			    operation_completed = 'Y'
222 		);
223 
224 	 --added for fix to bug 3543834:
225 	 CURSOR CON3 IS
226 	      select nvl(max(actual_end_date),sysdate-20000)
227 	      from eam_op_completion_txns eoct,wip_operation_networks won
228 	      where eoct.wip_entity_id = p_eam_op_comp_rec.wip_entity_id
229 	      and eoct.operation_seq_num=won.prior_operation
230 	      and won.wip_entity_id=eoct.wip_entity_id
231 	      and won.next_operation=p_eam_op_comp_rec.operation_seq_num
232 	      and transaction_type=1
233 	       and transaction_id = (select max(transaction_id)
234 				  from eam_op_completion_txns
235 				  where wip_entity_id = p_eam_op_comp_rec.wip_entity_id
236 					and operation_seq_num = eoct.operation_seq_num
237 					);
238 
239     BEGIN
240 
241     IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Operation Completeion Check Attributes'); END IF;
242 
243     x_return_status := FND_API.G_RET_STS_SUCCESS;
244 
245         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Checking actual start and end date  ...'); END IF;
246     BEGIN
247 	IF p_eam_op_comp_rec.actual_start_date  > p_eam_op_comp_rec.actual_end_date THEN
248 	    raise fnd_api.g_exc_unexpected_error;
249         END IF;
250 
251 	x_return_status := FND_API.G_RET_STS_SUCCESS;
252 
253     EXCEPTION
254       WHEN OTHERS THEN
255 	      l_token_tbl(1).token_name  := 'OP_SEQ_NO';
256 	      l_token_tbl(1).token_value :=  p_eam_op_comp_rec.operation_seq_num;
257 
258 	      l_out_mesg_token_tbl  := l_mesg_token_tbl;
259 	      EAM_ERROR_MESSAGE_PVT.Add_Error_Token
260 	      (  p_message_name  => 'EAM_OPCMPL_DATE_BAD'
261 	       , p_token_tbl     => l_token_tbl
262 	       , p_mesg_token_tbl     => l_mesg_token_tbl
263 	       , x_mesg_token_tbl     => l_out_mesg_token_tbl
264 	      );
265 	      l_mesg_token_tbl      := l_out_mesg_token_tbl;
266 
267 	      x_return_status := FND_API.G_RET_STS_ERROR;
268 	      x_mesg_token_tbl := l_mesg_token_tbl ;
269 	      RETURN;
270     END;
271 
272     BEGIN
273         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Checking shutdown start and end date  ...'); END IF;
274 	IF p_eam_op_comp_rec.shutdown_start_date  > p_eam_op_comp_rec.shutdown_end_date THEN
275 	    raise fnd_api.g_exc_unexpected_error;
276         END IF;
277 
278 	x_return_status := FND_API.G_RET_STS_SUCCESS;
279 
280     EXCEPTION
281       WHEN OTHERS THEN
282 	      l_token_tbl(1).token_name  := 'OP_SEQ_NO';
283 	      l_token_tbl(1).token_value :=  p_eam_op_comp_rec.operation_seq_num;
284 
285 	      l_out_mesg_token_tbl  := l_mesg_token_tbl;
286 	      EAM_ERROR_MESSAGE_PVT.Add_Error_Token
287 	      (  p_message_name  => 'EAM_OP_SHUTDOWN_DATE_BAD'
288 	       , p_token_tbl     => l_token_tbl
289 	       , p_mesg_token_tbl     => l_mesg_token_tbl
290 	       , x_mesg_token_tbl     => l_out_mesg_token_tbl
291 	      );
292 	      l_mesg_token_tbl      := l_out_mesg_token_tbl;
293 
294 	      x_return_status := FND_API.G_RET_STS_ERROR;
295 	      x_mesg_token_tbl := l_mesg_token_tbl ;
296 	      RETURN;
297     END;
298 
299         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Checking actual duration  ...'); END IF;
300     BEGIN
301 	IF p_eam_op_comp_rec.actual_duration < 0 THEN
302 	    raise fnd_api.g_exc_unexpected_error;
303        END IF;
304 
305        x_return_status := FND_API.G_RET_STS_SUCCESS;
306 
307     EXCEPTION
308       WHEN OTHERS THEN
309 	      l_token_tbl(1).token_name  := 'OP_SEQ_NO';
310 	      l_token_tbl(1).token_value :=  p_eam_op_comp_rec.operation_seq_num;
311 
312 	      l_out_mesg_token_tbl  := l_mesg_token_tbl;
313 	      EAM_ERROR_MESSAGE_PVT.Add_Error_Token
314 	      (  p_message_name  => 'EAM_OP_COMP_DURATION_BAD'
315 	       , p_token_tbl     => l_token_tbl
316 	       , p_mesg_token_tbl     => l_mesg_token_tbl
317 	       , x_mesg_token_tbl     => l_out_mesg_token_tbl
318 	      );
319 	      l_mesg_token_tbl      := l_out_mesg_token_tbl;
320 
321 	      x_return_status := FND_API.G_RET_STS_ERROR;
322 	      x_mesg_token_tbl := l_mesg_token_tbl ;
323 	      RETURN;
324     END;
325 
326         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Checking actual end date  ...'); END IF;
327     BEGIN
328 	IF p_eam_op_comp_rec.actual_end_date > sysdate THEN
329 	    raise fnd_api.g_exc_unexpected_error;
330        END IF;
331 
332        x_return_status := FND_API.G_RET_STS_SUCCESS;
333 
334     EXCEPTION
335       WHEN OTHERS THEN
336 
337 	      l_token_tbl(1).token_name  := 'OP_SEQ_NO';
338 	      l_token_tbl(1).token_value :=  p_eam_op_comp_rec.operation_seq_num;
339 
340 	      l_out_mesg_token_tbl  := l_mesg_token_tbl;
341 	      EAM_ERROR_MESSAGE_PVT.Add_Error_Token
342 	      (  p_message_name  => 'EAM_OP_END_LATER_THAN_TODAY'
343 	       , p_token_tbl     => l_token_tbl
344 	       , p_mesg_token_tbl     => l_mesg_token_tbl
345 	       , x_mesg_token_tbl     => l_out_mesg_token_tbl
346 	      );
347 	      l_mesg_token_tbl      := l_out_mesg_token_tbl;
348 
349 	      x_return_status := FND_API.G_RET_STS_ERROR;
350 	      x_mesg_token_tbl := l_mesg_token_tbl ;
351 	      RETURN;
352     END;
353 
354 --also added following code as part of bug 5476770
355     BEGIN
356 	IF p_eam_op_comp_rec.shutdown_end_date > sysdate THEN
357 	    raise fnd_api.g_exc_unexpected_error;
358     END IF;
359 
360     x_return_status := FND_API.G_RET_STS_SUCCESS;
361 
362     EXCEPTION
363       WHEN OTHERS THEN
364 
365 	      l_token_tbl(1).token_name  := 'OP_SEQ_NO';
366 	      l_token_tbl(1).token_value :=  p_eam_op_comp_rec.operation_seq_num;
367 
368 	      l_out_mesg_token_tbl  := l_mesg_token_tbl;
369 	      EAM_ERROR_MESSAGE_PVT.Add_Error_Token
370 	      (  p_message_name  => 'EAM_SHUTDOWN_DATE_IN_FUTURE'
371 	       , p_token_tbl     => l_token_tbl
372 	       , p_mesg_token_tbl     => l_mesg_token_tbl
373 	       , x_mesg_token_tbl     => l_out_mesg_token_tbl
374 	      );
375 	      l_mesg_token_tbl      := l_out_mesg_token_tbl;
376 
377 	      x_return_status := FND_API.G_RET_STS_ERROR;
378 	      x_mesg_token_tbl := l_mesg_token_tbl ;
379 	      RETURN;
380     END;
381 
382 --end of code as part of bug 5476770
383 
384 
385         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Checking open period ...'); END IF;
386     BEGIN
387       SELECT NVL(MIN(period_start_date), sysdate+1)
388         INTO l_open_acct_per_date
389         FROM org_acct_periods
390        WHERE organization_id = (select organization_id from wip_discrete_jobs where wip_entity_id = p_eam_op_comp_rec.wip_entity_id)
391          AND open_flag = 'Y';
392 
393 	IF sysdate < l_open_acct_per_date THEN  -- p_transaction_date < l_open_acct_per_date
394 	    raise fnd_api.g_exc_unexpected_error;
395         END IF;
396 
397         x_return_status := FND_API.G_RET_STS_SUCCESS;
398 
399     EXCEPTION
400       WHEN OTHERS THEN
401 
402 	      l_token_tbl(1).token_name  := 'OP_SEQ_NO';
403 	      l_token_tbl(1).token_value :=  p_eam_op_comp_rec.operation_seq_num;
404 
405 	      l_out_mesg_token_tbl  := l_mesg_token_tbl;
406 	      EAM_ERROR_MESSAGE_PVT.Add_Error_Token
407 	      (  p_message_name  => 'EAM_OP_TRANSACTION_DATE_INVALID'
408 	       , p_token_tbl     => l_token_tbl
409 	       , p_mesg_token_tbl     => l_mesg_token_tbl
410 	       , x_mesg_token_tbl     => l_out_mesg_token_tbl
411 	      );
412 	      l_mesg_token_tbl      := l_out_mesg_token_tbl;
413 
414 	      x_return_status := FND_API.G_RET_STS_ERROR;
415 	      x_mesg_token_tbl := l_mesg_token_tbl ;
416 	      RETURN;
417   END;
418 
419         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Checking reconciliation code ...'); END IF;
420   BEGIN
421 	IF p_eam_op_comp_rec.reconciliation_code  IS NOT NULL THEN
422 
423 	  SELECT ml.lookup_code
424             INTO l_reconciliation_code
425             FROM mfg_lookups ml			-- Fix for Bug 3509465
426            WHERE ml.lookup_type = 'WIP_EAM_RECONCILIATION_CODE'
427              AND ml.lookup_code = p_eam_op_comp_rec.reconciliation_code;
428 
429        END IF;
430 
431        x_return_status := FND_API.G_RET_STS_SUCCESS;
432 
433   EXCEPTION
434     WHEN NO_DATA_FOUND  THEN
435 
436 	      l_token_tbl(1).token_name  := 'OP_SEQ_NO';
437 	      l_token_tbl(1).token_value :=  p_eam_op_comp_rec.operation_seq_num;
438 
439 	      l_out_mesg_token_tbl  := l_mesg_token_tbl;
440 	      EAM_ERROR_MESSAGE_PVT.Add_Error_Token
441 	      (  p_message_name  => 'EAM_OP_RECONCILIATION_CODE'
442 	       , p_token_tbl     => l_token_tbl
443 	       , p_mesg_token_tbl     => l_mesg_token_tbl
444 	       , x_mesg_token_tbl     => l_out_mesg_token_tbl
445 	      );
446 	      l_mesg_token_tbl      := l_out_mesg_token_tbl;
447 
448 	      x_return_status := FND_API.G_RET_STS_ERROR;
449 	      x_mesg_token_tbl := l_mesg_token_tbl ;
450 	      RETURN;
451   END;
452 
453 
454   IF p_eam_op_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE THEN
455      BEGIN
456 	SELECT shutdown_type
457 	  INTO l_shutdown_type
458 	  FROM wip_operations
459 	 WHERE wip_entity_id    = p_eam_op_comp_rec.wip_entity_id
460 	  AND operation_seq_num = p_eam_op_comp_rec.operation_seq_num;
461 
462         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Checking shutdown start and end date ...'); END IF;
463 
464 	  IF l_shutdown_type IS NOT NULL AND to_number(l_shutdown_type) = 2 THEN
465 		IF p_eam_op_comp_rec.shutdown_start_date IS NULL OR p_eam_op_comp_rec.shutdown_end_date IS NULL THEN
466 		    raise fnd_api.g_exc_unexpected_error;
467 		END IF;
468 	  END IF;
469 
470 	  x_return_status := FND_API.G_RET_STS_SUCCESS;
471 
472      EXCEPTION
473         WHEN NO_DATA_FOUND  THEN
474 
475 	      l_token_tbl(1).token_name  := 'OP_SEQ_NO';
476 	      l_token_tbl(1).token_value :=  p_eam_op_comp_rec.operation_seq_num;
477 
478 	      l_out_mesg_token_tbl  := l_mesg_token_tbl;
479 	      EAM_ERROR_MESSAGE_PVT.Add_Error_Token
480 	      (  p_message_name  => 'EAM_OP_SHUTDOWN_DATE_MISS'
481 	       , p_token_tbl     => l_token_tbl
482 	       , p_mesg_token_tbl     => l_mesg_token_tbl
483 	       , x_mesg_token_tbl     => l_out_mesg_token_tbl
484 	      );
485 	      l_mesg_token_tbl      := l_out_mesg_token_tbl;
486 
487 	      x_return_status := FND_API.G_RET_STS_ERROR;
488 	      x_mesg_token_tbl := l_mesg_token_tbl ;
489 	      RETURN;
490      END;
491   END IF;
492 
493   IF p_eam_op_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UNCOMPLETE THEN
494 	BEGIN
495 	  open CON1;
496 	    fetch CON1 into l_prev_uncomplete;
497 	    if (CON1%NOTFOUND) then
498 		l_prev_uncomplete := 0;
499 	    end if;
500 	    close CON1;
501 
502         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Checking prev_uncomplete ...'); END IF;
503 	    IF l_prev_uncomplete > 0 THEN
504 		raise fnd_api.g_exc_unexpected_error;
505 	    END IF;
506 
507             x_return_status := FND_API.G_RET_STS_SUCCESS;
508 
509 	EXCEPTION
510           WHEN OTHERS THEN
511 
512 		--following 2 lines removed as part of bug 5440339
513 		--l_token_tbl(1).token_name  := 'OP_SEQ_NO';
514 	    --l_token_tbl(1).token_value :=  p_eam_op_comp_rec.operation_seq_num;
515 
516 	      l_out_mesg_token_tbl  := l_mesg_token_tbl;
517 	      EAM_ERROR_MESSAGE_PVT.Add_Error_Token
518 	      (  p_message_name  => 'EAM_NEXT_OP_COMPLETED'
519 	       , p_token_tbl     => l_token_tbl
520 	       , p_mesg_token_tbl     => l_mesg_token_tbl
521 	       , x_mesg_token_tbl     => l_out_mesg_token_tbl
522 	      );
523 	      l_mesg_token_tbl      := l_out_mesg_token_tbl;
524 
525 	      x_return_status := FND_API.G_RET_STS_ERROR;
526 	      x_mesg_token_tbl := l_mesg_token_tbl ;
527 	      RETURN;
528         END;
529   END IF;
530 
531   IF p_eam_op_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE THEN
532 	BEGIN
533 	   open CON;
534 	      fetch CON into l_prev_uncomplete;
535 	      if (CON%NOTFOUND) then
536 		l_prev_uncomplete := 0;
537 	      end if;
538 	   close CON;
539         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Checking prev_uncomplete ...'); END IF;
540 
541 	   IF l_prev_uncomplete > 0 THEN
542 		raise fnd_api.g_exc_unexpected_error;
543 	   END IF;
544 
545            x_return_status := FND_API.G_RET_STS_SUCCESS;
546 
547 	EXCEPTION
548            WHEN OTHERS THEN
549 
550 		--following 2 lines removed as part of bug 5440339
551 	    --l_token_tbl(1).token_name  := 'OP_SEQ_NO';
552 	    --l_token_tbl(1).token_value :=  p_eam_op_comp_rec.operation_seq_num;
553 
554 	      l_out_mesg_token_tbl  := l_mesg_token_tbl;
555 	      EAM_ERROR_MESSAGE_PVT.Add_Error_Token
556 	      (  p_message_name  => 'EAM_PREV_OP_NOT_COMPLETED'
557 	       , p_token_tbl     => l_token_tbl
558 	       , p_mesg_token_tbl     => l_mesg_token_tbl
559 	       , x_mesg_token_tbl     => l_out_mesg_token_tbl
560 	      );
561 	      l_mesg_token_tbl      := l_out_mesg_token_tbl;
562 
563 	      x_return_status := FND_API.G_RET_STS_ERROR;
564 	      x_mesg_token_tbl := l_mesg_token_tbl ;
565 	      RETURN;
566        END;
567   END IF;
568 
569   IF p_eam_op_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_UNCOMPLETE THEN
570       begin
571          SELECT status_type
572            INTO l_job_status
573            FROM wip_discrete_jobs
574           WHERE wip_entity_id = p_eam_op_comp_rec.wip_entity_id;
575         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Checking status_type ...'); END IF;
576 
577          IF (l_job_status = 4 ) THEN
578 		raise fnd_api.g_exc_unexpected_error;
579          END IF;
580 
581 	 x_return_status := FND_API.G_RET_STS_SUCCESS;
582 
583       EXCEPTION
584          WHEN OTHERS THEN
585 
586 	      l_token_tbl(1).token_name  := 'OP_SEQ_NO';
587 	      l_token_tbl(1).token_value :=  p_eam_op_comp_rec.operation_seq_num;
588 
589 	      l_out_mesg_token_tbl  := l_mesg_token_tbl;
590 	      EAM_ERROR_MESSAGE_PVT.Add_Error_Token
591 	      (  p_message_name  => 'EAM_OP_COMP_WOCOMP_TEST'
592 	       , p_token_tbl     => l_token_tbl
593 	       , p_mesg_token_tbl     => l_mesg_token_tbl
594 	       , x_mesg_token_tbl     => l_out_mesg_token_tbl
595 	      );
596 	      l_mesg_token_tbl      := l_out_mesg_token_tbl;
597 
598 	      x_return_status := FND_API.G_RET_STS_ERROR;
599 	      x_mesg_token_tbl := l_mesg_token_tbl ;
600 	      RETURN;
601        END;
602   END IF;
603 
604   IF p_eam_op_comp_rec.transaction_type = EAM_PROCESS_WO_PVT.G_OPR_COMPLETE THEN
605       BEGIN
606 		  open CON3;
607 			fetch CON3 into l_max_prior_end_date;
608 		  close CON3;
609         IF EAM_PROCESS_WO_PVT.Get_Debug = 'Y' THEN EAM_ERROR_MESSAGE_PVT.Write_Debug('Checking actual start date and max_prior_end_date ...'); END IF;
610 
611 		  if(p_eam_op_comp_rec.actual_start_date < l_max_prior_end_date) then
612 		     raise fnd_api.g_exc_unexpected_error;
613 		  end if;
614 
615 		  x_return_status := FND_API.G_RET_STS_SUCCESS;
616 
617       EXCEPTION
618 	       WHEN OTHERS THEN
619 		      l_token_tbl(1).token_name  := 'MIN_START_DATE';
620 		      l_token_tbl(1).token_value :=  TO_CHAR(l_max_prior_end_date,'dd-MON-yyyy HH24:MI:SS');
621 
622 		      l_out_mesg_token_tbl  := l_mesg_token_tbl;
623 		      EAM_ERROR_MESSAGE_PVT.Add_Error_Token
624 		      (  p_message_name  => 'EAM_PRIOR_OP_COMPLETED_AFTER'
625 		       , p_token_tbl     => l_token_tbl
626 		       , p_mesg_token_tbl     => l_mesg_token_tbl
627 		       , x_mesg_token_tbl     => l_out_mesg_token_tbl
628 		      );
629 		      l_mesg_token_tbl      := l_out_mesg_token_tbl;
630 
631 		      x_return_status := FND_API.G_RET_STS_ERROR;
632 		      x_mesg_token_tbl := l_mesg_token_tbl ;
633 		      RETURN;
634       END;
635   END IF;
636 
637  END Check_Attributes;
638 
639 END EAM_OP_COMP_VALIDATE_PVT;