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 2006/02/13 00:56:44 jnpinto noship $ */
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 
11681 
11682 BEGIN
11683 
11684     x_validate_result := 'S';
11685     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
11686 
11687     g_itm_mustuse_cache.DELETE;
11688     g_itmloc_mustuse_cache.DELETE;
11689     g_itm_exclusive_cache.DELETE;
11690     g_fac_exclusive_cache.DELETE;
11691 
11692     IF FND_API.to_Boolean( p_init_msg_list ) THEN
11693          FND_MSG_PUB.initialize;
11694     END IF;
11695 
11696     IF l_debug_on THEN
11697        wsh_debug_sv.push(l_module_name);
11698        WSH_DEBUG_SV.logmsg(l_module_name,'p_init_msg_list : '||p_init_msg_list);
11699     END IF;
11700 
11701     -- Action codes : ACT, ADT, UPD, CRD
11702 
11703     IF p_action_code NOT IN (G_AUTOCRT_DLVY_TRIP,G_ASSIGN_DLVY_TRIP,G_UPDATE_DLVY,G_CREATE_DLVY,G_AUTOCRT_MDC) OR
11704           p_action_code IS NULL THEN
11705           RAISE g_invalid_action_code;
11706     END IF;
11707 
11708     IF p_action_code IN (G_UPDATE_DLVY,G_CREATE_DLVY) AND p_delivery_info.COUNT = 0 THEN
11709            RAISE g_invalid_action_code;
11710     END IF;
11711 
11712     refresh_cache(l_return_status);
11713 
11714     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11715          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
11716             raise FND_API.G_EXC_UNEXPECTED_ERROR;
11717          END IF;
11718     END IF;
11719 
11720     -- Assumes p_comp_class_tab and p_exception_list are indexed by
11721     -- compatibility class codes
11722 
11723     IF NOT p_exception_list.EXISTS(G_FACILITY_MODE_NUM) THEN
11724       l_comp_class_tab(G_FACILITY_MODE_NUM) := G_FACILITY_MODE;
11725     END IF;
11726     IF NOT p_exception_list.EXISTS(G_FACILITY_CARRIER_NUM) THEN
11727       l_comp_class_tab(G_FACILITY_CARRIER_NUM) := G_FACILITY_CARRIER;
11728     END IF;
11729     IF NOT p_exception_list.EXISTS(G_FACILITY_VEHICLE_NUM) THEN
11730       l_comp_class_tab(G_FACILITY_VEHICLE_NUM) := G_FACILITY_VEHICLE;
11731     END IF;
11732     IF NOT p_exception_list.EXISTS(G_ITEM_MODE_NUM) THEN
11733       l_comp_class_tab(G_ITEM_MODE_NUM) := G_ITEM_MODE;
11734     END IF;
11735     IF NOT p_exception_list.EXISTS(G_ITEM_CARRIER_NUM) THEN
11736       l_comp_class_tab(G_ITEM_CARRIER_NUM) := G_ITEM_CARRIER;
11737     END IF;
11738     IF NOT p_exception_list.EXISTS(G_ITEM_VEHICLE_NUM) THEN
11739       l_comp_class_tab(G_ITEM_VEHICLE_NUM) := G_ITEM_VEHICLE;
11740     END IF;
11741     IF NOT p_exception_list.EXISTS(G_SHIPORG_FACILITY_NUM) THEN
11742        l_comp_class_tab(G_SHIPORG_FACILITY_NUM) := G_SHIPORG_FACILITY;
11743     END IF;
11744     IF NOT p_exception_list.EXISTS(G_CUSTOMER_FACILITY_NUM) THEN
11745        l_comp_class_tab(G_CUSTOMER_FACILITY_NUM) := G_CUSTOMER_FACILITY;
11746     END IF;
11747     IF NOT p_exception_list.EXISTS(G_SUPPLIER_FACILITY_NUM) THEN
11748        l_comp_class_tab(G_SUPPLIER_FACILITY_NUM) := G_SUPPLIER_FACILITY;
11749     END IF;
11750     IF NOT p_exception_list.EXISTS(G_ITEM_FACILITY_NUM) THEN
11751        l_comp_class_tab(G_ITEM_FACILITY_NUM) := G_ITEM_FACILITY;
11752     END IF;
11753     IF NOT p_exception_list.EXISTS(G_CUSTOMER_CUSTOMER_NUM) THEN
11754        l_comp_class_tab(G_CUSTOMER_CUSTOMER_NUM) := G_CUSTOMER_CUSTOMER;
11755     END IF;
11756 
11757     -- Assign delivery details to delivery
11758     -- does not update any grouping attributes for the delivery AS 10/18
11759     -- Populate l_delivery_info
11760 
11761     IF p_delivery_info.COUNT = 0 THEN
11762       --
11763       IF l_debug_on THEN
11764         WSH_DEBUG_SV.logmsg(l_module_name,'p_in_ids passed count : '||p_in_ids.COUNT);
11765       END IF;
11766       --
11767       i := p_in_ids.FIRST;
11768 
11769       IF i IS NOT NULL THEN
11770       LOOP
11771 
11772          -- c_get_dlvy is a global cursor.
11773 	 -- We are fetching entire information for a particluar record.
11774 
11775 	    OPEN  c_get_dlvy(p_in_ids(i));
11776           FETCH c_get_dlvy into l_delivery_info(i);
11777         CLOSE c_get_dlvy;
11778 
11779 	 --#DUM_LOC(S)
11780 	 -- Delivery's ultimate_dropoff_location_id to be converted to physical internal
11781 	 -- location if it is a dummy location.
11782 	 -- We have to use the API for this purpose.
11783 
11784 	 WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
11785              p_internal_cust_location_id  => l_delivery_info(i).ultimate_dropoff_location_id,
11786              x_internal_org_location_id   => l_physical_location_id,
11787              x_return_status              => l_return_status);
11788 
11789 	 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11790 	    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
11791 	       raise FND_API.G_EXC_UNEXPECTED_ERROR;
11792 	    END IF;
11793   	 END IF;
11794 
11795 	 --physical location id is not null implies- A dummy location.
11796 	 IF (l_physical_location_id IS NOT NULL) THEN
11797   	      --
11798 	      IF l_debug_on THEN
11799 		  WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_delivery_info(i).ultimate_dropoff_location_id||' is a dummy location');
11800 	      END IF;
11801 	      --
11802 	      l_delivery_info(i).ultimate_dropoff_location_id := l_physical_location_id;
11803               -- AGDUMMY TODO populate physical_dropoff_location_id
11804               l_delivery_info(i).physical_dropoff_location_id := l_physical_location_id;
11805 	 END IF;
11806          --#DUM_LOC(E)
11807 
11808          OPEN c_gettrip(p_in_ids(i));
11809          FETCH c_gettrip into l_delivery_info(i).TRIP_ID;
11810          CLOSE c_gettrip;
11811 
11812   	      --
11813 	      IF l_debug_on THEN
11814        WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info(i).initial_pickup_location_id : '||l_delivery_info(i).initial_pickup_location_id);
11815        WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info(i).ultimate_dropoff_location_id : '||l_delivery_info(i).ultimate_dropoff_location_id);
11816 	      END IF;
11817 	      --
11818          EXIT WHEN i = p_in_ids.LAST;
11819          i := p_in_ids.NEXT(i);
11820 
11821       END LOOP;
11822       END IF;
11823 
11824     ELSE
11825       --
11826       IF l_debug_on THEN
11827         WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info passed count : '||p_delivery_info.COUNT);
11828       END IF;
11829       --
11830 
11831       i := p_delivery_info.FIRST;
11832       IF i IS NOT NULL THEN
11833        LOOP
11834        --{
11835         IF ( p_delivery_info(i).INITIAL_PICKUP_LOCATION_ID IS NULL OR
11836            p_delivery_info(i).ULTIMATE_DROPOFF_LOCATION_ID IS NULL OR
11837            p_delivery_info(i).CUSTOMER_ID IS NULL OR
11838            p_delivery_info(i).ORGANIZATION_ID IS NULL OR
11839            p_delivery_info(i).PARTY_ID IS NULL OR
11840            p_delivery_info(i).SHIPMENT_DIRECTION IS NULL OR
11841            p_delivery_info(i).SHIPPING_CONTROL IS NULL ) AND
11842            p_action_code = G_UPDATE_DLVY THEN
11843 
11844            -- l_upd_delivery_rec may have a dummy location,
11845            -- Changing l_delivery_info,ultimate dropoff location id handles this case.
11846 
11847 	       OPEN c_get_dlvy(p_delivery_info(i).DELIVERY_ID);
11848              FETCH c_get_dlvy INTO l_upd_delivery_rec;
11849            CLOSE c_get_dlvy;
11850 
11851         END IF;
11852 
11853 	    l_delivery_info(i).DELIVERY_ID                       := p_delivery_info(i).DELIVERY_ID;
11854         l_delivery_info(i).TRIP_ID                           := p_delivery_info(i).TRIP_ID;
11855         l_delivery_info(i).EXISTS_IN_DATABASE                := p_delivery_info(i).EXISTS_IN_DATABASE;
11856         l_delivery_info(i).NAME                              := p_delivery_info(i).NAME;
11857         l_delivery_info(i).PLANNED_FLAG                      := p_delivery_info(i).PLANNED_FLAG;
11858         l_delivery_info(i).STATUS_CODE                       := p_delivery_info(i).STATUS_CODE;
11859         l_delivery_info(i).INITIAL_PICKUP_DATE               := p_delivery_info(i).INITIAL_PICKUP_DATE;
11860         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);
11861         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);
11862         l_delivery_info(i).ULTIMATE_DROPOFF_DATE             := p_delivery_info(i).ULTIMATE_DROPOFF_DATE;
11863         l_delivery_info(i).CUSTOMER_ID                       := nvl(p_delivery_info(i).CUSTOMER_ID,l_upd_delivery_rec.CUSTOMER_ID);
11864         l_delivery_info(i).INTMED_SHIP_TO_LOCATION_ID        := p_delivery_info(i).INTMED_SHIP_TO_LOCATION_ID;
11865         l_delivery_info(i).SHIP_METHOD_CODE                  := p_delivery_info(i).SHIP_METHOD_CODE;
11866         l_delivery_info(i).DELIVERY_TYPE                     := p_delivery_info(i).DELIVERY_TYPE;
11867         l_delivery_info(i).CARRIER_ID                        := p_delivery_info(i).CARRIER_ID;
11868         l_delivery_info(i).ORGANIZATION_ID                   := nvl(p_delivery_info(i).ORGANIZATION_ID,l_upd_delivery_rec.ORGANIZATION_ID);
11869         l_delivery_info(i).SERVICE_LEVEL                     := p_delivery_info(i).SERVICE_LEVEL;
11870         l_delivery_info(i).MODE_OF_TRANSPORT                 := p_delivery_info(i).MODE_OF_TRANSPORT;
11871         l_delivery_info(i).PARTY_ID                          := nvl(p_delivery_info(i).PARTY_ID,l_upd_delivery_rec.PARTY_ID);
11872         l_delivery_info(i).SHIPMENT_DIRECTION                := nvl(nvl(p_delivery_info(i).SHIPMENT_DIRECTION,l_upd_delivery_rec.SHIPMENT_DIRECTION),'O');
11873         l_delivery_info(i).SHIPPING_CONTROL                  := nvl(nvl(p_delivery_info(i).SHIPPING_CONTROL,l_upd_delivery_rec.SHIPPING_CONTROL),'BUYER');
11874 
11875   	      --
11876         IF l_debug_on THEN
11877             WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info(i).initial_pickup_location_id : '||p_delivery_info(i).initial_pickup_location_id);
11878             WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info(i).ultimate_dropoff_location_id : '||p_delivery_info(i).ultimate_dropoff_location_id);
11879             WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info(i).initial_pickup_location_id : '||l_delivery_info(i).initial_pickup_location_id);
11880             WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info(i).ultimate_dropoff_location_id : '||l_delivery_info(i).ultimate_dropoff_location_id);
11881         END IF;
11882 	      --
11883          --#DUM_LOC(S)
11884 	    WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
11885              p_internal_cust_location_id  => l_delivery_info(i).ultimate_dropoff_location_id,
11886              x_internal_org_location_id   => l_physical_location_id,
11887              x_return_status              => l_return_status);
11888 
11889 	  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
11890 	    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
11891 	       raise FND_API.G_EXC_UNEXPECTED_ERROR;
11892 	    END IF;
11893   	  END IF;
11894 
11895 	  IF (l_physical_location_id IS NOT NULL) THEN
11896   	      --
11897 	      IF l_debug_on THEN
11898 		  WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_delivery_info(i).ultimate_dropoff_location_id||' is a dummy location');
11899 	      END IF;
11900 	      --
11901 	      l_delivery_info(i).ultimate_dropoff_location_id := l_physical_location_id;
11902               -- AGDUMMY TODO
11903           l_delivery_info(i).physical_dropoff_location_id := l_physical_location_id;
11904   	  END IF;
11905           --#DUM_LOC(E)
11906 
11907         EXIT WHEN i = p_delivery_info.LAST;
11908         i := p_delivery_info.NEXT(i);
11909        --}
11910        END LOOP;
11911       END IF;
11912     END IF;
11913     --
11914     IF l_debug_on THEN
11915       WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info created : '||l_delivery_info.COUNT);
11916     END IF;
11917     --
11918 
11919     IF p_dlvy_assigned_lines.COUNT = 0 THEN
11920 
11921       l_end_count := 0;
11922       l_start_count := 0;
11923       i := l_delivery_info.FIRST;
11924       IF i IS NOT NULL THEN
11925       LOOP
11926       --
11927       IF l_debug_on THEN
11928         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);
11929       END IF;
11930 
11931       IF l_debug_on THEN
11932         WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info(i).delivery_type : '||l_delivery_info(i).delivery_type);
11933         --l_delivery_info(i).delivery_type := 'STANDARD';
11934         --WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info(i).delivery_type : '||l_delivery_info(i).delivery_type);
11935       END IF;
11936       --
11937       -- G_CREATE_DLVY should have 'N'
11938       IF l_delivery_info(i).exists_in_database = 'Y' THEN  -- Assigned lines have not been passed
11939       l_start_count := l_end_count + 1;
11940 
11941       IF l_delivery_info(i).delivery_type = 'STANDARD' THEN
11942           OPEN c_get_details(l_delivery_info(i).delivery_id);
11943           FETCH c_get_details BULK COLLECT INTO
11944                 l_detail_tab,l_delivery_tab,l_exists_tab,l_customer_tab,l_item_tab,l_shipfrom_loc_tab,
11945                 l_org_tab,l_shipto_loc_tab,l_intmed_shipto_loc_tab,
11946                 l_rel_stat_tab,l_cont_flag_tab,l_date_req_tab,l_date_sch_tab,
11947                 l_shipmethod_tab,l_carrier_tab,l_party_tab,l_line_direction_tab
11948                ,l_shipping_control_tab,l_dum_tab;
11949           --DUM_COMPILE (NULL)
11950           CLOSE c_get_details;
11951           IF l_debug_on THEN
11952             WSH_DEBUG_SV.logmsg(l_module_name,'after c_get_details: '||l_detail_tab.COUNT);
11953           END IF;
11954        ELSE
11955           OPEN c_get_details_consol(l_delivery_info(i).delivery_id);
11956           FETCH c_get_details_consol BULK COLLECT INTO
11957                 l_detail_tab,l_delivery_tab,l_exists_tab,l_customer_tab,l_item_tab,l_shipfrom_loc_tab,
11958                 l_org_tab,l_shipto_loc_tab,l_intmed_shipto_loc_tab,
11959                 l_rel_stat_tab,l_cont_flag_tab,l_date_req_tab,l_date_sch_tab,
11960                 l_shipmethod_tab,l_carrier_tab,l_party_tab,l_line_direction_tab
11961                ,l_shipping_control_tab,l_dum_tab;
11962           --DUM_COMPILE (NULL)
11963           CLOSE c_get_details_consol;
11964        END IF;
11965 
11966 
11967       END IF;
11968 
11969       IF l_detail_tab.COUNT > 0 THEN
11970          IF l_debug_on THEN
11971            WSH_DEBUG_SV.logmsg(l_module_name,'l_detail_tab.COUNT : '||l_detail_tab.COUNT);
11972          END IF;
11973          l_end_count := l_end_count + l_detail_tab.COUNT;
11974          k := 0;
11975 
11976 	 FOR j IN l_start_count .. l_end_count LOOP
11977 
11978 	   k := k+1;
11979            l_dlvy_assigned_lines(j).delivery_detail_id := l_detail_tab(k);
11980            l_dlvy_assigned_lines(j).delivery_id := l_delivery_tab(k);
11981            l_dlvy_assigned_lines(j).exists_in_database := 'Y';
11982            l_dlvy_assigned_lines(j).CUSTOMER_ID := l_customer_tab(k);
11983            l_dlvy_assigned_lines(j).INVENTORY_ITEM_ID := l_item_tab(k);
11984            l_dlvy_assigned_lines(j).SHIP_FROM_LOCATION_ID := l_shipfrom_loc_tab(k);
11985            l_dlvy_assigned_lines(j).ORGANIZATION_ID := l_org_tab(k);
11986            l_dlvy_assigned_lines(j).SHIP_TO_LOCATION_ID := l_shipto_loc_tab(k);
11987            l_dlvy_assigned_lines(j).INTMED_SHIP_TO_LOCATION_ID := l_intmed_shipto_loc_tab(k);
11988            l_dlvy_assigned_lines(j).RELEASED_STATUS := l_rel_stat_tab(k);
11989            l_dlvy_assigned_lines(j).CONTAINER_FLAG := l_cont_flag_tab(k);
11990            l_dlvy_assigned_lines(j).DATE_REQUESTED  := l_date_req_tab(k);
11991            l_dlvy_assigned_lines(j).DATE_SCHEDULED := l_date_sch_tab(k);
11992            l_dlvy_assigned_lines(j).SHIP_METHOD_CODE := l_shipmethod_tab(k);
11993            l_dlvy_assigned_lines(j).CARRIER_ID := l_carrier_tab(k);
11994            l_dlvy_assigned_lines(j).PARTY_ID := l_party_tab(k);
11995            l_dlvy_assigned_lines(j).LINE_DIRECTION := l_line_direction_tab(k);
11996            l_dlvy_assigned_lines(j).SHIPPING_CONTROL := l_shipping_control_tab(k);
11997 
11998 
11999 	   --#DUM_LOC(S)
12000 	   -- Delivery detail's Dummy ship_to_location_id has to be converted to physical internal
12001 	   -- location
12002 
12003 	   WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12004 	      p_internal_cust_location_id  => l_dlvy_assigned_lines(j).ship_to_location_id,
12005               x_internal_org_location_id   => l_physical_location_id,
12006               x_return_status              => l_return_status);
12007 
12008  	   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12009 	     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12010 	        raise FND_API.G_EXC_UNEXPECTED_ERROR;
12011 	     END IF;
12012     	   END IF;
12013 
12014   	   IF (l_physical_location_id IS NOT NULL) THEN
12015   	      --
12016 	      IF l_debug_on THEN
12017 		  WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_dlvy_assigned_lines(j).ship_to_location_id||' is a dummy location');
12018 	      END IF;
12019 	      --
12020 	      l_dlvy_assigned_lines(j).ship_to_location_id:= l_physical_location_id;
12021               -- AGDUMMY TODO
12022               l_dlvy_assigned_lines(j).physical_ship_to_location_id := l_physical_location_id;
12023 	   END IF;
12024            --#DUM_LOC(E)
12025 
12026 	END LOOP;
12027       END IF;
12028 
12029       EXIT WHEN i=l_delivery_info.LAST;
12030       i := l_delivery_info.NEXT(i);
12031       END LOOP;
12032       END IF;
12033     ELSE
12034 
12035       --
12036       IF l_debug_on THEN
12037         WSH_DEBUG_SV.logmsg(l_module_name,'p_dlvy_assigned_lines passed : '||p_dlvy_assigned_lines.COUNT);
12038       END IF;
12039       --
12040       i := p_dlvy_assigned_lines.FIRST;
12041       IF i IS NOT NULL THEN
12042        LOOP
12043 
12044              l_dlvy_assigned_lines(i).delivery_detail_id := p_dlvy_assigned_lines(i).delivery_detail_id;
12045              l_dlvy_assigned_lines(i).delivery_id := p_dlvy_assigned_lines(i).delivery_id;
12046              l_dlvy_assigned_lines(i).exists_in_database := p_dlvy_assigned_lines(i).exists_in_database;
12047              l_dlvy_assigned_lines(i).CUSTOMER_ID := p_dlvy_assigned_lines(i).CUSTOMER_ID;
12048              l_dlvy_assigned_lines(i).INVENTORY_ITEM_ID := p_dlvy_assigned_lines(i).INVENTORY_ITEM_ID;
12049              l_dlvy_assigned_lines(i).SHIP_FROM_LOCATION_ID := p_dlvy_assigned_lines(i).SHIP_FROM_LOCATION_ID;
12050              l_dlvy_assigned_lines(i).ORGANIZATION_ID := p_dlvy_assigned_lines(i).ORGANIZATION_ID;
12051              l_dlvy_assigned_lines(i).SHIP_TO_LOCATION_ID := p_dlvy_assigned_lines(i).SHIP_TO_LOCATION_ID;
12052              l_dlvy_assigned_lines(i).INTMED_SHIP_TO_LOCATION_ID := p_dlvy_assigned_lines(i).INTMED_SHIP_TO_LOCATION_ID;
12053              l_dlvy_assigned_lines(i).RELEASED_STATUS := p_dlvy_assigned_lines(i).RELEASED_STATUS;
12054              l_dlvy_assigned_lines(i).CONTAINER_FLAG := p_dlvy_assigned_lines(i).CONTAINER_FLAG;
12055              l_dlvy_assigned_lines(i).DATE_REQUESTED  := p_dlvy_assigned_lines(i).DATE_REQUESTED;
12056              l_dlvy_assigned_lines(i).DATE_SCHEDULED := p_dlvy_assigned_lines(i).DATE_SCHEDULED;
12057              l_dlvy_assigned_lines(i).SHIP_METHOD_CODE := p_dlvy_assigned_lines(i).SHIP_METHOD_CODE;
12058              l_dlvy_assigned_lines(i).CARRIER_ID := p_dlvy_assigned_lines(i).CARRIER_ID;
12059              l_dlvy_assigned_lines(i).party_id := p_dlvy_assigned_lines(i).party_id;
12060              l_dlvy_assigned_lines(i).line_direction := p_dlvy_assigned_lines(i).line_direction;
12061              l_dlvy_assigned_lines(i).shipping_control := nvl(p_dlvy_assigned_lines(i).shipping_control,'BUYER');
12062 
12063 	     --#DUM_LOC(S)
12064 	     WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12065 		 p_internal_cust_location_id  => l_dlvy_assigned_lines(i).ship_to_location_id,
12066                  x_internal_org_location_id   => l_physical_location_id,
12067                  x_return_status              => l_return_status);
12068 
12069 	     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12070 	       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12071 	          raise FND_API.G_EXC_UNEXPECTED_ERROR;
12072 	       END IF;
12073     	 END IF;
12074 
12075  	     IF (l_physical_location_id IS NOT NULL) THEN
12076   	        --
12077 	        IF l_debug_on THEN
12078 		        WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_dlvy_assigned_lines(i).ship_to_location_id||' is a dummy location');
12079    	        END IF;
12080 	        --
12081 	        l_dlvy_assigned_lines(i).ship_to_location_id:= l_physical_location_id;
12082                 -- AGDUMMY TODO
12083             l_dlvy_assigned_lines(i).physical_ship_to_location_id := l_physical_location_id;
12084   	     END IF;
12085              --#DUM_LOC(E)
12086 
12087 	 EXIT WHEN i = p_dlvy_assigned_lines.LAST;
12088          i := p_dlvy_assigned_lines.NEXT(i);
12089          END LOOP;
12090       END IF;
12091     END IF;
12092 
12093     IF p_action_code = G_ASSIGN_DLVY_TRIP THEN
12094 
12095      IF p_target_trip.trip_id IS NOT NULL  THEN
12096                                                         --  has been passed
12097        IF p_target_trip_assign_dels.COUNT = 0 THEN
12098           OPEN c_get_trip_dlvy(p_target_trip.trip_id); -- or container_id
12099           LOOP
12100                FETCH c_get_trip_dlvy INTO l_delivery_rec;
12101       	       EXIT WHEN c_get_trip_dlvy%NOTFOUND;
12102 
12103 	       --#DUM_LOC(S)
12104 	        WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12105 		        p_internal_cust_location_id  => l_delivery_rec.ultimate_dropoff_location_id,
12106 	            x_internal_org_location_id   => l_physical_location_id,
12107                 x_return_status              => l_return_status);
12108 
12109 	       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12110   		        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12111 		            raise FND_API.G_EXC_UNEXPECTED_ERROR;
12112 	            END IF;
12113 	       END IF;
12114 
12115 	       IF (l_physical_location_id IS NOT NULL) THEN
12116   	         --
12117 	         IF l_debug_on THEN
12118 		        WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_delivery_rec.ultimate_dropoff_location_id||' is a dummy location');
12119 	         END IF;
12120 	         --
12121 	         l_delivery_rec.ultimate_dropoff_location_id := l_physical_location_id;
12122                  -- AGDUMMY TODO
12123              l_delivery_rec.physical_dropoff_location_id := l_physical_location_id;
12124 	       END IF;
12125                --#DUM_LOC(E)
12126 
12127 	       l_trip_del_cnt := l_trip_del_cnt + 1;
12128                l_target_trip_assign_dels(l_trip_del_cnt) := l_delivery_rec;
12129            END LOOP;
12130            CLOSE c_get_trip_dlvy;
12131        ELSE
12132        l := p_target_trip_assign_dels.FIRST;
12133        LOOP
12134            l_target_trip_assign_dels(l) := p_target_trip_assign_dels(l);
12135            -- AGDUMMY
12136 
12137 	   --#DUM_LOC(S)
12138 	    WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12139 		p_internal_cust_location_id  => l_target_trip_assign_dels(l).ultimate_dropoff_location_id,
12140 	        x_internal_org_location_id   => l_physical_location_id,
12141                 x_return_status              => l_return_status);
12142 
12143 	   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12144   	      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12145 		  raise FND_API.G_EXC_UNEXPECTED_ERROR;
12146 	      END IF;
12147 	   END IF;
12148 
12149 	   IF (l_physical_location_id IS NOT NULL) THEN
12150   	      --
12151 	      IF l_debug_on THEN
12152 		    WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_target_trip_assign_dels(l).ultimate_dropoff_location_id||' is a dummy location');
12153 	      END IF;
12154 	      --
12155 	      l_target_trip_assign_dels(l).ultimate_dropoff_location_id := l_physical_location_id;
12156               -- AGDUMMY TODO
12157               l_target_trip_assign_dels(l).physical_dropoff_location_id := l_physical_location_id;
12158 	   END IF;
12159            --#DUM_LOC(E)
12160 
12161 	   EXIT WHEN l = p_target_trip_assign_dels.LAST;
12162            l := p_target_trip_assign_dels.NEXT(l);
12163        END LOOP;
12164        END IF;
12165 
12166        IF p_target_trip_dlvy_lines.COUNT = 0  THEN --AND p_action_code <> G_ASSIGN_DLVY_TRIP
12167           IF p_action_code = G_ASSIGN_DLVY_TRIP THEN
12168               OPEN c_get_trip_details_std(p_target_trip.trip_id); -- or container_id
12169               LOOP
12170                    FETCH c_get_trip_details_std INTO l_detail_rec;
12171                    EXIT WHEN c_get_trip_details_std%NOTFOUND;
12172 
12173                --#DUM_LOC(S)
12174                    WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12175                    p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
12176                    x_internal_org_location_id   => l_physical_location_id,
12177                    x_return_status              => l_return_status);
12178 
12179                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12180                         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12181                             raise FND_API.G_EXC_UNEXPECTED_ERROR;
12182                         END IF;
12183                    END IF;
12184 
12185                IF (l_physical_location_id IS NOT NULL) THEN
12186                  --
12187                  IF l_debug_on THEN
12188                     WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
12189                  END IF;
12190                  --
12191                  l_detail_rec.ship_to_location_id:= l_physical_location_id;
12192                      -- AGDUMMY TODO
12193                  l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
12194                END IF;
12195                    --#DUM_LOC(E)
12196 
12197                l_trip_detail_cnt := l_trip_detail_cnt + 1;
12198                l_target_trip_dlvy_lines(l_trip_detail_cnt) := l_detail_rec;
12199               END LOOP;
12200               CLOSE c_get_trip_details_std;
12201          ELSE
12202             OPEN c_get_trip_details(p_target_trip.trip_id); -- or container_id
12203               LOOP
12204                    FETCH c_get_trip_details INTO l_detail_rec;
12205                    EXIT WHEN c_get_trip_details%NOTFOUND;
12206 
12207                --#DUM_LOC(S)
12208                    WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12209                    p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
12210                    x_internal_org_location_id   => l_physical_location_id,
12211                    x_return_status              => l_return_status);
12212 
12213                    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12214                         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12215                             raise FND_API.G_EXC_UNEXPECTED_ERROR;
12216                         END IF;
12217                    END IF;
12218 
12219                IF (l_physical_location_id IS NOT NULL) THEN
12220                  --
12221                  IF l_debug_on THEN
12222                     WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
12223                  END IF;
12224                  --
12225                  l_detail_rec.ship_to_location_id:= l_physical_location_id;
12226                      -- AGDUMMY TODO
12227                  l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
12228                END IF;
12229                    --#DUM_LOC(E)
12230 
12231                l_trip_detail_cnt := l_trip_detail_cnt + 1;
12232                l_target_trip_dlvy_lines(l_trip_detail_cnt) := l_detail_rec;
12233               END LOOP;
12234               CLOSE c_get_trip_details;
12235          END IF;
12236        ELSE
12237         l := p_target_trip_dlvy_lines.FIRST;
12238        LOOP
12239            l_target_trip_dlvy_lines(l) := p_target_trip_dlvy_lines(l);
12240 
12241 	   --#DUM_LOC(S)
12242 	   WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12243 	      p_internal_cust_location_id  => l_target_trip_dlvy_lines(l).ship_to_location_id,
12244               x_internal_org_location_id   => l_physical_location_id,
12245               x_return_status              => l_return_status);
12246 
12247  	   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12248 	     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12249 	        raise FND_API.G_EXC_UNEXPECTED_ERROR;
12250 	     END IF;
12251     	   END IF;
12252 
12253   	   IF (l_physical_location_id IS NOT NULL) THEN
12254   	      --
12255 	      IF l_debug_on THEN
12256 		  WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_target_trip_dlvy_lines(l).ship_to_location_id||' is a dummy location');
12257 	      END IF;
12258 	      --
12259 	      l_target_trip_dlvy_lines(l).ship_to_location_id:= l_physical_location_id;
12260               -- AGDUMMY TODO
12261               l_target_trip_dlvy_lines(l).physical_ship_to_location_id := l_physical_location_id;
12262 	   END IF;
12263            --#DUM_LOC(E)
12264 
12265 	   EXIT WHEN l = p_target_trip_dlvy_lines.LAST;
12266 	   l := p_target_trip_dlvy_lines.NEXT(l);
12267         END LOOP;
12268        END IF;
12269 
12270        IF p_target_trip_incl_stops.COUNT = 0 THEN
12271           OPEN c_get_trip_stops(p_target_trip.trip_id); -- or container_id
12272           LOOP
12273                --#DUM_LOC(S)
12274 	       --Made changes in the cursor only.
12275 	       --#DUM_LOC(E)
12276 	       FETCH c_get_trip_stops INTO l_stop_rec;
12277                EXIT WHEN c_get_trip_stops%NOTFOUND;
12278 	       l_trip_stops_cnt := l_trip_stops_cnt + 1;
12279                l_target_trip_incl_stops(l_trip_stops_cnt) := l_stop_rec;
12280           END LOOP;
12281           CLOSE c_get_trip_stops;
12282        ELSE
12283 
12284 	/* SBAKSHI 8/24
12285 	   We should have p_target_trip_incl_stops sorted by planned arrival date
12286 	   p_target_trip_incl_stops is IN RECORD record
12287 	   Need to make a local record structure, for this purpose.
12288 	   l_target_sort_trip_incl_stops
12289 	*/
12290 
12291    	   sort_stop_table_asc(
12292 		 p_stop_table	   => p_target_trip_incl_stops,
12293 		 x_sort_stop_table => l_target_trip_incl_sort_stops,
12294 		 x_return_status   => l_return_status);
12295 
12296 
12297  	   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12298 	     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12299 	        raise FND_API.G_EXC_UNEXPECTED_ERROR;
12300 	     END IF;
12301       END IF;
12302 
12303 	 -- l := p_target_trip_incl_stops.FIRST;
12304 
12305 	   l := l_target_trip_incl_sort_stops.FIRST;
12306 
12307 	   LOOP
12308            --l_target_trip_incl_stops(l) := p_target_trip_incl_stops(l);
12309 	     l_target_trip_incl_stops(l) := l_target_trip_incl_sort_stops(l);
12310 
12311 	   -- AGDUMMY
12312            -- Use physical_location_id from the record structure instead
12313            -- Also sort the input p_target_trip_incl_stops by planned_arrival_date
12314            -- One trip can have more than one set of dummy-physical stop pairs - wrudge 8/20
12315 	   --#DUM_LOC(S) (Using the record structure)
12316 
12317 	   IF (l_target_trip_incl_stops(l).physical_location_id IS NOT NULL) THEN
12318 	       --
12319 	       IF l_debug_on THEN
12320 		   WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_target_trip_incl_stops(l).stop_location_id||' is a dummy location');
12321 	       END IF;
12322 	       --
12323 	       l_target_trip_incl_stops(l).stop_location_id:=l_target_trip_incl_stops(l).physical_location_id;
12324 	   END IF;
12325 	   --#DUM_LOC(E)
12326 
12327 	   --  EXIT WHEN l = p_target_trip_incl_stops.LAST;
12328            --  l := p_target_trip_incl_stops.NEXT(l);
12329 
12330 	   EXIT WHEN l = l_target_trip_incl_sort_stops.LAST;
12331 	   l := l_target_trip_incl_sort_stops.NEXT(l);
12332 
12333  	   -- SBAKSHI 8/24
12334 	   END LOOP;
12335 
12336        END IF;
12337 
12338        OPEN c_gettripdetails(p_target_trip.trip_id);
12339        FETCH c_gettripdetails into l_target_trip;
12340        CLOSE c_gettripdetails;
12341      END IF;
12342 
12343      -- AGDUMMY
12344      -- Convert the PICKUP and DROPOFF for p_target_tripstops
12345 
12346      -- #DUM_LOC(S)
12347      -- p_target_tripstops.PICKUP_LOCATION_ID
12348 
12349      WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12350 	 p_internal_cust_location_id  => p_target_tripstops.pickup_location_id,
12351         x_internal_org_location_id   => l_physical_location_id,
12352         x_return_status              => l_return_status);
12353 
12354      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12355         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12356            raise FND_API.G_EXC_UNEXPECTED_ERROR;
12357         END IF;
12358      END IF;
12359 
12360      IF (l_physical_location_id IS NOT NULL) THEN
12361         --
12362         IF l_debug_on THEN
12363           WSH_DEBUG_SV.logmsg(l_module_name,'Location '||p_target_tripstops.pickup_location_id||' is a dummy location');
12364         END IF;
12365 	--
12366 	    p_target_tripstops.pickup_location_id:=l_physical_location_id;
12367      END IF;
12368 
12369      --	p_target_tripstops.DROPOFF_LOCATION_ID
12370 
12371      WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
12372 	    p_internal_cust_location_id  => p_target_tripstops.dropoff_location_id,
12373         x_internal_org_location_id   => l_physical_location_id,
12374         x_return_status              => l_return_status);
12375 
12376      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12377         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12378            raise FND_API.G_EXC_UNEXPECTED_ERROR;
12379         END IF;
12380      END IF;
12381 
12382      IF (l_physical_location_id IS NOT NULL) THEN
12383         --
12384         IF l_debug_on THEN
12385           WSH_DEBUG_SV.logmsg(l_module_name,'Location '||p_target_tripstops.dropoff_location_id||' is a dummy location');
12386         END IF;
12387 	--
12388 	    p_target_tripstops.dropoff_location_id:=l_physical_location_id;
12389      END IF;
12390      --#DUM_LOC(E)
12391 
12392      IF l_debug_on THEN
12393         WSH_DEBUG_SV.logmsg(l_module_name,'p_target_tripstops.PICKUP_STOP_ID '||p_target_tripstops.PICKUP_STOP_ID);
12394         WSH_DEBUG_SV.logmsg(l_module_name,'p_target_tripstops.PICKUP_STOP_SEQ '||p_target_tripstops.PICKUP_STOP_SEQ);
12395         WSH_DEBUG_SV.logmsg(l_module_name,'p_target_tripstops.DROPOFF_STOP_ID '||p_target_tripstops.DROPOFF_STOP_ID);
12396         WSH_DEBUG_SV.logmsg(l_module_name,'p_target_tripstops.DROPOFF_STOP_SEQ '||p_target_tripstops.DROPOFF_STOP_SEQ);
12397         WSH_DEBUG_SV.logmsg(l_module_name,'p_target_tripstops.PICKUP_LOCATION_ID '||p_target_tripstops.PICKUP_LOCATION_ID);
12398         WSH_DEBUG_SV.logmsg(l_module_name,'p_target_tripstops.DROPOFF_LOCATION_ID '||p_target_tripstops.DROPOFF_LOCATION_ID);
12399      END IF;
12400      --
12401     END IF; -- G_ASSIGN_DLVY_TRIP
12402     --
12403     IF l_debug_on THEN
12404         WSH_DEBUG_SV.logmsg(l_module_name,'After populating table structures for action code '||p_action_code);
12405     END IF;
12406     --
12407 
12408     -- Populate assigned details
12409     --
12410     IF l_debug_on THEN
12411       WSH_DEBUG_SV.logmsg(l_module_name,'After populating l_comp_class_tab count : '||l_comp_class_tab.COUNT);
12412     END IF;
12413     --
12414 
12415     /*
12416     Auto create trip for delivery 	ACT	COM_FAC CUS_FAC CUS_CUS ITM_FAC ITM_ITM
12417 
12418     Assign deliveries to trip	        ADT	COM_FAC CUS_FAC CUS_CUS ITM_FAC ITM_ITM
12419                                                 FAC_MOD FAC_VEH FAC_CAR ITM_MOD ITM_CAR ITM_VEH
12420 
12421     Update (delivery, delivery leg)	UPD 	(Mode -FAC_MOD, ITM_MOD Carrier - ITM_CAR,FAC_CAR
12422     */
12423 
12424      -- Assumptions :
12425      -- 1. When you are here and have a delivery that means
12426      --    within a delivery, all attributes are valid
12427      -- When assigning deliveries to a trip
12428      -- 1. It creates trips for deliveries which do not have a trip at that point
12429      -- 2. If the deliveries under creation all have same ship method, it defaults that to the trip
12430      -- 3. Creates stops only for initial pickup and ultimate droppff, ignores intermediate
12431      -- 4. When creating trip stops creates sequence numbers arbitrarily
12432      --    ascending (eg. 10, 20, 30 etc.) as it finds new locations from the
12433      --    list of delivery
12434      -- 5. Assign to trip can pass a delivery and a target trip and
12435      --    override pickup stop and dropoff stop of those of the delivery
12436      -- 6. All validations on trip stops are based on stop sequence number and
12437      --    not stop dates
12438 
12439      -- Record types : Child, entity, group
12440      -- Child : child id, entity id
12441      -- Entity : entity id, pickup, dropoff, org, customer, group id
12442      -- Group : Group id
12443      -- Here entity : Delivery
12444      -- For every delivery : search existing groups if can be added
12445      -- If not, create a new group else add to the matching group and proceed
12446      -- search routine should take entity record as well as children table
12447 
12448 
12449       -- This loop checks only itm-itm and cus-cus for every delivery
12450       -- against every other delivery
12451       -- also itm-fac with pickup / dropoff locations of other delivery
12452       -- also com-fac, cus-fac with pickup / dropoff locations of other delivery
12453 
12454       -- Following done for ACT and ADT
12455       -- Valid groups created looking at only Exclusive constraints
12456 
12457      --
12458      --DUM_LOC We have modified record p_target_tripstops to store physical locations
12459      --in case of dummy locations.
12460 
12461     IF p_action_code = G_ASSIGN_DLVY_TRIP AND
12462        ( p_target_tripstops.pickup_location_id IS NOT NULL OR
12463          p_target_tripstops.dropoff_location_id IS NOT NULL ) THEN
12464 
12465     IF (l_target_trip.carrier_id IS NULL OR l_target_trip.MODE_OF_TRANSPORT IS NULL) AND
12466          (l_target_trip.ship_method_code IS NOT NULL) THEN
12467 
12468       l_carrier_service_inout_rec.ship_method_code := l_target_trip.ship_method_code;
12469       WSH_CARRIERS_GRP.get_carrier_service_mode(
12470                p_carrier_service_inout_rec   =>  l_carrier_service_inout_rec,
12471                x_return_status		     =>  l_return_status);
12472 
12473       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12474         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12475          IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
12476             raise FND_API.G_EXC_UNEXPECTED_ERROR;
12477          END IF;
12478          raise g_get_carrmode_failed;
12479         END IF;
12480       END IF;
12481       l_carrier := l_carrier_service_inout_rec.carrier_id;
12482       l_mode    := l_carrier_service_inout_rec.mode_of_transport;
12483 
12484     END IF; -- l_target_trip.carrier_id IS NULL OR ..
12485     IF l_debug_on THEN
12486        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);
12487     END IF;
12488 
12489       -- If carrier_id or mode is passed in, then those get preference for validation
12490       -- If they are not, they are derived from ship method if that is passed
12491 
12492     IF l_target_trip.carrier_id IS NOT NULL THEN
12493        l_carrier := l_target_trip.carrier_id;
12494     END IF;
12495     IF l_target_trip.mode_of_transport IS NOT NULL THEN
12496        l_mode := l_target_trip.mode_of_transport;
12497     END IF;
12498 
12499     IF (l_target_trip.VEHICLE_ITEM_ID IS NOT NULL AND l_target_trip.VEHICLE_ORGANIZATION_ID IS NOT NULL) THEN
12500 
12501       WSH_FTE_INTEGRATION.get_vehicle_type(
12502                p_vehicle_item_id     =>  l_target_trip.VEHICLE_ITEM_ID,
12503                p_vehicle_org_id      =>  l_target_trip.VEHICLE_ORGANIZATION_ID,
12504                x_vehicle_type_id     =>  l_vehicle_type,
12505                x_return_status       =>  l_return_status);
12506 
12507       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12508          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12509          IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
12510             raise FND_API.G_EXC_UNEXPECTED_ERROR;
12511          END IF;
12512             l_vehicle_name := WSH_UTIL_CORE.get_item_name (p_item_id => l_target_trip.VEHICLE_ITEM_ID,
12513                                                            p_organization_id => l_target_trip.VEHICLE_ORGANIZATION_ID);
12514             l_vehicle_org_name := WSH_UTIL_CORE.get_org_name (p_organization_id => l_target_trip.VEHICLE_ORGANIZATION_ID);
12515             FND_MESSAGE.SET_NAME('WSH','WSH_VEHICLE_TYPE_UNDEFINED');
12516             FND_MESSAGE.SET_TOKEN('ITEM',l_vehicle_name);
12517             FND_MESSAGE.SET_TOKEN('ORGANIZATION',l_vehicle_org_name);
12518             FND_MSG_PUB.ADD;
12519             --raise g_get_vehicletype_failed;
12520          END IF;
12521       END IF;
12522 
12523     END IF; -- l_target_trip.VEHICLE_ITEM_ID IS NOT NULL AND ..
12524 
12525     FOR i IN 1..2 LOOP
12526 
12527         -- Do the checks in calling procedure if pickup/dropoff stop/location ids have been passed
12528 
12529         IF i = 1 THEN
12530            IF p_target_tripstops.pickup_location_id IS NOT NULL AND
12531               p_target_tripstops.pickup_stop_id IS NULL THEN
12532                 l_location_id := p_target_tripstops.pickup_location_id;
12533                 IF l_debug_on THEN
12534                    WSH_DEBUG_SV.logmsg(l_module_name,'target pickup location id not null');
12535                 END IF;
12536            -- ELSIF p_target_tripstops.pickup_stop_id IS NOT NULL THEN
12537            -- If the pickupstop does not already exist in the target trip
12538            -- check here, if already exists then do not check
12539            -- not possible, p_target_tripstops.pickup_stop_id IS NOT NULL
12540            -- implies it already exists in the target trip
12541            ELSE
12542               -- Nothing to check
12543                 GOTO next_pass;
12544            END IF;
12545         ELSIF i = 2 THEN
12546            IF p_target_tripstops.dropoff_location_id IS NOT NULL AND
12547               p_target_tripstops.dropoff_stop_id IS NULL THEN
12548                 l_location_id := p_target_tripstops.dropoff_location_id;
12549                 IF l_debug_on THEN
12550                    WSH_DEBUG_SV.logmsg(l_module_name,'target dropoff location id not null');
12551                 END IF;
12552            ELSE
12553               -- Nothing to check
12554                 GOTO next_pass;
12555            END IF;
12556         END IF;
12557         --
12558         IF l_debug_on THEN
12559            WSH_DEBUG_SV.logmsg(l_module_name,'i : '||i||' l_location_id : '||l_location_id);
12560         END IF;
12561         --
12562 
12563         IF l_comp_class_tab.EXISTS(G_FACILITY_VEHICLE_NUM) AND
12564             l_vehicle_type IS NOT NULL THEN
12565 
12566             validate_constraint(
12567              p_comp_class_code          =>      G_FACILITY_VEHICLE,
12568              p_object1_type             =>      'FAC',
12569              p_object1_val_num          =>      l_location_id,
12570              p_object2_type             =>      'VHT',
12571              p_object2_val_num          =>      l_vehicle_type,
12572              x_validate_result          =>      l_validate_vehicle_result,
12573              x_failed_constraint        =>      l_failed_constraint,
12574              x_return_status            =>      l_return_status);
12575 
12576             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12577                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12578                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
12579                END IF;
12580             END IF;
12581 
12582             IF l_validate_vehicle_result <> 'S' THEN
12583               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
12584               l_failed_constraint.entity_type := G_LOCATION;
12585               l_failed_constraint.entity_line_id := l_location_id;
12586               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
12587               IF l_validate_vehicle_result = 'E' THEN
12588                x_validate_result := 'F';
12589               END IF;
12590             END IF;
12591 
12592         END IF;
12593 
12594         IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) AND
12595             l_carrier IS NOT NULL THEN
12596 
12597             validate_constraint(
12598              p_comp_class_code          =>      G_FACILITY_CARRIER,
12599              p_object1_type             =>      'FAC',
12600              p_object1_val_num          =>      l_location_id,
12601              p_object2_type             =>      'CAR',
12602              p_object2_val_num          =>      l_carrier,
12603              x_validate_result          =>      l_validate_carrier_result,
12604              x_failed_constraint        =>      l_failed_constraint,
12605              x_return_status            =>      l_return_status);
12606 
12607             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12608                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12609                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
12610                END IF;
12611             END IF;
12612 
12613             IF l_validate_carrier_result <> 'S' THEN
12614               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
12615               l_failed_constraint.entity_type := G_LOCATION;
12616               l_failed_constraint.entity_line_id := l_location_id;
12617               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
12618               IF l_validate_carrier_result = 'E' THEN
12619                x_validate_result := 'F';
12620               END IF;
12621             END IF;
12622 
12623         END IF;
12624 
12625         IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) AND
12626             l_mode IS NOT NULL THEN
12627 
12628             validate_constraint(
12629              p_comp_class_code          =>      G_FACILITY_MODE,
12630              p_object1_type             =>      'FAC',
12631              p_object1_val_num          =>      l_location_id,
12632              p_object2_type             =>      'MOD',
12633              p_object2_val_char          =>     l_mode,
12634              x_validate_result          =>      l_validate_mode_result,
12635              x_failed_constraint        =>      l_failed_constraint,
12636              x_return_status            =>      l_return_status);
12637 
12638             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12639                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12640                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
12641                END IF;
12642             END IF;
12643 
12644             IF l_validate_mode_result <> 'S' THEN
12645               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
12646               l_failed_constraint.entity_type := G_LOCATION;
12647               l_failed_constraint.entity_line_id := l_location_id;
12648               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
12649               IF l_validate_mode_result = 'E' THEN
12650                x_validate_result := 'F';
12651               END IF;
12652             END IF;
12653 
12654         END IF;
12655 
12656     <<next_pass>>
12657     null;
12658 
12659     END LOOP;
12660 
12661     END IF;
12662 
12663     k := l_delivery_info.FIRST;
12664     IF k IS NOT NULL THEN
12665       LOOP
12666 
12667         -- Skip if shipping control is SUPPLIER
12668 
12669         IF l_delivery_info(k).shipping_control = 'SUPPLIER' THEN
12670 
12671             l_supp_control_tab(l_delivery_info(k).delivery_id) := l_delivery_info(k).delivery_id;
12672             GOTO next_delivery;
12673 
12674         END IF;
12675 
12676         l_group_id         :=0;
12677         l_found            := FALSE;
12678 
12679         IF p_action_code IN (G_AUTOCRT_DLVY_TRIP,G_ASSIGN_DLVY_TRIP, G_AUTOCRT_MDC) THEN
12680          l_entity_tab(l_delivery_info(k).delivery_id).entity_id := l_delivery_info(k).delivery_id;
12681          l_entity_tab(l_delivery_info(k).delivery_id).organization_id := l_delivery_info(k).organization_id;
12682          l_entity_tab(l_delivery_info(k).delivery_id).initial_pickup_location_id := l_delivery_info(k).initial_pickup_location_id;
12683          l_entity_tab(l_delivery_info(k).delivery_id).ultimate_dropoff_location_id := l_delivery_info(k).ultimate_dropoff_location_id;
12684          l_entity_tab(l_delivery_info(k).delivery_id).initial_pickup_date := l_delivery_info(k).initial_pickup_date;
12685          l_entity_tab(l_delivery_info(k).delivery_id).ultimate_dropoff_date := l_delivery_info(k).ultimate_dropoff_date;
12686          l_entity_tab(l_delivery_info(k).delivery_id).physical_dropoff_location_id := l_delivery_info(k).physical_dropoff_location_id;
12687          l_entity_tab(l_delivery_info(k).delivery_id).intmed_ship_to_location_id := l_delivery_info(k).intmed_ship_to_location_id;
12688          l_entity_tab(l_delivery_info(k).delivery_id).ship_method_code := l_delivery_info(k).ship_method_code;
12689          l_entity_tab(l_delivery_info(k).delivery_id).carrier_id := l_delivery_info(k).carrier_id;
12690          l_entity_tab(l_delivery_info(k).delivery_id).mode_of_transport := l_delivery_info(k).mode_of_transport;
12691          l_entity_tab(l_delivery_info(k).delivery_id).customer_id := l_delivery_info(k).customer_id;
12692          l_entity_tab(l_delivery_info(k).delivery_id).party_id := l_delivery_info(k).party_id;
12693          l_entity_tab(l_delivery_info(k).delivery_id).shipment_direction := l_delivery_info(k).shipment_direction;
12694          l_entity_tab(l_delivery_info(k).delivery_id).shipping_control := l_delivery_info(k).shipping_control;
12695          --
12696          IF l_debug_on THEN
12697             WSH_DEBUG_SV.logmsg(l_module_name,'Created l_entity_tab with index : '||l_delivery_info(k).delivery_id||' for delivery index '||k);
12698        WSH_DEBUG_SV.logmsg(l_module_name,'l_entity_tab(l_delivery_info(k).delivery_id).entity_id : '||l_entity_tab(l_delivery_info(k).delivery_id).entity_id);
12699        WSH_DEBUG_SV.logmsg(l_module_name,'l_entity_tab(l_delivery_info(k).delivery_id).initial_pickup_location_id : '||l_entity_tab(l_delivery_info(k).delivery_id).initial_pickup_location_id);
12700        WSH_DEBUG_SV.logmsg(l_module_name,'l_entity_tab(l_delivery_info(k).delivery_id).ultimate_dropoff_location_id : '||l_entity_tab(l_delivery_info(k).delivery_id).ultimate_dropoff_location_id);
12701        WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info(k).initial_pickup_location_id : '||l_delivery_info(k).initial_pickup_location_id);
12702        WSH_DEBUG_SV.logmsg(l_module_name,'l_delivery_info(k).ultimate_dropoff_location_id : '||l_delivery_info(k).ultimate_dropoff_location_id);
12703          END IF;
12704          --
12705 
12706          IF k <> l_delivery_info.FIRST THEN
12707 
12708             search_matching_group(
12709                   p_entity_type           => 'DLVY',
12710                   p_action_code           => p_action_code,
12711                   p_children_info         => l_dlvy_assigned_lines,
12712                   p_comp_class_tab        => l_comp_class_tab,
12713                   p_target_stops_info     => p_target_tripstops,
12714                   p_entity_rec            => l_entity_tab(l_delivery_info(k).delivery_id),
12715                   p_target_trip_id        => l_target_trip.trip_id,
12716                   p_entity_tab            => l_entity_tab,
12717                   p_group_tab             => x_group_info,
12718                   x_failed_constraints    => l_failed_constraints,
12719                   x_group_id              => l_group_id,
12720                   x_found                 => l_found,
12721                   x_return_status         => l_return_status);
12722             --
12723             IF l_debug_on THEN
12724               WSH_DEBUG_SV.logmsg(l_module_name,'Called search_matching_group return status : '||l_return_status||' Group found ? '||l_group_id);
12725             END IF;
12726             --
12727 
12728             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12729                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12730                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
12731                END IF;
12732             END IF;
12733 
12734          END IF;
12735 
12736          IF l_found THEN
12737               l_entity_tab(l_delivery_info(k).delivery_id).group_id := l_group_id;
12738          ELSE
12739 
12740               create_valid_entity_group(
12741                   p_entity_rec            => l_entity_tab(l_delivery_info(k).delivery_id),
12742                   p_group_tab             => x_group_info,
12743                   x_return_status         => l_return_status);
12744               --
12745               IF l_debug_on THEN
12746                  WSH_DEBUG_SV.logmsg(l_module_name,'Called create_valid_entity_group return status : '||l_return_status);
12747               END IF;
12748               --
12749 
12750               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12751                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12752                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
12753                   END IF;
12754               END IF;
12755 
12756          END IF;
12757 
12758       -- Following done only for ADT
12759          IF p_action_code = G_ASSIGN_DLVY_TRIP THEN
12760 
12761          -- Here check the delivery against target trip for exclusive constraints
12762          -- com -fac, cus - fac, itm - fac for each delivery against trip stops
12763          -- itm -mod, itm - car and fac-mod, fac-car
12764          -- org - car, org - mode will not be stored in constraints table 11/6
12765          -- itm - itm, cus - cus
12766          -- Any delivery that is violating, remove from the group
12767 
12768             check_dlvy_against_trip(
12769                  p_entity_type         => 'DLVY',
12770                  p_delivery_rec        => l_delivery_info(k),
12771                  p_entity_id           => l_delivery_info(k).delivery_id,
12772                  p_detail_tab          => l_dlvy_assigned_lines,
12773                  p_comp_class_tab      => l_comp_class_tab,
12774                  p_target_stops_info   => p_target_tripstops,
12775                  p_target_trip         => l_target_trip,
12776                  p_target_tripstops    => l_target_trip_incl_stops,
12777                  p_target_dlvy         => l_target_trip_assign_dels,
12778                  p_target_dlvy_lines   => l_target_trip_dlvy_lines,
12779                  x_failed_constraints  => l_failed_constraints,
12780                  x_validate_result     => l_validate_result,
12781                  x_return_status       => l_return_status);
12782             --
12783             IF l_debug_on THEN
12784                WSH_DEBUG_SV.logmsg(l_module_name,'Called check_dlvy_against_trip return status : '||l_return_status||' validate result : '||l_validate_result);
12785             END IF;
12786             --
12787 
12788             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12789                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12790                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
12791                 END IF;
12792             END IF;
12793 
12794             IF l_return_status IN (WSH_UTIL_CORE.G_RET_STS_SUCCESS,WSH_UTIL_CORE.G_RET_STS_WARNING)
12795                THEN
12796                IF l_validate_result = 'F' THEN
12797                   -- Remove delivery from the line group
12798                   -- add to the failed lines
12799                   l_failed_lc := l_failed_lc + 1;
12800                   l_entity_tab.DELETE(l_delivery_info(k).delivery_id);
12801                   x_failed_lines(l_failed_lc).entity_line_id := l_delivery_info(k).delivery_id;
12802                   x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
12803 
12804                END IF;
12805 
12806             END IF;
12807 
12808          END IF; -- ADT
12809 
12810          l_dummy_failed_lc := l_dummy_failed_lc + 1;
12811          l_dummy_failed_lines(l_dummy_failed_lc).entity_line_id := l_delivery_info(k).delivery_id;
12812          l_dummy_failed_lines(l_dummy_failed_lc).failed_line_index := l_dummy_failed_lc;
12813 
12814          -- Populate x_line_groups table if l_entity_tab(l_delivery_info(k).delivery_id) exists
12815          -- Best place to populate x_line_groups is in
12816          -- validate_positive_constraint as that has the latest l_entity_tab
12817 
12818         END IF; -- ADT ACT
12819 
12820         IF p_action_code IN (G_UPDATE_DLVY,G_CREATE_DLVY) THEN
12821 
12822          -- Need to skip an Inbound delivery
12823          -- if the trip's status is "In Transit" or "Closed"
12824 
12825          IF l_delivery_info(k).status_code IN ('IT','CL') AND
12826                l_delivery_info(k).shipment_direction = 'I' THEN
12827                GOTO next_delivery;
12828          END IF;
12829 
12830          check_upd_dlvy(
12831                  p_delivery_rec        => l_delivery_info(k),
12832                  p_detail_tab          => l_dlvy_assigned_lines,
12833                  p_comp_class_tab      => l_comp_class_tab,
12834                  x_failed_constraints  => l_failed_constraints,
12835                  x_validate_result     => l_validate_result,
12836                  x_return_status       => l_return_status);
12837          --
12838          IF l_debug_on THEN
12839            WSH_DEBUG_SV.logmsg(l_module_name,'Called check_upd_dlvy return status : '||l_return_status||' validate result : '||l_validate_result);
12840          END IF;
12841          --
12842 
12843          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12844             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12845 
12846                raise FND_API.G_EXC_UNEXPECTED_ERROR;
12847             END IF;
12848          END IF;
12849 
12850          IF l_return_status IN (WSH_UTIL_CORE.G_RET_STS_SUCCESS,WSH_UTIL_CORE.G_RET_STS_WARNING) THEN
12851 
12852             IF l_validate_result = 'F' THEN
12853                -- Remove delivery from the line group
12854                -- add to the failed lines
12855                l_failed_lc := l_failed_lc + 1;
12856                x_failed_lines(l_failed_lc).entity_line_id := l_delivery_info(k).delivery_id;
12857                x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
12858 
12859                --
12860                IF l_debug_on THEN
12861                   WSH_DEBUG_SV.logmsg(l_module_name,'Adding failed delivery : '||l_delivery_info(k).delivery_id);
12862                END IF;
12863                --
12864 
12865             ELSE
12866 
12867                -- Populate x_line_groups table
12868                l_linegroup_indx := l_linegroup_indx + 1;
12869                x_line_groups(l_linegroup_indx).line_group_index := l_linegroup_indx;
12870                x_line_groups(l_linegroup_indx).entity_line_id   := l_delivery_info(k).delivery_id;
12871 
12872                --
12873                IF l_debug_on THEN
12874                   WSH_DEBUG_SV.logmsg(l_module_name,'Adding to linegroup delivery : '||l_delivery_info(k).delivery_id);
12875                END IF;
12876                --
12877 
12878             END IF;
12879 
12880          END IF;
12881 
12882 
12883         END IF;
12884 
12885         <<next_delivery>>
12886 
12887         EXIT WHEN k = l_delivery_info.LAST;
12888         k := l_delivery_info.NEXT(k);
12889 
12890       END LOOP;
12891     END IF;
12892 
12893     IF p_action_code IN (G_AUTOCRT_DLVY_TRIP,G_ASSIGN_DLVY_TRIP, G_AUTOCRT_MDC) AND
12894         (l_supp_control_tab.COUNT <> l_delivery_info.COUNT) THEN
12895       -- For each group / target trip
12896       -- find out list of stops to be created
12897       -- validate org - fac, cus - fac, itm -fac for must be constraints for each delivery
12898       -- shipmethod for the trip is populated only if all deliveries have same
12899       -- hence no need to validate fac - car fac - mode, itm - car, itm - mode for ACT
12900       -- For ADT : for each delivery validate these against those of the trip
12901 
12902       -- If ACT
12903       -- For each group created,
12904       -- check for violating group elements
12905       -- considering only positive constraints
12906       -- Remove group elements (deliveries) that are violating
12907       -- Handle more than one facilities (item also here or at dlvb ?) in same trip (group)
12908       -- having different must be carrier / mode
12909       -- : Put them in separate groups
12910 
12911       -- If ADT
12912       -- For each group created, check against target trip
12913       -- for positive constraints
12914       -- Remove violating group elements (deliveries) from the group
12915 
12916 
12917       validate_positive_constraint(
12918                     p_action_code         => p_action_code,
12919                     p_comp_class_tab      => l_comp_class_tab,
12920                     p_entity_tab          => l_entity_tab,
12921                     p_group_tab           => x_group_info,
12922                     p_detail_tab          => l_dlvy_assigned_lines,
12923                     p_target_trip         => l_target_trip,
12924                     p_target_tripstops    => l_target_trip_incl_stops,
12925                     p_target_stops_info   => p_target_tripstops,
12926                     x_line_groups         => x_line_groups,
12927                     x_failed_lines        => x_failed_lines,
12928                     x_failed_constraints  => l_failed_constraints,
12929                     x_return_status       => l_return_status);
12930       --
12931       IF l_debug_on THEN
12932         WSH_DEBUG_SV.logmsg(l_module_name,'Called validate_positive_constraint return status : '||l_return_status);
12933       END IF;
12934       --
12935 
12936       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
12937          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
12938             raise FND_API.G_EXC_UNEXPECTED_ERROR;
12939          END IF;
12940       END IF;
12941 
12942     END IF; -- ACT ADT
12943 
12944     IF l_supp_control_tab.COUNT > 0 THEN
12945 
12946         -- Populate line_groups and group
12947         -- Add to x_group_info
12948         l_group_count := x_group_info.COUNT + 1;
12949         x_group_info(l_group_count).group_index := l_group_count;
12950         x_group_info(l_group_count).line_group_id := l_group_count;
12951 
12952         i := l_supp_control_tab.FIRST;
12953         LOOP
12954 
12955            -- Populate x_line_groups table
12956            l_linegroup_indx := x_line_groups.COUNT + 1;
12957            x_line_groups(l_linegroup_indx).line_group_index := l_linegroup_indx;
12958            x_line_groups(l_linegroup_indx).entity_line_id   := l_supp_control_tab(i);
12959            x_line_groups(l_linegroup_indx).line_group_id    := l_group_count;
12960 
12961            EXIT WHEN i=l_supp_control_tab.LAST;
12962            i := l_supp_control_tab.NEXT(i);
12963         END LOOP;
12964 
12965     END IF;
12966 
12967     IF x_validate_result = 'F' THEN  -- Means for G_ASSIGN_DLVY_TRIP
12968     /*
12969     IF l_validate_vehicle_result = 'E' OR l_validate_mode_result = 'E' OR
12970        l_validate_carrier_result = 'E' THEN  -- Means for G_ASSIGN_DLVY_TRIP
12971     */
12972                                              -- one or more of the input locations have failed
12973         IF x_failed_lines.COUNT > 0 THEN
12974            x_failed_lines.DELETE;
12975         END IF;
12976         -- Need to populate all input lines into x_failed_lines
12977         i := l_dummy_failed_lines.FIRST;
12978         LOOP
12979 
12980            x_failed_lines(i) := l_dummy_failed_lines(i);
12981 
12982            EXIT WHEN i=l_dummy_failed_lines.LAST;
12983            i := l_dummy_failed_lines.NEXT(i);
12984         END LOOP;
12985 
12986         -- delete entries from x_group_info and x_line_groups
12987         --x_group_info.DELETE;
12988         --x_line_groups.DELETE;
12989     ELSIF x_group_info.COUNT > 1 OR x_failed_lines.COUNT > 0 THEN  -- Supplier controlled can be 2
12990         x_validate_result := 'F';
12991         IF x_group_info.COUNT > 1 AND p_action_code = G_ASSIGN_DLVY_TRIP THEN
12992            -- Put all input lines in incompatible groups into failed lines
12993 
12994            -- After changing the logic to form groups in case of
12995            -- assign, the following list of groups will only contain
12996            -- mutually incompatible groups
12997            -- not the always successful groups
12998            i := x_group_info.FIRST;
12999            LOOP
13000 
13001              -- Will not delete these lines from linegroups
13002              -- Hence for this case the sum of failed lines and
13003              -- lines in linegroups will exceed number of input lines
13004              -- by these lines in linegroups
13005              -- Will not delete these incompatible groups
13006              j := x_line_groups.FIRST;
13007              LOOP
13008 
13009                 IF x_line_groups(j).line_group_id <> x_group_info(i).line_group_id THEN
13010                    GOTO next_linegroup;
13011                 END IF;
13012 
13013                 -- Add to failed lines
13014                 l_failed_lc := x_failed_lines.COUNT + 1;
13015                 x_failed_lines(l_failed_lc).entity_line_id := x_line_groups(j).entity_line_id;
13016                 x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
13017 
13018 
13019                 <<next_linegroup>>
13020 
13021                 EXIT WHEN j=x_line_groups.LAST;
13022                 j := x_line_groups.NEXT(j);
13023              END LOOP;
13024 
13025              EXIT WHEN i=x_group_info.LAST;
13026              i := x_group_info.NEXT(i);
13027            END LOOP;
13028         END IF;
13029     END IF;
13030 
13031     IF x_failed_lines.COUNT = 0 AND (p_action_code = G_AUTOCRT_DLVY_TRIP OR p_action_code = G_AUTOCRT_MDC) THEN
13032         l_failed_constraints.DELETE;
13033     END IF;
13034 
13035     --  Loop over l_failed_constraints to add to the mesage stack
13036 
13037     stack_messages (
13038              p_failed_constraints       => l_failed_constraints,
13039              x_msg_count                => x_msg_count,
13040              x_msg_data                 => x_msg_data,
13041              x_return_status            => l_return_status);
13042     --
13043     IF l_debug_on THEN
13044         WSH_DEBUG_SV.logmsg(l_module_name,'Called stack_messages return status : '||l_return_status);
13045     END IF;
13046     --
13047 
13048     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13049          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13050             raise FND_API.G_EXC_UNEXPECTED_ERROR;
13051          END IF;
13052     END IF;
13053 
13054     -- Now can get x_validate_result = 'F' with x_group_info.COUNT = 1 and
13055     -- x_failed_lines.COUNT = 0 in case of assign delivery to trip
13056     -- Means there is violation for input pickup/dropoff stop/location
13057 
13058     IF x_validate_result = 'F' THEN
13059         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
13060 
13061     ELSIF l_failed_constraints.COUNT > 0 THEN
13062 
13063         x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
13064     END IF;
13065 
13066 
13067     --
13068     IF l_debug_on THEN
13069       WSH_DEBUG_SV.pop(l_module_name);
13070     END IF;
13071     --
13072 
13073 EXCEPTION
13074     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
13075       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
13076       --
13077       IF l_debug_on THEN
13078         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
13079         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
13080       END IF;
13081       --
13082     WHEN others THEN
13083       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.validate_constraint_dlvy');
13084       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
13085       --
13086       IF l_debug_on THEN
13087         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
13088         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
13089       END IF;
13090       --
13091 
13092 END validate_constraint_dlvy;
13093 
13094 --***************************************************************************--
13095 
13096 --========================================================================
13097 -- PROCEDURE : validate_constraint_dleg    Called by constraint Wrapper API
13098 --                                         and the Lane search API.
13099 --
13100 -- PARAMETERS: p_init_msg_list             FND_API.G_TRUE to reset list
13101 --             p_action_code               Predefined action code
13102 --             p_exception_list            Compatibility classes to skip if any
13103 --                                         indexed by class code numbers
13104 --             p_delivery_leg_rec          Input delivery leg record
13105 --             p_target_trip               Table of target trips for delivery leg trip search
13106 --             p_target_lane               Table of target lane for delivery leg lane search
13107 --             x_succ_trips                List of input trips that passed constraint check
13108 --             x_succ_lanes                List of input lanes that passed constraint check
13109 --             x_validate_result           Constraint Validation result : S / F
13110 --             x_msg_count                 Number of messages in the list
13111 --             x_msg_data                  Text of messages
13112 --             x_return_status             Return status
13113 -- COMMENT   : This procedure is used to perform for following actions
13114 --             A. Lane search for delivery leg (DLS)
13115 --========================================================================
13116 
13117 PROCEDURE validate_constraint_dleg(
13118              p_init_msg_list            IN      VARCHAR2 DEFAULT fnd_api.g_false,
13119              p_action_code              IN      VARCHAR2 DEFAULT NULL,
13120              p_exception_list           IN      WSH_UTIL_CORE.Column_Tab_Type,
13121              p_delivery_leg_rec         IN      dleg_ccinfo_rec_type,
13122              p_target_trip              IN      trip_ccinfo_tab_type,
13123              p_target_lane              IN      lane_ccinfo_tab_type,
13124              x_succ_trips               OUT NOCOPY  WSH_UTIL_CORE.id_tab_type,
13125              x_succ_lanes               OUT NOCOPY  WSH_UTIL_CORE.id_tab_type,
13126              x_validate_result          OUT NOCOPY  VARCHAR2,
13127              x_msg_count                OUT NOCOPY  NUMBER,
13128              x_msg_data                 OUT NOCOPY  VARCHAR2,
13129              x_return_status            OUT NOCOPY  VARCHAR2)
13130 
13131 IS
13132 
13133     cursor get_num_child_dlegs(p_delivery_leg_id IN NUMBER) IS
13134     SELECT
13135         count(*)
13136     FROM wsh_delivery_legs
13137     WHERE parent_delivery_leg_id = p_delivery_leg_id;
13138 
13139     l_orig_dlvy_puloc           NUMBER:=0;
13140     l_orig_dlvy_udloc           NUMBER:=0;
13141     l_intmed_leg                BOOLEAN:=FALSE;
13142     l_out_object2_num           NUMBER:=0;
13143     l_out_object2_char          VARCHAR2(30):=NULL;
13144 
13145     j                           NUMBER := 0;
13146     i                           NUMBER := 0;
13147     l_num_child_deliveries      NUMBER := 0;
13148     l_return_status             VARCHAR2(1);
13149     l_validate_excl_result      VARCHAR2(1) := 'S';
13150     l_carrier                   NUMBER := NULL;
13151     l_vehicle_type              NUMBER := NULL;
13152     l_mode                      VARCHAR2(30) := NULL;
13153     l_service_level             VARCHAR2(30) := NULL;
13154     l_carrier_service_inout_rec WSH_CARRIERS_GRP.Carrier_Service_InOut_Rec_Type;
13155     l_facility_id               NUMBER := 0;
13156     l_failed_constraint         line_constraint_rec_type;
13157     l_failed_constraints        line_constraint_tab_type;
13158     l_validate_carrier_result   VARCHAR2(1) := 'S';
13159     l_validate_vehicle_result   VARCHAR2(1) := 'S';
13160     l_validate_mode_result      VARCHAR2(1) := 'S';
13161     l_validate_orgfac_result    VARCHAR2(1) := 'S';
13162     l_validate_cusfac_result    VARCHAR2(1) := 'S';
13163     l_validate_supfac_result    VARCHAR2(1) := 'S';
13164     l_validate_itmfac_result    VARCHAR2(1) := 'S';
13165     l_validate_faccar_result    VARCHAR2(1) := 'S';
13166     l_validate_facveh_result    VARCHAR2(1) := 'S';
13167     l_validate_facmod_result    VARCHAR2(1) := 'S';
13168     l_validate_itmcar_result    VARCHAR2(1) := 'S';
13169     l_validate_itmveh_result    VARCHAR2(1) := 'S';
13170     l_validate_itmmod_result    VARCHAR2(1) := 'S';
13171     l_validate_result           VARCHAR2(1) := 'S';
13172 
13173     l_comp_class_tab            WSH_UTIL_CORE.Column_Tab_Type;
13174     l_detail_rec                detail_ccinfo_rec_type;
13175     l_dlvy_rec                  delivery_ccinfo_rec_type;
13176     l_dleg_dlvy_rec             delivery_ccinfo_rec_type;
13177     l_stop_rec                  stop_ccinfo_rec_type;
13178     l_detail_tab                detail_ccinfo_tab_type;
13179     l_trip_detail_tab           detail_ccinfo_tab_type;
13180     l_trip_dlvy_tab             delivery_ccinfo_tab_type;
13181     l_trip_stops_tab            stop_ccinfo_tab_type;
13182     l_target_tripstops          target_tripstop_cc_rec_type;
13183     l_entity_tab                entity_tab_type;
13184     l_line_groups               WSH_FTE_COMP_CONSTRAINT_PKG.line_group_tab_type;
13185     l_failed_lines              WSH_FTE_COMP_CONSTRAINT_PKG.failed_line_tab_type;
13186     l_group_info                WSH_FTE_COMP_CONSTRAINT_PKG.cc_group_tab_type;
13187 
13188     l_delivery_leg_rec          dleg_ccinfo_rec_type;
13189     l_physical_location_id      NUMBER := NULL;
13190 
13191     l_debug_on                  CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
13192     l_module_name               CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'validate_constraint_dleg';
13193 
13194 BEGIN
13195     x_validate_result := 'S';
13196     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
13197 
13198     g_itm_mustuse_cache.DELETE;
13199     g_itmloc_mustuse_cache.DELETE;
13200     g_itm_exclusive_cache.DELETE;
13201     g_fac_exclusive_cache.DELETE;
13202 
13203     IF FND_API.to_Boolean( p_init_msg_list ) THEN
13204          FND_MSG_PUB.initialize;
13205     END IF;
13206 
13207     IF l_debug_on THEN
13208        wsh_debug_sv.push(l_module_name);
13209        WSH_DEBUG_SV.logmsg(l_module_name,'p_init_msg_list : '||p_init_msg_list);
13210     END IF;
13211 
13212     refresh_cache(l_return_status);
13213 
13214     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13215          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13216             raise FND_API.G_EXC_UNEXPECTED_ERROR;
13217          END IF;
13218     END IF;
13219 
13220     /*
13221     Lane search for a delivery leg	DLS	FAC_MOD, FAC_CAR, ITM_CAR ITM_MOD
13222     : Input one dleg, table of lanes
13223     Output valid lanes
13224 
13225     Searching trip for a delivery leg	DST	CUS_CUS
13226     :Input one dleg, table of trips             ITM_FAC ITM_MOD ITM_CAR ITM_VEH
13227      Output : valid trips
13228 
13229     Creating  a delivery leg	        CDL	COM_FAC CUS_FAC FAC_MOD FAC_CAR ITM_FAC
13230                                                 ITM_MOD ITM_CAR SUP_FAC
13231 
13232     Editing                             UDL     COM_FAC CUS_FAC ITM_FAC FAC_MOD FAC_CAR
13233                                                 ITM_MOD ITM_CAR SUP_FAC
13234     */
13235 
13236      IF NOT p_exception_list.EXISTS(G_FACILITY_MODE_NUM) THEN
13237         l_comp_class_tab(G_FACILITY_MODE_NUM) := G_FACILITY_MODE;
13238      END IF;
13239      IF NOT p_exception_list.EXISTS(G_FACILITY_CARRIER_NUM) THEN
13240         l_comp_class_tab(G_FACILITY_CARRIER_NUM) := G_FACILITY_CARRIER;
13241      END IF;
13242      IF NOT p_exception_list.EXISTS(G_FACILITY_VEHICLE_NUM) THEN
13243         l_comp_class_tab(G_FACILITY_VEHICLE_NUM) := G_FACILITY_VEHICLE;
13244      END IF;
13245      IF NOT p_exception_list.EXISTS(G_ITEM_MODE_NUM) THEN
13246         l_comp_class_tab(G_ITEM_MODE_NUM) := G_ITEM_MODE;
13247      END IF;
13248      IF NOT p_exception_list.EXISTS(G_ITEM_CARRIER_NUM) THEN
13249         l_comp_class_tab(G_ITEM_CARRIER_NUM) := G_ITEM_CARRIER;
13250      END IF;
13251      IF NOT p_exception_list.EXISTS(G_ITEM_VEHICLE_NUM) THEN
13252         l_comp_class_tab(G_ITEM_VEHICLE_NUM) := G_ITEM_VEHICLE;
13253      END IF;
13254      IF NOT p_exception_list.EXISTS(G_SHIPORG_FACILITY_NUM) THEN
13255         l_comp_class_tab(G_SHIPORG_FACILITY_NUM) := G_SHIPORG_FACILITY;
13256      END IF;
13257      IF NOT p_exception_list.EXISTS(G_CUSTOMER_FACILITY_NUM) THEN
13258         l_comp_class_tab(G_CUSTOMER_FACILITY_NUM) := G_CUSTOMER_FACILITY;
13259      END IF;
13260      IF NOT p_exception_list.EXISTS(G_SUPPLIER_FACILITY_NUM) THEN
13261         l_comp_class_tab(G_SUPPLIER_FACILITY_NUM) := G_SUPPLIER_FACILITY;
13262      END IF;
13263      IF NOT p_exception_list.EXISTS(G_ITEM_FACILITY_NUM) THEN
13264         l_comp_class_tab(G_ITEM_FACILITY_NUM) := G_ITEM_FACILITY;
13265      END IF;
13266      IF NOT p_exception_list.EXISTS(G_CUSTOMER_CUSTOMER_NUM) THEN
13267         l_comp_class_tab(G_CUSTOMER_CUSTOMER_NUM) := G_CUSTOMER_CUSTOMER;
13268      END IF;
13269 
13270     -- AG
13271 
13272 
13273 
13274     OPEN get_num_child_dlegs(p_delivery_leg_rec.delivery_leg_id);
13275         FETCH get_num_child_dlegs into l_num_child_deliveries;
13276     CLOSE get_num_child_dlegs;
13277 
13278     /*IF l_debug_on THEN
13279         wsh_debug_sv.logmsg('p_delivery_leg_rec.delivery_leg_id : '||p_delivery_leg_rec.delivery_leg_id);
13280    END IF;*/
13281      IF l_debug_on THEN
13282             WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_leg_rec.delivery_leg_id : '||p_delivery_leg_rec.delivery_leg_id);
13283           END IF;
13284     IF l_num_child_deliveries > 0 THEN
13285         OPEN c_get_details_consol(p_delivery_leg_rec.delivery_id);
13286         LOOP
13287            FETCH c_get_details_consol INTO l_detail_rec;
13288            EXIT WHEN c_get_details_consol%NOTFOUND;
13289 
13290           /* IF l_debug_on THEN
13291                 wsh_debug_sv.logmsg('l_detail_rec.COUNT: '||l_detail_rec.COUNT);
13292            END IF;*/
13293 
13294         -- AGDUMMY
13295         -- Convert ultimate_dropoff if dummy to physical
13296         -- TODO
13297 
13298         --#DUM_LOC(S)
13299         --Check if ultimate drop off location is a dummy location
13300         WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
13301              p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
13302              x_internal_org_location_id   => l_physical_location_id,
13303              x_return_status              => l_return_status);
13304 
13305         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13306            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13307               raise FND_API.G_EXC_UNEXPECTED_ERROR;
13308            END IF;
13309         END IF;
13310 
13311         IF (l_physical_location_id IS NOT NULL) THEN
13312           --
13313           IF l_debug_on THEN
13314             WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
13315           END IF;
13316           --
13317           l_detail_rec.ship_to_location_id := l_physical_location_id;
13318           l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
13319         END IF;
13320         --#DUM_LOC(E)
13321 
13322            l_detail_tab(l_detail_tab.COUNT+1) := l_detail_rec;
13323         END LOOP;
13324         CLOSE c_get_details_consol;
13325     ELSE
13326         OPEN c_get_details(p_delivery_leg_rec.delivery_id);
13327         LOOP
13328            FETCH c_get_details INTO l_detail_rec;
13329            EXIT WHEN c_get_details%NOTFOUND;
13330 
13331 
13332         -- AGDUMMY
13333         -- Convert ultimate_dropoff if dummy to physical
13334         -- TODO
13335 
13336         --#DUM_LOC(S)
13337         --Check if ultimate drop off location is a dummy location
13338         WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
13339              p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
13340              x_internal_org_location_id   => l_physical_location_id,
13341              x_return_status              => l_return_status);
13342 
13343         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13344            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13345               raise FND_API.G_EXC_UNEXPECTED_ERROR;
13346            END IF;
13347         END IF;
13348 
13349         IF (l_physical_location_id IS NOT NULL) THEN
13350           --
13351           IF l_debug_on THEN
13352             WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
13353           END IF;
13354           --
13355           l_detail_rec.ship_to_location_id := l_physical_location_id;
13356           l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
13357         END IF;
13358         --#DUM_LOC(E)
13359 
13360            l_detail_tab(l_detail_tab.COUNT+1) := l_detail_rec;
13361         END LOOP;
13362         CLOSE c_get_details;
13363     END IF;
13364 
13365     OPEN c_get_dlvy(p_delivery_leg_rec.delivery_id);
13366     FETCH c_get_dlvy INTO l_dleg_dlvy_rec;
13367     CLOSE c_get_dlvy;
13368 
13369     -- AGDUMMY
13370     -- Convert ultimate_dropoff if dummy to physical
13371     -- TODO
13372 
13373     --#DUM_LOC(S)
13374     --Check if ultimate drop off location is a dummy location
13375     WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
13376          p_internal_cust_location_id  => l_dleg_dlvy_rec.ultimate_dropoff_location_id,
13377          x_internal_org_location_id   => l_physical_location_id,
13378          x_return_status              => l_return_status);
13379 
13380     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13381        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13382           raise FND_API.G_EXC_UNEXPECTED_ERROR;
13383        END IF;
13384     END IF;
13385 
13386     IF (l_physical_location_id IS NOT NULL) THEN
13387       --
13388       IF l_debug_on THEN
13389         WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_dleg_dlvy_rec.ultimate_dropoff_location_id||' is a dummy location');
13390       END IF;
13391       --
13392       l_dleg_dlvy_rec.ultimate_dropoff_location_id := l_physical_location_id;
13393       l_dleg_dlvy_rec.physical_dropoff_location_id := l_physical_location_id;
13394     END IF;
13395     --#DUM_LOC(E)
13396 
13397     l_orig_dlvy_puloc := l_dleg_dlvy_rec.initial_pickup_location_id;
13398     l_orig_dlvy_udloc := l_dleg_dlvy_rec.ultimate_dropoff_location_id;
13399 
13400     --#DUM_LOC(S)
13401     --Check if input dleg's drop off location is a dummy location
13402     l_delivery_leg_rec := p_delivery_leg_rec;
13403 
13404     WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
13405          p_internal_cust_location_id  => p_delivery_leg_rec.dropoffstop_location_id,
13406          x_internal_org_location_id   => l_physical_location_id,
13407          x_return_status              => l_return_status);
13408 
13409     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13410        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13411           raise FND_API.G_EXC_UNEXPECTED_ERROR;
13412        END IF;
13413     END IF;
13414 
13415     IF (l_physical_location_id IS NOT NULL) THEN
13416       --
13417       IF l_debug_on THEN
13418         WSH_DEBUG_SV.logmsg(l_module_name,'Location '||p_delivery_leg_rec.dropoffstop_location_id||' is a dummy location');
13419       END IF;
13420       --
13421       l_delivery_leg_rec.dropoffstop_location_id := l_physical_location_id;
13422       --p_delivery_leg_rec.physical_dropoff_location_id := l_physical_location_id;
13423     END IF;
13424     --#DUM_LOC(E)
13425 
13426     -- For DLL
13427     -- API for DST, CDL, UDL internally calls this
13428 
13429     -- For DLL
13430 
13431     IF p_action_code = G_DLEG_LANE_SEARCH THEN
13432 
13433       --LOOP -- over target lanes
13434       i := p_target_lane.FIRST;
13435       IF i IS NOT NULL THEN
13436         LOOP
13437 
13438            l_validate_faccar_result := 'S';
13439            l_validate_facmod_result := 'S';
13440            l_validate_itmcar_result := 'S';
13441            l_validate_itmmod_result := 'S';
13442            l_validate_result := 'S';
13443 
13444            IF l_dleg_dlvy_rec.shipping_control = 'SUPPLIER' THEN
13445               GOTO lane_nextpass;
13446            END IF;
13447 
13448            IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) THEN
13449 
13450              check_inclusive_object2(
13451                  p_comp_class_code          =>      G_FACILITY_CARRIER,
13452                  p_entity_type              =>      G_DELIVERY_LEG,
13453                  p_entity_id                =>      l_delivery_leg_rec.delivery_leg_id,
13454                  p_object1_type             =>      'FAC',
13455                  p_object1_val_num          =>      l_delivery_leg_rec.pickupstop_location_id,
13456                  p_object2_type             =>      'CAR',
13457                  p_object2_val_num          =>      p_target_lane(i).carrier_id,
13458                  x_out_object2_num          =>      l_out_object2_num,
13459                  x_out_object2_char         =>      l_out_object2_char,
13460                  x_validate_result          =>      l_validate_carrier_result,
13461                  x_failed_constraint        =>      l_failed_constraints,
13462                  x_return_status            =>      l_return_status);
13463 
13464              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13465                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13466                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
13467                 END IF;
13468              END IF;
13469 
13470              IF l_validate_carrier_result = 'F' THEN
13471                 x_validate_result := 'F';
13472                 l_validate_result := 'F';
13473                 GOTO lane_nextpass;
13474              END IF;
13475 
13476              check_inclusive_object2(
13477                  p_comp_class_code          =>      G_FACILITY_CARRIER,
13478                  p_entity_type              =>      G_DELIVERY_LEG,
13479                  p_entity_id                =>      l_delivery_leg_rec.delivery_leg_id,
13480                  p_object1_type             =>      'FAC',
13481                  p_object1_val_num          =>      l_delivery_leg_rec.dropoffstop_location_id,
13482                  p_object2_type             =>      'CAR',
13483                  p_object2_val_num          =>      p_target_lane(i).carrier_id,
13484                  x_out_object2_num          =>      l_out_object2_num,
13485                  x_out_object2_char         =>      l_out_object2_char,
13486                  x_validate_result          =>      l_validate_carrier_result,
13487                  x_failed_constraint        =>      l_failed_constraints,
13488                  x_return_status            =>      l_return_status);
13489 
13490              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13491                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13492                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
13493                 END IF;
13494              END IF;
13495 
13496              IF l_validate_carrier_result = 'F' THEN
13497                  x_validate_result := 'F';
13498                  l_validate_result := 'F';
13499                  GOTO lane_nextpass;
13500              END IF;
13501 
13502            END IF;
13503 
13504            IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) THEN
13505 
13506              check_inclusive_object2(
13507                  p_comp_class_code          =>      G_FACILITY_MODE,
13508                  p_entity_type              =>      G_DELIVERY_LEG,
13509                  p_entity_id                =>      l_delivery_leg_rec.delivery_leg_id,
13510                  p_object1_type             =>      'FAC',
13511                  p_object1_val_num          =>      l_delivery_leg_rec.pickupstop_location_id,
13512                  p_object2_type             =>      'MOD',
13513                  p_object2_val_char         =>      p_target_lane(i).mode_of_transportation_code,
13514                  x_out_object2_num          =>      l_out_object2_num,
13515                  x_out_object2_char         =>      l_out_object2_char,
13516                  x_validate_result          =>      l_validate_mode_result,
13517                  x_failed_constraint        =>      l_failed_constraints,
13518                  x_return_status            =>      l_return_status);
13519 
13520              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13521                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13522                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
13523                 END IF;
13524              END IF;
13525 
13526              IF l_validate_mode_result = 'F' THEN
13527                 x_validate_result := 'F';
13528                 l_validate_result := 'F';
13529                 GOTO lane_nextpass;
13530              END IF;
13531 
13532              check_inclusive_object2(
13533                  p_comp_class_code          =>      G_FACILITY_MODE,
13534                  p_entity_type              =>      G_DELIVERY_LEG,
13535                  p_entity_id                =>      l_delivery_leg_rec.delivery_leg_id,
13536                  p_object1_type             =>      'FAC',
13537                  p_object1_val_num          =>      l_delivery_leg_rec.dropoffstop_location_id,
13538                  p_object2_type             =>      'MOD',
13539                  p_object2_val_char         =>      p_target_lane(i).mode_of_transportation_code,
13540                  x_out_object2_num          =>      l_out_object2_num,
13541                  x_out_object2_char         =>      l_out_object2_char,
13542                  x_validate_result          =>      l_validate_mode_result,
13543                  x_failed_constraint        =>      l_failed_constraints,
13544                  x_return_status            =>      l_return_status);
13545 
13546              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13547                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13548                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
13549                 END IF;
13550              END IF;
13551 
13552              IF l_validate_mode_result = 'F' THEN
13553                 x_validate_result := 'F';
13554                 l_validate_result := 'F';
13555                 GOTO lane_nextpass;
13556              END IF;
13557 
13558 
13559            END IF;
13560 
13561            -- Proceed to check Exclusive constraints
13562            -- only if success
13563 
13564            -- FAC - CAR/MOD for dleg's locations against lane's carrier, mode
13565 
13566            IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) AND
13567               p_target_lane(i).carrier_id IS NOT NULL THEN
13568 
13569              validate_constraint(
13570                  p_comp_class_code          =>      G_FACILITY_CARRIER,
13571                  p_object1_type             =>      'FAC',
13572                  p_object1_val_num          =>      l_delivery_leg_rec.pickupstop_location_id,
13573                  p_object2_type             =>      'CAR',
13574                  p_object2_val_num          =>      p_target_lane(i).carrier_id,
13575                  x_validate_result          =>      l_validate_faccar_result,
13576                  x_failed_constraint        =>      l_failed_constraint,
13577                  x_return_status            =>      l_return_status);
13578 
13579              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13580                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13581                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
13582                 END IF;
13583              END IF;
13584 
13585              IF l_validate_faccar_result <> 'S' THEN
13586                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
13587                   l_failed_constraint.entity_type :=  G_DELIVERY_LEG;
13588                   l_failed_constraint.entity_line_id :=  l_delivery_leg_rec.delivery_leg_id;
13589                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
13590 
13591                   IF l_validate_faccar_result = 'E' THEN
13592                      x_validate_result := 'F';
13593                      l_validate_result := 'F';
13594                   END IF;
13595              END IF;
13596              -- Success can override Failure
13597 
13598              validate_constraint(
13599                  p_comp_class_code          =>      G_FACILITY_CARRIER,
13600                  p_object1_type             =>      'FAC',
13601                  p_object1_val_num          =>      l_delivery_leg_rec.dropoffstop_location_id,
13602                  p_object2_type             =>      'CAR',
13603                  p_object2_val_num          =>      p_target_lane(i).carrier_id,
13604                  x_validate_result          =>      l_validate_faccar_result,
13605                  x_failed_constraint        =>      l_failed_constraint,
13606                  x_return_status            =>      l_return_status);
13607 
13608              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13609                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13610                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
13611                 END IF;
13612              END IF;
13613 
13614              IF l_validate_faccar_result <> 'S' THEN
13615                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
13616                   l_failed_constraint.entity_type :=  G_DELIVERY_LEG;
13617                   l_failed_constraint.entity_line_id :=  l_delivery_leg_rec.delivery_leg_id;
13618                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
13619 
13620                   IF l_validate_faccar_result = 'E' THEN
13621                      x_validate_result := 'F';
13622                      l_validate_result := 'F';
13623                   END IF;
13624              END IF;
13625 
13626            END IF;
13627 
13628            IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) AND
13629               p_target_lane(i).mode_of_transportation_code IS NOT NULL THEN
13630 
13631              validate_constraint(
13632                  p_comp_class_code          =>      G_FACILITY_MODE,
13633                  p_object1_type             =>      'FAC',
13634                  p_object1_val_num          =>      l_delivery_leg_rec.pickupstop_location_id,
13635                  p_object2_type             =>      'MOD',
13636                  p_object2_val_char         =>      p_target_lane(i).mode_of_transportation_code,
13637                  x_validate_result          =>      l_validate_facmod_result,
13638                  x_failed_constraint        =>      l_failed_constraint,
13639                  x_return_status            =>      l_return_status);
13640 
13641              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13642                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13643                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
13644                 END IF;
13645              END IF;
13646 
13647              IF l_validate_facmod_result <> 'S' THEN
13648                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
13649                   l_failed_constraint.entity_type :=  G_DELIVERY_LEG;
13650                   l_failed_constraint.entity_line_id :=  l_delivery_leg_rec.delivery_leg_id;
13651                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
13652 
13653                   IF l_validate_facmod_result = 'E' THEN
13654                    x_validate_result := 'F';
13655                    l_validate_result := 'F';
13656                   END IF;
13657 
13658              END IF;
13659 
13660              validate_constraint(
13661                  p_comp_class_code          =>      G_FACILITY_MODE,
13662                  p_object1_type             =>      'FAC',
13663                  p_object1_val_num          =>      l_delivery_leg_rec.dropoffstop_location_id,
13664                  p_object2_type             =>      'MOD',
13665                  p_object2_val_char         =>      p_target_lane(i).mode_of_transportation_code,
13666                  x_validate_result          =>      l_validate_facmod_result,
13667                  x_failed_constraint        =>      l_failed_constraint,
13668                  x_return_status            =>      l_return_status);
13669 
13670              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13671                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13672                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
13673                 END IF;
13674              END IF;
13675 
13676              IF l_validate_facmod_result <> 'S' THEN
13677                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
13678                   l_failed_constraint.entity_type :=  G_DELIVERY_LEG;
13679                   l_failed_constraint.entity_line_id :=  l_delivery_leg_rec.delivery_leg_id;
13680                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
13681 
13682                   IF l_validate_facmod_result = 'E' THEN
13683                    x_validate_result := 'F';
13684                    l_validate_result := 'F';
13685                   END IF;
13686              END IF;
13687 
13688            END IF;
13689            --LOOP -- Over dleg's children details
13690            j := l_detail_tab.FIRST;
13691            IF j IS NOT NULL THEN
13692              LOOP
13693 
13694                 -- ITM - CAR/MOD for detail's item against lane's carrier, mode
13695              -- Inclusive constraints
13696              -- Not to check item levl inclusive constraints
13697              -- when entity = delivery/dleg
13698 
13699               IF l_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) THEN
13700 
13701                   check_inclusive_object2(
13702                    p_comp_class_code          =>      G_ITEM_CARRIER,
13703                    p_entity_type              =>      G_DEL_DETAIL,
13704                    p_entity_id                =>      l_detail_tab(j).delivery_detail_id,
13705                    p_object1_type             =>      'ITM',
13706                    p_object1_parent_id        =>      l_detail_tab(j).organization_id,
13707                    p_object1_val_num          =>      l_detail_tab(j).inventory_item_id,
13708                    p_object2_type             =>      'CAR',
13709                    p_object2_val_num          =>      p_target_lane(i).carrier_id,
13710                    x_out_object2_num          =>      l_out_object2_num,
13711                    x_out_object2_char         =>      l_out_object2_char,
13712                    x_validate_result          =>      l_validate_carrier_result,
13713                    x_failed_constraint        =>      l_failed_constraints,
13714                    x_return_status            =>      l_return_status);
13715 
13716                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13717                      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13718                         raise FND_API.G_EXC_UNEXPECTED_ERROR;
13719                      END IF;
13720                   END IF;
13721 
13722                   IF l_validate_carrier_result = 'F' THEN
13723                      x_validate_result := 'F';
13724                      l_validate_result := 'F';
13725                      EXIT;
13726                   END IF;
13727 
13728               END IF;
13729 
13730               IF l_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) THEN
13731 
13732                   check_inclusive_object2(
13733                    p_comp_class_code          =>      G_ITEM_MODE,
13734                    p_entity_type              =>      G_DEL_DETAIL,
13735                    p_entity_id                =>      l_detail_tab(j).delivery_detail_id,
13736                    p_object1_type             =>      'ITM',
13737                    p_object1_parent_id        =>      l_detail_tab(j).organization_id,
13738                    p_object1_val_num          =>      l_detail_tab(j).inventory_item_id,
13739                    p_object2_type             =>      'MOD',
13740                    p_object2_val_char         =>      p_target_lane(i).mode_of_transportation_code,
13741                    x_out_object2_num          =>      l_out_object2_num,
13742                    x_out_object2_char         =>      l_out_object2_char,
13743                    x_validate_result          =>      l_validate_mode_result,
13744                    x_failed_constraint        =>      l_failed_constraints,
13745                    x_return_status            =>      l_return_status);
13746 
13747                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13748                     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13749                        raise FND_API.G_EXC_UNEXPECTED_ERROR;
13750                     END IF;
13751                   END IF;
13752 
13753                   IF l_validate_mode_result = 'F' THEN
13754                      x_validate_result := 'F';
13755                      l_validate_result := 'F';
13756                      EXIT;
13757                   END IF;
13758 
13759               END IF;
13760 
13761               IF l_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) THEN
13762 
13763                  validate_constraint(   --  checks only negative constraints
13764                    p_comp_class_code          =>      G_ITEM_MODE,
13765                    p_object1_type             =>      'ITM',
13766                    p_object1_parent_id        =>      l_detail_tab(j).organization_id,
13767                    p_object2_type             =>      'MOD',
13768                    p_object1_val_num          =>      l_detail_tab(j).inventory_item_id,
13769                    p_object2_val_char         =>      p_target_lane(i).mode_of_transportation_code,
13770                    x_validate_result          =>      l_validate_itmmod_result,
13771                    x_failed_constraint        =>      l_failed_constraint,
13772                    x_return_status            =>      l_return_status);
13773 
13774                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13775                     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13776                        raise FND_API.G_EXC_UNEXPECTED_ERROR;
13777                     END IF;
13778                  END IF;
13779 
13780                  -- For exclusive constraints error with one detail in the group is error
13781                  -- But, for inclusive constraints success with one detail in the group is success
13782 
13783                  IF l_validate_itmmod_result <> 'S' THEN
13784                     l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
13785                     l_failed_constraint.entity_type :=  G_DEL_DETAIL;
13786                     l_failed_constraint.entity_line_id :=  l_detail_tab(j).delivery_detail_id;
13787                     l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
13788 
13789                     IF l_validate_itmmod_result = 'E' THEN
13790                      x_validate_result := 'F';
13791                      l_validate_result := 'F';
13792                     END IF;
13793 
13794                  END IF;
13795 
13796               END IF;
13797 
13798               IF l_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) THEN
13799 
13800                  validate_constraint(   --  checks only negative constraints
13801                    p_comp_class_code          =>      G_ITEM_CARRIER,
13802                    p_object1_type             =>      'ITM',
13803                    p_object1_parent_id        =>      l_detail_tab(j).organization_id,
13804                    p_object2_type             =>      'CAR',
13805                    p_object1_val_num          =>      l_detail_tab(j).inventory_item_id,
13806                    p_object2_val_num          =>      p_target_lane(i).carrier_id,
13807                    x_validate_result          =>      l_validate_itmcar_result,
13808                    x_failed_constraint        =>      l_failed_constraint,
13809                    x_return_status            =>      l_return_status);
13810 
13811                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13812                     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13813                        raise FND_API.G_EXC_UNEXPECTED_ERROR;
13814                     END IF;
13815                  END IF;
13816 
13817                  -- For exclusive constraints error with one detail in the group is error
13818                  -- But, for inclusive constraints success with one detail in the group is success
13819 
13820                  IF l_validate_itmcar_result <> 'S' THEN
13821                     l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
13822                     l_failed_constraint.entity_type :=  G_DEL_DETAIL;
13823                     l_failed_constraint.entity_line_id :=  l_detail_tab(j).delivery_detail_id;
13824                     l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
13825 
13826                     IF l_validate_itmcar_result = 'E' THEN
13827                      x_validate_result := 'F';
13828                      l_validate_result := 'F';
13829                     END IF;
13830 
13831                  END IF;
13832 
13833               END IF;
13834 
13835               <<det_nextpass>>
13836 
13837               EXIT WHEN j = l_detail_tab.LAST;
13838               j := l_detail_tab.NEXT(j);
13839 
13840              END LOOP;
13841            END IF;
13842 
13843            <<lane_nextpass>>
13844 
13845            IF l_validate_result = 'S' THEN
13846            -- populate x_succ_lanes
13847               x_succ_lanes(x_succ_lanes.COUNT+1) := p_target_lane(i).lane_id;
13848 
13849            END IF;
13850 
13851            EXIT WHEN i = p_target_lane.LAST;
13852            i := p_target_lane.NEXT(i);
13853 
13854         END LOOP;
13855       END IF;
13856 
13857     END IF;    --  DLS
13858 
13859     -- For DST
13860 
13861     IF p_action_code = G_DLEG_TRIP_SEARCH THEN
13862 
13863       --LOOP -- over target trips
13864       i := p_target_trip.FIRST;
13865       IF i IS NOT NULL THEN
13866         LOOP
13867 
13868           l_validate_faccar_result := 'S';
13869           l_validate_facmod_result := 'S';
13870           l_validate_itmcar_result := 'S';
13871           l_validate_itmmod_result := 'S';
13872           l_validate_result := 'S';
13873           l_validate_excl_result := 'S';
13874           l_carrier := NULL;
13875           l_mode := NULL;
13876           l_service_level := NULL;
13877 
13878           IF l_dleg_dlvy_rec.shipping_control = 'SUPPLIER' THEN
13879              GOTO next_trip;
13880           END IF;
13881 
13882            -- FAC - CAR/MOD for dleg's locations against trip's carrier, mode
13883 
13884            -- Inclusive constraints
13885            -- Proceed to check Exclusive constraints
13886            -- only if success
13887            -- ITM - CAR/MOD
13888 
13889 
13890           OPEN c_get_trip_details(p_target_trip(i).trip_id);
13891           LOOP
13892               FETCH c_get_trip_details INTO l_detail_rec;
13893               EXIT WHEN c_get_trip_details%NOTFOUND;
13894 
13895 
13896     -- AGDUMMY
13897     -- Convert ship_to if dummy to physical
13898     -- TODO
13899 
13900     --#DUM_LOC(S)
13901     --Check if ultimate drop off location is a dummy location
13902     WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
13903          p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
13904          x_internal_org_location_id   => l_physical_location_id,
13905          x_return_status              => l_return_status);
13906 
13907     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13908        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13909           raise FND_API.G_EXC_UNEXPECTED_ERROR;
13910        END IF;
13911     END IF;
13912 
13913     IF (l_physical_location_id IS NOT NULL) THEN
13914       --
13915       IF l_debug_on THEN
13916         WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
13917       END IF;
13918       --
13919       l_detail_rec.ship_to_location_id := l_physical_location_id;
13920       l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
13921     END IF;
13922     --#DUM_LOC(E)
13923 
13924               l_trip_detail_tab(l_trip_detail_tab.COUNT+1) := l_detail_rec;
13925           END LOOP;
13926           CLOSE c_get_trip_details;
13927 
13928           OPEN c_get_trip_dlvy(p_target_trip(i).trip_id);
13929           LOOP
13930               FETCH c_get_trip_dlvy INTO l_dlvy_rec;
13931               EXIT WHEN c_get_trip_dlvy%NOTFOUND;
13932 
13933 
13934     -- AGDUMMY
13935     -- Convert ultimate_dropoff if dummy to physical
13936     -- TODO
13937 
13938     --#DUM_LOC(S)
13939     --Check if ultimate drop off location is a dummy location
13940     WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
13941          p_internal_cust_location_id  => l_dlvy_rec.ultimate_dropoff_location_id,
13942          x_internal_org_location_id   => l_physical_location_id,
13943          x_return_status              => l_return_status);
13944 
13945     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
13946        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
13947           raise FND_API.G_EXC_UNEXPECTED_ERROR;
13948        END IF;
13949     END IF;
13950 
13951     IF (l_physical_location_id IS NOT NULL) THEN
13952       --
13953       IF l_debug_on THEN
13954         WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_dlvy_rec.ultimate_dropoff_location_id||' is a dummy location');
13955       END IF;
13956       --
13957       l_dlvy_rec.ultimate_dropoff_location_id := l_physical_location_id;
13958       l_dlvy_rec.physical_dropoff_location_id := l_physical_location_id;
13959     END IF;
13960     --#DUM_LOC(E)
13961 
13962               l_trip_dlvy_tab(l_trip_dlvy_tab.COUNT+1) := l_dlvy_rec;
13963           END LOOP;
13964           CLOSE c_get_trip_dlvy;
13965 
13966           OPEN c_get_trip_stops(p_target_trip(i).trip_id);
13967           LOOP
13968               FETCH c_get_trip_stops INTO l_stop_rec;
13969               EXIT WHEN c_get_trip_stops%NOTFOUND;
13970 
13971               l_trip_stops_tab(l_trip_stops_tab.COUNT+1) := l_stop_rec;
13972           END LOOP;
13973           CLOSE c_get_trip_stops;
13974 
13975           -- As this only filters open trip results by constraint violations,
13976           -- the moment a violation is found for an input trip
13977           -- no more violations are checked for that trip
13978 
13979           -- Need to check Inclusive facility as parameter2 constraints as well
13980           -- Call validate_positive_constraint
13981 
13982           l_entity_tab(l_dleg_dlvy_rec.delivery_id).entity_id := l_dleg_dlvy_rec.delivery_id;
13983           l_entity_tab(l_dleg_dlvy_rec.delivery_id).organization_id := l_dleg_dlvy_rec.organization_id;
13984           l_entity_tab(l_dleg_dlvy_rec.delivery_id).initial_pickup_location_id := l_dleg_dlvy_rec.initial_pickup_location_id;
13985           l_entity_tab(l_dleg_dlvy_rec.delivery_id).ultimate_dropoff_location_id := l_dleg_dlvy_rec.ultimate_dropoff_location_id;
13986          l_entity_tab(l_dleg_dlvy_rec.delivery_id).initial_pickup_date := l_dleg_dlvy_rec.initial_pickup_date;
13987          l_entity_tab(l_dleg_dlvy_rec.delivery_id).ultimate_dropoff_date := l_dleg_dlvy_rec.ultimate_dropoff_date;
13988           l_entity_tab(l_dleg_dlvy_rec.delivery_id).physical_dropoff_location_id := l_dleg_dlvy_rec.physical_dropoff_location_id;
13989           l_entity_tab(l_dleg_dlvy_rec.delivery_id).intmed_ship_to_location_id := l_dleg_dlvy_rec.intmed_ship_to_location_id;
13990           l_entity_tab(l_dleg_dlvy_rec.delivery_id).ship_method_code := l_dleg_dlvy_rec.ship_method_code;
13991           l_entity_tab(l_dleg_dlvy_rec.delivery_id).carrier_id := l_dleg_dlvy_rec.carrier_id;
13992           l_entity_tab(l_dleg_dlvy_rec.delivery_id).mode_of_transport := l_dleg_dlvy_rec.mode_of_transport;
13993           l_entity_tab(l_dleg_dlvy_rec.delivery_id).customer_id := l_dleg_dlvy_rec.customer_id;
13994           l_entity_tab(l_dleg_dlvy_rec.delivery_id).party_id := l_dleg_dlvy_rec.party_id;
13995           l_entity_tab(l_dleg_dlvy_rec.delivery_id).shipment_direction := l_dleg_dlvy_rec.shipment_direction;
13996           l_entity_tab(l_dleg_dlvy_rec.delivery_id).shipping_control := l_dleg_dlvy_rec.shipping_control;
13997           --
13998           IF l_debug_on THEN
13999              WSH_DEBUG_SV.logmsg(l_module_name,'Created l_entity_tab with index : '||l_dleg_dlvy_rec.delivery_id);
14000           END IF;
14001           --
14002 
14003           l_target_tripstops.pickup_stop_id        := l_delivery_leg_rec.pick_up_stop_id;
14004           l_target_tripstops.dropoff_stop_id       := l_delivery_leg_rec.drop_off_stop_id;
14005           l_target_tripstops.pickup_location_id    := l_delivery_leg_rec.pickupstop_location_id;
14006           l_target_tripstops.dropoff_location_id   := l_delivery_leg_rec.dropoffstop_location_id;
14007           -- AG 10+
14008           l_target_tripstops.pickup_stop_pa_date    := l_delivery_leg_rec.pickup_stop_pa_date;
14009           l_target_tripstops.dropoff_stop_pa_date   := l_delivery_leg_rec.dropoff_stop_pa_date;
14010 
14011           create_valid_entity_group(
14012                   p_entity_rec            => l_entity_tab(l_dleg_dlvy_rec.delivery_id),
14013                   p_group_tab             => l_group_info,
14014                   x_return_status         => l_return_status);
14015           --
14016           IF l_debug_on THEN
14017               WSH_DEBUG_SV.logmsg(l_module_name,'Called create_valid_entity_group return status : '||l_return_status);
14018           END IF;
14019           --
14020 
14021           IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14022               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14023                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
14024               END IF;
14025           END IF;
14026 
14027           validate_positive_constraint(
14028                     p_action_code         => G_ASSIGN_DLVY_TRIP,
14029                     p_comp_class_tab      => l_comp_class_tab,
14030                     p_entity_tab          => l_entity_tab,
14031                     p_group_tab           => l_group_info,
14032                     p_detail_tab          => l_detail_tab,
14033                     p_target_trip         => p_target_trip(i),
14034                     p_target_tripstops    => l_trip_stops_tab,
14035                     p_target_stops_info   => l_target_tripstops,
14036                     x_line_groups         => l_line_groups,
14037                     x_failed_lines        => l_failed_lines,
14038                     x_failed_constraints  => l_failed_constraints,
14039                     x_return_status       => l_return_status);
14040           --
14041           IF l_debug_on THEN
14042              WSH_DEBUG_SV.logmsg(l_module_name,'Called validate_positive_constraint return status : '||l_return_status);
14043              WSH_DEBUG_SV.logmsg(l_module_name,'l_failed_lines count : '||l_failed_lines.COUNT);
14044           END IF;
14045           --
14046 
14047           IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14048               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14049                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
14050               END IF;
14051           ELSIF l_failed_lines.COUNT > 0 THEN
14052               x_validate_result := 'F';
14053               l_validate_result := 'F';
14054           END IF;
14055 
14056           IF l_validate_result = 'S' THEN
14057 
14058            check_dlvy_against_trip(
14059                      p_entity_type         => 'DLEG',
14060                      p_entity_id           => l_delivery_leg_rec.delivery_leg_id,
14061                      p_delivery_rec        => l_dleg_dlvy_rec,
14062                      p_detail_tab          => l_detail_tab,
14063                      p_comp_class_tab      => l_comp_class_tab,
14064                      p_target_stops_info   => l_target_tripstops,
14065                      p_target_trip         => p_target_trip(i),
14066                      p_target_tripstops    => l_trip_stops_tab,
14067                      p_target_dlvy         => l_trip_dlvy_tab,
14068                      p_target_dlvy_lines   => l_trip_detail_tab,
14069                      x_failed_constraints  => l_failed_constraints,
14070                      x_validate_result     => l_validate_excl_result,
14071                      x_return_status       => l_return_status);
14072 
14073            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14074              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14075                 raise FND_API.G_EXC_UNEXPECTED_ERROR;
14076              END IF;
14077            END IF;
14078 
14079            IF l_validate_excl_result = 'F' THEN
14080                    x_validate_result := 'F';
14081                    l_validate_result := 'F';
14082            END IF;
14083 
14084           END IF; -- l_validate_result = 'S'
14085 
14086           <<next_trip>>
14087 
14088           IF l_validate_result = 'S' THEN
14089            -- populate x_succ_trips
14090               x_succ_trips(x_succ_trips.COUNT+1) := p_target_trip(i).trip_id;
14091 
14092           END IF;
14093 
14094           EXIT WHEN i = p_target_trip.LAST;
14095           i := p_target_trip.NEXT(i);
14096 
14097         END LOOP;
14098       END IF;
14099 
14100     END IF;   -- DST
14101 
14102     -- For DCE
14103 
14104     IF p_action_code IN (G_UPDATE_DLEG,G_DLEG_CRT) AND
14105        l_dleg_dlvy_rec.shipping_control <> 'SUPPLIER' THEN
14106 
14107     -- FAC - CAR/MOD for dleg against dleg's locations
14108 
14109        IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) AND
14110           l_delivery_leg_rec.carrier_id IS NOT NULL THEN
14111 
14112             validate_constraint(
14113              p_comp_class_code          =>      G_FACILITY_CARRIER,
14114              p_object1_type             =>      'FAC',
14115              p_object1_val_num          =>      l_delivery_leg_rec.pickupstop_location_id,
14116              p_object2_type             =>      'CAR',
14117              p_object2_val_num          =>      l_delivery_leg_rec.carrier_id,
14118              x_validate_result          =>      l_validate_faccar_result,
14119              x_failed_constraint        =>      l_failed_constraint,
14120              x_return_status            =>      l_return_status);
14121 
14122             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14123                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14124                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
14125                END IF;
14126             END IF;
14127 
14128             IF l_validate_faccar_result <> 'S' THEN
14129               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
14130               l_failed_constraint.entity_type :=  G_DELIVERY_LEG;
14131               l_failed_constraint.entity_line_id :=  l_delivery_leg_rec.delivery_leg_id;
14132               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
14133 
14134               IF l_validate_faccar_result = 'E' THEN
14135                  x_validate_result := 'F';
14136                  l_validate_result := 'F';
14137               END IF;
14138             END IF;
14139          -- Success can override Failure
14140 
14141             validate_constraint(
14142              p_comp_class_code          =>      G_FACILITY_CARRIER,
14143              p_object1_type             =>      'FAC',
14144              p_object1_val_num          =>      l_delivery_leg_rec.dropoffstop_location_id,
14145              p_object2_type             =>      'CAR',
14146              p_object2_val_num          =>      l_delivery_leg_rec.carrier_id,
14147              x_validate_result          =>      l_validate_faccar_result,
14148              x_failed_constraint        =>      l_failed_constraint,
14149              x_return_status            =>      l_return_status);
14150 
14151             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14152                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14153                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
14154                END IF;
14155             END IF;
14156 
14157             IF l_validate_faccar_result <> 'S' THEN
14158               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
14159               l_failed_constraint.entity_type :=  G_DELIVERY_LEG;
14160               l_failed_constraint.entity_line_id :=  l_delivery_leg_rec.delivery_leg_id;
14161               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
14162 
14163               IF l_validate_faccar_result = 'E' THEN
14164                  x_validate_result := 'F';
14165                 l_validate_result := 'F';
14166               END IF;
14167             END IF;
14168 
14169        END IF;
14170 
14171        IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) AND
14172           l_delivery_leg_rec.MODE_OF_TRANSPORT IS NOT NULL THEN
14173 
14174             validate_constraint(
14175              p_comp_class_code          =>      G_FACILITY_MODE,
14176              p_object1_type             =>      'FAC',
14177              p_object1_val_num          =>      l_delivery_leg_rec.pickupstop_location_id,
14178              p_object2_type             =>      'MOD',
14179              p_object2_val_char         =>      l_delivery_leg_rec.mode_of_transport,
14180              x_validate_result          =>      l_validate_facmod_result,
14181              x_failed_constraint        =>      l_failed_constraint,
14182              x_return_status            =>      l_return_status);
14183 
14184             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14185                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14186                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
14187                END IF;
14188             END IF;
14189 
14190             IF l_validate_facmod_result <> 'S' THEN
14191               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
14192               l_failed_constraint.entity_type :=  G_DELIVERY_LEG;
14193               l_failed_constraint.entity_line_id :=  l_delivery_leg_rec.delivery_leg_id;
14194               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
14195 
14196               IF l_validate_facmod_result = 'E' THEN
14197                x_validate_result := 'F';
14198                l_validate_result := 'F';
14199               END IF;
14200 
14201             END IF;
14202 
14203             validate_constraint(
14204              p_comp_class_code          =>      G_FACILITY_MODE,
14205              p_object1_type             =>      'FAC',
14206              p_object1_val_num          =>      l_delivery_leg_rec.dropoffstop_location_id,
14207              p_object2_type             =>      'MOD',
14208              p_object2_val_char         =>      l_delivery_leg_rec.mode_of_transport,
14209              x_validate_result          =>      l_validate_facmod_result,
14210              x_failed_constraint        =>      l_failed_constraint,
14211              x_return_status            =>      l_return_status);
14212 
14213             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14214                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14215                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
14216                END IF;
14217             END IF;
14218 
14219             IF l_validate_facmod_result <> 'S' THEN
14220               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
14221               l_failed_constraint.entity_type :=  G_DELIVERY_LEG;
14222               l_failed_constraint.entity_line_id :=  l_delivery_leg_rec.delivery_leg_id;
14223               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
14224 
14225               IF l_validate_facmod_result = 'E' THEN
14226                x_validate_result := 'F';
14227                l_validate_result := 'F';
14228               END IF;
14229             END IF;
14230 
14231        END IF;
14232 
14233        check_dleg_discretionary(
14234                  p_entity_type          => G_DELIVERY_LEG,
14235                  p_entity_id            => l_delivery_leg_rec.delivery_leg_id,
14236                  p_delivery_rec         => l_dleg_dlvy_rec,
14237                  p_comp_class_tab       => l_comp_class_tab,
14238                  p_dleg_pick_up_loc_id  => l_delivery_leg_rec.pickupstop_location_id,
14239                  p_dleg_drop_off_loc_id => l_delivery_leg_rec.dropoffstop_location_id,
14240                  p_detail_tab           => l_detail_tab,
14241                  p_carrier              => l_delivery_leg_rec.carrier_id,
14242                  p_mode                 => l_delivery_leg_rec.mode_of_transport,
14243                  x_failed_constraints   => l_failed_constraints,
14244                  x_validate_result      => l_validate_result,
14245                  x_return_status        => l_return_status);
14246 
14247            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14248               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14249                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
14250               END IF;
14251            END IF;
14252 
14253            IF l_validate_result = 'F' THEN
14254               x_validate_result := l_validate_result;
14255            END IF;
14256 
14257 
14258     END IF;
14259 
14260      --  Loop over l_failed_constraints to add to the mesage stack
14261 
14262     stack_messages (
14263              p_failed_constraints       => l_failed_constraints,
14264              x_msg_count                => x_msg_count,
14265              x_msg_data                 => x_msg_data,
14266              x_return_status            => l_return_status);
14267 
14268     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14269          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14270             raise FND_API.G_EXC_UNEXPECTED_ERROR;
14271          END IF;
14272     END IF;
14273 
14274     IF x_validate_result = 'F' THEN
14275         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
14276     ELSIF l_failed_constraints.COUNT > 0 THEN
14277         x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
14278     END IF;
14279 
14280     --
14281     IF l_debug_on THEN
14282       WSH_DEBUG_SV.pop(l_module_name);
14283     END IF;
14284     --
14285 
14286 EXCEPTION
14287     WHEN g_get_carrmode_failed THEN
14288       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
14289       --
14290       IF l_debug_on THEN
14291         WSH_DEBUG_SV.pop(l_module_name,' get carrier-mode failed ');
14292       END IF;
14293       --
14294     WHEN g_get_vehicletype_failed THEN
14295       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
14296       --
14297       IF l_debug_on THEN
14298         WSH_DEBUG_SV.pop(l_module_name,' get vehicletype failed ');
14299       END IF;
14300       --
14301     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
14302       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
14303       --
14304       IF l_debug_on THEN
14305         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
14306         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
14307       END IF;
14308       --
14309     WHEN others THEN
14310       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.validate_constraint_dleg');
14311       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
14312       --
14313       IF l_debug_on THEN
14314         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
14315         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
14316       END IF;
14317       --
14318 END validate_constraint_dleg;
14319 
14320 
14321 --***************************************************************************--
14322 --========================================================================
14323 -- PROCEDURE : validate_constraint_dlvb    Called by constraint Wrapper API
14324 --                                         and the Group API.
14325 --
14326 -- PARAMETERS: p_init_msg_list             FND_API.G_TRUE to reset list
14327 --             p_action_code               Predefined action code
14328 --             p_exception_list            Compatibility classes to skip if any
14329 --                                         indexed by class code numbers
14330 --             p_in_ids                    Table of delivery ids to process
14331 --                                         Either of the next two should be passed
14332 --             p_del_detail_info           Table of delivery detail records to process
14333 --                                         Only one of p_in_ids and p_del_detail_info should be passed
14334 --             p_target_delivery           Applicable for Assign delivery detail to delivery only
14335 --                                         Record of target delivery information
14336 --             p_target_container          Applicable for Assign delivery detail to container only
14337 --                                         Record of target container information
14338 --                                         If not passed, the API will query
14339 --             p_dlvy_assigned_lines       Table of delivery details already in target
14340 --                                         delivery or target container
14341 --                                         If not passed, the API will query
14342 --             x_validate_result           Constraint Validation result : S / F
14343 --             x_failed_lines              Table of input delivery lines that failed
14344 --                                         constraint check
14345 --             x_line_groups               Includes Successful and warning lines
14346 --                                         after constraint check
14347 --                                         Contains information of which input delivery should
14348 --                                         be grouped in which output group for trip creation
14349 --             x_group_info                Output groups for input deliveries
14350 --             x_msg_count                 Number of messages in the list
14351 --             x_msg_data                  Text of messages
14352 --             x_return_status             Return status
14353 -- COMMENT   : This procedure is used to perform for following actions
14354 --             A. Autocreate Delivery (ACD)
14355 --             B. Assign detail to Delivery (ADD)
14356 --             C. Packing (PKG)
14357 --             When specifying a target delivery, group all delivery lines that are being planned
14358 --             to the target delivery
14359 --========================================================================
14360 
14361 PROCEDURE validate_constraint_dlvb(
14362              p_init_msg_list            IN      VARCHAR2 DEFAULT fnd_api.g_false,
14363              p_action_code              IN      VARCHAR2 DEFAULT NULL,
14364              p_exception_list           IN      WSH_UTIL_CORE.Column_Tab_Type,
14365              p_in_ids                   IN      WSH_UTIL_CORE.id_tab_type,
14366              p_del_detail_info          IN      detail_ccinfo_tab_type,
14367              p_target_delivery          IN      delivery_ccinfo_rec_type,
14368              p_target_container         IN      detail_ccinfo_rec_type,
14369              p_dlvy_assigned_lines      IN      detail_ccinfo_tab_type,
14370              x_validate_result          OUT NOCOPY    VARCHAR2,
14371              x_failed_lines             OUT NOCOPY    WSH_FTE_COMP_CONSTRAINT_PKG.failed_line_tab_type,
14372              x_line_groups              OUT NOCOPY    WSH_FTE_COMP_CONSTRAINT_PKG.line_group_tab_type,
14373              x_group_info               OUT NOCOPY    WSH_FTE_COMP_CONSTRAINT_PKG.cc_group_tab_type,
14374              x_msg_count                OUT NOCOPY    NUMBER,
14375              x_msg_data                 OUT NOCOPY    VARCHAR2,
14376              x_return_status            OUT NOCOPY    VARCHAR2)
14377 IS
14378 
14379     CURSOR c_get_assigned_lines_cont(c_container_id IN NUMBER) IS
14380     SELECT wdd.DELIVERY_DETAIL_ID,wda.DELIVERY_ID,'Y',wdd.CUSTOMER_ID,
14381            wdd.INVENTORY_ITEM_ID,wdd.SHIP_FROM_LOCATION_ID,wdd.ORGANIZATION_ID,
14382            wdd.SHIP_TO_LOCATION_ID,wdd.INTMED_SHIP_TO_LOCATION_ID,wdd.RELEASED_STATUS,
14383            wdd.CONTAINER_FLAG,wdd.DATE_REQUESTED,wdd.DATE_SCHEDULED,wdd.SHIP_METHOD_CODE,
14384            wdd.CARRIER_ID,wdd.party_id,nvl(wdd.line_direction,'O')
14385            ,nvl(wdd.shipping_control,'BUYER'),NULL
14386 
14387     FROM   WSH_DELIVERY_DETAILS wdd,
14388            wsh_delivery_assignments_v wda
14389     WHERE  wda.DELIVERY_DETAIL_ID = wdd.DELIVERY_DETAIL_ID
14390     AND    nvl(wdd.shipping_control,'BUYER') <> 'SUPPLIER'
14391     AND    wda.PARENT_DELIVERY_DETAIL_ID = c_container_id;
14392 
14393     CURSOR c_get_line_details(c_detail_id IN NUMBER) IS
14394     SELECT wdd.DELIVERY_DETAIL_ID,null,'Y',wdd.CUSTOMER_ID,
14395            wdd.INVENTORY_ITEM_ID,wdd.SHIP_FROM_LOCATION_ID,wdd.ORGANIZATION_ID,
14396            wdd.SHIP_TO_LOCATION_ID,wdd.INTMED_SHIP_TO_LOCATION_ID,wdd.RELEASED_STATUS,
14397            wdd.CONTAINER_FLAG,wdd.DATE_REQUESTED,wdd.DATE_SCHEDULED,wdd.SHIP_METHOD_CODE,
14398            wdd.CARRIER_ID,wdd.party_id,nvl(wdd.line_direction,'O')
14399            ,nvl(wdd.shipping_control,'BUYER'),NULL
14400            --DUM_LOC
14401     FROM   WSH_DELIVERY_DETAILS wdd
14402     WHERE  wdd.DELIVERY_DETAIL_ID = c_detail_id;
14403 
14404     CURSOR c_getdelivery(c_detail_id IN NUMBER) IS
14405     SELECT wda.DELIVERY_ID
14406     FROM   wsh_delivery_assignments_v wda
14407     WHERE  wda.delivery_detail_id = c_detail_id;
14408 
14409     i                                    NUMBER:=0;
14410     j                                    NUMBER:=0;
14411     k                                    NUMBER:=0;
14412     l                                    NUMBER:=0;
14413     m                                    NUMBER:=0;
14414     n                                    NUMBER:=0;
14415     o                                    NUMBER:=0;
14416     p                                    NUMBER:=0;
14417     q                                    NUMBER:=0;
14418     s                                    NUMBER:=0;
14419     t                                    NUMBER:=0;
14420     l_assigned_line_cnt                  NUMBER:=0;
14421     l_group_count                        NUMBER:=0;
14422     l_failed_lc                          NUMBER:=0;
14423     l_input_target_id                    NUMBER:=0;
14424     l_group_id                           NUMBER:=0;
14425     l_linegroup_indx                     NUMBER:=0;
14426     l_item_org_id                        NUMBER:=0;
14427     l_item_id                            NUMBER:=0;
14428     l_customer_id                        NUMBER:=0;
14429     l_carrier                            NUMBER := NULL;
14430     l_found                              BOOLEAN := FALSE;
14431     l_failed_line_added                  BOOLEAN := FALSE;
14432     l_mode                               VARCHAR2(30) := NULL;
14433     l_service_level                      VARCHAR2(30) := NULL;
14434     l_carrier_service_inout_rec          WSH_CARRIERS_GRP.Carrier_Service_InOut_Rec_Type;
14435     l_intmed_location_id                 NUMBER:=0;
14436     l_hash_string                        VARCHAR2(200);
14437     l_hash_value                         NUMBER:=0;
14438     l_return_status                      VARCHAR2(1);
14439     l_validate_result                    VARCHAR2(1);
14440     l_validate_item_result               VARCHAR2(1);
14441     l_validate_customer_result           VARCHAR2(1);
14442     l_validate_carrier_result            VARCHAR2(1);
14443     l_validate_mode_result               VARCHAR2(1);
14444     l_validate_intmed_result             VARCHAR2(1);
14445     l_input_comp_class                   BOOLEAN := FALSE;
14446     l_input_assign_lines                 BOOLEAN := FALSE;
14447     l_item_check_cus                     BOOLEAN := FALSE;
14448     l_comp_class_tab                     WSH_UTIL_CORE.Column_Tab_Type;
14449     l_detail_rec                         detail_ccinfo_rec_type;
14450     l_line_group_rec                     WSH_FTE_COMP_CONSTRAINT_PKG.line_group_rec_type;
14451     l_linegroup_rec                      WSH_FTE_COMP_CONSTRAINT_PKG.cc_group_rec_type;
14452     l_failed_constraint                  line_constraint_rec_type;
14453     l_failed_constraints                 line_constraint_tab_type;
14454     l_entity_tab                         entity_tab_type;
14455     l_target_rec                         entity_rec_type;
14456     l_validate_itmin_result              VARCHAR2(1);
14457     l_inp_items_cnt                      NUMBER := 0;
14458     l_validate_itmfacin_result           VARCHAR2(1) := 'S';
14459     l_items_tab                          item_tab_type;
14460     l_locations_list                     WSH_UTIL_CORE.id_tab_type;
14461     l_supp_control_tab                   WSH_UTIL_CORE.id_tab_type;
14462     l_target_delivery                    delivery_ccinfo_rec_type;
14463     l_target_container                   detail_ccinfo_rec_type;
14464     l_del_detail_info                    detail_ccinfo_tab_type;
14465     l_dlvy_assigned_lines                detail_ccinfo_tab_type;
14466     l_dummy_assigned_lines               detail_ccinfo_tab_type;
14467     l_target_tripstops                   target_tripstop_cc_rec_type;
14468 
14469     --#DUM_LOC(S)
14470     l_physical_location_id		 NUMBER;
14471     --#DUM_LOC(E)
14472 
14473     g_invalid_action_code                EXCEPTION;
14474     g_invalid_input                      EXCEPTION;
14475     l_debug_on                           CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
14476     l_module_name                        CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'validate_constraint_dlvb';
14477 
14478 BEGIN
14479 
14480     x_validate_result := 'S'; --  Constraint Validation result : S / F
14481     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
14482 
14483     g_itm_mustuse_cache.DELETE;
14484     g_itmloc_mustuse_cache.DELETE;
14485     g_itm_exclusive_cache.DELETE;
14486     g_fac_exclusive_cache.DELETE;
14487 
14488     IF FND_API.to_Boolean( p_init_msg_list ) THEN
14489          FND_MSG_PUB.initialize;
14490     END IF;
14491 
14492     IF l_debug_on THEN
14493         wsh_debug_sv.push(l_module_name);
14494         WSH_DEBUG_SV.logmsg(l_module_name,'p_init_msg_list : '||p_init_msg_list);
14495     END IF;
14496 
14497     -- Action codes : ACD, ADD, PKG
14498     -- Assumes p_comp_class_tab and p_exception_list are indexed by
14499     -- compatibility class codes
14500 
14501     IF p_action_code NOT IN (G_AUTOCRT_DLVY,G_PACK_DLVB,G_ASSIGN_DLVB_DLVY) OR
14502        p_action_code IS NULL THEN
14503        RAISE g_invalid_action_code;
14504     END IF;
14505 
14506     refresh_cache(l_return_status);
14507 
14508     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14509          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14510             raise FND_API.G_EXC_UNEXPECTED_ERROR;
14511          END IF;
14512     END IF;
14513 
14514     IF NOT p_exception_list.EXISTS(G_CUSTOMER_CUSTOMER_NUM) THEN
14515      l_comp_class_tab(G_CUSTOMER_CUSTOMER_NUM) := G_CUSTOMER_CUSTOMER;
14516     END IF;
14517      -- 12/17 : For now packing will not conside item - car/mod for grouping
14518     IF p_action_code IN (G_AUTOCRT_DLVY,G_ASSIGN_DLVB_DLVY) THEN
14519        IF NOT p_exception_list.EXISTS(G_ITEM_MODE_NUM) THEN
14520         l_comp_class_tab(G_ITEM_MODE_NUM) := G_ITEM_MODE;
14521        END IF;
14522        IF NOT p_exception_list.EXISTS(G_ITEM_CARRIER_NUM) THEN
14523         l_comp_class_tab(G_ITEM_CARRIER_NUM) := G_ITEM_CARRIER;
14524        END IF;
14525        IF NOT p_exception_list.EXISTS(G_ITEM_VEHICLE_NUM) THEN
14526         l_comp_class_tab(G_ITEM_VEHICLE_NUM) := G_ITEM_VEHICLE;
14527        END IF;
14528        IF NOT p_exception_list.EXISTS(G_ITEM_FACILITY_NUM) THEN
14529         l_comp_class_tab(G_ITEM_FACILITY_NUM) := G_ITEM_FACILITY;
14530        END IF;
14531      -- Assign delivery details to delivery
14532      -- does not update any grouping attributes for the delivery AS 10/18
14533      -- What about packing a detail to a container ?
14534 
14535        IF NOT p_exception_list.EXISTS(G_FACILITY_MODE_NUM) THEN
14536         l_comp_class_tab(G_FACILITY_MODE_NUM) := G_FACILITY_MODE;
14537        END IF;
14538        IF NOT p_exception_list.EXISTS(G_FACILITY_CARRIER_NUM) THEN
14539         l_comp_class_tab(G_FACILITY_CARRIER_NUM) := G_FACILITY_CARRIER;
14540        END IF;
14541        IF NOT p_exception_list.EXISTS(G_FACILITY_VEHICLE_NUM) THEN
14542         l_comp_class_tab(G_FACILITY_VEHICLE_NUM) := G_FACILITY_VEHICLE;
14543        END IF;
14544        IF NOT p_exception_list.EXISTS(G_SHIPORG_FACILITY_NUM) THEN
14545         l_comp_class_tab(G_SHIPORG_FACILITY_NUM) := G_SHIPORG_FACILITY;
14546        END IF;
14547        IF NOT p_exception_list.EXISTS(G_CUSTOMER_FACILITY_NUM) THEN
14548         l_comp_class_tab(G_CUSTOMER_FACILITY_NUM) := G_CUSTOMER_FACILITY;
14549        END IF;
14550        IF NOT p_exception_list.EXISTS(G_SUPPLIER_FACILITY_NUM) THEN
14551         l_comp_class_tab(G_SUPPLIER_FACILITY_NUM) := G_SUPPLIER_FACILITY;
14552        END IF;
14553     END IF;
14554     --
14555     IF l_debug_on THEN
14556         WSH_DEBUG_SV.logmsg(l_module_name,'After populating l_comp_class_tab count : '||l_comp_class_tab.COUNT);
14557     END IF;
14558     --
14559     -- Populate l_del_detail_info
14560 
14561     IF p_del_detail_info.COUNT = 0 THEN
14562       --
14563       IF l_debug_on THEN
14564         WSH_DEBUG_SV.logmsg(l_module_name,'Passed p_in_ids count : '||p_in_ids.COUNT);
14565       END IF;
14566       --
14567 
14568       i := p_in_ids.FIRST;
14569 
14570       IF i IS NOT NULL THEN
14571         LOOP
14572            OPEN c_get_line_details(p_in_ids(i));
14573            FETCH c_get_line_details into l_del_detail_info(i);
14574            CLOSE c_get_line_details;
14575 
14576            --#DUM_LOC(S)
14577 	   WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
14578 	      p_internal_cust_location_id  => l_del_detail_info(i).ship_to_location_id,
14579               x_internal_org_location_id   => l_physical_location_id,
14580               x_return_status              => l_return_status);
14581 
14582  	   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14583 	     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14584 	        raise FND_API.G_EXC_UNEXPECTED_ERROR;
14585 	     END IF;
14586     	   END IF;
14587 
14588   	   IF (l_physical_location_id IS NOT NULL) THEN
14589   	      --
14590 	      IF l_debug_on THEN
14591 		  WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_del_detail_info(i).ship_to_location_id||' is a dummy location');
14592 	      END IF;
14593 	      --
14594 	      l_del_detail_info(i).ship_to_location_id:= l_physical_location_id;
14595               -- AGDUMMY TODO
14596               l_del_detail_info(i).physical_ship_to_location_id:= l_physical_location_id;
14597 	   END IF;
14598            --#DUM_LOC(E)
14599 
14600 	   OPEN  c_getdelivery(p_in_ids(i));
14601            FETCH c_getdelivery into l_del_detail_info(i).DELIVERY_ID;
14602            CLOSE c_getdelivery;
14603 
14604            EXIT WHEN i = p_in_ids.LAST;
14605            i := p_in_ids.NEXT(i);
14606 
14607         END LOOP;
14608       END IF;
14609 
14610     ELSE
14611       --
14612       IF l_debug_on THEN
14613         WSH_DEBUG_SV.logmsg(l_module_name,'Passed p_del_detail_info count : '||p_del_detail_info.COUNT);
14614       END IF;
14615       --
14616 
14617       i := p_del_detail_info.FIRST;
14618       IF i IS NOT NULL THEN
14619         LOOP
14620 
14621           l_del_detail_info(i).DELIVERY_DETAIL_ID          := p_del_detail_info(i).DELIVERY_DETAIL_ID;
14622           l_del_detail_info(i).DELIVERY_ID                 := p_del_detail_info(i).DELIVERY_ID;
14623           l_del_detail_info(i).exists_in_database          := p_del_detail_info(i).exists_in_database;
14624           l_del_detail_info(i).CUSTOMER_ID                 := p_del_detail_info(i).CUSTOMER_ID;
14625           l_del_detail_info(i).INVENTORY_ITEM_ID           := p_del_detail_info(i).INVENTORY_ITEM_ID;
14626           l_del_detail_info(i).RELEASED_STATUS             := p_del_detail_info(i).RELEASED_STATUS;
14627           l_del_detail_info(i).DATE_REQUESTED              := p_del_detail_info(i).DATE_REQUESTED;
14628           l_del_detail_info(i).SHIP_FROM_LOCATION_ID       := p_del_detail_info(i).SHIP_FROM_LOCATION_ID;
14629           l_del_detail_info(i).SHIP_TO_LOCATION_ID         := p_del_detail_info(i).SHIP_TO_LOCATION_ID;
14630           l_del_detail_info(i).DATE_SCHEDULED              := p_del_detail_info(i).DATE_SCHEDULED;
14631           l_del_detail_info(i).CONTAINER_FLAG              := p_del_detail_info(i).CONTAINER_FLAG;
14632           l_del_detail_info(i).INTMED_SHIP_TO_LOCATION_ID  := p_del_detail_info(i).INTMED_SHIP_TO_LOCATION_ID;
14633           l_del_detail_info(i).SHIP_METHOD_CODE            := p_del_detail_info(i).SHIP_METHOD_CODE;
14634           l_del_detail_info(i).CARRIER_ID                  := p_del_detail_info(i).CARRIER_ID;
14635           l_del_detail_info(i).PARTY_ID                    := p_del_detail_info(i).PARTY_ID;
14636           l_del_detail_info(i).LINE_DIRECTION              := p_del_detail_info(i).LINE_DIRECTION;
14637           l_del_detail_info(i).SHIPPING_CONTROL            := nvl(p_del_detail_info(i).SHIPPING_CONTROL,'BUYER');
14638           l_del_detail_info(i).ORGANIZATION_ID             := p_del_detail_info(i).ORGANIZATION_ID;
14639 
14640 	  --#DUM_LOC(S)
14641 	  WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
14642 	      p_internal_cust_location_id  => l_del_detail_info(i).ship_to_location_id,
14643               x_internal_org_location_id   => l_physical_location_id,
14644               x_return_status              => l_return_status);
14645 
14646  	  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14647 	    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14648 	       raise FND_API.G_EXC_UNEXPECTED_ERROR;
14649 	    END IF;
14650     	  END IF;
14651 
14652   	  IF (l_physical_location_id IS NOT NULL) THEN
14653   	      --
14654 	      IF l_debug_on THEN
14655 		  WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_del_detail_info(i).ship_to_location_id||' is a dummy location');
14656 	      END IF;
14657 	      --
14658 	      l_del_detail_info(i).ship_to_location_id:= l_physical_location_id;
14659               -- AGDUMMY TODO
14660               l_del_detail_info(i).physical_ship_to_location_id:= l_physical_location_id;
14661 	  END IF;
14662 	  --#DUM_LOC(E)
14663 
14664           EXIT WHEN i = p_del_detail_info.LAST;
14665           i := p_del_detail_info.NEXT(i);
14666 
14667         END LOOP;
14668       END IF;
14669 
14670     END IF;
14671 
14672     IF p_target_delivery.delivery_id IS NOT NULL THEN
14673 
14674        OPEN c_get_dlvy(p_target_delivery.delivery_id);
14675        FETCH c_get_dlvy into l_target_delivery;
14676        CLOSE c_get_dlvy;
14677 
14678        --#DUM_LOC(S)
14679        WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
14680           p_internal_cust_location_id  => l_target_delivery.ultimate_dropoff_location_id,
14681           x_internal_org_location_id   => l_physical_location_id,
14682           x_return_status              => l_return_status);
14683 
14684        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14685 	    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14686 	       raise FND_API.G_EXC_UNEXPECTED_ERROR;
14687 	    END IF;
14688        END IF;
14689 
14690        IF (l_physical_location_id IS NOT NULL) THEN
14691   	  --
14692 	  IF l_debug_on THEN
14693 	     WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_target_delivery.ultimate_dropoff_location_id||' is a dummy location');
14694 	  END IF;
14695 	  --
14696 	 l_target_delivery.ultimate_dropoff_location_id := l_physical_location_id;
14697          -- AGDUMMY TODO
14698          l_target_delivery.physical_dropoff_location_id := l_physical_location_id;
14699        END IF;
14700        --#DUM_LOC(E)
14701 
14702      ELSIF p_target_container.delivery_detail_id IS NOT NULL THEN
14703 
14704 	--#DUM_LOC(Q) Do we change for containers.
14705         --Verify.
14706         -- Yes
14707 
14708        OPEN c_get_line_details(p_target_container.delivery_detail_id);
14709        FETCH c_get_line_details into l_target_container;
14710        CLOSE c_get_line_details;
14711 
14712 	--#DUM_LOC(S)
14713        WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
14714 	  p_internal_cust_location_id  => l_target_container.ship_to_location_id,
14715           x_internal_org_location_id   => l_physical_location_id,
14716           x_return_status              => l_return_status);
14717 
14718        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14719 	  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14720 	    raise FND_API.G_EXC_UNEXPECTED_ERROR;
14721 	  END IF;
14722        END IF;
14723 
14724        IF (l_physical_location_id IS NOT NULL) THEN
14725   	    --
14726 	    IF l_debug_on THEN
14727 	       WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_target_container.ship_to_location_id||' is a dummy location');
14728 	    END IF;
14729 	    --
14730 	    l_target_container.ship_to_location_id:= l_physical_location_id;
14731             -- AGDUMMY TODO
14732             l_target_container.physical_ship_to_location_id := l_physical_location_id;
14733        END IF;
14734        --#DUM_LOC(E)
14735     END IF;
14736 
14737 
14738     IF p_dlvy_assigned_lines.COUNT = 0 THEN
14739      IF ( l_target_delivery.delivery_id IS NOT NULL
14740        AND l_target_delivery.exists_in_database = 'Y') THEN
14741 	      --
14742           --  has been passed
14743           IF l_target_delivery.delivery_type = 'STANDARD' THEN
14744               OPEN c_get_details(l_target_delivery.delivery_id); -- or container_id
14745               LOOP
14746                    FETCH c_get_details INTO l_detail_rec;
14747                    EXIT WHEN c_get_details%NOTFOUND;
14748 
14749                --#DUM_LOC(S)
14750                    WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
14751                        p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
14752                        x_internal_org_location_id   => l_physical_location_id,
14753                        x_return_status              => l_return_status);
14754 
14755                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14756                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14757                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
14758                  END IF;
14759                    END IF;
14760 
14761                IF (l_physical_location_id IS NOT NULL) THEN
14762              --
14763                  IF l_debug_on THEN
14764                 WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
14765                  END IF;
14766                  --
14767                  l_detail_rec.ship_to_location_id:= l_physical_location_id;
14768                      -- AGDUMMY TODO
14769                      l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
14770                END IF;
14771                    --#DUM_LOC(E)
14772                    l_assigned_line_cnt := l_assigned_line_cnt + 1;
14773                    l_dlvy_assigned_lines(l_assigned_line_cnt) := l_detail_rec;
14774               END LOOP;
14775               CLOSE c_get_details;
14776           ELSE
14777               OPEN c_get_details_consol(l_target_delivery.delivery_id); -- or container_id
14778               LOOP
14779                    FETCH c_get_details_consol INTO l_detail_rec;
14780                    EXIT WHEN c_get_details%NOTFOUND;
14781 
14782                --#DUM_LOC(S)
14783                    WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
14784                        p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
14785                        x_internal_org_location_id   => l_physical_location_id,
14786                        x_return_status              => l_return_status);
14787 
14788                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14789                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14790                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
14791                  END IF;
14792                    END IF;
14793 
14794                IF (l_physical_location_id IS NOT NULL) THEN
14795              --
14796                  IF l_debug_on THEN
14797                 WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
14798                  END IF;
14799                  --
14800                  l_detail_rec.ship_to_location_id:= l_physical_location_id;
14801                      -- AGDUMMY TODO
14802                      l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
14803                END IF;
14804                    --#DUM_LOC(E)
14805                    l_assigned_line_cnt := l_assigned_line_cnt + 1;
14806                    l_dlvy_assigned_lines(l_assigned_line_cnt) := l_detail_rec;
14807               END LOOP;
14808               CLOSE c_get_details_consol;
14809           END IF;
14810           ---
14811      ELSIF ( l_target_container.delivery_detail_id IS NOT NULL
14812           AND l_target_container.exists_in_database = 'Y') THEN  --  Check to see if target delivery/contain.
14813 
14814           OPEN c_get_assigned_lines_cont(l_target_container.delivery_detail_id); -- or container_id
14815           LOOP
14816                FETCH c_get_assigned_lines_cont INTO l_detail_rec;
14817                EXIT WHEN c_get_assigned_lines_cont%NOTFOUND;
14818 
14819 	       --#DUM_LOC(S)
14820 	       WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
14821 	           p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
14822                    x_internal_org_location_id   => l_physical_location_id,
14823                    x_return_status              => l_return_status);
14824 
14825  	       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14826 	         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14827 	           raise FND_API.G_EXC_UNEXPECTED_ERROR;
14828 	         END IF;
14829     	       END IF;
14830 
14831   	       IF (l_physical_location_id IS NOT NULL) THEN
14832   		 --
14833 	         IF l_debug_on THEN
14834 		    WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
14835 	         END IF;
14836 	         --
14837 	        l_detail_rec.ship_to_location_id:= l_physical_location_id;
14838                 -- AGDUMMY TODO
14839                 l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
14840 	       END IF;
14841                --#DUM_LOC(E)
14842 
14843 	       l_assigned_line_cnt := l_assigned_line_cnt + 1;
14844                l_dlvy_assigned_lines(l_assigned_line_cnt) := l_detail_rec;
14845           END LOOP;
14846           CLOSE c_get_assigned_lines_cont;
14847      END IF;
14848      --
14849      IF l_debug_on THEN
14850         WSH_DEBUG_SV.logmsg(l_module_name,'Created l_dlvy_assigned_lines count : '||l_dlvy_assigned_lines.COUNT);
14851      END IF;
14852      --
14853     ELSE
14854       --
14855       IF l_debug_on THEN
14856         WSH_DEBUG_SV.logmsg(l_module_name,'Passed p_dlvy_assigned_lines count : '||p_dlvy_assigned_lines.COUNT);
14857       END IF;
14858       --
14859 
14860       i := p_dlvy_assigned_lines.FIRST;
14861       IF i IS NOT NULL THEN
14862         LOOP
14863 
14864                l_dlvy_assigned_lines(i).delivery_detail_id := p_dlvy_assigned_lines(i).delivery_detail_id;
14865                l_dlvy_assigned_lines(i).delivery_id := p_dlvy_assigned_lines(i).delivery_id;
14866                l_dlvy_assigned_lines(i).exists_in_database := p_dlvy_assigned_lines(i).exists_in_database;
14867                l_dlvy_assigned_lines(i).CUSTOMER_ID := p_dlvy_assigned_lines(i).CUSTOMER_ID;
14868                l_dlvy_assigned_lines(i).INVENTORY_ITEM_ID := p_dlvy_assigned_lines(i).INVENTORY_ITEM_ID;
14869                l_dlvy_assigned_lines(i).SHIP_FROM_LOCATION_ID := p_dlvy_assigned_lines(i).SHIP_FROM_LOCATION_ID;
14870                l_dlvy_assigned_lines(i).ORGANIZATION_ID := p_dlvy_assigned_lines(i).ORGANIZATION_ID;
14871                l_dlvy_assigned_lines(i).SHIP_TO_LOCATION_ID := p_dlvy_assigned_lines(i).SHIP_TO_LOCATION_ID;
14872                l_dlvy_assigned_lines(i).INTMED_SHIP_TO_LOCATION_ID := p_dlvy_assigned_lines(i).INTMED_SHIP_TO_LOCATION_ID;
14873                l_dlvy_assigned_lines(i).RELEASED_STATUS := p_dlvy_assigned_lines(i).RELEASED_STATUS;
14874                l_dlvy_assigned_lines(i).CONTAINER_FLAG := p_dlvy_assigned_lines(i).CONTAINER_FLAG;
14875                l_dlvy_assigned_lines(i).DATE_REQUESTED  := p_dlvy_assigned_lines(i).DATE_REQUESTED;
14876                l_dlvy_assigned_lines(i).DATE_SCHEDULED := p_dlvy_assigned_lines(i).DATE_SCHEDULED;
14877                l_dlvy_assigned_lines(i).SHIP_METHOD_CODE := p_dlvy_assigned_lines(i).SHIP_METHOD_CODE;
14878                l_dlvy_assigned_lines(i).CARRIER_ID := p_dlvy_assigned_lines(i).CARRIER_ID;
14879                l_dlvy_assigned_lines(i).PARTY_ID := p_dlvy_assigned_lines(i).PARTY_ID;
14880                l_dlvy_assigned_lines(i).LINE_DIRECTION := p_dlvy_assigned_lines(i).LINE_DIRECTION;
14881                l_dlvy_assigned_lines(i).SHIPPING_CONTROL := nvl(p_dlvy_assigned_lines(i).SHIPPING_CONTROL,'BUYER');
14882 
14883                --#DUM_LOC(S)
14884 	       WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
14885 	           p_internal_cust_location_id  => l_dlvy_assigned_lines(i).ship_to_location_id,
14886                    x_internal_org_location_id   => l_physical_location_id,
14887                    x_return_status              => l_return_status);
14888 
14889  	       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14890 	          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14891 	              raise FND_API.G_EXC_UNEXPECTED_ERROR;
14892 	          END IF;
14893     	       END IF;
14894 
14895                IF (l_physical_location_id IS NOT NULL) THEN
14896   	          --
14897 	          IF l_debug_on THEN
14898 		     WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_dlvy_assigned_lines(i).ship_to_location_id||' is a dummy location');
14899    	          END IF;
14900 	          --
14901 	          l_dlvy_assigned_lines(i).ship_to_location_id:= l_physical_location_id;
14902                   -- AGDUMMY TODO
14903                   l_dlvy_assigned_lines(i).physical_ship_to_location_id := l_physical_location_id;
14904 	       END IF;
14905                --#DUM_LOC(E)
14906 
14907 	       EXIT WHEN i = p_dlvy_assigned_lines.LAST;
14908                i := p_dlvy_assigned_lines.NEXT(i);
14909 
14910         END LOOP;
14911       END IF;
14912 
14913     END IF;
14914 
14915      --  As per meeting on 10/18 : IGNORE GROUPING CRITERIA and do checks independently
14916      --  framework APIs will be called just before calling action appropriate private APIs
14917 
14918      -- The group line rec should have item and customer populated with the value of the first line
14919      -- For each subsequent line, check those with these values,
14920      -- if match, add to this group, if does not, create a new one
14921      -- ( The following checks are required for ACD )
14922      -- If WSH does not default from line to delivery,
14923      -- 1. any line that has violating item against its intmed ship to, ship method and last 2  being
14924      -- YES in grp crit, should error
14925      -- 2. any line that has violating ship from, ship to against ship method with ship method
14926      -- being YES in grp crit, should error
14927      -- 3. any line that has violating intmed ship to against ship method with both being
14928      -- YES in grp crit, should error
14929      -- 4. any line that has violating org, cus against its intmed ship to and last 1  being
14930      -- YES in grp crit, should error
14931      -- These 4 errors can be resolved by passing a hint to WSH that, even if grp crt is YES,
14932      -- do not default
14933 
14934      -- ( The following checks are required for ADD )
14935      -- For ADD returns whether 1. All input lines can be assigned to the target delivery
14936      -- If not, 2.Group of input lines how they can be grouped to create delivery
14937      -- 3. Input lines which can be assigned to the target delivery (line_group_id = delivery_id)
14938      -- Group input lines by item - item, cus - cus constraints first
14939      -- For each detail, find out if item satisfies delivery mode, carrier,intmed ship to
14940      -- and customer satisfies delivery customer / delivery already existing customers
14941      -- and item satisfies delivery already existing items
14942 
14943 
14944     j := l_del_detail_info.FIRST;
14945     IF j IS NOT NULL THEN
14946       LOOP
14947 
14948          -- Skip if SHIPPING_CONTROL is SUPPLIER
14949 
14950          IF l_del_detail_info(j).shipping_control = 'SUPPLIER' THEN
14951 
14952             l_supp_control_tab(l_del_detail_info(j).delivery_detail_id) := l_del_detail_info(j).delivery_detail_id;
14953             GOTO detail_nextpass;
14954 
14955          END IF;
14956 
14957          l_mode := null;
14958          l_service_level := NULL;
14959          l_carrier := null;
14960          l_intmed_location_id := null;
14961          l_group_id         :=0;
14962          l_found            := FALSE;
14963          l_failed_line_added := FALSE;
14964 
14965          l_validate_itmin_result    := 'S';
14966          l_validate_carrier_result  := 'S';
14967          l_validate_customer_result := 'S';
14968          l_validate_mode_result    := 'S';
14969          l_validate_intmed_result    := 'S';
14970          l_items_tab.DELETE;
14971          l_locations_list.DELETE;
14972 
14973          l_inp_items_cnt := l_items_tab.COUNT;
14974          l_items_tab(l_inp_items_cnt + 1).line_id := l_del_detail_info(j).delivery_detail_id;
14975          l_items_tab(l_inp_items_cnt + 1).item_id := l_del_detail_info(j).inventory_item_id;
14976          l_items_tab(l_inp_items_cnt + 1).org_id  := l_del_detail_info(j).organization_id;
14977 
14978          l_locations_list(l_locations_list.COUNT + 1) := l_del_detail_info(j).ship_from_location_id;
14979          l_locations_list(l_locations_list.COUNT + 1) := l_del_detail_info(j).ship_to_location_id;
14980 
14981          search_itm_fac_incl(
14982                      p_comp_class_tab      =>     l_comp_class_tab,
14983                      p_entity_type         =>     G_DEL_DETAIL,
14984                      p_entity_id           =>     l_del_detail_info(j).delivery_detail_id,
14985                      p_items_tab           =>     l_items_tab,
14986                      p_locations_list      =>     l_locations_list,
14987                      x_validate_result     =>     l_validate_itmfacin_result,
14988                      x_failed_constraints  =>     l_failed_constraints,
14989                      x_return_status       =>     l_return_status);
14990 
14991          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
14992             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
14993                 raise FND_API.G_EXC_UNEXPECTED_ERROR;
14994             END IF;
14995          END IF;
14996 
14997          IF l_validate_itmfacin_result = 'F' THEN
14998                    IF NOT l_failed_line_added THEN
14999                      -- Discard line (detail) from this group
15000                      -- populate failed lines
15001                      l_failed_lc := l_failed_lc + 1;
15002                      x_failed_lines(l_failed_lc).entity_line_id := l_del_detail_info(j).delivery_detail_id;
15003                      x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
15004                      l_failed_line_added := TRUE;
15005                    END IF;
15006              GOTO detail_nextpass;
15007          END IF;
15008 
15009          l_entity_tab(l_del_detail_info(j).delivery_detail_id).entity_id := l_del_detail_info(j).delivery_detail_id;
15010          l_entity_tab(l_del_detail_info(j).delivery_detail_id).organization_id := l_del_detail_info(j).organization_id;
15011          l_entity_tab(l_del_detail_info(j).delivery_detail_id).inventory_item_id := l_del_detail_info(j).inventory_item_id;
15012          l_entity_tab(l_del_detail_info(j).delivery_detail_id).customer_id := l_del_detail_info(j).customer_id;
15013          --
15014          IF l_debug_on THEN
15015            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);
15016          END IF;
15017          --
15018 
15019          IF j <> l_del_detail_info.FIRST THEN
15020 
15021             search_matching_group(
15022                   p_entity_type           => 'DLVB',
15023                   p_action_code           => p_action_code,
15024                   p_children_info         => l_dummy_assigned_lines,
15025                   p_comp_class_tab        => l_comp_class_tab,
15026                   p_target_stops_info     => l_target_tripstops,
15027                   p_entity_rec            => l_entity_tab(l_del_detail_info(j).delivery_detail_id),
15028                   p_entity_tab            => l_entity_tab, -- IN
15029                   p_group_tab             => x_group_info, -- IN
15030                   x_failed_constraints    => l_failed_constraints, -- IN OUT NOCOPY
15031                   x_group_id              => l_group_id, -- OUT
15032                   x_found                 => l_found, -- OUT
15033                   x_return_status         => l_return_status);
15034             --
15035             IF l_debug_on THEN
15036               WSH_DEBUG_SV.logmsg(l_module_name,'Called search_matching_group return status : '||l_return_status||' Group found ? '||l_group_id);
15037             END IF;
15038             --
15039 
15040             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15041                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15042                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
15043                END IF;
15044             END IF;
15045 
15046          END IF; -- FIRST
15047 
15048          IF l_found THEN
15049                l_entity_tab(l_del_detail_info(j).delivery_detail_id).group_id := l_group_id;
15050                --
15051                IF l_debug_on THEN
15052                  WSH_DEBUG_SV.logmsg(l_module_name,'Adding detail : '||l_del_detail_info(j).delivery_detail_id||' to_group : '||l_group_id);
15053                END IF;
15054                --
15055          ELSE
15056               create_valid_entity_group(
15057                   p_entity_rec    => l_entity_tab(l_del_detail_info(j).delivery_detail_id),
15058                   p_group_tab     => x_group_info, -- IN OUT
15059                   x_return_status => l_return_status);
15060               --
15061               IF l_debug_on THEN
15062                 WSH_DEBUG_SV.logmsg(l_module_name,'Called create_valid_entity_group return status : '||l_return_status);
15063               END IF;
15064               --
15065 
15066               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15067                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15068                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
15069                  END IF;
15070               END IF;
15071          END IF;
15072 
15073          -- Populate x_line_groups table with l_entity_tab(l_del_detail_info(j).delivery_detail_id)
15074 
15075          -- Populate x_line_groups table
15076          l_linegroup_indx := l_linegroup_indx + 1;
15077          x_line_groups(l_linegroup_indx).line_group_index := l_linegroup_indx;
15078          x_line_groups(l_linegroup_indx).entity_line_id   := l_del_detail_info(j).delivery_detail_id;
15079          x_line_groups(l_linegroup_indx).line_group_id   := l_entity_tab(l_del_detail_info(j).delivery_detail_id).group_id;
15080 
15081 
15082          -- Groups have already been created at this point x_group_info
15083          --
15084          IF l_debug_on THEN
15085            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);
15086          END IF;
15087          --
15088          --  END : Potential method to group details
15089          --  Returns valid groups of input lines
15090 
15091          -- If PKG with no target container
15092          -- go to next pass here
15093 
15094          IF (p_action_code = G_PACK_DLVB AND l_target_container.delivery_detail_id IS NULL) THEN
15095             GOTO detail_nextpass;
15096          END IF;
15097 
15098          --  START : Potential method to compare input details with target dlvy lines as per
15099          --  ITM - ITM and CUS - CUS constraints
15100 
15101          IF p_action_code = G_ASSIGN_DLVB_DLVY THEN
15102            IF l_comp_class_tab.EXISTS(G_CUSTOMER_CUSTOMER_NUM) AND
15103               l_target_delivery.customer_id <> l_del_detail_info(j).customer_id THEN
15104 
15105              l_item_check_cus := TRUE;
15106 
15107              validate_constraint(
15108                     p_comp_class_code          =>      G_CUSTOMER_CUSTOMER,
15109                     p_object1_val_num          =>      l_target_delivery.customer_id,
15110                     p_object2_val_num          =>      l_del_detail_info(j).customer_id,
15111                     x_validate_result          =>      l_validate_customer_result,
15112                     x_failed_constraint        =>      l_failed_constraint,
15113                     x_return_status            =>      l_return_status);
15114 
15115              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15116                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15117                   raise FND_API.G_EXC_UNEXPECTED_ERROR;
15118                END IF;
15119              END IF;
15120 
15121              IF l_validate_customer_result <> 'S' THEN
15122               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
15123               l_failed_constraint.entity_type :=  G_DEL_DETAIL;
15124               l_failed_constraint.entity_line_id :=  l_del_detail_info(j).delivery_detail_id;
15125               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
15126               IF l_validate_customer_result = 'E' THEN
15127                    l_validate_result := 'E';
15128                    IF NOT l_failed_line_added THEN
15129                      x_line_groups.DELETE(l_linegroup_indx);
15130                      -- Discard line (detail) from this group
15131                      -- populate failed lines
15132                      l_failed_lc := l_failed_lc + 1;
15133                      x_failed_lines(l_failed_lc).entity_line_id := l_del_detail_info(j).delivery_detail_id;
15134                      x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
15135                      l_failed_line_added := TRUE;
15136                    END IF;
15137               END IF;
15138 
15139              END IF;
15140              l_item_check_cus := FALSE;
15141 
15142             END IF;
15143 
15144          END IF;
15145 
15146          IF (p_action_code = G_PACK_DLVB) OR
15147             (p_action_code = G_ASSIGN_DLVB_DLVY) THEN
15148 
15149          -- Still need to check itm - itm and/or cus - cus
15150          -- between input lines and target delivery lines
15151 
15152             k := l_dlvy_assigned_lines.FIRST;
15153 
15154             IF k IS NOT NULL THEN
15155               LOOP
15156 
15157                   l_item_org_id := l_dlvy_assigned_lines(k).organization_id;
15158                   l_item_id := l_dlvy_assigned_lines(k).inventory_item_id;
15159                   l_customer_id := l_dlvy_assigned_lines(k).customer_id;
15160 
15161                   IF l_item_check_cus AND
15162                      l_del_detail_info(j).customer_id <> l_customer_id THEN
15163 
15164                     validate_constraint(
15165                       p_comp_class_code          =>      G_CUSTOMER_CUSTOMER,
15166                       p_object1_val_num          =>      l_del_detail_info(j).customer_id,
15167                       p_object2_val_num          =>      l_customer_id,
15168                       x_validate_result          =>      l_validate_customer_result,
15169                       x_failed_constraint        =>      l_failed_constraint,
15170                       x_return_status            =>      l_return_status);
15171 
15172                     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15173                        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15174 
15175                           raise FND_API.G_EXC_UNEXPECTED_ERROR;
15176                        END IF;
15177                     END IF;
15178 
15179                     IF l_validate_customer_result <> 'S' THEN
15180                      l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
15181                      l_failed_constraint.entity_type :=  G_DEL_DETAIL;
15182                      l_failed_constraint.entity_line_id :=  l_del_detail_info(j).delivery_detail_id;
15183                      l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
15184                          IF l_validate_customer_result = 'E' THEN
15185                             l_validate_result := 'E';
15186                           IF NOT l_failed_line_added THEN
15187                             x_line_groups.DELETE(l_linegroup_indx);
15188                             -- Discard line (detail) from this group
15189                             -- populate failed lines
15190                             l_failed_lc := l_failed_lc + 1;
15191                             x_failed_lines(l_failed_lc).entity_line_id := l_del_detail_info(j).delivery_detail_id;
15192                             x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
15193                             l_failed_line_added := TRUE;
15194                           END IF;
15195                          END IF;
15196                     END IF;
15197 
15198                   END IF;
15199 
15200                  -- itm - car/mod must use check between
15201                  -- p_children_info(l) and p_children_info(m)
15202 
15203                   IF (p_action_code = G_ASSIGN_DLVB_DLVY) THEN
15204 
15205                      l_target_rec.entity_id := l_dlvy_assigned_lines(k).delivery_detail_id;
15206                      l_target_rec.organization_id := l_dlvy_assigned_lines(k).organization_id;
15207                      l_target_rec.inventory_item_id := l_dlvy_assigned_lines(k).inventory_item_id;
15208                      l_target_rec.customer_id := l_dlvy_assigned_lines(k).customer_id;
15209                      --
15210                      IF l_debug_on THEN
15211                         WSH_DEBUG_SV.logmsg(l_module_name,'Created l_target_rec for assigned line : '||l_dlvy_assigned_lines(k).delivery_detail_id);
15212                      END IF;
15213                      --
15214 
15215                      IF ((l_entity_tab(l_del_detail_info(j).delivery_detail_id).inventory_item_id <> l_target_rec.inventory_item_id) OR
15216                         (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
15217 
15218                      search_group_itm (
15219                         p_comp_class_tab      =>   l_comp_class_tab,
15220                         p_entity_rec          =>   l_entity_tab(l_del_detail_info(j).delivery_detail_id),
15221                         p_target_rec          =>   l_target_rec,
15222                         x_validate_result     =>   l_validate_itmin_result,
15223                         x_failed_constraints  =>   l_failed_constraints,
15224                         x_return_status       =>   l_return_status);
15225 
15226                      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15227                         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15228                            raise FND_API.G_EXC_UNEXPECTED_ERROR;
15229                         END IF;
15230                      END IF;
15231 
15232                      IF l_validate_itmin_result = 'F' THEN
15233                          IF NOT l_failed_line_added THEN
15234                            x_line_groups.DELETE(l_linegroup_indx);
15235                            -- Discard line (detail) from this group
15236                            -- populate failed lines
15237                            l_failed_lc := l_failed_lc + 1;
15238                            x_failed_lines(l_failed_lc).entity_line_id := l_del_detail_info(j).delivery_detail_id;
15239                            x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
15240                            l_failed_line_added := TRUE;
15241                          END IF;
15242                          EXIT;
15243                      END IF;
15244                      END IF;
15245                   END IF;
15246 
15247                   EXIT WHEN k = l_dlvy_assigned_lines.LAST;
15248                   k := l_dlvy_assigned_lines.NEXT(k);
15249 
15250               END LOOP;
15251             END IF;
15252 
15253             IF l_validate_itmin_result = 'F' THEN
15254                GOTO detail_nextpass;
15255             END IF;
15256 
15257          --  END : Potential method to compare input details with target dlvy lines as per
15258          --  ITM - ITM and CUS - CUS constraints
15259 
15260          END IF;
15261 
15262          IF p_action_code = G_PACK_DLVB OR
15263             (l_target_delivery.ship_method_code IS NULL AND
15264              l_target_delivery.carrier_id IS NULL AND
15265              l_target_delivery.mode_of_transport IS NULL AND
15266              p_action_code = G_ASSIGN_DLVB_DLVY)
15267             OR (l_del_detail_info(j).ship_method_code IS NULL AND
15268                 l_del_detail_info(j).carrier_id IS NULL AND
15269                 p_action_code = G_AUTOCRT_DLVY) THEN
15270 
15271             GOTO detail_nextpass;
15272          END IF;
15273 
15274          IF p_action_code = G_ASSIGN_DLVB_DLVY THEN
15275            IF l_target_delivery.ship_method_code IS NOT NULL THEN
15276             l_carrier_service_inout_rec.ship_method_code := l_target_delivery.ship_method_code;
15277             WSH_CARRIERS_GRP.get_carrier_service_mode(
15278                      p_carrier_service_inout_rec   =>  l_carrier_service_inout_rec,
15279                      x_return_status       =>  l_return_status);
15280 
15281                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15282                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15283                   IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
15284                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
15285                   END IF;
15286                   raise g_get_carrmode_failed;
15287                  END IF;
15288                END IF;
15289                l_carrier := l_carrier_service_inout_rec.carrier_id;
15290                l_mode    := l_carrier_service_inout_rec.mode_of_transport;
15291            END IF;
15292            IF l_target_delivery.carrier_id IS NOT NULL THEN
15293               l_carrier := l_target_delivery.carrier_id;
15294            END IF;
15295            IF l_target_delivery.mode_of_transport IS NOT NULL THEN
15296               l_mode := l_target_delivery.mode_of_transport;
15297            END IF;
15298          ELSIF p_action_code = G_AUTOCRT_DLVY THEN
15299            IF l_del_detail_info(j).ship_method_code IS NOT NULL THEN
15300             l_carrier_service_inout_rec.ship_method_code := l_del_detail_info(j).ship_method_code;
15301             WSH_CARRIERS_GRP.get_carrier_service_mode(
15302                      p_carrier_service_inout_rec   =>  l_carrier_service_inout_rec,
15303                      x_return_status       =>  l_return_status);
15304 
15305             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15306                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15307                 IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
15308                    raise FND_API.G_EXC_UNEXPECTED_ERROR;
15309                 END IF;
15310                 raise g_get_carrmode_failed;
15311                END IF;
15312             END IF;
15313             l_carrier := l_carrier_service_inout_rec.carrier_id;
15314             l_mode    := l_carrier_service_inout_rec.mode_of_transport;
15315            END IF;
15316            IF l_del_detail_info(j).carrier_id IS NOT NULL THEN
15317                l_carrier := l_del_detail_info(j).carrier_id;
15318            END IF;
15319          END IF;
15320 
15321          IF l_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) AND l_carrier IS NOT NULL THEN
15322 
15323            validate_constraint(
15324              p_comp_class_code          =>      G_ITEM_CARRIER,
15325              p_object1_parent_id        =>      l_del_detail_info(j).organization_id,
15326              p_object1_val_num          =>      l_del_detail_info(j).inventory_item_id,
15327              p_object2_val_num          =>      l_carrier,
15328              x_validate_result          =>      l_validate_carrier_result,
15329              x_failed_constraint        =>      l_failed_constraint,
15330              x_return_status            =>      l_return_status);
15331 
15332            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15333               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15334                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
15335               END IF;
15336            END IF;
15337 
15338            IF l_validate_carrier_result <> 'S' THEN
15339               l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
15340               l_failed_constraint.entity_type :=  G_DEL_DETAIL;
15341               l_failed_constraint.entity_line_id :=  l_del_detail_info(j).delivery_detail_id;
15342               l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
15343               IF l_validate_carrier_result = 'E' THEN
15344                IF p_action_code = G_ASSIGN_DLVB_DLVY THEN
15345                   l_validate_result := 'E';
15346                      -- populate failed lines
15347                   IF NOT l_failed_line_added THEN
15348                       l_failed_lc := l_failed_lc + 1;
15349                       x_failed_lines(l_failed_lc).entity_line_id := l_del_detail_info(j).delivery_detail_id;
15350                       x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
15351                      -- Discard line (detail) from this group
15352                       x_line_groups.DELETE(l_linegroup_indx);
15353                       l_failed_line_added := TRUE;
15354                   END IF;
15355                END IF;
15356                x_group_info(l_entity_tab(l_del_detail_info(j).delivery_detail_id).group_id).upd_dlvy_ship_method     := 'N';
15357               END IF;
15358            END IF;
15359 
15360          END IF;
15361 
15362          IF l_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) AND l_mode IS NOT NULL THEN
15363 
15364            validate_constraint(
15365              p_comp_class_code          =>      G_ITEM_MODE,
15366              p_object1_parent_id        =>      l_del_detail_info(j).organization_id,
15367              p_object1_val_num          =>      l_del_detail_info(j).inventory_item_id,
15368              p_object2_val_char         =>      l_mode,
15369              x_validate_result          =>      l_validate_mode_result,
15370              x_failed_constraint        =>      l_failed_constraint,
15371              x_return_status            =>      l_return_status);
15372 
15373            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15374               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15375                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
15376               END IF;
15377            END IF;
15378 
15379            IF l_validate_mode_result <> 'S' THEN
15380             l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
15381             l_failed_constraint.entity_type :=  G_DEL_DETAIL;
15382             l_failed_constraint.entity_line_id :=  l_del_detail_info(j).delivery_detail_id;
15383             l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
15384             IF l_validate_mode_result = 'E' THEN
15385                IF p_action_code = G_ASSIGN_DLVB_DLVY THEN
15386                   l_validate_result := 'E';
15387                      -- populate failed lines
15388                   IF NOT l_failed_line_added THEN
15389                       l_failed_lc := l_failed_lc + 1;
15390                       x_failed_lines(l_failed_lc).entity_line_id := l_del_detail_info(j).delivery_detail_id;
15391                       x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
15392                      -- Discard line (detail) from this group
15393                       x_line_groups.DELETE(l_linegroup_indx);
15394                       l_failed_line_added := TRUE;
15395                   END IF;
15396                END IF;
15397                x_group_info(l_entity_tab(l_del_detail_info(j).delivery_detail_id).group_id).upd_dlvy_ship_method     := 'N';
15398             END IF;
15399            END IF;
15400 
15401          END IF;
15402 
15403          IF p_action_code = G_ASSIGN_DLVB_DLVY THEN
15404             GOTO detail_nextpass;
15405          END IF;
15406          IF l_carrier IS NOT NULL THEN
15407 
15408            IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) THEN
15409               validate_constraint(
15410                  p_comp_class_code          =>      G_FACILITY_CARRIER,
15411                  p_object1_type             =>      'FAC',
15412                  p_object1_val_num          =>      l_del_detail_info(j).ship_from_location_id,
15413                  p_object2_val_num          =>      l_carrier,
15414                  x_validate_result          =>      l_validate_carrier_result,
15415                  x_failed_constraint        =>      l_failed_constraint,
15416                  x_return_status            =>      l_return_status);
15417 
15418                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15419                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15420                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
15421                   END IF;
15422                END IF;
15423 
15424                IF l_validate_carrier_result <> 'S' THEN
15425                 l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
15426                 l_failed_constraint.entity_type :=  G_DEL_DETAIL;
15427                 l_failed_constraint.entity_line_id :=  l_del_detail_info(j).delivery_detail_id;
15428                 l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
15429                 IF l_validate_carrier_result = 'E' THEN
15430                    x_group_info(l_entity_tab(l_del_detail_info(j).delivery_detail_id).group_id).upd_dlvy_ship_method     := 'N';
15431                 END IF;
15432                END IF;
15433 
15434              -- If ship to location is also assumed to be customer site
15435              -- then need to check constraint with object1_type = CUSTOMER as well
15436                validate_constraint(
15437                  p_comp_class_code          =>      G_FACILITY_CARRIER,
15438                  p_object1_type             =>      'FAC',
15439                  p_object1_val_num          =>      l_del_detail_info(j).ship_to_location_id,
15440                  p_object2_val_num          =>      l_carrier,
15441                  x_validate_result          =>      l_validate_carrier_result,
15442                  x_failed_constraint        =>      l_failed_constraint,
15443                  x_return_status            =>      l_return_status);
15444 
15445                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15446                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15447                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
15448                   END IF;
15449                END IF;
15450 
15451                IF l_validate_carrier_result <> 'S' THEN
15452                 l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
15453                 l_failed_constraint.entity_type :=  G_DEL_DETAIL;
15454                 l_failed_constraint.entity_line_id :=  l_del_detail_info(j).delivery_detail_id;
15455                 l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
15456                 IF l_validate_carrier_result = 'E' THEN
15457                    -- populate failed lines
15458                    x_group_info(l_entity_tab(l_del_detail_info(j).delivery_detail_id).group_id).upd_dlvy_ship_method     := 'N';
15459                 END IF;
15460                END IF;
15461 
15462            END IF;
15463          END IF; -- l_carrier
15464 
15465          IF l_mode IS NOT NULL THEN
15466 
15467            IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) THEN
15468 
15469                validate_constraint(
15470                  p_comp_class_code          =>      G_FACILITY_MODE,
15471                  p_object1_type             =>      'FAC',
15472                  p_object1_val_num          =>      l_del_detail_info(j).ship_from_location_id,
15473                  p_object2_val_char         =>      l_mode,
15474                  x_validate_result          =>      l_validate_mode_result,
15475                  x_failed_constraint        =>      l_failed_constraint,
15476                  x_return_status            =>      l_return_status);
15477 
15478                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15479                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15480                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
15481                   END IF;
15482                END IF;
15483 
15484                IF l_validate_mode_result <> 'S' THEN
15485                 l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
15486                 l_failed_constraint.entity_type :=  G_DEL_DETAIL;
15487                 l_failed_constraint.entity_line_id :=  l_del_detail_info(j).delivery_detail_id;
15488                 l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
15489                 IF l_validate_mode_result = 'E' THEN
15490                          -- populate failed lines
15491                    x_group_info(l_entity_tab(l_del_detail_info(j).delivery_detail_id).group_id).upd_dlvy_ship_method     := 'N';
15492                 END IF;
15493                END IF;
15494 
15495                validate_constraint(
15496                  p_comp_class_code          =>      G_FACILITY_MODE,
15497                  p_object1_type             =>      'FAC',
15498                  p_object1_val_num          =>      l_del_detail_info(j).ship_to_location_id,
15499                  p_object2_val_char         =>      l_mode,
15500                  x_validate_result          =>      l_validate_mode_result,
15501                  x_failed_constraint        =>      l_failed_constraint,
15502                  x_return_status            =>      l_return_status);
15503 
15504                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15505                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15506                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
15507                   END IF;
15508                END IF;
15509 
15510                IF l_validate_mode_result <> 'S' THEN
15511                 l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
15512                 l_failed_constraint.entity_type :=  G_DEL_DETAIL;
15513                 l_failed_constraint.entity_line_id :=  l_del_detail_info(j).delivery_detail_id;
15514                 l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
15515                 IF l_validate_mode_result = 'E' THEN
15516                          -- populate failed lines
15517                    x_group_info(l_entity_tab(l_del_detail_info(j).delivery_detail_id).group_id).upd_dlvy_ship_method     := 'N';
15518                 END IF;
15519                END IF;
15520 
15521            END IF;
15522          END IF; -- l_mode
15523 
15524          <<detail_nextpass>>
15525 
15526          EXIT WHEN j = l_del_detail_info.LAST;
15527          j := l_del_detail_info.NEXT(j);
15528       END LOOP;
15529     END IF;
15530 
15531     IF l_supp_control_tab.COUNT > 0 THEN
15532 
15533         -- Populate line_groups and group
15534 
15535         -- Add to x_group_info
15536         l_group_count := x_group_info.COUNT + 1;
15537         x_group_info(l_group_count).group_index := l_group_count;
15538         x_group_info(l_group_count).line_group_id := l_group_count;
15539 
15540         i := l_supp_control_tab.FIRST;
15541         LOOP
15542 
15543            -- Populate x_line_groups table
15544            l_linegroup_indx := x_line_groups.COUNT + 1;
15545            x_line_groups(l_linegroup_indx).line_group_index := l_linegroup_indx;
15546            x_line_groups(l_linegroup_indx).entity_line_id   := l_supp_control_tab(i);
15547            x_line_groups(l_linegroup_indx).line_group_id    := l_group_count;
15548 
15549            EXIT WHEN i=l_supp_control_tab.LAST;
15550            i := l_supp_control_tab.NEXT(i);
15551         END LOOP;
15552 
15553     END IF;
15554 
15555     -- Populate x_validate_result
15556     IF x_group_info.COUNT > 1 OR x_failed_lines.COUNT > 0 THEN
15557         x_validate_result := 'F';
15558         IF x_group_info.COUNT > 1 AND p_action_code = G_ASSIGN_DLVB_DLVY THEN
15559            -- Put all input lines in incompatible groups into failed lines
15560 
15561            -- After changing the logic to form groups in case of
15562            -- assign, the following list of groups will only contain
15563            -- mutually incompatible groups
15564            -- not the always successful groups
15565            i := x_group_info.FIRST;
15566            LOOP
15567 
15568              -- Will not delete these lines from linegroups
15569              -- Hence for this case the sum of failed lines and
15570              -- lines in linegroups will exceed number of input lines
15571              -- by these lines in linegroups
15572              -- Will not delete these incompatible groups
15573              j := x_line_groups.FIRST;
15574              LOOP
15575 
15576                 IF x_line_groups(j).line_group_id <> x_group_info(i).line_group_id THEN
15577                    GOTO next_linegroup;
15578                 END IF;
15579 
15580                 -- Add to failed lines
15581                 l_failed_lc := x_failed_lines.COUNT + 1;
15582                 x_failed_lines(l_failed_lc).entity_line_id := x_line_groups(j).entity_line_id;
15583                 x_failed_lines(l_failed_lc).failed_line_index := l_failed_lc;
15584                 <<next_linegroup>>
15585                 EXIT WHEN j=x_line_groups.LAST;
15586                 j := x_line_groups.NEXT(j);
15587              END LOOP;
15588 
15589              EXIT WHEN i=x_group_info.LAST;
15590              i := x_group_info.NEXT(i);
15591            END LOOP;
15592         END IF;
15593     END IF;
15594 
15595     IF x_failed_lines.COUNT = 0 AND p_action_code = G_AUTOCRT_DLVY THEN
15596        l_failed_constraints.DELETE;
15597     END IF;
15598 
15599     --  Loop over l_failed_constraints to add to the mesage stack
15600 
15601     stack_messages (
15602              p_failed_constraints       => l_failed_constraints,
15603              x_msg_count                => x_msg_count,
15604              x_msg_data                 => x_msg_data,
15605              x_return_status            => l_return_status);
15606 
15607     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15608          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15609             raise FND_API.G_EXC_UNEXPECTED_ERROR;
15610          END IF;
15611     END IF;
15612 
15613     IF x_validate_result = 'F' THEN
15614         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
15615     ELSIF l_failed_constraints.COUNT > 0 THEN
15616         x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
15617     END IF;
15618 
15619     --
15620     IF l_debug_on THEN
15621        WSH_DEBUG_SV.pop(l_module_name);
15622     END IF;
15623     --
15624 
15625 EXCEPTION
15626     WHEN g_get_carrmode_failed THEN
15627       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
15628       --
15629       IF l_debug_on THEN
15630         WSH_DEBUG_SV.pop(l_module_name,' get carrier-mode failed ');
15631       END IF;
15632       --
15633     WHEN g_invalid_action_code THEN
15634       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
15635       --
15636       IF l_debug_on THEN
15637         WSH_DEBUG_SV.pop(l_module_name,' invalid_action_code ');
15638       END IF;
15639       --
15640     WHEN g_invalid_input THEN
15641       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
15642       --
15643       IF l_debug_on THEN
15644         WSH_DEBUG_SV.pop(l_module_name,' invalid_input ');
15645       END IF;
15646       --
15647 
15648     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
15649       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
15650       --
15651       IF l_debug_on THEN
15652         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
15653         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
15654       END IF;
15655       --
15656     WHEN others THEN
15657       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.validate_constraint_dlvb');
15658       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
15659       --
15660       IF l_debug_on THEN
15661         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
15662         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
15663       END IF;
15664       --
15665 END validate_constraint_dlvb;
15666 
15667 
15668 --***************************************************************************
15669 --
15670 --========================================================================
15671 -- PROCEDURE : validate_constraint_trip    Called by constraint Wrapper API
15672 --                                         and the Group API.
15673 --
15674 -- PARAMETERS: p_init_msg_list             FND_API.G_TRUE to reset list
15675 --             p_action_code               Predefined action code
15676 --             p_exception_list            Compatibility classes to skip if any
15677 --                                         indexed by class code numbers
15678 --             p_trip_info                 Table of Trip records to process
15679 --             p_trip_assigned_dels        Table of delivery records already in the trip
15680 --                                         If not passed, the API will query
15681 --             p_trip_dlvy_lines           Table of delivery details already in the trip
15682 --                                         If not passed, the API will query
15683 --             p_trip_incl_stops           Table of Stop records already in the trip
15684 --                                         If not passed, the API will query
15685 --             x_fail_trips                Table of input trips that failed constraint check
15686 --             x_validate_result           Constraint Validation result : S / F
15687 --             x_msg_count                 Number of messages in the list
15688 --             x_msg_data                  Text of messages
15689 --             x_return_status             Return status
15690 -- COMMENT   : This procedure is used to perform for following actions
15691 --             A. Update an existing trip (UPT)
15692 --========================================================================
15693 
15694 PROCEDURE validate_constraint_trip(
15695              p_init_msg_list            IN      VARCHAR2 DEFAULT fnd_api.g_false,
15696              p_action_code              IN      VARCHAR2 DEFAULT NULL,
15697              p_exception_list           IN      WSH_UTIL_CORE.Column_Tab_Type,
15698              p_trip_info                IN      trip_ccinfo_tab_type,
15699              p_trip_assigned_dels       IN      delivery_ccinfo_tab_type,
15700              p_trip_dlvy_lines          IN      detail_ccinfo_tab_type,
15701              p_trip_incl_stops          IN      stop_ccinfo_tab_type,
15702              x_fail_trips               OUT NOCOPY    WSH_UTIL_CORE.id_tab_type,
15703              x_validate_result          OUT NOCOPY    VARCHAR2,
15704              x_msg_count                OUT NOCOPY    NUMBER,
15705              x_msg_data                 OUT NOCOPY    VARCHAR2,
15706              x_return_status            OUT NOCOPY    VARCHAR2)
15707 IS
15708 
15709     j                                   NUMBER := 0;
15710     k                                   NUMBER := 0;
15711     l                                   NUMBER := 0;
15712     l_carrier                           NUMBER := 0;
15713     l_vehicle_type                      NUMBER := 0;
15714     l_mode                              VARCHAR2(30);
15715     l_service_level                     VARCHAR2(30) := NULL;
15716     l_carrier_service_inout_rec         WSH_CARRIERS_GRP.Carrier_Service_InOut_Rec_Type;
15717     l_trip_del_cnt                      NUMBER := 0;
15718     l_trip_detail_cnt                   NUMBER := 0;
15719     l_trip_stops_cnt                    NUMBER := 0;
15720     l_out_object2_num                   NUMBER:=0;
15721     l_out_object2_char                  VARCHAR2(30):=NULL;
15722     l_comp_class_tab                    WSH_UTIL_CORE.Column_Tab_Type;
15723     l_return_status                     VARCHAR2(1);
15724     l_failed_constraint                 line_constraint_rec_type;
15725     l_failed_constraints                line_constraint_tab_type;
15726     l_curr_trip_added                   BOOLEAN := FALSE;
15727     l_validate_mode_result              VARCHAR2(1) := 'S';
15728     l_validate_carrier_result           VARCHAR2(1) := 'S';
15729     l_validate_vehicle_result           VARCHAR2(1) := 'S';
15730     l_validate_faccar_result            VARCHAR2(1) := 'S';
15731     l_validate_facveh_result            VARCHAR2(1) := 'S';
15732     l_validate_facmod_result            VARCHAR2(1) := 'S';
15733     l_validate_itmveh_result            VARCHAR2(1) := 'S';
15734     l_validate_itmcar_result            VARCHAR2(1) := 'S';
15735     l_validate_itmmod_result            VARCHAR2(1) := 'S';
15736     l_validate_in_result                VARCHAR2(1) := 'S';
15737     l_validate_ex_result                VARCHAR2(1) := 'S';
15738     l_delivery_rec                      delivery_ccinfo_rec_type;
15739     l_detail_rec                        detail_ccinfo_rec_type;
15740     l_stop_rec                          stop_ccinfo_rec_type;
15741     l_trip_assigned_dels                delivery_ccinfo_tab_type;
15742     l_trip_dlvy_lines                   detail_ccinfo_tab_type;
15743     l_trip_incl_stops                   stop_ccinfo_tab_type;
15744     l_vehicle_name                      VARCHAR2(2000);
15745     l_vehicle_org_name                  VARCHAR2(240);
15746 
15747     --#DUM_LOC(S)
15748     l_physical_location_id		NUMBER;
15749     --#DUM_LOC(E)
15750 
15751     --SBAKSHI(8/24)
15752     l_trip_incl_stops_sort		stop_ccinfo_tab_type;
15753     l_idx				NUMBER;
15754     --SBAKSHI(8/24)
15755     l_debug_on                          CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
15756     l_module_name                       CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'validate_constraint_trip';
15757 
15758 BEGIN
15759 
15760     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
15761     x_validate_result := 'S';
15762 
15763     g_itm_mustuse_cache.DELETE;
15764     g_itmloc_mustuse_cache.DELETE;
15765     g_itm_exclusive_cache.DELETE;
15766     g_fac_exclusive_cache.DELETE;
15767 
15768     IF FND_API.to_Boolean( p_init_msg_list ) THEN
15769          FND_MSG_PUB.initialize;
15770     END IF;
15771 
15772     IF l_debug_on THEN
15773        wsh_debug_sv.push(l_module_name);
15774        WSH_DEBUG_SV.logmsg(l_module_name,'p_init_msg_list : '||p_init_msg_list);
15775     END IF;
15776 
15777     refresh_cache(l_return_status);
15778 
15779     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15780          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15781             raise FND_API.G_EXC_UNEXPECTED_ERROR;
15782          END IF;
15783     END IF;
15784 
15785     IF NOT p_exception_list.EXISTS(G_FACILITY_MODE_NUM) THEN
15786       l_comp_class_tab(G_FACILITY_MODE_NUM) := G_FACILITY_MODE;
15787     END IF;
15788     IF NOT p_exception_list.EXISTS(G_FACILITY_CARRIER_NUM) THEN
15789       l_comp_class_tab(G_FACILITY_CARRIER_NUM) := G_FACILITY_CARRIER;
15790     END IF;
15791     IF NOT p_exception_list.EXISTS(G_FACILITY_VEHICLE_NUM) THEN
15792       l_comp_class_tab(G_FACILITY_VEHICLE_NUM) := G_FACILITY_VEHICLE;
15793     END IF;
15794     IF NOT p_exception_list.EXISTS(G_ITEM_MODE_NUM) THEN
15795       l_comp_class_tab(G_ITEM_MODE_NUM) := G_ITEM_MODE;
15796     END IF;
15797     IF NOT p_exception_list.EXISTS(G_ITEM_CARRIER_NUM) THEN
15798       l_comp_class_tab(G_ITEM_CARRIER_NUM) := G_ITEM_CARRIER;
15799     END IF;
15800     IF NOT p_exception_list.EXISTS(G_ITEM_VEHICLE_NUM) THEN
15801       l_comp_class_tab(G_ITEM_VEHICLE_NUM) := G_ITEM_VEHICLE;
15802     END IF;
15803 
15804     j := p_trip_info.FIRST;
15805     IF j IS NOT NULL THEN
15806     LOOP
15807     IF p_trip_assigned_dels.COUNT = 0 THEN
15808 
15809           OPEN c_get_trip_dlvy(p_trip_info(j).trip_id); -- or container_id
15810           LOOP
15811                FETCH c_get_trip_dlvy INTO l_delivery_rec;
15812                EXIT WHEN c_get_trip_dlvy%NOTFOUND;
15813 
15814 	       --#DUM_LOC(S)
15815 	       WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
15816 	             p_internal_cust_location_id  => l_delivery_rec.ultimate_dropoff_location_id,
15817 	             x_internal_org_location_id   => l_physical_location_id,
15818 		     x_return_status              => l_return_status);
15819 
15820 	       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15821 	         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15822 	            raise FND_API.G_EXC_UNEXPECTED_ERROR;
15823 	         END IF;
15824   	       END IF;
15825 
15826 	       IF (l_physical_location_id IS NOT NULL) THEN
15827   	         --
15828 	         IF l_debug_on THEN
15829 		     WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_delivery_rec.ultimate_dropoff_location_id||' is a dummy location');
15830 	         END IF;
15831 	         --
15832 	         l_delivery_rec.ultimate_dropoff_location_id := l_physical_location_id;
15833                  -- AGDUMMY TODO
15834                  l_delivery_rec.physical_dropoff_location_id := l_physical_location_id;
15835 	       END IF;
15836                --#DUM_LOC(E)
15837 
15838 	       l_trip_del_cnt := l_trip_del_cnt + 1;
15839                l_trip_assigned_dels(l_trip_del_cnt) := l_delivery_rec;
15840           END LOOP;
15841           CLOSE c_get_trip_dlvy;
15842     END IF;
15843 
15844     IF p_trip_dlvy_lines.COUNT = 0 THEN
15845 
15846           OPEN c_get_trip_details_std(p_trip_info(j).trip_id); -- or container_id
15847           LOOP
15848                FETCH c_get_trip_details_std INTO l_detail_rec;
15849                EXIT WHEN c_get_trip_details_std%NOTFOUND;
15850                --#DUM_LOC(S)
15851 	       WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
15852 	  	      p_internal_cust_location_id  => l_detail_rec.ship_to_location_id,
15853 	          x_internal_org_location_id   => l_physical_location_id,
15854               x_return_status              => l_return_status);
15855 
15856 	       IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15857 		 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15858 			raise FND_API.G_EXC_UNEXPECTED_ERROR;
15859 	         END IF;
15860 	       END IF;
15861 
15862 	       IF (l_physical_location_id IS NOT NULL) THEN
15863   	          --
15864 	          IF l_debug_on THEN
15865 		    WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_detail_rec.ship_to_location_id||' is a dummy location');
15866 	          END IF;
15867 	          --
15868 	          l_detail_rec.ship_to_location_id:= l_physical_location_id;
15869                   -- AGDUMMY TODO
15870                   l_detail_rec.physical_ship_to_location_id := l_physical_location_id;
15871 	       END IF;
15872                 --#DUM_LOC(E)
15873 	       l_trip_detail_cnt := l_trip_detail_cnt + 1;
15874                l_trip_dlvy_lines(l_trip_detail_cnt) := l_detail_rec;
15875           END LOOP;
15876           CLOSE c_get_trip_details_std;
15877     END IF;
15878 
15879     IF p_trip_incl_stops.COUNT = 0 THEN
15880 
15881           OPEN c_get_trip_stops(p_trip_info(j).trip_id); -- or container_id
15882           LOOP
15883 	       -- Cursor c_get_trip_stops handles the case of returning physical locations
15884 	       -- for the dummy location.
15885 	       FETCH c_get_trip_stops INTO l_stop_rec;
15886                EXIT WHEN c_get_trip_stops%NOTFOUND;
15887                l_trip_stops_cnt := l_trip_stops_cnt + 1;
15888                l_trip_incl_stops(l_trip_stops_cnt) := l_stop_rec;
15889 
15890 	  END LOOP;
15891           CLOSE c_get_trip_stops;
15892 
15893     END IF;
15894 
15895     EXIT WHEN j = p_trip_info.LAST;
15896     j := p_trip_info.NEXT(j);
15897     END LOOP;
15898     END IF;
15899 
15900     IF p_trip_assigned_dels.COUNT <> 0 THEN
15901 
15902 	l := p_trip_assigned_dels.FIRST;
15903         LOOP
15904            l_trip_assigned_dels(l) := p_trip_assigned_dels(l);
15905 
15906 	   --#DUM_LOC(S)
15907 	   WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
15908              p_internal_cust_location_id  => l_trip_assigned_dels(l).ultimate_dropoff_location_id,
15909              x_internal_org_location_id   => l_physical_location_id,
15910              x_return_status              => l_return_status);
15911 
15912 	   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15913 	     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15914 	        raise FND_API.G_EXC_UNEXPECTED_ERROR;
15915 	     END IF;
15916   	   END IF;
15917 
15918 	   IF (l_physical_location_id IS NOT NULL) THEN
15919   	      --
15920 	      IF l_debug_on THEN
15921 		  WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_trip_assigned_dels(l).ultimate_dropoff_location_id||' is a dummy location');
15922 	      END IF;
15923 	      --
15924 	      l_trip_assigned_dels(l).ultimate_dropoff_location_id := l_physical_location_id;
15925               -- AGDUMMY TODO
15926               l_trip_assigned_dels(l).physical_dropoff_location_id := l_physical_location_id;
15927 	   END IF;
15928            --#DUM_LOC(E)
15929 
15930            EXIT WHEN l = p_trip_assigned_dels.LAST;
15931            l := p_trip_assigned_dels.NEXT(l);
15932         END LOOP;
15933 
15934     END IF;
15935 
15936     IF p_trip_dlvy_lines.COUNT <> 0 THEN
15937 
15938         l := p_trip_dlvy_lines.FIRST;
15939         LOOP
15940            l_trip_dlvy_lines(l) := p_trip_dlvy_lines(l);
15941            --#DUM_LOC(S)
15942 	   WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
15943 	      p_internal_cust_location_id  => l_trip_dlvy_lines(l).ship_to_location_id,
15944               x_internal_org_location_id   => l_physical_location_id,
15945               x_return_status              => l_return_status);
15946 
15947  	   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15948 	     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15949 	        raise FND_API.G_EXC_UNEXPECTED_ERROR;
15950 	     END IF;
15951     	   END IF;
15952 
15953   	   IF (l_physical_location_id IS NOT NULL) THEN
15954   	      --
15955 	      IF l_debug_on THEN
15956 		  WSH_DEBUG_SV.logmsg(l_module_name,'Location '||l_trip_dlvy_lines(l).ship_to_location_id||' is a dummy location');
15957 	      END IF;
15958 	      --
15959 	      l_trip_dlvy_lines(l).ship_to_location_id:= l_physical_location_id;
15960               -- AGDUMMY TODO
15961               l_trip_dlvy_lines(l).physical_ship_to_location_id := l_physical_location_id;
15962 	   END IF;
15963            --#DUM_LOC(E)
15964 
15965 	   EXIT WHEN l = p_trip_dlvy_lines.LAST;
15966            l := p_trip_dlvy_lines.NEXT(l);
15967         END LOOP;
15968     END IF;
15969 
15970     IF p_trip_incl_stops.COUNT <> 0 THEN
15971 
15972 	/* SBAKSHI 8/24
15973 	   We should have p_trip_incl_stops sorted by planned arrival date
15974 	   p_trip_incl_stops is IN RECORD  record
15975 	   Need to make a local record structure l_trip_incl_stops_sort for this purpose
15976 	*/
15977 
15978 	sort_stop_table_asc(
15979 	   p_stop_table	   => p_trip_incl_stops,
15980 	   x_sort_stop_table => l_trip_incl_stops_sort,
15981 	   x_return_status   => l_return_status);
15982 
15983 	IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
15984 	  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
15985 	    raise FND_API.G_EXC_UNEXPECTED_ERROR;
15986 	  END IF;
15987     	END IF;
15988 
15989 	-- l := p_trip_incl_stops.FIRST;
15990   	l := l_trip_incl_stops_sort.FIRST;
15991 
15992 	LOOP
15993            -- AGDUMMY
15994            -- Sort them in terms of planned_arrival_date
15995 	   -- l_trip_incl_stops(l) := p_trip_incl_stops(l);
15996 
15997 	   l_trip_incl_stops(l) := l_trip_incl_stops_sort(l);
15998 	   --#DUM_LOC(S)
15999 	   -- IF (p_trip_incl_stops(l).physical_location_id IS NOT NULL)  THEN
16000 	   IF (l_trip_incl_stops_sort(l).physical_location_id IS NOT NULL)  THEN
16001 		 l_trip_incl_stops(l).stop_location_id := l_trip_incl_stops(l).physical_location_id;
16002 	   END IF;
16003 	   --#DUM_LOC(E)
16004  	   -- EXIT WHEN l = p_trip_incl_stops.LAST;
16005            -- l := p_trip_incl_stops.NEXT(l);
16006 
16007 	   EXIT WHEN l = l_trip_incl_stops_sort.LAST;
16008 	   l := l_trip_incl_stops_sort.NEXT(l);
16009 	END LOOP;
16010 
16011     END IF;
16012     --SBAKSHI 8/24 (E)
16013 
16014     -- Only for action code = UPT
16015     -- Can update trip's carrier , mode, vehicle
16016 
16017     -- Need to check FAC - CAR,MOD    ITM - CAR,MOD
16018 
16019     --LOOP  -- Over input trips
16020     j := p_trip_info.FIRST;
16021     IF j IS NOT NULL THEN
16022       LOOP
16023 
16024         l_validate_faccar_result := 'S';
16025         l_validate_facmod_result := 'S';
16026         l_validate_facveh_result := 'S';
16027         l_validate_itmcar_result := 'S';
16028         l_validate_itmmod_result := 'S';
16029         l_validate_itmveh_result := 'S';
16030         l_validate_mode_result   := 'S';
16031         l_validate_carrier_result := 'S';
16032         l_validate_vehicle_result := 'S';
16033         l_validate_in_result := 'S';
16034         l_validate_ex_result := 'S';
16035         l_curr_trip_added := FALSE;
16036         l_carrier         := NULL;
16037         l_mode            := NULL;
16038         l_service_level   := NULL;
16039         l_vehicle_type    := NULL;
16040 
16041         IF (p_trip_info(j).carrier_id IS NULL OR p_trip_info(j).mode_of_transport IS NULL) AND
16042            (p_trip_info(j).ship_method_code IS NOT NULL) THEN
16043 
16044           l_carrier_service_inout_rec.ship_method_code := p_trip_info(j).ship_method_code;
16045           WSH_CARRIERS_GRP.get_carrier_service_mode(
16046                    p_carrier_service_inout_rec   =>  l_carrier_service_inout_rec,
16047                    x_return_status       =>  l_return_status);
16048 
16049           IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16050             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16051              IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
16052                 raise FND_API.G_EXC_UNEXPECTED_ERROR;
16053              END IF;
16054              raise g_get_carrmode_failed;
16055             END IF;
16056           END IF;
16057           l_carrier := l_carrier_service_inout_rec.carrier_id;
16058           l_mode    := l_carrier_service_inout_rec.mode_of_transport;
16059 
16060         END IF; -- p_trip_info(j).carrier_id IS NULL OR ..
16061 
16062         -- If carrier_id or mode is passed in, then those get preference for validation
16063         -- If they are not, they are derived from ship method if that is passed
16064 
16065         IF p_trip_info(j).carrier_id IS NOT NULL THEN
16066            l_carrier := p_trip_info(j).carrier_id;
16067         END IF;
16068         IF p_trip_info(j).mode_of_transport IS NOT NULL THEN
16069            l_mode := p_trip_info(j).mode_of_transport;
16070         END IF;
16071 
16072         IF (p_trip_info(j).VEHICLE_ITEM_ID IS NOT NULL AND p_trip_info(j).VEHICLE_ORGANIZATION_ID IS NOT NULL) THEN
16073 
16074           WSH_FTE_INTEGRATION.get_vehicle_type(
16075                    p_vehicle_item_id     =>  p_trip_info(j).VEHICLE_ITEM_ID,
16076                    p_vehicle_org_id      =>  p_trip_info(j).VEHICLE_ORGANIZATION_ID,
16077                    x_vehicle_type_id     =>  l_vehicle_type,
16078                    x_return_status       =>  l_return_status);
16079 
16080           IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16081              IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16082               IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
16083                 raise FND_API.G_EXC_UNEXPECTED_ERROR;
16084               END IF;
16085                l_vehicle_name := WSH_UTIL_CORE.get_item_name (p_item_id => p_trip_info(j).VEHICLE_ITEM_ID,
16086                                                            p_organization_id => p_trip_info(j).VEHICLE_ORGANIZATION_ID);
16087                l_vehicle_org_name := WSH_UTIL_CORE.get_org_name (p_organization_id => p_trip_info(j).VEHICLE_ORGANIZATION_ID);
16088                FND_MESSAGE.SET_NAME('WSH','WSH_VEHICLE_TYPE_UNDEFINED');
16089                FND_MESSAGE.SET_TOKEN('ITEM',l_vehicle_name);
16090                FND_MESSAGE.SET_TOKEN('ORGANIZATION',l_vehicle_org_name);
16091                FND_MSG_PUB.ADD;
16092               --raise g_get_vehicletype_failed;
16093              END IF;
16094           END IF;
16095 
16096         END IF; -- p_trip_info(j).VEHICLE_ITEM_ID IS NOT NULL AND ..
16097 
16098 
16099         --LOOP  -- Over each stop of this input trip
16100         k := l_trip_incl_stops.FIRST;
16101         IF k IS NOT NULL THEN
16102           LOOP
16103 
16104         -- AGDUMMY
16105         -- If for a trip,
16106         -- a dummy stop has already been checked, then
16107         -- any other stop in that trip that
16108         -- has the stop_location_id same as that of the physical_location_id of the already checked
16109         -- dummy stop, should not be checked.
16110 
16111         -- When ordered by planned_arrival_date, these two stops would come sequentially
16112         -- one exactly after the other always - wrudge 8/20/04
16113 
16114         -- Need to consider Facility - Vehicle and Item - Vehicle as well
16115 
16116             IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) THEN
16117 
16118                check_inclusive_object2(
16119                  p_comp_class_code          =>      G_FACILITY_MODE,
16120                  p_entity_type              =>      G_TRIP,
16121                  p_entity_id                =>      p_trip_info(j).trip_id,
16122                  p_object1_type             =>      'FAC',
16123                  p_object1_val_num          =>      l_trip_incl_stops(k).stop_location_id,
16124                  p_object2_type             =>      'MOD',
16125                  p_object2_val_char         =>      l_mode,
16126                  x_out_object2_num          =>      l_out_object2_num,
16127                  x_out_object2_char         =>      l_out_object2_char,
16128                  x_validate_result          =>      l_validate_mode_result,
16129                  x_failed_constraint        =>      l_failed_constraints,
16130                  x_return_status            =>      l_return_status);
16131 
16132                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16133                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16134                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16135                   END IF;
16136                END IF;
16137 
16138                IF l_validate_mode_result = 'F' THEN
16139                   l_validate_in_result := 'E';
16140                END IF;
16141 
16142             END IF;
16143 
16144             IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) THEN
16145 
16146                check_inclusive_object2(
16147                  p_comp_class_code          =>      G_FACILITY_CARRIER,
16148                  p_entity_type              =>      G_TRIP,
16149                  p_entity_id                =>      p_trip_info(j).trip_id,
16150                  p_object1_type             =>      'FAC',
16151                  p_object1_val_num          =>      l_trip_incl_stops(k).stop_location_id,
16152                  p_object2_type             =>      'CAR',
16153                  p_object2_val_num          =>      l_carrier,
16154                  x_out_object2_num          =>      l_out_object2_num,
16155                  x_out_object2_char         =>      l_out_object2_char,
16156                  x_validate_result          =>      l_validate_carrier_result,
16157                  x_failed_constraint        =>      l_failed_constraints,
16158                  x_return_status            =>      l_return_status);
16159 
16160                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16161                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16162                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16163                   END IF;
16164                END IF;
16165 
16166                IF l_validate_carrier_result = 'F' THEN
16167                   l_validate_in_result := 'E';
16168                END IF;
16169 
16170             END IF;
16171 
16172             IF l_comp_class_tab.EXISTS(G_FACILITY_VEHICLE_NUM) THEN
16173 
16174                check_inclusive_object2(
16175                  p_comp_class_code          =>      G_FACILITY_VEHICLE,
16176                  p_entity_type              =>      G_TRIP,
16177                  p_entity_id                =>      p_trip_info(j).trip_id,
16178                  p_object1_type             =>      'FAC',
16179                  p_object1_val_num          =>      l_trip_incl_stops(k).stop_location_id,
16180                  p_object2_type             =>      'VHT',
16181                  p_object2_val_num          =>      l_vehicle_type,
16182                  x_out_object2_num          =>      l_out_object2_num,
16183                  x_out_object2_char         =>      l_out_object2_char,
16184                  x_validate_result          =>      l_validate_vehicle_result,
16185                  x_failed_constraint        =>      l_failed_constraints,
16186                  x_return_status            =>      l_return_status);
16187 
16188                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16189                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16190                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16191                   END IF;
16192                END IF;
16193 
16194                IF l_validate_vehicle_result = 'F' THEN
16195                   l_validate_in_result := 'E';
16196                END IF;
16197 
16198             END IF;
16199 
16200             IF l_validate_in_result = 'E' THEN
16201                EXIT;
16202             END IF;
16203 
16204              -- Validate FAC - CAR  FAC - MOD against the stop locations
16205 	     -- Need to consider Facility - Vehicle
16206 
16207             IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) THEN
16208 
16209                validate_constraint(
16210                  p_comp_class_code          =>      G_FACILITY_CARRIER,
16211                  p_object1_type             =>      'FAC',
16212                  p_object1_val_num          =>      l_trip_incl_stops(k).stop_location_id,
16213                  p_object2_type             =>      'CAR',
16214                  p_object2_val_num          =>      l_carrier,
16215                  x_validate_result          =>      l_validate_faccar_result,
16216                  x_failed_constraint        =>      l_failed_constraint,
16217                  x_return_status            =>      l_return_status);
16218 
16219                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16220                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16221                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16222                   END IF;
16223                END IF;
16224 
16225                IF l_validate_faccar_result <> 'S' THEN
16226                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
16227                   l_failed_constraint.entity_type :=  G_TRIP;
16228                   l_failed_constraint.entity_line_id :=  p_trip_info(j).trip_id;
16229                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
16230                   IF l_validate_faccar_result = 'E' THEN
16231                      l_validate_ex_result := 'E';
16232                   END IF;
16233                END IF;
16234 
16235             END IF;
16236 
16237             IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) THEN
16238 
16239                validate_constraint(
16240                  p_comp_class_code          =>      G_FACILITY_MODE,
16241                  p_object1_type             =>      'FAC',
16242                  p_object1_val_num          =>      l_trip_incl_stops(k).stop_location_id,
16243                  p_object2_type             =>      'MOD',
16244                  p_object2_val_char         =>      l_mode,
16245                  x_validate_result          =>      l_validate_facmod_result,
16246                  x_failed_constraint        =>      l_failed_constraint,
16247                  x_return_status            =>      l_return_status);
16248 
16249                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16250                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16251                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16252                   END IF;
16253                END IF;
16254 
16255                IF l_validate_facmod_result <> 'S' THEN
16256                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
16257                   l_failed_constraint.entity_type :=  G_TRIP;
16258                   l_failed_constraint.entity_line_id :=  p_trip_info(j).trip_id;
16259                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
16260                   IF l_validate_facmod_result = 'E' THEN
16261                      l_validate_ex_result := 'E';
16262                   END IF;
16263                END IF;
16264 
16265             END IF;
16266 
16267             IF l_comp_class_tab.EXISTS(G_FACILITY_VEHICLE_NUM) THEN
16268 
16269                validate_constraint(
16270                  p_comp_class_code          =>      G_FACILITY_VEHICLE,
16271                  p_object1_type             =>      'FAC',
16272                  p_object1_val_num          =>      l_trip_incl_stops(k).stop_location_id,
16273                  p_object2_type             =>      'VHT',
16274                  p_object2_val_num          =>      l_vehicle_type,
16275                  x_validate_result          =>      l_validate_facveh_result,
16276                  x_failed_constraint        =>      l_failed_constraint,
16277                  x_return_status            =>      l_return_status);
16278 
16279                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16280                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16281                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16282                   END IF;
16283                END IF;
16284 
16285                IF l_validate_facveh_result <> 'S' THEN
16286                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
16287                   l_failed_constraint.entity_type :=  G_TRIP;
16288                   l_failed_constraint.entity_line_id :=  p_trip_info(j).trip_id;
16289                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
16290                   IF l_validate_facveh_result = 'E' THEN
16291                      l_validate_ex_result := 'E';
16292                   END IF;
16293                END IF;
16294 
16295             END IF;
16296 
16297             <<next_stop>>
16298 
16299             EXIT WHEN k = l_trip_incl_stops.LAST;
16300 
16301 	    l_idx := k ;
16302 	    k	  := l_trip_incl_stops.NEXT(k);
16303 
16304 	    --SBAKSHI(8/24) (S)
16305 	    --Check can be put here,in case the next record is the physical stop,
16306 	    --then move two times, Skip the record over here.
16307 	    --Pseudo code -  IF both locations are specified then
16308             -- TODO Should we use physical_stop_id ?
16309 
16310 	    IF (l_trip_incl_stops(k).trip_id = l_trip_incl_stops(l_idx).trip_id
16311 		     AND
16312 		l_trip_incl_stops(k).stop_location_id=l_trip_incl_stops(l_idx).physical_location_id)
16313 	    THEN
16314 
16315 		--
16316 		--Current record is for the physical location, we need to skip it .
16317 		--In case it is the last record we need to exit,otherwise skip.
16318 		--
16319 
16320 		IF (k = l_trip_incl_stops.LAST) THEN
16321 			EXIT ;
16322 		ELSE
16323 			k:= l_trip_incl_stops.NEXT(k);
16324 		END IF;
16325 
16326 	    END IF;
16327 	    --SBAKSHI(8/24) (E)
16328 
16329 	  END LOOP;
16330 
16331 	END IF;
16332 
16333         IF l_validate_ex_result = 'E' OR l_validate_in_result = 'E' THEN
16334 
16335            x_validate_result := 'F';
16336            x_fail_trips(x_fail_trips.COUNT+1) := p_trip_info(j).trip_id;
16337            l_curr_trip_added := TRUE;
16338            l_validate_in_result := 'S';
16339            l_validate_ex_result := 'S';
16340            --
16341            IF l_debug_on THEN
16342              WSH_DEBUG_SV.logmsg(l_module_name,'Added failed trip because of stops : '|| p_trip_info(j).trip_id);
16343            END IF;
16344            --
16345         END IF;
16346 
16347         --LOOP -- over each dlvy line of this input trip
16348         l := l_trip_dlvy_lines.FIRST;
16349         IF l IS NOT NULL THEN
16350           LOOP
16351 
16352           -- Need to skip an Inbound delivery line
16353           -- if the trip's status is "In Transit" or "Closed"
16354 
16355             --IF p_trip_info(j).STATUS_CODE IN ('IT','CL') AND
16356             IF l_trip_dlvy_lines(l).released_status IN ('C','L') AND
16357                l_trip_dlvy_lines(l).line_direction = 'I' THEN
16358                GOTO line_nextpass;
16359             END IF;
16360 
16361         -- Need to consider Item - Vehicle
16362 
16363             IF l_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) THEN
16364 
16365                check_inclusive_object2(
16366                  p_comp_class_code          =>      G_ITEM_MODE,
16367                  p_entity_type              =>      G_DEL_DETAIL,
16368                  p_entity_id                =>      l_trip_dlvy_lines(l).delivery_detail_id,
16369                  p_object1_type             =>      'ITM',
16370                  p_object1_parent_id        =>      l_trip_dlvy_lines(l).organization_id,
16371                  p_object1_val_num          =>      l_trip_dlvy_lines(l).inventory_item_id,
16372                  p_object2_type             =>      'MOD',
16373                  p_object2_val_char         =>      l_mode,
16374                  x_out_object2_num          =>      l_out_object2_num,
16375                  x_out_object2_char         =>      l_out_object2_char,
16376                  x_validate_result          =>      l_validate_mode_result,
16377                  x_failed_constraint        =>      l_failed_constraints,
16378                  x_return_status            =>      l_return_status);
16379 
16380                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16381                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16382                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16383                   END IF;
16384                END IF;
16385 
16386                IF l_validate_mode_result = 'F' THEN
16387                   l_validate_in_result := 'E';
16388                END IF;
16389 
16390             END IF;
16391 
16392             IF l_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) THEN
16393 
16394                check_inclusive_object2(
16395                  p_comp_class_code          =>      G_ITEM_CARRIER,
16396                  p_entity_type              =>      G_DEL_DETAIL,
16397                  p_entity_id                =>      l_trip_dlvy_lines(l).delivery_detail_id,
16398                  p_object1_type             =>      'ITM',
16399                  p_object1_parent_id        =>      l_trip_dlvy_lines(l).organization_id,
16400                  p_object1_val_num          =>      l_trip_dlvy_lines(l).inventory_item_id,
16401                  p_object2_type             =>      'CAR',
16402                  p_object2_val_num          =>      l_carrier,
16403                  x_out_object2_num          =>      l_out_object2_num,
16404                  x_out_object2_char         =>      l_out_object2_char,
16405                  x_validate_result          =>      l_validate_carrier_result,
16406                  x_failed_constraint        =>      l_failed_constraints,
16407                  x_return_status            =>      l_return_status);
16408 
16409                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16410                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16411                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16412                   END IF;
16413                END IF;
16414 
16415                IF l_validate_carrier_result = 'F' THEN
16416                   l_validate_in_result := 'E';
16417                END IF;
16418 
16419             END IF;
16420 
16421             IF l_comp_class_tab.EXISTS(G_ITEM_VEHICLE_NUM) THEN
16422 
16423                check_inclusive_object2(
16424                  p_comp_class_code          =>      G_ITEM_VEHICLE,
16425                  p_entity_type              =>      G_DEL_DETAIL,
16426                  p_entity_id                =>      l_trip_dlvy_lines(l).delivery_detail_id,
16427                  p_object1_type             =>      'ITM',
16428                  p_object1_parent_id        =>      l_trip_dlvy_lines(l).organization_id,
16429                  p_object1_val_num          =>      l_trip_dlvy_lines(l).inventory_item_id,
16430                  p_object2_type             =>      'VHT',
16431                  p_object2_val_num          =>      l_vehicle_type,
16432                  x_out_object2_num          =>      l_out_object2_num,
16433                  x_out_object2_char         =>      l_out_object2_char,
16434                  x_validate_result          =>      l_validate_vehicle_result,
16435                  x_failed_constraint        =>      l_failed_constraints,
16436                  x_return_status            =>      l_return_status);
16437 
16438                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16439                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16440                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16441                   END IF;
16442                END IF;
16443 
16444                IF l_validate_vehicle_result = 'F' THEN
16445                   l_validate_in_result := 'E';
16446                END IF;
16447 
16448             END IF;
16449 
16450             IF l_validate_in_result = 'E' THEN
16451                EXIT;
16452             END IF;
16453 
16454              -- Validate ITM - CAR  ITM - MOD against the items
16455     	     -- Need to consider Item - Vehicle
16456 
16457             IF l_comp_class_tab.EXISTS(G_ITEM_MODE_NUM) THEN
16458 
16459                validate_constraint(   --  checks only negative constraints
16460                  p_comp_class_code          =>      G_ITEM_MODE,
16461                  p_object1_type             =>      'ITM',
16462                  p_object1_parent_id        =>      l_trip_dlvy_lines(l).organization_id,
16463                  p_object2_type             =>      'MOD',
16464                  p_object1_val_num          =>      l_trip_dlvy_lines(l).inventory_item_id,
16465                  p_object2_val_char         =>      l_mode,
16466                  x_validate_result          =>      l_validate_itmmod_result,
16467                  x_failed_constraint        =>      l_failed_constraint,  -- id
16468                  x_return_status            =>      l_return_status);
16469 
16470                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16471                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16472                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16473                   END IF;
16474                END IF;
16475 
16476                IF l_validate_itmmod_result <> 'S' THEN
16477                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
16478                   l_failed_constraint.entity_type :=  G_DEL_DETAIL;
16479                   l_failed_constraint.entity_line_id :=  l_trip_dlvy_lines(l).delivery_detail_id;
16480                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
16481                   IF l_validate_itmmod_result = 'E' THEN
16482                      l_validate_ex_result := 'E';
16483                   END IF;
16484                END IF;
16485 
16486             END IF;
16487 
16488             IF l_comp_class_tab.EXISTS(G_ITEM_CARRIER_NUM) THEN
16489 
16490                validate_constraint(   --  checks only negative constraints
16491                  p_comp_class_code          =>      G_ITEM_CARRIER,
16492                  p_object1_type             =>      'ITM',
16493                  p_object1_parent_id        =>      l_trip_dlvy_lines(l).organization_id,
16494                  p_object2_type             =>      'CAR',
16495                  p_object1_val_num          =>      l_trip_dlvy_lines(l).inventory_item_id,
16496                  p_object2_val_num          =>      l_carrier,
16497                  x_validate_result          =>      l_validate_itmcar_result,
16498                  x_failed_constraint        =>      l_failed_constraint,  -- id
16499                  x_return_status            =>      l_return_status);
16500 
16501                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16502                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16503                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16504                   END IF;
16505                END IF;
16506 
16507                IF l_validate_itmcar_result <> 'S' THEN
16508                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
16509                   l_failed_constraint.entity_type :=  G_DEL_DETAIL;
16510                   l_failed_constraint.entity_line_id :=  l_trip_dlvy_lines(l).delivery_detail_id;
16511                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
16512                   IF l_validate_itmcar_result = 'E' THEN
16513                      l_validate_ex_result := 'E';
16514                   END IF;
16515                END IF;
16516 
16517             END IF;
16518 
16519             IF l_comp_class_tab.EXISTS(G_ITEM_VEHICLE_NUM) THEN
16520 
16521                validate_constraint(   --  checks only negative constraints
16522                  p_comp_class_code          =>      G_ITEM_VEHICLE,
16523                  p_object1_type             =>      'ITM',
16524                  p_object1_parent_id        =>      l_trip_dlvy_lines(l).organization_id,
16525                  p_object2_type             =>      'VHT',
16526                  p_object1_val_num          =>      l_trip_dlvy_lines(l).inventory_item_id,
16527                  p_object2_val_num          =>      l_vehicle_type,
16528                  x_validate_result          =>      l_validate_itmveh_result,
16529                  x_failed_constraint        =>      l_failed_constraint,  -- id
16530                  x_return_status            =>      l_return_status);
16531 
16532                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16533                   IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16534                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
16535                   END IF;
16536                END IF;
16537 
16538                IF l_validate_itmveh_result <> 'S' THEN
16539                   l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
16540                   l_failed_constraint.entity_type :=  G_DEL_DETAIL;
16541                   l_failed_constraint.entity_line_id :=  l_trip_dlvy_lines(l).delivery_detail_id;
16542                   l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
16543                   IF l_validate_itmveh_result = 'E' THEN
16544                      l_validate_ex_result := 'E';
16545                   END IF;
16546                END IF;
16547 
16548             END IF;
16549 
16550             <<line_nextpass>>
16551 
16552             EXIT WHEN l = l_trip_dlvy_lines.LAST;
16553             l := l_trip_dlvy_lines.NEXT(l);
16554 
16555           END LOOP;
16556         END IF;
16557 
16558         IF l_validate_in_result = 'E' OR l_validate_ex_result = 'E' THEN
16559 
16560            x_validate_result := 'F';
16561            IF NOT l_curr_trip_added THEN
16562              x_fail_trips(x_fail_trips.COUNT+1) := p_trip_info(j).trip_id;
16563              --
16564              IF l_debug_on THEN
16565                WSH_DEBUG_SV.logmsg(l_module_name,'Added failed trip because of items : '|| p_trip_info(j).trip_id);
16566              END IF;
16567              --
16568            END IF;
16569 
16570         END IF;
16571 
16572         EXIT WHEN j = p_trip_info.LAST;
16573         j := p_trip_info.NEXT(j);
16574 
16575       END LOOP;
16576     END IF;
16577 
16578     stack_messages (
16579              p_failed_constraints       => l_failed_constraints,
16580              x_msg_count                => x_msg_count,
16581              x_msg_data                 => x_msg_data,
16582              x_return_status            => l_return_status);
16583 
16584     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16585          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16586             raise FND_API.G_EXC_UNEXPECTED_ERROR;
16587          END IF;
16588     END IF;
16589 
16590     IF x_validate_result = 'F' THEN
16591         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
16592     ELSIF l_failed_constraints.COUNT > 0 THEN
16593         x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
16594     END IF;
16595 
16596     --
16597     IF l_debug_on THEN
16598       WSH_DEBUG_SV.logmsg(l_module_name,'failed trip count : '|| x_fail_trips.COUNT);
16599       WSH_DEBUG_SV.pop(l_module_name);
16600     END IF;
16601     --
16602 
16603 EXCEPTION
16604     WHEN g_get_carrmode_failed THEN
16605       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
16606       --
16607       IF l_debug_on THEN
16608         WSH_DEBUG_SV.pop(l_module_name,' get carrier-mode failed ');
16609       END IF;
16610       --
16611     WHEN g_get_vehicletype_failed THEN
16612       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
16613       --
16614       IF l_debug_on THEN
16615         WSH_DEBUG_SV.pop(l_module_name,' get vehicletype failed ');
16616       END IF;
16617       --
16618     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
16619       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
16620       --
16621       IF l_debug_on THEN
16622         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
16623         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
16624       END IF;
16625       --
16626     WHEN others THEN
16627       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.validate_constraint_trip');
16628       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
16629       --
16630       IF l_debug_on THEN
16631         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
16632         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
16633       END IF;
16634       --
16635 END validate_constraint_trip;
16636 
16637 
16638 --***************************************************************************
16639 --
16640 --========================================================================
16641 -- PROCEDURE : validate_constraint_stop    Called by constraint Wrapper API
16642 --                                         and the Group API.
16643 --
16644 -- PARAMETERS: p_init_msg_list             FND_API.G_TRUE to reset list
16645 --             p_action_code               Predefined action code
16646 --             p_exception_list            Compatibility classes to skip if any
16647 --                                         indexed by class code numbers
16648 --             p_stop_info                 Table of Stop records to process
16649 --             p_parent_trip_info          Table of Parent Trip records
16650 --                                         If not passed, the API will query
16651 --             x_fail_stops                Table of input stops that failed constraint check
16652 --             x_validate_result           Constraint Validation result : S / F
16653 --             x_msg_count                 Number of messages in the list
16654 --             x_msg_data                  Text of messages
16655 --             x_return_status             Return status
16656 -- COMMENT   : This procedure is used to perform for following actions
16657 --             A. Create a new stop ( CTS)
16658 --             B. Update an existing stop (UPS)
16659 --             C. Delete a stop (DTS)
16660 --========================================================================
16661 
16662 --Changes for DUM_LOC
16663 --Modified table p_stop_info in the beginning to get physical locations for dummy locations.
16664 
16665 
16666 PROCEDURE validate_constraint_stop(
16667              p_init_msg_list            IN	         VARCHAR2 DEFAULT fnd_api.g_false,
16668              p_action_code              IN	         VARCHAR2 DEFAULT NULL,
16669              p_exception_list           IN	         WSH_UTIL_CORE.Column_Tab_Type,
16670              p_stop_info                IN               stop_ccinfo_tab_type,
16671              p_parent_trip_info         IN	         trip_ccinfo_tab_type,
16672              x_fail_stops               OUT NOCOPY       WSH_UTIL_CORE.id_tab_type,
16673              x_validate_result          OUT NOCOPY       VARCHAR2,
16674              x_msg_count                OUT NOCOPY       NUMBER,
16675              x_msg_data                 OUT NOCOPY       VARCHAR2,
16676              x_return_status            OUT NOCOPY       VARCHAR2)
16677 IS
16678 
16679     CURSOR c_gettripdetails (l_stop_id IN NUMBER) is
16680     SELECT wt.TRIP_ID, 'Y'as exists_in_database, wt.NAME, wt.PLANNED_FLAG, wt.STATUS_CODE, wt.VEHICLE_ITEM_ID, wt.VEHICLE_NUMBER,
16681     wt.CARRIER_ID, wt.SHIP_METHOD_CODE, wt.VEHICLE_ORGANIZATION_ID, wt.VEHICLE_NUM_PREFIX, wt.SERVICE_LEVEL,
16682     wt.MODE_OF_TRANSPORT
16683     FROM wsh_trips wt, wsh_trip_stops wts
16684     WHERE wts.stop_id = l_stop_id
16685     AND   wts.trip_id=  wt.trip_id;
16686 
16687     CURSOR c_gettripinfo (l_trip_id IN NUMBER) is
16688     SELECT wt.TRIP_ID, 'Y'as exists_in_database, wt.NAME, wt.PLANNED_FLAG, wt.STATUS_CODE, wt.VEHICLE_ITEM_ID, wt.VEHICLE_NUMBER,
16689     wt.CARRIER_ID, wt.SHIP_METHOD_CODE, wt.VEHICLE_ORGANIZATION_ID, wt.VEHICLE_NUM_PREFIX, wt.SERVICE_LEVEL,
16690     wt.MODE_OF_TRANSPORT
16691     FROM wsh_trips wt
16692     WHERE wt.trip_id = l_trip_id;
16693 
16694     CURSOR c_get_dlvy_stops(c_delivery_id IN NUMBER,c_trip_id IN NUMBER) IS
16695     SELECT wts1.stop_sequence_number pickup_stop_seq,
16696            wts2.stop_sequence_number dropoff_stop_seq,
16697            wts1.planned_arrival_date pickup_stop_pa_date,
16698            wts2.planned_arrival_date dropoff_stop_pa_date
16699     FROM   wsh_new_deliveries wnd,
16700            wsh_delivery_legs wdl,
16701            wsh_trip_stops wts1,
16702            wsh_trip_stops wts2
16703     WHERE  wnd.delivery_id = c_delivery_id
16704     AND    wdl.delivery_id = wnd.delivery_id
16705     AND    wdl.pick_up_stop_id = wts1.stop_id
16706     AND    wdl.drop_off_stop_id = wts2.stop_id
16707     AND    wts1.trip_id = c_trip_id;
16708 
16709     z                                   NUMBER := 0;
16710     j                                   NUMBER := 0;
16711     k                                   NUMBER := 0;
16712     l                                   NUMBER := 0;
16713     m                                   NUMBER := 0;
16714     q                                   NUMBER := 0;
16715     l_carrier                           NUMBER := NULL;
16716     l_vehicle_type                      NUMBER := NULL;
16717     l_mode                              VARCHAR2(30) := NULL;
16718     l_service_level                     VARCHAR2(30) := NULL;
16719     l_carrier_service_inout_rec         WSH_CARRIERS_GRP.Carrier_Service_InOut_Rec_Type;
16720     l_trips_cnt                         NUMBER := 0;
16721     l_trip_del_cnt                      NUMBER := 0;
16722     l_trip_detail_cnt                   NUMBER := 0;
16723     l_trip_stop_cnt                     NUMBER := 0;
16724     l_out_object2_num                   NUMBER:=0;
16725     l_out_object2_char                  VARCHAR2(30):=NULL;
16726     l_added_stop                        BOOLEAN := FALSE;
16727     l_return_status                     VARCHAR2(1);
16728     l_comp_class_tab                    WSH_UTIL_CORE.Column_Tab_Type;
16729     l_failed_constraint                 line_constraint_rec_type;
16730     l_failed_constraints                line_constraint_tab_type;
16731     l_failed_constraints_dummy          line_constraint_tab_type;
16732     l_validate_faccar_result            VARCHAR2(1) := 'S';
16733     l_validate_facmod_result            VARCHAR2(1) := 'S';
16734     l_validate_facveh_result            VARCHAR2(1) := 'S';
16735     l_validate_orgfac_result            VARCHAR2(1) := 'S';
16736     l_validate_cusfac_result            VARCHAR2(1) := 'S';
16737     l_validate_supfac_result            VARCHAR2(1) := 'S';
16738     l_validate_supfacin_result          VARCHAR2(1) := 'S';
16739     l_validate_cusfacin_result          VARCHAR2(1) := 'S';
16740     l_validate_itmfac_result            VARCHAR2(1) := 'S';
16741     l_validate_in_result                VARCHAR2(1) := 'S';
16742     l_validate_vehicle_result           VARCHAR2(1) := 'S';
16743     l_validate_carrier_result           VARCHAR2(1) := 'S';
16744     l_validate_mode_result              VARCHAR2(1) := 'S';
16745     l_validate_dlvy_result              VARCHAR2(1) := 'S';
16746     l_validate_dlvb_result              VARCHAR2(1) := 'S';
16747     l_parent_trip_info                  trip_ccinfo_tab_type ;
16748     l_trip_rec                          trip_ccinfo_rec_type;
16749     l_delivery_rec                      delivery_ccinfo_rec_type;
16750     l_detail_rec                        detail_ccinfo_rec_type;
16751     l_stop_rec                          stop_ccinfo_rec_type;
16752     l_trip_assigned_dels                delivery_ccinfo_tab_type;
16753     l_trip_dlvy_lines                   detail_ccinfo_tab_type;
16754     --l_trip_children_stops               stop_ccinfo_tab_type;
16755     l_pickup_stop_seq                   NUMBER     := 0;
16756     l_dropoff_stop_seq                  NUMBER     := 0;
16757     l_pu_pa_date                        DATE;
16758     l_do_pa_date                        DATE;
16759     l_sibling_locations                 WSH_UTIL_CORE.id_tab_type;
16760     l_old_stop_location_id              NUMBER     := NULL;
16761     l_old_stop_seq_num                  NUMBER     := -999;
16762     l_old_stop_pa_date                  DATE;
16763     l_mustuse_loc_id                    NUMBER     := NULL;
16764     l_vehicle_name                      VARCHAR2(2000);
16765     l_vehicle_org_name                  VARCHAR2(240);
16766 
16767     l_direct_shipment                   BOOLEAN := TRUE;
16768     l_num_dlegs                         NUMBER  := 0;
16769 
16770     --#DUM_LOC(S)
16771     l_physical_location_id		NUMBER;
16772     --#DUM_LOC(E)
16773 
16774     --SBAKSHI (8/24)
16775     l_idx				NUMBER;
16776     l_stop_info				stop_ccinfo_tab_type;
16777     --SBAKSHI (8/24)
16778 
16779     l_debug_on                          CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
16780     l_module_name                       CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'validate_constraint_stop';
16781 
16782 BEGIN
16783 
16784     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
16785     x_validate_result := 'S';
16786 
16787     g_itm_mustuse_cache.DELETE;
16788     g_itmloc_mustuse_cache.DELETE;
16789     g_itm_exclusive_cache.DELETE;
16790     g_fac_exclusive_cache.DELETE;
16791 
16792     IF FND_API.to_Boolean( p_init_msg_list ) THEN
16793          FND_MSG_PUB.initialize;
16794     END IF;
16795 
16796     IF l_debug_on THEN
16797        wsh_debug_sv.push(l_module_name);
16798        WSH_DEBUG_SV.logmsg(l_module_name,'p_init_msg_list : '||p_init_msg_list);
16799     END IF;
16800 
16801     refresh_cache(l_return_status);
16802 
16803     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16804          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16805             raise FND_API.G_EXC_UNEXPECTED_ERROR;
16806          END IF;
16807     END IF;
16808 
16809     IF NOT p_exception_list.EXISTS(G_FACILITY_MODE_NUM) THEN
16810       l_comp_class_tab(G_FACILITY_MODE_NUM) := G_FACILITY_MODE;
16811     END IF;
16812     IF NOT p_exception_list.EXISTS(G_FACILITY_CARRIER_NUM) THEN
16813       l_comp_class_tab(G_FACILITY_CARRIER_NUM) := G_FACILITY_CARRIER;
16814     END IF;
16815     IF NOT p_exception_list.EXISTS(G_FACILITY_VEHICLE_NUM) THEN
16816       l_comp_class_tab(G_FACILITY_VEHICLE_NUM) := G_FACILITY_VEHICLE;
16817     END IF;
16818     IF NOT p_exception_list.EXISTS(G_ITEM_FACILITY_NUM) THEN
16819       l_comp_class_tab(G_ITEM_FACILITY_NUM) := G_ITEM_FACILITY;
16820     END IF;
16821     IF NOT p_exception_list.EXISTS(G_SHIPORG_FACILITY_NUM) THEN
16822       l_comp_class_tab(G_SHIPORG_FACILITY_NUM) := G_SHIPORG_FACILITY;
16823     END IF;
16824     IF NOT p_exception_list.EXISTS(G_CUSTOMER_FACILITY_NUM) THEN
16825       l_comp_class_tab(G_CUSTOMER_FACILITY_NUM) := G_CUSTOMER_FACILITY;
16826     END IF;
16827     IF NOT p_exception_list.EXISTS(G_SUPPLIER_FACILITY_NUM) THEN
16828       l_comp_class_tab(G_SUPPLIER_FACILITY_NUM) := G_SUPPLIER_FACILITY;
16829     END IF;
16830 
16831     -- #LOC_DUM(S)
16832     -- Replacing dummy locations by physical locations.
16833     -- #LOC_DUM(E)
16834 
16835     -- AGDUMMY
16836     -- Rather use nvl(p_stop_info(itr).physical_location_id,p_stop_info(itr).stop_location_id) everywhere
16837     -- We do not want to loose p_stop_info(itr).stop_location_id
16838 
16839     -- AGDUMMY
16840     -- Let's create a local l_stop_info
16841     -- which will store the sorted (by planned_arrival_date) p_stop_info
16842     -- This is to skip the check for the physical stop if already a dummy has been checked
16843     -- when they both exist in the same trip
16844 
16845     -- When the input stop table contains a dummy stop, but not  the corresponding physical stop
16846     -- dummy stop will still be checked
16847     -- For the reverse case, there is no way to figure out this stop is a physical stop and hence
16848     -- validation will be performed for it
16849 
16850 
16851     -- AGDUMMY TODO
16852     -- Sort the table outside the LOOP
16853 
16854 	--SBAKSHI - Sorting the p_stop_info table.
16855       sort_stop_table_asc(
16856 	p_stop_table	  => p_stop_info,
16857 	x_sort_stop_table => l_stop_info,
16858 	x_return_status   => l_return_status);
16859 
16860     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
16861 	  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
16862 	    raise FND_API.G_EXC_UNEXPECTED_ERROR;
16863 	  END IF;
16864     END IF;
16865 
16866     IF p_parent_trip_info.COUNT = 0 THEN
16867 
16868      --Replacing p_stop_info by l_stop_info
16869      -- j := p_stop_info.FIRST;
16870      j := l_stop_info.FIRST;
16871 
16872      IF j IS NOT NULL THEN
16873       LOOP
16874          IF l_stop_info(j).stop_id IS NOT NULL AND p_action_code <> G_CRT_TRIP_STOP THEN
16875           OPEN c_gettripdetails(l_stop_info(j).stop_id);
16876           LOOP
16877                FETCH c_gettripdetails INTO l_trip_rec;
16878                EXIT WHEN c_gettripdetails%NOTFOUND;
16879                l_trips_cnt := l_trips_cnt + 1;
16880                l_parent_trip_info(l_trips_cnt) := l_trip_rec;
16881           END LOOP;
16882           CLOSE c_gettripdetails;
16883          ELSIF l_stop_info(j).trip_id IS NOT NULL THEN
16884           OPEN c_gettripinfo(l_stop_info(j).trip_id);
16885           LOOP
16886                FETCH c_gettripinfo INTO l_trip_rec;
16887                EXIT WHEN c_gettripinfo%NOTFOUND;
16888                l_trips_cnt := l_trips_cnt + 1;
16889                l_parent_trip_info(l_trips_cnt) := l_trip_rec;
16890           END LOOP;
16891           CLOSE c_gettripinfo;
16892          ELSE
16893           IF l_debug_on THEN
16894                WSH_DEBUG_SV.logmsg(l_module_name,'Input stop index - '||j||' has null stop_id and trip_id');
16895           END IF;
16896          END IF;
16897          EXIT WHEN j = l_stop_info.LAST;
16898          j := l_stop_info.NEXT(j);
16899       END LOOP;
16900      END IF;
16901     ELSIF p_parent_trip_info.COUNT <> 0 THEN
16902 
16903         l := p_parent_trip_info.FIRST;
16904         LOOP
16905            l_parent_trip_info(l) := p_parent_trip_info(l);
16906            EXIT WHEN l = p_parent_trip_info.LAST;
16907            l := p_parent_trip_info.NEXT(l);
16908         END LOOP;
16909 
16910     END IF;
16911 
16912 
16913     IF l_debug_on THEN
16914         WSH_DEBUG_SV.logmsg(l_module_name,'Input stop count : '||l_stop_info.COUNT);
16915         WSH_DEBUG_SV.logmsg(l_module_name,'parent trip count : '||p_parent_trip_info.COUNT||' local trip count : '||l_parent_trip_info.COUNT);
16916     END IF;
16917 
16918     -- Only for action code = UPS
16919     -- Also create CTS, DTS
16920     -- Can update stop's location , planned arrival date
16921     -- Can't update stop location if any delivery is present
16922 
16923     --LOOP  -- Over input stops
16924     j := l_stop_info.FIRST;
16925     IF j IS NOT NULL THEN
16926 
16927      LOOP
16928 
16929       l_added_stop := FALSE;
16930       l_validate_faccar_result   := 'S';
16931       l_validate_facveh_result   := 'S';
16932       l_validate_facmod_result   := 'S';
16933       l_validate_orgfac_result   := 'S';
16934       l_validate_cusfac_result   := 'S';
16935       l_validate_supfac_result   := 'S';
16936       l_validate_cusfacin_result := 'S';
16937       l_validate_supfacin_result := 'S';
16938       l_validate_itmfac_result   := 'S';
16939       l_validate_in_result       := 'S';
16940       l_validate_carrier_result  := 'S';
16941       l_validate_vehicle_result  := 'S';
16942       l_validate_mode_result     := 'S';
16943       l_validate_dlvy_result     := 'S';
16944       l_validate_dlvb_result     := 'S';
16945       l_old_stop_pa_date         := NULL;
16946 
16947       IF l_debug_on THEN
16948    	 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)||
16949       ' Sequence : '||l_stop_info(j).stop_sequence_number||' trip id : '||l_stop_info(j).trip_id);
16950  	 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 : '||
16951          to_char(l_stop_info(j).planned_departure_date,'DD-MON-YYYY HH24:MI:SS'));
16952       END IF;
16953 
16954       -- AGDUMMY
16955       -- Skip this stop if it is the physical stop corresponding to
16956       -- an already processed dummy stop in the l_stop_info table
16957       -- TODO skip not done
16958 
16959       -- Fetch old data for the current stop
16960       -- if it is being updated
16961       -- this information will be required for inclusive constraint check
16962       -- related to stop sequence number update
16963 
16964       l_mustuse_loc_id := nvl(l_stop_info(j).physical_location_id,l_stop_info(j).stop_location_id);
16965 
16966       IF p_action_code = G_UPDATE_STOP THEN
16967          -- Changes made in cursor c_get_stop_location.
16968 	 -- To ensure dummy locations are replaced by physical locations.
16969 
16970 	 OPEN  c_get_stop_location(l_stop_info(j).stop_id);
16971          FETCH c_get_stop_location INTO l_old_stop_location_id, l_old_stop_seq_num,l_old_stop_pa_date;
16972 	 CLOSE c_get_stop_location;
16973 
16974 	 IF l_debug_on THEN
16975             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'));
16976          END IF;
16977 
16978          l_mustuse_loc_id := l_old_stop_location_id;
16979 
16980       END IF;
16981 
16982       IF p_action_code <> G_DELETE_STOP THEN
16983 
16984        --LOOP  -- Over parent trips
16985        k := l_parent_trip_info.FIRST;
16986        IF k IS NOT NULL THEN
16987         LOOP
16988 
16989            IF l_debug_on THEN
16990              WSH_DEBUG_SV.logmsg(l_module_name,'For stop : '||l_stop_info(j).stop_id);
16991              WSH_DEBUG_SV.logmsg(l_module_name,'Stops trip : '||l_stop_info(j).trip_id);
16992              WSH_DEBUG_SV.logmsg(l_module_name,'Current Trip : '||l_parent_trip_info(k).trip_id);
16993            END IF;
16994 
16995            IF l_stop_info(j).trip_id <> l_parent_trip_info(k).trip_id THEN
16996                GOTO next_trip;
16997            END IF;
16998 
16999            l_carrier                   := NULL;
17000            l_mode                      := NULL;
17001            l_service_level             := NULL;
17002            l_vehicle_type              := NULL;
17003 
17004            IF (l_parent_trip_info(k).carrier_id IS NULL OR l_parent_trip_info(k).mode_of_transport IS NULL) AND
17005               (l_parent_trip_info(k).ship_method_code IS NOT NULL) THEN
17006 
17007               l_carrier_service_inout_rec.ship_method_code := l_parent_trip_info(k).ship_method_code;
17008 
17009 	      WSH_CARRIERS_GRP.get_carrier_service_mode(
17010                     p_carrier_service_inout_rec =>  l_carrier_service_inout_rec,
17011                     x_return_status		=>  l_return_status);
17012 
17013               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17014                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17015                   IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
17016                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
17017                   END IF;
17018                   raise g_get_carrmode_failed;
17019                  END IF;
17020               END IF;
17021 
17022 	      l_carrier := l_carrier_service_inout_rec.carrier_id;
17023               l_mode    := l_carrier_service_inout_rec.mode_of_transport;
17024 
17025            END IF; -- l_parent_trip_info(k).carrier_id IS NULL OR ..
17026 
17027            -- If carrier_id or mode is passed in, then those get preference for validation
17028            -- If they are not, they are derived from ship method if that is passed
17029 
17030            IF l_parent_trip_info(k).carrier_id IS NOT NULL THEN
17031               l_carrier := l_parent_trip_info(k).carrier_id;
17032            END IF;
17033 
17034 	   IF l_parent_trip_info(k).mode_of_transport IS NOT NULL THEN
17035               l_mode := l_parent_trip_info(k).mode_of_transport;
17036            END IF;
17037 
17038            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
17039 
17040               WSH_FTE_INTEGRATION.get_vehicle_type(
17041                     p_vehicle_item_id     =>  l_parent_trip_info(k).vehicle_item_id,
17042                     p_vehicle_org_id      =>  l_parent_trip_info(k).vehicle_organization_id,
17043                     x_vehicle_type_id     =>  l_vehicle_type,
17044                     x_return_status       =>  l_return_status);
17045 
17046               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17047                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17048                  IF l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
17049                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
17050                  END IF;
17051                l_vehicle_name := WSH_UTIL_CORE.get_item_name (p_item_id => l_parent_trip_info(k).VEHICLE_ITEM_ID,
17052                                                            p_organization_id => l_parent_trip_info(k).VEHICLE_ORGANIZATION_ID);
17053                l_vehicle_org_name := WSH_UTIL_CORE.get_org_name (p_organization_id => l_parent_trip_info(k).VEHICLE_ORGANIZATION_ID);
17054                FND_MESSAGE.SET_NAME('WSH','WSH_VEHICLE_TYPE_UNDEFINED');
17055                FND_MESSAGE.SET_TOKEN('ITEM',l_vehicle_name);
17056                FND_MESSAGE.SET_TOKEN('ORGANIZATION',l_vehicle_org_name);
17057                FND_MSG_PUB.ADD;
17058                 END IF;
17059               END IF;
17060 
17061            END IF; -- l_parent_trip_info(k).VEHICLE_ITEM_ID IS NOT NULL AND ..
17062 
17063          -- Need to consider Facility - Vehicle
17064 
17065            IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) AND
17066                l_mode IS NOT NULL THEN
17067 
17068               check_inclusive_object2(
17069                   p_comp_class_code          =>      G_FACILITY_MODE,
17070                   p_entity_type              =>      G_TRIP,
17071                   p_entity_id                =>      l_parent_trip_info(k).trip_id,
17072                   p_object1_type             =>      'FAC',
17073                   p_object1_val_num          =>      nvl(l_stop_info(j).physical_location_id,l_stop_info(j).stop_location_id),
17074 		  p_object2_type             =>      'MOD',
17075                   p_object2_val_char         =>      l_mode,
17076                   x_out_object2_num          =>      l_out_object2_num,
17077                   x_out_object2_char         =>      l_out_object2_char,
17078                   x_validate_result          =>      l_validate_mode_result,
17079                   x_failed_constraint        =>      l_failed_constraints,
17080                   x_return_status            =>      l_return_status);
17081 
17082               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17083                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17084                      raise FND_API.G_EXC_UNEXPECTED_ERROR;
17085                  END IF;
17086               END IF;
17087 
17088               IF l_validate_mode_result = 'F' THEN
17089                    l_validate_in_result := 'F';
17090               END IF;
17091 
17092            END IF;
17093 
17094            IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) AND
17095                l_carrier IS NOT NULL THEN
17096 
17097               check_inclusive_object2(
17098                   p_comp_class_code          =>     G_FACILITY_CARRIER,
17099                   p_entity_type              =>     G_TRIP,
17100                   p_entity_id                =>     l_parent_trip_info(k).trip_id,
17101                   p_object1_type             =>     'FAC',
17102                   p_object1_val_num          =>      nvl(l_stop_info(j).physical_location_id,l_stop_info(j).stop_location_id),
17103                   p_object2_type             =>     'CAR',
17104                   p_object2_val_num          =>     l_carrier,
17105                   x_out_object2_num          =>     l_out_object2_num,
17106                   x_out_object2_char         =>     l_out_object2_char,
17107                   x_validate_result          =>     l_validate_carrier_result,
17108                   x_failed_constraint        =>     l_failed_constraints,
17109                   x_return_status            =>     l_return_status);
17110 
17111               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17112                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17113                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
17114                  END IF;
17115               END IF;
17116 
17117               IF l_validate_carrier_result = 'F' THEN
17118                 l_validate_in_result := 'F';
17119               END IF;
17120 
17121            END IF;
17122 
17123            IF l_comp_class_tab.EXISTS(G_FACILITY_VEHICLE_NUM) AND
17124                l_vehicle_type IS NOT NULL THEN
17125 
17126               check_inclusive_object2(
17127                   p_comp_class_code          =>      G_FACILITY_VEHICLE,
17128                   p_entity_type              =>      G_TRIP,
17129                   p_entity_id                =>      l_parent_trip_info(k).trip_id,
17130                   p_object1_type             =>      'FAC',
17131                   p_object1_val_num          =>      nvl(l_stop_info(j).physical_location_id,l_stop_info(j).stop_location_id),
17132                   p_object2_type             =>      'VHT',
17133                   p_object2_val_num          =>      l_vehicle_type,
17134                   x_out_object2_num          =>      l_out_object2_num,
17135                   x_out_object2_char         =>      l_out_object2_char,
17136                   x_validate_result          =>      l_validate_vehicle_result,
17137                   x_failed_constraint        =>      l_failed_constraints,
17138                   x_return_status            =>      l_return_status);
17139 
17140               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17141                  IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17142                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
17143                  END IF;
17144               END IF;
17145 
17146               IF l_validate_vehicle_result = 'F' THEN
17147                  l_validate_in_result := 'F';
17148               END IF;
17149 
17150            END IF;
17151 
17152            IF l_validate_in_result = 'F' THEN
17153                 EXIT;
17154            END IF;
17155 
17156 
17157            -- Need to consider Facility - Vehicle
17158            -- Validate FAC - CAR  FAC - MOD, FAC - VEH for the stop locations
17159            -- against parent trip's carrier, mode, vehicle
17160 
17161            IF l_comp_class_tab.EXISTS(G_FACILITY_CARRIER_NUM) AND
17162                l_carrier IS NOT NULL THEN
17163 
17164               validate_constraint(
17165                   p_comp_class_code          =>      G_FACILITY_CARRIER,
17166                   p_object1_type             =>      'FAC',
17167 		          p_object1_val_num          =>      nvl(l_stop_info(j).physical_location_id,l_stop_info(j).stop_location_id),
17168                   p_object2_type             =>      'CAR',
17169                   p_object2_val_num          =>      l_carrier,
17170                   x_validate_result          =>      l_validate_faccar_result,
17171                   x_failed_constraint        =>      l_failed_constraint,
17172                   x_return_status            =>      l_return_status);
17173 
17174               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17175                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17176                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
17177                END IF;
17178               END IF;
17179 
17180               IF l_validate_faccar_result <> 'S' THEN
17181                    l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
17182                    l_failed_constraint.entity_type :=  G_TRIP;
17183                    l_failed_constraint.entity_line_id :=  l_parent_trip_info(k).trip_id;
17184                    l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
17185               END IF;
17186 
17187            END IF;
17188 
17189            IF l_comp_class_tab.EXISTS(G_FACILITY_MODE_NUM) AND
17190                l_mode IS NOT NULL THEN
17191 
17192               validate_constraint(
17193                   p_comp_class_code          =>      G_FACILITY_MODE,
17194                   p_object1_type             =>      'FAC',
17195                   p_object1_val_num          =>      nvl(l_stop_info(j).physical_location_id,l_stop_info(j).stop_location_id),
17196                   p_object2_type             =>      'MOD',
17197                   p_object2_val_char         =>      l_mode,
17198                   x_validate_result          =>      l_validate_facmod_result,
17199                   x_failed_constraint        =>      l_failed_constraint,
17200                   x_return_status            =>      l_return_status);
17201 
17202               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17203                IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17204                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
17205                END IF;
17206               END IF;
17207 
17208               IF l_validate_facmod_result <> 'S' THEN
17209                    l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
17210                    l_failed_constraint.entity_type :=  G_TRIP;
17211                    l_failed_constraint.entity_line_id :=  l_parent_trip_info(k).trip_id;
17212                    l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
17213               END IF;
17214 
17215            END IF;
17216 
17217            IF l_comp_class_tab.EXISTS(G_FACILITY_VEHICLE_NUM) AND
17218                l_vehicle_type IS NOT NULL THEN
17219                --l_parent_trip_info(k).carrier_id IS NOT NULL THEN
17220 
17221               validate_constraint(
17222                   p_comp_class_code          =>      G_FACILITY_VEHICLE,
17223                   p_object1_type             =>      'FAC',
17224                   p_object1_val_num          =>      nvl(l_stop_info(j).physical_location_id,l_stop_info(j).stop_location_id),
17225                   p_object2_type             =>      'VHT',
17226                   p_object2_val_num          =>      l_vehicle_type,
17227                   x_validate_result          =>      l_validate_facveh_result,
17228                   x_failed_constraint        =>      l_failed_constraint,
17229                   x_return_status            =>      l_return_status);
17230 
17231               IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17232                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17233                  raise FND_API.G_EXC_UNEXPECTED_ERROR;
17234                 END IF;
17235               END IF;
17236 
17237               IF l_validate_facveh_result <> 'S' THEN
17238                    l_failed_constraint.line_constraint_index := l_failed_constraints.COUNT+1;
17239                    l_failed_constraint.entity_type :=  G_TRIP;
17240                    l_failed_constraint.entity_line_id :=  l_parent_trip_info(k).trip_id;
17241                    l_failed_constraints(l_failed_constraints.COUNT+1) := l_failed_constraint;
17242               END IF;
17243 
17244            END IF;
17245 
17246            IF l_validate_faccar_result = 'E' OR l_validate_facmod_result = 'E'  OR
17247               l_validate_facveh_result = 'E' THEN
17248 
17249               -- One stop has only one parent trip
17250               EXIT;
17251 
17252            END IF;
17253 
17254            -- What about manual deletion of a stop ?
17255            -- If the current input stop is the only 'must use' for org/cus/itm of dlvy/dlvb
17256            -- in parent trip, then prevent deletion;
17257            -- call modified validate_constraint with p_constraint_type = 'I'
17258            -- Returns 'S'/'W'/'E' between combinations sent to it
17259            -- if error (this location is must use), call
17260            --             check_inclusive_facilities for all other non pick/drop stops in this trip
17261            --             if success, proceed with deletion for the input stop
17262            --             else, prevent deletion of the input stop
17263            -- else, proceed with deletion for the input stop
17264            -- otherwise go ahead
17265               null;
17266 
17267            <<next_trip>>
17268 
17269            EXIT WHEN k = l_parent_trip_info.LAST;
17270            k := l_parent_trip_info.NEXT(k);
17271 
17272 	  END LOOP;
17273         END IF;
17274 
17275       END IF; -- p_action_code <> G_DELETE_STOP
17276 
17277 
17278       IF l_validate_carrier_result = 'F' OR l_validate_mode_result = 'F' OR
17279          l_validate_vehicle_result = 'F' OR
17280          l_validate_faccar_result = 'E' OR l_validate_facmod_result = 'E' OR
17281          l_validate_facveh_result = 'E'
17282 
17283       THEN
17284 
17285          x_validate_result := 'F';
17286          x_fail_stops(x_fail_stops.COUNT+1) := l_stop_info(j).stop_id;
17287          --
17288          IF l_debug_on THEN
17289             WSH_DEBUG_SV.logmsg(l_module_name,'Added failed stop : '|| l_stop_info(j).stop_id);
17290          END IF;
17291          --
17292 
17293       END IF;
17294 
17295       EXIT WHEN j = l_stop_info.LAST;
17296 
17297       l_idx := j;
17298       j     := l_stop_info.NEXT(j);
17299 
17300       --SBAKSHI(8/24) (S)
17301       --Check can be put here,in case the next record is the physical stop,
17302       --then move two times, Skip the record over here.
17303       -- TODO Should we use physical_stop_id ?
17304 
17305       IF (l_stop_info(j).trip_id = l_stop_info(l_idx).trip_id
17306 		 AND
17307 	  l_stop_info(j).stop_location_id=l_stop_info(l_idx).physical_location_id)
17308       THEN
17309 	--
17310 	--Current record is for the physical location, we need to advance further.
17311 	--In case we are at the last trip we need to exit,otherwise skip the record.
17312 	--
17313 
17314 	   IF (j = l_stop_info.LAST) THEN
17315 	         EXIT ;
17316 	   ELSE
17317 	        j:= l_stop_info.NEXT(j);
17318 	   END IF;
17319 
17320        END IF;
17321        --SBAKSHI(8/24) (E)
17322 
17323      END LOOP;
17324 
17325     END IF;
17326 
17327     stack_messages (
17328              p_failed_constraints       => l_failed_constraints,
17329              x_msg_count                => x_msg_count,
17330              x_msg_data                 => x_msg_data,
17331              x_return_status            => l_return_status);
17332 
17333     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17334          IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17335             raise FND_API.G_EXC_UNEXPECTED_ERROR;
17336          END IF;
17337     END IF;
17338 
17339     IF x_validate_result = 'F' THEN
17340         x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
17341     ELSIF
17342      l_failed_constraints.COUNT > 0 THEN
17343 
17344         x_return_status := WSH_UTIL_CORE.G_RET_STS_WARNING;
17345     END IF;
17346 
17347     --
17348     IF l_debug_on THEN
17349       WSH_DEBUG_SV.logmsg(l_module_name,'failed stop count : '|| x_fail_stops.COUNT);
17350       WSH_DEBUG_SV.pop(l_module_name);
17351     END IF;
17352     --
17353 
17354 EXCEPTION
17355     WHEN g_get_carrmode_failed THEN
17356       x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
17357       --
17358       IF l_debug_on THEN
17359         WSH_DEBUG_SV.pop(l_module_name,' get carrier-mode failed ');
17360       END IF;
17361       --
17362     WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
17363       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
17364       --
17365       IF l_debug_on THEN
17366         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
17367         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
17368       END IF;
17369       --
17370     WHEN others THEN
17371       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.validate_constraint_stop');
17372       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR;
17373       --
17374       IF l_debug_on THEN
17375         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
17376         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
17377       END IF;
17378       --
17379 END validate_constraint_stop;
17380 
17381 --***************************************************************************--
17382 --========================================================================
17383 -- PROCEDURE : validate_exclusive_constraints   PRIVATE
17384 --
17385 -- PARAMETERS: p_delivery_rec                   Input delivery record
17386 --             p_rule_deconsol_location         input location id to be validated
17387 --                                              against exclusive constraints
17388 --             x_validate_result                Constraint validation result
17389 --             x_return_status                  Return status
17390 -- COMMENT   : This procedure is used to perform for following actions
17391 --             Takes input delivery record and deconsol location id
17392 --             Checks if the input location it can be used as deconsol location
17393 --             Validate ALL exclusive discretionary routing point constraints
17394 --              1. Customer - Facility
17395 --              2. Region / Zone - Facility
17396 --              3. Organization - Facility
17397 --              4. Item - Facility
17398 --========================================================================
17399 
17400 PROCEDURE validate_exclusive_constraints(p_delivery_rec IN WSH_FTE_CONSTRAINT_FRAMEWORK.delivery_ccinfo_rec_type,
17401                                         p_rule_deconsol_location IN NUMBER,
17402                                         x_validate_result   OUT NOCOPY VARCHAR2,
17403                                         x_return_status     OUT NOCOPY VARCHAR2
17404 )
17405 
17406 IS
17407 l_validate_result           VARCHAR2(1) := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
17408 l_return_status             VARCHAR2(1) := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
17409 l_failed_constraint         WSH_FTE_CONSTRAINT_FRAMEWORK.line_constraint_rec_type;
17410 l_details_info              WSH_FTE_CONSTRAINT_FRAMEWORK.detail_ccinfo_tab_type;
17411 i_det                       NUMBER;
17412 l_module_name               CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'validate_exclusive_constraints';
17413 l_debug_on                  CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
17414 l_location_id               NUMBER;
17415 
17416 CURSOR c_get_details(c_delivery_id IN NUMBER) IS
17417 SELECT wdd.DELIVERY_DETAIL_ID
17418   , wda.DELIVERY_ID
17419   , 'Y'
17420   , wdd.CUSTOMER_ID
17421   , wdd.INVENTORY_ITEM_ID
17422   , wdd.SHIP_FROM_LOCATION_ID
17423   , wdd.ORGANIZATION_ID
17424   , wdd.SHIP_TO_LOCATION_ID
17425   , wdd.INTMED_SHIP_TO_LOCATION_ID
17426   , wdd.RELEASED_STATUS
17427   , wdd.CONTAINER_FLAG
17428   , wdd.DATE_REQUESTED
17429   , wdd.DATE_SCHEDULED
17430   , wdd.SHIP_METHOD_CODE
17431   , wdd.CARRIER_ID
17432   , wdd.PARTY_ID
17433   , nvl(wdd.LINE_DIRECTION,'O')
17434   , nvl(wdd.SHIPPING_CONTROL,'BUYER')
17435   , NULL
17436 FROM wsh_delivery_details wdd,
17437      wsh_delivery_assignments_v wda
17438 WHERE wdd.delivery_detail_id = wda.delivery_detail_id
17439 AND   nvl(wdd.shipping_control,'BUYER') <> 'SUPPLIER'
17440 AND   wda.delivery_id = c_delivery_id;
17441 
17442 BEGIN
17443 
17444     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
17445     x_validate_result := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
17446 
17447     IF l_debug_on THEN
17448       wsh_debug_sv.push (l_module_name);
17449     END IF;
17450 
17451     IF p_delivery_rec.ultimate_dropoff_location_id IS NOT NULL THEN
17452     --{
17453 
17454         IF l_debug_on THEN
17455             wsh_debug_sv.logmsg (l_module_name, 'p_delivery_rec.ultimate_dropoff_location_id: ' || p_delivery_rec.ultimate_dropoff_location_id);
17456             wsh_debug_sv.logmsg (l_module_name, 'p_rule_deconsol_location: '||p_rule_deconsol_location);
17457         END IF;
17458 
17459         validate_constraint(   --  checks only negative constraints
17460              p_comp_class_code          =>      WSH_FTE_CONSTRAINT_FRAMEWORK.G_CUSTOMER_FACILITY,
17461              p_object1_type             =>      'FAC',
17462              p_object2_type             =>      'FAC',
17463              p_object1_val_num          =>      p_delivery_rec.ultimate_dropoff_location_id,
17464              p_object1_physical_id      =>      p_delivery_rec.physical_dropoff_location_id,
17465              p_object2_val_num          =>      p_rule_deconsol_location,
17466              x_validate_result          =>      l_validate_result,
17467              x_failed_constraint        =>      l_failed_constraint,
17468              x_return_status            =>      l_return_status);
17469 
17470         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17471             raise FND_API.G_EXC_UNEXPECTED_ERROR;
17472         END IF;
17473 
17474 
17475         IF l_debug_on THEN
17476             wsh_debug_sv.logmsg (l_module_name, 'Customer FAC-FAC l_validate_result: '||l_validate_result);
17477         END IF;
17478 
17479         IF l_validate_result = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
17480             x_return_status := l_return_status;
17481             x_validate_result := l_validate_result;
17482 
17483             IF l_debug_on THEN
17484                 wsh_debug_sv.push(l_module_name);
17485                 wsh_debug_sv.log (l_module_name,'constraint id violated : ',to_char(l_failed_constraint.constraint_id));
17486                 wsh_debug_sv.log (l_module_name,'entity_type : ',to_char(l_failed_constraint.entity_type));
17487                 wsh_debug_sv.log (l_module_name,'constraint_class_code : ',to_char(l_failed_constraint.constraint_class_code));
17488                 wsh_debug_sv.log (l_module_name,'violation_type : ',to_char(l_failed_constraint.violation_type));
17489                 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');
17490             END IF;
17491             IF l_debug_on THEN
17492                 wsh_debug_sv.pop (l_module_name);
17493             END IF;
17494             return;
17495         END IF;
17496 
17497     --}
17498     END IF; -- p_delivery_rec.ULTIMATE_DROPOFF_LOCATION_ID IS NOT NULL
17499 
17500     IF p_delivery_rec.customer_id IS NOT NULL THEN
17501     --{
17502         IF l_debug_on THEN
17503           wsh_debug_sv.logmsg (l_module_name, 'p_delivery_rec.customer_id: ' || p_delivery_rec.customer_id);
17504           wsh_debug_sv.logmsg (l_module_name, 'p_rule_deconsol_location: '||p_rule_deconsol_location);
17505         END IF;
17506 
17507         validate_constraint(   --  checks only negative constraints
17508          p_comp_class_code          =>      WSH_FTE_CONSTRAINT_FRAMEWORK.G_CUSTOMER_FACILITY,
17509          p_object1_type             =>      'CUS',
17510          p_object2_type             =>      'FAC',
17511          p_object1_val_num          =>      p_delivery_rec.customer_id,
17512          p_object2_val_num          =>      p_rule_deconsol_location,
17513          x_validate_result          =>      l_validate_result,
17514          x_failed_constraint        =>      l_failed_constraint,
17515          x_return_status            =>      l_return_status);
17516 
17517         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17518             raise FND_API.G_EXC_UNEXPECTED_ERROR;
17519         END IF;
17520 
17521         IF l_debug_on THEN
17522           wsh_debug_sv.logmsg (l_module_name, 'CUS-FAC l_validate_result: '||l_validate_result);
17523         END IF;
17524 
17525         IF l_validate_result = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
17526             x_return_status := l_return_status;
17527             x_validate_result := l_validate_result;
17528             IF l_debug_on THEN
17529                 wsh_debug_sv.push(l_module_name);
17530                 wsh_debug_sv.log (l_module_name,'constraint id violated : ',to_char(l_failed_constraint.constraint_id));
17531                 wsh_debug_sv.log (l_module_name,'entity_type : ',to_char(l_failed_constraint.entity_type));
17532                 wsh_debug_sv.log (l_module_name,'constraint_class_code : ',to_char(l_failed_constraint.constraint_class_code));
17533                 wsh_debug_sv.log (l_module_name,'violation_type : ',to_char(l_failed_constraint.violation_type));
17534                 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');
17535             END IF;
17536             IF l_debug_on THEN
17537                 wsh_debug_sv.pop (l_module_name);
17538             END IF;
17539             return;
17540         END IF;
17541     --}
17542     END IF; -- p_delivery_rec.customer_id IS NOT NULL
17543 
17544 
17545 
17546     -- Validate Region/Zone - Facility Constraints for Ultimate drop off location
17547 
17548    /*validate_region_constraint(
17549          p_location_id       => p_delivery_rec.ultimate_dropoff_location_id,
17550          p_object2_val_num   => p_rule_deconsol_location,
17551          x_validate_result   => l_validate_result,
17552          x_failed_constraint => l_failed_constraint,
17553          x_return_status     => l_return_status);
17554 
17555     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17556        raise FND_API.G_EXC_UNEXPECTED_ERROR;
17557     END IF;
17558 
17559     IF l_debug_on THEN
17560         wsh_debug_sv.logmsg (l_module_name, 'Region/Zone - Facility constraint for ship to location l_validate_result: '||l_validate_result);
17561     END IF;
17562 
17563     IF l_validate_result = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
17564         x_return_status := l_return_status;
17565         x_validate_result := l_validate_result;
17566         IF l_debug_on THEN
17567             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');
17568         END IF;
17569         return;
17570     END IF;*/
17571 
17572     -- Validate Ship From Organization-Facility Constraints
17573 
17574     IF p_delivery_rec.organization_id IS NOT NULL THEN
17575 
17576         IF l_debug_on THEN
17577           wsh_debug_sv.logmsg (l_module_name, 'organization_id: ' || p_delivery_rec.organization_id);
17578           wsh_debug_sv.logmsg (l_module_name, 'p_rule_deconsol_location: '||p_rule_deconsol_location);
17579         END IF;
17580 
17581         validate_constraint(
17582                  p_comp_class_code          =>      WSH_FTE_CONSTRAINT_FRAMEWORK.G_SHIPORG_FACILITY,
17583                  p_object2_type             =>      'FAC',
17584                  p_object1_val_num          =>      p_delivery_rec.organization_id,
17585                  p_object2_val_num          =>      p_rule_deconsol_location,
17586                  x_validate_result          =>      l_validate_result,
17587                  x_failed_constraint        =>      l_failed_constraint,
17588                  x_return_status            =>      l_return_status);
17589 
17590         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17591             raise FND_API.G_EXC_UNEXPECTED_ERROR;
17592         END IF;
17593 
17594         IF l_debug_on THEN
17595             wsh_debug_sv.logmsg (l_module_name, 'ORG - FAC l_validate_result: '||l_validate_result);
17596         END IF;
17597 
17598         IF l_validate_result = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
17599             x_return_status := l_return_status;
17600             x_validate_result := l_validate_result;
17601             IF l_debug_on THEN
17602                 wsh_debug_sv.push(l_module_name);
17603                 wsh_debug_sv.log (l_module_name,'constraint id violated : ',to_char(l_failed_constraint.constraint_id));
17604                 wsh_debug_sv.log (l_module_name,'entity_type : ',to_char(l_failed_constraint.entity_type));
17605                 wsh_debug_sv.log (l_module_name,'constraint_class_code : ',to_char(l_failed_constraint.constraint_class_code));
17606                 wsh_debug_sv.log (l_module_name,'violation_type : ',to_char(l_failed_constraint.violation_type));
17607                 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');
17608             END IF;
17609             IF l_debug_on THEN
17610                 wsh_debug_sv.pop (l_module_name);
17611             END IF;
17612             return;
17613         END IF;
17614     END IF;
17615 
17616     -- Validate Region/Zone - Facility Constraints for Ship From Organization
17617 
17618     IF (p_delivery_rec.organization_id IS NOT NULL) THEN
17619 
17620         get_loc_for_org(
17621           p_org_id	       => p_delivery_rec.organization_id,
17622           x_location_id    => l_location_id,
17623           x_return_status  => x_return_status);
17624 
17625         IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17626             IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17627                raise FND_API.G_EXC_UNEXPECTED_ERROR;
17628             END IF;
17629         END IF;
17630 
17631       /*  validate_region_constraint(
17632              p_location_id       => p_delivery_rec.ultimate_dropoff_location_id,
17633              p_object2_val_num   => p_rule_deconsol_location,
17634              x_validate_result   => l_validate_result,
17635              x_failed_constraint => l_failed_constraint,
17636              x_return_status     => l_return_status);
17637 
17638         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17639             raise FND_API.G_EXC_UNEXPECTED_ERROR;
17640         END IF;
17641 
17642         IF l_debug_on THEN
17643             wsh_debug_sv.logmsg (l_module_name, 'Region/Zone - Facility constraint for ship to location l_validate_result: '||l_validate_result);
17644         END IF;
17645 
17646         IF l_validate_result = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
17647             x_return_status := l_return_status;
17648             x_validate_result := l_validate_result;
17649             IF l_debug_on THEN
17650                 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');
17651             END IF;
17652             return;
17653         END IF;*/
17654      END IF;
17655 
17656     -- For validating ITEM-FACILITY constraints, get items in delivery using cursor c_get_details
17657     -- and validate exclusive constraints for each item
17658 
17659     IF p_delivery_rec.delivery_id IS NOT NULL THEN
17660 
17661         OPEN c_get_details(p_delivery_rec.delivery_id);
17662             FETCH c_get_details BULK COLLECT INTO l_details_info;
17663         CLOSE c_get_details;
17664 
17665         i_det := l_details_info.FIRST;
17666 
17667         IF i_det IS NOT NULL THEN
17668             LOOP
17669 
17670                 IF l_debug_on THEN
17671                   wsh_debug_sv.logmsg (l_module_name, 'organization_id: ' || l_details_info(i_det).organization_id);
17672                   wsh_debug_sv.logmsg (l_module_name, 'inventory_item_id: '||l_details_info(i_det).inventory_item_id);
17673                 END IF;
17674 
17675                 validate_constraint(   --  checks only negative constraints
17676                      p_comp_class_code          =>  WSH_FTE_CONSTRAINT_FRAMEWORK.G_ITEM_FACILITY,
17677                      p_object1_type             =>  'ITM',
17678                      p_object1_parent_id        =>  l_details_info(i_det).organization_id,
17679                      p_object1_val_num          =>  l_details_info(i_det).inventory_item_id,
17680                      p_object2_type             =>  'FAC',
17681                      p_object2_val_num          =>  p_rule_deconsol_location,
17682                      x_validate_result          =>  l_validate_result,
17683                      x_failed_constraint        =>  l_failed_constraint,
17684                      x_return_status            =>  l_return_status);
17685 
17686                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS AND l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17687                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
17688                 END IF;
17689 
17690                 IF l_debug_on THEN
17691                     wsh_debug_sv.logmsg (l_module_name, 'ITM - FAC l_validate_result: '||l_validate_result);
17692                 END IF;
17693 
17694                 IF l_validate_result = WSH_UTIL_CORE.G_RET_STS_ERROR THEN
17695                     x_return_status := l_return_status;
17696                     x_validate_result := l_validate_result;
17697                     IF l_debug_on THEN
17698                         wsh_debug_sv.push(l_module_name);
17699                         wsh_debug_sv.log (l_module_name,'constraint id violated : ',to_char(l_failed_constraint.constraint_id));
17700                         wsh_debug_sv.log (l_module_name,'entity_type : ',to_char(l_failed_constraint.entity_type));
17701                         wsh_debug_sv.log (l_module_name,'constraint_class_code : ',to_char(l_failed_constraint.constraint_class_code));
17702                         wsh_debug_sv.log (l_module_name,'violation_type : ',to_char(l_failed_constraint.violation_type));
17703                         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');
17704                     END IF;
17705                     IF l_debug_on THEN
17706                         wsh_debug_sv.pop (l_module_name);
17707                     END IF;
17708                     return;
17709                 END IF;
17710 
17711              EXIT WHEN i_det = l_details_info.LAST OR l_validate_result <> 'S' OR l_return_status <> 'S' ;
17712              i_det := l_details_info.NEXT(i_det);
17713              END LOOP;
17714          END IF;
17715     END IF;
17716 
17717     IF l_debug_on THEN
17718         wsh_debug_sv.pop (l_module_name);
17719     END IF;
17720 
17721 EXCEPTION
17722 
17723 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
17724       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
17725       --
17726       IF l_debug_on THEN
17727         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
17728         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
17729       END IF;
17730 
17731 WHEN OTHERS THEN
17732       IF c_get_details%ISOPEN THEN
17733          CLOSE c_get_details;
17734       END IF;
17735       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.validate_exclusive_constraints');
17736       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
17737       --
17738       IF l_debug_on THEN
17739         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
17740         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
17741       END IF;
17742 
17743 END validate_exclusive_constraints;
17744 
17745 --***************************************************************************--
17746 --========================================================================
17747 -- PROCEDURE : get_must_use_facility            PRIVATE
17748 --
17749 -- PARAMETERS: p_delivery_rec                   Input delivery record
17750 --             x_deconsol_location              Output deconsolidation location
17751 --             x_return_status                  Return status
17752 -- COMMENT   : This procedure is used to perform for following actions
17753 --             Takes input delivery record
17754 --             Finds deconsolidation location for the delivery based on
17755 --             Inclusive constraints defined.
17756 --             Checks for the following constraints
17757 --              1. Ship to location - facility
17758 --              2. customer - facility
17759 --              3. Ship from org - facility
17760 --========================================================================
17761 
17762 PROCEDURE get_must_use_facility(p_delivery_rec IN WSH_FTE_CONSTRAINT_FRAMEWORK.delivery_ccinfo_rec_type,
17763                                 x_deconsol_location OUT NOCOPY NUMBER,
17764                                 x_return_status     OUT NOCOPY VARCHAR2)
17765 
17766 IS
17767 l_ship_from_location_id  NUMBER;
17768 l_ship_to_location_id    NUMBER;
17769 l_customer_id            NUMBER;
17770 l_region_tab             WSH_UTIL_CORE.ID_TAB_TYPE;
17771 l_zone_tab               WSH_UTIL_CORE.ID_TAB_TYPE;
17772 l_deconsol_location      NUMBER;
17773 l_debug_on               CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
17774 r_itr                    NUMBER;
17775 z_itr                    NUMBER;
17776 l_region_id              NUMBER;
17777 l_zone_id                NUMBER;
17778 l_return_status		     VARCHAR2(1);
17779 l_constr_region_id       NUMBER;
17780 l_constr_location_id     NUMBER;
17781 l_constr_org_id          NUMBER;
17782 l_module_name            CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'get_must_use_facility';
17783 
17784 -- AG add compatibility_class_id = 2
17785 -- as otherwise there is a small chance of wrongly picking up
17786 -- a supplier facility - facility constraint
17787 CURSOR c_get_must_use_location (c_object1_type VARCHAR2, c_object1_id NUMBER, c_class_id NUMBER) IS
17788 SELECT constraint_object2_id from wsh_fte_comp_constraints
17789 WHERE constraint_object2_type = 'FAC'
17790 AND constraint_object1_type = c_object1_type
17791 AND constraint_object1_id = c_object1_id
17792 AND Constraint_type = 'I'
17793 AND compatibility_class_id = c_class_id  -- 2 for Cus_FAC
17794 AND    nvl(trunc(EFFECTIVE_DATE_FROM,'DDD'),trunc(sysdate,'DDD')) <= trunc(sysdate,'DDD')
17795 AND    nvl(trunc(EFFECTIVE_DATE_TO,'DDD'),trunc(sysdate,'DDD')) >= trunc(sysdate,'DDD');
17796 
17797 /*CURSOR c_get_must_use_cus_fac (c_object1_id NUMBER) IS
17798 SELECT constraint_object2_id from wsh_fte_comp_constraints
17799 WHERE constraint_object1_type = 'CUS'
17800 AND constraint_object2_type = 'FAC'
17801 AND constraint_object1_id = c_object1_id
17802 AND Constraint_type = 'I'
17803 AND    nvl(trunc(EFFECTIVE_DATE_FROM,'DDD'),trunc(sysdate,'DDD')) <= trunc(sysdate,'DDD')
17804 AND    nvl(trunc(EFFECTIVE_DATE_TO,'DDD'),trunc(sysdate,'DDD')) >= trunc(sysdate,'DDD');*/
17805 
17806 CURSOR c_get_region_incl_constraints IS
17807 SELECT constraint_object1_id, constraint_object2_id from wsh_fte_comp_constraints
17808 WHERE constraint_type = 'I'
17809 AND compatibility_class_id=12
17810 AND    nvl(trunc(EFFECTIVE_DATE_FROM,'DDD'),trunc(sysdate,'DDD')) <= trunc(sysdate,'DDD')
17811 AND    nvl(trunc(EFFECTIVE_DATE_TO,'DDD'),trunc(sysdate,'DDD')) >= trunc(sysdate,'DDD')
17812 ORDER BY creation_date;
17813 
17814 BEGIN
17815 
17816     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
17817 
17818     IF l_debug_on THEN
17819        wsh_debug_sv.push(l_module_name);
17820     END IF;
17821 
17822     -- get ship to location for the delivery
17823     -- For this location, find must use facility using defined inclusive constraint.
17824     -- Check in cache first, if not found in cache, get from cursor c_get_must_use_location
17825 
17826     l_ship_to_location_id := p_delivery_rec.ULTIMATE_DROPOFF_LOCATION_ID;
17827 
17828     IF l_debug_on THEN
17829         WSH_DEBUG_SV.logmsg(l_module_name,'l_ship_to_location_id: '|| l_ship_to_location_id);
17830     END IF;
17831 
17832     IF ( l_ship_to_location_id < g_cache_max_size  and g_location_mustuse_location.EXISTS(l_ship_to_location_id)) THEN
17833 
17834         l_deconsol_location := g_location_mustuse_location(l_ship_to_location_id);
17835     ELSE
17836         --Does not exist in the cache.
17837         -- Compatibility_class_id is 2 for CUS_FAC constraints
17838         OPEN  c_get_must_use_location( 'FAC', l_ship_to_location_id, 2);
17839             FETCH c_get_must_use_location INTO l_deconsol_location;
17840             IF c_get_must_use_location%NOTFOUND THEN
17841                    l_deconsol_location := NULL;
17842             END IF;
17843         CLOSE c_get_must_use_location;
17844 
17845         IF l_debug_on THEN
17846             WSH_DEBUG_SV.logmsg(l_module_name,'l_deconsol_location for ship To Location using CUS_FAC constraints : '|| l_deconsol_location);
17847         END IF;
17848 
17849 
17850         IF (l_ship_to_location_id < g_cache_max_size AND l_deconsol_location IS NOT NULL) THEN
17851             g_location_mustuse_location(l_ship_to_location_id) := l_deconsol_location;
17852         END IF;
17853     END IF;
17854 
17855     -- If deconsol location not found from must use constraint on ship to location,
17856     -- fetch region level constraints and populate g_region_mustuse_location cache
17857     -- with region id and corresponding must use location id for all region level constraints
17858     -- defined.
17859 
17860     IF l_deconsol_location IS NULL THEN
17861     --{
17862 
17863         IF g_region_mustuse_constraints.COUNT = 0 THEN
17864             OPEN c_get_region_incl_constraints;
17865                 LOOP
17866                     FETCH c_get_region_incl_constraints INTO  l_constr_region_id, l_constr_location_id;
17867                     EXIT WHEN c_get_region_incl_constraints%NOTFOUND;
17868                     g_region_mustuse_location(l_constr_region_id) := l_constr_location_id;
17869                 END LOOP;
17870             CLOSE c_get_region_incl_constraints;
17871         END IF;
17872 
17873         IF l_debug_on THEN
17874             WSH_DEBUG_SV.logmsg(l_module_name,'g_region_mustuse_location.COUNT : '|| g_region_mustuse_location.COUNT);
17875         END IF;
17876 
17877     	WSH_REGIONS_SEARCH_PKG.Get_All_RegionId_Matches(
17878              p_location_id		=> l_ship_to_location_id,
17879              p_use_cache		=> TRUE,
17880              p_lang_code		=> USERENV('LANG'),
17881              x_region_tab		=> l_region_tab,
17882              x_return_status    => l_return_status);
17883 
17884 	    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17885            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17886               raise FND_API.G_EXC_UNEXPECTED_ERROR;
17887            END IF;
17888         END IF;
17889 
17890         r_itr:= l_region_tab.FIRST;
17891 
17892         IF r_itr IS NOT NULL THEN
17893             LOOP
17894                 l_region_id := l_region_tab(r_itr);
17895 
17896                 IF l_region_id < g_cache_max_size AND g_region_mustuse_location.EXISTS(l_region_id) THEN
17897                     l_deconsol_location := g_region_mustuse_location(l_region_id);
17898                 END IF;
17899 
17900                 IF l_debug_on THEN
17901                     WSH_DEBUG_SV.logmsg(l_module_name,'l_deconsol_location from g_region_mustuse_location: '|| l_deconsol_location);
17902                 END IF;
17903 
17904                 -- If deconsolidation location found, populate it in cache
17905                 -- Else, search for zone level constraints
17906 
17907                 IF (l_ship_to_location_id < g_cache_max_size AND l_deconsol_location IS NOT NULL) THEN
17908                     g_location_mustuse_location(l_ship_to_location_id) := l_deconsol_location;
17909                 ELSIF l_deconsol_location IS NULL THEN
17910                     WSH_REGIONS_SEARCH_PKG.Get_All_Zone_Matches(
17911                       p_region_id		    => l_region_id,
17912                       x_zone_tab		    => l_zone_tab,
17913                       x_return_status       => l_return_status);
17914 
17915                      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
17916                        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
17917                           raise FND_API.G_EXC_UNEXPECTED_ERROR;
17918                        END IF;
17919                     END IF;
17920 
17921                     IF l_debug_on THEN
17922                         WSH_DEBUG_SV.logmsg(l_module_name,'l_zone_tab.COUNT: '|| l_zone_tab.COUNT);
17923                     END IF;
17924 
17925                     IF l_zone_tab.COUNT > 0 THEN
17926                         z_itr:= l_zone_tab.FIRST;
17927                         IF z_itr IS NOT NULL THEN
17928                             LOOP
17929                                 l_zone_id := l_zone_tab(z_itr);
17930                                 IF l_zone_id < g_cache_max_size AND g_region_mustuse_location.EXISTS(l_zone_id) THEN
17931                                     l_deconsol_location := g_region_mustuse_location(l_zone_id);
17932                                 END IF;
17933                                 EXIT WHEN z_itr = l_zone_tab.LAST OR l_deconsol_location IS NOT NULL;
17934                                 z_itr:= l_zone_tab.NEXT(z_itr);
17935                             END LOOP;
17936                         END IF;
17937                     END IF; -- end l_zone_tab.count >0
17938                 END IF;
17939 
17940                 EXIT WHEN r_itr = l_region_tab.LAST OR l_deconsol_location IS NOT NULL;
17941                 r_itr:= l_region_tab.NEXT(r_itr);
17942 	        END LOOP;
17943         END IF;
17944 
17945         IF (l_ship_to_location_id < g_cache_max_size AND l_deconsol_location IS NOT NULL) THEN
17946             g_location_mustuse_location(l_ship_to_location_id) := l_deconsol_location;
17947         ELSE
17948             g_location_mustuse_location(l_ship_to_location_id) := -1;
17949         END IF;
17950     --}
17951     END IF;
17952 
17953     -- If deconsolidation location not found, search for Customer - Facility constraints.
17954 
17955 
17956     IF l_deconsol_location IS NULL OR l_deconsol_location = -1 THEN
17957 
17958         IF l_debug_on THEN
17959             WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_rec.CUSTOMER_ID: '|| p_delivery_rec.CUSTOMER_ID);
17960         END IF;
17961 
17962         l_customer_id := p_delivery_rec.CUSTOMER_ID;
17963 
17964         IF ( l_customer_id < g_cache_max_size  and g_customer_mustuse_location.EXISTS(l_customer_id)) THEN
17965             l_deconsol_location := g_customer_mustuse_location(l_customer_id);
17966             IF (l_deconsol_location = -1) THEN
17967                 l_deconsol_location := NULL;
17968             END IF;
17969         ELSE
17970             --Does not exist in the cache.
17971             -- Compatibility_class_id is 2 for CUS_FAC constraints
17972 
17973             OPEN  c_get_must_use_location('CUS', l_customer_id, 2);
17974                 FETCH c_get_must_use_location INTO l_deconsol_location;
17975                 IF c_get_must_use_location%NOTFOUND THEN
17976                        l_deconsol_location := NULL;
17977                 END IF;
17978             CLOSE c_get_must_use_location;
17979 
17980             IF (l_customer_id < g_cache_max_size AND l_deconsol_location IS NOT NULL) THEN
17981                 g_customer_mustuse_location(l_customer_id) := l_deconsol_location;
17982             END IF;
17983         END IF;
17984 
17985         IF l_debug_on THEN
17986             WSH_DEBUG_SV.logmsg(l_module_name,'l_deconsol_location from customer inclusive constraints: '|| l_deconsol_location);
17987         END IF;
17988     END IF;
17989 
17990     -- If no constraints defined for customer, search for Ship From ORG_FAC constraints
17991 
17992     IF l_deconsol_location IS NULL OR l_deconsol_location = -1 THEN
17993 
17994         l_constr_org_id := p_delivery_rec.organization_id;
17995 
17996         IF l_debug_on THEN
17997             WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_rec.organization_id: '|| l_constr_org_id);
17998         END IF;
17999 
18000         IF (l_constr_org_id IS NOT NULL) THEN
18001 
18002             /*get_loc_for_org(
18003                 p_org_id	       => p_delivery_rec.organization_id,
18004                 x_location_id    => l_ship_from_location_id,
18005                 x_return_status  => x_return_status);
18006 
18007             IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
18008                 IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
18009                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
18010                 END IF;
18011             END IF;*/
18012 
18013             IF ( l_constr_org_id < g_cache_max_size AND g_org_mustuse_location.EXISTS(l_constr_org_id)) THEN
18014 
18015                 l_deconsol_location := g_org_mustuse_location(l_constr_org_id);
18016             ELSE
18017                 --Does not exist in the cache.
18018                 -- Compatibility_class_id is 1 for CUS_FAC constraints
18019                 OPEN  c_get_must_use_location('ORG', l_constr_org_id, 1);
18020                     FETCH c_get_must_use_location INTO l_deconsol_location;
18021                     IF c_get_must_use_location%NOTFOUND THEN
18022                            l_deconsol_location := NULL;
18023                     END IF;
18024                 CLOSE c_get_must_use_location;
18025                 -- Add to cache
18026                 IF (l_constr_org_id < g_cache_max_size AND l_deconsol_location IS NOT NULL) THEN
18027                     g_org_mustuse_location(l_constr_org_id) := l_deconsol_location;
18028                 ELSE
18029                     g_org_mustuse_location(l_constr_org_id) := -1;
18030                 END IF;
18031             END IF;
18032             IF l_debug_on THEN
18033                 WSH_DEBUG_SV.logmsg(l_module_name,'l_deconsol_location from org inclusive constraints: '|| l_deconsol_location);
18034             END IF;
18035 
18036         END IF;
18037 
18038     END IF;
18039 
18040     -- If deconsol location not found from must use constraint on ship from location,
18041     -- fetch region level constraints and populate g_region_mustuse_location cache
18042     -- with region id and corresponding must use location id for all region level constraints
18043     -- defined.
18044 
18045     IF l_deconsol_location IS NULL OR l_deconsol_location = -1 THEN
18046     --{
18047 
18048         get_loc_for_org(
18049             p_org_id	       => p_delivery_rec.organization_id,
18050             x_location_id    => l_ship_from_location_id,
18051             x_return_status  => x_return_status);
18052 
18053         IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
18054             IF x_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
18055                 raise FND_API.G_EXC_UNEXPECTED_ERROR;
18056             END IF;
18057         END IF;
18058 
18059         IF g_region_mustuse_constraints.COUNT = 0 THEN
18060             OPEN c_get_region_incl_constraints;
18061                 LOOP
18062                     FETCH c_get_region_incl_constraints INTO  l_constr_region_id, l_constr_location_id;
18063                     EXIT WHEN c_get_region_incl_constraints%NOTFOUND;
18064                     g_region_mustuse_location(l_constr_region_id) := l_constr_location_id;
18065                 END LOOP;
18066             CLOSE c_get_region_incl_constraints;
18067         END IF;
18068 
18069         IF l_debug_on THEN
18070             WSH_DEBUG_SV.logmsg(l_module_name,'g_region_mustuse_location.COUNT : '|| g_region_mustuse_location.COUNT);
18071         END IF;
18072 
18073     	WSH_REGIONS_SEARCH_PKG.Get_All_RegionId_Matches(
18074              p_location_id		=> l_ship_from_location_id,
18075              p_use_cache		=> TRUE,
18076              p_lang_code		=> USERENV('LANG'),
18077              x_region_tab		=> l_region_tab,
18078              x_return_status    => l_return_status);
18079 
18080 	    IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
18081            IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
18082               raise FND_API.G_EXC_UNEXPECTED_ERROR;
18083            END IF;
18084         END IF;
18085 
18086         r_itr:= l_region_tab.FIRST;
18087 
18088         IF r_itr IS NOT NULL THEN
18089             LOOP
18090                 l_region_id := l_region_tab(r_itr);
18091 
18092                 IF l_region_id < g_cache_max_size AND g_region_mustuse_location.EXISTS(l_region_id) THEN
18093                     l_deconsol_location := g_region_mustuse_location(l_region_id);
18094                 END IF;
18095 
18096                 IF l_debug_on THEN
18097                     WSH_DEBUG_SV.logmsg(l_module_name,'l_deconsol_location from g_region_mustuse_location: '|| l_deconsol_location);
18098                 END IF;
18099 
18100                 -- If deconsolidation location found, populate it in cache
18101                 -- Else, search for zone level constraints
18102 
18103                 IF (l_ship_to_location_id < g_cache_max_size AND l_deconsol_location IS NOT NULL) THEN
18104                     g_location_mustuse_location(l_ship_from_location_id) := l_deconsol_location;
18105                 ELSIF l_deconsol_location IS NULL THEN
18106                     WSH_REGIONS_SEARCH_PKG.Get_All_Zone_Matches(
18107                       p_region_id		    => l_region_id,
18108                       x_zone_tab		    => l_zone_tab,
18109                       x_return_status       => l_return_status);
18110 
18111                      IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
18112                        IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
18113                           raise FND_API.G_EXC_UNEXPECTED_ERROR;
18114                        END IF;
18115                     END IF;
18116 
18117                     IF l_debug_on THEN
18118                         WSH_DEBUG_SV.logmsg(l_module_name,'l_zone_tab.COUNT: '|| l_zone_tab.COUNT);
18119                     END IF;
18120 
18121                     IF l_zone_tab.COUNT > 0 THEN
18122                         z_itr:= l_zone_tab.FIRST;
18123                         IF z_itr IS NOT NULL THEN
18124                             LOOP
18125                                 l_zone_id := l_zone_tab(z_itr);
18126                                 IF l_zone_id < g_cache_max_size AND g_region_mustuse_location.EXISTS(l_zone_id) THEN
18127                                     l_deconsol_location := g_region_mustuse_location(l_zone_id);
18128                                 END IF;
18129                                 EXIT WHEN z_itr = l_zone_tab.LAST OR l_deconsol_location IS NOT NULL;
18130                                 z_itr:= l_zone_tab.NEXT(z_itr);
18131                             END LOOP;
18132                         END IF;
18133                     END IF;
18134                 END IF;
18135 
18136                 EXIT WHEN r_itr = l_region_tab.LAST OR l_deconsol_location IS NOT NULL;
18137                 r_itr:= l_region_tab.NEXT(r_itr);
18138 	        END LOOP;
18139         END IF;
18140         IF (l_ship_from_location_id < g_cache_max_size AND l_deconsol_location IS NOT NULL) THEN
18141             g_location_mustuse_location(l_ship_from_location_id) := l_deconsol_location;
18142         ELSE
18143             g_location_mustuse_location(l_ship_from_location_id) := -1;
18144         END IF;
18145     --}
18146     END IF;
18147     IF l_deconsol_location <> -1 THEN
18148         x_deconsol_location := l_deconsol_location;
18149     END IF;
18150 
18151     IF l_debug_on THEN
18152         WSH_DEBUG_SV.pop(l_module_name);
18153     END IF;
18154 
18155 EXCEPTION
18156 
18157 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
18158       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
18159       --
18160       IF l_debug_on THEN
18161         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
18162         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
18163       END IF;
18164 
18165 WHEN OTHERS THEN
18166       IF c_get_must_use_location%ISOPEN THEN
18167          CLOSE c_get_must_use_location;
18168       END IF;
18169       /*IF c_get_must_use_cus_fac%ISOPEN THEN
18170          CLOSE c_get_must_use_cus_fac;
18171       END IF;*/
18172       IF c_get_region_incl_constraints%ISOPEN THEN
18173          CLOSE c_get_region_incl_constraints;
18174       END IF;
18175 
18176       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.get_must_use_facility');
18177       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
18178       --
18179       IF l_debug_on THEN
18180         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
18181         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
18182       END IF;
18183 
18184 END get_must_use_facility;
18185 
18186 --***************************************************************************--
18187 --========================================================================
18188 -- PROCEDURE : VALIDATE_CONSTRAINT_DECONSOL
18189 --
18190 -- PARAMETERS: p_init_msg_list             FND_API.G_TRUE to reset list
18191 --             p_delivery_info             Table of delivery records to process
18192 --                                         Only one of p_in_ids and p_delivery_info should be passed
18193 --             p_in_ids                    Table of delivery ids to process
18194 --             p_rule_deconsol_location    Default deconsolidation location passed
18195 --             p_rule_override_deconsol    If true, default deconsolidation location passed
18196 --                                         takes precedence.
18197 --             x_output_id_tab             Output tab with deconsol location specified for deliveries
18198 --             x_msg_count                 Number of messages in the list
18199 --             x_msg_data                  Text of messages
18200 --             x_return_status             Return status
18201 -- COMMENT   : This procedure is to find deconsolidation locations for a group of deliveries passed
18202 --
18203 --             Deconsolidation location is searched for in the following sequence
18204 --                if override flag is true
18205 --                    if fte is installed
18206 --                        check exclusive constraints
18207 --                        if constraint faliure - error out del
18208 --                   else
18209 --                        set given loc as intermediate location
18210 --                else
18211 --                    get inter-med loc for delivery
18212 --                    if fte is installed
18213 --                       if intermediate loc not null
18214 --                            check exclusive constraints - in case of failure - error out delivery
18215 --                        else if null
18216 --                            check inclusive contraints to get must use location
18217 --                            if loc found
18218 --                                check exclusive constraints for this location
18219 --                            else if not found
18220 --                                get deconsol location provided in region zones form
18221 --                                if loc found
18222 --                                    check exclusive constraints
18223 --                                    if constraints faliure -  error out del
18224 --                                else
18225 --                                    check constraints on supplied location
18226 --                                    use supplied location
18227 --                    else if fte not installed
18228 --                        check region-zones to get location
18229 --                            if loc found
18230 --                                use location found
18231 --                            else
18232 --                                use supplied location
18233 --========================================================================
18234 
18235 PROCEDURE validate_constraint_deconsol( p_init_msg_list          IN  VARCHAR2 DEFAULT fnd_api.g_false,
18236                                         p_delivery_info          IN  OUT NOCOPY delivery_ccinfo_tab_type,
18237                                         p_in_ids                 IN  wsh_util_core.id_tab_type,
18238                                         p_rule_deconsol_location IN  NUMBER default NULL,
18239                                         p_rule_override_deconsol IN  BOOLEAN  DEFAULT  FALSE,
18240                                         p_rule_to_zone_id        IN  NUMBER  DEFAULT  NULL,
18241                                         p_caller                 IN  VARCHAR2 DEFAULT NULL,
18242                                         x_output_id_tab          OUT NOCOPY deconsol_output_tab_type,
18243                                         x_return_status          OUT NOCOPY VARCHAR2,
18244                                         x_msg_count              OUT NOCOPY NUMBER,
18245                                         x_msg_data               OUT NOCOPY VARCHAR2
18246 ) IS
18247 
18248     l_return_status		        VARCHAR2(1);
18249     j                           NUMBER := 0;
18250     i                           NUMBER := 0;
18251     l_facility_id               NUMBER := 0;
18252     l_stop_id                   NUMBER := 0;
18253     --l_delivery_info             delivery_ccinfo_tab_type;
18254     l_failed_constraint         WSH_FTE_CONSTRAINT_FRAMEWORK.line_constraint_rec_type;
18255     l_validate_result           VARCHAR2(1) := 'S';
18256     l_physical_location_id      NUMBER := NULL;
18257     l_intermed_ship_to_loc_id   NUMBER;
18258     l_rule_deconsol_location    NUMBER;
18259     l_debug_on                  CONSTANT BOOLEAN := WSH_DEBUG_SV.is_debug_enabled;
18260     l_module_name               CONSTANT VARCHAR2(100) := 'wsh.plsql.' || G_PKG_NAME || '.' || 'VALIDATE_CONSTRAINT_DECONSOL';
18261     rec_cnt                     NUMBER;
18262     l_region_tab                WSH_REGIONS_SEARCH_PKG.region_deconsol_Tab_Type;
18263     l_success                   VARCHAR2(1) := 'S';
18264     l_failure                   VARCHAR2(1) := 'F';
18265     l_zone_index                NUMBER := 0;
18266     l_msg_count                 NUMBER := 0;
18267     l_msg_data                  VARCHAR2(2000) := NULL;
18268 
18269     cursor c_gettrip(l_deliveryid IN NUMBER) is
18270     select wts.TRIP_ID
18271     from wsh_trip_stops wts, wsh_delivery_legs wdl
18272     where wdl.delivery_id =l_deliveryid AND
18273     wdl.pick_up_stop_id = wts.stop_id;
18274 
18275 
18276     CURSOR c_get_dlvy(c_delivery_id IN NUMBER) IS
18277     SELECT wnd.DELIVERY_ID
18278       , NULL
18279       , 'Y'
18280       , wnd.NAME
18281       , wnd.PLANNED_FLAG
18282       , wnd.STATUS_CODE
18283       , wnd.INITIAL_PICKUP_DATE
18284       , wnd.INITIAL_PICKUP_LOCATION_ID
18285       , wnd.ULTIMATE_DROPOFF_LOCATION_ID
18286       , wnd.ULTIMATE_DROPOFF_DATE
18287       , wnd.CUSTOMER_ID
18288       , wnd.INTMED_SHIP_TO_LOCATION_ID
18289       , wnd.SHIP_METHOD_CODE
18290       , wnd.DELIVERY_TYPE
18291       , wnd.CARRIER_ID
18292       , wnd.ORGANIZATION_ID
18293       , wnd.SERVICE_LEVEL
18294       , wnd.MODE_OF_TRANSPORT
18295       , wnd.PARTY_ID
18296       , nvl(wnd.SHIPMENT_DIRECTION,'O')
18297       , nvl(wnd.SHIPPING_CONTROL,'BUYER')
18298       , NULL  -- AGDUMMY
18299     FROM wsh_new_deliveries wnd
18300     WHERE wnd.delivery_id = c_delivery_id;
18301 
18302 BEGIN
18303 
18304     x_return_status := WSH_UTIL_CORE.G_RET_STS_SUCCESS;
18305 
18306     refresh_cache(l_return_status);
18307 
18308     IF l_debug_on THEN
18309       wsh_debug_sv.push (l_module_name);
18310       WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info.COUNT: '||p_delivery_info.COUNT);
18311     END IF;
18312 
18313     IF p_delivery_info.COUNT = 0 THEN
18314 
18315         i := p_in_ids.FIRST;
18316 
18317         IF i IS NOT NULL THEN
18318             LOOP
18319 
18320                 -- Fetch entire information for a particular record.
18321 
18322                 OPEN  c_get_dlvy(p_in_ids(i));
18323                     FETCH c_get_dlvy into p_delivery_info(i);
18324                 CLOSE c_get_dlvy;
18325 
18326                 --#DUM_LOC(S)
18327                 -- Delivery's ultimate_dropoff_location_id to be converted to physical internal
18328                 -- location if it is a dummy location.
18329                 -- We have to use the API for this purpose.
18330 
18331                 WSH_LOCATIONS_PKG.CONVERT_INTERNAL_CUST_LOCATION(
18332                  p_internal_cust_location_id  => p_delivery_info(i).ultimate_dropoff_location_id,
18333                  x_internal_org_location_id   => l_physical_location_id,
18334                  x_return_status              => l_return_status);
18335 
18336                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
18337                     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
18338                         raise FND_API.G_EXC_UNEXPECTED_ERROR;
18339                     END IF;
18340                 END IF;
18341 
18342                 --physical location id is not null implies- A dummy location.
18343                 IF (l_physical_location_id IS NOT NULL) THEN
18344                 --
18345                     IF l_debug_on THEN
18346                         WSH_DEBUG_SV.logmsg(l_module_name,'Location '||p_delivery_info(i).ultimate_dropoff_location_id||' is a dummy location');
18347                     END IF;
18348                 --
18349                     p_delivery_info(i).ultimate_dropoff_location_id := l_physical_location_id;
18350                     p_delivery_info(i).physical_dropoff_location_id := l_physical_location_id;
18351                 END IF;
18352                 --#DUM_LOC(E)
18353 
18354                 OPEN c_gettrip(p_in_ids(i));
18355                     FETCH c_gettrip into p_delivery_info(i).TRIP_ID;
18356                 CLOSE c_gettrip;
18357 
18358                 --
18359                 IF l_debug_on THEN
18360                     WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info(i).delivery_id : '||p_delivery_info(i).delivery_id);
18361                     WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info(i).initial_pickup_location_id : '||p_delivery_info(i).initial_pickup_location_id);
18362                     WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info(i).ultimate_dropoff_location_id : '||p_delivery_info(i).ultimate_dropoff_location_id);
18363                     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);
18364                 END IF;
18365                 --
18366                 EXIT WHEN i = p_in_ids.LAST;
18367                 i := p_in_ids.NEXT(i);
18368             END LOOP;
18369         END IF;
18370     END IF; -- p_delivery_info.COUNT = 0
18371 
18372 
18373 
18374     IF l_debug_on THEN
18375         WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info.COUNT: '||p_delivery_info.COUNT);
18376         WSH_DEBUG_SV.logmsg(l_module_name, 'WSH_FTE_CONSTRAINT_FRAMEWORK.g_is_fte_installed: '||WSH_FTE_CONSTRAINT_FRAMEWORK.g_is_fte_installed);
18377         --WSH_DEBUG_SV.logmsg(l_module_name,'p_rule_override_deconsol: '||p_rule_override_deconsol);
18378     END IF;
18379 
18380     -- Loop through deliveries to set deconsol location for each delivery
18381 
18382     rec_cnt := p_delivery_info.FIRST;
18383 
18384     IF rec_cnt IS NOT NULL THEN
18385     --{
18386         LOOP
18387         --{
18388             IF p_delivery_info(rec_cnt).shipping_control = 'SUPPLIER'  THEN
18389                 GOTO del_nextpass;
18390             END IF;
18391             IF l_debug_on THEN
18392                     WSH_DEBUG_SV.logmsg(l_module_name,'p_delivery_info(rec_cnt).delivery_id : '||p_delivery_info(rec_cnt).delivery_id);
18393             END IF;
18394 
18395             IF p_rule_override_deconsol = TRUE AND p_rule_deconsol_location IS NULL THEN
18396             --{
18397                 IF l_debug_on THEN
18398                     WSH_DEBUG_SV.logmsg(l_module_name,'p_rule_override_deconsol = TRUE AND p_rule_deconsol_location IS NULL');
18399                 END IF;
18400                 x_return_status := WSH_UTIL_CORE.G_RET_STS_ERROR;
18401                 IF l_debug_on THEN
18402                     wsh_debug_sv.pop (l_module_name);
18403                 END IF;
18404                 return;
18405             --}
18406             ELSIF p_rule_override_deconsol = TRUE AND p_rule_deconsol_location IS NOT NULL THEN
18407             --{
18408 
18409                 IF l_debug_on THEN
18410                     WSH_DEBUG_SV.logmsg(l_module_name,'p_rule_override_deconsol = TRUE AND p_rule_deconsol_location IS NOT NULL');
18411                 END IF;
18412 
18413                 IF WSH_FTE_CONSTRAINT_FRAMEWORK.g_is_fte_installed = 'Y' THEN
18414                 --{
18415                 --
18416                 -- FTE is installed, validate exclusive constraints for location supplied
18417                 --
18418                     VALIDATE_EXCLUSIVE_CONSTRAINTS(p_delivery_rec            => p_delivery_info(rec_cnt),
18419                                                    p_rule_deconsol_location  => p_rule_deconsol_location,
18420                                                    x_validate_result         => l_validate_result,
18421                                                    x_return_status           => l_return_status);
18422 
18423                     IF l_debug_on THEN
18424                         WSH_DEBUG_SV.logmsg(l_module_name,'VALIDATE_EXCLUSIVE_CONSTRAINTS l_validate_result : '||l_validate_result);
18425                         WSH_DEBUG_SV.logmsg(l_module_name,'VALIDATE_EXCLUSIVE_CONSTRAINTS l_return_status : '||l_return_status);
18426                     END IF;
18427 
18428                     IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR  OR l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
18429                          raise FND_API.G_EXC_UNEXPECTED_ERROR;
18430                     ELSE
18431                         IF l_validate_result = l_success THEN
18432                             x_output_id_tab(rec_cnt).deconsol_location := p_rule_deconsol_location;
18433                             x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18434                             x_output_id_tab(rec_cnt).validation_status := l_success;
18435                             p_delivery_info(rec_cnt).intmed_ship_to_location_id := p_rule_deconsol_location;
18436                         ELSE
18437                             x_output_id_tab(rec_cnt).deconsol_location := NULL;
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_failure;
18440                             p_delivery_info(rec_cnt).intmed_ship_to_location_id := NULL;
18441                         END IF;
18442                     END IF;
18443 
18444                     IF l_debug_on THEN
18445                         WSH_DEBUG_SV.logmsg(l_module_name,'deconsol_location: '||x_output_id_tab(rec_cnt).deconsol_location);
18446                         WSH_DEBUG_SV.logmsg(l_module_name,'entity_id: '||x_output_id_tab(rec_cnt).entity_id);
18447                         WSH_DEBUG_SV.logmsg(l_module_name,'validation_status: '||x_output_id_tab(rec_cnt).validation_status);
18448                     END IF;
18449 
18450                     GOTO del_nextpass;
18451                 --}
18452                 ELSE
18453                 --{
18454                     -- since fte is not installed and over-ride flag is true, set supplied location as
18455                     -- intermediate location
18456                     x_output_id_tab(rec_cnt).deconsol_location := p_rule_deconsol_location;
18457                     x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18458                     x_output_id_tab(rec_cnt).validation_status := l_success;
18459                     p_delivery_info(rec_cnt).intmed_ship_to_location_id := p_rule_deconsol_location;
18460 
18461                     IF l_debug_on THEN
18462                         WSH_DEBUG_SV.logmsg(l_module_name,'deconsol_location: '||x_output_id_tab(rec_cnt).deconsol_location);
18463                         WSH_DEBUG_SV.logmsg(l_module_name,'entity_id: '||x_output_id_tab(rec_cnt).entity_id);
18464                         WSH_DEBUG_SV.logmsg(l_module_name,'validation_status: '||x_output_id_tab(rec_cnt).validation_status);
18465                     END IF;
18466                 --}
18467                 END IF;
18468                 GOTO del_nextpass;
18469             --}
18470             ELSIF p_rule_override_deconsol = FALSE THEN
18471             --{
18472                 IF l_debug_on THEN
18473                     WSH_DEBUG_SV.logmsg(l_module_name,'p_rule_override_deconsol IS FALSE');
18474                 END IF;
18475                 l_intermed_ship_to_loc_id := p_delivery_info(rec_cnt).intmed_ship_to_location_id;
18476 
18477                 IF WSH_FTE_CONSTRAINT_FRAMEWORK.g_is_fte_installed = 'Y' THEN
18478                 --{
18479                     IF l_intermed_ship_to_loc_id IS NOT NULL THEN
18480                     --{
18481                         IF l_debug_on THEN
18482                             WSH_DEBUG_SV.logmsg(l_module_name,'l_intermed_ship_to_loc_id: '|| l_intermed_ship_to_loc_id);
18483                         END IF;
18484 
18485                         VALIDATE_EXCLUSIVE_CONSTRAINTS(p_delivery_rec            => p_delivery_info(rec_cnt),
18486                                                        p_rule_deconsol_location  => l_intermed_ship_to_loc_id,
18487                                                        x_validate_result         => l_validate_result,
18488                                                        x_return_status           => l_return_status);
18489 
18490                         IF l_debug_on THEN
18491                             WSH_DEBUG_SV.logmsg(l_module_name,'VALIDATE_EXCLUSIVE_CONSTRAINTS_validate_result : '||l_validate_result);
18492                             WSH_DEBUG_SV.logmsg(l_module_name,'VALIDATE_EXCLUSIVE_CONSTRAINTS_return_status : '||l_return_status);
18493                         END IF;
18494 
18495                         IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR  OR l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
18496                             raise FND_API.G_EXC_UNEXPECTED_ERROR;
18497                         ELSE
18498                             IF l_validate_result = l_success THEN
18499                                 x_output_id_tab(rec_cnt).deconsol_location := l_intermed_ship_to_loc_id;
18500                                 x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18501                                 x_output_id_tab(rec_cnt).validation_status := l_success;
18502                                 p_delivery_info(rec_cnt).intmed_ship_to_location_id := l_intermed_ship_to_loc_id;
18503                             ELSE
18504                                 x_output_id_tab(rec_cnt).deconsol_location := NULL;
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_failure;
18507                                 p_delivery_info(rec_cnt).intmed_ship_to_location_id := NULL;
18508                             END IF;
18509 
18510                             IF l_debug_on THEN
18511                                 WSH_DEBUG_SV.logmsg(l_module_name,'deconsol_location: '||x_output_id_tab(rec_cnt).deconsol_location);
18512                                 WSH_DEBUG_SV.logmsg(l_module_name,'entity_id: '||x_output_id_tab(rec_cnt).entity_id);
18513                                 WSH_DEBUG_SV.logmsg(l_module_name,'validation_status: '||x_output_id_tab(rec_cnt).validation_status);
18514                             END IF;
18515 
18516                             GOTO del_nextpass;
18517                         END IF;
18518                     --}
18519                     ELSE
18520                     --{
18521 
18522                     -- intermediate location for delivery is NULL, get intermediate location from
18523                     -- must use constraints defined for the location
18524 
18525                         IF l_debug_on THEN
18526                             WSH_DEBUG_SV.logmsg(l_module_name,'l_intermed_ship_to_loc_id IS NULL ');
18527                         END IF;
18528 
18529                         get_must_use_facility(p_delivery_rec => p_delivery_info(rec_cnt),
18530                                               x_deconsol_location => l_rule_deconsol_location,
18531                                               x_return_status   => l_return_status);
18532 
18533                         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
18534                             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
18535                                 raise FND_API.G_EXC_UNEXPECTED_ERROR;
18536                             END IF;
18537                         END IF;
18538 
18539                         IF l_rule_deconsol_location IS NOT NULL THEN
18540                         --{
18541                             VALIDATE_EXCLUSIVE_CONSTRAINTS(p_delivery_rec            => p_delivery_info(rec_cnt),
18542                                                            p_rule_deconsol_location  => l_rule_deconsol_location,
18543                                                            x_validate_result         => l_validate_result,
18544                                                            x_return_status           => l_return_status);
18545 
18546                             IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR  OR l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
18547                                 raise FND_API.G_EXC_UNEXPECTED_ERROR;
18548                             ELSE
18549                                 IF l_validate_result = l_success THEN
18550                                     x_output_id_tab(rec_cnt).deconsol_location := l_rule_deconsol_location;
18551                                     x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18552                                     x_output_id_tab(rec_cnt).validation_status := l_success;
18553                                     p_delivery_info(rec_cnt).intmed_ship_to_location_id := l_rule_deconsol_location;
18554                                 ELSE
18555                                     x_output_id_tab(rec_cnt).deconsol_location := NULL;
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_failure;
18558                                     p_delivery_info(rec_cnt).intmed_ship_to_location_id := NULL;
18559                                 END IF;
18560 
18561                                 IF l_debug_on THEN
18562                                     WSH_DEBUG_SV.logmsg(l_module_name,'deconsol_location: '||x_output_id_tab(rec_cnt).deconsol_location);
18563                                     WSH_DEBUG_SV.logmsg(l_module_name,'entity_id: '||x_output_id_tab(rec_cnt).entity_id);
18564                                     WSH_DEBUG_SV.logmsg(l_module_name,'validation_status: '||x_output_id_tab(rec_cnt).validation_status);
18565                                 END IF;
18566 
18567                                 GOTO del_nextpass;
18568                             END IF;
18569                         --}
18570                         ELSE
18571                         --{
18572                             -- Must use location not found from inclusive constraints.
18573                             -- obtain deconsol location specified through Regions and Zones Form
18574 
18575                             IF l_debug_on THEN
18576                                 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);
18577                             END IF;
18578 
18579                             WSH_REGIONS_SEARCH_PKG.get_all_region_deconsols
18580                                                 ( p_location_id		    => p_delivery_info(rec_cnt).ULTIMATE_DROPOFF_LOCATION_ID,
18581                                                  p_use_cache		    => TRUE,
18582                                                  p_lang_code		    => USERENV('LANG'),
18583                                                  p_zone_flag            => TRUE,
18584                                                  p_rule_to_zone_id      => p_rule_to_zone_id,
18585                                                  p_caller               => p_caller,
18586                                                  x_region_consol_tab	=> l_region_tab,
18587                                                  x_return_status        => l_return_status);
18588 
18589                             IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
18590                                 IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
18591                                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
18592                                 END IF;
18593                             END IF;
18594 
18595                             --
18596                             -- First check if l_region_tab contains a zone matching
18597                             -- to p_rule_to_zone_id passed.
18598                             -- If yes, set the deconsol location for that zone
18599                             -- otherwise, set the deconsol location for the region where region_type <>10 (i.e.zone)
18600                             --
18601                             IF l_region_tab.COUNT > 0 THEN
18602                                 --IF p_caller like 'WMS%' THEN
18603                                     l_rule_deconsol_location := l_region_tab(l_region_tab.FIRST).Deconsol_location;
18604                             ELSIF p_rule_deconsol_location IS NOT NULL THEN
18605                                 l_rule_deconsol_location := p_rule_deconsol_location;
18606                             END IF;
18607 
18608                             IF l_rule_deconsol_location IS NOT NULL THEN
18609 
18610                                 VALIDATE_EXCLUSIVE_CONSTRAINTS(p_delivery_rec            => p_delivery_info(rec_cnt),
18611                                                                p_rule_deconsol_location  => l_rule_deconsol_location,
18612                                                                x_validate_result         => l_validate_result,
18613                                                                x_return_status           => l_return_status);
18614 
18615                                 IF l_return_status = WSH_UTIL_CORE.G_RET_STS_ERROR  OR l_return_status = WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR THEN
18616                                     raise FND_API.G_EXC_UNEXPECTED_ERROR;
18617                                 ELSE
18618                                     IF l_validate_result = l_success THEN
18619                                         x_output_id_tab(rec_cnt).deconsol_location := l_rule_deconsol_location;
18620                                         x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18621                                         x_output_id_tab(rec_cnt).validation_status := l_success;
18622                                         p_delivery_info(rec_cnt).intmed_ship_to_location_id := l_rule_deconsol_location;
18623                                     ELSE
18624                                         x_output_id_tab(rec_cnt).deconsol_location := NULL;
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_failure;
18627                                         p_delivery_info(rec_cnt).intmed_ship_to_location_id := NULL;
18628                                     END IF;
18629 
18630                                     IF l_debug_on THEN
18631                                         WSH_DEBUG_SV.logmsg(l_module_name,'deconsol_location: '||x_output_id_tab(rec_cnt).deconsol_location);
18632                                         WSH_DEBUG_SV.logmsg(l_module_name,'entity_id: '||x_output_id_tab(rec_cnt).entity_id);
18633                                         WSH_DEBUG_SV.logmsg(l_module_name,'validation_status: '||x_output_id_tab(rec_cnt).validation_status);
18634                                     END IF;
18635 
18636                                     GOTO del_nextpass;
18637                                 END IF;
18638                             ELSE
18639                                 x_output_id_tab(rec_cnt).deconsol_location := NULL;
18640                                 x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18641                                 x_output_id_tab(rec_cnt).validation_status := l_failure;
18642                                 p_delivery_info(rec_cnt).intmed_ship_to_location_id := NULL;
18643                             END IF;
18644                         --}
18645                         END IF;
18646                     --}
18647                     END IF;
18648                 --}
18649                 ELSE -- if Fte is not installed, Use deconsol location from regions if intmed_shipto of the delivery is NULL,
18650                      -- if not found, use supplied value
18651                 --{
18652 
18653                     IF l_debug_on THEN
18654                         WSH_DEBUG_SV.logmsg(l_module_name,'FTE installation status: '|| WSH_FTE_CONSTRAINT_FRAMEWORK.g_is_fte_installed);
18655                     END IF;
18656                     -- AG if intmed_shipto of the delivery is NOT NULL return that
18657                     -- else do the following
18658 
18659                     IF l_intermed_ship_to_loc_id IS NOT NULL THEN
18660                     --{
18661                                 x_output_id_tab(rec_cnt).deconsol_location := l_intermed_ship_to_loc_id;
18662                                 x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18663                                 x_output_id_tab(rec_cnt).validation_status := l_success;
18664                                 p_delivery_info(rec_cnt).intmed_ship_to_location_id := l_intermed_ship_to_loc_id;
18665                     -- }
18666                     ELSE -- if
18667                     --{
18668 
18669                     WSH_REGIONS_SEARCH_PKG.get_all_region_deconsols
18670                                            ( p_location_id		    => p_delivery_info(rec_cnt).ULTIMATE_DROPOFF_LOCATION_ID,
18671                                              p_use_cache		    => TRUE,
18672                                              p_lang_code		    => USERENV('LANG'),
18673                                              p_zone_flag            => TRUE,
18674                                              p_rule_to_zone_id      => p_rule_to_zone_id,
18675                                              p_caller               => p_caller,
18676                                              x_region_consol_tab	=> l_region_tab,
18677                                              x_return_status        => l_return_status);
18678 
18679                     IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_SUCCESS THEN
18680                         IF l_return_status <> WSH_UTIL_CORE.G_RET_STS_WARNING THEN
18681                             raise FND_API.G_EXC_UNEXPECTED_ERROR;
18682                         END IF;
18683                     END IF;
18684 
18685                     IF l_region_tab.COUNT > 0 THEN
18686 
18687                         --IF p_caller like 'WMS%' THEN
18688                             l_rule_deconsol_location := l_region_tab(l_region_tab.FIRST).Deconsol_location;
18689                         --l_rule_deconsol_location := l_region_tab(l_region_tab.FIRST).Deconsol_location;
18690                     ELSIF p_rule_deconsol_location IS NOT NULL THEN
18691                         l_rule_deconsol_location := p_rule_deconsol_location;
18692                     END IF;
18693 
18694                     IF l_rule_deconsol_location IS NOT NULL THEN
18695                         x_output_id_tab(rec_cnt).deconsol_location := l_rule_deconsol_location;
18696                         x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18697                         x_output_id_tab(rec_cnt).validation_status := l_success;
18698                         p_delivery_info(rec_cnt).intmed_ship_to_location_id := l_rule_deconsol_location;
18699 
18700                         IF l_debug_on THEN
18701                             WSH_DEBUG_SV.logmsg(l_module_name,'deconsol_location: '||x_output_id_tab(rec_cnt).deconsol_location);
18702                             WSH_DEBUG_SV.logmsg(l_module_name,'entity_id: '||x_output_id_tab(rec_cnt).entity_id);
18703                             WSH_DEBUG_SV.logmsg(l_module_name,'validation_status: '||x_output_id_tab(rec_cnt).validation_status);
18704                         END IF;
18705                     ELSE
18706                         x_output_id_tab(rec_cnt).deconsol_location := NULL;
18707                         x_output_id_tab(rec_cnt).entity_id := p_delivery_info(rec_cnt).delivery_id;
18708                         x_output_id_tab(rec_cnt).validation_status := l_failure;
18709                         p_delivery_info(rec_cnt).intmed_ship_to_location_id := NULL;
18710                     END IF;
18711                     --}
18712                     END IF;
18713 
18714                 -- }
18715                 END IF;
18716             --}
18717             END IF;
18718 
18719             <<del_nextpass>>
18720 
18721             EXIT WHEN rec_cnt = p_delivery_info.LAST;
18722             rec_cnt := p_delivery_info.NEXT(rec_cnt);
18723         --}
18724         END LOOP;
18725     --}
18726     END IF;
18727 
18728     FND_MSG_PUB.Count_And_Get (
18729         p_count         =>      l_msg_count,
18730         p_data          =>      l_msg_data ,
18731         p_encoded       =>      FND_API.G_FALSE );
18732 
18733     IF l_debug_on THEN
18734         wsh_debug_sv.log (l_module_name,'No. of messages already in stack : ',to_char(l_msg_count));
18735         WSH_DEBUG_SV.pop(l_module_name);
18736     END IF;
18737 
18738 EXCEPTION
18739 
18740 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
18741       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
18742       --
18743       IF l_debug_on THEN
18744         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
18745         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
18746       END IF;
18747 
18748 WHEN OTHERS THEN
18749       IF c_gettrip%ISOPEN THEN
18750          CLOSE c_gettrip;
18751       END IF;
18752       IF c_get_dlvy%ISOPEN THEN
18753          CLOSE c_get_dlvy;
18754       END IF;
18755       WSH_UTIL_CORE.default_handler('WSH_FTE_CONSTRAINT_FRAMEWORK.validate_constraint_deconsol');
18756       x_return_status := WSH_UTIL_CORE.G_RET_STS_UNEXP_ERROR ;
18757       --
18758       IF l_debug_on THEN
18759         WSH_DEBUG_SV.logmsg(l_module_name,'Unexpected error has occured. Oracle error message is '|| SQLERRM,WSH_DEBUG_SV.C_UNEXPEC_ERR_LEVEL);
18760         WSH_DEBUG_SV.pop(l_module_name,'EXCEPTION:FND_API.G_EXC_UNEXPECTED_ERROR');
18761       END IF;
18762 
18763 END validate_constraint_deconsol;
18764 
18765 END WSH_FTE_CONSTRAINT_FRAMEWORK;
18766