DBA Data[Home] [Help]

PACKAGE BODY: APPS.WSH_FTE_CONSTRAINT_FRAMEWORK

Source


1 PACKAGE BODY WSH_FTE_CONSTRAINT_FRAMEWORK as
2 /* $Header: WSHFCFWB.pls 120.11.12010000.2 2010/01/22 08:57:48 gbhargav ship $ */
3 
4 -- Global Variables
5 
6     G_PKG_NAME CONSTANT VARCHAR2(30) := 'WSH_FTE_CONSTRAINT_FRAMEWORK';
7 
8     g_itm_mustuse_cache		item_item_mustuse_tab_type ;
9     g_itmloc_mustuse_cache	item_location_mustuse_tab_type;
10     g_itm_exclusive_cache	item_exclusive_tab_type;
11     g_fac_exclusive_cache	fac_exclusive_tab_type;
12 
13     g_customer_mustuse_location		    WSH_UTIL_CORE.id_tab_type;
14     g_location_mustuse_location		    WSH_UTIL_CORE.id_tab_type;
15     g_org_mustuse_location		        WSH_UTIL_CORE.id_tab_type;
16     g_region_mustuse_constraints        WSH_UTIL_CORE.id_tab_type;
17     g_region_mustuse_location           WSH_UTIL_CORE.id_tab_type;
18 
19     --#REG-ZON
20     -- Region Constraint Cache used for iterating purpose.
21     g_reg_const_cache           comp_constraint_tab_type;
22     g_regloc_loc_cache	        loc_reg_constraint_tab_type;
23     --#REG-ZON
24 
25     g_unexp_char		VARCHAR2(30) := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
26     g_unexp_num			NUMBER       := -999999;
27 
28     --#REG-ZON
29     g_const_not_present		    NUMBER := -9999;
30     g_incl_cons_not_present     NUMBER := -1111;
31     g_loc_reg_not_validated     NUMBER := -3333;
32     l_reg_hash_base             NUMBER := 1;
33     l_reg_hash_size             NUMBER := power(2, 25);
34      --#REG-ZON
35 
36     --Cache size constant
37     g_cache_max_size		NUMBER := power(2,31);
38     --
39 
40     --Cache for retriving Customer/Supplier/Carrier/Organization from locations.
41     --g_customer_from_location		WSH_UTIL_CORE.id_tab_type;
42     g_customer_from_location            WSH_UTIL_CORE.tbl_varchar;
43     g_supplier_from_location		WSH_UTIL_CORE.id_tab_type;
44     g_carrier_from_location		WSH_UTIL_CORE.id_tab_type;
45     g_loc_from_org			WSH_UTIL_CORE.id_tab_type;
46     g_organization_from_location	WSH_UTIL_CORE.tbl_varchar;
47 
48     --
49 
50     g_get_carrier_failed                EXCEPTION;
51     g_get_customer_failed               EXCEPTION;
52     g_get_supplier_failed               EXCEPTION;
53     g_get_mast_org_failed               EXCEPTION;
54     g_get_carrmode_failed               EXCEPTION;
55     g_get_vehicletype_failed            EXCEPTION;
56 
57 
58 
59     CURSOR c_get_trip_details(c_trip_id IN NUMBER) IS
60     SELECT wdd.DELIVERY_DETAIL_ID
61       , wdl.DELIVERY_ID
62       , 'Y'
63       , wdd.CUSTOMER_ID
64       , wdd.INVENTORY_ITEM_ID
65       , wdd.SHIP_FROM_LOCATION_ID
66       , wdd.ORGANIZATION_ID
67       , wdd.SHIP_TO_LOCATION_ID
68       , wdd.INTMED_SHIP_TO_LOCATION_ID
69       , wdd.RELEASED_STATUS
70       , wdd.CONTAINER_FLAG
71       , wdd.DATE_REQUESTED
72       , wdd.DATE_SCHEDULED
73       , wdd.SHIP_METHOD_CODE
74       , wdd.CARRIER_ID
75       , wdd.PARTY_ID
76       , nvl(wdd.LINE_DIRECTION,'O')
77       , nvl(wdd.SHIPPING_CONTROL,'BUYER')
78       , NULL -- AGDUMMY
79     FROM wsh_delivery_details wdd,
80          wsh_delivery_assignments_v wda,
81          wsh_delivery_legs wdl,
82          wsh_trip_stops wts1
83     WHERE wdd.delivery_detail_id = wda.delivery_detail_id
84     AND   nvl(wdd.shipping_control,'BUYER') <> 'SUPPLIER'
85     AND   wda.delivery_id = wdl.delivery_id
86     AND   wdl.pick_up_stop_id = wts1.stop_id
87     AND   wts1.trip_id = c_trip_id;
88 
89 
90     CURSOR c_get_trip_details_std(c_trip_id IN NUMBER) IS
91     SELECT wdd.DELIVERY_DETAIL_ID
92       , wdl.DELIVERY_ID
93       , 'Y'
94       , wdd.CUSTOMER_ID
95       , wdd.INVENTORY_ITEM_ID
96       , wdd.SHIP_FROM_LOCATION_ID
97       , wdd.ORGANIZATION_ID
98       , wdd.SHIP_TO_LOCATION_ID
99       , wdd.INTMED_SHIP_TO_LOCATION_ID
100       , wdd.RELEASED_STATUS
101       , wdd.CONTAINER_FLAG
102       , wdd.DATE_REQUESTED
103       , wdd.DATE_SCHEDULED
104       , wdd.SHIP_METHOD_CODE
105       , wdd.CARRIER_ID
106       , wdd.PARTY_ID
107       , nvl(wdd.LINE_DIRECTION,'O')
108       , nvl(wdd.SHIPPING_CONTROL,'BUYER')
109       , NULL -- AGDUMMY
110     FROM wsh_delivery_details wdd,
111          wsh_delivery_assignments_v wda,
112          wsh_delivery_legs wdl,
113          wsh_trip_stops wts1,
114          wsh_new_deliveries wnd
115     WHERE wdd.delivery_detail_id = wda.delivery_detail_id
116     AND   nvl(wdd.shipping_control,'BUYER') <> 'SUPPLIER'
117     AND   wda.delivery_id = wdl.delivery_id
118     AND   wdl.pick_up_stop_id = wts1.stop_id
119     AND   wts1.trip_id = c_trip_id
120     AND   wnd.delivery_id = wdl.delivery_id
121     AND   wnd.delivery_type = 'STANDARD';
122 
123     CURSOR c_get_trip_details_consol(c_trip_id IN NUMBER) IS
124     SELECT wdd.DELIVERY_DETAIL_ID
125       , wdl1.DELIVERY_ID
126       , 'Y'
127       , wdd.CUSTOMER_ID
128       , wdd.INVENTORY_ITEM_ID
129       , wdd.SHIP_FROM_LOCATION_ID
130       , wdd.ORGANIZATION_ID
131       , wdd.SHIP_TO_LOCATION_ID
132       , wdd.INTMED_SHIP_TO_LOCATION_ID
133       , wdd.RELEASED_STATUS
134       , wdd.CONTAINER_FLAG
135       , wdd.DATE_REQUESTED
136       , wdd.DATE_SCHEDULED
137       , wdd.SHIP_METHOD_CODE
138       , wdd.CARRIER_ID
139       , wdd.PARTY_ID
140       , nvl(wdd.LINE_DIRECTION,'O')
141       , nvl(wdd.SHIPPING_CONTROL,'BUYER')
142       , NULL -- AGDUMMY
143     FROM wsh_delivery_details wdd,
144          wsh_delivery_assignments_v wda,
145          wsh_trip_stops wts1,
146          wsh_delivery_legs wdl1,
147          wsh_delivery_legs wdl2,
148          wsh_new_deliveries wnd
149     WHERE wdd.delivery_detail_id = wda.delivery_detail_id
150     AND   nvl(wdd.shipping_control,'BUYER') <> 'SUPPLIER'
151     AND   wda.delivery_id = wdl1.delivery_id
152     AND   wdl1.parent_delivery_leg_id = wdl2.delivery_leg_id
153     AND   wdl2.pick_up_stop_id = wts1.stop_id
154     AND   wts1.trip_id = c_trip_id
155     AND   wnd.delivery_id = wdl2.delivery_id
156     AND   wnd.delivery_type = 'CONSOLIDATION';
157 
158     CURSOR c_get_trip_dlvy(c_trip_id IN NUMBER) IS
159     SELECT wnd.DELIVERY_ID
160       , c_trip_id
161       , 'Y'
162       , wnd.NAME
163       , wnd.PLANNED_FLAG
164       , wnd.STATUS_CODE
165       , wnd.INITIAL_PICKUP_DATE
166       , wnd.INITIAL_PICKUP_LOCATION_ID
167       , wnd.ULTIMATE_DROPOFF_LOCATION_ID
168       , wnd.ULTIMATE_DROPOFF_DATE
169       , wnd.CUSTOMER_ID
170       , wnd.INTMED_SHIP_TO_LOCATION_ID
171       , wnd.SHIP_METHOD_CODE
172       , wnd.DELIVERY_TYPE
173       , wnd.CARRIER_ID
174       , wnd.ORGANIZATION_ID
175       , wnd.SERVICE_LEVEL
176       , wnd.MODE_OF_TRANSPORT
177       , wnd.PARTY_ID
178       , nvl(wnd.SHIPMENT_DIRECTION,'O')
179       , nvl(wnd.SHIPPING_CONTROL,'BUYER')
180       , NULL -- AGDUMMY
181     FROM wsh_new_deliveries wnd,
182          wsh_delivery_legs wdl,
183          wsh_trip_stops wts1
184     WHERE wnd.delivery_id = wdl.delivery_id
185     AND   wdl.pick_up_stop_id = wts1.stop_id
186     AND   nvl(wnd.shipping_control,'BUYER') <> 'SUPPLIER'
187     AND   wts1.trip_id = c_trip_id;
188 
189     CURSOR c_get_trip_stops(c_tripid IN NUMBER) is
190     SELECT wts.STOP_ID
191       , 'Y' as exists_in_database
192       , wts.TRIP_ID
193       --To handle dummy locations #DUM_LOC(S)
194       , NVL(wts.PHYSICAL_LOCATION_ID,wts.STOP_LOCATION_ID)
195       , wts.STATUS_CODE
196       , wts.STOP_SEQUENCE_NUMBER
197       , wts.PLANNED_ARRIVAL_DATE
198       , wts.PLANNED_DEPARTURE_DATE
199       , wts.ACTUAL_ARRIVAL_DATE
200       , wts.ACTUAL_DEPARTURE_DATE
201       --#DUM_LOC(S)
202       , wts.PHYSICAL_LOCATION_ID
203       --#DUM_LOC(E)
204       --#SBAKSHI
205       , wts.PHYSICAL_STOP_ID
206     FROM wsh_trip_stops wts
207     WHERE wts.trip_id = c_tripid
208     order by wts.PLANNED_ARRIVAL_DATE;
209 
210     CURSOR c_get_dlvy(c_delivery_id IN NUMBER) IS
211     SELECT wnd.DELIVERY_ID
212       , NULL
213       , 'Y'
214       , wnd.NAME
215       , wnd.PLANNED_FLAG
216       , wnd.STATUS_CODE
217       , wnd.INITIAL_PICKUP_DATE
218       , wnd.INITIAL_PICKUP_LOCATION_ID
219       , wnd.ULTIMATE_DROPOFF_LOCATION_ID
220       , wnd.ULTIMATE_DROPOFF_DATE
221       , wnd.CUSTOMER_ID
222       , wnd.INTMED_SHIP_TO_LOCATION_ID
223       , wnd.SHIP_METHOD_CODE
224       , wnd.DELIVERY_TYPE
225       , wnd.CARRIER_ID
226       , wnd.ORGANIZATION_ID
227       , wnd.SERVICE_LEVEL
228       , wnd.MODE_OF_TRANSPORT
229       , wnd.PARTY_ID
230       , nvl(wnd.SHIPMENT_DIRECTION,'O')
231       , nvl(wnd.SHIPPING_CONTROL,'BUYER')
232       , NULL  -- AGDUMMY
233     FROM wsh_new_deliveries wnd
234     WHERE wnd.delivery_id = c_delivery_id;
235 
236     CURSOR c_get_details(c_delivery_id IN NUMBER) IS
237     SELECT wdd.DELIVERY_DETAIL_ID
238       , wda.DELIVERY_ID
239       , 'Y'
240       , wdd.CUSTOMER_ID
241       , wdd.INVENTORY_ITEM_ID
242       , wdd.SHIP_FROM_LOCATION_ID
243       , wdd.ORGANIZATION_ID
244       , wdd.SHIP_TO_LOCATION_ID
245       , wdd.INTMED_SHIP_TO_LOCATION_ID
246       , wdd.RELEASED_STATUS
247       , wdd.CONTAINER_FLAG
248       , wdd.DATE_REQUESTED
249       , wdd.DATE_SCHEDULED
250       , wdd.SHIP_METHOD_CODE
251       , wdd.CARRIER_ID
252       , wdd.PARTY_ID
253       , nvl(wdd.LINE_DIRECTION,'O')
254       , nvl(wdd.SHIPPING_CONTROL,'BUYER')
255       , NULL --AGDUMMY
256     FROM wsh_delivery_details wdd,
257          wsh_delivery_assignments_v wda
258     WHERE wdd.delivery_detail_id = wda.delivery_detail_id
259     AND   nvl(wdd.shipping_control,'BUYER') <> 'SUPPLIER'
260     AND   wda.delivery_id = c_delivery_id;
261 
262 
263     CURSOR c_get_details_consol(c_delivery_id IN NUMBER) IS
264     SELECT wdd.DELIVERY_DETAIL_ID
265       , wda.DELIVERY_ID
266       , 'Y'
267       , wdd.CUSTOMER_ID
268       , wdd.INVENTORY_ITEM_ID
269       , wdd.SHIP_FROM_LOCATION_ID
270       , wdd.ORGANIZATION_ID
271       , wdd.SHIP_TO_LOCATION_ID
272       , wdd.INTMED_SHIP_TO_LOCATION_ID
273       , wdd.RELEASED_STATUS
274       , wdd.CONTAINER_FLAG
275       , wdd.DATE_REQUESTED
276       , wdd.DATE_SCHEDULED
277       , wdd.SHIP_METHOD_CODE
278       , wdd.CARRIER_ID
279       , wdd.PARTY_ID
280       , nvl(wdd.LINE_DIRECTION,'O')
281       , nvl(wdd.SHIPPING_CONTROL,'BUYER')
282       , NULL --AGDUMMY
283     FROM wsh_delivery_details wdd,
284          wsh_delivery_assignments_v wda,
285          wsh_delivery_legs wdl1,
286          wsh_delivery_legs wdl2
287     WHERE wdd.delivery_detail_id = wda.delivery_detail_id
288     AND   nvl(wdd.shipping_control,'BUYER') <> 'SUPPLIER'
289     AND   wda.delivery_id = wdl1.delivery_id --c_delivery_id
290     AND   wdl1.parent_delivery_leg_id = wdl2.delivery_leg_id
291     AND   wdl2.delivery_id = c_delivery_id
292     AND   wda.delivery_id is not null;
293 
294     CURSOR c_get_stop_location(c_stop_id IN NUMBER) IS
295 	   --#DUM_LOC(S)
296     SELECT nvl(wts.physical_location_id,wts.stop_location_id),
297 	   --#DUM_LOC(E)
298 	   wts.stop_sequence_number,wts.planned_arrival_date
299     FROM   wsh_trip_stops wts
300     WHERE  wts.stop_id = c_stop_id
301     order by wts.planned_arrival_date;
302 
303     -- AGDUMMY
304     -- This cursor might return both the dummy and the physical stop
305     CURSOR c_get_stop(c_location_id IN NUMBER,c_trip_id IN NUMBER) IS
306     SELECT wts.stop_sequence_number,wts.planned_arrival_date
307     FROM   wsh_trip_stops wts
308 	   --#DUM_LOC(S)
309     WHERE  nvl(wts.physical_location_id,wts.stop_location_id) = c_location_id
310 	   --#DUM_LOC(E)
311     AND    wts.trip_id = c_trip_id;
312 
313 
314     TYPE entity_info_rec_type IS RECORD
315         (entity_info_index                      NUMBER,
316          entity_id                              NUMBER,
317          entity_type                            VARCHAR2(30));
318 
319     TYPE entity_info_tab_type IS TABLE OF entity_info_rec_type INDEX BY BINARY_INTEGER;
320 
321     TYPE entity_rec_type IS RECORD (
322          entity_id                      NUMBER,
323          group_id                       NUMBER,
324          ship_method_code               VARCHAR2(30),
325          carrier_id                     NUMBER,
326          mode_of_transport              VARCHAR2(30),
327          organization_id                NUMBER,
328          inventory_item_id              NUMBER,
329          intmed_ship_to_location_id     NUMBER,
330          initial_pickup_location_id     NUMBER,
331          ultimate_dropoff_location_id   NUMBER,
332          initial_pickup_date     DATE,
333          ultimate_dropoff_date   DATE,
334          physical_dropoff_location_id   NUMBER, -- AGDUMMY
335          customer_id                    NUMBER,
336          party_id                       NUMBER,
337          shipment_direction             VARCHAR2(30),
338          shipping_control               VARCHAR2(30) );
339 
340     TYPE entity_tab_type IS TABLE OF entity_rec_type INDEX BY BINARY_INTEGER;
341 
342     TYPE item_rec_type IS RECORD (
343          line_id                       NUMBER,
344          item_id                       NUMBER,
345          org_id                        NUMBER );
346 
347     TYPE item_tab_type IS TABLE OF item_rec_type INDEX BY BINARY_INTEGER;
348 
349     TYPE entity_group_tab_type IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
350 
351     /*TYPE line_constraint_rec_type IS RECORD (
352        line_constraint_index                    NUMBER
353      , entity_type                              VARCHAR2(30)
354      , entity_line_id                           NUMBER
355      , constraint_id                            NUMBER
356      , constraint_class_code                    VARCHAR2(30)
357      , violation_type                           VARCHAR2(1)
358      );
359 
360     TYPE line_constraint_tab_type IS TABLE OF line_constraint_rec_type INDEX BY BINARY_INTEGER;*/
361 
362     TYPE dleg_stops_rec_type IS RECORD (
363        delivery_leg_id                          NUMBER
364      , sequence_number                          NUMBER
365      , pick_up_stop_id                          NUMBER
366      , drop_off_stop_id                         NUMBER
367      , pick_up_loc_id                           NUMBER
368      , drop_off_loc_id                          NUMBER
369      , pick_up_loc_pa_date                      DATE
370      , drop_off_loc_pa_date                     DATE
371      , trip_id                                  NUMBER
372      , delivery_id                              NUMBER
373      );
374 
375 -- Utility APIs
376 --***************************************************************************--
377 
378 FUNCTION entity_exists(
379                  p_entity_id IN NUMBER,
380                  p_entity_table IN WSH_UTIL_CORE.id_tab_type,
381                  x_found_index  OUT NOCOPY NUMBER) RETURN BOOLEAN
382 IS
383 
384       z          NUMBER := 0;
385       FOUND      BOOLEAN:= FALSE;
386 
387       l_debug_on          CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
388       l_module_name       CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'entity_exists';
389 BEGIN
390     IF l_debug_on THEN
391       WSH_DEBUG_SV.push (l_module_name);
392       WSH_DEBUG_SV.logmsg(l_module_name,'p_entity_id : '||p_entity_id||' p_entity_table count : '||p_entity_table.COUNT);
393     END IF;
394     --
395       z := p_entity_table.FIRST;
396       IF z IS NOT NULL THEN
397          LOOP
398 	        IF l_debug_on THEN
399                    WSH_DEBUG_SV.logmsg(l_module_name,' z : '||z||' p_entity_table(z) : '||p_entity_table(z));
400                 END IF;
401 
402                 IF p_entity_table(z) = p_entity_id THEN
403                    FOUND := TRUE;
404                    x_found_index := z;
405 	           IF l_debug_on THEN
406                       WSH_DEBUG_SV.logmsg(l_module_name,' exiting as p_entity_id found');
407                    END IF;
408                    EXIT;
409                 END IF;
410 
411                 EXIT WHEN z= p_entity_table.LAST;
412                 z:= p_entity_table.NEXT(z);
413 
414          END LOOP;
415       END IF;
416       IF FOUND THEN
417 	    IF l_debug_on THEN
418             WSH_DEBUG_SV.logmsg(l_module_name,' returning true');
419          END IF;
420       ELSE
421 	    IF l_debug_on THEN
422             WSH_DEBUG_SV.logmsg(l_module_name,'returning false');
423          END IF;
424       END IF;
425       IF l_debug_on THEN
426         wsh_debug_sv.pop (l_module_name);
427       END IF;
428       RETURN FOUND;
429 END entity_exists;
430 
431 
432 --***************************************************************************--
433 --========================================================================
434 -- PROCEDURE :  refresh_cache            PRIVATE
435 --
436 -- PARAMETERS: x_return_status           Return Status
437 -- COMMENT   :
438 --             Refreshes constraint related database cache s
439 --             if middletier session (ICX session) is changed
440 --========================================================================
441 
442 PROCEDURE refresh_cache (
443              x_return_status    OUT  NOCOPY  VARCHAR2 )
444 IS
445 
446     l_session_id        NUMBER  := 0;
447 
448     l_debug_on          CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
449     l_module_name       CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'refresh_cache';
450 
451 BEGIN
452     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
453     --
454     IF l_debug_on THEN
455       wsh_debug_sv.push (l_module_name);
456     END IF;
457     --
458 
459     l_session_id := icx_sec.g_session_id;
460 
461     IF l_debug_on THEN
462        wsh_debug_sv.logmsg(l_module_name,'g_comp_class_tab count : '||g_comp_class_tab.COUNT);
463        wsh_debug_sv.logmsg(l_module_name,'g_comp_constraint_tab count : '||g_comp_constraint_tab.COUNT);
464        wsh_debug_sv.logmsg(l_module_name,'g_session_id : '||g_session_id||' Current session id : '||l_session_id);
465     END IF;
466 
467     IF g_session_id IS NULL OR l_session_id <> g_session_id THEN
468        -- Delete constraint cache
469        g_comp_class_tab.DELETE;
470        g_comp_constraint_tab.DELETE;
471        --Delete Region Constaint Cache.
472        g_reg_const_cache.DELETE;
473        g_regloc_loc_cache.DELETE;
474 
475        g_session_id := l_session_id;
476 
477        IF l_debug_on THEN
478 	   wsh_debug_sv.logmsg(l_module_name,'Constraints Cache cleared');
479        END IF;
480 
481     END IF;
482 
483     --
484     IF l_debug_on THEN
485       wsh_debug_sv.pop (l_module_name);
486     END IF;
487     --
488 
489 EXCEPTION
490     WHEN others THEN
491       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.refresh_cache');
492       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
493       --
494       IF l_debug_on THEN
495         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
496         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
497       END IF;
498       --
499 END refresh_cache;
500 
501 --***************************************************************************
502 --
503 --========================================================================
504 -- FUNCTION :  get_compclass_code          PRIVATE
505 --
506 -- PARAMETERS: p_comp_class_id             Input compatibility class id
507 --             x_severity                  Ouput severity setting
508 -- COMMENT   : This information is cached
509 -- To retrieve compatibility class code
510 -- and severity setting for a compatibility class id
511 --========================================================================
512 
513 FUNCTION get_compclass_code(
514              p_comp_class_id          IN NUMBER,
515              x_severity               OUT NOCOPY VARCHAR2) RETURN VARCHAR2
516 IS
517 
518     CURSOR c_get_comp_class_info(c_comp_class_id IN NUMBER) IS
519     SELECT *
520     FROM   WSH_FTE_COMP_CLASSES
521     WHERE  COMPATIBILITY_CLASS_ID = c_comp_class_id;
522 
523     l_comp_class_rec   WSH_FTE_COMP_CLASSES%ROWTYPE;
524     i                  NUMBER := 0;
525     l_result           VARCHAR2(30)  := NULL;
526     l_hash_value       NUMBER := 0;
527 
528     l_debug_on         CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
529     l_module_name      CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'get_compclass_code';
530 
531 BEGIN
532     --
533     IF l_debug_on THEN
534       wsh_debug_sv.push (l_module_name);
535     END IF;
536     --
537 
538     i:=g_comp_class_tab.FIRST;
539 
540     IF i IS NOT NULL THEN
541       LOOP
542         IF g_comp_class_tab(i).compatibility_class_id = p_comp_class_id THEN
543            x_severity := g_comp_class_tab(i).CONSTRAINT_VIOLATION;
544            l_result := g_comp_class_tab(i).compatibility_class_code;
545            EXIT;
546         END IF;
547 
548         EXIT WHEN i=g_comp_class_tab.LAST;
549         i := g_comp_class_tab.NEXT(i);
550       END LOOP;
551     END IF;
552 
553     IF l_result IS NULL THEN
554 
555       OPEN  c_get_comp_class_info(p_comp_class_id);
556       FETCH c_get_comp_class_info INTO l_comp_class_rec;
557       CLOSE c_get_comp_class_info;
558 
559       l_result := l_comp_class_rec.compatibility_class_code;
560       x_severity := l_comp_class_rec.CONSTRAINT_VIOLATION;
561 
562     END IF;
563 
564     --
565     IF l_debug_on THEN
566       wsh_debug_sv.pop (l_module_name);
567     END IF;
568     --
569     RETURN l_result;
570 
571 EXCEPTION
572     WHEN others THEN
573       IF c_get_comp_class_info%ISOPEN THEN
574          CLOSE c_get_comp_class_info;
575       END IF;
576       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.get_compclass_code');
577       --
578       IF l_debug_on THEN
579         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
580         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
581       END IF;
582       --
583       RETURN g_unexp_char;
584 END get_compclass_code;
585 
586 --***************************************************************************--
587 --
588 --========================================================================
589 -- FUNCTION :  get_compclass_id            PRIVATE
590 --
591 -- PARAMETERS: p_comp_class_code           Input compatibility clas code
592 -- COMMENT   : This information is cached
593 -- To retrieve compatibility class id
594 -- for a compatibility class code
595 --========================================================================
596 
597 FUNCTION get_compclass_id(
598              p_comp_class_code          IN VARCHAR2) RETURN NUMBER
599 IS
600 
601     CURSOR c_get_comp_class_info(c_comp_class_code IN VARCHAR2) IS
602     SELECT *
603     FROM   WSH_FTE_COMP_CLASSES
604     WHERE  COMPATIBILITY_CLASS_CODE = c_comp_class_code;
605 
606     l_hash_value       NUMBER:=0;
607     l_comp_class_rec   WSH_FTE_COMP_CLASSES%ROWTYPE;
608 
609     l_debug_on         CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
610     l_module_name      CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'get_compclass_id';
611 
612 BEGIN
613 
614     --
615     IF l_debug_on THEN
616       wsh_debug_sv.push (l_module_name);
617     END IF;
618     --
619     l_hash_value := dbms_utility.get_hash_value(
620                                   name => p_comp_class_code,
621                                   base => g_hash_base,
622                                   hash_size =>g_hash_size );
623 
624     IF NOT (g_comp_class_tab.EXISTS(l_hash_value) AND
625             g_comp_class_tab(l_hash_value).compatibility_class_code = p_comp_class_code) THEN
626        OPEN c_get_comp_class_info(p_comp_class_code);
627        FETCH c_get_comp_class_info INTO l_comp_class_rec;
628        g_comp_class_tab(l_hash_value) := l_comp_class_rec;
629        CLOSE c_get_comp_class_info;
630     END IF;
631     --
632     IF l_debug_on THEN
633       wsh_debug_sv.pop (l_module_name);
634     END IF;
635     --
636 
637     RETURN g_comp_class_tab(l_hash_value).compatibility_class_id;
638 
639 EXCEPTION
640     WHEN others THEN
641       IF c_get_comp_class_info%ISOPEN THEN
642          CLOSE c_get_comp_class_info;
643       END IF;
644       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.get_compclass_id');
645       --
646       IF l_debug_on THEN
647         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
648         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
649       END IF;
650       --
651       RETURN g_unexp_num;
652 
653 END get_compclass_id;
654 
655 --***************************************************************************--
656 --========================================================================
657 -- PROCEDURE : get_constraint_display      Called by constraint Wrapper API
658 --                                         and FTE constraint UI
659 --
660 -- PARAMETERS: p_constraint_id             Constraint id to get information about
661 --             x_obj1_display              Display name of constraint object1 in input constraint
662 --             x_obj1_parent_display       Display name of constraint object1 parent
663 --             x_obj2_display              Display name of constraint object2 in input constraint
664 --             x_obj2_parent_display       Display name of constraint object2 parent
665 --             x_condition_display         Display name of constraint type
666 --                                         (Exclusive / Inclusive) in input constraint
667 --             x_fac1_company_type         Display name of company type if constraint object1
668 --                                         is a facility
669 --             x_fac1_company_name         Display name of company name if constraint object1
670 --                                         is a facility
671 --             x_fac2_company_type         Display name of company type if constraint object2
672 --                                         is a facility
673 --             x_fac2_company_name         Display name of company name if constraint object2
674 --                                         is a facility
675 --             x_comp_class_code           Display meaning of compatibility class code
676 --                                         for the input constraint
677 --             x_severity                  Display meaning of severity setting of the
678 --                                         compatibility class for the input constraint
679 --             x_return_status             Return status
680 -- COMMENT   : This procedure is used to perform for following actions
681 --             Takes as input a constraint id
682 --             and returns the names of the objects
683 --             which are associated by this constraint definition
684 --========================================================================
685 
686 PROCEDURE get_constraint_display(
687              p_constraint_id           IN NUMBER,
688              x_obj1_display            OUT NOCOPY      VARCHAR2,
689              x_obj1_parent_display     OUT NOCOPY      VARCHAR2,
690              x_obj2_display            OUT NOCOPY      VARCHAR2,
691              x_obj2_parent_display     OUT NOCOPY      VARCHAR2,
692              x_condition_display       OUT NOCOPY      VARCHAR2,
693              x_fac1_company_type       OUT NOCOPY      VARCHAR2,
694              x_fac1_company_name       OUT NOCOPY      VARCHAR2,
695              x_fac2_company_type       OUT NOCOPY      VARCHAR2,
696              x_fac2_company_name       OUT NOCOPY      VARCHAR2,
697              x_comp_class_code         OUT NOCOPY      VARCHAR2,
698              x_severity                OUT NOCOPY      VARCHAR2,
699              x_return_status           OUT NOCOPY      VARCHAR2 )
700 IS
701 
702     CURSOR c_get_constraint_info(c_constraint_id IN NUMBER) IS
703     SELECT *
704     FROM   WSH_FTE_COMP_CONSTRAINTS
705     WHERE  COMPATIBILITY_ID = c_constraint_id;
706 
707     l_comp_type1       VARCHAR2(3);
708     l_comp_type2       VARCHAR2(3);
709     l_fac_company_type VARCHAR2(30) := NULL;
710     l_fac_company_name VARCHAR2(2000) := NULL;
711     l_severity         VARCHAR2(30);
712     l_constraint_rec   WSH_FTE_COMP_CONSTRAINTS%ROWTYPE;
713 
714     l_debug_on         CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
715     l_module_name      CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'get_constraint_display';
716 
717 BEGIN
718 
719     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
720 
721     IF l_debug_on THEN
722        wsh_debug_sv.push(l_module_name);
723     END IF;
724 
725     -- object1_type values : ORG CUS FAC CAR MOD ITM
726 
727     OPEN c_get_constraint_info(p_constraint_id);
728     FETCH c_get_constraint_info INTO l_constraint_rec;
729     CLOSE c_get_constraint_info;
730 
731     x_comp_class_code := get_compclass_code(
732              p_comp_class_id          => l_constraint_rec.compatibility_class_id,
733              x_severity               => x_severity);
734 
735     IF x_comp_class_code = g_unexp_char THEN
736       IF l_debug_on THEN
737          wsh_debug_sv.log(l_module_name,'Unexpected error from get_compclass_code ');
738       END IF;
739        raise FND_API.G_EXC_UNEXPECTED_ERROR;
740     END IF;
741 
742     l_comp_type1       := SUBSTR(x_comp_class_code,1,3);
743     l_comp_type2       := SUBSTR(x_comp_class_code,5,3);
744 
745     IF l_constraint_rec.CONSTRAINT_OBJECT1_ID IS NOT NULL THEN
746 
747        IF l_debug_on THEN
748          wsh_debug_sv.log(l_module_name,'Calling WSH_FTE_INTEGRATION.get_cc_object_name for CONSTRAINT_OBJECT1_ID ');
749        END IF;
750        x_obj1_display := WSH_FTE_INTEGRATION.get_cc_object_name(
751              p_object_type             =>        l_constraint_rec.CONSTRAINT_OBJECT1_TYPE,
752              x_fac_company_name        =>        l_fac_company_name,
753              x_fac_company_type        =>        l_fac_company_type,
754              p_object_parent_id        =>        l_constraint_rec.OBJECT1_SOURCE_ID,
755              p_object_value_num        =>        l_constraint_rec.CONSTRAINT_OBJECT1_ID );
756 
757     ELSIF l_constraint_rec.CONSTRAINT_OBJECT1_VALUE_CHAR IS NOT NULL THEN
758 
759        IF l_debug_on THEN
760          wsh_debug_sv.log(l_module_name,'Calling WSH_FTE_INTEGRATION.get_cc_object_name for CONSTRAINT_OBJECT1_VALUE_CHAR ');
761        END IF;
762        x_obj1_display := WSH_FTE_INTEGRATION.get_cc_object_name(
763              p_object_type             =>        l_constraint_rec.CONSTRAINT_OBJECT1_TYPE,
764              x_fac_company_name        =>        l_fac_company_name,
765              x_fac_company_type        =>        l_fac_company_type,
766              p_object_value_char       =>        l_constraint_rec.CONSTRAINT_OBJECT1_VALUE_CHAR);
767 
768     END IF;
769 
770     IF x_obj1_display = g_unexp_char THEN
771       IF l_debug_on THEN
772          wsh_debug_sv.log(l_module_name,'Unexpected error from get_cc_object_name ');
773       END IF;
774        raise FND_API.G_EXC_UNEXPECTED_ERROR;
775     END IF;
776 
777     x_fac1_company_type := l_fac_company_type;
778     x_fac1_company_name := l_fac_company_name;
779 
780     IF l_constraint_rec.CONSTRAINT_OBJECT2_ID IS NOT NULL THEN
781 
782        IF l_debug_on THEN
783          wsh_debug_sv.log(l_module_name,'Calling WSH_FTE_INTEGRATION.get_cc_object_name for CONSTRAINT_OBJECT2_ID ');
784        END IF;
785        x_obj2_display := WSH_FTE_INTEGRATION.get_cc_object_name(
786              p_object_type             =>        l_constraint_rec.CONSTRAINT_OBJECT2_TYPE,
787              x_fac_company_name        =>        l_fac_company_name,
788              x_fac_company_type        =>        l_fac_company_type,
789              p_object_parent_id        =>        l_constraint_rec.OBJECT2_SOURCE_ID,
790              p_object_value_num        =>        l_constraint_rec.CONSTRAINT_OBJECT2_ID );
791 
792     ELSIF l_constraint_rec.CONSTRAINT_OBJECT2_VALUE_CHAR IS NOT NULL THEN
793 
794        IF l_debug_on THEN
795          wsh_debug_sv.log(l_module_name,'Calling WSH_FTE_INTEGRATION.get_cc_object_name for CONSTRAINT_OBJECT2_VALUE_CHAR ');
796        END IF;
797        x_obj2_display := WSH_FTE_INTEGRATION.get_cc_object_name(
798              p_object_type             =>        l_constraint_rec.CONSTRAINT_OBJECT2_TYPE,
799              x_fac_company_name        =>        l_fac_company_name,
800              x_fac_company_type        =>        l_fac_company_type,
801              p_object_value_char       =>        l_constraint_rec.CONSTRAINT_OBJECT2_VALUE_CHAR);
802 
803     END IF;
804 
805     IF x_obj2_display = g_unexp_char THEN
806       IF l_debug_on THEN
807          wsh_debug_sv.log(l_module_name,'Unexpected error from get_cc_object_name ');
808       END IF;
809        raise FND_API.G_EXC_UNEXPECTED_ERROR;
810     END IF;
811 
812     x_fac2_company_type := l_fac_company_type;
813     x_fac2_company_name := l_fac_company_name; -- Can return vehicle class code in case a constraint has been defined with vehicle type
814 
815     IF l_constraint_rec.OBJECT1_SOURCE_ID IS NOT NULL THEN
816 
817     -- Patch I : Supports only ORG as parent for Item
818 
819        x_obj1_parent_display := WSH_FTE_INTEGRATION.get_cc_object_name(
820              p_object_type             =>        'ORG',
821              x_fac_company_name        =>        l_fac_company_name,
822              x_fac_company_type        =>        l_fac_company_type ,
823              p_object_value_num        =>        l_constraint_rec.OBJECT1_SOURCE_ID);
824 
825     IF x_obj1_parent_display = g_unexp_char THEN
826        raise FND_API.G_EXC_UNEXPECTED_ERROR;
827     END IF;
828 
829     END IF;
830 
831     IF l_constraint_rec.OBJECT2_SOURCE_ID IS NOT NULL THEN
832 
833        x_obj2_parent_display := WSH_FTE_INTEGRATION.get_cc_object_name(
834              p_object_type             =>        'ORG',
835              x_fac_company_name        =>        l_fac_company_name,
836              x_fac_company_type        =>        l_fac_company_type ,
837              p_object_value_num        =>        l_constraint_rec.OBJECT2_SOURCE_ID);
838 
839     IF x_obj2_parent_display = g_unexp_char THEN
840        raise FND_API.G_EXC_UNEXPECTED_ERROR;
841     END IF;
842 
843     END IF;
844 
845     x_condition_display := WSH_XC_UTIL.Get_Lookup_Meaning(
846                 p_lookup_code     =>   l_constraint_rec.CONSTRAINT_TYPE,
847                 p_lookup_type     =>   'WSH_FTE_CONSTRAINT_TYPE'
848                 );
849 
850     IF x_condition_display IS NULL THEN
851        raise FND_API.G_EXC_UNEXPECTED_ERROR;
852     END IF;
853 
854     IF l_comp_type1 = 'FAC' AND l_constraint_rec.CONSTRAINT_OBJECT1_TYPE <> 'FAC' THEN
855        x_obj1_display := FND_MESSAGE.GET_STRING('FTE','FTE_COMP_ALL_FACILITIES')||' '||x_obj1_display;
856     ELSIF l_comp_type2 = 'FAC' AND l_constraint_rec.CONSTRAINT_OBJECT2_TYPE <> 'FAC' THEN
857        x_obj2_display := FND_MESSAGE.GET_STRING('FTE','FTE_COMP_ALL_FACILITIES')||' '||x_obj2_display;
858     END IF;
859 
860     --
861     IF l_debug_on THEN
862       WSH_DEBUG_SV.pop(l_module_name);
863     END IF;
864     --
865 
866 EXCEPTION
867     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
868       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
869       --
870       IF l_debug_on THEN
871         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
872         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
873       END IF;
874       --
875     WHEN OTHERS THEN
876       IF c_get_constraint_info%ISOPEN THEN
877          CLOSE c_get_constraint_info;
878       END IF;
879       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.get_constraint_display');
880       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
881       --
882       IF l_debug_on THEN
883         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
884         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
885       END IF;
886       --
887 END get_constraint_display;
888 
889 
890 --***************************************************************************--
891 --========================================================================
892 -- PROCEDURE : remove_duplicate_const  PRIVATE
893 --
894 -- PARAMETERS: p_failed_constraints       Violated Constraints table, may have duplicate entries.
895 --	       x_failed_constraints	  Violated Constraints table, after removing duplicate entries.
896 --             x_return_status            Return status
897 -- COMMENT   : Is used to remove duplicate constraints.
898 --========================================================================
899 PROCEDURE remove_duplicate_const(
900 	p_failed_constraints	IN  OUT  NOCOPY line_constraint_tab_type,
901 	x_return_status		OUT NOCOPY VARCHAR2)
902 IS
903 	i			NUMBER;
904 	j			NUMBER;
905 	k			NUMBER;
906 	l_del_flag		BOOLEAN;
907 
908 	l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' ||'remove_duplicate_const';
909 	l_debug_on    CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
910 
911 BEGIN
912 
913  x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
914 
915  IF l_debug_on THEN
916        wsh_debug_sv.push(l_module_name);
917        wsh_debug_sv.logmsg(l_module_name,'No. of constraints:'||p_failed_constraints.COUNT);
918  END IF;
919 
920  i:= p_failed_constraints.FIRST;
921 
922  IF i IS NOT NULL THEN
923  LOOP
924 
925    j := p_failed_constraints.NEXT(i);
926 
927    l_del_flag := FALSE;
928    IF j IS NOT NULL THEN
929      LOOP
930 
931 	IF (p_failed_constraints(i).constraint_id=p_failed_constraints(j).constraint_id) THEN
932 	    k := j;
933 	    l_del_flag := TRUE;
934 	    IF l_debug_on THEN
935 	       wsh_debug_sv.logmsg (l_module_name,'Constraint '||p_failed_constraints(i).constraint_id ||' appears more than once');
936 	    END IF;
937 	END IF;
938 
939 	EXIT WHEN j = p_failed_constraints.LAST;
940 
941 	j := p_failed_constraints.NEXT(j);
942 
943 	IF (l_del_flag) THEN
944 	   p_failed_constraints.DELETE(k);
945 	   l_del_flag := FALSE;
946 	END IF;
947 
948      END LOOP;
949 
950      -- If element is present at last position,We need to delete outside the loop.
951      IF (l_del_flag) THEN
952 	p_failed_constraints.DELETE(k);
953         l_del_flag := FALSE;
954      END IF;
955    END IF;
956 
957    EXIT WHEN i = p_failed_constraints.LAST;
958    i := p_failed_constraints.NEXT(i);
959 
960  END LOOP;
961  END IF;
962 
963  IF l_debug_on THEN
964     wsh_debug_sv.logmsg(l_module_name,'No. of constraints after deleting duplicate constraints:'||to_char(p_failed_constraints.COUNT));
965     WSH_DEBUG_SV.pop(l_module_name);
966  END IF;
967 
968 EXCEPTION
969 WHEN others THEN
970    WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.remove_duplicate_const');
971    x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
972    --
973    IF l_debug_on THEN
974       WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
975       WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
976    END IF;
977     --
978 END remove_duplicate_const;
979 
980 
981 --***************************************************************************--
982 --========================================================================
983 -- PROCEDURE : get_carrier_from_loc       PRIVATE
984 --
985 -- PARAMETERS: p_location_id              Input Location id
986 --             x_carrier_id               Carrier at the input location
987 --             x_return_status            Return status
988 -- COMMENT   :
989 -- Returns the carrier id of the carrier
990 -- having a location at input wsh location id
991 --========================================================================
992 PROCEDURE get_carrier_from_loc(
993               p_location_id    IN  NUMBER,
994               x_carrier_id     OUT NOCOPY  NUMBER,
995               x_return_status  OUT NOCOPY  VARCHAR2)
996 IS
997 
998     CURSOR c_get_carrier(c_location_id IN NUMBER) IS
999     SELECT wc.carrier_id
1000     FROM   wsh_locations wl,
1001            hz_party_sites hps,
1002            hz_parties     hp,
1003            wsh_carriers   wc
1004     WHERE  wl.wsh_location_id = c_location_id
1005     AND    wl.location_source_code = 'HZ'
1006     AND    wl.source_location_id = hps.location_id
1007     AND    hps.party_id = hp.party_id
1008     AND    hp.party_id = wc.carrier_id;
1009 
1010     l_debug_on    CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
1011     l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'get_carrier_from_loc';
1012 
1013 BEGIN
1014 
1015     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1016 
1017     IF l_debug_on THEN
1018        wsh_debug_sv.push(l_module_name);
1019     END IF;
1020 
1021 
1022     IF ( p_location_id < g_cache_max_size  and g_carrier_from_location.EXISTS(p_location_id)) THEN
1023 
1024 	x_carrier_id := g_carrier_from_location(p_location_id);
1025 	IF (x_carrier_id = -1) THEN
1026 	    x_carrier_id := NULL;
1027 	END IF;
1028 
1029     ELSE
1030 
1031    	--Does not exist in the cache.
1032 	OPEN  c_get_carrier(p_location_id);
1033         FETCH c_get_carrier INTO x_carrier_id;
1034 	IF c_get_carrier%NOTFOUND THEN
1035 	       x_carrier_id := NULL;
1036 	END IF;
1037 	CLOSE c_get_carrier;
1038 
1039 	IF (p_location_id < g_cache_max_size ) THEN
1040 	    g_carrier_from_location(p_location_id) := nvl(x_carrier_id,-1);
1041 	END IF;
1042 
1043     END IF;
1044 
1045     --
1046     IF l_debug_on THEN
1047       WSH_DEBUG_SV.logmsg(l_module_name,'Returning carrier id : '|| x_carrier_id ||' for location : ' ||p_location_id);
1048       WSH_DEBUG_SV.pop(l_module_name);
1049     END IF;
1050     --
1051 
1052 EXCEPTION
1053     WHEN others THEN
1054       IF c_get_carrier%ISOPEN THEN
1055             CLOSE c_get_carrier;
1056       END IF;
1057       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.get_carrier_from_loc');
1058       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1059       --
1060       IF l_debug_on THEN
1061         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1062         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
1063       END IF;
1064       --
1065 END get_carrier_from_loc;
1066 
1067 --***************************************************************************--
1068 --========================================================================
1069 -- PROCEDURE : get_customer_from_loc      PRIVATE
1070 --
1071 -- PARAMETERS: p_location_id              Input Location id
1072 --             x_customer_id              Carrier at the input location
1073 --             x_return_status            Return status
1074 -- COMMENT   :
1075 -- Returns the customer id of the customer
1076 -- having a location at input wsh location id
1077 --========================================================================
1078 
1079 PROCEDURE get_customer_from_loc(
1080               p_location_id    IN  NUMBER,
1081               --x_customer_id     OUT NOCOPY  NUMBER,
1082               x_customer_id_tab     OUT NOCOPY  WSH_UTIL_CORE.id_tab_type,
1083               x_return_status  OUT NOCOPY  VARCHAR2)
1084 IS
1085 
1086     CURSOR c_get_customer(c_location_id IN NUMBER) IS
1087     SELECT hcas.cust_account_id
1088     FROM   wsh_locations wl,
1089            hz_party_sites hps,
1090            hz_cust_acct_sites_all hcas
1091     WHERE  wl.wsh_location_id = c_location_id
1092     AND    wl.location_source_code = 'HZ'
1093     AND    wl.source_location_id = hps.location_id
1094     AND    hps.party_site_id = hcas.party_site_id;
1095 
1096     l_customer_id_tab   WSH_UTIL_CORE.id_tab_type;
1097     itr                    NUMBER := 0;
1098     i                      NUMBER := 0;
1099     l_return_status        VARCHAR2(1);
1100     l_cust_string          VARCHAR2(2000);
1101 
1102     l_debug_on    CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
1103     l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'get_customer_from_loc';
1104 
1105 BEGIN
1106 
1107     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1108 
1109     IF l_debug_on THEN
1110        wsh_debug_sv.push(l_module_name);
1111     END IF;
1112 
1113     IF ( p_location_id < g_cache_max_size  and g_customer_from_location.EXISTS(p_location_id)) THEN
1114 
1115 	wsh_util_core.get_idtab_from_string(
1116         	p_string	 => g_customer_from_location(p_location_id),
1117 		x_id_tab	 => l_customer_id_tab,
1118 		x_return_status  => l_return_status);
1119 
1120 	IF l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1121   	    raise FND_API.G_EXC_UNEXPECTED_ERROR;
1122 	END IF;
1123 
1124 	itr := l_customer_id_tab.FIRST;
1125 
1126 	IF (l_customer_id_tab(itr) <> -1) THEN
1127 
1128 	   x_customer_id_tab:=l_customer_id_tab;
1129 
1130 	END IF;
1131 
1132 	IF l_debug_on THEN
1133 	   wsh_debug_sv.push(l_module_name);
1134 	END IF;
1135 
1136 /*
1137 	x_customer_id := g_customer_from_location(p_location_id);
1138 
1139 	IF (x_customer_id = -1) THEN
1140 		x_customer_id := NULL;
1141 	END IF;
1142 */
1143     ELSE
1144 
1145 	--Does not exist in the cache.
1146 	OPEN c_get_customer(p_location_id);
1147 	FETCH c_get_customer BULK COLLECT INTO l_customer_id_tab;
1148 /*
1149 	IF c_get_customer%NOTFOUND THEN
1150 		 x_customer_id := NULL;
1151 	END IF;
1152 */
1153 	CLOSE c_get_customer;
1154 
1155 	x_customer_id_tab := l_customer_id_tab;
1156 
1157 	IF (p_location_id < g_cache_max_size ) THEN
1158 
1159 	  itr:=l_customer_id_tab.FIRST;
1160 
1161 	  IF (itr) IS NULL THEN
1162 	        l_cust_string := '-1';
1163 	  ELSE
1164 
1165 	     wsh_util_core.get_string_from_idtab(
1166 	    	p_id_tab	 => l_customer_id_tab,
1167 		x_string	 => l_cust_string,
1168 		x_return_status  => l_return_status);
1169 
1170 	     IF l_debug_on THEN
1171 		 WSH_DEBUG_SV.logmsg(l_module_name,'Org String '||l_cust_string);
1172 	     END IF;
1173 
1174 	     IF l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1175   		 raise FND_API.G_EXC_UNEXPECTED_ERROR;
1176   	     END IF;
1177 
1178 	  END IF;
1179 
1180 	  g_customer_from_location(p_location_id) := l_cust_string;
1181 
1182 	END IF;
1183 
1184 /*
1185 	IF (p_location_id < g_cache_max_size ) THEN
1186 	   g_customer_from_location(p_location_id) := nvl(x_customer_id,-1);
1187 	END IF;
1188 */
1189 
1190     END IF;
1191 
1192     --
1193     IF l_debug_on THEN
1194 	i := x_customer_id_tab.FIRST;
1195 	IF (i IS NOT NULL) THEN
1196 
1197 	    WSH_DEBUG_SV.logmsg(l_module_name,'Number of Customers for the location '||p_location_id||'is :'|| x_customer_id_tab.COUNT);
1198 	    LOOP
1199 	       WSH_DEBUG_SV.logmsg(l_module_name,'Customer_id :'||x_customer_id_tab(i));
1200            EXIT WHEN i = x_customer_id_tab.LAST;
1201 	       i  := x_customer_id_tab.NEXT(i);
1202 	    END LOOP;
1203 
1204 	ELSE
1205 	    WSH_DEBUG_SV.logmsg(l_module_name,'No Organization assocaited with location '||p_location_id);
1206 
1207 	END IF;
1208 
1209       WSH_DEBUG_SV.pop(l_module_name);
1210     END IF;
1211     --
1212 /*
1213 
1214     IF ( p_location_id < g_cache_max_size  and g_customer_from_location.EXISTS(p_location_id)) THEN
1215 	x_customer_id := g_customer_from_location(p_location_id);
1216 
1217 	IF (x_customer_id = -1) THEN
1218 		x_customer_id := NULL;
1219 	END IF;
1220     ELSE
1221 
1222 	--Does not exist in the cache.
1223 	OPEN c_get_customer(p_location_id);
1224 	FETCH c_get_customer INTO x_customer_id;
1225 	IF c_get_customer%NOTFOUND THEN
1226 		 x_customer_id := NULL;
1227 	END IF;
1228 	CLOSE c_get_customer;
1229 
1230 	IF (p_location_id < g_cache_max_size ) THEN
1231 	   g_customer_from_location(p_location_id) := nvl(x_customer_id,-1);
1232 	END IF;
1233 
1234     END IF;
1235 
1236     --
1237     IF l_debug_on THEN
1238       WSH_DEBUG_SV.logmsg(l_module_name,'Returning customer id : '|| x_customer_id || ' for location : '||p_location_id);
1239       WSH_DEBUG_SV.pop(l_module_name);
1240     END IF;
1241     --
1242 */
1243 
1244 EXCEPTION
1245      WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1246       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
1247         IF l_debug_on THEN
1248         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1249         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
1250       END IF;
1251     WHEN others THEN
1252       IF c_get_customer%ISOPEN THEN
1253          CLOSE c_get_customer;
1254       END IF;
1255       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.get_customer_from_loc');
1256       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1257       --
1258       IF l_debug_on THEN
1259         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1260         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
1261       END IF;
1262       --
1263 END get_customer_from_loc;
1264 
1265 --***************************************************************************--
1266 --========================================================================
1267 -- PROCEDURE : get_supplier_from_loc      PRIVATE
1268 --
1269 -- PARAMETERS: p_location_id              Input Location id
1270 --             x_supplier_id              supplier at the input location
1271 --             x_return_status            Return status
1272 -- COMMENT   :
1273 -- Returns the supplier id of the supplier
1274 -- having a location at input wsh location id
1275 --========================================================================
1276 
1277 PROCEDURE get_supplier_from_loc(
1278               p_location_id    IN  NUMBER,
1279               x_supplier_id     OUT NOCOPY  NUMBER,
1280               x_return_status  OUT NOCOPY  VARCHAR2)
1281 IS
1282 
1283     CURSOR c_get_supplier(c_location_id IN NUMBER) IS
1284     SELECT hz.party_id
1285     FROM   hz_parties hz,
1286            po_vendors po,
1287            hz_relationships rel,
1288            hz_party_sites hps,
1289            wsh_locations wl
1290     WHERE  wl.wsh_location_id = c_location_id
1291     AND    wl.location_source_code = 'HZ'
1292     AND    wl.source_location_id = hps.location_id
1293     AND    rel.relationship_type = 'POS_VENDOR_PARTY'
1294     and    rel.object_id = hz.party_id
1295     and    rel.object_table_name = 'HZ_PARTIES'
1296     and    rel.object_type = 'ORGANIZATION'
1297     and    rel.subject_table_name = 'PO_VENDORS'
1298     and    rel.subject_id = po.vendor_id
1299     and    rel.subject_type = 'POS_VENDOR'
1300     AND    hps.party_id = hz.party_id;
1301 
1302     l_debug_on    CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
1303     l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'get_supplier_from_loc';
1304 
1305 BEGIN
1306 
1307     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1308 
1309     IF l_debug_on THEN
1310        wsh_debug_sv.push(l_module_name);
1311     END IF;
1312 
1313 
1314     IF (p_location_id < g_cache_max_size  and g_supplier_from_location.EXISTS(p_location_id)) THEN
1315 
1316 	x_supplier_id := g_supplier_from_location(p_location_id);
1317 	IF (x_supplier_id = -1) THEN
1318 		x_supplier_id := NULL;
1319 	END IF;
1320 
1321     ELSE
1322 	    --Does not exist in the cache.
1323 	    OPEN c_get_supplier(p_location_id);
1324 	    FETCH c_get_supplier INTO x_supplier_id;
1325 	    IF c_get_supplier%NOTFOUND THEN
1326 	       x_supplier_id := NULL;
1327 	    END IF;
1328 	    CLOSE c_get_supplier;
1329 
1330 	    IF (p_location_id < g_cache_max_size ) THEN
1331 	      g_supplier_from_location(p_location_id) := nvl(x_supplier_id,-1);
1332 	    END IF;
1333 
1334     END IF;
1335 
1336     --
1337     IF l_debug_on THEN
1338       WSH_DEBUG_SV.logmsg(l_module_name,'Returning supplier id : '|| x_supplier_id || ' for location :'|| p_location_id);
1339       WSH_DEBUG_SV.pop(l_module_name);
1340     END IF;
1341     --
1342 
1343 EXCEPTION
1344     WHEN others THEN
1345       IF c_get_supplier%ISOPEN THEN
1346          CLOSE c_get_supplier;
1347       END IF;
1348       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.get_supplier_from_loc');
1349       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1350       --
1351       IF l_debug_on THEN
1352         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1353         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
1354       END IF;
1355       --
1356 END get_supplier_from_loc;
1357 
1358 
1359 --#DUM_LOC(S)
1360 --***************************************************************************--
1361 --========================================================================
1362 -- PROCEDURE : get_org_from_location      PRIVATE
1363 --
1364 -- PARAMETERS: p_location_id              Input Location id
1365 --             x_organization_tab         Organizations for the input location
1366 --             x_return_status            Return status
1367 -- COMMENT   :
1368 --	       Returns table of organizations for location.
1369 --========================================================================
1370 PROCEDURE get_org_from_location(
1371          p_location_id	       IN  NUMBER,
1372          x_organization_tab    OUT NOCOPY  WSH_UTIL_CORE.id_tab_type,
1373          x_return_status       OUT NOCOPY  VARCHAR2)
1374 IS
1375 	CURSOR c_get_org_from_loc(c_location_id IN NUMBER) IS
1376 	SELECT owner_party_id
1377 	FROM   wsh_location_owners
1378 	WHERE  owner_type = 1
1379         AND    wsh_location_id = c_location_id
1380 	AND    owner_party_id <> -1 ;
1381 
1382 
1383 	l_organization_tab	WSH_UTIL_CORE.id_tab_type;
1384 
1385 	itr			NUMBER;
1386 	i			NUMBER;
1387 	l_return_status		VARCHAR2(1);
1388 	l_org_string		VARCHAR2(32767);
1389 
1390 	l_debug_on		CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
1391         l_module_name		CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'get_org_from_location';
1392 
1393 BEGIN
1394    x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1395 
1396    IF l_debug_on THEN
1397        wsh_debug_sv.push(l_module_name);
1398    END IF;
1399 
1400    IF (p_location_id < g_cache_max_size and g_organization_from_location.EXISTS(p_location_id)) THEN
1401 
1402 	wsh_util_core.get_idtab_from_string(
1403         	p_string	 => g_organization_from_location(p_location_id),
1404 		x_id_tab	 => l_organization_tab,
1405 		x_return_status  => l_return_status);
1406 
1407 	IF l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1408   	    raise FND_API.G_EXC_UNEXPECTED_ERROR;
1409 	END IF;
1410 
1411 	itr := l_organization_tab.FIRST;
1412 
1413 	IF (l_organization_tab(itr) <> -1) THEN
1414 
1415 	   x_organization_tab:=l_organization_tab;
1416 
1417 	END IF;
1418 
1419 	IF l_debug_on THEN
1420 	   wsh_debug_sv.push(l_module_name);
1421 	END IF;
1422 
1423     ELSE
1424 
1425 	--Does not exist in the cache.
1426 	OPEN  c_get_org_from_loc(p_location_id);
1427 	FETCH c_get_org_from_loc BULK COLLECT INTO l_organization_tab;
1428 	CLOSE c_get_org_from_loc;
1429 
1430 	x_organization_tab := l_organization_tab;
1431 
1432 	IF (p_location_id < g_cache_max_size ) THEN
1433 
1434 	  itr:=l_organization_tab.FIRST;
1435 
1436 	  IF (itr) IS NULL THEN
1437 	        l_org_string := '-1';
1438 	  ELSE
1439 
1440 	     wsh_util_core.get_string_from_idtab(
1441 	    	p_id_tab	 => l_organization_tab,
1442 		x_string	 => l_org_string,
1443 		x_return_status  => l_return_status);
1444 
1445 	     IF l_debug_on THEN
1446 		 WSH_DEBUG_SV.logmsg(l_module_name,'Org String '||l_org_string);
1447 	     END IF;
1448 
1449 	     IF l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1450   		 raise FND_API.G_EXC_UNEXPECTED_ERROR;
1451   	     END IF;
1452 
1453 	  END IF;
1454 
1455 	  g_organization_from_location(p_location_id) := l_org_string;
1456 
1457 	END IF;
1458 
1459       END IF;
1460 
1461       -- BUG 4120043 : Replaced FOR loop by iteration using NEXT.
1462       IF l_debug_on THEN
1463 
1464 	i := x_organization_tab.FIRST;
1465 	IF (i IS NOT NULL) THEN
1466 
1467 	    WSH_DEBUG_SV.logmsg(l_module_name,'Number of Organizations for the location '||p_location_id||'is :'|| x_organization_tab.COUNT);
1468 	    LOOP
1469 	       WSH_DEBUG_SV.logmsg(l_module_name,'Organization_id :'||x_organization_tab(i));
1470            EXIT WHEN i = x_organization_tab.LAST;
1471 	       i  := x_organization_tab.NEXT(i);
1472 	    END LOOP;
1473 
1474 	ELSE
1475 	    WSH_DEBUG_SV.logmsg(l_module_name,'No Organization assocaited with location '||p_location_id);
1476 
1477 	END IF;
1478 
1479 	WSH_DEBUG_SV.pop(l_module_name);
1480 
1481       END IF;
1482       --
1483 
1484 EXCEPTION
1485      WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1486       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
1487        IF l_debug_on THEN
1488         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1489         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
1490       END IF;
1491     WHEN others THEN
1492       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1493 
1494       IF c_get_org_from_loc%ISOPEN THEN
1495          CLOSE c_get_org_from_loc;
1496       END IF;
1497 
1498       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.get_org_from_loc');
1499 
1500       --
1501       IF l_debug_on THEN
1502         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1503         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
1504       END IF;
1505       --
1506 END get_org_from_location;
1507 
1508 --#DUM_LOC(E)
1509 
1510 
1511 --
1512 -- Bug 4142393:TST11510.1CU.2:ENCOUNTERING UNEXPECTED ERROR IN DLWB, WHILE SPLITTING THE DEL'RY
1513 --
1514 --***************************************************************************--
1515 --========================================================================
1516 -- PROCEDURE : get_loc_for_org            PRIVATE
1517 --
1518 -- PARAMETERS: p_org_id                   Input Organization id
1519 --             x_location_id              Location id corresponding to the organization.
1520 --             x_return_status            Return status
1521 -- COMMENT   :
1522 --             Returns the corresponding location for the organziation.
1523 --            (The procedure handles cases where org is not associated with a location)
1524 --========================================================================
1525 PROCEDURE get_loc_for_org(
1526               p_org_id	       IN  NUMBER,
1527               x_location_id    OUT NOCOPY  NUMBER,
1528               x_return_status  OUT NOCOPY  VARCHAR2)
1529 IS
1530           --Bug 4891887
1531 	 /*CURSOR c_org_to_loc (v_org_id NUMBER) IS
1532          SELECT location_id
1533          FROM	wsh_ship_from_orgs_v
1534          WHERE  organization_id = v_org_id;*/
1535 
1536  	 l_debug_on    CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
1537          l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'get_loc_for_org';
1538 
1539 BEGIN
1540 
1541     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1542 
1543     IF l_debug_on THEN
1544        wsh_debug_sv.push(l_module_name);
1545     END IF;
1546 
1547 
1548     IF ( p_org_id < g_cache_max_size  and g_loc_from_org.EXISTS(p_org_id)) THEN
1549 
1550 	x_location_id := g_loc_from_org(p_org_id);
1551 	IF (x_location_id = -1) THEN
1552 	    x_location_id := NULL;
1553 	END IF;
1554 
1555     ELSE
1556 
1557    	--Does not exist in the cache.
1558 	--Bug 4891887
1559 	/*OPEN  c_org_to_loc(p_org_id);
1560         FETCH c_org_to_loc INTO x_location_id;
1561 
1562 	IF    c_org_to_loc%NOTFOUND THEN
1563 	       x_location_id := NULL;
1564 	END IF;
1565 
1566 	CLOSE c_org_to_loc;*/
1567 	--Bug 4891887 and 4891881 Calling Utilcore package
1568 	G_CALLING_API :='CONSTRAINT';
1569 	WSH_UTIL_CORE.Get_Location_Id(
1570 	                              p_mode=>'ORG',
1571 	                              p_source_id=>p_org_id,
1572 				      x_location_id=>x_location_id,
1573 				      x_api_status=>x_return_status,
1574 				      p_transfer_location=>FALSE);
1575         G_CALLING_API :=NULL;
1576 
1577 	IF (p_org_id < g_cache_max_size ) THEN
1578 	    g_loc_from_org(p_org_id) := nvl(x_location_id,-1);
1579 	END IF;
1580 
1581     END IF;
1582 
1583     --
1584     IF l_debug_on THEN
1585       WSH_DEBUG_SV.logmsg(l_module_name,'Returning location id : '|| x_location_id ||' for Organization: ' ||p_org_id);
1586       WSH_DEBUG_SV.pop(l_module_name);
1587     END IF;
1588     --
1589 
1590 EXCEPTION
1591     WHEN others THEN
1592       G_CALLING_API :=NULL;
1593          --Bug 4891887
1594       /*IF c_org_to_loc%ISOPEN THEN
1595             CLOSE c_org_to_loc;
1596       END IF;*/
1597 
1598       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.get_loc_for_org');
1599 
1600       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1601 
1602       --
1603       IF l_debug_on THEN
1604         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1605         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
1606       END IF;
1607       --
1608 END get_loc_for_org;
1609 
1610 
1611 --***************************************************************************--
1612 --========================================================================
1613 -- PROCEDURE : stack_messages             PRIVATE
1614 --
1615 -- PARAMETERS: p_failed_constraints       Table of violated constraint records
1616 --             x_msg_count                Number of messages in the list
1617 --             x_msg_data                 Text of messages
1618 --             x_return_status            Return status
1619 -- COMMENT   :
1620 -- Stacks constraint violation messages
1621 -- inpto the FND message stack
1622 --========================================================================
1623 PROCEDURE stack_messages (
1624              p_failed_constraints       IN  OUT NOCOPY line_constraint_tab_type,
1625              x_msg_count                OUT NOCOPY NUMBER,
1626              x_msg_data                 OUT NOCOPY VARCHAR2,
1627              x_return_status            OUT NOCOPY VARCHAR2)
1628 IS
1629 
1630     i                       NUMBER:=0;
1631     l_return_status         VARCHAR2(1);
1632     l_entity                VARCHAR2(2000);
1633     l_entity_id             NUMBER;
1634     l_object1_name          VARCHAR2(2000);
1635     l_object1_parent_name   VARCHAR2(2000);
1636     l_object2_name          VARCHAR2(2000);
1637     l_object2_parent_name   VARCHAR2(2000);
1638     l_condition             VARCHAR2(100);
1639     l_fac1_company_type     VARCHAR2(2000);
1640     l_fac1_company_name     VARCHAR2(2000);
1641     l_fac2_company_type     VARCHAR2(2000);
1642     l_fac2_company_name     VARCHAR2(2000);
1643     l_class_type            VARCHAR2(100);
1644     l_class_meaning         VARCHAR2(2000);
1645     l_severity              VARCHAR2(100);
1646     l_severity_meaning      VARCHAR2(2000);
1647     l_msg_count             NUMBER := 0;
1648     l_msg_data              VARCHAR2(2000) := NULL;
1649 
1650     g_object_name_failed    EXCEPTION;
1651 
1652     l_module_name           CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'stack_messages';
1653     l_debug_on              CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
1654 
1655 BEGIN
1656 
1657     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1658 
1659     IF l_debug_on THEN
1660        wsh_debug_sv.push(l_module_name);
1661        wsh_debug_sv.log (l_module_name,'No. of constraints violated : ',to_char(p_failed_constraints.COUNT));
1662     END IF;
1663     -- Loop pver p_failed_constraints and add messages
1664 
1665     FND_MSG_PUB.Count_And_Get (
1666      p_count         =>      l_msg_count,
1667      p_data          =>      l_msg_data ,
1668      p_encoded       =>      FND_API.G_FALSE );
1669 
1670     IF l_debug_on THEN
1671       wsh_debug_sv.log (l_module_name,'No. of messages already in stack : ',to_char(l_msg_count));
1672       --WSH_DEBUG_SV.pop(l_module_name);
1673     END IF;
1674 
1675     -- Remove duplicate constraints,from p_failed_constraints table.
1676     -- Unique constraints stored in l_failed_constraints table.
1677 
1678     remove_duplicate_const(
1679 	p_failed_constraints	=> p_failed_constraints,
1680 	x_return_status		=> l_return_status);
1681 
1682 
1683     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
1684          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
1685              raise FND_API.G_EXC_UNEXPECTED_ERROR;
1686           END IF;
1687     END IF;
1688 
1689     i := p_failed_constraints.FIRST;
1690     IF i IS NOT NULL THEN
1691      LOOP
1692 
1693      IF p_failed_constraints(i).constraint_id IS NOT NULL THEN
1694 
1695       IF l_debug_on THEN
1696          --wsh_debug_sv.push(l_module_name);
1697          wsh_debug_sv.log (l_module_name,'constraint id violated : ',to_char(p_failed_constraints(i).constraint_id));
1698       END IF;
1699 
1700       get_constraint_display(
1701              p_constraint_id           => p_failed_constraints(i).constraint_id,
1702              x_obj1_display            => l_object1_name,
1703              x_obj1_parent_display     => l_object1_parent_name,
1704              x_obj2_display            => l_object2_name,
1705              x_obj2_parent_display     => l_object2_parent_name,
1706              x_condition_display       => l_condition,
1707              x_fac1_company_type       => l_fac1_company_type,
1708              x_fac1_company_name       => l_fac1_company_name,
1709              x_fac2_company_type       => l_fac2_company_type,
1710              x_fac2_company_name       => l_fac2_company_name,
1711              x_comp_class_code         => l_class_type,
1712              x_severity                => l_severity,
1713              x_return_status           => l_return_status );
1714 
1715       IF l_return_status IN (WSH_UTIL_CORE.G_RET_STS_ERROR,WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR) THEN
1716             raise FND_API.G_EXC_UNEXPECTED_ERROR;
1717       END IF;
1718 
1719       l_class_meaning := WSH_XC_UTIL.Get_Lookup_Meaning(
1720                 p_lookup_code     =>   l_class_type,
1721                 p_lookup_type     =>   'WSH_FTE_COMP_CLASSES'
1722                 );
1723 
1724       IF l_class_meaning IS NULL THEN
1725          raise FND_API.G_EXC_UNEXPECTED_ERROR;
1726       END IF;
1727 
1728       l_severity_meaning := WSH_XC_UTIL.Get_Lookup_Meaning(
1729                 p_lookup_code     =>   l_severity,
1730                 p_lookup_type     =>   'WSH_FTE_VIOLATION_SEVERITY'
1731                 );
1732 
1733       IF l_severity_meaning IS NULL THEN
1734          raise FND_API.G_EXC_UNEXPECTED_ERROR;
1735       END IF;
1736 
1737       IF p_failed_constraints(i).entity_type = G_DELIVERY THEN
1738          l_entity := FND_MESSAGE.GET_STRING('FTE','FTE_ENTITY_DELIVERY');
1739       ELSIF p_failed_constraints(i).entity_type = G_DEL_DETAIL THEN
1740          l_entity := FND_MESSAGE.GET_STRING('FTE','FTE_ENTITY_DELIVERY_DETAIL');
1741       ELSIF p_failed_constraints(i).entity_type = G_DELIVERY_LEG THEN
1742          l_entity := FND_MESSAGE.GET_STRING('FTE','FTE_ENTITY_DELIVERY_LEG');
1743       ELSIF p_failed_constraints(i).entity_type = G_TRIP THEN
1744          l_entity := FND_MESSAGE.GET_STRING('FTE','FTE_ENTITY_TRIP');
1745       ELSIF p_failed_constraints(i).entity_type = G_STOP THEN
1746          l_entity := FND_MESSAGE.GET_STRING('FTE','FTE_ENTITY_STOP');
1747       ELSIF p_failed_constraints(i).entity_type = G_LANE THEN
1748          l_entity := FND_MESSAGE.GET_STRING('FTE','FTE_ENTITY_LANE');
1749       ELSIF p_failed_constraints(i).entity_type = G_CAR_SERVICE THEN
1750          l_entity := FND_MESSAGE.GET_STRING('FTE','FTE_ENTITY_CARRIER_SERVICE');
1751       ELSIF p_failed_constraints(i).entity_type = G_LOCATION THEN
1752          l_entity := FND_MESSAGE.GET_STRING('FTE','FTE_ENTITY_LOCATION');
1753       END IF;
1754 
1755       l_entity_id := (p_failed_constraints(i).entity_line_id);
1756 
1757       FND_MESSAGE.SET_NAME('FTE','FTE_COMP_VALIDATION_MESSAGE');
1758       FND_MESSAGE.SET_TOKEN('ENTITY',l_entity);
1759       FND_MESSAGE.SET_TOKEN('ID',to_char(l_entity_id));
1760       FND_MESSAGE.SET_TOKEN('TYPE',l_class_meaning);
1761       FND_MESSAGE.SET_TOKEN('OBJECT1',l_object1_name);
1762       FND_MESSAGE.SET_TOKEN('CONDITION',l_condition);
1763       FND_MESSAGE.SET_TOKEN('OBJECT2',l_object2_name);
1764       FND_MESSAGE.SET_TOKEN('SEVERITY',l_severity_meaning);
1765       FND_MSG_PUB.ADD;
1766 
1767       IF l_debug_on THEN
1768          wsh_debug_sv.log (l_module_name,'constraint found : ',to_char(i));
1769          wsh_debug_sv.log (l_module_name,'entity ',l_entity);
1770          wsh_debug_sv.log (l_module_name,'entity id ',to_char(l_entity_id));
1771          wsh_debug_sv.log (l_module_name,'class type ',l_class_type);
1772          wsh_debug_sv.log (l_module_name,'object1 name ',l_object1_name);
1773          wsh_debug_sv.log (l_module_name,'condition ',l_condition);
1774          wsh_debug_sv.log (l_module_name,'object2 name ',l_object2_name);
1775          wsh_debug_sv.log (l_module_name,'severity ',l_severity);
1776       END IF;
1777      END IF; -- constraint_id IS NOT NULL
1778 
1779      EXIT WHEN i = p_failed_constraints.LAST;
1780      i := p_failed_constraints.NEXT(i);
1781 
1782      END LOOP;
1783     END IF;
1784 
1785    -- Standard call to get message count and if count is 1,
1786    -- get message info.
1787 
1788     FND_MSG_PUB.Count_And_Get (
1789      p_count         =>      x_msg_count,
1790      p_data          =>      x_msg_data ,
1791      p_encoded       =>      FND_API.G_FALSE );
1792 
1793     IF l_debug_on THEN
1794       wsh_debug_sv.log (l_module_name,'No. of messages stacked : ',to_char(x_msg_count));
1795       WSH_DEBUG_SV.pop(l_module_name);
1796     END IF;
1797 
1798 EXCEPTION
1799     WHEN g_object_name_failed THEN
1800       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
1801       --
1802       IF l_debug_on THEN
1803         WSH_DEBUG_SV.pop(l_module_name,'get_constraint_display failed ');
1804       END IF;
1805       --
1806     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1807       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
1808       --
1809       IF l_debug_on THEN
1810         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1811         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
1812       END IF;
1813       --
1814     WHEN others THEN
1815       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.stack_messages');
1816       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1817       --
1818       IF l_debug_on THEN
1819         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1820         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
1821       END IF;
1822       --
1823 END stack_messages;
1824 
1825 
1826 --***************************************************************************--
1827 --========================================================================
1828 -- PROCEDURE : create_valid_entity_group  PRIVATE
1829 --                                        Called by the delivery and delivery detail
1830 --                                        API to build group
1831 --
1832 -- PARAMETERS: p_entity_rec               Record of input delivery OR delivery line
1833 --             p_group_tab                Output group table incremented by a new group for the
1834 --                                        input entity
1835 --             x_return_status            Return status
1836 -- COMMENT   : Output group in which entities can be put together
1837 --
1838 --========================================================================
1839 
1840 PROCEDURE create_valid_entity_group(
1841                   p_entity_rec            IN OUT NOCOPY  entity_rec_type,
1842                   p_group_tab             IN OUT NOCOPY  WSH_FTE_COMP_CONSTRAINT_PKG.cc_group_tab_type,
1843                   x_return_status         OUT NOCOPY     VARCHAR2)
1844 IS
1845 
1846     l_group_count    NUMBER :=   p_group_tab.COUNT;
1847 
1848     l_module_name    CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'create_valid_entity_group';
1849     l_debug_on       CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
1850 
1851 BEGIN
1852 
1853     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1854 
1855     IF l_debug_on THEN
1856        wsh_debug_sv.push(l_module_name);
1857     END IF;
1858 
1859     p_group_tab(l_group_count+1).group_index := l_group_count+1;
1860     p_group_tab(l_group_count+1).line_group_id := l_group_count+1;
1861 
1862     p_entity_rec.group_id := p_group_tab(l_group_count+1).line_group_id;
1863 
1864     --
1865     IF l_debug_on THEN
1866       WSH_DEBUG_SV.pop(l_module_name);
1867     END IF;
1868     --
1869 
1870 EXCEPTION
1871     WHEN others THEN
1872       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.create_valid_entity_group');
1873       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1874       --
1875       IF l_debug_on THEN
1876         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1877         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
1878       END IF;
1879       --
1880 END create_valid_entity_group;
1881 
1882 --***************************************************************************--
1883 --========================================================================
1884 -- PROCEDURE : populate_constraint_cache  PRIVATE
1885 --
1886 -- PARAMETERS: p_comp_class_code          Input compatibility class code
1887 --             x_return_status            Return status
1888 -- COMMENT   : Builds the database session caches
1889 --             for constraint definitions
1890 --========================================================================
1891 
1892 PROCEDURE populate_constraint_cache(
1893           p_comp_class_code          IN      VARCHAR2 DEFAULT NULL,
1894           x_return_status            OUT NOCOPY    VARCHAR2)
1895 IS
1896 
1897     CURSOR c_get_constraint_info(c_comp_class_id IN NUMBER) IS
1898     SELECT *
1899     FROM   WSH_FTE_COMP_CONSTRAINTS
1900     WHERE  COMPATIBILITY_CLASS_ID = nvl(c_comp_class_id,COMPATIBILITY_CLASS_ID)
1901     AND    nvl(trunc(EFFECTIVE_DATE_FROM,'DDD'),trunc(sysdate,'DDD')) <= trunc(sysdate,'DDD')
1902     AND    nvl(trunc(EFFECTIVE_DATE_TO,'DDD'),trunc(sysdate,'DDD')) >= trunc(sysdate,'DDD');
1903 
1904     l_hash_string      VARCHAR2(200):=NULL;
1905     l_hash_value       NUMBER:=0;
1906     l_comp_class_id    NUMBER:=NULL;
1907     l_constraint_rec   WSH_FTE_COMP_CONSTRAINTS%ROWTYPE;
1908 
1909     l_module_name      CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'populate_constraint_cache';
1910     l_debug_on         CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
1911 
1912 BEGIN
1913     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
1914 
1915     IF l_debug_on THEN
1916        WSH_DEBUG_SV.push(l_module_name);
1917        WSH_DEBUG_SV.logmsg(l_module_name,'p_comp_class_code : '||p_comp_class_code);
1918     END IF;
1919 
1920     IF p_comp_class_code IS NOT NULL THEN
1921        l_comp_class_id := get_compclass_id(p_comp_class_code);
1922 
1923        IF l_comp_class_id = g_unexp_num THEN
1924           raise FND_API.G_EXC_UNEXPECTED_ERROR;
1925        END IF;
1926        --
1927        IF l_debug_on THEN
1928           WSH_DEBUG_SV.logmsg(l_module_name,'Called get_compclass_id comp_class_id : '||l_comp_class_id);
1929        END IF;
1930        --
1931     END IF;
1932 
1933     -- Potentially when this API is called in case of a hash collision,
1934     -- the constraints cache will get rebuilt with all constraint definitions
1935     -- not only the constraint types that existed before the collision
1936     -- The only potential impact is more memory
1937 
1938     OPEN c_get_constraint_info(l_comp_class_id);
1939     LOOP
1940        FETCH c_get_constraint_info INTO l_constraint_rec;
1941        EXIT WHEN c_get_constraint_info%NOTFOUND;
1942 
1943        l_hash_string :=        (l_comp_class_id)||'-'||l_constraint_rec.constraint_object1_type||'-'||nvl(       to_char(l_constraint_rec.constraint_object1_id),
1944           l_constraint_rec.constraint_object1_value_char)||'-'||       (nvl(l_constraint_rec.object1_source_id,-9999))||
1945           '-'||l_constraint_rec.constraint_object2_type||'-'||nvl(to_char(l_constraint_rec.constraint_object2_id),l_constraint_rec.constraint_object2_value_char)||'-'||       (nvl(l_constraint_rec.object2_source_id,-9999));
1946 
1947        l_hash_value := dbms_utility.get_hash_value(
1948                                   name => l_hash_string,
1949                                   base => g_hash_base,
1950                                   hash_size => g_hash_size );
1951        --
1952        IF l_debug_on THEN
1953          WSH_DEBUG_SV.logmsg(l_module_name,'l_hash_string : '||l_hash_string);
1954          WSH_DEBUG_SV.logmsg(l_module_name,'l_hash_value : '||l_hash_value);
1955        END IF;
1956        --
1957 
1958        IF NOT g_comp_constraint_tab.EXISTS(l_hash_value) THEN
1959           g_comp_constraint_tab(l_hash_value) := l_constraint_rec;
1960        END IF;
1961 
1962     END LOOP;
1963     CLOSE c_get_constraint_info;
1964 
1965     --
1966     IF l_debug_on THEN
1967       WSH_DEBUG_SV.pop(l_module_name);
1968     END IF;
1969     --
1970 
1971 EXCEPTION
1972     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
1973       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
1974       --
1975       IF l_debug_on THEN
1976         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1977         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
1978       END IF;
1979       --
1980     WHEN others THEN
1981       IF c_get_constraint_info%ISOPEN THEN
1982          CLOSE c_get_constraint_info;
1983       END IF;
1984       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.populate_constraint_cache');
1985       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
1986       --
1987       IF l_debug_on THEN
1988         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
1989         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
1990       END IF;
1991       --
1992 END populate_constraint_cache;
1993 
1994 
1995 --***************************************************************************--
1996 --========================================================================
1997 -- FUNCTION  : check_cache               PRIVATE
1998 --
1999 -- PARAMETERS: p_hash_value              Input hash value
2000 --             p_hash_string             Input hash string corresponding to l_hash_value
2001 --             x_return_status           Return Status
2002 -- COMMENT   : Checks in global constraint cache if a record corresponding to
2003 --             l_hash_value and l_hash_string exists
2004 --             checks if hash string also matches for a match in hash value
2005 --             If it does not, constructs new hash value by increasing hash size
2006 --             and keeps on comparing
2007 --             Returns FALSE if there is no valid match
2008 --========================================================================
2009 
2010 FUNCTION check_cache (
2011              p_hash_value       IN   NUMBER,
2012              p_hash_string      IN   VARCHAR2 ) RETURN BOOLEAN
2013 IS
2014 
2015     l_hashval_exists    BOOLEAN := TRUE;
2016     l_hash_value        NUMBER := 0;
2017     lg_hash_string      VARCHAR2(2000) := NULL;
2018     l_return_status     VARCHAR2(1);
2019 
2020     l_debug_on          CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
2021     l_module_name       CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'check_cache';
2022 
2023 BEGIN
2024 
2025     --
2026     IF l_debug_on THEN
2027       wsh_debug_sv.push (l_module_name);
2028       wsh_debug_sv.logmsg(l_module_name,'p_hash_value : '||p_hash_value);
2029       wsh_debug_sv.logmsg(l_module_name,'p_hash_string : '||p_hash_string);
2030     END IF;
2031     --
2032 
2033     IF p_hash_value IS NULL OR p_hash_string IS NULL THEN
2034        --
2035        IF l_debug_on THEN
2036           wsh_debug_sv.pop (l_module_name);
2037        END IF;
2038        --
2039        RETURN FALSE;
2040     END IF;
2041 
2042     IF g_comp_constraint_tab.EXISTS(p_hash_value) THEN
2043 
2044        lg_hash_string := (g_comp_constraint_tab(p_hash_value).compatibility_class_id)||'-'||g_comp_constraint_tab(p_hash_value).constraint_object1_type||'-'||nvl(to_char(g_comp_constraint_tab(p_hash_value).constraint_object1_id),
2045        g_comp_constraint_tab(p_hash_value).constraint_object1_value_char)||'-'||(nvl(g_comp_constraint_tab(p_hash_value).object1_source_id,-9999))||
2046        '-'||g_comp_constraint_tab(p_hash_value).constraint_object2_type||'-'||nvl(to_char(g_comp_constraint_tab(p_hash_value).constraint_object2_id),g_comp_constraint_tab(p_hash_value).constraint_object2_value_char)||
2047        '-'||(nvl(g_comp_constraint_tab(p_hash_value).object2_source_id,-9999));
2048 
2049        IF l_debug_on THEN
2050           wsh_debug_sv.logmsg(l_module_name,'lg_hash_string : '||lg_hash_string);
2051        END IF;
2052 
2053        IF NOT lg_hash_string = p_hash_string THEN
2054           -- Hash collision with current g_hash_size for input p_hash_value
2055           l_hashval_exists := FALSE;
2056           WHILE NOT l_hashval_exists LOOP
2057            g_hash_size := g_hash_size + 1;
2058 
2059            -- Delete current constraint cache and
2060            -- rebuild current constraint cache with higher g_hash_size
2061 
2062            g_comp_constraint_tab.DELETE;
2063 
2064            populate_constraint_cache(
2065                --p_hash_size                =>    g_hash_size,
2066                x_return_status            =>    l_return_status) ;
2067 
2068            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
2069               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
2070                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
2071               END IF;
2072            END IF;
2073 
2074            --
2075            IF l_debug_on THEN
2076              WSH_DEBUG_SV.logmsg(l_module_name,'Called populate_constraint_cache return status : '||l_return_status);
2077            END IF;
2078            --
2079 
2080            l_hash_value := dbms_utility.get_hash_value(
2081                                   name => p_hash_string,
2082                                   base => g_hash_base,
2083                                   hash_size => g_hash_size );
2084 
2085            IF g_comp_constraint_tab.EXISTS(l_hash_value) THEN
2086 
2087               lg_hash_string := (g_comp_constraint_tab(l_hash_value).compatibility_class_id)||'-'||g_comp_constraint_tab(l_hash_value).constraint_object1_type||'-'||nvl(to_char(g_comp_constraint_tab(l_hash_value).constraint_object1_id),
2088               g_comp_constraint_tab(l_hash_value).constraint_object1_value_char)||'-'||(nvl(g_comp_constraint_tab(l_hash_value).object1_source_id,-9999))||
2089               '-'||g_comp_constraint_tab(l_hash_value).constraint_object2_type||'-'||nvl(to_char(g_comp_constraint_tab(l_hash_value).constraint_object2_id),g_comp_constraint_tab(l_hash_value).constraint_object2_value_char)||
2090               '-'||(nvl(g_comp_constraint_tab(l_hash_value).object2_source_id,-9999));
2091 
2092               IF l_debug_on THEN
2093                  wsh_debug_sv.logmsg(l_module_name,'lg_hash_string : '||lg_hash_string);
2094               END IF;
2095 
2096               IF lg_hash_string = p_hash_string THEN
2097                  -- Constraint found in new cache
2098                  l_hashval_exists := TRUE;
2099               ELSE
2100                  -- Still collision
2101                  l_hashval_exists := FALSE;
2102               END IF;
2103            ELSE
2104               -- No match in new cache for input hash string
2105               l_hashval_exists := FALSE;
2106               EXIT;
2107            END IF;
2108 
2109           END LOOP;
2110 
2111        END IF;
2112 
2113     ELSE
2114 
2115        l_hashval_exists := FALSE;
2116 
2117     END IF;
2118 
2119     --
2120     IF l_debug_on THEN
2121       wsh_debug_sv.pop (l_module_name);
2122     END IF;
2123     --
2124 
2125     RETURN l_hashval_exists;
2126 
2127 EXCEPTION
2128        WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2129        WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.check_cache');
2130       --
2131       IF l_debug_on THEN
2132         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
2133         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
2134       END IF;
2135       --
2136       RETURN FALSE;
2137       WHEN others THEN
2138       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.check_cache');
2139       --
2140       IF l_debug_on THEN
2141         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
2142         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
2143       END IF;
2144       --
2145       RETURN FALSE;
2146 END check_cache;
2147 
2148 
2149 
2150 --DUM_LOC
2151 --***************************************************************************--
2152 --========================================================================
2153 -- FUNCTION  : SORT_STOP_TABLE_ASC  PRIVATE
2154 --
2155 -- COMMENT   : Sorts  p_stop_table in ASCENDING order depending on PLANNED_ARRIVAL_DATE.
2156 --             In case two stops have the same PLANNED_ARRIVAL_DATE, Dummy locations
2157 --             appear before original locations.
2158 --	       SELECTION SORT - used to reduce the number of swaps
2159 --========================================================================
2160 PROCEDURE sort_stop_table_asc
2161 		(p_stop_table		IN	      stop_ccinfo_tab_type,
2162 		 x_sort_stop_table      OUT NOCOPY    stop_ccinfo_tab_type,
2163 		 x_return_status	OUT NOCOPY    VARCHAR2)
2164 
2165 IS
2166 
2167      min_pos		NUMBER;
2168      j			NUMBER;
2169      l_swap_rec		stop_ccinfo_rec_type;
2170      l_stop_table	stop_ccinfo_tab_type;
2171 
2172      l_module_name CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' ||'sort_stop_table_asc';
2173      l_debug_on    CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
2174 
2175 BEGIN
2176 
2177   IF l_debug_on THEN
2178           WSH_DEBUG_SV.push(l_module_name);
2179   END IF;
2180 
2181   x_return_status   := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
2182 
2183   l_stop_table      := p_stop_table;
2184 
2185   FOR i IN l_stop_table.FIRST..l_stop_table.LAST
2186   LOOP
2187 	min_pos := i;
2188 	j := l_stop_table.NEXT(i);
2189 
2190 	IF  j is NOT NULL THEN
2191 	LOOP
2192 
2193 	   IF ( l_stop_table(j).PLANNED_ARRIVAL_DATE < l_stop_table(min_pos).PLANNED_ARRIVAL_DATE) THEN
2194 		min_pos := j ;
2195         ELSIF (l_stop_table(j).PLANNED_ARRIVAL_DATE = l_stop_table(min_pos).PLANNED_ARRIVAL_DATE
2196 		  AND (l_stop_table(min_pos).PHYSICAL_LOCATION_ID IS  NULL AND
2197 		       l_stop_table(j).PHYSICAL_LOCATION_ID IS NOT NULL))
2198 	   THEN
2199 		min_pos := j;
2200 	   END IF;
2201 
2202 	   EXIT WHEN j= l_stop_table.LAST;
2203        j:= l_stop_table.NEXT(j);
2204      END LOOP;
2205      END IF;
2206 
2207 	 IF ( i <> min_pos ) THEN
2208 		 l_swap_rec  := l_stop_table(i);
2209 		 l_stop_table(i) := l_stop_table(min_pos);
2210 		 l_stop_table(min_pos)  := l_swap_rec;
2211 	 END IF;
2212 
2213    END LOOP;
2214 
2215    x_sort_stop_table := l_stop_table;
2216 
2217    IF l_debug_on THEN
2218 
2219 	  WSH_DEBUG_SV.logmsg(l_module_name,'Number of entries in Sorted table : '||x_sort_stop_table.count);
2220 	  FOR i in x_sort_stop_table.FIRST..x_sort_stop_table.LAST
2221   	  LOOP
2222 	    WSH_DEBUG_SV.logmsg(l_module_name,i||'STOP_ID'||x_sort_stop_table(i).STOP_ID||'Planned Arrival date '||x_sort_stop_table(i).PLANNED_ARRIVAL_DATE);
2223 	  END LOOP;
2224  	  WSH_DEBUG_SV.pop(l_module_name);
2225    END IF;
2226 
2227 EXCEPTION
2228 WHEN OTHERS THEN
2229       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.sort_stop_table_asc');
2230       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
2231 END sort_stop_table_asc;
2232 --DUM_LOC(E)
2233 
2234 
2235 
2236 --#REG-ZON
2237 --***************************************************************************--
2238 --
2239 --========================================================================
2240 -- PROCEDURE :  populate_reg_mustuse_cache            PRIVATE
2241 --
2242 -- PARAMETERS:  p_reg_class_id            REG-FAC Constraint Class Id.
2243 --		x_return_status           Return Status
2244 -- COMMENT   :  The cache constains Region -Facitlity MUST-USE constraints.
2245 --
2246 --========================================================================
2247 PROCEDURE populate_reg_mustuse_cache(
2248              p_reg_class_id             IN  NUMBER,
2249 	     x_return_status            OUT NOCOPY    VARCHAR2)
2250 IS
2251 
2252     CURSOR c_get_constraint_info(c_comp_class_id IN NUMBER) IS
2253     SELECT *
2254     FROM   WSH_FTE_COMP_CONSTRAINTS
2255     WHERE  COMPATIBILITY_CLASS_ID = c_comp_class_id
2256     AND    CONSTRAINT_TYPE        = 'I'
2257     AND    nvl(trunc(EFFECTIVE_DATE_FROM,'DDD'),trunc(sysdate,'DDD')) <= trunc(sysdate,'DDD')
2258     AND    nvl(trunc(EFFECTIVE_DATE_TO,'DDD'),trunc(sysdate,'DDD')) >= trunc(sysdate,'DDD');
2259 
2260     itr                NUMBER := 0;
2261     l_constraint_rec   WSH_FTE_COMP_CONSTRAINTS%ROWTYPE;
2262     l_module_name      CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'populate_reg_const_cache';
2263     l_debug_on         CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
2264 
2265 BEGIN
2266 
2267     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
2268 
2269     --
2270     IF l_debug_on THEN
2271         WSH_DEBUG_SV.push(l_module_name);
2272     END IF;
2273 
2274     --
2275     -- Cache needs to be populated only once in a Session.
2276     --
2277 
2278     IF (g_reg_const_cache.COUNT=0) THEN
2279 
2280        IF l_debug_on THEN
2281 	  WSH_DEBUG_SV.logmsg(l_module_name,'Populating g_reg_const_cache ');
2282        END IF;
2283 
2284        OPEN c_get_constraint_info(p_reg_class_id);
2285        /* Does not work in 8i
2286        FETCH c_get_constraint_info BULK COLLECT INTO g_reg_const_cache;
2287        */
2288 
2289        LOOP
2290        FETCH c_get_constraint_info INTO l_constraint_rec;
2291        EXIT WHEN c_get_constraint_info%NOTFOUND;
2292 
2293        itr := itr + 1;
2294        g_reg_const_cache(itr) := l_constraint_rec;
2295 
2296        END LOOP;
2297        CLOSE c_get_constraint_info;
2298 
2299     END IF;
2300 
2301     --
2302     IF l_debug_on THEN
2303 	WSH_DEBUG_SV.logmsg(l_module_name,' Number of entries in g_reg_const_cache : '||g_reg_const_cache.count);
2304         WSH_DEBUG_SV.pop(l_module_name);
2305     END IF;
2306     --
2307 EXCEPTION
2308   WHEN others THEN
2309       IF c_get_constraint_info%ISOPEN THEN
2310          CLOSE c_get_constraint_info;
2311       END IF;
2312 
2313       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.populate_reg_mustuse_cache');
2314       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
2315       --
2316       IF l_debug_on THEN
2317         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
2318         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
2319       END IF;
2320       --
2321 END populate_reg_mustuse_cache;
2322 
2323 
2324 --***************************************************************************--
2325 --
2326 --========================================================================
2327 -- PROCEDURE : add_region_constraint     PRIVATE
2328 --
2329 --PARAMETERS:  p_location_id		    Location id
2330 --	       p_object2_id		    Facility ID
2331 --	       p_constraint_id		    Constraint ID
2332 --					    ( Id is g_const_not_present when constraint
2333 --                                          is not present between entities)
2334 --	       p_constraint_type	    Constraint Type - E/I
2335 --	       x_return_status              Return Status
2336 -- COMMENT   :
2337 --	       Add  constraints to the location-facility cache.
2338 --	       The cache is stores following results
2339 --             a) LOCATION - FACILITY (INCLUSIVE CONSTRAINT/EXCLUSIVE)
2340 --                (Store location Facility which has inclusive constraint)
2341 --		  Location id - Facility ID - Constraint ID - I
2342 --		  Location id - Facility ID - Constraint ID - E
2343 --             b) LOCATION - FACILITY (EXCLUSIVE CONSTRAINT)
2344 --                (Store locations which have no exclusive  constriant)
2345 --                Location id - (-9999) - (-1111)  - I
2346 --========================================================================
2347 PROCEDURE add_region_constraint(
2348 	  p_location_id		IN	   NUMBER
2349 	, p_object2_id		IN	   NUMBER
2350 	, p_constraint_id	IN	   NUMBER
2351 	, p_constraint_type	IN   	   VARCHAR2
2352 	, x_return_status       OUT NOCOPY VARCHAR2)
2353 IS
2354 
2355 itr			NUMBER;
2356 l_count			NUMBER;
2357 l_region_hash_str	VARCHAR2(200);
2358 l_region_hash_val	NUMBER;
2359 l_module_name		CONSTANT VARCHAR2(100):= 'wsh.plsql.' ||G_PKG_NAME ||'.' ||'add_region_constraint';
2360 l_debug_on		CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
2361 
2362 BEGIN
2363     --
2364     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
2365     --
2366     IF l_debug_on THEN
2367        wsh_debug_sv.push (l_module_name);
2368        wsh_debug_sv.logmsg(l_module_name,'p_location_id : '||p_location_id);
2369        wsh_debug_sv.logmsg(l_module_name,'p_object2_id  : '||p_object2_id);
2370        wsh_debug_sv.logmsg(l_module_name,'p_constraint_id  : '||p_constraint_id);
2371        wsh_debug_sv.logmsg(l_module_name,'p_constraint_type: '||p_constraint_type);
2372     END IF;
2373     --
2374 
2375     l_region_hash_str :=    p_location_id  ||'-'
2376 		         || p_object2_id   ||'-'
2377 		         || p_constraint_type;
2378 
2379     l_region_hash_val := dbms_utility.get_hash_value(
2380 	  		 name => l_region_hash_str,
2381 			 base => l_reg_hash_base,
2382 		         hash_size =>l_reg_hash_size );
2383 
2384     IF l_debug_on THEN
2385 	  WSH_DEBUG_SV.logmsg(l_module_name,'l_region_hash_str : '||l_region_hash_str);
2386           WSH_DEBUG_SV.logmsg(l_module_name,'l_region_hash_val : '||l_region_hash_val);
2387     END IF;
2388 
2389 
2390     IF NOT (g_regloc_loc_cache.EXISTS(l_region_hash_val)) THEN
2391 	  g_regloc_loc_cache(l_region_hash_val).location_id	:= p_location_id;
2392 	  g_regloc_loc_cache(l_region_hash_val).object2_id	:= p_object2_id	;
2393 	  g_regloc_loc_cache(l_region_hash_val).constraint_id 	:= p_constraint_id;
2394 	  g_regloc_loc_cache(l_region_hash_val).constraint_type	:= p_constraint_type;
2395 	  g_regloc_loc_cache(l_region_hash_val).hash_string     := l_region_hash_str;
2396     ELSE
2397 	 -- Hash Collision has occured.
2398 	 -- Need to resolve it using Linear Probing.
2399 	 -- Iterate from the current position to check till found.
2400 
2401 	  IF l_debug_on THEN
2402 	     WSH_DEBUG_SV.logmsg(l_module_name,'HASH COLLISION for hash string :'||l_region_hash_str);
2403 	     WSH_DEBUG_SV.logmsg(l_module_name,'HASH value at COLLISION        :'||l_region_hash_val);
2404           END IF;
2405 
2406 	  itr := l_region_hash_val+1;
2407 
2408 	  LOOP
2409 	     EXIT WHEN NOT(g_regloc_loc_cache.EXISTS(itr));
2410 	     itr:=itr+1;
2411 	  END LOOP;
2412 
2413 	  IF l_debug_on THEN
2414 	     WSH_DEBUG_SV.logmsg(l_module_name,'HASH COLLISION resolved at position:'||itr);
2415           END IF;
2416 
2417 	  --Empty Space has been found.
2418 	  g_regloc_loc_cache(itr).location_id	  := p_location_id;
2419 	  g_regloc_loc_cache(itr).object2_id	  := p_object2_id	;
2420 	  g_regloc_loc_cache(itr).constraint_id   := p_constraint_id;
2421 	  g_regloc_loc_cache(itr).constraint_type := p_constraint_type;
2422 	  g_regloc_loc_cache(itr).hash_string     := l_region_hash_str;
2423 
2424      END IF;
2425 
2426      --
2427      IF l_debug_on THEN
2428         wsh_debug_sv.pop (l_module_name);
2429      END IF;
2430      --
2431 
2432 EXCEPTION
2433 WHEN others THEN
2434 
2435       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.add_region_constraint');
2436       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
2437       --
2438       IF l_debug_on THEN
2439         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
2440         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
2441       END IF;
2442       --
2443 END add_region_constraint;
2444 
2445 
2446 --************************************************************************
2447 --
2448 --========================================================================
2449 -- FUNCTION :  get_region_constraint          PRIVATE
2450 --
2451 -- PARAMETERS:   p_location_id		      Location id
2452 --		 p_object2_id		      Facility ID
2453 --		 p_constraint_type	      Constraint Type - E/I
2454 --		 x_return_status              Return Status
2455 --
2456 -- COMMENT   :  This procedure is used to retrieve the constraint id for a Region-FAC
2457 --		constrait. The cache stores location id of object 1 and object 2
2458 --========================================================================
2459 
2460 FUNCTION get_region_constraint
2461      (    p_location_id		IN	   NUMBER
2462 	, p_object2_id		IN	   NUMBER
2463 	, p_constraint_type	IN   	   VARCHAR2
2464 	, x_return_status       OUT NOCOPY VARCHAR2) RETURN NUMBER
2465 IS
2466 
2467      itr		NUMBER;
2468      l_count		NUMBER;
2469      l_slot_checked     NUMBER;
2470      l_region_hash_str	VARCHAR2(200);
2471      l_region_hash_val	NUMBER;
2472      l_module_name	CONSTANT VARCHAR2(100):= 'wsh.plsql.' ||G_PKG_NAME ||'.' ||'get_region_constraint';
2473      l_debug_on		CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
2474      l_constraint_id    NUMBER;
2475 
2476 BEGIN
2477 
2478     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
2479     --
2480     IF l_debug_on THEN
2481        wsh_debug_sv.push (l_module_name);
2482        wsh_debug_sv.logmsg(l_module_name,'p_location_id : '||p_location_id);
2483        wsh_debug_sv.logmsg(l_module_name,'p_object2_id  : '||p_object2_id);
2484     END IF;
2485     --
2486 
2487     l_region_hash_str :=  p_location_id  ||'-'
2488 		        || p_object2_id  ||'-'
2489 	                || p_constraint_type;
2490 
2491     l_region_hash_val := dbms_utility.get_hash_value(
2492 	 		 name => l_region_hash_str,
2493 			 base => l_reg_hash_base,
2494 		         hash_size =>l_reg_hash_size );
2495 
2496 
2497         IF l_debug_on THEN
2498 	    WSH_DEBUG_SV.logmsg(l_module_name,'l_region_hash_str : '||l_region_hash_str);
2499             WSH_DEBUG_SV.logmsg(l_module_name,'l_region_hash_val : '||l_region_hash_val);
2500         END IF;
2501 
2502         IF (NOT g_regloc_loc_cache.EXISTS(l_region_hash_val)) THEN
2503 	     -- implies entry was not made
2504 	     l_constraint_id := g_loc_reg_not_validated;
2505 
2506 	    IF l_debug_on THEN
2507 	      WSH_DEBUG_SV.logmsg(l_module_name,'Location has not been validated before');
2508             END IF;
2509 
2510 	ELSIF (g_regloc_loc_cache(l_region_hash_val).hash_string = l_region_hash_str) THEN
2511 	     -- Implies entry is present there
2512 	     l_constraint_id :=g_regloc_loc_cache(l_region_hash_val).constraint_id;
2513 
2514 	ELSE
2515 	     -- A collision has occured;
2516 
2517 	   IF l_debug_on THEN
2518 	      WSH_DEBUG_SV.logmsg(l_module_name,'Collision occured while retriving constraint');
2519            END IF;
2520 
2521 	   itr		  := l_region_hash_val+1;
2522 	   l_count	  := g_regloc_loc_cache.COUNT;
2523 	   l_slot_checked := 1;
2524 
2525 	   --
2526 	   -- We need to check total slots checked and total number
2527 	   -- of entries present , because in cases where entry is
2528 	   -- not present we will get in an infinite loop.
2529 	   --
2530 
2531 	   LOOP
2532 
2533 	      EXIT WHEN (g_regloc_loc_cache(itr).hash_string = l_region_hash_str)
2534 			OR (l_slot_checked=l_count);
2535 	      itr:=itr+1;
2536 	      l_slot_checked:=l_slot_checked+1;
2537 
2538 	   END LOOP;
2539 
2540 	   IF (l_slot_checked = l_count) THEN
2541 	        -- it implies could not find through the cache
2542 	        l_constraint_id := g_loc_reg_not_validated;
2543 	        IF l_debug_on THEN
2544 		   WSH_DEBUG_SV.logmsg(l_module_name,'Location has not been validated before');
2545 		END IF;
2546            ELSE
2547 	        -- found in the cache.
2548   	        l_constraint_id := g_regloc_loc_cache(itr).constraint_id;
2549 	   END IF;
2550 
2551         END IF;
2552 
2553     --
2554     IF l_debug_on THEN
2555         WSH_DEBUG_SV.logmsg(l_module_name,'l_constraint_id : '||l_constraint_id);
2556 	WSH_DEBUG_SV.pop (l_module_name);
2557     END IF;
2558     --
2559 
2560     RETURN l_constraint_id ;
2561 
2562 EXCEPTION
2563 WHEN OTHERS THEN
2564 
2565       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.get_region_constraint');
2566       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
2567       --
2568       IF l_debug_on THEN
2569         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
2570         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
2571       END IF;
2572       --
2573 END get_region_constraint;
2574 
2575 /*
2576 For  handling cases where we have both an inclusive constraint and an exclusive constraint
2577 Code change in validate_region_constraint
2578 
2579     If inclusive constraint is found at zone level then
2580       if the zone table has multiple enteries.
2581 	 LOOP through table of zones to see if COMPLEMENT CONSTRAINT is present
2582 	      if (COMPLEMENT - CONSTRIANT ) then
2583 		 it implies we have both inclusive and exclusive constriant
2584 		 NONE SHOULD APPLY.
2585 		 RETURN .
2586 	      END IF;
2587 	 Iterate through the table
2588 	 END LOOP;
2589       End if
2590      End if
2591 */
2592 --========================================================================
2593 --
2594 --========================================================================
2595 -- PROCEDURE : validate_region_constraint        PRIVATE
2596 --
2597 -- PARAMETERS:
2598 --             p_location_id              Constraint Object1 id
2599 --             p_constraint_type          Constraint Type : Exclusive/Inclusive
2600 --             p_object2_val_num          Constraint Object2 id
2601 --             x_validate_result          Constraint Validation result : S / E / W
2602 --             x_failed_constraint        failed constraint id in case of failure, null if success
2603 --             x_return_status            Return status
2604 -- COMMENT   :
2605 --      This is an internal procedure to determine if exclusive region/zone facility
2606 --      constraint  has been defined for a given Region/Zone and facility
2607 --      This procedure is called from WSH_FTE_COMP_CONSTRAINT_PKG.validate_constraint.
2608 --      The procedure First validates Region Level Constraints and then Zone
2609 --      Level constraints.
2610 --========================================================================
2611 
2612 PROCEDURE validate_region_constraint(
2613              p_location_id              IN	      NUMBER   DEFAULT NULL,
2614 	     p_constraint_type          IN	      VARCHAR2 DEFAULT 'E',
2615 	     p_object2_val_num          IN	      NUMBER   DEFAULT NULL,
2616 	     x_validate_result          OUT NOCOPY    VARCHAR2,
2617              x_failed_constraint        OUT NOCOPY    line_constraint_rec_type,
2618              x_return_status            OUT NOCOPY    VARCHAR2)
2619 IS
2620     l_region_tab         WSH_UTIL_CORE.ID_TAB_TYPE;
2621     l_zone_tab		 WSH_UTIL_CORE.ID_TAB_TYPE;
2622     l_module_name        CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'validate_region_constraint';
2623     l_debug_on           CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
2624     l_comp_class_code    CONSTANT VARCHAR2(30) := G_REGION_FACILITY;
2625     l_complement_constraint_type  VARCHAR2(1);
2626     l_comp_const_exists           BOOLEAN :=FALSE;
2627 
2628     l_hash_value         NUMBER;
2629     l_comp_class_id      NUMBER:=0;
2630     l_master_org_id      NUMBER:=0;
2631     r_itr		 NUMBER;
2632     z_itr                NUMBER;
2633     c_itr		 NUMBER;
2634 
2635     l_object1_id         NUMBER:=0;
2636     l_object2_id         NUMBER:=p_object2_val_num;
2637     l_zone_id            NUMBER;
2638     l_region_id          NUMBER;
2639     c_zone_id		 NUMBER;
2640     c_zone_hash_value	 NUMBER;
2641     c_zone_hash_string   VARCHAR2(200);
2642     l_reg_hash_string    VARCHAR2(200);
2643     l_reg_hash_value	 NUMBER;
2644     l_zone_hash_string   VARCHAR2(200);
2645     l_zone_hash_value    NUMBER;
2646 
2647     l_constraint_id	 NUMBER;
2648     l_return_status      VARCHAR2(1);
2649 
2650 BEGIN
2651 
2652         IF l_debug_on THEN
2653           WSH_DEBUG_SV.push(l_module_name);
2654           WSH_DEBUG_SV.logmsg(l_module_name,'Location Id       '||p_location_id);
2655           WSH_DEBUG_SV.logmsg(l_module_name,'Object2 val num : '||p_object2_val_num);
2656         END IF;
2657 
2658         x_return_status   := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
2659         x_validate_result := 'S';
2660 
2661         l_hash_value := dbms_utility.get_hash_value(
2662                                   name => l_comp_class_code,
2663                                   base => g_hash_base,
2664                                   hash_size =>g_hash_size );
2665 
2666         IF NOT (g_comp_class_tab.EXISTS(l_hash_value) AND
2667              g_comp_class_tab(l_hash_value).compatibility_class_code = l_comp_class_code) THEN
2668 
2669              populate_constraint_cache(
2670 	 	p_comp_class_code  =>  l_comp_class_code,
2671 	        x_return_status    =>  l_return_status) ;
2672 
2673             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
2674                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
2675                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
2676                END IF;
2677             END IF;
2678 
2679 	    --
2680             IF l_debug_on THEN
2681                WSH_DEBUG_SV.logmsg(l_module_name,'Return status after calling populate_constraint_cache  : '||l_return_status);
2682             END IF;
2683             --
2684         END IF;
2685 
2686         --
2687         -- Check in the Hash, If found in the cache then Return.
2688  	-- Passing the validation parameters.
2689         --
2690 
2691  	l_constraint_id := get_region_constraint(
2692 		          p_location_id	    => p_location_id
2693 		       ,  p_object2_id	    => l_object2_id
2694 		       ,  p_constraint_type => p_constraint_type
2695 		       ,  x_return_status   => l_return_status);
2696 
2697 
2698         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
2699            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
2700               raise FND_API.G_EXC_UNEXPECTED_ERROR;
2701            END IF;
2702         END IF;
2703 
2704         --
2705 	-- Exclusive constraint is present.
2706 	-- Cache stores exclusive constriants that have been validated.
2707 	--
2708 
2709 
2710 	IF  (l_constraint_id <> g_loc_reg_not_validated) THEN
2711 
2712 	   IF  (l_constraint_id <> g_const_not_present) THEN
2713 
2714 		x_validate_result := g_comp_class_tab(l_hash_value).constraint_violation;
2715                 x_failed_constraint.constraint_id := l_constraint_id;
2716                 x_failed_constraint.constraint_class_code := l_comp_class_code;
2717                 x_failed_constraint.violation_type := g_comp_class_tab(l_hash_value).constraint_violation;
2718 
2719 	   END IF;
2720 	   --
2721            IF l_debug_on THEN
2722 		 IF (l_constraint_id = g_const_not_present) THEN
2723 		     wsh_debug_sv.logmsg(l_module_name,'Region level constraints not present for location '||p_location_id);
2724 		 ELSE
2725   	             wsh_debug_sv.logmsg(l_module_name,'Region level constraint '||l_constraint_id||' present for location '||p_location_id);
2726 		 END IF;
2727 		 WSH_DEBUG_SV.pop(l_module_name);
2728 	   END IF;
2729            --
2730    	   RETURN;
2731 
2732 	END IF;
2733 
2734 	IF l_debug_on THEN
2735 	    wsh_debug_sv.logmsg(l_module_name,'Validating Region/Zone level constraints for location '||p_location_id);
2736 	END IF;
2737 
2738 
2739 	l_comp_class_id := g_comp_class_tab(l_hash_value).compatibility_class_id;
2740 
2741 
2742 	WSH_REGIONS_SEARCH_PKG.Get_All_RegionId_Matches(
2743 		 p_location_id		=> p_location_id,
2744 		 p_use_cache		=> TRUE,
2745 		 p_lang_code		=> USERENV('LANG'),
2746 		 x_region_tab		=> l_region_tab,
2747 		 x_return_status        => l_return_status);
2748 
2749 	IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
2750            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
2751               raise FND_API.G_EXC_UNEXPECTED_ERROR;
2752            END IF;
2753         END IF;
2754 
2755 	--
2756 	r_itr:= l_region_tab.FIRST;
2757 
2758 	IF r_itr IS NOT NULL THEN
2759 	    LOOP
2760           	-- Object id is the current region id
2761 		l_region_id 	    := l_region_tab(r_itr);
2762 
2763 		IF l_debug_on THEN
2764 			wsh_debug_sv.logmsg(l_module_name,'Validating for Region :'||l_region_id);
2765 		END IF;
2766 
2767 		l_reg_hash_string   :=   l_comp_class_id||'-'
2768 	    	                      ||'REG'||'-'
2769 				      ||l_region_id||'-'
2770 				      ||(-9999)||'-'
2771 				      ||'FAC'||'-'
2772                                       || to_char(l_object2_id)||'-'
2773                                       ||(-9999);
2774 
2775 	        l_reg_hash_value := dbms_utility.get_hash_value(
2776 					name => l_reg_hash_string,
2777 	                                base => g_hash_base,
2778 		                        hash_size =>g_hash_size);
2779 
2780 		IF check_cache(l_reg_hash_value,l_reg_hash_string) THEN
2781 
2782 			IF g_comp_constraint_tab(l_reg_hash_value).constraint_type = p_constraint_type THEN
2783 		             x_validate_result := g_comp_class_tab(l_hash_value).constraint_violation;
2784                              x_failed_constraint.constraint_id := g_comp_constraint_tab(l_reg_hash_value).compatibility_id;
2785                              x_failed_constraint.constraint_class_code := l_comp_class_code;
2786                              x_failed_constraint.violation_type := g_comp_class_tab(l_hash_value).constraint_violation;
2787 
2788 			     --
2789 			     -- We have a constraint for the location which we need to
2790 			     -- add to our region constraint cache.
2791 			     --
2792 			     add_region_constraint(
2793 				  p_location_id	       => p_location_id
2794 			 	 ,p_object2_id	       => l_object2_id
2795 				 ,p_constraint_id      => g_comp_constraint_tab(l_reg_hash_value).compatibility_id
2796 				 ,p_constraint_type    => p_constraint_type
2797 				 ,x_return_status      => l_return_status);
2798 
2799 			      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
2800 				IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
2801 				   raise FND_API.G_EXC_UNEXPECTED_ERROR;
2802 				END IF;
2803 			     END IF;
2804 
2805 			     IF l_debug_on THEN
2806 			           wsh_debug_sv.pop(l_module_name);
2807 			     END IF;
2808 			     RETURN;
2809 
2810 			END IF;
2811                 END IF;
2812 
2813                 -- l_object1_id currently holds the region id
2814 		WSH_REGIONS_SEARCH_PKG.Get_All_Zone_Matches(
2815 			p_region_id		=> l_region_id,
2816 			x_zone_tab		=> l_zone_tab,
2817 			x_return_status         => l_return_status);
2818 
2819 		IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
2820 	          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
2821 		      raise FND_API.G_EXC_UNEXPECTED_ERROR;
2822 	          END IF;
2823   	        END IF;
2824 
2825 		z_itr:= l_zone_tab.FIRST;
2826 		-- Region may not belong to any zone.
2827     	        IF z_itr IS NOT NULL THEN
2828 		LOOP
2829 		      l_zone_id 	    := l_zone_tab(z_itr);
2830 
2831 		      IF l_debug_on THEN
2832 			  wsh_debug_sv.logmsg(l_module_name,'Validating for Zone :'||l_zone_id);
2833 		      END IF;
2834 
2835 		      l_zone_hash_string    := l_comp_class_id||'-'
2836 	    	                               ||'ZON'||'-'
2837 				               ||l_zone_id||'-'
2838 				               || (-9999)||'-'
2839 				               ||'FAC'||'-'
2840                                                ||to_char(l_object2_id)||'-'
2841                                                ||(-9999);
2842 
2843 		      l_zone_hash_value := dbms_utility.get_hash_value(
2844 					name => l_zone_hash_string,
2845 	                                base => g_hash_base,
2846 		                        hash_size =>g_hash_size);
2847 
2848 
2849 		       IF check_cache(l_zone_hash_value,l_zone_hash_string) THEN
2850 			  IF g_comp_constraint_tab(l_zone_hash_value).constraint_type = p_constraint_type THEN
2851 
2852 			     --	It implies  a constraint has been found.
2853 			     -- Check if we have constraint of another type.
2854 			     --
2855 
2856  			     IF (l_zone_tab.COUNT > 1) THEN
2857 
2858 				l_comp_const_exists :=FALSE;
2859 
2860 				IF (p_constraint_type ='E') THEN
2861 				    l_complement_constraint_type :='I';
2862 			        ELSE
2863 				    l_complement_constraint_type :='E';
2864 			        END IF;
2865 
2866 				c_itr := l_zone_tab.FIRST;
2867 
2868   				LOOP
2869 				   c_zone_id := l_zone_tab(c_itr);
2870 				   c_zone_hash_string := l_comp_class_id||'-'
2871 		    	                               ||'ZON'||'-'
2872 					               || c_zone_id||'-'
2873 					               || (-9999)||'-'
2874 					               ||'FAC'||'-'
2875 						       ||to_char(l_object2_id)||'-'
2876 			                               ||(-9999);
2877 
2878 				   c_zone_hash_value := dbms_utility.get_hash_value(
2879 							name => c_zone_hash_string,
2880 							base => g_hash_base,
2881 							hash_size =>g_hash_size);
2882 
2883 				   IF check_cache(c_zone_hash_value,c_zone_hash_string) THEN
2884 				      IF g_comp_constraint_tab(c_zone_hash_value).constraint_type = l_complement_constraint_type THEN
2885 				        -- Both inclusive and exclusive constraints have been defined
2886 					IF l_debug_on THEN
2887 				            WSH_DEBUG_SV.logmsg(l_module_name,'Both Inclusive and Exclusive Zone level constraints defined for location'||p_location_id);
2888 					END IF;
2889 	       			        l_comp_const_exists:= TRUE;
2890 					EXIT;
2891 				       END IF;
2892 			 	   END IF;
2893 
2894 			          EXIT WHEN c_itr = l_zone_tab.LAST;
2895 			          c_itr:= l_zone_tab.NEXT(c_itr);
2896 				  END LOOP;
2897 
2898 				END IF;
2899 
2900 			        --
2901 				--If complement constraint exist it means we need to
2902 	  		        --check the next level
2903 				--
2904 
2905 				IF NOT(l_comp_const_exists) THEN
2906 					x_validate_result := g_comp_class_tab(l_hash_value).constraint_violation;
2907 					x_failed_constraint.constraint_id := g_comp_constraint_tab(l_zone_hash_value).compatibility_id;
2908 	                                x_failed_constraint.constraint_class_code := l_comp_class_code;
2909 		                        x_failed_constraint.violation_type := g_comp_class_tab(l_hash_value).constraint_violation;
2910 
2911 			           add_region_constraint(
2912 			     	        p_location_id	       => p_location_id
2913 			 	       ,p_object2_id	       => l_object2_id
2914 				       ,p_constraint_id      => g_comp_constraint_tab(l_zone_hash_value).compatibility_id
2915 				       ,p_constraint_type    => p_constraint_type
2916 				       ,x_return_status      => l_return_status);
2917 
2918 
2919                 	  	   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
2920 				     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
2921 				        raise FND_API.G_EXC_UNEXPECTED_ERROR;
2922 				     END IF;
2923 			           END IF;
2924 
2925 		 	           IF l_debug_on THEN
2926 				      wsh_debug_sv.pop(l_module_name);
2927                                    END IF;
2928   		            	   RETURN;
2929 				END IF;	--not (l_comp_const_exist)
2930 			    END IF;
2931                         END IF;
2932 
2933 		 EXIT WHEN z_itr = l_zone_tab.LAST;
2934                  z_itr:= l_zone_tab.NEXT(z_itr);
2935 	         END LOOP;
2936    	         END IF;
2937 
2938 	    EXIT WHEN r_itr = l_region_tab.LAST;
2939             r_itr:= l_region_tab.NEXT(r_itr);
2940 	END LOOP;
2941     END IF;
2942 
2943     --
2944     -- If we reach here we do not have any constraint present
2945     -- between location and the object.
2946     --
2947     IF l_debug_on THEN
2948 	wsh_debug_sv.logmsg(l_module_name,'No Region/Zone level constraint present for location :'||p_location_id);
2949     END IF;
2950 
2951     add_region_constraint(
2952 			  p_location_id	       => p_location_id
2953 		 	 ,p_object2_id	       => l_object2_id
2954 			 ,p_constraint_id      => g_const_not_present
2955 			 ,p_constraint_type    => p_constraint_type
2956 			 ,x_return_status      => l_return_status);
2957 
2958     IF l_debug_on THEN
2959         wsh_debug_sv.pop(l_module_name);
2960     END IF;
2961 
2962 EXCEPTION
2963 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
2964       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
2965 
2966       IF l_debug_on THEN
2967         WSH_DEBUG_SV.pop(l_module_name,'unexpected_error');
2968       END IF;
2969       --
2970 WHEN OTHERS THEN
2971       --
2972       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.validate_region_constraint');
2973       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
2974 
2975       IF l_debug_on THEN
2976         WSH_DEBUG_SV.pop(l_module_name,'unexpected_error');
2977       END IF;
2978 
2979       --
2980 END validate_region_constraint;
2981 
2982 
2983 
2984 /*
2985 For handling both inclusive and exclusive constraints
2986 strategy  is before adding Zone in the ERROR stack see
2987 whether any exclusive constriant exist for that location.
2988 Chagne has to be made at this point only.
2989 
2990 Suppose we have zone A, B
2991 For zone A should include FAC X,
2992     zone B should not include FAC X
2993 Only in such a case the constraints should cancel out,
2994 In cases zone A should include FAC Y
2995   	 zone B should not include FAC X
2996 Constraint should not cancel.
2997 
2998 Pseudo Code -
2999 
3000 For Zone -
3001 
3002 1) After iterating through Zone Cache, if we find an Inclusive Constraint
3003    that has not been satisfied, then store the facility id in variable 'K'
3004 
3005    IF NUMBER of Zones for the region is greater than 1
3006       Make the Hash String of the type
3007 		(Zone-in-tab),FAC - K, Exclusive
3008       Search in the cache, if found in the cache it implies we have both
3009       an inclusive and exclusive constraint.
3010       Change status found to found, and Validation Result to 'S'
3011    END LOOP;
3012 */
3013 --***************************************************************************--
3014 --
3015 --========================================================================
3016 -- PROCEDURE : check_reg_incl_facilities PRIVATE
3017 --
3018 -- PARAMETERS:
3019 --             p_entity_type              Entity for which check is running
3020 --             p_entity_id                Entity id for which check is running
3021 --             p_location_id              Constraint Object1 id
3022 --             p_location_list            Table of location ids to be checked as
3023 --                                        constraint object 2
3024 --             x_validate_result          Constraint Validation result : S / E / W
3025 --             x_failed_constraint        failed constraint table
3026 --             x_return_status            Return status
3027 -- COMMENT   :
3028 -- For a given location id , the procedure will validate for must use
3029 -- constraints against a list of locations.
3030 --========================================================================
3031 
3032 PROCEDURE check_reg_incl_facilities(
3033             p_entity_type              IN      VARCHAR2,
3034             p_entity_id                IN      NUMBER,
3035             p_location_id              IN      NUMBER,
3036             p_location_list            IN      WSH_UTIL_CORE.id_tab_type,
3037             x_validate_result          OUT NOCOPY     VARCHAR2,
3038             x_failed_constraint        IN  OUT NOCOPY  line_constraint_tab_type,
3039             x_return_status            OUT NOCOPY     VARCHAR2)
3040 IS
3041 
3042    l_hash_value           NUMBER;
3043    l_validate_result      VARCHAR2(1);
3044    l_region_tab           WSH_UTIL_CORE.ID_TAB_TYPE;
3045    l_zone_tab		  WSH_UTIL_CORE.ID_TAB_TYPE;
3046    l_comp_class_code      VARCHAR2(30) := G_REGION_FACILITY;
3047    l_reg_comp_class_id    NUMBER :=0;
3048 
3049    r_itr		  NUMBER :=0;
3050    z_itr                  NUMBER :=0;
3051    itr                    NUMBER :=0;
3052 
3053    failed_cons_last       NUMBER := x_failed_constraint.COUNT;
3054    l_fail_rec_cont        NUMBER :=0;
3055 
3056    l_constraint_found     BOOLEAN :=FALSE;
3057    l_region_id		  NUMBER  :=0;
3058    l_reg_hash_string	  VARCHAR2(200);
3059    l_reg_hash_str_const   VARCHAR2(200);
3060    l_reg_hash_value	  NUMBER;
3061 
3062    l_constraint_id        NUMBER;
3063 
3064 
3065    add_constraint	   BOOLEAN;
3066    l_fac_id		   NUMBER;
3067    ex_itr		   NUMBER;
3068    ex_zone_id		   NUMBER;
3069    l_zone_hash_excl_string VARCHAR2(200);
3070    l_zone_hash_excl_value  NUMBER;
3071 
3072 
3073    l_zone_id              NUMBER :=0;
3074    l_zone_hash_string     VARCHAR2(200);
3075    l_zone_hash_str_const  VARCHAR2(200);
3076    l_zone_hash_value      NUMBER;
3077 
3078    l_return_status        VARCHAR2(1);
3079 
3080    l_module_name          CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME ||'.'||'check_reg_incl_facilities';
3081    l_debug_on             CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
3082 
3083 BEGIN
3084 
3085     x_return_status   := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
3086     x_validate_result := 'F';
3087     l_validate_result := 'F';
3088 
3089     IF l_debug_on THEN
3090       wsh_debug_sv.push(l_module_name);
3091       WSH_DEBUG_SV.logmsg(l_module_name,'Object 1 Location id  : '||p_location_id);
3092       WSH_DEBUG_SV.logmsg(l_module_name,'Location list  count  : '||p_location_list.count);
3093     END IF;
3094 
3095     -- Check whether NO inclusive constriant occurs for the given location id
3096     -- If NO constraints found then return with status 'S'
3097 
3098     l_constraint_id := get_region_constraint(
3099 			 p_location_id	 => p_location_id
3100 		       , p_object2_id	 => g_const_not_present
3101 		       , p_constraint_type => 'I'
3102 		       , x_return_status   => l_return_status);
3103 
3104 
3105     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
3106            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
3107               raise FND_API.G_EXC_UNEXPECTED_ERROR;
3108            END IF;
3109     END IF;
3110 
3111 
3112     IF (l_constraint_id = g_incl_cons_not_present) THEN
3113         -- No constraint present for the location
3114         x_validate_result := 'S';
3115 
3116 	IF l_debug_on THEN
3117 	  WSH_DEBUG_SV.logmsg(l_module_name,'No REG/ZON Inclusive constraints defined for location - '||p_location_id);
3118 	  wsh_debug_sv.pop(l_module_name);
3119 	END IF;
3120 
3121 	RETURN;
3122     END IF;
3123 
3124     --
3125     -- Populate REG-FAC cache.
3126     --
3127 
3128     l_hash_value := dbms_utility.get_hash_value(
3129                              name => l_comp_class_code,
3130                              base => g_hash_base,
3131                              hash_size =>g_hash_size);
3132 
3133     IF NOT (g_comp_class_tab.EXISTS(l_hash_value) AND
3134             g_comp_class_tab(l_hash_value).compatibility_class_code = l_comp_class_code) THEN
3135 
3136        populate_constraint_cache(
3137           p_comp_class_code          =>    l_comp_class_code,
3138           x_return_status            =>    l_return_status) ;
3139 
3140       --
3141       IF l_debug_on THEN
3142         WSH_DEBUG_SV.logmsg(l_module_name,'Called populate_constraint_cache return status : '||l_return_status);
3143       END IF;
3144       --
3145 
3146       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
3147          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
3148             raise FND_API.G_EXC_UNEXPECTED_ERROR;
3149          END IF;
3150       END IF;
3151 
3152     END IF;
3153 
3154     l_reg_comp_class_id := g_comp_class_tab(l_hash_value).COMPATIBILITY_CLASS_ID;
3155 
3156     WSH_REGIONS_SEARCH_PKG.Get_All_RegionId_Matches(
3157 	 p_location_id		=> p_location_id,
3158 	 p_use_cache		=> TRUE,
3159 	 p_lang_code		=> USERENV('LANG'),
3160 	 x_region_tab		=> l_region_tab,
3161 	 x_return_status        => l_return_status);
3162 
3163     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
3164            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
3165               raise FND_API.G_EXC_UNEXPECTED_ERROR;
3166            END IF;
3167     END IF;
3168 
3169     -- ITERATE THROUGH THE REGION TAB.
3170     r_itr:= l_region_tab.FIRST;
3171 
3172     l_fail_rec_cont := failed_cons_last;
3173 
3174     IF (r_itr IS NOT NULL) THEN
3175 
3176 	LOOP
3177 
3178 	    l_region_id          := l_region_tab(r_itr);
3179 
3180 	    IF l_debug_on THEN
3181 		   wsh_debug_sv.logmsg(l_module_name,'Validating inclusive constraints for Region :'||l_region_id);
3182 	    END IF;
3183 
3184 	    l_reg_hash_str_const := l_reg_comp_class_id||'-'
3185 	    	                   ||'REG'||'-'
3186 				   ||l_region_id||'-'
3187 				   ||(-9999)||'-'
3188 				   ||'FAC'||'-' ;
3189 
3190 	    itr := p_location_list.FIRST;
3191 
3192             IF itr IS NOT NULL THEN
3193      	       LOOP
3194 		  --
3195 		  IF l_debug_on THEN
3196 		     WSH_DEBUG_SV.logmsg(l_module_name,'p_location_list  : '||p_location_list(itr));
3197 		  END IF;
3198 	          --
3199 	          l_reg_hash_string:=l_reg_hash_str_const||(p_location_list(itr))||'-'||(-9999);
3200 
3201 		  l_reg_hash_value := dbms_utility.get_hash_value(
3202 	                                  name => l_reg_hash_string,
3203 		                          base => g_hash_base,
3204 			                  hash_size =>g_hash_size );
3205 		  --
3206 		  IF l_debug_on THEN
3207 		     WSH_DEBUG_SV.logmsg(l_module_name,'l_reg_hash_string : '||l_reg_hash_string);
3208 		     WSH_DEBUG_SV.logmsg(l_module_name,'l_reg_hash_value  : '||l_reg_hash_value);
3209 		  END IF;
3210 	          --
3211 
3212 		  IF check_cache(l_reg_hash_value,l_reg_hash_string) THEN
3213 		      IF g_comp_constraint_tab(l_reg_hash_value).constraint_type = 'I' THEN
3214 		           x_validate_result := 'S';
3215 		           l_validate_result := 'S';
3216 			   l_constraint_found:= TRUE;
3217 
3218 			   IF l_debug_on THEN
3219 			      wsh_debug_sv.logmsg(l_module_name,'Inclusive Constraint Found ');
3220 			   END IF;
3221 
3222 			   EXIT;
3223 		       END IF;
3224 		  END IF;
3225 
3226 		  EXIT WHEN itr =p_location_list.LAST;
3227 	     	  itr := p_location_list.NEXT(itr);
3228 
3229 	       END LOOP;
3230             END IF;
3231 
3232             IF NOT (l_constraint_found) THEN
3233 
3234 	    -- Implies constraint was not found
3235 	    -- Loop over the constraints table , with current region id
3236 
3237                 IF (nvl(g_reg_const_cache.count,0)=0) THEN
3238 
3239 			populate_reg_mustuse_cache(
3240 			          p_reg_class_id  => l_reg_comp_class_id,
3241 			          x_return_status => l_return_status);
3242                 	--
3243                         IF l_debug_on THEN
3244                               WSH_DEBUG_SV.logmsg(l_module_name,'Called populate_reg_mustuse_cache return status:'||l_return_status);
3245                         END IF;
3246                         --
3247 
3248                         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
3249                               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
3250                                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
3251                               END IF;
3252                         END IF;
3253 		END IF;
3254 
3255 		itr := g_reg_const_cache.FIRST;
3256 
3257 		IF itr IS NOT NULL THEN
3258 		    LOOP
3259 		       IF l_debug_on THEN
3260 		          WSH_DEBUG_SV.logmsg(l_module_name,' Itr : '||itr);
3261 		       END IF;
3262 
3263 		       IF  g_reg_const_cache(itr).CONSTRAINT_OBJECT1_TYPE = 'REG' AND
3264                            g_reg_const_cache(itr).CONSTRAINT_OBJECT1_ID = l_region_id
3265        		       THEN
3266 	                   --
3267 			   IF l_debug_on THEN
3268 		                WSH_DEBUG_SV.logmsg(l_module_name,' Input has  Inclusive constraint: '||g_reg_const_cache(itr).compatibility_id);
3269 		           END IF;
3270 		           --
3271 	                   l_fail_rec_cont  := l_fail_rec_cont + 1;
3272 	   	           x_failed_constraint(l_fail_rec_cont).constraint_id  := g_reg_const_cache(itr).compatibility_id;
3273 		           x_failed_constraint(l_fail_rec_cont).entity_type    := p_entity_type;
3274 		           x_failed_constraint(l_fail_rec_cont).entity_line_id := p_entity_id;
3275 		           x_failed_constraint(l_fail_rec_cont).constraint_class_code := G_REGION_FACILITY;
3276 			   x_failed_constraint(l_fail_rec_cont).violation_type := g_comp_class_tab(l_hash_value).constraint_violation;
3277 			   l_validate_result := g_comp_class_tab(l_hash_value).constraint_violation;
3278 		           l_constraint_found :=TRUE;
3279 
3280                        END IF;
3281 
3282 		       EXIT WHEN itr=g_reg_const_cache.LAST;
3283 		       itr := g_reg_const_cache.NEXT(itr);
3284 	            END LOOP;
3285                 END IF;
3286 
3287 	     END IF; --(If NOT (l_constraint_found) THEN )
3288 
3289              --Check for the zone level constraint
3290 	     --Inclusive zone level constraints to be treated as OR.
3291 
3292 	     IF NOT(l_constraint_found) THEN
3293 
3294 		  IF l_debug_on THEN
3295 		     WSH_DEBUG_SV.logmsg(l_module_name,' Calling WSH_REGIONS_SEARCH_PKG.Get_All_Zone_Matches ');
3296 		  END IF;
3297 		  WSH_REGIONS_SEARCH_PKG.Get_All_Zone_Matches(
3298 			 p_region_id		=> l_region_id,
3299 			 x_zone_tab		=> l_zone_tab,
3300 			 x_return_status        => l_return_status);
3301 
3302 		 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
3303 	           IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
3304 		      raise FND_API.G_EXC_UNEXPECTED_ERROR;
3305 	           END IF;
3306 		 END IF;
3307 
3308 	         z_itr:= l_zone_tab.FIRST;
3309 
3310                   -- Check if zone level constraints are present.
3311 
3312 		 IF (z_itr IS NOT NULL) THEN
3313 
3314 		     LOOP
3315 
3316 			l_zone_id := l_zone_tab(z_itr);
3317 
3318   		        IF l_debug_on THEN
3319 			    wsh_debug_sv.logmsg(l_module_name,'Validating inclusive constraints for Zone :'||l_zone_id);
3320 			END IF;
3321 
3322 			l_zone_hash_str_const := l_reg_comp_class_id||'-'
3323 		     				 ||'ZON'||'-'
3324                                  		 ||l_zone_id||'-'
3325 					         ||(-9999)||'-'
3326 					         ||'FAC'||'-';
3327 
3328 		        IF l_debug_on THEN
3329 		           WSH_DEBUG_SV.logmsg(l_module_name,'Zone hash constant is : '||l_zone_hash_str_const);
3330 		        END IF;
3331 
3332 			itr := p_location_list.FIRST;
3333 
3334 			IF itr IS NOT NULL THEN
3335 	     	           LOOP
3336 			     --
3337 			     IF l_debug_on THEN
3338 			         WSH_DEBUG_SV.logmsg(l_module_name,'p_location_list  : '||p_location_list(itr));
3339 			     END IF;
3340 			     --
3341 			     l_zone_hash_string:=l_zone_hash_str_const ||(p_location_list(itr))||'-'||(-9999);
3342 
3343 	   		     l_zone_hash_value := dbms_utility.get_hash_value(
3344  		                              name => l_zone_hash_string,
3345 				              base => g_hash_base,
3346 			                      hash_size =>g_hash_size );
3347                 	      --
3348    			      IF l_debug_on THEN
3349 			          WSH_DEBUG_SV.logmsg(l_module_name,'l_zone_hash_string : '||l_zone_hash_string);
3350 		                  WSH_DEBUG_SV.logmsg(l_module_name,'l_zone_hash_value  : '||l_zone_hash_value);
3351        		              END IF;
3352                               --
3353 
3354 		              IF check_cache(l_zone_hash_value,l_zone_hash_string) THEN
3355 			        IF g_comp_constraint_tab(l_zone_hash_value).constraint_type = 'I' THEN
3356 				   x_validate_result := 'S';
3357   		                   l_validate_result := 'S';
3358 				   l_constraint_found:= TRUE;
3359 
3360 				   IF l_debug_on THEN
3361 				      wsh_debug_sv.logmsg(l_module_name,'Inclusive Constraint Found');
3362 				   END IF;
3363 				   EXIT;
3364 	                        END IF;
3365 		              END IF;
3366 
3367 			      EXIT WHEN itr =p_location_list.LAST;
3368                        	      itr := p_location_list.NEXT(itr);
3369  		           END LOOP;
3370 		   	 END IF;
3371 
3372 		         EXIT WHEN z_itr =l_zone_tab.LAST;
3373 		         z_itr := l_zone_tab.NEXT(z_itr);
3374 
3375 		      END LOOP;
3376 
3377 
3378 		      IF NOT (l_constraint_found) THEN
3379 		      -- loop over the zones against locations to check the constraints
3380                       z_itr:= l_zone_tab.FIRST;
3381 
3382                       LOOP
3383 	  	           l_zone_id := l_zone_tab(z_itr);
3384 			   itr := g_reg_const_cache.FIRST;
3385 
3386                        	   IF itr IS NOT NULL THEN
3387 		           LOOP
3388 
3389 				IF  g_reg_const_cache(itr).CONSTRAINT_OBJECT1_TYPE = 'ZON' AND
3390                                     g_reg_const_cache(itr).CONSTRAINT_OBJECT1_ID   = l_zone_id
3391 		                THEN
3392 	            	            --
3393                 		    IF l_debug_on THEN
3394 		                      WSH_DEBUG_SV.logmsg(l_module_name,' Zone :'||l_zone_id||' for Input has constraint:(Check for INCL/EXCL constraint '||g_reg_const_cache(itr).compatibility_id);
3395 		                    END IF;
3396 
3397 				    add_constraint := TRUE;
3398 
3399 				    --Check whether any exclusive constraint occurs ZONES In the location and the FACILITY.
3400 				    --If exists then it is not a  failed constraint, set add_constraint to FALSE appropriately.
3401 
3402 				    IF (l_zone_tab.count > 1 ) THEN
3403 
3404 					l_fac_id := g_reg_const_cache(itr).CONSTRAINT_OBJECT2_ID;
3405 
3406 					ex_itr := l_zone_tab.FIRST;
3407 
3408 					LOOP
3409 
3410 					  ex_zone_id := l_zone_tab(ex_itr);
3411 
3412 					  IF (ex_zone_id <> l_zone_id) THEN
3413 
3414 						l_zone_hash_excl_string := l_reg_comp_class_id||'-'
3415 				     					  ||'ZON'||'-'
3416 		                                 			  ||ex_zone_id||'-'
3417 								          ||(-9999)||'-'
3418 								          ||'FAC'||'-'
3419 							  	          ||to_char(l_fac_id)||'-'
3420 			        		                          ||(-9999);
3421 
3422 						l_zone_hash_excl_value := dbms_utility.get_hash_value(
3423 			 		                              name => l_zone_hash_excl_string,
3424 							              base => g_hash_base,
3425 								      hash_size =>g_hash_size );
3426 
3427 
3428 					       IF check_cache(l_zone_hash_excl_value,l_zone_hash_excl_string) THEN
3429 					          IF g_comp_constraint_tab(l_zone_hash_excl_value).constraint_type = 'E' THEN
3430 							-- both inclusive and excluive constraint is present.
3431 							-- Need not enter the constriant in the list.
3432 							IF l_debug_on THEN
3433 							    wsh_debug_sv.logmsg(l_module_name,'Both inclusive and exclusive constraint found for the location ');
3434 							END IF;
3435 							add_constraint := FALSE;
3436 							EXIT;
3437 					          END IF;
3438 					       END IF;
3439 
3440 					   END IF;
3441 
3442 					  EXIT WHEN ex_itr = l_zone_tab.LAST;
3443 					  ex_itr:= l_zone_tab.NEXT(ex_itr);
3444 					END LOOP;
3445 				    END IF;
3446 
3447 				    --
3448                 		    -- Add to the x_failed_constraint if add_constraint is TRUE;
3449 				    --
3450 		                    IF (add_constraint) THEN
3451 
3452 					    l_fail_rec_cont := l_fail_rec_cont + 1;
3453 				            x_failed_constraint(l_fail_rec_cont).constraint_id := g_reg_const_cache(itr).compatibility_id;
3454                		                    x_failed_constraint(l_fail_rec_cont).entity_type   := p_entity_type;
3455 				            x_failed_constraint(l_fail_rec_cont).entity_line_id:= p_entity_id;
3456 					    x_failed_constraint(l_fail_rec_cont).constraint_class_code := G_REGION_FACILITY;
3457 	                		    x_failed_constraint(l_fail_rec_cont).violation_type := g_comp_class_tab(l_hash_value).constraint_violation;
3458 				            l_validate_result := g_comp_class_tab(l_hash_value).constraint_violation;
3459 			                    l_constraint_found :=TRUE;
3460 				    END IF;
3461 
3462 				END IF;
3463 
3464 				EXIT WHEN itr=g_reg_const_cache.LAST;
3465 		                itr := g_reg_const_cache.NEXT(itr);
3466 
3467 			     END LOOP;
3468                              END IF;
3469 
3470 			EXIT WHEN z_itr=l_zone_tab.LAST;
3471 		        z_itr := l_zone_tab.NEXT(z_itr);
3472 			END LOOP;
3473 
3474 	 	  END IF;
3475 		END IF;-- (zone itr  is not null)
3476              END IF;  -- (if not constraint FOUND);
3477 
3478 	 EXIT WHEN (r_itr = l_region_tab.LAST) OR (l_constraint_found);
3479 
3480 	 r_itr:= l_region_tab.NEXT(r_itr);
3481 
3482 	 END LOOP;
3483       END IF;
3484 
3485 
3486       IF NOT l_constraint_found THEN
3487    	  x_validate_result := 'S';
3488 
3489 	  -- Maintain the location ID as no constraint is present
3490 	  -- at REGION and ZONE level
3491 
3492 	   IF l_debug_on THEN
3493 		   wsh_debug_sv.logmsg(l_module_name,'No Inclusive Region/Zone constraint present for location '||p_location_id);
3494 	   END IF;
3495 
3496 	   add_region_constraint(
3497 	          p_location_id	       => p_location_id
3498 	 	 ,p_object2_id	       => g_const_not_present
3499 		 ,p_constraint_id      => g_incl_cons_not_present
3500 		 ,p_constraint_type    => 'I'
3501 		 ,x_return_status      => l_return_status);
3502 
3503 
3504             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
3505                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
3506                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
3507                END IF;
3508             END IF;
3509 
3510       ELSE
3511 
3512 	  IF l_validate_result = 'W' THEN
3513              x_validate_result := 'W';
3514           END IF;
3515 
3516       END IF;
3517 
3518       IF l_debug_on THEN
3519          wsh_debug_sv.pop(l_module_name);
3520       END IF;
3521 
3522 EXCEPTION
3523 
3524     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
3525       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
3526        --
3527       IF l_debug_on THEN
3528         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
3529         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
3530       END IF;
3531       --
3532     WHEN others THEN
3533       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.check_reg_incl_facilities');
3534       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
3535       --
3536       IF l_debug_on THEN
3537         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
3538         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
3539       END IF;
3540 END check_reg_incl_facilities;
3541 
3542 
3543 --***************************************************************************--
3544 --
3545 --========================================================================
3546 -- PROCEDURE : validate_constraint        PRIVATE
3547 --
3548 -- PARAMETERS: p_comp_class_code          Compatibility class code
3549 --             p_constraint_type          Constraint Type : Exclusive / Inclusive
3550 --             p_object1_type	          Constraint Object1 Type
3551 --             p_object1_parent_id        Constraint Object1 Parent id
3552 --                                        Required only if object1 = Item
3553 --             p_object1_val_num          Constraint Object1 id
3554 --             p_object1_val_char         Constraint Object1 character code
3555 --             p_object1_physical_id      Physical Location Id - Passed in only for CUS_FAC for Customer Facility
3556 --             p_object2_type	          Constraint Object2 Type
3557 --             p_object2_parent_id        Constraint Object2 Parent id
3558 --             p_object2_val_num          Constraint Object2 id
3559 --             p_object2_val_char         Constraint Object2 character code
3560 --                                        Currently used for Mode of Transport code only
3561 --             p_direct_shipment          Is the shipment multileg
3562 --             x_validate_result          Constraint Validation result : S / E / W
3563 --             x_failed_constraint        failed constraint id in case of failure, null if success
3564 --             x_return_status            Return status
3565 -- COMMENT   :
3566 --      This is an internal procedure to determine if two objects
3567 --      have a constraint defined between them under the scope of a particular compatibility class
3568 --      Hence, returns constraint severity
3569 --      1. Passed I : if a constraint for this combination exists of type 'I'
3570 --      2. Passed E : if a constraint for this combination exists of type 'E'
3571 
3572 --      Assumes object1 and object2 have been passed as the class requires/defines
3573 --========================================================================
3574 
3575 PROCEDURE validate_constraint(
3576              p_comp_class_code          IN      VARCHAR2,
3577              p_constraint_type          IN      VARCHAR2 DEFAULT 'E',
3578              p_object1_type	        IN      VARCHAR2 DEFAULT NULL,
3579              p_object1_parent_id        IN      NUMBER   DEFAULT NULL,
3580              p_object1_val_char         IN      VARCHAR2 DEFAULT NULL,
3581              p_object1_val_num          IN      NUMBER   DEFAULT NULL,
3582              p_object1_physical_id	IN	NUMBER	 DEFAULT NULL,
3583 	         p_object2_type	        IN      VARCHAR2 DEFAULT NULL,
3584              p_object2_parent_id        IN      NUMBER   DEFAULT NULL,
3585              p_object2_val_char         IN      VARCHAR2 DEFAULT NULL,
3586              p_object2_val_num          IN      NUMBER   DEFAULT NULL,
3587              p_direct_shipment          IN      BOOLEAN  DEFAULT FALSE,
3588              x_validate_result          OUT NOCOPY    VARCHAR2,
3589              x_failed_constraint        OUT NOCOPY    line_constraint_rec_type,
3590              x_return_status            OUT NOCOPY    VARCHAR2)
3591 IS
3592 
3593     l_return_status    VARCHAR2(1);
3594 
3595     l_location_id       NUMBER:=0;
3596     l_master_org_id     NUMBER:=0;
3597     l_carrier_id        NUMBER:=0;
3598     --l_customer_id       NUMBER:=0;
3599     l_customer_id_tab   WSH_UTIL_CORE.id_tab_type;
3600     l_supplier_id       NUMBER:=0;
3601     l_object1_type      VARCHAR2(30):=NULL;
3602     l_object1_id        NUMBER:=0;
3603     l_object1_parent_id NUMBER:=p_object1_parent_id;
3604     l_object2_type      VARCHAR2(30):=NULL;
3605     l_object2_id        NUMBER:=0;
3606     l_object2_val_char  VARCHAR2(30):=NULL;
3607     l_object1_typesub   VARCHAR2(30):=NULL;
3608     l_object2_typesub   VARCHAR2(30):=NULL;
3609     l_comp_type1        VARCHAR2(3) := SUBSTR(p_comp_class_code,1,3);
3610     l_comp_type2        VARCHAR2(3) := SUBSTR(p_comp_class_code,5,3);
3611 
3612     l_comp_class_id     NUMBER:=0;
3613     l_hash_value        NUMBER;
3614     l1_hash_value       NUMBER;
3615     l11_hash_value      NUMBER;
3616     l_hash_active       NUMBER;
3617     l2_hash_value       NUMBER;
3618     l3_hash_value       NUMBER;
3619     l4_hash_value       NUMBER;
3620     l1_hash_string      VARCHAR2(200);
3621     l11_hash_string     VARCHAR2(200);
3622     l2_hash_string      VARCHAR2(200);
3623     l3_hash_string      VARCHAR2(200);
3624     l4_hash_string      VARCHAR2(200);
3625     l_itm_hash_value    NUMBER;
3626     l_itm_hash_string   VARCHAR2(200);
3627     l_fac_hash_value    NUMBER;
3628     l_fac_hash_string   VARCHAR2(200);
3629 
3630     --DUM_LOC(S)
3631     l_organization_tab  WSH_UTIL_CORE.id_tab_type;
3632     l_org_itr		NUMBER;
3633     itr                 NUMBER :=0;
3634     --DUM_LOC(E)
3635 
3636     l_module_name       CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'validate_constraint';
3637     l_debug_on          CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
3638 
3639 BEGIN
3640 
3641     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
3642     x_validate_result := 'S';
3643 
3644     IF l_debug_on THEN
3645       wsh_debug_sv.push(l_module_name);
3646       WSH_DEBUG_SV.logmsg(l_module_name,'Input comp class code : '||p_comp_class_code);
3647       WSH_DEBUG_SV.logmsg(l_module_name,'p_constraint_type : '||p_constraint_type);
3648       WSH_DEBUG_SV.logmsg(l_module_name,'Input Object1 type : '||p_object1_type);
3649       WSH_DEBUG_SV.logmsg(l_module_name,'Input Object2 type : '||p_object2_type);
3650       WSH_DEBUG_SV.logmsg(l_module_name,'Object1 val num : '||p_object1_val_num);
3651       WSH_DEBUG_SV.logmsg(l_module_name,'Object 1 parent : '||l_object1_parent_id);
3652       WSH_DEBUG_SV.logmsg(l_module_name,'Object2 val num : '||p_object2_val_num);
3653       WSH_DEBUG_SV.logmsg(l_module_name,'Object 2 val char : '||p_object2_val_char);
3654       IF p_direct_shipment THEN
3655        WSH_DEBUG_SV.logmsg(l_module_name,'p_direct_shipment is true');
3656       ELSE
3657        WSH_DEBUG_SV.logmsg(l_module_name,'p_direct_shipment is false');
3658       END IF;
3659     END IF;
3660 
3661     --return if object2 is NULL
3662     IF (p_object1_val_num IS NULL OR (p_object2_val_num IS NULL AND p_object2_val_char IS NULL)) OR
3663        (p_comp_class_code = G_CUSTOMER_CUSTOMER AND p_object1_val_num = p_object2_val_num) THEN
3664       --
3665       IF l_debug_on THEN
3666         WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
3667         WSH_DEBUG_SV.pop(l_module_name);
3668       END IF;
3669       --
3670       RETURN;
3671     END IF;
3672 
3673     IF g_is_tp_installed IS NULL THEN
3674      g_is_tp_installed := WSH_UTIL_CORE.TP_Is_Installed;
3675     END IF;
3676     -- Must pass in object types when CLASS code contains FAC
3677 
3678     l_object1_typesub := nvl(p_object1_type,l_comp_type1);
3679     l_object2_typesub := nvl(p_object2_type,l_comp_type2);
3680 
3681 
3682     --#DUM_LOC(S)
3683 /*
3684      Pseudo Code :
3685 
3686      1) IF p_comp_class_code = G_CUSTOMER_FACILITY, p_object1_type = G_FACILITY
3687         and (p_object1_physical_id IS NOT NULL) THEN
3688 
3689 	- get all the organizations for the location id .
3690 	- Call validate constriant recursively.
3691 	  The moment we find a constraint we return back.
3692 	  We do not do any further validations.
3693 
3694 	--AGDUMMY :
3695 	No constraints can exist for a dummy customer facility
3696 
3697      --For Dummy locations we have only ORG-FAC constraints.
3698 */
3699 
3700     IF (p_comp_class_code = G_CUSTOMER_FACILITY) AND (l_object1_typesub = G_FACILITY)
3701 	AND (p_object1_physical_id IS NOT NULL) THEN
3702 
3703 	IF l_debug_on THEN
3704 	   WSH_DEBUG_SV.logmsg(l_module_name,'Validating CUS-FAC constraint for dummy location, Finding corresponding Organizations');
3705 	END IF;
3706 
3707 	--get_org_from_location(
3708 	WSH_UTIL_CORE.get_org_from_location(
3709               p_location_id	  => p_object1_physical_id,
3710               x_organization_tab  => l_organization_tab,
3711               x_return_status     => l_return_status);
3712 
3713 	IF l_debug_on THEN
3714 	    WSH_DEBUG_SV.logmsg(l_module_name,'l_return_status:'||l_return_status);
3715             WSH_DEBUG_SV.logmsg(l_module_name,'Organizations Returned:'||l_organization_tab.Count);
3716 	END IF;
3717 
3718 	IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
3719           IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
3720             raise FND_API.G_EXC_UNEXPECTED_ERROR;
3721           END IF;
3722         END IF;
3723 
3724 	l_org_itr := l_organization_tab.FIRST;
3725 
3726 	IF l_org_itr IS NOT NULL THEN
3727            LOOP
3728 	        IF l_debug_on THEN
3729               WSH_DEBUG_SV.logmsg(l_module_name,'Organizations id:'||l_organization_tab(l_org_itr));
3730               WSH_DEBUG_SV.logmsg(l_module_name,'Validating ORG_FAC for the dummy location ');
3731             END IF;
3732 
3733 	        validate_constraint(
3734                   p_comp_class_code    => G_SHIPORG_FACILITY,
3735                   p_constraint_type    => p_constraint_type,
3736 	              p_object1_type       => G_COMP_ORG, -- AGDUMMY
3737                   p_object1_val_num    => l_organization_tab(l_org_itr),
3738      	          p_object2_type       => p_object2_type,
3739                   p_object2_val_num    => p_object2_val_num,
3740                   p_direct_shipment    => p_direct_shipment,
3741                   x_validate_result    => x_validate_result,
3742                   x_failed_constraint  => x_failed_constraint,
3743                   x_return_status      => x_return_status);
3744 
3745 	         IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
3746                    IF x_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
3747                         raise FND_API.G_EXC_UNEXPECTED_ERROR;
3748                     END IF;
3749                  END IF;
3750 
3751 		-- When we are getting a constraint at org level we return.
3752                 -- If x_validate_result <> S , it implies a constraint has been
3753 		-- violated.
3754 
3755 		EXIT WHEN (x_validate_result <> 'S' OR l_org_itr= l_organization_tab.LAST);
3756                 l_org_itr:= l_organization_tab.NEXT(l_org_itr);
3757 
3758 	     END LOOP;
3759 	   END IF;
3760 	   --
3761 	   IF l_debug_on THEN
3762 		 WSH_DEBUG_SV.logmsg(l_module_name,'Validation for CUS-FAC, Dummy locations over');
3763 		 WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
3764 		 WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_return_status :   '||x_return_status);
3765 	     WSH_DEBUG_SV.pop(l_module_name);
3766 	   END IF;
3767            --
3768 	   RETURN;
3769      END IF;
3770     --#DUM_LOC(E)
3771 
3772     IF (l_object1_typesub = 'ITM' AND g_is_tp_installed = 'Y') THEN
3773        l_object1_parent_id := null;
3774     END IF;
3775 
3776     -- Check ITM specific exclusive constraint cache s here
3777     -- If a combination of ITM-CAR/MOD/VEH/FAC cache record exists
3778     -- get result from that record and return
3779     -- proceed if does not exist in cache
3780 
3781     IF l_object1_typesub = 'ITM' AND p_constraint_type = 'E' THEN
3782 
3783       l_itm_hash_string :=p_comp_class_code||'-'||nvl(l_object1_parent_id,-9999)||'-'||p_object1_val_num||'-'||nvl(to_char(p_object2_val_num),p_object2_val_char);
3784 
3785       l_itm_hash_value := dbms_utility.get_hash_value(
3786                                   name => l_itm_hash_string,
3787                                   base => g_hash_base,
3788                                   hash_size =>g_hash_size );
3789 
3790       --
3791       IF l_debug_on THEN
3792          WSH_DEBUG_SV.logmsg(l_module_name,'l_itm_hash_string : '||l_itm_hash_string);
3793          WSH_DEBUG_SV.logmsg(l_module_name,'l_itm_hash_value : '||l_itm_hash_value);
3794       END IF;
3795       --
3796 
3797       IF g_itm_exclusive_cache.EXISTS(l_itm_hash_value) AND
3798        g_itm_exclusive_cache(l_itm_hash_value).hash_string = l_itm_hash_string THEN
3799        -- Found in cache
3800        x_validate_result := g_itm_exclusive_cache(l_itm_hash_value).validate_result;
3801           --
3802           IF l_debug_on THEN
3803             WSH_DEBUG_SV.logmsg(l_module_name,'Found in g_itm_exclusive_cache with hash string : '||l_itm_hash_string);
3804             WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
3805             WSH_DEBUG_SV.pop(l_module_name);
3806           END IF;
3807           --
3808           RETURN;  -- Done with as found for the input types
3809 
3810       END IF;
3811     END IF;
3812 
3813     -- Check FAC specific exclusive constraint cache s here
3814     -- If a combination of FAC-CAR/MOD/VEH cache record exists
3815     -- get result from that record and return
3816     -- proceed if does not exist in cache
3817 
3818     IF l_comp_type1 = 'FAC' AND p_constraint_type = 'E' THEN
3819 
3820       l_fac_hash_string := p_comp_class_code||'-'||l_object1_typesub||'-'||p_object1_val_num||'-'||nvl(to_char(p_object2_val_num),p_object2_val_char);
3821 
3822       l_fac_hash_value := dbms_utility.get_hash_value(
3823                                 name => l_fac_hash_string,
3824                                 base => g_hash_base,
3825                                 hash_size =>g_hash_size );
3826       --
3827       IF l_debug_on THEN
3828          WSH_DEBUG_SV.logmsg(l_module_name,'l_fac_hash_string : '||l_fac_hash_string);
3829          WSH_DEBUG_SV.logmsg(l_module_name,'l_fac_hash_value : '||l_fac_hash_value);
3830       END IF;
3831       --
3832 
3833       IF g_fac_exclusive_cache.EXISTS(l_fac_hash_value) AND
3834        g_fac_exclusive_cache(l_fac_hash_value).hash_string = l_fac_hash_string THEN
3835        -- Found in cache
3836        x_validate_result := g_fac_exclusive_cache(l_fac_hash_value).validate_result;
3837           --
3838           IF l_debug_on THEN
3839             WSH_DEBUG_SV.logmsg(l_module_name,'Found in g_fac_exclusive_cache with hash string : '||l_fac_hash_string);
3840             WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
3841             WSH_DEBUG_SV.pop(l_module_name);
3842           END IF;
3843           --
3844           RETURN;  -- Done with as found for the input types
3845 
3846       END IF;
3847 
3848     END IF;
3849 
3850     -- Alternatively the package can store internal numeric
3851     -- values for each of the compatibility classes and use that to index the table
3852     -- which will help avoiding hash creation
3853     l_hash_value := dbms_utility.get_hash_value(
3854                                   name => p_comp_class_code,
3855                                   base => g_hash_base,
3856                                   hash_size =>g_hash_size );
3857 
3858     -- Hash collision
3859     --IF NOT g_comp_class_tab.EXISTS(l_hash_value) THEN
3860     IF NOT (g_comp_class_tab.EXISTS(l_hash_value) AND
3861             g_comp_class_tab(l_hash_value).compatibility_class_code = p_comp_class_code) THEN
3862 
3863       populate_constraint_cache(
3864           p_comp_class_code          =>    p_comp_class_code,
3865           x_return_status            =>    l_return_status) ;
3866 
3867       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
3868          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
3869             raise FND_API.G_EXC_UNEXPECTED_ERROR;
3870          END IF;
3871       END IF;
3872 
3873       --
3874       IF l_debug_on THEN
3875         WSH_DEBUG_SV.logmsg(l_module_name,'Called populate_constraint_cache return status : '||l_return_status);
3876       END IF;
3877       --
3878     END IF;
3879 
3880     l_comp_class_id := g_comp_class_tab(l_hash_value).compatibility_class_id;
3881 
3882     -- For facility specific constraints if type  = facility then need to search only for
3883     -- constraints in that class for that facility(location), but if the type = company, then
3884     -- need to check if any constraints exist for that class for any of the locations
3885     -- being used by that company
3886     -- A constraint defined for a location applies to all companies using that location ?
3887 
3888     -- First check input combination types, if it has constraint_type = E, return failure
3889     -- Following special rules apply to facility specific constraints
3890     -- If not returned failure above :
3891     -- 1. ORG_FAC : object2_type = FAC, get carrier for input FAC, check
3892     --              Also check if anything is defined for master ORG if not found for input ORG
3893     -- 2. CUS_FAC : object1_type = FAC, object2_type = FAC, get carrier for obj2 FAC, check
3894     --              object1_type = CUS, object2_type = FAC, get carrier for obj2 FAC, check
3895     -- 3. ITM_FAC : object2_type = FAC, get carrier for obj2 FAC, check
3896     --                                  get customer for obj2 FAC, check
3897     --                                  get supplier for obj1 FAC, check
3898     -- 4. FAC_CAR : object1_type = FAC, get carrier for obj1 FAC, check
3899     --                                  get customer for obj1 FAC, check
3900     --                                  get supplier for obj1 FAC, check
3901     -- 5. FAC_MOD : object1_type = FAC, get carrier for obj1 FAC, check
3902     --                                  get customer for obj1 FAC, check
3903     --                                  get supplier for obj1 FAC, check
3904     -- 6. SUP_FAC : object1_type = FAC, object2_type = FAC, get carrier for obj2 FAC, check
3905     --              object1_type = SUP, object2_type = FAC, get carrier for obj2 FAC, check
3906     -- 7. FAC_VEH : object1_type = FAC, get carrier for obj1 FAC, check
3907     --                                  get customer for obj1 FAC, check
3908     --                                  get supplier for obj1 FAC, check
3909 
3910     -- When checking above classes with higher level TYPE at FAC side,
3911     -- ONLY checks existence of an I constraint at that level
3912     -- ie. does not go down the level to check
3913     -- though goes up to check for a location if required
3914 
3915     -- Can you have MUST USE at a lower level
3916     -- and CAN'T USE at a higher level
3917     -- NO - Does not make sense
3918 
3919     -- Can you have CAN'T USE at a lower level
3920     -- and MUST USE at a higher level (Means any facility of that parent)
3921     -- YES -  lower level takes precedence
3922 
3923     -- Need a data structure for hashing constraints
3924     -- hash by class+obj1 type+obj1+obj1 parent+obj2 type+obj2+obj2 parent
3925     -- As this combination defines a unique key
3926 
3927     -- Nothing needs to be done when storing the constraint definition
3928     -- as it will not have organization_id if TP is installed
3929 
3930     l1_hash_string :=        (l_comp_class_id)||'-'||l_object1_typesub||'-'||nvl(       to_char(p_object1_val_num),p_object1_val_char)||'-'||       (nvl(l_object1_parent_id,-9999))||
3931     '-'||l_object2_typesub||'-'||nvl(       to_char(p_object2_val_num),p_object2_val_char)||'-'||       (nvl(p_object2_parent_id,-9999));
3932 
3933 
3934     l1_hash_value := dbms_utility.get_hash_value(
3935                                   name => l1_hash_string,
3936                                   base => g_hash_base,
3937                                   hash_size =>g_hash_size );
3938 
3939     --
3940     IF l_debug_on THEN
3941        WSH_DEBUG_SV.logmsg(l_module_name,'l1_hash_string : '||l1_hash_string);
3942        WSH_DEBUG_SV.logmsg(l_module_name,'l1_hash_value : '||l1_hash_value);
3943     END IF;
3944     --
3945 
3946     IF p_comp_class_code = G_CUSTOMER_CUSTOMER THEN
3947 
3948       l11_hash_string :=        (l_comp_class_id)||'-'||l_object1_typesub||'-'||to_char(p_object2_val_num)||'-'||(nvl(p_object2_parent_id,-9999))||
3949       '-'||l_object2_typesub||'-'||to_char(p_object1_val_num)||'-'||(nvl(l_object1_parent_id,-9999));
3950 
3951       l11_hash_value := dbms_utility.get_hash_value(
3952                                   name => l11_hash_string,
3953                                   base => g_hash_base,
3954                                   hash_size =>g_hash_size );
3955 
3956       --
3957       IF l_debug_on THEN
3958         WSH_DEBUG_SV.logmsg(l_module_name,'l11_hash_string : '||l11_hash_string);
3959         WSH_DEBUG_SV.logmsg(l_module_name,'l11_hash_value : '||l11_hash_value);
3960       END IF;
3961       --
3962 
3963     ELSIF p_comp_class_code = G_SHIPORG_FACILITY THEN
3964 
3965       WSH_UTIL_CORE.get_master_from_org(
3966               p_org_id         => p_object1_val_num,
3967               x_master_org_id  => l_master_org_id,
3968               x_return_status  => l_return_status);
3969 
3970       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
3971          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
3972           IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
3973             raise FND_API.G_EXC_UNEXPECTED_ERROR;
3974           END IF;
3975           raise g_get_mast_org_failed;
3976          END IF;
3977       END IF;
3978 
3979       IF l_master_org_id <> p_object1_val_num THEN -- Input ORG is child of l_master_org_id
3980 
3981          l11_hash_string :=        (l_comp_class_id)||'-'||l_object1_typesub||'-'||to_char(l_master_org_id)||'-'||(nvl(l_object1_parent_id,-9999))||
3982          '-'||l_object2_typesub||'-'||to_char(p_object2_val_num)||'-'||(nvl(p_object2_parent_id,-9999));
3983 
3984          l11_hash_value := dbms_utility.get_hash_value(
3985                                   name => l11_hash_string,
3986                                   base => g_hash_base,
3987                                   hash_size =>g_hash_size );
3988 
3989          --
3990          IF l_debug_on THEN
3991             WSH_DEBUG_SV.logmsg(l_module_name,'l11_hash_string : '||l11_hash_string);
3992             WSH_DEBUG_SV.logmsg(l_module_name,'l11_hash_value : '||l11_hash_value);
3993          END IF;
3994          --
3995 
3996       END IF;
3997 
3998     END IF;
3999 
4000     -- How to handle constraint types in execution (Inclusive / exclusive ?)
4001 
4002     -- For this set of input, check the global table
4003     -- If the record exists (can be at most one)
4004     --                      and constraint type = E, return error
4005     --                      and constraint type = I, return success
4006     -- If it does not exist : Need to check all the records with obj1
4007     --                        For each record, construct the hash and cache structure
4008 
4009     IF check_cache(l1_hash_value,l1_hash_string) THEN
4010 
4011        IF g_comp_constraint_tab(l1_hash_value).constraint_type = p_constraint_type THEN
4012           x_validate_result := g_comp_class_tab(l_hash_value).constraint_violation;
4013           x_failed_constraint.constraint_id := g_comp_constraint_tab(l1_hash_value).compatibility_id;
4014           x_failed_constraint.constraint_class_code := p_comp_class_code;
4015           x_failed_constraint.violation_type := g_comp_class_tab(l_hash_value).constraint_violation;
4016 
4017           -- Create the ITM specific cache for exclusive constraints here
4018           IF l_object1_typesub = 'ITM' AND p_constraint_type = 'E' THEN
4019 
4020              g_itm_exclusive_cache(l_itm_hash_value).hash_string := l_itm_hash_string ;
4021              g_itm_exclusive_cache(l_itm_hash_value).comp_class_code := p_comp_class_code ;
4022              g_itm_exclusive_cache(l_itm_hash_value).item_id := p_object1_val_num ;
4023              g_itm_exclusive_cache(l_itm_hash_value).itemorg_id := l_object1_parent_id ;
4024              g_itm_exclusive_cache(l_itm_hash_value).object2_id := p_object2_val_num ;
4025              g_itm_exclusive_cache(l_itm_hash_value).object2_char := p_object2_val_char ;
4026              g_itm_exclusive_cache(l_itm_hash_value).validate_result := x_validate_result ;
4027 
4028              --
4029              IF l_debug_on THEN
4030                 WSH_DEBUG_SV.logmsg(l_module_name,'Created in g_itm_exclusive_cache with hash string : '||l_itm_hash_string);
4031              END IF;
4032              --
4033           END IF;
4034 
4035           -- Create the FAC specific cache for exclusive constraints here
4036           IF l_comp_type1 = 'FAC' AND p_constraint_type = 'E' THEN
4037 
4038              g_fac_exclusive_cache(l_fac_hash_value).hash_string := l_fac_hash_string ;
4039              g_fac_exclusive_cache(l_fac_hash_value).comp_class_code := p_comp_class_code ;
4040              g_fac_exclusive_cache(l_fac_hash_value).object1_type := l_object1_typesub ;
4041              g_fac_exclusive_cache(l_fac_hash_value).object1_id := p_object1_val_num ;
4042              g_fac_exclusive_cache(l_fac_hash_value).object2_id := p_object2_val_num ;
4043              g_fac_exclusive_cache(l_fac_hash_value).object2_char := p_object2_val_char ;
4044              g_fac_exclusive_cache(l_fac_hash_value).validate_result := x_validate_result ;
4045 
4046              --
4047              IF l_debug_on THEN
4048                 WSH_DEBUG_SV.logmsg(l_module_name,'Created in g_fac_exclusive_cache with hash string : '||l_fac_hash_string);
4049              END IF;
4050              --
4051           END IF;
4052 
4053           --
4054           IF l_debug_on THEN
4055             WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
4056             WSH_DEBUG_SV.pop(l_module_name);
4057           END IF;
4058           --
4059 
4060           RETURN;  -- Done with as found for the input types
4061 
4062        END IF;
4063 
4064     ELSIF (p_comp_class_code = G_CUSTOMER_CUSTOMER AND check_cache(l11_hash_value,l11_hash_string)) OR
4065           (l11_hash_value IS NOT NULL AND p_comp_class_code = G_SHIPORG_FACILITY AND check_cache(l11_hash_value,l11_hash_string)) THEN
4066 
4067        IF g_comp_constraint_tab(l11_hash_value).constraint_type = p_constraint_type THEN
4068           x_validate_result := g_comp_class_tab(l_hash_value).constraint_violation;
4069           x_failed_constraint.constraint_id := g_comp_constraint_tab(l11_hash_value).compatibility_id;
4070           x_failed_constraint.constraint_class_code := p_comp_class_code;
4071           x_failed_constraint.violation_type := g_comp_class_tab(l_hash_value).constraint_violation;
4072 
4073           --
4074           IF l_debug_on THEN
4075             WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
4076             WSH_DEBUG_SV.pop(l_module_name);
4077           END IF;
4078           --
4079           RETURN;  -- Done with as found for the input types
4080 
4081        END IF;
4082 
4083     END IF;
4084 
4085     IF ((p_comp_class_code = G_FACILITY_CARRIER OR p_comp_class_code = G_FACILITY_MODE OR p_comp_class_code = G_FACILITY_VEHICLE) AND
4086        l_object1_typesub = G_FACILITY) THEN
4087 
4088        l_location_id := p_object1_val_num;
4089 
4090        get_carrier_from_loc(
4091                    p_location_id    =>  l_location_id,
4092                    x_carrier_id     =>  l_carrier_id,
4093                    x_return_status  =>  l_return_status);
4094 
4095        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4096          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4097           IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
4098             raise FND_API.G_EXC_UNEXPECTED_ERROR;
4099           END IF;
4100           raise g_get_carrier_failed;
4101          END IF;
4102        END IF;
4103 
4104        l_object1_type := G_COMP_CARRIER;
4105        l_object1_id := l_carrier_id;
4106        l_object1_parent_id := null;
4107        l_object2_type := l_object2_typesub;
4108        l_object2_id := p_object2_val_num;
4109        l_object2_val_char := p_object2_val_char;
4110 
4111 
4112        IF l_carrier_id IS NOT NULL THEN
4113 
4114           l2_hash_string :=        (l_comp_class_id)||'-'||l_object1_type||'-'||       (l_object1_id)||'-'||       (nvl(l_object1_parent_id,-9999))||
4115           '-'||l_object2_type||'-'||nvl(       to_char(l_object2_id),l_object2_val_char)||'-'||       (-9999);
4116 
4117           l2_hash_value := dbms_utility.get_hash_value(
4118                                   name => l2_hash_string,
4119                                   base => g_hash_base,
4120                                   hash_size =>g_hash_size );
4121 
4122           --
4123           IF l_debug_on THEN
4124             WSH_DEBUG_SV.logmsg(l_module_name,'l2_hash_string : '||l2_hash_string);
4125             WSH_DEBUG_SV.logmsg(l_module_name,'l2_hash_value : '||l2_hash_value);
4126           END IF;
4127           --
4128 
4129          IF check_cache(l2_hash_value,l2_hash_string) THEN
4130            IF g_comp_constraint_tab(l2_hash_value).constraint_type = p_constraint_type THEN
4131               x_validate_result := g_comp_class_tab(l_hash_value).constraint_violation;
4132               x_failed_constraint.constraint_id := g_comp_constraint_tab(l2_hash_value).compatibility_id;
4133               x_failed_constraint.constraint_class_code := p_comp_class_code;
4134               x_failed_constraint.violation_type := g_comp_class_tab(l_hash_value).constraint_violation;
4135 
4136               --
4137               IF l_debug_on THEN
4138                  WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
4139                  WSH_DEBUG_SV.pop(l_module_name);
4140               END IF;
4141               --
4142               RETURN;  -- Done with as found for the input types
4143 
4144            END IF;
4145 
4146          END IF;
4147        END IF;
4148 
4149        --get_customer_from_loc(
4150        WSH_UTIL_CORE.get_customer_from_loc(
4151                    p_location_id     =>  l_location_id,
4152                    --x_customer_id     =>  l_customer_id,
4153                    x_customer_id_tab   =>  l_customer_id_tab,
4154                    x_return_status  =>  l_return_status);
4155 
4156        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4157          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4158           IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
4159             raise FND_API.G_EXC_UNEXPECTED_ERROR;
4160           END IF;
4161           raise g_get_customer_failed;
4162          END IF;
4163        END IF;
4164 
4165        itr := l_customer_id_tab.FIRST;
4166        IF itr IS NOT NULL THEN
4167        LOOP
4168        --IF l_customer_id IS NOT NULL THEN
4169 
4170          l_object1_type := G_COMP_CUSTOMER;
4171          --l_object1_id := l_customer_id;
4172          l_object1_id := l_customer_id_tab(itr);
4173          l_object1_parent_id := null;
4174          l_object2_type := l_object2_typesub;
4175          l_object2_id := p_object2_val_num;
4176          l_object2_val_char := p_object2_val_char;
4177 
4178 
4179         l3_hash_string :=        (l_comp_class_id)||'-'||l_object1_type||'-'||       (l_object1_id)||'-'||       (nvl(l_object1_parent_id,-9999))||
4180     '-'||l_object2_type||'-'||nvl(       to_char(l_object2_id),l_object2_val_char)||'-'||       (-9999);
4181 
4182         l3_hash_value := dbms_utility.get_hash_value(
4183                                   name => l3_hash_string,
4184                                   base => g_hash_base,
4185                                   hash_size =>g_hash_size );
4186 
4187         --
4188         IF l_debug_on THEN
4189           WSH_DEBUG_SV.logmsg(l_module_name,'l3_hash_string : '||l3_hash_string);
4190           WSH_DEBUG_SV.logmsg(l_module_name,'l3_hash_value : '||l3_hash_value);
4191         END IF;
4192         --
4193 
4194         IF check_cache(l3_hash_value,l3_hash_string) THEN
4195            IF g_comp_constraint_tab(l3_hash_value).constraint_type = p_constraint_type THEN
4196               x_validate_result := g_comp_class_tab(l_hash_value).constraint_violation;
4197               x_failed_constraint.constraint_id := g_comp_constraint_tab(l3_hash_value).compatibility_id;
4198               x_failed_constraint.constraint_class_code := p_comp_class_code;
4199               x_failed_constraint.violation_type := g_comp_class_tab(l_hash_value).constraint_violation;
4200 
4201               --
4202               IF l_debug_on THEN
4203                  WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
4204                  WSH_DEBUG_SV.pop(l_module_name);
4205               END IF;
4206               --
4207               RETURN;  -- Done with as found for the input types
4208 
4209            END IF;
4210 
4211         END IF; -- check_cache(l1_hash_value,l1_hash_string)
4212 
4213        EXIT WHEN itr = l_customer_id_tab.LAST;
4214        itr := l_customer_id_tab.NEXT(itr);
4215 
4216        END LOOP;
4217 
4218        END IF; -- l_customer_id IS NOT NULL
4219 
4220        get_supplier_from_loc(
4221                    p_location_id     =>  l_location_id,
4222                    x_supplier_id     =>  l_supplier_id,
4223                    x_return_status  =>  l_return_status);
4224 
4225        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4226          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4227           IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
4228             raise FND_API.G_EXC_UNEXPECTED_ERROR;
4229           END IF;
4230           raise g_get_supplier_failed;
4231          END IF;
4232        END IF;
4233 
4234        IF l_supplier_id IS NOT NULL THEN
4235 
4236          l_object1_type := G_COMP_SUPPLIER;
4237          l_object1_id := l_supplier_id;
4238          l_object1_parent_id := null;
4239          l_object2_type := l_object2_typesub;
4240          l_object2_id := p_object2_val_num;
4241          l_object2_val_char := p_object2_val_char;
4242 
4243 
4244         l4_hash_string :=        (l_comp_class_id)||'-'||l_object1_type||'-'||       (l_object1_id)||'-'||       (nvl(l_object1_parent_id,-9999))||
4245     '-'||l_object2_type||'-'||nvl(       to_char(l_object2_id),l_object2_val_char)||'-'||       (-9999);
4246 
4247         l4_hash_value := dbms_utility.get_hash_value(
4248                                   name => l4_hash_string,
4249                                   base => g_hash_base,
4250                                   hash_size =>g_hash_size );
4251 
4252         --
4253         IF l_debug_on THEN
4254           WSH_DEBUG_SV.logmsg(l_module_name,'l4_hash_string : '||l4_hash_string);
4255           WSH_DEBUG_SV.logmsg(l_module_name,'l4_hash_value : '||l4_hash_value);
4256         END IF;
4257         --
4258 
4259         IF check_cache(l4_hash_value,l4_hash_string) THEN
4260            IF g_comp_constraint_tab(l4_hash_value).constraint_type = p_constraint_type THEN
4261               x_validate_result := g_comp_class_tab(l_hash_value).constraint_violation;
4262               x_failed_constraint.constraint_id := g_comp_constraint_tab(l4_hash_value).compatibility_id;
4263               x_failed_constraint.constraint_class_code := p_comp_class_code;
4264               x_failed_constraint.violation_type := g_comp_class_tab(l_hash_value).constraint_violation;
4265 
4266               --
4267               IF l_debug_on THEN
4268                  WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
4269                  WSH_DEBUG_SV.pop(l_module_name);
4270               END IF;
4271               --
4272               RETURN;  -- Done with as found for the input types
4273 
4274            END IF;
4275 
4276         END IF; -- check_cache(l4_hash_value,l4_hash_string)
4277        END IF; -- l_supplier_id IS NOT NULL
4278     END IF;
4279 
4280     -- Validate for REG-FAC constrait
4281     -- Constraint type should be ORG_FAC, CUS_FAC, SUP_FAC
4282     -- Validates only exclusive constraints
4283     -- Object 1 type should be FAC or ORG.
4284 
4285     -- Do not call validate_region_constraint for inclusive constraint
4286     -- if the call is for a single leg delivery
4287 
4288      IF ( p_comp_class_code IN (G_SHIPORG_FACILITY,G_CUSTOMER_FACILITY,G_SUPPLIER_FACILITY)
4289          --AND p_object1_type IN (G_FACILITY,G_COMP_ORG)
4290 	 --AND p_object2_type = G_FACILITY
4291          AND l_object1_typesub IN (G_FACILITY,G_COMP_ORG)
4292 	 AND l_object2_typesub = G_FACILITY
4293          AND (p_constraint_type = 'E' OR NOT (p_direct_shipment)) )
4294      THEN
4295 
4296              -- Pseudo Code -
4297          -- 1. Validate for the location.
4298          -- 2. In case we have a Master Org then we have to validate constraints at
4299          --    Master Org level if Constraits are not present at org level.
4300 
4301          IF (p_comp_class_code = G_SHIPORG_FACILITY  AND l_object1_typesub = G_COMP_ORG) THEN
4302 
4303          --
4304          -- Bug 4142393:Replaced call to WSH_UTIL_CORE.ORG_TO_LOCATION by get_loc_for_org
4305          --
4306 
4307                 get_loc_for_org(
4308                   p_org_id	       => p_object1_val_num,
4309                   x_location_id    => l_location_id,
4310                   x_return_status  => x_return_status);
4311 
4312 
4313                 IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4314                     IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4315                        raise FND_API.G_EXC_UNEXPECTED_ERROR;
4316                     END IF;
4317                 END IF;
4318          ELSE
4319               l_location_id := p_object1_val_num;
4320          END IF;
4321 
4322        --
4323        -- Bug 4142393:Region constraints are validated only when location id is not NULL
4324        --
4325 
4326        IF (l_location_id IS NOT NULL) THEN
4327 
4328           validate_region_constraint(
4329              p_location_id       => l_location_id,
4330 	         p_constraint_type   => p_constraint_type,
4331 	         p_object2_val_num   => p_object2_val_num,
4332              x_validate_result   => x_validate_result,
4333              x_failed_constraint => x_failed_constraint,
4334              x_return_status     => x_return_status);
4335 
4336           IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4337 		IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4338 		   raise FND_API.G_EXC_UNEXPECTED_ERROR;
4339 		END IF;
4340 	  END IF;
4341 
4342         END IF;
4343 
4344         --  We need to validate Exclusive constraints for master Org in the following scenario.
4345 	--  a) Master Org exists for the organization.
4346 	--  b) x_validate_result is 'S' , this implies we had no constraint at org level
4347 
4348         IF (l_master_org_id <> p_object1_val_num) AND (x_validate_result ='S')
4349 	    AND (p_comp_class_code=G_SHIPORG_FACILITY) AND (l_object1_typesub = G_COMP_ORG) THEN
4350 
4351 
4352 	  --
4353           -- Bug 4142393:Replaced call to WSH_UTIL_CORE.ORG_TO_LOCATION by get_loc_for_org
4354           --
4355 
4356            get_loc_for_org(
4357               p_org_id	       => l_master_org_id,
4358               x_location_id    => l_location_id,
4359               x_return_status  => x_return_status);
4360 
4361  	   IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4362 	       IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4363 		   raise FND_API.G_EXC_UNEXPECTED_ERROR;
4364 	        END IF;
4365   	   END IF;
4366 
4367 	  --
4368           -- Bug 4142393:Region constraints are validated only when location id is not NULL
4369           --
4370 
4371 	   IF (l_location_id IS NOT NULL) THEN
4372 
4373 	     validate_region_constraint(
4374                 p_location_id       => l_location_id,
4375 	        p_constraint_type   => p_constraint_type,
4376 		p_object2_val_num   => p_object2_val_num,
4377                 x_validate_result   => x_validate_result,
4378                 x_failed_constraint => x_failed_constraint,
4379                 x_return_status     => x_return_status);
4380 
4381               IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4382 	         IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4383 		    raise FND_API.G_EXC_UNEXPECTED_ERROR;
4384 	         END IF;
4385 	      END IF;
4386 
4387 	    END IF;
4388 
4389 	END IF; --(If master org Exists)
4390 
4391     END IF;--( End of Validate Region Level Constraints)
4392 
4393     --
4394     IF l_debug_on THEN
4395       WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
4396       WSH_DEBUG_SV.pop(l_module_name);
4397     END IF;
4398     --
4399 
4400 EXCEPTION
4401 
4402     WHEN g_get_mast_org_failed THEN
4403       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4404       --
4405       IF l_debug_on THEN
4406         WSH_DEBUG_SV.pop(l_module_name,' get_mast_org failed ');
4407       END IF;
4408       --
4409     WHEN g_get_carrier_failed THEN
4410       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4411       --
4412       IF l_debug_on THEN
4413         WSH_DEBUG_SV.pop(l_module_name,' get_carrier failed ');
4414       END IF;
4415       --
4416     WHEN g_get_customer_failed THEN
4417       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4418       --
4419       IF l_debug_on THEN
4420         WSH_DEBUG_SV.pop(l_module_name,' get_customer failed ');
4421       END IF;
4422       --
4423     WHEN g_get_supplier_failed THEN
4424       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4425       --
4426       IF l_debug_on THEN
4427         WSH_DEBUG_SV.pop(l_module_name,' get_supplier failed ');
4428       END IF;
4429       --
4430 
4431     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
4432       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
4433       --
4434       IF l_debug_on THEN
4435         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
4436         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
4437       END IF;
4438       --
4439     WHEN others THEN
4440       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.validate_constraint');
4441       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
4442       --
4443       IF l_debug_on THEN
4444         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
4445         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
4446       END IF;
4447       --
4448 END validate_constraint;
4449 
4450 
4451 --***************************************************************************--
4452 --
4453 --========================================================================
4454 -- PROCEDURE : check_inclusive_facilities PRIVATE
4455 --
4456 -- PARAMETERS: p_comp_class_code          Compatibility class code
4457 --             p_entity_type              Entity for which check is running
4458 --             p_entity_id                Entity id for which check is running
4459 --             p_object1_type	          Constraint Object1 Type
4460 --             p_object1_physical_id      Physical Location Id - Passed in only for CUS_FAC for Customer Facility
4461 --             p_attribute_id             Constraint Object1 id
4462 --             p_parent_id                Constraint Object1 Parent id
4463 --             p_location_list            Table of location ids to be checked as
4464 --                                        constraint object 2
4465 --             p_direct_shipment          Is the shipment multileg
4466 --             x_validate_result          Constraint Validation result : S / E / W
4467 --             x_failed_constraint        failed constraint table
4468 --             x_return_status            Return status
4469 -- COMMENT   :
4470 -- For a given parameter 1 of a constraint definition
4471 -- and a list of locations which could be parameter2
4472 -- determines if parameter 1 is compatible with the location list
4473 -- Applies to following constraint types :
4474 -- A. Org - Facility
4475 -- B. Customer - Facility
4476 -- C. Supplier - Facility
4477 -- D. Item - Facility
4478 -- Assumes object1 and object2 have been passed as the class requires/defines
4479 --========================================================================
4480 
4481 PROCEDURE check_inclusive_facilities(
4482             p_comp_class_code          IN      VARCHAR2,
4483             p_entity_type              IN      VARCHAR2,
4484             p_entity_id                IN      NUMBER,
4485             p_object1_type             IN      VARCHAR2 DEFAULT NULL,
4486             p_object1_physical_id      IN      NUMBER	DEFAULT NULL,
4487 	        p_attribute_id             IN      NUMBER,
4488             p_parent_id                IN      NUMBER DEFAULT NULL,
4489             p_location_list            IN      WSH_UTIL_CORE.id_tab_type,
4490             p_direct_shipment          IN      BOOLEAN DEFAULT FALSE,
4491             x_validate_result          OUT NOCOPY     VARCHAR2,
4492             x_failed_constraint        IN  OUT NOCOPY  line_constraint_tab_type,
4493             x_return_status            OUT NOCOPY     VARCHAR2)
4494 IS
4495 
4496     l_object1_type         VARCHAR2(30):=NULL;
4497     l_return_status        VARCHAR2(1);
4498     l_validate_result      VARCHAR2(1);   -- S / F
4499     l_parent_id            NUMBER := p_parent_id;  -- Only for item
4500     l_carrier_id           NUMBER :=0;
4501     l_customer_id          NUMBER :=0;
4502     l_hash_value           NUMBER :=0;
4503     l_hash_active          NUMBER:=0;
4504     l_master_org_id        NUMBER:=0;
4505     l_master_org           BOOLEAN := FALSE;
4506     l1_hash_value          NUMBER;
4507     l11_hash_value         NUMBER;
4508     l2_hash_value          NUMBER;
4509     l21_hash_value         NUMBER;
4510     l3_hash_value          NUMBER;
4511     l31_hash_value         NUMBER;
4512     l1_hash_string         VARCHAR2(200);
4513     l11_hash_string        VARCHAR2(200);
4514     l2_hash_string         VARCHAR2(200);
4515     l21_hash_string        VARCHAR2(200);
4516     l3_hash_string         VARCHAR2(200);
4517     l31_hash_string        VARCHAR2(200);
4518     l_comp_class_id        NUMBER :=0;
4519     failed_cons_last       NUMBER:= x_failed_constraint.COUNT;
4520     l                      NUMBER :=0;
4521     k                      NUMBER :=0;
4522     i                      NUMBER :=0;
4523     l_incl_cons            BOOLEAN := FALSE;
4524 
4525     l_location_id	       NUMBER :=0;
4526 
4527     --DUM_LOC(S)
4528     l_organization_tab	   WSH_UTIL_CORE.id_tab_type;
4529     l_org_itr		       NUMBER;
4530     l_failed_constraint    line_constraint_tab_type;
4531     l_itr		           NUMBER;
4532     --DUM_LOC(E)
4533 
4534     l_module_name          CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'check_inclusive_facilities';
4535     l_debug_on             CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
4536 
4537 BEGIN
4538 
4539     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
4540 
4541     x_validate_result := 'F';
4542     l_validate_result := 'F';
4543 
4544     IF l_debug_on THEN
4545       wsh_debug_sv.push(l_module_name);
4546       WSH_DEBUG_SV.logmsg(l_module_name,'Input comp class code : '||p_comp_class_code);
4547       WSH_DEBUG_SV.logmsg(l_module_name,'Input Object1 type : '||p_object1_type);
4548       WSH_DEBUG_SV.logmsg(l_module_name,'Object1 val num : '||p_attribute_id);
4549       WSH_DEBUG_SV.logmsg(l_module_name,'Object 1 parent : '||l_parent_id);
4550       WSH_DEBUG_SV.logmsg(l_module_name,'Object2 count  : '||p_location_list.count);
4551       IF p_direct_shipment THEN
4552        WSH_DEBUG_SV.logmsg(l_module_name,'p_direct_shipment is true');
4553       ELSE
4554        WSH_DEBUG_SV.logmsg(l_module_name,'p_direct_shipment is false');
4555       END IF;
4556     END IF;
4557 
4558     --return if object1 is NULL
4559     IF p_attribute_id IS NULL THEN
4560     --IF p_attribute_id IS NULL OR p_location_list.count = 0 THEN
4561       x_validate_result := 'S';
4562       --
4563       IF l_debug_on THEN
4564         WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
4565         WSH_DEBUG_SV.pop(l_module_name);
4566       END IF;
4567       --
4568       RETURN;
4569     END IF;
4570 
4571     IF p_object1_type IS NULL THEN
4572     IF p_comp_class_code = G_SHIPORG_FACILITY THEN
4573        l_object1_type := 'ORG';
4574     ELSIF p_comp_class_code = G_CUSTOMER_FACILITY THEN
4575        l_object1_type := 'CUS';
4576     ELSIF p_comp_class_code = G_SUPPLIER_FACILITY THEN
4577        l_object1_type := 'SUP';
4578     ELSIF p_comp_class_code = G_ITEM_FACILITY THEN
4579        l_object1_type := 'ITM';
4580     END IF;
4581     ELSE
4582        l_object1_type := p_object1_type;
4583     END IF;
4584 
4585     -- AGDUMMY - Put the dummy cus fac to org conversion code here
4586     -- Note that for dummy customer facilities, no constraints can exist
4587     -- For Dummy customer faciliter only ORG_FAC constraints can exist.
4588 
4589     -- For dummy constraints we validate all the ORG_FAC constraints that are
4590     -- associated with the location.
4591 
4592     IF (p_comp_class_code = G_CUSTOMER_FACILITY) AND (l_object1_type = G_FACILITY)
4593 	AND (p_object1_physical_id IS NOT NULL) THEN
4594 
4595 	--get_org_from_location(
4596 	WSH_UTIL_CORE.get_org_from_location(
4597               p_location_id	  => p_object1_physical_id,
4598               x_organization_tab  => l_organization_tab,
4599               x_return_status     => l_return_status);
4600 
4601 
4602 	IF l_debug_on THEN
4603 	    WSH_DEBUG_SV.logmsg(l_module_name,'l_return_status:'||l_return_status);
4604         WSH_DEBUG_SV.logmsg(l_module_name,'Organizations Returned:'||l_organization_tab.Count);
4605 	END IF;
4606 
4607 
4608 	IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4609           IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
4610             raise FND_API.G_EXC_UNEXPECTED_ERROR;
4611           END IF;
4612         END IF;
4613 
4614 	l_org_itr := l_organization_tab.FIRST;
4615 
4616 	IF l_org_itr IS NOT NULL THEN
4617           LOOP
4618 
4619 	   check_inclusive_facilities(
4620 		p_comp_class_code         => G_SHIPORG_FACILITY,
4621 		p_entity_type             => p_entity_type,
4622 		p_entity_id               => p_entity_id,
4623                 p_object1_type            => G_COMP_ORG     ,
4624                 p_attribute_id            => l_organization_tab(l_org_itr),
4625                 p_location_list           => p_location_list,
4626                 p_direct_shipment         => p_direct_shipment,
4627                 x_validate_result         => x_validate_result,
4628                 x_failed_constraint       => x_failed_constraint,
4629                 x_return_status           => x_return_status);
4630 
4631 	       IF l_debug_on THEN
4632 	   	   WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
4633 		   WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_return_status :   '||x_return_status);
4634 	       END IF;
4635 
4636 	       IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4637 	         IF x_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
4638 	            raise FND_API.G_EXC_UNEXPECTED_ERROR;
4639                  END IF;
4640                END IF;
4641 
4642 	   -- When we are getting a constraint at org level we return.
4643      	   -- Need to add constraints to the level.
4644 
4645                EXIT WHEN (x_validate_result <> 'S' OR l_org_itr= l_organization_tab.LAST);
4646                l_org_itr:= l_organization_tab.NEXT(l_org_itr);
4647             END LOOP;
4648 
4649 	  ELSE
4650 		--No organizations exist for the location.
4651 		x_validate_result := 'S';
4652 	  END IF;
4653           --
4654 
4655 	  IF l_debug_on THEN
4656              WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
4657              WSH_DEBUG_SV.pop(l_module_name);
4658           END IF;
4659           --
4660           RETURN;
4661 
4662      END IF;
4663     --#DUM_LOC(E)
4664 
4665     l_hash_value := dbms_utility.get_hash_value(
4666                                   name => p_comp_class_code,
4667                                   base => g_hash_base,
4668                                   hash_size =>g_hash_size );
4669 
4670     -- If g_comp_class_tab has a recrd for p_comp_class_code
4671     -- but g_comp_constraint_tab does not have records for p_comp_class_code
4672     -- it will be a problem
4673     IF NOT (g_comp_class_tab.EXISTS(l_hash_value) AND
4674             g_comp_class_tab(l_hash_value).compatibility_class_code = p_comp_class_code) THEN
4675 
4676       populate_constraint_cache(
4677           p_comp_class_code          =>    p_comp_class_code,
4678           x_return_status            =>    l_return_status) ;
4679       --
4680       IF l_debug_on THEN
4681         WSH_DEBUG_SV.logmsg(l_module_name,'Called populate_constraint_cache return status : '||l_return_status);
4682       END IF;
4683       --
4684 
4685       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4686          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4687             raise FND_API.G_EXC_UNEXPECTED_ERROR;
4688          END IF;
4689       END IF;
4690 
4691     END IF;
4692 
4693     l_comp_class_id := g_comp_class_tab(l_hash_value).COMPATIBILITY_CLASS_ID;
4694 
4695     -- If any of the locations in the list belong to
4696     -- For org facility on RHS, type = FAC and location id is stored
4697     -- 1. object2 type = FAC and object2 id = location_id
4698     -- 2. For ORG_FAC : object2 type = CAR and object2 id = carrier_id (get carrier for location)
4699     --              Also check if anything is defined for master ORG if not found for input ORG
4700     -- 3. For CUS_FAC : object2 type = CAR and object2 id = carrier_id (get carrier for location)
4701     -- 4. For ITM_FAC : object2 type = CAR and object2 id = carrier_id (get carrier for location)
4702     --                  object2 type = CUS and object2 id = customer_id (get customer for location)
4703     --                  object2 type = SUP and object2 id = supplier_id (get supplier for location)
4704     -- 5. For SUP_FAC : object2 type = CAR and object2 id = carrier_id (get carrier for location)
4705     -- Return success
4706 
4707     IF p_comp_class_code = G_SHIPORG_FACILITY THEN
4708 
4709           WSH_UTIL_CORE.get_master_from_org(
4710               p_org_id         => p_attribute_id,
4711               x_master_org_id  => l_master_org_id,
4712               x_return_status  => l_return_status);
4713 
4714       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4715          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4716          IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
4717             raise FND_API.G_EXC_UNEXPECTED_ERROR;
4718          END IF;
4719             raise g_get_mast_org_failed;
4720          END IF;
4721       END IF;
4722 
4723       IF l_master_org_id <> p_attribute_id THEN -- Input ORG is child of l_master_org_id
4724 
4725          l_master_org := TRUE;
4726 
4727       END IF;
4728 
4729     END IF;
4730 
4731     IF g_is_tp_installed IS NULL THEN
4732      g_is_tp_installed := WSH_UTIL_CORE.TP_Is_Installed;
4733     END IF;
4734 
4735     IF (l_object1_type = 'ITM' AND g_is_tp_installed = 'Y') THEN
4736        l_parent_id := NULL;
4737     END IF;
4738 
4739     i := p_location_list.FIRST;
4740     IF i IS NOT NULL THEN
4741       LOOP
4742 
4743        --
4744        IF l_debug_on THEN
4745          WSH_DEBUG_SV.logmsg(l_module_name,'p_location_list  : '||p_location_list(i));
4746        END IF;
4747        --
4748 
4749     -- Need a data structure for hashing constraints
4750     -- hash by class+obj1 type+obj1+obj1 parent+obj2 type+obj2+obj2 parent
4751     -- As this combination defines a unique key
4752 
4753        l1_hash_string :=        (l_comp_class_id)||'-'||l_object1_type||'-'||       (p_attribute_id)||'-'||       (nvl(l_parent_id,-9999))||
4754        '-'||'FAC'||'-'||       (p_location_list(i))||'-'||       (-9999);
4755 
4756        l1_hash_value := dbms_utility.get_hash_value(
4757                                   name => l1_hash_string,
4758                                   base => g_hash_base,
4759                                   hash_size =>g_hash_size );
4760        --
4761        IF l_debug_on THEN
4762          WSH_DEBUG_SV.logmsg(l_module_name,'l1_hash_string : '||l1_hash_string);
4763          WSH_DEBUG_SV.logmsg(l_module_name,'l1_hash_value : '||l1_hash_value);
4764        END IF;
4765        --
4766 
4767        IF l_master_org THEN
4768 
4769           l11_hash_string := (l_comp_class_id)||'-'||l_object1_type||'-'||to_char(l_master_org_id)||'-'||(nvl(l_parent_id,-9999))||
4770           '-'||'FAC'||'-'||to_char(p_location_list(i))||'-'||(-9999);
4771 
4772           l11_hash_value := dbms_utility.get_hash_value(
4773                                   name => l11_hash_string,
4774                                   base => g_hash_base,
4775                                   hash_size =>g_hash_size );
4776 
4777           --
4778           IF l_debug_on THEN
4779              WSH_DEBUG_SV.logmsg(l_module_name,'l11_hash_string : '||l11_hash_string);
4780              WSH_DEBUG_SV.logmsg(l_module_name,'l11_hash_value : '||l11_hash_value);
4781           END IF;
4782           --
4783 
4784        END IF;
4785 
4786        IF check_cache(l1_hash_value,l1_hash_string) THEN
4787 
4788            IF g_comp_constraint_tab(l1_hash_value).constraint_type = 'I' THEN
4789 
4790               x_validate_result := 'S';
4791               l_validate_result := 'S';
4792               EXIT;
4793 
4794            END IF;
4795 
4796        ELSIF l_master_org AND check_cache(l11_hash_value,l11_hash_string) THEN
4797 
4798            IF g_comp_constraint_tab(l11_hash_value).constraint_type = 'I' THEN
4799 
4800               x_validate_result := 'S';
4801               l_validate_result := 'S';
4802               EXIT;
4803 
4804            END IF;
4805 
4806        END IF;
4807 
4808        EXIT WHEN i=p_location_list.LAST;
4809        i := p_location_list.NEXT(i);
4810 
4811       END LOOP;
4812     END IF;
4813 
4814     IF x_validate_result = 'F' THEN
4815       -- LOOP over g_comp_constraint_tab
4816       l := failed_cons_last;
4817       k := g_comp_constraint_tab.FIRST;
4818       IF k IS NOT NULL THEN
4819        LOOP
4820 
4821         IF g_comp_constraint_tab(k).compatibility_class_id = l_comp_class_id AND
4822            g_comp_constraint_tab(k).CONSTRAINT_OBJECT1_TYPE = l_object1_type AND
4823            nvl(g_comp_constraint_tab(k).OBJECT1_SOURCE_ID,-9999) = nvl(l_parent_id,-9999) AND
4824            (g_comp_constraint_tab(k).CONSTRAINT_OBJECT1_ID = p_attribute_id OR
4825            (l_master_org AND g_comp_constraint_tab(k).CONSTRAINT_OBJECT1_ID = l_master_org_id)) THEN
4826 
4827            --
4828            IF l_debug_on THEN
4829               WSH_DEBUG_SV.logmsg(l_module_name,' Input has constraint : '||g_comp_constraint_tab(k).compatibility_id);
4830            END IF;
4831            --
4832 
4833            IF g_comp_constraint_tab(k).constraint_type = 'I' THEN
4834 
4835              -- Add to the x_failed_constraint
4836              l := l + 1;
4837              x_failed_constraint(l).constraint_id := g_comp_constraint_tab(k).compatibility_id;
4838              x_failed_constraint(l).entity_type := p_entity_type;
4839              x_failed_constraint(l).entity_line_id := p_entity_id;
4840              x_failed_constraint(l).constraint_class_code := p_comp_class_code;
4841              x_failed_constraint(l).violation_type := g_comp_class_tab(l_hash_value).constraint_violation;
4842              l_validate_result := g_comp_class_tab(l_hash_value).constraint_violation;
4843              l_incl_cons := TRUE;
4844 
4845            END IF;
4846         END IF;
4847 
4848         EXIT WHEN k=g_comp_constraint_tab.LAST;
4849         k := g_comp_constraint_tab.NEXT(k);
4850 
4851        END LOOP;
4852       END IF;
4853 
4854    IF NOT l_incl_cons THEN
4855 
4856         IF l_debug_on THEN
4857               WSH_DEBUG_SV.logmsg(l_module_name,' Checking to see if we need to call check_reg_incl_facilities');
4858               WSH_DEBUG_SV.logmsg(l_module_name,' p_comp_class_code : '||p_comp_class_code);
4859               WSH_DEBUG_SV.logmsg(l_module_name,' l_object1_type : '|| l_object1_type);
4860         END IF;
4861 
4862 	IF (p_comp_class_code IN ( G_SHIPORG_FACILITY, G_CUSTOMER_FACILITY, G_SUPPLIER_FACILITY)
4863 	    AND l_object1_type IN (G_FACILITY,G_COMP_ORG)
4864             AND NOT (p_direct_shipment))
4865 	THEN
4866 
4867 	      -- We need to validate Region Level Constraints;
4868 	      IF (p_comp_class_code = G_SHIPORG_FACILITY) THEN
4869 
4870                   --
4871 		  -- Bug 4142393:Replaced call to WSH_UTIL_CORE.ORG_TO_LOCATION by get_loc_for_org
4872 		  --
4873 
4874 		  get_loc_for_org(
4875 			p_org_id	 => p_attribute_id,
4876 			x_location_id    => l_location_id,
4877 			x_return_status  => x_return_status);
4878 
4879 	 	   IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4880 		       IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4881 			   raise FND_API.G_EXC_UNEXPECTED_ERROR;
4882 			END IF;
4883 	  	   END IF;
4884 
4885 	      ELSE
4886 	          l_location_id := p_attribute_id;
4887 	      END IF;
4888 
4889     	      --
4890 	      --Bug 4142393:check_reg_incl_facilities is called only when location id is not null
4891 	      --
4892 
4893 	      IF (l_location_id IS NOT NULL) THEN
4894 
4895 	              IF l_debug_on THEN
4896 		         WSH_DEBUG_SV.logmsg(l_module_name,' calling check_reg_incl_facilities for input');
4897 		      END IF;
4898 
4899 		      -- We have the location id .
4900 		      -- Call validate inclusive locations to get the result.
4901 		      -- This API will return the results it finds.
4902 
4903 		      check_reg_incl_facilities(
4904 		            p_entity_type       => p_entity_type,
4905 			    p_entity_id         => p_entity_id,
4906 			    p_location_id       => l_location_id,
4907 		            p_location_list     => p_location_list,
4908 			    x_validate_result   => x_validate_result,
4909 			    x_failed_constraint => x_failed_constraint,
4910 			    x_return_status     => x_return_status);
4911 
4912 		      IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4913 	   		   IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4914 				raise FND_API.G_EXC_UNEXPECTED_ERROR;
4915 			   END IF;
4916  		      END IF;
4917 
4918 	       END IF;
4919 
4920   	      -- Master org is there , we need to validate for the master Org also.
4921 
4922 	       IF (l_master_org) AND (x_validate_result = 'S') THEN
4923 
4924 		 --
4925 		 -- Bug 4142393:Replaced call to WSH_UTIL_CORE.ORG_TO_LOCATION by get_loc_for_org
4926 	         --
4927 
4928 		 get_loc_for_org(
4929 			p_org_id	 => l_master_org_id,
4930 		        x_location_id    => l_location_id,
4931 			x_return_status  => x_return_status);
4932 
4933 	 	   IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4934 		       IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4935 			   raise FND_API.G_EXC_UNEXPECTED_ERROR;
4936 			END IF;
4937   		   END IF;
4938 
4939 		--
4940 		--Bug 4142393:check_reg_incl_facilities is called only when location id is not null
4941 		--
4942 
4943 		IF (l_location_id IS NOT NULL) THEN
4944 
4945 			IF l_debug_on THEN
4946 				WSH_DEBUG_SV.logmsg(l_module_name,' calling check_reg_incl_facilities for master org of input org');
4947 			END IF;
4948 
4949 			check_reg_incl_facilities(
4950 			    p_entity_type       => p_entity_type,
4951 			    p_entity_id         => p_entity_id,
4952 			    p_location_id       => l_location_id,
4953 			    p_location_list     => p_location_list,
4954 			    x_validate_result   => x_validate_result,
4955 			    x_failed_constraint => x_failed_constraint,
4956 			    x_return_status     => x_return_status);
4957 
4958 			 IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
4959 			    IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
4960 			       raise FND_API.G_EXC_UNEXPECTED_ERROR;
4961 			    END IF;
4962 			 END IF;
4963 
4964 		  END IF;
4965 
4966 	     END IF;
4967 
4968 	ELSE
4969 	      x_validate_result := 'S';
4970 	END IF;  -- (p_comp_class_code IN (G_SHIPORG_FACILITY, G_CUSTOMER_FACILITY)
4971 
4972       ELSE
4973 
4974          IF l_validate_result = 'W' THEN
4975             x_validate_result := 'W';
4976          END IF;
4977 
4978       END IF;
4979 
4980     END IF;
4981 
4982     --
4983     IF l_debug_on THEN
4984       WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
4985       WSH_DEBUG_SV.pop(l_module_name);
4986     END IF;
4987     --
4988 
4989 EXCEPTION
4990     WHEN g_get_mast_org_failed THEN
4991       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4992       --
4993       IF l_debug_on THEN
4994         WSH_DEBUG_SV.pop(l_module_name,' get_mast_org failed ');
4995       END IF;
4996       --
4997     WHEN g_get_carrier_failed THEN
4998       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
4999       --
5000       IF l_debug_on THEN
5001         WSH_DEBUG_SV.pop(l_module_name,' get_carrier failed ');
5002       END IF;
5003       --
5004     WHEN g_get_customer_failed THEN
5005       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
5006       --
5007       IF l_debug_on THEN
5008         WSH_DEBUG_SV.pop(l_module_name,' get_customer failed ');
5009       END IF;
5010       --
5011 
5012     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5013       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
5014       --
5015       IF l_debug_on THEN
5016         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
5017         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
5018       END IF;
5019       --
5020     WHEN others THEN
5021       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.check_inclusive_facilities');
5022       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
5023       --
5024       IF l_debug_on THEN
5025         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
5026         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
5027       END IF;
5028       --
5029 END check_inclusive_facilities;
5030 
5031 --***************************************************************************--
5032 --========================================================================
5033 -- PROCEDURE : check_inclusive_object2    PRIVATE
5034 --
5035 -- PARAMETERS: p_comp_class_code          Compatibility class code
5036 --             p_entity_type              Entity for which check is running
5037 --             p_entity_id                Entity id for which check is running
5038 --             p_object1_type	          Constraint Object1 Type
5039 --             p_object1_parent_id        Constraint Object1 Parent id
5040 --                                        Required only if object1 = Item
5041 --             p_object1_val_num          Constraint Object1 id
5042 --             p_object2_type	          Constraint Object2 Type
5043 --             p_object2_val_num          Constraint Object2 id
5044 --             p_object2_val_char         Constraint Object2 character code
5045 --             x_out_object2_num          Id of constraint object2 if constraint found
5046 --             x_out_object2_char         Code of constraint object2 if constraint found
5047 --             x_validate_result          Constraint Validation result : S / E / W
5048 --             x_failed_constraint        failed constraint table
5049 --             x_return_status            Return status
5050 -- COMMENT   :
5051 -- For a given parameter 1 of a constraint definition
5052 -- and a parameter2
5053 -- determines if parameter 1 is compatible with parameter2
5054 -- Applies to following constraint types :
5055 -- A. Facility - Carrier
5056 -- B. Facility - Mode
5057 -- C. Facility - Vehicle
5058 -- D. Item - Carrier
5059 -- E. Item - Mode
5060 -- F. Item - Vehicle
5061 -- Assumes object1 and object2 have been passed as the class requires/defines
5062 --========================================================================
5063 
5064 
5065 PROCEDURE check_inclusive_object2(
5066             p_comp_class_code            IN      VARCHAR2,
5067             p_entity_type                IN      VARCHAR2,
5068             p_entity_id                  IN      NUMBER,
5069             p_object1_type               IN      VARCHAR2,
5070             p_object1_val_num            IN      NUMBER,
5071             p_object1_parent_id          IN      NUMBER DEFAULT NULL,
5072             p_object2_type               IN      VARCHAR2,
5073             p_object2_val_num            IN      NUMBER DEFAULT NULL,
5074             p_object2_val_char           IN      VARCHAR2 DEFAULT NULL,
5075             x_out_object2_num            OUT NOCOPY     NUMBER,
5076             x_out_object2_char           OUT NOCOPY     VARCHAR2,
5077             x_validate_result            OUT NOCOPY     VARCHAR2,
5078             x_failed_constraint          IN OUT NOCOPY  line_constraint_tab_type,
5079             x_return_status              OUT NOCOPY     VARCHAR2)
5080 IS
5081 
5082     --l_object1_type         VARCHAR2(30):=NULL;
5083     l_return_status        VARCHAR2(1);
5084     l_carrier_id           NUMBER :=0;
5085     l_customer_id          NUMBER :=0;
5086     l_customer_id_tab   WSH_UTIL_CORE.id_tab_type;
5087     l_supplier_id          NUMBER:=0;
5088     l_object1_parent_id    NUMBER := p_object1_parent_id;
5089     l_hash_value           NUMBER :=0;
5090     l1_hash_value          NUMBER;
5091     l2_hash_value          NUMBER;
5092     l3_hash_value          NUMBER;
5093     l4_hash_value          NUMBER;
5094     l1_hash_string         VARCHAR2(200);
5095     l2_hash_string         VARCHAR2(200);
5096     l3_hash_string         VARCHAR2(200);
5097     l4_hash_string         VARCHAR2(200);
5098     l_comp_class_id        NUMBER :=0;
5099     l_compclass_severity   VARCHAR2(30):=NULL;
5100     failed_cons_last       NUMBER:= x_failed_constraint.COUNT;
5101     itr                    NUMBER :=0;
5102     l                      NUMBER :=0;
5103     k                      NUMBER :=0;
5104     l_incl_cons            BOOLEAN := FALSE;
5105     l_object1_typesub      VARCHAR2(30):=NULL;
5106     l_object2_typesub      VARCHAR2(30):=NULL;
5107     l_comp_type1           VARCHAR2(3) := SUBSTR(p_comp_class_code,1,3);
5108     l_comp_type2           VARCHAR2(3) := SUBSTR(p_comp_class_code,5,3);
5109 
5110     l_module_name          CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'check_inclusive_object2';
5111     l_debug_on             CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
5112 
5113 BEGIN
5114 
5115     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
5116 
5117     x_validate_result := 'F';
5118     x_out_object2_num          :=  NULL;
5119     x_out_object2_char         :=  NULL;
5120 
5121     IF l_debug_on THEN
5122       wsh_debug_sv.push(l_module_name);
5123       WSH_DEBUG_SV.logmsg(l_module_name,'Input comp class code : '||p_comp_class_code);
5124       WSH_DEBUG_SV.logmsg(l_module_name,'Input Object1 type : '||p_object1_type);
5125       WSH_DEBUG_SV.logmsg(l_module_name,'Input Object2 type : '||p_object2_type);
5126       WSH_DEBUG_SV.logmsg(l_module_name,'Object1 val num : '||p_object1_val_num);
5127       WSH_DEBUG_SV.logmsg(l_module_name,'Object 1 parent : '||l_object1_parent_id);
5128       WSH_DEBUG_SV.logmsg(l_module_name,'Object2 val num : '||p_object2_val_num);
5129       WSH_DEBUG_SV.logmsg(l_module_name,'Object 2 val char : '||p_object2_val_char);
5130     END IF;
5131 
5132     --return if object1 is NULL
5133     IF p_object1_val_num IS NULL THEN
5134       x_validate_result := 'S';
5135       --
5136       IF l_debug_on THEN
5137         WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
5138         WSH_DEBUG_SV.pop(l_module_name);
5139       END IF;
5140       --
5141       RETURN;
5142     END IF;
5143 
5144     -- Must pass in object types when CLASS code contains FAC
5145 
5146     l_object1_typesub := nvl(p_object1_type,l_comp_type1);
5147     l_object2_typesub := nvl(p_object2_type,l_comp_type2);
5148 
5149     l_hash_value := dbms_utility.get_hash_value(
5150                                   name => p_comp_class_code,
5151                                   base => g_hash_base,
5152                                   hash_size =>g_hash_size );
5153 
5154     --IF NOT g_comp_class_tab.EXISTS(l_hash_value) THEN
5155     IF NOT (g_comp_class_tab.EXISTS(l_hash_value) AND
5156             g_comp_class_tab(l_hash_value).compatibility_class_code = p_comp_class_code) THEN
5157 
5158       populate_constraint_cache(
5159           p_comp_class_code          =>    p_comp_class_code,
5160           x_return_status            =>    l_return_status) ;
5161       --
5162       IF l_debug_on THEN
5163         WSH_DEBUG_SV.logmsg(l_module_name,'Called populate_constraint_cache with return status : '||l_return_status);
5164       END IF;
5165       --
5166 
5167       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
5168          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5169             raise FND_API.G_EXC_UNEXPECTED_ERROR;
5170          END IF;
5171       END IF;
5172 
5173     END IF;
5174 
5175     l_comp_class_id := g_comp_class_tab(l_hash_value).COMPATIBILITY_CLASS_ID;
5176     l_compclass_severity := g_comp_class_tab(l_hash_value).CONSTRAINT_VIOLATION;
5177 
5178     --
5179     IF l_debug_on THEN
5180       WSH_DEBUG_SV.logmsg(l_module_name,'Comp class id : '||l_comp_class_id);
5181       WSH_DEBUG_SV.logmsg(l_module_name,'l_compclass_severity : '||l_compclass_severity);
5182     END IF;
5183     --
5184 
5185     IF g_is_tp_installed IS NULL THEN
5186      g_is_tp_installed := WSH_UTIL_CORE.TP_Is_Installed;
5187     END IF;
5188 
5189     --IF (l_object1_typesub = 'ITM' AND WSH_UTIL_CORE.TP_Is_Installed = 'Y') THEN
5190     IF (l_object1_typesub = 'ITM' AND g_is_tp_installed = 'Y') THEN
5191        l_object1_parent_id := NULL;
5192     END IF;
5193 
5194 
5195     -- If the location belongs to an I constraint for obj2
5196     -- 1. object1 type = FAC and object1 id = location_id
5197     -- 2. For FAC_CAR : object1 type = CAR and object1 id = carrier_id (get carrier for location)
5198     -- 3. For FAC_MOD : object1 type = CAR and object1 id = carrier_id (get carrier for location)
5199     --                  object1 type = CUS and object1 id = customer_id (get customer for location)
5200     -- 4. For FAC_VEH : object1 type = CAR and object1 id = carrier_id (get carrier for location)
5201     --                  object1 type = SUP and object1 id = supplier_id (get supplier for location)
5202     -- Return success
5203 
5204     IF p_object2_val_num IS NOT NULL OR p_object2_val_char IS NOT NULL THEN
5205 
5206     -- Need a data structure for hashing constraints
5207     -- hash by class+obj1 type+obj1+obj1 parent+obj2 type+obj2+obj2 parent
5208     -- As this combination defines a unique key
5209 
5210         l1_hash_string :=        (l_comp_class_id)||'-'||l_object1_typesub||'-'||       (p_object1_val_num)||'-'||       (nvl(l_object1_parent_id,-9999))||
5211         '-'||l_object2_typesub||'-'||nvl(       to_char(p_object2_val_num),p_object2_val_char)||'-'||       (-9999);
5212 
5213         l1_hash_value := dbms_utility.get_hash_value(
5214                                   name => l1_hash_string,
5215                                   base => g_hash_base,
5216                                   hash_size =>g_hash_size );
5217         --
5218         IF l_debug_on THEN
5219            WSH_DEBUG_SV.logmsg(l_module_name,'l1_hash_string : '||l1_hash_string);
5220            WSH_DEBUG_SV.logmsg(l_module_name,'l1_hash_value : '||l1_hash_value);
5221         END IF;
5222         --
5223 
5224 
5225         IF check_cache(l1_hash_value,l1_hash_string) THEN
5226 
5227           IF g_comp_constraint_tab(l1_hash_value).constraint_type = 'I' THEN
5228 
5229               x_validate_result := 'S';
5230               --
5231               IF l_debug_on THEN
5232                  WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
5233                  WSH_DEBUG_SV.pop(l_module_name);
5234               END IF;
5235               --
5236               RETURN;
5237 
5238           END IF;
5239 
5240         END IF;
5241     END IF; -- object2 NOT NULL
5242 
5243     IF l_object1_typesub = 'FAC' THEN
5244 
5245       get_carrier_from_loc(
5246                    p_location_id    =>  p_object1_val_num,
5247                    x_carrier_id     =>  l_carrier_id,
5248                    x_return_status  =>  l_return_status);
5249 
5250       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
5251          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5252          IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
5253             raise FND_API.G_EXC_UNEXPECTED_ERROR;
5254          END IF;
5255             raise g_get_carrier_failed;
5256          END IF;
5257       END IF;
5258 
5259       IF p_object2_val_num IS NOT NULL OR p_object2_val_char IS NOT NULL THEN
5260         -- For phase I, not doing fac as org - car/mode
5261 
5262         IF l_carrier_id IS NOT NULL THEN
5263 
5264            l2_hash_string :=        (l_comp_class_id)||'-'||'CAR'||'-'||       (l_carrier_id)||'-'||       (-9999)||
5265            '-'||l_object2_typesub||'-'||nvl(       to_char(p_object2_val_num),p_object2_val_char)||'-'||       (-9999);
5266 
5267            l2_hash_value := dbms_utility.get_hash_value(
5268                                   name => l2_hash_string,
5269                                   base => g_hash_base,
5270                                   hash_size =>g_hash_size );
5271            --
5272            IF l_debug_on THEN
5273               WSH_DEBUG_SV.logmsg(l_module_name,'l2_hash_string : '||l2_hash_string);
5274               WSH_DEBUG_SV.logmsg(l_module_name,'l2_hash_value : '||l2_hash_value);
5275            END IF;
5276            --
5277 
5278 
5279            IF check_cache(l2_hash_value,l2_hash_string) THEN
5280 
5281               IF g_comp_constraint_tab(l2_hash_value).constraint_type = 'I' THEN
5282 
5283                  x_validate_result := 'S';
5284                  --
5285                  IF l_debug_on THEN
5286                     WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
5287                     WSH_DEBUG_SV.pop(l_module_name);
5288                  END IF;
5289                  --
5290                  RETURN;
5291 
5292               END IF;
5293 
5294            END IF;
5295         END IF; -- l_carrier_id
5296       END IF; -- object2 NOT NULL
5297 
5298       --get_customer_from_loc(
5299       WSH_UTIL_CORE.get_customer_from_loc(
5300                    p_location_id    =>  p_object1_val_num,
5301                    --x_customer_id    =>  l_customer_id,
5302                    x_customer_id_tab    =>  l_customer_id_tab,
5303                    x_return_status  =>  l_return_status);
5304 
5305       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
5306          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5307          IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
5308             raise FND_API.G_EXC_UNEXPECTED_ERROR;
5309          END IF;
5310             raise g_get_customer_failed;
5311          END IF;
5312       END IF;
5313 
5314        itr := l_customer_id_tab.FIRST;
5315        IF itr IS NOT NULL THEN
5316         LOOP
5317 
5318             IF p_object2_val_num IS NOT NULL OR p_object2_val_char IS NOT NULL THEN
5319             --IF l_customer_id IS NOT NULL THEN
5320                 IF l_customer_id_tab(itr) IS NOT NULL THEN
5321 
5322                     l3_hash_string :=        (l_comp_class_id)||'-'||'CUS'||'-'||       (l_customer_id_tab(itr))||'-'||       (-9999)||
5323                     '-'||l_object2_typesub||'-'||nvl(       to_char(p_object2_val_num),p_object2_val_char)||'-'||       (-9999);
5324 
5325                     l3_hash_value := dbms_utility.get_hash_value(
5326                     name => l3_hash_string,
5327                     base => g_hash_base,
5328                     hash_size =>g_hash_size );
5329                     --
5330                     IF l_debug_on THEN
5331                         WSH_DEBUG_SV.logmsg(l_module_name,'l3_hash_string : '||l3_hash_string);
5332                         WSH_DEBUG_SV.logmsg(l_module_name,'l3_hash_value : '||l3_hash_value);
5333                     END IF;
5334                     --
5335 
5336 
5337                     IF check_cache(l3_hash_value,l3_hash_string) THEN
5338 
5339                         IF g_comp_constraint_tab(l3_hash_value).constraint_type = 'I' THEN
5340 
5341                             x_validate_result := 'S';
5342                             --
5343                             IF l_debug_on THEN
5344                                 WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
5345                                 WSH_DEBUG_SV.pop(l_module_name);
5346                             END IF;
5347                             --
5348                             RETURN;
5349 
5350                         END IF;
5351 
5352                     END IF;
5353 
5354                 END IF; -- object2 NOT NULL
5355             END IF; -- object2 NOT NULL
5356             EXIT WHEN itr = l_customer_id_tab.LAST;
5357             itr := l_customer_id_tab.NEXT(itr);
5358 
5359         END LOOP;
5360 
5361        END IF; -- l_customer_id
5362 
5363       get_supplier_from_loc(
5364                    p_location_id    =>  p_object1_val_num,
5365                    x_supplier_id     =>  l_supplier_id,
5366                    x_return_status  =>  l_return_status);
5367 
5368       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
5369          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5370          IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
5371             raise FND_API.G_EXC_UNEXPECTED_ERROR;
5372          END IF;
5373             raise g_get_supplier_failed;
5374          END IF;
5375       END IF;
5376 
5377       IF p_object2_val_num IS NOT NULL OR p_object2_val_char IS NOT NULL THEN
5378         -- For phase I, not doing fac as org - car/mode
5379 
5380        IF l_supplier_id IS NOT NULL THEN
5381 
5382         l4_hash_string :=        (l_comp_class_id)||'-'||'SUP'||'-'||       (l_supplier_id)||'-'||       (-9999)||
5383     '-'||l_object2_typesub||'-'||nvl(       to_char(p_object2_val_num),p_object2_val_char)||'-'||       (-9999);
5384 
5385         l4_hash_value := dbms_utility.get_hash_value(
5386                                   name => l4_hash_string,
5387                                   base => g_hash_base,
5388                                   hash_size =>g_hash_size );
5389         --
5390         IF l_debug_on THEN
5391           WSH_DEBUG_SV.logmsg(l_module_name,'l4_hash_string : '||l4_hash_string);
5392           WSH_DEBUG_SV.logmsg(l_module_name,'l4_hash_value : '||l4_hash_value);
5393         END IF;
5394         --
5395 
5396 
5397         IF check_cache(l4_hash_value,l4_hash_string) THEN
5398 
5399           IF g_comp_constraint_tab(l4_hash_value).constraint_type = 'I' THEN
5400 
5401              x_validate_result := 'S';
5402              --
5403              IF l_debug_on THEN
5404                WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
5405                WSH_DEBUG_SV.pop(l_module_name);
5406              END IF;
5407              --
5408              RETURN;
5409 
5410           END IF;
5411 
5412         END IF;
5413        END IF; -- l_supplier_id
5414       END IF; -- object2 NOT NULL
5415 
5416         -- For phase I, not doing fac as org - car/mode
5417 
5418     END IF;  -- FAC
5419 
5420     --
5421     IF l_debug_on THEN
5422       WSH_DEBUG_SV.logmsg(l_module_name,' x_validate_result before checking constraints cache : '||x_validate_result||' g_comp_constraint_tab count :' ||g_comp_constraint_tab.COUNT||' l_comp_class_id : '||l_comp_class_id);
5423     END IF;
5424     --
5425 
5426     IF x_validate_result = 'F' THEN
5427       -- LOOP over g_comp_constraint_tab
5428       l := failed_cons_last;
5429       k := g_comp_constraint_tab.FIRST;
5430       IF k IS NOT NULL THEN
5431        LOOP
5432 
5433 
5434         IF g_comp_constraint_tab(k).compatibility_class_id = l_comp_class_id AND
5435            ((g_comp_constraint_tab(k).CONSTRAINT_OBJECT1_TYPE = l_object1_typesub AND
5436            nvl(g_comp_constraint_tab(k).OBJECT1_SOURCE_ID,-9999) = nvl(l_object1_parent_id,-9999) AND
5437            g_comp_constraint_tab(k).CONSTRAINT_OBJECT1_ID = p_object1_val_num) OR
5438            (l_object1_typesub = 'FAC' AND
5439             l_carrier_id IS NOT NULL AND
5440             g_comp_constraint_tab(k).CONSTRAINT_OBJECT1_TYPE = 'CAR' AND
5441             g_comp_constraint_tab(k).CONSTRAINT_OBJECT1_ID = l_carrier_id) OR
5442            (l_object1_typesub = 'FAC' AND
5443             l_supplier_id IS NOT NULL AND
5444             g_comp_constraint_tab(k).CONSTRAINT_OBJECT1_TYPE = 'SUP' AND
5445             g_comp_constraint_tab(k).CONSTRAINT_OBJECT1_ID = l_supplier_id) OR
5446            (l_object1_typesub = 'FAC' AND
5447             l_customer_id IS NOT NULL AND
5448             g_comp_constraint_tab(k).CONSTRAINT_OBJECT1_TYPE = 'CUS' AND
5449             g_comp_constraint_tab(k).CONSTRAINT_OBJECT1_ID = l_customer_id)) THEN
5450            --
5451            IF l_debug_on THEN
5452               WSH_DEBUG_SV.logmsg(l_module_name,' Input has constraint : '||g_comp_constraint_tab(k).compatibility_id);
5453            END IF;
5454            --
5455 
5456            IF g_comp_constraint_tab(k).constraint_type = 'I' THEN
5457 
5458            -- Add to the x_failed_constraint
5459              l := l + 1;
5460              x_failed_constraint(l).constraint_id := g_comp_constraint_tab(k).compatibility_id;
5461              x_failed_constraint(l).entity_type := p_entity_type;
5462              x_failed_constraint(l).entity_line_id := p_entity_id;
5463              x_failed_constraint(l).constraint_class_code := p_comp_class_code;
5464              x_failed_constraint(l).violation_type := l_compclass_severity;
5465 
5466              --
5467              IF l_debug_on THEN
5468                 WSH_DEBUG_SV.logmsg(l_module_name,' x_out_object2_num : '||x_out_object2_num||' x_out_object2_char : '||x_out_object2_char);
5469              END IF;
5470              --
5471 
5472              IF (( x_out_object2_num IS NOT NULL OR x_out_object2_char IS NOT NULL) AND
5473                  ( g_comp_constraint_tab(k).constraint_object1_type <> 'FAC')) OR
5474                 (x_out_object2_num IS NULL AND x_out_object2_char IS NULL) THEN
5475              -- Company level must use overrides facility level must use if both defined
5476 
5477              x_out_object2_num  := g_comp_constraint_tab(k).constraint_object2_id;
5478              x_out_object2_char := g_comp_constraint_tab(k).constraint_object2_value_char;
5479 
5480              END IF;
5481 
5482              IF l_compclass_severity = 'E' THEN
5483                 l_incl_cons := TRUE;
5484              END IF;
5485 
5486            END IF;
5487         END IF;
5488 
5489         EXIT WHEN k=g_comp_constraint_tab.LAST;
5490         k := g_comp_constraint_tab.NEXT(k);
5491 
5492        END LOOP;
5493       END IF;
5494 
5495       IF NOT l_incl_cons THEN
5496 
5497            x_validate_result := 'S';
5498 
5499       END IF;
5500 
5501     END IF;
5502 
5503     --
5504     IF l_debug_on THEN
5505       WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
5506       WSH_DEBUG_SV.logmsg(l_module_name,' x_out_object2_num : '||x_out_object2_num);
5507       WSH_DEBUG_SV.logmsg(l_module_name,' x_out_object2_char : '||x_out_object2_char);
5508       WSH_DEBUG_SV.pop(l_module_name);
5509     END IF;
5510     --
5511 
5512 EXCEPTION
5513     WHEN g_get_carrier_failed THEN
5514       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
5515       --
5516       IF l_debug_on THEN
5517         WSH_DEBUG_SV.pop(l_module_name,' get_carrier failed ');
5518       END IF;
5519       --
5520     WHEN g_get_customer_failed THEN
5521       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
5522       --
5523       IF l_debug_on THEN
5524         WSH_DEBUG_SV.pop(l_module_name,' get_customer failed ');
5525       END IF;
5526       --
5527     WHEN g_get_supplier_failed THEN
5528       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
5529       --
5530       IF l_debug_on THEN
5531         WSH_DEBUG_SV.pop(l_module_name,' get_supplier failed ');
5532       END IF;
5533       --
5534     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5535       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
5536       --
5537       IF l_debug_on THEN
5538         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
5539         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
5540       END IF;
5541       --
5542     WHEN others THEN
5543       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.check_inclusive_object2');
5544       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
5545       --
5546       IF l_debug_on THEN
5547         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
5548         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
5549       END IF;
5550       --
5551 END check_inclusive_object2;
5552 
5553 --***************************************************************************--
5554 
5555 --========================================================================
5556 -- PROCEDURE : search_itm_fac_incl        PRIVATE
5557 --
5558 -- PARAMETERS: p_comp_class_tab           Table of Compatibility class codes to check
5559 --             p_items_tab                Table of item ids to validate
5560 --             p_entity_type              Entity for which check is running
5561 --             p_entity_id                Entity id for which check is running
5562 --             p_locations_list           Table of location ids to be checked
5563 --             x_validate_result          Constraint Validation result : S / E / W
5564 --             x_failed_constraints       Failed constraint table
5565 --             x_return_status            Return status
5566 -- COMMENT   :
5567 -- Checks whether all input items
5568 -- have same/different must use carrier/mode/vehicle
5569 -- compared to the list of input location id s
5570 -- If different, violation
5571 --========================================================================
5572 
5573 PROCEDURE search_itm_fac_incl (
5574               p_comp_class_tab      IN  WSH_UTIL_CORE.Column_Tab_Type,
5575               p_items_tab           IN  item_tab_type,
5576               p_entity_type         IN  VARCHAR2,
5577               p_entity_id           IN  NUMBER,
5578               p_locations_list      IN  WSH_UTIL_CORE.id_tab_type,
5579               x_validate_result     OUT NOCOPY    VARCHAR2,
5580               x_failed_constraints  IN OUT NOCOPY line_constraint_tab_type,
5581               x_return_status       OUT NOCOPY    VARCHAR2 )
5582 IS
5583 
5584       l_return_status             VARCHAR2(1) := 'S';
5585       l_const_count               NUMBER := x_failed_constraints.COUNT;
5586       l_validate_result           VARCHAR2(1) := 'S';
5587       l_validate_carrier_result   VARCHAR2(1) := 'S';
5588       l_validate_vehicle_result   VARCHAR2(1) := 'S';
5589       l_validate_mode_result      VARCHAR2(1) := 'S';
5590       l_validate_itmcar_result    VARCHAR2(1) := 'S';
5591       l_validate_itmveh_result    VARCHAR2(1) := 'S';
5592       l_validate_itmmode_result   VARCHAR2(1) := 'S';
5593       l_out_object2_vehnum        NUMBER := NULL;
5594       l_out_object2_num           NUMBER := NULL;
5595       l_out_object2_dummy_num     NUMBER := NULL;
5596       l_out_object2_char          VARCHAR2(30) := NULL;
5597       l_out_object2_dummy_char    VARCHAR2(30) := NULL;
5598       l_out_object2_itm_num       NUMBER := NULL;
5599       l_out_object2_itm_char      VARCHAR2(30) := NULL;
5600       i                           NUMBER :=  0;
5601       j                           NUMBER :=  0;
5602       l_item_org_id               NUMBER := null;
5603       l_hash_string               VARCHAR2(200);
5604       l_hash_value                NUMBER:=0;
5605       l_fac_hash_string           VARCHAR2(200);
5606 
5607       l_module_name               CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'search_itm_fac_incl';
5608       l_debug_on                  CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
5609 
5610 BEGIN
5611 
5612       x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
5613       x_validate_result := 'S';
5614 
5615       IF l_debug_on THEN
5616          wsh_debug_sv.push(l_module_name);
5617       END IF;
5618 
5619       IF g_is_tp_installed IS NULL THEN
5620          g_is_tp_installed := WSH_UTIL_CORE.TP_Is_Installed;
5621       END IF;
5622 
5623       i := p_locations_list.FIRST;
5624       IF i IS NOT NULL THEN
5625         LOOP
5626 
5627           l_validate_result := 'S';
5628           l_validate_carrier_result := 'S';
5629           l_validate_vehicle_result := 'S';
5630           l_validate_mode_result := 'S';
5631           l_validate_itmcar_result := 'S';
5632           l_validate_itmveh_result := 'S';
5633           l_validate_itmmode_result := 'S';
5634           l_out_object2_num := NULL;
5635           l_out_object2_vehnum := NULL;
5636           l_out_object2_char := NULL;
5637           l_out_object2_itm_num := NULL;
5638           l_out_object2_itm_char := NULL;
5639 
5640           l_fac_hash_string := p_locations_list(i)||'-';
5641 
5642           IF l_debug_on THEN
5643              WSH_DEBUG_SV.logmsg(l_module_name,'i : '||i||' p_locations_list(i) : '||p_locations_list(i));
5644           END IF;
5645 
5646           IF p_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) THEN
5647 
5648              check_inclusive_object2(
5649                  p_comp_class_code          =>      G_FACILITY_CARRIER,
5650                  p_entity_type              =>      p_entity_type,
5651                  p_entity_id                =>      p_entity_id,
5652                  p_object1_type             =>      'FAC',
5653                  p_object1_val_num          =>      p_locations_list(i),
5654                  p_object2_type             =>      'CAR',
5655                  x_out_object2_num          =>      l_out_object2_num,
5656                  x_out_object2_char         =>      l_out_object2_dummy_char,
5657                  x_validate_result          =>      l_validate_carrier_result,
5658                  x_failed_constraint        =>      x_failed_constraints,
5659                  x_return_status            =>      l_return_status);
5660 
5661              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
5662                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5663                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
5664                 END IF;
5665              END IF;
5666 
5667             IF l_debug_on THEN
5668                 WSH_DEBUG_SV.logmsg(l_module_name,'l_validate_carrier_result : '||l_validate_carrier_result);
5669             END IF;
5670 
5671           END IF;
5672 
5673 
5674 
5675           IF p_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) THEN
5676 
5677              check_inclusive_object2(
5678                  p_comp_class_code          =>      G_FACILITY_MODE,
5679                  p_entity_type              =>      p_entity_type,
5680                  p_entity_id                =>      p_entity_id,
5681                  p_object1_type             =>      'FAC',
5682                  p_object1_val_num          =>      p_locations_list(i),
5683                  p_object2_type             =>      'MOD',
5684                  x_out_object2_num          =>      l_out_object2_dummy_num,
5685                  x_out_object2_char         =>      l_out_object2_char,
5686                  x_validate_result          =>      l_validate_mode_result,
5687                  x_failed_constraint        =>      x_failed_constraints,
5688                  x_return_status            =>      l_return_status);
5689 
5690              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
5691                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5692                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
5693                 END IF;
5694              END IF;
5695 
5696              IF l_debug_on THEN
5697                 WSH_DEBUG_SV.logmsg(l_module_name,'l_validate_mode_result : '||l_validate_mode_result);
5698              END IF;
5699 
5700           END IF;
5701 
5702           IF p_comp_class_tab.EXISTS(G_FACILITY_VEHICLE_NUM) THEN
5703 
5704              check_inclusive_object2(
5705                  p_comp_class_code          =>      G_FACILITY_VEHICLE,
5706                  p_entity_type              =>      p_entity_type,
5707                  p_entity_id                =>      p_entity_id,
5708                  p_object1_type             =>      'FAC',
5709                  p_object1_val_num          =>      p_locations_list(i),
5710                  p_object2_type             =>      'VHT',
5711                  x_out_object2_num          =>      l_out_object2_vehnum,
5712                  x_out_object2_char         =>      l_out_object2_dummy_char,
5713                  x_validate_result          =>      l_validate_vehicle_result,
5714                  x_failed_constraint        =>      x_failed_constraints,
5715                  x_return_status            =>      l_return_status);
5716 
5717              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
5718                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5719                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
5720                 END IF;
5721              END IF;
5722 
5723              IF l_debug_on THEN
5724                 WSH_DEBUG_SV.logmsg(l_module_name,'l_validate_vehicle_result : '||l_validate_vehicle_result);
5725              END IF;
5726 
5727           END IF;
5728 
5729           IF l_validate_carrier_result = 'F' OR l_validate_mode_result = 'F'
5730              OR l_validate_vehicle_result = 'F' THEN
5731              IF l_debug_on THEN
5732                 WSH_DEBUG_SV.logmsg(l_module_name,' p_items_tab COUNT : '||p_items_tab.COUNT);
5733              END IF;
5734 
5735             j := p_items_tab.FIRST;
5736             IF j IS NOT NULL THEN
5737               LOOP
5738 
5739                 -- Performance bug 3432495
5740                 -- form unique combination of
5741                 -- locationid-item-org and mark for each combination
5742                 -- whether carrier/mode/vehicle check is successful
5743 
5744                 -- Any subsequent combination will be checked against that
5745                 -- list of unique combinations first
5746                 -- and if not found, then only proceed to call the
5747                 -- following API s which will end up adding that
5748                 -- combination to this list
5749 
5750                 IF l_debug_on THEN
5751                        WSH_DEBUG_SV.logmsg(l_module_name,'p_items_tab(j).item_id : '||p_items_tab(j).item_id||'p_items_tab(j).org_id : '||p_items_tab(j).org_id);
5752                 END IF;
5753 
5754                 --IF WSH_UTIL_CORE.TP_Is_Installed = 'N' THEN
5755                 IF g_is_tp_installed = 'N' THEN
5756                    l_item_org_id := p_items_tab(j).org_id;
5757                 END IF;
5758 
5759                 l_hash_string := l_fac_hash_string || p_items_tab(j).item_id||'-'||nvl(l_item_org_id,-9999);
5760 
5761                 l_hash_value := dbms_utility.get_hash_value(
5762                                     name => l_hash_string,
5763                                     base => g_hash_base,
5764                                     hash_size =>g_hash_size );
5765 
5766                 -- Hash collision
5767 
5768                 IF g_itmloc_mustuse_cache.EXISTS(l_hash_value) AND
5769                     g_itmloc_mustuse_cache(l_hash_value).hash_string = l_hash_string THEN
5770                     IF l_debug_on THEN
5771                        WSH_DEBUG_SV.logmsg(l_module_name,'g_itmloc_mustuse_cache has record with hash value : '||l_hash_value);
5772                        WSH_DEBUG_SV.logmsg(l_module_name,'g_itmloc_mustuse_cache carrier result : '||g_itmloc_mustuse_cache(l_hash_value).carrier_result);
5773                        WSH_DEBUG_SV.logmsg(l_module_name,'g_itmloc_mustuse_cache mode result : '||g_itmloc_mustuse_cache(l_hash_value).mode_result);
5774                        WSH_DEBUG_SV.logmsg(l_module_name,'g_itmloc_mustuse_cache vehicle result : '||g_itmloc_mustuse_cache(l_hash_value).vehicle_result);
5775                     END IF;
5776 
5777                    IF g_itmloc_mustuse_cache(l_hash_value).carrier_result = 'F' OR
5778                       g_itmloc_mustuse_cache(l_hash_value).mode_result = 'F' OR
5779                       g_itmloc_mustuse_cache(l_hash_value).vehicle_result = 'F' THEN
5780                         IF l_debug_on THEN
5781                            WSH_DEBUG_SV.logmsg(l_module_name,'g_itmloc_mustuse_cache record has failure ');
5782                         END IF;
5783                         l_validate_result := 'F';
5784                         EXIT;
5785                    END IF;
5786 
5787                 ELSE
5788 
5789                 -- populate g_itmloc_mustuse_cache
5790 
5791                 g_itmloc_mustuse_cache(l_hash_value).target_location_id := p_locations_list(i);
5792                 g_itmloc_mustuse_cache(l_hash_value).input_item_id := p_items_tab(j).item_id;
5793                 g_itmloc_mustuse_cache(l_hash_value).input_itemorg_id := l_item_org_id;
5794                 g_itmloc_mustuse_cache(l_hash_value).hash_string := l_hash_string;
5795                 g_itmloc_mustuse_cache(l_hash_value).carrier_result := 'S';
5796                 g_itmloc_mustuse_cache(l_hash_value).mode_result := 'S';
5797                 g_itmloc_mustuse_cache(l_hash_value).vehicle_result := 'S';
5798                 IF l_debug_on THEN
5799                      WSH_DEBUG_SV.logmsg(l_module_name,'g_itmloc_mustuse_cache record created with hash value : '||l_hash_value);
5800                 END IF;
5801 
5802                 IF p_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) AND l_validate_carrier_result = 'F' THEN
5803 
5804                   check_inclusive_object2(
5805                        p_comp_class_code          =>      G_ITEM_CARRIER,
5806                        p_entity_type              =>      G_DEL_DETAIL,
5807                        p_entity_id                =>      p_items_tab(j).line_id,
5808                        p_object1_type             =>      'ITM',
5809                        p_object1_val_num          =>      p_items_tab(j).item_id,
5810                        p_object1_parent_id        =>      p_items_tab(j).org_id,
5811                        p_object2_type             =>      'CAR',
5812                        x_out_object2_num          =>      l_out_object2_itm_num,
5813                        x_out_object2_char         =>      l_out_object2_itm_char,
5814                        x_validate_result          =>      l_validate_itmcar_result,
5815                        x_failed_constraint        =>      x_failed_constraints,
5816                        x_return_status            =>      l_return_status);
5817 
5818                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
5819                      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5820                         raise FND_API.G_EXC_UNEXPECTED_ERROR;
5821                      END IF;
5822                   END IF;
5823 
5824                   IF l_validate_itmcar_result = 'F' AND
5825                      l_out_object2_itm_num <> l_out_object2_num THEN
5826                      l_validate_result := 'F';
5827                      g_itmloc_mustuse_cache(l_hash_value).carrier_result := 'F';
5828                      --EXIT;
5829                   END IF;
5830 
5831                 END IF;
5832 
5833                 IF p_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) AND l_validate_mode_result = 'F' THEN
5834 
5835                   check_inclusive_object2(
5836                        p_comp_class_code          =>      G_ITEM_MODE,
5837                        p_entity_type              =>      G_DEL_DETAIL,
5838                        p_entity_id                =>      p_items_tab(j).line_id,
5839                        p_object1_type             =>      'ITM',
5840                        p_object1_val_num          =>      p_items_tab(j).item_id,
5841                        p_object1_parent_id        =>      p_items_tab(j).org_id,
5842                        p_object2_type             =>      'MOD',
5843                        x_out_object2_num          =>      l_out_object2_itm_num,
5844                        x_out_object2_char         =>      l_out_object2_itm_char,
5845                        x_validate_result          =>      l_validate_itmmode_result,
5846                        x_failed_constraint        =>      x_failed_constraints,
5847                        x_return_status            =>      l_return_status);
5848 
5849                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
5850                      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5851                         raise FND_API.G_EXC_UNEXPECTED_ERROR;
5852                      END IF;
5853                   END IF;
5854 
5855                   IF l_validate_itmmode_result = 'F' AND
5856                      l_out_object2_itm_char <> l_out_object2_char THEN
5857                      l_validate_result := 'F';
5858                      g_itmloc_mustuse_cache(l_hash_value).mode_result := 'F';
5859                      --EXIT;
5860                   END IF;
5861 
5862                 END IF;
5863 
5864                 IF p_comp_class_tab.EXISTS(G_ITEM_VEHICLE_NUM) AND l_validate_vehicle_result = 'F' THEN
5865 
5866                   check_inclusive_object2(
5867                        p_comp_class_code          =>      G_ITEM_VEHICLE,
5868                        p_entity_type              =>      G_DEL_DETAIL,
5869                        p_entity_id                =>      p_items_tab(j).line_id,
5870                        p_object1_type             =>      'ITM',
5871                        p_object1_val_num          =>      p_items_tab(j).item_id,
5872                        p_object1_parent_id        =>      p_items_tab(j).org_id,
5873                        p_object2_type             =>      'VHT',
5874                        x_out_object2_num          =>      l_out_object2_itm_num,
5875                        x_out_object2_char         =>      l_out_object2_itm_char,
5876                        x_validate_result          =>      l_validate_itmveh_result,
5877                        x_failed_constraint        =>      x_failed_constraints,
5878                        x_return_status            =>      l_return_status);
5879 
5880                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
5881                      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
5882                         raise FND_API.G_EXC_UNEXPECTED_ERROR;
5883                      END IF;
5884                   END IF;
5885 
5886                   IF l_validate_itmveh_result = 'F' AND
5887                      l_out_object2_itm_num <> l_out_object2_vehnum THEN
5888                      l_validate_result := 'F';
5889                      g_itmloc_mustuse_cache(l_hash_value).vehicle_result := 'F';
5890                      --EXIT;
5891                   END IF;
5892 
5893                 END IF;
5894 
5895                 --END IF; -- Facility check result
5896 
5897                 END IF; -- ELSE of hash found
5898 
5899                 IF l_debug_on THEN
5900                        WSH_DEBUG_SV.logmsg(l_module_name,'g_itmloc_mustuse_cache carrier result : '||g_itmloc_mustuse_cache(l_hash_value).carrier_result);
5901                        WSH_DEBUG_SV.logmsg(l_module_name,'g_itmloc_mustuse_cache mode result : '||g_itmloc_mustuse_cache(l_hash_value).mode_result);
5902                        WSH_DEBUG_SV.logmsg(l_module_name,'g_itmloc_mustuse_cache vehicle result : '||g_itmloc_mustuse_cache(l_hash_value).vehicle_result);
5903                 END IF;
5904 
5905                 EXIT WHEN j = p_items_tab.LAST;
5906                 j := p_items_tab.NEXT(j);
5907 
5908               END LOOP;
5909             END IF;
5910             END IF; -- Facility check result
5911 
5912           IF l_validate_result = 'F' THEN
5913              x_validate_result := 'F';
5914              EXIT;
5915           END IF;
5916 
5917           EXIT WHEN i = p_locations_list.LAST;
5918           i := p_locations_list.NEXT(i);
5919 
5920         END LOOP;
5921       END IF;
5922 
5923       IF ( l_const_count < x_failed_constraints.COUNT) AND
5924          x_validate_result <> 'F' THEN
5925 
5926          x_failed_constraints.DELETE(l_const_count+1,x_failed_constraints.COUNT);
5927 
5928       END IF;
5929 
5930       --
5931       IF l_debug_on THEN
5932         WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
5933         WSH_DEBUG_SV.pop(l_module_name);
5934       END IF;
5935       --
5936 
5937 EXCEPTION
5938     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
5939       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
5940       --
5941       IF l_debug_on THEN
5942         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
5943         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
5944       END IF;
5945       --
5946     WHEN others THEN
5947          WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.search_itm_fac_incl');
5948          x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
5949       --
5950       IF l_debug_on THEN
5951         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
5952         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
5953       END IF;
5954       --
5955 
5956 END search_itm_fac_incl;
5957 
5958 --***************************************************************************--
5959 
5960 --========================================================================
5961 -- PROCEDURE : search_group_itm           PRIVATE
5962 --
5963 -- PARAMETERS: p_comp_class_tab           Table of Compatibility class codes to check
5964 --             p_entity_rec               Table of item ids to validate
5965 --             p_target_rec               Table of item ids to validate
5966 --             x_validate_result          Constraint Validation result : S / E / W
5967 --             x_failed_constraints       failed constraint table in case of failure, null if success
5968 --             x_return_status            Return status
5969 -- COMMENT   :
5970 -- Checks whether input item in p_entity_rec
5971 -- have same/different must use carrier/mode/vehicle
5972 -- compared to the input item in p_target_rec
5973 -- If different, violation
5974 --========================================================================
5975 
5976 PROCEDURE search_group_itm (
5977               p_comp_class_tab      IN   WSH_UTIL_CORE.Column_Tab_Type,
5978               p_entity_rec          IN   entity_rec_type,
5979               p_target_rec          IN   entity_rec_type,
5980               x_validate_result     OUT NOCOPY      VARCHAR2,
5981               x_failed_constraints  IN OUT NOCOPY   line_constraint_tab_type,
5982               x_return_status       OUT NOCOPY      VARCHAR2 )
5983 IS
5984 
5985     l_return_status             VARCHAR2(1);
5986     l_const_count               NUMBER := x_failed_constraints.COUNT;
5987     i                           NUMBER := 0;
5988     l_entity_id                 NUMBER := 0;
5989     l_item_id                   NUMBER := 0;
5990     l_org_id                    NUMBER := 0;
5991     l_validate_carrier_result   VARCHAR2(1) := 'S';
5992     l_validate_vehicle_result   VARCHAR2(1) := 'S';
5993     l_validate_mode_result      VARCHAR2(1) := 'S';
5994     l_out_object2_vehnum        NUMBER := NULL;
5995     l_out_object2_num           NUMBER := NULL;
5996     l_out_object2_char          VARCHAR2(30) := NULL;
5997     l_prev_out_object2_vehnum   NUMBER := NULL;
5998     l_prev_out_object2_num      NUMBER := NULL;
5999     l_prev_out_object2_char     VARCHAR2(30) := NULL;
6000 
6001     l_input_item_org_id         NUMBER := null;
6002     l_target_item_org_id        NUMBER := null;
6003     l_hash_string               VARCHAR2(200);
6004     l_hash_value                NUMBER:=0;
6005 
6006     l_module_name               CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'search_group_itm';
6007     l_debug_on                  CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
6008 
6009 BEGIN
6010 
6011     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
6012     x_validate_result := 'S';
6013 
6014     IF l_debug_on THEN
6015        wsh_debug_sv.push(l_module_name);
6016     END IF;
6017 
6018     IF g_is_tp_installed IS NULL THEN
6019          g_is_tp_installed := WSH_UTIL_CORE.TP_Is_Installed;
6020     END IF;
6021 
6022     IF p_entity_rec.inventory_item_id = p_target_rec.inventory_item_id THEN
6023        IF g_is_tp_installed = 'Y' OR
6024           p_entity_rec.organization_id = p_target_rec.organization_id THEN
6025           IF l_debug_on THEN
6026             WSH_DEBUG_SV.logmsg(l_module_name,'Returning without check as input and target items are the same');
6027             WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
6028             WSH_DEBUG_SV.pop(l_module_name);
6029           END IF;
6030           return;
6031        END IF;
6032 
6033     ELSE
6034        IF l_debug_on THEN
6035           WSH_DEBUG_SV.logmsg(l_module_name,'p_entity_rec.inventory_item_id : '||p_entity_rec.inventory_item_id);
6036           WSH_DEBUG_SV.logmsg(l_module_name,'p_entity_rec.organization_id : '||p_entity_rec.organization_id);
6037           WSH_DEBUG_SV.logmsg(l_module_name,'p_target_rec.inventory_item_id : '||p_target_rec.inventory_item_id);
6038           WSH_DEBUG_SV.logmsg(l_module_name,'p_target_rec.organization_id : '||p_target_rec.organization_id);
6039        END IF;
6040 
6041     END IF;
6042 
6043     -- Performance bug 3432495
6044     -- proceed forward only for each unique combination of
6045     -- entityitem-entityorg-targetitem-targetorg
6046     -- for each unique combination also record whether carrier/mode/vehicle
6047     -- is failure or successful
6048 
6049     -- For all subsequent combinations, the result used
6050     -- will be as found for the first combination
6051 
6052     IF g_is_tp_installed = 'N' THEN
6053        l_input_item_org_id := p_entity_rec.organization_id;
6054        l_target_item_org_id := p_target_rec.organization_id;
6055     END IF;
6056 
6057     l_hash_string := p_entity_rec.inventory_item_id||'-'||nvl(l_input_item_org_id,-9999)||'-';
6058     l_hash_string := l_hash_string || p_target_rec.inventory_item_id||'-'||nvl(l_target_item_org_id,-9999);
6059 
6060     l_hash_value := dbms_utility.get_hash_value(
6061                                     name => l_hash_string,
6062                                     base => g_hash_base,
6063                                     hash_size =>g_hash_size );
6064 
6065     IF g_itm_mustuse_cache.EXISTS(l_hash_value) AND
6066          g_itm_mustuse_cache(l_hash_value).hash_string = l_hash_string THEN
6067 
6068       IF l_debug_on THEN
6069           WSH_DEBUG_SV.logmsg(l_module_name,'Found g_itm_mustuse_cache record with hash value : '||l_hash_value);
6070       END IF;
6071       IF g_itm_mustuse_cache(l_hash_value).carrier_result = 'F'
6072 OR
6073          g_itm_mustuse_cache(l_hash_value).mode_result = 'F' OR
6074          g_itm_mustuse_cache(l_hash_value).vehicle_result = 'F' THEN
6075 
6076          x_validate_result := 'F';
6077          IF l_debug_on THEN
6078             WSH_DEBUG_SV.logmsg(l_module_name,'g_itm_mustuse_cache record has failure ');
6079          END IF;
6080       END IF;
6081       IF l_debug_on THEN
6082           WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
6083           WSH_DEBUG_SV.pop(l_module_name);
6084       END IF;
6085       return;
6086 
6087     ELSE
6088 
6089     FOR i IN 1..2 LOOP
6090 
6091       IF i = 1 THEN
6092          l_entity_id := p_entity_rec.entity_id;
6093          l_item_id := p_entity_rec.inventory_item_id;
6094          l_org_id := p_entity_rec.organization_id;
6095 
6096       ELSIF i = 2 THEN
6097          l_entity_id := p_target_rec.entity_id;
6098          l_item_id := p_target_rec.inventory_item_id;
6099          l_org_id := p_target_rec.organization_id;
6100 
6101       END IF;
6102 
6103       IF i = 2 THEN
6104       -- populate g_itm_mustuse_cache
6105       g_itm_mustuse_cache(l_hash_value).input_item_id := p_entity_rec.inventory_item_id;
6106       g_itm_mustuse_cache(l_hash_value).input_itemorg_id := l_input_item_org_id;
6107       g_itm_mustuse_cache(l_hash_value).target_item_id := p_target_rec.inventory_item_id;
6108       g_itm_mustuse_cache(l_hash_value).target_itemorg_id := l_target_item_org_id;
6109       g_itm_mustuse_cache(l_hash_value).hash_string := l_hash_string;
6110       g_itm_mustuse_cache(l_hash_value).carrier_result := 'S';
6111       g_itm_mustuse_cache(l_hash_value).mode_result := 'S';
6112       g_itm_mustuse_cache(l_hash_value).vehicle_result := 'S';
6113       IF l_debug_on THEN
6114           WSH_DEBUG_SV.logmsg(l_module_name,'Creating g_itm_mustuse_cache record with hash value : '||l_hash_value);
6115       END IF;
6116       END IF;
6117 
6118       IF p_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) THEN
6119 
6120         check_inclusive_object2(
6121              p_comp_class_code          =>      G_ITEM_CARRIER,
6122              p_entity_type              =>      G_DEL_DETAIL,
6123              p_entity_id                =>      l_entity_id,
6124              p_object1_type             =>      'ITM',
6125              p_object1_val_num          =>      l_item_id,
6126              p_object1_parent_id        =>      l_org_id,
6127              p_object2_type             =>      'CAR',
6128              x_out_object2_num          =>      l_out_object2_num,
6129              x_out_object2_char         =>      l_out_object2_char,
6130              x_validate_result          =>      l_validate_carrier_result,
6131              x_failed_constraint        =>      x_failed_constraints,
6132              x_return_status            =>      l_return_status);
6133 
6134         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
6135            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
6136               raise FND_API.G_EXC_UNEXPECTED_ERROR;
6137            END IF;
6138         END IF;
6139 
6140         IF l_validate_carrier_result = 'F' THEN
6141            IF i = 2 AND l_prev_out_object2_num IS NOT NULL THEN
6142               IF l_out_object2_num <> l_prev_out_object2_num THEN
6143                  x_validate_result := 'F';
6144                  g_itm_mustuse_cache(l_hash_value).carrier_result := 'F';
6145                  --EXIT;
6146               END IF;
6147            END IF;
6148         END IF;
6149         l_prev_out_object2_num := l_out_object2_num;
6150 
6151       END IF;
6152 
6153       IF p_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) THEN
6154 
6155         check_inclusive_object2(
6156              p_comp_class_code          =>      G_ITEM_MODE,
6157              p_entity_type              =>      G_DEL_DETAIL,
6158              p_entity_id                =>      l_entity_id,
6159              p_object1_type             =>      'ITM',
6160              p_object1_val_num          =>      l_item_id,
6161              p_object1_parent_id        =>      l_org_id,
6162              p_object2_type             =>      'MOD',
6163              x_out_object2_num          =>      l_out_object2_num,
6164              x_out_object2_char         =>      l_out_object2_char,
6165              x_validate_result          =>      l_validate_mode_result,
6166              x_failed_constraint        =>      x_failed_constraints,
6167              x_return_status            =>      l_return_status);
6168 
6169         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
6170            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
6171               raise FND_API.G_EXC_UNEXPECTED_ERROR;
6172            END IF;
6173         END IF;
6174 
6175         IF l_validate_mode_result = 'F' THEN
6176            IF i = 2 AND l_prev_out_object2_char IS NOT NULL THEN
6177               IF l_out_object2_char <> l_prev_out_object2_char THEN
6178                  x_validate_result := 'F';
6179                  g_itm_mustuse_cache(l_hash_value).mode_result := 'F';
6180                  --EXIT;
6181               END IF;
6182            END IF;
6183         END IF;
6184         l_prev_out_object2_char := l_out_object2_char;
6185 
6186       END IF;
6187 
6188       IF p_comp_class_tab.EXISTS(G_ITEM_VEHICLE_NUM) THEN
6189 
6190         check_inclusive_object2(
6191              p_comp_class_code          =>      G_ITEM_VEHICLE,
6192              p_entity_type              =>      G_DEL_DETAIL,
6193              p_entity_id                =>      l_entity_id,
6194              p_object1_type             =>      'ITM',
6195              p_object1_val_num          =>      l_item_id,
6196              p_object1_parent_id        =>      l_org_id,
6197              p_object2_type             =>      'VHT',
6198              x_out_object2_num          =>      l_out_object2_vehnum,
6199              x_out_object2_char         =>      l_out_object2_char,
6200              x_validate_result          =>      l_validate_vehicle_result,
6201              x_failed_constraint        =>      x_failed_constraints,
6202              x_return_status            =>      l_return_status);
6203 
6204         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
6205            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
6206               raise FND_API.G_EXC_UNEXPECTED_ERROR;
6207            END IF;
6208         END IF;
6209 
6210         IF l_validate_vehicle_result = 'F' THEN
6211            IF i = 2 AND l_prev_out_object2_vehnum IS NOT NULL THEN
6212               IF l_out_object2_vehnum <> l_prev_out_object2_vehnum THEN
6213                  x_validate_result := 'F';
6214                  g_itm_mustuse_cache(l_hash_value).vehicle_result := 'F';
6215                  --EXIT;
6216               END IF;
6217            END IF;
6218         END IF;
6219         l_prev_out_object2_vehnum := l_out_object2_vehnum;
6220 
6221       END IF;
6222 
6223     END LOOP;
6224 
6225     END IF; -- cache check
6226 
6227     IF ( l_const_count < x_failed_constraints.COUNT) AND
6228          x_validate_result <> 'F' THEN
6229 
6230          x_failed_constraints.DELETE(l_const_count+1,x_failed_constraints.COUNT);
6231 
6232     END IF;
6233 
6234     --
6235     IF l_debug_on THEN
6236       WSH_DEBUG_SV.logmsg(l_module_name,'Returning x_validate_result : '||x_validate_result);
6237       WSH_DEBUG_SV.pop(l_module_name);
6238     END IF;
6239     --
6240 
6241 EXCEPTION
6242     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6243       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
6244       --
6245       IF l_debug_on THEN
6246         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
6247         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
6248       END IF;
6249       --
6250     WHEN others THEN
6251       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.search_group_itm');
6252       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
6253       --
6254       IF l_debug_on THEN
6255         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
6256         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
6257       END IF;
6258       --
6259 
6260 END search_group_itm;
6261 
6262 
6263 --***************************************************************************--
6264 --========================================================================
6265 -- PROCEDURE : search_matching_group      PRIVATE
6266 --
6267 -- PARAMETERS: p_entity_type              Entity for which check is running
6268 --             p_action_code              Current action that required constraint check
6269 --                                        Used only for Call from delivery API
6270 --             p_children_info            Table of children delivery details of the input delivery
6271 --                                        Used only for Call from delivery API
6272 --             p_comp_class_tab           Table of Compatibility class codes to check
6273 --             p_target_stops_info        Input pickup and dropoff stop/location of the delivery(s)
6274 --                                        in the target trip in case of assign delivery to trip
6275 --             p_entity_rec               Input entity record for which a group is being searched
6276 --                                        Can be delivery or delivery detail
6277 --             p_entity_tab               Table of entity records already formed
6278 --             p_group_tab                Table of group records which are being searched
6279 --             x_validate_result          Constraint Validation result : S / E / W
6280 --             x_failed_constraints       failed constraint table
6281 --             x_group_id                 Matching group id from the list p_group_tab
6282 --                                        for the input p_entity_rec
6283 --                                        Returns -999 if nothing is found
6284 --             x_found                    Whether a matching group has been found
6285 --             x_return_status            Return status
6286 -- COMMENT   :
6287 -- For a given entity which can be delivery or delivery detail
6288 -- determines if a group of entities can be found from the current list of groups
6289 -- where the input entity can be placed satisfying constraints
6290 --========================================================================
6291 
6292 PROCEDURE search_matching_group(
6293                   p_entity_type           IN    VARCHAR2,
6294                   p_action_code           IN    VARCHAR2,
6295                   p_children_info         IN    detail_ccinfo_tab_type,
6296                   p_comp_class_tab        IN    WSH_UTIL_CORE.Column_Tab_Type,
6297                   p_target_stops_info     IN    target_tripstop_cc_rec_type,
6298                   p_entity_rec            IN    entity_rec_type,
6299                   p_target_trip_id        IN    NUMBER DEFAULT NULL,
6300                   p_entity_tab            IN    entity_tab_type,
6301                   p_group_tab             IN    WSH_FTE_COMP_CONSTRAINT_PKG.cc_group_tab_type,
6302                   x_failed_constraints    IN OUT NOCOPY    line_constraint_tab_type,
6303                   x_group_id              OUT NOCOPY       NUMBER,
6304                   x_found                 OUT NOCOPY       BOOLEAN,
6305                   x_return_status         OUT NOCOPY       VARCHAR2)
6306 IS
6307 
6308     i                           NUMBER := 0;
6309     j                           NUMBER := 0;
6310     k                           NUMBER := 0;
6311     l                           NUMBER := 0;
6312     m                           NUMBER := 0;
6313     l_inp_items_cnt             NUMBER := 0;
6314     l_tgt_items_cnt             NUMBER := 0;
6315     l_const_count               NUMBER := 0;
6316     l_return_status             VARCHAR2(1);
6317     l_inp_dlvy_cus              BOOLEAN := TRUE;
6318     l_cuscus_checked            BOOLEAN := FALSE;
6319     l_curr_dlvy_cus             BOOLEAN := TRUE;
6320     l_checked_cus1_fac           BOOLEAN := FALSE;
6321     l_checked_cus2_fac           BOOLEAN := FALSE;
6322     l_checked_sup_fac           BOOLEAN := FALSE;
6323     l_validate_orgfac_result    VARCHAR2(1) := 'S';
6324     l_validate_cusfac_result    VARCHAR2(1) := 'S';
6325     l_validate_supfac_result    VARCHAR2(1) := 'S';
6326     l_validate_itmfac_result    VARCHAR2(1) := 'S';
6327     l_validate_cuscus_result    VARCHAR2(1) := 'S';
6328     l_validate_itmin_result     VARCHAR2(1) := 'S';
6329     l_validate_itmfacin_result  VARCHAR2(1) := 'S';
6330     l_validate_itmfacin_result2 VARCHAR2(1) := 'S';
6331     --l_validate_loop_result      VARCHAR2(1) := 'S';
6332     l_facility_id               NUMBER := 0;
6333     l_items_tab                 item_tab_type;
6334     l_target_items_tab          item_tab_type;
6335     l_locations_list            WSH_UTIL_CORE.id_tab_type;
6336     l_inp_locations_list        WSH_UTIL_CORE.id_tab_type;
6337     l_failed_constraint         line_constraint_rec_type;
6338     l_entity_rec                entity_rec_type;
6339     l_target_rec                entity_rec_type;
6340     l_check_pickup              BOOLEAN := FALSE;
6341     l_check_dropoff             BOOLEAN := FALSE;
6342     l_pu_sequencenum            NUMBER := NULL;
6343     l_pu_pa_date                DATE;
6344     l_do_sequencenum            NUMBER := NULL;
6345     l_do_pa_date                DATE;
6346     l_entity_id                 NUMBER := 0;
6347     l_shipment_direction        VARCHAR2(30) := NULL;
6348     l_org_id                    NUMBER := 0;
6349     l_cust_id                   NUMBER := 0;
6350     l_custfac_id                NUMBER := 0;
6351     l_supl_id                   NUMBER := 0;
6352     l_suplfac_id                NUMBER := 0;
6353     l_ini_pu_loc_id             NUMBER := 0;
6354     l_ult_do_loc_id             NUMBER := 0;
6355 
6356     --DUM_LOC
6357     l_physical_custfac_id	NUMBER := 0;
6358     --DUM_LOC
6359     l_obj_check_pickup          BOOLEAN := FALSE;
6360     l_obj_check_dropoff         BOOLEAN := FALSE;
6361     l_obj_itm_check_pickup          BOOLEAN := FALSE;
6362     l_obj_itm_check_dropoff         BOOLEAN := FALSE;
6363 
6364     l_module_name               CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'search_matching_group';
6365     l_debug_on                  CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
6366 
6367 BEGIN
6368 
6369     -- for assign delivery to trip
6370     -- might not need to check against locations of all other deliveries in a group
6371     -- for autocreate trip, still need to
6372 
6373     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
6374 
6375     IF l_debug_on THEN
6376        wsh_debug_sv.push(l_module_name);
6377     END IF;
6378 
6379       -- checks itm-itm , cus-cus
6380       -- itm-fac with pickup / dropoff locations
6381       -- com-fac, cus-fac with pickup / dropoff locations
6382       -- for every delivery
6383       -- against every other delivery
6384 
6385     IF NOT p_comp_class_tab.EXISTS(G_CUSTOMER_CUSTOMER_NUM) AND
6386        NOT p_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) AND
6387        NOT p_comp_class_tab.EXISTS(G_ITEM_VEHICLE_NUM) AND
6388        NOT p_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) THEN
6389 
6390       IF p_entity_type = 'DLVB' THEN
6391          --
6392          IF l_debug_on THEN
6393            WSH_DEBUG_SV.pop(l_module_name);
6394          END IF;
6395          --
6396          RETURN;
6397       END IF;
6398       l_cuscus_checked := TRUE;
6399     END IF;
6400 
6401     IF p_entity_rec.customer_id IS NULL THEN
6402        l_inp_dlvy_cus := FALSE;
6403     END IF;
6404 
6405     x_group_id  := -999; -- Means not found
6406     x_found     := FALSE;
6407 
6408     IF p_entity_type = 'DLVY' THEN
6409 
6410        l_inp_locations_list(l_inp_locations_list.COUNT + 1) := p_entity_rec.initial_pickup_location_id;
6411        l_inp_locations_list(l_inp_locations_list.COUNT + 1) := p_entity_rec.ultimate_dropoff_location_id;
6412 
6413     END IF;
6414 
6415     j := p_group_tab.FIRST;
6416     IF j IS NOT NULL THEN
6417       LOOP -- over p_group_tab
6418 
6419         l_items_tab.DELETE;
6420         l_locations_list.DELETE;
6421         l_target_items_tab.DELETE;
6422         --l_inp_locations_list.DELETE;
6423         --l_validate_orgfac_result := 'S';
6424         --l_validate_cusfac_result := 'S';
6425         --l_validate_supfac_result := 'S';
6426         --l_validate_itmfac_result := 'S';
6427         l_validate_cuscus_result := 'S';
6428         l_validate_itmin_result  := 'S';
6429         l_validate_itmfacin_result  := 'S';
6430         l_validate_itmfacin_result2 := 'S';
6431 
6432         k := p_entity_tab.FIRST;
6433         IF k IS NOT NULL THEN
6434           LOOP -- over p_entity_tab (for every other delivery)
6435 
6436            --l_items_tab.DELETE;
6437            l_curr_dlvy_cus := TRUE;
6438            l_checked_cus1_fac := FALSE;
6439            l_checked_cus2_fac := FALSE;
6440            l_checked_sup_fac := FALSE;
6441            --l_validate_loop_result := 'S';
6442            l_facility_id := NULL;
6443            l_check_pickup := FALSE;
6444            l_check_dropoff := FALSE;
6445 
6446 	   IF l_debug_on THEN
6447                 WSH_DEBUG_SV.logmsg(l_module_name,'p_group_tab(j).line_group_id : '||p_group_tab(j).line_group_id);
6448                 WSH_DEBUG_SV.logmsg(l_module_name,'p_entity_tab(k).entity_id : '||p_entity_tab(k).entity_id);
6449                 WSH_DEBUG_SV.logmsg(l_module_name,'p_entity_tab(k).group_id : '||p_entity_tab(k).group_id);
6450            END IF;
6451 
6452            IF (p_entity_tab(k).entity_id = p_entity_rec.entity_id) OR
6453                (p_entity_tab(k).group_id <> p_group_tab(j).line_group_id) THEN  -- check against same group
6454                GOTO dlvy_nextpass;
6455            END IF;
6456 
6457            IF p_entity_tab(k).customer_id IS NULL THEN
6458                l_curr_dlvy_cus := FALSE;
6459            END IF;
6460 
6461            IF p_action_code = G_ASSIGN_DLVY_TRIP THEN
6462 
6463              -- p_target_stops_info.pickup_stop_id/dropoff_stop_id
6464              -- can be null but the stop location might already exist in
6465              -- the target trip
6466              -- In that case the following facility related
6467              -- checks are not necessary
6468 
6469 	     IF p_target_stops_info.pickup_stop_id IS NULL THEN
6470                 -- check if delivery's initial pu location id already exists
6471                 -- in target trip
6472                 OPEN c_get_stop(p_entity_rec.initial_pickup_location_id,p_target_trip_id);
6473                 FETCH c_get_stop INTO l_pu_sequencenum,l_pu_pa_date;
6474                 CLOSE c_get_stop;
6475 
6476              END IF;
6477 
6478              IF p_target_stops_info.dropoff_stop_id IS NULL THEN
6479                 -- check if delivery's ultimate do location id already exists
6480                 -- in target trip
6481                   OPEN c_get_stop(p_entity_rec.ultimate_dropoff_location_id,p_target_trip_id);
6482                   FETCH c_get_stop INTO l_do_sequencenum,l_do_pa_date;
6483                   CLOSE c_get_stop;
6484              END IF;
6485 
6486              IF p_target_stops_info.pickup_stop_id IS NULL AND
6487                 l_pu_sequencenum IS NULL AND
6488                 p_target_stops_info.pickup_location_id IS NULL AND
6489                 (p_entity_rec.initial_pickup_location_id <> p_entity_tab(k).initial_pickup_location_id
6490                 AND p_entity_rec.initial_pickup_location_id <> p_entity_tab(k).ultimate_dropoff_location_id)
6491              THEN
6492                   l_check_pickup := TRUE;
6493              END IF;
6494 
6495 	     IF p_target_stops_info.dropoff_stop_id IS NULL AND
6496                 l_do_sequencenum IS NULL AND
6497                 p_target_stops_info.dropoff_location_id IS NULL AND
6498                 (p_entity_rec.ultimate_dropoff_location_id <> p_entity_tab(k).ultimate_dropoff_location_id
6499                 AND p_entity_rec.ultimate_dropoff_location_id <> p_entity_tab(k).initial_pickup_location_id)
6500              THEN
6501                   l_check_dropoff := TRUE;
6502              END IF;
6503 
6504            ELSIF p_action_code = G_AUTOCRT_DLVY_TRIP OR p_action_code = G_AUTOCRT_MDC THEN
6505              -- TODO
6506              -- Should ideally check dates here to determine what is intermediate stop
6507              IF (p_entity_rec.initial_pickup_location_id <> p_entity_tab(k).initial_pickup_location_id
6508                 AND p_entity_rec.initial_pickup_location_id <> p_entity_tab(k).ultimate_dropoff_location_id)
6509              THEN
6510                  l_check_pickup := TRUE;
6511              END IF;
6512 
6513 	     IF (p_entity_rec.ultimate_dropoff_location_id <> p_entity_tab(k).ultimate_dropoff_location_id
6514                 AND p_entity_rec.ultimate_dropoff_location_id <> p_entity_tab(k).initial_pickup_location_id)
6515              THEN
6516                  l_check_dropoff := TRUE;
6517              END IF;
6518 
6519 	   END IF;
6520 
6521            IF ((p_entity_type = 'DLVY' AND NOT l_cuscus_checked AND
6522              l_inp_dlvy_cus AND l_curr_dlvy_cus ) OR
6523              (p_entity_type = 'DLVB')) AND
6524              (p_entity_rec.customer_id <> p_entity_tab(k).customer_id) THEN
6525 
6526               l_cuscus_checked := TRUE;
6527 
6528               validate_constraint(   --  checks only negative constraints
6529                  p_comp_class_code          =>      G_CUSTOMER_CUSTOMER,
6530                  p_object1_type             =>      'CUS',
6531                  p_object2_type             =>      'CUS',
6532                  p_object1_val_num          =>      p_entity_rec.customer_id,
6533                  p_object2_val_num          =>      p_entity_tab(k).customer_id,
6534                  x_validate_result          =>      l_validate_cuscus_result,
6535                  x_failed_constraint        =>      l_failed_constraint,
6536                  x_return_status            =>      l_return_status);
6537 
6538               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
6539                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
6540                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
6541                  END IF;
6542               END IF;
6543 
6544 
6545               IF l_validate_cuscus_result <> 'S' THEN
6546                   l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
6547                   l_failed_constraint.entity_type := p_entity_type;
6548                   l_failed_constraint.entity_line_id := p_entity_rec.entity_id;
6549                   x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
6550                   IF l_validate_cuscus_result = 'E' THEN
6551                      EXIT;
6552                   END IF;
6553               END IF;
6554            END IF;
6555 
6556            IF (p_entity_type = 'DLVB') AND
6557             ((p_entity_rec.inventory_item_id <> p_entity_tab(k).inventory_item_id) OR
6558              (g_is_tp_installed = 'N' AND p_entity_rec.organization_id <> p_entity_tab(k).organization_id))  THEN
6559 
6560 
6561                l_const_count  := x_failed_constraints.COUNT;
6562 
6563                search_group_itm (
6564                       p_comp_class_tab      =>   p_comp_class_tab,
6565                       p_entity_rec          =>   p_entity_rec,
6566                       p_target_rec          =>   p_entity_tab(k),
6567                       x_validate_result     =>   l_validate_itmin_result,
6568                       x_failed_constraints  =>   x_failed_constraints,
6569                       x_return_status       =>   l_return_status);
6570 
6571                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
6572                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
6573                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
6574                   END IF;
6575                END IF;
6576 
6577                IF ( l_const_count < x_failed_constraints.COUNT) THEN
6578 
6579                   x_failed_constraints.DELETE(l_const_count+1,x_failed_constraints.COUNT);
6580 
6581                END IF;
6582 
6583                IF l_validate_itmin_result = 'F' THEN
6584                   EXIT;
6585                END IF;
6586 
6587            END IF;
6588 
6589            IF p_entity_type = 'DLVB' THEN
6590                 GOTO dlvy_nextpass;
6591            END IF;
6592 
6593            IF l_debug_on THEN
6594               WSH_DEBUG_SV.logmsg(l_module_name,'p_children_info COUNT :'||p_children_info.COUNT);
6595            END IF;
6596 
6597 	   l := p_children_info.FIRST;
6598 
6599 	   IF l IS NOT NULL THEN -- --{
6600               LOOP    -- over p_children_info (for input dlvy entity)
6601 
6602                  IF l_debug_on THEN
6603                     WSH_DEBUG_SV.logmsg(l_module_name,'delivery_id of curr child :'||p_children_info(l).delivery_id||' p_entity_rec.entity_id : '||p_entity_rec.entity_id);
6604                  END IF;
6605                  IF (p_children_info(l).delivery_id <> p_entity_rec.entity_id) THEN
6606                     GOTO inpdlvyline_nextpass;
6607                  END IF;
6608 
6609                  l_obj_itm_check_pickup := FALSE;
6610                  l_obj_itm_check_dropoff := FALSE;
6611 
6612 		 -- TODO
6613 		 -- check if object2 is intermediate discretionary routing point
6614 	         -- for object1
6615 		    IF p_entity_tab(k).initial_pickup_date > p_entity_rec.initial_pickup_date AND
6616 	                p_entity_tab(k).initial_pickup_date < p_entity_rec.ultimate_dropoff_date THEN
6617 			    l_obj_itm_check_pickup := TRUE;
6618             END IF;
6619 
6620 	         IF p_entity_tab(k).ultimate_dropoff_date > p_entity_rec.initial_pickup_date AND
6621 			p_entity_tab(k).ultimate_dropoff_date < p_entity_rec.ultimate_dropoff_date THEN
6622 			    l_obj_itm_check_dropoff := TRUE;
6623 		    END IF;
6624 
6625              l_inp_items_cnt := l_items_tab.COUNT;
6626              l_items_tab(l_inp_items_cnt + 1).line_id := p_children_info(l).delivery_detail_id;
6627              l_items_tab(l_inp_items_cnt + 1).item_id := p_children_info(l).inventory_item_id;
6628 	         l_items_tab(l_inp_items_cnt + 1).org_id  := p_children_info(l).organization_id;
6629 
6630 	     IF l_debug_on THEN
6631                 WSH_DEBUG_SV.logmsg(l_module_name,'l_inp_items_cnt : '||to_char(l_inp_items_cnt + 1));
6632                 WSH_DEBUG_SV.logmsg(l_module_name,'l_items_tab.COUNT :'||l_items_tab.COUNT);
6633              END IF;
6634 
6635 		 -- cus-cus for input lines against other delivery if not before
6636                  IF (NOT l_cuscus_checked) AND (NOT l_inp_dlvy_cus) AND (l_curr_dlvy_cus) AND
6637                     (p_children_info(l).customer_id IS NOT NULL) AND
6638                     (p_children_info(l).customer_id <> p_entity_tab(k).customer_id) THEN -- --{
6639 
6640                    validate_constraint(   --  checks only negative constraints
6641                      p_comp_class_code          =>      G_CUSTOMER_CUSTOMER,
6642                      p_object1_type             =>      'CUS',
6643                      p_object2_type             =>      'CUS',
6644                      p_object1_val_num          =>      p_children_info(l).customer_id,
6645                      p_object2_val_num          =>      p_entity_tab(k).customer_id,
6646                      x_validate_result          =>      l_validate_cuscus_result,
6647                      x_failed_constraint        =>      l_failed_constraint,
6648                      x_return_status            =>      l_return_status);
6649 
6650                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
6651                       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
6652                          raise FND_API.G_EXC_UNEXPECTED_ERROR;
6653                       END IF;
6654                    END IF;
6655 
6656                    IF l_validate_cuscus_result <> 'S' THEN
6657                     l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
6658                     l_failed_constraint.entity_type := p_entity_type;
6659                     l_failed_constraint.entity_line_id := p_entity_rec.entity_id;
6660                     x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
6661                     IF l_validate_cuscus_result = 'E' THEN
6662                        EXIT;
6663                     END IF;
6664                    END IF;
6665 
6666                  END IF; -- --}
6667 
6668                  -- As Item - Item scoped out for phase I,
6669 
6670                  IF ((NOT l_cuscus_checked) AND (NOT l_curr_dlvy_cus)
6671                     AND ( l_inp_dlvy_cus OR p_children_info(l).customer_id IS NOT NULL)) OR
6672                     (p_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) OR
6673                      p_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) ) THEN -- --{
6674 
6675                    m := p_children_info.FIRST;
6676                    IF m IS NOT NULL THEN -- --{
6677                      LOOP    -- over p_children_info (for other dlvy )
6678 
6679                         IF (p_children_info(m).delivery_id <> p_entity_tab(k).entity_id) THEN
6680                            GOTO othdlvyline_nextpass;
6681                         END IF;
6682 
6683                         l_obj_itm_check_pickup := FALSE;
6684                         l_obj_itm_check_dropoff := FALSE;
6685                         -- Build a list of items in p_entity_tab here
6686 
6687                         l_tgt_items_cnt := l_target_items_tab.COUNT;
6688                         l_target_items_tab(l_tgt_items_cnt + 1).line_id := p_children_info(m).delivery_detail_id;
6689                         l_target_items_tab(l_tgt_items_cnt + 1).item_id := p_children_info(m).inventory_item_id;
6690                         l_target_items_tab(l_tgt_items_cnt + 1).org_id  := p_children_info(m).organization_id;
6691 
6692 	                IF p_children_info(m).customer_id IS NOT NULL THEN
6693 
6694 			            IF l_inp_dlvy_cus AND
6695                               p_entity_rec.customer_id <> p_children_info(m).customer_id THEN
6696                                -- cus-cus for input delivey against other lines if not before
6697 
6698                                validate_constraint(   --  checks only negative constraints
6699                                    p_object1_type             =>      'CUS',
6700                                    p_object2_type             =>      'CUS',
6701                                    p_comp_class_code          =>      G_CUSTOMER_CUSTOMER,
6702                                    p_object1_val_num          =>      p_entity_rec.customer_id,
6703                                    p_object2_val_num          =>      p_children_info(m).customer_id,
6704                                    x_validate_result          =>      l_validate_cuscus_result,
6705                                    x_failed_constraint        =>      l_failed_constraint,
6706                                    x_return_status            =>      l_return_status);
6707 
6708                                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
6709                                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
6710                                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
6711                                   END IF;
6712                                END IF;
6713 
6714                                IF l_validate_cuscus_result <> 'S' THEN
6715                                 l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
6716                                 l_failed_constraint.entity_type := p_entity_type;
6717                                 l_failed_constraint.entity_line_id := p_entity_rec.entity_id;
6718                                 x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
6719                                 IF l_validate_cuscus_result = 'E' THEN
6720                                    EXIT;
6721                                 END IF;
6722                                END IF;
6723 
6724                            ELSIF p_children_info(l).customer_id IS NOT NULL AND
6725                                  p_children_info(l).customer_id <> p_children_info(m).customer_id  THEN
6726                                -- cus-cus for input lines against other lines if not before
6727 
6728                                 validate_constraint(   --  checks only negative constraints
6729                                      p_comp_class_code          =>      G_CUSTOMER_CUSTOMER,
6730                                      p_object1_type             =>      'CUS',
6731                                      p_object2_type             =>      'CUS',
6732                                      p_object1_val_num          =>      p_children_info(l).customer_id,
6733                                      p_object2_val_num          =>      p_children_info(m).customer_id,
6734                                      x_validate_result          =>      l_validate_cuscus_result,
6735                                      x_failed_constraint        =>      l_failed_constraint,
6736                                      x_return_status            =>      l_return_status);
6737 
6738                                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
6739                                     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
6740                                        raise FND_API.G_EXC_UNEXPECTED_ERROR;
6741                                     END IF;
6742                                 END IF;
6743 
6744                                 IF l_validate_cuscus_result <> 'S' THEN
6745                                  l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
6746                                  --l_failed_constraint.entity_type := p_entity_type;
6747                                  --l_failed_constraint.entity_line_id := p_entity_rec.entity_id;
6748                                  l_failed_constraint.entity_type := G_DEL_DETAIL;
6749                                  l_failed_constraint.entity_line_id := p_children_info(l).delivery_detail_id;
6750                                  x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
6751                                  IF l_validate_cuscus_result = 'E' THEN
6752                                     EXIT;
6753                                  END IF;
6754                                 END IF;
6755 
6756                            END IF; -- l_inp_d
6757 
6758                         END IF; -- p_children_info(m).customer_id IS NOT NULL
6759 
6760                         l_const_count  := x_failed_constraints.COUNT;
6761 
6762                         l_entity_rec.entity_id := p_children_info(l).delivery_detail_id;
6763                         l_entity_rec.organization_id := p_children_info(l).organization_id;
6764                         l_entity_rec.inventory_item_id := p_children_info(l).inventory_item_id;
6765                         l_entity_rec.customer_id := p_children_info(l).customer_id;
6766 
6767                         l_target_rec.entity_id := p_children_info(m).delivery_detail_id;
6768                         l_target_rec.organization_id := p_children_info(m).organization_id;
6769                         l_target_rec.inventory_item_id := p_children_info(m).inventory_item_id;
6770                         l_target_rec.customer_id := p_children_info(m).customer_id;
6771                         --
6772                         IF l_debug_on THEN
6773                             WSH_DEBUG_SV.logmsg(l_module_name,'Created l_target_rec for assigned line : '||p_children_info(m).delivery_detail_id);
6774                         END IF;
6775                         --
6776 
6777                       IF l_debug_on THEN
6778                         WSH_DEBUG_SV.logmsg(l_module_name,' l_entity_rec.inventory_item_id: '||l_entity_rec.inventory_item_id);
6779                         WSH_DEBUG_SV.logmsg(l_module_name,' l_target_rec.inventory_item_id: '||l_target_rec.inventory_item_id);
6780                         WSH_DEBUG_SV.logmsg(l_module_name,' l_entity_rec.organization_id: '||l_entity_rec.organization_id);
6781                         WSH_DEBUG_SV.logmsg(l_module_name,' l_target_rec.organization_id: '||l_target_rec.organization_id);
6782                         WSH_DEBUG_SV.logmsg(l_module_name,' g_is_tp_installed: '||g_is_tp_installed);
6783                       END IF;
6784 
6785                       IF ((l_entity_rec.inventory_item_id <> l_target_rec.inventory_item_id) OR
6786                         (g_is_tp_installed = 'N' AND l_entity_rec.organization_id <> l_target_rec.organization_id))  THEN
6787                         search_group_itm (
6788                             p_comp_class_tab      =>   p_comp_class_tab,
6789                             p_entity_rec          =>   l_entity_rec,
6790                             p_target_rec          =>   l_target_rec,
6791                             x_validate_result     =>   l_validate_itmin_result,
6792                             x_failed_constraints  =>   x_failed_constraints,
6793                             x_return_status       =>   l_return_status);
6794 
6795                         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
6796                             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
6797                                raise FND_API.G_EXC_UNEXPECTED_ERROR;
6798                             END IF;
6799                         END IF;
6800 
6801                         IF ( l_const_count < x_failed_constraints.COUNT) THEN
6802 
6803                             x_failed_constraints.DELETE(l_const_count+1,x_failed_constraints.COUNT);
6804 
6805                         END IF;
6806 
6807                         IF l_validate_itmin_result = 'F' THEN
6808                            EXIT;
6809                         END IF;
6810                       END IF;
6811 
6812                         <<othdlvyline_nextpass>>
6813 
6814                         EXIT WHEN m= p_children_info.LAST;
6815                         m:= p_children_info.NEXT(m);
6816 
6817                      END LOOP;
6818 
6819                      IF l_validate_cuscus_result = 'E' OR l_validate_itmin_result = 'F' THEN
6820                         --l_validate_loop_result = 'F' OR l_validate_itmfac_result = 'E' THEN
6821                         --l_validate_loop_result = 'F' THEN
6822                         EXIT; -- exit out of input delivery line group
6823                               -- as some customer of target delivery line
6824                               -- violates against this input dlvy / line customer
6825                      END IF;
6826 
6827                    END IF; -- --}
6828 
6829                  END IF; -- --}
6830                  <<inpdlvyline_nextpass>>
6831 
6832                  EXIT WHEN l= p_children_info.LAST;
6833                  l:= p_children_info.NEXT(l);
6834 
6835               END LOOP;
6836 
6837               --IF l_validate_cuscus_result = 'E' OR l_validate_itmfac_result = 'E' OR
6838               IF l_validate_cuscus_result = 'E' OR
6839                  l_validate_itmin_result = 'F' THEN
6840                  --l_validate_loop_result = 'F' THEN
6841                  EXIT; -- exit out of target dlvy loop
6842                        -- as some item of input delivery
6843                        -- violates against this delivery facility / customer
6844               END IF;
6845 
6846            END IF; -- --}
6847            IF l_debug_on THEN
6848               WSH_DEBUG_SV.logmsg(l_module_name,'l_items_tab.COUNT :'||l_items_tab.COUNT);
6849            END IF;
6850 
6851            IF l_check_pickup THEN
6852 
6853                IF l_debug_on THEN
6854                   WSH_DEBUG_SV.logmsg(l_module_name,' l_locations_list.COUNT : '||l_locations_list.COUNT||' initial_pickup loc : '||p_entity_tab(k).initial_pickup_location_id);
6855                END IF;
6856 
6857                l_locations_list(l_locations_list.COUNT + 1) := p_entity_tab(k).initial_pickup_location_id;
6858            END IF;
6859            IF l_check_dropoff THEN
6860 
6861                IF l_debug_on THEN
6862                   WSH_DEBUG_SV.logmsg(l_module_name,' l_locations_list.COUNT : '||l_locations_list.COUNT||' ultimate dropoff loc : '||p_entity_tab(k).ultimate_dropoff_location_id);
6863                END IF;
6864 
6865                l_locations_list(l_locations_list.COUNT + 1) := p_entity_tab(k).ultimate_dropoff_location_id;
6866            END IF;
6867 
6868            <<dlvy_nextpass>>
6869 
6870            EXIT WHEN k= p_entity_tab.LAST;
6871            k:= p_entity_tab.NEXT(k);
6872 
6873           END LOOP;
6874         END IF;
6875 
6876         -- Bug found in omfut11i
6877         -- Not checking list of locations of p_entity_rec
6878         -- against list of items in p_entity_tab in the current group
6879 
6880         IF p_entity_type = 'DLVY' AND l_locations_list.COUNT <> 0 THEN
6881 
6882            -- l_items_tab is list of items of p_entity_rec
6883            -- l_locations_list is list of locations of p_entity_tab
6884 
6885            l_const_count   := x_failed_constraints.COUNT;
6886 
6887            search_itm_fac_incl(
6888                        p_comp_class_tab     =>  p_comp_class_tab,
6889                        p_entity_type        =>  G_DELIVERY,
6890                        p_entity_id          =>  p_entity_rec.entity_id,
6891                        p_items_tab          =>  l_items_tab,
6892                        p_locations_list     =>  l_locations_list,
6893                        x_validate_result    =>  l_validate_itmfacin_result,
6894                        x_failed_constraints =>  x_failed_constraints,
6895                        x_return_status      =>  l_return_status);
6896 
6897            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
6898               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
6899                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
6900               END IF;
6901            END IF;
6902 
6903            IF ( l_const_count < x_failed_constraints.COUNT) THEN
6904 
6905                x_failed_constraints.DELETE(l_const_count+1,x_failed_constraints.COUNT);
6906 
6907            END IF;
6908         END IF;
6909 
6910         IF p_entity_type = 'DLVY' AND l_target_items_tab.COUNT <> 0 THEN
6911 
6912            -- l_target_items_tab is list of items of p_entity_tab
6913            -- l_inp_locations_list is list of locations of p_entity_rec
6914 
6915            l_const_count   := x_failed_constraints.COUNT;
6916 
6917            search_itm_fac_incl(
6918                        p_comp_class_tab     =>  p_comp_class_tab,
6919                        p_entity_type        =>  G_DELIVERY,
6920                        p_entity_id          =>  p_entity_rec.entity_id,
6921                        p_items_tab          =>  l_target_items_tab,
6922                        p_locations_list     =>  l_inp_locations_list,
6923                        x_validate_result    =>  l_validate_itmfacin_result2,
6924                        x_failed_constraints =>  x_failed_constraints,
6925                        x_return_status      =>  l_return_status);
6926 
6927            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
6928               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
6929                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
6930               END IF;
6931            END IF;
6932 
6933            IF ( l_const_count < x_failed_constraints.COUNT) THEN
6934 
6935                x_failed_constraints.DELETE(l_const_count+1,x_failed_constraints.COUNT);
6936 
6937            END IF;
6938         END IF;
6939 
6940         IF l_debug_on THEN
6941             WSH_DEBUG_SV.logmsg(l_module_name,' l_validate_cuscus_result: '||l_validate_cuscus_result);
6942             --WSH_DEBUG_SV.logmsg(l_module_name,' l_validate_itmfac_result: '||l_validate_itmfac_result);
6943             --WSH_DEBUG_SV.logmsg(l_module_name,' l_validate_orgfac_result: '||l_validate_orgfac_result);
6944             --WSH_DEBUG_SV.logmsg(l_module_name,' l_validate_loop_result: '||l_validate_loop_result);
6945             WSH_DEBUG_SV.logmsg(l_module_name,' l_validate_itmin_result: '||l_validate_itmin_result);
6946             WSH_DEBUG_SV.logmsg(l_module_name,' l_validate_itmfacin_result: '||l_validate_itmfacin_result);
6947             WSH_DEBUG_SV.logmsg(l_module_name,' l_validate_itmfacin_result2: '||l_validate_itmfacin_result2);
6948         END IF;
6949 
6950         --IF l_validate_cuscus_result <> 'E' AND l_validate_itmfac_result <> 'E'
6951         IF l_validate_cuscus_result <> 'E'
6952            --AND l_validate_orgfac_result <> 'E'
6953            --AND l_validate_loop_result <> 'F'
6954            AND l_validate_itmin_result <> 'F' AND l_validate_itmfacin_result <> 'F' AND l_validate_itmfacin_result2 <> 'F' THEN
6955                    x_group_id  := p_group_tab(j).line_group_id;
6956                    x_found     := TRUE;
6957                    EXIT; -- exit out of target group loop
6958                          -- as input delivery will belong to this group
6959         END IF;
6960 
6961         <<grp_nextpass>>
6962 
6963         EXIT WHEN j= p_group_tab.LAST;
6964         j:= p_group_tab.NEXT(j);
6965 
6966       END LOOP;
6967     END IF;
6968 
6969     --
6970     IF l_debug_on THEN
6971       WSH_DEBUG_SV.pop(l_module_name);
6972     END IF;
6973     --
6974 
6975 EXCEPTION
6976     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
6977       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
6978       --
6979       IF l_debug_on THEN
6980         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
6981         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
6982       END IF;
6983       --
6984     WHEN others THEN
6985       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.search_matching_group');
6986       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
6987       --
6988       IF l_debug_on THEN
6989         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
6990         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
6991       END IF;
6992       --
6993 END search_matching_group;
6994 
6995 
6996 PROCEDURE check_dleg_discretionary(
6997                  p_entity_type         IN VARCHAR2,
6998                  p_entity_id           IN NUMBER,
6999                  p_delivery_rec        IN delivery_ccinfo_rec_type,
7000                  p_comp_class_tab      IN WSH_UTIL_CORE.column_tab_type,
7001                  p_dleg_pick_up_loc_id  IN NUMBER,
7002                  p_dleg_drop_off_loc_id IN NUMBER,
7003                  p_dleg_pick_up_stop_id  IN NUMBER DEFAULT NULL,
7004                  p_dleg_drop_off_stop_id  IN NUMBER DEFAULT NULL,
7005                  p_detail_tab            IN detail_ccinfo_tab_type,
7006                  p_carrier               IN NUMBER,
7007                  p_mode                  IN VARCHAR2,
7008                  p_vehicle_type          IN NUMBER DEFAULT NULL,
7009                  x_failed_constraints  IN OUT NOCOPY line_constraint_tab_type,
7010                  x_validate_result     OUT NOCOPY VARCHAR2,
7011                  x_return_status       OUT NOCOPY VARCHAR2)
7012 IS
7013 
7014     j                           NUMBER := 0;
7015     i                           NUMBER := 0;
7016     l_return_status             VARCHAR2(1);
7017     l_facility_id               NUMBER := 0;
7018     l_stop_id                   NUMBER := 0;
7019     l_failed_constraint         line_constraint_rec_type;
7020     l_validate_orgfac_result    VARCHAR2(1) := 'S';
7021     l_validate_cusfac_result    VARCHAR2(1) := 'S';
7022     l_validate_supfac_result    VARCHAR2(1) := 'S';
7023     l_validate_result           VARCHAR2(1) := 'S';
7024     l_physical_location_id      NUMBER := NULL;
7025     l_validate_itmfac_result    VARCHAR2(1) := 'S';
7026     l_validate_itmcar_result    VARCHAR2(1) := 'S';
7027     l_validate_itmveh_result    VARCHAR2(1) := 'S';
7028     l_validate_itmmod_result    VARCHAR2(1) := 'S';
7029 
7030     l_debug_on                  CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
7031     l_module_name               CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'check_dleg_discretionary';
7032 
7033 BEGIN
7034 
7035     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
7036     x_validate_result := 'S';
7037 
7038     IF l_debug_on THEN
7039         wsh_debug_sv.push(l_module_name);
7040     END IF;
7041 
7042     -- ORG - FAC, CUS - FAC for delivery's org/cus against dleg's locations if sequence number
7043     --           of the dleg is non first/last in the delivery
7044     -- Not possible to check Inclusive constraint here
7045     -- as do not know all other stops
7046     -- sequence number is present but inclusive constraints are checked at the trip level only
7047 
7048     -- Supplier - Facility
7049 
7050        IF p_comp_class_tab.EXISTS(G_SHIPORG_FACILITY_NUM) AND
7051             p_delivery_rec.shipment_direction <> 'D' THEN
7052          -- Also need to check for constraints which have been defined for
7053          -- all facilities of a company
7054 
7055          --IF p_dleg_pick_up_loc_id IS NOT NULL AND p_dleg_pick_up_stop_id IS NULL AND
7056          IF p_dleg_pick_up_loc_id IS NOT NULL AND
7057             p_delivery_rec.initial_pickup_location_id <> p_dleg_pick_up_loc_id AND
7058             p_delivery_rec.ultimate_dropoff_location_id <> p_dleg_pick_up_loc_id THEN
7059 
7060            validate_constraint(   --  checks only negative constraints
7061              p_comp_class_code          =>      G_SHIPORG_FACILITY,
7062              p_object2_type             =>      'FAC',
7063              p_object1_val_num          =>      p_delivery_rec.organization_id,
7064              p_object2_val_num          =>      p_dleg_pick_up_loc_id,
7065              x_validate_result          =>      l_validate_orgfac_result,
7066              x_failed_constraint        =>      l_failed_constraint,
7067              x_return_status            =>      l_return_status);
7068 
7069            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7070               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
7071                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
7072               END IF;
7073            END IF;
7074 
7075            IF l_validate_orgfac_result <> 'S' THEN
7076               l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
7077               l_failed_constraint.entity_type :=  p_entity_type;
7078               l_failed_constraint.entity_line_id := p_entity_id;
7079               x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
7080               IF l_validate_orgfac_result = 'E' THEN
7081                x_validate_result := 'F';
7082                l_validate_result := 'F';
7083               END IF;
7084            END IF;
7085 
7086          END IF;
7087 
7088          --IF p_dleg_drop_off_loc_id IS NOT NULL AND p_dleg_drop_off_stop_id IS NULL AND
7089          IF p_dleg_drop_off_loc_id IS NOT NULL AND
7090             p_delivery_rec.ultimate_dropoff_location_id <> p_dleg_drop_off_loc_id AND
7091             p_delivery_rec.initial_pickup_location_id <> p_dleg_drop_off_loc_id THEN
7092 
7093            validate_constraint(   --  checks only negative constraints
7094              p_comp_class_code          =>      G_SHIPORG_FACILITY,
7095              p_object2_type             =>      'FAC',
7096              p_object1_val_num          =>      p_delivery_rec.organization_id,
7097              p_object2_val_num          =>      p_dleg_drop_off_loc_id,
7098              x_validate_result          =>      l_validate_orgfac_result,
7099              x_failed_constraint        =>      l_failed_constraint,
7100              x_return_status            =>      l_return_status);
7101 
7102            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7103               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
7104                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
7105               END IF;
7106            END IF;
7107 
7108            IF l_validate_orgfac_result <> 'S' THEN
7109               l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
7110               l_failed_constraint.entity_type :=  p_entity_type;
7111               l_failed_constraint.entity_line_id := p_entity_id;
7112               x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
7113               IF l_validate_orgfac_result = 'E' THEN
7114                x_validate_result := 'F';
7115                l_validate_result := 'F';
7116               END IF;
7117            END IF;
7118 
7119          END IF; -- p_delivery_rec.ultimate_dropoff_location_id
7120 
7121        END IF;
7122 
7123          -- CUS_FAC : for customer facility ie. ship to location as param1 as well
7124        IF p_comp_class_tab.EXISTS(G_CUSTOMER_FACILITY_NUM) AND
7125             p_delivery_rec.shipment_direction <> 'I' THEN
7126 
7127          FOR i IN 1..2 LOOP
7128 
7129            IF i = 1 THEN
7130               l_facility_id := p_dleg_pick_up_loc_id;
7131               l_stop_id := p_dleg_pick_up_stop_id;
7132            ELSE
7133               l_facility_id := p_dleg_drop_off_loc_id;
7134               l_stop_id := p_dleg_drop_off_stop_id;
7135            END IF;
7136 
7137            --IF l_facility_id IS NOT NULL AND l_stop_id IS NULL AND
7138            IF l_facility_id IS NOT NULL AND
7139               p_delivery_rec.initial_pickup_location_id <> l_facility_id AND p_delivery_rec.ultimate_dropoff_location_id <> l_facility_id THEN
7140              IF p_delivery_rec.customer_id IS NOT NULL THEN
7141 
7142                    validate_constraint(   --  checks only negative constraints
7143                      p_comp_class_code          =>      G_CUSTOMER_FACILITY,
7144                      p_object1_type             =>      'CUS',
7145                      p_object2_type             =>      'FAC',
7146                      p_object1_val_num          =>      p_delivery_rec.customer_id,
7147                      p_object2_val_num          =>      l_facility_id,
7148                      x_validate_result          =>      l_validate_cusfac_result,
7149                      x_failed_constraint        =>      l_failed_constraint,
7150                      x_return_status            =>      l_return_status);
7151 
7152                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7153                       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
7154                          raise FND_API.G_EXC_UNEXPECTED_ERROR;
7155                       END IF;
7156                    END IF;
7157 
7158                    IF l_validate_cusfac_result <> 'S' THEN
7159                       l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
7160                       l_failed_constraint.entity_type :=  p_entity_type;
7161                       l_failed_constraint.entity_line_id := p_entity_id;
7162                       x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
7163                       IF l_validate_cusfac_result = 'E' THEN
7164                        x_validate_result := 'F';
7165                        l_validate_result := 'F';
7166                       END IF;
7167                    END IF;
7168              END IF; -- p_delivery_rec.customer_id IS NOT NULL
7169 
7170              IF p_delivery_rec.ultimate_dropoff_location_id IS NOT NULL THEN
7171 
7172                    validate_constraint(   --  checks only negative constraints
7173                      p_comp_class_code          =>      G_CUSTOMER_FACILITY,
7174                      p_object1_type             =>      'FAC',
7175                      p_object2_type             =>      'FAC',
7176                      p_object1_val_num          =>      p_delivery_rec.ultimate_dropoff_location_id,
7177                      p_object1_physical_id      =>      p_delivery_rec.physical_dropoff_location_id,
7178                      p_object2_val_num          =>      l_facility_id,
7179                      x_validate_result          =>      l_validate_cusfac_result,
7180                      x_failed_constraint        =>      l_failed_constraint,
7181                      x_return_status            =>      l_return_status);
7182 
7183                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7184                       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
7185                          raise FND_API.G_EXC_UNEXPECTED_ERROR;
7186                       END IF;
7187                    END IF;
7188 
7189 
7190                    IF l_validate_cusfac_result <> 'S' THEN
7191                       l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
7192                       l_failed_constraint.entity_type :=  p_entity_type;
7193                       l_failed_constraint.entity_line_id := p_entity_id;
7194                       x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
7195                       IF l_validate_cusfac_result = 'E' THEN
7196                        x_validate_result := 'F';
7197                        l_validate_result := 'F';
7198                       END IF;
7199                    END IF;
7200              END IF; -- p_delivery_rec.ULTIMATE_DROPOFF_LOCATION_ID IS NOT NULL
7201             END IF;  -- p_delivery_rec.ultimate_dropoff_location_id
7202 
7203          END LOOP;
7204 
7205        END IF; -- G_CUSTOMER_FACILITY
7206 
7207        IF p_comp_class_tab.EXISTS(G_SUPPLIER_FACILITY_NUM) AND
7208             p_delivery_rec.shipment_direction <> 'O' THEN
7209 
7210          FOR i IN 1..2 LOOP
7211 
7212            IF i = 1 THEN
7213               l_facility_id := p_dleg_pick_up_loc_id;
7214               l_stop_id := p_dleg_pick_up_stop_id;
7215            ELSE
7216               l_facility_id := p_dleg_drop_off_loc_id;
7217               l_stop_id := p_dleg_drop_off_stop_id;
7218            END IF;
7219 
7220            --IF l_facility_id IS NOT NULL AND l_stop_id IS NULL AND
7221            IF l_facility_id IS NOT NULL AND
7222               p_delivery_rec.initial_pickup_location_id <> l_facility_id AND p_delivery_rec.ultimate_dropoff_location_id <> l_facility_id THEN
7223              IF p_delivery_rec.party_id IS NOT NULL THEN
7224 
7225                    validate_constraint(   --  checks only negative constraints
7226                      p_comp_class_code          =>      G_SUPPLIER_FACILITY,
7227                      p_object1_type             =>      'SUP',
7228                      p_object2_type             =>      'FAC',
7229                      p_object1_val_num          =>      p_delivery_rec.party_id,
7230                      p_object2_val_num          =>      l_facility_id,
7231                      x_validate_result          =>      l_validate_supfac_result,
7232                      x_failed_constraint        =>      l_failed_constraint,
7233                      x_return_status            =>      l_return_status);
7234 
7235                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7236                       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
7237                          raise FND_API.G_EXC_UNEXPECTED_ERROR;
7238                       END IF;
7239                    END IF;
7240 
7241 
7242                    IF l_validate_supfac_result <> 'S' THEN
7243                       l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
7244                       l_failed_constraint.entity_type :=  p_entity_type;
7245                       l_failed_constraint.entity_line_id := p_entity_id;
7246                       x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
7247                       IF l_validate_supfac_result = 'E' THEN
7248                        x_validate_result := 'F';
7249                        l_validate_result := 'F';
7250                       END IF;
7251                    END IF;
7252              END IF; -- p_delivery_rec.party_id IS NOT NULL
7253 
7254              IF p_delivery_rec.initial_pickup_location_id IS NOT NULL THEN
7255 
7256                    validate_constraint(   --  checks only negative constraints
7257                      p_comp_class_code          =>      G_SUPPLIER_FACILITY,
7258                      p_object1_type             =>      'FAC',
7259                      p_object2_type             =>      'FAC',
7260                      p_object1_val_num          =>      p_delivery_rec.initial_pickup_location_id,
7261                      p_object2_val_num          =>      l_facility_id,
7262                      x_validate_result          =>      l_validate_supfac_result,
7263                      x_failed_constraint        =>      l_failed_constraint,
7264                      x_return_status            =>      l_return_status);
7265 
7266                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7267                       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
7268                          raise FND_API.G_EXC_UNEXPECTED_ERROR;
7269                       END IF;
7270                    END IF;
7271 
7272                    IF l_validate_supfac_result <> 'S' THEN
7273                       l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
7274                       l_failed_constraint.entity_type :=  p_entity_type;
7275                       l_failed_constraint.entity_line_id := p_entity_id;
7276                       x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
7277                       IF l_validate_supfac_result = 'E' THEN
7278                        x_validate_result := 'F';
7279                        l_validate_result := 'F';
7280                       END IF;
7281                    END IF;
7282              END IF; -- p_delivery_rec.initial_pickup_location_id IS NOT NULL
7283            END IF;  -- p_delivery_rec.ultimate_dropoff_location_id
7284 
7285          END LOOP;
7286 
7287        END IF; -- G_SUPPLIER_FACILITY
7288 
7289             -- TODOAG (DONE)
7290             -- check p_delivery_rec 's item against p_target_stops_info.pickup/dropoff_location_id
7291 	    -- only if it is not null and p_target_stops_info.pickup/dropoff_stop_id s have not been passed (null)
7292 
7293        -- LOOP over input items
7294        j := p_detail_tab.FIRST;
7295        IF j IS NOT NULL THEN
7296         LOOP
7297 
7298           IF  p_detail_tab(j).delivery_id <> p_delivery_rec.delivery_id THEN
7299              GOTO det_next;
7300           END IF;
7301 
7302 	  IF l_debug_on THEN
7303              WSH_DEBUG_SV.logmsg(l_module_name,'p_entity_type : '||p_entity_type);
7304           END IF;
7305 
7306 	    --SBAKSHI (ITM_FAC)
7307          --IF p_dleg_pick_up_loc_id IS NOT NULL AND p_dleg_pick_up_stop_id IS NULL AND
7308          IF p_dleg_pick_up_loc_id IS NOT NULL AND
7309             p_delivery_rec.initial_pickup_location_id <> p_dleg_pick_up_loc_id AND
7310             p_delivery_rec.ultimate_dropoff_location_id <> p_dleg_pick_up_loc_id THEN
7311 
7312 	      -- A new delivery leg is being created, We need to validate for ITM_FAC constraint
7313               -- for the new location ie  p_target_stops_info.pickup_location_id
7314 
7315                IF p_comp_class_tab.EXISTS(G_ITEM_FACILITY_NUM) THEN
7316 
7317 		 validate_constraint(   --  checks only negative constraints
7318                   p_comp_class_code          =>  G_ITEM_FACILITY,
7319                   p_object1_type             =>  'ITM',
7320                   p_object1_parent_id        =>  p_detail_tab(j).organization_id,
7321                   p_object1_val_num          =>  p_detail_tab(j).inventory_item_id,
7322                   p_object2_type             =>  'FAC',
7323                   p_object2_val_num          =>  p_dleg_pick_up_loc_id,
7324                   x_validate_result          =>  l_validate_itmfac_result,
7325                   x_failed_constraint        =>  l_failed_constraint,
7326                   x_return_status            =>  l_return_status);
7327 
7328                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7329                     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
7330                        raise FND_API.G_EXC_UNEXPECTED_ERROR;
7331                     END IF;
7332                   END IF;
7333 
7334                   IF l_validate_itmfac_result <> 'S' THEN
7335                       l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
7336                       l_failed_constraint.entity_type := G_DEL_DETAIL;
7337                       l_failed_constraint.entity_line_id := p_detail_tab(j).delivery_detail_id;
7338                       x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
7339 
7340 		    IF l_validate_itmfac_result = 'E' THEN
7341                        x_validate_result := 'F';
7342                        l_validate_result := 'F';
7343                     END IF;
7344                    END IF;
7345 
7346 		END IF;
7347 
7348 	      END IF;
7349 
7350          --IF p_dleg_drop_off_loc_id IS NOT NULL AND p_dleg_drop_off_stop_id IS NULL AND
7351          IF p_dleg_drop_off_loc_id IS NOT NULL AND
7352             p_delivery_rec.ultimate_dropoff_location_id <> p_dleg_drop_off_loc_id AND
7353             p_delivery_rec.initial_pickup_location_id <> p_dleg_drop_off_loc_id THEN
7354 
7355 		IF p_comp_class_tab.EXISTS(G_ITEM_FACILITY_NUM) THEN
7356 
7357 
7358 		  validate_constraint(   --  checks only negative constraints
7359                      p_comp_class_code          =>  G_ITEM_FACILITY,
7360                      p_object1_type             =>  'ITM',
7361                      p_object1_parent_id        =>  p_detail_tab(j).organization_id,
7362                      p_object1_val_num          =>  p_detail_tab(j).inventory_item_id,
7363                      p_object2_type             =>  'FAC',
7364                      p_object2_val_num          =>  p_dleg_drop_off_loc_id,
7365                      x_validate_result          =>  l_validate_itmfac_result,
7366                      x_failed_constraint        =>  l_failed_constraint,
7367                      x_return_status            =>  l_return_status);
7368 
7369                     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7370                       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
7371                          raise FND_API.G_EXC_UNEXPECTED_ERROR;
7372                       END IF;
7373                     END IF;
7374 
7375                  IF l_validate_itmfac_result <> 'S' THEN
7376                    l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
7377                    l_failed_constraint.entity_type := G_DEL_DETAIL;
7378                    l_failed_constraint.entity_line_id := p_detail_tab(j).delivery_detail_id;
7379                    x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
7380                    IF l_validate_itmfac_result = 'E' THEN
7381                       x_validate_result := 'F';
7382                       l_validate_result := 'F';
7383                    END IF;
7384                  END IF;
7385                END IF;
7386 
7387 	    END IF;
7388 
7389 	  --SBAKSHI (ITM_FAC)
7390 
7391           IF p_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) AND
7392              p_mode IS NOT NULL THEN
7393 
7394            validate_constraint(   --  checks only negative constraints
7395              p_comp_class_code          =>      G_ITEM_MODE,
7396              p_object1_type             =>      'ITM',
7397              p_object1_parent_id        =>      p_detail_tab(j).organization_id,
7398              p_object2_type             =>      'MOD',
7399              p_object1_val_num          =>      p_detail_tab(j).inventory_item_id,
7400              p_object2_val_char         =>      p_mode,
7401              x_validate_result          =>      l_validate_itmmod_result,
7402              x_failed_constraint        =>      l_failed_constraint,  -- id
7403              x_return_status            =>      l_return_status);
7404 
7405            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7406               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
7407                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
7408               END IF;
7409            END IF;
7410 
7411            IF l_validate_itmmod_result <> 'S' THEN
7412               l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
7413               l_failed_constraint.entity_type := G_DEL_DETAIL;
7414               l_failed_constraint.entity_line_id := p_detail_tab(j).delivery_detail_id;
7415               x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
7416               IF l_validate_itmmod_result = 'E' THEN
7417                  x_validate_result := 'F';
7418                  l_validate_result := 'F';
7419               END IF;
7420            END IF;
7421 
7422          END IF;
7423 
7424          IF p_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) AND
7425             p_carrier IS NOT NULL THEN
7426 
7427            validate_constraint(   --  checks only negative constraints
7428              p_comp_class_code          =>      G_ITEM_CARRIER,
7429              p_object1_type             =>      'ITM',
7430              p_object1_parent_id        =>      p_detail_tab(j).organization_id,
7431              p_object2_type             =>      'CAR',
7432              p_object1_val_num          =>      p_detail_tab(j).inventory_item_id,
7433              p_object2_val_num          =>      p_carrier,
7434              x_validate_result          =>      l_validate_itmcar_result,
7435              x_failed_constraint        =>      l_failed_constraint,  -- id
7436              x_return_status            =>      l_return_status);
7437 
7438            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7439               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
7440                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
7441               END IF;
7442            END IF;
7443 
7444            IF l_validate_itmcar_result <> 'S' THEN
7445               l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
7446               l_failed_constraint.entity_type := G_DEL_DETAIL;
7447               l_failed_constraint.entity_line_id := p_detail_tab(j).delivery_detail_id;
7448               x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
7449               IF l_validate_itmcar_result = 'E' THEN
7450                  x_validate_result := 'F';
7451                  l_validate_result := 'F';
7452               END IF;
7453            END IF;
7454 
7455          END IF;
7456 
7457          IF p_comp_class_tab.EXISTS(G_ITEM_VEHICLE_NUM) AND
7458             p_vehicle_type IS NOT NULL THEN
7459 
7460            validate_constraint(   --  checks only negative constraints
7461              p_comp_class_code          =>      G_ITEM_VEHICLE,
7462              p_object1_type             =>      'ITM',
7463              p_object1_parent_id        =>      p_detail_tab(j).organization_id,
7464              p_object2_type             =>      'VHT',
7465              p_object1_val_num          =>      p_detail_tab(j).inventory_item_id,
7466              p_object2_val_num          =>      p_vehicle_type,
7467              x_validate_result          =>      l_validate_itmveh_result,
7468              x_failed_constraint        =>      l_failed_constraint,  -- id
7469              x_return_status            =>      l_return_status);
7470 
7471            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7472               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
7473                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
7474               END IF;
7475            END IF;
7476 
7477            IF l_validate_itmveh_result <> 'S' THEN
7478               l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
7479               l_failed_constraint.entity_type := G_DEL_DETAIL;
7480               l_failed_constraint.entity_line_id := p_detail_tab(j).delivery_detail_id;
7481               x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
7482               IF l_validate_itmveh_result = 'E' THEN
7483                  x_validate_result := 'F';
7484                  l_validate_result := 'F';
7485               END IF;
7486            END IF;
7487 
7488          END IF;
7489 
7490          <<det_next>>
7491 
7492          EXIT WHEN j= p_detail_tab.LAST;
7493          j:= p_detail_tab.NEXT(j);
7494 
7495         END LOOP; -- p_detail_tab
7496         END IF;
7497 
7498 
7499     --
7500     IF l_debug_on THEN
7501       WSH_DEBUG_SV.pop(l_module_name);
7502     END IF;
7503     --
7504 
7505 EXCEPTION
7506     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
7507       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
7508       --
7509       IF l_debug_on THEN
7510         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
7511         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
7512       END IF;
7513       --
7514     WHEN others THEN
7515       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.check_dleg_discretionary');
7516       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
7517       --
7518       IF l_debug_on THEN
7519         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
7520         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
7521       END IF;
7522       --
7523 END check_dleg_discretionary;
7524 
7525 --***************************************************************************--
7526 --
7527 --========================================================================
7528 -- PROCEDURE : check_dlvy_against_trip    PRIVATE
7529 --
7530 -- PARAMETERS: p_entity_type              Entity for which check is running
7531 --             p_entity_id                Entity id for which check is running
7532 --             p_delivery_rec             Input delivery record
7533 --             p_detail_tab               Children detail records of input delivery record
7534 --             p_comp_class_tab           Table of Compatibility class codes to check
7535 --             p_target_stops_info        Input pickup and dropoff stop/location of the delivery(s)
7536 --                                        in the target trip in case of assign delivery to trip
7537 --             p_target_trip              Target trip record
7538 --             p_target_tripstops         Children stops already present in target trip
7539 --             p_target_dlvy              Childrent deliveries already present in target trip
7540 --             p_target_dlvy_lines        Childrent delivery details already present in target trip
7541 --             x_failed_constraints       Failed constraint table
7542 --             x_validate_result          Constraint Validation result : S / F
7543 --             x_return_status            Return status
7544 -- COMMENT   :
7545 -- For a given delivery and a target trip
7546 -- determines if the delivery can be assigned to the target trip
7547 -- satisfying exclusive constraints
7548 --========================================================================
7549 
7550 PROCEDURE check_dlvy_against_trip(
7551                  p_entity_type         IN VARCHAR2,
7552                  p_entity_id           IN NUMBER,
7553                  p_delivery_rec        IN delivery_ccinfo_rec_type,
7554                  p_detail_tab          IN detail_ccinfo_tab_type,
7555                  p_comp_class_tab      IN WSH_UTIL_CORE.column_tab_type,
7556                  p_target_stops_info   IN target_tripstop_cc_rec_type,
7557                  p_target_trip         IN trip_ccinfo_rec_type,
7558                  p_target_tripstops    IN stop_ccinfo_tab_type,
7559                  p_target_dlvy         IN delivery_ccinfo_tab_type,
7560                  p_target_dlvy_lines   IN detail_ccinfo_tab_type,
7561                  x_failed_constraints  IN OUT NOCOPY line_constraint_tab_type,
7562                  x_validate_result     OUT NOCOPY VARCHAR2,
7563                  x_return_status       OUT NOCOPY VARCHAR2)
7564 IS
7565 
7566     --SBAKSHI
7567     CURSOR c_get_pickup_dropoff_dates(p_delivery_id IN NUMBER, p_trip_id IN NUMBER) IS
7568     SELECT wts1.planned_arrival_date, wts2.planned_arrival_date
7569     FROM   wsh_trip_stops wts1, wsh_trip_stops wts2, wsh_delivery_legs wdl
7570     WHERE  wts1.trip_id = p_trip_id
7571     AND    wts2.trip_id = p_trip_id
7572     AND    wdl.delivery_id = p_delivery_id
7573     AND    wts1.stop_id = wdl.pick_up_stop_id
7574     AND    wts2.stop_id = wdl.drop_off_stop_id;
7575 
7576 
7577     l_checked_dlvb_cnt          NUMBER := 0;
7578     l_checked_dlvy_cnt          NUMBER := 0;
7579     z                           NUMBER := 0;
7580     j                           NUMBER := 0;
7581     k                           NUMBER := 0;
7582     l                           NUMBER := 0;
7583     m                           NUMBER := 0;
7584     l_inp_customer_id           NUMBER := 0;
7585     --#SBAKSHI(08/24)
7586     l_idx			NUMBER := 0;
7587     --#SBAKSHI(08/24)
7588     l_carrier                   NUMBER := NULL;
7589     l_location_id               NUMBER := NULL;
7590     l_vehicle_type              NUMBER := NULL;
7591     l_mode                      VARCHAR2(30) := NULL;
7592     l_service_level             VARCHAR2(30) := NULL;
7593     l_carrier_service_inout_rec WSH_CARRIERS_GRP.Carrier_Service_InOut_Rec_Type;
7594     l_inp_items_cnt             NUMBER := 0;
7595     l_const_count               NUMBER := 0;
7596     l_return_status             VARCHAR2(1);
7597     l_inp_dlvy_cus              BOOLEAN := TRUE;
7598     l_curr_dlvy_cus             BOOLEAN := TRUE;
7599     l_cusfac_checked            BOOLEAN := FALSE;
7600     l_supfac_checked            BOOLEAN := FALSE;
7601     l_checked_cus_fac           BOOLEAN := FALSE;
7602     l_cuscus_checked            BOOLEAN := FALSE;
7603     l_dlvycuscus_checked        BOOLEAN := FALSE;
7604     l_targetdlvy_cusfac_checked BOOLEAN := FALSE;
7605     l_targetdlvy_supfac_checked BOOLEAN := FALSE;
7606     l_validate_result           VARCHAR2(1) := 'S';
7607     l_validate_cuscus_result    VARCHAR2(1) := 'S';
7608     l_validate_carrier_result   VARCHAR2(1) := 'S';
7609     l_validate_vehicle_result   VARCHAR2(1) := 'S';
7610     l_validate_mode_result      VARCHAR2(1) := 'S';
7611     l_validate_orgfac_result    VARCHAR2(1) := 'S';
7612     l_validate_cusfac_result    VARCHAR2(1) := 'S';
7613     l_validate_supfac_result    VARCHAR2(1) := 'S';
7614     l_validate_itmfac_result    VARCHAR2(1) := 'S';
7615     l_failed_constraint         line_constraint_rec_type;
7616     l_validate_itmcar_result    VARCHAR2(1) := 'S';
7617     l_validate_itmveh_result    VARCHAR2(1) := 'S';
7618     l_validate_itmmod_result    VARCHAR2(1) := 'S';
7619     l_validate_itmin_result     VARCHAR2(1) := 'S';
7620     l_validate_itmfacin_result  VARCHAR2(1) := 'S';
7621     l_items_tab                 item_tab_type;
7622     l_locations_list            WSH_UTIL_CORE.id_tab_type;
7623     l_entity_rec                entity_rec_type;
7624     l_target_rec                entity_rec_type;
7625     l_pu_location_id            NUMBER := NULL;
7626     l_pu_sequencenum            NUMBER := NULL;
7627     l_pu_pa_date                DATE;
7628     l_do_location_id            NUMBER := NULL;
7629     l_do_sequencenum            NUMBER := NULL;
7630     l_do_pa_date                DATE;
7631     l_checked_inpdlvb           WSH_UTIL_CORE.id_tab_type;
7632     l_checked_target_dlvy       WSH_UTIL_CORE.id_tab_type;
7633 
7634     l_vehicle_name              VARCHAR2(2000);
7635     l_vehicle_org_name          VARCHAR2(240);
7636 
7637     l_input_pu_location_id      NUMBER := NULL;
7638     l_input_do_location_id      NUMBER := NULL;
7639     l_dleg_loc_id               NUMBER := NULL;
7640     p                           NUMBER := NULL;
7641 
7642 
7643     l_module_name               CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'check_dlvy_against_trip';
7644     l_debug_on                  CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
7645 
7646     --SBAKSHI
7647     l_trp_dlvy_pickup_date      DATE;
7648     l_trp_dlvy_dropoff_date	DATE;
7649 
7650     --SBAKSHI
7651 
7652 BEGIN
7653 
7654     -- for assign delivery to trip
7655     -- might not need to check against all stops of the target trip
7656 
7657     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
7658     x_validate_result := 'S';
7659 
7660     IF l_debug_on THEN
7661         wsh_debug_sv.push(l_module_name);
7662         WSH_DEBUG_SV.logmsg(l_module_name,'p_entity_type    '||p_entity_type);
7663 	WSH_DEBUG_SV.logmsg(l_module_name,'target_tripstop count '|| p_target_tripstops.COUNT);
7664         WSH_DEBUG_SV.logmsg(l_module_name,'target_dlvy count '|| p_target_dlvy.COUNT);
7665         WSH_DEBUG_SV.logmsg(l_module_name,'target_dlvy_lines count '|| p_target_dlvy_lines.COUNT);
7666         WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_rec.initial_pickup_location '|| p_delivery_rec.initial_pickup_location_id);
7667         WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_rec.ultimate_dropoff_location '|| p_delivery_rec.ultimate_dropoff_location_id);
7668         WSH_DEBUG_SV.logmsg(l_module_name,'p_target_stops_info.pickup_location_id '|| p_target_stops_info.pickup_location_id);
7669         WSH_DEBUG_SV.logmsg(l_module_name,'p_target_stops_info.dropoff_location_id '|| p_target_stops_info.dropoff_location_id);
7670     END IF;
7671 
7672          -- Here check the delivery against target trip for exclusive constraints
7673          -- com -fac, cus - fac, itm - fac for each delivery against trip stops
7674          -- Are we going to get planned stop sequence of pickup and dropoff stop of delivery
7675          -- itm -mod, itm - car and fac-mod, fac-car
7676          -- Need not check fac -car/mod if called for a dleg
7677          -- org - car, org - mode will not be stored in constraints table 11/6
7678          -- itm - itm, cus - cus
7679          -- Any delivery that is violating, remove from the group
7680 
7681      -- Check fac-mod, fac-car
7682      -- between p_delivery_rec and p_target_trip
7683     IF l_debug_on THEN
7684         WSH_DEBUG_SV.logmsg(l_module_name,'p_target_trip.carrier_id    '||p_target_trip.carrier_id);
7685         WSH_DEBUG_SV.logmsg(l_module_name,'p_target_trip.mode_of_transport    '||p_target_trip.mode_of_transport);
7686         WSH_DEBUG_SV.logmsg(l_module_name,'p_target_trip.ship_method_code    '||p_target_trip.ship_method_code);
7687     END IF;
7688 
7689     IF (p_target_trip.carrier_id IS NULL OR p_target_trip.mode_of_transport IS NULL) AND
7690          (p_target_trip.ship_method_code IS NOT NULL) THEN
7691 
7692       l_carrier_service_inout_rec.ship_method_code := p_target_trip.ship_method_code;
7693 
7694       WSH_CARRIERS_GRP.get_carrier_service_mode(
7695                p_carrier_service_inout_rec   =>  l_carrier_service_inout_rec,
7696                x_return_status               =>  l_return_status);
7697 
7698       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7699         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
7700          IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
7701             raise FND_API.G_EXC_UNEXPECTED_ERROR;
7702          END IF;
7703          raise g_get_carrmode_failed;
7704         END IF;
7705       END IF;
7706 
7707       l_carrier := l_carrier_service_inout_rec.carrier_id;
7708       l_mode    := l_carrier_service_inout_rec.mode_of_transport;
7709 
7710     END IF; -- p_target_trip.carrier_id IS NULL OR ..
7711 
7712       -- If carrier_id or mode is passed in, then those get preference for validation
7713       -- If they are not, they are derived from ship method if that is passed
7714 
7715     IF p_target_trip.carrier_id IS NOT NULL THEN
7716        l_carrier := p_target_trip.carrier_id;
7717     END IF;
7718     IF p_target_trip.MODE_OF_TRANSPORT IS NOT NULL THEN
7719        l_mode := p_target_trip.MODE_OF_TRANSPORT;
7720     END IF;
7721 
7722     IF (p_target_trip.VEHICLE_ITEM_ID IS NOT NULL AND p_target_trip.VEHICLE_ORGANIZATION_ID IS NOT NULL) THEN
7723 
7724       WSH_FTE_INTEGRATION.get_vehicle_type(
7725                p_vehicle_item_id     =>  p_target_trip.VEHICLE_ITEM_ID,
7726                p_vehicle_org_id      =>  p_target_trip.VEHICLE_ORGANIZATION_ID,
7727                x_vehicle_type_id     =>  l_vehicle_type,
7728                x_return_status       =>  l_return_status);
7729 
7730       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7731          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
7732          IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
7733             raise FND_API.G_EXC_UNEXPECTED_ERROR;
7734          END IF;
7735             l_vehicle_name := WSH_UTIL_CORE.get_item_name (p_item_id => p_target_trip.VEHICLE_ITEM_ID,
7736                                                            p_organization_id => p_target_trip.VEHICLE_ORGANIZATION_ID);
7737             l_vehicle_org_name := WSH_UTIL_CORE.get_org_name (p_organization_id => p_target_trip.VEHICLE_ORGANIZATION_ID);
7738             FND_MESSAGE.SET_NAME('WSH','WSH_VEHICLE_TYPE_UNDEFINED');
7739             FND_MESSAGE.SET_TOKEN('ITEM',l_vehicle_name);
7740             FND_MESSAGE.SET_TOKEN('ORGANIZATION',l_vehicle_org_name);
7741             FND_MSG_PUB.ADD;
7742             --raise g_get_vehicletype_failed;
7743          END IF;
7744       END IF;
7745 
7746     END IF; -- p_target_trip.VEHICLE_ITEM_ID IS NOT NULL AND ..
7747 
7748     -- When the code comes here,
7749     -- for DLVY, only pickup/dropoff stop/location NULL case needs to be
7750     -- taken care of for facility - car/mod/veh
7751     -- for DLEG, it never needs to be checked
7752     -- dleg trip search will find any trip having either dleg pu loc OR do loc
7753     -- Hence should do fac-car/mod/veh check if a stop not already exists
7754     -- in the target trip with that location
7755 
7756     -- Even when pickup/drop off stop ids are null,
7757     -- the delivery's initial pu/ultimate do stops might already
7758     -- exist in the target trip
7759 
7760     IF p_target_stops_info.pickup_stop_id IS NOT NULL THEN
7761 
7762          OPEN c_get_stop_location(p_target_stops_info.pickup_stop_id);
7763          FETCH c_get_stop_location INTO l_pu_location_id,l_pu_sequencenum,l_pu_pa_date;
7764          CLOSE c_get_stop_location;
7765 
7766          IF l_debug_on THEN
7767             WSH_DEBUG_SV.logmsg(l_module_name,'l_pu_location_id    '||l_pu_location_id);
7768             WSH_DEBUG_SV.logmsg(l_module_name,'l_pu_sequencenum    '||l_pu_sequencenum);
7769             WSH_DEBUG_SV.logmsg(l_module_name,'l_pu_pa_date    '||l_pu_pa_date);
7770         END IF;
7771 
7772     ELSIF p_target_stops_info.pickup_location_id IS NOT NULL THEN
7773 
7774        l_pu_location_id := p_target_stops_info.pickup_location_id;
7775        --IF p_entity_type <> 'DLEG' THEN
7776        --IF p_target_stops_info.pickup_stop_seq IS NOT NULL THEN
7777        IF p_target_stops_info.pickup_stop_pa_date IS NOT NULL THEN
7778          l_pu_pa_date := p_target_stops_info.pickup_stop_pa_date;
7779          l_pu_sequencenum := p_target_stops_info.pickup_stop_seq;
7780        ELSE
7781 
7782          -- p_target_stops_info.pickup_location_id has to be a stop location of this trip
7783          -- for the input delivery leg to match this trip  HB 07/01/03
7784          -- we need to consider all stop locations after that stop location
7785          OPEN c_get_stop(p_target_stops_info.pickup_location_id,p_target_trip.trip_id);
7786          FETCH c_get_stop INTO l_pu_sequencenum,l_pu_pa_date;
7787          CLOSE c_get_stop;
7788 
7789          IF l_debug_on THEN
7790             WSH_DEBUG_SV.logmsg(l_module_name,'l_pu_location_id 11    '||p_target_stops_info.pickup_location_id);
7791             WSH_DEBUG_SV.logmsg(l_module_name,'l_pu_sequencenum 11   '||l_pu_sequencenum);
7792             WSH_DEBUG_SV.logmsg(l_module_name,'l_pu_pa_date  11  '||l_pu_pa_date);
7793         END IF;
7794 
7795        END IF;
7796 
7797     ELSIF p_target_stops_info.pickup_stop_id IS NULL THEN
7798        -- check if delivery's initial pu location id already exists
7799        -- in target trip
7800          OPEN c_get_stop(p_delivery_rec.initial_pickup_location_id,p_target_trip.trip_id);
7801          FETCH c_get_stop INTO l_pu_sequencenum,l_pu_pa_date;
7802          IF l_debug_on THEN
7803             WSH_DEBUG_SV.logmsg(l_module_name,'rowcount c_get_stop : '|| c_get_stop%rowcount ||' for deliverys initial pu : '||p_delivery_rec.initial_pickup_location_id);
7804          END IF;
7805          CLOSE c_get_stop;
7806 
7807     END IF;
7808 
7809     IF p_target_stops_info.dropoff_stop_id IS NOT NULL THEN
7810 
7811          OPEN c_get_stop_location(p_target_stops_info.dropoff_stop_id);
7812          FETCH c_get_stop_location INTO l_do_location_id,l_do_sequencenum,l_do_pa_date;
7813          CLOSE c_get_stop_location;
7814 
7815     ELSIF p_target_stops_info.dropoff_location_id IS NOT NULL THEN
7816 
7817        l_do_location_id := p_target_stops_info.dropoff_location_id;
7818        --IF p_entity_type <> 'DLEG' THEN
7819        --IF p_target_stops_info.dropoff_stop_seq IS NOT NULL THEN
7820        IF p_target_stops_info.dropoff_stop_pa_date IS NOT NULL THEN
7821          l_do_pa_date := p_target_stops_info.dropoff_stop_pa_date;
7822          l_do_sequencenum := p_target_stops_info.dropoff_stop_seq;
7823        ELSE
7824          OPEN c_get_stop(p_target_stops_info.dropoff_location_id,p_target_trip.trip_id);
7825          FETCH c_get_stop INTO l_do_sequencenum,l_do_pa_date;
7826          CLOSE c_get_stop;
7827 
7828        END IF;
7829 
7830     ELSIF p_target_stops_info.dropoff_stop_id IS NULL THEN
7831        -- check if delivery's ultimate do location id already exists
7832        -- in target trip
7833          OPEN c_get_stop(p_delivery_rec.ultimate_dropoff_location_id,p_target_trip.trip_id);
7834          FETCH c_get_stop INTO l_do_sequencenum,l_do_pa_date;
7835          IF l_debug_on THEN
7836             WSH_DEBUG_SV.logmsg(l_module_name,'rowcount c_get_stop : '|| c_get_stop%rowcount ||' for deliverys ultimate do : '||p_delivery_rec.ultimate_dropoff_location_id);
7837          END IF;
7838          CLOSE c_get_stop;
7839     END IF;
7840 
7841     -- TODOAG
7842     -- check p_delivery_rec 's org/cus/sup against p_target_stops_info.pickup/dropoff_location_id
7843     -- only if it is not null and p_target_stops_info.pickup/dropoff_stop_id s have not been passed (null)
7844     -- the following check only applies to dleg creation from WSH
7845     -- for assign del to trip from FTE, this check is not required as there
7846     -- the check is already performed at the dleg creation time
7847     IF l_debug_on THEN
7848         WSH_DEBUG_SV.logmsg(l_module_name, 'p_entity_type: '||p_entity_type);
7849     END IF;
7850     IF p_entity_type <> 'DLEG' THEN
7851 
7852        check_dleg_discretionary(
7853                  p_entity_type           => G_DELIVERY,
7854                  p_entity_id             => p_delivery_rec.delivery_id,
7855                  p_delivery_rec          => p_delivery_rec,
7856                  p_comp_class_tab        => p_comp_class_tab,
7857                  p_dleg_pick_up_loc_id   => p_target_stops_info.pickup_location_id,
7858                  p_dleg_drop_off_loc_id  => p_target_stops_info.dropoff_location_id,
7859                  p_dleg_pick_up_stop_id  => p_target_stops_info.pickup_stop_id,
7860                  p_dleg_drop_off_stop_id => p_target_stops_info.dropoff_stop_id,
7861                  p_detail_tab            => p_detail_tab,
7862                  p_carrier               => l_carrier,
7863                  p_mode                  => l_mode,
7864                  p_vehicle_type          => l_vehicle_type,
7865                  x_failed_constraints    => x_failed_constraints,
7866                  x_validate_result       => l_validate_result,
7867                  x_return_status         => l_return_status);
7868 
7869        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7870               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
7871                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
7872               END IF;
7873        END IF;
7874 
7875        IF l_debug_on THEN
7876         WSH_DEBUG_SV.logmsg(l_module_name,'l_pu_sequencenum '|| l_pu_sequencenum||' l_do_sequencenum '||l_do_sequencenum);
7877         WSH_DEBUG_SV.logmsg(l_module_name,'l_pu_pa_date '|| to_char(l_pu_pa_date,'DD-MON-YYYY HH24:MI:SS')||' l_do_pa_date '||to_char(l_do_pa_date,'DD-MON-YYYY HH24:MI:SS'));
7878        END IF;
7879     END IF;
7880 
7881 
7882     FOR i IN 1..2 LOOP
7883 
7884         -- Do the checks in calling procedure if pickup/dropoff stop/location ids have been passed
7885 
7886         IF i = 1 THEN
7887 
7888 	   IF p_target_stops_info.pickup_stop_id IS NULL AND
7889               l_pu_sequencenum IS NULL AND -- To take care if stop already existed
7890               p_target_stops_info.pickup_location_id IS NULL THEN
7891                 l_location_id := p_delivery_rec.initial_pickup_location_id;
7892            ELSE
7893               -- Nothing to check
7894 		GOTO next_pass;
7895 	   END IF;
7896         ELSIF i = 2 THEN
7897            IF p_target_stops_info.dropoff_stop_id IS NULL AND
7898               l_do_sequencenum IS NULL AND
7899               p_target_stops_info.dropoff_location_id IS NULL THEN
7900                 l_location_id := p_delivery_rec.ultimate_dropoff_location_id;
7901 
7902 	   ELSE
7903                 -- Nothing to check
7904                 GOTO next_pass;
7905            END IF;
7906         END IF;
7907 
7908         IF p_comp_class_tab.EXISTS(G_FACILITY_VEHICLE_NUM) AND
7909             p_entity_type <> 'DLEG' AND
7910             l_vehicle_type IS NOT NULL THEN
7911 
7912             validate_constraint(
7913              p_comp_class_code          =>      G_FACILITY_VEHICLE,
7914              p_object1_type             =>      'FAC',
7915              p_object1_val_num          =>      l_location_id,
7916              p_object2_type             =>      'VHT',
7917              p_object2_val_num          =>      l_vehicle_type,
7918              x_validate_result          =>      l_validate_vehicle_result,
7919              x_failed_constraint        =>      l_failed_constraint,
7920              x_return_status            =>      l_return_status);
7921 
7922             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7923                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
7924                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
7925                END IF;
7926             END IF;
7927 
7928             IF l_validate_vehicle_result <> 'S' THEN
7929               l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
7930               l_failed_constraint.entity_type := p_entity_type;
7931               l_failed_constraint.entity_line_id := p_entity_id;
7932               x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
7933               IF l_validate_vehicle_result = 'E' THEN
7934                l_validate_result := 'F';
7935               END IF;
7936             END IF;
7937         END IF;
7938 
7939         IF p_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) AND
7940             p_entity_type <> 'DLEG' AND
7941             l_carrier IS NOT NULL THEN
7942 
7943             validate_constraint(
7944              p_comp_class_code          =>      G_FACILITY_CARRIER,
7945              p_object1_type             =>      'FAC',
7946              p_object1_val_num          =>      l_location_id,
7947              p_object2_type             =>      'CAR',
7948              p_object2_val_num          =>      l_carrier,
7949              x_validate_result          =>      l_validate_carrier_result,
7950              x_failed_constraint        =>      l_failed_constraint,
7951              x_return_status            =>      l_return_status);
7952 
7953             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7954                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
7955                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
7956                END IF;
7957             END IF;
7958 
7959             IF l_validate_carrier_result <> 'S' THEN
7960               l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
7961               l_failed_constraint.entity_type := p_entity_type;
7962               l_failed_constraint.entity_line_id := p_entity_id;
7963               x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
7964               IF l_validate_carrier_result = 'E' THEN
7965                l_validate_result := 'F';
7966               END IF;
7967             END IF;
7968 	END IF;
7969 
7970         IF p_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) AND
7971             p_entity_type <> 'DLEG' AND
7972             l_mode IS NOT NULL THEN
7973 
7974             validate_constraint(
7975              p_comp_class_code          =>      G_FACILITY_MODE,
7976              p_object1_type             =>      'FAC',
7977              p_object1_val_num          =>      l_location_id,
7978              p_object2_type             =>      'MOD',
7979              p_object2_val_char          =>     l_mode,
7980              x_validate_result          =>      l_validate_mode_result,
7981              x_failed_constraint        =>      l_failed_constraint,
7982              x_return_status            =>      l_return_status);
7983 
7984             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
7985                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
7986                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
7987                END IF;
7988             END IF;
7989 
7990             IF l_validate_mode_result <> 'S' THEN
7991               l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
7992               l_failed_constraint.entity_type := p_entity_type;
7993               l_failed_constraint.entity_line_id := p_entity_id;
7994               x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
7995               IF l_validate_mode_result = 'E' THEN
7996                l_validate_result := 'F';
7997               END IF;
7998             END IF;
7999 
8000         END IF;
8001 
8002     <<next_pass>>
8003     null;
8004 
8005     END LOOP;
8006 
8007 
8008 
8009 -- AGMULT
8010 -- comment out only discretionary routing point checks inside the loop
8011 -- not everything inside the loop
8012 
8013     --LOOP  -- Over Trip stops
8014     k := p_target_tripstops.FIRST;
8015 
8016     IF k IS NOT NULL THEN
8017 
8018      LOOP
8019 
8020       l_locations_list.DELETE;
8021       l_items_tab.DELETE;
8022 
8023       IF l_debug_on THEN
8024         WSH_DEBUG_SV.logmsg(l_module_name,'target_tripstop id '|| p_target_tripstops(k).stop_id||' target_tripstop sequence '||p_target_tripstops(k).stop_sequence_number||' arriv date '||p_target_tripstops(k).planned_arrival_date);
8025         WSH_DEBUG_SV.logmsg(l_module_name,'target_tripstop location_id '|| p_target_tripstops(k).stop_location_id||' target_tripstop physical_location_id :'||p_target_tripstops(k).physical_location_id);
8026       END IF;
8027 
8028        --LOOP  -- Over p_detail_tab
8029       j := p_detail_tab.FIRST;
8030       IF j IS NOT NULL THEN
8031         LOOP
8032 
8033          IF  p_detail_tab(j).delivery_id <> p_delivery_rec.delivery_id THEN
8034              GOTO inpdet_nextpass;
8035          END IF;
8036 
8037          l_inp_customer_id := NULL;
8038          IF p_delivery_rec.customer_id IS NOT NULL THEN
8039              l_inp_customer_id := p_delivery_rec.customer_id;
8040          ELSIF p_detail_tab(j).customer_id IS NOT NULL THEN
8041               l_inp_customer_id := p_detail_tab(j).customer_id;
8042          END IF;
8043 
8044          IF ( p_comp_class_tab.EXISTS(G_CUSTOMER_CUSTOMER_NUM) AND
8045              l_inp_customer_id IS NOT NULL AND
8046              NOT l_dlvycuscus_checked) OR
8047              ( p_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) OR
8048                p_comp_class_tab.EXISTS(G_ITEM_VEHICLE_NUM) OR
8049                p_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) ) THEN
8050           --LOOP  -- Over p_target_dlvy
8051 
8052 	 l := p_target_dlvy.FIRST;
8053          IF l IS NOT NULL THEN
8054           LOOP
8055 
8056                 -- Skip this delivery if already checked
8057 
8058                 IF entity_exists(p_target_dlvy(l).delivery_id,l_checked_target_dlvy,z) THEN
8059                 --IF l_checked_target_dlvy.EXISTS(p_target_dlvy(l).delivery_id) THEN
8060                    GOTO next_target_dlvy;
8061                 END IF;
8062 
8063           	-- SBAKSHI (TODOAG)
8064 		-- Get the  planned arrival and depature date for the trip and the delivery.
8065 
8066 		-- TODOAG get these dates in one cursor
8067                 -- get planned arrival dates for both the stops as for stop sequencing that is used
8068 
8069 		-- Using one cursor.
8070 
8071 		OPEN c_get_pickup_dropoff_dates(p_target_dlvy(l).delivery_id,p_target_trip.trip_id);
8072 		FETCH c_get_pickup_dropoff_dates INTO l_trp_dlvy_pickup_date, l_trp_dlvy_dropoff_date;
8073 		CLOSE c_get_pickup_dropoff_dates;
8074 
8075 		l_checked_dlvy_cnt := l_checked_dlvy_cnt + 1;
8076                 l_checked_target_dlvy(l_checked_dlvy_cnt) := p_target_dlvy(l).delivery_id;
8077                 --l_checked_target_dlvy(p_target_dlvy(l).delivery_id) := p_target_dlvy(l).delivery_id;
8078 
8079                 l_cuscus_checked := FALSE;
8080                 l_validate_cuscus_result := 'S';
8081                 -- cus - cus if customer is at p_delivery_rec level and  p_target_dlvy level
8082                 -- or customer is at p_detail_tab level and p_target_dlvy level
8083 
8084 		IF p_target_dlvy(l).customer_id IS NOT NULL AND
8085                  l_inp_customer_id <> p_target_dlvy(l).customer_id THEN
8086 
8087                   l_cuscus_checked := TRUE;
8088                   l_dlvycuscus_checked := TRUE;
8089 
8090 
8091               validate_constraint(   --  checks only negative constraints
8092                p_comp_class_code          =>      G_CUSTOMER_CUSTOMER,
8093                p_object1_type             =>      'CUS',
8094                p_object2_type             =>      'CUS',
8095                p_object1_val_num          =>      l_inp_customer_id,
8096                p_object2_val_num          =>      p_target_dlvy(l).customer_id,
8097                x_validate_result          =>      l_validate_cuscus_result,
8098                x_failed_constraint        =>      l_failed_constraint,  -- id
8099                x_return_status            =>      l_return_status);
8100 
8101               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
8102                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
8103                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
8104                  END IF;
8105               END IF;
8106 
8107               IF l_validate_cuscus_result <> 'S' THEN
8108                 l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
8109                 l_failed_constraint.entity_type := p_entity_type;
8110                 l_failed_constraint.entity_line_id := p_entity_id;
8111                 x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
8112                 IF l_validate_cuscus_result = 'E' THEN
8113                    l_validate_result := 'F';
8114                 END IF;
8115               END IF;
8116 
8117              END IF;
8118 
8119          -- also check the children deliveries of the target trip against input delivery leg's locations
8120          -- for exclusive org -fac, cus - fac, sup - fac, itm - fac
8121          -- p_target_dlvy against p_target_stops_info or p_delivery_rec
8122          -- If p_target_stops_info.pick_up_stop_id and/or p_target_stops_info.drop_off_stop_id is populated
8123          -- then the check for that location is not required
8124          -- ELSE if p_target_stops_info.pick_up_location_id and/or p_target_stops_info.drop_off_location_id is populated
8125          -- check against those locations
8126          -- ELSE check against p_delivery_rec 's locations
8127 
8128           -- TODOAG
8129           -- Check only if input delivery leg's locations lie between p_target_dlvy 's pickup and dropoff loc on
8130           -- p_target_trip
8131           -- following checks which use p_target_dlvy(l).initial_pickup/ultimate_dropoff_date to
8132           -- determine the intermediate loc is not correct
8133           -- for each p_target_dlvy(l), the leg pickup and dropoff date in the target trip p_target_trip should be
8134           -- obtained and then used for this check
8135           -- write a new cursor which gets the pickup and dropoff stop dates for
8136           -- the delivery leg of p_target_dlvy(l) in p_target_trip and use those dates instead
8137 
8138              l_input_pu_location_id := NULL;
8139              l_input_do_location_id := NULL;
8140 
8141 	     IF p_target_stops_info.pickup_stop_id IS NULL THEN
8142 
8143 		-- Check only when new stops will be created in the target trip
8144                 -- Here, We want to do this check only either p_target_stops_info.pickup_location_id is NOT NULL
8145                 -- OR p_target_stops_info.pickup_location_id is NULL and p_delivery_rec.initial_pickup_location_id
8146                 -- not already exists in the trip
8147 
8148                IF p_target_stops_info.pickup_location_id IS NOT NULL THEN
8149 
8150                 -- TODOAG
8151                 -- instead use the leg dates as obtained above using the new cursor
8152             --    IF (p_target_dlvy(l).initial_pickup_date < l_pu_pa_date AND
8153             --        p_target_dlvy(l).ultimate_dropoff_date > l_pu_pa_date ) THEN
8154 
8155 		 --sbakshi(TODOAG)
8156 
8157 		 IF ( l_trp_dlvy_pickup_date < l_pu_pa_date AND
8158                       l_trp_dlvy_dropoff_date > l_pu_pa_date ) THEN
8159 
8160                     -- Check p_target_dlvy 's org, cus, sup against p_target_stops_info.pickup_location_id
8161                     l_input_pu_location_id := p_target_stops_info.pickup_location_id;
8162 
8163                     IF l_debug_on THEN
8164                        WSH_DEBUG_SV.logmsg(l_module_name,'Checking p_target_dlvy against p_target_stops_info.pickup_location_id :'|| p_target_stops_info.pickup_location_id);
8165                     END IF;
8166 
8167                 END IF;
8168                ELSIF l_pu_pa_date IS NULL THEN
8169 
8170                 -- TODOAG
8171                 -- instead use the leg dates as obtained above using the new cursor
8172 --                IF (p_target_dlvy(l).initial_pickup_date < p_delivery_rec.initial_pickup_date AND
8173 --                    p_target_dlvy(l).ultimate_dropoff_date > p_delivery_rec.initial_pickup_date ) THEN
8174 
8175 		 --sbakshi(TODOAG)
8176 
8177 		 IF ( l_trp_dlvy_pickup_date < p_delivery_rec.initial_pickup_date AND
8178                       l_trp_dlvy_dropoff_date > p_delivery_rec.initial_pickup_date ) THEN
8179 
8180 
8181                     -- Check p_target_dlvy 's org, cus, sup against p_delivery_rec.initial_pickup_location_id
8182                     l_input_pu_location_id := p_delivery_rec.initial_pickup_location_id;
8183 
8184                     IF l_debug_on THEN
8185                        WSH_DEBUG_SV.logmsg(l_module_name,'Checking p_target_dlvy against p_delivery_rec.initial_pickup_location_id :'|| p_delivery_rec.initial_pickup_location_id);
8186                     END IF;
8187 
8188                 END IF;
8189                END IF;
8190              END IF;
8191 
8192              IF p_target_stops_info.dropoff_stop_id IS NULL THEN
8193                 -- Here, We want to do this check only either p_target_stops_info.dropoff_location_id is NOT NULL
8194                 -- OR p_target_stops_info.dropoff_location_id is NULL and p_delivery_rec.ultimate_dropoff_location_id
8195                 -- not already exists in the trip
8196 
8197                IF p_target_stops_info.dropoff_location_id IS NOT NULL THEN
8198 
8199                 -- TODOAG
8200                 -- instead use the leg dates as obtained above using the new cursor
8201 
8202 --		IF (p_target_dlvy(l).initial_pickup_date < l_do_pa_date AND
8203 --                    p_target_dlvy(l).ultimate_dropoff_date > l_do_pa_date ) THEN
8204 
8205 
8206 		--sbakshi(TODOAG)
8207 		IF (l_trp_dlvy_pickup_date  < l_do_pa_date AND
8208                     l_trp_dlvy_dropoff_date > l_do_pa_date ) THEN
8209 
8210 
8211                     -- Check p_target_dlvy 's org, cus, sup against p_target_stops_info.dropoff_location_id
8212                     l_input_do_location_id := p_target_stops_info.dropoff_location_id;
8213 
8214                     IF l_debug_on THEN
8215                        WSH_DEBUG_SV.logmsg(l_module_name,'Checking p_target_dlvy against p_target_stops_info.dropoff_location_id :'|| p_target_stops_info.dropoff_location_id);
8216                     END IF;
8217 
8218                 END IF;
8219                ELSIF l_do_pa_date IS NULL THEN
8220 
8221                 -- TODOAG
8222                 -- instead use the leg dates as obtained above using the new cursor
8223 
8224 --		IF (p_target_dlvy(l).initial_pickup_date < p_delivery_rec.ultimate_dropoff_date AND
8225 --                    p_target_dlvy(l).ultimate_dropoff_date > p_delivery_rec.ultimate_dropoff_date ) THEN
8226 
8227 		--sbakshi(TODOAG)
8228 		IF (l_trp_dlvy_pickup_date  < p_delivery_rec.ultimate_dropoff_date AND
8229                     l_trp_dlvy_dropoff_date > p_delivery_rec.ultimate_dropoff_date ) THEN
8230 
8231                     -- Check p_target_dlvy 's org, cus, sup against p_delivery_rec.ultimate_dropoff_location_id
8232                     l_input_do_location_id := p_delivery_rec.ultimate_dropoff_location_id;
8233 
8234                     IF l_debug_on THEN
8235                        WSH_DEBUG_SV.logmsg(l_module_name,'Checking p_target_dlvy against p_delivery_rec.ultimate_dropoff_location_id :'|| p_delivery_rec.ultimate_dropoff_location_id);
8236                     END IF;
8237                 END IF;
8238                END IF;
8239              END IF;
8240 
8241 	  --LOOP -- Over p_target_dlvy_lines for p_target_dlvy
8242           m := p_target_dlvy_lines.FIRST;
8243           IF m IS NOT NULL THEN
8244                 LOOP
8245 
8246                  IF  p_target_dlvy_lines(m).delivery_id <> p_target_dlvy(l).delivery_id THEN
8247                      GOTO tardet_nextpass;
8248                  END IF;
8249 
8250                      -- cus - cus if not already for this p_target_dlvy
8251                      -- against p_delivery_rec OR p_detail_tab level
8252 
8253                  IF p_target_dlvy_lines(m).customer_id IS NOT NULL AND
8254                      l_inp_customer_id <> p_target_dlvy_lines(m).customer_id AND
8255                      NOT l_cuscus_checked THEN
8256 
8257                    l_dlvycuscus_checked := TRUE;
8258 
8259                    validate_constraint(   --  checks only negative constraints
8260                     p_comp_class_code          =>      G_CUSTOMER_CUSTOMER,
8261                     p_object1_type             =>      'CUS',
8262                     p_object2_type             =>      'CUS',
8263                     p_object1_val_num          =>      l_inp_customer_id,
8264                     p_object2_val_num          =>      p_target_dlvy_lines(m).customer_id,
8265                     x_validate_result          =>      l_validate_cuscus_result,
8266                     x_failed_constraint        =>      l_failed_constraint,  -- id
8267                     x_return_status            =>      l_return_status);
8268 
8269                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
8270                       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
8271                          raise FND_API.G_EXC_UNEXPECTED_ERROR;
8272                       END IF;
8273                    END IF;
8274 
8275                    IF l_validate_cuscus_result <> 'S' THEN
8276                      l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
8277                      l_failed_constraint.entity_type := p_entity_type;
8278                      l_failed_constraint.entity_line_id := p_entity_id;
8279                      x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
8280                      IF l_validate_cuscus_result = 'E' THEN
8281                         l_validate_result := 'F';
8282                      END IF;
8283                    END IF;
8284 
8285                  END IF;
8286 
8287                  -- itm - itm against p_detail_tab
8288                  -- p_children_info(l) and p_children_info(m)
8289 
8290                  l_entity_rec.entity_id := p_detail_tab(j).delivery_detail_id;
8291                  l_entity_rec.organization_id := p_detail_tab(j).organization_id;
8292                  l_entity_rec.inventory_item_id := p_detail_tab(j).inventory_item_id;
8293                  l_entity_rec.customer_id := p_detail_tab(j).customer_id;
8294 
8295                  l_target_rec.entity_id := p_target_dlvy_lines(m).delivery_detail_id;
8296                  l_target_rec.organization_id := p_target_dlvy_lines(m).organization_id;
8297                  l_target_rec.inventory_item_id := p_target_dlvy_lines(m).inventory_item_id;
8298                  l_target_rec.customer_id := p_target_dlvy_lines(m).customer_id;
8299                  --
8300                  IF l_debug_on THEN
8301                     WSH_DEBUG_SV.logmsg(l_module_name,'Created l_target_rec for assigned line : '||p_target_dlvy_lines(m).delivery_detail_id);
8302                  END IF;
8303                  --
8304 
8305                  IF ((l_entity_rec.inventory_item_id <> l_target_rec.inventory_item_id) OR
8306                         (g_is_tp_installed = 'N' AND l_entity_rec.organization_id <> l_target_rec.organization_id))  THEN
8307 
8308                  search_group_itm (
8309                     p_comp_class_tab      =>   p_comp_class_tab,
8310                     p_entity_rec          =>   l_entity_rec,
8311                     p_target_rec          =>   l_target_rec,
8312                     x_validate_result     =>   l_validate_itmin_result,
8313                     x_failed_constraints  =>   x_failed_constraints,
8314                     x_return_status       =>   l_return_status);
8315 
8316                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
8317                     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
8318                        raise FND_API.G_EXC_UNEXPECTED_ERROR;
8319                     END IF;
8320                  END IF;
8321 
8322                  IF l_validate_itmin_result = 'F' THEN
8323                     l_validate_result := 'F';
8324                      EXIT;
8325                  END IF;
8326                  END IF;
8327 
8328                   <<tardet_nextpass>>
8329 
8330                 EXIT WHEN m= p_target_dlvy_lines.LAST;
8331                 m:= p_target_dlvy_lines.NEXT(m);
8332 
8333                 END LOOP;
8334 
8335                 IF l_validate_itmin_result = 'F' THEN
8336                    l_validate_result := 'F';
8337                    EXIT;
8338                 END IF;
8339 
8340                 END IF;
8341 
8342                 <<next_target_dlvy>>
8343 
8344                 EXIT WHEN l= p_target_dlvy.LAST;
8345                 l:= p_target_dlvy.NEXT(l);
8346 
8347             END LOOP; -- over p_target_dlvy
8348 
8349             IF l_validate_itmin_result = 'F' THEN
8350                l_validate_result := 'F';
8351                EXIT;
8352             END IF;
8353 
8354           END IF;
8355 
8356          END IF; -- l_inp_customer
8357 
8358          l_inp_items_cnt := l_items_tab.COUNT;
8359          l_items_tab(l_inp_items_cnt + 1).line_id := p_detail_tab(j).delivery_detail_id;
8360          l_items_tab(l_inp_items_cnt + 1).item_id := p_detail_tab(j).inventory_item_id;
8361          l_items_tab(l_inp_items_cnt + 1).org_id  := p_detail_tab(j).organization_id;
8362 
8363          <<inpdet_nextpass>>
8364 
8365          EXIT WHEN j= p_detail_tab.LAST;
8366          j:= p_detail_tab.NEXT(j);
8367 
8368         END LOOP; -- p_detail_tab
8369 
8370         -- Checks whether all details in the delivery
8371         -- have same/different must use carrier/mode/vehicle
8372         -- compared to this stop of the target trip
8373         -- If different, violation
8374 
8375         IF l_locations_list.COUNT = 1 THEN
8376 
8377           search_itm_fac_incl(
8378                      p_comp_class_tab      =>   p_comp_class_tab,
8379                      p_entity_type         =>   G_TRIP,
8380                      p_entity_id           =>   p_target_trip.trip_id,
8381                      p_items_tab           =>   l_items_tab,
8382                      p_locations_list      =>   l_locations_list,
8383                      x_validate_result     =>   l_validate_itmfacin_result,
8384                      x_failed_constraints  =>   x_failed_constraints,
8385                      x_return_status       =>   l_return_status);
8386 
8387           IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
8388            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
8389               raise FND_API.G_EXC_UNEXPECTED_ERROR;
8390            END IF;
8391           END IF;
8392 
8393         END IF;
8394 
8395         IF l_validate_itmin_result = 'F' OR l_validate_itmfacin_result = 'F' THEN
8396           l_validate_result := 'F';
8397           EXIT;
8398         END IF;
8399 
8400        END IF;
8401 
8402        <<tarstop_nextpass>>
8403        EXIT WHEN k= p_target_tripstops.LAST;
8404        k:= p_target_tripstops.NEXT(k);
8405 
8406      END LOOP; -- p_target_trip_stops
8407     END IF;
8408 
8409     IF l_validate_result = 'F' THEN
8410        x_validate_result := 'F';
8411     END IF;
8412 
8413     --
8414     IF l_debug_on THEN
8415       WSH_DEBUG_SV.pop(l_module_name);
8416     END IF;
8417     --
8418 
8419 EXCEPTION
8420     WHEN g_get_carrmode_failed THEN
8421       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
8422       --
8423       IF l_debug_on THEN
8424         WSH_DEBUG_SV.pop(l_module_name,' get carrier-mode failed ');
8425       END IF;
8426       --
8427     WHEN g_get_vehicletype_failed THEN
8428       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
8429       --
8430       IF l_debug_on THEN
8431         WSH_DEBUG_SV.pop(l_module_name,' get vehicletype failed ');
8432       END IF;
8433       --
8434     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8435       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
8436       --
8437       IF l_debug_on THEN
8438         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
8439         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
8440       END IF;
8441       --
8442     WHEN others THEN
8443       IF c_get_stop%ISOPEN THEN
8444          CLOSE c_get_stop;
8445       END IF;
8446       IF c_get_stop_location%ISOPEN THEN
8447          CLOSE c_get_stop_location;
8448       END IF;
8449       IF c_get_pickup_dropoff_dates%ISOPEN THEN
8450          CLOSE c_get_pickup_dropoff_dates;
8451       END IF;
8452       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.check_dlvy_against_trip');
8453       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
8454       --
8455       IF l_debug_on THEN
8456         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
8457         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
8458       END IF;
8459       --
8460 END check_dlvy_against_trip;
8461 
8462 
8463 --***************************************************************************--
8464 --
8465 --========================================================================
8466 -- PROCEDURE : check_act_positive         PRIVATE
8467 --
8468 -- PARAMETERS: p_comp_class_tab           Table of Compatibility class codes to check
8469 --             p_item_id                  Item id for which check is running
8470 --             p_item_org_id              Organization id for the input Item id
8471 --             p_delivery_rec             Input delivery record
8472 --             x_failed_constraints       Failed constraint table
8473 --             x_validate_result          Constraint Validation result : S / F
8474 --             x_return_status            Return status
8475 -- COMMENT   :
8476 -- Applies to autocreate trip only
8477 -- For a given delivery
8478 -- Check pickup, drop off locations
8479 -- and all items
8480 -- against delivery's ship method
8481 -- for Inclusive constraint
8482 -- If different, violation
8483 -- Used to determine whether for any resulting trip
8484 -- delivery level shipmethod should not be updated to the trip
8485 --========================================================================
8486 
8487 PROCEDURE check_act_positive (
8488              p_comp_class_tab     IN WSH_UTIL_CORE.column_tab_type,
8489              p_item_id            IN NUMBER DEFAULT NULL,
8490              p_item_org_id        IN NUMBER DEFAULT NULL,
8491              p_delivery_rec       IN entity_rec_type,
8492              x_failed_constraint  IN OUT NOCOPY line_constraint_tab_type,
8493              x_validate_result    OUT NOCOPY VARCHAR2 ,
8494              x_return_status      OUT NOCOPY VARCHAR2)
8495 IS
8496 
8497     i                             NUMBER:=0;
8498     l_carrier                     NUMBER := NULL;
8499     l_location_id                 NUMBER:=0;
8500     l_out_object2_num             NUMBER:=0;
8501     l_out_object2_char            VARCHAR2(30):=NULL;
8502     l_const_count                 NUMBER := x_failed_constraint.COUNT;
8503 
8504     l_return_status               VARCHAR2(1);
8505     l_mode                        VARCHAR2(30) := NULL;
8506     l_service_level               VARCHAR2(30) := NULL;
8507     l_carrier_service_inout_rec   WSH_CARRIERS_GRP.Carrier_Service_InOut_Rec_Type;
8508     l_validate_carrier_result     VARCHAR2(1) := 'S';
8509     l_validate_mode_result        VARCHAR2(1) := 'S';
8510 
8511     l_module_name                 CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'check_act_positive';
8512     l_debug_on                    CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
8513 
8514 BEGIN
8515 
8516     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
8517     x_validate_result := 'S';
8518 
8519     IF l_debug_on THEN
8520        wsh_debug_sv.push(l_module_name);
8521     END IF;
8522 
8523     IF (p_delivery_rec.carrier_id IS NULL OR p_delivery_rec.mode_of_transport IS NULL) AND
8524        (p_delivery_rec.ship_method_code IS NOT NULL) THEN
8525         l_carrier_service_inout_rec.ship_method_code := p_delivery_rec.ship_method_code;
8526 
8527         WSH_CARRIERS_GRP.get_carrier_service_mode(
8528                    p_carrier_service_inout_rec   =>  l_carrier_service_inout_rec,
8529                    x_return_status               =>  l_return_status);
8530 
8531         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
8532            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
8533            IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
8534               raise FND_API.G_EXC_UNEXPECTED_ERROR;
8535            END IF;
8536               raise g_get_carrmode_failed;
8537            END IF;
8538         END IF;
8539         l_carrier := l_carrier_service_inout_rec.carrier_id;
8540         l_mode    := l_carrier_service_inout_rec.mode_of_transport;
8541     END IF;
8542 
8543     -- If carrier_id or mode is passed in, then those get preference for validation
8544     -- If they are not, they are derived from ship method if that is passed
8545 
8546     IF p_delivery_rec.carrier_id IS NOT NULL THEN
8547        l_carrier := p_delivery_rec.carrier_id;
8548     END IF;
8549     IF p_delivery_rec.mode_of_transport IS NOT NULL THEN
8550        l_mode := p_delivery_rec.mode_of_transport;
8551     END IF;
8552 
8553     IF l_carrier IS NULL AND l_mode IS NULL THEN
8554       --
8555       IF l_debug_on THEN
8556         WSH_DEBUG_SV.pop(l_module_name);
8557       END IF;
8558       --
8559      RETURN;
8560     END IF;
8561 
8562     -- Check success and l_carrier, l_mode non null
8563 
8564     IF p_item_id IS NOT NULL AND p_item_org_id IS NOT NULL THEN
8565 
8566        -- need to check ITM - CAR/MOD against delivery_rec's ship_method
8567 
8568         IF p_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) THEN
8569 
8570          check_inclusive_object2(
8571              p_comp_class_code          =>      G_ITEM_MODE,
8572              p_entity_type              =>      G_DEL_DETAIL,
8573              p_entity_id                =>      p_item_id,
8574              p_object1_type             =>      'ITM',
8575              p_object1_val_num          =>      p_item_id,
8576              p_object1_parent_id        =>      p_item_org_id,
8577              p_object2_type             =>      'MOD',
8578              p_object2_val_char          =>     l_mode,
8579              x_out_object2_num          =>      l_out_object2_num,
8580              x_out_object2_char         =>      l_out_object2_char,
8581              x_validate_result          =>      l_validate_mode_result,
8582              x_failed_constraint        =>      x_failed_constraint,
8583              x_return_status            =>      l_return_status);
8584 
8585          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
8586             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
8587                raise FND_API.G_EXC_UNEXPECTED_ERROR;
8588             END IF;
8589          END IF;
8590 
8591          IF l_validate_mode_result = 'F' THEN
8592             x_validate_result := 'F';
8593          END IF;
8594 
8595          END IF;
8596 
8597         IF p_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) AND x_validate_result = 'S' THEN
8598 
8599          check_inclusive_object2(
8600              p_comp_class_code          =>      G_ITEM_CARRIER,
8601              p_entity_type              =>      G_DEL_DETAIL,
8602              p_entity_id                =>      p_item_id,
8603              p_object1_type             =>      'ITM',
8604              p_object1_val_num          =>      p_item_id,
8605              p_object1_parent_id        =>      p_item_org_id,
8606              p_object2_type             =>      'CAR',
8607              p_object2_val_num          =>      l_carrier,
8608              x_out_object2_num          =>      l_out_object2_num,
8609              x_out_object2_char         =>      l_out_object2_char,
8610              x_validate_result          =>      l_validate_carrier_result,
8611              x_failed_constraint        =>      x_failed_constraint,
8612              x_return_status            =>      l_return_status);
8613 
8614          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
8615             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
8616                raise FND_API.G_EXC_UNEXPECTED_ERROR;
8617             END IF;
8618          END IF;
8619 
8620          IF l_validate_carrier_result = 'F' THEN
8621             x_validate_result := 'F';
8622          END IF;
8623 
8624         END IF;
8625 
8626     ELSE
8627 
8628         FOR i IN 1..2 LOOP
8629 
8630           IF i = 1 THEN
8631              l_location_id := p_delivery_rec.INITIAL_PICKUP_LOCATION_ID;
8632           ELSIF i = 2 THEN
8633              l_location_id := p_delivery_rec.ULTIMATE_DROPOFF_LOCATION_ID;
8634           END IF;
8635 
8636           IF l_location_id IS NOT NULL THEN
8637 
8638             IF p_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) THEN
8639 
8640              check_inclusive_object2(
8641                  p_comp_class_code          =>      G_FACILITY_MODE,
8642                  p_entity_type              =>      G_DELIVERY,
8643                  p_entity_id                =>      p_delivery_rec.entity_id,
8644                  p_object1_type             =>      'FAC',
8645                  p_object1_val_num          =>      l_location_id,
8646                  p_object2_type             =>      'MOD',
8647                  p_object2_val_char          =>     l_mode,
8648                  x_out_object2_num          =>      l_out_object2_num,
8649                  x_out_object2_char         =>      l_out_object2_char,
8650                  x_validate_result          =>      l_validate_mode_result,
8651                  x_failed_constraint        =>      x_failed_constraint,
8652                  x_return_status            =>      l_return_status);
8653 
8654              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
8655                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
8656                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
8657                 END IF;
8658              END IF;
8659 
8660              IF l_validate_mode_result = 'F' THEN
8661                 x_validate_result := 'F';
8662                 EXIT;
8663              END IF;
8664 
8665             END IF;
8666 
8667             IF p_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) THEN
8668 
8669              check_inclusive_object2(
8670                  p_comp_class_code          =>      G_FACILITY_CARRIER,
8671                  p_entity_type              =>      G_DELIVERY,
8672                  p_entity_id                =>      p_delivery_rec.entity_id,
8673                  p_object1_type             =>      'FAC',
8674                  p_object1_val_num          =>      l_location_id,
8675                  p_object2_type             =>      'CAR',
8676                  p_object2_val_num          =>      l_carrier,
8677                  x_out_object2_num          =>      l_out_object2_num,
8678                  x_out_object2_char         =>      l_out_object2_char,
8679                  x_validate_result          =>      l_validate_carrier_result,
8680                  x_failed_constraint        =>      x_failed_constraint,
8681                  x_return_status            =>      l_return_status);
8682 
8683              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
8684                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
8685                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
8686                 END IF;
8687              END IF;
8688 
8689              IF l_validate_carrier_result = 'F' THEN
8690                 x_validate_result := 'F';
8691                 EXIT;
8692              END IF;
8693 
8694             END IF;
8695           END IF; -- l_location_id non null
8696 
8697         END LOOP;
8698 
8699        -- need to check delivery_rec's facilities against delivery_rec's shipmethod
8700     END IF;
8701 
8702     IF ( l_const_count < x_failed_constraint.COUNT) THEN
8703 
8704          x_failed_constraint.DELETE(l_const_count+1,x_failed_constraint.COUNT);
8705 
8706     END IF;
8707 
8708     --
8709     IF l_debug_on THEN
8710       WSH_DEBUG_SV.pop(l_module_name);
8711     END IF;
8712     --
8713 
8714 EXCEPTION
8715     WHEN g_get_carrmode_failed THEN
8716       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
8717       --
8718       IF l_debug_on THEN
8719         WSH_DEBUG_SV.pop(l_module_name,' get carrier-mode failed ');
8720       END IF;
8721       --
8722     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
8723       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
8724       --
8725       IF l_debug_on THEN
8726         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
8727         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
8728       END IF;
8729       --
8730     WHEN others THEN
8731       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.check_act_positive');
8732       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
8733       --
8734       IF l_debug_on THEN
8735         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
8736         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
8737       END IF;
8738       --
8739 
8740 END check_act_positive;
8741 
8742 --***************************************************************************--
8743 --
8744 --========================================================================
8745 -- PROCEDURE : check_act_carmode          PRIVATE
8746 --
8747 -- PARAMETERS: p_comp_class_tab           Table of Compatibility class codes to check
8748 --             p_delivery_rec             Input delivery record
8749 --             p_group_locations          List of non pickup, non drop off locations
8750 --                                        of the delivery in the potential trip
8751 --             x_failed_constraint        Failed constraint table
8752 --             x_validate_result          Constraint Validation result : S / F
8753 --             x_return_status            Return status
8754 -- COMMENT   :
8755 -- Applies to autocreate trip only
8756 -- For a given delivery
8757 -- Check pickup drop off locations
8758 -- and all non pickup, drop off locations possible in the potential trip
8759 -- to make sure they all have same
8760 -- carrier/mode/vehicle for Inclusive constraint
8761 -- If different, violation
8762 --========================================================================
8763 
8764 PROCEDURE check_act_carmode (
8765              p_comp_class_tab     IN WSH_UTIL_CORE.column_tab_type,
8766              p_delivery_rec       IN OUT NOCOPY entity_rec_type,
8767              p_group_locations    IN WSH_UTIL_CORE.id_tab_type,
8768              x_failed_constraint  IN OUT NOCOPY line_constraint_tab_type,
8769              x_validate_result    OUT NOCOPY VARCHAR2 ,
8770              x_return_status      OUT NOCOPY VARCHAR2)
8771 IS
8772 
8773     i                             NUMBER :=0;
8774     l_return_status               VARCHAR2(1) := NULL;
8775     l_validate_carrier_result     VARCHAR2(1) := 'S';
8776     l_validate_vehicle_result     VARCHAR2(1) := 'S';
8777     l_validate_mode_result        VARCHAR2(1) := 'S';
8778     l_location_id                 NUMBER :=0;
8779     l_out_object2_num             NUMBER := NULL;
8780     l_out_object2_vehnum          NUMBER := NULL;
8781     l_out_object2_char            VARCHAR2(30) := NULL;
8782     l_prev_out_object2_num        NUMBER := NULL;
8783     l_prev_out_object2_vehnum     NUMBER := NULL;
8784     l_prev_out_object2_char       VARCHAR2(30) := NULL;
8785     l_const_count                 NUMBER := x_failed_constraint.COUNT;
8786 
8787     l_module_name                 CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'check_act_carmode';
8788     l_debug_on                    CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
8789 
8790 BEGIN
8791 
8792     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
8793     x_validate_result := 'S';
8794 
8795     IF l_debug_on THEN
8796        wsh_debug_sv.push(l_module_name);
8797     END IF;
8798 
8799     FOR i IN 1..2 LOOP
8800     -- Facility  - Vehicle
8801 
8802       IF i = 1 THEN
8803          l_location_id := p_delivery_rec.INITIAL_PICKUP_LOCATION_ID;
8804       ELSIF i = 2 THEN
8805          l_location_id := p_delivery_rec.ULTIMATE_DROPOFF_LOCATION_ID;
8806       END IF;
8807 
8808       IF l_location_id IS NOT NULL THEN
8809 
8810         IF p_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) THEN
8811 
8812               check_inclusive_object2(
8813                p_comp_class_code          =>      G_FACILITY_CARRIER,
8814                p_entity_type              =>      G_DELIVERY,
8815                p_entity_id                =>      p_delivery_rec.entity_id,
8816                p_object1_type             =>      'FAC',
8817                p_object1_val_num          =>      l_location_id,
8818                p_object2_type             =>      'CAR',
8819                x_out_object2_num          =>      l_out_object2_num,
8820                x_out_object2_char         =>      l_out_object2_char,
8821                x_validate_result          =>      l_validate_carrier_result,
8822                x_failed_constraint        =>      x_failed_constraint,
8823                x_return_status            =>      l_return_status);
8824 
8825               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
8826                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
8827                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
8828                  END IF;
8829               END IF;
8830 
8831               IF l_validate_carrier_result = 'F' THEN
8832                  IF i = 2 AND l_prev_out_object2_num IS NOT NULL THEN
8833                     IF l_out_object2_num <> l_prev_out_object2_num THEN
8834                        x_validate_result := 'F';
8835                        EXIT;
8836                     END IF;
8837                  END IF;
8838               END IF;
8839 
8840         END IF;
8841 
8842         IF p_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) THEN
8843 
8844               check_inclusive_object2(
8845                p_comp_class_code          =>      G_FACILITY_MODE,
8846                p_entity_type              =>      G_DELIVERY,
8847                p_entity_id                =>      p_delivery_rec.entity_id,
8848                p_object1_type             =>      'FAC',
8849                p_object1_val_num          =>      l_location_id,
8850                p_object2_type             =>      'MOD',
8851                x_out_object2_num          =>      l_out_object2_num,
8852                x_out_object2_char         =>      l_out_object2_char,
8853                x_validate_result          =>      l_validate_mode_result,
8854                x_failed_constraint        =>      x_failed_constraint,
8855                x_return_status            =>      l_return_status);
8856 
8857               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
8858                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
8859                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
8860                  END IF;
8861               END IF;
8862 
8863               IF l_validate_mode_result = 'F' THEN
8864                  IF i = 2 AND l_prev_out_object2_char IS NOT NULL THEN
8865                     IF l_out_object2_char <> l_prev_out_object2_char THEN
8866                        x_validate_result := 'F';
8867                        EXIT;
8868                     END IF;
8869                  END IF;
8870               END IF;
8871 
8872         END IF;
8873 
8874         IF p_comp_class_tab.EXISTS(G_FACILITY_VEHICLE_NUM) THEN
8875 
8876               check_inclusive_object2(
8877                p_comp_class_code          =>      G_FACILITY_VEHICLE,
8878                p_entity_type              =>      G_DELIVERY,
8879                p_entity_id                =>      p_delivery_rec.entity_id,
8880                p_object1_type             =>      'FAC',
8881                p_object1_val_num          =>      l_location_id,
8882                p_object2_type             =>      'VHT',
8883                x_out_object2_num          =>      l_out_object2_vehnum,
8884                x_out_object2_char         =>      l_out_object2_char,
8885                x_validate_result          =>      l_validate_vehicle_result,
8886                x_failed_constraint        =>      x_failed_constraint,
8887                x_return_status            =>      l_return_status);
8888 
8889               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
8890                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
8891                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
8892                  END IF;
8893               END IF;
8894 
8895               IF l_validate_vehicle_result = 'F' THEN
8896                  IF i = 2 AND l_prev_out_object2_vehnum IS NOT NULL THEN
8897                     IF l_out_object2_vehnum <> l_prev_out_object2_vehnum THEN
8898                        x_validate_result := 'F';
8899                        EXIT;
8900                     END IF;
8901                  END IF;
8902               END IF;
8903 
8904         END IF;
8905 
8906       END IF; -- l_location_id not null
8907 
8908       l_prev_out_object2_num := l_out_object2_num;
8909       l_prev_out_object2_vehnum := l_out_object2_vehnum;
8910       l_prev_out_object2_char := l_out_object2_char;
8911 
8912     END LOOP;
8913 
8914    -- Now check against other locations in the same group
8915    -- Is it really checking current delivery's location against other locations in
8916    -- p_group_locations ??? 5/21
8917    -- Yes, as the below part checks against l_prev_out_object2_num which could be populated
8918    -- above even in case of success
8919 
8920     IF x_validate_result = 'S' THEN
8921      i := p_group_locations.FIRST;
8922      IF i IS NOT NULL THEN
8923        LOOP
8924 
8925         -- Facility  - Vehicle
8926 
8927         IF p_group_locations(i) IS NOT NULL THEN
8928 
8929           IF p_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) THEN
8930 
8931                 check_inclusive_object2(
8932                  p_comp_class_code          =>      G_FACILITY_CARRIER,
8933                  p_entity_type              =>      G_DELIVERY,
8934                  p_entity_id                =>      p_delivery_rec.entity_id,
8935                  p_object1_type             =>      'FAC',
8936                  p_object1_val_num          =>      p_group_locations(i),
8937                  p_object2_type             =>      'CAR',
8938                  x_out_object2_num          =>      l_out_object2_num,
8939                  x_out_object2_char         =>      l_out_object2_char,
8940                  x_validate_result          =>      l_validate_carrier_result,
8941                  x_failed_constraint        =>      x_failed_constraint,
8942                  x_return_status            =>      l_return_status);
8943 
8944                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
8945                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
8946                       raise FND_API.G_EXC_UNEXPECTED_ERROR;
8947                    END IF;
8948                 END IF;
8949 
8950                 IF l_validate_carrier_result = 'F' THEN
8951                    IF l_prev_out_object2_num IS NOT NULL THEN
8952                       IF l_out_object2_num <> l_prev_out_object2_num THEN
8953                          x_validate_result := 'F';
8954                          EXIT;
8955                       END IF;
8956                    END IF;
8957                 END IF;
8958 
8959           END IF;
8960 
8961           IF p_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) THEN
8962 
8963                 check_inclusive_object2(
8964                  p_comp_class_code          =>      G_FACILITY_MODE,
8965                  p_entity_type              =>      G_DELIVERY,
8966                  p_entity_id                =>      p_delivery_rec.entity_id,
8967                  p_object1_type             =>      'FAC',
8968                  p_object1_val_num          =>      p_group_locations(i),
8969                  p_object2_type             =>      'MOD',
8970                  x_out_object2_num          =>      l_out_object2_num,
8971                  x_out_object2_char         =>      l_out_object2_char,
8972                  x_validate_result          =>      l_validate_mode_result,
8973                  x_failed_constraint        =>      x_failed_constraint,
8974                  x_return_status            =>      l_return_status);
8975 
8976                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
8977                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
8978                       raise FND_API.G_EXC_UNEXPECTED_ERROR;
8979                    END IF;
8980                 END IF;
8981 
8982                 IF l_validate_mode_result = 'F' THEN
8983                    IF l_prev_out_object2_char IS NOT NULL THEN
8984                       IF l_out_object2_char <> l_prev_out_object2_char THEN
8985                          x_validate_result := 'F';
8986                          EXIT;
8987                       END IF;
8988                    END IF;
8989                 END IF;
8990 
8991           END IF;
8992 
8993           IF p_comp_class_tab.EXISTS(G_FACILITY_VEHICLE_NUM) THEN
8994 
8995                 check_inclusive_object2(
8996                  p_comp_class_code          =>      G_FACILITY_VEHICLE,
8997                  p_entity_type              =>      G_DELIVERY,
8998                  p_entity_id                =>      p_delivery_rec.entity_id,
8999                  p_object1_type             =>      'FAC',
9000                  p_object1_val_num          =>      p_group_locations(i),
9001                  p_object2_type             =>      'VHT',
9002                  x_out_object2_num          =>      l_out_object2_vehnum,
9003                  x_out_object2_char         =>      l_out_object2_char,
9004                  x_validate_result          =>      l_validate_vehicle_result,
9005                  x_failed_constraint        =>      x_failed_constraint,
9006                  x_return_status            =>      l_return_status);
9007 
9008                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
9009                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
9010                       raise FND_API.G_EXC_UNEXPECTED_ERROR;
9011                    END IF;
9012                 END IF;
9013 
9014                 IF l_validate_vehicle_result = 'F' THEN
9015                    IF l_prev_out_object2_vehnum IS NOT NULL THEN
9016                       IF l_out_object2_vehnum <> l_prev_out_object2_vehnum THEN
9017                          x_validate_result := 'F';
9018                          EXIT;
9019                       END IF;
9020                    END IF;
9021                 END IF;
9022 
9023           END IF;
9024 
9025         END IF; -- l_location_id not null
9026 
9027         IF l_out_object2_num IS NOT NULL THEN
9028            l_prev_out_object2_num := l_out_object2_num;
9029         END IF;
9030         IF l_out_object2_vehnum IS NOT NULL THEN
9031            l_prev_out_object2_vehnum := l_out_object2_vehnum;
9032         END IF;
9033         IF l_out_object2_char IS NOT NULL THEN
9034            l_prev_out_object2_char := l_out_object2_char;
9035         END IF;
9036 
9037         EXIT WHEN i = p_group_locations.LAST;
9038         i := p_group_locations.NEXT(i);
9039 
9040        END LOOP;
9041      END IF; -- l_location_id not null
9042     ELSE
9043        p_delivery_rec.entity_id := null;
9044     END IF; -- x_validate_result
9045 
9046     -- If returning success, any constraint that failed should be deleted
9047     IF x_validate_result = 'S' AND
9048        ( l_const_count < x_failed_constraint.COUNT ) THEN
9049 
9050        x_failed_constraint.DELETE(l_const_count+1,x_failed_constraint.COUNT);
9051 
9052     END IF;
9053     --
9054     IF l_debug_on THEN
9055       WSH_DEBUG_SV.pop(l_module_name);
9056     END IF;
9057     --
9058 
9059 
9060 EXCEPTION
9061     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
9062       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
9063       --
9064       IF l_debug_on THEN
9065         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
9066         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
9067       END IF;
9068       --
9069     WHEN others THEN
9070       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.check_act_carmode');
9071       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
9072       --
9073       IF l_debug_on THEN
9074         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
9075         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
9076       END IF;
9077       --
9078 
9079 END check_act_carmode;
9080 
9081 --***************************************************************************--
9082 
9083 --========================================================================
9084 -- FUNCTION :  is_last_trip                PUBLIC
9085 --
9086 -- PARAMETERS: p_delivery_id               Input delivery
9087 --             p_initial_pu_loc_id         Delivery's initial pickup location
9088 --             p_ultimate_do_loc_id        Delivery's ultimate dropoff location
9089 --             p_target_stops_in_trip      Input pickup and dropoff stop/location of the delivery(s)
9090 --                                         in the target trip in case of assign delivery to trip
9091 --             p_target_trip_id            Target trip
9092 --             x_return_status             Return status
9093 -- COMMENT   :
9094 -- Applicable to Assign delivery to trip only
9095 -- Determines whether the target trip is the last trip for an input delivery
9096 -- in order to finish the multileg delivery
9097 --========================================================================
9098 
9099 FUNCTION is_last_trip (
9100             p_delivery_id           IN NUMBER,
9101             p_initial_pu_loc_id     IN NUMBER DEFAULT NULL,
9102             p_ultimate_do_loc_id    IN NUMBER DEFAULT NULL,
9103             p_target_trip_id        IN NUMBER,
9104             p_target_stops_in_trip  IN target_tripstop_cc_rec_type,
9105             x_return_status         OUT NOCOPY VARCHAR2 ) RETURN BOOLEAN
9106 IS
9107 
9108     CURSOR c_get_dlvy_locs(c_delivery_id IN NUMBER) IS
9109     SELECT initial_pickup_location_id,
9110            ultimate_dropoff_location_id
9111     FROM   wsh_new_deliveries
9112     WHERE  delivery_id = c_delivery_id;
9113 
9114     -- AGDUMMY
9115     -- all the stop_location_id
9116     -- AGDUMMY Start with a leg whose pickup loc is not a dropoff stop of another leg of that delivery
9117 
9118     CURSOR c_get_dlegs(c_delivery_id IN NUMBER) IS
9119     SELECT * from
9120     wsh_constraint_dleg_tmp v -- global temporary table
9121     where v.delivery_id = c_delivery_id
9122     CONNECT BY PRIOR v.drop_off_stop_location_id = v.pick_up_stop_location_id
9123     START WITH v.pick_up_stop_location_id NOT IN (select nvl(a.physical_location_id,a.stop_location_id)
9124               from wsh_delivery_legs c,wsh_trip_stops a where
9125               c.delivery_id = c_delivery_id and
9126               c.drop_off_stop_id = a.stop_id
9127               );
9128 
9129     l_stop_id              NUMBER := 0;
9130     l_count                NUMBER := 0;
9131     l_break_count          NUMBER := 0;
9132     l_result               BOOLEAN := FALSE;
9133     l_sequence             BOOLEAN := FALSE;
9134     l_first_pu_loc         NUMBER := NULL;
9135     l_prev_do_loc          NUMBER := NULL;
9136     l_dropoff_loc_id       NUMBER := NULL;
9137     l_dropoff_seq_id       NUMBER := NULL;
9138     l_dropoff_pa_date      DATE;
9139     l_pickup_loc_id        NUMBER := NULL;
9140     l_pickup_seq_id        NUMBER := NULL;
9141     l_pickup_pa_date       DATE;
9142     l_dlvy_dotrip_loc_id   NUMBER := NULL;
9143     l_dlvy_putrip_loc_id   NUMBER := NULL;
9144     l_initial_pu_loc_id    NUMBER := NULL;
9145     l_ultimate_do_loc_id   NUMBER := NULL;
9146     l_root2                NUMBER := NULL;
9147     l_leaf1                NUMBER := NULL;
9148     l_dleg_rec             dleg_stops_rec_type;
9149 
9150     l_tmp_count            NUMBER := NULL;
9151     --#DUM_LOC(S)
9152     l_physical_location_id NUMBER;
9153     l_return_status        VARCHAR2(1) := NULL;
9154     --#DUM_LOC(E)
9155 
9156     l_module_name          CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'is_last_trip';
9157     l_debug_on             CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
9158 
9159 BEGIN
9160 
9161     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
9162 
9163     IF l_debug_on THEN
9164        WSH_DEBUG_SV.push(l_module_name);
9165        WSH_DEBUG_SV.logmsg(l_module_name,'Input delivery : '||p_delivery_id);
9166     END IF;
9167 
9168     IF p_initial_pu_loc_id IS NULL OR p_ultimate_do_loc_id IS NULL THEN
9169        OPEN c_get_dlvy_locs(p_delivery_id);
9170        FETCH c_get_dlvy_locs INTO l_initial_pu_loc_id,l_ultimate_do_loc_id;
9171        CLOSE c_get_dlvy_locs;
9172        --AGDUMMY
9173        --Made the changes outside if condition.
9174 
9175        --#DUM_LOC(S)
9176     --Check if ultimate drop off location is a dummy location
9177     WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
9178          p_internal_cust_location_id  => l_ultimate_do_loc_id,
9179          x_internal_org_location_id   => l_physical_location_id,
9180          x_return_status              => l_return_status);
9181 
9182     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
9183        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
9184           raise FND_API.G_EXC_UNEXPECTED_ERROR;
9185        END IF;
9186     END IF;
9187 
9188     IF (l_physical_location_id IS NOT NULL) THEN
9189       --
9190       IF l_debug_on THEN
9191         WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_ultimate_do_loc_id||' is a dummy location');
9192       END IF;
9193       --
9194       l_ultimate_do_loc_id:= l_physical_location_id;
9195     END IF;
9196     --#DUM_LOC(E)
9197 
9198     ELSE
9199        -- AGDUMMY
9200        -- Ultimate dropoff location_id is already passed as converted to physical if dummy by the caller
9201        l_initial_pu_loc_id  := p_initial_pu_loc_id;
9202        l_ultimate_do_loc_id := p_ultimate_do_loc_id;
9203     END IF;
9204 
9205     -- Optionally can use p_target_tripstops table
9206     -- to search for delivery's initial/ultimate locations
9207 
9208     -- AGDUMMY
9209     -- p_target_stops_in_trip's dropoff_location_id already converted by the caller
9210     -- to physical_location_id if it was dummy
9211 
9212     IF p_target_stops_in_trip.dropoff_stop_id IS NULL THEN
9213        -- check if delivery's ultimate do location id already exists
9214        -- in target trip
9215          OPEN c_get_stop(l_ultimate_do_loc_id,p_target_trip_id);
9216          FETCH c_get_stop INTO l_dropoff_seq_id,l_dropoff_pa_date;
9217          CLOSE c_get_stop;
9218          IF l_dropoff_seq_id IS NOT NULL THEN
9219             l_dropoff_loc_id := l_ultimate_do_loc_id;
9220          END IF;
9221     ELSIF p_target_stops_in_trip.dropoff_stop_id IS NOT NULL THEN
9222 
9223        OPEN c_get_stop_location(p_target_stops_in_trip.dropoff_stop_id);
9224        FETCH c_get_stop_location INTO l_dropoff_loc_id,l_dropoff_seq_id,l_dropoff_pa_date;
9225        CLOSE c_get_stop_location;
9226 
9227     END IF;
9228 
9229     IF p_target_stops_in_trip.pickup_stop_id IS NULL THEN
9230        -- check if delivery's initial pu location id already exists
9231        -- in target trip
9232          OPEN c_get_stop(l_initial_pu_loc_id,p_target_trip_id);
9233          FETCH c_get_stop INTO l_pickup_seq_id,l_pickup_pa_date;
9234          CLOSE c_get_stop;
9235          IF l_pickup_seq_id IS NOT NULL THEN
9236             l_pickup_loc_id := l_initial_pu_loc_id;
9237          END IF;
9238     ELSIF p_target_stops_in_trip.pickup_stop_id IS NOT NULL THEN
9239 
9240        OPEN c_get_stop_location(p_target_stops_in_trip.pickup_stop_id);
9241        FETCH c_get_stop_location INTO l_pickup_loc_id,l_pickup_seq_id,l_pickup_pa_date;
9242        CLOSE c_get_stop_location;
9243 
9244     END IF;
9245 
9246     -- Either an existing stop of the target trip is chosen as
9247     -- pickup/dropoff or a new location is chosen
9248 
9249     -- The assumption will be if
9250     -- input pickup stop/location is null, this trip is the first dleg in sequence
9251     -- input dropoff stop/loc is null, this trip is the last dleg in sequence
9252 
9253     -- Found out that if input pickup/dropoff stop/location is NULL,
9254     -- creates a new stop in the trip only if a stop with that location not already exists
9255 
9256     l_dlvy_putrip_loc_id := nvl(nvl(p_target_stops_in_trip.pickup_location_id,l_pickup_loc_id),l_initial_pu_loc_id);
9257     l_dlvy_dotrip_loc_id := nvl(nvl(p_target_stops_in_trip.dropoff_location_id,l_dropoff_loc_id),l_ultimate_do_loc_id);
9258 
9259 
9260        -- Find out that if from the first to last trip on which the delivery
9261        -- will be on, all the delvery legs are connected
9262        -- and delivery's initial pickup and ultimate dropoff locations are satisfied
9263 
9264        IF l_debug_on THEN
9265              WSH_DEBUG_SV.logmsg(l_module_name,'del initial pickup : '||l_initial_pu_loc_id||' del ultimate dropoff : '||l_ultimate_do_loc_id);
9266              WSH_DEBUG_SV.logmsg(l_module_name,'l_pickup_loc_id : '||l_pickup_loc_id||' l_dropoff_loc_id : '||l_dropoff_loc_id);
9267              WSH_DEBUG_SV.logmsg(l_module_name,'l_dlvy_dotrip_loc_id : '||l_dlvy_dotrip_loc_id||' l_dlvy_putrip_loc_id : '||l_dlvy_putrip_loc_id);
9268        END IF;
9269 
9270     l_count := 0;
9271     l_break_count := 0;
9272     l_result := TRUE;
9273     l_sequence := TRUE;
9274 
9275     /*
9276     SELECT COUNT(*)
9277     INTO l_tmp_count
9278     FROM wsh_constraint_dleg_tmp
9279     WHERE delivery_id = p_delivery_id;
9280 
9281     IF l_debug_on THEN
9282        WSH_DEBUG_SV.logmsg(l_module_name,'Currently have :'||l_tmp_count||' rows into wsh_constraint_dleg_tmp for delivery : '||p_delivery_id);
9283     END IF;
9284     */
9285 
9286     OPEN c_get_dlegs(p_delivery_id);
9287     LOOP
9288           FETCH c_get_dlegs INTO l_dleg_rec;
9289           EXIT WHEN c_get_dlegs%NOTFOUND;
9290           IF l_debug_on THEN
9291              WSH_DEBUG_SV.logmsg(l_module_name,'dleg id :'||l_dleg_rec.delivery_leg_id||' pickup loc id : '||l_dleg_rec.pick_up_loc_id||' dropoff loc :'||l_dleg_rec.drop_off_loc_id);
9292              WSH_DEBUG_SV.logmsg(l_module_name,'pickup stop : '||l_dleg_rec.pick_up_stop_id||' dropoff stop :'||l_dleg_rec.drop_off_stop_id);
9293           END IF;
9294 
9295           l_count := l_count + 1;
9296           IF l_count > 1 THEN
9297              -- dlegs can have arbitrary sequence number
9298              IF l_dleg_rec.pick_up_loc_id <> l_prev_do_loc THEN
9299              -- There is a break in dleg sequence
9300              -- 09/24 The connect by query can return dlegs
9301              -- in improper sequence
9302              -- But the current dleg can finish multileg
9303              -- delivery only if no of breaks = 1
9304                 l_result := FALSE;
9305                 l_sequence := FALSE;
9306                 l_break_count := l_break_count + 1;
9307                 -- take care of the fact that
9308                 -- input pickup/dropoff stop can be null
9309                 -- but they already exist in the trip
9310                 IF l_break_count = 1 THEN
9311                    l_root2 := l_dleg_rec.pick_up_loc_id;
9312                    l_leaf1 := l_prev_do_loc;
9313                    IF l_dleg_rec.pick_up_loc_id = l_dlvy_dotrip_loc_id AND
9314                       l_prev_do_loc = l_dlvy_putrip_loc_id THEN
9315                         l_result := TRUE;
9316                    END IF;
9317                 END IF;
9318 
9319              END IF;
9320 
9321           ELSE
9322              l_first_pu_loc := l_dleg_rec.pick_up_loc_id;
9323           END IF;
9324           l_prev_do_loc := l_dleg_rec.drop_off_loc_id;
9325     END LOOP;
9326     CLOSE c_get_dlegs;
9327 
9328     IF l_debug_on THEN
9329              WSH_DEBUG_SV.logmsg(l_module_name,'l_first_pu_loc : '||l_first_pu_loc||' l_prev_do_loc : '||l_prev_do_loc||' l_break_count : '||l_break_count);
9330              WSH_DEBUG_SV.logmsg(l_module_name,'l_root2 : '||l_root2||' l_leaf1 : '||l_leaf1);
9331     END IF;
9332 
9333     IF l_result THEN
9334 
9335        -- Means either of
9336        -- 1. all the existing delivery legs are in sequence OR no dleg existing currently
9337        -- 2. there is a break in existing delivery legs and
9338        --    current input pick_up location and drop_off location fills that gap
9339 
9340           IF l_sequence THEN -- 1 in above
9341              IF l_count >= 1 THEN -- Atleast one leg already exists
9342                 -- If all the existing delivery legs are in sequence
9343                 -- needs to make sure delivery's ini pu and ult do
9344                 -- are satisfied and the current dleg will complete the
9345                 -- multileg delivery sequence from origin to
9346                 -- destination
9347                 IF l_debug_on THEN
9348                    WSH_DEBUG_SV.logmsg(l_module_name,'Atleast one dleg exists and they are in sequence');
9349                 END IF;
9350 
9351                IF NOT ( (l_first_pu_loc = l_dlvy_dotrip_loc_id AND l_initial_pu_loc_id = l_dlvy_putrip_loc_id AND l_prev_do_loc = l_ultimate_do_loc_id) OR
9352                 (l_prev_do_loc = l_dlvy_putrip_loc_id AND l_ultimate_do_loc_id = l_dlvy_dotrip_loc_id AND l_first_pu_loc = l_initial_pu_loc_id) ) THEN
9353                   -- The current delivery leg fits in the beginning
9354                   -- or end of the delivery leg
9355 
9356                   l_result := FALSE;
9357 
9358                END IF;
9359 
9360              ELSE -- No leg exists currently
9361                 IF l_debug_on THEN
9362                    WSH_DEBUG_SV.logmsg(l_module_name,'No dleg exists currently for the input delivery');
9363                 END IF;
9364                 -- need to make sure delivery's initial pickup and
9365                 -- ultimate dropoffs are satisfied
9366 
9367                IF NOT ( ( l_dlvy_putrip_loc_id = l_initial_pu_loc_id ) AND
9368                   (l_dlvy_dotrip_loc_id = l_ultimate_do_loc_id) ) THEN
9369 
9370                   l_result := FALSE;
9371 
9372                END IF;
9373 
9374              END IF;
9375           ELSE -- Case 2 above
9376              -- For case 2 need to make sure delivery's initial pickup and
9377              -- ultimate dropoffs are satisfied
9378 
9379              IF l_debug_on THEN
9380                 WSH_DEBUG_SV.logmsg(l_module_name,'there is a break in current leg sequences for the input delivery and current dleg fits in that break');
9381              END IF;
9382              IF NOT (l_first_pu_loc = l_initial_pu_loc_id AND
9383                 l_prev_do_loc = l_ultimate_do_loc_id ) THEN
9384                   l_result := FALSE;
9385              END IF;
9386           END IF;
9387 
9388     ELSE
9389           -- 09/24 The connect by query can return dlegs
9390           -- in improper sequence
9391           -- But the current dleg can finish multileg
9392           -- delivery only if no of breaks = 1
9393           IF (NOT l_sequence) AND l_break_count = 1 THEN
9394 
9395              IF l_first_pu_loc = l_dlvy_dotrip_loc_id AND
9396                    l_prev_do_loc = l_dlvy_putrip_loc_id THEN
9397 
9398                 IF l_debug_on THEN
9399                    WSH_DEBUG_SV.logmsg(l_module_name,'Dlegs have not been returned in proper hierarchical sequence by the connect by query');
9400                    WSH_DEBUG_SV.logmsg(l_module_name,'there is a break in current leg sequences for the input delivery and current dleg fits in that break');
9401                 END IF;
9402 
9403               IF (l_root2 = l_initial_pu_loc_id AND
9404                 l_leaf1 = l_ultimate_do_loc_id ) THEN
9405                 l_result := TRUE;
9406               END IF;
9407              END IF;
9408 
9409           ELSE
9410              IF l_debug_on THEN
9411                 WSH_DEBUG_SV.logmsg(l_module_name,'There is a break in already existing dleg sequence and the current dleg does not fit in that break');
9412              END IF;
9413           END IF;
9414     END IF;
9415 
9416     --
9417     IF l_debug_on THEN
9418       WSH_DEBUG_SV.pop(l_module_name);
9419     END IF;
9420     --
9421 
9422     RETURN l_result;
9423 
9424 EXCEPTION
9425     WHEN others THEN
9426       IF c_get_stop%ISOPEN THEN
9427          CLOSE c_get_stop;
9428       END IF;
9429       IF c_get_stop_location%ISOPEN THEN
9430          CLOSE c_get_stop_location;
9431       END IF;
9432       IF c_get_dlegs%ISOPEN THEN
9433          CLOSE c_get_dlegs;
9434       END IF;
9435       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.is_last_trip');
9436       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
9437       IF l_debug_on THEN
9438         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
9439         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
9440       END IF;
9441       RETURN FALSE;
9442 
9443 END is_last_trip;
9444 
9445 --***************************************************************************--
9446 
9447 --========================================================================
9448 -- PROCEDURE : get_intmed_stops           PRIVATE
9449 --
9450 -- PARAMETERS: p_delivery_id              Input delivery id
9451 --             p_pickup_loc_id            Input pickup location id in the target trip
9452 --                                        for the delivery in case of assign delivery to trip
9453 --             p_dropoff_loc_id           Input dropoff location id in the target trip
9454 --                                        for the delivery in case of assign delivery to trip
9455 --             x_num_dlegs                Number of existing delivery legs for this delivery
9456 --             x_stop_locations           List of output locations
9457 --             x_return_status            Return status
9458 -- COMMENT   :
9459 -- Applies to assign delivery to trip
9460 -- update/delete stop
9461 -- For a given delivery
9462 -- determine all stop locations in all existing trips the delivery is currently on
9463 -- except the delivery's initial pickup location and ultimate dropoff location
9464 --========================================================================
9465 
9466 PROCEDURE get_intmed_stops (
9467               p_delivery_id         IN  NUMBER,
9468               p_pickup_loc_id       IN  NUMBER,
9469               p_dropoff_loc_id      IN  NUMBER,
9470               x_num_dlegs           OUT NOCOPY    NUMBER,
9471               x_stop_locations      OUT NOCOPY    WSH_UTIL_CORE.id_tab_type,
9472               x_return_status       OUT NOCOPY    VARCHAR2)
9473 IS
9474 
9475     -- AGDUMMY
9476     -- all the stop_location_id
9477 
9478     -- delivery's ultimate_drop_off is converted to
9479     -- corresponding physical_location_id already if it was a dummy location
9480 
9481     CURSOR c_get_stops(c_delivery_id IN NUMBER) IS
9482     --#DUM_LOC(S)
9483     SELECT nvl(wts1.physical_location_id,wts1.stop_location_id) pickup_stop_loc,
9484 	   wts1.stop_sequence_number pickup_stop_seq,
9485 	   nvl(wts2.physical_location_id,wts2.stop_location_id) dropoff_stop_loc ,
9486 	   wts2.stop_sequence_number dropoff_stop_seq,
9487            wdl.sequence_number,wt.trip_id
9488     --#DUM_LOC(E)
9489     FROM   wsh_new_deliveries wnd,
9490            wsh_delivery_legs wdl,
9491            wsh_trips wt,
9492            wsh_trip_stops wts1,
9493            wsh_trip_stops wts2
9494     WHERE  wnd.delivery_id = c_delivery_id
9495     AND    wdl.delivery_id = wnd.delivery_id
9496     AND    wdl.pick_up_stop_id = wts1.stop_id
9497     AND    wdl.drop_off_stop_id = wts2.stop_id
9498     AND    wts1.trip_id = wt.trip_id
9499     AND    wts2.trip_id = wt.trip_id;
9500 
9501     z                                  NUMBER := 0;
9502     l_stop_loc_cnt                     NUMBER := 0;
9503     l_pickup_stop_loc                  NUMBER := 0;
9504     l_pickup_stop_seq                  NUMBER := 0;
9505     l_dropoff_stop_loc                 NUMBER := 0;
9506     l_dropoff_stop_seq                 NUMBER := 0;
9507     l_sequence_number                  NUMBER := 0;
9508     l_trip_id                          NUMBER := 0;
9509     l_stop_location_id                 NUMBER := 0;
9510 
9511     l_module_name                      CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'get_intmed_stops';
9512     l_debug_on                         CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
9513 
9514 BEGIN
9515 
9516     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
9517 
9518     IF l_debug_on THEN
9519        wsh_debug_sv.push(l_module_name);
9520     END IF;
9521 
9522     x_num_dlegs := 0;
9523     OPEN c_get_stops(p_delivery_id);
9524     LOOP
9525 
9526        FETCH c_get_stops INTO l_pickup_stop_loc, l_pickup_stop_seq,
9527              l_dropoff_stop_loc, l_dropoff_stop_seq, l_sequence_number, l_trip_id;
9528        EXIT WHEN c_get_stops%NOTFOUND;
9529        x_num_dlegs := x_num_dlegs + 1;
9530 
9531        IF l_pickup_stop_loc <> p_pickup_loc_id THEN
9532           --IF NOT x_stop_locations.EXISTS(l_pickup_stop_loc) THEN
9533           IF NOT entity_exists(l_pickup_stop_loc,x_stop_locations,z) THEN
9534              IF l_debug_on THEN
9535                    WSH_DEBUG_SV.logmsg(l_module_name,'Adding trip pickup stop location id : '||l_pickup_stop_loc);
9536              END IF;
9537              l_stop_loc_cnt := l_stop_loc_cnt + 1;
9538              x_stop_locations(l_stop_loc_cnt) := l_pickup_stop_loc;
9539              --x_stop_locations(l_pickup_stop_loc) := l_pickup_stop_loc;
9540           END IF;
9541        END IF;
9542 
9543        IF l_dropoff_stop_loc <> p_dropoff_loc_id THEN
9544           --IF NOT x_stop_locations.EXISTS(l_dropoff_stop_loc) THEN
9545           IF NOT entity_exists(l_dropoff_stop_loc,x_stop_locations,z) THEN
9546              IF l_debug_on THEN
9547                    WSH_DEBUG_SV.logmsg(l_module_name,'Adding trip dropoff stop location id : '||l_dropoff_stop_loc);
9548              END IF;
9549              l_stop_loc_cnt := l_stop_loc_cnt + 1;
9550              x_stop_locations(l_stop_loc_cnt) := l_dropoff_stop_loc;
9551              --x_stop_locations(l_dropoff_stop_loc) := l_dropoff_stop_loc;
9552           END IF;
9553        END IF;
9554 
9555 
9556     END LOOP;
9557     CLOSE c_get_stops;
9558 
9559     --
9560     IF l_debug_on THEN
9561       WSH_DEBUG_SV.logmsg(l_module_name,'x_num_dlegs : '||x_num_dlegs);
9562       WSH_DEBUG_SV.pop(l_module_name);
9563     END IF;
9564     --
9565 
9566 EXCEPTION
9567     WHEN others THEN
9568       IF c_get_stops%ISOPEN THEN
9569          CLOSE c_get_stops;
9570       END IF;
9571       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.get_intmed_stops');
9572       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
9573       IF l_debug_on THEN
9574         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
9575         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
9576       END IF;
9577 
9578 END get_intmed_stops;
9579 
9580 --***************************************************************************--
9581 --========================================================================
9582 -- PROCEDURE : append_current_trip_stops  PRIVATE
9583 --
9584 -- PARAMETERS: p_action_code              Current constraint validation action
9585 --                                        Can be 'ADT' or 'ACT'
9586 --             p_target_stop_info         Input pickup and dropoff stop/location of the delivery(s)
9587 --                                        in the target trip in case of assign delivery to trip
9588 --             p_target_tripstops         Children stops already present in target trip
9589 --             p_entity                   Input entity record for which a group is being searched
9590 --                                        Can be delivery
9591 --             p_entity_all               Table of delivery records in the current action
9592 --             x_stop_locations           List of output locations
9593 --             x_return_status            Return status
9594 -- COMMENT   :
9595 -- Applies to assign delivery to trip and autocreate trip only
9596 -- For a given delivery
9597 -- determine all stop locations in the target trip and
9598 -- the sister deliveries, which are between the delivery's
9599 -- pickup and dropoff location in the target / potential trip
9600 --========================================================================
9601 
9602 PROCEDURE append_current_trip_stops (
9603              p_action_code         IN   VARCHAR2,
9604              p_target_trip_id      IN   NUMBER DEFAULT NULL,
9605              p_target_stop_info    IN   target_tripstop_cc_rec_type,
9606              p_target_tripstops    IN   stop_ccinfo_tab_type,
9607              p_entity              IN   entity_rec_type,
9608              p_entity_all          IN   entity_tab_type,
9609              x_stop_locations      IN OUT NOCOPY   WSH_UTIL_CORE.id_tab_type,
9610              x_return_status       OUT NOCOPY      VARCHAR2)
9611 IS
9612 
9613     l                              NUMBER := NULL;
9614     i                              NUMBER := NULL;
9615     z                              NUMBER := 0;
9616     l_stop_loc_cnt                 NUMBER := x_stop_locations.COUNT;
9617     l_pu_location_id               NUMBER := NULL;
9618     l_pu_sequencenum               NUMBER := NULL;
9619     l_pu_pa_date                   DATE;
9620     l_do_location_id               NUMBER := NULL;
9621     l_do_sequencenum               NUMBER := NULL;
9622     l_do_pa_date                   DATE;
9623 
9624     --#SBAKSHI(08/24)
9625     l_idx			   NUMBER := 0;
9626     --#SBAKSHI(08/24)
9627 
9628     l_module_name                  CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'append_current_trip_stops';
9629     l_debug_on                     CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
9630 
9631 BEGIN
9632 
9633     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
9634 
9635     IF l_debug_on THEN
9636        wsh_debug_sv.push(l_module_name);
9637     END IF;
9638 
9639     IF p_action_code = G_ASSIGN_DLVY_TRIP THEN
9640 
9641       IF p_target_stop_info.pickup_stop_id IS NOT NULL THEN
9642 
9643          OPEN c_get_stop_location(p_target_stop_info.pickup_stop_id);
9644          FETCH c_get_stop_location INTO l_pu_location_id,l_pu_sequencenum,l_pu_pa_date;
9645          CLOSE c_get_stop_location;
9646 
9647       ELSIF p_target_stop_info.pickup_location_id IS NOT NULL THEN
9648 
9649          l_pu_location_id := p_target_stop_info.pickup_location_id;
9650          l_pu_sequencenum := p_target_stop_info.pickup_stop_seq;
9651          l_pu_pa_date := p_target_stop_info.pickup_stop_pa_date;
9652 
9653       ELSIF p_target_stop_info.pickup_stop_id IS NULL THEN
9654        -- check if delivery's initial pu location id already exists
9655        -- in target trip
9656          OPEN c_get_stop(p_entity.initial_pickup_location_id,p_target_trip_id);
9657          FETCH c_get_stop INTO l_pu_sequencenum,l_pu_pa_date;
9658          CLOSE c_get_stop;
9659          IF l_pu_sequencenum IS NOT NULL THEN
9660             l_pu_location_id := p_entity.initial_pickup_location_id;
9661          END IF;
9662 
9663       END IF;
9664 
9665       IF p_target_stop_info.dropoff_stop_id IS NOT NULL THEN
9666 
9667          OPEN c_get_stop_location(p_target_stop_info.dropoff_stop_id);
9668          FETCH c_get_stop_location INTO l_do_location_id,l_do_sequencenum,l_do_pa_date;
9669          CLOSE c_get_stop_location;
9670 
9671       ELSIF p_target_stop_info.dropoff_location_id IS NOT NULL THEN
9672 
9673          l_do_location_id := p_target_stop_info.dropoff_location_id;
9674          l_do_sequencenum := p_target_stop_info.dropoff_stop_seq;
9675          l_do_pa_date := p_target_stop_info.dropoff_stop_pa_date;
9676 
9677       ELSIF p_target_stop_info.dropoff_stop_id IS NULL THEN
9678        -- check if delivery's ultimate do location id already exists
9679        -- in target trip
9680          OPEN c_get_stop(p_entity.ultimate_dropoff_location_id,p_target_trip_id);
9681          FETCH c_get_stop INTO l_do_sequencenum,l_do_pa_date;
9682          CLOSE c_get_stop;
9683          IF l_do_sequencenum IS NOT NULL THEN
9684             l_do_location_id := p_entity.ultimate_dropoff_location_id;
9685          END IF;
9686 
9687       END IF;
9688       IF l_debug_on THEN
9689                WSH_DEBUG_SV.logmsg(l_module_name,'l_pu_location_id : '||l_pu_location_id||' l_pu_sequencenum : '||l_pu_sequencenum||' l_do_location_id : '||l_do_location_id||' l_do_sequencenum : '||l_do_sequencenum);
9690                WSH_DEBUG_SV.logmsg(l_module_name,'l_pu_pa_date : '||to_char(l_pu_pa_date,'DD-MON-YYYY HH24:MI:SS')||' l_do_pa_date : '||to_char(l_do_pa_date,'DD-MON-YYYY HH24:MI:SS'));
9691       END IF;
9692 
9693     END IF;
9694 
9695     l := p_entity_all.FIRST;
9696     IF l IS NOT NULL THEN
9697         LOOP -- Over each entity in that group
9698 
9699             --
9700             IF l_debug_on THEN
9701                   WSH_DEBUG_SV.logmsg(l_module_name,'for entity : '||p_entity.entity_id||' searching entity : '||p_entity_all(l).entity_id);
9702                   WSH_DEBUG_SV.logmsg(l_module_name,'outside entity group id : '||p_entity.group_id||' searching entity group id : '||p_entity_all(l).group_id);
9703                   WSH_DEBUG_SV.logmsg(l_module_name,'locations for entity : '||p_entity.initial_pickup_location_id||' : '||p_entity.ultimate_dropoff_location_id);
9704                   WSH_DEBUG_SV.logmsg(l_module_name,'locations for searching entity : '||p_entity_all(l).initial_pickup_location_id||' : '||p_entity_all(l).ultimate_dropoff_location_id);
9705             END IF;
9706             --
9707 
9708             IF p_entity_all(l).entity_id = p_entity.entity_id OR
9709                    p_entity.group_id <> p_entity_all(l).group_id THEN
9710                    GOTO subennextpass;
9711             END IF;
9712 
9713             -- Need to consider sequence number
9714             -- If l_pu_location_id and l_do_location_id both are null
9715             -- then can not consider sequence number as in that case sequence number
9716             -- is arbitrary for new stops
9717 
9718             IF l_pu_location_id IS NULL AND l_do_location_id IS NULL THEN
9719 
9720               IF ( p_entity_all(l).initial_pickup_location_id <> p_entity.initial_pickup_location_id)
9721               THEN
9722 
9723                       --IF NOT x_stop_locations.EXISTS(p_entity_all(l).initial_pickup_location_id) THEN
9724                       IF NOT entity_exists(p_entity_all(l).initial_pickup_location_id,x_stop_locations,z) THEN
9725                           l_stop_loc_cnt := l_stop_loc_cnt + 1;
9726                           x_stop_locations(l_stop_loc_cnt) := p_entity_all(l).initial_pickup_location_id;
9727                           --x_stop_locations(p_entity_all(l).initial_pickup_location_id) := p_entity_all(l).initial_pickup_location_id;
9728                       END IF;
9729 
9730               END IF;
9731 
9732               IF (p_entity_all(l).ultimate_dropoff_location_id <> p_entity.ultimate_dropoff_location_id)
9733               THEN
9734 
9735                       --IF NOT x_stop_locations.EXISTS(p_entity_all(l).ultimate_dropoff_location_id) THEN
9736                       IF NOT entity_exists(p_entity_all(l).ultimate_dropoff_location_id,x_stop_locations,z) THEN
9737                           l_stop_loc_cnt := l_stop_loc_cnt + 1;
9738                           x_stop_locations(l_stop_loc_cnt) := p_entity_all(l).ultimate_dropoff_location_id;
9739                           --x_stop_locations(p_entity_all(l).ultimate_dropoff_location_id) := p_entity_all(l).ultimate_dropoff_location_id;
9740                       END IF;
9741 
9742               END IF;
9743 
9744             -- For following 2 cases what happens if pickup sequence numbers become
9745             -- greater than drop off sequence numbers ??
9746 
9747             ELSIF l_pu_location_id IS NOT NULL AND l_do_location_id IS NULL THEN
9748 
9749               IF (p_entity_all(l).ultimate_dropoff_location_id <> p_entity.ultimate_dropoff_location_id)
9750               THEN
9751 
9752                       --IF NOT x_stop_locations.EXISTS(p_entity_all(l).ultimate_dropoff_location_id) THEN
9753                       IF NOT entity_exists(p_entity_all(l).ultimate_dropoff_location_id,x_stop_locations,z) THEN
9754                           l_stop_loc_cnt := l_stop_loc_cnt + 1;
9755                           x_stop_locations(l_stop_loc_cnt) := p_entity_all(l).ultimate_dropoff_location_id;
9756                           --x_stop_locations(p_entity_all(l).ultimate_dropoff_location_id) := p_entity_all(l).ultimate_dropoff_location_id;
9757                       END IF;
9758 
9759               END IF;
9760 
9761             ELSIF l_do_location_id IS NOT NULL AND l_pu_location_id IS NULL THEN
9762 
9763               IF ( p_entity_all(l).initial_pickup_location_id <> p_entity.initial_pickup_location_id)
9764               THEN
9765 
9766                       --IF NOT x_stop_locations.EXISTS(p_entity_all(l).initial_pickup_location_id) THEN
9767                       IF NOT entity_exists(p_entity_all(l).initial_pickup_location_id,x_stop_locations,z) THEN
9768                           l_stop_loc_cnt := l_stop_loc_cnt + 1;
9769                           x_stop_locations(l_stop_loc_cnt) := p_entity_all(l).initial_pickup_location_id;
9770                           --x_stop_locations(p_entity_all(l).initial_pickup_location_id) := p_entity_all(l).initial_pickup_location_id;
9771                       END IF;
9772 
9773               END IF;
9774 
9775             END IF;
9776 
9777             <<subennextpass>>
9778 
9779             EXIT WHEN l= p_entity_all.LAST;
9780             l:= p_entity_all.NEXT(l);
9781         END LOOP;
9782     END IF;
9783 
9784     IF p_action_code = G_ASSIGN_DLVY_TRIP THEN
9785 
9786        i := p_target_tripstops.FIRST;
9787        IF i IS NOT NULL THEN
9788            LOOP -- over p_target_tripstops
9789 
9790             -- Select only those stops which lie between(inclusive) stop sequence numbers
9791             -- of the input delivery's pickup and dropoff stops in this target trip
9792 
9793             --
9794             IF l_debug_on THEN
9795                WSH_DEBUG_SV.logmsg(l_module_name,'for child stop : '||p_target_tripstops(i).stop_id||' location : '||p_target_tripstops(i).stop_location_id||' sequence : '||
9796                p_target_tripstops(i).stop_sequence_number||' Planned Arrival Date : '||p_target_tripstops(i).planned_arrival_date);
9797             END IF;
9798             --
9799 
9800       -- AGDUMMY
9801       -- Check if this stop is a physical stop corresponding to an already checked dummy stop
9802       -- If Yes, skip the check
9803 
9804 	    -- Should we include the tripstop always
9805             -- if input pickup/drop off stop/location both are null
9806 
9807 	    --SBAKSHI (pseudo)
9808             -- p_target_tripstops is sorted according to planned_arrival_dates.
9809             -- Dummy stop and physical stop will occur in adjacent positions.
9810 	    -- Dummy stop and then the physical stop.
9811 	    -- In case previous record is for a dummy location,Do not add the current record.
9812 
9813 	    l_idx := 	p_target_tripstops.prior(i);
9814 
9815 	    IF (p_target_tripstops(i).stop_location_id <> p_entity.initial_pickup_location_id
9816                AND ( p_target_tripstops(i).planned_arrival_date > nvl(l_pu_pa_date,p_entity.initial_pickup_date) ) )
9817                AND (p_target_tripstops(i).stop_location_id <> p_entity.ultimate_dropoff_location_id
9818                AND ( p_target_tripstops(i).planned_arrival_date <= nvl(l_do_pa_date,p_entity.ultimate_dropoff_date) ) )
9819                AND NOT (l_idx IS NOT NULL AND p_target_tripstops(l_idx).physical_location_id IS NOT NULL
9820 	                AND p_target_tripstops(i).trip_id = p_target_tripstops(l_idx).trip_id
9821 			AND p_target_tripstops(i).stop_location_id = p_target_tripstops(l_idx).physical_location_id)
9822             THEN
9823 
9824                    IF NOT entity_exists(p_target_tripstops(i).stop_location_id,x_stop_locations,z) THEN
9825                    IF l_debug_on THEN
9826                       WSH_DEBUG_SV.logmsg(l_module_name,'Adding target trip stop location id : '||p_target_tripstops(i).stop_location_id);
9827                    END IF;
9828                    l_stop_loc_cnt := l_stop_loc_cnt + 1;
9829                    x_stop_locations(l_stop_loc_cnt) := p_target_tripstops(i).stop_location_id;
9830                    --x_stop_locations(p_target_tripstops(i).stop_location_id) := p_target_tripstops(i).stop_location_id;
9831             END IF;
9832 
9833             END IF;
9834 
9835             EXIT WHEN i= p_target_tripstops.LAST;
9836             i:= p_target_tripstops.NEXT(i);
9837 	   END LOOP;
9838        END IF;
9839 
9840     END IF;
9841 
9842     --
9843     IF l_debug_on THEN
9844       WSH_DEBUG_SV.pop(l_module_name);
9845     END IF;
9846     --
9847 
9848 EXCEPTION
9849     WHEN others THEN
9850       IF c_get_stop_location%ISOPEN THEN
9851          CLOSE c_get_stop_location;
9852       END IF;
9853       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.append_current_trip_stops');
9854       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
9855       IF l_debug_on THEN
9856         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
9857         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
9858       END IF;
9859 
9860 END append_current_trip_stops;
9861 
9862 
9863 --***************************************************************************--
9864 --========================================================================
9865 -- PROCEDURE : validate_positive_constraint PRIVATE
9866 --
9867 -- PARAMETERS: p_action_code                Current constraint validation action
9868 --                                          Can be 'ADT' or 'ACT'
9869 --             p_comp_class_tab             Table of Compatibility class codes to check
9870 --             p_entity_tab                 Table of delivery records in the current action
9871 --             p_group_tab                  Table of entity group records currently formed
9872 --             p_detail_tab                 Children detail records of input delivery record
9873 --             p_target_trip                Target trip record
9874 --             p_target_tripstops           Children stops already present in target trip
9875 --             p_target_stops_info          Input pickup and dropoff stop/location of the delivery(s)
9876 --                                          in the target trip in case of assign delivery to trip
9877 --             x_line_groups                Includes Successful and warning lines
9878 --                                          after constraint check
9879 --                                          Contains information of which input delivery should
9880 --                                          be grouped in which output group for trip creation
9881 --             x_failed_lines               Table of input delivery lines that failed
9882 --                                          constraint check
9883 --             x_failed_constraints         Failed constraint table
9884 --             x_return_status              Return status
9885 -- COMMENT   :
9886 -- Applicable for autocreate trip and assign delivery to trip
9887 -- For a given delivery and a target trip
9888 -- determines if the delivery can be assigned to the target trip
9889 -- OR trip can be created
9890 -- satisfying inclusive constraints
9891 --========================================================================
9892 
9893 PROCEDURE validate_positive_constraint(
9894                     p_action_code         IN VARCHAR2,
9895                     p_comp_class_tab      IN WSH_UTIL_CORE.column_tab_type,
9896                     p_entity_tab          IN OUT NOCOPY entity_tab_type,
9897                     p_group_tab           IN OUT NOCOPY WSH_FTE_COMP_CONSTRAINT_PKG.cc_group_tab_type,
9898                     p_detail_tab          IN detail_ccinfo_tab_type,
9899                     p_target_trip         IN trip_ccinfo_rec_type,
9900                     p_target_tripstops    IN stop_ccinfo_tab_type,
9901                     p_target_stops_info   IN target_tripstop_cc_rec_type,
9902                     x_line_groups         OUT NOCOPY    WSH_FTE_COMP_CONSTRAINT_PKG.line_group_tab_type,
9903                     x_failed_lines        IN OUT NOCOPY WSH_FTE_COMP_CONSTRAINT_PKG.failed_line_tab_type,
9904                     x_failed_constraints  IN OUT NOCOPY line_constraint_tab_type,
9905                     x_return_status       OUT NOCOPY    VARCHAR2)
9906 IS
9907 
9908       i                           NUMBER := 0;
9909       j                           NUMBER := 0;
9910       k                           NUMBER := 0;
9911       t                           NUMBER := x_failed_lines.COUNT;
9912       l                           NUMBER := 0;
9913       m                           NUMBER := 0;
9914       o                           NUMBER := 0;
9915       p                           NUMBER := 0;
9916       l_carrier                   NUMBER := NULL;
9917       l_vehicle_type              NUMBER := NULL;
9918       l_mode                      VARCHAR2(30) := NULL;
9919       l_service_level             VARCHAR2(30) := NULL;
9920       l_carrier_service_inout_rec WSH_CARRIERS_GRP.Carrier_Service_InOut_Rec_Type;
9921       l_out_object2_num           NUMBER:=0;
9922       l_out_object2_char          VARCHAR2(30):=NULL;
9923       l_linegroup_indx            NUMBER := 0;
9924       l_return_status             VARCHAR2(1);
9925       l_inp_dlvy_cus              BOOLEAN := TRUE;
9926       l_cuscus_checked            BOOLEAN := FALSE;
9927       l_curr_dlvy_cus             BOOLEAN := TRUE;
9928       l_cusfac_checked            BOOLEAN := FALSE;
9929       l_supfac_checked            BOOLEAN := FALSE;
9930       l_checked_cus_fac           BOOLEAN := FALSE;
9931       l_checked_cus_fac           BOOLEAN := FALSE;
9932       l_checked_cus_fac           BOOLEAN := FALSE;
9933       l_cuscus_checked            BOOLEAN := FALSE;
9934       l_acd_result                VARCHAR2(1) := 'S';
9935       l_act_result                VARCHAR2(1) := 'S';
9936       l_const_count               NUMBER      := 0;
9937       l_validate_cuscus_result    VARCHAR2(1) := 'S';
9938       l_validate_carrier_result   VARCHAR2(1) := 'S';
9939       l_validate_vehicle_result   VARCHAR2(1) := 'S';
9940       l_validate_mode_result      VARCHAR2(1) := 'S';
9941       l_validate_orgfac_result    VARCHAR2(1) := 'S';
9942       l_validate_cusfac_result    VARCHAR2(1) := 'S';
9943       l_validate_supfac_result    VARCHAR2(1) := 'S';
9944       l_validate_itmfac_result    VARCHAR2(1) := 'S';
9945       l_failed_constraint         line_constraint_rec_type;
9946       l_validate_itmcar_result    VARCHAR2(1) := 'S';
9947       l_validate_itmveh_result    VARCHAR2(1) := 'S';
9948       l_validate_itmmod_result    VARCHAR2(1) := 'S';
9949       l_item_result               VARCHAR2(1) := 'S';
9950       l_stop_locations            WSH_UTIL_CORE.id_tab_type;
9951       l_failed_group              WSH_UTIL_CORE.id_tab_type;
9952       l_pu_checked                BOOLEAN := FALSE;
9953       l_do_checked                BOOLEAN := FALSE;
9954       l_pu_car_failed             BOOLEAN := FALSE;
9955       l_pu_mod_failed             BOOLEAN := FALSE;
9956       l_pu_veh_failed             BOOLEAN := FALSE;
9957       l_do_car_failed             BOOLEAN := FALSE;
9958       l_do_mod_failed             BOOLEAN := FALSE;
9959       l_do_veh_failed             BOOLEAN := FALSE;
9960       l_last_trip                 BOOLEAN := FALSE;
9961       l_vehicle_name              VARCHAR2(2000);
9962       l_vehicle_org_name          VARCHAR2(240);
9963 
9964       l_direct_shipment           BOOLEAN := TRUE;
9965       l_num_dlegs                 NUMBER      := 0;
9966 
9967       l_delivery_ids              WSH_UTIL_CORE.id_tab_type;
9968       l_tmp_count                 NUMBER := 0;
9969 
9970     l_module_name                 CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'validate_positive_constraint';
9971     l_debug_on                    CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
9972 
9973 BEGIN
9974 
9975     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
9976 
9977     IF l_debug_on THEN
9978        wsh_debug_sv.push(l_module_name);
9979        WSH_DEBUG_SV.logmsg(l_module_name,'p_target_stops_info.pickup_location_id : '||p_target_stops_info.pickup_location_id);
9980        WSH_DEBUG_SV.logmsg(l_module_name,'p_target_stops_info.dropoff_location_id : '||p_target_stops_info.dropoff_location_id);
9981     END IF;
9982 
9983     IF (p_target_trip.carrier_id IS NULL OR p_target_trip.MODE_OF_TRANSPORT IS NULL) AND
9984        (p_target_trip.ship_method_code IS NOT NULL) THEN
9985       l_carrier_service_inout_rec.ship_method_code := p_target_trip.ship_method_code;
9986 
9987       WSH_CARRIERS_GRP.get_carrier_service_mode(
9988                p_carrier_service_inout_rec   =>  l_carrier_service_inout_rec,
9989                x_return_status       =>  l_return_status);
9990 
9991       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
9992         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
9993          IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
9994             raise FND_API.G_EXC_UNEXPECTED_ERROR;
9995          END IF;
9996          raise g_get_carrmode_failed;
9997         END IF;
9998       END IF;
9999       l_carrier := l_carrier_service_inout_rec.carrier_id;
10000       l_mode    := l_carrier_service_inout_rec.mode_of_transport;
10001 
10002     END IF; -- p_target_trip.carrier_id IS NULL OR ..
10003 
10004     -- If carrier_id or mode is passed in, then those get preference for validation
10005     -- If they are not, they are derived from ship method if that is passed
10006 
10007     IF p_target_trip.carrier_id IS NOT NULL THEN
10008        l_carrier := p_target_trip.carrier_id;
10009     END IF;
10010     IF p_target_trip.MODE_OF_TRANSPORT IS NOT NULL THEN
10011        l_mode := p_target_trip.MODE_OF_TRANSPORT;
10012     END IF;
10013 
10014     IF (p_target_trip.VEHICLE_ITEM_ID IS NOT NULL AND p_target_trip.VEHICLE_ORGANIZATION_ID IS NOT NULL) THEN
10015 
10016       WSH_FTE_INTEGRATION.get_vehicle_type(
10017                p_vehicle_item_id     =>  p_target_trip.VEHICLE_ITEM_ID,
10018                p_vehicle_org_id      =>  p_target_trip.VEHICLE_ORGANIZATION_ID,
10019                x_vehicle_type_id     =>  l_vehicle_type,
10020                x_return_status       =>  l_return_status);
10021 
10022       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10023         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10024          IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
10025             raise FND_API.G_EXC_UNEXPECTED_ERROR;
10026          END IF;
10027             l_vehicle_name := WSH_UTIL_CORE.get_item_name (p_item_id => p_target_trip.VEHICLE_ITEM_ID,
10028                                                            p_organization_id => p_target_trip.VEHICLE_ORGANIZATION_ID);
10029             l_vehicle_org_name := WSH_UTIL_CORE.get_org_name (p_organization_id => p_target_trip.VEHICLE_ORGANIZATION_ID);
10030             FND_MESSAGE.SET_NAME('WSH','WSH_VEHICLE_TYPE_UNDEFINED');
10031             FND_MESSAGE.SET_TOKEN('ITEM',l_vehicle_name);
10032             FND_MESSAGE.SET_TOKEN('ORGANIZATION',l_vehicle_org_name);
10033             FND_MSG_PUB.ADD;
10034          --raise g_get_vehicletype_failed;
10035         END IF;
10036       END IF;
10037 
10038     END IF; -- p_target_trip.VEHICLE_ITEM_ID IS NOT NULL AND ..
10039 
10040     IF p_action_code = G_ASSIGN_DLVY_TRIP THEN
10041 
10042         IF p_target_stops_info.pickup_location_id IS NOT NULL THEN
10043 
10044          l_pu_checked := TRUE;
10045 
10046          IF p_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) AND
10047             l_carrier IS NOT NULL AND p_target_stops_info.pickup_stop_id IS NULL THEN
10048 
10049             check_inclusive_object2(
10050              p_comp_class_code          =>      G_FACILITY_CARRIER,
10051              p_entity_type              =>      G_LOCATION,
10052              p_entity_id                =>      p_target_stops_info.pickup_location_id,
10053              p_object1_type             =>      'FAC',
10054              p_object1_val_num          =>      p_target_stops_info.pickup_location_id,
10055              p_object2_type             =>      'CAR',
10056              p_object2_val_num          =>      l_carrier,
10057              x_out_object2_num          =>      l_out_object2_num,
10058              x_out_object2_char         =>      l_out_object2_char,
10059              x_validate_result          =>      l_validate_carrier_result,
10060              x_failed_constraint        =>      x_failed_constraints,
10061              x_return_status            =>      l_return_status);
10062 
10063             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10064                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10065                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
10066                END IF;
10067             END IF;
10068 
10069             IF l_validate_carrier_result = 'F' THEN
10070 
10071                l_pu_car_failed := TRUE;
10072 
10073             END IF;
10074 
10075          END IF;
10076 
10077          IF p_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) AND
10078             l_mode IS NOT NULL AND p_target_stops_info.pickup_stop_id IS NULL THEN
10079 
10080             check_inclusive_object2(
10081              p_comp_class_code          =>      G_FACILITY_MODE,
10082              p_entity_type              =>      G_LOCATION,
10083              p_entity_id                =>      p_target_stops_info.pickup_location_id,
10084              p_object1_type             =>      'FAC',
10085              p_object1_val_num          =>      p_target_stops_info.pickup_location_id,
10086              p_object2_type             =>      'MOD',
10087              p_object2_val_char         =>      l_mode,
10088              x_out_object2_num          =>      l_out_object2_num,
10089              x_out_object2_char         =>      l_out_object2_char,
10090              x_validate_result          =>      l_validate_mode_result,
10091              x_failed_constraint        =>      x_failed_constraints,
10092              x_return_status            =>      l_return_status);
10093 
10094             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10095                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10096                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
10097                END IF;
10098             END IF;
10099 
10100             IF l_validate_mode_result = 'F' THEN
10101 
10102                l_pu_mod_failed := TRUE;
10103 
10104             END IF;
10105 
10106          END IF;
10107 
10108          IF p_comp_class_tab.EXISTS(G_FACILITY_VEHICLE_NUM) AND
10109             l_vehicle_type IS NOT NULL AND p_target_stops_info.pickup_stop_id IS NULL THEN
10110 
10111             check_inclusive_object2(
10112              p_comp_class_code          =>      G_FACILITY_VEHICLE,
10113              p_entity_type              =>      G_LOCATION,
10114              p_entity_id                =>      p_target_stops_info.pickup_location_id,
10115              p_object1_type             =>      'FAC',
10116              p_object1_val_num          =>      p_target_stops_info.pickup_location_id,
10117              p_object2_type             =>      'VHT',
10118              p_object2_val_num          =>      l_vehicle_type,
10119              x_out_object2_num          =>      l_out_object2_num,
10120              x_out_object2_char         =>      l_out_object2_char,
10121              x_validate_result          =>      l_validate_vehicle_result,
10122              x_failed_constraint        =>      x_failed_constraints,
10123              x_return_status            =>      l_return_status);
10124 
10125             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10126                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10127                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
10128                END IF;
10129             END IF;
10130 
10131             IF l_validate_vehicle_result = 'F' THEN
10132 
10133                l_pu_veh_failed := TRUE;
10134 
10135             END IF;
10136 
10137          END IF;
10138 
10139         END IF;
10140 
10141         IF p_target_stops_info.dropoff_location_id IS NOT NULL THEN
10142 
10143          l_do_checked := TRUE;
10144 
10145          IF p_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) AND
10146             l_carrier IS NOT NULL AND p_target_stops_info.dropoff_stop_id IS NULL THEN
10147 
10148             check_inclusive_object2(
10149              p_comp_class_code          =>      G_FACILITY_CARRIER,
10150              p_entity_type              =>      G_LOCATION,
10151              p_entity_id                =>      p_target_stops_info.dropoff_location_id,
10152              p_object1_type             =>      'FAC',
10153              p_object1_val_num          =>      p_target_stops_info.dropoff_location_id,
10154              p_object2_type             =>      'CAR',
10155              p_object2_val_num          =>      l_carrier,
10156              x_out_object2_num          =>      l_out_object2_num,
10157              x_out_object2_char         =>      l_out_object2_char,
10158              x_validate_result          =>      l_validate_carrier_result,
10159              x_failed_constraint        =>      x_failed_constraints,
10160              x_return_status            =>      l_return_status);
10161 
10162             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10163                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10164                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
10165                END IF;
10166             END IF;
10167 
10168             IF l_validate_carrier_result = 'F' THEN
10169 
10170                l_do_car_failed := TRUE;
10171 
10172             END IF;
10173 
10174          END IF;
10175 
10176          IF p_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) AND
10177             l_mode IS NOT NULL AND p_target_stops_info.dropoff_stop_id IS NULL THEN
10178 
10179             check_inclusive_object2(
10180              p_comp_class_code          =>      G_FACILITY_MODE,
10181              p_entity_type              =>      G_LOCATION,
10182              p_entity_id                =>      p_target_stops_info.dropoff_location_id,
10183              p_object1_type             =>      'FAC',
10184              p_object1_val_num          =>      p_target_stops_info.dropoff_location_id,
10185              p_object2_type             =>      'MOD',
10186              p_object2_val_char         =>      l_mode,
10187              x_out_object2_num          =>      l_out_object2_num,
10188              x_out_object2_char         =>      l_out_object2_char,
10189              x_validate_result          =>      l_validate_mode_result,
10190              x_failed_constraint        =>      x_failed_constraints,
10191              x_return_status            =>      l_return_status);
10192 
10193             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10194                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10195                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
10196                END IF;
10197             END IF;
10198 
10199             IF l_validate_mode_result = 'F' THEN
10200 
10201                l_do_mod_failed := TRUE;
10202 
10203             END IF;
10204 
10205          END IF;
10206 
10207          IF p_comp_class_tab.EXISTS(G_FACILITY_VEHICLE_NUM) AND
10208             l_vehicle_type IS NOT NULL AND p_target_stops_info.dropoff_stop_id IS NULL THEN
10209 
10210             check_inclusive_object2(
10211              p_comp_class_code          =>      G_FACILITY_VEHICLE,
10212              p_entity_type              =>      G_LOCATION,
10213              p_entity_id                =>      p_target_stops_info.dropoff_location_id,
10214              p_object1_type             =>      'FAC',
10215              p_object1_val_num          =>      p_target_stops_info.dropoff_location_id,
10216              p_object2_type             =>      'VHT',
10217              p_object2_val_num          =>      l_vehicle_type,
10218              x_out_object2_num          =>      l_out_object2_num,
10219              x_out_object2_char         =>      l_out_object2_char,
10220              x_validate_result          =>      l_validate_vehicle_result,
10221              x_failed_constraint        =>      x_failed_constraints,
10222              x_return_status            =>      l_return_status);
10223 
10224             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10225                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10226                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
10227                END IF;
10228             END IF;
10229 
10230             IF l_validate_vehicle_result = 'F' THEN
10231 
10232                l_do_veh_failed := TRUE;
10233 
10234             END IF;
10235 
10236          END IF;
10237 
10238         END IF;
10239 
10240     END IF;
10241 
10242     -- First check org -fac, cus -fac, itm -fac for every entity
10243     -- against other locations in the same group
10244     -- Supplier - Facility
10245 
10246 
10247     IF p_action_code = G_ASSIGN_DLVY_TRIP THEN
10248 
10249     -- LOOP over p_entity_tab to populate l_delivery_ids dense table
10250     -- use it to bulk insert into the global temp table
10251     p := p_entity_tab.FIRST;
10252     IF p IS NOT NULL THEN
10253         LOOP -- Over each entity in that group
10254 
10255           o := o+1;
10256           l_delivery_ids(o) := p_entity_tab(p).entity_id;
10257 
10258           EXIT WHEN p = p_entity_tab.LAST;
10259           p:= p_entity_tab.NEXT(p);
10260         END LOOP;
10261     END IF;
10262 
10263     IF l_delivery_ids.COUNT > 0 THEN
10264 
10265     IF l_debug_on THEN
10266              WSH_DEBUG_SV.logmsg(l_module_name,'Inserting into wsh_constraint_dleg_tmp ');
10267     END IF;
10268 
10269 
10270     FORALL q in l_delivery_ids.FIRST..l_delivery_ids.LAST
10271     INSERT INTO wsh_constraint_dleg_tmp (
10272     SELECT wdl.delivery_leg_id,wdl.sequence_number,
10273            wdl.pick_up_stop_id, wdl.drop_off_stop_id,
10274            nvl(wts1.physical_location_id,wts1.stop_location_id) ,
10275            nvl(wts2.physical_location_id,wts2.stop_location_id) ,
10276            wts1.planned_arrival_date ,
10277            wts2.planned_arrival_date ,
10278            wts1.trip_id,
10279            wdl.delivery_id
10280     FROM   wsh_delivery_legs wdl,
10281            wsh_trip_stops wts1,
10282            wsh_trip_stops wts2
10283     WHERE  wdl.delivery_id = l_delivery_ids(q)
10284     AND    wdl.pick_up_stop_id = wts1.stop_id
10285     AND    wdl.drop_off_stop_id = wts2.stop_id
10286     AND    wdl.delivery_leg_id NOT IN
10287            ( select wcdt.delivery_leg_id
10288              from wsh_constraint_dleg_tmp wcdt
10289              where wcdt.delivery_leg_id = wdl.delivery_leg_id)
10290     );
10291 
10292     /*
10293     SELECT COUNT(*)
10294     INTO l_tmp_count
10295     FROM wsh_constraint_dleg_tmp;
10296 
10297     IF l_debug_on THEN
10298              WSH_DEBUG_SV.logmsg(l_module_name,'Inserted :'||l_tmp_count||' rows into wsh_constraint_dleg_tmp ');
10299     END IF;
10300     */
10301 
10302     ELSE
10303        IF l_debug_on THEN
10304              WSH_DEBUG_SV.logmsg(l_module_name,'No records present in l_delivery_ids');
10305        END IF;
10306     END IF;
10307     END IF;
10308 
10309     k := p_entity_tab.FIRST;
10310     IF k IS NOT NULL THEN
10311         LOOP -- Over each entity in that group
10312 
10313           IF p_entity_tab(k).shipping_control = 'SUPPLIER' THEN
10314              GOTO entity_nextpass;
10315           END IF;
10316 
10317           l_stop_locations.DELETE;
10318           l_item_result := 'S';
10319           l_last_trip := FALSE;
10320           l_direct_shipment := TRUE;
10321 
10322           -- If ADT check locations of p_entity_tab(k) against carrier,mode of p_target_trip
10323 
10324           -- Check delivery's initial pickup only if that location is the pickup of that
10325           -- delivery in that trip. Same applies to ultimate dropoff.
10326           -- So if input pickup_stop_id has been passed, this check does not apply.
10327           -- Same for dropoff_stop_id.
10328           -- Applies against pickup_location_id/dropoff_location_id if they have been input
10329 
10330           IF p_action_code = G_ASSIGN_DLVY_TRIP THEN
10331 
10332 	    IF l_debug_on THEN
10333 	       WSH_DEBUG_SV.logmsg(l_module_name,'p_entity_tab(k).entity_id : '||p_entity_tab(k).entity_id);
10334 	       WSH_DEBUG_SV.logmsg(l_module_name,'p_entity_tab(k).initial_pickup_location_id : '||p_entity_tab(k).initial_pickup_location_id);
10335 	       WSH_DEBUG_SV.logmsg(l_module_name,'p_entity_tab(k).ultimate_dropoff_location_id : '||p_entity_tab(k).ultimate_dropoff_location_id);
10336 	    END IF;
10337             -- Take care that for pickup/dropoff location id input same check is not done
10338             -- more than once
10339 
10340       -- Facility  - Vehicle
10341 
10342            IF p_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) AND
10343               l_carrier IS NOT NULL THEN
10344 
10345             IF p_target_stops_info.pickup_stop_id IS NULL AND ( NOT l_pu_checked) THEN
10346 
10347               check_inclusive_object2(
10348                p_comp_class_code          =>      G_FACILITY_CARRIER,
10349                p_entity_type              =>      G_DELIVERY,
10350                p_entity_id                =>      p_entity_tab(k).entity_id,
10351                p_object1_type             =>      'FAC',
10352                p_object1_val_num          =>      p_entity_tab(k).initial_pickup_location_id,
10353                p_object2_type             =>      'CAR',
10354                p_object2_val_num          =>      l_carrier,
10355                x_out_object2_num          =>      l_out_object2_num,
10356                x_out_object2_char         =>      l_out_object2_char,
10357                x_validate_result          =>      l_validate_carrier_result,
10358                x_failed_constraint        =>      x_failed_constraints,
10359                x_return_status            =>      l_return_status);
10360 
10361               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10362                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10363                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
10364                  END IF;
10365               END IF;
10366 
10367               IF l_validate_carrier_result = 'F' THEN
10368                  p_entity_tab.DELETE(k);
10369                  t := t+1;
10370                  x_failed_lines(t).failed_line_index := t;
10371                  x_failed_lines(t).entity_line_id := k;
10372                  GOTO entity_nextpass;
10373               END IF;
10374 
10375             ELSIF l_pu_checked AND l_pu_car_failed THEN
10376 
10377                  p_entity_tab.DELETE(k);
10378                  t := t+1;
10379                  x_failed_lines(t).failed_line_index := t;
10380                  x_failed_lines(t).entity_line_id := k;
10381                  GOTO entity_nextpass;
10382 
10383             END IF;
10384 
10385             IF p_target_stops_info.dropoff_stop_id IS NULL AND ( NOT l_do_checked) THEN
10386 
10387               check_inclusive_object2(
10388                p_comp_class_code          =>      G_FACILITY_CARRIER,
10389                p_entity_type              =>      G_DELIVERY,
10390                p_entity_id                =>      p_entity_tab(k).entity_id,
10391                p_object1_type             =>      'FAC',
10392                p_object1_val_num          =>      p_entity_tab(k).ultimate_dropoff_location_id,
10393                p_object2_type             =>      'CAR',
10394                p_object2_val_num          =>      l_carrier,
10395                x_out_object2_num          =>      l_out_object2_num,
10396                x_out_object2_char         =>      l_out_object2_char,
10397                x_validate_result          =>      l_validate_carrier_result,
10398                x_failed_constraint        =>      x_failed_constraints,
10399                x_return_status            =>      l_return_status);
10400 
10401               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10402                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10403                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
10404                  END IF;
10405               END IF;
10406 
10407               IF l_validate_carrier_result = 'F' THEN
10408                  p_entity_tab.DELETE(k);
10409                  t := t+1;
10410                  x_failed_lines(t).failed_line_index := t;
10411                  x_failed_lines(t).entity_line_id := k;
10412                  GOTO entity_nextpass;
10413               END IF;
10414 
10415             ELSIF l_do_checked AND l_do_car_failed THEN
10416 
10417                  p_entity_tab.DELETE(k);
10418                  t := t+1;
10419                  x_failed_lines(t).failed_line_index := t;
10420                  x_failed_lines(t).entity_line_id := k;
10421                  GOTO entity_nextpass;
10422 
10423             END IF;
10424 
10425            END IF;
10426 
10427            IF p_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) AND
10428               l_mode IS NOT NULL THEN
10429 
10430             IF p_target_stops_info.pickup_stop_id IS NULL AND ( NOT l_pu_checked) THEN
10431 
10432               check_inclusive_object2(
10433                p_comp_class_code          =>      G_FACILITY_MODE,
10434                p_entity_type              =>      G_DELIVERY,
10435                p_entity_id                =>      p_entity_tab(k).entity_id,
10436                p_object1_type             =>      'FAC',
10437                p_object1_val_num          =>      p_entity_tab(k).initial_pickup_location_id,
10438                p_object2_type             =>      'MOD',
10439                p_object2_val_char         =>      l_mode,
10440                x_out_object2_num          =>      l_out_object2_num,
10441                x_out_object2_char         =>      l_out_object2_char,
10442                x_validate_result          =>      l_validate_mode_result,
10443                x_failed_constraint        =>      x_failed_constraints,
10444                x_return_status            =>      l_return_status);
10445 
10446               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10447                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10448                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
10449                  END IF;
10450               END IF;
10451 
10452               IF l_validate_mode_result = 'F' THEN
10453                  p_entity_tab.DELETE(k);
10454                  t := t+1;
10455                  x_failed_lines(t).failed_line_index := t;
10456                  x_failed_lines(t).entity_line_id := k;
10457                  GOTO entity_nextpass;
10458               END IF;
10459 
10460             ELSIF l_pu_checked AND l_pu_mod_failed THEN
10461 
10462                  p_entity_tab.DELETE(k);
10463                  t := t+1;
10464                  x_failed_lines(t).failed_line_index := t;
10465                  x_failed_lines(t).entity_line_id := k;
10466                  GOTO entity_nextpass;
10467 
10468             END IF;
10469 
10470             IF p_target_stops_info.dropoff_stop_id IS NULL AND ( NOT l_do_checked) THEN
10471 
10472               check_inclusive_object2(
10473                p_comp_class_code          =>      G_FACILITY_MODE,
10474                p_entity_type              =>      G_DELIVERY,
10475                p_entity_id                =>      p_entity_tab(k).entity_id,
10476                p_object1_type             =>      'FAC',
10477                p_object1_val_num          =>      p_entity_tab(k).ultimate_dropoff_location_id,
10478                p_object2_type             =>      'MOD',
10479                p_object2_val_char         =>      l_mode,
10480                x_out_object2_num          =>      l_out_object2_num,
10481                x_out_object2_char         =>      l_out_object2_char,
10482                x_validate_result          =>      l_validate_mode_result,
10483                x_failed_constraint        =>      x_failed_constraints,
10484                x_return_status            =>      l_return_status);
10485 
10486               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10487                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10488                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
10489                   END IF;
10490               END IF;
10491 
10492               IF l_validate_mode_result = 'F' THEN
10493                  p_entity_tab.DELETE(k);
10494                  t := t+1;
10495                  x_failed_lines(t).failed_line_index := t;
10496                  x_failed_lines(t).entity_line_id := k;
10497                  GOTO entity_nextpass;
10498               END IF;
10499 
10500             ELSIF l_do_checked AND l_do_mod_failed THEN
10501 
10502                  p_entity_tab.DELETE(k);
10503                  t := t+1;
10504                  x_failed_lines(t).failed_line_index := t;
10505                  x_failed_lines(t).entity_line_id := k;
10506                  GOTO entity_nextpass;
10507 
10508             END IF;
10509 
10510            END IF;
10511            IF p_comp_class_tab.EXISTS(G_FACILITY_VEHICLE_NUM) AND
10512               l_vehicle_type IS NOT NULL THEN
10513 
10514             IF p_target_stops_info.pickup_stop_id IS NULL AND ( NOT l_pu_checked) THEN
10515 
10516               check_inclusive_object2(
10517                p_comp_class_code          =>      G_FACILITY_VEHICLE,
10518                p_entity_type              =>      G_DELIVERY,
10519                p_entity_id                =>      p_entity_tab(k).entity_id,
10520                p_object1_type             =>      'FAC',
10521                p_object1_val_num          =>      p_entity_tab(k).initial_pickup_location_id,
10522                p_object2_type             =>      'VHT',
10523                p_object2_val_num          =>      l_vehicle_type,
10524                x_out_object2_num          =>      l_out_object2_num,
10525                x_out_object2_char         =>      l_out_object2_char,
10526                x_validate_result          =>      l_validate_vehicle_result,
10527                x_failed_constraint        =>      x_failed_constraints,
10528                x_return_status            =>      l_return_status);
10529 
10530               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10531                      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10532                         raise FND_API.G_EXC_UNEXPECTED_ERROR;
10533                      END IF;
10534               END IF;
10535 
10536               IF l_validate_vehicle_result = 'F' THEN
10537                  p_entity_tab.DELETE(k);
10538                  t := t+1;
10539                  x_failed_lines(t).failed_line_index := t;
10540                  x_failed_lines(t).entity_line_id := k;
10541                  GOTO entity_nextpass;
10542               END IF;
10543 
10544             ELSIF l_pu_checked AND l_pu_veh_failed THEN
10545 
10546                  p_entity_tab.DELETE(k);
10547                  t := t+1;
10548                  x_failed_lines(t).failed_line_index := t;
10549                  x_failed_lines(t).entity_line_id := k;
10550                  GOTO entity_nextpass;
10551 
10552             END IF;
10553 
10554             IF p_target_stops_info.dropoff_stop_id IS NULL AND ( NOT l_do_checked) THEN
10555 
10556               check_inclusive_object2(
10557                p_comp_class_code          =>      G_FACILITY_VEHICLE,
10558                p_entity_type              =>      G_DELIVERY,
10559                p_entity_id                =>      p_entity_tab(k).entity_id,
10560                p_object1_type             =>      'FAC',
10561                p_object1_val_num          =>      p_entity_tab(k).ultimate_dropoff_location_id,
10562                p_object2_type             =>      'VHT',
10563                p_object2_val_num          =>      l_vehicle_type,
10564                x_out_object2_num          =>      l_out_object2_num,
10565                x_out_object2_char         =>      l_out_object2_char,
10566                x_validate_result          =>      l_validate_vehicle_result,
10567                x_failed_constraint        =>      x_failed_constraints,
10568                x_return_status            =>      l_return_status);
10569 
10570               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10571                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10572                       raise FND_API.G_EXC_UNEXPECTED_ERROR;
10573                    END IF;
10574               END IF;
10575 
10576               IF l_validate_vehicle_result = 'F' THEN
10577                  p_entity_tab.DELETE(k);
10578                  t := t+1;
10579                  x_failed_lines(t).failed_line_index := t;
10580                  x_failed_lines(t).entity_line_id := k;
10581                  GOTO entity_nextpass;
10582               END IF;
10583 
10584             ELSIF l_do_checked AND l_do_veh_failed THEN
10585 
10586                  p_entity_tab.DELETE(k);
10587                  t := t+1;
10588                  x_failed_lines(t).failed_line_index := t;
10589                  x_failed_lines(t).entity_line_id := k;
10590                  GOTO entity_nextpass;
10591 
10592             END IF;
10593 
10594            END IF;
10595 
10596              -- 1. First determine if after assigning to this trip, the delivery
10597              --    is complete
10598 
10599             l_last_trip := is_last_trip (
10600                                p_delivery_id        => p_entity_tab(k).entity_id,
10601                                p_initial_pu_loc_id  => p_entity_tab(k).initial_pickup_location_id,
10602                                p_ultimate_do_loc_id => p_entity_tab(k).ultimate_dropoff_location_id,
10603                                p_target_trip_id       => p_target_trip.trip_id,
10604                                p_target_stops_in_trip => p_target_stops_info,
10605                                x_return_status        => l_return_status);
10606 
10607             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10608                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10609                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
10610                  END IF;
10611             END IF;
10612 
10613 
10614              -- 2. If Yes, proceed to determine all stops from first trip to last trip
10615 
10616             IF l_last_trip THEN
10617 
10618                 -- Start from first trip
10619                 -- Obtain list of stops excluding delivery's initial_pickup and ultimate dropoff
10620                 -- proceed to next trip and obtain all stops of the delivery on it
10621                 -- continue like this
10622 
10623                 IF l_debug_on THEN
10624                    WSH_DEBUG_SV.logmsg(l_module_name,'Trip : '||p_target_trip.trip_id||' is last_trip for current delivery : '||p_entity_tab(k).entity_id);
10625                 END IF;
10626 
10627                 get_intmed_stops (
10628                     p_delivery_id         =>    p_entity_tab(k).entity_id,
10629                     p_pickup_loc_id       =>    p_entity_tab(k).initial_pickup_location_id,
10630                     p_dropoff_loc_id      =>    p_entity_tab(k).ultimate_dropoff_location_id,
10631                     x_num_dlegs           =>    l_num_dlegs,
10632                     x_stop_locations      =>    l_stop_locations,
10633                     x_return_status       =>    l_return_status);
10634 
10635                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10636                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10637                       raise FND_API.G_EXC_UNEXPECTED_ERROR;
10638                    END IF;
10639                 END IF;
10640 
10641                 -- Even if number of dlegs is 1, it means the current assignment
10642                 -- will make it a multileg delivery
10643 
10644                 --IF l_stop_locations.COUNT > 0 THEN
10645                 IF l_num_dlegs >= 1 THEN
10646                    IF l_debug_on THEN
10647                       WSH_DEBUG_SV.logmsg(l_module_name,'current delivery : '||p_entity_tab(k).entity_id||' has '||l_num_dlegs||' delivery legs now and hence will not be direct shipment');
10648                    END IF;
10649 
10650                    l_direct_shipment := FALSE;
10651                 END IF;
10652                  --No need to append all the trip stops as they are not to be used.
10653             END IF;
10654 
10655 	  END IF;
10656 
10657           --
10658           IF l_debug_on THEN
10659             WSH_DEBUG_SV.logmsg(l_module_name,'l_stop_locations count : '||l_stop_locations.COUNT);
10660           END IF;
10661           --
10662 
10663           IF p_action_code = G_AUTOCRT_DLVY_TRIP OR p_action_code = G_AUTOCRT_MDC THEN
10664           -- check if locations of p_entity_tab has
10665           -- a different must be carrier / mode than any other location in l_stop_locations
10666           -- If Yes, create a new group for that
10667              l_const_count   := x_failed_constraints.COUNT;
10668 
10669              check_act_carmode (
10670                       p_comp_class_tab     => p_comp_class_tab,
10671                       p_delivery_rec       => p_entity_tab(k),
10672                       p_group_locations    => l_stop_locations,
10673                       x_failed_constraint  => x_failed_constraints,
10674                       x_validate_result    => l_act_result,
10675                       x_return_status      => l_return_status);
10676 
10677              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10678                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10679                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
10680                  END IF;
10681              END IF;
10682 
10683              IF l_act_result = 'F' THEN
10684 
10685                IF p_entity_tab(k).entity_id IS NULL THEN
10686                  p_entity_tab.DELETE(k);
10687                  t := t+1;
10688                  x_failed_lines(t).failed_line_index := t;
10689                  x_failed_lines(t).entity_line_id := k;
10690                  GOTO entity_nextpass;
10691 
10692                ELSE
10693                  -- Remove p_entity_tab(k) from its current group if it still exists
10694                  -- create a new group for it
10695                  IF ( l_const_count < x_failed_constraints.COUNT) THEN
10696 
10697                       x_failed_constraints.DELETE(l_const_count+1,x_failed_constraints.COUNT);
10698 
10699                  END IF;
10700 
10701                  create_valid_entity_group(
10702                     p_entity_rec            => p_entity_tab(k), -- IN OUT
10703                     p_group_tab             => p_group_tab, -- IN OUT
10704                     x_return_status         => l_return_status);
10705                  --
10706                  IF l_debug_on THEN
10707                    WSH_DEBUG_SV.logmsg(l_module_name,'Called create_valid_entity_group return status : '||l_return_status);
10708                  END IF;
10709                  --
10710 
10711                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10712                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10713                       raise FND_API.G_EXC_UNEXPECTED_ERROR;
10714                    END IF;
10715                  END IF;
10716 
10717                    -- Also remove group record if it does not have children inside
10718 
10719                END IF;
10720              END IF;
10721 
10722           END IF; -- ACT
10723 
10724             -- Check org , cus of p_entity_tab(k) against l_stop_locations
10725 
10726       -- 1.
10727       -- Inclusive facilities should be checked only if the current target trip is found to be
10728       -- the last trip that the input delivery is being assigned to
10729       -- The list of locations for checking inclusive constraints then will include
10730       -- all stops between first pickup and last dropoff of the delivery
10731       -- in all the trips that the delivery is on
10732       -- Take extra care in identifying intersecting stops of the trips as well
10733       -- Stop sequence number determines sequence of the stops
10734 
10735       -- 2.
10736       -- Hence
10737       -- For checking exclusive constraints
10738       -- create a list of locations between delivery's pickup and dropoff in target trip
10739       -- that need to be checked
10740       -- validate org, cus, sup, itm - facility constraint for each delivery
10741       -- against this list each time assign delivery to trip happens
10742 
10743       -- 3.
10744       -- For inclusive constraints
10745       -- determine if the current target trip is the last dleg of the current delivery
10746       -- If yes, create a list of intermediate stop locations considering all trips as 1 above
10747       -- validate org, cus, sup, itm - facility constraint for each delivery against this list
10748 
10749       -- Supplier - Facility
10750           -- alksharm
10751           -- When the action code is G_AUTOCRT_MDC, must use discretionary routing point checks
10752           -- if any will be ignored as those will be enforced later as part of deconsol
10753           -- location derivation for a delivery.
10754 
10755           IF  p_action_code = G_AUTOCRT_DLVY_TRIP OR
10756              (p_action_code = G_ASSIGN_DLVY_TRIP AND l_last_trip) THEN
10757 
10758            IF p_comp_class_tab.EXISTS(G_SHIPORG_FACILITY_NUM) AND
10759               p_entity_tab(k).shipment_direction <> 'D' THEN
10760 
10761               check_inclusive_facilities(
10762                     p_comp_class_code          =>      G_SHIPORG_FACILITY,
10763                     p_entity_type              =>      G_DELIVERY,
10764                     p_entity_id                =>      p_entity_tab(k).entity_id,
10765                     p_attribute_id             =>      p_entity_tab(k).organization_id,
10766                     p_location_list            =>      l_stop_locations,
10767                     p_direct_shipment          =>      l_direct_shipment,
10768                     x_validate_result          =>      l_validate_orgfac_result,
10769                     x_failed_constraint        =>      x_failed_constraints,
10770                     x_return_status            =>      l_return_status);
10771 
10772                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10773                      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10774                         raise FND_API.G_EXC_UNEXPECTED_ERROR;
10775                      END IF;
10776                   END IF;
10777 
10778               IF l_validate_orgfac_result = 'F' THEN
10779                  p_entity_tab.DELETE(k);
10780                  t := t+1;
10781                  x_failed_lines(t).failed_line_index := t;
10782                  x_failed_lines(t).entity_line_id := k;
10783                  GOTO entity_nextpass;
10784               END IF;
10785 
10786            END IF;
10787 
10788            IF p_comp_class_tab.EXISTS(G_CUSTOMER_FACILITY_NUM) AND
10789               p_entity_tab(k).shipment_direction <> 'I' THEN
10790 
10791               -- Need to check for a customer location
10792               -- or all locations of a customer
10793 
10794               check_inclusive_facilities(
10795                     p_comp_class_code          =>      G_CUSTOMER_FACILITY,
10796                     p_entity_type              =>      G_DELIVERY,
10797                     p_entity_id                =>      p_entity_tab(k).entity_id,
10798                     p_object1_type             =>      'FAC',
10799                     p_object1_physical_id      =>      p_entity_tab(k).physical_dropoff_location_id,
10800                     p_attribute_id             =>      p_entity_tab(k).ultimate_dropoff_location_id,
10801                     p_location_list            =>      l_stop_locations,
10802                     p_direct_shipment          =>      l_direct_shipment,
10803                     x_validate_result          =>      l_validate_cusfac_result,
10804                     x_failed_constraint        =>      x_failed_constraints,
10805                     x_return_status            =>      l_return_status);
10806 
10807                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10808                       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10809                          raise FND_API.G_EXC_UNEXPECTED_ERROR;
10810                       END IF;
10811                    END IF;
10812 
10813               IF l_validate_cusfac_result = 'F' THEN
10814                  p_entity_tab.DELETE(k);
10815                  t := t+1;
10816                  x_failed_lines(t).failed_line_index := t;
10817                  x_failed_lines(t).entity_line_id := k;
10818                  GOTO entity_nextpass;
10819               END IF;
10820 
10821 
10822               check_inclusive_facilities(
10823                     p_comp_class_code          =>      G_CUSTOMER_FACILITY,
10824                     p_entity_type              =>      G_DELIVERY,
10825                     p_entity_id                =>      p_entity_tab(k).entity_id,
10826                     p_object1_type             =>      'CUS',
10827                     p_attribute_id             =>      p_entity_tab(k).customer_id,
10828                     p_location_list            =>      l_stop_locations,
10829                     p_direct_shipment          =>      l_direct_shipment,
10830                     x_validate_result          =>      l_validate_cusfac_result,
10831                     x_failed_constraint        =>      x_failed_constraints,
10832                     x_return_status            =>      l_return_status);
10833 
10834                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10835                       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10836                          raise FND_API.G_EXC_UNEXPECTED_ERROR;
10837                       END IF;
10838                    END IF;
10839 
10840               IF l_validate_cusfac_result = 'F' THEN
10841                  p_entity_tab.DELETE(k);
10842                  t := t+1;
10843                  x_failed_lines(t).failed_line_index := t;
10844                  x_failed_lines(t).entity_line_id := k;
10845                  GOTO entity_nextpass;
10846               END IF;
10847 
10848            END IF;
10849 
10850            IF p_comp_class_tab.EXISTS(G_SUPPLIER_FACILITY_NUM) AND
10851               p_entity_tab(k).shipment_direction <> 'O' THEN
10852 
10853               -- Need to check for a customer location
10854               -- or all locations of a customer
10855 
10856               check_inclusive_facilities(
10857                     p_comp_class_code          =>      G_SUPPLIER_FACILITY,
10858                     p_entity_type              =>      G_DELIVERY,
10859                     p_entity_id                =>      p_entity_tab(k).entity_id,
10860                     p_object1_type             =>      'FAC',
10861                     p_attribute_id             =>      p_entity_tab(k).initial_pickup_location_id,
10862                     p_location_list            =>      l_stop_locations,
10863                     p_direct_shipment          =>      l_direct_shipment,
10864                     x_validate_result          =>      l_validate_supfac_result,
10865                     x_failed_constraint        =>      x_failed_constraints,
10866                     x_return_status            =>      l_return_status);
10867 
10868                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10869                       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10870                          raise FND_API.G_EXC_UNEXPECTED_ERROR;
10871                       END IF;
10872                    END IF;
10873 
10874               IF l_validate_supfac_result = 'F' THEN
10875                  p_entity_tab.DELETE(k);
10876                  t := t+1;
10877                  x_failed_lines(t).failed_line_index := t;
10878                  x_failed_lines(t).entity_line_id := k;
10879                  GOTO entity_nextpass;
10880               END IF;
10881 
10882 
10883               check_inclusive_facilities(
10884                     p_comp_class_code          =>      G_SUPPLIER_FACILITY,
10885                     p_entity_type              =>      G_DELIVERY,
10886                     p_entity_id                =>      p_entity_tab(k).entity_id,
10887                     p_object1_type             =>      'SUP',
10888                     p_attribute_id             =>      p_entity_tab(k).party_id,
10889                     p_location_list            =>      l_stop_locations,
10890                     p_direct_shipment          =>      l_direct_shipment,
10891                     x_validate_result          =>      l_validate_supfac_result,
10892                     x_failed_constraint        =>      x_failed_constraints,
10893                     x_return_status            =>      l_return_status);
10894 
10895                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10896                       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10897                          raise FND_API.G_EXC_UNEXPECTED_ERROR;
10898                       END IF;
10899                    END IF;
10900 
10901               IF l_validate_supfac_result = 'F' THEN
10902                  p_entity_tab.DELETE(k);
10903                  t := t+1;
10904                  x_failed_lines(t).failed_line_index := t;
10905                  x_failed_lines(t).entity_line_id := k;
10906                  GOTO entity_nextpass;
10907               END IF;
10908 
10909            END IF;
10910 
10911           END IF;
10912 
10913           IF (p_action_code = G_AUTOCRT_DLVY_TRIP OR  p_action_code = G_AUTOCRT_MDC) AND
10914               (p_entity_tab(k).ship_method_code IS NOT NULL OR
10915                p_entity_tab(k).carrier_id IS NOT NULL OR
10916                p_entity_tab(k).mode_of_transport IS NOT NULL) AND
10917              NOT l_failed_group.EXISTS(p_entity_tab(k).group_id) THEN
10918 
10919              -- Check initial,drop off locations
10920              -- and all items in that sequence
10921              -- against delivery's ship method
10922              -- for Inclusive constraint
10923              -- if for any delivery a violation is found,
10924              -- mark upd_ship_method = 'N' for that delivery's group
10925              -- and no need to check for any other delivery in that group
10926 
10927                 check_act_positive (
10928                       p_comp_class_tab     => p_comp_class_tab,
10929                       p_delivery_rec       => p_entity_tab(k),
10930                       x_failed_constraint  => x_failed_constraints,
10931                       x_validate_result    => l_acd_result,
10932                       x_return_status      => l_return_status);
10933 
10934                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10935                      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10936                         raise FND_API.G_EXC_UNEXPECTED_ERROR;
10937                      END IF;
10938                 END IF;
10939 
10940                 IF l_acd_result = 'F' THEN
10941                    l_failed_group(p_entity_tab(k).group_id) := p_entity_tab(k).group_id;
10942                    p_group_tab(p_entity_tab(k).group_id).upd_dlvy_ship_method := 'N';
10943 
10944                 END IF;
10945 
10946 
10947           END IF;
10948 
10949           m := p_detail_tab.FIRST;
10950           IF m IS NOT NULL THEN
10951            LOOP -- Over each entity in that group
10952 
10953             IF p_detail_tab(m).delivery_id <> p_entity_tab(k).entity_id THEN
10954                 GOTO detail_nextpass;
10955             END IF;
10956 
10957              -- Check itm of p_detail_tab(m) against l_stop_locations
10958             IF  p_action_code = G_AUTOCRT_DLVY_TRIP OR
10959                (p_action_code = G_ASSIGN_DLVY_TRIP AND l_last_trip) THEN
10960 
10961              IF p_comp_class_tab.EXISTS(G_ITEM_FACILITY_NUM) THEN
10962 
10963                 check_inclusive_facilities(
10964                    p_comp_class_code          =>      G_ITEM_FACILITY,
10965                    p_entity_type              =>      G_DEL_DETAIL,
10966                    p_entity_id                =>      p_detail_tab(m).delivery_detail_id,
10967                    p_attribute_id             =>      p_detail_tab(m).inventory_item_id,
10968                    p_parent_id                =>      p_detail_tab(m).organization_id,
10969                    p_location_list            =>      l_stop_locations,
10970                    p_direct_shipment          =>      l_direct_shipment,
10971                    x_validate_result          =>      l_validate_itmfac_result,
10972                    x_failed_constraint        =>      x_failed_constraints,
10973                    x_return_status            =>      l_return_status);
10974 
10975                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
10976                     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
10977                        raise FND_API.G_EXC_UNEXPECTED_ERROR;
10978                     END IF;
10979                 END IF;
10980 
10981                 IF l_validate_itmfac_result = 'F' THEN
10982                    l_item_result := 'F';
10983                 END IF;
10984 
10985              END IF;
10986             END IF;
10987 
10988             IF p_action_code = G_ASSIGN_DLVY_TRIP THEN
10989 
10990              -- Item - Vehicle
10991 
10992              IF p_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) AND
10993                 l_carrier IS NOT NULL THEN
10994 
10995                 check_inclusive_object2(
10996                  p_comp_class_code          =>      G_ITEM_CARRIER,
10997                  p_entity_type              =>      G_DEL_DETAIL,
10998                  p_entity_id                =>      p_detail_tab(m).delivery_detail_id,
10999                  p_object1_type             =>      'ITM',
11000                  p_object1_val_num          =>      p_detail_tab(m).inventory_item_id,
11001                  p_object1_parent_id        =>      p_detail_tab(m).organization_id,  -- Only for item
11002                  p_object2_type             =>      'CAR',
11003                  p_object2_val_num          =>      l_carrier,
11004                  x_out_object2_num          =>      l_out_object2_num,
11005                  x_out_object2_char         =>      l_out_object2_char,
11006                  x_validate_result          =>      l_validate_carrier_result,
11007                  x_failed_constraint        =>      x_failed_constraints,
11008                  x_return_status            =>      l_return_status);
11009 
11010                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11011                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
11012                       raise FND_API.G_EXC_UNEXPECTED_ERROR;
11013                    END IF;
11014                 END IF;
11015 
11016                 IF l_validate_carrier_result = 'F' THEN
11017                    l_item_result := 'F';
11018                 END IF;
11019 
11020              END IF;
11021 
11022              IF p_comp_class_tab.EXISTS(G_ITEM_VEHICLE_NUM) AND
11023                 l_vehicle_type IS NOT NULL THEN
11024 
11025                 check_inclusive_object2(
11026                  p_comp_class_code          =>      G_ITEM_VEHICLE,
11027                  p_entity_type              =>      G_DEL_DETAIL,
11028                  p_entity_id                =>      p_detail_tab(m).delivery_detail_id,
11029                  p_object1_type             =>      'ITM',
11030                  p_object1_val_num          =>      p_detail_tab(m).inventory_item_id,
11031                  p_object1_parent_id        =>      p_detail_tab(m).organization_id,  -- Only for item
11032                  p_object2_type             =>      'VHT',
11033                  p_object2_val_num          =>      l_vehicle_type,
11034                  x_out_object2_num          =>      l_out_object2_num,
11035                  x_out_object2_char         =>      l_out_object2_char,
11036                  x_validate_result          =>      l_validate_vehicle_result,
11037                  x_failed_constraint        =>      x_failed_constraints,
11038                  x_return_status            =>      l_return_status);
11039 
11040                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11041                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
11042                       raise FND_API.G_EXC_UNEXPECTED_ERROR;
11043                    END IF;
11044                 END IF;
11045 
11046                 IF l_validate_vehicle_result = 'F' THEN
11047                    l_item_result := 'F';
11048                 END IF;
11049 
11050              END IF;
11051 
11052              IF p_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) AND
11053                 l_mode IS NOT NULL THEN
11054 
11055                 check_inclusive_object2(
11056                  p_comp_class_code          =>      G_ITEM_MODE,
11057                  p_entity_type              =>      G_DEL_DETAIL,
11058                  p_entity_id                =>      p_detail_tab(m).delivery_detail_id,
11059                  p_object1_type             =>      'ITM',
11060                  p_object1_val_num          =>      p_detail_tab(m).inventory_item_id,
11061                  p_object1_parent_id        =>      p_detail_tab(m).organization_id,  -- Only for item
11062                  p_object2_type             =>      'MOD',
11063                  p_object2_val_char          =>      l_mode,
11064                  x_out_object2_num          =>      l_out_object2_num,
11065                  x_out_object2_char         =>      l_out_object2_char,
11066                  x_validate_result          =>      l_validate_mode_result,
11067                  x_failed_constraint        =>      x_failed_constraints,
11068                  x_return_status            =>      l_return_status);
11069 
11070                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11071                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
11072                       raise FND_API.G_EXC_UNEXPECTED_ERROR;
11073                    END IF;
11074                 END IF;
11075 
11076                 IF l_validate_mode_result = 'F' THEN
11077                    l_item_result := 'F';
11078                 END IF;
11079 
11080              END IF;
11081             END IF; -- G_ASSIGN_TRIP
11082 
11083             IF (p_action_code = G_AUTOCRT_DLVY_TRIP OR  p_action_code = G_AUTOCRT_MDC) AND
11084              (p_entity_tab(k).ship_method_code IS NOT NULL OR
11085               p_entity_tab(k).carrier_id IS NOT NULL OR
11086               p_entity_tab(k).mode_of_transport IS NOT NULL) AND
11087             NOT l_failed_group.EXISTS(p_entity_tab(k).group_id) THEN
11088 
11089                check_act_positive (
11090                      p_comp_class_tab     => p_comp_class_tab,
11091                      p_item_id            => p_detail_tab(m).inventory_item_id,
11092                      p_item_org_id        => p_detail_tab(m).organization_id,
11093                      p_delivery_rec       => p_entity_tab(k),
11094                      x_failed_constraint  => x_failed_constraints,
11095                      x_validate_result    => l_acd_result,
11096                      x_return_status      => l_return_status);
11097 
11098                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11099                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
11100                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
11101                   END IF;
11102                END IF;
11103 
11104                IF l_acd_result = 'F' THEN
11105                   l_failed_group(p_entity_tab(k).group_id) := p_entity_tab(k).group_id;
11106                   p_group_tab(p_entity_tab(k).group_id).upd_dlvy_ship_method := 'N';
11107                END IF;
11108 
11109             END IF;
11110 
11111             <<detail_nextpass>>
11112 
11113             EXIT WHEN m= p_detail_tab.LAST;
11114             m:= p_detail_tab.NEXT(m);
11115            END LOOP;
11116 
11117           END IF;
11118 
11119            --IF l_validate_itmfac_result = 'F' OR l_item_result = 'F' THEN
11120           IF l_item_result = 'F' THEN
11121                 p_entity_tab.DELETE(k);
11122                 t := t+1;
11123                 x_failed_lines(t).failed_line_index := t;
11124                 x_failed_lines(t).entity_line_id := k;
11125                 GOTO entity_nextpass;
11126           END IF;
11127 
11128                 -- Populate x_line_groups table
11129           l_linegroup_indx := l_linegroup_indx + 1;
11130           x_line_groups(l_linegroup_indx).line_group_index := l_linegroup_indx;
11131           x_line_groups(l_linegroup_indx).entity_line_id   := p_entity_tab(k).entity_id;
11132           x_line_groups(l_linegroup_indx).line_group_id    := p_entity_tab(k).group_id;
11133 
11134           -- END IF;   -- It was here for null protection of above loop
11135 
11136           <<entity_nextpass>>
11137           --
11138           IF l_debug_on THEN
11139              WSH_DEBUG_SV.logmsg(l_module_name,'p_entity_tab : FIRST -  '||p_entity_tab.FIRST||' NEXT - '||p_entity_tab.NEXT(k)||' LAST - '||p_entity_tab.LAST||' COUNT - '||p_entity_tab.COUNT);
11140           END IF;
11141           --
11142 
11143           -- Check whether NEXT works with DELETE
11144           EXIT WHEN ( k = p_entity_tab.LAST OR p_entity_tab.COUNT = 0 OR p_entity_tab.NEXT(k) IS NULL);
11145           k:= p_entity_tab.NEXT(k);
11146         END LOOP;
11147     END IF;
11148 
11149     --
11150     IF l_debug_on THEN
11151        WSH_DEBUG_SV.pop(l_module_name);
11152     END IF;
11153     --
11154 
11155 EXCEPTION
11156     WHEN g_get_carrmode_failed THEN
11157       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
11158       --
11159       IF l_debug_on THEN
11160         WSH_DEBUG_SV.pop(l_module_name,' get carrier-mode failed ');
11161       END IF;
11162       --
11163     WHEN g_get_vehicletype_failed THEN
11164       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
11165       --
11166       IF l_debug_on THEN
11167         WSH_DEBUG_SV.pop(l_module_name,' get vehicletype failed ');
11168       END IF;
11169       --
11170     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
11171       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
11172       --
11173       IF l_debug_on THEN
11174         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
11175         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
11176       END IF;
11177       --
11178     WHEN others THEN
11179       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.validate_positive_constraint');
11180       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
11181       --
11182       IF l_debug_on THEN
11183         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
11184         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
11185       END IF;
11186       --
11187 
11188 END validate_positive_constraint;
11189 
11190 --***************************************************************************--
11191 
11192 --========================================================================
11193 -- PROCEDURE : check_upd_dlvy             PRIVATE
11194 --
11195 -- PARAMETERS: p_delivery_rec             Input delivery record
11196 --             p_detail_tab               Children detail records of input delivery record
11197 --             p_comp_class_tab           Table of Compatibility class codes to check
11198 --             x_failed_constraints       Failed constraint table
11199 --             x_validate_result          Constraint Validation result : S / F
11200 --             x_return_status            Return status
11201 -- COMMENT   :
11202 -- Applicable for Manual create / Update of a delivery
11203 -- For a given delivery
11204 -- determines if the delivery can be updated to have the input record structure
11205 -- satisfying all constraints
11206 --========================================================================
11207 
11208 PROCEDURE check_upd_dlvy(
11209                  p_delivery_rec        IN delivery_ccinfo_rec_type,
11210                  p_detail_tab          IN detail_ccinfo_tab_type,
11211                  p_comp_class_tab      IN WSH_UTIL_CORE.Column_Tab_Type,
11212                  x_failed_constraints  IN OUT NOCOPY line_constraint_tab_type,
11213                  x_validate_result     OUT NOCOPY VARCHAR2,
11214                  x_return_status       OUT NOCOPY VARCHAR2)
11215 IS
11216 
11217     j                           NUMBER := 0;
11218     l_carrier                   NUMBER := 0;
11219     l_mode                      VARCHAR2(30);
11220     l_service_level             VARCHAR2(30) := NULL;
11221     l_carrier_service_inout_rec WSH_CARRIERS_GRP.Carrier_Service_InOut_Rec_Type;
11222     l_return_status             VARCHAR2(1);
11223     l_validate_result           VARCHAR2(1);
11224     l_failed_constraint         line_constraint_rec_type;
11225     l_validate_faccar_result    VARCHAR2(1) := 'S';
11226     l_validate_facmod_result    VARCHAR2(1) := 'S';
11227     l_validate_itmcar_result    VARCHAR2(1) := 'S';
11228     l_validate_itmmod_result    VARCHAR2(1) := 'S';
11229 
11230     l_module_name               CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'check_upd_dlvy';
11231     l_debug_on                  CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
11232 BEGIN
11233 
11234     x_validate_result := 'S';
11235     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
11236 
11237     IF l_debug_on THEN
11238        wsh_debug_sv.push(l_module_name);
11239     END IF;
11240 
11241     IF (p_delivery_rec.carrier_id IS NULL OR p_delivery_rec.MODE_OF_TRANSPORT IS NULL) AND
11242        (p_delivery_rec.ship_method_code IS NOT NULL) THEN
11243 
11244     l_carrier_service_inout_rec.ship_method_code := p_delivery_rec.ship_method_code;
11245     WSH_CARRIERS_GRP.get_carrier_service_mode(
11246              p_carrier_service_inout_rec   =>  l_carrier_service_inout_rec,
11247              x_return_status       =>  l_return_status);
11248 
11249     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11250        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
11251        IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
11252           raise FND_API.G_EXC_UNEXPECTED_ERROR;
11253        END IF;
11254        raise g_get_carrmode_failed;
11255        END IF;
11256     END IF;
11257     l_carrier := l_carrier_service_inout_rec.carrier_id;
11258     l_mode    := l_carrier_service_inout_rec.mode_of_transport;
11259 
11260     END IF; -- p_delivery_rec.carrier_id IS NULL OR ..
11261 
11262     -- If carrier_id or mode is passed in, then those get preference for validation
11263     -- If they are not, they are derived from ship method if that is passed
11264 
11265     IF p_delivery_rec.carrier_id IS NOT NULL THEN
11266        l_carrier := p_delivery_rec.carrier_id;
11267     END IF;
11268     IF p_delivery_rec.mode_of_transport IS NOT NULL THEN
11269        l_mode := p_delivery_rec.mode_of_transport;
11270     END IF;
11271 
11272     -- Check delivery's stop locations for FAC - CAR/MOD
11273 
11274     IF p_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) AND
11275           l_carrier IS NOT NULL THEN
11276 
11277       validate_constraint(
11278              p_comp_class_code          =>      G_FACILITY_CARRIER,
11279              p_object1_type             =>      'FAC',
11280              p_object1_val_num          =>      p_delivery_rec.initial_pickup_location_id,
11281              p_object2_type             =>      'CAR',
11282              p_object2_val_num          =>      l_carrier,
11283              x_validate_result          =>      l_validate_faccar_result,
11284              x_failed_constraint        =>      l_failed_constraint,
11285              x_return_status            =>      l_return_status);
11286 
11287       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11288          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
11289             raise FND_API.G_EXC_UNEXPECTED_ERROR;
11290          END IF;
11291       END IF;
11292 
11293       IF l_validate_faccar_result <> 'S' THEN
11294          l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
11295          l_failed_constraint.entity_type :=  G_DELIVERY;
11296          l_failed_constraint.entity_line_id :=  p_delivery_rec.delivery_id;
11297          x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
11298 
11299          IF l_validate_faccar_result = 'E' THEN
11300             x_validate_result := 'F';
11301             l_validate_result := 'F';
11302          END IF;
11303       END IF;
11304          -- Success can override Failure
11305 
11306       validate_constraint(
11307              p_comp_class_code          =>      G_FACILITY_CARRIER,
11308              p_object1_type             =>      'FAC',
11309              p_object1_val_num          =>      p_delivery_rec.ultimate_dropoff_location_id,
11310              p_object2_type             =>      'CAR',
11311              p_object2_val_num          =>      l_carrier,
11312              x_validate_result          =>      l_validate_faccar_result,
11313              x_failed_constraint        =>      l_failed_constraint,
11314              x_return_status            =>      l_return_status);
11315 
11316       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11317          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
11318             raise FND_API.G_EXC_UNEXPECTED_ERROR;
11319          END IF;
11320       END IF;
11321 
11322       IF l_validate_faccar_result <> 'S' THEN
11323         l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
11324         l_failed_constraint.entity_type :=  G_DELIVERY;
11325         l_failed_constraint.entity_line_id :=  p_delivery_rec.delivery_id;
11326         x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
11327 
11328         IF l_validate_faccar_result = 'E' THEN
11329            x_validate_result := 'F';
11330          l_validate_result := 'F';
11331         END IF;
11332       END IF;
11333 
11334     END IF;
11335 
11336     IF p_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) AND
11337           l_mode IS NOT NULL THEN
11338 
11339       validate_constraint(
11340              p_comp_class_code          =>      G_FACILITY_MODE,
11341              p_object1_type             =>      'FAC',
11342              p_object1_val_num          =>      p_delivery_rec.initial_pickup_location_id,
11343              p_object2_type             =>      'MOD',
11344              p_object2_val_char         =>     l_mode ,
11345              x_validate_result          =>      l_validate_facmod_result,
11346              x_failed_constraint        =>      l_failed_constraint,
11347              x_return_status            =>      l_return_status);
11348 
11349       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11350          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
11351             raise FND_API.G_EXC_UNEXPECTED_ERROR;
11352          END IF;
11353       END IF;
11354 
11355       IF l_validate_facmod_result <> 'S' THEN
11356         l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
11357         l_failed_constraint.entity_type :=  G_DELIVERY;
11358         l_failed_constraint.entity_line_id :=  p_delivery_rec.delivery_id;
11359         x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
11360 
11361         IF l_validate_facmod_result = 'E' THEN
11362          x_validate_result := 'F';
11363          l_validate_result := 'F';
11364         END IF;
11365 
11366       END IF;
11367 
11368       validate_constraint(
11369              p_comp_class_code          =>      G_FACILITY_MODE,
11370              p_object1_type             =>      'FAC',
11371              p_object1_val_num          =>      p_delivery_rec.ultimate_dropoff_location_id,
11372              p_object2_type             =>      'MOD',
11373              p_object2_val_char         =>     l_mode ,
11374              x_validate_result          =>      l_validate_facmod_result,
11375              x_failed_constraint        =>      l_failed_constraint,
11376              x_return_status            =>      l_return_status);
11377 
11378       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11379          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
11380             raise FND_API.G_EXC_UNEXPECTED_ERROR;
11381          END IF;
11382       END IF;
11383 
11384       IF l_validate_facmod_result <> 'S' THEN
11385         l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
11386         l_failed_constraint.entity_type :=  G_DELIVERY;
11387         l_failed_constraint.entity_line_id :=  p_delivery_rec.delivery_id;
11388         x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
11389 
11390         IF l_validate_facmod_result = 'E' THEN
11391          x_validate_result := 'F';
11392          l_validate_result := 'F';
11393         END IF;
11394       END IF;
11395 
11396     END IF;
11397 
11398     -- Check delivery lines items for ITM - CAR/MOD
11399 
11400     IF l_carrier IS NOT NULL OR
11401        l_mode IS NOT NULL THEN
11402 
11403       --LOOP  -- Over children of the dleg
11404       j := p_detail_tab.FIRST;
11405       IF j IS NOT NULL THEN
11406         LOOP
11407 
11408            -- ITM - CAR/MOD for detail's item against dleg's carrier, mode
11409 
11410            IF p_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) AND
11411               l_mode IS NOT NULL THEN
11412 
11413                validate_constraint(   --  checks only negative constraints
11414                  p_comp_class_code          =>      G_ITEM_MODE,
11415                  p_object1_type             =>      'ITM',
11416                  p_object1_parent_id        =>      p_detail_tab(j).organization_id,
11417                  p_object2_type             =>      'MOD',
11418                  p_object1_val_num          =>      p_detail_tab(j).inventory_item_id,
11419                  p_object2_val_char          =>     l_mode ,
11420                  x_validate_result          =>      l_validate_itmmod_result,
11421                  x_failed_constraint        =>      l_failed_constraint,  -- id
11422                  x_return_status            =>      l_return_status);
11423 
11424                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11425                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
11426                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
11427                   END IF;
11428                END IF;
11429 
11430                IF l_validate_itmmod_result <> 'S' THEN
11431                   l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
11432                   l_failed_constraint.entity_type :=  G_DEL_DETAIL;
11433                   l_failed_constraint.entity_line_id :=  p_detail_tab(j).delivery_detail_id;
11434                   x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
11435 
11436                   IF l_validate_itmmod_result = 'E' THEN
11437                    x_validate_result := 'F';
11438                    l_validate_result := 'F';
11439                   END IF;
11440 
11441                END IF;
11442 
11443            END IF;
11444 
11445            IF p_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) AND
11446               l_carrier IS NOT NULL THEN
11447 
11448                validate_constraint(   --  checks only negative constraints
11449                  p_comp_class_code          =>      G_ITEM_CARRIER,
11450                  p_object1_type             =>      'ITM',
11451                  p_object1_parent_id        =>      p_detail_tab(j).organization_id,
11452                  p_object2_type             =>      'CAR',
11453                  p_object1_val_num          =>      p_detail_tab(j).inventory_item_id,
11454                  p_object2_val_num          =>      l_carrier,
11455                  x_validate_result          =>      l_validate_itmcar_result,
11456                  x_failed_constraint        =>      l_failed_constraint,  -- id
11457                  x_return_status            =>      l_return_status);
11458 
11459                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11460                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
11461                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
11462                   END IF;
11463                END IF;
11464 
11465                IF l_validate_itmcar_result <> 'S' THEN
11466                   l_failed_constraint.line_constraint_index := x_failed_constraints.COUNT+1;
11467                   l_failed_constraint.entity_type :=  G_DEL_DETAIL;
11468                   l_failed_constraint.entity_line_id :=  p_detail_tab(j).delivery_detail_id;
11469                   x_failed_constraints(x_failed_constraints.COUNT+1) := l_failed_constraint;
11470 
11471                   IF l_validate_itmcar_result = 'E' THEN
11472                    x_validate_result := 'F';
11473                    l_validate_result := 'F';
11474                   END IF;
11475 
11476                END IF;
11477 
11478            END IF;
11479 
11480            EXIT WHEN j = p_detail_tab.LAST;
11481            j := p_detail_tab.NEXT(j);
11482 
11483         END LOOP;
11484       END IF;
11485 
11486     END IF; -- not null
11487 
11488     --
11489     IF l_debug_on THEN
11490       WSH_DEBUG_SV.pop(l_module_name);
11491     END IF;
11492     --
11493 
11494 EXCEPTION
11495     WHEN g_get_carrmode_failed THEN
11496       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
11497       --
11498       IF l_debug_on THEN
11499         WSH_DEBUG_SV.pop(l_module_name,' get carrier-mode failed ');
11500       END IF;
11501       --
11502     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
11503       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
11504       --
11505       IF l_debug_on THEN
11506         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
11507         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
11508       END IF;
11509       --
11510     WHEN others THEN
11511       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.check_upd_dlvy');
11512       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
11513       --
11514       IF l_debug_on THEN
11515         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
11516         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
11517       END IF;
11518       --
11519 
11520 END check_upd_dlvy;
11521 
11522 --========================================================================
11523 -- PROCEDURE : validate_constraint_dlvy    Called by constraint Wrapper API
11524 --                                         and the Group API.
11525 --
11526 -- PARAMETERS: p_init_msg_list             FND_API.G_TRUE to reset list
11527 --             p_action_code               Predefined action code
11528 --             p_exception_list            Compatibility classes to skip if any
11529 --                                         indexed by class code numbers
11530 --             p_in_ids                    Table of delivery ids to process
11531 --                                         Either of the next two should be passed
11532 --             p_delivery_info             Table of delivery records to process
11533 --                                         Only one of p_in_ids and p_delivery_info should be passed
11534 --             p_dlvy_assigned_lines       Table of assigned delivery details of
11535 --                                         input deliveries. Pass if queried information available
11536 --                                         If not passed, the API will query
11537 --             p_target_trip               Applicable for Assign delivery to Trip only
11538 --                                         Record of target trip information
11539 --             p_target_tripstops          Input pickup and dropoff stop/location of the delivery(s)
11540 --                                         in that target trip
11541 --             p_target_trip_assign_dels   Table of deliveries in target trip
11542 --                                         If not passed, the API will query
11543 --             p_target_trip_dlvy_lines    Table of delivery details in target trip
11544 --                                         If not passed, the API will query
11545 --             p_target_trip_incl_stops    Table of tripstops already in the target trip_
11546 --                                         If not passed, the API will query
11547 --             x_validate_result           Constraint Validation result : S / F
11548 --             x_line_groups               Includes Successful and warning lines
11549 --                                         after constraint check
11550 --                                         Contains information of which input delivery should
11551 --                                         be grouped in which output group for trip creation
11552 --             x_group_info                Output groups for input deliveries
11553 --             x_failed_lines              Table of input delivery lines that failed
11554 --                                         constraint check
11555 --             x_msg_count                 Number of messages in the list
11556 --             x_msg_data                  Text of messages
11557 --             x_return_status             Return status
11558 -- COMMENT   : This procedure is used to perform for following actions
11559 --             Can be called for
11560 --             A. Autocreate Trip (ACT)
11561 --             B. Assign Delivery to Trip (ADT)
11562 --             C. Update a delivery (UPD)
11563 --             D. Manually create a delivery (CRD)
11564 --             When specifying a target trip, group all deliveries that are being planned
11565 --             to the target trip
11566 --========================================================================
11567 
11568 PROCEDURE validate_constraint_dlvy(
11569              p_init_msg_list            IN            VARCHAR2 DEFAULT fnd_api.g_false,
11570              p_action_code              IN            VARCHAR2 DEFAULT NULL,
11571              p_exception_list           IN            WSH_UTIL_CORE.Column_Tab_Type,
11572              p_in_ids                   IN            WSH_UTIL_CORE.id_tab_type,
11573              p_delivery_info            IN            delivery_ccinfo_tab_type,
11574              p_dlvy_assigned_lines      IN            detail_ccinfo_tab_type,
11575              p_target_trip              IN            trip_ccinfo_rec_type,
11576              p_target_tripstops         IN OUT NOCOPY target_tripstop_cc_rec_type,
11577              p_target_trip_assign_dels  IN            delivery_ccinfo_tab_type,
11578              p_target_trip_dlvy_lines   IN            detail_ccinfo_tab_type,
11579              p_target_trip_incl_stops   IN            stop_ccinfo_tab_type,
11580              x_validate_result          OUT NOCOPY    VARCHAR2,
11581              x_line_groups              OUT NOCOPY    WSH_FTE_COMP_CONSTRAINT_PKG.line_group_tab_type,
11582              x_group_info               OUT NOCOPY    WSH_FTE_COMP_CONSTRAINT_PKG.cc_group_tab_type,
11583              x_failed_lines             OUT NOCOPY    WSH_FTE_COMP_CONSTRAINT_PKG.failed_line_tab_type,
11584              x_msg_count                OUT NOCOPY    NUMBER,
11585              x_msg_data                 OUT NOCOPY    VARCHAR2,
11586              x_return_status            OUT NOCOPY    VARCHAR2)
11587 IS
11588 
11589     CURSOR c_gettripdetails (l_tripid IN NUMBER) is
11590     SELECT TRIP_ID, 'Y'as EXISTS_IN_DATABASE, NAME, PLANNED_FLAG, STATUS_CODE, VEHICLE_ITEM_ID, VEHICLE_NUMBER,
11591     CARRIER_ID, SHIP_METHOD_CODE, VEHICLE_ORGANIZATION_ID, VEHICLE_NUM_PREFIX, SERVICE_LEVEL,
11592     MODE_OF_TRANSPORT
11593     FROM wsh_trips where trip_id=l_tripid;
11594 
11595     cursor c_gettrip(l_deliveryid IN NUMBER) is
11596     select wts.TRIP_ID
11597     from wsh_trip_stops wts, wsh_delivery_legs wdl
11598     where wdl.delivery_id =l_deliveryid AND
11599     wdl.pick_up_stop_id = wts.stop_id;
11600 
11601     k                            NUMBER:=0;
11602     l                            NUMBER:=0;
11603     i                            NUMBER:=0;
11604     j                            NUMBER:=0;
11605     l_end_count                  NUMBER:= 0;
11606     l_start_count                NUMBER:= 0;
11607     l_trip_del_cnt               NUMBER:=0;
11608     l_trip_detail_cnt            NUMBER:=0;
11609     l_trip_stops_cnt             NUMBER:=0;
11610     l_group_id                   NUMBER:=0;
11611     l_failed_lc                  NUMBER:=0;
11612     l_linegroup_indx             NUMBER:=0;
11613     l_return_status              VARCHAR2(1);
11614     l_validate_result            VARCHAR2(1);
11615     l_comp_class_tab             WSH_UTIL_CORE.column_tab_type;
11616     l_entity_tab                 entity_tab_type;
11617     l_group_tab                  entity_group_tab_type;
11618     l_group_tab1                 WSH_FTE_COMP_CONSTRAINT_PKG.cc_group_tab_type;
11619     l_found                      BOOLEAN := FALSE;
11620     l_failed_constraints         line_constraint_tab_type;
11621     l_failed_constraint          line_constraint_rec_type;
11622     l_delivery_rec               delivery_ccinfo_rec_type;
11623     l_detail_rec                 detail_ccinfo_rec_type;
11624     l_stop_rec                   stop_ccinfo_rec_type;
11625     l_delivery_info              delivery_ccinfo_tab_type;
11626     l_dlvy_assigned_lines        detail_ccinfo_tab_type;
11627     l_target_trip                trip_ccinfo_rec_type;
11628     l_target_trip_assign_dels    delivery_ccinfo_tab_type;
11629     l_target_trip_dlvy_lines     detail_ccinfo_tab_type;
11630     l_target_trip_incl_stops     stop_ccinfo_tab_type;
11631     l_detail_tab                 WSH_UTIL_CORE.id_tab_type;
11632     l_delivery_tab               WSH_UTIL_CORE.id_tab_type;
11633     l_exists_tab                 WSH_UTIL_CORE.column_tab_type;
11634     l_customer_tab               WSH_UTIL_CORE.id_tab_type;
11635     l_item_tab                   WSH_UTIL_CORE.id_tab_type;
11636     l_shipfrom_loc_tab           WSH_UTIL_CORE.id_tab_type;
11637     l_org_tab                    WSH_UTIL_CORE.id_tab_type;
11638     l_shipto_loc_tab             WSH_UTIL_CORE.id_tab_type;
11639     l_intmed_shipto_loc_tab      WSH_UTIL_CORE.id_tab_type;
11640     l_rel_stat_tab               WSH_UTIL_CORE.column_tab_type;
11641     l_cont_flag_tab              WSH_UTIL_CORE.column_tab_type;
11642     l_date_req_tab               WSH_UTIL_CORE.Date_Tab_Type;
11643     l_date_sch_tab               WSH_UTIL_CORE.Date_Tab_Type;
11644     l_carrier_tab                WSH_UTIL_CORE.id_tab_type;
11645     l_shipmethod_tab             WSH_UTIL_CORE.column_tab_type;
11646     l_party_tab                  WSH_UTIL_CORE.id_tab_type;
11647     l_line_direction_tab         WSH_UTIL_CORE.column_tab_type;
11648     l_shipping_control_tab       WSH_UTIL_CORE.column_tab_type;
11649     l_supp_control_tab           WSH_UTIL_CORE.id_tab_type;
11650     --DUM_COMP
11651     l_dum_tab			 WSH_UTIL_CORE.id_tab_type;
11652     --DUM_COMP
11653     --SBAKSHI (8/24)
11654     l_target_trip_incl_sort_stops stop_ccinfo_tab_type;
11655     --SBAKSHI (8/24)
11656 
11657     l_group_count                NUMBER:=0;
11658     l_carrier                    NUMBER := NULL;
11659     l_vehicle_type               NUMBER := NULL;
11660     l_mode                       VARCHAR2(30) := NULL;
11661     l_service_level              VARCHAR2(30) := NULL;
11662     l_carrier_service_inout_rec  WSH_CARRIERS_GRP.Carrier_Service_InOut_Rec_Type;
11663     l_location_id                NUMBER := NULL;
11664     l_validate_carrier_result    VARCHAR2(1) := 'S';
11665     l_validate_vehicle_result    VARCHAR2(1) := 'S';
11666     l_validate_mode_result       VARCHAR2(1) := 'S';
11667     l_dummy_failed_lines         WSH_FTE_COMP_CONSTRAINT_PKG.failed_line_tab_type;
11668     l_dummy_failed_lc            NUMBER:=0;
11669     l_upd_delivery_rec           delivery_ccinfo_rec_type;
11670     g_invalid_action_code        EXCEPTION;
11671     l_vehicle_name               VARCHAR2(2000);
11672     l_vehicle_org_name           VARCHAR2(240);
11673 
11674     l_module_name                CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'validate_constraint_dlvy';
11675     l_debug_on                   CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
11676 
11677     --#DUM_LOC(S)
11678     l_physical_location_id	 NUMBER;
11679     --#DUM_LOC(E)
11680     l_delivery_info_mod NUMBER ; --Bug 9222910
11681 
11682 
11683 BEGIN
11684 
11685     x_validate_result := 'S';
11686     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
11687 
11688     g_itm_mustuse_cache.DELETE;
11689     g_itmloc_mustuse_cache.DELETE;
11690     g_itm_exclusive_cache.DELETE;
11691     g_fac_exclusive_cache.DELETE;
11692 
11693     IF FND_API.to_Boolean( p_init_msg_list ) THEN
11694          FND_MSG_PUB.initialize;
11695     END IF;
11696 
11697     IF l_debug_on THEN
11698        wsh_debug_sv.push(l_module_name);
11699        WSH_DEBUG_SV.logmsg(l_module_name,'p_init_msg_list : '||p_init_msg_list);
11700     END IF;
11701 
11702     -- Action codes : ACT, ADT, UPD, CRD
11703 
11704     IF p_action_code NOT IN (G_AUTOCRT_DLVY_TRIP,G_ASSIGN_DLVY_TRIP,G_UPDATE_DLVY,G_CREATE_DLVY,G_AUTOCRT_MDC) OR
11705           p_action_code IS NULL THEN
11706           RAISE g_invalid_action_code;
11707     END IF;
11708 
11709     IF p_action_code IN (G_UPDATE_DLVY,G_CREATE_DLVY) AND p_delivery_info.COUNT = 0 THEN
11710            RAISE g_invalid_action_code;
11711     END IF;
11712 
11713     refresh_cache(l_return_status);
11714 
11715     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11716          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
11717             raise FND_API.G_EXC_UNEXPECTED_ERROR;
11718          END IF;
11719     END IF;
11720 
11721     -- Assumes p_comp_class_tab and p_exception_list are indexed by
11722     -- compatibility class codes
11723 
11724     IF NOT p_exception_list.EXISTS(G_FACILITY_MODE_NUM) THEN
11725       l_comp_class_tab(G_FACILITY_MODE_NUM) := G_FACILITY_MODE;
11726     END IF;
11727     IF NOT p_exception_list.EXISTS(G_FACILITY_CARRIER_NUM) THEN
11728       l_comp_class_tab(G_FACILITY_CARRIER_NUM) := G_FACILITY_CARRIER;
11729     END IF;
11730     IF NOT p_exception_list.EXISTS(G_FACILITY_VEHICLE_NUM) THEN
11731       l_comp_class_tab(G_FACILITY_VEHICLE_NUM) := G_FACILITY_VEHICLE;
11732     END IF;
11733     IF NOT p_exception_list.EXISTS(G_ITEM_MODE_NUM) THEN
11734       l_comp_class_tab(G_ITEM_MODE_NUM) := G_ITEM_MODE;
11735     END IF;
11736     IF NOT p_exception_list.EXISTS(G_ITEM_CARRIER_NUM) THEN
11737       l_comp_class_tab(G_ITEM_CARRIER_NUM) := G_ITEM_CARRIER;
11738     END IF;
11739     IF NOT p_exception_list.EXISTS(G_ITEM_VEHICLE_NUM) THEN
11740       l_comp_class_tab(G_ITEM_VEHICLE_NUM) := G_ITEM_VEHICLE;
11741     END IF;
11742     IF NOT p_exception_list.EXISTS(G_SHIPORG_FACILITY_NUM) THEN
11743        l_comp_class_tab(G_SHIPORG_FACILITY_NUM) := G_SHIPORG_FACILITY;
11744     END IF;
11745     IF NOT p_exception_list.EXISTS(G_CUSTOMER_FACILITY_NUM) THEN
11746        l_comp_class_tab(G_CUSTOMER_FACILITY_NUM) := G_CUSTOMER_FACILITY;
11747     END IF;
11748     IF NOT p_exception_list.EXISTS(G_SUPPLIER_FACILITY_NUM) THEN
11749        l_comp_class_tab(G_SUPPLIER_FACILITY_NUM) := G_SUPPLIER_FACILITY;
11750     END IF;
11751     IF NOT p_exception_list.EXISTS(G_ITEM_FACILITY_NUM) THEN
11752        l_comp_class_tab(G_ITEM_FACILITY_NUM) := G_ITEM_FACILITY;
11753     END IF;
11754     IF NOT p_exception_list.EXISTS(G_CUSTOMER_CUSTOMER_NUM) THEN
11755        l_comp_class_tab(G_CUSTOMER_CUSTOMER_NUM) := G_CUSTOMER_CUSTOMER;
11756     END IF;
11757 
11758     -- Assign delivery details to delivery
11759     -- does not update any grouping attributes for the delivery AS 10/18
11760     -- Populate l_delivery_info
11761 
11762     IF p_delivery_info.COUNT = 0 THEN
11763       --
11764       IF l_debug_on THEN
11765         WSH_DEBUG_SV.logmsg(l_module_name,'p_in_ids passed count : '||p_in_ids.COUNT);
11766       END IF;
11767       --
11768       i := p_in_ids.FIRST;
11769 
11770       IF i IS NOT NULL THEN
11771       LOOP
11772 
11773          -- c_get_dlvy is a global cursor.
11774 	 -- We are fetching entire information for a particluar record.
11775 
11776 	    OPEN  c_get_dlvy(p_in_ids(i));
11777           FETCH c_get_dlvy into l_delivery_info(i);
11778         CLOSE c_get_dlvy;
11779 
11780 	 --#DUM_LOC(S)
11781 	 -- Delivery's ultimate_dropoff_location_id to be converted to physical internal
11782 	 -- location if it is a dummy location.
11783 	 -- We have to use the API for this purpose.
11784 
11785 	 WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
11786              p_internal_cust_location_id  => l_delivery_info(i).ultimate_dropoff_location_id,
11787              x_internal_org_location_id   => l_physical_location_id,
11788              x_return_status              => l_return_status);
11789 
11790 	 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11791 	    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
11792 	       raise FND_API.G_EXC_UNEXPECTED_ERROR;
11793 	    END IF;
11794   	 END IF;
11795 
11796 	 --physical location id is not null implies- A dummy location.
11797 	 IF (l_physical_location_id IS NOT NULL) THEN
11798   	      --
11799 	      IF l_debug_on THEN
11800 		  WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_delivery_info(i).ultimate_dropoff_location_id||' is a dummy location');
11801 	      END IF;
11802 	      --
11803 	      l_delivery_info(i).ultimate_dropoff_location_id := l_physical_location_id;
11804               -- AGDUMMY TODO populate physical_dropoff_location_id
11805               l_delivery_info(i).physical_dropoff_location_id := l_physical_location_id;
11806 	 END IF;
11807          --#DUM_LOC(E)
11808 
11809          OPEN c_gettrip(p_in_ids(i));
11810          FETCH c_gettrip into l_delivery_info(i).TRIP_ID;
11811          CLOSE c_gettrip;
11812 
11813   	      --
11814 	      IF l_debug_on THEN
11815        WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info(i).initial_pickup_location_id : '||l_delivery_info(i).initial_pickup_location_id);
11816        WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info(i).ultimate_dropoff_location_id : '||l_delivery_info(i).ultimate_dropoff_location_id);
11817 	      END IF;
11818 	      --
11819          EXIT WHEN i = p_in_ids.LAST;
11820          i := p_in_ids.NEXT(i);
11821 
11822       END LOOP;
11823       END IF;
11824 
11825     ELSE
11826       --
11827       IF l_debug_on THEN
11828         WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info passed count : '||p_delivery_info.COUNT);
11829       END IF;
11830       --
11831 
11832       i := p_delivery_info.FIRST;
11833       IF i IS NOT NULL THEN
11834        LOOP
11835        --{
11836         IF ( p_delivery_info(i).INITIAL_PICKUP_LOCATION_ID IS NULL OR
11837            p_delivery_info(i).ULTIMATE_DROPOFF_LOCATION_ID IS NULL OR
11838            p_delivery_info(i).CUSTOMER_ID IS NULL OR
11839            p_delivery_info(i).ORGANIZATION_ID IS NULL OR
11840            p_delivery_info(i).PARTY_ID IS NULL OR
11841            p_delivery_info(i).SHIPMENT_DIRECTION IS NULL OR
11842            p_delivery_info(i).SHIPPING_CONTROL IS NULL ) AND
11843            p_action_code = G_UPDATE_DLVY THEN
11844 
11845            -- l_upd_delivery_rec may have a dummy location,
11846            -- Changing l_delivery_info,ultimate dropoff location id handles this case.
11847 
11848 	       OPEN c_get_dlvy(p_delivery_info(i).DELIVERY_ID);
11849              FETCH c_get_dlvy INTO l_upd_delivery_rec;
11850            CLOSE c_get_dlvy;
11851 
11852         END IF;
11853 
11854 	    l_delivery_info(i).DELIVERY_ID                       := p_delivery_info(i).DELIVERY_ID;
11855         l_delivery_info(i).TRIP_ID                           := p_delivery_info(i).TRIP_ID;
11856         l_delivery_info(i).EXISTS_IN_DATABASE                := p_delivery_info(i).EXISTS_IN_DATABASE;
11857         l_delivery_info(i).NAME                              := p_delivery_info(i).NAME;
11858         l_delivery_info(i).PLANNED_FLAG                      := p_delivery_info(i).PLANNED_FLAG;
11859         l_delivery_info(i).STATUS_CODE                       := p_delivery_info(i).STATUS_CODE;
11860         l_delivery_info(i).INITIAL_PICKUP_DATE               := p_delivery_info(i).INITIAL_PICKUP_DATE;
11861         l_delivery_info(i).INITIAL_PICKUP_LOCATION_ID        := nvl(p_delivery_info(i).INITIAL_PICKUP_LOCATION_ID,l_upd_delivery_rec.INITIAL_PICKUP_LOCATION_ID);
11862         l_delivery_info(i).ULTIMATE_DROPOFF_LOCATION_ID      := nvl(p_delivery_info(i).ULTIMATE_DROPOFF_LOCATION_ID,l_upd_delivery_rec.ULTIMATE_DROPOFF_LOCATION_ID);
11863         l_delivery_info(i).ULTIMATE_DROPOFF_DATE             := p_delivery_info(i).ULTIMATE_DROPOFF_DATE;
11864         l_delivery_info(i).CUSTOMER_ID                       := nvl(p_delivery_info(i).CUSTOMER_ID,l_upd_delivery_rec.CUSTOMER_ID);
11865         l_delivery_info(i).INTMED_SHIP_TO_LOCATION_ID        := p_delivery_info(i).INTMED_SHIP_TO_LOCATION_ID;
11866         l_delivery_info(i).SHIP_METHOD_CODE                  := p_delivery_info(i).SHIP_METHOD_CODE;
11867         l_delivery_info(i).DELIVERY_TYPE                     := p_delivery_info(i).DELIVERY_TYPE;
11868         l_delivery_info(i).CARRIER_ID                        := p_delivery_info(i).CARRIER_ID;
11869         l_delivery_info(i).ORGANIZATION_ID                   := nvl(p_delivery_info(i).ORGANIZATION_ID,l_upd_delivery_rec.ORGANIZATION_ID);
11870         l_delivery_info(i).SERVICE_LEVEL                     := p_delivery_info(i).SERVICE_LEVEL;
11871         l_delivery_info(i).MODE_OF_TRANSPORT                 := p_delivery_info(i).MODE_OF_TRANSPORT;
11872         l_delivery_info(i).PARTY_ID                          := nvl(p_delivery_info(i).PARTY_ID,l_upd_delivery_rec.PARTY_ID);
11873         l_delivery_info(i).SHIPMENT_DIRECTION                := nvl(nvl(p_delivery_info(i).SHIPMENT_DIRECTION,l_upd_delivery_rec.SHIPMENT_DIRECTION),'O');
11874         l_delivery_info(i).SHIPPING_CONTROL                  := nvl(nvl(p_delivery_info(i).SHIPPING_CONTROL,l_upd_delivery_rec.SHIPPING_CONTROL),'BUYER');
11875 
11876   	      --
11877         IF l_debug_on THEN
11878             WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info(i).initial_pickup_location_id : '||p_delivery_info(i).initial_pickup_location_id);
11879             WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info(i).ultimate_dropoff_location_id : '||p_delivery_info(i).ultimate_dropoff_location_id);
11880             WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info(i).initial_pickup_location_id : '||l_delivery_info(i).initial_pickup_location_id);
11881             WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info(i).ultimate_dropoff_location_id : '||l_delivery_info(i).ultimate_dropoff_location_id);
11882         END IF;
11883 	      --
11884          --#DUM_LOC(S)
11885 	    WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
11886              p_internal_cust_location_id  => l_delivery_info(i).ultimate_dropoff_location_id,
11887              x_internal_org_location_id   => l_physical_location_id,
11888              x_return_status              => l_return_status);
11889 
11890 	  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11891 	    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
11892 	       raise FND_API.G_EXC_UNEXPECTED_ERROR;
11893 	    END IF;
11894   	  END IF;
11895 
11896 	  IF (l_physical_location_id IS NOT NULL) THEN
11897   	      --
11898 	      IF l_debug_on THEN
11899 		  WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_delivery_info(i).ultimate_dropoff_location_id||' is a dummy location');
11900 	      END IF;
11901 	      --
11902 	      l_delivery_info(i).ultimate_dropoff_location_id := l_physical_location_id;
11903               -- AGDUMMY TODO
11904           l_delivery_info(i).physical_dropoff_location_id := l_physical_location_id;
11905   	  END IF;
11906           --#DUM_LOC(E)
11907 
11908         EXIT WHEN i = p_delivery_info.LAST;
11909         i := p_delivery_info.NEXT(i);
11910        --}
11911        END LOOP;
11912       END IF;
11913     END IF;
11914     --
11915     IF l_debug_on THEN
11916       WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info created : '||l_delivery_info.COUNT);
11917     END IF;
11918     --
11919 
11920     IF p_dlvy_assigned_lines.COUNT = 0 THEN
11921 
11922       l_end_count := 0;
11923       l_start_count := 0;
11924       i := l_delivery_info.FIRST;
11925       IF i IS NOT NULL THEN
11926       LOOP
11927       --
11928       IF l_debug_on THEN
11929         WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info : delivery id : '||l_delivery_info(i).delivery_id||' exists in db :'||l_delivery_info(i).exists_in_database);
11930       END IF;
11931 
11932       IF l_debug_on THEN
11933         WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info(i).delivery_type : '||l_delivery_info(i).delivery_type);
11934         --l_delivery_info(i).delivery_type := 'STANDARD';
11935         --WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info(i).delivery_type : '||l_delivery_info(i).delivery_type);
11936       END IF;
11937       --
11938       -- G_CREATE_DLVY should have 'N'
11939       IF l_delivery_info(i).exists_in_database = 'Y' THEN  -- Assigned lines have not been passed
11940       l_start_count := l_end_count + 1;
11941 
11942       IF l_delivery_info(i).delivery_type = 'STANDARD' THEN
11943           OPEN c_get_details(l_delivery_info(i).delivery_id);
11944           FETCH c_get_details BULK COLLECT INTO
11945                 l_detail_tab,l_delivery_tab,l_exists_tab,l_customer_tab,l_item_tab,l_shipfrom_loc_tab,
11946                 l_org_tab,l_shipto_loc_tab,l_intmed_shipto_loc_tab,
11947                 l_rel_stat_tab,l_cont_flag_tab,l_date_req_tab,l_date_sch_tab,
11948                 l_shipmethod_tab,l_carrier_tab,l_party_tab,l_line_direction_tab
11949                ,l_shipping_control_tab,l_dum_tab;
11950           --DUM_COMPILE (NULL)
11951           CLOSE c_get_details;
11952           IF l_debug_on THEN
11953             WSH_DEBUG_SV.logmsg(l_module_name,'after c_get_details: '||l_detail_tab.COUNT);
11954           END IF;
11955        ELSE
11956           OPEN c_get_details_consol(l_delivery_info(i).delivery_id);
11957           FETCH c_get_details_consol BULK COLLECT INTO
11958                 l_detail_tab,l_delivery_tab,l_exists_tab,l_customer_tab,l_item_tab,l_shipfrom_loc_tab,
11959                 l_org_tab,l_shipto_loc_tab,l_intmed_shipto_loc_tab,
11960                 l_rel_stat_tab,l_cont_flag_tab,l_date_req_tab,l_date_sch_tab,
11961                 l_shipmethod_tab,l_carrier_tab,l_party_tab,l_line_direction_tab
11962                ,l_shipping_control_tab,l_dum_tab;
11963           --DUM_COMPILE (NULL)
11964           CLOSE c_get_details_consol;
11965        END IF;
11966 
11967 
11968       END IF;
11969 
11970       IF l_detail_tab.COUNT > 0 THEN
11971          IF l_debug_on THEN
11972            WSH_DEBUG_SV.logmsg(l_module_name,'l_detail_tab.COUNT : '||l_detail_tab.COUNT);
11973          END IF;
11974          l_end_count := l_end_count + l_detail_tab.COUNT;
11975          k := 0;
11976 
11977 	 FOR j IN l_start_count .. l_end_count LOOP
11978 
11979 	   k := k+1;
11980            l_dlvy_assigned_lines(j).delivery_detail_id := l_detail_tab(k);
11981            l_dlvy_assigned_lines(j).delivery_id := l_delivery_tab(k);
11982            l_dlvy_assigned_lines(j).exists_in_database := 'Y';
11983            l_dlvy_assigned_lines(j).CUSTOMER_ID := l_customer_tab(k);
11984            l_dlvy_assigned_lines(j).INVENTORY_ITEM_ID := l_item_tab(k);
11985            l_dlvy_assigned_lines(j).SHIP_FROM_LOCATION_ID := l_shipfrom_loc_tab(k);
11986            l_dlvy_assigned_lines(j).ORGANIZATION_ID := l_org_tab(k);
11987            l_dlvy_assigned_lines(j).SHIP_TO_LOCATION_ID := l_shipto_loc_tab(k);
11988            l_dlvy_assigned_lines(j).INTMED_SHIP_TO_LOCATION_ID := l_intmed_shipto_loc_tab(k);
11989            l_dlvy_assigned_lines(j).RELEASED_STATUS := l_rel_stat_tab(k);
11990            l_dlvy_assigned_lines(j).CONTAINER_FLAG := l_cont_flag_tab(k);
11991            l_dlvy_assigned_lines(j).DATE_REQUESTED  := l_date_req_tab(k);
11992            l_dlvy_assigned_lines(j).DATE_SCHEDULED := l_date_sch_tab(k);
11993            l_dlvy_assigned_lines(j).SHIP_METHOD_CODE := l_shipmethod_tab(k);
11994            l_dlvy_assigned_lines(j).CARRIER_ID := l_carrier_tab(k);
11995            l_dlvy_assigned_lines(j).PARTY_ID := l_party_tab(k);
11996            l_dlvy_assigned_lines(j).LINE_DIRECTION := l_line_direction_tab(k);
11997            l_dlvy_assigned_lines(j).SHIPPING_CONTROL := l_shipping_control_tab(k);
11998 
11999 
12000 	   --#DUM_LOC(S)
12001 	   -- Delivery detail's Dummy ship_to_location_id has to be converted to physical internal
12002 	   -- location
12003 
12004 	   WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12005 	      p_internal_cust_location_id  => l_dlvy_assigned_lines(j).ship_to_location_id,
12006               x_internal_org_location_id   => l_physical_location_id,
12007               x_return_status              => l_return_status);
12008 
12009  	   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12010 	     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12011 	        raise FND_API.G_EXC_UNEXPECTED_ERROR;
12012 	     END IF;
12013     	   END IF;
12014 
12015   	   IF (l_physical_location_id IS NOT NULL) THEN
12016   	      --
12017 	      IF l_debug_on THEN
12018 		  WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_dlvy_assigned_lines(j).ship_to_location_id||' is a dummy location');
12019 	      END IF;
12020 	      --
12021 	      l_dlvy_assigned_lines(j).ship_to_location_id:= l_physical_location_id;
12022               -- AGDUMMY TODO
12023               l_dlvy_assigned_lines(j).physical_ship_to_location_id := l_physical_location_id;
12024 	   END IF;
12025            --#DUM_LOC(E)
12026 
12027 	END LOOP;
12028       END IF;
12029 
12030       EXIT WHEN i=l_delivery_info.LAST;
12031       i := l_delivery_info.NEXT(i);
12032       END LOOP;
12033       END IF;
12034     ELSE
12035 
12036       --
12037       IF l_debug_on THEN
12038         WSH_DEBUG_SV.logmsg(l_module_name,'p_dlvy_assigned_lines passed : '||p_dlvy_assigned_lines.COUNT);
12039       END IF;
12040       --
12041       i := p_dlvy_assigned_lines.FIRST;
12042       IF i IS NOT NULL THEN
12043        LOOP
12044 
12045              l_dlvy_assigned_lines(i).delivery_detail_id := p_dlvy_assigned_lines(i).delivery_detail_id;
12046              l_dlvy_assigned_lines(i).delivery_id := p_dlvy_assigned_lines(i).delivery_id;
12047              l_dlvy_assigned_lines(i).exists_in_database := p_dlvy_assigned_lines(i).exists_in_database;
12048              l_dlvy_assigned_lines(i).CUSTOMER_ID := p_dlvy_assigned_lines(i).CUSTOMER_ID;
12049              l_dlvy_assigned_lines(i).INVENTORY_ITEM_ID := p_dlvy_assigned_lines(i).INVENTORY_ITEM_ID;
12050              l_dlvy_assigned_lines(i).SHIP_FROM_LOCATION_ID := p_dlvy_assigned_lines(i).SHIP_FROM_LOCATION_ID;
12051              l_dlvy_assigned_lines(i).ORGANIZATION_ID := p_dlvy_assigned_lines(i).ORGANIZATION_ID;
12052              l_dlvy_assigned_lines(i).SHIP_TO_LOCATION_ID := p_dlvy_assigned_lines(i).SHIP_TO_LOCATION_ID;
12053              l_dlvy_assigned_lines(i).INTMED_SHIP_TO_LOCATION_ID := p_dlvy_assigned_lines(i).INTMED_SHIP_TO_LOCATION_ID;
12054              l_dlvy_assigned_lines(i).RELEASED_STATUS := p_dlvy_assigned_lines(i).RELEASED_STATUS;
12055              l_dlvy_assigned_lines(i).CONTAINER_FLAG := p_dlvy_assigned_lines(i).CONTAINER_FLAG;
12056              l_dlvy_assigned_lines(i).DATE_REQUESTED  := p_dlvy_assigned_lines(i).DATE_REQUESTED;
12057              l_dlvy_assigned_lines(i).DATE_SCHEDULED := p_dlvy_assigned_lines(i).DATE_SCHEDULED;
12058              l_dlvy_assigned_lines(i).SHIP_METHOD_CODE := p_dlvy_assigned_lines(i).SHIP_METHOD_CODE;
12059              l_dlvy_assigned_lines(i).CARRIER_ID := p_dlvy_assigned_lines(i).CARRIER_ID;
12060              l_dlvy_assigned_lines(i).party_id := p_dlvy_assigned_lines(i).party_id;
12061              l_dlvy_assigned_lines(i).line_direction := p_dlvy_assigned_lines(i).line_direction;
12062              l_dlvy_assigned_lines(i).shipping_control := nvl(p_dlvy_assigned_lines(i).shipping_control,'BUYER');
12063 
12064 	     --#DUM_LOC(S)
12065 	     WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12066 		 p_internal_cust_location_id  => l_dlvy_assigned_lines(i).ship_to_location_id,
12067                  x_internal_org_location_id   => l_physical_location_id,
12068                  x_return_status              => l_return_status);
12069 
12070 	     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12071 	       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12072 	          raise FND_API.G_EXC_UNEXPECTED_ERROR;
12073 	       END IF;
12074     	 END IF;
12075 
12076  	     IF (l_physical_location_id IS NOT NULL) THEN
12077   	        --
12078 	        IF l_debug_on THEN
12079 		        WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_dlvy_assigned_lines(i).ship_to_location_id||' is a dummy location');
12080    	        END IF;
12081 	        --
12082 	        l_dlvy_assigned_lines(i).ship_to_location_id:= l_physical_location_id;
12083                 -- AGDUMMY TODO
12084             l_dlvy_assigned_lines(i).physical_ship_to_location_id := l_physical_location_id;
12085   	     END IF;
12086              --#DUM_LOC(E)
12087 
12088 	 EXIT WHEN i = p_dlvy_assigned_lines.LAST;
12089          i := p_dlvy_assigned_lines.NEXT(i);
12090          END LOOP;
12091       END IF;
12092     END IF;
12093 
12094     IF p_action_code = G_ASSIGN_DLVY_TRIP THEN
12095 
12096      IF p_target_trip.trip_id IS NOT NULL  THEN
12097                                                         --  has been passed
12098        IF p_target_trip_assign_dels.COUNT = 0 THEN
12099           OPEN c_get_trip_dlvy(p_target_trip.trip_id); -- or container_id
12100           LOOP
12101                FETCH c_get_trip_dlvy INTO l_delivery_rec;
12102       	       EXIT WHEN c_get_trip_dlvy%NOTFOUND;
12103 
12104 	       --#DUM_LOC(S)
12105 	        WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12106 		        p_internal_cust_location_id  => l_delivery_rec.ultimate_dropoff_location_id,
12107 	            x_internal_org_location_id   => l_physical_location_id,
12108                 x_return_status              => l_return_status);
12109 
12110 	       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12111   		        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12112 		            raise FND_API.G_EXC_UNEXPECTED_ERROR;
12113 	            END IF;
12114 	       END IF;
12115 
12116 	       IF (l_physical_location_id IS NOT NULL) THEN
12117   	         --
12118 	         IF l_debug_on THEN
12119 		        WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_delivery_rec.ultimate_dropoff_location_id||' is a dummy location');
12120 	         END IF;
12121 	         --
12122 	         l_delivery_rec.ultimate_dropoff_location_id := l_physical_location_id;
12123                  -- AGDUMMY TODO
12124              l_delivery_rec.physical_dropoff_location_id := l_physical_location_id;
12125 	       END IF;
12126                --#DUM_LOC(E)
12127 
12128 	       l_trip_del_cnt := l_trip_del_cnt + 1;
12129                l_target_trip_assign_dels(l_trip_del_cnt) := l_delivery_rec;
12130            END LOOP;
12131            CLOSE c_get_trip_dlvy;
12132        ELSE
12133        l := p_target_trip_assign_dels.FIRST;
12134        LOOP
12135            l_target_trip_assign_dels(l) := p_target_trip_assign_dels(l);
12136            -- AGDUMMY
12137 
12138 	   --#DUM_LOC(S)
12139 	    WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12140 		p_internal_cust_location_id  => l_target_trip_assign_dels(l).ultimate_dropoff_location_id,
12141 	        x_internal_org_location_id   => l_physical_location_id,
12142                 x_return_status              => l_return_status);
12143 
12144 	   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12145   	      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12146 		  raise FND_API.G_EXC_UNEXPECTED_ERROR;
12147 	      END IF;
12148 	   END IF;
12149 
12150 	   IF (l_physical_location_id IS NOT NULL) THEN
12151   	      --
12152 	      IF l_debug_on THEN
12153 		    WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_target_trip_assign_dels(l).ultimate_dropoff_location_id||' is a dummy location');
12154 	      END IF;
12155 	      --
12156 	      l_target_trip_assign_dels(l).ultimate_dropoff_location_id := l_physical_location_id;
12157               -- AGDUMMY TODO
12158               l_target_trip_assign_dels(l).physical_dropoff_location_id := l_physical_location_id;
12159 	   END IF;
12160            --#DUM_LOC(E)
12161 
12162 	   EXIT WHEN l = p_target_trip_assign_dels.LAST;
12163            l := p_target_trip_assign_dels.NEXT(l);
12164        END LOOP;
12165        END IF;
12166 
12167        IF p_target_trip_dlvy_lines.COUNT = 0  THEN --AND p_action_code <> G_ASSIGN_DLVY_TRIP
12168           IF p_action_code = G_ASSIGN_DLVY_TRIP THEN
12169               OPEN c_get_trip_details_std(p_target_trip.trip_id); -- or container_id
12170               LOOP
12171                    FETCH c_get_trip_details_std INTO l_detail_rec;
12172                    EXIT WHEN c_get_trip_details_std%NOTFOUND;
12173 
12174                --#DUM_LOC(S)
12175                    WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12176                    p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
12177                    x_internal_org_location_id   => l_physical_location_id,
12178                    x_return_status              => l_return_status);
12179 
12180                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12181                         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12182                             raise FND_API.G_EXC_UNEXPECTED_ERROR;
12183                         END IF;
12184                    END IF;
12185 
12186                IF (l_physical_location_id IS NOT NULL) THEN
12187                  --
12188                  IF l_debug_on THEN
12189                     WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
12190                  END IF;
12191                  --
12192                  l_detail_rec.ship_to_location_id:= l_physical_location_id;
12193                      -- AGDUMMY TODO
12194                  l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
12195                END IF;
12196                    --#DUM_LOC(E)
12197 
12198                l_trip_detail_cnt := l_trip_detail_cnt + 1;
12199                l_target_trip_dlvy_lines(l_trip_detail_cnt) := l_detail_rec;
12200               END LOOP;
12201               CLOSE c_get_trip_details_std;
12202          ELSE
12203             OPEN c_get_trip_details(p_target_trip.trip_id); -- or container_id
12204               LOOP
12205                    FETCH c_get_trip_details INTO l_detail_rec;
12206                    EXIT WHEN c_get_trip_details%NOTFOUND;
12207 
12208                --#DUM_LOC(S)
12209                    WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12210                    p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
12211                    x_internal_org_location_id   => l_physical_location_id,
12212                    x_return_status              => l_return_status);
12213 
12214                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12215                         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12216                             raise FND_API.G_EXC_UNEXPECTED_ERROR;
12217                         END IF;
12218                    END IF;
12219 
12220                IF (l_physical_location_id IS NOT NULL) THEN
12221                  --
12222                  IF l_debug_on THEN
12223                     WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
12224                  END IF;
12225                  --
12226                  l_detail_rec.ship_to_location_id:= l_physical_location_id;
12227                      -- AGDUMMY TODO
12228                  l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
12229                END IF;
12230                    --#DUM_LOC(E)
12231 
12232                l_trip_detail_cnt := l_trip_detail_cnt + 1;
12233                l_target_trip_dlvy_lines(l_trip_detail_cnt) := l_detail_rec;
12234               END LOOP;
12235               CLOSE c_get_trip_details;
12236          END IF;
12237        ELSE
12238         l := p_target_trip_dlvy_lines.FIRST;
12239        LOOP
12240            l_target_trip_dlvy_lines(l) := p_target_trip_dlvy_lines(l);
12241 
12242 	   --#DUM_LOC(S)
12243 	   WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12244 	      p_internal_cust_location_id  => l_target_trip_dlvy_lines(l).ship_to_location_id,
12245               x_internal_org_location_id   => l_physical_location_id,
12246               x_return_status              => l_return_status);
12247 
12248  	   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12249 	     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12250 	        raise FND_API.G_EXC_UNEXPECTED_ERROR;
12251 	     END IF;
12252     	   END IF;
12253 
12254   	   IF (l_physical_location_id IS NOT NULL) THEN
12255   	      --
12256 	      IF l_debug_on THEN
12257 		  WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_target_trip_dlvy_lines(l).ship_to_location_id||' is a dummy location');
12258 	      END IF;
12259 	      --
12260 	      l_target_trip_dlvy_lines(l).ship_to_location_id:= l_physical_location_id;
12261               -- AGDUMMY TODO
12262               l_target_trip_dlvy_lines(l).physical_ship_to_location_id := l_physical_location_id;
12263 	   END IF;
12264            --#DUM_LOC(E)
12265 
12266 	   EXIT WHEN l = p_target_trip_dlvy_lines.LAST;
12267 	   l := p_target_trip_dlvy_lines.NEXT(l);
12268         END LOOP;
12269        END IF;
12270 
12271        IF p_target_trip_incl_stops.COUNT = 0 THEN
12272           OPEN c_get_trip_stops(p_target_trip.trip_id); -- or container_id
12273           LOOP
12274                --#DUM_LOC(S)
12275 	       --Made changes in the cursor only.
12276 	       --#DUM_LOC(E)
12277 	       FETCH c_get_trip_stops INTO l_stop_rec;
12278                EXIT WHEN c_get_trip_stops%NOTFOUND;
12279 	       l_trip_stops_cnt := l_trip_stops_cnt + 1;
12280                l_target_trip_incl_stops(l_trip_stops_cnt) := l_stop_rec;
12281           END LOOP;
12282           CLOSE c_get_trip_stops;
12283        ELSE
12284 
12285 	/* SBAKSHI 8/24
12286 	   We should have p_target_trip_incl_stops sorted by planned arrival date
12287 	   p_target_trip_incl_stops is IN RECORD record
12288 	   Need to make a local record structure, for this purpose.
12289 	   l_target_sort_trip_incl_stops
12290 	*/
12291 
12292    	   sort_stop_table_asc(
12293 		 p_stop_table	   => p_target_trip_incl_stops,
12294 		 x_sort_stop_table => l_target_trip_incl_sort_stops,
12295 		 x_return_status   => l_return_status);
12296 
12297 
12298  	   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12299 	     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12300 	        raise FND_API.G_EXC_UNEXPECTED_ERROR;
12301 	     END IF;
12302       END IF;
12303 
12304 	 -- l := p_target_trip_incl_stops.FIRST;
12305 
12306 	   l := l_target_trip_incl_sort_stops.FIRST;
12307 
12308 	   LOOP
12309            --l_target_trip_incl_stops(l) := p_target_trip_incl_stops(l);
12310 	     l_target_trip_incl_stops(l) := l_target_trip_incl_sort_stops(l);
12311 
12312 	   -- AGDUMMY
12313            -- Use physical_location_id from the record structure instead
12314            -- Also sort the input p_target_trip_incl_stops by planned_arrival_date
12315            -- One trip can have more than one set of dummy-physical stop pairs - wrudge 8/20
12316 	   --#DUM_LOC(S) (Using the record structure)
12317 
12318 	   IF (l_target_trip_incl_stops(l).physical_location_id IS NOT NULL) THEN
12319 	       --
12320 	       IF l_debug_on THEN
12321 		   WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_target_trip_incl_stops(l).stop_location_id||' is a dummy location');
12322 	       END IF;
12323 	       --
12324 	       l_target_trip_incl_stops(l).stop_location_id:=l_target_trip_incl_stops(l).physical_location_id;
12325 	   END IF;
12326 	   --#DUM_LOC(E)
12327 
12328 	   --  EXIT WHEN l = p_target_trip_incl_stops.LAST;
12329            --  l := p_target_trip_incl_stops.NEXT(l);
12330 
12331 	   EXIT WHEN l = l_target_trip_incl_sort_stops.LAST;
12332 	   l := l_target_trip_incl_sort_stops.NEXT(l);
12333 
12334  	   -- SBAKSHI 8/24
12335 	   END LOOP;
12336 
12337        END IF;
12338 
12339        OPEN c_gettripdetails(p_target_trip.trip_id);
12340        FETCH c_gettripdetails into l_target_trip;
12341        CLOSE c_gettripdetails;
12342      END IF;
12343 
12344      -- AGDUMMY
12345      -- Convert the PICKUP and DROPOFF for p_target_tripstops
12346 
12347      -- #DUM_LOC(S)
12348      -- p_target_tripstops.PICKUP_LOCATION_ID
12349 
12350      WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12351 	 p_internal_cust_location_id  => p_target_tripstops.pickup_location_id,
12352         x_internal_org_location_id   => l_physical_location_id,
12353         x_return_status              => l_return_status);
12354 
12355      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12356         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12357            raise FND_API.G_EXC_UNEXPECTED_ERROR;
12358         END IF;
12359      END IF;
12360 
12361      IF (l_physical_location_id IS NOT NULL) THEN
12362         --
12363         IF l_debug_on THEN
12364           WSH_DEBUG_SV.logmsg(l_module_name,'Location '||p_target_tripstops.pickup_location_id||' is a dummy location');
12365         END IF;
12366 	--
12367 	    p_target_tripstops.pickup_location_id:=l_physical_location_id;
12368      END IF;
12369 
12370      --	p_target_tripstops.DROPOFF_LOCATION_ID
12371 
12372      WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12373 	    p_internal_cust_location_id  => p_target_tripstops.dropoff_location_id,
12374         x_internal_org_location_id   => l_physical_location_id,
12375         x_return_status              => l_return_status);
12376 
12377      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12378         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12379            raise FND_API.G_EXC_UNEXPECTED_ERROR;
12380         END IF;
12381      END IF;
12382 
12383      IF (l_physical_location_id IS NOT NULL) THEN
12384         --
12385         IF l_debug_on THEN
12386           WSH_DEBUG_SV.logmsg(l_module_name,'Location '||p_target_tripstops.dropoff_location_id||' is a dummy location');
12387         END IF;
12388 	--
12389 	    p_target_tripstops.dropoff_location_id:=l_physical_location_id;
12390      END IF;
12391      --#DUM_LOC(E)
12392 
12393      IF l_debug_on THEN
12394         WSH_DEBUG_SV.logmsg(l_module_name,'p_target_tripstops.PICKUP_STOP_ID '||p_target_tripstops.PICKUP_STOP_ID);
12395         WSH_DEBUG_SV.logmsg(l_module_name,'p_target_tripstops.PICKUP_STOP_SEQ '||p_target_tripstops.PICKUP_STOP_SEQ);
12396         WSH_DEBUG_SV.logmsg(l_module_name,'p_target_tripstops.DROPOFF_STOP_ID '||p_target_tripstops.DROPOFF_STOP_ID);
12397         WSH_DEBUG_SV.logmsg(l_module_name,'p_target_tripstops.DROPOFF_STOP_SEQ '||p_target_tripstops.DROPOFF_STOP_SEQ);
12398         WSH_DEBUG_SV.logmsg(l_module_name,'p_target_tripstops.PICKUP_LOCATION_ID '||p_target_tripstops.PICKUP_LOCATION_ID);
12399         WSH_DEBUG_SV.logmsg(l_module_name,'p_target_tripstops.DROPOFF_LOCATION_ID '||p_target_tripstops.DROPOFF_LOCATION_ID);
12400      END IF;
12401      --
12402     END IF; -- G_ASSIGN_DLVY_TRIP
12403     --
12404     IF l_debug_on THEN
12405         WSH_DEBUG_SV.logmsg(l_module_name,'After populating table structures for action code '||p_action_code);
12406     END IF;
12407     --
12408 
12409     -- Populate assigned details
12410     --
12411     IF l_debug_on THEN
12412       WSH_DEBUG_SV.logmsg(l_module_name,'After populating l_comp_class_tab count : '||l_comp_class_tab.COUNT);
12413     END IF;
12414     --
12415 
12416     /*
12417     Auto create trip for delivery 	ACT	COM_FAC CUS_FAC CUS_CUS ITM_FAC ITM_ITM
12418 
12419     Assign deliveries to trip	        ADT	COM_FAC CUS_FAC CUS_CUS ITM_FAC ITM_ITM
12420                                                 FAC_MOD FAC_VEH FAC_CAR ITM_MOD ITM_CAR ITM_VEH
12421 
12422     Update (delivery, delivery leg)	UPD 	(Mode -FAC_MOD, ITM_MOD Carrier - ITM_CAR,FAC_CAR
12423     */
12424 
12425      -- Assumptions :
12426      -- 1. When you are here and have a delivery that means
12427      --    within a delivery, all attributes are valid
12428      -- When assigning deliveries to a trip
12429      -- 1. It creates trips for deliveries which do not have a trip at that point
12430      -- 2. If the deliveries under creation all have same ship method, it defaults that to the trip
12431      -- 3. Creates stops only for initial pickup and ultimate droppff, ignores intermediate
12432      -- 4. When creating trip stops creates sequence numbers arbitrarily
12433      --    ascending (eg. 10, 20, 30 etc.) as it finds new locations from the
12434      --    list of delivery
12435      -- 5. Assign to trip can pass a delivery and a target trip and
12436      --    override pickup stop and dropoff stop of those of the delivery
12437      -- 6. All validations on trip stops are based on stop sequence number and
12438      --    not stop dates
12439 
12440      -- Record types : Child, entity, group
12441      -- Child : child id, entity id
12442      -- Entity : entity id, pickup, dropoff, org, customer, group id
12443      -- Group : Group id
12444      -- Here entity : Delivery
12445      -- For every delivery : search existing groups if can be added
12446      -- If not, create a new group else add to the matching group and proceed
12447      -- search routine should take entity record as well as children table
12448 
12449 
12450       -- This loop checks only itm-itm and cus-cus for every delivery
12451       -- against every other delivery
12452       -- also itm-fac with pickup / dropoff locations of other delivery
12453       -- also com-fac, cus-fac with pickup / dropoff locations of other delivery
12454 
12455       -- Following done for ACT and ADT
12456       -- Valid groups created looking at only Exclusive constraints
12457 
12458      --
12459      --DUM_LOC We have modified record p_target_tripstops to store physical locations
12460      --in case of dummy locations.
12461 
12462     IF p_action_code = G_ASSIGN_DLVY_TRIP AND
12463        ( p_target_tripstops.pickup_location_id IS NOT NULL OR
12464          p_target_tripstops.dropoff_location_id IS NOT NULL ) THEN
12465 
12466     IF (l_target_trip.carrier_id IS NULL OR l_target_trip.MODE_OF_TRANSPORT IS NULL) AND
12467          (l_target_trip.ship_method_code IS NOT NULL) THEN
12468 
12469       l_carrier_service_inout_rec.ship_method_code := l_target_trip.ship_method_code;
12470       WSH_CARRIERS_GRP.get_carrier_service_mode(
12471                p_carrier_service_inout_rec   =>  l_carrier_service_inout_rec,
12472                x_return_status		     =>  l_return_status);
12473 
12474       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12475         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12476          IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
12477             raise FND_API.G_EXC_UNEXPECTED_ERROR;
12478          END IF;
12479          raise g_get_carrmode_failed;
12480         END IF;
12481       END IF;
12482       l_carrier := l_carrier_service_inout_rec.carrier_id;
12483       l_mode    := l_carrier_service_inout_rec.mode_of_transport;
12484 
12485     END IF; -- l_target_trip.carrier_id IS NULL OR ..
12486     IF l_debug_on THEN
12487        WSH_DEBUG_SV.logmsg(l_module_name,'target trip carrier : '||l_target_trip.carrier_id||' Mode : '||l_target_trip.mode_of_transport||' ship method : '||l_target_trip.ship_method_code);
12488     END IF;
12489 
12490       -- If carrier_id or mode is passed in, then those get preference for validation
12491       -- If they are not, they are derived from ship method if that is passed
12492 
12493     IF l_target_trip.carrier_id IS NOT NULL THEN
12494        l_carrier := l_target_trip.carrier_id;
12495     END IF;
12496     IF l_target_trip.mode_of_transport IS NOT NULL THEN
12497        l_mode := l_target_trip.mode_of_transport;
12498     END IF;
12499 
12500     IF (l_target_trip.VEHICLE_ITEM_ID IS NOT NULL AND l_target_trip.VEHICLE_ORGANIZATION_ID IS NOT NULL) THEN
12501 
12502       WSH_FTE_INTEGRATION.get_vehicle_type(
12503                p_vehicle_item_id     =>  l_target_trip.VEHICLE_ITEM_ID,
12504                p_vehicle_org_id      =>  l_target_trip.VEHICLE_ORGANIZATION_ID,
12505                x_vehicle_type_id     =>  l_vehicle_type,
12506                x_return_status       =>  l_return_status);
12507 
12508       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12509          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12510          IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
12511             raise FND_API.G_EXC_UNEXPECTED_ERROR;
12512          END IF;
12513             l_vehicle_name := WSH_UTIL_CORE.get_item_name (p_item_id => l_target_trip.VEHICLE_ITEM_ID,
12514                                                            p_organization_id => l_target_trip.VEHICLE_ORGANIZATION_ID);
12515             l_vehicle_org_name := WSH_UTIL_CORE.get_org_name (p_organization_id => l_target_trip.VEHICLE_ORGANIZATION_ID);
12516             FND_MESSAGE.SET_NAME('WSH','WSH_VEHICLE_TYPE_UNDEFINED');
12517             FND_MESSAGE.SET_TOKEN('ITEM',l_vehicle_name);
12518             FND_MESSAGE.SET_TOKEN('ORGANIZATION',l_vehicle_org_name);
12519             FND_MSG_PUB.ADD;
12520             --raise g_get_vehicletype_failed;
12521          END IF;
12522       END IF;
12523 
12524     END IF; -- l_target_trip.VEHICLE_ITEM_ID IS NOT NULL AND ..
12525 
12526     FOR i IN 1..2 LOOP
12527 
12528         -- Do the checks in calling procedure if pickup/dropoff stop/location ids have been passed
12529 
12530         IF i = 1 THEN
12531            IF p_target_tripstops.pickup_location_id IS NOT NULL AND
12532               p_target_tripstops.pickup_stop_id IS NULL THEN
12533                 l_location_id := p_target_tripstops.pickup_location_id;
12534                 IF l_debug_on THEN
12535                    WSH_DEBUG_SV.logmsg(l_module_name,'target pickup location id not null');
12536                 END IF;
12537            -- ELSIF p_target_tripstops.pickup_stop_id IS NOT NULL THEN
12538            -- If the pickupstop does not already exist in the target trip
12539            -- check here, if already exists then do not check
12540            -- not possible, p_target_tripstops.pickup_stop_id IS NOT NULL
12541            -- implies it already exists in the target trip
12542            ELSE
12543               -- Nothing to check
12544                 GOTO next_pass;
12545            END IF;
12546         ELSIF i = 2 THEN
12547            IF p_target_tripstops.dropoff_location_id IS NOT NULL AND
12548               p_target_tripstops.dropoff_stop_id IS NULL THEN
12549                 l_location_id := p_target_tripstops.dropoff_location_id;
12550                 IF l_debug_on THEN
12551                    WSH_DEBUG_SV.logmsg(l_module_name,'target dropoff location id not null');
12552                 END IF;
12553            ELSE
12554               -- Nothing to check
12555                 GOTO next_pass;
12556            END IF;
12557         END IF;
12558         --
12559         IF l_debug_on THEN
12560            WSH_DEBUG_SV.logmsg(l_module_name,'i : '||i||' l_location_id : '||l_location_id);
12561         END IF;
12562         --
12563 
12564         IF l_comp_class_tab.EXISTS(G_FACILITY_VEHICLE_NUM) AND
12565             l_vehicle_type IS NOT NULL THEN
12566 
12567             validate_constraint(
12568              p_comp_class_code          =>      G_FACILITY_VEHICLE,
12569              p_object1_type             =>      'FAC',
12570              p_object1_val_num          =>      l_location_id,
12571              p_object2_type             =>      'VHT',
12572              p_object2_val_num          =>      l_vehicle_type,
12573              x_validate_result          =>      l_validate_vehicle_result,
12574              x_failed_constraint        =>      l_failed_constraint,
12575              x_return_status            =>      l_return_status);
12576 
12577             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12578                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12579                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
12580                END IF;
12581             END IF;
12582 
12583             IF l_validate_vehicle_result <> 'S' THEN
12584               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
12585               l_failed_constraint.entity_type := G_LOCATION;
12586               l_failed_constraint.entity_line_id := l_location_id;
12587               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
12588               IF l_validate_vehicle_result = 'E' THEN
12589                x_validate_result := 'F';
12590               END IF;
12591             END IF;
12592 
12593         END IF;
12594 
12595         IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) AND
12596             l_carrier IS NOT NULL THEN
12597 
12598             validate_constraint(
12599              p_comp_class_code          =>      G_FACILITY_CARRIER,
12600              p_object1_type             =>      'FAC',
12601              p_object1_val_num          =>      l_location_id,
12602              p_object2_type             =>      'CAR',
12603              p_object2_val_num          =>      l_carrier,
12604              x_validate_result          =>      l_validate_carrier_result,
12605              x_failed_constraint        =>      l_failed_constraint,
12606              x_return_status            =>      l_return_status);
12607 
12608             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12609                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12610                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
12611                END IF;
12612             END IF;
12613 
12614             IF l_validate_carrier_result <> 'S' THEN
12615               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
12616               l_failed_constraint.entity_type := G_LOCATION;
12617               l_failed_constraint.entity_line_id := l_location_id;
12618               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
12619               IF l_validate_carrier_result = 'E' THEN
12620                x_validate_result := 'F';
12621               END IF;
12622             END IF;
12623 
12624         END IF;
12625 
12626         IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) AND
12627             l_mode IS NOT NULL THEN
12628 
12629             validate_constraint(
12630              p_comp_class_code          =>      G_FACILITY_MODE,
12631              p_object1_type             =>      'FAC',
12632              p_object1_val_num          =>      l_location_id,
12633              p_object2_type             =>      'MOD',
12634              p_object2_val_char          =>     l_mode,
12635              x_validate_result          =>      l_validate_mode_result,
12636              x_failed_constraint        =>      l_failed_constraint,
12637              x_return_status            =>      l_return_status);
12638 
12639             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12640                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12641                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
12642                END IF;
12643             END IF;
12644 
12645             IF l_validate_mode_result <> 'S' THEN
12646               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
12647               l_failed_constraint.entity_type := G_LOCATION;
12648               l_failed_constraint.entity_line_id := l_location_id;
12649               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
12650               IF l_validate_mode_result = 'E' THEN
12651                x_validate_result := 'F';
12652               END IF;
12653             END IF;
12654 
12655         END IF;
12656 
12657     <<next_pass>>
12658     null;
12659 
12660     END LOOP;
12661 
12662     END IF;
12663 
12664     k := l_delivery_info.FIRST;
12665     IF k IS NOT NULL THEN
12666       LOOP
12667 
12668         -- Skip if shipping control is SUPPLIER
12669         --Bug 9222910   replaced  l_delivery_info(k).delivery_id with l_delivery_info_mod  ,  WSH_UTIL_CORE.C_INDEX_LIMIT value is 2147483648; -- power(2,31)
12670         l_delivery_info_mod := MOD(l_delivery_info(k).delivery_id , WSH_UTIL_CORE.C_INDEX_LIMIT) ;
12671 
12672         IF l_delivery_info(k).shipping_control = 'SUPPLIER' THEN
12673 
12674             l_supp_control_tab(l_delivery_info_mod) := l_delivery_info(k).delivery_id;
12675             GOTO next_delivery;
12676 
12677         END IF;
12678 
12679         l_group_id         :=0;
12680         l_found            := FALSE;
12681 
12682 
12683         IF p_action_code IN (G_AUTOCRT_DLVY_TRIP,G_ASSIGN_DLVY_TRIP, G_AUTOCRT_MDC) THEN
12684 
12685          l_entity_tab(l_delivery_info_mod).entity_id := l_delivery_info(k).delivery_id;
12686          l_entity_tab(l_delivery_info_mod).organization_id := l_delivery_info(k).organization_id;
12687          l_entity_tab(l_delivery_info_mod).initial_pickup_location_id := l_delivery_info(k).initial_pickup_location_id;
12688          l_entity_tab(l_delivery_info_mod).ultimate_dropoff_location_id := l_delivery_info(k).ultimate_dropoff_location_id;
12689          l_entity_tab(l_delivery_info_mod).initial_pickup_date := l_delivery_info(k).initial_pickup_date;
12690          l_entity_tab(l_delivery_info_mod).ultimate_dropoff_date := l_delivery_info(k).ultimate_dropoff_date;
12691          l_entity_tab(l_delivery_info_mod).physical_dropoff_location_id := l_delivery_info(k).physical_dropoff_location_id;
12692          l_entity_tab(l_delivery_info_mod).intmed_ship_to_location_id := l_delivery_info(k).intmed_ship_to_location_id;
12693          l_entity_tab(l_delivery_info_mod).ship_method_code := l_delivery_info(k).ship_method_code;
12694          l_entity_tab(l_delivery_info_mod).carrier_id := l_delivery_info(k).carrier_id;
12695          l_entity_tab(l_delivery_info_mod).mode_of_transport := l_delivery_info(k).mode_of_transport;
12696          l_entity_tab(l_delivery_info_mod).customer_id := l_delivery_info(k).customer_id;
12697          l_entity_tab(l_delivery_info_mod).party_id := l_delivery_info(k).party_id;
12698          l_entity_tab(l_delivery_info_mod).shipment_direction := l_delivery_info(k).shipment_direction;
12699          l_entity_tab(l_delivery_info_mod).shipping_control := l_delivery_info(k).shipping_control;
12700          --
12701          IF l_debug_on THEN
12702             WSH_DEBUG_SV.logmsg(l_module_name,'Created l_entity_tab with index : '||l_delivery_info_mod||' for delivery index '||k);
12703        WSH_DEBUG_SV.logmsg(l_module_name,'l_entity_tab(l_delivery_info_mod).entity_id : '||l_entity_tab(l_delivery_info_mod).entity_id);
12704        WSH_DEBUG_SV.logmsg(l_module_name,'l_entity_tab(l_delivery_info_mod).initial_pickup_location_id : '||l_entity_tab(l_delivery_info_mod).initial_pickup_location_id);
12705        WSH_DEBUG_SV.logmsg(l_module_name,'l_entity_tab(l_delivery_info_mod).ultimate_dropoff_location_id : '||l_entity_tab(l_delivery_info_mod).ultimate_dropoff_location_id);
12706        WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info(k).initial_pickup_location_id : '||l_delivery_info(k).initial_pickup_location_id);
12707        WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info(k).ultimate_dropoff_location_id : '||l_delivery_info(k).ultimate_dropoff_location_id);
12708          END IF;
12709          --
12710 
12711          IF k <> l_delivery_info.FIRST THEN
12712 
12713             search_matching_group(
12714                   p_entity_type           => 'DLVY',
12715                   p_action_code           => p_action_code,
12716                   p_children_info         => l_dlvy_assigned_lines,
12717                   p_comp_class_tab        => l_comp_class_tab,
12718                   p_target_stops_info     => p_target_tripstops,
12719                   p_entity_rec            => l_entity_tab(l_delivery_info_mod),  --Bug 9222910
12720                   p_target_trip_id        => l_target_trip.trip_id,
12721                   p_entity_tab            => l_entity_tab,
12722                   p_group_tab             => x_group_info,
12723                   x_failed_constraints    => l_failed_constraints,
12724                   x_group_id              => l_group_id,
12725                   x_found                 => l_found,
12726                   x_return_status         => l_return_status);
12727             --
12728             IF l_debug_on THEN
12729               WSH_DEBUG_SV.logmsg(l_module_name,'Called search_matching_group return status : '||l_return_status||' Group found ? '||l_group_id);
12730             END IF;
12731             --
12732 
12733             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12734                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12735                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
12736                END IF;
12737             END IF;
12738 
12739          END IF;
12740 
12741          IF l_found THEN
12742               l_entity_tab(l_delivery_info_mod).group_id := l_group_id; --Bug 9222910
12743          ELSE
12744 
12745               create_valid_entity_group(
12746                   p_entity_rec            => l_entity_tab(l_delivery_info_mod),  --Bug 9222910
12747                   p_group_tab             => x_group_info,
12748                   x_return_status         => l_return_status);
12749               --
12750               IF l_debug_on THEN
12751                  WSH_DEBUG_SV.logmsg(l_module_name,'Called create_valid_entity_group return status : '||l_return_status);
12752               END IF;
12753               --
12754 
12755               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12756                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12757                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
12758                   END IF;
12759               END IF;
12760 
12761          END IF;
12762 
12763       -- Following done only for ADT
12764          IF p_action_code = G_ASSIGN_DLVY_TRIP THEN
12765 
12766          -- Here check the delivery against target trip for exclusive constraints
12767          -- com -fac, cus - fac, itm - fac for each delivery against trip stops
12768          -- itm -mod, itm - car and fac-mod, fac-car
12769          -- org - car, org - mode will not be stored in constraints table 11/6
12770          -- itm - itm, cus - cus
12771          -- Any delivery that is violating, remove from the group
12772 
12773             check_dlvy_against_trip(
12774                  p_entity_type         => 'DLVY',
12775                  p_delivery_rec        => l_delivery_info(k),
12776                  p_entity_id           => l_delivery_info(k).delivery_id,
12777                  p_detail_tab          => l_dlvy_assigned_lines,
12778                  p_comp_class_tab      => l_comp_class_tab,
12779                  p_target_stops_info   => p_target_tripstops,
12780                  p_target_trip         => l_target_trip,
12781                  p_target_tripstops    => l_target_trip_incl_stops,
12782                  p_target_dlvy         => l_target_trip_assign_dels,
12783                  p_target_dlvy_lines   => l_target_trip_dlvy_lines,
12784                  x_failed_constraints  => l_failed_constraints,
12785                  x_validate_result     => l_validate_result,
12786                  x_return_status       => l_return_status);
12787             --
12788             IF l_debug_on THEN
12789                WSH_DEBUG_SV.logmsg(l_module_name,'Called check_dlvy_against_trip return status : '||l_return_status||' validate result : '||l_validate_result);
12790             END IF;
12791             --
12792 
12793             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12794                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12795                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
12796                 END IF;
12797             END IF;
12798 
12799             IF l_return_status IN (WSH_UTIL_CORE.G_RET_STS_SUCCESS,WSH_UTIL_CORE.G_RET_STS_WARNING)
12800                THEN
12801                IF l_validate_result = 'F' THEN
12802                   -- Remove delivery from the line group
12803                   -- add to the failed lines
12804                   l_failed_lc := l_failed_lc + 1;
12805                   l_entity_tab.DELETE(l_delivery_info_mod); --Bug 9222910
12806                   x_failed_lines(l_failed_lc).entity_line_id := l_delivery_info(k).delivery_id;
12807                   x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
12808 
12809                END IF;
12810 
12811             END IF;
12812 
12813          END IF; -- ADT
12814 
12815          l_dummy_failed_lc := l_dummy_failed_lc + 1;
12816          l_dummy_failed_lines(l_dummy_failed_lc).entity_line_id := l_delivery_info(k).delivery_id;
12817          l_dummy_failed_lines(l_dummy_failed_lc).failed_line_index := l_dummy_failed_lc;
12818 
12819          -- Populate x_line_groups table if l_entity_tab(l_delivery_info_mod) exists
12820          -- Best place to populate x_line_groups is in
12821          -- validate_positive_constraint as that has the latest l_entity_tab
12822 
12823         END IF; -- ADT ACT
12824 
12825         IF p_action_code IN (G_UPDATE_DLVY,G_CREATE_DLVY) THEN
12826 
12827          -- Need to skip an Inbound delivery
12828          -- if the trip's status is "In Transit" or "Closed"
12829 
12830          IF l_delivery_info(k).status_code IN ('IT','CL') AND
12831                l_delivery_info(k).shipment_direction = 'I' THEN
12832                GOTO next_delivery;
12833          END IF;
12834 
12835          check_upd_dlvy(
12836                  p_delivery_rec        => l_delivery_info(k),
12837                  p_detail_tab          => l_dlvy_assigned_lines,
12838                  p_comp_class_tab      => l_comp_class_tab,
12839                  x_failed_constraints  => l_failed_constraints,
12840                  x_validate_result     => l_validate_result,
12841                  x_return_status       => l_return_status);
12842          --
12843          IF l_debug_on THEN
12844            WSH_DEBUG_SV.logmsg(l_module_name,'Called check_upd_dlvy return status : '||l_return_status||' validate result : '||l_validate_result);
12845          END IF;
12846          --
12847 
12848          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12849             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12850 
12851                raise FND_API.G_EXC_UNEXPECTED_ERROR;
12852             END IF;
12853          END IF;
12854 
12855          IF l_return_status IN (WSH_UTIL_CORE.G_RET_STS_SUCCESS,WSH_UTIL_CORE.G_RET_STS_WARNING) THEN
12856 
12857             IF l_validate_result = 'F' THEN
12858                -- Remove delivery from the line group
12859                -- add to the failed lines
12860                l_failed_lc := l_failed_lc + 1;
12861                x_failed_lines(l_failed_lc).entity_line_id := l_delivery_info(k).delivery_id;
12862                x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
12863 
12864                --
12865                IF l_debug_on THEN
12866                   WSH_DEBUG_SV.logmsg(l_module_name,'Adding failed delivery : '||l_delivery_info(k).delivery_id);
12867                END IF;
12868                --
12869 
12870             ELSE
12871 
12872                -- Populate x_line_groups table
12873                l_linegroup_indx := l_linegroup_indx + 1;
12874                x_line_groups(l_linegroup_indx).line_group_index := l_linegroup_indx;
12875                x_line_groups(l_linegroup_indx).entity_line_id   := l_delivery_info(k).delivery_id;
12876 
12877                --
12878                IF l_debug_on THEN
12879                   WSH_DEBUG_SV.logmsg(l_module_name,'Adding to linegroup delivery : '||l_delivery_info(k).delivery_id);
12880                END IF;
12881                --
12882 
12883             END IF;
12884 
12885          END IF;
12886 
12887 
12888         END IF;
12889 
12890         <<next_delivery>>
12891 
12892         EXIT WHEN k = l_delivery_info.LAST;
12893         k := l_delivery_info.NEXT(k);
12894 
12895       END LOOP;
12896     END IF;
12897 
12898     IF p_action_code IN (G_AUTOCRT_DLVY_TRIP,G_ASSIGN_DLVY_TRIP, G_AUTOCRT_MDC) AND
12899         (l_supp_control_tab.COUNT <> l_delivery_info.COUNT) THEN
12900       -- For each group / target trip
12901       -- find out list of stops to be created
12902       -- validate org - fac, cus - fac, itm -fac for must be constraints for each delivery
12903       -- shipmethod for the trip is populated only if all deliveries have same
12904       -- hence no need to validate fac - car fac - mode, itm - car, itm - mode for ACT
12905       -- For ADT : for each delivery validate these against those of the trip
12906 
12907       -- If ACT
12908       -- For each group created,
12909       -- check for violating group elements
12910       -- considering only positive constraints
12911       -- Remove group elements (deliveries) that are violating
12912       -- Handle more than one facilities (item also here or at dlvb ?) in same trip (group)
12913       -- having different must be carrier / mode
12914       -- : Put them in separate groups
12915 
12916       -- If ADT
12917       -- For each group created, check against target trip
12918       -- for positive constraints
12919       -- Remove violating group elements (deliveries) from the group
12920 
12921 
12922       validate_positive_constraint(
12923                     p_action_code         => p_action_code,
12924                     p_comp_class_tab      => l_comp_class_tab,
12925                     p_entity_tab          => l_entity_tab,
12926                     p_group_tab           => x_group_info,
12927                     p_detail_tab          => l_dlvy_assigned_lines,
12928                     p_target_trip         => l_target_trip,
12929                     p_target_tripstops    => l_target_trip_incl_stops,
12930                     p_target_stops_info   => p_target_tripstops,
12931                     x_line_groups         => x_line_groups,
12932                     x_failed_lines        => x_failed_lines,
12933                     x_failed_constraints  => l_failed_constraints,
12934                     x_return_status       => l_return_status);
12935       --
12936       IF l_debug_on THEN
12937         WSH_DEBUG_SV.logmsg(l_module_name,'Called validate_positive_constraint return status : '||l_return_status);
12938       END IF;
12939       --
12940 
12941       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12942          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12943             raise FND_API.G_EXC_UNEXPECTED_ERROR;
12944          END IF;
12945       END IF;
12946 
12947     END IF; -- ACT ADT
12948 
12949     IF l_supp_control_tab.COUNT > 0 THEN
12950 
12951         -- Populate line_groups and group
12952         -- Add to x_group_info
12953         l_group_count := x_group_info.COUNT + 1;
12954         x_group_info(l_group_count).group_index := l_group_count;
12955         x_group_info(l_group_count).line_group_id := l_group_count;
12956 
12957         i := l_supp_control_tab.FIRST;
12958         LOOP
12959 
12960            -- Populate x_line_groups table
12961            l_linegroup_indx := x_line_groups.COUNT + 1;
12962            x_line_groups(l_linegroup_indx).line_group_index := l_linegroup_indx;
12963            x_line_groups(l_linegroup_indx).entity_line_id   := l_supp_control_tab(i);
12964            x_line_groups(l_linegroup_indx).line_group_id    := l_group_count;
12965 
12966            EXIT WHEN i=l_supp_control_tab.LAST;
12967            i := l_supp_control_tab.NEXT(i);
12968         END LOOP;
12969 
12970     END IF;
12971 
12972     IF x_validate_result = 'F' THEN  -- Means for G_ASSIGN_DLVY_TRIP
12973     /*
12974     IF l_validate_vehicle_result = 'E' OR l_validate_mode_result = 'E' OR
12975        l_validate_carrier_result = 'E' THEN  -- Means for G_ASSIGN_DLVY_TRIP
12976     */
12977                                              -- one or more of the input locations have failed
12978         IF x_failed_lines.COUNT > 0 THEN
12979            x_failed_lines.DELETE;
12980         END IF;
12981         -- Need to populate all input lines into x_failed_lines
12982         i := l_dummy_failed_lines.FIRST;
12983         LOOP
12984 
12985            x_failed_lines(i) := l_dummy_failed_lines(i);
12986 
12987            EXIT WHEN i=l_dummy_failed_lines.LAST;
12988            i := l_dummy_failed_lines.NEXT(i);
12989         END LOOP;
12990 
12991         -- delete entries from x_group_info and x_line_groups
12992         --x_group_info.DELETE;
12993         --x_line_groups.DELETE;
12994     ELSIF x_group_info.COUNT > 1 OR x_failed_lines.COUNT > 0 THEN  -- Supplier controlled can be 2
12995         x_validate_result := 'F';
12996         IF x_group_info.COUNT > 1 AND p_action_code = G_ASSIGN_DLVY_TRIP THEN
12997            -- Put all input lines in incompatible groups into failed lines
12998 
12999            -- After changing the logic to form groups in case of
13000            -- assign, the following list of groups will only contain
13001            -- mutually incompatible groups
13002            -- not the always successful groups
13003            i := x_group_info.FIRST;
13004            LOOP
13005 
13006              -- Will not delete these lines from linegroups
13007              -- Hence for this case the sum of failed lines and
13008              -- lines in linegroups will exceed number of input lines
13009              -- by these lines in linegroups
13010              -- Will not delete these incompatible groups
13011              j := x_line_groups.FIRST;
13012              LOOP
13013 
13014                 IF x_line_groups(j).line_group_id <> x_group_info(i).line_group_id THEN
13015                    GOTO next_linegroup;
13016                 END IF;
13017 
13018                 -- Add to failed lines
13019                 l_failed_lc := x_failed_lines.COUNT + 1;
13020                 x_failed_lines(l_failed_lc).entity_line_id := x_line_groups(j).entity_line_id;
13021                 x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
13022 
13023 
13024                 <<next_linegroup>>
13025 
13026                 EXIT WHEN j=x_line_groups.LAST;
13027                 j := x_line_groups.NEXT(j);
13028              END LOOP;
13029 
13030              EXIT WHEN i=x_group_info.LAST;
13031              i := x_group_info.NEXT(i);
13032            END LOOP;
13033         END IF;
13034     END IF;
13035 
13036     IF x_failed_lines.COUNT = 0 AND (p_action_code = G_AUTOCRT_DLVY_TRIP OR p_action_code = G_AUTOCRT_MDC) THEN
13037         l_failed_constraints.DELETE;
13038     END IF;
13039 
13040     --  Loop over l_failed_constraints to add to the mesage stack
13041 
13042     stack_messages (
13043              p_failed_constraints       => l_failed_constraints,
13044              x_msg_count                => x_msg_count,
13045              x_msg_data                 => x_msg_data,
13046              x_return_status            => l_return_status);
13047     --
13048     IF l_debug_on THEN
13049         WSH_DEBUG_SV.logmsg(l_module_name,'Called stack_messages return status : '||l_return_status);
13050     END IF;
13051     --
13052 
13053     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13054          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13055             raise FND_API.G_EXC_UNEXPECTED_ERROR;
13056          END IF;
13057     END IF;
13058 
13059     -- Now can get x_validate_result = 'F' with x_group_info.COUNT = 1 and
13060     -- x_failed_lines.COUNT = 0 in case of assign delivery to trip
13061     -- Means there is violation for input pickup/dropoff stop/location
13062 
13063     IF x_validate_result = 'F' THEN
13064         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
13065 
13066     ELSIF l_failed_constraints.COUNT > 0 THEN
13067 
13068         x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
13069     END IF;
13070 
13071 
13072     --
13073     IF l_debug_on THEN
13074       WSH_DEBUG_SV.pop(l_module_name);
13075     END IF;
13076     --
13077 
13078 EXCEPTION
13079     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
13080       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
13081       --
13082       IF l_debug_on THEN
13083         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
13084         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
13085       END IF;
13086       --
13087     WHEN others THEN
13088       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.validate_constraint_dlvy');
13089       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
13090       --
13091       IF l_debug_on THEN
13092         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
13093         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
13094       END IF;
13095       --
13096 
13097 END validate_constraint_dlvy;
13098 
13099 --***************************************************************************--
13100 
13101 --========================================================================
13102 -- PROCEDURE : validate_constraint_dleg    Called by constraint Wrapper API
13103 --                                         and the Lane search API.
13104 --
13105 -- PARAMETERS: p_init_msg_list             FND_API.G_TRUE to reset list
13106 --             p_action_code               Predefined action code
13107 --             p_exception_list            Compatibility classes to skip if any
13108 --                                         indexed by class code numbers
13109 --             p_delivery_leg_rec          Input delivery leg record
13110 --             p_target_trip               Table of target trips for delivery leg trip search
13111 --             p_target_lane               Table of target lane for delivery leg lane search
13112 --             x_succ_trips                List of input trips that passed constraint check
13113 --             x_succ_lanes                List of input lanes that passed constraint check
13114 --             x_validate_result           Constraint Validation result : S / F
13115 --             x_msg_count                 Number of messages in the list
13116 --             x_msg_data                  Text of messages
13117 --             x_return_status             Return status
13118 -- COMMENT   : This procedure is used to perform for following actions
13119 --             A. Lane search for delivery leg (DLS)
13120 --========================================================================
13121 
13122 PROCEDURE validate_constraint_dleg(
13123              p_init_msg_list            IN      VARCHAR2 DEFAULT fnd_api.g_false,
13124              p_action_code              IN      VARCHAR2 DEFAULT NULL,
13125              p_exception_list           IN      WSH_UTIL_CORE.Column_Tab_Type,
13126              p_delivery_leg_rec         IN      dleg_ccinfo_rec_type,
13127              p_target_trip              IN      trip_ccinfo_tab_type,
13128              p_target_lane              IN      lane_ccinfo_tab_type,
13129              x_succ_trips               OUT NOCOPY  WSH_UTIL_CORE.id_tab_type,
13130              x_succ_lanes               OUT NOCOPY  WSH_UTIL_CORE.id_tab_type,
13131              x_validate_result          OUT NOCOPY  VARCHAR2,
13132              x_msg_count                OUT NOCOPY  NUMBER,
13133              x_msg_data                 OUT NOCOPY  VARCHAR2,
13134              x_return_status            OUT NOCOPY  VARCHAR2)
13135 
13136 IS
13137 
13138     cursor get_num_child_dlegs(p_delivery_leg_id IN NUMBER) IS
13139     SELECT
13140         count(*)
13141     FROM wsh_delivery_legs
13142     WHERE parent_delivery_leg_id = p_delivery_leg_id;
13143 
13144     l_orig_dlvy_puloc           NUMBER:=0;
13145     l_orig_dlvy_udloc           NUMBER:=0;
13146     l_intmed_leg                BOOLEAN:=FALSE;
13147     l_out_object2_num           NUMBER:=0;
13148     l_out_object2_char          VARCHAR2(30):=NULL;
13149 
13150     j                           NUMBER := 0;
13151     i                           NUMBER := 0;
13152     l_num_child_deliveries      NUMBER := 0;
13153     l_return_status             VARCHAR2(1);
13154     l_validate_excl_result      VARCHAR2(1) := 'S';
13155     l_carrier                   NUMBER := NULL;
13156     l_vehicle_type              NUMBER := NULL;
13157     l_mode                      VARCHAR2(30) := NULL;
13158     l_service_level             VARCHAR2(30) := NULL;
13159     l_carrier_service_inout_rec WSH_CARRIERS_GRP.Carrier_Service_InOut_Rec_Type;
13160     l_facility_id               NUMBER := 0;
13161     l_failed_constraint         line_constraint_rec_type;
13162     l_failed_constraints        line_constraint_tab_type;
13163     l_validate_carrier_result   VARCHAR2(1) := 'S';
13164     l_validate_vehicle_result   VARCHAR2(1) := 'S';
13165     l_validate_mode_result      VARCHAR2(1) := 'S';
13166     l_validate_orgfac_result    VARCHAR2(1) := 'S';
13167     l_validate_cusfac_result    VARCHAR2(1) := 'S';
13168     l_validate_supfac_result    VARCHAR2(1) := 'S';
13169     l_validate_itmfac_result    VARCHAR2(1) := 'S';
13170     l_validate_faccar_result    VARCHAR2(1) := 'S';
13171     l_validate_facveh_result    VARCHAR2(1) := 'S';
13172     l_validate_facmod_result    VARCHAR2(1) := 'S';
13173     l_validate_itmcar_result    VARCHAR2(1) := 'S';
13174     l_validate_itmveh_result    VARCHAR2(1) := 'S';
13175     l_validate_itmmod_result    VARCHAR2(1) := 'S';
13176     l_validate_result           VARCHAR2(1) := 'S';
13177 
13178     l_comp_class_tab            WSH_UTIL_CORE.Column_Tab_Type;
13179     l_detail_rec                detail_ccinfo_rec_type;
13180     l_dlvy_rec                  delivery_ccinfo_rec_type;
13181     l_dleg_dlvy_rec             delivery_ccinfo_rec_type;
13182     l_stop_rec                  stop_ccinfo_rec_type;
13183     l_detail_tab                detail_ccinfo_tab_type;
13184     l_trip_detail_tab           detail_ccinfo_tab_type;
13185     l_trip_dlvy_tab             delivery_ccinfo_tab_type;
13186     l_trip_stops_tab            stop_ccinfo_tab_type;
13187     l_target_tripstops          target_tripstop_cc_rec_type;
13188     l_entity_tab                entity_tab_type;
13189     l_line_groups               WSH_FTE_COMP_CONSTRAINT_PKG.line_group_tab_type;
13190     l_failed_lines              WSH_FTE_COMP_CONSTRAINT_PKG.failed_line_tab_type;
13191     l_group_info                WSH_FTE_COMP_CONSTRAINT_PKG.cc_group_tab_type;
13192 
13193     l_delivery_leg_rec          dleg_ccinfo_rec_type;
13194     l_physical_location_id      NUMBER := NULL;
13195 
13196     l_debug_on                  CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
13197     l_module_name               CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'validate_constraint_dleg';
13198 
13199 BEGIN
13200     x_validate_result := 'S';
13201     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
13202 
13203     g_itm_mustuse_cache.DELETE;
13204     g_itmloc_mustuse_cache.DELETE;
13205     g_itm_exclusive_cache.DELETE;
13206     g_fac_exclusive_cache.DELETE;
13207 
13208     IF FND_API.to_Boolean( p_init_msg_list ) THEN
13209          FND_MSG_PUB.initialize;
13210     END IF;
13211 
13212     IF l_debug_on THEN
13213        wsh_debug_sv.push(l_module_name);
13214        WSH_DEBUG_SV.logmsg(l_module_name,'p_init_msg_list : '||p_init_msg_list);
13215     END IF;
13216 
13217     refresh_cache(l_return_status);
13218 
13219     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13220          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13221             raise FND_API.G_EXC_UNEXPECTED_ERROR;
13222          END IF;
13223     END IF;
13224 
13225     /*
13226     Lane search for a delivery leg	DLS	FAC_MOD, FAC_CAR, ITM_CAR ITM_MOD
13227     : Input one dleg, table of lanes
13228     Output valid lanes
13229 
13230     Searching trip for a delivery leg	DST	CUS_CUS
13231     :Input one dleg, table of trips             ITM_FAC ITM_MOD ITM_CAR ITM_VEH
13232      Output : valid trips
13233 
13234     Creating  a delivery leg	        CDL	COM_FAC CUS_FAC FAC_MOD FAC_CAR ITM_FAC
13235                                                 ITM_MOD ITM_CAR SUP_FAC
13236 
13237     Editing                             UDL     COM_FAC CUS_FAC ITM_FAC FAC_MOD FAC_CAR
13238                                                 ITM_MOD ITM_CAR SUP_FAC
13239     */
13240 
13241      IF NOT p_exception_list.EXISTS(G_FACILITY_MODE_NUM) THEN
13242         l_comp_class_tab(G_FACILITY_MODE_NUM) := G_FACILITY_MODE;
13243      END IF;
13244      IF NOT p_exception_list.EXISTS(G_FACILITY_CARRIER_NUM) THEN
13245         l_comp_class_tab(G_FACILITY_CARRIER_NUM) := G_FACILITY_CARRIER;
13246      END IF;
13247      IF NOT p_exception_list.EXISTS(G_FACILITY_VEHICLE_NUM) THEN
13248         l_comp_class_tab(G_FACILITY_VEHICLE_NUM) := G_FACILITY_VEHICLE;
13249      END IF;
13250      IF NOT p_exception_list.EXISTS(G_ITEM_MODE_NUM) THEN
13251         l_comp_class_tab(G_ITEM_MODE_NUM) := G_ITEM_MODE;
13252      END IF;
13253      IF NOT p_exception_list.EXISTS(G_ITEM_CARRIER_NUM) THEN
13254         l_comp_class_tab(G_ITEM_CARRIER_NUM) := G_ITEM_CARRIER;
13255      END IF;
13256      IF NOT p_exception_list.EXISTS(G_ITEM_VEHICLE_NUM) THEN
13257         l_comp_class_tab(G_ITEM_VEHICLE_NUM) := G_ITEM_VEHICLE;
13258      END IF;
13259      IF NOT p_exception_list.EXISTS(G_SHIPORG_FACILITY_NUM) THEN
13260         l_comp_class_tab(G_SHIPORG_FACILITY_NUM) := G_SHIPORG_FACILITY;
13261      END IF;
13262      IF NOT p_exception_list.EXISTS(G_CUSTOMER_FACILITY_NUM) THEN
13263         l_comp_class_tab(G_CUSTOMER_FACILITY_NUM) := G_CUSTOMER_FACILITY;
13264      END IF;
13265      IF NOT p_exception_list.EXISTS(G_SUPPLIER_FACILITY_NUM) THEN
13266         l_comp_class_tab(G_SUPPLIER_FACILITY_NUM) := G_SUPPLIER_FACILITY;
13267      END IF;
13268      IF NOT p_exception_list.EXISTS(G_ITEM_FACILITY_NUM) THEN
13269         l_comp_class_tab(G_ITEM_FACILITY_NUM) := G_ITEM_FACILITY;
13270      END IF;
13271      IF NOT p_exception_list.EXISTS(G_CUSTOMER_CUSTOMER_NUM) THEN
13272         l_comp_class_tab(G_CUSTOMER_CUSTOMER_NUM) := G_CUSTOMER_CUSTOMER;
13273      END IF;
13274 
13275     -- AG
13276 
13277 
13278 
13279     OPEN get_num_child_dlegs(p_delivery_leg_rec.delivery_leg_id);
13280         FETCH get_num_child_dlegs into l_num_child_deliveries;
13281     CLOSE get_num_child_dlegs;
13282 
13283     /*IF l_debug_on THEN
13284         wsh_debug_sv.logmsg('p_delivery_leg_rec.delivery_leg_id : '||p_delivery_leg_rec.delivery_leg_id);
13285    END IF;*/
13286      IF l_debug_on THEN
13287             WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_leg_rec.delivery_leg_id : '||p_delivery_leg_rec.delivery_leg_id);
13288           END IF;
13289     IF l_num_child_deliveries > 0 THEN
13290         OPEN c_get_details_consol(p_delivery_leg_rec.delivery_id);
13291         LOOP
13292            FETCH c_get_details_consol INTO l_detail_rec;
13293            EXIT WHEN c_get_details_consol%NOTFOUND;
13294 
13295           /* IF l_debug_on THEN
13296                 wsh_debug_sv.logmsg('l_detail_rec.COUNT: '||l_detail_rec.COUNT);
13297            END IF;*/
13298 
13299         -- AGDUMMY
13300         -- Convert ultimate_dropoff if dummy to physical
13301         -- TODO
13302 
13303         --#DUM_LOC(S)
13304         --Check if ultimate drop off location is a dummy location
13305         WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
13306              p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
13307              x_internal_org_location_id   => l_physical_location_id,
13308              x_return_status              => l_return_status);
13309 
13310         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13311            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13312               raise FND_API.G_EXC_UNEXPECTED_ERROR;
13313            END IF;
13314         END IF;
13315 
13316         IF (l_physical_location_id IS NOT NULL) THEN
13317           --
13318           IF l_debug_on THEN
13319             WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
13320           END IF;
13321           --
13322           l_detail_rec.ship_to_location_id := l_physical_location_id;
13323           l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
13324         END IF;
13325         --#DUM_LOC(E)
13326 
13327            l_detail_tab(l_detail_tab.COUNT+1) := l_detail_rec;
13328         END LOOP;
13329         CLOSE c_get_details_consol;
13330     ELSE
13331         OPEN c_get_details(p_delivery_leg_rec.delivery_id);
13332         LOOP
13333            FETCH c_get_details INTO l_detail_rec;
13334            EXIT WHEN c_get_details%NOTFOUND;
13335 
13336 
13337         -- AGDUMMY
13338         -- Convert ultimate_dropoff if dummy to physical
13339         -- TODO
13340 
13341         --#DUM_LOC(S)
13342         --Check if ultimate drop off location is a dummy location
13343         WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
13344              p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
13345              x_internal_org_location_id   => l_physical_location_id,
13346              x_return_status              => l_return_status);
13347 
13348         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13349            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13350               raise FND_API.G_EXC_UNEXPECTED_ERROR;
13351            END IF;
13352         END IF;
13353 
13354         IF (l_physical_location_id IS NOT NULL) THEN
13355           --
13356           IF l_debug_on THEN
13357             WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
13358           END IF;
13359           --
13360           l_detail_rec.ship_to_location_id := l_physical_location_id;
13361           l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
13362         END IF;
13363         --#DUM_LOC(E)
13364 
13365            l_detail_tab(l_detail_tab.COUNT+1) := l_detail_rec;
13366         END LOOP;
13367         CLOSE c_get_details;
13368     END IF;
13369 
13370     OPEN c_get_dlvy(p_delivery_leg_rec.delivery_id);
13371     FETCH c_get_dlvy INTO l_dleg_dlvy_rec;
13372     CLOSE c_get_dlvy;
13373 
13374     -- AGDUMMY
13375     -- Convert ultimate_dropoff if dummy to physical
13376     -- TODO
13377 
13378     --#DUM_LOC(S)
13379     --Check if ultimate drop off location is a dummy location
13380     WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
13381          p_internal_cust_location_id  => l_dleg_dlvy_rec.ultimate_dropoff_location_id,
13382          x_internal_org_location_id   => l_physical_location_id,
13383          x_return_status              => l_return_status);
13384 
13385     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13386        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13387           raise FND_API.G_EXC_UNEXPECTED_ERROR;
13388        END IF;
13389     END IF;
13390 
13391     IF (l_physical_location_id IS NOT NULL) THEN
13392       --
13393       IF l_debug_on THEN
13394         WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_dleg_dlvy_rec.ultimate_dropoff_location_id||' is a dummy location');
13395       END IF;
13396       --
13397       l_dleg_dlvy_rec.ultimate_dropoff_location_id := l_physical_location_id;
13398       l_dleg_dlvy_rec.physical_dropoff_location_id := l_physical_location_id;
13399     END IF;
13400     --#DUM_LOC(E)
13401 
13402     l_orig_dlvy_puloc := l_dleg_dlvy_rec.initial_pickup_location_id;
13403     l_orig_dlvy_udloc := l_dleg_dlvy_rec.ultimate_dropoff_location_id;
13404 
13405     --#DUM_LOC(S)
13406     --Check if input dleg's drop off location is a dummy location
13407     l_delivery_leg_rec := p_delivery_leg_rec;
13408 
13409     WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
13410          p_internal_cust_location_id  => p_delivery_leg_rec.dropoffstop_location_id,
13411          x_internal_org_location_id   => l_physical_location_id,
13412          x_return_status              => l_return_status);
13413 
13414     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13415        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13416           raise FND_API.G_EXC_UNEXPECTED_ERROR;
13417        END IF;
13418     END IF;
13419 
13420     IF (l_physical_location_id IS NOT NULL) THEN
13421       --
13422       IF l_debug_on THEN
13423         WSH_DEBUG_SV.logmsg(l_module_name,'Location '||p_delivery_leg_rec.dropoffstop_location_id||' is a dummy location');
13424       END IF;
13425       --
13426       l_delivery_leg_rec.dropoffstop_location_id := l_physical_location_id;
13427       --p_delivery_leg_rec.physical_dropoff_location_id := l_physical_location_id;
13428     END IF;
13429     --#DUM_LOC(E)
13430 
13431     -- For DLL
13432     -- API for DST, CDL, UDL internally calls this
13433 
13434     -- For DLL
13435 
13436     IF p_action_code = G_DLEG_LANE_SEARCH THEN
13437 
13438       --LOOP -- over target lanes
13439       i := p_target_lane.FIRST;
13440       IF i IS NOT NULL THEN
13441         LOOP
13442 
13443            l_validate_faccar_result := 'S';
13444            l_validate_facmod_result := 'S';
13445            l_validate_itmcar_result := 'S';
13446            l_validate_itmmod_result := 'S';
13447            l_validate_result := 'S';
13448 
13449            IF l_dleg_dlvy_rec.shipping_control = 'SUPPLIER' THEN
13450               GOTO lane_nextpass;
13451            END IF;
13452 
13453            IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) THEN
13454 
13455              check_inclusive_object2(
13456                  p_comp_class_code          =>      G_FACILITY_CARRIER,
13457                  p_entity_type              =>      G_DELIVERY_LEG,
13458                  p_entity_id                =>      l_delivery_leg_rec.delivery_leg_id,
13459                  p_object1_type             =>      'FAC',
13460                  p_object1_val_num          =>      l_delivery_leg_rec.pickupstop_location_id,
13461                  p_object2_type             =>      'CAR',
13462                  p_object2_val_num          =>      p_target_lane(i).carrier_id,
13463                  x_out_object2_num          =>      l_out_object2_num,
13464                  x_out_object2_char         =>      l_out_object2_char,
13465                  x_validate_result          =>      l_validate_carrier_result,
13466                  x_failed_constraint        =>      l_failed_constraints,
13467                  x_return_status            =>      l_return_status);
13468 
13469              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13470                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13471                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
13472                 END IF;
13473              END IF;
13474 
13475              IF l_validate_carrier_result = 'F' THEN
13476                 x_validate_result := 'F';
13477                 l_validate_result := 'F';
13478                 GOTO lane_nextpass;
13479              END IF;
13480 
13481              check_inclusive_object2(
13482                  p_comp_class_code          =>      G_FACILITY_CARRIER,
13483                  p_entity_type              =>      G_DELIVERY_LEG,
13484                  p_entity_id                =>      l_delivery_leg_rec.delivery_leg_id,
13485                  p_object1_type             =>      'FAC',
13486                  p_object1_val_num          =>      l_delivery_leg_rec.dropoffstop_location_id,
13487                  p_object2_type             =>      'CAR',
13488                  p_object2_val_num          =>      p_target_lane(i).carrier_id,
13489                  x_out_object2_num          =>      l_out_object2_num,
13490                  x_out_object2_char         =>      l_out_object2_char,
13491                  x_validate_result          =>      l_validate_carrier_result,
13492                  x_failed_constraint        =>      l_failed_constraints,
13493                  x_return_status            =>      l_return_status);
13494 
13495              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13496                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13497                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
13498                 END IF;
13499              END IF;
13500 
13501              IF l_validate_carrier_result = 'F' THEN
13502                  x_validate_result := 'F';
13503                  l_validate_result := 'F';
13504                  GOTO lane_nextpass;
13505              END IF;
13506 
13507            END IF;
13508 
13509            IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) THEN
13510 
13511              check_inclusive_object2(
13512                  p_comp_class_code          =>      G_FACILITY_MODE,
13513                  p_entity_type              =>      G_DELIVERY_LEG,
13514                  p_entity_id                =>      l_delivery_leg_rec.delivery_leg_id,
13515                  p_object1_type             =>      'FAC',
13516                  p_object1_val_num          =>      l_delivery_leg_rec.pickupstop_location_id,
13517                  p_object2_type             =>      'MOD',
13518                  p_object2_val_char         =>      p_target_lane(i).mode_of_transportation_code,
13519                  x_out_object2_num          =>      l_out_object2_num,
13520                  x_out_object2_char         =>      l_out_object2_char,
13521                  x_validate_result          =>      l_validate_mode_result,
13522                  x_failed_constraint        =>      l_failed_constraints,
13523                  x_return_status            =>      l_return_status);
13524 
13525              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13526                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13527                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
13528                 END IF;
13529              END IF;
13530 
13531              IF l_validate_mode_result = 'F' THEN
13532                 x_validate_result := 'F';
13533                 l_validate_result := 'F';
13534                 GOTO lane_nextpass;
13535              END IF;
13536 
13537              check_inclusive_object2(
13538                  p_comp_class_code          =>      G_FACILITY_MODE,
13539                  p_entity_type              =>      G_DELIVERY_LEG,
13540                  p_entity_id                =>      l_delivery_leg_rec.delivery_leg_id,
13541                  p_object1_type             =>      'FAC',
13542                  p_object1_val_num          =>      l_delivery_leg_rec.dropoffstop_location_id,
13543                  p_object2_type             =>      'MOD',
13544                  p_object2_val_char         =>      p_target_lane(i).mode_of_transportation_code,
13545                  x_out_object2_num          =>      l_out_object2_num,
13546                  x_out_object2_char         =>      l_out_object2_char,
13547                  x_validate_result          =>      l_validate_mode_result,
13548                  x_failed_constraint        =>      l_failed_constraints,
13549                  x_return_status            =>      l_return_status);
13550 
13551              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13552                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13553                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
13554                 END IF;
13555              END IF;
13556 
13557              IF l_validate_mode_result = 'F' THEN
13558                 x_validate_result := 'F';
13559                 l_validate_result := 'F';
13560                 GOTO lane_nextpass;
13561              END IF;
13562 
13563 
13564            END IF;
13565 
13566            -- Proceed to check Exclusive constraints
13567            -- only if success
13568 
13569            -- FAC - CAR/MOD for dleg's locations against lane's carrier, mode
13570 
13571            IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) AND
13572               p_target_lane(i).carrier_id IS NOT NULL THEN
13573 
13574              validate_constraint(
13575                  p_comp_class_code          =>      G_FACILITY_CARRIER,
13576                  p_object1_type             =>      'FAC',
13577                  p_object1_val_num          =>      l_delivery_leg_rec.pickupstop_location_id,
13578                  p_object2_type             =>      'CAR',
13579                  p_object2_val_num          =>      p_target_lane(i).carrier_id,
13580                  x_validate_result          =>      l_validate_faccar_result,
13581                  x_failed_constraint        =>      l_failed_constraint,
13582                  x_return_status            =>      l_return_status);
13583 
13584              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13585                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13586                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
13587                 END IF;
13588              END IF;
13589 
13590              IF l_validate_faccar_result <> 'S' THEN
13591                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
13592                   l_failed_constraint.entity_type :=  G_DELIVERY_LEG;
13593                   l_failed_constraint.entity_line_id :=  l_delivery_leg_rec.delivery_leg_id;
13594                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
13595 
13596                   IF l_validate_faccar_result = 'E' THEN
13597                      x_validate_result := 'F';
13598                      l_validate_result := 'F';
13599                   END IF;
13600              END IF;
13601              -- Success can override Failure
13602 
13603              validate_constraint(
13604                  p_comp_class_code          =>      G_FACILITY_CARRIER,
13605                  p_object1_type             =>      'FAC',
13606                  p_object1_val_num          =>      l_delivery_leg_rec.dropoffstop_location_id,
13607                  p_object2_type             =>      'CAR',
13608                  p_object2_val_num          =>      p_target_lane(i).carrier_id,
13609                  x_validate_result          =>      l_validate_faccar_result,
13610                  x_failed_constraint        =>      l_failed_constraint,
13611                  x_return_status            =>      l_return_status);
13612 
13613              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13614                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13615                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
13616                 END IF;
13617              END IF;
13618 
13619              IF l_validate_faccar_result <> 'S' THEN
13620                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
13621                   l_failed_constraint.entity_type :=  G_DELIVERY_LEG;
13622                   l_failed_constraint.entity_line_id :=  l_delivery_leg_rec.delivery_leg_id;
13623                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
13624 
13625                   IF l_validate_faccar_result = 'E' THEN
13626                      x_validate_result := 'F';
13627                      l_validate_result := 'F';
13628                   END IF;
13629              END IF;
13630 
13631            END IF;
13632 
13633            IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) AND
13634               p_target_lane(i).mode_of_transportation_code IS NOT NULL THEN
13635 
13636              validate_constraint(
13637                  p_comp_class_code          =>      G_FACILITY_MODE,
13638                  p_object1_type             =>      'FAC',
13639                  p_object1_val_num          =>      l_delivery_leg_rec.pickupstop_location_id,
13640                  p_object2_type             =>      'MOD',
13641                  p_object2_val_char         =>      p_target_lane(i).mode_of_transportation_code,
13642                  x_validate_result          =>      l_validate_facmod_result,
13643                  x_failed_constraint        =>      l_failed_constraint,
13644                  x_return_status            =>      l_return_status);
13645 
13646              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13647                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13648                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
13649                 END IF;
13650              END IF;
13651 
13652              IF l_validate_facmod_result <> 'S' THEN
13653                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
13654                   l_failed_constraint.entity_type :=  G_DELIVERY_LEG;
13655                   l_failed_constraint.entity_line_id :=  l_delivery_leg_rec.delivery_leg_id;
13656                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
13657 
13658                   IF l_validate_facmod_result = 'E' THEN
13659                    x_validate_result := 'F';
13660                    l_validate_result := 'F';
13661                   END IF;
13662 
13663              END IF;
13664 
13665              validate_constraint(
13666                  p_comp_class_code          =>      G_FACILITY_MODE,
13667                  p_object1_type             =>      'FAC',
13668                  p_object1_val_num          =>      l_delivery_leg_rec.dropoffstop_location_id,
13669                  p_object2_type             =>      'MOD',
13670                  p_object2_val_char         =>      p_target_lane(i).mode_of_transportation_code,
13671                  x_validate_result          =>      l_validate_facmod_result,
13672                  x_failed_constraint        =>      l_failed_constraint,
13673                  x_return_status            =>      l_return_status);
13674 
13675              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13676                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13677                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
13678                 END IF;
13679              END IF;
13680 
13681              IF l_validate_facmod_result <> 'S' THEN
13682                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
13683                   l_failed_constraint.entity_type :=  G_DELIVERY_LEG;
13684                   l_failed_constraint.entity_line_id :=  l_delivery_leg_rec.delivery_leg_id;
13685                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
13686 
13687                   IF l_validate_facmod_result = 'E' THEN
13688                    x_validate_result := 'F';
13689                    l_validate_result := 'F';
13690                   END IF;
13691              END IF;
13692 
13693            END IF;
13694            --LOOP -- Over dleg's children details
13695            j := l_detail_tab.FIRST;
13696            IF j IS NOT NULL THEN
13697              LOOP
13698 
13699                 -- ITM - CAR/MOD for detail's item against lane's carrier, mode
13700              -- Inclusive constraints
13701              -- Not to check item levl inclusive constraints
13702              -- when entity = delivery/dleg
13703 
13704               IF l_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) THEN
13705 
13706                   check_inclusive_object2(
13707                    p_comp_class_code          =>      G_ITEM_CARRIER,
13708                    p_entity_type              =>      G_DEL_DETAIL,
13709                    p_entity_id                =>      l_detail_tab(j).delivery_detail_id,
13710                    p_object1_type             =>      'ITM',
13711                    p_object1_parent_id        =>      l_detail_tab(j).organization_id,
13712                    p_object1_val_num          =>      l_detail_tab(j).inventory_item_id,
13713                    p_object2_type             =>      'CAR',
13714                    p_object2_val_num          =>      p_target_lane(i).carrier_id,
13715                    x_out_object2_num          =>      l_out_object2_num,
13716                    x_out_object2_char         =>      l_out_object2_char,
13717                    x_validate_result          =>      l_validate_carrier_result,
13718                    x_failed_constraint        =>      l_failed_constraints,
13719                    x_return_status            =>      l_return_status);
13720 
13721                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13722                      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13723                         raise FND_API.G_EXC_UNEXPECTED_ERROR;
13724                      END IF;
13725                   END IF;
13726 
13727                   IF l_validate_carrier_result = 'F' THEN
13728                      x_validate_result := 'F';
13729                      l_validate_result := 'F';
13730                      EXIT;
13731                   END IF;
13732 
13733               END IF;
13734 
13735               IF l_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) THEN
13736 
13737                   check_inclusive_object2(
13738                    p_comp_class_code          =>      G_ITEM_MODE,
13739                    p_entity_type              =>      G_DEL_DETAIL,
13740                    p_entity_id                =>      l_detail_tab(j).delivery_detail_id,
13741                    p_object1_type             =>      'ITM',
13742                    p_object1_parent_id        =>      l_detail_tab(j).organization_id,
13743                    p_object1_val_num          =>      l_detail_tab(j).inventory_item_id,
13744                    p_object2_type             =>      'MOD',
13745                    p_object2_val_char         =>      p_target_lane(i).mode_of_transportation_code,
13746                    x_out_object2_num          =>      l_out_object2_num,
13747                    x_out_object2_char         =>      l_out_object2_char,
13748                    x_validate_result          =>      l_validate_mode_result,
13749                    x_failed_constraint        =>      l_failed_constraints,
13750                    x_return_status            =>      l_return_status);
13751 
13752                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13753                     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13754                        raise FND_API.G_EXC_UNEXPECTED_ERROR;
13755                     END IF;
13756                   END IF;
13757 
13758                   IF l_validate_mode_result = 'F' THEN
13759                      x_validate_result := 'F';
13760                      l_validate_result := 'F';
13761                      EXIT;
13762                   END IF;
13763 
13764               END IF;
13765 
13766               IF l_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) THEN
13767 
13768                  validate_constraint(   --  checks only negative constraints
13769                    p_comp_class_code          =>      G_ITEM_MODE,
13770                    p_object1_type             =>      'ITM',
13771                    p_object1_parent_id        =>      l_detail_tab(j).organization_id,
13772                    p_object2_type             =>      'MOD',
13773                    p_object1_val_num          =>      l_detail_tab(j).inventory_item_id,
13774                    p_object2_val_char         =>      p_target_lane(i).mode_of_transportation_code,
13775                    x_validate_result          =>      l_validate_itmmod_result,
13776                    x_failed_constraint        =>      l_failed_constraint,
13777                    x_return_status            =>      l_return_status);
13778 
13779                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13780                     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13781                        raise FND_API.G_EXC_UNEXPECTED_ERROR;
13782                     END IF;
13783                  END IF;
13784 
13785                  -- For exclusive constraints error with one detail in the group is error
13786                  -- But, for inclusive constraints success with one detail in the group is success
13787 
13788                  IF l_validate_itmmod_result <> 'S' THEN
13789                     l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
13790                     l_failed_constraint.entity_type :=  G_DEL_DETAIL;
13791                     l_failed_constraint.entity_line_id :=  l_detail_tab(j).delivery_detail_id;
13792                     l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
13793 
13794                     IF l_validate_itmmod_result = 'E' THEN
13795                      x_validate_result := 'F';
13796                      l_validate_result := 'F';
13797                     END IF;
13798 
13799                  END IF;
13800 
13801               END IF;
13802 
13803               IF l_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) THEN
13804 
13805                  validate_constraint(   --  checks only negative constraints
13806                    p_comp_class_code          =>      G_ITEM_CARRIER,
13807                    p_object1_type             =>      'ITM',
13808                    p_object1_parent_id        =>      l_detail_tab(j).organization_id,
13809                    p_object2_type             =>      'CAR',
13810                    p_object1_val_num          =>      l_detail_tab(j).inventory_item_id,
13811                    p_object2_val_num          =>      p_target_lane(i).carrier_id,
13812                    x_validate_result          =>      l_validate_itmcar_result,
13813                    x_failed_constraint        =>      l_failed_constraint,
13814                    x_return_status            =>      l_return_status);
13815 
13816                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13817                     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13818                        raise FND_API.G_EXC_UNEXPECTED_ERROR;
13819                     END IF;
13820                  END IF;
13821 
13822                  -- For exclusive constraints error with one detail in the group is error
13823                  -- But, for inclusive constraints success with one detail in the group is success
13824 
13825                  IF l_validate_itmcar_result <> 'S' THEN
13826                     l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
13827                     l_failed_constraint.entity_type :=  G_DEL_DETAIL;
13828                     l_failed_constraint.entity_line_id :=  l_detail_tab(j).delivery_detail_id;
13829                     l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
13830 
13831                     IF l_validate_itmcar_result = 'E' THEN
13832                      x_validate_result := 'F';
13833                      l_validate_result := 'F';
13834                     END IF;
13835 
13836                  END IF;
13837 
13838               END IF;
13839 
13840               <<det_nextpass>>
13841 
13842               EXIT WHEN j = l_detail_tab.LAST;
13843               j := l_detail_tab.NEXT(j);
13844 
13845              END LOOP;
13846            END IF;
13847 
13848            <<lane_nextpass>>
13849 
13850            IF l_validate_result = 'S' THEN
13851            -- populate x_succ_lanes
13852               x_succ_lanes(x_succ_lanes.COUNT+1) := p_target_lane(i).lane_id;
13853 
13854            END IF;
13855 
13856            EXIT WHEN i = p_target_lane.LAST;
13857            i := p_target_lane.NEXT(i);
13858 
13859         END LOOP;
13860       END IF;
13861 
13862     END IF;    --  DLS
13863 
13864     -- For DST
13865 
13866     IF p_action_code = G_DLEG_TRIP_SEARCH THEN
13867 
13868       --LOOP -- over target trips
13869       i := p_target_trip.FIRST;
13870       IF i IS NOT NULL THEN
13871         LOOP
13872 
13873           l_validate_faccar_result := 'S';
13874           l_validate_facmod_result := 'S';
13875           l_validate_itmcar_result := 'S';
13876           l_validate_itmmod_result := 'S';
13877           l_validate_result := 'S';
13878           l_validate_excl_result := 'S';
13879           l_carrier := NULL;
13880           l_mode := NULL;
13881           l_service_level := NULL;
13882 
13883           IF l_dleg_dlvy_rec.shipping_control = 'SUPPLIER' THEN
13884              GOTO next_trip;
13885           END IF;
13886 
13887            -- FAC - CAR/MOD for dleg's locations against trip's carrier, mode
13888 
13889            -- Inclusive constraints
13890            -- Proceed to check Exclusive constraints
13891            -- only if success
13892            -- ITM - CAR/MOD
13893 
13894 
13895           OPEN c_get_trip_details(p_target_trip(i).trip_id);
13896           LOOP
13897               FETCH c_get_trip_details INTO l_detail_rec;
13898               EXIT WHEN c_get_trip_details%NOTFOUND;
13899 
13900 
13901     -- AGDUMMY
13902     -- Convert ship_to if dummy to physical
13903     -- TODO
13904 
13905     --#DUM_LOC(S)
13906     --Check if ultimate drop off location is a dummy location
13907     WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
13908          p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
13909          x_internal_org_location_id   => l_physical_location_id,
13910          x_return_status              => l_return_status);
13911 
13912     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13913        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13914           raise FND_API.G_EXC_UNEXPECTED_ERROR;
13915        END IF;
13916     END IF;
13917 
13918     IF (l_physical_location_id IS NOT NULL) THEN
13919       --
13920       IF l_debug_on THEN
13921         WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
13922       END IF;
13923       --
13924       l_detail_rec.ship_to_location_id := l_physical_location_id;
13925       l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
13926     END IF;
13927     --#DUM_LOC(E)
13928 
13929               l_trip_detail_tab(l_trip_detail_tab.COUNT+1) := l_detail_rec;
13930           END LOOP;
13931           CLOSE c_get_trip_details;
13932 
13933           OPEN c_get_trip_dlvy(p_target_trip(i).trip_id);
13934           LOOP
13935               FETCH c_get_trip_dlvy INTO l_dlvy_rec;
13936               EXIT WHEN c_get_trip_dlvy%NOTFOUND;
13937 
13938 
13939     -- AGDUMMY
13940     -- Convert ultimate_dropoff if dummy to physical
13941     -- TODO
13942 
13943     --#DUM_LOC(S)
13944     --Check if ultimate drop off location is a dummy location
13945     WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
13946          p_internal_cust_location_id  => l_dlvy_rec.ultimate_dropoff_location_id,
13947          x_internal_org_location_id   => l_physical_location_id,
13948          x_return_status              => l_return_status);
13949 
13950     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13951        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13952           raise FND_API.G_EXC_UNEXPECTED_ERROR;
13953        END IF;
13954     END IF;
13955 
13956     IF (l_physical_location_id IS NOT NULL) THEN
13957       --
13958       IF l_debug_on THEN
13959         WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_dlvy_rec.ultimate_dropoff_location_id||' is a dummy location');
13960       END IF;
13961       --
13962       l_dlvy_rec.ultimate_dropoff_location_id := l_physical_location_id;
13963       l_dlvy_rec.physical_dropoff_location_id := l_physical_location_id;
13964     END IF;
13965     --#DUM_LOC(E)
13966 
13967               l_trip_dlvy_tab(l_trip_dlvy_tab.COUNT+1) := l_dlvy_rec;
13968           END LOOP;
13969           CLOSE c_get_trip_dlvy;
13970 
13971           OPEN c_get_trip_stops(p_target_trip(i).trip_id);
13972           LOOP
13973               FETCH c_get_trip_stops INTO l_stop_rec;
13974               EXIT WHEN c_get_trip_stops%NOTFOUND;
13975 
13976               l_trip_stops_tab(l_trip_stops_tab.COUNT+1) := l_stop_rec;
13977           END LOOP;
13978           CLOSE c_get_trip_stops;
13979 
13980           -- As this only filters open trip results by constraint violations,
13981           -- the moment a violation is found for an input trip
13982           -- no more violations are checked for that trip
13983 
13984           -- Need to check Inclusive facility as parameter2 constraints as well
13985           -- Call validate_positive_constraint
13986 
13987           l_entity_tab(l_dleg_dlvy_rec.delivery_id).entity_id := l_dleg_dlvy_rec.delivery_id;
13988           l_entity_tab(l_dleg_dlvy_rec.delivery_id).organization_id := l_dleg_dlvy_rec.organization_id;
13989           l_entity_tab(l_dleg_dlvy_rec.delivery_id).initial_pickup_location_id := l_dleg_dlvy_rec.initial_pickup_location_id;
13990           l_entity_tab(l_dleg_dlvy_rec.delivery_id).ultimate_dropoff_location_id := l_dleg_dlvy_rec.ultimate_dropoff_location_id;
13991          l_entity_tab(l_dleg_dlvy_rec.delivery_id).initial_pickup_date := l_dleg_dlvy_rec.initial_pickup_date;
13992          l_entity_tab(l_dleg_dlvy_rec.delivery_id).ultimate_dropoff_date := l_dleg_dlvy_rec.ultimate_dropoff_date;
13993           l_entity_tab(l_dleg_dlvy_rec.delivery_id).physical_dropoff_location_id := l_dleg_dlvy_rec.physical_dropoff_location_id;
13994           l_entity_tab(l_dleg_dlvy_rec.delivery_id).intmed_ship_to_location_id := l_dleg_dlvy_rec.intmed_ship_to_location_id;
13995           l_entity_tab(l_dleg_dlvy_rec.delivery_id).ship_method_code := l_dleg_dlvy_rec.ship_method_code;
13996           l_entity_tab(l_dleg_dlvy_rec.delivery_id).carrier_id := l_dleg_dlvy_rec.carrier_id;
13997           l_entity_tab(l_dleg_dlvy_rec.delivery_id).mode_of_transport := l_dleg_dlvy_rec.mode_of_transport;
13998           l_entity_tab(l_dleg_dlvy_rec.delivery_id).customer_id := l_dleg_dlvy_rec.customer_id;
13999           l_entity_tab(l_dleg_dlvy_rec.delivery_id).party_id := l_dleg_dlvy_rec.party_id;
14000           l_entity_tab(l_dleg_dlvy_rec.delivery_id).shipment_direction := l_dleg_dlvy_rec.shipment_direction;
14001           l_entity_tab(l_dleg_dlvy_rec.delivery_id).shipping_control := l_dleg_dlvy_rec.shipping_control;
14002           --
14003           IF l_debug_on THEN
14004              WSH_DEBUG_SV.logmsg(l_module_name,'Created l_entity_tab with index : '||l_dleg_dlvy_rec.delivery_id);
14005           END IF;
14006           --
14007 
14008           l_target_tripstops.pickup_stop_id        := l_delivery_leg_rec.pick_up_stop_id;
14009           l_target_tripstops.dropoff_stop_id       := l_delivery_leg_rec.drop_off_stop_id;
14010           l_target_tripstops.pickup_location_id    := l_delivery_leg_rec.pickupstop_location_id;
14011           l_target_tripstops.dropoff_location_id   := l_delivery_leg_rec.dropoffstop_location_id;
14012           -- AG 10+
14013           l_target_tripstops.pickup_stop_pa_date    := l_delivery_leg_rec.pickup_stop_pa_date;
14014           l_target_tripstops.dropoff_stop_pa_date   := l_delivery_leg_rec.dropoff_stop_pa_date;
14015 
14016           create_valid_entity_group(
14017                   p_entity_rec            => l_entity_tab(l_dleg_dlvy_rec.delivery_id),
14018                   p_group_tab             => l_group_info,
14019                   x_return_status         => l_return_status);
14020           --
14021           IF l_debug_on THEN
14022               WSH_DEBUG_SV.logmsg(l_module_name,'Called create_valid_entity_group return status : '||l_return_status);
14023           END IF;
14024           --
14025 
14026           IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14027               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14028                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
14029               END IF;
14030           END IF;
14031 
14032           validate_positive_constraint(
14033                     p_action_code         => G_ASSIGN_DLVY_TRIP,
14034                     p_comp_class_tab      => l_comp_class_tab,
14035                     p_entity_tab          => l_entity_tab,
14036                     p_group_tab           => l_group_info,
14037                     p_detail_tab          => l_detail_tab,
14038                     p_target_trip         => p_target_trip(i),
14039                     p_target_tripstops    => l_trip_stops_tab,
14040                     p_target_stops_info   => l_target_tripstops,
14041                     x_line_groups         => l_line_groups,
14042                     x_failed_lines        => l_failed_lines,
14043                     x_failed_constraints  => l_failed_constraints,
14044                     x_return_status       => l_return_status);
14045           --
14046           IF l_debug_on THEN
14047              WSH_DEBUG_SV.logmsg(l_module_name,'Called validate_positive_constraint return status : '||l_return_status);
14048              WSH_DEBUG_SV.logmsg(l_module_name,'l_failed_lines count : '||l_failed_lines.COUNT);
14049           END IF;
14050           --
14051 
14052           IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14053               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14054                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
14055               END IF;
14056           ELSIF l_failed_lines.COUNT > 0 THEN
14057               x_validate_result := 'F';
14058               l_validate_result := 'F';
14059           END IF;
14060 
14061           IF l_validate_result = 'S' THEN
14062 
14063            check_dlvy_against_trip(
14064                      p_entity_type         => 'DLEG',
14065                      p_entity_id           => l_delivery_leg_rec.delivery_leg_id,
14066                      p_delivery_rec        => l_dleg_dlvy_rec,
14067                      p_detail_tab          => l_detail_tab,
14068                      p_comp_class_tab      => l_comp_class_tab,
14069                      p_target_stops_info   => l_target_tripstops,
14070                      p_target_trip         => p_target_trip(i),
14071                      p_target_tripstops    => l_trip_stops_tab,
14072                      p_target_dlvy         => l_trip_dlvy_tab,
14073                      p_target_dlvy_lines   => l_trip_detail_tab,
14074                      x_failed_constraints  => l_failed_constraints,
14075                      x_validate_result     => l_validate_excl_result,
14076                      x_return_status       => l_return_status);
14077 
14078            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14079              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14080                 raise FND_API.G_EXC_UNEXPECTED_ERROR;
14081              END IF;
14082            END IF;
14083 
14084            IF l_validate_excl_result = 'F' THEN
14085                    x_validate_result := 'F';
14086                    l_validate_result := 'F';
14087            END IF;
14088 
14089           END IF; -- l_validate_result = 'S'
14090 
14091           <<next_trip>>
14092 
14093           IF l_validate_result = 'S' THEN
14094            -- populate x_succ_trips
14095               x_succ_trips(x_succ_trips.COUNT+1) := p_target_trip(i).trip_id;
14096 
14097           END IF;
14098 
14099           EXIT WHEN i = p_target_trip.LAST;
14100           i := p_target_trip.NEXT(i);
14101 
14102         END LOOP;
14103       END IF;
14104 
14105     END IF;   -- DST
14106 
14107     -- For DCE
14108 
14109     IF p_action_code IN (G_UPDATE_DLEG,G_DLEG_CRT) AND
14110        l_dleg_dlvy_rec.shipping_control <> 'SUPPLIER' THEN
14111 
14112     -- FAC - CAR/MOD for dleg against dleg's locations
14113 
14114        IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) AND
14115           l_delivery_leg_rec.carrier_id IS NOT NULL THEN
14116 
14117             validate_constraint(
14118              p_comp_class_code          =>      G_FACILITY_CARRIER,
14119              p_object1_type             =>      'FAC',
14120              p_object1_val_num          =>      l_delivery_leg_rec.pickupstop_location_id,
14121              p_object2_type             =>      'CAR',
14122              p_object2_val_num          =>      l_delivery_leg_rec.carrier_id,
14123              x_validate_result          =>      l_validate_faccar_result,
14124              x_failed_constraint        =>      l_failed_constraint,
14125              x_return_status            =>      l_return_status);
14126 
14127             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14128                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14129                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
14130                END IF;
14131             END IF;
14132 
14133             IF l_validate_faccar_result <> 'S' THEN
14134               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
14135               l_failed_constraint.entity_type :=  G_DELIVERY_LEG;
14136               l_failed_constraint.entity_line_id :=  l_delivery_leg_rec.delivery_leg_id;
14137               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
14138 
14139               IF l_validate_faccar_result = 'E' THEN
14140                  x_validate_result := 'F';
14141                  l_validate_result := 'F';
14142               END IF;
14143             END IF;
14144          -- Success can override Failure
14145 
14146             validate_constraint(
14147              p_comp_class_code          =>      G_FACILITY_CARRIER,
14148              p_object1_type             =>      'FAC',
14149              p_object1_val_num          =>      l_delivery_leg_rec.dropoffstop_location_id,
14150              p_object2_type             =>      'CAR',
14151              p_object2_val_num          =>      l_delivery_leg_rec.carrier_id,
14152              x_validate_result          =>      l_validate_faccar_result,
14153              x_failed_constraint        =>      l_failed_constraint,
14154              x_return_status            =>      l_return_status);
14155 
14156             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14157                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14158                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
14159                END IF;
14160             END IF;
14161 
14162             IF l_validate_faccar_result <> 'S' THEN
14163               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
14164               l_failed_constraint.entity_type :=  G_DELIVERY_LEG;
14165               l_failed_constraint.entity_line_id :=  l_delivery_leg_rec.delivery_leg_id;
14166               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
14167 
14168               IF l_validate_faccar_result = 'E' THEN
14169                  x_validate_result := 'F';
14170                 l_validate_result := 'F';
14171               END IF;
14172             END IF;
14173 
14174        END IF;
14175 
14176        IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) AND
14177           l_delivery_leg_rec.MODE_OF_TRANSPORT IS NOT NULL THEN
14178 
14179             validate_constraint(
14180              p_comp_class_code          =>      G_FACILITY_MODE,
14181              p_object1_type             =>      'FAC',
14182              p_object1_val_num          =>      l_delivery_leg_rec.pickupstop_location_id,
14183              p_object2_type             =>      'MOD',
14184              p_object2_val_char         =>      l_delivery_leg_rec.mode_of_transport,
14185              x_validate_result          =>      l_validate_facmod_result,
14186              x_failed_constraint        =>      l_failed_constraint,
14187              x_return_status            =>      l_return_status);
14188 
14189             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14190                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14191                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
14192                END IF;
14193             END IF;
14194 
14195             IF l_validate_facmod_result <> 'S' THEN
14196               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
14197               l_failed_constraint.entity_type :=  G_DELIVERY_LEG;
14198               l_failed_constraint.entity_line_id :=  l_delivery_leg_rec.delivery_leg_id;
14199               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
14200 
14201               IF l_validate_facmod_result = 'E' THEN
14202                x_validate_result := 'F';
14203                l_validate_result := 'F';
14204               END IF;
14205 
14206             END IF;
14207 
14208             validate_constraint(
14209              p_comp_class_code          =>      G_FACILITY_MODE,
14210              p_object1_type             =>      'FAC',
14211              p_object1_val_num          =>      l_delivery_leg_rec.dropoffstop_location_id,
14212              p_object2_type             =>      'MOD',
14213              p_object2_val_char         =>      l_delivery_leg_rec.mode_of_transport,
14214              x_validate_result          =>      l_validate_facmod_result,
14215              x_failed_constraint        =>      l_failed_constraint,
14216              x_return_status            =>      l_return_status);
14217 
14218             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14219                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14220                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
14221                END IF;
14222             END IF;
14223 
14224             IF l_validate_facmod_result <> 'S' THEN
14225               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
14226               l_failed_constraint.entity_type :=  G_DELIVERY_LEG;
14227               l_failed_constraint.entity_line_id :=  l_delivery_leg_rec.delivery_leg_id;
14228               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
14229 
14230               IF l_validate_facmod_result = 'E' THEN
14231                x_validate_result := 'F';
14232                l_validate_result := 'F';
14233               END IF;
14234             END IF;
14235 
14236        END IF;
14237 
14238        check_dleg_discretionary(
14239                  p_entity_type          => G_DELIVERY_LEG,
14240                  p_entity_id            => l_delivery_leg_rec.delivery_leg_id,
14241                  p_delivery_rec         => l_dleg_dlvy_rec,
14242                  p_comp_class_tab       => l_comp_class_tab,
14243                  p_dleg_pick_up_loc_id  => l_delivery_leg_rec.pickupstop_location_id,
14244                  p_dleg_drop_off_loc_id => l_delivery_leg_rec.dropoffstop_location_id,
14245                  p_detail_tab           => l_detail_tab,
14246                  p_carrier              => l_delivery_leg_rec.carrier_id,
14247                  p_mode                 => l_delivery_leg_rec.mode_of_transport,
14248                  x_failed_constraints   => l_failed_constraints,
14249                  x_validate_result      => l_validate_result,
14250                  x_return_status        => l_return_status);
14251 
14252            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14253               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14254                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
14255               END IF;
14256            END IF;
14257 
14258            IF l_validate_result = 'F' THEN
14259               x_validate_result := l_validate_result;
14260            END IF;
14261 
14262 
14263     END IF;
14264 
14265      --  Loop over l_failed_constraints to add to the mesage stack
14266 
14267     stack_messages (
14268              p_failed_constraints       => l_failed_constraints,
14269              x_msg_count                => x_msg_count,
14270              x_msg_data                 => x_msg_data,
14271              x_return_status            => l_return_status);
14272 
14273     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14274          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14275             raise FND_API.G_EXC_UNEXPECTED_ERROR;
14276          END IF;
14277     END IF;
14278 
14279     IF x_validate_result = 'F' THEN
14280         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
14281     ELSIF l_failed_constraints.COUNT > 0 THEN
14282         x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
14283     END IF;
14284 
14285     --
14286     IF l_debug_on THEN
14287       WSH_DEBUG_SV.pop(l_module_name);
14288     END IF;
14289     --
14290 
14291 EXCEPTION
14292     WHEN g_get_carrmode_failed THEN
14293       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
14294       --
14295       IF l_debug_on THEN
14296         WSH_DEBUG_SV.pop(l_module_name,' get carrier-mode failed ');
14297       END IF;
14298       --
14299     WHEN g_get_vehicletype_failed THEN
14300       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
14301       --
14302       IF l_debug_on THEN
14303         WSH_DEBUG_SV.pop(l_module_name,' get vehicletype failed ');
14304       END IF;
14305       --
14306     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
14307       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
14308       --
14309       IF l_debug_on THEN
14310         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
14311         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
14312       END IF;
14313       --
14314     WHEN others THEN
14315       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.validate_constraint_dleg');
14316       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
14317       --
14318       IF l_debug_on THEN
14319         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
14320         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
14321       END IF;
14322       --
14323 END validate_constraint_dleg;
14324 
14325 
14326 --***************************************************************************--
14327 --========================================================================
14328 -- PROCEDURE : validate_constraint_dlvb    Called by constraint Wrapper API
14329 --                                         and the Group API.
14330 --
14331 -- PARAMETERS: p_init_msg_list             FND_API.G_TRUE to reset list
14332 --             p_action_code               Predefined action code
14333 --             p_exception_list            Compatibility classes to skip if any
14334 --                                         indexed by class code numbers
14335 --             p_in_ids                    Table of delivery ids to process
14336 --                                         Either of the next two should be passed
14337 --             p_del_detail_info           Table of delivery detail records to process
14338 --                                         Only one of p_in_ids and p_del_detail_info should be passed
14339 --             p_target_delivery           Applicable for Assign delivery detail to delivery only
14340 --                                         Record of target delivery information
14341 --             p_target_container          Applicable for Assign delivery detail to container only
14342 --                                         Record of target container information
14343 --                                         If not passed, the API will query
14344 --             p_dlvy_assigned_lines       Table of delivery details already in target
14345 --                                         delivery or target container
14346 --                                         If not passed, the API will query
14347 --             x_validate_result           Constraint Validation result : S / F
14348 --             x_failed_lines              Table of input delivery lines that failed
14349 --                                         constraint check
14350 --             x_line_groups               Includes Successful and warning lines
14351 --                                         after constraint check
14352 --                                         Contains information of which input delivery should
14353 --                                         be grouped in which output group for trip creation
14354 --             x_group_info                Output groups for input deliveries
14355 --             x_msg_count                 Number of messages in the list
14356 --             x_msg_data                  Text of messages
14357 --             x_return_status             Return status
14358 -- COMMENT   : This procedure is used to perform for following actions
14359 --             A. Autocreate Delivery (ACD)
14360 --             B. Assign detail to Delivery (ADD)
14361 --             C. Packing (PKG)
14362 --             When specifying a target delivery, group all delivery lines that are being planned
14363 --             to the target delivery
14364 --========================================================================
14365 
14366 PROCEDURE validate_constraint_dlvb(
14367              p_init_msg_list            IN      VARCHAR2 DEFAULT fnd_api.g_false,
14368              p_action_code              IN      VARCHAR2 DEFAULT NULL,
14369              p_exception_list           IN      WSH_UTIL_CORE.Column_Tab_Type,
14370              p_in_ids                   IN      WSH_UTIL_CORE.id_tab_type,
14371              p_del_detail_info          IN      detail_ccinfo_tab_type,
14372              p_target_delivery          IN      delivery_ccinfo_rec_type,
14373              p_target_container         IN      detail_ccinfo_rec_type,
14374              p_dlvy_assigned_lines      IN      detail_ccinfo_tab_type,
14375              x_validate_result          OUT NOCOPY    VARCHAR2,
14376              x_failed_lines             OUT NOCOPY    WSH_FTE_COMP_CONSTRAINT_PKG.failed_line_tab_type,
14377              x_line_groups              OUT NOCOPY    WSH_FTE_COMP_CONSTRAINT_PKG.line_group_tab_type,
14378              x_group_info               OUT NOCOPY    WSH_FTE_COMP_CONSTRAINT_PKG.cc_group_tab_type,
14379              x_msg_count                OUT NOCOPY    NUMBER,
14380              x_msg_data                 OUT NOCOPY    VARCHAR2,
14381              x_return_status            OUT NOCOPY    VARCHAR2)
14382 IS
14383 
14384     CURSOR c_get_assigned_lines_cont(c_container_id IN NUMBER) IS
14385     SELECT wdd.DELIVERY_DETAIL_ID,wda.DELIVERY_ID,'Y',wdd.CUSTOMER_ID,
14386            wdd.INVENTORY_ITEM_ID,wdd.SHIP_FROM_LOCATION_ID,wdd.ORGANIZATION_ID,
14387            wdd.SHIP_TO_LOCATION_ID,wdd.INTMED_SHIP_TO_LOCATION_ID,wdd.RELEASED_STATUS,
14388            wdd.CONTAINER_FLAG,wdd.DATE_REQUESTED,wdd.DATE_SCHEDULED,wdd.SHIP_METHOD_CODE,
14389            wdd.CARRIER_ID,wdd.party_id,nvl(wdd.line_direction,'O')
14390            ,nvl(wdd.shipping_control,'BUYER'),NULL
14391 
14392     FROM   WSH_DELIVERY_DETAILS wdd,
14393            wsh_delivery_assignments_v wda
14394     WHERE  wda.DELIVERY_DETAIL_ID = wdd.DELIVERY_DETAIL_ID
14395     AND    nvl(wdd.shipping_control,'BUYER') <> 'SUPPLIER'
14396     AND    wda.PARENT_DELIVERY_DETAIL_ID = c_container_id;
14397 
14398     CURSOR c_get_line_details(c_detail_id IN NUMBER) IS
14399     SELECT wdd.DELIVERY_DETAIL_ID,null,'Y',wdd.CUSTOMER_ID,
14400            wdd.INVENTORY_ITEM_ID,wdd.SHIP_FROM_LOCATION_ID,wdd.ORGANIZATION_ID,
14401            wdd.SHIP_TO_LOCATION_ID,wdd.INTMED_SHIP_TO_LOCATION_ID,wdd.RELEASED_STATUS,
14402            wdd.CONTAINER_FLAG,wdd.DATE_REQUESTED,wdd.DATE_SCHEDULED,wdd.SHIP_METHOD_CODE,
14403            wdd.CARRIER_ID,wdd.party_id,nvl(wdd.line_direction,'O')
14404            ,nvl(wdd.shipping_control,'BUYER'),NULL
14405            --DUM_LOC
14406     FROM   WSH_DELIVERY_DETAILS wdd
14407     WHERE  wdd.DELIVERY_DETAIL_ID = c_detail_id;
14408 
14409     CURSOR c_getdelivery(c_detail_id IN NUMBER) IS
14410     SELECT wda.DELIVERY_ID
14411     FROM   wsh_delivery_assignments_v wda
14412     WHERE  wda.delivery_detail_id = c_detail_id;
14413 
14414     i                                    NUMBER:=0;
14415     j                                    NUMBER:=0;
14416     k                                    NUMBER:=0;
14417     l                                    NUMBER:=0;
14418     m                                    NUMBER:=0;
14419     n                                    NUMBER:=0;
14420     o                                    NUMBER:=0;
14421     p                                    NUMBER:=0;
14422     q                                    NUMBER:=0;
14423     s                                    NUMBER:=0;
14424     t                                    NUMBER:=0;
14425     l_assigned_line_cnt                  NUMBER:=0;
14426     l_group_count                        NUMBER:=0;
14427     l_failed_lc                          NUMBER:=0;
14428     l_input_target_id                    NUMBER:=0;
14429     l_group_id                           NUMBER:=0;
14430     l_linegroup_indx                     NUMBER:=0;
14431     l_item_org_id                        NUMBER:=0;
14432     l_item_id                            NUMBER:=0;
14433     l_customer_id                        NUMBER:=0;
14434     l_carrier                            NUMBER := NULL;
14435     l_found                              BOOLEAN := FALSE;
14436     l_failed_line_added                  BOOLEAN := FALSE;
14437     l_mode                               VARCHAR2(30) := NULL;
14438     l_service_level                      VARCHAR2(30) := NULL;
14439     l_carrier_service_inout_rec          WSH_CARRIERS_GRP.Carrier_Service_InOut_Rec_Type;
14440     l_intmed_location_id                 NUMBER:=0;
14441     l_hash_string                        VARCHAR2(200);
14442     l_hash_value                         NUMBER:=0;
14443     l_return_status                      VARCHAR2(1);
14444     l_validate_result                    VARCHAR2(1);
14445     l_validate_item_result               VARCHAR2(1);
14446     l_validate_customer_result           VARCHAR2(1);
14447     l_validate_carrier_result            VARCHAR2(1);
14448     l_validate_mode_result               VARCHAR2(1);
14449     l_validate_intmed_result             VARCHAR2(1);
14450     l_input_comp_class                   BOOLEAN := FALSE;
14451     l_input_assign_lines                 BOOLEAN := FALSE;
14452     l_item_check_cus                     BOOLEAN := FALSE;
14453     l_comp_class_tab                     WSH_UTIL_CORE.Column_Tab_Type;
14454     l_detail_rec                         detail_ccinfo_rec_type;
14455     l_line_group_rec                     WSH_FTE_COMP_CONSTRAINT_PKG.line_group_rec_type;
14456     l_linegroup_rec                      WSH_FTE_COMP_CONSTRAINT_PKG.cc_group_rec_type;
14457     l_failed_constraint                  line_constraint_rec_type;
14458     l_failed_constraints                 line_constraint_tab_type;
14459     l_entity_tab                         entity_tab_type;
14460     l_target_rec                         entity_rec_type;
14461     l_validate_itmin_result              VARCHAR2(1);
14462     l_inp_items_cnt                      NUMBER := 0;
14463     l_validate_itmfacin_result           VARCHAR2(1) := 'S';
14464     l_items_tab                          item_tab_type;
14465     l_locations_list                     WSH_UTIL_CORE.id_tab_type;
14466     l_supp_control_tab                   WSH_UTIL_CORE.id_tab_type;
14467     l_target_delivery                    delivery_ccinfo_rec_type;
14468     l_target_container                   detail_ccinfo_rec_type;
14469     l_del_detail_info                    detail_ccinfo_tab_type;
14470     l_dlvy_assigned_lines                detail_ccinfo_tab_type;
14471     l_dummy_assigned_lines               detail_ccinfo_tab_type;
14472     l_target_tripstops                   target_tripstop_cc_rec_type;
14473 
14474     --#DUM_LOC(S)
14475     l_physical_location_id		 NUMBER;
14476     --#DUM_LOC(E)
14477 
14478     g_invalid_action_code                EXCEPTION;
14479     g_invalid_input                      EXCEPTION;
14480     l_debug_on                           CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
14481     l_module_name                        CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'validate_constraint_dlvb';
14482 
14483 BEGIN
14484 
14485     x_validate_result := 'S'; --  Constraint Validation result : S / F
14486     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
14487 
14488     g_itm_mustuse_cache.DELETE;
14489     g_itmloc_mustuse_cache.DELETE;
14490     g_itm_exclusive_cache.DELETE;
14491     g_fac_exclusive_cache.DELETE;
14492 
14493     IF FND_API.to_Boolean( p_init_msg_list ) THEN
14494          FND_MSG_PUB.initialize;
14495     END IF;
14496 
14497     IF l_debug_on THEN
14498         wsh_debug_sv.push(l_module_name);
14499         WSH_DEBUG_SV.logmsg(l_module_name,'p_init_msg_list : '||p_init_msg_list);
14500     END IF;
14501 
14502     -- Action codes : ACD, ADD, PKG
14503     -- Assumes p_comp_class_tab and p_exception_list are indexed by
14504     -- compatibility class codes
14505 
14506     IF p_action_code NOT IN (G_AUTOCRT_DLVY,G_PACK_DLVB,G_ASSIGN_DLVB_DLVY) OR
14507        p_action_code IS NULL THEN
14508        RAISE g_invalid_action_code;
14509     END IF;
14510 
14511     refresh_cache(l_return_status);
14512 
14513     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14514          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14515             raise FND_API.G_EXC_UNEXPECTED_ERROR;
14516          END IF;
14517     END IF;
14518 
14519     IF NOT p_exception_list.EXISTS(G_CUSTOMER_CUSTOMER_NUM) THEN
14520      l_comp_class_tab(G_CUSTOMER_CUSTOMER_NUM) := G_CUSTOMER_CUSTOMER;
14521     END IF;
14522      -- 12/17 : For now packing will not conside item - car/mod for grouping
14523     IF p_action_code IN (G_AUTOCRT_DLVY,G_ASSIGN_DLVB_DLVY) THEN
14524        IF NOT p_exception_list.EXISTS(G_ITEM_MODE_NUM) THEN
14525         l_comp_class_tab(G_ITEM_MODE_NUM) := G_ITEM_MODE;
14526        END IF;
14527        IF NOT p_exception_list.EXISTS(G_ITEM_CARRIER_NUM) THEN
14528         l_comp_class_tab(G_ITEM_CARRIER_NUM) := G_ITEM_CARRIER;
14529        END IF;
14530        IF NOT p_exception_list.EXISTS(G_ITEM_VEHICLE_NUM) THEN
14531         l_comp_class_tab(G_ITEM_VEHICLE_NUM) := G_ITEM_VEHICLE;
14532        END IF;
14533        IF NOT p_exception_list.EXISTS(G_ITEM_FACILITY_NUM) THEN
14534         l_comp_class_tab(G_ITEM_FACILITY_NUM) := G_ITEM_FACILITY;
14535        END IF;
14536      -- Assign delivery details to delivery
14537      -- does not update any grouping attributes for the delivery AS 10/18
14538      -- What about packing a detail to a container ?
14539 
14540        IF NOT p_exception_list.EXISTS(G_FACILITY_MODE_NUM) THEN
14541         l_comp_class_tab(G_FACILITY_MODE_NUM) := G_FACILITY_MODE;
14542        END IF;
14543        IF NOT p_exception_list.EXISTS(G_FACILITY_CARRIER_NUM) THEN
14544         l_comp_class_tab(G_FACILITY_CARRIER_NUM) := G_FACILITY_CARRIER;
14545        END IF;
14546        IF NOT p_exception_list.EXISTS(G_FACILITY_VEHICLE_NUM) THEN
14547         l_comp_class_tab(G_FACILITY_VEHICLE_NUM) := G_FACILITY_VEHICLE;
14548        END IF;
14549        IF NOT p_exception_list.EXISTS(G_SHIPORG_FACILITY_NUM) THEN
14550         l_comp_class_tab(G_SHIPORG_FACILITY_NUM) := G_SHIPORG_FACILITY;
14551        END IF;
14552        IF NOT p_exception_list.EXISTS(G_CUSTOMER_FACILITY_NUM) THEN
14553         l_comp_class_tab(G_CUSTOMER_FACILITY_NUM) := G_CUSTOMER_FACILITY;
14554        END IF;
14555        IF NOT p_exception_list.EXISTS(G_SUPPLIER_FACILITY_NUM) THEN
14556         l_comp_class_tab(G_SUPPLIER_FACILITY_NUM) := G_SUPPLIER_FACILITY;
14557        END IF;
14558     END IF;
14559     --
14560     IF l_debug_on THEN
14561         WSH_DEBUG_SV.logmsg(l_module_name,'After populating l_comp_class_tab count : '||l_comp_class_tab.COUNT);
14562     END IF;
14563     --
14564     -- Populate l_del_detail_info
14565 
14566     IF p_del_detail_info.COUNT = 0 THEN
14567       --
14568       IF l_debug_on THEN
14569         WSH_DEBUG_SV.logmsg(l_module_name,'Passed p_in_ids count : '||p_in_ids.COUNT);
14570       END IF;
14571       --
14572 
14573       i := p_in_ids.FIRST;
14574 
14575       IF i IS NOT NULL THEN
14576         LOOP
14577            OPEN c_get_line_details(p_in_ids(i));
14578            FETCH c_get_line_details into l_del_detail_info(i);
14579            CLOSE c_get_line_details;
14580 
14581            --#DUM_LOC(S)
14582 	   WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
14583 	      p_internal_cust_location_id  => l_del_detail_info(i).ship_to_location_id,
14584               x_internal_org_location_id   => l_physical_location_id,
14585               x_return_status              => l_return_status);
14586 
14587  	   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14588 	     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14589 	        raise FND_API.G_EXC_UNEXPECTED_ERROR;
14590 	     END IF;
14591     	   END IF;
14592 
14593   	   IF (l_physical_location_id IS NOT NULL) THEN
14594   	      --
14595 	      IF l_debug_on THEN
14596 		  WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_del_detail_info(i).ship_to_location_id||' is a dummy location');
14597 	      END IF;
14598 	      --
14599 	      l_del_detail_info(i).ship_to_location_id:= l_physical_location_id;
14600               -- AGDUMMY TODO
14601               l_del_detail_info(i).physical_ship_to_location_id:= l_physical_location_id;
14602 	   END IF;
14603            --#DUM_LOC(E)
14604 
14605 	   OPEN  c_getdelivery(p_in_ids(i));
14606            FETCH c_getdelivery into l_del_detail_info(i).DELIVERY_ID;
14607            CLOSE c_getdelivery;
14608 
14609            EXIT WHEN i = p_in_ids.LAST;
14610            i := p_in_ids.NEXT(i);
14611 
14612         END LOOP;
14613       END IF;
14614 
14615     ELSE
14616       --
14617       IF l_debug_on THEN
14618         WSH_DEBUG_SV.logmsg(l_module_name,'Passed p_del_detail_info count : '||p_del_detail_info.COUNT);
14619       END IF;
14620       --
14621 
14622       i := p_del_detail_info.FIRST;
14623       IF i IS NOT NULL THEN
14624         LOOP
14625 
14626           l_del_detail_info(i).DELIVERY_DETAIL_ID          := p_del_detail_info(i).DELIVERY_DETAIL_ID;
14627           l_del_detail_info(i).DELIVERY_ID                 := p_del_detail_info(i).DELIVERY_ID;
14628           l_del_detail_info(i).exists_in_database          := p_del_detail_info(i).exists_in_database;
14629           l_del_detail_info(i).CUSTOMER_ID                 := p_del_detail_info(i).CUSTOMER_ID;
14630           l_del_detail_info(i).INVENTORY_ITEM_ID           := p_del_detail_info(i).INVENTORY_ITEM_ID;
14631           l_del_detail_info(i).RELEASED_STATUS             := p_del_detail_info(i).RELEASED_STATUS;
14632           l_del_detail_info(i).DATE_REQUESTED              := p_del_detail_info(i).DATE_REQUESTED;
14633           l_del_detail_info(i).SHIP_FROM_LOCATION_ID       := p_del_detail_info(i).SHIP_FROM_LOCATION_ID;
14634           l_del_detail_info(i).SHIP_TO_LOCATION_ID         := p_del_detail_info(i).SHIP_TO_LOCATION_ID;
14635           l_del_detail_info(i).DATE_SCHEDULED              := p_del_detail_info(i).DATE_SCHEDULED;
14636           l_del_detail_info(i).CONTAINER_FLAG              := p_del_detail_info(i).CONTAINER_FLAG;
14637           l_del_detail_info(i).INTMED_SHIP_TO_LOCATION_ID  := p_del_detail_info(i).INTMED_SHIP_TO_LOCATION_ID;
14638           l_del_detail_info(i).SHIP_METHOD_CODE            := p_del_detail_info(i).SHIP_METHOD_CODE;
14639           l_del_detail_info(i).CARRIER_ID                  := p_del_detail_info(i).CARRIER_ID;
14640           l_del_detail_info(i).PARTY_ID                    := p_del_detail_info(i).PARTY_ID;
14641           l_del_detail_info(i).LINE_DIRECTION              := p_del_detail_info(i).LINE_DIRECTION;
14642           l_del_detail_info(i).SHIPPING_CONTROL            := nvl(p_del_detail_info(i).SHIPPING_CONTROL,'BUYER');
14643           l_del_detail_info(i).ORGANIZATION_ID             := p_del_detail_info(i).ORGANIZATION_ID;
14644 
14645 	  --#DUM_LOC(S)
14646 	  WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
14647 	      p_internal_cust_location_id  => l_del_detail_info(i).ship_to_location_id,
14648               x_internal_org_location_id   => l_physical_location_id,
14649               x_return_status              => l_return_status);
14650 
14651  	  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14652 	    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14653 	       raise FND_API.G_EXC_UNEXPECTED_ERROR;
14654 	    END IF;
14655     	  END IF;
14656 
14657   	  IF (l_physical_location_id IS NOT NULL) THEN
14658   	      --
14659 	      IF l_debug_on THEN
14660 		  WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_del_detail_info(i).ship_to_location_id||' is a dummy location');
14661 	      END IF;
14662 	      --
14663 	      l_del_detail_info(i).ship_to_location_id:= l_physical_location_id;
14664               -- AGDUMMY TODO
14665               l_del_detail_info(i).physical_ship_to_location_id:= l_physical_location_id;
14666 	  END IF;
14667 	  --#DUM_LOC(E)
14668 
14669           EXIT WHEN i = p_del_detail_info.LAST;
14670           i := p_del_detail_info.NEXT(i);
14671 
14672         END LOOP;
14673       END IF;
14674 
14675     END IF;
14676 
14677     IF p_target_delivery.delivery_id IS NOT NULL THEN
14678 
14679        OPEN c_get_dlvy(p_target_delivery.delivery_id);
14680        FETCH c_get_dlvy into l_target_delivery;
14681        CLOSE c_get_dlvy;
14682 
14683        --#DUM_LOC(S)
14684        WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
14685           p_internal_cust_location_id  => l_target_delivery.ultimate_dropoff_location_id,
14686           x_internal_org_location_id   => l_physical_location_id,
14687           x_return_status              => l_return_status);
14688 
14689        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14690 	    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14691 	       raise FND_API.G_EXC_UNEXPECTED_ERROR;
14692 	    END IF;
14693        END IF;
14694 
14695        IF (l_physical_location_id IS NOT NULL) THEN
14696   	  --
14697 	  IF l_debug_on THEN
14698 	     WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_target_delivery.ultimate_dropoff_location_id||' is a dummy location');
14699 	  END IF;
14700 	  --
14701 	 l_target_delivery.ultimate_dropoff_location_id := l_physical_location_id;
14702          -- AGDUMMY TODO
14703          l_target_delivery.physical_dropoff_location_id := l_physical_location_id;
14704        END IF;
14705        --#DUM_LOC(E)
14706 
14707      ELSIF p_target_container.delivery_detail_id IS NOT NULL THEN
14708 
14709 	--#DUM_LOC(Q) Do we change for containers.
14710         --Verify.
14711         -- Yes
14712 
14713        OPEN c_get_line_details(p_target_container.delivery_detail_id);
14714        FETCH c_get_line_details into l_target_container;
14715        CLOSE c_get_line_details;
14716 
14717 	--#DUM_LOC(S)
14718        WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
14719 	  p_internal_cust_location_id  => l_target_container.ship_to_location_id,
14720           x_internal_org_location_id   => l_physical_location_id,
14721           x_return_status              => l_return_status);
14722 
14723        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14724 	  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14725 	    raise FND_API.G_EXC_UNEXPECTED_ERROR;
14726 	  END IF;
14727        END IF;
14728 
14729        IF (l_physical_location_id IS NOT NULL) THEN
14730   	    --
14731 	    IF l_debug_on THEN
14732 	       WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_target_container.ship_to_location_id||' is a dummy location');
14733 	    END IF;
14734 	    --
14735 	    l_target_container.ship_to_location_id:= l_physical_location_id;
14736             -- AGDUMMY TODO
14737             l_target_container.physical_ship_to_location_id := l_physical_location_id;
14738        END IF;
14739        --#DUM_LOC(E)
14740     END IF;
14741 
14742 
14743     IF p_dlvy_assigned_lines.COUNT = 0 THEN
14744      IF ( l_target_delivery.delivery_id IS NOT NULL
14745        AND l_target_delivery.exists_in_database = 'Y') THEN
14746 	      --
14747           --  has been passed
14748           IF l_target_delivery.delivery_type = 'STANDARD' THEN
14749               OPEN c_get_details(l_target_delivery.delivery_id); -- or container_id
14750               LOOP
14751                    FETCH c_get_details INTO l_detail_rec;
14752                    EXIT WHEN c_get_details%NOTFOUND;
14753 
14754                --#DUM_LOC(S)
14755                    WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
14756                        p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
14757                        x_internal_org_location_id   => l_physical_location_id,
14758                        x_return_status              => l_return_status);
14759 
14760                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14761                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14762                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
14763                  END IF;
14764                    END IF;
14765 
14766                IF (l_physical_location_id IS NOT NULL) THEN
14767              --
14768                  IF l_debug_on THEN
14769                 WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
14770                  END IF;
14771                  --
14772                  l_detail_rec.ship_to_location_id:= l_physical_location_id;
14773                      -- AGDUMMY TODO
14774                      l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
14775                END IF;
14776                    --#DUM_LOC(E)
14777                    l_assigned_line_cnt := l_assigned_line_cnt + 1;
14778                    l_dlvy_assigned_lines(l_assigned_line_cnt) := l_detail_rec;
14779               END LOOP;
14780               CLOSE c_get_details;
14781           ELSE
14782               OPEN c_get_details_consol(l_target_delivery.delivery_id); -- or container_id
14783               LOOP
14784                    FETCH c_get_details_consol INTO l_detail_rec;
14785                    EXIT WHEN c_get_details%NOTFOUND;
14786 
14787                --#DUM_LOC(S)
14788                    WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
14789                        p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
14790                        x_internal_org_location_id   => l_physical_location_id,
14791                        x_return_status              => l_return_status);
14792 
14793                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14794                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14795                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
14796                  END IF;
14797                    END IF;
14798 
14799                IF (l_physical_location_id IS NOT NULL) THEN
14800              --
14801                  IF l_debug_on THEN
14802                 WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
14803                  END IF;
14804                  --
14805                  l_detail_rec.ship_to_location_id:= l_physical_location_id;
14806                      -- AGDUMMY TODO
14807                      l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
14808                END IF;
14809                    --#DUM_LOC(E)
14810                    l_assigned_line_cnt := l_assigned_line_cnt + 1;
14811                    l_dlvy_assigned_lines(l_assigned_line_cnt) := l_detail_rec;
14812               END LOOP;
14813               CLOSE c_get_details_consol;
14814           END IF;
14815           ---
14816      ELSIF ( l_target_container.delivery_detail_id IS NOT NULL
14817           AND l_target_container.exists_in_database = 'Y') THEN  --  Check to see if target delivery/contain.
14818 
14819           OPEN c_get_assigned_lines_cont(l_target_container.delivery_detail_id); -- or container_id
14820           LOOP
14821                FETCH c_get_assigned_lines_cont INTO l_detail_rec;
14822                EXIT WHEN c_get_assigned_lines_cont%NOTFOUND;
14823 
14824 	       --#DUM_LOC(S)
14825 	       WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
14826 	           p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
14827                    x_internal_org_location_id   => l_physical_location_id,
14828                    x_return_status              => l_return_status);
14829 
14830  	       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14831 	         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14832 	           raise FND_API.G_EXC_UNEXPECTED_ERROR;
14833 	         END IF;
14834     	       END IF;
14835 
14836   	       IF (l_physical_location_id IS NOT NULL) THEN
14837   		 --
14838 	         IF l_debug_on THEN
14839 		    WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
14840 	         END IF;
14841 	         --
14842 	        l_detail_rec.ship_to_location_id:= l_physical_location_id;
14843                 -- AGDUMMY TODO
14844                 l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
14845 	       END IF;
14846                --#DUM_LOC(E)
14847 
14848 	       l_assigned_line_cnt := l_assigned_line_cnt + 1;
14849                l_dlvy_assigned_lines(l_assigned_line_cnt) := l_detail_rec;
14850           END LOOP;
14851           CLOSE c_get_assigned_lines_cont;
14852      END IF;
14853      --
14854      IF l_debug_on THEN
14855         WSH_DEBUG_SV.logmsg(l_module_name,'Created l_dlvy_assigned_lines count : '||l_dlvy_assigned_lines.COUNT);
14856      END IF;
14857      --
14858     ELSE
14859       --
14860       IF l_debug_on THEN
14861         WSH_DEBUG_SV.logmsg(l_module_name,'Passed p_dlvy_assigned_lines count : '||p_dlvy_assigned_lines.COUNT);
14862       END IF;
14863       --
14864 
14865       i := p_dlvy_assigned_lines.FIRST;
14866       IF i IS NOT NULL THEN
14867         LOOP
14868 
14869                l_dlvy_assigned_lines(i).delivery_detail_id := p_dlvy_assigned_lines(i).delivery_detail_id;
14870                l_dlvy_assigned_lines(i).delivery_id := p_dlvy_assigned_lines(i).delivery_id;
14871                l_dlvy_assigned_lines(i).exists_in_database := p_dlvy_assigned_lines(i).exists_in_database;
14872                l_dlvy_assigned_lines(i).CUSTOMER_ID := p_dlvy_assigned_lines(i).CUSTOMER_ID;
14873                l_dlvy_assigned_lines(i).INVENTORY_ITEM_ID := p_dlvy_assigned_lines(i).INVENTORY_ITEM_ID;
14874                l_dlvy_assigned_lines(i).SHIP_FROM_LOCATION_ID := p_dlvy_assigned_lines(i).SHIP_FROM_LOCATION_ID;
14875                l_dlvy_assigned_lines(i).ORGANIZATION_ID := p_dlvy_assigned_lines(i).ORGANIZATION_ID;
14876                l_dlvy_assigned_lines(i).SHIP_TO_LOCATION_ID := p_dlvy_assigned_lines(i).SHIP_TO_LOCATION_ID;
14877                l_dlvy_assigned_lines(i).INTMED_SHIP_TO_LOCATION_ID := p_dlvy_assigned_lines(i).INTMED_SHIP_TO_LOCATION_ID;
14878                l_dlvy_assigned_lines(i).RELEASED_STATUS := p_dlvy_assigned_lines(i).RELEASED_STATUS;
14879                l_dlvy_assigned_lines(i).CONTAINER_FLAG := p_dlvy_assigned_lines(i).CONTAINER_FLAG;
14880                l_dlvy_assigned_lines(i).DATE_REQUESTED  := p_dlvy_assigned_lines(i).DATE_REQUESTED;
14881                l_dlvy_assigned_lines(i).DATE_SCHEDULED := p_dlvy_assigned_lines(i).DATE_SCHEDULED;
14882                l_dlvy_assigned_lines(i).SHIP_METHOD_CODE := p_dlvy_assigned_lines(i).SHIP_METHOD_CODE;
14883                l_dlvy_assigned_lines(i).CARRIER_ID := p_dlvy_assigned_lines(i).CARRIER_ID;
14884                l_dlvy_assigned_lines(i).PARTY_ID := p_dlvy_assigned_lines(i).PARTY_ID;
14885                l_dlvy_assigned_lines(i).LINE_DIRECTION := p_dlvy_assigned_lines(i).LINE_DIRECTION;
14886                l_dlvy_assigned_lines(i).SHIPPING_CONTROL := nvl(p_dlvy_assigned_lines(i).SHIPPING_CONTROL,'BUYER');
14887 
14888                --#DUM_LOC(S)
14889 	       WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
14890 	           p_internal_cust_location_id  => l_dlvy_assigned_lines(i).ship_to_location_id,
14891                    x_internal_org_location_id   => l_physical_location_id,
14892                    x_return_status              => l_return_status);
14893 
14894  	       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14895 	          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14896 	              raise FND_API.G_EXC_UNEXPECTED_ERROR;
14897 	          END IF;
14898     	       END IF;
14899 
14900                IF (l_physical_location_id IS NOT NULL) THEN
14901   	          --
14902 	          IF l_debug_on THEN
14903 		     WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_dlvy_assigned_lines(i).ship_to_location_id||' is a dummy location');
14904    	          END IF;
14905 	          --
14906 	          l_dlvy_assigned_lines(i).ship_to_location_id:= l_physical_location_id;
14907                   -- AGDUMMY TODO
14908                   l_dlvy_assigned_lines(i).physical_ship_to_location_id := l_physical_location_id;
14909 	       END IF;
14910                --#DUM_LOC(E)
14911 
14912 	       EXIT WHEN i = p_dlvy_assigned_lines.LAST;
14913                i := p_dlvy_assigned_lines.NEXT(i);
14914 
14915         END LOOP;
14916       END IF;
14917 
14918     END IF;
14919 
14920      --  As per meeting on 10/18 : IGNORE GROUPING CRITERIA and do checks independently
14921      --  framework APIs will be called just before calling action appropriate private APIs
14922 
14923      -- The group line rec should have item and customer populated with the value of the first line
14924      -- For each subsequent line, check those with these values,
14925      -- if match, add to this group, if does not, create a new one
14926      -- ( The following checks are required for ACD )
14927      -- If WSH does not default from line to delivery,
14928      -- 1. any line that has violating item against its intmed ship to, ship method and last 2  being
14929      -- YES in grp crit, should error
14930      -- 2. any line that has violating ship from, ship to against ship method with ship method
14931      -- being YES in grp crit, should error
14932      -- 3. any line that has violating intmed ship to against ship method with both being
14933      -- YES in grp crit, should error
14934      -- 4. any line that has violating org, cus against its intmed ship to and last 1  being
14935      -- YES in grp crit, should error
14936      -- These 4 errors can be resolved by passing a hint to WSH that, even if grp crt is YES,
14937      -- do not default
14938 
14939      -- ( The following checks are required for ADD )
14940      -- For ADD returns whether 1. All input lines can be assigned to the target delivery
14941      -- If not, 2.Group of input lines how they can be grouped to create delivery
14942      -- 3. Input lines which can be assigned to the target delivery (line_group_id = delivery_id)
14943      -- Group input lines by item - item, cus - cus constraints first
14944      -- For each detail, find out if item satisfies delivery mode, carrier,intmed ship to
14945      -- and customer satisfies delivery customer / delivery already existing customers
14946      -- and item satisfies delivery already existing items
14947 
14948 
14949     j := l_del_detail_info.FIRST;
14950     IF j IS NOT NULL THEN
14951       LOOP
14952 
14953          -- Skip if SHIPPING_CONTROL is SUPPLIER
14954 
14955          IF l_del_detail_info(j).shipping_control = 'SUPPLIER' THEN
14956 
14957             l_supp_control_tab(l_del_detail_info(j).delivery_detail_id) := l_del_detail_info(j).delivery_detail_id;
14958             GOTO detail_nextpass;
14959 
14960          END IF;
14961 
14962          l_mode := null;
14963          l_service_level := NULL;
14964          l_carrier := null;
14965          l_intmed_location_id := null;
14966          l_group_id         :=0;
14967          l_found            := FALSE;
14968          l_failed_line_added := FALSE;
14969 
14970          l_validate_itmin_result    := 'S';
14971          l_validate_carrier_result  := 'S';
14972          l_validate_customer_result := 'S';
14973          l_validate_mode_result    := 'S';
14974          l_validate_intmed_result    := 'S';
14975          l_items_tab.DELETE;
14976          l_locations_list.DELETE;
14977 
14978          l_inp_items_cnt := l_items_tab.COUNT;
14979          l_items_tab(l_inp_items_cnt + 1).line_id := l_del_detail_info(j).delivery_detail_id;
14980          l_items_tab(l_inp_items_cnt + 1).item_id := l_del_detail_info(j).inventory_item_id;
14981          l_items_tab(l_inp_items_cnt + 1).org_id  := l_del_detail_info(j).organization_id;
14982 
14983          l_locations_list(l_locations_list.COUNT + 1) := l_del_detail_info(j).ship_from_location_id;
14984          l_locations_list(l_locations_list.COUNT + 1) := l_del_detail_info(j).ship_to_location_id;
14985 
14986          search_itm_fac_incl(
14987                      p_comp_class_tab      =>     l_comp_class_tab,
14988                      p_entity_type         =>     G_DEL_DETAIL,
14989                      p_entity_id           =>     l_del_detail_info(j).delivery_detail_id,
14990                      p_items_tab           =>     l_items_tab,
14991                      p_locations_list      =>     l_locations_list,
14992                      x_validate_result     =>     l_validate_itmfacin_result,
14993                      x_failed_constraints  =>     l_failed_constraints,
14994                      x_return_status       =>     l_return_status);
14995 
14996          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14997             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14998                 raise FND_API.G_EXC_UNEXPECTED_ERROR;
14999             END IF;
15000          END IF;
15001 
15002          IF l_validate_itmfacin_result = 'F' THEN
15003                    IF NOT l_failed_line_added THEN
15004                      -- Discard line (detail) from this group
15005                      -- populate failed lines
15006                      l_failed_lc := l_failed_lc + 1;
15007                      x_failed_lines(l_failed_lc).entity_line_id := l_del_detail_info(j).delivery_detail_id;
15008                      x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
15009                      l_failed_line_added := TRUE;
15010                    END IF;
15011              GOTO detail_nextpass;
15012          END IF;
15013 
15014          l_entity_tab(l_del_detail_info(j).delivery_detail_id).entity_id := l_del_detail_info(j).delivery_detail_id;
15015          l_entity_tab(l_del_detail_info(j).delivery_detail_id).organization_id := l_del_detail_info(j).organization_id;
15016          l_entity_tab(l_del_detail_info(j).delivery_detail_id).inventory_item_id := l_del_detail_info(j).inventory_item_id;
15017          l_entity_tab(l_del_detail_info(j).delivery_detail_id).customer_id := l_del_detail_info(j).customer_id;
15018          --
15019          IF l_debug_on THEN
15020            WSH_DEBUG_SV.logmsg(l_module_name,'Created l_entity_tab with index : '||l_del_detail_info(j).delivery_detail_id||' for detail index '||j);
15021          END IF;
15022          --
15023 
15024          IF j <> l_del_detail_info.FIRST THEN
15025 
15026             search_matching_group(
15027                   p_entity_type           => 'DLVB',
15028                   p_action_code           => p_action_code,
15029                   p_children_info         => l_dummy_assigned_lines,
15030                   p_comp_class_tab        => l_comp_class_tab,
15031                   p_target_stops_info     => l_target_tripstops,
15032                   p_entity_rec            => l_entity_tab(l_del_detail_info(j).delivery_detail_id),
15033                   p_entity_tab            => l_entity_tab, -- IN
15034                   p_group_tab             => x_group_info, -- IN
15035                   x_failed_constraints    => l_failed_constraints, -- IN OUT NOCOPY
15036                   x_group_id              => l_group_id, -- OUT
15037                   x_found                 => l_found, -- OUT
15038                   x_return_status         => l_return_status);
15039             --
15040             IF l_debug_on THEN
15041               WSH_DEBUG_SV.logmsg(l_module_name,'Called search_matching_group return status : '||l_return_status||' Group found ? '||l_group_id);
15042             END IF;
15043             --
15044 
15045             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15046                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15047                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
15048                END IF;
15049             END IF;
15050 
15051          END IF; -- FIRST
15052 
15053          IF l_found THEN
15054                l_entity_tab(l_del_detail_info(j).delivery_detail_id).group_id := l_group_id;
15055                --
15056                IF l_debug_on THEN
15057                  WSH_DEBUG_SV.logmsg(l_module_name,'Adding detail : '||l_del_detail_info(j).delivery_detail_id||' to_group : '||l_group_id);
15058                END IF;
15059                --
15060          ELSE
15061               create_valid_entity_group(
15062                   p_entity_rec    => l_entity_tab(l_del_detail_info(j).delivery_detail_id),
15063                   p_group_tab     => x_group_info, -- IN OUT
15064                   x_return_status => l_return_status);
15065               --
15066               IF l_debug_on THEN
15067                 WSH_DEBUG_SV.logmsg(l_module_name,'Called create_valid_entity_group return status : '||l_return_status);
15068               END IF;
15069               --
15070 
15071               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15072                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15073                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
15074                  END IF;
15075               END IF;
15076          END IF;
15077 
15078          -- Populate x_line_groups table with l_entity_tab(l_del_detail_info(j).delivery_detail_id)
15079 
15080          -- Populate x_line_groups table
15081          l_linegroup_indx := l_linegroup_indx + 1;
15082          x_line_groups(l_linegroup_indx).line_group_index := l_linegroup_indx;
15083          x_line_groups(l_linegroup_indx).entity_line_id   := l_del_detail_info(j).delivery_detail_id;
15084          x_line_groups(l_linegroup_indx).line_group_id   := l_entity_tab(l_del_detail_info(j).delivery_detail_id).group_id;
15085 
15086 
15087          -- Groups have already been created at this point x_group_info
15088          --
15089          IF l_debug_on THEN
15090            WSH_DEBUG_SV.logmsg(l_module_name,'Current detail is in x_group_info with group id : '||l_entity_tab(l_del_detail_info(j).delivery_detail_id).group_id);
15091          END IF;
15092          --
15093          --  END : Potential method to group details
15094          --  Returns valid groups of input lines
15095 
15096          -- If PKG with no target container
15097          -- go to next pass here
15098 
15099          IF (p_action_code = G_PACK_DLVB AND l_target_container.delivery_detail_id IS NULL) THEN
15100             GOTO detail_nextpass;
15101          END IF;
15102 
15103          --  START : Potential method to compare input details with target dlvy lines as per
15104          --  ITM - ITM and CUS - CUS constraints
15105 
15106          IF p_action_code = G_ASSIGN_DLVB_DLVY THEN
15107            IF l_comp_class_tab.EXISTS(G_CUSTOMER_CUSTOMER_NUM) AND
15108               l_target_delivery.customer_id <> l_del_detail_info(j).customer_id THEN
15109 
15110              l_item_check_cus := TRUE;
15111 
15112              validate_constraint(
15113                     p_comp_class_code          =>      G_CUSTOMER_CUSTOMER,
15114                     p_object1_val_num          =>      l_target_delivery.customer_id,
15115                     p_object2_val_num          =>      l_del_detail_info(j).customer_id,
15116                     x_validate_result          =>      l_validate_customer_result,
15117                     x_failed_constraint        =>      l_failed_constraint,
15118                     x_return_status            =>      l_return_status);
15119 
15120              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15121                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15122                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
15123                END IF;
15124              END IF;
15125 
15126              IF l_validate_customer_result <> 'S' THEN
15127               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
15128               l_failed_constraint.entity_type :=  G_DEL_DETAIL;
15129               l_failed_constraint.entity_line_id :=  l_del_detail_info(j).delivery_detail_id;
15130               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
15131               IF l_validate_customer_result = 'E' THEN
15132                    l_validate_result := 'E';
15133                    IF NOT l_failed_line_added THEN
15134                      x_line_groups.DELETE(l_linegroup_indx);
15135                      -- Discard line (detail) from this group
15136                      -- populate failed lines
15137                      l_failed_lc := l_failed_lc + 1;
15138                      x_failed_lines(l_failed_lc).entity_line_id := l_del_detail_info(j).delivery_detail_id;
15139                      x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
15140                      l_failed_line_added := TRUE;
15141                    END IF;
15142               END IF;
15143 
15144              END IF;
15145              l_item_check_cus := FALSE;
15146 
15147             END IF;
15148 
15149          END IF;
15150 
15151          IF (p_action_code = G_PACK_DLVB) OR
15152             (p_action_code = G_ASSIGN_DLVB_DLVY) THEN
15153 
15154          -- Still need to check itm - itm and/or cus - cus
15155          -- between input lines and target delivery lines
15156 
15157             k := l_dlvy_assigned_lines.FIRST;
15158 
15159             IF k IS NOT NULL THEN
15160               LOOP
15161 
15162                   l_item_org_id := l_dlvy_assigned_lines(k).organization_id;
15163                   l_item_id := l_dlvy_assigned_lines(k).inventory_item_id;
15164                   l_customer_id := l_dlvy_assigned_lines(k).customer_id;
15165 
15166                   IF l_item_check_cus AND
15167                      l_del_detail_info(j).customer_id <> l_customer_id THEN
15168 
15169                     validate_constraint(
15170                       p_comp_class_code          =>      G_CUSTOMER_CUSTOMER,
15171                       p_object1_val_num          =>      l_del_detail_info(j).customer_id,
15172                       p_object2_val_num          =>      l_customer_id,
15173                       x_validate_result          =>      l_validate_customer_result,
15174                       x_failed_constraint        =>      l_failed_constraint,
15175                       x_return_status            =>      l_return_status);
15176 
15177                     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15178                        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15179 
15180                           raise FND_API.G_EXC_UNEXPECTED_ERROR;
15181                        END IF;
15182                     END IF;
15183 
15184                     IF l_validate_customer_result <> 'S' THEN
15185                      l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
15186                      l_failed_constraint.entity_type :=  G_DEL_DETAIL;
15187                      l_failed_constraint.entity_line_id :=  l_del_detail_info(j).delivery_detail_id;
15188                      l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
15189                          IF l_validate_customer_result = 'E' THEN
15190                             l_validate_result := 'E';
15191                           IF NOT l_failed_line_added THEN
15192                             x_line_groups.DELETE(l_linegroup_indx);
15193                             -- Discard line (detail) from this group
15194                             -- populate failed lines
15195                             l_failed_lc := l_failed_lc + 1;
15196                             x_failed_lines(l_failed_lc).entity_line_id := l_del_detail_info(j).delivery_detail_id;
15197                             x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
15198                             l_failed_line_added := TRUE;
15199                           END IF;
15200                          END IF;
15201                     END IF;
15202 
15203                   END IF;
15204 
15205                  -- itm - car/mod must use check between
15206                  -- p_children_info(l) and p_children_info(m)
15207 
15208                   IF (p_action_code = G_ASSIGN_DLVB_DLVY) THEN
15209 
15210                      l_target_rec.entity_id := l_dlvy_assigned_lines(k).delivery_detail_id;
15211                      l_target_rec.organization_id := l_dlvy_assigned_lines(k).organization_id;
15212                      l_target_rec.inventory_item_id := l_dlvy_assigned_lines(k).inventory_item_id;
15213                      l_target_rec.customer_id := l_dlvy_assigned_lines(k).customer_id;
15214                      --
15215                      IF l_debug_on THEN
15216                         WSH_DEBUG_SV.logmsg(l_module_name,'Created l_target_rec for assigned line : '||l_dlvy_assigned_lines(k).delivery_detail_id);
15217                      END IF;
15218                      --
15219 
15220                      IF ((l_entity_tab(l_del_detail_info(j).delivery_detail_id).inventory_item_id <> l_target_rec.inventory_item_id) OR
15221                         (g_is_tp_installed = 'N' AND l_entity_tab(l_del_detail_info(j).delivery_detail_id).organization_id <> l_target_rec.organization_id))  THEN
15222 
15223                      search_group_itm (
15224                         p_comp_class_tab      =>   l_comp_class_tab,
15225                         p_entity_rec          =>   l_entity_tab(l_del_detail_info(j).delivery_detail_id),
15226                         p_target_rec          =>   l_target_rec,
15227                         x_validate_result     =>   l_validate_itmin_result,
15228                         x_failed_constraints  =>   l_failed_constraints,
15229                         x_return_status       =>   l_return_status);
15230 
15231                      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15232                         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15233                            raise FND_API.G_EXC_UNEXPECTED_ERROR;
15234                         END IF;
15235                      END IF;
15236 
15237                      IF l_validate_itmin_result = 'F' THEN
15238                          IF NOT l_failed_line_added THEN
15239                            x_line_groups.DELETE(l_linegroup_indx);
15240                            -- Discard line (detail) from this group
15241                            -- populate failed lines
15242                            l_failed_lc := l_failed_lc + 1;
15243                            x_failed_lines(l_failed_lc).entity_line_id := l_del_detail_info(j).delivery_detail_id;
15244                            x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
15245                            l_failed_line_added := TRUE;
15246                          END IF;
15247                          EXIT;
15248                      END IF;
15249                      END IF;
15250                   END IF;
15251 
15252                   EXIT WHEN k = l_dlvy_assigned_lines.LAST;
15253                   k := l_dlvy_assigned_lines.NEXT(k);
15254 
15255               END LOOP;
15256             END IF;
15257 
15258             IF l_validate_itmin_result = 'F' THEN
15259                GOTO detail_nextpass;
15260             END IF;
15261 
15262          --  END : Potential method to compare input details with target dlvy lines as per
15263          --  ITM - ITM and CUS - CUS constraints
15264 
15265          END IF;
15266 
15267          IF p_action_code = G_PACK_DLVB OR
15268             (l_target_delivery.ship_method_code IS NULL AND
15269              l_target_delivery.carrier_id IS NULL AND
15270              l_target_delivery.mode_of_transport IS NULL AND
15271              p_action_code = G_ASSIGN_DLVB_DLVY)
15272             OR (l_del_detail_info(j).ship_method_code IS NULL AND
15273                 l_del_detail_info(j).carrier_id IS NULL AND
15274                 p_action_code = G_AUTOCRT_DLVY) THEN
15275 
15276             GOTO detail_nextpass;
15277          END IF;
15278 
15279          IF p_action_code = G_ASSIGN_DLVB_DLVY THEN
15280            IF l_target_delivery.ship_method_code IS NOT NULL THEN
15281             l_carrier_service_inout_rec.ship_method_code := l_target_delivery.ship_method_code;
15282             WSH_CARRIERS_GRP.get_carrier_service_mode(
15283                      p_carrier_service_inout_rec   =>  l_carrier_service_inout_rec,
15284                      x_return_status       =>  l_return_status);
15285 
15286                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15287                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15288                   IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
15289                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
15290                   END IF;
15291                   raise g_get_carrmode_failed;
15292                  END IF;
15293                END IF;
15294                l_carrier := l_carrier_service_inout_rec.carrier_id;
15295                l_mode    := l_carrier_service_inout_rec.mode_of_transport;
15296            END IF;
15297            IF l_target_delivery.carrier_id IS NOT NULL THEN
15298               l_carrier := l_target_delivery.carrier_id;
15299            END IF;
15300            IF l_target_delivery.mode_of_transport IS NOT NULL THEN
15301               l_mode := l_target_delivery.mode_of_transport;
15302            END IF;
15303          ELSIF p_action_code = G_AUTOCRT_DLVY THEN
15304            IF l_del_detail_info(j).ship_method_code IS NOT NULL THEN
15305             l_carrier_service_inout_rec.ship_method_code := l_del_detail_info(j).ship_method_code;
15306             WSH_CARRIERS_GRP.get_carrier_service_mode(
15307                      p_carrier_service_inout_rec   =>  l_carrier_service_inout_rec,
15308                      x_return_status       =>  l_return_status);
15309 
15310             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15311                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15312                 IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
15313                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
15314                 END IF;
15315                 raise g_get_carrmode_failed;
15316                END IF;
15317             END IF;
15318             l_carrier := l_carrier_service_inout_rec.carrier_id;
15319             l_mode    := l_carrier_service_inout_rec.mode_of_transport;
15320            END IF;
15321            IF l_del_detail_info(j).carrier_id IS NOT NULL THEN
15322                l_carrier := l_del_detail_info(j).carrier_id;
15323            END IF;
15324          END IF;
15325 
15326          IF l_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) AND l_carrier IS NOT NULL THEN
15327 
15328            validate_constraint(
15329              p_comp_class_code          =>      G_ITEM_CARRIER,
15330              p_object1_parent_id        =>      l_del_detail_info(j).organization_id,
15331              p_object1_val_num          =>      l_del_detail_info(j).inventory_item_id,
15332              p_object2_val_num          =>      l_carrier,
15333              x_validate_result          =>      l_validate_carrier_result,
15334              x_failed_constraint        =>      l_failed_constraint,
15335              x_return_status            =>      l_return_status);
15336 
15337            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15338               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15339                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
15340               END IF;
15341            END IF;
15342 
15343            IF l_validate_carrier_result <> 'S' THEN
15344               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
15345               l_failed_constraint.entity_type :=  G_DEL_DETAIL;
15346               l_failed_constraint.entity_line_id :=  l_del_detail_info(j).delivery_detail_id;
15347               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
15348               IF l_validate_carrier_result = 'E' THEN
15349                IF p_action_code = G_ASSIGN_DLVB_DLVY THEN
15350                   l_validate_result := 'E';
15351                      -- populate failed lines
15352                   IF NOT l_failed_line_added THEN
15353                       l_failed_lc := l_failed_lc + 1;
15354                       x_failed_lines(l_failed_lc).entity_line_id := l_del_detail_info(j).delivery_detail_id;
15355                       x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
15356                      -- Discard line (detail) from this group
15357                       x_line_groups.DELETE(l_linegroup_indx);
15358                       l_failed_line_added := TRUE;
15359                   END IF;
15360                END IF;
15361                x_group_info(l_entity_tab(l_del_detail_info(j).delivery_detail_id).group_id).upd_dlvy_ship_method     := 'N';
15362               END IF;
15363            END IF;
15364 
15365          END IF;
15366 
15367          IF l_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) AND l_mode IS NOT NULL THEN
15368 
15369            validate_constraint(
15370              p_comp_class_code          =>      G_ITEM_MODE,
15371              p_object1_parent_id        =>      l_del_detail_info(j).organization_id,
15372              p_object1_val_num          =>      l_del_detail_info(j).inventory_item_id,
15373              p_object2_val_char         =>      l_mode,
15374              x_validate_result          =>      l_validate_mode_result,
15375              x_failed_constraint        =>      l_failed_constraint,
15376              x_return_status            =>      l_return_status);
15377 
15378            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15379               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15380                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
15381               END IF;
15382            END IF;
15383 
15384            IF l_validate_mode_result <> 'S' THEN
15385             l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
15386             l_failed_constraint.entity_type :=  G_DEL_DETAIL;
15387             l_failed_constraint.entity_line_id :=  l_del_detail_info(j).delivery_detail_id;
15388             l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
15389             IF l_validate_mode_result = 'E' THEN
15390                IF p_action_code = G_ASSIGN_DLVB_DLVY THEN
15391                   l_validate_result := 'E';
15392                      -- populate failed lines
15393                   IF NOT l_failed_line_added THEN
15394                       l_failed_lc := l_failed_lc + 1;
15395                       x_failed_lines(l_failed_lc).entity_line_id := l_del_detail_info(j).delivery_detail_id;
15396                       x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
15397                      -- Discard line (detail) from this group
15398                       x_line_groups.DELETE(l_linegroup_indx);
15399                       l_failed_line_added := TRUE;
15400                   END IF;
15401                END IF;
15402                x_group_info(l_entity_tab(l_del_detail_info(j).delivery_detail_id).group_id).upd_dlvy_ship_method     := 'N';
15403             END IF;
15404            END IF;
15405 
15406          END IF;
15407 
15408          IF p_action_code = G_ASSIGN_DLVB_DLVY THEN
15409             GOTO detail_nextpass;
15410          END IF;
15411          IF l_carrier IS NOT NULL THEN
15412 
15413            IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) THEN
15414               validate_constraint(
15415                  p_comp_class_code          =>      G_FACILITY_CARRIER,
15416                  p_object1_type             =>      'FAC',
15417                  p_object1_val_num          =>      l_del_detail_info(j).ship_from_location_id,
15418                  p_object2_val_num          =>      l_carrier,
15419                  x_validate_result          =>      l_validate_carrier_result,
15420                  x_failed_constraint        =>      l_failed_constraint,
15421                  x_return_status            =>      l_return_status);
15422 
15423                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15424                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15425                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
15426                   END IF;
15427                END IF;
15428 
15429                IF l_validate_carrier_result <> 'S' THEN
15430                 l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
15431                 l_failed_constraint.entity_type :=  G_DEL_DETAIL;
15432                 l_failed_constraint.entity_line_id :=  l_del_detail_info(j).delivery_detail_id;
15433                 l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
15434                 IF l_validate_carrier_result = 'E' THEN
15435                    x_group_info(l_entity_tab(l_del_detail_info(j).delivery_detail_id).group_id).upd_dlvy_ship_method     := 'N';
15436                 END IF;
15437                END IF;
15438 
15439              -- If ship to location is also assumed to be customer site
15440              -- then need to check constraint with object1_type = CUSTOMER as well
15441                validate_constraint(
15442                  p_comp_class_code          =>      G_FACILITY_CARRIER,
15443                  p_object1_type             =>      'FAC',
15444                  p_object1_val_num          =>      l_del_detail_info(j).ship_to_location_id,
15445                  p_object2_val_num          =>      l_carrier,
15446                  x_validate_result          =>      l_validate_carrier_result,
15447                  x_failed_constraint        =>      l_failed_constraint,
15448                  x_return_status            =>      l_return_status);
15449 
15450                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15451                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15452                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
15453                   END IF;
15454                END IF;
15455 
15456                IF l_validate_carrier_result <> 'S' THEN
15457                 l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
15458                 l_failed_constraint.entity_type :=  G_DEL_DETAIL;
15459                 l_failed_constraint.entity_line_id :=  l_del_detail_info(j).delivery_detail_id;
15460                 l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
15461                 IF l_validate_carrier_result = 'E' THEN
15462                    -- populate failed lines
15463                    x_group_info(l_entity_tab(l_del_detail_info(j).delivery_detail_id).group_id).upd_dlvy_ship_method     := 'N';
15464                 END IF;
15465                END IF;
15466 
15467            END IF;
15468          END IF; -- l_carrier
15469 
15470          IF l_mode IS NOT NULL THEN
15471 
15472            IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) THEN
15473 
15474                validate_constraint(
15475                  p_comp_class_code          =>      G_FACILITY_MODE,
15476                  p_object1_type             =>      'FAC',
15477                  p_object1_val_num          =>      l_del_detail_info(j).ship_from_location_id,
15478                  p_object2_val_char         =>      l_mode,
15479                  x_validate_result          =>      l_validate_mode_result,
15480                  x_failed_constraint        =>      l_failed_constraint,
15481                  x_return_status            =>      l_return_status);
15482 
15483                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15484                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15485                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
15486                   END IF;
15487                END IF;
15488 
15489                IF l_validate_mode_result <> 'S' THEN
15490                 l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
15491                 l_failed_constraint.entity_type :=  G_DEL_DETAIL;
15492                 l_failed_constraint.entity_line_id :=  l_del_detail_info(j).delivery_detail_id;
15493                 l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
15494                 IF l_validate_mode_result = 'E' THEN
15495                          -- populate failed lines
15496                    x_group_info(l_entity_tab(l_del_detail_info(j).delivery_detail_id).group_id).upd_dlvy_ship_method     := 'N';
15497                 END IF;
15498                END IF;
15499 
15500                validate_constraint(
15501                  p_comp_class_code          =>      G_FACILITY_MODE,
15502                  p_object1_type             =>      'FAC',
15503                  p_object1_val_num          =>      l_del_detail_info(j).ship_to_location_id,
15504                  p_object2_val_char         =>      l_mode,
15505                  x_validate_result          =>      l_validate_mode_result,
15506                  x_failed_constraint        =>      l_failed_constraint,
15507                  x_return_status            =>      l_return_status);
15508 
15509                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15510                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15511                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
15512                   END IF;
15513                END IF;
15514 
15515                IF l_validate_mode_result <> 'S' THEN
15516                 l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
15517                 l_failed_constraint.entity_type :=  G_DEL_DETAIL;
15518                 l_failed_constraint.entity_line_id :=  l_del_detail_info(j).delivery_detail_id;
15519                 l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
15520                 IF l_validate_mode_result = 'E' THEN
15521                          -- populate failed lines
15522                    x_group_info(l_entity_tab(l_del_detail_info(j).delivery_detail_id).group_id).upd_dlvy_ship_method     := 'N';
15523                 END IF;
15524                END IF;
15525 
15526            END IF;
15527          END IF; -- l_mode
15528 
15529          <<detail_nextpass>>
15530 
15531          EXIT WHEN j = l_del_detail_info.LAST;
15532          j := l_del_detail_info.NEXT(j);
15533       END LOOP;
15534     END IF;
15535 
15536     IF l_supp_control_tab.COUNT > 0 THEN
15537 
15538         -- Populate line_groups and group
15539 
15540         -- Add to x_group_info
15541         l_group_count := x_group_info.COUNT + 1;
15542         x_group_info(l_group_count).group_index := l_group_count;
15543         x_group_info(l_group_count).line_group_id := l_group_count;
15544 
15545         i := l_supp_control_tab.FIRST;
15546         LOOP
15547 
15548            -- Populate x_line_groups table
15549            l_linegroup_indx := x_line_groups.COUNT + 1;
15550            x_line_groups(l_linegroup_indx).line_group_index := l_linegroup_indx;
15551            x_line_groups(l_linegroup_indx).entity_line_id   := l_supp_control_tab(i);
15552            x_line_groups(l_linegroup_indx).line_group_id    := l_group_count;
15553 
15554            EXIT WHEN i=l_supp_control_tab.LAST;
15555            i := l_supp_control_tab.NEXT(i);
15556         END LOOP;
15557 
15558     END IF;
15559 
15560     -- Populate x_validate_result
15561     IF x_group_info.COUNT > 1 OR x_failed_lines.COUNT > 0 THEN
15562         x_validate_result := 'F';
15563         IF x_group_info.COUNT > 1 AND p_action_code = G_ASSIGN_DLVB_DLVY THEN
15564            -- Put all input lines in incompatible groups into failed lines
15565 
15566            -- After changing the logic to form groups in case of
15567            -- assign, the following list of groups will only contain
15568            -- mutually incompatible groups
15569            -- not the always successful groups
15570            i := x_group_info.FIRST;
15571            LOOP
15572 
15573              -- Will not delete these lines from linegroups
15574              -- Hence for this case the sum of failed lines and
15575              -- lines in linegroups will exceed number of input lines
15576              -- by these lines in linegroups
15577              -- Will not delete these incompatible groups
15578              j := x_line_groups.FIRST;
15579              LOOP
15580 
15581                 IF x_line_groups(j).line_group_id <> x_group_info(i).line_group_id THEN
15582                    GOTO next_linegroup;
15583                 END IF;
15584 
15585                 -- Add to failed lines
15586                 l_failed_lc := x_failed_lines.COUNT + 1;
15587                 x_failed_lines(l_failed_lc).entity_line_id := x_line_groups(j).entity_line_id;
15588                 x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
15589                 <<next_linegroup>>
15590                 EXIT WHEN j=x_line_groups.LAST;
15591                 j := x_line_groups.NEXT(j);
15592              END LOOP;
15593 
15594              EXIT WHEN i=x_group_info.LAST;
15595              i := x_group_info.NEXT(i);
15596            END LOOP;
15597         END IF;
15598     END IF;
15599 
15600     IF x_failed_lines.COUNT = 0 AND p_action_code = G_AUTOCRT_DLVY THEN
15601        l_failed_constraints.DELETE;
15602     END IF;
15603 
15604     --  Loop over l_failed_constraints to add to the mesage stack
15605 
15606     stack_messages (
15607              p_failed_constraints       => l_failed_constraints,
15608              x_msg_count                => x_msg_count,
15609              x_msg_data                 => x_msg_data,
15610              x_return_status            => l_return_status);
15611 
15612     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15613          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15614             raise FND_API.G_EXC_UNEXPECTED_ERROR;
15615          END IF;
15616     END IF;
15617 
15618     IF x_validate_result = 'F' THEN
15619         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
15620     ELSIF l_failed_constraints.COUNT > 0 THEN
15621         x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
15622     END IF;
15623 
15624     --
15625     IF l_debug_on THEN
15626        WSH_DEBUG_SV.pop(l_module_name);
15627     END IF;
15628     --
15629 
15630 EXCEPTION
15631     WHEN g_get_carrmode_failed THEN
15632       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
15633       --
15634       IF l_debug_on THEN
15635         WSH_DEBUG_SV.pop(l_module_name,' get carrier-mode failed ');
15636       END IF;
15637       --
15638     WHEN g_invalid_action_code THEN
15639       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
15640       --
15641       IF l_debug_on THEN
15642         WSH_DEBUG_SV.pop(l_module_name,' invalid_action_code ');
15643       END IF;
15644       --
15645     WHEN g_invalid_input THEN
15646       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
15647       --
15648       IF l_debug_on THEN
15649         WSH_DEBUG_SV.pop(l_module_name,' invalid_input ');
15650       END IF;
15651       --
15652 
15653     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
15654       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
15655       --
15656       IF l_debug_on THEN
15657         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
15658         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
15659       END IF;
15660       --
15661     WHEN others THEN
15662       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.validate_constraint_dlvb');
15663       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
15664       --
15665       IF l_debug_on THEN
15666         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
15667         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
15668       END IF;
15669       --
15670 END validate_constraint_dlvb;
15671 
15672 
15673 --***************************************************************************
15674 --
15675 --========================================================================
15676 -- PROCEDURE : validate_constraint_trip    Called by constraint Wrapper API
15677 --                                         and the Group API.
15678 --
15679 -- PARAMETERS: p_init_msg_list             FND_API.G_TRUE to reset list
15680 --             p_action_code               Predefined action code
15681 --             p_exception_list            Compatibility classes to skip if any
15682 --                                         indexed by class code numbers
15683 --             p_trip_info                 Table of Trip records to process
15684 --             p_trip_assigned_dels        Table of delivery records already in the trip
15685 --                                         If not passed, the API will query
15686 --             p_trip_dlvy_lines           Table of delivery details already in the trip
15687 --                                         If not passed, the API will query
15688 --             p_trip_incl_stops           Table of Stop records already in the trip
15689 --                                         If not passed, the API will query
15690 --             x_fail_trips                Table of input trips that failed constraint check
15691 --             x_validate_result           Constraint Validation result : S / F
15692 --             x_msg_count                 Number of messages in the list
15693 --             x_msg_data                  Text of messages
15694 --             x_return_status             Return status
15695 -- COMMENT   : This procedure is used to perform for following actions
15696 --             A. Update an existing trip (UPT)
15697 --========================================================================
15698 
15699 PROCEDURE validate_constraint_trip(
15700              p_init_msg_list            IN      VARCHAR2 DEFAULT fnd_api.g_false,
15701              p_action_code              IN      VARCHAR2 DEFAULT NULL,
15702              p_exception_list           IN      WSH_UTIL_CORE.Column_Tab_Type,
15703              p_trip_info                IN      trip_ccinfo_tab_type,
15704              p_trip_assigned_dels       IN      delivery_ccinfo_tab_type,
15705              p_trip_dlvy_lines          IN      detail_ccinfo_tab_type,
15706              p_trip_incl_stops          IN      stop_ccinfo_tab_type,
15707              x_fail_trips               OUT NOCOPY    WSH_UTIL_CORE.id_tab_type,
15708              x_validate_result          OUT NOCOPY    VARCHAR2,
15709              x_msg_count                OUT NOCOPY    NUMBER,
15710              x_msg_data                 OUT NOCOPY    VARCHAR2,
15711              x_return_status            OUT NOCOPY    VARCHAR2)
15712 IS
15713 
15714     j                                   NUMBER := 0;
15715     k                                   NUMBER := 0;
15716     l                                   NUMBER := 0;
15717     l_carrier                           NUMBER := 0;
15718     l_vehicle_type                      NUMBER := 0;
15719     l_mode                              VARCHAR2(30);
15720     l_service_level                     VARCHAR2(30) := NULL;
15721     l_carrier_service_inout_rec         WSH_CARRIERS_GRP.Carrier_Service_InOut_Rec_Type;
15722     l_trip_del_cnt                      NUMBER := 0;
15723     l_trip_detail_cnt                   NUMBER := 0;
15724     l_trip_stops_cnt                    NUMBER := 0;
15725     l_out_object2_num                   NUMBER:=0;
15726     l_out_object2_char                  VARCHAR2(30):=NULL;
15727     l_comp_class_tab                    WSH_UTIL_CORE.Column_Tab_Type;
15728     l_return_status                     VARCHAR2(1);
15729     l_failed_constraint                 line_constraint_rec_type;
15730     l_failed_constraints                line_constraint_tab_type;
15731     l_curr_trip_added                   BOOLEAN := FALSE;
15732     l_validate_mode_result              VARCHAR2(1) := 'S';
15733     l_validate_carrier_result           VARCHAR2(1) := 'S';
15734     l_validate_vehicle_result           VARCHAR2(1) := 'S';
15735     l_validate_faccar_result            VARCHAR2(1) := 'S';
15736     l_validate_facveh_result            VARCHAR2(1) := 'S';
15737     l_validate_facmod_result            VARCHAR2(1) := 'S';
15738     l_validate_itmveh_result            VARCHAR2(1) := 'S';
15739     l_validate_itmcar_result            VARCHAR2(1) := 'S';
15740     l_validate_itmmod_result            VARCHAR2(1) := 'S';
15741     l_validate_in_result                VARCHAR2(1) := 'S';
15742     l_validate_ex_result                VARCHAR2(1) := 'S';
15743     l_delivery_rec                      delivery_ccinfo_rec_type;
15744     l_detail_rec                        detail_ccinfo_rec_type;
15745     l_stop_rec                          stop_ccinfo_rec_type;
15746     l_trip_assigned_dels                delivery_ccinfo_tab_type;
15747     l_trip_dlvy_lines                   detail_ccinfo_tab_type;
15748     l_trip_incl_stops                   stop_ccinfo_tab_type;
15749     l_vehicle_name                      VARCHAR2(2000);
15750     l_vehicle_org_name                  VARCHAR2(240);
15751 
15752     --#DUM_LOC(S)
15753     l_physical_location_id		NUMBER;
15754     --#DUM_LOC(E)
15755 
15756     --SBAKSHI(8/24)
15757     l_trip_incl_stops_sort		stop_ccinfo_tab_type;
15758     l_idx				NUMBER;
15759     --SBAKSHI(8/24)
15760     l_debug_on                          CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
15761     l_module_name                       CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'validate_constraint_trip';
15762 
15763 BEGIN
15764 
15765     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
15766     x_validate_result := 'S';
15767 
15768     g_itm_mustuse_cache.DELETE;
15769     g_itmloc_mustuse_cache.DELETE;
15770     g_itm_exclusive_cache.DELETE;
15771     g_fac_exclusive_cache.DELETE;
15772 
15773     IF FND_API.to_Boolean( p_init_msg_list ) THEN
15774          FND_MSG_PUB.initialize;
15775     END IF;
15776 
15777     IF l_debug_on THEN
15778        wsh_debug_sv.push(l_module_name);
15779        WSH_DEBUG_SV.logmsg(l_module_name,'p_init_msg_list : '||p_init_msg_list);
15780     END IF;
15781 
15782     refresh_cache(l_return_status);
15783 
15784     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15785          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15786             raise FND_API.G_EXC_UNEXPECTED_ERROR;
15787          END IF;
15788     END IF;
15789 
15790     IF NOT p_exception_list.EXISTS(G_FACILITY_MODE_NUM) THEN
15791       l_comp_class_tab(G_FACILITY_MODE_NUM) := G_FACILITY_MODE;
15792     END IF;
15793     IF NOT p_exception_list.EXISTS(G_FACILITY_CARRIER_NUM) THEN
15794       l_comp_class_tab(G_FACILITY_CARRIER_NUM) := G_FACILITY_CARRIER;
15795     END IF;
15796     IF NOT p_exception_list.EXISTS(G_FACILITY_VEHICLE_NUM) THEN
15797       l_comp_class_tab(G_FACILITY_VEHICLE_NUM) := G_FACILITY_VEHICLE;
15798     END IF;
15799     IF NOT p_exception_list.EXISTS(G_ITEM_MODE_NUM) THEN
15800       l_comp_class_tab(G_ITEM_MODE_NUM) := G_ITEM_MODE;
15801     END IF;
15802     IF NOT p_exception_list.EXISTS(G_ITEM_CARRIER_NUM) THEN
15803       l_comp_class_tab(G_ITEM_CARRIER_NUM) := G_ITEM_CARRIER;
15804     END IF;
15805     IF NOT p_exception_list.EXISTS(G_ITEM_VEHICLE_NUM) THEN
15806       l_comp_class_tab(G_ITEM_VEHICLE_NUM) := G_ITEM_VEHICLE;
15807     END IF;
15808 
15809     j := p_trip_info.FIRST;
15810     IF j IS NOT NULL THEN
15811     LOOP
15812     IF p_trip_assigned_dels.COUNT = 0 THEN
15813 
15814           OPEN c_get_trip_dlvy(p_trip_info(j).trip_id); -- or container_id
15815           LOOP
15816                FETCH c_get_trip_dlvy INTO l_delivery_rec;
15817                EXIT WHEN c_get_trip_dlvy%NOTFOUND;
15818 
15819 	       --#DUM_LOC(S)
15820 	       WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
15821 	             p_internal_cust_location_id  => l_delivery_rec.ultimate_dropoff_location_id,
15822 	             x_internal_org_location_id   => l_physical_location_id,
15823 		     x_return_status              => l_return_status);
15824 
15825 	       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15826 	         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15827 	            raise FND_API.G_EXC_UNEXPECTED_ERROR;
15828 	         END IF;
15829   	       END IF;
15830 
15831 	       IF (l_physical_location_id IS NOT NULL) THEN
15832   	         --
15833 	         IF l_debug_on THEN
15834 		     WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_delivery_rec.ultimate_dropoff_location_id||' is a dummy location');
15835 	         END IF;
15836 	         --
15837 	         l_delivery_rec.ultimate_dropoff_location_id := l_physical_location_id;
15838                  -- AGDUMMY TODO
15839                  l_delivery_rec.physical_dropoff_location_id := l_physical_location_id;
15840 	       END IF;
15841                --#DUM_LOC(E)
15842 
15843 	       l_trip_del_cnt := l_trip_del_cnt + 1;
15844                l_trip_assigned_dels(l_trip_del_cnt) := l_delivery_rec;
15845           END LOOP;
15846           CLOSE c_get_trip_dlvy;
15847     END IF;
15848 
15849     IF p_trip_dlvy_lines.COUNT = 0 THEN
15850 
15851           OPEN c_get_trip_details_std(p_trip_info(j).trip_id); -- or container_id
15852           LOOP
15853                FETCH c_get_trip_details_std INTO l_detail_rec;
15854                EXIT WHEN c_get_trip_details_std%NOTFOUND;
15855                --#DUM_LOC(S)
15856 	       WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
15857 	  	      p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
15858 	          x_internal_org_location_id   => l_physical_location_id,
15859               x_return_status              => l_return_status);
15860 
15861 	       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15862 		 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15863 			raise FND_API.G_EXC_UNEXPECTED_ERROR;
15864 	         END IF;
15865 	       END IF;
15866 
15867 	       IF (l_physical_location_id IS NOT NULL) THEN
15868   	          --
15869 	          IF l_debug_on THEN
15870 		    WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
15871 	          END IF;
15872 	          --
15873 	          l_detail_rec.ship_to_location_id:= l_physical_location_id;
15874                   -- AGDUMMY TODO
15875                   l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
15876 	       END IF;
15877                 --#DUM_LOC(E)
15878 	       l_trip_detail_cnt := l_trip_detail_cnt + 1;
15879                l_trip_dlvy_lines(l_trip_detail_cnt) := l_detail_rec;
15880           END LOOP;
15881           CLOSE c_get_trip_details_std;
15882     END IF;
15883 
15884     IF p_trip_incl_stops.COUNT = 0 THEN
15885 
15886           OPEN c_get_trip_stops(p_trip_info(j).trip_id); -- or container_id
15887           LOOP
15888 	       -- Cursor c_get_trip_stops handles the case of returning physical locations
15889 	       -- for the dummy location.
15890 	       FETCH c_get_trip_stops INTO l_stop_rec;
15891                EXIT WHEN c_get_trip_stops%NOTFOUND;
15892                l_trip_stops_cnt := l_trip_stops_cnt + 1;
15893                l_trip_incl_stops(l_trip_stops_cnt) := l_stop_rec;
15894 
15895 	  END LOOP;
15896           CLOSE c_get_trip_stops;
15897 
15898     END IF;
15899 
15900     EXIT WHEN j = p_trip_info.LAST;
15901     j := p_trip_info.NEXT(j);
15902     END LOOP;
15903     END IF;
15904 
15905     IF p_trip_assigned_dels.COUNT <> 0 THEN
15906 
15907 	l := p_trip_assigned_dels.FIRST;
15908         LOOP
15909            l_trip_assigned_dels(l) := p_trip_assigned_dels(l);
15910 
15911 	   --#DUM_LOC(S)
15912 	   WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
15913              p_internal_cust_location_id  => l_trip_assigned_dels(l).ultimate_dropoff_location_id,
15914              x_internal_org_location_id   => l_physical_location_id,
15915              x_return_status              => l_return_status);
15916 
15917 	   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15918 	     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15919 	        raise FND_API.G_EXC_UNEXPECTED_ERROR;
15920 	     END IF;
15921   	   END IF;
15922 
15923 	   IF (l_physical_location_id IS NOT NULL) THEN
15924   	      --
15925 	      IF l_debug_on THEN
15926 		  WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_trip_assigned_dels(l).ultimate_dropoff_location_id||' is a dummy location');
15927 	      END IF;
15928 	      --
15929 	      l_trip_assigned_dels(l).ultimate_dropoff_location_id := l_physical_location_id;
15930               -- AGDUMMY TODO
15931               l_trip_assigned_dels(l).physical_dropoff_location_id := l_physical_location_id;
15932 	   END IF;
15933            --#DUM_LOC(E)
15934 
15935            EXIT WHEN l = p_trip_assigned_dels.LAST;
15936            l := p_trip_assigned_dels.NEXT(l);
15937         END LOOP;
15938 
15939     END IF;
15940 
15941     IF p_trip_dlvy_lines.COUNT <> 0 THEN
15942 
15943         l := p_trip_dlvy_lines.FIRST;
15944         LOOP
15945            l_trip_dlvy_lines(l) := p_trip_dlvy_lines(l);
15946            --#DUM_LOC(S)
15947 	   WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
15948 	      p_internal_cust_location_id  => l_trip_dlvy_lines(l).ship_to_location_id,
15949               x_internal_org_location_id   => l_physical_location_id,
15950               x_return_status              => l_return_status);
15951 
15952  	   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15953 	     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15954 	        raise FND_API.G_EXC_UNEXPECTED_ERROR;
15955 	     END IF;
15956     	   END IF;
15957 
15958   	   IF (l_physical_location_id IS NOT NULL) THEN
15959   	      --
15960 	      IF l_debug_on THEN
15961 		  WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_trip_dlvy_lines(l).ship_to_location_id||' is a dummy location');
15962 	      END IF;
15963 	      --
15964 	      l_trip_dlvy_lines(l).ship_to_location_id:= l_physical_location_id;
15965               -- AGDUMMY TODO
15966               l_trip_dlvy_lines(l).physical_ship_to_location_id := l_physical_location_id;
15967 	   END IF;
15968            --#DUM_LOC(E)
15969 
15970 	   EXIT WHEN l = p_trip_dlvy_lines.LAST;
15971            l := p_trip_dlvy_lines.NEXT(l);
15972         END LOOP;
15973     END IF;
15974 
15975     IF p_trip_incl_stops.COUNT <> 0 THEN
15976 
15977 	/* SBAKSHI 8/24
15978 	   We should have p_trip_incl_stops sorted by planned arrival date
15979 	   p_trip_incl_stops is IN RECORD  record
15980 	   Need to make a local record structure l_trip_incl_stops_sort for this purpose
15981 	*/
15982 
15983 	sort_stop_table_asc(
15984 	   p_stop_table	   => p_trip_incl_stops,
15985 	   x_sort_stop_table => l_trip_incl_stops_sort,
15986 	   x_return_status   => l_return_status);
15987 
15988 	IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15989 	  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15990 	    raise FND_API.G_EXC_UNEXPECTED_ERROR;
15991 	  END IF;
15992     	END IF;
15993 
15994 	-- l := p_trip_incl_stops.FIRST;
15995   	l := l_trip_incl_stops_sort.FIRST;
15996 
15997 	LOOP
15998            -- AGDUMMY
15999            -- Sort them in terms of planned_arrival_date
16000 	   -- l_trip_incl_stops(l) := p_trip_incl_stops(l);
16001 
16002 	   l_trip_incl_stops(l) := l_trip_incl_stops_sort(l);
16003 	   --#DUM_LOC(S)
16004 	   -- IF (p_trip_incl_stops(l).physical_location_id IS NOT NULL)  THEN
16005 	   IF (l_trip_incl_stops_sort(l).physical_location_id IS NOT NULL)  THEN
16006 		 l_trip_incl_stops(l).stop_location_id := l_trip_incl_stops(l).physical_location_id;
16007 	   END IF;
16008 	   --#DUM_LOC(E)
16009  	   -- EXIT WHEN l = p_trip_incl_stops.LAST;
16010            -- l := p_trip_incl_stops.NEXT(l);
16011 
16012 	   EXIT WHEN l = l_trip_incl_stops_sort.LAST;
16013 	   l := l_trip_incl_stops_sort.NEXT(l);
16014 	END LOOP;
16015 
16016     END IF;
16017     --SBAKSHI 8/24 (E)
16018 
16019     -- Only for action code = UPT
16020     -- Can update trip's carrier , mode, vehicle
16021 
16022     -- Need to check FAC - CAR,MOD    ITM - CAR,MOD
16023 
16024     --LOOP  -- Over input trips
16025     j := p_trip_info.FIRST;
16026     IF j IS NOT NULL THEN
16027       LOOP
16028 
16029         l_validate_faccar_result := 'S';
16030         l_validate_facmod_result := 'S';
16031         l_validate_facveh_result := 'S';
16032         l_validate_itmcar_result := 'S';
16033         l_validate_itmmod_result := 'S';
16034         l_validate_itmveh_result := 'S';
16035         l_validate_mode_result   := 'S';
16036         l_validate_carrier_result := 'S';
16037         l_validate_vehicle_result := 'S';
16038         l_validate_in_result := 'S';
16039         l_validate_ex_result := 'S';
16040         l_curr_trip_added := FALSE;
16041         l_carrier         := NULL;
16042         l_mode            := NULL;
16043         l_service_level   := NULL;
16044         l_vehicle_type    := NULL;
16045 
16046         IF (p_trip_info(j).carrier_id IS NULL OR p_trip_info(j).mode_of_transport IS NULL) AND
16047            (p_trip_info(j).ship_method_code IS NOT NULL) THEN
16048 
16049           l_carrier_service_inout_rec.ship_method_code := p_trip_info(j).ship_method_code;
16050           WSH_CARRIERS_GRP.get_carrier_service_mode(
16051                    p_carrier_service_inout_rec   =>  l_carrier_service_inout_rec,
16052                    x_return_status       =>  l_return_status);
16053 
16054           IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16055             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16056              IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
16057                 raise FND_API.G_EXC_UNEXPECTED_ERROR;
16058              END IF;
16059              raise g_get_carrmode_failed;
16060             END IF;
16061           END IF;
16062           l_carrier := l_carrier_service_inout_rec.carrier_id;
16063           l_mode    := l_carrier_service_inout_rec.mode_of_transport;
16064 
16065         END IF; -- p_trip_info(j).carrier_id IS NULL OR ..
16066 
16067         -- If carrier_id or mode is passed in, then those get preference for validation
16068         -- If they are not, they are derived from ship method if that is passed
16069 
16070         IF p_trip_info(j).carrier_id IS NOT NULL THEN
16071            l_carrier := p_trip_info(j).carrier_id;
16072         END IF;
16073         IF p_trip_info(j).mode_of_transport IS NOT NULL THEN
16074            l_mode := p_trip_info(j).mode_of_transport;
16075         END IF;
16076 
16077         IF (p_trip_info(j).VEHICLE_ITEM_ID IS NOT NULL AND p_trip_info(j).VEHICLE_ORGANIZATION_ID IS NOT NULL) THEN
16078 
16079           WSH_FTE_INTEGRATION.get_vehicle_type(
16080                    p_vehicle_item_id     =>  p_trip_info(j).VEHICLE_ITEM_ID,
16081                    p_vehicle_org_id      =>  p_trip_info(j).VEHICLE_ORGANIZATION_ID,
16082                    x_vehicle_type_id     =>  l_vehicle_type,
16083                    x_return_status       =>  l_return_status);
16084 
16085           IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16086              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16087               IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
16088                 raise FND_API.G_EXC_UNEXPECTED_ERROR;
16089               END IF;
16090                l_vehicle_name := WSH_UTIL_CORE.get_item_name (p_item_id => p_trip_info(j).VEHICLE_ITEM_ID,
16091                                                            p_organization_id => p_trip_info(j).VEHICLE_ORGANIZATION_ID);
16092                l_vehicle_org_name := WSH_UTIL_CORE.get_org_name (p_organization_id => p_trip_info(j).VEHICLE_ORGANIZATION_ID);
16093                FND_MESSAGE.SET_NAME('WSH','WSH_VEHICLE_TYPE_UNDEFINED');
16094                FND_MESSAGE.SET_TOKEN('ITEM',l_vehicle_name);
16095                FND_MESSAGE.SET_TOKEN('ORGANIZATION',l_vehicle_org_name);
16096                FND_MSG_PUB.ADD;
16097               --raise g_get_vehicletype_failed;
16098              END IF;
16099           END IF;
16100 
16101         END IF; -- p_trip_info(j).VEHICLE_ITEM_ID IS NOT NULL AND ..
16102 
16103 
16104         --LOOP  -- Over each stop of this input trip
16105         k := l_trip_incl_stops.FIRST;
16106         IF k IS NOT NULL THEN
16107           LOOP
16108 
16109         -- AGDUMMY
16110         -- If for a trip,
16111         -- a dummy stop has already been checked, then
16112         -- any other stop in that trip that
16113         -- has the stop_location_id same as that of the physical_location_id of the already checked
16114         -- dummy stop, should not be checked.
16115 
16116         -- When ordered by planned_arrival_date, these two stops would come sequentially
16117         -- one exactly after the other always - wrudge 8/20/04
16118 
16119         -- Need to consider Facility - Vehicle and Item - Vehicle as well
16120 
16121             IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) THEN
16122 
16123                check_inclusive_object2(
16124                  p_comp_class_code          =>      G_FACILITY_MODE,
16125                  p_entity_type              =>      G_TRIP,
16126                  p_entity_id                =>      p_trip_info(j).trip_id,
16127                  p_object1_type             =>      'FAC',
16128                  p_object1_val_num          =>      l_trip_incl_stops(k).stop_location_id,
16129                  p_object2_type             =>      'MOD',
16130                  p_object2_val_char         =>      l_mode,
16131                  x_out_object2_num          =>      l_out_object2_num,
16132                  x_out_object2_char         =>      l_out_object2_char,
16133                  x_validate_result          =>      l_validate_mode_result,
16134                  x_failed_constraint        =>      l_failed_constraints,
16135                  x_return_status            =>      l_return_status);
16136 
16137                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16138                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16139                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16140                   END IF;
16141                END IF;
16142 
16143                IF l_validate_mode_result = 'F' THEN
16144                   l_validate_in_result := 'E';
16145                END IF;
16146 
16147             END IF;
16148 
16149             IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) THEN
16150 
16151                check_inclusive_object2(
16152                  p_comp_class_code          =>      G_FACILITY_CARRIER,
16153                  p_entity_type              =>      G_TRIP,
16154                  p_entity_id                =>      p_trip_info(j).trip_id,
16155                  p_object1_type             =>      'FAC',
16156                  p_object1_val_num          =>      l_trip_incl_stops(k).stop_location_id,
16157                  p_object2_type             =>      'CAR',
16158                  p_object2_val_num          =>      l_carrier,
16159                  x_out_object2_num          =>      l_out_object2_num,
16160                  x_out_object2_char         =>      l_out_object2_char,
16161                  x_validate_result          =>      l_validate_carrier_result,
16162                  x_failed_constraint        =>      l_failed_constraints,
16163                  x_return_status            =>      l_return_status);
16164 
16165                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16166                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16167                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16168                   END IF;
16169                END IF;
16170 
16171                IF l_validate_carrier_result = 'F' THEN
16172                   l_validate_in_result := 'E';
16173                END IF;
16174 
16175             END IF;
16176 
16177             IF l_comp_class_tab.EXISTS(G_FACILITY_VEHICLE_NUM) THEN
16178 
16179                check_inclusive_object2(
16180                  p_comp_class_code          =>      G_FACILITY_VEHICLE,
16181                  p_entity_type              =>      G_TRIP,
16182                  p_entity_id                =>      p_trip_info(j).trip_id,
16183                  p_object1_type             =>      'FAC',
16184                  p_object1_val_num          =>      l_trip_incl_stops(k).stop_location_id,
16185                  p_object2_type             =>      'VHT',
16186                  p_object2_val_num          =>      l_vehicle_type,
16187                  x_out_object2_num          =>      l_out_object2_num,
16188                  x_out_object2_char         =>      l_out_object2_char,
16189                  x_validate_result          =>      l_validate_vehicle_result,
16190                  x_failed_constraint        =>      l_failed_constraints,
16191                  x_return_status            =>      l_return_status);
16192 
16193                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16194                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16195                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16196                   END IF;
16197                END IF;
16198 
16199                IF l_validate_vehicle_result = 'F' THEN
16200                   l_validate_in_result := 'E';
16201                END IF;
16202 
16203             END IF;
16204 
16205             IF l_validate_in_result = 'E' THEN
16206                EXIT;
16207             END IF;
16208 
16209              -- Validate FAC - CAR  FAC - MOD against the stop locations
16210 	     -- Need to consider Facility - Vehicle
16211 
16212             IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) THEN
16213 
16214                validate_constraint(
16215                  p_comp_class_code          =>      G_FACILITY_CARRIER,
16216                  p_object1_type             =>      'FAC',
16217                  p_object1_val_num          =>      l_trip_incl_stops(k).stop_location_id,
16218                  p_object2_type             =>      'CAR',
16219                  p_object2_val_num          =>      l_carrier,
16220                  x_validate_result          =>      l_validate_faccar_result,
16221                  x_failed_constraint        =>      l_failed_constraint,
16222                  x_return_status            =>      l_return_status);
16223 
16224                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16225                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16226                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16227                   END IF;
16228                END IF;
16229 
16230                IF l_validate_faccar_result <> 'S' THEN
16231                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
16232                   l_failed_constraint.entity_type :=  G_TRIP;
16233                   l_failed_constraint.entity_line_id :=  p_trip_info(j).trip_id;
16234                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
16235                   IF l_validate_faccar_result = 'E' THEN
16236                      l_validate_ex_result := 'E';
16237                   END IF;
16238                END IF;
16239 
16240             END IF;
16241 
16242             IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) THEN
16243 
16244                validate_constraint(
16245                  p_comp_class_code          =>      G_FACILITY_MODE,
16246                  p_object1_type             =>      'FAC',
16247                  p_object1_val_num          =>      l_trip_incl_stops(k).stop_location_id,
16248                  p_object2_type             =>      'MOD',
16249                  p_object2_val_char         =>      l_mode,
16250                  x_validate_result          =>      l_validate_facmod_result,
16251                  x_failed_constraint        =>      l_failed_constraint,
16252                  x_return_status            =>      l_return_status);
16253 
16254                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16255                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16256                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16257                   END IF;
16258                END IF;
16259 
16260                IF l_validate_facmod_result <> 'S' THEN
16261                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
16262                   l_failed_constraint.entity_type :=  G_TRIP;
16263                   l_failed_constraint.entity_line_id :=  p_trip_info(j).trip_id;
16264                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
16265                   IF l_validate_facmod_result = 'E' THEN
16266                      l_validate_ex_result := 'E';
16267                   END IF;
16268                END IF;
16269 
16270             END IF;
16271 
16272             IF l_comp_class_tab.EXISTS(G_FACILITY_VEHICLE_NUM) THEN
16273 
16274                validate_constraint(
16275                  p_comp_class_code          =>      G_FACILITY_VEHICLE,
16276                  p_object1_type             =>      'FAC',
16277                  p_object1_val_num          =>      l_trip_incl_stops(k).stop_location_id,
16278                  p_object2_type             =>      'VHT',
16279                  p_object2_val_num          =>      l_vehicle_type,
16280                  x_validate_result          =>      l_validate_facveh_result,
16281                  x_failed_constraint        =>      l_failed_constraint,
16282                  x_return_status            =>      l_return_status);
16283 
16284                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16285                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16286                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16287                   END IF;
16288                END IF;
16289 
16290                IF l_validate_facveh_result <> 'S' THEN
16291                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
16292                   l_failed_constraint.entity_type :=  G_TRIP;
16293                   l_failed_constraint.entity_line_id :=  p_trip_info(j).trip_id;
16294                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
16295                   IF l_validate_facveh_result = 'E' THEN
16296                      l_validate_ex_result := 'E';
16297                   END IF;
16298                END IF;
16299 
16300             END IF;
16301 
16302             <<next_stop>>
16303 
16304             EXIT WHEN k = l_trip_incl_stops.LAST;
16305 
16306 	    l_idx := k ;
16307 	    k	  := l_trip_incl_stops.NEXT(k);
16308 
16309 	    --SBAKSHI(8/24) (S)
16310 	    --Check can be put here,in case the next record is the physical stop,
16311 	    --then move two times, Skip the record over here.
16312 	    --Pseudo code -  IF both locations are specified then
16313             -- TODO Should we use physical_stop_id ?
16314 
16315 	    IF (l_trip_incl_stops(k).trip_id = l_trip_incl_stops(l_idx).trip_id
16316 		     AND
16317 		l_trip_incl_stops(k).stop_location_id=l_trip_incl_stops(l_idx).physical_location_id)
16318 	    THEN
16319 
16320 		--
16321 		--Current record is for the physical location, we need to skip it .
16322 		--In case it is the last record we need to exit,otherwise skip.
16323 		--
16324 
16325 		IF (k = l_trip_incl_stops.LAST) THEN
16326 			EXIT ;
16327 		ELSE
16328 			k:= l_trip_incl_stops.NEXT(k);
16329 		END IF;
16330 
16331 	    END IF;
16332 	    --SBAKSHI(8/24) (E)
16333 
16334 	  END LOOP;
16335 
16336 	END IF;
16337 
16338         IF l_validate_ex_result = 'E' OR l_validate_in_result = 'E' THEN
16339 
16340            x_validate_result := 'F';
16341            x_fail_trips(x_fail_trips.COUNT+1) := p_trip_info(j).trip_id;
16342            l_curr_trip_added := TRUE;
16343            l_validate_in_result := 'S';
16344            l_validate_ex_result := 'S';
16345            --
16346            IF l_debug_on THEN
16347              WSH_DEBUG_SV.logmsg(l_module_name,'Added failed trip because of stops : '|| p_trip_info(j).trip_id);
16348            END IF;
16349            --
16350         END IF;
16351 
16352         --LOOP -- over each dlvy line of this input trip
16353         l := l_trip_dlvy_lines.FIRST;
16354         IF l IS NOT NULL THEN
16355           LOOP
16356 
16357           -- Need to skip an Inbound delivery line
16358           -- if the trip's status is "In Transit" or "Closed"
16359 
16360             --IF p_trip_info(j).STATUS_CODE IN ('IT','CL') AND
16361             IF l_trip_dlvy_lines(l).released_status IN ('C','L') AND
16362                l_trip_dlvy_lines(l).line_direction = 'I' THEN
16363                GOTO line_nextpass;
16364             END IF;
16365 
16366         -- Need to consider Item - Vehicle
16367 
16368             IF l_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) THEN
16369 
16370                check_inclusive_object2(
16371                  p_comp_class_code          =>      G_ITEM_MODE,
16372                  p_entity_type              =>      G_DEL_DETAIL,
16373                  p_entity_id                =>      l_trip_dlvy_lines(l).delivery_detail_id,
16374                  p_object1_type             =>      'ITM',
16375                  p_object1_parent_id        =>      l_trip_dlvy_lines(l).organization_id,
16376                  p_object1_val_num          =>      l_trip_dlvy_lines(l).inventory_item_id,
16377                  p_object2_type             =>      'MOD',
16378                  p_object2_val_char         =>      l_mode,
16379                  x_out_object2_num          =>      l_out_object2_num,
16380                  x_out_object2_char         =>      l_out_object2_char,
16381                  x_validate_result          =>      l_validate_mode_result,
16382                  x_failed_constraint        =>      l_failed_constraints,
16383                  x_return_status            =>      l_return_status);
16384 
16385                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16386                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16387                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16388                   END IF;
16389                END IF;
16390 
16391                IF l_validate_mode_result = 'F' THEN
16392                   l_validate_in_result := 'E';
16393                END IF;
16394 
16395             END IF;
16396 
16397             IF l_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) THEN
16398 
16399                check_inclusive_object2(
16400                  p_comp_class_code          =>      G_ITEM_CARRIER,
16401                  p_entity_type              =>      G_DEL_DETAIL,
16402                  p_entity_id                =>      l_trip_dlvy_lines(l).delivery_detail_id,
16403                  p_object1_type             =>      'ITM',
16404                  p_object1_parent_id        =>      l_trip_dlvy_lines(l).organization_id,
16405                  p_object1_val_num          =>      l_trip_dlvy_lines(l).inventory_item_id,
16406                  p_object2_type             =>      'CAR',
16407                  p_object2_val_num          =>      l_carrier,
16408                  x_out_object2_num          =>      l_out_object2_num,
16409                  x_out_object2_char         =>      l_out_object2_char,
16410                  x_validate_result          =>      l_validate_carrier_result,
16411                  x_failed_constraint        =>      l_failed_constraints,
16412                  x_return_status            =>      l_return_status);
16413 
16414                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16415                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16416                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16417                   END IF;
16418                END IF;
16419 
16420                IF l_validate_carrier_result = 'F' THEN
16421                   l_validate_in_result := 'E';
16422                END IF;
16423 
16424             END IF;
16425 
16426             IF l_comp_class_tab.EXISTS(G_ITEM_VEHICLE_NUM) THEN
16427 
16428                check_inclusive_object2(
16429                  p_comp_class_code          =>      G_ITEM_VEHICLE,
16430                  p_entity_type              =>      G_DEL_DETAIL,
16431                  p_entity_id                =>      l_trip_dlvy_lines(l).delivery_detail_id,
16432                  p_object1_type             =>      'ITM',
16433                  p_object1_parent_id        =>      l_trip_dlvy_lines(l).organization_id,
16434                  p_object1_val_num          =>      l_trip_dlvy_lines(l).inventory_item_id,
16435                  p_object2_type             =>      'VHT',
16436                  p_object2_val_num          =>      l_vehicle_type,
16437                  x_out_object2_num          =>      l_out_object2_num,
16438                  x_out_object2_char         =>      l_out_object2_char,
16439                  x_validate_result          =>      l_validate_vehicle_result,
16440                  x_failed_constraint        =>      l_failed_constraints,
16441                  x_return_status            =>      l_return_status);
16442 
16443                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16444                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16445                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16446                   END IF;
16447                END IF;
16448 
16449                IF l_validate_vehicle_result = 'F' THEN
16450                   l_validate_in_result := 'E';
16451                END IF;
16452 
16453             END IF;
16454 
16455             IF l_validate_in_result = 'E' THEN
16456                EXIT;
16457             END IF;
16458 
16459              -- Validate ITM - CAR  ITM - MOD against the items
16460     	     -- Need to consider Item - Vehicle
16461 
16462             IF l_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) THEN
16463 
16464                validate_constraint(   --  checks only negative constraints
16465                  p_comp_class_code          =>      G_ITEM_MODE,
16466                  p_object1_type             =>      'ITM',
16467                  p_object1_parent_id        =>      l_trip_dlvy_lines(l).organization_id,
16468                  p_object2_type             =>      'MOD',
16469                  p_object1_val_num          =>      l_trip_dlvy_lines(l).inventory_item_id,
16470                  p_object2_val_char         =>      l_mode,
16471                  x_validate_result          =>      l_validate_itmmod_result,
16472                  x_failed_constraint        =>      l_failed_constraint,  -- id
16473                  x_return_status            =>      l_return_status);
16474 
16475                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16476                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16477                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16478                   END IF;
16479                END IF;
16480 
16481                IF l_validate_itmmod_result <> 'S' THEN
16482                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
16483                   l_failed_constraint.entity_type :=  G_DEL_DETAIL;
16484                   l_failed_constraint.entity_line_id :=  l_trip_dlvy_lines(l).delivery_detail_id;
16485                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
16486                   IF l_validate_itmmod_result = 'E' THEN
16487                      l_validate_ex_result := 'E';
16488                   END IF;
16489                END IF;
16490 
16491             END IF;
16492 
16493             IF l_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) THEN
16494 
16495                validate_constraint(   --  checks only negative constraints
16496                  p_comp_class_code          =>      G_ITEM_CARRIER,
16497                  p_object1_type             =>      'ITM',
16498                  p_object1_parent_id        =>      l_trip_dlvy_lines(l).organization_id,
16499                  p_object2_type             =>      'CAR',
16500                  p_object1_val_num          =>      l_trip_dlvy_lines(l).inventory_item_id,
16501                  p_object2_val_num          =>      l_carrier,
16502                  x_validate_result          =>      l_validate_itmcar_result,
16503                  x_failed_constraint        =>      l_failed_constraint,  -- id
16504                  x_return_status            =>      l_return_status);
16505 
16506                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16507                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16508                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16509                   END IF;
16510                END IF;
16511 
16512                IF l_validate_itmcar_result <> 'S' THEN
16513                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
16514                   l_failed_constraint.entity_type :=  G_DEL_DETAIL;
16515                   l_failed_constraint.entity_line_id :=  l_trip_dlvy_lines(l).delivery_detail_id;
16516                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
16517                   IF l_validate_itmcar_result = 'E' THEN
16518                      l_validate_ex_result := 'E';
16519                   END IF;
16520                END IF;
16521 
16522             END IF;
16523 
16524             IF l_comp_class_tab.EXISTS(G_ITEM_VEHICLE_NUM) THEN
16525 
16526                validate_constraint(   --  checks only negative constraints
16527                  p_comp_class_code          =>      G_ITEM_VEHICLE,
16528                  p_object1_type             =>      'ITM',
16529                  p_object1_parent_id        =>      l_trip_dlvy_lines(l).organization_id,
16530                  p_object2_type             =>      'VHT',
16531                  p_object1_val_num          =>      l_trip_dlvy_lines(l).inventory_item_id,
16532                  p_object2_val_num          =>      l_vehicle_type,
16533                  x_validate_result          =>      l_validate_itmveh_result,
16534                  x_failed_constraint        =>      l_failed_constraint,  -- id
16535                  x_return_status            =>      l_return_status);
16536 
16537                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16538                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16539                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16540                   END IF;
16541                END IF;
16542 
16543                IF l_validate_itmveh_result <> 'S' THEN
16544                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
16545                   l_failed_constraint.entity_type :=  G_DEL_DETAIL;
16546                   l_failed_constraint.entity_line_id :=  l_trip_dlvy_lines(l).delivery_detail_id;
16547                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
16548                   IF l_validate_itmveh_result = 'E' THEN
16549                      l_validate_ex_result := 'E';
16550                   END IF;
16551                END IF;
16552 
16553             END IF;
16554 
16555             <<line_nextpass>>
16556 
16557             EXIT WHEN l = l_trip_dlvy_lines.LAST;
16558             l := l_trip_dlvy_lines.NEXT(l);
16559 
16560           END LOOP;
16561         END IF;
16562 
16563         IF l_validate_in_result = 'E' OR l_validate_ex_result = 'E' THEN
16564 
16565            x_validate_result := 'F';
16566            IF NOT l_curr_trip_added THEN
16567              x_fail_trips(x_fail_trips.COUNT+1) := p_trip_info(j).trip_id;
16568              --
16569              IF l_debug_on THEN
16570                WSH_DEBUG_SV.logmsg(l_module_name,'Added failed trip because of items : '|| p_trip_info(j).trip_id);
16571              END IF;
16572              --
16573            END IF;
16574 
16575         END IF;
16576 
16577         EXIT WHEN j = p_trip_info.LAST;
16578         j := p_trip_info.NEXT(j);
16579 
16580       END LOOP;
16581     END IF;
16582 
16583     stack_messages (
16584              p_failed_constraints       => l_failed_constraints,
16585              x_msg_count                => x_msg_count,
16586              x_msg_data                 => x_msg_data,
16587              x_return_status            => l_return_status);
16588 
16589     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16590          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16591             raise FND_API.G_EXC_UNEXPECTED_ERROR;
16592          END IF;
16593     END IF;
16594 
16595     IF x_validate_result = 'F' THEN
16596         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
16597     ELSIF l_failed_constraints.COUNT > 0 THEN
16598         x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
16599     END IF;
16600 
16601     --
16602     IF l_debug_on THEN
16603       WSH_DEBUG_SV.logmsg(l_module_name,'failed trip count : '|| x_fail_trips.COUNT);
16604       WSH_DEBUG_SV.pop(l_module_name);
16605     END IF;
16606     --
16607 
16608 EXCEPTION
16609     WHEN g_get_carrmode_failed THEN
16610       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
16611       --
16612       IF l_debug_on THEN
16613         WSH_DEBUG_SV.pop(l_module_name,' get carrier-mode failed ');
16614       END IF;
16615       --
16616     WHEN g_get_vehicletype_failed THEN
16617       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
16618       --
16619       IF l_debug_on THEN
16620         WSH_DEBUG_SV.pop(l_module_name,' get vehicletype failed ');
16621       END IF;
16622       --
16623     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
16624       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
16625       --
16626       IF l_debug_on THEN
16627         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
16628         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
16629       END IF;
16630       --
16631     WHEN others THEN
16632       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.validate_constraint_trip');
16633       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
16634       --
16635       IF l_debug_on THEN
16636         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
16637         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
16638       END IF;
16639       --
16640 END validate_constraint_trip;
16641 
16642 
16643 --***************************************************************************
16644 --
16645 --========================================================================
16646 -- PROCEDURE : validate_constraint_stop    Called by constraint Wrapper API
16647 --                                         and the Group API.
16648 --
16649 -- PARAMETERS: p_init_msg_list             FND_API.G_TRUE to reset list
16650 --             p_action_code               Predefined action code
16651 --             p_exception_list            Compatibility classes to skip if any
16652 --                                         indexed by class code numbers
16653 --             p_stop_info                 Table of Stop records to process
16654 --             p_parent_trip_info          Table of Parent Trip records
16655 --                                         If not passed, the API will query
16656 --             x_fail_stops                Table of input stops that failed constraint check
16657 --             x_validate_result           Constraint Validation result : S / F
16658 --             x_msg_count                 Number of messages in the list
16659 --             x_msg_data                  Text of messages
16660 --             x_return_status             Return status
16661 -- COMMENT   : This procedure is used to perform for following actions
16662 --             A. Create a new stop ( CTS)
16663 --             B. Update an existing stop (UPS)
16664 --             C. Delete a stop (DTS)
16665 --========================================================================
16666 
16667 --Changes for DUM_LOC
16668 --Modified table p_stop_info in the beginning to get physical locations for dummy locations.
16669 
16670 
16671 PROCEDURE validate_constraint_stop(
16672              p_init_msg_list            IN	         VARCHAR2 DEFAULT fnd_api.g_false,
16673              p_action_code              IN	         VARCHAR2 DEFAULT NULL,
16674              p_exception_list           IN	         WSH_UTIL_CORE.Column_Tab_Type,
16675              p_stop_info                IN               stop_ccinfo_tab_type,
16676              p_parent_trip_info         IN	         trip_ccinfo_tab_type,
16677              x_fail_stops               OUT NOCOPY       WSH_UTIL_CORE.id_tab_type,
16678              x_validate_result          OUT NOCOPY       VARCHAR2,
16679              x_msg_count                OUT NOCOPY       NUMBER,
16680              x_msg_data                 OUT NOCOPY       VARCHAR2,
16681              x_return_status            OUT NOCOPY       VARCHAR2)
16682 IS
16683 
16684     CURSOR c_gettripdetails (l_stop_id IN NUMBER) is
16685     SELECT wt.TRIP_ID, 'Y'as exists_in_database, wt.NAME, wt.PLANNED_FLAG, wt.STATUS_CODE, wt.VEHICLE_ITEM_ID, wt.VEHICLE_NUMBER,
16686     wt.CARRIER_ID, wt.SHIP_METHOD_CODE, wt.VEHICLE_ORGANIZATION_ID, wt.VEHICLE_NUM_PREFIX, wt.SERVICE_LEVEL,
16687     wt.MODE_OF_TRANSPORT
16688     FROM wsh_trips wt, wsh_trip_stops wts
16689     WHERE wts.stop_id = l_stop_id
16690     AND   wts.trip_id=  wt.trip_id;
16691 
16692     CURSOR c_gettripinfo (l_trip_id IN NUMBER) is
16693     SELECT wt.TRIP_ID, 'Y'as exists_in_database, wt.NAME, wt.PLANNED_FLAG, wt.STATUS_CODE, wt.VEHICLE_ITEM_ID, wt.VEHICLE_NUMBER,
16694     wt.CARRIER_ID, wt.SHIP_METHOD_CODE, wt.VEHICLE_ORGANIZATION_ID, wt.VEHICLE_NUM_PREFIX, wt.SERVICE_LEVEL,
16695     wt.MODE_OF_TRANSPORT
16696     FROM wsh_trips wt
16697     WHERE wt.trip_id = l_trip_id;
16698 
16699     CURSOR c_get_dlvy_stops(c_delivery_id IN NUMBER,c_trip_id IN NUMBER) IS
16700     SELECT wts1.stop_sequence_number pickup_stop_seq,
16701            wts2.stop_sequence_number dropoff_stop_seq,
16702            wts1.planned_arrival_date pickup_stop_pa_date,
16703            wts2.planned_arrival_date dropoff_stop_pa_date
16704     FROM   wsh_new_deliveries wnd,
16705            wsh_delivery_legs wdl,
16706            wsh_trip_stops wts1,
16707            wsh_trip_stops wts2
16708     WHERE  wnd.delivery_id = c_delivery_id
16709     AND    wdl.delivery_id = wnd.delivery_id
16710     AND    wdl.pick_up_stop_id = wts1.stop_id
16711     AND    wdl.drop_off_stop_id = wts2.stop_id
16712     AND    wts1.trip_id = c_trip_id;
16713 
16714     z                                   NUMBER := 0;
16715     j                                   NUMBER := 0;
16716     k                                   NUMBER := 0;
16717     l                                   NUMBER := 0;
16718     m                                   NUMBER := 0;
16719     q                                   NUMBER := 0;
16720     l_carrier                           NUMBER := NULL;
16721     l_vehicle_type                      NUMBER := NULL;
16722     l_mode                              VARCHAR2(30) := NULL;
16723     l_service_level                     VARCHAR2(30) := NULL;
16724     l_carrier_service_inout_rec         WSH_CARRIERS_GRP.Carrier_Service_InOut_Rec_Type;
16725     l_trips_cnt                         NUMBER := 0;
16726     l_trip_del_cnt                      NUMBER := 0;
16727     l_trip_detail_cnt                   NUMBER := 0;
16728     l_trip_stop_cnt                     NUMBER := 0;
16729     l_out_object2_num                   NUMBER:=0;
16730     l_out_object2_char                  VARCHAR2(30):=NULL;
16731     l_added_stop                        BOOLEAN := FALSE;
16732     l_return_status                     VARCHAR2(1);
16733     l_comp_class_tab                    WSH_UTIL_CORE.Column_Tab_Type;
16734     l_failed_constraint                 line_constraint_rec_type;
16735     l_failed_constraints                line_constraint_tab_type;
16736     l_failed_constraints_dummy          line_constraint_tab_type;
16737     l_validate_faccar_result            VARCHAR2(1) := 'S';
16738     l_validate_facmod_result            VARCHAR2(1) := 'S';
16739     l_validate_facveh_result            VARCHAR2(1) := 'S';
16740     l_validate_orgfac_result            VARCHAR2(1) := 'S';
16741     l_validate_cusfac_result            VARCHAR2(1) := 'S';
16742     l_validate_supfac_result            VARCHAR2(1) := 'S';
16743     l_validate_supfacin_result          VARCHAR2(1) := 'S';
16744     l_validate_cusfacin_result          VARCHAR2(1) := 'S';
16745     l_validate_itmfac_result            VARCHAR2(1) := 'S';
16746     l_validate_in_result                VARCHAR2(1) := 'S';
16747     l_validate_vehicle_result           VARCHAR2(1) := 'S';
16748     l_validate_carrier_result           VARCHAR2(1) := 'S';
16749     l_validate_mode_result              VARCHAR2(1) := 'S';
16750     l_validate_dlvy_result              VARCHAR2(1) := 'S';
16751     l_validate_dlvb_result              VARCHAR2(1) := 'S';
16752     l_parent_trip_info                  trip_ccinfo_tab_type ;
16753     l_trip_rec                          trip_ccinfo_rec_type;
16754     l_delivery_rec                      delivery_ccinfo_rec_type;
16755     l_detail_rec                        detail_ccinfo_rec_type;
16756     l_stop_rec                          stop_ccinfo_rec_type;
16757     l_trip_assigned_dels                delivery_ccinfo_tab_type;
16758     l_trip_dlvy_lines                   detail_ccinfo_tab_type;
16759     --l_trip_children_stops               stop_ccinfo_tab_type;
16760     l_pickup_stop_seq                   NUMBER     := 0;
16761     l_dropoff_stop_seq                  NUMBER     := 0;
16762     l_pu_pa_date                        DATE;
16763     l_do_pa_date                        DATE;
16764     l_sibling_locations                 WSH_UTIL_CORE.id_tab_type;
16765     l_old_stop_location_id              NUMBER     := NULL;
16766     l_old_stop_seq_num                  NUMBER     := -999;
16767     l_old_stop_pa_date                  DATE;
16768     l_mustuse_loc_id                    NUMBER     := NULL;
16769     l_vehicle_name                      VARCHAR2(2000);
16770     l_vehicle_org_name                  VARCHAR2(240);
16771 
16772     l_direct_shipment                   BOOLEAN := TRUE;
16773     l_num_dlegs                         NUMBER  := 0;
16774 
16775     --#DUM_LOC(S)
16776     l_physical_location_id		NUMBER;
16777     --#DUM_LOC(E)
16778 
16779     --SBAKSHI (8/24)
16780     l_idx				NUMBER;
16781     l_stop_info				stop_ccinfo_tab_type;
16782     --SBAKSHI (8/24)
16783 
16784     l_debug_on                          CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
16785     l_module_name                       CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'validate_constraint_stop';
16786 
16787 BEGIN
16788 
16789     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
16790     x_validate_result := 'S';
16791 
16792     g_itm_mustuse_cache.DELETE;
16793     g_itmloc_mustuse_cache.DELETE;
16794     g_itm_exclusive_cache.DELETE;
16795     g_fac_exclusive_cache.DELETE;
16796 
16797     IF FND_API.to_Boolean( p_init_msg_list ) THEN
16798          FND_MSG_PUB.initialize;
16799     END IF;
16800 
16801     IF l_debug_on THEN
16802        wsh_debug_sv.push(l_module_name);
16803        WSH_DEBUG_SV.logmsg(l_module_name,'p_init_msg_list : '||p_init_msg_list);
16804     END IF;
16805 
16806     refresh_cache(l_return_status);
16807 
16808     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16809          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16810             raise FND_API.G_EXC_UNEXPECTED_ERROR;
16811          END IF;
16812     END IF;
16813 
16814     IF NOT p_exception_list.EXISTS(G_FACILITY_MODE_NUM) THEN
16815       l_comp_class_tab(G_FACILITY_MODE_NUM) := G_FACILITY_MODE;
16816     END IF;
16817     IF NOT p_exception_list.EXISTS(G_FACILITY_CARRIER_NUM) THEN
16818       l_comp_class_tab(G_FACILITY_CARRIER_NUM) := G_FACILITY_CARRIER;
16819     END IF;
16820     IF NOT p_exception_list.EXISTS(G_FACILITY_VEHICLE_NUM) THEN
16821       l_comp_class_tab(G_FACILITY_VEHICLE_NUM) := G_FACILITY_VEHICLE;
16822     END IF;
16823     IF NOT p_exception_list.EXISTS(G_ITEM_FACILITY_NUM) THEN
16824       l_comp_class_tab(G_ITEM_FACILITY_NUM) := G_ITEM_FACILITY;
16825     END IF;
16826     IF NOT p_exception_list.EXISTS(G_SHIPORG_FACILITY_NUM) THEN
16827       l_comp_class_tab(G_SHIPORG_FACILITY_NUM) := G_SHIPORG_FACILITY;
16828     END IF;
16829     IF NOT p_exception_list.EXISTS(G_CUSTOMER_FACILITY_NUM) THEN
16830       l_comp_class_tab(G_CUSTOMER_FACILITY_NUM) := G_CUSTOMER_FACILITY;
16831     END IF;
16832     IF NOT p_exception_list.EXISTS(G_SUPPLIER_FACILITY_NUM) THEN
16833       l_comp_class_tab(G_SUPPLIER_FACILITY_NUM) := G_SUPPLIER_FACILITY;
16834     END IF;
16835 
16836     -- #LOC_DUM(S)
16837     -- Replacing dummy locations by physical locations.
16838     -- #LOC_DUM(E)
16839 
16840     -- AGDUMMY
16841     -- Rather use nvl(p_stop_info(itr).physical_location_id,p_stop_info(itr).stop_location_id) everywhere
16842     -- We do not want to loose p_stop_info(itr).stop_location_id
16843 
16844     -- AGDUMMY
16845     -- Let's create a local l_stop_info
16846     -- which will store the sorted (by planned_arrival_date) p_stop_info
16847     -- This is to skip the check for the physical stop if already a dummy has been checked
16848     -- when they both exist in the same trip
16849 
16850     -- When the input stop table contains a dummy stop, but not  the corresponding physical stop
16851     -- dummy stop will still be checked
16852     -- For the reverse case, there is no way to figure out this stop is a physical stop and hence
16853     -- validation will be performed for it
16854 
16855 
16856     -- AGDUMMY TODO
16857     -- Sort the table outside the LOOP
16858 
16859 	--SBAKSHI - Sorting the p_stop_info table.
16860       sort_stop_table_asc(
16861 	p_stop_table	  => p_stop_info,
16862 	x_sort_stop_table => l_stop_info,
16863 	x_return_status   => l_return_status);
16864 
16865     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16866 	  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16867 	    raise FND_API.G_EXC_UNEXPECTED_ERROR;
16868 	  END IF;
16869     END IF;
16870 
16871     IF p_parent_trip_info.COUNT = 0 THEN
16872 
16873      --Replacing p_stop_info by l_stop_info
16874      -- j := p_stop_info.FIRST;
16875      j := l_stop_info.FIRST;
16876 
16877      IF j IS NOT NULL THEN
16878       LOOP
16879          IF l_stop_info(j).stop_id IS NOT NULL AND p_action_code <> G_CRT_TRIP_STOP THEN
16880           OPEN c_gettripdetails(l_stop_info(j).stop_id);
16881           LOOP
16882                FETCH c_gettripdetails INTO l_trip_rec;
16883                EXIT WHEN c_gettripdetails%NOTFOUND;
16884                l_trips_cnt := l_trips_cnt + 1;
16885                l_parent_trip_info(l_trips_cnt) := l_trip_rec;
16886           END LOOP;
16887           CLOSE c_gettripdetails;
16888          ELSIF l_stop_info(j).trip_id IS NOT NULL THEN
16889           OPEN c_gettripinfo(l_stop_info(j).trip_id);
16890           LOOP
16891                FETCH c_gettripinfo INTO l_trip_rec;
16892                EXIT WHEN c_gettripinfo%NOTFOUND;
16893                l_trips_cnt := l_trips_cnt + 1;
16894                l_parent_trip_info(l_trips_cnt) := l_trip_rec;
16895           END LOOP;
16896           CLOSE c_gettripinfo;
16897          ELSE
16898           IF l_debug_on THEN
16899                WSH_DEBUG_SV.logmsg(l_module_name,'Input stop index - '||j||' has null stop_id and trip_id');
16900           END IF;
16901          END IF;
16902          EXIT WHEN j = l_stop_info.LAST;
16903          j := l_stop_info.NEXT(j);
16904       END LOOP;
16905      END IF;
16906     ELSIF p_parent_trip_info.COUNT <> 0 THEN
16907 
16908         l := p_parent_trip_info.FIRST;
16909         LOOP
16910            l_parent_trip_info(l) := p_parent_trip_info(l);
16911            EXIT WHEN l = p_parent_trip_info.LAST;
16912            l := p_parent_trip_info.NEXT(l);
16913         END LOOP;
16914 
16915     END IF;
16916 
16917 
16918     IF l_debug_on THEN
16919         WSH_DEBUG_SV.logmsg(l_module_name,'Input stop count : '||l_stop_info.COUNT);
16920         WSH_DEBUG_SV.logmsg(l_module_name,'parent trip count : '||p_parent_trip_info.COUNT||' local trip count : '||l_parent_trip_info.COUNT);
16921     END IF;
16922 
16923     -- Only for action code = UPS
16924     -- Also create CTS, DTS
16925     -- Can update stop's location , planned arrival date
16926     -- Can't update stop location if any delivery is present
16927 
16928     --LOOP  -- Over input stops
16929     j := l_stop_info.FIRST;
16930     IF j IS NOT NULL THEN
16931 
16932      LOOP
16933 
16934       l_added_stop := FALSE;
16935       l_validate_faccar_result   := 'S';
16936       l_validate_facveh_result   := 'S';
16937       l_validate_facmod_result   := 'S';
16938       l_validate_orgfac_result   := 'S';
16939       l_validate_cusfac_result   := 'S';
16940       l_validate_supfac_result   := 'S';
16941       l_validate_cusfacin_result := 'S';
16942       l_validate_supfacin_result := 'S';
16943       l_validate_itmfac_result   := 'S';
16944       l_validate_in_result       := 'S';
16945       l_validate_carrier_result  := 'S';
16946       l_validate_vehicle_result  := 'S';
16947       l_validate_mode_result     := 'S';
16948       l_validate_dlvy_result     := 'S';
16949       l_validate_dlvb_result     := 'S';
16950       l_old_stop_pa_date         := NULL;
16951 
16952       IF l_debug_on THEN
16953    	 WSH_DEBUG_SV.logmsg(l_module_name,'Input stop index : '||j||' stop id : '||l_stop_info(j).stop_id||' location : '||nvl(l_stop_info(j).physical_location_id,l_stop_info(j).stop_location_id)||
16954       ' Sequence : '||l_stop_info(j).stop_sequence_number||' trip id : '||l_stop_info(j).trip_id);
16955  	 WSH_DEBUG_SV.logmsg(l_module_name,'Planned arrival date : '||to_char(l_stop_info(j).planned_arrival_date,'DD-MON-YYYY HH24:MI:SS')||' Planned departure date : '||
16956          to_char(l_stop_info(j).planned_departure_date,'DD-MON-YYYY HH24:MI:SS'));
16957       END IF;
16958 
16959       -- AGDUMMY
16960       -- Skip this stop if it is the physical stop corresponding to
16961       -- an already processed dummy stop in the l_stop_info table
16962       -- TODO skip not done
16963 
16964       -- Fetch old data for the current stop
16965       -- if it is being updated
16966       -- this information will be required for inclusive constraint check
16967       -- related to stop sequence number update
16968 
16969       l_mustuse_loc_id := nvl(l_stop_info(j).physical_location_id,l_stop_info(j).stop_location_id);
16970 
16971       IF p_action_code = G_UPDATE_STOP THEN
16972          -- Changes made in cursor c_get_stop_location.
16973 	 -- To ensure dummy locations are replaced by physical locations.
16974 
16975 	 OPEN  c_get_stop_location(l_stop_info(j).stop_id);
16976          FETCH c_get_stop_location INTO l_old_stop_location_id, l_old_stop_seq_num,l_old_stop_pa_date;
16977 	 CLOSE c_get_stop_location;
16978 
16979 	 IF l_debug_on THEN
16980             WSH_DEBUG_SV.logmsg(l_module_name,'Input stop values before this update : location_id : '||l_old_stop_location_id||' seq_num : '||l_old_stop_seq_num||' Planned arrival date : '||to_char(l_old_stop_pa_date,'DD-MON-YYYY HH24:MI:SS'));
16981          END IF;
16982 
16983          l_mustuse_loc_id := l_old_stop_location_id;
16984 
16985       END IF;
16986 
16987       IF p_action_code <> G_DELETE_STOP THEN
16988 
16989        --LOOP  -- Over parent trips
16990        k := l_parent_trip_info.FIRST;
16991        IF k IS NOT NULL THEN
16992         LOOP
16993 
16994            IF l_debug_on THEN
16995              WSH_DEBUG_SV.logmsg(l_module_name,'For stop : '||l_stop_info(j).stop_id);
16996              WSH_DEBUG_SV.logmsg(l_module_name,'Stops trip : '||l_stop_info(j).trip_id);
16997              WSH_DEBUG_SV.logmsg(l_module_name,'Current Trip : '||l_parent_trip_info(k).trip_id);
16998            END IF;
16999 
17000            IF l_stop_info(j).trip_id <> l_parent_trip_info(k).trip_id THEN
17001                GOTO next_trip;
17002            END IF;
17003 
17004            l_carrier                   := NULL;
17005            l_mode                      := NULL;
17006            l_service_level             := NULL;
17007            l_vehicle_type              := NULL;
17008 
17009            IF (l_parent_trip_info(k).carrier_id IS NULL OR l_parent_trip_info(k).mode_of_transport IS NULL) AND
17010               (l_parent_trip_info(k).ship_method_code IS NOT NULL) THEN
17011 
17012               l_carrier_service_inout_rec.ship_method_code := l_parent_trip_info(k).ship_method_code;
17013 
17014 	      WSH_CARRIERS_GRP.get_carrier_service_mode(
17015                     p_carrier_service_inout_rec =>  l_carrier_service_inout_rec,
17016                     x_return_status		=>  l_return_status);
17017 
17018               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17019                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17020                   IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
17021                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
17022                   END IF;
17023                   raise g_get_carrmode_failed;
17024                  END IF;
17025               END IF;
17026 
17027 	      l_carrier := l_carrier_service_inout_rec.carrier_id;
17028               l_mode    := l_carrier_service_inout_rec.mode_of_transport;
17029 
17030            END IF; -- l_parent_trip_info(k).carrier_id IS NULL OR ..
17031 
17032            -- If carrier_id or mode is passed in, then those get preference for validation
17033            -- If they are not, they are derived from ship method if that is passed
17034 
17035            IF l_parent_trip_info(k).carrier_id IS NOT NULL THEN
17036               l_carrier := l_parent_trip_info(k).carrier_id;
17037            END IF;
17038 
17039 	   IF l_parent_trip_info(k).mode_of_transport IS NOT NULL THEN
17040               l_mode := l_parent_trip_info(k).mode_of_transport;
17041            END IF;
17042 
17043            IF (l_parent_trip_info(k).vehicle_item_id IS NOT NULL AND l_parent_trip_info(k).vehicle_organization_id IS NOT NULL) THEN
17044 
17045               WSH_FTE_INTEGRATION.get_vehicle_type(
17046                     p_vehicle_item_id     =>  l_parent_trip_info(k).vehicle_item_id,
17047                     p_vehicle_org_id      =>  l_parent_trip_info(k).vehicle_organization_id,
17048                     x_vehicle_type_id     =>  l_vehicle_type,
17049                     x_return_status       =>  l_return_status);
17050 
17051               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17052                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17053                  IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
17054                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
17055                  END IF;
17056                l_vehicle_name := WSH_UTIL_CORE.get_item_name (p_item_id => l_parent_trip_info(k).VEHICLE_ITEM_ID,
17057                                                            p_organization_id => l_parent_trip_info(k).VEHICLE_ORGANIZATION_ID);
17058                l_vehicle_org_name := WSH_UTIL_CORE.get_org_name (p_organization_id => l_parent_trip_info(k).VEHICLE_ORGANIZATION_ID);
17059                FND_MESSAGE.SET_NAME('WSH','WSH_VEHICLE_TYPE_UNDEFINED');
17060                FND_MESSAGE.SET_TOKEN('ITEM',l_vehicle_name);
17061                FND_MESSAGE.SET_TOKEN('ORGANIZATION',l_vehicle_org_name);
17062                FND_MSG_PUB.ADD;
17063                 END IF;
17064               END IF;
17065 
17066            END IF; -- l_parent_trip_info(k).VEHICLE_ITEM_ID IS NOT NULL AND ..
17067 
17068          -- Need to consider Facility - Vehicle
17069 
17070            IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) AND
17071                l_mode IS NOT NULL THEN
17072 
17073               check_inclusive_object2(
17074                   p_comp_class_code          =>      G_FACILITY_MODE,
17075                   p_entity_type              =>      G_TRIP,
17076                   p_entity_id                =>      l_parent_trip_info(k).trip_id,
17077                   p_object1_type             =>      'FAC',
17078                   p_object1_val_num          =>      nvl(l_stop_info(j).physical_location_id,l_stop_info(j).stop_location_id),
17079 		  p_object2_type             =>      'MOD',
17080                   p_object2_val_char         =>      l_mode,
17081                   x_out_object2_num          =>      l_out_object2_num,
17082                   x_out_object2_char         =>      l_out_object2_char,
17083                   x_validate_result          =>      l_validate_mode_result,
17084                   x_failed_constraint        =>      l_failed_constraints,
17085                   x_return_status            =>      l_return_status);
17086 
17087               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17088                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17089                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
17090                  END IF;
17091               END IF;
17092 
17093               IF l_validate_mode_result = 'F' THEN
17094                    l_validate_in_result := 'F';
17095               END IF;
17096 
17097            END IF;
17098 
17099            IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) AND
17100                l_carrier IS NOT NULL THEN
17101 
17102               check_inclusive_object2(
17103                   p_comp_class_code          =>     G_FACILITY_CARRIER,
17104                   p_entity_type              =>     G_TRIP,
17105                   p_entity_id                =>     l_parent_trip_info(k).trip_id,
17106                   p_object1_type             =>     'FAC',
17107                   p_object1_val_num          =>      nvl(l_stop_info(j).physical_location_id,l_stop_info(j).stop_location_id),
17108                   p_object2_type             =>     'CAR',
17109                   p_object2_val_num          =>     l_carrier,
17110                   x_out_object2_num          =>     l_out_object2_num,
17111                   x_out_object2_char         =>     l_out_object2_char,
17112                   x_validate_result          =>     l_validate_carrier_result,
17113                   x_failed_constraint        =>     l_failed_constraints,
17114                   x_return_status            =>     l_return_status);
17115 
17116               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17117                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17118                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
17119                  END IF;
17120               END IF;
17121 
17122               IF l_validate_carrier_result = 'F' THEN
17123                 l_validate_in_result := 'F';
17124               END IF;
17125 
17126            END IF;
17127 
17128            IF l_comp_class_tab.EXISTS(G_FACILITY_VEHICLE_NUM) AND
17129                l_vehicle_type IS NOT NULL THEN
17130 
17131               check_inclusive_object2(
17132                   p_comp_class_code          =>      G_FACILITY_VEHICLE,
17133                   p_entity_type              =>      G_TRIP,
17134                   p_entity_id                =>      l_parent_trip_info(k).trip_id,
17135                   p_object1_type             =>      'FAC',
17136                   p_object1_val_num          =>      nvl(l_stop_info(j).physical_location_id,l_stop_info(j).stop_location_id),
17137                   p_object2_type             =>      'VHT',
17138                   p_object2_val_num          =>      l_vehicle_type,
17139                   x_out_object2_num          =>      l_out_object2_num,
17140                   x_out_object2_char         =>      l_out_object2_char,
17141                   x_validate_result          =>      l_validate_vehicle_result,
17142                   x_failed_constraint        =>      l_failed_constraints,
17143                   x_return_status            =>      l_return_status);
17144 
17145               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17146                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17147                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
17148                  END IF;
17149               END IF;
17150 
17151               IF l_validate_vehicle_result = 'F' THEN
17152                  l_validate_in_result := 'F';
17153               END IF;
17154 
17155            END IF;
17156 
17157            IF l_validate_in_result = 'F' THEN
17158                 EXIT;
17159            END IF;
17160 
17161 
17162            -- Need to consider Facility - Vehicle
17163            -- Validate FAC - CAR  FAC - MOD, FAC - VEH for the stop locations
17164            -- against parent trip's carrier, mode, vehicle
17165 
17166            IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) AND
17167                l_carrier IS NOT NULL THEN
17168 
17169               validate_constraint(
17170                   p_comp_class_code          =>      G_FACILITY_CARRIER,
17171                   p_object1_type             =>      'FAC',
17172 		          p_object1_val_num          =>      nvl(l_stop_info(j).physical_location_id,l_stop_info(j).stop_location_id),
17173                   p_object2_type             =>      'CAR',
17174                   p_object2_val_num          =>      l_carrier,
17175                   x_validate_result          =>      l_validate_faccar_result,
17176                   x_failed_constraint        =>      l_failed_constraint,
17177                   x_return_status            =>      l_return_status);
17178 
17179               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17180                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17181                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
17182                END IF;
17183               END IF;
17184 
17185               IF l_validate_faccar_result <> 'S' THEN
17186                    l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
17187                    l_failed_constraint.entity_type :=  G_TRIP;
17188                    l_failed_constraint.entity_line_id :=  l_parent_trip_info(k).trip_id;
17189                    l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
17190               END IF;
17191 
17192            END IF;
17193 
17194            IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) AND
17195                l_mode IS NOT NULL THEN
17196 
17197               validate_constraint(
17198                   p_comp_class_code          =>      G_FACILITY_MODE,
17199                   p_object1_type             =>      'FAC',
17200                   p_object1_val_num          =>      nvl(l_stop_info(j).physical_location_id,l_stop_info(j).stop_location_id),
17201                   p_object2_type             =>      'MOD',
17202                   p_object2_val_char         =>      l_mode,
17203                   x_validate_result          =>      l_validate_facmod_result,
17204                   x_failed_constraint        =>      l_failed_constraint,
17205                   x_return_status            =>      l_return_status);
17206 
17207               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17208                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17209                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
17210                END IF;
17211               END IF;
17212 
17213               IF l_validate_facmod_result <> 'S' THEN
17214                    l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
17215                    l_failed_constraint.entity_type :=  G_TRIP;
17216                    l_failed_constraint.entity_line_id :=  l_parent_trip_info(k).trip_id;
17217                    l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
17218               END IF;
17219 
17220            END IF;
17221 
17222            IF l_comp_class_tab.EXISTS(G_FACILITY_VEHICLE_NUM) AND
17223                l_vehicle_type IS NOT NULL THEN
17224                --l_parent_trip_info(k).carrier_id IS NOT NULL THEN
17225 
17226               validate_constraint(
17227                   p_comp_class_code          =>      G_FACILITY_VEHICLE,
17228                   p_object1_type             =>      'FAC',
17229                   p_object1_val_num          =>      nvl(l_stop_info(j).physical_location_id,l_stop_info(j).stop_location_id),
17230                   p_object2_type             =>      'VHT',
17231                   p_object2_val_num          =>      l_vehicle_type,
17232                   x_validate_result          =>      l_validate_facveh_result,
17233                   x_failed_constraint        =>      l_failed_constraint,
17234                   x_return_status            =>      l_return_status);
17235 
17236               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17237                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17238                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
17239                 END IF;
17240               END IF;
17241 
17242               IF l_validate_facveh_result <> 'S' THEN
17243                    l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
17244                    l_failed_constraint.entity_type :=  G_TRIP;
17245                    l_failed_constraint.entity_line_id :=  l_parent_trip_info(k).trip_id;
17246                    l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
17247               END IF;
17248 
17249            END IF;
17250 
17251            IF l_validate_faccar_result = 'E' OR l_validate_facmod_result = 'E'  OR
17252               l_validate_facveh_result = 'E' THEN
17253 
17254               -- One stop has only one parent trip
17255               EXIT;
17256 
17257            END IF;
17258 
17259            -- What about manual deletion of a stop ?
17260            -- If the current input stop is the only 'must use' for org/cus/itm of dlvy/dlvb
17261            -- in parent trip, then prevent deletion;
17262            -- call modified validate_constraint with p_constraint_type = 'I'
17263            -- Returns 'S'/'W'/'E' between combinations sent to it
17264            -- if error (this location is must use), call
17265            --             check_inclusive_facilities for all other non pick/drop stops in this trip
17266            --             if success, proceed with deletion for the input stop
17267            --             else, prevent deletion of the input stop
17268            -- else, proceed with deletion for the input stop
17269            -- otherwise go ahead
17270               null;
17271 
17272            <<next_trip>>
17273 
17274            EXIT WHEN k = l_parent_trip_info.LAST;
17275            k := l_parent_trip_info.NEXT(k);
17276 
17277 	  END LOOP;
17278         END IF;
17279 
17280       END IF; -- p_action_code <> G_DELETE_STOP
17281 
17282 
17283       IF l_validate_carrier_result = 'F' OR l_validate_mode_result = 'F' OR
17284          l_validate_vehicle_result = 'F' OR
17285          l_validate_faccar_result = 'E' OR l_validate_facmod_result = 'E' OR
17286          l_validate_facveh_result = 'E'
17287 
17288       THEN
17289 
17290          x_validate_result := 'F';
17291          x_fail_stops(x_fail_stops.COUNT+1) := l_stop_info(j).stop_id;
17292          --
17293          IF l_debug_on THEN
17294             WSH_DEBUG_SV.logmsg(l_module_name,'Added failed stop : '|| l_stop_info(j).stop_id);
17295          END IF;
17296          --
17297 
17298       END IF;
17299 
17300       EXIT WHEN j = l_stop_info.LAST;
17301 
17302       l_idx := j;
17303       j     := l_stop_info.NEXT(j);
17304 
17305       --SBAKSHI(8/24) (S)
17306       --Check can be put here,in case the next record is the physical stop,
17307       --then move two times, Skip the record over here.
17308       -- TODO Should we use physical_stop_id ?
17309 
17310       IF (l_stop_info(j).trip_id = l_stop_info(l_idx).trip_id
17311 		 AND
17312 	  l_stop_info(j).stop_location_id=l_stop_info(l_idx).physical_location_id)
17313       THEN
17314 	--
17315 	--Current record is for the physical location, we need to advance further.
17316 	--In case we are at the last trip we need to exit,otherwise skip the record.
17317 	--
17318 
17319 	   IF (j = l_stop_info.LAST) THEN
17320 	         EXIT ;
17321 	   ELSE
17322 	        j:= l_stop_info.NEXT(j);
17323 	   END IF;
17324 
17325        END IF;
17326        --SBAKSHI(8/24) (E)
17327 
17328      END LOOP;
17329 
17330     END IF;
17331 
17332     stack_messages (
17333              p_failed_constraints       => l_failed_constraints,
17334              x_msg_count                => x_msg_count,
17335              x_msg_data                 => x_msg_data,
17336              x_return_status            => l_return_status);
17337 
17338     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17339          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17340             raise FND_API.G_EXC_UNEXPECTED_ERROR;
17341          END IF;
17342     END IF;
17343 
17344     IF x_validate_result = 'F' THEN
17345         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
17346     ELSIF
17347      l_failed_constraints.COUNT > 0 THEN
17348 
17349         x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
17350     END IF;
17351 
17352     --
17353     IF l_debug_on THEN
17354       WSH_DEBUG_SV.logmsg(l_module_name,'failed stop count : '|| x_fail_stops.COUNT);
17355       WSH_DEBUG_SV.pop(l_module_name);
17356     END IF;
17357     --
17358 
17359 EXCEPTION
17360     WHEN g_get_carrmode_failed THEN
17361       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
17362       --
17363       IF l_debug_on THEN
17364         WSH_DEBUG_SV.pop(l_module_name,' get carrier-mode failed ');
17365       END IF;
17366       --
17367     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
17368       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
17369       --
17370       IF l_debug_on THEN
17371         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
17372         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
17373       END IF;
17374       --
17375     WHEN others THEN
17376       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.validate_constraint_stop');
17377       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
17378       --
17379       IF l_debug_on THEN
17380         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
17381         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
17382       END IF;
17383       --
17384 END validate_constraint_stop;
17385 
17386 --***************************************************************************--
17387 --========================================================================
17388 -- PROCEDURE : validate_exclusive_constraints   PRIVATE
17389 --
17390 -- PARAMETERS: p_delivery_rec                   Input delivery record
17391 --             p_rule_deconsol_location         input location id to be validated
17392 --                                              against exclusive constraints
17393 --             x_validate_result                Constraint validation result
17394 --             x_return_status                  Return status
17395 -- COMMENT   : This procedure is used to perform for following actions
17396 --             Takes input delivery record and deconsol location id
17397 --             Checks if the input location it can be used as deconsol location
17398 --             Validate ALL exclusive discretionary routing point constraints
17399 --              1. Customer - Facility
17400 --              2. Region / Zone - Facility
17401 --              3. Organization - Facility
17402 --              4. Item - Facility
17403 --========================================================================
17404 
17405 PROCEDURE validate_exclusive_constraints(p_delivery_rec IN WSH_FTE_CONSTRAINT_FRAMEWORK.delivery_ccinfo_rec_type,
17406                                         p_rule_deconsol_location IN NUMBER,
17407                                         x_validate_result   OUT NOCOPY VARCHAR2,
17408                                         x_return_status     OUT NOCOPY VARCHAR2
17409 )
17410 
17411 IS
17412 l_validate_result           VARCHAR2(1) := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
17413 l_return_status             VARCHAR2(1) := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
17414 l_failed_constraint         WSH_FTE_CONSTRAINT_FRAMEWORK.line_constraint_rec_type;
17415 l_details_info              WSH_FTE_CONSTRAINT_FRAMEWORK.detail_ccinfo_tab_type;
17416 i_det                       NUMBER;
17417 l_module_name               CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'validate_exclusive_constraints';
17418 l_debug_on                  CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
17419 l_location_id               NUMBER;
17420 
17421 CURSOR c_get_details(c_delivery_id IN NUMBER) IS
17422 SELECT wdd.DELIVERY_DETAIL_ID
17423   , wda.DELIVERY_ID
17424   , 'Y'
17425   , wdd.CUSTOMER_ID
17426   , wdd.INVENTORY_ITEM_ID
17427   , wdd.SHIP_FROM_LOCATION_ID
17428   , wdd.ORGANIZATION_ID
17429   , wdd.SHIP_TO_LOCATION_ID
17430   , wdd.INTMED_SHIP_TO_LOCATION_ID
17431   , wdd.RELEASED_STATUS
17432   , wdd.CONTAINER_FLAG
17433   , wdd.DATE_REQUESTED
17434   , wdd.DATE_SCHEDULED
17435   , wdd.SHIP_METHOD_CODE
17436   , wdd.CARRIER_ID
17437   , wdd.PARTY_ID
17438   , nvl(wdd.LINE_DIRECTION,'O')
17439   , nvl(wdd.SHIPPING_CONTROL,'BUYER')
17440   , NULL
17441 FROM wsh_delivery_details wdd,
17442      wsh_delivery_assignments_v wda
17443 WHERE wdd.delivery_detail_id = wda.delivery_detail_id
17444 AND   nvl(wdd.shipping_control,'BUYER') <> 'SUPPLIER'
17445 AND   wda.delivery_id = c_delivery_id;
17446 
17447 BEGIN
17448 
17449     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
17450     x_validate_result := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
17451 
17452     IF l_debug_on THEN
17453       wsh_debug_sv.push (l_module_name);
17454     END IF;
17455 
17456     IF p_delivery_rec.ultimate_dropoff_location_id IS NOT NULL THEN
17457     --{
17458 
17459         IF l_debug_on THEN
17460             wsh_debug_sv.logmsg (l_module_name, 'p_delivery_rec.ultimate_dropoff_location_id: ' || p_delivery_rec.ultimate_dropoff_location_id);
17461             wsh_debug_sv.logmsg (l_module_name, 'p_rule_deconsol_location: '||p_rule_deconsol_location);
17462         END IF;
17463 
17464         validate_constraint(   --  checks only negative constraints
17465              p_comp_class_code          =>      WSH_FTE_CONSTRAINT_FRAMEWORK.G_CUSTOMER_FACILITY,
17466              p_object1_type             =>      'FAC',
17467              p_object2_type             =>      'FAC',
17468              p_object1_val_num          =>      p_delivery_rec.ultimate_dropoff_location_id,
17469              p_object1_physical_id      =>      p_delivery_rec.physical_dropoff_location_id,
17470              p_object2_val_num          =>      p_rule_deconsol_location,
17471              x_validate_result          =>      l_validate_result,
17472              x_failed_constraint        =>      l_failed_constraint,
17473              x_return_status            =>      l_return_status);
17474 
17475         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17476             raise FND_API.G_EXC_UNEXPECTED_ERROR;
17477         END IF;
17478 
17479 
17480         IF l_debug_on THEN
17481             wsh_debug_sv.logmsg (l_module_name, 'Customer FAC-FAC l_validate_result: '||l_validate_result);
17482         END IF;
17483 
17484         IF l_validate_result = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
17485             x_return_status := l_return_status;
17486             x_validate_result := l_validate_result;
17487 
17488             IF l_debug_on THEN
17489                 wsh_debug_sv.push(l_module_name);
17490                 wsh_debug_sv.log (l_module_name,'constraint id violated : ',to_char(l_failed_constraint.constraint_id));
17491                 wsh_debug_sv.log (l_module_name,'entity_type : ',to_char(l_failed_constraint.entity_type));
17492                 wsh_debug_sv.log (l_module_name,'constraint_class_code : ',to_char(l_failed_constraint.constraint_class_code));
17493                 wsh_debug_sv.log (l_module_name,'violation_type : ',to_char(l_failed_constraint.violation_type));
17494                 wsh_debug_sv.logmsg(l_module_name, 'Constraint Violation Error. Ship to Customer Location'||p_delivery_rec.ultimate_dropoff_location_id||' can not use '||p_rule_deconsol_location|| ' as deconsolidation location');
17495             END IF;
17496             IF l_debug_on THEN
17497                 wsh_debug_sv.pop (l_module_name);
17498             END IF;
17499             return;
17500         END IF;
17501 
17502     --}
17503     END IF; -- p_delivery_rec.ULTIMATE_DROPOFF_LOCATION_ID IS NOT NULL
17504 
17505     IF p_delivery_rec.customer_id IS NOT NULL THEN
17506     --{
17507         IF l_debug_on THEN
17508           wsh_debug_sv.logmsg (l_module_name, 'p_delivery_rec.customer_id: ' || p_delivery_rec.customer_id);
17509           wsh_debug_sv.logmsg (l_module_name, 'p_rule_deconsol_location: '||p_rule_deconsol_location);
17510         END IF;
17511 
17512         validate_constraint(   --  checks only negative constraints
17513          p_comp_class_code          =>      WSH_FTE_CONSTRAINT_FRAMEWORK.G_CUSTOMER_FACILITY,
17514          p_object1_type             =>      'CUS',
17515          p_object2_type             =>      'FAC',
17516          p_object1_val_num          =>      p_delivery_rec.customer_id,
17517          p_object2_val_num          =>      p_rule_deconsol_location,
17518          x_validate_result          =>      l_validate_result,
17519          x_failed_constraint        =>      l_failed_constraint,
17520          x_return_status            =>      l_return_status);
17521 
17522         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17523             raise FND_API.G_EXC_UNEXPECTED_ERROR;
17524         END IF;
17525 
17526         IF l_debug_on THEN
17527           wsh_debug_sv.logmsg (l_module_name, 'CUS-FAC l_validate_result: '||l_validate_result);
17528         END IF;
17529 
17530         IF l_validate_result = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
17531             x_return_status := l_return_status;
17532             x_validate_result := l_validate_result;
17533             IF l_debug_on THEN
17534                 wsh_debug_sv.push(l_module_name);
17535                 wsh_debug_sv.log (l_module_name,'constraint id violated : ',to_char(l_failed_constraint.constraint_id));
17536                 wsh_debug_sv.log (l_module_name,'entity_type : ',to_char(l_failed_constraint.entity_type));
17537                 wsh_debug_sv.log (l_module_name,'constraint_class_code : ',to_char(l_failed_constraint.constraint_class_code));
17538                 wsh_debug_sv.log (l_module_name,'violation_type : ',to_char(l_failed_constraint.violation_type));
17539                 wsh_debug_sv.logmsg(l_module_name, 'Constraint Violation Error. Customer '||p_delivery_rec.customer_id||' can not use '||p_rule_deconsol_location|| ' as deconsolidation location');
17540             END IF;
17541             IF l_debug_on THEN
17542                 wsh_debug_sv.pop (l_module_name);
17543             END IF;
17544             return;
17545         END IF;
17546     --}
17547     END IF; -- p_delivery_rec.customer_id IS NOT NULL
17548 
17549 
17550 
17551     -- Validate Region/Zone - Facility Constraints for Ultimate drop off location
17552 
17553    /*validate_region_constraint(
17554          p_location_id       => p_delivery_rec.ultimate_dropoff_location_id,
17555          p_object2_val_num   => p_rule_deconsol_location,
17556          x_validate_result   => l_validate_result,
17557          x_failed_constraint => l_failed_constraint,
17558          x_return_status     => l_return_status);
17559 
17560     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17561        raise FND_API.G_EXC_UNEXPECTED_ERROR;
17562     END IF;
17563 
17564     IF l_debug_on THEN
17565         wsh_debug_sv.logmsg (l_module_name, 'Region/Zone - Facility constraint for ship to location l_validate_result: '||l_validate_result);
17566     END IF;
17567 
17568     IF l_validate_result = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
17569         x_return_status := l_return_status;
17570         x_validate_result := l_validate_result;
17571         IF l_debug_on THEN
17572             wsh_debug_sv.logmsg(l_module_name, 'Region/Zone - Facility Constraint Violation Error. Ship to  Location'||p_delivery_rec.ultimate_dropoff_location_id||' can not use '||p_rule_deconsol_location|| ' as deconsolidation location');
17573         END IF;
17574         return;
17575     END IF;*/
17576 
17577     -- Validate Ship From Organization-Facility Constraints
17578 
17579     IF p_delivery_rec.organization_id IS NOT NULL THEN
17580 
17581         IF l_debug_on THEN
17582           wsh_debug_sv.logmsg (l_module_name, 'organization_id: ' || p_delivery_rec.organization_id);
17583           wsh_debug_sv.logmsg (l_module_name, 'p_rule_deconsol_location: '||p_rule_deconsol_location);
17584         END IF;
17585 
17586         validate_constraint(
17587                  p_comp_class_code          =>      WSH_FTE_CONSTRAINT_FRAMEWORK.G_SHIPORG_FACILITY,
17588                  p_object2_type             =>      'FAC',
17589                  p_object1_val_num          =>      p_delivery_rec.organization_id,
17590                  p_object2_val_num          =>      p_rule_deconsol_location,
17591                  x_validate_result          =>      l_validate_result,
17592                  x_failed_constraint        =>      l_failed_constraint,
17593                  x_return_status            =>      l_return_status);
17594 
17595         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17596             raise FND_API.G_EXC_UNEXPECTED_ERROR;
17597         END IF;
17598 
17599         IF l_debug_on THEN
17600             wsh_debug_sv.logmsg (l_module_name, 'ORG - FAC l_validate_result: '||l_validate_result);
17601         END IF;
17602 
17603         IF l_validate_result = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
17604             x_return_status := l_return_status;
17605             x_validate_result := l_validate_result;
17606             IF l_debug_on THEN
17607                 wsh_debug_sv.push(l_module_name);
17608                 wsh_debug_sv.log (l_module_name,'constraint id violated : ',to_char(l_failed_constraint.constraint_id));
17609                 wsh_debug_sv.log (l_module_name,'entity_type : ',to_char(l_failed_constraint.entity_type));
17610                 wsh_debug_sv.log (l_module_name,'constraint_class_code : ',to_char(l_failed_constraint.constraint_class_code));
17611                 wsh_debug_sv.log (l_module_name,'violation_type : ',to_char(l_failed_constraint.violation_type));
17612                 wsh_debug_sv.logmsg(l_module_name, 'Constraint Violation Error. Ship From Organization'|| p_delivery_rec.organization_id ||' can not use '||p_rule_deconsol_location|| ' as deconsolidation location');
17613             END IF;
17614             IF l_debug_on THEN
17615                 wsh_debug_sv.pop (l_module_name);
17616             END IF;
17617             return;
17618         END IF;
17619     END IF;
17620 
17621     -- Validate Region/Zone - Facility Constraints for Ship From Organization
17622 
17623     IF (p_delivery_rec.organization_id IS NOT NULL) THEN
17624 
17625         get_loc_for_org(
17626           p_org_id	       => p_delivery_rec.organization_id,
17627           x_location_id    => l_location_id,
17628           x_return_status  => x_return_status);
17629 
17630         IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17631             IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17632                raise FND_API.G_EXC_UNEXPECTED_ERROR;
17633             END IF;
17634         END IF;
17635 
17636       /*  validate_region_constraint(
17637              p_location_id       => p_delivery_rec.ultimate_dropoff_location_id,
17638              p_object2_val_num   => p_rule_deconsol_location,
17639              x_validate_result   => l_validate_result,
17640              x_failed_constraint => l_failed_constraint,
17641              x_return_status     => l_return_status);
17642 
17643         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17644             raise FND_API.G_EXC_UNEXPECTED_ERROR;
17645         END IF;
17646 
17647         IF l_debug_on THEN
17648             wsh_debug_sv.logmsg (l_module_name, 'Region/Zone - Facility constraint for ship to location l_validate_result: '||l_validate_result);
17649         END IF;
17650 
17651         IF l_validate_result = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
17652             x_return_status := l_return_status;
17653             x_validate_result := l_validate_result;
17654             IF l_debug_on THEN
17655                 wsh_debug_sv.logmsg(l_module_name, 'Region/Zone - Facility Constraint Violation Error. Ship to  Location'||p_delivery_rec.ultimate_dropoff_location_id||' can not use '||p_rule_deconsol_location|| ' as deconsolidation location');
17656             END IF;
17657             return;
17658         END IF;*/
17659      END IF;
17660 
17661     -- For validating ITEM-FACILITY constraints, get items in delivery using cursor c_get_details
17662     -- and validate exclusive constraints for each item
17663 
17664     IF p_delivery_rec.delivery_id IS NOT NULL THEN
17665 
17666         OPEN c_get_details(p_delivery_rec.delivery_id);
17667             FETCH c_get_details BULK COLLECT INTO l_details_info;
17668         CLOSE c_get_details;
17669 
17670         i_det := l_details_info.FIRST;
17671 
17672         IF i_det IS NOT NULL THEN
17673             LOOP
17674 
17675                 IF l_debug_on THEN
17676                   wsh_debug_sv.logmsg (l_module_name, 'organization_id: ' || l_details_info(i_det).organization_id);
17677                   wsh_debug_sv.logmsg (l_module_name, 'inventory_item_id: '||l_details_info(i_det).inventory_item_id);
17678                 END IF;
17679 
17680                 validate_constraint(   --  checks only negative constraints
17681                      p_comp_class_code          =>  WSH_FTE_CONSTRAINT_FRAMEWORK.G_ITEM_FACILITY,
17682                      p_object1_type             =>  'ITM',
17683                      p_object1_parent_id        =>  l_details_info(i_det).organization_id,
17684                      p_object1_val_num          =>  l_details_info(i_det).inventory_item_id,
17685                      p_object2_type             =>  'FAC',
17686                      p_object2_val_num          =>  p_rule_deconsol_location,
17687                      x_validate_result          =>  l_validate_result,
17688                      x_failed_constraint        =>  l_failed_constraint,
17689                      x_return_status            =>  l_return_status);
17690 
17691                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17692                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
17693                 END IF;
17694 
17695                 IF l_debug_on THEN
17696                     wsh_debug_sv.logmsg (l_module_name, 'ITM - FAC l_validate_result: '||l_validate_result);
17697                 END IF;
17698 
17699                 IF l_validate_result = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
17700                     x_return_status := l_return_status;
17701                     x_validate_result := l_validate_result;
17702                     IF l_debug_on THEN
17703                         wsh_debug_sv.push(l_module_name);
17704                         wsh_debug_sv.log (l_module_name,'constraint id violated : ',to_char(l_failed_constraint.constraint_id));
17705                         wsh_debug_sv.log (l_module_name,'entity_type : ',to_char(l_failed_constraint.entity_type));
17706                         wsh_debug_sv.log (l_module_name,'constraint_class_code : ',to_char(l_failed_constraint.constraint_class_code));
17707                         wsh_debug_sv.log (l_module_name,'violation_type : ',to_char(l_failed_constraint.violation_type));
17708                         wsh_debug_sv.logmsg(l_module_name, 'Constraint Violation Error. Item'|| l_details_info(i_det).inventory_item_id ||' can not use '||p_rule_deconsol_location|| ' as deconsolidation location');
17709                     END IF;
17710                     IF l_debug_on THEN
17711                         wsh_debug_sv.pop (l_module_name);
17712                     END IF;
17713                     return;
17714                 END IF;
17715 
17716              EXIT WHEN i_det = l_details_info.LAST OR l_validate_result <> 'S' OR l_return_status <> 'S' ;
17717              i_det := l_details_info.NEXT(i_det);
17718              END LOOP;
17719          END IF;
17720     END IF;
17721 
17722     IF l_debug_on THEN
17723         wsh_debug_sv.pop (l_module_name);
17724     END IF;
17725 
17726 EXCEPTION
17727 
17728 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
17729       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
17730       --
17731       IF l_debug_on THEN
17732         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
17733         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
17734       END IF;
17735 
17736 WHEN OTHERS THEN
17737       IF c_get_details%ISOPEN THEN
17738          CLOSE c_get_details;
17739       END IF;
17740       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.validate_exclusive_constraints');
17741       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
17742       --
17743       IF l_debug_on THEN
17744         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
17745         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
17746       END IF;
17747 
17748 END validate_exclusive_constraints;
17749 
17750 --***************************************************************************--
17751 --========================================================================
17752 -- PROCEDURE : get_must_use_facility            PRIVATE
17753 --
17754 -- PARAMETERS: p_delivery_rec                   Input delivery record
17755 --             x_deconsol_location              Output deconsolidation location
17756 --             x_return_status                  Return status
17757 -- COMMENT   : This procedure is used to perform for following actions
17758 --             Takes input delivery record
17759 --             Finds deconsolidation location for the delivery based on
17760 --             Inclusive constraints defined.
17761 --             Checks for the following constraints
17762 --              1. Ship to location - facility
17763 --              2. customer - facility
17764 --              3. Ship from org - facility
17765 --========================================================================
17766 
17767 PROCEDURE get_must_use_facility(p_delivery_rec IN WSH_FTE_CONSTRAINT_FRAMEWORK.delivery_ccinfo_rec_type,
17768                                 x_deconsol_location OUT NOCOPY NUMBER,
17769                                 x_return_status     OUT NOCOPY VARCHAR2)
17770 
17771 IS
17772 l_ship_from_location_id  NUMBER;
17773 l_ship_to_location_id    NUMBER;
17774 l_customer_id            NUMBER;
17775 l_region_tab             WSH_UTIL_CORE.ID_TAB_TYPE;
17776 l_zone_tab               WSH_UTIL_CORE.ID_TAB_TYPE;
17777 l_deconsol_location      NUMBER;
17778 l_debug_on               CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
17779 r_itr                    NUMBER;
17780 z_itr                    NUMBER;
17781 l_region_id              NUMBER;
17782 l_zone_id                NUMBER;
17783 l_return_status		     VARCHAR2(1);
17784 l_constr_region_id       NUMBER;
17785 l_constr_location_id     NUMBER;
17786 l_constr_org_id          NUMBER;
17787 l_module_name            CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'get_must_use_facility';
17788 
17789 -- AG add compatibility_class_id = 2
17790 -- as otherwise there is a small chance of wrongly picking up
17791 -- a supplier facility - facility constraint
17792 CURSOR c_get_must_use_location (c_object1_type VARCHAR2, c_object1_id NUMBER, c_class_id NUMBER) IS
17793 SELECT constraint_object2_id from wsh_fte_comp_constraints
17794 WHERE constraint_object2_type = 'FAC'
17795 AND constraint_object1_type = c_object1_type
17796 AND constraint_object1_id = c_object1_id
17797 AND Constraint_type = 'I'
17798 AND compatibility_class_id = c_class_id  -- 2 for Cus_FAC
17799 AND    nvl(trunc(EFFECTIVE_DATE_FROM,'DDD'),trunc(sysdate,'DDD')) <= trunc(sysdate,'DDD')
17800 AND    nvl(trunc(EFFECTIVE_DATE_TO,'DDD'),trunc(sysdate,'DDD')) >= trunc(sysdate,'DDD');
17801 
17802 /*CURSOR c_get_must_use_cus_fac (c_object1_id NUMBER) IS
17803 SELECT constraint_object2_id from wsh_fte_comp_constraints
17804 WHERE constraint_object1_type = 'CUS'
17805 AND constraint_object2_type = 'FAC'
17806 AND constraint_object1_id = c_object1_id
17807 AND Constraint_type = 'I'
17808 AND    nvl(trunc(EFFECTIVE_DATE_FROM,'DDD'),trunc(sysdate,'DDD')) <= trunc(sysdate,'DDD')
17809 AND    nvl(trunc(EFFECTIVE_DATE_TO,'DDD'),trunc(sysdate,'DDD')) >= trunc(sysdate,'DDD');*/
17810 
17811 CURSOR c_get_region_incl_constraints IS
17812 SELECT constraint_object1_id, constraint_object2_id from wsh_fte_comp_constraints
17813 WHERE constraint_type = 'I'
17814 AND compatibility_class_id=12
17815 AND    nvl(trunc(EFFECTIVE_DATE_FROM,'DDD'),trunc(sysdate,'DDD')) <= trunc(sysdate,'DDD')
17816 AND    nvl(trunc(EFFECTIVE_DATE_TO,'DDD'),trunc(sysdate,'DDD')) >= trunc(sysdate,'DDD')
17817 ORDER BY creation_date;
17818 
17819 BEGIN
17820 
17821     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
17822 
17823     IF l_debug_on THEN
17824        wsh_debug_sv.push(l_module_name);
17825     END IF;
17826 
17827     -- get ship to location for the delivery
17828     -- For this location, find must use facility using defined inclusive constraint.
17829     -- Check in cache first, if not found in cache, get from cursor c_get_must_use_location
17830 
17831     l_ship_to_location_id := p_delivery_rec.ULTIMATE_DROPOFF_LOCATION_ID;
17832 
17833     IF l_debug_on THEN
17834         WSH_DEBUG_SV.logmsg(l_module_name,'l_ship_to_location_id: '|| l_ship_to_location_id);
17835     END IF;
17836 
17837     IF ( l_ship_to_location_id < g_cache_max_size  and g_location_mustuse_location.EXISTS(l_ship_to_location_id)) THEN
17838 
17839         l_deconsol_location := g_location_mustuse_location(l_ship_to_location_id);
17840     ELSE
17841         --Does not exist in the cache.
17842         -- Compatibility_class_id is 2 for CUS_FAC constraints
17843         OPEN  c_get_must_use_location( 'FAC', l_ship_to_location_id, 2);
17844             FETCH c_get_must_use_location INTO l_deconsol_location;
17845             IF c_get_must_use_location%NOTFOUND THEN
17846                    l_deconsol_location := NULL;
17847             END IF;
17848         CLOSE c_get_must_use_location;
17849 
17850         IF l_debug_on THEN
17851             WSH_DEBUG_SV.logmsg(l_module_name,'l_deconsol_location for ship To Location using CUS_FAC constraints : '|| l_deconsol_location);
17852         END IF;
17853 
17854 
17855         IF (l_ship_to_location_id < g_cache_max_size AND l_deconsol_location IS NOT NULL) THEN
17856             g_location_mustuse_location(l_ship_to_location_id) := l_deconsol_location;
17857         END IF;
17858     END IF;
17859 
17860     -- If deconsol location not found from must use constraint on ship to location,
17861     -- fetch region level constraints and populate g_region_mustuse_location cache
17862     -- with region id and corresponding must use location id for all region level constraints
17863     -- defined.
17864 
17865     IF l_deconsol_location IS NULL THEN
17866     --{
17867 
17868         IF g_region_mustuse_constraints.COUNT = 0 THEN
17869             OPEN c_get_region_incl_constraints;
17870                 LOOP
17871                     FETCH c_get_region_incl_constraints INTO  l_constr_region_id, l_constr_location_id;
17872                     EXIT WHEN c_get_region_incl_constraints%NOTFOUND;
17873                     g_region_mustuse_location(l_constr_region_id) := l_constr_location_id;
17874                 END LOOP;
17875             CLOSE c_get_region_incl_constraints;
17876         END IF;
17877 
17878         IF l_debug_on THEN
17879             WSH_DEBUG_SV.logmsg(l_module_name,'g_region_mustuse_location.COUNT : '|| g_region_mustuse_location.COUNT);
17880         END IF;
17881 
17882     	WSH_REGIONS_SEARCH_PKG.Get_All_RegionId_Matches(
17883              p_location_id		=> l_ship_to_location_id,
17884              p_use_cache		=> TRUE,
17885              p_lang_code		=> USERENV('LANG'),
17886              x_region_tab		=> l_region_tab,
17887              x_return_status    => l_return_status);
17888 
17889 	    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17890            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17891               raise FND_API.G_EXC_UNEXPECTED_ERROR;
17892            END IF;
17893         END IF;
17894 
17895         r_itr:= l_region_tab.FIRST;
17896 
17897         IF r_itr IS NOT NULL THEN
17898             LOOP
17899                 l_region_id := l_region_tab(r_itr);
17900 
17901                 IF l_region_id < g_cache_max_size AND g_region_mustuse_location.EXISTS(l_region_id) THEN
17902                     l_deconsol_location := g_region_mustuse_location(l_region_id);
17903                 END IF;
17904 
17905                 IF l_debug_on THEN
17906                     WSH_DEBUG_SV.logmsg(l_module_name,'l_deconsol_location from g_region_mustuse_location: '|| l_deconsol_location);
17907                 END IF;
17908 
17909                 -- If deconsolidation location found, populate it in cache
17910                 -- Else, search for zone level constraints
17911 
17912                 IF (l_ship_to_location_id < g_cache_max_size AND l_deconsol_location IS NOT NULL) THEN
17913                     g_location_mustuse_location(l_ship_to_location_id) := l_deconsol_location;
17914                 ELSIF l_deconsol_location IS NULL THEN
17915                     WSH_REGIONS_SEARCH_PKG.Get_All_Zone_Matches(
17916                       p_region_id		    => l_region_id,
17917                       x_zone_tab		    => l_zone_tab,
17918                       x_return_status       => l_return_status);
17919 
17920                      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17921                        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17922                           raise FND_API.G_EXC_UNEXPECTED_ERROR;
17923                        END IF;
17924                     END IF;
17925 
17926                     IF l_debug_on THEN
17927                         WSH_DEBUG_SV.logmsg(l_module_name,'l_zone_tab.COUNT: '|| l_zone_tab.COUNT);
17928                     END IF;
17929 
17930                     IF l_zone_tab.COUNT > 0 THEN
17931                         z_itr:= l_zone_tab.FIRST;
17932                         IF z_itr IS NOT NULL THEN
17933                             LOOP
17934                                 l_zone_id := l_zone_tab(z_itr);
17935                                 IF l_zone_id < g_cache_max_size AND g_region_mustuse_location.EXISTS(l_zone_id) THEN
17936                                     l_deconsol_location := g_region_mustuse_location(l_zone_id);
17937                                 END IF;
17938                                 EXIT WHEN z_itr = l_zone_tab.LAST OR l_deconsol_location IS NOT NULL;
17939                                 z_itr:= l_zone_tab.NEXT(z_itr);
17940                             END LOOP;
17941                         END IF;
17942                     END IF; -- end l_zone_tab.count >0
17943                 END IF;
17944 
17945                 EXIT WHEN r_itr = l_region_tab.LAST OR l_deconsol_location IS NOT NULL;
17946                 r_itr:= l_region_tab.NEXT(r_itr);
17947 	        END LOOP;
17948         END IF;
17949 
17950         IF (l_ship_to_location_id < g_cache_max_size AND l_deconsol_location IS NOT NULL) THEN
17951             g_location_mustuse_location(l_ship_to_location_id) := l_deconsol_location;
17952         ELSE
17953             g_location_mustuse_location(l_ship_to_location_id) := -1;
17954         END IF;
17955     --}
17956     END IF;
17957 
17958     -- If deconsolidation location not found, search for Customer - Facility constraints.
17959 
17960 
17961     IF l_deconsol_location IS NULL OR l_deconsol_location = -1 THEN
17962 
17963         IF l_debug_on THEN
17964             WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_rec.CUSTOMER_ID: '|| p_delivery_rec.CUSTOMER_ID);
17965         END IF;
17966 
17967         l_customer_id := p_delivery_rec.CUSTOMER_ID;
17968 
17969         IF ( l_customer_id < g_cache_max_size  and g_customer_mustuse_location.EXISTS(l_customer_id)) THEN
17970             l_deconsol_location := g_customer_mustuse_location(l_customer_id);
17971             IF (l_deconsol_location = -1) THEN
17972                 l_deconsol_location := NULL;
17973             END IF;
17974         ELSE
17975             --Does not exist in the cache.
17976             -- Compatibility_class_id is 2 for CUS_FAC constraints
17977 
17978             OPEN  c_get_must_use_location('CUS', l_customer_id, 2);
17979                 FETCH c_get_must_use_location INTO l_deconsol_location;
17980                 IF c_get_must_use_location%NOTFOUND THEN
17981                        l_deconsol_location := NULL;
17982                 END IF;
17983             CLOSE c_get_must_use_location;
17984 
17985             IF (l_customer_id < g_cache_max_size AND l_deconsol_location IS NOT NULL) THEN
17986                 g_customer_mustuse_location(l_customer_id) := l_deconsol_location;
17987             END IF;
17988         END IF;
17989 
17990         IF l_debug_on THEN
17991             WSH_DEBUG_SV.logmsg(l_module_name,'l_deconsol_location from customer inclusive constraints: '|| l_deconsol_location);
17992         END IF;
17993     END IF;
17994 
17995     -- If no constraints defined for customer, search for Ship From ORG_FAC constraints
17996 
17997     IF l_deconsol_location IS NULL OR l_deconsol_location = -1 THEN
17998 
17999         l_constr_org_id := p_delivery_rec.organization_id;
18000 
18001         IF l_debug_on THEN
18002             WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_rec.organization_id: '|| l_constr_org_id);
18003         END IF;
18004 
18005         IF (l_constr_org_id IS NOT NULL) THEN
18006 
18007             /*get_loc_for_org(
18008                 p_org_id	       => p_delivery_rec.organization_id,
18009                 x_location_id    => l_ship_from_location_id,
18010                 x_return_status  => x_return_status);
18011 
18012             IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
18013                 IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
18014                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
18015                 END IF;
18016             END IF;*/
18017 
18018             IF ( l_constr_org_id < g_cache_max_size AND g_org_mustuse_location.EXISTS(l_constr_org_id)) THEN
18019 
18020                 l_deconsol_location := g_org_mustuse_location(l_constr_org_id);
18021             ELSE
18022                 --Does not exist in the cache.
18023                 -- Compatibility_class_id is 1 for CUS_FAC constraints
18024                 OPEN  c_get_must_use_location('ORG', l_constr_org_id, 1);
18025                     FETCH c_get_must_use_location INTO l_deconsol_location;
18026                     IF c_get_must_use_location%NOTFOUND THEN
18027                            l_deconsol_location := NULL;
18028                     END IF;
18029                 CLOSE c_get_must_use_location;
18030                 -- Add to cache
18031                 IF (l_constr_org_id < g_cache_max_size AND l_deconsol_location IS NOT NULL) THEN
18032                     g_org_mustuse_location(l_constr_org_id) := l_deconsol_location;
18033                 ELSE
18034                     g_org_mustuse_location(l_constr_org_id) := -1;
18035                 END IF;
18036             END IF;
18037             IF l_debug_on THEN
18038                 WSH_DEBUG_SV.logmsg(l_module_name,'l_deconsol_location from org inclusive constraints: '|| l_deconsol_location);
18039             END IF;
18040 
18041         END IF;
18042 
18043     END IF;
18044 
18045     -- If deconsol location not found from must use constraint on ship from location,
18046     -- fetch region level constraints and populate g_region_mustuse_location cache
18047     -- with region id and corresponding must use location id for all region level constraints
18048     -- defined.
18049 
18050     IF l_deconsol_location IS NULL OR l_deconsol_location = -1 THEN
18051     --{
18052 
18053         get_loc_for_org(
18054             p_org_id	       => p_delivery_rec.organization_id,
18055             x_location_id    => l_ship_from_location_id,
18056             x_return_status  => x_return_status);
18057 
18058         IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
18059             IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
18060                 raise FND_API.G_EXC_UNEXPECTED_ERROR;
18061             END IF;
18062         END IF;
18063 
18064         IF g_region_mustuse_constraints.COUNT = 0 THEN
18065             OPEN c_get_region_incl_constraints;
18066                 LOOP
18067                     FETCH c_get_region_incl_constraints INTO  l_constr_region_id, l_constr_location_id;
18068                     EXIT WHEN c_get_region_incl_constraints%NOTFOUND;
18069                     g_region_mustuse_location(l_constr_region_id) := l_constr_location_id;
18070                 END LOOP;
18071             CLOSE c_get_region_incl_constraints;
18072         END IF;
18073 
18074         IF l_debug_on THEN
18075             WSH_DEBUG_SV.logmsg(l_module_name,'g_region_mustuse_location.COUNT : '|| g_region_mustuse_location.COUNT);
18076         END IF;
18077 
18078     	WSH_REGIONS_SEARCH_PKG.Get_All_RegionId_Matches(
18079              p_location_id		=> l_ship_from_location_id,
18080              p_use_cache		=> TRUE,
18081              p_lang_code		=> USERENV('LANG'),
18082              x_region_tab		=> l_region_tab,
18083              x_return_status    => l_return_status);
18084 
18085 	    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
18086            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
18087               raise FND_API.G_EXC_UNEXPECTED_ERROR;
18088            END IF;
18089         END IF;
18090 
18091         r_itr:= l_region_tab.FIRST;
18092 
18093         IF r_itr IS NOT NULL THEN
18094             LOOP
18095                 l_region_id := l_region_tab(r_itr);
18096 
18097                 IF l_region_id < g_cache_max_size AND g_region_mustuse_location.EXISTS(l_region_id) THEN
18098                     l_deconsol_location := g_region_mustuse_location(l_region_id);
18099                 END IF;
18100 
18101                 IF l_debug_on THEN
18102                     WSH_DEBUG_SV.logmsg(l_module_name,'l_deconsol_location from g_region_mustuse_location: '|| l_deconsol_location);
18103                 END IF;
18104 
18105                 -- If deconsolidation location found, populate it in cache
18106                 -- Else, search for zone level constraints
18107 
18108                 IF (l_ship_to_location_id < g_cache_max_size AND l_deconsol_location IS NOT NULL) THEN
18109                     g_location_mustuse_location(l_ship_from_location_id) := l_deconsol_location;
18110                 ELSIF l_deconsol_location IS NULL THEN
18111                     WSH_REGIONS_SEARCH_PKG.Get_All_Zone_Matches(
18112                       p_region_id		    => l_region_id,
18113                       x_zone_tab		    => l_zone_tab,
18114                       x_return_status       => l_return_status);
18115 
18116                      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
18117                        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
18118                           raise FND_API.G_EXC_UNEXPECTED_ERROR;
18119                        END IF;
18120                     END IF;
18121 
18122                     IF l_debug_on THEN
18123                         WSH_DEBUG_SV.logmsg(l_module_name,'l_zone_tab.COUNT: '|| l_zone_tab.COUNT);
18124                     END IF;
18125 
18126                     IF l_zone_tab.COUNT > 0 THEN
18127                         z_itr:= l_zone_tab.FIRST;
18128                         IF z_itr IS NOT NULL THEN
18129                             LOOP
18130                                 l_zone_id := l_zone_tab(z_itr);
18131                                 IF l_zone_id < g_cache_max_size AND g_region_mustuse_location.EXISTS(l_zone_id) THEN
18132                                     l_deconsol_location := g_region_mustuse_location(l_zone_id);
18133                                 END IF;
18134                                 EXIT WHEN z_itr = l_zone_tab.LAST OR l_deconsol_location IS NOT NULL;
18135                                 z_itr:= l_zone_tab.NEXT(z_itr);
18136                             END LOOP;
18137                         END IF;
18138                     END IF;
18139                 END IF;
18140 
18141                 EXIT WHEN r_itr = l_region_tab.LAST OR l_deconsol_location IS NOT NULL;
18142                 r_itr:= l_region_tab.NEXT(r_itr);
18143 	        END LOOP;
18144         END IF;
18145         IF (l_ship_from_location_id < g_cache_max_size AND l_deconsol_location IS NOT NULL) THEN
18146             g_location_mustuse_location(l_ship_from_location_id) := l_deconsol_location;
18147         ELSE
18148             g_location_mustuse_location(l_ship_from_location_id) := -1;
18149         END IF;
18150     --}
18151     END IF;
18152     IF l_deconsol_location <> -1 THEN
18153         x_deconsol_location := l_deconsol_location;
18154     END IF;
18155 
18156     IF l_debug_on THEN
18157         WSH_DEBUG_SV.pop(l_module_name);
18158     END IF;
18159 
18160 EXCEPTION
18161 
18162 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
18163       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
18164       --
18165       IF l_debug_on THEN
18166         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
18167         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
18168       END IF;
18169 
18170 WHEN OTHERS THEN
18171       IF c_get_must_use_location%ISOPEN THEN
18172          CLOSE c_get_must_use_location;
18173       END IF;
18174       /*IF c_get_must_use_cus_fac%ISOPEN THEN
18175          CLOSE c_get_must_use_cus_fac;
18176       END IF;*/
18177       IF c_get_region_incl_constraints%ISOPEN THEN
18178          CLOSE c_get_region_incl_constraints;
18179       END IF;
18180 
18181       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.get_must_use_facility');
18182       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
18183       --
18184       IF l_debug_on THEN
18185         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
18186         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
18187       END IF;
18188 
18189 END get_must_use_facility;
18190 
18191 --***************************************************************************--
18192 --========================================================================
18193 -- PROCEDURE : VALIDATE_CONSTRAINT_DECONSOL
18194 --
18195 -- PARAMETERS: p_init_msg_list             FND_API.G_TRUE to reset list
18196 --             p_delivery_info             Table of delivery records to process
18197 --                                         Only one of p_in_ids and p_delivery_info should be passed
18198 --             p_in_ids                    Table of delivery ids to process
18199 --             p_rule_deconsol_location    Default deconsolidation location passed
18200 --             p_rule_override_deconsol    If true, default deconsolidation location passed
18201 --                                         takes precedence.
18202 --             x_output_id_tab             Output tab with deconsol location specified for deliveries
18203 --             x_msg_count                 Number of messages in the list
18204 --             x_msg_data                  Text of messages
18205 --             x_return_status             Return status
18206 -- COMMENT   : This procedure is to find deconsolidation locations for a group of deliveries passed
18207 --
18208 --             Deconsolidation location is searched for in the following sequence
18209 --                if override flag is true
18210 --                    if fte is installed
18211 --                        check exclusive constraints
18212 --                        if constraint faliure - error out del
18213 --                   else
18214 --                        set given loc as intermediate location
18215 --                else
18216 --                    get inter-med loc for delivery
18217 --                    if fte is installed
18218 --                       if intermediate loc not null
18219 --                            check exclusive constraints - in case of failure - error out delivery
18220 --                        else if null
18221 --                            check inclusive contraints to get must use location
18222 --                            if loc found
18223 --                                check exclusive constraints for this location
18224 --                            else if not found
18225 --                                get deconsol location provided in region zones form
18226 --                                if loc found
18227 --                                    check exclusive constraints
18228 --                                    if constraints faliure -  error out del
18229 --                                else
18230 --                                    check constraints on supplied location
18231 --                                    use supplied location
18232 --                    else if fte not installed
18233 --                        check region-zones to get location
18234 --                            if loc found
18235 --                                use location found
18236 --                            else
18237 --                                use supplied location
18238 --========================================================================
18239 
18240 PROCEDURE validate_constraint_deconsol( p_init_msg_list          IN  VARCHAR2 DEFAULT fnd_api.g_false,
18241                                         p_delivery_info          IN  OUT NOCOPY delivery_ccinfo_tab_type,
18242                                         p_in_ids                 IN  wsh_util_core.id_tab_type,
18243                                         p_rule_deconsol_location IN  NUMBER default NULL,
18244                                         p_rule_override_deconsol IN  BOOLEAN  DEFAULT  FALSE,
18245                                         p_rule_to_zone_id        IN  NUMBER  DEFAULT  NULL,
18246                                         p_caller                 IN  VARCHAR2 DEFAULT NULL,
18247                                         x_output_id_tab          OUT NOCOPY deconsol_output_tab_type,
18248                                         x_return_status          OUT NOCOPY VARCHAR2,
18249                                         x_msg_count              OUT NOCOPY NUMBER,
18250                                         x_msg_data               OUT NOCOPY VARCHAR2
18251 ) IS
18252 
18253     l_return_status		        VARCHAR2(1);
18254     j                           NUMBER := 0;
18255     i                           NUMBER := 0;
18256     l_facility_id               NUMBER := 0;
18257     l_stop_id                   NUMBER := 0;
18258     --l_delivery_info             delivery_ccinfo_tab_type;
18259     l_failed_constraint         WSH_FTE_CONSTRAINT_FRAMEWORK.line_constraint_rec_type;
18260     l_validate_result           VARCHAR2(1) := 'S';
18261     l_physical_location_id      NUMBER := NULL;
18262     l_intermed_ship_to_loc_id   NUMBER;
18263     l_rule_deconsol_location    NUMBER;
18264     l_debug_on                  CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
18265     l_module_name               CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'VALIDATE_CONSTRAINT_DECONSOL';
18266     rec_cnt                     NUMBER;
18267     l_region_tab                WSH_REGIONS_SEARCH_PKG.region_deconsol_Tab_Type;
18268     l_success                   VARCHAR2(1) := 'S';
18269     l_failure                   VARCHAR2(1) := 'F';
18270     l_zone_index                NUMBER := 0;
18271     l_msg_count                 NUMBER := 0;
18272     l_msg_data                  VARCHAR2(2000) := NULL;
18273 
18274     cursor c_gettrip(l_deliveryid IN NUMBER) is
18275     select wts.TRIP_ID
18276     from wsh_trip_stops wts, wsh_delivery_legs wdl
18277     where wdl.delivery_id =l_deliveryid AND
18278     wdl.pick_up_stop_id = wts.stop_id;
18279 
18280 
18281     CURSOR c_get_dlvy(c_delivery_id IN NUMBER) IS
18282     SELECT wnd.DELIVERY_ID
18283       , NULL
18284       , 'Y'
18285       , wnd.NAME
18286       , wnd.PLANNED_FLAG
18287       , wnd.STATUS_CODE
18288       , wnd.INITIAL_PICKUP_DATE
18289       , wnd.INITIAL_PICKUP_LOCATION_ID
18290       , wnd.ULTIMATE_DROPOFF_LOCATION_ID
18291       , wnd.ULTIMATE_DROPOFF_DATE
18292       , wnd.CUSTOMER_ID
18293       , wnd.INTMED_SHIP_TO_LOCATION_ID
18294       , wnd.SHIP_METHOD_CODE
18295       , wnd.DELIVERY_TYPE
18296       , wnd.CARRIER_ID
18297       , wnd.ORGANIZATION_ID
18298       , wnd.SERVICE_LEVEL
18299       , wnd.MODE_OF_TRANSPORT
18300       , wnd.PARTY_ID
18301       , nvl(wnd.SHIPMENT_DIRECTION,'O')
18302       , nvl(wnd.SHIPPING_CONTROL,'BUYER')
18303       , NULL  -- AGDUMMY
18304     FROM wsh_new_deliveries wnd
18305     WHERE wnd.delivery_id = c_delivery_id;
18306 
18307 BEGIN
18308 
18309     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
18310 
18311     refresh_cache(l_return_status);
18312 
18313     IF l_debug_on THEN
18314       wsh_debug_sv.push (l_module_name);
18315       WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info.COUNT: '||p_delivery_info.COUNT);
18316     END IF;
18317 
18318     IF p_delivery_info.COUNT = 0 THEN
18319 
18320         i := p_in_ids.FIRST;
18321 
18322         IF i IS NOT NULL THEN
18323             LOOP
18324 
18325                 -- Fetch entire information for a particular record.
18326 
18327                 OPEN  c_get_dlvy(p_in_ids(i));
18328                     FETCH c_get_dlvy into p_delivery_info(i);
18329                 CLOSE c_get_dlvy;
18330 
18331                 --#DUM_LOC(S)
18332                 -- Delivery's ultimate_dropoff_location_id to be converted to physical internal
18333                 -- location if it is a dummy location.
18334                 -- We have to use the API for this purpose.
18335 
18336                 WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
18337                  p_internal_cust_location_id  => p_delivery_info(i).ultimate_dropoff_location_id,
18338                  x_internal_org_location_id   => l_physical_location_id,
18339                  x_return_status              => l_return_status);
18340 
18341                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
18342                     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
18343                         raise FND_API.G_EXC_UNEXPECTED_ERROR;
18344                     END IF;
18345                 END IF;
18346 
18347                 --physical location id is not null implies- A dummy location.
18348                 IF (l_physical_location_id IS NOT NULL) THEN
18349                 --
18350                     IF l_debug_on THEN
18351                         WSH_DEBUG_SV.logmsg(l_module_name,'Location '||p_delivery_info(i).ultimate_dropoff_location_id||' is a dummy location');
18352                     END IF;
18353                 --
18354                     p_delivery_info(i).ultimate_dropoff_location_id := l_physical_location_id;
18355                     p_delivery_info(i).physical_dropoff_location_id := l_physical_location_id;
18356                 END IF;
18357                 --#DUM_LOC(E)
18358 
18359                 OPEN c_gettrip(p_in_ids(i));
18360                     FETCH c_gettrip into p_delivery_info(i).TRIP_ID;
18361                 CLOSE c_gettrip;
18362 
18363                 --
18364                 IF l_debug_on THEN
18365                     WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info(i).delivery_id : '||p_delivery_info(i).delivery_id);
18366                     WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info(i).initial_pickup_location_id : '||p_delivery_info(i).initial_pickup_location_id);
18367                     WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info(i).ultimate_dropoff_location_id : '||p_delivery_info(i).ultimate_dropoff_location_id);
18368                     WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info(i).intmed_ship_to_location_id : '||p_delivery_info(i).intmed_ship_to_location_id);
18369                 END IF;
18370                 --
18371                 EXIT WHEN i = p_in_ids.LAST;
18372                 i := p_in_ids.NEXT(i);
18373             END LOOP;
18374         END IF;
18375     END IF; -- p_delivery_info.COUNT = 0
18376 
18377 
18378 
18379     IF l_debug_on THEN
18380         WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info.COUNT: '||p_delivery_info.COUNT);
18381         WSH_DEBUG_SV.logmsg(l_module_name, 'WSH_FTE_CONSTRAINT_FRAMEWORK.g_is_fte_installed: '||WSH_FTE_CONSTRAINT_FRAMEWORK.g_is_fte_installed);
18382         --WSH_DEBUG_SV.logmsg(l_module_name,'p_rule_override_deconsol: '||p_rule_override_deconsol);
18383     END IF;
18384 
18385     -- Loop through deliveries to set deconsol location for each delivery
18386 
18387     rec_cnt := p_delivery_info.FIRST;
18388 
18389     IF rec_cnt IS NOT NULL THEN
18390     --{
18391         LOOP
18392         --{
18393             IF p_delivery_info(rec_cnt).shipping_control = 'SUPPLIER'  THEN
18394                 GOTO del_nextpass;
18395             END IF;
18396             IF l_debug_on THEN
18397                     WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info(rec_cnt).delivery_id : '||p_delivery_info(rec_cnt).delivery_id);
18398             END IF;
18399 
18400             IF p_rule_override_deconsol = TRUE AND p_rule_deconsol_location IS NULL THEN
18401             --{
18402                 IF l_debug_on THEN
18403                     WSH_DEBUG_SV.logmsg(l_module_name,'p_rule_override_deconsol = TRUE AND p_rule_deconsol_location IS NULL');
18404                 END IF;
18405                 x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
18406                 IF l_debug_on THEN
18407                     wsh_debug_sv.pop (l_module_name);
18408                 END IF;
18409                 return;
18410             --}
18411             ELSIF p_rule_override_deconsol = TRUE AND p_rule_deconsol_location IS NOT NULL THEN
18412             --{
18413 
18414                 IF l_debug_on THEN
18415                     WSH_DEBUG_SV.logmsg(l_module_name,'p_rule_override_deconsol = TRUE AND p_rule_deconsol_location IS NOT NULL');
18416                 END IF;
18417 
18418                 IF WSH_FTE_CONSTRAINT_FRAMEWORK.g_is_fte_installed = 'Y' THEN
18419                 --{
18420                 --
18421                 -- FTE is installed, validate exclusive constraints for location supplied
18422                 --
18423                     VALIDATE_EXCLUSIVE_CONSTRAINTS(p_delivery_rec            => p_delivery_info(rec_cnt),
18424                                                    p_rule_deconsol_location  => p_rule_deconsol_location,
18425                                                    x_validate_result         => l_validate_result,
18426                                                    x_return_status           => l_return_status);
18427 
18428                     IF l_debug_on THEN
18429                         WSH_DEBUG_SV.logmsg(l_module_name,'VALIDATE_EXCLUSIVE_CONSTRAINTS l_validate_result : '||l_validate_result);
18430                         WSH_DEBUG_SV.logmsg(l_module_name,'VALIDATE_EXCLUSIVE_CONSTRAINTS l_return_status : '||l_return_status);
18431                     END IF;
18432 
18433                     IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR  OR l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
18434                          raise FND_API.G_EXC_UNEXPECTED_ERROR;
18435                     ELSE
18436                         IF l_validate_result = l_success THEN
18437                             x_output_id_tab(rec_cnt).deconsol_location := p_rule_deconsol_location;
18438                             x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18439                             x_output_id_tab(rec_cnt).validation_status := l_success;
18440                             p_delivery_info(rec_cnt).intmed_ship_to_location_id := p_rule_deconsol_location;
18441                         ELSE
18442                             x_output_id_tab(rec_cnt).deconsol_location := NULL;
18443                             x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18444                             x_output_id_tab(rec_cnt).validation_status := l_failure;
18445                             p_delivery_info(rec_cnt).intmed_ship_to_location_id := NULL;
18446                         END IF;
18447                     END IF;
18448 
18449                     IF l_debug_on THEN
18450                         WSH_DEBUG_SV.logmsg(l_module_name,'deconsol_location: '||x_output_id_tab(rec_cnt).deconsol_location);
18451                         WSH_DEBUG_SV.logmsg(l_module_name,'entity_id: '||x_output_id_tab(rec_cnt).entity_id);
18452                         WSH_DEBUG_SV.logmsg(l_module_name,'validation_status: '||x_output_id_tab(rec_cnt).validation_status);
18453                     END IF;
18454 
18455                     GOTO del_nextpass;
18456                 --}
18457                 ELSE
18458                 --{
18459                     -- since fte is not installed and over-ride flag is true, set supplied location as
18460                     -- intermediate location
18461                     x_output_id_tab(rec_cnt).deconsol_location := p_rule_deconsol_location;
18462                     x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18463                     x_output_id_tab(rec_cnt).validation_status := l_success;
18464                     p_delivery_info(rec_cnt).intmed_ship_to_location_id := p_rule_deconsol_location;
18465 
18466                     IF l_debug_on THEN
18467                         WSH_DEBUG_SV.logmsg(l_module_name,'deconsol_location: '||x_output_id_tab(rec_cnt).deconsol_location);
18468                         WSH_DEBUG_SV.logmsg(l_module_name,'entity_id: '||x_output_id_tab(rec_cnt).entity_id);
18469                         WSH_DEBUG_SV.logmsg(l_module_name,'validation_status: '||x_output_id_tab(rec_cnt).validation_status);
18470                     END IF;
18471                 --}
18472                 END IF;
18473                 GOTO del_nextpass;
18474             --}
18475             ELSIF p_rule_override_deconsol = FALSE THEN
18476             --{
18477                 IF l_debug_on THEN
18478                     WSH_DEBUG_SV.logmsg(l_module_name,'p_rule_override_deconsol IS FALSE');
18479                 END IF;
18480                 l_intermed_ship_to_loc_id := p_delivery_info(rec_cnt).intmed_ship_to_location_id;
18481 
18482                 IF WSH_FTE_CONSTRAINT_FRAMEWORK.g_is_fte_installed = 'Y' THEN
18483                 --{
18484                     IF l_intermed_ship_to_loc_id IS NOT NULL THEN
18485                     --{
18486                         IF l_debug_on THEN
18487                             WSH_DEBUG_SV.logmsg(l_module_name,'l_intermed_ship_to_loc_id: '|| l_intermed_ship_to_loc_id);
18488                         END IF;
18489 
18490                         VALIDATE_EXCLUSIVE_CONSTRAINTS(p_delivery_rec            => p_delivery_info(rec_cnt),
18491                                                        p_rule_deconsol_location  => l_intermed_ship_to_loc_id,
18492                                                        x_validate_result         => l_validate_result,
18493                                                        x_return_status           => l_return_status);
18494 
18495                         IF l_debug_on THEN
18496                             WSH_DEBUG_SV.logmsg(l_module_name,'VALIDATE_EXCLUSIVE_CONSTRAINTS_validate_result : '||l_validate_result);
18497                             WSH_DEBUG_SV.logmsg(l_module_name,'VALIDATE_EXCLUSIVE_CONSTRAINTS_return_status : '||l_return_status);
18498                         END IF;
18499 
18500                         IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR  OR l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
18501                             raise FND_API.G_EXC_UNEXPECTED_ERROR;
18502                         ELSE
18503                             IF l_validate_result = l_success THEN
18504                                 x_output_id_tab(rec_cnt).deconsol_location := l_intermed_ship_to_loc_id;
18505                                 x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18506                                 x_output_id_tab(rec_cnt).validation_status := l_success;
18507                                 p_delivery_info(rec_cnt).intmed_ship_to_location_id := l_intermed_ship_to_loc_id;
18508                             ELSE
18509                                 x_output_id_tab(rec_cnt).deconsol_location := NULL;
18510                                 x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18511                                 x_output_id_tab(rec_cnt).validation_status := l_failure;
18512                                 p_delivery_info(rec_cnt).intmed_ship_to_location_id := NULL;
18513                             END IF;
18514 
18515                             IF l_debug_on THEN
18516                                 WSH_DEBUG_SV.logmsg(l_module_name,'deconsol_location: '||x_output_id_tab(rec_cnt).deconsol_location);
18517                                 WSH_DEBUG_SV.logmsg(l_module_name,'entity_id: '||x_output_id_tab(rec_cnt).entity_id);
18518                                 WSH_DEBUG_SV.logmsg(l_module_name,'validation_status: '||x_output_id_tab(rec_cnt).validation_status);
18519                             END IF;
18520 
18521                             GOTO del_nextpass;
18522                         END IF;
18523                     --}
18524                     ELSE
18525                     --{
18526 
18527                     -- intermediate location for delivery is NULL, get intermediate location from
18528                     -- must use constraints defined for the location
18529 
18530                         IF l_debug_on THEN
18531                             WSH_DEBUG_SV.logmsg(l_module_name,'l_intermed_ship_to_loc_id IS NULL ');
18532                         END IF;
18533 
18534                         get_must_use_facility(p_delivery_rec => p_delivery_info(rec_cnt),
18535                                               x_deconsol_location => l_rule_deconsol_location,
18536                                               x_return_status   => l_return_status);
18537 
18538                         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
18539                             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
18540                                 raise FND_API.G_EXC_UNEXPECTED_ERROR;
18541                             END IF;
18542                         END IF;
18543 
18544                         IF l_rule_deconsol_location IS NOT NULL THEN
18545                         --{
18546                             VALIDATE_EXCLUSIVE_CONSTRAINTS(p_delivery_rec            => p_delivery_info(rec_cnt),
18547                                                            p_rule_deconsol_location  => l_rule_deconsol_location,
18548                                                            x_validate_result         => l_validate_result,
18549                                                            x_return_status           => l_return_status);
18550 
18551                             IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR  OR l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
18552                                 raise FND_API.G_EXC_UNEXPECTED_ERROR;
18553                             ELSE
18554                                 IF l_validate_result = l_success THEN
18555                                     x_output_id_tab(rec_cnt).deconsol_location := l_rule_deconsol_location;
18556                                     x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18557                                     x_output_id_tab(rec_cnt).validation_status := l_success;
18558                                     p_delivery_info(rec_cnt).intmed_ship_to_location_id := l_rule_deconsol_location;
18559                                 ELSE
18560                                     x_output_id_tab(rec_cnt).deconsol_location := NULL;
18561                                     x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18562                                     x_output_id_tab(rec_cnt).validation_status := l_failure;
18563                                     p_delivery_info(rec_cnt).intmed_ship_to_location_id := NULL;
18564                                 END IF;
18565 
18566                                 IF l_debug_on THEN
18567                                     WSH_DEBUG_SV.logmsg(l_module_name,'deconsol_location: '||x_output_id_tab(rec_cnt).deconsol_location);
18568                                     WSH_DEBUG_SV.logmsg(l_module_name,'entity_id: '||x_output_id_tab(rec_cnt).entity_id);
18569                                     WSH_DEBUG_SV.logmsg(l_module_name,'validation_status: '||x_output_id_tab(rec_cnt).validation_status);
18570                                 END IF;
18571 
18572                                 GOTO del_nextpass;
18573                             END IF;
18574                         --}
18575                         ELSE
18576                         --{
18577                             -- Must use location not found from inclusive constraints.
18578                             -- obtain deconsol location specified through Regions and Zones Form
18579 
18580                             IF l_debug_on THEN
18581                                 WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info(rec_cnt).ULTIMATE_DROPOFF_LOCATION_ID: '||p_delivery_info(rec_cnt).ULTIMATE_DROPOFF_LOCATION_ID);
18582                             END IF;
18583 
18584                             WSH_REGIONS_SEARCH_PKG.get_all_region_deconsols
18585                                                 ( p_location_id		    => p_delivery_info(rec_cnt).ULTIMATE_DROPOFF_LOCATION_ID,
18586                                                  p_use_cache		    => TRUE,
18587                                                  p_lang_code		    => USERENV('LANG'),
18588                                                  p_zone_flag            => TRUE,
18589                                                  p_rule_to_zone_id      => p_rule_to_zone_id,
18590                                                  p_caller               => p_caller,
18591                                                  x_region_consol_tab	=> l_region_tab,
18592                                                  x_return_status        => l_return_status);
18593 
18594                             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
18595                                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
18596                                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
18597                                 END IF;
18598                             END IF;
18599 
18600                             --
18601                             -- First check if l_region_tab contains a zone matching
18602                             -- to p_rule_to_zone_id passed.
18603                             -- If yes, set the deconsol location for that zone
18604                             -- otherwise, set the deconsol location for the region where region_type <>10 (i.e.zone)
18605                             --
18606                             IF l_region_tab.COUNT > 0 THEN
18607                                 --IF p_caller like 'WMS%' THEN
18608                                     l_rule_deconsol_location := l_region_tab(l_region_tab.FIRST).Deconsol_location;
18609                             ELSIF p_rule_deconsol_location IS NOT NULL THEN
18610                                 l_rule_deconsol_location := p_rule_deconsol_location;
18611                             END IF;
18612 
18613                             IF l_rule_deconsol_location IS NOT NULL THEN
18614 
18615                                 VALIDATE_EXCLUSIVE_CONSTRAINTS(p_delivery_rec            => p_delivery_info(rec_cnt),
18616                                                                p_rule_deconsol_location  => l_rule_deconsol_location,
18617                                                                x_validate_result         => l_validate_result,
18618                                                                x_return_status           => l_return_status);
18619 
18620                                 IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR  OR l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
18621                                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
18622                                 ELSE
18623                                     IF l_validate_result = l_success THEN
18624                                         x_output_id_tab(rec_cnt).deconsol_location := l_rule_deconsol_location;
18625                                         x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18626                                         x_output_id_tab(rec_cnt).validation_status := l_success;
18627                                         p_delivery_info(rec_cnt).intmed_ship_to_location_id := l_rule_deconsol_location;
18628                                     ELSE
18629                                         x_output_id_tab(rec_cnt).deconsol_location := NULL;
18630                                         x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18631                                         x_output_id_tab(rec_cnt).validation_status := l_failure;
18632                                         p_delivery_info(rec_cnt).intmed_ship_to_location_id := NULL;
18633                                     END IF;
18634 
18635                                     IF l_debug_on THEN
18636                                         WSH_DEBUG_SV.logmsg(l_module_name,'deconsol_location: '||x_output_id_tab(rec_cnt).deconsol_location);
18637                                         WSH_DEBUG_SV.logmsg(l_module_name,'entity_id: '||x_output_id_tab(rec_cnt).entity_id);
18638                                         WSH_DEBUG_SV.logmsg(l_module_name,'validation_status: '||x_output_id_tab(rec_cnt).validation_status);
18639                                     END IF;
18640 
18641                                     GOTO del_nextpass;
18642                                 END IF;
18643                             ELSE
18644                                 x_output_id_tab(rec_cnt).deconsol_location := NULL;
18645                                 x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18646                                 x_output_id_tab(rec_cnt).validation_status := l_failure;
18647                                 p_delivery_info(rec_cnt).intmed_ship_to_location_id := NULL;
18648                             END IF;
18649                         --}
18650                         END IF;
18651                     --}
18652                     END IF;
18653                 --}
18654                 ELSE -- if Fte is not installed, Use deconsol location from regions if intmed_shipto of the delivery is NULL,
18655                      -- if not found, use supplied value
18656                 --{
18657 
18658                     IF l_debug_on THEN
18659                         WSH_DEBUG_SV.logmsg(l_module_name,'FTE installation status: '|| WSH_FTE_CONSTRAINT_FRAMEWORK.g_is_fte_installed);
18660                     END IF;
18661                     -- AG if intmed_shipto of the delivery is NOT NULL return that
18662                     -- else do the following
18663 
18664                     IF l_intermed_ship_to_loc_id IS NOT NULL THEN
18665                     --{
18666                                 x_output_id_tab(rec_cnt).deconsol_location := l_intermed_ship_to_loc_id;
18667                                 x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18668                                 x_output_id_tab(rec_cnt).validation_status := l_success;
18669                                 p_delivery_info(rec_cnt).intmed_ship_to_location_id := l_intermed_ship_to_loc_id;
18670                     -- }
18671                     ELSE -- if
18672                     --{
18673 
18674                     WSH_REGIONS_SEARCH_PKG.get_all_region_deconsols
18675                                            ( p_location_id		    => p_delivery_info(rec_cnt).ULTIMATE_DROPOFF_LOCATION_ID,
18676                                              p_use_cache		    => TRUE,
18677                                              p_lang_code		    => USERENV('LANG'),
18678                                              p_zone_flag            => TRUE,
18679                                              p_rule_to_zone_id      => p_rule_to_zone_id,
18680                                              p_caller               => p_caller,
18681                                              x_region_consol_tab	=> l_region_tab,
18682                                              x_return_status        => l_return_status);
18683 
18684                     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
18685                         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
18686                             raise FND_API.G_EXC_UNEXPECTED_ERROR;
18687                         END IF;
18688                     END IF;
18689 
18690                     IF l_region_tab.COUNT > 0 THEN
18691 
18692                         --IF p_caller like 'WMS%' THEN
18693                             l_rule_deconsol_location := l_region_tab(l_region_tab.FIRST).Deconsol_location;
18694                         --l_rule_deconsol_location := l_region_tab(l_region_tab.FIRST).Deconsol_location;
18695                     ELSIF p_rule_deconsol_location IS NOT NULL THEN
18696                         l_rule_deconsol_location := p_rule_deconsol_location;
18697                     END IF;
18698 
18699                     IF l_rule_deconsol_location IS NOT NULL THEN
18700                         x_output_id_tab(rec_cnt).deconsol_location := l_rule_deconsol_location;
18701                         x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18702                         x_output_id_tab(rec_cnt).validation_status := l_success;
18703                         p_delivery_info(rec_cnt).intmed_ship_to_location_id := l_rule_deconsol_location;
18704 
18705                         IF l_debug_on THEN
18706                             WSH_DEBUG_SV.logmsg(l_module_name,'deconsol_location: '||x_output_id_tab(rec_cnt).deconsol_location);
18707                             WSH_DEBUG_SV.logmsg(l_module_name,'entity_id: '||x_output_id_tab(rec_cnt).entity_id);
18708                             WSH_DEBUG_SV.logmsg(l_module_name,'validation_status: '||x_output_id_tab(rec_cnt).validation_status);
18709                         END IF;
18710                     ELSE
18711                         x_output_id_tab(rec_cnt).deconsol_location := NULL;
18712                         x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18713                         x_output_id_tab(rec_cnt).validation_status := l_failure;
18714                         p_delivery_info(rec_cnt).intmed_ship_to_location_id := NULL;
18715                     END IF;
18716                     --}
18717                     END IF;
18718 
18719                 -- }
18720                 END IF;
18721             --}
18722             END IF;
18723 
18724             <<del_nextpass>>
18725 
18726             EXIT WHEN rec_cnt = p_delivery_info.LAST;
18727             rec_cnt := p_delivery_info.NEXT(rec_cnt);
18728         --}
18729         END LOOP;
18730     --}
18731     END IF;
18732 
18733     FND_MSG_PUB.Count_And_Get (
18734         p_count         =>      l_msg_count,
18735         p_data          =>      l_msg_data ,
18736         p_encoded       =>      FND_API.G_FALSE );
18737 
18738     IF l_debug_on THEN
18739         wsh_debug_sv.log (l_module_name,'No. of messages already in stack : ',to_char(l_msg_count));
18740         WSH_DEBUG_SV.pop(l_module_name);
18741     END IF;
18742 
18743 EXCEPTION
18744 
18745 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
18746       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
18747       --
18748       IF l_debug_on THEN
18749         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
18750         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
18751       END IF;
18752 
18753 WHEN OTHERS THEN
18754       IF c_gettrip%ISOPEN THEN
18755          CLOSE c_gettrip;
18756       END IF;
18757       IF c_get_dlvy%ISOPEN THEN
18758          CLOSE c_get_dlvy;
18759       END IF;
18760       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.validate_constraint_deconsol');
18761       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
18762       --
18763       IF l_debug_on THEN
18764         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
18765         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
18766       END IF;
18767 
18768 END validate_constraint_deconsol;
18769 
18770 END WSH_FTE_CONSTRAINT_FRAMEWORK;
18771