DBA Data[Home] [Help]

PACKAGE BODY: APPS.INV_RCV_INTEGRATION_PVT

Source


1 PACKAGE BODY inv_rcv_integration_pvt AS
2 /* $Header: INVRCVVB.pls 120.92.12010000.5 2008/09/29 14:19:36 vijrajen ship $*/
3 
4 --  Global constant holding the package name
5 g_pkg_name CONSTANT VARCHAR2(30) := 'INV_RCV_INTEGRATION_PVT';
6 
7 -- Define the LPN CONTEXTS
8 -- Resides in Inventory
9 G_LPN_CONTEXT_INV CONSTANT NUMBER := 1;
10 -- Resides in WIP
11 G_LPN_CONTEXT_WIP CONSTANT NUMBER := 2;
12 -- Resides in Receiving
13 G_LPN_CONTEXT_RCV CONSTANT NUMBER := 3;
14 -- Issued out of Stores
15 G_LPN_CONTEXT_STORES CONSTANT NUMBER := 4;
16 -- Pre-generated
17 G_LPN_CONTEXT_PREGENERATED CONSTANT NUMBER := 5;
18 -- Resides in intransit
19 G_LPN_CONTEXT_INTRANSIT CONSTANT NUMBER := 6;
20 -- Resides at vendor site
21 G_LPN_CONTEXT_VENDOR  CONSTANT NUMBER := 7;
22 -- Packing context, used as a temporary context value
23 -- when the user wants to reassociate the LPN with a
24 -- different license plate number and/or container item ID
25 G_LPN_CONTEXT_PACKING CONSTANT NUMBER := 8;
26 -- Loaded for shipment
27 G_LPN_LOADED_FOR_SHIPMENT CONSTANT NUMBER := 9;
28 -- Prepack of WIP
29 G_LPN_PREPACK_FOR_WIP CONSTANT NUMBER := 10;
30 -- LPN Picked
31 G_LPN_CONTEXT_PICKED CONSTANT NUMBER := 11;
32 
33 
34 G_RET_STS_ERROR	       CONSTANT	VARCHAR2(1) := fnd_api.g_ret_sts_error;
35 G_RET_STS_UNEXP_ERROR  CONSTANT	VARCHAR2(1) := fnd_api.g_ret_sts_unexp_error;
36 G_RET_STS_SUCCESS      CONSTANT	VARCHAR2(1) := FND_API.g_ret_sts_success;
37 G_TRUE		       CONSTANT	VARCHAR2(1) := fnd_api.g_true;
38 G_FALSE		       CONSTANT	VARCHAR2(1) := fnd_api.g_false;
39 
40 G_RTV CONSTANT VARCHAR2(25) := 'RETURN TO VENDOR';
41 G_RTC CONSTANT VARCHAR2(25) := 'RETURN TO CUSTOMER';
42 G_RTR CONSTANT VARCHAR2(25) := 'RETURN TO RECEIVING';
43 
44 g_lpn_group_id NUMBER;
45 g_epc_group_id NUMBER;
46 
47 PROCEDURE print_debug(p_err_msg VARCHAR2, p_level NUMBER) IS
48    l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
49    l_pkg_name VARCHAR2(100) := g_pkg_name||'($Revision: 120.92.12010000.5 $)';
50 BEGIN
51    IF (l_debug = 1) THEN
52       inv_mobile_helper_functions.tracelog(p_err_msg => p_err_msg, p_module => l_pkg_name, p_level => p_level);
53    END IF;
54 END print_debug;
55 
56 PROCEDURE print_stacked_messages IS
57    l_error_message VARCHAR2(4000) := '';
58 BEGIN
59    inv_mobile_helper_functions.get_stacked_messages(l_error_message);
60 
61    print_debug('STACKED ERROR MESSAGES : '||l_error_message,1);
62 END print_stacked_messages;
63 
64 PROCEDURE get_epc_info(p_mode          IN NUMBER
65 		       ,p_lpn          IN VARCHAR2 DEFAULT NULL
66 		       ,p_src_grp_id   IN NUMBER   DEFAULT NULL
67 		       ,p_ser_if_rowid IN ROWID    DEFAULT NULL
68 		       ,x_epc_column   OUT nocopy VARCHAR2
69 		       ,x_epc_value    OUT nocopy VARCHAR2
70 		       ) IS
71    l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
72    l_epc_column	    VARCHAR2(30);
73    l_epc_value      VARCHAR2(100);
74    l_epc_sql        VARCHAR2(1000);
75    l_epc_cursor         NUMBER;
76    l_last_error_pos NUMBER;
77    l_temp_str       VARCHAR2(100);
78    l_return         NUMBER;
79    l_progress       VARCHAR2(10);
80 BEGIN
81 
82    IF (p_mode = 1) THEN --LPN
83       l_epc_column := fnd_profile.value('WMS_EPC_LASN_COL');
84     ELSIF (p_mode = 2) THEN   -- Serial
85       l_epc_column := fnd_profile.value('WMS_EPC_SASN_COL');
86     ELSE
87       IF l_debug = 1 THEN
88 	 print_debug('Unsupported mode',4);
89       END IF;
90       RAISE fnd_api.g_exc_error;
91    END IF;
92 
93    x_epc_column := l_epc_column;
94 
95    IF (l_epc_column IS NULL) THEN
96       x_epc_column := NULL;
97       x_epc_value  := NULL;
98     ELSE
99       IF (p_mode = 1) THEN
100 	 l_epc_sql := 'SELECT ' || l_epc_column;
101 	 l_epc_sql := l_epc_sql || ' FROM wms_lpn_interface';
102 	 l_epc_sql := l_epc_sql || ' WHERE license_plate_number = :lpn';
103 	 l_epc_sql := l_epc_sql || ' AND   source_group_id = :src_grp_id';
104 
105 	 IF (l_debug = 1) THEN
106 	    print_debug('l_epc_sql: '||l_epc_sql,4);
107 	 END IF;
108 
109 	 l_epc_cursor := dbms_sql.open_cursor;
110          BEGIN
111 	    dbms_sql.parse(l_epc_cursor,l_epc_sql,dbms_sql.v7);
112 	 EXCEPTION
113 	    WHEN OTHERS THEN
114 	       l_last_error_pos := dbms_sql.last_error_position();
115 	       l_temp_str := Substr(l_epc_sql, l_last_error_pos-5, 50);
116 	       IF l_debug = 1 THEN
117 		  print_debug('Error in parse sql statement, at '||l_temp_str,4);
118 	       END IF;
119 	       RAISE fnd_api.g_exc_unexpected_error;
120 	 END;
121 
122 	 dbms_sql.bind_variable(l_epc_cursor,':lpn', p_lpn);
123 	 dbms_sql.bind_variable(l_epc_cursor,':src_grp_id', p_src_grp_id);
124 	 dbms_sql.define_column(l_epc_cursor, 1, l_epc_value, 30);
125 	 l_return := dbms_sql.execute(l_epc_cursor);
126 
127 	 IF dbms_sql.fetch_rows(l_epc_cursor) <> 0 THEN
128 	    dbms_sql.column_value(l_epc_cursor, 1, l_epc_value);
129 	    IF (l_debug = 1) THEN
130 	       print_debug('l_epc_value: '||l_epc_value,4);
131 	    END IF;
132 	    x_epc_value := l_epc_value;
133 	  ELSE
134 	    x_epc_value := NULL;
135 	 END IF;
136 
137 	 dbms_sql.close_cursor(l_epc_cursor);
138        ELSE --Serial
139 	 l_epc_sql := 'SELECT ' || l_epc_column;
140 	 l_epc_sql := l_epc_sql || ' FROM mtl_serial_numbers_temp';
141 	 l_epc_sql := l_epc_sql || ' WHERE rowid = :row_id';
142 
143 	 IF (l_debug = 1) THEN
144 	    print_debug('l_epc_sql: '||l_epc_sql,4);
145 	 END IF;
146 
147 	 l_epc_cursor := dbms_sql.open_cursor;
148          BEGIN
149 	    dbms_sql.parse(l_epc_cursor,l_epc_sql,dbms_sql.v7);
150 	 EXCEPTION
151 	    WHEN OTHERS THEN
152 	       l_last_error_pos := dbms_sql.last_error_position();
153 	       l_temp_str := Substr(l_epc_sql, l_last_error_pos-10, 50);
154 	       IF l_debug = 1 THEN
155 		  print_debug('Error in parse sql statement, at '||l_temp_str,4);
156 		  print_debug('ERROR CODE = '||SQLCODE||' ERROR MESSAGE = '||Sqlerrm,4);
157 	       END IF;
158 	       RAISE fnd_api.g_exc_unexpected_error;
159 	 END;
160 
161 	 dbms_sql.bind_variable(l_epc_cursor,':row_id', p_ser_if_rowid);
162 	 dbms_sql.define_column(l_epc_cursor, 1, l_epc_value, 30);
163 
164 	 l_return := dbms_sql.execute(l_epc_cursor);
165 
166 	 IF dbms_sql.fetch_rows(l_epc_cursor) <> 0 THEN
167 	    dbms_sql.column_value(l_epc_cursor, 1, l_epc_value);
168 	    IF (l_debug = 1) THEN
169 	       print_debug('l_epc_value: '||l_epc_value,4);
170 	    END IF;
171 	    x_epc_value := l_epc_value;
172 	  ELSE
173 	    x_epc_value := NULL;
174 	 END IF;
175 	 dbms_sql.close_cursor(l_epc_cursor);
176       END IF;
177    END IF;
178 
179 EXCEPTION
180    WHEN OTHERS THEN
181       IF l_debug = 1 THEN
182 	 print_debug('Error in get_epc_info at progress:'||l_progress,4);
183 	 print_debug('ERROR CODE = '||SQLCODE||' ERROR MESSAGE = '||Sqlerrm,4);
184       END IF;
185       dbms_sql.close_cursor(l_epc_cursor);
186 END get_epc_info;
187 
188 
189 /*****bug4187663, comment out the call to serial uniqueness api
190 --Following function calls the serial uniqueness api with txn_source and
191 --txn_action. It will return 0 on success and 1 on error.
192 
193 FUNCTION is_sernum_unique(p_org_id IN NUMBER,
194 			  p_item_id IN NUMBER,
195 			  p_serial IN VARCHAR2,
196 			  p_txn_src_type IN NUMBER,
197 			  p_txn_action IN NUMBER,
198 			  x_proc_msg OUT NOCOPY VARCHAR2)
199   RETURN NUMBER AS
200 LANGUAGE JAVA
201   NAME 'oracle.apps.inv.transaction.server.TrxProcessor.isSerialNumberUnique(java.lang.Long,
202   java.lang.Long,
203   java.lang.String,
204   java.lang.Integer,
205   java.lang.Integer,
206   java.lang.String[]) return java.lang.Integer';
207 
208 ****end of bug4187663*****/
209 
210 PROCEDURE check_lpn_in_wlpni(p_license_plate_number IN VARCHAR2,
211                              p_lpn_id               IN NUMBER,
212                              p_lpn_group_id         IN NUMBER,
213                              x_exists OUT NOCOPY NUMBER )
214   is
215 BEGIN
216    x_exists := 0;
217    select 1 into x_exists
218      from wms_lpn_interface
219      where ( ( license_plate_number = p_license_plate_number ) or ( lpn_id = p_lpn_id ))
220      and source_group_id = p_lpn_group_id
221      and rownum = 1;
222 EXCEPTION
223    WHEN OTHERS THEN
224       x_exists := 0;
225 END check_lpn_in_wlpni;
226 
227 function get_primary_qty(
228 			 p_organization_id       IN      NUMBER,
229 			 p_inventory_item_id     IN      NUMBER,
230 			 p_uom                   IN      VARCHAR2,
231 			 p_quantity              IN      NUMBER) return number IS
232 
233 			    -- local variables
234 			    l_primary_uom         VARCHAR2(10);
235 
236 BEGIN
237    -- if input qty is null, assume 0, in which case we return 0 as converted
238    -- qty also
239    if ( ( p_quantity IS NULL ) OR (p_quantity = 0) ) then
240       return 0;
241    end if;
242 
243    l_primary_uom := inv_rcv_cache.get_primary_uom_code(p_organization_id,p_inventory_item_id);
244 
245    return( inv_rcv_cache.convert_qty(p_inventory_item_id => p_inventory_item_id
246 		       ,p_from_qty         => p_quantity
247 		       ,p_from_uom_code    => p_uom
248 		       ,p_to_uom_code      => l_primary_uom
249 		       ,p_precision        => 5--BUG 4939647
250 		       ) );
251 
252 
253 Exception
254    When Others then
255       return 0;
256 end get_primary_qty ;
257 
258 FUNCTION validate_pjm_commingle(p_org_id IN NUMBER,
259 				   p_lpn_id IN NUMBER,
260 				   p_project_id IN NUMBER,
261 				   p_task_id IN NUMBER)
262   RETURN BOOLEAN
263   IS
264      l_dummy VARCHAR2(1);
265 
266 BEGIN
267    SELECT '1'
268      INTO l_dummy
269      FROM dual
270      WHERE exists (SELECT '1'
271 		   FROM mtl_txn_request_lines mtrl
272 		   WHERE mtrl.lpn_id = p_lpn_id
273 		   AND mtrl.organization_id = p_org_id
274 		   AND (Nvl(mtrl.project_id,-1) <> Nvl(p_project_id,-1)
275 			OR Nvl(mtrl.task_id,-1) <> Nvl(p_task_id,-1))
276 		   AND line_status <> inv_globals.G_TO_STATUS_CLOSED
277 		   AND (mtrl.quantity - Nvl(mtrl.quantity_delivered, 0)) > 0);
278 
279    RETURN TRUE;
280 
281 EXCEPTION
282    WHEN no_data_found THEN
283       RETURN FALSE;
284    WHEN OTHERS THEN
285       RETURN TRUE;
286 
287 END validate_pjm_commingle;
288 
289 
290 FUNCTION validate_mixed_expense_items(p_org_id IN NUMBER,
291 				      p_lpn_id IN NUMBER,
292 				      p_transactions_enabled_flag IN VARCHAR2)
293   RETURN BOOLEAN
294   IS
295      l_dummy VARCHAR2(1);
296 BEGIN
297    SELECT '1'
298      INTO l_dummy
299      FROM dual
300      WHERE exists (SELECT '1'
301 		   FROM wms_lpn_contents wlc
302 		   , wms_license_plate_numbers wlpn
303 		   , mtl_system_items msi
304 		   WHERE wlc.parent_lpn_id = wlpn.lpn_id
305 		   AND wlc.inventory_item_id = msi.inventory_item_id
306 		   AND msi.organization_id = p_org_id
307 		   AND wlpn.organization_id = p_org_id
308 		   AND msi.mtl_transactions_enabled_flag <> p_transactions_enabled_flag
309 		   AND wlpn.lpn_id IN (SELECT lpn_id
310 				       FROM wms_license_plate_numbers wlpn2
311 				       CONNECT BY PRIOR wlpn2.lpn_id = wlpn2.parent_lpn_id
312 				       START WITH wlpn2.lpn_id = p_lpn_id
313 				       UNION ALL
314 				       SELECT lpn_id
315 				       FROM wms_license_plate_numbers wlpn3
316 				       CONNECT BY PRIOR wlpn3.parent_lpn_id = wlpn3.lpn_id
317 				       START WITH wlpn3.parent_lpn_id = p_lpn_id));
318 
319    RETURN TRUE;
320 EXCEPTION
321    WHEN no_data_found THEN
322       RETURN FALSE;
323    WHEN OTHERS THEN
324       RETURN TRUE;
325 END validate_mixed_expense_items;
326 
327 --procedure to call appropriate atf api.
328 
329 PROCEDURE call_atf_api(x_return_status OUT nocopy VARCHAR2,
330 		       x_msg_data OUT nocopy VARCHAR2,
331 		       x_msg_count OUT nocopy NUMBER,
332 		       x_error_code OUT nocopy NUMBER,
333 		       p_source_task_id IN NUMBER,
334 		       p_activity_type_id IN NUMBER,
335 		       p_operation_type_id IN NUMBER,
336 		       p_mol_id IN NUMBER,
337 		       p_atf_api_name IN NUMBER,
338 		       p_mmtt_error_code   IN   VARCHAR2,
339 		       p_mmtt_error_explanation   IN   VARCHAR2,
340 		       p_retain_mmtt IN VARCHAR2)
341   IS
342      -- Bug 5231114: Added the condition on transaction_source_type_id and
343      -- transaction_action_id for the following combinations:13/12 and 4/27
344      CURSOR c_mmtt IS
345 	SELECT transaction_temp_id
346 	  FROM mtl_material_transactions_temp
347 	  WHERE move_order_line_id = p_mol_id
348 	  AND ((transaction_source_type_id = 1 AND transaction_action_id = 27)
349 	       OR (transaction_source_type_id = 7 AND transaction_action_id = 12)
350 	       OR (transaction_source_type_id = 12 AND transaction_action_id = 27)
351 	       OR (transaction_source_type_id = 13 AND transaction_action_id = 12)
352 	       OR (transaction_source_type_id = 4 AND transaction_action_id = 27));
353 
354      l_transaction_temp_id NUMBER;
355 
356      l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
357 BEGIN
358 
359    IF p_source_task_id IS NOT NULL THEN
360       IF (p_atf_api_name = g_atf_api_complete) THEN
361 	 wms_atf_runtime_pub_apis.complete_operation_instance(x_return_status => x_return_status
362 							      ,x_msg_data => x_msg_data
363 							      ,x_msg_count => x_msg_count
364 							      ,x_error_code => x_error_code
365 							      ,p_source_task_id => p_source_task_id
366 							      ,p_activity_id => p_activity_type_id
367 							      ,p_operation_type_id => p_operation_type_id);
368        ELSIF (p_atf_api_name = g_atf_api_cancel) THEN
369 	 wms_atf_runtime_pub_apis.cancel_operation_plan(x_return_status => x_return_status
370 							,x_msg_data => x_msg_data
371 							,x_msg_count => x_msg_count
372 							,x_error_code => x_error_code
373 							,p_source_task_id => p_source_task_id
374 							,p_activity_type_id=> p_activity_type_id
375 							,p_mmtt_error_code => p_mmtt_error_code
376 							,p_mmtt_error_explanation => p_mmtt_error_explanation
377 							,p_retain_mmtt => p_retain_mmtt);
378        ELSIF (p_atf_api_name = g_atf_api_abort) THEN
379 	 wms_atf_runtime_pub_apis.abort_operation_plan(x_return_status => x_return_status
380 						       ,x_msg_data => x_msg_data
381 						       ,x_msg_count => x_msg_count
382 						       ,x_error_code => x_error_code
383 						       ,p_source_task_id => p_source_task_id
384 						       ,p_activity_type_id => p_activity_type_id);
385        ELSIF (p_atf_api_name = g_atf_api_cleanup) THEN
386 	 wms_atf_runtime_pub_apis.cleanup_operation_instance(x_return_status => x_return_status
387 							     ,x_msg_data => x_msg_data
388 							     ,x_msg_count => x_msg_count
389 							     ,x_error_code => x_error_code
390 							     ,p_source_task_id => p_source_task_id
391 							     ,p_activity_type_id => p_activity_type_id);
392       END IF;--ELSIF (p_atf_api_name = g_atf_api_cleanup) THEN
393     ELSE --IF p_source_task_id IS NOT NULL THEN
394       FOR l_mmtt IN c_mmtt LOOP
395 	 IF (p_atf_api_name = g_atf_api_complete) THEN
396 	    wms_atf_runtime_pub_apis.complete_operation_instance(x_return_status => x_return_status
397 								 ,x_msg_data => x_msg_data
398 								 ,x_msg_count => x_msg_count
399 								 ,x_error_code => x_error_code
400 								 ,p_source_task_id => l_mmtt.transaction_temp_id
401 								 ,p_activity_id => p_activity_type_id
402 								 ,p_operation_type_id => p_operation_type_id);
403 	  ELSIF (p_atf_api_name = g_atf_api_cancel) THEN
404 	    wms_atf_runtime_pub_apis.cancel_operation_plan(x_return_status => x_return_status
405 							   ,x_msg_data => x_msg_data
406 							   ,x_msg_count => x_msg_count
407 							   ,x_error_code => x_error_code
408 							   ,p_source_task_id => l_mmtt.transaction_temp_id
409 							   ,p_activity_type_id => p_activity_type_id
410 							   ,p_mmtt_error_code => p_mmtt_error_code
411 							   ,p_mmtt_error_explanation => p_mmtt_error_explanation
412 							   ,p_retain_mmtt => p_retain_mmtt);
413 	  ELSIF (p_atf_api_name = g_atf_api_abort) THEN
414 	    wms_atf_runtime_pub_apis.abort_operation_plan(x_return_status => x_return_status
415 							  ,x_msg_data => x_msg_data
416 							  ,x_msg_count => x_msg_count
417 							  ,x_error_code => x_error_code
418 							  ,p_source_task_id => l_mmtt.transaction_temp_id
419 							  ,p_activity_type_id => p_activity_type_id);
420 	  ELSIF (p_atf_api_name = g_atf_api_cleanup) THEN
421 	    wms_atf_runtime_pub_apis.cleanup_operation_instance(x_return_status => x_return_status
422 								,x_msg_data => x_msg_data
423 								,x_msg_count => x_msg_count
424 								,x_error_code => x_error_code
425 								,p_source_task_id => l_mmtt.transaction_temp_id
426 								,p_activity_type_id => p_activity_type_id);
427 	 END IF;--ELSIF (p_atf_api_name = g_atf_api_cleanup) THEN
428       END LOOP; --FOR l_mmtt IN (c_mmtt) LOOP
429    END IF; --IF p_source_task_id IS NOT NULL THEN
430 
431 END call_atf_api;
432 
433 --Procedure to get the lot/serial controls in the source or for int shp/req rcpt.
434 PROCEDURE get_serial_lot_ctrl_in_src_org
435   (p_shipment_line_id IN NUMBER,
436    p_org_id IN NUMBER,
437    x_serial_control_code OUT nocopy NUMBER,
438    x_lot_control_code OUT nocopy NUMBER,
439    x_revision_control_code OUT nocopy NUMBER,
440    x_return_status OUT nocopy VARCHAR2,
441    x_msg_count OUT nocopy NUMBER,
442    x_msg_data OUT nocopy VARCHAR2)
443   IS
444      l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
445 BEGIN
446    x_return_status := g_ret_sts_success;
447 
448    SELECT msi.lot_control_code
449      , msi.serial_number_control_code
450      , msi.revision_qty_control_code
451      INTO x_lot_control_code
452      , x_serial_control_code
453      , x_revision_control_code
454      FROM mtl_system_items msi, rcv_shipment_lines rsl
455      WHERE rsl.shipment_line_id = p_shipment_line_id
456      AND rsl.to_organization_id = p_org_id
457      AND msi.inventory_item_id = rsl.item_id
458      AND msi.organization_id = rsl.from_organization_id;
459 
460 EXCEPTION
461    WHEN OTHERS THEN
462       x_return_status  := g_ret_sts_unexp_error;
463       IF (l_debug = 1) THEN
464          print_debug('get_serial_lot_ctrl_in_src_org - other exception: '||
465 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
466       END IF;
467       IF SQLCODE IS NOT NULL THEN
468 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.get_serial_lot_ctrl_in_src_org',Sqlerrm,SQLCODE);
469       END IF;
470       --  Get message count and data
471       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
472 END get_serial_lot_ctrl_in_src_org;
473 
474 PROCEDURE create_lot_serial_history(p_prod_txn_tmp_id IN NUMBER
475 				    ,p_prod_txn_id      IN NUMBER
476 				    ,x_return_status       OUT NOCOPY VARCHAR2
477 				    ,x_msg_count           OUT NOCOPY NUMBER
478 				    ,x_msg_data            OUT NOCOPY VARCHAR2)
479   IS
480      TYPE varchar30_tb_tp IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
481 
482      l_temp_prefix VARCHAR2(30);
483      l_from_ser_number NUMBER;
484      l_to_ser_number NUMBER;
485      l_cur_ser_number NUMBER;
486      l_range_numbers NUMBER;
487      l_cur_serial_number VARCHAR2(30);
488      l_serial_numbers varchar30_tb_tp;
489      l_sysdate DATE := Sysdate;
490 
491      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
492      l_progress VARCHAR2(15);
493 
494      CURSOR msnt_cur IS
495 	SELECT
496 	  msnt.transaction_temp_id transaction_temp_id
497 	  ,msnt.last_updated_by last_updated_by
498 	  ,msnt.created_by created_by
499 	  ,rti.item_id inventory_item_id
500 	  ,rti.to_organization_id organization_id
501 	  ,msnt.fm_serial_number fm_serial_number
502 	  ,msnt.to_serial_number to_serial_number
503 	  ,rti.transaction_date transaction_date
504 	  ,Decode(rti.source_document_code,
505 		  'INVENTORY',
506 		  13,
507 		  Decode(rti.source_document_code,
508 			 'PO',
509 			 1,
510 			 Decode(rti.source_document_code,
511 				'REQ',
512 				7,
513 				Decode(rti.source_document_code,
514 				       'RMA',
515 				       12,
516 				       -1)))) transaction_source_type_id
517 	  -- What to do in error condition?
518 	  ,rti.source_document_code transaction_source_name
519 	  ,Decode(rti.transaction_type,
520 		  'RETURN TO RECEIVING',
521 		  1,
522 		  Decode(rti.transaction_type,
523 			 'RETURN TO VENDOR',
524 			 1,
525 			 Decode(rti.transaction_type,
526 				'RETURN TO CUSTOMER',
527 				1,
528 				2))) receipt_issue_type
529 	  ,msnt.serial_attribute_category serial_attribute_category
530 	  ,msnt.origination_date origination_date
531 	  ,msnt.c_attribute1 c_attribute1
532 	  ,msnt.c_attribute2 c_attribute2
533 	  ,msnt.c_attribute3 c_attribute3
534 	  ,msnt.c_attribute4 c_attribute4
535 	  ,msnt.c_attribute5 c_attribute5
536 	  ,msnt.c_attribute6 c_attribute6
537 	  ,msnt.c_attribute7 c_attribute7
538 	  ,msnt.c_attribute8 c_attribute8
539 	  ,msnt.c_attribute9 c_attribute9
540 	  ,msnt.c_attribute10 c_attribute10
541 	  ,msnt.c_attribute11 c_attribute11
542 	  ,msnt.c_attribute12 c_attribute12
543 	  ,msnt.c_attribute13 c_attribute13
544 	  ,msnt.c_attribute14 c_attribute14
545 	  ,msnt.c_attribute15 c_attribute15
546 	  ,msnt.c_attribute16 c_attribute16
547 	  ,msnt.c_attribute17 c_attribute17
548 	  ,msnt.c_attribute18 c_attribute18
549 	  ,msnt.c_attribute19 c_attribute19
550 	  ,msnt.c_attribute20 c_attribute20
551 	  ,msnt.d_attribute1 d_attribute1
552 	  ,msnt.d_attribute2 d_attribute2
553 	  ,msnt.d_attribute3 d_attribute3
554 	  ,msnt.d_attribute4 d_attribute4
555 	  ,msnt.d_attribute5 d_attribute5
556 	  ,msnt.d_attribute6 d_attribute6
557 	  ,msnt.d_attribute7 d_attribute7
558 	  ,msnt.d_attribute8 d_attribute8
559 	  ,msnt.d_attribute9 d_attribute9
560 	  ,msnt.d_attribute10 d_attribute10
561 	  ,msnt.n_attribute1 n_attribute1
562 	  ,msnt.n_attribute2 n_attribute2
563 	  ,msnt.n_attribute3 n_attribute3
564 	  ,msnt.n_attribute4 n_attribute4
565 	  ,msnt.n_attribute5 n_attribute5
566 	  ,msnt.n_attribute6 n_attribute6
567 	  ,msnt.n_attribute7 n_attribute7
568 	  ,msnt.n_attribute8 n_attribute8
569 	  ,msnt.n_attribute9 n_attribute9
570 	  ,msnt.n_attribute10 n_attribute10
571 	  ,msnt.status_id status_id
572 	  ,msnt.territory_code territory_code
573 	  ,msnt.time_since_new time_since_new
574 	  ,msnt.cycles_since_new cycles_since_new
575 	  ,msnt.time_since_overhaul time_since_overhaul
576 	  ,msnt.cycles_since_overhaul cycles_since_overhaul
577 	  ,msnt.time_since_repair time_since_repair
578 	  ,msnt.cycles_since_repair cycles_since_repair
579 	  ,msnt.time_since_visit time_since_visit
580 	  ,msnt.cycles_since_visit cycles_since_visit
581 	  ,msnt.time_since_mark time_since_mark
582 	  ,msnt.cycles_since_mark cycles_since_mark
583 	  ,msnt.number_of_repairs number_of_repairs
584 	  from
585 	  mtl_serial_numbers_temp msnt
586 	  ,rcv_transactions_interface rti
587 	  where
588 	  msnt.product_code = 'RCV'
589 	  AND msnt.product_transaction_id = p_prod_txn_tmp_id
590 	  AND rti.interface_transaction_id = msnt.product_transaction_id;
591 BEGIN
592 
593    IF (l_debug = 1) THEN
594       print_debug('CREATE_LOT_SERIAL_HISTORY: Entered with the following paramenters -', 1);
595       print_debug('  p_prod_txn_tmp_id => ' || p_prod_txn_tmp_id, 1);
596       print_debug('  p_prod_txn_id     => ' || p_prod_txn_id, 1);
597    END IF;
598 
599    SAVEPOINT process_lot_serial_pub;
600 
601    x_return_status := g_ret_sts_success;
602 
603    l_progress := 'WMSINB-10431';
604 
605    IF (l_debug = 1) THEN
606       print_debug('CREATE_LOT_SERIAL_HISTORY: Processing MTLT...',1);
607    END IF;
608 
609    INSERT INTO mtl_transaction_lot_numbers
610      (
611       transaction_id
612       ,last_update_date
613       ,last_updated_by
614       ,creation_date
615       ,created_by
616       ,last_update_login
617       ,inventory_item_id
618       ,organization_id
619       ,transaction_date
620       ,transaction_source_id
621       ,transaction_source_type_id
622       ,transaction_source_name
623       ,transaction_quantity
624       ,primary_quantity
625       ,lot_number
626       ,serial_transaction_id
627       ,description
628       ,vendor_name
629       ,supplier_lot_number
630       ,origination_date
631       ,date_code
632       ,grade_code
633       ,change_date
634       ,maturity_date
635       ,status_id
636       ,retest_date
637       ,age
638       ,item_size
639       ,color
640       ,volume
641       ,volume_uom
642       ,place_of_origin
643       ,best_by_date
644       ,length
645       ,length_uom
646       ,width
647       ,width_uom
648       ,recycled_content
649       ,thickness
650       ,thickness_uom
651       ,curl_wrinkle_fold
652       ,lot_attribute_category
653       ,c_attribute1
654       ,c_attribute2
655       ,c_attribute3
656       ,c_attribute4
657       ,c_attribute5
658       ,c_attribute6
659      ,c_attribute7
660      ,c_attribute8
661      ,c_attribute9
662      ,c_attribute10
663      ,c_attribute11
664      ,c_attribute12
665      ,c_attribute13
666      ,c_attribute14
667      ,c_attribute15
668      ,c_attribute16
669      ,c_attribute17
670      ,c_attribute18
671      ,c_attribute19
672      ,c_attribute20
673      ,d_attribute1
674      ,d_attribute2
675      ,d_attribute3
676      ,d_attribute4
677      ,d_attribute5
678      ,d_attribute6
679      ,d_attribute7
680      ,d_attribute8
681      ,d_attribute9
682      ,d_attribute10
683      ,n_attribute1
684      ,n_attribute2
685      ,n_attribute3
686      ,n_attribute4
687      ,n_attribute5
688      ,n_attribute6
689      ,n_attribute7
690      ,n_attribute8
691      ,n_attribute9
692      ,n_attribute10
693      ,vendor_id
694      ,territory_code
695      ,product_code
696      ,product_transaction_id
697      ,attribute_category
698      ,attribute1
699      ,attribute2
700      ,attribute3
701      ,attribute4
702      ,attribute5
703      ,attribute6
704      ,attribute7
705      ,attribute8
706      ,attribute9
707      ,attribute10
708      ,attribute11
709      ,attribute12
710      ,attribute13
711      ,attribute14
712      ,attribute15 )
713      SELECT
714      mtlt.transaction_temp_id
715      ,l_sysdate
716      ,mtlt.last_updated_by
717      ,l_sysdate
718      ,mtlt.created_by
719      ,-1
720      ,rti.item_id
721      ,rti.to_organization_id
722      ,rti.transaction_date
723      ,NULL
724      ,Decode(rti.source_document_code,
725 	     'INVENTORY',
726 	     13,
727 	     Decode(rti.source_document_code,
728 		    'PO',
729 		    1,
730 		    Decode(rti.source_document_code,
731 			   'REQ',
732 			   7,
733 			   Decode(rti.source_document_code,
734 				  'RMA',
735 				  12,
736 				  -1))))
737      ,rti.source_document_code
738      ,mtlt.transaction_quantity
739      ,mtlt.primary_quantity
740      ,Ltrim(Rtrim(mtlt.lot_number))
741      ,mtlt.serial_transaction_temp_id
742      ,mtlt.description
743      ,mtlt.vendor_name
744      ,mtlt.supplier_lot_number
745      ,mtlt.origination_date
746      ,mtlt.date_code
747      ,mtlt.grade_code
748      ,mtlt.change_date
749      ,mtlt.maturity_date
750      ,mtlt.status_id
751      ,mtlt.retest_date
752      ,mtlt.age
753      ,mtlt.item_size
754      ,mtlt.color
755      ,mtlt.volume
756      ,mtlt.volume_uom
757      ,mtlt.place_of_origin
758      ,mtlt.best_by_date
759      ,mtlt.length
760      ,mtlt.length_uom
761      ,mtlt.recycled_content
762      ,mtlt.thickness
763      ,mtlt.thickness_uom
764      ,mtlt.width
765      ,mtlt.width_uom
766      ,mtlt.curl_wrinkle_fold
767      ,mtlt.lot_attribute_category
768      ,mtlt.c_attribute1
769      ,mtlt.c_attribute2
770      ,mtlt.c_attribute3
771      ,mtlt.c_attribute4
772      ,mtlt.c_attribute5
773      ,mtlt.c_attribute6
774      ,mtlt.c_attribute7
775      ,mtlt.c_attribute8
776      ,mtlt.c_attribute9
777      ,mtlt.c_attribute10
778      ,mtlt.c_attribute11
779      ,mtlt.c_attribute12
780      ,mtlt.c_attribute13
781      ,mtlt.c_attribute14
782      ,mtlt.c_attribute15
783      ,mtlt.c_attribute16
784      ,mtlt.c_attribute17
785      ,mtlt.c_attribute18
786      ,mtlt.c_attribute19
787      ,mtlt.c_attribute20
788      ,mtlt.d_attribute1
789      ,mtlt.d_attribute2
790      ,mtlt.d_attribute3
791      ,mtlt.d_attribute4
792      ,mtlt.d_attribute5
793      ,mtlt.d_attribute6
794      ,mtlt.d_attribute7
795      ,mtlt.d_attribute8
796      ,mtlt.d_attribute9
797      ,mtlt.d_attribute10
798      ,mtlt.n_attribute1
799      ,mtlt.n_attribute2
800      ,mtlt.n_attribute3
801      ,mtlt.n_attribute4
802      ,mtlt.n_attribute5
803      ,mtlt.n_attribute6
804      ,mtlt.n_attribute7
805      ,mtlt.n_attribute8
806      ,mtlt.n_attribute9
807      ,mtlt.n_attribute10
808      ,mtlt.vendor_id
809      ,mtlt.territory_code
810      ,'RCV'
811      ,p_prod_txn_id
812      ,mtlt.attribute_category
813      ,mtlt.attribute1
814      ,mtlt.attribute2
815      ,mtlt.attribute3
816      ,mtlt.attribute4
817      ,mtlt.attribute5
818      ,mtlt.attribute6
819      ,mtlt.attribute7
820      ,mtlt.attribute8
821      ,mtlt.attribute9
822      ,mtlt.attribute10
823      ,mtlt.attribute11
824      ,mtlt.attribute12
825      ,mtlt.attribute13
826      ,mtlt.attribute14
827      ,mtlt.attribute15
828      FROM
829      mtl_transaction_lots_temp mtlt
830      ,rcv_transactions_interface rti
831      WHERE
832      mtlt.product_transaction_id = p_prod_txn_tmp_id AND
833      mtlt.product_code = 'RCV' AND
834      rti.interface_transaction_id = p_prod_txn_tmp_id;
835 
836    l_progress := 'WMSINB-10664';
837 
838    IF (l_debug = 1) THEN
839       print_debug('CREATE_LOT_SERIAL_HISTORY: MTLNs inserted.',1);
840    END IF;
841 
842    FOR l_msnt IN msnt_cur LOOP
843       IF (l_debug = 1) THEN
844 	 print_debug('CREATE_LOT_SERIAL_HISTORY:   Processing MSNT with fm_serial_number = '
845 		     || l_msnt.fm_serial_number ||
846 		     ' to_serial_number = ' || l_msnt.to_serial_number,1);
847       END IF;
848 
849       l_progress := 'WMSINB-10677';
850       inv_validate.number_from_sequence(l_msnt.fm_serial_number, l_temp_prefix, l_from_ser_number);
851       l_progress := 'WMSINB-10679';
852       inv_validate.number_from_sequence(l_msnt.to_serial_number
853 					,l_temp_prefix
854 					,l_to_ser_number);
855       l_progress := 'WMSINB-10683';
856       l_range_numbers  := l_to_ser_number - l_from_ser_number + 1;
857 
858       l_progress := 'WMSINB-10686';
859       IF (l_serial_numbers.COUNT > 0) THEN
860 	 l_serial_numbers.DELETE;
861       END IF;
862 
863       l_progress := 'WMSINB-10691';
864 
865       for j in 1 .. l_range_numbers loop
866 	 l_cur_ser_number  := l_from_ser_number + j - 1;
867 
868 	 -- concatenate the serial number to be inserted
869 	 if (l_from_ser_number = -1
870 	     and l_to_ser_number = -1) then
871 	    l_cur_serial_number  := l_msnt.fm_serial_number;
872 	  else
873 	    l_cur_serial_number  := substr(l_msnt.fm_serial_number, 1, length(l_msnt.fm_serial_number) -
874 					   length(l_cur_ser_number)) || l_cur_ser_number;
875 	 end if;
876 
877 	 IF (l_debug = 1) THEN
878 	    print_debug('CREATE_LOT_SERIAL_HISTORY:    Cancatenated serial_number '
879 			|| l_cur_serial_number,1);
880 	 END IF;
881 
882 	 l_serial_numbers(j) := l_cur_serial_number;
883 
884       end loop;
885 
886       l_progress := 'WMSINB-10714';
887 
888       forall  j IN 1 .. l_serial_numbers.COUNT
889 	INSERT INTO mtl_unit_transactions
890 	( transaction_id
891 	  ,last_update_date
892 	  ,last_updated_by
893 	  ,creation_date
894 	  ,created_by
895 	  ,last_update_login
896 	  ,serial_number
897 	  ,inventory_item_id
898 	  ,organization_id
899 	  ,subinventory_code
900 	  ,locator_id
901 	  ,transaction_date
902 	  ,transaction_source_id
903 	  ,transaction_source_type_id
904 	  ,transaction_source_name
905 	  ,receipt_issue_type
906 	  ,customer_id
907 	  ,ship_id
908 	  ,serial_attribute_category
909 	  ,origination_date
910 	  ,c_attribute1
911 	  ,c_attribute2
912 	  ,c_attribute3
913 	  ,c_attribute4
914 	  ,c_attribute5
915 	  ,c_attribute6
916 	  ,c_attribute7
917 	  ,c_attribute8
918 	  ,c_attribute9
919 	  ,c_attribute10
920 	  ,c_attribute11
921 	  ,c_attribute12
922 	  ,c_attribute13
923 	  ,c_attribute14
924 	  ,c_attribute15
925 	  ,c_attribute16
926 	  ,c_attribute17
927 	  ,c_attribute18
928 	  ,c_attribute19
929 	  ,c_attribute20
930 	  ,d_attribute1
931 	  ,d_attribute2
932 	  ,d_attribute3
933 	  ,d_attribute4
934 	  ,d_attribute5
935 	  ,d_attribute6
936 	  ,d_attribute7
937 	  ,d_attribute8
938 	  ,d_attribute9
939 	  ,d_attribute10
940 	  ,n_attribute1
941 	  ,n_attribute2
942 	  ,n_attribute3
943 	  ,n_attribute4
944 	,n_attribute5
945 	,n_attribute6
946 	,n_attribute7
947 	,n_attribute8
948 	,n_attribute9
949 	,n_attribute10
950 	,status_id
951 	,territory_code
952 	,time_since_new
953 	,cycles_since_new
954 	,time_since_overhaul
955 	,cycles_since_overhaul
956 	,time_since_repair
957 	,cycles_since_repair
958 	,time_since_visit
959 	,cycles_since_visit
960 	,time_since_mark
961 	,cycles_since_mark
962 	,number_of_repairs
963 	,product_code
964 	,product_transaction_id )
965 	VALUES
966 	( l_msnt.transaction_temp_id
967 	  ,l_sysdate
968 	  ,l_msnt.last_updated_by
969 	  ,l_sysdate
970 	  ,l_msnt.created_by
971 	  ,-1
972 	  ,l_serial_numbers(j)
973 	  ,l_msnt.inventory_item_id
974 	  ,l_msnt.organization_id
975 	  ,NULL  -- sub
976 	  ,NULL  -- loc
977 	  ,l_msnt.transaction_date
978 	  ,NULL  -- txn souce id
979 	  ,l_msnt.transaction_source_type_id
980 	  ,l_msnt.transaction_source_name
981 	  ,l_msnt.receipt_issue_type
982 	  ,NULL  -- customer id
983 	  ,NULL  -- ship_id
984 	  ,l_msnt.serial_attribute_category
985 	  ,l_msnt.origination_date
986 	  ,l_msnt.c_attribute1
987 	  ,l_msnt.c_attribute2
988 	  ,l_msnt.c_attribute3
989 	  ,l_msnt.c_attribute4
990 	  ,l_msnt.c_attribute5
991 	  ,l_msnt.c_attribute6
992 	  ,l_msnt.c_attribute7
993 	  ,l_msnt.c_attribute8
994 	  ,l_msnt.c_attribute9
995 	  ,l_msnt.c_attribute10
996 	  ,l_msnt.c_attribute11
997 	  ,l_msnt.c_attribute12
998 	  ,l_msnt.c_attribute13
999 	  ,l_msnt.c_attribute14
1000 	  ,l_msnt.c_attribute15
1001 	  ,l_msnt.c_attribute16
1002 	  ,l_msnt.c_attribute17
1003 	  ,l_msnt.c_attribute18
1004 	  ,l_msnt.c_attribute19
1005 	  ,l_msnt.c_attribute20
1006 	  ,l_msnt.d_attribute1
1007 	,l_msnt.d_attribute2
1008 	,l_msnt.d_attribute3
1009 	,l_msnt.d_attribute4
1010 	,l_msnt.d_attribute5
1011 	,l_msnt.d_attribute6
1012 	,l_msnt.d_attribute7
1013 	,l_msnt.d_attribute8
1014 	,l_msnt.d_attribute9
1015 	,l_msnt.d_attribute10
1016 	,l_msnt.n_attribute1
1017 	,l_msnt.n_attribute2
1018 	,l_msnt.n_attribute3
1019 	,l_msnt.n_attribute4
1020 	,l_msnt.n_attribute5
1021 	,l_msnt.n_attribute6
1022 	,l_msnt.n_attribute7
1023 	,l_msnt.n_attribute8
1024 	,l_msnt.n_attribute9
1025 	,l_msnt.n_attribute10
1026 	,l_msnt.status_id
1027 	,l_msnt.territory_code
1028 	,l_msnt.time_since_new
1029 	,l_msnt.cycles_since_new
1030 	,l_msnt.time_since_overhaul
1031 	,l_msnt.cycles_since_overhaul
1032 	,l_msnt.time_since_repair
1033 	,l_msnt.cycles_since_repair
1034 	,l_msnt.time_since_visit
1035 	,l_msnt.cycles_since_visit
1036 	,l_msnt.time_since_mark
1037 	,l_msnt.cycles_since_mark
1038 	,l_msnt.number_of_repairs
1039 	,'RCV'
1040 	,p_prod_txn_id );
1041 
1042       l_progress := 'WMSINB-10870';
1043 
1044    END LOOP;
1045 
1046    IF (l_debug = 1) THEN
1047       print_debug('CREATE_LOT_SERIAL_HISTORY: Deleting MTLI/MSNT',1);
1048    END IF;
1049 
1050    --Delete MTLT/MSNT here
1051    DELETE FROM mtl_transaction_lots_temp
1052      WHERE product_code = 'RCV'
1053      AND product_transaction_id = p_prod_txn_tmp_id;
1054 
1055    l_progress := 'WMSINB-10883';
1056 
1057    DELETE FROM mtl_serial_numbers_temp
1058      WHERE product_code = 'RCV'
1059      AND product_transaction_id = p_prod_txn_tmp_id;
1060 
1061    IF (l_debug = 1) THEN
1062       print_debug('CREATE_LOT_SERIAL_HISTORY: Exited',1);
1063    END IF;
1064 
1065 EXCEPTION
1066    WHEN OTHERS THEN
1067       IF (l_debug = 1) THEN
1068 	 print_debug('CREATE_LOT_SERIAL_HISTORY: Exception occured aftr l_progress = '
1069 		     || l_progress,1);
1070       END IF;
1071       x_return_status := g_ret_sts_unexp_error;
1072       --fnd_msg_pub.count_and_get
1073       --  (   p_count                       => x_msg_count
1074       --      ,p_data                       => x_msg_data
1075       --      );
1076       ROLLBACK TO process_lot_serial_pub;
1077 END create_lot_serial_history;
1078 
1079 PROCEDURE cancel_asn
1080   (x_return_status OUT nocopy VARCHAR2
1081    ,x_msg_count OUT nocopy NUMBER
1082    ,x_msg_data OUT nocopy VARCHAR2
1083    ,p_shipment_header_id IN NUMBER
1084    ,p_shipment_line_id IN NUMBER
1085    ,p_primary_quantity IN NUMBER
1086 )
1087   IS
1088 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
1089      TYPE varchar30_tb_tp IS TABLE OF VARCHAR2(80) INDEX BY BINARY_INTEGER;
1090      TYPE number_tb_tp IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
1091      l_serial_numbers varchar30_tb_tp;
1092      l_lot_numbers varchar30_tb_tp;
1093      l_quantitys number_tb_tp;
1094 
1095      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1096      l_progress VARCHAR (15) := '0';
1097      l_asn_lpn_id NUMBER;
1098      l_item_id NUMBER;
1099      l_quantity_to_unpack NUMBER;
1100      l_lot_control_code NUMBER;
1101      l_serial_number_control_code NUMBER;
1102      l_lpn_context NUMBER;
1103      l_org_id NUMBER;
1104      l_uom_code VARCHAR2(3);
1105      l_quantity_received NUMBER;
1106      l_unit_of_measure VARCHAR2(25);
1107      l_prim_uom_code VARCHAR2(3);
1108      l_revision VARCHAR2(3);
1109 
1110      -- OPMConvergence
1111      l_sec_lot_qty            number_tb_tp;
1112      l_sec_uom_code           VARCHAR2(3);
1113      l_sec_uom_code_2         VARCHAR2(3);
1114      l_sec_quantity_to_unpack NUMBER;
1115      l_sec_unit_of_measure    VARCHAR2(25);
1116      -- OPMConvergence
1117 
1118      l_mol_res_in  cas_mol_rec_tb_tp;
1119      l_mol_res_out cas_mol_rec_tb_tp;
1120      l_po_header_id NUMBER;
1121      l_po_line_location_id NUMBER;
1122      l_prim_qty_to_unpack NUMBER;
1123      l_procedure_name         VARCHAR2(30) := 'CANCEL_ASN';
1124      l_serials_count    NUMBER := 0; --added for bug 6708102
1125      l_lots_count       NUMBER := 0; --added for bug 6708102
1126 BEGIN
1127    IF (l_debug = 1) THEN
1128       print_debug('CANCEL_ASN: Entering...', 1);
1129       print_debug('             p_shipment_header_id => '||
1130 		  p_shipment_header_id,1);
1131       print_debug('             p_shipment_lind_id   => '||
1132 		  p_shipment_line_id,1);
1133    END IF;
1134 
1135    x_return_status := g_ret_sts_success;
1136 
1137    l_progress := 'WMSINB-10945';
1138 
1139    BEGIN
1140       SELECT
1141 	rsl.asn_lpn_id asn_lpn_id
1142 	,rsl.item_id item_id
1143 	,rsl.item_revision revision
1144 	,rsl.to_organization_id organization_id
1145 	,rsl.unit_of_measure unit_of_measure
1146 	,msi.primary_uom_code prim_uom_code
1147 	,(Nvl(rsl.quantity_shipped,0) - Nvl(rsl.quantity_received,0)) quantity_to_unpack
1148    -- OPMConvergence
1149 	,rsl.secondary_unit_of_measure sec_unit_of_measure
1150 	,msi.secondary_uom_code sec_uom_code
1151 	,(Nvl(rsl.secondary_quantity_shipped,0) - Nvl(rsl.secondary_quantity_received,0)) sec_quantity_to_unpack
1152         -- OPMConvergence
1153 	,Nvl(rsl.quantity_received,0)
1154     ,msi.lot_control_code lot_control_code
1155 	,msi.serial_number_control_code serial_number_control_code
1156 --	,wlpn.lpn_context lpn_context
1157 	,rsl.po_line_location_id
1158 	,rsl.po_header_id
1159 	INTO
1160 	l_asn_lpn_id
1161 	,l_item_id
1162 	,l_revision
1163 	,l_org_id
1164 	,l_unit_of_measure
1165 	,l_prim_uom_code
1166 	,l_quantity_to_unpack
1167          -- OPMConvergence
1168 	,l_sec_unit_of_measure
1169 	,l_sec_uom_code
1170 	,l_sec_quantity_to_unpack
1171          -- OPMConvergence
1172 	,l_quantity_received
1173     ,l_lot_control_code
1174 	,l_serial_number_control_code
1175 --	,l_lpn_context
1176 	,l_po_line_location_id
1177 	,l_po_header_id
1178 	FROM
1179 	rcv_shipment_lines rsl
1180 	,mtl_system_items msi
1181 	WHERE
1182 	rsl.shipment_line_id = p_shipment_line_id
1183 	AND rsl.shipment_header_id = p_shipment_header_id
1184 	AND msi.inventory_item_id = rsl.item_id
1185 	AND msi.organization_id = rsl.to_organization_id;
1186    EXCEPTION
1187       --BUG 3387020
1188       WHEN no_data_found THEN
1189 	 IF (l_debug = 1) THEN
1190 	    print_debug('No data found for shipment_line_id: ' ||
1191 			p_shipment_line_id, 1);
1192 	 END IF;
1193 	 l_progress := 'WMSINB-10985';
1194 	 l_asn_lpn_id := NULL;
1195       WHEN OTHERS THEN
1196 	 IF (l_debug = 1) THEN
1197 	    print_debug('Error retrieving shipment line with id: ' ||
1198 			p_shipment_line_id, 1);
1199 	 END IF;
1200 	 l_progress := 'WMSINB-10986';
1201 	 RAISE fnd_api.g_exc_error;
1202    END;
1203 
1204    l_progress := 'WMSINB-10990';
1205 
1206    --BUG 3387020
1207    IF l_asn_lpn_id IS NOT NULL THEN
1208       BEGIN
1209 	 SELECT lpn_context
1210 	   INTO l_lpn_context
1211 	   FROM wms_license_plate_numbers
1212 	   WHERE lpn_id = l_asn_lpn_id;
1213       EXCEPTION
1214 	 WHEN OTHERS THEN
1215 	    IF (l_debug = 1) THEN
1216 	       print_debug('Error retrieving LPN context!',1);
1217 	    END IF;
1218 	    l_progress := 'WMSINB-10009';
1219 	    RAISE fnd_api.g_exc_error;
1220       END;
1221     ELSE
1222       l_lpn_context := NULL;
1223    END IF;
1224 
1225    IF (Nvl(l_lpn_context,-1) = 7) THEN
1226       IF (l_debug = 1) THEN
1227 	 print_debug('CANCEL_ASN: LPN Context is 7',
1228 		     1);
1229       END IF;
1230 
1231       IF (l_serial_number_control_code IN (2, 5)) THEN
1232 
1233 	 l_progress := 'WMSINB-11000';
1234 	 IF (l_debug = 1) THEN
1235 	    print_debug('CANCEL_ASN: item is serial_controlled', 1);
1236 	 END IF;
1237 
1238 	 BEGIN
1239 	    SELECT
1240 	      serial_num
1241 	      ,lot_num
1242 	      BULK collect INTO
1243 	      l_serial_numbers
1244 	      ,l_lot_numbers
1245 	      FROM
1246 	      rcv_serials_supply
1247 	      WHERE
1248 	      shipment_line_id = p_shipment_line_id
1249 	      AND supply_type_code = 'SHIPMENT';
1250 	 EXCEPTION
1251 	    WHEN OTHERS THEN
1252 	       IF (l_debug = 1) THEN
1253 		  print_debug('CANCEL_ASN: Error retrieving serial numbers'
1254 			      ,1);
1255 	       END IF;
1256 	 END;
1257 
1258 	 l_progress := 'WMSINB-11025';
1259 
1260 	 FOR i IN 1 .. l_serial_numbers.COUNT LOOP
1261 	    wms_container_pvt.packunpack_container
1262 	      (p_api_version       =>   1.0
1263 	       ,p_validation_level =>  fnd_api.g_valid_level_none
1264 	       ,p_lpn_id           =>   l_asn_lpn_id
1265 	       ,p_operation        =>   2 -- UNPACK
1266 	       ,p_organization_id  =>   l_org_id
1267 	       ,p_content_item_id  =>   l_item_id
1268 	       ,p_revision         =>   l_revision
1269 	       ,p_lot_number       =>   l_lot_numbers(i)
1270 	       ,p_from_serial_number => l_serial_numbers(i)
1271 	       ,p_to_serial_number =>   l_serial_numbers(i)
1272 	       ,p_uom              =>   l_prim_uom_code
1273 	       ,p_commit           =>   fnd_api.g_true --??
1274 	       ,x_return_status    =>   x_return_status
1275 	       ,x_msg_count        =>   x_msg_count
1276 	       ,x_msg_data         =>   x_msg_data
1277 	       );
1278 	    IF (x_return_status <> g_ret_sts_success) THEN
1279 	       IF (l_debug = 1) THEN
1280 		  print_debug('CANCEL_ASN: packunpack failed, but continue anyway', 1);
1281 	       END IF;
1282 	    END IF;
1283 	 END LOOP;
1284 
1285 	 IF (l_serial_numbers.COUNT = 0) THEN
1286 	    l_progress := 'WMSINB-11052';
1287 	    BEGIN
1288 	       SELECT uom_code
1289 		 into l_uom_code
1290 		 FROM mtl_item_uoms_view
1291 		 WHERE organization_id = l_org_id
1292 		 AND inventory_item_id = l_item_id
1293 		 AND unit_of_measure = l_unit_of_measure;
1294 	    EXCEPTION
1295 	       WHEN OTHERS THEN
1296 		  IF (l_debug = 1) THEN
1297 		     print_debug('CANCEL_ASN: Error retrieving uom_code', 1);
1298 		  END IF;
1299 		  l_progress := 'WMSINB-11065';
1300 		  RAISE fnd_api.g_exc_error;
1301 	    END;
1302 
1303 	    l_progress := 'WMSINB-11068';
1304 	    IF (l_debug = 1) THEN
1305 	       print_debug('CANCEL_ASN: Serial controlled, but no serial '
1306 			   || 'Calling pup ',1);
1307 	    END IF;
1308 
1309 	    wms_container_pvt.packunpack_container
1310 	      (p_api_version       =>   1.0
1311 	       ,p_validation_level =>  fnd_api.g_valid_level_none
1312 	       ,p_lpn_id           =>   l_asn_lpn_id
1313 	       ,p_operation        =>   2 -- UNPACK
1314 	       ,p_organization_id  =>   l_org_id
1315 	       ,p_content_item_id  =>   l_item_id
1316 	       ,p_revision         =>   l_revision
1317 	       ,p_quantity         =>   l_quantity_to_unpack
1318 	       ,p_uom              =>   l_uom_code
1319 	       ,p_commit           =>   fnd_api.g_true --??
1320 	       ,x_return_status    =>   x_return_status
1321 	       ,x_msg_count        =>   x_msg_count
1322 	       ,x_msg_data         =>   x_msg_data
1323 	       );
1324 	    IF (x_return_status <> g_ret_sts_success) THEN
1325 	       IF (l_debug = 1) THEN
1326 		  print_debug('CANCEL_ASN: packunpack failed, but continue anyway', 1);
1327 	       END IF;
1328 	    END IF;
1329 	 END IF;
1330        ELSIF (l_lot_control_code = 2) THEN
1331 	    l_progress := 'WMSINB-11096';
1332 	    IF (l_debug = 1) THEN
1333 	       print_debug('CANCEL_ASN: Item is lot controlled',1);
1334 	    END IF;
1335 
1336 	    BEGIN
1337 	       SELECT
1338 		 lot_num
1339 		 ,SUM(quantity)
1340                   -- OPMConvergence
1341 		 ,SUM(secondary_quantity)
1342                   -- OPMConvergence
1343 		 bulk collect INTO
1344 		 l_lot_numbers
1345 		 ,l_quantitys
1346                   -- OPMConvergence
1347                  ,l_sec_lot_qty
1348                   -- OPMConvergence
1349 		 FROM
1350 		 rcv_lots_supply
1351 		 WHERE
1352 		 shipment_line_id = p_shipment_line_id
1353 		 AND supply_type_code = 'SHIPMENT'
1354 		 GROUP BY lot_num;
1355 	    EXCEPTION
1356 	       WHEN OTHERS THEN
1357 		  IF (l_debug = 1) THEN
1358 		     print_debug('CANCEL_ASN: Error retrieving lot numbers'
1359 				 ,1);
1360 		  END IF;
1361 	    END;
1362 
1363 	    l_progress := 'WMSINB-11121';
1364 
1365 	    FOR i IN 1 .. l_lot_numbers.COUNT LOOP
1366 	       wms_container_pvt.packunpack_container
1367 		 (p_api_version       =>   1.0
1368 		  ,p_validation_level =>  fnd_api.g_valid_level_none
1369 		  ,p_lpn_id           =>   l_asn_lpn_Id
1370 		  ,p_operation        =>   2 -- UNPACK
1371 		  ,p_organization_id  =>   l_org_id
1372 		  ,p_content_item_id  =>   l_item_id
1373 		  ,p_revision         =>   l_revision
1374 		  ,p_lot_number       =>   l_lot_numbers(i)
1375 		  ,p_quantity         =>   l_quantitys(i)
1376 		  ,p_uom              =>   l_prim_uom_code
1377 		  ,p_commit           =>   fnd_api.g_true
1378 		  ,x_return_status    =>   x_return_status
1379 		  ,x_msg_count        =>   x_msg_count
1380 		  ,x_msg_data         =>   x_msg_data
1381                    -- OPMConvergence
1382                   ,p_sec_uom          =>   l_sec_uom_code
1383                   ,p_sec_quantity     =>   l_sec_lot_qty(i)
1384                    -- OPMConvergence
1385 		  );
1386 	       IF (x_return_status <> g_ret_sts_success) THEN
1387 		  IF (l_debug = 1) THEN
1388 		     print_debug('CANCEL_ASN: packunpack failed, but continue anyway', 1);
1389 		  END IF;
1390 	       END IF;
1391 	    END LOOP;
1392 
1393 	    IF (l_lot_numbers.COUNT = 0) THEN
1394 	       l_progress := 'WMSINB-11148';
1395 	       BEGIN
1396 		  SELECT uom_code
1397 		    into l_uom_code
1398 		    FROM mtl_item_uoms_view
1399 		    WHERE organization_id = l_org_id
1400 		    AND inventory_item_id = l_item_id
1401 		    AND unit_of_measure = l_unit_of_measure;
1402 	       EXCEPTION
1403 		  WHEN OTHERS THEN
1404 		     IF (l_debug = 1) THEN
1405 			print_debug('CANCEL_ASN: Error retrieving uom_code', 1);
1406 		     END IF;
1407 		     l_progress := 'WMSINB-11161';
1408 		     RAISE fnd_api.g_exc_error;
1409 	       END;
1410 
1411                -- OPMConvergence
1412           IF l_sec_unit_of_measure IS NOT NULL THEN
1413 
1414 	          BEGIN
1415 	             SELECT uom_code
1416 		          INTO   l_sec_uom_code_2
1417 		          FROM   mtl_item_uoms_view
1418 		          WHERE  organization_id = l_org_id
1419 		          AND    inventory_item_id = l_item_id
1420 		          AND    unit_of_measure = l_sec_unit_of_measure;
1421 	          EXCEPTION
1422 	             WHEN OTHERS THEN
1423 		            IF (l_debug = 1) THEN
1424 		               print_debug('CANCEL_ASN: Error retrieving sec_uom_code'||sqlerrm, 1);
1425 		            END IF;
1426 		          l_progress := 'WMSINB-11161';
1427 		          RAISE fnd_api.g_exc_error;
1428 	          END;
1429 
1430           END IF;
1431                -- OPMConvergence
1432 
1433 	       l_progress := 'WMSINB-11164';
1434 	       IF (l_debug =1 ) THEN
1435 		  print_debug('CANCEL_ASN: Lot controlled, but no lot row',1);
1436 	       END IF;
1437 
1438 	       wms_container_pvt.packunpack_container
1439 		 (p_api_version       =>   1.0
1440 		  ,p_validation_level =>  fnd_api.g_valid_level_none
1441 		  ,p_lpn_id           =>   l_asn_lpn_id
1442 		  ,p_operation        =>   2 -- UNPACK
1443 		  ,p_organization_id  =>   l_org_id
1444 		  ,p_content_item_id  =>   l_item_id
1445 		  ,p_revision         =>   l_revision
1446 		  ,p_quantity         =>   l_quantity_to_unpack
1447 		  ,p_uom              =>   l_uom_code
1448 		  ,p_commit           =>   fnd_api.g_true --??
1449 		  ,x_return_status    =>   x_return_status
1450 		  ,x_msg_count        =>   x_msg_count
1451 		  ,x_msg_data         =>   x_msg_data
1452                   -- OPMConvergence
1453 		  ,p_sec_quantity     =>   l_sec_quantity_to_unpack
1454 		  ,p_sec_uom          =>   l_sec_uom_code_2
1455                   -- OPMConvergence
1456 		  );
1457 	       IF (x_return_status <> g_ret_sts_success) THEN
1458 		  IF (l_debug = 1) THEN
1459 		     print_debug('CANCEL_ASN: packunpack failed, but continue anyway', 1);
1460 		  END IF;
1461 	       END IF;
1462 	    END IF;
1463 
1464        ELSE -- neither lot/serial controlled
1465 	       IF (l_debug = 1) THEN
1466 		  print_debug('CANCEL_ASN: Item is neither lot or serial controlled',
1467 			      1);
1468 	       END IF;
1469 
1470 	       l_progress := 'WMSINB-11197';
1471 
1472 	       BEGIN
1473 		  SELECT uom_code
1474 		    into l_uom_code
1475 		    FROM mtl_item_uoms_view
1476 		    WHERE organization_id = l_org_id
1477 		    AND inventory_item_id = l_item_id
1478 		    AND unit_of_measure = l_unit_of_measure;
1479 	       EXCEPTION
1480 		  WHEN OTHERS THEN
1481 		     IF (l_debug = 1) THEN
1482 			print_debug('CANCEL_ASN: Error retrieving uom_code', 1);
1483 		     END IF;
1484 		     l_progress := 'WMSINB-11211';
1485 		     RAISE fnd_api.g_exc_error;
1486 	       END;
1487 
1488                -- OPMConvergence
1489           IF l_sec_unit_of_measure IS NOT NULL THEN
1490 
1491 	          BEGIN
1492 	             SELECT uom_code
1493 		          INTO   l_sec_uom_code_2
1494 		          FROM   mtl_item_uoms_view
1495 		          WHERE  organization_id = l_org_id
1496 		          AND    inventory_item_id = l_item_id
1497 		          AND    unit_of_measure = l_sec_unit_of_measure;
1498 	          EXCEPTION
1499 	             WHEN OTHERS THEN
1500 		          IF (l_debug = 1) THEN
1501 		            print_debug('CANCEL_ASN: Error retrieving sec_uom_code'||sqlerrm, 1);
1502 		          END IF;
1503 		          l_progress := 'WMSINB-11211';
1504 		          RAISE fnd_api.g_exc_error;
1505 	          END;
1506 
1507           END IF;
1508                -- OPMConvergence
1509            l_quantity_to_unpack := p_primary_quantity - l_quantity_received;
1510 	       l_progress := 'WMSINB-11215';
1511 
1512 	       wms_container_pvt.packunpack_container
1513 		 (p_api_version       =>   1.0
1514 		  ,p_validation_level =>  fnd_api.g_valid_level_none
1515 		  ,p_lpn_id           =>   l_asn_lpn_id
1516 		  ,p_operation        =>   2 -- UNPACK
1517 		  ,p_organization_id  =>   l_org_id
1518 		  ,p_content_item_id  =>   l_item_id
1519 		  ,p_revision         =>   l_revision
1520 		  ,p_quantity         =>   l_quantity_to_unpack
1521 		  ,p_uom              =>   l_uom_code
1522 		  ,p_commit           =>   fnd_api.g_true --??
1523 		  ,x_return_status    =>   x_return_status
1524 		  ,x_msg_count        =>   x_msg_count
1525 		  ,x_msg_data         =>   x_msg_data
1526                   -- OPMConvergence
1527 		  ,p_sec_quantity     =>   l_sec_quantity_to_unpack
1528 		  ,p_sec_uom          =>   l_sec_uom_code_2
1529                   -- OPMConvergence
1530 		  );
1531 	       IF (x_return_status <> g_ret_sts_success) THEN
1532 		  IF (l_debug = 1) THEN
1533 		     print_debug('CANCEL_ASN: packunpack failed, but continue anyway', 1);
1534 		  END IF;
1535 	       END IF;
1536       END IF; -- end if l_serial_control in ( 2, 5)
1537    END IF;  -- end if (l_lpn_context = 7)
1538 
1539    IF (l_debug = 1) THEN
1540       print_debug('CANCEL_ASN: CALLING RSV API',1);
1541       print_debug('l_org_id               => '||l_org_id,1);
1542       print_debug('l_item_id              => '||l_item_id,1);
1543       print_debug('l_revision             => '||l_revision,1);
1544       print_debug('l_primary_uom          => '||l_prim_uom_code,1);
1545       print_debug('l_po_header_id         => '||l_po_header_id,1);
1546       print_debug('l_po_line_location_id  => '||l_po_line_location_id,1);
1547       print_debug('p_shipment_line_id     => '||p_shipment_line_id,1);
1548    END IF;
1549 
1550    l_mol_res_in(1).transaction_type       := 'CANCEL';
1551    l_mol_res_in(1).organization_id        := l_org_id;
1552    l_mol_res_in(1).inventory_item_id      := l_item_id;
1553    l_mol_res_in(1).item_revision          := l_revision;
1554    l_mol_res_in(1).primary_uom_code       := l_prim_uom_code;
1555    l_mol_res_in(1).po_header_id           := l_po_header_id;
1556    l_mol_res_in(1).po_line_location_id    := l_po_line_location_id;
1557    l_mol_res_in(1).shipment_line_id       := p_shipment_line_id;
1558 
1559    INV_RCV_RESERVATION_UTIL.maintain_reservations
1560      (x_return_status => x_return_status
1561       ,x_msg_count     => x_msg_count
1562       ,x_msg_data      => x_msg_data
1563       ,x_mol_tb        => l_mol_res_out
1564       ,p_cas_mol_tb    => l_mol_res_in
1565       );
1566 
1567    IF (l_debug = 1) THEN
1568       print_debug('CANCEL_ASN - rsv api returns:'||x_return_status,1);
1569    END IF;
1570 
1571    IF (x_return_status <> g_ret_sts_success) THEN
1572       l_progress := 'WMSINB-14998';
1573       RAISE FND_API.G_EXC_ERROR;
1574    END IF;
1575 
1576    /* ******************************************************
1577      BUG 6708102 by kagupta
1578 
1579      Description: Following code added to handle the proper
1580                   deletion of the serials and lots
1581                   from rcv and updation of msn.
1582     *******************************************************
1583    */
1584   IF (l_debug = 1) THEN
1585      l_progress := 'WMSINB-14999';
1586      print_debug('CANCEL_ASN - serial/lot updation:'||l_progress,1);
1587   END IF;
1588 
1589    SELECT Count(*)
1590    INTO l_serials_count
1591    FROM rcv_serials_supply
1592    WHERE shipment_line_id = p_shipment_line_id
1593    AND supply_type_code = 'SHIPMENT';
1594 
1595    SELECT Count(*)
1596    INTO l_lots_count
1597    FROM rcv_lots_supply
1598    WHERE shipment_line_id = p_shipment_line_id
1599    AND supply_type_code = 'SHIPMENT';
1600 
1601    IF (l_debug = 1) THEN
1602        l_progress := 'WMSINB-15000';
1603        print_debug('CANCEL_ASN - serial/lot updation:'||l_progress,1);
1604    END IF;
1605 
1606    IF l_serials_count > 0  THEN
1607 
1608     UPDATE mtl_serial_numbers
1609     SET current_status  = 1,
1610     group_mark_id = NULL,
1611     line_mark_id = NULL,
1612     lot_line_mark_id = NULL
1613     WHERE inventory_item_id = l_item_id
1614     AND current_organization_id = l_org_id
1615     AND serial_number IN (SELECT serial_number
1616                           FROM rcv_serials_supply
1617                           WHERE shipment_line_id = p_shipment_line_id
1618                           AND supply_type_code = 'SHIPMENT')
1619     AND current_status = 5;
1620 
1621 
1622     DELETE FROM rcv_serials_supply
1623     WHERE shipment_line_id = p_shipment_line_id
1624     AND supply_type_code = 'SHIPMENT';
1625    END IF;
1626 
1627     IF (l_debug = 1) THEN
1628         l_progress := 'WMSINB-15001';
1629         print_debug('CANCEL_ASN - serial/lot updation:'||l_progress,1);
1630     END IF;
1631 
1632    IF l_lots_count > 0  THEN
1633 
1634     DELETE FROM rcv_lots_supply
1635     WHERE shipment_line_id = p_shipment_line_id
1636     AND supply_type_code = 'SHIPMENT';
1637 
1638    END IF;
1639 
1640    IF (l_debug = 1) THEN
1641        l_progress := 'WMSINB-15002';
1642        print_debug('CANCEL_ASN - serial/lot updation:'||l_progress,1);
1643    END IF;
1644    /* ****************BUG 6708071 ENDS ********************/
1645 
1646    IF (l_debug = 1) THEN
1647       print_debug('CANCEL_ASN: Exiting cancel_asn',1);
1648    END IF;
1649 
1650 EXCEPTION
1651    WHEN OTHERS THEN
1652       IF (l_debug = 1) THEN
1653 	 print_debug('CANCEL_ASN: Exception ocurred after l_progress = ' ||
1654 		     l_progress,1);
1655       END IF;
1656       fnd_message.set_name('INV', 'INV_CANCEL_ASN_FAIL');
1657       fnd_msg_pub.ADD;
1658       ROLLBACK TO cancel_asn_pub;
1659       --	fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data =>
1660       --				  x_msg_data);
1661       x_return_status  := g_ret_sts_unexp_error;
1662 END cancel_asn;
1663 
1664 --
1665 -- This Procedue Packs Marterial into LPN
1666 -- IF ( l_lot_control_code > 1 AND l_serial_control_code <> 1 ) THEN -- CASE FOR LOT/SERIAL CONTROLLED
1667 -- Elsif ( l_lot_control_code > 1 and l_serial_control_code <> 1)  THEN -- CASE FOR LOT CONTROLLED ONLY
1668 -- Elsif (l_lot_control_code =1 and l_serial_control_code <> 1 ) -- CASE FOR SERIAL CONTROLLED ONLY
1669 -- ELse -- CASE FOR VANILA ITEM
1670 -- End if;
1671 
1672 Procedure PackUnpack_wrapper( x_return_status               OUT NOCOPY VARCHAR2
1673 			      ,x_msg_count                   OUT NOCOPY NUMBER
1674 			      ,x_msg_data                    OUT NOCOPY VARCHAR2
1675 			      ,p_lot_control_code            IN NUMBER default NULL
1676 			      ,p_serial_control_code         IN NUMBER default NULL
1677 			      ,p_product_txn_id              IN NUMBER
1678 			      ,p_product_code                IN VARCHAR2
1679 			      ,p_lpn_id                      IN NUMBER
1680 			      ,p_content_lpn_id              IN NUMBER
1681 			      ,p_content_item_id             IN NUMBER
1682 			      ,p_content_item_desc           IN VARCHAR2
1683 			      ,p_revision                    IN VARCHAR2
1684 			      ,p_primary_quantity            IN NUMBER
1685 			      ,p_primary_uom                 IN VARCHAR2
1686 			      ,p_organization_id             IN NUMBER
1687 			      ,p_operation                   IN NUMBER default 1
1688 			      ,p_cost_group_id               IN NUMBER
1689 			      ,p_source_type_id              IN NUMBER
1690 			      ,p_source_header_id            IN NUMBER
1691                               ,p_source_name                 IN VARCHAR2
1692                               ,p_source_line_id              IN NUMBER
1693                               ,p_source_line_detail_id       IN NUMBER
1694                               ,p_auto_unnest_empty_lpns      IN NUMBER DEFAULT 1
1695                                -- OPMConvergence
1696                               ,p_sec_quantity                IN NUMBER DEFAULT NULL
1697                               ,p_sec_uom                     IN VARCHAR2 DEFAULT NULL
1698                                -- OPMConvergence
1699                                -- R12
1700                               ,p_txn_quantity                IN NUMBER DEFAULT NULL
1701                               ,p_txn_uom_code                IN VARCHAR2 DEFAULT NULL
1702                               ) is
1703      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1704      l_progress VARCHAR2(15) := '10';
1705 
1706      l_total_lot_qty    NUMBER := 0;
1707      l_total_ser_qty NUMBER := 0;
1708 
1709      l_procedure_name VARCHAR2(30) := 'PACKUNPACK_WRAPPER';
1710 
1711 BEGIN
1712 
1713    -- Initialize API return status to success
1714 
1715    x_return_status  := g_ret_sts_success;
1716 
1717    l_progress := 'WMSINB-11301';
1718 
1719    -- GET the TOTAL LOT QTY
1720    if p_lot_control_code > 1 then
1721 BEGIN
1722    l_progress := 'WMSINB-11306';
1723    SELECT Nvl(SUM(transaction_quantity),0)
1724      INTO l_total_lot_qty
1725      FROM mtl_transaction_lots_temp
1726      WHERE product_code = p_product_code
1727      AND product_transaction_id = p_product_txn_id;
1728 END;
1729    End if;
1730 
1731    IF (l_debug = 1) THEN
1732       print_debug('PACKUNPACK_WRAPPER - Lot Control code:'||p_lot_control_code,1);
1733       print_debug('PACKUNPACK_WRAPPER - Total Lot Qty:'||l_total_lot_qty,1);
1734    END IF;
1735 
1736    -- GET the TOTAL SERIAL QTY
1737 
1738    if nvl(p_serial_control_code,1) <> 1 then
1739       BEGIN
1740 	 l_progress := 'WMSINB-11324';
1741 	 SELECT Nvl(SUM(inv_serial_number_pub.get_serial_diff(fm_serial_number,to_serial_number)),0)
1742 	   INTO l_total_ser_qty
1743 	   FROM mtl_serial_numbers_temp
1744 	   WHERE product_code = p_product_code
1745 	   AND product_transaction_id = p_product_txn_id;
1746       END;
1747    End if;
1748 
1749    IF (l_debug = 1) THEN
1750       print_debug('PACKUNPACK_WRAPPER - Serial Control code:'||p_serial_control_code,1);
1751       print_debug('PACKUNPACK_WRAPPER - Total Serial Qty:'||l_total_ser_qty,1);
1752    END IF;
1753 
1754    IF ( p_lot_control_code > 1 and l_total_lot_qty > 0 ) then
1755       l_progress := 'WMSINB-11339';
1756       if ( nvl(p_serial_control_code,1) <> 1 and l_total_ser_qty > 0 ) then -- CASE FOR BOTH LOT and SERIAL CONTROLLED ITEM
1757 	 -- Loop Through MTLT MSNT and INSERT
1758 	 l_progress := 'WMSINB-11342';
1759 	 For l_lot_rec in ( select Ltrim(Rtrim(lot_number)) lot_number
1760 			    , primary_quantity
1761 			    , serial_transaction_temp_id
1762 			    from mtl_transaction_lots_temp mtlt
1763 			    where mtlt.product_transaction_id = p_product_txn_id
1764 			    and mtlt.product_code = 'RCV'
1765 			    )
1766 	   Loop
1767 	      l_progress := 'WMSINB-11351';
1768 	      For l_serial_rec in ( select fm_serial_number
1769 				    , to_serial_number
1770 				    , inv_serial_number_pub.get_serial_diff(fm_serial_number,to_serial_number) serial_quantity
1771 				    from mtl_serial_numbers_temp msnt
1772 				    where msnt.transaction_temp_id = l_lot_rec.serial_transaction_temp_id
1773 				    and msnt.product_transaction_id = p_product_txn_id
1774 				    and msnt.product_code = 'RCV'
1775 				    )
1776 		Loop
1777 		   l_progress := 'WMSINB-11361';
1778 		   wms_container_pvt.packunpack_container(p_api_version  => 1.0
1779 							  ,x_return_status               => x_return_status
1780 							  ,x_msg_count                   => x_msg_count
1781 							  ,x_msg_data                    => x_msg_data
1782 							  ,p_lpn_id                      => p_lpn_id
1783 							  ,p_content_lpn_id              => p_content_lpn_id
1784 							  ,p_content_item_id             => p_content_item_id
1785 							  ,p_content_item_desc           => p_content_item_desc
1786 							  ,p_revision                    => p_revision
1787 							  ,p_lot_number                  => l_lot_rec.lot_number
1788 							  ,p_from_serial_number          => l_serial_rec.fm_serial_number
1789 							  ,p_to_serial_number            => l_serial_rec.to_serial_number
1790 							  ,p_quantity                    => l_serial_rec.serial_quantity
1791 							  ,p_uom                         => p_primary_uom
1792 							  ,p_organization_id             => p_organization_id
1793 							  ,p_subinventory                => null
1794 							  ,p_locator_id                  => null
1795 							  ,p_enforce_wv_constraints      => null
1796 		     ,p_operation                   => p_operation
1797 		     ,p_cost_group_id               => p_cost_group_id
1798 		     ,p_source_type_id              => p_source_type_id
1799 		     ,p_source_header_id            => p_source_header_id
1800 		     ,p_source_name                 => p_source_name
1801 		     ,p_source_line_id              => p_source_line_id
1802 		     ,p_source_line_detail_id       => p_source_line_detail_id
1803 		     ,p_validation_level            => fnd_api.g_valid_level_none
1804    --Bug #3457106    ,p_concurrent_pack             => 1
1805 		     ,p_auto_unnest_empty_lpns => p_auto_unnest_empty_lpns);
1806 
1807 		   l_progress := 'WMSINB-11390';
1808 
1809 		   if x_return_status <> G_RET_STS_SUCCESS Then
1810 		      -- MSG no new message just add the one on stack
1811 		      -- Check the Error Status from this call
1812 		      l_progress := 'WMSINB-11395';
1813 		      RAISE FND_API.G_EXC_ERROR;
1814 		   End if;
1815 
1816 		End Loop;
1817 	   End Loop;
1818 
1819        else -- CASE FOR JUST LOT CONTROLLED ITEM
1820 	 -- Loop Through MTLT And INSERT
1821 	 l_progress := 'WMSINB-11404';
1822 	 For l_lot_rec in ( select Ltrim(Rtrim(lot_number)) lot_number
1823 			    , primary_quantity
1824                             -- R12
1825                             , transaction_quantity
1826                             -- R12
1827                             -- OPMConvergence
1828                             , secondary_quantity
1829                              -- OPMConvergence
1830 			    from mtl_transaction_lots_temp mtlt
1831 			    where mtlt.product_transaction_id = p_product_txn_id
1832 			    and mtlt.product_code = 'RCV'
1833 			    )
1834 	   Loop
1835 	      l_progress := 'WMSINB-11412';
1836 	      wms_container_pvt.packunpack_container(p_api_version  => 1.0
1837 						     ,x_return_status               => x_return_status
1838 						     ,x_msg_count                   => x_msg_count
1839 						     ,x_msg_data                    => x_msg_data
1840 						     ,p_lpn_id                      => p_lpn_id
1841 						     ,p_content_lpn_id              => p_content_lpn_id
1842 						     ,p_content_item_id             => p_content_item_id
1843 						     ,p_content_item_desc           => p_content_item_desc
1844 						     ,p_revision                    => p_revision
1845 						     ,p_lot_number                  => l_lot_rec.lot_number
1846 						     ,p_from_serial_number          => null
1847 						     ,p_to_serial_number            => null
1848 						     ,p_quantity                    => l_lot_rec.transaction_quantity
1849                                                                                        -- l_lot_rec.primary_quantity --*R12*--
1850 						     ,p_uom                         => p_txn_uom_code
1851                                                                                        -- p_primary_uom --*R12*--
1852 						     ,p_organization_id             => p_organization_id
1853 						     ,p_subinventory                => null
1854 						     ,p_locator_id                  => null
1855 						     ,p_enforce_wv_constraints      => null
1856 		                                     ,p_operation                   => p_operation
1857 		                                     ,p_cost_group_id               => p_cost_group_id
1858 		                                     ,p_source_type_id              => p_source_type_id
1859 		                                     ,p_source_header_id            => p_source_header_id
1860 		                                     ,p_source_name                 => p_source_name
1861 		                                     ,p_source_line_id              => p_source_line_id
1862 		                                     ,p_source_line_detail_id       => p_source_line_detail_id
1863 		                                     ,p_validation_level            => fnd_api.g_valid_level_none
1864                                       --Bug #3457106 ,p_concurrent_pack             => 1
1865 		                                     ,p_auto_unnest_empty_lpns => p_auto_unnest_empty_lpns
1866                                                      -- OPMConvergence
1867                                                      ,p_sec_quantity                => l_lot_rec.secondary_quantity
1868                                                      ,p_sec_uom                     => p_sec_uom
1869                                                      -- OPMConvergence
1870                 );
1871 
1872 	      if x_return_status <> G_RET_STS_SUCCESS Then
1873 		 -- MSG no new message just add the one on stack
1874 		 -- Check the Error Status from this call
1875 		 l_progress := 'WMSINB-11444';
1876 		 RAISE FND_API.G_EXC_ERROR;
1877 	      End if;
1878 
1879 	   End Loop;
1880       End if;
1881     Elsif ( (nvl(p_lot_control_code,1) = 1 and
1882 	     nvl(p_serial_control_code,1) <> 1) and l_total_ser_qty > 0 )  then -- CASE FOR SERIAL CONTROLLED ITEM
1883 
1884       l_progress := 'WMSINB-11453';
1885       For l_serial_rec in ( select fm_serial_number
1886 			    ,to_serial_number
1887 			    ,inv_serial_number_pub.get_serial_diff(fm_serial_number,to_serial_number) serial_quantity
1888 			    from mtl_serial_numbers_temp msnt
1889 			    where msnt.product_transaction_id = p_product_txn_id
1890 			    and msnt.product_code = 'RCV'
1891 			    )
1892 	Loop
1893 	   -- Calculate the Quantity
1894 	   IF (l_debug = 1) THEN
1895 	      print_debug('PACKUNPACK_WRAPPER: packing fm serial :'||l_serial_rec.fm_serial_number,1);
1896 	      print_debug('PACKUNPACK_WRAPPER: packing to serial :'||l_serial_rec.to_serial_number,1);
1897 	   END IF;
1898 
1899 	   l_progress := 'WMSINB-11464';
1900 
1901 	   wms_container_pvt.packunpack_container(p_api_version                 => 1.0
1902 						  ,x_return_status               => x_return_status
1903 						  ,x_msg_count                   => x_msg_count
1904 						  ,x_msg_data                    => x_msg_data
1905 						  ,p_lpn_id                      => p_lpn_id
1906 						  ,p_content_lpn_id              => p_content_lpn_id
1907 						  ,p_content_item_id             => p_content_item_id
1908 						  ,p_content_item_desc           => p_content_item_desc
1909 						  ,p_revision                    => p_revision
1910 						  ,p_lot_number                  => null
1911 						  ,p_from_serial_number          => l_serial_rec.fm_serial_number
1912 						  ,p_to_serial_number            => l_serial_rec.to_serial_number
1913 						  ,p_quantity                    => l_serial_rec.serial_quantity
1914 						  ,p_uom                         => p_primary_uom
1915 						  ,p_organization_id             => p_organization_id
1916 						  ,p_subinventory                => null
1917 						  ,p_locator_id                  => null
1918 						  ,p_enforce_wv_constraints      => null
1919 	     ,p_operation                   => p_operation
1920 	     ,p_cost_group_id               => p_cost_group_id
1921 	     ,p_source_type_id              => p_source_type_id
1922 	     ,p_source_header_id            => p_source_header_id
1923 	     ,p_source_name                 => p_source_name
1924 	     ,p_source_line_id              => p_source_line_id
1925 	     ,p_source_line_detail_id       => p_source_line_detail_id
1926 	     ,p_validation_level            => fnd_api.g_valid_level_none
1927 --Bug#3457106,p_concurrent_pack             => 1
1928 	     ,p_auto_unnest_empty_lpns => p_auto_unnest_empty_lpns);
1929 
1930 	   if x_return_status <> G_RET_STS_SUCCESS Then
1931 	      -- MSG no new message just add the one on stack
1932 	      -- Check the Error Status from this call
1933 	      l_progress := 'WMSINB-11497';
1934 	      RAISE FND_API.G_EXC_ERROR;
1935 	   End if;
1936 
1937 	End Loop;
1938     Else -- CASE FOR VANILA ITEM
1939       -- Call container PUb PACkUNPACK
1940 
1941       l_progress := 'WMSINB-11505';
1942 
1943       wms_container_pvt.packunpack_container(p_api_version                 => 1.0
1944 					     ,x_return_status               => x_return_status
1945 					     ,x_msg_count                   => x_msg_count
1946 					     ,x_msg_data                    => x_msg_data
1947 					     ,p_lpn_id                      => p_lpn_id
1948 					     ,p_content_lpn_id              => p_content_lpn_id
1949 					     ,p_content_item_id             => p_content_item_id
1950 					     ,p_content_item_desc           => p_content_item_desc
1951 					     ,p_revision                    => p_revision
1952 					     ,p_lot_number                  => null
1953 					     ,p_from_serial_number          => null
1954 					     ,p_to_serial_number            => null
1955 					     ,p_quantity                    => p_txn_quantity
1956                                                                                -- p_primary_quantity -- *R12* --
1957 					     ,p_uom                         => p_txn_uom_code
1958                                                                                -- p_primary_uom --*R12* --
1959 					     ,p_organization_id             => p_organization_id
1960 					     ,p_subinventory                => null
1961 					     ,p_locator_id                  => null
1962 					     ,p_enforce_wv_constraints      => null
1963 					     ,p_operation                   => p_operation
1964 	                                     ,p_cost_group_id               => p_cost_group_id
1965 	                                     ,p_source_type_id              => p_source_type_id
1966 	                                     ,p_source_header_id            => p_source_header_id
1967 	                                     ,p_source_name                 => p_source_name
1968 	                                     ,p_source_line_id              => p_source_line_id
1969 	                                     ,p_source_line_detail_id       => p_source_line_detail_id
1970 	                                     ,p_validation_level            => fnd_api.g_valid_level_none
1971                                      --Bug #3457106	,p_concurrent_pack             => 1
1972 	                                     ,p_auto_unnest_empty_lpns => p_auto_unnest_empty_lpns
1973                                              -- OPMConvergence
1974                                              ,p_sec_quantity                => p_sec_quantity
1975                                              ,p_sec_uom                     => p_sec_uom
1976                                              -- OPMConvergence
1977                                              );
1978 
1979       IF (l_debug = 1) THEN
1980 	 print_debug('PACKUNPACK_WRAPPER: x_return_status:'||x_return_status,1);
1981       END IF;
1982 
1983       if x_return_status <> G_RET_STS_SUCCESS Then
1984 	 -- MSG no new message just add the one on stack
1985 	 -- Check the Error Status from this call
1986 	 l_progress := 'WMSINB-11542';
1987 	 RAISE FND_API.G_EXC_ERROR;
1988       End if;
1989 
1990    End if;
1991 
1992 EXCEPTION
1993 
1994    when fnd_api.g_exc_error THEN
1995       x_return_status  := g_ret_sts_error;
1996 
1997       IF (l_debug = 1) THEN
1998 	 print_debug('PACKUNPACK_WRAPPER : - Error :'|| l_progress ,1);
1999       END IF;
2000 
2001    WHEN OTHERS THEN
2002       x_return_status  := g_ret_sts_unexp_error;
2003 
2004       IF (l_debug = 1) THEN
2005          print_debug('PACKUNPACK_WRAPPER : - OTHER Exception:'|| l_progress || ' ' ||
2006 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
2007       END IF;
2008 
2009 End PackUnpack_wrapper;
2010 
2011 
2012 
2013 -- Description
2014 -- This just returns the LPN_ID for the License_plate_number passed
2015 -- if the license_plate_number exists in the system
2016 Function get_lpn_id(x_lpn_id               IN OUT NOCOPY NUMBER ,
2017 		    x_license_plate_number IN OUT NOCOPY VARCHAR2 ,
2018 		    x_lpn_context          OUT NOCOPY NUMBER,
2019 		    x_parent_lpn_id        OUT NOCOPY NUMBER,
2020 		    x_source_header_id     OUT nocopy NUMBER) return boolean
2021   is
2022 BEGIN
2023 
2024    -- print_debug('get LPN ID: 10 ', 1);
2025 
2026    -- Bug 4507808
2027    -- Performance Fix to get rid of NVLS
2028 
2029    if ( x_lpn_id is not null or x_license_plate_number is not null) then
2030       -- print_debug('get LPN ID: 20 ', 1);
2031       if ( x_lpn_id is not null and x_license_plate_number is not null) Then
2032          select lpn_id,
2033            license_plate_number,
2034            lpn_context,
2035            parent_lpn_id,
2036            source_header_id
2037            into x_lpn_id,
2038            x_license_plate_number,
2039            x_lpn_context,
2040            x_parent_lpn_id,
2041            x_source_header_id
2042            from wms_license_plate_numbers
2043            where lpn_id = x_lpn_id
2044            and license_plate_number = x_license_plate_number
2045            ;
2046          return TRUE;
2047       Elsif (x_lpn_id is not null and x_license_plate_number is null ) Then
2048          select lpn_id,
2049            license_plate_number,
2050            lpn_context,
2051            parent_lpn_id,
2052            source_header_id
2053            into x_lpn_id,
2054            x_license_plate_number,
2055            x_lpn_context,
2056            x_parent_lpn_id,
2057            x_source_header_id
2058            from wms_license_plate_numbers
2059            where lpn_id = x_lpn_id
2060            ;
2061          return TRUE;
2062       Elsif (x_lpn_id is null and x_license_plate_number is not null ) Then
2063          select lpn_id,
2064            license_plate_number,
2065            lpn_context,
2066            parent_lpn_id,
2067            source_header_id
2068            into x_lpn_id,
2069            x_license_plate_number,
2070            x_lpn_context,
2071            x_parent_lpn_id,
2072            x_source_header_id
2073            from wms_license_plate_numbers
2074            where license_plate_number = x_license_plate_number
2075            ;
2076          return TRUE;
2077       End if;
2078     else
2079       -- print_debug('get LPN ID: 30 ', 1);
2080       x_license_plate_number := null;
2081       x_lpn_id := to_number(null);
2082       x_lpn_context := to_number(null);
2083       x_parent_lpn_id := to_number(null);
2084       x_source_header_id := To_number(NULL);
2085       return TRUE;
2086    end if;
2087 EXCEPTION
2088    WHEN OTHERS THEN
2089       if x_lpn_id is not null then -- CASE WHERE LPN_ID is present and its an invalid ID
2090 	 --MSG WMS_CONT_INVALID_LPN
2091 	 -- print_debug('get LPN ID: Error =' || SQLCODE , 1);
2092 
2093 	 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
2094 	 fnd_msg_pub.ADD;
2095 
2096 	 x_lpn_context := to_number(null);
2097 	 x_parent_lpn_id := to_number(null);
2098 	 x_source_header_id := To_number(NULL);
2099 	 return FALSE;
2100        else -- MAY BE A CASE FOR NEW LPN
2101 	 x_lpn_context := to_number(null);
2102 	 x_parent_lpn_id := to_number(null);
2103 	 x_source_header_id := To_number(NULL);
2104 	 return TRUE;
2105       End if;
2106 END get_lpn_id;
2107 
2108 PROCEDURE modify_edi_xml_asn( p_group_id IN NUMBER
2109 			      ,x_return_status OUT nocopy VARCHAR2
2110 			      ,x_msg_count OUT nocopy NUMBER
2111 			      ,x_msg_data OUT nocopy VARCHAR2 )
2112   IS
2113 
2114      CURSOR rti_cur (l_grp_id NUMBER) IS
2115 	SELECT
2116 	  interface_transaction_id
2117 	  ,to_organization_id
2118 	  ,to_organization_code
2119 	  ,item_id
2120 	  ,item_num
2121 	  ,lpn_group_id
2122 	  ,quantity
2123 	  ,primary_quantity
2124 	  ,document_num
2125 	  FROM
2126 	  rcv_transactions_interface
2127 	  WHERE
2128 	  group_id = l_grp_id AND
2129 	  transaction_type = 'SHIP';
2130 
2131      CURSOR wlpnci_cur (l_intf_txn_id NUMBER) IS
2132 	SELECT
2133 	  wmslpnci.interface_transaction_id interface_transaction_id,
2134 	  wmslpn.lpn_id lpn_id,
2135 	  wmslpnci.license_plate_number license_plate_number,
2136 	  wmslpn.organization_id organization_id,
2137 	  wmslpnci.serial_transaction_intf_id,
2138 	  wmslpnci.lot_number lot_number,
2139 	  wmslpnci.quantity quantity,
2140 	  wmslpnci.uom_code uom_code,
2141 	  wmslpnci.expiration_date expiration_date,
2142 	  wmslpnci.status_id status_id,
2143 	  wmslpnci.item_description item_description,
2144 	  wmslpnci.vendor_item_num vendor_item_num,
2145 	  wmslpnci.supplier_lot_number supplier_lot_number,
2146 	  wmslpnci.origination_date origination_date,
2147 	  wmslpnci.date_code date_code,
2148 	  wmslpnci.grade_code grade_code,
2149 	  wmslpnci.change_date change_date,
2150 	  wmslpnci.maturity_date maturity_date,
2151 	  wmslpnci.retest_date retest_date,
2152 	  wmslpnci.age age,
2153 	  wmslpnci.item_size item_size,
2154 	  wmslpnci.color color,
2155 	  wmslpnci.volume volume,
2156 	  wmslpnci.place_of_origin place_of_origin,
2157 	  wmslpnci.best_by_date best_by_date,
2158 	  wmslpnci.length length,
2159 	  wmslpnci.length_uom_code length_uom_code,
2160 	  wmslpnci.recycled_content recycled_content,
2161 	  wmslpnci.thickness thickness,
2162 	  wmslpnci.thickness thickness_uom_code,
2163 	  wmslpnci.width width,
2164 	  wmslpnci.width_uom_code width_uom_code,
2165 	  wmslpnci.curl_wrinkle_fold curl_wrinkle_fold,
2166 	  wmslpnci.c_attribute1 c_attribute1,
2167 	  wmslpnci.c_attribute2 c_attribute2,
2168 	  wmslpnci.c_attribute3 c_attribute3,
2169 	  wmslpnci.c_attribute4 c_attribute4,
2170 	  wmslpnci.c_attribute5 c_attribute5,
2171 	  wmslpnci.c_attribute6 c_attribute6,
2172 	  wmslpnci.c_attribute7 c_attribute7,
2173 	  wmslpnci.c_attribute8 c_attribute8,
2174 	  wmslpnci.c_attribute9 c_attribute9,
2175 	  wmslpnci.c_attribute10 c_attribute10,
2176 	  wmslpnci.c_attribute11 c_attribute11,
2177 	  wmslpnci.c_attribute12 c_attribute12,
2178 	  wmslpnci.c_attribute13 c_attribute13,
2179 	  wmslpnci.c_attribute14 c_attribute14,
2180 	  wmslpnci.c_attribute15 c_attribute15,
2181 	  wmslpnci.c_attribute16 c_attribute16,
2182 	  wmslpnci.c_attribute17 c_attribute17,
2183 	  wmslpnci.c_attribute18 c_attribute18,
2184 	  wmslpnci.c_attribute19 c_attribute19,
2185 	  wmslpnci.c_attribute20 c_attribute20,
2186 	  wmslpnci.d_attribute1 d_attribute1,
2187 	  wmslpnci.d_attribute2 d_attribute2,
2188 	  wmslpnci.d_attribute3 d_attribute3,
2189 	  wmslpnci.d_attribute4 d_attribute4,
2190 	  wmslpnci.d_attribute5 d_attribute5,
2191 	  wmslpnci.d_attribute6 d_attribute6,
2192 	  wmslpnci.d_attribute7 d_attribute7,
2193 	  wmslpnci.d_attribute8 d_attribute8,
2194 	  wmslpnci.d_attribute9 d_attribute9,
2195 	  wmslpnci.d_attribute10 d_attribute10,
2196 	  wmslpnci.n_attribute1 n_attribute1,
2197 	  wmslpnci.n_attribute2 n_attribute2,
2198 	  wmslpnci.n_attribute3 n_attribute3,
2199 	  wmslpnci.n_attribute4 n_attribute4,
2200 	  wmslpnci.n_attribute5 n_attribute5,
2201 	  wmslpnci.n_attribute6 n_attribute6,
2202 	  wmslpnci.n_attribute7 n_attribute7,
2203 	  wmslpnci.n_attribute8 n_attribute8,
2204 	  wmslpnci.n_attribute9 n_attribute9,
2205 	  wmslpnci.n_attribute10 n_attribute10,
2206 	  wmslpnci.attribute_category attribute_category,
2207 	  wmslpnci.attribute1 attribute1,
2208 	  wmslpnci.attribute2 attribute2,
2209 	  wmslpnci.attribute3 attribute3,
2210 	  wmslpnci.attribute4 attribute4,
2211 	  wmslpnci.attribute5 attribute5,
2212 	  wmslpnci.attribute6 attribute6,
2213 	  wmslpnci.attribute7 attribute7,
2214 	  wmslpnci.attribute8 attribute8,
2215 	  wmslpnci.attribute9 attribute9,
2216 	  wmslpnci.attribute10 attribute10,
2217 	  wmslpnci.attribute11 attribute11,
2218 	  wmslpnci.attribute12 attribute12,
2219 	  wmslpnci.attribute13 attribute13,
2220 	  wmslpnci.attribute14 attribute14,
2221 	  wmslpnci.attribute15 attribute15
2222 	  FROM
2223 	  wms_lpn_contents_interface wmslpnci,
2224 	  wms_license_plate_numbers wmslpn
2225 	  WHERE
2226 	  wmslpnci.interface_transaction_id = l_intf_txn_id AND
2227 	  wmslpn.license_plate_number (+)= wmslpnci.license_plate_number;
2228 
2229      CURSOR msni_cur (l_intf_txn_id NUMBER) IS
2230 	SELECT
2231 	  fm_serial_number,
2232 	  to_serial_number
2233 	  FROM
2234 	  mtl_serial_numbers_interface
2235 	  WHERE l_intf_txn_id = transaction_interface_id;
2236 
2237      l_wlpnci_total_qty NUMBER;
2238      l_msni_total_qty NUMBER := 0;
2239      l_serial_qty NUMBER := 0;
2240      l_tmp_ser_txn_id NUMBER := NULL;
2241      l_serial_txn_intf_id NUMBER;
2242      l_txn_intf_id NUMBER;
2243      l_prim_qty NUMBER;
2244      l_exists NUMBER;
2245      l_prim_uom_code VARCHAR2(3);
2246 
2247      l_progress VARCHAR2(15) := '0';
2248      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2249 
2250      l_item_id number;
2251      l_to_organization_id number;
2252 
2253 BEGIN
2254 
2255    SAVEPOINT modify_edi_asn_pub;
2256 
2257    x_return_status := g_ret_sts_success;
2258 
2259    l_progress := 'WMSINB-11771';
2260 
2261    IF (l_debug = 1) THEN
2262       print_debug('MODIFY_EDI_XML_ASN: Entering modify_edi_asn', 1);
2263       print_debug('                 (p_group_id => ' || p_group_id, 1);
2264    END IF;
2265 
2266    -- Look at each RTI that has p_group_id
2267    FOR l_rti_rec IN rti_cur(p_group_id) LOOP
2268 
2269       IF (l_debug = 1) THEN
2270 	 print_debug('MODIFY_EDI_XML_ASN: ORGANIZATION ID:'||l_rti_rec.to_organization_id, 1);
2271 	 print_debug('MODIFY_EDI_XML_ASN: ORGANIZATION CODE:'||l_rti_rec.to_organization_code, 1);
2272 	 print_debug('MODIFY_EDI_XML_ASN: ITEM ID:'||l_rti_rec.item_id, 1);
2273 	 print_debug('MODIFY_EDI_XML_ASN: ITEM NUM:'||l_rti_rec.item_num, 1);
2274       END IF;
2275 
2276       IF (l_rti_rec.to_organization_code IS NULL AND l_rti_rec.to_organization_id IS NULL) THEN
2277 	 BEGIN
2278 	    --performace fix. Bug 3444172. Modified the query below.
2279 	    SELECT DISTINCT pll.ship_to_organization_id
2280 	      INTO l_rti_rec.to_organization_id
2281 	      FROM po_line_locations pll, po_headers ph, po_lines pl,
2282 	      mtl_system_items_kfv msik
2283 	      WHERE ph.segment1 = l_rti_rec.document_num
2284 	      AND ((msik.inventory_item_id = l_rti_rec.item_id)
2285 		   OR (msik.concatenated_segments = l_rti_rec.item_num
2286 		       AND l_rti_rec.item_id IS NULL))
2287 			 AND pl.item_id = msik.inventory_item_id
2288 			 AND pll.po_line_id = pl.po_line_id
2289 			 AND pl.po_header_id = ph.po_header_id
2290 			 AND pll.po_header_id = ph.po_header_id
2291 			 AND ph.type_lookup_code in ('STANDARD','BLANKET','PLANNED')
2292 			 AND ROWNUM = 1;
2293 	 EXCEPTION
2294 	    WHEN OTHERS THEN
2295 	       IF (l_debug = 1) THEN
2296 		  print_debug('MODIFY_EDI_XML_ASN: Failed to get ship_to_org_id',1);
2297 	       END IF;
2298 	       --review later
2299 	       l_progress := 'WMSINB-11812';
2300 	       RAISE fnd_api.g_exc_error;
2301 	 END;
2302       END IF; --IF (l_rti_rec.to_organization_code IS NULL AND l_rti_rec.to_organization_id IS NULL) THEN
2303 
2304       IF (l_debug = 1) THEN
2305 	 print_debug('MODIFY_EDI_XML_ASN: AFTER ORGANIZATION ID:'||l_rti_rec.to_organization_id, 1);
2306 	 print_debug('MODIFY_EDI_XML_ASN: AFTER ORGANIZATION CODE:'||l_rti_rec.to_organization_code, 1);
2307       END IF;
2308 
2309       BEGIN
2310 
2311 	--following is fix of performance issue 8113225 / bug 3631289
2312 
2313 	IF (L_RTI_REC.TO_ORGANIZATION_ID IS NOT NULL) THEN
2314 
2315 	       IF (L_RTI_REC.ITEM_ID IS NOT NULL) THEN
2316                         SELECT DISTINCT msik.primary_uom_code,
2317                             msik.inventory_item_id,
2318 			  mp.organization_id
2319 			  INTO l_prim_uom_code,
2320 			  l_item_id,
2321 			  l_to_organization_id
2322                         FROM  mtl_system_items_kfv msik,
2323                                 mtl_parameters mp
2324                       WHERE mp.organization_id = l_rti_rec.to_organization_id
2325                       AND msik.inventory_item_id = l_rti_rec.item_id
2326                     AND mp.organization_id = msik.organization_id;
2327 
2328 	        ELSE --IF (L_RTI_REC.ITEM_ID IS NOT NULL) THEN
2329                         SELECT DISTINCT msik.primary_uom_code,
2330                             msik.inventory_item_id,
2331                             mp.organization_id
2332 			  INTO l_prim_uom_code,
2333 			  l_item_id,
2334 			  l_to_organization_id
2335 			FROM  mtl_system_items_kfv msik,
2336                                 mtl_parameters mp
2337                       WHERE mp.organization_id = l_rti_rec.to_organization_id
2338                         AND msik.concatenated_segments = l_rti_rec.item_num
2339                     AND mp.organization_id = msik.organization_id;
2340                 END IF; --IF (L_RTI_REC.ITEM_ID IS NOT NULL) THEN
2341 
2342 	 ELSE --IF (L_RTI_REC.TO_ORGANIZATION_ID IS NOT NULL) THEN
2343 
2344 	        IF (L_RTI_REC.ITEM_ID IS NOT NULL) THEN
2345                         SELECT DISTINCT msik.primary_uom_code,
2346                             msik.inventory_item_id,
2347 			  mp.organization_id
2348 			  INTO l_prim_uom_code,
2349 			  l_item_id,
2350 			  l_to_organization_id
2351                         FROM  mtl_system_items_kfv msik,
2352                                 mtl_parameters mp
2353                       WHERE mp.organization_code = l_rti_rec.to_organization_code
2354                       AND msik.inventory_item_id = l_rti_rec.item_id
2355                     AND mp.organization_id = msik.organization_id;
2356 
2357 		ELSE --IF (L_RTI_REC.ITEM_ID IS NOT NULL) THEN
2358                         SELECT DISTINCT msik.primary_uom_code,
2359                             msik.inventory_item_id,
2360 			  mp.organization_id
2361 			  INTO l_prim_uom_code,
2362 			  l_item_id,
2363 			  l_to_organization_id
2364                         FROM  mtl_system_items_kfv msik,
2365                                 mtl_parameters mp
2366                       WHERE mp.organization_code = l_rti_rec.to_organization_code
2367                         AND msik.concatenated_segments = l_rti_rec.item_num
2368                     AND mp.organization_id = msik.organization_id;
2369 
2370 		END IF; --IF (L_RTI_REC.ITEM_ID IS NOT NULL) THEN
2371 
2372 	END IF; --IF (L_RTI_REC.TO_ORGANIZATION_ID IS NOT NULL) THEN
2373 
2374 
2375 		    --performace fix. Bug 3444172
2376 		    --WHERE ((msik.inventory_item_id = l_rti_rec.item_id)
2377 		    --  OR (msik.concatenated_segments = l_rti_rec.item_num
2378 		    --    AND l_rti_rec.item_id IS NULL))
2379 		    --AND ((msik.organization_id = l_rti_rec.to_organization_id)
2380 		    --   OR (mp.organization_code = l_rti_rec.to_organization_code
2381 		    -- AND l_rti_rec.to_organization_id IS NULL))
2382 		    -- AND mp.organization_id = msik.organization_id;
2383 
2384 	  -- Set the ITEM ID and Organization ID here
2385           If l_rti_rec.item_id is null then
2386              l_rti_rec.item_id := l_item_id;
2387           End if;
2388 
2389           If l_rti_rec.to_organization_id is null then
2390              l_rti_rec.to_organization_id := l_to_organization_id;
2391           End if;
2392 
2393       EXCEPTION
2394 	 WHEN OTHERS THEN
2395 	    IF (l_debug = 1) THEN
2396 	       print_debug('MODIFY_EDI_XML_ASN: Error retrieving primary uom', 1);
2397 	    END IF;
2398 	    l_progress := 'WMSINB-11843';
2399 	    RAISE fnd_api.g_exc_error;
2400       END ;
2401 
2402       IF (l_debug = 1) THEN
2403 	 print_debug('MODIFY_EDI_XML_ASN: ORGANIZATION ID:'||l_rti_rec.to_organization_id, 1);
2404 	 print_debug('MODIFY_EDI_XML_ASN: ITEM ID:'||l_rti_rec.item_id, 1);
2405       END IF;
2406 
2407 
2408       l_progress := 'WMSINB-11848';
2409 
2410       IF (l_debug = 1) THEN
2411 	 print_debug('MODIFY_EDI_XML_ASN: Looking at RTI:' ||
2412 		     l_rti_rec.interface_transaction_id, 1);
2413       END IF;
2414 
2415       l_wlpnci_total_qty := 0;
2416 
2417       --WLPNI will have rti.group_id
2418       --Update them to RTI.LPN_GROUP_ID so that it will get
2419       --picked up when the transaction is processed
2420       BEGIN
2421 	 UPDATE wms_lpn_interface
2422 	   SET  source_group_id = l_rti_rec.lpn_group_id
2423 	       ,organization_id = l_rti_rec.to_organization_id
2424 	   WHERE source_group_id = p_group_id
2425 	   AND   EXISTS (SELECT 1  --Only for EDI TXN we are doing this
2426 			           --And EDI TXN will have WLPNCI
2427 			 FROM   wms_lpn_contents_interface
2428 			 WHERE  group_id = p_group_id);
2429       EXCEPTION
2430 	 WHEN OTHERS THEN
2431 	 IF (l_debug = 1) THEN
2432 	    print_debug('MODIFY_EDI_XML_ASN: Error update source_group_id OF WLPNI',1);
2433 	 END IF;
2434       END;
2435 
2436       IF (l_debug = 1) THEN
2437 	 print_debug('MODIFY_EDI_XML_ASN: NUMBER OF WLPNI ROWS :' ||
2438 		     SQL%ROWCOUNT, 1);
2439       END IF;
2440 
2441       -- WLPNCI links to RTI through interface_transaction_id
2442       FOR l_wlpnci_rec IN wlpnci_cur(l_rti_rec.interface_transaction_id) LOOP
2443 
2444 	 l_progress := 'WMSINB-11860';
2445 
2446 	 IF (l_debug = 1) THEN
2447 	    print_debug('MODIFY_EDI_XML_ASN: Looking at WLPNCI:' ||
2448 			l_wlpnci_rec.interface_transaction_id, 1);
2449 	 END IF;
2450 
2451 	 -- Only insert wlpni if lpn_id is NULL
2452 	 IF (l_wlpnci_rec.lpn_id IS NULL) THEN
2453 	    check_lpn_in_wlpni
2454 	      (p_license_plate_number => l_wlpnci_rec.license_plate_number
2455                ,p_lpn_id => l_wlpnci_rec.lpn_id
2456 	       ,p_lpn_group_id => l_rti_rec.lpn_group_id
2457 	       ,x_exists  => l_exists);
2458 
2459 	    IF (l_exists <> 1) THEN
2460 	       -- All wlpnci will have the same lpn_id.  So just insert_wlpni once
2461 
2462 	       IF (l_debug = 1) THEN
2463 		  print_debug('MODIFY_EDI_XML_ASN: Calling insert_wlpni(', 1);
2464 		  print_debug('                 p_organization_id => '||l_wlpnci_rec.organization_id,1);
2465 		  print_debug('                 p_lpn_id          => '||l_wlpnci_rec.lpn_id,1);
2466 		  print_debug('                 p_license_plate_number=> '||l_wlpnci_rec.license_plate_number,1);
2467 		  print_debug('                 p_lpn_group_id    => '||p_group_id,1);
2468 	       END IF;
2469 
2470 	       l_progress := 'WMSINB-11886';
2471 
2472 	       inv_rcv_integration_apis.insert_wlpni
2473 		 (p_api_version           => 1.0
2474 		  ,x_return_status        => x_return_status
2475 		  ,x_msg_count            => x_msg_count
2476 		  ,x_msg_data             => x_msg_data
2477 		  ,p_organization_id      => l_rti_rec.to_organization_id
2478 		  ,p_lpn_id               => l_wlpnci_rec.lpn_id
2479 		  ,p_license_plate_number => l_wlpnci_rec.license_plate_number
2480 		  --,p_lpn_group_id         => p_group_id --??
2481 		  ,p_lpn_group_id         => l_rti_rec.lpn_group_id --Changed to pass the lpn_group_id otherwise it would fail in validate_lpn_info
2482 		  );
2483 	       IF (x_return_status <> g_ret_sts_success) THEN
2484 		  IF (l_debug = 1) THEN
2485 		     print_debug('MODIFY_EDI_XML_ASN: Error in insert_wlpni', 1);
2486 		  END IF;
2487 
2488 		  l_progress := 'WMSINB-11903';
2489 		  RAISE fnd_api.g_exc_error;
2490 	       END IF;
2491 
2492 	       l_progress := 'WMSINB-11907';
2493 
2494 	       IF (l_debug = 1) THEN
2495 		  print_debug('MODIFY_EDI_XML_ASN: WLPNI:' ||
2496 			      l_wlpnci_rec.lpn_id ||' inserted successfully', 1);
2497 	       END IF;
2498 
2499 	    END IF; --IF (l_exists <> 1) THEN
2500 	 END IF; --IF (l_wlpnci_rec.lpn_id IS NULL) THEN
2501 
2502 	 l_progress := 'WMSINB-11917';
2503 
2504 	 BEGIN
2505 	    UPDATE rcv_transactions_interface
2506 	      SET lpn_id = l_wlpnci_rec.lpn_id,
2507 	      license_plate_number = l_wlpnci_rec.license_plate_number
2508 	      WHERE interface_transaction_id = l_rti_rec.interface_transaction_id;
2509 	 EXCEPTION
2510 	    WHEN OTHERS THEN
2511 	       IF (l_debug = 1) THEN
2512 		  print_debug('MODIFY_EDI_XML_ASN: Error updating RTI', 1);
2513 	       END IF;
2514 	       l_progress := 'WMSINB-11929';
2515 	       RAISE fnd_api.g_exc_error;
2516 	 END;
2517 
2518 	 l_progress := 'WMSINB-11933';
2519 
2520 	 IF (l_wlpnci_rec.uom_code <> l_prim_uom_code) THEN
2521 	    l_prim_qty := inv_rcv_cache.convert_qty(p_inventory_item_id => l_rti_rec.item_id
2522 				      ,p_from_qty         => l_wlpnci_rec.quantity
2523 				      ,p_from_uom_code    => l_wlpnci_rec.uom_code
2524 				      ,p_to_uom_code      => l_prim_uom_code);
2525 	  ELSE
2526 	    l_prim_qty := l_wlpnci_rec.quantity;
2527 	 END IF;
2528 
2529 	 l_wlpnci_total_qty := l_wlpnci_total_qty + l_prim_qty;
2530 	 -- l_serial_txn_intf_id will be updated if item is lot controlled
2531 	 -- otherwise, use the same one in wlpnci
2532 	 l_serial_txn_intf_id := l_wlpnci_rec.serial_transaction_intf_id;
2533 
2534 	 IF (l_wlpnci_rec.lot_number IS NOT NULL) THEN
2535 
2536 	    l_progress := 'WMSINB-11957';
2537 
2538 	    IF (l_debug = 1) THEN
2539 	       print_debug('MODIFY_EDI_XML_ASN: Lot number is not null in WLPNCI. inserting MTLI',1);
2540 	    END IF;
2541 
2542 	    inv_rcv_integration_apis.insert_mtli
2543 	      (p_api_version     => 1.0
2544 	       ,x_return_status  => x_return_status
2545 	       ,x_msg_count      => x_msg_count
2546 	       ,x_msg_data       => x_msg_data
2547 	       ,p_transaction_interface_id => l_txn_intf_id
2548 	       ,p_lot_number     => ltrim(rtrim(l_wlpnci_rec.lot_number))
2549 	       ,p_transaction_quantity => l_wlpnci_rec.quantity
2550 	       ,p_primary_quantity     => l_prim_qty
2551 	       ,p_organization_id   =>  l_rti_rec.to_organization_id -- l_wlpnci_rec.organization_id
2552 	       ,p_inventory_item_id =>  l_rti_rec.item_id
2553 	       ,p_expiration_date   =>  l_wlpnci_rec.expiration_date
2554 	       ,p_status_id         =>  l_wlpnci_rec.status_id
2555 	       ,x_serial_transaction_temp_id => l_tmp_ser_txn_id -- update
2556 	       ,p_product_transaction_id => l_rti_rec.interface_transaction_id
2557 	       ,p_product_code      => 'RCV'
2558 	       ,p_description       =>  l_wlpnci_rec.item_description --??
2559 	       ,p_vendor_name       =>  l_wlpnci_rec.vendor_item_num --??
2560 	       ,p_supplier_lot_number => l_wlpnci_rec.supplier_lot_number
2561 	       ,p_origination_date  =>  l_wlpnci_rec.origination_date
2562 	      ,p_date_code          =>  l_wlpnci_rec.date_code
2563 	      ,p_grade_code         =>  l_wlpnci_rec.grade_code
2564 	      ,p_change_date        =>  l_wlpnci_rec.change_date
2565 	      ,p_maturity_date      =>  l_wlpnci_rec.maturity_date
2566 	      ,p_retest_date        =>  l_wlpnci_rec.retest_date
2567 	      ,p_age                =>  l_wlpnci_rec.age
2568 	      ,p_item_size          =>  l_wlpnci_rec.item_size
2569 	      ,p_color              =>  l_wlpnci_rec.color
2570 	      ,p_volume             =>  l_wlpnci_rec.volume
2571 	      ,p_place_of_origin    =>  l_wlpnci_rec.place_of_origin
2572 	      ,p_best_by_date       =>  l_wlpnci_rec.best_by_date
2573 	      ,p_length             =>  l_wlpnci_rec.length
2574 	      ,p_length_uom         =>  l_wlpnci_rec.length_uom_code
2575 	      ,p_recycled_content   =>  l_wlpnci_rec.recycled_content
2576 	      ,p_thickness          =>  l_wlpnci_rec.thickness
2577 	      ,p_thickness_uom      =>  l_wlpnci_rec.thickness_uom_code
2578 	      ,p_width              =>  l_wlpnci_rec.width
2579 	      ,p_width_uom          =>  l_wlpnci_rec.width_uom_code
2580 	      ,p_curl_wrinkle_fold  =>  l_wlpnci_rec.curl_wrinkle_fold
2581 	      ,p_c_attribute1       =>  l_wlpnci_rec.c_attribute1
2582 	      ,p_c_attribute2       =>  l_wlpnci_rec.c_attribute2
2583 	      ,p_c_attribute3       =>  l_wlpnci_rec.c_attribute3
2584 	      ,p_c_attribute4       =>  l_wlpnci_rec.c_attribute4
2585 	      ,p_c_attribute5       =>  l_wlpnci_rec.c_attribute5
2586 	      ,p_c_attribute6       =>  l_wlpnci_rec.c_attribute6
2587 	      ,p_c_attribute7       =>  l_wlpnci_rec.c_attribute7
2588 	      ,p_c_attribute8       =>  l_wlpnci_rec.c_attribute8
2589 	      ,p_c_attribute9       =>  l_wlpnci_rec.c_attribute9
2590 	      ,p_c_attribute10      =>  l_wlpnci_rec.c_attribute10
2591 	      ,p_c_attribute11      =>  l_wlpnci_rec.c_attribute11
2592 	      ,p_c_attribute12      =>  l_wlpnci_rec.c_attribute12
2593 	      ,p_c_attribute13      =>  l_wlpnci_rec.c_attribute13
2594 	      ,p_c_attribute14      =>  l_wlpnci_rec.c_attribute14
2595 	      ,p_c_attribute15      =>  l_wlpnci_rec.c_attribute15
2596 	      ,p_c_attribute16      =>  l_wlpnci_rec.c_attribute16
2597 	      ,p_c_attribute17      =>  l_wlpnci_rec.c_attribute17
2598 	      ,p_c_attribute18      =>  l_wlpnci_rec.c_attribute18
2599 	      ,p_c_attribute19      =>  l_wlpnci_rec.c_attribute19
2600 	      ,p_c_attribute20      =>  l_wlpnci_rec.c_attribute20
2601 	      ,p_d_attribute1       =>  l_wlpnci_rec.d_attribute1
2602 	      ,p_d_attribute2       =>  l_wlpnci_rec.d_attribute2
2603 	      ,p_d_attribute3       =>  l_wlpnci_rec.d_attribute3
2604 	      ,p_d_attribute4       =>  l_wlpnci_rec.d_attribute4
2605 	      ,p_d_attribute5       =>  l_wlpnci_rec.d_attribute5
2606 	      ,p_d_attribute6       =>  l_wlpnci_rec.d_attribute6
2607 	      ,p_d_attribute7       =>  l_wlpnci_rec.d_attribute7
2608 	      ,p_d_attribute8       =>  l_wlpnci_rec.d_attribute8
2609 	      ,p_d_attribute9       =>  l_wlpnci_rec.d_attribute9
2610 	      ,p_d_attribute10      =>  l_wlpnci_rec.d_attribute10
2611 	      ,p_n_attribute1       =>  l_wlpnci_rec.n_attribute1
2612 	      ,p_n_attribute2       =>  l_wlpnci_rec.n_attribute2
2613 	      ,p_n_attribute3       =>  l_wlpnci_rec.n_attribute3
2614 	      ,p_n_attribute4       =>  l_wlpnci_rec.n_attribute4
2615 	      ,p_n_attribute5       =>  l_wlpnci_rec.n_attribute5
2616 	      ,p_n_attribute6       =>  l_wlpnci_rec.n_attribute6
2617 	      ,p_n_attribute7       =>  l_wlpnci_rec.n_attribute7
2618 	      ,p_n_attribute8       =>  l_wlpnci_rec.n_attribute8
2619 	      ,p_n_attribute9       =>  l_wlpnci_rec.n_attribute9
2620 	      ,p_n_attribute10      =>  l_wlpnci_rec.n_attribute10
2621 	      ,p_attribute_category =>  l_wlpnci_rec.attribute_category
2622 	      ,p_attribute1         =>  l_wlpnci_rec.attribute1
2623 	      ,p_attribute2         =>  l_wlpnci_rec.attribute2
2624 	      ,p_attribute3         =>  l_wlpnci_rec.attribute3
2625 	      ,p_attribute4         =>  l_wlpnci_rec.attribute4
2626 	      ,p_attribute5         =>  l_wlpnci_rec.attribute5
2627 	      ,p_attribute6         =>  l_wlpnci_rec.attribute6
2628 	      ,p_attribute7         =>  l_wlpnci_rec.attribute7
2629 	      ,p_attribute8         =>  l_wlpnci_rec.attribute8
2630 	      ,p_attribute9         =>  l_wlpnci_rec.attribute9
2631 	      ,p_attribute10        =>  l_wlpnci_rec.attribute10
2632 	      ,p_attribute11        =>  l_wlpnci_rec.attribute11
2633 	      ,p_attribute12        =>  l_wlpnci_rec.attribute12
2634 	      ,p_attribute13        =>  l_wlpnci_rec.attribute13
2635 	      ,p_attribute14        =>  l_wlpnci_rec.attribute14
2636 	      ,p_attribute15        =>  l_wlpnci_rec.attribute15
2637 	      );
2638 
2639 	    IF (x_return_status <> g_ret_sts_success) THEN
2640 	       IF (l_debug = 1) THEN
2641 		  print_debug('MODIFY_EDI_XML_ASN: Error in insert_mtli', 1);
2642 	       END IF;
2643 	       l_progress := 'WMSINB-12064';
2644 	       RAISE fnd_api.g_exc_error;
2645 	    END IF;
2646 	 END IF;
2647 
2648 	 l_progress := 'WMSINB-12069';
2649 
2650 	 IF (l_wlpnci_rec.serial_transaction_intf_id IS NOT NULL) THEN
2651 	    -- for serial controlled only items, do they all have have
2652 	    -- different transaction_intf_id, or can they use the same?
2653 	    l_progress := 'WMSINB-12074';
2654 
2655 	    IF (l_debug = 1) THEN
2656 	       print_debug('MODIFY_EDI_XML_ASN: Looking at MSNIs with ID:' ||
2657 			   l_wlpnci_rec.serial_transaction_intf_id, 1);
2658 	    END IF;
2659 
2660 	    l_msni_total_qty := 0;
2661 
2662 	    FOR l_msni_rec IN msni_cur(l_wlpnci_rec.serial_transaction_intf_id) LOOP
2663 	       l_progress := 'WMSINB-12084';
2664 
2665 	       IF (l_debug = 1) THEN
2666 		  print_debug('MODIFY_EDI_XML_ASN: Looping MSNIs',1);
2667 	       END IF;
2668 
2669 	       l_progress := 'WMSINB-12090';
2670 	       l_serial_qty :=
2671 		 inv_serial_number_pub.get_serial_diff
2672 		 (p_fm_serial => l_msni_rec.fm_serial_number
2673 		  ,p_to_serial=> l_msni_rec.to_serial_number
2674 		  );
2675 	       l_progress := 'WMSINB-12096';
2676 	       l_msni_total_qty := l_msni_total_qty + l_serial_qty;
2677 
2678 	    END LOOP;
2679 
2680 
2681 	    IF (l_debug = 1) THEN
2682 	       print_debug('MODIFY_EDI_XML_ASN: MSNI loop exited',1);
2683 	    END IF;
2684 
2685 	    l_progress := 'WMSINB-12106';
2686 
2687 	    IF (l_msni_total_qty > 0 AND l_msni_total_qty <> l_wlpnci_rec.quantity) THEN
2688 	       -- this message is OK?
2689 	       fnd_message.set_name('INV', 'INV_SERQTY_NOTMATCH');
2690 	       fnd_msg_pub.ADD;
2691 	       IF (l_debug = 1) THEN
2692 		  print_debug('MODIFY_EDI_XML_ASN: MSNIs total quantity does not match WLPNCI quantity',1);
2693 	       END IF;
2694 	       l_progress := 'WMSINB-12115';
2695 	       RAISE fnd_api.g_exc_error;
2696 	    END IF;
2697 
2698 	    l_progress := 'WMSINB-12119';
2699 
2700 	    -- Now update the product code and product_intf_id
2701 	    IF (l_msni_total_qty > 0) THEN
2702 	       BEGIN
2703 		  UPDATE mtl_serial_numbers_interface
2704 		    SET product_code = 'RCV',
2705 		    product_transaction_id=l_rti_rec.interface_transaction_id,
2706 		    transaction_interface_id = l_serial_txn_intf_id
2707 		    --WHERE transaction_interface_id = l_wlpnci_rec.interface_transaction_id;
2708 		    WHERE transaction_interface_id = l_wlpnci_rec.serial_transaction_intf_id;
2709 
2710 
2711 		  UPDATE mtl_transaction_lots_interface
2712 		    SET serial_transaction_temp_id = l_serial_txn_intf_id
2713 		    WHERE product_code = 'RCV'
2714 		    AND product_transaction_id = l_wlpnci_rec.interface_transaction_id;
2715 
2716 	       EXCEPTION
2717 		  WHEN OTHERS THEN
2718 		     IF (l_debug = 1) THEN
2719 			print_debug('MODIFY_EDI_XML_ASN: Error updating MSNI',1);
2720 		     END IF;
2721 		     l_progress := 'WMSINB-12141';
2722 		     RAISE fnd_api.g_exc_error;
2723 	       END;
2724 	    END IF; --IF (l_msni_total_qty > 0) THEN
2725 	    l_progress := 'WMSINB-12145';
2726 	 END IF;
2727 
2728 	 IF (l_debug = 1) THEN
2729 	    l_progress := 'WMSINB-12149';
2730 	    print_debug('MODIFY_EDI_XML_ASN: WLPNCI loop exited',1);
2731 	 END IF;
2732 
2733       END LOOP;
2734 
2735       IF ((l_wlpnci_total_qty > 0) AND (l_wlpnci_total_qty <> l_rti_rec.primary_quantity)) THEN
2736 	 IF (l_debug = 1) THEN
2737 	    print_debug('MODIFY_EDI_XML_ASN: WLPNCIs total quantity does not match RTI quantity', 1);
2738 	 END IF;
2739 	 -- message to be added
2740 	 fnd_message.set_name('INV', 'INV_WLPNCI_RTI_QTY_NOTMATCH');
2741 	 fnd_msg_pub.ADD;
2742 	 l_progress := 'WMSINB-12162';
2743 	 RAISE fnd_api.g_exc_error;
2744       END IF;
2745 
2746 
2747       IF (l_debug = 1) THEN
2748 	 print_debug('MODIFY_EDI_XML_ASN: Updating RTI row',1);
2749       END IF;
2750 
2751       l_progress := 'WMSINB-12171';
2752    END LOOP;
2753 
2754    l_progress := 'WMSINB-12174';
2755 
2756    IF (l_debug = 1) THEN
2757       print_debug('MODIFY_EDI_XML_ASN: RTI loop exited.  Procedure returns',1);
2758    END IF;
2759 EXCEPTION
2760    WHEN OTHERS THEN
2761       IF (l_debug = 1) THEN
2762 	 print_debug('MODIFY_EDI_XML_ASN: Exception after l_progress = ' ||
2763 		     l_progress,1);
2764       END IF;
2765       x_return_status := g_ret_sts_unexp_error ;
2766       --      fnd_msg_pub.count_and_get
2767       --        (   p_count        => x_msg_count
2768       --	    ,p_data     => x_msg_data
2769       --	    );
2770       IF (rti_cur%isopen) THEN
2771 	 CLOSE rti_cur;
2772       END IF;
2773       IF (wlpnci_cur%isopen) THEN
2774 	 CLOSE wlpnci_cur;
2775       END IF;
2776       IF (msni_cur%isopen) THEN
2777 	 CLOSE msni_cur;
2778       END IF;
2779       ROLLBACK TO modify_edi_asn_pub;
2780 END modify_edi_xml_asn;
2781 
2782 PROCEDURE Explode_lpn(p_request_id       IN         NUMBER,
2783                       p_group_id         IN  NUMBER ) is
2784 
2785 			 l_errorneous_rows NUMBER := 0;
2786 			 l_msg_count number;
2787 			 l_msg_data VARCHAR2(2000);
2788 			 l_return_status VARCHAR2(1);
2789 			 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2790 			 l_progress VARCHAR2(15) := '10';
2791 
2792 			 l_lpn_grp_id NUMBER;
2793 
2794 			 l_dummy NUMBER := NULL;
2795 
2796 BEGIN
2797 
2798    -- Check for Erroneous rows in RTI
2799    --
2800 
2801    l_progress := 'WMSINB-12221';
2802 
2803    IF (l_debug = 1) THEN
2804       print_debug('Explode_LPN : '|| l_progress ,1);
2805       print_debug('Explode_LPN group_id: '|| p_group_id ,1);
2806       print_debug('Explode_LPN request_id: '|| p_request_id ,1);
2807    END IF;
2808 
2809    IF (Nvl(p_group_id,0) = 0 AND Nvl(p_request_id,0) = 0) THEN
2810       --raise error review later
2811       l_progress := 'WMSINB-12231';
2812       RAISE fnd_api.g_exc_error;
2813    END IF;
2814 
2815    l_progress := 'WMSINB-12235';
2816 
2817    /*************************** We do not need to do this check as PO will*
2818    *********************** update the lpn_group_id for all RTIs with LPNs*
2819      for l_error_row in ( select interface_transaction_id,
2820      group_id
2821      from rcv_transactions_interface
2822      where lpn_group_id is null
2823      and (   lpn_id is not null
2824      or license_plate_number is not null
2825      or transfer_lpn_id is not null
2826      or transfer_license_plate_number is not null
2827      )
2828      and processing_status_code in ('RUNNING')
2829      AND (processing_request_id IS NULL
2830      OR processing_request_id = p_request_id)
2831      AND group_id = Decode(p_group_id,0,group_id,NULL,group_id,p_group_id)
2832      ) Loop
2833      -- Call PO's API to mark the Error
2834      IF (l_debug = 1) THEN
2835      print_debug('Explode_LPN failed for interface_transaction_id : '|| l_error_row.interface_transaction_id ,1);
2836      print_debug('Explode_LPN failed for group_id: '|| p_group_id ,1);
2837      print_debug('Explode_LPN request_id failed for request_id : '|| p_request_id ,1);
2838      END IF;
2839      rcv_roi_preprocessor.explode_lpn_failed
2840      (x_interface_txn_id => l_error_row.interface_transaction_id,
2841      x_group_id => l_error_row.group_id,
2842      x_lpn_group_id => NULL);
2843      End Loop;
2844      *************************************************************************************/
2845      -- ** The update part is commented after discussion with po team
2846      -- ** Instead of Finding Errorneous Rows we will update the LPN GROUP_ID HERE *******
2847 
2848      l_progress := 'WMSINB-12268';
2849 
2850    -- See if there are any rtis which require explosion but have null
2851    -- lpn_group_id and update the lpn_group_id for such cases
2852 
2853    FOR l_lpn_grp_null IN (SELECT interface_transaction_id
2854 			  FROM rcv_transactions_interface
2855 			  WHERE Nvl(item_id, -1) = -1
2856 			  AND item_num IS NULL
2857 			  AND item_description IS NULL
2858 			  AND lpn_group_id IS NULL
2859 			  AND (lpn_id IS NOT NULL
2860 			       OR license_plate_number IS NOT NULL)
2861 			  AND transaction_type <> 'SHIP'
2862 			  AND processing_status_code in ('RUNNING')
2863 			  AND (processing_request_id IS NULL
2864 			       OR processing_request_id = p_request_id)
2865 			  AND group_id = Decode(p_group_id,0,group_id,NULL,group_id,p_group_id))
2866 			    LOOP
2867 			       IF (l_debug = 1) THEN
2868 				  print_debug('EXPLODE_LPN - Case for explosion without LPN_GROUP_ID. Updating for RTI: '||l_lpn_grp_null.interface_transaction_id,1);
2869 			       END IF;
2870 
2871 			       SELECT RCV_INTERFACE_GROUPS_S.NEXTVAL
2872 				 INTO l_lpn_grp_id
2873 				 FROM DUAL;
2874 
2875 			       UPDATE rcv_transactions_interface
2876 				 SET lpn_group_id = l_lpn_grp_id
2877 				 WHERE interface_transaction_id = l_lpn_grp_null.interface_transaction_id;
2878 
2879 			    END LOOP;
2880 
2881 			    -- Following will be removed after po gives us the patch for corrections/returns.
2882 			    /************************************************************************/
2883 			    --UPDATE rcv_transactions_interface SET lpn_group_id = group_id
2884 			    --WHERE lpn_group_id IS NULL
2885 			    --AND (lpn_id IS NOT NULL
2886 			    --   OR license_plate_number IS NOT NULL
2887 			    -- OR transfer_lpn_id IS NOT NULL
2888 			    -- OR transfer_license_plate_number IS NOT NULL
2889 			    -- )
2890 			    -- AND processing_status_code = 'RUNNING'
2891 			    -- AND (processing_request_id IS NULL
2892 			    --    OR processing_request_id = p_request_id)
2893 			    -- AND group_id = Decode(p_group_id,0,group_id,NULL,group_id,p_group_id);
2894 			    /***********************************************************************/
2895 				       l_progress := 'WMSINB-12314';
2896 
2897 				       FOR l_rti_rec IN ( SELECT DISTINCT lpn_group_id, group_id
2898 							  FROM rcv_transactions_interface rti
2899 							  WHERE lpn_group_id IS NOT NULL
2900 							  AND Nvl(item_id, -1) = -1
2901 							  AND item_num IS NULL
2902 							  AND item_description IS NULL
2903 							  AND transaction_type <> 'SHIP'
2904 							  AND processing_status_code in ('RUNNING')
2905 							  AND (processing_request_id IS NULL
2906 							       OR processing_request_id = p_request_id)
2907 							  AND group_id = Decode(p_group_id,0,group_id,NULL,group_id,p_group_id)) LOOP
2908 							     IF (l_debug = 1) THEN
2909 								print_debug('Explode_LPN_contents called for LPN_GROUP = '||l_rti_rec.lpn_group_id  ,1);
2910 							     END IF;
2911 							     Explode_lpn_contents(l_rti_rec.lpn_group_id,l_return_status,l_msg_count, l_msg_data);
2912 							     IF (l_return_status <> g_ret_sts_success) then
2913 								IF (l_debug = 1) THEN
2914 								   print_debug('Explode_LPN_contents FAILURE for LPN_GROUP = '||l_rti_rec.lpn_group_id  ,1);
2915 								END IF;
2916 								-- Call PO's API to mark the Error
2917 								rcv_roi_preprocessor.explode_lpn_failed(x_interface_txn_id => l_dummy,
2918 													x_group_id => l_rti_rec.group_id,
2919 													x_lpn_group_id => l_rti_rec.lpn_group_id);
2920 							     END IF;
2921 							  END LOOP;
2922 
2923 							  --See if there are any rows for ASN SHIP txn
2924 							  --which need updation of lpn_group_id
2925                                                           --Instead of shipment use interface_transaction_id as the shipment_num in rti may be null
2926 							  --FOR l_asn_lpn_grp_null IN (SELECT DISTINCT shipment_num
2927 
2928 							  FOR l_asn_lpn_grp_null IN (SELECT DISTINCT header_interface_id,
2929                                                                                                      shipment_num
2930 										     FROM rcv_transactions_interface rti
2931 										     WHERE rti.lpn_group_id IS NULL
2932 										     AND ( ( (rti.lpn_id IS NOT NULL
2933 											    OR rti.license_plate_number IS NOT NULL)
2934                                                                                            ) or
2935                                                                                            (exists ( select 'x' from wms_lpn_contents_interface wlc
2936                                                                                                     where wlc.interface_transaction_id =
2937                                                                                                         rti.interface_transaction_id
2938                                                                                                    )
2939                                                                                            )
2940                                                                                          )
2941 										     AND rti.processing_status_code = 'RUNNING'
2942 										     AND (rti.processing_request_id IS NULL
2943 											  OR rti.processing_request_id = p_request_id)
2944 										     AND rti.transaction_type = 'SHIP'
2945 										     AND rti.source_document_code = 'PO'
2946 										     AND (rti.item_id IS NOT NULL
2947 											  OR rti.item_num IS NOT NULL)
2948 										     AND rti.group_id = Decode(p_group_id,0,rti.group_id,NULL,rti.group_id,p_group_id))
2949 											    LOOP
2950 											       IF (l_debug = 1) THEN
2951 												  print_debug('EXPLODE_LPN - SHIP  Updating lpn_group for SHIPMENT: '||l_asn_lpn_grp_null.shipment_num,1);
2952 											       END IF;
2953 
2954 											       SELECT RCV_INTERFACE_GROUPS_S.NEXTVAL
2955 												 INTO l_lpn_grp_id
2956 												 FROM DUAL;
2957 
2958 											       UPDATE rcv_transactions_interface
2959 												 SET lpn_group_id = l_lpn_grp_id
2960                                                                                                  -- don't use shipment_num see update above ****
2961 												 -- WHERE shipment_num = l_asn_lpn_grp_null.shipment_num
2962 												 WHERE header_interface_id = l_asn_lpn_grp_null.header_interface_id
2963                                                                                                  AND lpn_group_id is null
2964 												 AND processing_status_code = 'RUNNING'
2965 												 AND (processing_request_id IS NULL
2966 												      OR processing_request_id = p_request_id)
2967 												   AND transaction_type = 'SHIP'
2968 												   AND source_document_code = 'PO'
2969 												   AND group_id = Decode(p_group_id,0,group_id,NULL,group_id,p_group_id);
2970 											    END LOOP;
2971 
2972 											    -- This PART Below is for ASN creation only
2973 											    FOR l_asn_rec IN ( SELECT DISTINCT group_id,processing_mode_code
2974 													       FROM rcv_transactions_interface rti
2975 													       WHERE processing_status_code = 'RUNNING'
2976 													       AND (processing_request_id IS NULL
2977 														    OR processing_request_id = p_request_id)
2978 													       AND transaction_type = 'SHIP'
2979 													       AND source_document_code = 'PO'
2980 													       AND lpn_group_id IS NOT NULL
2981 													       AND (item_id IS NOT NULL OR
2982 														    item_num IS NOT NULL)
2983 													       AND group_id = Decode(p_group_id,0,group_id,NULL,group_id,p_group_id)) LOOP
2984 														  IF (l_debug = 1) THEN
2985 														     print_debug('Modify_edi_xml_asn called for GROUP = '||l_asn_rec.group_id  ,1);
2986 														  END IF;
2987 														  modify_edi_xml_asn(l_asn_rec.group_id,l_return_status,l_msg_count, l_msg_data);
2988 														  IF (l_return_status <> g_ret_sts_success) then
2989 														     IF (l_debug = 1) THEN
2990 															print_debug('modify_edi_xml_asn FAILURE for GROUP = '||l_asn_rec.group_id  ,1);
2991 														     END IF;
2992 														     -- Call POs API to mark the Error
2993 														     IF (l_asn_rec.processing_mode_code='ONLINE') THEN
2994 															rcv_roi_preprocessor.explode_lpn_failed
2995 															  (x_interface_txn_id => l_dummy,
2996 															   x_group_id => l_asn_rec.group_id,
2997 															   x_lpn_group_id => NULL);
2998 														      ELSE
2999 															FOR l_err_row IN (SELECT interface_transaction_id
3000 																	  FROM rcv_transactions_interface
3001 																	  WHERE group_id = l_asn_rec.group_id) LOOP
3002 																	     -- Call PO's API to mark the Error
3003 																	     rcv_roi_preprocessor.explode_lpn_failed
3004 																	       (x_interface_txn_id => l_err_row.interface_transaction_id,
3005 																		x_group_id => l_asn_rec.group_id,
3006 																		x_lpn_group_id => NULL);
3007 																	  END LOOP;
3008 														     END IF; --IF (l_asn_rec.processing_mode_code='ONLINE') THEN
3009 														  END IF; --IF (l_return_status <> g_ret_sts_success) then
3010 													       END LOOP;
3011 
3012 													       -- Delete the Original row for Explosion
3013                                                                                                                -- Bug 3618348. The code below is changed from performance reasons
3014                                                                                                                /*
3015 													       DELETE FROM rcv_transactions_interface
3016 														 WHERE Nvl(item_id, -1)  = -1
3017 														 AND item_description IS NULL
3018 														   AND Nvl(quantity,0) = 0
3019 														   AND lpn_group_id IS NOT NULL
3020 														     AND processing_status_code = 'RUNNING'
3021 														     AND (processing_request_id IS NULL
3022 															  OR processing_request_id = p_request_id)
3023 														       AND group_id = Decode(p_group_id,0,group_id,NULL,group_id,p_group_id);
3024                                                                                                                */
3025 if nvl(p_group_id,0) = 0 then
3026    DELETE FROM rcv_transactions_interface
3027      WHERE Nvl(item_id, -1)  = -1
3028        AND item_description IS NULL
3029        AND Nvl(quantity,0) = 0
3030        AND lpn_group_id IS NOT NULL
3031        AND processing_status_code = 'RUNNING'
3032        -- Bug 3714354
3033        and ( lpn_id is not null or license_plate_number is not null )
3034        AND (processing_request_id IS NULL
3035              OR processing_request_id = p_request_id) ;
3036 Else
3037    DELETE FROM rcv_transactions_interface
3038      WHERE Nvl(item_id, -1)  = -1
3039        AND item_description IS NULL
3040        AND Nvl(quantity,0) = 0
3041        AND lpn_group_id IS NOT NULL
3042        AND processing_status_code = 'RUNNING'
3043        -- Bug 3714354
3044        and ( lpn_id is not null or license_plate_number is not null )
3045        AND (processing_request_id IS NULL
3046              OR processing_request_id = p_request_id)
3047        AND group_id = p_group_id;
3048 End if;
3049 
3050 END Explode_lpn;
3051 
3052 FUNCTION get_inspection_status(p_transaction_type IN VARCHAR2
3053 			       , p_routing_header_id IN NUMBER DEFAULT NULL
3054 			       , p_parent_transaction_type IN VARCHAR2 DEFAULT NULL
3055 			       , p_parent_parent_txn_type IN VARCHAR2 DEFAULT NULL
3056 			       , p_quantity IN NUMBER DEFAULT NULL) return NUMBER
3057   IS
3058      l_inspect_status NUMBER;
3059 BEGIN
3060    l_inspect_status := NULL;
3061 
3062    IF (p_transaction_type = 'RECEIVE' AND
3063        p_routing_header_id = 2) THEN
3064       l_inspect_status := 1;
3065     ELSIF (p_transaction_type = 'ACCEPT') THEN
3066       l_inspect_status := 2;
3067     ELSIF (p_transaction_type = 'REJECT') THEN
3068       l_inspect_status := 3;
3069     ELSIF (p_transaction_type = 'TRANSFER') THEN
3070       l_inspect_status := -9999;
3071    END IF;
3072 
3073    RETURN l_inspect_status;
3074 
3075 END get_inspection_status;
3076 
3077 Function get_serial_status(p_transaction_type IN VARCHAR2
3078          , p_auto_transact_code IN VARCHAR2 DEFAULT NULL
3079          , p_parent_transaction_type IN VARCHAR2 DEFAULT NULL
3080          , p_parent_parent_txn_type IN VARCHAR2 DEFAULT NULL
3081          , p_quantity IN NUMBER DEFAULT NULL
3082          ) return NUMBER
3083   is
3084 
3085      -- 1 defined But not used
3086      -- 3 Resides in Stores
3087      -- 4 Issued out of Stores
3088      -- 5 Resides in Intransit
3089 
3090      l_serial_status_new constant NUMBER := 1;
3091      l_serial_status_rcv constant NUMBER := 7;
3092      l_serial_status_inv constant NUMBER := 3;
3093      l_serial_status_intransit constant NUMBER := 5;
3094      l_serial_status_issued constant NUMBER := 4;
3095 
3096 Begin
3097    if p_transaction_type is null then
3098       return l_serial_status_new;
3099     elsif p_transaction_type = 'ACCEPT' then
3100       return l_serial_status_rcv;
3101     elsif p_transaction_type = 'REJECT' then
3102       return l_serial_status_rcv;
3103     elsif p_transaction_type = 'RECEIVE' THEN
3104       --Bug 7129718, we will always change the org of serial
3105       --   to receiving org and status to 'In Receiving' after receipt transaction.
3106       --   If its direct routing, then in the same session INV TM
3107       --   updates serial status to 'Resides in Stores'.
3108       --   Now, the LPN and the Serials will be in sync with each other.
3109       return l_serial_status_rcv;
3110 
3111       --IF (Nvl(p_auto_transact_code,'@@@@') <> 'DELIVER') THEN
3112       --   return l_serial_status_rcv;
3113       --ELSE
3114       --   -- Returns the status as -9999 otherwise fails for
3115       --   -- Direct routing cases in INV Txn Manager.
3116       --   -- and in update_serial_status when the values is -9999 don't
3117       --   -- update the status
3118       --   -- RETURN l_serial_status_inv;
3119       --   -- Bug 3184500
3120       --   return -9999;
3121       --END IF;
3122 
3123     elsif p_transaction_type = 'TRANSFER' then
3124       return l_serial_status_rcv;
3125     elsif p_transaction_type = 'DELIVER' then
3126       return l_serial_status_inv;
3127     elsif p_transaction_type = 'SHIP' then
3128       --Bug 4337726. A ship transaction with auto transact code as receive
3129       --should be treated like a receipt transaction
3130       IF (Nvl(p_auto_transact_code, 'SHIP') = 'RECEIVE') THEN
3131          RETURN l_serial_status_rcv;
3132        ELSE
3133          return l_serial_status_intransit;
3134       END IF;
3135     ELSIF p_transaction_type = 'RETURN TO RECEIVING' THEN
3136       RETURN l_serial_status_rcv;
3137     ELSIF p_transaction_type IN ('RETURN TO VENDOR', 'RETURN TO CUSTOMER') THEN
3138       RETURN l_serial_status_issued;
3139     ELSIF p_transaction_type = 'CORRECT' THEN
3140       IF (Nvl(p_parent_transaction_type,'@@@') IN ('ACCEPT','REJECT','TRANSFER')) THEN
3141 	 RETURN l_serial_status_rcv;
3142        ELSIF (Nvl(p_parent_transaction_type,'@@@') = 'DELIVER') THEN
3143 	 IF (Nvl(p_quantity, 0) < 0) THEN
3144 	    RETURN l_serial_status_rcv;
3145 	  ELSIF (Nvl(p_quantity, 0) > 0) THEN
3146 	    RETURN l_serial_status_inv;
3147 	  ELSE
3148 	    RETURN l_serial_status_new;
3149 	 END IF;
3150        ELSIF (Nvl(p_parent_transaction_type,'@@@') = 'RECEIVE') THEN
3151 	 IF (Nvl(p_quantity, 0) > 0) THEN
3152 	    RETURN l_serial_status_rcv;
3153 	  ELSE
3154 	    RETURN l_serial_status_new;
3155 	 END IF;
3156        ELSIF (Nvl(p_parent_transaction_type,'@@@') = 'RETURN TO RECEIVING') THEN
3157 	 IF (Nvl(p_quantity, 0) < 0) THEN
3158 	    RETURN l_serial_status_inv;
3159 	  ELSIF (Nvl(p_quantity, 0) > 0) THEN
3160 	    RETURN l_serial_status_rcv;
3161 	  ELSE
3162 	    RETURN l_serial_status_new;
3163 	 END IF;
3164        ELSIF (Nvl(p_parent_transaction_type,'@@@') IN ('RETURN TO VENDOR','RETURN TO CUSTOMER')) THEN
3165 	 IF(Nvl(p_quantity, 0) < 0) THEN
3166 	    IF (Nvl(p_parent_parent_txn_type,'@@@@') = 'DELIVER') THEN
3167 	       RETURN l_serial_status_inv;
3168 	     ELSIF p_parent_parent_txn_type IS NOT NULL THEN
3169 	       RETURN l_serial_status_rcv;
3170 	     ELSE
3171 	       RETURN l_serial_status_new;
3172 	    END IF;
3173 	  ELSIF (Nvl(p_quantity, 0) > 0) THEN
3174 	    RETURN l_serial_status_issued;
3175 	  ELSE
3176 	    RETURN l_serial_status_new;
3177          END IF;
3178        ELSE
3179 	 RETURN l_serial_status_new;
3180       END IF;
3181     else
3182       return l_serial_status_new;
3183    end if;
3184 Exception
3185    when others then
3186       return l_serial_status_new;
3187 End get_serial_status;
3188 
3189 -- Description
3190 -- THIS procedure updates the serial Status
3191 --
3192 PROCEDURE update_serial_status (  p_product_txn_id           IN NUMBER
3193 				  ,p_item_id                  IN NUMBER
3194 				  ,p_organization_id          IN NUMBER
3195 				  ,p_serial_status            IN NUMBER
3196 				  ,p_inspection_status        IN NUMBER
3197 				  ,p_sub                      IN VARCHAR2 default null
3198 				  ,p_locator_id               IN NUMBER default null
3199 				  ,x_return_status            OUT NOCOPY VARCHAR2
3200 				  ,x_msg_count                OUT NOCOPY NUMBER
3201 				  ,x_msg_data                 OUT NOCOPY VARCHAR2 ) IS
3202 
3203 				     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3204 				     l_progress VARCHAR2(15) := '10';
3205 			             l_count NUMBER; --bug 5008139
3206 				     l_comms_nl_trackable_flag mtl_system_items.comms_nl_trackable_flag%type;--Bug6374074
3207 				     l_destination_type        rcv_transactions_interface.destination_type_code%type;--Bug6374074
3208 				     l_clear_line_mark_id      number;--Bug6374074( if l_clear_line_mark_id = 1 then clear the line_mark_id field
3209 				                                      --            else preserve the line_mark_id field
3210 
3211 
3212 Begin
3213 
3214    x_return_status  := g_ret_sts_success;
3215    l_progress := 'WMSINB-12562';
3216 
3217    --BUG 5008139 -- Getting the count of serial records in MSNT
3218    select count(*)
3219    into   l_count
3220    from   mtl_serial_numbers_temp
3221    where  product_code = 'RCV'
3222    and    product_transaction_id = p_product_txn_id;
3223 
3224    IF (l_debug = 1) THEN
3225       print_debug('update_serial_status : l_count = '||l_count, 1);
3226    END IF;
3227 
3228    --Bug 7129718, we will always change the org of serial
3229    --   to receiving org after receipt transaction.
3230    --   If its direct routing, then in the same session INV TM
3231    --   updates serial status to 'Resides in Stores'.
3232    --   Now, the LPN and the Serials will be in sync with each other.
3233 
3234    --Bug: 5524134
3235    -- For direct deliver case we need not update the columns, if the serial
3236    -- status is -9999. This would ensure that the serial number uniqueness
3237    -- checks from inventory side goes through fine. These columns would be
3238    -- updated by the INV TM after serial uniqueness check.
3239    --
3240 
3241    --Bug#6374074:
3242    -- While receiving eIB tracked, 'Serial' or 'Lot and Serial' controlled items
3243    -- with Expense destination, hook maintained between Instal base and
3244    -- Receiving lost and because of this 'Instal base' is not able to view
3245    -- the Serial numbers in their forms.
3246    -- If the item is instalbased item and the transaction is for 'EXPENSE'
3247    -- destination, then dont clear the line_mark_id else we can clear the
3248    -- line_mark_id. Modified the update statments based on the above said condition.
3249 
3250    --Bug 5008139, running below update only if there are serial records in MSNT
3251 
3252    IF (l_count > 0) THEN
3253       --Bug 6374074, Checking whether the item is instal based tracked
3254       SELECT Nvl(comms_nl_trackable_flag,'N')
3255         INTO l_comms_nl_trackable_flag
3256         FROM mtl_system_items
3257        WHERE inventory_item_id = p_item_id
3258          AND organization_id= p_organization_id;
3259 
3260        IF l_comms_nl_trackable_flag = 'Y' THEN
3261          --Check whether this transaction is for EXPENSE destination
3262          --Then we have to preserve the line_mark_id and lot_line_mark_id
3263          SELECT nvl(destination_type_code,'dummy')
3264            INTO l_destination_type
3265            FROM rcv_transactions_interface
3266           WHERE interface_transaction_id = p_product_txn_id;
3267 
3268           IF l_destination_type = 'EXPENSE' THEN
3269              --Don't clear the line_mark_id and lot_line_mark_id
3270               l_clear_line_mark_id := 0;
3271           ELSE
3272               --Clear the line_mark_id and lot_line_mark_id
3273               l_clear_line_mark_id := 1;
3274           END IF;
3275        ELSE--IF l_comms_nl_trackable_flag = 'Y' THEN
3276           l_clear_line_mark_id := 1;
3277        END IF;--IF l_comms_nl_trackable_flag = 'Y' THEN
3278 
3279        -- Bug 7129718, Replacing all the branching by a single update.
3280        --    serial status of -9999 won't come into picture now as even during direct routing,
3281        --    we set serial status to 'In Receiving'. INV TM will change the status to
3282        --    'Resides in Stores' in the same session.
3283 
3284        -- Bug 7427382 Updating columns owning org and planning org also.
3285 
3286        update mtl_serial_numbers msn
3287           set msn.current_status = p_serial_status
3288             , inspection_status = p_inspection_status
3289             , group_mark_id = NULL
3290             , line_mark_id = decode(l_clear_line_mark_id, 1, NULL, line_mark_id)
3291             , lot_line_mark_id = decode(l_clear_line_mark_id, 1, NULL, lot_line_mark_id)
3292             , current_organization_id = p_organization_id
3293             , owning_organization_id = decode(owning_tp_type, 2, p_organization_id, owning_organization_id)
3294             , planning_organization_id = decode(planning_tp_type, 2, p_organization_id, planning_organization_id)
3295             , current_subinventory_code = p_sub
3296             , current_locator_id = p_locator_id
3297         where
3298            -- msn.inventory_item_id       = p_item_id
3299            -- and msn.current_organization_id = p_organization_id -- this part is not needed as this was causing INTSHIP RECEIVE to fail
3300            -- BUG 5611567
3301               msn.ROWID in (
3302                    select msn1.ROWID
3303                      from mtl_serial_numbers msn1
3304                         , mtl_serial_numbers_temp msnt
3305                     where msn1.inventory_item_id = p_item_id
3306                       and msnt.product_code = 'RCV'
3307                       and msnt.product_transaction_id = p_product_txn_id
3308                       and msn1.serial_number between msnt.fm_serial_number and msnt.to_serial_number
3309                       AND Length(msn1.serial_number) = Length(msnt.fm_serial_number)
3310                       AND length(msnt.fm_serial_number)=Length(nvl(msnt.to_serial_number,msnt.fm_serial_number))  --BUG 3818544
3311                            );
3312 
3313 
3314 --      --BEGIN Bug: 5524134
3315 --      IF p_serial_status = -9999 THEN
3316 --         IF l_clear_line_mark_id = 1  THEN --{
3317 --            update mtl_serial_numbers msn
3318 --            set
3319 --             group_mark_id = NULL,
3320 --             line_mark_id = NULL,
3321 --             lot_line_mark_id = NULL
3322 --            where msn.inventory_item_id       = p_item_id
3323 --            -- and msn.current_organization_id = p_organization_id -- this part is not needed as this was causing INTSHIP RECEIVE to fail
3324 --            and exists ( select 1
3325 --                     from mtl_serial_numbers_temp msnt
3326 --                     where msnt.product_code = 'RCV'
3327 --                     and msnt.product_transaction_id = p_product_txn_id
3328 --                     and msn.serial_number between msnt.fm_serial_number and msnt.to_serial_number
3329 --                     AND Length(msn.serial_number) = Length(msnt.fm_serial_number)
3330 --                     AND length(msnt.fm_serial_number)=Length(Nvl(msnt.to_serial_number,msnt.fm_serial_number))  --BUG 3818544
3331 --                     )
3332 --            ;
3333 --         ELSE --l_clear_line_mark_id = 1 }{
3334 --            update mtl_serial_numbers msn
3335 --            set
3336 --             group_mark_id = NULL
3337 --            where msn.inventory_item_id       = p_item_id
3338 --            -- and msn.current_organization_id = p_organization_id -- this part is not needed as this was causing INTSHIP RECEIVE to fail
3339 --            and exists ( select 1
3340 --                     from mtl_serial_numbers_temp msnt
3341 --                     where msnt.product_code = 'RCV'
3342 --                     and msnt.product_transaction_id = p_product_txn_id
3343 --                     and msn.serial_number between msnt.fm_serial_number and msnt.to_serial_number
3344 --                     AND Length(msn.serial_number) = Length(msnt.fm_serial_number)
3345 --                     AND length(msnt.fm_serial_number)=Length(Nvl(msnt.to_serial_number,msnt.fm_serial_number))  --BUG 3818544
3346 --                     )
3347 --            ;
3348 --         END IF;--l_clear_line_mark_id = 1 }
3349 --      ELSE
3350 --      --END Bug: 5524134
3351 --         IF l_clear_line_mark_id = 1  THEN --{
3352 --            update mtl_serial_numbers msn
3353 --              set msn.current_status = p_serial_status
3354 --              , inspection_status = p_inspection_status
3355 --              , group_mark_id = NULL
3356 --              , line_mark_id = NULL
3357 --              , lot_line_mark_id = NULL
3358 --              , current_organization_id = p_organization_id
3359 --              , current_subinventory_code = p_sub
3360 --              , current_locator_id = p_locator_id
3361 --                where
3362 --              -- msn.inventory_item_id       = p_item_id
3363 --              -- and msn.current_organization_id = p_organization_id -- this part is not needed as this was causing INTSHIP RECEIVE to fail
3364 --                      -- BUG 5611567
3365 --                      msn.ROWID in ( select msn1.ROWID
3366 --                           from mtl_serial_numbers msn1 ,
3367 --                           mtl_serial_numbers_temp msnt
3368 --                           where msn1.inventory_item_id = p_item_id
3369 --                           and msnt.product_code = 'RCV'
3370 --                           and msnt.product_transaction_id = p_product_txn_id
3371 --                           and msn1.serial_number between msnt.fm_serial_number and msnt.to_serial_number
3372 --                           AND Length(msn1.serial_number) = Length(msnt.fm_serial_number)
3373 --                           AND length(msnt.fm_serial_number)=Length(nvl(msnt.to_serial_number,msnt.fm_serial_number))  --BUG 3818544
3374 --                           )
3375 --            ;
3376 --         ELSE--l_clear_line_mark_id = 1 }{
3377 --            update mtl_serial_numbers msn
3378 --              set msn.current_status = p_serial_status
3379 --              , inspection_status = p_inspection_status
3380 --              , group_mark_id = NULL
3381 --              , current_organization_id = p_organization_id
3382 --              , current_subinventory_code = p_sub
3383 --              , current_locator_id = p_locator_id
3384 --                where
3385 --              -- msn.inventory_item_id       = p_item_id
3386 --              -- and msn.current_organization_id = p_organization_id -- this part is not needed as this was causing INTSHIP RECEIVE to fail
3387 --                      -- BUG 5611567
3388 --                      msn.ROWID in ( select msn1.ROWID
3389 --                           from mtl_serial_numbers msn1 ,
3390 --                           mtl_serial_numbers_temp msnt
3391 --                           where msn1.inventory_item_id = p_item_id
3392 --                           and msnt.product_code = 'RCV'
3393 --                           and msnt.product_transaction_id = p_product_txn_id
3394 --                           and msn1.serial_number between msnt.fm_serial_number and msnt.to_serial_number
3395 --                           AND Length(msn1.serial_number) = Length(msnt.fm_serial_number)
3396 --                           AND length(msnt.fm_serial_number)=Length(nvl(msnt.to_serial_number,msnt.fm_serial_number))  --BUG 3818544
3397 --                           )
3398 --            ;
3399 --         END IF;--l_clear_line_mark_id = 1 }
3400 --      --End of bug 6374074
3401 --    END IF; --BUG 5524134
3402     END IF; --BUG 5008139
3403    l_progress := 'WMSINB-12577';
3404 Exception
3405    when others then
3406       x_return_status  := g_ret_sts_unexp_error;
3407       IF (l_debug = 1) THEN
3408          print_debug('update_serial_status  : - other exception:'|| l_progress || ' ' ||
3409                      TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
3410       END IF;
3411       IF SQLCODE IS NOT NULL THEN
3412          inv_mobile_helper_functions.sql_error('inv_rcv_integration_pvt.update_serial_status',l_progress, SQLCODE);
3413       END IF;
3414       --  Get message count and data
3415       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
3416 
3417 End update_serial_status;
3418 
3419 
3420 -- Description
3421 -- THIS procedure updates the context/ org/ sub/ locator of LPN
3422 --
3423 PROCEDURE update_lpn_location_context ( p_organization_id          IN NUMBER
3424 					,p_sub                      IN VARCHAR2
3425 					,p_locator                  IN NUMBER
3426 					,p_lpn_context              IN NUMBER
3427 					,p_lpn_id                   IN NUMBER
3428 					,x_return_status            OUT NOCOPY VARCHAR2
3429 					,x_msg_count                OUT NOCOPY NUMBER
3430 					,x_msg_data                 OUT NOCOPY VARCHAR2
3431 					,p_source_name              IN VARCHAR2 DEFAULT NULL
3432 					,p_source_header_id         IN NUMBER DEFAULT NULL
3433 					,p_source_type_id           IN NUMBER DEFAULT NULL) IS
3434 
3435 					   l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3436 					   l_progress VARCHAR2(15) := '10';
3437 					   l_lpn_rec WMS_LICENSE_PLATE_NUMBERS%rowtype;
3438 
3439 BEGIN
3440 
3441    -- Initialize API return status to success
3442    x_return_status  := g_ret_sts_success;
3443 
3444    l_progress := 'WMSINB-12617';
3445 
3446    l_lpn_rec.lpn_id := p_lpn_id;
3447 
3448    if p_lpn_context is not null then
3449       l_lpn_rec.lpn_context := p_lpn_context;
3450    End if;
3451 
3452    l_lpn_rec.SUBINVENTORY_CODE := p_sub;
3453    l_lpn_rec.LOCATOR_ID := p_locator;
3454    l_lpn_rec.ORGANIZATION_ID := p_organization_id ;
3455    l_lpn_rec.source_header_id := p_source_header_id;
3456    l_lpn_rec.source_name := p_source_name;
3457    l_lpn_rec.source_type_id := p_source_type_id;
3458 
3459    IF (l_debug = 1) THEN
3460       print_debug(' update_lpn_location_context : lpn_id = '||p_lpn_id,1);
3461       print_debug(' update_lpn_location_context : lpn_context = '|| p_lpn_context , 1);
3462       print_debug(' update_lpn_location_context : sub = '|| p_sub , 1);
3463       print_debug(' update_lpn_location_context : locator = '|| p_locator , 1);
3464       print_debug(' update_lpn_location_context : organization_id = '|| p_organization_id , 1);
3465       print_debug(' update_lpn_location_context : source_header_id = '|| p_source_header_id , 1);
3466       print_debug(' update_lpn_location_context : source_name = '|| p_source_name , 1);
3467       print_debug(' update_lpn_location_context : source_type_id = '|| p_source_type_id , 1);
3468    END IF;
3469 
3470    wms_container_pvt.modify_lpn ( p_api_version           => 1.0,
3471 				  x_return_status         =>    x_return_status ,
3472 				  x_msg_count             =>    x_msg_count ,
3473 				  x_msg_data              =>    x_msg_data,
3474 				  p_validation_level      =>    fnd_api.g_valid_level_none,
3475 				  p_lpn                   =>    l_lpn_rec);
3476 
3477    l_progress := 'WMSINB-12645';
3478 
3479    -- Check the error status from the above call
3480    if x_return_status <> G_RET_STS_SUCCESS Then
3481       --  Review Late Set Appropiate Message
3482       l_progress := 'WMSINB-12650';
3483       RAISE FND_API.G_EXC_ERROR;
3484    End if;
3485 
3486 Exception
3487    when others then
3488       x_return_status  := g_ret_sts_unexp_error;
3489       IF (l_debug = 1) THEN
3490          print_debug('update_lpn_location_context : - other exception:'|| l_progress || ' ' ||
3491                      TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
3492       END IF;
3493       IF SQLCODE IS NOT NULL THEN
3494          inv_mobile_helper_functions.sql_error('inv_rcv_integration_pvt.update_lpn_location_context',l_progress, SQLCODE);
3495       END IF;
3496       --  Get message count and data
3497       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
3498 
3499 END update_lpn_location_context ;
3500 
3501 Function get_lpn_context(p_transaction_type IN VARCHAR2
3502 			 , p_routing_header_id IN NUMBER DEFAULT NULL
3503 			 , p_parent_transaction_type IN VARCHAR2 DEFAULT NULL
3504 			 , p_parent_parent_txn_type IN VARCHAR2 DEFAULT NULL
3505 			 , p_quantity IN NUMBER DEFAULT NULL
3506 			 , p_auto_transact_code IN VARCHAR2 DEFAULT NULL
3507 			 ) return NUMBER
3508   is
3509 Begin
3510    if p_transaction_type is null then
3511       return G_LPN_CONTEXT_PREGENERATED;
3512     elsif p_transaction_type = 'ACCEPT' then
3513       return G_LPN_CONTEXT_RCV;
3514     elsif p_transaction_type = 'REJECT' then
3515       return G_LPN_CONTEXT_RCV;
3516     elsif p_transaction_type = 'RECEIVE' THEN
3517       IF (Nvl(p_auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN
3518 	 return G_LPN_CONTEXT_RCV;
3519        ELSE
3520 	 RETURN g_lpn_context_inv;
3521       END IF;
3522     elsif p_transaction_type = 'TRANSFER' then
3523       return G_LPN_CONTEXT_RCV;
3524     elsif p_transaction_type = 'DELIVER' then
3525       return G_LPN_CONTEXT_INV;
3526     elsif p_transaction_type = 'SHIP' then
3527       --Bug 4337726. A ship transaction with auto transact code as receive
3528       --should be treated like a receipt transaction
3529       IF (Nvl(p_auto_transact_code, 'SHIP') = 'RECEIVE') THEN
3530          RETURN g_lpn_context_rcv;
3531        ELSE
3532          RETURN G_LPN_CONTEXT_VENDOR;
3533       END IF;
3534     ELSIF p_transaction_type = 'RETURN TO RECEIVING' THEN
3535       RETURN g_lpn_context_rcv;
3536     ELSIF p_transaction_type IN ('RETURN TO VENDOR', 'RETURN TO CUSTOMER') THEN
3537       RETURN g_lpn_context_stores;
3538     ELSIF p_transaction_type = 'CORRECT' THEN
3539       IF (Nvl(p_parent_transaction_type,'@@@') IN ('ACCEPT','REJECT','TRANSFER')) THEN
3540 	 RETURN g_lpn_context_rcv;
3541        ELSIF (Nvl(p_parent_transaction_type,'@@@') = 'DELIVER') THEN
3542 	 IF (Nvl(p_quantity, 0) < 0) THEN
3543 	    RETURN g_lpn_context_rcv;
3544 	  ELSIF (Nvl(p_quantity, 0) > 0) THEN
3545 	    RETURN g_lpn_context_inv;
3546 	  ELSE
3547 	    RETURN g_lpn_context_pregenerated;
3548 	 END IF;
3549        ELSIF (Nvl(p_parent_transaction_type,'@@@') = 'RECEIVE') THEN
3550 	 IF (Nvl(p_quantity, 0) > 0) THEN
3551 	    RETURN g_lpn_context_rcv;
3552 	  ELSE
3553 	    RETURN g_lpn_context_pregenerated;
3554 	 END IF;
3555        ELSIF (Nvl(p_parent_transaction_type,'@@@') = 'RETURN TO RECEIVING') THEN
3556 	 IF (Nvl(p_quantity, 0) < 0) THEN
3557 	    RETURN g_lpn_context_inv;
3558 	  ELSIF (Nvl(p_quantity, 0) > 0) THEN
3559 	    RETURN g_lpn_context_rcv;
3560 	  ELSE
3561 	    RETURN g_lpn_context_pregenerated;
3562 	 END IF;
3563        ELSIF (Nvl(p_parent_transaction_type,'@@@') IN ('RETURN TO VENDOR','RETURN TO CUSTOMER')) THEN
3564 	 IF(Nvl(p_quantity, 0) < 0) THEN
3565 	    IF (Nvl(p_parent_parent_txn_type,'@@@@') = 'DELIVER') THEN
3566 	       RETURN g_lpn_context_inv;
3567 	     ELSIF p_parent_parent_txn_type IS NOT NULL THEN
3568 	       RETURN g_lpn_context_rcv;
3569 	     ELSE
3570 	       RETURN g_lpn_context_pregenerated;
3571 	    END IF;
3572 	  ELSIF (Nvl(p_quantity, 0) > 0) THEN
3573 	    RETURN g_lpn_context_stores;
3574 	  ELSE
3575 	    RETURN g_lpn_context_pregenerated;
3576          END IF;
3577        ELSE
3578 	 RETURN g_lpn_context_pregenerated;
3579       END IF;
3580     else
3581       return G_LPN_CONTEXT_PREGENERATED;
3582    end if;
3583 Exception
3584    when others then
3585       return G_LPN_CONTEXT_PREGENERATED;
3586 End get_lpn_context;
3587 
3588 -- R12
3589 PROCEDURE  check_reference(
3590                             p_old_reference           IN VARCHAR2
3591                            ,p_old_reference_type_code IN NUMBER
3592                            ,p_old_reference_id        IN NUMBER
3593                            ,p_new_reference           IN VARCHAR2
3594                            ,p_new_reference_type_code IN NUMBER
3595                            ,p_new_reference_id        IN NUMBER
3596                            ,x_reference               OUT NOCOPY  VARCHAR2
3597                            ,x_reference_type_code     OUT NOCOPY NUMBER
3598                            ,x_reference_id            OUT NOCOPY NUMBER
3599                            ,x_transaction_type_id     OUT NOCOPY NUMBER
3600                            ,x_txn_source_type_id      OUT NOCOPY NUMBER
3601                            ,x_return_status           OUT NOCOPY VARCHAR2
3602                            ,x_msg_count               OUT NOCOPY NUMBER
3603                            ,x_msg_data                OUT NOCOPY VARCHAR2
3604                           ) is
3605 
3606 L_DEBUG NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3607 l_progress      VARCHAR2(15) := '40400';
3608 l_proc_name     VARCHAR2(30) := 'CHECK_REFERENCE';
3609 l_same_doc      NUMBER;
3610 l_asn_line_flag VARCHAR2(1);
3611 
3612 Begin
3613 
3614    x_return_status := g_ret_sts_success;
3615 
3616    IF (l_debug = 1) THEN
3617       print_debug('Entering '||l_proc_name||':'|| l_progress,1);
3618       print_debug('p_old_reference           = '||p_old_reference ,1);
3619       print_debug('p_old_reference_type_code = '||p_old_reference_type_code ,1);
3620       print_debug('p_old_reference_id        = '||p_old_reference_id ,1);
3621       print_debug('p_new_reference           = '||p_new_reference ,1);
3622       print_debug('p_new_reference_type_code = '||p_new_reference_type_code ,1);
3623       print_debug('p_new_reference_id        = '||p_new_reference_id ,1);
3624       l_progress := 'WMSINB-40400';
3625    END IF;
3626 
3627    x_reference           := p_new_reference;
3628    x_reference_type_code := p_new_reference_type_code;
3629    x_reference_id        := p_new_reference_id;
3630 
3631    l_progress := 'WMSINB-40401';
3632 
3633    if nvl(p_old_reference,'@#$') = nvl(p_new_reference,'@#$') then
3634       if nvl(p_old_reference_id,-9999) = nvl(p_new_reference_id,-9999) then
3635            IF (l_debug = 1) THEN
3636               print_debug(l_proc_name||' Reference Ids are same '|| l_progress,1);
3637            End if;
3638        Else
3639            IF (l_debug = 1) THEN
3640               print_debug(l_proc_name||' Reference Ids are different '|| l_progress,1);
3641            End if;
3642 
3643            l_progress := 'WMSINB-40404';
3644 
3645            -- REFERENCE INFO IS FROM THE SAME DOC TYPE BUT FROM DIFF DOCS
3646 
3647            -- KEEP THE SAME DOC TYPE BUT PUT THE ID's AS NULL IF THEY
3648            -- POINT TO DIFF DOCS.
3649 
3650            If p_new_reference = 'PO_LINE_LOCATION_ID' then
3651               IF (l_debug = 1) THEN
3652                  print_debug(l_proc_name||' CHECK FOR PO '|| l_progress,1);
3653               End if;
3654               BEGIN
3655                  select 1
3656                    into l_same_doc
3657                    from PO_LINE_LOCATIONS_ALL POLL
3658                   where POLL.LINE_LOCATION_ID = p_old_reference_id
3659                     and POLL.PO_HEADER_ID in ( select POLL1.PO_HEADER_ID
3660                                               from PO_LINE_LOCATIONS_ALL POLL1
3661                                              where POLL1.LINE_LOCATION_ID
3662                                                      = p_new_reference_id )
3663                     and rownum < 2;
3664 
3665                     l_progress := 'WMSINB-40405';
3666 
3667               EXCEPTION
3668                 WHEN OTHERS THEN
3669                     l_progress := 'WMSINB-40406';
3670                     IF (l_debug = 1) THEN
3671                        print_debug(l_proc_name||' POs  are different '|| l_progress,1);
3672                     End if;
3673                     x_reference_id        := NULL;
3674               END;
3675            End if;
3676 
3677            If p_new_reference = 'ORDER_LINE_ID' then
3678                l_progress := 'WMSINB-40407';
3679                IF (l_debug = 1) THEN
3680                  print_debug(l_proc_name||' CHECK FOR RMA '|| l_progress,1);
3681                End if;
3682                BEGIN
3683                  select 1
3684                    into l_same_doc
3685                    from OE_ORDER_LINES_ALL OEL
3686                   where OEL.LINE_ID = p_old_reference_id
3687                     and OEL.HEADER_ID in ( select OEL1.HEADER_ID
3688                                               from OE_ORDER_LINES_ALL OEL1
3689                                              where OEL1.LINE_ID
3690                                                      = p_new_reference_id )
3691                     and rownum < 2;
3692                   l_progress := 'WMSINB-40408';
3693               EXCEPTION
3694                 WHEN OTHERS THEN
3695                     l_progress := 'WMSINB-40409';
3696                     IF (l_debug = 1) THEN
3697                        print_debug(l_proc_name||' ORDERS are different '|| l_progress,1);
3698                     End if;
3699                     x_reference_id        := NULL;
3700                END;
3701            End if;
3702 
3703            If p_new_reference = 'SHIPMENT_LINE_ID' then
3704               BEGIN
3705                  l_progress := 'WMSINB-40410';
3706 
3707                  select nvl(asn_line_flag,'N')
3708                    into l_asn_line_flag
3709                    from rcv_shipment_lines rsl
3710                   where rsl.shipment_line_id = p_old_reference_id
3711                   ;
3712 
3713                  If l_asn_line_flag = 'Y' then
3714                    -- CASE FOR ASN
3715                      SELECT 1
3716                        INTO l_same_doc
3717                        FROM rcv_shipment_lines rsl, po_line_locations_all poll
3718                       WHERE rsl.shipment_line_id = p_old_reference_id
3719                         AND poll.line_location_id = rsl.po_line_location_id
3720                         AND poll.po_header_id in ( select poll1.po_header_id
3721                                                      from rcv_shipment_lines rsl1, po_line_locations_all poll1
3722                                                     where rsl1.shipment_line_id = p_new_reference_id
3723                                                       and poll1.line_location_id = rsl1.po_line_location_id )
3724                         AND rownum < 2;
3725                         l_progress := 'WMSINB-40411';
3726                   Else
3727                     -- CASE FOR INTSHIP/INTREQ
3728                     l_progress := 'WMSINB-40412';
3729                        SELECT 1
3730                        INTO l_same_doc
3731                        FROM rcv_shipment_lines rsl
3732                       WHERE rsl.shipment_line_id = p_old_reference_id
3733                         AND rsl.shipment_header_id in ( select rsl1.shipment_header_id
3734                                                           from rcv_shipment_lines rsl1
3735                                                          where rsl1.shipment_line_id = p_new_reference_id
3736                                                       )
3737                         AND rownum < 2;
3738                         l_progress := 'WMSINB-40413';
3739                   End if;
3740               EXCEPTION
3741                 WHEN OTHERS THEN
3742                     l_progress := 'WMSINB-40414';
3743                     IF (l_debug = 1) THEN
3744                        print_debug(l_proc_name||' SHIPMENT DIFFERENT '|| l_progress,1);
3745                     End if;
3746                     x_reference_id        := NULL;
3747               END;
3748            End if;
3749 
3750        End if;
3751    Else
3752        IF (l_debug = 1) THEN
3753            print_debug(l_proc_name||' Reference Types are different '|| l_progress,1);
3754        End if;
3755        l_progress := 'WMSINB-40415';
3756        x_reference           := null;
3757        x_reference_type_code := null;
3758        x_reference_id        := null;
3759 
3760        x_transaction_type_id := 81;   -- CHANGE IT WITH THE RIGHT TXN TYPE -- VISHY ?????
3761        x_txn_source_type_id  := 4;
3762    End if;
3763 
3764    IF (l_debug = 1) THEN
3765          print_debug(l_proc_name||' x_reference = '|| x_reference,1);
3766          print_debug(l_proc_name||' x_reference_type_code = '|| x_reference_type_code,1);
3767          print_debug(l_proc_name||' x_reference_id = '|| x_reference_id,1);
3768          print_debug(l_proc_name||' x_transaction_type_id = '|| x_transaction_type_id,1);
3769          print_debug(l_proc_name||' x_txn_source_type_id = '|| x_txn_source_type_id,1);
3770    End if;
3771 
3772 EXCEPTION
3773    WHEN OTHERS THEN
3774       IF (l_debug = 1) THEN
3775          print_debug('CHECK_REFERENCE: Exception occured aftr l_progress = '
3776                      || l_progress,1);
3777       END IF;
3778       x_return_status := g_ret_sts_unexp_error;
3779 End check_reference;
3780 -- R12
3781 
3782 -- R12
3783 PROCEDURE maintain_mo_con(p_rti_id IN NUMBER,
3784 		      p_primary_quantity IN NUMBER,
3785 		      p_primary_uom_code IN VARCHAR2,
3786 		      p_mmtt_temp_id IN NUMBER,
3787 		      p_org_id IN NUMBER,
3788 		      p_item_id IN NUMBER,
3789 		      p_revision IN VARCHAR2,
3790 		      p_qty IN NUMBER,
3791 		      p_uom_code IN VARCHAR2,
3792 		      p_lpn_id IN NUMBER,
3793 		      p_transfer_lpn_id IN NUMBER,
3794 		      p_lot_control_code IN NUMBER,
3795 		      p_serial_number_control_code IN NUMBER,
3796 		      p_lot_number IN VARCHAR2,
3797 		      p_po_line_location_id IN NUMBER,
3798 		      p_po_distribution_id IN NUMBER,
3799 		      p_shipment_line_id IN NUMBER,
3800 		      p_oe_order_line_id IN NUMBER,
3801 		      p_routing_header_id IN NUMBER,
3802 		      p_subinventory IN VARCHAR2,
3803 		      p_locator_id IN NUMBER,
3804 		      p_from_subinventory IN VARCHAR2,
3805 		      p_from_locator_id IN NUMBER,
3806 		      p_project_id IN NUMBER DEFAULT NULL,
3807 		      p_task_id IN NUMBER DEFAULT NULL,
3808 		      x_transaction_id OUT nocopy NUMBER,
3809 		      x_return_status OUT nocopy VARCHAR2,
3810 		      x_msg_count OUT nocopy NUMBER,
3811 		      x_msg_data OUT nocopy VARCHAR2,
3812                       -- OPMConvergence
3813                       p_sec_qty IN NUMBER DEFAULT NULL,
3814                       p_sec_uom IN VARCHAR DEFAULT NULL,
3815                       -- OPMConvergence
3816                       p_auto_transact_code IN VARCHAR2 DEFAULT NULL,
3817                       p_asn_line_flag IN VARCHAR2 DEFAULT NULL ,
3818                       p_validation_flag IN VARCHAR2 DEFAULT NULL,
3819                       -- Bug# 7154105
3820                       p_req_distribution_id IN NUMBER DEFAULT NULL
3821   )
3822   IS
3823      /* Bug: 5064782: Modified the where clause condition for project_id and task_id
3824                       for the cursors c_mol_mmtt and c_mol_no_mmtt */
3825 
3826      CURSOR c_mol_mmtt (
3827                         p_mmtt_id NUMBER,
3828                         p_item NUMBER,
3829                         p_lpn NUMBER,
3830 			p_lot VARCHAR2,
3831                         p_rev VARCHAR2,
3832                         p_from_sub varchar2,
3833                         p_from_locator_id NUMBER,
3834                         p_project_id NUMBER,
3835                         p_task_id NUMBER,
3836                         p_inspection_status NUMBER
3837      ) IS
3838 	SELECT DISTINCT mtrl.line_id
3839           , 1 UOM_ORDERING
3840 	  , mmtt.transaction_temp_id
3841 	  , mtrl.wms_process_flag
3842 	  , 1 quantity_ordering
3843 	  , (mtrl.quantity - Nvl(mtrl.quantity_delivered, 0)) quantity
3844 	  , mtrl.primary_quantity
3845 	  , mtrl.uom_code
3846 	  , mtrl.lpn_id
3847 	  , mtrl.inventory_item_id
3848 	  , mtrl.lot_number
3849           -- OPMConvergence
3850           , (mtrl.secondary_quantity - Nvl(mtrl.secondary_quantity_delivered, 0)) secondary_quantity_2
3851 	  , mtrl.secondary_quantity
3852 	  , mtrl.secondary_uom_code
3853           , mtrl.crossdock_type
3854           -- OPMConvergence
3855           , mtrl.backorder_delivery_detail_id
3856           , mmtt.wip_supply_type
3857           , mtrl.reference
3858           , mtrl.reference_type_code
3859           , mtrl.reference_id
3860 	  , mtrl.quantity txn_qty
3861 	  , mtrl.quantity_detailed quantity_detailed
3862 	  , mtrl.quantity_delivered quantity_delivered
3863 	  FROM mtl_txn_request_lines mtrl
3864 	  , mtl_material_transactions_temp mmtt
3865 	WHERE mtrl.organization_id = p_org_id
3866           AND nvl(mtrl.from_subinventory_code,'@$#_') = nvl(p_from_sub,'@$#_')
3867           AND nvl(mtrl.from_locator_id,-1) = nvl(p_from_locator_id,-1)
3868           AND ( nvl(mtrl.project_id,-1) = nvl(p_project_id,-1) OR p_project_id IS NULL )
3869           AND ( nvl(mtrl.task_id,-1) = nvl(p_task_id,-1) OR p_task_id IS NULL )
3870           AND Nvl(inspection_status,-1)    = Nvl(p_inspection_status,-1)
3871           AND mtrl.inventory_item_id = p_item
3872           AND Nvl(mtrl.revision, Nvl(p_rev, '@@@@')) = Nvl(p_rev, '@@@@')
3873           AND Nvl(mtrl.lpn_id, -1) = Nvl(p_lpn, -1)
3874           AND Nvl(mtrl.lot_number, Nvl(p_lot,'@$#_')) = Nvl(p_lot, '@$#_')
3875 	  AND mmtt.transaction_temp_id = p_mmtt_id
3876 	  AND mmtt.move_order_line_id = mtrl.line_id
3877 	  AND (mtrl.quantity - Nvl(mtrl.quantity_delivered, 0)) > 0
3878 	  AND mtrl.line_status <> inv_globals.G_TO_STATUS_CLOSED
3879 	  AND exists (SELECT 1
3880 		      FROM  mtl_txn_request_headers mtrh
3881 		      WHERE mtrh.move_order_type = inv_globals.g_move_order_put_away
3882 		      AND   mtrh.header_id = mtrl.header_id)
3883 	  ORDER BY 3 DESC;
3884 
3885      l_mol_rec c_mol_mmtt%ROWTYPE;
3886 
3887      CURSOR c_mol_no_mmtt (
3888                            p_item NUMBER,
3889                            p_lpn NUMBER,
3890 			   p_lot VARCHAR2,
3891                            p_rev VARCHAR2,
3892                            p_from_sub varchar2,
3893                            p_from_locator_id NUMBER,
3894                            -- p_cost_group_id NUMBER, ????
3895                            p_project_id NUMBER,
3896                            p_task_id NUMBER,
3897                            p_inspection_status NUMBER ,
3898                            p_uom_code varchar2
3899                    ) IS
3900  		              --Bug 5231114:Added the condition on transaction_source_type_id and
3901                               -- transaction_action_id for the following combinations:13/12 and 4/27
3902 			      SELECT DISTINCT mtrl.line_id
3903                                 , Decode(p_uom_code,mtrl.uom_code,2,1)
3904 				uom_ordering --changed the order
3905 		                -- we are doing a order by desc
3906 				, Decode(mmtt.transaction_source_type_id||'#'||mmtt.transaction_action_id,'1#27',1,
3907 					 '7#12',1,'12#27',1,'13#12',1,'4#27',1, null) transaction_temp_id
3908 				, Nvl(mtrl.wms_process_flag,1)--when ordering by DESC, NULL would come first;
3909 				                              --just do an NVL here
3910 				, Decode(mtrl.primary_quantity
3911 					 ,p_primary_quantity
3912 					 ,1
3913 					 ,2) quantity_ordering
3914 				, (mtrl.quantity - Nvl(mtrl.quantity_delivered, 0)) quantity
3915 				, mtrl.primary_quantity
3916 				, mtrl.uom_code
3917 				, mtrl.lpn_id
3918 				, mtrl.inventory_item_id
3919 				, mtrl.lot_number
3920                                 -- OPMConvergence
3921 				, (mtrl.secondary_quantity - Nvl(mtrl.secondary_quantity_delivered, 0)) secondary_quantity_2
3922 	                        , mtrl.secondary_quantity
3923 	                        , mtrl.secondary_uom_code
3924                                 -- OPMConvergence
3925                                 , mtrl.crossdock_type
3926                                 , mtrl.backorder_delivery_detail_id
3927                                 , mmtt.wip_supply_type
3928                                 , mtrl.reference
3929                                 , mtrl.reference_type_code
3930                                 , mtrl.reference_id
3931 				, mtrl.quantity txn_qty
3932 				, mtrl.quantity_detailed quantity_detailed
3933 				, mtrl.quantity_delivered quantity_delivered
3934 				FROM mtl_txn_request_lines mtrl
3935 				, mtl_material_transactions_temp mmtt
3936 				WHERE mtrl.organization_id = p_org_id
3937                                 AND nvl(mtrl.from_subinventory_code,'@$#_') = nvl(p_from_sub,'@$#_')
3938                                 AND nvl(mtrl.from_locator_id,-1) = nvl(p_from_locator_id,-1)
3939                                 AND ( nvl(mtrl.project_id,-1) = nvl(p_project_id,-1) OR p_project_id IS NULL )
3940                                 AND ( nvl(mtrl.task_id,-1) = nvl(p_task_id,-1) OR p_task_id IS NULL )
3941                                 AND Nvl(inspection_status,-1)    = Nvl(p_inspection_status,-1)
3942 				AND mtrl.inventory_item_id = p_item
3943 				AND Nvl(mtrl.revision, Nvl(p_rev, '@@@@')) = Nvl(p_rev, '@@@@')
3944 				AND Nvl(mtrl.lpn_id, -1) = Nvl(p_lpn, -1)
3945 				AND Nvl(mtrl.lot_number, Nvl(p_lot,'@$#_')) = Nvl(p_lot, '@$#_')
3946 				AND (mtrl.quantity - Nvl(mtrl.quantity_delivered, 0)) > 0
3947 				AND mmtt.move_order_line_id (+) = mtrl.line_id
3948 				AND mmtt.organization_id (+) = mtrl.organization_id
3949 				AND mtrl.line_status <> inv_globals.G_TO_STATUS_CLOSED
3950 				AND exists (SELECT 1
3951 					    FROM  mtl_txn_request_headers mtrh
3952 					    WHERE mtrh.move_order_type = inv_globals.g_move_order_put_away
3953 					    AND   mtrh.header_id = mtrl.header_id)
3954 				ORDER BY 2, 3 DESC, 4 DESC, 5;--order on 3 should be DESC because,
3955                                                               --if it is not, NULL values wouuld come last
3956 
3957      CURSOR c_transfer_mol ( p_lpn NUMBER
3958                             ,p_item NUMBER
3959                             ,p_lot VARCHAR2
3960                             ,p_rev VARCHAR2
3961                             ,p_from_sub VARCHAR2
3962                             ,p_from_locator_id NUMBER
3963                             -- ,p_cost_group_id NUMBER
3964                             ,p_project_id    NUMBER
3965                             ,p_task_id NUMBER
3966                             ,p_uom_code varchar2
3967                             ,p_backorder_delivery_detail_id NUMBER
3968                             ,p_crossdock_type varchar2
3969                             ,p_transfer_inspection_status NUMBER
3970                             ) IS
3971                               SELECT
3972                                  mtrl.line_id                 line_id
3973                                 -- Added columns below to make ordering same for both
3974                                 -- from and transfer cursor
3975                                 , Decode(p_uom_code,mtrl.uom_code,2,1) uom_ordering
3976 				, mtrl.wms_process_flag
3977 				, Decode(mtrl.primary_quantity
3978 					 ,p_primary_quantity
3979 					 ,1
3980 					 ,2) quantity_ordering
3981                                 ,mtrl.reference               reference
3982                                 ,mtrl.reference_type_code     reference_type_code
3983                                 ,mtrl.reference_id            reference_id
3984                                 FROM mtl_txn_request_lines mtrl
3985                                 WHERE  mtrl.organization_id = p_org_id
3986                                 AND mtrl.inventory_item_id = p_item
3987                                 AND mtrl.uom_code = p_uom_code
3988                                 AND Nvl(mtrl.revision, Nvl(p_rev, '@@@')) = Nvl(p_rev, '@@@')
3989                                 AND Nvl(mtrl.lpn_id, -1) = Nvl(p_lpn, -1)
3990                                 AND Nvl(mtrl.lot_number, Nvl(p_lot,'@$#_')) = Nvl(p_lot, '@$#_')
3991                                 AND (mtrl.quantity - Nvl(mtrl.quantity_delivered, 0)) > 0
3992                                 --
3993                                 AND Nvl(inspection_status,-1)    =
3994 				Nvl(p_transfer_inspection_status,-1)
3995                                 AND Nvl(from_subinventory_code,'@$#_') = Nvl(p_from_sub,'@$#_')
3996                                 AND Nvl(from_locator_id,-1)            = Nvl(p_from_locator_id,-1)
3997                                 AND Nvl(project_id,-1)                 = Nvl(p_project_id,-1)
3998                                 AND Nvl(task_id,-1)                    = Nvl(p_task_id,-1)
3999                                 AND Nvl(backorder_delivery_detail_id,-1) = Nvl(p_backorder_delivery_detail_id,-1)
4000                                 AND Nvl(crossdock_type,-1)               = Nvl(p_crossdock_type,-1)
4001                                 -- AND Nvl(from_cost_group_id,-1)           = Nvl(p_cost_group_id,-1) ????
4002                                 AND mtrl.line_status <> inv_globals.G_TO_STATUS_CLOSED
4003 				AND exists (SELECT 1
4004 					    FROM  mtl_txn_request_headers mtrh
4005 					    WHERE mtrh.move_order_type = inv_globals.g_move_order_put_away
4006 					    AND   mtrh.header_id = mtrl.header_id)
4007                                 ORDER BY 2,3 DESC, 4 ;
4008 
4009      l_transfer_mol_rec c_transfer_mol%rowtype;
4010 
4011      l_transaction_id NUMBER;
4012      l_transaction_type VARCHAR2(25);
4013      l_parent_transaction_id NUMBER;
4014      l_source_document_code VARCHAR2(25);
4015      l_grand_parent_txn_id NUMBER;
4016      l_great_grand_parent_txn_id NUMBER;
4017      l_parent_txn_type VARCHAR2(25);
4018      l_grand_parent_txn_type VARCHAR2(25);
4019 
4020      l_from_sub VARCHAR2(30);
4021      l_from_loc_id NUMBER;
4022 
4023      l_remaining_primary_quantity NUMBER;
4024      l_mol_qty_in_puom NUMBER;
4025      l_quantity_delivered NUMBER;
4026 
4027      l_move_order_header_id NUMBER;
4028      l_move_order_line_id NUMBER;
4029      l_inspect NUMBER := NULL;
4030      l_transfer_org_id NUMBER := NULL;
4031 
4032      l_project_id NUMBER := NULL;
4033      l_task_id NUMBER := NULL;
4034 
4035      l_mo_split_tb inv_rcv_integration_apis.mo_in_tb_tp;
4036 
4037      l_call_pregeneration BOOLEAN := TRUE;
4038 
4039      l_mol_txn_id NUMBER;
4040      l_mol_lpn_id NUMBER;
4041 
4042      l_error_code NUMBER;
4043      l_operation_type NUMBER;
4044 
4045      l_dummy VARCHAR2(1);
4046 
4047      L_DEBUG NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4048      l_progress VARCHAR2(15) := '00';
4049      l_proc_name VARCHAR2(30) := 'MAINTAIN_MO_CON';
4050 
4051      -- OPMConvergence
4052      l_remaining_secondary_quantity NUMBER;
4053      l_sec_quantity_delivered       NUMBER;
4054      -- OPMConvergence
4055 
4056     l_po_line_location_id NUMBER := NULL;
4057     l_po_distribution_id  NUMBER := NULL;
4058 
4059     l_new_reference           VARCHAR2(2000);
4060     l_new_reference_type_code NUMBER;
4061     l_new_reference_id        NUMBER;
4062 
4063     l_reference           VARCHAR2(2000);
4064     l_reference_type_code NUMBER;
4065     l_reference_id        NUMBER;
4066 
4067     l_transfer_inspection_status NUMBER;
4068     l_from_mol_inspection_status NUMBER;
4069     l_rti_inspection_status_code varchar2(80);
4070     l_mol_res_in  cas_mol_rec_tb_tp;
4071     l_mol_res_out cas_mol_rec_tb_tp;
4072 
4073     l_transaction_type_id NUMBER;
4074     l_txn_source_type_id NUMBER;
4075     l_backorder_delivery_detail_id NUMBER;
4076     l_loaded NUMBER;
4077 
4078     l_requisition_line_id    NUMBER;
4079     l_po_header_id           NUMBER;
4080     l_auto_transact_code     VARCHAR2(25);
4081 
4082     l_mol_consumed_full NUMBER;
4083     l_split_sec_qty     NUMBER;
4084     l_split_qty     NUMBER;
4085 
4086     l_pt_inspection_status_code VARCHAR2(20);
4087     l_grand_pt_insp_status_code VARCHAR2(20);
4088     l_grt_gr_parent_insp_stat_code VARCHAR2(20);
4089     l_grt_gr_routing_id      NUMBER;
4090 
4091     l_pt_routing_id NUMBER;
4092     l_grand_pt_routing_id NUMBER;
4093 
4094     l_transfer_sub   VARCHAR2(30);
4095     l_transfer_locator_id NUMBER;
4096     l_mol_transfer_lpn_id NUMBER;
4097     l_qty_detailed        NUMBER;
4098 
4099     L_UPDATE_OR_CLOSE  VARCHAR2(1);
4100 
4101     l_loop_index NUMBER;
4102     l_is_asn     VARCHAR2(1);
4103     l_is_req     VARCHAR2(1) := 'N'; -- Bug 5460505
4104 
4105     l_tmp_qty NUMBER;
4106     l_tmp_qty_dlvd NUMBER;
4107     l_tmp_qty_dtld NUMBER;
4108     l_tmp_uom_code VARCHAR2(3);
4109 
4110     --For calling delete_reservation in REJECT cases
4111     l_rsv_rec      inv_reservation_global.mtl_reservation_rec_type;
4112     l_dummy_serial inv_reservation_global.serial_number_tbl_type;
4113     l_msg_count number;
4114     l_msg_data VARCHAR2(2000);
4115     l_return_status VARCHAR2(1);
4116 
4117     l_conversion_rate NUMBER;  -- Bug 5632202
4118 BEGIN
4119 
4120    x_return_status := g_ret_sts_success;
4121 
4122    x_transaction_id := -1;
4123 
4124    IF (l_debug = 1) THEN
4125       print_debug('Entering MAINTAIN_MO_CON:'||l_progress,1);
4126       print_debug('MAINTAIN_MO_CON - MMTT TEMP ID:'||p_mmtt_temp_id||':'||l_progress,1);
4127       print_debug('MAINTAIN_MO_CON - p_from_subinventory:'||p_from_subinventory||':'||l_progress,1);
4128       print_debug('MAINTAIN_MO_CON - p_from_locator_id:'||p_from_locator_id||':'||l_progress,1);
4129       print_debug('MAINTAIN_MO_CON - p_subinventory:'||p_subinventory||':'||l_progress,1);
4130       print_debug('MAINTAIN_MO_CON - p_locator_id:'||p_locator_id||':'||l_progress,1);
4131       print_debug('MAINTAIN_MO_CON - p_project_id:'||p_project_id||':'||l_progress,1);
4132       print_debug('MAINTAIN_MO_CON - p_task_id:'||p_task_id||':'||l_progress,1);
4133       print_debug('MAINTAIN_MO_CON - p_line_location_id:'||p_po_line_location_id||':'||l_progress,1);
4134       print_debug('MAINTAIN_MO_CON - p_po_distribution_id:'||p_po_distribution_id||':'||l_progress,1);
4135       print_debug('MAINTAIN_MO_CON - p_shipment_line_id:'||p_shipment_line_id||':'||l_progress,1);
4136       print_debug('MAINTAIN_MO_CON - p_asn_line_flag:'||p_asn_line_flag||':'||l_progress,1);
4137       print_debug('MAINTAIN_MO_CON - p_uom_code:'||p_uom_code||':'||l_progress,1);
4138       l_progress := 'WMSINB-40000';
4139    END IF;
4140 
4141    --QUERY RT
4142    BEGIN
4143       SELECT transaction_id
4144 	, transaction_type
4145 	, parent_transaction_id
4146 	, source_document_code
4147         , INSPECTION_STATUS_CODE
4148         , requisition_line_id
4149         , po_header_id
4150 	INTO l_transaction_id
4151 	, l_transaction_type
4152 	, l_parent_transaction_id
4153 	, l_source_document_code
4154         , l_rti_inspection_status_code
4155         , l_requisition_line_id
4156         , l_po_header_id
4157 	FROM rcv_transactions
4158 	WHERE interface_transaction_id = p_rti_id;
4159 
4160    EXCEPTION
4161       WHEN no_data_found THEN
4162 	 --raise error
4163 	 l_progress := 'WMSINB-40010';
4164 	 RAISE fnd_api.g_exc_error;
4165       WHEN OTHERS THEN
4166 	 --raise error
4167 	 l_progress := 'WMSINB-40020';
4168 	 RAISE fnd_api.g_exc_error;
4169    END;
4170 
4171    x_transaction_id := l_transaction_id;
4172 
4173    IF (l_debug = 1) THEN
4174       print_debug('MAINTAIN_MO_CON - TRANSACTION TYPE:'||l_transaction_type||':'||l_progress,1);
4175       print_debug('MAINTAIN_MO_CON - SOURCE DOC CODE:'||l_source_document_code||':'||l_progress,1);
4176       print_debug('MAINTAIN_MO_CON - TRANSACTION ID:'||l_transaction_id||':'||l_progress,1);
4177       print_debug('MAINTAIN_MO_CON - PARENT TRANSACTION ID:'||l_parent_transaction_id||':'||l_progress,1);
4178       print_debug('MAINTAIN_MO_CON - PRIMARY QUANTITY:'||p_primary_quantity||':'||l_progress,1);
4179       -- OPMConvergence
4180       print_debug(l_proc_name||'SECONDARY QUANTITY: '||p_sec_qty||':'||l_progress,1);
4181       print_debug(l_proc_name||'SECONDARY UOM: '||p_sec_uom||':'||l_progress,1);
4182       -- OPMConvergence
4183       l_progress := 'WMSINB-40030';
4184    END IF;
4185 
4186    --QUERY RT TO GET THE GRAND PARENT
4187    IF (l_transaction_type IN ('CORRECT', 'RETURN TO RECEIVING',
4188 			      'RETURN TO VENDOR','RETURN TO CUSTOMER','ACCEPT','REJECT','TRANSFER',
4189                               'DELIVER')) THEN
4190       BEGIN
4191 	 SELECT parent_transaction_id
4192 	   , transaction_type
4193 	   , subinventory
4194 	   , locator_id
4195 	   , inspection_status_code
4196            , routing_header_id
4197 	   INTO l_grand_parent_txn_id
4198 	   , l_parent_txn_type
4199 	   , l_from_sub
4200 	   , l_from_loc_id
4201 	   , l_pt_inspection_status_code
4202            , l_pt_routing_id
4203 	   FROM rcv_transactions
4204 	   WHERE transaction_id = l_parent_transaction_id;
4205       EXCEPTION
4206 	 WHEN no_data_found THEN
4207 	    l_from_sub := NULL; --Review I think no data found in this
4208 	    --case must raise an error.
4209 	    l_from_loc_id := NULL;
4210 	    l_parent_txn_type := '';
4211 	    l_grand_parent_txn_id := -1;
4212       END;
4213 
4214       IF (l_debug = 1) THEN
4215          print_debug('l_pt_inspection_status_code := '||l_pt_inspection_status_code,1);
4216       END IF;
4217 
4218       IF (l_parent_txn_type IN ('RETURN TO VENDOR','RETURN TO CUSTOMER',
4219              'RETURN TO RECEIVING','CORRECT','ACCEPT','REJECT','DELIVER','TRANSFER')) THEN
4220 	 BEGIN
4221 	    SELECT parent_transaction_id
4222 	      , transaction_type
4223               , inspection_status_code
4224               , routing_header_id
4225 	      INTO l_great_grand_parent_txn_id
4226 	      , l_grand_parent_txn_type
4227               , l_grand_pt_insp_status_code
4228               , l_grand_pt_routing_id
4229 	      FROM rcv_transactions
4230 	      WHERE transaction_id = l_grand_parent_txn_id;
4231 	 EXCEPTION
4232 	    WHEN no_data_found THEN
4233 	       l_grand_parent_txn_type := '';
4234 	       l_great_grand_parent_txn_id := -1;
4235                l_grand_pt_insp_status_code := null;
4236                l_grand_pt_routing_id := null;
4237 	 END;
4238 
4239          --  Only for this case the inspection status code needs to be fetched
4240          --  For Great grand parent
4241          IF ( l_transaction_type = 'CORRECT' and
4242               l_parent_txn_type IN ('RETURN TO VENDOR','RETURN TO CUSTOMER',
4243 				'RETURN TO RECEIVING') ) THEN
4244 	    BEGIN
4245                 select inspection_status_code
4246                       ,routing_header_id
4247                   into l_grt_gr_parent_insp_stat_code
4248                       ,l_grt_gr_routing_id
4249                   from rcv_transactions
4250                  where transaction_id = l_great_grand_parent_txn_id;
4251             EXCEPTION
4252 	       WHEN no_data_found THEN
4253                   l_grt_gr_parent_insp_stat_code := null;
4254                   l_grt_gr_routing_id := null;
4255             END;
4256          END IF;
4257        ELSE
4258 	       l_grand_parent_txn_type := '';
4259 	       l_great_grand_parent_txn_id := -1;
4260                l_grand_pt_insp_status_code := null;
4261                l_grt_gr_parent_insp_stat_code := null;
4262                l_grt_gr_routing_id := null;
4263       END IF; --IF (l_parent_txn_type IN ('RETURN TO VENDOR','RETURN TO CUSTOMER',
4264     ELSE
4265 	 BEGIN
4266 	    SELECT parent_transaction_id
4267 	      , transaction_type
4268 	      , subinventory
4269 	      , locator_id
4270 	      INTO l_grand_parent_txn_id
4271 	      , l_parent_txn_type
4272 	      , l_from_sub
4273 	      , l_from_loc_id
4274 	      FROM rcv_transactions
4275 	      WHERE transaction_id = l_parent_transaction_id;
4276 	 EXCEPTION
4277 	    WHEN no_data_found THEN
4278 	       l_from_sub := NULL;
4279 	       l_from_loc_id := NULL;
4280 	       l_parent_txn_type := '';
4281 	       l_grand_parent_txn_id := -1;
4282 	 END;
4283    END IF; --IF (l_transaction_type IN ('CORRECT', 'RETURN TO RECEIVING')) THEN
4284 
4285    IF (l_debug = 1) THEN
4286       print_debug('MAINTAIN_MO_CON - PARENT TRANSACTION TYPE:'||l_parent_txn_type||':'||l_progress,1);
4287       print_debug('MAINTAIN_MO_CON - GRAND PARENT TRANSACTION ID:'||l_grand_parent_txn_id||':'||l_progress,1);
4288       print_debug('MAINTAIN_MO_CON - GRAND PARENT TRANSACTION TYPE:'||l_grand_parent_txn_type||':'||l_progress,1);
4289       print_debug('MAINTAIN_MO_CON - GREAT GRAND PARENT TRANSACTION ID:'||l_great_grand_parent_txn_id||':'||l_progress,1);
4290       print_debug('MAINTAIN_MO_CON - GRAND PARENT INSPECTION STATUS CODE:'||l_grand_pt_insp_status_code||':'||l_progress,1);
4291       l_progress := 'WMSINB-40035';
4292    END IF;
4293 
4294    --update mmtt with the sub/locator etc.
4295    IF (p_mmtt_temp_id IS NOT NULL) THEN
4296       IF (l_debug = 1) THEN
4297 	 print_debug('MAINTAIN_MO_CON - Updating MMTT with following values:',1);
4298 	 print_debug('MAINTAIN_MO_CON - Loc ID:'||p_locator_id,1);
4299 	 print_debug('MAINTAIN_MO_CON = Sub:'||p_subinventory,1);
4300 	 print_debug('MAINTAIN_MO_CON = Xfr LPN ID:'||p_transfer_lpn_id,1);
4301       END IF;
4302 
4303       --For DBI purpose
4304 
4305       --{{
4306       --After TRANSFER and DELIVER, make sure MMT for the transaction are
4307       --updated with the correct values }}
4308       UPDATE mtl_material_transactions_temp
4309 	SET rcv_transaction_id = l_transaction_id
4310 	, transfer_to_location = Decode(transfer_to_location,NULL,transfer_to_location,p_locator_id)
4311 	, transfer_subinventory = Decode(transfer_to_location,NULL,transfer_subinventory,p_subinventory)
4312 	, locator_id = Decode(transfer_to_location,NULL,p_locator_id,locator_id)
4313 	, subinventory_code = Decode(transfer_to_location,NULL,p_subinventory,subinventory_code)
4314 
4315 	--Bug 4082607.. commenting the following line as it is causing data
4316 	--corruption AND IS NOT required.
4317 	--	, lpn_id = Decode(l_transaction_type,'TRANSFER',Decode(p_transfer_lpn_id,NULL,lpn_id,p_transfer_lpn_id),lpn_id)
4318 	, transfer_lpn_id = decode(l_transaction_type,'TRANSFER',p_transfer_lpn_id,'DELIVER',p_transfer_lpn_id,transfer_lpn_id)
4319 	WHERE transaction_temp_id = p_mmtt_temp_id;
4320    END IF;
4321 
4322    l_progress := 'WMSINB-40039';
4323 
4324    -- FETCH THE REFERENCE INFORMATION
4325    IF p_shipment_line_id IS NOT NULL THEN
4326        BEGIN
4327 	  SELECT rsl.po_line_location_id,rsl.po_distribution_id,
4328 	    Decode(rsh.asn_type,'ASN','Y','N'),Decode(rsh.receipt_source_code,'INTERNAL ORDER','Y','N')
4329 	    INTO l_po_line_location_id,l_po_distribution_id,l_is_asn,l_is_req
4330 	    FROM rcv_shipment_lines rsl, rcv_shipment_headers rsh
4331 	    WHERE rsl.shipment_line_id = p_shipment_line_id
4332 	    AND   rsl.shipment_header_id = rsh.shipment_header_id;
4333        EXCEPTION
4334 	  WHEN OTHERS THEN
4335 	     IF (l_debug = 1) THEN
4336 		print_debug( 'MAINTAIN_MO_CON: RAISE FND_API.G_EXC_ERROR',4);
4337 	     END IF;
4338 	     RAISE fnd_api.g_exc_error;
4339        END;
4340 
4341        print_debug( 'MAINTAIN_MO_CON PLL ID : '||l_po_line_location_id ||
4342 		    '  POD ID : ' || l_po_distribution_id ||
4343 		    '  IS ASN?: ' || l_is_asn,4);
4344    END IF;
4345 
4346    IF (p_po_line_location_id IS NOT NULL AND l_is_asn = 'N') THEN
4347       --{{
4348       --Test PO transactions.  Also test for ASN transactions and see if
4349       --p_po_line_location_id is passed }}
4350       IF (l_debug = 1) THEN
4351         print_debug('MAINTAIN_MO_CON SETTING REFERENCE INFO for PO_LINE_LOCATION_ID '  , 4);
4352       END IF;
4353 
4354       l_new_reference_id := p_po_line_location_id;
4355       l_new_reference := 'PO_LINE_LOCATION_ID';
4356       l_new_reference_type_code := 4; -- for purchase orders
4357 
4358    ELSIF p_po_distribution_id IS NOT NULL THEN
4359       --{{
4360       --Test direct receipt, MSCA deliver cases, putaway to inventory,
4361       --negative correction of deliver for all items}}
4362 
4363       IF (l_debug = 1) THEN
4364         print_debug('MAINTAIN_MO_CON  SETTING REFERENCE INFO for PO_DISTRIBUTION_ID '  , 4);
4365       END IF;
4366 
4367       l_new_reference_id := p_po_distribution_id;
4368       l_new_reference := 'PO_DISTRIBUTION_ID';
4369       l_new_reference_type_code := 4; -- for purchase orders
4370 
4371    ELSIF p_oe_order_line_id IS NOT NULL AND l_is_req = 'N' THEN
4372       --{{
4373       --Test RMA transactions}}
4374 
4375       IF (l_debug = 1) THEN
4376         print_debug('MAINTAIN_MO_CON  SETTING REFERENCE INFO for ORDER_LINE_ID '  , 4);
4377       END IF;
4378 
4379       l_new_reference_id := p_oe_order_line_id;
4380       l_new_reference_type_code := 7; -- for RMA
4381       l_new_reference := 'ORDER_LINE_ID';
4382     ELSIF p_shipment_line_id IS NOT NULL THEN
4383 
4384       --{{
4385       --Test intrasit shipment, internal req.  For ASN, make sure that
4386       --the correct reference type code is stamped}}
4387       IF (l_debug = 1) THEN
4388         print_debug('MAINTAIN_MO_CON  SETTING REFERENCE INFO for SHIPMENT_LINE_ID '  , 4);
4389       END IF;
4390 
4391       l_new_reference_id := p_shipment_line_id;
4392 
4393       IF l_po_line_location_id IS NOT NULL OR l_po_distribution_id IS NOT NULL THEN
4394         l_new_reference_type_code := 4; --Considering the ASN
4395       ELSE
4396         l_new_reference_type_code := 8;
4397       END IF;
4398       l_new_reference := 'SHIPMENT_LINE_ID';
4399 
4400    END IF;
4401 
4402   l_progress := 'WMSINB-40047';
4403 
4404   -- ****************************************************
4405   -- FETCH THE TRANSFER INSPECTION STATUS
4406   -- ***************************************************
4407 
4408   IF (l_debug = 1) THEN
4409       print_debug( 'MAINTAIN_MO_CON p_routing_header_id = ' ||  p_routing_header_id , 4 );
4410   END if;
4411 
4412   if l_transaction_type = 'ACCEPT' then
4413      --{{
4414      --Inspect materials in a LPN that has already some inspected materials}}
4415      l_transfer_inspection_status := 2;
4416   Elsif l_transaction_type = 'REJECT' then
4417      l_transfer_inspection_status := 3;
4418   Else
4419      --IF (p_routing_header_id = 2) THEN
4420      IF (l_transaction_type <> 'RECEIVE') THEN
4421 	--{{
4422 	--Do receipt/transfer of materials whose source is a document
4423 	--with inspection routing into an LPN that have material with
4424 	--mixed inspection status.  Make sure that the correct MOL is
4425 	--picked up}}
4426 
4427          -- Txn TYPE CORRECT THEN TRANSFER INSPECTION STATUS
4428          -- SHOULD BE THE INSPECTION STATUS OF THE PARENT TXN.
4429          -- i,e MATERIAL SHOULD GO BACK TO THE ORIGINAL STATUS
4430          -- of PARENT TXN.
4431 
4432          IF ( (l_transaction_type IN ('CORRECT') and p_qty < 0 )
4433               AND l_parent_txn_type not in ('RETURN TO VENDOR',
4434                               'RETURN TO CUSTOMER','RETURN TO RECEIVING')
4435             )  THEN
4436 
4437              IF (l_debug = 1) THEN
4438                  print_debug( 'transfer insp stat correct and qty < 0 and parent txn not in RTV/ RTR/ RTC ', 4 );
4439              END if;
4440 
4441              IF l_grand_pt_insp_status_code is not null THEN
4442 	        IF    ( l_grand_pt_insp_status_code = 'NOT INSPECTED' and l_grand_pt_routing_id = 2) THEN
4443 	           l_transfer_inspection_status := 1;
4444 	        ELSIF ( l_grand_pt_insp_status_code = 'NOT INSPECTED' and l_grand_pt_routing_id <> 2) THEN
4445 	           l_transfer_inspection_status := null;
4446 	        ELSIF l_grand_pt_insp_status_code = 'ACCEPTED' THEN
4447 	           l_transfer_inspection_status := 2;
4448 	        ELSIF l_grand_pt_insp_status_code = 'REJECTED' THEN
4449 	           l_transfer_inspection_status := 3;
4450                 END IF;
4451              ELSE
4452                 -- There may not be any grand parent existing for this txn
4453                 -- So pick up the inspection status from the Parent txn.
4454                 IF (l_debug = 1) THEN
4455                   print_debug( 'l_grand_pt_insp_status_code is null  ', 4 );
4456                 END if;
4457 
4458 	        l_transfer_inspection_status := null;
4459              END IF;
4460          ELSIF ( ( l_transaction_type IN ('CORRECT') and p_qty > 0 )
4461               AND l_parent_txn_type not in ('RETURN TO VENDOR',
4462                               'RETURN TO CUSTOMER','RETURN TO RECEIVING')
4463                ) THEN
4464 
4465              IF (l_debug = 1) THEN
4466                 print_debug( 'MAINTAIN_MO_CON Setting transfer insp correct and qty > 0 and parent not in RTV / RTR / RTC ', 4 );
4467              END if;
4468 
4469 	     IF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2) THEN
4470 	        l_transfer_inspection_status := 1;
4471 	     ELSIF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2) THEN
4472 	        l_transfer_inspection_status := null;
4473 	     ELSIF l_pt_inspection_status_code = 'ACCEPTED' THEN
4474 	        l_transfer_inspection_status := 2;
4475 	     ELSIF l_pt_inspection_status_code = 'REJECTED' THEN
4476 	        l_transfer_inspection_status := 3;
4477              END IF;
4478 
4479          ELSIF ( (l_transaction_type IN ('CORRECT') and p_qty < 0 )
4480               AND l_parent_txn_type in ('RETURN TO VENDOR',
4481                               'RETURN TO CUSTOMER','RETURN TO RECEIVING')
4482                ) THEN
4483              IF (l_debug = 1) THEN
4484                  print_debug( 'Setting xfr insp correct and qty < 0 and parent in RTV / RTR / RTC ', 4 );
4485              END IF;
4486 
4487 	     IF (l_grt_gr_parent_insp_stat_code = 'NOT INSPECTED' and l_grt_gr_routing_id = 2) THEN
4488 	        l_transfer_inspection_status := 1;
4489 	     ELSIF (l_grt_gr_parent_insp_stat_code = 'NOT INSPECTED' and l_grt_gr_routing_id <> 2) THEN
4490 	        l_transfer_inspection_status := null;
4491 	     ELSIF l_grt_gr_parent_insp_stat_code = 'ACCEPTED' THEN
4492 	        l_transfer_inspection_status := 2;
4493 	     ELSIF  l_grt_gr_parent_insp_stat_code = 'REJECTED' THEN
4494 	        l_transfer_inspection_status := 3;
4495              END IF;
4496 
4497          ELSIF ( (l_transaction_type IN ('CORRECT') and p_qty > 0 )
4498               AND l_parent_txn_type in ('RETURN TO VENDOR',
4499                               'RETURN TO CUSTOMER','RETURN TO RECEIVING')
4500                ) THEN
4501              IF (l_debug = 1) THEN
4502                  print_debug( 'Setting xfr insp correct and qty > 0 and parent in RTV / RTR / RTC ', 4 );
4503              END if;
4504 
4505              l_transfer_inspection_status := null;
4506 
4507          ELSIF l_transaction_type IN ( 'RETURN TO VENDOR',
4508                               'RETURN TO CUSTOMER','RETURN TO RECEIVING' ) THEN
4509 
4510              IF (l_debug = 1) THEN
4511                  print_debug( 'MAINTAIN_MO_CON Setting xfr insp for RTV/ RTR/ RTC ', 4 );
4512              END if;
4513 
4514 	     IF (l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2 ) THEN
4515 	        l_transfer_inspection_status := 1;
4516 	     ELSIF (l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2 ) THEN
4517 	        l_transfer_inspection_status := null;
4518 	     ELSIF l_pt_inspection_status_code = 'ACCEPTED' THEN
4519 	        l_transfer_inspection_status := 2;
4520 	     ELSIF l_pt_inspection_status_code = 'REJECTED' THEN
4521 	        l_transfer_inspection_status := 3;
4522              END IF;
4523          ELSIF l_transaction_type IN ( 'TRANSFER') THEN
4524              IF (l_debug = 1) THEN
4525                  print_debug( 'MAINTAIN_MO_CON Setting xfr insp for TRANSFER TXN ', 4 );
4526              END if;
4527 
4528 	     IF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2) THEN
4529 	        l_transfer_inspection_status := 1;
4530 	     ELSIF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2) THEN
4531 	        l_transfer_inspection_status := null;
4532 	     ELSIF l_pt_inspection_status_code = 'ACCEPTED' THEN
4533 	        l_transfer_inspection_status := 2;
4534 	     ELSIF l_pt_inspection_status_code = 'REJECTED' THEN
4535 	        l_transfer_inspection_status := 3;
4536              END IF;
4537          ELSIF l_transaction_type IN ( 'DELIVER') THEN
4538              IF (l_debug = 1) THEN
4539                  print_debug( 'MAINTAIN_MO_CON DELIVER TXN Setting xfr inspection status ', 4 );
4540              END if;
4541 	     l_transfer_inspection_status := null;
4542          ELSE
4543             IF ( l_rti_inspection_status_code = 'NOT INSPECTED' and p_routing_header_id = 2) THEN
4544               l_transfer_inspection_status := 1;
4545             ELSIF ( l_rti_inspection_status_code = 'NOT INSPECTED' and p_routing_header_id <> 2) THEN
4546               l_transfer_inspection_status := null;
4547             ELSIF l_rti_inspection_status_code = 'ACCEPTED' THEN
4548               l_transfer_inspection_status := 2;
4549             ELSIF l_rti_inspection_status_code = 'REJECTED' THEN
4550               l_transfer_inspection_status := 3;
4551             END IF;
4552          END IF;
4553       ELSE
4554         -- Setting Inspection Status for RECEIVE CASE
4555 	--{{
4556 	--Do receipt/transfer of materials whose source is a document
4557 	--with standard routing into an LPN that have material with
4558 	--mixed inspection status.  Make sure that the correct MOL is
4559 	--picked up}}
4560 
4561         IF (l_debug = 1) THEN
4562             print_debug( 'MAINTAIN_MO_CON Setting xfr insp for RECEIVE ', 4 );
4563         END if;
4564 
4565         IF (p_routing_header_id = 2) THEN
4566 	   l_transfer_inspection_status := 1;
4567         ELSE
4568 	   l_transfer_inspection_status := null;
4569         END IF;
4570       END IF;
4571   End if;
4572 
4573 --Review need to discuss the above. This is not right because if the
4574 --transaction type is anything but accept or reject then we cannot blindly
4575 --  SET it based on the routing. it will also depend on the inspection
4576 --  status the rti/rt.
4577 -- ************************************************
4578 -- FETCH THE FROM INSPECTION STATUS
4579 -- ***********************************************
4580 
4581      IF (l_debug = 1) THEN
4582          print_debug( 'MAINTAIN_MO_CON Setting FROM MOL INSP STATUS', 4 );
4583      END if;
4584 
4585      IF (l_transaction_type IN ('ACCEPT','REJECT')) THEN
4586 	IF (l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2) THEN
4587 	   l_from_mol_inspection_status := 1;
4588 	ELSIF (l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2) THEN
4589 	   l_from_mol_inspection_status := null;
4590 	ELSIF l_pt_inspection_status_code = 'ACCEPTED' THEN
4591 	   l_from_mol_inspection_status := 2;
4592 	ELSIF l_pt_inspection_status_code = 'REJECTED' THEN
4593 	   l_from_mol_inspection_status := 3;
4594 	END IF;
4595      ELSE --RECEIVE/RTV/RTR/TRANSFER/DELIVER/CORRECT txn
4596          IF (l_transaction_type <> 'RECEIVE') THEN
4597 
4598             IF ( (l_transaction_type IN ('CORRECT') and p_qty < 0 )
4599               AND l_parent_txn_type not in ('RETURN TO VENDOR',
4600                               'RETURN TO CUSTOMER','RETURN TO RECEIVING')
4601             )  THEN
4602 
4603                 IF (l_debug = 1) THEN
4604                     print_debug( 'from mol insp stat correct and qty < 0 and parent txn not in RTV/ RTR/ RTC ', 4 );
4605                 END IF;
4606 
4607 	        IF (l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2) THEN
4608 	           l_from_mol_inspection_status := 1;
4609 	        ELSIF (l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2) THEN
4610 	           l_from_mol_inspection_status := null;
4611 	        ELSIF l_pt_inspection_status_code = 'ACCEPTED' THEN
4612 	           l_from_mol_inspection_status := 2;
4613 	        ELSIF l_pt_inspection_status_code = 'REJECTED' THEN
4614 	           l_from_mol_inspection_status := 3;
4615 	        END IF;
4616             ELSIF ( (l_transaction_type IN ('CORRECT') and p_qty > 0 )
4617               AND l_parent_txn_type not in ('RETURN TO VENDOR',
4618                               'RETURN TO CUSTOMER','RETURN TO RECEIVING')
4619                   ) THEN
4620                 IF l_grand_pt_insp_status_code is not null THEN
4621 	           IF ( l_grand_pt_insp_status_code = 'NOT INSPECTED' and l_grand_pt_routing_id = 2) THEN
4622 	              l_from_mol_inspection_status := 1;
4623 	           ELSIF ( l_grand_pt_insp_status_code = 'NOT INSPECTED' and l_grand_pt_routing_id <> 2) THEN
4624 	              l_from_mol_inspection_status := null;
4625 	           ELSIF l_grand_pt_insp_status_code = 'ACCEPTED' THEN
4626 	              l_from_mol_inspection_status := 2;
4627 	           ELSIF l_grand_pt_insp_status_code = 'REJECTED' THEN
4628 	              l_from_mol_inspection_status := 3;
4629                    END IF;
4630                 ELSE
4631                    -- There may not be any grand parent existing for this txn
4632                    -- So pick up the inspection status from the Parent txn.
4633                    IF (l_debug = 1) THEN
4634                      print_debug( 'l_grand_pt_insp_status_code is null  ', 4 );
4635                    END if;
4636 
4637 	           l_from_mol_inspection_status := null;
4638                 END IF;
4639             ELSIF l_transaction_type IN ( 'RETURN TO VENDOR',
4640                               'RETURN TO CUSTOMER','RETURN TO RECEIVING' ) THEN
4641 
4642                 IF (l_debug = 1) THEN
4643                     print_debug( 'MAINTAIN_MO_CON Setting xfr insp for RTV/ RTR/ RTC ', 4 );
4644                 END if;
4645 
4646                 IF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2) THEN
4647                    l_from_mol_inspection_status := 1;
4648                 ELSIF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2) THEN
4649                    l_from_mol_inspection_status := null;
4650                 ELSIF l_pt_inspection_status_code = 'ACCEPTED' THEN
4651                    l_from_mol_inspection_status := 2;
4652                 ELSIF l_pt_inspection_status_code = 'REJECTED' THEN
4653                    l_from_mol_inspection_status := 3;
4654                 END IF;
4655 
4656             ELSIF ( (l_transaction_type IN ('CORRECT') and p_qty < 0 )
4657                  AND l_parent_txn_type in ('RETURN TO VENDOR',
4658                                  'RETURN TO CUSTOMER','RETURN TO RECEIVING')
4659                   ) THEN
4660                 IF (l_debug = 1) THEN
4661                     print_debug( 'Setting from mol insp correct and qty < 0 and parent in RTV / RTR / RTC ', 4 );
4662                 END IF;
4663 
4664 	        IF ( l_grt_gr_parent_insp_stat_code = 'NOT INSPECTED' and l_grt_gr_routing_id = 2) THEN
4665 	           l_transfer_inspection_status := 1;
4666 	        ELSIF ( l_grt_gr_parent_insp_stat_code = 'NOT INSPECTED' and l_grt_gr_routing_id <> 2) THEN
4667 	           l_transfer_inspection_status := null;
4668 	        ELSIF l_grt_gr_parent_insp_stat_code = 'ACCEPTED' THEN
4669 	           l_transfer_inspection_status := 2;
4670 	        ELSIF  l_grt_gr_parent_insp_stat_code = 'REJECTED' THEN
4671 	           l_transfer_inspection_status := 3;
4672                 END IF;
4673             ELSIF ( (l_transaction_type IN ('CORRECT') and p_qty > 0 )
4674                  AND l_parent_txn_type in ('RETURN TO VENDOR',
4675                                  'RETURN TO CUSTOMER','RETURN TO RECEIVING')
4676                   ) THEN
4677                 IF (l_debug = 1) THEN
4678                     print_debug( 'Setting from mol insp correct and qty > 0 and parent in RTV / RTR / RTC ', 4 );
4679                 END IF;
4680                 -- Bug 7355205
4681                 -- l_from_mol_inspection_status := null;
4682                 IF ( l_grand_pt_insp_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2) THEN
4683 	           l_from_mol_inspection_status := 1;
4684 	        ELSIF ( l_grand_pt_insp_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2) THEN
4685 	           l_from_mol_inspection_status := null;
4686 	        ELSIF l_grand_pt_insp_status_code = 'ACCEPTED' THEN
4687 	           l_from_mol_inspection_status := 2;
4688 	        ELSIF l_grand_pt_insp_status_code = 'REJECTED' THEN
4689 	           l_from_mol_inspection_status := 3;
4690                 END IF;
4691             ELSIF l_transaction_type IN ( 'TRANSFER') THEN
4692                 IF (l_debug = 1) THEN
4693                     print_debug( 'MAINTAIN_MO_CON Setting from insp for TRANSFER TXN ', 4 );
4694                 END if;
4695 	        IF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2) THEN
4696 	           l_from_mol_inspection_status := 1;
4697 	        ELSIF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2) THEN
4698 	           l_from_mol_inspection_status := null;
4699 	        ELSIF l_pt_inspection_status_code = 'ACCEPTED' THEN
4700 	           l_from_mol_inspection_status := 2;
4701 	        ELSIF l_pt_inspection_status_code = 'REJECTED' THEN
4702 	           l_from_mol_inspection_status := 3;
4703                 END IF;
4704             ELSIF l_transaction_type IN ( 'DELIVER') THEN
4705                 IF (l_debug = 1) THEN
4706                     print_debug( 'MAINTAIN_MO_CON DELIVER TXN Setting from inspection status ', 4 );
4707                 END if;
4708 	        IF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2) THEN
4709 	           l_from_mol_inspection_status := 1;
4710 	        ELSIF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2) THEN
4711 	           l_from_mol_inspection_status := null;
4712 	        ELSIF l_pt_inspection_status_code = 'ACCEPTED' THEN
4713 	           l_from_mol_inspection_status := 2;
4714 	        ELSIF l_pt_inspection_status_code = 'REJECTED' THEN
4715 	           l_from_mol_inspection_status := 3;
4716                 END IF;
4717             END IF;
4718          ELSE
4719              IF (l_debug = 1) THEN
4720                  print_debug( 'MAINTAIN_MO_CON Txn is Receive Setting FROM MOL INSP STATUS TO NULL', 4 );
4721              END if;
4722              l_from_mol_inspection_status := null;
4723          END IF;
4724      END IF;
4725 
4726   --Why are we doing a if on transaction type when the code is
4727   --exactly same for if and else blocks.
4728 
4729   IF (l_debug = 1) THEN
4730       print_debug( 'MAINTAIN_MO_CON l_from_mol_inspection_status = ' ||  l_from_mol_inspection_status , 4 );
4731       print_debug( 'MAINTAIN_MO_CON l_transfer_inspection_status = ' ||  l_transfer_inspection_status , 4 );
4732   END IF;
4733 
4734    -- Now maintain MO
4735    IF (l_transaction_type in ('RECEIVE','MATCH') OR
4736        (l_transaction_type = 'CORRECT' AND
4737 	p_primary_quantity > 0 AND
4738 	l_parent_txn_type = 'RECEIVE')) THEN
4739 
4740       IF (l_debug = 1) THEN
4741           print_debug( 'MAINTAIN_MO_CON l_transfer_inspection_status = ' ||  l_transfer_inspection_status , 4 );
4742       END IF;
4743 
4744       --This is not used in INVRUTLB.  Make sure that this is OK
4745       IF l_source_document_code IN ('INVENTORY','REQ') THEN
4746 	 l_transfer_org_id := p_org_id;
4747       END IF;
4748 
4749       --Get the project and task information
4750 
4751       --{{
4752       --Test receipt and deliver in PJM org}}
4753       IF (p_project_id IS NULL) THEN
4754 
4755 	 --{{
4756 	 --Test receipt and deliver of PO with project/task distribution}}
4757 	 IF (p_po_distribution_id IS NOT NULL) THEN
4758 	    BEGIN
4759 	       SELECT project_id,
4760 	              task_id              -- bug 7218830
4761 		 INTO l_project_id,
4762 		 l_task_id
4763 		 FROM po_distributions_all
4764 		 WHERE po_distribution_id = p_po_distribution_id;
4765 	    EXCEPTION
4766 	       WHEN no_data_found THEN
4767 		  l_project_id := NULL;
4768 		  l_task_id := NULL;
4769 	    END ;
4770             ELSIF (p_po_line_location_id IS NOT NULL) then  -- Bug 6830559
4771             inv_rcv_std_rcpt_apis.get_project_task(
4772                  p_po_line_location_id     => p_po_line_location_id
4773                , p_oe_order_line_id        => NULL
4774                , x_project_id              => l_project_id
4775                , x_task_id                 => l_task_id
4776             );
4777 	 --{{
4778 	 --Test receipt and deliver of RMA with project/task distribution}}
4779 	  ELSIF (p_oe_order_line_id IS NOT NULL) THEN
4780                BEGIN
4781 		  SELECT project_id,
4782 		         task_id                -- bug 7218830
4783 		    INTO l_project_id
4784 		    , l_task_id
4785 		    FROM oe_order_lines_all
4786 		    WHERE line_id = p_oe_order_line_id;
4787 	       EXCEPTION
4788 		  WHEN no_data_found THEN
4789 		     l_project_id := NULL;
4790 		     l_task_id := NULL;
4791 	       END;
4792        -- Bug# 7154105 Picking up the Praject and Task from po_req_distributions_all when
4793        -- a distribution is specified in the Internal Requisition. There can be just one
4794        -- distribution for internally sourced documents
4795        ELSIF p_req_distribution_id IS NOT NULL THEN
4796          BEGIN
4797            select project_id, task_id
4798            into   l_project_id, l_task_id
4799            from   po_req_distributions_all
4800            where  distribution_id = p_req_distribution_id;
4801 
4802            print_debug('MAINTAIN_MOC_CON - Proj Task Pickup for distributions: Project: '||l_project_id || ' Task :  ' ||l_task_id || ' Distibution_id : ' ||p_req_distribution_id,1);
4803          EXCEPTION
4804 		   WHEN no_data_found THEN
4805 		     l_project_id := NULL;
4806 		     l_task_id := NULL;
4807             when too_many_rows then
4808              print_debug('MAINTAIN_MOC_CON - Proj Task Pickup for distributions fetches too many rows : ' || sqlerrm,1);
4809              raise fnd_api.g_exc_unexpected_error;
4810 	     END;
4811          -- End of Bug# 7154105
4812 	 END IF;
4813        ELSE --IF (p_project_id IS NULL) THEN
4814 		  l_project_id := p_project_id;
4815 		  l_task_id := p_task_id;
4816       END IF; --IF (p_project_id IS NULL) THEN
4817 
4818       IF (l_debug = 1) THEN
4819 	 print_debug('MAINTAIN_MOC_CON - Before calling Reservation API:'||l_progress,1);
4820 	 l_progress := 'WMSINB-45050';
4821       END IF;
4822 
4823       -- ******************************************************************
4824       -- CALL THE RESERVATION API HERE
4825       -- l_mol_res_in is returned from the reservation API
4826       -- CHANGE THIS PART ONCE THE RESERVATION API IS COMPLETED.
4827       -- ******************************************************************
4828 
4829       l_mol_res_in(1).transaction_type       := l_transaction_type;
4830       l_mol_res_in(1).organization_id        := p_org_id;
4831       l_mol_res_in(1).lpn_id                 := p_transfer_lpn_id;
4832       l_mol_res_in(1).inventory_item_id      := p_item_id;
4833       l_mol_res_in(1).lot_number             := p_lot_number;
4834       l_mol_res_in(1).item_revision          := p_revision;
4835       l_mol_res_in(1).from_subinventory_code := p_subinventory;
4836       l_mol_res_in(1).from_locator_id        := p_locator_id;
4837 
4838       -- l_mol_res_in(1).cost_group_id          := null; ????
4839 
4840       l_mol_res_in(1).project_id             := l_project_id;
4841       l_mol_res_in(1).task_id                := l_task_id;
4842       l_mol_res_in(1).uom_code               := p_uom_code;
4843       l_mol_res_in(1).quantity               := p_qty;
4844       l_mol_res_in(1).backorder_delivery_detail_id := null;
4845       l_mol_res_in(1).crossdock_type         := null;
4846       l_mol_res_in(1).transfer_org_id        := l_transfer_org_id;
4847       l_mol_res_in(1).secondary_quantity     := p_sec_qty;
4848       l_mol_res_in(1).secondary_uom          := p_sec_uom;
4849       l_mol_res_in(1).inspection_status      := l_transfer_inspection_status ;
4850       l_mol_res_in(1).line_id                := null;
4851       l_mol_res_in(1).primary_uom_code       := p_primary_uom_code;
4852       l_mol_res_in(1).primary_qty            := p_primary_quantity;
4853       l_mol_res_in(1).po_header_id           := l_po_header_id;
4854       l_mol_res_in(1).po_line_location_id    := p_po_line_location_id;
4855       l_mol_res_in(1).shipment_line_id       := p_shipment_line_id;
4856       l_mol_res_in(1).requisition_line_id    := l_requisition_line_id;
4857       l_mol_res_in(1).auto_transact_code     := p_auto_transact_code;
4858       l_mol_res_in(1).wip_supply_type        := null;
4859       l_mol_res_in(1).routing_header_id      := p_routing_header_id;
4860       l_mol_res_in(1).source_document_code   := l_source_document_code;
4861       l_mol_res_in(1).parent_transaction_id  := null;
4862       l_mol_res_in(1).asn_line_flag          := p_asn_line_flag;
4863       l_mol_res_in(1).parent_txn_type        := l_parent_txn_type;
4864 
4865       INV_RCV_RESERVATION_UTIL.maintain_reservations
4866                  (x_return_status => x_return_status
4867                  ,x_msg_count     => x_msg_count
4868                  ,x_msg_data      => x_msg_data
4869                  ,x_mol_tb        => l_mol_res_out
4870                  ,p_cas_mol_tb    => l_mol_res_in
4871        );
4872 
4873        IF (l_debug = 1) THEN
4874                 print_debug(' maintain_reservations - After calling maintain_reservations :'||x_return_status||':'||l_progress,1);
4875                 l_progress := 'WMSINB-45051';
4876        END IF;
4877 
4878        IF (x_return_status <> 'S') THEN
4879               l_progress := 'WMSINB-45052';
4880               RAISE fnd_api.g_exc_error;
4881        END IF;
4882 
4883       l_progress := 'WMSINB-45053';
4884 
4885       l_loop_index := l_mol_res_out.first;
4886 
4887       LOOP
4888 
4889 	 EXIT WHEN l_loop_index IS NULL;
4890 
4891          IF (l_debug = 1) THEN
4892 	    print_debug('MAINTAIN_MOC_CON -Inside MOL CONSL LOOP ',1);
4893 	    print_debug(' l_mol_res_out('||l_loop_index||').lpn_id                       => ' ||l_mol_res_out(l_loop_index).lpn_id,1);
4894 	    print_debug(' l_mol_res_out('||l_loop_index||').inventory_item_id            => ' ||l_mol_res_out(l_loop_index).inventory_item_id,1);
4895 	    print_debug(' l_mol_res_out('||l_loop_index||').lot_number                   => ' ||l_mol_res_out(l_loop_index).lot_number,1);
4896 	    print_debug(' l_mol_res_out('||l_loop_index||').item_revision                => ' ||l_mol_res_out(l_loop_index).item_revision,1);
4897 	    print_debug(' l_mol_res_out('||l_loop_index||').from_subinventory_code       => ' ||l_mol_res_out(l_loop_index).from_subinventory_code,1);
4898 	    print_debug(' l_mol_res_out('||l_loop_index||').from_locator_id              => ' ||l_mol_res_out(l_loop_index).from_locator_id,1);
4899 	    print_debug(' l_mol_res_out('||l_loop_index||').project_id                   => ' ||l_mol_res_out(l_loop_index).project_id,1);
4900 	    print_debug(' l_mol_res_out('||l_loop_index||').task_id                      => ' ||l_mol_res_out(l_loop_index).task_id,1);
4901 	    print_debug(' l_mol_res_out('||l_loop_index||').uom_code                     => ' ||l_mol_res_out(l_loop_index).uom_code,1);
4902 	    print_debug(' l_mol_res_out('||l_loop_index||').quantity                     => ' ||l_mol_res_out(l_loop_index).quantity,1);
4903 	    print_debug(' l_mol_res_out('||l_loop_index||').backorder_delivery_detail_id => ' ||l_mol_res_out(l_loop_index).backorder_delivery_detail_id,1);
4904 	    print_debug(' l_mol_res_out('||l_loop_index||').crossdock_type               => ' ||l_mol_res_out(l_loop_index).crossdock_type,1);
4905 	    print_debug(' l_mol_res_out('||l_loop_index||').inspection_status            => ' ||l_mol_res_out(l_loop_index).inspection_status,1);
4906 	 END IF;
4907 
4908 	 --{{
4909 	 --Do multiple receipt with the same conolidation critieria:
4910 	 --1) LPN 2) Item 3) Lot 4)Rev 5) From Sub 6) From Loc
4911 	 --7) Project ID 8) Task_Id 9) Uom_code 10) BDD_ID
4912 	 --11) Crossdock_type 12) Inspection Status }}
4913          open c_transfer_mol(
4914                              l_mol_res_out(l_loop_index).lpn_id
4915                             ,l_mol_res_out(l_loop_index).inventory_item_id
4916                             ,l_mol_res_out(l_loop_index).lot_number
4917                             ,l_mol_res_out(l_loop_index).item_revision
4918                             ,l_mol_res_out(l_loop_index).from_subinventory_code
4919                             ,l_mol_res_out(l_loop_index).from_locator_id
4920                              -- ,l_mol_res_out(l_loop_index).cost_group_id ???
4921                             ,l_mol_res_out(l_loop_index).project_id
4922                             ,l_mol_res_out(l_loop_index).task_id
4923                             ,l_mol_res_out(l_loop_index).uom_code
4924                             ,l_mol_res_out(l_loop_index).backorder_delivery_detail_id
4925                             ,l_mol_res_out(l_loop_index).crossdock_type
4926                             ,l_mol_res_out(l_loop_index).inspection_status
4927                             );
4928         Fetch c_transfer_mol into l_transfer_mol_rec;
4929         close c_transfer_mol;
4930 
4931 	IF (l_debug = 1) THEN
4932 	   print_debug('MAINTAIN_MOC_CON - Move Order Line Found line Id = '|| l_transfer_mol_rec.line_id,1);
4933 	END IF;
4934 
4935         if l_transfer_mol_rec.line_id is not null
4936         then
4937            -- Move Order Line found
4938            -- Check whether MOL is from the same SOURCE
4939            IF (l_debug = 1) THEN
4940 	      print_debug('MAINTAIN_MOC_CON - Move Order Line Found line Id = '|| l_transfer_mol_rec.line_id,1);
4941            END IF;
4942 
4943            check_reference(
4944                             p_old_reference           => l_transfer_mol_rec.reference
4945                            ,p_old_reference_type_code => l_transfer_mol_rec.reference_type_code
4946                            ,p_old_reference_id        => l_transfer_mol_rec.reference_id
4947                            ,p_new_reference           => l_new_reference
4948                            ,p_new_reference_type_code => l_new_reference_type_code
4949                            ,p_new_reference_id        => l_new_reference_id
4950                            ,x_reference               => l_reference
4951                            ,x_reference_type_code     => l_reference_type_code
4952                            ,x_reference_id            => l_reference_id
4953                            ,x_transaction_type_id     => l_transaction_type_id
4954                            ,x_txn_source_type_id      => l_txn_source_type_id
4955                            ,x_return_status           => x_return_status
4956                            ,x_msg_count               => x_msg_count
4957                            ,x_msg_data                => x_msg_data
4958                           );
4959 
4960            IF (l_debug = 1) THEN
4961                 print_debug('CHECK_REFERENCE - After calling check_reference :'||x_return_status||':'||l_progress,1);
4962                 l_progress := 'WMSINB-45056';
4963            END IF;
4964 
4965            IF (x_return_status <> 'S') THEN
4966               l_progress := 'WMSINB-45058';
4967               RAISE fnd_api.g_exc_error;
4968            END IF;
4969 
4970 
4971 	   --{{
4972 	   --Test the case where a matching MOL is found.  Make sure
4973 	   --that l_mol_res_out(l_loop_index).quantity is in the correct
4974 	   --uom -- It should be because of the cosolidation critieria}}
4975 
4976            --
4977            -- UPDATE THE MOVE ORDER LINE HERE
4978            --
4979            update mtl_txn_request_lines
4980 	     set reference = l_reference
4981 	     ,reference_type_code = l_reference_type_code
4982 	     ,reference_id = l_reference_id
4983 	     ,quantity = quantity + l_mol_res_out(l_loop_index).quantity
4984 	     --Review how are you ensuring that this quantity is in the
4985 	     --right uom
4986 	     ,primary_quantity = primary_quantity + l_mol_res_out(l_loop_index).primary_qty
4987 	     ,secondary_quantity = secondary_quantity + l_mol_res_out(l_loop_index).secondary_quantity
4988 	     ,transaction_type_id = nvl(l_transaction_type_id,transaction_type_id)
4989 	     ,transaction_source_type_id = nvl(l_txn_source_type_id,transaction_source_type_id)
4990              where line_id = l_transfer_mol_rec.line_id
4991 	     ;
4992 
4993            l_progress := 'WMSINB-45060';
4994 
4995            --
4996            -- CANCEL THE OPERATION PLAN
4997            -- IF THE LPN IS LOADED AND TASK IS DISPATCHED
4998            -- WE NEED TO FAIL HERE
4999            --
5000 
5001            l_loaded := 0;
5002 
5003 	   --{{
5004 	   --Try to receive into a LPN that is loaded.  This should have
5005 	   --been validated by the ui already}}
5006            BEGIN
5007                     SELECT 1
5008                     INTO l_loaded
5009                     FROM dual
5010                     WHERE exists
5011                     (SELECT 1
5012                      FROM wms_dispatched_tasks wdt
5013                      , mtl_material_transactions_temp mmtt
5014                      WHERE mmtt.move_order_line_id =  l_transfer_mol_rec.line_id
5015                      AND wdt.transaction_temp_id = mmtt.transaction_temp_id
5016                      AND wdt.status IN (3, 4) -- dispached or loaded
5017                      AND wdt.task_type = 2 -- putaway
5018                      );
5019 
5020                   IF (l_debug = 1) THEN
5021                      print_debug('MAINTAIN_MO_CON - TASK ALREADY LOADED FOR '||l_transfer_mol_rec.line_id || ' FAILURE' ,1);
5022                   END IF;
5023 
5024                   l_progress := 'WMSINB-45063';
5025                   RAISE fnd_api.g_exc_error;
5026 
5027            EXCEPTION
5028              WHEN NO_DATA_FOUND THEN
5029                   l_progress := 'WMSINB-45064';
5030                   null;
5031            END;
5032 
5033 	   --{{
5034 	   --Complete 1 step of a multi-step ATF plan.  Receive into that LPN.
5035 	   --Make sure that the operation instance is cancelled for that LPN.}}
5036            call_atf_api(x_return_status => x_return_status,
5037                             x_msg_data => x_msg_data,
5038                             x_msg_count => x_msg_count,
5039                             x_error_code => l_error_code,
5040                             p_source_task_id => NULL,
5041                             p_activity_type_id => 1,
5042                             p_operation_type_id => NULL,
5043                             p_mol_id => l_transfer_mol_rec.line_id,
5044                             p_atf_api_name => g_atf_api_cancel);
5045 
5046            IF (x_return_status <> g_ret_sts_success) THEN
5047                   IF (l_debug = 1) THEN
5048                      print_debug('MAINTAIN_MO_CON - call_atf_api failed:'||l_transfer_mol_rec.line_id,1);
5049                      l_progress := 'WMSINB-45063';
5050                   END IF;
5051                   --raise error
5052                   l_progress := 'WMSINB-45064';
5053                   RAISE fnd_api.g_exc_error;
5054            END IF;
5055 
5056         Else
5057 
5058            -- Move Order Line Not Found Create Move Order
5059 
5060            IF (l_debug = 1) THEN
5061 	      print_debug('MAINTAIN_MOC_CON - Move Order Line Not Found line Id ',1);
5062            END IF;
5063 
5064            --create mol
5065            inv_rcv_std_rcpt_apis.create_move_order(p_move_order_header_id => l_move_order_header_id
5066                                               ,p_po_line_location_id      => p_po_line_location_id
5067                                               ,p_po_distribution_id       => p_po_distribution_id
5068                                               ,p_shipment_line_id         => p_shipment_line_id
5069                                               ,p_oe_order_line_id         => p_oe_order_line_id
5070                                               ,p_routing                  => p_routing_header_id
5071                                               ,p_lot_control_code         => p_lot_control_code
5072                                               ,p_org_id                   => l_mol_res_out(l_loop_index).organization_id
5073                                               ,p_item_id                  => l_mol_res_out(l_loop_index).inventory_item_id
5074                                               ,p_qty                      => l_mol_res_out(l_loop_index).quantity
5075                                               ,p_uom_code                 => l_mol_res_out(l_loop_index).uom_code
5076                                               ,p_lpn                      => l_mol_res_out(l_loop_index).lpn_id
5077                                               ,p_project_id               => l_mol_res_out(l_loop_index).project_id
5078                                               ,p_task_id                  => l_mol_res_out(l_loop_index).task_id
5079                                               ,p_revision                 => l_mol_res_out(l_loop_index).item_revision
5080                                               ,p_inspect                  => l_mol_res_out(l_loop_index).inspection_status
5081                                               ,p_txn_source_id            => null
5082                                               ,x_status                   => x_return_status
5083                                               ,x_message                  => x_msg_data
5084                                               ,p_transfer_org_id          => l_mol_res_out(l_loop_index).transfer_org_id
5085                                               ,p_wms_process_flag         => 1
5086                                               ,p_lot_number               => l_mol_res_out(l_loop_index).lot_number
5087                                               ,p_secondary_quantity       => l_mol_res_out(l_loop_index).secondary_quantity
5088                                               ,p_secondary_uom            => l_mol_res_out(l_loop_index).secondary_uom
5089                                               ,x_line_id                  => l_move_order_line_id
5090                                               );
5091             IF (l_debug = 1) THEN
5092                  print_debug('MAINTAIN_MO_CON - After calling create_move_order:'||x_return_status||':'||l_progress,1);
5093                  print_debug('MAINTAIN_MO_CON - Move Order Header ID:'||l_move_order_header_id||':'||l_progress,1);
5094                  print_debug('MAINTAIN_MO_CON - Move Order Line ID:'||l_move_order_line_id||':'||l_progress,1);
5095             END IF;
5096 
5097             IF (x_return_status <> 'S') THEN
5098                l_progress := 'WMSINB-45064';
5099                RAISE fnd_api.g_exc_error;
5100             END IF;
5101 
5102            --update mol for the sub and loc
5103 	   --{{
5104 	   --Receive into a RCV sub/loc.  Check MOL has these columns
5105 	   --stamped afterwards}}
5106            UPDATE mtl_txn_request_lines
5107               SET from_subinventory_code = Nvl(p_subinventory,from_subinventory_code)
5108               , from_locator_id = Nvl(p_locator_id, from_locator_id)
5109 	      , backorder_delivery_detail_id = l_mol_res_out(l_loop_index).backorder_delivery_detail_id
5110 	      , crossdock_type = l_mol_res_out(l_loop_index).crossdock_type
5111 	     WHERE header_id = l_move_order_header_id
5112                 and line_id = l_move_order_line_id
5113                 and organization_id = p_org_id
5114                 AND inventory_item_id = p_item_id;
5115 
5116 	   -- Call to UPDATE WDD
5117 	   --Review. Shoudn't this be outside the if mol not found block???
5118 	   --{{
5119 	   --Create xdock reservation for the item.  Do receipt.  Make
5120 	   --sure that WDD is updated with the MOL}}
5121 	   IF (l_mol_res_out(l_loop_index).backorder_delivery_detail_id IS NOT NULL) THEN
5122 	      inv_rcv_reservation_util.update_wdd
5123 		(x_return_status => x_return_status
5124 		 ,x_msg_count    => x_msg_count
5125 		 ,x_msg_data     => x_msg_data
5126 		 ,p_wdd_id       => l_mol_res_out(l_loop_index).backorder_delivery_detail_id
5127 		 ,p_released_status => null
5128 		 ,p_mol_id          => l_move_order_line_id
5129 		 );
5130 	   END IF;
5131 
5132 
5133            IF (l_debug = 1) THEN
5134                  print_debug('MAINTAIN_MO_CON - After calling update_wdd '||x_return_status||':'||l_progress,1);
5135                  print_debug('MAINTAIN_MO_CON - Move Order Header ID:'||l_move_order_header_id||':'||l_progress,1);
5136            END IF;
5137 
5138            IF (x_return_status <> 'S') THEN
5139                l_progress := 'WMSINB-45064';
5140                RAISE fnd_api.g_exc_error;
5141            END IF;
5142 
5143 
5144         End if;
5145 
5146 
5147 	l_loop_index := l_mol_res_out.next(l_loop_index);
5148       END LOOP;
5149 
5150       --call upd_empty_mixed_flag
5151       IF p_locator_id IS NOT NULL THEN
5152 	 IF (l_debug = 1) THEN
5153 	    print_debug('MAINTAIN_MO_CON - Calling upd_empty_mixed_flag for	CURRENT sub',1);
5154 	 END IF;
5155 
5156 	 inv_loc_wms_utils.upd_empty_mixed_flag_rcv_loc ( x_return_status  => x_return_status
5157 							  ,x_msg_count    => x_msg_count
5158 							  ,x_msg_data     => x_msg_data
5159 							  ,p_subinventory => p_subinventory
5160 							  ,p_locator_id   => p_locator_id
5161 							  ,p_org_id       => p_org_id
5162 							  );
5163 	 IF (x_return_status <> 'S') THEN
5164 	    l_progress := 'WMSINB-45067';
5165       -- Bug 5393727: do not raise an exception if locator API returns an error
5166 	    -- RAISE fnd_api.g_exc_error;
5167 	 END IF;
5168 
5169 	 -- update curr capacity
5170 	 IF (l_debug = 1) THEN
5171 	    print_debug('MAINTAIN_MO_CON - Calling update_loc_curr_capacity_nauto FOR CURRENT sub',1);
5172 	 END IF;
5173 
5174 	 inv_loc_wms_utils.update_loc_curr_capacity_nauto
5175 	   ( x_return_status           => x_return_status
5176 	     ,x_msg_count               => x_msg_count
5177 	     ,x_msg_data                => x_msg_data
5178 	     ,p_organization_id         => p_org_id
5179 	     ,p_inventory_location_id   => p_locator_id
5180 	     ,p_inventory_item_id       => p_item_id
5181 	     ,p_primary_uom_flag        => 'N'
5182 	     ,p_transaction_uom_code    => p_uom_code
5183 	     ,p_quantity                => p_qty
5184 	     ,p_issue_flag              => 'N'
5185 	     );
5186 	 IF (x_return_status <> 'S') THEN
5187 	    l_progress := 'WMSINB-45070';
5188 	    -- Bug 5393727: do not raise an exception if locator API returns an error
5189 	    -- RAISE fnd_api.g_exc_error;
5190 	 END IF;
5191       END IF; --IF p_subinventory IS NOT NULL THEN
5192 
5193 --pregeneration
5194 --Review. Move this pregeneration call to complete_lpn_group !!!
5195 -- R12 commented this call
5196 -- As this has been moved to complete_lpn_group procedure
5197 -- l_call_pregeneration := TRUE;
5198 
5199 --     IF (p_transfer_lpn_id IS NULL) THEN
5200 --	 l_call_pregeneration := FALSE;
5201 --      ELSE
5202 --	 IF p_lot_control_code > 1 THEN
5203 --	    IF p_lot_number IS NULL THEN
5204 --	       l_call_pregeneration := FALSE;
5205 --	    END IF;
5206 --	  ELSIF p_serial_number_control_code IN (2,5,6) THEN
5207 --	    BEGIN
5208 --	       SELECT '1'
5209 --		 INTO l_dummy
5210 --		 FROM mtl_serial_numbers_temp
5211 --		 WHERE product_code = 'RCV'
5212 --		 AND product_transaction_id = p_rti_id
5213 --		 AND ROWNUM < 2;
5214 --	    EXCEPTION
5215 --	       WHEN OTHERS THEN
5216 --		  l_call_pregeneration := FALSE;
5217 --	    END;
5218 --	 END IF;
5219 --    END IF; --IF (p_lpn_id IS NULL) THEN
5220 
5221 --call pregeneration
5222 --     IF l_call_pregeneration THEN
5223 --	 IF (l_debug = 1) THEN
5224 --	    print_debug('MAINTAIN_MO_CON - Before calling start_pregenerate_program:'||l_progress,1);
5225 --	    l_progress := 'WMSINB-45072';
5226 --	 END IF;
5227 --	 wms_putaway_suggestions.start_pregenerate_program
5228 --	   (p_org_id => p_org_id,
5229 --	    p_lpn_id => p_transfer_lpn_id,
5230 --	    x_return_status => x_return_status,
5231 --	    x_msg_count => x_msg_count,
5232 --	    x_msg_data => x_msg_data);
5233 --
5234 --	 IF (l_debug = 1) THEN
5235 --	    print_debug('MAINTAIN_MO_CON - After calling start_pregenerate_program:'||x_return_status||':'||l_progress,1);
5236 --	    l_progress := 'WMSINB-45073';
5237 --	 END IF;
5238 --
5239 --	 IF (x_return_status <> 'S') THEN
5240 --	    x_return_status := 'S';
5241 --  	 END IF;
5242 -- END IF; --IF l_call_pregeneration THEN
5243 -- R12
5244 -- Commented the above call
5245 
5246    END IF; --IF l_transaction_type = 'RECEIVE' THEN
5247 
5248    IF l_transaction_type IN ('ACCEPT','REJECT','TRANSFER') THEN
5249       IF (l_debug = 1) THEN
5250 	 print_debug('MAINTAIN_MO_CON - CASE FOR ACCEP, TREJECT,TRANSFER',1);
5251       END IF;
5252 
5253 
5254       /* Bug 6830559 */
5255       IF (p_project_id IS NULL) THEN
5256 	 IF (p_po_distribution_id IS NOT NULL) THEN
5257 	    BEGIN
5258 	       SELECT project_id,
5259 		 Nvl(task_id, -1)
5260 		 INTO l_project_id,
5261 		 l_task_id
5262 		 FROM po_distributions_all
5263 		 WHERE po_distribution_id = p_po_distribution_id;
5264 	    EXCEPTION
5265 	       WHEN no_data_found THEN
5266 		  l_project_id := NULL;
5267 		  l_task_id := NULL;
5268 	    END ;
5269          ELSIF (p_po_line_location_id IS NOT NULL) then
5270             inv_rcv_std_rcpt_apis.get_project_task(
5271                  p_po_line_location_id     => p_po_line_location_id
5272                , p_oe_order_line_id        => NULL
5273                , x_project_id              => l_project_id
5274                , x_task_id                 => l_task_id
5275             );
5276 	 END IF;
5277        ELSE --IF (p_project_id IS NULL) THEN
5278 		  l_project_id := p_project_id;
5279 		  l_task_id := p_task_id;
5280        END IF; --IF (p_project_id IS NULL) THEN
5281 
5282 
5283 
5284       --{{
5285       --Test:
5286       --1) mobile putaway (there is always have MMTT)
5287       --2) Desktop transfer/deliver (turn pregen off so there is no MMTT)
5288       --3) Mobile inspect (there may or may not have MMTT)
5289       --4) Desktop inspect }}
5290 
5291       IF (p_mmtt_temp_id IS NOT NULL) THEN
5292 
5293 	 OPEN c_mol_mmtt(p_mmtt_temp_id,
5294                          p_item_id,
5295                          p_lpn_id,
5296 			 p_lot_number,
5297                          p_revision,
5298                          p_from_subinventory,
5299                          p_from_locator_id,
5300                          l_project_id, -- p_project_id, /* Bug 6830559 */
5301                          l_task_id, -- p_task_id, /* Bug 6830559 */
5302                          l_from_mol_inspection_status
5303                         );
5304        ELSE
5305 	 OPEN c_mol_no_mmtt(
5306                             p_item_id,
5307                             p_lpn_id,
5308 			    p_lot_number,
5309                             p_revision,
5310                             p_from_subinventory,
5311                             p_from_locator_id,
5312                             -- ,p_cost_group_id ????
5313                             l_project_id, -- p_project_id, -- Bug 6830559
5314                             l_task_id, -- p_task_id, -- Bug 6830559
5315                             l_from_mol_inspection_status ,
5316                             p_uom_code
5317                            );
5318       END IF;
5319 
5320       --Maneesh
5321       l_mol_res_in(1).transaction_type       := l_transaction_type;
5322       l_mol_res_in(1).organization_id        := p_org_id;
5323       l_mol_res_in(1).lpn_id                 := p_transfer_lpn_id;
5324       l_mol_res_in(1).inventory_item_id      := p_item_id;
5325       l_mol_res_in(1).lot_number             := p_lot_number;
5326       l_mol_res_in(1).item_revision          := p_revision;
5327       l_mol_res_in(1).from_subinventory_code := p_subinventory;
5328       l_mol_res_in(1).from_locator_id        := p_locator_id;
5329       -- l_mol_res_in(1).cost_group_id          := p_cost_group_id; ????
5330       l_mol_res_in(1).project_id             := l_project_id;
5331       l_mol_res_in(1).task_id                := l_task_id;
5332       l_mol_res_in(1).uom_code               := p_uom_code;
5333       l_mol_res_in(1).backorder_delivery_detail_id := null;
5334       l_mol_res_in(1).crossdock_type         := null;
5335       l_mol_res_in(1).transfer_org_id        := l_transfer_org_id;
5336       l_mol_res_in(1).secondary_uom          := p_sec_uom;
5337       l_mol_res_in(1).inspection_status      := l_transfer_inspection_status ;
5338 
5339       -- CHANGES FOR  FROM MOL AND TRANSFER MOL POINTS TO THE SAME MOL
5340       -- IF FROM AND TRANSFER MOL POINTS TO THE SAME MOL LINE i,e NO
5341       -- CHANGES IN THE CONSOLIDATING CRITERIA THEN DON'T DO ANYTHING
5342       -- FOR THE MOVE ORDER LINE FOR THE ABOVE TXNS.
5343 
5344       IF (  nvl(l_mol_res_in(1).lpn_id,-1) = nvl(p_lpn_id ,-1)
5345         and nvl(l_mol_res_in(1).inventory_item_id,-1) = nvl(p_item_id,-1)
5346         and nvl(l_mol_res_in(1).lot_number,'@$#_') = nvl(p_lot_number,'@$#_')
5347         and nvl(l_mol_res_in(1).item_revision,'@$#_') = nvl(p_revision,'@$#_')
5348         and nvl(l_mol_res_in(1).from_subinventory_code,'@$#_') =  nvl(p_from_subinventory,'@$#_')
5349         and nvl(l_mol_res_in(1).from_locator_id,-1) = nvl(p_from_locator_id,-1)
5350         and nvl(l_mol_res_in(1).project_id,-1) = nvl(l_project_id,-1) /* Bug 6830559 */
5351         and nvl(l_mol_res_in(1).task_id,-1) = nvl(l_task_id,-1) /* Bug 6830559 */
5352         and l_mol_res_in(1).uom_code = p_uom_code
5353         and nvl(l_mol_res_in(1).inspection_status,-1) =  nvl(l_from_mol_inspection_status,-1) )
5354      THEN
5355         -- CONSOLIDATING CRITERIA SAME NO CHANGES FOR MOL LINE FOR THIS CASE.
5356         l_update_or_close := 'N';
5357         IF (l_debug = 1) THEN
5358             print_debug('MAINTAIN_MO_CON - UPDATE OR CLOSE: '||l_update_or_close,1);
5359         END IF;
5360      END IF;
5361 
5362 
5363       --{{
5364       --Test cases where there is or is not a MOL line}}
5365 
5366       IF l_update_or_close = 'N' THEN
5367         IF (l_debug = 1) THEN
5368             print_debug('MAINTAIN_MO_CON - NO NEED TO PROCESS FOR THIS CASE',1);
5369         END IF;
5370       ELSE
5371         IF (l_debug = 1) THEN
5372             print_debug('MAINTAIN_MO_CON - OPENING TRANSFER MOL FOR THIS CASE',1);
5373         END IF;
5374         open c_transfer_mol(
5375 			  l_mol_res_in(1).lpn_id
5376 			  ,l_mol_res_in(1).inventory_item_id
5377 			  ,l_mol_res_in(1).lot_number
5378 			  ,l_mol_res_in(1).item_revision
5379 			  ,l_mol_res_in(1).from_subinventory_code
5380 			  ,l_mol_res_in(1).from_locator_id
5381 			  ,l_mol_res_in(1).project_id
5382 			  ,l_mol_res_in(1).task_id
5383 			  ,l_mol_res_in(1).uom_code
5384 			  ,l_mol_res_in(1).backorder_delivery_detail_id
5385 			  ,l_mol_res_in(1).crossdock_type
5386 			  ,l_mol_res_in(1).inspection_status
5387 			  );
5388 
5389         Fetch c_transfer_mol into l_transfer_mol_rec;
5390         close c_transfer_mol;
5391 
5392         IF l_transfer_mol_rec.line_id IS NOT NULL THEN
5393          	 l_update_or_close := 'C';
5394 
5395 	 --Move the check to here so that it is done before we
5396 	 --tie MMTT/WDT to the transfer MOL.  This is needed
5397 	 --because we won't call complete_operation_instance
5398 	 --for the MMTT until the end of the API.  Therefore,
5399 	 --the check below would fail if it is done after we
5400 	 --tie MMTT/WDT
5401 
5402 	 --Also, this check is not needed because we should allow
5403 	 --loading materials into a loaded LPN
5404 	   IF (l_transaction_type <> 'TRANSFER') THEN
5405 	      l_loaded := 0;
5406 
5407               BEGIN
5408 	         SELECT 1
5409 	  	 INTO l_loaded
5410 	  	 FROM dual
5411 	  	 WHERE exists
5412 	  	 (SELECT 1
5413 	  	  FROM wms_dispatched_tasks wdt
5414 	  	  , mtl_material_transactions_temp mmtt
5415 	  	  WHERE mmtt.move_order_line_id =  l_transfer_mol_rec.line_id
5416 	  	  AND wdt.transaction_temp_id = mmtt.transaction_temp_id
5417 	  	  AND wdt.status IN (3, 4) -- dispached or loaded
5418 	  	  AND wdt.task_type = 2 -- putaway
5419 		  );
5420 
5421 	         IF (l_debug = 1) THEN
5422 	  	  print_debug('MAINTAIN_MO_CON - TASK ALREADY LOADED FOR '||l_transfer_mol_rec.line_id || ' FAILURE ' ,1);
5423 	         END IF;
5424 
5425 	         l_progress := 'WMSINB-45129';
5426 	         RAISE fnd_api.g_exc_error;
5427 
5428 	      EXCEPTION
5429 	         WHEN NO_DATA_FOUND THEN
5430 	  	  l_progress := 'WMSINB-45130';
5431 	  	  null;
5432 	      END;
5433 	   END IF;
5434 
5435         ELSE
5436   	   l_update_or_close := 'U';
5437         END IF;
5438       END IF; -- IF l_update_or_close = 'N' THEN
5439 
5440       IF (l_debug = 1) THEN
5441 	 print_debug('MAINTAIN_MO_CON - UPDATE OR CLOSE: '||l_update_or_close,1);
5442       END IF;
5443 
5444 
5445     IF l_update_or_close = 'N' THEN
5446        --
5447        IF (l_debug = 1) THEN
5448 	 print_debug('MAINTAIN_MO_CON - NO PROCESSING!!',1);
5449        END IF;
5450     ELSE
5451 
5452       l_remaining_primary_quantity := p_primary_quantity;
5453 
5454       --{{
5455       --For cases where there is no MMTT, make sure that the correct MOL is returned.  }}
5456 
5457 
5458       LOOP
5459 	 IF (p_mmtt_temp_id IS NOT NULL) THEN
5460 	    FETCH c_mol_mmtt INTO l_mol_rec;
5461 	    EXIT WHEN c_mol_mmtt%notfound;
5462 	  ELSE
5463 	       FETCH c_mol_no_mmtt INTO l_mol_rec;
5464 	       EXIT WHEN c_mol_no_mmtt%notfound;
5465 	 END IF;
5466 
5467 	 IF (l_debug = 1) THEN
5468 	    print_debug('MAINTAIN_MO_CON - REMAINING QUANTITY:'||l_remaining_primary_quantity||':'||l_progress,1);
5469 	    print_debug('MAINTAIN_MO_CON - LINE_ID:'||l_mol_rec.line_id||' WMS_PROCESS_FLAG:'||l_mol_rec.wms_process_flag,1);
5470 	    l_progress := 'WMSINB-45075';
5471 	 END IF;
5472 
5473 	 --BUG 4766810: Always add before rounding.  Also, when comparing
5474 	 -- for equality, check if the two number differs by 0.000005
5475 	 -- (round to 5 digits).
5476 	 IF (l_mol_rec.uom_code <> p_primary_uom_code) THEN
5477 	    l_conversion_rate := inv_rcv_cache.get_conversion_rate(l_mol_rec.inventory_item_id,
5478 								   l_mol_rec.uom_code,
5479 								   p_primary_uom_code);
5480 	    l_mol_qty_in_puom := l_mol_rec.quantity * l_conversion_rate;
5481 	  ELSE
5482 	    l_mol_qty_in_puom := l_mol_rec.quantity;
5483 	    l_conversion_rate := 1;
5484 	 END IF;
5485 
5486 	 IF (l_debug = 1) THEN
5487 	    print_debug('MAINTAIN_MO - MOL QTY IN PUOM:'||l_mol_qty_in_puom||':'||l_progress,1);
5488 	 END IF;
5489 
5490          l_backorder_delivery_detail_id := null;
5491          l_mol_consumed_full            := 0;
5492 
5493          -- SET THE REFERENCE INFORMATION HERE
5494          l_new_reference           := l_mol_rec.reference;
5495          l_new_reference_type_code := l_mol_rec.reference_type_code;
5496          l_new_reference_id        := l_mol_rec.reference_id;
5497 
5498 	 --BUG 4766810, always round to 5 digits when comparing because
5499 	 --quantity is stored in 5 digits in Inventory
5500 	 IF Round(l_mol_qty_in_puom,5) <= Round(l_remaining_primary_quantity,5) THEN
5501 
5502             -- ***************************************************
5503             -- IF THE LINE IS NOT BACKORDERD THEN CLOSE THE LINE
5504             -- IF THE LINE IS BACKORDERD THEN UPDATED THE LINE
5505             -- ***************************************************
5506 	    IF (l_debug = 1) THEN
5507 	       print_debug('MAINTAIN_MO_CON - mol consumed full ',1);
5508 	    END IF;
5509 
5510             l_backorder_delivery_detail_id := l_mol_rec.backorder_delivery_detail_id;
5511             l_mol_consumed_full            := 1;
5512 
5513             IF (l_backorder_delivery_detail_id is not NULL AND l_transaction_type = 'REJECT') THEN
5514 	       IF (l_debug = 1) THEN
5515 		  print_debug('Reject xdock materials.  Calling inv_reservation_pub.delete_reservation',4);
5516 	       END IF;
5517 
5518 	       l_rsv_rec.demand_source_line_detail := l_backorder_delivery_detail_id;
5519 	       l_rsv_rec.organization_id           := p_org_id;
5520 	       l_rsv_rec.inventory_item_id         := l_mol_rec.inventory_item_id;
5521 
5522 	       inv_reservation_pub.delete_reservation
5523 		 (p_api_version_number       => 1.0
5524 		  , x_return_status          => l_return_status
5525 		  , x_msg_count              => l_msg_count
5526 		  , x_msg_data               => l_msg_data
5527 		  , p_rsv_rec                => l_rsv_rec
5528 		  , p_serial_number          => l_dummy_serial
5529 		  );
5530 
5531 	       IF (l_debug = 1) THEN
5532 		  print_debug('Returned from inv_reservation_pub.delete_reservation',4);
5533 		  print_debug('x_return_status =>'||l_return_status,4);
5534 	       END IF;
5535 
5536 	       IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
5537 		  IF (l_debug = 1) THEN
5538 		     print_debug('x_msg_data:  '||l_msg_data,4);
5539 		     print_debug('x_msg_count: '||l_msg_count,4);
5540 			 print_debug('SQLCODE:'||SQLCODE||' SQLERRM:'||SQLERRM,4);
5541 			 print_debug('Raising Exception!!!',4);
5542 		  END IF;
5543 		  l_progress := '@@@';
5544 		  RAISE fnd_api.g_exc_unexpected_error;
5545 	       END IF;
5546 
5547 	       l_backorder_delivery_detail_id := NULL;
5548 	    END IF; --IF (l_backorder_delivery_detail_id is not NULL AND l_transaction_type = 'REJECT') THEN
5549 
5550 	    IF l_backorder_delivery_detail_id IS NOT NULL THEN
5551 		l_progress := 'WMSINB-45078';
5552 	        --update the mol
5553 
5554 	        IF (l_debug = 1) THEN
5555 	           print_debug('MAINTAIN_MO_CON - l_backorder_delivery_detail_id = '|| l_backorder_delivery_detail_id,1);
5556 	        END IF;
5557 
5558 		--Update quantity with the quantity converted to the UOM in the RTI.  This is changed so
5559 		--that the we honor the UOM entered by the user during
5560 		--Transfer
5561 		IF (l_mol_rec.uom_code <> p_uom_code) THEN
5562 		   l_tmp_qty := inv_rcv_cache.convert_qty(l_mol_rec.inventory_item_id
5563 							  ,l_mol_rec.txn_qty
5564 							  ,l_mol_rec.uom_code
5565 							  ,p_uom_code);
5566 		   l_tmp_qty_dtld := inv_rcv_cache.convert_qty(l_mol_rec.inventory_item_id
5567 							       ,l_mol_rec.quantity_detailed
5568 							       ,l_mol_rec.uom_code
5569 							       ,p_uom_code);
5570 		   l_tmp_qty_dlvd := inv_rcv_cache.convert_qty(l_mol_rec.inventory_item_id
5571 							       ,l_mol_rec.quantity_delivered
5572 							       ,l_mol_rec.uom_code
5573 							       ,p_uom_code);
5574 		   l_tmp_uom_code := p_uom_code;
5575 		 ELSE
5576 		   l_tmp_qty := l_mol_rec.txn_qty;
5577 		   l_tmp_qty_dtld := l_mol_rec.quantity_detailed;
5578 		   l_tmp_qty_dlvd := l_mol_rec.quantity_delivered;
5579 		   l_tmp_uom_code := l_mol_rec.uom_code;
5580 		END IF;
5581 
5582 	        IF (l_debug = 1) THEN
5583 	           print_debug('MAINTAIN_MO_CON - l_tmp_qty:'||l_tmp_qty,4);
5584 		   print_debug('MAINTAIN_MO_CON - l_tmp_qty_dtld:'||l_tmp_qty_dtld,4);
5585 		   print_debug('MAINTAIN_MO_CON - l_tmp_qty_dlvd:'||l_tmp_qty_dlvd,4);
5586 		   print_debug('MAINTAIN_MO_CON - l_tmp_uom_code:'||l_tmp_uom_code,4);
5587 	        END IF;
5588 
5589 		UPDATE mtl_txn_request_lines
5590 	          SET inspection_status = Decode(l_transaction_type,'ACCEPT',2,'REJECT',3,inspection_status)
5591 	          , lpn_id = p_transfer_lpn_id
5592 		  , quantity = l_tmp_qty
5593 	          , quantity_detailed = Decode(l_transaction_type,'TRANSFER',l_tmp_qty_dtld,NULL)
5594 	          , quantity_delivered = Decode(l_transaction_type,'TRANSFER',l_tmp_qty_dlvd,NULL)
5595 		  , uom_code = l_tmp_uom_code
5596                   -- OPMConvergence
5597 	          , secondary_quantity_detailed = Decode(l_transaction_type,'TRANSFER',secondary_quantity_detailed,NULL)
5598                   -- OPMConvergence
5599 	          , lot_number = p_lot_number
5600 	          , revision = p_revision
5601 	          , from_subinventory_code = Nvl(p_subinventory, from_subinventory_code)
5602 	          , from_locator_id = Nvl(p_locator_id, from_locator_id)
5603 	          , wms_process_flag = 1
5604 	          WHERE line_id = l_mol_rec.line_id;
5605             else
5606 	        IF (l_debug = 1) THEN
5607 	           print_debug('MAINTAIN_MO_CON - backorder_delivery_detail_id is null ',1);
5608 	        END IF;
5609 		l_progress := 'WMSINB-45079';
5610 		--If p_mmtt_temp_id is not null then the move order line should
5611 		--not be closed because this unnecessarily leads to
5612 		--cancelling of operation plan. The line should be closed
5613 		--if and only if there is a transfer mol present with the
5614 		--same consolidation criteria. Otherwise it should be
5615 		--updated just like the crossdock mols.
5616 		--Add an extra parameter to transfer_mol cursor. This new
5617 		--parameter will be the current mol id. Transfer mol cursor
5618 		--should not pickup the lines which have line_id = new
5619 		--prameter. Open the transfer mol cursor
5620 
5621 		IF (l_update_or_close = 'C') THEN
5622 
5623 	           IF (l_debug = 1) THEN
5624 	              print_debug('MAINTAIN_MO_CON - before updating mol update or close = C ',1);
5625 	           END IF;
5626 
5627 		   UPDATE mtl_txn_request_lines
5628 		     SET   line_status = inv_globals.G_TO_STATUS_CLOSED
5629 		     , quantity = Nvl(quantity_delivered,0)
5630 		     , quantity_detailed = quantity_delivered
5631 		     , secondary_quantity_detailed = SECONDARY_QUANTITY_DELIVERED
5632 		     --BDD_ID will get NULL out for REJECT cases
5633 		     , backorder_delivery_detail_id = l_backorder_delivery_detail_id
5634 		     , crossdock_type = Decode(l_backorder_delivery_detail_id,NULL,NULL,crossdock_type)
5635 		     , wms_process_flag = 1
5636 		     WHERE line_id = l_mol_rec.line_id;
5637 
5638 		 ELSE
5639 
5640 		   --Update quantity with the quantity converted to the UOM in the RTI.  This is changed so
5641 		   --that the we honor the UOM entered by the user during
5642 		   --Transfer
5643 		   IF (l_mol_rec.uom_code <> p_uom_code) THEN
5644 		      l_tmp_qty := inv_rcv_cache.convert_qty(l_mol_rec.inventory_item_id
5645 							     ,l_mol_rec.txn_qty
5646 							     ,l_mol_rec.uom_code
5647 							     ,p_uom_code);
5648 		      l_tmp_qty_dtld := inv_rcv_cache.convert_qty(l_mol_rec.inventory_item_id
5649 								  ,l_mol_rec.quantity_detailed
5650 								  ,l_mol_rec.uom_code
5651 								  ,p_uom_code);
5652 		      l_tmp_qty_dlvd := inv_rcv_cache.convert_qty(l_mol_rec.inventory_item_id
5653 								  ,l_mol_rec.quantity_delivered
5654 								  ,l_mol_rec.uom_code
5655 								  ,p_uom_code);
5656 		      l_tmp_uom_code := p_uom_code;
5657 		    ELSE
5658 		      l_tmp_qty := l_mol_rec.txn_qty;
5659 		      l_tmp_qty_dtld := l_mol_rec.quantity_detailed;
5660 		      l_tmp_qty_dlvd := l_mol_rec.quantity_delivered;
5661 		      l_tmp_uom_code := l_mol_rec.uom_code;
5662 		   END IF;
5663 
5664 		   IF (l_debug = 1) THEN
5665 		      print_debug('MAINTAIN_MO_CON - l_tmp_qty:'||l_tmp_qty,4);
5666 		      print_debug('MAINTAIN_MO_CON - l_tmp_qty_dtld:'||l_tmp_qty_dtld,4);
5667 		      print_debug('MAINTAIN_MO_CON - l_tmp_qty_dlvd:'||l_tmp_qty_dlvd,4);
5668 		      print_debug('MAINTAIN_MO_CON - l_tmp_uom_code:'||l_tmp_uom_code,4);
5669 		   END IF;
5670 
5671 	           IF (l_debug = 1) THEN
5672 	              print_debug('MAINTAIN_MO_CON - before updating mol update or clode <> C ',1);
5673 	           END IF;
5674 
5675 		   UPDATE mtl_txn_request_lines
5676 		     SET inspection_status = Decode(l_transaction_type,'ACCEPT',2,'REJECT',3,inspection_status)
5677 		     , lpn_id = p_transfer_lpn_id
5678 		     , quantity = l_tmp_qty
5679 		     , quantity_detailed = Decode(l_transaction_type,'TRANSFER',l_tmp_qty_dtld,NULL)
5680 		     , quantity_delivered = l_tmp_qty_dlvd
5681 		     , uom_code = l_tmp_uom_code
5682 		     -- OPMConvergence
5683 		     , secondary_quantity_detailed = Decode(l_transaction_type,'TRANSFER',secondary_quantity_detailed,NULL)
5684 		     -- OPMConvergence
5685 		     , lot_number = p_lot_number
5686 		     , revision = p_revision
5687 		     , from_subinventory_code = Nvl(p_subinventory, from_subinventory_code)
5688 		     , from_locator_id = Nvl(p_locator_id, from_locator_id)
5689 		     --BDD_ID will get NULL out for REJECT cases
5690 		     , backorder_delivery_detail_id = l_backorder_delivery_detail_id
5691 		     , crossdock_type = Decode(l_backorder_delivery_detail_id,NULL,NULL,crossdock_type)
5692 		     , wms_process_flag = 1
5693 		     WHERE line_id = l_mol_rec.line_id;
5694 		END IF;
5695 
5696             end if; --  if l_backorder_delivery_detail_id  is not null
5697 
5698 	    l_remaining_primary_quantity := l_remaining_primary_quantity - l_mol_qty_in_puom;
5699 
5700 	    -- Bug 5632202 : Set l_remaining_primary_quantity to zero if it differs from MOL
5701 	    --               quantity in sixth decimal place
5702 	    IF trunc(( l_remaining_primary_quantity/ l_conversion_rate ),5) = 0 THEN
5703 	      l_remaining_primary_quantity := 0;
5704 	      IF (l_debug = 1) THEN
5705 		print_debug('MAINTAIN_MO_CON - Setting l_remaining_primary_quantity to zero',1);
5706 	      END IF;
5707 	    END IF;
5708 
5709 	    --cancel_operation_instance should be called only if
5710 	    --p_mmtt_temp_id is NULL
5711 	    IF (p_mmtt_temp_id IS NULL) THEN
5712 	       IF (l_debug = 1) THEN
5713 		  print_debug('MAINTAIN_MO_CON - calling call_atf_api:'||l_mol_rec.line_id,1);
5714 		  l_progress := 'WMSINB-45080';
5715 	       END IF;
5716 
5717 	       call_atf_api(x_return_status => x_return_status,
5718 			    x_msg_data => x_msg_data,
5719 			    x_msg_count => x_msg_count,
5720 			    x_error_code => l_error_code,
5721 			    p_source_task_id => NULL,
5722 			    p_activity_type_id => 1,
5723 			    p_operation_type_id => NULL,
5724 			    p_mol_id => l_mol_rec.line_id,
5725 			    p_atf_api_name => g_atf_api_cancel);
5726 
5727 	       IF (x_return_status <> g_ret_sts_success) THEN
5728 		  IF (l_debug = 1) THEN
5729 		     print_debug('MAINTAIN_MO - call_atf_api failed:'||l_mol_rec.line_id,1);
5730 		     l_progress := 'WMSINB-45085';
5731 		  END IF;
5732 		  --raise error
5733 		  l_progress := 'WMSINB-45090';
5734 		  RAISE fnd_api.g_exc_error;
5735 	       END IF;
5736 	    END IF;
5737 	  ELSE --IF  l_mol_qty_in_puom <= l_remaining_primary_quantity THEN
5738 	    --split_mol
5739 
5740 	    IF (l_debug = 1) THEN
5741 	       print_debug('MAINTAIN_MO_CON - CALLING SPLIT_MO:'||l_remaining_primary_quantity||':'||l_progress,1);
5742 	       l_progress := 'WMSINB-45108';
5743 	    END IF;
5744 
5745 	    l_mo_split_tb(1).prim_qty := l_remaining_primary_quantity;
5746             -- OPMConvergence
5747             -- Do we need to assign secondary quantity too ?
5748             -- OPMConvergence
5749 	    l_mo_split_tb(1).line_id := NULL;
5750 
5751 	    IF (l_debug = 1) THEN
5752 	       print_debug('MAINTAIN_MO - Finally Calling split_mo',1);
5753 	       l_progress := 'WMSINB-45110';
5754 	    END IF;
5755 
5756 	    IF p_mmtt_temp_id IS NOT NULL THEN
5757 	       -- Call split mo with operation_type DELIVER
5758 	       -- This will split the MO and tied the mmtt
5759 	       -- to the new MO
5760 	       inv_rcv_integration_apis.split_mo
5761 		 (p_orig_mol_id => l_mol_rec.line_id,
5762 		  p_mo_splt_tb => l_mo_split_tb,
5763 		  p_operation_type => 'DELIVER',
5764 		  p_txn_header_id => p_mmtt_temp_id,
5765 		  x_return_status => x_return_status,
5766 		  x_msg_count => x_msg_count,
5767 		  x_msg_data => x_msg_data);
5768 	     ELSE
5769 	       inv_rcv_integration_apis.split_mo
5770 		 (p_orig_mol_id => l_mol_rec.line_id,
5771 		  p_mo_splt_tb => l_mo_split_tb,
5772 		  x_return_status => x_return_status,
5773 		  x_msg_count => x_msg_count,
5774 		  x_msg_data => x_msg_data);
5775 	    END IF;
5776 
5777 	    IF (x_return_status <> 'S') THEN
5778 	       l_progress := 'WMSINB-45112';
5779 	       RAISE fnd_api.g_exc_error;
5780 	    END IF;
5781 
5782 
5783 	    IF (l_debug = 1) THEN
5784 	       print_debug('MAINTAIN_MO_CON - NEW LINE ID:'||l_mo_split_tb(1).line_id||':'||l_progress,1);
5785 	       l_progress := 'WMSINB-45114';
5786 	    END IF;
5787 
5788 
5789             l_mol_consumed_full            := 0;
5790             l_split_qty                    := 0;
5791             l_split_sec_qty                := 0;
5792 
5793             BEGIN
5794                   select  backorder_delivery_detail_id
5795                          ,(mtrl.quantity - Nvl(mtrl.quantity_delivered, 0))
5796                          ,(mtrl.secondary_quantity - Nvl(mtrl.secondary_quantity_delivered, 0))
5797                     into l_backorder_delivery_detail_id
5798                          ,l_split_qty
5799 			 ,l_split_sec_qty
5800                     from MTL_TXN_REQUEST_LINES mtrl
5801                    where mtrl.line_id = l_mo_split_tb(1).line_id;
5802 
5803 	       l_progress := 'WMSINB-45115';
5804 	       IF (l_debug = 1) THEN
5805 	           print_debug('MAINTAIN_MO_CON - CHECK WHETHER SPLITTED LINE IS BACKORDERD backorder_delivery_detail_id :'||l_backorder_delivery_detail_id,1);
5806 	       END IF;
5807 
5808             EXCEPTION
5809                  WHEN OTHERS THEN
5810                       l_backorder_delivery_detail_id := null;
5811             END;
5812 
5813 
5814             IF (l_backorder_delivery_detail_id is not null AND l_transaction_type = 'REJECT') THEN
5815 	       IF (l_debug = 1) THEN
5816 		  print_debug('Calling inv_reservation_pub.delete_reservation',4);
5817 	       END IF;
5818 
5819 	       l_rsv_rec.demand_source_line_detail := l_backorder_delivery_detail_id;
5820 	       l_rsv_rec.organization_id           := p_org_id;
5821 	       l_rsv_rec.inventory_item_id         := l_mol_rec.inventory_item_id;
5822 
5823 	       inv_reservation_pub.delete_reservation
5824 		 (p_api_version_number       => 1.0
5825 		  , x_return_status          => l_return_status
5826 		  , x_msg_count              => l_msg_count
5827 		  , x_msg_data               => l_msg_data
5828 		  , p_rsv_rec                => l_rsv_rec
5829 		     , p_serial_number          => l_dummy_serial
5830 		  );
5831 
5832 	       IF (l_debug = 1) THEN
5833 		  print_debug('Returned from inv_reservation_pub.delete_reservation',4);
5834 		  print_debug('x_return_status =>'||l_return_status,4);
5835 	       END IF;
5836 
5837 	       IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
5838 		  IF (l_debug = 1) THEN
5839 		     print_debug('x_msg_data:  '||l_msg_data,4);
5840 		     print_debug('x_msg_count: '||l_msg_count,4);
5841 		     print_debug('SQLCODE:'||SQLCODE||' SQLERRM:'||SQLERRM,4);
5842 		     print_debug('Raising Exception!!!',4);
5843 		  END IF;
5844 		  l_progress := '@@@';
5845 		  RAISE fnd_api.g_exc_unexpected_error;
5846 	       END IF;
5847 
5848 	       l_backorder_delivery_detail_id := NULL;
5849 	    END IF;--IF l_backorder_delivery_detail_id is not null AND l_transaction_type = 'REJECT') THEN
5850 
5851 	    IF (l_backorder_delivery_detail_id IS NOT NULL) THEN
5852 	       -- update the txn_source_id and inspection_status,
5853 	       -- lpn_id, wms_process_flag for the new row.
5854 	       -- and wms_process_flag for the old row.
5855 
5856 	       --Update quantity with the quantity converted to the UOM in the RTI.  This is changed so
5857 	       --that the we honor the UOM entered by the user during
5858 	       --Transfer
5859 	       UPDATE mtl_txn_request_lines
5860 	         SET inspection_status = Decode(l_transaction_type,'ACCEPT',2,'REJECT',3,inspection_status)
5861 	         , lpn_id = p_transfer_lpn_id
5862 		 , quantity = Decode(uom_code
5863 				     ,p_uom_code
5864 				     ,quantity
5865 				     ,inv_rcv_cache.convert_qty(inventory_item_id
5866 								,quantity
5867 								,uom_code
5868 								,p_uom_code)
5869 				     )
5870 		 , quantity_detailed = Decode(l_transaction_type
5871 					      ,'TRANSFER'
5872 					      ,Decode(uom_code
5873 						      ,p_uom_code
5874 						      ,quantity_detailed
5875 						      ,inv_rcv_cache.convert_qty(inventory_item_id
5876 										 ,quantity_detailed
5877 										 ,uom_code
5878 										 ,p_uom_code))
5879 					      ,NULL)
5880 		 , quantity_delivered = Decode(l_transaction_type
5881 					       ,'TRANSFER'
5882 					       ,Decode(uom_code
5883 						       ,p_uom_code
5884 						       ,quantity_delivered
5885 						       ,inv_rcv_cache.convert_qty(inventory_item_id
5886 										  ,quantity_delivered
5887 										  ,uom_code
5888 										  ,p_uom_code))
5889 					       ,NULL)
5890 		 , uom_code = p_uom_code
5891                  -- OPMConvergence
5892 	         , secondary_quantity_detailed = Decode(l_transaction_type,'TRANSFER',secondary_quantity_detailed,NULL)
5893                  -- OPMConvergence
5894 	         , lot_number = p_lot_number
5895 	         , revision = p_revision
5896 	         , from_subinventory_code = Nvl(p_subinventory, from_subinventory_code)
5897 	         , from_locator_id = Nvl(p_locator_id, from_locator_id)
5898 	         , wms_process_flag = 1
5899 	         WHERE line_id = l_mo_split_tb(1).line_id;
5900             ELSE
5901 	       -- CLOSE THE SPLITTED LINE IF NOT BACKORDERED
5902 
5903 
5904 	       --???? Should we also update the primary qty here????
5905 	       --If p_mmtt_temp_id is not null then the move order line should
5906 	       --not be closed because this unnecessarily leads to
5907 	       --cancelling of operation plan. The line should be closed
5908 	       --if and only if there is a transfer mol present with the
5909 	       --same consolidation criteria. Otherwise it should be
5910 	       --updated just like the crossdock mols.
5911 
5912 	       IF (l_update_or_close = 'C') THEN
5913 		  UPDATE mtl_txn_request_lines
5914 		    SET   line_status = inv_globals.G_TO_STATUS_CLOSED
5915 		    , quantity = quantity_delivered
5916 		    , quantity_detailed = quantity_delivered
5917 		    , secondary_quantity_detailed = SECONDARY_QUANTITY_DELIVERED
5918 		    , wms_process_flag = 1
5919 		    , backorder_delivery_detail_id = l_backorder_delivery_detail_id
5920 		    , crossdock_type = Decode(l_backorder_delivery_detail_id,NULL,NULL,crossdock_type)
5921 		    WHERE line_id = l_mo_split_tb(1).line_id;
5922 		ELSE
5923 		  UPDATE mtl_txn_request_lines
5924 		    SET inspection_status = Decode(l_transaction_type,'ACCEPT',2,'REJECT',3,inspection_status)
5925 		    , lpn_id = p_transfer_lpn_id
5926 		    , quantity = Decode(uom_code
5927 					,p_uom_code
5928 					,quantity
5929 					,inv_rcv_cache.convert_qty(inventory_item_id
5930 								   ,quantity
5931 								   ,uom_code
5932 								   ,p_uom_code)
5933 					)
5934 		    , quantity_detailed = Decode(l_transaction_type
5935 						 ,'TRANSFER'
5936 						 ,Decode(uom_code
5937 							 ,p_uom_code
5938 							 ,quantity_detailed
5939 							 ,inv_rcv_cache.convert_qty(inventory_item_id
5940 										    ,quantity_detailed
5941 										    ,uom_code
5942 										    ,p_uom_code))
5943 						 ,NULL)
5944 		    , quantity_delivered = Decode(l_transaction_type
5945 						  ,'TRANSFER'
5946 						  ,Decode(uom_code
5947 							 ,p_uom_code
5948 							  ,quantity_delivered
5949 							  ,inv_rcv_cache.convert_qty(inventory_item_id
5950 										     ,quantity_delivered
5951 										     ,uom_code
5952 										     ,p_uom_code))
5953 						  ,NULL)
5954 		    , uom_code = p_uom_code
5955 		    -- OPMConvergence
5956 		    , secondary_quantity_detailed = Decode(l_transaction_type,'TRANSFER',secondary_quantity_detailed,NULL)
5957 		    -- OPMConvergence
5958 		    , lot_number = p_lot_number
5959 		    , revision = p_revision
5960 		    , from_subinventory_code = Nvl(p_subinventory, from_subinventory_code)
5961 		    , from_locator_id = Nvl(p_locator_id, from_locator_id)
5962 		    , wms_process_flag = 1
5963 		    , backorder_delivery_detail_id = l_backorder_delivery_detail_id
5964 		    , crossdock_type = Decode(l_backorder_delivery_detail_id,NULL,NULL,crossdock_type)
5965 		    WHERE line_id = l_mo_split_tb(1).line_id;
5966 	       END IF;
5967 	    END IF;--IF (l_backorder_delivery_detail_id IS NOT NULL) THEN
5968 
5969 	    /* EG. MOL has 6.  RS has 3 and 3.  You do LPN split of 4.
5970 	     * PWB will split MOL into 4 and 2, and the line with 4
5971 	     * will have wms_process_flag of 2.  maintain_mo_con will be
5972 	     * called twice, 1 for 3, the other for 1.  You do not want
5973 	     * to update the wms_process_flag MOL with 4 the first time
5974 	     * time you reach here.  You should only update it when the
5975 	     * qty being processing match the MOL qty (which will done
5976 	     * when maintain_mo_con is called with qty 1 */
5977 	       --UPDATE mtl_txn_request_lines
5978 	       --SET wms_process_flag = 1
5979 	       --WHERE line_id = l_mol_rec.line_id;
5980 
5981 	    l_remaining_primary_quantity := 0;
5982 
5983 	    IF (l_debug = 1) THEN
5984 		  print_debug('MAINTAIN_MO_CON - calling call_atf_api:'||l_mo_split_tb(1).line_id,1);
5985 		  l_progress := 'WMSINB-45116';
5986 	    END IF;
5987 
5988 	    --cancel_operation_instance should be called only if
5989 	    --p_mmtt_temp_id is NULL
5990 	    IF (p_mmtt_temp_id IS NULL) THEN
5991 	       call_atf_api(x_return_status => x_return_status,
5992 			    x_msg_data => x_msg_data,
5993 			    x_msg_count => x_msg_count,
5994 			    x_error_code => l_error_code,
5995 			    p_source_task_id => NULL,
5996 			    p_activity_type_id => 1,
5997 			    p_operation_type_id => NULL,
5998 			    p_mol_id => l_mo_split_tb(1).line_id,
5999 			    p_atf_api_name => g_atf_api_cancel);
6000 
6001 	       IF (x_return_status <> g_ret_sts_success) THEN
6002 		  IF (l_debug = 1) THEN
6003 		     print_debug('MAINTAIN_MO_CON - call_atf_api failed:'||l_mo_split_tb(1).line_id,1);
6004 		     l_progress := 'WMSINB-45118';
6005 		  END IF;
6006 		  --raise error
6007 		  l_progress := 'WMSINB-45120';
6008 		  RAISE fnd_api.g_exc_error;
6009 	       END IF;
6010 	    END IF;
6011 
6012 	 END IF; --IF  l_mol_qty_in_puom <= l_remaining_primary_quantity THEN
6013 
6014          --
6015          -- Consolidate THE LINES FOR THE TRANSFER LPN.
6016          --
6017          if l_backorder_delivery_detail_id is null
6018 	 Then
6019 
6020 	    l_progress := 'WMSINB-45122';
6021 	    -- POPULATE THE RECORD FOR TRANSFER MOL
6022 
6023 	    IF (l_debug = 1) THEN
6024 	        print_debug('MAINTAIN_MO_CON - consolidate lines l_progess =  '|| l_progress,1);
6025 	    END IF;
6026 
6027 	    --.. Moved the open and fetch call above the loop
6028 
6029 	    -- ** SET THE MOL REC QTY HERE ***
6030 	    IF l_mol_consumed_full = 1 then
6031 
6032 	       IF (l_debug = 1) THEN
6033 	           print_debug('MAINTAIN_MO_CON - Setting qty at case 1 ',1);
6034 	       END IF;
6035 
6036 	       l_mol_res_in(1).quantity               := l_mol_rec.quantity;
6037 	       l_mol_res_in(1).primary_qty            := l_mol_rec.primary_quantity;
6038 	       l_mol_res_in(1).secondary_quantity     := l_mol_rec.secondary_quantity_2; -- This is the QTY to be transacted
6039 	    ELSE
6040 	       IF (l_debug = 1) THEN
6041 	           print_debug('MAINTAIN_MO_CON - Setting qty at case 2 ',1);
6042 	       END IF;
6043 
6044 	       l_mol_res_in(1).quantity               := l_split_qty;
6045 	       l_mol_res_in(1).secondary_quantity     := l_split_sec_qty;
6046 	       l_mol_res_in(1).primary_qty            := get_primary_qty(p_org_id,p_item_id,l_mol_rec.uom_code,l_split_qty);
6047 	    END IF;
6048 
6049 	    if l_transfer_mol_rec.line_id is not null
6050 	    then
6051 	       -- Move Order Line found
6052 	       -- Check whether MOL is from the same SOURCE
6053 
6054 	       l_progress := 'WMSINB-45124';
6055 
6056 	       IF (l_debug = 1) THEN
6057 		  print_debug('MAINTAIN_MOC_CON - Move Order Line Found line Id = '|| l_transfer_mol_rec.line_id,1);
6058 	       END IF;
6059 
6060 	       check_reference(
6061 			       p_old_reference           => l_transfer_mol_rec.reference
6062 			       ,p_old_reference_type_code => l_transfer_mol_rec.reference_type_code
6063 			       ,p_old_reference_id        => l_transfer_mol_rec.reference_id
6064 			       ,p_new_reference           => l_new_reference
6065 			       ,p_new_reference_type_code => l_new_reference_type_code
6066 			       ,p_new_reference_id        => l_new_reference_id
6067 			       ,x_reference               => l_reference
6068 			       ,x_reference_type_code     => l_reference_type_code
6069 			       ,x_reference_id            => l_reference_id
6070 			       ,x_transaction_type_id     => l_transaction_type_id
6071 			       ,x_txn_source_type_id      => l_txn_source_type_id
6072 			       ,x_return_status           => x_return_status
6073 			       ,x_msg_count               => x_msg_count
6074 			       ,x_msg_data                => x_msg_data
6075 			       );
6076 
6077 
6078 	       IF (l_debug = 1) THEN
6079 		  print_debug('CHECK_REFERENCE - After calling check_reference :'||x_return_status||':'||l_progress,1);
6080 		  l_progress := 'WMSINB-45126';
6081 	       END IF;
6082 
6083 	       IF (x_return_status <> 'S') THEN
6084 		  l_progress := 'WMSINB-45127';
6085 		  RAISE fnd_api.g_exc_error;
6086 	       END IF;
6087 
6088 	       --
6089 	       -- UPDATE THE MOVE ORDER LINE HERE
6090 	       --
6091 	       IF (p_mmtt_temp_id IS NOT NULL) THEN
6092 		  UPDATE mtl_material_transactions_temp
6093 		    SET  move_order_line_id = l_transfer_mol_rec.line_id
6094 		    WHERE transaction_temp_id = p_mmtt_temp_id;
6095 
6096 		  l_qty_detailed := l_mol_res_in(1).quantity;
6097 
6098 
6099 		  IF (l_debug = 1) THEN
6100 		     print_debug('NUMBER OF MMTT UPDATED: '||SQL%rowcount,1);
6101 		  END IF;
6102 		ELSE
6103 		  l_qty_detailed := 0;
6104 	       END IF;
6105 
6106 	       update mtl_txn_request_lines
6107 		 set reference = l_reference
6108 		 ,reference_type_code = l_reference_type_code
6109 		 ,reference_id = l_reference_id
6110 		 ,quantity = quantity + l_mol_res_in(1).quantity
6111 		 ,quantity_detailed = quantity_detailed + l_qty_detailed
6112 		 ,primary_quantity = primary_quantity + l_mol_res_in(1).primary_qty
6113 		 ,secondary_quantity = secondary_quantity + l_mol_res_in(1).secondary_quantity
6114 		 ,transaction_type_id = nvl(l_transaction_type_id,transaction_type_id)
6115 		 ,transaction_source_type_id = nvl(l_txn_source_type_id,transaction_source_type_id)
6116 		 ,wms_process_flag = 1
6117 		 where line_id = l_transfer_mol_rec.line_id
6118 		 ;
6119 
6120 	       l_progress := 'WMSINB-45128';
6121 
6122 	       /* Need to modify validate_lpN_info first.  Will revisit
6123 	       call_atf_api(x_return_status => x_return_status,
6124 			    x_msg_data => x_msg_data,
6125 			    x_msg_count => x_msg_count,
6126 			    x_error_code => l_error_code,
6127 			    p_source_task_id => NULL,
6128 			    p_activity_type_id => 1,
6129 			    p_operation_type_id => NULL,
6130 			    p_mol_id => l_transfer_mol_rec.line_id,
6131 			    p_atf_api_name => g_atf_api_cancel);
6132 */
6133 	       IF (x_return_status <> g_ret_sts_success) THEN
6134 		  IF (l_debug = 1) THEN
6135 		     print_debug('MAINTAIN_MO_CON - call_atf_api failed:'||l_transfer_mol_rec.line_id,1);
6136 		     l_progress := 'WMSINB-45131';
6137 		  END IF;
6138 		  l_progress := 'WMSINB-45064';
6139 		  RAISE fnd_api.g_exc_error;
6140 	       END IF;
6141 	    END IF;  --l_transfer_mol_rec.line_id is not null
6142 
6143 	       --... The following code should be commented because
6144 	       --there was no transfer MOL, we would have updated the orig
6145 	       --mol
6146 
6147 
6148 	    -- Else
6149 	    -- Move Order Line Not Found Create Move Order
6150 	    --     IF (l_debug = 1) THEN
6151 	    --print_debug('MAINTAIN_MOC_CON - Move Order Line Not Found line Id ',1);
6152 	    --		     END IF;
6153 
6154 	    --create mol
6155 	    --	     inv_rcv_std_rcpt_apis.create_move_order(p_move_order_header_id => l_move_order_header_id
6156 	    --					     ,p_po_line_location_id      => p_po_line_location_id
6157 	    --				     ,p_po_distribution_id       => p_po_distribution_id
6158 	    --			     ,p_shipment_line_id         => p_shipment_line_id
6159 	    --		     ,p_oe_order_line_id         => p_oe_order_line_id
6160 	    --	     ,p_routing                  => p_routing_header_id
6161 	    --     ,p_lot_control_code         => p_lot_control_code
6162 	    --   ,p_org_id                   => l_mol_res_in(1).organization_id
6163 	    -- ,p_item_id                  => l_mol_res_in(1).inventory_item_id
6164 	    --							     ,p_qty                      => l_mol_res_in(1).quantity
6165 	    --						     ,p_uom_code                 => l_mol_res_in(1).uom_code
6166 	    --					     ,p_lpn                      => l_mol_res_in(1).lpn_id
6167 	    --				     ,p_project_id               => l_mol_res_in(1).project_id
6168 	    --			     ,p_task_id                  => l_mol_res_in(1).task_id
6169 	    --		     ,p_revision                 => l_mol_res_in(1).item_revision
6170 	    --		       ,p_inspect                  => l_mol_res_in(1).inspection_status
6171 	    ---	       ,p_txn_source_id            => null
6172 	    --       ,x_status                   => x_return_status
6173 	    --     ,x_message                  => x_msg_data
6174 	    --   ,p_transfer_org_id          => l_mol_res_in(1).transfer_org_id
6175 	    -- ,p_wms_process_flag         => 1
6176 	    --		       ,p_lot_number               => l_mol_res_in(1).lot_number
6177 	    --	       ,p_secondary_quantity       => l_mol_res_in(1).secondary_quantity
6178 	    --       ,p_secondary_uom            => l_mol_res_in(1).secondary_uom
6179 	    --     ,x_line_id                  => l_move_order_line_id
6180 	    --   );
6181 
6182 	    --		     IF (l_debug = 1) THEN
6183 	    --print_debug('MAINTAIN_MO_CON - After calling create_move_order:'||x_return_status||':'||l_progress,1);
6184 	    --print_debug('MAINTAIN_MO_CON - Move Order Header ID:'||l_move_order_header_id||':'||l_progress,1);
6185 	    --	     END IF;
6186 	    --
6187 	    --   IF (x_return_status <> 'S') THEN
6188 	    --l_progress := 'WMSINB-45070';
6189 	    --			RAISE fnd_api.g_exc_error;
6190 	    --	     END IF;
6191 	    --
6192 	    --   --update mol for the sub and loc
6193 	    -- UPDATE mtl_txn_request_lines
6194 	    -- SET from_subinventory_code = Nvl(p_subinventory,from_subinventory_code)
6195 	    --		       , from_locator_id = Nvl(p_locator_id, from_locator_id)
6196 	    --	       WHERE header_id = l_move_order_header_id
6197 	    --             and organization_id = p_org_id
6198 	    --       AND inventory_item_id = p_item_id;
6199 
6200 	 End if; -- l_backorder_delivery_detail_id is null
6201 
6202 	 IF l_remaining_primary_quantity <= 0 THEN
6203 	       EXIT;
6204 	 END IF;
6205       END LOOP;
6206 
6207       IF c_mol_mmtt%isopen THEN
6208 	 CLOSE c_mol_mmtt;
6209       END IF;
6210 
6211       IF c_mol_no_mmtt%isopen THEN
6212 	 CLOSE c_mol_no_mmtt;
6213       END IF;
6214 
6215       IF (l_debug = 1) THEN
6216 	 print_debug('MAINTAIN_MO - l_remaining_primary_quantity:'||l_remaining_primary_quantity,1);
6217       END IF;
6218 
6219       IF (Round(l_remaining_primary_quantity,5) > 0) THEN
6220 	 IF (l_debug = 1) THEN
6221 	    print_debug('MAINTAIN_MO - QTY STILL REMAINING !!!'||l_remaining_primary_quantity||':'||l_progress,1);
6222 	    l_progress := 'WMSINB-13244';
6223 	 END IF;
6224 	 --raise error
6225 	 l_progress := 'WMSINB-13247';
6226 	 RAISE fnd_api.g_exc_error;
6227       END IF;
6228 
6229       --update capacity and empty flag for locators
6230       IF (Nvl(p_locator_id, Nvl(l_from_loc_id, -1)) <> Nvl(l_from_loc_id, -1)) THEN
6231 	 --call upd_empty_mixed_flag
6232 	 IF p_locator_id IS NOT NULL THEN
6233 	    IF (l_debug = 1) THEN
6234 	       print_debug('MAINTAIN_MO - Calling upd_empty_mixed_flag for	CURRENT sub',1);
6235 	    END IF;
6236 
6237 	    inv_loc_wms_utils.upd_empty_mixed_flag_rcv_loc ( x_return_status  => x_return_status
6238 							     ,x_msg_count    => x_msg_count
6239 							     ,x_msg_data     => x_msg_data
6240 							     ,p_subinventory => p_subinventory
6241 							     ,p_locator_id   => p_locator_id
6242 							     ,p_org_id       => p_org_id
6243 							     );
6244 	    IF (x_return_status <> 'S') THEN
6245 	       l_progress := 'WMSINB-13250';
6246 	       -- Bug 5393727: do not raise an exception if locator API returns an error
6247 	       -- RAISE fnd_api.g_exc_error;
6248 	    END IF;
6249 
6250 	    -- update curr capacity
6251 	    IF (l_debug = 1) THEN
6252 	       print_debug('MAINTAIN_MO - Calling update_loc_curr_capacity_nauto FOR CURRENT sub',1);
6253 	    END IF;
6254 
6255 	    inv_loc_wms_utils.update_loc_curr_capacity_nauto
6256 	      ( x_return_status           => x_return_status
6257 		,x_msg_count               => x_msg_count
6258 		,x_msg_data                => x_msg_data
6259 		,p_organization_id         => p_org_id
6260 		,p_inventory_location_id   => p_locator_id
6261 		,p_inventory_item_id       => p_item_id
6262 		,p_primary_uom_flag        => 'N'
6263 		,p_transaction_uom_code    => p_uom_code
6264 		,p_quantity                => p_qty
6265 		,p_issue_flag              => 'N'
6266 		);
6267 	    IF (x_return_status <> 'S') THEN
6268 	       l_progress := 'WMSINB-13252';
6269 	       -- Bug 5393727: do not raise an exception if locator API returns an error
6270 	       -- RAISE fnd_api.g_exc_error;
6271 	    END IF;
6272 	 END IF; --IF p_subinventory IS NOT NULL THEN
6273 
6274 	 IF l_from_loc_id IS NOT NULL THEN
6275 	    IF (l_debug = 1) THEN
6276 	       print_debug('MAINTAIN_MO - Calling upd_empty_mixed_flag for FROM sub',1);
6277 	    END IF;
6278 
6279 	    inv_loc_wms_utils.upd_empty_mixed_flag_rcv_loc ( x_return_status  => x_return_status
6280 							     ,x_msg_count    => x_msg_count
6281 							     ,x_msg_data     => x_msg_data
6282 							     ,p_subinventory => l_from_sub
6283 							     ,p_locator_id   => l_from_loc_id
6284 							     ,p_org_id       => p_org_id
6285 							     );
6286 	    IF (x_return_status <> 'S') THEN
6287 	       l_progress := 'WMSINB-13255';
6288 	       -- Bug 5393727: do not raise an exception if locator API returns an error
6289 	       -- RAISE fnd_api.g_exc_error;
6290 	    END IF;
6291 
6292 	    -- update curr capacity
6293 	    IF (l_debug = 1) THEN
6294 	       print_debug('MAINTAIN_MO - Calling update_loc_curr_capacity_nauto FOR FROM sub',1);
6295 	    END IF;
6296 
6297 	    inv_loc_wms_utils.update_loc_curr_capacity_nauto
6298 	      ( x_return_status           => x_return_status
6299 		,x_msg_count               => x_msg_count
6300 		,x_msg_data                => x_msg_data
6301 		,p_organization_id         => p_org_id
6302 		,p_inventory_location_id   => l_from_loc_id
6303 		,p_inventory_item_id       => p_item_id
6304 		,p_primary_uom_flag        => 'N'
6305 		,p_transaction_uom_code    => p_uom_code
6306 		,p_quantity                => p_qty
6307 		,p_issue_flag              => 'Y'
6308 		);
6309 	    IF (x_return_status <> 'S') THEN
6310 	       l_progress := 'WMSINB-13257';
6311 	       -- Bug 5393727: do not raise an exception if locator API returns an error
6312 	       -- RAISE fnd_api.g_exc_error;
6313 	    END IF;
6314 	 END IF; --IF l_from_sub IS NOT NULL THEN
6315       END IF; --IF (Nvl(p_locator_id, Nvl(l_from_loc_id, -1)) <> Nvl(l_from_loc_id, -1)) THEN
6316 
6317     END IF;--  IF l_update_or_close = 'N' THEN
6318 
6319 --Call pregeneration again for accept/reject transactions
6320 -- ... move the pregeneration call to complete lpn group.
6321 --      IF l_transaction_type IN ('ACCEPT', 'REJECT') THEN
6322 --	 l_call_pregeneration := TRUE;
6323 
6324 -- R12 Commented the call to pregeneration
6325 -- As this has been moved to complete_lpn_group
6326 --
6327 --	 IF (p_transfer_lpn_id IS NULL) THEN
6328 --	    l_call_pregeneration := FALSE;
6329 --	  ELSE
6330 --	    IF p_lot_control_code > 1 THEN
6331 --	       IF p_lot_number IS NULL THEN
6332 --		  l_call_pregeneration := FALSE;
6333 --	       END IF;
6334 --	     ELSIF p_serial_number_control_code IN (2,5,6) THEN
6335 --	       BEGIN
6336 --		  SELECT '1'
6337 --		    INTO l_dummy
6338 --		    FROM mtl_serial_numbers_temp
6339 --		    WHERE product_code = 'RCV'
6340 --		    AND product_transaction_id = p_rti_id
6341 --		    AND ROWNUM < 2;
6342 --	       EXCEPTION
6343 --		  WHEN OTHERS THEN
6344 --		     l_call_pregeneration := FALSE;
6345 --	       END;
6346 --	    END IF;
6347 --	 END IF; --IF (p_lpn_id IS NULL) THEN
6348 
6349 	 --call pregeneration
6350 --	 IF l_call_pregeneration THEN
6351 --	    IF (l_debug = 1) THEN
6352 --	       print_debug('MAINTAIN_MO - Before calling start_pregenerate_program:'||l_progress,1);
6353 --	       l_progress := 'WMSINB-13260';
6354 --	    END IF;
6355 --	    wms_putaway_suggestions.start_pregenerate_program
6356 --	      (p_org_id => p_org_id,
6357 --	       p_lpn_id => p_transfer_lpn_id,
6358 --	       x_return_status => x_return_status,
6359 --	       x_msg_count => x_msg_count,
6360 --	       x_msg_data => x_msg_data);
6361 --
6362 --	    IF (l_debug = 1) THEN
6363 --	       print_debug('MAINTAIN_MO - After calling start_pregenerate_program:'||x_return_status||':'||l_progress,1);
6364 --	       l_progress := 'WMSINB-13262';
6365 --	    END IF;
6366 --
6367 --	    IF (x_return_status <> 'S') THEN
6368 --	       x_return_status := 'S';
6369 --	    END IF;
6370 --	 END IF; --IF l_call_pregeneration THEN
6371 
6372 --      END IF; --IF l_transaction_type IN ('ACCEPT','REJECT') THEN
6373 
6374    END IF; --IF l_transaction_type IN ('ACCEPT','REJECT','TRANSFER') THEN
6375 
6376 
6377    IF (l_transaction_type = 'DELIVER' OR
6378        (l_transaction_type = 'CORRECT' AND
6379 	p_primary_quantity > 0 AND
6380 	l_parent_txn_type = 'DELIVER')) THEN
6381       IF (p_mmtt_temp_id IS NOT NULL) THEN
6382          OPEN c_mol_mmtt(p_mmtt_temp_id,
6383                          p_item_id,
6384                          p_lpn_id,
6385                          p_lot_number,
6386                          p_revision,
6387                          p_from_subinventory,
6388                          p_from_locator_id,
6389                          p_project_id,
6390                          p_task_id,
6391                          l_from_mol_inspection_status
6392                         );
6393        ELSE
6394 	 OPEN c_mol_no_mmtt(p_item_id,
6395                             p_lpn_id,
6396 			    p_lot_number,
6397                             p_revision,
6398                             p_from_subinventory,
6399                             p_from_locator_id,
6400                             p_project_id ,
6401                             p_task_id ,
6402                             l_from_mol_inspection_status,
6403                             p_uom_code
6404                           );
6405       END IF;
6406 
6407       l_remaining_primary_quantity := p_primary_quantity;
6408 
6409       -- OPMConvergence
6410       l_remaining_secondary_quantity := p_sec_qty;
6411       -- OPMConvergence
6412 
6413       LOOP
6414 	 IF (p_mmtt_temp_id IS NOT NULL) THEN
6415 	    FETCH c_mol_mmtt INTO l_mol_rec;
6416 	    EXIT WHEN c_mol_mmtt%notfound;
6417 	  ELSE
6418 	       FETCH c_mol_no_mmtt INTO l_mol_rec;
6419 	       EXIT WHEN c_mol_no_mmtt%notfound;
6420 	 END IF;
6421 
6422 	 IF (l_debug = 1) THEN
6423 	    print_debug('MAINTAIN_MO - REMAINING QUANTITY:'||l_remaining_primary_quantity||':'||l_progress,1);
6424 	    l_progress := 'WMSINB-13273';
6425 	 END IF;
6426 
6427 	 --BUG 4766810: Always add before rounding.  Also, when comparing
6428 	 -- for equality, check if the two number differs by 0.000005
6429 	 -- (round to 5 digits).
6430 	 IF (l_mol_rec.uom_code <> p_primary_uom_code) THEN
6431 	    l_conversion_rate := inv_rcv_cache.get_conversion_rate(l_mol_rec.inventory_item_id,
6432 								   l_mol_rec.uom_code,
6433 								   p_primary_uom_code);
6434 	    l_mol_qty_in_puom := l_mol_rec.quantity * l_conversion_rate;
6435 	  ELSE
6436 	    l_mol_qty_in_puom := l_mol_rec.quantity;
6437 	    l_conversion_rate := 1;
6438 	 END IF;
6439 
6440 	 l_quantity_delivered := inv_rcv_cache.convert_qty(p_inventory_item_id => l_mol_rec.inventory_item_id
6441 					     ,p_from_qty         => l_remaining_primary_quantity
6442 					     ,p_from_uom_code    => p_primary_uom_code
6443 					     ,p_to_uom_code      => l_mol_rec.uom_code);
6444 
6445          -- OPMConvergence
6446 
6447          IF l_mol_rec.secondary_uom_code <> p_sec_uom THEN
6448 
6449             l_sec_quantity_delivered := inv_rcv_cache.convert_qty(p_inventory_item_id => l_mol_rec.inventory_item_id
6450 						    ,p_from_qty         => l_remaining_primary_quantity
6451 						    ,p_from_uom_code    => p_sec_uom
6452 						    ,p_to_uom_code      => l_mol_rec.secondary_uom_code);
6453          ELSE
6454 
6455            l_sec_quantity_delivered := l_remaining_secondary_quantity;
6456 
6457          END IF;
6458 
6459          -- OPMConvergence
6460 
6461 	 IF (l_debug = 1) THEN
6462 	    print_debug('MAINTAIN_MO_CON - MOL QTY IN PUOM:'||l_mol_qty_in_puom||':'||l_progress,1);
6463 	    print_debug('MAINTAIN_MO_CON - QUANTITY DELIVERED:'||l_quantity_delivered||':'||l_progress,1);
6464             -- OPMConvergence
6465 	    print_debug(l_proc_name||' SEC QUANTITY DELIVERED:'||l_sec_quantity_delivered||':'||l_progress,1);
6466             -- OPMConvergence
6467 	    l_progress := 'WMSINB-13295';
6468 	 END IF;
6469 
6470 	 IF (p_mmtt_temp_id IS NULL AND l_mol_rec.transaction_temp_id IS NOT NULL) THEN
6471 	    IF (l_debug = 1) THEN
6472 	       print_debug('MAINTAIN_MO - calling call_atf_api:'||l_mol_rec.line_id,1);
6473 	       l_progress := 'WMSINB-13305';
6474 	    END IF;
6475 
6476 	    call_atf_api(x_return_status => x_return_status,
6477 			 x_msg_data => x_msg_data,
6478 			 x_msg_count => x_msg_count,
6479 			 x_error_code => l_error_code,
6480 			 p_source_task_id => NULL,
6481 			 p_activity_type_id => 1,
6482 			 p_operation_type_id => NULL,
6483 			 p_mol_id => l_mol_rec.line_id,
6484 			 p_atf_api_name => g_atf_api_cancel);
6485 	 END IF;
6486 
6487 	 --BUG 4766810, always round to 5 digits when comparing because
6488 	 --quantity is stored in 5 digits in Inventory
6489 	 IF (Round(l_remaining_primary_quantity,5) < Round(l_mol_qty_in_puom,5)) THEN
6490 	    IF (l_debug = 1) THEN
6491 	       print_debug('MAINTAIN_MO_CON - Updating MOL:'||l_mol_rec.line_id||':'||l_progress,1);
6492 	       l_progress := 'WMSINB-13301';
6493 	    END IF;
6494 
6495 	    l_mo_split_tb(1).prim_qty := l_remaining_primary_quantity;
6496             -- OPMConvergence
6497             -- Do we need to assign secondary quantity too ?
6498             -- OPMConvergence
6499 	    l_mo_split_tb(1).line_id := NULL;
6500 
6501 	    IF p_mmtt_temp_id IS NOT NULL THEN
6502 	       -- Call split mo with operation_type DELIVER
6503 	       -- This will split the MO and tied the mmtt
6504 	       -- to the new MO
6505 	       inv_rcv_integration_apis.split_mo
6506 		 (p_orig_mol_id => l_mol_rec.line_id,
6507 		  p_mo_splt_tb => l_mo_split_tb,
6508 		  p_operation_type => 'DELIVER',
6509 		  p_txn_header_id => p_mmtt_temp_id,
6510 		  x_return_status => x_return_status,
6511 		  x_msg_count => x_msg_count,
6512 		  x_msg_data => x_msg_data);
6513 	     ELSE
6514 	       inv_rcv_integration_apis.split_mo
6515 		 (p_orig_mol_id => l_mol_rec.line_id,
6516 		  p_mo_splt_tb => l_mo_split_tb,
6517 		  x_return_status => x_return_status,
6518 		  x_msg_count => x_msg_count,
6519 		  x_msg_data => x_msg_data);
6520 	    END IF;
6521 
6522 	    --Call Reservations
6523             --R12
6524 	    /* Bug 5627083.
6525 	     * We need to pass in the transfer_lpn_id to update the reservation record.
6526 	    */
6527             l_mol_res_in(1).transaction_type       := l_transaction_type;
6528             l_mol_res_in(1).organization_id        := p_org_id;
6529             l_mol_res_in(1).lpn_id                 := p_transfer_lpn_id;
6530             l_mol_res_in(1).inventory_item_id      := p_item_id;
6531 	    l_mol_res_in(1).lot_number             := p_lot_number;
6532             l_mol_res_in(1).item_revision          := p_revision;
6533             l_mol_res_in(1).project_id             := p_project_id;
6534             l_mol_res_in(1).task_id                := p_task_id;
6535             l_mol_res_in(1).uom_code               := NULL;
6536             l_mol_res_in(1).quantity               := 0;
6537             l_mol_res_in(1).backorder_delivery_detail_id := l_mo_split_tb(1).wdd_id;--New field in l_mo_split_tb
6538             l_mol_res_in(1).crossdock_type         := NULL;
6539             l_mol_res_in(1).secondary_quantity     := 0;
6540             l_mol_res_in(1).secondary_uom          := NULL;
6541             l_mol_res_in(1).line_id                := l_mo_split_tb(1).line_id;
6542             l_mol_res_in(1).primary_qty            := l_remaining_primary_quantity;
6543             l_mol_res_in(1).primary_uom_code       := p_primary_uom_code;
6544             l_mol_res_in(1).primary_qty            := l_remaining_primary_quantity;
6545             l_mol_res_in(1).wip_supply_type        := l_mol_rec.wip_supply_type;
6546             l_mol_res_in(1).crossdock_type         := l_mol_rec.crossdock_type;
6547             l_mol_res_in(1).inspection_status      := l_from_mol_inspection_status;
6548 	    l_mol_res_in(1).subinventory_code      := p_subinventory;
6549 	    l_mol_res_in(1).locator_id             := p_locator_id;
6550 	    l_mol_res_in(1).parent_txn_type        := l_parent_txn_type;
6551 
6552 	    INV_RCV_RESERVATION_UTIL.maintain_reservations
6553 	      (x_return_status => x_return_status
6554 	       ,x_msg_count     => x_msg_count
6555 	       ,x_msg_data      => x_msg_data
6556 	       ,x_mol_tb        => l_mol_res_out
6557 	       ,p_cas_mol_tb    => l_mol_res_in
6558 	       );
6559 
6560 	    IF (l_debug = 1) THEN
6561 	       print_debug(' maintain_reservations - After calling maintain_reservations :'||x_return_status||':'||l_progress,1);
6562 	       l_progress := 'WMSINB-45051';
6563 	    END IF;
6564 
6565 	    IF (x_return_status <> 'S') THEN
6566 	       l_progress := 'WMSINB-45052';
6567 	       RAISE fnd_api.g_exc_error;
6568 	    END IF;
6569 
6570 	    l_progress := 'WMSINB-45053';
6571 
6572 
6573 	    --Close line
6574 	    UPDATE mtl_txn_request_lines
6575 	      SET quantity_delivered = Decode(p_mmtt_temp_id,NULL,
6576 					      Nvl(quantity_delivered,0)+l_quantity_delivered,quantity_delivered)
6577 	      ,secondary_quantity_delivered = Decode(p_mmtt_temp_id,NULL,
6578 						     Nvl(secondary_quantity_delivered,0)+l_sec_quantity_delivered,quantity_delivered)
6579 	      , line_status = Decode(p_mmtt_temp_id,NULL,
6580 				     Decode((Nvl(quantity_delivered,0)+l_quantity_delivered),quantity,
6581 					    inv_globals.G_TO_STATUS_CLOSED,line_status),line_status)
6582 	      , wms_process_flag = 1
6583 	      WHERE line_id = l_mo_split_tb(1).line_id;
6584 
6585 	    -- R12
6586 
6587 	    l_remaining_primary_quantity := 0;
6588 
6589             -- OPMConvergence
6590 	    l_remaining_secondary_quantity := 0;
6591             -- OPMConvergence
6592 
6593 	  ELSE --IF (l_remaining_primary_quantity < l_mol_qty_in_puom) THEN
6594 
6595             -- R12
6596 
6597 	    /* Bug 5627083.
6598 	     * We need to pass in the transfer_lpn_id to update the reservation record.
6599 	    */
6600             l_mol_res_in(1).transaction_type       := l_transaction_type;
6601             l_mol_res_in(1).organization_id        := p_org_id;
6602             l_mol_res_in(1).lpn_id                 := p_transfer_lpn_id;
6603             l_mol_res_in(1).inventory_item_id      := p_item_id;
6604 	    l_mol_res_in(1).lot_number             := p_lot_number;
6605 	    l_mol_res_in(1).item_revision          := p_revision;
6606             l_mol_res_in(1).project_id             := p_project_id;
6607             l_mol_res_in(1).task_id                := p_task_id;
6608             l_mol_res_in(1).uom_code               := null;
6609             l_mol_res_in(1).quantity               := 0;
6610             l_mol_res_in(1).backorder_delivery_detail_id := l_mol_rec.backorder_delivery_detail_id;
6611             l_mol_res_in(1).secondary_quantity     := 0;
6612             l_mol_res_in(1).secondary_uom          := null;
6613             l_mol_res_in(1).line_id                := l_mol_rec.line_id;
6614             l_mol_res_in(1).primary_qty            := l_mol_qty_in_puom;
6615             l_mol_res_in(1).primary_uom_code       := p_primary_uom_code;
6616             l_mol_res_in(1).primary_qty            := l_remaining_primary_quantity;
6617             l_mol_res_in(1).inspection_status      := l_from_mol_inspection_status;
6618 
6619             -- Added the below two line also
6620             l_mol_res_in(1).wip_supply_type        := l_mol_rec.wip_supply_type;
6621             l_mol_res_in(1).crossdock_type         := l_mol_rec.crossdock_type;
6622 
6623 	    l_mol_res_in(1).subinventory_code      := p_subinventory;
6624 	    l_mol_res_in(1).locator_id             := p_locator_id;
6625 	    l_mol_res_in(1).parent_txn_type        := l_parent_txn_type;
6626 
6627 	    INV_RCV_RESERVATION_UTIL.maintain_reservations
6628 	      (x_return_status => x_return_status
6629 	       ,x_msg_count     => x_msg_count
6630 	       ,x_msg_data      => x_msg_data
6631 	       ,x_mol_tb        => l_mol_res_out
6632 	       ,p_cas_mol_tb    => l_mol_res_in
6633 	       );
6634 
6635 	    IF (l_debug = 1) THEN
6636 	       print_debug(' maintain_reservations - After calling maintain_reservations :'||x_return_status||':'||l_progress,1);
6637 	       l_progress := 'WMSINB-45051';
6638 	    END IF;
6639 
6640 	    IF (x_return_status <> 'S') THEN
6641 	       l_progress := 'WMSINB-45052';
6642 	       RAISE fnd_api.g_exc_error;
6643 	    END IF;
6644 
6645 	    l_progress := 'WMSINB-45053';
6646 
6647 	    UPDATE mtl_txn_request_lines
6648 	      SET quantity_delivered = Decode(p_mmtt_temp_id,NULL,quantity,quantity_delivered)
6649               -- OPMConvergence
6650 	      , secondary_quantity_delivered = Decode(p_mmtt_temp_id,NULL,secondary_quantity,secondary_quantity_delivered)
6651               -- OPMConvergence
6652 	      , line_status = Decode(p_mmtt_temp_id,NULL,inv_globals.g_to_status_closed,line_status)
6653 	      , wms_process_flag = 1
6654 	      WHERE line_id = l_mol_rec.line_id;
6655 
6656             -- OPMConvergence
6657             l_remaining_secondary_quantity := (l_remaining_primary_quantity - l_mol_qty_in_puom )*
6658                                               (l_remaining_secondary_quantity / l_remaining_primary_quantity );
6659 
6660             -- OPMConvergence
6661 	    l_remaining_primary_quantity := l_remaining_primary_quantity - l_mol_qty_in_puom;
6662 
6663 	    -- Bug 5632202 : Set l_remaining_primary_quantity to zero if it differs from MOL
6664 	    --               quantity in sixth decimal place
6665 	    IF trunc(( l_remaining_primary_quantity/ l_conversion_rate ),5) = 0 THEN
6666 	      l_remaining_primary_quantity := 0;
6667 	      l_remaining_secondary_quantity := 0;
6668 	      IF (l_debug = 1) THEN
6669 		print_debug('MAINTAIN_MO_CON - Setting l_remaining_primary_quantity to zero',1);
6670 	      END IF;
6671 	    END IF;
6672 
6673 	 END IF; --IF (l_remaining_primary_quantity <= l_mol_qty_in_puom) THEN
6674 
6675 	 IF (l_debug = 1) THEN
6676 	    print_debug('MAINTAIN_MO_CON - l_remaining_primary_quantity:'||l_remaining_primary_quantity,1);
6677 	 END IF;
6678 
6679 	 IF (Round(l_remaining_primary_quantity,5) <= 0) THEN
6680 	    EXIT;
6681 	 END IF;
6682 
6683       END LOOP;
6684 
6685       IF c_mol_mmtt%isopen THEN
6686 	 CLOSE c_mol_mmtt;
6687       END IF;
6688 
6689       IF c_mol_no_mmtt%isopen THEN
6690 	 CLOSE c_mol_no_mmtt;
6691       END IF;
6692 
6693       IF (Round(l_remaining_primary_quantity,5) > 0) THEN
6694 	 IF (l_debug = 1) THEN
6695 	    print_debug('MAINTAIN_MO_CON - QTY STILL REMAINING *** HOW ???:'||l_remaining_primary_quantity||':'||l_progress,1);
6696 	    l_progress := 'WMSINB-13342';
6697 	 END IF;
6698 	 --raise error
6699 	 l_progress := 'WMSINB-13345';
6700 	 RAISE fnd_api.g_exc_error;
6701       END IF;
6702 
6703       --call upd_empty_mixed_flag
6704       IF l_from_loc_id IS NOT NULL THEN
6705 	 IF (l_debug = 1) THEN
6706 	    print_debug('MAINTAIN_MO_CON - Calling upd_empty_mixed_flag for	FROM sub',1);
6707 	 END IF;
6708 
6709 	 inv_loc_wms_utils.upd_empty_mixed_flag_rcv_loc ( x_return_status  => x_return_status
6710 							  ,x_msg_count    => x_msg_count
6711 							  ,x_msg_data     => x_msg_data
6712 							  ,p_subinventory => l_from_sub
6713 							  ,p_locator_id   => l_from_loc_id
6714 							  ,p_org_id       => p_org_id
6715 							  );
6716 	 IF (x_return_status <> 'S') THEN
6717 	    l_progress := 'WMSINB-13350';
6718 	    -- Bug 5393727: do not raise an exception if locator API returns an error
6719 	    -- RAISE fnd_api.g_exc_error;
6720 	 END IF;
6721 
6722 	 -- update curr capacity
6723 	 IF (l_debug = 1) THEN
6724 	    print_debug('MAINTAIN_MO_CON - Calling update_loc_curr_capacity_nauto FOR FROM sub',1);
6725 	 END IF;
6726 
6727 	 inv_loc_wms_utils.update_loc_curr_capacity_nauto
6728 	   ( x_return_status           => x_return_status
6729 	     ,x_msg_count               => x_msg_count
6730 	     ,x_msg_data                => x_msg_data
6731 	     ,p_organization_id         => p_org_id
6732 	     ,p_inventory_location_id   => l_from_loc_id
6733 	     ,p_inventory_item_id       => p_item_id
6734 	     ,p_primary_uom_flag        => 'N'
6735 	     ,p_transaction_uom_code    => p_uom_code
6736 	     ,p_quantity                => p_qty
6737 	     ,p_issue_flag              => 'Y'
6738 	     );
6739 	 IF (x_return_status <> 'S') THEN
6740 	    l_progress := 'WMSINB-13357';
6741 	    -- Bug 5393727: do not raise an exception if locator API returns an error
6742 	    -- RAISE fnd_api.g_exc_error;
6743 	 END IF;
6744       END IF; --IF l_from_sub IS NOT NULL THEN
6745 
6746       IF (l_transaction_type = 'CORRECT') THEN
6747 	 --We need to update the wms_process_flag on mol for all the lines for the given lpn as
6748 	 --we update all the mols for the given lpn to 2 in mark_returns
6749 	 UPDATE mtl_txn_request_lines
6750 	   SET wms_process_flag = 1
6751 	   WHERE (lpn_id = p_lpn_id
6752 		  OR lpn_id = p_transfer_lpn_id);
6753       END IF;
6754    END IF; --IF (l_transaction_type = 'DELIVER') THEN
6755 
6756 
6757    IF (l_transaction_type IN ('CORRECT','RETURN TO VENDOR',
6758 			      'RETURN TO CUSTOMER','RETURN TO RECEIVING')
6759        --Treat + Corr of Deliver as DELIVER above
6760        AND (NOT (l_transaction_type = 'CORRECT'
6761 		 AND p_primary_quantity > 0
6762 		 AND l_parent_txn_type = 'DELIVER'))
6763        --Treat + Corr of Receive as RECEIVE above
6764        AND (NOT (l_transaction_type = 'CORRECT'
6765 		 AND p_primary_quantity > 0
6766 		 AND l_parent_txn_type = 'RECEIVE'))
6767        ) THEN
6768 
6769       IF (l_debug = 1) THEN
6770 	 print_debug('MAINTAIN_MO_CON - Case of Return/Correct',1);
6771       END IF;
6772 
6773       /* Bug 6830559 */
6774       IF (p_project_id IS NULL) THEN
6775 	 IF (p_po_distribution_id IS NOT NULL) THEN
6776 	    BEGIN
6777 	       SELECT project_id,
6778 		 Nvl(task_id, '')  -- Bug 7355205
6779 		 INTO l_project_id,
6780 		 l_task_id
6781 		 FROM po_distributions_all
6782 		 WHERE po_distribution_id = p_po_distribution_id;
6783 	    EXCEPTION
6784 	       WHEN no_data_found THEN
6785 		  l_project_id := NULL;
6786 		  l_task_id := NULL;
6787 	    END ;
6788          ELSIF (p_po_line_location_id IS NOT NULL) then
6789             inv_rcv_std_rcpt_apis.get_project_task(
6790                  p_po_line_location_id     => p_po_line_location_id
6791                , p_oe_order_line_id        => NULL
6792                , x_project_id              => l_project_id
6793                , x_task_id                 => l_task_id
6794             );
6795 	 END IF;
6796       ELSE --IF (p_project_id IS NULL) THEN
6797 		  l_project_id := p_project_id;
6798 		  l_task_id := p_task_id;
6799       END IF; --IF (p_project_id IS NULL) THEN
6800 
6801       -- PUT THE VALUES IN THE STRUCTURE HERE
6802       l_mol_res_in(1).transaction_type       := l_transaction_type;
6803       l_mol_res_in(1).organization_id        := p_org_id;
6804       l_mol_res_in(1).inventory_item_id      := p_item_id;
6805       l_mol_res_in(1).lot_number             := p_lot_number;
6806       l_mol_res_in(1).item_revision          := p_revision;
6807 
6808       -- l_mol_res_in(1).cost_group_id          := null; ????
6809 
6810       l_mol_res_in(1).project_id             := l_project_id;
6811       l_mol_res_in(1).task_id                := l_task_id;
6812       l_mol_res_in(1).uom_code               := p_uom_code;
6813       l_mol_res_in(1).quantity               := p_qty;
6814       l_mol_res_in(1).backorder_delivery_detail_id := null;
6815       l_mol_res_in(1).crossdock_type         := null;
6816       l_mol_res_in(1).transfer_org_id        := l_transfer_org_id;
6817       l_mol_res_in(1).secondary_quantity     := p_sec_qty;
6818       l_mol_res_in(1).secondary_uom          := p_sec_uom;
6819 
6820       l_mol_res_in(1).inspection_status      := l_from_mol_inspection_status ;
6821       l_mol_res_in(1).line_id                := null;
6822 
6823       l_mol_res_in(1).primary_uom_code       := p_primary_uom_code;
6824       l_mol_res_in(1).primary_qty            := p_primary_quantity;
6825       l_mol_res_in(1).po_header_id           := l_po_header_id;
6826       l_mol_res_in(1).po_line_location_id    := p_po_line_location_id;
6827       l_mol_res_in(1).shipment_line_id       := p_shipment_line_id;
6828       l_mol_res_in(1).requisition_line_id    := l_requisition_line_id;
6829       l_mol_res_in(1).auto_transact_code     := p_auto_transact_code;
6830       l_mol_res_in(1).wip_supply_type        := null;
6831       l_mol_res_in(1).routing_header_id      := p_routing_header_id;
6832       l_mol_res_in(1).source_document_code   := l_source_document_code;
6833       l_mol_res_in(1).parent_transaction_id  := l_transaction_id;
6834       l_mol_res_in(1).parent_txn_type        := l_parent_txn_type;
6835       l_mol_res_in(1).grand_parent_txn_type  := l_grand_parent_txn_type;
6836       l_mol_res_in(1).asn_line_flag          := p_asn_line_flag;
6837 
6838 
6839       IF ((l_transaction_type = 'CORRECT'
6840 	   AND ((p_primary_quantity < 0 AND l_parent_txn_type IN ('RECEIVE','ACCEPT','REJECT','TRANSFER','RETURN TO RECEIVING'))
6841 		OR (p_primary_quantity > 0 AND ((l_parent_txn_type IN ('ACCEPT','REJECT','TRANSFER','DELIVER'))
6842 						OR (l_parent_txn_type IN ('RETURN TO VENDOR','RETURN TO CUSTOMER')
6843 						    AND l_grand_parent_txn_type <> 'DELIVER')))))
6844 	  OR (l_transaction_type IN ('RETURN TO VENDOR','RETURN TO CUSTOMER') AND l_parent_txn_type <> 'DELIVER')) THEN
6845 
6846          IF (l_debug = 1) THEN
6847                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 1',1);
6848          END IF;
6849 
6850 	 IF (l_parent_txn_type = 'RETURN TO RECEIVING') THEN
6851 
6852             IF (l_debug = 1) THEN
6853                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 2',1);
6854             END IF;
6855 
6856             l_mol_res_in(1).lpn_id          := p_lpn_id;
6857             -- FROM SUB
6858             l_mol_res_in(1).from_subinventory_code := p_from_subinventory;
6859             l_mol_res_in(1).from_locator_id        := p_from_locator_id;
6860             -- DEST SUB/LOC
6861             --l_transfer_sub        := p_subinventory;
6862             --l_transfer_locator_id := p_locator_id ;
6863             --l_mol_transfer_lpn_id := p_transfer_lpn_id;
6864 
6865 	  ELSIF ((l_transaction_type = 'CORRECT' AND p_primary_quantity < 0)
6866 		 AND l_parent_txn_type <> 'RETURN TO RECEIVING') THEN
6867 
6868             IF (l_debug = 1) THEN
6869                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 3',1);
6870             END IF;
6871 
6872             l_mol_res_in(1).lpn_id          := p_transfer_lpn_id;
6873 
6874 	    --See BUG 4502518 Issue 32
6875             l_mol_res_in(1).from_subinventory_code := p_from_subinventory;
6876             l_mol_res_in(1).from_locator_id        := p_from_locator_id;
6877 
6878             -- DEST SUB/LOC
6879             --l_transfer_sub        := p_from_subinventory;
6880             --l_transfer_locator_id := p_from_locator_id ;
6881             --l_mol_transfer_lpn_id :=  p_lpn_id;
6882 
6883 
6884 	  ELSIF (l_transaction_type IN ('RETURN TO CUSTOMER','RETURN TO VENDOR')) THEN
6885 
6886             IF (l_debug = 1) THEN
6887                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 4',1);
6888             END IF;
6889 
6890             l_mol_res_in(1).lpn_id          := p_lpn_id;
6891 
6892             -- FROM SUB
6893             l_mol_res_in(1).from_subinventory_code := p_from_subinventory;
6894             l_mol_res_in(1).from_locator_id        := p_from_locator_id;
6895             -- DEST SUB/LOC
6896             --l_transfer_sub        := p_subinventory;
6897             --l_transfer_locator_id := p_locator_id ;
6898             --l_mol_transfer_lpn_id := p_transfer_lpn_id;
6899 
6900 	  ELSIF (l_transaction_type = 'CORRECT' AND p_primary_quantity > 0) THEN
6901 
6902             IF (l_debug = 1) THEN
6903                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 5',1);
6904             END IF;
6905 
6906             l_mol_res_in(1).lpn_id          := p_lpn_id;
6907             -- FROM SUB
6908             l_mol_res_in(1).from_subinventory_code := p_from_subinventory;
6909             l_mol_res_in(1).from_locator_id        := p_from_locator_id;
6910             -- DEST SUB/LOC
6911             --l_transfer_sub        := p_subinventory;
6912             --l_transfer_locator_id := p_locator_id ;
6913             --l_mol_transfer_lpn_id := p_transfer_lpn_id;
6914 
6915 	 END IF;
6916 
6917 	 IF (l_debug = 1) THEN
6918 	    print_debug('MAINTAIN_MO_CON - Txn ID to Consume MOL:'||l_mol_txn_id,1);
6919 	    print_debug('MAINTAIN_MO_CON - LPN ID to Consume MOL:'||l_mol_lpn_id,1);
6920 	    l_progress := 'WMSINB-00000';
6921 	 END IF;
6922 
6923 	 IF (l_debug = 1) THEN
6924 	    print_debug('MAINTAIN_MO_CON - Primary Quantity: = ',1);
6925 	    l_progress := 'WMSINB-13391';
6926 	 END IF;
6927       END IF; --IF ((p_primary_quantity < 0 AND l_parent_txn_type IN
6928 
6929       IF ((l_transaction_type = 'CORRECT'
6930 	   AND ((p_primary_quantity < 0 AND (l_parent_txn_type IN ('ACCEPT','REJECT','TRANSFER','DELIVER')
6931 					     OR (l_parent_txn_type IN ('RETURN TO VENDOR','RETURN TO CUSTOMER')
6932 						 AND l_grand_parent_txn_type <> 'DELIVER')))
6933 		OR (p_primary_quantity > 0 AND l_parent_txn_type IN
6934 		    ('RECEIVE','ACCEPT','REJECT','TRANSFER','RETURN TO RECEIVING'))))
6935 	  OR (l_transaction_type = 'RETURN TO RECEIVING')) THEN
6936 
6937             IF (l_debug = 1) THEN
6938                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 6',1);
6939             END IF;
6940 
6941 	 IF (l_parent_txn_type = 'RETURN TO RECEIVING') THEN
6942 
6943             IF (l_debug = 1) THEN
6944                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 7',1);
6945             END IF;
6946 
6947             l_mol_res_in(1).lpn_id          := null;
6948             -- FROM SUB
6949             l_mol_res_in(1).from_subinventory_code := null;
6950             l_mol_res_in(1).from_locator_id        := null;
6951             -- DEST SUB/LOC
6952             l_transfer_sub        := p_subinventory;
6953             l_transfer_locator_id := p_locator_id ;
6954             l_mol_transfer_lpn_id := p_transfer_lpn_id;
6955 
6956 	  ELSIF (l_transaction_type = 'CORRECT' AND p_primary_quantity < 0) THEN
6957 
6958             IF (l_debug = 1) THEN
6959                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 8',1);
6960             END IF;
6961 
6962             --l_mol_res_in(1).lpn_id          := p_transfer_lpn_id;
6963             -- FROM SUB
6964             --l_mol_res_in(1).from_subinventory_code := p_subinventory;
6965             --l_mol_res_in(1).from_locator_id        := p_locator_id;
6966 
6967             -- DEST SUB/LOC
6968             -- This does not need to be set if it's a deliver txn.
6969             if l_parent_txn_type = 'DELIVER' then
6970                l_transfer_sub        := null;
6971                l_transfer_locator_id := null ;
6972             else
6973 	       --See bug 4502518 issue 32
6974                l_transfer_sub        := p_subinventory;
6975                l_transfer_locator_id := p_locator_id;
6976             end if;
6977 
6978             l_mol_transfer_lpn_id := p_lpn_id;
6979 
6980 	  ELSIF (l_transaction_type = 'RETURN TO RECEIVING') THEN
6981 
6982             IF (l_debug = 1) THEN
6983                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 9',1);
6984             END IF;
6985 
6986             --l_mol_res_in(1).lpn_id          := p_lpn_id;
6987             -- FROM SUB
6988             --l_mol_res_in(1).from_subinventory_code := p_from_subinventory;
6989             --l_mol_res_in(1).from_locator_id        := p_from_locator_id;
6990 
6991             -- DEST SUB/LOC
6992             l_transfer_sub        := p_subinventory;
6993             l_transfer_locator_id := p_locator_id ;
6994             l_mol_transfer_lpn_id := p_transfer_lpn_id;
6995 
6996 	  ELSIF (l_transaction_type = 'CORRECT' AND p_primary_quantity > 0
6997 		 AND l_parent_txn_type <> 'RETURN TO RECEIVING') THEN
6998 
6999             IF (l_debug = 1) THEN
7000                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 10',1);
7001             END IF;
7002 
7003             --l_mol_res_in(1).lpn_id          := p_lpn_id;
7004             -- FROM SUB
7005             --l_mol_res_in(1).from_subinventory_code := p_from_subinventory;
7006             --l_mol_res_in(1).from_locator_id        := p_from_locator_id;
7007 
7008             -- DEST SUB/LOC
7009             l_transfer_sub        := p_subinventory;
7010             l_transfer_locator_id := p_locator_id ;
7011             l_mol_transfer_lpn_id := p_transfer_lpn_id;
7012 
7013 	 END IF;
7014       END IF; --IF ((p_quantity < 0 AND l_parent_txn_type IN
7015 
7016       IF (l_debug = 1) THEN
7017 	    print_debug('MAINTAIN_MO_CON - BEFORE CALLING RESERVATION API' ,1);
7018 
7019 	    print_debug('MAINTAIN_MO_CON - LPN ID :='      || l_mol_res_in(1).lpn_id,1);
7020 	    print_debug('MAINTAIN_MO_CON - FROM SUB :='    || l_mol_res_in(1).from_subinventory_code,1);
7021 	    print_debug('MAINTAIN_MO_CON - FROM LOCATOR :='|| l_mol_res_in(1).from_locator_id,1);
7022 
7023 	    print_debug('MAINTAIN_MO_CON - TRANSFER LPN ID := '||  l_mol_transfer_lpn_id,1);
7024 
7025 	    print_debug('MAINTAIN_MO_CON - DESTINATION SUB :='||l_transfer_sub,1);
7026 	    print_debug('MAINTAIN_MO_CON - DESTINATION LOCATOR :='||l_transfer_locator_id,1);
7027       END IF;
7028 
7029       IF (l_debug = 1) THEN
7030 	    print_debug('MAINTAIN_MO - Before calling RSERVATION'||l_progress,1);
7031 	    l_progress := 'WMSINB-13616';
7032       END IF;
7033 
7034       INV_RCV_RESERVATION_UTIL.maintain_reservations
7035 	(x_return_status => x_return_status
7036 	 ,x_msg_count     => x_msg_count
7037 	 ,x_msg_data      => x_msg_data
7038 	 ,x_mol_tb        => l_mol_res_out
7039 	 ,p_cas_mol_tb    => l_mol_res_in
7040 	 );
7041 
7042       IF (l_debug = 1) THEN
7043 	 print_debug(' maintain_reservations - After calling maintain_reservations :'||x_return_status||':'||l_progress,1);
7044 	 print_debug(' maintain_reservations - l_mol_res_out.count: '||l_mol_res_out.COUNT,1);
7045 	 l_progress := 'WMSINB-45051';
7046       END IF;
7047 
7048       IF (x_return_status <> 'S') THEN
7049 	 l_progress := 'WMSINB-45052';
7050 	 RAISE fnd_api.g_exc_error;
7051       END IF;
7052 
7053       l_progress := 'WMSINB-45053';
7054 
7055       l_loop_index := l_mol_res_out.first;
7056       LOOP
7057 
7058 	EXIT WHEN l_loop_index IS NULL;
7059 
7060         IF (l_debug = 1) THEN
7061                    print_debug('MAINTAIN_MOC_CON -Inside MOL CONSL LOOP ',1);
7062         END IF;
7063 
7064 	--Bug 4286172...BEGIN CHANGES... Null out the lot_number if the transaction is a
7065 	--desktop txn without lpn.
7066 
7067 	IF (p_validation_flag = 'N' AND l_mol_transfer_lpn_id IS NULL) THEN
7068 	   l_mol_res_out(l_loop_index).lot_number := NULL;
7069 	END IF;
7070 
7071 	IF (l_debug = 1) THEN
7072 	   print_debug('MAINTAIN_MO - Lot to Query/Create MOL:'||l_mol_res_out(l_loop_index).lot_number,1);
7073 	END IF;
7074 
7075 	--Bug 4286172...END CHANGES...
7076 
7077         open c_transfer_mol(
7078                              l_mol_transfer_lpn_id
7079                             ,l_mol_res_out(l_loop_index).inventory_item_id
7080                             ,l_mol_res_out(l_loop_index).lot_number
7081                             ,l_mol_res_out(l_loop_index).item_revision
7082                             ,l_transfer_sub
7083                             ,l_transfer_locator_id
7084                             ,l_mol_res_out(l_loop_index).project_id
7085                             ,l_mol_res_out(l_loop_index).task_id
7086                             ,l_mol_res_out(l_loop_index).uom_code
7087                             ,l_mol_res_out(l_loop_index).backorder_delivery_detail_id
7088                             ,l_mol_res_out(l_loop_index).crossdock_type
7089                             ,l_transfer_inspection_status
7090                             );
7091         Fetch c_transfer_mol into l_transfer_mol_rec;
7092         close c_transfer_mol;
7093 
7094         if l_transfer_mol_rec.line_id is not null
7095         then
7096            -- Move Order Line found
7097            -- Check whether MOL is from the same SOURCE
7098            IF (l_debug = 1) THEN
7099 	      print_debug('MAINTAIN_MOC_CON - Move Order Line Found line Id = '|| l_transfer_mol_rec.line_id,1);
7100            END IF;
7101 
7102            check_reference(
7103                             p_old_reference           => l_transfer_mol_rec.reference
7104                            ,p_old_reference_type_code => l_transfer_mol_rec.reference_type_code
7105                            ,p_old_reference_id        => l_transfer_mol_rec.reference_id
7106                            ,p_new_reference           => l_new_reference
7107                            ,p_new_reference_type_code => l_new_reference_type_code
7108                            ,p_new_reference_id        => l_new_reference_id
7109                            ,x_reference               => l_reference
7110                            ,x_reference_type_code     => l_reference_type_code
7111                            ,x_reference_id            => l_reference_id
7112                            ,x_transaction_type_id     => l_transaction_type_id
7113                            ,x_txn_source_type_id      => l_txn_source_type_id
7114                            ,x_return_status           => x_return_status
7115                            ,x_msg_count               => x_msg_count
7116                            ,x_msg_data                => x_msg_data
7117                           );
7118 
7119            IF (l_debug = 1) THEN
7120                 print_debug('CHECK_REFERENCE - After calling check_reference :'||x_return_status||':'||l_progress,1);
7121                 l_progress := 'WMSINB-45056';
7122            END IF;
7123 
7124            IF (x_return_status <> 'S') THEN
7125               l_progress := 'WMSINB-45058';
7126               RAISE fnd_api.g_exc_error;
7127            END IF;
7128 
7129            --
7130            -- UPDATE THE MOVE ORDER LINE HERE
7131            --
7132            update mtl_txn_request_lines
7133                set reference = l_reference
7134                   ,reference_type_code = l_reference_type_code
7135                   ,reference_id = l_reference_id
7136                   ,quantity = quantity + ABS(l_mol_res_out(l_loop_index).quantity)
7137 	          ,primary_quantity = primary_quantity + ABS(l_mol_res_out(l_loop_index).primary_qty)
7138                   ,secondary_quantity = secondary_quantity + ABS(l_mol_res_out(l_loop_index).secondary_quantity)
7139                   ,transaction_type_id = nvl(l_transaction_type_id,transaction_type_id)
7140                   ,transaction_source_type_id = nvl(l_txn_source_type_id,transaction_source_type_id)
7141              where line_id = l_transfer_mol_rec.line_id
7142            ;
7143 
7144            l_progress := 'WMSINB-45060';
7145 
7146            --
7147            -- CANCEL THE OPERATION PLAN
7148            -- IF THE LPN IS LOADED AND TASK IS DISPATCHED
7149            -- WE NEED TO FAIL HERE
7150            --
7151 
7152            l_loaded := 0;
7153 
7154            BEGIN
7155                     SELECT 1
7156                     INTO l_loaded
7157                     FROM dual
7158                     WHERE exists
7159                     (SELECT 1
7160                      FROM wms_dispatched_tasks wdt
7161                      , mtl_material_transactions_temp mmtt
7162                      WHERE mmtt.move_order_line_id =  l_transfer_mol_rec.line_id
7163                      AND wdt.transaction_temp_id = mmtt.transaction_temp_id
7164                      AND wdt.status IN (3, 4) -- dispached or loaded
7165                      AND wdt.task_type = 2 -- putaway
7166                      );
7167 
7168                   IF (l_debug = 1) THEN
7169                      print_debug('MAINTAIN_MO_CON - TASK ALREADY LOADED FOR '||l_transfer_mol_rec.line_id || ' FAILURE' ,1);
7170                   END IF;
7171 
7172                   l_progress := 'WMSINB-45063';
7173                   RAISE fnd_api.g_exc_error;
7174 
7175            EXCEPTION
7176              WHEN NO_DATA_FOUND THEN
7177                   l_progress := 'WMSINB-45064';
7178                   null;
7179            END;
7180 
7181            call_atf_api(x_return_status => x_return_status,
7182                             x_msg_data => x_msg_data,
7183                             x_msg_count => x_msg_count,
7184                             x_error_code => l_error_code,
7185                             p_source_task_id => NULL,
7186                             p_activity_type_id => 1,
7187                             p_operation_type_id => NULL,
7188                             p_mol_id => l_transfer_mol_rec.line_id,
7189                             p_atf_api_name => g_atf_api_cancel);
7190 
7191            IF (x_return_status <> g_ret_sts_success) THEN
7192                   IF (l_debug = 1) THEN
7193                      print_debug('MAINTAIN_MO_CON - call_atf_api failed:'||l_transfer_mol_rec.line_id,1);
7194                      l_progress := 'WMSINB-45063';
7195                   END IF;
7196                   --raise error
7197                   l_progress := 'WMSINB-45064';
7198                   RAISE fnd_api.g_exc_error;
7199            END IF;
7200 
7201         Else
7202 
7203            -- Move Order Line Not Found Create Move Order
7204 
7205            IF (l_debug = 1) THEN
7206 	      print_debug('MAINTAIN_MOC_CON - Move Order Line Not Found line Id ',1);
7207            END IF;
7208 
7209            --create mol
7210            -- Bug 4508608. Abs of Qty is passed for negative correction when creating MOL
7211 
7212            inv_rcv_std_rcpt_apis.create_move_order(p_move_order_header_id => l_move_order_header_id
7213                                               ,p_po_line_location_id      => p_po_line_location_id
7214                                               ,p_po_distribution_id       => p_po_distribution_id
7215                                               ,p_shipment_line_id         => p_shipment_line_id
7216                                               ,p_oe_order_line_id         => p_oe_order_line_id
7217                                               ,p_routing                  => p_routing_header_id
7218                                               ,p_lot_control_code         => p_lot_control_code
7219                                               ,p_org_id                   => l_mol_res_out(l_loop_index).organization_id
7220                                               ,p_item_id                  => l_mol_res_out(l_loop_index).inventory_item_id
7221                                               ,p_qty                      => ABS(l_mol_res_out(l_loop_index).quantity)
7222                                               ,p_uom_code                 => l_mol_res_out(l_loop_index).uom_code
7223                                               ,p_lpn                      => l_mol_transfer_lpn_id
7224                                               ,p_project_id               => l_mol_res_out(l_loop_index).project_id
7225                                               ,p_task_id                  => l_mol_res_out(l_loop_index).task_id
7226                                               ,p_revision                 => l_mol_res_out(l_loop_index).item_revision
7227                                               ,p_inspect                  => l_transfer_inspection_status
7228                                               ,p_txn_source_id            => null
7229                                               ,x_status                   => x_return_status
7230                                               ,x_message                  => x_msg_data
7231                                               ,p_transfer_org_id          => l_mol_res_out(l_loop_index).transfer_org_id
7232                                               ,p_wms_process_flag         => 1
7233                                               ,p_lot_number               => l_mol_res_out(l_loop_index).lot_number
7234                                               ,p_secondary_quantity       => ABS(l_mol_res_out(l_loop_index).secondary_quantity)
7235                                               ,p_secondary_uom            => l_mol_res_out(l_loop_index).secondary_uom
7236                                               ,x_line_id                  => l_move_order_line_id
7237                                               );
7238             IF (l_debug = 1) THEN
7239                  print_debug('MAINTAIN_MO_CON - After calling create_move_order:'||x_return_status||':'||l_progress,1);
7240                  print_debug('MAINTAIN_MO_CON - Move Order Header ID:'||l_move_order_header_id||':'||l_progress,1);
7241                  print_debug('MAINTAIN_MO_CON - Move Order Line ID:'||l_move_order_line_id||':'||l_progress,1);
7242             END IF;
7243 
7244             IF (x_return_status <> 'S') THEN
7245                l_progress := 'WMSINB-45064';
7246                RAISE fnd_api.g_exc_error;
7247             END IF;
7248 
7249            --update mol for the sub and loc
7250            UPDATE mtl_txn_request_lines
7251               SET from_subinventory_code = Nvl(l_transfer_sub,from_subinventory_code)
7252               , from_locator_id = Nvl(l_transfer_locator_id, from_locator_id)
7253               WHERE header_id = l_move_order_header_id
7254                 and line_id = l_move_order_line_id
7255                 and organization_id = p_org_id
7256                 AND inventory_item_id = p_item_id;
7257 
7258 	   -- Call to UPDATE WDD
7259 	   IF (l_mol_res_out(l_loop_index).backorder_delivery_detail_id IS NOT NULL) THEN
7260 	      inv_rcv_reservation_util.update_wdd
7261 		(x_return_status => x_return_status
7262 		 ,x_msg_count    => x_msg_count
7263 		 ,x_msg_data     => x_msg_data
7264 		 ,p_wdd_id       => l_mol_res_out(l_loop_index).backorder_delivery_detail_id
7265 		 ,p_released_status => null
7266 		 ,p_mol_id          => l_move_order_line_id
7267 		 );
7268 	   END IF;
7269 
7270 
7271            IF (l_debug = 1) THEN
7272                  print_debug('MAINTAIN_MO_CON - After calling update_wdd '||x_return_status||':'||l_progress,1);
7273                  print_debug('MAINTAIN_MO_CON - Move Order Header ID:'||l_move_order_header_id||':'||l_progress,1);
7274            END IF;
7275 
7276            IF (x_return_status <> 'S') THEN
7277                l_progress := 'WMSINB-45064';
7278                RAISE fnd_api.g_exc_error;
7279            END IF;
7280         End if;
7281 
7282 	l_loop_index := l_mol_res_out.next(l_loop_index);
7283       End Loop;
7284 
7285 
7286       --We need to update the wms_process_flag on mol for all the lines for the given lpn as
7287       --we update all the mols for the given lpn to 2 in mark_returns
7288 
7289       UPDATE mtl_txn_request_lines
7290 	SET wms_process_flag = 1
7291 	WHERE (lpn_id = p_lpn_id
7292 	       OR lpn_id = p_transfer_lpn_id);
7293 
7294    END IF; --IF (l_transaction_type = 'CORRECT') THEN
7295 
7296 
7297    -- The transaction is complete so call the complete op instance now
7298    IF (l_transaction_type <> 'DELIVER') THEN
7299       IF p_mmtt_temp_id IS NOT NULL THEN
7300 	 IF (l_debug = 1) THEN
7301 	    print_debug('MAINTAIN_MO - calling call_atf_api:'||p_mmtt_temp_id,1);
7302 	    l_progress := 'WMSINB-13721';
7303 	 END IF;
7304 
7305 	 IF (l_transaction_type IN ('ACCEPT','REJECT')) THEN
7306 	    l_operation_type := wms_globals.g_op_type_inspect;
7307 	  ELSE
7308 	    l_operation_type := NULL;
7309 	 END IF;
7310 
7311 	 call_atf_api(x_return_status => x_return_status,
7312 		      x_msg_data => x_msg_data,
7313 		      x_msg_count => x_msg_count,
7314 		      x_error_code => l_error_code,
7315 		      p_source_task_id => p_mmtt_temp_id,
7316 		      p_activity_type_id => 1,
7317 		      p_operation_type_id => l_operation_type,
7318 		      p_mol_id => NULL,
7319 		      p_atf_api_name => g_atf_api_complete);
7320 
7321 	 IF (l_debug = 1) THEN
7322 	    print_debug('MAINTAIN_MO - Error Code from ATF API:'||l_error_code,1);
7323 	 END IF;
7324 
7325 	 IF (x_return_status <> g_ret_sts_success) THEN
7326 	    IF (l_error_code <> 15 OR l_error_code IS NULL) THEN
7327 	       IF (l_debug = 1) THEN
7328 		  print_debug('MAINTAIN_MO - call_atf_api failed:'||p_mmtt_temp_id,1);
7329 	       END IF;
7330 	       --raise error
7331 	       l_progress := 'WMSINB-13750';
7332 	       RAISE fnd_api.g_exc_error;
7333 	     ELSE --IF (l_error_code <> 15) THEN
7334 	       x_return_status := g_ret_sts_success;
7335 	    END IF; --IF (l_error_code <> 15) THEN
7336 	 END IF;
7337       END IF; --IF p_mmtt_temp_id IS NOT NULL THEN
7338    END IF; --IF (l_transaction_type <> 'DELIVER') THEN
7339 
7340    /* You do not want to update the wms_process_flag here because
7341       another RTI within the same group may want to process the
7342       same MOL, which has been marked by the UI.  Updating the MOL
7343       should have been performed in the logic above.  Note that this
7344       assumes that the UI have marked the correct MOL for processing
7345 
7346    --Update the wms_process_flag for all MOLs for the fiven lpns
7347    UPDATE mtl_txn_request_lines
7348      SET wms_process_flag = 1
7349      WHERE lpn_id = p_lpn_id;
7350 
7351    UPDATE mtl_txn_request_lines
7352      SET wms_process_flag = 1
7353      WHERE lpn_id = p_transfer_lpn_id;
7354      */
7355 EXCEPTION
7356    WHEN fnd_api.g_exc_error THEN
7357       x_return_status  := g_ret_sts_error;
7358       IF (l_debug = 1) THEN
7359 	 print_debug('MAINTAIN_MO - execution error:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
7360       END IF;
7361    WHEN fnd_api.g_exc_unexpected_error THEN
7362       x_return_status  := g_ret_sts_unexp_error;
7363       IF (l_debug = 1) THEN
7364 	 print_debug('MAINTAIN_MO - unexpected error:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
7365       END IF;
7366    WHEN OTHERS THEN
7367       X_RETURN_STATUS  := G_RET_STS_UNEXP_ERROR;
7368       IF (L_DEBUG = 1) THEN
7369 	 PRINT_DEBUG('MAINTAIN_MO - OTHER EXCEPTION:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
7370       END IF;
7371 
7372       IF SQLCODE IS NOT NULL THEN
7373 	 INV_MOBILE_HELPER_FUNCTIONS.SQL_ERROR('INV_RCV_INTERFACE_PVT.MAINTAIN_MO', l_progress,SQLCODE);
7374       END IF;
7375       -- GET MESSAGE COUNT AND DATA
7376       -- FND_MSG_PUB.COUNT_AND_GET(P_ENCODED => G_FALSE, P_COUNT => X_MSG_COUNT, P_DATA => X_MSG_DATA);
7377 END maintain_mo_con;
7378 -- R12
7379 
7380 PROCEDURE maintain_mo_wrapper(
7381                       p_rti_id IN NUMBER,
7382        		      p_primary_quantity IN NUMBER,
7383        		      p_primary_uom_code IN VARCHAR2,
7384        		      p_mmtt_temp_id IN NUMBER,
7385        		      p_org_id IN NUMBER,
7386        		      p_item_id IN NUMBER,
7387        		      p_revision IN VARCHAR2,
7388        		      p_qty IN NUMBER,
7389        		      p_uom_code IN VARCHAR2,
7390        		      p_lpn_id IN NUMBER,
7391        		      p_transfer_lpn_id IN NUMBER,
7392        		      p_lot_control_code IN NUMBER,
7393        		      p_serial_number_control_code IN NUMBER,
7394        		      p_po_line_location_id IN NUMBER,
7395        		      p_po_distribution_id IN NUMBER,
7396        		      p_shipment_line_id IN NUMBER,
7397        		      p_oe_order_line_id IN NUMBER,
7398        		      p_routing_header_id IN NUMBER,
7399        		      p_subinventory IN VARCHAR2,
7400        		      p_locator_id IN NUMBER,
7401        		      p_from_subinventory IN VARCHAR2,
7402        		      p_from_locator_id IN NUMBER,
7403        		      p_project_id IN NUMBER DEFAULT NULL,
7404        		      p_task_id IN NUMBER DEFAULT NULL,
7405        		      x_transaction_id OUT nocopy NUMBER,
7406        		      x_return_status OUT nocopy VARCHAR2,
7407        		      x_msg_count OUT nocopy NUMBER,
7408        		      x_msg_data OUT nocopy VARCHAR2,
7409                       -- OPMConvergence
7410                       p_sec_qty IN NUMBER DEFAULT NULL,
7411                       p_sec_uom IN VARCHAR2 DEFAULT NULL,
7412                       -- OPMConvergence
7413                       p_auto_transact_code IN VARCHAR2 DEFAULT NULL,
7414                       p_asn_line_flag IN VARCHAR2 DEFAULT NULL ,
7415                       p_validation_flag IN VARCHAR2 DEFAULT NULL,
7416                       -- Bug# 7154105
7417                       p_req_distribution_id IN NUMBER DEFAULT NULL
7418   )
7419   IS
7420      CURSOR c_mtlt(p_product_txn_id NUMBER) IS
7421 	SELECT Ltrim(Rtrim(lot_number)) lot_number,
7422 	  transaction_quantity,
7423 	  primary_quantity,
7424           -- OPMConvergence
7425           secondary_quantity
7426           -- OPMConvergence
7427 	  FROM mtl_transaction_lots_temp
7428 	  WHERE product_code = 'RCV'
7429 	  AND product_transaction_id = p_product_txn_id;
7430 
7431      l_mtlt_rec c_mtlt%ROWTYPE;
7432 
7433      l_num_lot_recs NUMBER := 0;
7434 
7435      l_lot_primary_qty NUMBER := 0;
7436      l_lot_txn_qty NUMBER := 0;
7437 
7438      l_progress VARCHAR2(15) := '00';
7439      L_DEBUG NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
7440      l_proc_name  VARCHAR2(30) := 'MAINTAIN_MO_WRAPPER';
7441 
7442      -- OPMConvergence
7443      l_lot_sec_qty  NUMBER;
7444      -- OPMConvergence
7445 BEGIN
7446    x_return_status := g_ret_sts_success;
7447 
7448    IF (l_debug = 1) THEN
7449       PRINT_DEBUG('Entering MAINTAIN_MO_WRAPPER:'||l_progress, 1);
7450       PRINT_DEBUG('MAINTAIN_MO_WRAPPER - LOT CONTROL CODE:'||p_lot_control_code||':'||l_progress, 1);
7451       l_progress := 'WMSINB-13832';
7452    END IF;
7453 
7454    IF p_lot_control_code > 1 THEN
7455       IF (l_debug = 1) THEN
7456 	 PRINT_DEBUG('MAINTAIN_MO_WRAPPER - LOT CONTROLLED:'||l_progress, 1);
7457 	 l_progress := 'WMSINB-13838';
7458       END IF;
7459 
7460       OPEN c_mtlt(p_rti_id);
7461 
7462       l_num_lot_recs := 0;
7463       LOOP
7464 	 FETCH c_mtlt INTO l_mtlt_rec;
7465 	 EXIT WHEN c_mtlt%notfound;
7466 
7467 	 IF (l_debug = 1) THEN
7468 	    PRINT_DEBUG('MAINTAIN_MO_WRAPPER - LOT NUMBER:'||l_mtlt_rec.lot_number||':'||l_progress, 1);
7469 	    PRINT_DEBUG('MAINTAIN_MO_WRAPPER - LOT PRIMARY QTY:'||l_mtlt_rec.primary_quantity||':'||l_progress, 1);
7470             -- OPMConvergence
7471 	    PRINT_DEBUG(l_proc_name||'- LOT SEC QTY:'||l_mtlt_rec.secondary_quantity||':'||l_progress, 1);
7472             -- OPMConvergence
7473 	    l_progress := 'WMSINB-13851';
7474 	 END IF;
7475 
7476 	 l_lot_primary_qty := (Sign(p_primary_quantity)) * l_mtlt_rec.primary_quantity;
7477 	 l_lot_txn_qty := (Sign(p_primary_quantity)) * l_mtlt_rec.transaction_quantity;
7478          -- OPMConvergence
7479 	 l_lot_sec_qty := (sign(p_primary_quantity)) * l_mtlt_rec.secondary_quantity;
7480          -- OPMConvergence
7481 	 l_num_lot_recs := l_num_lot_recs + 1;
7482 
7483          maintain_mo_con(
7484              p_rti_id => p_rti_id,
7485              p_primary_quantity => l_lot_primary_qty,
7486              p_primary_uom_code => p_primary_uom_code,
7487              p_mmtt_temp_id => p_mmtt_temp_id,
7488              p_org_id => p_org_id,
7489              p_item_id => p_item_id,
7490              p_revision => p_revision,
7491              p_qty => l_lot_txn_qty,
7492              p_uom_code => p_uom_code,
7493              p_lpn_id => p_lpn_id,
7494              p_transfer_lpn_id => p_transfer_lpn_id,
7495              p_lot_control_code => p_lot_control_code,
7496              p_serial_number_control_code => p_serial_number_control_code,
7497              p_lot_number => l_mtlt_rec.lot_number,
7498              p_po_line_location_id => p_po_line_location_id,
7499              p_po_distribution_id => p_po_distribution_id,
7500              p_shipment_line_id => p_shipment_line_id,
7501              p_oe_order_line_id => p_oe_order_line_id,
7502              p_routing_header_id => p_routing_header_id,
7503              p_subinventory => p_subinventory,
7504              p_locator_id => p_locator_id,
7505              p_from_subinventory => p_from_subinventory,
7506              p_from_locator_id => p_from_locator_id,
7507              p_project_id => p_project_id,
7508              p_task_id => p_task_id,
7509              x_transaction_id => x_transaction_id,
7510              x_return_status => x_return_status,
7511              x_msg_count => x_msg_count,
7512              x_msg_data => x_msg_data,
7513              -- OPMConvergence
7514              p_sec_uom => p_sec_uom,
7515              p_sec_qty => l_lot_sec_qty,
7516              -- OPMConvergence
7517 	     p_auto_transact_code => p_auto_transact_code,
7518 	     p_asn_line_flag => p_asn_line_flag,
7519 	     p_validation_flag => p_validation_flag,
7520          -- Bug# 7154105
7521          p_req_distribution_id => p_req_distribution_id
7522 	   );
7523 
7524 	 IF (l_debug = 1) THEN
7525 	    PRINT_DEBUG('MAINTAIN_MO_WRAPPER - MAINTAIN_MO RETURNED:'||x_return_status||':'||l_progress, 1);
7526 	    l_progress := 'WMSINB-13889';
7527 	 END IF;
7528 
7529 	 IF (x_return_status <> 'S') THEN
7530 	    l_progress := 'WMSINB-13893';
7531 	    RAISE fnd_api.g_exc_error;
7532 	 END IF;
7533       END LOOP;
7534 
7535       CLOSE c_mtlt;
7536    END IF;
7537 
7538    IF (l_debug = 1) THEN
7539       PRINT_DEBUG('MAINTAIN_MO_WRAPPER - NUM OF LOT RECS:'||l_num_lot_recs||':'||l_progress, 1);
7540       l_progress := 'WMSINB-13903';
7541    END IF;
7542 
7543    IF (p_lot_control_code = 1 OR l_num_lot_recs = 0) THEN
7544       maintain_mo_con(p_rti_id => p_rti_id,
7545         	  p_primary_quantity => p_primary_quantity,
7546         	  p_primary_uom_code => p_primary_uom_code,
7547         	  p_mmtt_temp_id => p_mmtt_temp_id,
7548         	  p_org_id => p_org_id,
7549         	  p_item_id => p_item_id,
7550         	  p_revision => p_revision,
7551         	  p_qty => p_qty,
7552         	  p_uom_code => p_uom_code,
7553         	  p_lpn_id => p_lpn_id,
7554         	  p_transfer_lpn_id => p_transfer_lpn_id,
7555         	  p_lot_control_code => p_lot_control_code,
7556         	  p_serial_number_control_code => p_serial_number_control_code,
7557         	  p_lot_number => NULL,
7558         	  p_po_line_location_id => p_po_line_location_id,
7559         	  p_po_distribution_id => p_po_distribution_id,
7560         	  p_shipment_line_id => p_shipment_line_id,
7561         	  p_oe_order_line_id => p_oe_order_line_id,
7562         	  p_routing_header_id => p_routing_header_id,
7563         	  p_subinventory => p_subinventory,
7564         	  p_locator_id => p_locator_id,
7565         	  p_from_subinventory => p_from_subinventory,
7566         	  p_from_locator_id => p_from_locator_id,
7567         	  p_project_id => p_project_id,
7568         	  p_task_id => p_task_id,
7569         	  x_transaction_id => x_transaction_id,
7570         	  x_return_status => x_return_status,
7571         	  x_msg_count => x_msg_count,
7572                   x_msg_data => x_msg_data,
7573                   -- OPMConvergence
7574                   p_sec_uom => p_sec_uom,
7575                   p_sec_qty => p_sec_qty,
7576                   -- OPMConvergence
7577 	          p_auto_transact_code => p_auto_transact_code,
7578 	          p_asn_line_flag => p_asn_line_flag,
7579 	          p_validation_flag => p_validation_flag,
7580               -- Bug# 7154105
7581               p_req_distribution_id => p_req_distribution_id
7582                   );
7583       IF (l_debug = 1) THEN
7584 	 PRINT_DEBUG('MAINTAIN_MO_WRAPPER - MAINTAIN_MO RETURNED:'||x_return_status||':'||l_progress, 1);
7585 	 l_progress := 'WMSINB-13937';
7586       END IF;
7587 
7588       IF (x_return_status <> 'S') THEN
7589 	 l_progress := 'WMSINB-13941';
7590 	 RAISE fnd_api.g_exc_error;
7591       END IF;
7592    END IF;
7593 
7594    IF (l_debug = 1) THEN
7595       print_debug('MAINTAIN_MO_WRAPPER - Sucessfull:'||':'||l_progress, 1);
7596    END IF;
7597 
7598 EXCEPTION
7599    WHEN fnd_api.g_exc_error THEN
7600       x_return_status  := g_ret_sts_error;
7601       IF (l_debug = 1) THEN
7602 	 print_debug('MAINTAIN_MO_WRAPPER - execution error:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
7603       END IF;
7604    WHEN fnd_api.g_exc_unexpected_error THEN
7605       x_return_status  := g_ret_sts_unexp_error;
7606       IF (l_debug = 1) THEN
7607 	 print_debug('MAINTAIN_MO_WRAPPER - unexpected error:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
7608       END IF;
7609    WHEN OTHERS THEN
7610       X_RETURN_STATUS  := G_RET_STS_UNEXP_ERROR;
7611       IF (L_DEBUG = 1) THEN
7612 	 PRINT_DEBUG('MAINTAIN_MO_WRAPPER - OTHER EXCEPTION:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
7613       END IF;
7614 
7615       IF SQLCODE IS NOT NULL THEN
7616 	 INV_MOBILE_HELPER_FUNCTIONS.SQL_ERROR('INV_RCV_INTERFACE_PVT.MAINTAIN_MO',l_progress, SQLCODE);
7617       END IF;
7618       -- GET MESSAGE COUNT AND DATA
7619       -- FND_MSG_PUB.COUNT_AND_GET(P_ENCODED => G_FALSE, P_COUNT => X_MSG_COUNT, P_DATA => X_MSG_DATA);
7620 END maintain_mo_wrapper;
7621 
7622 
7623 PROCEDURE process_txn(p_txn_id             IN NUMBER,
7624                       x_return_status            OUT NOCOPY VARCHAR2,
7625                       x_msg_count                OUT NOCOPY NUMBER,
7626                       x_msg_data                 OUT NOCOPY VARCHAR2
7627 		      ) IS
7628 
7629 			 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
7630 			 l_progress VARCHAR2(15) := '10';
7631 
7632 
7633 			 l_primary_uom VARCHAR2(3);
7634 			 l_primary_unit_of_measure VARCHAR2(30);
7635 			 l_lot_control_code NUMBER;
7636 			 l_serial_control_code NUMBER;
7637 			 l_revision_control_flag VARCHAR2(10);
7638                          -- OPMConvergence
7639 			 l_sec_uom_code VARCHAR2(3);
7640                          -- OPMConvergence
7641 			  l_proc_name VARCHAR2(30) := 'PROCESS_TXN';
7642 			 cursor c_rti is
7643 			    select interface_transaction_id
7644 			      ,transaction_type
7645 			      ,item_id
7646 			      ,item_description
7647                               ,item_revision
7648 			      ,lpn_id
7649 			      ,transfer_lpn_id
7650 			      ,license_plate_number
7651 			      ,transfer_license_plate_number
7652 			      ,quantity
7653                               ,uom_code
7654                               ,unit_of_measure
7655 			      ,shipment_header_id
7656                               ,shipment_num
7657 			      ,routing_header_id
7658 			      ,to_organization_id
7659 			      ,from_organization_id
7660 			      ,subinventory
7661 			      ,locator_id
7662 			      ,from_subinventory
7663 			      ,from_locator_id
7664 			      ,parent_transaction_id
7665 			      ,source_document_code
7666                               ,group_id
7667                               ,primary_quantity
7668                               ,mmtt_temp_id
7669 			      ,po_line_location_id
7670 			      ,po_distribution_id
7671 			      ,shipment_line_id
7672 			      ,oe_order_line_id
7673                               ,auto_transact_code
7674 			      ,Nvl(validation_flag,'N') validation_flag
7675 			      ,project_id
7676 			      ,task_id
7677 			      ,Nvl(mobile_txn, 'N') mobile_txn
7678 			      ,inv_transaction_id
7679 			      ,processing_mode_code
7680                               -- OPMConvergence
7681                               ,secondary_quantity
7682                               ,secondary_unit_of_measure
7683                               ,secondary_uom_code
7684                               -- OPMConvergence
7685 			      ,requisition_line_id
7686                   -- Bug# 7154105
7687                   ,req_distribution_id
7688 			      from rcv_transactions_interface rti
7689 			      where rti.interface_transaction_id = p_txn_id;
7690 
7691 			 l_rti_rec c_rti%rowtype;
7692 
7693 			 l_parent_txn_type varchar2(30);
7694 			 l_parent_parent_txn_type varchar2(30);
7695 			 l_parent_parent_txn_id NUMBER;
7696 
7697 			 l_from_lpn_state boolean;
7698 			 l_to_lpn_state boolean;
7699 
7700 			 l_lpn_context NUMBER;
7701 			 l_transfer_lpn_context NUMBER;
7702 
7703 			 l_cur_from_parent_lpn_id NUMBER;
7704 			 l_cur_to_parent_lpn_id NUMBER;
7705 
7706 			 l_serial_status NUMBER;
7707 			 l_inspection_status NUMBER;
7708 
7709 			 l_unpack_org_id NUMBER;
7710 
7711 			 l_rt_transaction_id NUMBER;
7712 
7713 			 l_from_org_serial_control NUMBER;
7714 			 l_from_org_lot_control NUMBER;
7715 			 l_from_org_rev_control NUMBER;
7716 			 l_full_unpack BOOLEAN := FALSE;
7717 
7718 			 l_total_lot_qty NUMBER;
7719 			 l_total_serial_qty NUMBER;
7720 
7721 			 l_asn_line_flag VARCHAR2(1) := 'N';
7722 
7723 			 l_trx_type_for_unpack VARCHAR2(30) := NULL;
7724 			 l_int_trx_id_for_unpack NUMBER := NULL;
7725 
7726 			 l_transactions_enabled_flag VARCHAR2(1);
7727 
7728 			 l_sec_txn_for_rtv VARCHAR2(1) := 'N';
7729 
7730                          l_lpn_org NUMBER;
7731 
7732                          l_parent_project_id NUMBER;
7733                          l_parent_task_id    NUMBER;
7734 
7735 			 l_wlpn_source_header_id NUMBER;
7736 			 l_xfr_wlpn_source_header_id NUMBER;
7737 
7738 			 l_intransit_type NUMBER :=0;
7739 			 l_auto_unnest_empty_lpns NUMBER := 1;
7740 
7741 			 --R12
7742 			 l_mol_res_in  cas_mol_rec_tb_tp;
7743 			 l_mol_res_out cas_mol_rec_tb_tp;
7744 			 l_po_header_id NUMBER;
7745 			 l_shipment_header_id NUMBER;
7746 			 l_requisition_line_id NUMBER;
7747 			 --6168447
7748 			 l_current_lpn_context NUMBER;
7749 BEGIN
7750    x_return_status := g_ret_sts_success;
7751 
7752    IF (l_debug = 1) THEN
7753       print_debug('Inside PROCESS_TXN', 4);
7754    END IF;
7755 
7756    open c_rti;
7757    Fetch c_rti into l_rti_rec;
7758    Close c_rti;
7759 
7760    IF (l_debug = 1) THEN
7761       print_debug('TRANSACTION_TYPE: '||l_rti_rec.transaction_type,1);
7762       print_debug('VALIDATION_FLAG:  '||l_rti_rec.validation_flag,1);
7763 
7764    END IF;
7765 
7766    IF (l_rti_rec.item_id IS NULL) THEN
7767       IF (l_debug = 1) THEN
7768          print_debug('PROCESS_TXN - One Time Item Exiting...',1);
7769          l_progress := 'WMSINB-14075';
7770       END IF;
7771       RETURN;
7772    END IF;
7773 
7774    IF (l_rti_rec.transaction_type = 'UNORDERED') THEN
7775       IF (l_debug = 1) THEN
7776          print_debug('PROCESS_TXN - Unordered Transaction Exit with success...',1);
7777          l_progress := 'WMSINB-14076';
7778       END IF;
7779       RETURN;
7780    END IF;
7781 
7782    --If the source document is 'REQ' then of the intransit_type in
7783    --mtl_interorg_parameters is set to 'Direct' then exit from this api.
7784    IF (l_rti_rec.source_document_code = 'REQ'
7785        AND l_rti_rec.mobile_txn = 'N'
7786        AND l_rti_rec.transaction_type = 'RECEIVE'
7787        AND l_rti_rec.inv_transaction_id IS NOT NULL
7788        AND l_rti_rec.processing_mode_code = 'ONLINE') THEN
7789       BEGIN
7790          SELECT intransit_type
7791            INTO l_intransit_type
7792            FROM mtl_interorg_parameters
7793           WHERE from_organization_id = l_rti_rec.from_organization_id
7794             AND to_organization_id = l_rti_rec.to_organization_id;
7795 
7796       EXCEPTION
7797          WHEN OTHERS THEN
7798             NULL;
7799       END;
7800 
7801       IF (l_intransit_type = 1) THEN
7802           SELECT primary_uom_code
7803             INTO  l_primary_uom
7804             FROM mtl_system_items
7805             WHERE inventory_item_id = l_rti_rec.item_id
7806             AND organization_id = l_rti_rec.to_organization_id;
7807 
7808           IF (l_debug = 1) THEN
7809              print_debug('PROCESS_TXN - DIRECT REQ RECEIPT. CALLING RSV API',1);
7810              print_debug('l_rti_rec.transaction_type     => '||l_rti_rec.transaction_type,1);
7811              print_debug('l_rti_rec.to_organization_id   => '||l_rti_rec.to_organization_id,1);
7812              print_debug('l_rti_rec.item_id              => '||l_rti_rec.item_id,1);
7813              print_debug('l_rti_rec.item_revision        => '||l_rti_rec.item_revision,1);
7814              print_debug('l_rti_rec.project_id           => '||l_rti_rec.project_id,1);
7815              print_debug('l_rti_rec.task_id              => '||l_rti_rec.task_id,1);
7816              print_debug('l_rti_rec.primary_uom_code     => '||l_primary_uom,1);
7817              print_debug('l_rti_rec.primary_quantity     => '||l_rti_rec.primary_quantity,1);
7818              print_debug('l_rti_rec.requisition_line_id  => '||l_rti_rec.requisition_line_id,1);
7819              print_debug('l_rti_rec.auto_transact_code   => '||'DELIVER',1);
7820           END IF;
7821 
7822           l_mol_res_in(1).transaction_type       := l_rti_rec.transaction_type;
7823           l_mol_res_in(1).organization_id        := l_rti_rec.to_organization_id;
7824           l_mol_res_in(1).inventory_item_id      := l_rti_rec.item_id;
7825           l_mol_res_in(1).item_revision          := l_rti_rec.item_revision;
7826           l_mol_res_in(1).project_id             := l_rti_rec.project_id;
7827           l_mol_res_in(1).task_id                := l_rti_rec.task_id;
7828           l_mol_res_in(1).primary_uom_code       := l_primary_uom;
7829           l_mol_res_in(1).primary_qty            := l_rti_rec.primary_quantity;
7830           l_mol_res_in(1).requisition_line_id    := l_rti_rec.requisition_line_id;
7831           l_mol_res_in(1).auto_transact_code     := 'DELIVER';
7832 
7833           INV_RCV_RESERVATION_UTIL.maintain_reservations
7834             (x_return_status => x_return_status
7835              ,x_msg_count     => x_msg_count
7836              ,x_msg_data      => x_msg_data
7837              ,x_mol_tb        => l_mol_res_out
7838              ,p_cas_mol_tb    => l_mol_res_in
7839              );
7840 
7841           IF (l_debug = 1) THEN
7842              print_debug('PROCESS_TXN - rsv api returns:'||x_return_status,1);
7843           END IF;
7844 
7845           IF (x_return_status <> g_ret_sts_success) THEN
7846              l_progress := 'WMSINB-14998';
7847              RAISE FND_API.G_EXC_ERROR;
7848           END IF;
7849 
7850           RETURN;
7851       END IF;
7852 
7853    END IF; --IF (l_rti_rec.source_document_code = 'REQ') THEN
7854 
7855 
7856    l_progress := 'WMSINB-14080';
7857 
7858    -- Get The Parent Txn Details
7859    BEGIN
7860       select transaction_type,
7861              parent_transaction_id,
7862              project_id,
7863              task_id
7864         into l_parent_txn_type,
7865              l_parent_parent_txn_id,
7866              l_parent_project_id,
7867              l_parent_task_id
7868         from rcv_transactions rt
7869        where rt.transaction_id = l_rti_rec.parent_transaction_id;
7870    Exception
7871       When others then
7872           -- Review Later
7873           -- Set appropiate Message
7874           --
7875           l_progress := 'WMSINB-14095';
7876           null;
7877    End;
7878 
7879    --Bug No.      :  3159152/3101512
7880    --Description  :  The problem was receiving calls process_txn twice for a RTV txn on
7881    --top of a deliver txn - one for the RTR txn they create on
7882    --top of the deliver txn and other time for the RTV txn
7883    --created on top of the RTR txn. This was throwing too many
7884    --rows exception at WMSINB-12888.
7885    --The fix is to return from process_txn for the second time
7886    --they call us and do all the processing the first time itself.
7887    BEGIN
7888       IF l_rti_rec.transaction_type in ('RETURN TO VENDOR','RETURN TO CUSTOMER') AND
7889          l_parent_txn_type = 'DELIVER' THEN
7890           SELECT 'Y'
7891             INTO l_sec_txn_for_rtv
7892             FROM rcv_transactions
7893             WHERE transaction_type = 'RETURN TO RECEIVING'
7894             AND interface_transaction_id = p_txn_id
7895             AND exists (SELECT 1
7896                    FROM rcv_transactions
7897                    WHERE transaction_type IN ('RETURN TO VENDOR','RETURN TO CUSTOMER')
7898                    AND interface_transaction_id = p_txn_id);
7899       END IF;
7900    EXCEPTION
7901       WHEN no_data_found THEN
7902           l_sec_txn_for_rtv := 'N';
7903           l_progress := 'WMSINB-14097';
7904       WHEN OTHERS THEN
7905           l_progress := 'WMSINB-14098';
7906           RAISE fnd_api.g_exc_error;
7907    END;
7908    IF l_sec_txn_for_rtv = 'Y' THEN
7909       l_progress := 'WMSINB-14099';
7910       x_return_status := g_ret_sts_success;
7911       IF (l_debug = 1) THEN
7912           print_debug('PROCESS_TXN returned with success for one step rtv on dlvr txn', 4);
7913       END IF;
7914       RETURN;
7915    END IF;
7916 
7917    -- Get The grand Parent Txn Details
7918    Begin
7919       select transaction_type
7920         into l_parent_parent_txn_type
7921         from rcv_transactions rt
7922        where rt.transaction_id = l_parent_parent_txn_id;
7923    Exception
7924       When others then
7925          -- Review Later
7926          -- Set appropiate Message
7927          --
7928          l_progress := 'WMSINB-14110';
7929          null;
7930    End;
7931 
7932    --bug 4201926 and bug 4286203 code fix begin
7933    IF (l_rti_rec.transaction_type IN ('CORRECT','RETURN TO VENDOR',
7934                                       'RETURN TO CUSTOMER','RETURN TO RECEIVING')
7935        AND (l_parent_txn_type = 'UNORDERED' OR l_parent_parent_txn_type = 'UNORDERED')) THEN
7936       IF (l_debug = 1) THEN
7937           print_debug('PROCESS_TXN - Unordered Transaction Exit with success...',1);
7938           l_progress := 'WMSINB-14115';
7939       END IF;
7940       RETURN;
7941    END IF;
7942    --bug 4201926 and bug 4286203 code fix end
7943 
7944    -- ASN_LINE_FLAG indicates whether it's an ASN or not
7945 
7946    IF (l_rti_rec.shipment_line_id IS NOT NULL
7947        AND l_rti_rec.transaction_type = 'RECEIVE') THEN
7948       BEGIN
7949          -- This part of code is changed to take into account ASN_TYPE
7950          --SELECT Nvl(asn_line_flag, 'N')
7951          --  INTO l_asn_line_flag
7952          --  FROM rcv_shipment_lines
7953          --  WHERE shipment_line_id = l_rti_rec.shipment_line_id;
7954          --
7955          select decode(ASN_TYPE,'ASN','Y','N')
7956            into l_asn_line_flag
7957            from rcv_shipment_headers
7958           WHERE shipment_header_id =  l_rti_rec.shipment_header_id;
7959       EXCEPTION
7960           WHEN OTHERS THEN
7961              l_asn_line_flag := 'N';
7962       END;
7963    END IF;
7964 
7965    l_progress := 'WMSINB-14127';
7966 
7967    l_from_lpn_state := get_lpn_id(l_rti_rec.lpn_id,
7968                        l_rti_rec.license_plate_number,
7969                        l_lpn_context,l_cur_from_parent_lpn_id,l_wlpn_source_header_id);
7970 
7971    l_progress := 'WMSINB-14131';
7972 
7973    if (l_from_lpn_state <> TRUE ) then
7974       l_progress := 'WMSINB-14134';
7975       IF (l_debug = 1) THEN
7976          print_debug('Process_txn: lpn_id and license_plate number does not exist' , 1);
7977       END If;
7978       -- MSG no new message just add the one on stack
7979       -- Review Later.
7980       -- Set Appropiate MESSAGE For ERROR
7981       --
7982       l_progress := 'WMSINB-14142';
7983       RAISE FND_API.G_EXC_ERROR;
7984    end if;
7985 
7986    l_progress := 'WMSINB-14146';
7987 
7988    l_to_lpn_state := get_lpn_id(l_rti_rec.transfer_lpn_id,
7989                                 l_rti_rec.transfer_license_plate_number,
7990                                 l_transfer_lpn_context,
7991                                 l_cur_to_parent_lpn_id,
7992                                 l_xfr_wlpn_source_header_id);
7993 
7994    l_progress := 'WMSINB-14153';
7995 
7996    if (l_to_lpn_state <> TRUE ) then
7997       l_progress := 'WMSINB-14156';
7998       IF (l_debug = 1) THEN
7999          print_debug('Process_txn: transfer_lpn_id and transfer_license_plate number does not exist' , 1);
8000       END If;
8001       -- MSG no new message just add the one on stack
8002       -- EXISTING LPN_ID and LICENSE_PLATE_NUMBER COMBINATION IS INVALID
8003       -- Review Later.
8004       -- Set Appropiate MESSAGE For ERROR
8005       --
8006       l_progress := 'WMSINB-14165';
8007       RAISE FND_API.G_EXC_ERROR;
8008    End if;
8009 
8010    l_progress := 'WMSINB-14169';
8011 
8012    SELECT primary_uom_code,
8013      primary_unit_of_measure,
8014      mtl_transactions_enabled_flag,
8015      lot_control_code,
8016      serial_number_control_code,
8017      decode(revision_qty_control_code
8018        ,1, 'N'
8019        ,2, 'Y'
8020        ,'N') item_rev_control_flag,
8021      secondary_uom_code
8022    INTO  l_primary_uom,
8023      l_primary_unit_of_measure,
8024      l_transactions_enabled_flag,
8025      l_lot_control_code,
8026      l_serial_control_code,
8027      l_revision_control_flag,
8028      -- OPMConvergence
8029      l_sec_uom_code
8030      -- OPMConvergence
8031    FROM mtl_system_items
8032    WHERE inventory_item_id = l_rti_rec.item_id
8033      AND organization_id = l_rti_rec.to_organization_id;
8034 
8035    l_progress := 'WMSINB-14190';
8036 
8037    --PO tracks the revision information for non revision controlled items.
8038    --We cannot track revision if revision controll is not on, hence nulling
8039    --it OUT.
8040    IF (l_revision_control_flag = 'N') THEN
8041       l_rti_rec.item_revision := NULL;
8042    END IF;
8043 
8044    IF (l_rti_rec.transaction_type = 'CANCEL') THEN
8045       IF (l_debug = 1) THEN
8046           print_debug('PROCESS_TXN - Calling cancel_asn',1);
8047       END IF;
8048 
8049       cancel_asn(x_return_status => x_return_status
8050                 ,x_msg_count => x_msg_count
8051                 ,x_msg_data => x_msg_data
8052                 ,p_shipment_header_id => l_rti_rec.shipment_header_id
8053                 ,p_shipment_line_id => l_rti_rec.shipment_line_id
8054                 ,p_primary_quantity => l_rti_rec.primary_quantity
8055       );
8056       IF (x_return_status <> g_ret_sts_success) THEN
8057           IF (l_debug = 1) THEN
8058              print_debug('PROCESS_TXN - Cancel ASN Failed...:'||x_return_status,1);
8059           END IF;
8060           --raise an error
8061           --review later
8062           l_progress := 'WMSINB-14209';
8063           RAISE fnd_api.g_exc_error;
8064       END IF;
8065 
8066       IF (l_debug = 1) THEN
8067           print_debug('PROCESS_TXN - Done calling cancel_asn',1);
8068       END IF;
8069    END IF; --IF (l_rti_rec.transaction_type = 'CANCEL') THEN
8070 
8071    IF (l_rti_rec.validation_flag = 'N'
8072        AND l_rti_rec.transaction_type IN ('CORRECT','RETURN TO VENDOR',
8073                                           'RETURN TO CUSTOMER','RETURN TO RECEIVING')) THEN
8074       l_trx_type_for_unpack := l_rti_rec.transaction_type;
8075       l_int_trx_id_for_unpack := l_rti_rec.interface_transaction_id;
8076     ELSE
8077       l_trx_type_for_unpack := NULL;
8078       l_int_trx_id_for_unpack := NULL;
8079    END IF;
8080 
8081    -- Validating Project and Task
8082    -- Currently Validate Project/Task for Deliver
8083    l_progress := 'WMSINB-14210';
8084 
8085    IF ( l_rti_rec.transaction_type in( 'DELIVER','ACCEPT','REJECT','TRANSFER') ) then
8086      IF ( (l_rti_rec.project_id is null and l_parent_project_id is not null) or
8087           (l_rti_rec.task_id is null and l_parent_task_id is not null)
8088         ) then
8089        l_progress := 'WMSINB-14211';
8090        IF (l_debug = 1) THEN
8091           print_debug('PROCESS_TXN - parent rti has proj/task info and txn has no proj/task info ',1);
8092        END IF;
8093        -- Raise Failure
8094        RAISE fnd_api.g_exc_error;
8095      ELSIF (l_rti_rec.project_id is not null or l_rti_rec.task_id is not null) then
8096         if (l_parent_project_id is null and l_parent_task_id is null ) then
8097            l_progress := 'WMSINB-14212';
8098            IF (l_debug = 1) THEN
8099                print_debug('PROCESS_TXN - parent rti has no proj/task info ',1);
8100            END IF;
8101            -- This is ok
8102         Else
8103            if ( ( nvl(l_rti_rec.project_id,0) <> nvl(l_parent_project_id,0) ) or
8104              ( nvl(l_rti_rec.task_id,0) <> nvl(l_parent_task_id,0))
8105               ) then
8106               -- Raise Failure
8107               l_progress := 'WMSINB-14213';
8108               IF (l_debug = 1) THEN
8109                  print_debug('PROCESS_TXN - parent rti has different proj/task info than rti ',1);
8110               END IF;
8111               RAISE fnd_api.g_exc_error;
8112            End if;
8113         End if;
8114      END IF;
8115    END IF;
8116 
8117    l_progress := 'WMSINB-14228';
8118 
8119    IF ( ( l_rti_rec.transaction_type NOT IN
8120         ('SHIP','CORRECT','CANCEL','DELIVER','RETURN TO RECEIVING') )
8121         AND NOT ( l_rti_rec.transaction_type in ('RETURN TO VENDOR','RETURN TO CUSTOMER') and l_parent_txn_type = 'DELIVER' )
8122    )  THEN -- CASE FOR RTV, RTC for a parent RECEIVE TXN, CASE FOR RECEIVE TXN
8123       l_progress := 'WMSINB-14234';
8124 
8125       IF (l_asn_line_flag = 'Y' AND l_rti_rec.transaction_type = 'RECEIVE' ) THEN
8126 
8127          IF (l_debug = 1) THEN
8128             print_debug('PROCESS_TXN - ASN RECEIVE TXN ',1);
8129          END IF;
8130 
8131          l_progress := 'WMSINB-14237';
8132 
8133          IF l_rti_rec.lpn_id IS NOT NULL THEN
8134             -- Review Later
8135             l_progress := 'WMSINB-14241';
8136 
8137             -- Don't do unpack all but only unpack the REQUIRED QTY /ITEM from here also.
8138             -- This is needed to keep the Nesting
8139             --wms_container_pvt.packunpack_container(
8140             --   p_api_version            => 1.0,
8141             --   p_init_msg_list          => g_false,
8142             --   p_commit                 => g_false,
8143             --   p_validation_level       => fnd_api.g_valid_level_none,
8144             --   x_return_status          => x_return_status,
8145             --   x_msg_count              => x_msg_count,
8146             --   x_msg_data               => x_msg_data,
8147             --   p_lpn_id                 => l_rti_rec.lpn_id,
8148             --   p_organization_id        => l_rti_rec.to_organization_id,
8149             --   p_operation              => 2, --- TO UNPACK
8150             --   p_unpack_all            => 1
8151             --   );
8152             Begin
8153                -- Get the LPN's Org Here
8154                select organization_id
8155                  into l_lpn_org
8156                  from wms_license_plate_numbers wlpn
8157                 where wlpn.lpn_id = l_rti_rec.lpn_id;
8158                --
8159                l_progress := 'WMSINB-14465';
8160             Exception
8161                when others then
8162                  l_progress := 'WMSINB-14466';
8163                  l_lpn_org := null;
8164             End;
8165 
8166             IF (l_rti_rec.lpn_id = Nvl(l_rti_rec.transfer_lpn_id,-1)) THEN
8167                l_auto_unnest_empty_lpns := 2;
8168             ELSE
8169                l_auto_unnest_empty_lpns := 1;
8170             END IF;
8171 
8172             PackUnpack_wrapper( x_return_status                => x_return_status
8173                               ,x_msg_count                   => x_msg_count
8174                               ,x_msg_data                    => x_msg_data
8175                               ,p_lot_control_code            => l_lot_control_code
8176                               ,p_serial_control_code         => l_serial_control_code
8177                               ,p_product_txn_id              => p_txn_id
8178                               ,p_product_code                => 'RCV'
8179                               ,p_lpn_id                      => l_rti_rec.lpn_id
8180                               ,p_content_lpn_id              => null
8181                               ,p_content_item_id             => l_rti_rec.item_id
8182                               ,p_content_item_desc           => l_rti_rec.item_description
8183                               ,p_revision                    => l_rti_rec.item_revision
8184                               ,p_primary_quantity            => l_rti_rec.primary_quantity
8185                               ,p_primary_uom                 => l_primary_uom
8186                               ,p_organization_id             => l_lpn_org
8187                               ,p_operation                   => 2
8188                               ,p_cost_group_id               => null
8189                               ,p_source_type_id              => null
8190                               ,p_source_header_id            => NULL --l_rti_rec.group_id
8191                               ,p_source_name                 => null
8192                               ,p_source_line_id            => NULL
8193                               ,p_source_line_detail_id     => NULL
8194                               ,p_auto_unnest_empty_lpns    => l_auto_unnest_empty_lpns
8195                               -- OPMConvergence
8196                               ,p_sec_quantity          => l_rti_rec.secondary_quantity
8197                               ,p_sec_uom               => l_sec_uom_code
8198                               -- OPMConvergence
8199                               -- *R12* --
8200                               ,p_txn_quantity          => l_rti_rec.quantity
8201                               ,p_txn_uom_code          => l_rti_rec.uom_code
8202                               -- *R12 *--
8203             );
8204 
8205 
8206             -- Check the error status from the above call
8207             if x_return_status <> G_RET_STS_SUCCESS Then
8208                --  Review Late Set Appropiate Message
8209                l_progress := 'WMSINB-14258';
8210                -- Do not error out for ASNs
8211                x_return_status := g_ret_sts_success;
8212                --RAISE FND_API.G_EXC_ERROR;
8213             End if;
8214 
8215          End if; --l_rti_rec.lpn_id is not null
8216 
8217          l_progress := 'WMSINB-14266';
8218 
8219          IF l_rti_rec.transfer_lpn_id IS NOT NULL THEN
8220             --
8221             l_progress := 'WMSINB-14270';
8222 
8223             IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
8224                           l_rti_rec.transfer_lpn_id,
8225                           l_transactions_enabled_flag))
8226             THEN
8227                IF (l_debug = 1) THEN
8228                   print_debug('PROCESS_TXN - Expense and Non Expense Items cannot be Mixed in an LPN',1);
8229                   print_debug('PROCESS_TXN - ORG:LPN:TXNENABLEDFLAG::'||
8230                      l_rti_rec.to_organization_id||':'||l_rti_rec.transfer_lpn_id||
8231                      ':'||l_transactions_enabled_flag,1);
8232                END IF;
8233                l_progress := 'WMSINB-14282';
8234 
8235                --review later
8236                RAISE fnd_api.g_exc_error;
8237             END IF; --IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
8238 
8239             IF (validate_pjm_commingle(l_rti_rec.to_organization_id,
8240                      l_rti_rec.transfer_lpn_id,
8241                      l_rti_rec.project_id,
8242                      l_rti_rec.task_id))
8243             THEN
8244                IF (l_debug = 1) THEN
8245                   print_debug('PROCESS_TXN - Project/Task commingling not allowed in LPN:'||l_rti_rec.transfer_lpn_id,1);
8246                END IF;
8247                l_progress := 'WMSINB-14288';
8248 
8249                RAISE fnd_api.g_exc_error;
8250             END IF; --IF (!validate_pjm_commingle(l_rti_rec.to_organization_id,
8251 
8252             IF (l_debug = 1) THEN
8253                print_debug('PROCESS_TXN - Organization ID:'||l_rti_rec.to_organization_id,1);
8254             END IF;
8255 
8256             --
8257             -- CALL UPDATE TLPN ORGANIZATION LOCATOR FOR WLPN/WLPNC
8258             --
8259 
8260             l_lpn_context := get_lpn_context(p_transaction_type => l_rti_rec.transaction_type
8261                              , p_routing_header_id => l_rti_rec.routing_header_id
8262                              , p_parent_transaction_type => l_parent_txn_type
8263                              , p_parent_parent_txn_type => l_parent_parent_txn_type
8264                              , p_quantity => l_rti_rec.primary_quantity
8265                              , p_auto_transact_code => l_rti_rec.auto_transact_code);
8266 
8267 
8268             l_progress := 'WMSINB-14305';
8269 
8270             update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
8271                                         ,p_sub             => l_rti_rec.SUBINVENTORY
8272                                         ,p_locator         => l_rti_rec.LOCATOR_ID
8273                                         ,p_lpn_context     => l_lpn_context
8274                                         ,p_lpn_id          => l_rti_rec.transfer_lpn_id
8275                                         ,x_return_status   => x_return_status
8276                                         ,x_msg_count       => x_msg_count
8277                                         ,x_msg_data        => x_msg_data ) ;
8278 
8279             l_progress := 'WMSINB-14316';
8280 
8281             -- Check the error status from the above call
8282             if x_return_status <> G_RET_STS_SUCCESS Then
8283                --  Review Late Set Appropiate Message
8284                l_progress := 'WMSINB-14321';
8285                RAISE FND_API.G_EXC_ERROR;
8286             End if;
8287 
8288 
8289             PackUnpack_wrapper( x_return_status               => x_return_status
8290                               ,x_msg_count                   => x_msg_count
8291                               ,x_msg_data                    => x_msg_data
8292                               ,p_lot_control_code            => l_lot_control_code
8293                               ,p_serial_control_code         => l_serial_control_code
8294                               ,p_product_txn_id              => p_txn_id
8295                               ,p_product_code                => 'RCV'
8296                               ,p_lpn_id                      => l_rti_rec.transfer_lpn_id
8297                               ,p_content_lpn_id              => null
8298                               ,p_content_item_id             => l_rti_rec.item_id
8299                               ,p_content_item_desc           => l_rti_rec.item_description
8300                               ,p_revision                    => l_rti_rec.item_revision
8301                               ,p_primary_quantity            => l_rti_rec.primary_quantity
8302                               ,p_primary_uom                 => l_primary_uom
8303                               ,p_organization_id             => l_rti_rec.to_organization_id
8304                               ,p_operation                   => 1
8305                               ,p_cost_group_id               => null
8306                               ,p_source_type_id              => null
8307                               ,p_source_header_id            => null -- l_rti_rec.group_id
8308                               ,p_source_name                 => null
8309                               ,p_source_line_id              => NULL
8310                               ,p_source_line_detail_id     => NULL
8311                               -- OPMConvergence
8312                               ,p_sec_quantity          => l_rti_rec.secondary_quantity
8313                               ,p_sec_uom               => l_sec_uom_code
8314                               -- OPMConvergence
8315                               -- *R12* --
8316                               ,p_txn_quantity          => l_rti_rec.quantity
8317                               ,p_txn_uom_code          => l_rti_rec.uom_code
8318                               -- *R12 *--
8319             );
8320 
8321             -- Check the error status from the above call
8322             if x_return_status <> G_RET_STS_SUCCESS Then
8323                --  Review Late Set Appropiate Message
8324                l_progress := 'WMSINB-14353';
8325                RAISE FND_API.G_EXC_ERROR;
8326             End if;
8327 
8328          END IF; --if l_rti_rec.transfer_lpn_id is not null then
8329          --
8330          -- **** UPDATE CURRENT STATUS/INSPECTION STATUS/ SUB /LOC/ORG  OF MSN ******
8331 
8332          if l_serial_control_code not in (1,6) then
8333              l_progress := 'WMSINB-14362';
8334              l_serial_status := get_serial_status(p_transaction_type  => l_rti_rec.transaction_type
8335                          , p_auto_transact_code  => l_rti_rec.auto_transact_code
8336                          , p_parent_transaction_type => l_parent_txn_type
8337                          , p_parent_parent_txn_type  => l_parent_parent_txn_type
8338                          , p_quantity => l_rti_rec.primary_quantity);
8339 
8340              l_progress := 'WMSINB-14369';
8341              l_inspection_status := get_inspection_status(p_transaction_type  => l_rti_rec.transaction_type
8342                          , p_routing_header_id  => l_rti_rec.routing_header_id
8343                          , p_parent_transaction_type => l_parent_txn_type
8344                          , p_parent_parent_txn_type  => l_parent_parent_txn_type
8345                          , p_quantity => l_rti_rec.primary_quantity);
8346 
8347              l_progress := 'WMSINB-14376';
8348              update_serial_status ( p_product_txn_id => p_txn_id
8349                         ,p_item_id => l_rti_rec.item_id
8350                         ,p_organization_id => l_rti_rec.to_organization_id
8351                         ,p_serial_status => l_serial_status
8352                         ,p_inspection_status => l_inspection_status
8353                         ,p_sub => l_rti_rec.subinventory
8354                         ,p_locator_id => l_rti_rec.locator_id
8355                         ,x_return_status => x_return_status
8356                         ,x_msg_count => x_msg_count
8357                         ,x_msg_data => x_msg_data );
8358 
8359              -- Check the error status from the above call
8360              if x_return_status <> G_RET_STS_SUCCESS Then
8361                 --  Review Late Set Appropiate Message
8362                 l_progress := 'WMSINB-14389';
8363                 RAISE FND_API.G_EXC_ERROR;
8364              End if;
8365          End if;
8366 
8367       ELSIF (l_rti_rec.source_document_code IN ('INVENTORY','REQ') AND
8368              l_rti_rec.transaction_type = 'RECEIVE') THEN
8369           l_progress := 'WMSINB-14396';
8370 
8371           IF (l_debug = 1) THEN
8372              print_debug('PROCESS_TXN - Case for Intship/REQ Receive ' ,1);
8373              print_debug('PROCESS_TXN - Case for Intship/REQ Receive lpn_id=  '|| l_rti_rec.lpn_id ,1);
8374              print_debug('PROCESS_TXN - Case for Intship/REQ Receive transfer_lpn_id=  '|| l_rti_rec.transfer_lpn_id ,1);
8375           END IF;
8376 
8377           if l_rti_rec.lpn_id is not null then
8378              -- Review Later
8379              l_progress := 'WMSINB-14400';
8380 
8381              get_serial_lot_ctrl_in_src_org
8382                 (p_shipment_line_id => l_rti_rec.shipment_line_id,
8383                  p_org_id => l_rti_rec.to_organization_id,
8384                  x_serial_control_code => l_from_org_serial_control,
8385                  x_lot_control_code => l_from_org_lot_control,
8386                  x_revision_control_code => l_from_org_rev_control,
8387                  x_return_status => x_return_status,
8388                  x_msg_count => x_msg_count,
8389                  x_msg_data => x_msg_data);
8390 
8391              IF (x_return_status <> g_ret_sts_success) THEN
8392                  --Review Later
8393                  l_progress := 'WMSINB-14413';
8394                  RAISE fnd_api.g_exc_error;
8395              END IF;
8396 
8397              IF ((l_lot_control_code = 2 AND l_from_org_lot_control <> 2)
8398                OR (l_lot_control_code <> 2 AND l_from_org_lot_control = 2)
8399                OR (l_serial_control_code > 1
8400                AND l_from_org_serial_control = 1)
8401                OR (l_serial_control_code = 1
8402                    AND l_from_org_serial_control > 1)
8403                OR (l_from_org_rev_control = 1
8404                    AND l_revision_control_flag = 'Y')
8405                OR (l_from_org_rev_control = 2
8406                    AND l_revision_control_flag = 'N')) THEN
8407               l_progress := 'WMSINB-14423';
8408               l_full_unpack := TRUE;
8409              END IF;
8410 
8411              IF ((l_from_org_lot_control = 2 AND l_lot_control_code = 2)
8412                   OR (l_from_org_serial_control > 1
8413                       AND l_serial_control_code > 1)) THEN
8414                  -- Get total lot qty
8415                  l_progress := 'WMSINB-14431';
8416                  SELECT Nvl(SUM(transaction_quantity),0)
8417                    INTO l_total_lot_qty
8418                    FROM mtl_transaction_lots_temp
8419                    WHERE product_code = 'RCV'
8420                    AND product_transaction_id = l_rti_rec.interface_transaction_id;
8421 
8422                  -- GET the TOTAL SERIAL QTY
8423                  l_progress := 'WMSINB-14439';
8424                  SELECT Nvl(SUM(inv_serial_number_pub.get_serial_diff(fm_serial_number,to_serial_number)),0)
8425                    INTO l_total_serial_qty
8426                    FROM mtl_serial_numbers_temp
8427                    WHERE product_code = 'RCV'
8428                    AND product_transaction_id = l_rti_rec.interface_transaction_id;
8429 
8430                  IF (l_total_lot_qty = 0 AND l_total_serial_qty = 0) THEN
8431                     l_progress := 'WMSINB-14447';
8432                     l_full_unpack := TRUE;
8433                  END IF;
8434 
8435              END IF; --IF ((l_from_org_lot_control = 2 AND l_lot_control_code = 2)
8436 
8437              -- if transfer lpn id is same as LPN Id then we need to do full unpack here
8438              -- otherwise for Express Receipt if you have multiple items in the same lpn then subsequent
8439              -- unpack for next transactions would fail as the LPN's org get changed after the
8440              -- first transaction.
8441              --if (l_rti_rec.lpn_id = nvl(l_rti_rec.transfer_lpn_id,-9999) ) then
8442              --   l_progress := 'WMSINB-14448';
8443              --   l_full_unpack := TRUE;
8444              --   IF (l_debug = 1) THEN
8445              --	    print_debug('PROCESS_TXN - full unpack Flag coming here ' ,1);
8446              --   END IF;
8447              --End if;
8448 
8449              Begin
8450                 -- Get the LPN's Org Here
8451                 select organization_id
8452                   into l_lpn_org
8453                   from wms_license_plate_numbers wlpn
8454                  where wlpn.lpn_id = l_rti_rec.lpn_id;
8455                 --
8456                 l_progress := 'WMSINB-14465';
8457              Exception
8458                 when others then
8459                    l_progress := 'WMSINB-14466';
8460                    l_lpn_org := null;
8461              End;
8462 
8463              IF (l_rti_rec.lpn_id = Nvl(l_rti_rec.transfer_lpn_id,-1)) THEN
8464                 l_auto_unnest_empty_lpns := 2;
8465              ELSE
8466                 l_auto_unnest_empty_lpns := 1;
8467              END IF;
8468 
8469              IF l_full_unpack THEN
8470                  IF (l_debug = 1) THEN
8471                     print_debug('PROCESS_TXN - Performing item unpack of LPN = '|| l_rti_rec.lpn_id ,1);
8472                  END IF;
8473 
8474                  -- CASE FOR EXPRESS RECEIPT FOR MULTIPLE ITEMS
8475                  -- For the First Time for rti rows within the same group this API
8476                  -- Gets called the LPN org and the rti from ORG is same so LPN will
8477                  -- get fully unpacked..
8478                  -- For the second time when it comes the LPN org
8479                  -- and the from ORG of rti will be different and we don't need to
8480                  -- unpack in that case as it already got unpacked once before.
8481                  -- if l_rti_rec.from_organization_id = nvl(l_lpn_org,0) then
8482                  -- Don't need the above case anymore here'
8483 
8484                  -- We should not be doing full unpack. Instead if one of
8485                  -- the conditions used to set l_full_unpack to true is
8486                  -- met then we should null out the lot_number on
8487                  -- wms_lpn_contents and null out the lpn_id on mtl_serial_numbers
8488 
8489                  UPDATE wms_lpn_contents
8490                    SET lot_number = NULL,
8491                    revision = NULL
8492                    WHERE parent_lpn_id = l_rti_rec.lpn_id
8493                    AND inventory_item_id = l_rti_rec.item_id;
8494 
8495                  UPDATE mtl_serial_numbers
8496                    SET lpn_id = NULL
8497                    WHERE inventory_item_id = l_rti_rec.item_id
8498                    AND lpn_id = l_rti_rec.lpn_id;
8499 
8500                  l_progress := 'WMSINB-14468';
8501                  PackUnpack_wrapper( x_return_status                => x_return_status
8502                               ,x_msg_count                   => x_msg_count
8503                               ,x_msg_data                    => x_msg_data
8504                               ,p_lot_control_code            => 1
8505                               ,p_serial_control_code         => 1
8506                               ,p_product_txn_id              => p_txn_id
8507                               ,p_product_code                => 'RCV'
8508                               ,p_lpn_id                      => l_rti_rec.lpn_id
8509                               ,p_content_lpn_id              => null
8510                               ,p_content_item_id             => l_rti_rec.item_id
8511                               ,p_content_item_desc           => l_rti_rec.item_description
8512                               ,p_revision                    => NULL
8513                               ,p_primary_quantity            => l_rti_rec.primary_quantity
8514                               ,p_primary_uom                 => l_primary_uom
8515                               ,p_organization_id             => l_lpn_org
8516                               ,p_operation                   => 2
8517                               ,p_cost_group_id               => null
8518                               ,p_source_type_id              => null
8519                               ,p_source_header_id            => NULL --l_rti_rec.group_id
8520                               ,p_source_name                 => null
8521                               ,p_source_line_id              => NULL
8522                               ,p_source_line_detail_id       => NULL
8523                               ,p_auto_unnest_empty_lpns      => l_auto_unnest_empty_lpns
8524                               -- OPMConvergence
8525                               ,p_sec_quantity          => l_rti_rec.secondary_quantity
8526                               ,p_sec_uom               => l_sec_uom_code
8527                               -- OPMConvergence
8528                               -- Following 2 line were added for bugfix 5488003
8529                               ,p_txn_quantity          => l_rti_rec.quantity
8530                               ,p_txn_uom_code          => l_rti_rec.uom_code
8531                  );
8532                  -- Check the error status from the above call
8533                  if x_return_status <> G_RET_STS_SUCCESS Then
8534                     --  Review Late Set Appropiate Message
8535                     l_progress := 'WMSINB-14469';
8536                     --Do not error out for Int receipts
8537                     x_return_status := g_ret_sts_success;
8538                     --RAISE FND_API.G_EXC_ERROR;
8539                  End if;
8540              ELSE
8541 
8542                  -- Always pass the LPN's org in this case for UNPACK
8543                  -- Otherwise multiple items packed in the same LPN
8544                  -- Causing issues
8545 
8546                  l_progress := 'WMSINB-14500';
8547 
8548                  if l_lpn_org is null then
8549                     l_lpn_org :=  l_rti_rec.from_organization_id;
8550                  End if;
8551 
8552                  PackUnpack_wrapper( x_return_status               => x_return_status
8553                                     ,x_msg_count                   => x_msg_count
8554                                     ,x_msg_data                    => x_msg_data
8555                                     ,p_lot_control_code            => l_lot_control_code
8556                                     ,p_serial_control_code         => l_serial_control_code
8557                                     ,p_product_txn_id              => p_txn_id
8558                                     ,p_product_code                => 'RCV'
8559                                     ,p_lpn_id                      => l_rti_rec.lpn_id
8560                                     ,p_content_lpn_id              => null
8561                                     ,p_content_item_id             => l_rti_rec.item_id
8562                                     ,p_content_item_desc           => l_rti_rec.item_description
8563                                     ,p_revision                    => l_rti_rec.item_revision
8564                                     ,p_primary_quantity            => l_rti_rec.primary_quantity
8565                                     ,p_primary_uom                 => l_primary_uom
8566                                     ,p_organization_id             => l_lpn_org
8567                                     ,p_operation                   => 2
8568                                     ,p_cost_group_id               => null
8569                                     ,p_source_type_id              => null
8570                                     ,p_source_header_id            => NULL --l_rti_rec.group_id
8571                                     ,p_source_name                 => null
8572                                     ,p_source_line_id              => NULL
8573                                     ,p_source_line_detail_id       => NULL
8574                                     ,p_auto_unnest_empty_lpns      => l_auto_unnest_empty_lpns
8575                                     -- OPMConvergence
8576                                     ,p_sec_quantity          => l_rti_rec.secondary_quantity
8577                                     ,p_sec_uom               => l_sec_uom_code
8578                                     -- OPMConvergence
8579                                     -- *R12* --
8580                                     ,p_txn_quantity          => l_rti_rec.quantity
8581                                     ,p_txn_uom_code          => l_rti_rec.uom_code
8582                                     -- *R12 *--
8583                  );
8584                  -- Check the error status from the above call
8585                  if x_return_status <> G_RET_STS_SUCCESS Then
8586                     --  Review Late Set Appropiate Message
8587                     l_progress := 'WMSINB-14501';
8588                     --Do not error out for Int Receipts
8589                     x_return_status := g_ret_sts_success;
8590                     --RAISE FND_API.G_EXC_ERROR;
8591                  End if;
8592              END IF; --IF l_full_unpack THEN
8593 
8594           End if; --l_rti_rec.lpn_id is not null
8595 
8596           l_progress := 'WMSINB-14510';
8597 
8598           if l_rti_rec.transfer_lpn_id is not null then
8599              --
8600              l_progress := 'WMSINB-14514';
8601 
8602              IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
8603                      l_rti_rec.transfer_lpn_id,
8604                      l_transactions_enabled_flag))
8605              THEN
8606                  IF (l_debug = 1) THEN
8607                     print_debug('PROCESS_TXN - Expense and Non Expense Items cannot be Mixed in an LPN',1);
8608                     print_debug('PROCESS_TXN - ORG:LPN:TXNENABLEDFLAG::'||
8609                          l_rti_rec.to_organization_id||':'||l_rti_rec.transfer_lpn_id||
8610                          ':'||l_transactions_enabled_flag,1);
8611                  END IF;
8612                  l_progress := 'WMSINB-14526';
8613 
8614                  --review later
8615                  RAISE fnd_api.g_exc_error;
8616              END IF; --IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
8617 
8618              IF (validate_pjm_commingle(l_rti_rec.to_organization_id,
8619                        l_rti_rec.transfer_lpn_id,
8620                        l_rti_rec.project_id,
8621                        l_rti_rec.task_id))
8622              THEN
8623                  IF (l_debug = 1) THEN
8624                     print_debug('PROCESS_TXN - Project/Task commingling not allowed in LPN:'||l_rti_rec.transfer_lpn_id,1);
8625                  END IF;
8626                  l_progress := 'WMSINB-14532';
8627 
8628                  RAISE fnd_api.g_exc_error;
8629              END IF; --IF (!validate_pjm_commingle(l_rti_rec.to_organization_id,
8630 
8631              IF (l_debug = 1) THEN
8632                  print_debug('PROCESS_TXN - Organization ID:'||l_rti_rec.to_organization_id,1);
8633              END IF;
8634 
8635              --
8636              -- CALL UPDATE TLPN ORGANIZATION LOCATOR FOR WLPN/WLPNC
8637              --
8638 
8639              l_lpn_context := get_lpn_context(p_transaction_type => l_rti_rec.transaction_type
8640                      , p_routing_header_id => l_rti_rec.routing_header_id
8641                      , p_parent_transaction_type => l_parent_txn_type
8642                      , p_parent_parent_txn_type => l_parent_parent_txn_type
8643                      , p_quantity =>	l_rti_rec.primary_quantity
8644                      , p_auto_transact_code => l_rti_rec.auto_transact_code);
8645 
8646              l_progress := 'WMSINB-14548';
8647 
8648              update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
8649                      ,p_sub             => l_rti_rec.SUBINVENTORY
8650                      ,p_locator         => l_rti_rec.LOCATOR_ID
8651                      ,p_lpn_context     => l_lpn_context
8652                      ,p_lpn_id          => l_rti_rec.transfer_lpn_id
8653                      ,x_return_status   => x_return_status
8654                      ,x_msg_count       => x_msg_count
8655                      ,x_msg_data        => x_msg_data ) ;
8656 
8657              l_progress := 'WMSINB-14559';
8658 
8659              -- Check the error status from the above call
8660              if x_return_status <> G_RET_STS_SUCCESS Then
8661                  --  Review Late Set Appropiate Message
8662                  l_progress := 'WMSINB-14564';
8663                  RAISE FND_API.G_EXC_ERROR;
8664              End if;
8665 
8666              IF ( nvl(l_rti_rec.lpn_id,0)  > 0 ) THEN  --6612300
8667                 --Bug 6168447:Update the org of the FROM LPN to that of receiving org.
8668                 --Also null out source_name and source_header_id.
8669                 --This needs to be done only if the LPN is getting unpacked completely.
8670                 SELECT lpn_context
8671                 INTO l_current_lpn_context
8672                 FROM wms_license_plate_numbers
8673                 WHERE lpn_id = l_rti_rec.lpn_id;
8674 
8675                 IF (l_current_lpn_context = 5) THEN
8676                    IF (l_debug = 1) THEN
8677                       print_debug('PROCESS_TXN - Updating the oranization of from lpn to that of receiving org',1);
8678                    END IF;
8679 
8680                    update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
8681                                         ,p_sub             => NULL
8682                                         ,p_locator         => NULL
8683                                         ,p_lpn_context     => 5
8684                                         ,p_source_name     => FND_API.G_MISS_CHAR
8685                                         ,p_lpn_id          => l_rti_rec.lpn_id
8686                                         ,x_return_status   => x_return_status
8687                                         ,x_msg_count       => x_msg_count
8688                                         ,x_msg_data        => x_msg_data ) ;
8689                    -- Check the error status from the above call
8690                    if x_return_status <> G_RET_STS_SUCCESS Then
8691                        --  Review Late Set Appropiate Message
8692                        l_progress := 'WMSINB-14564a';
8693                        RAISE FND_API.G_EXC_ERROR;
8694                    End if;
8695                 END IF;
8696                 --6168447:end
8697              END IF;
8698 
8699           END IF; --if l_rti_rec.transfer_lpn_id is not null then
8700 
8701           -- **** This needs to be done before packunpack as the
8702           -- **** serials are accessed using the current_organization_id = to_organization_id in the
8703           -- **** in wms_container_pvt.packunpack_container
8704           -- **** and it was unable to  fetch serials
8705           -- **** UPDATE CURRENT STATUS/INSPECTION STATUS/ SUB /LOC/ORG  OF MSN ******
8706 
8707           if l_serial_control_code <> 1 then
8708              l_progress := 'WMSINB-14604';
8709              l_serial_status := get_serial_status(p_transaction_type  => l_rti_rec.transaction_type
8710                                , p_auto_transact_code  => l_rti_rec.auto_transact_code
8711                                , p_parent_transaction_type => l_parent_txn_type
8712                                , p_parent_parent_txn_type  => l_parent_parent_txn_type
8713                                , p_quantity => l_rti_rec.primary_quantity);
8714 
8715              l_progress := 'WMSINB-14611';
8716              l_inspection_status := get_inspection_status(p_transaction_type  => l_rti_rec.transaction_type
8717                                , p_routing_header_id  => l_rti_rec.routing_header_id
8718                                , p_parent_transaction_type => l_parent_txn_type
8719                                , p_parent_parent_txn_type  => l_parent_parent_txn_type
8720                                , p_quantity => l_rti_rec.primary_quantity);
8721 
8722              l_progress := 'WMSINB-14618';
8723              update_serial_status ( p_product_txn_id => p_txn_id
8724                               ,p_item_id => l_rti_rec.item_id
8725                               ,p_organization_id => l_rti_rec.to_organization_id
8726                               ,p_serial_status => l_serial_status
8727                               ,p_inspection_status => l_inspection_status
8728                               ,p_sub => l_rti_rec.subinventory
8729                               ,p_locator_id => l_rti_rec.locator_id
8730                               ,x_return_status => x_return_status
8731                               ,x_msg_count => x_msg_count
8732                               ,x_msg_data => x_msg_data );
8733 
8734              -- Check the error status from the above call
8735              if x_return_status <> G_RET_STS_SUCCESS Then
8736                 --  Review Late Set Appropiate Message
8737                 l_progress := 'WMSINB-14631';
8738                 RAISE FND_API.G_EXC_ERROR;
8739              End if;
8740           End if; -- l_serial_control_code not in (1,6) then
8741 
8742           if l_rti_rec.transfer_lpn_id is not null then
8743              PackUnpack_wrapper( x_return_status               => x_return_status
8744                                ,x_msg_count                   => x_msg_count
8745                                ,x_msg_data                    => x_msg_data
8746                                ,p_lot_control_code            => l_lot_control_code
8747                                ,p_serial_control_code         => l_serial_control_code
8748                                ,p_product_txn_id              => p_txn_id
8749                                ,p_product_code                => 'RCV'
8750                                ,p_lpn_id                      => l_rti_rec.transfer_lpn_id
8751                                ,p_content_lpn_id              => null
8752                                ,p_content_item_id             => l_rti_rec.item_id
8753                                ,p_content_item_desc           => l_rti_rec.item_description
8754                                ,p_revision                    => l_rti_rec.item_revision
8755                                ,p_primary_quantity            => l_rti_rec.primary_quantity
8756                                ,p_primary_uom                 => l_primary_uom
8757                                ,p_organization_id             => l_rti_rec.to_organization_id
8758                                ,p_operation                   => 1
8759                                ,p_cost_group_id               => null
8760                                ,p_source_type_id              => null
8761                                ,p_source_header_id            => null -- l_rti_rec.group_id
8762                                ,p_source_name                 => null
8763                                ,p_source_line_id              => NULL
8764                                ,p_source_line_detail_id     => NULL
8765                                -- OPMConvergence
8766                                ,p_sec_quantity          => l_rti_rec.secondary_quantity
8767                                ,p_sec_uom               => l_sec_uom_code
8768                                -- OPMConvergence
8769                                -- *R12* --
8770                                ,p_txn_quantity          => l_rti_rec.quantity
8771                                ,p_txn_uom_code          => l_rti_rec.uom_code
8772                                -- *R12 *--
8773              );
8774 
8775              -- Check the error status from the above call
8776              if x_return_status <> G_RET_STS_SUCCESS Then
8777                  --  Review Late Set Appropiate Message
8778                  l_progress := 'WMSINB-14634';
8779                  RAISE FND_API.G_EXC_ERROR;
8780              End if;
8781 
8782           END IF; --if l_rti_rec.transfer_lpn_id is not null then
8783           --
8784           -- **** UPDATE CURRENT STATUS/INSPECTION STATUS/ SUB /LOC/ORG  OF MSN ******
8785           -- **** This part is done above now
8786 
8787       Else --if (l_lpn_context = G_LPN_CONTEXT_VENDOR and l_rti_rec.transaction_type = 'RECEIVE' ) then
8788 
8789           IF (l_debug = 1) THEN
8790               print_debug('PROCESS_TXN - CASE FOR  RECEIVE TXN ',1);
8791           END IF;
8792 
8793           l_progress := 'WMSINB-14637';
8794 
8795 	 /* Bug 7410777 */
8796 	  IF l_rti_rec.transaction_type IN ('ACCEPT', 'REJECT') THEN
8797 	       IF l_rti_rec.uom_code is null then
8798 		  IF (l_debug = 1) THEN
8799 		    print_debug('PROCESS_TXN - Before Pack Unpack Get uom_code from unit_of_measure as Uom_code is null in rti',1);
8800 		    print_debug('PROCESS_TXN - Before Pack Unpack Unit_of_measure = '|| l_rti_rec.unit_of_measure,1);
8801 		  END IF;
8802 
8803 	          BEGIN
8804 		    SELECT uom_code
8805 		    into l_rti_rec.uom_code
8806 		    FROM mtl_item_uoms_view
8807 		    WHERE organization_id = l_rti_rec.to_organization_id
8808 		    AND inventory_item_id =  l_rti_rec.item_id
8809 		    AND unit_of_measure = l_rti_rec.unit_of_measure;
8810 	          EXCEPTION
8811 		    WHEN OTHERS THEN
8812 		    IF (l_debug = 1) THEN
8813 		       print_debug('PROCESS_TXN : Error retrieving uom_code', 1);
8814 		    END IF;
8815 		    l_progress := 'WMSINB-14638';
8816 		    RAISE fnd_api.g_exc_error;
8817 	          END;
8818 	       END IF;
8819 	    END IF;
8820 	     /* End of fix for Bug 7410777*/
8821 
8822           if l_rti_rec.lpn_id is not null then
8823               l_progress := 'WMSINB-14639';
8824               if (l_rti_rec.lpn_id <> nvl(l_rti_rec.transfer_lpn_id,-9999)) then
8825                  -- UNPACK FLPN FOR RTI.ITEM, MTLT.LOTNUM, MSNT.FMSERNUM, MSNT.TOSERNUM
8826                  l_progress := 'WMSINB-14642';
8827                  IF (l_rti_rec.transaction_type = 'RECEIVE') THEN
8828                      l_unpack_org_id := l_rti_rec.from_organization_id;
8829                  ELSE
8830                      l_unpack_org_id := l_rti_rec.to_organization_id;
8831                  END IF;
8832 
8833                  PackUnpack_wrapper( x_return_status               => x_return_status
8834                                     ,x_msg_count                   => x_msg_count
8835                                     ,x_msg_data                    => x_msg_data
8836                                     ,p_lot_control_code            => l_lot_control_code
8837                                     ,p_serial_control_code         => l_serial_control_code
8838                                     ,p_product_txn_id              => p_txn_id
8839                                     ,p_product_code                => 'RCV'
8840                                     ,p_lpn_id                      => l_rti_rec.lpn_id
8841                                     ,p_content_lpn_id              => null
8842                                     ,p_content_item_id             => l_rti_rec.item_id
8843                                     ,p_content_item_desc           => l_rti_rec.item_description
8844                                     ,p_revision                    => l_rti_rec.item_revision
8845                                     ,p_primary_quantity            => l_rti_rec.primary_quantity
8846                                     ,p_primary_uom                 => l_primary_uom
8847                                     ,p_organization_id             => l_unpack_org_id
8848                                     ,p_operation                   => 2
8849                                     ,p_cost_group_id               => null
8850                                     ,p_source_type_id              => NULL
8851                                     ,p_source_header_id            => l_int_trx_id_for_unpack
8852                                     ,p_source_name                 => l_trx_type_for_unpack
8853                                     ,p_source_line_id              => NULL
8854                                     ,p_source_line_detail_id     => NULL
8855                                     -- OPMConvergence
8856                                     ,p_sec_quantity          => l_rti_rec.secondary_quantity
8857                                     ,p_sec_uom               => l_sec_uom_code
8858                                     -- OPMConvergence
8859                                     -- *R12* --
8860                                     ,p_txn_quantity          => l_rti_rec.quantity
8861                                     ,p_txn_uom_code          => l_rti_rec.uom_code
8862                                     -- *R12 *--
8863                  );
8864                  -- Check the error status from the above call
8865                  if x_return_status <> G_RET_STS_SUCCESS Then
8866                      --  Review Late Set Appropiate Message
8867                      l_progress := 'WMSINB-14675';
8868                      RAISE FND_API.G_EXC_ERROR;
8869                  End if;
8870 
8871               End if; -- END OF FLPN AND TLP DIFFERENT
8872           End if; -- END OF l_rti_rec.lpn_id is not null
8873 
8874           l_progress := 'WMSINB-14682';
8875 
8876           if l_rti_rec.transfer_lpn_id is not null then
8877               l_progress := 'WMSINB-14685';
8878               if (l_rti_rec.transfer_lpn_id <> nvl(l_rti_rec.lpn_id,-9999)) then
8879                  l_progress := 'WMSINB-14687';
8880                  IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
8881                            l_rti_rec.transfer_lpn_id,
8882                            l_transactions_enabled_flag))
8883                  THEN
8884                      IF (l_debug = 1) THEN
8885                         print_debug('PROCESS_TXN - Expense and Non Expense Items cannot be Mixed in an LPN',1);
8886                         print_debug('PROCESS_TXN - ORG:LPN:TXNENABLEDFLAG::'||
8887                                l_rti_rec.to_organization_id||':'||l_rti_rec.transfer_lpn_id||
8888                                ':'||l_transactions_enabled_flag,1);
8889                      END IF;
8890                      l_progress := 'WMSINB-14699';
8891 
8892                      --review later
8893                      RAISE fnd_api.g_exc_error;
8894                  END IF; --IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
8895 
8896                  IF (validate_pjm_commingle(l_rti_rec.to_organization_id,
8897                      l_rti_rec.transfer_lpn_id,
8898                      l_rti_rec.project_id,
8899                      l_rti_rec.task_id))
8900                  THEN
8901                     IF (l_debug = 1) THEN
8902                         print_debug('PROCESS_TXN - Project/Task commingling not allowed in LPN:'||l_rti_rec.transfer_lpn_id,1);
8903                     END IF;
8904                     l_progress := 'WMSINB-14705';
8905 
8906                     RAISE fnd_api.g_exc_error;
8907                  END IF; --IF (!validate_pjm_commingle(l_rti_rec.to_organization_id,
8908 
8909                  l_lpn_context := get_lpn_context(p_transaction_type => l_rti_rec.transaction_type
8910                            , p_routing_header_id => l_rti_rec.routing_header_id
8911                            , p_parent_transaction_type => l_parent_txn_type
8912                            , p_parent_parent_txn_type => l_parent_parent_txn_type
8913                            , p_quantity => l_rti_rec.primary_quantity
8914                            , p_auto_transact_code => l_rti_rec.auto_transact_code);
8915 
8916                  IF (l_rti_rec.transaction_type NOT IN ('ACCEPT','REJECT') OR l_transfer_lpn_context = 5) THEN
8917                      l_progress := 'WMSINB-14714';
8918                      update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
8919                          ,p_sub             => l_rti_rec.SUBINVENTORY
8920                          ,p_locator         => l_rti_rec.LOCATOR_ID
8921                          ,p_lpn_context     => l_lpn_context
8922                          ,p_lpn_id          => l_rti_rec.transfer_lpn_id
8923                          ,x_return_status   => x_return_status
8924                          ,x_msg_count       => x_msg_count
8925                          ,x_msg_data        => x_msg_data ) ;
8926 
8927                      -- Check the error status from the above call
8928                      if x_return_status <> G_RET_STS_SUCCESS Then
8929                         --  Review Late Set Appropiate Message
8930                         l_progress := 'WMSINB-14727';
8931                         RAISE FND_API.G_EXC_ERROR;
8932                      End if;
8933                  END IF; --IF (l_rti_rec.transaction_type NOT IN ('ACCEPT','REJECT') OR l_transfer_lpn_context = 5) THEN
8934                  -- This part is changed to call before packunpack_wrapper
8935                  -- because if issued out serials are repacked then they might have
8936                  -- a different org, so packunpack would fail to pack those serials
8937                  -- unless those serials had the org updated first to the current org
8938 
8939                  if l_serial_control_code <> 1 then
8940                      l_progress := 'WMSINB-14764';
8941                      l_serial_status := get_serial_status(p_transaction_type  => l_rti_rec.transaction_type
8942                              , p_auto_transact_code  => l_rti_rec.auto_transact_code
8943                              , p_parent_transaction_type => l_parent_txn_type
8944                              , p_parent_parent_txn_type  => l_parent_parent_txn_type
8945                              , p_quantity => l_rti_rec.primary_quantity);
8946 
8947                      l_progress := 'WMSINB-14771';
8948                      l_inspection_status := get_inspection_status(p_transaction_type  => l_rti_rec.transaction_type
8949                              , p_routing_header_id  => l_rti_rec.routing_header_id
8950                              , p_parent_transaction_type => l_parent_txn_type
8951                              , p_parent_parent_txn_type  => l_parent_parent_txn_type
8952                              , p_quantity => l_rti_rec.primary_quantity);
8953 
8954                      l_progress := 'WMSINB-14778';
8955                      update_serial_status ( p_product_txn_id => p_txn_id
8956                             ,p_item_id => l_rti_rec.item_id
8957                             ,p_organization_id => l_rti_rec.to_organization_id
8958                             ,p_serial_status => l_serial_status
8959                             ,p_inspection_status => l_inspection_status
8960                             ,p_sub => l_rti_rec.subinventory
8961                             ,p_locator_id => l_rti_rec.locator_id
8962                             ,x_return_status => x_return_status
8963                             ,x_msg_count => x_msg_count
8964                             ,x_msg_data => x_msg_data );
8965 
8966                      -- Check the error status from the above call
8967                      if x_return_status <> G_RET_STS_SUCCESS Then
8968                         --  Review Late Set Appropiate Message
8969                         l_progress := 'WMSINB-14791';
8970                         RAISE FND_API.G_EXC_ERROR;
8971                      End if;
8972                  End if;
8973 
8974                  PackUnpack_wrapper( x_return_status               => x_return_status
8975                                     ,x_msg_count                   => x_msg_count
8976                                     ,x_msg_data                    => x_msg_data
8977                                     ,p_lot_control_code            => l_lot_control_code
8978                                     ,p_serial_control_code         => l_serial_control_code
8979                                     ,p_product_txn_id              => p_txn_id
8980                                     ,p_product_code                => 'RCV'
8981                                     ,p_lpn_id                      => l_rti_rec.transfer_lpn_id
8982                                     ,p_content_lpn_id              => null
8983                                     ,p_content_item_id             => l_rti_rec.item_id
8984                                     ,p_content_item_desc           => l_rti_rec.item_description
8985                                     ,p_revision                    => l_rti_rec.item_revision
8986                                     ,p_primary_quantity            => l_rti_rec.primary_quantity
8987                                     ,p_primary_uom                 => l_primary_uom
8988                                     ,p_organization_id             => l_rti_rec.to_organization_id
8989                                     ,p_operation                   => 1
8990                                     ,p_cost_group_id               => null
8991                                     ,p_source_type_id              => null
8992                                     ,p_source_header_id            => null --l_rti_rec.group_id
8993                                     ,p_source_name                 => null
8994                                     ,p_source_line_id              => NULL
8995                                     ,p_source_line_detail_id     => NULL
8996                                     -- OPMConvergence
8997                                     ,p_sec_quantity          => l_rti_rec.secondary_quantity
8998                                     ,p_sec_uom               => l_sec_uom_code
8999                                     -- OPMConvergence
9000                                     -- *R12* --
9001                                     ,p_txn_quantity          => l_rti_rec.quantity
9002                                     ,p_txn_uom_code          => l_rti_rec.uom_code
9003                                     -- *R12 *--
9004                  );
9005 
9006                  -- Check the error status from the above call
9007                  if x_return_status <> G_RET_STS_SUCCESS Then
9008                      --  Review Late Set Appropiate Message
9009                      l_progress := 'WMSINB-14759';
9010                      RAISE FND_API.G_EXC_ERROR;
9011                  End if;
9012 
9013               ELSE -- when FLPN = TLPN
9014                  l_progress := 'WMSINB-14796';
9015 
9016                  IF(l_debug = 1) THEN
9017                      print_debug('PROCESS_TXN - FLPN AND TLPN ARE SAME:'||l_progress,1);
9018                  END IF;
9019 
9020                  l_lpn_context := get_lpn_context(p_transaction_type => l_rti_rec.transaction_type
9021                                     , p_routing_header_id => l_rti_rec.routing_header_id
9022                                     , p_parent_transaction_type => l_parent_txn_type
9023                                     , p_parent_parent_txn_type => l_parent_parent_txn_type
9024                                     , p_quantity => l_rti_rec.primary_quantity
9025                                     , p_auto_transact_code => l_rti_rec.auto_transact_code);
9026 
9027                  IF (l_rti_rec.transaction_type NOT IN ('ACCEPT','REJECT') ) THEN
9028                      l_progress := 'WMSINB-14809';
9029                      update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
9030                                                  ,p_sub             => l_rti_rec.SUBINVENTORY
9031                                                  ,p_locator         => l_rti_rec.LOCATOR_ID
9032                                                  ,p_lpn_context     => l_lpn_context
9033                                                  ,p_lpn_id          => l_rti_rec.transfer_lpn_id
9034                                                  ,x_return_status   => x_return_status
9035                                                  ,x_msg_count       => x_msg_count
9036                                                  ,x_msg_data        => x_msg_data ) ;
9037 
9038                      -- Check the error status from the above call
9039                      if x_return_status <> G_RET_STS_SUCCESS Then
9040                         --  Review Late Set Appropiate Message
9041                         l_progress := 'WMSINB-14822';
9042                         RAISE FND_API.G_EXC_ERROR;
9043                      End if;
9044                  END IF; --IF (l_rti_rec.transaction_type NOT IN ('ACCEPT','REJECT') ) THEN
9045 
9046                  if l_serial_control_code <> 1 then
9047                      l_progress := 'WMSINB-14828';
9048                      l_serial_status := get_serial_status(p_transaction_type  => l_rti_rec.transaction_type
9049                                       , p_auto_transact_code  => l_rti_rec.auto_transact_code
9050                                       , p_parent_transaction_type => l_parent_txn_type
9051                                       , p_parent_parent_txn_type  => l_parent_parent_txn_type
9052                                       , p_quantity => l_rti_rec.primary_quantity);
9053 
9054                      l_progress := 'WMSINB-14835';
9055                      l_inspection_status := get_inspection_status(p_transaction_type  => l_rti_rec.transaction_type
9056                                       , p_routing_header_id  => l_rti_rec.routing_header_id
9057                                       , p_parent_transaction_type => l_parent_txn_type
9058                                       , p_parent_parent_txn_type  => l_parent_parent_txn_type
9059                                       , p_quantity => l_rti_rec.primary_quantity);
9060 
9061                      l_progress := 'WMSINB-14842';
9062                      update_serial_status ( p_product_txn_id => p_txn_id
9063                                      ,p_item_id => l_rti_rec.item_id
9064                                      ,p_organization_id => l_rti_rec.to_organization_id
9065                                      ,p_serial_status => l_serial_status
9066                                      ,p_inspection_status => l_inspection_status
9067                                      ,p_sub => l_rti_rec.subinventory
9068                                      ,p_locator_id => l_rti_rec.locator_id
9069                                      ,x_return_status => x_return_status
9070                                      ,x_msg_count => x_msg_count
9071                                      ,x_msg_data => x_msg_data );
9072 
9073                      -- Check the error status from the above call
9074                      if x_return_status <> G_RET_STS_SUCCESS Then
9075                         --  Review Late Set Appropiate Message
9076                         l_progress := 'WMSINB-14855';
9077                         RAISE FND_API.G_EXC_ERROR;
9078                      End if;
9079                  End if;-- if l_serial_control_code not in (1,6) then
9080               End if; -- END OF FLPN AND TLPN DIFFERENT
9081           ELSE -- ELSE OF l_rti_rec.transfer_lpn_id is not null
9082               if l_serial_control_code <> 1 then
9083                  l_serial_status := get_serial_status(p_transaction_type  => l_rti_rec.transaction_type
9084                                    , p_auto_transact_code  => l_rti_rec.auto_transact_code
9085                                    , p_parent_transaction_type => l_parent_txn_type
9086                                    , p_parent_parent_txn_type  => l_parent_parent_txn_type
9087                                    , p_quantity => l_rti_rec.primary_quantity);
9088 
9089                  l_inspection_status := get_inspection_status(p_transaction_type  => l_rti_rec.transaction_type
9090                                    , p_routing_header_id  => l_rti_rec.routing_header_id
9091                                    , p_parent_transaction_type => l_parent_txn_type
9092                                    , p_parent_parent_txn_type  => l_parent_parent_txn_type
9093                                    , p_quantity => l_rti_rec.primary_quantity);
9094 
9095                  update_serial_status ( p_product_txn_id => p_txn_id
9096                                   ,p_item_id => l_rti_rec.item_id
9097                                   ,p_organization_id => l_rti_rec.to_organization_id
9098                                   ,p_serial_status => l_serial_status
9099                                   ,p_inspection_status => l_inspection_status
9100                                   ,p_sub => l_rti_rec.subinventory
9101                                   ,p_locator_id => l_rti_rec.locator_id
9102                                   ,x_return_status => x_return_status
9103                                   ,x_msg_count => x_msg_count
9104                                   ,x_msg_data => x_msg_data );
9105 
9106                  -- Check the error status from the above call
9107                  if x_return_status <> G_RET_STS_SUCCESS Then
9108                      --  Review Late Set Appropiate Message
9109                      l_progress := 'WMSINB-14860';
9110                      RAISE FND_API.G_EXC_ERROR;
9111                  End if;
9112               End if;-- if l_serial_control_code not in (1,6) then
9113           End if; -- END OF l_rti_rec.transfer_lpn_id is not null
9114       End if; -- END OF l_lpn_context = G_LPN_CONTEXT_VENDOR and l_rti_rec.txntype = 'RECEIVE'
9115 
9116    elsif ( l_rti_rec.transaction_type = 'DELIVER' and  l_rti_rec.source_document_code = 'RMA' ) then
9117        l_progress := 'WMSINB-14864';
9118        -- UPDATE SERIAL STATUS to 4 for serial control code at SO ISUUE CASE
9119        if l_serial_control_code = 6 then
9120           l_progress := 'WMSINB-14867';
9121           update mtl_serial_numbers msn
9122              set msn.current_status = 4
9123              where msn.inventory_item_id       = l_rti_rec.item_id
9124              and msn.current_organization_id = l_rti_rec.to_organization_id
9125              and exists ( select 1
9126                            from mtl_serial_numbers_temp msnt
9127                            where msnt.product_code = 'RCV'
9128                              and msnt.product_transaction_id = p_txn_id
9129                              and msn.serial_number between msnt.fm_serial_number and msnt.to_serial_number
9130                              AND Length(msn.serial_number) = Length(msnt.fm_serial_number)
9131                              AND length(msnt.fm_serial_number)=Length(Nvl(msnt.to_serial_number,msnt.fm_serial_number))  --BUG 3818544
9132                         )
9133           ;
9134        End if;
9135    elsif ( l_rti_rec.transaction_type = 'SHIP' and  l_rti_rec.source_document_code = 'PO' ) then
9136        -- PACK FLPN
9137        --
9138        -- CHECK WHEtheR WE NEED TO POPULATE SOURCE_NAME AS SHIPMENT NUM HERE
9139        --
9140        l_progress := 'WMSINB-14885';
9141 
9142        IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
9143                        l_rti_rec.lpn_id,
9144                        l_transactions_enabled_flag))
9145        THEN
9146           IF (l_debug = 1) THEN
9147               print_debug('PROCESS_TXN - Expense and Non Expense Items cannot be Mixed in an LPN',1);
9148               print_debug('PROCESS_TXN - ORG:LPN:TXNENABLEDFLAG::'||
9149                   l_rti_rec.to_organization_id||':'||l_rti_rec.lpn_id||
9150                   ':'||l_transactions_enabled_flag,1);
9151           END IF;
9152           l_progress := 'WMSINB-14897';
9153 
9154           --review later
9155           RAISE fnd_api.g_exc_error;
9156        END IF; --IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
9157 
9158        l_progress := 'WMSINB-14903';
9159 
9160        IF l_rti_rec.lpn_id IS NOT NULL THEN
9161           l_progress := 'WMSINB-14904';
9162           l_lpn_context := get_lpn_context(p_transaction_type => l_rti_rec.transaction_type
9163                            , p_routing_header_id => l_rti_rec.routing_header_id
9164                            , p_parent_transaction_type => l_parent_txn_type
9165                            , p_parent_parent_txn_type => l_parent_parent_txn_type
9166                            , p_quantity =>	l_rti_rec.primary_quantity
9167                            , p_auto_transact_code => l_rti_rec.auto_transact_code);
9168 
9169           l_progress := 'WMSINB-14911';
9170           update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
9171                            ,p_sub             => l_rti_rec.SUBINVENTORY
9172                            ,p_locator         => l_rti_rec.LOCATOR_ID
9173                            ,p_lpn_context     => l_lpn_context
9174                            ,p_lpn_id          => l_rti_rec.lpn_id
9175                            ,x_return_status   => x_return_status
9176                            ,x_msg_count       => x_msg_count
9177                            ,x_msg_data        => x_msg_data
9178                            ,p_source_name     => l_rti_rec.shipment_num
9179                            ,p_source_header_id => l_rti_rec.shipment_header_id) ;
9180 
9181           -- Check the error status from the above call
9182           if x_return_status <> G_RET_STS_SUCCESS Then
9183               --  Review Late Set Appropiate Message
9184               l_progress := 'WMSINB-14926';
9185               RAISE FND_API.G_EXC_ERROR;
9186           End if;
9187 
9188           PackUnpack_wrapper( x_return_status               => x_return_status
9189                            ,x_msg_count                   => x_msg_count
9190                            ,x_msg_data                    => x_msg_data
9191                            ,p_lot_control_code            => l_lot_control_code
9192                            ,p_serial_control_code         => l_serial_control_code
9193                            ,p_product_txn_id              => p_txn_id
9194                            ,p_product_code                => 'RCV'
9195                            ,p_lpn_id                      => l_rti_rec.lpn_id
9196                            ,p_content_lpn_id              => null
9197                            ,p_content_item_id             => l_rti_rec.item_id
9198                            ,p_content_item_desc           => l_rti_rec.item_description
9199                            ,p_revision                    => l_rti_rec.item_revision
9200                            ,p_primary_quantity            => l_rti_rec.primary_quantity
9201                            ,p_primary_uom                 => l_primary_uom
9202                            ,p_organization_id             => l_rti_rec.to_organization_id
9203                            ,p_operation                   => 1
9204                            ,p_cost_group_id               => null
9205                            ,p_source_type_id              => 1
9206                            ,p_source_header_id            => null --l_rti_rec.shipment_header_id
9207                            ,p_source_name                 => null -- l_rti_rec.shipment_num
9208                            ,p_source_line_id              => NULL
9209                            ,p_source_line_detail_id       => NULL
9210                            -- OPMConvergence
9211                            ,p_sec_quantity          => l_rti_rec.secondary_quantity
9212                            ,p_sec_uom               => l_sec_uom_code
9213                            -- OPMConvergence
9214                            -- *R12* --
9215                            ,p_txn_quantity          => l_rti_rec.quantity
9216                            ,p_txn_uom_code          => l_rti_rec.uom_code
9217                            -- *R12 *--
9218           );
9219 
9220           -- Check the error status from the above call
9221           if x_return_status <> G_RET_STS_SUCCESS Then
9222               --  Review Late Set Appropiate Message
9223               l_progress := 'WMSINB-14957';
9224               RAISE FND_API.G_EXC_ERROR;
9225           End if;
9226        End if; --l_rti_rec.lpn_id IS NOT NULL THEN
9227 
9228        --Serial status update is required at this point - bug 3487843
9229        if l_serial_control_code not in (1,6) then
9230           l_serial_status := get_serial_status(p_transaction_type  => l_rti_rec.transaction_type
9231                             , p_auto_transact_code  => l_rti_rec.auto_transact_code
9232                             , p_parent_transaction_type => l_parent_txn_type
9233                             , p_parent_parent_txn_type  => l_parent_parent_txn_type
9234                             , p_quantity => l_rti_rec.primary_quantity);
9235 
9236 
9237 
9238           --Bug #4337726
9239           --For a ship transaction with auto transact code 'RECEIVE', set
9240           --inspection status based on routing header id.
9241           IF ( (NVL(l_rti_rec.auto_transact_code, '@#$#$@') = 'RECEIVE') AND
9242                (NVL(l_rti_rec.routing_header_id, 1) = 2)
9243              ) THEN
9244             l_inspection_status := 1;
9245           ELSE
9246             l_inspection_status := null;
9247           END IF;
9248 
9249 
9250           update_serial_status ( p_product_txn_id => p_txn_id
9251                            ,p_item_id => l_rti_rec.item_id
9252                            ,p_organization_id => l_rti_rec.to_organization_id
9253                            ,p_serial_status => l_serial_status
9254                            ,p_inspection_status => l_inspection_status
9255                            ,p_sub => l_rti_rec.subinventory
9256                            ,p_locator_id => l_rti_rec.locator_id
9257                            ,x_return_status => x_return_status
9258                            ,x_msg_count => x_msg_count
9259                            ,x_msg_data => x_msg_data );
9260 
9261           -- Check the error status from the above call
9262           if x_return_status <> G_RET_STS_SUCCESS Then
9263               --  Review Late Set Appropiate Message
9264               l_progress := 'WMSINB-14960';
9265               RAISE FND_API.G_EXC_ERROR;
9266           End if;
9267        End if; --if l_serial_control_code not in (1,6) then
9268 
9269        BEGIN
9270           SELECT po_header_id
9271              INTO l_po_header_id
9272              FROM po_line_locations_all
9273              WHERE line_location_id = l_rti_rec.po_line_location_id;
9274        EXCEPTION
9275           WHEN OTHERS THEN
9276               IF (l_debug = 1) THEN
9277                  print_debug('Error retrieving po_header_id',1);
9278               END IF;
9279        END ;
9280 
9281        IF (l_debug = 1) THEN
9282           print_debug('PROCESS_TXN - IMPORT ASN. CALLING RSV API',1);
9283           print_debug('l_rti_rec.transaction_type     => '||l_rti_rec.transaction_type,1);
9284           print_debug('l_rti_rec.source_document_code => '||l_rti_rec.source_document_code,1);
9285           print_debug('l_rti_rec.to_organization_id   => '||l_rti_rec.to_organization_id,1);
9286           print_debug('l_rti_rec.item_id              => '||l_rti_rec.item_id,1);
9287           print_debug('l_rti_rec.item_revision        => '||l_rti_rec.item_revision,1);
9288           print_debug('l_rti_rec.project_id           => '||l_rti_rec.project_id,1);
9289           print_debug('l_rti_rec.task_id              => '||l_rti_rec.task_id,1);
9290           print_debug('l_rti_rec.primary_uom_code     => '||l_primary_uom,1);
9291           print_debug('l_rti_rec.primary_quantity     => '||l_rti_rec.primary_quantity,1);
9292           print_debug('l_po_header_id                 => '||l_po_header_id,1);
9293           print_debug('l_rti_rec.po_line_location_id  => '||l_rti_rec.po_line_location_id,1);
9294           print_debug('l_rti_rec.shipment_line_id     => '||l_rti_rec.shipment_line_id,1);
9295           print_debug('l_rti_rec.asn_line_flag     => '||l_asn_line_flag,1);
9296        END IF;
9297 
9298        /* Bug 5365065.
9299        * In the procedure maintain_reservation, we check whether l_asn_line_flag is Y or N.
9300        * But the table l_mol_res_in was not populated with asn_line_flag. Populated the table
9301        * with l_asn_line_flag.
9302        */
9303        l_mol_res_in(1).transaction_type       := l_rti_rec.transaction_type;
9304        l_mol_res_in(1).source_document_code   := l_rti_rec.source_document_code;
9305        l_mol_res_in(1).organization_id        := l_rti_rec.to_organization_id;
9306        l_mol_res_in(1).inventory_item_id      := l_rti_rec.item_id;
9307        l_mol_res_in(1).item_revision          := l_rti_rec.item_revision;
9308        l_mol_res_in(1).project_id             := l_rti_rec.project_id;
9309        l_mol_res_in(1).task_id                := l_rti_rec.task_id;
9310        l_mol_res_in(1).primary_uom_code       := l_primary_uom;
9311        l_mol_res_in(1).primary_qty            := l_rti_rec.primary_quantity;
9312        l_mol_res_in(1).po_header_id           := l_po_header_id;
9313        l_mol_res_in(1).po_line_location_id    := l_rti_rec.po_line_location_id;
9314        l_mol_res_in(1).shipment_line_id       := l_rti_rec.shipment_line_id;
9315        l_mol_res_in(1).asn_line_flag          := l_asn_line_flag;
9316 
9317        INV_RCV_RESERVATION_UTIL.maintain_reservations
9318          (x_return_status => x_return_status
9319           ,x_msg_count     => x_msg_count
9320           ,x_msg_data      => x_msg_data
9321           ,x_mol_tb        => l_mol_res_out
9322           ,p_cas_mol_tb    => l_mol_res_in
9323           );
9324 
9325        IF (l_debug = 1) THEN
9326           print_debug('PROCESS_TXN - rsv api returns:'||x_return_status,1);
9327        END IF;
9328 
9329        IF (x_return_status <> g_ret_sts_success) THEN
9330           l_progress := 'WMSINB-14998';
9331           RAISE FND_API.G_EXC_ERROR;
9332        END IF;
9333 
9334    elsif ( l_rti_rec.transaction_type = 'CORRECT' and ( l_parent_txn_type not in ( 'DELIVER','RETURN TO RECEIVING')
9335           and NOT (l_parent_txn_type in ('RETURN TO VENDOR', 'RETURN TO CUSTOMER') and l_parent_parent_txn_type =
9336               'DELIVER' )  )
9337          ) then
9338        l_progress := 'WMSINB-14965';
9339        if l_rti_rec.primary_quantity  < 0 then
9340           if l_rti_rec.transfer_lpn_id is not null then
9341              -- fix for bug 5530130: if l_rti_rec.transfer_lpn_id <> nvl(l_rti_rec.lpn_id,-9999 ) then
9342              l_progress := 'WMSINB-14969';
9343              -- UNPACK TLPN FOR RTI.ITEM, MTLT.LOTNUM, MSNT.FMSERNUM, MSNT.TOSERNUM
9344              PackUnpack_wrapper( x_return_status               => x_return_status
9345                                  ,x_msg_count                   => x_msg_count
9346                                  ,x_msg_data                    => x_msg_data
9347                                  ,p_lot_control_code            => l_lot_control_code
9348                                  ,p_serial_control_code         => l_serial_control_code
9349                                  ,p_product_txn_id              => p_txn_id
9350                                  ,p_product_code                => 'RCV'
9351                                  ,p_lpn_id                      => l_rti_rec.transfer_lpn_id
9352                                  ,p_content_lpn_id              => null
9353                                  ,p_content_item_id             => l_rti_rec.item_id
9354                                  ,p_content_item_desc           => l_rti_rec.item_description
9355                                  ,p_revision                    => l_rti_rec.item_revision
9356                                  ,p_primary_quantity            => Abs(l_rti_rec.primary_quantity)
9357                                  ,p_primary_uom                 => l_primary_uom
9358                                  ,p_organization_id             => l_rti_rec.to_organization_id
9359                                  ,p_operation                   => 2
9360                                  ,p_cost_group_id               => null
9361                                  ,p_source_type_id              => null
9362                                  ,p_source_header_id            => l_int_trx_id_for_unpack
9363                                  ,p_source_name                 => l_trx_type_for_unpack
9364                                  ,p_source_line_id              => NULL
9365                                  ,p_source_line_detail_id       => NULL
9366                                  -- OPMConvergence
9367                                  ,p_sec_quantity          => ABS(l_rti_rec.secondary_quantity)
9368                                  ,p_sec_uom               => l_sec_uom_code
9369                                  -- OPMConvergence
9370                                  -- *R12* --
9371                                  ,p_txn_quantity          => ABS(l_rti_rec.quantity)
9372                                  ,p_txn_uom_code          => l_rti_rec.uom_code
9373                                  -- *R12 *--
9374              );
9375 
9376              -- Check the error status from the above call
9377              if x_return_status <> G_RET_STS_SUCCESS Then
9378                   --  Review Late Set Appropiate Message
9379                   l_progress := 'WMSINB-14998';
9380                   RAISE FND_API.G_EXC_ERROR;
9381              End if;
9382              -- fix for bug 5530130:End if;  -- END OF FLPN and TLPN Different
9383           End if; -- END OF l_rti_rec.transfer_lpn_id is not null
9384 
9385           l_progress := 'WMSINB-15004';
9386 
9387           if l_rti_rec.lpn_id is not null then
9388               -- fix for bug 5530130:if l_rti_rec.lpn_id <> nvl(l_rti_rec.transfer_lpn_id,-9999) then
9389               l_progress := 'WMSINB-15008';
9390 
9391               IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
9392                            l_rti_rec.lpn_id,
9393                            l_transactions_enabled_flag))
9394               THEN
9395                   IF (l_debug = 1) THEN
9396                      print_debug('PROCESS_TXN - Expense and Non Expense Items cannot be Mixed in an LPN',1);
9397                      print_debug('PROCESS_TXN - ORG:LPN:TXNENABLEDFLAG::'||
9398                             l_rti_rec.to_organization_id||':'||l_rti_rec.lpn_id||
9399                             ':'||l_transactions_enabled_flag,1);
9400                   END IF;
9401                   l_progress := 'WMSINB-15020';
9402 
9403                   --review later
9404                   RAISE fnd_api.g_exc_error;
9405               END IF; --IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
9406 
9407               IF (validate_pjm_commingle(l_rti_rec.to_organization_id,
9408                      l_rti_rec.lpn_id,
9409                      l_rti_rec.project_id,
9410                      l_rti_rec.task_id))
9411               THEN
9412                   IF (l_debug = 1) THEN
9413                      print_debug('PROCESS_TXN - Project/Task commingling not allowed in LPN:'||l_rti_rec.lpn_id,1);
9414                   END IF;
9415                   l_progress := 'WMSINB-15026';
9416 
9417                   RAISE fnd_api.g_exc_error;
9418               END IF; --IF (!validate_pjm_commingle(l_rti_rec.to_organization_id,
9419 
9420               l_lpn_context := get_lpn_context(p_transaction_type => l_rti_rec.transaction_type
9421                               , p_routing_header_id => l_rti_rec.routing_header_id
9422                               , p_parent_transaction_type => l_parent_txn_type
9423                               , p_parent_parent_txn_type => l_parent_parent_txn_type
9424                               , p_quantity => l_rti_rec.primary_quantity
9425                               , p_auto_transact_code => l_rti_rec.auto_transact_code);
9426 
9427               l_progress := 'WMSINB-15034';
9428               update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
9429                             ,p_sub             => l_rti_rec.SUBINVENTORY
9430                             ,p_locator         => l_rti_rec.LOCATOR_ID
9431                             ,p_lpn_context     => l_lpn_context
9432                             ,p_lpn_id          => l_rti_rec.lpn_id
9433                             ,x_return_status   => x_return_status
9434                             ,x_msg_count       => x_msg_count
9435                             ,x_msg_data        => x_msg_data ) ;
9436 
9437               -- Check the error status from the above call
9438               if x_return_status <> G_RET_STS_SUCCESS Then
9439                   --  Review Late Set Appropiate Message
9440                   l_progress := 'WMSINB-15047';
9441                   RAISE FND_API.G_EXC_ERROR;
9442               End if;
9443 
9444               PackUnpack_wrapper( x_return_status               => x_return_status
9445                               ,x_msg_count                   => x_msg_count
9446                               ,x_msg_data                    => x_msg_data
9447                               ,p_lot_control_code            => l_lot_control_code
9448                               ,p_serial_control_code         => l_serial_control_code
9449                               ,p_product_txn_id              => p_txn_id
9450                               ,p_product_code                => 'RCV'
9451                               ,p_lpn_id                      => l_rti_rec.lpn_id
9452                               ,p_content_lpn_id              => null
9453                               ,p_content_item_id             => l_rti_rec.item_id
9454                               ,p_content_item_desc           => l_rti_rec.item_description
9455                               ,p_revision                    => l_rti_rec.item_revision
9456                               ,p_primary_quantity            => Abs(l_rti_rec.primary_quantity)
9457                               ,p_primary_uom                 => l_primary_uom
9458                               ,p_organization_id             => l_rti_rec.to_organization_id
9459                               ,p_operation                   => 1
9460                               ,p_cost_group_id               => null
9461                               ,p_source_type_id              => null
9462                               ,p_source_header_id            => null -- l_rti_rec.group_id
9463                               ,p_source_name                 => null
9464                               ,p_source_line_id              => NULL
9465                               ,p_source_line_detail_id       => NULL
9466                               -- OPMConvergence
9467                               ,p_sec_quantity          => Abs(l_rti_rec.secondary_quantity)
9468                               ,p_sec_uom               => l_sec_uom_code
9469                               -- OPMConvergence
9470                               -- *R12* --
9471                               ,p_txn_quantity          => Abs(l_rti_rec.quantity)
9472                               ,p_txn_uom_code          => l_rti_rec.uom_code
9473                               -- *R12 *--
9474               );
9475 
9476               -- Check the error status from the above call
9477               if x_return_status <> G_RET_STS_SUCCESS Then
9478                   --  Review Late Set Appropiate Message
9479                   l_progress := 'WMSINB-15078';
9480                   RAISE FND_API.G_EXC_ERROR;
9481               End if;
9482 
9483               -- fix for bug 5530130: END IF; --Endif of FLPN <> TLPN
9484           End if; -- END OF l_rti_rec.lpn_id is not null
9485           l_progress := 'WMSINB-15082';
9486           if l_serial_control_code not in (1,6) then
9487 
9488               l_progress := 'WMSINB-15085';
9489               l_serial_status := get_serial_status(p_transaction_type  => l_rti_rec.transaction_type
9490                             , p_auto_transact_code  => l_rti_rec.auto_transact_code
9491                             , p_parent_transaction_type => l_parent_txn_type
9492                             , p_parent_parent_txn_type  => l_parent_parent_txn_type
9493                             , p_quantity => l_rti_rec.primary_quantity);
9494 
9495               l_progress := 'WMSINB-15092';
9496               l_inspection_status := get_inspection_status(p_transaction_type  => l_rti_rec.transaction_type
9497                             , p_routing_header_id  => l_rti_rec.routing_header_id
9498                             , p_parent_transaction_type => l_parent_txn_type
9499                             , p_parent_parent_txn_type  => l_parent_parent_txn_type
9500                             , p_quantity => l_rti_rec.primary_quantity);
9501 
9502               l_progress := 'WMSINB-15099';
9503 
9504               update_serial_status ( p_product_txn_id => p_txn_id
9505                             ,p_item_id => l_rti_rec.item_id
9506                             ,p_organization_id => l_rti_rec.to_organization_id
9507                             ,p_serial_status => l_serial_status
9508                             ,p_inspection_status => l_inspection_status
9509                             ,p_sub => l_rti_rec.subinventory
9510                             ,p_locator_id => l_rti_rec.locator_id
9511                             ,x_return_status => x_return_status
9512                             ,x_msg_count => x_msg_count
9513                             ,x_msg_data => x_msg_data );
9514 
9515               -- Check the error status from the above call
9516               if x_return_status <> G_RET_STS_SUCCESS Then
9517                  --  Review Late Set Appropiate Message
9518                  l_progress := 'WMSINB-15113';
9519                  RAISE FND_API.G_EXC_ERROR;
9520               End if;
9521           End if; --if l_serial_control_code not in (1,6) then
9522        Else -- QTY > 0
9523           l_progress := 'WMSINB-15120';
9524           if l_rti_rec.lpn_id is not null then
9525               if l_rti_rec.lpn_id <> nvl(l_rti_rec.transfer_lpn_id,-9999) then
9526                  -- UNPACK FLPN FOR RTI.ITEM, MTLT.LOTNUM, MSNT.FMSERNUM, MSNT.TOSERNUM
9527                  l_progress := 'WMSINB-15124';
9528                  PackUnpack_wrapper( x_return_status            => x_return_status
9529                                     ,x_msg_count                   => x_msg_count
9530                                     ,x_msg_data                    => x_msg_data
9531                                     ,p_lot_control_code            => l_lot_control_code
9532                                     ,p_serial_control_code         => l_serial_control_code
9533                                     ,p_product_txn_id              => p_txn_id
9534                                     ,p_product_code                => 'RCV'
9535                                     ,p_lpn_id                      => l_rti_rec.lpn_id
9536                                     ,p_content_lpn_id              => null
9537                                     ,p_content_item_id             => l_rti_rec.item_id
9538                                     ,p_content_item_desc           => l_rti_rec.item_description
9539                                     ,p_revision                    => l_rti_rec.item_revision
9540                                     ,p_primary_quantity            => l_rti_rec.primary_quantity
9541                                     ,p_primary_uom                 => l_primary_uom
9542                                     ,p_organization_id             => l_rti_rec.to_organization_id
9543                                     ,p_operation                   => 2
9544                                     ,p_cost_group_id               => null
9545                                     ,p_source_type_id              => null
9546                                     ,p_source_header_id            => l_int_trx_id_for_unpack
9547                                     ,p_source_name                 => l_trx_type_for_unpack
9548                                     ,p_source_line_id              => NULL
9549                                     ,p_source_line_detail_id       => NULL
9550                                     -- OPMConvergence
9551                                     ,p_sec_quantity          => l_rti_rec.secondary_quantity
9552                                     ,p_sec_uom               => l_sec_uom_code
9553                                     -- OPMConvergence
9554                                     -- *R12* --
9555                                     ,p_txn_quantity          => l_rti_rec.quantity
9556                                     ,p_txn_uom_code          => l_rti_rec.uom_code
9557                                     -- *R12 *--
9558                  );
9559 
9560                  -- Check the error status from the above call
9561                  if x_return_status <> G_RET_STS_SUCCESS Then
9562                      --  Review Late Set Appropiate Message
9563                      l_progress := 'WMSINB-15152';
9564                      RAISE FND_API.G_EXC_ERROR;
9565                  End if;
9566 
9567               End if; -- END OF FLPN and TLPN different
9568           End if; -- END OF l_rti_rec.lpn_id is not null then
9569 
9570           if l_rti_rec.transfer_lpn_id is not null then
9571               if l_rti_rec.transfer_lpn_id <> nvl(l_rti_rec.lpn_id,-9999 ) then
9572                  l_progress := 'WMSINB-15161';
9573 
9574                  IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
9575                            l_rti_rec.transfer_lpn_id,
9576                            l_transactions_enabled_flag))
9577                  THEN
9578                      IF (l_debug = 1) THEN
9579                         print_debug('PROCESS_TXN - Expense and Non Expense Items cannot be Mixed in an LPN',1);
9580                         print_debug('PROCESS_TXN - ORG:LPN:TXNENABLEDFLAG::'||
9581                                l_rti_rec.to_organization_id||':'||l_rti_rec.transfer_lpn_id||
9582                                ':'||l_transactions_enabled_flag,1);
9583                      END IF;
9584                      l_progress := 'WMSINB-15173';
9585 
9586                      --review later
9587                      RAISE fnd_api.g_exc_error;
9588                  END IF; --IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
9589 
9590                  IF (validate_pjm_commingle(l_rti_rec.to_organization_id,
9591                      l_rti_rec.transfer_lpn_id,
9592                      l_rti_rec.project_id,
9593                      l_rti_rec.task_id))
9594                  THEN
9595                      IF (l_debug = 1) THEN
9596                         print_debug('PROCESS_TXN - Project/Task commingling not allowed in LPN:'||l_rti_rec.transfer_lpn_id,1);
9597                      END IF;
9598                      l_progress := 'WMSINB-15179';
9599 
9600                      RAISE fnd_api.g_exc_error;
9601                  END IF; --IF (!validate_pjm_commingle(l_rti_rec.to_organization_id,
9602 
9603                  l_lpn_context := get_lpn_context(p_transaction_type => l_rti_rec.transaction_type
9604                                  , p_routing_header_id => l_rti_rec.routing_header_id
9605                                  , p_parent_transaction_type => l_parent_txn_type
9606                                  , p_parent_parent_txn_type => l_parent_parent_txn_type
9607                                  , p_quantity => l_rti_rec.primary_quantity
9608                                  , p_auto_transact_code => l_rti_rec.auto_transact_code);
9609 
9610                  l_progress := 'WMSINB-15187';
9611 
9612                  update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
9613                                ,p_sub             => l_rti_rec.SUBINVENTORY
9614                                ,p_locator         => l_rti_rec.LOCATOR_ID
9615                                ,p_lpn_context     => l_lpn_context
9616                                ,p_lpn_id          => l_rti_rec.transfer_lpn_id
9617                                ,x_return_status   => x_return_status
9618                                ,x_msg_count       => x_msg_count
9619                                ,x_msg_data        => x_msg_data ) ;
9620 
9621                  -- Check the error status from the above call
9622                  if x_return_status <> G_RET_STS_SUCCESS Then
9623                      --  Review Late Set Appropiate Message
9624                      l_progress := 'WMSINB-15201';
9625                      RAISE FND_API.G_EXC_ERROR;
9626                  End if;
9627 
9628                  PackUnpack_wrapper( x_return_status               => x_return_status
9629                                     ,x_msg_count                   => x_msg_count
9630                                     ,x_msg_data                    => x_msg_data
9631                                     ,p_lot_control_code            => l_lot_control_code
9632                                     ,p_serial_control_code         => l_serial_control_code
9633                                     ,p_product_txn_id              => p_txn_id
9634                                     ,p_product_code                => 'RCV'
9635                                     ,p_lpn_id                      => l_rti_rec.transfer_lpn_id
9636                                     ,p_content_lpn_id              => null
9637                                     ,p_content_item_id             => l_rti_rec.item_id
9638                                     ,p_content_item_desc           => l_rti_rec.item_description
9639                                     ,p_revision                    => l_rti_rec.item_revision
9640                                     ,p_primary_quantity            => l_rti_rec.primary_quantity
9641                                     ,p_primary_uom                 => l_primary_uom
9642                                     ,p_organization_id             => l_rti_rec.to_organization_id
9643                                     ,p_operation                   => 1
9644                                     ,p_cost_group_id               => null
9645                                     ,p_source_type_id              => null
9646                                     ,p_source_header_id            => null -- l_rti_rec.group_id
9647                                     ,p_source_name                 => null
9648                                     ,p_source_line_id              => NULL
9649                                     ,p_source_line_detail_id       => NULL
9650                                     -- OPMConvergence
9651                                     ,p_sec_quantity          => l_rti_rec.secondary_quantity
9652                                     ,p_sec_uom               => l_sec_uom_code
9653                                     -- OPMConvergence
9654                                     -- *R12* --
9655                                     ,p_txn_quantity          => l_rti_rec.quantity
9656                                     ,p_txn_uom_code          => l_rti_rec.uom_code
9657                                     -- *R12 *--
9658                  );
9659 
9660                  -- Check the error status from the above call
9661                  if x_return_status <> G_RET_STS_SUCCESS Then
9662                      --  Review Late Set Appropiate Message
9663                      l_progress := 'WMSINB-15232';
9664                      RAISE FND_API.G_EXC_ERROR;
9665                  End if;
9666 
9667               End if; -- END OF FLPN and TLPN different
9668           End if; -- END OF l_rti_rec.transfer_lpn_id is not null
9669 
9670           if l_serial_control_code not in (1,6) then
9671               l_serial_status := get_serial_status(p_transaction_type  => l_rti_rec.transaction_type
9672                                , p_auto_transact_code  => l_rti_rec.auto_transact_code
9673                                , p_parent_transaction_type => l_parent_txn_type
9674                                , p_parent_parent_txn_type  => l_parent_parent_txn_type
9675                                , p_quantity => l_rti_rec.primary_quantity);
9676 
9677               l_inspection_status := get_inspection_status(p_transaction_type  => l_rti_rec.transaction_type
9678                                , p_routing_header_id  => l_rti_rec.routing_header_id
9679                                , p_parent_transaction_type => l_parent_txn_type
9680                                , p_parent_parent_txn_type  => l_parent_parent_txn_type
9681                                , p_quantity => l_rti_rec.primary_quantity);
9682 
9683               l_progress := 'WMSINB-15249';
9684               update_serial_status ( p_product_txn_id => p_txn_id
9685                                ,p_item_id => l_rti_rec.item_id
9686                                ,p_organization_id => l_rti_rec.to_organization_id
9687                                ,p_serial_status => l_serial_status
9688                                ,p_inspection_status => l_inspection_status
9689                                ,p_sub => l_rti_rec.subinventory
9690                                ,p_locator_id => l_rti_rec.locator_id
9691                                ,x_return_status => x_return_status
9692                                ,x_msg_count => x_msg_count
9693                                ,x_msg_data => x_msg_data );
9694 
9695               -- Check the error status from the above call
9696               if x_return_status <> G_RET_STS_SUCCESS Then
9697                  --  Review Late Set Appropiate Message
9698                  l_progress := 'WMSINB-15262';
9699                  RAISE FND_API.G_EXC_ERROR;
9700               End if;
9701           End if; --if l_serial_control_code not in (1,6) then
9702 
9703        End if; -- END OF l_rti.rec.primary_quantity  < 0
9704        --
9705        --BUG 5095399 (FP of BUG 5095182)
9706    elsif ((l_rti_rec.transaction_type = 'CORRECT') and  (l_parent_txn_type = 'DELIVER')) THEN
9707        IF (l_rti_rec.primary_quantity < 0) and  (l_rti_rec.lpn_id is not null) THEN
9708 
9709           IF (l_debug = 1) THEN
9710             print_debug('PROCESS_TXN - Transaction type CORRECT and Parent DELIVER'||l_lpn_context,1);
9711           END IF;
9712 
9713           l_progress := 'WMSINB-15265';
9714 
9715           l_lpn_context := get_lpn_context(p_transaction_type => l_rti_rec.transaction_type
9716                           , p_routing_header_id => l_rti_rec.routing_header_id
9717                           , p_parent_transaction_type => l_parent_txn_type
9718                           , p_parent_parent_txn_type => l_parent_parent_txn_type
9719                           , p_quantity => l_rti_rec.primary_quantity
9720                           , p_auto_transact_code => l_rti_rec.auto_transact_code);
9721 
9722           l_progress := 'WMSINB-15266';
9723           IF (l_debug = 1) THEN
9724              print_debug('PROCESS_TXN - l_lpn_context='||l_lpn_context,1);
9725           END IF;
9726 
9727           update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
9728                                         ,p_sub             => l_rti_rec.SUBINVENTORY
9729                                         ,p_locator         => l_rti_rec.LOCATOR_ID
9730                                         ,p_lpn_context     => l_lpn_context
9731                                         ,p_lpn_id          => l_rti_rec.lpn_id
9732                                         ,x_return_status   => x_return_status
9733                                         ,x_msg_count       => x_msg_count
9734                                         ,x_msg_data        => x_msg_data ) ;
9735 
9736           l_progress := 'WMSINB-15267';
9737 
9738           if x_return_status <> G_RET_STS_SUCCESS Then
9739              --  Review Late Set Appropiate Message
9740              l_progress := 'WMSINB-15268';
9741              RAISE FND_API.G_EXC_ERROR;
9742           End if;
9743        end if; -- IF (l_rti_rec.primary_quantity < 0) and  (l_rti_rec.lpn_id is not null) THEN
9744        --End bug 5095399
9745    END IF;
9746 
9747 
9748    IF (l_debug = 1) THEN
9749       print_debug('PROCESS_TXN - Auto Transact code = '|| l_rti_rec.auto_transact_code,1);
9750    END IF;
9751 
9752    /* Changes for Match Txn as the UOM_CODE might be null in RTI for Match Txn */
9753 
9754    IF l_rti_rec.uom_code is null then
9755       IF (l_debug = 1) THEN
9756          print_debug('PROCESS_TXN - Get uom_code from unit_of_measure as Uom_code is null in rti',1);
9757          print_debug('PROCESS_TXN - Unit_of_measure = '|| l_rti_rec.unit_of_measure,1);
9758       END IF;
9759 
9760       BEGIN
9761           SELECT uom_code
9762           into l_rti_rec.uom_code
9763           FROM mtl_item_uoms_view
9764           WHERE organization_id = l_rti_rec.to_organization_id
9765           AND inventory_item_id =  l_rti_rec.item_id
9766           AND unit_of_measure = l_rti_rec.unit_of_measure;
9767       EXCEPTION
9768           WHEN OTHERS THEN
9769               IF (l_debug = 1) THEN
9770                  print_debug('PROCESS_TXN : Error retrieving uom_code', 1);
9771               END IF;
9772               l_progress := 'WMSINB-15300';
9773               RAISE fnd_api.g_exc_error;
9774       END;
9775       -- OPMConvergence
9776       IF l_rti_rec.secondary_unit_of_measure IS NOT NULL THEN
9777 
9778           BEGIN
9779              SELECT uom_code
9780              INTO   l_rti_rec.secondary_uom_code
9781              FROM   mtl_item_uoms_view
9782              WHERE  organization_id = l_rti_rec.to_organization_id
9783              AND    inventory_item_id = l_rti_rec.item_id
9784              AND    unit_of_measure = l_rti_rec.secondary_unit_of_measure;
9785           EXCEPTION
9786              WHEN OTHERS THEN
9787                IF (l_debug = 1) THEN
9788                  print_debug('CANCEL_ASN: Error retrieving sec_uom_code'||sqlerrm, 1);
9789                END IF;
9790                l_progress := 'WMSINB-11211';
9791                RAISE fnd_api.g_exc_error;
9792           END;
9793 
9794        END IF;
9795                -- OPMConvergence
9796    END IF;
9797 
9798    --BUG 3386801: No need to call maintain_mo_wrapper for CANCEL transactions
9799 
9800    -- 4398331 The CASE FOR SHIP and auto trasact code of DELIVER is also
9801    -- added for the case below.
9802 
9803    IF (l_rti_rec.transaction_type in ('RECEIVE','DELIVER','SHIP') AND
9804        Nvl(l_rti_rec.auto_transact_code, '@#$#$@') = 'DELIVER') THEN
9805       BEGIN
9806           SELECT requisition_line_id
9807             INTO l_requisition_line_id
9808             FROM rcv_transactions
9809             WHERE interface_transaction_id = p_txn_id;
9810       EXCEPTION
9811           WHEN OTHERS THEN
9812              IF (l_debug = 1) THEN
9813                 print_debug('Error retrieving req_line_id',1);
9814              END IF;
9815              l_requisition_line_id := NULL;
9816       END;
9817 
9818       IF (l_rti_rec.po_line_location_id IS NOT NULL) THEN
9819          BEGIN
9820              SELECT po_header_id
9821                INTO l_po_header_id
9822                FROM po_line_locations_all
9823                WHERE line_location_id = l_rti_rec.po_line_location_id;
9824          EXCEPTION
9825              WHEN OTHERS THEN
9826                 IF (l_debug = 1) THEN
9827               print_debug('Error retrieving po_header_id',1);
9828                 END IF;
9829          END ;
9830       ELSE
9831          l_po_header_id := NULL;
9832       END IF;
9833 
9834 
9835       IF (l_debug = 1) THEN
9836           print_debug('PROCESS_TXN - DIRECT RECEIPT. CALLING RSV API',1);
9837           print_debug('l_rti_rec.transaction_type     => '||l_rti_rec.transaction_type,1);
9838           print_debug('l_rti_rec.to_organization_id   => '||l_rti_rec.to_organization_id,1);
9839           print_debug('l_rti_rec.item_id              => '||l_rti_rec.item_id,1);
9840           print_debug('l_rti_rec.item_revision        => '||l_rti_rec.item_revision,1);
9841           print_debug('l_rti_rec.project_id           => '||l_rti_rec.project_id,1);
9842           print_debug('l_rti_rec.task_id              => '||l_rti_rec.task_id,1);
9843           print_debug('l_rti_rec.primary_uom_code     => '||l_primary_uom,1);
9844           print_debug('l_rti_rec.primary_quantity     => '||l_rti_rec.primary_quantity,1);
9845           print_debug('l_po_header_id                 => '||l_po_header_id,1);
9846           print_debug('l_rti_rec.po_line_location_id  => '||l_rti_rec.po_line_location_id,1);
9847           print_debug('l_rti_rec.shipment_line_id     => '||l_rti_rec.shipment_line_id,1);
9848           print_debug('l_requisition_line_id          => '||l_requisition_line_id,1);
9849           print_debug('l_rti_rec.auto_transact_code   => '||l_rti_rec.auto_transact_code,1);
9850           print_debug('l_rti_rec.asn_line_flag        => '||l_asn_line_flag,1);
9851       END IF;
9852 
9853       /* Bug 5365065.
9854        * In the procedure maintain_reservation, we check whether l_asn_line_flag is Y or N.
9855        * But the table l_mol_res_in was not populated with asn_line_flag. Populated the table
9856        * with l_asn_line_flag.
9857        */
9858       l_mol_res_in(1).transaction_type       := l_rti_rec.transaction_type;
9859       l_mol_res_in(1).organization_id        := l_rti_rec.to_organization_id;
9860       l_mol_res_in(1).inventory_item_id      := l_rti_rec.item_id;
9861       l_mol_res_in(1).item_revision          := l_rti_rec.item_revision;
9862       l_mol_res_in(1).project_id             := l_rti_rec.project_id;
9863       l_mol_res_in(1).task_id                := l_rti_rec.task_id;
9864       l_mol_res_in(1).primary_uom_code       := l_primary_uom;
9865       l_mol_res_in(1).primary_qty            := l_rti_rec.primary_quantity;
9866       l_mol_res_in(1).po_header_id           := l_po_header_id;
9867       l_mol_res_in(1).po_line_location_id    := l_rti_rec.po_line_location_id;
9868       l_mol_res_in(1).shipment_line_id       := l_rti_rec.shipment_line_id;
9869       l_mol_res_in(1).requisition_line_id    := l_requisition_line_id;
9870       l_mol_res_in(1).auto_transact_code     := l_rti_rec.auto_transact_code;
9871       l_mol_res_in(1).asn_line_flag          := l_asn_line_flag;
9872       INV_RCV_RESERVATION_UTIL.maintain_reservations
9873          (x_return_status => x_return_status
9874           ,x_msg_count     => x_msg_count
9875           ,x_msg_data      => x_msg_data
9876           ,x_mol_tb        => l_mol_res_out
9877           ,p_cas_mol_tb    => l_mol_res_in
9878           );
9879 
9880       IF (l_debug = 1) THEN
9881          print_debug('PROCESS_TXN - rsv api returns:'||x_return_status,1);
9882       END IF;
9883 
9884       IF (x_return_status <> g_ret_sts_success) THEN
9885          l_progress := 'WMSINB-14998';
9886          RAISE FND_API.G_EXC_ERROR;
9887       END IF;
9888 
9889    ELSIF ((l_rti_rec.transaction_type = 'SHIP'
9890       AND Nvl(l_rti_rec.auto_transact_code, '@#$#$@') <> 'RECEIVE')
9891        OR (l_rti_rec.transaction_type = 'CANCEL')
9892        OR (l_rti_rec.transaction_type IN ('RETURN TO VENDOR','RETURN TO CUSTOMER')
9893       AND l_parent_txn_type = 'DELIVER')) THEN
9894       IF (l_debug = 1) THEN
9895           print_debug('PROCESS_TXN - No Need to call MAINTAIN_MO_WRAPPER for this case ',1);
9896       END IF;
9897    ELSE --IF ((l_rti_rec.transaction_type in ('RECEIVE','DELIVER') AND (SHIP with auto transact code as RECEIVE
9898       IF (l_debug = 1) THEN
9899           print_debug('PROCESS_TXN - Calling MAINTAIN_MO_WRAPPER for this case ',1);
9900           print_debug('PROCESS_TXN - Primary Quantity:'||l_rti_rec.primary_quantity,1);
9901           -- OPMConvergence
9902           print_debug(l_proc_name||'- secondary Quantity:'||l_rti_rec.secondary_quantity,1);
9903           -- OPMConvergence
9904       END IF;
9905 
9906       IF (l_transactions_enabled_flag = 'Y') THEN
9907 
9908           -- 4398331
9909           -- For ROI Txns with txn type SHIP and auto transact RECEIVE Pass TRANSFER LPN
9910           -- AS LPN ID IF THE TRANSFER LPN ID DOES NOT HAVE ANY VALUE.
9911           -- This needs to be done to satisfy ship and receive in the same LPN.
9912 
9913           IF ( l_rti_rec.transaction_type = 'SHIP'
9914               AND Nvl(l_rti_rec.auto_transact_code, '@#$#$@') = 'RECEIVE' ) THEN
9915 
9916              if l_rti_rec.transfer_lpn_id is null then
9917                 IF (l_debug = 1) THEN
9918                    print_debug('PROCESS_TXN - Resetting transfer lpn id for SHIP and auto transact code Receive',1);
9919                 End if;
9920                 l_rti_rec.transfer_lpn_id := l_rti_rec.lpn_id;
9921              End if;
9922 
9923           END IF;
9924 
9925           maintain_mo_wrapper(p_rti_id => p_txn_id,
9926                   p_primary_quantity => l_rti_rec.primary_quantity,
9927                   p_primary_uom_code => l_primary_uom,
9928                   p_mmtt_temp_id => l_rti_rec.mmtt_temp_id,
9929                   p_org_id => l_rti_rec.to_organization_id,
9930                   p_item_id => l_rti_rec.item_id,
9931                   p_revision => l_rti_rec.item_revision,
9932                   p_qty => l_rti_rec.quantity,
9933                   p_uom_code => l_rti_rec.uom_code,
9934                   p_lpn_id => l_rti_rec.lpn_id,
9935                   p_transfer_lpn_id => l_rti_rec.transfer_lpn_id,
9936                   p_lot_control_code => l_lot_control_code,
9937                   p_serial_number_control_code => l_serial_control_code,
9938                   p_po_line_location_id => l_rti_rec.po_line_location_id,
9939                   p_po_distribution_id => l_rti_rec.po_distribution_id,
9940                   p_shipment_line_id => l_rti_rec.shipment_line_id,
9941                   p_oe_order_line_id => l_rti_rec.oe_order_line_id,
9942                   p_routing_header_id => l_rti_rec.routing_header_id,
9943                   p_subinventory => l_rti_rec.subinventory,
9944                   p_locator_id => l_rti_rec.locator_id,
9945                   p_from_subinventory => l_rti_rec.from_subinventory,
9946                   p_from_locator_id => l_rti_rec.from_locator_id,
9947                   p_project_id => l_rti_rec.project_id,
9948                   p_task_id => l_rti_rec.task_id,
9949                   x_transaction_id => l_rt_transaction_id,
9950                   x_return_status => x_return_status,
9951                   x_msg_count => x_msg_count,
9952                   x_msg_data => x_msg_data,
9953                   -- OPMConvergence
9954                   p_sec_qty => l_rti_rec.secondary_quantity,
9955                   p_sec_uom => l_rti_rec.secondary_uom_code,
9956                   -- OPMConvergence
9957                   p_auto_transact_code => l_rti_rec.auto_transact_code,
9958                   p_asn_line_flag      => l_asn_line_flag,
9959                   p_validation_flag    => l_rti_rec.validation_flag,
9960                   -- Bug# 7154105
9961                   p_req_distribution_id => l_rti_rec.req_distribution_id
9962           );
9963 
9964           IF x_return_status <> G_RET_STS_SUCCESS THEN
9965              --  Review Late Set Appropiate Message
9966              l_progress := 'WMSINB-15321';
9967              RAISE FND_API.G_EXC_ERROR;
9968           END IF;
9969              ELSE --IF (l_transactions_enabled_flag = 'Y') THEN
9970           IF (l_debug = 1) THEN
9971              print_debug('PROCESS_TXN - Expense Item. No MOVE ORDERS.',1);
9972           END IF;
9973       END IF; --IF (l_transactions_enabled_flag = 'Y') THEN
9974    END IF; --IF ((l_rti_rec.transaction_type in ('RECEIVE','DELIVER') AND
9975 
9976    IF (l_rti_rec.transaction_type <> 'DELIVER' AND
9977        Nvl(l_rti_rec.auto_transact_code, '@#$#$@') <> 'DELIVER'
9978        AND Nvl(l_parent_txn_type, '@@@@') <> 'DELIVER') THEN
9979       IF (l_debug = 1) THEN
9980           print_debug('PROCESS_TXN - Calling create_lot_serial_history ...',1);
9981           print_debug('PROCESS_TXN - Interface Txn ID:'||l_rti_rec.interface_transaction_id,1);
9982           print_debug('PROCESS_TXN - Txn ID:'||l_rt_transaction_id,1);
9983       END IF;
9984 
9985       create_lot_serial_history(p_prod_txn_tmp_id => l_rti_rec.interface_transaction_id,
9986                p_prod_txn_id => l_rt_transaction_id,
9987                x_return_status => x_return_status,
9988                x_msg_count => x_msg_count,
9989                x_msg_data => x_msg_data);
9990 
9991       IF (x_return_status <> g_ret_sts_success) THEN
9992           l_progress := 'WMSINB-15346';
9993           RAISE fnd_api.g_exc_error;
9994       END IF;
9995 
9996    END IF; --IF (l_rti_rec.transaction_type <> 'DELIVER' AND
9997 
9998    IF (l_debug = 1) THEN
9999       print_debug('PROCESS_TXN - Transaction Status: '||x_return_status,1);
10000      --print_debug('PROCESS_TXN - Transaction processed SUCCESSFULLY... UNBELEIVABLE!!! BELEIVE IT!!!!!',1);
10001    END IF;
10002 
10003 Exception
10004    when others then
10005       x_return_status  := g_ret_sts_unexp_error;
10006       IF (l_debug = 1) THEN
10007           print_debug('PROCESS_TXN : - Exception :'|| l_progress || ' ' ||
10008               TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
10009           print_stacked_messages;
10010       END IF;
10011 
10012       x_msg_data := l_progress;
10013 
10014       IF SQLCODE IS NOT NULL THEN
10015           inv_mobile_helper_functions.sql_error('inv_rcv_integration_pvt.process_txn',l_progress, SQLCODE);
10016       END IF;
10017       -- Get message count and data
10018       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
10019 
10020 END process_txn;
10021 
10022 PROCEDURE insert_msni(p_product_transaction_id   IN NUMBER,
10023                       p_product_code             IN VARCHAR2,
10024                       p_interface_id             IN NUMBER,
10025                       p_item_id                  IN NUMBER,
10026                       p_lot_number               IN VARCHAR2,
10027                       p_fm_serial_number         IN VARCHAR2,
10028                       p_to_serial_number         IN VARCHAR2,
10029                       x_return_status            OUT NOCOPY VARCHAR2,
10030                       x_msg_count                OUT NOCOPY NUMBER,
10031                       x_msg_data                 OUT NOCOPY VARCHAR2
10032 		      ) is
10033 
10034 			 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
10035 
10036 			 l_progress VARCHAR2(15) := '10';
10037 
10038 			 l_msg_count number;
10039 			 l_msg_data VARCHAR2(2000);
10040 
10041 			 l_user_id NUMBER;
10042 			 l_login_id NUMBER;
10043 
10044 BEGIN
10045 
10046    x_return_status := g_ret_sts_success;
10047 
10048    IF (l_debug = 1) THEN
10049       print_debug('Inside INSERT_MSNI', 4);
10050    END IF;
10051 
10052 
10053    l_user_id        := fnd_global.user_id;
10054    l_login_id       := fnd_global.login_id;
10055 
10056    Insert into MTL_SERIAL_NUMBERS_INTERFACE
10057      (
10058       transaction_interface_id,
10059       Source_Code,
10060       Source_Line_Id,
10061       Process_flag, --Is this the same process_flag as above?
10062       Last_Update_Date,
10063       Last_Updated_By,
10064       Creation_Date,
10065       Created_By,
10066       Fm_Serial_Number,
10067       To_Serial_Number,
10068       PRODUCT_CODE,
10069       PRODUCT_TRANSACTION_ID
10070       )
10071      Values
10072      (
10073       p_interface_id,            -- transaction_interface_id
10074       1,                         -- Source_Code,
10075       -1,                        -- Source_Line_Id,
10076       1,                         -- Process_flag,
10077       sysdate,                   -- Last_Update_Date,
10078       l_User_Id,                 -- Last_Updated_By,
10079       sysdate,                   -- Creation_Date,
10080       l_User_Id,                 -- Created_By,
10081       p_fm_Serial_number,        -- from_Serial_Number,
10082       p_to_Serial_number,        -- To_Serial_Number
10083       p_product_code,
10084       p_product_transaction_id
10085       );
10086 
10087    IF (l_debug = 1) THEN
10088       print_debug('INSERT_MSNI Complete without Error', 4);
10089    END IF;
10090 
10091 EXCEPTION
10092    when others then
10093       x_return_status  := g_ret_sts_unexp_error;
10094       IF (l_debug = 1) THEN
10095          print_debug('insert_msni : - other exception:'|| l_progress || ' ' ||
10096 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
10097       END IF;
10098       IF SQLCODE IS NOT NULL THEN
10099 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.insert_msni',l_progress, SQLCODE);
10100       END IF;
10101       --  Get message count and data
10102       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => l_msg_count, p_data => x_msg_data);
10103 
10104 END insert_msni;
10105 
10106 PROCEDURE insert_mtli(p_product_transaction_id  IN NUMBER,
10107                       p_product_code                      IN VARCHAR2,
10108                       p_interface_id                      IN NUMBER,
10109                       p_org_id                            IN NUMBER,
10110                       p_item_id                           IN NUMBER,
10111                       p_lot_number                        IN VARCHAR2,
10112                       p_transaction_quantity              IN NUMBER,
10113                       p_primary_quantity                  IN NUMBER,
10114                       p_serial_interface_id               IN NUMBER,
10115                       x_return_status                     OUT NOCOPY VARCHAR2,
10116                       x_msg_count                         OUT NOCOPY NUMBER,
10117                       x_msg_data                          OUT NOCOPY VARCHAR2,
10118                       p_sec_qty                           IN NUMBER DEFAULT NULL
10119 		      ) is
10120 
10121 			 cursor mln_csr(p_lot_number VARCHAR2, p_item_id  NUMBER, p_org_id in NUMBER ) IS
10122 			    select  mln.inventory_item_id,
10123 			      mln.lot_number, mln.expiration_date, mln.description, mln.vendor_id,mln.vendor_name,
10124 			      mln.supplier_lot_number, mln.territory_code, mln.grade_code, mln.origination_date,
10125 			      mln.date_code, mln.status_id, mln.change_date, mln.age, mln.retest_date, mln.maturity_date,
10126 			      mln.lot_attribute_category, mln.item_size, mln.color, mln.volume, mln.volume_uom,
10127 			      mln.place_of_origin, mln.best_by_date, mln.length, mln.length_uom, mln.recycled_content,
10128 			      mln.thickness, mln.thickness_uom, mln.width, mln.width_uom, mln.curl_wrinkle_fold,
10129 			      mln.c_attribute1, mln.c_Attribute2, mln.c_attribute3, mln.c_attribute4, mln.c_attribute5,
10130 			      mln.c_attribute6, mln.c_attribute7, mln.c_attribute8, mln.c_attribute9, mln.c_attribute10,
10131 			      mln.c_attribute11, mln.c_attribute12, mln.c_attribute13, mln.c_attribute14, mln.c_attribute15,
10132 			      mln.c_attribute16, mln.c_attribute17, mln.c_attribute18, mln.c_attribute19, mln.c_attribute20,
10133 			      mln.d_attribute1, mln.d_attribute2, mln.d_attribute3, mln.d_attribute4, mln.d_attribute5,
10134 			      mln.d_attribute6, mln.d_attribute7, mln.d_attribute8, mln.d_attribute9, mln.d_attribute10,
10135 			      mln.n_attribute1, mln.n_attribute2, mln.n_attribute3, mln.n_attribute4, mln.n_attribute5,
10136 			      mln.n_attribute6, mln.n_attribute7, mln.n_attribute8, mln.n_attribute9, mln.n_attribute10
10137 			      FROM MTL_LOT_NUMBERS MLN
10138 			      WHERE mln.lot_number = Ltrim(Rtrim(p_lot_number))
10139 			      AND mln.organization_id = p_org_id
10140 			      AND mln.inventory_item_id = p_item_id
10141 			      ;
10142 
10143 			 l_mln_rec mln_csr%rowtype;
10144 
10145 			 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
10146 
10147 			 l_progress VARCHAR2(15) := '10';
10148 
10149 			 l_msg_count number;
10150 			 l_msg_data VARCHAR2(2000);
10151 
10152 			 l_user_id NUMBER;
10153 			 l_login_id NUMBER;
10154 
10155 BEGIN
10156 
10157    x_return_status := g_ret_sts_success;
10158 
10159    IF (l_debug = 1) THEN
10160       print_debug('Inside INSERT_MTLI' , 4);
10161    END IF;
10162 
10163 
10164    l_user_id        := fnd_global.user_id;
10165    l_login_id       := fnd_global.login_id;
10166 
10167    open mln_csr(p_lot_number, p_item_id, p_org_id);
10168    Fetch mln_csr into l_mln_rec;
10169    close mln_csr;
10170 
10171    IF (l_debug = 1) THEN
10172       print_debug('p_item_id = '|| p_item_id , 4);
10173       print_debug('p_lot_number = '|| p_lot_number , 4);
10174       print_debug('p_transaction_quantity = '|| p_transaction_quantity , 4);
10175       print_debug('p_primary_quantity = '|| p_primary_quantity , 4);
10176    END IF;
10177 
10178    insert into mtl_transaction_lots_interface (
10179 					       TRANSACTION_INTERFACE_ID,
10180 					       SOURCE_CODE,
10181 					       SOURCE_LINE_ID,
10182 					       LAST_UPDATE_DATE,
10183 					       LAST_UPDATED_BY,
10184 					       CREATION_DATE ,
10185 					       CREATED_BY,
10186 					       LAST_UPDATE_LOGIN,
10187 					       REQUEST_ID,
10188 					       PROGRAM_APPLICATION_ID,
10189 					       PROGRAM_ID,
10190 					       PROGRAM_UPDATE_DATE,
10191 					       LOT_NUMBER,
10192 					       LOT_EXPIRATION_DATE,
10193 					       TRANSACTION_QUANTITY,
10194 					       PRIMARY_QUANTITY,
10195 					       SERIAL_TRANSACTION_TEMP_ID,
10196 					       ERROR_CODE,
10197 					       PROCESS_FLAG,
10198 					       DESCRIPTION,
10199 					       VENDOR_NAME,
10200 					       SUPPLIER_LOT_NUMBER,
10201 					       ORIGINATION_DATE,
10202 					       DATE_CODE,
10203 					       GRADE_CODE,
10204 					       CHANGE_DATE,
10205 					       MATURITY_DATE,
10206 					       STATUS_ID,
10207 					       RETEST_DATE,
10208 					       AGE,
10209 					       ITEM_SIZE,
10210 					       COLOR,
10211 					       VOLUME,
10212 					       VOLUME_UOM,
10213 					       PLACE_OF_ORIGIN,
10214 					       BEST_BY_DATE,
10215 					       LENGTH,
10216      LENGTH_UOM,
10217      RECYCLED_CONTENT,
10218      THICKNESS,
10219      THICKNESS_UOM,
10220      WIDTH,
10221      WIDTH_UOM,
10222      CURL_WRINKLE_FOLD,
10223      LOT_ATTRIBUTE_CATEGORY,
10224      C_ATTRIBUTE1,
10225      C_ATTRIBUTE2,
10226      C_ATTRIBUTE3,
10227      C_ATTRIBUTE4,
10228      C_ATTRIBUTE5,
10229      C_ATTRIBUTE6,
10230      C_ATTRIBUTE7,
10231      C_ATTRIBUTE8,
10232      C_ATTRIBUTE9,
10233      C_ATTRIBUTE10,
10234      C_ATTRIBUTE11,
10235      C_ATTRIBUTE12,
10236      C_ATTRIBUTE13,
10237      C_ATTRIBUTE14,
10238      C_ATTRIBUTE15,
10239      C_ATTRIBUTE16,
10240      C_ATTRIBUTE17,
10241      C_ATTRIBUTE18,
10242      C_ATTRIBUTE19,
10243      C_ATTRIBUTE20,
10244      D_ATTRIBUTE1,
10245      D_ATTRIBUTE2,
10246      D_ATTRIBUTE3,
10247      D_ATTRIBUTE4,
10248      D_ATTRIBUTE5,
10249      D_ATTRIBUTE6,
10250      D_ATTRIBUTE7,
10251      D_ATTRIBUTE8,
10252      D_ATTRIBUTE9,
10253      D_ATTRIBUTE10,
10254      N_ATTRIBUTE1,
10255      N_ATTRIBUTE2,
10256      N_ATTRIBUTE3,
10257      N_ATTRIBUTE4,
10258      N_ATTRIBUTE5,
10259      N_ATTRIBUTE6,
10260      N_ATTRIBUTE7,
10261      N_ATTRIBUTE8,
10262      N_ATTRIBUTE9,
10263      N_ATTRIBUTE10,
10264      VENDOR_ID,
10265      TERRITORY_CODE,
10266      PRODUCT_CODE,
10267      PRODUCT_TRANSACTION_ID,
10268      SECONDARY_TRANSACTION_QUANTITY
10269      ) values
10270      (
10271       p_interface_id,
10272       1,
10273       -1,
10274       sysdate,
10275       l_user_id,
10276       sysdate,
10277       l_user_id,
10278       l_login_id,
10279       null, -- REQUEST_ID
10280       null, -- PROGRAM_APPLICATION_ID
10281       null, -- PROGRAM_ID
10282       null, -- PROGRAM_UPDATE_DATE
10283       Ltrim(Rtrim(p_lot_number)),
10284       l_mln_rec.EXPIRATION_DATE,
10285       P_TRANSACTION_QUANTITY,
10286       P_PRIMARY_QUANTITY,
10287       P_serial_interface_id, -- serial_transaction_temp_id
10288       null, -- ERROR_CODE
10289       null, -- PROCESS_FLAG,
10290       l_mln_rec.DESCRIPTION,
10291       l_mln_rec.VENDOR_NAME,
10292       l_mln_rec.SUPPLIER_LOT_NUMBER,
10293       l_mln_rec.ORIGINATION_DATE,
10294       l_mln_rec.DATE_CODE,
10295       l_mln_rec.GRADE_CODE ,
10296       l_mln_rec.CHANGE_DATE,
10297       l_mln_rec.MATURITY_DATE,
10298       l_mln_rec.STATUS_ID,
10299       l_mln_rec.RETEST_DATE,
10300       l_mln_rec.AGE,
10301       l_mln_rec.ITEM_SIZE,
10302       l_mln_rec.COLOR,
10303       l_mln_rec.VOLUME,
10304       l_mln_rec.VOLUME_UOM,
10305       l_mln_rec.PLACE_OF_ORIGIN,
10306       l_mln_rec.BEST_BY_DATE,
10307       l_mln_rec.LENGTH,
10308      l_mln_rec.LENGTH_UOM,
10309      l_mln_rec.RECYCLED_CONTENT,
10310      l_mln_rec.THICKNESS,
10311      l_mln_rec.THICKNESS_UOM,
10312      l_mln_rec.WIDTH,
10313      l_mln_rec.WIDTH_UOM,
10314      l_mln_rec.CURL_WRINKLE_FOLD,
10315      l_mln_rec.LOT_ATTRIBUTE_CATEGORY,
10316      l_mln_rec.C_ATTRIBUTE1,
10317      l_mln_rec.C_ATTRIBUTE2,
10318      l_mln_rec.C_ATTRIBUTE3,
10319      l_mln_rec.C_ATTRIBUTE4,
10320      l_mln_rec.C_ATTRIBUTE5,
10321      l_mln_rec.C_ATTRIBUTE6,
10322      l_mln_rec.C_ATTRIBUTE7,
10323      l_mln_rec.C_ATTRIBUTE8,
10324      l_mln_rec.C_ATTRIBUTE9,
10325      l_mln_rec.C_ATTRIBUTE10,
10326      l_mln_rec.C_ATTRIBUTE11,
10327      l_mln_rec.C_ATTRIBUTE12,
10328      l_mln_rec.C_ATTRIBUTE13,
10329      l_mln_rec.C_ATTRIBUTE14,
10330      l_mln_rec.C_ATTRIBUTE15,
10331      l_mln_rec.C_ATTRIBUTE16,
10332      l_mln_rec.C_ATTRIBUTE17,
10333      l_mln_rec.C_ATTRIBUTE18,
10334      l_mln_rec.C_ATTRIBUTE19,
10335      l_mln_rec.C_ATTRIBUTE20,
10336      l_mln_rec.D_ATTRIBUTE1 ,
10337      l_mln_rec.D_ATTRIBUTE2,
10338      l_mln_rec.D_ATTRIBUTE3,
10339      l_mln_rec.D_ATTRIBUTE4,
10340      l_mln_rec.D_ATTRIBUTE5,
10341      l_mln_rec.D_ATTRIBUTE6,
10342      l_mln_rec.D_ATTRIBUTE7,
10343      l_mln_rec.D_ATTRIBUTE8,
10344      l_mln_rec.D_ATTRIBUTE9,
10345      l_mln_rec.D_ATTRIBUTE10,
10346      l_mln_rec.N_ATTRIBUTE1,
10347      l_mln_rec.N_ATTRIBUTE2,
10348      l_mln_rec.N_ATTRIBUTE3,
10349      l_mln_rec.N_ATTRIBUTE4,
10350      l_mln_rec.N_ATTRIBUTE5,
10351      l_mln_rec.N_ATTRIBUTE6,
10352      l_mln_rec.N_ATTRIBUTE7,
10353      l_mln_rec.N_ATTRIBUTE8,
10354      l_mln_rec.N_ATTRIBUTE9,
10355      l_mln_rec.N_ATTRIBUTE10,
10356      l_mln_rec.VENDOR_ID,
10357      l_mln_rec.TERRITORY_CODE,
10358      p_PRODUCT_CODE,
10359      p_PRODUCT_TRANSACTION_ID,
10360      p_sec_qty
10361      );
10362 
10363    IF (l_debug = 1) THEN
10364       print_debug('INSERT_MTLI  Commplete without Error ' , 4);
10365    END IF;
10366 
10367 EXCEPTION
10368    when others then
10369       x_return_status  := g_ret_sts_unexp_error;
10370       IF (l_debug = 1) THEN
10371          print_debug('insert_mtli : - other exception:'|| l_progress || ' ' ||
10372 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
10373       END IF;
10374       IF SQLCODE IS NOT NULL THEN
10375 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.insert_mtli',l_progress, SQLCODE);
10376       END IF;
10377       --  Get message count and data
10378       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => l_msg_count, p_data => x_msg_data);
10379 
10380 END insert_mtli;
10381 
10382 -- Description
10383 -- This API creates RTI rows for LPN contents
10384 --
10385 PROCEDURE create_rti_for_lpn(p_transaction_type         IN        VARCHAR2,
10386 			     p_interface_transaction_id IN        NUMBER,
10387                              p_lpn_id                   IN        NUMBER,
10388                              p_item_id                  IN        NUMBER,
10389                              p_org_id                   IN        NUMBER,
10390                              p_to_org_id                IN        NUMBER,
10391                              p_item_desc                IN        VARCHAR2 default null,
10392                              p_item_revision            IN        VARCHAR2 default null,
10393                              p_quantity                 IN        NUMBER,
10394                              p_txn_uom_code             IN        VARCHAR2,
10395                              p_transfer_lpn_id          IN        NUMBER default null,
10396                              p_transfer_lpn             IN        VARCHAR2 default null,
10397                              p_txn_source_id            IN        NUMBER default NULL,
10398                              p_mmtt_temp_id             IN        NUMBER default NULL,
10399   p_project_id               IN         NUMBER DEFAULT NULL,
10400   p_task_id                  IN         NUMBER DEFAULT NULL,
10401   x_interface_transaction_id OUT NOCOPY NUMBER,
10402   x_return_status            OUT NOCOPY VARCHAR2,
10403   x_msg_count                OUT NOCOPY NUMBER,
10404   x_msg_data                 OUT NOCOPY VARCHAR2)
10405   is
10406      l_interface_transaction_id NUMBER;
10407 
10408      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
10409      l_progress VARCHAR2(15) := '10';
10410      l_msg_count number;
10411      l_msg_data VARCHAR2(2000);
10412 
10413 
10414      l_user_id NUMBER;
10415      l_login_id NUMBER;
10416 
10417      l_sysdate DATE := SYSDATE;
10418      l_rti_rowid VARCHAR2 (40);
10419      l_group_id NUMBER;
10420      l_transaction_type VARCHAR2(100);
10421      l_transaction_mode VARCHAR2(100);
10422      l_employee_id NUMBER;
10423      l_auto_transact_code VARCHAR2 ( 30 );
10424      l_shipment_header_id NUMBER;
10425      l_shipment_line_id NUMBER;
10426      l_source_type_code VARCHAR2(30);
10427      l_vendor_id NUMBER;
10428      l_vendor_site_id NUMBER;
10429 
10430      l_primary_uom VARCHAR2(3);
10431      l_primary_unit_of_measure VARCHAR2(30);
10432      l_lot_control_code NUMBER;
10433      l_serial_control_code NUMBER;
10434      l_unit_of_measure VARCHAR2(30);
10435      l_primary_qty  NUMBER;
10436      l_primary_lot_qty  NUMBER;
10437 
10438      l_lot_interface_id NUMBER;
10439      l_serial_interface_id NUMBER;
10440 
10441      l_serial_interface_inserted BOOLEAN;
10442 
10443      l_source_document_code VARCHAR2(25);
10444      l_receipt_source_code VARCHAR2(25);
10445 
10446      l_num_serial_inserted NUMBER;
10447 
10448      --< R12 MOAC>
10449      l_po_header_id       RCV_TRANSACTIONS.PO_HEADER_ID%TYPE;
10450      l_req_line_id        RCV_TRANSACTIONS.REQUISITION_LINE_ID%TYPE;
10451      l_oe_order_header_id RCV_TRANSACTIONS.OE_ORDER_HEADER_ID%TYPE;
10452      l_operating_unit_id  MO_GLOB_ORG_ACCESS_TMP.ORGANIZATION_ID%TYPE;
10453 
10454 
10455 BEGIN
10456 
10457    x_return_status := g_ret_sts_success;
10458 
10459    l_progress := 'WMSINB-15799';
10460 
10461    -- Get the New Interface ID
10462    --
10463    SELECT primary_uom_code,
10464      primary_unit_of_measure,
10465      lot_control_code,
10466      serial_number_control_code
10467      INTO  l_primary_uom,
10468      l_primary_unit_of_measure,
10469      l_lot_control_code,
10470      l_serial_control_code
10471      FROM mtl_system_items
10472      WHERE inventory_item_id = p_item_id
10473      AND organization_id = p_to_org_id;
10474 
10475    l_progress := 'WMSINB-15816';
10476 
10477    SELECT unit_of_measure
10478      into l_unit_of_measure
10479      FROM mtl_item_uoms_view
10480      WHERE organization_id = p_to_org_id
10481      AND inventory_item_id = p_item_id
10482      AND uom_code = p_txn_uom_code;
10483 
10484    l_progress := 'WMSINB-15825';
10485 
10486    IF (l_debug = 1) THEN
10487       print_debug('create_rti_for_lpn:p_item_id = '|| p_item_id , 4);
10488       print_debug('create_rti_for_lpn:l_primary_uom = '|| l_primary_uom , 4);
10489       print_debug('create_rti_for_lpn:l_primary_unit_of_measure = '|| l_primary_unit_of_measure , 4);
10490       print_debug('create_rti_for_lpn:l_unit_of_measure = '|| l_unit_of_measure , 4);
10491       print_debug('create_rti_for_lpn:p_txn_uom_code = '|| p_txn_uom_code , 4);
10492       print_debug('create_rti_for_lpn:p_txn_source_id = '|| p_txn_source_id , 4);
10493       print_debug('create_rti_for_lpn:p_mmtt_temp_id = '|| p_mmtt_temp_id , 4);
10494    END IF;
10495 
10496    IF (p_txn_uom_code <> l_primary_uom) THEN
10497       l_primary_qty :=  inv_rcv_cache.convert_qty(p_inventory_item_id => p_item_id
10498 				    ,p_from_qty         => p_quantity
10499 				    ,p_from_uom_code    => p_txn_uom_code
10500 				    ,p_to_uom_code      => l_primary_uom
10501 				    );
10502     ELSE
10503       l_primary_qty := p_quantity;
10504    END IF;
10505 
10506    IF (l_debug = 1) THEN
10507       print_debug('create_rti_for_lpn:Quantity = '|| p_quantity , 4);
10508       print_debug('create_rti_for_lpn:Primary Qty = '|| l_primary_qty , 4);
10509    END IF;
10510 
10511    l_progress := 'WMSINB-15850';
10512 
10513    SELECT rcv_transactions_interface_s.NEXTVAL
10514      INTO   l_interface_transaction_id
10515      FROM   DUAL;
10516 
10517    l_progress := 'WMSINB-15856';
10518 
10519    l_user_id        := fnd_global.user_id;
10520    l_login_id       := fnd_global.login_id;
10521 
10522    l_progress := 'WMSINB-15861';
10523 
10524    --get the receipt_source_code and source_document_code
10525    IF (p_txn_source_id IS NOT NULL) THEN
10526 
10527       /* R12 MOAC : Fetch the po_header_id, requisition_line_id, oe_order_header_id from
10528       **            rcv_transactions and derive the operating unit id
10529       */
10530 
10531       BEGIN
10532 	 SELECT rt.source_document_code
10533 	   , rsh.receipt_source_code
10534            , rt.po_header_id
10535            , rt.requisition_line_id
10536            , rt.oe_order_header_id
10537 	   INTO l_source_document_code
10538 	   , l_receipt_source_code
10539            , l_po_header_id
10540            , l_req_line_id
10541            , l_oe_order_header_id
10542 	   FROM rcv_transactions rt
10543 	   , rcv_shipment_headers rsh
10544 	   WHERE rt.transaction_id = p_txn_source_id
10545 	   AND rt.shipment_header_id = rsh.shipment_header_id
10546 	   AND rt.organization_id = p_to_org_id
10547 	   AND exists (SELECT '1' FROM rcv_shipment_lines rsl
10548 		       WHERE rsl.shipment_header_id = rsh.shipment_header_id
10549 		       AND rt.organization_id = rsl.to_organization_id);
10550       EXCEPTION
10551 	 WHEN no_data_found THEN
10552 	    --raise an error
10553 	    --review later
10554 	    l_progress := 'WMSINB-15882';
10555 	    RAISE fnd_api.g_exc_error;
10556       END;
10557 
10558       --<R12 MOAC>
10559       l_operating_unit_id := inv_rcv_common_apis.get_operating_unit_id(
10560                                           l_receipt_source_code,
10561                                           l_po_header_id,
10562                                           l_req_line_id,
10563                                           l_oe_order_header_id);
10564 
10565     ELSE --IF (p_txn_source_id IS NOT NULL) THEN
10566       BEGIN
10567 
10568 	--following is as per perfomance fix 8113852 / bug 3631289
10569 
10570 	 SELECT rsh.receipt_source_code,
10571 	   Decode(rsh.receipt_source_code,'INTERNAL
10572 		  ORDER','REQ','INVENTORY','INVENTORY','VENDOR','PO','CUSTOMER','RMA')
10573 		  INTO l_receipt_source_code
10574 		  , l_source_document_code
10575 	  FROM rcv_shipment_headers rsh, wms_license_plate_numbers wlpn
10576 	WHERE RSH.SHIPMENT_HEADER_ID = WLPN.SOURCE_HEADER_ID
10577         	AND WLPN.SOURCE_HEADER_ID IS NOT NULL
10578         	AND wlpn.lpn_id = p_lpn_id
10579         	AND exists (SELECT '1' FROM rcv_shipment_lines rsl
10580                         WHERE rsl.shipment_header_id = rsh.shipment_header_id
10581                         AND wlpn.organization_id = rsl.to_organization_id);
10582 	 EXCEPTION
10583 	      WHEN NO_DATA_FOUND THEN
10584                 BEGIN
10585 		  SELECT rsh.receipt_source_code,
10586 		  Decode(rsh.receipt_source_code,'INTERNAL
10587 			 ORDER','REQ','INVENTORY','INVENTORY','VENDOR','PO','CUSTOMER','RMA')
10588 			 INTO l_receipt_source_code
10589 			 , l_source_document_code
10590 	                FROM rcv_shipment_headers rsh, wms_license_plate_numbers wlpn
10591 			WHERE RSH.SHIPMENT_NUM = WLPN.SOURCE_NAME
10592 	                        AND WLPN.SOURCE_NAME IS NOT NULL
10593 	                        AND wlpn.lpn_id = p_lpn_id
10594 	                        AND exists (SELECT '1' FROM rcv_shipment_lines rsl
10595                                    WHERE rsl.shipment_header_id = rsh.shipment_header_id
10596                                         AND wlpn.organization_id = rsl.to_organization_id);
10597 
10598      	--Two exception blocks as such necessary?
10599 	EXCEPTION
10600 		 WHEN no_data_found THEN
10601 	   	 --raise an error
10602 	    	--review later
10603 	    	l_progress := 'WMSINB-15904';
10604 	    RAISE fnd_api.g_exc_error;
10605 	    END;
10606 	END;
10607    END IF; --IF (p_txn_source_id IS NOT NULL) THEN
10608 
10609    IF (l_debug = 1) THEN
10610       print_debug('create_rti_for_lpn:SOURCE_DOCUMENT_CODE:'||l_source_document_code,1);
10611       print_debug('create_rti_for_lpn:RECEIPT_SOURCE_CODE:'||l_receipt_source_code,1);
10612    END IF;
10613 
10614    l_progress := 'WMSINB-15914';
10615 
10616    -- Fetch the original RTI row
10617    For l_rcv_transaction_rec in (
10618 				 select group_id                       ,
10619 				 lpn_group_id                   ,
10620 				 transaction_type               ,
10621 				 processing_mode_code           ,
10622 				 processing_request_id          ,
10623 				 item_category                  ,
10624 				 quantity                       ,
10625 				 unit_of_measure                ,
10626 				 uom_code                       ,
10627 				 employee_id                    ,
10628 				 auto_transact_code             ,
10629 				 shipment_header_id             ,
10630 				 shipment_line_id               ,
10631 				 ship_to_location_id            ,
10632 				 primary_quantity               ,
10633 				 primary_unit_of_measure        ,
10634 				 receipt_source_code            ,
10635 				 vendor_id                      ,
10636 				 vendor_site_id                 ,
10637 				 from_Organization_Id           ,
10638 				 to_Organization_Id           ,
10639 				 Routing_Header_Id              ,
10640 				 Routing_Step_Id                ,
10641 				 Source_Document_Code           ,
10642 				 Parent_Transaction_Id          ,
10643 				 Po_Header_Id                   ,
10644      Po_Revision_Num                ,
10645      Po_Release_Id                  ,
10646      Po_Line_Id                     ,
10647      Po_Line_Location_Id            ,
10648      Po_Unit_Price                  ,
10649      Currency_Code                  ,
10650      Currency_Conversion_Type       ,
10651      Currency_Conversion_Rate       ,
10652      Currency_Conversion_Date       ,
10653      Po_Distribution_Id             ,
10654      Requisition_Line_Id            ,
10655      Req_Distribution_Id            ,
10656      Charge_Account_Id              ,
10657      Substitute_Unordered_Code      ,
10658      Receipt_Exception_Flag         ,
10659      Accrual_Status_Code            ,
10660      Inspection_Status_Code         ,
10661      Inspection_Quality_Code        ,
10662      Destination_Type_Code          ,
10663      Deliver_To_Person_Id           ,
10664      Location_Id                    ,
10665      Deliver_To_Location_Id         ,
10666      Subinventory                   ,
10667      Locator_Id                     ,
10668      Wip_Entity_Id                  ,
10669      Wip_Line_Id                    ,
10670      Department_Code                ,
10671      Wip_Repetitive_Schedule_Id     ,
10672      Wip_Operation_Seq_Num          ,
10673      Wip_Resource_Seq_Num           ,
10674      Bom_Resource_Id                ,
10675      Shipment_Num                   ,
10676      Freight_Carrier_Code           ,
10677      Bill_Of_Lading                 ,
10678      Packing_Slip                   ,
10679      Shipped_Date                   ,
10680      Expected_Receipt_Date          ,
10681      Actual_Cost                    ,
10682      Transfer_Cost                  ,
10683      Transportation_Cost            ,
10684      Transportation_Account_Id      ,
10685      Num_Of_Containers              ,
10686      Waybill_Airbill_Num            ,
10687      Vendor_Item_Num                ,
10688      Vendor_Lot_Num                 ,
10689      Rma_Reference                  ,
10690      Comments                       ,
10691      Attribute_Category             ,
10692      Attribute1                     ,
10693      Attribute2                     ,
10694      Attribute3                     ,
10695      Attribute4                     ,
10696      Attribute5                     ,
10697      Attribute6                     ,
10698      Attribute7                     ,
10699      Attribute8                     ,
10700      Attribute9                     ,
10701      Attribute10                    ,
10702      Attribute11                    ,
10703      Attribute12                    ,
10704      Attribute13                    ,
10705      Attribute14                    ,
10706      Attribute15                    ,
10707      Ship_Head_Attribute_Category   ,
10708      Ship_Head_Attribute1           ,
10709      Ship_Head_Attribute2           ,
10710      Ship_Head_Attribute3           ,
10711      Ship_Head_Attribute4           ,
10712      Ship_Head_Attribute5           ,
10713      Ship_Head_Attribute6           ,
10714      Ship_Head_Attribute7           ,
10715      Ship_Head_Attribute8           ,
10716      Ship_Head_Attribute9           ,
10717      Ship_Head_Attribute10          ,
10718      Ship_Head_Attribute11          ,
10719      Ship_Head_Attribute12          ,
10720      Ship_Head_Attribute13          ,
10721      Ship_Head_Attribute14          ,
10722      Ship_Head_Attribute15          ,
10723      Ship_Line_Attribute_Category   ,
10724      Ship_Line_Attribute1           ,
10725      Ship_Line_Attribute2           ,
10726      Ship_Line_Attribute3           ,
10727      Ship_Line_Attribute4           ,
10728      Ship_Line_Attribute5           ,
10729      Ship_Line_Attribute6           ,
10730      Ship_Line_Attribute7           ,
10731      Ship_Line_Attribute8           ,
10732      Ship_Line_Attribute9           ,
10733      Ship_Line_Attribute10          ,
10734      Ship_Line_Attribute11          ,
10735      Ship_Line_Attribute12          ,
10736      Ship_Line_Attribute13          ,
10737      Ship_Line_Attribute14          ,
10738      Ship_Line_Attribute15          ,
10739      Ussgl_Transaction_Code         ,
10740      Government_Context             ,
10741      Reason_Id                      ,
10742      Destination_Context            ,
10743      Source_Doc_Quantity            ,
10744      Source_Doc_Unit_Of_Measure     ,
10745      use_mtl_lot                  ,
10746      use_mtl_serial               ,
10747      QA_Collection_Id               ,
10748      Country_of_Origin_Code         ,
10749      oe_order_header_id             ,
10750      oe_order_line_id               ,
10751      customer_item_num              ,
10752      customer_id                    ,
10753      customer_site_id               ,
10754      put_away_rule_id               ,
10755      put_away_strategy_id           ,
10756      lpn_id                         ,
10757      transfer_lpn_id                ,
10758      license_plate_number           ,
10759      transfer_license_plate_number  ,
10760      cost_group_id                  ,
10761      mmtt_temp_id                   ,
10762      mobile_txn                     ,
10763      transfer_cost_group_id         ,
10764      secondary_quantity             ,
10765      secondary_unit_of_measure      ,
10766      org_id                          --<R12 MOAC>
10767      from  rcv_transactions_interface rti
10768      where rti.interface_transaction_id = p_interface_transaction_id )
10769      Loop
10770 	-- Insert the row
10771 	IF (l_debug = 1) THEN
10772 	   print_debug('create_rti_from_lpn : - Before Inserting into RTI' , 1);
10773 	END IF;
10774 
10775 
10776 	-- Needs to be reviewed Later
10777 	-- Fetch Details from parent if necessary for Transfer and Deliver Txn
10778 	--
10779 	--
10780 	--   shipment_line_id
10781 	--    shipment_header_id
10782 	--   oe_order_header_id             ,
10783 	--    oe_order_line_id               ,
10784 	--    Wip_Entity_Id                  ,
10785 	--   Wip_Line_Id                    ,
10786 	--   Department_Code                ,
10787 	--   Wip_Repetitive_Schedule_Id     ,
10788 	--   Wip_Operation_Seq_Num          ,
10789 	--   Wip_Resource_Seq_Num           ,
10790 	--   Po_Header_Id                   ,
10791 	--   Po_Revision_Num                ,
10792 	--   Po_Release_Id                  ,
10793 	--   Po_Line_Id                     ,
10794 	--   Po_Line_Location_Id            ,
10795 	--   Po_Unit_Price                  ,
10796 	--   Po_Distribution_Id             ,
10797 	--  Requisition_Line_Id            ,
10798 	--  Req_Distribution_Id            ,
10799 	--
10800 	--
10801 
10802         l_progress := 'WMSINB-16101';
10803 
10804 	rcv_trx_interface_insert_pkg.insert_row ( l_rti_rowid,
10805 						  l_interface_transaction_id,
10806 						  l_rcv_transaction_rec.group_id,
10807 						  l_sysdate,
10808 						  l_user_id,
10809 						  l_sysdate,            /* Created Date */
10810 						  l_user_id,            /* Created By */
10811 						  l_login_id,           /* last Update Login */
10812 						  l_rcv_transaction_rec.transaction_type,   /* transaction type */
10813 						  l_sysdate ,  /* transaction date */
10814 						  'RUNNING',            /* Processing status code */
10815 						  l_rcv_transaction_rec.processing_mode_code,
10816 						  /* Processing Request id Debug: Not sure how this is used */
10817 						  l_rcv_transaction_rec.processing_request_id ,
10818 						  'PENDING',            /* Transaction status code */
10819 						  NULL,                 /* item_category */
10820 						  p_quantity,
10821 						  l_unit_of_measure,                  /* unit_of_measure */
10822 						  'RCV',                /* interface source code */
10823 						  NULL,                 /* interface source line id */
10824 						  NULL,                 /* inv_transaction id */
10825 	  p_item_id,
10826 	  p_item_desc,
10827 	  p_item_revision,
10828 	  p_txn_uom_code,       /* uom code */
10829 	  l_rcv_transaction_rec.employee_id,
10830 	  l_rcv_transaction_rec.auto_transact_code, /* Auto transact code */
10831 	  l_rcv_transaction_rec.shipment_header_id, /* shipment header id */
10832 	  l_rcv_transaction_rec.shipment_line_id,   /* shipment line id */
10833 	  l_rcv_transaction_rec.ship_to_location_id,
10834 	  l_primary_qty, /* primary quantity */
10835 	  l_primary_unit_of_measure, /* primary uom */
10836 	  l_receipt_source_code, /* receipt source code */
10837 	  l_rcv_transaction_rec.vendor_id,
10838 	  l_rcv_transaction_rec.vendor_site_id,
10839 	  l_rcv_transaction_rec.from_organization_id,   /* from org id */
10840 	  l_rcv_transaction_rec.to_organization_id,       /* to org id */
10841 	  l_rcv_transaction_rec.routing_header_id,
10842 	  l_rcv_transaction_rec.routing_step_id,           /* routing step id */
10843 	  l_source_document_code, /* source document code */
10844 	  nvl(p_txn_source_id,-1) , /* Parent trx id */
10845 	  l_rcv_transaction_rec.po_header_id,
10846 	  NULL,     /* PO Revision number */
10847 	  l_rcv_transaction_rec.po_release_id,
10848 	  l_rcv_transaction_rec.po_line_id,
10849 	  l_rcv_transaction_rec.po_line_location_id,
10850 	  l_rcv_transaction_rec.po_unit_price,
10851 	  l_rcv_transaction_rec.currency_code, /* Currency_Code */
10852 	  l_rcv_transaction_rec.currency_conversion_type,
10853 	  l_rcv_transaction_rec.currency_conversion_rate,
10854 	  l_rcv_transaction_rec.currency_conversion_date,
10855 	  l_rcv_transaction_rec.po_distribution_id,
10856 	  l_rcv_transaction_rec.Requisition_Line_Id,
10857 	  l_rcv_transaction_rec.req_distribution_id,
10858 	  l_rcv_transaction_rec.charge_account_id,   /* Charge_Account_Id */
10859 	  l_rcv_transaction_rec.substitute_unordered_code, /* Substitute_Unordered_Code */
10860 	  l_rcv_transaction_rec.receipt_exception_flag, /* Receipt_Exception_Flag  forms check box?*/
10861 	  l_rcv_transaction_rec.Accrual_Status_Code,    /* Accrual_Status_Code */
10862 	  l_rcv_transaction_rec.Inspection_Status_Code, /* Inspection_Status_Code */
10863 	  l_rcv_transaction_rec.Inspection_Quality_Code, /* Inspection_Quality_Code */
10864 	  l_rcv_transaction_rec.destination_type_code, /* Destination_Type_Code */
10865 	  l_rcv_transaction_rec.deliver_to_person_id, /* Deliver_To_Person_Id */
10866 	  l_rcv_transaction_rec.location_id,   /* Location_Id */
10867 	  l_rcv_transaction_rec.deliver_to_location_id, /* Deliver_To_Location_Id */
10868 	  l_rcv_transaction_rec.subinventory, /* Subinventory */
10869 	  l_rcv_transaction_rec.locator_id,     /* Locator_Id */
10870 	  l_rcv_transaction_rec.wip_entity_id, /* Wip_Entity_Id */
10871 	  l_rcv_transaction_rec.wip_line_id,   /* Wip_Line_Id */
10872 	  l_rcv_transaction_rec.department_code, /* Department_Code */
10873 	  l_rcv_transaction_rec.Wip_Repetitive_Schedule_Id, /* Wip_Repetitive_Schedule_Id */
10874 	  l_rcv_transaction_rec.Wip_Operation_Seq_Num, /* Wip_Operation_Seq_Num */
10875 	  l_rcv_transaction_rec.Wip_Resource_Seq_Num,
10876 	  l_rcv_transaction_rec.Bom_Resource_Id                ,
10877 	  l_rcv_transaction_rec.Shipment_Num                   ,
10878 	  l_rcv_transaction_rec.Freight_Carrier_Code           ,
10879 	  l_rcv_transaction_rec.Bill_Of_Lading                 ,
10880 	  l_rcv_transaction_rec.Packing_Slip                   ,
10881 	  l_rcv_transaction_rec.Shipped_Date                   ,
10882 	  l_rcv_transaction_rec.Expected_Receipt_Date          ,
10883 	  l_rcv_transaction_rec.Actual_Cost                    ,
10884 	  l_rcv_transaction_rec.Transfer_Cost                  ,
10885 	  l_rcv_transaction_rec.Transportation_Cost            ,
10886 	  l_rcv_transaction_rec.Transportation_Account_Id      ,
10887 	  l_rcv_transaction_rec.Num_Of_Containers              ,
10888 	  l_rcv_transaction_rec.Waybill_Airbill_Num            ,
10889 	  l_rcv_transaction_rec.Vendor_Item_Num                ,
10890 	  l_rcv_transaction_rec.Vendor_Lot_Num                 ,
10891 	  l_rcv_transaction_rec.Rma_Reference                  ,
10892 	  l_rcv_transaction_rec.Comments                       ,
10893 	  l_rcv_transaction_rec.Attribute_Category             ,
10894 	  l_rcv_transaction_rec.Attribute1                     ,
10895 	  l_rcv_transaction_rec.Attribute2                     ,
10896 	  l_rcv_transaction_rec.Attribute3                     ,
10897 	  l_rcv_transaction_rec.Attribute4                     ,
10898 	  l_rcv_transaction_rec.Attribute5                     ,
10899 	  l_rcv_transaction_rec.Attribute6                     ,
10900 	  l_rcv_transaction_rec.Attribute7                     ,
10901 	  l_rcv_transaction_rec.Attribute8                     ,
10902 	  l_rcv_transaction_rec.Attribute9                     ,
10903 	  l_rcv_transaction_rec.Attribute10                    ,
10904 	  l_rcv_transaction_rec.Attribute11                    ,
10905 	  l_rcv_transaction_rec.Attribute12                    ,
10906 	  l_rcv_transaction_rec.Attribute13                    ,
10907 	  l_rcv_transaction_rec.Attribute14                    ,
10908 	  l_rcv_transaction_rec.Attribute15                    ,
10909 	  l_rcv_transaction_rec.Ship_Head_Attribute_Category   ,
10910 	  l_rcv_transaction_rec.Ship_Head_Attribute1           ,
10911 	  l_rcv_transaction_rec.Ship_Head_Attribute2           ,
10912 	  l_rcv_transaction_rec.Ship_Head_Attribute3           ,
10913 	  l_rcv_transaction_rec.Ship_Head_Attribute4           ,
10914 	  l_rcv_transaction_rec.Ship_Head_Attribute5           ,
10915 	  l_rcv_transaction_rec.Ship_Head_Attribute6           ,
10916 	  l_rcv_transaction_rec.Ship_Head_Attribute7           ,
10917 	  l_rcv_transaction_rec.Ship_Head_Attribute8           ,
10918 	  l_rcv_transaction_rec.Ship_Head_Attribute9           ,
10919 	  l_rcv_transaction_rec.Ship_Head_Attribute10          ,
10920 	  l_rcv_transaction_rec.Ship_Head_Attribute11          ,
10921 	  l_rcv_transaction_rec.Ship_Head_Attribute12          ,
10922 	  l_rcv_transaction_rec.Ship_Head_Attribute13          ,
10923 	  l_rcv_transaction_rec.Ship_Head_Attribute14          ,
10924 	  l_rcv_transaction_rec.Ship_Head_Attribute15          ,
10925 	  l_rcv_transaction_rec.Ship_Line_Attribute_Category   ,
10926 	  l_rcv_transaction_rec.Ship_Line_Attribute1           ,
10927 	  l_rcv_transaction_rec.Ship_Line_Attribute2           ,
10928 	  l_rcv_transaction_rec.Ship_Line_Attribute3           ,
10929 	  l_rcv_transaction_rec.Ship_Line_Attribute4           ,
10930 	  l_rcv_transaction_rec.Ship_Line_Attribute5           ,
10931 	  l_rcv_transaction_rec.Ship_Line_Attribute6           ,
10932 	  l_rcv_transaction_rec.Ship_Line_Attribute7           ,
10933 	  l_rcv_transaction_rec.Ship_Line_Attribute8           ,
10934 	  l_rcv_transaction_rec.Ship_Line_Attribute9           ,
10935 	  l_rcv_transaction_rec.Ship_Line_Attribute10          ,
10936 	  l_rcv_transaction_rec.Ship_Line_Attribute11          ,
10937 	  l_rcv_transaction_rec.Ship_Line_Attribute12          ,
10938 	  l_rcv_transaction_rec.Ship_Line_Attribute13          ,
10939 	  l_rcv_transaction_rec.Ship_Line_Attribute14          ,
10940 	  l_rcv_transaction_rec.Ship_Line_Attribute15          ,
10941 	  l_rcv_transaction_rec.Ussgl_Transaction_Code         ,
10942 	  l_rcv_transaction_rec.Government_Context             ,
10943 	  l_rcv_transaction_rec.Reason_Id                      ,
10944 	  l_rcv_transaction_rec.Destination_Context            ,
10945 	  l_rcv_transaction_rec.Source_Doc_Quantity            ,
10946 	  l_rcv_transaction_rec.Source_Doc_Unit_Of_Measure     ,
10947 	  l_rcv_transaction_rec.use_mtl_lot                  ,
10948 	  l_rcv_transaction_rec.use_mtl_serial               ,
10949 	  l_rcv_transaction_rec.QA_Collection_Id               ,
10950 	  l_rcv_transaction_rec.Country_of_Origin_Code         ,
10951 	  l_rcv_transaction_rec.oe_order_header_id             ,
10952 	  l_rcv_transaction_rec.oe_order_line_id               ,
10953 	  l_rcv_transaction_rec.customer_item_num              ,
10954 	  l_rcv_transaction_rec.customer_id                    ,
10955 	  l_rcv_transaction_rec.customer_site_id               ,
10956 	  l_rcv_transaction_rec.put_away_rule_id               ,
10957 	  l_rcv_transaction_rec.put_away_strategy_id           ,
10958 	  p_lpn_id                         ,
10959 	  p_transfer_lpn_id                ,
10960 	  l_rcv_transaction_rec.cost_group_id                  ,
10961 	  p_mmtt_temp_id                                       ,
10962 	  l_rcv_transaction_rec.mobile_txn                     ,
10963 	  l_rcv_transaction_rec.transfer_cost_group_id         ,
10964 	  l_rcv_transaction_rec.secondary_quantity             ,
10965 	  l_rcv_transaction_rec.secondary_unit_of_measure      ,
10966 	  l_rcv_transaction_rec.lpn_group_id,
10967 	  nvl(l_operating_unit_id,l_rcv_transaction_rec.org_id)   --<R12 MOAC>
10968 	  );
10969 	-- *****************
10970 	-- This part may not be nneded when license_plate_numbver, transfer_license_plate_number
10971 	-- is inserted by insert_row itself.
10972 	-- added update to validation_flag
10973 	-- *******************
10974 	update rcv_transactions_interface
10975 	  set transfer_license_plate_number = p_transfer_lpn,
10976 	  validation_flag = 'Y',
10977 	  project_id = p_project_id,
10978 	  task_id = p_task_id
10979 	  where interface_transaction_id = l_interface_transaction_id;
10980 
10981 	Exit;
10982      End loop;
10983 
10984      l_progress := 'WMSINB-16280';
10985 
10986      x_interface_transaction_id := l_interface_transaction_id;
10987 
10988 
10989      -- Call the LOT API to insert into LOTS Interface
10990 
10991      l_lot_interface_id := null;
10992      l_serial_interface_id := null;
10993      l_serial_interface_inserted := FALSE;
10994 
10995      IF (l_debug = 1) THEN
10996 	print_debug('create_rti_from_lpn : - after Inserting into RTI' , 1);
10997      END IF;
10998 
10999 
11000      l_progress := 'WMSINB-16296';
11001 
11002      IF (p_transaction_type = 'RECEIVE') THEN
11003 	-- Case where EXPLOSION NEEDS TO HAPPEN FROM WLC
11004 	IF (l_debug = 1) THEN
11005            print_debug('create_rti_from_lpn : - Before Inserting Lots from WLC ' , 1);
11006 	END IF;
11007 
11008         l_progress := 'WMSINB-16604';
11009 
11010 	For l_lot_rec in ( select lot_number,
11011 			   uom_code,
11012 			   sum(quantity) quantity
11013 			   from wms_lpn_contents wlc
11014                            where wlc.inventory_item_id = p_item_id
11015 			   and wlc.organization_id = p_org_id
11016 			   and wlc.parent_lpn_id = p_lpn_id
11017                            group by lot_number, uom_code )
11018 	  Loop
11019 
11020 	     IF (l_lot_rec.uom_code <> l_primary_uom) THEN
11021 		l_primary_lot_qty := inv_rcv_cache.convert_qty(p_inventory_item_id => p_item_id
11022 						 ,p_from_qty         => l_lot_rec.quantity
11023 						 ,p_from_uom_code    => l_lot_rec.uom_code
11024 						 ,p_to_uom_code      => l_primary_uom
11025 						 );
11026 	      ELSE
11027 		l_primary_lot_qty := l_lot_rec.quantity;
11028 	     END IF;
11029 
11030 	     if l_lot_interface_id is null then
11031 		SELECT mtl_material_transactions_s.NEXTVAL
11032                   INTO l_lot_Interface_Id
11033 		  FROM DUAL;
11034 	     End if;
11035 
11036 	     l_serial_interface_id := null;
11037 
11038 	     -- Call insert MSNI for linked Serials Here
11039 	     For l_serial_rec in ( select msn.serial_number
11040 				   from mtl_serial_numbers msn
11041 				   where msn.lpn_id = p_lpn_id
11042 				   and msn.current_organization_id = p_org_id
11043 				   and msn.lot_number = l_lot_rec.lot_number
11044 				   and msn.inventory_item_id = p_item_id
11045 				   )
11046 	       Loop
11047 		  -- Generate the serial interface id here
11048 		  if l_serial_interface_id is null then
11049 		     SELECT mtl_material_transactions_s.NEXTVAL
11050 		       INTO l_serial_Interface_Id
11051 		       FROM DUAL;
11052 		  End if;
11053 
11054 		  insert_msni(p_product_transaction_id   => l_interface_transaction_id,
11055 			      p_product_code             => 'RCV',
11056 			      p_interface_id             => l_serial_Interface_Id,
11057 			      p_item_id                  => p_item_id,
11058 			      p_lot_number               => l_lot_rec.lot_number,
11059 			      p_fm_serial_number         => l_serial_rec.serial_number,
11060 			      p_to_serial_number         => l_serial_rec.serial_number,
11061 			      x_return_status            => x_return_status,
11062 			      x_msg_count                => l_msg_count,
11063 			      x_msg_data                 => l_msg_data
11064 			      );
11065 		  -- Check the error status from the above call
11066 		  if x_return_status <> G_RET_STS_SUCCESS Then
11067 		     -- MSG no new message just add the one on stack
11068 		     --  Review Late Set Appropiate Message
11069 		     exit; -- Exit from the Loop
11070 		  End if;
11071 
11072 		  l_serial_interface_inserted := TRUE;
11073 
11074 	       End Loop;
11075 
11076 	       insert_mtli(p_product_transaction_id   => l_interface_transaction_id,
11077 			   p_product_code             => 'RCV',
11078 			   p_interface_id             => l_lot_Interface_Id,
11079 			   p_org_id                   => p_org_id,
11080 			   p_item_id                  => p_item_id,
11081 			   p_lot_number               => l_lot_rec.lot_number,
11082 			   p_transaction_quantity     => l_lot_rec.quantity,
11083 			   p_primary_quantity         => l_primary_lot_qty,
11084 			   p_serial_interface_id      => l_serial_interface_id,
11085 			   x_return_status            => x_return_status,
11086 			   x_msg_count                => l_msg_count,
11087 			   x_msg_data                 => l_msg_data
11088 			   );
11089 
11090 	       -- Check the error status from the above call
11091 	       if x_return_status <> G_RET_STS_SUCCESS Then
11092 		  -- MSG no new message just add the one on stack
11093 		  --  Review Late Set Appropiate Message
11094 		  null;
11095 	       End if;
11096 	  End Loop;
11097 
11098           l_progress := 'WMSINB-16693';
11099 
11100 	  -- Cases for JUST SERIAL CONTROLLED
11101 	  if (l_serial_interface_inserted <> TRUE ) then
11102 
11103 	     For l_serial_rec in ( select msn.serial_number
11104 				   from mtl_serial_numbers msn
11105 				   where msn.lpn_id = p_lpn_id
11106 				   and msn.current_organization_id = p_org_id
11107 				   and msn.inventory_item_id = p_item_id
11108 				   )
11109 	       Loop
11110 		  -- Generate the serial interface id here
11111 		  if l_serial_interface_id is null then
11112 		     SELECT mtl_material_transactions_s.NEXTVAL
11113 		       INTO l_serial_Interface_Id
11114 		       FROM DUAL;
11115 		  End if;
11116 
11117 		  insert_msni(p_product_transaction_id   => l_interface_transaction_id,
11118 			      p_product_code             => 'RCV',
11119 			      p_interface_id             => l_serial_Interface_Id,
11120 			      p_item_id                  => p_item_id,
11121 			      p_lot_number               => null,
11122 			      p_fm_serial_number         => l_serial_rec.serial_number,
11123 			      p_to_serial_number         => l_serial_rec.serial_number,
11124 			      x_return_status            => x_return_status,
11125 			      x_msg_count                => l_msg_count,
11126 			      x_msg_data                 => l_msg_data
11127 			      );
11128 		  -- Check the error status from the above call
11129 		  if x_return_status <> G_RET_STS_SUCCESS Then
11130 		     -- MSG no new message just add the one on stack
11131 		     --  Review Late Set Appropiate Message
11132 		     exit; -- Exit from the Loop
11133 		  End if;
11134 
11135 		  l_serial_interface_inserted := TRUE;
11136 
11137 	       End Loop;
11138                l_progress := 'WMSINB-16733';
11139 	  End if;
11140      End if;
11141 
11142      IF (l_debug = 1) THEN
11143         print_debug('create_rti_from_lpn : - COMPLETED WITH SUCCESS'  , 1);
11144      END IF;
11145 
11146 EXCEPTION
11147    when others then
11148       x_return_status  := g_ret_sts_unexp_error;
11149       IF (l_debug = 1) THEN
11150          print_debug('create_rti_from_lpn : - other exception:'|| l_progress || ' ' ||
11151 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
11152       END IF;
11153       IF SQLCODE IS NOT NULL THEN
11154 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.create_rti_for_lpn',l_progress, SQLCODE);
11155       END IF;
11156       --  Get message count and data
11157       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => l_msg_count, p_data => x_msg_data);
11158 
11159 END create_rti_for_lpn;
11160 
11161 PROCEDURE explode_lpn_for_xfer_dlvr(p_transaction_type          IN varchar2
11162 				    ,p_lpn_id                    IN NUMBER
11163 				    ,p_rti_id                   IN NUMBER
11164 				    ,p_rti_lpn_id               IN NUMBER
11165 				    ,p_rti_xfer_lpn_id          IN NUMBER
11166 				    ,p_rti_xfer_lpn             IN VARCHAR2
11167 				    ,p_rti_to_organization_id   IN NUMBER
11168 				    ,x_return_status            OUT NOCOPY VARCHAR2
11169 				    ,x_msg_count                OUT NOCOPY NUMBER
11170 				    ,x_msg_data                 OUT NOCOPY VARCHAR2
11171 				    ) IS
11172    CURSOR c_mol_mmtt_ctnt_cur(v_lpn_id NUMBER ) IS
11173       SELECT mmtt.transaction_temp_id txn_tmp_id
11174 	,    mtrl.lpn_id
11175 	,    mtrl.inventory_item_id
11176 	,    mtrl.organization_id
11177 	,    mtrl.revision
11178 	,    mtrl.lot_number
11179 	,    mtrl.project_id
11180 	,    mtrl.task_id
11181 	,    mtrl.inspection_status
11182 	,    Nvl(mmtt.primary_quantity,mtrl.primary_quantity) prim_qty
11183 	,    Nvl(mmtt.transaction_quantity,mtrl.quantity-Nvl(mtrl.quantity_delivered,0)) txn_qty
11184 	,    Nvl(mmtt.transaction_uom,mtrl.uom_code) txn_uom_code
11185 	,    Nvl(mmtt.secondary_transaction_quantity
11186 	,    mtrl.secondary_quantity-Nvl(mtrl.secondary_quantity_delivered,0)) sec_qty --OPM Convergence
11187 	FROM   mtl_material_transactions_temp mmtt, mtl_txn_request_lines mtrl
11188 	WHERE  mmtt.move_order_line_id (+)= mtrl.line_id
11189 	AND    mtrl.lpn_id                = v_lpn_id
11190 	AND    mtrl.line_status           = 7
11191 	AND    mtrl.quantity-Nvl(mtrl.quantity_delivered,0) > 0
11192 	AND    exists (SELECT 1
11193 		       FROM  mtl_txn_request_headers mtrh
11194 		       WHERE mtrh.move_order_type = inv_globals.g_move_order_put_away
11195 		       AND   mtrh.header_id = mtrl.header_id);
11196 
11197    TYPE mol_mmtt_ctnt_tb_tp IS TABLE OF c_mol_mmtt_ctnt_cur%ROWTYPE;
11198    l_mol_mmtt_ctnt_tb mol_mmtt_ctnt_tb_tp;
11199 
11200    CURSOR c_rs_cursor(v_lpn_id NUMBER) IS
11201       SELECT rs.rcv_transaction_id         transaction_id
11202 	,    rs.item_id                inventory_item_id
11203 	,    rs.to_organization_id     organization_id
11204 	,    rs.item_revision          revision
11205 	,    Decode(rls.lot_num
11206 		    ,NULL
11207 		    ,rs.quantity
11208 		    ,rls.quantity)     quantity
11209 	,    rs.unit_of_measure        unit_of_measure
11210 	,    rls.lot_num               lot_number
11211 	,    NULL                      serial_number
11212 	,    Decode(rt.routing_header_id
11213 		    ,2
11214 		    ,Decode(rt.inspection_status_code
11215 			    -- Modified for the bug #: 6598429
11216 			    -- ,'ACCEPT'
11217 			    ,'ACCEPTED'
11218                             -- End of bug #: 6598429
11219 			    ,2
11220 			    ,Decode(rt.inspection_status_code
11221 				   -- Modified for the bug #: 6598429
11222 				   -- ,'REJECT'
11223 				   ,'REJECTED'
11224 				   -- End of bug #: 6598429
11225 				   ,3
11226 				    ,Decode(rt.inspection_status_code
11227 					    ,'NOT INSPECTED'
11228 					    ,1
11229 					    ,0)
11230 				    )
11231 			    )
11232 		    , NULL) inspection_status
11233 	,    rt.project_id             project_id
11234 	,    rt.task_id                task_id
11235 	FROM rcv_supply rs
11236 	,    rcv_lots_supply rls
11237 	,    rcv_transactions rt
11238 	WHERE rs.lpn_id = v_lpn_id
11239 	AND   rs.rcv_transaction_id = rls.transaction_id (+)
11240 	AND   rs.supply_type_code = 'RECEIVING'
11241 	AND   rs.rcv_transaction_id = rt.transaction_id
11242 	AND   NOT exists (SELECT 1
11243 			  FROM   rcv_serials_supply rss
11244 			  WHERE  rss.transaction_id = rs.rcv_transaction_id)
11245 	UNION
11246 	SELECT rs.rcv_transaction_id     transaction_id
11247 	,      rs.item_id                inventory_item_id
11248 	,      rs.to_organization_id     organization_id
11249 	,      rs.item_revision          revision
11250 	,      1
11251 	,      rs.unit_of_measure        unit_of_measure
11252 	,      rss.lot_num               lot_number
11253 	,      rss.serial_num            serial_number
11254 	,      Decode(rt.routing_header_id
11255 		      ,2
11256 		      ,Decode(rt.inspection_status_code
11257 			      -- Modified for the bug #: 6598429
11258 			      -- ,'ACCEPT'
11259 			       ,'ACCEPTED'
11260                               -- End of bug #: 6598429
11261 			      ,2
11262 			      ,Decode(rt.inspection_status_code
11263 				      -- Modified for the bug #: 6598429
11264                                       -- ,'REJECT'
11265 				      ,'REJECTED'
11266                                       -- End of bug #: 6598429
11267 				      ,3
11268 				      ,Decode(rt.inspection_status_code
11269 					      ,'NOT INSPECTED'
11270 					      ,1
11271 					      ,0)
11272 				      )
11273 			      )
11274 		      , NULL) inspection_status
11275 	,    rt.project_id             project_id
11276 	,    rt.task_id                task_id
11277 	FROM rcv_supply rs
11278 	,    rcv_serials_supply rss
11279 	,    rcv_transactions rt
11280 	WHERE rs.lpn_id = v_lpn_id
11281 	AND   rs.rcv_transaction_id = rss.transaction_id
11282 	AND   rs.supply_type_code = 'RECEIVING'
11283 	AND   rs.rcv_transaction_id = rt.transaction_id;
11284 
11285 
11286    TYPE rs_tb_tp IS TABLE OF c_rs_cursor%ROWTYPE;
11287    l_rs_tb rs_tb_tp;
11288 
11289    l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
11290    l_progress VARCHAR2(15) := '10';
11291    l_return_status VARCHAR2(1);
11292    l_msg_count     NUMBER;
11293    l_msg_data      VARCHAR2(2000);
11294    l_rs_index NUMBER;
11295    l_next_rs_index NUMBER;
11296    l_qty_to_match NUMBER;
11297    l_rs_uom_code  VARCHAR2(3);
11298    l_prim_uom_code VARCHAR2(3);
11299    l_avail_rs_qty NUMBER;
11300    l_avail_rs_prim_qty NUMBER;
11301    l_mmtt_to_insert NUMBER;
11302    l_qty_to_insert  NUMBER;
11303    l_xfer_lpn_id_to_insert NUMBER;
11304    l_xfer_lpn_to_insert VARCHAR2(30);
11305    l_transaction_id NUMBER;
11306    l_lot_interface_id NUMBER;
11307    l_serial_interface_id NUMBER;
11308    l_prim_qty_to_insert NUMBER;
11309    l_rti_index NUMBER;
11310    l_rti_serial_index NUMBER;
11311    l_sn_ctrl          NUMBER;
11312 
11313    l_serial_found     NUMBER;
11314    l_delete_rs        NUMBER;
11315 
11316    TYPE num_tb_tp IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
11317 
11318    TYPE rti_rec IS RECORD
11319      (quantity      NUMBER);
11320    TYPE rti_tb_tp IS TABLE OF rti_rec INDEX BY BINARY_INTEGER;
11321    l_rti_tb rti_tb_tp;
11322    TYPE serial_tb IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
11323    TYPE rti_serial_tb IS TABLE OF serial_tb INDEX BY BINARY_INTEGER;
11324    l_rti_serial_tb rti_serial_tb;
11325 BEGIN
11326 
11327    IF (l_debug = 1) THEN
11328       print_debug('Entering explode_lpn_for_xfer_dlvr',4);
11329       print_debug('p_lpn_id                 => '||p_lpn_id,4);
11330       print_debug('p_rti_lpn_id             => '||p_rti_lpn_id,4);
11331       print_debug('p_rti_xfer_lpn_id        => '||p_rti_xfer_lpn_id,4);
11332       print_debug('p_rti_xfer_lpn           => '||p_rti_xfer_lpn,4);
11333       print_debug('p_rti_to_organization_id => '||p_rti_to_organization_id,4);
11334    END IF;
11335 
11336    l_progress := '###';
11337    OPEN c_mol_mmtt_ctnt_cur(p_lpn_id);
11338    l_progress := '###';
11339    FETCH c_mol_mmtt_ctnt_cur bulk collect INTO l_mol_mmtt_ctnt_tb;
11340    l_progress := '###';
11341    CLOSE c_mol_mmtt_ctnt_cur;
11342 
11343    IF l_mol_mmtt_ctnt_tb.COUNT = 0 THEN
11344       IF (l_debug = 1) THEN
11345 	 print_debug('This LPN has no contents.  Returning success',4);
11346 	 RETURN;
11347       END IF;
11348     ELSE
11349       IF (l_debug = 1) THEN
11350 	 print_debug('Number of MOL/MMTT records: '||l_mol_mmtt_ctnt_tb.COUNT,4);
11351       END IF;
11352    END IF;
11353 
11354    l_progress := '###';
11355    OPEN c_rs_cursor(p_lpn_id);
11356    l_progress := '###';
11357    FETCH c_rs_cursor bulk collect INTO l_rs_tb;
11358    l_progress := '###';
11359    CLOSE c_rs_cursor;
11360    l_progress := '###';
11361 
11362    IF l_rs_tb.COUNT = 0 THEN
11363       IF (l_debug = 1) THEN
11364 	 print_debug('There is no RCV records, but LPN has contents.  How?',4);
11365       END IF;
11366       RAISE fnd_api.g_exc_error;
11367     ELSE
11368       IF (l_debug = 1) THEN
11369 	 print_debug('Number of RCV records: '||l_rs_tb.COUNT,4);
11370       END IF;
11371    END IF;
11372 
11373    FOR i IN 1..l_mol_mmtt_ctnt_tb.COUNT LOOP
11374       IF (l_debug = 1) THEN
11375 	 print_debug('i:'||i||
11376 		     ' item_id:'||l_mol_mmtt_ctnt_tb(i).inventory_item_id||
11377 		     ' revision:'||l_mol_mmtt_ctnt_tb(i).revision||
11378 		     ' lot_num:'||l_mol_mmtt_ctnt_tb(i).lot_number||
11379 		     ' qty:'|| l_mol_mmtt_ctnt_tb(i).txn_qty||
11380 		     ' uom:'|| l_mol_mmtt_ctnt_tb(i).txn_uom_code||
11381 		     ' insect_status:'||l_mol_mmtt_ctnt_tb(i).inspection_status||
11382 		     ' txn_tmp_id:'||l_mol_mmtt_ctnt_tb(i).txn_tmp_id
11383 		     ,4);
11384       END IF;
11385 
11386       l_progress := '###';
11387       l_qty_to_match := l_mol_mmtt_ctnt_tb(i).txn_qty;
11388       l_serial_found := 0;
11389       l_rs_index     := l_rs_tb.first;
11390       l_rti_tb.DELETE;
11391       l_rti_serial_tb.DELETE;
11392 
11393       l_prim_uom_code := inv_rcv_cache.get_primary_uom_code
11394 	                    (l_mol_mmtt_ctnt_tb(i).organization_id
11395 			     ,l_mol_mmtt_ctnt_tb(i).inventory_item_id);
11396       l_sn_ctrl := inv_rcv_cache.get_sn_ctrl_code
11397 	              (l_mol_mmtt_ctnt_tb(i).organization_id
11398 		       ,l_mol_mmtt_ctnt_tb(i).inventory_item_id);
11399 
11400       LOOP
11401 	 l_progress := '###';
11402 	 EXIT WHEN l_rs_index IS NULL;
11403 
11404 	 l_delete_rs    := 0;
11405 
11406 	 IF (l_debug = 1) THEN
11407 	    print_debug('l_rs_index:'||l_rs_index||
11408 			' rcv_txn_id:'||l_rs_tb(l_rs_index).transaction_id||
11409 			' item_id:'||l_rs_tb(l_rs_index).inventory_item_id||
11410 			' revision:'||l_rs_tb(l_rs_index).revision||
11411 			' lot_num:'||l_rs_tb(l_rs_index).lot_number||
11412 			' ser_num:'||l_rs_tb(l_rs_index).serial_number||
11413 			' qty:'|| l_rs_tb(l_rs_index).quantity||
11414 			' uom:'|| l_rs_tb(l_rs_index).unit_of_measure||
11415 			' insect_status:'||l_rs_tb(l_rs_index).inspection_status
11416 			,4);
11417 	 END IF;
11418 
11419 	 IF (l_mol_mmtt_ctnt_tb(i).organization_id = l_rs_tb(l_rs_index).organization_id
11420 	     AND l_mol_mmtt_ctnt_tb(i).inventory_item_id = l_rs_tb(l_rs_index).inventory_item_id
11421 	     AND Nvl(l_mol_mmtt_ctnt_tb(i).revision,'#$#') = Nvl(l_rs_tb(l_rs_index).revision,'#$#')
11422 	     AND Nvl(l_mol_mmtt_ctnt_tb(i).lot_number,'#$#') = Nvl(l_rs_tb(l_rs_index).lot_number,'#$#')
11423 	     AND Nvl(l_mol_mmtt_ctnt_tb(i).inspection_status,0) = Nvl(l_rs_tb(l_rs_index).inspection_status,0)
11424 	     AND Nvl(l_mol_mmtt_ctnt_tb(i).project_id,-1) = Nvl(l_rs_tb(l_rs_index).project_id,-1)
11425 	     AND Nvl(l_mol_mmtt_ctnt_tb(i).task_id,-1) = Nvl(l_rs_tb(l_rs_index).task_id,-1))
11426 	   THEN
11427 
11428 	    IF l_rs_tb(l_rs_index).serial_number IS NULL THEN--Non-serialized item
11429 
11430 	       BEGIN
11431 		  SELECT uom_code
11432 		    into l_rs_uom_code
11433 		    FROM mtl_item_uoms_view
11434 		    WHERE organization_id = l_rs_tb(l_rs_index).organization_id
11435 		    AND inventory_item_id = l_rs_tb(l_rs_index).inventory_item_id
11436 		    AND unit_of_measure = l_rs_tb(l_rs_index).unit_of_measure;
11437 	       EXCEPTION
11438 		  WHEN OTHERS THEN
11439 		     IF (l_debug = 1) THEN
11440 			print_debug('Error retrieving uom_code', 1);
11441 		     END IF;
11442 		     l_progress := 'WMSINB-11065';
11443 		     RAISE fnd_api.g_exc_error;
11444 	       END;
11445 
11446 	       IF l_mol_mmtt_ctnt_tb(i).txn_uom_code <> l_rs_uom_code THEN
11447 		  l_avail_rs_qty := inv_rcv_cache.convert_qty(l_rs_tb(l_rs_index).inventory_item_id
11448 						,l_rs_tb(l_rs_index).quantity
11449 						,l_rs_uom_code
11450 						,l_mol_mmtt_ctnt_tb(i).txn_uom_code);
11451 		ELSE
11452 		  l_avail_rs_qty := l_rs_tb(l_rs_index).quantity;
11453 	       END IF;
11454 
11455 	       IF l_qty_to_match > l_avail_rs_qty THEN
11456 
11457 		  IF (l_mol_mmtt_ctnt_tb(i).txn_tmp_id IS NOT NULL) then
11458 		     IF (l_mol_mmtt_ctnt_tb(i).txn_uom_code <> l_prim_uom_code) THEN
11459 			l_avail_rs_prim_qty := inv_rcv_cache.convert_qty(l_rs_tb(l_rs_index).inventory_item_id
11460 							   ,l_avail_rs_qty
11461 							   ,l_mol_mmtt_ctnt_tb(i).txn_uom_code
11462 							   ,l_prim_uom_code);
11463 		      ELSE
11464 			l_avail_rs_prim_qty := l_avail_rs_qty;
11465 		     END IF;
11466 
11467 		     inv_rcv_integration_apis.split_mmtt
11468 		       (p_orig_mmtt_id      => l_mol_mmtt_ctnt_tb(i).txn_tmp_id
11469 			,p_prim_qty_to_splt => l_avail_rs_prim_qty
11470 			,p_prim_uom_code    => l_prim_uom_code
11471 			,x_new_mmtt_id      => l_mmtt_to_insert
11472 			,x_return_status    => l_return_status
11473 			,x_msg_count        => l_msg_count
11474 			,x_msg_data         => l_msg_data
11475 			);
11476 		   ELSE
11477 		     l_mmtt_to_insert := NULL;
11478 		  END IF;--IF (l_mol_mmtt_ctnt_tb(i).txn_tmp_id IS NOT NULL) then
11479 
11480 		  l_qty_to_insert    := l_avail_rs_qty;
11481 		  l_qty_to_match     := l_qty_to_match - l_avail_rs_qty;
11482 
11483 		  l_delete_rs := 1;
11484 		ELSE
11485 		  l_mmtt_to_insert   := l_mol_mmtt_ctnt_tb(i).txn_tmp_id;
11486 		  l_qty_to_insert    := l_qty_to_match;
11487 		  l_qty_to_match     := 0;
11488 
11489 		  IF l_mol_mmtt_ctnt_tb(i).txn_uom_code <> l_rs_uom_code THEN
11490 		     l_rs_tb(l_rs_index).quantity := l_rs_tb(l_rs_index).quantity -
11491 		                                     inv_rcv_cache.convert_qty
11492 		                                        (l_rs_tb(l_rs_index).inventory_item_id
11493 							 ,l_qty_to_match
11494 							 ,l_mol_mmtt_ctnt_tb(i).txn_uom_code
11495 							 ,l_rs_uom_code);
11496 		   ELSE
11497 		     l_rs_tb(l_rs_index).quantity := l_rs_tb(l_rs_index).quantity-l_qty_to_match;
11498 		  END IF;
11499 
11500 		  l_delete_rs := 0;
11501 
11502 	       END IF;--IF l_qty_to_match > l_avail_rs_qty THEN
11503 
11504 	       IF ( p_lpn_id <> p_rti_lpn_id) then
11505 		  -- Create a new RTI row with flpn=childlpn and tlpn = childlpn;
11506 		  l_xfer_lpn_id_to_insert := p_lpn_id;
11507 		  l_xfer_lpn_to_insert := NULL;
11508 		ELSE
11509 		  -- Create a new RTI row with flpn=childlpn and tlpn = tlpn;
11510 		  l_xfer_lpn_id_to_insert := p_rti_xfer_lpn_id;
11511 		  l_xfer_lpn_to_insert := p_rti_xfer_lpn;
11512 	       END IF;
11513 
11514 	       create_rti_for_lpn(p_transaction_type         => p_transaction_type,
11515 				  p_interface_transaction_id => p_rti_id,
11516 				  p_lpn_id                   => l_mol_mmtt_ctnt_tb(i).lpn_id,
11517 				  p_item_id                  => l_mol_mmtt_ctnt_tb(i).inventory_item_id,
11518 				  p_org_id                   => l_mol_mmtt_ctnt_tb(i).organization_id,
11519 				  p_to_org_id                => p_rti_to_organization_id,
11520 				  p_item_desc                => '',
11521 				  p_item_revision            => l_mol_mmtt_ctnt_tb(i).revision,
11522 				  p_quantity                 => l_qty_to_insert,
11523 				  p_txn_uom_code             => l_mol_mmtt_ctnt_tb(i).txn_uom_code,
11524 				  p_transfer_lpn_id          => l_xfer_lpn_id_to_insert,
11525 				  p_transfer_lpn             => l_xfer_lpn_to_insert,
11526 				  p_txn_source_id            => l_rs_tb(l_rs_index).transaction_id,
11527 				  p_mmtt_temp_id             => l_mmtt_to_insert,
11528 				  p_project_id               => l_mol_mmtt_ctnt_tb(i).project_id,
11529 				  p_task_id                  => l_mol_mmtt_ctnt_tb(i).task_id,
11530 				  x_interface_transaction_id => l_transaction_id,
11531 		                  x_return_status            => x_return_status,
11532 		                  x_msg_count                => l_msg_count,
11533 		                  x_msg_data                 => l_msg_data
11534 		 );
11535 
11536 	       IF  x_return_status <> G_RET_STS_SUCCESS Then
11537 		  -- MSG no new message just add the one on stack
11538 		  -- Check the Error Status from this call
11539 		  l_progress := 'WMSINB-17580';
11540 		  RAISE FND_API.G_EXC_ERROR;
11541 	       END IF;
11542 
11543 	       IF (l_mol_mmtt_ctnt_tb(i).lot_number IS NOT NULL) THEN
11544 		  IF l_lot_interface_id IS NULL THEN
11545 		     SELECT mtl_material_transactions_s.NEXTVAL
11546 		       INTO l_lot_interface_id
11547 		       FROM DUAL;
11548 		  END IF;
11549 
11550 		  IF (l_mol_mmtt_ctnt_tb(i).txn_uom_code <> l_prim_uom_code) THEN
11551 		     l_prim_qty_to_insert := inv_rcv_cache.convert_qty(l_rs_tb(l_rs_index).inventory_item_id
11552 							,l_qty_to_insert
11553 							,l_mol_mmtt_ctnt_tb(i).txn_uom_code
11554 							,l_prim_uom_code);
11555 		   ELSE
11556 		     l_prim_qty_to_insert := l_qty_to_insert;
11557 		  END IF;
11558 
11559 
11560 		  insert_mtli(p_product_transaction_id   => l_transaction_id,
11561 			      p_product_code             => 'RCV',
11562 			      p_interface_id             => l_lot_Interface_Id,
11563 			      p_org_id                   => l_mol_mmtt_ctnt_tb(i).organization_id,
11564 			      p_item_id                  => l_mol_mmtt_ctnt_tb(i).inventory_item_id,
11565 			      p_lot_number               => l_mol_mmtt_ctnt_tb(i).lot_number,
11566 			      p_transaction_quantity     => l_qty_to_insert,
11567 			      p_primary_quantity         => l_prim_qty_to_insert,
11568 			      p_serial_interface_id      => NULL ,
11569 			      x_return_status            => l_return_status,
11570 			      x_msg_count                => l_msg_count,
11571 			      x_msg_data                 => l_msg_data
11572 			      );
11573 
11574 		  -- Check the error status from the above call
11575 		  IF x_return_status <> G_RET_STS_SUCCESS Then
11576 		     -- MSG no new message just add the one on stack
11577 		     --  Review Late Set Appropiate Message
11578 		     NULL;
11579 		  END IF ;
11580 
11581 	       END IF;--IF (l_mol_mmtt_ctnt_tb(i).lot_number IS NOT NULL) THEN
11582 
11583 	     ELSE --Item is serial controlled
11584 	       l_serial_found := 1;
11585 	       l_rti_index := l_rs_tb(l_rs_index).transaction_id;
11586 
11587 	       IF l_rti_tb.exists(l_rti_index) THEN
11588 		  l_rti_tb(l_rti_index).quantity := l_rti_tb(l_rti_index).quantity + 1;
11589 		ELSE
11590 		  l_rti_tb(l_rti_index).quantity := 1;
11591 	       END IF;
11592 
11593 	       IF l_rti_serial_tb.exists(l_rti_index) THEN
11594 		  l_rti_serial_index := l_rti_serial_tb(l_rti_index).COUNT  + 1;
11595 		ELSE
11596 		  l_rti_serial_index := 1;
11597 	       END IF;
11598 	       l_rti_serial_tb(l_rti_index)(l_rti_serial_index) := l_rs_tb(l_rs_index).serial_number;
11599 	       l_qty_to_match := l_qty_to_match - 1;
11600 	       l_delete_rs := 1;
11601 
11602 	    END IF;--IF l_rs_tb(l_rs_index).serial_number IS NULL THEN
11603 
11604 	    IF (l_delete_rs = 1) THEN
11605 	       l_next_rs_index := l_rs_tb.next(l_rs_index);
11606 	       l_rs_tb.DELETE(l_rs_index);
11607 	       l_rs_index := l_next_rs_index;
11608 	     ELSE
11609 	       l_rs_index := l_rs_tb.next(l_rs_index);
11610 	    END IF;
11611 
11612 	    IF (l_qty_to_match <= 0) THEN
11613 	       EXIT;
11614 	    END IF;
11615 	  ELSE
11616 	       l_rs_index := l_rs_tb.next(l_rs_index);
11617 	 END IF;--IF (l_mol_mmtt_ctnt_tb(i).organization_id = l_rs_tb(l_rs_index).organization_id
11618 
11619 
11620       END LOOP;--l_rs_index := l_rs_tb.first;-
11621 
11622       IF (l_serial_found = 1) THEN
11623 	 l_serial_interface_id := NULL;
11624 	 l_lot_interface_id := NULL;
11625 	 l_rti_index := l_rti_tb.first;
11626 
11627 	 LOOP
11628 	    EXIT WHEN l_rti_index IS NULL OR l_mol_mmtt_ctnt_tb(i).txn_qty <= 0;
11629 
11630 	    l_serial_interface_id := NULL;
11631 	    l_lot_interface_id := NULL;
11632 
11633 	    IF (l_debug = 1) THEN
11634 	       print_debug('Insert rti with txn_id: '||l_rti_index,4);
11635 	    END IF;
11636 
11637 	    IF (l_mol_mmtt_ctnt_tb(i).txn_qty > l_rti_tb(l_rti_index).quantity) THEN
11638 	       IF (l_mol_mmtt_ctnt_tb(i).txn_tmp_id IS NOT NULL) then
11639 		  inv_rcv_integration_apis.split_mmtt
11640 		    (p_orig_mmtt_id      => l_mol_mmtt_ctnt_tb(i).txn_tmp_id
11641 		     ,p_prim_qty_to_splt => l_rti_tb(l_rti_index).quantity
11642 		     ,p_prim_uom_code    => l_prim_uom_code
11643 		     ,x_new_mmtt_id      => l_mmtt_to_insert
11644 		     ,x_return_status    => l_return_status
11645 		     ,x_msg_count        => l_msg_count
11646 		     ,x_msg_data         => l_msg_data
11647 		     );
11648 		ELSE
11649 		  l_mmtt_to_insert := NULL;
11650 	       END IF;
11651 
11652 	       l_mol_mmtt_ctnt_tb(i).txn_qty := l_mol_mmtt_ctnt_tb(i).txn_qty - l_rti_tb(l_rti_index).quantity;
11653 	     ELSE
11654 	       l_mmtt_to_insert := l_mol_mmtt_ctnt_tb(i).txn_tmp_id;
11655 	       l_mol_mmtt_ctnt_tb(i).txn_qty := 0;
11656 	    END IF;
11657 
11658 	    IF ( p_lpn_id <> p_rti_lpn_id) then
11659 	       -- Create a new RTI row with flpn=childlpn and tlpn = childlpn;
11660 	       l_xfer_lpn_id_to_insert := p_lpn_id;
11661 	       l_xfer_lpn_to_insert := NULL;
11662 	     ELSE
11663 	       -- Create a new RTI row with flpn=childlpn and tlpn = tlpn;
11664 	       l_xfer_lpn_id_to_insert := p_rti_xfer_lpn_id;
11665 	       l_xfer_lpn_to_insert := p_rti_xfer_lpn;
11666 	    END IF;
11667 
11668 	    create_rti_for_lpn(p_transaction_type         => p_transaction_type,
11669 			       p_interface_transaction_id => p_rti_id,
11670 			       p_lpn_id                   => l_mol_mmtt_ctnt_tb(i).lpn_id,
11671 			       p_item_id                  => l_mol_mmtt_ctnt_tb(i).inventory_item_id,
11672 			       p_org_id                   => l_mol_mmtt_ctnt_tb(i).organization_id,
11673 			       p_to_org_id                => p_rti_to_organization_id,
11674 			       p_item_desc                => '',
11675 			       p_item_revision            => l_mol_mmtt_ctnt_tb(i).revision,
11676 			       p_quantity                 => l_rti_tb(l_rti_index).quantity,
11677 			       p_txn_uom_code             => l_mol_mmtt_ctnt_tb(i).txn_uom_code,
11678 			       p_transfer_lpn_id          => l_xfer_lpn_id_to_insert,
11679 			       p_transfer_lpn             => l_xfer_lpn_to_insert,
11680 			       p_txn_source_id            => l_rti_index,
11681 			       p_mmtt_temp_id             => l_mmtt_to_insert,
11682 			       p_project_id               => l_mol_mmtt_ctnt_tb(i).project_id,
11683 			       p_task_id                  => l_mol_mmtt_ctnt_tb(i).task_id,
11684 	                       x_interface_transaction_id => l_transaction_id,
11685 	                       x_return_status            => x_return_status,
11686 	                       x_msg_count                => l_msg_count,
11687 	                       x_msg_data                 => l_msg_data
11688 	      );
11689 
11690 	    IF  x_return_status <> G_RET_STS_SUCCESS Then
11691 	       -- MSG no new message just add the one on stack
11692 	       -- Check the Error Status from this call
11693 	       l_progress := 'WMSINB-17580';
11694 	       RAISE FND_API.G_EXC_ERROR;
11695 	    END IF;
11696 
11697 	    FOR j IN 1..l_rti_serial_tb(l_rti_index).COUNT LOOP
11698 	       IF l_serial_interface_id IS NULL THEN
11699 		  SELECT mtl_material_transactions_s.NEXTVAL
11700 		    INTO l_serial_Interface_Id
11701 		    FROM DUAL;
11702 	       END IF;
11703 
11704 	       IF (l_debug = 1) THEN
11705 		  print_debug('Inserting MSNI for serial: '||l_rti_serial_tb(l_rti_index)(j),4);
11706 	       END IF;
11707 
11708 	       insert_msni(p_product_transaction_id   => l_transaction_id,
11709 			   p_product_code             => 'RCV',
11710 			   p_interface_id             => l_serial_interface_id,
11711 			   p_item_id                  => l_mol_mmtt_ctnt_tb(i).inventory_item_id,
11712 			   p_lot_number               => l_mol_mmtt_ctnt_tb(i).lot_number,
11713 			   p_fm_serial_number         => l_rti_serial_tb(l_rti_index)(j),
11714 			   p_to_serial_number         => l_rti_serial_tb(l_rti_index)(j),
11715 			   x_return_status            => l_return_status,
11716 			   x_msg_count                => l_msg_count,
11717 			   x_msg_data                 => l_msg_data
11718 		 );
11719 
11720 	       -- Check the error status from the above call
11721 	       if x_return_status <> G_RET_STS_SUCCESS Then
11722 		  --  Review Late Set Appropiate Message
11723 		  EXIT; -- Exit from the Loop
11724 	       END IF;
11725 	    END LOOP;--FOR j IN 1..l_rti_serial_tb(l_rti_index).COUNT LOOP
11726 
11727 	    IF (l_mol_mmtt_ctnt_tb(i).lot_number IS NOT NULL) THEN
11728 	       IF l_lot_interface_id IS NULL THEN
11729 		  SELECT mtl_material_transactions_s.NEXTVAL
11730 		    INTO l_lot_interface_id
11731 		    FROM DUAL;
11732 	       END IF;
11733 
11734 	       IF (l_debug = 1) THEN
11735 		  print_debug('Inserting MTLI for lot: '||l_mol_mmtt_ctnt_tb(i).lot_number||
11736 			      ' qty: '||l_rti_tb(l_rti_index).quantity,4);
11737 	       END IF;
11738 
11739 	       insert_mtli(p_product_transaction_id   => l_transaction_id,
11740 			   p_product_code             => 'RCV',
11741 			   p_interface_id             => l_lot_Interface_Id,
11742 			   p_org_id                   => l_mol_mmtt_ctnt_tb(i).organization_id,
11743 			   p_item_id                  => l_mol_mmtt_ctnt_tb(i).inventory_item_id,
11744 			   p_lot_number               => l_mol_mmtt_ctnt_tb(i).lot_number,
11745 			   p_transaction_quantity     => l_rti_tb(l_rti_index).quantity,
11746 			   p_primary_quantity         => l_rti_tb(l_rti_index).quantity,
11747 			   p_serial_interface_id      => l_serial_interface_id,
11748 			   x_return_status            => l_return_status,
11749 			   x_msg_count                => l_msg_count,
11750 			   x_msg_data                 => l_msg_data
11751 			   );
11752 
11753 	       -- Check the error status from the above call
11754 	       IF x_return_status <> G_RET_STS_SUCCESS Then
11755 		  -- MSG no new message just add the one on stack
11756 		  --  Review Late Set Appropiate Message
11757 		  NULL;
11758 	       END IF ;
11759 	    END IF;--IF (l_mol_mmtt_ctnt_tb(i).lot_number IS NOT NULL) THEN
11760 
11761 	    l_rti_index := l_rti_tb.next(l_rti_index);
11762 
11763 	 END LOOP;--l_rti_index := l_rti_tb.first;
11764 
11765 	 IF l_qty_to_match > 0 THEN
11766 	    IF (l_debug = 1) THEN
11767 	       print_debug('Have finished looking at RS.  Qty still remaining. how???',4);
11768 	    END IF;
11769 	    RAISE fnd_api.g_exc_error;
11770 	 END IF;
11771 
11772       END IF; --IF (l_serial_found = 1) THEN
11773 
11774    END LOOP; --FOR i IN 1..l_mol_mmtt_ctnt_tb.COUNT LOOP
11775 
11776 EXCEPTION
11777    WHEN OTHERS THEN
11778       x_return_status  := g_ret_sts_unexp_error;
11779       IF (l_debug = 1) THEN
11780          print_debug('explode_lpn_for_xfer_dlvr : - other exception:'|| l_progress || ' ' ||
11781 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
11782       END IF;
11783 END explode_lpn_for_xfer_dlvr;
11784 
11785 -- Description
11786 -- This API create the WLPNI for the VALUES PASSED
11787 -- This is needed only for Changing Parents
11788 PROCEDURE insert_wlpni(              p_LPN_ID                        IN NUMBER ,
11789                                      p_LICENSE_PLATE_NUMBER          IN VARCHAR2 DEFAULT NULL,
11790                                      p_PARENT_LPN_ID                 IN NUMBER,
11791                                      p_PARENT_LICENSE_PLATE_NUMBER   IN VARCHAR2 DEFAULT NULL,
11792                                      p_REQUEST_ID                    IN NUMBER   DEFAULT NULL,
11793                                      p_INVENTORY_ITEM_ID             IN NUMBER   DEFAULT NULL,
11794                                      p_REVISION                      IN VARCHAR2 DEFAULT NULL,
11795                                      p_LOT_NUMBER                    IN VARCHAR2 DEFAULT NULL,
11796                                      p_SERIAL_NUMBER                 IN VARCHAR2 DEFAULT NULL,
11797                                      p_ORGANIZATION_ID               IN NUMBER ,
11798                                      p_SUBINVENTORY_CODE             IN VARCHAR2 DEFAULT NULL,
11799 				     p_LOCATOR_ID                    IN NUMBER   DEFAULT NULL,
11800   p_GROSS_WEIGHT_UOM_CODE         IN VARCHAR2 DEFAULT NULL,
11801   p_GROSS_WEIGHT                  IN NUMBER   DEFAULT NULL,
11802   p_CONTENT_VOLUME_UOM_CODE       IN VARCHAR2 DEFAULT NULL,
11803   p_CONTENT_VOLUME                IN NUMBER   DEFAULT NULL,
11804   p_TARE_WEIGHT_UOM_CODE          IN VARCHAR2 DEFAULT NULL,
11805   p_TARE_WEIGHT                   IN NUMBER   DEFAULT NULL,
11806   p_STATUS_ID                     IN NUMBER   DEFAULT NULL,
11807   p_SEALED_STATUS                 IN NUMBER   DEFAULT NULL,
11808   p_ATTRIBUTE_CATEGORY            IN VARCHAR2 DEFAULT NULL,
11809   p_ATTRIBUTE1                    IN VARCHAR2 DEFAULT NULL,
11810   p_ATTRIBUTE2                    IN VARCHAR2 DEFAULT NULL,
11811   p_ATTRIBUTE3                    IN VARCHAR2 DEFAULT NULL,
11812   p_ATTRIBUTE4                    IN VARCHAR2 DEFAULT NULL,
11813   p_ATTRIBUTE5                    IN VARCHAR2 DEFAULT NULL,
11814   p_ATTRIBUTE6                    IN VARCHAR2 DEFAULT NULL,
11815   p_ATTRIBUTE7                    IN VARCHAR2 DEFAULT NULL,
11816   p_ATTRIBUTE8                    IN VARCHAR2 DEFAULT NULL,
11817   p_ATTRIBUTE9                    IN VARCHAR2 DEFAULT NULL,
11818   p_ATTRIBUTE10                   IN VARCHAR2 DEFAULT NULL,
11819   p_ATTRIBUTE11                   IN VARCHAR2 DEFAULT NULL,
11820   p_ATTRIBUTE12                   IN VARCHAR2 DEFAULT NULL,
11821   p_ATTRIBUTE13                   IN VARCHAR2 DEFAULT NULL,
11822   p_ATTRIBUTE14                   IN VARCHAR2 DEFAULT NULL,
11823   p_ATTRIBUTE15                   IN VARCHAR2 DEFAULT NULL,
11824   p_COST_GROUP_ID                 IN NUMBER   DEFAULT NULL,
11825   p_LPN_CONTEXT                   IN NUMBER   DEFAULT NULL,
11826   p_LPN_REUSABILITY               IN NUMBER   DEFAULT NULL,
11827   p_OUTERMOST_LPN_ID              IN NUMBER   DEFAULT NULL,
11828   p_outermost_lpn                 IN VARCHAR2 DEFAULT NULL,
11829   p_HOMOGENEOUS_CONTAINER         IN NUMBER   DEFAULT NULL,
11830   p_SOURCE_TYPE_ID                IN NUMBER   DEFAULT NULL,
11831   p_SOURCE_HEADER_ID              IN NUMBER   DEFAULT NULL,
11832   p_SOURCE_LINE_ID                IN NUMBER   DEFAULT NULL,
11833   p_SOURCE_LINE_DETAIL_ID         IN NUMBER   DEFAULT NULL,
11834   p_SOURCE_NAME                   IN VARCHAR2 DEFAULT NULL,
11835   p_LPN_GROUP_ID                  IN NUMBER,
11836   x_return_status                 OUT NOCOPY VARCHAR2,
11837   x_msg_count                     OUT NOCOPY NUMBER,
11838   x_msg_data                      OUT NOCOPY VARCHAR2)
11839   is
11840      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
11841      l_progress VARCHAR2(15) := '10';
11842      l_msg_count number;
11843      l_msg_data VARCHAR2(2000);
11844 
11845 
11846      l_sysdate DATE := SYSDATE;
11847      l_user     NUMBER;
11848      l_login_id NUMBER;
11849 
11850 BEGIN
11851    x_return_status := g_ret_sts_success;
11852 
11853    l_progress := 'WMSINB-16824';
11854 
11855    l_user        := fnd_global.user_id;
11856    l_login_id       := fnd_global.login_id;
11857 
11858 
11859    IF (l_debug = 1) THEN
11860       print_debug('insert_wlpni : - WLPNI for LPNID = ' || p_lpn_id || ' LPN =' ||
11861 		  p_license_plate_number || ' '||  TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
11862    END IF;
11863 
11864    insert into wms_lpn_interface (
11865 				   LPN_ID                                 ,
11866 				   LICENSE_PLATE_NUMBER                   ,
11867 				   INVENTORY_ITEM_ID                      ,
11868 				   LAST_UPDATE_DATE                       ,
11869 				   LAST_UPDATED_BY                        ,
11870 				   CREATION_DATE                          ,
11871 				   CREATED_BY                             ,
11872 				   LAST_UPDATE_LOGIN                      ,
11873 				   REQUEST_ID                             ,
11874 				   PROGRAM_APPLICATION_ID                 ,
11875 				   PROGRAM_ID                             ,
11876 				   PROGRAM_UPDATE_DATE                    ,
11877 				   REVISION                               ,
11878 				   LOT_NUMBER                             ,
11879 				   SERIAL_NUMBER                          ,
11880 				   ORGANIZATION_ID                        ,
11881 				   SUBINVENTORY_CODE                      ,
11882 				   LOCATOR_ID                             ,
11883 				   PARENT_LPN_ID                          ,
11884 				   PARENT_LICENSE_PLATE_NUMBER            ,
11885 				   GROSS_WEIGHT_UOM_CODE                  ,
11886      GROSS_WEIGHT                           ,
11887      CONTENT_VOLUME_UOM_CODE                ,
11888      CONTENT_VOLUME                         ,
11889      TARE_WEIGHT_UOM_CODE                   ,
11890      TARE_WEIGHT                            ,
11891      STATUS_ID                              ,
11892      SEALED_STATUS                          ,
11893      ATTRIBUTE_CATEGORY                     ,
11894      ATTRIBUTE1                             ,
11895      ATTRIBUTE2                             ,
11896      ATTRIBUTE3                             ,
11897      ATTRIBUTE4                             ,
11898      ATTRIBUTE5                             ,
11899      ATTRIBUTE6                             ,
11900      ATTRIBUTE7                             ,
11901      ATTRIBUTE8                             ,
11902      ATTRIBUTE9                             ,
11903      ATTRIBUTE10                            ,
11904      ATTRIBUTE11                            ,
11905      ATTRIBUTE12                            ,
11906      ATTRIBUTE13                            ,
11907      ATTRIBUTE14                            ,
11908      ATTRIBUTE15                            ,
11909      COST_GROUP_ID                          ,
11910      LPN_CONTEXT                            ,
11911      LPN_REUSABILITY                        ,
11912      OUTERMOST_LPN_ID                       ,
11913      HOMOGENEOUS_CONTAINER                  ,
11914      SOURCE_TYPE_ID                         ,
11915      SOURCE_HEADER_ID                       ,
11916      SOURCE_LINE_ID                         ,
11917      SOURCE_LINE_DETAIL_ID                  ,
11918      SOURCE_NAME                            ,
11919      SOURCE_GROUP_ID                       )
11920      values
11921      (
11922       p_LPN_ID                                 ,
11923       p_LICENSE_PLATE_NUMBER                   ,
11924       p_INVENTORY_ITEM_ID                      ,
11925       l_sysdate                       ,
11926       l_user                        ,
11927       l_sysdate                          ,
11928       l_user                             ,
11929       l_login_id                      ,
11930       p_REQUEST_ID                             ,
11931       null, --PROGRAM_APPLICATION_ID
11932       null, -- PROGRAM_ID
11933       null, -- PROGRAM_UPDATE_DATE
11934       p_REVISION                               ,
11935       p_LOT_NUMBER                             ,
11936       p_SERIAL_NUMBER                          ,
11937       p_ORGANIZATION_ID                        ,
11938       p_SUBINVENTORY_CODE                      ,
11939       p_LOCATOR_ID                             ,
11940       p_PARENT_LPN_ID                          ,
11941       p_PARENT_LICENSE_PLATE_NUMBER            ,
11942       p_GROSS_WEIGHT_UOM_CODE                  ,
11943      p_GROSS_WEIGHT                           ,
11944      p_CONTENT_VOLUME_UOM_CODE                ,
11945      p_CONTENT_VOLUME                         ,
11946      p_TARE_WEIGHT_UOM_CODE                   ,
11947      p_TARE_WEIGHT                            ,
11948      p_STATUS_ID                              ,
11949      p_SEALED_STATUS                          ,
11950      p_ATTRIBUTE_CATEGORY                     ,
11951      p_ATTRIBUTE1                             ,
11952      p_ATTRIBUTE2                             ,
11953      p_ATTRIBUTE3                             ,
11954      p_ATTRIBUTE4                             ,
11955      p_ATTRIBUTE5                             ,
11956      p_ATTRIBUTE6                             ,
11957      p_ATTRIBUTE7                             ,
11958      p_ATTRIBUTE8                             ,
11959      p_ATTRIBUTE9                             ,
11960      p_ATTRIBUTE10                            ,
11961      p_ATTRIBUTE11                            ,
11962      p_ATTRIBUTE12                            ,
11963      p_ATTRIBUTE13                            ,
11964      p_ATTRIBUTE14                            ,
11965      p_ATTRIBUTE15                            ,
11966      p_COST_GROUP_ID                          ,
11967      p_LPN_CONTEXT                            ,
11968      p_LPN_REUSABILITY                        ,
11969      p_OUTERMOST_LPN_ID                       ,
11970      p_HOMOGENEOUS_CONTAINER                  ,
11971      p_SOURCE_TYPE_ID                         ,
11972      p_SOURCE_HEADER_ID                       ,
11973      p_SOURCE_LINE_ID                         ,
11974      p_SOURCE_LINE_DETAIL_ID                  ,
11975      p_SOURCE_NAME                            ,
11976      p_LPN_GROUP_ID  );
11977 
11978    IF (l_debug = 1) THEN
11979       print_debug('insert_wlpni : - End of Insertioin in WLPNI for LPNID = ' || p_lpn_id || ' LPN =' ||
11980 		  p_license_plate_number || ' '||  TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
11981    END IF;
11982 
11983 EXCEPTION
11984    when others then
11985       x_return_status  := g_ret_sts_unexp_error;
11986       IF (l_debug = 1) THEN
11987          print_debug('insert_wlpni : - other exception:'|| l_progress || ' ' ||
11988 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
11989       END IF;
11990       IF SQLCODE IS NOT NULL THEN
11991 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.insert_wlpni',l_progress, SQLCODE);
11992       END IF;
11993       --  Get message count and data
11994       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
11995 
11996 END insert_wlpni;
11997 
11998 
11999 -- Description
12000 -- This procedure creates a LPN from a WLPNI row
12001 --
12002 PROCEDURE create_lpn_from_wlpni(p_license_plate_number IN VARCHAR2,
12003                                 p_lpn_group_id     IN NUMBER,
12004                                 p_organization_id  IN NUMBER,
12005                                 p_lpn_context      IN NUMBER default 5 , -- defined but not used
12006                                 p_source_header_id IN NUMBER default null ,
12007                                 p_source_type_id   IN NUMBER default null ,
12008                                 x_lpn_id           OUT NOCOPY NUMBER,
12009                                 x_return_status    OUT NOCOPY VARCHAR2,
12010                                 x_msg_count        OUT NOCOPY NUMBER,
12011                                 x_msg_data         OUT NOCOPY VARCHAR2)
12012   is
12013 
12014      l_license_plate_number  varchar2(30);
12015      l_subinventory_code     varchar2(30);
12016      l_locator_id            NUMBER;
12017      l_cost_group_id         NUMBER;
12018      l_source_type_id        NUMBER;
12019      l_source_header_id      NUMBER;
12020      l_source_name           VARCHAR2(30);
12021      l_source_line_id        NUMBER;
12022      l_source_line_detail_id NUMBER;
12023      l_parent_lpn_id         NUMBER;
12024 
12025      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
12026      l_progress VARCHAR2(15) := '10';
12027      l_msg_count number;
12028      l_msg_data VARCHAR2(2000);
12029      l_lpn_id   NUMBER;
12030 
12031 BEGIN
12032    x_return_status := g_ret_sts_success;
12033 
12034    l_progress := 'WMSINB-17003';
12035 
12036 BEGIN
12037    SELECT DISTINCT
12038      license_plate_number,
12039      subinventory_code,
12040      locator_id,
12041      cost_group_id,
12042      source_type_id,
12043      source_header_id,
12044      source_name,
12045      source_line_id,
12046      source_line_detail_id,
12047      parent_lpn_id
12048      INTO
12049      l_license_plate_number,
12050      l_subinventory_code,
12051      l_locator_id,
12052      l_cost_group_id,
12053      l_source_type_id,
12054      l_source_header_id,
12055      l_source_name,
12056      l_source_line_id,
12057      l_source_line_detail_id,
12058      l_parent_lpn_id
12059      FROM wms_lpn_interface wlpni
12060      WHERE wlpni.license_plate_number = p_license_plate_number
12061      AND wlpni.source_group_id = p_lpn_group_id;
12062 EXCEPTION
12063    WHEN no_data_found THEN
12064       IF (l_debug = 1) THEN
12065 	 print_debug('CREATE_LPN_FROM_WLPNI - WLPNI record does not exist for LPN:'||p_license_plate_number,1);
12066 	 print_debug('CREATE_LPN_FROM_WLPNI - WLPNI record does not exist for lpn_group_id:'||p_lpn_group_id,1);
12067       END IF;
12068       l_progress := 'WMSINB-17020';
12069       RAISE fnd_api.g_exc_error;
12070 END;
12071 
12072 l_progress := 'WMSINB-17021';
12073 -- Overwrite/ set the source_type_id and source_header_id only if not null
12074 if p_source_header_id is not null then
12075    l_source_header_id :=  p_source_header_id;
12076 End if;
12077 
12078 if p_source_type_id is not null then
12079    l_source_type_id :=  p_source_type_id;
12080 End if;
12081 
12082 l_progress := 'WMSINB-17031';
12083 
12084 IF (l_debug = 1) THEN
12085    print_debug('CREATE_LPN_FROM_WLPNI - LPN:'||p_license_plate_number,1);
12086    print_debug('CREATE_LPN_FROM_WLPNI - lpn_group_id:'||p_lpn_group_id,1);
12087    print_debug('CREATE_LPN_FROM_WLPNI - Source header_id:'||l_source_header_id,1);
12088    print_debug('CREATE_LPN_FROM_WLPNI - Source_type_id:'||l_source_type_id,1);
12089    print_debug('CREATE_LPN_FROM_WLPNI - Source_name:'||l_source_name,1);
12090 END IF;
12091 
12092 -- Call Container API to create LPN
12093 wms_container_pvt.create_lpn(
12094 			     p_api_version           => 1.0,
12095 			     p_init_msg_list         => g_false,
12096 			     p_commit                => g_false,
12097 			     p_validation_level      => fnd_api.g_valid_level_full,
12098 			     x_return_status         => x_return_status,
12099 			     x_msg_count             => l_msg_count,
12100 			     x_msg_data              => l_msg_data,
12101 			     p_lpn                   => l_license_plate_number,
12102 			     p_organization_id       => p_organization_id,
12103 			     p_container_item_id     => NULL,
12104 			     p_lot_number            => NULL,
12105 			     p_revision              => NULL,
12106 			     p_serial_number         => NULL,
12107 			     p_subinventory          => l_subinventory_code,
12108 			     p_locator_id            => l_locator_id,
12109 			     p_source                => p_lpn_context, -- Maps to lpn_context of wms_license_plate_number
12110 			     p_cost_group_id         => l_cost_group_id,
12111 			     p_parent_lpn_id         => l_parent_lpn_id,
12112 			     p_source_type_id        => l_source_type_id,
12113 			     p_source_header_id      => l_source_header_id,
12114   p_source_name           => l_source_name,
12115   p_source_line_id        => l_source_line_id,
12116   p_source_line_detail_id => l_source_line_detail_id,
12117   x_lpn_id                => l_lpn_id );
12118 
12119 l_progress := 'WMSINB-17060';
12120 
12121 if x_return_status <> G_RET_STS_SUCCESS Then
12122    -- MSG no new message just add the one on stack
12123    -- Check the Error Status from this call
12124    l_progress := 'WMSINB-17065';
12125    RAISE FND_API.G_EXC_ERROR;
12126 End if;
12127 
12128 x_lpn_id := l_lpn_id;
12129 
12130 
12131 EXCEPTION
12132    WHEN fnd_api.g_exc_error THEN
12133       x_return_status  := g_ret_sts_error;
12134       IF (l_debug = 1) THEN
12135          print_debug('CREATE_LPN_FROM_WLPNI - Execution Error:'|| l_progress || ':' ||sqlcode, 1);
12136       END IF;
12137 
12138    WHEN OTHERS THEN
12139       x_return_status  := g_ret_sts_unexp_error;
12140       x_lpn_id := NULL;
12141       IF (l_debug = 1) THEN
12142          print_debug('CREATE_LPN_FROM_WLPNI - other exception:'|| l_progress || ' ' ||
12143 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
12144       END IF;
12145       IF SQLCODE IS NOT NULL THEN
12146 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.CREATE_LPN_FROM_WLPNI',l_progress, SQLCODE);
12147       END IF;
12148       --  Get message count and data
12149       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => l_msg_count, p_data => x_msg_data);
12150 END create_lpn_from_wlpni;
12151 
12152 Function validate_rs(p_lpn_id         IN NUMBER default null,
12153                      p_txn_id         IN NUMBER ,
12154                      x_lpn_id         OUT nocopy NUMBER
12155 		     ) return BOOLEAN
12156   is
12157 
12158      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
12159      l_progress VARCHAR2(15) := '10';
12160      l_supply_Exists NUMBER;
12161 
12162 BEGIN
12163 
12164    select lpn_id
12165      into x_lpn_id
12166      from rcv_supply rs
12167      where rs.supply_source_id = p_txn_id
12168      and ( (p_lpn_id is not null and rs.lpn_id = p_lpn_id) or (p_lpn_id is null) )
12169        and rownum = 1 ;
12170 
12171      return TRUE;
12172 
12173 EXCEPTION
12174    WHEN no_data_found THEN
12175       IF (l_debug = 1) THEN
12176 	 print_debug('validate_rs - No row found for txn/lpn:'||p_txn_id||'/'||p_lpn_id,1);
12177       END IF;
12178       RETURN FALSE;
12179    When others then
12180       IF (l_debug = 1) THEN
12181          print_debug('validate_rs - other exception:'|| l_progress || ' ' ||
12182 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||' '||sqlcode, 1);
12183       END IF;
12184       IF SQLCODE IS NOT NULL THEN
12185 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.validate_rs',l_progress, SQLCODE);
12186       END IF;
12187       return FALSE;
12188 End validate_rs;
12189 
12190 Function validate_lpn_context(p_transaction_type         IN VARCHAR2,
12191                               p_auto_transact_code       IN VARCHAR2,
12192                               p_to_lpn_context           IN NUMBER ) return BOOLEAN
12193   is
12194 
12195      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
12196      l_progress VARCHAR2(15) := '10';
12197 
12198 Begin
12199 
12200    -- Validates the TO LPN context for a transaction type
12201 
12202    if p_transaction_type = 'RECEIVE' then
12203       if (nvl(p_auto_transact_code, 'RECEIVE') <> 'DELIVER') then
12204 	 if p_to_lpn_context not in (G_LPN_CONTEXT_RCV ,G_LPN_CONTEXT_PREGENERATED ) then
12205 	    l_progress := 'WMSINB-17140';
12206 	    RAISE FND_API.G_EXC_ERROR;
12207 	 end if;
12208        else
12209 	 if p_to_lpn_context not in (G_LPN_CONTEXT_INV , G_LPN_CONTEXT_PREGENERATED ) then
12210 	    l_progress := 'WMSINB-17145';
12211 	    RAISE FND_API.G_EXC_ERROR;
12212 	 end if;
12213       end if;
12214    end if;
12215 
12216    if p_transaction_type in ('ACCEPT','REJECT') then
12217       if p_to_lpn_context not in (G_LPN_CONTEXT_RCV,G_LPN_CONTEXT_PREGENERATED ) then
12218 	 l_progress := 'WMSINB-17153';
12219 	 RAISE FND_API.G_EXC_ERROR;
12220       end if;
12221    End if;
12222 
12223    if p_transaction_type = 'DELIVER' then
12224       if p_to_lpn_context not in (G_LPN_CONTEXT_INV, G_LPN_CONTEXT_PREGENERATED ,G_LPN_CONTEXT_PICKED) then
12225 	 l_progress := 'WMSINB-17160';
12226 	 RAISE FND_API.G_EXC_ERROR;
12227       end if;
12228    End if;
12229 
12230    if p_transaction_type = 'TRANSFER' then
12231       if p_to_lpn_context not in (G_LPN_CONTEXT_PREGENERATED ,G_LPN_CONTEXT_RCV) then
12232 	 l_progress := 'WMSINB-17167';
12233 	 RAISE FND_API.G_EXC_ERROR;
12234       end if;
12235    End if;
12236 
12237    if p_transaction_type = 'SHIP' then
12238       if p_to_lpn_context not in (G_LPN_CONTEXT_PREGENERATED ) then
12239 	 l_progress := 'WMSINB-17174';
12240 	 RAISE FND_API.G_EXC_ERROR;
12241       end if;
12242    End if;
12243 
12244    return TRUE;
12245 
12246 Exception
12247    When others then
12248       --MSG WMS_CONT_INVALID_LPN_CONTEXT
12249       IF (l_debug = 1) THEN
12250          print_debug('validate_lpn_context - other exception:'|| l_progress || ' ' ||
12251 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
12252       END IF;
12253       IF SQLCODE IS NOT NULL THEN
12254 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.validate_lpn_context',l_progress, SQLCODE);
12255       END IF;
12256 
12257       fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN_CONTEXT');
12258       fnd_msg_pub.ADD;
12259 
12260       return FALSE;
12261 End validate_lpn_context;
12262 
12263 PROCEDURE delete_wlpni(p_lpn_group_id  IN NUMBER,
12264                        p_lpn_id        IN NUMBER,
12265                        p_license_plate_number IN VARCHAR2,
12266 		       x_return_status    OUT NOCOPY VARCHAR2,
12267 		       x_msg_count        OUT NOCOPY NUMBER,
12268 		       x_msg_data         OUT NOCOPY VARCHAR2)
12269   is
12270 Begin
12271    -- Deletes rows from WLPNI for the lpn_group
12272 
12273    -- Initialize API return status to success
12274    x_return_status  := g_ret_sts_success;
12275 
12276    delete from wms_lpn_interface where source_group_id = p_lpn_group_id
12277      and ( ( lpn_id = p_lpn_id ) or (license_plate_number = p_license_plate_number) ) ;
12278 
12279 Exception
12280    When others then null;
12281 End delete_wlpni;
12282 
12283 PROCEDURE Explode_lpn_contents(p_lpn_group_id     IN         NUMBER,
12284 			       x_return_status    OUT NOCOPY VARCHAR2,
12285 			       x_msg_count        OUT NOCOPY NUMBER,
12286 			       x_msg_data         OUT NOCOPY VARCHAR2)
12287   is
12288      cursor c_explode_lpn is
12289 	select interface_transaction_id
12290 	  ,transaction_type
12291 	  ,item_id
12292 	  ,item_description
12293 	  ,lpn_id
12294 	  ,transfer_lpn_id
12295 	  ,license_plate_number
12296 	  ,transfer_license_plate_number
12297 	  ,quantity
12298 	  ,shipment_header_id
12299 	  ,routing_header_id
12300 	  ,to_organization_id
12301 	  ,from_organization_id
12302 	  from rcv_transactions_interface rti
12303 	  where rti.lpn_group_id = p_lpn_group_id
12304 	  and ( Nvl(rti.item_id,-1) = -1 AND rti.item_description is null)
12305           -- Bug 3714354
12306           and ( lpn_id is not null or license_plate_number is not null )
12307 	    order by interface_transaction_id;
12308 
12309 	  l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
12310 
12311 	  l_lpn_rec c_explode_lpn%rowtype;
12312 
12313 	  l_other_txn_exists NUMBER;
12314 
12315 	  l_progress VARCHAR2(15) := '10';
12316 
12317 	  -- 1 => Means that only one type of Transaction exists for this lpn_group
12318 	  -- 0 => Means that Multiple  type of Transaction exists for this lpn_group
12319 
12320 	  l_no_other_txn_type NUMBER := 0;
12321 
12322 	  l_from_lpn_status boolean;
12323 	  l_trasfer_lpn_status boolean;
12324 
12325 	  cursor c_child_lpn(p_child_lpn_id NUMBER) is
12326 	     select distinct lpn_id
12327 	       ,license_plate_number
12328 	       from wms_license_plate_numbers
12329 	       connect by prior lpn_id = parent_lpn_id
12330 	       start with lpn_id = p_child_lpn_id
12331 	       ;
12332 
12333 	  l_child_lpn_rec c_child_lpn%rowtype;
12334 
12335 	  cursor c_lpn_contents(p_child_lpn_id1 NUMBER) is
12336 	     select  wlpn.lpn_id lpn_id
12337 	       ,wlc.inventory_item_id inventory_item_id
12338 	       ,wlc.revision item_revision
12339 	       ,wlc.uom_code mol_uom_code
12340 	       ,NULL mmtt_uom_code
12341 	       ,wlc.organization_id organization_id
12342 	       ,wlc.item_description item_description
12343 	       ,null txn_source_id
12344 	       ,null transaction_temp_id
12345 	       ,NULL project_id
12346 	       ,NULL task_id
12347 	       ,0 mmtt_quantity
12348 	       ,sum(nvl(wlc.quantity,0)) mol_quantity
12349 	       from   wms_license_plate_numbers wlpn,
12350 	       wms_lpn_contents wlc
12351 	       where  wlc.parent_lpn_id = wlpn.lpn_id
12352 	       and    wlpn.lpn_id = p_child_lpn_id1
12353 	       group by
12354 	       wlpn.lpn_id
12355 	       ,wlc.inventory_item_id
12356 	       ,wlc.revision
12357 	       ,wlc.uom_code
12358 	       ,wlc.organization_id
12359 	       ,wlc.item_description
12360 	       ;
12361 
12362 	  l_lpn_contents_rec c_lpn_contents%ROWTYPE;
12363 
12364 	  cursor c_immediate_child(p_lpn_id1 NUMBER) is
12365 	     select lpn_id
12366 	       ,license_plate_number
12367 	       ,parent_lpn_id
12368 	       ,organization_id
12369 	       from wms_license_plate_numbers
12370 	       where parent_lpn_id = p_lpn_id1;
12371 
12372 	  l_immediate_child_rec c_immediate_child%rowtype;
12373 
12374 	  l_msg_count number;
12375 	  l_msg_data VARCHAR2(2000);
12376 
12377 	  l_lpn_context NUMBER;
12378 	  l_transfer_lpn_context NUMBER;
12379 	  l_transaction_id NUMBER;
12380 
12381 	  l_wlpni_exists NUMBER;
12382 
12383 	  l_from_lpn_state BOOLEAN;
12384 	  l_to_lpn_state BOOLEAN;
12385 
12386 	  l_cur_parent_lpn_id NUMBER;
12387 
12388 	  l_wlpn_source_header_id NUMBER;
12389 	  l_xfr_wlpn_source_header_id NUMBER;
12390 
12391 	  l_mmtt_qty_mol_uom NUMBER;
12392 
12393 BEGIN
12394 
12395    x_return_status := g_ret_sts_success;
12396 
12397    l_progress := 'WMSINB-17350';
12398 
12399    IF (l_debug = 1) THEN
12400       print_debug('Explode lpn :'|| l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
12401       print_debug('Explode lpn : lpn_group_id = '|| p_lpn_group_id, 1);
12402    END If;
12403 
12404    select count(distinct decode(rti.TRANSACTION_TYPE,'ACCEPT','INSPECT TXN','REJECT','INSPECT TXN',rti.TRANSACTION_TYPE))
12405      into l_other_txn_exists
12406      from rcv_transactions_interface rti
12407      where rti.lpn_group_id = p_lpn_group_id
12408        -- Bug 3714354
12409        and ( lpn_id is not null or license_plate_number is not null )
12410      ;
12411 
12412    l_progress := 'WMSINB-17362';
12413 
12414    if l_other_txn_exists > 1 then
12415       -- Review Later
12416       -- Set appropiate message DIFFERENT TXN TYPES EXIST FOR THE SAME LPN GROUP
12417       -- MSG INV_INVALID_LPN_GROUP
12418       x_return_status := g_ret_sts_error;
12419       l_progress := 'WMSINB-17369';
12420       RAISE FND_API.G_EXC_ERROR;
12421    end if;
12422 
12423    l_progress := 'WMSINB-17373';
12424 
12425    -- Opens Cursor on RTI based on lpn_group_id
12426    open c_explode_lpn;
12427    Loop
12428       fetch c_explode_lpn into l_lpn_rec;
12429       exit when c_explode_lpn%notfound;
12430       IF (l_debug = 1) THEN
12431          print_debug('Explode_lpn_contents: inside Loop for interface_id = :'|| l_lpn_rec.interface_transaction_id, 1);
12432       END IF;
12433       -- Check whether the TRANSACTIONS Types are all same for this LPN Group ID otherwise throw error.
12434 
12435       if nvl(l_lpn_rec.quantity,0) <> 0 then
12436 	 --
12437 	 -- Quantity is not null so failure return from Here
12438 	 IF (l_debug = 1) THEN
12439 	    print_debug('Explode_lpn_contents:  Qty is not null for this lpn : FAILURE '|| l_lpn_rec.lpn_id , 1);
12440 	    print_debug('Explode_lpn_contents: Qty is not null for this lpn : FAILURE '|| l_lpn_rec.license_plate_number, 1);
12441 	 END If;
12442 
12443 
12444 	 l_progress := 'WMSINB-17395';
12445 	 x_return_status := g_ret_sts_error;
12446 
12447 	 -- Review Later
12448 	 -- Set appropiate Message
12449 
12450 	 exit;
12451        else
12452 	 if (  l_lpn_rec.lpn_id is null and
12453 	       l_lpn_rec.license_plate_number is null
12454 	       ) then
12455 	    IF (l_debug = 1) THEN
12456 	       print_debug('Explode_lpn_contents:  qty lpn item  all are null so FAILURE', 1);
12457 	    END If;
12458 	    l_progress := 'WMSINB-17409';
12459 	    x_return_status := g_ret_sts_error;
12460 	    -- Review Later
12461 	    -- Set appropiate Message
12462 	    exit;
12463 	 end if;
12464 
12465 	 -- Quantity is null so proceed with this row
12466 	 -- **************************************************************
12467 	 -- START CASES  FOR  RECEIPT  TRANSACTION
12468 	 -- **************************************************************
12469 
12470 	 --
12471 	 l_progress := 'WMSINB-17422';
12472 	 --
12473 
12474 	 l_from_lpn_state := get_lpn_id(l_lpn_rec.lpn_id,
12475 					l_lpn_rec.license_plate_number,
12476 					l_lpn_context,l_cur_parent_lpn_id,
12477 					l_wlpn_source_header_id);
12478 
12479 	 if (l_from_lpn_state <> TRUE ) then
12480 	    IF (l_debug = 1) THEN
12481 	       print_debug('Explode_LPN_contents: lpn_id and license_plate number does not exist' , 1);
12482 	    END If;
12483 	    -- MSG no new message just add the one on stack
12484 	    -- Review Later.
12485 	    -- Set Appropiate MESSAGE For ERROR
12486 	    --
12487 	    l_progress := 'WMSINB-17435';
12488 	    RAISE FND_API.G_EXC_ERROR;
12489 	  else
12490             if  l_lpn_rec.lpn_id is null then -- CASE WHERE THERE IS AN INVALID LPN
12491 	       IF (l_debug = 1) THEN
12492 		  print_debug('Explode_LPN_contents: lpn_id and license_plate number does not exist' , 1);
12493 	       END If;
12494 	       -- MSG no new message just add the one on stack
12495 	       -- Review Later.
12496 	       -- Set Appropiate MESSAGE For ERROR
12497 	       --
12498 	       l_progress := 'WMSINB-17446';
12499 	       RAISE FND_API.G_EXC_ERROR;
12500             End if;
12501 	 end if;
12502 	 --
12503 	 -- Call get_lpn_id to get the transfer lpn detials
12504 	 --
12505 	 l_progress := 'WMSINB-17453';
12506 
12507 	 l_to_lpn_state := get_lpn_id(l_lpn_rec.transfer_lpn_id,
12508 				      l_lpn_rec.transfer_license_plate_number,
12509 				      l_transfer_lpn_context,
12510 				      l_cur_parent_lpn_id,
12511 				      l_xfr_wlpn_source_header_id);
12512 
12513 	 if (l_to_lpn_state <> TRUE ) then
12514 	    IF (l_debug = 1) THEN
12515 	       print_debug('Explode_LPN_contents: lpn_id and license_plate number does not exist' , 1);
12516 	    END If;
12517 	    -- MSG no new message just add the one on stack
12518 	    -- EXISTING LPN_ID and LICENSE_PLATE_NUMBER COMBINATION IS INVALID
12519 	    -- Review Later.
12520 	    -- Set Appropiate MESSAGE For ERROR
12521 	    --
12522 	    l_progress := 'WMSINB-17469';
12523 	    RAISE FND_API.G_EXC_ERROR;
12524 	 End if;
12525 
12526 	 l_progress := 'WMSINB-17473';
12527 
12528 	 if ( l_lpn_rec.transaction_type in ( 'TRANSFER','DELIVER','RECEIVE' )) then
12529 	    IF (l_debug = 1) THEN
12530 	       print_debug('Explode_LPN_contents: For Receive Txn ', 1);
12531 	    END If;
12532 	    open c_child_lpn(l_lpn_rec.lpn_id);
12533 	    Loop
12534                IF (l_debug = 1) THEN
12535 		  print_debug('Explode_LPN_contents: Inside Child LPN loop lpn_id = ' || l_lpn_rec.lpn_id , 1);
12536                END If;
12537 
12538                Fetch c_child_lpn into l_child_lpn_rec;
12539                Exit when c_child_lpn%NotFound;
12540 
12541                IF (l_debug = 1) THEN
12542 		  print_debug('Explode LPN: Inside Child LPN loop lpn_id = ' || l_child_lpn_rec.lpn_id , 1);
12543                END If;
12544 
12545 	       IF l_lpn_rec.transaction_type = 'RECEIVE' THEN
12546 		  OPEN c_lpn_contents(l_child_lpn_rec.lpn_id);
12547 		  LOOP
12548 		     IF (l_debug = 1) THEN
12549 			print_debug('Explode LPN: Inside LPN contents loop for RECEIVE', 1);
12550 		     END If;
12551 		     FETCH c_lpn_contents into l_lpn_contents_rec;
12552 		     EXIT WHEN c_lpn_contents%notfound;
12553 		     l_transaction_id := NULL;
12554 
12555 		     IF ( l_child_lpn_rec.lpn_id <> l_lpn_rec.lpn_id) then
12556 
12557 			-- Create a new RTI row with flpn=childlpn and tlpn = childlpn;
12558 			-- Review Later
12559 			-- Call create_rti_for_lpn
12560 
12561 			l_progress := 'WMSINB-17549';
12562 
12563 			create_rti_for_lpn(p_transaction_type         => l_lpn_rec.transaction_type,
12564 					   p_interface_transaction_id => l_lpn_rec.interface_transaction_id,
12565 					   p_lpn_id                   => l_lpn_contents_rec.lpn_id,
12566 					   p_org_id                   => l_lpn_contents_rec.organization_id,
12567 					   p_to_org_id                => l_lpn_rec.to_organization_id,
12568 					   p_item_id                  => l_lpn_contents_rec.inventory_item_id,
12569 					   p_item_desc                => '',
12570 					   p_item_revision            => l_lpn_contents_rec.item_revision,
12571 					   p_quantity                 => l_lpn_contents_rec.mol_quantity,
12572 					   p_txn_uom_code             => l_lpn_contents_rec.mol_uom_code,
12573 					   p_transfer_lpn_id          => l_lpn_contents_rec.lpn_id,
12574 					   p_transfer_lpn             => null ,
12575 					   p_txn_source_id            => l_lpn_contents_rec.txn_source_id,
12576 					   p_mmtt_temp_id             => l_lpn_contents_rec.transaction_temp_id,
12577 					   p_project_id               => l_lpn_contents_rec.project_id,
12578 					   p_task_id                  => l_lpn_contents_rec.task_id,
12579 			                   x_interface_transaction_id => l_transaction_id,
12580 			                   x_return_status            => x_return_status,
12581 			                   x_msg_count                => l_msg_count,
12582 			                   x_msg_data                 => l_msg_data
12583 			  );
12584 			IF x_return_status <> G_RET_STS_SUCCESS Then
12585 			   -- MSG no new message just add the one on stack
12586 			   -- Check the Error Status from this call
12587 			   l_progress := 'WMSINB-17550';
12588 			   RAISE FND_API.G_EXC_ERROR;
12589 			END if;
12590 		      ELSE
12591 			--
12592 			-- Create a new RTI row with flpn=childlpn and tlpn = tlpn;
12593 			-- Review Later
12594 			l_progress := 'WMSINB-17579';
12595 			create_rti_for_lpn(p_transaction_type         => l_lpn_rec.transaction_type,
12596 					   p_interface_transaction_id => l_lpn_rec.interface_transaction_id,
12597 					   p_lpn_id                   => l_lpn_contents_rec.lpn_id,
12598 					   p_item_id                  => l_lpn_contents_rec.inventory_item_id,
12599 					   p_org_id                   => l_lpn_contents_rec.organization_id,
12600 					   p_to_org_id                => l_lpn_rec.to_organization_id,
12601 					   p_item_desc                => '',
12602 					   p_item_revision            => l_lpn_contents_rec.item_revision,
12603 					   p_quantity                 => l_lpn_contents_rec.mol_quantity,
12604 					   p_txn_uom_code             => l_lpn_contents_rec.mol_uom_code,
12605 					   p_transfer_lpn_id          => l_lpn_rec.transfer_lpn_id,
12606 					   p_transfer_lpn             => l_lpn_rec.transfer_license_plate_number,
12607 					   p_txn_source_id            => l_lpn_contents_rec.txn_source_id,
12608 					   p_mmtt_temp_id             => l_lpn_contents_rec.transaction_temp_id,
12609 					   p_project_id               => l_lpn_contents_rec.project_id,
12610 					   p_task_id                  => l_lpn_contents_rec.task_id,
12611 			                   x_interface_transaction_id => l_transaction_id,
12612 			                   x_return_status            => x_return_status,
12613 			                   x_msg_count                => l_msg_count,
12614 			                   x_msg_data                 => l_msg_data
12615 			  );
12616 			IF  x_return_status <> G_RET_STS_SUCCESS Then
12617 			   -- MSG no new message just add the one on stack
12618 			   -- Check the Error Status from this call
12619 			   l_progress := 'WMSINB-17580';
12620 			   RAISE FND_API.G_EXC_ERROR;
12621 			END IF;
12622 		     END IF;
12623 		  END LOOP;
12624 
12625 		  IF c_lpn_contents%isopen THEN
12626 		     CLOSE c_lpn_contents;
12627 		  END IF;
12628 
12629 		ELSIF l_lpn_rec.transaction_type IN ('TRANSFER','DELIVER') THEN
12630 		   explode_lpn_for_xfer_dlvr
12631 		     (p_transaction_type          => l_lpn_rec.transaction_type
12632 		      ,p_lpn_id                   => l_child_lpn_rec.lpn_id
12633 		      ,p_rti_id                   => l_lpn_rec.interface_transaction_id
12634 		      ,p_rti_lpn_id               => l_lpn_rec.lpn_id
12635 		      ,p_rti_xfer_lpn_id          => l_lpn_rec.transfer_lpn_id
12636 		      ,p_rti_xfer_lpn             => l_lpn_rec.transfer_license_plate_number
12637 		      ,p_rti_to_organization_id   => l_lpn_rec.to_organization_id
12638 		      ,x_return_status            => x_return_status
12639 		      ,x_msg_count                => l_msg_count
12640 		      ,x_msg_data                 => l_msg_data
12641 		      );
12642 	       END IF;
12643 	    End Loop;
12644 
12645 	    if c_child_lpn%isopen then
12646                close c_child_lpn;
12647 	    end if;
12648 
12649 	    l_progress := 'WMSINB-17621';
12650 
12651 	    --
12652 	    -- Create WLPNI rows for Explosion if needed
12653 	    --
12654 	    if ( nvl(l_lpn_rec.lpn_id,-1) <> nvl(l_lpn_rec.transfer_lpn_id,-1) ) then
12655 
12656 	       IF (l_debug = 1) THEN
12657 		  print_debug('Explode LPN: Before Immediate Child LPN loop ', 1);
12658 	       END If;
12659 
12660 	       open c_immediate_child (l_lpn_rec.lpn_id);
12661 	       Loop
12662 		  Fetch c_immediate_child into l_immediate_child_rec;
12663 		  Exit when c_immediate_child%notfound;
12664 		  -- Call create WLPNI here
12665 	          l_progress := 'WMSINB-17637';
12666 		  insert_wlpni(  p_LPN_ID => l_immediate_child_rec.lpn_id,
12667 				 p_LICENSE_PLATE_NUMBER => l_immediate_child_rec.license_plate_number,
12668 				 p_PARENT_LPN_ID => l_lpn_rec.transfer_lpn_id,
12669 				 p_PARENT_LICENSE_PLATE_NUMBER => l_lpn_rec.transfer_license_plate_number,
12670 				 p_organization_id => l_lpn_rec.to_organization_id,
12671 				 p_LPN_GROUP_ID                => p_LPN_GROUP_ID,
12672 				 x_return_status               => x_return_status,
12673 				 x_msg_count                   => l_msg_count,
12674 				 x_msg_data                    => l_msg_data
12675 				 );
12676 		  if x_return_status <> G_RET_STS_SUCCESS Then
12677 		     -- MSG no new message just add the one on stack
12678 		     -- Check the Error Status from this call
12679 		     null;
12680 		  End if;
12681 	       End loop;
12682 
12683 	       if c_immediate_child%isopen then
12684 		  close c_immediate_child;
12685 	       End if;
12686              else
12687 		     --
12688 	             l_progress := 'WMSINB-17660';
12689 		     -- Call create WLPNI here
12690 		     IF (l_debug = 1) THEN
12691 			print_debug('Explode LPN: Before insert_wlpni else ', 1);
12692 		     END If;
12693 
12694 		     -- Check Existence of rows in WLPNI
12695 		     -- If not exists then create
12696 
12697 	             l_progress := 'WMSINB-17669';
12698 		     check_lpn_in_wlpni(l_lpn_rec.license_plate_number, l_lpn_rec.lpn_id, p_lpn_group_id, l_wlpni_exists);
12699 
12700 		     if l_wlpni_exists = 0 then
12701 	                l_progress := 'WMSINB-17673';
12702 			insert_wlpni(  p_LPN_ID => l_lpn_rec.lpn_id,
12703 				       p_LICENSE_PLATE_NUMBER => l_lpn_rec.license_plate_number,
12704 				       p_PARENT_LPN_ID => null,
12705 				       p_PARENT_LICENSE_PLATE_NUMBER => null,
12706 				       p_organization_id => l_lpn_rec.to_organization_id,
12707 				       p_LPN_GROUP_ID                => p_LPN_GROUP_ID,
12708 				       x_return_status               => x_return_status,
12709 				       x_msg_count                   => l_msg_count,
12710 				       x_msg_data                    => l_msg_data
12711 				       );
12712 		     End if;
12713 	    end if;
12714 
12715 	    --
12716 	 end if; /* END OF RECEIVE TXN CASE */
12717 
12718 	 /* START OF CASE FOR OTHER TXN TYPE */
12719 	 if ( l_lpn_rec.transaction_type in ( 'ACCEPT','REJECT','RETURN TO CUSTOMER',
12720 					      'CORRECT','SHIP','RETURN TO RECEIVING','RETURN TO VENDOR','UNORDERED' )) then
12721 	    IF (l_debug = 1) THEN
12722 	       print_debug('Explode_lpn_contents:  INSPECT TXN failure txn type is wrong', 1);
12723 	       print_debug('Explode_lpn_contents:  INSPECT TXN failure txn type '|| l_lpn_rec.transaction_type, 1);
12724 	    END If;
12725 	    x_return_status := g_ret_sts_error;
12726 	    -- MSG INV_INVALID_LPN_TXN
12727 	    -- Review Later
12728 	    -- Set appropiate Message
12729 	    exit;
12730 	 end if;  /* END OF CASE FOR OTHER TXN */
12731       end if;    /* END OF QTY = 0 CASE */
12732 
12733    End Loop;
12734 
12735    IF (l_debug = 1) THEN
12736       print_debug('EXPLODE_LPN:',1);
12737    END IF;
12738 
12739 EXCEPTION
12740    WHEN OTHERS THEN
12741       x_return_status  := g_ret_sts_unexp_error;
12742 
12743       if c_lpn_contents%isopen then
12744          close c_lpn_contents;
12745       end if;
12746 
12747       if c_child_lpn%isopen then
12748          close c_child_lpn;
12749       end if;
12750 
12751       if c_immediate_child%isopen then
12752          close c_immediate_child;
12753       End if;
12754 
12755       IF (l_debug = 1) THEN
12756          print_debug('Explode lpn: - other exception:'|| l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS') || 'Error = '|| SQLCODE , 1);
12757       END IF;
12758       IF SQLCODE IS NOT NULL THEN
12759 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.explode_lpn_contents',l_progress, SQLCODE);
12760       END IF;
12761       --  Get message count and data
12762       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => l_msg_count, p_data => l_msg_data);
12763 
12764 END Explode_lpn_contents;
12765 
12766 -- Description
12767 -- Procedure whether the sub, loc,org data passed matches with the LPN
12768 -- Information
12769 PROCEDURE validate_lpn_locator( p_lpn_id IN NUMBER,
12770                                 p_subinventory     IN VARCHAR2,
12771                                 p_locator_id       IN NUMBER,
12772                                 p_organization_id  IN NUMBER,
12773                                 x_lpn_match        OUT NOCOPY VARCHAR2,
12774                                 x_return_status    OUT NOCOPY VARCHAR2,
12775                                 x_msg_count        OUT NOCOPY NUMBER,
12776                                 x_msg_data         OUT NOCOPY VARCHAR2)
12777   is
12778 
12779      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
12780      l_progress VARCHAR2(15) := '10';
12781      l_msg_count number;
12782      l_msg_data VARCHAR2(2000);
12783 
12784      l_sub_match varchar2(1) := 'N';
12785 
12786 BEGIN
12787 
12788    x_return_status := g_ret_sts_success;
12789 
12790    SELECT 'Y'
12791      INTO l_sub_match
12792      FROM wms_license_plate_numbers wlpn
12793      WHERE wlpn.lpn_id = p_lpn_id
12794      AND ((wlpn.lpn_context <> 5
12795 	   AND (Nvl(wlpn.subinventory_code,'@@@') = Nvl(p_subinventory,'@@@'))
12796 	   AND (Nvl(wlpn.locator_id,-1) = Nvl(p_locator_id,-1)))
12797 	  OR wlpn.lpn_context = 5)
12798      AND wlpn.organization_id = p_organization_id
12799      AND ROWNUM = 1
12800      ;
12801 
12802    x_lpn_match := l_sub_match;
12803 
12804 EXCEPTION
12805    when no_data_found then
12806       x_lpn_match := 'N';
12807       -- MSG WMS_CONT_INVALID_LOC
12808    when others then
12809       -- MSG WMS_CONT_INVALID_LOC
12810       x_lpn_match := 'N';
12811       x_return_status  := g_ret_sts_unexp_error;
12812       IF (l_debug = 1) THEN
12813          print_debug('validate_lpn_locator - other exception:'|| l_progress || ' ' ||
12814 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
12815       END IF;
12816       IF SQLCODE IS NOT NULL THEN
12817 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.validate_lp_locator',l_progress, SQLCODE);
12818       END IF;
12819       --  Get message count and data
12820       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => l_msg_count, p_data => x_msg_data);
12821 END validate_lpn_locator;
12822 
12823 
12824 -- Description
12825 -- This Procedure returns the PARENT_LPN_ID
12826 -- from WLPN
12827 PROCEDURE get_parent_lpn(p_license_plate_number IN VARCHAR2,
12828                          x_parent_lpn_id IN OUT NOCOPY NUMBER)
12829   is
12830 BEGIN
12831    select PARENT_LPN_ID
12832      into x_parent_lpn_id
12833      from wms_license_plate_numbers
12834      where license_plate_number = p_license_plate_number
12835      ;
12836 EXCEPTION
12837    WHEN OTHERS THEN
12838       x_parent_lpn_id := null;
12839 END get_parent_lpn;
12840 
12841 -- Description
12842 -- This Procedure returns the PARENT_LPN_ID / PARENT LICENSE_PLATE_NUMBER
12843 -- from WLPNI
12844 PROCEDURE get_parent_lpn_in_wlpni(p_license_plate_number IN VARCHAR2,
12845 				  p_lpn_id               IN NUMBER,
12846 				  p_lpn_group_id         IN NUMBER,
12847 				  x_parent_lpn IN OUT NOCOPY VARCHAR2 ,
12848 				  x_parent_lpn_id IN OUT NOCOPY NUMBER )
12849   is
12850 BEGIN
12851    if p_lpn_id is null then
12852       select PARENT_LPN_ID,
12853 	PARENT_LICENSE_PLATE_NUMBER
12854 	into x_parent_lpn_id,
12855 	x_parent_lpn
12856 	from wms_lpn_interface
12857 	where lpn_id = p_lpn_id
12858 	and source_group_id = p_lpn_group_id
12859 	;
12860     else
12861       select PARENT_LPN_ID,
12862 	PARENT_LICENSE_PLATE_NUMBER
12863 	into x_parent_lpn_id,
12864 	x_parent_lpn
12865 	from wms_lpn_interface
12866 	where license_plate_number = p_license_plate_number
12867 	and source_group_id = p_lpn_group_id;
12868    end if;
12869 EXCEPTION
12870    WHEN OTHERS THEN
12871       x_parent_lpn_id := null;
12872       x_parent_lpn    := null;
12873 END get_parent_lpn_in_wlpni;
12874 
12875 
12876 PROCEDURE VALIDATE_TOTAL_QTY(p_lpn_group_id     IN NUMBER,
12877                              p_from_lpn_id      IN NUMBER,
12878 			     p_parent_lpn_id    IN NUMBER,
12879                              p_transaction_type IN VARCHAR2,
12880                              x_return_status    OUT NOCOPY VARCHAR2,
12881                              x_msg_count        OUT NOCOPY NUMBER,
12882 		             x_msg_data         OUT NOCOPY VARCHAR2
12883 			     ) is
12884 
12885 				l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
12886 				l_progress VARCHAR2(15) := '10';
12887 				l_rti_qty  NUMBER;
12888 
12889 				l_serial_disc NUMBER;
12890 				l_outermost_lpn_id NUMBER;
12891 				l_dummy VARCHAR2(1);
12892 Begin
12893 
12894    -- Initialize API return status to success
12895    x_return_status  := g_ret_sts_success;
12896 
12897    IF (l_debug = 1) THEN
12898       print_debug('VALIDATE_TOTAL_QTY: P_LPN_GROUP_ID = '||p_lpn_group_id,1);
12899       print_debug('VALIDATE_TOTAL_QTY: P_FROM_LPN_ID = '||p_from_lpn_id,1);
12900       print_debug('VALIDATE_TOTAL_QTY: P_PARENT_LPN_ID = '||p_parent_lpn_id,1);
12901       print_debug('VALIDATE_TOTAL_QTY: P_TRANSACTION_TYPE = '||p_transaction_type,1);
12902    END If;
12903 
12904    FOR l_outermost_lpn IN (SELECT lpn_id, license_plate_number,
12905 			   Nvl(parent_lpn_id, outermost_lpn_id) parent_lpn_id
12906 			   FROM wms_license_plate_numbers
12907 			   START WITH lpn_id = p_from_lpn_id
12908 			   CONNECT BY lpn_id = PRIOR parent_lpn_id)
12909      LOOP
12910 	l_outermost_lpn_id := l_outermost_lpn.lpn_id;
12911 
12912 	BEGIN
12913 	   SELECT '1'
12914 	     INTO l_dummy
12915 	     FROM wms_lpn_interface
12916 	     WHERE source_group_id = p_lpn_group_id
12917 	     AND (lpn_id = l_outermost_lpn.lpn_id
12918 		  OR license_plate_number = l_outermost_lpn.license_plate_number)
12919 	     AND Nvl(parent_lpn_id, -1) <> l_outermost_lpn.parent_lpn_id;
12920 
12921 	   EXIT;
12922 	EXCEPTION
12923 	   WHEN OTHERS THEN
12924 	      NULL;
12925 	END;
12926 
12927      END LOOP; --FOR l_outermost_lpn IN
12928 
12929    IF Nvl(p_transaction_type,'@@@') <> 'RECEIVE' THEN
12930       For l_wln_csr in (
12931                     select lpn_id lpn_id,
12932                            license_plate_number license_plate_number
12933                       from wms_license_plate_numbers wlpn
12934                       connect by prior wlpn.lpn_id = wlpn.parent_lpn_id
12935                       start with wlpn.lpn_id = l_outermost_lpn_id
12936                        )
12937       Loop
12938       For l_lpn_contents in (
12939 			     select
12940 			     wlc.parent_lpn_id lpn_id
12941 			     ,l_wln_csr.license_plate_number license_plate_number
12942 			     ,wlc.inventory_item_id inventory_item_id
12943 			     ,wlc.revision item_revision
12944 			     ,wlc.organization_id organization_id
12945 			     --,wlc.item_description item_description
12946 			     ,sum(get_primary_qty(wlc.organization_id, wlc.inventory_item_id, wlc.uom_code,nvl(wlc.quantity,0)))
12947 			     primary_quantity
12948 			     from  wms_lpn_contents wlc
12949                              where  wlc.parent_lpn_id = l_wln_csr.lpn_id
12950                              -- 4507808
12951                              -- Commented the exists statement below
12952                              -- by the l_wln_csr above.
12953 			     -- where  wlc.parent_lpn_id = wln.lpn_id
12954 			     -- AND exists ( select '1' from wms_license_plate_numbers wlpn
12955 			--		  where  wlc.parent_lpn_id = wlpn.lpn_id
12956 			--		  connect by prior wlpn.lpn_id = wlpn.parent_lpn_id
12957 			--		  start with wlpn.lpn_id = l_outermost_lpn_id
12958 					  --union all
12959 					  --select '1' from wms_license_plate_numbers wlpn1
12960 					  --where  wlc.parent_lpn_id = wlpn1.lpn_id
12961 					  --and not exists ( select 1 from wms_lpn_interface wlpni
12962 						--	   where wlpni.lpn_id = p_from_lpn_id and
12963 						--	   Nvl(wlpni.parent_lpn_id, -1) <> Nvl(p_parent_lpn_id, -1)
12964 						--	   )
12965 					  --connect by prior wlpn1.parent_lpn_id = wlpn1.lpn_id
12966 					  --start with wlpn1.lpn_id = p_from_lpn_id
12967 		 	--			  )
12968         group by
12969         wlc.parent_lpn_id
12970         ,l_wln_csr.license_plate_number
12971         ,wlc.inventory_item_id
12972         ,wlc.revision
12973         ,wlc.organization_id
12974         --,wlc.item_description
12975         )
12976         Loop
12977 	   IF (l_debug = 1) THEN
12978 	      print_debug('VALIDATE_TOTAL_QTY: Inventory_Item_Id = '||l_lpn_contents.inventory_item_id,1);
12979 	      print_debug('VALIDATE_TOTAL_QTY: Item_Revision = '||l_lpn_contents.item_revision,1);
12980 	      print_debug('VALIDATE_TOTAL_QTY: Primary_Quantity = '||l_lpn_contents.primary_quantity,1);
12981 	      print_debug('VALIDATE_TOTAL_QTY: License_Plate_Number = '||l_lpn_contents.license_plate_number,1);
12982 	   END If;
12983 
12984 	   -- THERE IS a PROBLEM HERE IF DIFFERENT UOM_CODES EXIST in WLC FOR THE SAME ITEM. ***********
12985 	   -- NOT YET CONVERTED UOM
12986 
12987 	   select sum(primary_quantity)
12988 	     into l_rti_qty
12989 	     from rcv_transactions_interface rti
12990 	     where rti.lpn_group_id = p_lpn_group_id
12991 	     and (rti.lpn_id = l_lpn_contents.lpn_id
12992 		  OR rti.license_plate_number = l_lpn_contents.license_plate_number)
12993              -- 3397823
12994 	     -- and rti.transfer_lpn_id = l_lpn_contents.lpn_id
12995 	     and rti.item_id = l_lpn_contents.inventory_item_id
12996 	     and decode(rti.transaction_type,'ACCEPT','INSPECT','REJECT','INSPECT',rti.transaction_type)
12997 	     = decode(p_transaction_type,'ACCEPT','INSPECT','REJECT','INSPECT',p_transaction_type)
12998 	     and ( (l_lpn_contents.item_revision is null) or (rti.item_revision = l_lpn_contents.item_revision))
12999 	       --and ( (l_lpn_contents.item_description is null) or (rti.item_description = l_lpn_contents.item_description ))
13000 		 ;
13001 
13002 	     IF l_rti_qty IS NULL THEN
13003 		l_rti_qty := 0;
13004 	     END IF;
13005 
13006 	     IF (l_debug = 1) THEN
13007 		print_debug('VALIDATE_TOTAL_QTY: L_RTI_QTY = '||l_rti_qty,1);
13008 	     END If;
13009 
13010 	     --BUG 4939647 Need to round rti quantity to 5 decimals as we only store
13011 	     --5 decimals in lpn contents
13012 	     l_rti_qty := Round(l_rti_qty,5);
13013 
13014 	     -- Check the QUANTITY
13015 	     IF l_rti_qty <> 0 THEN
13016 		-- bug 4897277
13017 		-- Use absolute value of transaction qty for checking
13018 		IF ABS(l_rti_qty) <> l_lpn_contents.primary_quantity then
13019 		   IF (l_debug = 1) THEN
13020 		      print_debug('VALIDATE_TOTAL_QTY: QTY MISMATCH l_rti_qty = '|| to_char(l_rti_qty) || ' lpn qty ' ||
13021 				  to_char(l_lpn_contents.primary_quantity) , 1);
13022 		   END If;
13023 		   l_progress := 'WMSINB-17926';
13024 		   RAISE FND_API.G_EXC_ERROR;
13025 		End if;
13026 	     END IF;
13027 
13028         End Loop;
13029         End Loop; --l_wln_csr
13030     ELSE --IF Nvl(p_transaction_type,'@@@') <> 'RECEIVE' THEN
13031       For l_wln_csr in (
13032                     select lpn_id lpn_id,
13033                            license_plate_number license_plate_number
13034                       from wms_license_plate_numbers wlpn
13035                       connect by prior wlpn.lpn_id = wlpn.parent_lpn_id
13036                       start with wlpn.lpn_id = l_outermost_lpn_id
13037                        )
13038       Loop
13039       For l_lpn_contents in (
13040 			     select
13041 			     wlc.parent_lpn_id lpn_id
13042 			     ,l_wln_csr.license_plate_number license_plate_number
13043 			     ,wlc.inventory_item_id inventory_item_id
13044 			     ,wlc.revision item_revision
13045 			     ,wlc.organization_id organization_id
13046 			     --,wlc.item_description item_description
13047 			     ,wlc.lot_number lot_number
13048 			     ,sum(get_primary_qty(wlc.organization_id, wlc.inventory_item_id, wlc.uom_code,nvl(wlc.quantity,0)))
13049 			     primary_quantity
13050 			     from  wms_lpn_contents wlc
13051                              where  wlc.parent_lpn_id = l_wln_csr.lpn_id
13052                              -- 4507808
13053                              -- Commented the exists statement below
13054                              -- and replaced by the outer cursor l_wln_csr
13055 			     -- where  wlc.parent_lpn_id = wln.lpn_id
13056 			     -- AND exists ( select '1' from wms_license_plate_numbers wlpn
13057 			--		  where  wlc.parent_lpn_id = wlpn.lpn_id
13058 			--		  connect by prior wlpn.lpn_id = wlpn.parent_lpn_id
13059 			--		  start with wlpn.lpn_id = l_outermost_lpn_id
13060 					  --union all
13061 					  --select '1' from wms_license_plate_numbers wlpn1
13062 					  --where  wlc.parent_lpn_id = wlpn1.lpn_id
13063 					  --and not exists ( select 1 from wms_lpn_interface wlpni
13064 						--	   where wlpni.lpn_id = p_from_lpn_id and
13065 						--	   Nvl(wlpni.parent_lpn_id, -1) <> Nvl(p_parent_lpn_id, -1)
13066 						--	   )
13067 					  --connect by prior wlpn1.parent_lpn_id = wlpn1.lpn_id
13068 					  --start with wlpn1.lpn_id = p_from_lpn_id
13069 				--	  )
13070 	group by
13071 	wlc.parent_lpn_id
13072 	,l_wln_csr.license_plate_number
13073 	,wlc.inventory_item_id
13074 	,wlc.revision
13075 	,wlc.organization_id
13076 	--,wlc.item_description
13077 	,wlc.lot_number
13078 	)
13079 	Loop
13080 
13081 	   -- THERE IS a PROBLEM HERE IF DIFFERENT UOM_CODES EXIST in WLC FOR THE SAME ITEM. ***********
13082 	   -- NOT YET CONVERTED UOM
13083 	   IF l_lpn_contents.lot_number IS NULL THEN
13084 	      select sum(primary_quantity)
13085 		into l_rti_qty
13086 		from rcv_transactions_interface rti
13087 		where rti.lpn_group_id = p_lpn_group_id
13088 		and (rti.lpn_id = l_lpn_contents.lpn_id
13089 		     OR rti.license_plate_number = l_lpn_contents.license_plate_number)
13090                 -- 3397823
13091 		--and rti.transfer_lpn_id = l_lpn_contents.lpn_id
13092 		and rti.item_id = l_lpn_contents.inventory_item_id
13093 		and decode(rti.transaction_type,'ACCEPT','INSPECT','REJECT','INSPECT',rti.transaction_type)
13094 		= decode(p_transaction_type,'ACCEPT','INSPECT','REJECT','INSPECT',p_transaction_type)
13095 		and ( (l_lpn_contents.item_revision is null) or (rti.item_revision = l_lpn_contents.item_revision))
13096 		  --and ( (l_lpn_contents.item_description is null) or (rti.item_description = l_lpn_contents.item_description ))
13097 		    AND l_lpn_contents.lot_number IS NULL;
13098 	    ELSE --IF l_lpn_contents.lot_number IS NULL THEN
13099 	      select sum(mtli.primary_quantity)
13100 		into l_rti_qty
13101 		from rcv_transactions_interface rti
13102 		, mtl_transaction_lots_interface mtli
13103 		where rti.lpn_group_id = p_lpn_group_id
13104 		and (rti.lpn_id = l_lpn_contents.lpn_id
13105 		     OR rti.license_plate_number = l_lpn_contents.license_plate_number)
13106                 -- 3397823
13107 		-- and rti.transfer_lpn_id = l_lpn_contents.lpn_id
13108 		and rti.item_id = l_lpn_contents.inventory_item_id
13109 		and decode(rti.transaction_type,'ACCEPT','INSPECT','REJECT','INSPECT',rti.transaction_type)
13110 		= decode(p_transaction_type,'ACCEPT','INSPECT','REJECT','INSPECT',p_transaction_type)
13111 		and ( (l_lpn_contents.item_revision is null) or (rti.item_revision = l_lpn_contents.item_revision))
13112 		  --and ( (l_lpn_contents.item_description is null) or (rti.item_description = l_lpn_contents.item_description ))
13113 		    AND l_lpn_contents.lot_number = mtli.lot_number
13114 		    AND mtli.product_code = 'RCV'
13115 		    AND mtli.product_transaction_id = rti.interface_transaction_id
13116 		    ;
13117 	   END IF; --IF l_lpn_contents.lot_number IS NULL THEN
13118 
13119 	   IF (l_rti_qty IS NULL) THEN
13120 	      l_rti_qty := 0;
13121 	   END IF;
13122 
13123 	   IF (l_debug = 1) THEN
13124 	      print_debug('VALIDATE_TOTAL_QTY: L_RTI_QTY = '||l_rti_qty,1);
13125 	   END If;
13126 
13127 	   --BUG 4939647 Need to round rti quantity to 5 decimals as we only store
13128 	   --5 decimals in lpn contents
13129 	   l_rti_qty := Round(l_rti_qty,5);
13130 
13131 	   -- Check the QUANTITY
13132           /* Bug 5616019.
13133            * We need to validate the quantities even when l_rti_qty is zero.
13134            * Commenting out the if condition.
13135            * IF (l_rti_qty <> 0) THEN
13136           */
13137 
13138 	      if l_rti_qty <> l_lpn_contents.primary_quantity then
13139 		 IF (l_debug = 1) THEN
13140 		    print_debug('VALIDATE_TOTAL_QTY: QTY MISMATCH l_rti_qty = '|| to_char(l_rti_qty) || ' lpn qty ' ||
13141 				to_char(l_lpn_contents.primary_quantity) , 1);
13142 		 END If;
13143 		 l_progress := 'WMSINB-17927';
13144 		 RAISE FND_API.G_EXC_ERROR;
13145 	      End if;
13146           /* Bug 5616019.
13147            * END IF;
13148           */
13149 
13150 	   l_serial_disc := 1;
13151 
13152 	   For l_test_serial_rec in (
13153 				     select serial_number
13154 				     from mtl_serial_numbers msn
13155 				     WHERE msn.lpn_id = l_lpn_contents.lpn_id
13156 				     AND msn.inventory_item_id = l_lpn_contents.inventory_item_id
13157 				     )
13158 	     Loop
13159 		BEGIN
13160 		   SELECT 1
13161 		     INTO l_serial_disc
13162 		     FROM mtl_serial_numbers_interface msni
13163 		     , rcv_transactions_interface rti
13164 		     where rti.lpn_group_id = p_lpn_group_id
13165 		     and (rti.lpn_id = l_lpn_contents.lpn_id
13166 			  OR rti.license_plate_number = l_lpn_contents.license_plate_number)
13167                      -- 3397823
13168 		     -- and rti.transfer_lpn_id = l_lpn_contents.lpn_id
13169 		     and rti.item_id = l_lpn_contents.inventory_item_id
13170 		     AND msni.product_code = 'RCV'
13171 		     AND msni.product_transaction_id = rti.interface_transaction_id
13172 		     and l_test_serial_rec.serial_number between msni.fm_serial_number and msni.to_serial_number
13173 		     AND Length(l_test_serial_rec.serial_number) = Length(msni.fm_serial_number)
13174 		     AND length(msni.fm_serial_number)=Length(Nvl(msni.to_serial_number,msni.fm_serial_number))  --BUG 3818544
13175 		     and rownum = 1
13176 		     ;
13177 		EXCEPTION
13178 		   WHEN others THEN
13179 		      IF (l_debug = 1) THEN
13180 			 print_debug('VALIDATE_TOTAL_QTY: Serial Mismatched is '|| l_test_serial_rec.serial_number , 1);
13181 		      END If;
13182 		      l_serial_disc := 0;
13183 		      exit;
13184 		END;
13185 	     End Loop;
13186 
13187 	     if l_serial_disc = 0 then
13188 		IF (l_debug = 1) THEN
13189 		   print_debug('VALIDATE_TOTAL_QTY: validate serial mismatch' , 1);
13190 		END If;
13191 		l_progress := 'WMSINB-17928';
13192 		RAISE FND_API.G_EXC_ERROR;
13193 	     End if;
13194 	End Loop;
13195         End Loop; -- l_wln_csr
13196    END IF; --IF Nvl(p_transaction_type,'@@@') <> 'RECEIVE' THEN
13197 
13198 Exception
13199    when fnd_api.g_exc_error THEN
13200       x_return_status  := g_ret_sts_error;
13201 
13202    when others then
13203       x_return_status  := g_ret_sts_unexp_error;
13204       IF (l_debug = 1) THEN
13205          print_debug('validate_quantity - other exception:'|| l_progress || ' ' ||
13206 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
13207       END IF;
13208       IF SQLCODE IS NOT NULL THEN
13209 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.validate_quantity',l_progress, SQLCODE);
13210       END IF;
13211       --  Get message count and data
13212       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
13213 End validate_total_qty;
13214 
13215 PROCEDURE VALIDATE_LPN_INFO(p_lpn_group_id     IN         NUMBER,
13216 			    x_return_status    OUT NOCOPY VARCHAR2,
13217 			    x_msg_count        OUT NOCOPY NUMBER,
13218 			    x_msg_data         OUT NOCOPY VARCHAR2)
13219   is
13220      cursor c_validate_lpn is
13221 	select interface_transaction_id
13222 	  ,transaction_type
13223 	  ,item_id
13224 	  ,item_description
13225 	  ,lpn_id
13226 	  ,transfer_lpn_id
13227 	  ,license_plate_number
13228 	  ,transfer_license_plate_number
13229 	  ,quantity
13230 	  ,shipment_header_id
13231 	  ,shipment_num
13232 	  ,routing_header_id
13233 	  ,to_organization_id
13234 	  ,nvl(from_organization_id,to_organization_id) from_organization_id -- This is needed
13235 	  ,subinventory                   -- as for some txns like ASN Receive, TRANSFER, DELIVER
13236 	  ,locator_id                     -- the from organization_id is null in rti
13237 	  ,from_subinventory              -- so we have to take the to_organization_id
13238 	  ,from_locator_id
13239 	  ,parent_transaction_id
13240 	  ,source_document_code
13241 	  ,auto_transact_code
13242 	  ,Nvl(mobile_txn, 'N') mobile_txn
13243 	  ,processing_mode_code
13244 	  ,inv_transaction_id
13245 	  ,mmtt_temp_id
13246           ,Nvl(express_transaction,'N') express_transaction --Bug 5550783
13247 	  from rcv_transactions_interface rti
13248 	  where rti.lpn_group_id = p_lpn_group_id
13249 	  order by interface_transaction_id;
13250 
13251      cursor c_child_lpn(p_child_lpn_id varchar2) is
13252 	select lpn_id
13253 	  ,license_plate_number
13254 	  from wms_license_plate_numbers
13255 	  where outermost_lpn_id = p_child_lpn_id;
13256 
13257      l_child_lpn_rec c_child_lpn%rowtype;
13258 
13259      cursor c_immd_child_lpn(p_child_lpn_id varchar2) is
13260 	select lpn_id
13261 	  ,license_plate_number
13262 	  from wms_license_plate_numbers
13263 	  where parent_lpn_id = p_child_lpn_id;
13264 
13265      l_immd_child_rec c_immd_child_lpn%rowtype;
13266 
13267      cursor c_lpn_contents(p_child_lpn_id varchar2) is
13268 	select parent_lpn_id
13269 	  ,inventory_item_id
13270 	  ,quantity
13271 	  from wms_lpn_contents
13272 	  where parent_lpn_id = p_child_lpn_id;
13273 
13274      l_lpn_contents_rec c_lpn_contents%rowtype;
13275 
13276 
13277      l_lpn_rec c_validate_lpn%rowtype;
13278 
13279      l_progress varchar2(15) := '00';
13280 
13281      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
13282 
13283      l_source_header_id NUMBER;
13284      l_asn_type VARCHAR2(10);
13285      l_lpn_context NUMBER;
13286      l_transfer_lpn_context NUMBER;
13287      l_to_lpn_context NUMBER;
13288      l_wlpni_exists NUMBER;
13289      l_insp_mat_exists NUMBER;
13290      l_rti_quantity NUMBER;
13291 
13292      l_msg_count number;
13293      l_msg_data VARCHAR2(2000);
13294 
13295      l_WLPNIQLPN    VARCHAR2(30);
13296      l_WLPNIQLPN_ID NUMBER;
13297      l_WLPNIQLPN_PARENT_LPN_ID NUMBER;
13298 
13299      l_PTLPN    VARCHAR2(30);
13300      l_PTLPN_ID NUMBER;
13301      l_PTLPN_CONTEXT NUMBER;
13302      l_PTLPN_EXISTS NUMBER;
13303 
13304      l_P_PTLPN    VARCHAR2(30);
13305      l_P_PTLPN_ID NUMBER;
13306 
13307      l_from_lpn_state BOOLEAN;
13308      l_to_lpn_state BOOLEAN;
13309      l_lpn_state BOOLEAN;
13310      l_lpn_match varchar2(1);
13311 
13312      l_parent_txn_type varchar2(30);
13313      l_parent_parent_txn_id NUMBER;
13314      l_parent_parent_parent_txn_id NUMBER;
13315      l_parent_parent_txn_type VARCHAR2(30);
13316 
13317      l_rs_ptid_ptid_lpn_id NUMBER;    -- Variable to hold the lpn_id from rcv_supply for parent_parent_txn_id
13318      l_rs_ptid_ptid_exists Boolean;   -- Variable to indicate whether their Exists a supply for the Parent_parent_txn_Id
13319 
13320      l_rs_ptid_ptid_ptid_lpn_id NUMBER;   -- Variable to hold the lpn_id from rcv_supply for parent_parent_txn_id
13321      l_rs_ptid_ptid_ptid_exists Boolean;  -- Variable to indicate whether their
13322      --  Exists a supply for the Parent parent txn Id and the Tranfer LPN
13323 
13324      l_rs_ptid_lpn_id NUMBER;  -- Variable to hold the lpn_id from rcv_supply for parent_txn_id
13325      l_rs_ptid_exists Boolean;   -- Variable to indicate whether their Exists a supply for the parent txn Id
13326 
13327 
13328      l_cur_from_parent_lpn_id NUMBER;
13329      l_cur_to_parent_lpn_id NUMBER;
13330      l_cur_PTLPN_parent_lpn_id NUMBER;
13331 
13332 
13333      l_wlpni_state BOOLEAN;
13334      l_wlpni_lpn   VARCHAR2(30);
13335      l_wlpni_parent_lpn varchar2(30);
13336      l_wlpni_lpn_id NUMBER;
13337      l_wlpni_parent_lpn_id NUMBER;
13338      l_wlpni_lpn_context NUMBER;
13339      l_wlpni_cur_parent_lpn NUMBER;
13340 
13341      l_wlpni_parent_state BOOLEAN;
13342      l_wlpni_parent_lpn_context NUMBER;
13343      l_wlpni_cur_parent_parent_lpn NUMBER;
13344 
13345      l_validate_sub VARCHAR2(10);
13346      l_validate_loc_id NUMBER;
13347 
13348      l_parent_lpn_context NUMBER;
13349      l_parent_source_name VARCHAR2(30);
13350      l_parent_source_header_id NUMBER;
13351      l_parent_source_type_id NUMBER;
13352 
13353      l_update_lpn_id BOOLEAN := FALSE;
13354 
13355      l_miss_num NUMBER := FND_API.G_MISS_NUM;
13356      l_miss_char VARCHAR2(1) := FND_API.G_MISS_CHAR;
13357 
13358      l_lpn_count NUMBER;
13359 
13360      l_asn_source_header_id NUMBER;
13361      l_asn_source_type_id   NUMBER;
13362 
13363      l_lpn_already_processed NUMBER;
13364 
13365      l_parent_sub VARCHAR2(10);
13366      l_parent_locator_id NUMBER;
13367      l_parent_to_organization_id NUMBER;
13368 
13369      l_intransit_type NUMBER := 0;
13370 
13371      l_wlpn_source_header_id NUMBER;
13372      l_xfr_wlpn_source_header_id NUMBER;
13373 
13374      --R12
13375      l_lpn_grp_id                   NUMBER;
13376      l_epc_column                   VARCHAR2(30);
13377      l_epc_value                    VARCHAR2(100);
13378      l_return_status                VARCHAR2(1);
13379      --R12
13380 BEGIN
13381 
13382    x_return_status := g_ret_sts_success;
13383 
13384    IF (l_debug = 1) THEN
13385       print_debug('VALIDATE_LPN_INFO Entered...:'|| l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
13386    END If;
13387 
13388    l_progress := 'WMSINB-18089';
13389 
13390    -- Opens Cursor on RTI based on lpn_group_id
13391    open c_validate_lpn;
13392    Loop
13393       fetch c_validate_lpn into l_lpn_rec;
13394       exit when c_validate_lpn%notfound;
13395 
13396       IF (l_debug = 1) THEN
13397          print_debug('VALIDATE_LPN_INFO - Express Transaction :'||l_lpn_rec.express_transaction, 1);--Bug 5550783
13398          print_debug('VALIDATE_LPN_INFO - Transaction type :'||l_lpn_rec.transaction_type||':'||l_progress, 1);
13399       END If;
13400 
13401       --If the source document is 'REQ' then of the intransit_type in
13402       --mtl_interorg_parameters is set to 'Direct' then exit from this api.
13403       IF (l_lpn_rec.source_document_code = 'REQ'
13404 	  AND l_lpn_rec.mobile_txn = 'N'
13405 	  AND l_lpn_rec.transaction_type = 'RECEIVE'
13406 	  AND l_lpn_rec.inv_transaction_id IS NOT NULL
13407 	  AND l_lpn_rec.processing_mode_code = 'ONLINE') THEN
13408 	 BEGIN
13409 	    SELECT intransit_type
13410 	      INTO l_intransit_type
13411 	      FROM mtl_interorg_parameters
13412 	      WHERE from_organization_id = l_lpn_rec.from_organization_id
13413 	      AND to_organization_id = l_lpn_rec.to_organization_id;
13414 
13415 	    IF (l_intransit_type = 1) THEN
13416 	       print_debug('VALIDATE_LPN_INFO: Direct Org Transfer ... Exitting...',1);
13417 	       EXIT;
13418 	    END IF;
13419 	 EXCEPTION
13420 	    WHEN OTHERS THEN
13421 	       NULL;
13422 	 END;
13423       END IF; --IF (l_lpn_rec.source_document_code = 'REQ') THEN
13424 
13425       -- Set the ASN variables to null
13426       l_asn_source_header_id := null;
13427       l_asn_source_type_id := null;
13428 
13429       IF ( l_lpn_rec.item_id IS NOT NULL OR l_lpn_rec.item_description IS NOT NULL ) THEN
13430 
13431 	 IF (l_debug = 1) THEN
13432 	    print_debug('VALIDATE_LPN_INFO - item id or description is not null:'||l_lpn_rec.item_id||':'||l_lpn_rec.item_description, 1);
13433 	 END If;
13434 
13435 	 IF ((l_lpn_rec.item_id IS NULL)
13436 	     AND (l_lpn_rec.lpn_id IS NOT NULL
13437 		  OR l_lpn_rec.license_plate_number IS NOT NULL
13438 		  OR l_lpn_rec.transfer_lpn_id IS NOT NULL
13439 		  OR l_lpn_rec.transfer_license_plate_number IS NOT NULL))
13440 		    THEN
13441 	    IF (l_debug = 1) THEN
13442 	       print_debug('VALIDATE_LPN_INFO: LPNS are not supported for one time items.',1);
13443 	    END IF;
13444 	    l_progress := 'WMSINB-18116';
13445 	    RAISE fnd_api.g_exc_error;
13446 	 END IF;
13447 
13448 	 IF NVL(l_lpn_rec.quantity,0) = 0 THEN
13449 	    --
13450 	    -- Quantity is null so failure return from Here
13451 	    --
13452 	    IF (l_debug = 1) THEN
13453 	       print_debug('VALIDATE_LPN_INFO lpn/item Qty is null or zero  for this lpn id:'|| l_lpn_rec.lpn_id , 1);
13454 	       print_debug('VALIDATE_LPN_INFO lpn/item Qty is null or zero for this lpn :'|| l_lpn_rec.license_plate_number, 1);
13455 	    END If;
13456 
13457 	    l_progress := 'WMSINB-18129';
13458 	    x_return_status := g_ret_sts_error;
13459 
13460 	    -- Review Later
13461 	    -- Set appropiate Message
13462 
13463             RAISE FND_API.G_EXC_ERROR;
13464          End if;
13465 
13466 	 -- Quantity is not null so proceed with this row
13467 
13468 	 IF (l_debug = 1) THEN
13469 	    print_debug('VALIDATE_LPN_INFO - Quantity:'||l_lpn_rec.quantity, 1);
13470 	 END If;
13471 
13472 	 -- Initialize Variables
13473 	 l_source_header_id := null;
13474 	 l_asn_type := null;
13475 	 l_lpn_context := null;
13476 	 l_wlpni_exists := 0;
13477 
13478 	 -- See if we need to update the lpn_id or transfer_lpn_id in rti.
13479 	 IF ((l_lpn_rec.lpn_id IS NULL AND l_lpn_rec.license_plate_number IS NOT NULL)
13480 	     OR (l_lpn_rec.transfer_lpn_id IS NULL AND l_lpn_rec.transfer_license_plate_number IS NOT NULL)) THEN
13481 	    l_update_lpn_id := TRUE;
13482 	 END IF;
13483 
13484 	 -- **************************************************************
13485 	 -- Get THE LPN DETAILS for FROM and TRASNFER LPN
13486 	 -- **************************************************************
13487 
13488 	 l_progress := 'WMSINB-18160';
13489 
13490 	 l_from_lpn_state := get_lpn_id(l_lpn_rec.lpn_id,
13491 					l_lpn_rec.license_plate_number,
13492 					l_lpn_context,
13493 					l_cur_from_parent_lpn_id,
13494 					l_wlpn_source_header_id);
13495 
13496 	 if (l_from_lpn_state <> TRUE) then
13497 	    IF (l_debug = 1) THEN
13498 	       print_debug('VALIDATE_LPN_INFO: lpn_id and license_plate number does not exist' , 1);
13499 	    END If;
13500 	    -- Review Later.
13501 	    -- Set Appropiate MESSAGE For ERROR
13502 	    --
13503 	    l_progress := 'WMSINB-18171';
13504 	    RAISE FND_API.G_EXC_ERROR;
13505 	 End if;
13506 
13507 	 IF (l_debug = 1) THEN
13508 	    print_debug('VALIDATE_LPN_INFO - LPN ID:'||l_lpn_rec.lpn_id,1);
13509 	    print_debug('VALIDATE_LPN_INFO - LPN NAME:'||l_lpn_rec.license_plate_number,1);
13510 	    print_debug('VALIDATE_LPN_INFO - LPN Context:'||l_lpn_context,1);
13511 	    print_debug('VALIDATE_LPN_INFO - LPN Parent:'||l_cur_from_parent_lpn_id,1);
13512 	 END If;
13513 
13514 	 --
13515 	 -- Call get_lpn_id to get the transfer lpn detials
13516 	 --
13517 	 l_progress := 'WMSINB-18185';
13518 
13519 	 l_to_lpn_state := get_lpn_id(l_lpn_rec.transfer_lpn_id,
13520 				      l_lpn_rec.transfer_license_plate_number,
13521 				      l_transfer_lpn_context,
13522 				      l_cur_to_parent_lpn_id,
13523 				      l_xfr_wlpn_source_header_id);
13524 
13525 	 if (l_to_lpn_state <> TRUE ) then
13526 	    IF (l_debug = 1) THEN
13527 	       print_debug('VALIDATE_LPN_INFO: lpn_id and license_plate number does not exist' , 1);
13528 	    END If;
13529 	    -- EXISTING LPN_ID and LPN Combination is INVALID
13530 	    -- Review Later.
13531 	    -- Set Appropiate MESSAGE For ERROR
13532 	    --
13533 	    l_progress := 'WMSINB-18200';
13534 	    RAISE fnd_api.g_exc_error;
13535 	 End if;
13536 
13537 	 IF (l_debug = 1) THEN
13538 	    print_debug('VALIDATE_LPN_INFO - Transfer LPN ID:'||l_lpn_rec.transfer_lpn_id,1);
13539 	    print_debug('VALIDATE_LPN_INFO - Transfer LPN NAME:'||l_lpn_rec.transfer_license_plate_number,1);
13540 	    print_debug('VALIDATE_LPN_INFO - Transfer LPN Context:'||l_transfer_lpn_context, 1);
13541 	    print_debug('VALIDATE_LPN_INFO - Transfer LPN Parent:'||l_cur_to_parent_lpn_id,1);
13542 	 END If;
13543 
13544 	 l_progress := 'WMSINB-18211';
13545 
13546 	 if ( ( l_lpn_rec.transaction_type in ( 'RECEIVE', 'ACCEPT','REJECT','DELIVER','TRANSFER') ) or
13547 	      ( l_lpn_rec.transaction_type = 'SHIP' and l_lpn_rec.source_document_code = 'PO') ) then
13548 
13549 
13550 	    -- FROM LPN VALIDATION
13551 	    if (l_from_lpn_state = TRUE) then
13552 	       l_progress := 'WMSINB-18219';
13553 	       if l_lpn_rec.transaction_type in ( 'RECEIVE', 'ACCEPT','REJECT','DELIVER','TRANSFER') then
13554 		  if l_lpn_rec.lpn_id is null and l_lpn_rec.license_plate_number is not null then
13555 		     -- INVALID LPN or non EXISTENT LPN IN THE SYSTEM
13556 		     l_progress := 'WMSINB-18223';
13557 		     RAISE fnd_api.g_exc_error;
13558 		  End if;
13559 	       End if;
13560 	    End if;
13561 
13562 	    l_progress := 'WMSINB-18229';
13563 
13564 	    if ( l_lpn_rec.transaction_type = 'SHIP') then
13565 
13566                -- Check whether it is already processed in the same LPN Group then by pass this step
13567                -- as the context now updated properly by the previous loop
13568                -- This is based on the order by given in lpn_validation loop..
13569                -- if you change the order by in lpn validation loop then change here also..
13570 
13571                l_lpn_already_processed := 0;
13572 
13573                select count(distinct interface_transaction_id)
13574                  into l_lpn_already_processed
13575                  from rcv_transactions_interface rti
13576                 where rti.lpn_group_id = p_lpn_group_id
13577                   and ( ( rti.lpn_id = l_lpn_rec.lpn_id) or (rti.license_plate_number = l_lpn_rec.license_plate_number))
13578                   and rti.interface_transaction_id < l_lpn_rec.interface_transaction_id ;
13579 
13580 	       IF l_lpn_rec.lpn_id is not null THEN
13581 		  IF (l_debug = 1) THEN
13582 		     print_debug('VALIDATE_LPN_INFO - l_lpn_already_processed:'||l_lpn_already_processed,1);
13583 		     print_debug('VALIDATE_LPN_INFO - Shipment Header ID:'||l_lpn_rec.shipment_header_id,1);
13584 		     print_debug('VALIDATE_LPN_INFO - Source Header ID:'||l_wlpn_source_header_id,1);
13585 		  END IF;
13586                   IF (l_lpn_already_processed >= 1
13587 		      OR (l_wlpn_source_header_id =
13588 			  l_lpn_rec.shipment_header_id)) then
13589 		     -- don't need to do any validation
13590 		     IF (l_debug = 1) THEN
13591 			print_debug('VALIDATE_LPN_INFO - LPN Context already validated: '||l_lpn_rec.lpn_id,1);
13592 		     END If;
13593 		     l_progress := 'WMSINB-18230';
13594 		   ELSE
13595 		     IF ( l_lpn_context <> G_LPN_CONTEXT_PREGENERATED ) THEN
13596 			-- FAIL TRANSACTIONS
13597 			-- for SHIP TXNS it should be 6, whereas for ASN's it shoubd be 5
13598 			-- REVIEW LATER
13599 			l_progress := 'WMSINB-18237';
13600 			RAISE FND_API.G_EXC_ERROR;
13601 		     END IF;
13602                   END IF;
13603 		Else
13604 		  l_progress := 'WMSINB-18241';
13605 		  -- Create LPN Here
13606 		  if l_lpn_rec.license_plate_number is not null then
13607 
13608 		     l_progress := 'WMSINB-18244';
13609 
13610                      -- Set the ASN Variables Here
13611 	             if ( l_lpn_rec.transaction_type = 'SHIP'
13612                          and l_lpn_rec.source_document_code = 'PO' ) then
13613                         l_asn_source_header_id := l_lpn_rec.shipment_header_id;
13614                         l_asn_source_type_id   := 1;
13615                      Else
13616                         l_asn_source_header_id := null;
13617                         l_asn_source_type_id   := null;
13618                      End if;
13619 
13620 		     l_progress := 'WMSINB-18245';
13621 
13622 		     create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.license_plate_number,
13623 					   p_lpn_group_id => p_lpn_group_id,
13624 					   p_organization_id => l_lpn_rec.to_organization_id,
13625 					   p_lpn_context => G_LPN_CONTEXT_VENDOR , -- Context should be RESIDES IN VENDOR THIS CASE.
13626                                            p_source_header_id => l_asn_source_header_id,
13627                                            p_source_type_id   => l_asn_source_type_id,
13628 					   x_lpn_id => l_lpn_rec.lpn_id,
13629 					   x_return_status => x_return_status,
13630 					   x_msg_count => l_msg_count,
13631 					   x_msg_data => l_msg_data);
13632 		     -- Check the error status from the above call
13633 		     if x_return_status <> G_RET_STS_SUCCESS Then
13634 			--  Review Late Set Appropiate Message
13635 			l_progress := 'WMSINB-18256';
13636 			RAISE FND_API.G_EXC_ERROR;
13637 		     End if;
13638 
13639 		     IF (l_lpn_rec.transaction_type = 'SHIP' AND l_lpn_rec.source_document_code = 'PO') THEN
13640 			IF (l_debug = 1) THEN
13641 			   print_debug('Need to call populate_outside_epc for asn import',4);
13642 			END IF;
13643 
13644 			get_epc_info(p_mode        => 1
13645 				     ,p_lpn        => l_lpn_rec.license_plate_number
13646 				     ,p_src_grp_id => p_lpn_group_id
13647 				     ,x_epc_column => l_epc_column
13648 				     ,x_epc_value  => l_epc_value
13649 				     );
13650 
13651 			IF (l_debug = 1) THEN
13652 			   print_debug('l_epc_column:'||l_epc_column||' l_epc_value:'||l_epc_value,4);
13653 			END IF;
13654 
13655 			IF (l_epc_column IS NOT NULL) THEN
13656 			   IF (Nvl(g_lpn_group_id,-999) <> p_lpn_group_id) THEN
13657 			      g_lpn_group_id := p_lpn_group_id;
13658 			      SELECT wms_epc_s2.NEXTVAL
13659 				INTO g_epc_group_id
13660 				FROM dual;
13661 			   END IF;
13662 
13663 			   IF (l_debug = 1) THEN
13664 			      print_debug('Calling populate_outside_epc',4);
13665 			      print_debug(' p_group_id       => '||g_epc_group_id,4);
13666 			      print_debug(' p_cross_ref_type => '||1,4);
13667 			      print_debug(' p_epc            => '||l_epc_value,4);
13668 			      print_debug(' p_Lpn_id         => '||l_lpn_rec.lpn_id,4);
13669 			   END IF;
13670 
13671 			   wms_epc_pvt.populate_outside_epc
13672 			     (p_group_id        => g_epc_group_id
13673 			      ,p_cross_ref_type => 1 --LPN-EPC
13674 			      ,p_Lpn_id         => l_lpn_rec.lpn_id
13675 			      ,p_epc            => l_epc_value
13676 			      ,x_return_status  => l_return_status
13677 			      ,x_return_mesg    => l_msg_data
13678 			      );
13679 
13680 			END IF;--IF (l_epc_column IS NOT NULL) THEN
13681 		     END IF;--IF (l_lpn_rec.transaction_type = 'SHIP' AND l_lpn_rec.source_document_code = 'PO') THEN
13682 		  End if;
13683 	       End if;
13684 	    End if;
13685 
13686 	    if ( l_lpn_rec.transaction_type = 'RECEIVE') then
13687 	       --
13688 	       -- Get the Source Name of the LPN
13689 	       --
13690 	       l_progress := 'WMSINB-18267';
13691                Begin
13692 		  if l_lpn_rec.lpn_id is not null then
13693 		     --
13694 		     -- Case where lpn id is present in RTI
13695 		     --
13696 		     l_progress := 'WMSINB-18273';
13697 		     select RSH.shipment_header_id ,
13698 		       RSH.ASN_TYPE,
13699 		       WLPN.LPN_CONTEXT
13700 		       into l_source_header_id ,
13701 		       l_asn_type,
13702 		       l_lpn_context
13703 		       from WMS_LICENSE_PLATE_NUMBERS WLPN,
13704 		       RCV_SHIPMENT_HEADERS RSH
13705 		       where WLPN.lpn_id = l_lpn_rec.lpn_id
13706 		       AND (
13707 		               ((rsh.receipt_source_code IN ('INVENTORY','INTERNAL ORDER')
13708 		                  AND rsh.organization_id = wlpn.organization_id) --BUG 4730474
13709 		                  and  wlpn.source_header_id is null
13710 		                  and  wlpn.source_name=rsh.shipment_num)
13711                                   OR
13712                                  (Nvl(rsh.receipt_source_code,'#$#') NOT IN ('INVENTORY','INTERNAL ORDER')
13713 		                  and rsh.shipment_header_id=wlpn.source_header_id)
13714 			       )
13715                        and rownum = 1 ; --bug 5749200 rearranged the where clause of the query
13716 		   else
13717 		     --
13718 		     -- Case where lpn_id is not valid or null
13719 		     -- Review Later
13720 		     l_progress := 'WMSINB-18291';
13721 		     l_source_header_id := null;
13722 		     l_asn_type := null;
13723 		     l_lpn_context := null;
13724 		  end if;
13725 
13726 	       Exception
13727 		  When others then
13728 		     -- Review Later
13729 		     -- Set appropiate Message
13730 		     l_progress := 'WMSINB-18301';
13731 		     l_source_header_id := null;
13732 		     l_asn_type := null;
13733 		     l_lpn_context := null;
13734 	       End;
13735 
13736 	       IF (l_debug = 1) THEN
13737 		  print_debug('VALIDATE_LPN_INFO - Source Header ID:'||l_source_header_id,1);
13738 		  print_debug('VALIDATE_LPN_INFO - ASN Type:'||l_asn_type,1);
13739 		  print_debug('VALIDATE_LPN_INFO - Shipment Num:'||l_lpn_rec.shipment_num,1);
13740 		  print_debug('VALIDATE_LPN_INFO - Shipment Header ID:'||l_lpn_rec.shipment_header_id,1);
13741 	       END If;
13742 
13743 	       IF (l_lpn_rec.shipment_header_id IS NULL) THEN
13744 		  IF (l_lpn_rec.shipment_num IS NOT NULL) THEN
13745 		     BEGIN
13746 			SELECT shipment_header_id
13747 			  INTO l_lpn_rec.shipment_header_id
13748 			  FROM rcv_shipment_headers
13749 			  WHERE shipment_num = l_lpn_rec.shipment_num;
13750 		     EXCEPTION
13751 			WHEN OTHERS THEN
13752 			   NULL;
13753 		     END;
13754 		  END IF; --IF (l_lpn_rec.shipment_num IS NOT NULL) THEN
13755 	       END IF; --IF (l_lpn_rec.shipment_header_id IS NULL) THEN
13756 
13757 	       IF (l_debug = 1) THEN
13758 		  print_debug('VALIDATE_LPN_INFO - Shipment Header ID NOW:'||l_lpn_rec.shipment_header_id,1);
13759 	       END If;
13760 
13761 	       --
13762 	       -- Case where SOURCE in LPN and  SHIPMENT Info MISMATCH in RTI Generate Error
13763 	       --
13764 	       if (l_source_header_id is not null or l_lpn_rec.shipment_header_id is not null) then
13765 		  IF (l_lpn_rec.lpn_id IS NOT NULL AND
13766 		      nvl(l_source_header_id,0) <> nvl(l_lpn_rec.shipment_header_id,0)) then
13767 		     --
13768 		     -- Review Later
13769 		     -- Set appropiate Message
13770 		     --
13771 		     l_progress := 'WMSINB-18322';
13772 		     RAISE fnd_api.g_exc_error;
13773 		  end if;
13774 	       end if;
13775 	       --
13776 	       if ( ( Nvl(l_asn_type,'#$#$') = 'ASN' and l_lpn_context not in (G_LPN_CONTEXT_VENDOR ,G_LPN_CONTEXT_PREGENERATED)) or
13777 		    ( l_asn_type is null and l_lpn_context not in (G_LPN_CONTEXT_INTRANSIT ,G_LPN_CONTEXT_PREGENERATED) )) then
13778 		  --
13779 		  -- ASN and LPN_context is not resides in Vendor
13780 		  -- SHIPMENT and LPN_context is not Intransit
13781 		  -- Review Later
13782 		  -- Set appropiate Message
13783 		  --
13784 		  l_progress := 'WMSINB-18335';
13785 		  RAISE fnd_api.g_exc_error;
13786 	       end if;
13787 	    End if; -- Receive
13788 
13789 	    if ( l_lpn_rec.transaction_type in ('ACCEPT','REJECT') ) then
13790 	       if l_lpn_rec.lpn_id IS NOT NULL then
13791 		  if l_lpn_context <> G_LPN_CONTEXT_RCV then
13792 		     l_progress := 'WMSINB-18343';
13793 		     -- FAIL TRANSACTIONS
13794 		     -- REVIEW LATER
13795 		     RAISE FND_API.G_EXC_ERROR;
13796 		  End if;
13797 	       End if;
13798 	    End if;  -- Inspect
13799 
13800 	    l_progress := 'WMSINB-18351';
13801 
13802 	    if ( l_lpn_rec.transaction_type in ('DELIVER','TRANSFER')) then
13803 	       if l_lpn_rec.lpn_id IS NOT NULL then
13804 		  if l_lpn_context <> G_LPN_CONTEXT_RCV then
13805                      if  l_lpn_rec.transaction_type = 'DELIVER' then
13806                        BEGIN
13807 
13808                          -- CHECK WHETHER MULTIPLE ROWS EXIST in RTI FOR THE SAME FROM LPN
13809                          -- THEN FOR SUBSEQUENT LOOPS WITHIN THE SAME LPN GROUP WE
13810                          -- DON't need to validate context for DELIVER TXN because it
13811                          -- might have update the lpn context.
13812 
13813                          select count(*) into l_lpn_Count
13814                            from rcv_transactions_interface
13815                           where lpn_id = l_lpn_rec.lpn_id
13816                             and transaction_type ='DELIVER'
13817                             and interface_transaction_id < l_lpn_rec.interface_transaction_id
13818                             and lpn_group_id = p_lpn_group_id;
13819 
13820                          if l_lpn_count = 0 then
13821 		           l_progress := 'WMSINB-18357';
13822 		           RAISE FND_API.G_EXC_ERROR;
13823                          End if;
13824                        EXCEPTION
13825                          WHEN OTHERS THEN NULL;
13826                        END;
13827                      Else
13828 		       l_progress := 'WMSINB-18358';
13829 		       RAISE FND_API.G_EXC_ERROR;
13830                      End if;
13831 		  End if;
13832 		  --
13833 		  if ( l_lpn_rec.transaction_type = 'DELIVER') then
13834 		     --
13835 		     null;
13836 		     --
13837 		     -- Commented this call as not needed.
13838 		     --
13839 		     -- INSPECTED MATERIAL EXISTS IN FLPN FAIL THE TXN
13840 		     -- Begin
13841 		     --    select 1
13842 		     --      into l_insp_mat_exists
13843 		     --      from mtl_txn_request_lines mol
13844 		     --      where mol.lpn_id = l_lpn_rec.lpn_id
13845 		     --      and nvl(mol.inspection_status,2) = 1
13846 		     --      and rownum = 1;
13847 		     --    if l_insp_mat_exists = 1 then
13848 		     --       -- FAIL TRANSACTIONS
13849 		     --       -- REVIEW LATER
13850 		     --       RAISE FND_API.G_EXC_ERROR;
13851 		     --    End if;
13852 		     -- Exception
13853 		     --    When no_data_found then
13854 		     --       -- No material with Inspection Reqd. exists ok to procedd with this LPN
13855 		     --       null;
13856 		     --    When Others then
13857 		     --       -- Other Error for checking Inspection Reqd Flag.
13858 		     --       -- FAIL TRANSACTIONS
13859 		     --       -- REVIEW LATER
13860 		     --       RAISE FND_API.G_EXC_ERROR;
13861 		     -- End;
13862 		  End if;
13863 	       End if;
13864 	    End if; -- Deliver Transfer
13865 
13866 	    l_progress := 'WMSINB-18395';
13867 
13868 	    IF (l_debug = 1) THEN
13869 	       print_debug('VALIDATE_LPN_INFO - From LPN Validation ***PASSED***', 1);
13870 	    END If;
13871 
13872 	    if ( l_lpn_rec.transfer_license_plate_number is not null or l_lpn_rec.transfer_lpn_id is not null or
13873 		 l_lpn_rec.transaction_type = 'SHIP' ) then
13874 
13875 	       IF (l_debug = 1) THEN
13876 		  print_debug('VALIDATE_LPN_INFO - STARTING Transfer LPN Validation ...', 1);
13877 	       END If;
13878 
13879 	       --For a non-wms org if the transfer_lpn is not null
13880 	       --for a deliver transaction then we should fail the txn.
13881 	       IF (NOT wms_install.check_install(x_return_status,l_msg_count,
13882 					      l_msg_data,l_lpn_rec.to_organization_id)) THEN
13883 		  IF (l_lpn_rec.transaction_type = 'DELIVER' OR
13884 		      l_lpn_rec.auto_transact_code = 'DELIVER') THEN
13885 		     l_progress := 'WMSINB-18400';
13886 		     RAISE fnd_api.g_exc_error;
13887 		  END IF;
13888 	       END IF;
13889 
13890 	       --
13891 	       -- VALIDATION FOR SHIP  TXN
13892 
13893 	       l_progress := 'WMSINB-18415';
13894 
13895 	       if (l_lpn_rec.transaction_type = 'SHIP' ) then
13896 		  if ( l_lpn_rec.transfer_license_plate_number is not null
13897 		       or l_lpn_rec.transfer_lpn_id is not null ) then
13898 		     -- TRANSFER LPN SHOULD BE NULL FOR SHIP TXN
13899 		     -- FAIL TRANSACTIONS
13900 		     -- REVIEW LATER
13901 		     l_progress := 'WMSINB-18423';
13902 		     RAISE FND_API.G_EXC_ERROR;
13903 		  End if;
13904 	       End if;
13905 
13906 	       --
13907 	       -- VALIDATION FOR DELIVER and TRANSFER TXN
13908 	       -- REVIEW LATER
13909 	       --
13910 	       l_progress := 'WMSINB-18432';
13911 
13912 	       -- if l_lpn_rec.transaction_type in ('DELIVER','TRANSFER' ) then
13913 	       if l_lpn_rec.transaction_type in ('DELIVER','TRANSFER','RECEIVE' ) then
13914 
13915                      --Bug 5550783 start
13916                      IF (l_debug = 1) THEN
13917                         print_debug('lpn_id and expess_transaction check: ' || l_lpn_rec.express_transaction || ', ' || l_lpn_rec.lpn_id || ', ' || l_lpn_rec.transfer_lpn_id, 1);
13918                      END If;
13919                      --Bug 5550783 end
13920 
13921 		  if ((l_lpn_rec.lpn_id is not null) and (l_lpn_rec.lpn_id = l_lpn_rec.transfer_lpn_id )) then
13922                     x_return_status := g_ret_sts_success; --Bug 5550783
13923                      IF (l_debug = 1) THEN
13924 
13925                         print_debug('l_lpn_rec.express_transaction=' || l_lpn_rec.express_transaction , 1);
13926                         print_debug('VALIDATE_LPN_INFO - l_lpn_rec.express_transaction check ...', 1);
13927                         print_debug('VALIDATE_LPN_INFO - x_return_status=' || x_return_status, 1);
13928                         print_debug('VALIDATE_LPN_INFO - l_lpn_rec.transaction_type=' || l_lpn_rec.transaction_type, 1);
13929                         print_debug('VALIDATE_LPN_INFO - l_lpn_rec.mobile_txn=' || l_lpn_rec.mobile_txn, 1);
13930                      END If;
13931 
13932                     --Do not do the validate_total_qty if it is express transaction and also if it is a Mobil Deliver/Transfer
13933                     if ((l_lpn_rec.express_transaction = 'Y') OR (l_lpn_rec.transaction_type in ('DELIVER','TRANSFER') AND l_lpn_rec.mobile_txn = 'Y')) then--Bug 555078
13934                          IF (l_debug = 1) THEN
13935                             print_debug('l_lpn_rec.express_transaction', 1);
13936                             print_debug('VALIDATE_LPN_INFO - Not doing validate_total_qty ...', 1);
13937                          END If;
13938 
13939                     Else
13940                        --
13941                        -- CALL THE TOTAL QTY VALIDATION API HERE
13942                        --
13943                        --
13944 		       l_progress := 'WMSINB-18440';
13945 
13946 		       IF (l_debug = 1) THEN
13947 
13948 			print_debug('l_lpn_rec.express_transaction', 1);
13949 			print_debug('VALIDATE_LPN_INFO - Before validate_total_qty ...', 1);
13950 		     END If;
13951 
13952 		     validate_total_qty(p_lpn_group_id => p_lpn_group_id,
13953 					p_from_lpn_id => l_lpn_rec.lpn_id,
13954 					p_parent_lpn_id => l_cur_from_parent_lpn_id,
13955 					p_transaction_type => l_lpn_rec.transaction_type,
13956 					x_return_status    => x_return_status,
13957 					x_msg_count        => x_msg_count,
13958 					x_msg_data         => x_msg_data);
13959 
13960 		     IF (l_debug = 1) THEN
13961 			print_debug('VALIDATE_LPN_INFO - After validate_total_qty :'||x_return_status, 1);
13962 		     END If;
13963                      End if;--Bug 5550783
13964 
13965 		     if x_return_status <> G_RET_STS_SUCCESS Then
13966 			if  l_lpn_rec.transaction_type <> 'RECEIVE' then
13967 			   --  Review Late Set Appropiate Message
13968 			   l_progress := 'WMSINB-18460';
13969 			   RAISE FND_API.G_EXC_ERROR;
13970 			 Else
13971 			   -- Unpack all from here
13972 			   l_progress := 'WMSINB-18461';
13973 			   IF (l_debug = 1) THEN
13974 			      print_debug('VALIDATE_LPN_INFO - Case for Full UNPACK as QTY MISMATCH' , 1);
13975 			   END If;
13976 			   wms_container_pvt.packunpack_container(
13977 								  p_api_version            => 1.0,
13978 								  p_init_msg_list          => g_false,
13979 								  p_commit                 => g_false,
13980 								  p_validation_level       => fnd_api.g_valid_level_none,
13981 								  x_return_status          => x_return_status,
13982 								  x_msg_count              => x_msg_count,
13983 								  x_msg_data               => x_msg_data,
13984 								  p_lpn_id                 => l_lpn_rec.lpn_id,
13985 								  p_organization_id        => l_lpn_rec.from_organization_id,
13986 								  p_operation              => 2, --- TO UNPACK
13987 								  p_unpack_all             => 1,
13988 								  p_auto_unnest_empty_lpns => 2
13989 								  );
13990 			   if x_return_status <> G_RET_STS_SUCCESS Then
13991 			      l_progress := 'WMSINB-18462';
13992 			      RAISE FND_API.G_EXC_ERROR;
13993 			   End if;
13994 			End if;
13995 		     End if;
13996 		  End if;
13997 	       End if;
13998 
13999 	       l_progress := 'WMSINB-18467';
14000 
14001 	       --
14002 	       -- *********************
14003 	       -- Transfer LPN does not already exists in the system
14004 	       -- This validations is not needed for SHIP TXN
14005 	       -- *********************
14006 
14007 	       if (l_lpn_rec.transaction_type <> 'SHIP') then
14008 		  if (l_lpn_rec.transfer_lpn_id is null) then
14009 		     -- Check existence in WLPNI
14010 		     l_progress := 'WMSINB-18478';
14011 		     check_lpn_in_wlpni(l_lpn_rec.transfer_license_plate_number,
14012 					l_lpn_rec.transfer_lpn_id,
14013 					p_lpn_group_id,
14014 					l_wlpni_exists);
14015 		     if (l_wlpni_exists = 0) then
14016 			--
14017 			-- WLPNI does not exists fail the TXN
14018 			-- Review Later
14019 			-- Set appropiate Message
14020 			--
14021 			l_progress := 'WMSINB-18489';
14022 			RAISE FND_API.G_EXC_ERROR;
14023 		      else
14024 			--
14025 			-- WLPNI exists create the LPN
14026 			--
14027 			l_progress := 'WMSINB-18495';
14028 			--
14029 			-- Call API to create LPN
14030 			-- Transfer LPN Context needs to be set properly depending on context.
14031 			--
14032 			-- Call the API get_lpn_context here
14033 
14034 			l_to_lpn_context := get_lpn_context(p_transaction_type => l_lpn_rec.transaction_type
14035 							    , p_auto_transact_code => l_lpn_rec.auto_transact_code);
14036 
14037 			l_progress := 'WMSINB-18504';
14038 
14039 			IF (l_debug = 1) THEN
14040 			   print_debug('VALIDATE_LPN_INFO - NEW LPN - Calling create_lpn_from_wlpni ...', 1);
14041 			END If;
14042 
14043 			create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.transfer_license_plate_number,
14044 					      p_lpn_group_id => p_lpn_group_id,
14045 					      p_organization_id => l_lpn_rec.to_organization_id,
14046 					      p_lpn_context => l_to_lpn_context,
14047 					      x_lpn_id => l_lpn_rec.transfer_lpn_id,
14048 					      x_return_status => x_return_status,
14049 					      x_msg_count => l_msg_count,
14050 					      x_msg_data => l_msg_data);
14051 			-- Check the error status from the above call
14052 			if x_return_status <> G_RET_STS_SUCCESS Then
14053 			   --  Review Late Set Appropiate Message
14054 			   l_progress := 'WMSINB-18521';
14055 			   RAISE FND_API.G_EXC_ERROR;
14056 			End if;
14057 		     end if;
14058 		   else
14059 		     -- *********************
14060 		     -- Transfer LPN already exists in the system
14061 		     -- *********************
14062 
14063 		     -- The following validation needs to be done only when
14064 		     -- from and to lpn is different
14065 		     if (l_lpn_rec.transfer_lpn_id <> nvl(l_lpn_rec.lpn_id,-9999))  then
14066 			-- Validate Locator
14067 			l_progress := 'WMSINB-18534';
14068 			l_lpn_match := 'N';
14069 
14070 			IF (l_debug = 1) THEN
14071 			   print_debug('VALIDATE_LPN_INFO - Calling validate_lpn_locator ...', 1);
14072 			END If;
14073 
14074 			validate_lpn_locator( p_lpn_id => l_lpn_rec.transfer_lpn_id,
14075 					      p_subinventory => l_lpn_rec.subinventory,
14076 					      p_locator_id   => l_lpn_rec.locator_id,
14077 					      p_organization_id  => l_lpn_rec.to_organization_id,
14078 					      x_lpn_match        => l_lpn_match,
14079 					      x_return_status    => x_return_status,
14080 					      x_msg_count        => x_msg_count,
14081 					      x_msg_data         => x_msg_data);
14082 
14083 			if x_return_status <> G_RET_STS_SUCCESS Then
14084 			   --  Review Late Set Appropiate Message
14085 			   l_progress := 'WMSINB-18552';
14086 			   RAISE FND_API.G_EXC_ERROR;
14087 			End if;
14088 
14089 			if l_lpn_match = 'N' then
14090 			   l_progress := 'WMSINB-18557';
14091 			   RAISE FND_API.G_EXC_ERROR;
14092 			End if;
14093 
14094 			-- Check Error Status
14095 			if ( (validate_lpn_context(l_lpn_rec.transaction_type,
14096 						  l_lpn_rec.auto_transact_code,
14097 						  l_transfer_lpn_context ) <> TRUE )
14098 			     OR (l_transfer_lpn_context = g_lpn_context_picked
14099 				 AND l_lpn_rec.mmtt_temp_id IS NULL)) THEN
14100 			   --  Review Late Set Appropiate Message
14101 			   l_progress := 'WMSINB-18566';
14102 			   RAISE FND_API.G_EXC_ERROR;
14103 			End if;
14104 		     End if;
14105 		  End if;
14106 	       End if;
14107 	       --
14108 	       --
14109 	       -- Processing for NESTING
14110 	       --
14111 	       --
14112 
14113 	       l_progress := 'WMSINB-18578';
14114 
14115 	       if l_lpn_rec.transaction_type = 'SHIP' then
14116 		  l_WLPNIQLPN    := l_lpn_rec.license_plate_number;
14117 		  l_WLPNIQLPN_ID := l_lpn_rec.lpn_id;
14118 
14119 		  l_validate_sub := l_lpn_rec.subinventory;
14120 		  l_validate_loc_id := l_lpn_rec.locator_id;
14121 
14122 		  l_parent_source_name := l_lpn_rec.shipment_num;
14123 		  l_parent_source_type_id := 1;
14124 		  l_parent_source_header_id := l_lpn_rec.shipment_header_id;
14125 
14126 		  l_parent_lpn_context := get_lpn_context(p_transaction_type => l_lpn_rec.transaction_type
14127 							  , p_auto_transact_code => l_lpn_rec.auto_transact_code);
14128 		ELSE --if l_lpn_rec.transaction_type = 'SHIP' then
14129 		  l_WLPNIQLPN    := l_lpn_rec.transfer_license_plate_number;
14130 		  l_WLPNIQLPN_ID := l_lpn_rec.transfer_lpn_id;
14131 
14132 		  IF (l_lpn_rec.subinventory IS NULL) THEN
14133 		     BEGIN
14134 			SELECT subinventory_code
14135 			  , locator_id
14136 			  INTO l_validate_sub
14137 			  , l_validate_loc_id
14138 			  FROM wms_license_plate_numbers
14139 			  WHERE lpn_id = l_lpn_rec.transfer_lpn_id
14140 			  OR license_plate_number = l_lpn_rec.transfer_license_plate_number;
14141 		     EXCEPTION
14142 			WHEN OTHERS THEN
14143 			   l_validate_sub := NULL;
14144 			   l_validate_loc_id := NULL;
14145 		     END;
14146 		   ELSE
14147 			   l_validate_sub := l_lpn_rec.subinventory;
14148 			   l_validate_loc_id := l_lpn_rec.locator_id;
14149 		  END IF;
14150 
14151 		  l_parent_source_name := NULL;
14152 		  l_parent_source_type_id := NULL;
14153 		  l_parent_source_header_id := NULL;
14154 
14155 		  l_parent_lpn_context := get_lpn_context(p_transaction_type => l_lpn_rec.transaction_type
14156 							  , p_auto_transact_code => l_lpn_rec.auto_transact_code);
14157 	       END IF; --if l_lpn_rec.transaction_type = 'SHIP' then
14158 
14159 	       IF (l_debug = 1) THEN
14160 		  print_debug('VALIDATE_LPN_INFO - Getting into nesting logic ...', 1);
14161 		  print_debug('VALIDATE_LPN_INFO - WLPNQLPN:'||l_wlpniqlpn,1);
14162 		  print_debug('VALIDATE_LPN_INFO - WLPNQLPN_ID:'||l_wlpniqlpn_id,1);
14163 	       END If;
14164 
14165 	       Loop
14166 		  -- Initialize
14167 		  l_PTLPN_ID := null;
14168 		  l_PTLPN    := null;
14169 		  l_PTLPN_CONTEXT := null;
14170 		  l_PTLPN_EXISTS := 0;
14171 
14172 
14173 		  l_WLPNIQLPN_PARENT_LPN_ID := null;
14174 
14175 		  l_progress := 'WMSINB-18638';
14176 
14177                   Begin
14178 
14179 		     -- We need to make this distinct becasue there might exist multple rows in wlpni
14180 		     -- for the same LPN , but for all those rows the parent should be same
14181 
14182 		     select distinct
14183 		       parent_lpn_id,
14184 		       parent_license_plate_number
14185 		       into l_PTLPN_ID,
14186 		       l_PTLPN
14187 		       from wms_lpn_interface wlpni
14188 		       where ( nvl(wlpni.license_plate_number,'-1') = nvl(l_WLPNIQLPN,'-1') or
14189 			       nvl(wlpni.lpn_id,'-1') = nvl(l_WLPNIQLPN_ID,'-1') )
14190 		       and wlpni.source_group_id = p_lpn_group_id;
14191 
14192 		     l_progress := 'WMSINB-18655';
14193 		  Exception
14194 		     When no_data_found then
14195 			l_progress := 'WMSINB-18658';
14196 			exit;
14197 		     When others then
14198 			l_progress := 'WMSINB-18661';
14199 			-- Review Later
14200 			-- Set appropiate Message
14201 			--
14202 			RAISE FND_API.G_EXC_ERROR;
14203 		  End;
14204 		  --
14205 
14206 		  IF (l_debug = 1) THEN
14207 		     print_debug('VALIDATE_LPN_INFO - FROM WLPNI parent_lpn_id:'||l_PTLPN_ID,1);
14208 		     print_debug('VALIDATE_LPN_INFO - FROM WLPNI parent_lpn:'||l_PTLPN,1);
14209 		  END If;
14210 
14211 		  l_progress := 'WMSINB-18674';
14212 
14213 		  if (l_PTLPN_ID is not null or l_PTLPN is not null) then
14214 		     --
14215 		     -- Call get_lpn_id
14216 
14217 		     l_lpn_state := get_lpn_id(l_PTLPN_ID, l_PTLPN ,
14218 					       l_PTLPN_context,
14219 					       l_cur_ptlpn_parent_lpn_id,
14220 					       l_wlpn_source_header_id) ;
14221 
14222 		     --
14223 
14224 		     IF (l_debug = 1) THEN
14225 			print_debug('VALIDATE_LPN_INFO - l_PTLPN_context:'||l_PTLPN_context,1);
14226 			print_debug('VALIDATE_LPN_INFO - l_cur_PTLPN_parent_lpn_id:'||l_cur_PTLPN_parent_lpn_id,1);
14227 		     END If;
14228 
14229 		     if (l_PTLPN_ID is null ) then
14230 			-- Check existence in WLPNI
14231 			l_progress := 'WMSINB-18691';
14232 			-- Call API to create LPN
14233 
14234 			-- Need to set the CONTEXT properly Here. This part might come for
14235 			-- SHIP TXN so handled here
14236 			-- Call the get_lpn_context to set the conext
14237 
14238 			l_to_lpn_context := get_lpn_context(p_transaction_type => l_lpn_rec.transaction_type
14239 							    , p_auto_transact_code => l_lpn_rec.auto_transact_code);
14240 
14241 			l_progress := 'WMSINB-18700';
14242 
14243 			create_lpn_from_wlpni(p_license_plate_number => l_PTLPN,
14244 					      p_lpn_group_id => p_lpn_group_id,
14245 					      p_organization_id => l_lpn_rec.to_organization_id,
14246 					      p_lpn_context => l_to_lpn_context,
14247                                               p_source_header_id => l_asn_source_header_id,
14248                                               p_source_type_id   => l_asn_source_type_id,
14249 					      x_lpn_id => l_PTLPN_ID,
14250 					      x_return_status => x_return_status,
14251 					      x_msg_count => l_msg_count,
14252 					      x_msg_data => l_msg_data);
14253 			-- Check error status
14254 			-- Check the error status from the above call
14255 			if x_return_status <> G_RET_STS_SUCCESS Then
14256 			   --  Review Late Set Appropiate Message
14257 			   l_progress := 'WMSINB-18714';
14258 			   RAISE FND_API.G_EXC_ERROR;
14259 			End if;
14260 		      else
14261 			-- *********************
14262 			-- PARENT LPN already exists in the system
14263 			-- *********************
14264 			-- Validate Locator
14265 			l_progress := 'WMSINB-18722';
14266 			l_lpn_match := 'N';
14267 			validate_lpn_locator( p_lpn_id => l_PTLPN_ID,
14268 					      p_subinventory => l_validate_sub,
14269 					      p_locator_id   => l_validate_loc_id,
14270 					      p_organization_id  => l_lpn_rec.to_organization_id,
14271 					      x_lpn_match        => l_lpn_match,
14272 					      x_return_status    => x_return_status,
14273 					      x_msg_count        => x_msg_count,
14274 					      x_msg_data         => x_msg_data);
14275 
14276 			if x_return_status <> G_RET_STS_SUCCESS Then
14277 			   --  Review Late Set Appropiate Message
14278 			   l_progress := 'WMSINB-18735';
14279 			   RAISE FND_API.G_EXC_ERROR;
14280 			End if;
14281 
14282 			if l_lpn_match = 'N' then
14283 			   l_progress := 'WMSINB-18740';
14284 			   RAISE FND_API.G_EXC_ERROR;
14285 			End if;
14286 
14287 			IF (l_lpn_rec.transaction_type = 'SHIP'
14288 			    AND	(l_lpn_rec.shipment_header_id = l_wlpn_source_header_id)) THEN
14289 			   IF (l_debug = 1) THEN
14290 			      print_debug('VALIDATE_LPN_INFO - LPN Context already validated: '||l_PTLPN_ID,1);
14291 			   END If;
14292 			 ELSE
14293 			   if ( (validate_lpn_context(l_lpn_rec.transaction_type,
14294 						     l_lpn_rec.auto_transact_code,
14295 						     l_PTLPN_CONTEXT ) <> TRUE)
14296 				OR (l_PTLPN_CONTEXT = g_lpn_context_picked
14297 				    AND l_lpn_rec.mmtt_temp_id IS NULL)
14298 				) then
14299 			      --  Review Late Set Appropiate Message
14300 			      l_progress := 'WMSINB-18748';
14301 			      RAISE FND_API.G_EXC_ERROR;
14302 			   End if;
14303 			END IF; --IF (l_lpn_rec.transaction_type = 'SHIP'
14304 			--
14305 
14306 			IF (l_ptlpn_context = g_lpn_context_picked
14307 			    AND l_lpn_rec.mmtt_temp_id IS NOT NULL
14308 			    AND l_lpn_rec.transaction_type = 'DELIVER') THEN
14309 			   l_parent_lpn_context := l_ptlpn_context;
14310 			END IF;
14311 		     end if;
14312 		     --
14313 		     --
14314 		     l_progress := 'WMSINB-18755';
14315 		     get_parent_lpn(l_WLPNIQLPN, l_WLPNIQLPN_PARENT_LPN_ID);
14316 		     --
14317 		     --
14318 		     --l_progress := 'WMSINB-18759';
14319 		     --get_parent_lpn_in_wlpni(l_PTLPN, l_PTLPN_ID, p_lpn_group_id, l_P_PTLPN, l_P_PTLPN_ID);
14320 		     --
14321 		     -- Review the Organization id in call to packunpack.
14322 
14323 		     IF (l_debug = 1) THEN
14324 			print_debug('VALIDATE_LPN_INFO - FROM WLPN l_WLPNIQLPN_PARENT_LPN_ID:'||l_WLPNIQLPN_PARENT_LPN_ID,1);
14325 		     END If;
14326 
14327 		     if(l_WLPNIQLPN_PARENT_LPN_ID is not null and
14328 			l_WLPNIQLPN_PARENT_LPN_ID <> l_PTLPN_ID )
14329 		       then
14330 			l_progress := 'WMSINB-18771';
14331 			-- Review Later
14332 			-- UNPACK WLPNIQLPN FROM CURRENT PARENT
14333 			-- PACK WLPNIQLPN IN PTLPN
14334 
14335 			wms_container_pvt.packunpack_container(
14336 							       p_api_version            => 1.0,
14337 							       p_init_msg_list          => g_false,
14338 							       p_commit                 => g_false,
14339 							       p_validation_level       => fnd_api.g_valid_level_none,
14340 							       x_return_status          => x_return_status,
14341 							       x_msg_count              => l_msg_count,
14342 							       x_msg_data               => l_msg_data,
14343 							       p_lpn_id                 => l_WLPNIQLPN_PARENT_LPN_ID,
14344 							       p_content_lpn_id         => l_WLPNIQLPN_ID,
14345 							       p_organization_id        => l_lpn_rec.from_organization_id,
14346 							       p_operation              => 2 --- TO UNPACK
14347 							       );
14348 
14349 			IF (x_return_status <> g_ret_sts_success) THEN
14350 			   IF (l_debug = 1) THEN
14351 			      print_debug('VALIDATE_LPN_INFO: packunpack_container failed progress = ' || l_progress,1);
14352 			   END IF;
14353 			   l_progress := 'WMSINB-18794';
14354 			   RAISE fnd_api.g_exc_error;
14355 			END IF;
14356 
14357 			l_progress := 'WMSINB-18798';
14358 
14359 			--we need to update the lpn_context and sub/loc for the
14360 			--transfer lpn right here so that it has the right context.
14361 			--we need to do it before the packunpack
14362 			--otherwise packunpack fails
14363 
14364 			update_lpn_location_context(p_organization_id => NULL
14365 						    ,p_sub => l_lpn_rec.subinventory
14366 						    ,p_locator => l_lpn_rec.locator_id
14367 						    ,p_lpn_context => l_parent_lpn_context
14368 						    ,p_lpn_id => l_WLPNIQLPN_ID
14369 						    ,x_return_status => x_return_status
14370 						    ,x_msg_count => x_msg_count
14371 						    ,x_msg_data => x_msg_data
14372 						    ,p_source_name => l_parent_source_name
14373 						    ,p_source_header_id => l_parent_source_header_id
14374 						    ,p_source_type_id => l_parent_source_type_id);
14375 			IF (x_return_status <> g_ret_sts_success) THEN
14376 			   --raise an error
14377 			   --review later
14378 			   l_progress := 'WMSINB-18818';
14379 			   RAISE fnd_api.g_exc_error;
14380 			END IF;
14381 
14382 
14383 			--we need to update the lpn_context for the
14384 			--parent right here so that it has the right context.
14385 
14386 			update_lpn_location_context(p_organization_id => NULL
14387 						    ,p_sub => l_lpn_rec.subinventory
14388 						    ,p_locator => l_lpn_rec.locator_id
14389 						    ,p_lpn_context => l_parent_lpn_context
14390 						    ,p_lpn_id => l_PTLPN_ID
14391 						    ,x_return_status => x_return_status
14392 						    ,x_msg_count => x_msg_count
14393 						    ,x_msg_data => x_msg_data
14394 						    ,p_source_name => l_parent_source_name
14395 						    ,p_source_header_id => l_parent_source_header_id
14396 						    ,p_source_type_id => l_parent_source_type_id);
14397 			IF (x_return_status <> g_ret_sts_success) THEN
14398 			   --raise an error
14399 			   --review later
14400 			   l_progress := 'WMSINB-18822';
14401 			   RAISE fnd_api.g_exc_error;
14402 			END IF;
14403 
14404 			wms_container_pvt.packunpack_container(
14405 							       p_api_version            => 1.0,
14406 							       p_init_msg_list          => g_false,
14407 							       p_commit                 => g_false,
14408 							       p_validation_level       => fnd_api.g_valid_level_none,
14409 							       x_return_status          => x_return_status,
14410 							       x_msg_count              => l_msg_count,
14411 							       x_msg_data               => l_msg_data,
14412 							       p_lpn_id                 => l_PTLPN_ID,
14413 							       p_content_lpn_id         => l_WLPNIQLPN_ID,
14414 							       p_organization_id        => l_lpn_rec.to_organization_id,
14415 							       p_operation              => 1 --- TO PACK
14416 							       );
14417 			IF (x_return_status <> g_ret_sts_success) THEN
14418 			   IF (l_debug = 1) THEN
14419 			      print_debug('VALIDATE_LPN_INFO: packunpack_container failed progress = ' || l_progress,1);
14420 			   END IF;
14421 			   l_progress := 'WMSINB-18841';
14422 			   RAISE fnd_api.g_exc_error;
14423 			END IF;
14424 
14425 		      else
14426 			l_progress := 'WMSINB-18869';
14427 			if  l_WLPNIQLPN_PARENT_LPN_ID is null then
14428 			   l_progress := 'WMSINB-18871';
14429 
14430 			   --we need to update the lpn_context and sub/loc for the
14431 			   --transfer lpn right here so that it has the right context.
14432 			   --we need to do it before the packunpack
14433 			   --otherwise packunpack fails
14434 			   IF (l_debug = 1) THEN
14435 			      print_debug('Going to update the lpn:'|| l_WLPNIQLPN_ID,1);
14436 			   END IF;
14437 
14438 			   update_lpn_location_context(p_organization_id => NULL
14439 						       ,p_sub => l_lpn_rec.subinventory
14440 						       ,p_locator => l_lpn_rec.locator_id
14441 						       ,p_lpn_context => l_parent_lpn_context
14442 						       ,p_lpn_id => l_WLPNIQLPN_ID
14443 						       ,x_return_status => x_return_status
14444 						       ,x_msg_count => x_msg_count
14445 						       ,x_msg_data => x_msg_data
14446 						       ,p_source_name => l_parent_source_name
14447 						       ,p_source_header_id => l_parent_source_header_id
14448 						       ,p_source_type_id => l_parent_source_type_id);
14449 			   IF (x_return_status <> g_ret_sts_success) THEN
14450 			      --raise an error
14451 			      --review later
14452 			      l_progress := 'WMSINB-18891';
14453 			      RAISE fnd_api.g_exc_error;
14454 			   END IF;
14455 
14456 			   --we need to update the lpn_context for the
14457 			   --parent right here so that it has the right context.
14458 
14459 			   update_lpn_location_context(p_organization_id => NULL
14460 						       ,p_sub => l_lpn_rec.subinventory
14461 						       ,p_locator => l_lpn_rec.locator_id
14462 						       ,p_lpn_context => l_parent_lpn_context
14463 						       ,p_lpn_id => l_PTLPN_ID
14464 						       ,x_return_status => x_return_status
14465 						       ,x_msg_count => x_msg_count
14466 						       ,x_msg_data => x_msg_data
14467 						       ,p_source_name => l_parent_source_name
14468 						       ,p_source_header_id => l_parent_source_header_id
14469 						       ,p_source_type_id => l_parent_source_type_id);
14470 			   IF (x_return_status <> g_ret_sts_success) THEN
14471 			      --raise an error
14472 			      --review later
14473 			      l_progress := 'WMSINB-18895';
14474 			      RAISE fnd_api.g_exc_error;
14475 			   END IF;
14476 
14477 			   -- Review Later
14478 			   --PACK WLPNIQLPN IN PTLPN
14479 			      IF (l_debug = 1) THEN
14480 			     print_debug('Calling packunpack_container',1);
14481   		           END IF;
14482 
14483 		          /* Bug 4624542-Passing the parameters p_source_name and
14484 			   p_source_header_id to packunpack_container */
14485 
14486 			   wms_container_pvt.packunpack_container(
14487 								  p_api_version            => 1.0,
14488 								  p_init_msg_list          => g_false,
14489 								  p_commit                 => g_false,
14490 								  p_validation_level       => fnd_api.g_valid_level_none,
14491 								  x_return_status          => x_return_status,
14492 								  x_msg_count              => l_msg_count,
14493 								  x_msg_data               => l_msg_data,
14494 								  p_lpn_id                 => l_PTLPN_ID,
14495 								  p_content_lpn_id         => l_WLPNIQLPN_ID,
14496 								  p_organization_id        => l_lpn_rec.to_organization_id,
14497 								  p_operation              => 1, --- TO PACK
14498 								  p_source_name            => l_parent_source_name, --Bug 4624542
14499 							          p_source_header_id       => l_parent_source_header_id --Bug 4624542
14500 
14501 								  );
14502 			   IF (x_return_status <> g_ret_sts_success) THEN
14503 			      IF (l_debug = 1) THEN
14504 				 print_debug('VALIDATE_LPN_INFO: packunpack_container failed progress = ' || l_progress,1);
14505 			      END IF;
14506 			      l_progress := 'WMSINB-18917';
14507 			      RAISE fnd_api.g_exc_error;
14508 			   END IF;
14509 			end if;
14510 		     end if;
14511 		   else -- **** where PTLPN and PTLPN_ID is both null in WLPNI
14512 		     --
14513 		     l_progress := 'WMSINB-18944';
14514 		     get_parent_lpn(l_WLPNIQLPN, l_WLPNIQLPN_PARENT_LPN_ID);
14515 		     --
14516 
14517 		     IF (l_debug = 1) THEN
14518 			print_debug('VALIDATE_LPN_INFO - FROM WLPN l_WLPNIQLPN_PARENT_LPN_ID:'||l_WLPNIQLPN_PARENT_LPN_ID,1);
14519 		     END If;
14520 
14521 		     if l_WLPNIQLPN_PARENT_LPN_ID is not null then
14522 			l_progress := 'WMSINB-18953';
14523 			-- Call UNPACK API to unpack this LPN from parent LPN
14524 			-- Review Later
14525 			wms_container_pvt.packunpack_container(
14526 							       p_api_version            => 1.0,
14527 							       p_init_msg_list          => g_false,
14528 							       p_commit                 => g_false,
14529 							       p_validation_level       => fnd_api.g_valid_level_none,
14530 							       x_return_status          => x_return_status,
14531 							       x_msg_count              => l_msg_count,
14532 							       x_msg_data               => l_msg_data,
14533 							       p_lpn_id                 => l_WLPNIQLPN_PARENT_LPN_ID,
14534 							       p_content_lpn_id         => l_WLPNIQLPN_ID,
14535 							       p_organization_id        => l_lpn_rec.from_organization_id,
14536 							       p_operation              => 2 --- TO UNPACK
14537 							       );
14538 			IF (x_return_status <> g_ret_sts_success) THEN
14539 			   IF (l_debug = 1) THEN
14540 			      print_debug('VALIDATE_LPN_INFO: packunpack_container failed progress = ' || l_progress,1);
14541 			   END IF;
14542 			   l_progress := 'WMSINB-18973';
14543 			   RAISE fnd_api.g_exc_error;
14544 			END IF;
14545 			l_progress := 'WMSINB-18976';
14546 		     end if;
14547 		  end if;
14548 
14549 		  --
14550 		  -- Reinitialize for the next loop
14551 
14552 		  l_progress := 'WMSINB-18983';
14553 
14554 		  IF (l_debug = 1) THEN
14555 		     print_debug('VALIDATE_LPN_INFO: Before deleting wlpni l_progess = '|| l_progress, 1);
14556 		  END If;
14557 
14558 		  delete_wlpni(p_lpn_group_id,l_WLPNIQLPN_ID,l_WLPNIQLPN,x_return_status,x_msg_count,x_msg_data);
14559 
14560 		  l_progress := 'WMSINB-18991';
14561 
14562 		  IF (l_debug = 1) THEN
14563 		     print_debug('VALIDATE_LPN_INFO: after deleting wlpni l_progess = '|| l_progress, 1);
14564 		  END If;
14565 
14566 		  l_WLPNIQLPN    := l_PTLPN;
14567 		  l_WLPNIQLPN_ID := l_PTLPN_ID;
14568 
14569 		  if (l_WLPNIQLPN is null and l_WLPNIQLPN_ID is null ) then
14570 		     -- If PARENT is null, no change in nesting so exit from loop
14571 		     exit;
14572 		  End if;
14573 
14574 	       End Loop;
14575 
14576 	       IF (l_debug = 1) THEN
14577 		  print_debug('VALIDATE_LPN_INFO - Done with Nesting ...',1);
14578 	       END IF;
14579 	       --
14580 	       --
14581 	       -- **** LPN and TRANSFER LPN ARE SAME ************
14582 	       --
14583 	       l_progress := 'WMSINB-19014';
14584 
14585 	       -- The following can happen only in case for existing LPN's so
14586 	       -- in that case both the lpn_id, transfer_lpn_id, lpn, transfer_lpn
14587 	       -- must have been derived by the system
14588 	       --
14589 	       if ( (l_lpn_rec.lpn_id = l_lpn_rec.transfer_lpn_id) and
14590 		    (l_lpn_rec.license_plate_number = l_lpn_rec.transfer_license_plate_number) ) then
14591 		  --
14592 		  l_progress := 'WMSINB-19023';
14593 
14594 		  l_PTLPN := null;
14595 		  l_PTLPN_ID := null;
14596 
14597 		  get_parent_lpn(l_lpn_rec.transfer_license_plate_number, l_PTLPN_ID);
14598 
14599 		  -- Validate Locator
14600 		  l_progress := 'WMSINB-19031';
14601 
14602 		  l_lpn_state := get_lpn_id(l_PTLPN, l_PTLPN_ID,
14603 					    l_PTLPN_CONTEXT,
14604 					    l_cur_ptlpn_parent_lpn_id,
14605 					    l_wlpn_source_header_id);
14606 
14607 		  if (l_PTLPN_ID is not null ) then
14608 		     null;
14609 		  end if;
14610 	       end if;
14611 	    end if;
14612 	 end if; -- End of RECEIVE, DELIVER, TRANSFER, SHIP txn
14613 
14614 
14615 	 if (l_lpn_rec.transaction_type in ('CORRECT','RETURN TO VENDOR','RETURN TO RECEIVING', 'RETURN TO CUSTOMER'))
14616 	   then
14617 
14618 	    l_progress := 'WMSINB-19046';
14619 	    -- Get The Parent Txn Details
14620             Begin
14621 	       select transaction_type
14622 		 into l_parent_txn_type
14623 		 from rcv_transactions rt
14624 		 where rt.transaction_id = l_lpn_rec.parent_transaction_id;
14625 	    Exception
14626 	       When others then
14627 		  -- Review Later
14628 		  -- Set appropiate Message
14629 		  --
14630 		  null;
14631 	    End;
14632 
14633 	    -- Get The Grand Parent Txn Details
14634 	    -- May not be Needed for ALL CASES
14635             Begin
14636 	       select parent_transaction_id
14637 		 into l_parent_parent_txn_id
14638 		 from rcv_transactions rt
14639 		 where rt.transaction_id = l_lpn_rec.parent_transaction_id;
14640 	    Exception
14641 	       When others then
14642 		  null;
14643 	    End;
14644 
14645 	    -- Get The Grand Parent Txn TYPE Details
14646 	    -- May not be Needed for ALL CASES
14647             Begin
14648 	       select transaction_type
14649 		 into l_parent_parent_txn_type
14650 		 from rcv_transactions rt
14651 		 where rt.transaction_id = l_parent_parent_txn_id;
14652 	    Exception
14653 	       When others then
14654 		  null;
14655 	    End;
14656 
14657 	    -- Get The Grand Grand Parent Txn Details
14658 	    -- May not be Needed for ALL CASES
14659             Begin
14660 	       select parent_transaction_id
14661 		 into l_parent_parent_parent_txn_id
14662 		 from rcv_transactions rt
14663 		 where rt.transaction_id = l_parent_parent_txn_id;
14664 	    Exception
14665 	       When others then
14666 		  null;
14667 	    End;
14668 
14669 	    l_progress := 'WMSINB-19097';
14670 
14671 	    l_rs_ptid_exists := validate_rs(null,
14672 					    l_lpn_rec.parent_transaction_id,
14673 					    l_rs_ptid_lpn_id );
14674 
14675 	    l_rs_ptid_ptid_exists := validate_rs(null,
14676 						 l_parent_parent_txn_id,
14677 						 l_rs_ptid_ptid_lpn_id );
14678 
14679 	    l_rs_ptid_ptid_ptid_exists := validate_rs(null,
14680 						      l_parent_parent_parent_txn_id,
14681 						      l_rs_ptid_ptid_ptid_lpn_id );
14682 
14683 	    IF (l_debug = 1) THEN
14684 	       print_debug('VALIDATE_LPN_INFO: l_rs_ptid_lpn_id:'||l_rs_ptid_lpn_id,1);
14685 	       print_debug('VALIDATE_LPN_INFO: l_rs_ptid_ptid_lpn_id:'||l_rs_ptid_ptid_lpn_id,1);
14686 	       print_debug('VALIDATE_LPN_INFO: l_rs_ptid_ptid_ptid_lpn_id:'||l_rs_ptid_ptid_ptid_lpn_id,1);
14687 	    END IF;
14688 
14689 	    l_progress := 'WMSINB-19112';
14690 
14691 	    -- START OF NEGATIVE CORRECTION
14692 	    if (l_lpn_rec.transaction_type = 'CORRECT' and l_lpn_rec.quantity < 0 ) then  -- START OF NEGATIVE CORRECTION
14693 
14694 	       if l_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER','DELIVER') then
14695 
14696 		  if (l_lpn_rec.transfer_license_plate_number is not null or l_lpn_rec.transfer_lpn_id is not null) then
14697 
14698 		     if l_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER') then
14699 			l_progress := 'WMSINB-19122';
14700 			if l_lpn_rec.transfer_lpn_id is null then
14701 			   --  TRANSFER LPN DOES NOT EXIST IN THE SYSTEM
14702 			   -- FAIL the TXN
14703 			   -- Review Later
14704 			   -- Set appropiate Message
14705 			   --
14706 			   l_progress := 'WMSINB-19129';
14707 			   RAISE FND_API.G_EXC_ERROR;
14708 			 else
14709 			   -- TRANSFER LPN EXISTS in THE SYSTEM
14710 			   if l_transfer_lpn_context <> G_LPN_CONTEXT_RCV then
14711 			      -- Transfer LPN Context Invalid for this TXN
14712 			      -- FAIL the TXN
14713 			      -- Review Later
14714 			      -- Set appropiate Message
14715 			      --
14716 			      l_progress := 'WMSINB-19139';
14717 			      RAISE FND_API.G_EXC_ERROR;
14718 			   End if;
14719 			   l_progress := 'WMSINB-19142';
14720 			   --
14721 			   -- START CHECKING IN RCV_SUPPLY
14722 			   -- IF RS.PTID.TLPN NOT EXISTS THEN FAIL TXN
14723 
14724 			   if ( (l_rs_ptid_Exists <> TRUE) or ( nvl(l_lpn_rec.transfer_lpn_id,0) <>
14725 								nvl(l_rs_ptid_lpn_id,-9999)) ) then
14726 			      --
14727 			      -- FAIL the TXN
14728 			      -- Review Later
14729 			      -- Set appropiate Message
14730 			      --
14731 			      l_progress := 'WMSINB-19154';
14732 			      RAISE FND_API.G_EXC_ERROR;
14733 			   End if;
14734 			End if;
14735 		     End if; -- End of RECEIVE','ACCEPT','REJECT','TRANSFER TXN
14736 
14737 		     l_progress := 'WMSINB-19160';
14738 
14739 		     if l_parent_txn_type in ('DELIVER') then
14740 			if l_lpn_rec.transfer_lpn_id is null then
14741 			   --  TRANSFER LPN DOES NOT EXIST IN THE SYSTEM
14742 			   -- FAIL the TXN
14743 			   -- Review Later
14744 			   -- Set appropiate Message
14745 			   --
14746 			   l_progress := 'WMSINB-19169';
14747 			   RAISE FND_API.G_EXC_ERROR;
14748 			 else
14749 			   -- TRANSFER LPN EXISTS in THE SYSTEM
14750 			   if l_transfer_lpn_context <> G_LPN_CONTEXT_INV then
14751 			      -- Transfer LPN Context Invalid for this TXN
14752 			      -- FAIL the TXN
14753 			      -- Review Later
14754 			      -- Set appropiate Message
14755 			      --
14756 			      l_progress := 'WMSINB-19179';
14757 			      RAISE FND_API.G_EXC_ERROR;
14758 			   End if;
14759 			End if;
14760 		     End if;  -- End of DELIVER TXN
14761 
14762 		   Else -- Transfer LPN is null case
14763 		     if l_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER','DELIVER') then
14764 			if ( l_rs_ptid_lpn_id is not null) then
14765 			   -- FAIL the TXN
14766 			   -- Review Later
14767 			   -- Set appropiate Message
14768 			   --
14769 			   l_progress := 'WMSINB-19192';
14770 			   RAISE FND_API.G_EXC_ERROR;
14771 			End if;
14772 		     End if;
14773 		  End if; -- End of Transfer LPN Not null
14774 
14775 		  l_progress := 'WMSINB-19198';
14776 
14777 		  if (l_lpn_rec.lpn_id is not null or l_lpn_rec.license_plate_number is not null) then
14778 		     if l_parent_txn_type in ('RECEIVE') then
14779 			-- FAIL the TXN
14780 			-- Review Later
14781 			-- Set appropiate Message
14782 			--
14783 			l_progress := 'WMSINB-19206';
14784 			RAISE FND_API.G_EXC_ERROR;
14785 		     End if;
14786 
14787 		     IF ( ( NVL(l_lpn_rec.lpn_id,0) <> NVL(l_lpn_rec.transfer_lpn_id,0) ) OR
14788 			  ( NVL(l_lpn_rec.license_plate_number,'-9999') <> NVL(l_lpn_rec.transfer_license_plate_number,'-9999') )
14789 			  ) THEN
14790 
14791 			IF l_parent_txn_type in ('ACCEPT','REJECT','TRANSFER','DELIVER') THEN
14792 			   IF ( l_rs_ptid_ptid_exists <> TRUE ) THEN
14793 			      IF l_lpn_rec.lpn_id IS NOT NULL THEN
14794 				 IF l_lpn_context NOT IN (G_LPN_CONTEXT_RCV, G_LPN_CONTEXT_PREGENERATED) THEN
14795 				    -- FAIL the TXN
14796 				    -- Review Later
14797 				    -- Set appropiate Message
14798 				    --
14799 				    l_progress := 'WMSINB-19222';
14800 				    RAISE FND_API.G_EXC_ERROR;
14801 				 End if;
14802 				 -- Validate Locator
14803 				 -- Review Later
14804 				 l_lpn_match := 'N';
14805 				 validate_lpn_locator( p_lpn_id => l_lpn_rec.lpn_id,
14806 						       p_subinventory => l_lpn_rec.subinventory,
14807 						       p_locator_id   => l_lpn_rec.locator_id,
14808 						       p_organization_id  => l_lpn_rec.to_organization_id,
14809 						       x_lpn_match        => l_lpn_match,
14810 						       x_return_status    => x_return_status,
14811 						       x_msg_count        => x_msg_count,
14812 						       x_msg_data         => x_msg_data);
14813 
14814 				 l_progress := 'WMSINB-19237';
14815 				 if x_return_status <> G_RET_STS_SUCCESS Then
14816 				    --  Review Late Set Appropiate Message
14817 				    l_progress := 'WMSINB-19240';
14818 				    RAISE FND_API.G_EXC_ERROR;
14819 				 End if;
14820 
14821 				 l_progress := 'WMSINB-19244';
14822 
14823 				 if l_lpn_match = 'N' then
14824 				    l_progress := 'WMSINB-19247';
14825 				    RAISE FND_API.G_EXC_ERROR;
14826 				 End if;
14827 			       Else -- Create LPN with context as 3
14828 				 -- Create LPN Here
14829 				 l_progress := 'WMSINB-19252';
14830 				 create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.license_plate_number,
14831 						       p_lpn_group_id => p_lpn_group_id,
14832 						       p_organization_id => l_lpn_rec.to_organization_id,
14833 						       p_lpn_context => G_LPN_CONTEXT_RCV ,
14834 						       x_lpn_id => l_lpn_rec.lpn_id,
14835 						       x_return_status => x_return_status,
14836 						       x_msg_count => l_msg_count,
14837 						       x_msg_data => l_msg_data);
14838 				 -- Check the error status from the above call
14839 				 if x_return_status <> G_RET_STS_SUCCESS Then
14840 				    --  Review Late Set Appropiate Message
14841 				    l_progress := 'WMSINB-19264';
14842 				    RAISE FND_API.G_EXC_ERROR;
14843 				 End if;
14844 			      End if;
14845 			    Else -- RS.PTID.PTID Exists case supply LPN and FROM LPN SHOULD MATCH
14846 			      if (nvl(l_rs_ptid_ptid_lpn_id,-9999) <> nvl(l_lpn_rec.lpn_id,0) ) then
14847 				 -- FAIL the TXN
14848 				 -- Review Later
14849 				 -- Set appropiate Message
14850 				 --
14851 				 l_progress := 'WMSINB-19274';
14852 				 RAISE FND_API.G_EXC_ERROR;
14853 			      End if;
14854 			   End if;
14855 			End if;  -- END OF ACCEPT/REJECT/TRANSFER/DELIVER
14856 		      Elsif (l_lpn_rec.lpn_id = l_lpn_rec.transfer_lpn_id) then  -- FLPN and TLPN SAME
14857 			if l_parent_txn_type in ('ACCEPT','REJECT','TRANSFER','DELIVER') then
14858 			   if ( l_rs_ptid_ptid_exists = TRUE ) then
14859 			      if (nvl(l_rs_ptid_ptid_lpn_id,-9999) <> l_lpn_rec.lpn_id ) then
14860 				 -- FAIL the TXN
14861 				 -- Review Later
14862 				 -- Set appropiate Message
14863 				 --
14864 				 l_progress := 'WMSINB-19287';
14865 				 RAISE FND_API.G_EXC_ERROR;
14866 			      End if;
14867 			   End if;
14868 			End if;
14869 
14870 			-- Total QTY Validation and LOCATOR validation for Deliver Txn
14871 
14872 			l_progress := 'WMSINB-19295';
14873 			l_lpn_match := 'N';
14874 			validate_lpn_locator( p_lpn_id => l_lpn_rec.lpn_id,
14875 					      p_subinventory => l_lpn_rec.from_subinventory,
14876 					      p_locator_id   => l_lpn_rec.from_locator_id,
14877 					      p_organization_id  => l_lpn_rec.to_organization_id,
14878 					      x_lpn_match        => l_lpn_match,
14879 					      x_return_status    => x_return_status,
14880 					      x_msg_count        => x_msg_count,
14881 					      x_msg_data         => x_msg_data);
14882 
14883 			if x_return_status <> G_RET_STS_SUCCESS Then
14884 			   --  Review Late Set Appropiate Message
14885 			   l_progress := 'WMSINB-19308';
14886 			   RAISE FND_API.G_EXC_ERROR;
14887 			End if;
14888 
14889 			if ( (l_parent_txn_type in ('DELIVER')) or (l_lpn_match = 'N') ) then
14890 			   -- Call Total QTY VALIDATION API HERE
14891 			   validate_total_qty(p_lpn_group_id => p_lpn_group_id,
14892 					      p_from_lpn_id => l_lpn_rec.lpn_id,
14893 					      p_parent_lpn_id => l_cur_from_parent_lpn_id,
14894 					      p_transaction_type => l_lpn_rec.transaction_type,
14895 					      x_return_status    => x_return_status,
14896 					      x_msg_count        => x_msg_count,
14897 					      x_msg_data         => x_msg_data);
14898 
14899 			   l_progress := 'WMSINB-19322';
14900 
14901 			   if x_return_status <> G_RET_STS_SUCCESS Then
14902 			      --  Review Late Set Appropiate Message
14903 			      l_progress := 'WMSINB-19326';
14904 			      RAISE FND_API.G_EXC_ERROR;
14905 			   End if;
14906 			End if;
14907 		     End if;
14908 		  End if; -- End of From LPN not null
14909 
14910 	       End if; -- END OF PARENT TXN TYPE IN RECEIVE ACCEPT REJECT TRANSFER DELIVER
14911 	       --
14912 
14913 	       l_progress := 'WMSINB-19336';
14914 
14915 	       if l_parent_txn_type in ('RETURN TO VENDOR','RETURN TO RECEIVING', 'RETURN TO CUSTOMER') then
14916 
14917 		  l_progress := 'WMSINB-19340';
14918 
14919 		  if (l_lpn_rec.transfer_license_plate_number is not null) then
14920 		     if l_parent_txn_type in ('RETURN TO VENDOR', 'RETURN TO CUSTOMER') then
14921 			-- FAIL THE TXN
14922 			--  Review Late Set Appropiate Message
14923 			l_progress := 'WMSINB-19346';
14924 			RAISE FND_API.G_EXC_ERROR;
14925 		     End if;
14926 
14927 		     if l_parent_txn_type in ('RETURN TO RECEIVING') then
14928 			if l_lpn_rec.transfer_lpn_id is null then
14929 			   -- TRANSFER LPN DOES NOT EXISTS FAIL THE TXN
14930 			   --  Review Late Set Appropiate Message
14931 			   l_progress := 'WMSINB-19354';
14932 			   RAISE FND_API.G_EXC_ERROR;
14933 			 Else
14934 			   -- TRANSFER LPN EXIST
14935 			   if l_transfer_lpn_context <> G_LPN_CONTEXT_RCV then
14936 			      --  Review Late Set Appropiate Message
14937 			      l_progress := 'WMSINB-19360';
14938 			      RAISE FND_API.G_EXC_ERROR;
14939 			   End if;
14940 			   --
14941 			   if ( ( l_rs_ptid_ptid_ptid_exists <> TRUE ) or ( l_lpn_rec.transfer_lpn_id <> nvl(l_rs_ptid_ptid_ptid_lpn_id,-9999)) ) then
14942 			      --  Review Late Set Appropiate Message
14943 			      l_progress := 'WMSINB-19366';
14944 			      RAISE FND_API.G_EXC_ERROR;
14945 			   End if;
14946 			End if;
14947 		     End if; -- END OF RTR
14948 		   Else    -- TRANSFER LPN NULL
14949 		     if l_parent_txn_type in ('RETURN TO RECEIVING') then
14950 			if l_rs_ptid_ptid_ptid_lpn_id is not null then -- SUPPLY EXISTS WITH LPN SO FAIL THE TXN
14951 			   --  Review Late Set Appropiate Message
14952 			   l_progress := 'WMSINB-19375';
14953 			   RAISE FND_API.G_EXC_ERROR;
14954 			End if;
14955 		     End if;
14956 		  End if; -- END OF TRANSFER LPN NULL
14957 
14958 		  if (l_lpn_rec.lpn_id is not null or l_lpn_rec.license_plate_number is not null ) then
14959 		     if ( ( nvl(l_lpn_rec.lpn_id,0) <> nvl(l_lpn_rec.transfer_lpn_id,0) ) or
14960 			  ( nvl(l_lpn_rec.license_plate_number,'-9999') <> nvl(l_lpn_rec.transfer_license_plate_number,'-9999') )
14961 			  ) then
14962 			if l_parent_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER') then
14963 			   if l_rs_ptid_ptid_exists <> TRUE then
14964 			      if l_lpn_rec.lpn_id is not null then
14965 				 if l_lpn_context not in (G_LPN_CONTEXT_RCV , G_LPN_CONTEXT_PREGENERATED ) then
14966 				    -- FAIL the TXN
14967 				    -- Review Later
14968 				    -- Set appropiate Message
14969 				    --
14970 				    l_progress := 'WMSINB-19393';
14971 				    RAISE FND_API.G_EXC_ERROR;
14972 				 End if;
14973 				 -- Validate Locator
14974 				 -- Review Later
14975 				 l_lpn_match := 'N';
14976 				 validate_lpn_locator( p_lpn_id => l_lpn_rec.lpn_id,
14977 						       p_subinventory => l_lpn_rec.from_subinventory,
14978 						       p_locator_id   => l_lpn_rec.from_locator_id,
14979 						       p_organization_id  => l_lpn_rec.to_organization_id,
14980 						       x_lpn_match        => l_lpn_match,
14981 						       x_return_status    => x_return_status,
14982 						       x_msg_count        => x_msg_count,
14983 						       x_msg_data         => x_msg_data);
14984 
14985 				 if x_return_status <> G_RET_STS_SUCCESS Then
14986 				    --  Review Late Set Appropiate Message
14987 				    l_progress := 'WMSINB-19410';
14988 				    RAISE FND_API.G_EXC_ERROR;
14989 				 End if;
14990 
14991 				 if l_lpn_match = 'N' then
14992 				    l_progress := 'WMSINB-19415';
14993 				    RAISE FND_API.G_EXC_ERROR;
14994 				 End if;
14995 			       Else -- LPN ID NULL CASE
14996 				 -- Create LPN Here
14997 				 create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.license_plate_number,
14998 						       p_lpn_group_id => p_lpn_group_id,
14999 						       p_organization_id => l_lpn_rec.to_organization_id,
15000 						       p_lpn_context => G_LPN_CONTEXT_RCV ,
15001 						       x_lpn_id => l_lpn_rec.lpn_id,
15002 						       x_return_status => x_return_status,
15003 						       x_msg_count => l_msg_count,
15004 						       x_msg_data => l_msg_data);
15005 				 -- Check the error status from the above call
15006 				 if x_return_status <> G_RET_STS_SUCCESS Then
15007 				    --  Review Late Set Appropiate Message
15008 				    l_progress := 'WMSINB-19431';
15009 				    RAISE FND_API.G_EXC_ERROR;
15010 				 End if;
15011 			      End if;
15012 			    Else -- RS.PTID.PTID EXISTS
15013 			      if (nvl(l_rs_ptid_ptid_lpn_id, -9999) <> l_lpn_rec.lpn_id ) then
15014 				 --  Review Late Set Appropiate Message
15015 				 l_progress := 'WMSINB-19438';
15016 				 RAISE FND_API.G_EXC_ERROR;
15017 			      End if;
15018 			   End if;
15019 			End if; -- END OF PTID.PTID.TXNTYPE IN RECEIVE/ACCEPT/REJECT/TRANSFER
15020 
15021 			if l_parent_parent_txn_type in ('DELIVER') then
15022 			   if l_lpn_rec.lpn_id is not null then
15023 			      if l_lpn_context not in (G_LPN_CONTEXT_INV , G_LPN_CONTEXT_PREGENERATED) then
15024 				 -- FAIL the TXN
15025 				 -- Review Later
15026 				 -- Set appropiate Message
15027 				 --
15028 				 l_progress := 'WMSINB-19451';
15029 				 RAISE FND_API.G_EXC_ERROR;
15030 			      End if;
15031 			      -- Validate Locator
15032 			      -- Review Later
15033 			      l_lpn_match := 'N';
15034 			      validate_lpn_locator( p_lpn_id => l_lpn_rec.lpn_id,
15035 						    p_subinventory => l_lpn_rec.from_subinventory,
15036 						    p_locator_id   => l_lpn_rec.from_locator_id,
15037 						    p_organization_id  => l_lpn_rec.to_organization_id,
15038 						    x_lpn_match        => l_lpn_match,
15039 						    x_return_status    => x_return_status,
15040 						    x_msg_count        => x_msg_count,
15041 						    x_msg_data         => x_msg_data);
15042 
15043 			      l_progress := 'WMSINB-19466';
15044 			      if x_return_status <> G_RET_STS_SUCCESS Then
15045 				 --  Review Late Set Appropiate Message
15046 				 l_progress := 'WMSINB-19469';
15047 				 RAISE FND_API.G_EXC_ERROR;
15048 			      End if;
15049 
15050 			      if l_lpn_match = 'N' then
15051 				 l_progress := 'WMSINB-19474';
15052 				 RAISE FND_API.G_EXC_ERROR;
15053 			      End if;
15054 			    Else -- LPN ID NULL CASE
15055 			      -- Create LPN Here
15056 			      l_progress := 'WMSINB-19479';
15057 			      create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.license_plate_number,
15058 						    p_lpn_group_id => p_lpn_group_id,
15059 						    p_organization_id => l_lpn_rec.to_organization_id,
15060 						    p_lpn_context => G_LPN_CONTEXT_INV,
15061 						    x_lpn_id => l_lpn_rec.lpn_id,
15062 						    x_return_status => x_return_status,
15063 						    x_msg_count => l_msg_count,
15064 						    x_msg_data => l_msg_data);
15065 			      -- Check the error status from the above call
15066 			      if x_return_status <> G_RET_STS_SUCCESS Then
15067 				 --  Review Late Set Appropiate Message
15068 				 l_progress := 'WMSINB-19491';
15069 				 RAISE FND_API.G_EXC_ERROR;
15070 			      End if;
15071 			   End if; -- END OF LPN ID NOT NULL CASE
15072 			End if; --END OF PTID.TXNTYPE DELIVER
15073 		      Elsif (l_lpn_rec.lpn_id = l_lpn_rec.transfer_lpn_id) then
15074                      --Bug 5550783 start
15075                      IF (l_debug = 1) THEN
15076                         print_debug('expess_transaction check: ' || l_lpn_rec.express_transaction, 1);
15077                      END If;
15078                      --Bug 5550783 end
15079                      --Do not do the validate_total_qty if it is express transaction and also if it is a Mobil Deliver/Transfer
15080                      if ((l_lpn_rec.express_transaction = 'Y') OR (l_lpn_rec.transaction_type in ('DELIVER','TRANSFER') AND l_lpn_rec.mobile_txn = 'Y')) then--Bug 555078
15081                          IF (l_debug = 1) THEN
15082                             print_debug('l_lpn_rec.express_transaction', 1);
15083                             print_debug('VALIDATE_LPN_INFO - Not doing validate_total_qty ...', 1);
15084                          END If;
15085 
15086                      Else
15087                      print_debug('l_lpn_rec.express_transaction-1', 1);
15088                         -- Call Total QTY VALIDATION API HERE
15089 			l_progress := 'WMSINB-19498';
15090 			validate_total_qty(p_lpn_group_id => p_lpn_group_id,
15091 					   p_from_lpn_id => l_lpn_rec.lpn_id,
15092 					   p_parent_lpn_id => l_cur_from_parent_lpn_id,
15093 					   p_transaction_type => l_lpn_rec.transaction_type,
15094 					   x_return_status    => x_return_status,
15095 					   x_msg_count        => x_msg_count,
15096 					   x_msg_data         => x_msg_data);
15097 
15098 			if x_return_status <> G_RET_STS_SUCCESS Then
15099 			   --  Review Late Set Appropiate Message
15100 			   l_progress := 'WMSINB-19509';
15101 			   RAISE FND_API.G_EXC_ERROR;
15102 			End if;
15103                        End if;--Bug 5550783
15104 		     End if; -- END OF TLPN and FLPN DIFFERENT
15105 		   Else -- FROM LPN NULL
15106 		     l_progress := 'WMSINB-19514';
15107 		     if l_parent_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER') then
15108 			if ( l_rs_ptid_ptid_exists = TRUE and l_rs_ptid_ptid_lpn_id is not null) then
15109 			   --  Review Late Set Appropiate Message
15110 			   l_progress := 'WMSINB-19518';
15111 			   RAISE FND_API.G_EXC_ERROR;
15112 			End if;
15113 		     End if;
15114 		  End if; -- END OF FROM LPN NOT NULL CASE
15115 	       End if; --END OF RTR RTV RTC
15116 
15117 	       -- ******************************************************
15118 	       -- END OF NEGATIVE CORRECTION
15119 	       --************************************************************
15120 
15121 	       -- START OF POSITIVE CORRECTION
15122 
15123 	     Elsif ( ( l_lpn_rec.transaction_type = 'CORRECT' and l_lpn_rec.quantity > 0 )
15124 		     or (l_lpn_rec.transaction_type in ('RETURN TO VENDOR','RETURN TO RECEIVING', 'RETURN TO CUSTOMER')) ) then
15125 
15126 	       l_progress := 'WMSINB-19534';
15127 
15128 	       if l_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER','DELIVER') then
15129 		  l_progress := 'WMSINB-19537';
15130 
15131 		  if ( l_lpn_rec.lpn_id is not null or l_lpn_rec.license_plate_number is not null ) then
15132 		     if (l_parent_txn_type = 'RECEIVE' and l_lpn_rec.transaction_type = 'CORRECT') then
15133 			--  Review Late Set Appropiate Message
15134 			l_progress := 'WMSINB-19542';
15135 			RAISE FND_API.G_EXC_ERROR;
15136 		     End if;
15137 
15138 		     if l_lpn_rec.lpn_id is null then
15139 			--  Review Late Set Appropiate Message
15140 			l_progress := 'WMSINB-19548';
15141 			RAISE FND_API.G_EXC_ERROR;
15142 		      Else -- FLPN Exists
15143 			if l_lpn_rec.transaction_type = 'CORRECT' then
15144 			   if l_lpn_context not in (G_LPN_CONTEXT_RCV ) then
15145 			      --  Review Late Set Appropiate Message
15146 			      l_progress := 'WMSINB-19554';
15147 			      RAISE FND_API.G_EXC_ERROR;
15148 			   End if;
15149 
15150 			   -- Case WHERE FROM LPN and SUPPLY LPN mismatch fail the TXN
15151 			   if (l_lpn_rec.lpn_id <> nvl(l_rs_ptid_ptid_lpn_id,-9999)) then
15152 			      --  Review Late Set Appropiate Message
15153 			      l_progress := 'WMSINB-19561';
15154 			      RAISE FND_API.G_EXC_ERROR;
15155 			   End if;
15156 			 Else -- case for RTV/RTR/RTC
15157 			   if l_parent_txn_type in ('DELIVER') then
15158 			      if l_lpn_context not in (G_LPN_CONTEXT_INV) then
15159 				 --  Review Late Set Appropiate Message
15160 				 l_progress := 'WMSINB-19568';
15161 				 RAISE FND_API.G_EXC_ERROR;
15162 			      End if;
15163 			    Else
15164 			      if l_lpn_context not in (G_LPN_CONTEXT_RCV) then
15165 				 --  Review Late Set Appropiate Message
15166 				 l_progress := 'WMSINB-19574';
15167 				 RAISE FND_API.G_EXC_ERROR;
15168 			      End if;
15169 			      if ( ( l_rs_ptid_exists <> TRUE ) or (l_lpn_rec.lpn_id <> nvl(l_rs_ptid_lpn_id, -9999)) ) then
15170 				 --  Review Late Set Appropiate Message
15171 				 l_progress := 'WMSINB-19579';
15172 				 RAISE FND_API.G_EXC_ERROR;
15173 			      End if;
15174 			   End if; -- END OF parent_txn_type as DELIVER
15175 			End if; -- END OF TXNTYPE CORRECT
15176 		     End if; -- WLPN.FLPN exists CASE
15177 		   Else -- CASE WHERE FLPN IS NULL
15178 		     if l_lpn_rec.transaction_type in ('CORRECT') then
15179 			if (l_rs_ptid_ptid_exists = TRUE) then
15180 			   if (l_rs_ptid_ptid_lpn_id is not null) then
15181 			      --  Review Late Set Appropiate Message
15182 			      l_progress := 'WMSINB-19590';
15183 			      RAISE FND_API.G_EXC_ERROR;
15184 			   End if;
15185 			End if;
15186 		      Else  -- Transaction for RTV/RTR/RTC
15187 			if (l_rs_ptid_exists = TRUE ) then
15188 			   if (l_rs_ptid_ptid_lpn_id is not null ) then
15189 			      --  Review Late Set Appropiate Message
15190 			      l_progress := 'WMSINB-19598';
15191 			      RAISE FND_API.G_EXC_ERROR;
15192 			   End if;
15193 			End if;
15194 		     End if; -- END OF transaction_type CORRECT
15195 		  End if; -- END OF FLPN NOT NULL CASE
15196 
15197 		  if (l_lpn_rec.transfer_lpn_id is not null or l_lpn_rec.transfer_license_plate_number is not null ) then
15198 		     if ( ( nvl(l_lpn_rec.lpn_id,0) <> nvl(l_lpn_rec.transfer_lpn_id,0) ) or
15199 			  ( nvl(l_lpn_rec.license_plate_number,'-9999') <> nvl(l_lpn_rec.transfer_license_plate_number,'-9999') )
15200 			  ) then
15201 			l_progress := 'WMSINB-19609';
15202 			if l_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER') then
15203 			   if l_lpn_rec.transaction_type in ('CORRECT') then
15204 			      if (l_rs_ptid_ptid_exists <> TRUE) then
15205 				 if l_lpn_rec.transfer_lpn_id is not null then
15206 				    if l_transfer_lpn_context not in (G_LPN_CONTEXT_RCV ,G_LPN_CONTEXT_PREGENERATED ) then
15207 				       --  Review Late Set Appropiate Message
15208 				       l_progress := 'WMSINB-19616';
15209 				       RAISE FND_API.G_EXC_ERROR;
15210 				    End if;
15211 
15212 				    -- Validate Locator
15213 				    -- Review Later
15214 				    l_lpn_match := 'N';
15215 				    validate_lpn_locator( p_lpn_id => l_lpn_rec.transfer_lpn_id,
15216 							  p_subinventory => l_lpn_rec.subinventory,
15217 							  p_locator_id   => l_lpn_rec.locator_id,
15218 							  p_organization_id  => l_lpn_rec.to_organization_id,
15219 							  x_lpn_match        => l_lpn_match,
15220 							  x_return_status    => x_return_status,
15221 							  x_msg_count        => x_msg_count,
15222 							  x_msg_data         => x_msg_data);
15223 
15224 				    l_progress := 'WMSINB-19632';
15225 
15226 				    if x_return_status <> G_RET_STS_SUCCESS Then
15227 				       --  Review Late Set Appropiate Message
15228 				       l_progress := 'WMSINB-19636';
15229 				       RAISE FND_API.G_EXC_ERROR;
15230 				    End if;
15231 
15232 				    if l_lpn_match = 'N' then
15233 				       l_progress := 'WMSINB-19641';
15234 				       RAISE FND_API.G_EXC_ERROR;
15235 				    End if;
15236 				  Else
15237 				    -- Create LPN Here
15238 				    l_progress := 'WMSINB-19646';
15239 				    create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.transfer_license_plate_number,
15240 							  p_lpn_group_id => p_lpn_group_id,
15241 							  p_organization_id => l_lpn_rec.to_organization_id,
15242 							  p_lpn_context => G_LPN_CONTEXT_RCV,
15243 							  x_lpn_id => l_lpn_rec.transfer_lpn_id,
15244 							  x_return_status => x_return_status,
15245 							  x_msg_count => l_msg_count,
15246 							  x_msg_data => l_msg_data);
15247 				    -- Check the error status from the above call
15248 				    if x_return_status <> G_RET_STS_SUCCESS Then
15249 				       --  Review Late Set Appropiate Message
15250 				       l_progress := 'WMSINB-19658';
15251 				       RAISE FND_API.G_EXC_ERROR;
15252 				    End if;
15253 				 End if;
15254 			       Else
15255 				 -- CHECK THE LPN IN SUPPLY
15256 				 --BUG 4502518 Issue 34: Positive Correction of Transfer
15257 				 --User can't change LPN if RS exists for the
15258 				 --Transfer txn.  In this case, make sure that
15259 				 --the transfer_lpn_id is tied to that RS.
15260 				 IF (l_rs_ptid_exists = TRUE) THEN
15261 				     if (l_lpn_rec.transfer_lpn_id <> nvl(l_rs_ptid_lpn_id,-9999) ) then
15262 					--  Review Late Set Appropiate Message
15263 					l_progress := 'WMSINB-19666';
15264 					RAISE FND_API.G_EXC_ERROR;
15265 				     END IF;
15266 				 END IF;
15267 			      End if;-- END OF RS EXISTS
15268 			    Else -- THIS PART FOR RTV/RTR/RTC . THIS LPN WILL BE FINALLY ISSUED OUT
15269 			      if l_lpn_rec.transfer_lpn_id is not null then
15270 				 if l_transfer_lpn_context not in (G_LPN_CONTEXT_PREGENERATED) then
15271 				    --  Review Late Set Appropiate Message
15272 				    l_progress := 'WMSINB-19674';
15273 				    RAISE FND_API.G_EXC_ERROR;
15274 				 End if;
15275 			       Else -- TRANSFER LPN DOES NOT EXIST IN THE SYETEM
15276 				 -- Create LPN Here
15277 				 l_progress := 'WMSINB-19679';
15278 				 create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.transfer_license_plate_number,
15279 						       p_lpn_group_id => p_lpn_group_id,
15280 						       p_organization_id => l_lpn_rec.to_organization_id,
15281 						       p_lpn_context => G_LPN_CONTEXT_STORES,
15282 						       x_lpn_id => l_lpn_rec.transfer_lpn_id,
15283 						       x_return_status => x_return_status,
15284 						       x_msg_count => l_msg_count,
15285 						       x_msg_data => l_msg_data);
15286 				 -- Check the error status from the above call
15287 				 if x_return_status <> G_RET_STS_SUCCESS Then
15288 				    --  Review Late Set Appropiate Message
15289 				    l_progress := 'WMSINB-19691';
15290 				    RAISE FND_API.G_EXC_ERROR;
15291 				 End if;
15292 			      End if;
15293 			   End if; -- END OF parent_txn_type CORRECT
15294 			End if; -- END OF 'RECEIVE','ACCEPT','REJECT','TRANSFER'
15295 
15296 			if l_parent_txn_type in ('DELIVER') then
15297 			   if l_lpn_rec.transfer_lpn_id is not null then
15298 			      if l_lpn_rec.transaction_type = 'CORRECT' then
15299 				 if l_transfer_lpn_context not in (G_LPN_CONTEXT_INV ,G_LPN_CONTEXT_PREGENERATED ) then
15300 				    --  Review Late Set Appropiate Message
15301 				    l_progress := 'WMSINB-19703';
15302 				    RAISE FND_API.G_EXC_ERROR;
15303 				 End if;
15304 				 -- Validate Locator
15305 				 -- Review Later
15306 				 l_lpn_match := 'N';
15307 				 validate_lpn_locator( p_lpn_id => l_lpn_rec.transfer_lpn_id,
15308 						       p_subinventory => l_lpn_rec.subinventory,
15309 						       p_locator_id   => l_lpn_rec.locator_id,
15310 						       p_organization_id  => l_lpn_rec.to_organization_id,
15311 						       x_lpn_match        => l_lpn_match,
15312 						       x_return_status    => x_return_status,
15313 						       x_msg_count        => x_msg_count,
15314 						       x_msg_data         => x_msg_data);
15315 
15316 				 l_progress := 'WMSINB-19718';
15317 
15318 				 if x_return_status <> G_RET_STS_SUCCESS Then
15319 				    --  Review Late Set Appropiate Message
15320 				    l_progress := 'WMSINB-19722';
15321 				    RAISE FND_API.G_EXC_ERROR;
15322 				 End if;
15323 
15324 				 if l_lpn_match = 'N' then
15325 				    l_progress := 'WMSINB-19727';
15326 				    RAISE FND_API.G_EXC_ERROR;
15327 				 End if;
15328 			       Elsif l_lpn_rec.transaction_type in ('RETURN TO VENDOR', 'RETURN TO CUSTOMER' ) then
15329 				 if l_transfer_lpn_context not in (G_LPN_CONTEXT_PREGENERATED) then
15330 				    --  Review Late Set Appropiate Message
15331 				    l_progress := 'WMSINB-19733';
15332 				    RAISE FND_API.G_EXC_ERROR;
15333 				 End if;
15334 			       Elsif  l_lpn_rec.transaction_type in ('RETURN TO RECEIVING' ) then
15335 				 if l_rs_ptid_ptid_exists <> TRUE then
15336 				    if l_transfer_lpn_context not in (G_LPN_CONTEXT_PREGENERATED ,G_LPN_CONTEXT_RCV ) then
15337 				       --  Review Late Set Appropiate Message
15338 				       l_progress := 'WMSINB-19740';
15339 				       RAISE FND_API.G_EXC_ERROR;
15340 				    End if;
15341 				    -- Validate Locator
15342 				    -- Review Later
15343 				    l_lpn_match := 'N';
15344 				    l_progress := 'WMSINB-19746';
15345 				    validate_lpn_locator( p_lpn_id => l_lpn_rec.transfer_lpn_id,
15346 							  p_subinventory => l_lpn_rec.subinventory,
15347 							  p_locator_id   => l_lpn_rec.locator_id,
15348 							  p_organization_id  => l_lpn_rec.to_organization_id,
15349 							  x_lpn_match        => l_lpn_match,
15350 							  x_return_status    => x_return_status,
15351 							  x_msg_count        => x_msg_count,
15352 							  x_msg_data         => x_msg_data);
15353 
15354 				    if x_return_status <> G_RET_STS_SUCCESS Then
15355 				       --  Review Late Set Appropiate Message
15356 				       l_progress := 'WMSINB-19758';
15357 				       RAISE FND_API.G_EXC_ERROR;
15358 				    End if;
15359 
15360 				    if l_lpn_match = 'N' then
15361 				       l_progress := 'WMSINB-19763';
15362 				       RAISE FND_API.G_EXC_ERROR;
15363 				    End if;
15364 				  Else
15365 				    if (l_lpn_rec.transfer_lpn_id <> nvl(l_rs_ptid_ptid_lpn_id,-9999) ) then
15366 				       --  Review Late Set Appropiate Message
15367 				       l_progress := 'WMSINB-19769';
15368 				       RAISE FND_API.G_EXC_ERROR;
15369 				    End if;
15370 				 End if;
15371 			      End if; -- END OF RTR
15372 
15373 			    Else -- TRANSFER LPN DOES NOT EXIST IN THE SYSTEM
15374 			      if l_lpn_rec.transaction_type = 'RETURN TO RECEIVING' then
15375 				 if (l_rs_ptid_ptid_exists = TRUE ) then
15376 				    --  Review Late Set Appropiate Message
15377 				    l_progress := 'WMSINB-19779';
15378 				    RAISE FND_API.G_EXC_ERROR;
15379 				 End if;
15380 				 --
15381 				 -- Create NEW LPN For TLPN
15382 				 create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.transfer_license_plate_number,
15383 						       p_lpn_group_id => p_lpn_group_id,
15384 						       p_organization_id => l_lpn_rec.to_organization_id,
15385 						       p_lpn_context => G_LPN_CONTEXT_RCV,
15386 						       x_lpn_id => l_lpn_rec.transfer_lpn_id,
15387 						       x_return_status => x_return_status,
15388 						       x_msg_count => l_msg_count,
15389 						       x_msg_data => l_msg_data);
15390 				 -- Check the error status from the above call
15391 				 if x_return_status <> G_RET_STS_SUCCESS Then
15392 				    --  Review Late Set Appropiate Message
15393 				    l_progress := 'WMSINB-19795';
15394 				    RAISE FND_API.G_EXC_ERROR;
15395 				 End if;
15396 			      End if;
15397 			   End if; -- TRANSFER LPN ID NOT NULL
15398 
15399 			End if; -- END OF DELIVER
15400 
15401 		      Else -- FLPN and TLPN Same
15402 			if l_lpn_rec.transaction_type = 'RETURN TO RECEIVING' then
15403 			   if (l_rs_ptid_ptid_exists = TRUE and l_lpn_rec.transfer_lpn_id <> nvl(l_rs_ptid_ptid_lpn_id,-9999)) then
15404 			      --  Review Late Set Appropiate Message
15405 			      l_progress := 'WMSINB-19807';
15406 			      RAISE FND_API.G_EXC_ERROR;
15407 			   End if;
15408 			 Elsif (l_lpn_rec.transaction_type  = 'CORRECT' and l_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER')) then
15409 			   if l_rs_ptid_exists = TRUE then
15410 			      l_progress := 'WMSINB-19812';
15411 			      if (l_lpn_rec.transfer_lpn_id <> nvl(l_rs_ptid_lpn_id,-9999)) then
15412 				 --  Review Late Set Appropiate Message
15413 				 RAISE FND_API.G_EXC_ERROR;
15414 			      End if;
15415 			   End if;
15416 			End if;
15417 
15418 			-- Total QTY Validation and LOCATOR validation for Deliver Txn
15419 
15420 			l_lpn_match := 'N';
15421 			validate_lpn_locator( p_lpn_id => l_lpn_rec.lpn_id,
15422 					      p_subinventory => l_lpn_rec.from_subinventory,
15423 					      p_locator_id   => l_lpn_rec.from_locator_id,
15424 					      p_organization_id  => l_lpn_rec.to_organization_id,
15425 					      x_lpn_match        => l_lpn_match,
15426 					      x_return_status    => x_return_status,
15427 					      x_msg_count        => x_msg_count,
15428 					      x_msg_data         => x_msg_data);
15429 
15430 			if x_return_status <> G_RET_STS_SUCCESS Then
15431 			   --  Review Late Set Appropiate Message
15432 			   l_progress := 'WMSINB-19834';
15433 			   RAISE FND_API.G_EXC_ERROR;
15434 			End if;
15435 
15436 			if ( (l_parent_txn_type in ('DELIVER')) or (l_lpn_match = 'N') ) then
15437 			   -- Call Total QTY VALIDATION API HERE
15438 			   l_progress := 'WMSINB-19840';
15439 			   validate_total_qty(p_lpn_group_id => p_lpn_group_id,
15440 					      p_from_lpn_id => l_lpn_rec.lpn_id,
15441 					      p_parent_lpn_id => l_cur_from_parent_lpn_id,
15442 					      p_transaction_type => l_lpn_rec.transaction_type,
15443 					      x_return_status    => x_return_status,
15444 					      x_msg_count        => x_msg_count,
15445 					      x_msg_data         => x_msg_data);
15446 
15447 			   if x_return_status <> G_RET_STS_SUCCESS Then
15448 			      --  Review Late Set Appropiate Message
15449 			      l_progress := 'WMSINB-19851';
15450 			      RAISE FND_API.G_EXC_ERROR;
15451 			   End if;
15452 			End if;
15453 
15454 		     End if; --END OF FLPN AND TLPN DIFFERENT
15455 
15456 		   Else --   TLPN NULL CASE
15457 		     if l_lpn_rec.transaction_type = 'RETURN TO RECEIVING' then
15458 			if (l_rs_ptid_ptid_lpn_id is not null) then
15459 			   --  Review Late Set Appropiate Message
15460 			   l_progress := 'WMSINB-19862';
15461 			   RAISE FND_API.G_EXC_ERROR;
15462 			End if;
15463 		      Elsif (l_lpn_rec.transaction_type  = 'CORRECT' and l_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER')) then
15464 			if (l_rs_ptid_lpn_id is not null ) then
15465 			   --  Review Late Set Appropiate Message
15466 			   l_progress := 'WMSINB-19868';
15467 			   RAISE FND_API.G_EXC_ERROR;
15468 			End if;
15469 		     End if;
15470 
15471 		  End if; --END OF TRANSFER LPN NOT NULL CASE
15472 
15473 	       End if; -- END OF parent_txn_type as RECEIVE ACCEPT REJECT TRANSFER DELIVER
15474 
15475 	       if l_parent_txn_type in ('RETURN TO VENDOR','RETURN TO RECEIVING', 'RETURN TO CUSTOMER') then -- ONLY FOR TXNTYPE AS CORRECT THIS WILL HAPPEN
15476 
15477 		  l_progress := 'WMSINB-19879';
15478 
15479 		  if ( l_lpn_rec.lpn_id is not null or l_lpn_rec.license_plate_number is not null ) then
15480 
15481 		     if l_parent_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER') then
15482 			if l_lpn_rec.lpn_id is null then
15483 			   --  Review Late Set Appropiate Message
15484 			   l_progress := 'WMSINB-19886';
15485 			   RAISE FND_API.G_EXC_ERROR;
15486 			 Else
15487 			   if l_lpn_context not in (G_LPN_CONTEXT_RCV) then
15488 			      --  Review Late Set Appropiate Message
15489 			      l_progress := 'WMSINB-19891';
15490 			      RAISE FND_API.G_EXC_ERROR;
15491 			   End if;
15492 			   --
15493 			   if ( l_lpn_rec.lpn_id <> nvl(l_rs_ptid_ptid_lpn_id,-9999)) then
15494 			      --  Review Late Set Appropiate Message
15495 			      l_progress := 'WMSINB-19897';
15496 			      RAISE FND_API.G_EXC_ERROR;
15497 			   End if;
15498 			End if;
15499 		     End if; -- END OF PTID.PTID txntype as RECEIVE ACCEPT REJECT TRANSFER
15500 
15501 		     if l_parent_parent_txn_type in ('DELIVER') then
15502 			if l_lpn_rec.lpn_id is null then
15503 			   --  Review Late Set Appropiate Message
15504 			   l_progress := 'WMSINB-19906';
15505 			   RAISE FND_API.G_EXC_ERROR;
15506 			 Else
15507 			   if l_lpn_context <> G_LPN_CONTEXT_INV then
15508 			      --  Review Late Set Appropiate Message
15509 			      l_progress := 'WMSINB-19911';
15510 			      RAISE FND_API.G_EXC_ERROR;
15511 			   End if;
15512 			End if;
15513 		     End if; --END OF PTID.PTID txntype as DELIVER
15514 		   Else -- FROM LPN NULL
15515 		     if l_parent_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER') then
15516 			if l_rs_ptid_ptid_lpn_id is not null then
15517 			   --  Review Late Set Appropiate Message
15518 			   l_progress := 'WMSINB-19920';
15519 			   RAISE FND_API.G_EXC_ERROR;
15520 			End if;
15521 		     End if;
15522 		  End if; -- END OF FROM LPN NOT NULL
15523 
15524 		  if ( l_lpn_rec.transfer_lpn_id is not null or l_lpn_rec.transfer_license_plate_number is not null ) then
15525 		     if l_parent_txn_type in ('RETURN TO VENDOR','RETURN TO CUSTOMER') then
15526 			--  Review Late Set Appropiate Message
15527 			l_progress := 'WMSINB-19929';
15528 			RAISE FND_API.G_EXC_ERROR;
15529 		     End if;
15530 
15531 		     if ( ( nvl(l_lpn_rec.lpn_id,0) <> nvl(l_lpn_rec.transfer_lpn_id,0) ) or
15532 			  ( nvl(l_lpn_rec.license_plate_number,'-9999') <> nvl(l_lpn_rec.transfer_license_plate_number,'-9999') )
15533 			  ) then
15534 			if l_parent_txn_type in ('RETURN TO RECEIVING') then
15535 			   if (l_rs_ptid_ptid_exists <> TRUE) then
15536 			      if l_lpn_rec.transfer_lpn_id is not null then
15537 
15538 				 if l_transfer_lpn_context not in (G_LPN_CONTEXT_PREGENERATED ,G_LPN_CONTEXT_INV ) then
15539 				    --  Review Late Set Appropiate Message
15540 				    l_progress := 'WMSINB-19942';
15541 				    RAISE FND_API.G_EXC_ERROR;
15542 				 End if;
15543 
15544 				 l_progress := 'WMSINB-19946';
15545 				 -- Validate Locator
15546 				 -- Review Later
15547 				 l_lpn_match := 'N';
15548 				 validate_lpn_locator( p_lpn_id => l_lpn_rec.transfer_lpn_id,
15549 						       p_subinventory => l_lpn_rec.subinventory,
15550 						       p_locator_id   => l_lpn_rec.locator_id,
15551 						       p_organization_id  => l_lpn_rec.to_organization_id,
15552 						       x_lpn_match        => l_lpn_match,
15553 						       x_return_status    => x_return_status,
15554 						       x_msg_count        => x_msg_count,
15555 						       x_msg_data         => x_msg_data);
15556 
15557 				 if x_return_status <> G_RET_STS_SUCCESS Then
15558 				    --  Review Late Set Appropiate Message
15559 				    l_progress := 'WMSINB-19961';
15560 				    RAISE FND_API.G_EXC_ERROR;
15561 				 End if;
15562 
15563 				 if l_lpn_match = 'N' then
15564 				    l_progress := 'WMSINB-19966';
15565 				    RAISE FND_API.G_EXC_ERROR;
15566 				 End if;
15567 
15568 			       Else -- TRANSFER LPN DOES NOT EXIST IN THE SYSTEM
15569 				 -- Create NEW LPN For TLPN
15570 				 l_progress := 'WMSINB-19972';
15571 				 create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.transfer_license_plate_number,
15572 						       p_lpn_group_id => p_lpn_group_id,
15573 						       p_organization_id => l_lpn_rec.to_organization_id,
15574 						       p_lpn_context => G_LPN_CONTEXT_RCV,
15575 						       x_lpn_id => l_lpn_rec.transfer_lpn_id,
15576 						       x_return_status => x_return_status,
15577 						       x_msg_count => l_msg_count,
15578 						       x_msg_data => l_msg_data);
15579 				 -- Check the error status from the above call
15580 				 if x_return_status <> G_RET_STS_SUCCESS Then
15581 				    --  Review Late Set Appropiate Message
15582 				    l_progress := 'WMSINB-19984';
15583 				    RAISE FND_API.G_EXC_ERROR;
15584 				 End if;
15585 
15586 			      End if;
15587 			    Else -- RS.PTID.PTID Exists
15588 			      l_progress := 'WMSINB-19990';
15589 			      if ( ( l_rs_ptid_ptid_ptid_exists <> TRUE ) or (nvl(l_lpn_rec.transfer_lpn_id,0) <> nvl(l_rs_ptid_ptid_ptid_lpn_id,-9999)) ) then
15590 				 --  Review Late Set Appropiate Message
15591 				 l_progress := 'WMSINB-19993';
15592 				 RAISE FND_API.G_EXC_ERROR;
15593 			      End if;
15594 			   End if;
15595 			End if; -- END OF RTR
15596 		      Else -- TLPN and FLPN same
15597 			if l_rs_ptid_ptid_ptid_exists = TRUE then
15598 			   if nvl(l_lpn_rec.lpn_id,0) <> nvl(l_rs_ptid_ptid_ptid_lpn_id,-9999) then
15599 			      --  Review Late Set Appropiate Message
15600 			      l_progress := 'WMSINB-20002';
15601 			      RAISE FND_API.G_EXC_ERROR;
15602 			   End if;
15603 			End if;
15604 		     End if; -- END OF TLPN and FLPN Different
15605 
15606 		   Else -- TLPN null CASE
15607 		     l_progress := 'WMSINB-20009';
15608 		     if l_parent_txn_type in ('RETURN TO RECEIVING') then
15609 			if l_rs_ptid_ptid_ptid_exists = TRUE then
15610 			   if l_rs_ptid_ptid_ptid_lpn_id is not null then
15611 			      --  Review Late Set Appropiate Message
15612 			      l_progress := 'WMSINB-20014';
15613 			      RAISE FND_API.G_EXC_ERROR;
15614 			   End if;
15615 			End if;
15616 		     End if;
15617 		  End if; --END OF TLPN not null
15618 	       End if; --END OF RTR RTV RTC
15619 
15620 	    End if;
15621 	    -- END OF POSITIVE CORRECTION
15622 
15623 	 End if; -- END OF CORRECT','RETURN TO VENDOR' RTR and RTC  TXN
15624 	 -- **********************************************************************************************
15625 	 -- FOR item id null case . THIS IS THE CASES FOR EXPENSE ITEM WHERE THERE IS NO ITEM ID PRESENT
15626 	 -- **********************************************************************************************
15627        else
15628 		  -- Check the Quantity and if it is null the return otherwise continue with the Loop
15629 		  if nvl(l_lpn_rec.quantity,0) = 0 then
15630 		     --
15631 		     -- Return Error as qty is null
15632 		     --
15633 		     l_progress := 'WMSINB-20035';
15634 		     --x_return_status := g_ret_sts_error;
15635 		     --
15636 		     -- Review Later
15637 		     -- Set appropiate Message
15638 		     --
15639 		     -- exit;
15640                      -- Bug 3714354
15641                      -- The ABOVE CASE WMSINB-20035 Does not need to be failed here
15642                      -- Becasuse this will be checked by PO's pre-processor , and
15643                      -- for Service Items there may be cases where qty and item both null
15644                      null;
15645 		  end if;
15646 		  -- **************************************************************
15647 		  -- START OF CASES  FOR  RECEIPT  TRANSACTION
15648 		  -- **************************************************************
15649 		  IF (l_debug = 1) THEN
15650 		     print_debug('VALIDATE_LPN_INFO: Case for Expense ITEM :'|| l_lpn_rec.lpn_id , 1);
15651 		  END If;
15652 
15653       end if;
15654 
15655 
15656       IF (l_update_lpn_id = TRUE) THEN
15657 	 UPDATE rcv_transactions_interface
15658 	   SET lpn_id = l_lpn_rec.lpn_id
15659 	   , transfer_lpn_id = l_lpn_rec.transfer_lpn_id
15660 	   WHERE interface_transaction_id = l_lpn_rec.interface_transaction_id;
15661       END IF;
15662 
15663    End loop;
15664 
15665    -- Delete WLPNI rows
15666    -- This call has been moved above
15667    -- delete_wlpni(p_lpn_group_id,p_lpn_id, p_license_plate_number,x_return_status,x_msg_count,x_msg_data);
15668 
15669    close c_validate_lpn;
15670 
15671    --if direct org transfer then return from here.
15672    IF (l_intransit_type = 1) THEN
15673       RETURN;
15674    END IF;
15675 
15676    -- Query the rest of WLPNI for the same group
15677    -- And check if parent needs to be changed
15678 
15679    l_progress := 'WMSINB-20071';
15680    For c_wlpni_rec in ( select lpn_id,
15681 			license_plate_number,
15682 			parent_lpn_id,
15683 			parent_license_plate_number,
15684 			organization_id,
15685 			rowid
15686 			from wms_lpn_interface
15687 			where source_group_id = p_lpn_group_id)
15688      Loop
15689 	l_progress := 'WMSINB-20081';
15690 
15691 	IF (l_debug = 1) THEN
15692 	   print_debug('VALIDATE_LPN_INFO: Inside wlpni loop at End l_progess = '|| l_progress, 1);
15693 	END If;
15694 
15695 	l_wlpni_state := get_lpn_id(c_wlpni_rec.lpn_id,
15696 				    c_wlpni_rec.license_plate_number,l_wlpni_lpn_context,l_wlpni_cur_parent_lpn,
15697 				    l_wlpn_source_header_id);
15698 
15699 	l_wlpni_parent_state := get_lpn_id(c_wlpni_rec.parent_lpn_id,
15700 					   c_wlpni_rec.parent_license_plate_number,
15701 					   l_wlpni_parent_lpn_context,l_wlpni_cur_parent_parent_lpn,
15702 					   l_xfr_wlpn_source_header_id);
15703 
15704 	l_progress := 'WMSINB-20091';
15705 
15706 	IF (l_debug = 1) THEN
15707 	   print_debug('VALIDATE_LPN_INFO:LPN_ID:'||c_wlpni_rec.lpn_id, 1);
15708 	   print_debug('VALIDATE_LPN_INFO:PARENT_LPN_ID:'||l_wlpni_cur_parent_lpn, 1);
15709 	END IF;
15710 
15711 	if (Nvl(l_wlpni_cur_parent_lpn,-1) <>  nvl(c_wlpni_rec.parent_lpn_id,-1)) then
15712 	   -- Unpack the LPN from the current Parent and
15713 	   -- Pack according to wlpni info
15714 	   IF l_wlpni_cur_parent_lpn IS NOT NULL THEN
15715 	      wms_container_pvt.packunpack_container(
15716 						     p_api_version            => 1.0,
15717 						     p_init_msg_list          => g_false,
15718 						     p_commit                 => g_false,
15719 						     p_validation_level       => fnd_api.g_valid_level_none,
15720 						     x_return_status          => x_return_status,
15721 						     x_msg_count              => l_msg_count,
15722 						     x_msg_data               => l_msg_data,
15723 						     p_lpn_id                 => l_wlpni_cur_parent_lpn,
15724 						     p_content_lpn_id         => c_wlpni_rec.LPN_ID,
15725 						     p_organization_id        => c_wlpni_rec.organization_id,
15726 						     p_operation              => 2 --- TO UNPACK
15727 						     );
15728 
15729 	      l_progress := 'WMSINB-20116';
15730 
15731 	      IF (x_return_status <> g_ret_sts_success) THEN
15732 		 IF (l_debug = 1) THEN
15733 		    print_debug('VALIDATE_LPN_INFO: packunpack_container failed progress = ' || l_progress,1);
15734 		 END IF;
15735 		 l_progress := 'WMSINB-20122';
15736 		 RAISE fnd_api.g_exc_error;
15737 	      END IF;
15738 	   END IF; --IF l_wlpni_cur_parent_lpn IS NOT NULL THEN
15739 
15740 	   IF c_wlpni_rec.parent_lpn_id IS NOT NULL THEN
15741               -- Bug 3349931
15742               -- Get the SUB/LOC from RTI and update the LPN before packing the LPN into parent LPN
15743               -- This is needed AS the parent LPN might exist in a diff SUB/LOC than the LPN
15744               -- So the packing might FAIL.
15745               -- This needs to be done only when there is no immediate contents in LPN
15746               Begin
15747                  SELECT rti.subinventory,
15748 		   rti.locator_id,
15749 		   rti.to_organization_id,
15750 		   rti.shipment_header_id,
15751 		   rti.shipment_num,
15752 		   rti.transaction_type
15753                    INTO l_parent_sub,
15754 		   l_parent_locator_id,
15755 		   l_parent_to_organization_id,
15756 		   l_parent_source_header_id,
15757 		   l_parent_source_name,
15758 		   l_parent_txn_type
15759                    FROM rcv_transactions_interface rti
15760 		   WHERE rti.lpn_id = rti.transfer_lpn_id
15761 		   AND rti.lpn_group_id = p_lpn_group_id
15762 		   AND rti.lpn_id IN (SELECT lpn_id
15763 				      FROM wms_license_plate_numbers wlpn2
15764 				      CONNECT BY PRIOR wlpn2.lpn_id = wlpn2.parent_lpn_id
15765 				      START WITH wlpn2.lpn_id =  c_wlpni_rec.LPN_ID
15766                                       )
15767 		   AND NOT exists ( SELECT 'x' FROM wms_lpn_contents
15768 				    WHERE parent_lpn_id =  c_wlpni_rec.LPN_ID
15769 				    )
15770 		   AND ROWNUM = 1
15771                    ;
15772               Exception
15773                  When others then
15774                  -- No need to update SUB / LOC
15775 		 l_progress := 'WMSINB-20123';
15776 		 IF (l_debug = 1) THEN
15777 		    print_debug('VALIDATE_LPN_INFO: No SUB/LOC Found : progress = ' || l_progress,1);
15778 		 END IF;
15779               End;
15780 
15781 	      IF (l_parent_txn_type = 'SHIP') THEN
15782 		 l_parent_source_type_id := 1;
15783 	       ELSE
15784 		 l_parent_source_type_id := NULL;
15785 		 l_parent_source_name := NULL;
15786 		 l_parent_source_header_id := NULL;
15787 	      END IF;
15788 
15789               if (l_parent_sub is not null
15790 		  or l_parent_locator_id is not	NULL
15791 		  OR l_parent_txn_type = 'SHIP') then
15792 		 IF (l_debug = 1) THEN
15793 		    print_debug('VALIDATE_LPN_INFO: SUB/LOC Found or SHIP txn, Updating with SUB and LOC as ' || l_parent_sub || ':'|| l_parent_locator_id ,1);
15794 		 END IF;
15795                  update_lpn_location_context(p_organization_id => l_parent_to_organization_id
15796 					     ,p_sub             => l_parent_sub
15797 					     ,p_locator         => l_parent_locator_id
15798 					     ,p_lpn_context     => null
15799 					     ,p_lpn_id          => c_wlpni_rec.lpn_id
15800 					     ,p_source_name     => l_parent_source_name
15801 					     ,p_source_header_id => l_parent_source_header_id
15802 					     ,p_source_type_id => l_parent_source_type_id
15803 					     ,x_return_status   => x_return_status
15804 					     ,x_msg_count       => x_msg_count
15805 					     ,x_msg_data        => x_msg_data ) ;
15806 
15807                   l_progress := 'WMSINB-20124';
15808 
15809                   -- Check the error status from the above call
15810                   if x_return_status <> G_RET_STS_SUCCESS Then
15811                      --  Review Late Set Appropiate Message
15812                      l_progress := 'WMSINB-20125';
15813                      RAISE FND_API.G_EXC_ERROR;
15814                   End if;
15815 
15816 		  --We also need to update sub/loc/sourc_name etc for parent
15817 		  update_lpn_location_context(p_organization_id => l_parent_to_organization_id
15818 					      ,p_sub             => l_parent_sub
15819 					      ,p_locator         => l_parent_locator_id
15820 					      ,p_lpn_context     => null
15821 					      ,p_lpn_id          => c_wlpni_rec.parent_lpn_id
15822 					      ,p_source_name     => l_parent_source_name
15823 					      ,p_source_header_id => l_parent_source_header_id
15824 					      ,p_source_type_id => l_parent_source_type_id
15825 					      ,x_return_status   => x_return_status
15826 					      ,x_msg_count       => x_msg_count
15827 					      ,x_msg_data        => x_msg_data ) ;
15828 
15829                   l_progress := 'WMSINB-20126';
15830 
15831                   -- Check the error status from the above call
15832                   if x_return_status <> G_RET_STS_SUCCESS Then
15833                      --  Review Late Set Appropiate Message
15834                      l_progress := 'WMSINB-20127';
15835                      RAISE FND_API.G_EXC_ERROR;
15836                   End if;
15837               End if;
15838 
15839               l_progress := 'WMSINB-20128';
15840 
15841 	      wms_container_pvt.packunpack_container(   p_api_version            => 1.0,
15842 							p_init_msg_list          => g_false,
15843 							p_commit                 => g_false,
15844 							p_validation_level       => fnd_api.g_valid_level_none,
15845 							x_return_status          => x_return_status,
15846 							x_msg_count              => l_msg_count,
15847 							x_msg_data               => l_msg_data,
15848 							p_lpn_id                 => c_wlpni_rec.parent_lpn_id,
15849 							p_content_lpn_id         => c_wlpni_rec.LPN_ID,
15850 							p_organization_id        => c_wlpni_rec.organization_id,
15851 							p_operation              => 1 --- TO PACK
15852 							);
15853 	      IF (x_return_status <> g_ret_sts_success) THEN
15854 		 IF (l_debug = 1) THEN
15855 		    print_debug('VALIDATE_LPN_INFO: packunpack_container failed progress = ' || l_progress,1);
15856 		 END IF;
15857 		 l_progress := 'WMSINB-20144';
15858 		 RAISE fnd_api.g_exc_error;
15859 	      END IF;
15860 	   END IF; --IF c_wlpni_rec.parent_lpn_id IS NOT NULL THEN
15861 
15862 	End if;
15863      End Loop;
15864 
15865      -- Finally delete the processed rows.
15866      l_progress := 'WMSINB-20153';
15867      delete from wms_lpn_interface where source_group_id = p_lpn_group_id;
15868 
15869 
15870 EXCEPTION
15871    WHEN fnd_api.g_exc_error THEN
15872       x_return_status  := g_ret_sts_error;
15873       IF (l_debug = 1) THEN
15874          print_debug('VALIDATE_LPN_INFO - Execution Error:'|| l_progress || ':' ||sqlcode, 1);
15875 	 print_stacked_messages;
15876       END IF;
15877       x_msg_data := l_progress;
15878 
15879    WHEN OTHERS THEN
15880       x_return_status  := g_ret_sts_unexp_error;
15881       IF (l_debug = 1) THEN
15882          print_debug('VALIDATE_LPN_INFO - OTHER Exception:'|| l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
15883 	 print_stacked_messages;
15884       END IF;
15885 
15886       x_msg_data := l_progress;
15887 
15888       IF SQLCODE IS NOT NULL THEN
15889 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.VALIDATE_LPN_INFO',l_progress, SQLCODE);
15890       END IF;
15891       -- Get message count and data
15892       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => l_msg_count, p_data => l_msg_data);
15893 
15894 END VALIDATE_LPN_INFO;
15895 
15896 PROCEDURE insert_mtli_rowid (p_rowid                  IN ROWID,
15897 			     p_product_txn_id         IN NUMBER,
15898 			     p_new_serial_txn_temp_id IN NUMBER,
15899 			     p_quantity               IN NUMBER,
15900 			     p_primary_quantity       IN NUMBER,
15901 			     x_return_status          OUT NOCOPY VARCHAR2,
15902 			     x_msg_count              OUT NOCOPY NUMBER,
15903 			     x_msg_data               OUT NOCOPY VARCHAR2)
15904   IS
15905      l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
15906 BEGIN
15907 
15908    x_return_status := g_ret_sts_success;
15909 
15910    IF (l_debug = 1) THEN
15911       print_debug('insert_mtli_rowid:010: Entry Stamp :' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
15912    END If;
15913 
15914    INSERT INTO mtl_transaction_lots_interface
15915      (TRANSACTION_INTERFACE_ID,
15916       SOURCE_CODE,
15917       SOURCE_LINE_ID,
15918       LAST_UPDATE_DATE,
15919       LAST_UPDATED_BY,
15920       CREATION_DATE,
15921       CREATED_BY,
15922       LAST_UPDATE_LOGIN,
15923       REQUEST_ID,
15924       PROGRAM_APPLICATION_ID,
15925       PROGRAM_ID,
15926       PROGRAM_UPDATE_DATE,
15927       LOT_NUMBER,
15928       LOT_EXPIRATION_DATE,
15929       TRANSACTION_QUANTITY,
15930       PRIMARY_QUANTITY,
15931       SERIAL_TRANSACTION_TEMP_ID,
15932       ERROR_CODE,
15933       PROCESS_FLAG,
15934       DESCRIPTION,
15935       VENDOR_NAME,
15936       SUPPLIER_LOT_NUMBER,
15937       ORIGINATION_DATE,
15938       DATE_CODE,
15939       GRADE_CODE,
15940       CHANGE_DATE,
15941       MATURITY_DATE,
15942       STATUS_ID,
15943       RETEST_DATE,
15944       AGE,
15945       ITEM_SIZE,
15946       COLOR,
15947       VOLUME,
15948       VOLUME_UOM,
15949       PLACE_OF_ORIGIN,
15950       BEST_BY_DATE,
15951       LENGTH,
15952       LENGTH_UOM,
15953       RECYCLED_CONTENT,
15954       THICKNESS,
15955       THICKNESS_UOM,
15956       WIDTH,
15957       WIDTH_UOM,
15958       CURL_WRINKLE_FOLD,
15959       LOT_ATTRIBUTE_CATEGORY,
15960       C_ATTRIBUTE1,
15961       C_ATTRIBUTE2,
15962       C_ATTRIBUTE3,
15963      C_ATTRIBUTE4,
15964      C_ATTRIBUTE5,
15965      C_ATTRIBUTE6,
15966      C_ATTRIBUTE7,
15967      C_ATTRIBUTE8,
15968      C_ATTRIBUTE9,
15969      C_ATTRIBUTE10,
15970      C_ATTRIBUTE11,
15971      C_ATTRIBUTE12,
15972      C_ATTRIBUTE13,
15973      C_ATTRIBUTE14,
15974      C_ATTRIBUTE15,
15975      C_ATTRIBUTE16,
15976      C_ATTRIBUTE17,
15977      C_ATTRIBUTE18,
15978      C_ATTRIBUTE19,
15979      C_ATTRIBUTE20,
15980      D_ATTRIBUTE1,
15981      D_ATTRIBUTE2,
15982      D_ATTRIBUTE3,
15983      D_ATTRIBUTE4,
15984      D_ATTRIBUTE5,
15985      D_ATTRIBUTE6,
15986      D_ATTRIBUTE7,
15987      D_ATTRIBUTE8,
15988      D_ATTRIBUTE9,
15989      D_ATTRIBUTE10,
15990      N_ATTRIBUTE1,
15991      N_ATTRIBUTE2,
15992      N_ATTRIBUTE3,
15993      N_ATTRIBUTE4,
15994      N_ATTRIBUTE5,
15995      N_ATTRIBUTE6,
15996      N_ATTRIBUTE7,
15997      N_ATTRIBUTE8,
15998      N_ATTRIBUTE9,
15999      N_ATTRIBUTE10,
16000      VENDOR_ID,
16001      TERRITORY_CODE,
16002      /*INVCONV, Remove sublot_num, add other attributes. Punit Kumar */
16003      ---sublot_num,
16004      PARENT_LOT_NUMBER		   ,
16005      ORIGINATION_TYPE         ,
16006      EXPIRATION_ACTION_DATE   ,
16007      EXPIRATION_ACTION_CODE   ,
16008      HOLD_DATE                ,
16009      REASON_ID                ,
16010      /* end INVCONV */
16011 
16012      reason_code,
16013      secondary_transaction_quantity,
16014      PRODUCT_CODE,
16015      product_transaction_id)
16016      (SELECT TRANSACTION_INTERFACE_ID,
16017       SOURCE_CODE,
16018       SOURCE_LINE_ID,
16019       LAST_UPDATE_DATE,
16020       LAST_UPDATED_BY,
16021       CREATION_DATE,
16022       CREATED_BY,
16023       LAST_UPDATE_LOGIN,
16024       REQUEST_ID,
16025       PROGRAM_APPLICATION_ID,
16026       PROGRAM_ID,
16027       PROGRAM_UPDATE_DATE,
16028       Ltrim(Rtrim(lot_number)),
16029       LOT_EXPIRATION_DATE,
16030       p_quantity,
16031       p_primary_quantity, -- Calculate
16032       p_new_serial_txn_temp_id, -- New sequence
16033       ERROR_CODE,
16034       PROCESS_FLAG,
16035       DESCRIPTION,
16036       VENDOR_NAME,
16037       SUPPLIER_LOT_NUMBER,
16038       ORIGINATION_DATE,
16039       DATE_CODE,
16040       GRADE_CODE,
16041       CHANGE_DATE,
16042       MATURITY_DATE,
16043       STATUS_ID,
16044       RETEST_DATE,
16045       AGE,
16046       ITEM_SIZE,
16047       COLOR,
16048       VOLUME,
16049       VOLUME_UOM,
16050       PLACE_OF_ORIGIN,
16051       BEST_BY_DATE,
16052       LENGTH,
16053       LENGTH_UOM,
16054       RECYCLED_CONTENT,
16055       THICKNESS,
16056       THICKNESS_UOM,
16057       WIDTH,
16058       WIDTH_UOM,
16059       CURL_WRINKLE_FOLD,
16060       LOT_ATTRIBUTE_CATEGORY,
16061       C_ATTRIBUTE1,
16062      C_ATTRIBUTE2,
16063      C_ATTRIBUTE3,
16064      C_ATTRIBUTE4,
16065      C_ATTRIBUTE5,
16066      C_ATTRIBUTE6,
16067      C_ATTRIBUTE7,
16068      C_ATTRIBUTE8,
16069      C_ATTRIBUTE9,
16070      C_ATTRIBUTE10,
16071      C_ATTRIBUTE11,
16072      C_ATTRIBUTE12,
16073      C_ATTRIBUTE13,
16074      C_ATTRIBUTE14,
16075      C_ATTRIBUTE15,
16076      C_ATTRIBUTE16,
16077      C_ATTRIBUTE17,
16078      C_ATTRIBUTE18,
16079      C_ATTRIBUTE19,
16080      C_ATTRIBUTE20,
16081      D_ATTRIBUTE1,
16082      D_ATTRIBUTE2,
16083      D_ATTRIBUTE3,
16084      D_ATTRIBUTE4,
16085      D_ATTRIBUTE5,
16086      D_ATTRIBUTE6,
16087      D_ATTRIBUTE7,
16088      D_ATTRIBUTE8,
16089      D_ATTRIBUTE9,
16090      D_ATTRIBUTE10,
16091      N_ATTRIBUTE1,
16092      N_ATTRIBUTE2,
16093      N_ATTRIBUTE3,
16094      N_ATTRIBUTE4,
16095      N_ATTRIBUTE5,
16096      N_ATTRIBUTE6,
16097      N_ATTRIBUTE7,
16098      N_ATTRIBUTE8,
16099      N_ATTRIBUTE9,
16100      N_ATTRIBUTE10,
16101      VENDOR_ID,
16102      TERRITORY_CODE,
16103      /*INVCONV , remove sublot_num, add other attributes.Punit Kumar*/
16104      ----sublot_num,
16105      PARENT_LOT_NUMBER,
16106      ORIGINATION_TYPE ,
16107      EXPIRATION_ACTION_DATE ,
16108      EXPIRATION_ACTION_CODE ,
16109      HOLD_DATE  ,
16110      REASON_ID  ,
16111      /* end INVCONV */
16112      reason_code,
16113      NULL,
16114      PRODUCT_CODE,
16115      p_product_txn_id
16116      FROM mtl_transaction_lots_interface
16117      WHERE ROWID = p_rowid);
16118 
16119    IF (l_debug = 1) THEN
16120       print_debug('insert_mtli_rowid:020: Exit Stamp :' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
16121       /* INVCONV*/
16122       print_debug('INVCONV, removed sublot_num, Added some more parameters in INSERT INTO mtl_transaction_lots_interface (insert_mtli_rowid)', 1);
16123       /*end , INVCONV*/
16124 
16125    END If;
16126 EXCEPTION
16127    WHEN OTHERS THEN
16128       x_return_status  := g_ret_sts_unexp_error;
16129       IF (l_debug = 1) THEN
16130          print_debug('insert_mtli_rowid - other exception: '||
16131 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
16132       END IF;
16133       IF SQLCODE IS NOT NULL THEN
16134 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.insert_mtli_rowid',Sqlerrm,SQLCODE);
16135       END IF;
16136       --  Get message count and data
16137       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
16138 END insert_mtli_rowid;
16139 
16140 
16141 PROCEDURE insert_msni_rowid (p_rowid                  IN ROWID,
16142 			     p_product_txn_id         IN NUMBER,
16143 			     p_new_serial_txn_temp_id IN NUMBER DEFAULT NULL,
16144 			     p_new_fm_ser_num         IN VARCHAR2 DEFAULT NULL,
16145 			     p_new_to_ser_num         IN VARCHAR2 DEFAULT NULL,
16146 			     x_return_status          OUT NOCOPY VARCHAR2,
16147 			     x_msg_count              OUT NOCOPY NUMBER,
16148 			     x_msg_data               OUT NOCOPY VARCHAR2)
16149   IS
16150      l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
16151 BEGIN
16152    x_return_status := g_ret_sts_success;
16153 
16154    IF (l_debug = 1) THEN
16155       print_debug('insert_msni_rowid:010: Entry Stamp :' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
16156    END If;
16157 
16158    INSERT INTO mtl_serial_numbers_interface
16159      (TRANSACTION_INTERFACE_ID,
16160       SOURCE_CODE,
16161       SOURCE_LINE_ID,
16162       LAST_UPDATE_DATE,
16163       LAST_UPDATED_BY,
16164       CREATION_DATE,
16165       CREATED_BY,
16166       LAST_UPDATE_LOGIN,
16167       REQUEST_ID,
16168       PROGRAM_APPLICATION_ID,
16169       PROGRAM_ID,
16170       PROGRAM_UPDATE_DATE,
16171       VENDOR_SERIAL_NUMBER,
16172       VENDOR_LOT_NUMBER,
16173       FM_SERIAL_NUMBER,
16174       TO_SERIAL_NUMBER,
16175       ERROR_CODE,
16176       PROCESS_FLAG,
16177       PARENT_SERIAL_NUMBER,
16178       SERIAL_ATTRIBUTE_CATEGORY,
16179       ORIGINATION_DATE,
16180       C_ATTRIBUTE1,
16181       C_ATTRIBUTE2,
16182       C_ATTRIBUTE3,
16183       C_ATTRIBUTE4,
16184       C_ATTRIBUTE5,
16185       C_ATTRIBUTE6,
16186       C_ATTRIBUTE7,
16187       C_ATTRIBUTE8,
16188       C_ATTRIBUTE9,
16189       C_ATTRIBUTE10,
16190       C_ATTRIBUTE11,
16191       C_ATTRIBUTE12,
16192       C_ATTRIBUTE13,
16193       C_ATTRIBUTE14,
16194       C_ATTRIBUTE15,
16195       C_ATTRIBUTE16,
16196       C_ATTRIBUTE18,
16197       C_ATTRIBUTE19,
16198       C_ATTRIBUTE20,
16199       D_ATTRIBUTE1,
16200       D_ATTRIBUTE2,
16201       D_ATTRIBUTE3,
16202       D_ATTRIBUTE4,
16203       D_ATTRIBUTE5,
16204       D_ATTRIBUTE6,
16205      D_ATTRIBUTE7,
16206      D_ATTRIBUTE8,
16207      D_ATTRIBUTE9,
16208      D_ATTRIBUTE10,
16209      N_ATTRIBUTE1,
16210      N_ATTRIBUTE2,
16211      N_ATTRIBUTE3,
16212      N_ATTRIBUTE4,
16213      N_ATTRIBUTE5,
16214      N_ATTRIBUTE6,
16215      N_ATTRIBUTE7,
16216      N_ATTRIBUTE8,
16217      N_ATTRIBUTE9,
16218      N_ATTRIBUTE10,
16219      STATUS_ID,
16220      TERRITORY_CODE,
16221      TIME_SINCE_NEW,
16222      CYCLES_SINCE_NEW,
16223      TIME_SINCE_OVERHAUL,
16224      CYCLES_SINCE_OVERHAUL,
16225      TIME_SINCE_REPAIR,
16226      CYCLES_SINCE_REPAIR,
16227      TIME_SINCE_VISIT,
16228      CYCLES_SINCE_VISIT,
16229      TIME_SINCE_MARK,
16230      CYCLES_SINCE_MARK,
16231      NUMBER_OF_REPAIRS,
16232      STATUS_NAME,
16233      C_ATTRIBUTE17,
16234      ATTRIBUTE_CATEGORY,
16235      ATTRIBUTE1,
16236      ATTRIBUTE2,
16237      ATTRIBUTE3,
16238      ATTRIBUTE4,
16239      ATTRIBUTE5,
16240      ATTRIBUTE6,
16241      ATTRIBUTE7,
16242      ATTRIBUTE8,
16243      ATTRIBUTE9,
16244      ATTRIBUTE10,
16245      ATTRIBUTE11,
16246      ATTRIBUTE12,
16247      ATTRIBUTE13,
16248      ATTRIBUTE14,
16249      ATTRIBUTE15,
16250      PRODUCT_CODE,
16251      PRODUCT_TRANSACTION_ID)
16252      (SELECT Nvl(p_new_serial_txn_temp_id, transaction_interface_id),
16253       SOURCE_CODE,
16254       SOURCE_LINE_ID,
16255       LAST_UPDATE_DATE,
16256       LAST_UPDATED_BY,
16257       CREATION_DATE,
16258       CREATED_BY,
16259       LAST_UPDATE_LOGIN,
16260       REQUEST_ID,
16261       PROGRAM_APPLICATION_ID,
16262       PROGRAM_ID,
16263       PROGRAM_UPDATE_DATE,
16264       VENDOR_SERIAL_NUMBER,
16265       VENDOR_LOT_NUMBER,
16266       Nvl(p_new_fm_ser_num,fm_serial_number),
16267       Nvl(p_new_to_ser_num, to_serial_number),
16268       ERROR_CODE,
16269       PROCESS_FLAG,
16270       PARENT_SERIAL_NUMBER,
16271       SERIAL_ATTRIBUTE_CATEGORY,
16272       ORIGINATION_DATE,
16273       C_ATTRIBUTE1,
16274       C_ATTRIBUTE2,
16275       C_ATTRIBUTE3,
16276       C_ATTRIBUTE4,
16277       C_ATTRIBUTE5,
16278       C_ATTRIBUTE6,
16279       C_ATTRIBUTE7,
16280       C_ATTRIBUTE8,
16281       C_ATTRIBUTE9,
16282       C_ATTRIBUTE10,
16283       C_ATTRIBUTE11,
16284       C_ATTRIBUTE12,
16285       C_ATTRIBUTE13,
16286       C_ATTRIBUTE14,
16287       C_ATTRIBUTE15,
16288       C_ATTRIBUTE16,
16289       C_ATTRIBUTE18,
16290       C_ATTRIBUTE19,
16291       C_ATTRIBUTE20,
16292       D_ATTRIBUTE1,
16293       D_ATTRIBUTE2,
16294      D_ATTRIBUTE3,
16295      D_ATTRIBUTE4,
16296      D_ATTRIBUTE5,
16297      D_ATTRIBUTE6,
16298      D_ATTRIBUTE7,
16299      D_ATTRIBUTE8,
16300      D_ATTRIBUTE9,
16301      D_ATTRIBUTE10,
16302      N_ATTRIBUTE1,
16303      N_ATTRIBUTE2,
16304      N_ATTRIBUTE3,
16305      N_ATTRIBUTE4,
16306      N_ATTRIBUTE5,
16307      N_ATTRIBUTE6,
16308      N_ATTRIBUTE7,
16309      N_ATTRIBUTE8,
16310      N_ATTRIBUTE9,
16311      N_ATTRIBUTE10,
16312      STATUS_ID,
16313      TERRITORY_CODE,
16314      TIME_SINCE_NEW,
16315      CYCLES_SINCE_NEW,
16316      TIME_SINCE_OVERHAUL,
16317      CYCLES_SINCE_OVERHAUL,
16318      TIME_SINCE_REPAIR,
16319      CYCLES_SINCE_REPAIR,
16320      TIME_SINCE_VISIT,
16321      CYCLES_SINCE_VISIT,
16322      TIME_SINCE_MARK,
16323      CYCLES_SINCE_MARK,
16324      NUMBER_OF_REPAIRS,
16325      STATUS_NAME,
16326      C_ATTRIBUTE17,
16327      ATTRIBUTE_CATEGORY,
16328      ATTRIBUTE1,
16329      ATTRIBUTE2,
16330      ATTRIBUTE3,
16331      ATTRIBUTE4,
16332      ATTRIBUTE5,
16333      ATTRIBUTE6,
16334      ATTRIBUTE7,
16335      ATTRIBUTE8,
16336      ATTRIBUTE9,
16337      ATTRIBUTE10,
16338      ATTRIBUTE11,
16339      ATTRIBUTE12,
16340      ATTRIBUTE13,
16341      ATTRIBUTE14,
16342      ATTRIBUTE15,
16343      PRODUCT_CODE,
16344      p_product_txn_id
16345      FROM mtl_serial_numbers_interface
16346      WHERE ROWID = p_rowid);
16347 
16348    IF (l_debug = 1) THEN
16349       print_debug('insert_msni_rowid:020: Exit Stamp :' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
16350    END If;
16351 EXCEPTION
16352    WHEN OTHERS THEN
16353       x_return_status  := g_ret_sts_unexp_error;
16354       IF (l_debug = 1) THEN
16355          print_debug('insert_msni_rowid - other exception: '||
16356 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
16357       END IF;
16358       IF SQLCODE IS NOT NULL THEN
16359 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.insert_msni_rowid',Sqlerrm, SQLCODE);
16360       END IF;
16361       --  Get message count and data
16362       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
16363 
16364 END insert_msni_rowid;
16365 
16366 PROCEDURE split_lot_serial(p_rti_tb         IN  inv_rcv_integration_apis.child_rec_tb_tp,
16367 			   x_return_status  OUT NOCOPY VARCHAR2,
16368 			   x_msg_count      OUT NOCOPY NUMBER,
16369 			   x_msg_data       OUT NOCOPY VARCHAR2)
16370   IS
16371      CURSOR mtli_recs (l_old_rti_id NUMBER) IS
16372 	SELECT Ltrim(Rtrim(lot_number)) lot_number,
16373 	  transaction_quantity,
16374 	  primary_quantity,
16375 	  serial_transaction_temp_id,
16376 	  ROWID
16377 	  FROM mtl_transaction_lots_interface
16378 	  WHERE product_code = 'RCV'
16379 	  AND product_transaction_id = l_old_rti_id;
16380 
16381      l_mtli_rec mtli_recs%ROWTYPE;
16382 
16383      CURSOR msni_recs (l_old_rti_id NUMBER) IS
16384 	SELECT fm_serial_number,
16385 	  to_serial_number,
16386 	  ROWID
16387 	  FROM mtl_serial_numbers_interface
16388 	  WHERE product_code = 'RCV'
16389 	  AND product_transaction_id = l_old_rti_id;
16390 
16391      l_msni_rec msni_recs%ROWTYPE;
16392 
16393      CURSOR msni_recs_lotserial(l_serial_transaction_temp_id NUMBER) IS
16394 	SELECT fm_serial_number,
16395 	  to_serial_number,
16396 	  ROWID
16397 	  FROM mtl_serial_numbers_interface
16398 	  WHERE transaction_interface_id = l_serial_transaction_temp_id;
16399 
16400      l_remaining_quantity NUMBER;
16401      l_primary_rem_qty NUMBER;
16402      l_remaining_serial_qty NUMBER;
16403      l_ser_rem_quantity NUMBER;
16404      l_serial_transaction_temp_id NUMBER;
16405 
16406      l_orig_interface_trx_id NUMBER;
16407      l_total_split_qty NUMBER;
16408      l_total_lot_qty NUMBER;
16409      l_total_serial_qty NUMBER;
16410      l_lot_ser_qty NUMBER;
16411      l_serial_quantity NUMBER;
16412 
16413      l_serial_split_done BOOLEAN := false;
16414      l_new_serial_txn_temp_id NUMBER;
16415 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
16416      l_temp_prefix VARCHAR2(80);
16417      l_from_ser_number NUMBER;
16418 
16419      l_new_from_ser_num VARCHAR2(30);
16420      l_new_to_ser_num VARCHAR2(30);
16421 
16422      l_rti_count NUMBER;
16423 
16424      l_progress VARCHAR2(15) := '0';
16425      l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
16426 
16427      -- Bug 3395211
16428      l_to_organization_id NUMBER;
16429      l_item_id            NUMBER;
16430      l_uom_code VARCHAR2(3);
16431      l_unit_of_measure VARCHAR2(25);
16432 
16433 BEGIN
16434    x_return_status := g_ret_sts_success;
16435 
16436    IF (l_debug = 1) THEN
16437       print_debug('split_lot_serial:010: Entry Stamp :' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
16438    END If;
16439 
16440    l_serial_split_done := FALSE;
16441 
16442    -- first do the quantity check
16443    l_total_split_qty := 0;
16444    l_orig_interface_trx_id := 0;
16445    l_rti_count := p_rti_tb.COUNT;
16446 
16447    FOR newrti IN 1..l_rti_count LOOP
16448       IF (l_total_split_qty <> 0 AND l_orig_interface_trx_id <>
16449 	  p_rti_tb(newrti).orig_interface_trx_id) THEN
16450 
16451 	 IF (l_debug = 1) THEN
16452 	    print_debug('SPLIT_LOT_SERIAL:l_total_split_qty:'||l_total_split_qty,1);
16453 	 END IF;
16454 
16455 	 BEGIN
16456 	    SELECT SUM(transaction_quantity)
16457 	      INTO l_total_lot_qty
16458 	      FROM mtl_transaction_lots_interface
16459 	      WHERE product_code = 'RCV'
16460 	      AND product_transaction_id = l_orig_interface_trx_id;
16461 	 EXCEPTION
16462 	    WHEN no_data_found THEN
16463 	       l_total_lot_qty := 0;
16464 	 END;
16465 
16466 	 IF l_total_lot_qty IS NULL THEN
16467 	    l_total_lot_qty := 0;
16468 	 END IF;
16469 
16470 	 IF (l_debug = 1) THEN
16471 	    print_debug('SPLIT_LOT_SERIAL:l_total_lot_qty:'||l_total_lot_qty,1);
16472 	 END IF;
16473 
16474          BEGIN
16475 	    SELECT SUM(inv_serial_number_pub.get_serial_diff(fm_serial_number,to_serial_number))
16476 	      INTO l_total_serial_qty
16477 	      FROM mtl_serial_numbers_interface
16478 	      WHERE product_code = 'RCV'
16479 	      AND product_transaction_id = l_orig_interface_trx_id;
16480 	 EXCEPTION
16481 	    WHEN no_data_found THEN
16482 	       l_total_serial_qty := 0;
16483 	 END;
16484 
16485 	 IF l_total_serial_qty IS NULL THEN
16486 	    l_total_serial_qty := 0;
16487 	 END IF;
16488 
16489 	 IF (l_debug = 1) THEN
16490 	    print_debug('SPLIT_LOT_SERIAL:l_total_serial_qty:'||l_total_serial_qty,1);
16491 	 END IF;
16492 
16493 	 IF (l_total_lot_qty <> 0 AND l_total_lot_qty <> l_total_split_qty) THEN
16494 	    IF (l_debug = 1) THEN
16495 	       print_debug('split_lot_serial:020: Lot Quantity Mismatch', 1);
16496 	       print_debug('split_lot_serial:030: total_lot_qty : '||l_total_lot_qty, 1);
16497 	       print_debug('split_lot_serial:040: total_split_qty : '||l_total_split_qty, 1);
16498 	    END If;
16499 
16500 	    -- raise an error
16501 	    l_progress := 'WMSINB-20780';
16502 	    RAISE fnd_api.g_exc_error;
16503 	 END IF;
16504 
16505          -- Bug 3395211
16506          -- Get the UOM code and Organization Id to calculate the primary qty.
16507          -- Bug 3446419
16508          -- This will not be called if values are passed in the record structure
16509 
16510          l_uom_code := p_rti_tb(newrti).uom_code;
16511          l_item_id  := p_rti_tb(newrti).item_id;
16512          l_to_organization_id := p_rti_tb(newrti).to_organization_id;
16513 
16514          if (l_uom_code is null or l_item_id is null or l_to_organization_id is null) then
16515          Begin
16516            select uom_code,
16517                   unit_of_measure,
16518                   item_id,
16519                   to_organization_id
16520              into l_uom_code,
16521                   l_unit_of_measure,
16522                   l_item_id,
16523                   l_to_organization_id
16524              from rcv_transactions_interface rti
16525             where rti.interface_transaction_id = p_rti_tb(newrti).new_interface_trx_id;
16526 
16527             if l_uom_code is null then
16528               BEGIN
16529                SELECT uom_code
16530                  into l_uom_code
16531                  FROM mtl_item_uoms_view
16532                  WHERE organization_id = l_to_organization_id
16533                  AND inventory_item_id =  l_item_id
16534                  AND unit_of_measure = l_unit_of_measure;
16535                EXCEPTION
16536                  WHEN OTHERS THEN
16537                   IF (l_debug = 1) THEN
16538                      print_debug('SPLIT_LOT_SERIAL : Error retrieving UOM inside split_lot_serial', 1);
16539                   END IF;
16540                   l_progress := 'WMSINB-20781';
16541                   RAISE fnd_api.g_exc_error;
16542                END;
16543             End if;
16544          Exception
16545            when others then
16546                   IF (l_debug = 1) THEN
16547                      print_debug('SPLIT_LOT_SERIAL : Error retrieving uom_code inside split_lot_serial ', 1);
16548                   END IF;
16549                   l_progress := 'WMSINB-20782';
16550                   RAISE fnd_api.g_exc_error;
16551          End;
16552          End if;
16553 
16554 	 IF (l_total_serial_qty <> 0 AND l_total_serial_qty <> get_primary_qty(l_to_organization_id,l_item_id,l_uom_code,l_total_split_qty) ) THEN
16555 	    IF (l_debug = 1) THEN
16556 	       print_debug('split_lot_serial:050: Serial Quantity Mismatch', 1);
16557 	       print_debug('split_lot_serial:060: total_serial_qty : '||l_total_serial_qty, 1);
16558 	       print_debug('split_lot_serial:070: total_split_qty : '||get_primary_qty(l_to_organization_id,l_item_id,l_uom_code,l_total_split_qty), 1);
16559 	    END If;
16560 
16561 	    -- raise an error
16562 	    l_progress := 'WMSINB-20792';
16563 	    RAISE fnd_api.g_exc_error;
16564 	 END IF;
16565 
16566 	 -- one more check for lot/serial items
16567          -- Bug 3395211 A nvl is added on primary_quantity because ideally the serial qty
16568          -- Should match with the primary qty.
16569 
16570 	 BEGIN
16571 	    SELECT SUM(mtli.transaction_quantity)
16572 	      INTO l_lot_ser_qty
16573 	      FROM mtl_transaction_lots_interface mtli
16574 	      WHERE mtli.product_code = 'RCV'
16575 	      AND mtli.product_transaction_id = l_orig_interface_trx_id
16576 	      AND (mtli.serial_transaction_temp_id IS NULL
16577 		   OR nvl(mtli.primary_quantity,
16578                           get_primary_qty(l_to_organization_id,l_item_id,l_uom_code,
16579                           mtli.transaction_quantity)
16580                          )
16581                  = (SELECT SUM(inv_serial_number_pub.get_serial_diff(msni.fm_serial_number,
16582 												    msni.to_serial_number))
16583 						   FROM mtl_serial_numbers_interface msni
16584 						   WHERE  msni.transaction_interface_id = mtli.serial_transaction_temp_id));
16585 	 EXCEPTION
16586 	    WHEN no_data_found then
16587 	       l_lot_ser_qty := 0;
16588 	 END;
16589 
16590 	 IF l_lot_ser_qty IS NULL THEN
16591 	    l_lot_ser_qty := 0;
16592 	 END IF;
16593 
16594 	 IF (l_debug = 1) THEN
16595 	    print_debug('SPLIT_LOT_SERIAL:l_lot_ser_qty:'||l_lot_ser_qty,1);
16596 	 END IF;
16597 
16598 	 IF (l_total_lot_qty <> 0 AND l_total_lot_qty <> l_lot_ser_qty) THEN
16599 	    IF (l_debug = 1) THEN
16600 	       print_debug('split_lot_serial:071: Lot Serial Quantity Mismatch', 1);
16601 	       print_debug('split_lot_serial:072: total_lot_qty : '||l_total_lot_qty, 1);
16602 	       print_debug('split_lot_serial:073: lot_ser_qty : '||l_lot_ser_qty, 1);
16603 	    END If;
16604 
16605 	    -- raise an error
16606 	    l_progress := 'WMSINB-20830';
16607 	    RAISE fnd_api.g_exc_error;
16608 	 END IF;
16609 
16610 	 l_orig_interface_trx_id := p_rti_tb(newrti).orig_interface_trx_id;
16611          /* Need to populate the absolute quantity otherwise fails for -ve correction*/
16612 	 l_total_split_qty := ABS(p_rti_tb(newrti).quantity);
16613        ELSE
16614 	       l_orig_interface_trx_id := p_rti_tb(newrti).orig_interface_trx_id;
16615 	       l_total_split_qty := l_total_split_qty + ABS(p_rti_tb(newrti).quantity);
16616 
16617                -- Bug 3395211
16618                -- Get the UOM code and Organization Id to calculate the primary qty.
16619                -- Bug 3446419
16620                -- This will not be called if values are passed in the record structure
16621 
16622                l_uom_code := p_rti_tb(newrti).uom_code;
16623                l_item_id  := p_rti_tb(newrti).item_id;
16624                l_to_organization_id := p_rti_tb(newrti).to_organization_id;
16625 
16626                if (l_uom_code is null or l_item_id is null or l_to_organization_id is null) then
16627                Begin
16628 	         IF (l_debug = 1) THEN
16629 	           print_debug('split_lot_serial: new_interface_trx_id = '|| p_rti_tb(newrti).new_interface_trx_id, 1);
16630                  End if;
16631 
16632                  select uom_code,
16633                         unit_of_measure,
16634                         item_id,
16635                         to_organization_id
16636                    into l_uom_code,
16637                         l_unit_of_measure,
16638                         l_item_id,
16639                         l_to_organization_id
16640                    from rcv_transactions_interface rti
16641                   where rti.interface_transaction_id = p_rti_tb(newrti).new_interface_trx_id;
16642 
16643                   if l_uom_code is null then
16644                     BEGIN
16645                      SELECT uom_code
16646                        into l_uom_code
16647                        FROM mtl_item_uoms_view
16648                        WHERE organization_id = l_to_organization_id
16649                        AND inventory_item_id =  l_item_id
16650                        AND unit_of_measure = l_unit_of_measure;
16651                      EXCEPTION
16652                        WHEN OTHERS THEN
16653                         IF (l_debug = 1) THEN
16654                            print_debug('SPLIT_LOT_SERIAL : Error retrieving UOM inside split_lot_serial', 1);
16655                         END IF;
16656                         l_progress := 'WMSINB-20835';
16657                         RAISE fnd_api.g_exc_error;
16658                      END;
16659                   End if;
16660                Exception
16661                  when others then
16662                         IF (l_debug = 1) THEN
16663                            print_debug('SPLIT_LOT_SERIAL : Error retrieving uom_code inside split_lot_serial ', 1);
16664                         END IF;
16665                         l_progress := 'WMSINB-20836';
16666                         RAISE fnd_api.g_exc_error;
16667                End;
16668                End if;
16669 
16670 	       IF newrti = l_rti_count THEN
16671 		  IF (l_debug = 1) THEN
16672 		     print_debug('SPLIT_LOT_SERIAL:l_total_split_qty:'||l_total_split_qty,1);
16673 		  END IF;
16674 
16675 	          BEGIN
16676 		     SELECT SUM(transaction_quantity)
16677 		       INTO l_total_lot_qty
16678 		       FROM mtl_transaction_lots_interface
16679 		       WHERE product_code = 'RCV'
16680 		       AND product_transaction_id = l_orig_interface_trx_id;
16681 		  EXCEPTION
16682 		     WHEN no_data_found THEN
16683 			l_total_lot_qty := 0;
16684 		  END;
16685 
16686 		  IF l_total_lot_qty IS NULL THEN
16687 		     l_total_lot_qty := 0;
16688 		  END IF;
16689 
16690 		  IF (l_debug = 1) THEN
16691 		     print_debug('SPLIT_LOT_SERIAL:l_total_lot_qty:'||l_total_lot_qty,1);
16692 		  END IF;
16693 
16694                   BEGIN
16695 		     SELECT SUM(inv_serial_number_pub.get_serial_diff(fm_serial_number,to_serial_number))
16696 		       INTO l_total_serial_qty
16697 		       FROM mtl_serial_numbers_interface
16698 		       WHERE product_code = 'RCV'
16699 		       AND product_transaction_id = l_orig_interface_trx_id;
16700 		  EXCEPTION
16701 		     WHEN no_data_found THEN
16702 			l_total_serial_qty := 0;
16703 		  END;
16704 
16705 		  IF l_total_serial_qty IS NULL THEN
16706 		     l_total_serial_qty := 0;
16707 		  END IF;
16708 
16709 		  IF (l_debug = 1) THEN
16710 		     print_debug('SPLIT_LOT_SERIAL:l_total_serial_qty:'||l_total_serial_qty,1);
16711 		  END IF;
16712 
16713 		  IF (l_total_lot_qty <> 0 AND l_total_lot_qty <> l_total_split_qty) THEN
16714 		     IF (l_debug = 1) THEN
16715 			print_debug('split_lot_serial:075.1: Lot Quantity Mismatch', 1);
16716 			print_debug('split_lot_serial:075.2: total_lot_qty : '||l_total_lot_qty, 1);
16717 			print_debug('split_lot_serial:075.3: total_split_qty : '||l_total_split_qty, 1);
16718 		     END If;
16719 
16720 		     -- raise an error
16721 		     l_progress := 'WMSINB-20891';
16722 		     RAISE fnd_api.g_exc_error;
16723 		  END IF;
16724 
16725 		  IF (l_total_serial_qty <> 0 AND l_total_serial_qty <> get_primary_qty(l_to_organization_id,l_item_id,l_uom_code,l_total_split_qty)) THEN
16726 		     IF (l_debug = 1) THEN
16727 			print_debug('split_lot_serial:075.4: Serial Quantity Mismatch', 1);
16728 			print_debug('split_lot_serial:075.5: total_serial_qty : '||l_total_serial_qty, 1);
16729 			print_debug('split_lot_serial:075.6: total_split_qty : '||get_primary_qty(l_to_organization_id,l_item_id,l_uom_code,l_total_split_qty), 1);
16730 			print_debug('SPLIT_LOT_SERIAL : to_organization_id:'||l_to_organization_id, 1);
16731 			print_debug('SPLIT_LOT_SERIAL : item_id:'||l_item_id, 1);
16732 			print_debug('SPLIT_LOT_SERIAL : uom_code:'||l_uom_code, 1);
16733 		     END If;
16734 
16735 		     -- raise an error
16736 		     l_progress := 'WMSINB-20903';
16737 		     RAISE fnd_api.g_exc_error;
16738 		  END IF;
16739 
16740 		  -- one more check for lot/serial items
16741 
16742 	          BEGIN
16743 		     SELECT SUM(mtli.transaction_quantity)
16744 		       INTO l_lot_ser_qty
16745 		       FROM mtl_transaction_lots_interface mtli
16746 		       WHERE mtli.product_code = 'RCV'
16747 		       AND mtli.product_transaction_id = l_orig_interface_trx_id
16748 		       AND (mtli.serial_transaction_temp_id IS NULL
16749 			    OR nvl(mtli.primary_quantity,
16750                                get_primary_qty(l_to_organization_id,l_item_id,l_uom_code,
16751                                mtli.transaction_quantity)
16752                            ) = (SELECT SUM(inv_serial_number_pub.get_serial_diff(msni.fm_serial_number,
16753                                                   msni.to_serial_number))
16754 				    FROM mtl_serial_numbers_interface msni
16755 				    WHERE  msni.transaction_interface_id = mtli.serial_transaction_temp_id));
16756 		  EXCEPTION
16757 		     WHEN no_data_found then
16758 			l_lot_ser_qty := 0;
16759 		  END;
16760 
16761 		  IF l_lot_ser_qty IS NULL THEN
16762 		     l_lot_ser_qty := 0;
16763 		  END IF;
16764 
16765 		  IF (l_debug = 1) THEN
16766 		     print_debug('SPLIT_LOT_SERIAL:l_lot_ser_qty:'||l_lot_ser_qty,1);
16767 		  END IF;
16768 
16769 		  IF (l_total_lot_qty <> 0 AND l_total_lot_qty <> l_lot_ser_qty) THEN
16770 		     IF (l_debug = 1) THEN
16771 			print_debug('split_lot_serial:075.7: Lot Serial Quantity Mismatch', 1);
16772 			print_debug('split_lot_serial:075.8: total_lot_qty : '||l_total_lot_qty, 1);
16773 			print_debug('split_lot_serial:075.9: lot_ser_qty : '||l_lot_ser_qty, 1);
16774 		     END If;
16775 
16776 		     -- raise an error
16777 		     l_progress := 'WMSINB-20941';
16778 		     RAISE fnd_api.g_exc_error;
16779 		  END IF;
16780 	       END IF; --IF newrti = p_rti_tb.COUNT THEN
16781       END IF;
16782    END LOOP;
16783 
16784    -- Now split the rows
16785    FOR newrti IN 1..p_rti_tb.COUNT LOOP
16786       IF (l_debug = 1) THEN
16787 	 print_debug('split_lot_serial:080: current record '||newrti, 1);
16788 	 print_debug('split_lot_serial:090: orig interface trx id '
16789 		     ||p_rti_tb(newrti).orig_interface_trx_id, 1);
16790 	 print_debug('split_lot_serial:100: new interface trx id '
16791 		     ||p_rti_tb(newrti).new_interface_trx_id, 1);
16792 	 print_debug('split_lot_serial:110: transaction_quantity '
16793 		     ||p_rti_tb(newrti).quantity, 1);
16794 	 --print_debug('split_lot_serial:120: unit of measure '
16795          --||p_rti_tb(newrti).unit_of_measure, 1);
16796       END If;
16797 
16798       -- Bug 3395211
16799       -- Get the UOM code and Organization Id to calculate the primary qty.
16800       -- Bug 3446419
16801       -- This will not be called if values are passed in the record structure
16802 
16803       l_uom_code := p_rti_tb(newrti).uom_code;
16804       l_item_id  := p_rti_tb(newrti).item_id;
16805       l_to_organization_id := p_rti_tb(newrti).to_organization_id;
16806 
16807       if (l_uom_code is null or l_item_id is null or l_to_organization_id is null) then
16808       Begin
16809           IF (l_debug = 1) THEN
16810 	      print_debug('split_lot_serial: new_interface_trx_id = '|| p_rti_tb(newrti).new_interface_trx_id, 1);
16811           End if;
16812 
16813            select uom_code,
16814                unit_of_measure,
16815                item_id,
16816                to_organization_id
16817           into l_uom_code,
16818                l_unit_of_measure,
16819                l_item_id,
16820                l_to_organization_id
16821           from rcv_transactions_interface rti
16822          where rti.interface_transaction_id = p_rti_tb(newrti).new_interface_trx_id;
16823 
16824          if l_uom_code is null then
16825            BEGIN
16826             SELECT uom_code
16827               into l_uom_code
16828               FROM mtl_item_uoms_view
16829               WHERE organization_id = l_to_organization_id
16830               AND inventory_item_id =  l_item_id
16831               AND unit_of_measure = l_unit_of_measure;
16832             EXCEPTION
16833               WHEN OTHERS THEN
16834                IF (l_debug = 1) THEN
16835                   print_debug('SPLIT_LOT_SERIAL : Error retrieving UOM inside split_lot_serial', 1);
16836                END IF;
16837                l_progress := 'WMSINB-20942';
16838                RAISE fnd_api.g_exc_error;
16839             END;
16840          End if;
16841       Exception
16842         when others then
16843                IF (l_debug = 1) THEN
16844                   print_debug('SPLIT_LOT_SERIAL : Error retrieving uom_code inside split_lot_serial ', 1);
16845                END IF;
16846                l_progress := 'WMSINB-20943';
16847                RAISE fnd_api.g_exc_error;
16848       END;
16849       End if;
16850 
16851       IF (p_rti_tb(newrti).new_interface_trx_id <> p_rti_tb(newrti).orig_interface_trx_id) THEN
16852 
16853 	 IF (l_debug = 1) THEN
16854 	    print_debug('split_lot_serial:130: Opening mtli_recs cursor', 1);
16855 	 END If;
16856 
16857 	 OPEN mtli_recs(p_rti_tb(newrti).orig_interface_trx_id);
16858 
16859 	 l_remaining_quantity := p_rti_tb(newrti).quantity;
16860 
16861 	 LOOP
16862 	    FETCH mtli_recs INTO l_mtli_rec;
16863 	    EXIT WHEN mtli_recs%notfound;
16864 	    IF (l_debug = 1) THEN
16865 	       print_debug('split_lot_serial:140: remaining_qty '||l_remaining_quantity, 1);
16866 	       print_debug('split_lot_serial:150: transaction_qty '||l_mtli_rec.transaction_quantity, 1);
16867 	    END If;
16868 
16869 	    l_primary_rem_qty := (l_remaining_quantity*l_mtli_rec.primary_quantity)/l_mtli_rec.transaction_quantity;
16870 
16871 	    IF (l_mtli_rec.transaction_quantity <= l_remaining_quantity) THEN
16872 	       -- update the mtli with new rti id.
16873 	       UPDATE mtl_transaction_lots_interface
16874 		 SET product_transaction_id = p_rti_tb(newrti).new_interface_trx_id
16875 		 WHERE ROWID = l_mtli_rec.ROWID;
16876 
16877 	       IF (l_debug = 1) THEN
16878 		  print_debug('split_lot_serial:160: serial_txn_tmp_id '||l_mtli_rec.serial_transaction_temp_id, 1);
16879 	       END If;
16880 
16881 	       -- update the serial records if exist.
16882 	       IF (l_mtli_rec.serial_transaction_temp_id IS NOT NULL) THEN
16883 		  OPEN msni_recs_lotserial(l_mtli_rec.serial_transaction_temp_id);
16884 
16885 		  l_serial_split_done := TRUE;
16886 
16887 		  LOOP
16888 		     FETCH msni_recs_lotserial INTO l_msni_rec;
16889 		     EXIT WHEN msni_recs_lotserial%notfound;
16890 
16891 		     IF (l_debug = 1) THEN
16892 			print_debug('split_lot_serial:170: update msni ', 1);
16893 		     END If;
16894 		     -- update the msni with new rti id.
16895 		     UPDATE mtl_serial_numbers_interface
16896 		       SET product_transaction_id = p_rti_tb(newrti).new_interface_trx_id
16897 		       WHERE ROWID = l_msni_rec.ROWID;
16898 
16899 		  END LOOP; -- fetch msni_recs_lotserial
16900                   close msni_recs_lotserial;
16901 
16902 	       END IF;
16903 	       l_remaining_quantity := l_remaining_quantity -
16904 		 l_mtli_rec.transaction_quantity;
16905 
16906 	     ELSE
16907 		  -- insert a new row with transaction_quantity = l_remaining
16908 		  -- quantity and new rti id. And update the original row
16909 		  -- with transaction_quantity =
16910 		  -- l_mtli_rec.transaction_quantity - l_remaining_quantity
16911 
16912 		  IF (l_mtli_rec.serial_transaction_temp_id IS NOT NULL)
16913 		    THEN
16914 		     SELECT mtl_material_transactions_s.NEXTVAL
16915 		       INTO l_new_serial_txn_temp_id
16916 		       FROM DUAL;
16917 		   ELSE
16918 		     l_new_serial_txn_temp_id := NULL;
16919 		  END IF;
16920 
16921 		  IF (l_debug = 1) THEN
16922 		     print_debug('split_lot_serial:180: insert mtli rowid ', 1);
16923 		  END If;
16924 
16925 		  insert_mtli_rowid (p_rowid => l_mtli_rec.ROWID,
16926 				     p_product_txn_id => p_rti_tb(newrti).new_interface_trx_id,
16927 				     p_new_serial_txn_temp_id => l_new_serial_txn_temp_id,
16928 				     p_quantity => l_remaining_quantity,
16929 				     p_primary_quantity => l_primary_rem_qty,
16930 				     x_return_status => x_return_status,
16931 				     x_msg_count => x_msg_count,
16932 				     x_msg_data => x_msg_data);
16933 
16934 		  IF (x_return_status <> g_ret_sts_success) THEN
16935 		     IF (l_debug = 1) THEN
16936 			print_debug('split_lot_serial:185: insert mtli rowid failed ', 1);
16937 		     END If;
16938 		     -- raise error
16939 		     l_progress := 'WMSINB-21051';
16940 		     RAISE fnd_api.g_exc_error;
16941 		  END IF;
16942 
16943 		  IF (l_debug = 1) THEN
16944 		     print_debug('split_lot_serial:190: update mtli ', 1);
16945 		  END If;
16946 
16947 		  -- update the original row
16948 		  -- For OPM null out the secondary_transaction_quantity
16949 		  UPDATE mtl_transaction_lots_interface
16950 		    SET transaction_quantity = transaction_quantity -
16951 		    l_remaining_quantity,
16952 		    primary_quantity = primary_quantity - l_primary_rem_qty,
16953 		    secondary_transaction_quantity = NULL
16954 		    WHERE ROWID = l_mtli_rec.ROWID;
16955 
16956 		  IF (l_mtli_rec.serial_transaction_temp_id IS NOT NULL) THEN
16957 		     OPEN msni_recs_lotserial(l_mtli_rec.serial_transaction_temp_id);
16958 
16959 		     l_serial_split_done := TRUE;
16960                      -- Bug 3395211
16961 		     l_remaining_serial_qty := get_primary_qty(l_to_organization_id,l_item_id,l_uom_code,l_remaining_quantity);
16962 
16963 		     LOOP
16964 			FETCH msni_recs_lotserial INTO l_msni_rec;
16965 			EXIT WHEN msni_recs_lotserial%notfound;
16966 
16967 			l_serial_quantity :=
16968 			  inv_serial_number_pub.get_serial_diff(l_msni_rec.fm_serial_number,
16969 								l_msni_rec.to_serial_number);
16970 
16971 			IF (l_debug = 1) THEN
16972 			   print_debug('split_lot_serial:200: serial quantity '||l_serial_quantity, 1);
16973 			END If;
16974 
16975 			IF (l_serial_quantity <= l_remaining_serial_qty)
16976 			  THEN
16977 			   -- update the msni record with new transaction
16978 			   -- id and new serial_transaction_temp_id
16979 			   IF (l_debug = 1) THEN
16980 			      print_debug('split_lot_serial:210: update msni ', 1);
16981 			   END If;
16982 
16983 			   UPDATE mtl_serial_numbers_interface
16984 			     SET product_transaction_id = p_rti_tb(newrti).new_interface_trx_id,
16985 			     transaction_interface_id = l_new_serial_txn_temp_id
16986 			     WHERE ROWID = l_msni_rec.ROWID;
16987 
16988 			   l_remaining_serial_qty := l_remaining_serial_qty
16989 			     - l_serial_quantity;
16990 			 ELSE
16991 			   -- split the msni row
16992 			   inv_validate.number_from_sequence(l_msni_rec.fm_serial_number, l_temp_prefix, l_from_ser_number);
16993 
16994 			   l_new_to_ser_num :=
16995 			     SUBSTR(l_msni_rec.fm_serial_number, 1,
16996 				    LENGTH(l_msni_rec.fm_serial_number) -
16997 				    LENGTH(l_from_ser_number))||(l_from_ser_number+l_remaining_serial_qty-1);
16998 
16999 			   l_new_from_ser_num :=
17000 			     SUBSTR(l_msni_rec.fm_serial_number, 1,
17001 				    LENGTH(l_msni_rec.fm_serial_number) -
17002 				    LENGTH(l_from_ser_number))||(l_from_ser_number+l_remaining_serial_qty);
17003 
17004 			   IF (l_debug = 1) THEN
17005 			      print_debug('split_lot_serial:220: insert	msni rowid', 1);
17006 			   END If;
17007 
17008 			   --insert new msni row.
17009 			   insert_msni_rowid (p_rowid =>l_msni_rec.ROWID,
17010 					      p_product_txn_id => p_rti_tb(newrti).new_interface_trx_id,
17011 					      p_new_serial_txn_temp_id => l_new_serial_txn_temp_id,
17012 					      p_new_fm_ser_num => null,
17013 					      p_new_to_ser_num => l_new_to_ser_num,
17014 					      x_return_status =>x_return_status,
17015 					      x_msg_count => x_msg_count,
17016 					      x_msg_data => x_msg_data);
17017 
17018 			   IF (x_return_status <> g_ret_sts_success) THEN
17019 			      IF (l_debug = 1) THEN
17020 				 print_debug('split_lot_serial:225: insert msni rowid failed ', 1);
17021 			      END If;
17022 			      -- raise error
17023 			      l_progress := 'WMSINB-21134';
17024 			      RAISE fnd_api.g_exc_error;
17025 			   END IF;
17026 
17027 			   -- update the original msni
17028 
17029 			   IF (l_debug = 1) THEN
17030 			      print_debug('split_lot_serial:230: update msni ', 1);
17031 			   END IF;
17032 
17033 			   UPDATE mtl_serial_numbers_interface
17034 			     SET fm_serial_number = l_new_from_ser_num
17035 			     WHERE ROWID = l_msni_rec.ROWID;
17036 
17037 			   l_remaining_serial_qty := 0;
17038 			END IF;
17039 
17040 			IF (l_remaining_serial_qty = 0) THEN
17041 			   EXIT;
17042 			END IF;
17043 
17044 		     END LOOP; -- fetch msni_recs_lotserial
17045                      close msni_recs_lotserial;
17046 		  END IF;
17047 		  l_remaining_quantity := 0;
17048 	    END IF;
17049 
17050 	    IF (l_remaining_quantity <= 0) THEN
17051 	       EXIT;
17052 	    END IF;
17053 
17054 	 END LOOP; -- fetch mtli_recs
17055          close mtli_recs;
17056 
17057 	 -- split the serial rows.
17058 	 IF NOT l_serial_split_done THEN
17059 	    OPEN msni_recs(p_rti_tb(newrti).orig_interface_trx_id);
17060 
17061             -- Bug 3395211
17062 	    l_remaining_quantity := get_primary_qty(l_to_organization_id,l_item_id,l_uom_code,p_rti_tb(newrti).quantity);
17063 
17064 	    LOOP
17065 	       FETCH msni_recs INTO l_msni_rec;
17066 	       EXIT WHEN msni_recs%notfound;
17067 
17068 	       IF (l_debug = 1) THEN
17069 		  print_debug('split_lot_serial:236: remaining quantity '||l_remaining_quantity, 1);
17070 	       END If;
17071 
17072 	       l_serial_quantity :=
17073 		 inv_serial_number_pub.get_serial_diff(l_msni_rec.fm_serial_number,l_msni_rec.to_serial_number);
17074 
17075 	       IF (l_debug = 1) THEN
17076 		  print_debug('split_lot_serial:237: serial quantity '||l_serial_quantity, 1);
17077 	       END If;
17078 
17079 	       IF (l_serial_quantity <= l_remaining_quantity) THEN
17080 
17081 		  IF (l_debug = 1) THEN
17082 		     print_debug('split_lot_serial:240: update msni ', 1);
17083 		     print_debug('split_lot_serial:241: new rti '||p_rti_tb(newrti).new_interface_trx_id, 1);
17084 		  END If;
17085 
17086 		  UPDATE mtl_serial_numbers_interface
17087 		    SET product_transaction_id = p_rti_tb(newrti).new_interface_trx_id
17088 		    WHERE ROWID = l_msni_rec.ROWID;
17089 
17090 		  l_remaining_quantity := l_remaining_quantity -
17091 		    l_serial_quantity;
17092 		ELSE
17093 		  -- split msni
17094 		  inv_validate.number_from_sequence(l_msni_rec.fm_serial_number, l_temp_prefix, l_from_ser_number);
17095 
17096 		  IF (l_debug = 1) THEN
17097 		     print_debug('split_lot_serial:242: Almost ready to split msni ', 1);
17098 		  END If;
17099 
17100 		  l_new_to_ser_num :=
17101 		    SUBSTR(l_msni_rec.fm_serial_number, 1,
17102 			   LENGTH(l_msni_rec.fm_serial_number) -
17103 			   LENGTH(l_from_ser_number))||(l_from_ser_number+l_remaining_quantity-1);
17104 
17105 		  l_new_from_ser_num :=
17106 		    SUBSTR(l_msni_rec.fm_serial_number, 1,
17107 			   LENGTH(l_msni_rec.fm_serial_number) -
17108 			   LENGTH(l_from_ser_number))||(l_from_ser_number+l_remaining_quantity);
17109 
17110 		  IF (l_debug = 1) THEN
17111 		     print_debug('split_lot_serial:250: insert msni rowid ', 1);
17112 		  END If;
17113 
17114 		  --insert new msni row.
17115 		  insert_msni_rowid (p_rowid =>l_msni_rec.ROWID,
17116 				     p_product_txn_id => p_rti_tb(newrti).new_interface_trx_id,
17117 				     p_new_serial_txn_temp_id => NULL,
17118 				     p_new_fm_ser_num => NULL,
17119 				     p_new_to_ser_num => l_new_to_ser_num,
17120 				     x_return_status =>x_return_status,
17121 				     x_msg_count => x_msg_count,
17122 				     x_msg_data => x_msg_data);
17123 
17124 		  IF (x_return_status <> g_ret_sts_success) THEN
17125 		     IF (l_debug = 1) THEN
17126 			print_debug('split_lot_serial:255: insert msni rowid failed ', 1);
17127 		     END If;
17128 		     -- raise error
17129 		     l_progress := 'WMSINB-21239';
17130 		     RAISE fnd_api.g_exc_error;
17131 		  END IF;
17132 
17133 		  -- update the original msni
17134 
17135 		  IF (l_debug = 1) THEN
17136 		     print_debug('split_lot_serial:260: update msni ', 1);
17137 		  END If;
17138 
17139 		  UPDATE mtl_serial_numbers_interface
17140 		    SET fm_serial_number = l_new_from_ser_num
17141 		    WHERE ROWID = l_msni_rec.ROWID;
17142 
17143 		  l_remaining_quantity := 0;
17144 	       END IF;
17145 
17146 	       IF (l_remaining_quantity <= 0) THEN
17147 		  EXIT;
17148 	       END IF;
17149 
17150 	    END LOOP; -- fetch msni_recs
17151             close msni_recs;
17152 	 END IF;
17153 
17154       END IF;
17155    END LOOP; -- for loop
17156 
17157    IF (l_debug = 1) THEN
17158       print_debug('split_lot_serial:270: Exit Stamp :' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
17159    END If;
17160 
17161 EXCEPTION
17162    WHEN fnd_api.g_exc_error THEN
17163       x_return_status  := g_ret_sts_error;
17164       IF (l_debug = 1) THEN
17165          print_debug('SPLIT_LOT_SERIAL - Execution Error:'||':'||l_progress||':'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
17166 	 print_stacked_messages;
17167       END IF;
17168 
17169       x_msg_data := l_progress;
17170 
17171    WHEN fnd_api.g_exc_unexpected_error THEN
17172       x_return_status  := g_ret_sts_unexp_error;
17173       IF (l_debug = 1) THEN
17174          print_debug('SPLIT_LOT_SERIAL - Unexpected Error:'||':'||l_progress||':'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
17175 	 print_stacked_messages;
17176       END IF;
17177 
17178       x_msg_data := l_progress;
17179 
17180    WHEN OTHERS THEN
17181       x_return_status  := g_ret_sts_unexp_error;
17182       IF (l_debug = 1) THEN
17183          print_debug('SPLIT_LOT_SERIAL - OTHER Exception: '||':'||l_progress||':'||
17184 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
17185 	 print_stacked_messages;
17186       END IF;
17187 
17188       x_msg_data := l_progress;
17189 
17190       IF SQLCODE IS NOT NULL THEN
17191 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.SPLIT_LOT_SERIAL', Sqlerrm,SQLCODE);
17192       END IF;
17193       -- Get message count and data
17194       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
17195 
17196 END split_lot_serial;
17197 
17198 
17199 --Function to check if the serials were entered for the parent transaction
17200 FUNCTION serial_entered_on_parent (p_parent_txn_id IN NUMBER)
17201   RETURN BOOLEAN
17202   IS
17203      l_dummy VARCHAR2(1);
17204 BEGIN
17205    SELECT '1'
17206      INTO l_dummy
17207      FROM rcv_serials_supply
17208      WHERE transaction_id = p_parent_txn_id
17209      AND ROWNUM = 1;
17210 
17211    RETURN TRUE;
17212 EXCEPTION
17213    WHEN no_data_found THEN
17214       RETURN FALSE;
17215 
17216 END serial_entered_on_parent;
17217 
17218 --Function to check if the lots were entered for the parent transaction
17219 FUNCTION lot_entered_on_parent (p_parent_txn_id IN NUMBER)
17220   RETURN BOOLEAN
17221   IS
17222      l_dummy VARCHAR2(1);
17223 BEGIN
17224    SELECT '1'
17225      INTO l_dummy
17226      FROM rcv_lots_supply
17227      WHERE transaction_id = p_parent_txn_id
17228      AND ROWNUM = 1;
17229 
17230    RETURN TRUE;
17231 EXCEPTION
17232    WHEN no_data_found THEN
17233       RETURN FALSE;
17234 
17235 END lot_entered_on_parent;
17236 
17237 --Function to check if the serials are present for ASN.
17238 FUNCTION rss_exists (p_shipment_header_id IN NUMBER,
17239 		     p_item_id            IN NUMBER)
17240   RETURN BOOLEAN
17241   IS
17242      l_dummy VARCHAR2(1);
17243 BEGIN
17244    SELECT '1'
17245      INTO l_dummy
17246      FROM rcv_serials_supply rss
17247      , rcv_shipment_lines rsl
17248      WHERE rss.shipment_line_id = rsl.shipment_line_id
17249      AND rsl.shipment_header_id = p_shipment_header_id
17250      AND rsl.item_id = p_item_id
17251      AND rss.supply_type_code = 'SHIPMENT'
17252      AND ROWNUM = 1;
17253 
17254    RETURN TRUE;
17255 EXCEPTION
17256    WHEN no_data_found THEN
17257       RETURN FALSE;
17258 END;
17259 
17260 --Function to update the group_mark_id fro serials to -7937
17261 FUNCTION update_group_mark_id(p_item_id IN NUMBER,
17262 			      p_serial_number IN VARCHAR2)
17263   RETURN BOOLEAN
17264   IS
17265 BEGIN
17266    UPDATE mtl_serial_numbers
17267      SET group_mark_id = -7937
17268      WHERE inventory_item_id = p_item_id
17269      AND serial_number = p_serial_number;
17270 
17271    RETURN TRUE;
17272 EXCEPTION
17273    WHEN OTHERS THEN
17274       RETURN FALSE;
17275 END;
17276 
17277 
17278 -- Procedure to move lot/serial info from interface tables to temp tables
17279 PROCEDURE move_lot_serial_info(p_rti_id IN NUMBER,
17280 			       x_return_status OUT nocopy VARCHAR2,
17281 			       x_msg_count OUT nocopy NUMBER,
17282 			       x_msg_data OUT nocopy VARCHAR2)
17283   IS
17284      L_DEBUG NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
17285 BEGIN
17286 
17287    x_return_status := g_ret_sts_success;
17288 
17289    INSERT INTO mtl_transaction_lots_temp (TRANSACTION_TEMP_ID,
17290 					  LAST_UPDATE_DATE,
17291 					  LAST_UPDATED_BY,
17292 					  CREATION_DATE,
17293 					  CREATED_BY,
17294 					  LAST_UPDATE_LOGIN,
17295 					  REQUEST_ID,
17296 					  PROGRAM_APPLICATION_ID,
17297 					  PROGRAM_ID,
17298 					  PROGRAM_UPDATE_DATE,
17299 					  TRANSACTION_QUANTITY,
17300 					  PRIMARY_QUANTITY,
17301 					  LOT_NUMBER,
17302 					  LOT_EXPIRATION_DATE,
17303 					  ERROR_CODE,
17304 					  SERIAL_TRANSACTION_TEMP_ID,
17305 					  DESCRIPTION,
17306 					  VENDOR_NAME,
17307 					  SUPPLIER_LOT_NUMBER,
17308 					  ORIGINATION_DATE,
17309 					  DATE_CODE,
17310 					  GRADE_CODE,
17311 					  CHANGE_DATE,
17312 					  MATURITY_DATE,
17313 					  STATUS_ID,
17314 					  RETEST_DATE,
17315 					  AGE,
17316 					  ITEM_SIZE,
17317 					  COLOR,
17318 					  VOLUME,
17319 					  VOLUME_UOM,
17320 					  PLACE_OF_ORIGIN,
17321 					  BEST_BY_DATE,
17322 					  LENGTH,
17323 					  LENGTH_UOM,
17324 					  RECYCLED_CONTENT,
17325 					  THICKNESS,
17326 					  THICKNESS_UOM,
17327 					  WIDTH,
17328 					  WIDTH_UOM,
17329 					  CURL_WRINKLE_FOLD,
17330 					  LOT_ATTRIBUTE_CATEGORY,
17331 					  C_ATTRIBUTE1,
17332 					  C_ATTRIBUTE2,
17333 					  C_ATTRIBUTE3,
17334 					  C_ATTRIBUTE4,
17335      C_ATTRIBUTE5,
17336      C_ATTRIBUTE6,
17337      C_ATTRIBUTE7,
17338      C_ATTRIBUTE8,
17339      C_ATTRIBUTE9,
17340      C_ATTRIBUTE10,
17341      C_ATTRIBUTE11,
17342      C_ATTRIBUTE12,
17343      C_ATTRIBUTE13,
17344      C_ATTRIBUTE14,
17345      C_ATTRIBUTE15,
17346      C_ATTRIBUTE16,
17347      C_ATTRIBUTE17,
17348      C_ATTRIBUTE18,
17349      C_ATTRIBUTE19,
17350      C_ATTRIBUTE20,
17351      D_ATTRIBUTE1,
17352      D_ATTRIBUTE2,
17353      D_ATTRIBUTE3,
17354      D_ATTRIBUTE4,
17355      D_ATTRIBUTE5,
17356      D_ATTRIBUTE6,
17357      D_ATTRIBUTE7,
17358      D_ATTRIBUTE8,
17359      D_ATTRIBUTE9,
17360      D_ATTRIBUTE10,
17361      N_ATTRIBUTE1,
17362      N_ATTRIBUTE2,
17363      N_ATTRIBUTE3,
17364      N_ATTRIBUTE4,
17365      N_ATTRIBUTE5,
17366      N_ATTRIBUTE6,
17367      N_ATTRIBUTE7,
17368      N_ATTRIBUTE8,
17369      N_ATTRIBUTE9,
17370      N_ATTRIBUTE10,
17371      attribute_category,
17372      attribute1,
17373      attribute2,
17374      attribute3,
17375      attribute4,
17376      attribute5,
17377      attribute6,
17378      attribute7,
17379      attribute8,
17380      attribute9,
17381      attribute10,
17382      attribute11,
17383      attribute12,
17384      attribute13,
17385      attribute14,
17386      attribute15,
17387      VENDOR_ID,
17388      TERRITORY_CODE,
17389      PRODUCT_CODE,
17390      PRODUCT_TRANSACTION_ID,
17391      /*INVCONV , Remove sublot_num and add parent parent_lot_number and other attributes, Punit Kumar */
17392 
17393      /** OPM change Bug# 3061052**/
17394      --SUBLOT_NUM             ,
17395      PARENT_LOT_NUMBER        ,
17396      ORIGINATION_TYPE         ,
17397      EXPIRATION_ACTION_DATE   ,
17398      EXPIRATION_ACTION_CODE   ,
17399      HOLD_DATE    ,
17400      REASON_ID    ,
17401      /* end  INVCONV */
17402      SECONDARY_QUANTITY      ,
17403      REASON_CODE                    )
17404      SELECT transaction_interface_id ,
17405      LAST_UPDATE_DATE,
17406      LAST_UPDATED_BY,
17407      CREATION_DATE,
17408      CREATED_BY,
17409      LAST_UPDATE_LOGIN,
17410      REQUEST_ID,
17411      PROGRAM_APPLICATION_ID,
17412      PROGRAM_ID,
17413      PROGRAM_UPDATE_DATE,
17414      TRANSACTION_QUANTITY,
17415      PRIMARY_QUANTITY,
17416      Ltrim(Rtrim(lot_number)),
17417      LOT_EXPIRATION_DATE,
17418      ERROR_CODE,
17419      SERIAL_TRANSACTION_TEMP_ID,
17420      DESCRIPTION,
17421      VENDOR_NAME,
17422      SUPPLIER_LOT_NUMBER,
17423      ORIGINATION_DATE,
17424      DATE_CODE,
17425      GRADE_CODE,
17426      CHANGE_DATE,
17427      MATURITY_DATE,
17428      STATUS_ID,
17429      RETEST_DATE,
17430      AGE,
17431      ITEM_SIZE,
17432      COLOR,
17433      VOLUME,
17434      VOLUME_UOM,
17435      PLACE_OF_ORIGIN,
17436      BEST_BY_DATE,
17437      LENGTH,
17438      LENGTH_UOM,
17439      RECYCLED_CONTENT,
17440      THICKNESS,
17441      THICKNESS_UOM,
17442      WIDTH,
17443      WIDTH_UOM,
17444      CURL_WRINKLE_FOLD,
17445      LOT_ATTRIBUTE_CATEGORY,
17446      C_ATTRIBUTE1,
17447      C_ATTRIBUTE2,
17448      C_ATTRIBUTE3,
17449      C_ATTRIBUTE4,
17450      C_ATTRIBUTE5,
17451      C_ATTRIBUTE6,
17452      C_ATTRIBUTE7,
17453      C_ATTRIBUTE8,
17454      C_ATTRIBUTE9,
17455      C_ATTRIBUTE10,
17456      C_ATTRIBUTE11,
17457      C_ATTRIBUTE12,
17458      C_ATTRIBUTE13,
17459      C_ATTRIBUTE14,
17460      C_ATTRIBUTE15,
17461      C_ATTRIBUTE16,
17462      C_ATTRIBUTE17,
17463      C_ATTRIBUTE18,
17464      C_ATTRIBUTE19,
17465      C_ATTRIBUTE20,
17466      D_ATTRIBUTE1,
17467      D_ATTRIBUTE2,
17468      D_ATTRIBUTE3,
17469      D_ATTRIBUTE4,
17470      D_ATTRIBUTE5,
17471      D_ATTRIBUTE6,
17472      D_ATTRIBUTE7,
17473      D_ATTRIBUTE8,
17474      D_ATTRIBUTE9,
17475      D_ATTRIBUTE10,
17476      N_ATTRIBUTE1,
17477      N_ATTRIBUTE2,
17478      N_ATTRIBUTE3,
17479      N_ATTRIBUTE4,
17480      N_ATTRIBUTE5,
17481      N_ATTRIBUTE6,
17482      N_ATTRIBUTE7,
17483      N_ATTRIBUTE8,
17484      N_ATTRIBUTE9,
17485      N_ATTRIBUTE10,
17486      attribute_category,
17487      attribute1,
17488      attribute2,
17489      attribute3,
17490      attribute4,
17491      attribute5,
17492      attribute6,
17493      attribute7,
17494      attribute8,
17495      attribute9,
17496      attribute10,
17497      attribute11,
17498      attribute12,
17499      attribute13,
17500      attribute14,
17501      attribute15,
17502      VENDOR_ID,
17503      TERRITORY_CODE,
17504      PRODUCT_CODE,
17505      product_transaction_id,
17506 
17507      /*INVCONV , Remove sublot_num and add parent parent_lot_number and other attributes,
17508      ORIGINATION_TYPE defaulted to 'PURCHASING'. Punit Kumar */
17509 
17510      /** OPM change Bug# 3061052**/
17511      ---sublot_num,
17512 
17513      PARENT_LOT_NUMBER		   ,
17514      3             ,   /* defaulting the value of ORIGINATION_TYPE  to 'PURCHASING'*/
17515      EXPIRATION_ACTION_DATE   ,
17516      EXPIRATION_ACTION_CODE   ,
17517      HOLD_DATE                ,
17518      REASON_ID                ,
17519      /* end INVCONV */
17520      secondary_transaction_quantity,
17521      reason_code
17522      FROM mtl_transaction_lots_interface
17523      WHERE product_code = 'RCV'
17524      AND product_transaction_id = p_rti_id;
17525 
17526 
17527    IF (l_debug = 1) THEN
17528       print_debug('move_lot_serial_info - Number of MTLT Inserted =: '||SQL%ROWCOUNT ||
17529 		  ' with product transaction_id = ' || p_rti_id, 1);
17530       /*INVCONV*/
17531        print_debug('INVCONV, removed sublot_num, Added some more parameters in INSERT INTO mtl_transaction_lots_temp (move_lot_serial_info)', 1);
17532      /*end , INVCONV*/
17533 
17534    END IF;
17535 
17536 
17537 
17538 
17539    INSERT INTO mtl_serial_numbers_temp (TRANSACTION_TEMP_ID,
17540 					LAST_UPDATE_DATE,
17541 					LAST_UPDATED_BY,
17542 					CREATION_DATE,
17543 					CREATED_BY,
17544 					LAST_UPDATE_LOGIN,
17545 					REQUEST_ID,
17546 					PROGRAM_APPLICATION_ID,
17547 					PROGRAM_ID,
17548 					PROGRAM_UPDATE_DATE,
17549 					VENDOR_SERIAL_NUMBER,
17550 					VENDOR_LOT_NUMBER,
17551 					FM_SERIAL_NUMBER,
17552 					TO_SERIAL_NUMBER,
17553 					ERROR_CODE,
17554 					PARENT_SERIAL_NUMBER,
17555 					SERIAL_ATTRIBUTE_CATEGORY,
17556 					ORIGINATION_DATE,
17557 					C_ATTRIBUTE1,
17558 					C_ATTRIBUTE2,
17559 					C_ATTRIBUTE3,
17560 					C_ATTRIBUTE4,
17561 					C_ATTRIBUTE5,
17562 					C_ATTRIBUTE6,
17563 					C_ATTRIBUTE7,
17564 					C_ATTRIBUTE8,
17565 					C_ATTRIBUTE9,
17566 					C_ATTRIBUTE10,
17567 					C_ATTRIBUTE11,
17568 					C_ATTRIBUTE12,
17569 					C_ATTRIBUTE13,
17570 					C_ATTRIBUTE14,
17571 					C_ATTRIBUTE15,
17572 					C_ATTRIBUTE16,
17573 					C_ATTRIBUTE17,
17574 					C_ATTRIBUTE18,
17575 					C_ATTRIBUTE19,
17576 					C_ATTRIBUTE20,
17577 					D_ATTRIBUTE1,
17578 					D_ATTRIBUTE2,
17579 					D_ATTRIBUTE3,
17580 					D_ATTRIBUTE4,
17581 					D_ATTRIBUTE5,
17582 					D_ATTRIBUTE6,
17583 					D_ATTRIBUTE7,
17584 					D_ATTRIBUTE8,
17585 					D_ATTRIBUTE9,
17586 					D_ATTRIBUTE10,
17587 					N_ATTRIBUTE1,
17588      N_ATTRIBUTE2,
17589      N_ATTRIBUTE3,
17590      N_ATTRIBUTE4,
17591      N_ATTRIBUTE5,
17592      N_ATTRIBUTE6,
17593      N_ATTRIBUTE7,
17594      N_ATTRIBUTE8,
17595      N_ATTRIBUTE9,
17596      N_ATTRIBUTE10,
17597      attribute_category,
17598      attribute1,
17599      attribute2,
17600      attribute3,
17601      attribute4,
17602      attribute5,
17603      attribute6,
17604      attribute7,
17605      attribute8,
17606      attribute9,
17607      attribute10,
17608      attribute11,
17609      attribute12,
17610      attribute13,
17611      attribute14,
17612      attribute15,
17613      STATUS_ID,
17614      TERRITORY_CODE,
17615      TIME_SINCE_NEW,
17616      CYCLES_SINCE_NEW,
17617      TIME_SINCE_OVERHAUL,
17618      CYCLES_SINCE_OVERHAUL,
17619      TIME_SINCE_REPAIR,
17620      CYCLES_SINCE_REPAIR,
17621      TIME_SINCE_VISIT,
17622      CYCLES_SINCE_VISIT,
17623      TIME_SINCE_MARK,
17624      CYCLES_SINCE_MARK,
17625      NUMBER_OF_REPAIRS,
17626      PRODUCT_CODE,
17627      product_transaction_id)
17628      SELECT transaction_interface_id,
17629      LAST_UPDATE_DATE,
17630      LAST_UPDATED_BY,
17631      CREATION_DATE,
17632      CREATED_BY,
17633      LAST_UPDATE_LOGIN,
17634      REQUEST_ID,
17635      PROGRAM_APPLICATION_ID,
17636      PROGRAM_ID,
17637      PROGRAM_UPDATE_DATE,
17638      VENDOR_SERIAL_NUMBER,
17639      VENDOR_LOT_NUMBER,
17640      FM_SERIAL_NUMBER,
17641      TO_SERIAL_NUMBER,
17642      ERROR_CODE,
17643      PARENT_SERIAL_NUMBER,
17644      SERIAL_ATTRIBUTE_CATEGORY,
17645      ORIGINATION_DATE,
17646      C_ATTRIBUTE1,
17647      C_ATTRIBUTE2,
17648      C_ATTRIBUTE3,
17649      C_ATTRIBUTE4,
17650      C_ATTRIBUTE5,
17651      C_ATTRIBUTE6,
17652      C_ATTRIBUTE7,
17653      C_ATTRIBUTE8,
17654      C_ATTRIBUTE9,
17655      C_ATTRIBUTE10,
17656      C_ATTRIBUTE11,
17657      C_ATTRIBUTE12,
17658      C_ATTRIBUTE13,
17659      C_ATTRIBUTE14,
17660      C_ATTRIBUTE15,
17661      C_ATTRIBUTE16,
17662      C_ATTRIBUTE17,
17663      C_ATTRIBUTE18,
17664      C_ATTRIBUTE19,
17665      C_ATTRIBUTE20,
17666      D_ATTRIBUTE1,
17667      D_ATTRIBUTE2,
17668      D_ATTRIBUTE3,
17669      D_ATTRIBUTE4,
17670      D_ATTRIBUTE5,
17671      D_ATTRIBUTE6,
17672      D_ATTRIBUTE7,
17673      D_ATTRIBUTE8,
17674      D_ATTRIBUTE9,
17675      D_ATTRIBUTE10,
17676      N_ATTRIBUTE1,
17677      N_ATTRIBUTE2,
17678      N_ATTRIBUTE3,
17679      N_ATTRIBUTE4,
17680      N_ATTRIBUTE5,
17681      N_ATTRIBUTE6,
17682      N_ATTRIBUTE7,
17683      N_ATTRIBUTE8,
17684      N_ATTRIBUTE9,
17685      N_ATTRIBUTE10,
17686      attribute_category,
17687      attribute1,
17688      attribute2,
17689      attribute3,
17690      attribute4,
17691      attribute5,
17692      attribute6,
17693      attribute7,
17694      attribute8,
17695      attribute9,
17696      attribute10,
17697      attribute11,
17698      attribute12,
17699      attribute13,
17700      attribute14,
17701      attribute15,
17702      STATUS_ID,
17703      TERRITORY_CODE,
17704      TIME_SINCE_NEW,
17705      CYCLES_SINCE_NEW,
17706      TIME_SINCE_OVERHAUL,
17707      CYCLES_SINCE_OVERHAUL,
17708      TIME_SINCE_REPAIR,
17709      CYCLES_SINCE_REPAIR,
17710      TIME_SINCE_VISIT,
17711      CYCLES_SINCE_VISIT,
17712      TIME_SINCE_MARK,
17713      CYCLES_SINCE_MARK,
17714      NUMBER_OF_REPAIRS,
17715      PRODUCT_CODE,
17716      product_transaction_id
17717      FROM mtl_serial_numbers_interface
17718      WHERE product_code = 'RCV'
17719      AND product_transaction_id = p_rti_id;
17720 
17721    IF (l_debug = 1) THEN
17722       print_debug('move_lot_serial_info - Number of MSNT Inserted =: '||SQL%ROWCOUNT ||
17723 		  ' with product transaction_id =' || p_rti_id, 1);
17724    END IF;
17725 
17726    --delete mtli and msni
17727    DELETE FROM mtl_transaction_lots_interface
17728      WHERE product_code = 'RCV'
17729      AND product_transaction_id = p_rti_id;
17730 
17731    DELETE FROM mtl_serial_numbers_interface
17732      WHERE product_code = 'RCV'
17733      AND product_transaction_id = p_rti_id;
17734 
17735 EXCEPTION
17736    WHEN OTHERS THEN
17737       IF (l_debug = 1) THEN
17738          print_debug('move_lot_serial_info - Other Exception error = '|| SQLCODE || ' this is ignored ' , 1);
17739       END IF;
17740       NULL;
17741 END move_lot_serial_info;
17742 
17743 
17744 /* The following procedure will be called from RCV processor to validate
17745 lot serials. This procecure will be called once for each RTI row. */
17746 
17747 
17748   PROCEDURE VALIDATE_LOT_SERIAL_INFO (P_RTI_ID IN NUMBER,
17749 				      X_RETURN_STATUS OUT NOCOPY VARCHAR2,
17750 				      X_MSG_COUNT OUT NOCOPY NUMBER,
17751 				      X_MSG_DATA OUT NOCOPY VARCHAR2)
17752   IS
17753      l_lot_status_enabled VARCHAR2(1) := 'Y'; --Bug 4066234
17754      --Bug #3187688 - Fetch the INV attribute category and attributes1-15 from MTLT
17755      CURSOR C_MTLT (L_RTI_ID NUMBER) IS
17756 	SELECT Ltrim(Rtrim(lot_number)) lot_number
17757 	  , SERIAL_TRANSACTION_TEMP_ID
17758 	  , TRANSACTION_QUANTITY
17759 	  , primary_quantity
17760 	  , lot_expiration_date
17761 	  , lot_attribute_category
17762 	  , C_ATTRIBUTE1
17763 	  , C_ATTRIBUTE2
17764 	  , C_ATTRIBUTE3
17765 	  , C_ATTRIBUTE4
17766 	  , C_ATTRIBUTE5
17767 	  , C_ATTRIBUTE6
17768 	  , C_ATTRIBUTE7
17769 	  , C_ATTRIBUTE8
17770 	  , C_ATTRIBUTE9
17771 	  , C_ATTRIBUTE10
17772 	  , C_ATTRIBUTE11
17773 	  , C_ATTRIBUTE12
17774 	  , C_ATTRIBUTE13
17775 	  , C_ATTRIBUTE14
17776 	  , C_ATTRIBUTE15
17777 	  , C_ATTRIBUTE16
17778 	  , C_ATTRIBUTE17
17779 	  , C_ATTRIBUTE18
17780 	  , C_ATTRIBUTE19
17781 	  , C_ATTRIBUTE20
17782 	  , D_ATTRIBUTE1
17783 	  , D_ATTRIBUTE2
17784 	  , D_ATTRIBUTE3
17785 	  , D_ATTRIBUTE4
17786 	  , D_ATTRIBUTE5
17787 	  , D_ATTRIBUTE6
17788 	  , D_ATTRIBUTE7
17789 	  , D_ATTRIBUTE8
17790 	  , D_ATTRIBUTE9
17791 	  , D_ATTRIBUTE10
17792 	  , N_ATTRIBUTE1
17793 	  , N_ATTRIBUTE2
17794 	  , N_ATTRIBUTE3
17795 	  , N_ATTRIBUTE4
17796 	  , N_ATTRIBUTE5
17797 	  , N_ATTRIBUTE6
17798 	  , N_ATTRIBUTE7
17799 	  , N_ATTRIBUTE8
17800 	  , N_ATTRIBUTE9
17801 	  , n_attribute10
17802 	  , grade_code
17803 	  , origination_date
17804 	  , date_code
17805 	  , Decode(l_lot_status_enabled,'Y',status_id,1) status_id --Bug 4066234
17806 	  , change_date
17807 	  , age
17808 	  , retest_date
17809 	  , maturity_date
17810 	  , item_size
17811 	  , color
17812 	  , volume
17813 	  , volume_uom
17814 	  , place_of_origin
17815 	  , best_by_date
17816 	  , Length
17817 	  , length_uom
17818 	  , recycled_content
17819 	  , thickness
17820 	  , thickness_uom
17821 	  , width
17822 	  , width_uom
17823 	  , territory_code
17824 	  , supplier_lot_number
17825 	  , vendor_name
17826 	  /** INVCONV,remove sublot_number, add Parent lot number and SECONDARY_UNIT_OF_MEASURE etc,
17827       Punit Kumar**/
17828 	  ---, Ltrim(Rtrim(sublot_num)) sublot_num
17829      ,Ltrim(Rtrim(PARENT_LOT_NUMBER)) PARENT_LOT_NUMBER
17830      ----,SECONDARY_UNIT_OF_MEASURE
17831      ,REASON_ID
17832      ,LAST_UPDATED_BY
17833      ,CREATED_BY
17834      ,LAST_UPDATE_LOGIN
17835      ,REQUEST_ID
17836      ,PROGRAM_APPLICATION_ID
17837      ,PROGRAM_ID
17838      ,PROGRAM_UPDATE_DATE
17839      ,DESCRIPTION
17840      ,CURL_WRINKLE_FOLD
17841      ,VENDOR_ID
17842      ,ORIGINATION_TYPE
17843      ,EXPIRATION_ACTION_DATE
17844      ,EXPIRATION_ACTION_CODE
17845      ,HOLD_DATE
17846      ----,TRANSACTION_TEMP_ID
17847      /* end INVCONV */
17848 	  , secondary_quantity
17849 	  , reason_code
17850 	  , rowid
17851     , attribute_category
17852     , attribute1
17853     , attribute2
17854     , attribute3
17855     , attribute4
17856     , attribute5
17857     , attribute6
17858     , attribute7
17859     , attribute8
17860     , attribute9
17861     , attribute10
17862     , attribute11
17863     , attribute12
17864     , attribute13
17865     , attribute14
17866     , attribute15
17867 	  FROM MTL_TRANSACTION_LOTS_TEMP
17868 	  WHERE PRODUCT_CODE = 'RCV'
17869 	  AND PRODUCT_TRANSACTION_ID = L_RTI_ID;
17870 
17871      L_MTLT_REC C_MTLT%ROWTYPE;
17872 
17873      CURSOR C_MSNT (L_RTI_ID NUMBER) IS
17874 	SELECT FM_SERIAL_NUMBER
17875 	  , to_serial_number
17876 	  , vendor_serial_number
17877 	  , transaction_temp_id
17878 	  , serial_attribute_category
17879 	  , origination_date
17880 	  , c_attribute1
17881 	  , c_attribute2
17882 	  , c_attribute3
17883 	  , c_attribute4
17884 	  , c_attribute5
17885 	  , c_attribute6
17886 	  , c_attribute7
17887 	  , c_attribute8
17888 	  , c_attribute9
17889 	  , c_attribute10
17890 	  , c_attribute11
17891 	  , c_attribute12
17892 	  , c_attribute13
17893 	  , c_attribute14
17894 	  , c_attribute15
17895 	  , c_attribute16
17896 	  , c_attribute17
17897 	  , c_attribute18
17898 	  , c_attribute19
17899 	  , c_attribute20
17900 	  , d_attribute1
17901 	  , d_attribute2
17902 	  , d_attribute3
17903 	  , d_attribute4
17904 	  , d_attribute5
17905 	  , d_attribute6
17906 	  , d_attribute7
17907 	  , d_attribute8
17908 	  , d_attribute9
17909 	  , d_attribute10
17910 	  , n_attribute1
17911 	  , n_attribute2
17912 	  , n_attribute3
17913 	  , n_attribute4
17914 	  , n_attribute5
17915 	  , n_attribute6
17916 	  , n_attribute7
17917 	  , n_attribute8
17918 	  , n_attribute9
17919 	  , n_attribute10
17920 	  , status_id
17921 	  , territory_code
17922 	  , ROWID
17923 	  FROM MTL_SERIAL_NUMBERS_TEMP
17924 	  WHERE PRODUCT_CODE = 'RCV'
17925 	  AND PRODUCT_TRANSACTION_ID = L_RTI_ID;
17926 
17927      L_MSNT_REC C_MSNT%ROWTYPE;
17928 
17929      CURSOR C_MSNT_LOTSERIAL (L_SERIAL_TXN_ID NUMBER) IS
17930 	SELECT FM_SERIAL_NUMBER
17931 	  , to_serial_number
17932 	  , vendor_serial_number
17933 	  , transaction_temp_id
17934 	  , serial_attribute_category
17935 	  , origination_date
17936 	  , c_attribute1
17937 	  , c_attribute2
17938 	  , c_attribute3
17939 	  , c_attribute4
17940 	  , c_attribute5
17941 	  , c_attribute6
17942 	  , c_attribute7
17943 	  , c_attribute8
17944 	  , c_attribute9
17945 	  , c_attribute10
17946 	  , c_attribute11
17947 	  , c_attribute12
17948 	  , c_attribute13
17949 	  , c_attribute14
17950 	  , c_attribute15
17951 	  , c_attribute16
17952 	  , c_attribute17
17953 	  , c_attribute18
17954 	  , c_attribute19
17955 	  , c_attribute20
17956 	  , d_attribute1
17957 	  , d_attribute2
17958 	  , d_attribute3
17959 	  , d_attribute4
17960 	  , d_attribute5
17961 	  , d_attribute6
17962 	  , d_attribute7
17963 	  , d_attribute8
17964 	  , d_attribute9
17965 	  , d_attribute10
17966 	  , n_attribute1
17967 	  , n_attribute2
17968 	  , n_attribute3
17969 	  , n_attribute4
17970 	  , n_attribute5
17971 	  , n_attribute6
17972 	  , n_attribute7
17973 	  , n_attribute8
17974 	  , n_attribute9
17975 	  , n_attribute10
17976 	  , status_id
17977 	  , territory_code
17978 	  , ROWID
17979 	  FROM MTL_SERIAL_NUMBERS_TEMP
17980 	  WHERE PRODUCT_CODE = 'RCV'
17981 	  AND transaction_temp_id = L_SERIAL_TXN_ID;
17982 
17983      l_rti_id NUMBER;
17984 
17985      L_TRANSACTION_TYPE VARCHAR2(25);
17986      L_AUTO_TRANSACT_CODE VARCHAR2(25);
17987      L_SOURCE_DOCUMENT_CODE VARCHAR2(25);
17988      L_ITEM_ID NUMBER;
17989      l_item_revision varchar2(3);
17990      L_LPN_ID NUMBER;
17991      L_TRANSFER_LPN_ID NUMBER;
17992      L_LOT_CONTROL_CODE NUMBER;
17993      L_SERIAL_NUMBER_CONTROL_CODE NUMBER;
17994      L_FROM_ORG_ID NUMBER;
17995      L_ORG_ID NUMBER;
17996      L_SHIPMENT_LINE_ID NUMBER;
17997      L_SHIPMENT_HEADER_ID NUMBER;
17998      L_PARENT_TRANSACTION_ID NUMBER;
17999      L_SUB_CODE VARCHAR2(10);
18000      L_LOC_ID NUMBER;
18001      l_routing_header_id NUMBER;
18002      l_asn_line_flag VARCHAR2(1);
18003      l_rti_primary_qty NUMBER;
18004      l_rti_trans_qty NUMBER; -- Bug# 4225766
18005      l_mobile_txn VARCHAR2(1);
18006      l_inv_txn_id NUMBER;
18007      l_proc_mode_code VARCHAR2(30);
18008 
18009      l_destination_type_code VARCHAR2(30);
18010 
18011      l_transaction_type_id NUMBER;
18012      l_transaction_action_id NUMBER;
18013 
18014      L_NUM_MTLT_RECS NUMBER;
18015      L_NUM_MSNT_RECS NUMBER;
18016      l_tot_mtlt_prim_qty NUMBER;
18017      l_tot_mtlt_trans_qty NUMBER; -- Bug# 4225766
18018      l_tot_msnt_serial_qty NUMBER;
18019 
18020      L_LOT_EXISTS NUMBER := 0;
18021      l_serial_exists NUMBER := 0;
18022 
18023      L_SERIAL_QUANTITY NUMBER;
18024      L_TEMP_PREFIX VARCHAR2(30);
18025      L_FROM_SER_NUMBER NUMBER;
18026      L_TO_SER_NUMBER   NUMBER;
18027      L_SERIAL_NUMBER VARCHAR2(30);
18028      L_CUR_NUMBER     NUMBER;
18029 
18030      L_CURR_ORG_ID NUMBER;
18031      L_CURR_STATUS NUMBER;
18032 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
18033      l_curr_lot_num VARCHAR2(80);
18034      l_curr_lpn_id NUMBER;
18035      l_inspection_status NUMBER;
18036      l_group_mark_id NUMBER;
18037 
18038      L_FROM_ORG_LOT_CTRL NUMBER;
18039      L_FROM_ORG_SER_CRTL NUMBER;
18040      l_from_org_rev_ctrl NUMBER;
18041 
18042      L_DUMMY VARCHAR2(1);
18043      L_ATT_VAL_STATUS VARCHAR2(1);
18044      L_LOT_ENTERED_ON_PARENT BOOLEAN;
18045      L_SERIAL_ENTERED_ON_PARENT BOOLEAN;
18046      L_RLS_PRIMARY_QUANTITY NUMBER;
18047 
18048      L_VALIDATION_STATUS VARCHAR2(1);
18049 
18050      --l_txn_src_type_id NUMBER; /*bug4187663*/
18051 
18052      l_inv_attributes_tbl           inv_lot_api_pub.char_tbl;
18053      l_c_attributes_tbl             inv_lot_api_pub.char_tbl;
18054      l_n_attributes_tbl             inv_lot_api_pub.number_tbl;
18055      l_d_attributes_tbl             inv_lot_api_pub.date_tbl;
18056 
18057      l_serial_attributes_tbl        inv_lot_sel_attr.lot_sel_attributes_tbl_type;
18058 
18059      l_inv_att_index NUMBER;
18060 
18061      l_parent_txn_type VARCHAR2(25);
18062      l_grand_parent_txn_id NUMBER;
18063 
18064      l_grand_parent_txn_type VARCHAR2(25);
18065      l_great_grand_parent_txn_id NUMBER;
18066 
18067      l_object_id NUMBER;
18068 
18069      l_dummy_lpn NUMBER;
18070 
18071      l_restrict_rcpt_ser VARCHAR2(1) := NVL(fnd_profile.value('INV_RESTRICT_RCPT_SER'),'2');
18072 
18073      L_DEBUG NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
18074      l_progress VARCHAR2(15) := '00';
18075 
18076      l_intransit_type NUMBER := 0;
18077 
18078      -- OPM related variables. bug# 3061052
18079      l_discrete_transaction	BOOLEAN := TRUE;
18080      l_opm_lot_ctl		NUMBER(5) := -1;
18081      ----l_opm_sublot_ctl		NUMBER(5) := -1;
18082      l_opm_item_id		NUMBER    := NULL ;
18083      l_item_no			VARCHAR2(32) ;
18084      l_opm_lot_id		NUMBER;
18085      /* INVCONV , added local variables. Punit Kumar */
18086      l_parent_lot_number            VARCHAR2(80);
18087      l_OE_ORDER_HEADER_ID           NUMBER      ;
18088      l_OE_ORDER_LINE_ID             NUMBER      ;
18089      l_rti_SECONDARY_QUANTITY       NUMBER      ;
18090      l_rti_PRIMARY_UNIT_OF_MEASURE  VARCHAR2(25);
18091      l_rti_UNIT_OF_MEASURE          VARCHAR2(25);
18092      l_rti_UOM_CODE                 VARCHAR2(3) ;
18093      l_rti_SECONDARY_UOM_CODE       VARCHAR2(3) ;
18094      l_mln_rec          mtl_lot_numbers%ROWTYPE ;
18095      l_sourcedoc_unit_of_measure    VARCHAR2(25);
18096      l_rti_SEC_UNIT_OF_MEASURE   VARCHAR2(25);
18097      /* end INVCONV */
18098 
18099      --R12: EPC requirements
18100      l_lpn_grp_id                   NUMBER;
18101      l_epc_column                   VARCHAR2(30);
18102      l_epc_value                    VARCHAR2(100);
18103      l_return_status                VARCHAR2(1);
18104      l_msg_data                     VARCHAR2(2000);
18105      --END R12
18106 
18107      l_last_transaction_id       mtl_material_transactions.transaction_id%type; --bug 5168883
18108      l_last_transaction_type_id  mtl_material_transactions.transaction_type_id%type; -- 5168883
18109 
18110   BEGIN
18111      X_RETURN_STATUS := G_RET_STS_SUCCESS;
18112 
18113      IF (l_debug = 1) THEN
18114 	print_debug('VALIDATE_LOT_SERIAL_INFO: RTI_ID =  : '|| P_RTI_ID , 1);
18115    /*INVCONV*/
18116    print_debug('INVCONV, removed sublot num and added soem more parameters',1);
18117    /*end , INVCONV*/
18118 
18119      END IF;
18120 
18121      L_RTI_ID := P_RTI_ID;
18122 
18123      l_progress := 'WMSINB-21949';
18124 
18125      --FIRST MOVE MTLI TO MTLT AND MSNI TO MSNT.
18126      MOVE_LOT_SERIAL_INFO(P_RTI_ID => L_RTI_ID,
18127 			  X_RETURN_STATUS => X_RETURN_STATUS,
18128 			  X_MSG_COUNT => X_MSG_COUNT,
18129 			  X_MSG_DATA => X_MSG_DATA);
18130      IF X_RETURN_STATUS <> 'S' THEN
18131 	-- RAIse error
18132 	l_progress := 'WMSINB-21958';
18133 	RAISE fnd_api.g_exc_error;
18134      END IF;
18135 
18136      IF (l_debug = 1) THEN
18137 	print_debug('VALIDATE_LOT_SERIAL_INFO: MOVE_LOT_SERIAL_INFO done :'||l_progress, 1);
18138 	l_progress := 'WMSINB-21964';
18139      END IF;
18140 
18141 
18142      -- QUERY RTI TO GET SOME BASIC INFORMATION FROM RTI
18143      BEGIN
18144 	SELECT TRANSACTION_TYPE
18145 	  , AUTO_TRANSACT_CODE
18146 	  , SOURCE_DOCUMENT_CODE
18147 	  , item_id
18148 	  , item_revision
18149 	  , LPN_ID
18150 	  , TRANSFER_LPN_ID
18151 	  , FROM_ORGANIZATION_ID
18152 	  , TO_ORGANIZATION_ID
18153 	  , SHIPMENT_LINE_ID
18154 	  , PARENT_TRANSACTION_ID
18155 	  , SUBINVENTORY
18156 	  , locator_id
18157 	  , routing_header_id
18158 	  , Nvl(primary_quantity, quantity)
18159 	  , quantity -- Bug# 4225766
18160 	  , shipment_header_id
18161 	  , destination_type_code
18162 	  , Nvl(mobile_txn, 'N')
18163 	  , inv_transaction_id
18164 	  , processing_mode_code
18165       /* INVCONV , added following , Punit Kumar */
18166      ,OE_ORDER_HEADER_ID
18167      ,OE_ORDER_LINE_ID
18168      ,SECONDARY_QUANTITY
18169      ,PRIMARY_UNIT_OF_MEASURE
18170      ,UOM_CODE
18171      ,SECONDARY_UOM_CODE
18172      ,SOURCE_DOC_UNIT_OF_MEASURE
18173      ,UNIT_OF_MEASURE
18174      ,SECONDARY_UNIT_OF_MEASURE
18175      /* end INVCONV */
18176      ,lpn_group_id
18177      INTO L_TRANSACTION_TYPE
18178 	  , L_AUTO_TRANSACT_CODE
18179 	  , L_SOURCE_DOCUMENT_CODE
18180 	  , l_item_id
18181 	  , l_item_revision
18182 	  , L_LPN_ID
18183 	  , L_TRANSFER_LPN_ID
18184 	  , L_FROM_ORG_ID
18185 	  , L_ORG_ID
18186 	  , L_SHIPMENT_LINE_ID
18187 	  , L_PARENT_TRANSACTION_ID
18188 	  , L_SUB_CODE
18189 	  , l_loc_id
18190 	  , l_routing_header_id
18191 	  , l_rti_primary_qty
18192 	  , l_rti_trans_qty -- Bug# 4225766
18193 	  , l_shipment_header_id
18194 	  , l_destination_type_code
18195 	  , l_mobile_txn
18196 	  , l_inv_txn_id
18197 	  , l_proc_mode_code
18198      /* INVCONV , added following , Punit Kumar */
18199      , l_OE_ORDER_HEADER_ID
18200      , l_OE_ORDER_LINE_ID
18201      , l_rti_SECONDARY_QUANTITY
18202      , l_rti_PRIMARY_UNIT_OF_MEASURE
18203      , l_rti_UOM_CODE
18204      , l_rti_SECONDARY_UOM_CODE
18205      , l_sourcedoc_unit_of_measure
18206      , l_rti_UNIT_OF_MEASURE
18207      , l_rti_SEC_UNIT_OF_MEASURE
18208      /* end INVCONV */
18209      , l_lpn_grp_id
18210 	  FROM RCV_TRANSACTIONS_INTERFACE
18211 	  WHERE INTERFACE_TRANSACTION_ID = L_RTI_ID;
18212 
18213 	IF l_shipment_line_id IS NOT NULL THEN
18214 	   -- THIS IS CHANGED TO TAKE INTO ACCOUNT ASN_TYPE
18215 	   --SELECT Nvl(asn_line_flag, 'N')
18216 	   --  INTO l_asn_line_flag
18217 	   --  FROM rcv_shipment_lines
18218 	   --  WHERE shipment_line_id = l_shipment_line_id;
18219 	   select decode(ASN_TYPE,'ASN','Y','N')
18220 	     into l_asn_line_flag
18221 	     from rcv_shipment_headers
18222 	     WHERE shipment_header_id =  l_shipment_header_id;
18223 	 ELSE
18224 	   l_asn_line_flag := 'N';
18225 	END IF;
18226      EXCEPTION
18227 	WHEN NO_DATA_FOUND THEN
18228 	   -- RAISE ERROR
18229 	   l_progress := 'WMSINB-22014';
18230 	   RAISE fnd_api.g_exc_error;
18231      END;
18232 
18233      IF (l_debug = 1) THEN
18234 	print_debug('VALIDATE_LOT_SERIAL_INFO: RTI query done :'||l_progress, 1);
18235 	print_debug('VALIDATE_LOT_SERIAL_INFO: TRANSACTION TYPE: '||l_transaction_type||': '||l_progress, 1);
18236 	l_progress := 'WMSINB-22021';
18237      END IF;
18238 
18239      -- If destination_type_Code is EXPENSE then lot/serial information is
18240      -- not required.
18241      IF (Nvl(l_destination_type_code, '@@@@@') IN ('EXPENSE','SHOP FLOOR')) THEN
18242 	IF (l_debug = 1) THEN
18243 	   print_debug('VALIDATE_LOT_SERIAL_INFO: Destination EXPENSE/SHOP FLOOR. Exiting...',1);
18244 	END IF;
18245 	RETURN;
18246      END IF;
18247 
18248      -- ONE TIME ITEMS CANNOT BE LOT/SERIAL CONTROLLED
18249      IF l_item_id IS NULL THEN
18250 	IF (l_debug = 1) THEN
18251 	   print_debug('VALIDATE_LOT_SERIAL_INFO: One Time Item. Exiting...',1);
18252 	END IF;
18253 	RETURN;
18254      END IF;
18255 
18256      --If the source document is 'REQ' then of the intransit_type in
18257      --mtl_interorg_parameters is set to 'Direct' then exit from this api.
18258      IF (l_source_document_code = 'REQ'
18259 	 AND l_mobile_txn = 'N'
18260 	 AND l_transaction_type = 'RECEIVE'
18261 	 AND l_inv_txn_id IS NOT NULL
18262 	 AND l_proc_mode_code = 'ONLINE') THEN
18263 	BEGIN
18264 	   SELECT intransit_type
18265 	     INTO l_intransit_type
18266 	     FROM mtl_interorg_parameters
18267 	     WHERE from_organization_id = l_from_org_id
18268 	     AND to_organization_id = l_org_id;
18269 
18270 	   IF (l_intransit_type = 1) THEN
18271 	      print_debug('VALIDATE_LOT_SERIAL_INFO: Direct Org Transfer ... Exitting...',1);
18272 	      RETURN;
18273 	   END IF;
18274 	EXCEPTION
18275 	   WHEN OTHERS THEN
18276 	      NULL;
18277 	END;
18278      END IF; --IF (l_source_document_code = 'REQ') THEN
18279 
18280      /*INVCONV, The code is forked for OPM specific logic.
18281        We shall remove this and merge OPM logic with discrete logic.
18282        Following OPM installation check  needs to be removed, Punit Kumar */
18283 
18284      /*   IF GML_PROCESS_FLAGS.opm_installed = 0 OR
18285           (gml_process_flags.check_process_orgn(p_organization_id =>l_org_id) = 0) THEN
18286    	l_discrete_transaction := TRUE;
18287          ELSE
18288    	l_discrete_transaction := FALSE; -- OPM transaction
18289         END IF;
18290 
18291      end, INVCONV */
18292 
18293      -- QUERY THE ITEM RECORD TO GET LOT/SERIAL CONTROLS FOR THE ITEM
18294 
18295      BEGIN
18296 
18297    /*INVCONV , OPM specific fork and discrete specific check need to be removed.
18298       Now there shall be one common logic for both.Punit Kumar*/
18299 
18300 	/* IF (l_discrete_transaction) THEN */
18301 
18302 	   SELECT LOT_CONTROL_CODE
18303 	     , SERIAL_NUMBER_CONTROL_CODE
18304         , lot_status_enabled --Bug 4066234
18305 	     INTO L_LOT_CONTROL_CODE
18306 	     , L_SERIAL_NUMBER_CONTROL_CODE
18307         , l_lot_status_enabled --Bug 4066234
18308 	     FROM MTL_SYSTEM_ITEMS
18309 	     WHERE INVENTORY_ITEM_ID = L_ITEM_ID
18310 	     AND ORGANIZATION_ID = L_ORG_ID;
18311     /*
18312 	 ELSE	--IF (l_discrete_transaction) THEN
18313 	   /** OPM change  bug# 3061052
18314          select iim.lot_ctl,iim.sublot_ctl,iim.item_id,iim.item_no
18315 	     into l_opm_lot_ctl,l_opm_sublot_ctl,l_opm_item_id,l_item_no
18316 	     from mtl_system_items msi , ic_item_mst iim
18317 	     where msi.inventory_item_id = l_item_id
18318 	     and   msi.organization_id = l_org_id
18319 	     and   msi.segment1 = iim.item_no ;
18320 
18321 	END IF; --IF (l_discrete_transaction) THEN
18322 	end , INVCONV **/
18323 
18324      EXCEPTION
18325 	WHEN NO_DATA_FOUND THEN
18326 	   --RAISE ERROR
18327 	   l_progress := 'WMSINB-22070';
18328 	   RAISE fnd_api.g_exc_error;
18329      END;
18330 
18331      IF (l_debug = 1) THEN
18332 	print_debug('VALIDATE_LOT_SERIAL_INFO: MTL_SYSTEM_ITEMS query done :'||l_progress, 1);
18333    print_debug('INVCONV, Removing OPM specific fork :'||l_progress,1);
18334    --Bug 4066234
18335    print_debug('VALIDATE_LOT_SERIAL_INFO: Lot Control Code:'||l_lot_control_code,1);
18336    print_debug('VALIDATE_LOT_SERIAL_INFO: Serial Number Control Code:'||l_serial_number_control_code,1);
18337    print_debug('VALIDATE_LOT_SERIAL_INFO: Lot Status Enabled:'||l_lot_status_enabled,1);
18338 	l_progress := 'WMSINB-22076';
18339      END IF;
18340 
18341      -- if item is not lot controlled, then transaction should fail
18342      -- if the MTLT has been created for the transaction
18343      IF (l_lot_control_code = 1) THEN
18344 	BEGIN
18345 	   SELECT '1'
18346 	     INTO l_dummy
18347 	     FROM dual
18348 	     WHERE exists (SELECT 1
18349 			   FROM mtl_transaction_lots_temp
18350 			   WHERE product_code = 'RCV'
18351 			   AND product_transaction_id = l_rti_id);
18352 
18353 	   --Fail transaction
18354 	   IF (l_debug = 1) THEN
18355 	      print_debug('VALIDATE_LOT_SERIAL_INFO: MTLT exists for non-lot item: '||l_progress, 1);
18356 	   END IF;
18357 
18358 	   l_progress := 'WMSINB-22080';
18359 	   RAISE fnd_api.g_exc_error;
18360 
18361 	EXCEPTION
18362 	   WHEN no_data_found THEN
18363 	      NULL;
18364 	END;
18365      END IF; --IF (l_lot_control_code = 1) THEN
18366 
18367      -- if item is not serial controlled, then transaction should fail
18368      -- if the MSNT has been created for the transaction
18369      IF (l_serial_number_control_code = 1) THEN
18370 	BEGIN
18371 	   SELECT '1'
18372 	     INTO l_dummy
18373 	     FROM dual
18374 	     WHERE exists (SELECT 1
18375 			   FROM mtl_serial_numbers_temp
18376 			   WHERE product_code = 'RCV'
18377 			   AND product_transaction_id = l_rti_id);
18378 
18379 	   --Fail transaction
18380 	   IF (l_debug = 1) THEN
18381 	      print_debug('VALIDATE_LOT_SERIAL_INFO: MSNI exists for non-serial item: '||l_progress, 1);
18382 	   END IF;
18383 
18384 	   l_progress := 'WMSINB-22082';
18385 	   RAISE fnd_api.g_exc_error;
18386 
18387 	EXCEPTION
18388 	   WHEN no_data_found THEN
18389 	      NULL;
18390 	END;
18391      END IF; --IF (l_serial_number_control_code = 1) THEN
18392 
18393      -- FIRST VALIDATE FOR RECEIVE, ACCEPT, REJECT, TRANSFER AND DELIVER
18394      -- TRANSACTIONS
18395      IF (l_transaction_type IN ('RECEIVE','ACCEPT','REJECT','TRANSFER','DELIVER')) THEN
18396 	-- CHECK TO SEE IF THE ITEM IS LOT CONTROLLED OR NOT
18397 	-- opm change added l_opm_lot_ctl bug# 3061052
18398 
18399    /* INVCONV ,OPM specific separate check needs to be removed. Punit Kumar*/
18400    IF (L_LOT_CONTROL_CODE = 2 /*OR l_opm_lot_ctl = 1 */) THEN
18401    /* end INVCONV */
18402 
18403 	   IF (l_debug = 1) THEN
18404 	      print_debug('VALIDATE_LOT_SERIAL_INFO: Lot Controlled :'||l_progress, 1);
18405 	      l_progress := 'WMSINB-22087';
18406 	   END IF;
18407 
18408 	   L_NUM_MTLT_RECS := 0;
18409 	   l_tot_mtlt_prim_qty := 0;
18410 	   l_tot_mtlt_trans_qty := 0; -- Bug# 4225766
18411 
18412 	   OPEN C_MTLT(L_RTI_ID);
18413 
18414 	   LOOP
18415 	      FETCH C_MTLT INTO L_MTLT_REC;
18416 	      EXIT WHEN C_MTLT%NOTFOUND;
18417 
18418          /* INVCONV , get L_MTLT_REC values into l_mln_rec which shall be passed to INV_NEW_LOT
18419             for new lot creation */
18420 
18421          	   l_mln_rec.LOT_NUMBER                := L_MTLT_REC.LOT_NUMBER                    ;
18422                l_mln_rec.LAST_UPDATE_DATE          := SYSDATE                                  ;
18423                l_mln_rec.LAST_UPDATED_BY           := L_MTLT_REC.LAST_UPDATED_BY               ;
18424                l_mln_rec.CREATION_DATE             := SYSDATE                                  ;
18425                l_mln_rec.CREATED_BY                := L_MTLT_REC.CREATED_BY                    ;
18426                l_mln_rec.LAST_UPDATE_LOGIN         := L_MTLT_REC.LAST_UPDATE_LOGIN             ;
18427                l_mln_rec.EXPIRATION_DATE           := L_MTLT_REC.LOT_EXPIRATION_DATE           ;
18428                l_mln_rec.ATTRIBUTE_CATEGORY        := L_MTLT_REC.ATTRIBUTE_CATEGORY            ;
18429                l_mln_rec.ATTRIBUTE1                := L_MTLT_REC.ATTRIBUTE1                    ;
18430                l_mln_rec.ATTRIBUTE2                := L_MTLT_REC.ATTRIBUTE2                    ;
18431                l_mln_rec.ATTRIBUTE3                := L_MTLT_REC.ATTRIBUTE3                    ;
18432                l_mln_rec.ATTRIBUTE4                := L_MTLT_REC.ATTRIBUTE4                    ;
18433                l_mln_rec.ATTRIBUTE5                := L_MTLT_REC.ATTRIBUTE5                    ;
18434                l_mln_rec.ATTRIBUTE6                := L_MTLT_REC.ATTRIBUTE6                    ;
18435                l_mln_rec.ATTRIBUTE7                := L_MTLT_REC.ATTRIBUTE7                    ;
18436                l_mln_rec.ATTRIBUTE8                := L_MTLT_REC.ATTRIBUTE8                    ;
18437                l_mln_rec.ATTRIBUTE9                := L_MTLT_REC.ATTRIBUTE9                    ;
18438                l_mln_rec.ATTRIBUTE10               := L_MTLT_REC.ATTRIBUTE10                   ;
18439                l_mln_rec.ATTRIBUTE11               := L_MTLT_REC.ATTRIBUTE11                   ;
18440                l_mln_rec.ATTRIBUTE12               := L_MTLT_REC.ATTRIBUTE12                   ;
18441                l_mln_rec.ATTRIBUTE13               := L_MTLT_REC.ATTRIBUTE13                   ;
18442                l_mln_rec.ATTRIBUTE14               := L_MTLT_REC.ATTRIBUTE14                   ;
18443                l_mln_rec.ATTRIBUTE15               := L_MTLT_REC.ATTRIBUTE15                   ;
18444                l_mln_rec.REQUEST_ID                := L_MTLT_REC.REQUEST_ID                    ;
18445                l_mln_rec.PROGRAM_APPLICATION_ID    := L_MTLT_REC.PROGRAM_APPLICATION_ID        ;
18446                l_mln_rec.PROGRAM_ID                := L_MTLT_REC.PROGRAM_ID                    ;
18447                l_mln_rec.PROGRAM_UPDATE_DATE       := L_MTLT_REC.PROGRAM_UPDATE_DATE           ;
18448                l_mln_rec.DESCRIPTION               := L_MTLT_REC.DESCRIPTION                   ;
18449                l_mln_rec.VENDOR_NAME               := L_MTLT_REC.VENDOR_NAME                   ;
18450                l_mln_rec.SUPPLIER_LOT_NUMBER       := L_MTLT_REC.SUPPLIER_LOT_NUMBER           ;
18451                l_mln_rec.GRADE_CODE                := L_MTLT_REC.GRADE_CODE                    ;
18452                l_mln_rec.ORIGINATION_DATE          := L_MTLT_REC.ORIGINATION_DATE              ;
18453                l_mln_rec.DATE_CODE                 := L_MTLT_REC.DATE_CODE                     ;
18454                l_mln_rec.STATUS_ID                 := L_MTLT_REC.STATUS_ID                     ;
18455                l_mln_rec.CHANGE_DATE               := L_MTLT_REC.CHANGE_DATE                   ;
18456                l_mln_rec.AGE                       := L_MTLT_REC.AGE                           ;
18457                l_mln_rec.RETEST_DATE               := L_MTLT_REC.RETEST_DATE                   ;
18458                l_mln_rec.MATURITY_DATE             := L_MTLT_REC.MATURITY_DATE                 ;
18459                l_mln_rec.LOT_ATTRIBUTE_CATEGORY    := L_MTLT_REC.LOT_ATTRIBUTE_CATEGORY        ;
18460                l_mln_rec.ITEM_SIZE                 := L_MTLT_REC.ITEM_SIZE                     ;
18461                l_mln_rec.COLOR                     := L_MTLT_REC.COLOR                         ;
18462                l_mln_rec.VOLUME                    := L_MTLT_REC.VOLUME                        ;
18463                l_mln_rec.VOLUME_UOM                := L_MTLT_REC.VOLUME_UOM                    ;
18464                l_mln_rec.PLACE_OF_ORIGIN           := L_MTLT_REC.PLACE_OF_ORIGIN               ;
18465                l_mln_rec.BEST_BY_DATE              := L_MTLT_REC.BEST_BY_DATE                  ;
18466                l_mln_rec.LENGTH                    := L_MTLT_REC.LENGTH                        ;
18467                l_mln_rec.LENGTH_UOM                := L_MTLT_REC.LENGTH_UOM                    ;
18468                l_mln_rec.RECYCLED_CONTENT          := L_MTLT_REC.RECYCLED_CONTENT              ;
18469                l_mln_rec.THICKNESS                 := L_MTLT_REC.THICKNESS                     ;
18470                l_mln_rec.THICKNESS_UOM             := L_MTLT_REC.THICKNESS_UOM                 ;
18471                l_mln_rec.WIDTH                     := L_MTLT_REC.WIDTH                         ;
18472                l_mln_rec.WIDTH_UOM                 := L_MTLT_REC.WIDTH_UOM                     ;
18473                l_mln_rec.CURL_WRINKLE_FOLD         := L_MTLT_REC.CURL_WRINKLE_FOLD             ;
18474                l_mln_rec.C_ATTRIBUTE1              := L_MTLT_REC.C_ATTRIBUTE1                  ;
18475                l_mln_rec.C_ATTRIBUTE2              := L_MTLT_REC.C_ATTRIBUTE2                  ;
18476                l_mln_rec.C_ATTRIBUTE3              := L_MTLT_REC.C_ATTRIBUTE3                  ;
18477                l_mln_rec.C_ATTRIBUTE4              := L_MTLT_REC.C_ATTRIBUTE4                  ;
18478                l_mln_rec.C_ATTRIBUTE5              := L_MTLT_REC.C_ATTRIBUTE5                  ;
18479                l_mln_rec.C_ATTRIBUTE6              := L_MTLT_REC.C_ATTRIBUTE6                  ;
18480                l_mln_rec.C_ATTRIBUTE7              := L_MTLT_REC.C_ATTRIBUTE7                  ;
18481                l_mln_rec.C_ATTRIBUTE8              := L_MTLT_REC.C_ATTRIBUTE8                  ;
18482                l_mln_rec.C_ATTRIBUTE9              := L_MTLT_REC.C_ATTRIBUTE9                  ;
18483                l_mln_rec.C_ATTRIBUTE10             := L_MTLT_REC.C_ATTRIBUTE10                 ;
18484                l_mln_rec.C_ATTRIBUTE11             := L_MTLT_REC.C_ATTRIBUTE11                 ;
18485                l_mln_rec.C_ATTRIBUTE12             := L_MTLT_REC.C_ATTRIBUTE12                 ;
18486                l_mln_rec.C_ATTRIBUTE13             := L_MTLT_REC.C_ATTRIBUTE13                 ;
18487                l_mln_rec.C_ATTRIBUTE14             := L_MTLT_REC.C_ATTRIBUTE14                 ;
18488                l_mln_rec.C_ATTRIBUTE15             := L_MTLT_REC.C_ATTRIBUTE15                 ;
18489                l_mln_rec.C_ATTRIBUTE16             := L_MTLT_REC.C_ATTRIBUTE16                 ;
18490                l_mln_rec.C_ATTRIBUTE17             := L_MTLT_REC.C_ATTRIBUTE17                 ;
18491                l_mln_rec.C_ATTRIBUTE18             := L_MTLT_REC.C_ATTRIBUTE18                 ;
18492                l_mln_rec.C_ATTRIBUTE19             := L_MTLT_REC.C_ATTRIBUTE19                 ;
18493                l_mln_rec.C_ATTRIBUTE20             := L_MTLT_REC.C_ATTRIBUTE20                 ;
18494                l_mln_rec.D_ATTRIBUTE1              := L_MTLT_REC.D_ATTRIBUTE1                  ;
18495                l_mln_rec.D_ATTRIBUTE2              := L_MTLT_REC.D_ATTRIBUTE2                  ;
18496                l_mln_rec.D_ATTRIBUTE3              := L_MTLT_REC.D_ATTRIBUTE3                  ;
18497                l_mln_rec.D_ATTRIBUTE4              := L_MTLT_REC.D_ATTRIBUTE4                  ;
18498                l_mln_rec.D_ATTRIBUTE5              := L_MTLT_REC.D_ATTRIBUTE5                  ;
18499                l_mln_rec.D_ATTRIBUTE6              := L_MTLT_REC.D_ATTRIBUTE6                  ;
18500                l_mln_rec.D_ATTRIBUTE7              := L_MTLT_REC.D_ATTRIBUTE7                  ;
18501                l_mln_rec.D_ATTRIBUTE8              := L_MTLT_REC.D_ATTRIBUTE8                  ;
18502                l_mln_rec.D_ATTRIBUTE9              := L_MTLT_REC.D_ATTRIBUTE9                  ;
18503                l_mln_rec.D_ATTRIBUTE10             := L_MTLT_REC.D_ATTRIBUTE10                 ;
18504                l_mln_rec.N_ATTRIBUTE1              := L_MTLT_REC.N_ATTRIBUTE1                  ;
18505                l_mln_rec.N_ATTRIBUTE2              := L_MTLT_REC.N_ATTRIBUTE2                  ;
18506                l_mln_rec.N_ATTRIBUTE3              := L_MTLT_REC.N_ATTRIBUTE3                  ;
18507                l_mln_rec.N_ATTRIBUTE4              := L_MTLT_REC.N_ATTRIBUTE4                  ;
18508                l_mln_rec.N_ATTRIBUTE5              := L_MTLT_REC.N_ATTRIBUTE5                  ;
18509                l_mln_rec.N_ATTRIBUTE6              := L_MTLT_REC.N_ATTRIBUTE6                  ;
18510                l_mln_rec.N_ATTRIBUTE7              := L_MTLT_REC.N_ATTRIBUTE7                  ;
18511                l_mln_rec.N_ATTRIBUTE8              := L_MTLT_REC.N_ATTRIBUTE8                  ;
18512                l_mln_rec.N_ATTRIBUTE9              := L_MTLT_REC.N_ATTRIBUTE9                  ;
18513                l_mln_rec.N_ATTRIBUTE10             := L_MTLT_REC.N_ATTRIBUTE10                 ;
18514                l_mln_rec.VENDOR_ID                 := L_MTLT_REC.VENDOR_ID                     ;
18515                l_mln_rec.TERRITORY_CODE            := L_MTLT_REC.TERRITORY_CODE                ;
18516                l_mln_rec.PARENT_LOT_NUMBER         := L_MTLT_REC.PARENT_LOT_NUMBER             ;
18517                l_mln_rec.ORIGINATION_TYPE          := L_MTLT_REC.ORIGINATION_TYPE              ;
18518                l_mln_rec.EXPIRATION_ACTION_DATE    := L_MTLT_REC.EXPIRATION_ACTION_DATE        ;
18519                l_mln_rec.EXPIRATION_ACTION_CODE    := L_MTLT_REC.EXPIRATION_ACTION_CODE        ;
18520                l_mln_rec.HOLD_DATE                 := L_MTLT_REC.HOLD_DATE                     ;
18521 
18522          /*end , INVCONV*/
18523 
18524 	      L_NUM_MTLT_RECS := L_NUM_MTLT_RECS + 1;
18525 	      l_tot_mtlt_prim_qty := l_tot_mtlt_prim_qty + l_mtlt_rec.primary_quantity;
18526 	      l_tot_mtlt_trans_qty := l_tot_mtlt_trans_qty + l_mtlt_rec.transaction_quantity; -- Bug# 4225766
18527 
18528 	      IF (l_debug = 1) THEN
18529 		    print_debug('VALIDATE_LOT_SERIAL_INFO: LOT NUMBER: '||l_mtlt_rec.lot_number||': '||l_progress, 1);
18530            /*INVCONV */
18531             /*
18532             print_debug('VALIDATE_LOT_SERIAL_INFO: SUBLOT NUMBER: '||l_mtlt_rec.sublot_num||': '||l_progress, 1);
18533             */
18534             print_debug('Assigning values fetched from MTLT to l_mln_rec'||l_progress,1);
18535             /*end , INVCONV */
18536 		      print_debug('VALIDATE_LOT_SERIAL_INFO: LOT PRIMARY QUANTITY: '||l_mtlt_rec.primary_quantity||': '||l_progress, 1);
18537 		      l_progress := 'WMSINB-22106';
18538 	      END IF;
18539 
18540        /*INVCONV, Check whether Lot is existing or it's a new Lot .
18541          If it exists then we shall validate its parent lot also.
18542          Remove OPM fork.Add parent_lot_number in discrete query.Punit Kumar*/
18543 
18544 	      BEGIN
18545 		/* IF (l_discrete_transaction) THEN		 */
18546 
18547 		    SELECT 1,parent_lot_number
18548 		      INTO L_LOT_EXISTS ,l_parent_lot_number
18549 		      FROM MTL_LOT_NUMBERS
18550 		      WHERE ORGANIZATION_ID = L_ORG_ID
18551 		      AND   INVENTORY_ITEM_ID = L_ITEM_ID
18552 		      AND LOT_NUMBER = Ltrim(Rtrim(L_MTLT_REC.lot_number));
18553 
18554 		 /* ELSE -- opm change bug# 3061052 --IF (l_discrete_transaction) THEN
18555 		    IF  Ltrim(Rtrim(L_MTLT_REC.sublot_num)) IS NOT NULL THEN
18556 		       SELECT 1, LOT_ID
18557 			 INTO L_LOT_EXISTS , l_opm_lot_id
18558 			 FROM IC_LOTS_MST
18559 			 WHERE ITEM_ID = l_opm_item_id
18560 			 AND LOT_NO = Ltrim(Rtrim(L_MTLT_REC.lot_number))
18561 			 AND SUBLOT_NO = Ltrim(Rtrim(L_MTLT_REC.sublot_num)) ;
18562 		     ELSE
18563 		       SELECT 1 , LOT_ID
18564 			 INTO L_LOT_EXISTS , l_opm_lot_id
18565 			 FROM IC_LOTS_MST
18566 			 WHERE ITEM_ID = l_opm_item_id
18567 			 AND LOT_NO = Ltrim(Rtrim(L_MTLT_REC.lot_number))
18568 			 AND SUBLOT_NO IS NULL ;
18569 		    END IF;
18570 		 END IF; --IF (l_discrete_transaction) THEN
18571 
18572 		end , INVCONV */
18573 
18574           EXCEPTION
18575 		 WHEN NO_DATA_FOUND THEN
18576 		    L_LOT_EXISTS := 0;
18577 	      END;
18578 
18579 	      IF (l_debug = 1) THEN
18580 		 print_debug('VALIDATE_LOT_SERIAL_INFO: LOT EXISTS: '||l_lot_exists||' : '||l_progress, 1);
18581 		 l_progress := 'WMSINB-22143';
18582          print_debug('INVCONV, Removing OPM specific fork and selecting parent lot number :'||l_progress||':'||l_parent_lot_number,1);
18583 	      END IF;
18584 
18585 	      IF L_LOT_EXISTS = 1 THEN
18586 
18587        /*INVCONV , validating for parent lot, Punit Kumar */
18588             IF  L_MTLT_REC.parent_lot_number IS NOT NULL THEN
18589                IF L_MTLT_REC.parent_lot_number <> l_parent_lot_number THEN
18590                   fnd_message.set_name ('INV' , 'INV_CL_PARENT_INVALID' );
18591 					   fnd_msg_pub.ADD;
18592 					   l_progress := 'WMSINB-22145';
18593 					   RAISE fnd_api.g_exc_error;
18594                END IF;
18595             ELSE
18596                L_MTLT_REC.parent_lot_number := l_parent_lot_number;
18597             END IF;
18598             /*end , INVCONV */
18599 
18600 		 IF (L_TRANSACTION_TYPE <> 'RECEIVE') THEN
18601 		    L_LOT_ENTERED_ON_PARENT := LOT_ENTERED_ON_PARENT(L_PARENT_TRANSACTION_ID);
18602 		  ELSE
18603 		    L_LOT_ENTERED_ON_PARENT := FALSE;
18604 		 END IF;
18605 
18606 		 IF (l_debug = 1) THEN
18607 		    print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||L_SOURCE_DOCUMENT_CODE||' : '||l_progress, 1);
18608           print_debug('INVCONV, validating for parent lot :'||l_progress,1);
18609 		    l_progress := 'WMSINB-22155';
18610 		 END IF;
18611 
18612 		 IF NOT L_LOT_ENTERED_ON_PARENT THEN
18613           --Validate the lot number and primary quantity for the source org.
18614 		    IF (l_debug = 1) THEN
18615 		       print_debug('VALIDATE_LOT_SERIAL_INFO: LOT NOT ENTERED ON PARENT: '||l_progress, 1);
18616 		       l_progress := 'WMSINB-22161';
18617 		    END IF;
18618 
18619            /* INVCONV , Existing discrete validations. Same will be executed for process org also. Punit Kumar */
18620 		    /*IF (l_discrete_transaction) THEN */
18621 		    /* end ,INVCONV */
18622 
18623 		       IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY', 'REQ')) THEN
18624 			  -- GET THE LOT/SERIAL CONTROL IN SOURCE ORG
18625 			  GET_SERIAL_LOT_CTRL_IN_SRC_ORG
18626 			    (L_SHIPMENT_LINE_ID, L_ORG_ID,
18627 			     L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL, l_from_org_rev_ctrl,
18628 			     X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
18629 
18630 			  IF (l_debug = 1) THEN
18631 			     print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CONTROL FROM ORG: '||L_FROM_ORG_LOT_CTRL||' : '||l_progress, 1);
18632 			     l_progress := 'WMSINB-22175';
18633 			  END IF;
18634 
18635 			  IF (L_FROM_ORG_LOT_CTRL = 2) THEN
18636 			     BEGIN
18637 		/** Bug:5489462
18638 		 *      If a lot number doesn't belong to that shipment line is entered through ROI,
18639 		 *      L_RLS_PRIMARY_QUANTITY will be loaded with null value and the 'if' condition
18640 		 *      to check the quanity entered in mtlt record exceeds the supply quantity won't
18641 		 *      raise the exception, as the comparision is made against a null value.
18642 		 *      So, added nvl for the SUM(rls.primary_quantity).
18643 		 */
18644 				SELECT nvl(SUM(rls.primary_quantity),0)--Bug:5489462
18645 				  INTO L_RLS_PRIMARY_QUANTITY
18646 				  FROM rcv_lots_supply rls
18647 				  , rcv_shipment_lines rsl
18648 				  WHERE rsl.SHIPMENT_LINE_ID = rls.SHIPMENT_LINE_ID
18649 				  AND rsl.shipment_header_id = l_shipment_header_id
18650 				  AND rsl.item_id = l_item_id
18651 				  AND rls.SUPPLY_TYPE_CODE = 'SHIPMENT'
18652 				  AND rls.LOT_NUM = Ltrim(Rtrim(L_MTLT_REC.lot_number));
18653 
18654 				IF (L_MTLT_REC.PRIMARY_QUANTITY >
18655 				    L_RLS_PRIMARY_QUANTITY) THEN
18656 				   --RAISE ERROR
18657 				   l_progress := 'WMSINB-22192';
18658 				   RAISE fnd_api.g_exc_error;
18659 				END IF;
18660 			     EXCEPTION
18661 				WHEN NO_DATA_FOUND THEN
18662 				   --RAISE ERROR
18663 				   l_progress := 'WMSINB-22198';
18664 				   RAISE fnd_api.g_exc_error;
18665 			     END;
18666 			  END IF; --IF (L_FROM_ORG_LOT_CTRL = 2) THEN
18667 
18668 		       END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY', 'REQ')) THEN
18669 
18670 		       -- PERFORM MATERIAL_STATUS CHECK
18671 		       -- if deliver or direct receipt
18672 		       IF (l_transaction_type = 'DELIVER' OR l_auto_transact_code = 'DELIVER') THEN
18673 			  IF (l_source_document_code = 'PO') THEN
18674 			     l_transaction_type_id := 18;
18675 			   ELSIF (l_source_document_code = 'RMA') THEN
18676 			     l_transaction_type_id := 15;
18677 			   ELSE
18678 			     l_transaction_type_id := 61;
18679 			  END IF;
18680 
18681            /*INVCONV, adding a debug message , Punit Kumar*/
18682 
18683 			  IF (l_debug = 1) THEN
18684 			     print_debug('transaction type id in validate_lot_serial_info is : '||l_transaction_type_id||' : '||l_progress, 1);
18685            END IF;
18686 
18687            /*end , INVCONV */
18688 
18689 			  INV_LOT_TRX_VALIDATION_PUB.VALIDATE_MATERIAL_STATUS(X_RETURN_STATUS => X_RETURN_STATUS,
18690 									      X_MSG_COUNT => X_MSG_COUNT,
18691 									      X_MSG_DATA => X_MSG_DATA,
18692 									      X_VALIDATION_STATUS => L_VALIDATION_STATUS,
18693 									      P_TRANSACTION_TYPE_ID => l_transaction_type_id,
18694 									      P_ORGANIZATION_ID => L_ORG_ID,
18695 									      P_INVENTORY_ITEM_ID => L_ITEM_ID,
18696 									      P_LOT_NUMBER => L_MTLT_REC.LOT_NUMBER,
18697 									      P_SUBINVENTORY_CODE => L_SUB_CODE,
18698 									      P_LOCATOR_ID => L_LOC_ID,
18699 									      P_STATUS_ID => NULL);
18700 			  IF X_RETURN_STATUS <> 'S' THEN
18701 			     --RAISE ERROR
18702 			     l_progress := 'WMSINB-22225';
18703 			     RAISE fnd_api.g_exc_error;
18704 			  END IF;
18705 
18706 			  IF (l_debug = 1) THEN
18707 			     print_debug('VALIDATE_LOT_SERIAL_INFO: LOT MATERIAL VALIDATION STATUS: '||L_VALIDATION_STATUS||' : '||l_progress, 1);
18708 			     l_progress := 'WMSINB-22231';
18709 			  END IF;
18710 
18711 			  IF L_VALIDATION_STATUS <> 'Y' THEN
18712 			     --RAISE ERROR
18713 			     l_progress := 'WMSINB-22236';
18714 			     RAISE fnd_api.g_exc_error;
18715 			  END IF;
18716 		       END IF; --IF (l_transaction_type = 'DELIVER' OR l_auto_transact_code = 'DELIVER') THEN
18717 
18718              /*INVCONV , Instead of calling OPM specific API gml_opm_roi_grp.validate_opm_lot,
18719                 we shall now call a new procedure INV_ROI_INTEGRATION_GRP. INV_VALIDATE_LOT.
18720                 This new procedure shall  validate the extra process attributes
18721                 that are being merged for discrete items too.
18722                 Punit Kumar */
18723              /*
18724 		     ELSE --IF (l_discrete_transaction) THEN
18725 			  -- opm change bug# 3061052
18726 			  gml_opm_roi_grp.validate_opm_lot(p_api_version	 	=> 1.0,
18727 							   p_init_msg_lst	 	=> FND_API.G_FALSE,
18728 							   p_mtlt_rowid		=> l_mtlt_rec.rowid,
18729 							   p_new_lot	 	=> 'N',
18730 							   p_opm_item_id		=> l_opm_item_id,
18731 							   p_item_no		=> l_item_no,
18732 							   p_lots_specified_on_parent => 'N',
18733 							   p_lot_id		=> l_opm_lot_id,
18734 							   x_return_status 	=> x_return_status,
18735 							   x_msg_data      	=> x_msg_data,
18736 							   x_msg_count     	=> x_msg_count
18737 							   );
18738             */
18739 
18740            IF (l_debug = 1) THEN
18741               print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
18742               print_debug('transaction type id before calling in validate_lot_serial_info is : '||l_transaction_type_id||' : '||l_progress, 1);
18743            END IF;
18744 
18745 
18746 
18747 
18748             INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
18749                                                        x_return_status      		   => x_return_status
18750                                                       ,x_msg_data           		   => x_msg_data
18751                                                       ,x_msg_count          		   => x_msg_count
18752                                                       ,p_api_version	               => 1.0
18753                                                       ,p_init_msg_lst	            => FND_API.G_FALSE
18754                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
18755                                                       ,p_transaction_type_id 	      => l_transaction_type_id
18756                                                       ,p_new_lot			            => 'N'
18757                                                       ,p_item_id	 		            => l_item_id
18758                                                       ,p_to_organization_id		   => L_ORG_ID
18759                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
18760                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
18761                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
18762                                                       ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
18763                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
18764                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
18765                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
18766                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
18767                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
18768                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
18769                                                       ,p_rti_id	                  => L_RTI_ID
18770                                                       ,p_revision             	   => l_item_revision
18771                                                       ,p_subinventory_code  	      => L_SUB_CODE
18772                                                       ,p_locator_id           	   => l_loc_id
18773                                                       ,p_transaction_type           => l_transaction_type
18774                                                       ,p_parent_txn_type            => l_parent_txn_type
18775                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
18776                                                       );
18777             IF (l_debug = 1) THEN
18778                print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
18779             END IF;
18780             /* end , INVCONV */
18781 
18782 
18783 			  IF X_RETURN_STATUS <> 'S' THEN
18784 			     --RAISE ERROR
18785 			     l_progress := 'WMSINB-22256';
18786 			     RAISE fnd_api.g_exc_error;
18787 			  END IF;
18788 
18789            /*INVCONV , Changed the debug message*/
18790 			  IF (l_debug = 1) THEN
18791 			     /*print_debug('VALIDATE_LOT_SERIAL_INFO: VALIDATE_OPM_LOT STATUS: '||x_return_status||' : '||l_progress, 1);*/
18792               print_debug('INVCONV, VALIDATE_LOT_SERIAL_INFO: VALIDATE_LOT STATUS,x_return_status is : '||x_return_status||' : '||l_progress, 1);
18793 			     l_progress := 'WMSINB-22262';
18794 			  END IF;
18795 
18796 		    /* END IF; -- IF (l_discrete_transaction) THEN */
18797 		   /*end , INVCONV*/
18798 
18799 		  ELSE --IF NOT L_LOT_ENTERED_ON_PARENT THEN
18800 		       -- LOT WAS ENTERERED ON THE PARENT SO USER CANNOT ENTER
18801 		       -- ANY OTHER LOT HERE
18802 		       BEGIN
18803 
18804   -- INVCONV , Remove sublot_num. Punit Kumar
18805 
18806 			  SELECT primary_quantity
18807 			    INTO l_rls_primary_quantity
18808 			    FROM rcv_lots_supply
18809 			    WHERE transaction_id = l_parent_transaction_id
18810 			    AND lot_num = Ltrim(Rtrim(l_mtlt_rec.lot_number)) ;
18811            /*
18812 			    AND ((sublot_num IS NULL and Ltrim(Rtrim(l_mtlt_rec.sublot_num)) IS NULL)
18813 				 OR (sublot_num = Ltrim(Rtrim(l_mtlt_rec.sublot_num)))) ;
18814 			  */
18815 			    IF (l_mtlt_rec.primary_quantity >
18816 				l_rls_primary_quantity) THEN
18817 			       --raise error
18818 			       l_progress := 'WMSINB-22284';
18819 			       RAISE fnd_api.g_exc_error;
18820 			    END IF;
18821 		       EXCEPTION
18822 			  WHEN no_data_found THEN
18823 			     --raise error
18824 			     l_progress := 'WMSINB-22290';
18825 			     RAISE fnd_api.g_exc_error;
18826 		       END;
18827 
18828              /*INVCONV , Removing the process specific call. Shall call a new procedure INV_VALIDATE_LOT
18829                in Package INV_ROI_INTEGRATION_GRP to perform the same set of validations for all.
18830                Punit Kumar*/
18831              /*
18832 		       -- opm change bug# 3061052
18833 		       IF (NOT l_discrete_transaction) THEN
18834 			  gml_opm_roi_grp.validate_opm_lot(p_api_version	 	=> 1.0,
18835 							   p_init_msg_lst	 	=> FND_API.G_FALSE,
18836 							   p_mtlt_rowid		=> l_mtlt_rec.rowid,
18837 							   p_new_lot	 	=> 'N',
18838 							   p_opm_item_id		=> l_opm_item_id,
18839 							   p_item_no		=> l_item_no,
18840 							   p_lots_specified_on_parent => 'Y',
18841 							   p_lot_id		=> l_opm_lot_id,
18842 							   x_return_status 	=> x_return_status,
18843 							   x_msg_data      	=> x_msg_data,
18844 							   x_msg_count     	=> x_msg_count
18845 							   );
18846 
18847             */
18848              IF (l_debug = 1) THEN
18849              print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
18850              END IF;
18851 
18852              INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
18853                                                        x_return_status      		   => x_return_status
18854                                                       ,x_msg_data           		   => x_msg_data
18855                                                       ,x_msg_count          		   => x_msg_count
18856                                                       ,p_api_version	               => 1.0
18857                                                       ,p_init_msg_lst	            => FND_API.G_FALSE
18858                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
18859                                                       ,p_transaction_type_id 	      => l_transaction_type_id
18860                                                       ,p_new_lot			            => 'N'
18861                                                       ,p_item_id	 		            => l_item_id
18862                                                       ,p_to_organization_id		   => L_ORG_ID
18863                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
18864                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
18865                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
18866                                                       ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
18867                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
18868                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
18869                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
18870                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
18871                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
18872                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
18873                                                       ,p_rti_id	                  => L_RTI_ID
18874                                                       ,p_revision             	   => l_item_revision
18875                                                       ,p_subinventory_code  	      => L_SUB_CODE
18876                                                       ,p_locator_id           	   => l_loc_id
18877                                                       ,p_transaction_type           => l_transaction_type
18878                                                       ,p_parent_txn_type            => l_parent_txn_type
18879                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
18880                                                       );
18881 
18882            IF (l_debug = 1) THEN
18883            print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
18884            END IF;
18885 
18886 			  IF X_RETURN_STATUS <> 'S' THEN
18887 			     --RAISE ERROR
18888 			     l_progress := 'WMSINB-22310';
18889 			     RAISE fnd_api.g_exc_error;
18890 			  END IF;
18891 
18892 			   /*INVCONV , Changed the debug message*/
18893 			  IF (l_debug = 1) THEN
18894 			     /*print_debug('VALIDATE_LOT_SERIAL_INFO: VALIDATE_OPM_LOT STATUS: '||x_return_status||' : '||l_progress, 1);*/
18895               print_debug('VALIDATE_LOT_SERIAL_INFO: VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
18896 		     END IF;
18897 		   /*END IF;--IF (NOT l_discrete_transaction) THEN */
18898 
18899         END IF; --IF NOT L_LOT_ENTERED_ON_PARENT THEN
18900 	       ELSE --IF L_LOT_EXISTS = 1 THEN
18901 		       -- MAKE SURE THE LOT WAS NOT ENTERED ON THE PARENT TXN
18902 		       -- IF LOT WAS ENTERED ON THE PARENT TRANSACTION THEN
18903 		       -- FAIL THE TRANSACTION
18904 		       IF (L_TRANSACTION_TYPE <> 'RECEIVE') THEN
18905 			  L_LOT_ENTERED_ON_PARENT := LOT_ENTERED_ON_PARENT(L_PARENT_TRANSACTION_ID);
18906 			ELSE
18907 			  L_LOT_ENTERED_ON_PARENT := FALSE;
18908 		       END IF;
18909 
18910 		       IF (l_debug = 1) THEN
18911 			  print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||L_SOURCE_DOCUMENT_CODE||' : '||l_progress, 1);
18912 			  l_progress := 'WMSINB-22332';
18913 		       END IF;
18914 
18915 		       IF NOT l_lot_entered_on_parent THEN
18916 			  IF (l_debug = 1) THEN
18917 			     print_debug('VALIDATE_LOT_SERIAL_INFO: LOT NOT ENTERED ON PARENT: '||l_progress, 1);
18918 			     l_progress := 'WMSINB-22338';
18919 			  END IF;
18920 
18921 			  -- opm change bug# 3061052
18922            /*INVCONV , existing discrete validations. Same will be executed for process org,Punit Kumar*/
18923 
18924            --IF (l_discrete_transaction) THEN
18925 
18926 			     IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY', 'REQ')) THEN
18927 				-- GET THE LOT/SERIAL CONTROL IN SOURCE ORG
18928 				GET_SERIAL_LOT_CTRL_IN_SRC_ORG
18929 				  (L_SHIPMENT_LINE_ID, L_ORG_ID,
18930 				   L_FROM_ORG_SER_CRTL,
18931 				   L_FROM_ORG_LOT_CTRL, l_from_org_rev_ctrl,
18932 				   X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
18933 
18934 				IF (l_debug = 1) THEN
18935 				   print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CONTROL FROM ORG: '||L_FROM_ORG_LOT_CTRL||' : '||l_progress, 1);
18936 				   l_progress := 'WMSINB-22352';
18937 				END IF;
18938 
18939 				IF (L_FROM_ORG_LOT_CTRL = 2) THEN
18940 			           BEGIN
18941 				      SELECT nvl(SUM(rls.primary_quantity),0) --Bug:5489462
18942 					INTO L_RLS_PRIMARY_QUANTITY
18943 					FROM rcv_lots_supply rls
18944 					, rcv_shipment_lines rsl
18945 					WHERE rls.SHIPMENT_LINE_ID = rsl.SHIPMENT_LINE_ID
18946 					AND rsl.shipment_header_id = l_shipment_header_id
18947 					AND rsl.item_id = l_item_id
18948 					AND rls.SUPPLY_TYPE_CODE = 'SHIPMENT'
18949 					AND rls.LOT_NUM = Ltrim(Rtrim(L_MTLT_REC.lot_number));
18950 
18951 				      IF (L_MTLT_REC.PRIMARY_QUANTITY >
18952 					  L_RLS_PRIMARY_QUANTITY) THEN
18953 					 --RAISE ERROR
18954 					 l_progress :=     'WMSINB-22367';
18955 					 RAISE fnd_api.g_exc_error;
18956 				      END IF;
18957 				   EXCEPTION
18958 				      WHEN NO_DATA_FOUND THEN
18959 					 --RAISE ERROR
18960 					 l_progress :=     'WMSINB-22373';
18961 					 RAISE fnd_api.g_exc_error;
18962 				   END;
18963 				END IF; --IF (L_FROM_ORG_LOT_CTRL = 2) THEN
18964 			     END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY', 'REQ')) THEN
18965 			     -- PERFORM NEW LOT VALIDATIONS
18966 			     -- CREATE LOT
18967 			     -- CALL INV_LOT_API_PUB.CREATE_INV_LOT
18968 
18969 			     --FOR l_inv_att_index IN 1..15 LOOP
18970 			     -- l_inv_attributes_tbl(l_inv_att_index) := NULL;
18971 			     --END LOOP;
18972 
18973               /*
18974 			     l_c_attributes_tbl(1)  := l_mtlt_rec.c_attribute1;
18975 			     l_c_attributes_tbl(2)  := l_mtlt_rec.c_attribute2;
18976 			     l_c_attributes_tbl(3)  := l_mtlt_rec.c_attribute3;
18977 			     l_c_attributes_tbl(4)  := l_mtlt_rec.c_attribute4;
18978 			     l_c_attributes_tbl(5)  := l_mtlt_rec.c_attribute5;
18979 			     l_c_attributes_tbl(6)  := l_mtlt_rec.c_attribute6;
18980 			     l_c_attributes_tbl(7)  := l_mtlt_rec.c_attribute7;
18981 			     l_c_attributes_tbl(8)  := l_mtlt_rec.c_attribute8;
18982 			     l_c_attributes_tbl(9)  := l_mtlt_rec.c_attribute9;
18983 			     l_c_attributes_tbl(10) := l_mtlt_rec.c_attribute10;
18984 			     l_c_attributes_tbl(11) := l_mtlt_rec.c_attribute11;
18985 			     l_c_attributes_tbl(12) := l_mtlt_rec.c_attribute12;
18986 			     l_c_attributes_tbl(13) := l_mtlt_rec.c_attribute13;
18987 			     l_c_attributes_tbl(14) := l_mtlt_rec.c_attribute14;
18988 			     l_c_attributes_tbl(15) := l_mtlt_rec.c_attribute15;
18989 			     l_c_attributes_tbl(16) := l_mtlt_rec.c_attribute16;
18990 			     l_c_attributes_tbl(17) := l_mtlt_rec.c_attribute17;
18991 			     l_c_attributes_tbl(18) := l_mtlt_rec.c_attribute18;
18992 			     l_c_attributes_tbl(19) := l_mtlt_rec.c_attribute19;
18993 			     l_c_attributes_tbl(20) := l_mtlt_rec.c_attribute20;
18994 			     l_d_attributes_tbl(1)  := l_mtlt_rec.d_attribute1;
18995 			     l_d_attributes_tbl(2)  := l_mtlt_rec.d_attribute2;
18996 			     l_d_attributes_tbl(3)  := l_mtlt_rec.d_attribute3;
18997 			     l_d_attributes_tbl(4)  := l_mtlt_rec.d_attribute4;
18998 			     l_d_attributes_tbl(5)  := l_mtlt_rec.d_attribute5;
18999 			     l_d_attributes_tbl(6)  := l_mtlt_rec.d_attribute6;
19000 			     l_d_attributes_tbl(7)  := l_mtlt_rec.d_attribute7;
19001 			     l_d_attributes_tbl(8)  := l_mtlt_rec.d_attribute8;
19002 			     l_d_attributes_tbl(9)  := l_mtlt_rec.d_attribute9;
19003 			     l_d_attributes_tbl(10) := l_mtlt_rec.d_attribute10;
19004 			     l_n_attributes_tbl(1)  := l_mtlt_rec.n_attribute1;
19005 			     l_n_attributes_tbl(2)  := l_mtlt_rec.n_attribute2;
19006 			     l_n_attributes_tbl(3)  := l_mtlt_rec.n_attribute3;
19007 			     l_n_attributes_tbl(4)  := l_mtlt_rec.n_attribute4;
19008 			     l_n_attributes_tbl(5)  := l_mtlt_rec.n_attribute5;
19009 			     l_n_attributes_tbl(6)  := l_mtlt_rec.n_attribute6;
19010 			     l_n_attributes_tbl(7)  := l_mtlt_rec.n_attribute7;
19011 			     l_n_attributes_tbl(8)  := l_mtlt_rec.n_attribute8;
19012 			     l_n_attributes_tbl(9)  := l_mtlt_rec.n_attribute9;
19013 			     l_n_attributes_tbl(10) := l_mtlt_rec.n_attribute10;
19014 
19015            --Bug #3187688
19016            --Populate the INV attributes table and pass the attribute cateogry
19017            l_inv_attributes_tbl(1)  := l_mtlt_rec.attribute1;
19018            l_inv_attributes_tbl(2)  := l_mtlt_rec.attribute2;
19019            l_inv_attributes_tbl(3)  := l_mtlt_rec.attribute3;
19020            l_inv_attributes_tbl(4)  := l_mtlt_rec.attribute4;
19021            l_inv_attributes_tbl(5)  := l_mtlt_rec.attribute5;
19022            l_inv_attributes_tbl(6)  := l_mtlt_rec.attribute6;
19023            l_inv_attributes_tbl(7)  := l_mtlt_rec.attribute7;
19024            l_inv_attributes_tbl(8)  := l_mtlt_rec.attribute8;
19025            l_inv_attributes_tbl(9)  := l_mtlt_rec.attribute9;
19026            l_inv_attributes_tbl(10) := l_mtlt_rec.attribute10;
19027            l_inv_attributes_tbl(11) := l_mtlt_rec.attribute11;
19028            l_inv_attributes_tbl(12) := l_mtlt_rec.attribute12;
19029            l_inv_attributes_tbl(13) := l_mtlt_rec.attribute13;
19030            l_inv_attributes_tbl(14) := l_mtlt_rec.attribute14;
19031            l_inv_attributes_tbl(15) := l_mtlt_rec.attribute15;
19032 
19033 			     inv_lot_api_pub.create_inv_lot(x_return_status => x_return_status
19034 							    , x_msg_count => x_msg_count
19035 							    , x_msg_data => x_msg_data
19036 							    , p_inventory_item_id => l_item_id
19037 							    , p_organization_id => l_org_id
19038 							    , p_lot_number => l_mtlt_rec.lot_number
19039 							    , p_expiration_date => l_mtlt_rec.lot_expiration_date
19040 							    , p_disable_flag => NULL
19041 							    , p_attribute_category => l_mtlt_rec.attribute_category
19042 							    , p_lot_attribute_category => l_mtlt_rec.lot_attribute_category
19043 							    , p_attributes_tbl => l_inv_attributes_tbl
19044 							    , p_c_attributes_tbl => l_c_attributes_tbl
19045 							    , p_n_attributes_tbl => l_n_attributes_tbl
19046 							    , p_d_attributes_tbl => l_d_attributes_tbl
19047 							    , p_grade_code => l_mtlt_rec.grade_code
19048 							    , p_origination_date => l_mtlt_rec.origination_date
19049 							    , p_date_code => l_mtlt_rec.date_code
19050 							    , p_status_id => l_mtlt_rec.status_id
19051 							    , p_change_date => l_mtlt_rec.change_date
19052 							    , p_age => l_mtlt_rec.age
19053 							    , p_retest_date => l_mtlt_rec.retest_date
19054 			       , p_maturity_date => l_mtlt_rec.maturity_date
19055 			       , p_item_size => l_mtlt_rec.item_size
19056 			       , p_color => l_mtlt_rec.color
19057 			       , p_volume => l_mtlt_rec.volume
19058 			       , p_volume_uom => l_mtlt_rec.volume_uom
19059 			       , p_place_of_origin => l_mtlt_rec.place_of_origin
19060 			       , p_best_by_date => l_mtlt_rec.best_by_date
19061 			       , p_length => l_mtlt_rec.Length
19062 			       , p_length_uom => l_mtlt_rec.length_uom
19063 			       , p_recycled_content => l_mtlt_rec.recycled_content
19064 			       , p_thickness => l_mtlt_rec.thickness
19065 			       , p_thickness_uom => l_mtlt_rec.thickness_uom
19066 			       , p_width => l_mtlt_rec.width
19067 			       , p_width_uom => l_mtlt_rec.width_uom
19068 			       , p_territory_code => l_mtlt_rec.territory_code
19069 			       , p_supplier_lot_number => l_mtlt_rec.supplier_lot_number
19070 			       , p_vendor_name => l_mtlt_rec.vendor_name
19071 			       , p_source => inv_lot_api_pub.inv);
19072 
19073 			     IF (x_return_status <> 'S') THEN
19074 				--raise error
19075 	   			l_progress :=     'WMSINB-22469';
19076 				RAISE fnd_api.g_exc_error;
19077 			     END IF;
19078 
19079 			     IF (l_debug = 1) THEN
19080 				print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CREATED: '||l_progress, 1);
19081 				l_progress := 'WMSINB-22475';
19082 			     END IF;
19083 			   ELSE --IF (l_discrete_transaction) THEN
19084 			   	-- opm change bug# 3061052
19085 				gml_opm_roi_grp.validate_opm_lot(p_api_version	=> 1.0,
19086 								 p_init_msg_lst	 	=> FND_API.G_FALSE,
19087 								 p_mtlt_rowid		=> l_mtlt_rec.rowid,
19088 								 p_new_lot	 	=> 'Y',
19089 								 p_opm_item_id		=> l_opm_item_id,
19090 								 p_item_no		=> l_item_no,
19091 								 p_lots_specified_on_parent => 'N',
19092 								 p_lot_id		=> l_opm_lot_id,
19093 								 x_return_status 	=> x_return_status,
19094 								 x_msg_data      	=> x_msg_data,
19095 								 x_msg_count     	=> x_msg_count
19096 								 );
19097 		     		IF X_RETURN_STATUS <> 'S' THEN
19098 				   --RAISE ERROR
19099 				   l_progress := 'WMSINB-22493';
19100 				   RAISE fnd_api.g_exc_error;
19101 		     		END IF;
19102 
19103 		     		IF (l_debug = 1) THEN
19104 				   print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CREATED: '||x_return_status||' : '||l_progress, 1);
19105 		     		END IF;
19106 			  END IF; --IF (l_discrete_transaction) THEN
19107            */
19108 
19109            /*INVCONV , Perform lot validations and create the new lot.
19110                Call Lot Create API INV_ROI_INTEGRATION_GRP.INV_NEW_LOT to create the new lot.
19111                This shall also create lot specific conversions after creating the new Lot.
19112 			      This replaces the existing procedure INV_LOT_API_PUB.CREATE_INV_LOT to create NEW LOT
19113                Punit Kumar*/
19114               IF (l_debug = 1) THEN
19115               print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
19116               END IF;
19117 
19118               INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
19119                                                          x_return_status      		   => x_return_status
19120                                                         ,x_msg_data           		   => x_msg_data
19121                                                         ,x_msg_count          		   => x_msg_count
19122                                                         ,p_api_version	               => 1.0
19123                                                         ,p_init_msg_lst	               => FND_API.G_FALSE
19124                                                         ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
19125                                                         ,p_transaction_type_id 	      => l_transaction_type_id
19126                                                         ,p_new_lot			            => 'Y'
19127                                                         ,p_item_id	 		            => l_item_id
19128                                                         ,p_to_organization_id		      => L_ORG_ID
19129                                                         ,p_lot_number			         => L_MTLT_REC.lot_number
19130                                                         ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
19131                                                         ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
19132                                                         ,x_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
19133                                                         ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
19134                                                         ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
19135                                                         ,p_transaction_unit_of_measure => l_rti_UNIT_OF_MEASURE
19136                                                         ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
19137                                                         ,p_OE_ORDER_HEADER_ID	         => l_OE_ORDER_HEADER_ID
19138                                                         ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
19139                                                         ,p_rti_id	                     => L_RTI_ID
19140                                                         ,p_revision             	      => l_item_revision
19141                                                         ,p_subinventory_code  	      => L_SUB_CODE
19142                                                         ,p_locator_id           	      => l_loc_id
19143                                                         ,p_transaction_type           => l_transaction_type
19144                                                         ,p_parent_txn_type            => l_parent_txn_type
19145                                                         ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
19146                                                         );
19147 
19148               IF (l_debug = 1) THEN
19149 
19150               print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
19151               END IF;
19152 
19153 
19154               IF X_RETURN_STATUS <> 'S' THEN
19155             --RAISE ERROR
19156             l_progress := 'WMSINB-22493';
19157             RAISE fnd_api.g_exc_error;
19158             END IF;
19159 
19160              /*INVCONV ,*/
19161 			  IF (l_debug = 1) THEN
19162               print_debug('VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
19163               print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
19164 		     END IF;
19165 
19166 
19167            INV_ROI_INTEGRATION_GRP.INV_NEW_LOT(
19168                                                 x_return_status      		   => x_return_status
19169                                                ,x_msg_count          		   => x_msg_count
19170                                                ,x_msg_data           		   => x_msg_data
19171                                                ,p_api_version	               => 1.0
19172                                                ,p_init_msg_lst	               => FND_API.G_FALSE
19173                                                ,p_source_document_code			=> L_SOURCE_DOCUMENT_CODE
19174                                                ,p_item_id				         => l_item_id
19175                                                ,p_from_organization_id			=> L_FROM_ORG_ID
19176                                                ,p_to_organization_id	         => L_ORG_ID
19177                                                ,p_lot_number				      => L_MTLT_REC.lot_number
19178                                                ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
19179                                                ,p_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
19180                                                ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
19181                                                ,p_primary_unit_of_measure	   => l_rti_PRIMARY_UNIT_OF_MEASURE
19182                                                ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
19183                                                ,p_uom_code	                  => l_rti_UOM_CODE
19184                                                ,p_secondary_uom_code	         => l_rti_SECONDARY_UOM_CODE
19185                                                ,p_reason_id	                  => L_MTLT_REC.REASON_ID
19186                                                ,P_MLN_REC                     => L_MLN_REC
19187                                                ,p_mtlt_rowid	               => L_MTLT_REC.ROWID
19188                                                );
19189 
19190             /*INVCONV ,*/
19191 			  IF (l_debug = 1) THEN
19192               print_debug('VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_NEW_LOT return status: '||x_return_status||' : '||l_progress, 1);
19193               print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
19194 		     END IF;
19195 
19196             IF X_RETURN_STATUS <> 'S' THEN
19197           --RAISE ERROR
19198           l_progress := 'WMSINB-22494';
19199           RAISE fnd_api.g_exc_error;
19200           END IF;
19201 
19202 
19203 
19204 
19205 			ELSE --IF NOT l_lot_entered_on_parent THEN
19206 			     --raise error
19207 			     l_progress := 'WMSINB-22504';
19208 			     RAISE fnd_api.g_exc_error;
19209 		       END IF; --IF NOT l_lot_entered_on_parent THEN
19210 	      END IF; --IF L_LOT_EXISTS = 1 THEN
19211 
19212 	      IF (L_SERIAL_NUMBER_CONTROL_CODE IN (2,5,6)) THEN
19213 
19214 		 IF (l_debug = 1) THEN
19215 		    print_debug('VALIDATE_LOT_SERIAL_INFO: LOT AND SERIAL CONTROLLED: '||l_progress, 1);
19216 		    print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROL CODE: '||l_serial_number_control_code||' : '||l_progress, 1);
19217 		    print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||l_source_document_code||' : '||l_progress, 1);
19218 		    l_progress := 'WMSINB-22515';
19219 		 END IF;
19220 
19221 		 L_NUM_MSNT_RECS := 0;
19222 		 l_tot_msnt_serial_qty := 0;
19223 
19224 		 OPEN C_MSNT_LOTSERIAL(L_MTLT_REC.SERIAL_TRANSACTION_TEMP_ID);
19225 
19226 		 LOOP
19227 		    FETCH C_MSNT_LOTSERIAL INTO L_MSNT_REC;
19228 
19229 		    EXIT WHEN C_MSNT_LOTSERIAL%NOTFOUND;
19230 
19231 		    L_NUM_MSNT_RECS := L_NUM_MSNT_RECS + 1;
19232 
19233 		    IF (L_SERIAL_NUMBER_CONTROL_CODE = 6 AND
19234 			L_SOURCE_DOCUMENT_CODE NOT IN ('RMA','REQ','INVENTORY')) THEN
19235 		       -- RAISE AN ERROR. IF SERIAL IS AT SALES ORDER ISSUE THEN
19236 		       -- IT CAN BE ENTERED ONLY FOR A RMA RECEIPT.
19237 		       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19238 		       fnd_msg_pub.ADD;
19239 		       l_progress := 'WMSINB-22536';
19240 		       RAISE fnd_api.g_exc_error;
19241 		    END IF;
19242 
19243 		    L_SERIAL_QUANTITY :=
19244 		      INV_SERIAL_NUMBER_PUB.GET_SERIAL_DIFF(L_MSNT_REC.FM_SERIAL_NUMBER,
19245 							    L_MSNT_REC.TO_SERIAL_NUMBER);
19246 
19247 		    l_tot_msnt_serial_qty := l_tot_msnt_serial_qty +
19248 		      l_serial_quantity;
19249 
19250 		    INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.FM_SERIAL_NUMBER, L_TEMP_PREFIX, L_FROM_SER_NUMBER);
19251 		    INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.TO_SERIAL_NUMBER, L_TEMP_PREFIX, L_TO_SER_NUMBER);
19252 
19253 		    IF (l_debug = 1) THEN
19254 		       print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL QUANTITY: '||l_serial_quantity||' : '||l_progress, 1);
19255 		       l_progress := 'WMSINB-22551';
19256 		    END IF;
19257 
19258 		    --populate attributes table
19259 		    l_serial_attributes_tbl(1).column_name   := 'SERIAL_ATTRIBUTE_CATEGORY';
19260 		    l_serial_attributes_tbl(1).column_value  := l_msnt_rec.serial_attribute_category;
19261 		    l_serial_attributes_tbl(2).column_name   := 'ORIGINATION_DATE';
19262 		    l_serial_attributes_tbl(2).column_value  := l_msnt_rec.origination_date;
19263 		    l_serial_attributes_tbl(3).column_name   := 'C_ATTRIBUTE1';
19264 		    l_serial_attributes_tbl(3).column_value  := l_msnt_rec.c_attribute1;
19265 		    l_serial_attributes_tbl(4).column_name   := 'C_ATTRIBUTE2';
19266 		    l_serial_attributes_tbl(4).column_value  := l_msnt_rec.c_attribute2;
19267 		    l_serial_attributes_tbl(5).column_name   := 'C_ATTRIBUTE3';
19268 		    l_serial_attributes_tbl(5).column_value  := l_msnt_rec.c_attribute3;
19269 		    l_serial_attributes_tbl(6).column_name   := 'C_ATTRIBUTE4';
19270 		    l_serial_attributes_tbl(6).column_value   := l_msnt_rec.c_attribute4;
19271 		    l_serial_attributes_tbl(7).column_name   := 'C_ATTRIBUTE5';
19272 		    l_serial_attributes_tbl(7).column_value   := l_msnt_rec.c_attribute5;
19273 		    l_serial_attributes_tbl(8).column_name   := 'C_ATTRIBUTE6';
19274 		    l_serial_attributes_tbl(8).column_value   := l_msnt_rec.c_attribute6;
19275 		    l_serial_attributes_tbl(9).column_name   := 'C_ATTRIBUTE7';
19276 		    l_serial_attributes_tbl(9).column_value   := l_msnt_rec.c_attribute7;
19277 		    l_serial_attributes_tbl(10).column_name  := 'C_ATTRIBUTE8';
19278 		    l_serial_attributes_tbl(10).column_value  := l_msnt_rec.c_attribute8;
19279 		    l_serial_attributes_tbl(11).column_name  := 'C_ATTRIBUTE9';
19280 		    l_serial_attributes_tbl(11).column_value  := l_msnt_rec.c_attribute9;
19281 		    l_serial_attributes_tbl(12).column_name  := 'C_ATTRIBUTE10';
19282 		    l_serial_attributes_tbl(12).column_value  := l_msnt_rec.c_attribute10;
19283 		    l_serial_attributes_tbl(13).column_name  := 'C_ATTRIBUTE11';
19284 		    l_serial_attributes_tbl(13).column_value  := l_msnt_rec.c_attribute11;
19285 		    l_serial_attributes_tbl(14).column_name  := 'C_ATTRIBUTE12';
19286 		    l_serial_attributes_tbl(14).column_value  := l_msnt_rec.c_attribute12;
19287 		    l_serial_attributes_tbl(15).column_name  := 'C_ATTRIBUTE13';
19288 		    l_serial_attributes_tbl(15).column_value  := l_msnt_rec.c_attribute13;
19289 		    l_serial_attributes_tbl(16).column_name  := 'C_ATTRIBUTE14';
19290 		    l_serial_attributes_tbl(16).column_value  := l_msnt_rec.c_attribute14;
19291 		    l_serial_attributes_tbl(17).column_name  := 'C_ATTRIBUTE15';
19292 		    l_serial_attributes_tbl(17).column_value  := l_msnt_rec.c_attribute15;
19293 		    l_serial_attributes_tbl(18).column_name  := 'C_ATTRIBUTE16';
19294 		    l_serial_attributes_tbl(18).column_value  := l_msnt_rec.c_attribute16;
19295 		    l_serial_attributes_tbl(19).column_name  := 'C_ATTRIBUTE17';
19296 		    l_serial_attributes_tbl(19).column_value  := l_msnt_rec.c_attribute17;
19297 		    l_serial_attributes_tbl(20).column_name  := 'C_ATTRIBUTE18';
19298 		    l_serial_attributes_tbl(20).column_value  := l_msnt_rec.c_attribute18;
19299 		    l_serial_attributes_tbl(21).column_name  := 'C_ATTRIBUTE19';
19300 		    l_serial_attributes_tbl(21).column_value  := l_msnt_rec.c_attribute19;
19301 		    l_serial_attributes_tbl(22).column_name  := 'C_ATTRIBUTE20';
19302 		    l_serial_attributes_tbl(22).column_value  := l_msnt_rec.c_attribute20;
19303 		    l_serial_attributes_tbl(23).column_name  := 'D_ATTRIBUTE1';
19304 		    l_serial_attributes_tbl(23).column_value  := l_msnt_rec.d_attribute1;
19305 		    l_serial_attributes_tbl(24).column_name  := 'D_ATTRIBUTE2';
19306 		    l_serial_attributes_tbl(24).column_value  := l_msnt_rec.d_attribute2;
19307 		    l_serial_attributes_tbl(25).column_name  := 'D_ATTRIBUTE3';
19308 		    l_serial_attributes_tbl(25).column_value  := l_msnt_rec.d_attribute3;
19309 		    l_serial_attributes_tbl(26).column_name  := 'D_ATTRIBUTE4';
19310 		    l_serial_attributes_tbl(26).column_value  := l_msnt_rec.d_attribute4;
19311 		    l_serial_attributes_tbl(27).column_name  := 'D_ATTRIBUTE5';
19312 		    l_serial_attributes_tbl(27).column_value  := l_msnt_rec.d_attribute5;
19313 		    l_serial_attributes_tbl(28).column_name  := 'D_ATTRIBUTE6';
19314 		    l_serial_attributes_tbl(28).column_value  := l_msnt_rec.d_attribute6;
19315 		    l_serial_attributes_tbl(29).column_name  := 'D_ATTRIBUTE7';
19316 		    l_serial_attributes_tbl(29).column_value  := l_msnt_rec.d_attribute7;
19317 		    l_serial_attributes_tbl(30).column_name  := 'D_ATTRIBUTE8';
19318 		    l_serial_attributes_tbl(30).column_value  := l_msnt_rec.d_attribute8;
19319 		    l_serial_attributes_tbl(31).column_name  := 'D_ATTRIBUTE9';
19320 		    l_serial_attributes_tbl(31).column_value  := l_msnt_rec.d_attribute9;
19321 		    l_serial_attributes_tbl(32).column_name  := 'D_ATTRIBUTE10';
19322 		    l_serial_attributes_tbl(32).column_value  := l_msnt_rec.d_attribute10;
19323 		    l_serial_attributes_tbl(33).column_name  := 'N_ATTRIBUTE1';
19324 		    l_serial_attributes_tbl(33).column_value  := l_msnt_rec.n_attribute1;
19325 		    l_serial_attributes_tbl(34).column_name  := 'N_ATTRIBUTE2';
19326 		    l_serial_attributes_tbl(34).column_value  := l_msnt_rec.n_attribute2;
19327 		    l_serial_attributes_tbl(35).column_name  := 'N_ATTRIBUTE3';
19328 		    l_serial_attributes_tbl(35).column_value  := l_msnt_rec.n_attribute3;
19329 		    l_serial_attributes_tbl(36).column_name  := 'N_ATTRIBUTE4';
19330 		    l_serial_attributes_tbl(36).column_value  := l_msnt_rec.n_attribute4;
19331 		    l_serial_attributes_tbl(37).column_name  := 'N_ATTRIBUTE5';
19332 		    l_serial_attributes_tbl(37).column_value := l_msnt_rec.n_attribute5;
19333 		    l_serial_attributes_tbl(38).column_name  := 'N_ATTRIBUTE6';
19334 		    l_serial_attributes_tbl(38).column_value := l_msnt_rec.n_attribute6;
19335 		    l_serial_attributes_tbl(39).column_name  := 'N_ATTRIBUTE7';
19336 		    l_serial_attributes_tbl(39).column_value := l_msnt_rec.n_attribute7;
19337 		    l_serial_attributes_tbl(40).column_name  := 'N_ATTRIBUTE8';
19338 		    l_serial_attributes_tbl(40).column_value := l_msnt_rec.n_attribute8;
19339 		    l_serial_attributes_tbl(41).column_name  := 'N_ATTRIBUTE9';
19340 		    l_serial_attributes_tbl(41).column_value := l_msnt_rec.n_attribute9;
19341 		    l_serial_attributes_tbl(42).column_name  := 'N_ATTRIBUTE10';
19342 		    l_serial_attributes_tbl(42).column_value := l_msnt_rec.n_attribute10;
19343 		    l_serial_attributes_tbl(43).column_name  := 'STATUS_ID';
19344 		    l_serial_attributes_tbl(43).column_value := l_msnt_rec.status_id;
19345 		    l_serial_attributes_tbl(44).column_name  := 'TERRITORY_CODE';
19346 		    l_serial_attributes_tbl(44).column_value := l_msnt_rec.territory_code;
19347 
19348 		    --Validate the serials
19349 		    FOR SERIALQTY IN 1..L_SERIAL_QUANTITY LOOP
19350 
19351 		       l_progress := 'WMSINB-22557';
19352 
19353                        L_CUR_NUMBER := L_FROM_SER_NUMBER+SERIALQTY -1;
19354                        if L_FROM_SER_NUMBER = -1 and  L_TO_SER_NUMBER = -1 then
19355 	                    L_SERIAL_NUMBER  := L_MSNT_REC.fm_serial_number;
19356 		       else
19357 		            L_SERIAL_NUMBER :=
19358 			      SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
19359 				LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
19360 				LENGTH(L_CUR_NUMBER))
19361 			      ||L_CUR_NUMBER;
19362                        End if;
19363 
19364 		       l_progress := 'WMSINB-22565';
19365 
19366 		       BEGIN
19367 			  SELECT CURRENT_ORGANIZATION_ID
19368 			    , current_status
19369 			    , lot_number
19370 			    , Decode(lpn_id,0,NULL,lpn_id)
19371 			    , inspection_status
19372 			    , group_mark_id
19373 			    INTO L_CURR_ORG_ID
19374 			    , l_curr_status
19375 			    , l_curr_lot_num
19376 			    , l_curr_lpn_id
19377 			    , l_inspection_status
19378 			    , l_group_mark_id
19379 			    FROM MTL_SERIAL_NUMBERS
19380 			    WHERE SERIAL_NUMBER = l_serial_number
19381 			    AND inventory_item_id = l_item_id;
19382 
19383 			  l_serial_exists := 1;
19384 			  l_progress := 'WMSINB-22585';
19385 		       EXCEPTION
19386 			  WHEN no_data_found THEN
19387 			     l_serial_exists := 0;
19388 			     l_progress := 'WMSINB-22589';
19389 		       END;
19390 
19391 		       IF (l_debug = 1) THEN
19392 			  print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL EXISTS: '||l_serial_exists||' : '||l_progress, 1);
19393 			  print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NUMBER: '||l_serial_number||' : '||l_progress, 1);
19394 			  print_debug('VALIDATE_LOT_SERIAL_INFO: CURR STATUS: '||l_curr_status||' : '||l_progress, 1);
19395 			  print_debug('VALIDATE_LOT_SERIAL_INFO: CURR ORG ID: '||l_curr_org_id||' : '||l_progress, 1);
19396 			  print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LPN ID: '||l_curr_lpn_id||' : '||l_progress, 1);
19397 			  print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LOT NUM: '||l_curr_lot_num||' : '||l_progress, 1);
19398 			  print_debug('VALIDATE_LOT_SERIAL_INFO: INSPECT STS: '||l_inspection_status||' : '||l_progress, 1);
19399 			  print_debug('VALIDATE_LOT_SERIAL_INFO: GROUP MARK ID: '||l_group_mark_id||' : '||l_progress, 1);
19400 			  print_debug('VALIDATE_LOT_SERIAL_INFO: RESTRICT RCPT SER: '||l_restrict_rcpt_ser||' : '||l_progress, 1);
19401 			  l_progress := 'WMSINB-22602';
19402 		       END IF;
19403 
19404 		       l_progress := 'WMSINB-22605';
19405 
19406 		       IF (L_TRANSACTION_TYPE <> 'RECEIVE') THEN
19407 			  L_SERIAL_ENTERED_ON_PARENT := SERIAL_ENTERED_ON_PARENT(L_PARENT_TRANSACTION_ID);
19408 			ELSE
19409 			  L_SERIAL_ENTERED_ON_PARENT := FALSE;
19410 		       END IF;
19411 
19412 		       IF (l_debug = 1) THEN
19413 			  print_debug('VALIDATE_LOT_SERIAL_INFO: ASN LINE FLAG: '||l_asn_line_flag||' : '||l_progress, 1);
19414 			  l_progress := 'WMSINB-22615';
19415 		       END IF;
19416 
19417 		       IF NOT L_SERIAL_ENTERED_ON_PARENT THEN
19418 			  IF (l_debug = 1) THEN
19419 			     print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NOT ENTERED ON PARENT: '||l_progress, 1);
19420 			     l_progress := 'WMSINB-22621';
19421 			  END IF;
19422 
19423 			  IF (l_serial_number_control_code IN (2,5)
19424 			      OR (l_serial_number_control_code = 6
19425 				  AND l_source_document_code IN
19426 				  ('INVENTORY','REQ'))) THEN
19427 			     IF l_serial_exists = 1 THEN
19428 				IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')
19429 				    OR l_asn_line_flag = 'Y') THEN
19430 
19431 				   IF (l_asn_line_flag = 'Y') THEN
19432 				      IF ((l_curr_org_id <> l_org_id) and not (l_restrict_rcpt_ser = '2'
19433 									       and l_curr_status = 4 ))  THEN
19434 					 --raise error
19435 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19436 					 fnd_msg_pub.ADD;
19437 					 l_progress := 'WMSINB-22634';
19438 					 RAISE fnd_api.g_exc_error;
19439 				       ELSE
19440 					 IF ((l_curr_lot_num IS NOT NULL)
19441 					     AND (l_curr_lot_num <>
19442 						  l_mtlt_rec.lot_number)
19443 					     AND (Nvl(l_curr_status,1) NOT
19444 						  IN (1,4))) THEN
19445 					    --raise error
19446 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19447 					    fnd_msg_pub.ADD;
19448 					    l_progress := 'WMSINB-22641';
19449 					    RAISE fnd_api.g_exc_error;
19450 					 END IF;
19451 				      END IF;
19452 
19453 				      IF (rss_exists(l_shipment_header_id,l_item_id)) THEN
19454 				         BEGIN
19455 					    SELECT '1'
19456 					      INTO l_dummy
19457 					      FROM rcv_serials_supply rss
19458 					      , rcv_shipment_lines rsl
19459 					      WHERE rss.shipment_line_id = rsl.shipment_line_id
19460 					      AND rsl.shipment_header_id = l_shipment_header_id
19461 					      AND rsl.item_id = l_item_id
19462 					      AND rss.supply_type_code = 'SHIPMENT'
19463 					      AND rss.serial_num = l_serial_number;
19464 
19465 					    IF (l_debug = 1) THEN
19466 					       print_debug('VALIDATE_LOT_SERIAL_INFO: RSS EXISTS: '||l_progress, 1);
19467 					       l_progress := 'WMSINB-22657';
19468 					    END IF;
19469 
19470 					    IF l_curr_status <> 5 THEN
19471 					       --raise error
19472 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19473 					       fnd_msg_pub.ADD;
19474 					       l_progress := 'WMSINB-22664';
19475 					       RAISE fnd_api.g_exc_error;
19476 					    END IF;
19477 					 EXCEPTION
19478 					    WHEN no_data_found THEN
19479 					       IF l_restrict_rcpt_ser = '2' THEN
19480 						  IF l_curr_status NOT IN
19481 						    (1,4,6) THEN
19482 						     --raise error
19483 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19484 						     fnd_msg_pub.ADD;
19485 						     l_progress := 'WMSINB-22675';
19486 						     RAISE fnd_api.g_exc_error;
19487 						  END IF;
19488 						ELSE --IF l_restrict_rcpt_ser = '2' THEN
19489 						  IF l_curr_status NOT IN
19490 						    (1,6) THEN
19491 						     --raise error
19492 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19493 						     fnd_msg_pub.ADD;
19494 						     l_progress := 'WMSINB-22684';
19495 						     RAISE fnd_api.g_exc_error;
19496 						  END IF;
19497 					       END IF; --IF l_restrict_rcpt_ser = '2' THEN
19498 					 END;
19499 				       ELSE --IF (rss_exists(l_shipment_header_id,l_item_id)) THEN
19500 					       IF l_restrict_rcpt_ser = '2' THEN
19501 						  IF l_curr_status NOT IN
19502 						    (1,4,6) THEN
19503 						     --raise error
19504 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19505 						     fnd_msg_pub.ADD;
19506 						     l_progress := 'WMSINB-22696';
19507 						     RAISE fnd_api.g_exc_error;
19508 						  END IF;
19509 						ELSE --IF l_restrict_rcpt_ser = '2' THEN
19510 						  IF l_curr_status NOT IN
19511 						    (1,6) THEN
19512 						     --raise error
19513 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19514 						     fnd_msg_pub.ADD;
19515 						     l_progress := 'WMSINB-22705';
19516 						     RAISE fnd_api.g_exc_error;
19517 						  END IF;
19518 					       END IF; --IF l_restrict_rcpt_ser = '2' THEN
19519 				      END IF; --IF (rss_exists(l_shipment_header_id,l_item_id)) THEN
19520 				   END IF; --IF (l_asn_line_flag = 'Y') THEN
19521 
19522 				   IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
19523 				      -- CHECK TO SEE IF THE ITEM IS SERIAL
19524 				      -- CONTROLLED IN SOURCE ORG
19525 
19526 				      GET_SERIAL_LOT_CTRL_IN_SRC_ORG
19527 					(L_SHIPMENT_LINE_ID, L_ORG_ID,
19528 					 L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
19529 					 l_from_org_rev_ctrl, X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
19530 
19531 				      IF ((L_FROM_ORG_SER_CRTL IN (2,5,6)
19532 					   AND l_source_document_code = 'REQ')
19533 					  OR (l_from_org_ser_crtl IN (2,5)
19534 					      AND l_source_document_code = 'INVENTORY')
19535 					  ) THEN
19536 
19537                                          /*****bug4187663, comment out the call to serial uniqueness check, the check will be in TM
19538 					 IF (l_source_document_code = 'REQ') THEN
19539 					    l_txn_src_type_id := 7;
19540 					  ELSE
19541 					    l_txn_src_type_id := 13;
19542 					 END IF;
19543 
19544 					 --Validate Serial Uniqueness in
19545 					 --current org.
19546 					 IF (l_debug = 1) THEN
19547 					    print_debug('VALIDATE_LOT_SERIAL_INFO: CALLING IS_SERNUM_UNIQUE...', 1);
19548 					 END IF;
19549 
19550 					 IF
19551 					   (is_sernum_unique(l_org_id,l_item_id,l_serial_number,l_txn_src_type_id,12,x_msg_data)<>0) THEN
19552 					      --raise error
19553 					      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19554 					      fnd_msg_pub.ADD;
19555 					      l_progress := 'WMSINB-22725';
19556 					      RAISE fnd_api.g_exc_error;
19557 					   END IF;
19558 
19559 					   IF (l_debug = 1) THEN
19560 					      print_debug('VALIDATE_LOT_SERIAL_INFO: CALLING IS_SERNUM_UNIQUE...DONE', 1);
19561 					   END IF;
19562                                            *****end of bug4187663*****/
19563 
19564 					   IF l_curr_org_id <> l_from_org_id THEN
19565 					      --raise error
19566 					      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19567 					      fnd_msg_pub.ADD;
19568 					      l_progress := 'WMSINB-22726';
19569 					      RAISE fnd_api.g_exc_error;
19570 					    ELSE
19571 					      IF ((l_curr_lot_num IS NOT NULL) AND
19572 						  (l_curr_lot_num <>
19573 						   l_mtlt_rec.lot_number)
19574 						  AND (Nvl(l_curr_status,1)
19575 						       NOT IN (1,4))) THEN
19576 						 --raise error
19577 						 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19578 						 fnd_msg_pub.ADD;
19579 						 l_progress := 'WMSINB-22734';
19580 						 RAISE fnd_api.g_exc_error;
19581 					      END IF;
19582 					   END IF;
19583 
19584 				         BEGIN
19585 					    SELECT '1'
19586 					      INTO L_DUMMY
19587 					      FROM rcv_serials_supply rss
19588 					      , rcv_shipment_lines rsl
19589 					      WHERE rss.SHIPMENT_LINE_ID = rsl.SHIPMENT_LINE_ID
19590 					      AND rsl.shipment_header_id = l_shipment_header_id
19591 					      AND rsl.item_id = l_item_id
19592 					      AND rss.SUPPLY_TYPE_CODE = 'SHIPMENT'
19593 					      AND rss.serial_num = l_serial_number;
19594 
19595 					    IF L_CURR_STATUS <> 5 THEN
19596 					       -- RAISE AN ERROR
19597 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19598 					       fnd_msg_pub.ADD;
19599 					       l_progress := 'WMSINB-22751';
19600 					       RAISE fnd_api.g_exc_error;
19601 					    END IF;
19602 
19603 					 EXCEPTION
19604 					    WHEN NO_DATA_FOUND THEN
19605 					       -- RAISE AN ERROR
19606 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19607 					       fnd_msg_pub.ADD;
19608 					       l_progress := 'WMSINB-22760';
19609 					       RAISE fnd_api.g_exc_error;
19610 					 END;
19611 				       ELSE --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
19612                 --BUG 5524134
19613                 /* For lot serials with serial numbers in status 4
19614                   i.e. issued out of stores, we need to
19615                   honor the INV_RESTRICT_RCPT_SER profile.
19616                   And for serial status defined but not used
19617                   error out only if the org id in MSN is equal to
19618                   that present in the RSL.
19619                   */
19620 					       IF L_CURR_ORG_ID <> l_org_id THEN
19621                     BEGIN
19622                            SELECT from_organization_id INTO l_from_org_id
19623                            FROM rcv_shipment_lines
19624                            WHERE shipment_line_id = L_SHIPMENT_LINE_ID;
19625                     EXCEPTION
19626                            WHEN NO_DATA_FOUND THEN
19627                            -- RAISE AN ERROR
19628                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19629                            fnd_msg_pub.ADD;
19630                            l_progress := 'WMSINB-22765';
19631                            RAISE fnd_api.g_exc_error;
19632                     END;
19633                     IF L_SOURCE_DOCUMENT_CODE IN ( 'INVENTORY' , 'REQ' ) THEN
19634                        IF NOT (
19635                                ( L_CURR_STATUS = 1 AND L_CURR_ORG_ID = l_from_org_id)
19636                             OR ( L_CURR_STATUS = 4 AND l_restrict_rcpt_ser = '2' )
19637                               )
19638                              THEN
19639                              l_progress := 'WMSINB-22761';
19640                              IF (l_debug = 1) THEN
19641                                   print_debug('For Intransit receipt the serial number org does not match the sending org!', 1);
19642                              END IF;
19643                              fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19644                              fnd_msg_pub.ADD;
19645                              RAISE fnd_api.g_exc_error;
19646                     END IF;
19647             ELSE
19648     						  --raise error
19649     						  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19650     						  fnd_msg_pub.ADD;
19651     						  l_progress := 'WMSINB-22768';
19652     						  RAISE fnd_api.g_exc_error;
19653 				    END IF;
19654 						ELSE
19655 						  IF ((l_curr_lot_num IS
19656 						       NOT NULL)
19657 						      AND (l_curr_lot_num
19658 							   <>
19659 							   l_mtlt_rec.lot_number)
19660 						      AND
19661 						      (Nvl(l_curr_status,1)
19662 						       NOT IN (1,4))) THEN
19663 						     --raise error
19664 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19665 						     fnd_msg_pub.ADD;
19666 						     l_progress := 'WMSINB-22776';
19667 						     RAISE fnd_api.g_exc_error;
19668 						  END IF;
19669 					       END IF;
19670 					       /* Bug: 5524134
19671                     In case of serial numbers that are in status
19672 					          4 i.e. issued out of stores, we need to
19673                     honor the INV_RESTRICT_RCPT_SER profile.
19674                   */
19675 					       IF (L_CURR_STATUS NOT IN (1,6)
19676                      AND NOT (l_restrict_rcpt_ser = '2'and l_curr_status = 4)
19677                     ) THEN
19678 						  -- RAISE AN ERROR
19679 						  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19680 						  fnd_msg_pub.ADD;
19681 						  l_progress := 'WMSINB-22785';
19682 						  RAISE fnd_api.g_exc_error;
19683 					       END IF;
19684 				      END IF; --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
19685 				   END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
19686 				 ELSE  --IF (L_SOURCE_DOCUMENT_CODE IN
19687 				      --('INVENTORY','REQ') OR l_asn_line_flag = 'Y') THEN
19688 				      IF (( (L_SOURCE_DOCUMENT_CODE <> 'RMA' AND l_curr_org_id <> l_org_id) )
19689                            and not (l_restrict_rcpt_ser = '2'and l_curr_status = 4 ))  THEN
19690 					 --raise error
19691 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19692 					 fnd_msg_pub.ADD;
19693 					 l_progress := 'WMSINB-22796';
19694 					 RAISE fnd_api.g_exc_error;
19695 				       ELSE
19696 					 IF ((l_curr_lot_num IS NOT NULL)
19697 					     AND (l_curr_lot_num <>
19698 						  l_mtlt_rec.lot_number)
19699 					     AND (Nvl(l_curr_status,1) NOT
19700 						  IN (1,4))) THEN
19701 					    --raise error
19702 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19703 					    fnd_msg_pub.ADD;
19704 					    l_progress := 'WMSINB-22803';
19705 					    RAISE fnd_api.g_exc_error;
19706 					 END IF;
19707 				      END IF;
19708 
19709 				      IF l_restrict_rcpt_ser = '2' THEN
19710 					 IF l_curr_status NOT IN (1,4,6) THEN
19711 					    --raise error
19712 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19713 					    fnd_msg_pub.ADD;
19714 					    l_progress := 'WMSINB-22813';
19715 					    RAISE fnd_api.g_exc_error;
19716 					 END IF;
19717 /* Bug 6847337:
19718  * Fix done to allow the re-using of serials after the
19719  * correction of a PO receipt by handling the transaction type
19720  * for correction(71) and return to vendor(36) in the following
19721  * ELSE condition when the INV: Restrict Receipt of Serials = 'Yes'.
19722  */
19723 				       ELSE --IF l_restrict_rcpt_ser = '2' THEN
19724 					 IF ((l_curr_status NOT IN (1,6))
19725 					     AND NOT (l_curr_status = 4 and
19726 						     (l_source_document_code = 'RMA' OR
19727 						        (l_source_document_code = 'PO'
19728 						           and l_last_transaction_type_id in (36,71))))) THEN
19729 					    --raise error
19730 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19731 					    fnd_msg_pub.ADD;
19732 					    l_progress := 'WMSINB-22821';
19733 					    RAISE fnd_api.g_exc_error;
19734 					 END IF;
19735 				      END IF; --IF l_restrict_rcpt_ser = '2' THEN
19736 
19737 				END IF; --IF (L_SOURCE_DOCUMENT_CODE IN
19738 				--('INVENTORY','REQ') OR l_asn_line_flag = 'Y') THEN
19739 
19740 				--Validate serial/LPN
19741 				IF l_transaction_type = 'RECEIVE' THEN
19742 				   IF (l_source_document_code IN ('INVENTORY', 'REQ')) then
19743 				      IF (Nvl(l_curr_lpn_id, -9999) <>
19744 					  Nvl(l_lpn_id, -9999)
19745 					  AND (
19746                  Nvl(l_curr_status,1) NOT IN (1,5, 6))  ----bug 7112775 (Added status 6 also)
19747                  AND NOT (l_curr_status = 4 and l_restrict_rcpt_ser = '2') --Bug: 5524134
19748                  ) THEN
19749 					 --raise error
19750 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19751 					 fnd_msg_pub.ADD;
19752 					 l_progress := 'WMSINB-22837';
19753 					 RAISE fnd_api.g_exc_error;
19754 				      END IF;
19755 				   END IF;
19756 				 ELSE
19757 				   IF ((Nvl(l_curr_lpn_id, -9999) <>
19758 					Nvl(l_lpn_id, -9999))
19759 					AND Nvl(l_curr_status,1) <> 4) THEN
19760 				      --raise error
19761 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19762 				      fnd_msg_pub.ADD;
19763 				      l_progress := 'WMSINB-22847';
19764 				      RAISE fnd_api.g_exc_error;
19765 				   END IF;
19766 				END IF;
19767 
19768 				--Validate Serial/Inspection_status
19769 		 /*  Commented for bug 6269102
19770                   *  To allow the inspection done again
19771 		  *  on an inspection transaction to succeed
19772 		  *  as it was failing because of the
19773 		  *  inspection status <> 1
19774 
19775 				IF l_transaction_type IN ('ACCEPT', 'REJECT') THEN
19776 				   IF (Nvl(l_inspection_status, 1) <> 1) THEN
19777 				      --raise error
19778 				      l_progress := 'WMSINB-22856';
19779 				      RAISE fnd_api.g_exc_error;
19780 				   END IF;
19781 				 ELS*/
19782 				 IF (l_transaction_type = 'DELIVER') THEN
19783 				   IF (l_routing_header_id = 2) THEN
19784 				      IF l_inspection_status IS NOT NULL AND l_inspection_status = 1 THEN
19785 					 --raise error
19786 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19787 					 fnd_msg_pub.ADD;
19788 					 l_progress := 'WMSINB-22865';
19789 					 RAISE fnd_api.g_exc_error;
19790 				      END IF;
19791 				   END IF;
19792 				END IF;
19793 
19794 				--Validate serial/group_mark_id to prevent
19795 				--entering of duplicate serials
19796 
19797 				IF (Nvl(l_group_mark_id, -99) = -7937) THEN
19798 				   --raise error
19799 				   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19800 				   fnd_msg_pub.ADD;
19801 				   l_progress := 'WMSINB-22878';
19802 				   RAISE fnd_api.g_exc_error;
19803 				END IF;
19804 
19805 				IF (Nvl(l_curr_status, 1) IN (1,6)) THEN
19806 				   --validate and update the attributes.
19807 				   inv_serial_number_pub.validate_update_serial_att
19808 				     (x_return_status     => x_return_status,
19809 				      x_msg_count         => x_msg_count,
19810 				      x_msg_data          => x_msg_data,
19811 				      x_validation_status => l_validation_status,
19812 				      p_serial_number     => l_serial_number,
19813 				      p_organization_id   => l_org_id,
19814 				      p_inventory_item_id => l_item_id,
19815 				      p_serial_att_tbl    => l_serial_attributes_tbl,
19816 				      p_validate_only     => FALSE
19817 				      );
19818 
19819 				   IF (l_validation_status <> 'Y'
19820 				       OR x_return_status <> g_ret_sts_success) THEN
19821 				      --raise error
19822 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19823 				      fnd_msg_pub.ADD;
19824 				      l_progress := 'WMSINB-22880';
19825 				      RAISE fnd_api.g_exc_error;
19826 				   END IF;
19827 				END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
19828 
19829 				--UPDATE GROUP_MARK_ID TO -7937
19830 				IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
19831 				   --raise error
19832 				   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19833 				   fnd_msg_pub.ADD;
19834 				   l_progress := 'WMSINB-22887';
19835 				   RAISE fnd_api.g_exc_error;
19836 				END IF;
19837 
19838 			      ELSE --IF l_serial_exists = 1 THEN
19839 				      IF (l_source_document_code IN ('INVENTORY','REQ')) THEN
19840 					 GET_SERIAL_LOT_CTRL_IN_SRC_ORG
19841 					   (L_SHIPMENT_LINE_ID, L_ORG_ID,
19842 					    L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
19843 					    l_from_org_rev_ctrl, X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
19844 
19845 					 IF ((L_FROM_ORG_SER_CRTL IN (2,5,6)
19846 					      AND l_source_document_code = 'REQ')
19847 					     OR (l_from_org_ser_crtl IN (2,5)
19848 						 AND l_source_document_code = 'INVENTORY')
19849 					     ) THEN
19850 					    --raise error
19851 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19852 					    fnd_msg_pub.ADD;
19853 					    l_progress := 'WMSINB-22902';
19854 					    RAISE fnd_api.g_exc_error;
19855 					 END IF;
19856 				      END IF;
19857 
19858 				      IF l_serial_number_control_code = 5 THEN
19859 					 --PERFORM SERIAL VALIDATION FOR NEW SERIAL
19860 					 --(INCLUDING ATT VALIDATION)
19861 					 --CREATE MSN
19862 
19863 					 inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
19864 										   , p_inventory_item_id => l_item_id
19865 										   , p_organization_id => l_org_id
19866 										   , p_from_serial_number => l_serial_number
19867 										   , p_to_serial_number => l_serial_number
19868 										   , p_initialization_date => SYSDATE
19869 										   , p_completion_date => NULL
19870 										   , p_ship_date => NULL
19871 										   , p_revision => l_item_revision
19872 										   , p_lot_number => l_mtlt_rec.lot_number
19873 										   , p_current_locator_id => l_loc_id
19874 										   , p_subinventory_code => l_sub_code
19875 										   , p_trx_src_id => NULL
19876 										   , p_unit_vendor_id => NULL
19877 										   , p_vendor_lot_number => l_mtlt_rec.supplier_lot_number
19878 										   , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
19879 										   , p_receipt_issue_type => NULL
19880 										   , p_txn_src_id => NULL
19881 										   , p_txn_src_name => NULL
19882 										   , p_txn_src_type_id => NULL
19883 										   , p_transaction_id => NULL
19884 										   , p_current_status => 1
19885 					   , p_parent_item_id => NULL
19886 					   , p_parent_serial_number => NULL
19887 					   , p_cost_group_id => NULL
19888 					   , p_transaction_action_id => 27
19889 					   , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
19890 					   , p_status_id => NULL
19891 					   , p_inspection_status => NULL
19892 					   , x_object_id => l_object_id
19893 					   , x_return_status => x_return_status
19894 					   , x_msg_count => x_msg_count
19895 					   , x_msg_data => x_msg_data);
19896 
19897 					 IF (x_return_status <> g_ret_sts_success) THEN
19898 					    --raise error
19899 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19900 					    fnd_msg_pub.ADD;
19901 					    l_progress := 'WMSINB-22911';
19902 					    RAISE fnd_api.g_exc_error;
19903 					 END IF;
19904 
19905 					 --validate and update the attributes.
19906 					 inv_serial_number_pub.validate_update_serial_att
19907 					   (x_return_status     => x_return_status,
19908 					    x_msg_count         => x_msg_count,
19909 					    x_msg_data          => x_msg_data,
19910 					    x_validation_status => l_validation_status,
19911 					    p_serial_number     => l_serial_number,
19912 					    p_organization_id   => l_org_id,
19913 					    p_inventory_item_id => l_item_id,
19914 					    p_serial_att_tbl    => l_serial_attributes_tbl,
19915 					    p_validate_only     => FALSE
19916 					    );
19917 
19918 					 IF (l_validation_status <> 'Y'
19919 					     OR x_return_status <> g_ret_sts_success) THEN
19920 					    --raise error
19921 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19922 					    fnd_msg_pub.ADD;
19923 					    l_progress := 'WMSINB-22941';
19924 					    RAISE fnd_api.g_exc_error;
19925 					 END IF;
19926 
19927 					 --UPDATE GROUP_MARK_ID TO -7937
19928 					 IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
19929 					    --raise error
19930 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19931 					    fnd_msg_pub.ADD;
19932 					    l_progress := 'WMSINB-22951';
19933 					    RAISE fnd_api.g_exc_error;
19934 					 END IF;
19935 				       ELSE
19936 					 --raise error
19937 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19938 					 fnd_msg_pub.ADD;
19939 					 l_progress := 'WMSINB-22958';
19940 					 RAISE fnd_api.g_exc_error;
19941 				      END IF;
19942 			     END IF; --IF l_serial_exists = 1 THEN
19943 			   ELSIF (l_serial_number_control_code = 6 AND
19944 				  l_source_document_code = 'RMA') THEN
19945 				   IF l_serial_exists = 1 THEN
19946                   --bug#3571808 removed the current_org_id check
19947                   /*
19948 				      IF ((l_curr_org_id <> l_org_id) and not (l_restrict_rcpt_ser = '2'
19949 									       and l_curr_status = 4 ))  THEN
19950 					 --raise error
19951 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19952 					 fnd_msg_pub.ADD;
19953 					 l_progress := 'WMSINB-22969';
19954 					 RAISE fnd_api.g_exc_error;
19955 				       ELSE */
19956 					 IF ((l_curr_lot_num IS NOT NULL)
19957 					     AND (l_curr_lot_num <> l_mtlt_rec.lot_number)
19958 					     AND (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
19959 					    --raise error
19960 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19961 					    fnd_msg_pub.ADD;
19962 					    l_progress := 'WMSINB-22976';
19963 					    RAISE fnd_api.g_exc_error;
19964 					 END IF;
19965 				      --END IF;
19966 
19967 
19968 				      IF l_curr_status NOT IN (1,4,6) THEN
19969 					 --raise error
19970 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19971 					 fnd_msg_pub.ADD;
19972 					 l_progress := 'WMSINB-22985';
19973 					 RAISE fnd_api.g_exc_error;
19974 				      END IF;
19975 
19976 				      -- see if we need to restrict 4's based on
19977 				      -- inv_restrict_rcpt profile
19978 				      -- REVIEW at CODE REVIEW
19979 				      IF l_restrict_rcpt_ser <> 2 THEN
19980 					 l_dummy := '0';
19981 				         BEGIN
19982 					    SELECT '1'
19983 					      INTO l_dummy
19984 					      FROM dual
19985 					      WHERE exists (SELECT '1'
19986 							    FROM   mtl_serial_numbers
19987 							    WHERE  inventory_item_id = l_item_id
19988 							    AND    current_organization_id = l_org_id
19989 							    AND    current_status IN (1, 4) --Do we need 4 here
19990 							    AND    serial_number = l_serial_number
19991 							    AND    LAST_TXN_SOURCE_TYPE_ID = 12);
19992 
19993 					    IF l_dummy <> '0' THEN
19994 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
19995 					       fnd_msg_pub.ADD;
19996 					       l_progress := 'WMSINB-23009';
19997 					       RAISE fnd_api.g_exc_error;
19998 					    END IF;
19999 
20000 					 EXCEPTION
20001 					    WHEN no_data_found THEN
20002 					       NULL;
20003 					 END;
20004 				      END IF;
20005 
20006 				      IF (Nvl(l_group_mark_id, -99) = -7937) THEN
20007 					 --raise error
20008 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20009 					 fnd_msg_pub.ADD;
20010 					 l_progress := 'WMSINB-23023';
20011 					 RAISE fnd_api.g_exc_error;
20012 				      END IF;
20013 
20014 				      IF (Nvl(l_curr_status, 1) in (1,6)) THEN
20015 					 --validate and update the attributes.
20016 					 inv_serial_number_pub.validate_update_serial_att
20017 					   (x_return_status     => x_return_status,
20018 					    x_msg_count         => x_msg_count,
20019 					    x_msg_data          => x_msg_data,
20020 					    x_validation_status => l_validation_status,
20021 					    p_serial_number     => l_serial_number,
20022 					    p_organization_id   => l_org_id,
20023 					    p_inventory_item_id => l_item_id,
20024 					    p_serial_att_tbl    => l_serial_attributes_tbl,
20025 					    p_validate_only     => FALSE
20026 					    );
20027 
20028 					 IF (l_validation_status <> 'Y'
20029 					     OR x_return_status <> g_ret_sts_success) THEN
20030 					    --raise error
20031 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20032 					    fnd_msg_pub.ADD;
20033 					    l_progress := 'WMSINB-23030';
20034 					    RAISE fnd_api.g_exc_error;
20035 					 END IF;
20036 				      END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
20037 
20038 				      --UPDATE GROUP_MARK_ID TO -7937
20039 				      IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
20040 					 --raise error
20041 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20042 					 fnd_msg_pub.ADD;
20043 					 l_progress := 'WMSINB-23032';
20044 					 RAISE fnd_api.g_exc_error;
20045 				      END IF;
20046 				    ELSE --IF l_serial_exists = 1 THEN
20047 					 --PERFORM SERIAL VALIDATION FOR NEW SERIAL
20048 					 --(INCLUDING ATT VALIDATION)
20049 					 --CREATE MSN
20050 
20051 					 inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
20052 										   , p_inventory_item_id => l_item_id
20053 										   , p_organization_id => l_org_id
20054 										   , p_from_serial_number => l_serial_number
20055 										   , p_to_serial_number => l_serial_number
20056 										   , p_initialization_date => SYSDATE
20057 										   , p_completion_date => NULL
20058 										   , p_ship_date => NULL
20059 										   , p_revision => l_item_revision
20060 										   , p_lot_number => l_mtlt_rec.lot_number
20061 										   , p_current_locator_id => l_loc_id
20062 										   , p_subinventory_code => l_sub_code
20063 										   , p_trx_src_id => NULL
20064 										   , p_unit_vendor_id => NULL
20065 										   , p_vendor_lot_number => l_mtlt_rec.supplier_lot_number
20066 										   , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
20067 										   , p_receipt_issue_type => NULL
20068 										   , p_txn_src_id => NULL
20069 										   , p_txn_src_name => NULL
20070 										   , p_txn_src_type_id => NULL
20071 										   , p_transaction_id => NULL
20072 										   , p_current_status => 1
20073 					   , p_parent_item_id => NULL
20074 					   , p_parent_serial_number => NULL
20075 					   , p_cost_group_id => NULL
20076 					   , p_transaction_action_id => 27
20077 					   , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
20078 					   , p_status_id => NULL
20079 					   , p_inspection_status => NULL
20080 					   , x_object_id => l_object_id
20081 					   , x_return_status => x_return_status
20082 					   , x_msg_count => x_msg_count
20083 					   , x_msg_data => x_msg_data);
20084 
20085 
20086 					 IF (x_return_status <> g_ret_sts_success) THEN
20087 					    --raise error
20088 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20089 					    fnd_msg_pub.ADD;
20090 					    l_progress := 'WMSINB-23035';
20091 					    RAISE fnd_api.g_exc_error;
20092 					 END IF;
20093 
20094 					 --validate and update the attributes.
20095 					 inv_serial_number_pub.validate_update_serial_att
20096 					   (x_return_status     => x_return_status,
20097 					    x_msg_count         => x_msg_count,
20098 					    x_msg_data          => x_msg_data,
20099 					    x_validation_status => l_validation_status,
20100 					    p_serial_number     => l_serial_number,
20101 					    p_organization_id   => l_org_id,
20102 					    p_inventory_item_id => l_item_id,
20103 					    p_serial_att_tbl    => l_serial_attributes_tbl,
20104 					    p_validate_only     => FALSE
20105 					    );
20106 
20107 					 IF (l_validation_status <> 'Y'
20108 					     OR x_return_status <> g_ret_sts_success) THEN
20109 					    --raise error
20110 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20111 					    fnd_msg_pub.ADD;
20112 					    l_progress := 'WMSINB-23069';
20113 					    RAISE fnd_api.g_exc_error;
20114 					 END IF;
20115 
20116 					 --UPDATE GROUP_MARK_ID TO -7937
20117 					 IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
20118 					    --raise error
20119 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20120 					    fnd_msg_pub.ADD;
20121 					    l_progress := 'WMSINB-23079';
20122 					    RAISE fnd_api.g_exc_error;
20123 					 END IF;
20124 				   END IF; --IF l_serial_exists = 1 THEN
20125 			  END IF; --IF l_serial_number_control_code IN (2,5) THEN
20126 			ELSE --IF NOT L_SERIAL_ENTERED_ON_PARENT THEN
20127 			   BEGIN
20128 			      SELECT '1'
20129 				INTO L_DUMMY
20130 				FROM RCV_SERIALS_SUPPLY
20131 				WHERE TRANSACTION_ID = L_PARENT_TRANSACTION_ID
20132 				AND SERIAL_NUM = L_SERIAL_NUMBER;
20133 
20134 			      IF (l_curr_status <> 7) THEN
20135 				 --raise error
20136 				 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20137 				 fnd_msg_pub.ADD;
20138 				 l_progress := 'WMSINB-23096';
20139 				 RAISE fnd_api.g_exc_error;
20140 			      END IF;
20141 
20142 			      --Validate Serial/Inspection_status
20143                          /*  Commented for bug 6269102
20144                           *  To allow the inspection done again
20145                 	  *  on an inspection transaction to succeed
20146 		          *  as it was failing because of the
20147         		  *  inspection status <> 1
20148 
20149 			      IF l_transaction_type IN ('ACCEPT', 'REJECT') THEN
20150 				 IF (Nvl(l_inspection_status, 1) <> 1) THEN
20151 				    --raise error
20152 				    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20153 				    fnd_msg_pub.ADD;
20154 				    l_progress := 'WMSINB-23106';
20155 				    RAISE fnd_api.g_exc_error;
20156 				 END IF;
20157 			       ELS */
20158 			       IF l_transaction_type = 'DELIVER' THEN
20159 				 IF (l_routing_header_id = 2) THEN
20160 				    IF l_inspection_status IS NOT NULL AND l_inspection_status = 1 THEN
20161 				       --raise error
20162 				       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20163 				       fnd_msg_pub.ADD;
20164 				       l_progress := 'WMSINB-23115';
20165 				       RAISE fnd_api.g_exc_error;
20166 				    END IF;
20167 				 END IF;
20168 			      END IF;
20169 
20170 			      --Validate serial/group_mark_id to prevent
20171 			      --entering of duplicate serials
20172 
20173 			      IF (Nvl(l_group_mark_id, -99) = -7937) THEN
20174 				 --raise error
20175 				 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20176 				 fnd_msg_pub.ADD;
20177 				 l_progress := 'WMSINB-23128';
20178 				 RAISE fnd_api.g_exc_error;
20179 			      END IF;
20180 
20181 			      --UPDATE GROUP_MARK_ID TO -7937
20182 			      IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
20183 				 --raise error
20184 				 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20185 				 fnd_msg_pub.ADD;
20186 				 l_progress := 'WMSINB-23137';
20187 				 RAISE fnd_api.g_exc_error;
20188 			      END IF;
20189 			   EXCEPTION
20190 			      WHEN NO_DATA_FOUND THEN
20191 				 -- RAISE ERROR
20192 				 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20193 				 fnd_msg_pub.ADD;
20194 				 l_progress := 'WMSINB-23145';
20195 				 RAISE fnd_api.g_exc_error;
20196 			   END;
20197 		       END IF; --IF NOT L_SERIAL_ENTERED_ON_PARENT THEN
20198 		    END LOOP; -- FOR 1..L_SERIAL_QUANTITY
20199 		 END LOOP; --FETCH C_MSNT_LOTSERIAL INTO L_MSNT_REC;
20200 
20201 		 CLOSE c_msnt_lotserial;
20202 
20203 		 IF (l_num_msnt_recs > 0) THEN
20204 		    IF l_mtlt_rec.primary_quantity <> l_tot_msnt_serial_qty THEN
20205 		       --raise error
20206 		       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20207 		       fnd_msg_pub.ADD;
20208 		       l_progress := 'WMSINB-23159';
20209 		       RAISE fnd_api.g_exc_error;
20210 		    END IF;
20211 		  ELSE
20212 
20213 		    IF l_source_document_code IN ('INVENTORY', 'REQ') THEN
20214 		       GET_SERIAL_LOT_CTRL_IN_SRC_ORG
20215 			 (L_SHIPMENT_LINE_ID, L_ORG_ID,
20216 			  L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
20217 			  l_from_org_rev_ctrl,
20218 			  X_RETURN_STATUS, X_MSG_COUNT,
20219 			  x_msg_data);
20220 		    END IF;
20221 
20222 		    IF (l_serial_number_control_code IN (2,5)
20223 			OR (l_serial_number_control_code = 6
20224 			    AND l_source_document_code IN ('RMA'))
20225 			OR (l_serial_number_control_code = 6
20226 			    AND l_source_document_code = 'INVENTORY'
20227 			    AND l_from_org_ser_crtl IN (2,5))
20228 			--BUG 3644289: Do the following check for INTREQ
20229 			OR (l_serial_number_control_code = 6
20230 			    AND l_from_org_ser_crtl IN (2,5,6)
20231 			    AND l_source_document_code = 'REQ')) THEN
20232 		       --raise error
20233 		       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20234 		       fnd_msg_pub.ADD;
20235 		       l_progress := 'WMSINB-23166';
20236 		       RAISE fnd_api.g_exc_error;
20237 		    END IF;
20238 		 END IF;
20239 
20240 	      END IF; -- IF (L_SERIAL_NUMBER_CONTROL_CODE IN (2,5,6)) THEN
20241 	   END LOOP; --FETCH C_MTLT INTO L_MTLT_REC;
20242 
20243 	   CLOSE c_mtlt;
20244 
20245         /* Bug 4546519 : l_tot_mtlt_prim_qty is a computed floating point number.
20246          **  In the following condition, it is necessary to use round function for
20247          **  comparing the floating point values.
20248          */
20249 
20250 	   IF (l_num_mtlt_recs > 0) THEN
20251 	      IF (ROUND(l_tot_mtlt_prim_qty,5) <> ROUND(l_rti_primary_qty,5)) THEN
20252 		-- Bug# 4225766 Compare transaction qty there can be a difference in primary qty
20253 		-- if there is a lot specific conversion
20254 		IF (ROUND(l_tot_mtlt_trans_qty,5) <> ROUND(l_rti_trans_qty,5)) THEN -- Bug# 4225766
20255 			--raise error
20256 			l_progress := 'WMSINB-23178';
20257 			RAISE fnd_api.g_exc_error;
20258 		END IF; -- Bug# 4225766
20259 	      END IF;
20260 	    ELSE
20261 	      IF (l_transaction_type = 'DELIVER'
20262 		  OR Nvl(l_auto_transact_code,'@@@@') = 'DELIVER') THEN
20263 		 --raise error;
20264 		 l_progress := 'WMSINB-23184';
20265 		 RAISE fnd_api.g_exc_error;
20266 	       ELSIF (lot_entered_on_parent(l_parent_transaction_id)) THEN
20267 		 --raise error;
20268 		 l_progress := 'WMSINB-23188';
20269 		 RAISE fnd_api.g_exc_error;
20270 	      END IF;
20271 	   END IF;
20272 	 ELSIF l_serial_number_control_code IN (2,5,6) THEN --IF (L_LOT_CONTROL_CODE = 2) THEN
20273 
20274 				IF (l_debug = 1) THEN
20275 				   print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROLLED: '||l_progress, 1);
20276 				   print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROL CODE: '||l_serial_number_control_code||' : '||l_progress, 1);
20277 				   print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||l_source_document_code||' : '||l_progress, 1);
20278 				   l_progress := 'WMSINB-23198';
20279 				END IF;
20280 				L_NUM_MSNT_RECS := 0;
20281 				l_tot_msnt_serial_qty := 0;
20282 
20283 				OPEN C_MSNT(L_RTI_ID);
20284 
20285 				LOOP
20286 				   FETCH C_MSNT INTO L_MSNT_REC;
20287 
20288 				   EXIT WHEN C_MSNT%NOTFOUND;
20289 
20290 				   L_NUM_MSNT_RECS := L_NUM_MSNT_RECS + 1;
20291 
20292 				   IF (L_SERIAL_NUMBER_CONTROL_CODE = 6 AND
20293 				       L_SOURCE_DOCUMENT_CODE NOT IN ('RMA','REQ','INVENTORY')) THEN
20294 				      -- RAISE AN ERROR. IF SERIAL IS AT SALES ORDER ISSUE THEN
20295 				      -- IT CAN BE ENTERED ONLY FOR A RMA RECEIPT.
20296 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20297 				      fnd_msg_pub.ADD;
20298 				      l_progress := 'WMSINB-23218';
20299 				      RAISE fnd_api.g_exc_error;
20300 				   END IF;
20301 
20302 				   L_SERIAL_QUANTITY :=
20303 				     INV_SERIAL_NUMBER_PUB.GET_SERIAL_DIFF(L_MSNT_REC.FM_SERIAL_NUMBER,
20304 									   L_MSNT_REC.TO_SERIAL_NUMBER);
20305 
20306 				   l_tot_msnt_serial_qty := l_tot_msnt_serial_qty +
20307 				     l_serial_quantity;
20308 
20309 				   INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.FM_SERIAL_NUMBER, L_TEMP_PREFIX, L_FROM_SER_NUMBER);
20310 		                   INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.TO_SERIAL_NUMBER, L_TEMP_PREFIX, L_TO_SER_NUMBER);
20311 
20312 				   IF (l_debug = 1) THEN
20313 				      print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL QUANTITY: '||l_serial_quantity||' : '||l_progress, 1);
20314 				      l_progress := 'WMSINB-23233';
20315 				   END IF;
20316 
20317 				   --populate attributes table
20318 				   l_serial_attributes_tbl(1).column_name   := 'SERIAL_ATTRIBUTE_CATEGORY';
20319 				   l_serial_attributes_tbl(1).column_value  := l_msnt_rec.serial_attribute_category;
20320 				   l_serial_attributes_tbl(2).column_name   := 'ORIGINATION_DATE';
20321 				   l_serial_attributes_tbl(2).column_value  := l_msnt_rec.origination_date;
20322 				   l_serial_attributes_tbl(3).column_name   := 'C_ATTRIBUTE1';
20323 				   l_serial_attributes_tbl(3).column_value  := l_msnt_rec.c_attribute1;
20324 				   l_serial_attributes_tbl(4).column_name   := 'C_ATTRIBUTE2';
20325 				   l_serial_attributes_tbl(4).column_value  := l_msnt_rec.c_attribute2;
20326 				   l_serial_attributes_tbl(5).column_name   := 'C_ATTRIBUTE3';
20327 				   l_serial_attributes_tbl(5).column_value  := l_msnt_rec.c_attribute3;
20328 				   l_serial_attributes_tbl(6).column_name   := 'C_ATTRIBUTE4';
20329 				   l_serial_attributes_tbl(6).column_value   := l_msnt_rec.c_attribute4;
20330 				   l_serial_attributes_tbl(7).column_name   := 'C_ATTRIBUTE5';
20331 				   l_serial_attributes_tbl(7).column_value   := l_msnt_rec.c_attribute5;
20332 				   l_serial_attributes_tbl(8).column_name   := 'C_ATTRIBUTE6';
20333 				   l_serial_attributes_tbl(8).column_value   := l_msnt_rec.c_attribute6;
20334 				   l_serial_attributes_tbl(9).column_name   := 'C_ATTRIBUTE7';
20335 				   l_serial_attributes_tbl(9).column_value   := l_msnt_rec.c_attribute7;
20336 				   l_serial_attributes_tbl(10).column_name  := 'C_ATTRIBUTE8';
20337 				   l_serial_attributes_tbl(10).column_value  := l_msnt_rec.c_attribute8;
20338 				   l_serial_attributes_tbl(11).column_name  := 'C_ATTRIBUTE9';
20339 				   l_serial_attributes_tbl(11).column_value  := l_msnt_rec.c_attribute9;
20340 				   l_serial_attributes_tbl(12).column_name  := 'C_ATTRIBUTE10';
20341 				   l_serial_attributes_tbl(12).column_value  := l_msnt_rec.c_attribute10;
20342 				   l_serial_attributes_tbl(13).column_name  := 'C_ATTRIBUTE11';
20343 				   l_serial_attributes_tbl(13).column_value  := l_msnt_rec.c_attribute11;
20344 				   l_serial_attributes_tbl(14).column_name  := 'C_ATTRIBUTE12';
20345 				   l_serial_attributes_tbl(14).column_value  := l_msnt_rec.c_attribute12;
20346 				   l_serial_attributes_tbl(15).column_name  := 'C_ATTRIBUTE13';
20347 				   l_serial_attributes_tbl(15).column_value  := l_msnt_rec.c_attribute13;
20348 				   l_serial_attributes_tbl(16).column_name  := 'C_ATTRIBUTE14';
20349 				   l_serial_attributes_tbl(16).column_value  := l_msnt_rec.c_attribute14;
20350 				   l_serial_attributes_tbl(17).column_name  := 'C_ATTRIBUTE15';
20351 				   l_serial_attributes_tbl(17).column_value  := l_msnt_rec.c_attribute15;
20352 				   l_serial_attributes_tbl(18).column_name  := 'C_ATTRIBUTE16';
20353 				   l_serial_attributes_tbl(18).column_value  := l_msnt_rec.c_attribute16;
20354 				   l_serial_attributes_tbl(19).column_name  := 'C_ATTRIBUTE17';
20355 				   l_serial_attributes_tbl(19).column_value  := l_msnt_rec.c_attribute17;
20356 				   l_serial_attributes_tbl(20).column_name  := 'C_ATTRIBUTE18';
20357 				   l_serial_attributes_tbl(20).column_value  := l_msnt_rec.c_attribute18;
20358 				   l_serial_attributes_tbl(21).column_name  := 'C_ATTRIBUTE19';
20359 				   l_serial_attributes_tbl(21).column_value  := l_msnt_rec.c_attribute19;
20360 				   l_serial_attributes_tbl(22).column_name  := 'C_ATTRIBUTE20';
20361 				   l_serial_attributes_tbl(22).column_value  := l_msnt_rec.c_attribute20;
20362 				   l_serial_attributes_tbl(23).column_name  := 'D_ATTRIBUTE1';
20363 				   l_serial_attributes_tbl(23).column_value  := l_msnt_rec.d_attribute1;
20364 				   l_serial_attributes_tbl(24).column_name  := 'D_ATTRIBUTE2';
20365 				   l_serial_attributes_tbl(24).column_value  := l_msnt_rec.d_attribute2;
20366 				   l_serial_attributes_tbl(25).column_name  := 'D_ATTRIBUTE3';
20367 				   l_serial_attributes_tbl(25).column_value  := l_msnt_rec.d_attribute3;
20368 				   l_serial_attributes_tbl(26).column_name  := 'D_ATTRIBUTE4';
20369 				   l_serial_attributes_tbl(26).column_value  := l_msnt_rec.d_attribute4;
20370 				   l_serial_attributes_tbl(27).column_name  := 'D_ATTRIBUTE5';
20371 				   l_serial_attributes_tbl(27).column_value  := l_msnt_rec.d_attribute5;
20372 				   l_serial_attributes_tbl(28).column_name  := 'D_ATTRIBUTE6';
20373 				   l_serial_attributes_tbl(28).column_value  := l_msnt_rec.d_attribute6;
20374 				   l_serial_attributes_tbl(29).column_name  := 'D_ATTRIBUTE7';
20375 				   l_serial_attributes_tbl(29).column_value  := l_msnt_rec.d_attribute7;
20376 				   l_serial_attributes_tbl(30).column_name  := 'D_ATTRIBUTE8';
20377 				   l_serial_attributes_tbl(30).column_value  := l_msnt_rec.d_attribute8;
20378 				   l_serial_attributes_tbl(31).column_name  := 'D_ATTRIBUTE9';
20379 				   l_serial_attributes_tbl(31).column_value  := l_msnt_rec.d_attribute9;
20380 				   l_serial_attributes_tbl(32).column_name  := 'D_ATTRIBUTE10';
20381 				   l_serial_attributes_tbl(32).column_value  := l_msnt_rec.d_attribute10;
20382 				   l_serial_attributes_tbl(33).column_name  := 'N_ATTRIBUTE1';
20383 				   l_serial_attributes_tbl(33).column_value  := l_msnt_rec.n_attribute1;
20384 				   l_serial_attributes_tbl(34).column_name  := 'N_ATTRIBUTE2';
20385 				   l_serial_attributes_tbl(34).column_value  := l_msnt_rec.n_attribute2;
20386 				   l_serial_attributes_tbl(35).column_name  := 'N_ATTRIBUTE3';
20387 				   l_serial_attributes_tbl(35).column_value  := l_msnt_rec.n_attribute3;
20388 				   l_serial_attributes_tbl(36).column_name  := 'N_ATTRIBUTE4';
20389 				   l_serial_attributes_tbl(36).column_value  := l_msnt_rec.n_attribute4;
20390 				   l_serial_attributes_tbl(37).column_name  := 'N_ATTRIBUTE5';
20391 				   l_serial_attributes_tbl(37).column_value := l_msnt_rec.n_attribute5;
20392 				   l_serial_attributes_tbl(38).column_name  := 'N_ATTRIBUTE6';
20393 				   l_serial_attributes_tbl(38).column_value := l_msnt_rec.n_attribute6;
20394 				   l_serial_attributes_tbl(39).column_name  := 'N_ATTRIBUTE7';
20395 				   l_serial_attributes_tbl(39).column_value := l_msnt_rec.n_attribute7;
20396 				   l_serial_attributes_tbl(40).column_name  := 'N_ATTRIBUTE8';
20397 				   l_serial_attributes_tbl(40).column_value := l_msnt_rec.n_attribute8;
20398 				   l_serial_attributes_tbl(41).column_name  := 'N_ATTRIBUTE9';
20399 				   l_serial_attributes_tbl(41).column_value := l_msnt_rec.n_attribute9;
20400 				   l_serial_attributes_tbl(42).column_name  := 'N_ATTRIBUTE10';
20401 				   l_serial_attributes_tbl(42).column_value := l_msnt_rec.n_attribute10;
20402 				   l_serial_attributes_tbl(43).column_name  := 'STATUS_ID';
20403 				   l_serial_attributes_tbl(43).column_value := l_msnt_rec.status_id;
20404 				   l_serial_attributes_tbl(44).column_name  := 'TERRITORY_CODE';
20405 				   l_serial_attributes_tbl(44).column_value := l_msnt_rec.territory_code;
20406 
20407 				   --Validate the serials
20408 				   FOR SERIALQTY IN 1..L_SERIAL_QUANTITY LOOP
20409                                     L_CUR_NUMBER := L_FROM_SER_NUMBER+SERIALQTY -1;
20410                                     if L_FROM_SER_NUMBER = -1 and  L_TO_SER_NUMBER = -1 then
20411 	                                 L_SERIAL_NUMBER  := L_MSNT_REC.fm_serial_number;
20412 		                    else
20413 		                         L_SERIAL_NUMBER :=
20414 			                   SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
20415 				             LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
20416 				             LENGTH(L_CUR_NUMBER))
20417 			                   ||L_CUR_NUMBER;
20418                                     End if;
20419 
20420 				      --L_SERIAL_NUMBER :=
20421 					--SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
20422 					 --      LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
20423 					  --     LENGTH(L_FROM_SER_NUMBER))
20424 					--||(L_FROM_SER_NUMBER+SERIALQTY -1);
20425 
20426 	                              BEGIN
20427 					 SELECT CURRENT_ORGANIZATION_ID
20428 					   , current_status
20429 					   , lot_number
20430 					   , Decode(lpn_id,0,NULL,lpn_id)
20431 					   , inspection_status
20432 					   , group_mark_id
20433 					   , last_transaction_id --bug 5168883
20434 					   INTO L_CURR_ORG_ID
20435 					   , l_curr_status
20436 					   , l_curr_lot_num
20437 					   , l_curr_lpn_id
20438 					   , l_inspection_status
20439 					   , l_group_mark_id
20440 					   , l_last_transaction_id --bug 5168883
20441 					   FROM MTL_SERIAL_NUMBERS
20442 					   WHERE SERIAL_NUMBER = l_serial_number
20443 					   AND inventory_item_id = l_item_id;
20444 
20445 					 l_serial_exists := 1;
20446 				      EXCEPTION
20447 					 WHEN no_data_found THEN
20448 					    l_serial_exists := 0;
20449 				      END;
20450 
20451 				      IF (l_debug = 1) THEN
20452 					 print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL EXISTS: '||l_serial_exists||' : '||l_progress, 1);
20453 					 print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NUMBER: '||l_serial_number||' : '||l_progress, 1);
20454 					 print_debug('VALIDATE_LOT_SERIAL_INFO: CURR STATUS: '||l_curr_status||' : '||l_progress, 1);
20455 					 print_debug('VALIDATE_LOT_SERIAL_INFO: CURR ORG ID: '||l_curr_org_id||' : '||l_progress, 1);
20456 					 print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LPN ID: '||l_curr_lpn_id||' : '||l_progress, 1);
20457 					 print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LOT NUM: '||l_curr_lot_num||' : '||l_progress, 1);
20458 					 print_debug('VALIDATE_LOT_SERIAL_INFO: INSPECT STS: '||l_inspection_status||' : '||l_progress, 1);
20459 					 print_debug('VALIDATE_LOT_SERIAL_INFO: GROUP MARK ID: '||l_group_mark_id||' : '||l_progress, 1);
20460 					 print_debug('VALIDATE_LOT_SERIAL_INFO: RESTRICT RCPT SER: '||l_restrict_rcpt_ser||' : '||l_progress, 1);
20461 					 l_progress := 'WMSINB-23276';
20462 				      END IF;
20463 
20464 				      IF (L_TRANSACTION_TYPE <> 'RECEIVE') THEN
20465 					 L_SERIAL_ENTERED_ON_PARENT := SERIAL_ENTERED_ON_PARENT(L_PARENT_TRANSACTION_ID);
20466 				       ELSE
20467 					 L_SERIAL_ENTERED_ON_PARENT := FALSE;
20468 				      END IF;
20469 
20470 				      IF (l_debug = 1) THEN
20471 					 print_debug('VALIDATE_LOT_SERIAL_INFO: ASN LINE FLAG: '||l_asn_line_flag||' : '||l_progress, 1);
20472 					 l_progress := 'WMSINB-23287';
20473 				      END IF;
20474 
20475 				      IF NOT L_SERIAL_ENTERED_ON_PARENT THEN
20476 					 IF (l_debug = 1) THEN
20477 					    print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NOT ENTERED ON PARENT: '||l_progress, 1);
20478 					    l_progress := 'WMSINB-23293';
20479 					 END IF;
20480 					 IF (l_serial_number_control_code IN (2,5)
20481 					     OR (l_serial_number_control_code = 6
20482 						 AND l_source_document_code IN ('INVENTORY','REQ'))) THEN
20483 					    IF l_serial_exists = 1 THEN
20484 					       IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')
20485 						   OR l_asn_line_flag = 'Y') THEN
20486 
20487 						  IF (l_asn_line_flag = 'Y') THEN
20488 						     IF ((l_curr_org_id <> l_org_id) and not (l_restrict_rcpt_ser = '2'
20489 											      and l_curr_status = 4 ))  THEN
20490 							--raise error
20491 							l_progress := 'WMSINB-23303';
20492 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20493 							fnd_msg_pub.ADD;
20494 							l_progress := 'WMSINB-23306';
20495 							RAISE fnd_api.g_exc_error;
20496 						      ELSE
20497 							IF (l_curr_lot_num IS NOT NULL) THEN
20498 							   --raise error
20499 							   l_progress := 'WMSINB-23311';
20500 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20501 							   fnd_msg_pub.ADD;
20502 							   l_progress := 'WMSINB-23314';
20503 							   RAISE fnd_api.g_exc_error;
20504 							END IF;
20505 						     END IF;
20506 
20507 						     IF (rss_exists(l_shipment_header_id,l_item_id)) THEN
20508 			                                BEGIN
20509 							   SELECT '1'
20510 							     INTO l_dummy
20511 							     FROM rcv_serials_supply rss
20512 							     , rcv_shipment_lines rsl
20513 							     WHERE rss.SHIPMENT_LINE_ID = rsl.SHIPMENT_LINE_ID
20514 							     AND rsl.shipment_header_id = l_shipment_header_id
20515 							     AND rsl.item_id = l_item_id
20516 							     AND rss.supply_type_code = 'SHIPMENT'
20517 							     AND rss.serial_num = l_serial_number;
20518 
20519 							   IF (l_debug = 1) THEN
20520 							      print_debug('VALIDATE_LOT_SERIAL_INFO: RSS EXISTS: '||l_progress, 1);
20521 							      l_progress := 'WMSINB-23330';
20522 							   END IF;
20523 
20524 							   IF l_curr_status <> 5 THEN
20525 							      --raise error
20526 							      l_progress := 'WMSINB-23335';
20527 							      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20528 							      fnd_msg_pub.ADD;
20529 							      RAISE fnd_api.g_exc_error;
20530 							   END IF;
20531 							EXCEPTION
20532 							   WHEN no_data_found THEN
20533 							      IF l_restrict_rcpt_ser = '2' THEN
20534 								 IF l_curr_status NOT IN
20535 								   (1,4,6) THEN
20536 								    --raise error
20537 								    l_progress := 'WMSINB-23346';
20538 								    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20539 								    fnd_msg_pub.ADD;
20540 								    RAISE fnd_api.g_exc_error;
20541 								 END IF;
20542 							       ELSE --IF l_restrict_rcpt_ser = '2' THEN
20543 								 IF l_curr_status NOT IN
20544 								   (1,6) THEN
20545 								    --raise error
20546 								    l_progress := 'WMSINB-23355';
20547 								    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20548 								    fnd_msg_pub.ADD;
20549 								    RAISE fnd_api.g_exc_error;
20550 								 END IF;
20551 							      END IF; --IF l_restrict_rcpt_ser = '2' THEN
20552 							END;
20553 						      ELSE --IF (rss_exists(l_shipment_header_id,l_item_id)) THEN
20554 							      IF l_restrict_rcpt_ser = '2' THEN
20555 								 IF l_curr_status NOT IN
20556 								   (1,4,6) THEN
20557 								    --raise error
20558 								    l_progress := 'WMSINB-23367';
20559 								    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20560 								    fnd_msg_pub.ADD;
20561 								    RAISE fnd_api.g_exc_error;
20562 								 END IF;
20563 							       ELSE --IF l_restrict_rcpt_ser = '2' THEN
20564 								 IF l_curr_status NOT IN
20565 								   (1,6) THEN
20566 								    --raise error
20567 								    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20568 								    fnd_msg_pub.ADD;
20569 								    l_progress := 'WMSINB-23378';
20570 								    RAISE fnd_api.g_exc_error;
20571 								 END IF;
20572 							      END IF; --IF l_restrict_rcpt_ser = '2' THEN
20573 						     END IF; --IF (rss_exists(l_shipment_header_id,l_item_id)) THEN
20574 						  END IF; --IF (l_asn_line_flag = 'Y') THEN
20575 
20576 						  IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
20577 						     -- CHECK TO SEE IF THE ITEM IS SERIAL
20578 						     -- CONTROLLED IN SOURCE ORG
20579 
20580 						     GET_SERIAL_LOT_CTRL_IN_SRC_ORG
20581 						       (L_SHIPMENT_LINE_ID, L_ORG_ID,
20582 							L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
20583 							l_from_org_rev_ctrl, X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
20584 
20585 						     IF ((L_FROM_ORG_SER_CRTL IN (2,5,6)
20586 							  AND l_source_document_code = 'REQ')
20587 							 OR (l_from_org_ser_crtl IN (2,5)
20588 							     AND l_source_document_code = 'INVENTORY')
20589 							 ) THEN
20590 
20591                                                         /*****bug4187663, comment out the call to serial uniqueness check, the check will be in TM
20592 							IF (l_source_document_code = 'REQ') THEN
20593 							   l_txn_src_type_id := 7;
20594 							 ELSE
20595 							   l_txn_src_type_id := 13;
20596 							END IF;
20597 
20598 							--Validate Serial Uniqueness in current org.
20599 							IF (l_debug = 1) THEN
20600 							   print_debug('VALIDATE_LOT_SERIAL_INFO: CALLING IS_SERNUM_UNIQUE...', 1);
20601 							END IF;
20602 
20603 							IF (is_sernum_unique(l_org_id, l_item_id,l_serial_number,l_txn_src_type_id,12,x_msg_data)<>0) THEN
20604 							   --raise error
20605 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20606 							   fnd_msg_pub.ADD;
20607 							   l_progress := 'WMSINB-22725';
20608 							   RAISE fnd_api.g_exc_error;
20609 							END IF;
20610 
20611 							IF (l_debug = 1) THEN
20612 							   print_debug('VALIDATE_LOT_SERIAL_INFO: CALLING IS_SERNUM_UNIQUE...DONE', 1);
20613 							END IF;
20614                                                         *****end of bug4187663*****/
20615 
20616 							IF l_curr_org_id <> l_from_org_id THEN
20617 							   --raise error
20618 							   l_progress := 'WMSINB-23397';
20619 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20620 							   fnd_msg_pub.ADD;
20621 							   RAISE fnd_api.g_exc_error;
20622 							 ELSE
20623 							   IF (l_curr_lot_num IS NOT NULL) THEN
20624 
20625                            if (L_FROM_ORG_LOT_CTRL = 1 ) then
20626 							      --raise error
20627 							         l_progress := 'WMSINB-23404';
20628 							         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20629 							         fnd_msg_pub.ADD;
20630 							         RAISE fnd_api.g_exc_error;
20631                            else
20632 							         --update the serial row
20633 							         IF (l_debug = 1) THEN
20634 							            print_debug('VALIDATE_LOT_SERIAL_INFO: UPDATING LOT_NUMBER to null as destination org is not lot controlled', 1);
20635 							         END IF;
20636                                                                  update mtl_serial_numbers msn
20637                                                                     set lot_number = null
20638                                                                   where msn.serial_number = l_serial_number
20639                                                                     AND inventory_item_id = l_item_id;
20640                                                               end if;
20641 							   END IF;
20642 							END IF;
20643 
20644 			                                BEGIN
20645 							   SELECT '1'
20646 							     INTO L_DUMMY
20647 							     FROM rcv_serials_supply rss
20648 							     , rcv_shipment_lines rsl
20649 							     WHERE rss.SHIPMENT_LINE_ID = rsl.SHIPMENT_LINE_ID
20650 							     AND rsl.shipment_header_id = l_shipment_header_id
20651 							     AND rsl.item_id = l_item_id
20652 							     AND rss.SUPPLY_TYPE_CODE = 'SHIPMENT'
20653 							     AND rss.serial_num = l_serial_number;
20654 
20655 							   IF L_CURR_STATUS <> 5 THEN
20656 							      -- RAISE AN ERROR
20657 							      l_progress := 'WMSINB-23421';
20658 							      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20659 							      fnd_msg_pub.ADD;
20660 							      RAISE fnd_api.g_exc_error;
20661 							   END IF;
20662 
20663 							EXCEPTION
20664 							   WHEN NO_DATA_FOUND THEN
20665 							      -- RAISE AN ERROR
20666 							      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20667 							      fnd_msg_pub.ADD;
20668 							      l_progress := 'WMSINB-23432';
20669 							      RAISE fnd_api.g_exc_error;
20670 							END;
20671 						      ELSE --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
20672 							      IF L_CURR_ORG_ID <> l_org_id THEN
20673                       --BUG 5524134
20674                       /* In case of serial numbers in status 4
20675                       i.e. issued out of stores, we need to
20676                       honor the INV_RESTRICT_RCPT_SER profile.
20677                       And for serial status defined but not used
20678                       error out only if the org id in MSN is equal to
20679                       that present in the RSL.
20680                       */
20681                       BEGIN
20682                            SELECT from_organization_id
20683                            INTO l_from_org_id
20684                            FROM rcv_shipment_lines
20685                            WHERE shipment_line_id = L_SHIPMENT_LINE_ID;
20686                       EXCEPTION
20687                         WHEN NO_DATA_FOUND THEN
20688                         -- RAISE AN ERROR
20689                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20690                         fnd_msg_pub.ADD;
20691                         l_progress := 'WMSINB-23433';
20692                         RAISE fnd_api.g_exc_error;
20693                       END;
20694                       --BEGIN Bug: 5524134
20695                       IF L_SOURCE_DOCUMENT_CODE IN ( 'INVENTORY' , 'REQ' ) THEN
20696                          IF NOT (
20697                                  ( L_CURR_STATUS = 1 AND L_CURR_ORG_ID = l_from_org_id)
20698                               OR ( L_CURR_STATUS = 4 AND l_restrict_rcpt_ser = '2' )
20699                                 )
20700                                THEN
20701                                l_progress := 'WMSINB-23435';
20702                                IF (l_debug = 1) THEN
20703                                     print_debug('For Intransit receipt the serial number org does not match the sending org!', 1);
20704                                END IF;
20705         								 --raise error
20706         								 l_progress := 'WMSINB-23438';
20707         								 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20708         								 fnd_msg_pub.ADD;
20709         								 RAISE fnd_api.g_exc_error;
20710                          END IF;
20711                      ELSE
20712                          l_progress := 'WMSINB-23438';
20713                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20714                          fnd_msg_pub.ADD;
20715                          RAISE fnd_api.g_exc_error;
20716                      END IF;
20717                      --END Bug: 5524134
20718 							       ELSE
20719 								 IF (l_curr_lot_num IS NOT NULL) THEN
20720 								    --raise error
20721 								    l_progress := 'WMSINB-23445';
20722 								    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20723 								    fnd_msg_pub.ADD;
20724 								    RAISE fnd_api.g_exc_error;
20725 								 END IF;
20726 							      END IF;
20727 
20728 							      IF L_CURR_STATUS NOT IN (1,6)
20729                        AND NOT (l_restrict_rcpt_ser = '2'and l_curr_status = 4 ) --Bug: 5524134
20730                        THEN
20731 								 -- RAISE AN ERROR
20732 								 l_progress := 'WMSINB-23454';
20733 								 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20734 								 fnd_msg_pub.ADD;
20735 								 RAISE fnd_api.g_exc_error;
20736 							      END IF;
20737 						     END IF; --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
20738 						  END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
20739 						ELSE  --IF (L_SOURCE_DOCUMENT_CODE IN
20740 						     --('INVENTORY','REQ') OR l_asn_line_flag = 'Y') THEN
20741 						     IF ((L_SOURCE_DOCUMENT_CODE <> 'RMA' AND l_curr_org_id <> l_org_id )
20742                            and not (l_restrict_rcpt_ser = '2'and l_curr_status = 4 ) )  THEN
20743 							--raise error
20744 							l_progress := 'WMSINB-23465';
20745 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20746 							fnd_msg_pub.ADD;
20747 							RAISE fnd_api.g_exc_error;
20748 
20749                                                       --BUG 5114851 (FP of BUG 5060131):
20750                                                       --For RMA, the item for the original org of
20751                                                       --the serial number may be lot serial controlled, while
20752                                                       --the receiving org is not lot controlled.  So bypass
20753                                                       --the lot check for RMA
20754 						      --ELSIF (l_source_document_code <> 'RMA') THEN
20755                                                       -- bug 5259803
20756                                                       ELSIF ((l_source_document_code <> 'RMA')
20757                                                        AND NOT (l_source_document_code = 'PO' AND l_restrict_rcpt_ser = '2' AND l_curr_status = 4 )) THEN
20758 							IF (l_curr_lot_num IS NOT NULL) THEN
20759 							   --raise error
20760 							   l_progress := 'WMSINB-23472';
20761 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20762 							   fnd_msg_pub.ADD;
20763 							   RAISE fnd_api.g_exc_error;
20764 							END IF;
20765 						     END IF;
20766 
20767 						     --bug 5168883
20768 						     BEGIN
20769 						       select transaction_type_id
20770 						       into   l_last_transaction_type_id
20771 						       from   mtl_material_transactions
20772 						       where  transaction_id = l_last_transaction_id;
20773 						     EXCEPTION
20774 						       when others then
20775 						         l_last_transaction_type_id := null;
20776 						     END;
20777 						     -- end bug 5168883
20778 
20779 						     IF l_restrict_rcpt_ser = '2' THEN
20780 							IF l_curr_status NOT IN (1,4,6) THEN
20781 							   --raise error
20782 							   l_progress := 'WMSINB-23482';
20783 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20784 							   fnd_msg_pub.ADD;
20785 							   RAISE fnd_api.g_exc_error;
20786 							END IF;
20787 
20788    /* Bug 6847337:
20789     * Fix done to allow the re-using of serials after the
20790     * correction of a PO receipt by handling the transaction type
20791     * for correction(71) along with return to vendor(36) in
20792     * the following ELSE condition.
20793     */
20794 						      ELSE --IF l_restrict_rcpt_ser = '2' THEN
20795 							IF ((l_curr_status NOT IN (1,6))
20796 							    AND NOT (l_curr_status = 4 and
20797 								     (l_source_document_code = 'RMA'
20798 								      OR (l_source_document_code = 'PO'
20799 								          and l_last_transaction_type_id in(36,71))))) THEN --bug 5168883
20800 							   --raise error
20801 							   l_progress := 'WMSINB-23490';
20802 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20803 							   fnd_msg_pub.ADD;
20804 							   RAISE fnd_api.g_exc_error;
20805 							END IF;
20806 						     END IF; --IF l_restrict_rcpt_ser = '2' THEN
20807 
20808 					       END IF; --IF (L_SOURCE_DOCUMENT_CODE IN
20809 					       --('INVENTORY','REQ') OR l_asn_line_flag = 'Y') THEN
20810 
20811 					       --Validate serial/LPN
20812 					       IF l_transaction_type = 'RECEIVE' THEN
20813 						  IF (l_source_document_code IN ('INVENTORY', 'REQ')) then
20814 						     IF (Nvl(l_curr_lpn_id, -9999) <>
20815 							 Nvl(l_lpn_id, -9999)
20816 							 AND
20817 							  ( Nvl(l_curr_status,1) NOT IN (1,5)
20818 							    AND NOT (l_restrict_rcpt_ser = '2'and l_curr_status = 4 ) --Bug 5524134
20819 					      )
20820                ) THEN --bug 5235808 changed from 4 to 5
20821 							--raise error
20822 							l_progress := 'WMSINB-23506';
20823 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20824 							fnd_msg_pub.ADD;
20825 							RAISE fnd_api.g_exc_error;
20826 						     END IF;
20827 						  END IF;
20828 						ELSE
20829 						  IF (Nvl(l_curr_lpn_id, -9999) <>
20830 						      Nvl(l_lpn_id, -9999)
20831 						      AND Nvl(l_curr_status,1) <> 4) THEN
20832 						     --raise error
20833 						     l_progress := 'WMSINB-23516';
20834 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20835 						     fnd_msg_pub.ADD;
20836 						     RAISE fnd_api.g_exc_error;
20837 						  END IF;
20838 					       END IF;
20839 
20840 					       --Validate Serial/Inspection_status
20841                            /*  Commented for bug 6269102
20842                           *  To allow the inspection done again
20843                 	  *  on an inspection transaction to succeed
20844 		          *  as it was failing because of the
20845         		  *  inspection status <> 1
20846 
20847 					       IF l_transaction_type IN ('ACCEPT', 'REJECT') THEN
20848 						  IF (Nvl(l_inspection_status, 1) <> 1) THEN
20849 						     --raise error
20850 						     l_progress := 'WMSINB-23527';
20851 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20852 						     fnd_msg_pub.ADD;
20853 						     RAISE fnd_api.g_exc_error;
20854 						  END IF;
20855 						ELS */
20856 						IF l_transaction_type = 'DELIVER' THEN
20857 						  IF (l_routing_header_id = 2) THEN
20858 						     IF l_inspection_status IS NOT NULL AND l_inspection_status = 1 THEN
20859 						       --raise error
20860 							l_progress := 'WMSINB-23536';
20861 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20862 							fnd_msg_pub.ADD;
20863 							RAISE fnd_api.g_exc_error;
20864 						     END IF;
20865 						  END IF;
20866 					       END IF;
20867 
20868 					       --Validate serial/group_mark_id to prevent
20869 					       --entering of duplicate serials
20870 
20871 					       IF (Nvl(l_group_mark_id, -99) = -7937) THEN
20872 						  --raise error
20873 						  l_progress := 'WMSINB-23549';
20874 						  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20875 						  fnd_msg_pub.ADD;
20876 						  RAISE fnd_api.g_exc_error;
20877 					       END IF;
20878 
20879 					       IF (Nvl(l_curr_status, 1) in (1,6)) THEN
20880 						  --validate and update the attributes.
20881 						  inv_serial_number_pub.validate_update_serial_att
20882 						    (x_return_status     => x_return_status,
20883 						     x_msg_count         => x_msg_count,
20884 						     x_msg_data          => x_msg_data,
20885 						     x_validation_status => l_validation_status,
20886 						     p_serial_number     => l_serial_number,
20887 						     p_organization_id   => l_org_id,
20888 						     p_inventory_item_id => l_item_id,
20889 						     p_serial_att_tbl    => l_serial_attributes_tbl,
20890 						     p_validate_only     => FALSE
20891 						     );
20892 
20893 						  IF (l_validation_status <> 'Y'
20894 						      OR x_return_status <> g_ret_sts_success) THEN
20895 						     --raise error
20896 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20897 						     fnd_msg_pub.ADD;
20898 						     l_progress := 'WMSINB-22555';
20899 						     RAISE fnd_api.g_exc_error;
20900 						  END IF;
20901 					       END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
20902 
20903 					       --UPDATE GROUP_MARK_ID TO -7937
20904 					       IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
20905 						  --raise error
20906 						  l_progress := 'WMSINB-23558';
20907 						  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20908 						  fnd_msg_pub.ADD;
20909 						  RAISE fnd_api.g_exc_error;
20910 					       END IF;
20911 
20912 					     ELSE --IF l_serial_exists = 1 THEN
20913 						     IF (l_source_document_code IN ('INVENTORY','REQ')) THEN
20914 							GET_SERIAL_LOT_CTRL_IN_SRC_ORG
20915 							  (L_SHIPMENT_LINE_ID, L_ORG_ID,
20916 							   L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
20917 							   l_from_org_rev_ctrl, X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
20918 
20919 							IF ((L_FROM_ORG_SER_CRTL IN (2,5,6)
20920 							     AND l_source_document_code = 'REQ')
20921 							    OR (l_from_org_ser_crtl IN (2,5)
20922 								AND l_source_document_code = 'INVENTORY')
20923 							    ) THEN
20924 							   --raise error
20925 							   l_progress := 'WMSINB-23573';
20926 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20927 							   fnd_msg_pub.ADD;
20928 							   RAISE fnd_api.g_exc_error;
20929 							END IF;
20930 						     END IF;
20931 
20932 						     IF l_serial_number_control_code = 5 THEN
20933 							--PERFORM SERIAL VALIDATION FOR NEW SERIAL
20934 							--(INCLUDING ATT VALIDATION)
20935 							--CREATE MSN
20936 
20937 							inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
20938 												  , p_inventory_item_id => l_item_id
20939 												  , p_organization_id => l_org_id
20940 												  , p_from_serial_number => l_serial_number
20941 												  , p_to_serial_number => l_serial_number
20942 												  , p_initialization_date => SYSDATE
20943 												  , p_completion_date => NULL
20944 												  , p_ship_date => NULL
20945 												  , p_revision => l_item_revision
20946 												  , p_lot_number => NULL
20947 												  , p_current_locator_id => l_loc_id
20948 												  , p_subinventory_code => l_sub_code
20949 												  , p_trx_src_id => NULL
20950 												  , p_unit_vendor_id => NULL
20951 												  , p_vendor_lot_number => NULL
20952 												  , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
20953 												  , p_receipt_issue_type => NULL
20954 												  , p_txn_src_id => NULL
20955 												  , p_txn_src_name => NULL
20956 												  , p_txn_src_type_id => NULL
20957 												  , p_transaction_id => NULL
20958 												  , p_current_status => 1
20959 												  , p_parent_item_id => NULL
20960 							  , p_parent_serial_number => NULL
20961 							  , p_cost_group_id => NULL
20962 							  , p_transaction_action_id => 27
20963 							  , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
20964 							  , p_status_id => NULL
20965 							  , p_inspection_status => NULL
20966 							  , x_object_id => l_object_id
20967 							  , x_return_status => x_return_status
20968 							  , x_msg_count => x_msg_count
20969 							  , x_msg_data => x_msg_data);
20970 
20971 							IF (x_return_status <> g_ret_sts_success) THEN
20972 							   --raise error
20973 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20974 							   fnd_msg_pub.ADD;
20975 							   l_progress := 'WMSINB-23580';
20976 							   RAISE fnd_api.g_exc_error;
20977 							END IF;
20978 
20979 							--validate and update the attributes.
20980 							inv_serial_number_pub.validate_update_serial_att
20981 							  (x_return_status     => x_return_status,
20982 							   x_msg_count         => x_msg_count,
20983 							   x_msg_data          => x_msg_data,
20984 							   x_validation_status => l_validation_status,
20985 							   p_serial_number     => l_serial_number,
20986 							   p_organization_id   => l_org_id,
20987 							   p_inventory_item_id => l_item_id,
20988 							   p_serial_att_tbl    => l_serial_attributes_tbl,
20989 							   p_validate_only     => FALSE
20990 							   );
20991 
20992 							IF (l_validation_status <> 'Y'
20993 							    OR x_return_status <> g_ret_sts_success) THEN
20994 							   --raise error
20995 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20996 							   fnd_msg_pub.ADD;
20997 							   l_progress := 'WMSINB-23615';
20998 							   RAISE fnd_api.g_exc_error;
20999 							END IF;
21000 
21001 
21002 							--UPDATE GROUP_MARK_ID TO -7937
21003 							IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
21004 							   --raise error
21005 							   l_progress := 'WMSINB-23622';
21006 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21007 							   fnd_msg_pub.ADD;
21008 							   RAISE fnd_api.g_exc_error;
21009 							END IF;
21010 						      ELSE
21011 							--raise error
21012 							l_progress := 'WMSINB-23629';
21013 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21014 							fnd_msg_pub.ADD;
21015 							RAISE fnd_api.g_exc_error;
21016 						     END IF;
21017 					    END IF; --IF l_serial_exists = 1 THEN
21018 					  ELSIF (l_serial_number_control_code = 6 AND
21019 						 l_source_document_code = 'RMA') THEN
21020 						  IF l_serial_exists = 1 THEN
21021                        --bug#3571808 removed the current_org_id check
21022                        /*
21023 						     IF ((l_curr_org_id <> l_org_id) and not (l_restrict_rcpt_ser = '2'
21024 											      and l_curr_status = 4 ))  THEN
21025 							--raise error
21026 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21027 							fnd_msg_pub.ADD;
21028 							l_progress := 'WMSINB-23642';
21029 							RAISE fnd_api.g_exc_error;
21030 						      ELSE*/
21031 							IF (l_curr_lot_num IS NOT NULL
21032                          AND (Nvl(l_curr_status,1) NOT IN (1,4) )) THEN
21033 							   --raise error
21034 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21035 							   fnd_msg_pub.ADD;
21036 							   l_progress := 'WMSINB-23649';
21037 							   RAISE fnd_api.g_exc_error;
21038 							END IF;
21039 						     --END IF;
21040 
21041 						     IF l_curr_status NOT IN (1,4,6) THEN
21042 							--raise error
21043 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21044 							fnd_msg_pub.ADD;
21045 							l_progress := 'WMSINB-23658';
21046 							RAISE fnd_api.g_exc_error;
21047 						     END IF;
21048 
21049 						     -- see if we need to restrict 4's based on
21050 						     -- inv_restrict_rcpt profile
21051 						     -- REVIEW at CODE REVIEW
21052 						     IF l_restrict_rcpt_ser <> 2 THEN
21053 							l_dummy := '0';
21054 			                                BEGIN
21055 							   SELECT '1'
21056 							     INTO l_dummy
21057 							     FROM dual
21058 							     WHERE exists (SELECT '1'
21059 									   FROM   mtl_serial_numbers
21060 									   WHERE  inventory_item_id = l_item_id
21061 									   AND    current_organization_id = l_org_id
21062 									   AND    current_status IN (1, 4) --Do we need 4 here
21063 									   AND    serial_number = l_serial_number
21064 									   AND    LAST_TXN_SOURCE_TYPE_ID = 12);
21065 
21066 							   IF l_dummy <> '0' THEN
21067 							      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21068 							      fnd_msg_pub.ADD;
21069 							      l_progress := 'WMSINB-23682';
21070 							      RAISE fnd_api.g_exc_error;
21071 							   END IF;
21072 
21073 							EXCEPTION
21074 							   WHEN no_data_found THEN
21075 							      NULL;
21076 							END;
21077 						     END IF;
21078 
21079 						     IF (Nvl(l_group_mark_id, -99) = -7937) THEN
21080 							--raise error
21081 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21082 							fnd_msg_pub.ADD;
21083 							l_progress := 'WMSINB-23696';
21084 							RAISE fnd_api.g_exc_error;
21085 						     END IF;
21086 
21087 						     IF (Nvl(l_curr_status, 1) in (1,6)) THEN
21088 							--validate and update the attributes.
21089 							inv_serial_number_pub.validate_update_serial_att
21090 							  (x_return_status     => x_return_status,
21091 							   x_msg_count         => x_msg_count,
21092 							   x_msg_data          => x_msg_data,
21093 							   x_validation_status => l_validation_status,
21094 							   p_serial_number     => l_serial_number,
21095 							   p_organization_id   => l_org_id,
21096 							   p_inventory_item_id => l_item_id,
21097 							   p_serial_att_tbl    => l_serial_attributes_tbl,
21098 							   p_validate_only     => FALSE
21099 							   );
21100 
21101 							IF (l_validation_status <> 'Y'
21102 							    OR x_return_status <> g_ret_sts_success) THEN
21103 							   --raise error
21104 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21105 							   fnd_msg_pub.ADD;
21106 							   l_progress := 'WMSINB-23702';
21107 							   RAISE fnd_api.g_exc_error;
21108 							END IF;
21109 						     END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
21110 
21111 						     --UPDATE GROUP_MARK_ID TO -7937
21112 						     IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
21113 							--raise error
21114 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21115 							fnd_msg_pub.ADD;
21116 							l_progress := 'WMSINB-23705';
21117 							RAISE fnd_api.g_exc_error;
21118 						     END IF;
21119 						   ELSE --IF l_serial_exists = 1 THEN
21120 							--PERFORM SERIAL VALIDATION FOR NEW SERIAL
21121 							--(INCLUDING ATT VALIDATION)
21122 							--CREATE MSN
21123 
21124 							inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
21125 												  , p_inventory_item_id => l_item_id
21126 												  , p_organization_id => l_org_id
21127 												  , p_from_serial_number => l_serial_number
21128 												  , p_to_serial_number => l_serial_number
21129 												  , p_initialization_date => SYSDATE
21130 												  , p_completion_date => NULL
21131 												  , p_ship_date => NULL
21132 												  , p_revision => l_item_revision
21133 												  , p_lot_number => NULL
21134 												  , p_current_locator_id => l_loc_id
21135 												  , p_subinventory_code => l_sub_code
21136 												  , p_trx_src_id => NULL
21137 												  , p_unit_vendor_id => NULL
21138 												  , p_vendor_lot_number => NULL
21139 												  , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
21140 												  , p_receipt_issue_type => NULL
21141 												  , p_txn_src_id => NULL
21142 												  , p_txn_src_name => NULL
21143 												  , p_txn_src_type_id => NULL
21144 												  , p_transaction_id => NULL
21145 												  , p_current_status => 1
21146 												  , p_parent_item_id => NULL
21147 							  , p_parent_serial_number => NULL
21148 							  , p_cost_group_id => NULL
21149 							  , p_transaction_action_id => 27
21150 							  , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
21151 							  , p_status_id => NULL
21152 							  , p_inspection_status => NULL
21153 							  , x_object_id => l_object_id
21154 							  , x_return_status => x_return_status
21155 							  , x_msg_count => x_msg_count
21156 							  , x_msg_data => x_msg_data);
21157 
21158 							IF (x_return_status <> g_ret_sts_success) THEN
21159 							   --raise error
21160 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21161 							   fnd_msg_pub.ADD;
21162 							   l_progress := 'WMSINB-23710';
21163 							   RAISE fnd_api.g_exc_error;
21164 							END IF;
21165 
21166 							--validate and update the attributes.
21167 							inv_serial_number_pub.validate_update_serial_att
21168 							  (x_return_status     => x_return_status,
21169 							   x_msg_count         => x_msg_count,
21170 							   x_msg_data          => x_msg_data,
21171 							   x_validation_status => l_validation_status,
21172 							   p_serial_number     => l_serial_number,
21173 							   p_organization_id   => l_org_id,
21174 							   p_inventory_item_id => l_item_id,
21175 							   p_serial_att_tbl    => l_serial_attributes_tbl,
21176 							   p_validate_only     => FALSE
21177 							   );
21178 
21179 							IF (l_validation_status <> 'Y'
21180 							    OR x_return_status <> g_ret_sts_success) THEN
21181 							   --raise error
21182 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21183 							   fnd_msg_pub.ADD;
21184 							   l_progress := 'WMSINB-23745';
21185 							   RAISE fnd_api.g_exc_error;
21186 							END IF;
21187 
21188 							--UPDATE GROUP_MARK_ID TO -7937
21189 							IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
21190 							   --raise error
21191 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21192 							   fnd_msg_pub.ADD;
21193 							   l_progress := 'WMSINB-23752';
21194 							   RAISE fnd_api.g_exc_error;
21195 							END IF;
21196 						  END IF; --IF l_serial_exists = 1 THEN
21197 					 END IF; --IF l_serial_number_control_code IN (2,5) THEN
21198 				       ELSE --IF NOT L_SERIAL_ENTERED_ON_PARENT THEN
21199 		                          BEGIN
21200 					     SELECT '1'
21201 					       INTO L_DUMMY
21202 					       FROM RCV_SERIALS_SUPPLY
21203 					       WHERE TRANSACTION_ID = L_PARENT_TRANSACTION_ID
21204 					       AND SERIAL_NUM = L_SERIAL_NUMBER;
21205 
21206 					     IF (l_curr_status <> 7) THEN
21207 						--raise error
21208 						fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21209 						fnd_msg_pub.ADD;
21210 						l_progress := 'WMSINB-23769';
21211 						RAISE fnd_api.g_exc_error;
21212 					     END IF;
21213 
21214 					     --Validate Serial/Inspection_status
21215 		        /*  Commented for bug 6269102
21216                           *  To allow the inspection done again
21217                 	  *  on an inspection transaction to succeed
21218 		          *  as it was failing because of the
21219         		  *  inspection status <> 1
21220 
21221 					     IF l_transaction_type IN ('ACCEPT', 'REJECT') THEN
21222 						IF (Nvl(l_inspection_status, 1) <> 1) THEN
21223 						   --raise error
21224 						   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21225 						   fnd_msg_pub.ADD;
21226 						   l_progress := 'WMSINB-23779';
21227 						   RAISE fnd_api.g_exc_error;
21228 						END IF;
21229 					      ELS */
21230 					      IF l_transaction_type = 'DELIVER' THEN
21231 						IF (l_routing_header_id = 2) THEN
21232 						   IF l_inspection_status IS NOT NULL AND l_inspection_status = 1 THEN
21233 						      --raise error
21234 						      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21235 						      fnd_msg_pub.ADD;
21236 						      l_progress := 'WMSINB-23788';
21237 						      RAISE fnd_api.g_exc_error;
21238 						   END IF;
21239 						END IF;
21240 					     END IF;
21241 
21242 					     --Validate serial/group_mark_id to prevent
21243 					     --entering of duplicate serials
21244 
21245 					     IF (Nvl(l_group_mark_id, -99) = -7937) THEN
21246 						--raise error
21247 						fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21248 						fnd_msg_pub.ADD;
21249 						l_progress := 'WMSINB-23801';
21250 						RAISE fnd_api.g_exc_error;
21251 					     END IF;
21252 
21253 					     --UPDATE GROUP_MARK_ID TO -7937
21254 					     IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
21255 						--raise error
21256 						fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21257 						fnd_msg_pub.ADD;
21258 						l_progress := 'WMSINB-23810';
21259 						RAISE fnd_api.g_exc_error;
21260 					     END IF;
21261 					  EXCEPTION
21262 					     WHEN NO_DATA_FOUND THEN
21263 						-- RAISE ERROR
21264 						fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21265 						fnd_msg_pub.ADD;
21266 						l_progress := 'WMSINB-23818';
21267 						RAISE fnd_api.g_exc_error;
21268 					  END;
21269 				      END IF; --IF NOT L_SERIAL_ENTERED_ON_PARENT THEN
21270 				   END LOOP; -- FOR 1..L_SERIAL_QUANTITY
21271 				END LOOP; --FETCH C_MSNT INTO L_MSNT_REC;
21272 
21273 				CLOSE c_msnt;
21274 
21275 				IF (l_num_msnt_recs > 0) THEN
21276 				   IF l_tot_msnt_serial_qty <> l_rti_primary_qty THEN
21277 				      --raise error
21278 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21279 				      fnd_msg_pub.ADD;
21280 				      l_progress := 'WMSINB-23832';
21281 				      RAISE fnd_api.g_exc_error;
21282 				   END IF;
21283 				 ELSE
21284 				   IF (l_transaction_type = 'DELIVER'
21285 				       OR Nvl(l_auto_transact_code,'@@@@') = 'DELIVER') THEN
21286 
21287 				      IF l_source_document_code IN ('INVENTORY', 'REQ') THEN
21288 					 GET_SERIAL_LOT_CTRL_IN_SRC_ORG
21289 					   (L_SHIPMENT_LINE_ID, L_ORG_ID,
21290 					    L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
21291 					    l_from_org_rev_ctrl,
21292 					    X_RETURN_STATUS, X_MSG_COUNT,
21293 					    x_msg_data);
21294 				      END IF;
21295 
21296 				      IF (l_serial_number_control_code IN (2,5)
21297 					  OR (l_serial_number_control_code = 6
21298 					      AND l_source_document_code IN ('RMA'))
21299 					  OR (l_serial_number_control_code = 6
21300 					      AND l_source_document_code = 'INVENTORY'
21301 					      AND l_from_org_ser_crtl NOT IN (1, 6))
21302 					  --BUG 3644289: Do the following check for INTREQ
21303 					  OR (l_serial_number_control_code = 6
21304 					      AND l_from_org_ser_crtl IN (2,5,6)
21305 					      AND l_source_document_code = 'REQ'))
21306 					THEN
21307 					 --raise error
21308 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21309 					 fnd_msg_pub.ADD;
21310 					 l_progress := 'WMSINB-23840';
21311 					 RAISE fnd_api.g_exc_error;
21312 				      END IF;
21313 				    ELSIF (serial_entered_on_parent(l_parent_transaction_id)) THEN
21314 				      --raise error
21315 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21316 				      fnd_msg_pub.ADD;
21317 				      l_progress := 'WMSINB-23846';
21318 				      RAISE fnd_api.g_exc_error;
21319 				   END IF;
21320 				END IF;
21321 
21322 	END IF; -- IF (L_LOT_CONTROL_CODE = 2) THEN
21323      END IF;--IF (l_transaction_type IN ('RECEIVE','ACCEPT','REJECT','TRANSFER','DELIVER')) THEN
21324 
21325      --Validate lot/serial for ASN import.
21326 
21327      IF (l_transaction_type = 'SHIP' AND l_source_document_code = 'PO') THEN
21328 	-- opm change bug# 3061052 added l_opm_lot_ctl check
21329 
21330    /*INVCONV, Remove the separate lot control check for OPM items.
21331       To be checked only once for all items.Punit Kumar */
21332 
21333 	IF (l_lot_control_code = 2 /* OR l_opm_lot_ctl = 1  */) THEN
21334 	   IF (l_debug = 1) THEN
21335 	      print_debug('VALIDATE_LOT_SERIAL_INFO: Lot Controlled :'||l_progress, 1);
21336 	      l_progress := 'WMSINB-23861';
21337 	   END IF;
21338 
21339 	   l_num_mtlt_recs := 0;
21340 	   l_tot_mtlt_prim_qty := 0;
21341 	   l_tot_mtlt_trans_qty := 0; -- Bug# 4225766
21342 
21343 	   OPEN C_MTLT(L_RTI_ID);
21344 
21345 	   LOOP
21346 	      FETCH C_MTLT INTO L_MTLT_REC;
21347 	      EXIT WHEN C_MTLT%NOTFOUND;
21348 
21349          /* INVCONV , get L_MTLT_REC values into l_mln_rec which shall be passed to INV_NEW_LOT
21350             for lot creation */
21351               IF (l_debug = 1) THEN
21352                  print_debug('INVCONV, Assigning values fetched from MTLT to l_mln_rec'||l_progress,1);
21353               END IF;
21354 
21355          	   l_mln_rec.LOT_NUMBER                := L_MTLT_REC.LOT_NUMBER                    ;
21356                l_mln_rec.LAST_UPDATE_DATE          := SYSDATE                                  ;
21357                l_mln_rec.LAST_UPDATED_BY           := L_MTLT_REC.LAST_UPDATED_BY               ;
21358                l_mln_rec.CREATION_DATE             := SYSDATE                                  ;
21359                l_mln_rec.CREATED_BY                := L_MTLT_REC.CREATED_BY                    ;
21360                l_mln_rec.LAST_UPDATE_LOGIN         := L_MTLT_REC.LAST_UPDATE_LOGIN             ;
21361                l_mln_rec.EXPIRATION_DATE           := L_MTLT_REC.LOT_EXPIRATION_DATE               ;
21362                l_mln_rec.ATTRIBUTE_CATEGORY        := L_MTLT_REC.ATTRIBUTE_CATEGORY            ;
21363                l_mln_rec.ATTRIBUTE1                := L_MTLT_REC.ATTRIBUTE1                    ;
21364                l_mln_rec.ATTRIBUTE2                := L_MTLT_REC.ATTRIBUTE2                    ;
21365                l_mln_rec.ATTRIBUTE3                := L_MTLT_REC.ATTRIBUTE3                    ;
21366                l_mln_rec.ATTRIBUTE4                := L_MTLT_REC.ATTRIBUTE4                    ;
21367                l_mln_rec.ATTRIBUTE5                := L_MTLT_REC.ATTRIBUTE5                    ;
21368                l_mln_rec.ATTRIBUTE6                := L_MTLT_REC.ATTRIBUTE6                    ;
21369                l_mln_rec.ATTRIBUTE7                := L_MTLT_REC.ATTRIBUTE7                    ;
21370                l_mln_rec.ATTRIBUTE8                := L_MTLT_REC.ATTRIBUTE8                    ;
21371                l_mln_rec.ATTRIBUTE9                := L_MTLT_REC.ATTRIBUTE9                    ;
21372                l_mln_rec.ATTRIBUTE10               := L_MTLT_REC.ATTRIBUTE10                   ;
21373                l_mln_rec.ATTRIBUTE11               := L_MTLT_REC.ATTRIBUTE11                   ;
21374                l_mln_rec.ATTRIBUTE12               := L_MTLT_REC.ATTRIBUTE12                   ;
21375                l_mln_rec.ATTRIBUTE13               := L_MTLT_REC.ATTRIBUTE13                   ;
21376                l_mln_rec.ATTRIBUTE14               := L_MTLT_REC.ATTRIBUTE14                   ;
21377                l_mln_rec.ATTRIBUTE15               := L_MTLT_REC.ATTRIBUTE15                   ;
21378                l_mln_rec.REQUEST_ID                := L_MTLT_REC.REQUEST_ID                    ;
21379                l_mln_rec.PROGRAM_APPLICATION_ID    := L_MTLT_REC.PROGRAM_APPLICATION_ID        ;
21380                l_mln_rec.PROGRAM_ID                := L_MTLT_REC.PROGRAM_ID                    ;
21381                l_mln_rec.PROGRAM_UPDATE_DATE       := L_MTLT_REC.PROGRAM_UPDATE_DATE           ;
21382                l_mln_rec.DESCRIPTION               := L_MTLT_REC.DESCRIPTION                   ;
21383                l_mln_rec.VENDOR_NAME               := L_MTLT_REC.VENDOR_NAME                   ;
21384                l_mln_rec.SUPPLIER_LOT_NUMBER       := L_MTLT_REC.SUPPLIER_LOT_NUMBER           ;
21385                l_mln_rec.GRADE_CODE                := L_MTLT_REC.GRADE_CODE                    ;
21386                l_mln_rec.ORIGINATION_DATE          := L_MTLT_REC.ORIGINATION_DATE              ;
21387                l_mln_rec.DATE_CODE                 := L_MTLT_REC.DATE_CODE                     ;
21388                l_mln_rec.STATUS_ID                 := L_MTLT_REC.STATUS_ID                     ;
21389                l_mln_rec.CHANGE_DATE               := L_MTLT_REC.CHANGE_DATE                   ;
21390                l_mln_rec.AGE                       := L_MTLT_REC.AGE                           ;
21391                l_mln_rec.RETEST_DATE               := L_MTLT_REC.RETEST_DATE                   ;
21392                l_mln_rec.MATURITY_DATE             := L_MTLT_REC.MATURITY_DATE                 ;
21393                l_mln_rec.LOT_ATTRIBUTE_CATEGORY    := L_MTLT_REC.LOT_ATTRIBUTE_CATEGORY        ;
21394                l_mln_rec.ITEM_SIZE                 := L_MTLT_REC.ITEM_SIZE                     ;
21395                l_mln_rec.COLOR                     := L_MTLT_REC.COLOR                         ;
21396                l_mln_rec.VOLUME                    := L_MTLT_REC.VOLUME                        ;
21397                l_mln_rec.VOLUME_UOM                := L_MTLT_REC.VOLUME_UOM                    ;
21398                l_mln_rec.PLACE_OF_ORIGIN           := L_MTLT_REC.PLACE_OF_ORIGIN               ;
21399                l_mln_rec.BEST_BY_DATE              := L_MTLT_REC.BEST_BY_DATE                  ;
21400                l_mln_rec.LENGTH                    := L_MTLT_REC.LENGTH                        ;
21401                l_mln_rec.LENGTH_UOM                := L_MTLT_REC.LENGTH_UOM                    ;
21402                l_mln_rec.RECYCLED_CONTENT          := L_MTLT_REC.RECYCLED_CONTENT              ;
21403                l_mln_rec.THICKNESS                 := L_MTLT_REC.THICKNESS                     ;
21404                l_mln_rec.THICKNESS_UOM             := L_MTLT_REC.THICKNESS_UOM                 ;
21405                l_mln_rec.WIDTH                     := L_MTLT_REC.WIDTH                         ;
21406                l_mln_rec.WIDTH_UOM                 := L_MTLT_REC.WIDTH_UOM                     ;
21407                l_mln_rec.CURL_WRINKLE_FOLD         := L_MTLT_REC.CURL_WRINKLE_FOLD             ;
21408                l_mln_rec.C_ATTRIBUTE1              := L_MTLT_REC.C_ATTRIBUTE1                  ;
21409                l_mln_rec.C_ATTRIBUTE2              := L_MTLT_REC.C_ATTRIBUTE2                  ;
21410                l_mln_rec.C_ATTRIBUTE3              := L_MTLT_REC.C_ATTRIBUTE3                  ;
21411                l_mln_rec.C_ATTRIBUTE4              := L_MTLT_REC.C_ATTRIBUTE4                  ;
21412                l_mln_rec.C_ATTRIBUTE5              := L_MTLT_REC.C_ATTRIBUTE5                  ;
21413                l_mln_rec.C_ATTRIBUTE6              := L_MTLT_REC.C_ATTRIBUTE6                  ;
21414                l_mln_rec.C_ATTRIBUTE7              := L_MTLT_REC.C_ATTRIBUTE7                  ;
21415                l_mln_rec.C_ATTRIBUTE8              := L_MTLT_REC.C_ATTRIBUTE8                  ;
21416                l_mln_rec.C_ATTRIBUTE9              := L_MTLT_REC.C_ATTRIBUTE9                  ;
21417                l_mln_rec.C_ATTRIBUTE10             := L_MTLT_REC.C_ATTRIBUTE10                 ;
21418                l_mln_rec.C_ATTRIBUTE11             := L_MTLT_REC.C_ATTRIBUTE11                 ;
21419                l_mln_rec.C_ATTRIBUTE12             := L_MTLT_REC.C_ATTRIBUTE12                 ;
21420                l_mln_rec.C_ATTRIBUTE13             := L_MTLT_REC.C_ATTRIBUTE13                 ;
21421                l_mln_rec.C_ATTRIBUTE14             := L_MTLT_REC.C_ATTRIBUTE14                 ;
21422                l_mln_rec.C_ATTRIBUTE15             := L_MTLT_REC.C_ATTRIBUTE15                 ;
21423                l_mln_rec.C_ATTRIBUTE16             := L_MTLT_REC.C_ATTRIBUTE16                 ;
21424                l_mln_rec.C_ATTRIBUTE17             := L_MTLT_REC.C_ATTRIBUTE17                 ;
21425                l_mln_rec.C_ATTRIBUTE18             := L_MTLT_REC.C_ATTRIBUTE18                 ;
21426                l_mln_rec.C_ATTRIBUTE19             := L_MTLT_REC.C_ATTRIBUTE19                 ;
21427                l_mln_rec.C_ATTRIBUTE20             := L_MTLT_REC.C_ATTRIBUTE20                 ;
21428                l_mln_rec.D_ATTRIBUTE1              := L_MTLT_REC.D_ATTRIBUTE1                  ;
21429                l_mln_rec.D_ATTRIBUTE2              := L_MTLT_REC.D_ATTRIBUTE2                  ;
21430                l_mln_rec.D_ATTRIBUTE3              := L_MTLT_REC.D_ATTRIBUTE3                  ;
21431                l_mln_rec.D_ATTRIBUTE4              := L_MTLT_REC.D_ATTRIBUTE4                  ;
21432                l_mln_rec.D_ATTRIBUTE5              := L_MTLT_REC.D_ATTRIBUTE5                  ;
21433                l_mln_rec.D_ATTRIBUTE6              := L_MTLT_REC.D_ATTRIBUTE6                  ;
21434                l_mln_rec.D_ATTRIBUTE7              := L_MTLT_REC.D_ATTRIBUTE7                  ;
21435                l_mln_rec.D_ATTRIBUTE8              := L_MTLT_REC.D_ATTRIBUTE8                  ;
21436                l_mln_rec.D_ATTRIBUTE9              := L_MTLT_REC.D_ATTRIBUTE9                  ;
21437                l_mln_rec.D_ATTRIBUTE10             := L_MTLT_REC.D_ATTRIBUTE10                 ;
21438                l_mln_rec.N_ATTRIBUTE1              := L_MTLT_REC.N_ATTRIBUTE1                  ;
21439                l_mln_rec.N_ATTRIBUTE2              := L_MTLT_REC.N_ATTRIBUTE2                  ;
21440                l_mln_rec.N_ATTRIBUTE3              := L_MTLT_REC.N_ATTRIBUTE3                  ;
21441                l_mln_rec.N_ATTRIBUTE4              := L_MTLT_REC.N_ATTRIBUTE4                  ;
21442                l_mln_rec.N_ATTRIBUTE5              := L_MTLT_REC.N_ATTRIBUTE5                  ;
21443                l_mln_rec.N_ATTRIBUTE6              := L_MTLT_REC.N_ATTRIBUTE6                  ;
21444                l_mln_rec.N_ATTRIBUTE7              := L_MTLT_REC.N_ATTRIBUTE7                  ;
21445                l_mln_rec.N_ATTRIBUTE8              := L_MTLT_REC.N_ATTRIBUTE8                  ;
21446                l_mln_rec.N_ATTRIBUTE9              := L_MTLT_REC.N_ATTRIBUTE9                  ;
21447                l_mln_rec.N_ATTRIBUTE10             := L_MTLT_REC.N_ATTRIBUTE10                 ;
21448                l_mln_rec.VENDOR_ID                 := L_MTLT_REC.VENDOR_ID                     ;
21449                l_mln_rec.TERRITORY_CODE            := L_MTLT_REC.TERRITORY_CODE                ;
21450                l_mln_rec.PARENT_LOT_NUMBER         := L_MTLT_REC.PARENT_LOT_NUMBER             ;
21451                l_mln_rec.ORIGINATION_TYPE          := L_MTLT_REC.ORIGINATION_TYPE              ;
21452                l_mln_rec.EXPIRATION_ACTION_DATE    := L_MTLT_REC.EXPIRATION_ACTION_DATE        ;
21453                l_mln_rec.EXPIRATION_ACTION_CODE    := L_MTLT_REC.EXPIRATION_ACTION_CODE        ;
21454                l_mln_rec.HOLD_DATE                 := L_MTLT_REC.HOLD_DATE                     ;
21455 
21456          /*end , INVCONV*/
21457 
21458 
21459 	      L_NUM_MTLT_RECS := L_NUM_MTLT_RECS + 1;
21460 	      l_tot_mtlt_prim_qty := l_tot_mtlt_prim_qty + l_mtlt_rec.primary_quantity;
21461 	      l_tot_mtlt_trans_qty := l_tot_mtlt_trans_qty + l_mtlt_rec.transaction_quantity; -- Bug# 4225766
21462 
21463 	      IF (l_debug = 1) THEN
21464 		 print_debug('VALIDATE_LOT_SERIAL_INFO: LOT NUMBER: '||l_mtlt_rec.lot_number||': '||l_progress, 1);
21465 		 print_debug('VALIDATE_LOT_SERIAL_INFO: LOT PRIMARY QUANTITY: '||l_mtlt_rec.primary_quantity||': '||l_progress, 1);
21466        print_debug('INVCONV , Finished Assigning values fetched from MTLT to l_mln_rec'||l_progress,1);		 l_progress := 'WMSINB-23879';
21467         l_progress := 'WMSINB-23879';
21468 
21469 	      END IF;
21470 
21471 	      BEGIN
21472           /* INVCONV, Remove OPM specific ic_lots_mst logic
21473             Validation of Lot existence for OPM items shall be done from
21474             MTL_LOT_NUMBERS as is done for discrete items.
21475             If it exists then we shall validate its parent lot also.
21476             Remove OPM fork.Add parent_lot_number in discrete query.Punit Kumar */
21477 
21478 		 /*IF (l_discrete_transaction) THEN		 */
21479 		      SELECT 1,parent_lot_number
21480                INTO L_LOT_EXISTS ,l_parent_lot_number
21481                FROM MTL_LOT_NUMBERS
21482                WHERE ORGANIZATION_ID = L_ORG_ID
21483                AND   INVENTORY_ITEM_ID = L_ITEM_ID
21484                AND LOT_NUMBER = Ltrim(Rtrim(L_MTLT_REC.lot_number));
21485 
21486 
21487 		  /* ELSE -- opm change bug# 3061052 --IF (l_discrete_transaction) THEN
21488 		    IF Ltrim(Rtrim(L_MTLT_REC.sublot_num)) IS NOT NULL THEN
21489 		       SELECT 1, LOT_ID
21490 			 INTO L_LOT_EXISTS , l_opm_lot_id
21491 			 FROM IC_LOTS_MST
21492 			 WHERE ITEM_ID = l_opm_item_id
21493 			 AND LOT_NO = Ltrim(Rtrim(L_MTLT_REC.lot_number))
21494 			 AND SUBLOT_NO = Ltrim(Rtrim(L_MTLT_REC.sublot_num)) ;
21495 		     ELSE
21496 		       SELECT 1, LOT_ID
21497 			 INTO L_LOT_EXISTS , l_opm_lot_id
21498 			 FROM IC_LOTS_MST
21499 			 WHERE ITEM_ID = l_opm_item_id
21500 			 AND LOT_NO = Ltrim(Rtrim(L_MTLT_REC.lot_number))
21501 			 AND SUBLOT_NO IS NULL ;
21502 		    END IF;
21503 		 END IF; --IF (l_discrete_transaction) THEN
21504 		*/
21505       EXCEPTION
21506 		 WHEN NO_DATA_FOUND THEN
21507 		    L_LOT_EXISTS := 0;
21508 	      END;
21509 
21510 	      IF (l_debug = 1) THEN
21511 		 print_debug('VALIDATE_LOT_SERIAL_INFO: LOT EXISTS: '||l_lot_exists||' : '||l_progress, 1);
21512        print_debug('INVCONV, Removing OPM specific fork :'||l_progress,1);
21513 		 l_progress := 'WMSINB-23915';
21514 	      END IF;
21515 
21516 	      IF L_LOT_EXISTS = 1 THEN
21517 
21518             /*INVCONV , validating for parent lot, Punit Kumar */
21519             IF  L_MTLT_REC.parent_lot_number IS NOT NULL THEN
21520                IF L_MTLT_REC.parent_lot_number <> l_parent_lot_number THEN
21521                   fnd_message.set_name ('INV' , 'INV_CL_PARENT_INVALID' );
21522 					   fnd_msg_pub.ADD;
21523                   RAISE fnd_api.g_exc_error;
21524                END IF;
21525             ELSE
21526                L_MTLT_REC.parent_lot_number := l_parent_lot_number;
21527             END IF;
21528             /*end , INVCONV */
21529 
21530           /*INVCONV , Remove the process specific call as now we shall validate the proces
21531             attributes for discrete items too. Punit Kumar */
21532 
21533 	     /*IF (l_discrete_transaction) THEN */
21534         /* end , INVCONV */
21535 
21536          /* The below code was already commented.  It has nothing to do with INVCONV */
21537 
21538 		    -- This is NOT required for a SHIP transaction.
21539 		    -- perform material status check
21540 		    --INV_LOT_TRX_VALIDATION_PUB.VALIDATE_MATERIAL_STATUS(X_RETURN_STATUS => X_RETURN_STATUS,
21541 		    --X_MSG_COUNT => X_MSG_COUNT,
21542 		    --X_MSG_DATA => X_MSG_DATA,
21543 		    --X_VALIDATION_STATUS => L_VALIDATION_STATUS,
21544 		    --P_TRANSACTION_TYPE_ID => 18,
21545 		    --P_ORGANIZATION_ID => L_ORG_ID,
21546 		    --P_INVENTORY_ITEM_ID => L_ITEM_ID,
21547 		    --P_LOT_NUMBER => L_MTLT_REC.LOT_NUMBER,
21548 		    --P_SUBINVENTORY_CODE => l_sub_code,
21549 		    --P_LOCATOR_ID => l_loc_id,
21550 		    --P_STATUS_ID => NULL);
21551 		    --IF X_RETURN_STATUS <> 'S' THEN
21552 		    --RAISE ERROR
21553 		    --l_progress := 'WMSINB-23934';
21554 		    --RAISE fnd_api.g_exc_error;
21555 		    --END IF;
21556 
21557 		    --IF (l_debug = 1) THEN
21558 		    --print_debug('VALIDATE_LOT_SERIAL_INFO: LOT MATERIAL VALIDATION STATUS: '||L_VALIDATION_STATUS||' : '||l_progress, 1);
21559 		    --l_progress := 'WMSINB-23940';
21560 		    --END IF;
21561 
21562 		    --IF L_VALIDATION_STATUS <> 'Y' THEN
21563 		    --RAISE ERROR
21564 		    --l_progress := 'WMSINB-23945';
21565 		    --RAISE fnd_api.g_exc_error;
21566 		    --END IF;
21567 
21568       /* end , The above code was already commented.  It has nothing to do with INVCONV */
21569 
21570 		    NULL;
21571 
21572        /* INVCONV */
21573 
21574 		/*  ELSE --IF (l_discrete_transaction) THEN
21575 		    -- opm change bug# 3061052
21576 		    gml_opm_roi_grp.validate_opm_lot(p_api_version	 	=> 1.0,
21577 						     p_init_msg_lst	 	=> FND_API.G_FALSE,
21578 						     p_mtlt_rowid		=> l_mtlt_rec.rowid,
21579 						     p_new_lot	 	=> 'N',
21580 						     p_opm_item_id		=> l_opm_item_id,
21581 						     p_item_no		=> l_item_no,
21582 						     p_lots_specified_on_parent => 'N',
21583 						     p_lot_id		=> l_opm_lot_id,
21584 						     x_return_status 	=> x_return_status,
21585 						     x_msg_data      	=> x_msg_data,
21586 						     x_msg_count     	=> x_msg_count
21587 						     );
21588 
21589          end , INVCONV */
21590 
21591           /*INVCONV ,*/
21592           IF (l_debug = 1) THEN
21593              print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
21594           END IF;
21595 
21596           INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
21597                                                        x_return_status      		   => x_return_status
21598                                                       ,x_msg_data           		   => x_msg_data
21599                                                       ,x_msg_count          		   => x_msg_count
21600                                                       ,p_api_version	               => 1.0
21601                                                       ,p_init_msg_lst	            => FND_API.G_FALSE
21602                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
21603                                                       ,p_transaction_type_id 	      => l_transaction_type_id
21604                                                       ,p_new_lot			            => 'N'
21605                                                       ,p_item_id	 		            => l_item_id
21606                                                       ,p_to_organization_id		   => L_ORG_ID
21607                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
21608                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
21609                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
21610                                                       ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
21611                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
21612                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
21613                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
21614                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
21615                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
21616                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
21617                                                       ,p_rti_id	                  => L_RTI_ID
21618                                                       ,p_revision             	   => l_item_revision
21619                                                       ,p_subinventory_code  	      => L_SUB_CODE
21620                                                       ,p_locator_id           	   => l_loc_id
21621                                                       ,p_transaction_type           => l_transaction_type
21622                                                       ,p_parent_txn_type            => l_parent_txn_type
21623                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
21624                                                       );
21625           /*INVCONV ,*/
21626           IF (l_debug = 1) THEN
21627              print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
21628              print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
21629           END IF;
21630 
21631 		    IF X_RETURN_STATUS <> 'S' THEN
21632 		       --RAISE ERROR
21633 		       l_progress := 'WMSINB-23964';
21634 		       RAISE fnd_api.g_exc_error;
21635 		    END IF;
21636 
21637 		    IF (l_debug = 1) THEN
21638 		       print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
21639 		    END IF;
21640 
21641 		 /*END IF; --IF (l_discrete_transaction) THEN */
21642 
21643 	       ELSE --IF L_LOT_EXISTS = 1 THEN
21644 
21645 
21646 		  /* IF (l_discrete_transaction) THEN
21647 		    --call CREATE_INV_LOT
21648 		    --FOR l_inv_att_index IN 1..15 LOOP
21649 		    -- l_inv_attributes_tbl(l_inv_att_index) := NULL;
21650 		    --END LOOP;
21651 
21652 		    l_c_attributes_tbl(1)  := l_mtlt_rec.c_attribute1;
21653 		    l_c_attributes_tbl(2)  := l_mtlt_rec.c_attribute2;
21654 		    l_c_attributes_tbl(3)  := l_mtlt_rec.c_attribute3;
21655 		    l_c_attributes_tbl(4)  := l_mtlt_rec.c_attribute4;
21656 		    l_c_attributes_tbl(5)  := l_mtlt_rec.c_attribute5;
21657 		    l_c_attributes_tbl(6)  := l_mtlt_rec.c_attribute6;
21658 		    l_c_attributes_tbl(7)  := l_mtlt_rec.c_attribute7;
21659 		    l_c_attributes_tbl(8)  := l_mtlt_rec.c_attribute8;
21660 		    l_c_attributes_tbl(9)  := l_mtlt_rec.c_attribute9;
21661 		    l_c_attributes_tbl(10) := l_mtlt_rec.c_attribute10;
21662 		    l_c_attributes_tbl(11) := l_mtlt_rec.c_attribute11;
21663 		    l_c_attributes_tbl(12) := l_mtlt_rec.c_attribute12;
21664 		    l_c_attributes_tbl(13) := l_mtlt_rec.c_attribute13;
21665 		    l_c_attributes_tbl(14) := l_mtlt_rec.c_attribute14;
21666 		    l_c_attributes_tbl(15) := l_mtlt_rec.c_attribute15;
21667 		    l_c_attributes_tbl(16) := l_mtlt_rec.c_attribute16;
21668 		    l_c_attributes_tbl(17) := l_mtlt_rec.c_attribute17;
21669 		    l_c_attributes_tbl(18) := l_mtlt_rec.c_attribute18;
21670 		    l_c_attributes_tbl(19) := l_mtlt_rec.c_attribute19;
21671 		    l_c_attributes_tbl(20) := l_mtlt_rec.c_attribute20;
21672 		    l_d_attributes_tbl(1)  := l_mtlt_rec.d_attribute1;
21673 		    l_d_attributes_tbl(2)  := l_mtlt_rec.d_attribute2;
21674 		    l_d_attributes_tbl(3)  := l_mtlt_rec.d_attribute3;
21675 		    l_d_attributes_tbl(4)  := l_mtlt_rec.d_attribute4;
21676 		    l_d_attributes_tbl(5)  := l_mtlt_rec.d_attribute5;
21677 		    l_d_attributes_tbl(6)  := l_mtlt_rec.d_attribute6;
21678 		    l_d_attributes_tbl(7)  := l_mtlt_rec.d_attribute7;
21679 		    l_d_attributes_tbl(8)  := l_mtlt_rec.d_attribute8;
21680 		    l_d_attributes_tbl(9)  := l_mtlt_rec.d_attribute9;
21681 		    l_d_attributes_tbl(10) := l_mtlt_rec.d_attribute10;
21682 		    l_n_attributes_tbl(1)  := l_mtlt_rec.n_attribute1;
21683 		    l_n_attributes_tbl(2)  := l_mtlt_rec.n_attribute2;
21684 		    l_n_attributes_tbl(3)  := l_mtlt_rec.n_attribute3;
21685 		    l_n_attributes_tbl(4)  := l_mtlt_rec.n_attribute4;
21686 		    l_n_attributes_tbl(5)  := l_mtlt_rec.n_attribute5;
21687 		    l_n_attributes_tbl(6)  := l_mtlt_rec.n_attribute6;
21688 		    l_n_attributes_tbl(7)  := l_mtlt_rec.n_attribute7;
21689 		    l_n_attributes_tbl(8)  := l_mtlt_rec.n_attribute8;
21690 		    l_n_attributes_tbl(9)  := l_mtlt_rec.n_attribute9;
21691 		    l_n_attributes_tbl(10) := l_mtlt_rec.n_attribute10;
21692 
21693        --Bug #3187688
21694        --Populate the INV attributes table and pass the attribute cateogry
21695        l_inv_attributes_tbl(1)  := l_mtlt_rec.attribute1;
21696        l_inv_attributes_tbl(2)  := l_mtlt_rec.attribute2;
21697        l_inv_attributes_tbl(3)  := l_mtlt_rec.attribute3;
21698        l_inv_attributes_tbl(4)  := l_mtlt_rec.attribute4;
21699        l_inv_attributes_tbl(5)  := l_mtlt_rec.attribute5;
21700        l_inv_attributes_tbl(6)  := l_mtlt_rec.attribute6;
21701        l_inv_attributes_tbl(7)  := l_mtlt_rec.attribute7;
21702        l_inv_attributes_tbl(8)  := l_mtlt_rec.attribute8;
21703        l_inv_attributes_tbl(9)  := l_mtlt_rec.attribute9;
21704        l_inv_attributes_tbl(10) := l_mtlt_rec.attribute10;
21705        l_inv_attributes_tbl(11) := l_mtlt_rec.attribute11;
21706        l_inv_attributes_tbl(12) := l_mtlt_rec.attribute12;
21707        l_inv_attributes_tbl(13) := l_mtlt_rec.attribute13;
21708        l_inv_attributes_tbl(14) := l_mtlt_rec.attribute14;
21709        l_inv_attributes_tbl(15) := l_mtlt_rec.attribute15;
21710 
21711 		    inv_lot_api_pub.create_inv_lot(x_return_status => x_return_status
21712 						   , x_msg_count => x_msg_count
21713 						   , x_msg_data => x_msg_data
21714 						   , p_inventory_item_id => l_item_id
21715 						   , p_organization_id => l_org_id
21716 						   , p_lot_number => l_mtlt_rec.lot_number
21717 						   , p_expiration_date => l_mtlt_rec.lot_expiration_date
21718 						   , p_disable_flag => NULL
21719 						   , p_attribute_category => l_mtlt_rec.attribute_category
21720 						   , p_lot_attribute_category => l_mtlt_rec.lot_attribute_category
21721 						   , p_attributes_tbl => l_inv_attributes_tbl
21722 						   , p_c_attributes_tbl => l_c_attributes_tbl
21723 						   , p_n_attributes_tbl => l_n_attributes_tbl
21724 						   , p_d_attributes_tbl => l_d_attributes_tbl
21725 						   , p_grade_code => l_mtlt_rec.grade_code
21726 						   , p_origination_date => l_mtlt_rec.origination_date
21727 						   , p_date_code => l_mtlt_rec.date_code
21728 						   , p_status_id => l_mtlt_rec.status_id
21729 						   , p_change_date => l_mtlt_rec.change_date
21730 						   , p_age => l_mtlt_rec.age
21731 						   , p_retest_date => l_mtlt_rec.retest_date
21732 		      , p_maturity_date => l_mtlt_rec.maturity_date
21733 		      , p_item_size => l_mtlt_rec.item_size
21734 		      , p_color => l_mtlt_rec.color
21735 		      , p_volume => l_mtlt_rec.volume
21736 		      , p_volume_uom => l_mtlt_rec.volume_uom
21737 		      , p_place_of_origin => l_mtlt_rec.place_of_origin
21738 		      , p_best_by_date => l_mtlt_rec.best_by_date
21739 		      , p_length => l_mtlt_rec.Length
21740 		      , p_length_uom => l_mtlt_rec.length_uom
21741 		      , p_recycled_content => l_mtlt_rec.recycled_content
21742 		      , p_thickness => l_mtlt_rec.thickness
21743 		      , p_thickness_uom => l_mtlt_rec.thickness_uom
21744 		      , p_width => l_mtlt_rec.width
21745 		      , p_width_uom => l_mtlt_rec.width_uom
21746 		      , p_territory_code => l_mtlt_rec.territory_code
21747 		      , p_supplier_lot_number => l_mtlt_rec.supplier_lot_number
21748 		      , p_vendor_name => l_mtlt_rec.vendor_name
21749 		      , p_source => inv_lot_api_pub.inv);
21750 
21751 		    IF (x_return_status <> 'S') THEN
21752 		       --raise error
21753 		       l_progress := 'WMSINB-24062';
21754 		       RAISE fnd_api.g_exc_error;
21755 		    END IF;
21756 
21757 		    IF (l_debug = 1) THEN
21758 		       print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CREATED: '||l_progress, 1);
21759 		       l_progress := 'WMSINB-24068';
21760 		    END IF;
21761 		  ELSE --IF (l_discrete_transaction) THEN
21762 		    -- opm change bug# 3061052
21763 		    gml_opm_roi_grp.validate_opm_lot(p_api_version	 	=> 1.0,
21764 						     p_init_msg_lst	 	=> FND_API.G_FALSE,
21765 						     p_mtlt_rowid		=> l_mtlt_rec.rowid,
21766 						     p_new_lot	 	=> 'Y',
21767 						     p_opm_item_id		=> l_opm_item_id,
21768 						     p_item_no		=> l_item_no,
21769 						     p_lots_specified_on_parent => 'N',
21770 						     p_lot_id		=> l_opm_lot_id,
21771 						     x_return_status 	=> x_return_status,
21772 						     x_msg_data      	=> x_msg_data,
21773 						     x_msg_count     	=> x_msg_count
21774 						     );
21775 		    IF X_RETURN_STATUS <> 'S' THEN
21776 		       --RAISE ERROR
21777 		       l_progress := 'WMSINB-24086';
21778 		       RAISE fnd_api.g_exc_error;
21779 		    END IF;
21780 
21781 		    IF (l_debug = 1) THEN
21782 		       print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CREATED: '||x_return_status||' : '||l_progress, 1);
21783 		    END IF;
21784 		 END IF; --IF (l_discrete_transaction) THEN
21785 
21786 
21787        /*INVCONV , Perform lot validations and create the new lot.
21788                Call Lot Create API INV_ROI_INTEGRATION_GRP.INV_NEW_LOT to create the new lot.
21789                This shall also create lot specific conversions after creating the new Lot.
21790 			      This replaces the existing procedure INV_LOT_API_PUB.CREATE_INV_LOT to create NEW LOT
21791                Punit Kumar*/
21792 
21793              /*INVCONV ,*/
21794              IF (l_debug = 1) THEN
21795                 print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
21796              END IF;
21797 
21798               INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
21799                                                          x_return_status      		   => x_return_status
21800                                                          ,x_msg_data           		   => x_msg_data
21801                                                          ,x_msg_count          		   => x_msg_count
21802                                                         ,p_api_version	               => 1.0
21803                                                         ,p_init_msg_lst	               => FND_API.G_FALSE
21804                                                         ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
21805                                                         ,p_transaction_type_id 	      => l_transaction_type_id
21806                                                         ,p_new_lot			            => 'Y'
21807                                                         ,p_item_id	 		            => l_item_id
21808                                                         ,p_to_organization_id		      => L_ORG_ID
21809                                                         ,p_lot_number			         => L_MTLT_REC.lot_number
21810                                                         ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
21811                                                         ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
21812                                                         ,x_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
21813                                                         ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
21814                                                         ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
21815                                                         ,p_transaction_unit_of_measure => l_rti_UNIT_OF_MEASURE
21816                                                         ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
21817                                                         ,p_OE_ORDER_HEADER_ID	         => l_OE_ORDER_HEADER_ID
21818                                                         ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
21819                                                         ,p_rti_id	                     => L_RTI_ID
21820                                                         ,p_revision             	      => l_item_revision
21821                                                         ,p_subinventory_code  	      => L_SUB_CODE
21822                                                         ,p_locator_id           	      => l_loc_id
21823                                                         ,p_transaction_type           => l_transaction_type
21824                                                         ,p_parent_txn_type            => l_parent_txn_type
21825                                                         ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
21826                                                         );
21827               /*INVCONV ,*/
21828               IF (l_debug = 1) THEN
21829                  print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
21830                  print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
21831               END IF;
21832 
21833             IF (x_return_status <> 'S') THEN
21834 		       --raise error
21835 		       l_progress := 'WMSINB-24062';
21836 		       RAISE fnd_api.g_exc_error;
21837 		    END IF;
21838 
21839             /*INVCONV ,*/
21840           IF (l_debug = 1) THEN
21841              print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
21842           END IF;
21843 
21844            INV_ROI_INTEGRATION_GRP.INV_NEW_LOT(
21845                                                 x_return_status      		   => x_return_status
21846                                                ,x_msg_count          		   => x_msg_count
21847                                                ,x_msg_data           		   => x_msg_data
21848                                                ,p_api_version	               => 1.0
21849                                                ,p_init_msg_lst	               => FND_API.G_FALSE
21850                                                ,p_source_document_code			=> L_SOURCE_DOCUMENT_CODE
21851                                                ,p_item_id				         => l_item_id
21852                                                ,p_from_organization_id			=> L_FROM_ORG_ID
21853                                                ,p_to_organization_id	         => L_ORG_ID
21854                                                ,p_lot_number				      => L_MTLT_REC.lot_number
21855                                                ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
21856                                                ,p_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
21857                                                ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
21858                                                ,p_primary_unit_of_measure	   => l_rti_PRIMARY_UNIT_OF_MEASURE
21859                                                ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
21860                                                ,p_uom_code	                  => l_rti_UOM_CODE
21861                                                ,p_secondary_uom_code	         => l_rti_SECONDARY_UOM_CODE
21862                                                ,p_reason_id	                  => L_MTLT_REC.REASON_ID
21863                                                ,P_MLN_REC                     => L_MLN_REC
21864                                                ,p_mtlt_rowid	               => L_MTLT_REC.ROWID
21865                                                 );
21866            /*INVCONV ,*/
21867            IF (l_debug = 1) THEN
21868               print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
21869               print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_NEW_LOT return status: '||x_return_status||' : '||l_progress, 1);
21870            END IF;
21871 
21872 		    IF X_RETURN_STATUS <> 'S' THEN
21873 		       --RAISE ERROR
21874 		       l_progress := 'WMSINB-24086';
21875 		       RAISE fnd_api.g_exc_error;
21876 		    END IF;
21877 
21878 		    IF (l_debug = 1) THEN
21879 		       print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CREATED: '||x_return_status||' : '||l_progress, 1);
21880 		    END IF;
21881 	      END IF;--IF L_LOT_EXISTS = 1 THEN
21882 
21883 	      IF (L_SERIAL_NUMBER_CONTROL_CODE IN (2,5)) THEN
21884 
21885 		 IF (l_debug = 1) THEN
21886 		    print_debug('VALIDATE_LOT_SERIAL_INFO: LOT AND SERIAL CONTROLLED: '||l_progress, 1);
21887 		    print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROL CODE: '||l_serial_number_control_code||' : '||l_progress, 1);
21888 		    print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||l_source_document_code||' : '||l_progress, 1);
21889 		    l_progress := 'WMSINB-24102';
21890 		 END IF;
21891 
21892 		 L_NUM_MSNT_RECS := 0;
21893 		 l_tot_msnt_serial_qty := 0;
21894 
21895 		 OPEN C_MSNT_LOTSERIAL(L_MTLT_REC.SERIAL_TRANSACTION_TEMP_ID);
21896 
21897 		 LOOP
21898 		    FETCH C_MSNT_LOTSERIAL INTO L_MSNT_REC;
21899 
21900 		    EXIT WHEN C_MSNT_LOTSERIAL%NOTFOUND;
21901 
21902 		    L_NUM_MSNT_RECS := L_NUM_MSNT_RECS + 1;
21903 
21904 		    L_SERIAL_QUANTITY :=
21905 		      INV_SERIAL_NUMBER_PUB.GET_SERIAL_DIFF(L_MSNT_REC.FM_SERIAL_NUMBER,
21906 							    L_MSNT_REC.TO_SERIAL_NUMBER);
21907 
21908 		    l_tot_msnt_serial_qty := l_tot_msnt_serial_qty + l_serial_quantity;
21909 
21910 		    INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.FM_SERIAL_NUMBER, L_TEMP_PREFIX, L_FROM_SER_NUMBER);
21911 		    INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.TO_SERIAL_NUMBER, L_TEMP_PREFIX, L_TO_SER_NUMBER);
21912 
21913 		    IF (l_debug = 1) THEN
21914 		       print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL QUANTITY: '||l_serial_quantity||' : '||l_progress, 1);
21915 		       l_progress := 'WMSINB-24127';
21916 		    END IF;
21917 
21918 		    --populate attributes table
21919 		    l_serial_attributes_tbl(1).column_name   := 'SERIAL_ATTRIBUTE_CATEGORY';
21920 		    l_serial_attributes_tbl(1).column_value  := l_msnt_rec.serial_attribute_category;
21921 		    l_serial_attributes_tbl(2).column_name   := 'ORIGINATION_DATE';
21922 		    l_serial_attributes_tbl(2).column_value  := l_msnt_rec.origination_date;
21923 		    l_serial_attributes_tbl(3).column_name   := 'C_ATTRIBUTE1';
21924 		    l_serial_attributes_tbl(3).column_value  := l_msnt_rec.c_attribute1;
21925 		    l_serial_attributes_tbl(4).column_name   := 'C_ATTRIBUTE2';
21926 		    l_serial_attributes_tbl(4).column_value  := l_msnt_rec.c_attribute2;
21927 		    l_serial_attributes_tbl(5).column_name   := 'C_ATTRIBUTE3';
21928 		    l_serial_attributes_tbl(5).column_value  := l_msnt_rec.c_attribute3;
21929 		    l_serial_attributes_tbl(6).column_name   := 'C_ATTRIBUTE4';
21930 		    l_serial_attributes_tbl(6).column_value   := l_msnt_rec.c_attribute4;
21931 		    l_serial_attributes_tbl(7).column_name   := 'C_ATTRIBUTE5';
21932 		    l_serial_attributes_tbl(7).column_value   := l_msnt_rec.c_attribute5;
21933 		    l_serial_attributes_tbl(8).column_name   := 'C_ATTRIBUTE6';
21934 		    l_serial_attributes_tbl(8).column_value   := l_msnt_rec.c_attribute6;
21935 		    l_serial_attributes_tbl(9).column_name   := 'C_ATTRIBUTE7';
21936 		    l_serial_attributes_tbl(9).column_value   := l_msnt_rec.c_attribute7;
21937 		    l_serial_attributes_tbl(10).column_name  := 'C_ATTRIBUTE8';
21938 		    l_serial_attributes_tbl(10).column_value  := l_msnt_rec.c_attribute8;
21939 		    l_serial_attributes_tbl(11).column_name  := 'C_ATTRIBUTE9';
21940 		    l_serial_attributes_tbl(11).column_value  := l_msnt_rec.c_attribute9;
21941 		    l_serial_attributes_tbl(12).column_name  := 'C_ATTRIBUTE10';
21942 		    l_serial_attributes_tbl(12).column_value  := l_msnt_rec.c_attribute10;
21943 		    l_serial_attributes_tbl(13).column_name  := 'C_ATTRIBUTE11';
21944 		    l_serial_attributes_tbl(13).column_value  := l_msnt_rec.c_attribute11;
21945 		    l_serial_attributes_tbl(14).column_name  := 'C_ATTRIBUTE12';
21946 		    l_serial_attributes_tbl(14).column_value  := l_msnt_rec.c_attribute12;
21947 		    l_serial_attributes_tbl(15).column_name  := 'C_ATTRIBUTE13';
21948 		    l_serial_attributes_tbl(15).column_value  := l_msnt_rec.c_attribute13;
21949 		    l_serial_attributes_tbl(16).column_name  := 'C_ATTRIBUTE14';
21950 		    l_serial_attributes_tbl(16).column_value  := l_msnt_rec.c_attribute14;
21951 		    l_serial_attributes_tbl(17).column_name  := 'C_ATTRIBUTE15';
21952 		    l_serial_attributes_tbl(17).column_value  := l_msnt_rec.c_attribute15;
21953 		    l_serial_attributes_tbl(18).column_name  := 'C_ATTRIBUTE16';
21954 		    l_serial_attributes_tbl(18).column_value  := l_msnt_rec.c_attribute16;
21955 		    l_serial_attributes_tbl(19).column_name  := 'C_ATTRIBUTE17';
21956 		    l_serial_attributes_tbl(19).column_value  := l_msnt_rec.c_attribute17;
21957 		    l_serial_attributes_tbl(20).column_name  := 'C_ATTRIBUTE18';
21958 		    l_serial_attributes_tbl(20).column_value  := l_msnt_rec.c_attribute18;
21959 		    l_serial_attributes_tbl(21).column_name  := 'C_ATTRIBUTE19';
21960 		    l_serial_attributes_tbl(21).column_value  := l_msnt_rec.c_attribute19;
21961 		    l_serial_attributes_tbl(22).column_name  := 'C_ATTRIBUTE20';
21962 		    l_serial_attributes_tbl(22).column_value  := l_msnt_rec.c_attribute20;
21963 		    l_serial_attributes_tbl(23).column_name  := 'D_ATTRIBUTE1';
21964 		    l_serial_attributes_tbl(23).column_value  := l_msnt_rec.d_attribute1;
21965 		    l_serial_attributes_tbl(24).column_name  := 'D_ATTRIBUTE2';
21966 		    l_serial_attributes_tbl(24).column_value  := l_msnt_rec.d_attribute2;
21967 		    l_serial_attributes_tbl(25).column_name  := 'D_ATTRIBUTE3';
21968 		    l_serial_attributes_tbl(25).column_value  := l_msnt_rec.d_attribute3;
21969 		    l_serial_attributes_tbl(26).column_name  := 'D_ATTRIBUTE4';
21970 		    l_serial_attributes_tbl(26).column_value  := l_msnt_rec.d_attribute4;
21971 		    l_serial_attributes_tbl(27).column_name  := 'D_ATTRIBUTE5';
21972 		    l_serial_attributes_tbl(27).column_value  := l_msnt_rec.d_attribute5;
21973 		    l_serial_attributes_tbl(28).column_name  := 'D_ATTRIBUTE6';
21974 		    l_serial_attributes_tbl(28).column_value  := l_msnt_rec.d_attribute6;
21975 		    l_serial_attributes_tbl(29).column_name  := 'D_ATTRIBUTE7';
21976 		    l_serial_attributes_tbl(29).column_value  := l_msnt_rec.d_attribute7;
21977 		    l_serial_attributes_tbl(30).column_name  := 'D_ATTRIBUTE8';
21978 		    l_serial_attributes_tbl(30).column_value  := l_msnt_rec.d_attribute8;
21979 		    l_serial_attributes_tbl(31).column_name  := 'D_ATTRIBUTE9';
21980 		    l_serial_attributes_tbl(31).column_value  := l_msnt_rec.d_attribute9;
21981 		    l_serial_attributes_tbl(32).column_name  := 'D_ATTRIBUTE10';
21982 		    l_serial_attributes_tbl(32).column_value  := l_msnt_rec.d_attribute10;
21983 		    l_serial_attributes_tbl(33).column_name  := 'N_ATTRIBUTE1';
21984 		    l_serial_attributes_tbl(33).column_value  := l_msnt_rec.n_attribute1;
21985 		    l_serial_attributes_tbl(34).column_name  := 'N_ATTRIBUTE2';
21986 		    l_serial_attributes_tbl(34).column_value  := l_msnt_rec.n_attribute2;
21987 		    l_serial_attributes_tbl(35).column_name  := 'N_ATTRIBUTE3';
21988 		    l_serial_attributes_tbl(35).column_value  := l_msnt_rec.n_attribute3;
21989 		    l_serial_attributes_tbl(36).column_name  := 'N_ATTRIBUTE4';
21990 		    l_serial_attributes_tbl(36).column_value  := l_msnt_rec.n_attribute4;
21991 		    l_serial_attributes_tbl(37).column_name  := 'N_ATTRIBUTE5';
21992 		    l_serial_attributes_tbl(37).column_value := l_msnt_rec.n_attribute5;
21993 		    l_serial_attributes_tbl(38).column_name  := 'N_ATTRIBUTE6';
21994 		    l_serial_attributes_tbl(38).column_value := l_msnt_rec.n_attribute6;
21995 		    l_serial_attributes_tbl(39).column_name  := 'N_ATTRIBUTE7';
21996 		    l_serial_attributes_tbl(39).column_value := l_msnt_rec.n_attribute7;
21997 		    l_serial_attributes_tbl(40).column_name  := 'N_ATTRIBUTE8';
21998 		    l_serial_attributes_tbl(40).column_value := l_msnt_rec.n_attribute8;
21999 		    l_serial_attributes_tbl(41).column_name  := 'N_ATTRIBUTE9';
22000 		    l_serial_attributes_tbl(41).column_value := l_msnt_rec.n_attribute9;
22001 		    l_serial_attributes_tbl(42).column_name  := 'N_ATTRIBUTE10';
22002 		    l_serial_attributes_tbl(42).column_value := l_msnt_rec.n_attribute10;
22003 		    l_serial_attributes_tbl(43).column_name  := 'STATUS_ID';
22004 		    l_serial_attributes_tbl(43).column_value := l_msnt_rec.status_id;
22005 		    l_serial_attributes_tbl(44).column_name  := 'TERRITORY_CODE';
22006 		    l_serial_attributes_tbl(44).column_value := l_msnt_rec.territory_code;
22007 
22008 		    --R12: Get the EPC info for this MSNT
22009 		    get_epc_info(p_mode          => 2
22010 				 ,p_ser_if_rowid => l_msnt_rec.ROWID
22011 				 ,x_epc_column   => l_epc_column
22012 				 ,x_epc_value    => l_epc_value
22013 				 );
22014 
22015 		    IF (l_debug = 1) THEN
22016 		       print_debug('l_epc_column:'||l_epc_column||' l_epc_value:'||l_epc_value,4);
22017 		    END IF;
22018 
22019 		    --Validate the serials
22020 		    FOR SERIALQTY IN 1..L_SERIAL_QUANTITY LOOP
22021 
22022 		       l_progress := 'WMSINB-24133';
22023 
22024                        L_CUR_NUMBER := L_FROM_SER_NUMBER+SERIALQTY -1;
22025                        if L_FROM_SER_NUMBER = -1 and  L_TO_SER_NUMBER = -1 then
22026 	                    L_SERIAL_NUMBER  := L_MSNT_REC.fm_serial_number;
22027 		       else
22028 		            L_SERIAL_NUMBER :=
22029 			      SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
22030 				LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
22031 				LENGTH(L_CUR_NUMBER))
22032 			      ||L_CUR_NUMBER;
22033                        End if;
22034 
22035 		       l_progress := 'WMSINB-24141';
22036 
22037 		       BEGIN
22038 			  SELECT CURRENT_ORGANIZATION_ID
22039 			    , current_status
22040 			    , lot_number
22041 			    , Decode(lpn_id,0,NULL,lpn_id)
22042 			    , inspection_status
22043 			    , group_mark_id
22044 			    INTO L_CURR_ORG_ID
22045 			    , l_curr_status
22046 			    , l_curr_lot_num
22047 			    , l_curr_lpn_id
22048 			    , l_inspection_status
22049 			    , l_group_mark_id
22050 			    FROM MTL_SERIAL_NUMBERS
22051 			    WHERE SERIAL_NUMBER = l_serial_number
22052 			    AND inventory_item_id = l_item_id;
22053 
22054 			  l_serial_exists := 1;
22055 			  l_progress := 'WMSINB-24161';
22056 		       EXCEPTION
22057 			  WHEN no_data_found THEN
22058 			     l_serial_exists := 0;
22059 			     l_progress := 'WMSINB-24165';
22060 		       END;
22061 
22062 		       IF (l_debug = 1) THEN
22063 			  print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL EXISTS: '||l_serial_exists||' : '||l_progress, 1);
22064 			  print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NUMBER: '||l_serial_number||' : '||l_progress, 1);
22065 			  print_debug('VALIDATE_LOT_SERIAL_INFO: CURR STATUS: '||l_curr_status||' : '||l_progress, 1);
22066 			  print_debug('VALIDATE_LOT_SERIAL_INFO: CURR ORG ID: '||l_curr_org_id||' : '||l_progress, 1);
22067 			  print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LPN ID: '||l_curr_lpn_id||' : '||l_progress, 1);
22068 			  print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LOT NUM: '||l_curr_lot_num||' : '||l_progress, 1);
22069 			  print_debug('VALIDATE_LOT_SERIAL_INFO: INSPECT STS: '||l_inspection_status||' : '||l_progress, 1);
22070 			  print_debug('VALIDATE_LOT_SERIAL_INFO: GROUP MARK ID: '||l_group_mark_id||' : '||l_progress, 1);
22071 			  print_debug('VALIDATE_LOT_SERIAL_INFO: RESTRICT RCPT SER: '||l_restrict_rcpt_ser||' : '||l_progress, 1);
22072 			  l_progress := 'WMSINB-24178';
22073 		       END IF;
22074 
22075 		       IF (l_serial_exists = 1) THEN
22076 			  IF l_curr_org_id <> l_org_id THEN
22077 			     --raise error
22078 			     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22079 			     fnd_msg_pub.ADD;
22080 			     l_progress := 'WMSINB-24186';
22081 			     RAISE fnd_api.g_exc_error;
22082 			   ELSE
22083 			     IF ((l_curr_lot_num IS NOT NULL) AND
22084 				 (l_curr_lot_num <> l_mtlt_rec.lot_number)
22085 				 AND (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
22086 				--raise error
22087 				fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22088 				fnd_msg_pub.ADD;
22089 				l_progress := 'WMSINB-24193';
22090 				RAISE fnd_api.g_exc_error;
22091 			     END IF;
22092 			  END IF;
22093 
22094 	/* Bug#6670394
22095 	   * In order to allow the Issued out Serial numbers during
22096 	   * ASN import transaction made the following changes.
22097 	   */
22098 			  IF l_curr_status NOT IN (1,4,6) THEN --Bug#6670394
22099 			     --raise error
22100 			     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22101 			     fnd_msg_pub.ADD;
22102 			     l_progress := 'WMSINB-24202';
22103 			     RAISE fnd_api.g_exc_error;
22104 			  END IF;
22105 
22106 			  IF (Nvl(l_group_mark_id, -99) = -7937) THEN
22107 			     --raise error
22108 			     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22109 			     fnd_msg_pub.ADD;
22110 			     l_progress := 'WMSINB-24210';
22111 			     RAISE fnd_api.g_exc_error;
22112 			  END IF;
22113 
22114 			  IF (Nvl(l_curr_status, 1) IN (1,6)) THEN
22115 			     --validate and update the attributes.
22116 			     inv_serial_number_pub.validate_update_serial_att
22117 			       (x_return_status     => x_return_status,
22118 				x_msg_count         => x_msg_count,
22119 				x_msg_data          => x_msg_data,
22120 				x_validation_status => l_validation_status,
22121 				p_serial_number     => l_serial_number,
22122 				p_organization_id   => l_org_id,
22123 				p_inventory_item_id => l_item_id,
22124 				p_serial_att_tbl    => l_serial_attributes_tbl,
22125 				p_validate_only     => FALSE
22126 				);
22127 
22128 			     IF (l_validation_status <> 'Y'
22129 				 OR x_return_status <> g_ret_sts_success) THEN
22130 				--raise error
22131 				fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22132 				fnd_msg_pub.ADD;
22133 				l_progress := 'WMSINB-24215';
22134 				RAISE fnd_api.g_exc_error;
22135 			     END IF;
22136 			  END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
22137 
22138 			  --UPDATE GROUP_MARK_ID TO -7937
22139 			  IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
22140 			     --raise error
22141 			     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22142 			     fnd_msg_pub.ADD;
22143 			     l_progress := 'WMSINB-24219';
22144 			     RAISE fnd_api.g_exc_error;
22145 			  END IF;
22146 			ELSE --IF (l_serial_exists = 1) THEN
22147 			  IF l_serial_number_control_code = 5 THEN
22148 			     --PERFORM SERIAL VALIDATION FOR NEW SERIAL
22149 			     --(INCLUDING ATT VALIDATION)
22150 			     --CREATE MSN
22151 
22152 			     inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
22153 								       , p_inventory_item_id => l_item_id
22154 								       , p_organization_id => l_org_id
22155 								       , p_from_serial_number => l_serial_number
22156 								       , p_to_serial_number => l_serial_number
22157 								       , p_initialization_date => SYSDATE
22158 								       , p_completion_date => NULL
22159 								       , p_ship_date => NULL
22160 								       , p_revision => l_item_revision
22161 								       , p_lot_number => l_mtlt_rec.lot_number
22162 								       , p_current_locator_id => l_loc_id
22163 								       , p_subinventory_code => l_sub_code
22164 								       , p_trx_src_id => NULL
22165 								       , p_unit_vendor_id => NULL
22166 								       , p_vendor_lot_number => l_mtlt_rec.supplier_lot_number
22167 								       , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
22168 								       , p_receipt_issue_type => NULL
22169 								       , p_txn_src_id => NULL
22170 								       , p_txn_src_name => NULL
22171 								       , p_txn_src_type_id => NULL
22172 								       , p_transaction_id => NULL
22173 			       , p_current_status => 1
22174 			       , p_parent_item_id => NULL
22175 			       , p_parent_serial_number => NULL
22176 			       , p_cost_group_id => NULL
22177 			       , p_transaction_action_id => 27
22178 			       , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
22179 			       , p_status_id => NULL
22180 			       , p_inspection_status => NULL
22181 			       , x_object_id => l_object_id
22182 			       , x_return_status => x_return_status
22183 			       , x_msg_count => x_msg_count
22184 			       , x_msg_data => x_msg_data);
22185 
22186 			     IF (x_return_status <> g_ret_sts_success) THEN
22187 				--raise error
22188 				fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22189 				fnd_msg_pub.ADD;
22190 				l_progress := 'WMSINB-24225';
22191 				RAISE fnd_api.g_exc_error;
22192 			     END IF;
22193 
22194 			     --validate and update the attributes.
22195 			     inv_serial_number_pub.validate_update_serial_att
22196 			       (x_return_status     => x_return_status,
22197 				x_msg_count         => x_msg_count,
22198 				x_msg_data          => x_msg_data,
22199 				x_validation_status => l_validation_status,
22200 				p_serial_number     => l_serial_number,
22201 				p_organization_id   => l_org_id,
22202 				p_inventory_item_id => l_item_id,
22203 				p_serial_att_tbl    => l_serial_attributes_tbl,
22204 				p_validate_only     => FALSE
22205 				);
22206 
22207 			     IF (l_validation_status <> 'Y'
22208 				 OR x_return_status <> g_ret_sts_success) THEN
22209 				--raise error
22210 				fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22211 				fnd_msg_pub.ADD;
22212 				l_progress := 'WMSINB-24260';
22213 				RAISE fnd_api.g_exc_error;
22214 			     END IF;
22215 
22216 			     --UPDATE GROUP_MARK_ID TO -7937
22217 			     IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
22218 				--raise error
22219 				fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22220 				fnd_msg_pub.ADD;
22221 				l_progress := 'WMSINB-24267';
22222 				RAISE fnd_api.g_exc_error;
22223 			     END IF;
22224 			   ELSE
22225 			     --raise error
22226 			     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22227 			     fnd_msg_pub.ADD;
22228 			     l_progress := 'WMSINB-24274';
22229 			     RAISE fnd_api.g_exc_error;
22230 			  END IF;
22231 		       END IF; --IF (l_serial_exists = 1) THEN
22232 
22233 		       --Call EPC API here for ASN Import
22234 		       IF (l_epc_column IS NOT NULL) THEN
22235 			  IF (Nvl(g_lpn_group_id,-999) <> l_lpn_grp_id) THEN
22236 			     g_lpn_group_id := l_lpn_grp_id;
22237 			     SELECT wms_epc_s2.NEXTVAL
22238 			       INTO g_epc_group_id
22239 			       FROM dual;
22240 			  END IF;
22241 
22242 			  IF (l_debug = 1) THEN
22243 			     print_debug('Calling populate_outside_epc',4);
22244 			     print_debug(' p_group_id       => '||g_epc_group_id,4);
22245 			     print_debug(' p_cross_ref_type => '||2,4);
22246 			     print_debug(' p_epc            => '||l_epc_value,4);
22247 			     print_debug(' p_serial_number  => '||l_serial_number,4);
22248 			  END IF;
22249 
22250 			  wms_epc_pvt.populate_outside_epc
22251 			    (p_group_id        => g_epc_group_id
22252 			     ,p_cross_ref_type => 2 --LPN-EPC
22253 			     ,p_serial_number  => l_serial_number
22254 			     ,p_epc            => l_epc_value
22255 			     ,x_return_status  => l_return_status
22256 			     ,x_return_mesg    => l_msg_data
22257 			     );
22258 
22259 		       END IF;--IF (l_epc_column IS NOT NULL) THEN
22260 		    END LOOP; -- FOR 1..L_SERIAL_QUANTITY
22261 		 END LOOP; --FETCH C_MSNT_LOTSERIAL INTO L_MSNT_REC;
22262 
22263 		 CLOSE c_msnt_lotserial;
22264 
22265 		 IF (l_num_msnt_recs > 0) THEN
22266 		    IF l_mtlt_rec.primary_quantity <> l_tot_msnt_serial_qty THEN
22267 		       --raise error
22268 		       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22269 		       fnd_msg_pub.ADD;
22270 		       l_progress := 'WMSINB-24288';
22271 		       RAISE fnd_api.g_exc_error;
22272 		    END IF;
22273 		  ELSE
22274 		    IF (l_serial_number_control_code IN (2,5)
22275 			OR (l_serial_number_control_code = 6
22276 			    AND l_source_document_code IN ('RMA','REQ','INVENTORY'))) THEN
22277 		       --raise error
22278 		       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22279 		       fnd_msg_pub.ADD;
22280 		       l_progress := 'WMSINB-24295';
22281 		       RAISE fnd_api.g_exc_error;
22282 		    END IF;
22283 		 END IF;
22284 
22285 	      END IF; -- IF (L_SERIAL_NUMBER_CONTROL_CODE IN (2,5)) THEN
22286 	   END LOOP; --FETCH C_MTLT INTO L_MTLT_REC;
22287 
22288 	   CLOSE c_mtlt;
22289 
22290           /* Bug 4546519 : l_tot_mtlt_prim_qty is a computed floating point number.
22291            **  In the following condition, it is necessary to use round function for
22292            **  comparing the floating point values.
22293            */
22294 	   IF (l_num_mtlt_recs > 0) THEN
22295 	      IF (ROUND(l_tot_mtlt_prim_qty,5) <> ROUND(l_rti_primary_qty,5)) THEN
22296 		-- Bug# 4225766 Compare transaction qty there can be a difference in primary qty
22297 		-- if there is a lot specific conversion
22298 		IF (ROUND(l_tot_mtlt_trans_qty,5) <> ROUND(l_rti_trans_qty,5)) THEN -- Bug# 4225766
22299 			--raise error
22300 			fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22301 			fnd_msg_pub.ADD;
22302 			l_progress := 'WMSINB-24309';
22303 			RAISE fnd_api.g_exc_error;
22304 		END IF; -- Bug# 4225766
22305 	      END IF;
22306 	   END IF;
22307 	 ELSIF l_serial_number_control_code IN (2,5) THEN --IF (L_LOT_CONTROL_CODE = 2) THEN
22308 
22309 		       IF (l_debug = 1) THEN
22310 			  print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROLLED: '||l_progress, 1);
22311 			  print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROL CODE: '||l_serial_number_control_code||' : '||l_progress, 1);
22312 			  print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||l_source_document_code||' : '||l_progress, 1);
22313 			  l_progress := 'WMSINB-24319';
22314 		       END IF;
22315 		       L_NUM_MSNT_RECS := 0;
22316 		       l_tot_msnt_serial_qty := 0;
22317 
22318 		       OPEN C_MSNT(L_RTI_ID);
22319 
22320 		       LOOP
22321 			  FETCH C_MSNT INTO L_MSNT_REC;
22322 
22323 			  EXIT WHEN C_MSNT%NOTFOUND;
22324 
22325 			  L_NUM_MSNT_RECS := L_NUM_MSNT_RECS + 1;
22326 
22327 			  L_SERIAL_QUANTITY :=
22328 			    INV_SERIAL_NUMBER_PUB.GET_SERIAL_DIFF(L_MSNT_REC.FM_SERIAL_NUMBER,
22329 								  L_MSNT_REC.TO_SERIAL_NUMBER);
22330 
22331 			  l_tot_msnt_serial_qty := l_tot_msnt_serial_qty + l_serial_quantity;
22332 
22333 			  INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.FM_SERIAL_NUMBER, L_TEMP_PREFIX, L_FROM_SER_NUMBER);
22334 			  INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.TO_SERIAL_NUMBER, L_TEMP_PREFIX, L_TO_SER_NUMBER);
22335 
22336 			  IF (l_debug = 1) THEN
22337 			     print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL QUANTITY: '||l_serial_quantity||' : '||l_progress, 1);
22338 			     print_debug('VALIDATE_LOT_SERIAL_INFO: L_TEMP_PREFIX: '||L_TEMP_PREFIX, 1);
22339 			     l_progress := 'WMSINB-24343';
22340 			  END IF;
22341 
22342 			  --populate attributes table
22343 			  l_serial_attributes_tbl(1).column_name   := 'SERIAL_ATTRIBUTE_CATEGORY';
22344 			  l_serial_attributes_tbl(1).column_value  := l_msnt_rec.serial_attribute_category;
22345 			  l_serial_attributes_tbl(2).column_name   := 'ORIGINATION_DATE';
22346 			  l_serial_attributes_tbl(2).column_value  := l_msnt_rec.origination_date;
22347 			  l_serial_attributes_tbl(3).column_name   := 'C_ATTRIBUTE1';
22348 			  l_serial_attributes_tbl(3).column_value  := l_msnt_rec.c_attribute1;
22349 			  l_serial_attributes_tbl(4).column_name   := 'C_ATTRIBUTE2';
22350 			  l_serial_attributes_tbl(4).column_value  := l_msnt_rec.c_attribute2;
22351 			  l_serial_attributes_tbl(5).column_name   := 'C_ATTRIBUTE3';
22352 			  l_serial_attributes_tbl(5).column_value  := l_msnt_rec.c_attribute3;
22353 			  l_serial_attributes_tbl(6).column_name   := 'C_ATTRIBUTE4';
22354 			  l_serial_attributes_tbl(6).column_value   := l_msnt_rec.c_attribute4;
22355 			  l_serial_attributes_tbl(7).column_name   := 'C_ATTRIBUTE5';
22356 			  l_serial_attributes_tbl(7).column_value   := l_msnt_rec.c_attribute5;
22357 			  l_serial_attributes_tbl(8).column_name   := 'C_ATTRIBUTE6';
22358 			  l_serial_attributes_tbl(8).column_value   := l_msnt_rec.c_attribute6;
22359 			  l_serial_attributes_tbl(9).column_name   := 'C_ATTRIBUTE7';
22360 			  l_serial_attributes_tbl(9).column_value   := l_msnt_rec.c_attribute7;
22361 			  l_serial_attributes_tbl(10).column_name  := 'C_ATTRIBUTE8';
22362 			  l_serial_attributes_tbl(10).column_value  := l_msnt_rec.c_attribute8;
22363 			  l_serial_attributes_tbl(11).column_name  := 'C_ATTRIBUTE9';
22364 			  l_serial_attributes_tbl(11).column_value  := l_msnt_rec.c_attribute9;
22365 			  l_serial_attributes_tbl(12).column_name  := 'C_ATTRIBUTE10';
22366 			  l_serial_attributes_tbl(12).column_value  := l_msnt_rec.c_attribute10;
22367 			  l_serial_attributes_tbl(13).column_name  := 'C_ATTRIBUTE11';
22368 			  l_serial_attributes_tbl(13).column_value  := l_msnt_rec.c_attribute11;
22369 			  l_serial_attributes_tbl(14).column_name  := 'C_ATTRIBUTE12';
22370 			  l_serial_attributes_tbl(14).column_value  := l_msnt_rec.c_attribute12;
22371 			  l_serial_attributes_tbl(15).column_name  := 'C_ATTRIBUTE13';
22372 			  l_serial_attributes_tbl(15).column_value  := l_msnt_rec.c_attribute13;
22373 			  l_serial_attributes_tbl(16).column_name  := 'C_ATTRIBUTE14';
22374 			  l_serial_attributes_tbl(16).column_value  := l_msnt_rec.c_attribute14;
22375 			  l_serial_attributes_tbl(17).column_name  := 'C_ATTRIBUTE15';
22376 			  l_serial_attributes_tbl(17).column_value  := l_msnt_rec.c_attribute15;
22377 			  l_serial_attributes_tbl(18).column_name  := 'C_ATTRIBUTE16';
22378 			  l_serial_attributes_tbl(18).column_value  := l_msnt_rec.c_attribute16;
22379 			  l_serial_attributes_tbl(19).column_name  := 'C_ATTRIBUTE17';
22380 			  l_serial_attributes_tbl(19).column_value  := l_msnt_rec.c_attribute17;
22381 			  l_serial_attributes_tbl(20).column_name  := 'C_ATTRIBUTE18';
22382 			  l_serial_attributes_tbl(20).column_value  := l_msnt_rec.c_attribute18;
22383 			  l_serial_attributes_tbl(21).column_name  := 'C_ATTRIBUTE19';
22384 			  l_serial_attributes_tbl(21).column_value  := l_msnt_rec.c_attribute19;
22385 			  l_serial_attributes_tbl(22).column_name  := 'C_ATTRIBUTE20';
22386 			  l_serial_attributes_tbl(22).column_value  := l_msnt_rec.c_attribute20;
22387 			  l_serial_attributes_tbl(23).column_name  := 'D_ATTRIBUTE1';
22388 			  l_serial_attributes_tbl(23).column_value  := l_msnt_rec.d_attribute1;
22389 			  l_serial_attributes_tbl(24).column_name  := 'D_ATTRIBUTE2';
22390 			  l_serial_attributes_tbl(24).column_value  := l_msnt_rec.d_attribute2;
22391 			  l_serial_attributes_tbl(25).column_name  := 'D_ATTRIBUTE3';
22392 			  l_serial_attributes_tbl(25).column_value  := l_msnt_rec.d_attribute3;
22393 			  l_serial_attributes_tbl(26).column_name  := 'D_ATTRIBUTE4';
22394 			  l_serial_attributes_tbl(26).column_value  := l_msnt_rec.d_attribute4;
22395 			  l_serial_attributes_tbl(27).column_name  := 'D_ATTRIBUTE5';
22396 			  l_serial_attributes_tbl(27).column_value  := l_msnt_rec.d_attribute5;
22397 			  l_serial_attributes_tbl(28).column_name  := 'D_ATTRIBUTE6';
22398 			  l_serial_attributes_tbl(28).column_value  := l_msnt_rec.d_attribute6;
22399 			  l_serial_attributes_tbl(29).column_name  := 'D_ATTRIBUTE7';
22400 			  l_serial_attributes_tbl(29).column_value  := l_msnt_rec.d_attribute7;
22401 			  l_serial_attributes_tbl(30).column_name  := 'D_ATTRIBUTE8';
22402 			  l_serial_attributes_tbl(30).column_value  := l_msnt_rec.d_attribute8;
22403 			  l_serial_attributes_tbl(31).column_name  := 'D_ATTRIBUTE9';
22404 			  l_serial_attributes_tbl(31).column_value  := l_msnt_rec.d_attribute9;
22405 			  l_serial_attributes_tbl(32).column_name  := 'D_ATTRIBUTE10';
22406 			  l_serial_attributes_tbl(32).column_value  := l_msnt_rec.d_attribute10;
22407 			  l_serial_attributes_tbl(33).column_name  := 'N_ATTRIBUTE1';
22408 			  l_serial_attributes_tbl(33).column_value  := l_msnt_rec.n_attribute1;
22409 			  l_serial_attributes_tbl(34).column_name  := 'N_ATTRIBUTE2';
22410 			  l_serial_attributes_tbl(34).column_value  := l_msnt_rec.n_attribute2;
22411 			  l_serial_attributes_tbl(35).column_name  := 'N_ATTRIBUTE3';
22412 			  l_serial_attributes_tbl(35).column_value  := l_msnt_rec.n_attribute3;
22413 			  l_serial_attributes_tbl(36).column_name  := 'N_ATTRIBUTE4';
22414 			  l_serial_attributes_tbl(36).column_value  := l_msnt_rec.n_attribute4;
22415 			  l_serial_attributes_tbl(37).column_name  := 'N_ATTRIBUTE5';
22416 			  l_serial_attributes_tbl(37).column_value := l_msnt_rec.n_attribute5;
22417 			  l_serial_attributes_tbl(38).column_name  := 'N_ATTRIBUTE6';
22418 			  l_serial_attributes_tbl(38).column_value := l_msnt_rec.n_attribute6;
22419 			  l_serial_attributes_tbl(39).column_name  := 'N_ATTRIBUTE7';
22420 			  l_serial_attributes_tbl(39).column_value := l_msnt_rec.n_attribute7;
22421 			  l_serial_attributes_tbl(40).column_name  := 'N_ATTRIBUTE8';
22422 			  l_serial_attributes_tbl(40).column_value := l_msnt_rec.n_attribute8;
22423 			  l_serial_attributes_tbl(41).column_name  := 'N_ATTRIBUTE9';
22424 			  l_serial_attributes_tbl(41).column_value := l_msnt_rec.n_attribute9;
22425 			  l_serial_attributes_tbl(42).column_name  := 'N_ATTRIBUTE10';
22426 			  l_serial_attributes_tbl(42).column_value := l_msnt_rec.n_attribute10;
22427 			  l_serial_attributes_tbl(43).column_name  := 'STATUS_ID';
22428 			  l_serial_attributes_tbl(43).column_value := l_msnt_rec.status_id;
22429 			  l_serial_attributes_tbl(44).column_name  := 'TERRITORY_CODE';
22430 			  l_serial_attributes_tbl(44).column_value := l_msnt_rec.territory_code;
22431 
22432 			  --R12: Get the EPC info for this MSNT
22433 			  get_epc_info(p_mode          => 2
22434 				       ,p_ser_if_rowid => l_msnt_rec.ROWID
22435 				       ,x_epc_column   => l_epc_column
22436 				       ,x_epc_value    => l_epc_value
22437 				       );
22438 
22439 			  IF (l_debug = 1) THEN
22440 			     print_debug('l_epc_column:'||l_epc_column||' l_epc_value:'||l_epc_value,4);
22441 			  END IF;
22442 
22443 			  --Validate the serials
22444 			  FOR SERIALQTY IN 1..L_SERIAL_QUANTITY LOOP
22445 
22446                              L_CUR_NUMBER := L_FROM_SER_NUMBER+SERIALQTY -1;
22447 
22448                              if L_FROM_SER_NUMBER = -1 and  L_TO_SER_NUMBER = -1 then
22449 	                          L_SERIAL_NUMBER  := L_MSNT_REC.fm_serial_number;
22450 		             else
22451 		                  L_SERIAL_NUMBER :=
22452 			            SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
22453 				      LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
22454 				      LENGTH(L_CUR_NUMBER))
22455 			            ||L_CUR_NUMBER;
22456                              End if;
22457 
22458 			     --L_SERIAL_NUMBER :=
22459 			     --  SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
22460 			     -- LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
22461 			     -- LENGTH(L_FROM_SER_NUMBER))
22462 			      -- ||(L_FROM_SER_NUMBER+SERIALQTY -1);
22463 
22464 	                     BEGIN
22465 				SELECT CURRENT_ORGANIZATION_ID
22466 				  , current_status
22467 				  , lot_number
22468 				  , Decode(lpn_id,0,NULL,lpn_id)
22469 				  , inspection_status
22470 				  , group_mark_id
22471 				  INTO L_CURR_ORG_ID
22472 				  , l_curr_status
22473 				  , l_curr_lot_num
22474 				  , l_curr_lpn_id
22475 				  , l_inspection_status
22476 				  , l_group_mark_id
22477 				  FROM MTL_SERIAL_NUMBERS
22478 				  WHERE SERIAL_NUMBER = l_serial_number
22479 				  AND inventory_item_id = l_item_id;
22480 
22481 				l_serial_exists := 1;
22482 			     EXCEPTION
22483 				WHEN no_data_found THEN
22484 				   l_serial_exists := 0;
22485 			     END;
22486 
22487 			     IF (l_debug = 1) THEN
22488 				print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL EXISTS: '||l_serial_exists||' : '||l_progress, 1);
22489 				print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NUMBER: '||l_serial_number||' : '||l_progress, 1);
22490 				print_debug('VALIDATE_LOT_SERIAL_INFO: CURR STATUS: '||l_curr_status||' : '||l_progress, 1);
22491 				print_debug('VALIDATE_LOT_SERIAL_INFO: CURR ORG ID: '||l_curr_org_id||' : '||l_progress, 1);
22492 				print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LPN ID: '||l_curr_lpn_id||' : '||l_progress, 1);
22493 				print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LOT NUM: '||l_curr_lot_num||' : '||l_progress, 1);
22494 				print_debug('VALIDATE_LOT_SERIAL_INFO: INSPECT STS: '||l_inspection_status||' : '||l_progress, 1);
22495 				print_debug('VALIDATE_LOT_SERIAL_INFO: GROUP MARK ID: '||l_group_mark_id||' : '||l_progress, 1);
22496 				print_debug('VALIDATE_LOT_SERIAL_INFO: RESTRICT RCPT SER: '||l_restrict_rcpt_ser||' : '||l_progress, 1);
22497 				l_progress := 'WMSINB-24386';
22498 			     END IF;
22499 
22500 			     IF (l_serial_exists = 1) THEN
22501 				IF l_curr_org_id <> l_org_id THEN
22502 				   --raise error
22503 				   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22504 				   fnd_msg_pub.ADD;
22505 				   l_progress := 'WMSINB-24394';
22506 				   RAISE fnd_api.g_exc_error;
22507 				 ELSE
22508 				   IF (l_curr_lot_num IS NOT NULL) THEN
22509 				      --raise error
22510 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22511 				      fnd_msg_pub.ADD;
22512 				      l_progress := 'WMSINB-24401';
22513 				      RAISE fnd_api.g_exc_error;
22514 				   END IF;
22515 				END IF;
22516 
22517 				IF l_curr_status NOT IN (1,4,6) THEN --Bug#6670394
22518 				   --raise error
22519 				   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22520 				   fnd_msg_pub.ADD;
22521 				   l_progress := 'WMSINB-24410';
22522 				   RAISE fnd_api.g_exc_error;
22523 				END IF;
22524 
22525 				IF (Nvl(l_group_mark_id, -99) = -7937) THEN
22526 				   --raise error
22527 				   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22528 				   fnd_msg_pub.ADD;
22529 				   l_progress := 'WMSINB-24418';
22530 				   RAISE fnd_api.g_exc_error;
22531 				END IF;
22532 
22533 				IF (Nvl(l_curr_status, 1) in (1,6)) THEN
22534 				   --validate and update the attributes.
22535 				   inv_serial_number_pub.validate_update_serial_att
22536 				     (x_return_status     => x_return_status,
22537 				      x_msg_count         => x_msg_count,
22538 				      x_msg_data          => x_msg_data,
22539 				      x_validation_status => l_validation_status,
22540 				      p_serial_number     => l_serial_number,
22541 				      p_organization_id   => l_org_id,
22542 				      p_inventory_item_id => l_item_id,
22543 				      p_serial_att_tbl    => l_serial_attributes_tbl,
22544 				      p_validate_only     => FALSE
22545 				      );
22546 
22547 				   IF (l_validation_status <> 'Y'
22548 				       OR x_return_status <> g_ret_sts_success) THEN
22549 				      --raise error
22550 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22551 				      fnd_msg_pub.ADD;
22552 				      l_progress := 'WMSINB-24424';
22553 				      RAISE fnd_api.g_exc_error;
22554 				   END IF;
22555 				END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
22556 
22557 				--UPDATE GROUP_MARK_ID TO -7937
22558 				IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
22559 				   --raise error
22560 				   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22561 				   fnd_msg_pub.ADD;
22562 				   l_progress := 'WMSINB-24427';
22563 				   RAISE fnd_api.g_exc_error;
22564 				END IF;
22565 			      ELSE --IF (l_serial_exists = 1) THEN
22566 				IF l_serial_number_control_code = 5 THEN
22567 				   --PERFORM SERIAL VALIDATION FOR NEW SERIAL
22568 				   --(INCLUDING ATT VALIDATION)
22569 				   --CREATE MSN
22570 
22571 				   inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
22572 									     , p_inventory_item_id => l_item_id
22573 									     , p_organization_id => l_org_id
22574 									     , p_from_serial_number => l_serial_number
22575 									     , p_to_serial_number => l_serial_number
22576 									     , p_initialization_date => SYSDATE
22577 									     , p_completion_date => NULL
22578 									     , p_ship_date => NULL
22579 									     , p_revision => l_item_revision
22580 									     , p_lot_number => NULL
22581 									     , p_current_locator_id => l_loc_id
22582 									     , p_subinventory_code => l_sub_code
22583 									     , p_trx_src_id => NULL
22584 									     , p_unit_vendor_id => NULL
22585 									     , p_vendor_lot_number => NULL
22586 									     , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
22587 									     , p_receipt_issue_type => NULL
22588 									     , p_txn_src_id => NULL
22589 									     , p_txn_src_name => NULL
22590 									     , p_txn_src_type_id => NULL
22591 									     , p_transaction_id => NULL
22592 									     , p_current_status => 1
22593 									     , p_parent_item_id => NULL
22594 				     , p_parent_serial_number => NULL
22595 				     , p_cost_group_id => NULL
22596 				     , p_transaction_action_id => 27
22597 				     , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
22598 				     , p_status_id => NULL
22599 				     , p_inspection_status => NULL
22600 				     , x_object_id => l_object_id
22601 				     , x_return_status => x_return_status
22602 				     , x_msg_count => x_msg_count
22603 				     , x_msg_data => x_msg_data);
22604 
22605 				   IF (x_return_status <> g_ret_sts_success) THEN
22606 				      --raise error
22607 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22608 				      fnd_msg_pub.ADD;
22609 				      l_progress := 'WMSINB-24430';
22610 				      RAISE fnd_api.g_exc_error;
22611 				   END IF;
22612 
22613 				   --validate and update the attributes.
22614 				   inv_serial_number_pub.validate_update_serial_att
22615 				     (x_return_status     => x_return_status,
22616 				      x_msg_count         => x_msg_count,
22617 				      x_msg_data          => x_msg_data,
22618 				      x_validation_status => l_validation_status,
22619 				      p_serial_number     => l_serial_number,
22620 				      p_organization_id   => l_org_id,
22621 				      p_inventory_item_id => l_item_id,
22622 				      p_serial_att_tbl    => l_serial_attributes_tbl,
22623 				      p_validate_only     => FALSE
22624 				      );
22625 
22626 				   IF (l_validation_status <> 'Y'
22627 				       OR x_return_status <> g_ret_sts_success) THEN
22628 				      --raise error
22629 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22630 				      fnd_msg_pub.ADD;
22631 				      l_progress := 'WMSINB-24470';
22632 				      RAISE fnd_api.g_exc_error;
22633 				   END IF;
22634 
22635 				   --UPDATE GROUP_MARK_ID TO -7937
22636 				   IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
22637 				      --raise error
22638 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22639 				      fnd_msg_pub.ADD;
22640 				      l_progress := 'WMSINB-24475';
22641 				      RAISE fnd_api.g_exc_error;
22642 				   END IF;
22643 				 ELSE
22644 				   --raise error
22645 				   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22646 				   fnd_msg_pub.ADD;
22647 				   l_progress := 'WMSINB-24482';
22648 				   RAISE fnd_api.g_exc_error;
22649 				END IF;
22650 			     END IF; --IF (l_serial_exists = 1) THEN
22651 			     --Call EPC API here for ASN Import
22652 
22653 			     --Call EPC API here for ASN Import
22654 			     IF (l_epc_column IS NOT NULL) THEN
22655 				IF (Nvl(g_lpn_group_id,-999) <> l_lpn_grp_id) THEN
22656 				   g_lpn_group_id := l_lpn_grp_id;
22657 				   SELECT wms_epc_s2.NEXTVAL
22658 				     INTO g_epc_group_id
22659 				     FROM dual;
22660 				END IF;
22661 
22662 				IF (l_debug = 1) THEN
22663 				   print_debug('Calling populate_outside_epc',4);
22664 				   print_debug(' p_group_id       => '||g_epc_group_id,4);
22665 				   print_debug(' p_cross_ref_type => '||2,4);
22666 				   print_debug(' p_epc            => '||l_epc_value,4);
22667 				   print_debug(' p_serial_number  => '||l_serial_number,4);
22668 				END IF;
22669 
22670 				wms_epc_pvt.populate_outside_epc
22671 				  (p_group_id        => g_epc_group_id
22672 				   ,p_cross_ref_type => 2 --LPN-EPC
22673 				   ,p_serial_number  => l_serial_number
22674 				   ,p_epc            => l_epc_value
22675 				   ,x_return_status  => l_return_status
22676 				   ,x_return_mesg    => l_msg_data
22677 				   );
22678 
22679 			     END IF;--IF (l_epc_column IS NOT NULL) THEN
22680 
22681 			  END LOOP; -- FOR 1..L_SERIAL_QUANTITY
22682 		       END LOOP; --FETCH C_MSNT INTO L_MSNT_REC;
22683 
22684 		       CLOSE c_msnt;
22685 
22686 		       IF (l_num_msnt_recs > 0) THEN
22687 			  IF l_tot_msnt_serial_qty <> l_rti_primary_qty THEN
22688 			     --raise error
22689 			     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22690 			     fnd_msg_pub.ADD;
22691 			     l_progress := 'WMSINB-24496';
22692 			     RAISE fnd_api.g_exc_error;
22693 			  END IF;
22694 		       END IF;
22695 	END IF;--IF (l_lot_control_code = 2) THEN
22696      END IF;--IF (l_transaction_type = 'SHIP' AND l_source_document_code = 'PO') THEN
22697 
22698      --Validate lot/serial for returns/corrections
22699 
22700      IF (l_transaction_type IN ('CORRECT',G_RTR,G_RTV,G_RTC)) THEN
22701 	--Query the parent txn type
22702         BEGIN
22703 	   SELECT transaction_type
22704 	     , parent_transaction_id
22705 	     INTO l_parent_txn_type
22706 	     , l_grand_parent_txn_id
22707 	     FROM rcv_transactions
22708 	     WHERE transaction_id = l_parent_transaction_id;
22709 	EXCEPTION
22710 	   WHEN no_data_found THEN
22711 	      --raise an error
22712 	      l_progress := 'WMSINB-24517';
22713 	      RAISE fnd_api.g_exc_error;
22714 	END;
22715 
22716 	IF (l_debug = 1) THEN
22717 	   print_debug('VALIDATE_LOT_SERIAL_INFO: Parent Txn Type:'||l_parent_txn_type,1);
22718 	   print_debug('VALIDATE_LOT_SERIAL_INFO: Grand Parent Txn ID:'||l_grand_parent_txn_id,1);
22719 	   l_progress := 'WMSINB-24524';
22720 	END IF;
22721 
22722 	IF (l_grand_parent_txn_id > 0) THEN
22723            BEGIN
22724 	      SELECT transaction_type
22725 		, parent_transaction_id
22726 		INTO l_grand_parent_txn_type
22727 		, l_great_grand_parent_txn_id
22728 		FROM rcv_transactions
22729 		WHERE transaction_id = l_grand_parent_txn_id;
22730 	   EXCEPTION
22731 	      WHEN no_data_found THEN
22732 		 --raise an error
22733 		 l_progress := 'WMSINB-24538';
22734 		 RAISE fnd_api.g_exc_error;
22735 	   END;
22736 	END IF; --IF (l_grand_parent_txn_id > 0) THEN
22737 
22738 	IF (l_debug = 1) THEN
22739 	   print_debug('VALIDATE_LOT_SERIAL_INFO: Grand Parent Txn Type:'||l_grand_parent_txn_type,1);
22740 	   print_debug('VALIDATE_LOT_SERIAL_INFO: Great Grand Parent Txn ID:'||l_great_grand_parent_txn_id,1);
22741 	   l_progress := 'WMSINB-24546';
22742 	END IF;
22743 
22744 	IF ((l_transaction_type = 'CORRECT' AND l_rti_primary_qty < 0)
22745 	    OR l_transaction_type IN (G_RTR,G_RTV,G_RTC)) THEN
22746 	   -- opm change bug# 3061052 added l_opm_lot_ctl check.
22747        /** INVCONV, Remove OPM specific lot control check  Punit Kumar */
22748 	   IF (l_lot_control_code = 2 /* OR l_opm_lot_ctl = 1 */) THEN
22749 	      IF (l_debug = 1) THEN
22750 		 print_debug('VALIDATE_LOT_SERIAL_INFO: Lot Controlled :'||l_progress, 1);
22751 		 l_progress := 'WMSINB-24555';
22752 	      END IF;
22753 
22754 	      l_num_mtlt_recs := 0;
22755 	      l_tot_mtlt_prim_qty := 0;
22756 	      l_tot_mtlt_trans_qty := 0; -- Bug# 4225766
22757 
22758 	      OPEN C_MTLT(L_RTI_ID);
22759 
22760 	      LOOP
22761 		 FETCH C_MTLT INTO L_MTLT_REC;
22762 		 EXIT WHEN C_MTLT%NOTFOUND;
22763 
22764 
22765        /* INVCONV , get L_MTLT_REC values into l_mln_rec which shall be passed to INV_NEW_LOT
22766             for lot creation */
22767 
22768               IF (l_debug = 1) THEN
22769                  print_debug('INVCONV,Assigning values fetched from MTLT to l_mln_rec'||l_progress,1);
22770               END IF;
22771 
22772          	   l_mln_rec.LOT_NUMBER                := L_MTLT_REC.LOT_NUMBER                    ;
22773                l_mln_rec.LAST_UPDATE_DATE          := SYSDATE                                  ;
22774                l_mln_rec.LAST_UPDATED_BY           := L_MTLT_REC.LAST_UPDATED_BY               ;
22775                l_mln_rec.CREATION_DATE             := SYSDATE                                  ;
22776                l_mln_rec.CREATED_BY                := L_MTLT_REC.CREATED_BY                    ;
22777                l_mln_rec.LAST_UPDATE_LOGIN         := L_MTLT_REC.LAST_UPDATE_LOGIN             ;
22778                l_mln_rec.EXPIRATION_DATE           := L_MTLT_REC.LOT_EXPIRATION_DATE               ;
22779                l_mln_rec.ATTRIBUTE_CATEGORY        := L_MTLT_REC.ATTRIBUTE_CATEGORY            ;
22780                l_mln_rec.ATTRIBUTE1                := L_MTLT_REC.ATTRIBUTE1                    ;
22781                l_mln_rec.ATTRIBUTE2                := L_MTLT_REC.ATTRIBUTE2                    ;
22782                l_mln_rec.ATTRIBUTE3                := L_MTLT_REC.ATTRIBUTE3                    ;
22783                l_mln_rec.ATTRIBUTE4                := L_MTLT_REC.ATTRIBUTE4                    ;
22784                l_mln_rec.ATTRIBUTE5                := L_MTLT_REC.ATTRIBUTE5                    ;
22785                l_mln_rec.ATTRIBUTE6                := L_MTLT_REC.ATTRIBUTE6                    ;
22786                l_mln_rec.ATTRIBUTE7                := L_MTLT_REC.ATTRIBUTE7                    ;
22787                l_mln_rec.ATTRIBUTE8                := L_MTLT_REC.ATTRIBUTE8                    ;
22788                l_mln_rec.ATTRIBUTE9                := L_MTLT_REC.ATTRIBUTE9                    ;
22789                l_mln_rec.ATTRIBUTE10               := L_MTLT_REC.ATTRIBUTE10                   ;
22790                l_mln_rec.ATTRIBUTE11               := L_MTLT_REC.ATTRIBUTE11                   ;
22791                l_mln_rec.ATTRIBUTE12               := L_MTLT_REC.ATTRIBUTE12                   ;
22792                l_mln_rec.ATTRIBUTE13               := L_MTLT_REC.ATTRIBUTE13                   ;
22793                l_mln_rec.ATTRIBUTE14               := L_MTLT_REC.ATTRIBUTE14                   ;
22794                l_mln_rec.ATTRIBUTE15               := L_MTLT_REC.ATTRIBUTE15                   ;
22795                l_mln_rec.REQUEST_ID                := L_MTLT_REC.REQUEST_ID                    ;
22796                l_mln_rec.PROGRAM_APPLICATION_ID    := L_MTLT_REC.PROGRAM_APPLICATION_ID        ;
22797                l_mln_rec.PROGRAM_ID                := L_MTLT_REC.PROGRAM_ID                    ;
22798                l_mln_rec.PROGRAM_UPDATE_DATE       := L_MTLT_REC.PROGRAM_UPDATE_DATE           ;
22799                l_mln_rec.DESCRIPTION               := L_MTLT_REC.DESCRIPTION                   ;
22800                l_mln_rec.VENDOR_NAME               := L_MTLT_REC.VENDOR_NAME                   ;
22801                l_mln_rec.SUPPLIER_LOT_NUMBER       := L_MTLT_REC.SUPPLIER_LOT_NUMBER           ;
22802                l_mln_rec.GRADE_CODE                := L_MTLT_REC.GRADE_CODE                    ;
22803                l_mln_rec.ORIGINATION_DATE          := L_MTLT_REC.ORIGINATION_DATE              ;
22804                l_mln_rec.DATE_CODE                 := L_MTLT_REC.DATE_CODE                     ;
22805                l_mln_rec.STATUS_ID                 := L_MTLT_REC.STATUS_ID                     ;
22806                l_mln_rec.CHANGE_DATE               := L_MTLT_REC.CHANGE_DATE                   ;
22807                l_mln_rec.AGE                       := L_MTLT_REC.AGE                           ;
22808                l_mln_rec.RETEST_DATE               := L_MTLT_REC.RETEST_DATE                   ;
22809                l_mln_rec.MATURITY_DATE             := L_MTLT_REC.MATURITY_DATE                 ;
22810                l_mln_rec.LOT_ATTRIBUTE_CATEGORY    := L_MTLT_REC.LOT_ATTRIBUTE_CATEGORY        ;
22811                l_mln_rec.ITEM_SIZE                 := L_MTLT_REC.ITEM_SIZE                     ;
22812                l_mln_rec.COLOR                     := L_MTLT_REC.COLOR                         ;
22813                l_mln_rec.VOLUME                    := L_MTLT_REC.VOLUME                        ;
22814                l_mln_rec.VOLUME_UOM                := L_MTLT_REC.VOLUME_UOM                    ;
22815                l_mln_rec.PLACE_OF_ORIGIN           := L_MTLT_REC.PLACE_OF_ORIGIN               ;
22816                l_mln_rec.BEST_BY_DATE              := L_MTLT_REC.BEST_BY_DATE                  ;
22817                l_mln_rec.LENGTH                    := L_MTLT_REC.LENGTH                        ;
22818                l_mln_rec.LENGTH_UOM                := L_MTLT_REC.LENGTH_UOM                    ;
22819                l_mln_rec.RECYCLED_CONTENT          := L_MTLT_REC.RECYCLED_CONTENT              ;
22820                l_mln_rec.THICKNESS                 := L_MTLT_REC.THICKNESS                     ;
22821                l_mln_rec.THICKNESS_UOM             := L_MTLT_REC.THICKNESS_UOM                 ;
22822                l_mln_rec.WIDTH                     := L_MTLT_REC.WIDTH                         ;
22823                l_mln_rec.WIDTH_UOM                 := L_MTLT_REC.WIDTH_UOM                     ;
22824                l_mln_rec.CURL_WRINKLE_FOLD         := L_MTLT_REC.CURL_WRINKLE_FOLD             ;
22825                l_mln_rec.C_ATTRIBUTE1              := L_MTLT_REC.C_ATTRIBUTE1                  ;
22826                l_mln_rec.C_ATTRIBUTE2              := L_MTLT_REC.C_ATTRIBUTE2                  ;
22827                l_mln_rec.C_ATTRIBUTE3              := L_MTLT_REC.C_ATTRIBUTE3                  ;
22828                l_mln_rec.C_ATTRIBUTE4              := L_MTLT_REC.C_ATTRIBUTE4                  ;
22829                l_mln_rec.C_ATTRIBUTE5              := L_MTLT_REC.C_ATTRIBUTE5                  ;
22830                l_mln_rec.C_ATTRIBUTE6              := L_MTLT_REC.C_ATTRIBUTE6                  ;
22831                l_mln_rec.C_ATTRIBUTE7              := L_MTLT_REC.C_ATTRIBUTE7                  ;
22832                l_mln_rec.C_ATTRIBUTE8              := L_MTLT_REC.C_ATTRIBUTE8                  ;
22833                l_mln_rec.C_ATTRIBUTE9              := L_MTLT_REC.C_ATTRIBUTE9                  ;
22834                l_mln_rec.C_ATTRIBUTE10             := L_MTLT_REC.C_ATTRIBUTE10                 ;
22835                l_mln_rec.C_ATTRIBUTE11             := L_MTLT_REC.C_ATTRIBUTE11                 ;
22836                l_mln_rec.C_ATTRIBUTE12             := L_MTLT_REC.C_ATTRIBUTE12                 ;
22837                l_mln_rec.C_ATTRIBUTE13             := L_MTLT_REC.C_ATTRIBUTE13                 ;
22838                l_mln_rec.C_ATTRIBUTE14             := L_MTLT_REC.C_ATTRIBUTE14                 ;
22839                l_mln_rec.C_ATTRIBUTE15             := L_MTLT_REC.C_ATTRIBUTE15                 ;
22840                l_mln_rec.C_ATTRIBUTE16             := L_MTLT_REC.C_ATTRIBUTE16                 ;
22841                l_mln_rec.C_ATTRIBUTE17             := L_MTLT_REC.C_ATTRIBUTE17                 ;
22842                l_mln_rec.C_ATTRIBUTE18             := L_MTLT_REC.C_ATTRIBUTE18                 ;
22843                l_mln_rec.C_ATTRIBUTE19             := L_MTLT_REC.C_ATTRIBUTE19                 ;
22844                l_mln_rec.C_ATTRIBUTE20             := L_MTLT_REC.C_ATTRIBUTE20                 ;
22845                l_mln_rec.D_ATTRIBUTE1              := L_MTLT_REC.D_ATTRIBUTE1                  ;
22846                l_mln_rec.D_ATTRIBUTE2              := L_MTLT_REC.D_ATTRIBUTE2                  ;
22847                l_mln_rec.D_ATTRIBUTE3              := L_MTLT_REC.D_ATTRIBUTE3                  ;
22848                l_mln_rec.D_ATTRIBUTE4              := L_MTLT_REC.D_ATTRIBUTE4                  ;
22849                l_mln_rec.D_ATTRIBUTE5              := L_MTLT_REC.D_ATTRIBUTE5                  ;
22850                l_mln_rec.D_ATTRIBUTE6              := L_MTLT_REC.D_ATTRIBUTE6                  ;
22851                l_mln_rec.D_ATTRIBUTE7              := L_MTLT_REC.D_ATTRIBUTE7                  ;
22852                l_mln_rec.D_ATTRIBUTE8              := L_MTLT_REC.D_ATTRIBUTE8                  ;
22853                l_mln_rec.D_ATTRIBUTE9              := L_MTLT_REC.D_ATTRIBUTE9                  ;
22854                l_mln_rec.D_ATTRIBUTE10             := L_MTLT_REC.D_ATTRIBUTE10                 ;
22855                l_mln_rec.N_ATTRIBUTE1              := L_MTLT_REC.N_ATTRIBUTE1                  ;
22856                l_mln_rec.N_ATTRIBUTE2              := L_MTLT_REC.N_ATTRIBUTE2                  ;
22857                l_mln_rec.N_ATTRIBUTE3              := L_MTLT_REC.N_ATTRIBUTE3                  ;
22858                l_mln_rec.N_ATTRIBUTE4              := L_MTLT_REC.N_ATTRIBUTE4                  ;
22859                l_mln_rec.N_ATTRIBUTE5              := L_MTLT_REC.N_ATTRIBUTE5                  ;
22860                l_mln_rec.N_ATTRIBUTE6              := L_MTLT_REC.N_ATTRIBUTE6                  ;
22861                l_mln_rec.N_ATTRIBUTE7              := L_MTLT_REC.N_ATTRIBUTE7                  ;
22862                l_mln_rec.N_ATTRIBUTE8              := L_MTLT_REC.N_ATTRIBUTE8                  ;
22863                l_mln_rec.N_ATTRIBUTE9              := L_MTLT_REC.N_ATTRIBUTE9                  ;
22864                l_mln_rec.N_ATTRIBUTE10             := L_MTLT_REC.N_ATTRIBUTE10                 ;
22865                l_mln_rec.VENDOR_ID                 := L_MTLT_REC.VENDOR_ID                     ;
22866                l_mln_rec.TERRITORY_CODE            := L_MTLT_REC.TERRITORY_CODE                ;
22867                l_mln_rec.PARENT_LOT_NUMBER         := L_MTLT_REC.PARENT_LOT_NUMBER             ;
22868                l_mln_rec.ORIGINATION_TYPE          := L_MTLT_REC.ORIGINATION_TYPE              ;
22869                l_mln_rec.EXPIRATION_ACTION_DATE    := L_MTLT_REC.EXPIRATION_ACTION_DATE        ;
22870                l_mln_rec.EXPIRATION_ACTION_CODE    := L_MTLT_REC.EXPIRATION_ACTION_CODE        ;
22871                l_mln_rec.HOLD_DATE                 := L_MTLT_REC.HOLD_DATE                     ;
22872 
22873          /*end , INVCONV*/
22874 
22875 
22876 
22877 		 L_NUM_MTLT_RECS := L_NUM_MTLT_RECS + 1;
22878 		 l_tot_mtlt_prim_qty := l_tot_mtlt_prim_qty + l_mtlt_rec.primary_quantity;
22879 		 l_tot_mtlt_trans_qty := l_tot_mtlt_trans_qty + l_mtlt_rec.transaction_quantity; -- Bug# 4225766
22880 
22881 		 IF (l_debug = 1) THEN
22882 		    print_debug('VALIDATE_LOT_SERIAL_INFO: LOT NUMBER: '||l_mtlt_rec.lot_number||': '||l_progress, 1);
22883 		    print_debug('VALIDATE_LOT_SERIAL_INFO: LOT PRIMARY QUANTITY: '||l_mtlt_rec.primary_quantity||': '||l_progress, 1);
22884 		    l_progress := 'WMSINB-24573';
22885           print_debug('INVCONV,Finished Assigning values fetched from MTLT to l_mln_rec'||l_progress,1);
22886 		 END IF;
22887 
22888 		 IF (l_parent_txn_type IN (g_rtv,g_rtr,g_rtc)) THEN
22889 		    IF (l_grand_parent_txn_type <> 'DELIVER') THEN
22890 		       IF NOT (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
22891 			  --raise an error
22892 			  l_progress := 'WMSINB-24580';
22893 			  RAISE fnd_api.g_exc_error;
22894 		       END IF; --IF NOT (lot_entered_on_parent(l_grand_parent_txn_id))
22895 		    END IF; --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
22896 		  ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtr,g_rtc)) THEN
22897 		    IF (l_parent_txn_type <> 'DELIVER') THEN
22898 		       IF NOT (lot_entered_on_parent(l_parent_transaction_id)) THEN
22899 			  --raise an error
22900 			  l_progress := 'WMSINB-24588';
22901 			  RAISE fnd_api.g_exc_error;
22902 		       END IF;
22903 		    END IF; --IF (l_parent_txn_type <> 'DELIVER') THEN
22904 		 END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtr,g_rtc)) THEN
22905 
22906        /*INVCONV , removed OPM specific fork , Punit Kumar*/
22907 
22908 	         BEGIN
22909 		    ----IF (l_discrete_transaction) THEN
22910                SELECT 1,parent_lot_number
22911                   INTO L_LOT_EXISTS ,l_parent_lot_number
22912                   FROM MTL_LOT_NUMBERS
22913                   WHERE ORGANIZATION_ID = L_ORG_ID
22914                   AND   INVENTORY_ITEM_ID = L_ITEM_ID
22915                   AND LOT_NUMBER = Ltrim(Rtrim(L_MTLT_REC.lot_number));
22916 
22917          /*
22918 		     ELSE -- opm change bug# 3061052 --IF (l_discrete_transaction) THEN
22919 		       IF  Ltrim(Rtrim(L_MTLT_REC.sublot_num)) IS NOT NULL THEN
22920 			  SELECT 1, LOT_ID
22921 			    INTO L_LOT_EXISTS , l_opm_lot_id
22922 			    FROM IC_LOTS_MST
22923 			    WHERE ITEM_ID = l_opm_item_id
22924 			    AND LOT_NO = Ltrim(Rtrim(L_MTLT_REC.lot_number))
22925 			    AND SUBLOT_NO = Ltrim(Rtrim(L_MTLT_REC.sublot_num)) ;
22926 			ELSE
22927 			  SELECT 1, LOT_ID
22928 			    INTO L_LOT_EXISTS , l_opm_lot_id
22929 			    FROM IC_LOTS_MST
22930 			    WHERE ITEM_ID = l_opm_item_id
22931 			    AND LOT_NO = Ltrim(Rtrim(L_MTLT_REC.lot_number))
22932 			    AND SUBLOT_NO IS NULL ;
22933 		       END IF;
22934 		    END IF; --IF (l_discrete_transaction) THEN
22935 		  */
22936 
22937          /*INVCONV ,*/
22938          IF (l_debug = 1) THEN
22939             print_debug('INVCONV, Removing OPM specific fork :'||l_progress,1);
22940          END IF;
22941 
22942 		 EXCEPTION
22943 		    WHEN NO_DATA_FOUND THEN
22944 		       L_LOT_EXISTS := 0;
22945 		 END;
22946 
22947 		 IF (l_lot_exists = 1) THEN
22948 
22949            /*INVCONV , validating for parent lot, Punit Kumar */
22950             IF  L_MTLT_REC.parent_lot_number IS NOT NULL THEN
22951                IF L_MTLT_REC.parent_lot_number <> l_parent_lot_number THEN
22952                   fnd_message.set_name ('INV' , 'INV_CL_PARENT_INVALID' );
22953 					   fnd_msg_pub.ADD;
22954                   RAISE fnd_api.g_exc_error;
22955                END IF;
22956             ELSE
22957                L_MTLT_REC.parent_lot_number := l_parent_lot_number;
22958             END IF;
22959             /*end , INVCONV */
22960 
22961 
22962 		    IF (l_parent_txn_type IN (g_rtv, g_rtc)) THEN
22963 		       IF (l_grand_parent_txn_type = 'DELIVER') THEN
22964 
22965           /*INVCONV , remove OPM specific fork, Punit Kumar */
22966            /*IF (l_discrete_transaction) THEN	 */
22967 
22968            /*end , INVCONV */
22969              --PERFORM LOT MATERIAL STATUS CHECK
22970 			     IF (l_transaction_type = g_rtv) THEN
22971 				l_transaction_type_id := 36;
22972 			      ELSIF (l_transaction_type = g_rtc) THEN
22973 				l_transaction_type_id := 37;
22974 			      ELSIF (l_transaction_type = g_rtr) THEN
22975 				IF (l_source_document_code = 'PO') THEN
22976 				   l_transaction_type_id := 36;
22977 				 ELSE
22978 				   l_transaction_type_id := 37; --For RMA
22979 				END IF;
22980 			      ELSE
22981 				IF (l_source_document_code = 'PO') THEN
22982 				   l_transaction_type_id := 71;
22983 				 ELSE
22984 				   l_transaction_type_id := 72;
22985 				END IF;
22986 			     END IF;
22987 
22988 			     INV_LOT_TRX_VALIDATION_PUB.VALIDATE_MATERIAL_STATUS(X_RETURN_STATUS => X_RETURN_STATUS,
22989 										 X_MSG_COUNT => X_MSG_COUNT,
22990 										 X_MSG_DATA => X_MSG_DATA,
22991 										 X_VALIDATION_STATUS => L_VALIDATION_STATUS,
22992 										 P_TRANSACTION_TYPE_ID => l_transaction_type_id,
22993 										 P_ORGANIZATION_ID => L_ORG_ID,
22994 										 P_INVENTORY_ITEM_ID => L_ITEM_ID,
22995 										 P_LOT_NUMBER => L_MTLT_REC.LOT_NUMBER,
22996 										 P_SUBINVENTORY_CODE => L_SUB_CODE,
22997 										 P_LOCATOR_ID => L_LOC_ID,
22998 										 P_STATUS_ID => NULL);
22999 			     IF X_RETURN_STATUS <> 'S' THEN
23000 				--RAISE ERROR
23001 	   			l_progress     := 'WMSINB-24661';
23002 				RAISE fnd_api.g_exc_error;
23003 			     END IF;
23004 
23005 			     IF (l_debug = 1) THEN
23006 				print_debug('VALIDATE_LOT_SERIAL_INFO: LOT MATERIAL VALIDATION STATUS: '||L_VALIDATION_STATUS||' : '||l_progress, 1);
23007 				l_progress := 'WMSINB-24667';
23008 			     END IF;
23009 
23010 			     IF L_VALIDATION_STATUS <> 'Y' THEN
23011 				--RAISE ERROR
23012 				l_progress     := 'WMSINB-24672';
23013 				RAISE fnd_api.g_exc_error;
23014 			     END IF;
23015             /*
23016 			   ELSE --IF (l_discrete_transaction) THEN
23017 			     -- opm change bug# 3061052
23018 			     gml_opm_roi_grp.validate_opm_lot(p_api_version	 	=> 1.0,
23019 							      p_init_msg_lst	 	=> FND_API.G_FALSE,
23020 							      p_mtlt_rowid		=> l_mtlt_rec.rowid,
23021 							      p_new_lot	 	=> 'N',
23022 							      p_opm_item_id		=> l_opm_item_id,
23023 							      p_item_no		=> l_item_no,
23024 							      p_lots_specified_on_parent => 'Y',
23025 							      p_lot_id		=> l_opm_lot_id,
23026 							      p_parent_txn_type	=> l_parent_txn_type,
23027 							      p_grand_parent_txn_type => l_grand_parent_txn_type,
23028 							      x_return_status 	=> x_return_status,
23029 							      x_msg_data      	=> x_msg_data,
23030 							      x_msg_count     	=> x_msg_count
23031 							      );
23032 
23033             */
23034               /*INVCONV ,*/
23035                IF (l_debug = 1) THEN
23036                  print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
23037               END IF;
23038 
23039               INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
23040                                                        x_return_status      		   => x_return_status
23041                                                       ,x_msg_data           		   => x_msg_data
23042                                                       ,x_msg_count          		   => x_msg_count
23043                                                       ,p_api_version	               => 1.0
23044                                                       ,p_init_msg_lst	            => FND_API.G_FALSE
23045                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
23046                                                       ,p_transaction_type_id 	      => l_transaction_type_id
23047                                                       ,p_new_lot			            => 'N'
23048                                                       ,p_item_id	 		            => l_item_id
23049                                                       ,p_to_organization_id		   => L_ORG_ID
23050                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
23051                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
23052                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
23053                                                       ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
23054                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
23055                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
23056                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
23057                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
23058                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
23059                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
23060                                                       ,p_rti_id	                  => L_RTI_ID
23061                                                       ,p_revision             	   => l_item_revision
23062                                                       ,p_subinventory_code  	      => L_SUB_CODE
23063                                                       ,p_locator_id           	   => l_loc_id
23064                                                       ,p_transaction_type           => l_transaction_type
23065                                                       ,p_parent_txn_type            => l_parent_txn_type
23066                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
23067                                                       );
23068 
23069                /*INVCONV ,*/
23070               IF (l_debug = 1) THEN
23071                  print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
23072                  print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
23073               END IF;
23074 
23075 			     IF X_RETURN_STATUS <> 'S' THEN
23076 				--RAISE ERROR
23077 				l_progress := 'WMSINB-24693';
23078 				RAISE fnd_api.g_exc_error;
23079 			     END IF;
23080 
23081 			     IF (l_debug = 1) THEN
23082 				print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
23083 			     END IF;
23084 			  /*END IF; --IF (l_discrete_transaction) THEN*/
23085 			ELSE --IF (l_grand_parent_txn_type = 'DELIVER') THEN
23086 			  IF (validate_rs(NULL,l_grand_parent_txn_id,l_dummy_lpn)) THEN
23087 			     IF NOT (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
23088 				--raise error
23089 				l_progress := 'WMSINB-24705';
23090 				RAISE fnd_api.g_exc_error;
23091 			     END IF;
23092 			  END IF;
23093 
23094 			   /*INVCONV , remove OPM specific fork, Punit Kumar */
23095 			  /*IF (NOT l_discrete_transaction) THEN
23096 
23097 			     -- opm change bug# 3061052
23098 			     gml_opm_roi_grp.validate_opm_lot(p_api_version	 	=> 1.0,
23099 							      p_init_msg_lst	 	=> FND_API.G_FALSE,
23100 							      p_mtlt_rowid		=> l_mtlt_rec.rowid,
23101 							      p_new_lot	 	=> 'N',
23102 							      p_opm_item_id		=> l_opm_item_id,
23103 							      p_item_no		=> l_item_no,
23104 							      p_lots_specified_on_parent => 'Y',
23105 							      p_lot_id		=> l_opm_lot_id,
23106 							      p_parent_txn_type	=> l_parent_txn_type,
23107 							      p_grand_parent_txn_type => l_grand_parent_txn_type,
23108 							      x_return_status 	=> x_return_status,
23109 							      x_msg_data      	=> x_msg_data,
23110 							      x_msg_count     	=> x_msg_count
23111 							      );
23112 
23113             */
23114 
23115                /*INVCONV ,*/
23116               IF (l_debug = 1) THEN
23117                  print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
23118               END IF;
23119 
23120                INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
23121                                                        x_return_status      		   => x_return_status
23122                                                       ,x_msg_data           		   => x_msg_data
23123                                                       ,x_msg_count          		   => x_msg_count
23124                                                       ,p_api_version	               => 1.0
23125                                                       ,p_init_msg_lst	            => FND_API.G_FALSE
23126                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
23127                                                       ,p_transaction_type_id 	      => l_transaction_type_id
23128                                                       ,p_new_lot			            => 'N'
23129                                                       ,p_item_id	 		            => l_item_id
23130                                                       ,p_to_organization_id		   => L_ORG_ID
23131                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
23132                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
23133                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
23134                                                       ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
23135                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
23136                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
23137                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
23138                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
23139                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
23140                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
23141                                                       ,p_rti_id	                  => L_RTI_ID
23142                                                       ,p_revision             	   => l_item_revision
23143                                                       ,p_subinventory_code  	      => L_SUB_CODE
23144                                                       ,p_locator_id           	   => l_loc_id
23145                                                       ,p_transaction_type           => l_transaction_type
23146                                                       ,p_parent_txn_type            => l_parent_txn_type
23147                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
23148                                                       );
23149 
23150                 /*INVCONV ,*/
23151                IF (l_debug = 1) THEN
23152                   print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
23153                   print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
23154                END IF;
23155 
23156 			     IF X_RETURN_STATUS <> 'S' THEN
23157 				--RAISE ERROR
23158 				l_progress := 'WMSINB-24728';
23159 				RAISE fnd_api.g_exc_error;
23160 			     END IF;
23161 
23162 			     IF (l_debug = 1) THEN
23163 				print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
23164 			     END IF;
23165 			  /*END IF; --IF (NOT l_discrete_transaction) THEN*/
23166 
23167 		       END IF; --IF (l_grand_parent_txn_type = 'DELIVER') THEN
23168 		     ELSIF (l_parent_txn_type = g_rtr) THEN --IF (l_parent_txn_type IN (g_rtv, g_rtc)) THEN
23169 		       IF (lot_entered_on_parent(l_great_grand_parent_txn_id)) THEN
23170 		          BEGIN
23171 
23172               /*INVCONV, Remove the sublot no check in SQL, Punit Kumar */
23173 
23174 			     SELECT primary_quantity
23175 			       INTO l_rls_primary_quantity
23176 			       FROM rcv_lots_supply
23177 			       WHERE transaction_id = l_great_grand_parent_txn_id
23178 			       AND lot_num = Ltrim(Rtrim(l_mtlt_rec.lot_number)) ;
23179 
23180               /*
23181 			       AND ((sublot_num IS NULL and Ltrim(Rtrim(l_mtlt_rec.sublot_num)) IS NULL)
23182 				    OR (sublot_num = Ltrim(Rtrim(l_mtlt_rec.sublot_num)))) ;
23183                */
23184 
23185 			       IF (l_mtlt_rec.primary_quantity > l_rls_primary_quantity) THEN
23186 				  --raise error
23187 				  l_progress := 'WMSINB-24752';
23188 				  RAISE fnd_api.g_exc_error;
23189 			       END IF;
23190 			  EXCEPTION
23191 			     WHEN no_data_found THEN
23192 				--raise error
23193 				l_progress := 'WMSINB-24758';
23194 				RAISE fnd_api.g_exc_error;
23195 			  END;
23196 		       END IF; --IF (lot_entered_on_parent(l_great_grand_parent_txn_id)) THEN
23197 
23198              /*INVCONV , existing discrete validations. Same will be executed for
23199                process org, Punit Kumar */
23200 
23201 		      /*IF (l_discrete_transaction) THEN*/
23202 
23203              --PERFORM MATERIAL STATUS CHECK FOR LOT
23204 			  IF (l_transaction_type = g_rtv) THEN
23205 			     l_transaction_type_id := 36;
23206 			   ELSIF (l_transaction_type = g_rtc) THEN
23207 			     l_transaction_type_id := 37;
23208 			   ELSIF (l_transaction_type = g_rtr) THEN
23209 			     IF (l_source_document_code = 'PO') THEN
23210 				l_transaction_type_id := 36;
23211 			      ELSE
23212 				l_transaction_type_id := 37; --For RMA
23213 			     END IF;
23214 			   ELSE
23215 			     IF (l_source_document_code = 'PO') THEN
23216 				l_transaction_type_id := 71;
23217 			      ELSE
23218 				l_transaction_type_id := 72;
23219 			     END IF;
23220 			  END IF;
23221 
23222 			  INV_LOT_TRX_VALIDATION_PUB.VALIDATE_MATERIAL_STATUS(X_RETURN_STATUS => X_RETURN_STATUS,
23223 									      X_MSG_COUNT => X_MSG_COUNT,
23224 									      X_MSG_DATA => X_MSG_DATA,
23225 									      X_VALIDATION_STATUS => L_VALIDATION_STATUS,
23226 									      P_TRANSACTION_TYPE_ID => l_transaction_type_id,
23227 									      P_ORGANIZATION_ID => L_ORG_ID,
23228 									      P_INVENTORY_ITEM_ID => L_ITEM_ID,
23229 									      P_LOT_NUMBER => L_MTLT_REC.LOT_NUMBER,
23230 									      P_SUBINVENTORY_CODE => L_SUB_CODE,
23231 									      P_LOCATOR_ID => L_LOC_ID,
23232 									      P_STATUS_ID => NULL);
23233 			  IF X_RETURN_STATUS <> 'S' THEN
23234 			     --RAISE ERROR
23235 			     l_progress := 'WMSINB-24796';
23236 			     RAISE fnd_api.g_exc_error;
23237 			  END IF;
23238 
23239 			  IF (l_debug = 1) THEN
23240 			     print_debug('VALIDATE_LOT_SERIAL_INFO: LOT MATERIAL VALIDATION STATUS: '||L_VALIDATION_STATUS||' : '||l_progress, 1);
23241 			     l_progress := 'WMSINB-24802';
23242 			  END IF;
23243 
23244 			  IF L_VALIDATION_STATUS <> 'Y' THEN
23245 			     --RAISE ERROR
23246 			     l_progress := 'WMSINB-24807';
23247 			     RAISE fnd_api.g_exc_error;
23248 			  END IF;
23249 
23250 
23251          /*
23252 			ELSE --IF (l_discrete_transaction) THEN
23253 			  -- opm change bug# 3061052
23254 			  gml_opm_roi_grp.validate_opm_lot(p_api_version	 	=> 1.0,
23255 							   p_init_msg_lst	 	=> FND_API.G_FALSE,
23256 							   p_mtlt_rowid		=> l_mtlt_rec.rowid,
23257 							   p_new_lot	 	=> 'N',
23258 							   p_opm_item_id		=> l_opm_item_id,
23259 							   p_item_no		=> l_item_no,
23260 							   p_lots_specified_on_parent => 'Y',
23261 							   p_lot_id		=> l_opm_lot_id,
23262 							   p_parent_txn_type	=> l_parent_txn_type,
23263 							   p_grand_parent_txn_type => l_grand_parent_txn_type,
23264 							   x_return_status 	=> x_return_status,
23265 							   x_msg_data      	=> x_msg_data,
23266 							   x_msg_count     	=> x_msg_count
23267 							   );
23268 
23269           */
23270 
23271            /*INVCONV ,*/
23272               IF (l_debug = 1) THEN
23273                  print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
23274               END IF;
23275 
23276 
23277            INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
23278                                                        x_return_status      		   => x_return_status
23279                                                       ,x_msg_data           		   => x_msg_data
23280                                                       ,x_msg_count          		   => x_msg_count
23281                                                       ,p_api_version	               => 1.0
23282                                                       ,p_init_msg_lst	            => FND_API.G_FALSE
23283                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
23284                                                       ,p_transaction_type_id 	      => l_transaction_type_id
23285                                                       ,p_new_lot			            => 'N'
23286                                                       ,p_item_id	 		            => l_item_id
23287                                                       ,p_to_organization_id		   => L_ORG_ID
23288                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
23289                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
23290                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
23291                                                       ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
23292                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
23293                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
23294                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
23295                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
23296                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
23297                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
23298                                                       ,p_rti_id	                  => L_RTI_ID
23299                                                       ,p_revision             	   => l_item_revision
23300                                                       ,p_subinventory_code  	      => L_SUB_CODE
23301                                                       ,p_locator_id           	   => l_loc_id
23302                                                       ,p_transaction_type           => l_transaction_type
23303                                                       ,p_parent_txn_type            => l_parent_txn_type
23304                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
23305                                                       );
23306 
23307             /*INVCONV ,*/
23308           IF (l_debug = 1) THEN
23309              print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
23310              print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
23311           END IF;
23312 
23313 			  IF X_RETURN_STATUS <> 'S' THEN
23314 			     --RAISE ERROR
23315 			     l_progress := 'WMSINB-24828';
23316 			     RAISE fnd_api.g_exc_error;
23317 			  END IF;
23318 
23319 			  IF (l_debug = 1) THEN
23320 			     print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
23321 			  END IF;
23322 		       /*END IF;  --IF (l_discrete_transaction) THEN*/
23323 
23324 		     ELSE --	ELSIF (l_parent_txn_type = g_rtr)
23325 			  IF l_parent_txn_type <> 'DELIVER' THEN
23326 			     BEGIN
23327 
23328 				/* INVCONV , Remove Sublot Num from SQL , Punit Kumar*/
23329 
23330 				SELECT primary_quantity
23331 				  INTO l_rls_primary_quantity
23332 				  FROM rcv_lots_supply
23333 				  WHERE transaction_id = l_parent_transaction_id
23334 				  AND lot_num = Ltrim(Rtrim(l_mtlt_rec.lot_number));
23335 
23336             /*
23337 				  AND ((sublot_num IS NULL and Ltrim(Rtrim(l_mtlt_rec.sublot_num)) IS NULL)
23338 				       OR (sublot_num = Ltrim(Rtrim(l_mtlt_rec.sublot_num)))) ;
23339             */
23340 
23341 
23342 				  IF (l_mtlt_rec.primary_quantity > l_rls_primary_quantity) THEN
23343 				     --raise error
23344 				     l_progress := 'WMSINB-24851';
23345 				     RAISE fnd_api.g_exc_error;
23346 				  END IF;
23347 			     EXCEPTION
23348 				WHEN no_data_found THEN
23349 				   --raise error
23350 				   l_progress := 'WMSINB-24857';
23351 				   RAISE fnd_api.g_exc_error;
23352 			     END;
23353 
23354 			    /*INVCONV*/
23355 			   /*  IF (NOT l_discrete_transaction) THEN
23356 				-- opm change bug# 3061052.
23357 				gml_opm_roi_grp.validate_opm_lot(p_api_version	=> 1.0,
23358 								 p_init_msg_lst	 	=> FND_API.G_FALSE,
23359 								 p_mtlt_rowid		=> l_mtlt_rec.rowid,
23360 								 p_new_lot	 	=> 'N',
23361 								 p_opm_item_id		=> l_opm_item_id,
23362 								 p_item_no		=> l_item_no,
23363 								 p_lots_specified_on_parent => 'Y',
23364 								 p_lot_id		=> l_opm_lot_id,
23365 								 p_parent_txn_type	=> l_parent_txn_type,
23366 								 p_grand_parent_txn_type => l_grand_parent_txn_type,
23367 								 x_return_status 	=> x_return_status,
23368 								 x_msg_data      	=> x_msg_data,
23369 								 x_msg_count     	=> x_msg_count
23370 								 );
23371 
23372              */
23373                /*INVCONV ,*/
23374               IF (l_debug = 1) THEN
23375                  print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
23376               END IF;
23377 
23378 
23379               INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
23380                                                           x_return_status      		   => x_return_status
23381                                                          ,x_msg_data           		   => x_msg_data
23382                                                          ,x_msg_count          		   => x_msg_count
23383                                                          ,p_api_version	               => 1.0
23384                                                          ,p_init_msg_lst	            => FND_API.G_FALSE
23385                                                          ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
23386                                                          ,p_transaction_type_id 	      => l_transaction_type_id
23387                                                          ,p_new_lot			            => 'N'
23388                                                          ,p_item_id	 		            => l_item_id
23389                                                          ,p_to_organization_id		   => L_ORG_ID
23390                                                          ,p_lot_number			         => L_MTLT_REC.lot_number
23391                                                          ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
23392                                                          ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
23393                                                          ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
23394                                                          ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
23395                                                          ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
23396                                                          ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
23397                                                          ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
23398                                                          ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
23399                                                          ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
23400                                                          ,p_rti_id	                  => L_RTI_ID
23401                                                          ,p_revision             	   => l_item_revision
23402                                                          ,p_subinventory_code  	      => L_SUB_CODE
23403                                                          ,p_locator_id           	   => l_loc_id
23404                                                          ,p_transaction_type           => l_transaction_type
23405                                                          ,p_parent_txn_type            => l_parent_txn_type
23406                                                          ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
23407                                                          );
23408 
23409                /*INVCONV ,*/
23410               IF (l_debug = 1) THEN
23411                  print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
23412                  print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
23413               END IF;
23414 
23415             IF X_RETURN_STATUS <> 'S' THEN
23416 				   --RAISE ERROR
23417 				   l_progress := 'WMSINB-24880';
23418 				   RAISE fnd_api.g_exc_error;
23419 				END IF;
23420 
23421 				IF (l_debug = 1) THEN
23422 				   print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
23423 				END IF;
23424 			     /*END IF; --IF (NOT l_discrete_transaction) THEN*/
23425             /*end , INVCONV*/
23426 			   ELSE --IF l_parent_txn_type <> 'DELIVER' THEN
23427 
23428                /*INVCONV , Remove OPM specific fork, Punit Kumar*/
23429 
23430 				   /*IF (l_discrete_transaction) THEN		 */
23431                /*end , INVCONV*/
23432 
23433                --PERFORM MATERIAL STATUS CHECK FOR LOT
23434 				      IF (l_transaction_type = g_rtv) THEN
23435 					 l_transaction_type_id := 36;
23436 				       ELSIF (l_transaction_type = g_rtc) THEN
23437 					 l_transaction_type_id := 37;
23438 				       ELSIF (l_transaction_type = g_rtr) THEN
23439 					 IF (l_source_document_code = 'PO') THEN
23440 					    l_transaction_type_id := 36;
23441 					  ELSE
23442 					    l_transaction_type_id := 37; --For RMA
23443 					 END IF;
23444 				       ELSE
23445 					 IF (l_source_document_code = 'PO') THEN
23446 					    l_transaction_type_id := 71;
23447 					  ELSE
23448 					    l_transaction_type_id := 72;
23449 					 END IF;
23450 				      END IF;
23451 
23452 				      INV_LOT_TRX_VALIDATION_PUB.VALIDATE_MATERIAL_STATUS(X_RETURN_STATUS => X_RETURN_STATUS,
23453 											  X_MSG_COUNT => X_MSG_COUNT,
23454 											  X_MSG_DATA => X_MSG_DATA,
23455 											  X_VALIDATION_STATUS => L_VALIDATION_STATUS,
23456 											  P_TRANSACTION_TYPE_ID => l_transaction_type_id,
23457 											  P_ORGANIZATION_ID => L_ORG_ID,
23458 											  P_INVENTORY_ITEM_ID => L_ITEM_ID,
23459 											  P_LOT_NUMBER => L_MTLT_REC.LOT_NUMBER,
23460 											  P_SUBINVENTORY_CODE => L_SUB_CODE,
23461 											  P_LOCATOR_ID => L_LOC_ID,
23462 											  P_STATUS_ID => NULL);
23463 				      IF X_RETURN_STATUS <> 'S' THEN
23464 					 --RAISE ERROR
23465 					 l_progress := 'WMSINB-24922';
23466 					 RAISE fnd_api.g_exc_error;
23467 				      END IF;
23468 
23469 				      IF (l_debug = 1) THEN
23470 					 print_debug('VALIDATE_LOT_SERIAL_INFO: LOT MATERIAL VALIDATION STATUS: '||L_VALIDATION_STATUS||' : '||l_progress, 1);
23471 					 l_progress := 'WMSINB-24928';
23472 				      END IF;
23473 
23474 				      IF L_VALIDATION_STATUS <> 'Y' THEN
23475 					 --RAISE ERROR
23476 					 l_progress := 'WMSINB-24933';
23477 					 RAISE fnd_api.g_exc_error;
23478 				      END IF;
23479 
23480               /*
23481 				    ELSE --IF (l_discrete_transaction) THEN
23482 				      -- opm change bug# 3061052
23483 				      gml_opm_roi_grp.validate_opm_lot(p_api_version	=> 1.0,
23484 								       p_init_msg_lst	 	=> FND_API.G_FALSE,
23485 								       p_mtlt_rowid		=> l_mtlt_rec.rowid,
23486 								       p_new_lot	 	=> 'N',
23487 								       p_opm_item_id		=> l_opm_item_id,
23488 								       p_item_no		=> l_item_no,
23489 								       p_lots_specified_on_parent => 'Y',
23490 								       p_lot_id		=> l_opm_lot_id,
23491 								       p_parent_txn_type	=> l_parent_txn_type,
23492 								       p_grand_parent_txn_type => l_grand_parent_txn_type,
23493 								       x_return_status 	=> x_return_status,
23494 								       x_msg_data      	=> x_msg_data,
23495 								       x_msg_count     	=> x_msg_count
23496 								       );
23497 
23498                */
23499                    /*INVCONV ,*/
23500               IF (l_debug = 1) THEN
23501                  print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
23502               END IF;
23503 
23504 
23505                   INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
23506                                                           x_return_status      		   => x_return_status
23507                                                          ,x_msg_data           		   => x_msg_data
23508                                                          ,x_msg_count          		   => x_msg_count
23509                                                          ,p_api_version	               => 1.0
23510                                                          ,p_init_msg_lst	            => FND_API.G_FALSE
23511                                                          ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
23512                                                          ,p_transaction_type_id 	      => l_transaction_type_id
23513                                                          ,p_new_lot			            => 'N'
23514                                                          ,p_item_id	 		            => l_item_id
23515                                                          ,p_to_organization_id		   => L_ORG_ID
23516                                                          ,p_lot_number			         => L_MTLT_REC.lot_number
23517                                                          ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
23518                                                          ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
23519                                                          ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
23520                                                          ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
23521                                                          ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
23522                                                          ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
23523                                                          ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
23524                                                          ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
23525                                                          ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
23526                                                          ,p_rti_id	                  => L_RTI_ID
23527                                                          ,p_revision             	   => l_item_revision
23528                                                          ,p_subinventory_code  	      => L_SUB_CODE
23529                                                          ,p_locator_id           	   => l_loc_id
23530                                                          ,p_transaction_type           => l_transaction_type
23531                                                          ,p_parent_txn_type            => l_parent_txn_type
23532                                                          ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
23533                                                          );
23534 
23535                   /*INVCONV ,*/
23536                   IF (l_debug = 1) THEN
23537                      print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
23538                      print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
23539                   END IF;
23540 
23541                   IF X_RETURN_STATUS <> 'S' THEN
23542                      --RAISE ERROR
23543                      l_progress := 'WMSINB-24955';
23544                      RAISE fnd_api.g_exc_error;
23545                   END IF;
23546 
23547 				      IF (l_debug = 1) THEN
23548 					 print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
23549 				      END IF;
23550 				   /*END IF; -- IF (l_discrete_transaction) THEN*/
23551 			  END IF; --IF l_parent_txn_type <> 'DELIVER' THEN
23552 		    END IF; --IF (l_parent_txn_type IN (g_rtv, g_rtc)) THEN
23553 		  ELSE --IF (l_lot_exists = 1) THEN
23554 			  IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
23555 			     IF (l_grand_parent_txn_type = 'DELIVER') THEN
23556 				-- opm change bug# 3061052
23557 
23558            /* INVCONV, replace the existing create_inv_lot call with a new call */
23559            /*
23560 				IF (l_discrete_transaction) THEN
23561 				   --CALL CREATE_INV_LOT
23562 				   --FOR l_inv_att_index IN 1..15 LOOP
23563 				   -- l_inv_attributes_tbl(l_inv_att_index) := NULL;
23564 				   --END LOOP;
23565 
23566 				   l_c_attributes_tbl(1)  := l_mtlt_rec.c_attribute1;
23567 				   l_c_attributes_tbl(2)  := l_mtlt_rec.c_attribute2;
23568 				   l_c_attributes_tbl(3)  := l_mtlt_rec.c_attribute3;
23569 				   l_c_attributes_tbl(4)  := l_mtlt_rec.c_attribute4;
23570 				   l_c_attributes_tbl(5)  := l_mtlt_rec.c_attribute5;
23571 				   l_c_attributes_tbl(6)  := l_mtlt_rec.c_attribute6;
23572 				   l_c_attributes_tbl(7)  := l_mtlt_rec.c_attribute7;
23573 				   l_c_attributes_tbl(8)  := l_mtlt_rec.c_attribute8;
23574 				   l_c_attributes_tbl(9)  := l_mtlt_rec.c_attribute9;
23575 				   l_c_attributes_tbl(10) := l_mtlt_rec.c_attribute10;
23576 				   l_c_attributes_tbl(11) := l_mtlt_rec.c_attribute11;
23577 				   l_c_attributes_tbl(12) := l_mtlt_rec.c_attribute12;
23578 				   l_c_attributes_tbl(13) := l_mtlt_rec.c_attribute13;
23579 				   l_c_attributes_tbl(14) := l_mtlt_rec.c_attribute14;
23580 				   l_c_attributes_tbl(15) := l_mtlt_rec.c_attribute15;
23581 				   l_c_attributes_tbl(16) := l_mtlt_rec.c_attribute16;
23582 				   l_c_attributes_tbl(17) := l_mtlt_rec.c_attribute17;
23583 				   l_c_attributes_tbl(18) := l_mtlt_rec.c_attribute18;
23584 				   l_c_attributes_tbl(19) := l_mtlt_rec.c_attribute19;
23585 				   l_c_attributes_tbl(20) := l_mtlt_rec.c_attribute20;
23586 				   l_d_attributes_tbl(1)  := l_mtlt_rec.d_attribute1;
23587 				   l_d_attributes_tbl(2)  := l_mtlt_rec.d_attribute2;
23588 				   l_d_attributes_tbl(3)  := l_mtlt_rec.d_attribute3;
23589 				   l_d_attributes_tbl(4)  := l_mtlt_rec.d_attribute4;
23590 				   l_d_attributes_tbl(5)  := l_mtlt_rec.d_attribute5;
23591 				   l_d_attributes_tbl(6)  := l_mtlt_rec.d_attribute6;
23592 				   l_d_attributes_tbl(7)  := l_mtlt_rec.d_attribute7;
23593 				   l_d_attributes_tbl(8)  := l_mtlt_rec.d_attribute8;
23594 				   l_d_attributes_tbl(9)  := l_mtlt_rec.d_attribute9;
23595 				   l_d_attributes_tbl(10) := l_mtlt_rec.d_attribute10;
23596 				   l_n_attributes_tbl(1)  := l_mtlt_rec.n_attribute1;
23597 				   l_n_attributes_tbl(2)  := l_mtlt_rec.n_attribute2;
23598 				   l_n_attributes_tbl(3)  := l_mtlt_rec.n_attribute3;
23599 				   l_n_attributes_tbl(4)  := l_mtlt_rec.n_attribute4;
23600 				   l_n_attributes_tbl(5)  := l_mtlt_rec.n_attribute5;
23601 				   l_n_attributes_tbl(6)  := l_mtlt_rec.n_attribute6;
23602 				   l_n_attributes_tbl(7)  := l_mtlt_rec.n_attribute7;
23603 				   l_n_attributes_tbl(8)  := l_mtlt_rec.n_attribute8;
23604 				   l_n_attributes_tbl(9)  := l_mtlt_rec.n_attribute9;
23605 				   l_n_attributes_tbl(10) := l_mtlt_rec.n_attribute10;
23606 
23607            --Bug #3187688
23608            --Populate the INV attributes table and pass the attribute cateogry
23609            l_inv_attributes_tbl(1)  := l_mtlt_rec.attribute1;
23610            l_inv_attributes_tbl(2)  := l_mtlt_rec.attribute2;
23611            l_inv_attributes_tbl(3)  := l_mtlt_rec.attribute3;
23612            l_inv_attributes_tbl(4)  := l_mtlt_rec.attribute4;
23613            l_inv_attributes_tbl(5)  := l_mtlt_rec.attribute5;
23614            l_inv_attributes_tbl(6)  := l_mtlt_rec.attribute6;
23615            l_inv_attributes_tbl(7)  := l_mtlt_rec.attribute7;
23616            l_inv_attributes_tbl(8)  := l_mtlt_rec.attribute8;
23617            l_inv_attributes_tbl(9)  := l_mtlt_rec.attribute9;
23618            l_inv_attributes_tbl(10) := l_mtlt_rec.attribute10;
23619            l_inv_attributes_tbl(11) := l_mtlt_rec.attribute11;
23620            l_inv_attributes_tbl(12) := l_mtlt_rec.attribute12;
23621            l_inv_attributes_tbl(13) := l_mtlt_rec.attribute13;
23622            l_inv_attributes_tbl(14) := l_mtlt_rec.attribute14;
23623            l_inv_attributes_tbl(15) := l_mtlt_rec.attribute15;
23624 
23625 				   inv_lot_api_pub.create_inv_lot(x_return_status => x_return_status
23626 								  , x_msg_count => x_msg_count
23627 								  , x_msg_data => x_msg_data
23628 								  , p_inventory_item_id => l_item_id
23629 								  , p_organization_id => l_org_id
23630 								  , p_lot_number => l_mtlt_rec.lot_number
23631 								  , p_expiration_date => l_mtlt_rec.lot_expiration_date
23632 								  , p_disable_flag => NULL
23633 								  , p_attribute_category => l_mtlt_rec.attribute_category
23634 								  , p_lot_attribute_category => l_mtlt_rec.lot_attribute_category
23635 								  , p_attributes_tbl => l_inv_attributes_tbl
23636 								  , p_c_attributes_tbl => l_c_attributes_tbl
23637 								  , p_n_attributes_tbl => l_n_attributes_tbl
23638 								  , p_d_attributes_tbl => l_d_attributes_tbl
23639 								  , p_grade_code => l_mtlt_rec.grade_code
23640 								  , p_origination_date => l_mtlt_rec.origination_date
23641 								  , p_date_code => l_mtlt_rec.date_code
23642 								  , p_status_id => l_mtlt_rec.status_id
23643 								  , p_change_date => l_mtlt_rec.change_date
23644 								  , p_age => l_mtlt_rec.age
23645 								  , p_retest_date => l_mtlt_rec.retest_date
23646 				     , p_maturity_date => l_mtlt_rec.maturity_date
23647 				     , p_item_size => l_mtlt_rec.item_size
23648 				     , p_color => l_mtlt_rec.color
23649 				     , p_volume => l_mtlt_rec.volume
23650 				     , p_volume_uom => l_mtlt_rec.volume_uom
23651 				     , p_place_of_origin => l_mtlt_rec.place_of_origin
23652 				     , p_best_by_date => l_mtlt_rec.best_by_date
23653 				     , p_length => l_mtlt_rec.Length
23654 				     , p_length_uom => l_mtlt_rec.length_uom
23655 				     , p_recycled_content => l_mtlt_rec.recycled_content
23656 				     , p_thickness => l_mtlt_rec.thickness
23657 				     , p_thickness_uom => l_mtlt_rec.thickness_uom
23658 				     , p_width => l_mtlt_rec.width
23659 				     , p_width_uom => l_mtlt_rec.width_uom
23660 				     , p_territory_code => l_mtlt_rec.territory_code
23661 				     , p_supplier_lot_number => l_mtlt_rec.supplier_lot_number
23662 				     , p_vendor_name => l_mtlt_rec.vendor_name
23663 				     , p_source => inv_lot_api_pub.inv);
23664 
23665 				   IF (x_return_status <> 'S') THEN
23666 				      --raise error
23667 				      l_progress := 'WMSINB-25058';
23668 				      RAISE fnd_api.g_exc_error;
23669 				   END IF;
23670 
23671 				   IF (l_debug = 1) THEN
23672 				      print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CREATED: '||l_progress, 1);
23673 				      l_progress := 'WMSINB-25064';
23674 				   END IF;
23675 				 ELSE -- IF (l_discrete_transaction) THEN
23676 				   -- opm change bug# 3061052.
23677 				   gml_opm_roi_grp.validate_opm_lot(p_api_version	=> 1.0,
23678 								    p_init_msg_lst	 	=> FND_API.G_FALSE,
23679 								    p_mtlt_rowid		=> l_mtlt_rec.rowid,
23680 								    p_new_lot	 	=> 'Y',
23681 								    p_opm_item_id		=> l_opm_item_id,
23682 								    p_item_no		=> l_item_no,
23683 								    p_lots_specified_on_parent => 'Y',
23684 								    p_lot_id		=> l_opm_lot_id,
23685 								    p_parent_txn_type	=> l_parent_txn_type,
23686 								    p_grand_parent_txn_type => l_grand_parent_txn_type,
23687 								    x_return_status 	=> x_return_status,
23688 								    x_msg_data      	=> x_msg_data,
23689 								    x_msg_count     	=> x_msg_count
23690 								    );
23691               */
23692                /*end , INVCONV */
23693 
23694                  /*INVCONV , Perform lot validations and create the new lot.
23695                Call Lot Create API INV_ROI_INTEGRATION_GRP.INV_NEW_LOT to create the new lot.
23696                This shall also create lot specific conversions after creating the new Lot.
23697 			      This replaces the existing procedure INV_LOT_API_PUB.CREATE_INV_LOT to create NEW LOT
23698                Punit Kumar*/
23699 
23700               /*INVCONV ,*/
23701               IF (l_debug = 1) THEN
23702                  print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
23703               END IF;
23704 
23705               INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
23706                                                          x_return_status      		   => x_return_status
23707                                                         ,x_msg_data           		   => x_msg_data
23708                                                         ,x_msg_count          		   => x_msg_count
23709                                                         ,p_api_version	               => 1.0
23710                                                         ,p_init_msg_lst	               => FND_API.G_FALSE
23711                                                         ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
23712                                                         ,p_transaction_type_id 	      => l_transaction_type_id
23713                                                         ,p_new_lot			            => 'Y'
23714                                                         ,p_item_id	 		            => l_item_id
23715                                                         ,p_to_organization_id		      => L_ORG_ID
23716                                                         ,p_lot_number			         => L_MTLT_REC.lot_number
23717                                                         ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
23718                                                         ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
23719                                                         ,x_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
23720                                                         ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
23721                                                         ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
23722                                                         ,p_transaction_unit_of_measure => l_rti_UNIT_OF_MEASURE
23723                                                         ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
23724                                                         ,p_OE_ORDER_HEADER_ID	         => l_OE_ORDER_HEADER_ID
23725                                                         ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
23726                                                         ,p_rti_id	                     => L_RTI_ID
23727                                                         ,p_revision             	      => l_item_revision
23728                                                         ,p_subinventory_code  	      => L_SUB_CODE
23729                                                         ,p_locator_id           	      => l_loc_id
23730                                                         ,p_transaction_type           => l_transaction_type
23731                                                         ,p_parent_txn_type            => l_parent_txn_type
23732                                                         ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
23733                                                         );
23734 
23735                /*INVCONV ,*/
23736               IF (l_debug = 1) THEN
23737                  print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
23738                  print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
23739               END IF;
23740 
23741               IF (x_return_status <> 'S') THEN
23742                  --raise error
23743                  l_progress := 'WMSINB-25058';
23744                  RAISE fnd_api.g_exc_error;
23745               END IF;
23746 
23747               /*INVCONV ,*/
23748               IF (l_debug = 1) THEN
23749                  print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
23750               END IF;
23751 
23752                INV_ROI_INTEGRATION_GRP.INV_NEW_LOT(
23753                                                 x_return_status      		   => x_return_status
23754                                                ,x_msg_count          		   => x_msg_count
23755                                                ,x_msg_data           		   => x_msg_data
23756                                                ,p_api_version	               => 1.0
23757                                                ,p_init_msg_lst	               => FND_API.G_FALSE
23758                                                ,p_source_document_code			=> L_SOURCE_DOCUMENT_CODE
23759                                                ,p_item_id				         => l_item_id
23760                                                ,p_from_organization_id			=> L_FROM_ORG_ID
23761                                                ,p_to_organization_id	         => L_ORG_ID
23762                                                ,p_lot_number				      => L_MTLT_REC.lot_number
23763                                                ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
23764                                                ,p_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
23765                                                ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
23766                                                ,p_primary_unit_of_measure	   => l_rti_PRIMARY_UNIT_OF_MEASURE
23767                                                ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
23768                                                ,p_uom_code	                  => l_rti_UOM_CODE
23769                                                ,p_secondary_uom_code	         => l_rti_SECONDARY_UOM_CODE
23770                                                ,p_reason_id	                  => L_MTLT_REC.REASON_ID
23771                                                ,P_MLN_REC                     => L_MLN_REC
23772                                                ,p_mtlt_rowid	               => L_MTLT_REC.ROWID
23773                                                );
23774 
23775 		          /*INVCONV ,*/
23776                IF (l_debug = 1) THEN
23777                   print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
23778                   print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_NEW_LOT return status: '||x_return_status||' : '||l_progress, 1);
23779                END IF;
23780 
23781 				   IF X_RETURN_STATUS <> 'S' THEN
23782                   --RAISE ERROR
23783                   l_progress := 'WMSINB-25085';
23784                   RAISE fnd_api.g_exc_error;
23785                END IF;
23786 
23787 				   IF (l_debug = 1) THEN
23788 				      print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
23789 				   END IF;
23790 				/*END IF; --IF (l_discrete_transaction) THEN*/
23791 			      ELSE --IF (l_grand_parent_txn_type = 'DELIVER') THEN
23792 				IF (validate_rs(NULL,l_grand_parent_txn_id,l_dummy_lpn)) THEN
23793 				   IF NOT (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
23794 				      --raise an error
23795 				      l_progress := 'WMSINB-25097';
23796 				      RAISE fnd_api.g_exc_error;
23797 				   END IF;
23798 				END IF;
23799 
23800             /*INVCONV, Replace existing create lot call with a new call */
23801             /*
23802 				-- opm change bug# 3061052
23803 				IF (l_discrete_transaction) THEN
23804 
23805 				   --CALL CREATE_INV_LOT
23806 				   --FOR l_inv_att_index IN 1..15 LOOP
23807 				   -- l_inv_attributes_tbl(l_inv_att_index) := NULL;
23808 				   --END LOOP;
23809 
23810 				   l_c_attributes_tbl(1)  := l_mtlt_rec.c_attribute1;
23811 				   l_c_attributes_tbl(2)  := l_mtlt_rec.c_attribute2;
23812 				   l_c_attributes_tbl(3)  := l_mtlt_rec.c_attribute3;
23813 				   l_c_attributes_tbl(4)  := l_mtlt_rec.c_attribute4;
23814 				   l_c_attributes_tbl(5)  := l_mtlt_rec.c_attribute5;
23815 				   l_c_attributes_tbl(6)  := l_mtlt_rec.c_attribute6;
23816 				   l_c_attributes_tbl(7)  := l_mtlt_rec.c_attribute7;
23817 				   l_c_attributes_tbl(8)  := l_mtlt_rec.c_attribute8;
23818 				   l_c_attributes_tbl(9)  := l_mtlt_rec.c_attribute9;
23819 				   l_c_attributes_tbl(10) := l_mtlt_rec.c_attribute10;
23820 				   l_c_attributes_tbl(11) := l_mtlt_rec.c_attribute11;
23821 				   l_c_attributes_tbl(12) := l_mtlt_rec.c_attribute12;
23822 				   l_c_attributes_tbl(13) := l_mtlt_rec.c_attribute13;
23823 				   l_c_attributes_tbl(14) := l_mtlt_rec.c_attribute14;
23824 				   l_c_attributes_tbl(15) := l_mtlt_rec.c_attribute15;
23825 				   l_c_attributes_tbl(16) := l_mtlt_rec.c_attribute16;
23826 				   l_c_attributes_tbl(17) := l_mtlt_rec.c_attribute17;
23827 				   l_c_attributes_tbl(18) := l_mtlt_rec.c_attribute18;
23828 				   l_c_attributes_tbl(19) := l_mtlt_rec.c_attribute19;
23829 				   l_c_attributes_tbl(20) := l_mtlt_rec.c_attribute20;
23830 				   l_d_attributes_tbl(1)  := l_mtlt_rec.d_attribute1;
23831 				   l_d_attributes_tbl(2)  := l_mtlt_rec.d_attribute2;
23832 				   l_d_attributes_tbl(3)  := l_mtlt_rec.d_attribute3;
23833 				   l_d_attributes_tbl(4)  := l_mtlt_rec.d_attribute4;
23834 				   l_d_attributes_tbl(5)  := l_mtlt_rec.d_attribute5;
23835 				   l_d_attributes_tbl(6)  := l_mtlt_rec.d_attribute6;
23836 				   l_d_attributes_tbl(7)  := l_mtlt_rec.d_attribute7;
23837 				   l_d_attributes_tbl(8)  := l_mtlt_rec.d_attribute8;
23838 				   l_d_attributes_tbl(9)  := l_mtlt_rec.d_attribute9;
23839 				   l_d_attributes_tbl(10) := l_mtlt_rec.d_attribute10;
23840 				   l_n_attributes_tbl(1)  := l_mtlt_rec.n_attribute1;
23841 				   l_n_attributes_tbl(2)  := l_mtlt_rec.n_attribute2;
23842 				   l_n_attributes_tbl(3)  := l_mtlt_rec.n_attribute3;
23843 				   l_n_attributes_tbl(4)  := l_mtlt_rec.n_attribute4;
23844 				   l_n_attributes_tbl(5)  := l_mtlt_rec.n_attribute5;
23845 				   l_n_attributes_tbl(6)  := l_mtlt_rec.n_attribute6;
23846 				   l_n_attributes_tbl(7)  := l_mtlt_rec.n_attribute7;
23847 				   l_n_attributes_tbl(8)  := l_mtlt_rec.n_attribute8;
23848 				   l_n_attributes_tbl(9)  := l_mtlt_rec.n_attribute9;
23849 				   l_n_attributes_tbl(10) := l_mtlt_rec.n_attribute10;
23850 
23851            --Bug #3187688
23852            --Populate the INV attributes table and pass the attribute cateogry
23853            l_inv_attributes_tbl(1)  := l_mtlt_rec.attribute1;
23854            l_inv_attributes_tbl(2)  := l_mtlt_rec.attribute2;
23855            l_inv_attributes_tbl(3)  := l_mtlt_rec.attribute3;
23856            l_inv_attributes_tbl(4)  := l_mtlt_rec.attribute4;
23857            l_inv_attributes_tbl(5)  := l_mtlt_rec.attribute5;
23858            l_inv_attributes_tbl(6)  := l_mtlt_rec.attribute6;
23859            l_inv_attributes_tbl(7)  := l_mtlt_rec.attribute7;
23860            l_inv_attributes_tbl(8)  := l_mtlt_rec.attribute8;
23861            l_inv_attributes_tbl(9)  := l_mtlt_rec.attribute9;
23862            l_inv_attributes_tbl(10) := l_mtlt_rec.attribute10;
23863            l_inv_attributes_tbl(11) := l_mtlt_rec.attribute11;
23864            l_inv_attributes_tbl(12) := l_mtlt_rec.attribute12;
23865            l_inv_attributes_tbl(13) := l_mtlt_rec.attribute13;
23866            l_inv_attributes_tbl(14) := l_mtlt_rec.attribute14;
23867            l_inv_attributes_tbl(15) := l_mtlt_rec.attribute15;
23868 
23869 				   inv_lot_api_pub.create_inv_lot(x_return_status => x_return_status
23870 								  , x_msg_count => x_msg_count
23871 								  , x_msg_data => x_msg_data
23872 								  , p_inventory_item_id => l_item_id
23873 								  , p_organization_id => l_org_id
23874 								  , p_lot_number => l_mtlt_rec.lot_number
23875 								  , p_expiration_date => l_mtlt_rec.lot_expiration_date
23876 								  , p_disable_flag => NULL
23877 								  , p_attribute_category => l_mtlt_rec.attribute_category
23878 								  , p_lot_attribute_category => l_mtlt_rec.lot_attribute_category
23879 								  , p_attributes_tbl => l_inv_attributes_tbl
23880 								  , p_c_attributes_tbl => l_c_attributes_tbl
23881 								  , p_n_attributes_tbl => l_n_attributes_tbl
23882 								  , p_d_attributes_tbl => l_d_attributes_tbl
23883 								  , p_grade_code => l_mtlt_rec.grade_code
23884 								  , p_origination_date => l_mtlt_rec.origination_date
23885 								  , p_date_code => l_mtlt_rec.date_code
23886 								  , p_status_id => l_mtlt_rec.status_id
23887 								  , p_change_date => l_mtlt_rec.change_date
23888 								  , p_age => l_mtlt_rec.age
23889 								  , p_retest_date => l_mtlt_rec.retest_date
23890 				     , p_maturity_date => l_mtlt_rec.maturity_date
23891 				     , p_item_size => l_mtlt_rec.item_size
23892 				     , p_color => l_mtlt_rec.color
23893 				     , p_volume => l_mtlt_rec.volume
23894 				     , p_volume_uom => l_mtlt_rec.volume_uom
23895 				     , p_place_of_origin => l_mtlt_rec.place_of_origin
23896 				     , p_best_by_date => l_mtlt_rec.best_by_date
23897 				     , p_length => l_mtlt_rec.Length
23898 				     , p_length_uom => l_mtlt_rec.length_uom
23899 				     , p_recycled_content => l_mtlt_rec.recycled_content
23900 				     , p_thickness => l_mtlt_rec.thickness
23901 				     , p_thickness_uom => l_mtlt_rec.thickness_uom
23902 				     , p_width => l_mtlt_rec.width
23903 				     , p_width_uom => l_mtlt_rec.width_uom
23904 				     , p_territory_code => l_mtlt_rec.territory_code
23905 				     , p_supplier_lot_number => l_mtlt_rec.supplier_lot_number
23906 				     , p_vendor_name => l_mtlt_rec.vendor_name
23907 				     , p_source => inv_lot_api_pub.inv);
23908 
23909 				   IF (x_return_status <> 'S') THEN
23910 				      --raise error
23911 				      l_progress := 'WMSINB-25193';
23912 				      RAISE fnd_api.g_exc_error;
23913 				   END IF;
23914 
23915 				   IF (l_debug = 1) THEN
23916 				      print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CREATED: '||l_progress, 1);
23917 				      l_progress := 'WMSINB-25199';
23918 				   END IF;
23919 				 ELSE --IF (l_discrete_transaction) THEN
23920 				   -- opm change bug# 3061052
23921 				   gml_opm_roi_grp.validate_opm_lot(p_api_version	=> 1.0,
23922 								    p_init_msg_lst	 	=> FND_API.G_FALSE,
23923 								    p_mtlt_rowid		=> l_mtlt_rec.rowid,
23924 								    p_new_lot	 	=> 'Y',
23925 								    p_opm_item_id		=> l_opm_item_id,
23926 								    p_item_no		=> l_item_no,
23927 								    p_lots_specified_on_parent => 'Y',
23928 								    p_lot_id		=> l_opm_lot_id,
23929 								    p_parent_txn_type	=> l_parent_txn_type,
23930 								    p_grand_parent_txn_type => l_grand_parent_txn_type,
23931 								    x_return_status 	=> x_return_status,
23932 								    x_msg_data      	=> x_msg_data,
23933 								    x_msg_count     	=> x_msg_count
23934 								    );
23935 
23936              */
23937 
23938              /*INVCONV ,*/
23939             IF (l_debug = 1) THEN
23940                print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
23941             END IF;
23942 
23943             INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
23944                                                        x_return_status      		   => x_return_status
23945                                                       ,x_msg_data           		   => x_msg_data
23946                                                       ,x_msg_count          		   => x_msg_count
23947                                                       ,p_api_version	               => 1.0
23948                                                       ,p_init_msg_lst	               => FND_API.G_FALSE
23949                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
23950                                                       ,p_transaction_type_id 	      => l_transaction_type_id
23951                                                       ,p_new_lot			            => 'Y'
23952                                                       ,p_item_id	 		            => l_item_id
23953                                                       ,p_to_organization_id		   => L_ORG_ID
23954                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
23955                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
23956                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
23957                                                       ,x_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
23958                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
23959                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
23960                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
23961                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
23962                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
23963                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
23964                                                       ,p_rti_id	                  => L_RTI_ID
23965                                                       ,p_revision             	   => l_item_revision
23966                                                       ,p_subinventory_code  	      => L_SUB_CODE
23967                                                       ,p_locator_id           	   => l_loc_id
23968                                                       ,p_transaction_type           => l_transaction_type
23969                                                       ,p_parent_txn_type            => l_parent_txn_type
23970                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
23971                                                       );
23972 
23973                /*INVCONV ,*/
23974                IF (l_debug = 1) THEN
23975                   print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
23976                   print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
23977                END IF;
23978 
23979                IF (x_return_status <> 'S') THEN
23980 				      --raise error
23981 				      l_progress := 'WMSINB-25193';
23982 				      RAISE fnd_api.g_exc_error;
23983 				   END IF;
23984 
23985                 /*INVCONV ,*/
23986                IF (l_debug = 1) THEN
23987                   print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
23988                END IF;
23989 
23990                  INV_ROI_INTEGRATION_GRP.INV_NEW_LOT(
23991                                                 x_return_status      		   => x_return_status
23992                                                ,x_msg_count          		   => x_msg_count
23993                                                ,x_msg_data           		   => x_msg_data
23994                                                ,p_api_version	               => 1.0
23995                                                ,p_init_msg_lst	               => FND_API.G_FALSE
23996                                                ,p_source_document_code			=> L_SOURCE_DOCUMENT_CODE
23997                                                ,p_item_id				         => l_item_id
23998                                                ,p_from_organization_id			=> L_FROM_ORG_ID
23999                                                ,p_to_organization_id	         => L_ORG_ID
24000                                                ,p_lot_number				      => L_MTLT_REC.lot_number
24001                                                ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
24002                                                ,p_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
24003                                                ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
24004                                                ,p_primary_unit_of_measure	   => l_rti_PRIMARY_UNIT_OF_MEASURE
24005                                                ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
24006                                                ,p_uom_code	                  => l_rti_UOM_CODE
24007                                                ,p_secondary_uom_code	         => l_rti_SECONDARY_UOM_CODE
24008                                                ,p_reason_id	                  => L_MTLT_REC.REASON_ID
24009                                                ,P_MLN_REC                     => L_MLN_REC
24010                                                ,p_mtlt_rowid	               => L_MTLT_REC.ROWID
24011                                                );
24012 
24013                /*INVCONV ,*/
24014                IF (l_debug = 1) THEN
24015                   print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
24016                   print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_NEW_LOT return status: '||x_return_status||' : '||l_progress, 1);
24017                END IF;
24018 
24019 
24020 				   IF X_RETURN_STATUS <> 'S' THEN
24021 				      --RAISE ERROR
24022 				      l_progress := 'WMSINB-25220';
24023 				      RAISE fnd_api.g_exc_error;
24024 				   END IF;
24025 
24026 				   IF (l_debug = 1) THEN
24027 				      print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
24028 				   END IF;
24029 				/*END IF; --IF (l_discrete_transaction) THEN*/
24030 			     END IF; --IF (l_grand_parent_txn_type = 'DELIVER') THEN
24031 			   ELSIF (l_parent_txn_type = g_rtr) THEN --IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
24032 			     IF (lot_entered_on_parent(l_great_grand_parent_txn_id)) THEN
24033 				--raise an error
24034 				l_progress := 'WMSINB-25232';
24035 				RAISE fnd_api.g_exc_error;
24036 			      ELSE
24037 				--CALL CREATE_INV_LOT
24038 				--FOR l_inv_att_index IN 1..15 LOOP
24039 				-- l_inv_attributes_tbl(l_inv_att_index) := NULL;
24040 				--END LOOP;
24041 
24042             /* INVCONV, replace the existing create_inv_lot call with a new call */
24043 				/*
24044 				-- opm change bug# 3061052
24045 				IF (l_discrete_transaction) THEN
24046 				   l_c_attributes_tbl(1)  := l_mtlt_rec.c_attribute1;
24047 				   l_c_attributes_tbl(2)  := l_mtlt_rec.c_attribute2;
24048 				   l_c_attributes_tbl(3)  := l_mtlt_rec.c_attribute3;
24049 				   l_c_attributes_tbl(4)  := l_mtlt_rec.c_attribute4;
24050 				   l_c_attributes_tbl(5)  := l_mtlt_rec.c_attribute5;
24051 				   l_c_attributes_tbl(6)  := l_mtlt_rec.c_attribute6;
24052 				   l_c_attributes_tbl(7)  := l_mtlt_rec.c_attribute7;
24053 				   l_c_attributes_tbl(8)  := l_mtlt_rec.c_attribute8;
24054 				   l_c_attributes_tbl(9)  := l_mtlt_rec.c_attribute9;
24055 				   l_c_attributes_tbl(10) := l_mtlt_rec.c_attribute10;
24056 				   l_c_attributes_tbl(11) := l_mtlt_rec.c_attribute11;
24057 				   l_c_attributes_tbl(12) := l_mtlt_rec.c_attribute12;
24058 				   l_c_attributes_tbl(13) := l_mtlt_rec.c_attribute13;
24059 				   l_c_attributes_tbl(14) := l_mtlt_rec.c_attribute14;
24060 				   l_c_attributes_tbl(15) := l_mtlt_rec.c_attribute15;
24061 				   l_c_attributes_tbl(16) := l_mtlt_rec.c_attribute16;
24062 				   l_c_attributes_tbl(17) := l_mtlt_rec.c_attribute17;
24063 				   l_c_attributes_tbl(18) := l_mtlt_rec.c_attribute18;
24064 				   l_c_attributes_tbl(19) := l_mtlt_rec.c_attribute19;
24065 				   l_c_attributes_tbl(20) := l_mtlt_rec.c_attribute20;
24066 				   l_d_attributes_tbl(1)  := l_mtlt_rec.d_attribute1;
24067 				   l_d_attributes_tbl(2)  := l_mtlt_rec.d_attribute2;
24068 				   l_d_attributes_tbl(3)  := l_mtlt_rec.d_attribute3;
24069 				   l_d_attributes_tbl(4)  := l_mtlt_rec.d_attribute4;
24070 				   l_d_attributes_tbl(5)  := l_mtlt_rec.d_attribute5;
24071 				   l_d_attributes_tbl(6)  := l_mtlt_rec.d_attribute6;
24072 				   l_d_attributes_tbl(7)  := l_mtlt_rec.d_attribute7;
24073 				   l_d_attributes_tbl(8)  := l_mtlt_rec.d_attribute8;
24074 				   l_d_attributes_tbl(9)  := l_mtlt_rec.d_attribute9;
24075 				   l_d_attributes_tbl(10) := l_mtlt_rec.d_attribute10;
24076 				   l_n_attributes_tbl(1)  := l_mtlt_rec.n_attribute1;
24077 				   l_n_attributes_tbl(2)  := l_mtlt_rec.n_attribute2;
24078 				   l_n_attributes_tbl(3)  := l_mtlt_rec.n_attribute3;
24079 				   l_n_attributes_tbl(4)  := l_mtlt_rec.n_attribute4;
24080 				   l_n_attributes_tbl(5)  := l_mtlt_rec.n_attribute5;
24081 				   l_n_attributes_tbl(6)  := l_mtlt_rec.n_attribute6;
24082 				   l_n_attributes_tbl(7)  := l_mtlt_rec.n_attribute7;
24083 				   l_n_attributes_tbl(8)  := l_mtlt_rec.n_attribute8;
24084 				   l_n_attributes_tbl(9)  := l_mtlt_rec.n_attribute9;
24085 				   l_n_attributes_tbl(10) := l_mtlt_rec.n_attribute10;
24086 
24087            --Bug #3187688
24088            --Populate the INV attributes table and pass the attribute cateogry
24089            l_inv_attributes_tbl(1)  := l_mtlt_rec.attribute1;
24090            l_inv_attributes_tbl(2)  := l_mtlt_rec.attribute2;
24091            l_inv_attributes_tbl(3)  := l_mtlt_rec.attribute3;
24092            l_inv_attributes_tbl(4)  := l_mtlt_rec.attribute4;
24093            l_inv_attributes_tbl(5)  := l_mtlt_rec.attribute5;
24094            l_inv_attributes_tbl(6)  := l_mtlt_rec.attribute6;
24095            l_inv_attributes_tbl(7)  := l_mtlt_rec.attribute7;
24096            l_inv_attributes_tbl(8)  := l_mtlt_rec.attribute8;
24097            l_inv_attributes_tbl(9)  := l_mtlt_rec.attribute9;
24098            l_inv_attributes_tbl(10) := l_mtlt_rec.attribute10;
24099            l_inv_attributes_tbl(11) := l_mtlt_rec.attribute11;
24100            l_inv_attributes_tbl(12) := l_mtlt_rec.attribute12;
24101            l_inv_attributes_tbl(13) := l_mtlt_rec.attribute13;
24102            l_inv_attributes_tbl(14) := l_mtlt_rec.attribute14;
24103            l_inv_attributes_tbl(15) := l_mtlt_rec.attribute15;
24104 
24105 				   inv_lot_api_pub.create_inv_lot(x_return_status => x_return_status
24106 								  , x_msg_count => x_msg_count
24107 								  , x_msg_data => x_msg_data
24108 								  , p_inventory_item_id => l_item_id
24109 								  , p_organization_id => l_org_id
24110 								  , p_lot_number => l_mtlt_rec.lot_number
24111 								  , p_expiration_date => l_mtlt_rec.lot_expiration_date
24112 								  , p_disable_flag => NULL
24113 								  , p_attribute_category => l_mtlt_rec.attribute_category
24114 								  , p_lot_attribute_category => l_mtlt_rec.lot_attribute_category
24115 								  , p_attributes_tbl => l_inv_attributes_tbl
24116 								  , p_c_attributes_tbl => l_c_attributes_tbl
24117 								  , p_n_attributes_tbl => l_n_attributes_tbl
24118 								  , p_d_attributes_tbl => l_d_attributes_tbl
24119 								  , p_grade_code => l_mtlt_rec.grade_code
24120 								  , p_origination_date => l_mtlt_rec.origination_date
24121 								  , p_date_code => l_mtlt_rec.date_code
24122 								  , p_status_id => l_mtlt_rec.status_id
24123 								  , p_change_date => l_mtlt_rec.change_date
24124 								  , p_age => l_mtlt_rec.age
24125 								  , p_retest_date => l_mtlt_rec.retest_date
24126 				     , p_maturity_date => l_mtlt_rec.maturity_date
24127 				     , p_item_size => l_mtlt_rec.item_size
24128 				     , p_color => l_mtlt_rec.color
24129 				     , p_volume => l_mtlt_rec.volume
24130 				     , p_volume_uom => l_mtlt_rec.volume_uom
24131 				     , p_place_of_origin => l_mtlt_rec.place_of_origin
24132 				     , p_best_by_date => l_mtlt_rec.best_by_date
24133 				     , p_length => l_mtlt_rec.Length
24134 				     , p_length_uom => l_mtlt_rec.length_uom
24135 				     , p_recycled_content => l_mtlt_rec.recycled_content
24136 				     , p_thickness => l_mtlt_rec.thickness
24137 				     , p_thickness_uom => l_mtlt_rec.thickness_uom
24138 				     , p_width => l_mtlt_rec.width
24139 				     , p_width_uom => l_mtlt_rec.width_uom
24140 				     , p_territory_code => l_mtlt_rec.territory_code
24141 				     , p_supplier_lot_number => l_mtlt_rec.supplier_lot_number
24142 				     , p_vendor_name => l_mtlt_rec.vendor_name
24143 				     , p_source => inv_lot_api_pub.inv);
24144 
24145 				   IF (x_return_status <> 'S') THEN
24146 				      --raise error
24147 				      l_progress := 'WMSINB-25325';
24148 				      RAISE fnd_api.g_exc_error;
24149 				   END IF;
24150 
24151 				   IF (l_debug = 1) THEN
24152 				      print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CREATED: '||l_progress, 1);
24153 				      l_progress := 'WMSINB-25331';
24154 				   END IF;
24155 				 ELSE --IF (l_discrete_transaction) THEN
24156 				   -- opm change bug# 3061052
24157 				   gml_opm_roi_grp.validate_opm_lot(p_api_version	=> 1.0,
24158 								    p_init_msg_lst	 	=> FND_API.G_FALSE,
24159 								    p_mtlt_rowid		=> l_mtlt_rec.rowid,
24160 								    p_new_lot	 	=> 'Y',
24161 								    p_opm_item_id		=> l_opm_item_id,
24162 								    p_item_no		=> l_item_no,
24163 								    p_lots_specified_on_parent => 'N',
24164 								    p_lot_id		=> l_opm_lot_id,
24165 								    p_parent_txn_type	=> l_parent_txn_type,
24166 								    p_grand_parent_txn_type => l_grand_parent_txn_type,
24167 								    x_return_status 	=> x_return_status,
24168 								    x_msg_data      	=> x_msg_data,
24169 								    x_msg_count     	=> x_msg_count
24170 								    );
24171 
24172           */
24173              /*INVCONV , Perform lot validations and create the new lot.
24174                Call Lot Create API INV_ROI_INTEGRATION_GRP.INV_NEW_LOT to create the new lot.
24175                This shall also create lot specific conversions after creating the new Lot.
24176 			      This replaces the existing procedure INV_LOT_API_PUB.CREATE_INV_LOT to create NEW LOT
24177                Punit Kumar*/
24178 
24179                   /*INVCONV ,*/
24180                   IF (l_debug = 1) THEN
24181                      print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
24182                   END IF;
24183 
24184                   INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
24185                                                           x_return_status      		   => x_return_status
24186                                                          ,x_msg_data           		   => x_msg_data
24187                                                          ,x_msg_count          		   => x_msg_count
24188                                                          ,p_api_version	               => 1.0
24189                                                          ,p_init_msg_lst	            => FND_API.G_FALSE
24190                                                          ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
24191                                                          ,p_transaction_type_id 	      => l_transaction_type_id
24192                                                          ,p_new_lot			            => 'Y'
24193                                                          ,p_item_id	 		            => l_item_id
24194                                                          ,p_to_organization_id		   => L_ORG_ID
24195                                                          ,p_lot_number			         => L_MTLT_REC.lot_number
24196                                                          ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
24197                                                          ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
24198                                                          ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
24199                                                          ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
24200                                                          ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
24201                                                          ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
24202                                                          ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
24203                                                          ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
24204                                                          ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
24205                                                          ,p_rti_id	                  => L_RTI_ID
24206                                                          ,p_revision             	   => l_item_revision
24207                                                          ,p_subinventory_code  	      => L_SUB_CODE
24208                                                          ,p_locator_id           	   => l_loc_id
24209                                                          ,p_transaction_type           => l_transaction_type
24210                                                          ,p_parent_txn_type            => l_parent_txn_type
24211                                                          ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
24212                                                          );
24213 
24214                    /*INVCONV ,*/
24215                   IF (l_debug = 1) THEN
24216                      print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
24217                      print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
24218                   END IF;
24219 
24220                   IF (x_return_status <> 'S') THEN
24221                    --raise error
24222                    l_progress := 'WMSINB-25325';
24223                    RAISE fnd_api.g_exc_error;
24224                 END IF;
24225 
24226                  /*INVCONV ,*/
24227                 IF (l_debug = 1) THEN
24228                    print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
24229                 END IF;
24230 
24231                  INV_ROI_INTEGRATION_GRP.INV_NEW_LOT(
24232                                                 x_return_status      		   => x_return_status
24233                                                ,x_msg_count          		   => x_msg_count
24234                                                ,x_msg_data           		   => x_msg_data
24235                                                ,p_api_version	               => 1.0
24236                                                ,p_init_msg_lst	               => FND_API.G_FALSE
24237                                                ,p_source_document_code			=> L_SOURCE_DOCUMENT_CODE
24238                                                ,p_item_id				         => l_item_id
24239                                                ,p_from_organization_id			=> L_FROM_ORG_ID
24240                                                ,p_to_organization_id	         => L_ORG_ID
24241                                                ,p_lot_number				      => L_MTLT_REC.lot_number
24242                                                ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
24243                                                ,p_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
24244                                                ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
24245                                                ,p_primary_unit_of_measure	   => l_rti_PRIMARY_UNIT_OF_MEASURE
24246                                                ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
24247                                                ,p_uom_code	                  => l_rti_UOM_CODE
24248                                                ,p_secondary_uom_code	         => l_rti_SECONDARY_UOM_CODE
24249                                                ,p_reason_id	                  => L_MTLT_REC.REASON_ID
24250                                                ,P_MLN_REC                     => L_MLN_REC
24251                                                ,p_mtlt_rowid	               => L_MTLT_REC.ROWID
24252                                                );
24253 
24254                  /*INVCONV ,*/
24255                  IF (l_debug = 1) THEN
24256                     print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
24257                     print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_NEW_LOT return status: '||x_return_status||' : '||l_progress, 1);
24258                  END IF;
24259 
24260 				   IF X_RETURN_STATUS <> 'S' THEN
24261 				      --RAISE ERROR
24262 				      l_progress := 'WMSINB-25352';
24263 				      RAISE fnd_api.g_exc_error;
24264 				   END IF;
24265 
24266 				   IF (l_debug = 1) THEN
24267 				      print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
24268 				   END IF;
24269 			  /* END IF ; --   IF (l_discrete_transaction) THEN*/
24270 			     END IF; ---- IF (lot_entered_on_parent(l_great_grand_parent_txn_id)) THEN
24271 
24272               /*the comment for above end if was wrong , I have corrected it. Punit Kumar*/
24273 
24274 
24275 
24276           ELSE --ELSIF (l_parent_txn_type = g_rtr) THEN
24277 
24278             --raise an error
24279 			     l_progress := 'WMSINB-25363';
24280 			     RAISE fnd_api.g_exc_error;
24281 			  END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
24282 		 END IF;--IF (l_lot_exists = 1) THEN
24283 
24284 		 IF (l_serial_number_control_code IN (2,5,6)) THEN
24285 		    IF (l_debug = 1) THEN
24286 		       print_debug('VALIDATE_LOT_SERIAL_INFO: LOT AND SERIAL CONTROLLED: '||l_progress, 1);
24287 		       print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROL CODE: '||l_serial_number_control_code||' : '||l_progress, 1);
24288 		       print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||l_source_document_code||' : '||l_progress, 1);
24289 		       l_progress := 'WMSINB-25373';
24290 		    END IF;
24291 
24292 		    L_NUM_MSNT_RECS := 0;
24293 		    l_tot_msnt_serial_qty := 0;
24294 
24295 		    OPEN C_MSNT_LOTSERIAL(L_MTLT_REC.SERIAL_TRANSACTION_TEMP_ID);
24296 
24297 		    LOOP
24298 		       FETCH C_MSNT_LOTSERIAL INTO L_MSNT_REC;
24299 
24300 		       EXIT WHEN C_MSNT_LOTSERIAL%NOTFOUND;
24301 
24302 		       L_NUM_MSNT_RECS := L_NUM_MSNT_RECS + 1;
24303 
24304 		       L_SERIAL_QUANTITY :=
24305 			 INV_SERIAL_NUMBER_PUB.GET_SERIAL_DIFF(L_MSNT_REC.FM_SERIAL_NUMBER,
24306 							       L_MSNT_REC.TO_SERIAL_NUMBER);
24307 
24308 		       l_tot_msnt_serial_qty := l_tot_msnt_serial_qty + l_serial_quantity;
24309 
24310 		       INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.FM_SERIAL_NUMBER, L_TEMP_PREFIX, L_FROM_SER_NUMBER);
24311 		       INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.TO_SERIAL_NUMBER, L_TEMP_PREFIX, L_TO_SER_NUMBER);
24312 
24313 		       IF (l_debug = 1) THEN
24314 			  print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL QUANTITY: '||l_serial_quantity||' : '||l_progress, 1);
24315 			  l_progress := 'WMSINB-25398';
24316 		       END IF;
24317 
24318 		       --populate attributes table
24319 		       l_serial_attributes_tbl(1).column_name   := 'SERIAL_ATTRIBUTE_CATEGORY';
24320 		       l_serial_attributes_tbl(1).column_value  := l_msnt_rec.serial_attribute_category;
24321 		       l_serial_attributes_tbl(2).column_name   := 'ORIGINATION_DATE';
24322 		       l_serial_attributes_tbl(2).column_value  := l_msnt_rec.origination_date;
24323 		       l_serial_attributes_tbl(3).column_name   := 'C_ATTRIBUTE1';
24324 		       l_serial_attributes_tbl(3).column_value  := l_msnt_rec.c_attribute1;
24325 		       l_serial_attributes_tbl(4).column_name   := 'C_ATTRIBUTE2';
24326 		       l_serial_attributes_tbl(4).column_value  := l_msnt_rec.c_attribute2;
24327 		       l_serial_attributes_tbl(5).column_name   := 'C_ATTRIBUTE3';
24328 		       l_serial_attributes_tbl(5).column_value  := l_msnt_rec.c_attribute3;
24329 		       l_serial_attributes_tbl(6).column_name   := 'C_ATTRIBUTE4';
24330 		       l_serial_attributes_tbl(6).column_value   := l_msnt_rec.c_attribute4;
24331 		       l_serial_attributes_tbl(7).column_name   := 'C_ATTRIBUTE5';
24332 		       l_serial_attributes_tbl(7).column_value   := l_msnt_rec.c_attribute5;
24333 		       l_serial_attributes_tbl(8).column_name   := 'C_ATTRIBUTE6';
24334 		       l_serial_attributes_tbl(8).column_value   := l_msnt_rec.c_attribute6;
24335 		       l_serial_attributes_tbl(9).column_name   := 'C_ATTRIBUTE7';
24336 		       l_serial_attributes_tbl(9).column_value   := l_msnt_rec.c_attribute7;
24337 		       l_serial_attributes_tbl(10).column_name  := 'C_ATTRIBUTE8';
24338 		       l_serial_attributes_tbl(10).column_value  := l_msnt_rec.c_attribute8;
24339 		       l_serial_attributes_tbl(11).column_name  := 'C_ATTRIBUTE9';
24340 		       l_serial_attributes_tbl(11).column_value  := l_msnt_rec.c_attribute9;
24341 		       l_serial_attributes_tbl(12).column_name  := 'C_ATTRIBUTE10';
24342 		       l_serial_attributes_tbl(12).column_value  := l_msnt_rec.c_attribute10;
24343 		       l_serial_attributes_tbl(13).column_name  := 'C_ATTRIBUTE11';
24344 		       l_serial_attributes_tbl(13).column_value  := l_msnt_rec.c_attribute11;
24345 		       l_serial_attributes_tbl(14).column_name  := 'C_ATTRIBUTE12';
24346 		       l_serial_attributes_tbl(14).column_value  := l_msnt_rec.c_attribute12;
24347 		       l_serial_attributes_tbl(15).column_name  := 'C_ATTRIBUTE13';
24348 		       l_serial_attributes_tbl(15).column_value  := l_msnt_rec.c_attribute13;
24349 		       l_serial_attributes_tbl(16).column_name  := 'C_ATTRIBUTE14';
24350 		       l_serial_attributes_tbl(16).column_value  := l_msnt_rec.c_attribute14;
24351 		       l_serial_attributes_tbl(17).column_name  := 'C_ATTRIBUTE15';
24352 		       l_serial_attributes_tbl(17).column_value  := l_msnt_rec.c_attribute15;
24353 		       l_serial_attributes_tbl(18).column_name  := 'C_ATTRIBUTE16';
24354 		       l_serial_attributes_tbl(18).column_value  := l_msnt_rec.c_attribute16;
24355 		       l_serial_attributes_tbl(19).column_name  := 'C_ATTRIBUTE17';
24356 		       l_serial_attributes_tbl(19).column_value  := l_msnt_rec.c_attribute17;
24357 		       l_serial_attributes_tbl(20).column_name  := 'C_ATTRIBUTE18';
24358 		       l_serial_attributes_tbl(20).column_value  := l_msnt_rec.c_attribute18;
24359 		       l_serial_attributes_tbl(21).column_name  := 'C_ATTRIBUTE19';
24360 		       l_serial_attributes_tbl(21).column_value  := l_msnt_rec.c_attribute19;
24361 		       l_serial_attributes_tbl(22).column_name  := 'C_ATTRIBUTE20';
24362 		       l_serial_attributes_tbl(22).column_value  := l_msnt_rec.c_attribute20;
24363 		       l_serial_attributes_tbl(23).column_name  := 'D_ATTRIBUTE1';
24364 		       l_serial_attributes_tbl(23).column_value  := l_msnt_rec.d_attribute1;
24365 		       l_serial_attributes_tbl(24).column_name  := 'D_ATTRIBUTE2';
24366 		       l_serial_attributes_tbl(24).column_value  := l_msnt_rec.d_attribute2;
24367 		       l_serial_attributes_tbl(25).column_name  := 'D_ATTRIBUTE3';
24368 		       l_serial_attributes_tbl(25).column_value  := l_msnt_rec.d_attribute3;
24369 		       l_serial_attributes_tbl(26).column_name  := 'D_ATTRIBUTE4';
24370 		       l_serial_attributes_tbl(26).column_value  := l_msnt_rec.d_attribute4;
24371 		       l_serial_attributes_tbl(27).column_name  := 'D_ATTRIBUTE5';
24372 		       l_serial_attributes_tbl(27).column_value  := l_msnt_rec.d_attribute5;
24373 		       l_serial_attributes_tbl(28).column_name  := 'D_ATTRIBUTE6';
24374 		       l_serial_attributes_tbl(28).column_value  := l_msnt_rec.d_attribute6;
24375 		       l_serial_attributes_tbl(29).column_name  := 'D_ATTRIBUTE7';
24376 		       l_serial_attributes_tbl(29).column_value  := l_msnt_rec.d_attribute7;
24377 		       l_serial_attributes_tbl(30).column_name  := 'D_ATTRIBUTE8';
24378 		       l_serial_attributes_tbl(30).column_value  := l_msnt_rec.d_attribute8;
24379 		       l_serial_attributes_tbl(31).column_name  := 'D_ATTRIBUTE9';
24380 		       l_serial_attributes_tbl(31).column_value  := l_msnt_rec.d_attribute9;
24381 		       l_serial_attributes_tbl(32).column_name  := 'D_ATTRIBUTE10';
24382 		       l_serial_attributes_tbl(32).column_value  := l_msnt_rec.d_attribute10;
24383 		       l_serial_attributes_tbl(33).column_name  := 'N_ATTRIBUTE1';
24384 		       l_serial_attributes_tbl(33).column_value  := l_msnt_rec.n_attribute1;
24385 		       l_serial_attributes_tbl(34).column_name  := 'N_ATTRIBUTE2';
24386 		       l_serial_attributes_tbl(34).column_value  := l_msnt_rec.n_attribute2;
24387 		       l_serial_attributes_tbl(35).column_name  := 'N_ATTRIBUTE3';
24388 		       l_serial_attributes_tbl(35).column_value  := l_msnt_rec.n_attribute3;
24389 		       l_serial_attributes_tbl(36).column_name  := 'N_ATTRIBUTE4';
24390 		       l_serial_attributes_tbl(36).column_value  := l_msnt_rec.n_attribute4;
24391 		       l_serial_attributes_tbl(37).column_name  := 'N_ATTRIBUTE5';
24392 		       l_serial_attributes_tbl(37).column_value := l_msnt_rec.n_attribute5;
24393 		       l_serial_attributes_tbl(38).column_name  := 'N_ATTRIBUTE6';
24394 		       l_serial_attributes_tbl(38).column_value := l_msnt_rec.n_attribute6;
24395 		       l_serial_attributes_tbl(39).column_name  := 'N_ATTRIBUTE7';
24396 		       l_serial_attributes_tbl(39).column_value := l_msnt_rec.n_attribute7;
24397 		       l_serial_attributes_tbl(40).column_name  := 'N_ATTRIBUTE8';
24398 		       l_serial_attributes_tbl(40).column_value := l_msnt_rec.n_attribute8;
24399 		       l_serial_attributes_tbl(41).column_name  := 'N_ATTRIBUTE9';
24400 		       l_serial_attributes_tbl(41).column_value := l_msnt_rec.n_attribute9;
24401 		       l_serial_attributes_tbl(42).column_name  := 'N_ATTRIBUTE10';
24402 		       l_serial_attributes_tbl(42).column_value := l_msnt_rec.n_attribute10;
24403 		       l_serial_attributes_tbl(43).column_name  := 'STATUS_ID';
24404 		       l_serial_attributes_tbl(43).column_value := l_msnt_rec.status_id;
24405 		       l_serial_attributes_tbl(44).column_name  := 'TERRITORY_CODE';
24406 		       l_serial_attributes_tbl(44).column_value := l_msnt_rec.territory_code;
24407 
24408 		       --validate the serials
24409 		       FOR SERIALQTY IN 1..L_SERIAL_QUANTITY LOOP
24410 
24411 			  l_progress := 'WMSINB-25404';
24412 
24413                           L_CUR_NUMBER := L_FROM_SER_NUMBER+SERIALQTY -1;
24414                           if L_FROM_SER_NUMBER = -1 and  L_TO_SER_NUMBER = -1 then
24415 	                       L_SERIAL_NUMBER  := L_MSNT_REC.fm_serial_number;
24416 		          else
24417 		               L_SERIAL_NUMBER :=
24418 			         SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
24419 				   LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
24420 				   LENGTH(L_CUR_NUMBER))
24421 			         ||L_CUR_NUMBER;
24422                           End if;
24423 			  --L_SERIAL_NUMBER :=
24424 			    --SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
24425 				   --LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
24426 				  -- LENGTH(L_FROM_SER_NUMBER))
24427 			    --||(L_FROM_SER_NUMBER+SERIALQTY -1);
24428 
24429 			  l_progress := 'WMSINB-25412';
24430 
24431 		          BEGIN
24432 			     SELECT CURRENT_ORGANIZATION_ID
24433 			       , current_status
24434 			       , lot_number
24435 			       , Decode(lpn_id,0,NULL,lpn_id)
24436 			       , inspection_status
24437 			       , group_mark_id
24438 			       INTO L_CURR_ORG_ID
24439 			       , l_curr_status
24440 			       , l_curr_lot_num
24441 			       , l_curr_lpn_id
24442 			       , l_inspection_status
24443 			       , l_group_mark_id
24444 			       FROM MTL_SERIAL_NUMBERS
24445 			       WHERE SERIAL_NUMBER = l_serial_number
24446 			       AND inventory_item_id = l_item_id;
24447 
24448 			     l_serial_exists := 1;
24449 			     l_progress := 'WMSINB-25432';
24450 			  EXCEPTION
24451 			     WHEN no_data_found THEN
24452 				l_serial_exists := 0;
24453 				l_progress := 'WMSINB-25436';
24454 			  END;
24455 
24456 			  IF (l_debug = 1) THEN
24457 			     print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL EXISTS: '||l_serial_exists||' : '||l_progress, 1);
24458 			     print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NUMBER: '||l_serial_number||' : '||l_progress, 1);
24459 			     print_debug('VALIDATE_LOT_SERIAL_INFO: CURR STATUS: '||l_curr_status||' : '||l_progress, 1);
24460 			     print_debug('VALIDATE_LOT_SERIAL_INFO: CURR ORG ID: '||l_curr_org_id||' : '||l_progress, 1);
24461 			     print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LPN ID: '||l_curr_lpn_id||' : '||l_progress, 1);
24462 			     print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LOT NUM: '||l_curr_lot_num||' : '||l_progress, 1);
24463 			     print_debug('VALIDATE_LOT_SERIAL_INFO: INSPECT STS: '||l_inspection_status||' : '||l_progress, 1);
24464 			     print_debug('VALIDATE_LOT_SERIAL_INFO: GROUP MARK ID: '||l_group_mark_id||' : '||l_progress, 1);
24465 			     print_debug('VALIDATE_LOT_SERIAL_INFO: RESTRICT RCPT SER: '||l_restrict_rcpt_ser||' : '||l_progress, 1);
24466 			     l_progress := 'WMSINB-25449';
24467 			  END IF;
24468 
24469 			  IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
24470 			     IF (l_grand_parent_txn_type <> 'DELIVER') THEN
24471 				IF NOT (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
24472 				   --raise an error
24473 				   l_progress := 'WMSINB-25456';
24474 				   RAISE fnd_api.g_exc_error;
24475 				END IF;
24476 			     END IF; --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
24477 
24478 			     IF (l_serial_exists = 1) THEN
24479 				IF l_curr_org_id <> l_org_id THEN
24480 				   --raise error
24481 				   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24482 				   fnd_msg_pub.ADD;
24483 				   l_progress := 'WMSINB-25466';
24484 				   RAISE fnd_api.g_exc_error;
24485 				 ELSE
24486 				   IF ((l_curr_lot_num IS NOT NULL) AND
24487 				       (l_curr_lot_num <>
24488 					l_mtlt_rec.lot_number)
24489 				       AND (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
24490 				      --raise error
24491 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24492 				      fnd_msg_pub.ADD;
24493 				      l_progress := 'WMSINB-25473';
24494 				      RAISE fnd_api.g_exc_error;
24495 				   END IF;
24496 				END IF;
24497 
24498 				IF l_curr_status NOT IN (1,6) THEN
24499 				   --raise error
24500 				   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24501 				   fnd_msg_pub.ADD;
24502 				   l_progress := 'WMSINB-25482';
24503 				   RAISE fnd_api.g_exc_error;
24504 				END IF;
24505 
24506 				IF (Nvl(l_group_mark_id, -99) = -7937) THEN
24507 				   --raise error
24508 				   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24509 				   fnd_msg_pub.ADD;
24510 				   l_progress := 'WMSINB-25490';
24511 				   RAISE fnd_api.g_exc_error;
24512 				END IF;
24513 
24514 				IF (Nvl(l_curr_status, 1) in (1,6)) THEN
24515 				   --validate and update the attributes.
24516 				   inv_serial_number_pub.validate_update_serial_att
24517 				     (x_return_status     => x_return_status,
24518 				      x_msg_count         => x_msg_count,
24519 				      x_msg_data          => x_msg_data,
24520 				      x_validation_status => l_validation_status,
24521 				      p_serial_number     => l_serial_number,
24522 				      p_organization_id   => l_org_id,
24523 				      p_inventory_item_id => l_item_id,
24524 				      p_serial_att_tbl    => l_serial_attributes_tbl,
24525 				      p_validate_only     => FALSE
24526 				      );
24527 
24528 				   IF (l_validation_status <> 'Y'
24529 				       OR x_return_status <> g_ret_sts_success) THEN
24530 				      --raise error
24531 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24532 				      fnd_msg_pub.ADD;
24533 				      l_progress := 'WMSINB-254960';
24534 				      RAISE fnd_api.g_exc_error;
24535 				   END IF;
24536 				END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
24537 
24538 				--UPDATE GROUP_MARK_ID TO -7937
24539 				IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
24540 				   --raise error
24541 				   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24542 				   fnd_msg_pub.ADD;
24543 				   l_progress := 'WMSINB-25499';
24544 				   RAISE fnd_api.g_exc_error;
24545 				END IF;
24546 			      ELSE --IF (l_serial_exists = 1) THEN
24547 				IF l_serial_number_control_code = 5 THEN
24548 				   --PERFORM SERIAL VALIDATION FOR NEW SERIAL
24549 				   --(INCLUDING ATT VALIDATION)
24550 				   --CREATE MSN
24551 				   IF (l_transaction_type = 'CORRECT') THEN
24552 				      l_transaction_action_id := 29;
24553 				    ELSE
24554 				      l_transaction_action_id := 1;
24555 				   END IF;
24556 
24557 				   inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
24558 									     , p_inventory_item_id => l_item_id
24559 									     , p_organization_id => l_org_id
24560 									     , p_from_serial_number => l_serial_number
24561 									     , p_to_serial_number => l_serial_number
24562 									     , p_initialization_date => SYSDATE
24563 									     , p_completion_date => NULL
24564 									     , p_ship_date => NULL
24565 									     , p_revision => l_item_revision
24566 									     , p_lot_number => l_mtlt_rec.lot_number
24567 									     , p_current_locator_id => l_loc_id
24568 									     , p_subinventory_code => l_sub_code
24569 									     , p_trx_src_id => NULL
24570 									     , p_unit_vendor_id => NULL
24571 									     , p_vendor_lot_number => l_mtlt_rec.supplier_lot_number
24572 									     , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
24573 									     , p_receipt_issue_type => NULL
24574 									     , p_txn_src_id => NULL
24575 									     , p_txn_src_name => NULL
24576 									     , p_txn_src_type_id => NULL
24577 									     , p_transaction_id => NULL
24578 									     , p_current_status => 1
24579 				     , p_parent_item_id => NULL
24580 				     , p_parent_serial_number => NULL
24581 				     , p_cost_group_id => NULL
24582 				     , p_transaction_action_id => l_transaction_action_id
24583 				     , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
24584 				     , p_status_id => NULL
24585 				     , p_inspection_status => NULL
24586 				     , x_object_id => l_object_id
24587 				     , x_return_status => x_return_status
24588 				     , x_msg_count => x_msg_count
24589 				     , x_msg_data => x_msg_data);
24590 
24591 				   IF (x_return_status <> g_ret_sts_success) THEN
24592 				      --raise error
24593 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24594 				      fnd_msg_pub.ADD;
24595 				      l_progress := 'WMSINB-25505';
24596 				      RAISE fnd_api.g_exc_error;
24597 				   END IF;
24598 
24599 				   --validate and update the attributes.
24600 				   inv_serial_number_pub.validate_update_serial_att
24601 				     (x_return_status     => x_return_status,
24602 				      x_msg_count         => x_msg_count,
24603 				      x_msg_data          => x_msg_data,
24604 				      x_validation_status => l_validation_status,
24605 				      p_serial_number     => l_serial_number,
24606 				      p_organization_id   => l_org_id,
24607 				      p_inventory_item_id => l_item_id,
24608 				      p_serial_att_tbl    => l_serial_attributes_tbl,
24609 				      p_validate_only     => FALSE
24610 				      );
24611 
24612 				   IF (l_validation_status <> 'Y'
24613 				       OR x_return_status <> g_ret_sts_success) THEN
24614 				      --raise error
24615 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24616 				      fnd_msg_pub.ADD;
24617 				      l_progress := 'WMSINB-25545';
24618 				      RAISE fnd_api.g_exc_error;
24619 				   END IF;
24620 
24621 				   --UPDATE GROUP_MARK_ID TO -7937
24622 				   IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
24623 				      --raise error
24624 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24625 				      fnd_msg_pub.ADD;
24626 				      l_progress := 'WMSINB-25552';
24627 				      RAISE fnd_api.g_exc_error;
24628 				   END IF;
24629 				 ELSE --IF l_serial_number_control_code = 5 THEN
24630 				   --raise error
24631 				   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24632 				   fnd_msg_pub.ADD;
24633 				   l_progress := 'WMSINB-25559';
24634 				   RAISE fnd_api.g_exc_error;
24635 				END IF; --IF l_serial_number_control_code = 5 THEN
24636 			     END IF; --IF (l_serial_exists = 1) THEN
24637 			   ELSIF (l_parent_txn_type = g_rtr) THEN --IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
24638 			     IF (serial_entered_on_parent(l_great_grand_parent_txn_id)) THEN
24639 			        BEGIN
24640 				   SELECT '1'
24641 				     INTO L_DUMMY
24642 				     FROM RCV_SERIALS_SUPPLY
24643 				     WHERE TRANSACTION_ID = l_great_grand_parent_txn_id
24644 				     AND SERIAL_NUM = L_SERIAL_NUMBER;
24645 
24646 				   IF (l_curr_status <> 7) THEN
24647 				      --raise error
24648 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24649 				      fnd_msg_pub.ADD;
24650 				      l_progress := 'WMSINB-25576';
24651 				      RAISE fnd_api.g_exc_error;
24652 				   END IF;
24653 
24654 				   --Validate serial/group_mark_id to prevent
24655 				   --entering of duplicate serials
24656 
24657 				   IF (Nvl(l_group_mark_id, -99) = -7937) THEN
24658 				      --raise error
24659 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24660 				      fnd_msg_pub.ADD;
24661 				      l_progress := 'WMSINB-25587';
24662 				      RAISE fnd_api.g_exc_error;
24663 				   END IF;
24664 
24665 				   --UPDATE GROUP_MARK_ID TO -7937
24666 				   IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
24667 				      --raise error
24668 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24669 				      fnd_msg_pub.ADD;
24670 				      l_progress := 'WMSINB-25596';
24671 				      RAISE fnd_api.g_exc_error;
24672 				   END IF;
24673 				EXCEPTION
24674 				   WHEN NO_DATA_FOUND THEN
24675 				      -- RAISE ERROR
24676 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24677 				      fnd_msg_pub.ADD;
24678 				      l_progress := 'WMSINB-25604';
24679 				      RAISE fnd_api.g_exc_error;
24680 				END;
24681 			      ELSE --IF (serial_entered_on_parent(l_great_grand_parent_txn_id)) THEN
24682 				      IF (l_serial_exists = 1) THEN
24683 					 IF l_curr_org_id <> l_org_id THEN
24684 					    --raise error
24685 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24686 					    fnd_msg_pub.ADD;
24687 					    l_progress := 'WMSINB-25613';
24688 					    RAISE fnd_api.g_exc_error;
24689 					  ELSE
24690 					    IF ((l_curr_lot_num IS NOT
24691 						 NULL) AND (l_curr_lot_num
24692 							    <>
24693 							    l_mtlt_rec.lot_number)
24694 						AND (Nvl(l_curr_status,1)
24695 						     NOT IN (1,4))) THEN
24696 					       --raise error
24697 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24698 					       fnd_msg_pub.ADD;
24699 					       l_progress := 'WMSINB-25620';
24700 					       RAISE fnd_api.g_exc_error;
24701 					    END IF;
24702 					 END IF;
24703 
24704 					 IF l_curr_status NOT IN (1,6) THEN
24705 					    --raise error
24706 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24707 					    fnd_msg_pub.ADD;
24708 					    l_progress := 'WMSINB-25629';
24709 					    RAISE fnd_api.g_exc_error;
24710 					 END IF;
24711 
24712 					 IF (Nvl(l_group_mark_id, -99) = -7937) THEN
24713 					    --raise error
24714 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24715 					    fnd_msg_pub.ADD;
24716 					    l_progress := 'WMSINB-25637';
24717 					    RAISE fnd_api.g_exc_error;
24718 					 END IF;
24719 
24720 					 IF (Nvl(l_curr_status, 1) in (1,6)) THEN
24721 					    --validate and update the attributes.
24722 					    inv_serial_number_pub.validate_update_serial_att
24723 					      (x_return_status     => x_return_status,
24724 					       x_msg_count         => x_msg_count,
24725 					       x_msg_data          => x_msg_data,
24726 					       x_validation_status => l_validation_status,
24727 					       p_serial_number     => l_serial_number,
24728 					       p_organization_id   => l_org_id,
24729 					       p_inventory_item_id => l_item_id,
24730 					       p_serial_att_tbl    => l_serial_attributes_tbl,
24731 					       p_validate_only     => FALSE
24732 					       );
24733 
24734 					    IF (l_validation_status <> 'Y'
24735 						OR x_return_status <> g_ret_sts_success) THEN
24736 					       --raise error
24737 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24738 					       fnd_msg_pub.ADD;
24739 					       l_progress := 'WMSINB-25642';
24740 					       RAISE fnd_api.g_exc_error;
24741 					    END IF;
24742 					 END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
24743 
24744 					 --UPDATE GROUP_MARK_ID TO -7937
24745 					 IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
24746 					    --raise error
24747 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24748 					    fnd_msg_pub.ADD;
24749 					    l_progress := 'WMSINB-25646';
24750 					    RAISE fnd_api.g_exc_error;
24751 					 END IF;
24752 				       ELSE --IF (l_serial_exists = 1) THEN
24753 					 IF l_serial_number_control_code = 5 THEN
24754 					    --PERFORM SERIAL VALIDATION FOR NEW SERIAL
24755 					    --(INCLUDING ATT VALIDATION)
24756 					    --CREATE MSN
24757 					    IF (l_transaction_type = 'CORRECT') THEN
24758 					       l_transaction_action_id := 29;
24759 					     ELSE
24760 					       l_transaction_action_id := 1;
24761 					    END IF;
24762 
24763 					    inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
24764 										      , p_inventory_item_id => l_item_id
24765 										      , p_organization_id => l_org_id
24766 										      , p_from_serial_number => l_serial_number
24767 										      , p_to_serial_number => l_serial_number
24768 										      , p_initialization_date => SYSDATE
24769 										      , p_completion_date => NULL
24770 										      , p_ship_date => NULL
24771 										      , p_revision => l_item_revision
24772 										      , p_lot_number => l_mtlt_rec.lot_number
24773 										      , p_current_locator_id => l_loc_id
24774 										      , p_subinventory_code => l_sub_code
24775 										      , p_trx_src_id => NULL
24776 										      , p_unit_vendor_id => NULL
24777 										      , p_vendor_lot_number => l_mtlt_rec.supplier_lot_number
24778 										      , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
24779 										      , p_receipt_issue_type => NULL
24780 										      , p_txn_src_id => NULL
24781 										      , p_txn_src_name => NULL
24782 										      , p_txn_src_type_id => NULL
24783 										      , p_transaction_id => NULL
24784 					      , p_current_status => 1
24785 					      , p_parent_item_id => NULL
24786 					      , p_parent_serial_number => NULL
24787 					      , p_cost_group_id => NULL
24788 					      , p_transaction_action_id => l_transaction_action_id
24789 					      , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
24790 					      , p_status_id => NULL
24791 					      , p_inspection_status => NULL
24792 					      , x_object_id => l_object_id
24793 					      , x_return_status => x_return_status
24794 					      , x_msg_count => x_msg_count
24795 					      , x_msg_data => x_msg_data);
24796 
24797 					    IF (x_return_status <> g_ret_sts_success) THEN
24798 					       --raise error
24799 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24800 					       fnd_msg_pub.ADD;
24801 					       l_progress := 'WMSINB-25650';
24802 					       RAISE fnd_api.g_exc_error;
24803 					    END IF;
24804 
24805 					    --validate and update the attributes.
24806 					    inv_serial_number_pub.validate_update_serial_att
24807 					      (x_return_status     => x_return_status,
24808 					       x_msg_count         => x_msg_count,
24809 					       x_msg_data          => x_msg_data,
24810 					       x_validation_status => l_validation_status,
24811 					       p_serial_number     => l_serial_number,
24812 					       p_organization_id   => l_org_id,
24813 					       p_inventory_item_id => l_item_id,
24814 					       p_serial_att_tbl    => l_serial_attributes_tbl,
24815 					       p_validate_only     => FALSE
24816 					       );
24817 
24818 					    IF (l_validation_status <> 'Y'
24819 						OR x_return_status <> g_ret_sts_success) THEN
24820 					       --raise error
24821 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24822 					       fnd_msg_pub.ADD;
24823 					       l_progress := 'WMSINB-25691';
24824 					       RAISE fnd_api.g_exc_error;
24825 					    END IF;
24826 
24827 					    --UPDATE GROUP_MARK_ID TO -7937
24828 					    IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
24829 					       --raise error
24830 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24831 					       fnd_msg_pub.ADD;
24832 					       l_progress := 'WMSINB-25699';
24833 					       RAISE fnd_api.g_exc_error;
24834 					    END IF;
24835 					  ELSE --IF l_serial_number_control_code = 5 THEN
24836 					    --raise error
24837 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24838 					    fnd_msg_pub.ADD;
24839 					    l_progress := 'WMSINB-25706';
24840 					    RAISE fnd_api.g_exc_error;
24841 					 END IF; --IF l_serial_number_control_code = 5 THEN
24842 				      END IF; --IF (l_serial_exists = 1) THEN
24843 			     END IF; --IF (serial_entered_on_parent(l_great_grand_parent_txn_id)) THEN
24844 			   ELSE --ELSIF (l_parent_txn_type = g_rtr) THEN
24845 				IF (l_parent_txn_type <> 'DELIVER') THEN
24846 				   IF NOT (serial_entered_on_parent(l_parent_transaction_id)) THEN
24847 				      --raise an error
24848 				      l_progress := 'WMSINB-25715';
24849 				      RAISE fnd_api.g_exc_error;
24850 				    ELSE
24851 			               BEGIN
24852 					  SELECT '1'
24853 					    INTO L_DUMMY
24854 					    FROM RCV_SERIALS_SUPPLY
24855 					    WHERE TRANSACTION_ID = l_parent_transaction_id
24856 					    AND SERIAL_NUM = L_SERIAL_NUMBER;
24857 
24858 					  IF (l_curr_status <> 7) THEN
24859 					     --raise error
24860 					     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24861 					     fnd_msg_pub.ADD;
24862 					     l_progress := 'WMSINB-25729';
24863 					     RAISE fnd_api.g_exc_error;
24864 					  END IF;
24865 
24866 					  --Validate serial/group_mark_id to prevent
24867 					  --entering of duplicate serials
24868 
24869 					  IF (Nvl(l_group_mark_id, -99) = -7937) THEN
24870 					     --raise error
24871 					     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24872 					     fnd_msg_pub.ADD;
24873 					     l_progress := 'WMSINB-25740';
24874 					     RAISE fnd_api.g_exc_error;
24875 					  END IF;
24876 
24877 					  --UPDATE GROUP_MARK_ID TO -7937
24878 					  IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
24879 					     --raise error
24880 					     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24881 					     fnd_msg_pub.ADD;
24882 					     l_progress := 'WMSINB-25749';
24883 					     RAISE fnd_api.g_exc_error;
24884 					  END IF;
24885 				       EXCEPTION
24886 					  WHEN NO_DATA_FOUND THEN
24887 					     -- RAISE ERROR
24888 					     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24889 					     fnd_msg_pub.ADD;
24890 					     l_progress := 'WMSINB-25757';
24891 					     RAISE fnd_api.g_exc_error;
24892 				       END;
24893 				   END IF; --IF NOT (serial_entered_on_parent(l_parent_transaction_id)) THEN
24894 				 ELSE --IF (l_parent_txn_type <> 'DELIVER') THEN
24895 				      IF l_curr_org_id <> l_org_id THEN
24896 					 --raise error
24897 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24898 					 fnd_msg_pub.ADD;
24899 					 l_progress := 'WMSINB-25766';
24900 					 RAISE fnd_api.g_exc_error;
24901 				       ELSE
24902 					 IF ((l_curr_lot_num IS NOT NULL)
24903 					     AND (l_curr_lot_num <>
24904 						  l_mtlt_rec.lot_number)
24905 					     AND (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
24906 					    --raise error
24907 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24908 					    fnd_msg_pub.ADD;
24909 					    l_progress := 'WMSINB-25773';
24910 					    RAISE fnd_api.g_exc_error;
24911 					 END IF;
24912 				      END IF;
24913 
24914 				      IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
24915 					 IF l_curr_status NOT IN (1,6) THEN
24916 					    --raise error
24917 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24918 					    fnd_msg_pub.ADD;
24919 					    l_progress := 'WMSINB-25783';
24920 					    RAISE fnd_api.g_exc_error;
24921 					 END IF;
24922 				       ELSE --IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
24923 					 IF (l_curr_status <> 3) THEN
24924 					    --raise error
24925 					    fnd_message.set_name('INV','INV_FAIL_VALIDATE_SERIAL');
24926 					    fnd_msg_pub.ADD;
24927 					    l_progress := 'WMSINB-25791';
24928 					    RAISE fnd_api.g_exc_error;
24929 					 END IF;
24930 				      END IF; --IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
24931 
24932 				      IF (Nvl(l_group_mark_id, -99) = -7937) THEN
24933 					 --raise error
24934 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24935 					 fnd_msg_pub.ADD;
24936 					 l_progress := 'WMSINB-25800';
24937 					 RAISE fnd_api.g_exc_error;
24938 				      END IF;
24939 
24940 				      IF (Nvl(l_curr_status, 1) in (1,6)) THEN
24941 					 --validate and update the attributes.
24942 					 inv_serial_number_pub.validate_update_serial_att
24943 					   (x_return_status     => x_return_status,
24944 					    x_msg_count         => x_msg_count,
24945 					    x_msg_data          => x_msg_data,
24946 					    x_validation_status => l_validation_status,
24947 					    p_serial_number     => l_serial_number,
24948 					    p_organization_id   => l_org_id,
24949 					    p_inventory_item_id => l_item_id,
24950 					    p_serial_att_tbl    => l_serial_attributes_tbl,
24951 					    p_validate_only     => FALSE
24952 					    );
24953 
24954 					 IF (l_validation_status <> 'Y'
24955 					     OR x_return_status <> g_ret_sts_success) THEN
24956 					    --raise error
24957 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24958 					    fnd_msg_pub.ADD;
24959 					    l_progress := 'WMSINB-25805';
24960 					    RAISE fnd_api.g_exc_error;
24961 					 END IF;
24962 				      END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
24963 
24964 				      --UPDATE GROUP_MARK_ID TO -7937
24965 				      IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
24966 					 --raise error
24967 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24968 					 fnd_msg_pub.ADD;
24969 					 l_progress := 'WMSINB-25809';
24970 					 RAISE fnd_api.g_exc_error;
24971 				      END IF;
24972 				END IF; --IF (l_parent_txn_type <> 'DELIVER') THEN
24973 			  END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
24974 		       END LOOP; -- FOR 1..L_SERIAL_QUANTITY
24975 		    END LOOP; --FETCH C_MSNT_LOTSERIAL INTO L_MSNT_REC;
24976 
24977 		    CLOSE c_msnt_lotserial;
24978 
24979 		    IF (l_num_msnt_recs > 0) THEN
24980 		       IF l_mtlt_rec.primary_quantity <> l_tot_msnt_serial_qty THEN
24981 			  --raise error
24982 			  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24983 			  fnd_msg_pub.ADD;
24984 			  l_progress := 'WMSINB-25824';
24985 			  RAISE fnd_api.g_exc_error;
24986 		       END IF;
24987 		     ELSE
24988 		       IF (l_serial_number_control_code IN (2,5)
24989 			   OR (l_serial_number_control_code = 6
24990 			       AND l_source_document_code IN ('RMA','REQ','INVENTORY'))) THEN
24991 			  --raise error
24992 			  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
24993 			  fnd_msg_pub.ADD;
24994 			  l_progress := 'WMSINB-25831';
24995 			  RAISE fnd_api.g_exc_error;
24996 		       END IF;
24997 		    END IF;
24998 
24999 		 END IF; -- IF (L_SERIAL_NUMBER_CONTROL_CODE IN (2,5,6)) THEN
25000 	      END LOOP; --FETCH C_MTLT INTO L_MTLT_REC;
25001 
25002 	      CLOSE c_mtlt;
25003 
25004              /* Bug 4546519 : l_tot_mtlt_prim_qty is a computed floating point number.
25005               **  In the following condition, it is necessary to use round function for
25006               **  comparing the floating point values.
25007               */
25008 
25009 	      IF (l_num_mtlt_recs > 0) THEN
25010 		 IF (ROUND(l_tot_mtlt_prim_qty,5) <> ROUND(Abs(l_rti_primary_qty),5)) THEN
25011 			-- Bug# 4225766 Compare transaction qty there can be a difference in primary qty
25012 			-- if there is a lot specific conversion
25013 			IF (ROUND(l_tot_mtlt_trans_qty,5) <> ROUND(Abs(l_rti_trans_qty),5)) THEN -- Bug# 4225766
25014 				--raise error
25015 				fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25016 				fnd_msg_pub.ADD;
25017 				l_progress := 'WMSINB-25845';
25018 				RAISE fnd_api.g_exc_error;
25019 			END IF; -- Bug# 4225766
25020 		 END IF;
25021 	       ELSE
25022 		 IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
25023 		    IF (l_grand_parent_txn_type = 'DELIVER') THEN
25024 		       --raise an error
25025 		       l_progress := 'WMSINB-25852';
25026 		       RAISE fnd_api.g_exc_error;
25027 		     ELSE
25028 		       IF (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
25029 			  --raise error;
25030 			  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25031 			  fnd_msg_pub.ADD;
25032 			  l_progress := 'WMSINB-25859';
25033 			  RAISE fnd_api.g_exc_error;
25034 		       END IF;
25035 		    END IF; --IF (l_grand_parent_txn_type = 'DELIVER') THEN
25036 		  ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
25037 		    IF (l_parent_txn_type <> 'DELIVER') THEN
25038 		       IF (lot_entered_on_parent(l_parent_transaction_id)) THEN
25039 			  --raise an error
25040 			  l_progress := 'WMSINB-25867';
25041 			  RAISE fnd_api.g_exc_error;
25042 		       END IF;
25043 		     ELSE
25044 		       --raise an error
25045 		       l_progress := 'WMSINB-25872';
25046 		       RAISE fnd_api.g_exc_error;
25047 		    END IF; -- IF (l_parent_txn_type <> 'DELIVER') THEN
25048 		 END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
25049 	      END IF; --IF (l_num_mtlt_recs > 0) THEN
25050 	    ELSIF (l_serial_number_control_code IN (2,5,6)) THEN -- IF (l_lot_control_code = 2) THEN
25051 			     IF (l_debug = 1) THEN
25052 				print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROLLED: '||l_progress, 1);
25053 				print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROL CODE: '||l_serial_number_control_code||' : '||l_progress, 1);
25054 				print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||l_source_document_code||' : '||l_progress, 1);
25055 				l_progress := 'WMSINB-25882';
25056 			     END IF;
25057 
25058 			     L_NUM_MSNT_RECS := 0;
25059 			     l_tot_msnt_serial_qty := 0;
25060 
25061 			     OPEN C_MSNT(L_RTI_ID);
25062 
25063 			     LOOP
25064 				FETCH C_MSNT INTO L_MSNT_REC;
25065 
25066 				EXIT WHEN C_MSNT%NOTFOUND;
25067 
25068 				L_NUM_MSNT_RECS := L_NUM_MSNT_RECS + 1;
25069 
25070 				L_SERIAL_QUANTITY :=
25071 				  INV_SERIAL_NUMBER_PUB.GET_SERIAL_DIFF(L_MSNT_REC.FM_SERIAL_NUMBER,
25072 									L_MSNT_REC.TO_SERIAL_NUMBER);
25073 
25074 				l_tot_msnt_serial_qty := l_tot_msnt_serial_qty + l_serial_quantity;
25075 
25076 				INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.FM_SERIAL_NUMBER, L_TEMP_PREFIX, L_FROM_SER_NUMBER);
25077 		                INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.TO_SERIAL_NUMBER, L_TEMP_PREFIX, L_TO_SER_NUMBER);
25078 
25079 				IF (l_debug = 1) THEN
25080 				   print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL QUANTITY: '||l_serial_quantity||' : '||l_progress, 1);
25081 				   l_progress := 'WMSINB-25907';
25082 				END IF;
25083 
25084 				--populate attributes table
25085 				l_serial_attributes_tbl(1).column_name   := 'SERIAL_ATTRIBUTE_CATEGORY';
25086 				l_serial_attributes_tbl(1).column_value  := l_msnt_rec.serial_attribute_category;
25087 				l_serial_attributes_tbl(2).column_name   := 'ORIGINATION_DATE';
25088 				l_serial_attributes_tbl(2).column_value  := l_msnt_rec.origination_date;
25089 				l_serial_attributes_tbl(3).column_name   := 'C_ATTRIBUTE1';
25090 				l_serial_attributes_tbl(3).column_value  := l_msnt_rec.c_attribute1;
25091 				l_serial_attributes_tbl(4).column_name   := 'C_ATTRIBUTE2';
25092 				l_serial_attributes_tbl(4).column_value  := l_msnt_rec.c_attribute2;
25093 				l_serial_attributes_tbl(5).column_name   := 'C_ATTRIBUTE3';
25094 				l_serial_attributes_tbl(5).column_value  := l_msnt_rec.c_attribute3;
25095 				l_serial_attributes_tbl(6).column_name   := 'C_ATTRIBUTE4';
25096 				l_serial_attributes_tbl(6).column_value   := l_msnt_rec.c_attribute4;
25097 				l_serial_attributes_tbl(7).column_name   := 'C_ATTRIBUTE5';
25098 				l_serial_attributes_tbl(7).column_value   := l_msnt_rec.c_attribute5;
25099 				l_serial_attributes_tbl(8).column_name   := 'C_ATTRIBUTE6';
25100 				l_serial_attributes_tbl(8).column_value   := l_msnt_rec.c_attribute6;
25101 				l_serial_attributes_tbl(9).column_name   := 'C_ATTRIBUTE7';
25102 				l_serial_attributes_tbl(9).column_value   := l_msnt_rec.c_attribute7;
25103 				l_serial_attributes_tbl(10).column_name  := 'C_ATTRIBUTE8';
25104 				l_serial_attributes_tbl(10).column_value  := l_msnt_rec.c_attribute8;
25105 				l_serial_attributes_tbl(11).column_name  := 'C_ATTRIBUTE9';
25106 				l_serial_attributes_tbl(11).column_value  := l_msnt_rec.c_attribute9;
25107 				l_serial_attributes_tbl(12).column_name  := 'C_ATTRIBUTE10';
25108 				l_serial_attributes_tbl(12).column_value  := l_msnt_rec.c_attribute10;
25109 				l_serial_attributes_tbl(13).column_name  := 'C_ATTRIBUTE11';
25110 				l_serial_attributes_tbl(13).column_value  := l_msnt_rec.c_attribute11;
25111 				l_serial_attributes_tbl(14).column_name  := 'C_ATTRIBUTE12';
25112 				l_serial_attributes_tbl(14).column_value  := l_msnt_rec.c_attribute12;
25113 				l_serial_attributes_tbl(15).column_name  := 'C_ATTRIBUTE13';
25114 				l_serial_attributes_tbl(15).column_value  := l_msnt_rec.c_attribute13;
25115 				l_serial_attributes_tbl(16).column_name  := 'C_ATTRIBUTE14';
25116 				l_serial_attributes_tbl(16).column_value  := l_msnt_rec.c_attribute14;
25117 				l_serial_attributes_tbl(17).column_name  := 'C_ATTRIBUTE15';
25118 				l_serial_attributes_tbl(17).column_value  := l_msnt_rec.c_attribute15;
25119 				l_serial_attributes_tbl(18).column_name  := 'C_ATTRIBUTE16';
25120 				l_serial_attributes_tbl(18).column_value  := l_msnt_rec.c_attribute16;
25121 				l_serial_attributes_tbl(19).column_name  := 'C_ATTRIBUTE17';
25122 				l_serial_attributes_tbl(19).column_value  := l_msnt_rec.c_attribute17;
25123 				l_serial_attributes_tbl(20).column_name  := 'C_ATTRIBUTE18';
25124 				l_serial_attributes_tbl(20).column_value  := l_msnt_rec.c_attribute18;
25125 				l_serial_attributes_tbl(21).column_name  := 'C_ATTRIBUTE19';
25126 				l_serial_attributes_tbl(21).column_value  := l_msnt_rec.c_attribute19;
25127 				l_serial_attributes_tbl(22).column_name  := 'C_ATTRIBUTE20';
25128 				l_serial_attributes_tbl(22).column_value  := l_msnt_rec.c_attribute20;
25129 				l_serial_attributes_tbl(23).column_name  := 'D_ATTRIBUTE1';
25130 				l_serial_attributes_tbl(23).column_value  := l_msnt_rec.d_attribute1;
25131 				l_serial_attributes_tbl(24).column_name  := 'D_ATTRIBUTE2';
25132 				l_serial_attributes_tbl(24).column_value  := l_msnt_rec.d_attribute2;
25133 				l_serial_attributes_tbl(25).column_name  := 'D_ATTRIBUTE3';
25134 				l_serial_attributes_tbl(25).column_value  := l_msnt_rec.d_attribute3;
25135 				l_serial_attributes_tbl(26).column_name  := 'D_ATTRIBUTE4';
25136 				l_serial_attributes_tbl(26).column_value  := l_msnt_rec.d_attribute4;
25137 				l_serial_attributes_tbl(27).column_name  := 'D_ATTRIBUTE5';
25138 				l_serial_attributes_tbl(27).column_value  := l_msnt_rec.d_attribute5;
25139 				l_serial_attributes_tbl(28).column_name  := 'D_ATTRIBUTE6';
25140 				l_serial_attributes_tbl(28).column_value  := l_msnt_rec.d_attribute6;
25141 				l_serial_attributes_tbl(29).column_name  := 'D_ATTRIBUTE7';
25142 				l_serial_attributes_tbl(29).column_value  := l_msnt_rec.d_attribute7;
25143 				l_serial_attributes_tbl(30).column_name  := 'D_ATTRIBUTE8';
25144 				l_serial_attributes_tbl(30).column_value  := l_msnt_rec.d_attribute8;
25145 				l_serial_attributes_tbl(31).column_name  := 'D_ATTRIBUTE9';
25146 				l_serial_attributes_tbl(31).column_value  := l_msnt_rec.d_attribute9;
25147 				l_serial_attributes_tbl(32).column_name  := 'D_ATTRIBUTE10';
25148 				l_serial_attributes_tbl(32).column_value  := l_msnt_rec.d_attribute10;
25149 				l_serial_attributes_tbl(33).column_name  := 'N_ATTRIBUTE1';
25150 				l_serial_attributes_tbl(33).column_value  := l_msnt_rec.n_attribute1;
25151 				l_serial_attributes_tbl(34).column_name  := 'N_ATTRIBUTE2';
25152 				l_serial_attributes_tbl(34).column_value  := l_msnt_rec.n_attribute2;
25153 				l_serial_attributes_tbl(35).column_name  := 'N_ATTRIBUTE3';
25154 				l_serial_attributes_tbl(35).column_value  := l_msnt_rec.n_attribute3;
25155 				l_serial_attributes_tbl(36).column_name  := 'N_ATTRIBUTE4';
25156 				l_serial_attributes_tbl(36).column_value  := l_msnt_rec.n_attribute4;
25157 				l_serial_attributes_tbl(37).column_name  := 'N_ATTRIBUTE5';
25158 				l_serial_attributes_tbl(37).column_value := l_msnt_rec.n_attribute5;
25159 				l_serial_attributes_tbl(38).column_name  := 'N_ATTRIBUTE6';
25160 				l_serial_attributes_tbl(38).column_value := l_msnt_rec.n_attribute6;
25161 				l_serial_attributes_tbl(39).column_name  := 'N_ATTRIBUTE7';
25162 				l_serial_attributes_tbl(39).column_value := l_msnt_rec.n_attribute7;
25163 				l_serial_attributes_tbl(40).column_name  := 'N_ATTRIBUTE8';
25164 				l_serial_attributes_tbl(40).column_value := l_msnt_rec.n_attribute8;
25165 				l_serial_attributes_tbl(41).column_name  := 'N_ATTRIBUTE9';
25166 				l_serial_attributes_tbl(41).column_value := l_msnt_rec.n_attribute9;
25167 				l_serial_attributes_tbl(42).column_name  := 'N_ATTRIBUTE10';
25168 				l_serial_attributes_tbl(42).column_value := l_msnt_rec.n_attribute10;
25169 				l_serial_attributes_tbl(43).column_name  := 'STATUS_ID';
25170 				l_serial_attributes_tbl(43).column_value := l_msnt_rec.status_id;
25171 				l_serial_attributes_tbl(44).column_name  := 'TERRITORY_CODE';
25172 				l_serial_attributes_tbl(44).column_value := l_msnt_rec.territory_code;
25173 
25174 				--Validate the serials
25175 				FOR SERIALQTY IN 1..L_SERIAL_QUANTITY LOOP
25176 
25177 				   l_progress := 'WMSINB-25913';
25178 
25179                                    L_CUR_NUMBER := L_FROM_SER_NUMBER+SERIALQTY -1;
25180                                    if L_FROM_SER_NUMBER = -1 and  L_TO_SER_NUMBER = -1 then
25181 	                                L_SERIAL_NUMBER  := L_MSNT_REC.fm_serial_number;
25182 		                   else
25183 		                        L_SERIAL_NUMBER :=
25184 			                  SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
25185 				            LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
25186 				            LENGTH(L_CUR_NUMBER))
25187 			                  ||L_CUR_NUMBER;
25188                                    End if;
25189 
25190 				   --L_SERIAL_NUMBER :=
25191 				     --SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
25192 					    --LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
25193 					    --LENGTH(L_FROM_SER_NUMBER))
25194 				     --||(L_FROM_SER_NUMBER+SERIALQTY -1);
25195 
25196 				   l_progress := 'WMSINB-25921';
25197 
25198 		                   BEGIN
25199 				      SELECT CURRENT_ORGANIZATION_ID
25200 					, current_status
25201 					, lot_number
25202 					, Decode(lpn_id,0,NULL,lpn_id)
25203 					, inspection_status
25204 					, group_mark_id
25205 					INTO L_CURR_ORG_ID
25206 					, l_curr_status
25207 					, l_curr_lot_num
25208 					, l_curr_lpn_id
25209 					, l_inspection_status
25210 					, l_group_mark_id
25211 					FROM MTL_SERIAL_NUMBERS
25212 					WHERE SERIAL_NUMBER = l_serial_number
25213 					AND inventory_item_id = l_item_id;
25214 
25215 				      l_serial_exists := 1;
25216 				      l_progress := 'WMSINB-25941';
25217 				   EXCEPTION
25218 				      WHEN no_data_found THEN
25219 					 l_serial_exists := 0;
25220 					 l_progress := 'WMSINB-25945';
25221 				   END;
25222 
25223 				   IF (l_debug = 1) THEN
25224 				      print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL EXISTS: '||l_serial_exists||' : '||l_progress, 1);
25225 				      print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NUMBER: '||l_serial_number||' : '||l_progress, 1);
25226 				      print_debug('VALIDATE_LOT_SERIAL_INFO: CURR STATUS: '||l_curr_status||' : '||l_progress, 1);
25227 				      print_debug('VALIDATE_LOT_SERIAL_INFO: CURR ORG ID: '||l_curr_org_id||' : '||l_progress, 1);
25228 				      print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LPN ID: '||l_curr_lpn_id||' : '||l_progress, 1);
25229 				      print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LOT NUM: '||l_curr_lot_num||' : '||l_progress, 1);
25230 				      print_debug('VALIDATE_LOT_SERIAL_INFO: INSPECT STS: '||l_inspection_status||' : '||l_progress, 1);
25231 				      print_debug('VALIDATE_LOT_SERIAL_INFO: GROUP MARK ID: '||l_group_mark_id||' : '||l_progress, 1);
25232 				      print_debug('VALIDATE_LOT_SERIAL_INFO: RESTRICT RCPT SER: '||l_restrict_rcpt_ser||' : '||l_progress, 1);
25233 				      l_progress := 'WMSINB-25958';
25234 				   END IF;
25235 
25236 				   IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
25237 				      IF (l_grand_parent_txn_type <> 'DELIVER') THEN
25238 					 IF NOT (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
25239 					    --raise an error
25240 					    l_progress := 'WMSINB-25965';
25241 					    RAISE fnd_api.g_exc_error;
25242 					 END IF;
25243 				      END IF; --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
25244 
25245 				      IF (l_serial_exists = 1) THEN
25246 					 IF l_curr_org_id <> l_org_id THEN
25247 					    --raise error
25248 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25249 					    fnd_msg_pub.ADD;
25250 					    l_progress := 'WMSINB-25975';
25251 					    RAISE fnd_api.g_exc_error;
25252 					  ELSE
25253 					    IF (l_curr_lot_num IS NOT NULL) THEN
25254 					       --raise error
25255 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25256 					       fnd_msg_pub.ADD;
25257 					       l_progress := 'WMSINB-25982';
25258 					       RAISE fnd_api.g_exc_error;
25259 					    END IF;
25260 					 END IF;
25261 
25262 					 IF l_curr_status NOT IN (1,6) THEN
25263 					    --raise error
25264 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25265 					    fnd_msg_pub.ADD;
25266 					    l_progress := 'WMSINB-25991';
25267 					    RAISE fnd_api.g_exc_error;
25268 					 END IF;
25269 
25270 					 IF (Nvl(l_group_mark_id, -99) = -7937) THEN
25271 					    --raise error
25272 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25273 					    fnd_msg_pub.ADD;
25274 					    l_progress := 'WMSINB-25999';
25275 					    RAISE fnd_api.g_exc_error;
25276 					 END IF;
25277 
25278 				IF (Nvl(l_curr_status, 1) in (1,6)) THEN
25279 				   --validate and update the attributes.
25280 				   inv_serial_number_pub.validate_update_serial_att
25281 				     (x_return_status     => x_return_status,
25282 				      x_msg_count         => x_msg_count,
25283 				      x_msg_data          => x_msg_data,
25284 				      x_validation_status => l_validation_status,
25285 				      p_serial_number     => l_serial_number,
25286 				      p_organization_id   => l_org_id,
25287 				      p_inventory_item_id => l_item_id,
25288 				      p_serial_att_tbl    => l_serial_attributes_tbl,
25289 				      p_validate_only     => FALSE
25290 				      );
25291 
25292 				   IF (l_validation_status <> 'Y'
25293 				       OR x_return_status <> g_ret_sts_success) THEN
25294 				      --raise error
25295 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25296 				      fnd_msg_pub.ADD;
25297 				      l_progress := 'WMSINB-26005';
25298 				      RAISE fnd_api.g_exc_error;
25299 				   END IF;
25300 				END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
25301 
25302 					 --UPDATE GROUP_MARK_ID TO -7937
25303 					 IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
25304 					    --raise error
25305 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25306 					    fnd_msg_pub.ADD;
25307 					    l_progress := 'WMSINB-26008';
25308 					    RAISE fnd_api.g_exc_error;
25309 					 END IF;
25310 				       ELSE --IF (l_serial_exists = 1) THEN
25311 					 IF l_serial_number_control_code = 5 THEN
25312 					    --PERFORM SERIAL VALIDATION FOR NEW SERIAL
25313 					    --(INCLUDING ATT VALIDATION)
25314 					    --CREATE MSN
25315 					    IF (l_transaction_type = 'CORRECT') THEN
25316 					       l_transaction_action_id := 29;
25317 					     ELSE
25318 					       l_transaction_action_id := 1;
25319 					    END IF;
25320 
25321 					    inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
25322 										      , p_inventory_item_id => l_item_id
25323 										      , p_organization_id => l_org_id
25324 										      , p_from_serial_number => l_serial_number
25325 										      , p_to_serial_number => l_serial_number
25326 										      , p_initialization_date => SYSDATE
25327 										      , p_completion_date => NULL
25328 										      , p_ship_date => NULL
25329 										      , p_revision => l_item_revision
25330 										      , p_lot_number => NULL
25331 										      , p_current_locator_id => l_loc_id
25332 										      , p_subinventory_code => l_sub_code
25333 										      , p_trx_src_id => NULL
25334 										      , p_unit_vendor_id => NULL
25335 										      , p_vendor_lot_number => NULL
25336 										      , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
25337 										      , p_receipt_issue_type => NULL
25338 										      , p_txn_src_id => NULL
25339 										      , p_txn_src_name => NULL
25340 										      , p_txn_src_type_id => NULL
25341 										      , p_transaction_id => NULL
25342 										      , p_current_status => 1
25343 					      , p_parent_item_id => NULL
25344 					      , p_parent_serial_number => NULL
25345 					      , p_cost_group_id => NULL
25346 					      , p_transaction_action_id => l_transaction_action_id
25347 					      , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
25348 					      , p_status_id => NULL
25349 					      , p_inspection_status => NULL
25350 					      , x_object_id => l_object_id
25351 					      , x_return_status => x_return_status
25352 					      , x_msg_count => x_msg_count
25353 					      , x_msg_data => x_msg_data);
25354 
25355 					    IF (x_return_status <> g_ret_sts_success) THEN
25356 					       --raise error
25357 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25358 					       fnd_msg_pub.ADD;
25359 					       l_progress := 'WMSINB-26015';
25360 					       RAISE fnd_api.g_exc_error;
25361 					    END IF;
25362 
25363 					    --validate and update the attributes.
25364 					    inv_serial_number_pub.validate_update_serial_att
25365 					      (x_return_status     => x_return_status,
25366 					       x_msg_count         => x_msg_count,
25367 					       x_msg_data          => x_msg_data,
25368 					       x_validation_status => l_validation_status,
25369 					       p_serial_number     => l_serial_number,
25370 					       p_organization_id   => l_org_id,
25371 					       p_inventory_item_id => l_item_id,
25372 					       p_serial_att_tbl    => l_serial_attributes_tbl,
25373 					       p_validate_only     => FALSE
25374 					       );
25375 
25376 					    IF (l_validation_status <> 'Y'
25377 						OR x_return_status <> g_ret_sts_success) THEN
25378 					       --raise error
25379 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25380 					       fnd_msg_pub.ADD;
25381 					       l_progress := 'WMSINB-29051';
25382 					       RAISE fnd_api.g_exc_error;
25383 					    END IF;
25384 
25385 					    --UPDATE GROUP_MARK_ID TO -7937
25386 					    IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
25387 					       --raise error
25388 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25389 					       fnd_msg_pub.ADD;
25390 					       l_progress := 'WMSINB-26061';
25391 					       RAISE fnd_api.g_exc_error;
25392 					    END IF;
25393 					  ELSE --IF l_serial_number_control_code = 5 THEN
25394 					    --raise error
25395 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25396 					    fnd_msg_pub.ADD;
25397 					    l_progress := 'WMSINB-26068';
25398 					    RAISE fnd_api.g_exc_error;
25399 					 END IF; --IF l_serial_number_control_code = 5 THEN
25400 				      END IF; --IF (l_serial_exists = 1) THEN
25401 				    ELSIF (l_parent_txn_type = g_rtr) THEN --IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
25402 				      IF (serial_entered_on_parent(l_great_grand_parent_txn_id)) THEN
25403 				         BEGIN
25404 					    SELECT '1'
25405 					      INTO L_DUMMY
25406 					      FROM RCV_SERIALS_SUPPLY
25407 					      WHERE TRANSACTION_ID = l_great_grand_parent_txn_id
25408 					      AND SERIAL_NUM = L_SERIAL_NUMBER;
25409 
25410 					    IF (l_curr_status <> 7) THEN
25411 					       --raise error
25412 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25413 					       fnd_msg_pub.ADD;
25414 					       l_progress := 'WMSINB-26085';
25415 					       RAISE fnd_api.g_exc_error;
25416 					    END IF;
25417 
25418 					    --Validate serial/group_mark_id to prevent
25419 					    --entering of duplicate serials
25420 
25421 					    IF (Nvl(l_group_mark_id, -99) = -7937) THEN
25422 					       --raise error
25423 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25424 					       fnd_msg_pub.ADD;
25425 					       l_progress := 'WMSINB-26096';
25426 					       RAISE fnd_api.g_exc_error;
25427 					    END IF;
25428 
25429 					    --UPDATE GROUP_MARK_ID TO -7937
25430 					    IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
25431 					       --raise error
25432 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25433 					       fnd_msg_pub.ADD;
25434 					       l_progress := 'WMSINB-26105';
25435 					       RAISE fnd_api.g_exc_error;
25436 					    END IF;
25437 					 EXCEPTION
25438 					    WHEN NO_DATA_FOUND THEN
25439 					       -- RAISE ERROR
25440 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25441 					       fnd_msg_pub.ADD;
25442 					       l_progress := 'WMSINB-26113';
25443 					       RAISE fnd_api.g_exc_error;
25444 					 END;
25445 				       ELSE --IF (serial_entered_on_parent(l_great_grand_parent_txn_id)) THEN
25446 					       IF (l_serial_exists = 1) THEN
25447 						  IF l_curr_org_id <> l_org_id THEN
25448 						     --raise error
25449 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25450 						     fnd_msg_pub.ADD;
25451 						     l_progress := 'WMSINB-26122';
25452 						     RAISE fnd_api.g_exc_error;
25453 						   ELSE
25454 						     IF (l_curr_lot_num IS NOT NULL) THEN
25455 							--raise error
25456 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25457 							fnd_msg_pub.ADD;
25458 							l_progress := 'WMSINB-26129';
25459 							RAISE fnd_api.g_exc_error;
25460 						     END IF;
25461 						  END IF;
25462 
25463 						  IF l_curr_status NOT IN (1,6) THEN
25464 						     --raise error
25465 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25466 						     fnd_msg_pub.ADD;
25467 						     l_progress := 'WMSINB-26138';
25468 						     RAISE fnd_api.g_exc_error;
25469 						  END IF;
25470 
25471 						  IF (Nvl(l_group_mark_id, -99) = -7937) THEN
25472 						     --raise error
25473 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25474 						     fnd_msg_pub.ADD;
25475 						     l_progress := 'WMSINB-26146';
25476 						     RAISE fnd_api.g_exc_error;
25477 						  END IF;
25478 
25479 				IF (Nvl(l_curr_status, 1) in (1,6)) THEN
25480 				   --validate and update the attributes.
25481 				   inv_serial_number_pub.validate_update_serial_att
25482 				     (x_return_status     => x_return_status,
25483 				      x_msg_count         => x_msg_count,
25484 				      x_msg_data          => x_msg_data,
25485 				      x_validation_status => l_validation_status,
25486 				      p_serial_number     => l_serial_number,
25487 				      p_organization_id   => l_org_id,
25488 				      p_inventory_item_id => l_item_id,
25489 				      p_serial_att_tbl    => l_serial_attributes_tbl,
25490 				      p_validate_only     => FALSE
25491 				      );
25492 
25493 				   IF (l_validation_status <> 'Y'
25494 				       OR x_return_status <> g_ret_sts_success) THEN
25495 				      --raise error
25496 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25497 				      fnd_msg_pub.ADD;
25498 				      l_progress := 'WMSINB-26152';
25499 				      RAISE fnd_api.g_exc_error;
25500 				   END IF;
25501 				END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
25502 
25503 						  --UPDATE GROUP_MARK_ID TO -7937
25504 						  IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
25505 						     --raise error
25506 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25507 						     fnd_msg_pub.ADD;
25508 						     l_progress := 'WMSINB-26155';
25509 						     RAISE fnd_api.g_exc_error;
25510 						  END IF;
25511 						ELSE --IF (l_serial_exists = 1) THEN
25512 						  IF l_serial_number_control_code = 5 THEN
25513 						     --PERFORM SERIAL VALIDATION FOR NEW SERIAL
25514 						     --(INCLUDING ATT VALIDATION)
25515 						     --CREATE MSN
25516 						     IF (l_transaction_type = 'CORRECT') THEN
25517 							l_transaction_action_id := 29;
25518 						      ELSE
25519 							l_transaction_action_id := 1;
25520 						     END IF;
25521 
25522 						     inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
25523 											       , p_inventory_item_id => l_item_id
25524 											       , p_organization_id => l_org_id
25525 											       , p_from_serial_number => l_serial_number
25526 											       , p_to_serial_number => l_serial_number
25527 											       , p_initialization_date => SYSDATE
25528 											       , p_completion_date => NULL
25529 											       , p_ship_date => NULL
25530 											       , p_revision => l_item_revision
25531 											       , p_lot_number => NULL
25532 											       , p_current_locator_id => l_loc_id
25533 											       , p_subinventory_code => l_sub_code
25534 											       , p_trx_src_id => NULL
25535 											       , p_unit_vendor_id => NULL
25536 											       , p_vendor_lot_number => NULL
25537 											       , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
25538 											       , p_receipt_issue_type => NULL
25539 											       , p_txn_src_id => NULL
25540 											       , p_txn_src_name => NULL
25541 											       , p_txn_src_type_id => NULL
25542 											       , p_transaction_id => NULL
25543 						       , p_current_status => 1
25544 						       , p_parent_item_id => NULL
25545 						       , p_parent_serial_number => NULL
25546 						       , p_cost_group_id => NULL
25547 						       , p_transaction_action_id => l_transaction_action_id
25548 						       , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
25549 						       , p_status_id => NULL
25550 						       , p_inspection_status => NULL
25551 						       , x_object_id => l_object_id
25552 						       , x_return_status => x_return_status
25553 						       , x_msg_count => x_msg_count
25554 						       , x_msg_data => x_msg_data);
25555 
25556 						     IF (x_return_status <> g_ret_sts_success) THEN
25557 							--raise error
25558 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25559 							fnd_msg_pub.ADD;
25560 							l_progress := 'WMSINB-26160';
25561 							RAISE fnd_api.g_exc_error;
25562 						     END IF;
25563 
25564 						     --validate and update the attributes.
25565 						     inv_serial_number_pub.validate_update_serial_att
25566 						       (x_return_status     => x_return_status,
25567 							x_msg_count         => x_msg_count,
25568 							x_msg_data          => x_msg_data,
25569 							x_validation_status => l_validation_status,
25570 							p_serial_number     => l_serial_number,
25571 							p_organization_id   => l_org_id,
25572 							p_inventory_item_id => l_item_id,
25573 							p_serial_att_tbl    => l_serial_attributes_tbl,
25574 							p_validate_only     => FALSE
25575 							);
25576 
25577 						     IF (l_validation_status <> 'Y'
25578 							 OR x_return_status <> g_ret_sts_success) THEN
25579 							--raise error
25580 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25581 							fnd_msg_pub.ADD;
25582 							l_progress := 'WMSINB-26200';
25583 							RAISE fnd_api.g_exc_error;
25584 						     END IF;
25585 
25586 						     --UPDATE GROUP_MARK_ID TO -7937
25587 						     IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
25588 							--raise error
25589 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25590 							fnd_msg_pub.ADD;
25591 							l_progress := 'WMSINB-26208';
25592 							RAISE fnd_api.g_exc_error;
25593 						     END IF;
25594 						   ELSE --IF l_serial_number_control_code = 5 THEN
25595 						     --raise error
25596 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25597 						     fnd_msg_pub.ADD;
25598 						     l_progress := 'WMSINB-26215';
25599 						     RAISE fnd_api.g_exc_error;
25600 						  END IF; --IF l_serial_number_control_code = 5 THEN
25601 					       END IF; --IF (l_serial_exists = 1) THEN
25602 				      END IF; --IF (serial_entered_on_parent(l_great_grand_parent_txn_id)) THEN
25603 				    ELSE --ELSIF (l_parent_txn_type = g_rtr) THEN
25604 					 IF (l_parent_txn_type <> 'DELIVER') THEN
25605 					    IF NOT (serial_entered_on_parent(l_parent_transaction_id)) THEN
25606 					       --raise an error
25607 					       l_progress := 'WMSINB-26224';
25608 					       RAISE fnd_api.g_exc_error;
25609 					     ELSE
25610 					        BEGIN
25611 						   SELECT '1'
25612 						     INTO L_DUMMY
25613 						     FROM RCV_SERIALS_SUPPLY
25614 						     WHERE TRANSACTION_ID = l_parent_transaction_id
25615 						     AND SERIAL_NUM = L_SERIAL_NUMBER;
25616 
25617 						   IF (l_curr_status <> 7) THEN
25618 						      --raise error
25619 						      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25620 						      fnd_msg_pub.ADD;
25621 						      l_progress := 'WMSINB-26238';
25622 						      RAISE fnd_api.g_exc_error;
25623 						   END IF;
25624 
25625 						   --Validate serial/group_mark_id to prevent
25626 						   --entering of duplicate serials
25627 
25628 						   IF (Nvl(l_group_mark_id, -99) = -7937) THEN
25629 						      --raise error
25630 						      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25631 						      fnd_msg_pub.ADD;
25632 						      l_progress := 'WMSINB-26249';
25633 						      RAISE fnd_api.g_exc_error;
25634 						   END IF;
25635 
25636 						   --UPDATE GROUP_MARK_ID TO -7937
25637 						   IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
25638 						      --raise error
25639 						      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25640 						      fnd_msg_pub.ADD;
25641 						      l_progress := 'WMSINB-26258';
25642 						      RAISE fnd_api.g_exc_error;
25643 						   END IF;
25644 						EXCEPTION
25645 						   WHEN NO_DATA_FOUND THEN
25646 						      -- RAISE ERROR
25647 						      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25648 						      fnd_msg_pub.ADD;
25649 						      l_progress := 'WMSINB-26266';
25650 						      RAISE fnd_api.g_exc_error;
25651 						END;
25652 					    END IF; --IF NOT (serial_entered_on_parent(l_parent_transaction_id)) THEN
25653 					  ELSE --IF (l_parent_txn_type <> 'DELIVER') THEN
25654 					       IF l_curr_org_id <> l_org_id THEN
25655 						  --raise error
25656 						  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25657 						  fnd_msg_pub.ADD;
25658 						  l_progress := 'WMSINB-26275';
25659 						  RAISE fnd_api.g_exc_error;
25660 						ELSE
25661 						  IF (l_curr_lot_num IS NOT NULL) THEN
25662 						     --raise error
25663 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25664 						     fnd_msg_pub.ADD;
25665 						     l_progress := 'WMSINB-26282';
25666 						     RAISE fnd_api.g_exc_error;
25667 						  END IF;
25668 					       END IF;
25669 
25670 					       IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
25671 						  IF l_curr_status NOT IN (1,6) THEN
25672 						     --raise error
25673 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25674 						     fnd_msg_pub.ADD;
25675 						     l_progress := 'WMSINB-26292';
25676 						     RAISE fnd_api.g_exc_error;
25677 						  END IF;
25678 						ELSE --IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
25679 						  IF (l_curr_status <> 3) THEN
25680 						     --raise error
25681 						     fnd_message.set_name('INV','INV_FAIL_VALIDATE_SERIAL');
25682 						     fnd_msg_pub.ADD;
25683 						     l_progress := 'WMSINB-26300';
25684 						     RAISE fnd_api.g_exc_error;
25685 						  END IF;
25686 					       END IF; --IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
25687 
25688 					       IF (Nvl(l_group_mark_id, -99) = -7937) THEN
25689 						  --raise error
25690 						  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25691 						  fnd_msg_pub.ADD;
25692 						  l_progress := 'WMSINB-26309';
25693 						  RAISE fnd_api.g_exc_error;
25694 					       END IF;
25695 
25696 				IF (Nvl(l_curr_status, 1) in (1,6)) THEN
25697 				   --validate and update the attributes.
25698 				   inv_serial_number_pub.validate_update_serial_att
25699 				     (x_return_status     => x_return_status,
25700 				      x_msg_count         => x_msg_count,
25701 				      x_msg_data          => x_msg_data,
25702 				      x_validation_status => l_validation_status,
25703 				      p_serial_number     => l_serial_number,
25704 				      p_organization_id   => l_org_id,
25705 				      p_inventory_item_id => l_item_id,
25706 				      p_serial_att_tbl    => l_serial_attributes_tbl,
25707 				      p_validate_only     => FALSE
25708 				      );
25709 
25710 				   IF (l_validation_status <> 'Y'
25711 				       OR x_return_status <> g_ret_sts_success) THEN
25712 				      --raise error
25713 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25714 				      fnd_msg_pub.ADD;
25715 				      l_progress := 'WMSINB-26315';
25716 				      RAISE fnd_api.g_exc_error;
25717 				   END IF;
25718 				END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
25719 
25720 					       --UPDATE GROUP_MARK_ID TO -7937
25721 					       IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
25722 						  --raise error
25723 						  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25724 						  fnd_msg_pub.ADD;
25725 						  l_progress := 'WMSINB-26318';
25726 						  RAISE fnd_api.g_exc_error;
25727 					       END IF;
25728 					 END IF; --IF (l_parent_txn_type <> 'DELIVER') THEN
25729 				   END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
25730 				END LOOP; -- FOR 1..L_SERIAL_QUANTITY
25731 			     END LOOP; --FETCH C_MSNT INTO L_MSNT_REC;
25732 
25733 			     CLOSE c_msnt;
25734 
25735 			     IF (l_num_msnt_recs > 0) THEN
25736 				IF Abs(l_rti_primary_qty) <> l_tot_msnt_serial_qty THEN
25737 				   --raise error
25738 				   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25739 				   fnd_msg_pub.ADD;
25740 				   l_progress := 'WMSINB-26333';
25741 				   RAISE fnd_api.g_exc_error;
25742 				END IF;
25743 			      ELSE
25744 				IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
25745 				   IF (l_grand_parent_txn_type = 'DELIVER') THEN
25746 				      --raise an error
25747 				      l_progress := 'WMSINB-26340';
25748 				      RAISE fnd_api.g_exc_error;
25749 				    ELSE --IF (l_grand_parent_txn_type = 'DELIVER') THEN
25750 				      IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
25751 					 --raise on error
25752 					 l_progress := 'WMSINB-26345';
25753 					 RAISE fnd_api.g_exc_error;
25754 				      END IF;
25755 				   END IF; --IF (l_grand_parent_txn_type = 'DELIVER') THEN
25756 				 ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
25757 				   IF (l_parent_txn_type = 'DELIVER') THEN
25758 				      IF (l_serial_number_control_code IN (2,5)
25759 					  OR (l_serial_number_control_code = 6
25760 					      AND l_source_document_code = 'RMA')) THEN
25761 					 --raise an error
25762 					 l_progress := 'WMSINB-26352';
25763 					 RAISE fnd_api.g_exc_error;
25764 				      END IF;
25765 				    ELSE
25766 				      IF (serial_entered_on_parent(l_parent_transaction_id)) THEN
25767 					 --raise an error
25768 					 l_progress := 'WMSINB-26357';
25769 					 RAISE fnd_api.g_exc_error;
25770 				      END IF;
25771 				   END IF; --IF (l_parent_txn_type = 'DELIVER') THEN
25772 				END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
25773 			     END IF; --IF (l_num_msnt_recs > 0) THEN
25774 	   END IF; --IF (l_lot_control_code = 2) THEN
25775 	 ELSIF (l_transaction_type = 'CORRECT' AND l_rti_primary_qty > 0) THEN
25776 	                              -- opm change bug# 3061052 added l_opm_lot_ctl check
25777 
25778            /*INVCONV , Remove OPM specific l_opm_lot_ctl check , Punit Kumar*/
25779 
25780 				      IF (l_lot_control_code = 2 /* or l_opm_lot_ctl=1 */) THEN
25781 					 IF (l_debug = 1) THEN
25782 					    print_debug('VALIDATE_LOT_SERIAL_INFO: Lot Controlled :'||l_progress, 1);
25783 					    l_progress := 'WMSINB-26368';
25784 					 END IF;
25785 
25786 					 l_num_mtlt_recs := 0;
25787 					 l_tot_mtlt_prim_qty := 0;
25788 					 l_tot_mtlt_trans_qty := 0; -- Bug# 4225766
25789 
25790 					 OPEN C_MTLT(L_RTI_ID);
25791 
25792 					 LOOP
25793 					    FETCH C_MTLT INTO L_MTLT_REC;
25794 					    EXIT WHEN C_MTLT%NOTFOUND;
25795 
25796                      /* INVCONV , get L_MTLT_REC values into l_mln_rec which shall be passed to INV_NEW_LOT
25797                      for lot creation */
25798 
25799                   /*INVCONV ,*/
25800                    IF (l_debug = 1) THEN
25801                       print_debug('INVCONV,Assigning values fetched from MTLT to l_mln_rec'||l_progress,1);
25802                    END IF;
25803 
25804          	   l_mln_rec.LOT_NUMBER                := L_MTLT_REC.LOT_NUMBER                    ;
25805                l_mln_rec.LAST_UPDATE_DATE          := SYSDATE                                  ;
25806                l_mln_rec.LAST_UPDATED_BY           := L_MTLT_REC.LAST_UPDATED_BY               ;
25807                l_mln_rec.CREATION_DATE             := SYSDATE                                  ;
25808                l_mln_rec.CREATED_BY                := L_MTLT_REC.CREATED_BY                    ;
25809                l_mln_rec.LAST_UPDATE_LOGIN         := L_MTLT_REC.LAST_UPDATE_LOGIN             ;
25810                l_mln_rec.EXPIRATION_DATE           := L_MTLT_REC.LOT_EXPIRATION_DATE               ;
25811                l_mln_rec.ATTRIBUTE_CATEGORY        := L_MTLT_REC.ATTRIBUTE_CATEGORY            ;
25812                l_mln_rec.ATTRIBUTE1                := L_MTLT_REC.ATTRIBUTE1                    ;
25813                l_mln_rec.ATTRIBUTE2                := L_MTLT_REC.ATTRIBUTE2                    ;
25814                l_mln_rec.ATTRIBUTE3                := L_MTLT_REC.ATTRIBUTE3                    ;
25815                l_mln_rec.ATTRIBUTE4                := L_MTLT_REC.ATTRIBUTE4                    ;
25816                l_mln_rec.ATTRIBUTE5                := L_MTLT_REC.ATTRIBUTE5                    ;
25817                l_mln_rec.ATTRIBUTE6                := L_MTLT_REC.ATTRIBUTE6                    ;
25818                l_mln_rec.ATTRIBUTE7                := L_MTLT_REC.ATTRIBUTE7                    ;
25819                l_mln_rec.ATTRIBUTE8                := L_MTLT_REC.ATTRIBUTE8                    ;
25820                l_mln_rec.ATTRIBUTE9                := L_MTLT_REC.ATTRIBUTE9                    ;
25821                l_mln_rec.ATTRIBUTE10               := L_MTLT_REC.ATTRIBUTE10                   ;
25822                l_mln_rec.ATTRIBUTE11               := L_MTLT_REC.ATTRIBUTE11                   ;
25823                l_mln_rec.ATTRIBUTE12               := L_MTLT_REC.ATTRIBUTE12                   ;
25824                l_mln_rec.ATTRIBUTE13               := L_MTLT_REC.ATTRIBUTE13                   ;
25825                l_mln_rec.ATTRIBUTE14               := L_MTLT_REC.ATTRIBUTE14                   ;
25826                l_mln_rec.ATTRIBUTE15               := L_MTLT_REC.ATTRIBUTE15                   ;
25827                l_mln_rec.REQUEST_ID                := L_MTLT_REC.REQUEST_ID                    ;
25828                l_mln_rec.PROGRAM_APPLICATION_ID    := L_MTLT_REC.PROGRAM_APPLICATION_ID        ;
25829                l_mln_rec.PROGRAM_ID                := L_MTLT_REC.PROGRAM_ID                    ;
25830                l_mln_rec.PROGRAM_UPDATE_DATE       := L_MTLT_REC.PROGRAM_UPDATE_DATE           ;
25831                l_mln_rec.DESCRIPTION               := L_MTLT_REC.DESCRIPTION                   ;
25832                l_mln_rec.VENDOR_NAME               := L_MTLT_REC.VENDOR_NAME                   ;
25833                l_mln_rec.SUPPLIER_LOT_NUMBER       := L_MTLT_REC.SUPPLIER_LOT_NUMBER           ;
25834                l_mln_rec.GRADE_CODE                := L_MTLT_REC.GRADE_CODE                    ;
25835                l_mln_rec.ORIGINATION_DATE          := L_MTLT_REC.ORIGINATION_DATE              ;
25836                l_mln_rec.DATE_CODE                 := L_MTLT_REC.DATE_CODE                     ;
25837                l_mln_rec.STATUS_ID                 := L_MTLT_REC.STATUS_ID                     ;
25838                l_mln_rec.CHANGE_DATE               := L_MTLT_REC.CHANGE_DATE                   ;
25839                l_mln_rec.AGE                       := L_MTLT_REC.AGE                           ;
25840                l_mln_rec.RETEST_DATE               := L_MTLT_REC.RETEST_DATE                   ;
25841                l_mln_rec.MATURITY_DATE             := L_MTLT_REC.MATURITY_DATE                 ;
25842                l_mln_rec.LOT_ATTRIBUTE_CATEGORY    := L_MTLT_REC.LOT_ATTRIBUTE_CATEGORY        ;
25843                l_mln_rec.ITEM_SIZE                 := L_MTLT_REC.ITEM_SIZE                     ;
25844                l_mln_rec.COLOR                     := L_MTLT_REC.COLOR                         ;
25845                l_mln_rec.VOLUME                    := L_MTLT_REC.VOLUME                        ;
25846                l_mln_rec.VOLUME_UOM                := L_MTLT_REC.VOLUME_UOM                    ;
25847                l_mln_rec.PLACE_OF_ORIGIN           := L_MTLT_REC.PLACE_OF_ORIGIN               ;
25848                l_mln_rec.BEST_BY_DATE              := L_MTLT_REC.BEST_BY_DATE                  ;
25849                l_mln_rec.LENGTH                    := L_MTLT_REC.LENGTH                        ;
25850                l_mln_rec.LENGTH_UOM                := L_MTLT_REC.LENGTH_UOM                    ;
25851                l_mln_rec.RECYCLED_CONTENT          := L_MTLT_REC.RECYCLED_CONTENT              ;
25852                l_mln_rec.THICKNESS                 := L_MTLT_REC.THICKNESS                     ;
25853                l_mln_rec.THICKNESS_UOM             := L_MTLT_REC.THICKNESS_UOM                 ;
25854                l_mln_rec.WIDTH                     := L_MTLT_REC.WIDTH                         ;
25855                l_mln_rec.WIDTH_UOM                 := L_MTLT_REC.WIDTH_UOM                     ;
25856                l_mln_rec.CURL_WRINKLE_FOLD         := L_MTLT_REC.CURL_WRINKLE_FOLD             ;
25857                l_mln_rec.C_ATTRIBUTE1              := L_MTLT_REC.C_ATTRIBUTE1                  ;
25858                l_mln_rec.C_ATTRIBUTE2              := L_MTLT_REC.C_ATTRIBUTE2                  ;
25859                l_mln_rec.C_ATTRIBUTE3              := L_MTLT_REC.C_ATTRIBUTE3                  ;
25860                l_mln_rec.C_ATTRIBUTE4              := L_MTLT_REC.C_ATTRIBUTE4                  ;
25861                l_mln_rec.C_ATTRIBUTE5              := L_MTLT_REC.C_ATTRIBUTE5                  ;
25862                l_mln_rec.C_ATTRIBUTE6              := L_MTLT_REC.C_ATTRIBUTE6                  ;
25863                l_mln_rec.C_ATTRIBUTE7              := L_MTLT_REC.C_ATTRIBUTE7                  ;
25864                l_mln_rec.C_ATTRIBUTE8              := L_MTLT_REC.C_ATTRIBUTE8                  ;
25865                l_mln_rec.C_ATTRIBUTE9              := L_MTLT_REC.C_ATTRIBUTE9                  ;
25866                l_mln_rec.C_ATTRIBUTE10             := L_MTLT_REC.C_ATTRIBUTE10                 ;
25867                l_mln_rec.C_ATTRIBUTE11             := L_MTLT_REC.C_ATTRIBUTE11                 ;
25868                l_mln_rec.C_ATTRIBUTE12             := L_MTLT_REC.C_ATTRIBUTE12                 ;
25869                l_mln_rec.C_ATTRIBUTE13             := L_MTLT_REC.C_ATTRIBUTE13                 ;
25870                l_mln_rec.C_ATTRIBUTE14             := L_MTLT_REC.C_ATTRIBUTE14                 ;
25871                l_mln_rec.C_ATTRIBUTE15             := L_MTLT_REC.C_ATTRIBUTE15                 ;
25872                l_mln_rec.C_ATTRIBUTE16             := L_MTLT_REC.C_ATTRIBUTE16                 ;
25873                l_mln_rec.C_ATTRIBUTE17             := L_MTLT_REC.C_ATTRIBUTE17                 ;
25874                l_mln_rec.C_ATTRIBUTE18             := L_MTLT_REC.C_ATTRIBUTE18                 ;
25875                l_mln_rec.C_ATTRIBUTE19             := L_MTLT_REC.C_ATTRIBUTE19                 ;
25876                l_mln_rec.C_ATTRIBUTE20             := L_MTLT_REC.C_ATTRIBUTE20                 ;
25877                l_mln_rec.D_ATTRIBUTE1              := L_MTLT_REC.D_ATTRIBUTE1                  ;
25878                l_mln_rec.D_ATTRIBUTE2              := L_MTLT_REC.D_ATTRIBUTE2                  ;
25879                l_mln_rec.D_ATTRIBUTE3              := L_MTLT_REC.D_ATTRIBUTE3                  ;
25880                l_mln_rec.D_ATTRIBUTE4              := L_MTLT_REC.D_ATTRIBUTE4                  ;
25881                l_mln_rec.D_ATTRIBUTE5              := L_MTLT_REC.D_ATTRIBUTE5                  ;
25882                l_mln_rec.D_ATTRIBUTE6              := L_MTLT_REC.D_ATTRIBUTE6                  ;
25883                l_mln_rec.D_ATTRIBUTE7              := L_MTLT_REC.D_ATTRIBUTE7                  ;
25884                l_mln_rec.D_ATTRIBUTE8              := L_MTLT_REC.D_ATTRIBUTE8                  ;
25885                l_mln_rec.D_ATTRIBUTE9              := L_MTLT_REC.D_ATTRIBUTE9                  ;
25886                l_mln_rec.D_ATTRIBUTE10             := L_MTLT_REC.D_ATTRIBUTE10                 ;
25887                l_mln_rec.N_ATTRIBUTE1              := L_MTLT_REC.N_ATTRIBUTE1                  ;
25888                l_mln_rec.N_ATTRIBUTE2              := L_MTLT_REC.N_ATTRIBUTE2                  ;
25889                l_mln_rec.N_ATTRIBUTE3              := L_MTLT_REC.N_ATTRIBUTE3                  ;
25890                l_mln_rec.N_ATTRIBUTE4              := L_MTLT_REC.N_ATTRIBUTE4                  ;
25891                l_mln_rec.N_ATTRIBUTE5              := L_MTLT_REC.N_ATTRIBUTE5                  ;
25892                l_mln_rec.N_ATTRIBUTE6              := L_MTLT_REC.N_ATTRIBUTE6                  ;
25893                l_mln_rec.N_ATTRIBUTE7              := L_MTLT_REC.N_ATTRIBUTE7                  ;
25894                l_mln_rec.N_ATTRIBUTE8              := L_MTLT_REC.N_ATTRIBUTE8                  ;
25895                l_mln_rec.N_ATTRIBUTE9              := L_MTLT_REC.N_ATTRIBUTE9                  ;
25896                l_mln_rec.N_ATTRIBUTE10             := L_MTLT_REC.N_ATTRIBUTE10                 ;
25897                l_mln_rec.VENDOR_ID                 := L_MTLT_REC.VENDOR_ID                     ;
25898                l_mln_rec.TERRITORY_CODE            := L_MTLT_REC.TERRITORY_CODE                ;
25899                l_mln_rec.PARENT_LOT_NUMBER         := L_MTLT_REC.PARENT_LOT_NUMBER             ;
25900                l_mln_rec.ORIGINATION_TYPE          := L_MTLT_REC.ORIGINATION_TYPE              ;
25901                l_mln_rec.EXPIRATION_ACTION_DATE    := L_MTLT_REC.EXPIRATION_ACTION_DATE        ;
25902                l_mln_rec.EXPIRATION_ACTION_CODE    := L_MTLT_REC.EXPIRATION_ACTION_CODE        ;
25903                l_mln_rec.HOLD_DATE                 := L_MTLT_REC.HOLD_DATE                     ;
25904 
25905          /*end , INVCONV*/
25906 
25907 					    L_NUM_MTLT_RECS := L_NUM_MTLT_RECS + 1;
25908 					    l_tot_mtlt_prim_qty := l_tot_mtlt_prim_qty + l_mtlt_rec.primary_quantity;
25909 					    l_tot_mtlt_trans_qty := l_tot_mtlt_trans_qty + l_mtlt_rec.transaction_quantity; -- Bug# 4225766
25910 
25911 					    IF (l_debug = 1) THEN
25912 					       print_debug('VALIDATE_LOT_SERIAL_INFO: LOT NUMBER: '||l_mtlt_rec.lot_number||': '||l_progress, 1);
25913 					       print_debug('VALIDATE_LOT_SERIAL_INFO: LOT PRIMARY QUANTITY: '||l_mtlt_rec.primary_quantity||': '||l_progress, 1);
25914 					       l_progress := 'WMSINB-26386';
25915                       print_debug('INVCONV,Finished Assigning values fetched from MTLT to l_mln_rec'||l_progress,1);
25916 					    END IF;
25917 
25918 					    IF (l_parent_txn_type IN (g_rtv,g_rtr,g_rtc)) THEN
25919 					       IF (l_grand_parent_txn_type <> 'DELIVER') THEN
25920 						  IF NOT (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
25921 						     --raise an error
25922 						     l_progress := 'WMSINB-26393';
25923 						     RAISE fnd_api.g_exc_error;
25924 						  END IF; --IF NOT (lot_entered_on_parent(l_grand_parent_txn_id))
25925 					       END IF; --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
25926 					     ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtr,g_rtc)) THEN
25927 					       IF (l_parent_txn_type <> 'DELIVER') THEN
25928 						  IF (validate_rs(NULL,l_parent_transaction_id,l_dummy_lpn)) THEN
25929 						     IF NOT (lot_entered_on_parent(l_parent_transaction_id)) THEN
25930 							--raise an error
25931 							l_progress := 'WMSINB-26402';
25932 							RAISE fnd_api.g_exc_error;
25933 						     END IF;
25934 						  END IF;
25935 					       END IF; --IF (l_parent_txn_type <> 'DELIVER') THEN
25936 					    END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtr,g_rtc)) THEN
25937 
25938 	               BEGIN
25939 
25940                    /*INVCONV , Remove OPM specific ic_lots_mst logic , Punit Kumar */
25941 					      ----- IF (l_discrete_transaction) THEN
25942 
25943 						  SELECT 1,parent_lot_number
25944                        INTO L_LOT_EXISTS ,l_parent_lot_number
25945                        FROM MTL_LOT_NUMBERS
25946                        WHERE ORGANIZATION_ID = L_ORG_ID
25947                        AND   INVENTORY_ITEM_ID = L_ITEM_ID
25948                        AND LOT_NUMBER = Ltrim(Rtrim(L_MTLT_REC.lot_number));
25949 
25950 						/*
25951 						ELSE -- opm change bug# 3061052 --IF (l_discrete_transaction) THEN
25952 						  IF  Ltrim(Rtrim(L_MTLT_REC.sublot_num)) IS NOT NULL THEN
25953 						     SELECT 1, LOT_ID
25954 						       INTO L_LOT_EXISTS , L_OPM_LOT_ID
25955 						       FROM IC_LOTS_MST
25956 						       WHERE ITEM_ID = l_opm_item_id
25957 						       AND LOT_NO = Ltrim(Rtrim(L_MTLT_REC.lot_number))
25958 						       AND SUBLOT_NO = Ltrim(Rtrim(L_MTLT_REC.sublot_num)) ;
25959 						   ELSE
25960 						     SELECT 1 , lot_id
25961 						       INTO L_LOT_EXISTS , L_OPM_LOT_ID
25962 						       FROM IC_LOTS_MST
25963 						       WHERE ITEM_ID = l_opm_item_id
25964 						       AND LOT_NO = Ltrim(Rtrim(L_MTLT_REC.lot_number))
25965 						       AND SUBLOT_NO IS NULL ;
25966 						  END IF;
25967 					       END IF; --IF (l_discrete_transaction) THEN
25968 
25969                  */
25970 
25971                    /*INVCONV ,*/
25972                     IF (l_debug = 1) THEN
25973                        print_debug('INVCONV, Removing OPM specific fork :'||l_progress,1);
25974                     END IF;
25975 					    EXCEPTION
25976 					       WHEN NO_DATA_FOUND THEN
25977 						  L_LOT_EXISTS := 0;
25978 					    END;
25979 
25980 					    IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
25981 					       IF (l_grand_parent_txn_type <> 'DELIVER') THEN
25982 					          BEGIN
25983 						     -- opm change bug# 3061052. added SUBLOT_NO
25984                         /* INVCONV, Remove sublot Num , Punit Kumar */
25985 
25986                          SELECT primary_quantity
25987 						       INTO l_rls_primary_quantity
25988 						       FROM rcv_lots_supply
25989 						       WHERE transaction_id = l_grand_parent_txn_id
25990 						       AND lot_num = Ltrim(Rtrim(l_mtlt_rec.lot_number)) ;
25991 
25992                          /*
25993 						       AND ((sublot_num IS NULL and Ltrim(Rtrim(l_mtlt_rec.sublot_num)) IS NULL)
25994 							    OR (sublot_num = Ltrim(Rtrim(l_mtlt_rec.sublot_num)))) ;
25995                          */
25996 
25997 						       IF (l_mtlt_rec.primary_quantity > l_rls_primary_quantity) THEN
25998 							  --raise error
25999 							  l_progress := 'WMSINB-26454';
26000 							  RAISE fnd_api.g_exc_error;
26001 						       END IF;
26002 						  EXCEPTION
26003 						     WHEN no_data_found THEN
26004 							--raise error
26005 	   						l_progress := 'WMSINB-26460';
26006 							RAISE fnd_api.g_exc_error;
26007 						  END;
26008 
26009 						  -- opm change bug# 3061052
26010 
26011                     /*
26012 						  IF (NOT l_discrete_transaction) THEN
26013 						     gml_opm_roi_grp.validate_opm_lot(p_api_version	=> 1.0,
26014 										      p_init_msg_lst	 	=> FND_API.G_FALSE,
26015 										      p_mtlt_rowid		=> l_mtlt_rec.rowid,
26016 										      p_new_lot	 	=> 'N',
26017 										      p_opm_item_id		=> l_opm_item_id,
26018 										      p_item_no		=> l_item_no,
26019 										      p_lots_specified_on_parent => 'Y',
26020 										      p_lot_id		=> l_opm_lot_id,
26021 										      p_parent_txn_type	=> l_parent_txn_type,
26022 										      p_grand_parent_txn_type => l_grand_parent_txn_type,
26023 										      x_return_status 	=> x_return_status,
26024 										      x_msg_data      	=> x_msg_data,
26025 										      x_msg_count     	=> x_msg_count
26026 										      );
26027                     */
26028 
26029                      /*INVCONV ,*/
26030                     IF (l_debug = 1) THEN
26031                        print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
26032                     END IF;
26033 
26034                      INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
26035                                                        x_return_status      		   => x_return_status
26036                                                       ,x_msg_data           		   => x_msg_data
26037                                                       ,x_msg_count          		   => x_msg_count
26038                                                       ,p_api_version	               => 1.0
26039                                                       ,p_init_msg_lst	            => FND_API.G_FALSE
26040                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
26041                                                       ,p_transaction_type_id 	      => l_transaction_type_id
26042                                                       ,p_new_lot			            => 'N'
26043                                                       ,p_item_id	 		            => l_item_id
26044                                                       ,p_to_organization_id		   => L_ORG_ID
26045                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
26046                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
26047                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
26048                                                       ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
26049                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
26050                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
26051                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
26052                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
26053                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
26054                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
26055                                                       ,p_rti_id	                  => L_RTI_ID
26056                                                       ,p_revision             	   => l_item_revision
26057                                                       ,p_subinventory_code  	      => L_SUB_CODE
26058                                                       ,p_locator_id           	   => l_loc_id
26059                                                       ,p_transaction_type           => l_transaction_type
26060                                                       ,p_parent_txn_type            => l_parent_txn_type
26061                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
26062                                                       );
26063 
26064                       /*INVCONV ,*/
26065                      IF (l_debug = 1) THEN
26066                         print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
26067                         print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
26068                      END IF;
26069 
26070 						     IF X_RETURN_STATUS <> 'S' THEN
26071 							--RAISE ERROR
26072 							l_progress := 'WMSINB-26483';
26073 							RAISE fnd_api.g_exc_error;
26074 						     END IF;
26075 
26076 						     IF (l_debug = 1) THEN
26077 							print_debug('VALIDATE_LOT_SERIAL_INFO: VALIDATE_OPM_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
26078 						     END IF;
26079 						 /* END IF; --IF (NOT l_discrete_transaction) THEN*/
26080 						ELSE --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
26081 							IF (l_lot_exists = 1) THEN
26082 
26083                         /*INVCONV , validating for parent lot, Punit Kumar */
26084 
26085                         IF  L_MTLT_REC.parent_lot_number IS NOT NULL THEN
26086                            IF L_MTLT_REC.parent_lot_number <> l_parent_lot_number THEN
26087                               fnd_message.set_name ('INV' , 'INV_CL_PARENT_INVALID' );
26088                               fnd_msg_pub.ADD;
26089                               RAISE fnd_api.g_exc_error;
26090                            END IF;
26091                         ELSE
26092                            L_MTLT_REC.parent_lot_number := l_parent_lot_number;
26093                         END IF;
26094                         /*end , INVCONV */
26095 
26096 							   -- opm change bug# 3061052
26097 							   -- this combination not possible
26098 
26099                       /*INVCONV , existing discrete validations. Same will be executed for process org
26100                         Punit Kumar */
26101 
26102 							   --------IF (l_discrete_transaction) THEN
26103 							      --PERFORM MATERIAL STATUS CHECK FOR LOT
26104 
26105 							      IF (l_source_document_code = 'PO') THEN
26106 								 l_transaction_type_id := 71;
26107 							       ELSE
26108 								 l_transaction_type_id := 72;
26109 							      END IF;
26110 
26111 							      INV_LOT_TRX_VALIDATION_PUB.VALIDATE_MATERIAL_STATUS(X_RETURN_STATUS => X_RETURN_STATUS,
26112 														  X_MSG_COUNT => X_MSG_COUNT,
26113 														  X_MSG_DATA => X_MSG_DATA,
26114 														  X_VALIDATION_STATUS => L_VALIDATION_STATUS,
26115 														  P_TRANSACTION_TYPE_ID => l_transaction_type_id,
26116 														  P_ORGANIZATION_ID => L_ORG_ID,
26117 														  P_INVENTORY_ITEM_ID => L_ITEM_ID,
26118 														  P_LOT_NUMBER => L_MTLT_REC.LOT_NUMBER,
26119 														  P_SUBINVENTORY_CODE => L_SUB_CODE,
26120 														  P_LOCATOR_ID => L_LOC_ID,
26121 														  P_STATUS_ID => NULL);
26122 							      IF X_RETURN_STATUS <> 'S' THEN
26123 								 --RAISE an ERROR
26124 								 l_progress := 'WMSINB-26517';
26125 								 RAISE fnd_api.g_exc_error;
26126 							      END IF;
26127 
26128 							      IF (l_debug = 1) THEN
26129 								 print_debug('VALIDATE_LOT_SERIAL_INFO: LOT MATERIAL VALIDATION STATUS: '||L_VALIDATION_STATUS||' : '||l_progress, 1);
26130 								 l_progress := 'WMSINB-26523';
26131 							      END IF;
26132 
26133 							      IF L_VALIDATION_STATUS <> 'Y' THEN
26134 								 --RAISE an ERROR
26135 								 l_progress := 'WMSINB-26528';
26136 								 RAISE fnd_api.g_exc_error;
26137 							      END IF;
26138 
26139                        /*
26140 							    ELSE --IF (l_discrete_transaction) THEN
26141 						              gml_opm_roi_grp.validate_opm_lot(p_api_version	=> 1.0,
26142 											       p_init_msg_lst	 	=> FND_API.G_FALSE,
26143 											       p_mtlt_rowid		=> l_mtlt_rec.rowid,
26144 											       p_new_lot	 	=> 'N',
26145 											       p_opm_item_id		=> l_opm_item_id,
26146 											       p_item_no		=> l_item_no,
26147 											       p_lots_specified_on_parent => 'Y',
26148 											       p_lot_id		=> l_opm_lot_id,
26149 											       p_parent_txn_type	=> l_parent_txn_type,
26150 											       p_grand_parent_txn_type => l_grand_parent_txn_type,
26151 											       x_return_status 	=> x_return_status,
26152 											       x_msg_data      	=> x_msg_data,
26153 											       x_msg_count     	=> x_msg_count
26154 											       );
26155 							    */
26156                          /*INVCONV ,*/
26157                          IF (l_debug = 1) THEN
26158                             print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
26159                          END IF;
26160 
26161                            INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
26162                                                        x_return_status      		   => x_return_status
26163                                                       ,x_msg_data           		   => x_msg_data
26164                                                       ,x_msg_count          		   => x_msg_count
26165                                                       ,p_api_version	               => 1.0
26166                                                       ,p_init_msg_lst	            => FND_API.G_FALSE
26167                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
26168                                                       ,p_transaction_type_id 	      => l_transaction_type_id
26169                                                       ,p_new_lot			            => 'N'
26170                                                       ,p_item_id	 		            => l_item_id
26171                                                       ,p_to_organization_id		   => L_ORG_ID
26172                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
26173                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
26174                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
26175                                                       ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
26176                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
26177                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
26178                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
26179                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
26180                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
26181                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
26182                                                       ,p_rti_id	                  => L_RTI_ID
26183                                                       ,p_revision             	   => l_item_revision
26184                                                       ,p_subinventory_code  	      => L_SUB_CODE
26185                                                       ,p_locator_id           	   => l_loc_id
26186                                                       ,p_transaction_type           => l_transaction_type
26187                                                       ,p_parent_txn_type            => l_parent_txn_type
26188                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
26189                                                       );
26190 
26191                         /*INVCONV ,*/
26192                         IF (l_debug = 1) THEN
26193                            print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
26194                            print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
26195                         END IF;
26196 
26197 			 			      IF X_RETURN_STATUS <> 'S' THEN
26198 								 --RAISE ERROR
26199 								 l_progress := 'WMSINB-26549';
26200 								 RAISE fnd_api.g_exc_error;
26201 		         			              END IF;
26202 
26203 		         			              IF (l_debug = 1) THEN
26204 								 print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
26205 		         			              END IF;
26206 
26207 							   /*END IF; -- IF (l_discrete_transaction) THEN	*/
26208 							 ELSE --IF (l_lot_exists = 1) THEN
26209 							   --raise an error
26210 							   l_progress := 'WMSINB-26560';
26211 							   RAISE fnd_api.g_exc_error;
26212 							END IF; --IF (l_lot_exists = 1) THEN
26213 					       END IF; --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
26214 					     ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
26215 						  IF (l_parent_txn_type <> 'RECEIVE') THEN
26216 						     IF (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
26217 						        BEGIN
26218 							   -- opm change bug# 3061052 added SUBLOT_NO
26219 
26220                     /*INVCONV , Remove Sublot Num , Punit Kumar*/
26221 
26222 							   SELECT primary_quantity
26223 							     INTO l_rls_primary_quantity
26224 							     FROM rcv_lots_supply
26225 							     WHERE transaction_id = l_grand_parent_txn_id
26226 							     AND lot_num = Ltrim(Rtrim(l_mtlt_rec.lot_number));
26227                        /*
26228 							     AND ((sublot_num IS NULL and Ltrim(Rtrim(l_mtlt_rec.sublot_num)) IS NULL)
26229 								  OR (sublot_num = Ltrim(Rtrim(l_mtlt_rec.sublot_num)))) ;
26230 							  */
26231 
26232 							     IF (l_mtlt_rec.primary_quantity > l_rls_primary_quantity) THEN
26233 								--raise error
26234 								l_progress := 'WMSINB-26579';
26235 								RAISE fnd_api.g_exc_error;
26236 							     END IF;
26237 							EXCEPTION
26238 							   WHEN no_data_found THEN
26239 							      --raise error
26240 							      l_progress := 'WMSINB-26585';
26241 							      RAISE fnd_api.g_exc_error;
26242 							END;
26243 						     END IF; --IF (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
26244 						   ELSE --IF (l_parent_txn_type <> 'RECEIVE') THEN
26245 
26246                      /* INVCONV , remove OPM specific fork , Punit Kumar*/
26247 
26248 							----IF (l_discrete_transaction) THEN
26249 
26250 							   IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY', 'REQ')) THEN
26251 							      -- GET THE LOT/SERIAL CONTROL IN SOURCE ORG
26252 							      GET_SERIAL_LOT_CTRL_IN_SRC_ORG
26253 								(L_SHIPMENT_LINE_ID, L_ORG_ID,
26254 								 L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
26255 								 l_from_org_rev_ctrl, X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
26256 
26257 							      IF (l_debug = 1) THEN
26258 								 print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CONTROL FROM ORG: '||L_FROM_ORG_LOT_CTRL||' : '||l_progress, 1);
26259 								 l_progress := 'WMSINB-26600';
26260 							      END IF;
26261 
26262 							      IF (L_FROM_ORG_LOT_CTRL = 2) THEN
26263 							         BEGIN
26264 								    SELECT nvl(SUM(rls.primary_quantity),0) --Bug:5489462
26265 								      INTO L_RLS_PRIMARY_QUANTITY
26266 								      FROM rcv_lots_supply rls
26267 								      , rcv_shipment_lines rsl
26268 								      WHERE rsl.SHIPMENT_LINE_ID = rls.SHIPMENT_LINE_ID
26269 								      AND rsl.shipment_header_id = l_shipment_header_id
26270 								      AND rsl.item_id = l_item_id
26271 								      AND rls.SUPPLY_TYPE_CODE = 'SHIPMENT'
26272 								      AND rls.LOT_NUM = Ltrim(Rtrim(L_MTLT_REC.lot_number));
26273 
26274 								    IF (L_MTLT_REC.PRIMARY_QUANTITY >
26275 									L_RLS_PRIMARY_QUANTITY) THEN
26276 								       --RAISE ERROR
26277 								       l_progress := 'WMSINB-26617';
26278 								       RAISE fnd_api.g_exc_error;
26279 								    END IF;
26280 								 EXCEPTION
26281 								    WHEN NO_DATA_FOUND THEN
26282 								       --RAISE ERROR
26283 								       l_progress := 'WMSINB-26623';
26284 								       RAISE fnd_api.g_exc_error;
26285 								 END;
26286 							      END IF; --IF (L_FROM_ORG_LOT_CTRL = 2) THEN
26287 							   END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY', 'REQ')) THEN
26288 						  /* END IF; --  IF (l_discrete_transaction) THEN*/
26289 						  END IF; --IF (l_parent_txn_type <> 'RECEIVE') THEN
26290 
26291 						  IF (l_lot_exists = 1) THEN
26292 
26293                        /*INVCONV, Remove descrete specific call*/
26294 						     -- opm change bug# 3061052
26295 						     /*IF (l_discrete_transaction) THEN */
26296                         /*end , INVCONV*/
26297 							--PERFORM MATERIAL STATUS CHECK FOR LOT
26298 
26299 							IF (l_source_document_code = 'PO') THEN
26300 							   l_transaction_type_id := 71;
26301 							 ELSE
26302 							   l_transaction_type_id := 72;
26303 							END IF;
26304 
26305 							INV_LOT_TRX_VALIDATION_PUB.validate_material_status
26306 							  (X_RETURN_STATUS => X_RETURN_STATUS,
26307 							   X_MSG_COUNT => X_MSG_COUNT,
26308 							   X_MSG_DATA => X_MSG_DATA,
26309 							   X_VALIDATION_STATUS => L_VALIDATION_STATUS,
26310 							   P_TRANSACTION_TYPE_ID => l_transaction_type_id,
26311 							   P_ORGANIZATION_ID => L_ORG_ID,
26312 							   P_INVENTORY_ITEM_ID => L_ITEM_ID,
26313 							   P_LOT_NUMBER => L_MTLT_REC.LOT_NUMBER,
26314 							   P_SUBINVENTORY_CODE => L_SUB_CODE,
26315 							   P_LOCATOR_ID => L_LOC_ID,
26316 							   P_STATUS_ID => NULL);
26317 							IF X_RETURN_STATUS <> 'S' THEN
26318 							   --RAISE an ERROR
26319 							   l_progress := 'WMSINB-26656';
26320 							   RAISE fnd_api.g_exc_error;
26321 							END IF;
26322 
26323 							IF (l_debug = 1) THEN
26324 							   print_debug('VALIDATE_LOT_SERIAL_INFO: LOT MATERIAL VALIDATION STATUS: '||L_VALIDATION_STATUS||' : '||l_progress, 1);
26325 							   l_progress := 'WMSINB-26662';
26326 							END IF;
26327 
26328 							IF L_VALIDATION_STATUS <> 'Y' THEN
26329 							   --RAISE an ERROR
26330 							   l_progress := 'WMSINB-26667';
26331 							   RAISE fnd_api.g_exc_error;
26332 							END IF;
26333 
26334                    /*
26335 						      ELSE --IF (l_discrete_transaction) THEN
26336 							-- opm change bug# 3061052
26337 
26338 							gml_opm_roi_grp.validate_opm_lot(p_api_version => 1.0,
26339 											 p_init_msg_lst	 	=> FND_API.G_FALSE,
26340 											 p_mtlt_rowid		=> l_mtlt_rec.rowid,
26341 											 p_new_lot	 	=> 'N',
26342 											 p_opm_item_id		=> l_opm_item_id,
26343 											 p_item_no		=> l_item_no,
26344 											 p_lots_specified_on_parent => 'Y',
26345 											 p_lot_id		=> l_opm_lot_id,
26346 											 p_parent_txn_type	=> l_parent_txn_type,
26347 											 p_grand_parent_txn_type => l_grand_parent_txn_type,
26348 											 x_return_status 	=> x_return_status,
26349 											 x_msg_data      	=> x_msg_data,
26350 											 x_msg_count     	=> x_msg_count
26351 											 );
26352 
26353                    */
26354                      /*INVCONV ,*/
26355                      IF (l_debug = 1) THEN
26356                         print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
26357                      END IF;
26358 
26359                      INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
26360                                                         x_return_status      		   => x_return_status
26361                                                        ,x_msg_data           		   => x_msg_data
26362                                                        ,x_msg_count          		   => x_msg_count
26363                                                        ,p_api_version	               => 1.0
26364                                                        ,p_init_msg_lst	            => FND_API.G_FALSE
26365                                                        ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
26366                                                        ,p_transaction_type_id 	   => l_transaction_type_id
26367                                                        ,p_new_lot			            => 'N'
26368                                                        ,p_item_id	 		            => l_item_id
26369                                                        ,p_to_organization_id		   => L_ORG_ID
26370                                                        ,p_lot_number			         => L_MTLT_REC.lot_number
26371                                                        ,p_parent_lot_number			=> L_MTLT_REC.parent_lot_number
26372                                                        ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
26373                                                        ,x_lot_secondary_quantity    => L_MTLT_REC.SECONDARY_QUANTITY
26374                                                        ,p_line_secondary_quantity	=> l_rti_SECONDARY_QUANTITY
26375                                                        ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
26376                                                        ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
26377                                                        ,p_source_document_code	   => L_SOURCE_DOCUMENT_CODE
26378                                                        ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
26379                                                        ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
26380                                                        ,p_rti_id	                  => L_RTI_ID
26381                                                        ,p_revision             	   => l_item_revision
26382                                                        ,p_subinventory_code  	      => L_SUB_CODE
26383                                                        ,p_locator_id           	   => l_loc_id
26384                                                        ,p_transaction_type           => l_transaction_type
26385                                                        ,p_parent_txn_type            => l_parent_txn_type
26386                                                        ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
26387                                                        );
26388 
26389 
26390 						   /*INVCONV ,*/
26391                      IF (l_debug = 1) THEN
26392                         print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
26393                         print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
26394                      END IF;
26395 
26396 							IF X_RETURN_STATUS <> 'S' THEN
26397 							   --RAISE ERROR
26398 							   l_progress := 'WMSINB-26690';
26399 							   RAISE fnd_api.g_exc_error;
26400 							END IF;
26401 
26402 							IF (l_debug = 1) THEN
26403 							   print_debug('VALIDATE_LOT_SERIAL_INFO: VALIDATE_OPM_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
26404 							END IF;
26405 
26406 						    /* END IF; --IF (l_discrete_transaction) THEN*/
26407 						   ELSE --IF (l_lot_exists = 1) THEN
26408 						     -- opm change bug# 3061052
26409 
26410                      /*
26411 						     IF (l_discrete_transaction) THEN
26412 							--call CREATE_INV_LOT
26413 							--FOR l_inv_att_index IN 1..15 LOOP
26414 							-- l_inv_attributes_tbl(l_inv_att_index) := NULL;
26415 							--END LOOP;
26416 
26417 							l_c_attributes_tbl(1)  := l_mtlt_rec.c_attribute1;
26418 							l_c_attributes_tbl(2)  := l_mtlt_rec.c_attribute2;
26419 							l_c_attributes_tbl(3)  := l_mtlt_rec.c_attribute3;
26420 							l_c_attributes_tbl(4)  := l_mtlt_rec.c_attribute4;
26421 							l_c_attributes_tbl(5)  := l_mtlt_rec.c_attribute5;
26422 							l_c_attributes_tbl(6)  := l_mtlt_rec.c_attribute6;
26423 							l_c_attributes_tbl(7)  := l_mtlt_rec.c_attribute7;
26424 							l_c_attributes_tbl(8)  := l_mtlt_rec.c_attribute8;
26425 							l_c_attributes_tbl(9)  := l_mtlt_rec.c_attribute9;
26426 							l_c_attributes_tbl(10) := l_mtlt_rec.c_attribute10;
26427 							l_c_attributes_tbl(11) := l_mtlt_rec.c_attribute11;
26428 							l_c_attributes_tbl(12) := l_mtlt_rec.c_attribute12;
26429 							l_c_attributes_tbl(13) := l_mtlt_rec.c_attribute13;
26430 							l_c_attributes_tbl(14) := l_mtlt_rec.c_attribute14;
26431 							l_c_attributes_tbl(15) := l_mtlt_rec.c_attribute15;
26432 							l_c_attributes_tbl(16) := l_mtlt_rec.c_attribute16;
26433 							l_c_attributes_tbl(17) := l_mtlt_rec.c_attribute17;
26434 							l_c_attributes_tbl(18) := l_mtlt_rec.c_attribute18;
26435 							l_c_attributes_tbl(19) := l_mtlt_rec.c_attribute19;
26436 							l_c_attributes_tbl(20) := l_mtlt_rec.c_attribute20;
26437 							l_d_attributes_tbl(1)  := l_mtlt_rec.d_attribute1;
26438 							l_d_attributes_tbl(2)  := l_mtlt_rec.d_attribute2;
26439 							l_d_attributes_tbl(3)  := l_mtlt_rec.d_attribute3;
26440 							l_d_attributes_tbl(4)  := l_mtlt_rec.d_attribute4;
26441 							l_d_attributes_tbl(5)  := l_mtlt_rec.d_attribute5;
26442 							l_d_attributes_tbl(6)  := l_mtlt_rec.d_attribute6;
26443 							l_d_attributes_tbl(7)  := l_mtlt_rec.d_attribute7;
26444 							l_d_attributes_tbl(8)  := l_mtlt_rec.d_attribute8;
26445 							l_d_attributes_tbl(9)  := l_mtlt_rec.d_attribute9;
26446 							l_d_attributes_tbl(10) := l_mtlt_rec.d_attribute10;
26447 							l_n_attributes_tbl(1)  := l_mtlt_rec.n_attribute1;
26448 							l_n_attributes_tbl(2)  := l_mtlt_rec.n_attribute2;
26449 							l_n_attributes_tbl(3)  := l_mtlt_rec.n_attribute3;
26450 							l_n_attributes_tbl(4)  := l_mtlt_rec.n_attribute4;
26451 							l_n_attributes_tbl(5)  := l_mtlt_rec.n_attribute5;
26452 							l_n_attributes_tbl(6)  := l_mtlt_rec.n_attribute6;
26453 							l_n_attributes_tbl(7)  := l_mtlt_rec.n_attribute7;
26454 							l_n_attributes_tbl(8)  := l_mtlt_rec.n_attribute8;
26455 							l_n_attributes_tbl(9)  := l_mtlt_rec.n_attribute9;
26456 							l_n_attributes_tbl(10) := l_mtlt_rec.n_attribute10;
26457 
26458               --Bug #3187688
26459               --Populate the INV attributes table and pass the attribute cateogry
26460               l_inv_attributes_tbl(1)  := l_mtlt_rec.attribute1;
26461               l_inv_attributes_tbl(2)  := l_mtlt_rec.attribute2;
26462               l_inv_attributes_tbl(3)  := l_mtlt_rec.attribute3;
26463               l_inv_attributes_tbl(4)  := l_mtlt_rec.attribute4;
26464               l_inv_attributes_tbl(5)  := l_mtlt_rec.attribute5;
26465               l_inv_attributes_tbl(6)  := l_mtlt_rec.attribute6;
26466               l_inv_attributes_tbl(7)  := l_mtlt_rec.attribute7;
26467               l_inv_attributes_tbl(8)  := l_mtlt_rec.attribute8;
26468               l_inv_attributes_tbl(9)  := l_mtlt_rec.attribute9;
26469               l_inv_attributes_tbl(10) := l_mtlt_rec.attribute10;
26470               l_inv_attributes_tbl(11) := l_mtlt_rec.attribute11;
26471               l_inv_attributes_tbl(12) := l_mtlt_rec.attribute12;
26472               l_inv_attributes_tbl(13) := l_mtlt_rec.attribute13;
26473               l_inv_attributes_tbl(14) := l_mtlt_rec.attribute14;
26474               l_inv_attributes_tbl(15) := l_mtlt_rec.attribute15;
26475 
26476 
26477 							inv_lot_api_pub.create_inv_lot(x_return_status => x_return_status
26478 										       , x_msg_count => x_msg_count
26479 										       , x_msg_data => x_msg_data
26480 										       , p_inventory_item_id => l_item_id
26481 										       , p_organization_id => l_org_id
26482 										       , p_lot_number => l_mtlt_rec.lot_number
26483 										       , p_expiration_date => l_mtlt_rec.lot_expiration_date
26484 										       , p_disable_flag => NULL
26485 										       , p_attribute_category => l_mtlt_rec.attribute_category
26486 										       , p_lot_attribute_category => l_mtlt_rec.lot_attribute_category
26487 										       , p_attributes_tbl => l_inv_attributes_tbl
26488 										       , p_c_attributes_tbl => l_c_attributes_tbl
26489 										       , p_n_attributes_tbl => l_n_attributes_tbl
26490 										       , p_d_attributes_tbl => l_d_attributes_tbl
26491 										       , p_grade_code => l_mtlt_rec.grade_code
26492 										       , p_origination_date => l_mtlt_rec.origination_date
26493 										       , p_date_code => l_mtlt_rec.date_code
26494 										       , p_status_id => l_mtlt_rec.status_id
26495 							  , p_change_date => l_mtlt_rec.change_date
26496 							  , p_age => l_mtlt_rec.age
26497 							  , p_retest_date => l_mtlt_rec.retest_date
26498 							  , p_maturity_date => l_mtlt_rec.maturity_date
26499 							  , p_item_size => l_mtlt_rec.item_size
26500 							  , p_color => l_mtlt_rec.color
26501 							  , p_volume => l_mtlt_rec.volume
26502 							  , p_volume_uom => l_mtlt_rec.volume_uom
26503 							  , p_place_of_origin => l_mtlt_rec.place_of_origin
26504 							  , p_best_by_date => l_mtlt_rec.best_by_date
26505 							  , p_length => l_mtlt_rec.Length
26506 							  , p_length_uom => l_mtlt_rec.length_uom
26507 							  , p_recycled_content => l_mtlt_rec.recycled_content
26508 							  , p_thickness => l_mtlt_rec.thickness
26509 							  , p_thickness_uom => l_mtlt_rec.thickness_uom
26510 							  , p_width => l_mtlt_rec.width
26511 							  , p_width_uom => l_mtlt_rec.width_uom
26512 							  , p_territory_code => l_mtlt_rec.territory_code
26513 							  , p_supplier_lot_number => l_mtlt_rec.supplier_lot_number
26514 							  , p_vendor_name => l_mtlt_rec.vendor_name
26515 							  , p_source => inv_lot_api_pub.inv);
26516 
26517 							IF (x_return_status <> 'S') THEN
26518 							   --raise error
26519 							   l_progress := 'WMSINB-26790';
26520 							   RAISE fnd_api.g_exc_error;
26521 							END IF;
26522 
26523 							IF (l_debug = 1) THEN
26524 							   print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CREATED: '||l_progress, 1);
26525 							   l_progress := 'WMSINB-26796';
26526 							END IF;
26527 						      ELSE --IF (l_discrete_transaction) THEN
26528 							-- opm change bug# 3061052
26529 							gml_opm_roi_grp.validate_opm_lot(p_api_version => 1.0,
26530 											 p_init_msg_lst	 	=> FND_API.G_FALSE,
26531 											 p_mtlt_rowid		=> l_mtlt_rec.rowid,
26532 											 p_new_lot	 	=> 'Y',
26533 											 p_opm_item_id		=> l_opm_item_id,
26534 											 p_item_no		=> l_item_no,
26535 											 p_lots_specified_on_parent => 'Y',
26536 											 p_lot_id		=> l_opm_lot_id,
26537 											 p_parent_txn_type	=> l_parent_txn_type,
26538 											 p_grand_parent_txn_type => l_grand_parent_txn_type,
26539 											 x_return_status 	=> x_return_status,
26540 											 x_msg_data      	=> x_msg_data,
26541 											 x_msg_count     	=> x_msg_count
26542 											 );
26543 
26544                    */
26545 
26546                  /*INVCONV , Perform lot validations and create the new lot.
26547                Call Lot Create API INV_ROI_INTEGRATION_GRP.INV_NEW_LOT to create the new lot.
26548                This shall also create lot specific conversions after creating the new Lot.
26549 			      This replaces the existing procedure INV_LOT_API_PUB.CREATE_INV_LOT to create NEW LOT
26550                Punit Kumar*/
26551 
26552               /*INVCONV ,*/
26553               IF (l_debug = 1) THEN
26554                  print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
26555               END IF;
26556 
26557               INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
26558                                                          x_return_status      		   => x_return_status
26559                                                         ,x_msg_data           		   => x_msg_data
26560                                                         ,x_msg_count          		   => x_msg_count
26561                                                         ,p_api_version	               => 1.0
26562                                                         ,p_init_msg_lst	               => FND_API.G_FALSE
26563                                                         ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
26564                                                         ,p_transaction_type_id 	      => l_transaction_type_id
26565                                                         ,p_new_lot			            => 'Y'
26566                                                         ,p_item_id	 		            => l_item_id
26567                                                         ,p_to_organization_id		      => L_ORG_ID
26568                                                         ,p_lot_number			         => L_MTLT_REC.lot_number
26569                                                         ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
26570                                                         ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
26571                                                         ,x_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
26572                                                         ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
26573                                                         ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
26574                                                         ,p_transaction_unit_of_measure => l_rti_UNIT_OF_MEASURE
26575                                                         ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
26576                                                         ,p_OE_ORDER_HEADER_ID	         => l_OE_ORDER_HEADER_ID
26577                                                         ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
26578                                                         ,p_rti_id	                     => L_RTI_ID
26579                                                         ,p_revision             	      => l_item_revision
26580                                                         ,p_subinventory_code  	      => L_SUB_CODE
26581                                                         ,p_locator_id           	      => l_loc_id
26582                                                         ,p_transaction_type           => l_transaction_type
26583                                                         ,p_parent_txn_type            => l_parent_txn_type
26584                                                         ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
26585                                                         );
26586 
26587                /*INVCONV ,*/
26588                IF (l_debug = 1) THEN
26589                   print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
26590                   print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
26591                END IF;
26592 
26593               IF (x_return_status <> 'S') THEN
26594                  --raise error
26595                  l_progress := 'WMSINB-26790';
26596                  RAISE fnd_api.g_exc_error;
26597               END IF;
26598 
26599               /*INVCONV ,*/
26600               IF (l_debug = 1) THEN
26601                  print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
26602               END IF;
26603 
26604                INV_ROI_INTEGRATION_GRP.INV_NEW_LOT(
26605                                                 x_return_status      		   => x_return_status
26606                                                ,x_msg_count          		   => x_msg_count
26607                                                ,x_msg_data           		   => x_msg_data
26608                                                ,p_api_version	               => 1.0
26609                                                ,p_init_msg_lst	               => FND_API.G_FALSE
26610                                                ,p_source_document_code			=> L_SOURCE_DOCUMENT_CODE
26611                                                ,p_item_id				         => l_item_id
26612                                                ,p_from_organization_id			=> L_FROM_ORG_ID
26613                                                ,p_to_organization_id	         => L_ORG_ID
26614                                                ,p_lot_number				      => L_MTLT_REC.lot_number
26615                                                ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
26616                                                ,p_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
26617                                                ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
26618                                                ,p_primary_unit_of_measure	   => l_rti_PRIMARY_UNIT_OF_MEASURE
26619                                                ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
26620                                                ,p_uom_code	                  => l_rti_UOM_CODE
26621                                                ,p_secondary_uom_code	         => l_rti_SECONDARY_UOM_CODE
26622                                                ,p_reason_id	                  => L_MTLT_REC.REASON_ID
26623                                                ,P_MLN_REC                     => L_MLN_REC
26624                                                ,p_mtlt_rowid	               => L_MTLT_REC.ROWID
26625                                                );
26626 
26627                /*INVCONV ,*/
26628                IF (l_debug = 1) THEN
26629                   print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
26630                   print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_NEW_LOT return status: '||x_return_status||' : '||l_progress, 1);
26631                END IF;
26632 
26633                IF X_RETURN_STATUS <> 'S' THEN
26634                   --RAISE ERROR
26635                   l_progress := 'WMSINB-26817';
26636                   RAISE fnd_api.g_exc_error;
26637                END IF;
26638 
26639 							IF (l_debug = 1) THEN
26640 							   print_debug('VALIDATE_LOT_SERIAL_INFO: VALIDATE_OPM_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
26641 							END IF;
26642 
26643 						    /*END IF; -- IF (l_discrete_transaction) THEN*/
26644 						  END IF; --IF (l_lot_exists = 1) THEN
26645 					    END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
26646 
26647 					    IF (l_serial_number_control_code IN (2,5,6)) THEN
26648 					       IF (l_debug = 1) THEN
26649 						  print_debug('VALIDATE_LOT_SERIAL_INFO: LOT AND SERIAL CONTROLLED: '||l_progress, 1);
26650 						  print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROL CODE: '||l_serial_number_control_code||' : '||l_progress, 1);
26651 						  print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||l_source_document_code||' : '||l_progress, 1);
26652 						  l_progress := 'WMSINB-26834';
26653 					       END IF;
26654 
26655 					       L_NUM_MSNT_RECS := 0;
26656 					       l_tot_msnt_serial_qty := 0;
26657 
26658 					       OPEN C_MSNT_LOTSERIAL(L_MTLT_REC.SERIAL_TRANSACTION_TEMP_ID);
26659 
26660 					       LOOP
26661 						  FETCH C_MSNT_LOTSERIAL INTO L_MSNT_REC;
26662 
26663 						  EXIT WHEN C_MSNT_LOTSERIAL%NOTFOUND;
26664 
26665 						  L_NUM_MSNT_RECS := L_NUM_MSNT_RECS + 1;
26666 
26667 						  L_SERIAL_QUANTITY :=
26668 						    INV_SERIAL_NUMBER_PUB.GET_SERIAL_DIFF(L_MSNT_REC.FM_SERIAL_NUMBER,
26669 											  L_MSNT_REC.TO_SERIAL_NUMBER);
26670 
26671 						  l_tot_msnt_serial_qty := l_tot_msnt_serial_qty + l_serial_quantity;
26672 
26673 						  INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.FM_SERIAL_NUMBER, L_TEMP_PREFIX, L_FROM_SER_NUMBER);
26674 		                                  INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.TO_SERIAL_NUMBER, L_TEMP_PREFIX, L_TO_SER_NUMBER);
26675 
26676 						  IF (l_debug = 1) THEN
26677 						     print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL QUANTITY: '||l_serial_quantity||' : '||l_progress, 1);
26678 						     l_progress := 'WMSINB-26859';
26679 						  END IF;
26680 
26681 						  --populate attributes table
26682 						  l_serial_attributes_tbl(1).column_name   := 'SERIAL_ATTRIBUTE_CATEGORY';
26683 						  l_serial_attributes_tbl(1).column_value  := l_msnt_rec.serial_attribute_category;
26684 						  l_serial_attributes_tbl(2).column_name   := 'ORIGINATION_DATE';
26685 						  l_serial_attributes_tbl(2).column_value  := l_msnt_rec.origination_date;
26686 						  l_serial_attributes_tbl(3).column_name   := 'C_ATTRIBUTE1';
26687 						  l_serial_attributes_tbl(3).column_value  := l_msnt_rec.c_attribute1;
26688 						  l_serial_attributes_tbl(4).column_name   := 'C_ATTRIBUTE2';
26689 						  l_serial_attributes_tbl(4).column_value  := l_msnt_rec.c_attribute2;
26690 						  l_serial_attributes_tbl(5).column_name   := 'C_ATTRIBUTE3';
26691 						  l_serial_attributes_tbl(5).column_value  := l_msnt_rec.c_attribute3;
26692 						  l_serial_attributes_tbl(6).column_name   := 'C_ATTRIBUTE4';
26693 						  l_serial_attributes_tbl(6).column_value   := l_msnt_rec.c_attribute4;
26694 						  l_serial_attributes_tbl(7).column_name   := 'C_ATTRIBUTE5';
26695 						  l_serial_attributes_tbl(7).column_value   := l_msnt_rec.c_attribute5;
26696 						  l_serial_attributes_tbl(8).column_name   := 'C_ATTRIBUTE6';
26697 						  l_serial_attributes_tbl(8).column_value   := l_msnt_rec.c_attribute6;
26698 						  l_serial_attributes_tbl(9).column_name   := 'C_ATTRIBUTE7';
26699 						  l_serial_attributes_tbl(9).column_value   := l_msnt_rec.c_attribute7;
26700 						  l_serial_attributes_tbl(10).column_name  := 'C_ATTRIBUTE8';
26701 						  l_serial_attributes_tbl(10).column_value  := l_msnt_rec.c_attribute8;
26702 						  l_serial_attributes_tbl(11).column_name  := 'C_ATTRIBUTE9';
26703 						  l_serial_attributes_tbl(11).column_value  := l_msnt_rec.c_attribute9;
26704 						  l_serial_attributes_tbl(12).column_name  := 'C_ATTRIBUTE10';
26705 						  l_serial_attributes_tbl(12).column_value  := l_msnt_rec.c_attribute10;
26706 						  l_serial_attributes_tbl(13).column_name  := 'C_ATTRIBUTE11';
26707 						  l_serial_attributes_tbl(13).column_value  := l_msnt_rec.c_attribute11;
26708 						  l_serial_attributes_tbl(14).column_name  := 'C_ATTRIBUTE12';
26709 						  l_serial_attributes_tbl(14).column_value  := l_msnt_rec.c_attribute12;
26710 						  l_serial_attributes_tbl(15).column_name  := 'C_ATTRIBUTE13';
26711 						  l_serial_attributes_tbl(15).column_value  := l_msnt_rec.c_attribute13;
26712 						  l_serial_attributes_tbl(16).column_name  := 'C_ATTRIBUTE14';
26713 						  l_serial_attributes_tbl(16).column_value  := l_msnt_rec.c_attribute14;
26714 						  l_serial_attributes_tbl(17).column_name  := 'C_ATTRIBUTE15';
26715 						  l_serial_attributes_tbl(17).column_value  := l_msnt_rec.c_attribute15;
26716 						  l_serial_attributes_tbl(18).column_name  := 'C_ATTRIBUTE16';
26717 						  l_serial_attributes_tbl(18).column_value  := l_msnt_rec.c_attribute16;
26718 						  l_serial_attributes_tbl(19).column_name  := 'C_ATTRIBUTE17';
26719 						  l_serial_attributes_tbl(19).column_value  := l_msnt_rec.c_attribute17;
26720 						  l_serial_attributes_tbl(20).column_name  := 'C_ATTRIBUTE18';
26721 						  l_serial_attributes_tbl(20).column_value  := l_msnt_rec.c_attribute18;
26722 						  l_serial_attributes_tbl(21).column_name  := 'C_ATTRIBUTE19';
26723 						  l_serial_attributes_tbl(21).column_value  := l_msnt_rec.c_attribute19;
26724 						  l_serial_attributes_tbl(22).column_name  := 'C_ATTRIBUTE20';
26725 						  l_serial_attributes_tbl(22).column_value  := l_msnt_rec.c_attribute20;
26726 						  l_serial_attributes_tbl(23).column_name  := 'D_ATTRIBUTE1';
26727 						  l_serial_attributes_tbl(23).column_value  := l_msnt_rec.d_attribute1;
26728 						  l_serial_attributes_tbl(24).column_name  := 'D_ATTRIBUTE2';
26729 						  l_serial_attributes_tbl(24).column_value  := l_msnt_rec.d_attribute2;
26730 						  l_serial_attributes_tbl(25).column_name  := 'D_ATTRIBUTE3';
26731 						  l_serial_attributes_tbl(25).column_value  := l_msnt_rec.d_attribute3;
26732 						  l_serial_attributes_tbl(26).column_name  := 'D_ATTRIBUTE4';
26733 						  l_serial_attributes_tbl(26).column_value  := l_msnt_rec.d_attribute4;
26734 						  l_serial_attributes_tbl(27).column_name  := 'D_ATTRIBUTE5';
26735 						  l_serial_attributes_tbl(27).column_value  := l_msnt_rec.d_attribute5;
26736 						  l_serial_attributes_tbl(28).column_name  := 'D_ATTRIBUTE6';
26737 						  l_serial_attributes_tbl(28).column_value  := l_msnt_rec.d_attribute6;
26738 						  l_serial_attributes_tbl(29).column_name  := 'D_ATTRIBUTE7';
26739 						  l_serial_attributes_tbl(29).column_value  := l_msnt_rec.d_attribute7;
26740 						  l_serial_attributes_tbl(30).column_name  := 'D_ATTRIBUTE8';
26741 						  l_serial_attributes_tbl(30).column_value  := l_msnt_rec.d_attribute8;
26742 						  l_serial_attributes_tbl(31).column_name  := 'D_ATTRIBUTE9';
26743 						  l_serial_attributes_tbl(31).column_value  := l_msnt_rec.d_attribute9;
26744 						  l_serial_attributes_tbl(32).column_name  := 'D_ATTRIBUTE10';
26745 						  l_serial_attributes_tbl(32).column_value  := l_msnt_rec.d_attribute10;
26746 						  l_serial_attributes_tbl(33).column_name  := 'N_ATTRIBUTE1';
26747 						  l_serial_attributes_tbl(33).column_value  := l_msnt_rec.n_attribute1;
26748 						  l_serial_attributes_tbl(34).column_name  := 'N_ATTRIBUTE2';
26749 						  l_serial_attributes_tbl(34).column_value  := l_msnt_rec.n_attribute2;
26750 						  l_serial_attributes_tbl(35).column_name  := 'N_ATTRIBUTE3';
26751 						  l_serial_attributes_tbl(35).column_value  := l_msnt_rec.n_attribute3;
26752 						  l_serial_attributes_tbl(36).column_name  := 'N_ATTRIBUTE4';
26753 						  l_serial_attributes_tbl(36).column_value  := l_msnt_rec.n_attribute4;
26754 						  l_serial_attributes_tbl(37).column_name  := 'N_ATTRIBUTE5';
26755 						  l_serial_attributes_tbl(37).column_value := l_msnt_rec.n_attribute5;
26756 						  l_serial_attributes_tbl(38).column_name  := 'N_ATTRIBUTE6';
26757 						  l_serial_attributes_tbl(38).column_value := l_msnt_rec.n_attribute6;
26758 						  l_serial_attributes_tbl(39).column_name  := 'N_ATTRIBUTE7';
26759 						  l_serial_attributes_tbl(39).column_value := l_msnt_rec.n_attribute7;
26760 						  l_serial_attributes_tbl(40).column_name  := 'N_ATTRIBUTE8';
26761 						  l_serial_attributes_tbl(40).column_value := l_msnt_rec.n_attribute8;
26762 						  l_serial_attributes_tbl(41).column_name  := 'N_ATTRIBUTE9';
26763 						  l_serial_attributes_tbl(41).column_value := l_msnt_rec.n_attribute9;
26764 						  l_serial_attributes_tbl(42).column_name  := 'N_ATTRIBUTE10';
26765 						  l_serial_attributes_tbl(42).column_value := l_msnt_rec.n_attribute10;
26766 						  l_serial_attributes_tbl(43).column_name  := 'STATUS_ID';
26767 						  l_serial_attributes_tbl(43).column_value := l_msnt_rec.status_id;
26768 						  l_serial_attributes_tbl(44).column_name  := 'TERRITORY_CODE';
26769 						  l_serial_attributes_tbl(44).column_value := l_msnt_rec.territory_code;
26770 
26771 						  --Validate the serials
26772 						  FOR SERIALQTY IN 1..L_SERIAL_QUANTITY LOOP
26773 
26774 						     l_progress := 'WMSINB-26865';
26775 
26776                                                      L_CUR_NUMBER := L_FROM_SER_NUMBER+SERIALQTY -1;
26777                                                      if L_FROM_SER_NUMBER = -1 and  L_TO_SER_NUMBER = -1 then
26778 	                                                  L_SERIAL_NUMBER  := L_MSNT_REC.fm_serial_number;
26779 		                                     else
26780 		                                          L_SERIAL_NUMBER :=
26781 			                                    SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
26782 				                              LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
26783 				                              LENGTH(L_CUR_NUMBER))
26784 			                                    ||L_CUR_NUMBER;
26785                                                      End if;
26786 
26787 						     --L_SERIAL_NUMBER :=
26788 						       --SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
26789 							      --LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
26790 							      --LENGTH(L_FROM_SER_NUMBER))
26791 						       --||(L_FROM_SER_NUMBER+SERIALQTY -1);
26792 
26793 						     l_progress := 'WMSINB-26873';
26794 
26795 		                                     BEGIN
26796 							SELECT CURRENT_ORGANIZATION_ID
26797 							  , current_status
26798 							  , lot_number
26799 							  , Decode(lpn_id,0,NULL,lpn_id)
26800 							  , inspection_status
26801 							  , group_mark_id
26802 							  INTO L_CURR_ORG_ID
26803 							  , l_curr_status
26804 							  , l_curr_lot_num
26805 							  , l_curr_lpn_id
26806 							  , l_inspection_status
26807 							  , l_group_mark_id
26808 							  FROM MTL_SERIAL_NUMBERS
26809 							  WHERE SERIAL_NUMBER = l_serial_number
26810 							  AND inventory_item_id = l_item_id;
26811 
26812 							l_serial_exists := 1;
26813 							l_progress := 'WMSINB-26893';
26814 						     EXCEPTION
26815 							WHEN no_data_found THEN
26816 							   l_serial_exists := 0;
26817 							   l_progress := 'WMSINB-26897';
26818 						     END;
26819 
26820 						     IF (l_debug = 1) THEN
26821 							print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL EXISTS: '||l_serial_exists||' : '||l_progress, 1);
26822 							print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NUMBER: '||l_serial_number||' : '||l_progress, 1);
26823 							print_debug('VALIDATE_LOT_SERIAL_INFO: CURR STATUS: '||l_curr_status||' : '||l_progress, 1);
26824 							print_debug('VALIDATE_LOT_SERIAL_INFO: CURR ORG ID: '||l_curr_org_id||' : '||l_progress, 1);
26825 							print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LPN ID: '||l_curr_lpn_id||' : '||l_progress, 1);
26826 							print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LOT NUM: '||l_curr_lot_num||' : '||l_progress, 1);
26827 							print_debug('VALIDATE_LOT_SERIAL_INFO: INSPECT STS: '||l_inspection_status||' : '||l_progress, 1);
26828 							print_debug('VALIDATE_LOT_SERIAL_INFO: GROUP MARK ID: '||l_group_mark_id||' : '||l_progress, 1);
26829 							print_debug('VALIDATE_LOT_SERIAL_INFO: RESTRICT RCPT SER: '||l_restrict_rcpt_ser||' : '||l_progress, 1);
26830 							l_progress := 'WMSINB-26910';
26831 						     END IF;
26832 
26833 						     IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
26834 							IF (l_grand_parent_txn_type <> 'DELIVER') THEN
26835 							   IF NOT (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
26836 							      --raise an error
26837 							      l_progress :=
26838 								'WMSINB-26915';
26839 							      RAISE fnd_api.g_exc_error;
26840 							    ELSE --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
26841 							       BEGIN
26842 								  SELECT '1'
26843 								    INTO L_DUMMY
26844 								    FROM RCV_SERIALS_SUPPLY
26845 								    WHERE TRANSACTION_ID = l_grand_parent_txn_id
26846 								    AND SERIAL_NUM = L_SERIAL_NUMBER;
26847 
26848 								  IF (l_curr_status <> 7) THEN
26849 								     --raise error
26850 								     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26851 								     fnd_msg_pub.ADD;
26852 								     l_progress := 'WMSINB-26931';
26853 								     RAISE fnd_api.g_exc_error;
26854 								  END IF;
26855 
26856 								  --Validate serial/group_mark_id to prevent
26857 								  --entering of duplicate serials
26858 
26859 								  IF (Nvl(l_group_mark_id, -99) = -7937) THEN
26860 								     --raise error
26861 								     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26862 								     fnd_msg_pub.ADD;
26863 								     l_progress := 'WMSINB-26942';
26864 								     RAISE fnd_api.g_exc_error;
26865 								  END IF;
26866 
26867 								  --UPDATE GROUP_MARK_ID TO -7937
26868 								  IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
26869 								     --raise error
26870 								     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26871 								     fnd_msg_pub.ADD;
26872 								     l_progress := 'WMSINB-26951';
26873 								     RAISE fnd_api.g_exc_error;
26874 								  END IF;
26875 							       EXCEPTION
26876 								  WHEN NO_DATA_FOUND THEN
26877 								     -- RAISE ERROR
26878 								     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26879 								     fnd_msg_pub.ADD;
26880 								     l_progress := 'WMSINB-26959';
26881 								     RAISE fnd_api.g_exc_error;
26882 							       END;
26883 							   END IF; --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
26884 							 ELSE --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
26885 							      IF l_curr_org_id <> l_org_id THEN
26886 								 --raise error
26887 								 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26888 								 fnd_msg_pub.ADD;
26889 								 l_progress := 'WMSINB-26968';
26890 								 RAISE fnd_api.g_exc_error;
26891 							       ELSE
26892 								 IF
26893 								   ((l_curr_lot_num IS NOT NULL) AND (l_curr_lot_num <> l_mtlt_rec.lot_number)
26894 								    AND
26895 								    (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
26896 								    --raise error
26897 								    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26898 								    fnd_msg_pub.ADD;
26899 								    l_progress := 'WMSINB-26975';
26900 								    RAISE fnd_api.g_exc_error;
26901 								 END IF;
26902 							      END IF;
26903 
26904 							      IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
26905 								 IF l_curr_status NOT IN (1,6) THEN
26906 								    --raise error
26907 								    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26908 								    fnd_msg_pub.ADD;
26909 								    l_progress := 'WMSINB-26985';
26910 								    RAISE fnd_api.g_exc_error;
26911 								 END IF;
26912 							       ELSE --IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
26913 								 IF (l_curr_status <> 3) THEN
26914 								    --raise error
26915 								    fnd_message.set_name('INV','INV_FAIL_VALIDATE_SERIAL');
26916 								    fnd_msg_pub.ADD;
26917 								    l_progress := 'WMSINB-26993';
26918 								    RAISE fnd_api.g_exc_error;
26919 								 END IF;
26920 							      END IF; --IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
26921 
26922 							      IF (Nvl(l_group_mark_id, -99) = -7937) THEN
26923 								 --raise error
26924 								 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26925 								 fnd_msg_pub.ADD;
26926 								 l_progress := 'WMSINB-27002';
26927 								 RAISE fnd_api.g_exc_error;
26928 							      END IF;
26929 
26930 				IF (Nvl(l_curr_status, 1) in (1,6)) THEN
26931 				   --validate and update the attributes.
26932 				   inv_serial_number_pub.validate_update_serial_att
26933 				     (x_return_status     => x_return_status,
26934 				      x_msg_count         => x_msg_count,
26935 				      x_msg_data          => x_msg_data,
26936 				      x_validation_status => l_validation_status,
26937 				      p_serial_number     => l_serial_number,
26938 				      p_organization_id   => l_org_id,
26939 				      p_inventory_item_id => l_item_id,
26940 				      p_serial_att_tbl    => l_serial_attributes_tbl,
26941 				      p_validate_only     => FALSE
26942 				      );
26943 
26944 				   IF (l_validation_status <> 'Y'
26945 				       OR x_return_status <> g_ret_sts_success) THEN
26946 				      --raise error
26947 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26948 				      fnd_msg_pub.ADD;
26949 				      l_progress := 'WMSINB-27008';
26950 				      RAISE fnd_api.g_exc_error;
26951 				   END IF;
26952 				END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
26953 
26954 							      --UPDATE GROUP_MARK_ID TO -7937
26955 							      IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
26956 								 --raise error
26957 								 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26958 								 fnd_msg_pub.ADD;
26959 								 l_progress := 'WMSINB-27011';
26960 								 RAISE fnd_api.g_exc_error;
26961 							      END IF;
26962 							END IF; --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
26963 						      ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
26964 							   IF (l_parent_txn_type <> 'RECEIVE') THEN
26965 							      IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
26966 							         BEGIN
26967 								    SELECT '1'
26968 								      INTO L_DUMMY
26969 								      FROM RCV_SERIALS_SUPPLY
26970 								      WHERE TRANSACTION_ID = l_grand_parent_txn_id
26971 								      AND SERIAL_NUM = L_SERIAL_NUMBER;
26972 
26973 								    IF (l_curr_status <> 7) THEN
26974 								       --raise error
26975 								       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26976 								       fnd_msg_pub.ADD;
26977 								       l_progress := 'WMSINB-27029';
26978 								       RAISE fnd_api.g_exc_error;
26979 								    END IF;
26980 
26981 								    --Validate serial/group_mark_id to prevent
26982 								    --entering of duplicate serials
26983 
26984 								    IF (Nvl(l_group_mark_id, -99) = -7937) THEN
26985 								       --raise error
26986 								       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26987 								       fnd_msg_pub.ADD;
26988 								       l_progress := 'WMSINB-27040';
26989 								       RAISE fnd_api.g_exc_error;
26990 								    END IF;
26991 
26992 								    --UPDATE GROUP_MARK_ID TO -7937
26993 								    IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
26994 								       --raise error
26995 								       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26996 								       fnd_msg_pub.ADD;
26997 								       l_progress := 'WMSINB-27049';
26998 								       RAISE fnd_api.g_exc_error;
26999 								    END IF;
27000 								 EXCEPTION
27001 								    WHEN NO_DATA_FOUND THEN
27002 								       -- RAISE ERROR
27003 								       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27004 								       fnd_msg_pub.ADD;
27005 								       l_progress := 'WMSINB-27057';
27006 								       RAISE fnd_api.g_exc_error;
27007 								 END;
27008 							       ELSE --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
27009 								       IF (l_serial_exists = 1) THEN
27010 									  IF l_curr_org_id <> l_org_id THEN
27011 									     --raise error
27012 									     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27013 									     fnd_msg_pub.ADD;
27014 									     l_progress := 'WMSINB-27066';
27015 									     RAISE fnd_api.g_exc_error;
27016 									   ELSE
27017 									     IF ((l_curr_lot_num IS NOT NULL) AND (l_curr_lot_num <> l_mtlt_rec.lot_number)
27018 										 AND (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
27019 										--raise error
27020 										fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27021 										fnd_msg_pub.ADD;
27022 										l_progress := 'WMSINB-27073';
27023 										RAISE fnd_api.g_exc_error;
27024 									     END IF;
27025 									  END IF;
27026 
27027 									/* Bug#6450814
27028 									   * In order to receive the Issued out Serial numbers during
27029 									   * Positive Correction transaction made the following changes.
27030 									   */
27031 									  IF l_curr_status NOT IN (1,4,6) THEN--Bug: 6450814
27032 									     --raise error
27033 									     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27034 									     fnd_msg_pub.ADD;
27035 									     l_progress := 'WMSINB-27082';
27036 									     RAISE fnd_api.g_exc_error;
27037 									  END IF;
27038 
27039 									  IF (Nvl(l_group_mark_id, -99) = -7937) THEN
27040 									     --raise error
27041 									     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27042 									     fnd_msg_pub.ADD;
27043 									     l_progress := 'WMSINB-27090';
27044 									     RAISE fnd_api.g_exc_error;
27045 									  END IF;
27046 
27047 				IF (Nvl(l_curr_status, 1) in (1,6)) THEN
27048 				   --validate and update the attributes.
27049 				   inv_serial_number_pub.validate_update_serial_att
27050 				     (x_return_status     => x_return_status,
27051 				      x_msg_count         => x_msg_count,
27052 				      x_msg_data          => x_msg_data,
27053 				      x_validation_status => l_validation_status,
27054 				      p_serial_number     => l_serial_number,
27055 				      p_organization_id   => l_org_id,
27056 				      p_inventory_item_id => l_item_id,
27057 				      p_serial_att_tbl    => l_serial_attributes_tbl,
27058 				      p_validate_only     => FALSE
27059 				      );
27060 
27061 				   IF (l_validation_status <> 'Y'
27062 				       OR x_return_status <> g_ret_sts_success) THEN
27063 				      --raise error
27064 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27065 				      fnd_msg_pub.ADD;
27066 				      l_progress := 'WMSINB-27095';
27067 				      RAISE fnd_api.g_exc_error;
27068 				   END IF;
27069 				END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
27070 
27071 									  --UPDATE GROUP_MARK_ID TO -7937
27072 									  IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
27073 									     --raise error
27074 									     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27075 									     fnd_msg_pub.ADD;
27076 									     l_progress := 'WMSINB-27099';
27077 									     RAISE fnd_api.g_exc_error;
27078 									  END IF;
27079 									ELSE --IF (l_serial_exists = 1) THEN
27080 									  IF l_serial_number_control_code = 5 THEN
27081 									     --PERFORM SERIAL VALIDATION FOR NEW SERIAL
27082 									     --(INCLUDING ATT VALIDATION)
27083 									     --CREATE MSN
27084 									     IF (l_transaction_type = 'CORRECT') THEN
27085 										l_transaction_action_id := 29;
27086 									      ELSE
27087 										l_transaction_action_id := 1;
27088 									     END IF;
27089 
27090 									     inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
27091 														       , p_inventory_item_id => l_item_id
27092 														       , p_organization_id => l_org_id
27093 														       , p_from_serial_number => l_serial_number
27094 														       , p_to_serial_number => l_serial_number
27095 														       , p_initialization_date => SYSDATE
27096 														       , p_completion_date => NULL
27097 														       , p_ship_date => NULL
27098 														       , p_revision => l_item_revision
27099 														       , p_lot_number => l_mtlt_rec.lot_number
27100 														       , p_current_locator_id => l_loc_id
27101 														       , p_subinventory_code => l_sub_code
27102 														       , p_trx_src_id => NULL
27103 														       , p_unit_vendor_id => NULL
27104 														       , p_vendor_lot_number => l_mtlt_rec.supplier_lot_number
27105 														       , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
27106 														       , p_receipt_issue_type => NULL
27107 														       , p_txn_src_id => NULL
27108 														       , p_txn_src_name => NULL
27109 									       , p_txn_src_type_id => NULL
27110 									       , p_transaction_id => NULL
27111 									       , p_current_status => 1
27112 									       , p_parent_item_id => NULL
27113 									       , p_parent_serial_number => NULL
27114 									       , p_cost_group_id => NULL
27115 									       , p_transaction_action_id => l_transaction_action_id
27116 									       , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
27117 									       , p_status_id => NULL
27118 									       , p_inspection_status => NULL
27119 									       , x_object_id => l_object_id
27120 									       , x_return_status => x_return_status
27121 									       , x_msg_count => x_msg_count
27122 									       , x_msg_data => x_msg_data);
27123 
27124 									     IF (x_return_status <> g_ret_sts_success) THEN
27125 										--raise error
27126 										fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27127 										fnd_msg_pub.ADD;
27128 										l_progress := 'WMSINB-27105';
27129 										RAISE fnd_api.g_exc_error;
27130 									     END IF;
27131 
27132 									     --validate and update the attributes.
27133 									     inv_serial_number_pub.validate_update_serial_att
27134 									       (x_return_status     => x_return_status,
27135 										x_msg_count         => x_msg_count,
27136 										x_msg_data          => x_msg_data,
27137 										x_validation_status => l_validation_status,
27138 										p_serial_number     => l_serial_number,
27139 										p_organization_id   => l_org_id,
27140 										p_inventory_item_id => l_item_id,
27141 										p_serial_att_tbl    => l_serial_attributes_tbl,
27142 										p_validate_only     => FALSE
27143 										);
27144 
27145 									     IF (l_validation_status <> 'Y'
27146 										 OR x_return_status <> g_ret_sts_success) THEN
27147 										--raise error
27148 										fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27149 										fnd_msg_pub.ADD;
27150 										l_progress := 'WMSINB-27145';
27151 										RAISE fnd_api.g_exc_error;
27152 									     END IF;
27153 
27154 									     --UPDATE GROUP_MARK_ID TO -7937
27155 									     IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
27156 										--raise error
27157 										fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27158 										fnd_msg_pub.ADD;
27159 										l_progress := 'WMSINB-27152';
27160 										RAISE fnd_api.g_exc_error;
27161 									     END IF;
27162 									   ELSE --IF l_serial_number_control_code = 5 THEN
27163 									     --raise error
27164 									     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27165 									     fnd_msg_pub.ADD;
27166 									     l_progress := 'WMSINB-27159';
27167 									     RAISE fnd_api.g_exc_error;
27168 									  END IF; --IF l_serial_number_control_code = 5 THEN
27169 								       END IF; --IF (l_serial_exists = 1) THEN
27170 							      END IF; --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
27171 							    ELSE --IF (l_parent_txn_type <> 'RECEIVE') THEN
27172 								 IF (l_serial_exists = 1) THEN
27173 								    IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
27174 								       -- CHECK TO SEE IF THE ITEM IS SERIAL
27175 								       -- CONTROLLED IN SOURCE ORG
27176 
27177 								       GET_SERIAL_LOT_CTRL_IN_SRC_ORG
27178 									 (L_SHIPMENT_LINE_ID, L_ORG_ID,
27179 									  L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
27180 									  l_from_org_rev_ctrl, X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
27181 
27182 								       IF ((L_FROM_ORG_SER_CRTL IN (2,5,6)
27183 									    AND l_source_document_code = 'REQ')
27184 									   OR (l_from_org_ser_crtl IN (2,5)
27185 									       AND l_source_document_code = 'INVENTORY')
27186 									   ) THEN
27187 									  IF l_curr_org_id <> l_from_org_id THEN
27188 									     --raise error
27189 									     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27190 									     fnd_msg_pub.ADD;
27191 									     l_progress := 'WMSINB-27180';
27192 									     RAISE fnd_api.g_exc_error;
27193 									   ELSE --IF l_curr_org_id <> l_from_org_id THEN
27194 									     IF ((l_curr_lot_num IS NOT NULL) AND
27195 										 (l_curr_lot_num <> l_mtlt_rec.lot_number)
27196 										 AND (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
27197 										--raise error
27198 										fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27199 										fnd_msg_pub.ADD;
27200 										l_progress := 'WMSINB-27188';
27201 										RAISE fnd_api.g_exc_error;
27202 									     END IF;
27203 									  END IF; --IF l_curr_org_id <> l_from_org_id THEN
27204 
27205 								          BEGIN
27206 									     SELECT '1'
27207 									       INTO L_DUMMY
27208 									       FROM rcv_serials_supply rss
27209 									       , rcv_shipment_lines rsl
27210 									       WHERE rss.SHIPMENT_LINE_ID = rsl.SHIPMENT_LINE_ID
27211 									       AND rsl.shipment_header_id = l_shipment_header_id
27212 									       AND rsl.item_id = l_item_id
27213 									       AND rss.SUPPLY_TYPE_CODE = 'SHIPMENT'
27214 									       AND rss.serial_num = l_serial_number;
27215 
27216 									     IF L_CURR_STATUS <> 5 THEN
27217 										-- RAISE AN ERROR
27218 										fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27219 										fnd_msg_pub.ADD;
27220 										l_progress := 'WMSINB-27205';
27221 										RAISE fnd_api.g_exc_error;
27222 									     END IF;
27223 
27224 									  EXCEPTION
27225 									     WHEN NO_DATA_FOUND THEN
27226 										-- RAISE AN ERROR
27227 										fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27228 										fnd_msg_pub.ADD;
27229 										l_progress := 'WMSINB-27214';
27230 										RAISE fnd_api.g_exc_error;
27231 									  END;
27232 									ELSE --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
27233 										IF l_curr_org_id <> l_org_id THEN
27234 										   --raise error
27235 										   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27236 										   fnd_msg_pub.ADD;
27237 										   l_progress := 'WMSINB-27222';
27238 										   RAISE fnd_api.g_exc_error;
27239 										 ELSE
27240 										   IF ((l_curr_lot_num IS NOT NULL) AND (l_curr_lot_num <> l_mtlt_rec.lot_number)
27241 										       AND (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
27242 										      --raise error
27243 										      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27244 										      fnd_msg_pub.ADD;
27245 										      l_progress := 'WMSINB-27229';
27246 										      RAISE fnd_api.g_exc_error;
27247 										   END IF;
27248 										END IF;
27249 
27250 										IF l_curr_status NOT IN (1,6) THEN
27251 										   --raise error
27252 										   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27253 										   fnd_msg_pub.ADD;
27254 										   l_progress := 'WMSINB-27238';
27255 										   RAISE fnd_api.g_exc_error;
27256 										END IF;
27257 
27258 										IF (Nvl(l_group_mark_id, -99) = -7937) THEN
27259 										   --raise error
27260 										   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27261 										   fnd_msg_pub.ADD;
27262 										   l_progress := 'WMSINB-27246';
27263 										   RAISE fnd_api.g_exc_error;
27264 										END IF;
27265 
27266 				IF (Nvl(l_curr_status, 1) in (1,6)) THEN
27267 				   --validate and update the attributes.
27268 				   inv_serial_number_pub.validate_update_serial_att
27269 				     (x_return_status     => x_return_status,
27270 				      x_msg_count         => x_msg_count,
27271 				      x_msg_data          => x_msg_data,
27272 				      x_validation_status => l_validation_status,
27273 				      p_serial_number     => l_serial_number,
27274 				      p_organization_id   => l_org_id,
27275 				      p_inventory_item_id => l_item_id,
27276 				      p_serial_att_tbl    => l_serial_attributes_tbl,
27277 				      p_validate_only     => FALSE
27278 				      );
27279 
27280 				   IF (l_validation_status <> 'Y'
27281 				       OR x_return_status <> g_ret_sts_success) THEN
27282 				      --raise error
27283 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27284 				      fnd_msg_pub.ADD;
27285 				      l_progress := 'WMSINB-27251';
27286 				      RAISE fnd_api.g_exc_error;
27287 				   END IF;
27288 				END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
27289 
27290 										--UPDATE GROUP_MARK_ID TO -7937
27291 										IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
27292 										   --raise error
27293 										   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27294 										   fnd_msg_pub.ADD;
27295 										   l_progress := 'WMSINB-27255';
27296 										   RAISE fnd_api.g_exc_error;
27297 										END IF;
27298 								       END IF; --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
27299 								     ELSE --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
27300 									  IF l_curr_org_id <> l_org_id THEN
27301 									     --raise error
27302 									     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27303 									     fnd_msg_pub.ADD;
27304 									     l_progress := 'WMSINB-27264';
27305 									     RAISE fnd_api.g_exc_error;
27306 									   ELSE
27307 									     IF ((l_curr_lot_num IS NOT NULL) AND (l_curr_lot_num <> l_mtlt_rec.lot_number)
27308 										 AND (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
27309 										--raise error
27310 										fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27311 										fnd_msg_pub.ADD;
27312 										l_progress := 'WMSINB-27271';
27313 										RAISE fnd_api.g_exc_error;
27314 									     END IF;
27315 									  END IF;
27316 
27317 									  IF l_curr_status NOT IN (1,4,6) THEN--Bug: 6450814
27318 									     --raise error
27319 									     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27320 									     fnd_msg_pub.ADD;
27321 									     l_progress := 'WMSINB-27280';
27322 									     RAISE fnd_api.g_exc_error;
27323 									  END IF;
27324 
27325 									  IF (Nvl(l_group_mark_id, -99) = -7937) THEN
27326 									     --raise error
27327 									     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27328 									     fnd_msg_pub.ADD;
27329 									     l_progress := 'WMSINB-27288';
27330 									     RAISE fnd_api.g_exc_error;
27331 									  END IF;
27332 
27333 				IF (Nvl(l_curr_status, 1) in (1,6)) THEN
27334 				   --validate and update the attributes.
27335 				   inv_serial_number_pub.validate_update_serial_att
27336 				     (x_return_status     => x_return_status,
27337 				      x_msg_count         => x_msg_count,
27338 				      x_msg_data          => x_msg_data,
27339 				      x_validation_status => l_validation_status,
27340 				      p_serial_number     => l_serial_number,
27341 				      p_organization_id   => l_org_id,
27342 				      p_inventory_item_id => l_item_id,
27343 				      p_serial_att_tbl    => l_serial_attributes_tbl,
27344 				      p_validate_only     => FALSE
27345 				      );
27346 
27347 				   IF (l_validation_status <> 'Y'
27348 				       OR x_return_status <> g_ret_sts_success) THEN
27349 				      --raise error
27350 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27351 				      fnd_msg_pub.ADD;
27352 				      l_progress := 'WMSINB-27294';
27353 				      RAISE fnd_api.g_exc_error;
27354 				   END IF;
27355 				END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
27356 
27357 									  --UPDATE GROUP_MARK_ID TO -7937
27358 									  IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
27359 									     --raise error
27360 									     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27361 									     fnd_msg_pub.ADD;
27362 									     l_progress := 'WMSINB-27297';
27363 									     RAISE fnd_api.g_exc_error;
27364 									  END IF;
27365 								    END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
27366 								  ELSE --IF (l_serial_exists = 1) THEN
27367 								       IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
27368 									  -- CHECK TO SEE IF THE ITEM IS SERIAL
27369 									  -- CONTROLLED IN SOURCE ORG
27370 
27371 									  GET_SERIAL_LOT_CTRL_IN_SRC_ORG
27372 									    (L_SHIPMENT_LINE_ID, L_ORG_ID,
27373 									     L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
27374 									     l_from_org_rev_ctrl, X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
27375 
27376 									  IF ((L_FROM_ORG_SER_CRTL IN (2,5,6)
27377 									       AND l_source_document_code = 'REQ')
27378 									      OR (l_from_org_ser_crtl IN (2,5)
27379 										  AND l_source_document_code = 'INVENTORY')
27380 									      ) THEN
27381 									     --raise error
27382 									     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27383 									     fnd_msg_pub.ADD;
27384 									     l_progress := 'WMSINB-27315';
27385 									     RAISE fnd_api.g_exc_error;
27386 									  END IF; --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
27387 								       END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
27388 
27389 								       IF l_serial_number_control_code = 5 THEN
27390 									  --PERFORM SERIAL VALIDATION FOR NEW SERIAL
27391 									  --(INCLUDING ATT VALIDATION)
27392 									  --CREATE MSN
27393 									  IF (l_transaction_type = 'CORRECT') THEN
27394 									     l_transaction_action_id := 29;
27395 									   ELSE
27396 									     l_transaction_action_id := 1;
27397 									  END IF;
27398 
27399 									  inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
27400 														    , p_inventory_item_id => l_item_id
27401 														    , p_organization_id => l_org_id
27402 														    , p_from_serial_number => l_serial_number
27403 														    , p_to_serial_number => l_serial_number
27404 														    , p_initialization_date => SYSDATE
27405 														    , p_completion_date => NULL
27406 														    , p_ship_date => NULL
27407 														    , p_revision => l_item_revision
27408 														    , p_lot_number => l_mtlt_rec.lot_number
27409 														    , p_current_locator_id => l_loc_id
27410 														    , p_subinventory_code => l_sub_code
27411 														    , p_trx_src_id => NULL
27412 														    , p_unit_vendor_id => NULL
27413 														    , p_vendor_lot_number => l_mtlt_rec.supplier_lot_number
27414 														    , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
27415 														    , p_receipt_issue_type => NULL
27416 														    , p_txn_src_id => NULL
27417 														    , p_txn_src_name => NULL
27418 														    , p_txn_src_type_id => NULL
27419 									    , p_transaction_id => NULL
27420 									    , p_current_status => 1
27421 									    , p_parent_item_id => NULL
27422 									    , p_parent_serial_number => NULL
27423 									    , p_cost_group_id => NULL
27424 									    , p_transaction_action_id => l_transaction_action_id
27425 									    , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
27426 									    , p_status_id => NULL
27427 									    , p_inspection_status => NULL
27428 									    , x_object_id => l_object_id
27429 									    , x_return_status => x_return_status
27430 									    , x_msg_count => x_msg_count
27431 									    , x_msg_data => x_msg_data);
27432 
27433 					 IF (x_return_status <> g_ret_sts_success) THEN
27434 					    --raise error
27435 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27436 					    fnd_msg_pub.ADD;
27437 					    l_progress := 'WMSINB-27320';
27438 					    RAISE fnd_api.g_exc_error;
27439 					 END IF;
27440 
27441 					 --validate and update the attributes.
27442 					 inv_serial_number_pub.validate_update_serial_att
27443 					   (x_return_status     => x_return_status,
27444 					    x_msg_count         => x_msg_count,
27445 					    x_msg_data          => x_msg_data,
27446 					    x_validation_status => l_validation_status,
27447 					    p_serial_number     => l_serial_number,
27448 					    p_organization_id   => l_org_id,
27449 					    p_inventory_item_id => l_item_id,
27450 					    p_serial_att_tbl    => l_serial_attributes_tbl,
27451 					    p_validate_only     => FALSE
27452 					    );
27453 
27454 					 IF (l_validation_status <> 'Y'
27455 					     OR x_return_status <> g_ret_sts_success) THEN
27456 					    --raise error
27457 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27458 					    fnd_msg_pub.ADD;
27459 					    l_progress := 'WMSINB-27360';
27460 					    RAISE fnd_api.g_exc_error;
27461 					 END IF;
27462 
27463 									  --UPDATE GROUP_MARK_ID TO -7937
27464 									  IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
27465 									     --raise error
27466 									     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27467 									     fnd_msg_pub.ADD;
27468 									     l_progress := 'WMSINB-27369';
27469 									     RAISE fnd_api.g_exc_error;
27470 									  END IF;
27471 									ELSE --IF l_serial_number_control_code = 5 THEN
27472 									  --raise error
27473 									  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27474 									  fnd_msg_pub.ADD;
27475 									  l_progress := 'WMSINB-27376';
27476 									  RAISE fnd_api.g_exc_error;
27477 								       END IF; --IF l_serial_number_control_code = 5 THEN
27478 								 END IF; --IF (l_serial_exists = 1) THEN
27479 							   END IF; --IF (l_parent_txn_type <> 'RECEIVE') THEN
27480 						     END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
27481 						  END LOOP; -- FOR 1..L_SERIAL_QUANTITY
27482 					       END LOOP; --FETCH C_MSNT_LOTSERIAL INTO L_MSNT_REC;
27483 
27484 					       CLOSE c_msnt_lotserial;
27485 
27486 					       IF (l_num_msnt_recs > 0) THEN
27487 						  IF l_mtlt_rec.primary_quantity <> l_tot_msnt_serial_qty THEN
27488 						     --raise error
27489 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27490 						     fnd_msg_pub.ADD;
27491 						     l_progress := 'WMSINB-27392';
27492 						     RAISE fnd_api.g_exc_error;
27493 						  END IF;
27494 						ELSE
27495 						  IF (l_serial_number_control_code IN (2,5)
27496 						      OR (l_serial_number_control_code = 6
27497 							  AND l_source_document_code IN ('RMA','REQ','INVENTORY'))) THEN
27498 						     --raise error
27499 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27500 						     fnd_msg_pub.ADD;
27501 						     l_progress := 'WMSINB-27399';
27502 						     RAISE fnd_api.g_exc_error;
27503 						  END IF;
27504 					       END IF;
27505 
27506 					    END IF; -- IF (L_SERIAL_NUMBER_CONTROL_CODE IN (2,5,6)) THEN
27507 					 END LOOP; --FETCH C_MTLT INTO L_MTLT_REC;
27508 
27509 					 CLOSE c_mtlt;
27510 
27511                                        /* Bug 4546519 : l_tot_mtlt_prim_qty is a computed floating point number.
27512                                         **  In the following condition, it is necessary to use round function for
27513                                         **  comparing the floating point values.
27514                                         */
27515 
27516 					 IF (l_num_mtlt_recs > 0) THEN
27517 					    IF (ROUND(l_tot_mtlt_prim_qty,5) <> ROUND(l_rti_primary_qty,5)) THEN
27518 						-- Bug# 4225766 Compare transaction qty there can be a difference in primary qty
27519 						-- if there is a lot specific conversion
27520 						IF (ROUND(l_tot_mtlt_trans_qty,5) <> ROUND(l_rti_trans_qty,5)) THEN -- Bug# 4225766
27521 							--raise error
27522 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27523 							fnd_msg_pub.ADD;
27524 							l_progress := 'WMSINB-27413';
27525 							RAISE fnd_api.g_exc_error;
27526 						END IF; -- Bug# 4225766
27527 					    END IF;
27528 					  ELSE
27529 					    IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
27530 					       IF (l_grand_parent_txn_type = 'DELIVER') THEN
27531 						  --raise an error
27532 						  l_progress := 'WMSINB-27420';
27533 						  RAISE fnd_api.g_exc_error;
27534 						ELSE
27535 						  IF (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
27536 						     --raise error;
27537 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27538 						     fnd_msg_pub.ADD;
27539 						     l_progress := 'WMSINB-27427';
27540 						     RAISE fnd_api.g_exc_error;
27541 						  END IF;
27542 					       END IF; --IF (l_grand_parent_txn_type = 'DELIVER') THEN
27543 					     ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
27544 					       IF (l_parent_txn_type <> 'DELIVER') THEN
27545 						  IF (validate_rs(NULL,l_parent_transaction_id,l_dummy_lpn)) THEN
27546 						     IF (lot_entered_on_parent(l_parent_transaction_id)) THEN
27547 							--raise an error
27548 							l_progress := 'WMSINB-27436';
27549 							RAISE fnd_api.g_exc_error;
27550 						     END IF;
27551 						   ELSE --IF (validate_rs(NULL,l_parent_transaction_id,l_dummy_lpn)) THEN
27552 						     IF (l_parent_txn_type <> 'RECEIVE') THEN
27553 							IF (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
27554 							   --raise an error
27555 							   l_progress := 'WMSINB-27443';
27556 							   RAISE fnd_api.g_exc_error;
27557 							END IF;
27558 						     END IF;
27559 						  END IF; --IF (validate_rs(NULL,l_parent_transaction_id,l_dummy_lpn)) THEN
27560 						ELSE --IF (l_parent_txn_type <> 'DELIVER') THEN
27561 						  --raise an error
27562 						  l_progress := 'WMSINB-27450';
27563 						  RAISE fnd_api.g_exc_error;
27564 					       END IF; -- IF (l_parent_txn_type <> 'DELIVER') THEN
27565 					    END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
27566 					 END IF; --IF (l_num_mtlt_recs > 0) THEN
27567 				       ELSIF (l_serial_number_control_code IN (2,5,6)) THEN --IF (l_lot_control_code = 2) THEN
27568 							   IF (l_debug = 1) THEN
27569 							      print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROLLED: '||l_progress, 1);
27570 							      print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROL CODE: '||l_serial_number_control_code||' : '||l_progress, 1);
27571 							      print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||l_source_document_code||' : '||l_progress, 1);
27572 							      l_progress := 'WMSINB-27460';
27573 							   END IF;
27574 
27575 							   L_NUM_MSNT_RECS := 0;
27576 							   l_tot_msnt_serial_qty := 0;
27577 
27578 							   OPEN C_MSNT(L_RTI_ID);
27579 
27580 							   LOOP
27581 							      FETCH C_MSNT INTO L_MSNT_REC;
27582 
27583 							      EXIT WHEN C_MSNT%NOTFOUND;
27584 
27585 							      L_NUM_MSNT_RECS := L_NUM_MSNT_RECS + 1;
27586 
27587 							      L_SERIAL_QUANTITY :=
27588 								INV_SERIAL_NUMBER_PUB.GET_SERIAL_DIFF(L_MSNT_REC.FM_SERIAL_NUMBER,
27589 												      L_MSNT_REC.TO_SERIAL_NUMBER);
27590 
27591 							      l_tot_msnt_serial_qty := l_tot_msnt_serial_qty + l_serial_quantity;
27592 
27593 							      INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.FM_SERIAL_NUMBER, L_TEMP_PREFIX, L_FROM_SER_NUMBER);
27594 		                                              INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.TO_SERIAL_NUMBER, L_TEMP_PREFIX, L_TO_SER_NUMBER);
27595 
27596 							      IF (l_debug = 1) THEN
27597 								 print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL QUANTITY: '||l_serial_quantity||' : '||l_progress, 1);
27598 								 l_progress := 'WMSINB-27485';
27599 							      END IF;
27600 
27601 							      --populate attributes table
27602 							      l_serial_attributes_tbl(1).column_name   := 'SERIAL_ATTRIBUTE_CATEGORY';
27603 							      l_serial_attributes_tbl(1).column_value  := l_msnt_rec.serial_attribute_category;
27604 							      l_serial_attributes_tbl(2).column_name   := 'ORIGINATION_DATE';
27605 							      l_serial_attributes_tbl(2).column_value  := l_msnt_rec.origination_date;
27606 							      l_serial_attributes_tbl(3).column_name   := 'C_ATTRIBUTE1';
27607 							      l_serial_attributes_tbl(3).column_value  := l_msnt_rec.c_attribute1;
27608 							      l_serial_attributes_tbl(4).column_name   := 'C_ATTRIBUTE2';
27609 							      l_serial_attributes_tbl(4).column_value  := l_msnt_rec.c_attribute2;
27610 							      l_serial_attributes_tbl(5).column_name   := 'C_ATTRIBUTE3';
27611 							      l_serial_attributes_tbl(5).column_value  := l_msnt_rec.c_attribute3;
27612 							      l_serial_attributes_tbl(6).column_name   := 'C_ATTRIBUTE4';
27613 							      l_serial_attributes_tbl(6).column_value   := l_msnt_rec.c_attribute4;
27614 							      l_serial_attributes_tbl(7).column_name   := 'C_ATTRIBUTE5';
27615 							      l_serial_attributes_tbl(7).column_value   := l_msnt_rec.c_attribute5;
27616 							      l_serial_attributes_tbl(8).column_name   := 'C_ATTRIBUTE6';
27617 							      l_serial_attributes_tbl(8).column_value   := l_msnt_rec.c_attribute6;
27618 							      l_serial_attributes_tbl(9).column_name   := 'C_ATTRIBUTE7';
27619 							      l_serial_attributes_tbl(9).column_value   := l_msnt_rec.c_attribute7;
27620 							      l_serial_attributes_tbl(10).column_name  := 'C_ATTRIBUTE8';
27621 							      l_serial_attributes_tbl(10).column_value  := l_msnt_rec.c_attribute8;
27622 							      l_serial_attributes_tbl(11).column_name  := 'C_ATTRIBUTE9';
27623 							      l_serial_attributes_tbl(11).column_value  := l_msnt_rec.c_attribute9;
27624 							      l_serial_attributes_tbl(12).column_name  := 'C_ATTRIBUTE10';
27625 							      l_serial_attributes_tbl(12).column_value  := l_msnt_rec.c_attribute10;
27626 							      l_serial_attributes_tbl(13).column_name  := 'C_ATTRIBUTE11';
27627 							      l_serial_attributes_tbl(13).column_value  := l_msnt_rec.c_attribute11;
27628 							      l_serial_attributes_tbl(14).column_name  := 'C_ATTRIBUTE12';
27629 							      l_serial_attributes_tbl(14).column_value  := l_msnt_rec.c_attribute12;
27630 							      l_serial_attributes_tbl(15).column_name  := 'C_ATTRIBUTE13';
27631 							      l_serial_attributes_tbl(15).column_value  := l_msnt_rec.c_attribute13;
27632 							      l_serial_attributes_tbl(16).column_name  := 'C_ATTRIBUTE14';
27633 							      l_serial_attributes_tbl(16).column_value  := l_msnt_rec.c_attribute14;
27634 							      l_serial_attributes_tbl(17).column_name  := 'C_ATTRIBUTE15';
27635 							      l_serial_attributes_tbl(17).column_value  := l_msnt_rec.c_attribute15;
27636 							      l_serial_attributes_tbl(18).column_name  := 'C_ATTRIBUTE16';
27637 							      l_serial_attributes_tbl(18).column_value  := l_msnt_rec.c_attribute16;
27638 							      l_serial_attributes_tbl(19).column_name  := 'C_ATTRIBUTE17';
27639 							      l_serial_attributes_tbl(19).column_value  := l_msnt_rec.c_attribute17;
27640 							      l_serial_attributes_tbl(20).column_name  := 'C_ATTRIBUTE18';
27641 							      l_serial_attributes_tbl(20).column_value  := l_msnt_rec.c_attribute18;
27642 							      l_serial_attributes_tbl(21).column_name  := 'C_ATTRIBUTE19';
27643 							      l_serial_attributes_tbl(21).column_value  := l_msnt_rec.c_attribute19;
27644 							      l_serial_attributes_tbl(22).column_name  := 'C_ATTRIBUTE20';
27645 							      l_serial_attributes_tbl(22).column_value  := l_msnt_rec.c_attribute20;
27646 							      l_serial_attributes_tbl(23).column_name  := 'D_ATTRIBUTE1';
27647 							      l_serial_attributes_tbl(23).column_value  := l_msnt_rec.d_attribute1;
27648 							      l_serial_attributes_tbl(24).column_name  := 'D_ATTRIBUTE2';
27649 							      l_serial_attributes_tbl(24).column_value  := l_msnt_rec.d_attribute2;
27650 							      l_serial_attributes_tbl(25).column_name  := 'D_ATTRIBUTE3';
27651 							      l_serial_attributes_tbl(25).column_value  := l_msnt_rec.d_attribute3;
27652 							      l_serial_attributes_tbl(26).column_name  := 'D_ATTRIBUTE4';
27653 							      l_serial_attributes_tbl(26).column_value  := l_msnt_rec.d_attribute4;
27654 							      l_serial_attributes_tbl(27).column_name  := 'D_ATTRIBUTE5';
27655 							      l_serial_attributes_tbl(27).column_value  := l_msnt_rec.d_attribute5;
27656 							      l_serial_attributes_tbl(28).column_name  := 'D_ATTRIBUTE6';
27657 							      l_serial_attributes_tbl(28).column_value  := l_msnt_rec.d_attribute6;
27658 							      l_serial_attributes_tbl(29).column_name  := 'D_ATTRIBUTE7';
27659 							      l_serial_attributes_tbl(29).column_value  := l_msnt_rec.d_attribute7;
27660 							      l_serial_attributes_tbl(30).column_name  := 'D_ATTRIBUTE8';
27661 							      l_serial_attributes_tbl(30).column_value  := l_msnt_rec.d_attribute8;
27662 							      l_serial_attributes_tbl(31).column_name  := 'D_ATTRIBUTE9';
27663 							      l_serial_attributes_tbl(31).column_value  := l_msnt_rec.d_attribute9;
27664 							      l_serial_attributes_tbl(32).column_name  := 'D_ATTRIBUTE10';
27665 							      l_serial_attributes_tbl(32).column_value  := l_msnt_rec.d_attribute10;
27666 							      l_serial_attributes_tbl(33).column_name  := 'N_ATTRIBUTE1';
27667 							      l_serial_attributes_tbl(33).column_value  := l_msnt_rec.n_attribute1;
27668 							      l_serial_attributes_tbl(34).column_name  := 'N_ATTRIBUTE2';
27669 							      l_serial_attributes_tbl(34).column_value  := l_msnt_rec.n_attribute2;
27670 							      l_serial_attributes_tbl(35).column_name  := 'N_ATTRIBUTE3';
27671 							      l_serial_attributes_tbl(35).column_value  := l_msnt_rec.n_attribute3;
27672 							      l_serial_attributes_tbl(36).column_name  := 'N_ATTRIBUTE4';
27673 							      l_serial_attributes_tbl(36).column_value  := l_msnt_rec.n_attribute4;
27674 							      l_serial_attributes_tbl(37).column_name  := 'N_ATTRIBUTE5';
27675 							      l_serial_attributes_tbl(37).column_value := l_msnt_rec.n_attribute5;
27676 							      l_serial_attributes_tbl(38).column_name  := 'N_ATTRIBUTE6';
27677 							      l_serial_attributes_tbl(38).column_value := l_msnt_rec.n_attribute6;
27678 							      l_serial_attributes_tbl(39).column_name  := 'N_ATTRIBUTE7';
27679 							      l_serial_attributes_tbl(39).column_value := l_msnt_rec.n_attribute7;
27680 							      l_serial_attributes_tbl(40).column_name  := 'N_ATTRIBUTE8';
27681 							      l_serial_attributes_tbl(40).column_value := l_msnt_rec.n_attribute8;
27682 							      l_serial_attributes_tbl(41).column_name  := 'N_ATTRIBUTE9';
27683 							      l_serial_attributes_tbl(41).column_value := l_msnt_rec.n_attribute9;
27684 							      l_serial_attributes_tbl(42).column_name  := 'N_ATTRIBUTE10';
27685 							      l_serial_attributes_tbl(42).column_value := l_msnt_rec.n_attribute10;
27686 							      l_serial_attributes_tbl(43).column_name  := 'STATUS_ID';
27687 							      l_serial_attributes_tbl(43).column_value := l_msnt_rec.status_id;
27688 							      l_serial_attributes_tbl(44).column_name  := 'TERRITORY_CODE';
27689 							      l_serial_attributes_tbl(44).column_value := l_msnt_rec.territory_code;
27690 
27691 							      --Validate the serials
27692 							      FOR SERIALQTY IN 1..L_SERIAL_QUANTITY LOOP
27693 
27694 								 l_progress := 'WMSINB-27491';
27695 
27696                                                                  L_CUR_NUMBER := L_FROM_SER_NUMBER+SERIALQTY -1;
27697                                                                  if L_FROM_SER_NUMBER = -1 and  L_TO_SER_NUMBER = -1 then
27698 	                                                              L_SERIAL_NUMBER  := L_MSNT_REC.fm_serial_number;
27699 		                                                 else
27700 		                                                      L_SERIAL_NUMBER :=
27701 			                                                SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
27702 				                                          LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
27703 				                                          LENGTH(L_CUR_NUMBER))
27704 			                                                ||L_CUR_NUMBER;
27705                                                                  End if;
27706 
27707 								 --L_SERIAL_NUMBER :=
27708 								   --SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
27709 									  --LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
27710 									  --LENGTH(L_FROM_SER_NUMBER))
27711 								   --||(L_FROM_SER_NUMBER+SERIALQTY -1);
27712 
27713 								 l_progress := 'WMSINB-27499';
27714 
27715 		                                                 BEGIN
27716 								    SELECT CURRENT_ORGANIZATION_ID
27717 								      , current_status
27718 								      , lot_number
27719 								      , Decode(lpn_id,0,NULL,lpn_id)
27720 								      , inspection_status
27721 								      , group_mark_id
27722 								      INTO L_CURR_ORG_ID
27723 								      , l_curr_status
27724 								      , l_curr_lot_num
27725 								      , l_curr_lpn_id
27726 								      , l_inspection_status
27727 								      , l_group_mark_id
27728 								      FROM MTL_SERIAL_NUMBERS
27729 								      WHERE SERIAL_NUMBER = l_serial_number
27730 								      AND inventory_item_id = l_item_id;
27731 
27732 								    l_serial_exists := 1;
27733 								    l_progress := 'WMSINB-27519';
27734 								 EXCEPTION
27735 								    WHEN no_data_found THEN
27736 								       l_serial_exists := 0;
27737 								       l_progress := 'WMSINB-27523';
27738 								 END;
27739 
27740 								 IF (l_debug = 1) THEN
27741 								    print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL EXISTS: '||l_serial_exists||' : '||l_progress, 1);
27742 								    print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NUMBER: '||l_serial_number||' : '||l_progress, 1);
27743 								    print_debug('VALIDATE_LOT_SERIAL_INFO: CURR STATUS: '||l_curr_status||' : '||l_progress, 1);
27744 								    print_debug('VALIDATE_LOT_SERIAL_INFO: CURR ORG ID: '||l_curr_org_id||' : '||l_progress, 1);
27745 								    print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LPN ID: '||l_curr_lpn_id||' : '||l_progress, 1);
27746 								    print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LOT NUM: '||l_curr_lot_num||' : '||l_progress, 1);
27747 								    print_debug('VALIDATE_LOT_SERIAL_INFO: INSPECT STS: '||l_inspection_status||' : '||l_progress, 1);
27748 								    print_debug('VALIDATE_LOT_SERIAL_INFO: GROUP MARK ID: '||l_group_mark_id||' : '||l_progress, 1);
27749 								    print_debug('VALIDATE_LOT_SERIAL_INFO: RESTRICT RCPT SER: '||l_restrict_rcpt_ser||' : '||l_progress, 1);
27750 								    l_progress := 'WMSINB-27536';
27751 								 END IF;
27752 
27753 								 IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
27754 								    IF (l_grand_parent_txn_type <> 'DELIVER') THEN
27755 								       IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
27756 									  --raise an error
27757 									  RAISE
27758 									    fnd_api.g_exc_error;
27759 									ELSE --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
27760 							                   BEGIN
27761 									      SELECT '1'
27762 										INTO L_DUMMY
27763 										FROM RCV_SERIALS_SUPPLY
27764 										WHERE TRANSACTION_ID = l_grand_parent_txn_id
27765 										AND SERIAL_NUM = L_SERIAL_NUMBER;
27766 
27767 									      IF (l_curr_status <> 7) THEN
27768 										 --raise error
27769 										 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27770 										 fnd_msg_pub.ADD;
27771 										 l_progress := 'WMSINB-27557';
27772 										 RAISE fnd_api.g_exc_error;
27773 									      END IF;
27774 
27775 									      --Validate serial/group_mark_id to prevent
27776 									      --entering of duplicate serials
27777 
27778 									      IF (Nvl(l_group_mark_id, -99) = -7937) THEN
27779 										 --raise error
27780 										 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27781 										 fnd_msg_pub.ADD;
27782 										 l_progress := 'WMSINB-27568';
27783 										 RAISE fnd_api.g_exc_error;
27784 									      END IF;
27785 
27786 									      --UPDATE GROUP_MARK_ID TO -7937
27787 									      IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
27788 										 --raise error
27789 										 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27790 										 fnd_msg_pub.ADD;
27791 										 l_progress := 'WMSINB-27577';
27792 										 RAISE fnd_api.g_exc_error;
27793 									      END IF;
27794 									   EXCEPTION
27795 									      WHEN NO_DATA_FOUND THEN
27796 										 -- RAISE ERROR
27797 										 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27798 										 fnd_msg_pub.ADD;
27799 										 l_progress := 'WMSINB-27585';
27800 										 RAISE fnd_api.g_exc_error;
27801 									   END;
27802 								       END IF; --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
27803 								     ELSE --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
27804 									  IF l_curr_org_id <> l_org_id THEN
27805 									     --raise error
27806 									     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27807 									     fnd_msg_pub.ADD;
27808 									     l_progress := 'WMSINB-27594';
27809 									     RAISE fnd_api.g_exc_error;
27810 									   ELSE
27811 									     IF (l_curr_lot_num IS NOT NULL) THEN
27812 										--raise error
27813 										fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27814 										fnd_msg_pub.ADD;
27815 										l_progress := 'WMSINB-27601';
27816 										RAISE fnd_api.g_exc_error;
27817 									     END IF;
27818 									  END IF;
27819 
27820 									  IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
27821 									     IF l_curr_status NOT IN (1,6) THEN
27822 										--raise error
27823 										fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27824 										fnd_msg_pub.ADD;
27825 										l_progress := 'WMSINB-27611';
27826 										RAISE fnd_api.g_exc_error;
27827 									     END IF;
27828 									   ELSE --IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
27829 									     IF (l_curr_status <> 3) THEN
27830 										--raise error
27831 										fnd_message.set_name('INV','INV_FAIL_VALIDATE_SERIAL');
27832 										fnd_msg_pub.ADD;
27833 										l_progress := 'WMSINB-27619';
27834 										RAISE fnd_api.g_exc_error;
27835 									     END IF;
27836 									  END IF; --IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
27837 
27838 									  IF (Nvl(l_group_mark_id, -99) = -7937) THEN
27839 									     --raise error
27840 									     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27841 									     fnd_msg_pub.ADD;
27842 									     l_progress := 'WMSINB-27628';
27843 									     RAISE fnd_api.g_exc_error;
27844 									  END IF;
27845 
27846 				IF (Nvl(l_curr_status, 1) in (1,6)) THEN
27847 				   --validate and update the attributes.
27848 				   inv_serial_number_pub.validate_update_serial_att
27849 				     (x_return_status     => x_return_status,
27850 				      x_msg_count         => x_msg_count,
27851 				      x_msg_data          => x_msg_data,
27852 				      x_validation_status => l_validation_status,
27853 				      p_serial_number     => l_serial_number,
27854 				      p_organization_id   => l_org_id,
27855 				      p_inventory_item_id => l_item_id,
27856 				      p_serial_att_tbl    => l_serial_attributes_tbl,
27857 				      p_validate_only     => FALSE
27858 				      );
27859 
27860 				   IF (l_validation_status <> 'Y'
27861 				       OR x_return_status <> g_ret_sts_success) THEN
27862 				      --raise error
27863 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27864 				      fnd_msg_pub.ADD;
27865 				      l_progress := 'WMSINB-27634';
27866 				      RAISE fnd_api.g_exc_error;
27867 				   END IF;
27868 				END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
27869 
27870 									  --UPDATE GROUP_MARK_ID TO -7937
27871 									  IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
27872 									     --raise error
27873 									     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27874 									     fnd_msg_pub.ADD;
27875 									     l_progress := 'WMSINB-27637';
27876 									     RAISE fnd_api.g_exc_error;
27877 									  END IF;
27878 								    END IF; --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
27879 								  ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
27880 								       IF (l_parent_txn_type <> 'RECEIVE') THEN
27881 									  IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
27882 							                     BEGIN
27883 										SELECT '1'
27884 										  INTO L_DUMMY
27885 										  FROM RCV_SERIALS_SUPPLY
27886 										  WHERE TRANSACTION_ID = l_grand_parent_txn_id
27887 										  AND SERIAL_NUM = L_SERIAL_NUMBER;
27888 
27889 										IF (l_curr_status <> 7) THEN
27890 										   --raise error
27891 										   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27892 										   fnd_msg_pub.ADD;
27893 										   l_progress := 'WMSINB-27655';
27894 										   RAISE fnd_api.g_exc_error;
27895 										END IF;
27896 
27897 										--Validate serial/group_mark_id to prevent
27898 										--entering of duplicate serials
27899 
27900 										IF (Nvl(l_group_mark_id, -99) = -7937) THEN
27901 										   --raise error
27902 										   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27903 										   fnd_msg_pub.ADD;
27904 										   l_progress := 'WMSINB-27666';
27905 										   RAISE fnd_api.g_exc_error;
27906 										END IF;
27907 
27908 										--UPDATE GROUP_MARK_ID TO -7937
27909 										IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
27910 										   --raise error
27911 										   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27912 										   fnd_msg_pub.ADD;
27913 										   l_progress := 'WMSINB-27675';
27914 										   RAISE fnd_api.g_exc_error;
27915 										END IF;
27916 									     EXCEPTION
27917 										WHEN NO_DATA_FOUND THEN
27918 										   -- RAISE ERROR
27919 										   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27920 										   fnd_msg_pub.ADD;
27921 										   l_progress := 'WMSINB-27683';
27922 										   RAISE fnd_api.g_exc_error;
27923 									     END;
27924 									   ELSE --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
27925 										   IF (l_serial_exists = 1) THEN
27926 										      IF l_curr_org_id <> l_org_id THEN
27927 											 --raise error
27928 											 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27929 											 fnd_msg_pub.ADD;
27930 											 l_progress := 'WMSINB-27692';
27931 											 RAISE fnd_api.g_exc_error;
27932 										       ELSE
27933 											 IF (l_curr_lot_num IS NOT NULL) THEN
27934 											    --raise error
27935 											    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27936 											    fnd_msg_pub.ADD;
27937 											    l_progress := 'WMSINB-27699';
27938 											    RAISE fnd_api.g_exc_error;
27939 											 END IF;
27940 										      END IF;
27941 
27942 										      IF l_curr_status NOT IN (1,4,6) THEN -- Bug 6177465
27943 											 --raise error
27944 											 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27945 											 fnd_msg_pub.ADD;
27946 											 l_progress := 'WMSINB-27708';
27947 											 RAISE fnd_api.g_exc_error;
27948 										      END IF;
27949 
27950 										      IF (Nvl(l_group_mark_id, -99) = -7937) THEN
27951 											 --raise error
27952 											 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27953 											 fnd_msg_pub.ADD;
27954 											 l_progress := 'WMSINB-27716';
27955 											 RAISE fnd_api.g_exc_error;
27956 										      END IF;
27957 
27958 				IF (Nvl(l_curr_status, 1) in (1,6)) THEN
27959 				   --validate and update the attributes.
27960 				   inv_serial_number_pub.validate_update_serial_att
27961 				     (x_return_status     => x_return_status,
27962 				      x_msg_count         => x_msg_count,
27963 				      x_msg_data          => x_msg_data,
27964 				      x_validation_status => l_validation_status,
27965 				      p_serial_number     => l_serial_number,
27966 				      p_organization_id   => l_org_id,
27967 				      p_inventory_item_id => l_item_id,
27968 				      p_serial_att_tbl    => l_serial_attributes_tbl,
27969 				      p_validate_only     => FALSE
27970 				      );
27971 
27972 				   IF (l_validation_status <> 'Y'
27973 				       OR x_return_status <> g_ret_sts_success) THEN
27974 				      --raise error
27975 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27976 				      fnd_msg_pub.ADD;
27977 				      l_progress := 'WMSINB-27721';
27978 				      RAISE fnd_api.g_exc_error;
27979 				   END IF;
27980 				END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
27981 
27982 										      --UPDATE GROUP_MARK_ID TO -7937
27983 										      IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
27984 											 --raise error
27985 											 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27986 											 fnd_msg_pub.ADD;
27987 											 l_progress := 'WMSINB-27725';
27988 											 RAISE fnd_api.g_exc_error;
27989 										      END IF;
27990 										    ELSE --IF (l_serial_exists = 1) THEN
27991 										      IF l_serial_number_control_code = 5 THEN
27992 											 --PERFORM SERIAL VALIDATION FOR NEW SERIAL
27993 											 --(INCLUDING ATT VALIDATION)
27994 											 --CREATE MSN
27995 											 IF (l_transaction_type = 'CORRECT') THEN
27996 											    l_transaction_action_id := 29;
27997 											  ELSE
27998 											    l_transaction_action_id := 1;
27999 											 END IF;
28000 
28001 											 inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
28002 																   , p_inventory_item_id => l_item_id
28003 																   , p_organization_id => l_org_id
28004 																   , p_from_serial_number => l_serial_number
28005 																   , p_to_serial_number => l_serial_number
28006 																   , p_initialization_date => SYSDATE
28007 																   , p_completion_date => NULL
28008 																   , p_ship_date => NULL
28009 																   , p_revision => l_item_revision
28010 																   , p_lot_number => NULL
28011 																   , p_current_locator_id => l_loc_id
28012 																   , p_subinventory_code => l_sub_code
28013 																   , p_trx_src_id => NULL
28014 																   , p_unit_vendor_id => NULL
28015 																   , p_vendor_lot_number => NULL
28016 																   , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
28017 																   , p_receipt_issue_type => NULL
28018 																   , p_txn_src_id => NULL
28019 																   , p_txn_src_name => NULL
28020 																   , p_txn_src_type_id => NULL
28021 											   , p_transaction_id => NULL
28022 											   , p_current_status => 1
28023 											   , p_parent_item_id => NULL
28024 											   , p_parent_serial_number => NULL
28025 											   , p_cost_group_id => NULL
28026 											   , p_transaction_action_id => l_transaction_action_id
28027 											   , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
28028 											   , p_status_id => NULL
28029 											   , p_inspection_status => NULL
28030 											   , x_object_id => l_object_id
28031 											   , x_return_status => x_return_status
28032 											   , x_msg_count => x_msg_count
28033 											   , x_msg_data => x_msg_data);
28034 
28035 					 IF (x_return_status <> g_ret_sts_success) THEN
28036 					    --raise error
28037 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28038 					    fnd_msg_pub.ADD;
28039 					    l_progress := 'WMSINB-27730';
28040 					    RAISE fnd_api.g_exc_error;
28041 					 END IF;
28042 
28043 					 --validate and update the attributes.
28044 					 inv_serial_number_pub.validate_update_serial_att
28045 					   (x_return_status     => x_return_status,
28046 					    x_msg_count         => x_msg_count,
28047 					    x_msg_data          => x_msg_data,
28048 					    x_validation_status => l_validation_status,
28049 					    p_serial_number     => l_serial_number,
28050 					    p_organization_id   => l_org_id,
28051 					    p_inventory_item_id => l_item_id,
28052 					    p_serial_att_tbl    => l_serial_attributes_tbl,
28053 					    p_validate_only     => FALSE
28054 					    );
28055 
28056 					 IF (l_validation_status <> 'Y'
28057 					     OR x_return_status <> g_ret_sts_success) THEN
28058 					    --raise error
28059 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28060 					    fnd_msg_pub.ADD;
28061 					    l_progress := 'WMSINB-27770';
28062 					    RAISE fnd_api.g_exc_error;
28063 					 END IF;
28064 
28065 											 --UPDATE GROUP_MARK_ID TO -7937
28066 											 IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
28067 											    --raise error
28068 											    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28069 											    fnd_msg_pub.ADD;
28070 											    l_progress := 'WMSINB-27778';
28071 											    RAISE fnd_api.g_exc_error;
28072 											 END IF;
28073 										       ELSE --IF l_serial_number_control_code = 5 THEN
28074 											 --raise error
28075 											 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28076 											 fnd_msg_pub.ADD;
28077 											 l_progress := 'WMSINB-27785';
28078 											 RAISE fnd_api.g_exc_error;
28079 										      END IF; --IF l_serial_number_control_code = 5 THEN
28080 										   END IF; --IF (l_serial_exists = 1) THEN
28081 									  END IF; --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
28082 									ELSE --IF (l_parent_txn_type <> 'RECEIVE') THEN
28083 									     IF (l_serial_exists = 1) THEN
28084 										IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
28085 										   -- CHECK TO SEE IF THE ITEM IS SERIAL
28086 										   -- CONTROLLED IN SOURCE ORG
28087 
28088 										   GET_SERIAL_LOT_CTRL_IN_SRC_ORG
28089 										     (L_SHIPMENT_LINE_ID, L_ORG_ID,
28090 										      L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
28091 										      l_from_org_rev_ctrl, X_RETURN_STATUS,
28092 										      X_MSG_COUNT, X_MSG_DATA);
28093 
28094 										   IF ((L_FROM_ORG_SER_CRTL IN (2,5,6)
28095 											AND l_source_document_code = 'REQ')
28096 										       OR (l_from_org_ser_crtl IN (2,5)
28097 											   AND l_source_document_code = 'INVENTORY')
28098 										       ) THEN
28099 										      IF l_curr_org_id <> l_from_org_id THEN
28100 											 --raise error
28101 											 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28102 											 fnd_msg_pub.ADD;
28103 											 l_progress := 'WMSINB-27806';
28104 											 RAISE fnd_api.g_exc_error;
28105 										       ELSE --IF l_curr_org_id <> l_from_org_id THEN
28106 											 IF (l_curr_lot_num IS NOT NULL) THEN
28107 											    --raise error
28108 											    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28109 											    fnd_msg_pub.ADD;
28110 											    l_progress := 'WMSINB-27813';
28111 											    RAISE fnd_api.g_exc_error;
28112 											 END IF;
28113 										      END IF; --IF l_curr_org_id <> l_from_org_id THEN
28114 
28115 								                      BEGIN
28116 											 SELECT '1'
28117 											   INTO L_DUMMY
28118 											   FROM rcv_serials_supply rss
28119 											   , rcv_shipment_lines rsl
28120 											   WHERE rss.SHIPMENT_LINE_ID = rsl.SHIPMENT_LINE_ID
28121 											   AND rsl.shipment_header_id = l_shipment_header_id
28122 											   AND rsl.item_id = l_item_id
28123 											   AND rss.SUPPLY_TYPE_CODE = 'SHIPMENT'
28124 											   AND rss.serial_num = l_serial_number;
28125 
28126 											 IF L_CURR_STATUS <> 5 THEN
28127 											    -- RAISE AN ERROR
28128 											    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28129 											    fnd_msg_pub.ADD;
28130 											    l_progress := 'WMSINB-27830';
28131 											    RAISE fnd_api.g_exc_error;
28132 											 END IF;
28133 
28134 										      EXCEPTION
28135 											 WHEN NO_DATA_FOUND THEN
28136 											    -- RAISE AN ERROR
28137 											    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28138 											    fnd_msg_pub.ADD;
28139 											    l_progress := 'WMSINB-27839';
28140 											    RAISE fnd_api.g_exc_error;
28141 										      END;
28142 										    ELSE --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
28143 											    IF l_curr_org_id <> l_org_id THEN
28144 											       --raise error
28145 											       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28146 											       fnd_msg_pub.ADD;
28147 											       l_progress := 'WMSINB-27847';
28148 											       RAISE fnd_api.g_exc_error;
28149 											     ELSE
28150 											       IF (l_curr_lot_num IS NOT NULL) THEN
28151 												  --raise error
28152 												  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28153 												  fnd_msg_pub.ADD;
28154 												  l_progress := 'WMSINB-27854';
28155 												  RAISE fnd_api.g_exc_error;
28156 											       END IF;
28157 											    END IF;
28158 
28159 											    IF l_curr_status NOT IN (1,6) THEN
28160 											       --raise error
28161 											       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28162 											       fnd_msg_pub.ADD;
28163 											       l_progress := 'WMSINB-27863';
28164 											       RAISE fnd_api.g_exc_error;
28165 											    END IF;
28166 
28167 											    IF (Nvl(l_group_mark_id, -99) = -7937) THEN
28168 											       --raise error
28169 											       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28170 											       fnd_msg_pub.ADD;
28171 											       l_progress := 'WMSINB-27871';
28172 											       RAISE fnd_api.g_exc_error;
28173 											    END IF;
28174 
28175 				IF (Nvl(l_curr_status, 1) in (1,6)) THEN
28176 				   --validate and update the attributes.
28177 				   inv_serial_number_pub.validate_update_serial_att
28178 				     (x_return_status     => x_return_status,
28179 				      x_msg_count         => x_msg_count,
28180 				      x_msg_data          => x_msg_data,
28181 				      x_validation_status => l_validation_status,
28182 				      p_serial_number     => l_serial_number,
28183 				      p_organization_id   => l_org_id,
28184 				      p_inventory_item_id => l_item_id,
28185 				      p_serial_att_tbl    => l_serial_attributes_tbl,
28186 				      p_validate_only     => FALSE
28187 				      );
28188 
28189 				   IF (l_validation_status <> 'Y'
28190 				       OR x_return_status <> g_ret_sts_success) THEN
28191 				      --raise error
28192 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28193 				      fnd_msg_pub.ADD;
28194 				      l_progress := 'WMSINB-27876';
28195 				      RAISE fnd_api.g_exc_error;
28196 				   END IF;
28197 				END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
28198 
28199 											    --UPDATE GROUP_MARK_ID TO -7937
28200 											    IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
28201 											       --raise error
28202 											       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28203 											       fnd_msg_pub.ADD;
28204 											       l_progress := 'WMSINB-27880';
28205 											       RAISE fnd_api.g_exc_error;
28206 											    END IF;
28207 										   END IF; --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
28208 										 ELSE --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
28209 										      IF l_curr_org_id <> l_org_id THEN
28210 											 --raise error
28211 											 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28212 											 fnd_msg_pub.ADD;
28213 											 l_progress := 'WMSINB-27889';
28214 											 RAISE fnd_api.g_exc_error;
28215 										       ELSE
28216 											 IF (l_curr_lot_num IS NOT NULL) THEN
28217 											    --raise error
28218 											    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28219 											    fnd_msg_pub.ADD;
28220 											    l_progress := 'WMSINB-27896';
28221 											    RAISE fnd_api.g_exc_error;
28222 											 END IF;
28223 										      END IF;
28224 
28225 										      IF l_curr_status NOT IN (1,4,6) THEN--Bug: 6450814
28226 											 --raise error
28227 											 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28228 											 fnd_msg_pub.ADD;
28229 											 l_progress := 'WMSINB-27905';
28230 											 RAISE fnd_api.g_exc_error;
28231 										      END IF;
28232 
28233 										      IF (Nvl(l_group_mark_id, -99) = -7937) THEN
28234 											 --raise error
28235 											 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28236 											 fnd_msg_pub.ADD;
28237 											 l_progress := 'WMSINB-27913';
28238 											 RAISE fnd_api.g_exc_error;
28239 										      END IF;
28240 
28241 				IF (Nvl(l_curr_status, 1) in (1,6)) THEN
28242 				   --validate and update the attributes.
28243 				   inv_serial_number_pub.validate_update_serial_att
28244 				     (x_return_status     => x_return_status,
28245 				      x_msg_count         => x_msg_count,
28246 				      x_msg_data          => x_msg_data,
28247 				      x_validation_status => l_validation_status,
28248 				      p_serial_number     => l_serial_number,
28249 				      p_organization_id   => l_org_id,
28250 				      p_inventory_item_id => l_item_id,
28251 				      p_serial_att_tbl    => l_serial_attributes_tbl,
28252 				      p_validate_only     => FALSE
28253 				      );
28254 
28255 				   IF (l_validation_status <> 'Y'
28256 				       OR x_return_status <> g_ret_sts_success) THEN
28257 				      --raise error
28258 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28259 				      fnd_msg_pub.ADD;
28260 				      l_progress := 'WMSINB-27918';
28261 				      RAISE fnd_api.g_exc_error;
28262 				   END IF;
28263 				END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
28264 
28265 										      --UPDATE GROUP_MARK_ID TO -7937
28266 										      IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
28267 											 --raise error
28268 											 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28269 											 fnd_msg_pub.ADD;
28270 											 l_progress := 'WMSINB-27922';
28271 											 RAISE fnd_api.g_exc_error;
28272 										      END IF;
28273 										END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
28274 									      ELSE --IF (l_serial_exists = 1) THEN
28275 										   IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
28276 										      -- CHECK TO SEE IF THE ITEM IS SERIAL
28277 										      -- CONTROLLED IN SOURCE ORG
28278 
28279 										      GET_SERIAL_LOT_CTRL_IN_SRC_ORG
28280 											(L_SHIPMENT_LINE_ID, L_ORG_ID,
28281 											 L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
28282 											 l_from_org_rev_ctrl, X_RETURN_STATUS,
28283 											 X_MSG_COUNT, X_MSG_DATA);
28284 
28285 										      IF ((L_FROM_ORG_SER_CRTL IN (2,5,6)
28286 											   AND l_source_document_code = 'REQ')
28287 											  OR (l_from_org_ser_crtl IN (2,5)
28288 											      AND l_source_document_code = 'INVENTORY')
28289 											  ) THEN
28290 											 --raise error
28291 											 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28292 											 fnd_msg_pub.ADD;
28293 											 l_progress := 'WMSINB-27940';
28294 											 RAISE fnd_api.g_exc_error;
28295 										      END IF; --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
28296 										   END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
28297 
28298 										   IF l_serial_number_control_code = 5 THEN
28299 										      --PERFORM SERIAL VALIDATION FOR NEW SERIAL
28300 										      --(INCLUDING ATT VALIDATION)
28301 										      --CREATE MSN
28302 										      IF (l_transaction_type = 'CORRECT') THEN
28303 											 l_transaction_action_id := 29;
28304 										       ELSE
28305 											 l_transaction_action_id := 1;
28306 										      END IF;
28307 
28308 										      inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
28309 																, p_inventory_item_id => l_item_id
28310 																, p_organization_id => l_org_id
28311 																, p_from_serial_number => l_serial_number
28312 																, p_to_serial_number => l_serial_number
28313 																, p_initialization_date => SYSDATE
28314 																, p_completion_date => NULL
28315 																, p_ship_date => NULL
28316 																, p_revision => l_item_revision
28317 																, p_lot_number => NULL
28318 																, p_current_locator_id => l_loc_id
28319 																, p_subinventory_code => l_sub_code
28320 																, p_trx_src_id => NULL
28321 																, p_unit_vendor_id => NULL
28322 																, p_vendor_lot_number => NULL
28323 																, p_vendor_serial_number => l_msnt_rec.vendor_serial_number
28324 																, p_receipt_issue_type => NULL
28325 																, p_txn_src_id => NULL
28326 																, p_txn_src_name => NULL
28327 																, p_txn_src_type_id => NULL
28328 																, p_transaction_id => NULL
28329 																, p_current_status => 1
28330 											, p_parent_item_id => NULL
28331 											, p_parent_serial_number => NULL
28332 											, p_cost_group_id => NULL
28333 											, p_transaction_action_id => l_transaction_action_id
28334 											, p_transaction_temp_id => l_msnt_rec.transaction_temp_id
28335 											, p_status_id => NULL
28336 											, p_inspection_status => NULL
28337 											, x_object_id => l_object_id
28338 											, x_return_status => x_return_status
28339 											, x_msg_count => x_msg_count
28340 											, x_msg_data => x_msg_data);
28341 
28342 					 IF (x_return_status <> g_ret_sts_success) THEN
28343 					    --raise error
28344 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28345 					    fnd_msg_pub.ADD;
28346 					    l_progress := 'WMSINB-27950';
28347 					    RAISE fnd_api.g_exc_error;
28348 					 END IF;
28349 
28350 					 --validate and update the attributes.
28351 					 inv_serial_number_pub.validate_update_serial_att
28352 					   (x_return_status     => x_return_status,
28353 					    x_msg_count         => x_msg_count,
28354 					    x_msg_data          => x_msg_data,
28355 					    x_validation_status => l_validation_status,
28356 					    p_serial_number     => l_serial_number,
28357 					    p_organization_id   => l_org_id,
28358 					    p_inventory_item_id => l_item_id,
28359 					    p_serial_att_tbl    => l_serial_attributes_tbl,
28360 					    p_validate_only     => FALSE
28361 					    );
28362 
28363 					 IF (l_validation_status <> 'Y'
28364 					     OR x_return_status <> g_ret_sts_success) THEN
28365 					    --raise error
28366 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28367 					    fnd_msg_pub.ADD;
28368 					    l_progress := 'WMSINB-27985';
28369 					    RAISE fnd_api.g_exc_error;
28370 					 END IF;
28371 
28372 										      --UPDATE GROUP_MARK_ID TO -7937
28373 										      IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
28374 											 --raise error
28375 											 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28376 											 fnd_msg_pub.ADD;
28377 											 l_progress := 'WMSINB-27994';
28378 											 RAISE fnd_api.g_exc_error;
28379 										      END IF;
28380 										    ELSE --IF l_serial_number_control_code = 5 THEN
28381 										      --raise error
28382 										      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28383 										      fnd_msg_pub.ADD;
28384 										      l_progress := 'WMSINB-28001';
28385 										      RAISE fnd_api.g_exc_error;
28386 										   END IF; --IF l_serial_number_control_code = 5 THEN
28387 									     END IF; --IF (l_serial_exists = 1) THEN
28388 								       END IF; --IF (l_parent_txn_type <> 'RECEIVE') THEN
28389 								 END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
28390 							      END LOOP; -- FOR 1..L_SERIAL_QUANTITY
28391 							   END LOOP; --FETCH C_MSNT INTO L_MSNT_REC;
28392 
28393 							   CLOSE c_msnt;
28394 
28395 							   IF (l_num_msnt_recs > 0) THEN
28396 							      IF l_mtlt_rec.primary_quantity <> l_tot_msnt_serial_qty THEN
28397 								 --raise error
28398 								 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28399 								 fnd_msg_pub.ADD;
28400 								 l_progress := 'WMSINB-28017';
28401 								 RAISE fnd_api.g_exc_error;
28402 							      END IF;
28403 							    ELSE --IF (l_num_msnt_recs > 0) THEN
28404 							      IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
28405 								 IF (l_grand_parent_txn_type <> 'DELIVER') THEN
28406 								    IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
28407 								       --raise an error
28408 								       fnd_message.set_name('INV' , 'INV_FAIL_VALIDATE_SERIAL');
28409 								       fnd_msg_pub.ADD;
28410 								       l_progress := 'WMSINB-28027';
28411 								       RAISE fnd_api.g_exc_error;
28412 								    END IF; --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
28413 								  ELSE --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
28414 								    --raise an error
28415 								    fnd_message.set_name('INV' , 'INV_FAIL_VALIDATE_SERIAL');
28416 								    fnd_msg_pub.ADD;
28417 								    l_progress := 'WMSINB-28034';
28418 								    RAISE fnd_api.g_exc_error;
28419 								 END IF; --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
28420 							       ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
28421 								 IF (l_parent_txn_type <> 'DELIVER') THEN
28422 								    IF (validate_rs(NULL,l_parent_transaction_id,l_dummy_lpn)) THEN
28423 								       IF (serial_entered_on_parent(l_parent_transaction_id)) THEN
28424 									  --raise an error
28425 									  fnd_message.set_name('INV' , 'INV_FAIL_VALIDATE_SERIAL');
28426 									  fnd_msg_pub.ADD;
28427 									  l_progress := 'WMSINB-28044';
28428 									  RAISE fnd_api.g_exc_error;
28429 								       END IF; --IF (serial_entered_on_parent(l_parent_transaction_id)) THEN
28430 								     ELSE --IF (validate_rs(NULL,l_parent_transaction_id,l_dummy_lpn)) THEN
28431 								       IF (l_parent_txn_type <> 'RECEIVE') THEN
28432 									  IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
28433 									     --raise an error
28434 									     fnd_message.set_name('INV' , 'INV_FAIL_VALIDATE_SERIAL');
28435 									     fnd_msg_pub.ADD;
28436 									     l_progress := 'WMSINB-28053';
28437 									     RAISE fnd_api.g_exc_error;
28438 									  END IF; --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
28439 								       END IF; --IF (l_parent_txn_type <> 'RECEIVE') THEN
28440 								    END IF; --IF (validate_rs(NULL,l_parent_transaction_id,l_dummy_lpn)) THEN
28441 								  ELSE --IF (l_parent_txn_type <> 'DELIVER') THEN
28442 								    IF (l_serial_number_control_code IN (2,5)
28443 									OR (l_serial_number_control_code = 6
28444 									    AND l_source_document_code = 'RMA')) THEN
28445 								       --raise error
28446 								       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28447 								       fnd_msg_pub.ADD;
28448 								       l_progress := 'WMSINB-28062';
28449 								       RAISE fnd_api.g_exc_error;
28450 								    END IF;
28451 								 END IF; --IF (l_parent_txn_type <> 'DELIVER') THEN
28452 							      END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
28453 							   END IF; --IF (l_num_msnt_recs > 0) THEN
28454 				      END IF; --IF (l_lot_control_code = 2) THEN
28455 	END IF; --IF ((l_transaction_type = 'CORRECT' AND l_rti_primary_qty < 0)
28456      END IF; --IF (l_transaction_type IN ('CORRECT',G_RTR,G_RTV,G_RTC)) THEN
28457 
28458      IF (l_debug = 1) THEN
28459 	--print_debug('VALIDATE_LOT_SERIAL_INFO: What a relief !!! Completed succesfully !!!',1);
28460 	print_debug('VALIDATE_LOT_SERIAL_INFO:Completed succesfully!',1);
28461      END IF;
28462 
28463   EXCEPTION
28464      WHEN fnd_api.g_exc_error THEN
28465 	x_return_status  := g_ret_sts_error;
28466 	IF (l_debug = 1) THEN
28467 	   print_debug('Exitting VALIDATE_LOT_SERIAL_INFO - execution error:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
28468 	   print_stacked_messages;
28469 	END IF;
28470 	x_msg_data := l_progress;
28471      WHEN fnd_api.g_exc_unexpected_error THEN
28472 	x_return_status  := g_ret_sts_unexp_error;
28473 	IF (l_debug = 1) THEN
28474 	   print_debug('Exitting VALIDATE_LOT_SERIAL_INFO - unexpected error:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
28475 	   print_stacked_messages;
28476 	END IF;
28477 	x_msg_data := l_progress;
28478      WHEN OTHERS THEN
28479 	X_RETURN_STATUS  := G_RET_STS_UNEXP_ERROR;
28480 	IF (L_DEBUG = 1) THEN
28481 	   PRINT_DEBUG('Exitting VALIDATE_LOT_SERIAL_INFO - OTHER EXCEPTION:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
28482 	   print_stacked_messages;
28483 	END IF;
28484 
28485 	x_msg_data := l_progress;
28486 
28487 	IF SQLCODE IS NOT NULL THEN
28488 	   INV_MOBILE_HELPER_FUNCTIONS.SQL_ERROR('INV_RCV_INTERFACE_PVT.VALIDATE_LOT_SERIAL_INFO', Sqlerrm, SQLCODE);
28489 	END IF;
28490 	-- GET MESSAGE COUNT AND DATA
28491 	-- FND_MSG_PUB.COUNT_AND_GET(P_ENCODED => G_FALSE, P_COUNT => X_MSG_COUNT, P_DATA => X_MSG_DATA);
28492   END VALIDATE_LOT_SERIAL_INFO;
28493 END inv_rcv_integration_pvt;