DBA Data[Home] [Help]

PACKAGE BODY: APPS.INV_LOC_WMS_UTILS

Source


1 PACKAGE BODY inv_loc_wms_utils AS
2 /* $Header: INVLCPYB.pls 120.11.12010000.2 2008/07/29 13:41:33 ptkumar ship $ */
3 
4 g_pkg_name CONSTANT VARCHAR2(30) := 'INV_LOC_WMS_UTILS';
5 
6 
7 -- to turn off debugger, comment out the line 'dbms_output.put_line(msg);'
8 PROCEDURE mdebug(msg in varchar2)
9 IS
10     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
11 BEGIN
12    -- dbms_output.put_line(msg);
13    INV_TRX_UTIL_PUB.TRACE(msg,'INV_LOC_WMS_UTILS ',9);
14 END;
15 
16 -- This API returns the current and suggested volume, weight, and units capacity of a
17 -- given locator in the primary unit of measure
18 PROCEDURE get_locator_capacity
19   ( x_return_status             OUT NOCOPY VARCHAR2, -- return status (success/error/unexpected_error)
20     x_msg_count                 OUT NOCOPY NUMBER,   -- number of messages in the message queue
21     x_msg_data                  OUT NOCOPY VARCHAR2, -- message text when x_msg_count>0
22     x_location_maximum_units    OUT NOCOPY NUMBER,   -- max number of units that can be stored in locator
23     x_location_current_units    OUT NOCOPY NUMBER,   -- current number of units in locator
24     x_location_suggested_units  OUT NOCOPY NUMBER,   -- suggested number of units to be put into locator
25     x_location_available_units  OUT NOCOPY NUMBER,   -- number of units that can still be put into locator
26     x_location_weight_uom_code  OUT NOCOPY VARCHAR2, -- the locator's unit of measure for weight
27     x_max_weight                OUT NOCOPY NUMBER,   -- max weight the locator can take
28     x_current_weight            OUT NOCOPY NUMBER,   -- current weight in the locator
29     x_suggested_weight          OUT NOCOPY NUMBER,   -- suggested weight to be put into locator
30     x_available_weight          OUT NOCOPY NUMBER,   -- weight the locator can still take
31     x_volume_uom_code           OUT NOCOPY VARCHAR2, -- the locator's unit of measure for volume
32     x_max_cubic_area            OUT NOCOPY NUMBER,   -- max volume the locator can take
33     x_current_cubic_area        OUT NOCOPY NUMBER,   -- current volume in the locator
34     x_suggested_cubic_area      OUT NOCOPY NUMBER,   -- suggested volume to be put into locator
35     x_available_cubic_area      OUT NOCOPY NUMBER,   -- volume the locator can still take
36     p_organization_id           IN  NUMBER,   -- org of locator whose capacity is to be determined
37     p_inventory_location_id     IN  NUMBER    -- identifier of locator
38   )
39   IS
40      l_physical_locator_id             NUMBER;
41      l_locator_id                      NUMBER;
42      l_inventory_location_id           NUMBER;
43     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
44 BEGIN
45 
46    -- Initialize API return status to success
47    x_return_status := FND_API.G_RET_STS_SUCCESS;
48   /* If the locator has a physical_location_id
49      then use the physical_location_id for further
50      processing.Else we have to use the inventory_location_id
51      for further processing
52    */
53    /* Select all required values at same time
54    SELECT physical_location_id ,
55 	  inventory_location_id
56    INTO l_physical_locator_id,
57 	l_locator_id
58    FROM mtl_item_locations
59    WHERE  inventory_location_id =p_inventory_location_id
60        and organization_id = p_organization_id; */
61 
62    SELECT
63        physical_location_id,
64        inventory_location_id,
65        location_maximum_units,
66        location_current_units,
67        location_available_units,
68        location_suggested_units,
69        location_weight_uom_code,
70        max_weight,
71        current_weight,
72        suggested_weight,
73        available_weight,
74        volume_uom_code,
75        max_cubic_area,
76        current_cubic_area,
77        suggested_cubic_area,
78        available_cubic_area
79      INTO l_physical_locator_id,
80        l_locator_id,
81        x_location_maximum_units,
82        x_location_current_units,
83        x_location_available_units,
84        x_location_suggested_units,
85        x_location_weight_uom_code,
86        x_max_weight,
87        x_current_weight,
88        x_suggested_weight,
89        x_available_weight,
90        x_volume_uom_code,
91        x_max_cubic_area,
92        x_current_cubic_area,
93        x_suggested_cubic_area,
94        x_available_cubic_area
95      from mtl_item_locations
96      where organization_id              = p_organization_id
97        and   inventory_location_id      = p_inventory_location_id;
98 
99    IF (l_physical_locator_id is NOT null) AND (l_physical_locator_id <> p_inventory_location_id) THEN
100 
101      select
102        location_maximum_units,
103        location_current_units,
104        location_available_units,
105        location_suggested_units,
106        location_weight_uom_code,
107        max_weight,
108        current_weight,
109        suggested_weight,
110        available_weight,
111        volume_uom_code,
112        max_cubic_area,
113        current_cubic_area,
114        suggested_cubic_area,
115        available_cubic_area
116      into
117        x_location_maximum_units,
118        x_location_current_units,
119        x_location_available_units,
120        x_location_suggested_units,
121        x_location_weight_uom_code,
122        x_max_weight,
123        x_current_weight,
124        x_suggested_weight,
125        x_available_weight,
126        x_volume_uom_code,
127        x_max_cubic_area,
128        x_current_cubic_area,
129        x_suggested_cubic_area,
130        x_available_cubic_area
131      from mtl_item_locations
132      where organization_id 		= p_organization_id
133        and   inventory_location_id 	= l_physical_locator_id;
134 
135    END IF;
136 
137 EXCEPTION
138 
139  WHEN fnd_api.g_exc_error THEN
140       x_return_status := fnd_api.g_ret_sts_error;
141       fnd_msg_pub.count_and_get
142 	( p_count => x_msg_count,
143 	  p_data  => x_msg_data
144 	 );
145 
146    WHEN fnd_api.g_exc_unexpected_error THEN
147       x_return_status := fnd_api.g_ret_sts_unexp_error ;
148        fnd_msg_pub.count_and_get
149 	( p_count => x_msg_count,
150 	  p_data  => x_msg_data
151 	  );
152 
153    WHEN NO_DATA_FOUND THEN
154      x_return_status := fnd_api.g_ret_sts_error;
155 
156    WHEN OTHERS THEN
157       x_return_status := fnd_api.g_ret_sts_unexp_error;
158      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
159 	THEN
160 	 fnd_msg_pub.add_exc_msg
161 	   (  g_pkg_name,
162 	      'get_locator_capacity'
163 	      );
164 	END IF;
165      fnd_msg_pub.count_and_get
166 	( p_count => x_msg_count,
167 	  p_data  => x_msg_data
168 	  );
169 
170 END get_locator_capacity;
171 
172 -- This API only returns the current and suggested unit capacity of a
173 -- given locator
174 PROCEDURE get_locator_unit_capacity
175   ( x_return_status             OUT NOCOPY VARCHAR2, -- return status (success/error/unexpected_error)
176     x_msg_count                 OUT NOCOPY NUMBER,   -- number of messages in the message queue
177     x_msg_data                  OUT NOCOPY VARCHAR2, -- message text when x_msg_count>0
178     x_location_maximum_units    OUT NOCOPY NUMBER,   -- max number of units that can be stored in locator
179     x_location_current_units    OUT NOCOPY NUMBER,   -- current number of units in locator
180     x_location_suggested_units  OUT NOCOPY NUMBER,   -- suggested number of units to be put into locator
181     x_location_available_units  OUT NOCOPY NUMBER,   -- number of units that can still be put into locator
182     p_organization_id           IN  NUMBER,   -- org of locator whose capacity is to be determined
183     p_inventory_location_id     IN  NUMBER    -- identifier of locator
184     )
185   IS
186      l_physical_locator_id             NUMBER;
187      l_locator_id              NUMBER;
188      l_inventory_location_id           NUMBER;
189     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
190 BEGIN
191 
192    -- Initialize API return status to success
193    x_return_status := FND_API.G_RET_STS_SUCCESS;
194   /* If the locator has a physical_location_id
195      then use the physical_location_id for further
196      processing.Else we have to use the inventory_location_id
197      for further processing
198    */
199    /* Select all required values at same time
200    SELECT physical_location_id ,
201 	  inventory_location_id
202    INTO l_physical_locator_id,
203 	l_locator_id
204    FROM mtl_item_locations
205    WHERE  inventory_location_id =p_inventory_location_id
206        and organization_id = p_organization_id; */
207    SELECT physical_location_id ,
208 	  inventory_location_id ,
209        location_maximum_units,
210        location_current_units,
211        location_available_units,
212        location_suggested_units
213    INTO l_physical_locator_id,
214 	l_locator_id,
215         x_location_maximum_units,
216         x_location_current_units,
217         x_location_available_units,
218         x_location_suggested_units
219    FROM mtl_item_locations
220    WHERE  inventory_location_id =p_inventory_location_id
221        and organization_id = p_organization_id;
222 
223    IF (l_physical_locator_id is  NOT null) AND (l_physical_locator_id <> p_inventory_location_id) THEN
224       select
225          location_maximum_units,
226          location_current_units,
227          location_available_units,
228          location_suggested_units
229        into
230          x_location_maximum_units,
231          x_location_current_units,
232          x_location_available_units,
233          x_location_suggested_units
234        from mtl_item_locations
235        where organization_id 		= p_organization_id
236          and inventory_location_id 	= l_inventory_location_id;
237    END IF;
238 
239 EXCEPTION
240 
241  WHEN fnd_api.g_exc_error THEN
242       x_return_status := fnd_api.g_ret_sts_error;
243       fnd_msg_pub.count_and_get
244 	( p_count => x_msg_count,
245 	  p_data  => x_msg_data
246 	 );
247 
248    WHEN fnd_api.g_exc_unexpected_error THEN
249       x_return_status := fnd_api.g_ret_sts_unexp_error ;
250        fnd_msg_pub.count_and_get
251 	( p_count => x_msg_count,
252 	  p_data  => x_msg_data
253 	  );
254 
255    WHEN NO_DATA_FOUND THEN
256      x_return_status := fnd_api.g_ret_sts_error;
257 
258    WHEN OTHERS THEN
259       x_return_status := fnd_api.g_ret_sts_unexp_error;
260      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
261 	THEN
262 	 fnd_msg_pub.add_exc_msg
263 	   (  g_pkg_name
264 	      , 'get_locator_unit_capacity'
265 	      );
266 	END IF;
267      fnd_msg_pub.count_and_get
268 	( p_count => x_msg_count,
269 	  p_data  => x_msg_data
270 	  );
271 
272 END get_locator_unit_capacity;
273 
274 
275 -- This API only returns the current and suggested weight capacity of a
276 -- given locator
277 PROCEDURE get_locator_weight_capacity
278   ( x_return_status             OUT NOCOPY VARCHAR2, -- return status (success/error/unexpected_error)
279     x_msg_count                 OUT NOCOPY NUMBER,   -- number of messages in the message queue
280     x_msg_data                  OUT NOCOPY VARCHAR2, -- message text when x_msg_count>0
281     x_location_weight_uom_code  OUT NOCOPY VARCHAR2, -- the locator's unit of measure for weight
282     x_max_weight                OUT NOCOPY NUMBER,   -- max weight the locator can take
283     x_current_weight            OUT NOCOPY NUMBER,   -- current weight in the locator
284     x_suggested_weight          OUT NOCOPY NUMBER,   -- suggested weight to be put into locator
285     x_available_weight          OUT NOCOPY NUMBER,   -- weight the locator can still take
286     p_organization_id           IN  NUMBER,   -- org of locator whose capacity is to be determined
287     p_inventory_location_id     IN  NUMBER    -- identifier of locator
288     )
289   IS
290      l_physical_locator_id             NUMBER;
291      l_locator_id              NUMBER;
292      l_inventory_location_id           NUMBER;
293     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
294 BEGIN
295 
296    -- Initialize API return status to success
297    x_return_status := FND_API.G_RET_STS_SUCCESS;
298   /* If the locator has a physical_location_id
299      then use the physical_location_id for further
300      processing.Else we have to use the inventory_location_id
301      for further processing
302    */
303    /* Select all required values at same time
304    SELECT physical_location_id ,
305 	  inventory_location_id
306    INTO l_physical_locator_id,
307 	l_locator_id
308    FROM mtl_item_locations
309    WHERE  inventory_location_id =p_inventory_location_id
310        and organization_id = p_organization_id; */
311    SELECT physical_location_id ,
312         inventory_location_id,
313         location_weight_uom_code,
314         max_weight,
315         current_weight,
316         suggested_weight,
317         available_weight
318    INTO l_physical_locator_id,
319 	l_locator_id,
320         x_location_weight_uom_code,
321         x_max_weight,
322         x_current_weight,
323         x_suggested_weight,
324         x_available_weight
325    FROM mtl_item_locations
326    WHERE  inventory_location_id =p_inventory_location_id
327        and organization_id = p_organization_id;
328 
329    IF (l_physical_locator_id is  NOT null) AND (l_physical_locator_id <> p_inventory_location_id) THEN
330       select
331          location_weight_uom_code,
332          max_weight,
333          current_weight,
334          suggested_weight,
335          available_weight
336       into
337          x_location_weight_uom_code,
338          x_max_weight,
339          x_current_weight,
340          x_suggested_weight,
341          x_available_weight
342        from mtl_item_locations
343        where organization_id 		= p_organization_id
344          and   inventory_location_id 	= l_inventory_location_id;
345    END IF;
346 
347 EXCEPTION
348 
349  WHEN fnd_api.g_exc_error THEN
350       x_return_status := fnd_api.g_ret_sts_error;
351       fnd_msg_pub.count_and_get
352 	( p_count => x_msg_count,
353 	  p_data  => x_msg_data
354 	 );
355 
356    WHEN fnd_api.g_exc_unexpected_error THEN
357       x_return_status := fnd_api.g_ret_sts_unexp_error ;
358        fnd_msg_pub.count_and_get
359 	( p_count => x_msg_count,
360 	  p_data  => x_msg_data
361 	  );
362 
363    WHEN NO_DATA_FOUND THEN
364      x_return_status := fnd_api.g_ret_sts_error;
365 
366    WHEN OTHERS THEN
367       x_return_status := fnd_api.g_ret_sts_unexp_error;
368      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
369 	THEN
370 	 fnd_msg_pub.add_exc_msg
371 	   (  g_pkg_name
372 	      , 'get_locator_weight_capacity'
373 	      );
374 	END IF;
375      fnd_msg_pub.count_and_get
376 	( p_count => x_msg_count,
377 	  p_data  => x_msg_data
378 	  );
379 
380 END get_locator_weight_capacity;
381 
382 -- This API only returns the current and suggested volume capacity of a
383 -- given locator
384 PROCEDURE get_locator_volume_capacity
385   ( x_return_status             OUT NOCOPY VARCHAR2, -- return status (success/error/unexpected_error)
386     x_msg_count                 OUT NOCOPY NUMBER,   -- number of messages in the message queue
387     x_msg_data                  OUT NOCOPY VARCHAR2, -- message text when x_msg_count>0
388     x_volume_uom_code           OUT NOCOPY VARCHAR2, -- the locator's unit of measure for volume
389     x_max_cubic_area            OUT NOCOPY NUMBER,   -- max volume the locator can take
390     x_current_cubic_area        OUT NOCOPY NUMBER,   -- current volume in the locator
391     x_suggested_cubic_area      OUT NOCOPY NUMBER,   -- suggested volume to be put into locator
392     x_available_cubic_area      OUT NOCOPY NUMBER,   -- volume the locator can still take
393     p_organization_id           IN  NUMBER,   -- org of locator whose capacity is to be determined
394     p_inventory_location_id     IN  NUMBER    -- identifier of locator
395     )
396   IS
397      l_physical_locator_id             NUMBER;
398      l_locator_id              NUMBER;
399      l_inventory_location_id           NUMBER;
400     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
401 BEGIN
402 
403    -- Initialize API return status to success
404    x_return_status := FND_API.G_RET_STS_SUCCESS;
405   /* If the locator has a physical_location_id
406      then use the physical_location_id for further
407      processing.Else we have to use the inventory_location_id
408      for further processing
409    */
410    /* Select all required values at same time
411    SELECT physical_location_id ,
412 	  inventory_location_id
413    INTO l_physical_locator_id,
414 	l_locator_id
415    FROM mtl_item_locations
416    WHERE  inventory_location_id =p_inventory_location_id
417        and organization_id = p_organization_id; */
418 
419    SELECT physical_location_id ,
420       inventory_location_id,
421        volume_uom_code,
422        max_cubic_area,
423        current_cubic_area,
424        suggested_cubic_area,
425        available_cubic_area
426    INTO l_physical_locator_id,
427 	l_locator_id,
428         x_volume_uom_code,
429         x_max_cubic_area,
430         x_current_cubic_area,
431         x_suggested_cubic_area,
432         x_available_cubic_area
433     FROM mtl_item_locations
434     WHERE organization_id 		= p_organization_id
435        and   inventory_location_id 	= p_inventory_location_id;
436 
437    IF (l_physical_locator_id is NOT null) AND (l_physical_locator_id <> l_inventory_location_id) THEN
438     select
439        volume_uom_code,
440        max_cubic_area,
441        current_cubic_area,
442        suggested_cubic_area,
443        available_cubic_area
444      into
445        x_volume_uom_code,
446        x_max_cubic_area,
447        x_current_cubic_area,
448        x_suggested_cubic_area,
449        x_available_cubic_area
450      from mtl_item_locations
451      where organization_id 		= p_organization_id
452        and   inventory_location_id 	= l_physical_locator_id;
453    END IF;
454 
455 
456 EXCEPTION
457 
458  WHEN fnd_api.g_exc_error THEN
459       x_return_status := fnd_api.g_ret_sts_error;
460       fnd_msg_pub.count_and_get
461 	( p_count => x_msg_count,
462 	  p_data  => x_msg_data
463 	 );
464 
465    WHEN fnd_api.g_exc_unexpected_error THEN
466       x_return_status := fnd_api.g_ret_sts_unexp_error ;
467        fnd_msg_pub.count_and_get
468 	( p_count => x_msg_count,
469 	  p_data  => x_msg_data
470 	  );
471 
472    WHEN NO_DATA_FOUND THEN
473      x_return_status := fnd_api.g_ret_sts_error;
474 
475    WHEN OTHERS THEN
476       x_return_status := fnd_api.g_ret_sts_unexp_error;
477      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
478 	THEN
479 	 fnd_msg_pub.add_exc_msg
480 	   (  g_pkg_name
481 	      , 'get_locator_volume_capacity'
482 	      );
483 	END IF;
484      fnd_msg_pub.count_and_get
485 	( p_count => x_msg_count,
486 	  p_data  => x_msg_data
487 	  );
488 
489 END get_locator_volume_capacity;
490 
491 
492 -- This API updates the current volume, weight and units capacity of a locator when items are
493 -- issued or received in the locator
494 PROCEDURE update_loc_curr_capacity_nauto
495   ( x_return_status             OUT NOCOPY VARCHAR2, -- return status (success/error/unexpected_error)
496     x_msg_count                 OUT NOCOPY NUMBER,   -- number of messages in the message queue
497     x_msg_data                  OUT NOCOPY VARCHAR2, -- message text when x_msg_count>0
498     p_organization_id           IN  NUMBER,   -- org of locator whose capacity is to be determined
499     p_inventory_location_id     IN  NUMBER,   -- identifier of locator
500     p_inventory_item_id         IN  NUMBER,   -- identifier of item
501     p_primary_uom_flag          IN  VARCHAR2, -- 'Y' - transaction was in item's primary UOM
502 					      -- 'N' - transaction was NOT in item's primary UOM
503 					      --       or the information is not known
504     p_transaction_uom_code      IN  VARCHAR2, -- UOM of the transacted material that causes the
505 					      -- locator capacity to get updated
506     p_quantity                  IN  NUMBER,   -- transaction quantity in p_transaction_uom_code
507     p_issue_flag                IN  VARCHAR2  -- 'Y' - Issue transaction
508 					      -- 'N' - Receipt transaction
509   )
510   IS
511      -- item attributes
512      l_item_primary_uom_code     varchar2(3);
513      l_item_weight_uom_code 	 varchar2(3);
514      l_item_unit_weight		 number;
515      l_item_volume_uom_code	 varchar2(3);
516      l_item_unit_volume		 number;
517      -- transaction attributes
518      l_quantity                  NUMBER;  -- local variable to check that p_quantity always > 0
519      l_primary_quantity	         number;
520      l_transacted_weight	 number;
521      l_transacted_volume	 number;
522      -- converted transaction attributes
523      l_loc_uom_xacted_weight	 number;
524      l_loc_uom_xacted_volume	 number;
525      -- location attributes in units
526      l_max_units       	         number;
527      l_current_units	         number;
528      l_suggested_units	         number;
529      l_available_units	         number;
530      -- location attributes in weight
531      l_location_weight_uom_code	 varchar2(3);
532      l_max_weight		 number;
533      l_current_weight		 number;
534      l_suggested_weight		 number;
535      l_available_weight 	 number;
536      -- location attributes in volume
537      l_volume_uom_code		 varchar2(3);
538      l_max_cubic_area		 number;
539      l_current_cubic_area	 number;
540      l_suggested_cubic_area	 number;
541      l_available_cubic_area	 number;
542      -- updated capacity
543      l_update_units		 boolean := TRUE;  -- always update units
544      l_update_weight		 boolean := FALSE; -- only update if have location and item UOMs
545      l_update_volume		 boolean := FALSE; -- only update if have location and item UOMs
546      -- updated location
547      l_upd_loc_current_units	number;
548      l_upd_loc_available_units	number;
549      l_upd_loc_current_weight	number;
550      l_upd_loc_available_weight	number;
551      l_upd_loc_current_volume	number;
552      l_upd_loc_available_volume	number;
553 
554      l_physical_locator_id             NUMBER;
555      l_locator_id              NUMBER;
556      l_inventory_location_id           NUMBER;
557     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
558 BEGIN
559     IF (l_debug = 1) THEN
560        mdebug('In update_loc_curr_capacity_nauto');
561     END IF;
562    -- Initialize API return status to success
563    x_return_status := FND_API.G_RET_STS_SUCCESS;
564   /* If the locator has a physical_location_id
565      then use the physical_location_id for further
566      processing.Else we have to use the inventory_location_id
567      for further processing
568    */
569    SELECT physical_location_id ,
570 	  inventory_location_id
571    INTO l_physical_locator_id,
572 	l_locator_id
573    FROM mtl_item_locations
574    WHERE  inventory_location_id =p_inventory_location_id
575        and organization_id = p_organization_id;
576 
577    IF l_physical_locator_id is null THEN
578      l_inventory_location_id := l_locator_id;
579    ELSE
580      l_inventory_location_id := l_physical_locator_id;
581    END IF;
582 
583    /*
584    ############# If the locator capacity is infinite, then dont update anything, simply return#############
585    */
586    SELECT location_maximum_units, max_weight, max_cubic_area
587    INTO l_max_units, l_max_weight, l_max_cubic_area
588    FROM mtl_item_locations_kfv
589    WHERE organization_id        = p_organization_id
590      AND inventory_location_id  = l_inventory_location_id;
591 
592    IF l_max_units IS NULL AND l_max_weight IS NULL AND l_max_cubic_area IS NULL THEN
593         return;
594    END IF;
595 
596    -- Bug# 3067627
597    IF (l_debug = 1) THEN
598       mdebug('Before locking locator ' || l_inventory_location_id || ' in update_loc_curr_capacity_nauto');
599    END IF;
600 
601    SELECT inventory_location_id INTO l_inventory_location_id
602    FROM mtl_item_locations
603    WHERE  inventory_location_id = l_inventory_location_id
604        and organization_id = p_organization_id
605    FOR UPDATE NOWAIT;
606 
607    IF (l_debug = 1) THEN
608       mdebug('After locking locator ' || l_inventory_location_id || ' in update_loc_curr_capacity_nauto');
609    END IF;
610 
611    -- ensure that the input quantity (p_quantity) is always positive regardless whether
612    -- issue or receipt
613    l_quantity :=Abs(p_quantity);
614 
615    -- select necessary data from mtl_system_items and mtl_item_locations
616    select
617      primary_uom_code,
618      weight_uom_code,
619      unit_weight,
620      volume_uom_code,
621      unit_volume
622    into
623      l_item_primary_uom_code,
624      l_item_weight_uom_code,
625      l_item_unit_weight,
626      l_item_volume_uom_code,
627      l_item_unit_volume
628    from mtl_system_items
629    where organization_id 	= p_organization_id
630    and   inventory_item_id 	= p_inventory_item_id;
631 
632    select
633      location_maximum_units,
634      location_current_units,
635      location_suggested_units,
636      location_available_units,
637      location_weight_uom_code,
638      max_weight,
639      current_weight,
640      suggested_weight,
641      available_weight,
642      volume_uom_code,
643      max_cubic_area,
644      current_cubic_area,
645      suggested_cubic_area,
646      available_cubic_area
647    into
648      l_max_units,
649      l_current_units,
650      l_suggested_units,
651      l_available_units,
652      l_location_weight_uom_code,
653      l_max_weight,
654      l_current_weight,
655      l_suggested_weight,
656      l_available_weight,
657      l_volume_uom_code,
658      l_max_cubic_area,
659      l_current_cubic_area,
660      l_suggested_cubic_area,
661      l_available_cubic_area
662      from mtl_item_locations
663      where organization_id 	= p_organization_id
664      and   inventory_location_id 	= l_inventory_location_id;
665 
666    IF (l_debug = 1) THEN
667       mdebug('After select: p_organization_id: '|| p_organization_id);
668       mdebug('After select: p_inventory_item_id: '|| p_inventory_item_id);
669       mdebug('After select: p_inventory_location_id: '|| l_inventory_location_id);
670       mdebug('After select: l_current_units: '|| l_current_units);
671       mdebug('After select: l_max_units: '|| l_max_units);
672    END IF;
673 
674    -- Convert transaction quantity into primary quantity (l_primary_quantity) if needed
675    -- Note: the p_primary_uom_flag is used when the transaction_uom is not known during
676    -- running of the upgrade script
677    IF (l_item_primary_uom_code <> p_transaction_uom_code)
678      and (p_primary_uom_flag <> 'Y') then
679 
680 	l_primary_quantity :=
681 		inv_convert.inv_um_convert( item_id 	  => p_inventory_item_id,
682 					    precision	  => null,
683 					    from_quantity => l_quantity,
684 					    from_unit	  => p_transaction_uom_code,
685 					    to_unit	  => l_item_primary_uom_code,
686 					    from_name	  => null,
687 					    to_name	  => null);
688    ELSE
689       l_primary_quantity := l_quantity;
690    END IF;
691     IF (l_debug = 1) THEN
692        mdebug('l_primary_quantity: '|| l_primary_quantity);
693     END IF;
694 
695   -- if have enough info, set update_weight flag to true:
696   -- convert transacted item weight to transacted location weight (if necessary)
697   -- and set l_update_weight flag to TRUE
698   IF (l_item_unit_weight > 0 and
699       l_item_weight_uom_code is not null and
700       l_location_weight_uom_code is not NULL) then
701 
702 
703 	l_transacted_weight := l_primary_quantity * l_item_unit_weight;
704 
705 	IF (l_item_weight_uom_code <> l_location_weight_uom_code) then
706 	   l_loc_uom_xacted_weight :=
707 		  inv_convert.inv_um_convert( item_id 	  => p_inventory_item_id,
708 					    precision	  => null,
709 					    from_quantity => l_transacted_weight,
710 					    from_unit	  => l_item_weight_uom_code,
711 					    to_unit	  => l_location_weight_uom_code,
712 					    from_name	  => null,
713 					    to_name	  => null) ;
714 	ELSE
715 	   l_loc_uom_xacted_weight := l_transacted_weight;
716 	END IF;
717 
718 	l_update_weight := TRUE;
719   END IF;
720 
721   --  if have enough info, set update_volume flag to true:
722   --  convert transacted item volume to transacted location volume (if necessary)
723   --  and set l_update_volume flag to TRUE
724   IF (l_item_unit_volume > 0 and
725       l_item_volume_uom_code is not null and
726       l_volume_uom_code is not NULL) then
727 
728 
729 	l_transacted_volume := l_primary_quantity * l_item_unit_volume;
730 	IF (l_item_volume_uom_code <> l_volume_uom_code) then
731 	   l_loc_uom_xacted_volume :=
732 		  inv_convert.inv_um_convert( item_id 	  => p_inventory_item_id,
733 					    precision	  => null,
734 					    from_quantity => l_transacted_volume,
735 					    from_unit	  => l_item_volume_uom_code,
736 					    to_unit	  => l_volume_uom_code,
737 					    from_name	  => null,
738 					    to_name	  => null);
739 	ELSE
740 	   l_loc_uom_xacted_volume := l_transacted_volume;
741 	END IF;
742 
743 	l_update_volume := TRUE;
744   END IF;
745 
746   -- update current weight
747   IF (l_update_weight) then
748      -- check that current_weight and suggested weight are not null or < 0
749      -- if current_weight is null, drive current_weight to zero
750      IF (l_current_weight IS NULL) OR (l_current_weight < 0) then
751 	l_current_weight := 0;
752      END IF;
753      -- if suggested_weight is negative or null, set l_suggested_weight to zero
754      IF (l_suggested_weight IS NULL) OR (l_suggested_weight < 0) then
755 	l_suggested_weight := 0;
756      END IF;
757 
758      -- if receipt (put into location), update current_weight
759      -- we have checked that current_weight an xacted_weight > 0
760      IF (Upper(p_issue_flag) = 'N') THEN
761 	l_upd_loc_current_weight := l_current_weight + l_loc_uom_xacted_weight;
762 	-- if max not defined, let available_weight be undefined
763 	-- assume that max_weight > 0 (the form takes care of this)
764 	IF (l_max_weight IS NULL) THEN
765 	   l_upd_loc_available_weight :=  NULL;
766 	 ELSE
767 	   -- update available weight, and make sure that it is > 0
768 	   l_upd_loc_available_weight := l_max_weight
769 	     - (l_upd_loc_current_weight + l_suggested_weight);
770 	   IF (l_upd_loc_available_weight < 0) THEN
771 	      l_upd_loc_available_weight := 0;
772 	   END IF;
773 	END IF;
774 
775 	-- if issue: p_issue='Y' (take out of location)
776       ELSIF (Upper(p_issue_flag) = 'Y') THEN
777 	-- update current weight
778 	l_upd_loc_current_weight := l_current_weight - l_loc_uom_xacted_weight;
779 	 -- update current_ weight, and make sure that it is > 0
780 	IF (l_upd_loc_current_weight < 0) THEN
781 	   l_upd_loc_current_weight := 0;
782 	END IF;
783 	-- if max not defined, let available_weight be undefined
784 	-- assume that max_weight > 0 (the form takes care of this)
785 	IF (l_max_weight IS NULL) THEN
786 	   l_upd_loc_available_weight :=  NULL;
787 	 ELSE
788 	   -- update available weight, and make sure that it is > 0
789 	   l_upd_loc_available_weight := l_max_weight
790 	     -  (l_upd_loc_current_weight + l_suggested_weight);
791 	   IF (l_upd_loc_available_weight < 0) THEN
792 	      l_upd_loc_available_weight := 0;
793 	   END IF;
794 	END IF;
795 	-- if p_issue_flag neither Y/N, raise error
796       ELSE
797 	fnd_message.set_name('INV', 'INV_FIELD_INVALID');
798 	fnd_msg_pub.ADD;
799 	RAISE fnd_api.g_exc_error;
800      END IF;
801      -- if not updating weight, then just propagate current_weight to updated_weight.
802    ELSE
803      l_upd_loc_current_weight := l_current_weight;
804      l_upd_loc_available_weight := l_available_weight;
805   END IF;
806 
807    -- update current volume
808   IF (l_update_volume) then
809      -- check that current_volume and suggested volume are not null or < 0
810      -- if current_volume is null, drive current_volume to zero
811      IF (l_current_cubic_area IS NULL) OR (l_current_cubic_area < 0) then
812 	l_current_cubic_area := 0;
813      END IF;
814      -- if suggested_volume is negative or null, set l_suggested_volume to zero
815      IF (l_suggested_cubic_area IS NULL) OR (l_suggested_cubic_area < 0) then
816 	l_suggested_cubic_area := 0;
817      END IF;
818 
819      -- if receipt (put into location), update current_volume
820      IF (Upper(p_issue_flag) = 'N') THEN
821 	l_upd_loc_current_volume := l_current_cubic_area + l_loc_uom_xacted_volume;
822 	-- if max not defined, let available_volume be undefined
823 	-- assume that max_volume > 0 (the form takes care of this)
824 	IF (l_max_cubic_area IS NULL) THEN
825 	   l_upd_loc_available_volume :=  NULL;
826 	 ELSE
827 	   -- update available volume, and make sure that it is > 0
828 	   l_upd_loc_available_volume := l_max_cubic_area
829 	     - (l_upd_loc_current_volume + l_suggested_cubic_area);
830 	   IF (l_upd_loc_available_volume < 0) THEN
831 	      l_upd_loc_available_volume := 0;
832 	   END IF;
833 	END IF;
834 
835 	-- if issue: p_issue='Y' (take out of location)
836       ELSIF (Upper(p_issue_flag) = 'Y') THEN
837 	-- update current volume
838 	l_upd_loc_current_volume := l_current_cubic_area - l_loc_uom_xacted_volume;
839 	-- update current_volume, and make sure that it is > 0
840 	IF (l_upd_loc_current_volume < 0) THEN
841 	   l_upd_loc_current_volume := 0;
842 	END IF;
843 	-- if max not defined, let available_volume be undefined
844 	-- assume that max_volume > 0 (the form takes care of this)
845 	IF (l_max_cubic_area IS NULL) THEN
846 	   l_upd_loc_available_volume :=  NULL;
847 	 ELSE
848 	   -- update available volume, and make sure that it is > 0
849 	   l_upd_loc_available_volume := l_max_cubic_area
850 	     - (l_upd_loc_current_volume + l_suggested_cubic_area);
851 	   IF (l_upd_loc_available_volume < 0) THEN
852 	      l_upd_loc_available_volume := 0;
853 	   END IF;
854 	END IF;
855       ELSE
856 	fnd_message.set_name('WMS', 'Invalid input to p_issue_flag (receipt/issue)');
857 	fnd_msg_pub.ADD;
858 	RAISE fnd_api.g_exc_error;
859 
860      END IF;
861    ELSE
862      l_upd_loc_current_volume := l_current_cubic_area;
863      l_upd_loc_available_volume := l_available_cubic_area;
864   END IF;
865 
866  -- update current units
867   IF (l_update_units) then
868      -- check that current_units and suggested units are not null or < 0
869      -- if current_units is null, drive current_units to zero
870      IF (l_current_units IS NULL) OR (l_current_units < 0) then
871 	l_current_units := 0;
872      END IF;
873      -- if suggested_units is negative or null, set l_suggested_units to zero
874      IF (l_suggested_units IS NULL) OR (l_suggested_units < 0) then
875 	l_suggested_units := 0;
876      END IF;
877      IF (l_debug = 1) THEN
878         mdebug('l_current_units: '|| l_current_units);
879      END IF;
880      -- if receipt (put into location), update current_units
881      IF (Upper(p_issue_flag) = 'N') THEN
882 	l_upd_loc_current_units := l_current_units + l_primary_quantity;
883 	-- if max not defined, let available_units be undefined
884 	-- assume that max_units > 0 (the form takes care of this)
885 	IF (l_max_units IS NULL) THEN
886 	   l_upd_loc_available_units :=  NULL;
887 	 ELSE
888 	   -- update available units, and make sure that it is > 0
889 	   l_upd_loc_available_units := l_max_units
890 	     - (l_upd_loc_current_units + l_suggested_units);
891 	   IF (l_upd_loc_available_units < 0) THEN
892 	      l_upd_loc_available_units := 0;
893 	   END IF;
894 	END IF;
895 	-- if issue: p_issue='Y' (take out of location)
896       ELSIF (Upper(p_issue_flag) = 'Y') THEN
897 	-- update current units
898 	l_upd_loc_current_units := l_current_units - l_primary_quantity;
899 	-- update current_units, and make sure that it is > 0
900 	IF (l_upd_loc_current_units < 0) THEN
901 	   l_upd_loc_current_units := 0;
902 	END IF;
903 	-- if max not defined, let available_units be undefined
904 	-- assume that max_units > 0 (the form takes care of this)
905 	IF (l_max_units IS NULL) THEN
906 	   l_upd_loc_available_units :=  NULL;
907 	 ELSE
908 	   -- update available units, and make sure that it is > 0
909 	   l_upd_loc_available_units := l_max_units
910 	     -  (l_upd_loc_current_units + l_suggested_units);
911 	   IF (l_upd_loc_available_units < 0) THEN
912 	      l_upd_loc_available_units := 0;
913 	   END IF;
914 	END IF;
915 	-- if p_issue_flag neither Y/N, raise error
916       ELSE
917 	fnd_message.set_name('WMS', 'Invalid input to p_issue_flag (receipt/issue)');
918 	fnd_msg_pub.ADD;
919 	RAISE fnd_api.g_exc_error;
920      END IF;
921    ELSE
922      l_upd_loc_current_units := l_current_units;
923      l_upd_loc_available_units := l_available_units;
924   END IF;
925   IF (l_debug = 1) THEN
926      mdebug('l_upd_loc_current_units: '|| l_upd_loc_current_units);
927   END IF;
928   -- Now we update the table MTL_ITEM_LOCATIONS
929   IF (l_update_weight) OR (l_update_volume) OR (l_update_units) THEN
930      UPDATE mtl_item_locations
931        SET
932        location_current_units 	        = l_upd_loc_current_units,
933        location_available_units 	= l_upd_loc_available_units,
934        current_weight             	= l_upd_loc_current_weight,
935        available_weight		        = l_upd_loc_available_weight,
936        current_cubic_area		= l_upd_loc_current_volume,
937        available_cubic_area 		= l_upd_loc_available_volume
938        where   inventory_location_id = l_inventory_location_id
939        and     organization_id           = p_organization_id;
940   END IF;
941 
942 EXCEPTION
943 
944    WHEN fnd_api.g_exc_error THEN
945       ROLLBACK;
946       x_return_status := fnd_api.g_ret_sts_error;
947       fnd_msg_pub.count_and_get
948 	( p_count => x_msg_count,
949 	  p_data  => x_msg_data
950 	 );
951 
952    WHEN fnd_api.g_exc_unexpected_error THEN
953       ROLLBACK;
954       x_return_status := fnd_api.g_ret_sts_unexp_error ;
955        fnd_msg_pub.count_and_get
956 	( p_count => x_msg_count,
957 	  p_data  => x_msg_data
958 	  );
959 
960    WHEN NO_DATA_FOUND THEN
961       ROLLBACK;
962       x_return_status := fnd_api.g_ret_sts_error;
963 
964    WHEN OTHERS THEN
965       ROLLBACK;
966       x_return_status := fnd_api.g_ret_sts_unexp_error;
967      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
968 	THEN
969 	 fnd_msg_pub.add_exc_msg
970 	   (  g_pkg_name
971 	      , 'update_loc_curr_capacity_nauto'
972 	      );
973 	END IF;
974      fnd_msg_pub.count_and_get
975 	( p_count => x_msg_count,
976 	  p_data  => x_msg_data
977 	  );
978 END update_loc_curr_capacity_nauto;
979 
980 -- This API updates the current volume, weight and units capacity of a locator when items are
981 -- issued or received in the locator
982 -- An autonomous commit is performed in the end
983 PROCEDURE update_loc_current_capacity
984   ( x_return_status             OUT NOCOPY VARCHAR2, -- return status (success/error/unexpected_error)
985     x_msg_count                 OUT NOCOPY NUMBER,   -- number of messages in the message queue
986     x_msg_data                  OUT NOCOPY VARCHAR2, -- message text when x_msg_count>0
987     p_organization_id           IN  NUMBER,   -- org of locator whose capacity is to be determined
988     p_inventory_location_id     IN  NUMBER,   -- identifier of locator
989     p_inventory_item_id         IN  NUMBER,   -- identifier of item
990     p_primary_uom_flag          IN  VARCHAR2, -- 'Y' - transaction was in item's primary UOM
991 					      -- 'N' - transaction was NOT in item's primary UOM
992 					      --       or the information is not known
993     p_transaction_uom_code      IN  VARCHAR2, -- UOM of the transacted material that causes the
994 					      -- locator capacity to get updated
995     p_quantity                  IN  NUMBER,   -- transaction quantity in p_transaction_uom_code
996     p_issue_flag                IN  VARCHAR2  -- 'Y' - Issue transaction
997 					      -- 'N' - Receipt transaction
998   )
999 IS
1000      -- this whole function is an autonomous commit
1001      PRAGMA autonomous_transaction;
1002 
1003      l_return_status            varchar2(1);
1004      l_msg_count                number;
1005      l_msg_data                 varchar2(1000);
1006 
1007     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1008 BEGIN
1009 
1010   -- Initialize API return status to success
1011   x_return_status := FND_API.G_RET_STS_SUCCESS;
1012 
1013   inv_loc_wms_utils.update_loc_curr_capacity_nauto
1014   ( x_return_status             => l_return_status,
1015     x_msg_count                 => x_msg_count,
1016     x_msg_data                  => x_msg_data,
1017     p_organization_id           => p_organization_id,
1018     p_inventory_location_id     => p_inventory_location_id,
1019     p_inventory_item_id         => p_inventory_item_id,
1020     p_primary_uom_flag          => p_primary_uom_flag,
1021     p_transaction_uom_code      => p_transaction_uom_code,
1022     p_quantity                  => p_quantity,
1023     p_issue_flag                => p_issue_flag);
1024 
1025   IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
1026 	    IF (l_return_status = fnd_api.g_ret_sts_error) THEN
1027 		RAISE fnd_api.g_exc_error;
1028 	    ELSE
1029 		RAISE fnd_api.g_exc_unexpected_error;
1030 	    END IF;
1031   END IF;
1032 
1033   -- end of autonomous commit
1034   COMMIT;
1035 EXCEPTION
1036 
1037    WHEN fnd_api.g_exc_error THEN
1038       ROLLBACK;
1039       x_return_status := fnd_api.g_ret_sts_error;
1040       fnd_msg_pub.count_and_get
1041 	( p_count => x_msg_count,
1042 	  p_data  => x_msg_data
1043 	 );
1044 
1045    WHEN fnd_api.g_exc_unexpected_error THEN
1046       ROLLBACK;
1047       x_return_status := fnd_api.g_ret_sts_unexp_error ;
1048        fnd_msg_pub.count_and_get
1049 	( p_count => x_msg_count,
1050 	  p_data  => x_msg_data
1051 	  );
1052 
1053    WHEN NO_DATA_FOUND THEN
1054       ROLLBACK;
1055       x_return_status := fnd_api.g_ret_sts_error;
1056 
1057    WHEN OTHERS THEN
1058       ROLLBACK;
1059       x_return_status := fnd_api.g_ret_sts_unexp_error;
1060      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
1061 	THEN
1062 	 fnd_msg_pub.add_exc_msg
1063 	   (  g_pkg_name
1064 	      , 'update_loc_current_capacity'
1065 	      );
1066 	END IF;
1067      fnd_msg_pub.count_and_get
1068 	( p_count => x_msg_count,
1069 	  p_data  => x_msg_data
1070 	  );
1071 END update_loc_current_capacity;
1072 
1073 
1074 -- This API updates the suggested volume, weight and units capacity of a locator when
1075 -- drop off locator is suggested.
1076 -- THIS API DOES NOT UPDATE EMPTY FLAG OF THE LOCATOR.
1077 
1078 PROCEDURE update_loc_sugg_cap_wo_empf
1079   ( x_return_status             OUT NOCOPY VARCHAR2, -- return status (success/error/unexpected_error)
1080     x_msg_count                 OUT NOCOPY NUMBER,   -- number of messages in the message queue
1081     x_msg_data                  OUT NOCOPY VARCHAR2, -- message text when x_msg_count>0
1082     p_organization_id           IN  NUMBER,   -- org of locator whose capacity is to be determined
1083     p_inventory_location_id     IN  NUMBER,   -- identifier of locator
1084     p_inventory_item_id         IN  NUMBER,   -- identifier of item
1085     p_primary_uom_flag          IN  VARCHAR2, -- 'Y' - transaction was in item's primary UOM
1086 					      -- 'N' - transaction was NOT in item's primary UOM
1087 					      --       or the information is not known
1088     p_transaction_uom_code      IN  VARCHAR2, -- UOM of the transacted material that causes the
1089 					      -- locator capacity to get updated
1090     p_quantity                  IN  NUMBER   -- transaction quantity in p_transaction_uom_code
1091 
1092   )
1093 IS
1094      -- this whole function is an autonomous commit
1095      PRAGMA autonomous_transaction;
1096 
1097      l_return_status            varchar2(1);
1098      l_msg_count                number;
1099      l_msg_data                 varchar2(1000);
1100     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1101 BEGIN
1102 
1103    -- Initialize API return status to success
1104    x_return_status := FND_API.G_RET_STS_SUCCESS;
1105 
1106   inv_loc_wms_utils.update_loc_sugg_capacity_nauto
1107   ( x_return_status             => l_return_status,
1108     x_msg_count                 => x_msg_count,
1109     x_msg_data                  => x_msg_data,
1110     p_organization_id           => p_organization_id,
1111     p_inventory_location_id     => p_inventory_location_id,
1112     p_inventory_item_id         => p_inventory_item_id,
1113     p_primary_uom_flag          => p_primary_uom_flag,
1114     p_transaction_uom_code      => p_transaction_uom_code,
1115     p_quantity                  => p_quantity
1116   );
1117 
1118   IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
1119 	    IF (l_return_status = fnd_api.g_ret_sts_error) THEN
1120 		RAISE fnd_api.g_exc_error;
1121 	    ELSE
1122 		RAISE fnd_api.g_exc_unexpected_error;
1123 	    END IF;
1124   END IF;
1125 
1126   -- end of autonomous commit;
1127   COMMIT;
1128 EXCEPTION
1129 
1130    WHEN fnd_api.g_exc_error THEN
1131       ROLLBACK;
1132       x_return_status := fnd_api.g_ret_sts_error;
1133       fnd_msg_pub.count_and_get
1134 	( p_count => x_msg_count,
1135 	  p_data  => x_msg_data
1136 	 );
1137 
1138    WHEN fnd_api.g_exc_unexpected_error THEN
1139       ROLLBACK;
1140       x_return_status := fnd_api.g_ret_sts_unexp_error ;
1141        fnd_msg_pub.count_and_get
1142 	( p_count => x_msg_count,
1143 	  p_data  => x_msg_data
1144 	  );
1145 
1146    WHEN NO_DATA_FOUND THEN
1147       ROLLBACK;
1148      x_return_status := fnd_api.g_ret_sts_error;
1149 
1150    WHEN OTHERS THEN
1151       ROLLBACK;
1152       x_return_status := fnd_api.g_ret_sts_unexp_error;
1153      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
1154 	THEN
1155 	 fnd_msg_pub.add_exc_msg
1156 	   (  g_pkg_name
1157 	      , 'update_loc_suggested_capacity'
1158 	      );
1159 	END IF;
1160      fnd_msg_pub.count_and_get
1161 	( p_count => x_msg_count,
1162 	  p_data  => x_msg_data
1163 	  );
1164 END update_loc_sugg_cap_wo_empf;
1165 
1166 
1167 
1168 
1169 -- This API updates the suggested volume, weight and units capacity of a locator when items are
1170 --  received in the locator.  Suggestions are only receipt suggestions.
1171 PROCEDURE update_loc_sugg_capacity_nauto
1172   ( x_return_status             OUT NOCOPY VARCHAR2, -- return status (success/error/unexpected_error)
1173     x_msg_count                 OUT NOCOPY NUMBER,   -- number of messages in the message queue
1174     x_msg_data                  OUT NOCOPY VARCHAR2, -- message text when x_msg_count>0
1175     p_organization_id           IN  NUMBER,   -- org of locator whose capacity is to be determined
1176     p_inventory_location_id     IN  NUMBER,   -- identifier of locator
1177     p_inventory_item_id         IN  NUMBER,   -- identifier of item
1178     p_primary_uom_flag          IN  VARCHAR2, -- 'Y' - transaction was in item's primary UOM
1179 					      -- 'N' - transaction was NOT in item's primary UOM
1180 					      --       or the information is not known
1181     p_transaction_uom_code      IN  VARCHAR2, -- UOM of the transacted material that causes the
1182 					      -- locator capacity to get updated
1183     p_quantity                  IN  NUMBER   -- transaction quantity in p_transaction_uom_code
1184 
1185   )
1186   IS
1187      -- item attributes
1188      l_item_primary_uom_code     varchar2(3);
1189      l_item_weight_uom_code 	 varchar2(3);
1190      l_item_unit_weight		 number;
1191      l_item_volume_uom_code	 varchar2(3);
1192      l_item_unit_volume		 number;
1193      -- transaction attributes
1194      l_quantity                  NUMBER;  -- local variable to check that p_quantity always > 0
1195      l_primary_quantity	         number;
1196      l_transacted_weight	 number;
1197      l_transacted_volume	 number;
1198      -- converted transaction attributes
1199      l_loc_uom_xacted_weight	 number;
1200      l_loc_uom_xacted_volume	 number;
1201      -- location attributes in units
1202      l_max_units       	         number;
1203      l_current_units	         number;
1204      l_suggested_units	         number;
1205      l_available_units	         number;
1206      -- location attributes in weight
1207      l_location_weight_uom_code	 varchar2(3);
1208      l_max_weight		 number;
1209      l_current_weight		 number;
1210      l_suggested_weight		 number;
1211      l_available_weight 	 number;
1212      -- location attributes in volume
1213      l_volume_uom_code		 varchar2(3);
1214      l_max_cubic_area		 number;
1215      l_current_cubic_area	 number;
1216      l_suggested_cubic_area	 number;
1217      l_available_cubic_area	 number;
1218      -- updated capacity
1219      l_update_units		 boolean := TRUE;  -- always update units
1220      l_update_weight		 boolean := FALSE; -- only update if have location and item UOMs
1221      l_update_volume		 boolean := FALSE; -- only update if have location and item UOMs
1222      -- updated location
1223      l_upd_loc_suggested_units	number;
1224      l_upd_loc_available_units	number;
1225      l_upd_loc_suggested_weight	number;
1226      l_upd_loc_available_weight	number;
1227      l_upd_loc_suggested_volume	number;
1228      l_upd_loc_available_volume	number;
1229 
1230      l_physical_locator_id             NUMBER;
1231      l_locator_id              NUMBER;
1232      l_inventory_location_id           NUMBER;
1233 
1234     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1235 BEGIN
1236    IF (l_debug = 1) THEN
1237       mdebug('In update_loc_sugg_capacity_nauto');
1238    END IF;
1239    -- Initialize API return status to success
1240    x_return_status := FND_API.G_RET_STS_SUCCESS;
1241   /* If the locator has a physical_location_id
1242      then use the physical_location_id for further
1243      processing.Else we have to use the inventory_location_id
1244      for further processing
1245    */
1246    SELECT physical_location_id ,
1247 	  inventory_location_id
1248    INTO l_physical_locator_id,
1249 	l_locator_id
1250    FROM mtl_item_locations
1251    WHERE  inventory_location_id =p_inventory_location_id
1252        and organization_id = p_organization_id;
1253 
1254    IF l_physical_locator_id is null THEN
1255      l_inventory_location_id := l_locator_id;
1256    ELSE
1257      l_inventory_location_id := l_physical_locator_id;
1258    END IF;
1259 
1260    /*
1261    ############# If the locator capacity is infinite, then dont update anything, simply return#############
1262    */
1263    SELECT location_maximum_units, max_weight, max_cubic_area
1264    INTO l_max_units, l_max_weight, l_max_cubic_area
1265    FROM mtl_item_locations_kfv
1266    WHERE organization_id        = p_organization_id
1267      AND inventory_location_id  = l_inventory_location_id;
1268 
1269    IF l_max_units IS NULL AND l_max_weight IS NULL AND l_max_cubic_area IS NULL THEN
1270         return;
1271    END IF;
1272 
1273    -- Bug# 3067627
1274    IF (l_debug = 1) THEN
1275       mdebug('Before locking locator ' || l_inventory_location_id || ' in update_loc_sugg_capacity_nauto');
1276    END IF;
1277 
1278    SELECT inventory_location_id INTO l_inventory_location_id
1279    FROM mtl_item_locations
1280    WHERE  inventory_location_id = l_inventory_location_id
1281        and organization_id = p_organization_id
1282    FOR UPDATE NOWAIT;
1283 
1284    IF (l_debug = 1) THEN
1285       mdebug('After locking locator ' || l_inventory_location_id || ' in update_loc_sugg_capacity_nauto');
1286    END IF;
1287 
1288    -- ensure that the input quantity (p_quantity) is always positive regardless whether
1289    -- issue or receipt
1290    l_quantity :=Abs(p_quantity);
1291    -- select necessary data from mtl_system_items and mtl_item_locations
1292    select
1293      primary_uom_code,
1294      weight_uom_code,
1295      unit_weight,
1296      volume_uom_code,
1297      unit_volume
1298    into
1299      l_item_primary_uom_code,
1300      l_item_weight_uom_code,
1301      l_item_unit_weight,
1302      l_item_volume_uom_code,
1303      l_item_unit_volume
1304    from mtl_system_items
1305    where organization_id 	= p_organization_id
1306    and   inventory_item_id 	= p_inventory_item_id;
1307 
1308    select
1309      location_maximum_units,
1310      location_current_units,
1311      location_suggested_units,
1312      location_available_units,
1313      location_weight_uom_code,
1314      max_weight,
1315      current_weight,
1316      suggested_weight,
1317      available_weight,
1318      volume_uom_code,
1319      max_cubic_area,
1320      current_cubic_area,
1321      suggested_cubic_area,
1322      available_cubic_area
1323    into
1324      l_max_units,
1325      l_current_units,
1326      l_suggested_units,
1327      l_available_units,
1328      l_location_weight_uom_code,
1329      l_max_weight,
1330      l_current_weight,
1331      l_suggested_weight,
1332      l_available_weight,
1333      l_volume_uom_code,
1334      l_max_cubic_area,
1335      l_current_cubic_area,
1336      l_suggested_cubic_area,
1337      l_available_cubic_area
1338      from mtl_item_locations
1339      where organization_id 	= p_organization_id
1340      and   inventory_location_id 	= l_inventory_location_id;
1341 
1342    IF (l_debug = 1) THEN
1343       mdebug('After select: p_organization_id: '|| p_organization_id);
1344       mdebug('After select: p_inventory_item_id: '|| p_inventory_item_id);
1345       mdebug('After select: p_inventory_location_id: '|| l_inventory_location_id);
1346       mdebug('After select: l_suggested_units: '|| l_suggested_units);
1347       mdebug('After select: l_max_units: '|| l_max_units);
1348    END IF;
1349 
1350      -- Convert transaction quantity into primary quantity (l_primary_quantity) if needed
1351    -- Note: the p_primary_uom_flag is used when the transaction_uom is not known during
1352    -- running of the upgrade script
1353    IF (l_item_primary_uom_code <> p_transaction_uom_code)
1354      and (p_primary_uom_flag <> 'Y') then
1355 
1356 	l_primary_quantity :=
1357 		inv_convert.inv_um_convert( item_id 	  => p_inventory_item_id,
1358 					    precision	  => null,
1359 					    from_quantity => l_quantity,
1360 					    from_unit	  => p_transaction_uom_code,
1361 					    to_unit	  => l_item_primary_uom_code,
1362 					    from_name	  => null,
1363 					    to_name	  => null);
1364    ELSE
1365       l_primary_quantity := l_quantity;
1366   END IF;
1367 
1368   IF (l_debug = 1) THEN
1369      mdebug ('l_primary_quantity: '||l_primary_quantity);
1370   END IF;
1371   -- if have enough info, set update_weight flag to true:
1372   -- convert transacted item weight to transacted location weight (if necessary)
1373   -- and set l_update_weight flag to TRUE
1374   IF (l_item_unit_weight > 0 and
1375       l_item_weight_uom_code is not null and
1376       l_location_weight_uom_code is not NULL) then
1377 
1378 	l_transacted_weight := l_primary_quantity * l_item_unit_weight;
1379 
1380 	IF (l_item_weight_uom_code <> l_location_weight_uom_code) then
1381 	   l_loc_uom_xacted_weight :=
1382 		  inv_convert.inv_um_convert( item_id 	  => p_inventory_item_id,
1383 					    precision	  => null,
1384 					    from_quantity => l_transacted_weight,
1385 					    from_unit	  => l_item_weight_uom_code,
1386 					    to_unit	  => l_location_weight_uom_code,
1387 					    from_name	  => null,
1388 					    to_name	  => null) ;
1389 	ELSE
1390 	   l_loc_uom_xacted_weight := l_transacted_weight;
1391 	END IF;
1392 
1393 	l_update_weight := TRUE;
1394   END IF;
1395 
1396   --  if have enough info, set update_volume flag to true:
1397   --  convert transacted item volume to transacted location volume (if necessary)
1398   --  and set l_update_volume flag to TRUE
1399   IF (l_item_unit_volume > 0 and
1400       l_item_volume_uom_code is not null and
1401       l_volume_uom_code is not NULL) then
1402 
1403 
1404 	l_transacted_volume := l_primary_quantity * l_item_unit_volume;
1405 	-- make sure that transcated_volume > 0
1406 	IF (l_item_volume_uom_code <> l_volume_uom_code) then
1407 	   l_loc_uom_xacted_volume :=
1408 		  inv_convert.inv_um_convert( item_id 	  => p_inventory_item_id,
1409 					    precision	  => null,
1410 					    from_quantity => l_transacted_volume,
1411 					    from_unit	  => l_item_volume_uom_code,
1412 					    to_unit	  => l_volume_uom_code,
1413 					    from_name	  => null,
1414 					    to_name	  => null);
1415 	ELSE
1416 	   l_loc_uom_xacted_volume := l_transacted_volume;
1417 	END IF;
1418 
1419 	l_update_volume := TRUE;
1420   END IF;
1421 
1422   -- update suggested weight when receiving
1423   IF (l_update_weight) then
1424      -- check that current_weight and suggested weight are not null or < 0
1425      -- if current_weight is null, drive current_weight to zero
1426      IF (l_current_weight IS NULL) OR (l_current_weight < 0) then
1427 	l_current_weight := 0;
1428      END IF;
1429      -- if suggested_weight is negative or null, set l_suggested_weight to zero
1430      IF (l_suggested_weight IS NULL) OR (l_suggested_weight < 0) then
1431 	l_suggested_weight := 0;
1432      END IF;
1433 
1434      -- when receipt (put into location), update suggested_weight
1435      -- Note: All suggestions are receipt suggestions
1436      l_upd_loc_suggested_weight := l_suggested_weight + l_loc_uom_xacted_weight;
1437      -- if max not defined, let available_weight be undefined
1438      -- assume that max_weight > 0 (the Form takes care of this)
1439      IF (l_max_weight IS NULL) THEN
1440 	l_upd_loc_available_weight :=  NULL;
1441       ELSE
1442 	-- update available weight, and make sure that it is > 0
1443 	l_upd_loc_available_weight := l_max_weight
1444 	  - (l_upd_loc_suggested_weight + l_current_weight);
1445 	IF (l_upd_loc_available_weight < 0) THEN
1446 	   l_upd_loc_available_weight := 0;
1447 	END IF;
1448      END IF;
1449    ELSE
1450      -- if weight not updated, just propagate current suggested weight
1451      l_upd_loc_suggested_weight := l_suggested_weight;
1452      l_upd_loc_available_weight := l_available_weight;
1453   END IF;
1454 
1455    -- update suggested volume; Note: volume = cubic area
1456   IF (l_update_volume) then
1457      -- check that current_volume and suggested volume are not null or < 0
1458      -- if current_volume is null, drive current_volume to zero
1459      IF (l_current_cubic_area IS NULL) OR (l_current_cubic_area < 0) then
1460 	l_current_cubic_area := 0;
1461      END IF;
1462      -- if suggested_volume is negative or null, set l_suggested_volume to zero
1463      IF (l_suggested_cubic_area IS NULL) OR (l_suggested_cubic_area < 0) then
1464 	l_suggested_cubic_area := 0;
1465      END IF;
1466 
1467      -- when receipt (put into location)
1468      -- Note: All suggestions are receipt suggestions
1469      l_upd_loc_suggested_volume := l_suggested_cubic_area + l_loc_uom_xacted_volume;
1470      -- if max not defined, let available_volume be undefined
1471      -- assume that max_volume > 0 (the Form takes care of this)
1472      IF (l_max_cubic_area IS NULL) THEN
1473 	l_upd_loc_available_volume :=  NULL;
1474       ELSE
1475 	-- update available volume, and make sure that it is > 0
1476 	l_upd_loc_available_volume := l_max_cubic_area
1477 	  - (l_upd_loc_suggested_volume + l_current_cubic_area);
1478 	IF (l_upd_loc_available_volume < 0) THEN
1479 	   l_upd_loc_available_volume := 0;
1480 	END IF;
1481      END IF;
1482    ELSE
1483      -- if volume not updated, just propagate current suggested volume
1484      l_upd_loc_suggested_volume := l_suggested_cubic_area;
1485      l_upd_loc_available_volume := l_available_cubic_area;
1486   END IF;
1487 
1488  -- update current units
1489   IF (l_update_units) then
1490     -- check that current_units and suggested units are not null or < 0
1491      -- if current_units is null, drive current_units to zero
1492      IF (l_current_units IS NULL) OR (l_current_units < 0) then
1493 	l_current_units := 0;
1494      END IF;
1495      -- if suggested_units is negative or null, set l_suggested_units to zero
1496      IF (l_suggested_units IS NULL) OR (l_suggested_units < 0) then
1497 	l_suggested_units := 0;
1498      END IF;
1499 
1500      -- when receipt (put into location), update suggested_units
1501      -- Note: All suggestions are receipt suggestions
1502      l_upd_loc_suggested_units := l_suggested_units + l_primary_quantity;
1503      -- if max not defined, let available_units be undefined
1504      -- assume that max_units > 0 (the Form takes care of this)
1505      IF (l_max_units IS NULL) THEN
1506 	l_upd_loc_available_units :=  NULL;
1507       ELSE
1508 	-- update available units, and make sure that it is > 0
1509 	l_upd_loc_available_units := l_max_units
1510 	  - (l_upd_loc_suggested_units + l_current_units);
1511 	IF (l_upd_loc_available_units < 0) THEN
1512 	   l_upd_loc_available_units := 0;
1513 	END IF;
1514      END IF;
1515    ELSE
1516      -- if units not updated, just propagate current suggested units
1517      l_upd_loc_suggested_units := l_suggested_units;
1518      l_upd_loc_available_units := l_available_units;
1519   END IF;
1520 
1521   IF (l_debug = 1) THEN
1522      mdebug('l_upd_loc_suggested_units: '|| l_upd_loc_suggested_units);
1523   END IF;
1524   -- Now we update the table MTL_ITEM_LOCATIONS
1525   IF (l_update_weight) OR (l_update_volume) OR (l_update_units) THEN
1526      UPDATE mtl_item_locations
1527        SET
1528        location_suggested_units 	= l_upd_loc_suggested_units,
1529        location_available_units 	= l_upd_loc_available_units,
1530        suggested_weight             	= l_upd_loc_suggested_weight,
1531        available_weight		        = l_upd_loc_available_weight,
1532        suggested_cubic_area		= l_upd_loc_suggested_volume,
1533        available_cubic_area 		= l_upd_loc_available_volume
1534        where inventory_location_id = l_inventory_location_id
1535        and     organization_id           = p_organization_id;
1536   END IF;
1537 
1538 EXCEPTION
1539 
1540    WHEN fnd_api.g_exc_error THEN
1541       ROLLBACK;
1542       x_return_status := fnd_api.g_ret_sts_error;
1543       fnd_msg_pub.count_and_get
1544 	( p_count => x_msg_count,
1545 	  p_data  => x_msg_data
1546 	 );
1547 
1548    WHEN fnd_api.g_exc_unexpected_error THEN
1549       ROLLBACK;
1550       x_return_status := fnd_api.g_ret_sts_unexp_error ;
1551        fnd_msg_pub.count_and_get
1552 	( p_count => x_msg_count,
1553 	  p_data  => x_msg_data
1554 	  );
1555 
1556    WHEN NO_DATA_FOUND THEN
1557       ROLLBACK;
1558      x_return_status := fnd_api.g_ret_sts_error;
1559 
1560    WHEN OTHERS THEN
1561       ROLLBACK;
1562       x_return_status := fnd_api.g_ret_sts_unexp_error;
1563      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
1564 	THEN
1565 	 fnd_msg_pub.add_exc_msg
1566 	   (  g_pkg_name
1567 	      , 'update_loc_sugg_capacity_nauto'
1568 	      );
1569 	END IF;
1570      fnd_msg_pub.count_and_get
1571 	( p_count => x_msg_count,
1572 	  p_data  => x_msg_data
1573 	  );
1574 END update_loc_sugg_capacity_nauto;
1575 
1576 -- This API updates the suggested volume, weight and units capacity of a locator when items are
1577 -- received in the locator.  Suggestions are only receipt suggestions.
1578 -- An autonomous commit is done in the end.
1579 PROCEDURE update_loc_suggested_capacity
1580   ( x_return_status             OUT NOCOPY VARCHAR2, -- return status (success/error/unexpected_error)
1581     x_msg_count                 OUT NOCOPY NUMBER,   -- number of messages in the message queue
1582     x_msg_data                  OUT NOCOPY VARCHAR2, -- message text when x_msg_count>0
1583     p_organization_id           IN  NUMBER,   -- org of locator whose capacity is to be determined
1584     p_inventory_location_id     IN  NUMBER,   -- identifier of locator
1585     p_inventory_item_id         IN  NUMBER,   -- identifier of item
1586     p_primary_uom_flag          IN  VARCHAR2, -- 'Y' - transaction was in item's primary UOM
1587 					      -- 'N' - transaction was NOT in item's primary UOM
1588 					      --       or the information is not known
1589     p_transaction_uom_code      IN  VARCHAR2, -- UOM of the transacted material that causes the
1590 					      -- locator capacity to get updated
1591     p_quantity                  IN  NUMBER   -- transaction quantity in p_transaction_uom_code
1592 
1593   )
1594 IS
1595      -- this whole function is an autonomous commit
1596      PRAGMA autonomous_transaction;
1597 
1598      l_return_status            varchar2(1);
1599      l_msg_count                number;
1600      l_msg_data                 varchar2(1000);
1601     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1602 BEGIN
1603 
1604    -- Initialize API return status to success
1605    x_return_status := FND_API.G_RET_STS_SUCCESS;
1606 
1607   inv_loc_wms_utils.update_loc_sugg_capacity_nauto
1608   ( x_return_status             => l_return_status,
1609     x_msg_count                 => x_msg_count,
1610     x_msg_data                  => x_msg_data,
1611     p_organization_id           => p_organization_id,
1612     p_inventory_location_id     => p_inventory_location_id,
1613     p_inventory_item_id         => p_inventory_item_id,
1614     p_primary_uom_flag          => p_primary_uom_flag,
1615     p_transaction_uom_code      => p_transaction_uom_code,
1616     p_quantity                  => p_quantity
1617   );
1618 
1619   IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
1620 	    IF (l_return_status = fnd_api.g_ret_sts_error) THEN
1621 		RAISE fnd_api.g_exc_error;
1622 	    ELSE
1623 		RAISE fnd_api.g_exc_unexpected_error;
1624 	    END IF;
1625   END IF;
1626 
1627   -- Update empty_flag, mixed_item_flag. Pass transaction action of receipt
1628   -- regardless of whether suggestion is receipt or transfer
1629 
1630   INV_LOC_WMS_UTILS.LOC_EMPTY_MIXED_FLAG (
1631     X_RETURN_STATUS 		=> l_return_status
1632   , X_MSG_COUNT     		=> x_msg_count
1633   , X_MSG_DATA      		=> x_msg_data
1634   , p_organization_id           => p_organization_id
1635   , p_inventory_location_id     => p_inventory_location_id
1636   , p_inventory_item_id         => p_inventory_item_id
1637   , P_TRANSACTION_ACTION_ID  	=> 27
1638   , P_TRANSFER_ORGANIZATION  	=> NULL
1639   , P_TRANSFER_LOCATION_ID   	=> NULL
1640   , P_SOURCE                 	=> null);
1641 
1642   IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
1643 	    IF (l_return_status = fnd_api.g_ret_sts_error) THEN
1644 		RAISE fnd_api.g_exc_error;
1645 	    ELSE
1646 		RAISE fnd_api.g_exc_unexpected_error;
1647 	    END IF;
1648   END IF;
1649 
1650   -- end of autonomous commit;
1651   COMMIT;
1652 EXCEPTION
1653 
1654    WHEN fnd_api.g_exc_error THEN
1655       ROLLBACK;
1656       x_return_status := fnd_api.g_ret_sts_error;
1657       fnd_msg_pub.count_and_get
1658 	( p_count => x_msg_count,
1659 	  p_data  => x_msg_data
1660 	 );
1661 
1662    WHEN fnd_api.g_exc_unexpected_error THEN
1663       ROLLBACK;
1664       x_return_status := fnd_api.g_ret_sts_unexp_error ;
1665        fnd_msg_pub.count_and_get
1666 	( p_count => x_msg_count,
1667 	  p_data  => x_msg_data
1668 	  );
1669 
1670    WHEN NO_DATA_FOUND THEN
1671       ROLLBACK;
1672      x_return_status := fnd_api.g_ret_sts_error;
1673 
1674    WHEN OTHERS THEN
1675       ROLLBACK;
1676       x_return_status := fnd_api.g_ret_sts_unexp_error;
1677      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
1678 	THEN
1679 	 fnd_msg_pub.add_exc_msg
1680 	   (  g_pkg_name
1681 	      , 'update_loc_suggested_capacity'
1682 	      );
1683 	END IF;
1684      fnd_msg_pub.count_and_get
1685 	( p_count => x_msg_count,
1686 	  p_data  => x_msg_data
1687 	  );
1688 END update_loc_suggested_capacity;
1689 
1690 -- This API reverts the updates of the suggested  volume, weight and units capacity of a locator
1691 -- when an error in suggested receipt happens.
1692 -- In other words, this API can be considered as issue suggestions (opposite of receipt suggestions)
1693 PROCEDURE revert_loc_suggested_cap_nauto
1694   ( x_return_status             OUT NOCOPY VARCHAR2, -- return status (success/error/unexpected_error)
1695     x_msg_count                 OUT NOCOPY NUMBER,   -- number of messages in the message queue
1696     x_msg_data                  OUT NOCOPY VARCHAR2, -- message text when x_msg_count>0
1697     p_organization_id           IN  NUMBER,   -- org of locator whose capacity is to be determined
1698     p_inventory_location_id     IN  NUMBER,   -- identifier of locator
1699     p_inventory_item_id         IN  NUMBER,   -- identifier of item
1700     p_primary_uom_flag          IN  VARCHAR2, -- 'Y' - transaction was in item's primary UOM
1701 					      -- 'N' - transaction was NOT in item's primary UOM
1702 					      --       or the information is not known
1703     p_transaction_uom_code      IN  VARCHAR2, -- UOM of the transacted material that causes the
1704 					      -- locator capacity to get updated
1705 					      -- Note: can be NULL if p_primary_uom_flag = 'Y'
1706     p_quantity                  IN  NUMBER    -- transaction quantity in p_transaction_uom_code
1707 
1708   )
1709   IS
1710 
1711      -- item attributes
1712      l_item_primary_uom_code     varchar2(3);
1713      l_item_weight_uom_code 	 varchar2(3);
1714      l_item_unit_weight		 number;
1715      l_item_volume_uom_code	 varchar2(3);
1716      l_item_unit_volume		 number;
1717      -- transaction attributes
1718      l_quantity                  NUMBER;  -- local variable to check that p_quantity always > 0
1719      l_primary_quantity	         number;
1720      l_transacted_weight	 number;
1721      l_transacted_volume	 number;
1722      -- converted transaction attributes
1723      l_loc_uom_xacted_weight	 number;
1724      l_loc_uom_xacted_volume	 number;
1725      -- location attributes in units
1726      l_max_units       	         number;
1727      l_current_units	         number;
1728      l_suggested_units	         number;
1729      l_available_units	         number;
1730      -- location attributes in weight
1731      l_location_weight_uom_code	 varchar2(3);
1732      l_max_weight		 number;
1733      l_current_weight		 number;
1734      l_suggested_weight		 number;
1735      l_available_weight 	 number;
1736      -- location attributes in volume
1737      l_volume_uom_code		 varchar2(3);
1738      l_max_cubic_area		 number;
1739      l_current_cubic_area	 number;
1740      l_suggested_cubic_area	 number;
1741      l_available_cubic_area	 number;
1742      -- updated capacity
1743      l_update_units		 boolean := TRUE;  -- always update units
1744      l_update_weight		 boolean := FALSE; -- only update if have location and item UOMs
1745      l_update_volume		 boolean := FALSE; -- only update if have location and item UOMs
1746      -- updated location
1747      l_upd_loc_suggested_units	number;
1748      l_upd_loc_available_units	number;
1749      l_upd_loc_suggested_weight	number;
1750      l_upd_loc_available_weight	number;
1751      l_upd_loc_suggested_volume	number;
1752      l_upd_loc_available_volume	number;
1753 
1754      l_physical_locator_id     NUMBER;
1755      l_locator_id              NUMBER;
1756      l_inventory_location_id   NUMBER;
1757 
1758      l_return_status           varchar2(1);
1759 
1760      l_loc_counter 	      NUMBER := 10000;
1761      l_locator_locked         BOOLEAN := TRUE;
1762      resource_busy_detected   EXCEPTION;
1763 
1764      PRAGMA EXCEPTION_INIT(resource_busy_detected, -54);
1765 
1766     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1767 BEGIN
1768    -- Initialize API return status to success
1769    x_return_status := FND_API.G_RET_STS_SUCCESS;
1770 
1771    SAVEPOINT revert_loc_suggested_cap_sp;--BUG 4890372
1772 
1773    IF (l_debug=1) THEN
1774       mdebug('Inside Procedure Revert Suggested Locator Capacity');
1775    END IF;
1776   /* If the locator has a physical_location_id
1777      then use the physical_location_id for further
1778      processing.Else we have to use the inventory_location_id
1779      for further processing
1780    */
1781    SELECT physical_location_id ,
1782 	  inventory_location_id
1783    INTO l_physical_locator_id,
1784 	l_locator_id
1785    FROM mtl_item_locations
1786    WHERE  inventory_location_id =p_inventory_location_id
1787        and organization_id = p_organization_id;
1788 
1789    IF l_physical_locator_id is null THEN
1790      l_inventory_location_id := l_locator_id;
1791    ELSE
1792      l_inventory_location_id := l_physical_locator_id;
1793    END IF;
1794 
1795    /*
1796    ############# If the locator capacity is infinite, then dont update anything, simply return#############
1797    */
1798    SELECT location_maximum_units, max_weight, max_cubic_area
1799    INTO l_max_units, l_max_weight, l_max_cubic_area
1800    FROM mtl_item_locations_kfv
1801    WHERE organization_id        = p_organization_id
1802      AND inventory_location_id  = l_inventory_location_id;
1803 
1804    IF l_max_units IS NULL AND l_max_weight IS NULL AND l_max_cubic_area IS NULL THEN
1805         return;
1806    END IF;
1807 
1808    -- Bug# 3067627
1809    IF (l_debug = 1) THEN
1810       mdebug('Before locking locator ' || l_inventory_location_id || ' in revert_loc_suggested_capacity');
1811    END IF;
1812 
1813    WHILE ((l_loc_counter > 0) and (l_locator_locked))
1814    LOOP
1815       BEGIN
1816 
1817          SELECT inventory_location_id INTO l_inventory_location_id
1818          FROM mtl_item_locations
1819          WHERE  inventory_location_id = l_inventory_location_id
1820          AND    organization_id = p_organization_id
1821          FOR UPDATE NOWAIT;
1822 
1823          IF (l_debug = 1) THEN
1824             mdebug('After locking locator ' || l_inventory_location_id || ' in revert_loc_suggested_capacity');
1825          END IF;
1826          l_locator_locked := FALSE;
1827 
1828 
1829        EXCEPTION
1830            WHEN resource_busy_detected THEN
1831                l_loc_counter := l_loc_counter - 1;
1832                IF (l_loc_counter = 0) THEN
1833                    mdebug('exception ora-00054 ' || ' in revert_loc_suggested_capacity');
1834                    x_msg_count := 1;
1835                    x_msg_data  := sqlerrm;
1836                    RAISE;
1837                ELSE
1838                   IF (l_debug = 1) THEN
1839                       mdebug('locking locator - Attempt:  ' || 10001-l_loc_counter || ' in revert_loc_suggested_capacity');
1840                   END IF;
1841                END IF;
1842            WHEN OTHERS THEN
1843                RAISE fnd_api.g_exc_unexpected_error;
1844        END;
1845    END LOOP;
1846 
1847 
1848 
1849    -- ensure that the input quantity (p_quantity) is always positive regardless whether
1850    -- issue or receipt
1851    l_quantity :=Abs(p_quantity);
1852    -- select necessary data from mtl_system_items and mtl_item_locations
1853    select
1854      primary_uom_code,
1855      weight_uom_code,
1856      unit_weight,
1857      volume_uom_code,
1858      unit_volume
1859    into
1860      l_item_primary_uom_code,
1861      l_item_weight_uom_code,
1862      l_item_unit_weight,
1863      l_item_volume_uom_code,
1864      l_item_unit_volume
1865    from mtl_system_items
1866    where organization_id 	= p_organization_id
1867    and   inventory_item_id 	= p_inventory_item_id;
1868 
1869    select
1870      location_maximum_units,
1871      location_current_units,
1872      location_suggested_units,
1873      location_available_units,
1874      location_weight_uom_code,
1875      max_weight,
1876      current_weight,
1877      suggested_weight,
1878      available_weight,
1879      volume_uom_code,
1880      max_cubic_area,
1881      current_cubic_area,
1882      suggested_cubic_area,
1883      available_cubic_area
1884    into
1885      l_max_units,
1886      l_current_units,
1887      l_suggested_units,
1888      l_available_units,
1889      l_location_weight_uom_code,
1890      l_max_weight,
1891      l_current_weight,
1892      l_suggested_weight,
1893      l_available_weight,
1894      l_volume_uom_code,
1895      l_max_cubic_area,
1896      l_current_cubic_area,
1897      l_suggested_cubic_area,
1898      l_available_cubic_area
1899      from mtl_item_locations
1900      where organization_id 	= p_organization_id
1901      and   inventory_location_id 	= l_inventory_location_id;
1902 
1903    -- Convert transaction quantity into primary quantity (l_primary_quantity) if needed
1904    -- Note: the p_primary_uom_flag is used when the transaction_uom is not known during
1905    -- running of the upgrade script
1906    IF (l_item_primary_uom_code <> p_transaction_uom_code)
1907      and (p_primary_uom_flag <> 'Y') then
1908 
1909 	l_primary_quantity :=
1910 		inv_convert.inv_um_convert( item_id 	  => p_inventory_item_id,
1911 					    precision	  => null,
1912 					    from_quantity => l_quantity,
1913 					    from_unit	  => p_transaction_uom_code,
1914 					    to_unit	  => l_item_primary_uom_code,
1915 					    from_name	  => null,
1916 					    to_name	  => null);
1917    ELSE
1918       l_primary_quantity := l_quantity;
1919   END IF;
1920 
1921   -- if have enough info, set update_weight flag to true:
1922   -- convert transacted item weight to transacted location weight (if necessary)
1923   -- and set l_update_weight flag to TRUE
1924   IF (l_item_unit_weight > 0 and
1925       l_item_weight_uom_code is not null and
1926       l_location_weight_uom_code is not NULL) then
1927 
1928 	l_transacted_weight := l_primary_quantity * l_item_unit_weight;
1929 
1930 	IF (l_item_weight_uom_code <> l_location_weight_uom_code) then
1931 	   l_loc_uom_xacted_weight :=
1932 		  inv_convert.inv_um_convert( item_id 	  => p_inventory_item_id,
1933 					    precision	  => null,
1934 					    from_quantity => l_transacted_weight,
1935 					    from_unit	  => l_item_weight_uom_code,
1936 					    to_unit	  => l_location_weight_uom_code,
1937 					    from_name	  => null,
1938 					    to_name	  => null) ;
1939 	ELSE
1940 	   l_loc_uom_xacted_weight := l_transacted_weight;
1941 	END IF;
1942 
1943 	l_update_weight := TRUE;
1944   END IF;
1945 
1946   --  if have enough info, set update_volume flag to true:
1947   --  convert transacted item volume to transacted location volume (if necessary)
1948   --  and set l_update_volume flag to TRUE
1949   IF (l_item_unit_volume > 0 and
1950       l_item_volume_uom_code is not null and
1951       l_volume_uom_code is not NULL) then
1952 
1953 
1954 	l_transacted_volume := l_primary_quantity * l_item_unit_volume;
1955 	-- make sure that transcated_volume > 0
1956 	IF (l_item_volume_uom_code <> l_volume_uom_code) then
1957 	   l_loc_uom_xacted_volume :=
1958 		  inv_convert.inv_um_convert( item_id 	  => p_inventory_item_id,
1959 					    precision	  => null,
1960 					    from_quantity => l_transacted_volume,
1961 					    from_unit	  => l_item_volume_uom_code,
1962 					    to_unit	  => l_volume_uom_code,
1963 					    from_name	  => null,
1964 					    to_name	  => null);
1965 	ELSE
1966 	   l_loc_uom_xacted_volume := l_transacted_volume;
1967 	END IF;
1968 
1969 	l_update_volume := TRUE;
1970   END IF;
1971 
1972   -- update suggested weight when issue
1973   IF (l_update_weight) then
1974      -- check that current_weight and suggested weight are not null or < 0
1975      -- if current_weight is null, drive current_weight to zero
1976      IF (l_current_weight IS NULL) OR (l_current_weight < 0) then
1977 	l_current_weight := 0;
1978      END IF;
1979      -- if suggested_weight is negative or null, set l_suggested_weight to zero
1980      IF (l_suggested_weight IS NULL) OR (l_suggested_weight < 0) then
1981 	l_suggested_weight := 0;
1982      END IF;
1983 
1984      -- when issue (take out of location), update suggested_weight
1985      -- Note: All suggestions are receipt suggestions, but this API is to correct
1986      -- an error in receipt.
1987      l_upd_loc_suggested_weight := l_suggested_weight - l_loc_uom_xacted_weight;
1988      -- update suggested_weight, and make sure that it is > 0
1989      IF (l_upd_loc_suggested_weight < 0) THEN
1990 	l_upd_loc_suggested_weight := 0;
1991      END IF;
1992      -- if max not defined, let available_weight be undefined
1993      -- assume that max_weight > 0 (the Form takes care of this)
1994      IF (l_max_weight IS NULL) THEN
1995 	l_upd_loc_available_weight :=  NULL;
1996       ELSE
1997 	-- update available weight, and make sure that it is > 0
1998 	l_upd_loc_available_weight := l_max_weight
1999 	  - (l_upd_loc_suggested_weight + l_current_weight);
2000 	IF (l_upd_loc_available_weight < 0) THEN
2001 	   l_upd_loc_available_weight := 0;
2002 	END IF;
2003      END IF;
2004    ELSE
2005      -- if weight not updated, just propagate current suggested weight
2006      l_upd_loc_suggested_weight := l_suggested_weight;
2007      l_upd_loc_available_weight := l_available_weight;
2008   END IF;
2009 
2010    -- update suggested volume; Note: volume = cubic area
2011   IF (l_update_volume) then
2012      -- check that current_volume and suggested volume are not null or < 0
2013      -- if current_volume is null, drive current_volume to zero
2014      IF (l_current_cubic_area IS NULL) OR (l_current_cubic_area < 0) then
2015 	l_current_cubic_area := 0;
2016      END IF;
2017      -- if suggested_volume is negative or null, set l_suggested_volume to zero
2018      IF (l_suggested_cubic_area IS NULL) OR (l_suggested_cubic_area < 0) then
2019 	l_suggested_cubic_area := 0;
2020      END IF;
2021 
2022      -- when issue (put into location)
2023      -- Note: All suggestions are receipt suggestions, but this API
2024      -- corrects an error in the receipt suggestion - hence an issue.
2025      l_upd_loc_suggested_volume := l_suggested_cubic_area - l_loc_uom_xacted_volume;
2026      -- update suggested_volume, and make sure that it is > 0
2027      IF (l_upd_loc_suggested_volume < 0) THEN
2028 	l_upd_loc_suggested_volume := 0;
2029      END IF;
2030      -- if max not defined, let available_volume be undefined
2031      -- assume that max_volume > 0 (the Form takes care of this)
2032      IF (l_max_cubic_area IS NULL) THEN
2033 	l_upd_loc_available_volume :=  NULL;
2034       ELSE
2035 	-- update available volume, and make sure that it is > 0
2036 	l_upd_loc_available_volume := l_max_cubic_area
2037 	  - (l_upd_loc_suggested_volume + l_current_cubic_area);
2038 	IF (l_upd_loc_available_volume < 0) THEN
2039 	   l_upd_loc_available_volume := 0;
2040 	END IF;
2041      END IF;
2042    ELSE
2043      -- if volume not updated, just propagate current suggested volume
2044      l_upd_loc_suggested_volume := l_suggested_cubic_area;
2045      l_upd_loc_available_volume := l_available_cubic_area;
2046   END IF;
2047 
2048  -- update current units
2049   IF (l_update_units) then
2050     -- check that current_units and suggested units are not null or < 0
2051      -- if current_units is null, drive current_units to zero
2052      IF (l_current_units IS NULL) OR (l_current_units < 0) then
2053 	l_current_units := 0;
2054      END IF;
2055      -- if suggested_units is negative or null, set l_suggested_units to zero
2056      IF (l_suggested_units IS NULL) OR (l_suggested_units < 0) then
2057 	l_suggested_units := 0;
2058      END IF;
2059 
2060      -- when issue (put into location), update suggested_units
2061      -- Note: All suggestions are receipt suggestions, but this API
2062      -- corrects error in receipt suggestions - hence, issue suggestions
2063      l_upd_loc_suggested_units := l_suggested_units - l_primary_quantity;
2064      -- update suggested_units, and make sure that it is > 0
2065      IF (l_upd_loc_suggested_units < 0) THEN
2066 	l_upd_loc_suggested_units := 0;
2067      END IF;
2068      -- if max not defined, let available_units be undefined
2069      -- assume that max_units > 0 (the Form takes care of this)
2070      IF (l_max_units IS NULL) THEN
2071 	l_upd_loc_available_units :=  NULL;
2072       ELSE
2073 	-- update available units, and make sure that it is > 0
2074 	l_upd_loc_available_units := l_max_units
2075 	  - (l_upd_loc_suggested_units + l_current_units);
2076 	IF (l_upd_loc_available_units < 0) THEN
2077 	   l_upd_loc_available_units := 0;
2078 	END IF;
2079      END IF;
2080    ELSE
2081      -- if units not updated, just propagate current suggested units
2082      l_upd_loc_suggested_units := l_suggested_units;
2083      l_upd_loc_available_units := l_available_units;
2084   END IF;
2085 
2086   -- Now we update the table MTL_ITEM_LOCATIONS
2087   IF (l_update_weight) OR (l_update_volume) OR (l_update_units) THEN
2088      UPDATE mtl_item_locations
2089        SET
2090        location_suggested_units 	= l_upd_loc_suggested_units,
2091        location_available_units 	= l_upd_loc_available_units,
2092        suggested_weight             	= l_upd_loc_suggested_weight,
2093        available_weight		        = l_upd_loc_available_weight,
2094        suggested_cubic_area		= l_upd_loc_suggested_volume,
2095        available_cubic_area 		= l_upd_loc_available_volume
2096        where inventory_location_id = l_inventory_location_id
2097        and   organization_id       = p_organization_id;
2098   END IF;
2099 
2100   -- Update empty_flag, mixed_item_flag. Pass transaction action of issue
2101 
2102   INV_LOC_WMS_UTILS.LOC_EMPTY_MIXED_FLAG (
2103     X_RETURN_STATUS             => l_return_status
2104   , X_MSG_COUNT                 => x_msg_count
2105   , X_MSG_DATA                  => x_msg_data
2106   , p_organization_id           => p_organization_id
2107   , p_inventory_location_id     => l_inventory_location_id
2108   , p_inventory_item_id         => p_inventory_item_id
2109   , P_TRANSACTION_ACTION_ID     => 1
2110   , P_TRANSFER_ORGANIZATION     => NULL
2111   , P_TRANSFER_LOCATION_ID      => NULL
2112   , P_SOURCE                    => null);
2113 
2114   IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
2115             IF (l_return_status = fnd_api.g_ret_sts_error) THEN
2116                 RAISE fnd_api.g_exc_error;
2117             ELSE
2118                 RAISE fnd_api.g_exc_unexpected_error;
2119             END IF;
2120   END IF;
2121 
2122 
2123 EXCEPTION
2124 
2125    WHEN fnd_api.g_exc_error THEN
2126       ROLLBACK TO revert_loc_suggested_cap_sp;--BUG 4890372
2127       x_return_status := fnd_api.g_ret_sts_error;
2128       fnd_msg_pub.count_and_get
2129 	( p_count => x_msg_count,
2130 	  p_data  => x_msg_data
2131 	 );
2132 
2133    WHEN fnd_api.g_exc_unexpected_error THEN
2134       ROLLBACK TO revert_loc_suggested_cap_sp;--BUG 4890372
2135       x_return_status := fnd_api.g_ret_sts_unexp_error ;
2136        fnd_msg_pub.count_and_get
2137 	( p_count => x_msg_count,
2138 	  p_data  => x_msg_data
2139 	  );
2140 
2141    WHEN NO_DATA_FOUND THEN
2142      ROLLBACK TO revert_loc_suggested_cap_sp;--BUG 4890372
2143      x_return_status := fnd_api.g_ret_sts_error;
2144 
2145    WHEN resource_busy_detected  THEN
2146      ROLLBACK TO revert_loc_suggested_cap_sp;--BUG 4890372
2147      x_return_status := fnd_api.g_ret_sts_error;
2148 
2149    WHEN OTHERS THEN
2150       ROLLBACK TO revert_loc_suggested_cap_sp;--BUG 4890372
2151       x_return_status := fnd_api.g_ret_sts_unexp_error;
2152      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
2153 	THEN
2154 	 fnd_msg_pub.add_exc_msg
2155 	   (  g_pkg_name
2156 	      , 'revert_loc_suggested_capacity'
2157 	      );
2158 	END IF;
2159      fnd_msg_pub.count_and_get
2160 	( p_count => x_msg_count,
2161 	  p_data  => x_msg_data
2162 	  );
2163 END revert_loc_suggested_cap_nauto;
2164 
2165 PROCEDURE revert_loc_suggested_capacity
2166   ( x_return_status             OUT NOCOPY VARCHAR2, -- return status (success/error/unexpected_error)
2167     x_msg_count                 OUT NOCOPY NUMBER,   -- number of messages in the message queue
2168     x_msg_data                  OUT NOCOPY VARCHAR2, -- message text when x_msg_count>0
2169     p_organization_id           IN  NUMBER,   -- org of locator whose capacity is to be determined
2170     p_inventory_location_id     IN  NUMBER,   -- identifier of locator
2171     p_inventory_item_id         IN  NUMBER,   -- identifier of item
2172     p_primary_uom_flag          IN  VARCHAR2, -- 'Y' - transaction was in item's primary UOM
2173 					      -- 'N' - transaction was NOT in item's primary UOM
2174 					      --       or the information is not known
2175     p_transaction_uom_code      IN  VARCHAR2, -- UOM of the transacted material that causes the
2176 					      -- locator capacity to get updated
2177 					      -- Note: can be NULL if p_primary_uom_flag = 'Y'
2178     p_quantity                  IN  NUMBER    -- transaction quantity in p_transaction_uom_code
2179 
2180   )
2181   IS
2182 	-- this whole function is an autonomous commit
2183 
2184      PRAGMA autonomous_transaction;
2185 BEGIN
2186    revert_loc_suggested_cap_nauto
2187      (
2188       x_return_status => x_return_status,
2189       x_msg_count => x_msg_count,
2190       x_msg_data => x_msg_data,
2191       p_organization_id => p_organization_id,
2192       p_inventory_location_id => p_inventory_location_id,
2193       p_inventory_item_id => p_inventory_item_id,
2194       p_primary_uom_flag => p_primary_uom_flag,
2195       p_transaction_uom_code => p_transaction_uom_code,
2196       p_quantity => p_quantity
2197      );
2198 
2199    COMMIT;
2200 
2201 END revert_loc_suggested_capacity;
2202 
2203 
2204 PROCEDURE fetch_lpn_content_qty
2205    (
2206      p_lpn_id        IN          NUMBER
2207    , x_quantity      OUT NOCOPY  NUMBER
2208    )
2209 IS
2210 BEGIN
2211    SELECT nvl(sum(wlc.primary_quantity),0) /* Bug 5689378 */
2212      INTO x_quantity
2213      FROM wms_lpn_contents wlc
2214         , wms_license_plate_numbers wlpn
2215     WHERE wlc.parent_lpn_id = wlpn.lpn_id
2216       AND wlpn.outermost_lpn_id = p_lpn_id;
2217 END fetch_lpn_content_qty;
2218 
2219 PROCEDURE get_container_capacity
2220   (   x_return_status             OUT NOCOPY VARCHAR2
2221     , x_msg_count                 OUT NOCOPY NUMBER
2222     , x_msg_data                  OUT NOCOPY VARCHAR2
2223     , p_locator_weight_uom        IN         VARCHAR2
2224     , p_locator_volume_uom        IN         VARCHAR2
2225     , p_lpn_id                    IN         NUMBER
2226     , p_organization_id           IN         NUMBER
2227     , x_container_item_wt         OUT NOCOPY NUMBER
2228     , x_container_item_vol        OUT NOCOPY NUMBER
2229     , x_lpn_gross_weight          OUT NOCOPY NUMBER
2230     , x_lpn_content_vol           OUT NOCOPY NUMBER
2231   )
2232 IS
2233    l_lpn_gross_weight_uom_code   VARCHAR2(3);
2234    l_lpn_content_volume_uom_code VARCHAR2(3);
2235    l_lpn_gross_weight            NUMBER;
2236    l_lpn_content_volume          NUMBER;
2237    l_lpn_container_item_weight   NUMBER;
2238    l_lpn_container_item_vol      NUMBER;
2239    l_dummy                       VARCHAR2(1);
2240    l_lpn_weight                  NUMBER   := 0;
2241    l_gross_weight                NUMBER   := 0;
2242    l_lpn_volume                  NUMBER   := 0;
2243    l_content_volume              NUMBER   := 0;
2244    l_prog_name                   VARCHAR2(40) := 'get_container_capacity';
2245 BEGIN
2246    INV_LOC_WMS_UTILS.lpn_attributes(
2247      x_return_status            =>   x_return_status
2248    , x_msg_data                 =>   x_msg_data
2249    , x_msg_count                =>   x_msg_count
2250    , x_gross_weight_uom_code    =>   l_lpn_gross_weight_uom_code
2251    , x_content_volume_uom_code  =>   l_lpn_content_volume_uom_code
2252    , x_gross_weight             =>   l_lpn_gross_weight
2253    , x_content_volume           =>   l_lpn_content_volume
2254    , x_container_item_weight    =>   l_lpn_container_item_weight
2255    , x_container_item_vol       =>   l_lpn_container_item_vol
2256    , x_lpn_exists_in_locator    =>   l_dummy
2257    , p_lpn_id                   =>   p_lpn_id
2258    , p_org_id                   =>   p_organization_id
2259    );
2260    -- Compute gross Weight
2261    if ((p_locator_weight_uom is not null) and
2262        (l_lpn_gross_weight_uom_code is not NULL)) then
2263 
2264       l_gross_weight := nvl(l_lpn_gross_weight,0);
2265        if (l_lpn_gross_weight_uom_code <>
2266            p_locator_weight_uom) then
2267 
2268         l_gross_weight :=
2269           inv_convert.inv_um_convert(
2270             item_id       => NULL,
2271             precision     => null,
2272             from_quantity => nvl(l_lpn_gross_weight,0),
2273             from_unit     => l_lpn_gross_weight_uom_code,
2274             to_unit       => p_locator_weight_uom,
2275             from_name     => null,
2276             to_name       => null) ;
2277        end if;
2278 
2279        IF l_gross_weight = -99999 THEN
2280           RAISE fnd_api.g_exc_error;
2281        END IF;
2282    end if;
2283 
2284    -- Compute content Volume
2285    if ((p_locator_volume_uom is not null) and
2286        (l_lpn_content_volume_uom_code is not null)) then
2287        l_content_volume := nvl(l_lpn_content_volume,0);
2288        if (l_lpn_content_volume_uom_code <>
2289            p_locator_volume_uom) then
2290 
2291         l_content_volume :=
2292           inv_convert.inv_um_convert(
2293             item_id       => NULL,
2294             precision     => null,
2295             from_quantity => nvl(l_lpn_content_volume,0),
2296             from_unit     => l_lpn_content_volume_uom_code,
2297             to_unit       => p_locator_volume_uom,
2298             from_name     => null,
2299             to_name       => null) ;
2300        end if;
2301 
2302        IF l_content_volume = -99999 THEN
2303           RAISE fnd_api.g_exc_error;
2304        END IF;
2305    end if;
2306 
2307    -- Compute container Weight
2308    if ((p_locator_weight_uom is not null) and
2309        (l_lpn_gross_weight_uom_code is not NULL)) then
2310        l_lpn_weight := nvl(l_lpn_container_item_weight,0);
2311        if (l_lpn_gross_weight_uom_code <>
2312            p_locator_weight_uom) then
2313 
2314         l_lpn_weight :=
2315           inv_convert.inv_um_convert(
2316             item_id       => NULL,
2317             precision     => null,
2318             from_quantity => nvl(l_lpn_container_item_weight,0),
2319             from_unit     => l_lpn_gross_weight_uom_code,
2320             to_unit       => p_locator_weight_uom,
2321             from_name     => null,
2322             to_name       => null) ;
2323        end if;
2324 
2325        IF l_lpn_weight = -99999 THEN
2326           RAISE fnd_api.g_exc_error;
2327        END IF;
2328    end if;
2329 
2330    -- Compute container Volume
2331    if ((p_locator_volume_uom is not null) and
2332        (l_lpn_content_volume_uom_code is not null)) then
2333        l_lpn_volume := nvl(l_lpn_container_item_vol,0);
2334        if (l_lpn_content_volume_uom_code <>
2335            p_locator_volume_uom) then
2336 
2337         l_lpn_volume :=
2338           inv_convert.inv_um_convert(
2339             item_id       => NULL,
2340             precision     => null,
2341             from_quantity => nvl(l_lpn_container_item_vol,0),
2342             from_unit     => l_lpn_content_volume_uom_code,
2343             to_unit       => p_locator_volume_uom,
2344             from_name     => null,
2345             to_name       => null) ;
2346        end if;
2347 
2348        IF l_lpn_volume = -99999 THEN
2349           RAISE fnd_api.g_exc_error;
2350        END IF;
2351    end if;
2352    x_container_item_wt  := l_lpn_weight;
2353    x_container_item_vol := l_lpn_volume;
2354    x_lpn_gross_weight   := l_gross_weight;
2355    x_lpn_content_vol    := l_content_volume;
2356    mdebug(l_prog_name||'container wt  :'||x_container_item_wt);
2357    mdebug(l_prog_name||'container vol :'||x_container_item_vol);
2358 EXCEPTION
2359 
2360  WHEN fnd_api.g_exc_error THEN
2361       x_return_status := fnd_api.g_ret_sts_error;
2362       fnd_msg_pub.count_and_get
2363 	( p_count => x_msg_count,
2364 	  p_data  => x_msg_data
2365 	 );
2366 
2367    WHEN fnd_api.g_exc_unexpected_error THEN
2368       x_return_status := fnd_api.g_ret_sts_unexp_error ;
2369        fnd_msg_pub.count_and_get
2370 	( p_count => x_msg_count,
2371 	  p_data  => x_msg_data
2372 	  );
2373 
2374    WHEN NO_DATA_FOUND THEN
2375      x_return_status := fnd_api.g_ret_sts_error;
2376 
2377    WHEN OTHERS THEN
2378       x_return_status := fnd_api.g_ret_sts_unexp_error;
2379      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
2380 	THEN
2381 	 fnd_msg_pub.add_exc_msg
2382 	   (  g_pkg_name,
2383 	      'get_container_capacity'
2384 	      );
2385 	END IF;
2386      fnd_msg_pub.count_and_get
2387 	( p_count => x_msg_count,
2388 	  p_data  => x_msg_data
2389 	  );
2390 END get_container_capacity;
2391 
2392 
2393 
2394 -- This is an upgrade script that updates the locator's current capacity information
2395 -- corresponding to each onhand quantity (or mmtt) record
2396 
2397 PROCEDURE locators_capacity_cleanup
2398   (  x_return_status             OUT NOCOPY VARCHAR2 -- return status
2399    , x_msg_count                 OUT NOCOPY NUMBER   -- number of messages in the message queue
2400    , x_msg_data                  OUT NOCOPY VARCHAR2 -- message text when x_msg_count>0
2401    , p_organization_id           IN         NUMBER
2402    , p_mixed_flag                IN         VARCHAR2
2403    , p_subinventory              IN         VARCHAR2 DEFAULT NULL
2404    , p_locator_id                IN         NUMBER   DEFAULT NULL
2405     )
2406   IS
2407      l_prog_name   VARCHAR2(40) := 'locators_capacity_cleanup:';
2408 
2409      TYPE t_number         is table of number       index by binary_integer;
2410      TYPE t_varchar2       is table of varchar2(10) index by binary_integer;
2411      TYPE t_varchar2_small is table of varchar2(10) index by binary_integer;
2412 
2413      /* Locator CACHE */
2414      t_locator                  t_number;
2415      t_subinventory_code        t_varchar2;
2416      t_location_weight_uom_code t_varchar2;
2417      t_volume_uom_code          t_varchar2;
2418      t_location_maximum_units   t_number;
2419      t_max_weight               t_number;
2420      t_max_cubic_area           t_number;
2421 
2422      t_location_current_units   t_number;
2423      t_location_suggested_units t_number;
2424      t_location_available_units t_number;
2425      t_current_weight           t_number;
2426      t_suggested_weight         t_number;
2427      t_available_weight         t_number;
2428      t_current_cubic_area       t_number;
2429      t_suggested_cubic_area     t_number;
2430      t_available_cubic_area     t_number;
2431      t_inventory_item_id        t_number;
2432      t_empty_flag               t_varchar2_small;
2433      t_mixed_items_flag         t_varchar2_small;
2434 
2435      /* Item Cache */
2436      TYPE r_item_info is record(
2437          inventory_item_id        number
2438        , item_primary_uom_code    varchar2(10)
2439        , item_weight_uom_code     varchar2(10)
2440        , item_unit_weight         number
2441        , item_volume_uom_code     varchar2(10)
2442        , item_unit_volume         number);
2443 
2444      TYPE t_item_info_type is table of r_item_info index by binary_integer;
2445 
2446      t_item_info t_item_info_type;
2447 
2448      /* LPN Cache */
2449      TYPE r_lpn_info IS RECORD (
2450          lpn_id                  NUMBER
2451        , gross_weight_uom_code   VARCHAR2(3)
2452        , content_volume_uom_code VARCHAR2(3)
2453        , gross_weight            NUMBER := 0
2454        , content_volume          NUMBER := 0
2455        , container_item_weight   NUMBER := 0
2456        , container_item_vol      NUMBER := 0
2457        , lpn_exists_in_locator   VARCHAR2(1) := 'N'
2458        , lpn_already_considered  VARCHAR2(1) := 'N'
2459      );
2460 
2461      TYPE t_lpn_info_type IS TABLE OF r_lpn_info INDEX BY BINARY_INTEGER;
2462 
2463      t_lpn_info  t_lpn_info_type;
2464      l_content_lpn_volume NUMBER := 0;
2465 
2466 
2467      /* Item Locator Cache - number of units of item in locator */
2468      TYPE r_item_units is record(
2469          inventory_item_id        number
2470        , location_current_units   number
2471        , location_suggested_units number);
2472 
2473      TYPE t_item_units_type is table of r_item_units index by binary_integer;
2474 
2475      t_item_units t_item_units_type;
2476 
2477      l_record_source            varchar2(40);
2478      l_inventory_item_id        number;
2479      l_transaction_quantity     number;
2480      l_containerized_flag       number;
2481      l_transaction_action_id    number;
2482      l_transfer_lpn_id          number;
2483      l_content_lpn_id           number;
2484      l_lpn_id                   number;
2485      l_transaction_status       number;
2486 
2487      l_return_status            varchar2(1);
2488      l_msg_count                number;
2489      l_msg_data                 varchar2(1000);
2490 
2491      l_locator_id               number;
2492      l_subinventory_code        varchar2(10);
2493 
2494      l_loop_count               number;
2495      l_bulk_count               number;
2496      l_count                    number;
2497      l_index                    number;
2498 
2499      l_transacted_weight        number;
2500      l_transacted_volume        number;
2501 
2502      l_item_id                  number;
2503 
2504      l_lpn_weight               NUMBER;
2505      l_lpn_volume               NUMBER;
2506      l_cnt_lpn_qty              NUMBER;
2507 
2508      --Variables for addressing the Bug 4333758
2509      l_allocated_txn_status     NUMBER := 2 ;
2510 
2511      l_txn_action_int_rcpt      NUMBER := INV_GLOBALS.G_ACTION_INTRANSITRECEIPT /* 12 */;
2512      l_txn_action_rcpt          NUMBER := INV_GLOBALS.G_ACTION_RECEIPT /* 27 */ ;
2513      l_txn_action_subxfer       NUMBER := INV_GLOBALS.G_ACTION_SUBXFR /* 2 */ ;
2514      l_txn_action_orgxfer       NUMBER := INV_GLOBALS.G_ACTION_ORGXFR /* 3 */ ;
2515      l_txn_action_stgxfer       NUMBER := INV_GLOBALS.G_ACTION_STGXFR /* 28 */ ;
2516      --Variables for addressing the Bug 4333758
2517 
2518      cursor c_all_locators(p_locator_id NUMBER,p_subinventory VARCHAR2) is
2519      select inventory_location_id,
2520             subinventory_code,
2521             location_weight_uom_code,
2522             volume_uom_code,
2523             location_maximum_units,
2524             max_weight,
2525             max_cubic_area
2526      from   mtl_item_locations
2527      where organization_id = p_organization_id
2528        AND subinventory_code = nvl(p_subinventory,subinventory_code)
2529        --Bug #3949621 (Changed the query, because for PJM Orgs, Physical Location Id won't be null)
2530        AND nvl(physical_location_id,inventory_location_id) = nvl(p_locator_id ,nvl(physical_location_id,inventory_location_id) );
2531      /*
2532        AND inventory_location_id = nvl(p_locator_id,inventory_location_id)
2533        AND physical_location_id IS NULL;
2534      */
2535 
2536      cursor c_onhand(l_locator_id NUMBER, l_subinventory VARCHAR2) is
2537        /* Get MOQ */
2538      SELECT
2539            'MOQ_RECORD'                       record_source,
2540            moq.inventory_item_id              inventory_item_id,
2541            moq.primary_transaction_quantity   transaction_quantity,
2542            moq.containerized_flag             containerized_flag,
2543            TO_NUMBER(NULL)                    transaction_action_id,
2544            TO_NUMBER(NULL)                    transfer_lpn_id,
2545            TO_NUMBER(NULL)                    content_lpn_id,
2546          --TO_NUMBER(NULL)                    lpn_id,
2547          --moq.lpn_id                         lpn_id,
2548            wlpn.outermost_lpn_id              lpn_id,
2549            TO_NUMBER(NULL)                    transaction_status
2550      FROM MTL_ONHAND_QUANTITIES_DETAIL  MOQ,
2551           mtl_item_locations mil,
2552           wms_license_plate_numbers wlpn
2553      WHERE moq.locator_id        = mil.inventory_location_id
2554      AND   mil.organization_id   = moq.organization_id
2555      AND   mil.subinventory_code = moq.subinventory_code
2556      AND   nvl(mil.physical_location_id,mil.inventory_location_id) = l_locator_id
2557      AND   moq.organization_id      = p_organization_id
2558      AND   moq.subinventory_code    = l_subinventory_code
2559      AND   moq.locator_id           = l_locator_id --Added to address Bug 4333758
2560      AND   moq.transaction_quantity > 0
2561      AND   moq.lpn_id = wlpn.lpn_id(+)
2562 
2563      UNION ALL
2564 
2565      /*
2566      ** We want all transactions that are pending. And we want all Putaway
2567      ** suggestions. However, we are dealing with just the Source location/sub
2568      ** in this side of the UNION.
2569      */
2570      SELECT
2571            'MMTT_SOURCE_LOCATOR_RECORD'          record_source
2572           , mmtt.inventory_item_id               inventory_item_id
2573           , mmtt.primary_quantity                transaction_quantity
2574           , TO_NUMBER(NULL)                      containerized_flag
2575           , mmtt.transaction_action_id           transaction_action_id
2576           , mmtt.transfer_lpn_id                 transfer_lpn_id
2577           , mmtt.content_lpn_id                  content_lpn_id
2578           , mmtt.lpn_id                          lpn_id
2579           , transaction_status                   transaction_status
2580      FROM mtl_material_transactions_temp mmtt,
2581           mtl_item_locations mil
2582      WHERE mmtt.locator_id        = mil.inventory_location_id
2583      AND   mil.organization_id    = mmtt.organization_id
2584      AND   mil.subinventory_code  = mmtt.subinventory_code
2585      AND   nvl(mil.physical_location_id,mil.inventory_location_id) = l_locator_id
2586      AND   mmtt.organization_id   = p_organization_id
2587      AND   mmtt.subinventory_code = l_subinventory_code
2588      AND   mmtt.locator_id        = l_locator_id --Added to address Bug 4333758
2589      AND   mmtt.posting_flag      = 'Y'
2590      AND ( Nvl(mmtt.transaction_status,0) <> l_allocated_txn_status  OR -- pending txns
2591               -- only receipt suggested transactions are used
2592             (Nvl(mmtt.transaction_status,0) = l_allocated_txn_status  AND
2593                  mmtt.transaction_action_id IN (l_txn_action_int_rcpt , l_txn_action_rcpt ))
2594           )
2595 
2596      UNION ALL
2597 
2598      /*
2599      ** We want all pending transactions and suggestions that are sub transfers.
2600      ** However, we only deal with the destination sub/locator in this side of UNION.
2601      */
2602      SELECT
2603             'MMTT_DESTINATION_LOCATOR_RECORD'    record_source
2604           , mmtt.inventory_item_id               inventory_item_id
2605           , mmtt.primary_quantity                transaction_quantity
2606           , TO_NUMBER(NULL)                      containerized_flag
2607           , mmtt.transaction_action_id           transaction_action_id
2608           , mmtt.transfer_lpn_id                 transfer_lpn_id
2609           , mmtt.content_lpn_id                  content_lpn_id
2610           , mmtt.lpn_id                          lpn_id
2611           , transaction_status                   transaction_status
2612      FROM mtl_material_transactions_temp mmtt,
2613           mtl_item_locations mil
2614      WHERE mmtt.transfer_to_location = mil.inventory_location_id
2615      AND   mil.organization_id       = mmtt.organization_id
2616      AND   mil.subinventory_code     = mmtt.transfer_subinventory--bug 6110275 for destination locator
2617      AND   nvl(mil.physical_location_id,mil.inventory_location_id) = l_locator_id
2618      AND   mmtt.organization_id         = p_organization_id
2619      AND   mmtt.transfer_subinventory   = l_subinventory_code
2620      AND   mmtt.transfer_to_location    = l_locator_id --Added to address Bug 4333758
2621      AND   mmtt.posting_flag            = 'Y'
2622      AND   mmtt.transaction_action_id IN (l_txn_action_subxfer , l_txn_action_orgxfer, l_txn_action_stgxfer );
2623 
2624      l_commit_count number := 0;
2625 
2626     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2627 BEGIN
2628    -- Initialize API return status to success
2629    x_return_status := FND_API.G_RET_STS_SUCCESS;
2630    SAVEPOINT locators_capacity_cleanup;
2631 
2632    IF (l_debug = 1) THEN
2633       mdebug(l_prog_name||'Start Locator_Capacity_Clean_Up');
2634    END IF;
2635 
2636    /**************************************************************************************************
2637     * Open cursor to fetch all the physical locators. (Logical locators are not fetched as capacity
2638     * is considered at the physical locator level only.
2639     **************************************************************************************************/
2640    if not c_all_locators%isopen then
2641         open c_all_locators(p_locator_id,p_subinventory);
2642    end if;
2643 
2644    IF (l_debug = 1) THEN
2645       mdebug(l_prog_name||'Open c_all_locators Locator_Capacity_Clean_Up');
2646    END IF;
2647 
2648    l_loop_count := 0;
2649    l_bulk_count := 0;
2650 
2651    loop
2652         /* Empty PL/SQL tables */
2653         t_locator.delete;
2654         t_subinventory_code.delete;
2655         t_location_weight_uom_code.delete;
2656         t_volume_uom_code.delete;
2657         t_location_maximum_units.delete;
2658         t_max_weight.delete;
2659         t_max_cubic_area.delete;
2660 
2661         t_location_current_units.delete;
2662         t_location_suggested_units.delete;
2663         t_location_available_units.delete;
2664         t_current_weight.delete;
2665         t_suggested_weight.delete;
2666         t_available_weight.delete;
2667         t_current_cubic_area.delete;
2668         t_suggested_cubic_area.delete;
2669         t_available_cubic_area.delete;
2670         t_inventory_item_id.delete;
2671         t_empty_flag.delete;
2672         t_mixed_items_flag.delete;
2673 
2674         -- Fetch 500 locators at a time
2675         fetch c_all_locators bulk collect into
2676             t_locator
2677           , t_subinventory_code
2678           , t_location_weight_uom_code
2679           , t_volume_uom_code
2680           , t_location_maximum_units
2681           , t_max_weight
2682           , t_max_cubic_area
2683             limit 500;
2684 
2685         l_loop_count := c_all_locators%rowcount - l_bulk_count;
2686 
2687         -- Loop thru each locator
2688         for i in 1..l_loop_count
2689         loop
2690            l_locator_id         := t_locator(i);
2691            l_subinventory_code  := t_subinventory_code(i);
2692 
2693            -- Initialize
2694            t_location_current_units(i)   := 0;
2695            t_location_suggested_units(i) := 0;
2696            t_current_weight(i)           := 0;
2697            t_suggested_weight(i)         := 0;
2698            t_current_cubic_area(i)       := 0;
2699            t_suggested_cubic_area(i)     := 0;
2700            t_inventory_item_id(i)        := 0;
2701            t_empty_flag(i)               := null;
2702            t_mixed_items_flag(i)         := null;
2703 
2704            -- Initialize Item Locator cache
2705            t_item_units.delete;
2706 
2707            /********************************************************************************************
2708             * Get the ON Hand for all locators having this as physical locator. This is needed because
2709             * onhand is maintained even at logical locator level. so, we need to get all the locators
2710             * in MOQD and MMTT for which
2711                  1. The physical location is null and the inventory location is the choosen locator.
2712                  2. The physical location is not null. (for logical locator), and it is equal to the
2713                     locator choosen.
2714             * See the Cursor definition.
2715             ********************************************************************************************/
2716            open c_onhand(t_locator(i),t_subinventory_code(i));
2717            LOOP
2718                 Fetch  c_onhand into
2719                  l_record_source,
2720                  l_inventory_item_id,
2721                  l_transaction_quantity,
2722                  l_containerized_flag,
2723                  l_transaction_action_id,
2724                  l_transfer_lpn_id,
2725                  l_content_lpn_id,
2726                  l_lpn_id,
2727                  l_transaction_status;
2728 
2729                  EXIT WHEN c_onhand%NOTFOUND;
2730 
2731                  /*****************************************************************************
2732                   * Inventory item id will be -1 if the content_lpn_id is not null
2733                   *****************************************************************************/
2734                 if (l_inventory_item_id > 0) then
2735                    if NOT(t_item_info.exists(l_inventory_item_id)) then
2736 
2737                         -- Item doesn't exist in cache. Hit the DB.
2738                         select
2739                           inventory_item_id
2740                         , primary_uom_code
2741                         , weight_uom_code
2742                         , unit_weight
2743                         , volume_uom_code
2744                         , unit_volume
2745                         into
2746                           t_item_info(l_inventory_item_id).inventory_item_id
2747                         , t_item_info(l_inventory_item_id).item_primary_uom_code
2748                         , t_item_info(l_inventory_item_id).item_weight_uom_code
2749                         , t_item_info(l_inventory_item_id).item_unit_weight
2750                         , t_item_info(l_inventory_item_id).item_volume_uom_code
2751                         , t_item_info(l_inventory_item_id).item_unit_volume
2752                         from mtl_system_items
2753                         where organization_id        = p_organization_id
2754                         and   inventory_item_id      = l_inventory_item_id;
2755              	   end if;
2756 
2757                    if NOT(t_item_units.exists(l_inventory_item_id)) then
2758                         -- Item doesnt exist in Item Locator cache Initialize
2759                         t_item_units(l_inventory_item_id).inventory_item_id :=
2760                                 l_inventory_item_id;
2761                         t_item_units(l_inventory_item_id).location_current_units := 0;
2762                         t_item_units(l_inventory_item_id).location_suggested_units := 0;
2763                    end if;
2764 
2765                    -- MMTT quantity maybe negative
2766                    l_transaction_quantity := abs(l_transaction_quantity);
2767 
2768                    -- Initialize
2769                    l_transacted_weight := 0;
2770                    l_transacted_volume := 0;
2771 
2772                    -- Compute Weight
2773                    if ((t_location_weight_uom_code(i)                         is not null) and
2774                        (t_item_info(l_inventory_item_id).item_weight_uom_code is not null) and
2775                        (t_item_info(l_inventory_item_id).item_unit_weight > 0)) then
2776 
2777                        l_transacted_weight := l_transaction_quantity *
2778                                 t_item_info(l_inventory_item_id).item_unit_weight;
2779 
2780                        if (t_item_info(l_inventory_item_id).item_weight_uom_code <>
2781                            t_location_weight_uom_code(i)) then
2782 
2783                         l_transacted_weight :=
2784                           inv_convert.inv_um_convert(
2785                             item_id       => l_inventory_item_id,
2786                             precision     => null,
2787                             from_quantity => l_transacted_weight,
2788                             from_unit     => t_item_info(l_inventory_item_id).item_weight_uom_code,
2789                             to_unit       => t_location_weight_uom_code(i),
2790                             from_name     => null,
2791                             to_name       => null) ;
2792                        end if;
2793 
2794                        if (l_transacted_weight < 0) then
2795                                 l_transacted_weight := 0;
2796                        end if;
2797                    end if;
2798 
2799                    -- Compute Volume
2800                    if ((t_volume_uom_code(i)                                  is not null) and
2801                        (t_item_info(l_inventory_item_id).item_volume_uom_code is not null) and
2802                        (t_item_info(l_inventory_item_id).item_unit_volume > 0)) then
2803 
2804                        l_transacted_volume := l_transaction_quantity *
2805                                 t_item_info(l_inventory_item_id).item_unit_volume;
2806 
2807                        if (t_item_info(l_inventory_item_id).item_volume_uom_code <>
2808                            t_volume_uom_code(i)) then
2809 
2810                         l_transacted_volume :=
2811                           inv_convert.inv_um_convert(
2812                             item_id       => l_inventory_item_id,
2813                             precision     => null,
2814                             from_quantity => l_transacted_volume,
2815                             from_unit     => t_item_info(l_inventory_item_id).item_volume_uom_code,
2816                             to_unit       => t_volume_uom_code(i),
2817                             from_name     => null,
2818                             to_name       => null) ;
2819                        end if;
2820 
2821                        if (l_transacted_volume < 0) then
2822                                 l_transacted_volume := 0;
2823                        end if;
2824                    end if;
2825                 END IF; --inventory_item_id > 0
2826 
2827                  /*******************************************************************************
2828                   * Fetch the details of the LPN if passed.
2829                   *******************************************************************************/
2830                  IF l_lpn_id IS NOT NULL AND NOT t_lpn_info.EXISTS(l_lpn_id) THEN
2831                     get_container_capacity
2832                       (   x_return_status             => x_return_status
2833                         , x_msg_count                 => x_msg_count
2834                         , x_msg_data                  => x_msg_data
2835                         , p_locator_weight_uom        => t_location_weight_uom_code(i)
2836                         , p_locator_volume_uom        => t_volume_uom_code(i)
2837                         , p_lpn_id                    => l_lpn_id
2838                         , p_organization_id           => p_organization_id
2839                         , x_container_item_wt         => t_lpn_info(l_lpn_id).container_item_weight
2840                         , x_container_item_vol        => t_lpn_info(l_lpn_id).container_item_vol
2841                         , x_lpn_gross_weight          => t_lpn_info(l_lpn_id).gross_weight
2842                         , x_lpn_content_vol           => t_lpn_info(l_lpn_id).content_volume
2843                       );
2844                  END IF;
2845                  /*******************************************************************************
2846                   * Fetch the details of the Content  LPN if passed.
2847                   *******************************************************************************/
2848                  IF l_content_lpn_id IS NOT NULL AND NOT t_lpn_info.EXISTS(l_content_lpn_id) THEN
2849                     get_container_capacity
2850                       (   x_return_status             => x_return_status
2851                         , x_msg_count                 => x_msg_count
2852                         , x_msg_data                  => x_msg_data
2853                         , p_locator_weight_uom        => t_location_weight_uom_code(i)
2854                         , p_locator_volume_uom        => t_volume_uom_code(i)
2855                         , p_lpn_id                    => l_content_lpn_id
2856                         , p_organization_id           => p_organization_id
2857                         , x_container_item_wt         => t_lpn_info(l_content_lpn_id).container_item_weight
2858                         , x_container_item_vol        => t_lpn_info(l_content_lpn_id).container_item_vol
2859                         , x_lpn_gross_weight          => t_lpn_info(l_content_lpn_id).gross_weight
2860                         , x_lpn_content_vol           => t_lpn_info(l_content_lpn_id).content_volume
2861                       );
2862                  END IF;
2863                  /*******************************************************************************
2864                   * Fetch the details of the Transfer LPN if passed.
2865                   *******************************************************************************/
2866                  IF l_transfer_lpn_id IS NOT NULL AND NOT t_lpn_info.EXISTS(l_transfer_lpn_id) THEN
2867                     get_container_capacity
2868                       (   x_return_status             => x_return_status
2869                         , x_msg_count                 => x_msg_count
2870                         , x_msg_data                  => x_msg_data
2871                         , p_locator_weight_uom        => t_location_weight_uom_code(i)
2872                         , p_locator_volume_uom        => t_volume_uom_code(i)
2873                         , p_lpn_id                    => l_transfer_lpn_id
2874                         , p_organization_id           => p_organization_id
2875                         , x_container_item_wt         => t_lpn_info(l_transfer_lpn_id).container_item_weight
2876                         , x_container_item_vol        => t_lpn_info(l_transfer_lpn_id).container_item_vol
2877                         , x_lpn_gross_weight          => t_lpn_info(l_transfer_lpn_id).gross_weight
2878                         , x_lpn_content_vol           => t_lpn_info(l_transfer_lpn_id).content_volume
2879                       );
2880                  END IF;
2881 
2882                  /********************************************************************************
2883                   * Check if the record is from MOQD or MMTT and process accordingly.
2884                   ********************************************************************************/
2885                  IF (l_record_source = 'MOQ_RECORD') THEN
2886                      -- Add Units
2887                      t_item_units(l_inventory_item_id).location_current_units :=
2888                        t_item_units(l_inventory_item_id).location_current_units +
2889                        l_transaction_quantity;
2890 
2891                      t_location_current_units(i) := t_location_current_units(i) +
2892                        l_transaction_quantity;
2893 
2894                      -- lpn has not already been considered, then consider the container weight
2895                      -- and volume.
2896 
2897                      IF l_lpn_id IS NOT NULL AND t_lpn_info(l_lpn_id).lpn_exists_in_locator = 'N' THEN
2898                         -- check if the content volume is > container item volume, in which case
2899                         -- add the content volume, else add the container item volume.
2900                         IF t_lpn_info(l_lpn_id).content_volume < t_lpn_info(l_lpn_id).container_item_vol THEN
2901                            t_current_cubic_area(i) := t_current_cubic_area(i) + t_lpn_info(l_lpn_id).container_item_vol;
2902                         ELSE
2903                            t_current_cubic_area(i) := t_current_cubic_area(i) + t_lpn_info(l_lpn_id).content_volume;
2904                         END IF;
2905                         t_current_weight(i)     := t_current_weight(i) + t_lpn_info(l_lpn_id).gross_weight;
2906                         t_lpn_info(l_lpn_id).lpn_exists_in_locator := 'Y';
2907                         mdebug(l_prog_name||'moq current wt is         :'||t_current_weight(i));
2908                         mdebug(l_prog_name||'moq current cubic area is :'||t_current_cubic_area(i));
2909                      ELSIF l_lpn_id IS NULL THEN
2910                         -- Loose Qty
2911                         -- Add transacted weight
2912                         t_current_weight(i) := t_current_weight(i) + l_transacted_weight;
2913                         -- the MOQD record is for loose quantity. just add the transacted volume.
2914                         t_current_cubic_area(i) := t_current_cubic_area(i) + l_transacted_volume;
2915                         mdebug(l_prog_name||'moq current wt is         :'||t_current_weight(i));
2916                         mdebug(l_prog_name||'moq current cubic area is :'||t_current_cubic_area(i));
2917                      END IF;
2918                  ELSIF (l_record_source = 'MMTT_SOURCE_LOCATOR_RECORD') THEN
2919                     /********************************************************************************
2920                      * The record is from MMTT. Check whether the transaction is a suggestion or a
2921                      * Pending transaction. If it is a suggestion, then only suggested capacity is
2922                      * modified.
2923                      ********************************************************************************/
2924                     IF (l_transaction_status = 2) THEN  -- This is a Receipt Suggestion.
2925                      --Add transacted weight
2926                      t_suggested_weight(i) := t_suggested_weight(i) + l_transacted_weight;
2927                      --Add transacted volume
2928                      t_suggested_cubic_area(i) := t_suggested_cubic_area(i) + l_transacted_volume;
2929                      -- Add Units
2930                      t_item_units(l_inventory_item_id).location_suggested_units :=
2931                        t_item_units(l_inventory_item_id).location_suggested_units +
2932                        l_transaction_quantity;
2933                      t_location_suggested_units(i) := t_location_suggested_units(i) +
2934                        l_transaction_quantity;
2935                    ELSE
2936                      IF (l_transaction_action_id in (12,27)) THEN    -- Receipt Pending Xn
2937                        --Add transacted weight. this needs to be done irrespective of whether
2938                        --the transaction has LPN or not.
2939                        t_current_weight(i) := t_current_weight(i) + l_transacted_weight;
2940                        -- Add Units
2941                        t_item_units(l_inventory_item_id).location_current_units :=
2942                          t_item_units(l_inventory_item_id).location_current_units +
2943                          l_transaction_quantity;
2944 
2945                        t_location_current_units(i) := t_location_current_units(i) +
2946                          l_transaction_quantity;
2947                        --This is an LPN transation, Check if the lpn already exists in the locator.
2948                        --If not, then we need to consider the container weight and volume.
2949                        IF l_transfer_lpn_id IS NOT NULL AND t_lpn_info(l_transfer_lpn_id).lpn_exists_in_locator = 'N' THEN
2950                           mdebug('**************lpn exists in locator***********'||t_lpn_info(l_transfer_lpn_id).lpn_exists_in_locator);
2951                           IF l_transacted_volume < t_lpn_info(l_transfer_lpn_id).container_item_vol THEN
2952                              t_current_cubic_area(i) := t_current_cubic_area(i) + t_lpn_info(l_transfer_lpn_id).container_item_vol;
2953                           ELSE
2954                              t_current_cubic_area(i) := t_current_cubic_area(i) + l_transacted_volume;
2955                           END IF;
2956                           t_current_weight(i)     := t_current_weight(i) + t_lpn_info(l_transfer_lpn_id).container_item_weight;
2957                           t_lpn_info(l_transfer_lpn_id).lpn_exists_in_locator := 'Y';
2958                           mdebug(l_prog_name||'mmtt current wt is         :'||t_current_weight(i));
2959                           mdebug(l_prog_name||'mmtt current cubic area is :'||t_current_cubic_area(i));
2960                        ELSIF l_transfer_lpn_id IS NOT NULL THEN
2961                           --The LPN already exists in the locator. so we need to check if the addition of this
2962                           --quantity would overflow the container or not.
2963                           IF t_lpn_info(l_transfer_lpn_id).container_item_vol > t_lpn_info(l_transfer_lpn_id).content_volume THEN
2964                              IF l_transacted_volume > (t_lpn_info(l_transfer_lpn_id).container_item_vol
2965                                                      - t_lpn_info(l_transfer_lpn_id).content_volume)  THEN
2966                                 t_current_cubic_area(i) := t_current_cubic_area(i) + l_transacted_volume
2967                                                               + t_lpn_info(l_transfer_lpn_id).content_volume
2968                                                               - t_lpn_info(l_transfer_lpn_id).container_item_vol;
2969                              END IF;
2970                              mdebug(l_prog_name||'mmtt current wt is         :'||t_current_weight(i));
2971                              mdebug(l_prog_name||'mmtt current cubic area is :'||t_current_cubic_area(i));
2972                           ELSE
2973                              --Already the LPN has more volume than the container. so just add the transacted
2974                              --volume.
2975                              t_current_Cubic_area(i) := t_current_cubic_area(i) + l_transacted_volume;
2976                              mdebug(l_prog_name||'mmtt current wt is         :'||t_current_weight(i));
2977                              mdebug(l_prog_name||'mmtt current cubic area is :'||t_current_cubic_area(i));
2978                           END IF;
2979                        ELSE
2980                           -- loose quantity, just add the transacted volume
2981                           t_current_cubic_area(i) := t_current_cubic_area(i) + l_transacted_volume;
2982                           mdebug(l_prog_name||'mmtt current wt is         :'||t_current_weight(i));
2983                           mdebug(l_prog_name||'mmtt current cubic area is :'||t_current_cubic_area(i));
2984                        END IF;
2985 
2986                        IF l_transfer_lpn_id IS NOT NULL THEN
2987                           --need to update the LPN Cache with the transacted volume and weight.
2988                           --This is needed as the record is still in MMTT and the LPN weight and
2989                           --volume are not properly updated yet.
2990                           t_lpn_info(l_transfer_lpn_id).gross_weight := t_lpn_info(l_transfer_lpn_id).gross_weight
2991                                           + l_transacted_weight;
2992                           t_lpn_info(l_transfer_lpn_id).content_volume := t_lpn_info(l_transfer_lpn_id).content_volume
2993                                                                       + l_transacted_volume;
2994 
2995                        END IF;
2996                      ELSIF (l_transaction_action_id in (1,2,3,28)) THEN -- Issue Pending Xn
2997                        --If the content lpn is stamped, the transaction quantity will always be -1.
2998                        --so we need to fetch the actual transated qty from the LPN contents.
2999                        IF l_content_lpn_id IS NULL THEN
3000                           t_current_weight(i) := t_current_weight(i) - l_transacted_weight;
3001 
3002                        -- Minus Units
3003                           t_item_units(l_inventory_item_id).location_current_units :=
3004                             t_item_units(l_inventory_item_id).location_current_units -
3005                             l_transaction_quantity;
3006 
3007                           t_location_current_units(i) := t_location_current_units(i) -
3008                             l_transaction_quantity;
3009                        END IF;
3010                        IF l_content_lpn_id IS NOT NULL AND t_lpn_info(l_content_lpn_id).lpn_already_considered <> 'Y'  THEN
3011                           --Content LPN is not null => the whole LPN is being transacted.
3012                           t_current_weight(i)     := t_current_weight(i) - t_lpn_info(l_content_lpn_id).gross_weight;
3013                           IF t_lpn_info(l_content_lpn_id).container_item_vol > t_lpn_info(l_content_lpn_id).content_volume THEN
3014                              t_current_cubic_area(i) := t_current_cubic_area(i) - t_lpn_info(l_content_lpn_id).container_item_vol;
3015                           ELSE
3016                              t_current_cubic_area(i) := t_current_cubic_area(i) - t_lpn_info(l_content_lpn_id).content_volume;
3017                           END IF;
3018 
3019                           t_lpn_info(l_content_lpn_id).lpn_already_considered := 'Y';
3020                           fetch_lpn_content_qty(
3021                                     p_lpn_id             =>    l_content_lpn_id
3022                                   , x_quantity           =>    l_cnt_lpn_qty
3023                           );
3024 
3025                           t_location_current_units(i) := t_location_current_units(i) - l_cnt_lpn_qty;
3026                           mdebug(l_prog_name||'mmtt current wt is :'||t_current_weight(i));
3027                           mdebug(l_prog_name||'mmtt current cubic area is :'||t_current_cubic_area(i));
3028                        ELSE
3029                           IF l_lpn_id IS NOT NULL AND t_lpn_info(l_lpn_id).lpn_already_considered <> 'Y' AND
3030                              l_transacted_volume = t_lpn_info(l_lpn_id).content_volume THEN
3031                              --Transacting the entire LPN. Consider deducting container wt and vol.
3032                              t_current_weight(i)     := t_current_weight(i) - t_lpn_info(l_lpn_id).container_item_weight;
3033                              IF t_lpn_info(l_lpn_id).container_item_vol > t_lpn_info(l_lpn_id).content_volume THEN
3034                                 t_current_cubic_area(i) := t_current_cubic_area(i) - t_lpn_info(l_lpn_id).container_item_vol;
3035                              ELSE
3036                                 t_current_cubic_area(i) := t_current_cubic_area(i) - t_lpn_info(l_lpn_id).content_volume;
3037                              END IF;
3038                              t_lpn_info
3039                                 (l_lpn_id).lpn_already_considered := 'Y';
3040                              mdebug(l_prog_name||'mmtt current wt is :'||t_current_weight(i));
3041                              mdebug(l_prog_name||'mmtt current cubic area is :'||t_current_cubic_area(i));
3042                           ELSIF l_lpn_id IS NOT NULL AND t_lpn_info(l_lpn_id).lpn_already_considered <> 'Y'THEN
3043                                 --Transacting partial LPN.
3044                                 t_current_cubic_area(i) := t_current_cubic_area(i) - l_transacted_volume;
3045                                 t_lpn_info(l_lpn_id).content_volume := t_lpn_info(l_lpn_id).content_volume - l_transacted_volume;
3046                                 t_lpn_info(l_lpn_id).gross_weight := t_lpn_info(l_lpn_id).gross_weight - l_transacted_weight;
3047                                 mdebug(l_prog_name||'mmtt current wt is         :'||t_current_weight(i));
3048                                 mdebug(l_prog_name||'mmtt current cubic area is :'||t_current_cubic_area(i));
3049                           ELSIF l_lpn_id IS NULL THEN
3050                                t_current_cubic_area(i) := t_current_cubic_area(i) - l_transacted_volume;
3051                                mdebug(l_prog_name||'mmtt current wt is         :'||t_current_weight(i));
3052                                mdebug(l_prog_name||'mmtt current cubic area is :'||t_current_cubic_area(i));
3053                           END IF;
3054                        END IF;
3055                      ELSIF (l_transaction_action_id  = 50) THEN  --Pack Transaction
3056                           IF l_transfer_lpn_id IS NOT NULL AND t_lpn_info(l_transfer_lpn_id).lpn_exists_in_locator = 'N' THEN
3057                              t_current_weight(i)     := t_current_weight(i) + t_lpn_info(l_transfer_lpn_id).container_item_weight;
3058                              IF l_content_lpn_id IS NULL THEN
3059                                 IF l_transacted_volume >= t_lpn_info(l_transfer_lpn_id).container_item_vol THEN
3060                                    t_current_cubic_area(i) := t_current_cubic_area(i);
3061                                 ELSE
3062                                    t_current_cubic_area(i) := t_current_cubic_area(i) + t_lpn_info(l_transfer_lpn_id).container_item_vol
3063                                                                                       - l_transacted_volume;
3064                                 END IF;
3065                              ELSE
3066                                 IF t_lpn_info(l_content_lpn_id).content_volume > t_lpn_info(l_content_lpn_id).container_item_vol THEN
3067                                    l_content_lpn_volume := t_lpn_info(l_content_lpn_id).content_volume;
3068                                 ELSE
3069                                    l_content_lpn_volume := t_lpn_info(l_content_lpn_id).container_item_vol;
3070                                 END IF;
3071                                 IF l_content_lpn_volume >= t_lpn_info(l_transfer_lpn_id).container_item_vol THEN
3072                                    t_current_cubic_area(i) := t_current_cubic_area(i);
3073                                 ELSE
3074                                    t_current_cubic_area(i) := t_current_cubic_area(i) + t_lpn_info(l_transfer_lpn_id).container_item_vol
3075                                                                                       - l_content_lpn_volume;
3076                                 END IF;
3077                              END IF;
3078                              t_lpn_info(l_transfer_lpn_id).lpn_exists_in_locator := 'Y';
3079                           ELSIF l_transfer_lpn_id IS NOT NULL THEN
3080                                 IF l_content_lpn_id IS NULL THEN
3081                                    IF l_transacted_volume <= (t_lpn_info(l_transfer_lpn_id).container_item_vol
3082                                                           -  t_lpn_info(l_transfer_lpn_id).content_volume) THEN
3083                                       t_current_cubic_area(i) := t_current_cubic_area(i) - l_transacted_volume;
3084                                    ELSE
3085                                       t_current_cubic_area(i) := t_current_cubic_area(i) + t_lpn_info(l_transfer_lpn_id).content_volume
3086                                                                                          - t_lpn_info(l_transfer_lpn_id).container_item_vol;
3087                                    END IF;
3088                                 ELSE
3089                                    IF t_lpn_info(l_content_lpn_id).content_volume > t_lpn_info(l_content_lpn_id).container_item_vol THEN
3090                                       l_content_lpn_volume := t_lpn_info(l_content_lpn_id).content_volume;
3091                                    ELSE
3092                                       l_content_lpn_volume := t_lpn_info(l_content_lpn_id).container_item_vol;
3093                                    END IF;
3094                                    IF l_content_lpn_volume > (t_lpn_info(l_transfer_lpn_id).container_item_vol
3095                                                            -  t_lpn_info(l_transfer_lpn_id).content_volume) THEN
3096                                       t_current_cubic_area(i) := t_current_cubic_area(i) - l_content_lpn_volume;
3097                                    ELSE
3098                                       t_current_cubic_area(i) := t_current_cubic_area(i) - t_lpn_info(l_transfer_lpn_id).container_item_vol
3099                                                                                          + t_lpn_info(l_transfer_lpn_id).content_volume;
3100                                    END IF;
3101                                 END IF;
3102                           END IF;
3103                           IF l_content_lpn_id IS NULL THEN
3104                              t_lpn_info(l_transfer_lpn_id).gross_weight := t_lpn_info(l_transfer_lpn_id).gross_weight + l_transacted_weight;
3105                              t_lpn_info(l_transfer_lpn_id).content_volume := t_lpn_info(l_transfer_lpn_id).content_volume + l_transacted_volume;
3106                           ELSE
3107                              t_lpn_info(l_transfer_lpn_id).gross_weight := t_lpn_info(l_transfer_lpn_id).gross_weight
3108                                                                         +  t_lpn_info(l_content_lpn_id).gross_weight;
3109                              t_lpn_info(l_transfer_lpn_id).content_volume := t_lpn_info(l_transfer_lpn_id).content_volume
3110                                                                         +  l_content_lpn_volume;
3111                           END IF;
3112                      ELSIF (l_transaction_action_id  = 51) THEN   --Unpack Transaction.
3113                           IF l_content_lpn_id IS NULL  THEN
3114                                IF t_lpn_info(l_lpn_id).container_item_vol <> 0
3115                                   AND (t_lpn_info(l_lpn_id).content_volume - l_transacted_volume)
3116                                       < t_lpn_info(l_lpn_id).container_item_vol THEN
3117                                   IF t_lpn_info(l_lpn_id).content_volume > t_lpn_info(l_lpn_id).container_item_vol THEN
3118                                      t_current_cubic_area(i) := t_current_cubic_area(i) - t_lpn_info(l_lpn_id).content_volume
3119                                                           + t_lpn_info(l_lpn_id).container_item_vol + l_transacted_volume;
3120                                   ELSE
3121                                      t_current_cubic_area(i) := t_current_cubic_area(i) + l_transacted_volume;
3122                                   END IF;
3123                                END IF;
3124 			       --Bug#5083715.Changed l_transfer_lpn_id to l_lpn_id
3125 			       IF l_lpn_id IS NOT NULL THEN -- Added for 4484753
3126                                		t_lpn_info(l_lpn_id).gross_weight := t_lpn_info(l_lpn_id).gross_weight - l_transacted_weight;
3127                                		t_lpn_info(l_lpn_id).content_volume := t_lpn_info(l_lpn_id).content_volume - l_transacted_volume;
3128 			       END IF;
3129                           ELSE
3130                                IF t_lpn_info(l_content_lpn_id).content_volume > t_lpn_info(l_content_lpn_id).container_item_vol THEN
3131                                   l_content_lpn_volume := t_lpn_info(l_content_lpn_id).content_volume;
3132                                ELSE
3133                                   l_content_lpn_volume := t_lpn_info(l_content_lpn_id).container_item_vol;
3134                                END IF;
3135                                IF t_lpn_info(l_lpn_id).container_item_vol <> 0
3136                                   AND (t_lpn_info(l_lpn_id).content_volume - l_content_lpn_volume)
3137                                       < t_lpn_info(l_lpn_id).container_item_vol THEN
3138                                   IF t_lpn_info(l_lpn_id).content_volume > t_lpn_info(l_lpn_id).container_item_vol THEN
3139                                      t_current_cubic_area(i) := t_current_cubic_area(i) - t_lpn_info(l_lpn_id).content_volume
3140                                                           + t_lpn_info(l_lpn_id).container_item_vol + l_content_lpn_volume;
3141                                   ELSE
3142                                      t_current_cubic_area(i) := t_current_cubic_area(i) + l_content_lpn_volume;
3143                                   END IF;
3144                                END IF;
3145 
3146 			       --Bug#5083715.Changed l_transfer_lpn_id to l_lpn_id
3147 				IF l_lpn_id IS NOT NULL THEN -- added for bug 5234216
3148 			       		t_lpn_info(l_lpn_id).gross_weight := t_lpn_info(l_lpn_id).gross_weight
3149                                                                           -  t_lpn_info(l_content_lpn_id).gross_weight;
3150                                		t_lpn_info(l_lpn_id).content_volume := t_lpn_info(l_lpn_id).content_volume
3151                                                                           -  l_content_lpn_volume;
3152 				END IF;
3153                           END IF;
3154                      end if;
3155                    end if;
3156                  else   /* MMTT_DESTINATION_LOCATOR_RECORD */
3157                    if (l_transaction_status = 2) then  -- Receipt Dest. Suggestion
3158 
3159                      --Add transacted weight
3160                      t_suggested_weight(i) := t_suggested_weight(i) +
3161                                               l_transacted_weight;
3162 
3163                      --Add transacted volume
3164                      t_suggested_cubic_area(i) := t_suggested_cubic_area(i) +
3165                                                   l_transacted_volume;
3166                      -- Add Units
3167                      t_item_units(l_inventory_item_id).location_suggested_units :=
3168                        t_item_units(l_inventory_item_id).location_suggested_units +
3169                        l_transaction_quantity;
3170 
3171                      t_location_suggested_units(i) := t_location_suggested_units(i) +
3172                        l_transaction_quantity;
3173 
3174                    else                               -- Receipt Dest. Pending Xn
3175                      IF l_content_lpn_id IS NULL THEN
3176                       --Add transacted weight
3177                       t_current_weight(i) := t_current_weight(i) + l_transacted_weight;
3178 
3179                       -- Add Units
3180                       t_item_units(l_inventory_item_id).location_current_units :=
3181                          t_item_units(l_inventory_item_id).location_current_units +
3182                          l_transaction_quantity;
3183 
3184                       t_location_current_units(i) := t_location_current_units(i) +
3185                          l_transaction_quantity;
3186                      END IF;
3187 
3188                       IF l_content_lpn_id IS NOT NULL THEN
3189                          fetch_lpn_content_qty(
3190                                    p_lpn_id             =>    l_content_lpn_id
3191                                  , x_quantity           =>    l_cnt_lpn_qty
3192                          );
3193                          IF t_lpn_info(l_content_lpn_id).content_volume < t_lpn_info(l_content_lpn_id).container_item_vol THEN
3194                             t_current_cubic_area(i) := t_current_cubic_area(i) + t_lpn_info(l_content_lpn_id).container_item_vol;
3195                          ELSE
3196                             t_current_cubic_area(i) := t_current_cubic_area(i) + t_lpn_info(l_content_lpn_id).content_volume;
3197                          END IF;
3198                          t_current_weight(i) := t_current_weight(i) + t_lpn_info(l_content_lpn_id).gross_weight;
3199                          mdebug(l_prog_name||'mmtt dest current wt is :'||t_current_weight(i));
3200                          mdebug(l_prog_name||'mmtt dest current cubic area is :'||t_current_cubic_area(i));
3201                          t_location_current_units(i) := t_location_current_units(i) + l_cnt_lpn_qty;
3202                       ELSE
3203                         IF l_transfer_lpn_id IS NOT NULL AND t_lpn_info(l_transfer_lpn_id).lpn_exists_in_locator = 'N' THEN
3204                            IF l_transacted_volume < t_lpn_info(l_transfer_lpn_id).container_item_vol THEN
3205                               t_current_cubic_area(i) := t_current_cubic_area(i) + t_lpn_info(l_transfer_lpn_id).container_item_vol;
3206                            ELSE
3207                               t_current_cubic_area(i) := t_current_cubic_area(i) + l_transacted_volume;
3208                            END IF;
3209                            t_current_weight(i)     := t_current_weight(i) + t_lpn_info(l_transfer_lpn_id).container_item_weight;
3210                            t_lpn_info(l_transfer_lpn_id).lpn_exists_in_locator := 'Y';
3211                            mdebug(l_prog_name||'mmtt current wt is         :'||t_current_weight(i));
3212                            mdebug(l_prog_name||'mmtt current cubic area is :'||t_current_cubic_area(i));
3213                            --t_lpn_info(l_lpn_id).lpn_already_considered := 'Y'
3214                         ELSIF l_transfer_lpn_id IS NOT NULL THEN
3215                            IF t_lpn_info(l_transfer_lpn_id).container_item_vol > t_lpn_info(l_transfer_lpn_id).content_volume THEN
3216                               IF l_transacted_volume > (t_lpn_info(l_transfer_lpn_id).container_item_vol
3217                                                       - t_lpn_info(l_transfer_lpn_id).content_volume)  THEN
3218                                  t_current_cubic_area(i) := t_current_cubic_area(i) + l_transacted_volume
3219                                                                + t_lpn_info(l_transfer_lpn_id).content_volume
3220                                                                - t_lpn_info(l_transfer_lpn_id).container_item_vol;
3221                               END IF;
3222                               mdebug(l_prog_name||'mmtt current wt is         :'||t_current_weight(i));
3223                               mdebug(l_prog_name||'mmtt current cubic area is :'||t_current_cubic_area(i));
3224                            ELSE
3225                               t_current_cubic_area(i) := t_current_cubic_area(i) + l_transacted_volume;
3226                               mdebug(l_prog_name||'mmtt current wt is         :'||t_current_weight(i));
3227                               mdebug(l_prog_name||'mmtt current cubic area is :'||t_current_cubic_area(i));
3228                            END IF;
3229                         ELSE -- loose quantity
3230                            t_current_cubic_area(i) := t_current_cubic_area(i) + l_transacted_volume;
3231                            mdebug(l_prog_name||'mmtt current wt is         :'||t_current_weight(i));
3232                            mdebug(l_prog_name||'mmtt current cubic area is :'||t_current_cubic_area(i));
3233                         END IF;
3234                       END IF;
3235                    end if;
3236                  end if;
3237                  --end if;        -- (l_inventory_item_id > 0)
3238            END LOOP;            -- (c_onhand loop)
3239 
3240            close c_onhand;
3241 
3242            /*
3243            ** Determine weight and volume of packed material in locator
3244            */
3245 
3246            /*
3247            ** Determine empty, mixed items and item(if single item)
3248            */
3249            if ((t_location_current_units(i) + t_location_suggested_units(i)) <= 0) then
3250                 -- Empty
3251                 t_inventory_item_id(i) := NULL;
3252                 t_empty_flag(i)        := 'Y';
3253                 t_mixed_items_flag(i)  := 'N';
3254            elsif (t_item_units.count = 0) then
3255                 -- Empty
3256                 t_inventory_item_id(i) := NULL;
3257                 t_empty_flag(i)        := 'Y';
3258                 t_mixed_items_flag(i)  := 'N';
3259            else
3260                 l_count   := 0;
3261                 l_item_id := NULL;
3262                 l_index   := t_item_units.first;
3263 
3264                 loop
3265                   if ((t_item_units(l_index).location_current_units +
3266                        t_item_units(l_index).location_suggested_units) > 0) then
3267                         l_count   := l_count + 1;
3268                         l_item_id := t_item_units(l_index).inventory_item_id;
3269                   end if;
3270 
3271                   if (l_count > 1) then
3272                         exit;
3273                   end if;
3274 
3275                   exit when l_index = t_item_units.last;
3276 
3277                   l_index := t_item_units.next(l_index);
3278                 end loop;
3279 
3280                 if (l_count = 1) then
3281                         -- Single Item
3282                         t_inventory_item_id(i) := l_item_id;
3283                         t_empty_flag(i)        := 'N';
3284                         t_mixed_items_flag(i)  := 'N';
3285                 else
3286                         -- Multiple Items
3287                         t_inventory_item_id(i) := NULL;
3288                         t_empty_flag(i)        := 'N';
3289                         t_mixed_items_flag(i)  := 'Y';
3290                 end if;
3291            end if;
3292 
3293            -- Set Available Units
3294            if (t_location_maximum_units(i) IS NULL) THEN
3295                 t_location_available_units(i) := NULL ;
3296            else
3297                 t_location_available_units(i) := t_location_maximum_units(i)
3298                   - (t_location_current_units(i) + t_location_suggested_units(i));
3299 
3300                 if (t_location_available_units(i) < 0) then
3301                         t_location_available_units(i) := 0;
3302                 end if;
3303            end if;
3304 
3305            -- Set Available Weight
3306            if (t_max_weight(i) IS NULL) THEN
3307                 t_available_weight(i) := NULL ;
3308            else
3309                 t_available_weight(i) := t_max_weight(i)
3310                   - (t_current_weight(i) + t_suggested_weight(i));
3311 
3312                 if (t_available_weight(i) < 0) then
3313                         t_available_weight(i) := 0;
3314                 end if;
3315            end if;
3316 
3317            -- Set Available Volume
3318            if (t_max_cubic_area(i) IS NULL) THEN
3319                 t_available_cubic_area(i) := NULL ;
3320            else
3321                 t_available_cubic_area(i) := t_max_cubic_area(i)
3322                   - (t_current_cubic_area(i) + t_suggested_cubic_area(i));
3323 
3324                 if (t_available_cubic_area(i) < 0) then
3325                         t_available_cubic_area(i) := 0;
3326                 end if;
3327            end if;
3328 
3329         end loop;               -- (looping thru 500 locators)
3330 
3331         l_bulk_count := c_all_locators%rowcount;
3332         -- BULK update
3333         forall i in t_locator.first..t_locator.last
3334                 update mtl_item_locations
3335                 set
3336                   location_current_units   = t_location_current_units(i)
3337                 , location_suggested_units = t_location_suggested_units(i)
3338                 , location_available_units = t_location_available_units(i)
3339                 , current_weight           = t_current_weight(i)
3340                 , suggested_weight         = t_suggested_weight(i)
3341                 , available_weight         = t_available_weight(i)
3342                 , current_cubic_area       = t_current_cubic_area(i)
3343                 , suggested_cubic_area     = t_suggested_cubic_area(i)
3344                 , available_cubic_area     = t_available_cubic_area(i)
3345                 , inventory_item_id        = t_inventory_item_id(i)
3346                 , empty_flag               = t_empty_flag(i)
3347                 , mixed_items_flag         = t_mixed_items_flag(i)
3348 	       , last_update_date     = sysdate                                                       /* Added for Bug 6363028 */
3349                 where organization_id        = p_organization_id
3350                 and   inventory_location_id  = t_locator(i);
3351 
3352         -- Commit 500 at a time. Last batch will have <= 500
3353         commit;
3354 
3355         -- For logging purpose
3356         l_commit_count := l_commit_count + 1;
3357 
3358         IF (l_debug = 1) THEN
3359            INV_TRX_UTIL_PUB.TRACE('After commit'     ||
3360                                ', commit count: ' || to_char(l_commit_count) ||
3361                                ', last locator: ' || to_char(t_locator.last) ,
3362                                'Locator_Capacity_Clean_Up',9);
3363         END IF;
3364 
3365         exit when l_loop_count < 500;
3366    end loop;                    -- (c_all_locators loop)
3367 
3368    close c_all_locators;
3369 
3370    IF (l_debug = 1) THEN
3371       INV_TRX_UTIL_PUB.TRACE('End ','Locator_Capacity_Clean_Up',9);
3372    END IF;
3373 
3374 EXCEPTION
3375       WHEN fnd_api.g_exc_error THEN
3376          mdebug('Error:-'||SQLERRM);
3377          ROLLBACK TO locators_capacity_cleanup ;
3378       x_return_status := fnd_api.g_ret_sts_error;
3379       fnd_msg_pub.count_and_get
3380 	( p_count => x_msg_count,
3381 	  p_data  => x_msg_data
3382 	 );
3383 
3384    WHEN fnd_api.g_exc_unexpected_error THEN
3385       mdebug('Error:-'||SQLERRM);
3386 	ROLLBACK TO locators_capacity_cleanup;
3387       x_return_status := fnd_api.g_ret_sts_unexp_error ;
3388        fnd_msg_pub.count_and_get
3389 	( p_count => x_msg_count,
3390 	  p_data  => x_msg_data
3391 	  );
3392 
3393    WHEN OTHERS THEN
3394       mdebug('Error:-'||SQLERRM);
3395 	ROLLBACK TO locators_capacity_cleanup;
3396       x_return_status := fnd_api.g_ret_sts_unexp_error;
3397      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
3398 	THEN
3399 	 fnd_msg_pub.add_exc_msg
3400 	   (  'inv_loc_wms_utils'
3401 	      , 'locator_capacity_cleanup'
3402 	      );
3403 	END IF;
3404      fnd_msg_pub.count_and_get
3405 	( p_count => x_msg_count,
3406 	  p_data  => x_msg_data
3407 	  );
3408 END locators_capacity_cleanup;
3409 
3410 --  this API upgrades (cleans up) the capacity in each location thru concurrent request
3411 PROCEDURE launch_upgrade(
3412     x_errorbuf         OUT  NOCOPY VARCHAR2,
3413     x_retcode          OUT  NOCOPY VARCHAR2,
3414     p_organization_id   IN  NUMBER,
3415     p_subinventory      IN  VARCHAR2,
3416     p_mixed_items_flag  IN  NUMBER
3417     )
3418 IS
3419      l_return_status		varchar2(1);
3420      l_msg_count	        number;
3421      l_msg_data			varchar2(1000);
3422      l_conc_status               BOOLEAN;
3423      l_mixed_items_flag		varchar2(1);
3424     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3425 BEGIN
3426 
3427 	IF (p_organization_id is null) THEN
3428 	 fnd_message.set_name('INV', 'INV_ORG_REQUIRED');
3429 	 fnd_msg_pub.add;
3430 	 RAISE fnd_api.g_exc_error;
3431 	END IF;
3432 
3433         IF nvl(p_mixed_items_flag,2) = 1 then
3434           l_mixed_items_flag :='Y';
3435         else
3436           l_mixed_items_flag := null;
3437         END IF;
3438 
3439 	-- call cleanup API
3440 	inv_loc_wms_utils.locators_capacity_cleanup
3441 	(    x_return_status       => l_return_status
3442 	   , x_msg_count           => l_msg_count
3443 	   , x_msg_data            => l_msg_data
3444 	   , p_organization_id     => p_organization_id
3445 	   , p_mixed_flag          => l_mixed_items_flag
3446 	   , p_subinventory        => p_subinventory);
3447 
3448 	IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
3449 	    IF (l_return_status = fnd_api.g_ret_sts_error) THEN
3450 	     IF (l_debug = 1) THEN
3451    	     INV_TRX_UTIL_PUB.TRACE('Locator capacity calc prog completed with Errors ', 'launch Upgrade',9);
3452 	     END IF;
3453 	     RAISE fnd_api.g_exc_error;
3454 	    ELSE
3455 	     IF (l_debug = 1) THEN
3456    	     INV_TRX_UTIL_PUB.TRACE('Locator capacity calc prog completed with Unexp errors ', 'launch Upgrade',9);
3457 	     END IF;
3458 	     RAISE fnd_api.g_exc_unexpected_error;
3459 	    END IF;
3460 	ELSE
3461 	     IF (l_debug = 1) THEN
3462    	     INV_TRX_UTIL_PUB.TRACE('Locator capacity calc prog completed successfully ', 'launch Upgrade',9);
3463 	     END IF;
3464 	      print_message();
3465 	      l_conc_status := fnd_concurrent.set_completion_status('NORMAL','NORMAL');
3466 	      x_retcode := RETCODE_SUCCESS;
3467 	      x_errorbuf := NULL;
3468 	END IF;
3469 
3470 EXCEPTION
3471   WHEN fnd_api.g_exc_error THEN
3472 
3473        print_message();
3474        l_conc_status := fnd_concurrent.set_completion_status('ERROR','ERROR');
3475        x_retcode := RETCODE_ERROR;
3476        x_errorbuf := fnd_msg_pub.get(p_encoded => fnd_api.g_false);
3477 
3478   WHEN fnd_api.g_exc_unexpected_error THEN
3479 
3480        print_message();
3481        l_conc_status := fnd_concurrent.set_completion_status('ERROR','ERROR');
3482        x_retcode := RETCODE_ERROR;
3483        x_errorbuf := fnd_msg_pub.get(p_encoded => fnd_api.g_false);
3484 
3485   WHEN OTHERS THEN
3486 
3487        print_message();
3488        l_conc_status := fnd_concurrent.set_completion_status('ERROR','ERROR');
3489        x_retcode := RETCODE_ERROR;
3490        x_errorbuf := fnd_msg_pub.get(p_encoded => fnd_api.g_false);
3491 
3492 END launch_upgrade;
3493 
3494 PROCEDURE print_message(dummy IN VARCHAR2 )IS
3495 
3496    l_msg_count    NUMBER;
3497    l_msg_data     VARCHAR2(2000);
3498 
3499     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3500 BEGIN
3501 
3502        fnd_msg_pub.count_and_get(
3503 	 p_count   => l_msg_count,
3504 	 p_data    => l_msg_data,
3505 	 p_encoded => 'F'
3506 	 );
3507 
3508        FOR i IN 1..l_msg_count LOOP
3509 	   l_msg_data := fnd_msg_pub.get(i, 'F');
3510 	   fnd_file.put_line(fnd_file.log, l_msg_data);
3511        END LOOP;
3512        fnd_file.put_line(fnd_file.log, ' ');
3513 
3514        fnd_msg_pub.initialize;
3515 
3516 EXCEPTION
3517    WHEN OTHERS THEN
3518 	fnd_file.put_line(fnd_file.log, sqlerrm);
3519 
3520 END print_message;
3521 
3522 
3523 /************************************************************************************************
3524  * Procedure fetch_locator()                                                                    *
3525  * @Params :                                                                                    *
3526  *          1. Inventory Location Passed                                                        *
3527  *          2. Organization                                                                     *
3528  *          3. Actual Physical Locator ID                                                       *
3529  ************************************************************************************************/
3530 PROCEDURE fetch_locator
3531    ( p_inventory_location_id    IN          NUMBER     -- inventory location id
3532    , p_organization_id          IN          NUMBER     -- organization
3533    , x_locator_id               OUT  NOCOPY NUMBER     -- actual physical location id
3534    )
3535 IS
3536    l_loc_id                 NUMBER;
3537    l_physical_locator_id    NUMBER;
3538    l_debug                           NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3539 BEGIN
3540    /*---------------------------------------------------------------------------------------------
3541      Check if the locator has a physical_location_id then use the physical_location_id for further
3542      processing.Else we have to use the inventory_location_id for further processing
3543      ---------------------------------------------------------------------------------------------*/
3544    SELECT   physical_location_id
3545 	     ,   inventory_location_id
3546      INTO   l_physical_locator_id
3547 	     ,   l_loc_id
3548      FROM   mtl_item_locations
3549     WHERE   inventory_location_id = p_inventory_location_id
3550       AND   organization_id = p_organization_id;
3551 
3552    /*---------------------------------------------------------------------------------------------
3553      If physical location id is null, then the location_id passes is normal locator, else it is a
3554      logical locator and we have to use the physical location id to fetch the capacity.
3555      ---------------------------------------------------------------------------------------------*/
3556    IF l_physical_locator_id IS NULL THEN
3557      x_locator_id := l_loc_id;
3558    ELSE
3559      x_locator_id := l_physical_locator_id;
3560    END IF;
3561 END fetch_locator;
3562 
3563 PROCEDURE fetch_loc_curr_capacity
3564    (
3565      p_inventory_location_id        IN         NUMBER     -- inventory location id
3566    , p_organization_id              IN         NUMBER     -- organization passed
3567    , x_loc_attr                     OUT NOCOPY LocatorRec -- Record Containing Locator Details
3568    )
3569 IS
3570 l_locator_weight_uom_code          VARCHAR2(3);
3571 l_locator_max_weight               NUMBER;
3572 l_locator_suggested_weight         NUMBER;
3573 l_locator_suggested_cubic_area     NUMBER;
3574 l_locator_current_weight           NUMBER;
3575 l_locator_available_weight         NUMBER;
3576 l_locator_volume_uom_code          VARCHAR2(3);
3577 l_locator_max_cubic_area           NUMBER;
3578 l_locator_current_cubic_area       NUMBER;
3579 l_locator_available_cubic_area     NUMBER;
3580 l_locator_maximum_units            NUMBER;
3581 l_locator_current_units            NUMBER;
3582 l_locator_available_units          NUMBER;
3583 l_locator_suggested_units          NUMBER;
3584 l_debug                            NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3585 l_proc_name                        VARCHAR2(20) := 'FETCH_LOCATOR: ';
3586 BEGIN
3587    /*---------------------------------------------------------------------------------------------
3588      Fetch the locator's current capacity.
3589      ---------------------------------------------------------------------------------------------*/
3590    SELECT location_weight_uom_code
3591         , max_weight
3592         , suggested_weight
3593         , suggested_cubic_area
3594         , current_weight
3595         , available_weight
3596         , volume_uom_code
3597         , max_cubic_area
3598         , current_cubic_area
3599         , available_cubic_area
3600         , location_maximum_units
3601         , location_current_units
3602         , location_available_units
3603         , location_suggested_units
3604      INTO l_locator_weight_uom_code
3605         , l_locator_max_weight
3606         , l_locator_suggested_weight
3607         , l_locator_suggested_cubic_area
3608         , l_locator_current_weight
3609         , l_locator_available_weight
3610         , l_locator_volume_uom_code
3611         , l_locator_max_cubic_area
3612         , l_locator_current_cubic_area
3613         , l_locator_available_cubic_area
3614         , l_locator_maximum_units
3615         , l_locator_current_units
3616         , l_locator_available_units
3617         , l_locator_suggested_units
3618      FROM MTL_ITEM_LOCATIONS
3619     WHERE organization_id = p_organization_id
3620 	   AND inventory_location_id = p_inventory_location_id;
3621 
3622    /*------------------------------------------------------------------------------------------
3623      Validate the locator_current_weight,suggested_weight, current volume and suggested volume,
3624      Current units and Suggested Units.
3625      ------------------------------------------------------------------------------------------*/
3626 
3627    IF l_locator_current_weight IS NULL OR l_locator_current_weight < 0 THEN
3628      l_locator_current_weight  := 0;
3629      IF (l_debug = 1) THEN
3630         mdebug(l_proc_name||'The l_locator_current_weight is ZERO');
3631      END IF;
3632    END IF;
3633 
3634    IF l_locator_suggested_weight IS NULL OR l_locator_suggested_weight <0 THEN
3635      l_locator_suggested_weight := 0;
3636      IF (l_debug = 1) THEN
3637         mdebug(l_proc_name||'The l_locator_suggested_weight is ZERO');
3638      END IF;
3639    END IF;
3640 
3641     IF l_locator_current_cubic_area IS NULL OR l_locator_current_cubic_area <0 THEN
3642        l_locator_current_cubic_area  := 0;
3643        IF (l_debug = 1) THEN
3644           mdebug(l_proc_name||'The l_locator_current_cubic_area is ZERO');
3645        END IF;
3646    END IF;
3647 
3648    IF l_locator_suggested_cubic_area IS NULL OR l_locator_suggested_cubic_area <0 THEN
3649       l_locator_suggested_cubic_area := 0;
3650        IF (l_debug = 1) THEN
3651           mdebug(l_proc_name||'The l_locator_suggested_cubic_area is ZERO');
3652        END IF;
3653    END IF;
3654 
3655    IF (l_locator_current_units IS NULL) OR (l_locator_current_units < 0) then
3656       l_locator_current_units := 0;
3657       IF (l_debug = 1) THEN
3658          mdebug(l_proc_name||'The l_locator_current units is ZERO');
3659       END IF;
3660    END IF;
3661 
3662    IF (l_locator_suggested_units IS NULL) OR (l_locator_suggested_units < 0) then
3663       l_locator_suggested_units := 0;
3664       IF (l_debug = 1) THEN
3665          mdebug(l_proc_name||'The l_locator_suggested units is ZERO');
3666       END IF;
3667    END IF;
3668 
3669    /*-------------------------------------------------------------------------------------------
3670      Note if the max_weight of the locator is not defined, then available weight is nulled out.
3671      Similarly, if the max_volume is not defined, then the available volume is nulled out.
3672      If the max_units is not defined, the available number of units is nulled out.
3673      -------------------------------------------------------------------------------------------*/
3674 
3675    IF l_locator_max_weight IS NULL THEN
3676       l_locator_available_weight := NULL;
3677       IF (l_debug = 1) THEN
3678          mdebug(l_proc_name||'The l_locator_MAX_weight is NULL and hence
3679                                     available weight is also NULLED out');
3680       END IF;
3681    END IF;
3682 
3683    IF l_locator_max_cubic_area is null THEN
3684       l_locator_available_cubic_area := null;
3685       IF (l_debug = 1) THEN
3686          mdebug(l_proc_name||'The l_locator_MAX_cubic_area is NULL and hence
3687                                     available cubic_area is also nulled out');
3688       END IF;
3689    END IF;
3690 
3691    IF (l_locator_maximum_units IS NULL) THEN
3692       l_locator_available_units :=  NULL;
3693       IF (l_debug = 1) THEN
3694          mdebug(l_proc_name||'The l_locator_MAX_units is NULL and hence
3695                                     available units is also nulled out');
3696       END IF;
3697    END IF;
3698 
3699 x_loc_attr.l_locator_weight_uom_code           :=    l_locator_weight_uom_code;
3700 x_loc_attr.l_locator_max_weight                :=    l_locator_max_weight;
3701 x_loc_attr.l_locator_suggested_weight          :=    l_locator_suggested_weight;
3702 x_loc_attr.l_locator_suggested_cubic_area      :=    l_locator_suggested_cubic_area;
3703 x_loc_attr.l_locator_current_weight            :=    l_locator_current_weight;
3704 x_loc_attr.l_locator_available_weight          :=    l_locator_available_weight;
3705 x_loc_attr.l_locator_volume_uom_code           :=    l_locator_volume_uom_code;
3706 x_loc_attr.l_locator_max_cubic_area            :=    l_locator_max_cubic_area;
3707 x_loc_attr.l_locator_current_cubic_area        :=    l_locator_current_cubic_area;
3708 x_loc_attr.l_locator_available_cubic_area      :=    l_locator_available_cubic_area;
3709 x_loc_attr.l_locator_maximum_units             :=    l_locator_maximum_units;
3710 x_loc_attr.l_locator_current_units             :=    l_locator_current_units;
3711 x_loc_attr.l_locator_available_units           :=    l_locator_available_units;
3712 x_loc_attr.l_locator_suggested_units           :=    l_locator_suggested_units;
3713 
3714 END fetch_loc_curr_capacity;
3715 
3716 PROCEDURE fetch_item_attributes(
3717      	      x_return_status            OUT NOCOPY VARCHAR2
3718           , x_msg_data                 OUT NOCOPY VARCHAR2
3719           , x_msg_count                OUT NOCOPY NUMBER
3720           , x_item_attr                OUT NOCOPY ItemRec
3721           , p_inventory_item_id        IN         NUMBER
3722           , p_transaction_uom_code     IN         NUMBER
3723           , p_primary_uom_flag         IN         VARCHAR2
3724           , p_locator_weight_uom_code  IN         VARCHAR2
3725           , p_locator_volume_uom_code  IN         VARCHAR2
3726           , p_quantity                 IN         NUMBER
3727           , p_organization_id          IN         NUMBER
3728           , p_container_item           IN         VARCHAR2
3729           )
3730 IS
3731    l_debug                        NUMBER       := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3732    l_proc_name                    VARCHAR2(50) := 'FETCH_ITEM_ATTRIBUTES: ';
3733 BEGIN
3734    x_return_status := FND_API.G_RET_STS_SUCCESS;
3735    item_attributes(
3736        x_return_status            =>    x_return_status
3737      , x_msg_data                 =>    x_msg_data
3738      , x_msg_count                =>    x_msg_count
3739      , x_item_weight_uom_code     =>    x_item_attr.l_item_weight_uom_code
3740      , x_item_unit_weight         =>    x_item_attr.l_item_unit_weight
3741      , x_item_volume_uom_code     =>    x_item_attr.l_item_volume_uom_code
3742      , x_item_unit_volume         =>    x_item_attr.l_item_unit_volume
3743      , x_item_xacted_weight       =>    x_item_attr.l_item_xacted_weight
3744      , x_item_xacted_volume       =>    x_item_attr.l_item_xacted_volume
3745      , p_inventory_item_id        =>    p_inventory_item_id
3746      , p_transaction_uom_code     =>    p_transaction_uom_code
3747      , p_primary_uom_flag         =>    p_primary_uom_flag
3748      , p_locator_weight_uom_code  =>    p_locator_weight_uom_code
3749      , p_locator_volume_uom_code  =>    p_locator_volume_uom_code
3750      , p_quantity                 =>    p_quantity
3751      , p_organization_id          =>    p_organization_id
3752      , p_container_item           =>    p_container_item
3753      );
3754    IF x_return_status =fnd_api.g_ret_sts_error THEN
3755       RAISE fnd_api.g_exc_error;
3756    ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error   THEN
3757       RAISE fnd_api.g_exc_unexpected_error;
3758    END IF;
3759 
3760    IF (l_debug = 1) THEN
3761       mdebug(l_proc_name||'The item weight UOM code  : '||x_item_attr.l_item_weight_uom_code);
3762       mdebug(l_proc_name||'item unit weight          : '||x_item_attr.l_item_unit_weight);
3763       mdebug(l_proc_name||'item volume UOM code      : '||x_item_attr.l_item_volume_uom_code);
3764       mdebug(l_proc_name||'item unit volume          : '||x_item_attr.l_item_unit_volume);
3765       mdebug(l_proc_name||'item extracted weight     : '||x_item_attr.l_item_xacted_weight);
3766       mdebug(l_proc_name||'item extracted volume     : '||x_item_attr.l_item_xacted_volume);
3767     END IF;
3768 
3769 END fetch_item_attributes;
3770 
3771 
3772 PROCEDURE fetch_lpn_attr
3773    (
3774      x_return_status                    OUT NOCOPY VARCHAR2  -- return status (success/error/unexpected_error)
3775    , x_msg_data                         OUT NOCOPY VARCHAR2  -- message text when x_msg-count > 0
3776    , x_msg_count                        OUT NOCOPY NUMBER    -- number of messages in message queue
3777    , x_lpn_attr                         OUT nocopy LpnRec
3778    , p_lpn_id                           IN         NUMBER    -- Content LPN ID
3779    , p_org_id                           IN         NUMBER    -- Organization ID
3780    , p_locator_volume_uom_code          IN         VARCHAR2  -- Locator Volume UOM Code
3781    , p_locator_weight_uom_code          IN         VARCHAR2  -- Locator Weight UOM Code
3782    )
3783 IS
3784    l_lpn_content_volume              NUMBER;
3785    l_lpn_gross_weight_uom_code       VARCHAR2(3);
3786    l_lpn_content_volume_uom_code     VARCHAR2(3);
3787    l_lpn_gross_weight                NUMBER;
3788    l_lpn_container_item_weight       NUMBER;
3789    l_lpn_container_item_vol          NUMBER;
3790    l_lpn_exists_in_locator           VARCHAR2(1);
3791    l_proc_name                       VARCHAR2(50) := 'FETCH_LPN_ATTR: ';
3792    l_debug                           NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3793 BEGIN
3794    x_return_status := FND_API.G_RET_STS_SUCCESS;
3795    IF (l_debug = 1) THEN
3796       mdebug(l_proc_name||'Fetching of LPN attibutes ');
3797    END IF;
3798    INV_LOC_WMS_UTILS.lpn_attributes(
3799                          x_return_status            =>   x_return_status
3800                        , x_msg_data                 =>   x_msg_data
3801                        , x_msg_count                =>   x_msg_count
3802                        , x_gross_weight_uom_code    =>   l_lpn_gross_weight_uom_code
3803                        , x_content_volume_uom_code  =>   l_lpn_content_volume_uom_code
3804                        , x_gross_weight             =>   l_lpn_gross_weight
3805                        , x_content_volume           =>   l_lpn_content_volume
3806                        , x_container_item_weight    =>   l_lpn_container_item_weight
3807                        , x_container_item_vol       =>   l_lpn_container_item_vol
3808                        , x_lpn_exists_in_locator    =>   l_lpn_exists_in_locator
3809                        , p_lpn_id                   =>   p_lpn_id
3810                        , p_org_id                   =>   p_org_id
3811                        );
3812 
3813    IF x_return_status =fnd_api.g_ret_sts_error THEN
3814       RAISE fnd_api.g_exc_error;
3815    ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error   THEN
3816       RAISE fnd_api.g_exc_unexpected_error;
3817    END IF;
3818 
3819  /*--------------------------------------------------------------------------------------
3820    Convert the  Volume of the LPN into the Locator's Volume UOM code.
3821    --------------------------------------------------------------------------------------*/
3822    IF l_lpn_content_volume_uom_code IS NOT NULL AND
3823       p_locator_volume_uom_code IS NOT NULL AND
3824       l_lpn_content_volume >0  THEN
3825       IF (l_lpn_content_volume_uom_code <> p_locator_volume_uom_code) THEN
3826          l_lpn_content_volume := inv_convert.inv_um_convert(
3827                          item_id                    => null
3828                        , precision                  => null
3829                        , from_quantity              => l_lpn_content_volume
3830                        , from_unit                  => l_lpn_content_volume_uom_code
3831                        , to_unit                    => p_locator_volume_uom_code
3832                        , from_name                  => null
3833                        , to_name                    => null
3834                        );
3835       ELSE
3836         l_lpn_content_volume := l_lpn_content_volume;
3837       END IF;
3838    END IF;
3839 
3840  /*--------------------------------------------------------------------------------------
3841    Conversion is not defined. Raise form trigger failure.
3842    --------------------------------------------------------------------------------------*/
3843    IF l_lpn_content_volume = -99999 THEN
3844       RAISE fnd_api.g_exc_error;
3845    END IF;
3846 
3847    IF (l_debug = 1) THEN
3848       mdebug(l_proc_name||'l_lpn_content_volume is '||to_char(l_lpn_content_volume));
3849    END IF;
3850 
3851    /*--------------------------------------------------------------------------------------
3852      Convert the container Volume into the Locator's Volume UOM code.
3853      --------------------------------------------------------------------------------------*/
3854    IF l_lpn_content_volume_uom_code IS NOT NULL
3855       AND  p_locator_volume_uom_code IS NOT NULL
3856       AND  l_lpn_container_item_vol >0  THEN
3857       IF (l_lpn_content_volume_uom_code <> p_locator_volume_uom_code) THEN
3858          l_lpn_container_item_vol := inv_convert.inv_um_convert(
3859                          item_id                    =>    null
3860                        , precision                  =>    null
3861                        , from_quantity              =>    l_lpn_container_item_vol
3862                        , from_unit                  =>    l_lpn_content_volume_uom_code
3863                        , to_unit                    =>    p_locator_volume_uom_code
3864                        , from_name                  =>    null
3865                        , to_name                    =>    null
3866                        );
3867       ELSE
3868          l_lpn_container_item_vol := l_lpn_container_item_vol ;
3869       END IF;
3870    END IF;
3871 
3872    IF (l_debug = 1) THEN
3873       mdebug(l_proc_name||'l_lpn_container_item_vol is: '||to_char(l_lpn_container_item_vol));
3874    END IF;
3875 
3876    /*--------------------------------------------------------------------------------------
3877      Conversion is not defined. Raise form trigger failure.
3878      --------------------------------------------------------------------------------------*/
3879    IF l_lpn_container_item_vol = -99999 THEN
3880       RAISE fnd_api.g_exc_error;
3881    END IF;
3882 
3883    /*--------------------------------------------------------------------------------------
3884      Convert the Gross Weight of the LPN into the Locator's Volume UOM code.
3885      --------------------------------------------------------------------------------------*/
3886    IF  l_lpn_gross_weight_uom_code IS NOT NULL AND
3887        p_locator_weight_uom_code IS NOT NULL   AND
3888        l_lpn_gross_weight >0  THEN
3889        IF (p_locator_weight_uom_code<> l_lpn_gross_weight_uom_code) THEN
3890           l_lpn_gross_weight := inv_convert.inv_um_convert(
3891                          item_id                    =>    null
3892                        , precision                  =>    null
3893                        , from_quantity              =>    l_lpn_gross_weight
3894                        , from_unit                  =>    l_lpn_gross_weight_uom_code
3895                        , to_unit	                   =>    p_locator_weight_uom_code
3896                        , from_name                  =>    null
3897                        , to_name	                   =>    null
3898                        );
3899        ELSE
3900           l_lpn_gross_weight :=l_lpn_gross_weight;
3901        END IF;
3902    END IF;
3903 
3904    /*--------------------------------------------------------------------------------------
3905      Conversion is not defined. Raise form trigger failure.
3906      --------------------------------------------------------------------------------------*/
3907    IF l_lpn_gross_weight = -99999 THEN
3908       RAISE fnd_api.g_exc_error;
3909    END IF;
3910 
3911    /*--------------------------------------------------------------------------------------
3912      Convert the Container Item Weight of the LPN into the Locator's Volume UOM code.
3913      --------------------------------------------------------------------------------------*/
3914    IF  l_lpn_gross_weight_uom_code IS NOT NULL AND
3915        p_locator_weight_uom_code IS NOT NULL   AND
3916        l_lpn_container_item_weight >0  THEN
3917        IF (p_locator_weight_uom_code<> l_lpn_gross_weight_uom_code) THEN
3918           l_lpn_container_item_weight := inv_convert.inv_um_convert(
3919                          item_id                    =>    null
3920                        , precision                  =>    null
3921                        , from_quantity              =>    l_lpn_container_item_weight
3922                        , from_unit                  =>    l_lpn_gross_weight_uom_code
3923                        , to_unit	                   =>    p_locator_weight_uom_code
3924                        , from_name                  =>    null
3925                        , to_name	                   =>    null
3926                        );
3927        ELSE
3928           l_lpn_container_item_weight :=l_lpn_container_item_weight;
3929        END IF;
3930    END IF;
3931 
3932    /*--------------------------------------------------------------------------------------
3933      Conversion is not defined. Raise form trigger failure.
3934      --------------------------------------------------------------------------------------*/
3935    IF l_lpn_container_item_weight = -99999 THEN
3936       RAISE fnd_api.g_exc_error;
3937    END IF;
3938 
3939    IF (l_debug = 1) THEN
3940       mdebug(l_proc_name||'End of Content LPN attibutes ');
3941    END IF;
3942 
3943    x_lpn_attr.l_gross_weight             :=  l_lpn_gross_weight;
3944    x_lpn_attr.l_content_volume           :=  l_lpn_content_volume;
3945    x_lpn_attr.l_container_item_weight    :=  l_lpn_container_item_weight;
3946    x_lpn_attr.l_container_item_vol       :=  l_lpn_container_item_vol;
3947    x_lpn_attr.l_gross_weight_uom_code    :=  l_lpn_gross_weight_uom_code;
3948    x_lpn_attr.l_content_volume_uom_code  :=  l_lpn_content_volume_uom_code;
3949    x_lpn_attr.l_lpn_exists_in_locator    :=  l_lpn_exists_in_locator;
3950 END fetch_lpn_attr;
3951 
3952 
3953 PROCEDURE fetch_transfer_lpn_attr
3954    (
3955      x_return_status                    OUT NOCOPY VARCHAR2  -- return status (success/error/unexpected_error)
3956    , x_msg_data                         OUT NOCOPY VARCHAR2  -- message text when x_msg-count > 0
3957    , x_msg_count                        OUT NOCOPY NUMBER    -- number of messages in message queue
3958    , x_trn_lpn_attr                     OUT NOCOPY LpnRec
3959    , p_lpn_id                           IN         NUMBER    -- Content LPN ID
3960    , p_org_id                           IN         NUMBER    -- Organization ID
3961    , p_locator_volume_uom_code          IN         VARCHAR2  -- Locator Volume UOM Code
3962    , p_locator_weight_uom_code          IN         VARCHAR2  -- Locator Weight UOM Code
3963    )
3964 IS
3965 l_trn_gross_weight                NUMBER;
3966 l_trn_content_volume              NUMBER;
3967 l_trn_container_item_weight       NUMBER;
3968 l_trn_container_item_vol          NUMBER;
3969 l_trn_gross_weight_uom_code       VARCHAR2(3);
3970 l_trn_content_volume_uom_code     VARCHAR2(3);
3971 l_trn_lpn_exists_in_locator       VARCHAR2(1);
3972 l_proc_name                       VARCHAR2(50) := 'FETCH_TRANSFER_LPN_ATTR: ';
3973 l_debug                           NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3974 BEGIN
3975    x_return_status := FND_API.G_RET_STS_SUCCESS;
3976    IF (l_debug = 1) THEN
3977       mdebug(l_proc_name||'Fetching of Transfer LPN attibutes ');
3978    END IF;
3979    INV_LOC_WMS_UTILS.lpn_attributes(
3980                          x_return_status            =>   x_return_status
3981                        , x_msg_data                 =>   x_msg_data
3982                        , x_msg_count                =>   x_msg_count
3983                        , x_gross_weight_uom_code    =>   l_trn_gross_weight_uom_code
3984                        , x_content_volume_uom_code  =>   l_trn_content_volume_uom_code
3985                        , x_gross_weight             =>   l_trn_gross_weight
3986                        , x_content_volume           =>   l_trn_content_volume
3987                        , x_container_item_weight    =>   l_trn_container_item_weight
3988                        , x_container_item_vol       =>   l_trn_container_item_vol
3989                        , x_lpn_exists_in_locator    =>   l_trn_lpn_exists_in_locator
3990                        , p_lpn_id                   =>   p_lpn_id
3991                        , p_org_id                   =>   p_org_id
3992                        );
3993 
3994    IF x_return_status =fnd_api.g_ret_sts_error THEN
3995       RAISE fnd_api.g_exc_error;
3996    ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error   THEN
3997       RAISE fnd_api.g_exc_unexpected_error;
3998    END IF;
3999 
4000    /*--------------------------------------------------------------------------------------
4001      Convert the content Volume of Transfer LPN into the Locator's Volume UOM code.
4002      --------------------------------------------------------------------------------------*/
4003    IF l_trn_content_volume_uom_code IS NOT NULL AND
4004       p_locator_volume_uom_code is not null AND
4005       l_trn_content_volume >0  THEN
4006       IF (l_trn_content_volume_uom_code <> p_locator_volume_uom_code) THEN
4007          l_trn_content_volume := inv_convert.inv_um_convert(
4008                          item_id                    =>    null
4009                        , precision                  =>    null
4010                        , from_quantity              =>    l_trn_content_volume
4011                        , from_unit                  =>    l_trn_content_volume_uom_code
4012                        , to_unit                    =>    p_locator_volume_uom_code
4013                        , from_name                  =>    null
4014                        , to_name                    =>    null
4015                        );
4016       ELSE
4017          l_trn_content_volume := l_trn_content_volume;
4018       END IF;
4019    END IF;
4020 
4021    /*--------------------------------------------------------------------------------------
4022      Conversion is not defined. Raise form trigger failure.
4023      --------------------------------------------------------------------------------------*/
4024    IF l_trn_content_volume = -99999 THEN
4025       RAISE fnd_api.g_exc_error;
4026    END IF;
4027 
4028    IF (l_debug = 1) THEN
4029       mdebug(l_proc_name||'l_trn_content_volume is: '||to_char(l_trn_content_volume));
4030    END IF;
4031 
4032    /*--------------------------------------------------------------------------------------
4033      Convert the Gross Weight of the LPN into the Locator's Volume UOM code.
4034      --------------------------------------------------------------------------------------*/
4035    IF l_trn_gross_weight_uom_code IS NOT NULL AND
4036       p_locator_weight_uom_code IS NOT NULL AND
4037       l_trn_gross_weight >0  THEN
4038       IF (l_trn_gross_weight_uom_code <> p_locator_weight_uom_code) THEN
4039          l_trn_gross_weight := inv_convert.inv_um_convert(
4040                          item_id                   =>     null
4041                        , precision                 =>     null
4042                        , from_quantity             =>     l_trn_gross_weight
4043                        , from_unit                 =>     l_trn_gross_weight_uom_code
4044                        , to_unit                   =>     p_locator_weight_uom_code
4045                        , from_name                 =>     null
4046                        , to_name                   =>     null
4047                        );
4048       ELSE
4049          l_trn_gross_weight := l_trn_gross_weight;
4050       END IF;
4051    END IF;
4052 
4053    /*--------------------------------------------------------------------------------------
4054      Conversion is not defined. Raise form trigger failure.
4055      --------------------------------------------------------------------------------------*/
4056    IF l_trn_gross_weight = -99999 THEN
4057       RAISE fnd_api.g_exc_error;
4058    END IF;
4059 
4060    IF (l_debug = 1) THEN
4061       mdebug(l_proc_name||'l_trn_gross_weight is: '||to_char(l_trn_gross_weight));
4062    END IF;
4063 
4064    /*--------------------------------------------------------------------------------------
4065      Convert the Gross Weight of the Container Items into the Locator's Volume UOM code.
4066      --------------------------------------------------------------------------------------*/
4067    IF l_trn_gross_weight_uom_code IS NOT NULL AND
4068       p_locator_weight_uom_code IS NOT NULL AND
4069       l_trn_container_item_weight >0 THEN
4070       IF (l_trn_gross_weight_uom_code <> p_locator_weight_uom_code) THEN
4071          l_trn_container_item_weight := inv_convert.inv_um_convert(
4072                          item_id                   =>     null
4073                        , precision                 =>     null
4074                        , from_quantity             =>     l_trn_container_item_weight
4075                        , from_unit                 =>     l_trn_gross_weight_uom_code
4076                        , to_unit                   =>     p_locator_weight_uom_code
4077                        , from_name                 =>     null
4078                        , to_name                   =>     null
4079                        );
4080       ELSE
4081          l_trn_container_item_weight := l_trn_container_item_weight ;
4082       END IF;
4083    END IF;
4084 
4085    /*--------------------------------------------------------------------------------------
4086      Conversion is not defined. Raise form trigger failure.
4087      --------------------------------------------------------------------------------------*/
4088    IF l_trn_container_item_weight = -99999 THEN
4089      RAISE fnd_api.g_exc_error;
4090    END IF;
4091 
4092    IF (l_debug = 1) THEN
4093      mdebug(l_proc_name||'l_trn_container_item_weight is: '||to_char(l_trn_container_item_weight));
4094    END IF;
4095 
4096    /*--------------------------------------------------------------------------------------
4097      Convert the Gross Volume of the Container Items into the Locator's Volume UOM code.
4098      --------------------------------------------------------------------------------------*/
4099    IF l_trn_content_volume_uom_code IS NOT NULL AND
4100       p_locator_volume_uom_code IS NOT NULL AND
4101       l_trn_container_item_vol >0 THEN
4102       IF (l_trn_content_volume_uom_code <> p_locator_volume_uom_code) THEN
4103          l_trn_container_item_vol := inv_convert.inv_um_convert(
4104                          item_id                   =>     null
4105                        , precision                 =>     null
4106                        , from_quantity             =>     l_trn_container_item_vol
4107                        , from_unit                 =>     l_trn_content_volume_uom_code
4108                        , to_unit                   =>     p_locator_volume_uom_code
4109                        , from_name                 =>     null
4110                        , to_name                   =>     null
4111                        );
4112        ELSE
4113          l_trn_container_item_vol := l_trn_container_item_vol ;
4114        END IF;
4115    END IF;
4116 
4117    /*--------------------------------------------------------------------------------------
4118      Conversion is not defined. Raise form trigger failure.
4119      --------------------------------------------------------------------------------------*/
4120    IF l_trn_container_item_vol = -99999 THEN
4121       RAISE fnd_api.g_exc_error;
4122    END IF;
4123 
4124    IF (l_debug = 1) THEN
4125      mdebug(l_proc_name||'l_trn_container_item_vol is: '||to_char(l_trn_container_item_vol));
4126    END IF;
4127    x_trn_lpn_attr.l_gross_weight             :=  l_trn_gross_weight;
4128    x_trn_lpn_attr.l_content_volume           :=  l_trn_content_volume;
4129    x_trn_lpn_attr.l_container_item_weight    :=  l_trn_container_item_weight;
4130    x_trn_lpn_attr.l_container_item_vol       :=  l_trn_container_item_vol;
4131    x_trn_lpn_attr.l_gross_weight_uom_code    :=  l_trn_gross_weight_uom_code;
4132    x_trn_lpn_attr.l_content_volume_uom_code  :=  l_trn_content_volume_uom_code;
4133    x_trn_lpn_attr.l_lpn_exists_in_locator    :=  l_trn_lpn_exists_in_locator;
4134 END fetch_transfer_lpn_attr;
4135 
4136 PROCEDURE fetch_content_lpn_attr
4137    (
4138      x_return_status                    OUT NOCOPY VARCHAR2
4139    , x_msg_data                         OUT NOCOPY VARCHAR2
4140    , x_msg_count                        OUT NOCOPY VARCHAR2
4141    , x_cnt_lpn_attr                     OUT NOCOPY LpnRec
4142    , x_cnt_lpn_qty                      OUT NOCOPY NUMBER
4143    , p_lpn_id                           IN         NUMBER    -- Content LPN ID
4144    , p_org_id                           IN         NUMBER    -- Organization ID
4145    , p_locator_volume_uom_code          IN         VARCHAR2  -- Locator Volume UOM Code
4146    , p_locator_weight_uom_code          IN         VARCHAR2  -- Locator Weight UOM Code
4147    )
4148 IS
4149    l_cnt_gross_weight                NUMBER ;
4150    l_cnt_content_volume              NUMBER;
4151    l_cnt_container_item_weight       NUMBER;
4152    l_cnt_container_item_vol          NUMBER;
4153    l_cnt_gross_weight_uom_code       VARCHAR2(3);
4154    l_cnt_content_volume_uom_code     VARCHAR2(3);
4155    l_cnt_lpn_exists_in_locator       VARCHAR2(1);
4156    l_quantity                        NUMBER := 0;
4157    l_proc_name                       VARCHAR2(50) := 'FETCH_CONTENT_LPN_ATTR: ';
4158    l_debug                           NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4159 BEGIN
4160    x_return_status := FND_API.G_RET_STS_SUCCESS;
4161    IF (l_debug = 1) THEN
4162       mdebug(l_proc_name||'Fetching attributes of the Content lpn: '||to_char(p_lpn_id));
4163    END IF;
4164    INV_LOC_WMS_UTILS.lpn_attributes(
4165                          x_return_status            =>   x_return_status
4166                        , x_msg_data                 =>   x_msg_data
4167                        , x_msg_count                =>   x_msg_count
4168                        , x_gross_weight_uom_code    =>   l_cnt_gross_weight_uom_code
4169                        , x_content_volume_uom_code  =>   l_cnt_content_volume_uom_code
4170                        , x_gross_weight             =>   l_cnt_gross_weight
4171                        , x_content_volume           =>   l_cnt_content_volume
4172                        , x_container_item_weight    =>   l_cnt_container_item_weight
4173                        , x_container_item_vol       =>   l_cnt_container_item_vol
4174                        , x_lpn_exists_in_locator    =>   l_cnt_lpn_exists_in_locator
4175                        , p_lpn_id                   =>   p_lpn_id
4176                        , p_org_id                   =>   p_org_id
4177                        );
4178 
4179    /*--------------------------------------------------------------------------------------
4180      Convert the content Volume of Content LPN into the Locator's Volume UOM code.
4181      --------------------------------------------------------------------------------------*/
4182    IF l_cnt_content_volume_uom_code IS NOT NULL AND
4183       p_locator_volume_uom_code IS NOT NULL AND
4184       l_cnt_content_volume >0  THEN
4185       IF (l_cnt_content_volume_uom_code <> p_locator_volume_uom_code) THEN
4186          l_cnt_content_volume := inv_convert.inv_um_convert(
4187                          item_id                    =>    null
4188                        , precision                  =>    null
4189                        , from_quantity              =>    l_cnt_content_volume
4190                        , from_unit                  =>    l_cnt_content_volume_uom_code
4191                        , to_unit                    =>    p_locator_volume_uom_code
4192                        , from_name                  =>    null
4193                        , to_name                    =>    null
4194                        );
4195       ELSE
4196          l_cnt_content_volume := l_cnt_content_volume;
4197       END IF;
4198    END IF;
4199 
4200    IF (l_debug = 1) THEN
4201       mdebug(l_proc_name||'l_cnt_content_volume is: '||to_char(l_cnt_content_volume));
4202    END IF;
4203 
4204    /*--------------------------------------------------------------------------------------
4205      Conversion is not defined. Raise form trigger failure.
4206      --------------------------------------------------------------------------------------*/
4207    IF l_cnt_content_volume = -99999 THEN
4208       RAISE fnd_api.g_exc_error;
4209    END IF;
4210 
4211    /*--------------------------------------------------------------------------------------
4212      Convert the container Volume into the Locator's Volume UOM code.
4213      --------------------------------------------------------------------------------------*/
4214    IF l_cnt_content_volume_uom_code IS NOT NULL
4215       AND  p_locator_volume_uom_code IS NOT NULL
4216       AND  l_cnt_container_item_vol >0  THEN
4217       IF (l_cnt_content_volume_uom_code <> p_locator_volume_uom_code) THEN
4218          l_cnt_container_item_vol := inv_convert.inv_um_convert(
4219                          item_id                    =>    null
4220                        , precision                  =>    null
4221                        , from_quantity              =>    l_cnt_container_item_vol
4222                        , from_unit                  =>    l_cnt_content_volume_uom_code
4223                        , to_unit                    =>    p_locator_volume_uom_code
4224                        , from_name                  =>    null
4225                        , to_name                    =>    null
4226                        );
4227       ELSE
4228          l_cnt_container_item_vol := l_cnt_container_item_vol ;
4229       END IF;
4230    END IF;
4231 
4232    IF (l_debug = 1) THEN
4233       mdebug(l_proc_name||'l_cnt_container_item_vol is: '||to_char(l_cnt_container_item_vol));
4234    END IF;
4235 
4236    /*--------------------------------------------------------------------------------------
4237      Conversion is not defined. Raise form trigger failure.
4238      --------------------------------------------------------------------------------------*/
4239    IF l_cnt_container_item_vol = -99999 THEN
4240       RAISE fnd_api.g_exc_error;
4241    END IF;
4242 
4243    /*--------------------------------------------------------------------------------------
4244      Convert the Gross Weight of the LPN into the Locator's Volume UOM code.
4245      --------------------------------------------------------------------------------------*/
4246    IF  l_cnt_gross_weight_uom_code IS NOT NULL AND
4247        p_locator_weight_uom_code IS NOT NULL   AND
4248        l_cnt_gross_weight >0  THEN
4249        IF (p_locator_weight_uom_code<> l_cnt_gross_weight_uom_code) THEN
4250           l_cnt_gross_weight := inv_convert.inv_um_convert(
4251                          item_id                    =>    null
4252                        , precision                  =>    null
4253                        , from_quantity              =>    l_cnt_gross_weight
4254                        , from_unit                  =>    l_cnt_gross_weight_uom_code
4255                        , to_unit	                   =>    p_locator_weight_uom_code
4256                        , from_name                  =>    null
4257                        , to_name	                   =>    null
4258                        );
4259        ELSE
4260           l_cnt_gross_weight :=l_cnt_gross_weight;
4261        END IF;
4262    END IF;
4263 
4264    /*--------------------------------------------------------------------------------------
4265      Conversion is not defined. Raise form trigger failure.
4266      --------------------------------------------------------------------------------------*/
4267    IF l_cnt_gross_weight = -99999 THEN
4268       RAISE fnd_api.g_exc_error;
4269    END IF;
4270 
4271    /*--------------------------------------------------------------------------------------
4272      Convert the Container Item Weight of the LPN into the Locator's Volume UOM code.
4273      --------------------------------------------------------------------------------------*/
4274    IF  l_cnt_gross_weight_uom_code IS NOT NULL AND
4275        p_locator_weight_uom_code IS NOT NULL   AND
4276        l_cnt_container_item_weight >0  THEN
4277        IF (p_locator_weight_uom_code<> l_cnt_gross_weight_uom_code) THEN
4278           l_cnt_container_item_weight := inv_convert.inv_um_convert(
4279                          item_id                    =>    null
4280                        , precision                  =>    null
4281                        , from_quantity              =>    l_cnt_container_item_weight
4282                        , from_unit                  =>    l_cnt_gross_weight_uom_code
4283                        , to_unit	                   =>    p_locator_weight_uom_code
4284                        , from_name                  =>    null
4285                        , to_name	                   =>    null
4286                        );
4287        ELSE
4288           l_cnt_container_item_weight :=l_cnt_container_item_weight;
4289        END IF;
4290    END IF;
4291 
4292    /*--------------------------------------------------------------------------------------
4293      Conversion is not defined. Raise form trigger failure.
4294      --------------------------------------------------------------------------------------*/
4295    IF l_cnt_container_item_weight = -99999 THEN
4296       RAISE fnd_api.g_exc_error;
4297    END IF;
4298 
4299    IF (l_debug = 1) THEN
4300       mdebug(l_proc_name||'End of Content LPN attibutes ');
4301    END IF;
4302 
4303    fetch_lpn_content_qty(
4304                           p_lpn_id             =>    p_lpn_id
4305                         , x_quantity           =>    x_cnt_lpn_qty
4306                         );
4307 
4308    x_cnt_lpn_attr.l_gross_weight             :=  l_cnt_gross_weight;
4309    x_cnt_lpn_attr.l_content_volume           :=  l_cnt_content_volume;
4310    x_cnt_lpn_attr.l_container_item_weight    :=  l_cnt_container_item_weight;
4311    x_cnt_lpn_attr.l_container_item_vol       :=  l_cnt_container_item_vol;
4312    x_cnt_lpn_attr.l_gross_weight_uom_code    :=  l_cnt_gross_weight_uom_code;
4313    x_cnt_lpn_attr.l_content_volume_uom_code  :=  l_cnt_content_volume_uom_code;
4314    x_cnt_lpn_attr.l_lpn_exists_in_locator    :=  l_cnt_lpn_exists_in_locator;
4315 END fetch_content_lpn_attr;
4316 
4317 PROCEDURE upd_lpn_loc_cpty_for_issue
4318    (
4319      x_return_status                 OUT    NOCOPY VARCHAR2
4320    , x_msg_data                      OUT    NOCOPY VARCHAR2
4321    , x_msg_count                     OUT    NOCOPY NUMBER
4322    , p_loc_attr                      IN            LocatorRec
4323    , p_content_lpn_id                IN            NUMBER
4324    , p_cnt_lpn_attr                  IN            LpnRec
4325    , p_transaction_action_id         IN            NUMBER
4326    , p_item_attr                     IN            ItemRec
4327    , p_quantity                      IN            NUMBER
4328    , p_inventory_location_id         IN            NUMBER
4329    , p_organization_id               IN            NUMBER
4330    )
4331 IS
4332    l_proc_name                    VARCHAR2(50) := 'UPD_LPN_LOC_CPTY_FOR_ISSUE:';
4333    l_locator_current_cubic_area   NUMBER := 0;
4334    l_locator_available_cubic_area NUMBER;
4335    l_locator_current_weight       NUMBER := 0;
4336    l_locator_available_weight     NUMBER;
4337    l_locator_current_units        NUMBER := 0;
4338    l_locator_available_units      NUMBER;
4339    l_debug                        NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4340 BEGIN
4341   x_return_status := FND_API.G_RET_STS_SUCCESS;
4342 
4343   IF (l_debug = 1) THEN
4344     mdebug(l_proc_name||'transaction Type is issue ');
4345   END IF;
4346 
4347   /* Reduce the weight of the locator by the weight of the content lpn.*/
4348   l_locator_current_weight   := p_loc_attr.l_locator_current_weight - p_cnt_lpn_attr.l_gross_weight;
4349   IF l_locator_current_weight <0 THEN
4350      l_locator_current_weight := 0;
4351   END IF;
4352 
4353   l_locator_available_weight := p_loc_attr.l_locator_Max_weight-(l_locator_current_weight
4354                                                                   + p_loc_attr.l_locator_suggested_weight);
4355   IF l_locator_available_weight <0 THEN
4356      l_locator_available_weight := 0;
4357   END IF;
4358   INV_LOC_WMS_UTILS.cal_locator_current_volume(
4359                 x_return_status               =>       x_return_status
4360               , x_msg_data                    =>       x_msg_data
4361               , x_msg_count                   =>       x_msg_count
4362               , x_locator_current_volume      =>       l_locator_current_cubic_area
4363               , p_trn_lpn_container_item_vol  =>       null
4364               , p_trn_lpn_content_volume      =>       null
4365               , p_cnt_lpn_container_item_vol  =>       p_cnt_lpn_attr.l_container_item_vol
4366               , p_cnt_lpn_content_volume      =>       p_cnt_lpn_attr.l_content_volume
4367               , p_lpn_container_item_vol      =>       null
4368               , p_lpn_content_volume          =>       null
4369               , p_xacted_volume               =>       p_cnt_lpn_attr.l_content_volume
4370               , p_locator_current_cubic_area  =>       p_loc_attr.l_locator_current_cubic_area
4371               , p_transaction_action_id       =>       p_transaction_action_id
4372               , p_transfer_lpn_id             =>       null
4373               , p_content_lpn_id              =>       p_content_lpn_id
4374               , p_lpn_id                      =>       null
4375               , p_trn_lpn_exists_in_loc       =>       null
4376              );
4377    IF x_return_status =fnd_api.g_ret_sts_error THEN
4378       RAISE fnd_api.g_exc_error;
4379    ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error   THEN
4380       RAISE fnd_api.g_exc_unexpected_error;
4381    END IF;
4382 
4383    l_locator_current_units := p_loc_attr.l_locator_current_units - p_quantity;
4384 
4385    IF l_locator_current_units <0 THEN
4386       l_locator_current_units := 0;
4387    END IF;
4388 
4389    IF l_locator_current_cubic_area <0 THEN
4390       l_locator_current_cubic_area := 0;
4391    END IF;
4392    l_locator_available_cubic_area := p_loc_attr.l_locator_max_cubic_area-(l_locator_current_cubic_area +
4393                                                                    p_loc_attr.l_locator_suggested_cubic_area) ;
4394    IF l_locator_available_cubic_area <0 THEN
4395       l_locator_available_cubic_area := 0;
4396    END IF;
4397 
4398    l_locator_available_units := p_loc_attr.l_locator_maximum_units-(l_locator_current_units +
4399                                                                  p_loc_attr.l_locator_suggested_units) ;
4400    IF l_locator_available_units <0 THEN
4401       l_locator_available_units := 0;
4402    END IF;
4403 
4404    IF (l_debug = 1) THEN
4405       mdebug(l_proc_name||'issue transaction is successful ');
4406    END IF;
4407 
4408    UPDATE MTL_ITEM_LOCATIONS mil
4409       SET current_weight           = nvl(l_locator_current_weight,current_weight)
4410         , available_weight         = nvl(l_locator_available_weight,available_weight)
4411         , current_cubic_area       = nvl(l_locator_current_cubic_area,current_cubic_area)
4412         , available_cubic_area     = nvl(l_locator_available_cubic_area,available_cubic_area)
4413         , location_current_units   = nvl(l_locator_current_units,location_current_units)
4414         , location_available_units = nvl(l_locator_available_units,mil.location_available_units)
4415     WHERE inventory_location_id    = p_inventory_location_id
4416       AND organization_id          = p_organization_id;
4417 
4418    IF l_debug = 1 THEN
4419       mdebug(l_proc_name||'Locator Current Weight after update      : '||l_locator_current_weight);
4420       mdebug(l_proc_name||'Locator Available Weight after update    : '||l_locator_available_weight);
4421       mdebug(l_proc_name||'Locator Current Cubic Area after update  : '||l_locator_current_cubic_area);
4422       mdebug(l_proc_name||'Locator Available Cubic Area after update: '||l_locator_available_cubic_area);
4423       mdebug(l_proc_name||'Locator Current Units after update       : '||l_locator_current_units);
4424       mdebug(l_proc_name||'Locator Available Units after update     : '||l_locator_available_units);
4425    END IF;
4426 END upd_lpn_loc_cpty_for_issue;
4427 
4428 PROCEDURE upd_lpn_loc_cpty_for_rcpt
4429    (
4430      x_return_status                 OUT    NOCOPY VARCHAR2
4431    , x_msg_data                      OUT    NOCOPY VARCHAR2
4432    , x_msg_count                     OUT    NOCOPY NUMBER
4433    , p_loc_attr                      IN            LocatorRec
4434    , p_transfer_lpn_id               IN            NUMBER
4435    , p_trn_lpn_attr                  IN            LpnRec
4436    , p_transaction_action_id         IN            NUMBER
4437    , p_item_attr                     IN            ItemRec
4438    , p_quantity                      IN            NUMBER
4439    , p_inventory_location_id         IN            NUMBER
4440    , p_organization_id               IN            NUMBER
4441    )
4442 IS
4443    l_proc_name                    VARCHAR2(50) := 'UPD_LPN_LOC_CPTY_FOR_RCPT:';
4444    l_locator_current_cubic_area   NUMBER := 0;
4445    l_locator_available_cubic_area NUMBER;
4446    l_locator_current_weight       NUMBER := 0;
4447    l_locator_available_weight     NUMBER;
4448    l_locator_current_units        NUMBER := 0;
4449    l_locator_available_units      NUMBER;
4450    l_debug                        NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4451 BEGIN
4452   x_return_status := FND_API.G_RET_STS_SUCCESS;
4453 
4454   IF (l_debug = 1) THEN
4455     mdebug(l_proc_name||'transaction Type is receipt ');
4456   END IF;
4457 
4458   /*-------------------------------------------------------------------------------------
4459     If Transfer LPN does not exist in the receipt locator and it is not null, then add the
4460     weight of the container item to the locator current weight
4461     -------------------------------------------------------------------------------------*/
4462   IF p_trn_lpn_attr.l_lpn_exists_in_locator ='N' AND p_transfer_lpn_id IS NOT NULL THEN
4463      l_locator_current_weight   := p_loc_attr.l_locator_current_weight + p_trn_lpn_attr.l_container_item_weight ;
4464      l_locator_current_weight   := l_locator_current_weight + p_item_attr.l_item_xacted_weight;
4465   ELSE
4466      l_locator_current_weight   := p_loc_attr.l_locator_current_weight + p_item_attr.l_item_xacted_weight;
4467   END IF;
4468 
4469   l_locator_available_weight := p_loc_attr.l_locator_Max_weight-(l_locator_current_weight +
4470                       p_loc_attr.l_locator_suggested_weight);
4471   IF l_locator_available_weight <0 THEN
4472      l_locator_available_weight := 0;
4473   END IF;
4474 
4475   l_locator_current_units   := p_loc_attr.l_locator_current_units + p_quantity;
4476   IF l_locator_current_units <0 THEN
4477      l_locator_current_units := 0;
4478   END IF;
4479 
4480   l_locator_available_units := p_loc_attr.l_locator_maximum_units-(l_locator_current_units +
4481                       p_loc_attr.l_locator_suggested_units);
4482   IF l_locator_available_units <0 THEN
4483      l_locator_available_units := 0;
4484   END IF;
4485 
4486   IF p_transfer_lpn_id IS NULL THEN
4487     l_locator_current_cubic_area := p_loc_attr.l_locator_current_cubic_area + p_item_attr.l_item_xacted_volume;
4488   ELSE
4489     INV_LOC_WMS_UTILS.cal_locator_current_volume(
4490               x_return_status               =>       x_return_status
4491             , x_msg_data                    =>       x_msg_data
4492             , x_msg_count                   =>       x_msg_count
4493             , x_locator_current_volume      =>       l_locator_current_cubic_area
4494             , p_trn_lpn_container_item_vol  =>       p_trn_lpn_attr.l_container_item_vol
4495             , p_trn_lpn_content_volume      =>       p_trn_lpn_attr.l_content_volume
4496             , p_cnt_lpn_container_item_vol  =>       null
4497             , p_cnt_lpn_content_volume      =>       null
4498             , p_lpn_container_item_vol      =>       p_trn_lpn_attr.l_container_item_vol
4499             , p_lpn_content_volume          =>       p_trn_lpn_attr.l_content_volume
4500             , p_xacted_volume               =>       p_item_attr.l_item_xacted_volume
4501             , p_locator_current_cubic_area  =>       p_loc_attr.l_locator_current_cubic_area
4502             , p_transaction_action_id       =>       p_transaction_action_id
4503             , p_transfer_lpn_id             =>       p_transfer_lpn_id
4504             , p_content_lpn_id              =>       null
4505             , p_lpn_id                      =>       p_transfer_lpn_id
4506             , p_trn_lpn_exists_in_loc       =>       p_trn_lpn_attr.l_lpn_exists_in_locator
4507             );
4508   END IF;
4509 
4510   l_locator_available_cubic_area := p_loc_attr.l_locator_Max_Cubic_area-(l_locator_current_cubic_area +
4511                             p_loc_attr.l_locator_suggested_cubic_area) ;
4512   IF l_locator_available_cubic_area <0 THEN
4513      l_locator_available_cubic_area := 0;
4514   END IF;
4515 
4516   UPDATE MTL_ITEM_LOCATIONS
4517      SET current_weight           = nvl(l_locator_current_weight,current_weight)
4518        , available_weight         = nvl(l_locator_available_weight,available_weight)
4519        , current_cubic_area       = nvl(l_locator_current_cubic_area,current_cubic_area)
4520        , available_cubic_area     = nvl(l_locator_available_cubic_area,available_cubic_area)
4521        , location_current_units   = nvl(l_locator_current_units,location_current_units)
4522        , location_available_units = nvl(l_locator_available_units,location_available_units)
4523    WHERE inventory_location_id    = p_inventory_location_id
4524      AND organization_id          = p_organization_id;
4525 
4526   IF l_debug = 1 THEN
4527      mdebug(l_proc_name||'Locator Current Weight after update      : '||l_locator_current_weight);
4528      mdebug(l_proc_name||'Locator Available Weight after update    : '||l_locator_available_weight);
4529      mdebug(l_proc_name||'Locator Current Cubic Area after update  : '||l_locator_current_cubic_area);
4530      mdebug(l_proc_name||'Locator Available Cubic Area after update: '||l_locator_available_cubic_area);
4531      mdebug(l_proc_name||'Locator Current Units after update       : '||l_locator_current_units);
4532      mdebug(l_proc_name||'Locator Available Units after update     : '||l_locator_available_units);
4533   END IF;
4534 
4535 END upd_lpn_loc_cpty_for_rcpt;
4536 
4537 -- bug#2876849. Added the two new parameters from org id and from loc id. These are needed
4538 -- for a transfer transaction to decrement the capacity from the souce locator.
4539 -- Also modified the code to handle case of Staging Xfr where the transfer_lpn_id is
4540 -- populated in MMTT.
4541 
4542 PROCEDURE upd_lpn_loc_cpty_for_xfr(
4543             x_return_status                   OUT NOCOPY VARCHAR2
4544           , x_msg_data                        OUT NOCOPY VARCHAR2
4545           , x_msg_count                       OUT NOCOPY VARCHAR2
4546           , p_loc_attr                        IN         LocatorRec
4547           , p_content_lpn_id                  IN         NUMBER
4548           , p_cnt_lpn_attr                    IN         LpnRec
4549           , p_trn_lpn_id                      IN         NUMBER
4550           , p_trn_lpn_attr                    IN         LpnRec
4551           , p_lpn_id                          IN         NUMBER
4552           , p_lpn_attr                        IN         LpnRec
4553           , p_transaction_action_id           IN         NUMBER
4554           , p_item_attr                       IN         ItemRec
4555           , p_quantity                        IN         NUMBER
4556           , p_inventory_location_id           IN         NUMBER
4557           , p_organization_id                 IN         NUMBER
4558           , p_inventory_item_id               IN         NUMBER
4559           , p_transaction_uom_code            IN         VARCHAR2
4560           , p_primary_uom_flag                IN         VARCHAR2
4561           , p_from_org_id                     IN         NUMBER
4562           , p_from_loc_id                     IN         NUMBER
4563           )
4564 IS
4565    l_old_inventory_location_id            NUMBER;
4566    l_old_organization_id                  NUMBER :=p_from_org_id;
4567    l_old_locator_id                       NUMBER :=p_from_loc_id;
4568    l_old_loc_attr                         LocatorRec;
4569    l_cnt_lpn_attr                         LpnRec;
4570    l_lpn_attr                             LpnRec;
4571    l_item_attr                            ItemRec;
4572    l_old_loc_current_weight               NUMBER := 0;
4573    l_old_loc_available_weight             NUMBER;
4574    l_old_loc_current_vol                  NUMBER;
4575    l_old_loc_available_vol                NUMBER;
4576    l_old_loc_current_units                NUMBER := 0;
4577    l_old_loc_available_units              NUMBER;
4578    l_loc_current_weight                   NUMBER := 0;
4579    l_loc_available_weight                 NUMBER;
4580    l_loc_current_vol                      NUMBER := 0;
4581    l_loc_available_vol                    NUMBER;
4582    l_loc_current_units                    NUMBER := 0;
4583    l_loc_available_units                  NUMBER;
4584    l_quantity                             NUMBER := p_quantity;
4585    l_update_table                         BOOLEAN := TRUE;
4586    l_content_lpn_quantity                 NUMBER;
4587 
4588    l_proc_name                    VARCHAR2(50) := 'UPD_LPN_LOC_CPTY_FOR_XFR:';
4589    l_debug                        NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4590 BEGIN
4591    x_return_status := FND_API.G_RET_STS_SUCCESS;
4592 
4593    /*--------------------------------------------------------------------------------------------
4594      Fetch the actual Inventory Location ID for the source Locator.
4595      --------------------------------------------------------------------------------------------*/
4596 
4597    IF (l_debug = 1) THEN
4598       mdebug(l_proc_name||'From Organization Id :'||l_old_organization_id);
4599       mdebug(l_proc_name||'From Locator ID      :'||l_old_locator_id);
4600    END IF;
4601    fetch_locator(
4602             p_inventory_location_id          =>    l_old_locator_id
4603           , p_organization_id                =>    l_old_organization_id
4604           , x_locator_id                     =>    l_old_inventory_location_id
4605           );
4606 
4607    -- Bug# 3067627
4608    IF (l_debug = 1) THEN
4609       mdebug('Before locking source locator ' || l_old_inventory_location_id || ' in UPD_LPN_LOC_CPTY_FOR_XFR');
4610    END IF;
4611 
4612    SELECT inventory_location_id INTO l_old_inventory_location_id
4613    FROM mtl_item_locations
4614    WHERE  inventory_location_id = l_old_inventory_location_id
4615        and organization_id = l_old_organization_id
4616    FOR UPDATE NOWAIT;
4617 
4618    IF (l_debug = 1) THEN
4619       mdebug('After locking source locator ' || l_old_inventory_location_id || ' in UPD_LPN_LOC_CPTY_FOR_XFR');
4620    END IF;
4621 
4622    /*---------------------------------------------------------------------------------------------
4623      Fetch the Source locator's current capacity.
4624      ---------------------------------------------------------------------------------------------*/
4625    fetch_loc_curr_capacity(
4626             p_inventory_location_id          =>    l_old_inventory_location_id
4627           , p_organization_id                =>    l_old_organization_id
4628           , x_loc_attr                       =>    l_old_loc_attr
4629           );
4630 
4631    IF (l_debug = 1) THEN
4632       mdebug(l_proc_name||'At the start of the program             : ');
4633       mdebug(l_proc_name||'The Source locator id used is           : '||l_old_inventory_location_id);
4634       mdebug(l_proc_name||'The attributes of Source locator follow : ');
4635       mdebug(l_proc_name||'l_Source_locator_weight_uom_code        : '||l_old_loc_attr.l_locator_weight_uom_code);
4636       mdebug(l_proc_name||'l_Source_locator_max_weight             : '||l_old_loc_attr.l_locator_max_weight);
4637       mdebug(l_proc_name||'l_Source_locator_suggested_weight       : '||l_old_loc_attr.l_locator_suggested_weight);
4638       mdebug(l_proc_name||'l_Source_locator_suggested_cubic_area   : '||l_old_loc_attr.l_locator_suggested_cubic_area);
4639       mdebug(l_proc_name||'l_Source_locator_current_weight         : '||l_old_loc_attr.l_locator_current_weight);
4640       mdebug(l_proc_name||'l_Source_locator_available_weight       : '||l_old_loc_attr.l_locator_available_weight);
4641       mdebug(l_proc_name||'l_Source_locator_volume_uom_code        : '||l_old_loc_attr.l_locator_volume_uom_code);
4642       mdebug(l_proc_name||'l_Source_locator_max_cubic_area         : '||l_old_loc_attr.l_locator_max_cubic_area);
4643       mdebug(l_proc_name||'l_Source_locator_current_cubic_area     : '||l_old_loc_attr.l_locator_current_cubic_area);
4644       mdebug(l_proc_name||'l_Source_locator_available_cubic_area   : '||l_old_loc_attr.l_locator_available_cubic_area);
4645       mdebug(l_proc_name||'l_Source_locator_max_units              : '||l_old_loc_attr.l_locator_maximum_units);
4646       mdebug(l_proc_name||'l_Source_locator_current_units          : '||l_old_loc_attr.l_locator_current_units);
4647       mdebug(l_proc_name||'l_Source_locator_available_units        : '||l_old_loc_attr.l_locator_available_units);
4648       mdebug(l_proc_name||'l_Source_locator_suggested_units        : '||l_old_loc_attr.l_locator_suggested_units);
4649       mdebug(l_proc_name||'transaction quantity                    : '||l_quantity);
4650     END IF;
4651 
4652     /*-------------------------------------------------------------------------------------------------------
4653       Get the attributes for the inventory_item_id that is passed as input parameter in source locators units
4654       -------------------------------------------------------------------------------------------------------*/
4655 
4656     IF  p_inventory_item_id IS NOT NULL AND p_inventory_item_id <>-1 THEN
4657         fetch_item_attributes(
4658      	      x_return_status            =>    x_return_status
4659           , x_msg_data                 =>    x_msg_data
4660           , x_msg_count                =>    x_msg_count
4661           , x_item_attr                =>    l_item_attr
4662           , p_inventory_item_id        =>    p_inventory_item_id
4663           , p_transaction_uom_code     =>    p_transaction_uom_code
4664           , p_primary_uom_flag         =>    p_primary_uom_flag
4665           , p_locator_weight_uom_code  =>    l_old_loc_attr.l_locator_weight_uom_code
4666           , p_locator_volume_uom_code  =>    l_old_loc_attr.l_locator_volume_uom_code
4667           , p_quantity                 =>    p_quantity
4668           , p_organization_id          =>    l_old_organization_id
4669           , p_container_item           =>    null
4670           );
4671         IF x_return_status =fnd_api.g_ret_sts_error THEN
4672            RAISE fnd_api.g_exc_error;
4673         ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error   THEN
4674            RAISE fnd_api.g_exc_unexpected_error;
4675         END IF;
4676 
4677         IF (l_debug = 1) THEN
4678            mdebug(l_proc_name||'The item weight UOM code  : '||l_item_attr.l_item_weight_uom_code);
4679            mdebug(l_proc_name||'item unit weight          : '||l_item_attr.l_item_unit_weight);
4680            mdebug(l_proc_name||'item volume UOM code      : '||l_item_attr.l_item_volume_uom_code);
4681            mdebug(l_proc_name||'item unit volume          : '||l_item_attr.l_item_unit_volume);
4682            mdebug(l_proc_name||'item extracted weight     : '||l_item_attr.l_item_xacted_weight);
4683            mdebug(l_proc_name||'item extracted volume     : '||l_item_attr.l_item_xacted_volume);
4684            mdebug(l_proc_name||'inventory item id         : '||p_inventory_item_id);
4685            mdebug(l_proc_name||'transaction uom code      : '||p_transaction_uom_code);
4686            mdebug(l_proc_name||'primary UOM flag          : '||p_primary_uom_flag);
4687            mdebug(l_proc_name||'locator weight UOM code   : '||l_old_loc_attr.l_locator_weight_uom_code);
4688            mdebug(l_proc_name||'locator volume UOM code   : '||l_old_loc_attr.l_locator_volume_uom_code);
4689            mdebug(l_proc_name||'transacted quantity       : '||p_quantity);
4690            mdebug(l_proc_name||'Organization id           : '||l_old_organization_id);
4691            mdebug(l_proc_name||'container item            : ');
4692          END IF;
4693     END IF;
4694 
4695     /*------------------------------------------------------------------------------------
4696       Fetch the attributes of Content LPN if passed, in Source locator's Units
4697       ------------------------------------------------------------------------------------*/
4698 
4699     IF p_content_lpn_id is not null THEN
4700        fetch_content_lpn_attr
4701           (
4702             x_return_status                =>    x_return_status
4703           , x_msg_data                     =>    x_msg_data
4704           , x_msg_count                    =>    x_msg_count
4705           , x_cnt_lpn_attr                 =>    l_cnt_lpn_attr
4706           , x_cnt_lpn_qty                  =>    l_content_lpn_quantity
4707           , p_lpn_id                       =>    p_content_lpn_id
4708           , p_org_id                       =>    p_organization_id
4709           , p_locator_volume_uom_code      =>    l_old_loc_attr.l_locator_volume_uom_code
4710           , p_locator_weight_uom_code      =>    l_old_loc_attr.l_locator_weight_uom_code
4711           );
4712         IF x_return_status =fnd_api.g_ret_sts_error THEN
4713            RAISE fnd_api.g_exc_error;
4714         ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error   THEN
4715            RAISE fnd_api.g_exc_unexpected_error;
4716         END IF;
4717         IF p_inventory_item_id = -1 THEN
4718            l_quantity := l_content_lpn_quantity;
4719         END IF;
4720         IF (l_debug = 1) THEN
4721            mdebug(l_proc_name||'l_cnt_gross_weight_uom_code    : '||l_cnt_lpn_attr.l_gross_weight_uom_code);
4722            mdebug(l_proc_name||'l_cnt_content_volume_uom_code  : '||l_cnt_lpn_attr.l_content_volume_uom_code);
4723            mdebug(l_proc_name||'l_cnt_gross_weight             : '||l_cnt_lpn_attr.l_gross_weight);
4724            mdebug(l_proc_name||'l_cnt_content_volume           : '||l_cnt_lpn_attr.l_content_volume);
4725            mdebug(l_proc_name||'l_cnt_container_item_weight    : '||l_cnt_lpn_attr.l_container_item_weight);
4726            mdebug(l_proc_name||'l_cnt_container_item_vol       : '||l_cnt_lpn_attr.l_container_item_vol);
4727            mdebug(l_proc_name||'l_cnt_lpn_exists_in_locator    : '||l_cnt_lpn_attr.l_lpn_exists_in_locator);
4728            mdebug(l_proc_name||'p_content_lpn_id               : '||p_content_lpn_id);
4729            mdebug(l_proc_name||'p_organization_id              : '||p_organization_id);
4730            mdebug(l_proc_name||'locator weight UOM code        : '||l_old_loc_attr.l_locator_weight_uom_code);
4731            mdebug(l_proc_name||'lpn content qty                : '||l_quantity);
4732          END IF;
4733     END IF; /* End of p_content_lpn_id is not null */
4734 
4735     /*----------------------------------------------------------------------------------------
4736       Fetch the attributes of LPN if passed, in Source Locator's UOM
4737       ----------------------------------------------------------------------------------------*/
4738 
4739     IF p_lpn_id is not null THEN
4740        fetch_lpn_attr
4741           (
4742             x_return_status                =>    x_return_status
4743           , x_msg_data                     =>    x_msg_data
4744           , x_msg_count                    =>    x_msg_count
4745           , x_lpn_attr                     =>    l_lpn_attr
4746           , p_lpn_id                       =>    p_lpn_id
4747           , p_org_id                       =>    p_organization_id
4748           , p_locator_volume_uom_code      =>    l_old_loc_attr.l_locator_volume_uom_code
4749           , p_locator_weight_uom_code      =>    l_old_loc_attr.l_locator_weight_uom_code
4750           );
4751         IF x_return_status =fnd_api.g_ret_sts_error THEN
4752            RAISE fnd_api.g_exc_error;
4753         ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error   THEN
4754            RAISE fnd_api.g_exc_unexpected_error;
4755         END IF;
4756         IF (l_debug = 1) THEN
4757            mdebug(l_proc_name||'l_lpn_gross_weight_uom_code    : '||l_lpn_attr.l_gross_weight_uom_code);
4758            mdebug(l_proc_name||'l_lpn_content_volume_uom_code  : '||l_lpn_attr.l_content_volume_uom_code);
4759            mdebug(l_proc_name||'l_lpn_gross_weight             : '||l_lpn_attr.l_gross_weight);
4760            mdebug(l_proc_name||'l_lpn_content_volume           : '||l_lpn_attr.l_content_volume);
4761            mdebug(l_proc_name||'l_lpn_container_item_weight    : '||l_lpn_attr.l_container_item_weight);
4762            mdebug(l_proc_name||'l_lpn_container_item_vol       : '||l_lpn_attr.l_container_item_vol);
4763            mdebug(l_proc_name||'l_lpn_exists_in_locator        : '||l_lpn_attr.l_lpn_exists_in_locator);
4764            mdebug(l_proc_name||'p_lpn_id                       : '||p_lpn_id);
4765            mdebug(l_proc_name||'p_organization_id              : '||p_organization_id);
4766            mdebug(l_proc_name||'locator weight UOM code        : '||l_old_loc_attr.l_locator_weight_uom_code);
4767            mdebug(l_proc_name||'locator volume UOM code        : '||l_old_loc_attr.l_locator_volume_uom_code);
4768          END IF;
4769     END IF; /*End of if lpn */
4770 
4771     /*-------------------------------------------------------------------------------------------------------
4772       First Update the Source Locator's Capacity.
4773         * If content lpn is passed  => Issue the lpn from the source locator.
4774         * If lpn id is passed       => check whether the whole lpn is being transfered or not. if so, need to
4775                                        decrement the container weight and volume, else decrement the transacted
4776                                        items weight and volume.
4777       Then Update the destination Locator's capacity.
4778         * If content lpn is passesd  => receive into it.
4779         * If transfer lpn is passed  => receive into it.
4780         * else                       => receive loose
4781       -------------------------------------------------------------------------------------------------------*/
4782 /* Do update the locator capacity only if the locator capacity is finite */
4783   IF NOT (l_old_loc_attr.l_locator_maximum_units IS NULL AND l_old_loc_attr.l_locator_max_weight IS NULL AND l_old_loc_attr.l_locator_max_cubic_area IS NULL) THEN
4784 
4785     IF p_content_lpn_id IS NOT NULL THEN
4786        /*-----------------------------------------------------------------
4787          Issue Content LPN from the source locator
4788          -----------------------------------------------------------------*/
4789        upd_lpn_loc_cpty_for_issue(
4790             x_return_status                   =>        x_return_status
4791           , x_msg_data                        =>        x_msg_data
4792           , x_msg_count                       =>        x_msg_count
4793           , p_loc_attr                        =>        l_old_loc_attr
4794           , p_content_lpn_id                  =>        p_content_lpn_id
4795           , p_cnt_lpn_attr                    =>        l_cnt_lpn_attr
4796           , p_transaction_action_id           =>        1
4797           , p_item_attr                       =>        p_item_attr
4798           , p_quantity                        =>        l_quantity
4799           , p_inventory_location_id           =>        l_old_inventory_location_id
4800           , p_organization_id                 =>        l_old_organization_id
4801           );
4802        IF x_return_status =fnd_api.g_ret_sts_error THEN
4803           RAISE fnd_api.g_exc_error;
4804        ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error   THEN
4805           RAISE fnd_api.g_exc_unexpected_error;
4806        END IF;
4807        l_update_table := FALSE;
4808     ELSIF p_lpn_id IS NOT NULL THEN
4809           fetch_lpn_content_qty(
4810                                  p_lpn_id       =>    p_lpn_id
4811                                , x_quantity     =>    l_quantity
4812                                );
4813           IF p_quantity = l_quantity THEN
4814              /*-----------------------------------------------------------------
4815                Issue LPN from the source locator
4816                -----------------------------------------------------------------*/
4817              upd_lpn_loc_cpty_for_issue(
4818                   x_return_status                   =>        x_return_status
4819                 , x_msg_data                        =>        x_msg_data
4820                 , x_msg_count                       =>        x_msg_count
4821                 , p_loc_attr                        =>        l_old_loc_attr
4822                 , p_content_lpn_id                  =>        p_lpn_id
4823                 , p_cnt_lpn_attr                    =>        l_lpn_attr
4824                 , p_transaction_action_id           =>        1
4825                 , p_item_attr                       =>        p_item_attr
4826                 , p_quantity                        =>        l_quantity
4827                 , p_inventory_location_id           =>        l_old_inventory_location_id
4828                 , p_organization_id                 =>        l_old_organization_id
4829                 );
4830              IF x_return_status =fnd_api.g_ret_sts_error THEN
4831                 RAISE fnd_api.g_exc_error;
4832              ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error   THEN
4833                 RAISE fnd_api.g_exc_unexpected_error;
4834              END IF;
4835              l_update_table := FALSE;
4836           ELSE
4837              /*-----------------------------------------------------------------
4838                Issue transacted Item Capacity from the source locator (LPN)
4839                -----------------------------------------------------------------*/
4840              l_old_loc_current_weight   := l_old_loc_attr.l_locator_current_weight - l_item_attr.l_item_xacted_weight;
4841              IF l_old_loc_current_weight <0 THEN
4842                 l_old_loc_current_weight := 0;
4843              END IF;
4844 
4845              l_old_loc_available_weight := l_old_loc_attr.l_locator_max_weight - ( l_old_loc_current_weight +
4846                                                l_old_loc_attr.l_locator_suggested_weight);
4847              IF l_old_loc_available_weight <0 THEN
4848                 l_old_loc_available_weight := 0;
4849              END IF;
4850 
4851 
4852              l_old_loc_current_units   :=  l_old_loc_attr.l_locator_current_units - p_quantity;
4853 
4854              IF l_old_loc_current_units <0 THEN
4855                 l_old_loc_current_units := 0;
4856              END IF;
4857 
4858              l_old_loc_available_units := l_old_loc_attr.l_locator_maximum_units - ( l_old_loc_current_units +
4859                                           l_old_loc_attr.l_locator_suggested_units);
4860              IF l_old_loc_available_units <0 THEN
4861                 l_old_loc_available_units := 0;
4862              END IF;
4863 
4864              IF l_lpn_attr.l_content_volume > l_lpn_attr.l_container_item_vol THEN
4865                 IF l_lpn_attr.l_container_item_vol = 0
4866                    OR (l_lpn_attr.l_content_volume - l_item_attr.l_item_xacted_volume
4867                                                  >= l_lpn_attr.l_container_item_vol) THEN
4868                    l_old_loc_current_vol := l_old_loc_attr.l_locator_current_cubic_area - l_item_attr.l_item_xacted_volume;
4869                 ELSIF (l_lpn_attr.l_content_volume - l_item_attr.l_item_xacted_volume
4870                                                  < l_lpn_attr.l_container_item_vol) THEN
4871                    l_old_loc_current_vol := l_old_loc_attr.l_locator_current_cubic_area -
4872                                             ( l_lpn_attr.l_content_volume - l_lpn_attr.l_container_item_vol );
4873                 END IF;
4874              END IF;
4875 
4876              IF l_old_loc_current_vol < 0 THEN
4877                 l_old_loc_current_vol := 0;
4878              END IF;
4879 
4880              l_old_loc_available_vol := l_old_loc_attr.l_locator_max_cubic_area - ( l_old_loc_current_vol
4881                                                                 + l_old_loc_attr.l_locator_suggested_cubic_area);
4882              IF l_old_loc_available_vol < 0 THEN
4883                 l_old_loc_available_vol := 0;
4884              END IF;
4885           END IF;
4886     ELSE
4887        /*-----------------------------------------------------------------
4888          Issue transacted Item Capacity from the source locator (LPN)
4889          -----------------------------------------------------------------*/
4890        l_old_loc_current_weight   := l_old_loc_attr.l_locator_current_weight - l_item_attr.l_item_xacted_weight;
4891        IF l_old_loc_current_weight <0 THEN
4892           l_old_loc_current_weight := 0;
4893        END IF;
4894 
4895        l_old_loc_available_weight := l_old_loc_attr.l_locator_max_weight - ( l_old_loc_current_weight +
4896                                          l_old_loc_attr.l_locator_suggested_weight);
4897        IF l_old_loc_available_weight <0 THEN
4898           l_old_loc_available_weight := 0;
4899        END IF;
4900 
4901 
4902        l_old_loc_current_units   :=  l_old_loc_attr.l_locator_current_units - p_quantity;
4903 
4904        IF l_old_loc_current_units <0 THEN
4905           l_old_loc_current_units := 0;
4906        END IF;
4907 
4908        l_old_loc_available_units := l_old_loc_attr.l_locator_maximum_units - ( l_old_loc_current_units +
4909                                     l_old_loc_attr.l_locator_suggested_units);
4910        IF l_old_loc_available_units <0 THEN
4911           l_old_loc_available_units := 0;
4912        END IF;
4913 
4914        l_old_loc_current_vol := l_old_loc_attr.l_locator_current_cubic_area - l_item_attr.l_item_xacted_volume;
4915        IF l_old_loc_current_vol < 0 THEN
4916           l_old_loc_current_vol := 0;
4917        END IF;
4918 
4919        l_old_loc_available_vol := l_old_loc_attr.l_locator_max_cubic_area - ( l_old_loc_current_vol
4920                                                           + l_old_loc_attr.l_locator_suggested_cubic_area);
4921        IF l_old_loc_available_vol < 0 THEN
4922           l_old_loc_available_vol := 0;
4923        END IF;
4924   END IF;
4925 
4926   IF l_update_table THEN
4927      UPDATE MTL_ITEM_LOCATIONS
4928         SET current_weight           = nvl(l_old_loc_current_weight,current_weight)
4929           , available_weight         = nvl(l_old_loc_available_weight,available_weight)
4930           , current_cubic_area       = nvl(l_old_loc_current_vol,current_cubic_area)
4931           , available_cubic_area     = nvl(l_old_loc_available_vol,available_cubic_area)
4932           , location_current_units   = nvl(l_old_loc_current_units,location_current_units)
4933           , location_available_units = nvl(l_old_loc_available_units,location_available_units)
4934       WHERE inventory_location_id    = l_old_inventory_location_id
4935         AND organization_id          = l_old_organization_id;
4936   END IF;
4937   END IF; /* Update locator capacity only if the locator capacity is finite */
4938 
4939 /* Do update the locator capacity only if the locator capacity is finite */
4940  IF NOT (p_loc_attr.l_locator_maximum_units IS NULL AND p_loc_attr.l_locator_max_weight IS NULL AND p_loc_attr.l_locator_max_cubic_area IS NULL) THEN
4941 
4942     IF p_trn_lpn_id IS NOT NULL THEN
4943        /*-----------------------------------------------------------------
4944          Receive the transfer LPN into the destination Locator.
4945          -----------------------------------------------------------------*/
4946        upd_lpn_loc_cpty_for_rcpt (
4947             x_return_status                   =>        x_return_status
4948           , x_msg_data                        =>        x_msg_data
4949           , x_msg_count                       =>        x_msg_count
4950           , p_loc_attr                        =>        p_loc_attr
4951           , p_transfer_lpn_id                 =>        p_trn_lpn_id
4952           , p_trn_lpn_attr                    =>        p_trn_lpn_attr
4953           , p_transaction_action_id           =>        27
4954           , p_item_attr                       =>        p_item_attr
4955           , p_quantity                        =>        p_quantity
4956           , p_inventory_location_id           =>        p_inventory_location_id
4957           , p_organization_id                 =>        p_organization_id
4958           );
4959        IF x_return_status =fnd_api.g_ret_sts_error THEN
4960           RAISE fnd_api.g_exc_error;
4961        ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error   THEN
4962           RAISE fnd_api.g_exc_unexpected_error;
4963        END IF;
4964     ELSIF p_content_lpn_id IS NOT NULL THEN
4965         /*-----------------------------------------------------------------
4966          Receive the Content LPN into the destination Locator.
4967          -----------------------------------------------------------------*/
4968        upd_lpn_loc_cpty_for_rcpt (
4969             x_return_status                   =>        x_return_status
4970           , x_msg_data                        =>        x_msg_data
4971           , x_msg_count                       =>        x_msg_count
4972           , p_loc_attr                        =>        p_loc_attr
4973           , p_transfer_lpn_id                 =>        p_content_lpn_id
4974           , p_trn_lpn_attr                    =>        p_cnt_lpn_attr
4975           , p_transaction_action_id           =>        27
4976           , p_item_attr                       =>        p_item_attr
4977           , p_quantity                        =>        l_quantity
4978           , p_inventory_location_id           =>        p_inventory_location_id
4979           , p_organization_id                 =>        p_organization_id
4980           );
4981        IF x_return_status =fnd_api.g_ret_sts_error THEN
4982           RAISE fnd_api.g_exc_error;
4983        ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error   THEN
4984           RAISE fnd_api.g_exc_unexpected_error;
4985        END IF;
4986     ELSE
4987        /*-------------------------------------------------------------------
4988          Receive transacted loose Item Capacity into the destination locator
4989          -------------------------------------------------------------------*/
4990        l_loc_current_weight   := p_loc_attr.l_locator_current_weight + p_item_attr.l_item_xacted_weight;
4991        IF l_loc_current_weight <0 THEN
4992           l_loc_current_weight := 0;
4993        END IF;
4994 
4995        l_loc_available_weight := p_loc_attr.l_locator_max_weight - ( l_loc_current_weight +
4996                                          p_loc_attr.l_locator_suggested_weight);
4997        IF l_loc_available_weight <0 THEN
4998           l_loc_available_weight := 0;
4999        END IF;
5000 
5001        l_loc_current_units   :=  p_loc_attr.l_locator_current_units + p_quantity;
5002 
5003        IF l_loc_current_units <0 THEN
5004           l_loc_current_units := 0;
5005        END IF;
5006 
5007        l_loc_available_units := p_loc_attr.l_locator_maximum_units - ( l_loc_current_units +
5008                                     p_loc_attr.l_locator_suggested_units);
5009        IF l_loc_available_units <0 THEN
5010           l_loc_available_units := 0;
5011        END IF;
5012 
5013        l_loc_current_vol := p_loc_attr.l_locator_current_cubic_area + p_item_attr.l_item_xacted_volume;
5014 
5015        IF l_loc_current_vol < 0 THEN
5016           l_loc_current_vol := 0;
5017        END IF;
5018 
5019        l_loc_available_vol := p_loc_attr.l_locator_max_cubic_area - ( l_loc_current_vol
5020                                                           + p_loc_attr.l_locator_suggested_cubic_area);
5021        IF l_loc_available_vol < 0 THEN
5022           l_loc_available_vol := 0;
5023        END IF;
5024 
5025        UPDATE MTL_ITEM_LOCATIONS
5026           SET current_weight           = nvl(l_loc_current_weight,current_weight)
5027             , available_weight         = nvl(l_loc_available_weight,available_weight)
5028             , current_cubic_area       = nvl(l_loc_current_vol,current_cubic_area)
5029             , available_cubic_area     = nvl(l_loc_available_vol,available_cubic_area)
5030             , location_current_units   = nvl(l_loc_current_units,location_current_units)
5031             , location_available_units = nvl(l_loc_available_units,location_available_units)
5032         WHERE inventory_location_id    = p_inventory_location_id
5033           AND organization_id          = p_organization_id;
5034     END IF;
5035    END IF; /* Update locator capacity only if the locator capacity is finite */
5036 END upd_lpn_loc_cpty_for_xfr;
5037 
5038 PROCEDURE upd_lpn_loc_cpty_for_unpack
5039    (
5040      x_return_status                 OUT    NOCOPY VARCHAR2
5041    , x_msg_data                      OUT    NOCOPY VARCHAR2
5042    , x_msg_count                     OUT    NOCOPY NUMBER
5043    , p_content_lpn_id                IN            NUMBER
5044    , p_cnt_lpn_attr                  IN            LpnRec
5045    , p_lpn_id                        IN            NUMBER
5046    , p_lpn_attr                      IN            LpnRec
5047    , p_inventory_location_id         IN            NUMBER
5048    , p_loc_attr                      IN            LocatorRec
5049    , p_organization_id               IN            NUMBER
5050    , p_item_attr                     IN            ItemRec
5051    , p_quantity                      IN            NUMBER
5052    )
5053 IS
5054    l_proc_name                    VARCHAR2(50) := 'UPD_LPN_LOC_CPTY_FOR_UNPACK:';
5055    l_locator_current_cubic_area   NUMBER := 0;
5056    l_locator_available_cubic_area NUMBER;
5057    l_locator_current_weight       NUMBER := 0;
5058    l_locator_available_weight     NUMBER;
5059    l_debug                        NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5060    l_content_qty                  NUMBER;
5061    l_lpn_qty                      NUMBER;
5062    l_content_lpn_vol              NUMBER;
5063 BEGIN
5064   x_return_status := FND_API.G_RET_STS_SUCCESS;
5065   l_locator_current_weight   := p_loc_attr.l_locator_current_weight;
5066   l_locator_available_weight := p_loc_attr.l_locator_available_weight;
5067   /*-------------------------------------------------------------------------------------------------
5068     Content LPN is null. UnPack material to loose.
5069     -------------------------------------------------------------------------------------------------*/
5070   IF p_content_lpn_id  IS NULL THEN
5071     IF (l_debug = 1) THEN
5072        mdebug(l_proc_name||'The p_content_id is null  -case Unpack ');
5073     END IF;
5074       INV_LOC_WMS_UTILS.cal_locator_current_volume(
5075                 x_return_status               =>       x_return_status
5076               , x_msg_data                    =>       x_msg_data
5077               , x_msg_count                   =>       x_msg_count
5078               , x_locator_current_volume      =>       l_locator_current_cubic_area
5079               , p_trn_lpn_container_item_vol  =>       NULL
5080               , p_trn_lpn_content_volume      =>       NULL
5081               , p_cnt_lpn_container_item_vol  =>       null
5082               , p_cnt_lpn_content_volume      =>       null
5083               , p_lpn_container_item_vol      =>       p_lpn_attr.l_container_item_vol
5084               , p_lpn_content_volume          =>       p_lpn_attr.l_content_volume
5085               , p_xacted_volume               =>       p_item_attr.l_item_xacted_volume
5086               , p_locator_current_cubic_area  =>       p_loc_attr.l_locator_current_cubic_area
5087               , p_transaction_action_id       =>       51
5088               , p_transfer_lpn_id             =>       NULL
5089               , p_content_lpn_id              =>       null
5090               , p_lpn_id                      =>       p_lpn_id
5091               , p_trn_lpn_exists_in_loc       =>       p_lpn_attr.l_lpn_exists_in_locator
5092               );
5093     ELSE
5094     /*-------------------------------------------------------------------------------------------------
5095       Content LPN is NOT null. UnPack lpn from another LPN.
5096       -------------------------------------------------------------------------------------------------*/
5097     IF (l_debug = 1) THEN
5098        mdebug(l_proc_name||'The P_content_lpn_id is not null -case Unpack ');
5099     END IF;
5100 
5101     INV_LOC_WMS_UTILS.cal_locator_current_volume(
5102               x_return_status               =>       x_return_status
5103             , x_msg_data                    =>       x_msg_data
5104             , x_msg_count                   =>       x_msg_count
5105             , x_locator_current_volume      =>       l_locator_current_cubic_area
5106             , p_trn_lpn_container_item_vol  =>       NULL
5107             , p_trn_lpn_content_volume      =>       NULL
5108             , p_cnt_lpn_container_item_vol  =>       p_cnt_lpn_attr.l_container_item_vol
5109             , p_cnt_lpn_content_volume      =>       p_cnt_lpn_attr.l_content_volume
5110             , p_lpn_container_item_vol      =>       p_lpn_attr.l_container_item_vol
5111             , p_lpn_content_volume          =>       p_lpn_attr.l_content_volume
5112             , p_xacted_volume               =>       p_cnt_lpn_attr.l_content_volume
5113             , p_locator_current_cubic_area  =>       p_loc_attr.l_locator_current_cubic_area
5114             , p_transaction_action_id       =>       51
5115             , p_transfer_lpn_id             =>       NULL
5116             , p_content_lpn_id              =>       p_content_lpn_id
5117             , p_lpn_id                      =>       p_lpn_id
5118             , p_trn_lpn_exists_in_loc       =>       p_lpn_attr.l_lpn_exists_in_locator
5119             );
5120     END IF;
5121        IF (p_cnt_lpn_attr.l_content_volume < p_cnt_lpn_attr.l_container_item_vol)  THEN
5122           l_content_lpn_vol := p_cnt_lpn_attr.l_container_item_vol;
5123        ELSE
5124           l_content_lpn_vol := p_cnt_lpn_attr.l_content_volume;
5125        END IF;
5126        /* check if the entire LPN is being unpacked, if so then subtract the container capacity */
5127        IF (p_content_lpn_id IS NULL AND p_lpn_attr.l_content_volume = p_item_attr.l_item_xacted_volume) OR
5128            (p_content_lpn_id IS NOT NULL AND p_lpn_attr.l_content_volume = l_content_lpn_vol)
5129        THEN
5130               l_locator_current_weight   := l_locator_current_weight - p_lpn_attr.l_container_item_weight;
5131               l_locator_available_weight := p_loc_attr.l_locator_max_weight - ( l_locator_current_weight
5132                                                                 +  p_loc_attr.l_locator_suggested_weight);
5133               l_locator_current_cubic_area := l_locator_current_cubic_area - p_lpn_attr.l_container_item_vol;
5134               IF (l_debug = 1) THEN
5135                  mdebug(l_proc_name||'l_locator_current_weight    : '||l_locator_current_weight);
5136                  mdebug(l_proc_name||'l_locator_current_cubic_area: '||l_locator_current_cubic_area);
5137               END IF;
5138        END IF;
5139 
5140     l_locator_available_cubic_area := p_loc_attr.l_locator_max_cubic_area - (l_locator_current_cubic_area
5141                                                                   + p_loc_attr.l_locator_suggested_cubic_area);
5142     IF l_locator_available_cubic_area < 0 THEN
5143        l_locator_available_cubic_area := 0;
5144     END IF;
5145 
5146     UPDATE MTL_ITEM_LOCATIONS
5147        SET current_cubic_area    = nvl(l_locator_current_cubic_area,current_cubic_area)
5148          , available_cubic_area  = nvl(l_locator_available_cubic_area,available_cubic_area)
5149          , current_weight        = nvl(l_locator_current_weight,current_weight)
5150          , available_weight      = nvl(l_locator_available_weight,available_weight)
5151      WHERE inventory_location_id = p_inventory_location_id
5152        AND organization_id       = p_organization_id;
5153 
5154     IF l_debug = 1 THEN
5155        mdebug(l_proc_name||'Locator Current Cubic Area after update  : '||l_locator_current_cubic_area);
5156        mdebug(l_proc_name||'Locator Available Cubic Area after update: '||l_locator_available_cubic_area);
5157        mdebug(l_proc_name||'Locator Current weight after update      : '||l_locator_current_weight);
5158        mdebug(l_proc_name||'Locator Available weight after update    : '||l_locator_available_weight);
5159     END IF;
5160 
5161 END upd_lpn_loc_cpty_for_unpack;
5162 
5163 PROCEDURE upd_lpn_loc_cpty_for_pack
5164    (
5165      x_return_status                 OUT    NOCOPY VARCHAR2
5166    , x_msg_data                      OUT    NOCOPY VARCHAR2
5167    , x_msg_count                     OUT    NOCOPY NUMBER
5168    , p_content_lpn_id                IN            NUMBER
5169    , p_cnt_lpn_attr                  IN            LpnRec
5170    , p_transfer_lpn_id               IN            NUMBER
5171    , p_trn_lpn_attr                  IN            LpnRec
5172    , p_inventory_location_id         IN            NUMBER
5173    , p_loc_attr                      IN            LocatorRec
5174    , p_organization_id               IN            NUMBER
5175    , p_item_attr                     IN            ItemRec
5176    , p_container_item_id             IN            NUMBER
5177    , p_cartonization_id              IN            NUMBER
5178    )
5179 IS
5180    l_proc_name                    VARCHAR2(50) := 'UPD_LPN_LOC_CPTY_FOR_PACK:';
5181    l_locator_current_cubic_area   NUMBER;
5182    l_locator_available_cubic_area NUMBER;
5183    l_locator_current_weight       NUMBER;
5184    l_locator_available_weight     NUMBER;
5185    l_debug                        NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5186    l_container_item_weight        NUMBER;
5187    l_container_item_vol           NUMBER;
5188    l_content_volume               NUMBER;
5189    l_lpn_exists_in_locator        VARCHAR2(1);
5190    l_container_item_attr          ItemRec;
5191 BEGIN
5192   x_return_status := FND_API.G_RET_STS_SUCCESS;
5193 
5194   --if it is a cartonization txn, the the lpn would not contain the container item weight and volume
5195   --yet.
5196   IF (l_debug = 1) THEN
5197      mdebug(l_proc_name||'cartonization id  : '||p_cartonization_id);
5198      mdebug(l_proc_name||'transfer lpn id   : '||p_transfer_lpn_id);
5199      mdebug(l_proc_name||'container item id : '||p_container_item_id);
5200   END IF;
5201 
5202   IF (p_cartonization_id IS NOT NULL AND p_cartonization_id = p_transfer_lpn_id) THEN
5203      fetch_item_attributes(
5204          x_return_status            =>    x_return_status
5205        , x_msg_data                 =>    x_msg_data
5206        , x_msg_count                =>    x_msg_count
5207        , x_item_attr                =>    l_container_item_attr
5208        , p_inventory_item_id        =>    p_container_item_id
5209        , p_transaction_uom_code     =>    NULL
5210        , p_primary_uom_flag         =>    NULL
5211        , p_locator_weight_uom_code  =>    p_loc_attr.l_locator_weight_uom_code
5212        , p_locator_volume_uom_code  =>    p_loc_attr.l_locator_volume_uom_code
5213        , p_quantity                 =>    NULL
5214        , p_organization_id          =>    p_organization_id
5215        , p_container_item           =>    'Y'
5216        );
5217      IF x_return_status =fnd_api.g_ret_sts_error THEN
5218         RAISE fnd_api.g_exc_error;
5219      ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error   THEN
5220         RAISE fnd_api.g_exc_unexpected_error;
5221      END IF;
5222 
5223      IF (l_debug = 1) THEN
5224         mdebug(l_proc_name||'The item weight UOM code  : '||l_container_item_attr.l_item_weight_uom_code);
5225         mdebug(l_proc_name||'item unit weight          : '||l_container_item_attr.l_item_unit_weight);
5226         mdebug(l_proc_name||'item volume UOM code      : '||l_container_item_attr.l_item_volume_uom_code);
5227         mdebug(l_proc_name||'item unit volume          : '||l_container_item_attr.l_item_unit_volume);
5228         mdebug(l_proc_name||'item extracted weight     : '||l_container_item_attr.l_item_xacted_weight);
5229         mdebug(l_proc_name||'item extracted volume     : '||l_container_item_attr.l_item_xacted_volume);
5230         mdebug(l_proc_name||'inventory item id         : '||p_container_item_id);
5231         mdebug(l_proc_name||'transaction uom code      : '||NULL);
5232         mdebug(l_proc_name||'primary UOM flag          : '||NULL);
5233         mdebug(l_proc_name||'locator weight UOM code   : '||p_loc_attr.l_locator_weight_uom_code);
5234         mdebug(l_proc_name||'locator volume UOM code   : '||p_loc_attr.l_locator_volume_uom_code);
5235         mdebug(l_proc_name||'transacted quantity       : '||NULL);
5236         mdebug(l_proc_name||'Organization id           : '||p_organization_id);
5237         mdebug(l_proc_name||'container item            : Y');
5238       END IF;
5239 
5240      l_container_item_weight := l_container_item_attr.l_item_unit_weight;
5241      l_container_item_vol    := l_container_item_attr.l_item_unit_volume   ;
5242      l_content_volume := 0;
5243      l_lpn_exists_in_locator := 'N';
5244   ELSE
5245      l_container_item_weight := p_trn_lpn_attr.l_container_item_weight;
5246      l_container_item_vol    := p_trn_lpn_attr.l_container_item_vol;
5247      l_content_volume        := p_trn_lpn_attr.l_content_volume;
5248      l_lpn_exists_in_locator := p_trn_lpn_attr.l_lpn_exists_in_locator;
5249   END IF;
5250 
5251   l_locator_current_weight   := p_loc_attr.l_locator_current_weight;
5252   l_locator_available_weight := p_loc_attr.l_locator_available_weight;
5253   IF p_trn_lpn_attr.l_lpn_exists_in_locator = 'N' THEN
5254      l_locator_current_weight := l_locator_current_weight + l_container_item_weight;
5255      l_locator_available_weight := p_loc_attr.l_locator_max_weight - ( l_locator_current_weight +
5256                                                             p_loc_attr.l_locator_suggested_weight);
5257   END IF;
5258 
5259   /*-------------------------------------------------------------------------------------------------
5260     Content LPN is null. Pack loose material into an LPN.
5261     -------------------------------------------------------------------------------------------------*/
5262   IF p_content_lpn_id  IS NULL THEN
5263     IF (l_debug = 1) THEN
5264        mdebug(l_proc_name||'The p_content_id is null  -case pack ');
5265     END IF;
5266       INV_LOC_WMS_UTILS.cal_locator_current_volume(
5267                 x_return_status               =>       x_return_status
5268               , x_msg_data                    =>       x_msg_data
5269               , x_msg_count                   =>       x_msg_count
5270               , x_locator_current_volume      =>       l_locator_current_cubic_area
5271               , p_trn_lpn_container_item_vol  =>       l_container_item_vol
5272               , p_trn_lpn_content_volume      =>       l_content_volume
5273               , p_cnt_lpn_container_item_vol  =>       null
5274               , p_cnt_lpn_content_volume      =>       null
5275               , p_lpn_container_item_vol      =>       null
5276               , p_lpn_content_volume          =>       null
5277               , p_xacted_volume               =>       p_item_attr.l_item_xacted_volume
5278               , p_locator_current_cubic_area  =>       p_loc_attr.l_locator_current_cubic_area
5279               , p_transaction_action_id       =>       50
5280               , p_transfer_lpn_id             =>       p_transfer_lpn_id
5281               , p_content_lpn_id              =>       null
5282               , p_lpn_id                      =>       null
5283               , p_trn_lpn_exists_in_loc       =>       l_lpn_exists_in_locator
5284               );
5285     ELSE
5286     /*-------------------------------------------------------------------------------------------------
5287       Content LPN is NOT null. Pack lpn into another LPN.
5288       -------------------------------------------------------------------------------------------------*/
5289     IF (l_debug = 1) THEN
5290        mdebug(l_proc_name||'The P_content_lpn_id is not null -case pack ');
5291     END IF;
5292     INV_LOC_WMS_UTILS.cal_locator_current_volume(
5293               x_return_status               =>       x_return_status
5294             , x_msg_data                    =>       x_msg_data
5295             , x_msg_count                   =>       x_msg_count
5296             , x_locator_current_volume      =>       l_locator_current_cubic_area
5297             , p_trn_lpn_container_item_vol  =>       l_container_item_vol
5298             , p_trn_lpn_content_volume      =>       l_content_volume
5299             , p_cnt_lpn_container_item_vol  =>       p_cnt_lpn_attr.l_container_item_vol
5300             , p_cnt_lpn_content_volume      =>       p_cnt_lpn_attr.l_content_volume
5301             , p_lpn_container_item_vol      =>       null
5302             , p_lpn_content_volume          =>       null
5303             , p_xacted_volume               =>       p_cnt_lpn_attr.l_content_volume
5304             , p_locator_current_cubic_area  =>       p_loc_attr.l_locator_current_cubic_area
5305             , p_transaction_action_id       =>       50
5306             , p_transfer_lpn_id             =>       p_transfer_lpn_id
5307             , p_content_lpn_id              =>       p_content_lpn_id
5308             , p_lpn_id                      =>       null
5309             , p_trn_lpn_exists_in_loc       =>       l_lpn_exists_in_locator
5310             );
5311     END IF;
5312 
5313     l_locator_available_cubic_area := p_loc_attr.l_locator_max_cubic_area - (l_locator_current_cubic_area
5314                                                                   + p_loc_attr.l_locator_suggested_cubic_area);
5315     IF l_locator_available_cubic_area < 0 THEN
5316        l_locator_available_cubic_area := 0;
5317     END IF;
5318 
5319     UPDATE MTL_ITEM_LOCATIONS
5320        SET current_cubic_area    = nvl(l_locator_current_cubic_area,current_cubic_area)
5321          , available_cubic_area  = nvl(l_locator_available_cubic_area,available_cubic_area)
5322          , current_weight        = nvl(l_locator_current_weight,current_weight)
5323          , available_weight      = nvl(l_locator_available_weight,available_weight)
5324      WHERE inventory_location_id = p_inventory_location_id
5325        AND organization_id       = p_organization_id;
5326 
5327     IF l_debug = 1 THEN
5328        mdebug(l_proc_name||'Locator Current Cubic Area after update  : '||l_locator_current_cubic_area);
5329        mdebug(l_proc_name||'Locator Available Cubic Area after update: '||l_locator_available_cubic_area);
5330        mdebug(l_proc_name||'Locator Current Weight After update      : '||l_locator_current_weight);
5331        mdebug(l_proc_name||'Locator Available Weight after update    : '||l_locator_available_weight);
5332     END IF;
5333 
5334 END upd_lpn_loc_cpty_for_pack;
5335 
5336 -- bug#2876849. Added the two new parameters from org id and from loc id. These are needed
5337 -- for a transfer transaction to decrement the capacity from the souce locator.
5338 
5339 PROCEDURE upd_lpn_loc_curr_cpty_nauto
5340   (  x_return_status             OUT NOCOPY VARCHAR2   -- return status (success/error/unexpected_error)
5341     ,x_msg_count                 OUT NOCOPY NUMBER     -- number of messages in the message queue
5342     ,x_msg_data                  OUT NOCOPY VARCHAR2   -- message text when x_msg_count>0
5343     ,p_organization_id           IN         NUMBER     -- org of locator whose capacity is to be determined
5344     ,p_inventory_location_id     IN         NUMBER     -- identifier of locator
5345     ,p_inventory_item_id         IN         NUMBER     -- identifier of item
5346     ,p_primary_uom_FLAG          IN         VARCHAR2   -- iF Y primary UOM
5347     ,p_transaction_uom_code      IN         VARCHAR2   -- UOM of the transacted material that causes the
5348 	    			                                        -- locator capacity to get updated
5349     ,p_transaction_action_id     IN         NUMBER     -- transaction action id for pack,unpack,issue,receive,
5350  					                                        -- transfer
5351     ,p_lpn_id                    IN         NUMBER     -- lpn id
5352     ,p_transfer_lpn_id		      IN         NUMBER     -- transfer_lpn_id
5353     ,p_content_lpn_id	         IN         NUMBER     -- content_lpn_id
5354     ,p_quantity                  IN         NUMBER     -- Primary quantity in primary UOM.
5355     ,p_container_item_id         IN         NUMBER     DEFAULT NULL
5356     ,p_cartonization_id          IN         NUMBER     DEFAULT NULL
5357     ,p_from_org_id               IN         NUMBER     DEFAULT NULL
5358     ,p_from_loc_id               IN         NUMBER     DEFAULT NULL
5359   )
5360 IS
5361      l_inventory_location_id           NUMBER;
5362      l_loc_attr                        LocatorRec;
5363      l_item_attr                       ItemRec;
5364      l_cnt_lpn_attr                    LpnRec;
5365      l_trn_lpn_attr                    LpnRec;
5366      l_lpn_attr                        LpnRec;
5367      l_quantity                        NUMBER := p_quantity;
5368 
5369      l_content_lpn_quantity            NUMBER;
5370 
5371     l_return_status                    VARCHAR2(1);
5372     l_msg_data                         VARCHAR2(1000);
5373     l_msg_count                        NUMBER;
5374     l_from_inventory_location_id       NUMBER;
5375     l_max_units                        NUMBER;
5376     l_max_weight                       NUMBER;
5377     l_max_cubic_area                   NUMBER;
5378 
5379 
5380 /* Debug Check */
5381     l_debug                            NUMBER       := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5382     l_proc_name                        VARCHAR2(50) := 'UPD_LPN_LOC_CURR_CPTY_NOAUTO:';
5383 BEGIN
5384 
5385    x_return_status := FND_API.G_RET_STS_SUCCESS;
5386 
5387    /*--------------------------------------------------------------------------------------------
5388      Fetch the actual Inventory Location ID
5389      --------------------------------------------------------------------------------------------*/
5390 
5391    fetch_locator(
5392             p_inventory_location_id          =>    p_inventory_location_id
5393           , p_organization_id                =>    p_organization_id
5394           , x_locator_id                     =>    l_inventory_location_id
5395           );
5396 
5397  /*
5398       ############# If the locator capacity is infinite, then dont update anything, simply return#############
5399       */
5400       SELECT location_maximum_units, max_weight, max_cubic_area
5401       INTO l_max_units, l_max_weight, l_max_cubic_area
5402       FROM mtl_item_locations_kfv
5403       WHERE organization_id        = p_organization_id
5404         AND inventory_location_id  = l_inventory_location_id;
5405 
5406       IF l_max_units IS NULL AND l_max_weight IS NULL AND l_max_cubic_area IS NULL AND p_transaction_action_id NOT IN (2,3,28) THEN
5407            return;
5408       ELSIF p_transaction_action_id IN (2,3,28) AND l_max_units IS NULL AND l_max_weight IS NULL AND l_max_cubic_area IS NULL THEN
5409              fetch_locator( /* Fetch the physical location id for the from locator */
5410                p_inventory_location_id          =>    p_from_loc_id
5411              , p_organization_id                =>    p_from_org_id
5412              , x_locator_id                     =>    l_from_inventory_location_id
5413              );
5414 
5415              SELECT location_maximum_units, max_weight, max_cubic_area
5416               INTO l_max_units, l_max_weight, l_max_cubic_area
5417               FROM mtl_item_locations_kfv
5418               WHERE organization_id         = p_from_org_id
5419                 AND inventory_location_id         = l_from_inventory_location_id;
5420 
5421              IF l_max_units IS NULL AND l_max_weight IS NULL AND l_max_cubic_area IS NULL THEN /* If from locator is infinite */
5422                    return;
5423              END IF;
5424 
5425       END IF;
5426 
5427    -- Bug# 3067627
5428    IF (l_debug = 1) THEN
5429       mdebug('Before locking locator ' || l_inventory_location_id || ' in UPD_LPN_LOC_CURR_CPTY_NOAUTO');
5430    END IF;
5431 
5432    SELECT inventory_location_id INTO l_inventory_location_id
5433    FROM mtl_item_locations
5434    WHERE  inventory_location_id = l_inventory_location_id
5435        and organization_id = p_organization_id
5436    FOR UPDATE NOWAIT;
5437 
5438    IF (l_debug = 1) THEN
5439       mdebug('After locking locator ' || l_inventory_location_id || ' in UPD_LPN_LOC_CURR_CPTY_NOAUTO');
5440    END IF;
5441 
5442    /*---------------------------------------------------------------------------------------------
5443      Fetch the locator's current capacity.
5444      ---------------------------------------------------------------------------------------------*/
5445    fetch_loc_curr_capacity(
5446             p_inventory_location_id          =>    l_inventory_location_id
5447           , p_organization_id                =>    p_organization_id
5448           , x_loc_attr                       =>    l_loc_attr
5449           );
5450 
5451    IF (l_debug = 1) THEN
5452       mdebug(l_proc_name||'At the start of the program      : ');
5453       mdebug(l_proc_name||'The locator id used is           : '||l_inventory_location_id);
5454       mdebug(l_proc_name||'The attributes of locator follow : ');
5455       mdebug(l_proc_name||'l_locator_weight_uom_code        : '||l_loc_attr.l_locator_weight_uom_code);
5456       mdebug(l_proc_name||'l_locator_max_weight             : '||l_loc_attr.l_locator_max_weight);
5457       mdebug(l_proc_name||'l_locator_suggested_weight       : '||l_loc_attr.l_locator_suggested_weight);
5458       mdebug(l_proc_name||'l_locator_suggested_cubic_area   : '||l_loc_attr.l_locator_suggested_cubic_area);
5459       mdebug(l_proc_name||'l_locator_current_weight         : '||l_loc_attr.l_locator_current_weight);
5460       mdebug(l_proc_name||'l_locator_available_weight       : '||l_loc_attr.l_locator_available_weight);
5461       mdebug(l_proc_name||'l_locator_volume_uom_code        : '||l_loc_attr.l_locator_volume_uom_code);
5462       mdebug(l_proc_name||'l_locator_max_cubic_area         : '||l_loc_attr.l_locator_max_cubic_area);
5463       mdebug(l_proc_name||'l_locator_current_cubic_area     : '||l_loc_attr.l_locator_current_cubic_area);
5464       mdebug(l_proc_name||'l_locator_available_cubic_area   : '||l_loc_attr.l_locator_available_cubic_area);
5465       mdebug(l_proc_name||'l_locator_max_units              : '||l_loc_attr.l_locator_maximum_units);
5466       mdebug(l_proc_name||'l_locator_current_units          : '||l_loc_attr.l_locator_current_units);
5467       mdebug(l_proc_name||'l_locator_available_units        : '||l_loc_attr.l_locator_available_units);
5468       mdebug(l_proc_name||'l_locator_suggested_units        : '||l_loc_attr.l_locator_suggested_units);
5469       mdebug(l_proc_name||'transaction quantity             : '||l_quantity);
5470     END IF;
5471 
5472 
5473     /*---------------------------------------------------------------------------------
5474       Get the attributes for the inventory_item_id that is passed as input parameter
5475       ---------------------------------------------------------------------------------*/
5476 
5477     IF  p_inventory_item_id IS NOT NULL AND p_inventory_item_id <>-1 THEN
5478         fetch_item_attributes(
5479      	      x_return_status            =>    l_return_status
5480           , x_msg_data                 =>    l_msg_data
5481           , x_msg_count                =>    l_msg_count
5482           , x_item_attr                =>    l_item_attr
5483           , p_inventory_item_id        =>    p_inventory_item_id
5484           , p_transaction_uom_code     =>    p_transaction_uom_code
5485           , p_primary_uom_flag         =>    p_primary_uom_flag
5486           , p_locator_weight_uom_code  =>    l_loc_attr.l_locator_weight_uom_code
5487           , p_locator_volume_uom_code  =>    l_loc_attr.l_locator_volume_uom_code
5488           , p_quantity                 =>    l_quantity
5489           , p_organization_id          =>    p_organization_id
5490           , p_container_item           =>    null
5491           );
5492         IF l_return_status =fnd_api.g_ret_sts_error THEN
5493            RAISE fnd_api.g_exc_error;
5494         ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error   THEN
5495            RAISE fnd_api.g_exc_unexpected_error;
5496         END IF;
5497 
5498         IF (l_debug = 1) THEN
5499            mdebug(l_proc_name||'The item weight UOM code  : '||l_item_attr.l_item_weight_uom_code);
5500            mdebug(l_proc_name||'item unit weight          : '||l_item_attr.l_item_unit_weight);
5501            mdebug(l_proc_name||'item volume UOM code      : '||l_item_attr.l_item_volume_uom_code);
5502            mdebug(l_proc_name||'item unit volume          : '||l_item_attr.l_item_unit_volume);
5503            mdebug(l_proc_name||'item extracted weight     : '||l_item_attr.l_item_xacted_weight);
5504            mdebug(l_proc_name||'item extracted volume     : '||l_item_attr.l_item_xacted_volume);
5505            mdebug(l_proc_name||'inventory item id         : '||p_inventory_item_id);
5506            mdebug(l_proc_name||'transaction uom code      : '||p_transaction_uom_code);
5507            mdebug(l_proc_name||'primary UOM flag          : '||p_primary_uom_flag);
5508            mdebug(l_proc_name||'locator weight UOM code   : '||l_loc_attr.l_locator_weight_uom_code);
5509            mdebug(l_proc_name||'locator volume UOM code   : '||l_loc_attr.l_locator_volume_uom_code);
5510            mdebug(l_proc_name||'transacted quantity       : '||l_quantity);
5511            mdebug(l_proc_name||'Organization id           : '||p_organization_id);
5512            mdebug(l_proc_name||'container item            : ');
5513          END IF;
5514     END IF;
5515 
5516     /*------------------------------------------------------------------------------------
5517       Fetch the attributes of Content LPN if passed
5518       ------------------------------------------------------------------------------------*/
5519 
5520     IF p_content_lpn_id is not null THEN
5521        fetch_content_lpn_attr
5522           (
5523             x_return_status                =>    l_return_status
5524           , x_msg_data                     =>    l_msg_data
5525           , x_msg_count                    =>    l_msg_count
5526           , x_cnt_lpn_attr                 =>    l_cnt_lpn_attr
5527           , x_cnt_lpn_qty                  =>    l_content_lpn_quantity
5528           , p_lpn_id                       =>    p_content_lpn_id
5529           , p_org_id                       =>    p_organization_id
5530           , p_locator_volume_uom_code      =>    l_loc_attr.l_locator_volume_uom_code
5531           , p_locator_weight_uom_code      =>    l_loc_attr.l_locator_weight_uom_code
5532           );
5533         IF l_return_status =fnd_api.g_ret_sts_error THEN
5534            RAISE fnd_api.g_exc_error;
5535         ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error   THEN
5536            RAISE fnd_api.g_exc_unexpected_error;
5537         END IF;
5538 
5539         IF p_inventory_item_id = -1 THEN
5540            l_quantity := l_content_lpn_quantity;
5541         END IF;
5542 
5543         IF (l_debug = 1) THEN
5544            mdebug(l_proc_name||'l_cnt_gross_weight_uom_code    : '||l_cnt_lpn_attr.l_gross_weight_uom_code);
5545            mdebug(l_proc_name||'l_cnt_content_volume_uom_code  : '||l_cnt_lpn_attr.l_content_volume_uom_code);
5546            mdebug(l_proc_name||'l_cnt_gross_weight             : '||l_cnt_lpn_attr.l_gross_weight);
5547            mdebug(l_proc_name||'l_cnt_content_volume           : '||l_cnt_lpn_attr.l_content_volume);
5548            mdebug(l_proc_name||'l_cnt_container_item_weight    : '||l_cnt_lpn_attr.l_container_item_weight);
5549            mdebug(l_proc_name||'l_cnt_container_item_vol       : '||l_cnt_lpn_attr.l_container_item_vol);
5550            mdebug(l_proc_name||'l_cnt_lpn_exists_in_locator    : '||l_cnt_lpn_attr.l_lpn_exists_in_locator);
5551            mdebug(l_proc_name||'p_content_lpn_id               : '||p_content_lpn_id);
5552            mdebug(l_proc_name||'p_organization_id              : '||p_organization_id);
5553            mdebug(l_proc_name||'locator weight UOM code        : '||l_loc_attr.l_locator_weight_uom_code);
5554            mdebug(l_proc_name||'lpn content qty                : '||l_quantity);
5555          END IF;
5556     END IF; /* End of p_content_lpn_id is not null */
5557 
5558     /*----------------------------------------------------------------------------------------
5559       Fetch the attributes of Transfer LPN if passed
5560       ----------------------------------------------------------------------------------------*/
5561     IF p_transfer_lpn_id is not null THEN
5562        fetch_transfer_lpn_attr
5563           (
5564             x_return_status                =>    l_return_status
5565           , x_msg_data                     =>    l_msg_data
5566           , x_msg_count                    =>    l_msg_count
5567           , x_trn_lpn_attr                 =>    l_trn_lpn_attr
5568           , p_lpn_id                       =>    p_transfer_lpn_id
5569           , p_org_id                       =>    p_organization_id
5570           , p_locator_volume_uom_code      =>    l_loc_attr.l_locator_volume_uom_code
5571           , p_locator_weight_uom_code      =>    l_loc_attr.l_locator_weight_uom_code
5572           );
5573         IF l_return_status =fnd_api.g_ret_sts_error THEN
5574            RAISE fnd_api.g_exc_error;
5575         ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error   THEN
5576            RAISE fnd_api.g_exc_unexpected_error;
5577         END IF;
5578         IF (l_debug = 1) THEN
5579            mdebug(l_proc_name||'l_trn_gross_weight_uom_code    : '||l_trn_lpn_attr.l_gross_weight_uom_code);
5580            mdebug(l_proc_name||'l_trn_content_volume_uom_code  : '||l_trn_lpn_attr.l_content_volume_uom_code);
5581            mdebug(l_proc_name||'l_trn_gross_weight             : '||l_trn_lpn_attr.l_gross_weight);
5582            mdebug(l_proc_name||'l_trn_content_volume           : '||l_trn_lpn_attr.l_content_volume);
5583            mdebug(l_proc_name||'l_trn_container_item_weight    : '||l_trn_lpn_attr.l_container_item_weight);
5584            mdebug(l_proc_name||'l_trn_container_item_vol       : '||l_trn_lpn_attr.l_container_item_vol);
5585            mdebug(l_proc_name||'l_trn_lpn_exists_in_locator    : '||l_trn_lpn_attr.l_lpn_exists_in_locator);
5586            mdebug(l_proc_name||'p_transfer_lpn_id              : '||p_transfer_lpn_id);
5587            mdebug(l_proc_name||'p_organization_id              : '||p_organization_id);
5588            mdebug(l_proc_name||'locator weight UOM code        : '||l_loc_attr.l_locator_weight_uom_code);
5589            mdebug(l_proc_name||'locator volume UOM code        : '||l_loc_attr.l_locator_volume_uom_code);
5590          END IF;
5591     END IF; /*End of if transfer lpn */
5592 
5593     /*----------------------------------------------------------------------------------------
5594       Fetch the attributes of LPN if passed
5595       ----------------------------------------------------------------------------------------*/
5596 
5597     IF p_lpn_id is not null THEN
5598        fetch_lpn_attr
5599           (
5600             x_return_status                =>    l_return_status
5601           , x_msg_data                     =>    l_msg_data
5602           , x_msg_count                    =>    l_msg_count
5603           , x_lpn_attr                     =>    l_lpn_attr
5604           , p_lpn_id                       =>    p_lpn_id
5605           , p_org_id                       =>    p_organization_id
5606           , p_locator_volume_uom_code      =>    l_loc_attr.l_locator_volume_uom_code
5607           , p_locator_weight_uom_code      =>    l_loc_attr.l_locator_weight_uom_code
5608           );
5609         IF l_return_status =fnd_api.g_ret_sts_error THEN
5610            RAISE fnd_api.g_exc_error;
5611         ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error   THEN
5612            RAISE fnd_api.g_exc_unexpected_error;
5613         END IF;
5614         IF (l_debug = 1) THEN
5615            mdebug(l_proc_name||'l_lpn_gross_weight_uom_code    : '||l_lpn_attr.l_gross_weight_uom_code);
5616            mdebug(l_proc_name||'l_lpn_content_volume_uom_code  : '||l_lpn_attr.l_content_volume_uom_code);
5617            mdebug(l_proc_name||'l_lpn_gross_weight             : '||l_lpn_attr.l_gross_weight);
5618            mdebug(l_proc_name||'l_lpn_content_volume           : '||l_lpn_attr.l_content_volume);
5619            mdebug(l_proc_name||'l_lpn_container_item_weight    : '||l_lpn_attr.l_container_item_weight);
5620            mdebug(l_proc_name||'l_lpn_container_item_vol       : '||l_lpn_attr.l_container_item_vol);
5621            mdebug(l_proc_name||'l_lpn_exists_in_locator        : '||l_lpn_attr.l_lpn_exists_in_locator);
5622            mdebug(l_proc_name||'p_lpn_id                       : '||p_lpn_id);
5623            mdebug(l_proc_name||'p_organization_id              : '||p_organization_id);
5624            mdebug(l_proc_name||'locator weight UOM code        : '||l_loc_attr.l_locator_weight_uom_code);
5625            mdebug(l_proc_name||'locator volume UOM code        : '||l_loc_attr.l_locator_volume_uom_code);
5626          END IF;
5627     END IF; /*End of if lpn */
5628 
5629     /*---------------------------------------------------------------------------------------------------
5630       Check for the transaction action, and peform the updation accordingly.
5631       ---------------------------------------------------------------------------------------------------*/
5632     IF p_transaction_action_id = 50 THEN
5633        /*-------------------------------------------------------------------------------------------
5634                                              Pack Transaction
5635          -------------------------------------------------------------------------------------------*/
5636        IF (l_debug = 1) THEN
5637           mdebug(l_proc_name||'transaction action id is =50 i.e pack ');
5638        END IF;
5639        upd_lpn_loc_cpty_for_pack
5640          (
5641            x_return_status                    =>      l_return_status
5642          , x_msg_data                         =>      l_msg_data
5643          , x_msg_count                        =>      l_msg_count
5644          , p_content_lpn_id                   =>      p_content_lpn_id
5645          , p_cnt_lpn_attr                     =>      l_cnt_lpn_attr
5646          , p_transfer_lpn_id                  =>      p_transfer_lpn_id
5647          , p_trn_lpn_attr                     =>      l_trn_lpn_attr
5648          , p_inventory_location_id            =>      l_inventory_location_id
5649          , p_loc_attr                         =>      l_loc_attr
5650          , p_organization_id                  =>      p_organization_id
5651          , p_item_attr                        =>      l_item_attr
5652          , p_container_item_id                =>      p_container_item_id
5653          , p_cartonization_id                 =>      p_cartonization_id
5654          );
5655        IF l_return_status =fnd_api.g_ret_sts_error THEN
5656           RAISE fnd_api.g_exc_error;
5657        ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error   THEN
5658           RAISE fnd_api.g_exc_unexpected_error;
5659        END IF;
5660    ELSIF p_transaction_action_id = 51 THEN
5661        /*-------------------------------------------------------------------------------------------
5662                                              UnPack Transaction
5663          -------------------------------------------------------------------------------------------*/
5664        IF (l_debug = 1) THEN
5665           mdebug(l_proc_name||'transaction action id is =51 i.e Unpack ');
5666        END IF;
5667        upd_lpn_loc_cpty_for_unpack
5668          (
5669            x_return_status                    =>      l_return_status
5670          , x_msg_data                         =>      l_msg_data
5671          , x_msg_count                        =>      l_msg_count
5672          , p_content_lpn_id                   =>      p_content_lpn_id
5673          , p_cnt_lpn_attr                     =>      l_cnt_lpn_attr
5674          , p_lpn_id                           =>      p_lpn_id
5675          , p_lpn_attr                         =>      l_lpn_attr
5676          , p_inventory_location_id            =>      l_inventory_location_id
5677          , p_loc_attr                         =>      l_loc_attr
5678          , p_organization_id                  =>      p_organization_id
5679          , p_item_attr                        =>      l_item_attr
5680          , p_quantity                         =>      p_quantity
5681          );
5682        IF l_return_status =fnd_api.g_ret_sts_error THEN
5683           RAISE fnd_api.g_exc_error;
5684        ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error   THEN
5685           RAISE fnd_api.g_exc_unexpected_error;
5686        END IF;
5687    ELSIF p_transaction_action_id IN (27,12, 31) OR
5688         (p_transaction_action_id IN (40,41,42) AND p_transfer_lpn_id IS NOT NULL ) THEN --Bug#4750846
5689        /*-------------------------------------------------------------------------------------------
5690                                              Receipt Transaction
5691          -------------------------------------------------------------------------------------------*/
5692        IF (l_debug = 1) THEN
5693           mdebug(l_proc_name||'transaction type is receipt ');
5694        END IF;
5695        upd_lpn_loc_cpty_for_rcpt (
5696             x_return_status                   =>        l_return_status
5697           , x_msg_data                        =>        l_msg_data
5698           , x_msg_count                       =>        l_msg_count
5699           , p_loc_attr                        =>        l_loc_attr
5700           , p_transfer_lpn_id                 =>        p_transfer_lpn_id
5701           , p_trn_lpn_attr                    =>        l_trn_lpn_attr
5702           , p_transaction_action_id           =>        p_transaction_action_id
5703           , p_item_attr                       =>        l_item_attr
5704           , p_quantity                        =>        l_quantity
5705           , p_inventory_location_id           =>        l_inventory_location_id
5706           , p_organization_id                 =>        p_organization_id
5707           );
5708        IF l_return_status =fnd_api.g_ret_sts_error THEN
5709           RAISE fnd_api.g_exc_error;
5710        ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error   THEN
5711           RAISE fnd_api.g_exc_unexpected_error;
5712        END IF;
5713    ELSIF p_transaction_action_id IN (1,21,32,34) OR
5714         (p_transaction_action_id IN (40,41,42) AND p_lpn_id IS NOT NULL ) THEN --Bug#4750846
5715        /*-------------------------------------------------------------------------------------------
5716                                           Issue Transaction
5717          -------------------------------------------------------------------------------------------*/
5718        IF (l_debug = 1) THEN
5719           mdebug(l_proc_name||'transaction type is issue ');
5720        END IF;
5721        upd_lpn_loc_cpty_for_issue(
5722             x_return_status                   =>        l_return_status
5723           , x_msg_data                        =>        l_msg_data
5724           , x_msg_count                       =>        l_msg_count
5725           , p_loc_attr                        =>        l_loc_attr
5726           , p_content_lpn_id                  =>        p_content_lpn_id
5727           , p_cnt_lpn_attr                    =>        l_cnt_lpn_attr
5728           , p_transaction_action_id           =>        p_transaction_action_id
5729           , p_item_attr                       =>        l_item_attr
5730           , p_quantity                        =>        l_quantity
5731           , p_inventory_location_id           =>        l_inventory_location_id
5732           , p_organization_id                 =>        p_organization_id
5733           );
5734        IF l_return_status =fnd_api.g_ret_sts_error THEN
5735           RAISE fnd_api.g_exc_error;
5736        ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error   THEN
5737           RAISE fnd_api.g_exc_unexpected_error;
5738        END IF;
5739     ELSIF p_transaction_action_id IN (2,3,28) THEN
5740        /*-------------------------------------------------------------------------------------------
5741                                            Transfer Transaction
5742         -------------------------------------------------------------------------------------------*/
5743        IF (l_debug = 1) THEN
5744           mdebug(l_proc_name||'transaction type is Transfer ');
5745        END IF;
5746        -- the xfr transaction is implemented as issue from source and receipt into dest locator.
5747        -- now, if an entire lpn is transferred (content lpn), then the same lpn is passed as
5748        -- content lpn during issue and as transfer lpn during rcpt. However, for receipt part of
5749        -- the txn the lpn attribute lpn_exists_in_locator should be made 'no' and the item_xacted
5750        -- weight must be made equal to the lpn content weight (this is just a hack to use the
5751        -- same procedure upd_lpn_loc_cpty_for_rcpt())
5752        IF p_content_lpn_id IS NOT NULL THEN
5753           l_cnt_lpn_attr.l_lpn_exists_in_locator := 'N';
5754           l_item_attr.l_item_xacted_weight := abs(l_cnt_lpn_attr.l_gross_weight
5755                                                - l_cnt_lpn_attr.l_container_item_weight);
5756           l_item_attr.l_item_xacted_volume := l_cnt_lpn_attr.l_content_volume;
5757        END IF;
5758        upd_lpn_loc_cpty_for_xfr(
5759             x_return_status                   =>        l_return_status
5760           , x_msg_data                        =>        l_msg_data
5761           , x_msg_count                       =>        l_msg_count
5762           , p_loc_attr                        =>        l_loc_attr
5763           , p_content_lpn_id                  =>        p_content_lpn_id
5764           , p_cnt_lpn_attr                    =>        l_cnt_lpn_attr
5765           , p_trn_lpn_id                      =>        p_transfer_lpn_id
5766           , p_trn_lpn_attr                    =>        l_trn_lpn_attr
5767           , p_lpn_id                          =>        p_lpn_id
5768           , p_lpn_attr                        =>        l_lpn_attr
5769           , p_transaction_action_id           =>        p_transaction_action_id
5770           , p_item_attr                       =>        l_item_attr
5771           , p_quantity                        =>        l_quantity
5772           , p_inventory_location_id           =>        l_inventory_location_id
5773           , p_organization_id                 =>        p_organization_id
5774           , p_inventory_item_id               =>        p_inventory_item_id
5775           , p_transaction_uom_code            =>        p_transaction_uom_code
5776           , p_primary_uom_flag                =>        p_primary_uom_flag
5777           , p_from_org_id                     =>        p_from_org_id
5778           , p_from_loc_id                     =>        p_from_loc_id
5779           );
5780        IF l_return_status =fnd_api.g_ret_sts_error THEN
5781           RAISE fnd_api.g_exc_error;
5782        ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error   THEN
5783           RAISE fnd_api.g_exc_unexpected_error;
5784        END IF;
5785    ELSIF p_transaction_action_id = (52) THEN
5786       /*-------------------------------------------------------------------------------------------
5787                                        LPN Split Transaction
5788         -------------------------------------------------------------------------------------------*/
5789       IF (l_debug = 1) THEN
5790           mdebug(l_proc_name||'transaction type is LPN split ');
5791       END IF;
5792       -- Call Unpack first to unpack from the from LPN (lpn_id)
5793       IF (l_debug = 1) THEN
5794          mdebug(l_proc_name||'Unpack part of Split Transaction ');
5795       END IF;
5796       upd_lpn_loc_cpty_for_unpack
5797         (
5798           x_return_status                    =>      l_return_status
5799         , x_msg_data                         =>      l_msg_data
5800         , x_msg_count                        =>      l_msg_count
5801         , p_content_lpn_id                   =>      NULL
5802         , p_cnt_lpn_attr                     =>      NULL
5803         , p_lpn_id                           =>      p_lpn_id
5804         , p_lpn_attr                         =>      l_lpn_attr
5805         , p_inventory_location_id            =>      l_inventory_location_id
5806         , p_loc_attr                         =>      l_loc_attr
5807         , p_organization_id                  =>      p_organization_id
5808         , p_item_attr                        =>      l_item_attr
5809         , p_quantity                         =>      p_quantity
5810         );
5811       IF l_return_status =fnd_api.g_ret_sts_error THEN
5812          RAISE fnd_api.g_exc_error;
5813       ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error   THEN
5814          RAISE fnd_api.g_exc_unexpected_error;
5815       END IF;
5816 
5817       -- Then Call pack to pack the items into to LPN (transfer_lpn_id)
5818       IF (l_debug = 1) THEN
5819          mdebug(l_proc_name||'Pack part of Split Transaction');
5820       END IF;
5821       upd_lpn_loc_cpty_for_pack
5822         (
5823           x_return_status                    =>      l_return_status
5824         , x_msg_data                         =>      l_msg_data
5825         , x_msg_count                        =>      l_msg_count
5826         , p_content_lpn_id                   =>      NULL
5827         , p_cnt_lpn_attr                     =>      NULL
5828         , p_transfer_lpn_id                  =>      p_transfer_lpn_id
5829         , p_trn_lpn_attr                     =>      l_trn_lpn_attr
5830         , p_inventory_location_id            =>      l_inventory_location_id
5831         , p_loc_attr                         =>      l_loc_attr
5832         , p_organization_id                  =>      p_organization_id
5833         , p_item_attr                        =>      l_item_attr
5834         , p_container_item_id                =>      p_container_item_id
5835         , p_cartonization_id                 =>      p_cartonization_id
5836         );
5837       IF l_return_status =fnd_api.g_ret_sts_error THEN
5838          RAISE fnd_api.g_exc_error;
5839       ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error   THEN
5840          RAISE fnd_api.g_exc_unexpected_error;
5841       END IF;
5842     END IF;
5843 END upd_lpn_loc_curr_cpty_nauto;
5844 
5845 -- bug#2876849. Added the two new parameters from org id and from loc id. These are needed
5846 -- for a transfer transaction to decrement the capacity from the souce locator.
5847 
5848 PROCEDURE update_lpn_loc_curr_capacity
5849   ( x_return_status             OUT NOCOPY VARCHAR2, -- return status (success/error/unexpected_error)
5850     x_msg_count                 OUT NOCOPY NUMBER,   -- number of messages in the message queue
5851     x_msg_data                  OUT NOCOPY VARCHAR2, -- message text when x_msg_count>0
5852     p_organization_id           IN         NUMBER,   -- org of locator whose capacity is to be determined
5853     p_inventory_location_id     IN         NUMBER,   -- identifier of locator
5854     p_inventory_item_id         IN         NUMBER,   -- identifier of item
5855     p_primary_uom_FLAG          IN         VARCHAR2, -- iF Y primary UOM
5856     p_transaction_uom_code      IN         VARCHAR2, -- UOM of the transacted material that causes the
5857 					                                      -- locator capacity to get updated
5858     p_transaction_action_id	  IN         NUMBER,   -- transaction action id for pack,unpack,issue,receive,
5859 					                                      -- transfer
5860     p_lpn_id                    IN         NUMBER,   -- lpn id
5861     p_transfer_lpn_id	        IN         NUMBER,   -- transfer_lpn_id
5862     p_content_lpn_id		        IN         NUMBER,   -- content_lpn_id
5863     p_quantity                  IN         NUMBER,   -- transaction quantity in p_transaction_uom_code
5864     p_container_item_id         IN         NUMBER DEFAULT NULL,
5865     p_cartonization_id          IN         NUMBER DEFAULT NULL,
5866     p_from_org_id               IN         NUMBER DEFAULT NULL,
5867     p_from_loc_id               IN         NUMBER DEFAULT NULL
5868   )
5869 IS
5870 PRAGMA autonomous_transaction;
5871    l_return_status             VARCHAR2(1);
5872    l_msg_count                 NUMBER;
5873    l_msg_data                  VARCHAR2(1000);
5874    l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5875 BEGIN
5876    x_return_status := FND_API.G_RET_STS_SUCCESS;
5877  INV_LOC_WMS_UTILS.upd_lpn_loc_curr_cpty_nauto
5878   ( x_return_status             =>l_return_status,
5879     x_msg_count                 =>l_msg_count,
5880     x_msg_data                  =>l_msg_data,
5881     p_organization_id           => p_organization_id,
5882     p_inventory_location_id     => p_inventory_location_id,
5883     p_inventory_item_id         => p_inventory_item_id,
5884     p_primary_uom_FLAG          =>'Y',
5885     p_transaction_uom_code      =>p_transaction_uom_code,
5886     p_transaction_action_id	=>p_transaction_action_id,
5887     p_lpn_id                    =>p_lpn_id,
5888     p_transfer_lpn_id		=>p_transfer_lpn_id,
5889     p_content_lpn_id		=>p_content_lpn_id,
5890     p_quantity                  =>abs(p_quantity),
5891     p_container_item_id         => p_container_item_id,
5892     p_cartonization_id          => p_cartonization_id,
5893     p_from_org_id               => p_from_org_id,
5894     p_from_loc_id               => p_from_loc_id
5895   );
5896 
5897     if l_return_status <> fnd_api.g_ret_sts_success THEN
5898 	IF l_return_status = fnd_api.g_ret_sts_error then
5899 	   raise fnd_api.g_exc_error;
5900 	ELSE
5901 	   RAISE fnd_api.g_exc_unexpected_error;
5902 	END IF;
5903     end if;
5904 
5905     commit;
5906 EXCEPTION
5907   WHEN fnd_api.g_exc_error THEN
5908       rollback;
5909       x_return_status := fnd_api.g_ret_sts_error;
5910       fnd_msg_pub.count_and_get
5911 	( p_count => x_msg_count,
5912 	  p_data  => x_msg_data
5913 	 );
5914 
5915    WHEN fnd_api.g_exc_unexpected_error THEN
5916       rollback;
5917       x_return_status := fnd_api.g_ret_sts_unexp_error ;
5918        fnd_msg_pub.count_and_get
5919 	( p_count => x_msg_count,
5920 	  p_data  => x_msg_data
5921 	  );
5922 
5923    WHEN NO_DATA_FOUND THEN
5924       rollback;
5925       x_return_status := fnd_api.g_ret_sts_error;
5926 
5927    WHEN OTHERS THEN
5928       rollback;
5929       x_return_status := fnd_api.g_ret_sts_unexp_error;
5930      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
5931 	THEN
5932 	 fnd_msg_pub.add_exc_msg
5933 	   (  'inv_loc_wms_utils'
5934 	      , 'update_lpn_loc_curr_capacity'
5935 	      );
5936 	END IF;
5937      fnd_msg_pub.count_and_get
5938 	( p_count => x_msg_count,
5939 	  p_data  => x_msg_data
5940 	 );
5941 END ;
5942 
5943 PROCEDURE lpn_loc_capacity_clean_up(x_return_status   OUT NOCOPY varchar2 --return status
5944 			       ,x_msg_count       OUT NOCOPY NUMBER --number of messages in message queue
5945 			       ,x_msg_data        OUT NOCOPY varchar2 --message text when x_msg_count>0
5946 			       ,p_organization_id IN NUMBER -- identier for the organization
5947 			       ,p_mixed_flag      IN VARCHAR2
5948 				    )
5949 IS
5950  l_return_status varchar2(10);
5951  l_msg_data      varchar2(1000);
5952  l_msg_count number;
5953     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5954 BEGIN
5955     x_return_status := fnd_api.g_ret_sts_success;
5956 
5957     savepoint lpn_loc_cleanup;
5958    IF (l_debug = 1) THEN
5959       INV_TRX_UTIL_PUB.TRACE('In LPN_LOC_CAPACITY_clean_up Procedure ','lpn_loc_capacity_clean_up',9);
5960    END IF;
5961 
5962      INV_LOC_WMS_UTILS.LPN_LOC_CURRENT_CAPACITY (x_return_status   =>l_return_status,
5963 			       x_msg_count       =>l_msg_count,
5964 			       x_msg_data        => x_msg_data,
5965 			       p_organization_id =>p_organization_id,
5966 			       p_mixed_flag      => p_mixed_flag);
5967 
5968      IF X_RETURN_STATUS =fnd_api.g_ret_sts_error THEN
5969 	IF (l_debug = 1) THEN
5970    	INV_TRX_UTIL_PUB.TRACE('Call to LPN_LOC_current_CAPACITY failed with Status E ','lpn_loc_capacity_clean_up',9);
5971 	END IF;
5972 	RAISE fnd_api.g_exc_error;
5973      ELSIF X_RETURN_STATUS =fnd_api.g_ret_sts_unexp_error THEN
5974        IF (l_debug = 1) THEN
5975           INV_TRX_UTIL_PUB.TRACE('Call to LPN_LOC_current_CAPACITY failed with status U','lpn_loc_capacity_clean_up',9);
5976        END IF;
5977 	RAISE fnd_api.g_exc_unexpected_error;
5978      END IF;
5979 
5980      IF (l_debug = 1) THEN
5981         INV_TRX_UTIL_PUB.TRACE('Before call to lpn_loc_cleanup_mmtt','lpn_loc_capacity_clean_up',9);
5982      END IF;
5983 
5984      INV_LOC_WMS_UTILS.lpn_loc_cleanup_mmtt(x_return_status   =>l_return_status,
5985 			  x_msg_count       =>l_msg_count,
5986 			  x_msg_data       =>l_msg_data,
5987 			  p_organization_id =>p_organization_id,
5988 			  p_mixed_flag      =>p_mixed_flag);
5989 
5990      IF X_RETURN_STATUS =fnd_api.g_ret_sts_error THEN
5991        IF (l_debug = 1) THEN
5992           INV_TRX_UTIL_PUB.TRACE('Call to lpn_loc_cleanup_mmtt failed with status E','lpn_loc_capacity_clean_up',9);
5993        END IF;
5994 	RAISE fnd_api.g_exc_error;
5995      ELSIF X_RETURN_STATUS =fnd_api.g_ret_sts_unexp_error THEN
5996        IF (l_debug = 1) THEN
5997           INV_TRX_UTIL_PUB.TRACE('Call to lpn_loc_cleanup_mmtt failed with status U','lpn_loc_capacity_clean_up',9);
5998        END IF;
5999 	RAISE fnd_api.g_exc_unexpected_error;
6000      END IF;
6001 
6002 EXCEPTION
6003  WHEN fnd_api.g_exc_error THEN
6004     --Fixed bug 2342723, do not rollback to savepoint
6005     -- Bug 3511690 rolling back to savepoint
6006     rollback to lpn_loc_cleanup;
6007     --rollback;
6008       x_return_status := fnd_api.g_ret_sts_error;
6009       fnd_msg_pub.count_and_get
6010 	( p_count => x_msg_count,
6011 	  p_data  => x_msg_data
6012 	 );
6013 
6014    WHEN fnd_api.g_exc_unexpected_error THEN
6015       x_return_status := fnd_api.g_ret_sts_unexp_error ;
6016     rollback to lpn_loc_cleanup;
6017     --rollback;
6018        fnd_msg_pub.count_and_get
6019 	( p_count => x_msg_count,
6020 	  p_data  => x_msg_data
6021 	  );
6022 
6023    WHEN NO_DATA_FOUND THEN
6024      x_return_status := fnd_api.g_ret_sts_error;
6025     rollback to lpn_loc_cleanup;
6026     --rollback;
6027        fnd_msg_pub.count_and_get
6028 	( p_count => x_msg_count,
6029 	    p_data  => x_msg_data
6030 	  );
6031    WHEN OTHERS THEN
6032     x_return_status := fnd_api.g_ret_sts_unexp_error;
6033     rollback to lpn_loc_cleanup;
6034     --rollback;
6035      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
6036 	THEN
6037 	 fnd_msg_pub.add_exc_msg
6038 	   (  'INV_LOC_WMS_UTILS',
6039 	      'lpn_loc_capacity_clean_up'
6040 	      );
6041      END IF;
6042      fnd_msg_pub.count_and_get
6043 	( p_count => x_msg_count,
6044 	  p_data  => x_msg_data
6045 	  );
6046 END lpn_loc_capacity_clean_up;
6047 
6048 PROCEDURE cal_locator_current_volume(
6049 		x_return_status               OUT NOCOPY VARCHAR2, --return status
6050 		x_msg_data                    OUT NOCOPY VARCHAR2, --message text when x_msg_count>0
6051 		x_msg_count                   OUT NOCOPY NUMBER,   --number of messages in message queue
6052 		x_locator_current_volume      OUT NOCOPY NUMBER,   --locator's current_cubic_area
6053 		p_trn_lpn_container_item_vol  IN         NUMBER,   --container item volume associated with transfer LPN
6054 		p_trn_lpn_content_volume      IN         NUMBER,   --Content volume of the Transfer LPN
6055 		p_cnt_lpn_container_item_vol  IN         NUMBER,   --container item volume associated with content LPN
6056 		p_cnt_lpn_content_volume      IN         NUMBER,   --Content volume of the Content LPN
6057 		p_lpn_container_item_vol      IN         NUMBER,   --container item volume associated with LPN
6058 		p_lpn_content_volume          IN         NUMBER,   --Content volume of the LPN
6059 		p_xacted_volume               IN         NUMBER,   -- Transacted volume
6060 		p_locator_current_cubic_area  IN         NUMBER,   --locator's current_cubic_area
6061 		p_transaction_action_id       IN         NUMBER,   -- transaction action id for pack,unpack,issue,receive,Transfer
6062 		p_transfer_lpn_id             IN         NUMBER,   --Transfer_LPN_ID
6063 		p_content_lpn_id              IN         NUMBER,   --Content LPN_ID
6064 		p_lpn_id                      IN         NUMBER,   --LPN_ID
6065 		p_trn_lpn_exists_in_loc       IN         VARCHAR2  --Flag indicates if Transfer LPN exists in Locator.
6066 							                                    -- Y if the Transfer LPN exists in locator.
6067 							                                    -- N if the Transfer LPN does not exists in locator
6068 					      )
6069 IS
6070  l_locator_current_volume         NUMBER;
6071  l_trn_lpn_container_item_vol     NUMBER;
6072  l_trn_lpn_content_volume         NUMBER;
6073  l_cnt_lpn_container_item_vol     NUMBER;
6074  l_cnt_lpn_content_volume         NUMBER;
6075  l_xacted_volume                  NUMBER;
6076  l_trn_xacted_volume              NUMBER;
6077  l_trn_lpn_exists_in_loc          VARCHAR2(1);
6078  l_debug                          NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6079  l_proc_name                      VARCHAR2(40) := 'CAL_LOCATOR_CURRENT_VOL: ';
6080 BEGIN
6081  l_locator_current_volume         :=p_locator_current_cubic_area;
6082  l_trn_lpn_container_item_vol     :=p_trn_lpn_container_item_vol;
6083  l_trn_lpn_content_volume         :=p_trn_lpn_content_volume;
6084  l_cnt_lpn_container_item_vol     :=p_cnt_lpn_container_item_vol;
6085  l_cnt_lpn_content_volume         :=p_cnt_lpn_content_volume;
6086  l_xacted_volume                  :=p_xacted_volume;
6087  l_trn_lpn_exists_in_loc          := p_trn_lpn_exists_in_loc;
6088  /*---------------------------------------------------------------------------------------------------
6089                                         Pack Transaction
6090    ---------------------------------------------------------------------------------------------------*/
6091  IF p_transaction_action_id =50  /*PACK */ THEN
6092     IF p_content_lpn_id IS NULL THEN
6093 	/*-------------------------------------------------------------------------------------------------
6094      Packing loose item in locator into a Transfer LPN
6095      -------------------------------------------------------------------------------------------------*/
6096 	  IF (l_debug = 1) THEN
6097          mdebug(l_proc_name||'The content_lpn_id is null -case pack ');
6098 	  END IF;
6099      /*------------------------------------------------------------------
6100        LPN already exists in the locator, need not add the container vol
6101        ------------------------------------------------------------------*/
6102 	  IF p_trn_lpn_exists_in_loc ='Y' THEN
6103 	     IF (l_debug = 1) THEN
6104    	    mdebug(l_proc_name||'The p_trn_lpn__exists_in_loc is Y -case pack ');
6105 	     END IF;
6106 	     IF l_trn_lpn_content_volume > l_trn_lpn_container_item_vol THEN
6107 		     x_locator_current_volume := l_locator_current_volume ;
6108 	     ELSIF (l_trn_lpn_content_volume + l_xacted_volume) <= l_trn_lpn_container_item_vol THEN
6109 		     x_locator_current_volume := l_locator_current_volume -l_xacted_volume;
6110 	     ELSIF (l_trn_lpn_content_volume + l_xacted_volume) > l_trn_lpn_container_item_vol THEN
6111 		     x_locator_current_volume := l_locator_current_volume -l_xacted_volume +(
6112 					    l_trn_lpn_content_volume + l_xacted_volume -l_trn_lpn_container_item_vol);
6113 	     END IF;
6114      /*------------------------------------------------------------------
6115        LPN does not exist in the locator, need to add the container vol
6116        ------------------------------------------------------------------*/
6117      ELSE
6118 	    IF (l_debug = 1) THEN
6119    	    mdebug(l_proc_name||'The p_trn_lpn__exists_in_loc is N -case pack ');
6120 	    END IF;
6121 	    l_locator_current_volume  := l_locator_current_volume + l_trn_lpn_container_item_vol;
6122 	    IF l_xacted_volume <= l_trn_lpn_container_item_vol THEN
6123 		    x_locator_current_volume := l_locator_current_volume -l_xacted_volume;
6124 	    ELSIF l_xacted_volume > l_trn_lpn_container_item_vol THEN
6125         -- In case the Transacted volume is > container Volume, the volume of locator does
6126         -- not change.
6127 	     	x_locator_current_volume := l_locator_current_volume - l_trn_lpn_container_item_vol;
6128 	    END IF;
6129 	  END IF;
6130 	/*-------------------------------------------------------------------------------------------------
6131      Packing Content LPN in locator into another Transfer LPN
6132      -------------------------------------------------------------------------------------------------*/
6133    ELSIF  p_content_lpn_id IS NOT NULL THEN
6134 	  IF l_cnt_lpn_content_volume > l_cnt_lpn_container_item_vol THEN
6135 	     l_locator_current_volume := l_locator_current_volume - l_cnt_lpn_content_volume;
6136 		  l_trn_xacted_volume:= l_cnt_lpn_content_volume;
6137 	  ELSIF l_cnt_lpn_content_volume <= l_cnt_lpn_container_item_vol  THEN
6138 	        l_locator_current_volume := l_locator_current_volume - l_cnt_lpn_container_item_vol;
6139 		     l_trn_xacted_volume:= l_cnt_lpn_container_item_vol;
6140 	  END IF;
6141      /*--------------------------------------------------------------------------
6142        Transfer LPN already exists in the locator, need not add the container vol
6143        --------------------------------------------------------------------------*/
6144 	  IF p_trn_lpn_exists_in_loc ='Y' THEN
6145 	     IF l_trn_lpn_content_volume > l_trn_lpn_container_item_vol THEN
6146 		     x_locator_current_volume := l_locator_current_volume + l_trn_xacted_volume;
6147 		  ELSIF (l_trn_lpn_content_volume +l_trn_xacted_volume) <= l_trn_lpn_container_item_vol THEN
6148 		         x_locator_current_volume :=l_locator_current_volume;
6149 		  ELSIF (l_trn_lpn_content_volume +l_trn_xacted_volume) > l_trn_lpn_container_item_vol THEN
6150 		         x_locator_current_volume :=l_locator_current_volume +
6151 				  (l_trn_lpn_content_volume+l_trn_xacted_volume-l_trn_lpn_container_item_vol);
6152 		  END IF;
6153      /*--------------------------------------------------------------------------
6154        Transfer LPN does not exist in the locator, need to add the container vol
6155        --------------------------------------------------------------------------*/
6156 	  ELSE /* p_trn_lpn_exists_in_loc <>Y' */
6157 	     l_locator_current_volume  := l_locator_current_volume + l_trn_lpn_container_item_vol;
6158 	     IF l_trn_xacted_volume > l_trn_lpn_container_item_vol THEN
6159 		     x_locator_current_volume :=l_locator_current_volume + (l_trn_xacted_volume-l_trn_lpn_container_item_vol);
6160 	     ELSIF l_trn_xacted_volume <= l_trn_lpn_container_item_vol THEN
6161 		        x_locator_current_volume :=l_locator_current_volume;
6162 	     END IF;
6163 	     IF (l_debug = 1) THEN
6164    	       mdebug(l_proc_name||'Trx type Pack content lpn _id is not null ');
6165              mdebug(l_proc_name||'The value of current volume is  :'||to_char(x_locator_current_volume));
6166 	     END IF;
6167 	  END IF;/* p_trn_lpn_exists_in_loc ='Y' */
6168    END IF;
6169   /*---------------------------------------------------------------------------------------------------
6170                                         UnPack Transaction
6171    ---------------------------------------------------------------------------------------------------*/
6172  ELSIF p_transaction_action_id =51 THEN
6173    IF p_content_lpn_id is null THEN
6174 	   IF p_lpn_content_volume > p_lpn_container_item_vol THEN
6175 	      IF (p_lpn_content_volume-l_xacted_volume) > p_lpn_container_item_vol THEN
6176 	          x_locator_current_volume :=l_locator_current_volume;
6177 	      ELSIF (p_lpn_content_volume-l_xacted_volume) <= p_lpn_container_item_vol THEN
6178           -- In case of unpack, if the content vol > container vol. then the
6179           -- volume calculation should be current + transacted - diff( Content and Container vol).
6180 	        x_locator_current_volume :=l_locator_current_volume + l_xacted_volume -(
6181 					      p_lpn_content_volume -p_lpn_container_item_vol);
6182 	      END IF;
6183 	   ELSIF p_lpn_content_volume <= p_lpn_container_item_vol THEN
6184 		      x_locator_current_volume :=l_locator_current_volume + l_xacted_volume;
6185 	   END IF;
6186    ELSE
6187 	   IF l_cnt_lpn_content_volume > l_cnt_lpn_container_item_vol THEN
6188 		   x_locator_current_volume := l_locator_current_volume + l_cnt_lpn_content_volume;
6189 	   ELSE
6190 		   x_locator_current_volume := l_locator_current_volume + l_cnt_lpn_container_item_vol;
6191 	   END IF;
6192    END IF;
6193   /*---------------------------------------------------------------------------------------------------
6194                                         Receipt Transaction
6195    ---------------------------------------------------------------------------------------------------*/
6196  ELSIF p_transaction_action_id in (27,12,31) /*Receipt*/ THEN
6197 	IF  p_trn_lpn_exists_in_loc ='Y' THEN
6198 	    IF l_trn_lpn_content_volume > l_trn_lpn_container_item_vol THEN
6199 	       x_locator_current_volume := l_locator_current_volume + l_xacted_volume;
6200 	    ELSIF (l_trn_lpn_content_volume + l_xacted_volume) <= l_trn_lpn_container_item_vol THEN
6201 		    x_locator_current_volume := l_locator_current_volume ;
6202 	    ELSIF (l_trn_lpn_content_volume + l_xacted_volume) > l_trn_lpn_container_item_vol THEN
6203 		    x_locator_current_volume := l_locator_current_volume + (l_trn_lpn_content_volume + l_xacted_volume
6204 									-l_trn_lpn_container_item_vol);
6205 	    END IF;
6206 	ELSE
6207 	    l_locator_current_volume  := l_locator_current_volume + l_trn_lpn_container_item_vol;
6208 	    IF l_xacted_volume <= l_trn_lpn_container_item_vol THEN
6209 	       x_locator_current_volume := l_locator_current_volume;
6210 	    ELSIF l_xacted_volume > l_trn_lpn_container_item_vol THEN
6211 	       x_locator_current_volume := l_locator_current_volume +(l_xacted_volume-l_trn_lpn_container_item_vol);
6212 	    END IF;
6213 	END IF;
6214   /*---------------------------------------------------------------------------------------------------
6215                                         Issue Transaction
6216    ---------------------------------------------------------------------------------------------------*/
6217   ELSIF p_transaction_action_id in (1,21,32,34)  THEN
6218 	   IF l_cnt_lpn_content_volume > l_cnt_lpn_container_item_vol THEN
6219 		   x_locator_current_volume := l_locator_current_volume - l_cnt_lpn_content_volume;
6220 	   ELSIF l_cnt_lpn_content_volume <= l_cnt_lpn_container_item_vol  THEN
6221 		   x_locator_current_volume := l_locator_current_volume - l_cnt_lpn_container_item_vol;
6222 	   END IF;
6223   /*---------------------------------------------------------------------------------------------------
6224                                         Xfr Transaction
6225    ---------------------------------------------------------------------------------------------------*/
6226   ELSIF p_transaction_action_id in (2,3,28) /* TRANSFER */ THEN
6227 	   IF l_cnt_lpn_content_volume > l_cnt_lpn_container_item_vol THEN
6228 	      x_locator_current_volume := l_locator_current_volume - l_cnt_lpn_content_volume;
6229 	   ELSIF l_cnt_lpn_content_volume <= l_cnt_lpn_container_item_vol  THEN
6230 		   x_locator_current_volume := l_locator_current_volume - l_cnt_lpn_container_item_vol;
6231 	   END IF;
6232   END IF;
6233 EXCEPTION
6234   WHEN fnd_api.g_exc_error THEN
6235     x_return_status := fnd_api.g_ret_sts_error;
6236     fnd_msg_pub.count_and_get
6237 	( p_count => x_msg_count,
6238 	  p_data  => x_msg_data
6239 	 );
6240    WHEN fnd_api.g_exc_unexpected_error THEN
6241      x_return_status := fnd_api.g_ret_sts_unexp_error ;
6242        fnd_msg_pub.count_and_get
6243 	( p_count => x_msg_count,
6244 	  p_data  => x_msg_data
6245 	  );
6246    WHEN NO_DATA_FOUND THEN
6247       x_return_status := fnd_api.g_ret_sts_error;
6248    WHEN OTHERS THEN
6249       x_return_status := fnd_api.g_ret_sts_unexp_error;
6250       IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
6251 	THEN
6252 	 fnd_msg_pub.add_exc_msg
6253 	   (  'inv_loc_wms_utils'
6254 	      , 'cal_locator_current_volume'
6255 	      );
6256      END IF;
6257      fnd_msg_pub.count_and_get
6258 	( p_count => x_msg_count,
6259 	  p_data  => x_msg_data
6260 	 );
6261 END cal_locator_current_volume;
6262 
6263 PROCEDURE lpn_attributes (
6264 	   x_return_status             OUT NOCOPY VARCHAR2, -- Return status
6265 	   x_msg_data                  OUT NOCOPY VARCHAR2,--message text when x_msg_count>0
6266 	   x_msg_count                 OUT NOCOPY NUMBER,-- Count iof message in the message queue
6267 	   x_gross_weight_uom_code     OUT NOCOPY VARCHAR2,--Gross_Weight_UOM_Code of the LPN
6268 	   x_content_volume_uom_code   OUT NOCOPY VARCHAR2,--Content_Volume_UOM_Code of the LPN
6269 	   x_gross_weight              OUT NOCOPY NUMBER,--Gross Weight of the LPN
6270 	   x_content_volume            OUT NOCOPY NUMBER,--Content_Volume of the LPN
6271 	   x_container_item_weight     OUT NOCOPY NUMBER,-- Container item's weight (in terms of Gross_weight_UOM_code)
6272 						  -- associated with the LPN
6273 	   x_container_item_vol        OUT NOCOPY NUMBER,-- Container item Volume's (in terms of Content_Volume_UOM_code)
6274 						  -- associated with the LPN
6275 	   x_lpn_exists_in_locator     OUT NOCOPY VARCHAR2,--Flag indicates if Transfer LPN exists in Locator.
6276 						    -- Y if the Transfer LPN exists in locator.
6277 						    -- N if the Transfer LPN does not exists in locator
6278 	   p_lpn_id                    IN NUMBER,--Identifier of the LPN
6279 	   p_org_id                    IN NUMBER--Identifier of the Organization
6280 			)
6281 IS
6282      l_gross_weight_uom_code       varchar2(3);
6283      l_content_volume_uom_code     varchar2(3);
6284      l_subinventory_code           varchar2(30);
6285      l_gross_weight                NUMBER ;
6286      l_content_volume              NUMBER;
6287      l_locator_id                  NUMBER;
6288      l_container_item_id           NUMBER;
6289      l_return_status               VARCHAR2(1);
6290 
6291      l_container_item_wt_uom_code   VARCHAR2(3);
6292      l_container_item_unit_weight   NUMBER;
6293      l_container_item_vol_uom_code  VARCHAR2(3);
6294      l_container_item_unit_volume   NUMBER;
6295      l_container_item_xacted_weight NUMBER;
6296      l_container_item_xacted_volume NUMBER;
6297 
6298      l_msg_data                     VARCHAR2(1000);
6299      l_msg_count                    NUMBER;
6300     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6301 BEGIN
6302 	 x_return_status := FND_API.G_RET_STS_SUCCESS;
6303      BEGIN
6304 
6305 	 SELECT GROSS_WEIGHT_UOM_CODE,
6306 		CONTENT_VOLUME_UOM_CODE,
6307 		GROSS_WEIGHT,
6308 		CONTENT_VOLUME,
6309 		LOCATOR_ID,
6310 		SUBINVENTORY_CODE,
6311 		INVENTORY_ITEM_ID
6312 	  INTO  l_gross_weight_uom_code,
6313 		l_content_volume_uom_code,
6314 		l_gross_weight,
6315 		l_content_volume,
6316 		l_locator_id,
6317 		l_subinventory_code,
6318 		l_container_item_id
6319 	   FROM wms_license_plate_numbers
6320 	   WHERE lpn_id = p_lpn_id;
6321      exception
6322        when no_data_found  then
6323 	null;
6324       end;
6325 
6326 	   IF (l_debug = 1) THEN
6327    	   INV_TRX_UTIL_PUB.TRACE('The p_lpn_id  '||to_char(p_lpn_id),'LPN-ATTRIBUTE-UPDATE_LPN_LOC',9);
6328    	   INV_TRX_UTIL_PUB.TRACE('The attribute of the lpn_id are :'||
6329 		   'l_gross_weight_uom_code :'||l_gross_weight_uom_code ||
6330 		   'l_content_volume_uom_code :'||l_content_volume_uom_code ||
6331 		   'l_Subinventory_code :'||l_subinventory_code||
6332 		   'l_gross_weight '||to_char(l_gross_weight)||
6333 		   'l_content_volume '||to_char(l_content_volume) ||
6334 		   'l_locator_id '||to_char(l_locator_id) ||
6335 		   'l_container_item_id '||to_char(l_container_item_id)
6336 		   ,'LPN-ATTRIBUTE-UPDATE_LPN_LOC',9
6337 		  );
6338 	   END IF;
6339 
6340 	   IF  l_container_item_id is not null THEN
6341 	       INV_LOC_WMS_UTILS.item_attributes( l_return_status,
6342 				l_msg_data,
6343 				l_msg_count,
6344 				L_CONTAINER_ITEM_WT_UOM_CODE,
6345 				l_container_item_unit_weight,
6346 				l_container_item_vol_uom_code,
6347 				l_container_item_unit_volume,
6348 				l_container_item_xacted_weight,
6349 				l_container_item_xacted_volume,
6350 				l_container_item_id,
6351 				Null,
6352 				null,
6353 				null,
6354 				null,
6355 				null ,
6356 				p_org_id,
6357 				'Y'
6358 			       );
6359 	      IF l_return_status =fnd_api.g_ret_sts_error THEN
6360 		 IF (l_debug = 1) THEN
6361    		 INV_TRX_UTIL_PUB.TRACE('Error fetching container item attributes - '||l_return_status , 'LPN-ATTRIBUTE-UPDATE_LPN_LOC',4);
6362 		 END IF;
6363 		 RAISE fnd_api.g_exc_error;
6364 	      ELSIF l_return_status = fnd_api.g_ret_sts_unexp_error   THEN
6365 		 IF (l_debug = 1) THEN
6366    		 INV_TRX_UTIL_PUB.TRACE('Error fetching container item attributes - '||l_return_status , 'LPN-ATTRIBUTE-UPDATE_LPN_LOC',4);
6367 		 END IF;
6368 		RAISE fnd_api.g_exc_unexpected_error;
6369 	      END IF;
6370 	   END IF;
6371 
6372 	   IF  l_gross_weight_uom_code is not null AND
6373 	       L_CONTAINER_ITEM_WT_UOM_CODE is not null AND
6374 	       l_container_item_unit_weight >0  THEN
6375 	       IF (l_gross_weight_uom_code <> L_CONTAINER_ITEM_WT_UOM_CODE) THEN
6376 
6377 		 IF (l_debug = 1) THEN
6378    		 INV_TRX_UTIL_PUB.TRACE('Gross_weight_uom_weight code different from container item weight uom code', 'LPN-ATTRIBUTE-UPDATE_LPN_LOC',4);
6379 		 END IF;
6380 		   l_container_item_xacted_weight := inv_convert.inv_um_convert(
6381 									  item_id       => null,
6382 									  precision     => null,
6383 									  from_quantity => l_container_item_unit_weight,
6384 									  from_unit     => L_CONTAINER_ITEM_WT_UOM_CODE,
6385 									  to_unit	=> l_gross_weight_uom_code,
6386 									  from_name     => null,
6387 									  to_name	=> null
6388 										);
6389 
6390 		ELSE
6391 		    l_container_item_xacted_weight := l_container_item_unit_weight;
6392 		END IF;
6393 		IF l_container_item_xacted_weight = -99999 THEN
6394 		    RAISE fnd_api.g_exc_error;
6395 		END IF;
6396 		 IF (l_debug = 1) THEN
6397    		 INV_TRX_UTIL_PUB.TRACE('l_container_item_xacted_weight is '||to_char(l_container_item_xacted_weight), 'LPN-ATTRIBUTE-UPDATE_LPN_LOC',4);
6398 		 END IF;
6399 	    END IF;
6400 
6401 	     IF l_content_volume_uom_code is not null AND
6402 	       l_container_item_vol_uom_code is not null AND
6403 	       l_container_item_unit_volume >0  THEN
6404 	       IF (l_content_volume_uom_code <> l_container_item_vol_uom_code) THEN
6405 
6406 		  l_container_item_xacted_volume := inv_convert.inv_um_convert(
6407 									   item_id       => null,
6408 									   precision     => null,
6409 									   from_quantity => l_container_item_unit_volume,
6410 									   from_unit     => l_container_item_vol_uom_code,
6411 									   to_unit	 => l_content_volume_uom_code,
6412 									   from_name     => null,
6413 									   to_name	 => null
6414 										);
6415 		ELSE
6416 		   l_container_item_xacted_volume := l_container_item_unit_volume;
6417 		END IF;
6418 		 IF (l_debug = 1) THEN
6419    		 INV_TRX_UTIL_PUB.TRACE('l_container_item_xacted_volume is '||to_char(l_container_item_xacted_volume), 'LPN-ATTRIBUTE-UPDATE_LPN_LOC',4);
6420 		 END IF;
6421 		IF l_container_item_xacted_volume = -99999 THEN
6422 		    RAISE fnd_api.g_exc_error;
6423 		END IF;
6424 
6425 	    END IF;
6426 
6427 	   IF (l_debug = 1) THEN
6428    	   INV_TRX_UTIL_PUB.TRACE('The weight and volume of the Container item are :'||
6429 		   'l_container_item_unit_weight :'||to_char(l_container_item_unit_weight) ||
6430 		   'L_CONTAINER_ITEM_WT_UOM_CODE :'||L_CONTAINER_ITEM_WT_UOM_CODE ||
6431 		   'l_container_item_unit_volume :'||to_char(l_container_item_unit_volume)||
6432 		   'l_container_item_vol_uom_code'||l_container_item_vol_uom_code
6433 		   ,'LPN-ATTRIBUTE-UPDATE_LPN_LOC',4
6434 		  );
6435 	   END IF;
6436 	  IF l_subinventory_code is null and l_locator_id is null then
6437 	       x_lpn_exists_in_locator := 'N';
6438 	  ELSE
6439 	       x_lpn_exists_in_locator := 'Y';
6440 	  END IF;
6441 
6442 	  x_gross_weight_uom_code     :=l_gross_weight_uom_code;
6443 	  x_content_volume_uom_code   :=l_content_volume_uom_code;
6444 	  x_gross_weight              :=nvl(l_gross_weight,0);
6445 	  x_content_volume            :=nvl(l_content_volume,0);
6446 	  x_container_item_weight     :=nvl(l_container_item_xacted_weight,0);
6447 	  x_container_item_vol     :=nvl(l_container_item_xacted_volume,0);
6448 
6449 EXCEPTION
6450   WHEN fnd_api.g_exc_error THEN
6451     x_return_status := fnd_api.g_ret_sts_error;
6452     fnd_msg_pub.count_and_get
6453 	( p_count => x_msg_count,
6454 	  p_data  => x_msg_data
6455 	 );
6456 
6457    WHEN fnd_api.g_exc_unexpected_error THEN
6458      x_return_status := fnd_api.g_ret_sts_unexp_error ;
6459        fnd_msg_pub.count_and_get
6460 	( p_count => x_msg_count,
6461 	  p_data  => x_msg_data
6462 	  );
6463 
6464    WHEN NO_DATA_FOUND THEN
6465       x_return_status := fnd_api.g_ret_sts_error;
6466 
6467    WHEN OTHERS THEN
6468       x_return_status := fnd_api.g_ret_sts_unexp_error;
6469      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
6470 	THEN
6471 	 fnd_msg_pub.add_exc_msg
6472 	   (  'inv_loc_wms_utils'
6473 	      , 'lpn_attributes'
6474 	      );
6475 	END IF;
6476      fnd_msg_pub.count_and_get
6477 	( p_count => x_msg_count,
6478 	  p_data  => x_msg_data
6479 	 );
6480 END lpn_attributes;
6481 
6482 
6483 PROCEDURE item_attributes(
6484 	      x_return_status           OUT NOCOPY VARCHAR2,--return status
6485 	      x_msg_data                OUT NOCOPY VARCHAR2,
6486 	      x_msg_count               OUT NOCOPY NUMBER,  --Count of messages in the Message queue
6487 	      x_item_weight_uom_code    OUT NOCOPY VARCHAR2,--Item's weight UOM_code
6488 	      x_item_unit_weight        OUT NOCOPY NUMBER,  --Item's unit weight
6489 	      x_item_volume_uom_code    OUT NOCOPY VARCHAR2,--Item's Volume UOM_Code
6490 	      x_item_unit_volume        OUT NOCOPY NUMBER,  --Item's unit volume
6491 	      x_item_xacted_weight      OUT NOCOPY NUMBER,  --Transacted weight of item
6492 	      x_item_xacted_volume      OUT NOCOPY NUMBER, -- Transacted volume of item
6493 	      p_inventory_item_id       IN  NUMBER,-- Identifier of Item
6494 	      p_transaction_uom_code    IN  VARCHAR2 ,--UOM of the transacted material
6495 	      p_primary_uom_flag        IN  VARCHAR2 ,--Y if Primary_UOM
6496 	      p_locator_weight_uom_code IN VARCHAR2 ,--Locator's weight_UOM_Code
6497 	      p_locator_volume_uom_code IN VARCHAR2 ,--Locator's Volume_UOM_Code
6498 	      p_quantity                IN  NUMBER   ,--Transaction quantity
6499 	      p_organization_id          IN NUMBER, -- Identier of the Organization
6500 	      p_container_item          IN  VARCHAR2--Flag which indicates the item passed is a container item.
6501 								--Y if the item is a container item
6502 								-- N if the item is not a container item
6503 		      )
6504 IS
6505      l_item_primary_uom_code           VARCHAR2(3);
6506      l_item_weight_uom_code            VARCHAR2(3);
6507      l_item_unit_weight                NUMBER;
6508      l_item_volume_uom_code            VARCHAR2(3);
6509      l_item_unit_volume                NUMBER;
6510 
6511      l_container_item_id               NUMBER;
6512      l_subinventory_code               VARCHAR2(20);
6513      l_locator_id                      NUMBER;
6514      l_primary_uom_code                VARCHAR2(3);
6515      l_weight_uom_code                 varchar2(3);
6516      l_volume_uom_code                 varchar2(3);
6517      l_item_xacted_weight              NUMBER;
6518      l_item_xacted_volume              NUMBER;
6519      l_quantity                        NUMBER;
6520 
6521     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6522     BEGIN
6523 	 x_return_status := FND_API.G_RET_STS_SUCCESS;
6524 
6525 	 SELECT primary_uom_code
6526 		,weight_uom_code
6527 		,unit_weight
6528 		,volume_uom_code
6529 		,unit_volume
6530 	 INTO
6531 	    l_item_primary_uom_code
6532 	   ,l_item_weight_uom_code
6533 	   ,l_item_unit_weight
6534 	   ,l_item_volume_uom_code
6535 	   ,l_item_unit_volume
6536 	 FROM
6537 	    mtl_system_items
6538 	 WHERE
6539 	    inventory_item_id = p_inventory_item_id  and
6540 	    organization_id   = p_organization_id;
6541 
6542 	 IF (l_debug = 1) THEN
6543    	 INV_TRX_UTIL_PUB.TRACE('The attributes of p_inventory_item are :' ||
6544 	       'l_item_primary_uom_code :'||l_item_primary_uom_code ||
6545 	       'l_item_weight_uom_code  :'||l_item_weight_uom_code ||
6546 	       'l_item_unit_weight  :'||to_char(l_item_unit_weight)||
6547 	       'l_item_volume_uom_code :'||l_item_volume_uom_code ||
6548 		'l_item_unit_volume :'||to_char(l_item_unit_volume),'UPD_LPN_LOC-ITEM_ATTRIBUTES',9
6549 	     );
6550 	 END IF;
6551 
6552 	 IF l_item_unit_weight IS NULL THEN
6553 	   IF (l_debug = 1) THEN
6554    	   INV_TRX_UTIL_PUB.TRACE('The item_unit_weight is either < 0 or null','UPD_LPN_LOC-ITEM_ATTRIBUTES',4);
6555 	   END IF;
6556 	   l_item_unit_weight := 0;
6557 	 ELSIF l_item_unit_volume IS NULL THEN
6558 	   IF (l_debug = 1) THEN
6559    	   INV_TRX_UTIL_PUB.TRACE('The item_unit_volume is either < 0 or null','UPD_LPN_LOC-ITEM_ATTRIBUTES',4);
6560 	   END IF;
6561 	   l_item_unit_volume := 0;
6562 	 END IF;
6563 
6564 	    /* Convert this unit_weight and unit_volume into
6565 		locator's weight_uom_code and volume_uom_code
6566 		if item_uom_code and locator's uom do not match
6567 	     */
6568 
6569 	  IF  l_item_weight_uom_code is not null AND
6570 	      p_locator_weight_uom_code is not null AND
6571 	      l_item_unit_weight >0  THEN
6572 	      IF (p_locator_weight_uom_code <> l_weight_uom_code) THEN
6573 
6574 		    l_item_unit_weight := inv_convert.inv_um_convert( item_id       => p_inventory_item_id,
6575 								      precision     => null,
6576 								      from_quantity => l_item_unit_weight,
6577 								      from_unit     => l_item_weight_uom_code,
6578 								      to_unit	    => p_locator_weight_uom_code,
6579 								      from_name     => null,
6580 								      to_name	    => null
6581 								     );
6582 	      ELSE
6583 		 l_item_unit_weight := l_item_unit_weight;
6584 	      END IF;
6585 	      IF l_item_unit_weight = -99999 THEN
6586 		  RAISE fnd_api.g_exc_error;
6587 	      END IF;
6588 	   END IF;
6589 
6590 	   IF  l_item_volume_uom_code is not null AND
6591 	       p_locator_volume_uom_code is not null AND
6592 	       l_item_unit_volume >0  THEN
6593 
6594 	       IF (p_locator_volume_uom_code<> l_volume_uom_code) THEN
6595 		  l_item_unit_volume := inv_convert.inv_um_convert(item_id       => p_inventory_item_id,
6596 								   precision     => null,
6597 								   from_quantity => l_item_unit_volume,
6598 								   from_unit     => l_item_volume_uom_code,
6599 								   to_unit	 => p_locator_volume_uom_code,
6600 								   from_name     => null,
6601 								   to_name	 => null
6602 								     );
6603 	       ELSE
6604 		      l_item_unit_volume := l_item_unit_volume;
6605 	       END IF;
6606 	       IF l_item_unit_volume = -99999 THEN
6607 		   RAISE fnd_api.g_exc_error;
6608 	       END IF;
6609 	   END IF;
6610 	   IF p_container_item ='Y' THEN
6611 
6612 	      x_item_unit_weight     := nvl(l_item_unit_weight,0);
6613 	      x_item_unit_volume     := nvl(l_item_unit_volume,0);
6614 	      x_item_weight_uom_code := l_item_weight_uom_code;
6615 	      x_item_volume_uom_code := l_item_volume_uom_code;
6616 	      x_item_xacted_weight   := null;
6617 	      x_item_xacted_volume   := null;
6618 
6619 	    IF (l_debug = 1) THEN
6620    	    INV_TRX_UTIL_PUB.TRACE('Item passed is a container item ','UPD_LPN_LOC-ITEM_ATTRIBUTES',4);
6621 	    END IF;
6622 
6623 	 ELSE /* Item passed is not a container item */
6624 
6625 	       IF l_primary_uom_code <> p_transaction_uom_code  and p_primary_uom_flag <>'Y'  THEN
6626 
6627 		  /* Convert the transaction_uom_qty into primary_uom_quantity if p_primary_uom_quantity_flag <>Y */
6628 		  IF (l_debug = 1) THEN
6629    		  INV_TRX_UTIL_PUB.TRACE('The value of primary_uom_flag  <>y or PUOM is not equal to Transaction UOM', 'UPDATE_LPN_LOC_CURR_CAPACITY',9);
6630 		  END IF;
6631 
6632 		  l_quantity := inv_convert.inv_um_convert(item_id       => p_inventory_item_id,
6633 						       precision     => null,
6634 						       from_quantity =>p_quantity,
6635 						       from_unit     => p_transaction_uom_code,
6636 						       to_unit       => l_item_primary_uom_code,
6637 						       from_name     => null,
6638 						       to_name       => null
6639 						     );
6640 	       ELSE
6641 		   l_quantity := p_quantity ;
6642 	       END IF;
6643 
6644 	       IF l_quantity = -99999 THEN
6645 		   RAISE fnd_api.g_exc_error;
6646 	       END IF;
6647 	       IF (l_debug = 1) THEN
6648    	       INV_TRX_UTIL_PUB.TRACE('The value of l_quantity is '||to_char(l_quantity),'UPD_LPN_LOC-ITEM_ATTRIBUTES',4);
6649 	       END IF;
6650 
6651 	       /* Check if the weight and volume uom code of item and locator are different.
6652 		  If so convert the weight and volume code of item in terms of locator weight
6653 		  and volume uom code
6654 	       */
6655 
6656 		 IF l_item_weight_uom_code is not null    AND
6657 		    p_locator_weight_uom_code is not null AND
6658 		    l_item_unit_weight >0  THEN
6659 
6660 		    IF (l_debug = 1) THEN
6661    		    INV_TRX_UTIL_PUB.TRACE('check if the p_locator_weight_uom_code and l_item_weight_uom_code are same or not', 'UPD_LPN_LOC-ITEM_ATTRIBUTES',4);
6662 		    END IF;
6663 
6664 		   l_item_xacted_weight := l_quantity *l_item_unit_weight;
6665 
6666 		    IF  (l_item_weight_uom_code <> p_locator_weight_uom_code) THEN
6667 			  IF (l_debug = 1) THEN
6668    			  INV_TRX_UTIL_PUB.TRACE('p_locator_weight_uom_code and l_item_weight_uom_code are not same', 'UPD_LPN_LOC-ITEM_ATTRIBUTES',4);
6669 			  END IF;
6670 
6671 			l_item_xacted_weight := inv_convert.inv_um_convert(
6672 							      item_id       => p_inventory_item_id,
6673 							      precision     => null,
6674 							      from_quantity => l_item_xacted_weight ,
6675 							      from_unit     => l_item_weight_uom_code,
6676 							      to_unit       => p_locator_weight_uom_code,
6677 							      from_name     => null,
6678 							      to_name       => null
6679 								    );
6680 			IF l_item_xacted_weight= -99999 THEN
6681 			   RAISE fnd_api.g_exc_error;
6682 			END IF;
6683 		    END IF;
6684 		  END IF;
6685 
6686 		IF (l_debug = 1) THEN
6687    		INV_TRX_UTIL_PUB.TRACE('The value of l_item_xacted_weight  is ' ||to_char(l_item_xacted_weight), 'UPD_LPN_LOC-ITEM_ATTRIBUTES',4);
6688 		END IF;
6689 
6690 		IF l_item_volume_uom_code IS NOT NULL and
6691 		   p_locator_volume_uom_code  IS NOT NULL and
6692 		   l_item_unit_volume >0 THEN
6693 
6694 		   l_item_xacted_volume  := l_quantity *l_item_unit_volume;
6695 
6696 		   IF  l_item_volume_uom_code <> p_locator_volume_uom_code THEN
6697 
6698 		      IF (l_debug = 1) THEN
6699    		      INV_TRX_UTIL_PUB.TRACE('p_locator_volume_uom_code and l_item_volume_uom_code are same or not', 'UPD_LPN_LOC-ITEM_ATTRIBUTES',4);
6700 		      END IF;
6701 
6702 		     l_item_xacted_volume  := inv_convert.inv_um_convert(item_id        => p_inventory_item_id,
6703 									 precision      => null,
6704 									 from_quantity  => l_item_xacted_volume,
6705 									 from_unit      => l_item_volume_uom_code,
6706 									 to_unit        => p_locator_volume_uom_code,
6707 									 from_name      => null,
6708 									 to_name        => null
6709 									);
6710 		  END IF;
6711 		  IF l_item_xacted_volume= -99999 THEN
6712 		      RAISE fnd_api.g_exc_error;
6713 		  END IF;
6714 	       END IF;
6715 
6716 	      x_item_unit_weight     := nvl(l_item_unit_weight,0);
6717 	      x_item_unit_volume     := nvl(l_item_unit_volume,0);
6718 	      x_item_weight_uom_code := l_item_weight_uom_code;
6719 	      x_item_volume_uom_code := l_item_volume_uom_code;
6720 	      x_item_xacted_weight   := nvl(l_item_xacted_weight,0);
6721 	      x_item_xacted_volume   := nvl(l_item_xacted_volume,0);
6722 
6723 	    IF (l_debug = 1) THEN
6724    	    INV_TRX_UTIL_PUB.TRACE('The value of l_item_xacted_volume is ' ||to_char(l_item_xacted_volume), 'UPD_LPN_LOC-ITEM_ATTRIBUTES',4);
6725 	    END IF;
6726 
6727 	 END IF; /* End of p_container_item =Y */
6728 EXCEPTION
6729       WHEN fnd_api.g_exc_error THEN
6730        x_return_status := fnd_api.g_ret_sts_error;
6731        fnd_msg_pub.count_and_get
6732 	( p_count => x_msg_count,
6733 	  p_data  => x_msg_data
6734 	 );
6735 
6736       WHEN fnd_api.g_exc_unexpected_error THEN
6737 	 x_return_status := fnd_api.g_ret_sts_unexp_error ;
6738        fnd_msg_pub.count_and_get
6739 	( p_count => x_msg_count,
6740 	  p_data  => x_msg_data
6741 	  );
6742 
6743    WHEN NO_DATA_FOUND THEN
6744       x_return_status := fnd_api.g_ret_sts_error;
6745 
6746    WHEN OTHERS THEN
6747       x_return_status := fnd_api.g_ret_sts_unexp_error;
6748      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
6749 	THEN
6750 	 fnd_msg_pub.add_exc_msg
6751 	   (  'inv_loc_wms_utils'
6752 	      , 'item_attributes'
6753 	      );
6754 	END IF;
6755      fnd_msg_pub.count_and_get
6756 	( p_count => x_msg_count,
6757 	  p_data  => x_msg_data
6758 	 );
6759 END ITEM_ATTRIBUTES;
6760 
6761 PROCEDURE LOC_EMPTY_MIXED_FLAG_AUTO(
6762   X_RETURN_STATUS          OUT NOCOPY VARCHAR2
6763 , X_MSG_COUNT              OUT NOCOPY NUMBER
6764 , X_MSG_DATA               OUT NOCOPY VARCHAR2
6765 , P_ORGANIZATION_ID        IN  NUMBER
6766 , P_INVENTORY_LOCATION_ID  IN  NUMBER
6767 , P_INVENTORY_ITEM_ID      IN  NUMBER
6768 , P_TRANSACTION_ACTION_ID  IN  NUMBER
6769 , P_TRANSFER_ORGANIZATION  IN  NUMBER
6770 , P_TRANSFER_LOCATION_ID   IN  NUMBER
6771 , P_SOURCE                 IN  VARCHAR2 )
6772 is
6773    PRAGMA autonomous_transaction;
6774 
6775    l_return_status 		varchar2(1);
6776    l_msg_data			varchar2(1000);
6777    l_msg_count			number;
6778     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6779 BEGIN
6780      x_return_status := fnd_api.g_ret_sts_success  ;
6781 
6782      INV_LOC_WMS_UTILS.LOC_EMPTY_MIXED_FLAG (
6783        X_RETURN_STATUS   	=> l_return_status
6784      , X_MSG_COUNT       	=> l_MSG_COUNT
6785      , X_MSG_DATA        	=> l_MSG_DATA
6786      , P_ORGANIZATION_ID 	=> p_organization_id
6787      , P_INVENTORY_LOCATION_ID  => p_inventory_location_id
6788      , P_INVENTORY_ITEM_ID      => p_inventory_item_id
6789      , P_TRANSACTION_ACTION_ID  => p_transaction_action_id
6790      , P_TRANSFER_ORGANIZATION  => p_transfer_organization
6791      , P_TRANSFER_LOCATION_ID   => p_transfer_location_id
6792      , P_SOURCE                 => null);
6793 
6794     if l_return_status <> fnd_api.g_ret_sts_success THEN
6795 	IF l_return_status = fnd_api.g_ret_sts_error then
6796 	   raise fnd_api.g_exc_error;
6797 	ELSE
6798 	   RAISE fnd_api.g_exc_unexpected_error;
6799 	END IF;
6800     end if;
6801 
6802     commit;
6803 EXCEPTION
6804   WHEN fnd_api.g_exc_error THEN
6805       x_return_status := fnd_api.g_ret_sts_error;
6806       fnd_msg_pub.count_and_get
6807 	( p_count => x_msg_count,
6808 	  p_data  => x_msg_data
6809 	 );
6810 
6811    WHEN fnd_api.g_exc_unexpected_error THEN
6812       x_return_status := fnd_api.g_ret_sts_unexp_error ;
6813        fnd_msg_pub.count_and_get
6814 	( p_count => x_msg_count,
6815 	  p_data  => x_msg_data
6816 	  );
6817 
6818    WHEN NO_DATA_FOUND THEN
6819       x_return_status := fnd_api.g_ret_sts_error;
6820 
6821    WHEN OTHERS THEN
6822       x_return_status := fnd_api.g_ret_sts_unexp_error;
6823      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
6824 	THEN
6825 	 fnd_msg_pub.add_exc_msg
6826 	   (  'inv_loc_wms_utils'
6827 	      , 'LOC_EMPTY_MIXED_FLAG_AUTO'
6828 	      );
6829 	END IF;
6830      fnd_msg_pub.count_and_get
6831 	( p_count => x_msg_count,
6832 	  p_data  => x_msg_data
6833 	 );
6834 END LOC_EMPTY_MIXED_FLAG_AUTO ;
6835 
6836 PROCEDURE LOC_EMPTY_MIXED_FLAG(
6837   X_RETURN_STATUS          OUT NOCOPY VARCHAR2
6838 , X_MSG_COUNT              OUT NOCOPY NUMBER
6839 , X_MSG_DATA               OUT NOCOPY VARCHAR2
6840 , P_ORGANIZATION_ID        IN  NUMBER
6841 , P_INVENTORY_LOCATION_ID  IN  NUMBER
6842 , P_INVENTORY_ITEM_ID      IN  NUMBER
6843 , P_TRANSACTION_ACTION_ID  IN  NUMBER
6844 , P_TRANSFER_ORGANIZATION  IN  NUMBER
6845 , P_TRANSFER_LOCATION_ID   IN  NUMBER
6846 , P_SOURCE                 IN  VARCHAR2 )
6847 IS
6848     l_physical_locator_id             NUMBER;
6849     l_loc_id                          NUMBER;
6850     l_des_physical_locator_id         NUMBER;
6851     l_des_loc_id                      NUMBER;
6852     l_inventory_location_id           NUMBER;
6853     l_des_inventory_location_id       NUMBER;
6854     l_chk_flag                        NUMBER;
6855     l_mixed_flag                      VARCHAR2(1);
6856     l_empty_flag                      VARCHAR2(1);
6857     l_item_id                         NUMBER;
6858     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6859 BEGIN
6860    IF (l_debug = 1) THEN
6861       INV_TRX_UTIL_PUB.TRACE('In LOC_EMPTY_MIXED_FLAG Procedure ','LOC_EMPTY_MIXED_FLAG',10);
6862    END IF;
6863 
6864     -- Fixed bug 2342723, remove the savepoint
6865     -- savepoint loc_empty;
6866 
6867    x_return_status := FND_API.G_RET_STS_SUCCESS;
6868 
6869    SELECT physical_location_id ,
6870 	  inventory_location_id
6871    INTO l_physical_locator_id,
6872 	l_loc_id
6873    FROM mtl_item_locations
6874    WHERE  inventory_location_id = p_inventory_location_id
6875    and    organization_id       = p_organization_id;
6876 
6877    IF l_physical_locator_id is null THEN
6878      l_inventory_location_id := l_loc_id;
6879    ELSE
6880      l_inventory_location_id := l_physical_locator_id;
6881    END IF;
6882 
6883    -- Bug# 3067627
6884    IF (l_debug = 1) THEN
6885       mdebug('Before locking locator ' || l_inventory_location_id || ' in LOC_EMPTY_MIXED_FLAG(1)');
6886    END IF;
6887 
6888    SELECT inventory_location_id INTO l_inventory_location_id
6889    FROM mtl_item_locations
6890    WHERE  inventory_location_id = l_inventory_location_id
6891        and organization_id = p_organization_id
6892    FOR UPDATE NOWAIT;
6893 
6894    IF (l_debug = 1) THEN
6895       mdebug('After locking locator ' || l_inventory_location_id || ' in LOC_EMPTY_MIXED_FLAG(1)');
6896    END IF;
6897 
6898    IF P_TRANSACTION_ACTION_ID IN (27,12) /* Receipt */ THEN
6899        /* Check if there is more than one item in the locator either in
6900        ** loose state or packed in the LPN sitting in the same locator.
6901        ** Check in MOQD if there is any other item in the
6902        ** same locator other than the inventory item id passed as IN
6903        ** parameter. If found then we have to Flag Mixed Flag =Y' and null
6904        ** out the inventory Item id column in MIL.
6905        */
6906 
6907        IF (l_debug = 1) THEN
6908           INV_TRX_UTIL_PUB.TRACE('Receipt transaction ','LOC_EMPTY_MIXED_FLAG',10);
6909        END IF;
6910 
6911        INV_LOC_WMS_UTILS.inv_loc_receipt (x_return_status     => X_return_status
6912 				   ,X_MSG_COUNT         => X_msg_count
6913 				   ,X_MSG_DATA          => X_msg_data
6914 				   ,X_EMPTY_FLAG        => l_empty_flag
6915 				   ,X_MIXED_FLAG        => l_mixed_flag
6916 				   ,X_ITEM_ID           => l_item_id
6917 				   ,P_LOCATOR_ID        => l_inventory_location_id
6918 				   ,P_ORG_ID            => P_ORGANIZATION_ID
6919 				   ,P_INVENTORY_ITEM_ID => P_INVENTORY_ITEM_ID
6920 				   ) ;
6921 
6922        IF X_RETURN_STATUS =fnd_api.g_ret_sts_error THEN
6923              IF (l_debug = 1) THEN
6924                 INV_TRX_UTIL_PUB.TRACE('Failed for Receipt transaction with status -E ', 'LOC_EMPTY_MIXED_FLAG',9);
6925              END IF;
6926 	     RAISE fnd_api.g_exc_error;
6927        ELSIF X_RETURN_STATUS =fnd_api.g_ret_sts_unexp_error THEN
6928 	     IF (l_debug = 1) THEN
6929    	     INV_TRX_UTIL_PUB.TRACE('Failed for Receipt transaction with status -U ', 'LOC_EMPTY_MIXED_FLAG',9);
6930 	     END IF;
6931 	     RAISE fnd_api.g_exc_unexpected_error;
6932        END IF;
6933 
6934      ELSIF P_TRANSACTION_ACTION_ID in (1,21,32,34) /* Issue */  THEN
6935 	  IF (l_debug = 1) THEN
6936    	  INV_TRX_UTIL_PUB.TRACE('Issue transaction ','LOC_EMPTY_MIXED_FLAG',10);
6937 	  END IF;
6938 
6939 	  INV_LOC_WMS_UTILS.inv_loc_issues  (x_return_status    => X_return_status
6940 				   ,X_MSG_COUNT        => X_msg_count
6941 				   ,X_MSG_DATA         => X_msg_data
6942 				   ,X_EMPTY_FLAG       => l_empty_flag
6943 				   ,X_MIXED_FLAG       => l_mixed_flag
6944 				   ,X_ITEM_ID          => l_item_id
6945 				   ,P_ORG_ID           => P_ORGANIZATION_ID
6946 				   ,P_LOCATOR_ID       => l_inventory_location_id
6947 				   ,P_INVENTORY_ITEM_ID=> P_INVENTORY_ITEM_ID
6948 				   ,P_SOURCE           =>p_source
6949 				    ) ;
6950 	  IF X_RETURN_STATUS =fnd_api.g_ret_sts_error THEN
6951 	       IF (l_debug = 1) THEN
6952    	       INV_TRX_UTIL_PUB.TRACE('Failed for Issue transaction with status -E ', 'LOC_EMPTY_MIXED_FLAG',9);
6953 	       END IF;
6954                RAISE fnd_api.g_exc_error;
6955 	  ELSIF X_RETURN_STATUS =fnd_api.g_ret_sts_unexp_error THEN
6956 	      IF (l_debug = 1) THEN
6957    	      INV_TRX_UTIL_PUB.TRACE('Failed for Issue transaction with status - U', 'LOC_EMPTY_MIXED_FLAG',9);
6958 	      END IF;
6959 	       RAISE fnd_api.g_exc_unexpected_error;
6960 	  END IF;
6961     ELSIF p_transaction_action_id in(2,3,28) /* TRANSFER */ THEN
6962 
6963 	IF (l_debug = 1) THEN
6964    	INV_TRX_UTIL_PUB.TRACE('Transfer transaction ','LOC_EMPTY_MIXED_FLAG',10);
6965 	END IF;
6966 
6967         if (p_transfer_location_id > 0) then
6968           /* For the destination organization */
6969 
6970 	  SELECT physical_location_id ,
6971 		 inventory_location_id
6972 	  INTO l_des_physical_locator_id,
6973 	       l_des_loc_id
6974 	  FROM mtl_item_locations
6975 	  WHERE  inventory_location_id = p_transfer_location_id
6976 	  and    organization_id       = p_transfer_organization;
6977 
6978 	  IF l_des_physical_locator_id is null THEN
6979 	    l_des_inventory_location_id := l_des_loc_id;
6980 	  ELSE
6981 	   l_des_inventory_location_id := l_des_physical_locator_id;
6982 	  END IF;
6983 
6984 	   -- Bug# 3067627
6985 	   IF (l_debug = 1) THEN
6986 	      mdebug('Before locking destination locator ' || l_des_inventory_location_id || ' in LOC_EMPTY_MIXED_FLAG(2)');
6987 	   END IF;
6988 
6989 	   SELECT inventory_location_id INTO l_des_inventory_location_id
6990 	   FROM mtl_item_locations
6991 	   WHERE  inventory_location_id = l_des_inventory_location_id
6992 	       and organization_id = p_transfer_organization
6993 	   FOR UPDATE NOWAIT;
6994 
6995 	   IF (l_debug = 1) THEN
6996 	      mdebug('After locking destination locator ' || l_des_inventory_location_id || ' in LOC_EMPTY_MIXED_FLAG(2)');
6997 	   END IF;
6998 
6999           IF (l_debug = 1) THEN
7000              INV_TRX_UTIL_PUB.TRACE('Before call to Receipt transaction ', 'LOC_EMPTY_MIXED_FLAG',10);
7001           END IF;
7002 
7003 	  INV_LOC_WMS_UTILS.inv_loc_receipt (
7004                                     x_return_status     => X_return_status
7005 				   ,X_MSG_COUNT         => X_msg_count
7006 				   ,X_MSG_DATA          => X_msg_data
7007 				   ,X_EMPTY_FLAG        => l_empty_flag
7008 				   ,X_MIXED_FLAG        => l_mixed_flag
7009 				   ,X_ITEM_ID           => l_item_id
7010 				   ,P_LOCATOR_ID        => l_des_inventory_location_id
7011 				   ,P_ORG_ID            => P_TRANSFER_ORGANIZATION
7012 				   ,P_INVENTORY_ITEM_ID => P_INVENTORY_ITEM_ID
7013 				    ) ;
7014 	  IF X_RETURN_STATUS =fnd_api.g_ret_sts_error THEN
7015 		      IF (l_debug = 1) THEN
7016    		      INV_TRX_UTIL_PUB.TRACE('Failed for Receipt transaction with status -E ', 'LOC_EMPTY_MIXED_FLAG',9);
7017 		      END IF;
7018 		       RAISE fnd_api.g_exc_error;
7019 	  ELSIF X_RETURN_STATUS =fnd_api.g_ret_sts_unexp_error THEN
7020 		      IF (l_debug = 1) THEN
7021    		      INV_TRX_UTIL_PUB.TRACE('Failed for Receipt transaction with status -U ', 'LOC_EMPTY_MIXED_FLAG',9);
7022 		      END IF;
7023 		       RAISE fnd_api.g_exc_unexpected_error;
7024 	  END IF;
7025 
7026 	  IF (l_debug = 1) THEN
7027    	  INV_TRX_UTIL_PUB.TRACE('Before Updating destination locator ', 'LOC_EMPTY_MIXED_FLAG',10);
7028    	  INV_TRX_UTIL_PUB.TRACE('The values of Empty _Flag is '||l_empty_flag , 'LOC_EMPTY_MIXED_FLAG',10);
7029              INV_TRX_UTIL_PUB.TRACE('The values of Mixed_Flag is '||l_mixed_flag , 'LOC_EMPTY_MIXED_FLAG',10);
7030              INV_TRX_UTIL_PUB.TRACE('The values of Item ID is '||l_item_id , 'LOC_EMPTY_MIXED_FLAG',10);
7031           END IF;
7032 
7033           UPDATE MTL_ITEM_LOCATIONS mil
7034 	          SET EMPTY_FLAG            = nvl(l_empty_flag,mil.empty_flag)
7035 	            , MIXED_ITEMS_FLAG      = nvl(l_mixed_flag,mil.mixed_items_flag)
7036                , INVENTORY_ITEM_ID     = nvl(l_item_id,mil.inventory_item_id)
7037 	       , LAST_UPDATE_DATE     = sysdate                                                       /* Added for Bug 6363028 */
7038            WHERE INVENTORY_LOCATION_ID = l_des_inventory_location_id
7039 	          AND ORGANIZATION_ID       = P_TRANSFER_ORGANIZATION;
7040 
7041  	end if;
7042 
7043         /* For the Source Organization */
7044 
7045         IF (l_debug = 1) THEN
7046            INV_TRX_UTIL_PUB.TRACE('Before call to Issue transaction ','LOC_EMPTY_MIXED_FLAG',10);
7047         END IF;
7048 
7049         INV_LOC_WMS_UTILS.inv_loc_issues(x_return_status    => X_return_status
7050 				   ,X_MSG_COUNT        => X_msg_count
7051 				   ,X_MSG_DATA         => X_msg_data
7052 				   ,X_EMPTY_FLAG       => l_empty_flag
7053 				   ,X_MIXED_FLAG       => l_mixed_flag
7054 				   ,X_ITEM_ID          => l_item_id
7055 				   ,P_ORG_ID           => P_ORGANIZATION_ID
7056 				   ,P_LOCATOR_ID       => l_inventory_location_id
7057 				   ,P_INVENTORY_ITEM_ID=> P_INVENTORY_ITEM_ID
7058 				   ,P_SOURCE           =>p_source
7059 				    ) ;
7060         IF X_RETURN_STATUS =fnd_api.g_ret_sts_error THEN
7061 		      IF (l_debug = 1) THEN
7062    		      INV_TRX_UTIL_PUB.TRACE('Failed for Issue transaction with status -E ', 'LOC_EMPTY_MIXED_FLAG',9);
7063 		      END IF;
7064 		       RAISE fnd_api.g_exc_error;
7065         ELSIF X_RETURN_STATUS =fnd_api.g_ret_sts_unexp_error THEN
7066 		       IF (l_debug = 1) THEN
7067    		       INV_TRX_UTIL_PUB.TRACE('Failed for Issue transaction with status - U', 'LOC_EMPTY_MIXED_FLAG',9);
7068 		       END IF;
7069 		       RAISE fnd_api.g_exc_unexpected_error;
7070         END IF;
7071       END IF; /* End if for the transaction_action_id */
7072 
7073       IF (l_debug = 1) THEN
7074          INV_TRX_UTIL_PUB.TRACE('The values of Empty _Flag is '|| l_empty_flag , 'LOC_EMPTY_MIXED_FLAG',10);
7075          INV_TRX_UTIL_PUB.TRACE('The values of Mixed_Flag is '|| l_mixed_flag , 'LOC_EMPTY_MIXED_FLAG',10);
7076          INV_TRX_UTIL_PUB.TRACE('The values of Item ID is '|| l_item_id , 'LOC_EMPTY_MIXED_FLAG',10);
7077       END IF;
7078 
7079       --Bug#2756609. Should update empty_flag and mixed_items_flag only if
7080       --the values passed are not null.
7081 
7082       UPDATE MTL_ITEM_LOCATIONS MIL
7083          SET EMPTY_FLAG            = NVL(l_empty_flag,MIL.empty_flag)
7084            , MIXED_ITEMS_FLAG      = NVL(l_mixed_flag,MIL.mixed_items_flag)
7085            , INVENTORY_ITEM_ID     = NVL(l_item_id,MIL.inventory_item_id)
7086            , LAST_UPDATE_DATE     = sysdate                                                       /* Added for Bug 6363028 */
7087        WHERE INVENTORY_LOCATION_ID = l_inventory_location_id
7088          AND ORGANIZATION_ID       = P_ORGANIZATION_ID;
7089 
7090       IF (l_debug = 1) THEN
7091          INV_TRX_UTIL_PUB.TRACE('End of Procedure LOC_EMPTY_MIXED_FLAG ', 'LOC_EMPTY_MIXED_FLAG',10);
7092       END IF;
7093 EXCEPTION
7094  WHEN fnd_api.g_exc_error THEN
7095       x_return_status := fnd_api.g_ret_sts_error;
7096     --Fixed bug 2342723, do not rollback to savepoint
7097     --ROLLBACK TO loc_empty;
7098     ROLLBACK;
7099       fnd_msg_pub.count_and_get
7100 	( p_count => x_msg_count,
7101 	  p_data  => x_msg_data
7102 	);
7103  WHEN fnd_api.g_exc_unexpected_error THEN
7104       x_return_status := fnd_api.g_ret_sts_unexp_error ;
7105     --ROLLBACK TO loc_empty;
7106     ROLLBACK;
7107        fnd_msg_pub.count_and_get
7108 	( p_count => x_msg_count,
7109 	  p_data  => x_msg_data
7110 	  );
7111  WHEN NO_DATA_FOUND THEN
7112       x_return_status := fnd_api.g_ret_sts_error;
7113     --ROLLBACK TO loc_empty;
7114     ROLLBACK;
7115  WHEN OTHERS THEN
7116       x_return_status := fnd_api.g_ret_sts_unexp_error;
7117     --ROLLBACK TO loc_empty;
7118     ROLLBACK;
7119      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
7120 	 fnd_msg_pub.add_exc_msg
7121 	   (  'inv_loc_wms_utils'
7122 	    , 'LOC_EMPTY_MIXED_FLAG '
7123 	    );
7124      END IF;
7125      fnd_msg_pub.count_and_get
7126 	 ( p_count => x_msg_count,
7127 	  p_data  => x_msg_data
7128 	 );
7129 END LOC_EMPTY_MIXED_FLAG;
7130 
7131 procedure inv_loc_issues  (
7132   x_return_status     OUT NOCOPY VARCHAR2
7133 , X_MSG_COUNT        OUT NOCOPY NUMBER
7134 , X_MSG_DATA         OUT NOCOPY VARCHAR2
7135 , X_EMPTY_FLAG       OUT NOCOPY VARCHAR2
7136 , X_MIXED_FLAG       OUT NOCOPY VARCHAR2
7137 , X_ITEM_ID          OUT NOCOPY NUMBER
7138 , P_ORG_ID           IN NUMBER
7139 , P_LOCATOR_ID       IN NUMBER
7140 , P_INVENTORY_ITEM_ID IN NUMBER
7141 , P_SOURCE           IN VARCHAR2 )
7142 IS
7143     cursor item_cnt
7144     is
7145     SELECT inventory_item_id
7146     FROM MTL_ONHAND_QUANTITIES_DETAIL
7147     WHERE LOCATOR_ID = p_locator_id
7148     and   organization_id =p_org_id
7149     and   inventory_item_id <> p_inventory_item_id
7150     and   rownum <3
7151     group by inventory_item_id;
7152 
7153     l_loc_current_units    NUMBER;
7154     l_loc_suggested_units  NUMBER;
7155     l_chk_flag             NUMBER;
7156     l_item                 item_cnt%rowtype;
7157     l_mixed_flag           varchar2(1);
7158     l_empty_flag           varchar2(1);
7159     l_inventory_item_id    number;
7160     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
7161 BEGIN
7162 
7163        IF (l_debug = 1) THEN
7164           INV_TRX_UTIL_PUB.TRACE('In Procedure inv_loc_issues ','inv_loc_issues',10);
7165        END IF;
7166 
7167        x_return_status := FND_API.G_RET_STS_SUCCESS;
7168 
7169        IF P_SOURCE IS NULL THEN
7170 
7171 	  IF (l_debug = 1) THEN
7172    	  INV_TRX_UTIL_PUB.TRACE('P_Source is null ','inv_loc_issues',10);
7173 	  END IF;
7174 
7175 	   SELECT LOCATION_CURRENT_UNITS,
7176                   location_suggested_units,
7177 		  mixed_items_flag,
7178 		  inventory_item_id,
7179 		  empty_flag
7180 	   INTO l_loc_current_units ,
7181                 l_loc_suggested_units,
7182 		l_mixed_flag,
7183 		l_inventory_item_id,
7184 		l_empty_flag
7185 	   FROM MTL_ITEM_LOCATIONS
7186 	   WHERE INVENTORY_LOCATION_ID = p_locator_id
7187 	      AND ORGANIZATION_ID      = P_ORG_ID;
7188 
7189 	   IF ((nvl(l_loc_current_units,0)   = 0)  and
7190                (nvl(l_loc_suggested_units,0) = 0)) THEN
7191 
7192 	      IF (l_debug = 1) THEN
7193    	      INV_TRX_UTIL_PUB.TRACE('Current/Suggested units is 0 ','inv_loc_issues',10);
7194 	      END IF;
7195 	      x_empty_flag := 'Y';
7196 	      x_mixed_flag := 'N';
7197 	      x_item_id    := null;
7198 	    ELSE
7199 	      x_empty_flag := l_empty_flag;
7200 	      x_mixed_flag := l_mixed_flag;
7201 	      x_item_id    := l_inventory_item_id;
7202 	   END IF;
7203 	ELSE
7204 	  IF (l_debug = 1) THEN
7205    	  INV_TRX_UTIL_PUB.TRACE('P_Source is not null ','inv_loc_issues',10);
7206 	  END IF;
7207 	       BEGIN
7208 		  SELECT 1
7209 		  INTO l_chk_flag
7210 		  FROM dual
7211 		  WHERE EXISTS (SELECT 1
7212 				FROM MTL_ONHAND_QUANTITIES_DETAIL
7213 				WHERE	LOCATOR_ID        = P_LOCATOR_ID
7214 				   AND	ORGANIZATION_ID	  = P_ORG_ID
7215 				   AND	INVENTORY_ITEM_ID = P_INVENTORY_ITEM_ID
7216 				 );
7217 		     IF (l_debug = 1) THEN
7218    		     INV_TRX_UTIL_PUB.TRACE('Item exists in MOQD ','inv_loc_issues',10);
7219 		     END IF;
7220 		  BEGIN
7221 		    SELECT 1
7222 		    INTO l_chk_flag
7223 		    FROM dual
7224 		    WHERE EXISTS (SELECT 1
7225 				  FROM  MTL_ONHAND_QUANTITIES_DETAIL
7226 				  WHERE LOCATOR_ID        =  P_LOCATOR_ID
7227 				    AND ORGANIZATION_ID   =  P_ORG_ID
7228 				    AND INVENTORY_ITEM_ID <> P_INVENTORY_ITEM_ID
7229 				  );
7230 		    x_empty_flag :='N';
7231 		    x_mixed_flag :='Y';
7232 		    x_item_id := NULL;
7233 
7234 		    IF (l_debug = 1) THEN
7235    		    INV_TRX_UTIL_PUB.TRACE('More than  one item exists in locator ', 'inv_loc_issues',10);
7236 		    END IF;
7237 		  EXCEPTION
7238 		    WHEN NO_DATA_FOUND THEN
7239 		     IF (l_debug = 1) THEN
7240    		     INV_TRX_UTIL_PUB.TRACE('Only one item exists in locator', 'inv_loc_issues',10);
7241 		     END IF;
7242 		     x_empty_flag :='N';
7243 		     x_mixed_flag :='N';
7244 		     x_item_id    := p_inventory_item_id;
7245 		  END;
7246 		EXCEPTION
7247 		     WHEN NO_DATA_FOUND	THEN
7248 		     IF (l_debug = 1) THEN
7249    		     INV_TRX_UTIL_PUB.TRACE('Item passed does not exists in MOQD ', 'inv_loc_issues',10);
7250 		     END IF;
7251 		      open item_cnt;
7252 		      loop
7253 			fetch item_cnt into  l_item;
7254 			exit when item_cnt%notfound or item_cnt%rowcount =2;
7255 		      end loop;
7256 			IF item_cnt%rowcount =0	THEN
7257 			  IF (l_debug = 1) THEN
7258    			  INV_TRX_UTIL_PUB.TRACE('Locator is empty','inv_loc_issues',10);
7259 			  END IF;
7260 			   x_empty_flag	:= 'Y';
7261 			   x_mixed_flag	:= 'N';
7262 			   x_item_id :=	null;
7263 			ELSIF item_cnt%rowcount	=1 THEN
7264 			  IF (l_debug = 1) THEN
7265    			  INV_TRX_UTIL_PUB.TRACE('One item alone exists	in the locator', 'inv_loc_issues',10);
7266 			  END IF;
7267 			   x_empty_flag	:= 'N';
7268 			   x_mixed_flag	:= 'N';
7269 			   x_item_id :=	l_item.inventory_item_id;
7270 			ELSIF item_cnt%rowcount	=2 THEN
7271 			  IF (l_debug = 1) THEN
7272    			  INV_TRX_UTIL_PUB.TRACE('More than one	item alone exists in the locator', 'inv_loc_issues',10);
7273 			  END IF;
7274 			   x_empty_flag	:= 'N';
7275 			   x_mixed_flag	:= 'Y';
7276 			   x_item_id :=	null;
7277 			END IF;
7278 		      CLOSE ITEM_CNT;
7279 		END;
7280 	END IF; /* FOR P_SOURCE IS NULL*/
7281 EXCEPTION
7282  WHEN OTHERS THEN
7283       x_return_status := fnd_api.g_ret_sts_unexp_error;
7284      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
7285 	 fnd_msg_pub.add_exc_msg
7286 	   (  'inv_loc_wms_utils'
7287 	    , 'inv_loc_issues'
7288 	    );
7289      END IF;
7290      fnd_msg_pub.count_and_get
7291 	 ( p_count => x_msg_count,
7292 	  p_data  => x_msg_data
7293 	 );
7294 END inv_loc_issues;
7295 
7296 procedure inv_loc_receipt ( x_return_status     OUT NOCOPY VARCHAR2
7297 			   ,X_MSG_COUNT         OUT NOCOPY NUMBER
7298 			   ,X_MSG_DATA          OUT NOCOPY VARCHAR2
7299 			   ,X_EMPTY_FLAG        OUT NOCOPY VARCHAR2
7300 			   ,X_MIXED_FLAG        OUT NOCOPY VARCHAR2
7301 			   ,X_ITEM_ID           OUT NOCOPY NUMBER
7302 			   ,P_LOCATOR_ID        IN NUMBER
7303 			   ,P_ORG_ID            IN NUMBER
7304 			   ,P_INVENTORY_ITEM_ID IN NUMBER
7305 			   )
7306 is
7307    l_chk_flag number;
7308    l_subinventory_code varchar2(30); --Added variable for 3237709
7309     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
7310 BEGIN
7311    x_return_status := FND_API.G_RET_STS_SUCCESS;
7312 
7313       IF (l_debug = 1) THEN
7314          INV_TRX_UTIL_PUB.TRACE('In Procedure inv_loc_receipt ','receipts',10);
7315       END IF;
7316     --Added to get subinventory bug3237709
7317  SELECT subinventory_code
7318    INTO l_subinventory_code
7319    FROM mtl_item_locations
7320    WHERE  inventory_location_id = p_locator_id
7321    and    organization_id       = p_org_id;
7322 
7323      BEGIN
7324 	 SELECT 1
7325 	 INTO l_chk_flag
7326 	 FROM dual
7327 	 WHERE EXISTS (
7328                        -- Onhand
7329 		       SELECT 1
7330 		       FROM  MTL_ONHAND_QUANTITIES_DETAIL
7331 		       WHERE LOCATOR_ID     = P_LOCATOR_ID
7332 			AND ORGANIZATION_ID = P_ORG_ID
7333 			AND INVENTORY_ITEM_ID <> P_INVENTORY_ITEM_ID
7334                         AND SUBINVENTORY_CODE = l_subinventory_code --Added 3237709
7335 
7336                        UNION ALL --Bug 4566485
7337 
7338                        -- Pending/Suggestion receipts
7339 	               SELECT 1
7340 		       FROM  mtl_material_transactions_temp
7341 		       WHERE LOCATOR_ID     = P_LOCATOR_ID
7342 			AND ORGANIZATION_ID = P_ORG_ID
7343 			AND INVENTORY_ITEM_ID <> P_INVENTORY_ITEM_ID
7344                         AND POSTING_FLAG    = 'Y'
7345                         AND transaction_action_id IN (12,27)
7346                         AND SUBINVENTORY_CODE = l_subinventory_code --Added 3237709
7347 
7348                        UNION ALL --Bug 4566485
7349 
7350                        -- Pending/Suggestion receipts on transfer side
7351 	               SELECT 1
7352 		       FROM  mtl_material_transactions_temp
7353 		       WHERE TRANSFER_TO_LOCATION  = P_LOCATOR_ID
7354 			AND ORGANIZATION_ID        = P_ORG_ID
7355 			AND INVENTORY_ITEM_ID <> P_INVENTORY_ITEM_ID
7356                         AND POSTING_FLAG           = 'Y'
7357                         AND transaction_action_id IN (2,3,28)
7358                         AND SUBINVENTORY_CODE = l_subinventory_code --Added 3237709
7359 		       );
7360 
7361 	 X_EMPTY_FLAG := 'N';
7362 	 X_mixed_flag := 'Y';
7363 	 X_item_id    := NULL;
7364 
7365 	IF (l_debug = 1) THEN
7366    	INV_TRX_UTIL_PUB.TRACE('More than 1 item exists in the locator','inv_loc_receipts',10);
7367 	END IF;
7368 
7369        EXCEPTION
7370 	WHEN NO_DATA_FOUND THEN
7371 	   IF (l_debug = 1) THEN
7372    	   INV_TRX_UTIL_PUB.TRACE('Only one item exists in the locator','inv_loc_receipts',10);
7373 	   END IF;
7374 	      X_EMPTY_FLAG := 'N';
7375 	      x_mixed_flag := 'N';
7376 	      x_item_id    := P_INVENTORY_ITEM_ID;
7377 	END;
7378 EXCEPTION
7379   WHEN OTHERS THEN
7380      x_return_status := fnd_api.g_ret_sts_unexp_error;
7381 
7382      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
7383 	 fnd_msg_pub.add_exc_msg
7384 	   (  'inv_loc_wms_utils'
7385 	    , 'lpn_loc_receipt'
7386 	    );
7387      END IF;
7388 
7389      fnd_msg_pub.count_and_get
7390 	 ( p_count => x_msg_count,
7391 	  p_data  => x_msg_data
7392 	 );
7393 END inv_loc_receipt;
7394 
7395 PROCEDURE lpn_loc_cleanup_mmtt(x_return_status   OUT NOCOPY varchar2 --return status
7396 			  ,x_msg_count       OUT NOCOPY NUMBER --number of messages in message queue
7397 			  ,x_msg_data        OUT NOCOPY varchar2 --message text when x_msg_count>0
7398 			  ,p_organization_id IN NUMBER -- identier for the organization
7399 			  ,p_mixed_flag      IN VARCHAR2
7400 			  )
7401 IS
7402  cursor mmtt_cur_mixed_flg is
7403   SELECT MMTT.organization_id,
7404 	 MMTT.inventory_item_id,
7405 	 MMTT.locator_id,
7406 	 MMTT.transfer_organization,
7407 	 MMTT.transfer_to_location,
7408 	 MMTT.transaction_action_id,
7409 	 MMTT.primary_quantity,
7410 	 MMTT.transaction_quantity,
7411 	 MMTT.transfer_lpn_id,
7412 	 MMTT.content_lpn_id,
7413 	 MMTT.lpn_id
7414    FROM MTL_MATERIAL_TRANSACTIONS_TEMP MMTT,
7415 	MTL_ITEM_LOCATIONS MIL
7416    WHERE MMTT.transaction_status <> 2
7417     AND MMTT.organization_id = p_organization_id
7418     AND MMTT.LOCATOR_ID = MIL.INVENTORY_LOCATION_ID
7419     AND MIL.MIXED_ITEMS_FLAG ='Y'
7420     AND MMTT.locator_id >0
7421     AND (MMTT.transfer_lpn_id is not null or
7422 	 MMTT.content_lpn_id is not null or
7423 	 MMTT.lpn_id is not null
7424 	);
7425 
7426  cursor mmtt_cur is
7427   SELECT organization_id,
7428 	 inventory_item_id,
7429 	 locator_id,
7430 	 transfer_organization,
7431 	 transfer_to_location,
7432 	transaction_action_id,
7433 	primary_quantity,
7434 	transaction_quantity,
7435 	transfer_lpn_id,
7436 	content_lpn_id,
7437 	lpn_id
7438    FROM MTL_MATERIAL_TRANSACTIONS_TEMP
7439    WHERE transaction_status <> 2
7440     AND organization_id = p_organization_id
7441     and locator_id >0
7442     AND (transfer_lpn_id is not null or
7443 	 content_lpn_id is not null or
7444 	 lpn_id is not null
7445 	);
7446  l_mmtt_cur_mixed_flg          mmtt_cur_mixed_flg%ROWTYPE;
7447  l_mmtt_cur                    mmtt_cur%ROWTYPE ;
7448  l_return_status               varchar2(10);
7449  l_msg_data                    varchar2(1000);
7450  l_msg_count                   number;
7451     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
7452 BEGIN
7453     x_return_status := fnd_api.g_ret_sts_success;
7454     --Fixed bug 2342723, removed savepoint
7455     -- bug 3511690 retained the savepoint
7456     savepoint lpn_loc_mmtt_upd;
7457     IF p_mixed_flag IS NOT NULL THEN
7458      open  mmtt_cur_mixed_flg;
7459      loop
7460      fetch  mmtt_cur_mixed_flg into l_mmtt_cur_mixed_flg;
7461      exit when mmtt_cur_mixed_flg%NOTFOUND;
7462 	 IF (l_debug = 1) THEN
7463    	 INV_TRX_UTIL_PUB.TRACE('Fetch from mmtt_cur_mixed_flg is success','LPN_LOC_CLEANUP_MMTT',4);
7464 	 END IF;
7465 
7466 	IF l_mmtt_cur_mixed_flg.transaction_action_id in (2,3,28) then
7467 	    if l_mmtt_cur_mixed_flg.transfer_organization is null then
7468 		l_mmtt_cur_mixed_flg.transfer_organization := l_mmtt_cur_mixed_flg.organization_id;
7469 	     end if;
7470 	    INV_LOC_WMS_UTILS.upd_lpn_loc_curr_cpty_nauto(x_return_status    => l_return_status,
7471 					x_msg_count             => l_msg_count ,
7472 					x_msg_data              => l_msg_data ,
7473 					p_organization_id       => l_mmtt_cur_mixed_flg.transfer_organization,
7474 					p_inventory_location_id => l_mmtt_cur_mixed_flg.transfer_to_location,
7475 					p_inventory_item_id     => l_mmtt_cur_mixed_flg.inventory_item_id,
7476 					p_primary_uom_flag      => 'Y',
7477 					p_transaction_uom_code  => NULL,
7478 					p_transaction_action_id => l_mmtt_cur_mixed_flg.transaction_action_id,
7479 					p_lpn_id                => l_mmtt_cur_mixed_flg.lpn_id,
7480 					p_transfer_lpn_id       => l_mmtt_cur_mixed_flg.transfer_lpn_id,
7481 					p_content_lpn_id        => l_mmtt_cur_mixed_flg.content_lpn_id,
7482 					p_quantity              => l_mmtt_cur_mixed_flg.primary_quantity
7483 						);
7484 	    IF X_RETURN_STATUS =fnd_api.g_ret_sts_error THEN
7485 	       IF (l_debug = 1) THEN
7486    	       INV_TRX_UTIL_PUB.TRACE('Loc cpty calc -Transfer case- failed with status E','LPN_LOC_CLEANUP_MMTT',10);
7487 	       END IF;
7488 	       RAISE fnd_api.g_exc_error;
7489 	    ELSIF X_RETURN_STATUS =fnd_api.g_ret_sts_unexp_error THEN
7490 	       IF (l_debug = 1) THEN
7491    	       INV_TRX_UTIL_PUB.TRACE('Loc cpty calc-Transfer case- failed with status U','LPN_LOC_CLEANUP_MMTT',10);
7492 	       END IF;
7493 	       RAISE fnd_api.g_exc_unexpected_error;
7494 	    END IF;
7495 
7496 	   INV_LOC_WMS_UTILS.LOC_EMPTY_MIXED_FLAG (
7497 			     X_RETURN_STATUS          => l_return_status
7498 			    ,X_MSG_COUNT              => l_MSG_COUNT
7499 			    ,X_MSG_DATA               => l_MSG_DATA
7500 			    ,P_ORGANIZATION_ID        => l_mmtt_cur_mixed_flg.organization_id
7501 			    ,P_INVENTORY_LOCATION_ID  => l_mmtt_cur_mixed_flg.locator_id
7502 			    ,P_INVENTORY_ITEM_ID      => l_mmtt_cur_mixed_flg.inventory_item_id
7503 			    ,P_TRANSACTION_ACTION_ID  => l_mmtt_cur_mixed_flg.transaction_action_id
7504 			    ,P_TRANSFER_ORGANIZATION  => l_mmtt_cur_mixed_flg.transfer_organization
7505 			    ,P_TRANSFER_LOCATION_ID   => l_mmtt_cur_mixed_flg.transfer_to_location
7506 			    ,P_SOURCE                 => 'CONCURRENT'
7507 						 );
7508 	    IF X_RETURN_STATUS =fnd_api.g_ret_sts_error THEN
7509 	      IF (l_debug = 1) THEN
7510    	      INV_TRX_UTIL_PUB.TRACE('LOC_EMPTY_MIXED-Transfer Case failed with status E','LPN_LOC_CLEANUP_MMTT',10);
7511 	      END IF;
7512 	      RAISE fnd_api.g_exc_error;
7513 	    ELSIF X_RETURN_STATUS =fnd_api.g_ret_sts_unexp_error THEN
7514 	     IF (l_debug = 1) THEN
7515    	     INV_TRX_UTIL_PUB.TRACE('LOC_EMPTY_MIXED-Transfer case failed with status U','LPN_LOC_CLEANUP_MMTT',10);
7516 	     END IF;
7517 	     RAISE fnd_api.g_exc_unexpected_error;
7518 	    END IF;
7519 
7520 	ELSE /* For transaction_action_id not in (2,3,28) */
7521 	    INV_LOC_WMS_UTILS.upd_lpn_loc_curr_cpty_nauto(x_return_status    => l_return_status,
7522 				     x_msg_count               => l_msg_count ,
7523 				     x_msg_data                => l_msg_data ,
7524 				     p_organization_id         => l_mmtt_cur_mixed_flg.organization_id,
7525 				     p_inventory_location_id   => l_mmtt_cur_mixed_flg.locator_id,
7526 				     p_inventory_item_id       => l_mmtt_cur_mixed_flg.inventory_item_id,
7527 				     p_primary_uom_flag        => 'Y',
7528 				     p_transaction_uom_code    => NULL,
7529 				     p_transaction_action_id   =>l_mmtt_cur_mixed_flg.transaction_action_id,
7530 				     p_lpn_id                  => l_mmtt_cur_mixed_flg.lpn_id,
7531 				     p_transfer_lpn_id         => l_mmtt_cur_mixed_flg.transfer_lpn_id,
7532 				     p_content_lpn_id          => l_mmtt_cur_mixed_flg.content_lpn_id,
7533 				     p_quantity                => l_mmtt_cur_mixed_flg.primary_quantity
7534 				     );
7535 	     IF X_RETURN_STATUS =fnd_api.g_ret_sts_error THEN
7536 		IF (l_debug = 1) THEN
7537    		INV_TRX_UTIL_PUB.TRACE('Loc cpty calc - failed with status E','LPN_LOC_CLEANUP_MMTT',10);
7538 		END IF;
7539 		RAISE fnd_api.g_exc_error;
7540 	     ELSIF X_RETURN_STATUS =fnd_api.g_ret_sts_unexp_error THEN
7541 		IF (l_debug = 1) THEN
7542    		INV_TRX_UTIL_PUB.TRACE('Loc cpty calc - failed with status U','LPN_LOC_CLEANUP_MMTT',10);
7543 		END IF;
7544 		RAISE fnd_api.g_exc_unexpected_error;
7545 	     END IF;
7546 
7547 	   INV_LOC_WMS_UTILS.LOC_EMPTY_MIXED_FLAG (
7548 			     X_RETURN_STATUS          => l_return_status
7549 			    ,X_MSG_COUNT              => l_MSG_COUNT
7550 			    ,X_MSG_DATA               => l_MSG_DATA
7551 			    ,P_ORGANIZATION_ID        => l_mmtt_cur_mixed_flg.organization_id
7552 			    ,P_INVENTORY_LOCATION_ID  => l_mmtt_cur_mixed_flg.locator_id
7553 			    ,P_INVENTORY_ITEM_ID      => l_mmtt_cur_mixed_flg.inventory_item_id
7554 			    ,P_TRANSACTION_ACTION_ID  => l_mmtt_cur_mixed_flg.transaction_action_id
7555 			    ,P_TRANSFER_ORGANIZATION  => NULL
7556 			    ,P_TRANSFER_LOCATION_ID   => NULL
7557 			    ,P_SOURCE                 => 'CONCURRENT'
7558 						 );
7559 	      IF X_RETURN_STATUS =fnd_api.g_ret_sts_error THEN
7560 		 IF (l_debug = 1) THEN
7561    		 INV_TRX_UTIL_PUB.TRACE('LOC_EMPTY_MIXED failed with status E','LPN_LOC_CLEANUP_MMTT',10);
7562 		 END IF;
7563 		 RAISE fnd_api.g_exc_error;
7564 	      ELSIF X_RETURN_STATUS =fnd_api.g_ret_sts_unexp_error THEN
7565 		 IF (l_debug = 1) THEN
7566    		 INV_TRX_UTIL_PUB.TRACE('LOC_EMPTY_MIXED failed with status U','LPN_LOC_CLEANUP_MMTT',10);
7567 		 END IF;
7568 		 RAISE fnd_api.g_exc_unexpected_error;
7569 	       END IF;
7570 
7571 	  END IF;
7572       END LOOP;
7573      close mmtt_cur_mixed_flg;
7574 
7575     ELSE /* P_MIXED_FLAG IS NULL */
7576     OPEN  mmtt_cur ;
7577      LOOP
7578      FETCH  mmtt_cur into l_mmtt_cur ;
7579      exit when mmtt_cur%NOTFOUND;
7580 	IF (l_debug = 1) THEN
7581    	INV_TRX_UTIL_PUB.TRACE('Fetch from mmtt_cur is success','LPN_LOC_CLEANUP_MMTT',10);
7582 	END IF;
7583 	IF l_mmtt_cur.transaction_action_id in (2,3,28) then
7584 	    if l_mmtt_cur.transfer_organization is null then
7585 		l_mmtt_cur.transfer_organization := l_mmtt_cur.organization_id;
7586 	     end if;
7587 	    INV_LOC_WMS_UTILS.upd_lpn_loc_curr_cpty_nauto(x_return_status    => l_return_status,
7588 					x_msg_count             => l_msg_count ,
7589 					x_msg_data              => l_msg_data ,
7590 					p_organization_id       => l_mmtt_cur.transfer_organization,
7591 					p_inventory_location_id => l_mmtt_cur.transfer_to_location,
7592 					p_inventory_item_id     => l_mmtt_cur.inventory_item_id,
7593 					p_primary_uom_flag      => 'Y',
7594 					p_transaction_uom_code  => NULL,
7595 					p_transaction_action_id =>l_mmtt_cur.transaction_action_id,
7596 					p_lpn_id                => l_mmtt_cur.lpn_id,
7597 					p_transfer_lpn_id       => l_mmtt_cur.transfer_lpn_id,
7598 					p_content_lpn_id        =>  l_mmtt_cur.content_lpn_id,
7599 					p_quantity              => l_mmtt_cur.primary_quantity
7600 						);
7601 	     IF X_RETURN_STATUS =fnd_api.g_ret_sts_error THEN
7602 		IF (l_debug = 1) THEN
7603    		INV_TRX_UTIL_PUB.TRACE('Loc cpty calc -Transfer case- failed with status E','LPN_LOC_CLEANUP_MMTT',10);
7604 		END IF;
7605 		RAISE fnd_api.g_exc_error;
7606 	     ELSIF X_RETURN_STATUS =fnd_api.g_ret_sts_unexp_error THEN
7607 		IF (l_debug = 1) THEN
7608    		INV_TRX_UTIL_PUB.TRACE('Loc cpty calc -Transfer case- failed with status U','LPN_LOC_CLEANUP_MMTT',10);
7609 		END IF;
7610 		RAISE fnd_api.g_exc_unexpected_error;
7611 	     END IF;
7612 
7613 	    INV_LOC_WMS_UTILS.LOC_EMPTY_MIXED_FLAG (
7614 			     X_RETURN_STATUS          => l_return_status
7615 			    ,X_MSG_COUNT              => l_MSG_COUNT
7616 			    ,X_MSG_DATA               => l_MSG_DATA
7617 			    ,P_ORGANIZATION_ID        => l_mmtt_cur.organization_id
7618 			    ,P_INVENTORY_LOCATION_ID  => l_mmtt_cur.locator_id
7619 			    ,P_INVENTORY_ITEM_ID      => l_mmtt_cur.inventory_item_id
7620 			    ,P_TRANSACTION_ACTION_ID  => l_mmtt_cur.transaction_action_id
7621 			    ,P_TRANSFER_ORGANIZATION  => l_mmtt_cur.transfer_organization
7622 			    ,P_TRANSFER_LOCATION_ID   => l_mmtt_cur.transfer_to_location
7623 			    ,P_SOURCE                 => 'CONCURRENT'
7624 						 );
7625 	     IF X_RETURN_STATUS =fnd_api.g_ret_sts_error THEN
7626 	       IF (l_debug = 1) THEN
7627    	       INV_TRX_UTIL_PUB.TRACE('LOC_EMPTY_MIXED-Transfer Case failed with status E','LPN_LOC_CLEANUP_MMTT',10);
7628 	       END IF;
7629 	       RAISE fnd_api.g_exc_error;
7630 	     ELSIF X_RETURN_STATUS =fnd_api.g_ret_sts_unexp_error THEN
7631 	       IF (l_debug = 1) THEN
7632    	       INV_TRX_UTIL_PUB.TRACE('LOC_EMPTY_MIXED-Transfer Case failed with status U','LPN_LOC_CLEANUP_MMTT',10);
7633 	       END IF;
7634 	       RAISE fnd_api.g_exc_unexpected_error;
7635 	     END IF;
7636 
7637 	  ELSE /* For transaction_action_id not in (2,3,28) */
7638 	    INV_LOC_WMS_UTILS.upd_lpn_loc_curr_cpty_nauto(x_return_status    => l_return_status,
7639 				     x_msg_count               => l_msg_count ,
7640 				     x_msg_data                => l_msg_data ,
7641 				     p_organization_id         => l_mmtt_cur.organization_id,
7642 				     p_inventory_location_id   => l_mmtt_cur.locator_id,
7643 				     p_inventory_item_id       => l_mmtt_cur.inventory_item_id,
7644 				     p_primary_uom_flag        => 'Y',
7645 				     p_transaction_uom_code    => NULL,
7646 				     p_transaction_action_id   =>l_mmtt_cur.transaction_action_id,
7647 				     p_lpn_id                  => l_mmtt_cur.lpn_id,
7648 				     p_transfer_lpn_id         => l_mmtt_cur.transfer_lpn_id,
7649 				     p_content_lpn_id          => l_mmtt_cur.content_lpn_id,
7650 				     p_quantity                => l_mmtt_cur.primary_quantity
7651 				     );
7652 	    IF X_RETURN_STATUS =fnd_api.g_ret_sts_error THEN
7653 	      IF (l_debug = 1) THEN
7654    	      INV_TRX_UTIL_PUB.TRACE('Loc cpty calc - failed with status E','LPN_LOC_CLEANUP_MMTT',10);
7655 	      END IF;
7656 	      RAISE fnd_api.g_exc_error;
7657 	    ELSIF X_RETURN_STATUS =fnd_api.g_ret_sts_unexp_error THEN
7658 	      IF (l_debug = 1) THEN
7659    	      INV_TRX_UTIL_PUB.TRACE('Loc cpty calc - failed with status U','LPN_LOC_CLEANUP_MMTT',10);
7660 	      END IF;
7661 	      RAISE fnd_api.g_exc_unexpected_error;
7662 	    END IF;
7663 
7664 	      INV_LOC_WMS_UTILS.LOC_EMPTY_MIXED_FLAG (
7665 			     X_RETURN_STATUS          => l_return_status
7666 			    ,X_MSG_COUNT              => l_MSG_COUNT
7667 			    ,X_MSG_DATA               => l_MSG_DATA
7668 			    ,P_ORGANIZATION_ID        => l_mmtt_cur.organization_id
7669 			    ,P_INVENTORY_LOCATION_ID  => l_mmtt_cur.locator_id
7670 			    ,P_INVENTORY_ITEM_ID      => l_mmtt_cur.inventory_item_id
7671 			    ,P_TRANSACTION_ACTION_ID  => l_mmtt_cur.transaction_action_id
7672 			    ,P_TRANSFER_ORGANIZATION  => NULL
7673 			    ,P_TRANSFER_LOCATION_ID   => NULL
7674 			    ,P_SOURCE                 => 'CONCURRENT'
7675 						 );
7676 	       IF X_RETURN_STATUS =fnd_api.g_ret_sts_error THEN
7677 		 IF (l_debug = 1) THEN
7678    		 INV_TRX_UTIL_PUB.TRACE('LOC_EMPTY_MIXED failed with Return status E','LPN_LOC_CLEANUP_MMTT',10);
7679 		 END IF;
7680 		 RAISE fnd_api.g_exc_error;
7681 	       ELSIF X_RETURN_STATUS =fnd_api.g_ret_sts_unexp_error THEN
7682 		  RAISE fnd_api.g_exc_unexpected_error;
7683 		  IF (l_debug = 1) THEN
7684    		  INV_TRX_UTIL_PUB.TRACE('LOC_EMPTY_MIXED failed with Return status U','LPN_LOC_CLEANUP_MMTT',10);
7685 		  END IF;
7686 	       END IF;
7687 	  END IF;
7688       END LOOP;
7689      CLOSE mmtt_cur;
7690       IF (l_debug = 1) THEN
7691          INV_TRX_UTIL_PUB.TRACE('successful Completion of LPN_LOC_CLEANUP_MMTT ','LPN_LOC_CLEANUP_MMTT',10);
7692       END IF;
7693     END IF;
7694 EXCEPTION
7695 
7696  WHEN fnd_api.g_exc_error THEN
7697     IF mmtt_cur_mixed_flg%ISOPEN then
7698        close mmtt_cur_mixed_flg;
7699     end if;
7700     IF mmtt_cur%isopen then
7701        close mmtt_cur;
7702     end if;
7703     --Fixed bug 2342723
7704     rollback to lpn_loc_mmtt_upd;
7705     --rollback;
7706       x_return_status := fnd_api.g_ret_sts_error;
7707       fnd_msg_pub.count_and_get
7708 	( p_count => x_msg_count,
7709 	  p_data  => x_msg_data
7710 	 );
7711 
7712    WHEN fnd_api.g_exc_unexpected_error THEN
7713     IF mmtt_cur_mixed_flg%ISOPEN then
7714        close mmtt_cur_mixed_flg;
7715     end if;
7716     IF mmtt_cur%isopen then
7717        close mmtt_cur;
7718     end if;
7719       x_return_status := fnd_api.g_ret_sts_unexp_error ;
7720     rollback to lpn_loc_mmtt_upd;
7721     --rollback;
7722        fnd_msg_pub.count_and_get
7723 	( p_count => x_msg_count,
7724 	  p_data  => x_msg_data
7725 	  );
7726 
7727    WHEN NO_DATA_FOUND THEN
7728     IF mmtt_cur_mixed_flg%ISOPEN then
7729        close mmtt_cur_mixed_flg;
7730     end if;
7731     IF mmtt_cur%isopen then
7732        close mmtt_cur;
7733     end if;
7734      x_return_status := fnd_api.g_ret_sts_error;
7735     rollback to lpn_loc_mmtt_upd;
7736     --rollback;
7737 
7738    WHEN OTHERS THEN
7739     IF mmtt_cur_mixed_flg%ISOPEN then
7740        close mmtt_cur_mixed_flg;
7741     end if;
7742     IF mmtt_cur%isopen then
7743        close mmtt_cur;
7744      end if;
7745     x_return_status := fnd_api.g_ret_sts_unexp_error;
7746     rollback to lpn_loc_mmtt_upd;
7747     --rollback;
7748      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
7749 	THEN
7750 	 fnd_msg_pub.add_exc_msg
7751 	   (  'INV_LOC_WMS_UTILS',
7752 	      'lpn_loc_cleanup_mmtt'
7753 	      );
7754      END IF;
7755      fnd_msg_pub.count_and_get
7756 	( p_count => x_msg_count,
7757 	  p_data  => x_msg_data
7758 	  );
7759 END lpn_loc_cleanup_mmtt;
7760 PROCEDURE LPN_LOC_CURRENT_CAPACITY (
7761 				x_return_status   OUT NOCOPY varchar2 --return status
7762 			       ,x_msg_count       OUT NOCOPY NUMBER --number of messages in message queue
7763 			       ,x_msg_data        OUT NOCOPY varchar2 --message text when x_msg_count>0
7764 			       ,p_organization_id IN NUMBER -- identier for the organization
7765 			       ,p_mixed_flag      IN varchar2
7766 						    )
7767 IS
7768 CURSOR current_cpty  is
7769   SELECT WLPN.locator_id,
7770   nvl(sum(DECODE(MIL.LOCATION_WEIGHT_UOM_CODE,WLPN.GROSS_WEIGHT_UOM_CODE,
7771 						     WLPN.gross_weight,
7772 					     GREATEST(INV_CONVERT.INV_UM_CONVERT(
7773 							     null
7774 							    ,null
7775 							    ,WLPN.GROSS_WEIGHT
7776 							    ,WLPN.GROSS_WEIGHT_UOM_CODE
7777 							    ,MIL.LOCATION_WEIGHT_UOM_CODE
7778 							    ,null
7779 							   ,null),0))),0) gross_weight,
7780 
7781 	 nvl(sum(DECODE(MIL.VOLUME_UOM_CODE,WLPN.CONTENT_VOLUME_UOM_CODE,
7782 					       WLPN.content_volume,
7783 					      GREATEST(INV_CONVERT.INV_UM_CONVERT(
7784 							     null
7785 							    ,null
7786 							    ,WLPN.CONTENT_VOLUME
7787 							    ,WLPN.CONTENT_VOLUME_UOM_CODE
7788 							    ,MIL.VOLUME_UOM_CODE
7789 							    ,null
7790 							   ,null),0))),0) content_volume
7791   FROM wms_license_plate_numbers WLPN,
7792        MTL_ITEM_LOCATIONS MIL
7793   WHERE MIL.INVENTORY_LOCATION_ID = WLPN.LOCATOR_ID
7794     AND WLPN.organization_id =p_organization_id
7795     AND WLPN.lpn_context =1
7796     AND WLPN.parent_lpn_id is null
7797     AND WLPN.locator_id  >0
7798   GROUP by  WLPN.locator_id ;
7799 
7800  CURSOR curr_cpty_mixed_flg  is
7801   SELECT WLPN.locator_id,
7802 	 nvl(sum(DECODE(MIL.LOCATION_WEIGHT_UOM_CODE,WLPN.GROSS_WEIGHT_UOM_CODE,
7803 						     WLPN.gross_weight,
7804 					     GREATEST(INV_CONVERT.INV_UM_CONVERT(
7805 							     null
7806 							    ,null
7807 							    ,WLPN.GROSS_WEIGHT
7808 							    ,WLPN.GROSS_WEIGHT_UOM_CODE
7809 							    ,MIL.LOCATION_WEIGHT_UOM_CODE
7810 							    ,null
7811 							   ,null),0))),0) gross_weight,
7812 
7813 	 nvl(sum(DECODE(MIL.VOLUME_UOM_CODE,WLPN.CONTENT_VOLUME_UOM_CODE,
7814 					       WLPN.content_volume,
7815 					      GREATEST(INV_CONVERT.INV_UM_CONVERT(
7816 							     null
7817 							    ,null
7818 							    ,WLPN.CONTENT_VOLUME
7819 							    ,WLPN.CONTENT_VOLUME_UOM_CODE
7820 							    ,MIL.VOLUME_UOM_CODE
7821 							    ,null
7822 							   ,null),0))),0) content_volume
7823   FROM wms_license_plate_numbers WLPN,
7824        MTL_ITEM_LOCATIONS MIL
7825   WHERE WLPN.LOCATOR_ID =  MIL.INVENTORY_LOCATION_ID
7826     AND WLPN.organization_id =p_organization_id
7827     AND WLPN.lpn_context =1
7828     AND WLPN.parent_lpn_id is null
7829     AND WLPN.locator_id  >0
7830     AND MIL.MIXED_ITEMS_FLAG ='Y'
7831   GROUP by  WLPN.locator_id ;
7832 
7833  l_curr_cpty                   current_cpty%ROWTYPE;
7834  l_curr_cpty_mixed_flg         curr_cpty_mixed_flg%ROWTYPE ;
7835  l_physical_locator_id         NUMBER;
7836  l_locator_id                  NUMBER;
7837  l_inventory_location_id       NUMBER;
7838  l_return_status               VARCHAR2(1);
7839  l_msg_data                    VARCHAR2(1000);
7840  l_msg_count                   NUMBER;
7841  l_units                       NUMBER ;
7842 
7843     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
7844 BEGIN
7845     IF (l_debug = 1) THEN
7846        INV_TRX_UTIL_PUB.TRACE('In LPN_LOC_CURRENT_CAPACITY  Procedure ','LPN_LOC_CURRENT_CAPACITY',9);
7847     END IF;
7848    x_return_status := fnd_api.g_ret_sts_success;
7849    --Fixed bug 2342723, romoved the savepoint
7850    -- Bug 3511690 savepoint retained
7851    savepoint lpn_loc_cpty_upd;
7852    IF p_mixed_flag IS NOT NULL THEN
7853     OPEN curr_cpty_mixed_flg;
7854      LOOP
7855        FETCH curr_cpty_mixed_flg INTO l_curr_cpty_mixed_flg;
7856        EXIT WHEN curr_cpty_mixed_flg %NOTFOUND;
7857        /* If the locator has a physical_location_id
7858 	  then use the physical_location_id for further
7859 	  processing.Else we have to use the inventory_location_id
7860 	  for further processing
7861 	*/
7862        IF (l_debug = 1) THEN
7863           INV_TRX_UTIL_PUB.TRACE('Curr_cpty_mixed_flag is successful ','LPN_LOC_CURRENT_CAPACITY',10);
7864        END IF;
7865 	l_inventory_location_id :=null;
7866 	l_physical_locator_id :=null;
7867 	l_locator_id :=null;
7868 
7869 	SELECT physical_location_id ,
7870 	       inventory_location_id
7871 	INTO l_physical_locator_id,
7872 	     l_locator_id
7873 	FROM mtl_item_locations
7874 	WHERE  inventory_location_id =l_curr_cpty.locator_id
7875 	    and organization_id = p_organization_id;
7876 
7877 	IF l_physical_locator_id is null THEN
7878 	  l_inventory_location_id := l_locator_id;
7879 	ELSE
7880 	  l_inventory_location_id := l_physical_locator_id;
7881 	END IF;
7882 	/* Update current weight and current cubic area of the locator with the
7883 	    LPN's gross weight and content volume
7884 	*/
7885        IF (l_debug = 1) THEN
7886           INV_TRX_UTIL_PUB.TRACE('The value of locator _id is '||to_char(l_inventory_location_id), 'LPN_LOC_CURRENT_CAPACITY',10);
7887           INV_TRX_UTIL_PUB.TRACE('The value of org_id is'||to_char(p_organization_id),'LPN_LOC_CURRENT_CAPACITY',10);
7888           INV_TRX_UTIL_PUB.TRACE('The value of gross_weight is '||to_char(l_curr_cpty.gross_weight), 'LPN_LOC_CURRENT_CAPACITY',10);
7889           INV_TRX_UTIL_PUB.TRACE('The value of content_volume is '||to_char(l_curr_cpty.content_volume), 'LPN_LOC_CURRENT_CAPACITY',10);
7890        END IF;
7891        begin
7892         SELECT sum(abs(primary_transaction_quantity))
7893         into l_units
7894         FROM MTL_ONHAND_QUANTITIES_DETAIL
7895         WHERE locator_id = l_inventory_location_id
7896           AND containerized_flag = 1
7897           AND locator_id >0
7898           AND organization_id =p_organization_id;
7899        exception
7900          when no_data_found then
7901          null;
7902        end;
7903 
7904 	UPDATE mtl_item_locations
7905 	set current_weight=nvl(current_weight,0)+l_curr_cpty.gross_weight,
7906 	    available_weight = max_weight-(nvl(suggested_weight,0) + nvl(current_weight,0)),
7907 	   current_cubic_area = nvl(current_cubic_area,0) + l_curr_cpty.content_volume,
7908 	   available_cubic_area = max_cubic_area -(nvl(suggested_cubic_area,0)+nvl(current_cubic_area,0)),
7909            LOCATION_CURRENT_UNITS = nvl(LOCATION_CURRENT_UNITS,0) + l_units,
7910            LOCATION_AVAILABLE_UNITS = greatest(nvl(LOCATION_MAXIMUM_UNITS,0)-(nvl(LOCATION_SUGGESTED_UNITS,0)+ nvl(LOCATION_CURRENT_UNITS,0)),0)
7911 	where
7912 	     inventory_location_id =l_inventory_location_id
7913 	  and organization_id = p_organization_id;
7914      end loop;
7915      close curr_cpty_mixed_flg;
7916 
7917    ELSE
7918     open current_cpty;
7919      loop
7920       fetch current_cpty into  l_curr_cpty;
7921        exit when current_cpty%notfound;
7922        IF (l_debug = 1) THEN
7923           INV_TRX_UTIL_PUB.TRACE('Fetch from current_cpty is success','LPN_LOC_CURRENT_CAPACITY',10);
7924        END IF;
7925 
7926        /* If the locator has a physical_location_id
7927 	  then use the physical_location_id for further
7928 	  processing.Else we have to use the inventory_location_id
7929 	  for further processing
7930 	*/
7931 	l_inventory_location_id :=null;
7932 	l_physical_locator_id :=null;
7933 	l_locator_id :=null;
7934 
7935 	SELECT physical_location_id ,
7936 	       inventory_location_id
7937 	INTO l_physical_locator_id,
7938 	     l_locator_id
7939 	FROM mtl_item_locations
7940 	WHERE  inventory_location_id =l_curr_cpty.locator_id
7941 	    and organization_id = p_organization_id;
7942 
7943 	IF l_physical_locator_id is null THEN
7944 	  l_inventory_location_id := l_locator_id;
7945 	ELSE
7946 	  l_inventory_location_id := l_physical_locator_id;
7947 	END IF;
7948 	/* Update current weight and current cubic area of the locator with the
7949 	    LPN gross weight and content volume
7950 	*/
7951        IF (l_debug = 1) THEN
7952           INV_TRX_UTIL_PUB.TRACE('The value of locator _id is '||to_char(l_inventory_location_id), 'LPN_LOC_CURRENT_CAPACITY',10);
7953           INV_TRX_UTIL_PUB.TRACE('The value of org_id is'||to_char(p_organization_id),'LPN_LOC_CURRENT_CAPACITY',10);
7954           INV_TRX_UTIL_PUB.TRACE('The value of gross_weight is '||to_char(l_curr_cpty.gross_weight), 'LPN_LOC_CURRENT_CAPACITY',10);
7955           INV_TRX_UTIL_PUB.TRACE('The value of content_volume is '||to_char(l_curr_cpty.content_volume), 'LPN_LOC_CURRENT_CAPACITY',10);
7956        END IF;
7957        begin
7958         SELECT sum(abs(primary_transaction_quantity))
7959         into l_units
7960         FROM MTL_ONHAND_QUANTITIES_DETAIL
7961         WHERE locator_id = l_inventory_location_id
7962           AND containerized_flag = 1
7963           AND locator_id >0
7964           AND organization_id =p_organization_id;
7965        exception
7966           when no_data_found then
7967           null;
7968         end;
7969 
7970 	UPDATE mtl_item_locations
7971 	set current_weight=nvl(current_weight,0)+l_curr_cpty.gross_weight,
7972 	    available_weight = max_weight-(nvl(suggested_weight,0) + nvl(current_weight,0)),
7973 	   current_cubic_area = nvl(current_cubic_area,0) + l_curr_cpty.content_volume,
7974 	   available_cubic_area = max_cubic_area -(nvl(suggested_cubic_area,0)+nvl(current_cubic_area,0)),
7975            LOCATION_CURRENT_UNITS = nvl(LOCATION_CURRENT_UNITS,0) + nvl(l_units,0),
7976            LOCATION_AVAILABLE_UNITS = greatest(nvl(LOCATION_MAXIMUM_UNITS,0)-(nvl(LOCATION_SUGGESTED_UNITS,0)+ nvl(LOCATION_CURRENT_UNITS,0)),0)
7977 	where
7978 	     inventory_location_id =l_inventory_location_id
7979 	  and organization_id = p_organization_id;
7980      end loop;
7981    close current_cpty;
7982    END IF;
7983 EXCEPTION
7984  WHEN fnd_api.g_exc_error THEN
7985     IF current_cpty%ISOPEN then
7986        close current_cpty;
7987     end if;
7988     IF curr_cpty_mixed_flg%isopen then
7989        close curr_cpty_mixed_flg;
7990     end if;
7991     -- Fixed bug 2342723, do not rollback to savepoint
7992     rollback to lpn_loc_cpty_upd;
7993     --rollback;
7994       x_return_status := fnd_api.g_ret_sts_error;
7995       fnd_msg_pub.count_and_get
7996 	( p_count => x_msg_count,
7997 	  p_data  => x_msg_data
7998 	 );
7999 
8000    WHEN fnd_api.g_exc_unexpected_error THEN
8001     IF current_cpty%ISOPEN then
8002        close current_cpty;
8003     end if;
8004     IF curr_cpty_mixed_flg%isopen then
8005        close curr_cpty_mixed_flg;
8006     end if;
8007       x_return_status := fnd_api.g_ret_sts_unexp_error ;
8008     rollback to lpn_loc_cpty_upd;
8009     --rollback;
8010        fnd_msg_pub.count_and_get
8011 	( p_count => x_msg_count,
8012 	  p_data  => x_msg_data
8013 	  );
8014 
8015    WHEN NO_DATA_FOUND THEN
8016     IF current_cpty%ISOPEN then
8017        close current_cpty;
8018     end if;
8019     IF curr_cpty_mixed_flg%isopen then
8020        close curr_cpty_mixed_flg;
8021     end if;
8022      x_return_status := fnd_api.g_ret_sts_error;
8023     rollback to lpn_loc_cpty_upd;
8024     --rollback;
8025 
8026    WHEN OTHERS THEN
8027     IF current_cpty%ISOPEN then
8028        close current_cpty;
8029     end if;
8030     IF curr_cpty_mixed_flg%isopen then
8031        close curr_cpty_mixed_flg;
8032      end if;
8033     x_return_status := fnd_api.g_ret_sts_unexp_error;
8034      rollback to lpn_loc_cpty_upd;
8035     --rollback;
8036      IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error)
8037 	THEN
8038 	 fnd_msg_pub.add_exc_msg
8039 	   (  'INV_LOC_WMS_UTILS',
8040 	      'LPN_LOC_CURRENT_CAPACITY'
8041 	      );
8042      END IF;
8043      fnd_msg_pub.count_and_get
8044 	( p_count => x_msg_count,
8045 	  p_data  => x_msg_data
8046 	  );
8047 END LPN_LOC_CURRENT_CAPACITY;
8048 
8049 procedure upd_empty_mixed_flag_rcv_loc ( x_return_status      OUT NOCOPY VARCHAR2
8050 					 ,x_msg_count         OUT NOCOPY NUMBER
8051 					 ,x_msg_data          OUT NOCOPY VARCHAR2
8052 					 ,p_subinventory      IN VARCHAR2
8053 					 ,p_locator_id        IN NUMBER
8054 					 ,p_org_id            IN NUMBER
8055 					 )
8056   is
8057      l_chk_flag number;
8058      l_empty_flag VARCHAR2(1) := 'Y';
8059      l_mixed_flag VARCHAR2(1) := 'N';
8060      l_mixed_num NUMBER := 0;
8061 
8062      l_physical_locator_id NUMBER := NULL;
8063      l_locator_id NUMBER;
8064      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
8065 BEGIN
8066    x_return_status := FND_API.G_RET_STS_SUCCESS;
8067 
8068    l_locator_id := p_locator_id;
8069 
8070    IF (l_debug = 1) THEN
8071       mdebug('UPD_EMPTY_MIXED_FLAG_RCV_LOC: Subinv : '||p_subinventory);
8072       mdebug('UPD_EMPTY_MIXED_FLAG_RCV_LOC: Loc ID : '||p_locator_id);
8073       mdebug('UPD_EMPTY_MIXED_FLAG_RCV_LOC: Org ID : '||p_org_id);
8074    END IF;
8075 
8076    -- Get the physical locator id for PJM.
8077    SELECT physical_location_id,
8078      inventory_location_id
8079      INTO l_physical_locator_id,
8080      l_locator_id
8081      FROM mtl_item_locations
8082      WHERE  inventory_location_id = p_locator_id
8083      and organization_id = p_org_id;
8084 
8085    IF (l_debug = 1) THEN
8086       mdebug('UPD_EMPTY_MIXED_FLAG_RCV_LOC: Physical Loc ID : '||l_physical_locator_id);
8087    END IF;
8088 
8089    IF l_physical_locator_id IS NOT NULL THEN
8090       l_locator_id := l_physical_locator_id;
8091    END IF;
8092 
8093    BEGIN
8094       SELECT 1
8095 	INTO l_chk_flag
8096 	FROM dual
8097 	WHERE EXISTS (
8098 		      SELECT 1
8099 		      FROM  rcv_supply rs
8100 		      WHERE rs.to_locator_id    = p_locator_id
8101 		      AND rs.to_organization_id = p_org_id
8102 		      AND rs.to_subinventory    = p_subinventory
8103 		      AND rs.quantity           > 0
8104 		      );
8105 
8106       l_empty_flag := 'N';
8107       l_mixed_flag := 'N';
8108 
8109       IF (l_debug = 1) THEN
8110 	 mdebug('UPD_EMPTY_MIXED_FLAG_RCV_LOC: Locator is not empty');
8111       END IF;
8112 
8113       SELECT COUNT(DISTINCT item_id)
8114 	INTO l_mixed_num
8115 	FROM rcv_supply rs
8116 	WHERE rs.to_locator_id    = p_locator_id
8117 	AND rs.to_organization_id = p_org_id
8118 	AND rs.to_subinventory    = p_subinventory
8119 	AND rs.quantity           > 0;
8120 
8121       IF (l_mixed_num > 1) THEN
8122 	 l_mixed_flag := 'Y';
8123 
8124 	 IF (l_debug = 1) THEN
8125 	    mdebug('UPD_EMPTY_MIXED_FLAG_RCV_LOC: Locator had Mixed Items');
8126 	 END IF;
8127       END IF;
8128    EXCEPTION
8129       WHEN NO_DATA_FOUND THEN
8130 	   IF (l_debug = 1) THEN
8131 	      mdebug('UPD_EMPTY_MIXED_FLAG_RCV_LOC: Locator is empty');
8132 	   END IF;
8133 	   l_EMPTY_FLAG := 'Y';
8134 	   l_mixed_flag := 'N';
8135    END;
8136 
8137    --Update the empty flag/mixed flag
8138    UPDATE mtl_item_locations mil
8139      SET empty_flag     = NVL(l_empty_flag,mil.empty_flag)
8140      , mixed_items_flag = NVL(l_mixed_flag,mil.mixed_items_flag)
8141      , last_update_date     = sysdate                                                       /* Added for Bug 6363028 */
8142      WHERE inventory_location_id = l_locator_id
8143      AND organization_id         = p_org_id;
8144 
8145 EXCEPTION
8146    WHEN OTHERS THEN
8147       x_return_status := fnd_api.g_ret_sts_unexp_error;
8148 
8149       IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
8150 	 fnd_msg_pub.add_exc_msg
8151 	   (  'inv_loc_wms_utils'
8152 	      , 'upd_empty_mixed_flag_rcv_loc'
8153 	      );
8154       END IF;
8155 
8156       fnd_msg_pub.count_and_get
8157 	( p_count => x_msg_count,
8158 	  p_data  => x_msg_data
8159 	  );
8160 END upd_empty_mixed_flag_rcv_loc;
8161 
8162 --Added following procedure for bug #6976034
8163 procedure get_locator_id ( x_locator_id OUT NOCOPY NUMBER, p_locator VARCHAR2 ,p_org_id NUMBER ) IS
8164 
8165 l_operation VARCHAR2(100);
8166 l_locator VARCHAR2(32000)   := p_locator;
8167 l_org_id  NUMBER            := p_org_id ;
8168 l_val     BOOLEAN ;
8169 
8170 BEGIN
8171 
8172 fnd_flex_key_api.set_session_mode('seed_data');
8173 
8174 l_operation := 'FIND_COMBINATION';
8175 
8176 l_val := FND_FLEX_KEYVAL.Validate_Segs(
8177                   OPERATION        => l_operation,
8178                   APPL_SHORT_NAME  => 'INV',
8179                   KEY_FLEX_CODE    => 'MTLL',
8180                   STRUCTURE_NUMBER => 101,
8181                   CONCAT_SEGMENTS  => l_locator,
8182                   VALUES_OR_IDS    => 'I',
8183                   DATA_SET         => l_org_id ) ;
8184 
8185 if l_val then
8186    x_locator_id := fnd_flex_keyval.combination_id;
8187 else
8188    x_locator_id := NULL;
8189 end if;
8190 
8191 EXCEPTION
8192 WHEN OTHERS THEN
8193    x_locator_id := NULL;
8194 END get_locator_id;
8195 
8196 END inv_loc_wms_utils;