DBA Data[Home] [Help]

PACKAGE BODY: APPS.BOM_RTG_NETWORK_API

Source


1 PACKAGE BODY BOM_RTG_NETWORK_API AS
2 /* $Header: BOMRNWKB.pls 120.2 2006/02/02 23:07:16 abbhardw ship $ */
3 
4 FUNCTION get_routing_sequence_id (
5 	p_assy_item_id      IN  NUMBER,
6 	p_org_id            IN  NUMBER,
7 	p_alt_rtg_desig     IN  VARCHAR2 DEFAULT NULL) RETURN NUMBER IS
8 
9 l_rtg_seq_id NUMBER := NULL;
10 
11 BEGIN
12 	select routing_sequence_id
13 	into   l_rtg_seq_id
14 	from   bom_operational_routings
15 	where  assembly_item_id = p_assy_item_id
16 	and    organization_id  = p_org_id
17 	and    NVL(alternate_routing_designator, 'NONE') =
18 				NVL(p_alt_rtg_desig, 'NONE');
19 
20 	return (l_rtg_seq_id);
21 
22 EXCEPTION WHEN NO_DATA_FOUND THEN
23 	return null;
24 END;
25 
26 FUNCTION find_line_op (
27 				p_line_op IN NUMBER,
28 				p_op_tbl  IN Op_Tbl_Type) RETURN BOOLEAN IS
29 i INTEGER;
30 BEGIN
31 	FOR i IN 1..p_op_tbl.COUNT LOOP
32 		if p_op_tbl(i).operation_seq_num = p_line_op then
33 		return (TRUE);
34 		end if;
35 	END LOOP;
36 	return (FALSE);
37 END find_line_op;
38 
39 FUNCTION check_network_exists (
40 				p_rtg_sequence_id IN NUMBER) RETURN BOOLEAN IS
41 net_exists NUMBER;
42 BEGIN
43 	select 1
44 	into   net_exists
45 	from dual
46 	where exists (select null
47 			from bom_operation_networks_v
48 			where routing_sequence_id = p_rtg_sequence_id
49 			and   operation_type = 3);
50 
51 	return (TRUE);
52 EXCEPTION WHEN NO_DATA_FOUND THEN
53 	return(FALSE);
54 END check_network_exists;
55 
56 PROCEDURE get_all_prior_line_ops (
57 	p_rtg_sequence_id 	IN  NUMBER,
58     p_assy_item_id      IN  NUMBER,
59     p_org_id            IN  NUMBER,
60     p_alt_rtg_desig     IN  VARCHAR2,
61     p_curr_line_op      IN  NUMBER,
62     x_Op_Tbl      		 IN OUT NOCOPY  Op_Tbl_Type ) IS
63 i INTEGER := 1;
64 l_rtg_seq_id NUMBER;
65 l_op_seq_id NUMBER;
66 l_op_seq_num NUMBER;
67 cursor all_prior_line_ops (c_line_op_id NUMBER) IS
68     select  from_op_seq_id operation_sequence_id
69     from bom_operation_networks
70     connect by prior from_op_seq_id = to_op_seq_id
71         and transition_type <> 3
72     start with to_op_seq_id = c_line_op_id
73         and transition_type <> 3;
74 cursor all_prior_line_ops2 IS
75 	select operation_sequence_id, operation_seq_num
76 	from   bom_operation_sequences
77 	where  routing_sequence_id = l_rtg_seq_id
78 	and    operation_seq_num < p_curr_line_op
79 	and    operation_type = 3
80 	and    nvl(eco_for_production,2) = 2
81 	and exists (select null
82 		from bom_operation_sequences
83 		where routing_sequence_id = l_rtg_seq_id
84 		and  operation_seq_num = p_curr_line_op
85 	        and    nvl(eco_for_production,2) = 2
86 		and  operation_type = 3);
87 BEGIN
88 	if p_rtg_sequence_id is not null then
89 		l_rtg_seq_id := p_rtg_sequence_id;
90 	else
91 		l_rtg_seq_id := get_routing_sequence_id (
92                         p_assy_item_id,
93                         p_org_id,
94                         p_alt_rtg_desig);
95 	end if;
96 
97 
98 	if  check_network_exists(l_rtg_seq_id)  then
99 		select operation_sequence_id
100 		into   l_op_seq_id
101 		from   bom_operation_sequences
102 		where  routing_sequence_id = l_rtg_seq_id
103 		and    operation_type = 3
104 	        and    nvl(eco_for_production,2) = 2
105 		and    operation_seq_num = p_curr_line_op;
106 
107         FOR all_prior_line_op_rec IN all_prior_line_ops(l_op_seq_id) LOOP
108 			select operation_seq_num
109 			into   l_op_seq_num
110 			from   bom_operation_sequences
111 			where  operation_sequence_id =
112 					all_prior_line_op_rec.operation_sequence_id;
113 
114 			if (NOT find_line_op (l_op_seq_num, x_Op_Tbl)) then
115 				x_Op_Tbl(i).operation_sequence_id :=
116 					all_prior_line_op_rec.operation_sequence_id;
117 				x_Op_Tbl(i).operation_seq_num := l_op_seq_num;
118 				i := i + 1;
119 			end if;
120         END LOOP;
121 	else
122 		FOR all_prior_line_op_rec2 IN all_prior_line_ops2 LOOP
123 			x_Op_Tbl(i).operation_sequence_id :=
124 				all_prior_line_op_rec2.operation_sequence_id;
125 			x_Op_Tbl(i).operation_seq_num :=
126 				all_prior_line_op_rec2.operation_seq_num;
127 			i := i + 1;
128 		END LOOP;
129 	end if;
130 EXCEPTION WHEN NO_DATA_FOUND THEN
131 	NULL;
132 END get_all_prior_line_ops;
133 
134 
135 PROCEDURE get_primary_prior_line_ops (
136 	p_rtg_sequence_id   IN NUMBER,
137     p_assy_item_id      IN  NUMBER,
138     p_org_id            IN  NUMBER,
139     p_alt_rtg_desig     IN  VARCHAR2,
140     p_curr_line_op      IN  NUMBER,
141     x_Op_Tbl            IN OUT NOCOPY Op_Tbl_Type ) IS
142 
143 i INTEGER := 1;
144 l_rtg_seq_id NUMBER;
145 l_transition_type NUMBER := 2;
146 l_last_alt_line_op NUMBER;
147 l_op_seq_num NUMBER;
148 l_op_seq_id  NUMBER;
149 cursor primary_prior_line_ops (c_line_op_id NUMBER) IS
150     select  from_op_seq_id operation_sequence_id
151     from bom_operation_networks
152     connect by prior from_op_seq_id = to_op_seq_id
153 		and transition_type NOT IN (2, 3)
154     start with to_op_seq_id = c_line_op_id
155 		and transition_type NOT IN (2, 3);
156 
157 cursor alt_prior_line_ops (c_line_op_id NUMBER) IS
158     select  from_op_seq_id operation_sequence_id
159     from bom_operation_networks
160     connect by prior from_op_seq_id = to_op_seq_id
161 				and  transition_type NOT IN (1, 3)
162     start with to_op_seq_id = c_line_op_id
163 				and  transition_type NOT IN (1, 3);
164 
165 cursor primary_prior_line_ops2 IS
166     select operation_sequence_id, operation_seq_num
167     from   bom_operation_sequences
168     where  routing_sequence_id = l_rtg_seq_id
169     and    operation_seq_num < p_curr_line_op
170     and    operation_type = 3
171     and    nvl(eco_for_production,2) = 2
172 	and exists (select null
173 		from bom_operation_sequences
174 		where routing_sequence_id = l_rtg_seq_id
175 		and   operation_seq_num = p_curr_line_op
176                 and    nvl(eco_for_production,2) = 2
177 		and   operation_type = 3);
178 
179 BEGIN
180 	if p_rtg_sequence_id is not null then
181 		l_rtg_seq_id := p_rtg_sequence_id;
182 	else
183 		l_rtg_seq_id := get_routing_sequence_id (
184 						p_assy_item_id,
185 						p_org_id,
186 						p_alt_rtg_desig);
187 	end if;
188 
189 	if check_network_exists(l_rtg_seq_id) then
190 	BEGIN
191 		select operation_sequence_id
192 		into   l_op_seq_id
193 		from   bom_operation_sequences
194 		where  routing_sequence_id = l_rtg_seq_id
195 		and    operation_type = 3
196 		and    operation_seq_num = p_curr_line_op;
197 
198 		select 1
199 		into   l_transition_type
200 		from   bom_operation_networks
201 		where  to_op_seq_id = l_op_seq_id
202 		and    transition_type = 1
203 		and    rownum =1 ;
204 
205 		FOR primary_line_op_rec IN primary_prior_line_ops(l_op_seq_id) LOOP
206 		select operation_seq_num
207 		into   l_op_seq_num
208 		from   bom_operation_sequences
209 		where  operation_sequence_id =
210 				primary_line_op_rec.operation_sequence_id;
211 		If (NOT find_line_op(l_op_seq_num, x_Op_Tbl)) then
212         x_Op_Tbl(i).operation_sequence_id :=
213 			primary_line_op_rec.operation_sequence_id;
214 		x_Op_Tbl(i).operation_seq_num := l_op_seq_num;
215         i := i + 1;
216 		end if;
217 		END LOOP;
218 	EXCEPTION WHEN NO_DATA_FOUND THEN
219 		FOR alt_line_op_rec IN alt_prior_line_ops(l_op_seq_id) LOOP
220 			select operation_seq_num
221 			into   l_op_seq_num
222 			from   bom_operation_sequences
223 			where  operation_sequence_id =
224 					alt_line_op_rec.operation_sequence_id;
225 
226 			if (NOT find_line_op(l_op_seq_num, x_Op_Tbl)) then
227 			x_Op_Tbl(i).operation_seq_num := l_op_seq_num;
228 			x_Op_Tbl(i).operation_sequence_id :=
229 				alt_line_op_rec.operation_sequence_id;
230 			i := i + 1;
231 			end if;
232 			l_last_alt_line_op := alt_line_op_rec.operation_sequence_id;
233 		END LOOP;
234 		FOR primary_line_op_rec IN
235 				primary_prior_line_ops(l_last_alt_line_op)
236 		 LOOP
237 			select operation_seq_num
238 			into   l_op_seq_num
239 			from   bom_operation_sequences
240 			where  operation_sequence_id =
241 					primary_line_op_rec.operation_sequence_id;
242 			 if (NOT find_line_op(l_op_seq_num, x_Op_Tbl)) then
243 				x_Op_Tbl(i).operation_seq_num := l_op_seq_num;
244 				x_Op_Tbl(i).operation_sequence_id :=
245 					primary_line_op_rec.operation_sequence_id;
246 				i := i + 1;
247 			end if;
248         END LOOP;
249 	END;
250 	else
251 	BEGIN
252 	 	FOR primary_prior_line_ops2_rec IN primary_prior_line_ops2 LOOP
253 			x_Op_Tbl(i).operation_seq_num :=
254 				primary_prior_line_ops2_rec.operation_seq_num;
255 			x_Op_Tbl(i).operation_sequence_id :=
256 				primary_prior_line_ops2_rec.operation_sequence_id;
257 			i := i + 1;
258 		END LOOP;
259 	END;
260 	end if;
261 EXCEPTION WHEN NO_DATA_FOUND THEN
262 	NULL;
263 END get_primary_prior_line_ops;
264 
265 PROCEDURE get_all_line_ops (
266 	p_rtg_sequence_id	IN  NUMBER,
267     p_assy_item_id      IN  NUMBER,
268     p_org_id            IN  NUMBER,
269     p_alt_rtg_desig     IN  VARCHAR2 DEFAULT NULL,
270     x_Op_Tbl     		 IN OUT NOCOPY  Op_Tbl_Type ) IS
271 
272 l_rtg_seq_id NUMBER := NULL;
273 I Integer := 1;
274 /*Cursor all_line_ops  is
275 	select from_seq_num operation_seq_num ,
276 		   from_op_seq_id operation_sequence_id
277 	from bom_operation_networks_v
278 	where routing_sequence_id = l_rtg_seq_id
279 	and   operation_type = 3
280 	and   transition_type <> 3
281 	union
282 	select bonv.to_seq_num operation_seq_num,
283 		   to_op_seq_id operation_sequence_id
284 	from bom_operation_networks_v bonv
285 	where routing_sequence_id = l_rtg_seq_id
286 	and   operation_type = 3
287 	and not exists (select null
288 		from bom_operation_networks_v net
289 		where bonv.to_op_seq_id = net.from_op_seq_id
290 		and   transition_type <> 3
291 		and net.routing_sequence_id = l_rtg_seq_id);
292 */
293 -- Replaced the sql for the cursor above with the one below for better performance BUG 4929600
294 Cursor all_line_ops  is
295 	select  bos1.operation_seq_num operation_seq_num ,
296                 bon1.from_op_seq_id operation_sequence_id
297 	from bom_operation_networks bon1 ,bom_operation_sequences bos1
298 	where bos1.routing_sequence_id = l_rtg_seq_id
299 		and bos1.operation_type = 3
300 		and bon1.transition_type <> 3
301 		and bon1.from_op_seq_id = bos1.operation_sequence_id
302 	union
303 	select bos2.operation_seq_num operation_seq_num,
304 		bon2.to_op_seq_id operation_sequence_id
305 	from bom_operation_networks bon2, bom_operation_sequences bos2
306 	where bos2.routing_sequence_id = l_rtg_seq_id
307 		and bos2.operation_type = 3
308 		and bon2.to_op_seq_id = bos2.operation_sequence_id
309 	and not exists ( select null
310 		from bom_operation_networks net ,bom_operation_sequences bos3
311 		where bon2.to_op_seq_id = net.from_op_seq_id
312 		     and net.transition_type <> 3
313 		     and bos3.routing_sequence_id = l_rtg_seq_id
314 		     and net.from_op_seq_id = bos3.operation_sequence_id );
315 cursor all_line_ops2 IS
316     select operation_sequence_id, operation_seq_num
317     from   bom_operation_sequences
318     where  routing_sequence_id = l_rtg_seq_id
319     and    nvl(eco_for_production,2) = 2
320     and    operation_type = 3;
321 
322 BEGIN
323 	if p_rtg_sequence_id is not null then
324 		l_rtg_seq_id := p_rtg_sequence_id;
325 	else
326 		l_rtg_seq_id := get_routing_sequence_id (
327 						p_assy_item_id,
328 						p_org_id,
329 						p_alt_rtg_desig);
330 	end if;
331 
332 	if check_network_exists(l_rtg_seq_id) then
333 		FOR line_op_rec IN all_line_ops LOOP
334 			x_Op_Tbl(I).operation_seq_num := line_op_rec.operation_seq_num;
335 			x_Op_Tbl(I).operation_sequence_id :=
336 				line_op_rec.operation_sequence_id;
337 			I := I + 1;
338 		END LOOP;
339 	else
340 		FOR all_line_ops2_rec IN all_line_ops2 LOOP
341 			x_Op_Tbl(I).operation_seq_num :=
342 				all_line_ops2_rec.operation_seq_num;
343 			x_Op_Tbl(I).operation_sequence_id :=
344 				all_line_ops2_rec.operation_sequence_id;
345 			i := i + 1;
346 		END LOOP;
347 	end if;
348 END get_all_line_ops;
349 
350 PROCEDURE get_all_primary_line_ops (
351 	p_rtg_sequence_id	IN  NUMBER,
352     p_assy_item_id      IN  NUMBER,
353     p_org_id            IN  NUMBER,
354     p_alt_rtg_desig     IN  VARCHAR2,
355     x_Op_Tbl     		 IN OUT NOCOPY  Op_Tbl_Type ) IS
356 
357 l_rtg_seq_id NUMBER := NULL;
358 I Integer := 1;
359 /*Cursor all_primary_line_ops  is
360     select from_seq_num operation_seq_num ,
361            from_op_seq_id operation_sequence_id
362     from bom_operation_networks_v
363     where routing_sequence_id = l_rtg_seq_id
364 	and   transition_type = 1
365     and   operation_type = 3
366     union
367     select bonv.to_seq_num operation_seq_num,
368            to_op_seq_id operation_sequence_id
369     from bom_operation_networks_v bonv
370     where routing_sequence_id = l_rtg_seq_id
371 	and   transition_type = 1
372     and   operation_type = 3
373     and not exists (select null
374         from bom_operation_networks_v net
375         where bonv.to_op_seq_id = net.from_op_seq_id
376 		and transition_type <> 3
377         and net.routing_sequence_id = l_rtg_seq_id);
378 */
379 -- Replaced the sql for the cursor above with the one below for better performance BUG 4929600
380 Cursor all_primary_line_ops is
381     select bos1.operation_seq_num operation_seq_num ,
382            bon1.from_op_seq_id operation_sequence_id
383     from bom_operation_networks bon1 ,bom_operation_sequences bos1
384     where bos1.routing_sequence_id = l_rtg_seq_id
385 	   and bon1.transition_type = 1
386 	   and bos1.operation_type = 3
387 	   and bon1.from_op_seq_id = bos1.operation_sequence_id
388     union
389     select bos2.operation_seq_num operation_seq_num,
390            bon2.to_op_seq_id operation_sequence_id
391     from bom_operation_networks bon2, bom_operation_sequences bos2
392     where bos2.routing_sequence_id = l_rtg_seq_id
393 	   and bon2.transition_type = 1
394 	   and bos2.operation_type = 3
395 	   and bon2.to_op_seq_id = bos2.operation_sequence_id
396     and not exists ( select null
397            from bom_operation_networks net ,bom_operation_sequences bos3
398            where bon2.to_op_seq_id = net.from_op_seq_id
399 		and net.transition_type <> 3
400 		and bos3.routing_sequence_id = l_rtg_seq_id
401 		and net.from_op_seq_id = bos3.operation_sequence_id );
402 
403 cursor all_primary_line_ops2 IS
404     select operation_sequence_id, operation_seq_num
405     from   bom_operation_sequences
406     where  routing_sequence_id = l_rtg_seq_id
407     and    nvl(eco_for_production,2) = 2
408     and    operation_type = 3;
409 
410 BEGIN
411 	if p_rtg_sequence_id is not null then
412 		l_rtg_seq_id := p_rtg_sequence_id;
413 	else
414 		l_rtg_seq_id := get_routing_sequence_id (
415                         p_assy_item_id,
416                         p_org_id,
417                         p_alt_rtg_desig);
418  	end if;
419 	if check_network_exists(l_rtg_seq_id) then
420 		FOR line_op_rec IN all_primary_line_ops LOOP
421 			x_Op_Tbl(I).operation_seq_num := line_op_rec.operation_seq_num;
422 			x_Op_Tbl(I).operation_sequence_id :=
423 				line_op_rec.operation_sequence_id;
424 			I := I + 1;
425 		END LOOP;
426 	else
427 		FOR all_primary_line_ops2_rec IN all_primary_line_ops2 LOOP
431 				all_primary_line_ops2_rec.operation_sequence_id;
428 			x_Op_Tbl(I).operation_seq_num :=
429 				all_primary_line_ops2_rec.operation_seq_num;
430 			x_Op_Tbl(I).operation_sequence_id :=
432 			I := I + 1;
433 		END LOOP;
434 	end if;
435 
436 END get_all_primary_line_ops;
437 
438 PROCEDURE get_all_next_line_ops (
439 	p_rtg_sequence_id	IN 	NUMBER,
440     p_assy_item_id      IN  NUMBER,
441     p_org_id            IN  NUMBER,
442     p_alt_rtg_desig     IN  VARCHAR2,
443     p_curr_line_op      IN  NUMBER,
444     x_Op_Tbl      		 IN OUT NOCOPY  Op_Tbl_Type ) IS
445 i INTEGER := 1;
446 l_rtg_seq_id NUMBER;
447 l_op_seq_id NUMBER;
448 l_op_seq_num NUMBER;
449 cursor all_next_line_ops (c_line_op_id NUMBER) IS
450     select  to_op_seq_id operation_sequence_id
451     from bom_operation_networks
452     connect by prior to_op_seq_id = from_op_seq_id
453         and transition_type <> 3
454     start with from_op_seq_id = c_line_op_id
455         and transition_type <> 3;
456 cursor all_next_line_ops2 IS
457     select operation_sequence_id, operation_seq_num
458     from   bom_operation_sequences
459     where  routing_sequence_id = l_rtg_seq_id
460 	and    operation_seq_num > p_curr_line_op
461     and    nvl(eco_for_production,2) = 2
462     and    operation_type = 3
463 	and exists (select null
464 		from   bom_operation_sequences
465 		where  routing_sequence_id = l_rtg_seq_id
466 		and    operation_seq_num = p_curr_line_op
467 		and    operation_type = 3);
468 
469 BEGIN
470 	if p_rtg_sequence_id is not null then
471 		l_rtg_seq_id := p_rtg_sequence_id;
472 	else
473 		l_rtg_seq_id := get_routing_sequence_id (
474                         p_assy_item_id,
475                         p_org_id,
476                         p_alt_rtg_desig);
477 	end if;
478 
479 	if check_network_exists(l_rtg_seq_id) then
480 		select operation_sequence_id
481 		into   l_op_seq_id
482 		from   bom_operation_sequences
483 		where  routing_sequence_id = l_rtg_seq_id
484 		and    operation_type = 3
485 		and    operation_seq_num = p_curr_line_op;
486 
487         FOR all_next_line_op_rec IN all_next_line_ops(l_op_seq_id) LOOP
488 			select operation_seq_num
489 			into   l_op_seq_num
490 			from   bom_operation_sequences
491 			where  operation_sequence_id =
492 					all_next_line_op_rec.operation_sequence_id;
493 			if (NOT find_line_op (l_op_seq_num, x_Op_Tbl)) then
494 				x_Op_Tbl(i).operation_sequence_id :=
495 					all_next_line_op_rec.operation_sequence_id;
496 				x_Op_Tbl(i).operation_seq_num := l_op_seq_num;
497 				i := i + 1;
498 			end if;
499         END LOOP;
500 	else
501 		FOR all_next_line_ops2_rec IN all_next_line_ops2 LOOP
502 			x_Op_Tbl(i).operation_sequence_id :=
503 				all_next_line_ops2_rec.operation_sequence_id;
504 			 x_Op_Tbl(i).operation_seq_num :=
505 				all_next_line_ops2_rec.operation_seq_num;
506 			i := i + 1;
507 		END LOOP;
508 	end if;
509 EXCEPTION WHEN NO_DATA_FOUND THEN
510 	null;
511 END get_all_next_line_ops;
512 
513 FUNCTION get_next_line_operation (
514 	p_rtg_sequence_id 	IN 	NUMBER,
515     p_assy_item_id      IN  NUMBER,
516     p_org_id            IN  NUMBER,
517     p_alt_rtg_desig     IN  VARCHAR2,
518     p_curr_line_op      IN  NUMBER ) RETURN NUMBER IS
519 
520 l_rtg_seq_id NUMBER;
521 next_line_op NUMBER := NULL;
522 BEGIN
523 	if p_rtg_sequence_id is not null then
524 		l_rtg_seq_id := p_rtg_sequence_id;
525 	else
526 		l_rtg_seq_id := get_routing_sequence_id (
527 						p_assy_item_id,
528 						p_org_id,
529 						p_alt_rtg_desig );
530 	end if;
531 
532 	if check_network_exists(l_rtg_seq_id) then
533 	BEGIN
534 		select to_seq_num
535 		into   next_line_op
536 		from   bom_operation_networks_v
537 		where  routing_sequence_id = l_rtg_seq_id
538 		and    operation_type = 3
539 		and    from_seq_num = p_curr_line_op
540 		and    transition_type = 1;
541 
542 		return (next_line_op);
543 
544 	EXCEPTION WHEN NO_DATA_FOUND THEN
545 		BEGIN
546 			select min(to_seq_num)
547 			into   next_line_op
548 			from   bom_operation_networks_v
549 			where  routing_sequence_id = l_rtg_seq_id
550 			and    operation_type = 3
551 			and    from_seq_num = p_curr_line_op
552 			and    transition_type = 2;
553 
554 			return (next_line_op);
555 
556 		EXCEPTION WHEN NO_DATA_FOUND THEN
557 			return (NULL);
558 		END;
559 	END;
560 	else
561 	BEGIN
562 		select MIN(operation_seq_num)
563 		into   next_line_op
564 		from   bom_operation_sequences
565 		where  routing_sequence_id = l_rtg_seq_id
566 		and    operation_type = 3
567                 and    nvl(eco_for_production,2) = 2
568 		and    operation_seq_num > p_curr_line_op
569 		and    exists (select null
570 					from bom_operation_sequences
571 					where routing_sequence_id = l_rtg_seq_id
572 					and   operation_type = 3
573 					and   operation_seq_num = p_curr_line_op);
574 
575 		return (next_line_op);
576 
577 	EXCEPTION WHEN NO_DATA_FOUND THEN
578 		return (NULL);
579 	END;
580 	end if;
581 END get_next_line_operation;
582 
583 FUNCTION check_last_line_op (
584 	p_rtg_sequence_id	IN  NUMBER,
585     p_assy_item_id      IN  NUMBER,
586     p_org_id            IN  NUMBER,
587     p_alt_rtg_desig     IN  VARCHAR2,
588     p_curr_line_op      IN  NUMBER ) RETURN BOOLEAN IS
589 
590 l_rtg_seq_id NUMBER;
591 l_last_op NUMBER;
592 
593 BEGIN
594 
595 	if p_rtg_sequence_id is not null then
596 		l_rtg_seq_id := p_rtg_sequence_id;
597 	else
598 		l_rtg_seq_id := get_routing_sequence_id (
599 						p_assy_item_id,
600 						p_org_id,
601 						p_alt_rtg_desig );
602 	end if;
603 
604 	if check_network_exists (l_rtg_seq_id) then
605 	BEGIN
606 		select 1
607 		into   l_last_op
608 		from dual
609 		where not exists (select null
610 					from  bom_operation_networks_v
611 					where from_seq_num = p_curr_line_op
612 					and   operation_type = 3
613 					and   transition_type <> 3
614 					and   routing_sequence_id = l_rtg_seq_id)
615 		and exists (select null
616 				from   bom_operation_networks_v
617 				where  to_seq_num = p_curr_line_op
618 				and   transition_type <> 3
619 				and    operation_type = 3
620 				and    routing_sequence_id = l_rtg_seq_id);
621 		return (TRUE);
622 
623 	EXCEPTION WHEN NO_DATA_FOUND THEN
624 		return (FALSE);
625 	END;
626 	else
627 	BEGIN
628 		select 1
629 		into   l_last_op
630 		from dual
631 		where not exists (select null
632 				from bom_operation_sequences
633 				where routing_sequence_id = l_rtg_seq_id
634 				and   operation_type = 3
635                                 and    nvl(eco_for_production,2) = 2
636 				and   operation_seq_num > p_curr_line_op)
637 			and exists (select null
638 				from   bom_operation_sequences
639 				where  routing_sequence_id = l_rtg_seq_id
640 				and    operation_type = 3
641 				and    operation_seq_num = p_curr_line_op);
642 
643 		return (TRUE);
644 	EXCEPTION WHEN NO_DATA_FOUND THEN
645 		return (FALSE);
646 	END;
647 	end if;
648 
649 END check_last_line_op;
650 
651 END BOM_RTG_NETWORK_API;