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.173.12020000.32 2013/03/20 14:42:03 ragudise 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 g_mixed_expense_lpn_id  NUMBER  := -999 ;  --Bug#8662279
48 g_mixed_expense_result  BOOLEAN := FALSE ; --Bug#8662279
49 
50 g_org_wms_enabled boolean;--Bug#8731994
51 g_org_id          number; --Bug#8731994
52 
53 
54 PROCEDURE print_debug(p_err_msg VARCHAR2, p_level NUMBER) IS
55    l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
56    l_pkg_name VARCHAR2(100) := g_pkg_name||'($Revision: 120.173.12020000.32 $)';
57 BEGIN
58    IF (l_debug = 1) THEN
59       inv_mobile_helper_functions.tracelog(p_err_msg => p_err_msg, p_module => l_pkg_name, p_level => p_level);
60    END IF;
61 END print_debug;
62 
63 PROCEDURE print_stacked_messages IS
64    l_error_message VARCHAR2(4000) := '';
65 BEGIN
66    inv_mobile_helper_functions.get_stacked_messages(l_error_message);
67 
68    print_debug('STACKED ERROR MESSAGES : '||l_error_message,1);
69 END print_stacked_messages;
70 
71 PROCEDURE get_epc_info(p_mode          IN NUMBER
72 		       ,p_lpn          IN VARCHAR2 DEFAULT NULL
73 		       ,p_src_grp_id   IN NUMBER   DEFAULT NULL
74 		       ,p_ser_if_rowid IN ROWID    DEFAULT NULL
75 		       ,x_epc_column   OUT nocopy VARCHAR2
76 		       ,x_epc_value    OUT nocopy VARCHAR2
77 		       ) IS
78    l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
79    l_epc_column	    VARCHAR2(30);
80    l_epc_value      VARCHAR2(100);
81    l_epc_sql        VARCHAR2(1000);
82    l_epc_cursor         NUMBER;
83    l_last_error_pos NUMBER;
84    l_temp_str       VARCHAR2(100);
85    l_return         NUMBER;
86    l_progress       VARCHAR2(10);
87 BEGIN
88 
89    IF (p_mode = 1) THEN --LPN
90       l_epc_column := fnd_profile.value('WMS_EPC_LASN_COL');
91     ELSIF (p_mode = 2) THEN   -- Serial
92       l_epc_column := fnd_profile.value('WMS_EPC_SASN_COL');
93     ELSE
94       IF l_debug = 1 THEN
95 	 print_debug('Unsupported mode',4);
96       END IF;
97       RAISE fnd_api.g_exc_error;
98    END IF;
99 
100    x_epc_column := l_epc_column;
101 
102    IF (l_epc_column IS NULL) THEN
103       x_epc_column := NULL;
104       x_epc_value  := NULL;
105     ELSE
106       IF (p_mode = 1) THEN
107 	 l_epc_sql := 'SELECT ' || l_epc_column;
108 	 l_epc_sql := l_epc_sql || ' FROM wms_lpn_interface';
109 	 l_epc_sql := l_epc_sql || ' WHERE license_plate_number = :lpn';
110 	 l_epc_sql := l_epc_sql || ' AND   source_group_id = :src_grp_id';
111 
112 	 IF (l_debug = 1) THEN
113 	    print_debug('l_epc_sql: '||l_epc_sql,4);
114 	 END IF;
115 
116 	 l_epc_cursor := dbms_sql.open_cursor;
117          BEGIN
118 	    dbms_sql.parse(l_epc_cursor,l_epc_sql,dbms_sql.v7);
119 	 EXCEPTION
120 	    WHEN OTHERS THEN
121 	       l_last_error_pos := dbms_sql.last_error_position();
122 	       l_temp_str := Substr(l_epc_sql, l_last_error_pos-5, 50);
123 	       IF l_debug = 1 THEN
124 		  print_debug('Error in parse sql statement, at '||l_temp_str,4);
125 	       END IF;
126 	       RAISE fnd_api.g_exc_unexpected_error;
127 	 END;
128 
129 	 dbms_sql.bind_variable(l_epc_cursor,':lpn', p_lpn);
130 	 dbms_sql.bind_variable(l_epc_cursor,':src_grp_id', p_src_grp_id);
131 	 dbms_sql.define_column(l_epc_cursor, 1, l_epc_value, 30);
132 	 l_return := dbms_sql.execute(l_epc_cursor);
133 
134 	 IF dbms_sql.fetch_rows(l_epc_cursor) <> 0 THEN
135 	    dbms_sql.column_value(l_epc_cursor, 1, l_epc_value);
136 	    IF (l_debug = 1) THEN
137 	       print_debug('l_epc_value: '||l_epc_value,4);
138 	    END IF;
139 	    x_epc_value := l_epc_value;
140 	  ELSE
141 	    x_epc_value := NULL;
142 	 END IF;
143 
144 	 dbms_sql.close_cursor(l_epc_cursor);
145        ELSE --Serial
146 	 l_epc_sql := 'SELECT ' || l_epc_column;
147 	 l_epc_sql := l_epc_sql || ' FROM mtl_serial_numbers_temp';
148 	 l_epc_sql := l_epc_sql || ' WHERE rowid = :row_id';
149 
150 	 IF (l_debug = 1) THEN
151 	    print_debug('l_epc_sql: '||l_epc_sql,4);
152 	 END IF;
153 
154 	 l_epc_cursor := dbms_sql.open_cursor;
155          BEGIN
156 	    dbms_sql.parse(l_epc_cursor,l_epc_sql,dbms_sql.v7);
157 	 EXCEPTION
158 	    WHEN OTHERS THEN
159 	       l_last_error_pos := dbms_sql.last_error_position();
160 	       l_temp_str := Substr(l_epc_sql, l_last_error_pos-10, 50);
161 	       IF l_debug = 1 THEN
162 		  print_debug('Error in parse sql statement, at '||l_temp_str,4);
163 		  print_debug('ERROR CODE = '||SQLCODE||' ERROR MESSAGE = '||Sqlerrm,4);
164 	       END IF;
165 	       RAISE fnd_api.g_exc_unexpected_error;
166 	 END;
167 
168 	 dbms_sql.bind_variable(l_epc_cursor,':row_id', p_ser_if_rowid);
169 	 dbms_sql.define_column(l_epc_cursor, 1, l_epc_value, 30);
170 
171 	 l_return := dbms_sql.execute(l_epc_cursor);
172 
173 	 IF dbms_sql.fetch_rows(l_epc_cursor) <> 0 THEN
174 	    dbms_sql.column_value(l_epc_cursor, 1, l_epc_value);
175 	    IF (l_debug = 1) THEN
176 	       print_debug('l_epc_value: '||l_epc_value,4);
177 	    END IF;
178 	    x_epc_value := l_epc_value;
179 	  ELSE
180 	    x_epc_value := NULL;
181 	 END IF;
182 	 dbms_sql.close_cursor(l_epc_cursor);
183       END IF;
184    END IF;
185 
186 EXCEPTION
187    WHEN OTHERS THEN
188       IF l_debug = 1 THEN
189 	 print_debug('Error in get_epc_info at progress:'||l_progress,4);
190 	 print_debug('ERROR CODE = '||SQLCODE||' ERROR MESSAGE = '||Sqlerrm,4);
191       END IF;
192       dbms_sql.close_cursor(l_epc_cursor);
193 END get_epc_info;
194 
195 
196 /*****bug4187663, comment out the call to serial uniqueness api
197 --Following function calls the serial uniqueness api with txn_source and
198 --txn_action. It will return 0 on success and 1 on error.
199 
200 FUNCTION is_sernum_unique(p_org_id IN NUMBER,
201 			  p_item_id IN NUMBER,
202 			  p_serial IN VARCHAR2,
203 			  p_txn_src_type IN NUMBER,
204 			  p_txn_action IN NUMBER,
205 			  x_proc_msg OUT NOCOPY VARCHAR2)
206   RETURN NUMBER AS
207 LANGUAGE JAVA
208   NAME 'oracle.apps.inv.transaction.server.TrxProcessor.isSerialNumberUnique(java.lang.Long,
209   java.lang.Long,
210   java.lang.String,
211   java.lang.Integer,
212   java.lang.Integer,
213   java.lang.String[]) return java.lang.Integer';
214 
215 ****end of bug4187663*****/
216 
217 PROCEDURE check_lpn_in_wlpni(p_license_plate_number IN VARCHAR2,
218                              p_lpn_id               IN NUMBER,
219                              p_lpn_group_id         IN NUMBER,
220                              x_exists OUT NOCOPY NUMBER )
221   is
222 BEGIN
223    x_exists := 0;
224    select 1 into x_exists
225      from wms_lpn_interface
226      where ( ( license_plate_number = p_license_plate_number ) or ( lpn_id = p_lpn_id ))
227      and source_group_id = p_lpn_group_id
228      and rownum = 1;
229 EXCEPTION
230    WHEN OTHERS THEN
231       x_exists := 0;
232 END check_lpn_in_wlpni;
233 
234 function get_primary_qty(
235 			 p_organization_id       IN      NUMBER,
236 			 p_inventory_item_id     IN      NUMBER,
237 			 p_uom                   IN      VARCHAR2,
238 			 p_quantity              IN      NUMBER,
239 			 p_lot_number            IN      VARCHAR2 DEFAULT NULL) return number IS --Bug#9570776
240 
241 			    -- local variables
242 			    l_primary_uom         VARCHAR2(10);
243 
244 BEGIN
245    -- if input qty is null, assume 0, in which case we return 0 as converted
246    -- qty also
247    if ( ( p_quantity IS NULL ) OR (p_quantity = 0) ) then
248       return 0;
249    end if;
250 
251    l_primary_uom := inv_rcv_cache.get_primary_uom_code(p_organization_id,p_inventory_item_id);
252 
253    return( inv_rcv_cache.convert_qty(p_inventory_item_id => p_inventory_item_id
254 		       ,p_from_qty         => p_quantity
255 		       ,p_from_uom_code    => p_uom
256 		       ,p_to_uom_code      => l_primary_uom
257 		       ,p_precision        => 5--BUG 4939647
258 		       ,p_organization_id  => p_organization_id --Bug#9570776
259 		       ,p_lot_number       => p_lot_number --Bug#9570776
260 		       ) );
261 
262 
263 Exception
264    When Others then
265       return 0;
266 end get_primary_qty ;
267 
268 FUNCTION validate_pjm_commingle(p_org_id IN NUMBER,
269 				   p_lpn_id IN NUMBER,
270 				   p_project_id IN NUMBER,
271 				   p_task_id IN NUMBER)
272   RETURN BOOLEAN
273   IS
274      l_dummy VARCHAR2(1);
275 
276 BEGIN
277    SELECT '1'
278      INTO l_dummy
279      FROM dual
280      WHERE exists (SELECT '1'
281 		   FROM mtl_txn_request_lines mtrl
282 		   WHERE mtrl.lpn_id = p_lpn_id
283 		   AND mtrl.organization_id = p_org_id
284 		   AND (Nvl(mtrl.project_id,-1) <> Nvl(p_project_id,-1)
285 			OR Nvl(mtrl.task_id,-1) <> Nvl(p_task_id,-1))
286 		   AND line_status <> inv_globals.G_TO_STATUS_CLOSED
287 		   AND (mtrl.quantity - Nvl(mtrl.quantity_delivered, 0)) > 0);
288 
289    RETURN TRUE;
290 
291 EXCEPTION
292    WHEN no_data_found THEN
293       RETURN FALSE;
294    WHEN OTHERS THEN
295       RETURN TRUE;
296 
297 END validate_pjm_commingle;
298 
299 
300 FUNCTION validate_mixed_expense_items(p_org_id IN NUMBER,
301 				      p_lpn_id IN NUMBER,
302 				      p_transactions_enabled_flag IN VARCHAR2)
303   RETURN BOOLEAN
304   IS
305      l_dummy VARCHAR2(1);
306 BEGIN
307    /*Bug8662279. Performance fix. Added the following
308     1)Enabled cahche for one LPN_ID
309     2)Moved WLPN query to form clause by adding org_id and context restrictions
310     3)Eliminated need for extra WLPN
311     4)Removed reference to DUAL and used ROWNUM<2
312    */
313    IF (p_lpn_id = g_mixed_expense_lpn_id )  THEN
314       RETURN g_mixed_expense_result;
315    ELSE
316         g_mixed_expense_lpn_id := p_lpn_id ;
317    END IF;
318    SELECT '1' INTO l_dummy
319      FROM  wms_lpn_contents wlc
320          , mtl_system_items msi
321          , (SELECT lpn_id
322              FROM wms_license_plate_numbers wlpn2
323              WHERE wlpn2.organization_id = p_org_id
324                 AND wlpn2.lpn_context <> G_LPN_CONTEXT_STORES
325                 CONNECT BY PRIOR wlpn2.lpn_id = wlpn2.parent_lpn_id
326                 START WITH wlpn2.lpn_id = p_lpn_id
327               UNION ALL
328               SELECT lpn_id
329               FROM wms_license_plate_numbers wlpn3
330               WHERE wlpn3.organization_id = p_org_id
331                  AND wlpn3.lpn_context <> G_LPN_CONTEXT_STORES
332                  CONNECT BY PRIOR wlpn3.parent_lpn_id = wlpn3.lpn_id
333                  START WITH wlpn3.parent_lpn_id = p_lpn_id) wlpn
334      WHERE wlc.parent_lpn_id = wlpn.lpn_id
335       AND wlc.inventory_item_id = msi.inventory_item_id
336       AND msi.organization_id = p_org_id
337       AND msi.mtl_transactions_enabled_flag <> p_transactions_enabled_flag
338       AND ROWNUM<2;
339    g_mixed_expense_result := TRUE;
340 
341    RETURN TRUE;
342 EXCEPTION
343    WHEN no_data_found THEN
344       g_mixed_expense_result := FALSE;
345       RETURN FALSE;
346    WHEN OTHERS THEN
347       g_mixed_expense_result := TRUE;
348       RETURN TRUE;
349 END validate_mixed_expense_items;
350 
351 --procedure to call appropriate atf api.
352 
353 PROCEDURE call_atf_api(x_return_status OUT nocopy VARCHAR2,
354 		       x_msg_data OUT nocopy VARCHAR2,
355 		       x_msg_count OUT nocopy NUMBER,
356 		       x_error_code OUT nocopy NUMBER,
357 		       p_source_task_id IN NUMBER,
358 		       p_activity_type_id IN NUMBER,
359 		       p_operation_type_id IN NUMBER,
360 		       p_mol_id IN NUMBER,
361 		       p_atf_api_name IN NUMBER,
362 		       p_mmtt_error_code   IN   VARCHAR2,
363 		       p_mmtt_error_explanation   IN   VARCHAR2,
364 		       p_retain_mmtt IN VARCHAR2)
365   IS
366      -- Bug 5231114: Added the condition on transaction_source_type_id and
367      -- transaction_action_id for the following combinations:13/12 and 4/27
368      CURSOR c_mmtt IS
369 	SELECT transaction_temp_id
370 	  FROM mtl_material_transactions_temp
371 	  WHERE move_order_line_id = p_mol_id
372 	  AND ((transaction_source_type_id = 1 AND transaction_action_id = 27)
373 	       OR (transaction_source_type_id = 7 AND transaction_action_id = 12)
374 	       OR (transaction_source_type_id = 12 AND transaction_action_id = 27)
375 	       OR (transaction_source_type_id = 13 AND transaction_action_id = 12)
376 	       OR (transaction_source_type_id = 4 AND transaction_action_id = 27));
377 
378      l_transaction_temp_id NUMBER;
379 
380      l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
381 BEGIN
382 
383    IF p_source_task_id IS NOT NULL THEN
384       IF (p_atf_api_name = g_atf_api_complete) THEN
385 	 wms_atf_runtime_pub_apis.complete_operation_instance(x_return_status => x_return_status
386 							      ,x_msg_data => x_msg_data
387 							      ,x_msg_count => x_msg_count
388 							      ,x_error_code => x_error_code
389 							      ,p_source_task_id => p_source_task_id
390 							      ,p_activity_id => p_activity_type_id
391 							      ,p_operation_type_id => p_operation_type_id);
392        ELSIF (p_atf_api_name = g_atf_api_cancel) THEN
393 	 wms_atf_runtime_pub_apis.cancel_operation_plan(x_return_status => x_return_status
394 							,x_msg_data => x_msg_data
395 							,x_msg_count => x_msg_count
396 							,x_error_code => x_error_code
397 							,p_source_task_id => p_source_task_id
398 							,p_activity_type_id=> p_activity_type_id
399 							,p_mmtt_error_code => p_mmtt_error_code
400 							,p_mmtt_error_explanation => p_mmtt_error_explanation
401 							,p_retain_mmtt => p_retain_mmtt);
402        ELSIF (p_atf_api_name = g_atf_api_abort) THEN
403 	 wms_atf_runtime_pub_apis.abort_operation_plan(x_return_status => x_return_status
404 						       ,x_msg_data => x_msg_data
405 						       ,x_msg_count => x_msg_count
406 						       ,x_error_code => x_error_code
407 						       ,p_source_task_id => p_source_task_id
408 						       ,p_activity_type_id => p_activity_type_id);
409        ELSIF (p_atf_api_name = g_atf_api_cleanup) THEN
410 	 wms_atf_runtime_pub_apis.cleanup_operation_instance(x_return_status => x_return_status
411 							     ,x_msg_data => x_msg_data
412 							     ,x_msg_count => x_msg_count
413 							     ,x_error_code => x_error_code
414 							     ,p_source_task_id => p_source_task_id
415 							     ,p_activity_type_id => p_activity_type_id);
416       END IF;--ELSIF (p_atf_api_name = g_atf_api_cleanup) THEN
417     ELSE --IF p_source_task_id IS NOT NULL THEN
418       FOR l_mmtt IN c_mmtt LOOP
419 	 IF (p_atf_api_name = g_atf_api_complete) THEN
420 	    wms_atf_runtime_pub_apis.complete_operation_instance(x_return_status => x_return_status
421 								 ,x_msg_data => x_msg_data
422 								 ,x_msg_count => x_msg_count
423 								 ,x_error_code => x_error_code
424 								 ,p_source_task_id => l_mmtt.transaction_temp_id
425 								 ,p_activity_id => p_activity_type_id
426 								 ,p_operation_type_id => p_operation_type_id);
427 	  ELSIF (p_atf_api_name = g_atf_api_cancel) THEN
428 	    wms_atf_runtime_pub_apis.cancel_operation_plan(x_return_status => x_return_status
429 							   ,x_msg_data => x_msg_data
430 							   ,x_msg_count => x_msg_count
431 							   ,x_error_code => x_error_code
432 							   ,p_source_task_id => l_mmtt.transaction_temp_id
433 							   ,p_activity_type_id => p_activity_type_id
434 							   ,p_mmtt_error_code => p_mmtt_error_code
435 							   ,p_mmtt_error_explanation => p_mmtt_error_explanation
436 							   ,p_retain_mmtt => p_retain_mmtt);
437 	  ELSIF (p_atf_api_name = g_atf_api_abort) THEN
438 	    wms_atf_runtime_pub_apis.abort_operation_plan(x_return_status => x_return_status
439 							  ,x_msg_data => x_msg_data
440 							  ,x_msg_count => x_msg_count
441 							  ,x_error_code => x_error_code
442 							  ,p_source_task_id => l_mmtt.transaction_temp_id
443 							  ,p_activity_type_id => p_activity_type_id);
444 	  ELSIF (p_atf_api_name = g_atf_api_cleanup) THEN
445 	    wms_atf_runtime_pub_apis.cleanup_operation_instance(x_return_status => x_return_status
446 								,x_msg_data => x_msg_data
447 								,x_msg_count => x_msg_count
448 								,x_error_code => x_error_code
449 								,p_source_task_id => l_mmtt.transaction_temp_id
450 								,p_activity_type_id => p_activity_type_id);
451 	 END IF;--ELSIF (p_atf_api_name = g_atf_api_cleanup) THEN
452       END LOOP; --FOR l_mmtt IN (c_mmtt) LOOP
453    END IF; --IF p_source_task_id IS NOT NULL THEN
454 
455 END call_atf_api;
456 
457 --Procedure to get the lot/serial controls in the source or for int shp/req rcpt.
458 PROCEDURE get_serial_lot_ctrl_in_src_org
459   (p_shipment_line_id IN NUMBER,
460    p_org_id IN NUMBER,
461    x_serial_control_code OUT nocopy NUMBER,
462    x_lot_control_code OUT nocopy NUMBER,
463    x_revision_control_code OUT nocopy NUMBER,
464    x_return_status OUT nocopy VARCHAR2,
465    x_msg_count OUT nocopy NUMBER,
466    x_msg_data OUT nocopy VARCHAR2)
467   IS
468      l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
469 BEGIN
470    x_return_status := g_ret_sts_success;
471 
472    SELECT msi.lot_control_code
473      , msi.serial_number_control_code
474      , msi.revision_qty_control_code
475      INTO x_lot_control_code
476      , x_serial_control_code
477      , x_revision_control_code
478      FROM mtl_system_items msi, rcv_shipment_lines rsl
479      WHERE rsl.shipment_line_id = p_shipment_line_id
480      AND rsl.to_organization_id = p_org_id
481      AND msi.inventory_item_id = rsl.item_id
482      AND msi.organization_id = rsl.from_organization_id;
483 
484 EXCEPTION
485    WHEN OTHERS THEN
486       x_return_status  := g_ret_sts_unexp_error;
487       IF (l_debug = 1) THEN
488          print_debug('get_serial_lot_ctrl_in_src_org - other exception: '||
489 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
490       END IF;
491       IF SQLCODE IS NOT NULL THEN
492 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.get_serial_lot_ctrl_in_src_org',Sqlerrm,SQLCODE);
493       END IF;
494       --  Get message count and data
495       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
496 END get_serial_lot_ctrl_in_src_org;
497 
498 PROCEDURE create_lot_serial_history(p_prod_txn_tmp_id IN NUMBER
499 				    ,p_prod_txn_id      IN NUMBER
500 				    ,x_return_status       OUT NOCOPY VARCHAR2
501 				    ,x_msg_count           OUT NOCOPY NUMBER
502 				    ,x_msg_data            OUT NOCOPY VARCHAR2)
503   IS
504      TYPE varchar30_tb_tp IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
505 
506      l_temp_prefix VARCHAR2(30);
507      l_from_ser_number NUMBER;
508      l_to_ser_number NUMBER;
509      l_cur_ser_number NUMBER;
510      l_range_numbers NUMBER;
511      l_cur_serial_number VARCHAR2(30);
512      l_serial_numbers varchar30_tb_tp;
513      l_sysdate DATE := Sysdate;
514 
515      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
516      l_progress VARCHAR2(15);
517 
518      CURSOR msnt_cur IS
519 	SELECT
520 	  msnt.transaction_temp_id transaction_temp_id
521 	  ,msnt.last_updated_by last_updated_by
522 	  ,msnt.created_by created_by
523 	  ,rti.item_id inventory_item_id
524 	  ,rti.to_organization_id organization_id
525 	  ,msnt.fm_serial_number fm_serial_number
526 	  ,msnt.to_serial_number to_serial_number
527 	  ,rti.transaction_date transaction_date
528 	  ,Decode(rti.source_document_code,
529 		  'INVENTORY',
530 		  13,
531 		  Decode(rti.source_document_code,
532 			 'PO',
533 			 1,
534 			 Decode(rti.source_document_code,
535 				'REQ',
536 				7,
537 				Decode(rti.source_document_code,
538 				       'RMA',
539 				       12,
540 				       -1)))) transaction_source_type_id
541 	  -- What to do in error condition?
542 	  ,rti.source_document_code transaction_source_name
543 	  ,Decode(rti.transaction_type,
544 		  'RETURN TO RECEIVING',
545 		  1,
546 		  Decode(rti.transaction_type,
547 			 'RETURN TO VENDOR',
548 			 1,
549 			 Decode(rti.transaction_type,
550 				'RETURN TO CUSTOMER',
551 				1,
552 				2))) receipt_issue_type
553 	  ,msnt.serial_attribute_category serial_attribute_category
554 	  ,msnt.origination_date origination_date
555 	  ,msnt.c_attribute1 c_attribute1
556 	  ,msnt.c_attribute2 c_attribute2
557 	  ,msnt.c_attribute3 c_attribute3
558 	  ,msnt.c_attribute4 c_attribute4
559 	  ,msnt.c_attribute5 c_attribute5
560 	  ,msnt.c_attribute6 c_attribute6
561 	  ,msnt.c_attribute7 c_attribute7
562 	  ,msnt.c_attribute8 c_attribute8
563 	  ,msnt.c_attribute9 c_attribute9
564 	  ,msnt.c_attribute10 c_attribute10
565 	  ,msnt.c_attribute11 c_attribute11
566 	  ,msnt.c_attribute12 c_attribute12
567 	  ,msnt.c_attribute13 c_attribute13
568 	  ,msnt.c_attribute14 c_attribute14
569 	  ,msnt.c_attribute15 c_attribute15
570 	  ,msnt.c_attribute16 c_attribute16
571 	  ,msnt.c_attribute17 c_attribute17
572 	  ,msnt.c_attribute18 c_attribute18
573 	  ,msnt.c_attribute19 c_attribute19
574 	  ,msnt.c_attribute20 c_attribute20
575 	  ,msnt.d_attribute1 d_attribute1
576 	  ,msnt.d_attribute2 d_attribute2
577 	  ,msnt.d_attribute3 d_attribute3
578 	  ,msnt.d_attribute4 d_attribute4
579 	  ,msnt.d_attribute5 d_attribute5
580 	  ,msnt.d_attribute6 d_attribute6
581 	  ,msnt.d_attribute7 d_attribute7
582 	  ,msnt.d_attribute8 d_attribute8
583 	  ,msnt.d_attribute9 d_attribute9
584 	  ,msnt.d_attribute10 d_attribute10
585 	  ,msnt.n_attribute1 n_attribute1
586 	  ,msnt.n_attribute2 n_attribute2
587 	  ,msnt.n_attribute3 n_attribute3
588 	  ,msnt.n_attribute4 n_attribute4
589 	  ,msnt.n_attribute5 n_attribute5
590 	  ,msnt.n_attribute6 n_attribute6
591 	  ,msnt.n_attribute7 n_attribute7
592 	  ,msnt.n_attribute8 n_attribute8
593 	  ,msnt.n_attribute9 n_attribute9
594 	  ,msnt.n_attribute10 n_attribute10
595 	  ,msnt.status_id status_id
596 	  ,msnt.territory_code territory_code
597 	  ,msnt.time_since_new time_since_new
598 	  ,msnt.cycles_since_new cycles_since_new
599 	  ,msnt.time_since_overhaul time_since_overhaul
600 	  ,msnt.cycles_since_overhaul cycles_since_overhaul
601 	  ,msnt.time_since_repair time_since_repair
602 	  ,msnt.cycles_since_repair cycles_since_repair
603 	  ,msnt.time_since_visit time_since_visit
604 	  ,msnt.cycles_since_visit cycles_since_visit
605 	  ,msnt.time_since_mark time_since_mark
606 	  ,msnt.cycles_since_mark cycles_since_mark
607 	  ,msnt.number_of_repairs number_of_repairs
608 	  from
609 	  mtl_serial_numbers_temp msnt
610 	  ,rcv_transactions_interface rti
611 	  where
612 	  msnt.product_code = 'RCV'
613 	  AND msnt.product_transaction_id = p_prod_txn_tmp_id
614 	  AND rti.interface_transaction_id = msnt.product_transaction_id;
615 BEGIN
616 
617    IF (l_debug = 1) THEN
618       print_debug('CREATE_LOT_SERIAL_HISTORY: Entered with the following paramenters -', 1);
619       print_debug('  p_prod_txn_tmp_id => ' || p_prod_txn_tmp_id, 1);
620       print_debug('  p_prod_txn_id     => ' || p_prod_txn_id, 1);
621    END IF;
622 
623    SAVEPOINT process_lot_serial_pub;
624 
625    x_return_status := g_ret_sts_success;
626 
627    l_progress := 'WMSINB-10431';
628 
629    IF (l_debug = 1) THEN
630       print_debug('CREATE_LOT_SERIAL_HISTORY: Processing MTLT...',1);
631    END IF;
632 
633    INSERT INTO mtl_transaction_lot_numbers
634      (
635       transaction_id
636       ,last_update_date
637       ,last_updated_by
638       ,creation_date
639       ,created_by
640       ,last_update_login
641       ,inventory_item_id
642       ,organization_id
643       ,transaction_date
644       ,transaction_source_id
645       ,transaction_source_type_id
646       ,transaction_source_name
647       ,transaction_quantity
648       ,primary_quantity
649       ,lot_number
650       ,serial_transaction_id
651       ,description
652       ,vendor_name
653       ,supplier_lot_number
654       ,origination_date
655       ,date_code
656       ,grade_code
657       ,change_date
658       ,maturity_date
659       ,status_id
660       ,retest_date
661       ,age
662       ,item_size
663       ,color
664       ,volume
665       ,volume_uom
666       ,place_of_origin
667       ,best_by_date
668       ,length
669       ,length_uom
670       ,width
671       ,width_uom
672       ,recycled_content
673       ,thickness
674       ,thickness_uom
675       ,curl_wrinkle_fold
676       ,lot_attribute_category
677       ,c_attribute1
678       ,c_attribute2
679       ,c_attribute3
680       ,c_attribute4
681       ,c_attribute5
682       ,c_attribute6
683      ,c_attribute7
684      ,c_attribute8
685      ,c_attribute9
686      ,c_attribute10
687      ,c_attribute11
688      ,c_attribute12
689      ,c_attribute13
690      ,c_attribute14
691      ,c_attribute15
692      ,c_attribute16
693      ,c_attribute17
694      ,c_attribute18
695      ,c_attribute19
696      ,c_attribute20
697      ,d_attribute1
698      ,d_attribute2
699      ,d_attribute3
700      ,d_attribute4
701      ,d_attribute5
702      ,d_attribute6
703      ,d_attribute7
704      ,d_attribute8
705      ,d_attribute9
706      ,d_attribute10
707      ,n_attribute1
708      ,n_attribute2
709      ,n_attribute3
710      ,n_attribute4
711      ,n_attribute5
712      ,n_attribute6
713      ,n_attribute7
714      ,n_attribute8
715      ,n_attribute9
716      ,n_attribute10
717      ,vendor_id
718      ,territory_code
719      ,product_code
720      ,product_transaction_id
721      ,attribute_category
722      ,attribute1
723      ,attribute2
724      ,attribute3
725      ,attribute4
726      ,attribute5
727      ,attribute6
728      ,attribute7
729      ,attribute8
730      ,attribute9
731      ,attribute10
732      ,attribute11
733      ,attribute12
734      ,attribute13
735      ,attribute14
736      ,attribute15 )
737      SELECT
738      mtlt.transaction_temp_id
739      ,l_sysdate
740      ,mtlt.last_updated_by
741      ,l_sysdate
742      ,mtlt.created_by
743      ,-1
744      ,rti.item_id
745      ,rti.to_organization_id
746      ,rti.transaction_date
747      ,NULL
748      ,Decode(rti.source_document_code,
749 	     'INVENTORY',
750 	     13,
751 	     Decode(rti.source_document_code,
752 		    'PO',
753 		    1,
754 		    Decode(rti.source_document_code,
755 			   'REQ',
756 			   7,
757 			   Decode(rti.source_document_code,
758 				  'RMA',
759 				  12,
760 				  -1))))
761      ,rti.source_document_code
762      ,mtlt.transaction_quantity
763      ,mtlt.primary_quantity
764      ,Ltrim(Rtrim(mtlt.lot_number))
765      ,mtlt.serial_transaction_temp_id
766      ,mtlt.description
767      ,mtlt.vendor_name
768      ,mtlt.supplier_lot_number
769      ,mtlt.origination_date
770      ,mtlt.date_code
771      ,mtlt.grade_code
772      ,mtlt.change_date
773      ,mtlt.maturity_date
774      ,mtlt.status_id
775      ,mtlt.retest_date
776      ,mtlt.age
777      ,mtlt.item_size
778      ,mtlt.color
779      ,mtlt.volume
780      ,mtlt.volume_uom
781      ,mtlt.place_of_origin
782      ,mtlt.best_by_date
783      ,mtlt.length
784      ,mtlt.length_uom
785      ,mtlt.recycled_content
786      ,mtlt.thickness
787      ,mtlt.thickness_uom
788      ,mtlt.width
789      ,mtlt.width_uom
790      ,mtlt.curl_wrinkle_fold
791      ,mtlt.lot_attribute_category
792      ,mtlt.c_attribute1
793      ,mtlt.c_attribute2
794      ,mtlt.c_attribute3
795      ,mtlt.c_attribute4
796      ,mtlt.c_attribute5
797      ,mtlt.c_attribute6
798      ,mtlt.c_attribute7
799      ,mtlt.c_attribute8
800      ,mtlt.c_attribute9
801      ,mtlt.c_attribute10
802      ,mtlt.c_attribute11
803      ,mtlt.c_attribute12
804      ,mtlt.c_attribute13
805      ,mtlt.c_attribute14
806      ,mtlt.c_attribute15
807      ,mtlt.c_attribute16
808      ,mtlt.c_attribute17
809      ,mtlt.c_attribute18
810      ,mtlt.c_attribute19
811      ,mtlt.c_attribute20
812      ,mtlt.d_attribute1
813      ,mtlt.d_attribute2
814      ,mtlt.d_attribute3
815      ,mtlt.d_attribute4
816      ,mtlt.d_attribute5
817      ,mtlt.d_attribute6
818      ,mtlt.d_attribute7
819      ,mtlt.d_attribute8
820      ,mtlt.d_attribute9
821      ,mtlt.d_attribute10
822      ,mtlt.n_attribute1
823      ,mtlt.n_attribute2
824      ,mtlt.n_attribute3
825      ,mtlt.n_attribute4
826      ,mtlt.n_attribute5
827      ,mtlt.n_attribute6
828      ,mtlt.n_attribute7
829      ,mtlt.n_attribute8
830      ,mtlt.n_attribute9
831      ,mtlt.n_attribute10
832      ,mtlt.vendor_id
833      ,mtlt.territory_code
834      ,'RCV'
835      ,p_prod_txn_id
836      ,mtlt.attribute_category
837      ,mtlt.attribute1
838      ,mtlt.attribute2
839      ,mtlt.attribute3
840      ,mtlt.attribute4
841      ,mtlt.attribute5
842      ,mtlt.attribute6
843      ,mtlt.attribute7
844      ,mtlt.attribute8
845      ,mtlt.attribute9
846      ,mtlt.attribute10
847      ,mtlt.attribute11
848      ,mtlt.attribute12
849      ,mtlt.attribute13
850      ,mtlt.attribute14
851      ,mtlt.attribute15
852      FROM
853      mtl_transaction_lots_temp mtlt
854      ,rcv_transactions_interface rti
855      WHERE
856      mtlt.product_transaction_id = p_prod_txn_tmp_id AND
857      mtlt.product_code = 'RCV' AND
858      rti.interface_transaction_id = p_prod_txn_tmp_id;
859 
860    l_progress := 'WMSINB-10664';
861 
862    IF (l_debug = 1) THEN
863       print_debug('CREATE_LOT_SERIAL_HISTORY: MTLNs inserted.',1);
864    END IF;
865 
866    FOR l_msnt IN msnt_cur LOOP
867       IF (l_debug = 1) THEN
868 	 print_debug('CREATE_LOT_SERIAL_HISTORY:   Processing MSNT with fm_serial_number = '
869 		     || l_msnt.fm_serial_number ||
870 		     ' to_serial_number = ' || l_msnt.to_serial_number,1);
871       END IF;
872 
873       l_progress := 'WMSINB-10677';
874       inv_validate.number_from_sequence(l_msnt.fm_serial_number, l_temp_prefix, l_from_ser_number);
875       l_progress := 'WMSINB-10679';
876       inv_validate.number_from_sequence(l_msnt.to_serial_number
877 					,l_temp_prefix
878 					,l_to_ser_number);
879       l_progress := 'WMSINB-10683';
880       l_range_numbers  := l_to_ser_number - l_from_ser_number + 1;
881 
882       l_progress := 'WMSINB-10686';
883       IF (l_serial_numbers.COUNT > 0) THEN
884 	 l_serial_numbers.DELETE;
885       END IF;
886 
887       l_progress := 'WMSINB-10691';
888 
889       for j in 1 .. l_range_numbers loop
890 	 l_cur_ser_number  := l_from_ser_number + j - 1;
891 
892 	 -- concatenate the serial number to be inserted
893 	 if (l_from_ser_number = -1
894 	     and l_to_ser_number = -1) then
895 	    l_cur_serial_number  := l_msnt.fm_serial_number;
896 	  else
897 	    l_cur_serial_number  := substr(l_msnt.fm_serial_number, 1, length(l_msnt.fm_serial_number) -
898 					   length(l_cur_ser_number)) || l_cur_ser_number;
899 	 end if;
900 
901 	 IF (l_debug = 1) THEN
902 	    print_debug('CREATE_LOT_SERIAL_HISTORY:    Cancatenated serial_number '
903 			|| l_cur_serial_number,1);
904 	 END IF;
905 
906 	 l_serial_numbers(j) := l_cur_serial_number;
907 
908       end loop;
909 
910       l_progress := 'WMSINB-10714';
911 
912       forall  j IN 1 .. l_serial_numbers.COUNT
913 	INSERT INTO mtl_unit_transactions
914 	( transaction_id
915 	  ,last_update_date
916 	  ,last_updated_by
917 	  ,creation_date
918 	  ,created_by
919 	  ,last_update_login
920 	  ,serial_number
921 	  ,inventory_item_id
922 	  ,organization_id
923 	  ,subinventory_code
924 	  ,locator_id
925 	  ,transaction_date
926 	  ,transaction_source_id
927 	  ,transaction_source_type_id
928 	  ,transaction_source_name
929 	  ,receipt_issue_type
930 	  ,customer_id
931 	  ,ship_id
932 	  ,serial_attribute_category
933 	  ,origination_date
934 	  ,c_attribute1
935 	  ,c_attribute2
936 	  ,c_attribute3
937 	  ,c_attribute4
938 	  ,c_attribute5
939 	  ,c_attribute6
940 	  ,c_attribute7
941 	  ,c_attribute8
942 	  ,c_attribute9
943 	  ,c_attribute10
944 	  ,c_attribute11
945 	  ,c_attribute12
946 	  ,c_attribute13
947 	  ,c_attribute14
948 	  ,c_attribute15
949 	  ,c_attribute16
950 	  ,c_attribute17
951 	  ,c_attribute18
952 	  ,c_attribute19
953 	  ,c_attribute20
954 	  ,d_attribute1
955 	  ,d_attribute2
956 	  ,d_attribute3
957 	  ,d_attribute4
958 	  ,d_attribute5
959 	  ,d_attribute6
960 	  ,d_attribute7
961 	  ,d_attribute8
962 	  ,d_attribute9
963 	  ,d_attribute10
964 	  ,n_attribute1
965 	  ,n_attribute2
966 	  ,n_attribute3
967 	  ,n_attribute4
968 	,n_attribute5
969 	,n_attribute6
970 	,n_attribute7
971 	,n_attribute8
972 	,n_attribute9
973 	,n_attribute10
974 	,status_id
975 	,territory_code
976 	,time_since_new
977 	,cycles_since_new
978 	,time_since_overhaul
979 	,cycles_since_overhaul
980 	,time_since_repair
981 	,cycles_since_repair
982 	,time_since_visit
983 	,cycles_since_visit
984 	,time_since_mark
985 	,cycles_since_mark
986 	,number_of_repairs
987 	,product_code
988 	,product_transaction_id )
989 	VALUES
990 	( l_msnt.transaction_temp_id
991 	  ,l_sysdate
992 	  ,l_msnt.last_updated_by
993 	  ,l_sysdate
994 	  ,l_msnt.created_by
995 	  ,-1
996 	  ,l_serial_numbers(j)
997 	  ,l_msnt.inventory_item_id
998 	  ,l_msnt.organization_id
999 	  ,NULL  -- sub
1000 	  ,NULL  -- loc
1001 	  ,l_msnt.transaction_date
1002 	  ,NULL  -- txn souce id
1003 	  ,l_msnt.transaction_source_type_id
1004 	  ,l_msnt.transaction_source_name
1005 	  ,l_msnt.receipt_issue_type
1006 	  ,NULL  -- customer id
1007 	  ,NULL  -- ship_id
1008 	  ,l_msnt.serial_attribute_category
1009 	  ,l_msnt.origination_date
1010 	  ,l_msnt.c_attribute1
1011 	  ,l_msnt.c_attribute2
1012 	  ,l_msnt.c_attribute3
1013 	  ,l_msnt.c_attribute4
1014 	  ,l_msnt.c_attribute5
1015 	  ,l_msnt.c_attribute6
1016 	  ,l_msnt.c_attribute7
1017 	  ,l_msnt.c_attribute8
1018 	  ,l_msnt.c_attribute9
1019 	  ,l_msnt.c_attribute10
1020 	  ,l_msnt.c_attribute11
1021 	  ,l_msnt.c_attribute12
1022 	  ,l_msnt.c_attribute13
1023 	  ,l_msnt.c_attribute14
1024 	  ,l_msnt.c_attribute15
1025 	  ,l_msnt.c_attribute16
1026 	  ,l_msnt.c_attribute17
1027 	  ,l_msnt.c_attribute18
1028 	  ,l_msnt.c_attribute19
1029 	  ,l_msnt.c_attribute20
1030 	  ,l_msnt.d_attribute1
1031 	,l_msnt.d_attribute2
1032 	,l_msnt.d_attribute3
1033 	,l_msnt.d_attribute4
1034 	,l_msnt.d_attribute5
1035 	,l_msnt.d_attribute6
1036 	,l_msnt.d_attribute7
1037 	,l_msnt.d_attribute8
1038 	,l_msnt.d_attribute9
1039 	,l_msnt.d_attribute10
1040 	,l_msnt.n_attribute1
1041 	,l_msnt.n_attribute2
1042 	,l_msnt.n_attribute3
1043 	,l_msnt.n_attribute4
1044 	,l_msnt.n_attribute5
1045 	,l_msnt.n_attribute6
1046 	,l_msnt.n_attribute7
1047 	,l_msnt.n_attribute8
1048 	,l_msnt.n_attribute9
1049 	,l_msnt.n_attribute10
1050 	,l_msnt.status_id
1051 	,l_msnt.territory_code
1052 	,l_msnt.time_since_new
1053 	,l_msnt.cycles_since_new
1054 	,l_msnt.time_since_overhaul
1055 	,l_msnt.cycles_since_overhaul
1056 	,l_msnt.time_since_repair
1057 	,l_msnt.cycles_since_repair
1058 	,l_msnt.time_since_visit
1059 	,l_msnt.cycles_since_visit
1060 	,l_msnt.time_since_mark
1061 	,l_msnt.cycles_since_mark
1062 	,l_msnt.number_of_repairs
1063 	,'RCV'
1064 	,p_prod_txn_id );
1065 
1066       l_progress := 'WMSINB-10870';
1067 
1068    END LOOP;
1069 
1070    IF (l_debug = 1) THEN
1071       print_debug('CREATE_LOT_SERIAL_HISTORY: Deleting MTLI/MSNT',1);
1072    END IF;
1073 
1074    --Delete MTLT/MSNT here
1075    DELETE FROM mtl_transaction_lots_temp
1076      WHERE product_code = 'RCV'
1077      AND product_transaction_id = p_prod_txn_tmp_id;
1078 
1079    l_progress := 'WMSINB-10883';
1080 
1081    DELETE FROM mtl_serial_numbers_temp
1082      WHERE product_code = 'RCV'
1083      AND product_transaction_id = p_prod_txn_tmp_id;
1084 
1085    IF (l_debug = 1) THEN
1086       print_debug('CREATE_LOT_SERIAL_HISTORY: Exited',1);
1087    END IF;
1088 
1089 EXCEPTION
1090    WHEN OTHERS THEN
1091       IF (l_debug = 1) THEN
1092 	 print_debug('CREATE_LOT_SERIAL_HISTORY: Exception occured aftr l_progress = '
1093 		     || l_progress,1);
1094       END IF;
1095       x_return_status := g_ret_sts_unexp_error;
1096       --fnd_msg_pub.count_and_get
1097       --  (   p_count                       => x_msg_count
1098       --      ,p_data                       => x_msg_data
1099       --      );
1100       ROLLBACK TO process_lot_serial_pub;
1101 END create_lot_serial_history;
1102 
1103 PROCEDURE cancel_asn
1104   (x_return_status OUT nocopy VARCHAR2
1105    ,x_msg_count OUT nocopy NUMBER
1106    ,x_msg_data OUT nocopy VARCHAR2
1107    ,p_shipment_header_id IN NUMBER
1108    ,p_shipment_line_id IN NUMBER
1109    ,p_primary_quantity IN NUMBER
1110 )
1111   IS
1112 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
1113      TYPE varchar30_tb_tp IS TABLE OF VARCHAR2(80) INDEX BY BINARY_INTEGER;
1114      TYPE number_tb_tp IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
1115      l_serial_numbers varchar30_tb_tp;
1116      l_lot_numbers varchar30_tb_tp;
1117      l_quantitys number_tb_tp;
1118 
1119      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1120      l_progress VARCHAR (15) := '0';
1121      l_asn_lpn_id NUMBER;
1122      l_item_id NUMBER;
1123      l_quantity_to_unpack NUMBER;
1124      l_lot_control_code NUMBER;
1125      l_serial_number_control_code NUMBER;
1126      l_lpn_context NUMBER;
1127      l_org_id NUMBER;
1128      l_uom_code VARCHAR2(3);
1129      l_quantity_received NUMBER;
1130      l_unit_of_measure VARCHAR2(25);
1131      l_prim_uom_code VARCHAR2(3);
1132      l_revision VARCHAR2(3);
1133 
1134      -- OPMConvergence
1135      l_sec_lot_qty            number_tb_tp;
1136      l_sec_uom_code           VARCHAR2(3);
1137      l_sec_uom_code_2         VARCHAR2(3);
1138      l_sec_quantity_to_unpack NUMBER;
1139      l_sec_unit_of_measure    VARCHAR2(25);
1140      -- OPMConvergence
1141 
1142      l_mol_res_in  cas_mol_rec_tb_tp;
1143      l_mol_res_out cas_mol_rec_tb_tp;
1144      l_po_header_id NUMBER;
1145      l_po_line_location_id NUMBER;
1146      l_prim_qty_to_unpack NUMBER;
1147      l_procedure_name         VARCHAR2(30) := 'CANCEL_ASN';
1148      l_serials_count    NUMBER := 0; --added for bug 6708102
1149      l_lots_count       NUMBER := 0; --added for bug 6708102
1150 BEGIN
1151    IF (l_debug = 1) THEN
1152       print_debug('CANCEL_ASN: Entering...', 1);
1153       print_debug('             p_shipment_header_id => '||
1154 		  p_shipment_header_id,1);
1155       print_debug('             p_shipment_lind_id   => '||
1156 		  p_shipment_line_id,1);
1157    END IF;
1158 
1159    x_return_status := g_ret_sts_success;
1160 
1161    l_progress := 'WMSINB-10945';
1162 
1163    BEGIN
1164       SELECT
1165 	rsl.asn_lpn_id asn_lpn_id
1166 	,rsl.item_id item_id
1167 	,rsl.item_revision revision
1168 	,rsl.to_organization_id organization_id
1169 	,rsl.unit_of_measure unit_of_measure
1170 	,msi.primary_uom_code prim_uom_code
1171 	,(Nvl(rsl.quantity_shipped,0) - Nvl(rsl.quantity_received,0)) quantity_to_unpack
1172    -- OPMConvergence
1173 	,rsl.secondary_unit_of_measure sec_unit_of_measure
1174 	,msi.secondary_uom_code sec_uom_code
1175 	,(Nvl(rsl.secondary_quantity_shipped,0) - Nvl(rsl.secondary_quantity_received,0)) sec_quantity_to_unpack
1176         -- OPMConvergence
1177 	,Nvl(rsl.quantity_received,0)
1178     ,msi.lot_control_code lot_control_code
1179 	,msi.serial_number_control_code serial_number_control_code
1180 --	,wlpn.lpn_context lpn_context
1181 	,rsl.po_line_location_id
1182 	,rsl.po_header_id
1183 	INTO
1184 	l_asn_lpn_id
1185 	,l_item_id
1186 	,l_revision
1187 	,l_org_id
1188 	,l_unit_of_measure
1189 	,l_prim_uom_code
1190 	,l_quantity_to_unpack
1191          -- OPMConvergence
1192 	,l_sec_unit_of_measure
1193 	,l_sec_uom_code
1194 	,l_sec_quantity_to_unpack
1195          -- OPMConvergence
1196 	,l_quantity_received
1197     ,l_lot_control_code
1198 	,l_serial_number_control_code
1199 --	,l_lpn_context
1200 	,l_po_line_location_id
1201 	,l_po_header_id
1202 	FROM
1203 	rcv_shipment_lines rsl
1204 	,mtl_system_items msi
1205 	WHERE
1206 	rsl.shipment_line_id = p_shipment_line_id
1207 	AND rsl.shipment_header_id = p_shipment_header_id
1208 	AND msi.inventory_item_id = rsl.item_id
1209 	AND msi.organization_id = rsl.to_organization_id;
1210    EXCEPTION
1211       --BUG 3387020
1212       WHEN no_data_found THEN
1213 	 IF (l_debug = 1) THEN
1214 	    print_debug('No data found for shipment_line_id: ' ||
1215 			p_shipment_line_id, 1);
1216 	 END IF;
1217 	 l_progress := 'WMSINB-10985';
1218 	 l_asn_lpn_id := NULL;
1219       WHEN OTHERS THEN
1220 	 IF (l_debug = 1) THEN
1221 	    print_debug('Error retrieving shipment line with id: ' ||
1222 			p_shipment_line_id, 1);
1223 	 END IF;
1224 	 l_progress := 'WMSINB-10986';
1225 	 RAISE fnd_api.g_exc_error;
1226    END;
1227 
1228    l_progress := 'WMSINB-10990';
1229 
1230    --BUG 3387020
1231    IF l_asn_lpn_id IS NOT NULL THEN
1232       BEGIN
1233 	 SELECT lpn_context
1234 	   INTO l_lpn_context
1235 	   FROM wms_license_plate_numbers
1236 	   WHERE lpn_id = l_asn_lpn_id;
1237       EXCEPTION
1238 	 WHEN OTHERS THEN
1239 	    IF (l_debug = 1) THEN
1240 	       print_debug('Error retrieving LPN context!',1);
1241 	    END IF;
1242 	    l_progress := 'WMSINB-10009';
1243 	    RAISE fnd_api.g_exc_error;
1244       END;
1245     ELSE
1246       l_lpn_context := NULL;
1247    END IF;
1248 
1249    IF (Nvl(l_lpn_context,-1) = 7) THEN
1250       IF (l_debug = 1) THEN
1251 	 print_debug('CANCEL_ASN: LPN Context is 7',
1252 		     1);
1253       END IF;
1254 
1255       IF (l_serial_number_control_code IN (2, 5)) THEN
1256 
1257 	 l_progress := 'WMSINB-11000';
1258 	 IF (l_debug = 1) THEN
1259 	    print_debug('CANCEL_ASN: item is serial_controlled', 1);
1260 	 END IF;
1261 
1262 	 BEGIN
1263 	    SELECT
1264 	      serial_num
1265 	      ,lot_num
1266 	      BULK collect INTO
1267 	      l_serial_numbers
1268 	      ,l_lot_numbers
1269 	      FROM
1270 	      rcv_serials_supply
1271 	      WHERE
1272 	      shipment_line_id = p_shipment_line_id
1273 	      AND supply_type_code = 'SHIPMENT';
1274 	 EXCEPTION
1275 	    WHEN OTHERS THEN
1276 	       IF (l_debug = 1) THEN
1277 		  print_debug('CANCEL_ASN: Error retrieving serial numbers'
1278 			      ,1);
1279 	       END IF;
1280 	 END;
1281 
1282 	 l_progress := 'WMSINB-11025';
1283 
1284 	 FOR i IN 1 .. l_serial_numbers.COUNT LOOP
1285 	    wms_container_pvt.packunpack_container
1286 	      (p_api_version       =>   1.0
1287 	       ,p_validation_level =>  fnd_api.g_valid_level_none
1288 	       ,p_lpn_id           =>   l_asn_lpn_id
1289 	       ,p_operation        =>   2 -- UNPACK
1290 	       ,p_organization_id  =>   l_org_id
1291 	       ,p_content_item_id  =>   l_item_id
1292 	       ,p_revision         =>   l_revision
1293 	       ,p_lot_number       =>   l_lot_numbers(i)
1294 	       ,p_from_serial_number => l_serial_numbers(i)
1295 	       ,p_to_serial_number =>   l_serial_numbers(i)
1296 	       ,p_uom              =>   l_prim_uom_code
1297 	       ,p_commit           =>   fnd_api.g_true --??
1298 	       ,x_return_status    =>   x_return_status
1299 	       ,x_msg_count        =>   x_msg_count
1300 	       ,x_msg_data         =>   x_msg_data
1301 	       );
1302 	    IF (x_return_status <> g_ret_sts_success) THEN
1303 	       IF (l_debug = 1) THEN
1304 		  print_debug('CANCEL_ASN: packunpack failed, but continue anyway', 1);
1305 	       END IF;
1306 	    END IF;
1307 	 END LOOP;
1308 
1309 	 IF (l_serial_numbers.COUNT = 0) THEN
1310 	    l_progress := 'WMSINB-11052';
1311 	    BEGIN
1312 	       SELECT uom_code
1313 		 into l_uom_code
1314 		 FROM mtl_item_uoms_view
1315 		 WHERE organization_id = l_org_id
1316 		 AND inventory_item_id = l_item_id
1317 		 AND unit_of_measure = l_unit_of_measure;
1318 	    EXCEPTION
1319 	       WHEN OTHERS THEN
1320 		  IF (l_debug = 1) THEN
1321 		     print_debug('CANCEL_ASN: Error retrieving uom_code', 1);
1322 		  END IF;
1323 		  l_progress := 'WMSINB-11065';
1324 		  RAISE fnd_api.g_exc_error;
1325 	    END;
1326 
1327 	    l_progress := 'WMSINB-11068';
1328 	    IF (l_debug = 1) THEN
1329 	       print_debug('CANCEL_ASN: Serial controlled, but no serial '
1330 			   || 'Calling pup ',1);
1331 	    END IF;
1332 
1333 	    wms_container_pvt.packunpack_container
1334 	      (p_api_version       =>   1.0
1335 	       ,p_validation_level =>  fnd_api.g_valid_level_none
1336 	       ,p_lpn_id           =>   l_asn_lpn_id
1337 	       ,p_operation        =>   2 -- UNPACK
1338 	       ,p_organization_id  =>   l_org_id
1339 	       ,p_content_item_id  =>   l_item_id
1340 	       ,p_revision         =>   l_revision
1341 	       ,p_quantity         =>   l_quantity_to_unpack
1342 	       ,p_uom              =>   l_uom_code
1343 	       ,p_commit           =>   fnd_api.g_true --??
1344 	       ,x_return_status    =>   x_return_status
1345 	       ,x_msg_count        =>   x_msg_count
1346 	       ,x_msg_data         =>   x_msg_data
1347 	       );
1348 	    IF (x_return_status <> g_ret_sts_success) THEN
1349 	       IF (l_debug = 1) THEN
1350 		  print_debug('CANCEL_ASN: packunpack failed, but continue anyway', 1);
1351 	       END IF;
1352 	    END IF;
1353 	 END IF;
1354        ELSIF (l_lot_control_code = 2) THEN
1355 	    l_progress := 'WMSINB-11096';
1356 	    IF (l_debug = 1) THEN
1357 	       print_debug('CANCEL_ASN: Item is lot controlled',1);
1358 	    END IF;
1359 
1360 	    BEGIN
1361 	       SELECT
1362 		 lot_num
1363 		 ,SUM(quantity)
1364                   -- OPMConvergence
1365 		 ,SUM(secondary_quantity)
1366                   -- OPMConvergence
1367 		 bulk collect INTO
1368 		 l_lot_numbers
1369 		 ,l_quantitys
1370                   -- OPMConvergence
1371                  ,l_sec_lot_qty
1372                   -- OPMConvergence
1373 		 FROM
1374 		 rcv_lots_supply
1375 		 WHERE
1376 		 shipment_line_id = p_shipment_line_id
1377 		 AND supply_type_code = 'SHIPMENT'
1378 		 GROUP BY lot_num;
1379 	    EXCEPTION
1380 	       WHEN OTHERS THEN
1381 		  IF (l_debug = 1) THEN
1382 		     print_debug('CANCEL_ASN: Error retrieving lot numbers'
1383 				 ,1);
1384 		  END IF;
1385 	    END;
1386 
1387 	    l_progress := 'WMSINB-11121';
1388 
1389 	    FOR i IN 1 .. l_lot_numbers.COUNT LOOP
1390 	       wms_container_pvt.packunpack_container
1391 		 (p_api_version       =>   1.0
1392 		  ,p_validation_level =>  fnd_api.g_valid_level_none
1393 		  ,p_lpn_id           =>   l_asn_lpn_Id
1394 		  ,p_operation        =>   2 -- UNPACK
1395 		  ,p_organization_id  =>   l_org_id
1396 		  ,p_content_item_id  =>   l_item_id
1397 		  ,p_revision         =>   l_revision
1398 		  ,p_lot_number       =>   l_lot_numbers(i)
1399 		  ,p_quantity         =>   l_quantitys(i)
1400 		  ,p_uom              =>   l_prim_uom_code
1401 		  ,p_commit           =>   fnd_api.g_true
1402 		  ,x_return_status    =>   x_return_status
1403 		  ,x_msg_count        =>   x_msg_count
1404 		  ,x_msg_data         =>   x_msg_data
1405                    -- OPMConvergence
1406                   ,p_sec_uom          =>   l_sec_uom_code
1407                   ,p_sec_quantity     =>   l_sec_lot_qty(i)
1408                    -- OPMConvergence
1409 		  );
1410 	       IF (x_return_status <> g_ret_sts_success) THEN
1411 		  IF (l_debug = 1) THEN
1412 		     print_debug('CANCEL_ASN: packunpack failed, but continue anyway', 1);
1413 		  END IF;
1414 	       END IF;
1415 	    END LOOP;
1416 
1417 	    IF (l_lot_numbers.COUNT = 0) THEN
1418 	       l_progress := 'WMSINB-11148';
1419 	       BEGIN
1420 		  SELECT uom_code
1421 		    into l_uom_code
1422 		    FROM mtl_item_uoms_view
1423 		    WHERE organization_id = l_org_id
1424 		    AND inventory_item_id = l_item_id
1425 		    AND unit_of_measure = l_unit_of_measure;
1426 	       EXCEPTION
1427 		  WHEN OTHERS THEN
1428 		     IF (l_debug = 1) THEN
1429 			print_debug('CANCEL_ASN: Error retrieving uom_code', 1);
1430 		     END IF;
1431 		     l_progress := 'WMSINB-11161';
1432 		     RAISE fnd_api.g_exc_error;
1433 	       END;
1434 
1435                -- OPMConvergence
1436           IF l_sec_unit_of_measure IS NOT NULL THEN
1437 
1438 	          BEGIN
1439 	             SELECT uom_code
1440 		          INTO   l_sec_uom_code_2
1441 		          FROM   mtl_item_uoms_view
1442 		          WHERE  organization_id = l_org_id
1443 		          AND    inventory_item_id = l_item_id
1444 		          AND    unit_of_measure = l_sec_unit_of_measure;
1445 	          EXCEPTION
1446 	             WHEN OTHERS THEN
1447 		            IF (l_debug = 1) THEN
1448 		               print_debug('CANCEL_ASN: Error retrieving sec_uom_code'||sqlerrm, 1);
1449 		            END IF;
1450 		          l_progress := 'WMSINB-11161';
1451 		          RAISE fnd_api.g_exc_error;
1452 	          END;
1453 
1454           END IF;
1455                -- OPMConvergence
1456 
1457 	       l_progress := 'WMSINB-11164';
1458 	       IF (l_debug =1 ) THEN
1459 		  print_debug('CANCEL_ASN: Lot controlled, but no lot row',1);
1460 	       END IF;
1461 
1462 	       wms_container_pvt.packunpack_container
1463 		 (p_api_version       =>   1.0
1464 		  ,p_validation_level =>  fnd_api.g_valid_level_none
1465 		  ,p_lpn_id           =>   l_asn_lpn_id
1466 		  ,p_operation        =>   2 -- UNPACK
1467 		  ,p_organization_id  =>   l_org_id
1468 		  ,p_content_item_id  =>   l_item_id
1469 		  ,p_revision         =>   l_revision
1470 		  ,p_quantity         =>   l_quantity_to_unpack
1471 		  ,p_uom              =>   l_uom_code
1472 		  ,p_commit           =>   fnd_api.g_true --??
1473 		  ,x_return_status    =>   x_return_status
1474 		  ,x_msg_count        =>   x_msg_count
1475 		  ,x_msg_data         =>   x_msg_data
1476                   -- OPMConvergence
1477 		  ,p_sec_quantity     =>   l_sec_quantity_to_unpack
1478 		  ,p_sec_uom          =>   l_sec_uom_code_2
1479                   -- OPMConvergence
1480 		  );
1481 	       IF (x_return_status <> g_ret_sts_success) THEN
1482 		  IF (l_debug = 1) THEN
1483 		     print_debug('CANCEL_ASN: packunpack failed, but continue anyway', 1);
1484 		  END IF;
1485 	       END IF;
1486 	    END IF;
1487 
1488        ELSE -- neither lot/serial controlled
1489 	       IF (l_debug = 1) THEN
1490 		  print_debug('CANCEL_ASN: Item is neither lot or serial controlled',
1491 			      1);
1492 	       END IF;
1493 
1494 	       l_progress := 'WMSINB-11197';
1495 
1496 	       BEGIN
1497 		  SELECT uom_code
1498 		    into l_uom_code
1499 		    FROM mtl_item_uoms_view
1500 		    WHERE organization_id = l_org_id
1501 		    AND inventory_item_id = l_item_id
1502 		    AND unit_of_measure = l_unit_of_measure;
1503 	       EXCEPTION
1504 		  WHEN OTHERS THEN
1505 		     IF (l_debug = 1) THEN
1506 			print_debug('CANCEL_ASN: Error retrieving uom_code', 1);
1507 		     END IF;
1508 		     l_progress := 'WMSINB-11211';
1509 		     RAISE fnd_api.g_exc_error;
1510 	       END;
1511 
1512                -- OPMConvergence
1513           IF l_sec_unit_of_measure IS NOT NULL THEN
1514 
1515 	          BEGIN
1516 	             SELECT uom_code
1517 		          INTO   l_sec_uom_code_2
1518 		          FROM   mtl_item_uoms_view
1519 		          WHERE  organization_id = l_org_id
1520 		          AND    inventory_item_id = l_item_id
1521 		          AND    unit_of_measure = l_sec_unit_of_measure;
1522 	          EXCEPTION
1523 	             WHEN OTHERS THEN
1524 		          IF (l_debug = 1) THEN
1525 		            print_debug('CANCEL_ASN: Error retrieving sec_uom_code'||sqlerrm, 1);
1526 		          END IF;
1527 		          l_progress := 'WMSINB-11211';
1528 		          RAISE fnd_api.g_exc_error;
1529 	          END;
1530 
1531           END IF;
1532                -- OPMConvergence
1533            l_quantity_to_unpack := p_primary_quantity - l_quantity_received;
1534 	       l_progress := 'WMSINB-11215';
1535 
1536 	       wms_container_pvt.packunpack_container
1537 		 (p_api_version       =>   1.0
1538 		  ,p_validation_level =>  fnd_api.g_valid_level_none
1539 		  ,p_lpn_id           =>   l_asn_lpn_id
1540 		  ,p_operation        =>   2 -- UNPACK
1541 		  ,p_organization_id  =>   l_org_id
1542 		  ,p_content_item_id  =>   l_item_id
1543 		  ,p_revision         =>   l_revision
1544 		  ,p_quantity         =>   l_quantity_to_unpack
1545 		  ,p_uom              =>   l_uom_code
1546 		  ,p_commit           =>   fnd_api.g_true --??
1547 		  ,x_return_status    =>   x_return_status
1548 		  ,x_msg_count        =>   x_msg_count
1549 		  ,x_msg_data         =>   x_msg_data
1550                   -- OPMConvergence
1551 		  ,p_sec_quantity     =>   l_sec_quantity_to_unpack
1552 		  ,p_sec_uom          =>   l_sec_uom_code_2
1553                   -- OPMConvergence
1554 		  );
1555 	       IF (x_return_status <> g_ret_sts_success) THEN
1556 		  IF (l_debug = 1) THEN
1557 		     print_debug('CANCEL_ASN: packunpack failed, but continue anyway', 1);
1558 		  END IF;
1559 	       END IF;
1560       END IF; -- end if l_serial_control in ( 2, 5)
1561    END IF;  -- end if (l_lpn_context = 7)
1562 
1563    IF (l_debug = 1) THEN
1564       print_debug('CANCEL_ASN: CALLING RSV API',1);
1565       print_debug('l_org_id               => '||l_org_id,1);
1566       print_debug('l_item_id              => '||l_item_id,1);
1567       print_debug('l_revision             => '||l_revision,1);
1568       print_debug('l_primary_uom          => '||l_prim_uom_code,1);
1569       print_debug('l_po_header_id         => '||l_po_header_id,1);
1570       print_debug('l_po_line_location_id  => '||l_po_line_location_id,1);
1571       print_debug('p_shipment_line_id     => '||p_shipment_line_id,1);
1572    END IF;
1573 
1574    l_mol_res_in(1).transaction_type       := 'CANCEL';
1575    l_mol_res_in(1).organization_id        := l_org_id;
1576    l_mol_res_in(1).inventory_item_id      := l_item_id;
1577    l_mol_res_in(1).item_revision          := l_revision;
1578    l_mol_res_in(1).primary_uom_code       := l_prim_uom_code;
1579    l_mol_res_in(1).po_header_id           := l_po_header_id;
1580    l_mol_res_in(1).po_line_location_id    := l_po_line_location_id;
1581    l_mol_res_in(1).shipment_line_id       := p_shipment_line_id;
1582 
1583    INV_RCV_RESERVATION_UTIL.maintain_reservations
1584      (x_return_status => x_return_status
1585       ,x_msg_count     => x_msg_count
1586       ,x_msg_data      => x_msg_data
1587       ,x_mol_tb        => l_mol_res_out
1588       ,p_cas_mol_tb    => l_mol_res_in
1589       );
1590 
1591    IF (l_debug = 1) THEN
1592       print_debug('CANCEL_ASN - rsv api returns:'||x_return_status,1);
1593    END IF;
1594 
1595    IF (x_return_status <> g_ret_sts_success) THEN
1596       l_progress := 'WMSINB-14998';
1597       RAISE FND_API.G_EXC_ERROR;
1598    END IF;
1599 
1600    /* ******************************************************
1601      BUG 6708102 by kagupta
1602 
1603      Description: Following code added to handle the proper
1604                   deletion of the serials and lots
1605                   from rcv and updation of msn.
1606     *******************************************************
1607    */
1608   IF (l_debug = 1) THEN
1609      l_progress := 'WMSINB-14999';
1610      print_debug('CANCEL_ASN - serial/lot updation:'||l_progress,1);
1611   END IF;
1612 
1613    SELECT Count(*)
1614    INTO l_serials_count
1615    FROM rcv_serials_supply
1616    WHERE shipment_line_id = p_shipment_line_id
1617    AND supply_type_code = 'SHIPMENT';
1618 
1619    SELECT Count(*)
1620    INTO l_lots_count
1621    FROM rcv_lots_supply
1622    WHERE shipment_line_id = p_shipment_line_id
1623    AND supply_type_code = 'SHIPMENT';
1624 
1625    IF (l_debug = 1) THEN
1626        l_progress := 'WMSINB-15000';
1627        print_debug('CANCEL_ASN - serial/lot updation:'||l_progress,1);
1628    END IF;
1629 
1630    IF l_serials_count > 0  THEN
1631       /* Changed the serial_number with serial_num in inner query for the bug#16068136
1632          With out this fix, status of all the serials of the item are updating to 1*/
1633     UPDATE mtl_serial_numbers
1634     SET current_status  = 1,
1635     group_mark_id = NULL,
1636     line_mark_id = NULL,
1637     lot_line_mark_id = NULL
1638     WHERE inventory_item_id = l_item_id
1639     AND current_organization_id = l_org_id
1640     AND serial_number IN (SELECT serial_num
1641                           FROM rcv_serials_supply
1642                           WHERE shipment_line_id = p_shipment_line_id
1643                           AND supply_type_code = 'SHIPMENT')
1644     AND current_status = 5;
1645 
1646 
1647     DELETE FROM rcv_serials_supply
1648     WHERE shipment_line_id = p_shipment_line_id
1649     AND supply_type_code = 'SHIPMENT';
1650    END IF;
1651 
1652     IF (l_debug = 1) THEN
1653         l_progress := 'WMSINB-15001';
1654         print_debug('CANCEL_ASN - serial/lot updation:'||l_progress,1);
1655     END IF;
1656 
1657    IF l_lots_count > 0  THEN
1658 
1659     DELETE FROM rcv_lots_supply
1660     WHERE shipment_line_id = p_shipment_line_id
1661     AND supply_type_code = 'SHIPMENT';
1662 
1663    END IF;
1664 
1665    IF (l_debug = 1) THEN
1666        l_progress := 'WMSINB-15002';
1667        print_debug('CANCEL_ASN - serial/lot updation:'||l_progress,1);
1668    END IF;
1669    /* ****************BUG 6708071 ENDS ********************/
1670 
1671    IF (l_debug = 1) THEN
1672       print_debug('CANCEL_ASN: Exiting cancel_asn',1);
1673    END IF;
1674 
1675 EXCEPTION
1676    WHEN OTHERS THEN
1677       IF (l_debug = 1) THEN
1678 	 print_debug('CANCEL_ASN: Exception ocurred after l_progress = ' ||
1679 		     l_progress,1);
1680       END IF;
1681       fnd_message.set_name('INV', 'INV_CANCEL_ASN_FAIL');
1682       fnd_msg_pub.ADD;
1683       ROLLBACK TO cancel_asn_pub;
1684       --	fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data =>
1685       --				  x_msg_data);
1686       x_return_status  := g_ret_sts_unexp_error;
1687 END cancel_asn;
1688 
1689 --
1690 -- This Procedue Packs Marterial into LPN
1691 -- IF ( l_lot_control_code > 1 AND l_serial_control_code <> 1 ) THEN -- CASE FOR LOT/SERIAL CONTROLLED
1692 -- Elsif ( l_lot_control_code > 1 and l_serial_control_code <> 1)  THEN -- CASE FOR LOT CONTROLLED ONLY
1693 -- Elsif (l_lot_control_code =1 and l_serial_control_code <> 1 ) -- CASE FOR SERIAL CONTROLLED ONLY
1694 -- ELse -- CASE FOR VANILA ITEM
1695 -- End if;
1696 
1697 Procedure PackUnpack_wrapper( x_return_status               OUT NOCOPY VARCHAR2
1698 			      ,x_msg_count                   OUT NOCOPY NUMBER
1699 			      ,x_msg_data                    OUT NOCOPY VARCHAR2
1700 			      ,p_lot_control_code            IN NUMBER default NULL
1701 			      ,p_serial_control_code         IN NUMBER default NULL
1702 			      ,p_product_txn_id              IN NUMBER
1703 			      ,p_product_code                IN VARCHAR2
1704 			      ,p_lpn_id                      IN NUMBER
1705 			      ,p_content_lpn_id              IN NUMBER
1706 			      ,p_content_item_id             IN NUMBER
1707 			      ,p_content_item_desc           IN VARCHAR2
1708 			      ,p_revision                    IN VARCHAR2
1709 			      ,p_primary_quantity            IN NUMBER
1710 			      ,p_primary_uom                 IN VARCHAR2
1711 			      ,p_organization_id             IN NUMBER
1712 			      ,p_operation                   IN NUMBER default 1
1713 			      ,p_cost_group_id               IN NUMBER
1714 			      ,p_source_type_id              IN NUMBER
1715 			      ,p_source_header_id            IN NUMBER
1716                               ,p_source_name                 IN VARCHAR2
1717                               ,p_source_line_id              IN NUMBER
1718                               ,p_source_line_detail_id       IN NUMBER
1719                               ,p_auto_unnest_empty_lpns      IN NUMBER DEFAULT 1
1720                                -- OPMConvergence
1721                               ,p_sec_quantity                IN NUMBER DEFAULT NULL
1722                               ,p_sec_uom                     IN VARCHAR2 DEFAULT NULL
1723                                -- OPMConvergence
1724                                -- R12
1725                               ,p_txn_quantity                IN NUMBER DEFAULT NULL
1726                               ,p_txn_uom_code                IN VARCHAR2 DEFAULT NULL
1727 							  ,p_ignore_item_controls        IN  NUMBER :=2 -- 12610461
1728                               ) is
1729      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1730      l_progress VARCHAR2(15) := '10';
1731 
1732      l_total_lot_qty    NUMBER := 0;
1733      l_total_ser_qty NUMBER := 0;
1734 
1735      l_procedure_name VARCHAR2(30) := 'PACKUNPACK_WRAPPER';
1736 
1737 BEGIN
1738 
1739    -- Initialize API return status to success
1740 
1741    x_return_status  := g_ret_sts_success;
1742 
1743    l_progress := 'WMSINB-11301';
1744 
1745    -- GET the TOTAL LOT QTY
1746    if p_lot_control_code > 1 then
1747 BEGIN
1748    l_progress := 'WMSINB-11306';
1749    SELECT Nvl(SUM(transaction_quantity),0)
1750      INTO l_total_lot_qty
1751      FROM mtl_transaction_lots_temp
1752      WHERE product_code = p_product_code
1753      AND product_transaction_id = p_product_txn_id;
1754 END;
1755    End if;
1756 
1757    IF (l_debug = 1) THEN
1758       print_debug('PACKUNPACK_WRAPPER - Lot Control code:'||p_lot_control_code,1);
1759       print_debug('PACKUNPACK_WRAPPER - Total Lot Qty:'||l_total_lot_qty,1);
1760    END IF;
1761 
1762    -- GET the TOTAL SERIAL QTY
1763 
1764    if nvl(p_serial_control_code,1) <> 1 then
1765       BEGIN
1766 	 l_progress := 'WMSINB-11324';
1767 	 SELECT Nvl(SUM(inv_serial_number_pub.get_serial_diff(fm_serial_number,to_serial_number)),0)
1768 	   INTO l_total_ser_qty
1769 	   FROM mtl_serial_numbers_temp
1770 	   WHERE product_code = p_product_code
1771 	   AND product_transaction_id = p_product_txn_id;
1772       END;
1773    End if;
1774 
1775    IF (l_debug = 1) THEN
1776       print_debug('PACKUNPACK_WRAPPER - Serial Control code:'||p_serial_control_code,1);
1777       print_debug('PACKUNPACK_WRAPPER - Total Serial Qty:'||l_total_ser_qty,1);
1778    END IF;
1779 
1780    IF ( p_lot_control_code > 1 and l_total_lot_qty > 0 ) then
1781       l_progress := 'WMSINB-11339';
1782       if ( nvl(p_serial_control_code,1) <> 1 and l_total_ser_qty > 0 ) then -- CASE FOR BOTH LOT and SERIAL CONTROLLED ITEM
1783 	 -- Loop Through MTLT MSNT and INSERT
1784 	 l_progress := 'WMSINB-11342';
1785 	 For l_lot_rec in ( select Ltrim(Rtrim(lot_number)) lot_number
1786 			    , primary_quantity
1787 			    , serial_transaction_temp_id
1788 			    from mtl_transaction_lots_temp mtlt
1789 			    where mtlt.product_transaction_id = p_product_txn_id
1790 			    and mtlt.product_code = 'RCV'
1791 			    )
1792 	   Loop
1793 	      l_progress := 'WMSINB-11351';
1794 	      For l_serial_rec in ( select fm_serial_number
1795 				    , to_serial_number
1796 				    , inv_serial_number_pub.get_serial_diff(fm_serial_number,to_serial_number) serial_quantity
1797 				    from mtl_serial_numbers_temp msnt
1798 				    where msnt.transaction_temp_id = l_lot_rec.serial_transaction_temp_id
1799 				    and msnt.product_transaction_id = p_product_txn_id
1800 				    and msnt.product_code = 'RCV'
1801 				    )
1802 		Loop
1803 		   l_progress := 'WMSINB-11361';
1804 		   wms_container_pvt.packunpack_container(p_api_version  => 1.0
1805 							  ,x_return_status               => x_return_status
1806 							  ,x_msg_count                   => x_msg_count
1807 							  ,x_msg_data                    => x_msg_data
1808 							  ,p_lpn_id                      => p_lpn_id
1809 							  ,p_content_lpn_id              => p_content_lpn_id
1810 							  ,p_content_item_id             => p_content_item_id
1811 							  ,p_content_item_desc           => p_content_item_desc
1812 							  ,p_revision                    => p_revision
1813 							  ,p_lot_number                  => l_lot_rec.lot_number
1814 							  ,p_from_serial_number          => l_serial_rec.fm_serial_number
1815 							  ,p_to_serial_number            => l_serial_rec.to_serial_number
1816 							  ,p_quantity                    => l_serial_rec.serial_quantity
1817 							  ,p_uom                         => p_primary_uom
1818 							  ,p_organization_id             => p_organization_id
1819 							  ,p_subinventory                => null
1820 							  ,p_locator_id                  => null
1821 							  ,p_enforce_wv_constraints      => null
1822 		     ,p_operation                   => p_operation
1823 		     ,p_cost_group_id               => p_cost_group_id
1824 		     ,p_source_type_id              => p_source_type_id
1825 		     ,p_source_header_id            => p_source_header_id
1826 		     ,p_source_name                 => p_source_name
1827 		     ,p_source_line_id              => p_source_line_id
1828 		     ,p_source_line_detail_id       => p_source_line_detail_id
1829 		     ,p_validation_level            => fnd_api.g_valid_level_none
1830    --Bug #3457106    ,p_concurrent_pack             => 1
1831 		     ,p_auto_unnest_empty_lpns => p_auto_unnest_empty_lpns
1832 			 ,p_ignore_item_controls   => p_ignore_item_controls);
1833 
1834 		   l_progress := 'WMSINB-11390';
1835 
1836 		   if x_return_status <> G_RET_STS_SUCCESS Then
1837 		      -- MSG no new message just add the one on stack
1838 		      -- Check the Error Status from this call
1839 		      l_progress := 'WMSINB-11395';
1840 		      RAISE FND_API.G_EXC_ERROR;
1841 		   End if;
1842 
1843 		End Loop;
1844 	   End Loop;
1845 
1846        else -- CASE FOR JUST LOT CONTROLLED ITEM
1847 	 -- Loop Through MTLT And INSERT
1848 	 l_progress := 'WMSINB-11404';
1849 	 For l_lot_rec in ( select Ltrim(Rtrim(lot_number)) lot_number
1850 			    , primary_quantity
1851                             -- R12
1852                             , transaction_quantity
1853                             -- R12
1854                             -- OPMConvergence
1855                             , secondary_quantity
1856                              -- OPMConvergence
1857 			    from mtl_transaction_lots_temp mtlt
1858 			    where mtlt.product_transaction_id = p_product_txn_id
1859 			    and mtlt.product_code = 'RCV'
1860 			    )
1861 	   Loop
1862 	      l_progress := 'WMSINB-11412';
1863 	      wms_container_pvt.packunpack_container(p_api_version  => 1.0
1864 						     ,x_return_status               => x_return_status
1865 						     ,x_msg_count                   => x_msg_count
1866 						     ,x_msg_data                    => x_msg_data
1867 						     ,p_lpn_id                      => p_lpn_id
1868 						     ,p_content_lpn_id              => p_content_lpn_id
1869 						     ,p_content_item_id             => p_content_item_id
1870 						     ,p_content_item_desc           => p_content_item_desc
1871 						     ,p_revision                    => p_revision
1872 						     ,p_lot_number                  => l_lot_rec.lot_number
1873 						     ,p_from_serial_number          => null
1874 						     ,p_to_serial_number            => null
1875 						     ,p_quantity                    => l_lot_rec.transaction_quantity
1876                                                      ,p_primary_quantity            => Round(l_lot_rec.primary_quantity,5) --Added by 13591755 for GRUPO *R12*--
1877 						     ,p_uom                         => p_txn_uom_code
1878                                                                                        -- p_primary_uom --*R12*--
1879 						     ,p_organization_id             => p_organization_id
1880 						     ,p_subinventory                => null
1881 						     ,p_locator_id                  => null
1882 						     ,p_enforce_wv_constraints      => null
1883 		                                     ,p_operation                   => p_operation
1884 		                                     ,p_cost_group_id               => p_cost_group_id
1885 		                                     ,p_source_type_id              => p_source_type_id
1886 		                                     ,p_source_header_id            => p_source_header_id
1887 		                                     ,p_source_name                 => p_source_name
1888 		                                     ,p_source_line_id              => p_source_line_id
1889 		                                     ,p_source_line_detail_id       => p_source_line_detail_id
1890 		                                     ,p_validation_level            => fnd_api.g_valid_level_none
1891                                       --Bug #3457106 ,p_concurrent_pack             => 1
1892 		                                     ,p_auto_unnest_empty_lpns => p_auto_unnest_empty_lpns
1893                                                      -- OPMConvergence
1894                                                      ,p_sec_quantity                => l_lot_rec.secondary_quantity
1895                                                      ,p_sec_uom                     => p_sec_uom
1896                                                      -- OPMConvergence
1897 													 ,p_ignore_item_controls        => p_ignore_item_controls
1898                 );
1899 
1900 	      if x_return_status <> G_RET_STS_SUCCESS Then
1901 		 -- MSG no new message just add the one on stack
1902 		 -- Check the Error Status from this call
1903 		 l_progress := 'WMSINB-11444';
1904 		 RAISE FND_API.G_EXC_ERROR;
1905 	      End if;
1906 
1907 	   End Loop;
1908       End if;
1909     Elsif ( (nvl(p_lot_control_code,1) = 1 and
1910 	     nvl(p_serial_control_code,1) <> 1) and l_total_ser_qty > 0 )  then -- CASE FOR SERIAL CONTROLLED ITEM
1911 
1912       l_progress := 'WMSINB-11453';
1913       For l_serial_rec in ( select fm_serial_number
1914 			    ,to_serial_number
1915 			    ,inv_serial_number_pub.get_serial_diff(fm_serial_number,to_serial_number) serial_quantity
1916 			    from mtl_serial_numbers_temp msnt
1917 			    where msnt.product_transaction_id = p_product_txn_id
1918 			    and msnt.product_code = 'RCV'
1919 			    )
1920 	Loop
1921 	   -- Calculate the Quantity
1922 	   IF (l_debug = 1) THEN
1923 	      print_debug('PACKUNPACK_WRAPPER: packing fm serial :'||l_serial_rec.fm_serial_number,1);
1924 	      print_debug('PACKUNPACK_WRAPPER: packing to serial :'||l_serial_rec.to_serial_number,1);
1925 	   END IF;
1926 
1927 	   l_progress := 'WMSINB-11464';
1928 
1929 	   wms_container_pvt.packunpack_container(p_api_version                 => 1.0
1930 						  ,x_return_status               => x_return_status
1931 						  ,x_msg_count                   => x_msg_count
1932 						  ,x_msg_data                    => x_msg_data
1933 						  ,p_lpn_id                      => p_lpn_id
1934 						  ,p_content_lpn_id              => p_content_lpn_id
1935 						  ,p_content_item_id             => p_content_item_id
1936 						  ,p_content_item_desc           => p_content_item_desc
1937 						  ,p_revision                    => p_revision
1938 						  ,p_lot_number                  => null
1939 						  ,p_from_serial_number          => l_serial_rec.fm_serial_number
1940 						  ,p_to_serial_number            => l_serial_rec.to_serial_number
1941 						  ,p_quantity                    => l_serial_rec.serial_quantity
1942 						  ,p_uom                         => p_primary_uom
1943 						  ,p_organization_id             => p_organization_id
1944 						  ,p_subinventory                => null
1945 						  ,p_locator_id                  => null
1946 						  ,p_enforce_wv_constraints      => null
1947 	     ,p_operation                   => p_operation
1948 	     ,p_cost_group_id               => p_cost_group_id
1949 	     ,p_source_type_id              => p_source_type_id
1950 	     ,p_source_header_id            => p_source_header_id
1951 	     ,p_source_name                 => p_source_name
1952 	     ,p_source_line_id              => p_source_line_id
1953 	     ,p_source_line_detail_id       => p_source_line_detail_id
1954 	     ,p_validation_level            => fnd_api.g_valid_level_none
1955 --Bug#3457106,p_concurrent_pack             => 1
1956 	     ,p_auto_unnest_empty_lpns => p_auto_unnest_empty_lpns
1957 		 ,p_ignore_item_controls   => p_ignore_item_controls);
1958 
1959 	   if x_return_status <> G_RET_STS_SUCCESS Then
1960 	      -- MSG no new message just add the one on stack
1961 	      -- Check the Error Status from this call
1962 	      l_progress := 'WMSINB-11497';
1963 	      RAISE FND_API.G_EXC_ERROR;
1964 	   End if;
1965 
1966 	End Loop;
1967     Else -- CASE FOR VANILA ITEM
1968       -- Call container PUb PACkUNPACK
1969 
1970       l_progress := 'WMSINB-11505';
1971 
1972       wms_container_pvt.packunpack_container(p_api_version                 => 1.0
1973 					     ,x_return_status               => x_return_status
1974 					     ,x_msg_count                   => x_msg_count
1975 					     ,x_msg_data                    => x_msg_data
1976 					     ,p_lpn_id                      => p_lpn_id
1977 					     ,p_content_lpn_id              => p_content_lpn_id
1978 					     ,p_content_item_id             => p_content_item_id
1979 					     ,p_content_item_desc           => p_content_item_desc
1980 					     ,p_revision                    => p_revision
1981 					     ,p_lot_number                  => null
1982 					     ,p_from_serial_number          => null
1983 					     ,p_to_serial_number            => null
1984 					     ,p_quantity                    => p_txn_quantity
1985                          ,p_primary_quantity            => Round(p_primary_quantity,5) --Added by 13591755 for GRUPO *R12*--
1986 					     ,p_uom                         => p_txn_uom_code
1987                                                                                -- p_primary_uom --*R12* --
1988 					     ,p_organization_id             => p_organization_id
1989 					     ,p_subinventory                => null
1990 					     ,p_locator_id                  => null
1991 					     ,p_enforce_wv_constraints      => null
1992 					     ,p_operation                   => p_operation
1993 	                                     ,p_cost_group_id               => p_cost_group_id
1994 	                                     ,p_source_type_id              => p_source_type_id
1995 	                                     ,p_source_header_id            => p_source_header_id
1996 	                                     ,p_source_name                 => p_source_name
1997 	                                     ,p_source_line_id              => p_source_line_id
1998 	                                     ,p_source_line_detail_id       => p_source_line_detail_id
1999 	                                     ,p_validation_level            => fnd_api.g_valid_level_none
2000                                      --Bug #3457106	,p_concurrent_pack             => 1
2001 	                                     ,p_auto_unnest_empty_lpns => p_auto_unnest_empty_lpns
2002                                              -- OPMConvergence
2003                                              ,p_sec_quantity                => p_sec_quantity
2004                                              ,p_sec_uom                     => p_sec_uom
2005                                              -- OPMConvergence
2006                                              );
2007 
2008       IF (l_debug = 1) THEN
2009 	 print_debug('PACKUNPACK_WRAPPER: x_return_status:'||x_return_status,1);
2010       END IF;
2011 
2012       if x_return_status <> G_RET_STS_SUCCESS Then
2013 	 -- MSG no new message just add the one on stack
2014 	 -- Check the Error Status from this call
2015 	 l_progress := 'WMSINB-11542';
2016 	 RAISE FND_API.G_EXC_ERROR;
2017       End if;
2018 
2019    End if;
2020 
2021 EXCEPTION
2022 
2023    when fnd_api.g_exc_error THEN
2024       x_return_status  := g_ret_sts_error;
2025 
2026       IF (l_debug = 1) THEN
2027 	 print_debug('PACKUNPACK_WRAPPER : - Error :'|| l_progress ,1);
2028       END IF;
2029 
2030    WHEN OTHERS THEN
2031       x_return_status  := g_ret_sts_unexp_error;
2032 
2033       IF (l_debug = 1) THEN
2034          print_debug('PACKUNPACK_WRAPPER : - OTHER Exception:'|| l_progress || ' ' ||
2035 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
2036       END IF;
2037 
2038 End PackUnpack_wrapper;
2039 
2040 
2041 
2042 -- Description
2043 -- This just returns the LPN_ID for the License_plate_number passed
2044 -- if the license_plate_number exists in the system
2045 Function get_lpn_id(x_lpn_id               IN OUT NOCOPY NUMBER ,
2046 		    x_license_plate_number IN OUT NOCOPY VARCHAR2 ,
2047 		    x_lpn_context          OUT NOCOPY NUMBER,
2048 		    x_parent_lpn_id        OUT NOCOPY NUMBER,
2049 		    x_source_header_id     OUT nocopy NUMBER) return boolean
2050   is
2051 BEGIN
2052 
2053    -- print_debug('get LPN ID: 10 ', 1);
2054 
2055    -- Bug 4507808
2056    -- Performance Fix to get rid of NVLS
2057 
2058    if ( x_lpn_id is not null or x_license_plate_number is not null) then
2059       -- print_debug('get LPN ID: 20 ', 1);
2060       if ( x_lpn_id is not null and x_license_plate_number is not null) Then
2061          select lpn_id,
2062            license_plate_number,
2063            lpn_context,
2064            parent_lpn_id,
2065            source_header_id
2066            into x_lpn_id,
2067            x_license_plate_number,
2068            x_lpn_context,
2069            x_parent_lpn_id,
2070            x_source_header_id
2071            from wms_license_plate_numbers
2072            where lpn_id = x_lpn_id
2073            and license_plate_number = x_license_plate_number
2074            ;
2075          return TRUE;
2076       Elsif (x_lpn_id is not null and x_license_plate_number is null ) Then
2077          select lpn_id,
2078            license_plate_number,
2079            lpn_context,
2080            parent_lpn_id,
2081            source_header_id
2082            into x_lpn_id,
2083            x_license_plate_number,
2084            x_lpn_context,
2085            x_parent_lpn_id,
2086            x_source_header_id
2087            from wms_license_plate_numbers
2088            where lpn_id = x_lpn_id
2089            ;
2090          return TRUE;
2091       Elsif (x_lpn_id is null and x_license_plate_number is not null ) Then
2092          select lpn_id,
2093            license_plate_number,
2094            lpn_context,
2095            parent_lpn_id,
2096            source_header_id
2097            into x_lpn_id,
2098            x_license_plate_number,
2099            x_lpn_context,
2100            x_parent_lpn_id,
2101            x_source_header_id
2102            from wms_license_plate_numbers
2103            where license_plate_number = x_license_plate_number
2104            ;
2105          return TRUE;
2106       End if;
2107     else
2108       -- print_debug('get LPN ID: 30 ', 1);
2109       x_license_plate_number := null;
2110       x_lpn_id := to_number(null);
2111       x_lpn_context := to_number(null);
2112       x_parent_lpn_id := to_number(null);
2113       x_source_header_id := To_number(NULL);
2114       return TRUE;
2115    end if;
2116 EXCEPTION
2117    WHEN OTHERS THEN
2118       if x_lpn_id is not null then -- CASE WHERE LPN_ID is present and its an invalid ID
2119 	 --MSG WMS_CONT_INVALID_LPN
2120 	 -- print_debug('get LPN ID: Error =' || SQLCODE , 1);
2121 
2122 	 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
2123 	 fnd_msg_pub.ADD;
2124 
2125 	 x_lpn_context := to_number(null);
2126 	 x_parent_lpn_id := to_number(null);
2127 	 x_source_header_id := To_number(NULL);
2128 	 return FALSE;
2129        else -- MAY BE A CASE FOR NEW LPN
2130 	 x_lpn_context := to_number(null);
2131 	 x_parent_lpn_id := to_number(null);
2132 	 x_source_header_id := To_number(NULL);
2133 	 return TRUE;
2134       End if;
2135 END get_lpn_id;
2136 
2137 PROCEDURE modify_edi_xml_asn( p_group_id IN NUMBER
2138 			      ,x_return_status OUT nocopy VARCHAR2
2139 			      ,x_msg_count OUT nocopy NUMBER
2140 			      ,x_msg_data OUT nocopy VARCHAR2 )
2141   IS
2142 
2143      CURSOR rti_cur (l_grp_id NUMBER) IS
2144 	SELECT
2145 	  interface_transaction_id
2146 	  ,to_organization_id
2147 	  ,to_organization_code
2148 	  ,item_id
2149 	  ,item_num
2150 	  ,lpn_group_id
2151 	  ,quantity
2152 	  ,primary_quantity
2153 	  ,document_num
2154 	  FROM
2155 	  rcv_transactions_interface
2156 	  WHERE
2157 	  group_id = l_grp_id AND
2158 	  transaction_type = 'SHIP';
2159 
2160      CURSOR wlpnci_cur (l_intf_txn_id NUMBER) IS
2161 	SELECT
2162 	  wmslpnci.interface_transaction_id interface_transaction_id,
2163 	  wmslpn.lpn_id lpn_id,
2164 	  wmslpnci.license_plate_number license_plate_number,
2165 	  wmslpn.organization_id organization_id,
2166 	  wmslpnci.serial_transaction_intf_id,
2167 	  wmslpnci.lot_number lot_number,
2168 	  wmslpnci.quantity quantity,
2169 	  wmslpnci.uom_code uom_code,
2170 	  wmslpnci.expiration_date expiration_date,
2171 	  wmslpnci.status_id status_id,
2172 	  wmslpnci.item_description item_description,
2173 	  wmslpnci.vendor_item_num vendor_item_num,
2174 	  wmslpnci.supplier_lot_number supplier_lot_number,
2175 	  wmslpnci.origination_date origination_date,
2176 	  wmslpnci.date_code date_code,
2177 	  wmslpnci.grade_code grade_code,
2178 	  wmslpnci.change_date change_date,
2179 	  wmslpnci.maturity_date maturity_date,
2180 	  wmslpnci.retest_date retest_date,
2181 	  wmslpnci.age age,
2182 	  wmslpnci.item_size item_size,
2183 	  wmslpnci.color color,
2184 	  wmslpnci.volume volume,
2185 	  wmslpnci.place_of_origin place_of_origin,
2186 	  wmslpnci.best_by_date best_by_date,
2187 	  wmslpnci.length length,
2188 	  wmslpnci.length_uom_code length_uom_code,
2189 	  wmslpnci.recycled_content recycled_content,
2190 	  wmslpnci.thickness thickness,
2191 	  wmslpnci.thickness thickness_uom_code,
2192 	  wmslpnci.width width,
2193 	  wmslpnci.width_uom_code width_uom_code,
2194 	  wmslpnci.curl_wrinkle_fold curl_wrinkle_fold,
2195 	  wmslpnci.c_attribute1 c_attribute1,
2196 	  wmslpnci.c_attribute2 c_attribute2,
2197 	  wmslpnci.c_attribute3 c_attribute3,
2198 	  wmslpnci.c_attribute4 c_attribute4,
2199 	  wmslpnci.c_attribute5 c_attribute5,
2200 	  wmslpnci.c_attribute6 c_attribute6,
2201 	  wmslpnci.c_attribute7 c_attribute7,
2202 	  wmslpnci.c_attribute8 c_attribute8,
2203 	  wmslpnci.c_attribute9 c_attribute9,
2204 	  wmslpnci.c_attribute10 c_attribute10,
2205 	  wmslpnci.c_attribute11 c_attribute11,
2206 	  wmslpnci.c_attribute12 c_attribute12,
2207 	  wmslpnci.c_attribute13 c_attribute13,
2208 	  wmslpnci.c_attribute14 c_attribute14,
2209 	  wmslpnci.c_attribute15 c_attribute15,
2210 	  wmslpnci.c_attribute16 c_attribute16,
2211 	  wmslpnci.c_attribute17 c_attribute17,
2212 	  wmslpnci.c_attribute18 c_attribute18,
2213 	  wmslpnci.c_attribute19 c_attribute19,
2214 	  wmslpnci.c_attribute20 c_attribute20,
2215 	  wmslpnci.d_attribute1 d_attribute1,
2216 	  wmslpnci.d_attribute2 d_attribute2,
2217 	  wmslpnci.d_attribute3 d_attribute3,
2218 	  wmslpnci.d_attribute4 d_attribute4,
2219 	  wmslpnci.d_attribute5 d_attribute5,
2220 	  wmslpnci.d_attribute6 d_attribute6,
2221 	  wmslpnci.d_attribute7 d_attribute7,
2222 	  wmslpnci.d_attribute8 d_attribute8,
2223 	  wmslpnci.d_attribute9 d_attribute9,
2224 	  wmslpnci.d_attribute10 d_attribute10,
2225 	  wmslpnci.n_attribute1 n_attribute1,
2226 	  wmslpnci.n_attribute2 n_attribute2,
2227 	  wmslpnci.n_attribute3 n_attribute3,
2228 	  wmslpnci.n_attribute4 n_attribute4,
2229 	  wmslpnci.n_attribute5 n_attribute5,
2230 	  wmslpnci.n_attribute6 n_attribute6,
2231 	  wmslpnci.n_attribute7 n_attribute7,
2232 	  wmslpnci.n_attribute8 n_attribute8,
2233 	  wmslpnci.n_attribute9 n_attribute9,
2234 	  wmslpnci.n_attribute10 n_attribute10,
2235 	  wmslpnci.attribute_category attribute_category,
2236 	  wmslpnci.attribute1 attribute1,
2237 	  wmslpnci.attribute2 attribute2,
2238 	  wmslpnci.attribute3 attribute3,
2239 	  wmslpnci.attribute4 attribute4,
2240 	  wmslpnci.attribute5 attribute5,
2241 	  wmslpnci.attribute6 attribute6,
2242 	  wmslpnci.attribute7 attribute7,
2243 	  wmslpnci.attribute8 attribute8,
2244 	  wmslpnci.attribute9 attribute9,
2245 	  wmslpnci.attribute10 attribute10,
2246 	  wmslpnci.attribute11 attribute11,
2247 	  wmslpnci.attribute12 attribute12,
2248 	  wmslpnci.attribute13 attribute13,
2249 	  wmslpnci.attribute14 attribute14,
2250 	  wmslpnci.attribute15 attribute15
2251 	  FROM
2252 	  wms_lpn_contents_interface wmslpnci,
2253 	  wms_license_plate_numbers wmslpn
2254 	  WHERE
2255 	  wmslpnci.interface_transaction_id = l_intf_txn_id AND
2256 	  wmslpn.license_plate_number (+)= wmslpnci.license_plate_number;
2257 
2258      CURSOR msni_cur (l_intf_txn_id NUMBER) IS
2259 	SELECT
2260 	  fm_serial_number,
2261 	  to_serial_number
2262 	  FROM
2263 	  mtl_serial_numbers_interface
2264 	  WHERE l_intf_txn_id = transaction_interface_id;
2265 
2266      l_wlpnci_total_qty NUMBER;
2267      l_msni_total_qty NUMBER := 0;
2268      l_serial_qty NUMBER := 0;
2269      l_tmp_ser_txn_id NUMBER := NULL;
2270      l_serial_txn_intf_id NUMBER;
2271      l_txn_intf_id NUMBER;
2272      l_prim_qty NUMBER;
2273      l_exists NUMBER;
2274      l_prim_uom_code VARCHAR2(3);
2275 
2276      l_progress VARCHAR2(15) := '0';
2277      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2278 
2279      l_item_id number;
2280      l_to_organization_id number;
2281 
2282 BEGIN
2283 
2284    SAVEPOINT modify_edi_asn_pub;
2285 
2286    x_return_status := g_ret_sts_success;
2287 
2288    l_progress := 'WMSINB-11771';
2289 
2290    IF (l_debug = 1) THEN
2291       print_debug('MODIFY_EDI_XML_ASN: Entering modify_edi_asn', 1);
2292       print_debug('                 (p_group_id => ' || p_group_id, 1);
2293    END IF;
2294 
2295    -- Look at each RTI that has p_group_id
2296    FOR l_rti_rec IN rti_cur(p_group_id) LOOP
2297 
2298       IF (l_debug = 1) THEN
2299 	 print_debug('MODIFY_EDI_XML_ASN: ORGANIZATION ID:'||l_rti_rec.to_organization_id, 1);
2300 	 print_debug('MODIFY_EDI_XML_ASN: ORGANIZATION CODE:'||l_rti_rec.to_organization_code, 1);
2301 	 print_debug('MODIFY_EDI_XML_ASN: ITEM ID:'||l_rti_rec.item_id, 1);
2302 	 print_debug('MODIFY_EDI_XML_ASN: ITEM NUM:'||l_rti_rec.item_num, 1);
2303       END IF;
2304 
2305       IF (l_rti_rec.to_organization_code IS NULL AND l_rti_rec.to_organization_id IS NULL) THEN
2306 	 BEGIN
2307 	    --performace fix. Bug 3444172. Modified the query below.
2308 	    SELECT DISTINCT pll.ship_to_organization_id
2309 	      INTO l_rti_rec.to_organization_id
2310 	      FROM po_line_locations pll, po_headers ph, po_lines pl,
2311 	      mtl_system_items_kfv msik
2312 	      WHERE ph.segment1 = l_rti_rec.document_num
2313 	      AND ((msik.inventory_item_id = l_rti_rec.item_id)
2314 		   OR (msik.concatenated_segments = l_rti_rec.item_num
2315 		       AND l_rti_rec.item_id IS NULL))
2316 			 AND pl.item_id = msik.inventory_item_id
2317 			 AND pll.po_line_id = pl.po_line_id
2318 			 AND pl.po_header_id = ph.po_header_id
2319 			 AND pll.po_header_id = ph.po_header_id
2320 			 AND ph.type_lookup_code in ('STANDARD','BLANKET','PLANNED')
2321 			 AND ROWNUM = 1;
2322 	 EXCEPTION
2323 	    WHEN OTHERS THEN
2324 	       IF (l_debug = 1) THEN
2325 		  print_debug('MODIFY_EDI_XML_ASN: Failed to get ship_to_org_id',1);
2326 	       END IF;
2327 	       --review later
2328 	       l_progress := 'WMSINB-11812';
2329 	       RAISE fnd_api.g_exc_error;
2330 	 END;
2331       END IF; --IF (l_rti_rec.to_organization_code IS NULL AND l_rti_rec.to_organization_id IS NULL) THEN
2332 
2333       IF (l_debug = 1) THEN
2334 	 print_debug('MODIFY_EDI_XML_ASN: AFTER ORGANIZATION ID:'||l_rti_rec.to_organization_id, 1);
2335 	 print_debug('MODIFY_EDI_XML_ASN: AFTER ORGANIZATION CODE:'||l_rti_rec.to_organization_code, 1);
2336       END IF;
2337 
2338       BEGIN
2339 
2340 	--following is fix of performance issue 8113225 / bug 3631289
2341 
2342 	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_id = l_rti_rec.to_organization_id
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_id = l_rti_rec.to_organization_id
2367                         AND msik.concatenated_segments = l_rti_rec.item_num
2368                     AND mp.organization_id = msik.organization_id;
2369                 END IF; --IF (L_RTI_REC.ITEM_ID IS NOT NULL) THEN
2370 
2371 	 ELSE --IF (L_RTI_REC.TO_ORGANIZATION_ID IS NOT NULL) THEN
2372 
2373 	        IF (L_RTI_REC.ITEM_ID IS NOT NULL) THEN
2374                         SELECT DISTINCT msik.primary_uom_code,
2375                             msik.inventory_item_id,
2376 			  mp.organization_id
2377 			  INTO l_prim_uom_code,
2378 			  l_item_id,
2379 			  l_to_organization_id
2380                         FROM  mtl_system_items_kfv msik,
2381                                 mtl_parameters mp
2382                       WHERE mp.organization_code = l_rti_rec.to_organization_code
2383                       AND msik.inventory_item_id = l_rti_rec.item_id
2384                     AND mp.organization_id = msik.organization_id;
2385 
2386 		ELSE --IF (L_RTI_REC.ITEM_ID IS NOT NULL) THEN
2387                         SELECT DISTINCT msik.primary_uom_code,
2388                             msik.inventory_item_id,
2389 			  mp.organization_id
2390 			  INTO l_prim_uom_code,
2391 			  l_item_id,
2392 			  l_to_organization_id
2393                         FROM  mtl_system_items_kfv msik,
2394                                 mtl_parameters mp
2395                       WHERE mp.organization_code = l_rti_rec.to_organization_code
2396                         AND msik.concatenated_segments = l_rti_rec.item_num
2397                     AND mp.organization_id = msik.organization_id;
2398 
2399 		END IF; --IF (L_RTI_REC.ITEM_ID IS NOT NULL) THEN
2400 
2401 	END IF; --IF (L_RTI_REC.TO_ORGANIZATION_ID IS NOT NULL) THEN
2402 
2403 
2404 		    --performace fix. Bug 3444172
2405 		    --WHERE ((msik.inventory_item_id = l_rti_rec.item_id)
2406 		    --  OR (msik.concatenated_segments = l_rti_rec.item_num
2407 		    --    AND l_rti_rec.item_id IS NULL))
2408 		    --AND ((msik.organization_id = l_rti_rec.to_organization_id)
2409 		    --   OR (mp.organization_code = l_rti_rec.to_organization_code
2410 		    -- AND l_rti_rec.to_organization_id IS NULL))
2411 		    -- AND mp.organization_id = msik.organization_id;
2412 
2413 	  -- Set the ITEM ID and Organization ID here
2414           If l_rti_rec.item_id is null then
2415              l_rti_rec.item_id := l_item_id;
2416           End if;
2417 
2418           If l_rti_rec.to_organization_id is null then
2419              l_rti_rec.to_organization_id := l_to_organization_id;
2420           End if;
2421 
2422       EXCEPTION
2423 	 WHEN OTHERS THEN
2424 	    IF (l_debug = 1) THEN
2425 	       print_debug('MODIFY_EDI_XML_ASN: Error retrieving primary uom', 1);
2426 	    END IF;
2427 	    l_progress := 'WMSINB-11843';
2428 	    RAISE fnd_api.g_exc_error;
2429       END ;
2430 
2431       IF (l_debug = 1) THEN
2432 	 print_debug('MODIFY_EDI_XML_ASN: ORGANIZATION ID:'||l_rti_rec.to_organization_id, 1);
2433 	 print_debug('MODIFY_EDI_XML_ASN: ITEM ID:'||l_rti_rec.item_id, 1);
2434       END IF;
2435 
2436 
2437       l_progress := 'WMSINB-11848';
2438 
2439       IF (l_debug = 1) THEN
2440 	 print_debug('MODIFY_EDI_XML_ASN: Looking at RTI:' ||
2441 		     l_rti_rec.interface_transaction_id, 1);
2442       END IF;
2443 
2444       l_wlpnci_total_qty := 0;
2445 
2446       --WLPNI will have rti.group_id
2447       --Update them to RTI.LPN_GROUP_ID so that it will get
2448       --picked up when the transaction is processed
2449       BEGIN
2450 	 UPDATE wms_lpn_interface
2451 	   SET  source_group_id = l_rti_rec.lpn_group_id
2452 	       ,organization_id = l_rti_rec.to_organization_id
2453 	   WHERE source_group_id = p_group_id
2454 	   AND   EXISTS (SELECT 1  --Only for EDI TXN we are doing this
2455 			           --And EDI TXN will have WLPNCI
2456 			 FROM   wms_lpn_contents_interface
2457 			 WHERE  group_id = p_group_id);
2458       EXCEPTION
2459 	 WHEN OTHERS THEN
2460 	 IF (l_debug = 1) THEN
2461 	    print_debug('MODIFY_EDI_XML_ASN: Error update source_group_id OF WLPNI',1);
2462 	 END IF;
2463       END;
2464 
2465       IF (l_debug = 1) THEN
2466 	 print_debug('MODIFY_EDI_XML_ASN: NUMBER OF WLPNI ROWS :' ||
2467 		     SQL%ROWCOUNT, 1);
2468       END IF;
2469 
2470       -- WLPNCI links to RTI through interface_transaction_id
2471       FOR l_wlpnci_rec IN wlpnci_cur(l_rti_rec.interface_transaction_id) LOOP
2472 
2473 	 l_progress := 'WMSINB-11860';
2474 
2475 	 IF (l_debug = 1) THEN
2476 	    print_debug('MODIFY_EDI_XML_ASN: Looking at WLPNCI:' ||
2477 			l_wlpnci_rec.interface_transaction_id, 1);
2478 	 END IF;
2479 
2480 	 -- Only insert wlpni if lpn_id is NULL
2481 	 IF (l_wlpnci_rec.lpn_id IS NULL) THEN
2482 	    check_lpn_in_wlpni
2483 	      (p_license_plate_number => l_wlpnci_rec.license_plate_number
2484                ,p_lpn_id => l_wlpnci_rec.lpn_id
2485 	       ,p_lpn_group_id => l_rti_rec.lpn_group_id
2486 	       ,x_exists  => l_exists);
2487 
2488 	    IF (l_exists <> 1) THEN
2489 	       -- All wlpnci will have the same lpn_id.  So just insert_wlpni once
2490 
2491 	       IF (l_debug = 1) THEN
2492 		  print_debug('MODIFY_EDI_XML_ASN: Calling insert_wlpni(', 1);
2493 		  print_debug('                 p_organization_id => '||l_wlpnci_rec.organization_id,1);
2494 		  print_debug('                 p_lpn_id          => '||l_wlpnci_rec.lpn_id,1);
2495 		  print_debug('                 p_license_plate_number=> '||l_wlpnci_rec.license_plate_number,1);
2496 		  print_debug('                 p_lpn_group_id    => '||p_group_id,1);
2497 	       END IF;
2498 
2499 	       l_progress := 'WMSINB-11886';
2500 
2501 	       inv_rcv_integration_apis.insert_wlpni
2502 		 (p_api_version           => 1.0
2503 		  ,x_return_status        => x_return_status
2504 		  ,x_msg_count            => x_msg_count
2505 		  ,x_msg_data             => x_msg_data
2506 		  ,p_organization_id      => l_rti_rec.to_organization_id
2507 		  ,p_lpn_id               => l_wlpnci_rec.lpn_id
2508 		  ,p_license_plate_number => l_wlpnci_rec.license_plate_number
2509 		  --,p_lpn_group_id         => p_group_id --??
2510 		  ,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
2511 		  );
2512 	       IF (x_return_status <> g_ret_sts_success) THEN
2513 		  IF (l_debug = 1) THEN
2514 		     print_debug('MODIFY_EDI_XML_ASN: Error in insert_wlpni', 1);
2515 		  END IF;
2516 
2517 		  l_progress := 'WMSINB-11903';
2518 		  RAISE fnd_api.g_exc_error;
2519 	       END IF;
2520 
2521 	       l_progress := 'WMSINB-11907';
2522 
2523 	       IF (l_debug = 1) THEN
2524 		  print_debug('MODIFY_EDI_XML_ASN: WLPNI:' ||
2525 			      l_wlpnci_rec.lpn_id ||' inserted successfully', 1);
2526 	       END IF;
2527 
2528 	    END IF; --IF (l_exists <> 1) THEN
2529 	 END IF; --IF (l_wlpnci_rec.lpn_id IS NULL) THEN
2530 
2531 	 l_progress := 'WMSINB-11917';
2532 
2533 	 BEGIN
2534 	    UPDATE rcv_transactions_interface
2535 	      SET lpn_id = l_wlpnci_rec.lpn_id,
2536 	      license_plate_number = l_wlpnci_rec.license_plate_number
2537 	      WHERE interface_transaction_id = l_rti_rec.interface_transaction_id;
2538 	 EXCEPTION
2539 	    WHEN OTHERS THEN
2540 	       IF (l_debug = 1) THEN
2541 		  print_debug('MODIFY_EDI_XML_ASN: Error updating RTI', 1);
2542 	       END IF;
2543 	       l_progress := 'WMSINB-11929';
2544 	       RAISE fnd_api.g_exc_error;
2545 	 END;
2546 
2547 	 l_progress := 'WMSINB-11933';
2548 
2549 	 IF (l_wlpnci_rec.uom_code <> l_prim_uom_code) THEN
2550 	    l_prim_qty := inv_rcv_cache.convert_qty(p_inventory_item_id => l_rti_rec.item_id
2551 				      ,p_from_qty         => l_wlpnci_rec.quantity
2552 				      ,p_from_uom_code    => l_wlpnci_rec.uom_code
2553 				      ,p_to_uom_code      => l_prim_uom_code);
2554 	  ELSE
2555 	    l_prim_qty := l_wlpnci_rec.quantity;
2556 	 END IF;
2557 
2558 	 l_wlpnci_total_qty := l_wlpnci_total_qty + l_prim_qty;
2559 	 -- l_serial_txn_intf_id will be updated if item is lot controlled
2560 	 -- otherwise, use the same one in wlpnci
2561 	 l_serial_txn_intf_id := l_wlpnci_rec.serial_transaction_intf_id;
2562 
2563 	 IF (l_wlpnci_rec.lot_number IS NOT NULL) THEN
2564 
2565 	    l_progress := 'WMSINB-11957';
2566 
2567 	    IF (l_debug = 1) THEN
2568 	       print_debug('MODIFY_EDI_XML_ASN: Lot number is not null in WLPNCI. inserting MTLI',1);
2569 	    END IF;
2570 
2571 	    inv_rcv_integration_apis.insert_mtli
2572 	      (p_api_version     => 1.0
2573 	       ,x_return_status  => x_return_status
2574 	       ,x_msg_count      => x_msg_count
2575 	       ,x_msg_data       => x_msg_data
2576 	       ,p_transaction_interface_id => l_txn_intf_id
2577 	       ,p_lot_number     => ltrim(rtrim(l_wlpnci_rec.lot_number))
2578 	       ,p_transaction_quantity => l_wlpnci_rec.quantity
2579 	       ,p_primary_quantity     => l_prim_qty
2580 	       ,p_organization_id   =>  l_rti_rec.to_organization_id -- l_wlpnci_rec.organization_id
2581 	       ,p_inventory_item_id =>  l_rti_rec.item_id
2582 	       ,p_expiration_date   =>  l_wlpnci_rec.expiration_date
2583 	       ,p_status_id         =>  l_wlpnci_rec.status_id
2584 	       ,x_serial_transaction_temp_id => l_tmp_ser_txn_id -- update
2585 	       ,p_product_transaction_id => l_rti_rec.interface_transaction_id
2586 	       ,p_product_code      => 'RCV'
2587 	       ,p_description       =>  l_wlpnci_rec.item_description --??
2588 	       ,p_vendor_name       =>  l_wlpnci_rec.vendor_item_num --??
2589 	       ,p_supplier_lot_number => l_wlpnci_rec.supplier_lot_number
2590 	       ,p_origination_date  =>  l_wlpnci_rec.origination_date
2591 	      ,p_date_code          =>  l_wlpnci_rec.date_code
2592 	      ,p_grade_code         =>  l_wlpnci_rec.grade_code
2593 	      ,p_change_date        =>  l_wlpnci_rec.change_date
2594 	      ,p_maturity_date      =>  l_wlpnci_rec.maturity_date
2595 	      ,p_retest_date        =>  l_wlpnci_rec.retest_date
2596 	      ,p_age                =>  l_wlpnci_rec.age
2597 	      ,p_item_size          =>  l_wlpnci_rec.item_size
2598 	      ,p_color              =>  l_wlpnci_rec.color
2599 	      ,p_volume             =>  l_wlpnci_rec.volume
2600 	      ,p_place_of_origin    =>  l_wlpnci_rec.place_of_origin
2601 	      ,p_best_by_date       =>  l_wlpnci_rec.best_by_date
2602 	      ,p_length             =>  l_wlpnci_rec.length
2603 	      ,p_length_uom         =>  l_wlpnci_rec.length_uom_code
2604 	      ,p_recycled_content   =>  l_wlpnci_rec.recycled_content
2605 	      ,p_thickness          =>  l_wlpnci_rec.thickness
2606 	      ,p_thickness_uom      =>  l_wlpnci_rec.thickness_uom_code
2607 	      ,p_width              =>  l_wlpnci_rec.width
2608 	      ,p_width_uom          =>  l_wlpnci_rec.width_uom_code
2609 	      ,p_curl_wrinkle_fold  =>  l_wlpnci_rec.curl_wrinkle_fold
2610 	      ,p_c_attribute1       =>  l_wlpnci_rec.c_attribute1
2611 	      ,p_c_attribute2       =>  l_wlpnci_rec.c_attribute2
2612 	      ,p_c_attribute3       =>  l_wlpnci_rec.c_attribute3
2613 	      ,p_c_attribute4       =>  l_wlpnci_rec.c_attribute4
2614 	      ,p_c_attribute5       =>  l_wlpnci_rec.c_attribute5
2615 	      ,p_c_attribute6       =>  l_wlpnci_rec.c_attribute6
2616 	      ,p_c_attribute7       =>  l_wlpnci_rec.c_attribute7
2617 	      ,p_c_attribute8       =>  l_wlpnci_rec.c_attribute8
2618 	      ,p_c_attribute9       =>  l_wlpnci_rec.c_attribute9
2619 	      ,p_c_attribute10      =>  l_wlpnci_rec.c_attribute10
2620 	      ,p_c_attribute11      =>  l_wlpnci_rec.c_attribute11
2621 	      ,p_c_attribute12      =>  l_wlpnci_rec.c_attribute12
2622 	      ,p_c_attribute13      =>  l_wlpnci_rec.c_attribute13
2623 	      ,p_c_attribute14      =>  l_wlpnci_rec.c_attribute14
2624 	      ,p_c_attribute15      =>  l_wlpnci_rec.c_attribute15
2625 	      ,p_c_attribute16      =>  l_wlpnci_rec.c_attribute16
2626 	      ,p_c_attribute17      =>  l_wlpnci_rec.c_attribute17
2627 	      ,p_c_attribute18      =>  l_wlpnci_rec.c_attribute18
2628 	      ,p_c_attribute19      =>  l_wlpnci_rec.c_attribute19
2629 	      ,p_c_attribute20      =>  l_wlpnci_rec.c_attribute20
2630 	      ,p_d_attribute1       =>  l_wlpnci_rec.d_attribute1
2631 	      ,p_d_attribute2       =>  l_wlpnci_rec.d_attribute2
2632 	      ,p_d_attribute3       =>  l_wlpnci_rec.d_attribute3
2633 	      ,p_d_attribute4       =>  l_wlpnci_rec.d_attribute4
2634 	      ,p_d_attribute5       =>  l_wlpnci_rec.d_attribute5
2635 	      ,p_d_attribute6       =>  l_wlpnci_rec.d_attribute6
2636 	      ,p_d_attribute7       =>  l_wlpnci_rec.d_attribute7
2637 	      ,p_d_attribute8       =>  l_wlpnci_rec.d_attribute8
2638 	      ,p_d_attribute9       =>  l_wlpnci_rec.d_attribute9
2639 	      ,p_d_attribute10      =>  l_wlpnci_rec.d_attribute10
2640 	      ,p_n_attribute1       =>  l_wlpnci_rec.n_attribute1
2641 	      ,p_n_attribute2       =>  l_wlpnci_rec.n_attribute2
2642 	      ,p_n_attribute3       =>  l_wlpnci_rec.n_attribute3
2643 	      ,p_n_attribute4       =>  l_wlpnci_rec.n_attribute4
2644 	      ,p_n_attribute5       =>  l_wlpnci_rec.n_attribute5
2645 	      ,p_n_attribute6       =>  l_wlpnci_rec.n_attribute6
2646 	      ,p_n_attribute7       =>  l_wlpnci_rec.n_attribute7
2647 	      ,p_n_attribute8       =>  l_wlpnci_rec.n_attribute8
2648 	      ,p_n_attribute9       =>  l_wlpnci_rec.n_attribute9
2649 	      ,p_n_attribute10      =>  l_wlpnci_rec.n_attribute10
2650 	      ,p_attribute_category =>  l_wlpnci_rec.attribute_category
2651 	      ,p_attribute1         =>  l_wlpnci_rec.attribute1
2652 	      ,p_attribute2         =>  l_wlpnci_rec.attribute2
2653 	      ,p_attribute3         =>  l_wlpnci_rec.attribute3
2654 	      ,p_attribute4         =>  l_wlpnci_rec.attribute4
2655 	      ,p_attribute5         =>  l_wlpnci_rec.attribute5
2656 	      ,p_attribute6         =>  l_wlpnci_rec.attribute6
2657 	      ,p_attribute7         =>  l_wlpnci_rec.attribute7
2658 	      ,p_attribute8         =>  l_wlpnci_rec.attribute8
2659 	      ,p_attribute9         =>  l_wlpnci_rec.attribute9
2660 	      ,p_attribute10        =>  l_wlpnci_rec.attribute10
2661 	      ,p_attribute11        =>  l_wlpnci_rec.attribute11
2662 	      ,p_attribute12        =>  l_wlpnci_rec.attribute12
2663 	      ,p_attribute13        =>  l_wlpnci_rec.attribute13
2664 	      ,p_attribute14        =>  l_wlpnci_rec.attribute14
2665 	      ,p_attribute15        =>  l_wlpnci_rec.attribute15
2666 	      );
2667 
2668 	    IF (x_return_status <> g_ret_sts_success) THEN
2669 	       IF (l_debug = 1) THEN
2670 		  print_debug('MODIFY_EDI_XML_ASN: Error in insert_mtli', 1);
2671 	       END IF;
2672 	       l_progress := 'WMSINB-12064';
2673 	       RAISE fnd_api.g_exc_error;
2674 	    END IF;
2675 	 END IF;
2676 
2677 	 l_progress := 'WMSINB-12069';
2678 
2679 	 IF (l_wlpnci_rec.serial_transaction_intf_id IS NOT NULL) THEN
2680 	    -- for serial controlled only items, do they all have have
2681 	    -- different transaction_intf_id, or can they use the same?
2682 	    l_progress := 'WMSINB-12074';
2683 
2684 	    IF (l_debug = 1) THEN
2685 	       print_debug('MODIFY_EDI_XML_ASN: Looking at MSNIs with ID:' ||
2686 			   l_wlpnci_rec.serial_transaction_intf_id, 1);
2687 	    END IF;
2688 
2689 	    l_msni_total_qty := 0;
2690 
2691 	    FOR l_msni_rec IN msni_cur(l_wlpnci_rec.serial_transaction_intf_id) LOOP
2692 	       l_progress := 'WMSINB-12084';
2693 
2694 	       IF (l_debug = 1) THEN
2695 		  print_debug('MODIFY_EDI_XML_ASN: Looping MSNIs',1);
2696 	       END IF;
2697 
2698 	       l_progress := 'WMSINB-12090';
2699 	       l_serial_qty :=
2700 		 inv_serial_number_pub.get_serial_diff
2701 		 (p_fm_serial => l_msni_rec.fm_serial_number
2702 		  ,p_to_serial=> l_msni_rec.to_serial_number
2703 		  );
2704 	       l_progress := 'WMSINB-12096';
2705 	       l_msni_total_qty := l_msni_total_qty + l_serial_qty;
2706 
2707 	    END LOOP;
2708 
2709 
2710 	    IF (l_debug = 1) THEN
2711 	       print_debug('MODIFY_EDI_XML_ASN: MSNI loop exited',1);
2712 	    END IF;
2713 
2714 	    l_progress := 'WMSINB-12106';
2715 
2716 	    IF (l_msni_total_qty > 0 AND l_msni_total_qty <> l_wlpnci_rec.quantity) THEN
2717 	       -- this message is OK?
2718 	       fnd_message.set_name('INV', 'INV_SERQTY_NOTMATCH');
2719 	       fnd_msg_pub.ADD;
2720 	       IF (l_debug = 1) THEN
2721 		  print_debug('MODIFY_EDI_XML_ASN: MSNIs total quantity does not match WLPNCI quantity',1);
2722 	       END IF;
2723 	       l_progress := 'WMSINB-12115';
2724 	       RAISE fnd_api.g_exc_error;
2725 	    END IF;
2726 
2727 	    l_progress := 'WMSINB-12119';
2728 
2729 	    -- Now update the product code and product_intf_id
2730 	    IF (l_msni_total_qty > 0) THEN
2731 	       BEGIN
2732 		  UPDATE mtl_serial_numbers_interface
2733 		    SET product_code = 'RCV',
2734 		    product_transaction_id=l_rti_rec.interface_transaction_id,
2735 		    transaction_interface_id = l_serial_txn_intf_id
2736 		    --WHERE transaction_interface_id = l_wlpnci_rec.interface_transaction_id;
2737 		    WHERE transaction_interface_id = l_wlpnci_rec.serial_transaction_intf_id;
2738 
2739         --Bug 9226468 To update mtli we need to check based on the serial_transaction_temp_id but not based on product transaction id
2740         --so that it will not fetch the already processed lots.
2741 		  UPDATE mtl_transaction_lots_interface
2742 		    SET serial_transaction_temp_id = l_serial_txn_intf_id
2743 		    WHERE product_code = 'RCV'
2744           AND serial_transaction_temp_id=l_tmp_ser_txn_id;
2745 		    --AND product_transaction_id = l_wlpnci_rec.interface_transaction_id;
2746 
2747 	       EXCEPTION
2748 		  WHEN OTHERS THEN
2749 		     IF (l_debug = 1) THEN
2750 			print_debug('MODIFY_EDI_XML_ASN: Error updating MSNI',1);
2751 		     END IF;
2752 		     l_progress := 'WMSINB-12141';
2753 		     RAISE fnd_api.g_exc_error;
2754 	       END;
2755 	    END IF; --IF (l_msni_total_qty > 0) THEN
2756 	    l_progress := 'WMSINB-12145';
2757 	 END IF;
2758 
2759 	 IF (l_debug = 1) THEN
2760 	    l_progress := 'WMSINB-12149';
2761 	    print_debug('MODIFY_EDI_XML_ASN: WLPNCI loop exited',1);
2762 	 END IF;
2763 
2764       END LOOP;
2765 
2766       IF ((l_wlpnci_total_qty > 0) AND (l_wlpnci_total_qty <> l_rti_rec.primary_quantity)) THEN
2767 	 IF (l_debug = 1) THEN
2768 	    print_debug('MODIFY_EDI_XML_ASN: WLPNCIs total quantity does not match RTI quantity', 1);
2769 	 END IF;
2770 	 -- message to be added
2771 	 fnd_message.set_name('INV', 'INV_WLPNCI_RTI_QTY_NOTMATCH');
2772 	 fnd_msg_pub.ADD;
2773 	 l_progress := 'WMSINB-12162';
2774 	 RAISE fnd_api.g_exc_error;
2775       END IF;
2776 
2777 
2778       IF (l_debug = 1) THEN
2779 	 print_debug('MODIFY_EDI_XML_ASN: Updating RTI row',1);
2780       END IF;
2781 
2782       l_progress := 'WMSINB-12171';
2783    END LOOP;
2784 
2785    l_progress := 'WMSINB-12174';
2786 
2787    IF (l_debug = 1) THEN
2788       print_debug('MODIFY_EDI_XML_ASN: RTI loop exited.  Procedure returns',1);
2789    END IF;
2790 EXCEPTION
2791    WHEN OTHERS THEN
2792       IF (l_debug = 1) THEN
2793 	 print_debug('MODIFY_EDI_XML_ASN: Exception after l_progress = ' ||
2794 		     l_progress,1);
2795       END IF;
2796       x_return_status := g_ret_sts_unexp_error ;
2797       --      fnd_msg_pub.count_and_get
2798       --        (   p_count        => x_msg_count
2799       --	    ,p_data     => x_msg_data
2800       --	    );
2801       IF (rti_cur%isopen) THEN
2802 	 CLOSE rti_cur;
2803       END IF;
2804       IF (wlpnci_cur%isopen) THEN
2805 	 CLOSE wlpnci_cur;
2806       END IF;
2807       IF (msni_cur%isopen) THEN
2808 	 CLOSE msni_cur;
2809       END IF;
2810       ROLLBACK TO modify_edi_asn_pub;
2811 END modify_edi_xml_asn;
2812 
2813 PROCEDURE Explode_lpn(p_request_id       IN         NUMBER,
2814                       p_group_id         IN  NUMBER ) is
2815 
2816 			 l_errorneous_rows NUMBER := 0;
2817 			 l_msg_count number;
2818 			 l_msg_data VARCHAR2(2000);
2819 			 l_return_status VARCHAR2(1);
2820 			 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2821 			 l_progress VARCHAR2(15) := '10';
2822 
2823 			 l_lpn_grp_id NUMBER;
2824 
2825 			 l_dummy NUMBER := NULL;
2826 
2827 BEGIN
2828 
2829    -- Check for Erroneous rows in RTI
2830    --
2831 
2832    l_progress := 'WMSINB-12221';
2833 
2834    IF (l_debug = 1) THEN
2835       print_debug('Explode_LPN : '|| l_progress ,1);
2836       print_debug('Explode_LPN group_id: '|| p_group_id ,1);
2837       print_debug('Explode_LPN request_id: '|| p_request_id ,1);
2838    END IF;
2839 
2840    IF (Nvl(p_group_id,0) = 0 AND Nvl(p_request_id,0) = 0) THEN
2841       --raise error review later
2842       l_progress := 'WMSINB-12231';
2843       RAISE fnd_api.g_exc_error;
2844    END IF;
2845 
2846    l_progress := 'WMSINB-12235';
2847 
2848    /*************************** We do not need to do this check as PO will*
2849    *********************** update the lpn_group_id for all RTIs with LPNs*
2850      for l_error_row in ( select interface_transaction_id,
2851      group_id
2852      from rcv_transactions_interface
2853      where lpn_group_id is null
2854      and (   lpn_id is not null
2855      or license_plate_number is not null
2856      or transfer_lpn_id is not null
2857      or transfer_license_plate_number is not null
2858      )
2859      and processing_status_code in ('RUNNING')
2860      AND (processing_request_id IS NULL
2861      OR processing_request_id = p_request_id)
2862      AND group_id = Decode(p_group_id,0,group_id,NULL,group_id,p_group_id)
2863      ) Loop
2864      -- Call PO's API to mark the Error
2865      IF (l_debug = 1) THEN
2866      print_debug('Explode_LPN failed for interface_transaction_id : '|| l_error_row.interface_transaction_id ,1);
2867      print_debug('Explode_LPN failed for group_id: '|| p_group_id ,1);
2868      print_debug('Explode_LPN request_id failed for request_id : '|| p_request_id ,1);
2869      END IF;
2870      rcv_roi_preprocessor.explode_lpn_failed
2871      (x_interface_txn_id => l_error_row.interface_transaction_id,
2872      x_group_id => l_error_row.group_id,
2873      x_lpn_group_id => NULL);
2874      End Loop;
2875      *************************************************************************************/
2876      -- ** The update part is commented after discussion with po team
2877      -- ** Instead of Finding Errorneous Rows we will update the LPN GROUP_ID HERE *******
2878 
2879      l_progress := 'WMSINB-12268';
2880 
2881    -- See if there are any rtis which require explosion but have null
2882    -- lpn_group_id and update the lpn_group_id for such cases
2883 
2884    FOR l_lpn_grp_null IN (SELECT interface_transaction_id
2885 			  FROM rcv_transactions_interface
2886 			  WHERE Nvl(item_id, -1) = -1
2887 			  AND item_num IS NULL
2888 			  AND item_description IS NULL
2889 			  AND lpn_group_id IS NULL
2890 			  AND (lpn_id IS NOT NULL
2891 			       OR license_plate_number IS NOT NULL)
2892 			  AND transaction_type <> 'SHIP'
2893 			  AND processing_status_code in ('RUNNING')
2894 			  AND (processing_request_id IS NULL
2895 			       OR processing_request_id = p_request_id)
2896 			  AND group_id = Decode(p_group_id,0,group_id,NULL,group_id,p_group_id))
2897 			    LOOP
2898 			       IF (l_debug = 1) THEN
2899 				  print_debug('EXPLODE_LPN - Case for explosion without LPN_GROUP_ID. Updating for RTI: '||l_lpn_grp_null.interface_transaction_id,1);
2900 			       END IF;
2901 
2902 			       SELECT RCV_INTERFACE_GROUPS_S.NEXTVAL
2903 				 INTO l_lpn_grp_id
2904 				 FROM DUAL;
2905 
2906 			       UPDATE rcv_transactions_interface
2907 				 SET lpn_group_id = l_lpn_grp_id
2908 				 WHERE interface_transaction_id = l_lpn_grp_null.interface_transaction_id;
2909 
2910 			    END LOOP;
2911 
2912 			    -- Following will be removed after po gives us the patch for corrections/returns.
2913 			    /************************************************************************/
2914 			    --UPDATE rcv_transactions_interface SET lpn_group_id = group_id
2915 			    --WHERE lpn_group_id IS NULL
2916 			    --AND (lpn_id IS NOT NULL
2917 			    --   OR license_plate_number IS NOT NULL
2918 			    -- OR transfer_lpn_id IS NOT NULL
2919 			    -- OR transfer_license_plate_number IS NOT NULL
2920 			    -- )
2921 			    -- AND processing_status_code = 'RUNNING'
2922 			    -- AND (processing_request_id IS NULL
2923 			    --    OR processing_request_id = p_request_id)
2924 			    -- AND group_id = Decode(p_group_id,0,group_id,NULL,group_id,p_group_id);
2925 			    /***********************************************************************/
2926 				       l_progress := 'WMSINB-12314';
2927 
2928 				       FOR l_rti_rec IN ( SELECT DISTINCT lpn_group_id, group_id
2929 							  FROM rcv_transactions_interface rti
2930 							  WHERE lpn_group_id IS NOT NULL
2931 							  AND Nvl(item_id, -1) = -1
2932 							  AND item_num IS NULL
2933 							  AND item_description IS NULL
2934 							  AND transaction_type <> 'SHIP'
2935 							  AND processing_status_code in ('RUNNING')
2936 							  AND (processing_request_id IS NULL
2937 							       OR processing_request_id = p_request_id)
2938 							  AND group_id = Decode(p_group_id,0,group_id,NULL,group_id,p_group_id)) LOOP
2939 							     IF (l_debug = 1) THEN
2940 								print_debug('Explode_LPN_contents called for LPN_GROUP = '||l_rti_rec.lpn_group_id  ,1);
2941 							     END IF;
2942 							     Explode_lpn_contents(l_rti_rec.lpn_group_id,l_return_status,l_msg_count, l_msg_data);
2943 							     IF (l_return_status <> g_ret_sts_success) then
2944 								IF (l_debug = 1) THEN
2945 								   print_debug('Explode_LPN_contents FAILURE for LPN_GROUP = '||l_rti_rec.lpn_group_id  ,1);
2946 								END IF;
2947 								-- Call PO's API to mark the Error
2948 								rcv_roi_preprocessor.explode_lpn_failed(x_interface_txn_id => l_dummy,
2949 													x_group_id => l_rti_rec.group_id,
2950 													x_lpn_group_id => l_rti_rec.lpn_group_id);
2951 							     END IF;
2952 							  END LOOP;
2953 
2954 							  --See if there are any rows for ASN SHIP txn
2955 							  --which need updation of lpn_group_id
2956                                                           --Instead of shipment use interface_transaction_id as the shipment_num in rti may be null
2957 							  --FOR l_asn_lpn_grp_null IN (SELECT DISTINCT shipment_num
2958 
2959 							  FOR l_asn_lpn_grp_null IN (SELECT DISTINCT header_interface_id,
2960                                                                                                      shipment_num
2961 										     FROM rcv_transactions_interface rti
2962 										     WHERE rti.lpn_group_id IS NULL
2963 										     AND ( ( (rti.lpn_id IS NOT NULL
2964 											    OR rti.license_plate_number IS NOT NULL)
2965                                                                                            ) or
2966                                                                                            (exists ( select 'x' from wms_lpn_contents_interface wlc
2967                                                                                                     where wlc.interface_transaction_id =
2968                                                                                                         rti.interface_transaction_id
2969                                                                                                    )
2970                                                                                            )
2971                                                                                          )
2972 										     AND rti.processing_status_code = 'RUNNING'
2973 										     AND (rti.processing_request_id IS NULL
2974 											  OR rti.processing_request_id = p_request_id)
2975 										     AND rti.transaction_type = 'SHIP'
2976 										     AND rti.source_document_code = 'PO'
2977 										     AND (rti.item_id IS NOT NULL
2978 											  OR rti.item_num IS NOT NULL)
2979 										     AND rti.group_id = Decode(p_group_id,0,rti.group_id,NULL,rti.group_id,p_group_id))
2980 											    LOOP
2981 											       IF (l_debug = 1) THEN
2982 												  print_debug('EXPLODE_LPN - SHIP  Updating lpn_group for SHIPMENT: '||l_asn_lpn_grp_null.shipment_num,1);
2983 											       END IF;
2984 
2985 											       SELECT RCV_INTERFACE_GROUPS_S.NEXTVAL
2986 												 INTO l_lpn_grp_id
2987 												 FROM DUAL;
2988 
2989 											       UPDATE rcv_transactions_interface
2990 												 SET lpn_group_id = l_lpn_grp_id
2991                                                                                                  -- don't use shipment_num see update above ****
2992 												 -- WHERE shipment_num = l_asn_lpn_grp_null.shipment_num
2993 												 WHERE header_interface_id = l_asn_lpn_grp_null.header_interface_id
2994                                                                                                  AND lpn_group_id is null
2995 												 AND processing_status_code = 'RUNNING'
2996 												 AND (processing_request_id IS NULL
2997 												      OR processing_request_id = p_request_id)
2998 												   AND transaction_type = 'SHIP'
2999 												   AND source_document_code = 'PO'
3000 												   AND group_id = Decode(p_group_id,0,group_id,NULL,group_id,p_group_id);
3001 											    END LOOP;
3002 
3003 											    -- This PART Below is for ASN creation only
3004 											    FOR l_asn_rec IN ( SELECT DISTINCT group_id,processing_mode_code
3005 													       FROM rcv_transactions_interface rti
3006 													       WHERE processing_status_code = 'RUNNING'
3007 													       AND (processing_request_id IS NULL
3008 														    OR processing_request_id = p_request_id)
3009 													       AND transaction_type = 'SHIP'
3010 													       AND source_document_code = 'PO'
3011 													       AND lpn_group_id IS NOT NULL
3012 													       AND (item_id IS NOT NULL OR
3013 														    item_num IS NOT NULL)
3014 													       AND group_id = Decode(p_group_id,0,group_id,NULL,group_id,p_group_id)) LOOP
3015 														  IF (l_debug = 1) THEN
3016 														     print_debug('Modify_edi_xml_asn called for GROUP = '||l_asn_rec.group_id  ,1);
3017 														  END IF;
3018 														  modify_edi_xml_asn(l_asn_rec.group_id,l_return_status,l_msg_count, l_msg_data);
3019 														  IF (l_return_status <> g_ret_sts_success) then
3020 														     IF (l_debug = 1) THEN
3021 															print_debug('modify_edi_xml_asn FAILURE for GROUP = '||l_asn_rec.group_id  ,1);
3022 														     END IF;
3023 														     -- Call POs API to mark the Error
3024 														     IF (l_asn_rec.processing_mode_code='ONLINE') THEN
3025 															rcv_roi_preprocessor.explode_lpn_failed
3026 															  (x_interface_txn_id => l_dummy,
3027 															   x_group_id => l_asn_rec.group_id,
3028 															   x_lpn_group_id => NULL);
3029 														      ELSE
3030 															FOR l_err_row IN (SELECT interface_transaction_id
3031 																	  FROM rcv_transactions_interface
3032 																	  WHERE group_id = l_asn_rec.group_id) LOOP
3033 																	     -- Call PO's API to mark the Error
3034 																	     rcv_roi_preprocessor.explode_lpn_failed
3035 																	       (x_interface_txn_id => l_err_row.interface_transaction_id,
3036 																		x_group_id => l_asn_rec.group_id,
3037 																		x_lpn_group_id => NULL);
3038 																	  END LOOP;
3039 														     END IF; --IF (l_asn_rec.processing_mode_code='ONLINE') THEN
3040 														  END IF; --IF (l_return_status <> g_ret_sts_success) then
3041 													       END LOOP;
3042 
3043 													       -- Delete the Original row for Explosion
3044                                                                                                                -- Bug 3618348. The code below is changed from performance reasons
3045                                                                                                                /*
3046 													       DELETE FROM rcv_transactions_interface
3047 														 WHERE Nvl(item_id, -1)  = -1
3048 														 AND item_description IS NULL
3049 														   AND Nvl(quantity,0) = 0
3050 														   AND lpn_group_id IS NOT NULL
3051 														     AND processing_status_code = 'RUNNING'
3052 														     AND (processing_request_id IS NULL
3053 															  OR processing_request_id = p_request_id)
3054 														       AND group_id = Decode(p_group_id,0,group_id,NULL,group_id,p_group_id);
3055                                                                                                                */
3056 if nvl(p_group_id,0) = 0 then
3057    DELETE FROM rcv_transactions_interface
3058      WHERE Nvl(item_id, -1)  = -1
3059        AND item_description IS NULL
3060        AND Nvl(quantity,0) = 0
3061        AND lpn_group_id IS NOT NULL
3062        AND processing_status_code = 'RUNNING'
3063        -- Bug 3714354
3064        and ( lpn_id is not null or license_plate_number is not null )
3065        AND (processing_request_id IS NULL
3066              OR processing_request_id = p_request_id) ;
3067 Else
3068    DELETE FROM rcv_transactions_interface
3069      WHERE Nvl(item_id, -1)  = -1
3070        AND item_description IS NULL
3071        AND Nvl(quantity,0) = 0
3072        AND lpn_group_id IS NOT NULL
3073        AND processing_status_code = 'RUNNING'
3074        -- Bug 3714354
3075        and ( lpn_id is not null or license_plate_number is not null )
3076        AND (processing_request_id IS NULL
3077              OR processing_request_id = p_request_id)
3078        AND group_id = p_group_id;
3079 End if;
3080 
3081 END Explode_lpn;
3082 
3083 FUNCTION get_inspection_status(p_transaction_type IN VARCHAR2
3084 			       , p_routing_header_id IN NUMBER DEFAULT NULL
3085 			       , p_parent_transaction_type IN VARCHAR2 DEFAULT NULL
3086 			       , p_parent_parent_txn_type IN VARCHAR2 DEFAULT NULL
3087 			       , p_quantity IN NUMBER DEFAULT NULL) return NUMBER
3088   IS
3089      l_inspect_status NUMBER;
3090 	 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3091 BEGIN
3092    l_inspect_status := NULL;
3093 
3094    IF (p_transaction_type = 'RECEIVE' AND
3095        p_routing_header_id = 2) THEN
3096       l_inspect_status := 1;
3097     ELSIF (p_transaction_type = 'ACCEPT') THEN
3098       l_inspect_status := 2;
3099     ELSIF (p_transaction_type = 'REJECT') THEN
3100       l_inspect_status := 3;
3101     ELSIF (p_transaction_type = 'TRANSFER') THEN
3102       l_inspect_status := -9999;
3103    END IF;
3104 
3105    --bug 12864098
3106    IF (l_debug = 1) THEN
3107      print_debug('get_inspection_status  : p_parent_transaction_type: '|| p_parent_transaction_type,1);
3108      print_debug('get_inspection_status  : p_transaction_type: '|| p_transaction_type,1);
3109      print_debug('get_inspection_status  : p_quantity: '|| p_quantity,1);
3110    END IF;
3111    IF (p_transaction_type = 'CORRECT') THEN
3112      IF (p_parent_transaction_type = 'ACCEPT') THEN
3113       l_inspect_status := 1;
3114      ELSIF (p_parent_transaction_type = 'REJECT') THEN
3115       l_inspect_status := 1;
3116      ELSIF (p_parent_transaction_type = 'RECEIVE' AND p_quantity>0) THEN
3117       l_inspect_status := 1;
3118     --14811374
3119      ELSIF (p_parent_transaction_type = 'TRANSFER' ) THEN
3120       l_inspect_status := -9999;
3121     --14811374 The Inspection status was stamped as NULL after performing Correction on TRANSFER Record
3122      END IF;
3123    END IF;
3124    --bug 12864098
3125 
3126    RETURN l_inspect_status;
3127 
3128 END get_inspection_status;
3129 
3130 Function get_serial_status(p_transaction_type IN VARCHAR2
3131          , p_auto_transact_code IN VARCHAR2 DEFAULT NULL
3132          , p_parent_transaction_type IN VARCHAR2 DEFAULT NULL
3133          , p_parent_parent_txn_type IN VARCHAR2 DEFAULT NULL
3134          , p_quantity IN NUMBER DEFAULT NULL
3135          ) return NUMBER
3136   is
3137 
3138      -- 1 defined But not used
3139      -- 3 Resides in Stores
3140      -- 4 Issued out of Stores
3141      -- 5 Resides in Intransit
3142 
3143      l_serial_status_new constant NUMBER := 1;
3144      l_serial_status_rcv constant NUMBER := 7;
3145      l_serial_status_inv constant NUMBER := 3;
3146      l_serial_status_intransit constant NUMBER := 5;
3147      l_serial_status_issued constant NUMBER := 4;
3148 
3149 Begin
3150    if p_transaction_type is null then
3151       return l_serial_status_new;
3152     elsif p_transaction_type = 'ACCEPT' then
3153       return l_serial_status_rcv;
3154     elsif p_transaction_type = 'REJECT' then
3155       return l_serial_status_rcv;
3156     elsif p_transaction_type = 'RECEIVE' THEN
3157       --Bug 7129718, we will always change the org of serial
3158       --   to receiving org and status to 'In Receiving' after receipt transaction.
3159       --   If its direct routing, then in the same session INV TM
3160       --   updates serial status to 'Resides in Stores'.
3161       --   Now, the LPN and the Serials will be in sync with each other.
3162       return l_serial_status_rcv;
3163 
3164       --IF (Nvl(p_auto_transact_code,'@@@@') <> 'DELIVER') THEN
3165       --   return l_serial_status_rcv;
3166       --ELSE
3167       --   -- Returns the status as -9999 otherwise fails for
3168       --   -- Direct routing cases in INV Txn Manager.
3169       --   -- and in update_serial_status when the values is -9999 don't
3170       --   -- update the status
3171       --   -- RETURN l_serial_status_inv;
3172       --   -- Bug 3184500
3173       --   return -9999;
3174       --END IF;
3175 
3176     elsif p_transaction_type = 'TRANSFER' then
3177       return l_serial_status_rcv;
3178     elsif p_transaction_type = 'DELIVER' then
3179       return l_serial_status_inv;
3180     elsif p_transaction_type = 'SHIP' then
3181       --Bug 4337726. A ship transaction with auto transact code as receive
3182       --should be treated like a receipt transaction
3183       IF (Nvl(p_auto_transact_code, 'SHIP') = 'RECEIVE') THEN
3184          RETURN l_serial_status_rcv;
3185        ELSE
3186          return l_serial_status_intransit;
3187       END IF;
3188     ELSIF p_transaction_type = 'RETURN TO RECEIVING' THEN
3189       RETURN l_serial_status_rcv;
3190     ELSIF p_transaction_type IN ('RETURN TO VENDOR', 'RETURN TO CUSTOMER') THEN
3191       RETURN l_serial_status_issued;
3192     ELSIF p_transaction_type = 'CORRECT' THEN
3193       IF (Nvl(p_parent_transaction_type,'@@@') IN ('ACCEPT','REJECT','TRANSFER')) THEN
3194 	 RETURN l_serial_status_rcv;
3195        ELSIF (Nvl(p_parent_transaction_type,'@@@') = 'DELIVER') THEN
3196 	 IF (Nvl(p_quantity, 0) < 0) THEN
3197 	    RETURN l_serial_status_rcv;
3198 	  ELSIF (Nvl(p_quantity, 0) > 0) THEN
3199 	    RETURN l_serial_status_inv;
3200 	  ELSE
3201 	    RETURN l_serial_status_new;
3202 	 END IF;
3203        ELSIF (Nvl(p_parent_transaction_type,'@@@') = 'RECEIVE') THEN
3204 	 IF (Nvl(p_quantity, 0) > 0) THEN
3205 	    RETURN l_serial_status_rcv;
3206 	  ELSE
3207 	    RETURN l_serial_status_new;
3208 	 END IF;
3209        ELSIF (Nvl(p_parent_transaction_type,'@@@') = 'RETURN TO RECEIVING') THEN
3210 	 IF (Nvl(p_quantity, 0) < 0) THEN
3211 	    RETURN l_serial_status_inv;
3212 	  ELSIF (Nvl(p_quantity, 0) > 0) THEN
3213 	    RETURN l_serial_status_rcv;
3214 	  ELSE
3215 	    RETURN l_serial_status_new;
3216 	 END IF;
3217        ELSIF (Nvl(p_parent_transaction_type,'@@@') IN ('RETURN TO VENDOR','RETURN TO CUSTOMER')) THEN
3218 	 IF(Nvl(p_quantity, 0) < 0) THEN
3219 	    IF (Nvl(p_parent_parent_txn_type,'@@@@') = 'DELIVER') THEN
3220 	       RETURN l_serial_status_inv;
3221 	     ELSIF p_parent_parent_txn_type IS NOT NULL THEN
3222 	       RETURN l_serial_status_rcv;
3223 	     ELSE
3224 	       RETURN l_serial_status_new;
3225 	    END IF;
3226 	  ELSIF (Nvl(p_quantity, 0) > 0) THEN
3227 	    RETURN l_serial_status_issued;
3228 	  ELSE
3229 	    RETURN l_serial_status_new;
3230          END IF;
3231        ELSE
3232 	 RETURN l_serial_status_new;
3233       END IF;
3234     else
3235       return l_serial_status_new;
3236    end if;
3237 Exception
3238    when others then
3239       return l_serial_status_new;
3240 End get_serial_status;
3241 
3242 -- Description
3243 -- THIS procedure updates the serial Status
3244 --
3245 PROCEDURE update_serial_status (  p_product_txn_id           IN NUMBER
3246 				  ,p_item_id                  IN NUMBER
3247 				  ,p_organization_id          IN NUMBER
3248 				  ,p_serial_status            IN NUMBER
3249 				  ,p_inspection_status        IN NUMBER
3250 				  ,p_sub                      IN VARCHAR2 default null
3251 				  ,p_locator_id               IN NUMBER default null
3252 				  ,x_return_status            OUT NOCOPY VARCHAR2
3253 				  ,x_msg_count                OUT NOCOPY NUMBER
3254 				  ,x_msg_data                 OUT NOCOPY VARCHAR2 ) IS
3255 
3256 				     l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3257 				     l_progress VARCHAR2(15) := '10';
3258 			             l_count NUMBER; --bug 5008139
3259 				     l_comms_nl_trackable_flag mtl_system_items.comms_nl_trackable_flag%type;--Bug6374074
3260 				     l_destination_type        rcv_transactions_interface.destination_type_code%type;--Bug6374074
3261 				     l_clear_line_mark_id      number;--Bug6374074( if l_clear_line_mark_id = 1 then clear the line_mark_id field
3262 				                                      --            else preserve the line_mark_id field
3263 
3264 
3265 Begin
3266 
3267    x_return_status  := g_ret_sts_success;
3268    l_progress := 'WMSINB-12562';
3269 
3270    --BUG 5008139 -- Getting the count of serial records in MSNT
3271    select count(*)
3272    into   l_count
3273    from   mtl_serial_numbers_temp
3274    where  product_code = 'RCV'
3275    and    product_transaction_id = p_product_txn_id;
3276 
3277    IF (l_debug = 1) THEN
3278       print_debug('update_serial_status : l_count = '||l_count, 1);
3279    END IF;
3280 
3281    --Bug 7129718, we will always change the org of serial
3282    --   to receiving org after receipt transaction.
3283    --   If its direct routing, then in the same session INV TM
3284    --   updates serial status to 'Resides in Stores'.
3285    --   Now, the LPN and the Serials will be in sync with each other.
3286 
3287    --Bug: 5524134
3288    -- For direct deliver case we need not update the columns, if the serial
3289    -- status is -9999. This would ensure that the serial number uniqueness
3290    -- checks from inventory side goes through fine. These columns would be
3291    -- updated by the INV TM after serial uniqueness check.
3292    --
3293 
3294    --Bug#6374074:
3295    -- While receiving eIB tracked, 'Serial' or 'Lot and Serial' controlled items
3296    -- with Expense destination, hook maintained between Instal base and
3297    -- Receiving lost and because of this 'Instal base' is not able to view
3298    -- the Serial numbers in their forms.
3299    -- If the item is instalbased item and the transaction is for 'EXPENSE'
3300    -- destination, then dont clear the line_mark_id else we can clear the
3301    -- line_mark_id. Modified the update statments based on the above said condition.
3302 
3303    --Bug 5008139, running below update only if there are serial records in MSNT
3304 
3305    IF (l_count > 0) THEN
3306       --Bug 6374074, Checking whether the item is instal based tracked
3307       SELECT Nvl(comms_nl_trackable_flag,'N')
3308         INTO l_comms_nl_trackable_flag
3309         FROM mtl_system_items
3310        WHERE inventory_item_id = p_item_id
3311          AND organization_id= p_organization_id;
3312 
3313        IF l_comms_nl_trackable_flag = 'Y' THEN
3314          --Check whether this transaction is for EXPENSE destination
3315          --Then we have to preserve the line_mark_id and lot_line_mark_id
3316          SELECT nvl(destination_type_code,'dummy')
3317            INTO l_destination_type
3318            FROM rcv_transactions_interface
3319           WHERE interface_transaction_id = p_product_txn_id;
3320 
3321           IF l_destination_type = 'EXPENSE' THEN
3322              --Don't clear the line_mark_id and lot_line_mark_id
3323               l_clear_line_mark_id := 0;
3324           ELSE
3325               --Clear the line_mark_id and lot_line_mark_id
3326               l_clear_line_mark_id := 1;
3327           END IF;
3328        ELSE--IF l_comms_nl_trackable_flag = 'Y' THEN
3329           l_clear_line_mark_id := 1;
3330        END IF;--IF l_comms_nl_trackable_flag = 'Y' THEN
3331 
3332        -- Bug 7129718, Replacing all the branching by a single update.
3333        --    serial status of -9999 won't come into picture now as even during direct routing,
3334        --    we set serial status to 'In Receiving'. INV TM will change the status to
3335        --    'Resides in Stores' in the same session.
3336 
3337        -- Bug 7427382 Updating columns owning org and planning org also.
3338 
3339        update mtl_serial_numbers msn
3340           set msn.current_status = p_serial_status
3341             , inspection_status = p_inspection_status
3342             , group_mark_id = NULL
3343             , line_mark_id = decode(l_clear_line_mark_id, 1, NULL, line_mark_id)
3344             , lot_line_mark_id = decode(l_clear_line_mark_id, 1, NULL, lot_line_mark_id)
3345             , current_organization_id = p_organization_id
3346             , owning_organization_id = decode(owning_tp_type, 2, p_organization_id, owning_organization_id)
3347             , planning_organization_id = decode(planning_tp_type, 2, p_organization_id, planning_organization_id)
3348             , current_subinventory_code = p_sub
3349             , current_locator_id = p_locator_id
3350         where
3351            -- msn.inventory_item_id       = p_item_id
3352            -- and msn.current_organization_id = p_organization_id -- this part is not needed as this was causing INTSHIP RECEIVE to fail
3353            -- BUG 5611567
3354               msn.ROWID in (
3355                    select msn1.ROWID
3356                      from mtl_serial_numbers msn1
3357                         , mtl_serial_numbers_temp msnt
3358                     where msn1.inventory_item_id = p_item_id
3359                       and msnt.product_code = 'RCV'
3360                       and msnt.product_transaction_id = p_product_txn_id
3361                       and msn1.serial_number between msnt.fm_serial_number and msnt.to_serial_number
3362                       AND Length(msn1.serial_number) = Length(msnt.fm_serial_number)
3363                       AND length(msnt.fm_serial_number)=Length(nvl(msnt.to_serial_number,msnt.fm_serial_number))  --BUG 3818544
3364                            );
3365 
3366 
3367 --      --BEGIN Bug: 5524134
3368 --      IF p_serial_status = -9999 THEN
3369 --         IF l_clear_line_mark_id = 1  THEN --{
3370 --            update mtl_serial_numbers msn
3371 --            set
3372 --             group_mark_id = NULL,
3373 --             line_mark_id = NULL,
3374 --             lot_line_mark_id = NULL
3375 --            where msn.inventory_item_id       = p_item_id
3376 --            -- and msn.current_organization_id = p_organization_id -- this part is not needed as this was causing INTSHIP RECEIVE to fail
3377 --            and exists ( select 1
3378 --                     from mtl_serial_numbers_temp msnt
3379 --                     where msnt.product_code = 'RCV'
3380 --                     and msnt.product_transaction_id = p_product_txn_id
3381 --                     and msn.serial_number between msnt.fm_serial_number and msnt.to_serial_number
3382 --                     AND Length(msn.serial_number) = Length(msnt.fm_serial_number)
3383 --                     AND length(msnt.fm_serial_number)=Length(Nvl(msnt.to_serial_number,msnt.fm_serial_number))  --BUG 3818544
3384 --                     )
3385 --            ;
3386 --         ELSE --l_clear_line_mark_id = 1 }{
3387 --            update mtl_serial_numbers msn
3388 --            set
3389 --             group_mark_id = NULL
3390 --            where msn.inventory_item_id       = p_item_id
3391 --            -- and msn.current_organization_id = p_organization_id -- this part is not needed as this was causing INTSHIP RECEIVE to fail
3392 --            and exists ( select 1
3393 --                     from mtl_serial_numbers_temp msnt
3394 --                     where msnt.product_code = 'RCV'
3395 --                     and msnt.product_transaction_id = p_product_txn_id
3396 --                     and msn.serial_number between msnt.fm_serial_number and msnt.to_serial_number
3397 --                     AND Length(msn.serial_number) = Length(msnt.fm_serial_number)
3398 --                     AND length(msnt.fm_serial_number)=Length(Nvl(msnt.to_serial_number,msnt.fm_serial_number))  --BUG 3818544
3399 --                     )
3400 --            ;
3401 --         END IF;--l_clear_line_mark_id = 1 }
3402 --      ELSE
3403 --      --END Bug: 5524134
3404 --         IF l_clear_line_mark_id = 1  THEN --{
3405 --            update mtl_serial_numbers msn
3406 --              set msn.current_status = p_serial_status
3407 --              , inspection_status = p_inspection_status
3408 --              , group_mark_id = NULL
3409 --              , line_mark_id = NULL
3410 --              , lot_line_mark_id = NULL
3411 --              , current_organization_id = p_organization_id
3412 --              , current_subinventory_code = p_sub
3413 --              , current_locator_id = p_locator_id
3414 --                where
3415 --              -- msn.inventory_item_id       = p_item_id
3416 --              -- and msn.current_organization_id = p_organization_id -- this part is not needed as this was causing INTSHIP RECEIVE to fail
3417 --                      -- BUG 5611567
3418 --                      msn.ROWID in ( select msn1.ROWID
3419 --                           from mtl_serial_numbers msn1 ,
3420 --                           mtl_serial_numbers_temp msnt
3421 --                           where msn1.inventory_item_id = p_item_id
3422 --                           and msnt.product_code = 'RCV'
3423 --                           and msnt.product_transaction_id = p_product_txn_id
3424 --                           and msn1.serial_number between msnt.fm_serial_number and msnt.to_serial_number
3425 --                           AND Length(msn1.serial_number) = Length(msnt.fm_serial_number)
3426 --                           AND length(msnt.fm_serial_number)=Length(nvl(msnt.to_serial_number,msnt.fm_serial_number))  --BUG 3818544
3427 --                           )
3428 --            ;
3429 --         ELSE--l_clear_line_mark_id = 1 }{
3430 --            update mtl_serial_numbers msn
3431 --              set msn.current_status = p_serial_status
3432 --              , inspection_status = p_inspection_status
3433 --              , group_mark_id = NULL
3434 --              , current_organization_id = p_organization_id
3435 --              , current_subinventory_code = p_sub
3436 --              , current_locator_id = p_locator_id
3437 --                where
3438 --              -- msn.inventory_item_id       = p_item_id
3439 --              -- and msn.current_organization_id = p_organization_id -- this part is not needed as this was causing INTSHIP RECEIVE to fail
3440 --                      -- BUG 5611567
3441 --                      msn.ROWID in ( select msn1.ROWID
3442 --                           from mtl_serial_numbers msn1 ,
3443 --                           mtl_serial_numbers_temp msnt
3444 --                           where msn1.inventory_item_id = p_item_id
3445 --                           and msnt.product_code = 'RCV'
3446 --                           and msnt.product_transaction_id = p_product_txn_id
3447 --                           and msn1.serial_number between msnt.fm_serial_number and msnt.to_serial_number
3448 --                           AND Length(msn1.serial_number) = Length(msnt.fm_serial_number)
3449 --                           AND length(msnt.fm_serial_number)=Length(nvl(msnt.to_serial_number,msnt.fm_serial_number))  --BUG 3818544
3450 --                           )
3451 --            ;
3452 --         END IF;--l_clear_line_mark_id = 1 }
3453 --      --End of bug 6374074
3454 --    END IF; --BUG 5524134
3455     END IF; --BUG 5008139
3456    l_progress := 'WMSINB-12577';
3457 Exception
3458    when others then
3459       x_return_status  := g_ret_sts_unexp_error;
3460       IF (l_debug = 1) THEN
3461          print_debug('update_serial_status  : - other exception:'|| l_progress || ' ' ||
3462                      TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
3463       END IF;
3464       IF SQLCODE IS NOT NULL THEN
3465          inv_mobile_helper_functions.sql_error('inv_rcv_integration_pvt.update_serial_status',l_progress, SQLCODE);
3466       END IF;
3467       --  Get message count and data
3468       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
3469 
3470 End update_serial_status;
3471 
3472 
3473 -- Description
3474 -- THIS procedure updates the context/ org/ sub/ locator of LPN
3475 --
3476 PROCEDURE update_lpn_location_context ( p_organization_id          IN NUMBER
3477 					,p_sub                      IN VARCHAR2
3478 					,p_locator                  IN NUMBER
3479 					,p_lpn_context              IN NUMBER
3480 					,p_lpn_id                   IN NUMBER
3481 					,x_return_status            OUT NOCOPY VARCHAR2
3482 					,x_msg_count                OUT NOCOPY NUMBER
3483 					,x_msg_data                 OUT NOCOPY VARCHAR2
3484 					,p_source_name              IN VARCHAR2 DEFAULT NULL
3485 					,p_source_header_id         IN NUMBER DEFAULT NULL
3486 					,p_source_type_id           IN NUMBER DEFAULT NULL) IS
3487 
3488 					   l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3489 					   l_progress VARCHAR2(15) := '10';
3490 					   l_lpn_rec WMS_LICENSE_PLATE_NUMBERS%rowtype;
3491 
3492 BEGIN
3493 
3494    -- Initialize API return status to success
3495    x_return_status  := g_ret_sts_success;
3496 
3497    l_progress := 'WMSINB-12617';
3498 
3499    l_lpn_rec.lpn_id := p_lpn_id;
3500 
3501    if p_lpn_context is not null then
3502       l_lpn_rec.lpn_context := p_lpn_context;
3503    End if;
3504 
3505    l_lpn_rec.SUBINVENTORY_CODE := NVL(p_sub, FND_API.G_MISS_CHAR); -- Modified for bug 16248920
3506    l_lpn_rec.LOCATOR_ID := NVL(p_locator, FND_API.G_MISS_NUM); -- Modified for bug 16248920
3507    l_lpn_rec.ORGANIZATION_ID := p_organization_id ;
3508    l_lpn_rec.source_header_id := Nvl(p_source_header_id, FND_API.G_MISS_NUM); -- Modified by 13591755 for GRUPO
3509    l_lpn_rec.source_name := Nvl(p_source_name, FND_API.G_MISS_CHAR); -- Modified by 13591755 for GRUPO
3510    l_lpn_rec.source_type_id := Nvl(p_source_type_id, FND_API.G_MISS_NUM); -- Modified by 13591755 for GRUPO
3511 
3512    IF (l_debug = 1) THEN
3513       print_debug(' update_lpn_location_context : lpn_id = '||p_lpn_id,1);
3514       print_debug(' update_lpn_location_context : lpn_context = '|| p_lpn_context , 1);
3515       print_debug(' update_lpn_location_context : sub = '|| p_sub , 1);
3516       print_debug(' update_lpn_location_context : locator = '|| p_locator , 1);
3517       print_debug(' update_lpn_location_context : organization_id = '|| p_organization_id , 1);
3518       print_debug(' update_lpn_location_context : source_header_id = '|| p_source_header_id , 1);
3519       print_debug(' update_lpn_location_context : source_name = '|| p_source_name , 1);
3520       print_debug(' update_lpn_location_context : source_type_id = '|| p_source_type_id , 1);
3521    END IF;
3522 
3523    wms_container_pvt.modify_lpn ( p_api_version           => 1.0,
3524 				  x_return_status         =>    x_return_status ,
3525 				  x_msg_count             =>    x_msg_count ,
3526 				  x_msg_data              =>    x_msg_data,
3527 				  p_validation_level      =>    fnd_api.g_valid_level_none,
3528 				  p_lpn                   =>    l_lpn_rec);
3529 
3530    l_progress := 'WMSINB-12645';
3531 
3532    -- Check the error status from the above call
3533    if x_return_status <> G_RET_STS_SUCCESS Then
3534       --  Review Late Set Appropiate Message
3535       l_progress := 'WMSINB-12650';
3536       RAISE FND_API.G_EXC_ERROR;
3537    End if;
3538 
3539 Exception
3540    when others then
3541       x_return_status  := g_ret_sts_unexp_error;
3542       IF (l_debug = 1) THEN
3543          print_debug('update_lpn_location_context : - other exception:'|| l_progress || ' ' ||
3544                      TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
3545       END IF;
3546       IF SQLCODE IS NOT NULL THEN
3547          inv_mobile_helper_functions.sql_error('inv_rcv_integration_pvt.update_lpn_location_context',l_progress, SQLCODE);
3548       END IF;
3549       --  Get message count and data
3550       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
3551 
3552 END update_lpn_location_context ;
3553 
3554 Function get_lpn_context(p_transaction_type IN VARCHAR2
3555 			 , p_routing_header_id IN NUMBER DEFAULT NULL
3556 			 , p_parent_transaction_type IN VARCHAR2 DEFAULT NULL
3557 			 , p_parent_parent_txn_type IN VARCHAR2 DEFAULT NULL
3558 			 , p_quantity IN NUMBER DEFAULT NULL
3559 			 , p_auto_transact_code IN VARCHAR2 DEFAULT NULL
3560 			 ) return NUMBER
3561   is
3562 Begin
3563    if p_transaction_type is null then
3564       return G_LPN_CONTEXT_PREGENERATED;
3565     elsif p_transaction_type = 'ACCEPT' then
3566       return G_LPN_CONTEXT_RCV;
3567     elsif p_transaction_type = 'REJECT' then
3568       return G_LPN_CONTEXT_RCV;
3569     elsif p_transaction_type = 'RECEIVE' THEN
3570       IF (Nvl(p_auto_transact_code, 'RECEIVE') <> 'DELIVER') THEN
3571 	 return G_LPN_CONTEXT_RCV;
3572        ELSE
3573 	 RETURN g_lpn_context_inv;
3574       END IF;
3575     elsif p_transaction_type = 'TRANSFER' then
3576       return G_LPN_CONTEXT_RCV;
3577     elsif p_transaction_type = 'DELIVER' then
3578       return G_LPN_CONTEXT_INV;
3579     elsif p_transaction_type = 'SHIP' then
3580       --Bug 4337726. A ship transaction with auto transact code as receive
3581       --should be treated like a receipt transaction
3582       IF (Nvl(p_auto_transact_code, 'SHIP') = 'RECEIVE') THEN
3583          RETURN g_lpn_context_rcv;
3584        ELSE
3585          RETURN G_LPN_CONTEXT_VENDOR;
3586       END IF;
3587     ELSIF p_transaction_type = 'RETURN TO RECEIVING' THEN
3588       RETURN g_lpn_context_rcv;
3589     ELSIF p_transaction_type IN ('RETURN TO VENDOR', 'RETURN TO CUSTOMER') THEN
3590       RETURN g_lpn_context_stores;
3591     ELSIF p_transaction_type = 'CORRECT' THEN
3592       IF (Nvl(p_parent_transaction_type,'@@@') IN ('ACCEPT','REJECT','TRANSFER')) THEN
3593 	 RETURN g_lpn_context_rcv;
3594        ELSIF (Nvl(p_parent_transaction_type,'@@@') = 'DELIVER') THEN
3595 	 IF (Nvl(p_quantity, 0) < 0) THEN
3596 	    RETURN g_lpn_context_rcv;
3597 	  ELSIF (Nvl(p_quantity, 0) > 0) THEN
3598 	    RETURN g_lpn_context_inv;
3599 	  ELSE
3600 	    RETURN g_lpn_context_pregenerated;
3601 	 END IF;
3602        ELSIF (Nvl(p_parent_transaction_type,'@@@') = 'RECEIVE') THEN
3603 	 IF (Nvl(p_quantity, 0) > 0) THEN
3604 	    RETURN g_lpn_context_rcv;
3605 	  ELSE
3606 	    RETURN g_lpn_context_pregenerated;
3607 	 END IF;
3608        ELSIF (Nvl(p_parent_transaction_type,'@@@') = 'RETURN TO RECEIVING') THEN
3609 	 IF (Nvl(p_quantity, 0) < 0) THEN
3610 	    RETURN g_lpn_context_inv;
3611 	  ELSIF (Nvl(p_quantity, 0) > 0) THEN
3612 	    RETURN g_lpn_context_rcv;
3613 	  ELSE
3614 	    RETURN g_lpn_context_pregenerated;
3615 	 END IF;
3616        ELSIF (Nvl(p_parent_transaction_type,'@@@') IN ('RETURN TO VENDOR','RETURN TO CUSTOMER')) THEN
3617 	 IF(Nvl(p_quantity, 0) < 0) THEN
3618 	    IF (Nvl(p_parent_parent_txn_type,'@@@@') = 'DELIVER') THEN
3619 	       RETURN g_lpn_context_inv;
3620 	     ELSIF p_parent_parent_txn_type IS NOT NULL THEN
3621 	       RETURN g_lpn_context_rcv;
3622 	     ELSE
3623 	       RETURN g_lpn_context_pregenerated;
3624 	    END IF;
3625 	  ELSIF (Nvl(p_quantity, 0) > 0) THEN
3626 	    RETURN g_lpn_context_stores;
3627 	  ELSE
3628 	    RETURN g_lpn_context_pregenerated;
3629          END IF;
3630        ELSE
3631 	 RETURN g_lpn_context_pregenerated;
3632       END IF;
3633     else
3634       return G_LPN_CONTEXT_PREGENERATED;
3635    end if;
3636 Exception
3637    when others then
3638       return G_LPN_CONTEXT_PREGENERATED;
3639 End get_lpn_context;
3640 
3641 -- R12
3642 PROCEDURE  check_reference(
3643                             p_old_reference           IN VARCHAR2
3644                            ,p_old_reference_type_code IN NUMBER
3645                            ,p_old_reference_id        IN NUMBER
3646                            ,p_new_reference           IN VARCHAR2
3647                            ,p_new_reference_type_code IN NUMBER
3648                            ,p_new_reference_id        IN NUMBER
3649                            ,x_reference               OUT NOCOPY  VARCHAR2
3650                            ,x_reference_type_code     OUT NOCOPY NUMBER
3651                            ,x_reference_id            OUT NOCOPY NUMBER
3652                            ,x_transaction_type_id     OUT NOCOPY NUMBER
3653                            ,x_txn_source_type_id      OUT NOCOPY NUMBER
3654                            ,x_return_status           OUT NOCOPY VARCHAR2
3655                            ,x_msg_count               OUT NOCOPY NUMBER
3656                            ,x_msg_data                OUT NOCOPY VARCHAR2
3657                           ) is
3658 
3659 L_DEBUG NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3660 l_progress      VARCHAR2(15) := '40400';
3661 l_proc_name     VARCHAR2(30) := 'CHECK_REFERENCE';
3662 l_same_doc      NUMBER;
3663 l_asn_line_flag VARCHAR2(1);
3664 
3665 Begin
3666 
3667    x_return_status := g_ret_sts_success;
3668 
3669    IF (l_debug = 1) THEN
3670       print_debug('Entering '||l_proc_name||':'|| l_progress,1);
3671       print_debug('p_old_reference           = '||p_old_reference ,1);
3672       print_debug('p_old_reference_type_code = '||p_old_reference_type_code ,1);
3673       print_debug('p_old_reference_id        = '||p_old_reference_id ,1);
3674       print_debug('p_new_reference           = '||p_new_reference ,1);
3675       print_debug('p_new_reference_type_code = '||p_new_reference_type_code ,1);
3676       print_debug('p_new_reference_id        = '||p_new_reference_id ,1);
3677       l_progress := 'WMSINB-40400';
3678    END IF;
3679 
3680    x_reference           := p_new_reference;
3681    x_reference_type_code := p_new_reference_type_code;
3682    x_reference_id        := p_new_reference_id;
3683 
3684    l_progress := 'WMSINB-40401';
3685 
3686    if nvl(p_old_reference,'@#$') = nvl(p_new_reference,'@#$') then
3687       if nvl(p_old_reference_id,-9999) = nvl(p_new_reference_id,-9999) then
3688            IF (l_debug = 1) THEN
3689               print_debug(l_proc_name||' Reference Ids are same '|| l_progress,1);
3690            End if;
3691        Else
3692            IF (l_debug = 1) THEN
3693               print_debug(l_proc_name||' Reference Ids are different '|| l_progress,1);
3694            End if;
3695 
3696            l_progress := 'WMSINB-40404';
3697 
3698            -- REFERENCE INFO IS FROM THE SAME DOC TYPE BUT FROM DIFF DOCS
3699 
3700            -- KEEP THE SAME DOC TYPE BUT PUT THE ID's AS NULL IF THEY
3701            -- POINT TO DIFF DOCS.
3702 /*
3703  Commenting for bug 13613257
3704 
3705            If p_new_reference = 'PO_LINE_LOCATION_ID' then
3706               IF (l_debug = 1) THEN
3707                  print_debug(l_proc_name||' CHECK FOR PO '|| l_progress,1);
3708               End if;
3709               BEGIN
3710                  select 1
3711                    into l_same_doc
3712                    from PO_LINE_LOCATIONS_ALL POLL
3713                   where POLL.LINE_LOCATION_ID = p_old_reference_id
3714                     and POLL.PO_HEADER_ID in ( select POLL1.PO_HEADER_ID
3715                                               from PO_LINE_LOCATIONS_ALL POLL1
3716                                              where POLL1.LINE_LOCATION_ID
3717                                                      = p_new_reference_id )
3718                     and rownum < 2;
3719 
3720                     l_progress := 'WMSINB-40405';
3721 
3722               EXCEPTION
3723                 WHEN OTHERS THEN
3724                     l_progress := 'WMSINB-40406';
3725                     IF (l_debug = 1) THEN
3726                        print_debug(l_proc_name||' POs  are different '|| l_progress,1);
3727                     End if;
3728                     x_reference_id        := NULL;
3729               END;
3730            End if;
3731 
3732            If p_new_reference = 'ORDER_LINE_ID' then
3733                l_progress := 'WMSINB-40407';
3734                IF (l_debug = 1) THEN
3735                  print_debug(l_proc_name||' CHECK FOR RMA '|| l_progress,1);
3736                End if;
3737                BEGIN
3738                  select 1
3739                    into l_same_doc
3740                    from OE_ORDER_LINES_ALL OEL
3741                   where OEL.LINE_ID = p_old_reference_id
3742                     and OEL.HEADER_ID in ( select OEL1.HEADER_ID
3743                                               from OE_ORDER_LINES_ALL OEL1
3744                                              where OEL1.LINE_ID
3745                                                      = p_new_reference_id )
3746                     and rownum < 2;
3747                   l_progress := 'WMSINB-40408';
3748               EXCEPTION
3749                 WHEN OTHERS THEN
3750                     l_progress := 'WMSINB-40409';
3751                     IF (l_debug = 1) THEN
3752                        print_debug(l_proc_name||' ORDERS are different '|| l_progress,1);
3753                     End if;
3754                     x_reference_id        := NULL;
3755                END;
3756            End if;
3757 
3758            If p_new_reference = 'SHIPMENT_LINE_ID' then
3759               BEGIN
3760                  l_progress := 'WMSINB-40410';
3761 
3762                  select nvl(asn_line_flag,'N')
3763                    into l_asn_line_flag
3764                    from rcv_shipment_lines rsl
3765                   where rsl.shipment_line_id = p_old_reference_id
3766                   ;
3767 
3768                  If l_asn_line_flag = 'Y' then
3769                    -- CASE FOR ASN
3770                      SELECT 1
3771                        INTO l_same_doc
3772                        FROM rcv_shipment_lines rsl, po_line_locations_all poll
3773                       WHERE rsl.shipment_line_id = p_old_reference_id
3774                         AND poll.line_location_id = rsl.po_line_location_id
3775                         AND poll.po_header_id in ( select poll1.po_header_id
3776                                                      from rcv_shipment_lines rsl1, po_line_locations_all poll1
3777                                                     where rsl1.shipment_line_id = p_new_reference_id
3778                                                       and poll1.line_location_id = rsl1.po_line_location_id )
3779                         AND rownum < 2;
3780                         l_progress := 'WMSINB-40411';
3781                   Else
3782                     -- CASE FOR INTSHIP/INTREQ
3783                     l_progress := 'WMSINB-40412';
3784                        SELECT 1
3785                        INTO l_same_doc
3786                        FROM rcv_shipment_lines rsl
3787                       WHERE rsl.shipment_line_id = p_old_reference_id
3788                         AND rsl.shipment_header_id in ( select rsl1.shipment_header_id
3789                                                           from rcv_shipment_lines rsl1
3790                                                          where rsl1.shipment_line_id = p_new_reference_id
3791                                                       )
3792                         AND rownum < 2;
3793                         l_progress := 'WMSINB-40413';
3794                   End if;
3795               EXCEPTION
3796                 WHEN OTHERS THEN
3797                     l_progress := 'WMSINB-40414';
3798                     IF (l_debug = 1) THEN
3799                        print_debug(l_proc_name||' SHIPMENT DIFFERENT '|| l_progress,1);
3800                     End if;
3801                     x_reference_id        := NULL;
3802               END;
3803            End if;
3804 */
3805            x_reference_id        := NULL;
3806        End if;
3807    Else
3808        IF (l_debug = 1) THEN
3809            print_debug(l_proc_name||' Reference Types are different '|| l_progress,1);
3810        End if;
3811        l_progress := 'WMSINB-40415';
3812        x_reference           := null;
3813        x_reference_type_code := null;
3814        x_reference_id        := null;
3815 
3816        x_transaction_type_id := 81;   -- CHANGE IT WITH THE RIGHT TXN TYPE -- VISHY ?????
3817        x_txn_source_type_id  := 4;
3818    End if;
3819 
3820    IF (l_debug = 1) THEN
3821          print_debug(l_proc_name||' x_reference = '|| x_reference,1);
3822          print_debug(l_proc_name||' x_reference_type_code = '|| x_reference_type_code,1);
3823          print_debug(l_proc_name||' x_reference_id = '|| x_reference_id,1);
3824          print_debug(l_proc_name||' x_transaction_type_id = '|| x_transaction_type_id,1);
3825          print_debug(l_proc_name||' x_txn_source_type_id = '|| x_txn_source_type_id,1);
3826    End if;
3827 
3828 EXCEPTION
3829    WHEN OTHERS THEN
3830       IF (l_debug = 1) THEN
3831          print_debug('CHECK_REFERENCE: Exception occured aftr l_progress = '
3832                      || l_progress,1);
3833       END IF;
3834       x_return_status := g_ret_sts_unexp_error;
3835 End check_reference;
3836 -- R12
3837 
3838 -- R12
3839 PROCEDURE maintain_mo_con(p_rti_id IN NUMBER,
3840 		      p_primary_quantity IN NUMBER,
3841 		      p_primary_uom_code IN VARCHAR2,
3842 		      p_mmtt_temp_id IN NUMBER,
3843 		      p_org_id IN NUMBER,
3844 		      p_item_id IN NUMBER,
3845 		      p_revision IN VARCHAR2,
3846 		      p_qty IN NUMBER,
3847 		      p_uom_code IN VARCHAR2,
3848 		      p_lpn_id IN NUMBER,
3849 		      p_transfer_lpn_id IN NUMBER,
3850 		      p_lot_control_code IN NUMBER,
3851 		      p_serial_number_control_code IN NUMBER,
3852 		      p_lot_number IN VARCHAR2,
3853 		      p_po_line_location_id IN NUMBER,
3854 		      p_po_distribution_id IN NUMBER,
3855 		      p_shipment_line_id IN NUMBER,
3856 		      p_oe_order_line_id IN NUMBER,
3857 		      p_routing_header_id IN NUMBER,
3858 		      p_subinventory IN VARCHAR2,
3859 		      p_locator_id IN NUMBER,
3860 		      p_from_subinventory IN VARCHAR2,
3861 		      p_from_locator_id IN NUMBER,
3862 		      p_project_id IN NUMBER DEFAULT NULL,
3863 		      p_task_id IN NUMBER DEFAULT NULL,
3864 		      x_transaction_id OUT nocopy NUMBER,
3865 		      x_return_status OUT nocopy VARCHAR2,
3866 		      x_msg_count OUT nocopy NUMBER,
3867 		      x_msg_data OUT nocopy VARCHAR2,
3868                       -- OPMConvergence
3869                       p_sec_qty IN NUMBER DEFAULT NULL,
3870                       p_sec_uom IN VARCHAR DEFAULT NULL,
3871                       -- OPMConvergence
3872                       p_auto_transact_code IN VARCHAR2 DEFAULT NULL,
3873                       p_asn_line_flag IN VARCHAR2 DEFAULT NULL ,
3874                       p_validation_flag IN VARCHAR2 DEFAULT NULL,
3875                       -- Bug# 7154105
3876                       p_req_distribution_id IN NUMBER DEFAULT NULL
3877   )
3878   IS
3879      /* Bug: 5064782: Modified the where clause condition for project_id and task_id
3880                       for the cursors c_mol_mmtt and c_mol_no_mmtt */
3881 
3882      CURSOR c_mol_mmtt (
3883                         p_mmtt_id NUMBER,
3884                         p_item NUMBER,
3885                         p_lpn NUMBER,
3886 			p_lot VARCHAR2,
3887                         p_rev VARCHAR2,
3888                         p_from_sub varchar2,
3889                         p_from_locator_id NUMBER,
3890                         p_project_id NUMBER,
3891                         p_task_id NUMBER,
3892                         p_inspection_status NUMBER
3893      ) IS
3894 	SELECT DISTINCT mtrl.line_id
3895           , 1 UOM_ORDERING
3896 	  , mmtt.transaction_temp_id
3897 	  , mtrl.wms_process_flag
3898 	  , 1 quantity_ordering
3899 	  , (mtrl.quantity - Nvl(mtrl.quantity_delivered, 0)) quantity
3900 	  , mtrl.primary_quantity
3901 	  , mtrl.uom_code
3902 	  , mtrl.lpn_id
3903 	  , mtrl.inventory_item_id
3904 	  , mtrl.lot_number
3905           -- OPMConvergence
3906           , (mtrl.secondary_quantity - Nvl(mtrl.secondary_quantity_delivered, 0)) secondary_quantity_2
3907 	  , mtrl.secondary_quantity
3908 	  , mtrl.secondary_uom_code
3909           , mtrl.crossdock_type
3910           -- OPMConvergence
3911           , mtrl.backorder_delivery_detail_id
3912           , mmtt.wip_supply_type
3913           , mtrl.reference
3914           , mtrl.reference_type_code
3915           , mtrl.reference_id
3916 	  , mtrl.quantity txn_qty
3917 	  , mtrl.quantity_detailed quantity_detailed
3918 	  , mtrl.quantity_delivered quantity_delivered
3919 	  FROM mtl_txn_request_lines mtrl
3920 	  , mtl_material_transactions_temp mmtt
3921 	WHERE mtrl.organization_id = p_org_id
3922           AND nvl(mtrl.from_subinventory_code,'@$#_') = nvl(p_from_sub,'@$#_')
3923           AND nvl(mtrl.from_locator_id,-1) = nvl(p_from_locator_id,-1)
3924           AND ( nvl(mtrl.project_id,-1) = nvl(p_project_id,-1) OR p_project_id IS NULL )
3925           AND ( nvl(mtrl.task_id,-1) = nvl(p_task_id,-1) OR p_task_id IS NULL )
3926           AND Nvl(inspection_status,-1)    = Nvl(p_inspection_status,-1)
3927           AND mtrl.inventory_item_id = p_item
3928           AND Nvl(mtrl.revision, Nvl(p_rev, '@@@@')) = Nvl(p_rev, '@@@@')
3929           AND Nvl(mtrl.lpn_id, -1) = Nvl(p_lpn, -1)
3930           AND Nvl(mtrl.lot_number, Nvl(p_lot,'@$#_')) = Nvl(p_lot, '@$#_')
3931 	  AND mmtt.transaction_temp_id = p_mmtt_id
3932 	  AND mmtt.move_order_line_id = mtrl.line_id
3933 	  AND (mtrl.quantity - Nvl(mtrl.quantity_delivered, 0)) > 0
3934 	  AND mtrl.line_status <> inv_globals.G_TO_STATUS_CLOSED
3935 	  AND exists (SELECT 1
3936 		      FROM  mtl_txn_request_headers mtrh
3937 		      WHERE mtrh.move_order_type = inv_globals.g_move_order_put_away
3938 		      AND   mtrh.header_id = mtrl.header_id)
3939 	  ORDER BY 3 DESC;
3940 
3941      l_mol_rec c_mol_mmtt%ROWTYPE;
3942      -- Bug 7460491 Removed the OR project id, task id is null in the where clause
3943      -- Bug 8463898, Modified the cursor to by-pass the check for MTRL project/task when p_lpn is NULL
3944      CURSOR c_mol_no_mmtt (
3945                            p_item NUMBER,
3946                            p_lpn NUMBER,
3947 			   p_lot VARCHAR2,
3948                            p_rev VARCHAR2,
3949                            p_from_sub varchar2,
3950                            p_from_locator_id NUMBER,
3951                            -- p_cost_group_id NUMBER, ????
3952                            p_project_id NUMBER,
3953                            p_task_id NUMBER,
3954                            p_inspection_status NUMBER ,
3955                            p_uom_code varchar2,
3956 						   p_new_reference_id NUMBER  ----14133874
3957                    ) IS
3958  		              --Bug 5231114:Added the condition on transaction_source_type_id and
3959                               -- transaction_action_id for the following combinations:13/12 and 4/27
3960 			      SELECT DISTINCT mtrl.line_id
3961                                 , Decode(p_uom_code,mtrl.uom_code,2,1)
3962 				uom_ordering --changed the order
3963 		                -- we are doing a order by desc
3964 				, Decode(mmtt.transaction_source_type_id||'#'||mmtt.transaction_action_id,'1#27',1,
3965 					 '7#12',1,'12#27',1,'13#12',1,'4#27',1, null) transaction_temp_id
3966 				, Nvl(mtrl.wms_process_flag,1)--when ordering by DESC, NULL would come first;
3967 				                              --just do an NVL here
3968 				, Decode(mtrl.primary_quantity
3969 					 ,p_primary_quantity
3970 					 ,1
3971 					 ,2) quantity_ordering
3972 				, (mtrl.quantity - Nvl(mtrl.quantity_delivered, 0)) quantity
3973 				, mtrl.primary_quantity
3974 				, mtrl.uom_code
3975 				, mtrl.lpn_id
3976 				, mtrl.inventory_item_id
3977 				, mtrl.lot_number
3978                                 -- OPMConvergence
3979 				, (mtrl.secondary_quantity - Nvl(mtrl.secondary_quantity_delivered, 0)) secondary_quantity_2
3980 	                        , mtrl.secondary_quantity
3981 	                        , mtrl.secondary_uom_code
3982                                 -- OPMConvergence
3983                                 , mtrl.crossdock_type
3984                                 , mtrl.backorder_delivery_detail_id
3985                                 , mmtt.wip_supply_type
3986                                 , mtrl.reference
3987                                 , mtrl.reference_type_code
3988                                 , mtrl.reference_id
3989 				, mtrl.quantity txn_qty
3990 				, mtrl.quantity_detailed quantity_detailed
3991 				, mtrl.quantity_delivered quantity_delivered
3992 				FROM mtl_txn_request_lines mtrl
3993 				, mtl_material_transactions_temp mmtt
3994 				WHERE mtrl.organization_id = p_org_id
3995                                 AND nvl(mtrl.from_subinventory_code,'@$#_') = nvl(p_from_sub,'@$#_')
3996                                 AND nvl(mtrl.from_locator_id,-1) = nvl(p_from_locator_id,-1)
3997                                 AND ( nvl(mtrl.project_id,-1) = nvl(p_project_id,-1) OR p_lpn IS NULL)
3998                                 AND ( nvl(mtrl.task_id,-1) = nvl(p_task_id,-1) OR p_lpn IS NULL)
3999                                 AND Nvl(inspection_status,-1)    = Nvl(p_inspection_status,-1)
4000 				AND mtrl.inventory_item_id = p_item
4001 				AND Nvl(mtrl.revision, Nvl(p_rev, '@@@@')) = Nvl(p_rev, '@@@@')
4002 				AND Nvl(mtrl.lpn_id, -1)=Decode(Nvl(p_lpn,-1),-1,Nvl(mtrl.lpn_id, -1),p_lpn) --bug 9578275
4003 				AND Nvl(mtrl.lot_number, Nvl(p_lot,'@$#_')) = Nvl(p_lot, '@$#_')
4004 				AND (mtrl.quantity - Nvl(mtrl.quantity_delivered, 0)) > 0
4005 				AND mmtt.move_order_line_id (+) = mtrl.line_id
4006 				AND mtrl.reference_id = p_new_reference_id  --14133874
4007 				AND mmtt.organization_id (+) = mtrl.organization_id
4008 				AND mtrl.line_status <> inv_globals.G_TO_STATUS_CLOSED
4009 				AND exists (SELECT 1
4010 					    FROM  mtl_txn_request_headers mtrh
4011 					    WHERE mtrh.move_order_type = inv_globals.g_move_order_put_away
4012 					    AND   mtrh.header_id = mtrl.header_id)
4013 				ORDER BY 2, 3 DESC, 4 DESC, 5;--order on 3 should be DESC because,
4014                                                               --if it is not, NULL values wouuld come last
4015 
4016      CURSOR c_transfer_mol ( p_lpn NUMBER
4017                             ,p_item NUMBER
4018                             ,p_lot VARCHAR2
4019                             ,p_rev VARCHAR2
4020                             ,p_from_sub VARCHAR2
4021                             ,p_from_locator_id NUMBER
4022                             -- ,p_cost_group_id NUMBER
4023                             ,p_project_id    NUMBER
4024                             ,p_task_id NUMBER
4025                             ,p_uom_code varchar2
4026                             ,p_backorder_delivery_detail_id NUMBER
4027                             ,p_crossdock_type varchar2
4028                             ,p_transfer_inspection_status NUMBER
4029 							,p_reference VARCHAR2   --13935217
4030                             ,p_reference_id NUMBER  --13935217
4031                             ) IS
4032                               SELECT
4033                                   mtrl.line_id                 line_id
4034 				 ,mtrl.uom_code   uom_code  --added for bug8283511
4035                                 -- Added columns below to make ordering same for both
4036                                 -- from and transfer cursor
4037                                 , Decode(p_uom_code,mtrl.uom_code,2,1) uom_ordering
4038 				, mtrl.wms_process_flag
4039 				, Decode(mtrl.primary_quantity
4040 					 ,p_primary_quantity
4041 					 ,1
4042 					 ,2) quantity_ordering
4043                                 ,mtrl.reference               reference
4044                                 ,mtrl.reference_type_code     reference_type_code
4045                                 ,mtrl.reference_id            reference_id
4046                                 FROM mtl_txn_request_lines mtrl
4047                                 WHERE  mtrl.organization_id = p_org_id
4048                                 AND mtrl.inventory_item_id = p_item
4049                                 AND mtrl.uom_code = p_uom_code
4050                                 AND Nvl(mtrl.revision, Nvl(p_rev, '@@@')) = Nvl(p_rev, '@@@')
4051                                 AND Nvl(mtrl.lpn_id, -1) = Nvl(p_lpn, -1)
4052                                 AND Nvl(mtrl.lot_number, Nvl(p_lot,'@$#_')) = Nvl(p_lot, '@$#_')
4053                                 AND (mtrl.quantity - Nvl(mtrl.quantity_delivered, 0)) > 0
4054                                 --
4055                                 AND Nvl(inspection_status,-1)    =
4056 				Nvl(p_transfer_inspection_status,-1)
4057                                 AND Nvl(from_subinventory_code,'@$#_') = Nvl(p_from_sub,'@$#_')
4058                                 AND Nvl(from_locator_id,-1)            = Nvl(p_from_locator_id,-1)
4059 								AND mtrl.reference                     = p_reference  --13935217
4060                                 AND mtrl.reference_id                  = p_reference_id  --13935217
4061                                 AND Nvl(project_id,-1)                 = Nvl(p_project_id,-1)
4062                                 AND Nvl(task_id,-1)                    = Nvl(p_task_id,-1)
4063                                 AND Nvl(backorder_delivery_detail_id,-1) = Nvl(p_backorder_delivery_detail_id,-1)
4064                                 AND Nvl(crossdock_type,-1)               = Nvl(p_crossdock_type,-1)
4065                                 -- AND Nvl(from_cost_group_id,-1)           = Nvl(p_cost_group_id,-1) ????
4066                                 AND mtrl.line_status <> inv_globals.G_TO_STATUS_CLOSED
4067 				AND exists (SELECT 1
4068 					    FROM  mtl_txn_request_headers mtrh
4069 					    WHERE mtrh.move_order_type = inv_globals.g_move_order_put_away
4070 					    AND   mtrh.header_id = mtrl.header_id)
4071                                 ORDER BY 2,3 DESC, 4 ;
4072 
4073      l_transfer_mol_rec c_transfer_mol%rowtype;
4074 
4075      l_transaction_id NUMBER;
4076      l_transaction_type VARCHAR2(25);
4077      l_parent_transaction_id NUMBER;
4078      l_source_document_code VARCHAR2(25);
4079      l_grand_parent_txn_id NUMBER;
4080      l_great_grand_parent_txn_id NUMBER;
4081      l_parent_txn_type VARCHAR2(25);
4082      l_grand_parent_txn_type VARCHAR2(25);
4083 
4084      l_from_sub VARCHAR2(30);
4085      l_from_loc_id NUMBER;
4086 
4087      l_remaining_primary_quantity NUMBER;
4088      l_mol_qty_in_puom NUMBER;
4089      l_quantity_delivered NUMBER;
4090 
4091      l_move_order_header_id NUMBER;
4092      l_move_order_line_id NUMBER;
4093      l_inspect NUMBER := NULL;
4094      l_transfer_org_id NUMBER := NULL;
4095 
4096      l_project_id NUMBER := NULL;
4097      l_task_id NUMBER := NULL;
4098 
4099      l_mo_split_tb inv_rcv_integration_apis.mo_in_tb_tp;
4100 
4101      l_call_pregeneration BOOLEAN := TRUE;
4102 
4103      l_mol_txn_id NUMBER;
4104      l_mol_lpn_id NUMBER;
4105 
4106      l_error_code NUMBER;
4107      l_operation_type NUMBER;
4108 
4109      l_dummy VARCHAR2(1);
4110 
4111      L_DEBUG NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4112      l_progress VARCHAR2(15) := '00';
4113      l_proc_name VARCHAR2(30) := 'MAINTAIN_MO_CON';
4114 
4115      -- OPMConvergence
4116      l_remaining_secondary_quantity NUMBER;
4117      l_sec_quantity_delivered       NUMBER;
4118      -- OPMConvergence
4119 
4120     l_po_line_location_id NUMBER := NULL;
4121     l_po_distribution_id  NUMBER := NULL;
4122 
4123     l_new_reference           VARCHAR2(2000);
4124     l_new_reference_type_code NUMBER;
4125     l_new_reference_id        NUMBER;
4126 
4127     l_reference           VARCHAR2(2000);
4128     l_reference_type_code NUMBER;
4129     l_reference_id        NUMBER;
4130 
4131     l_transfer_inspection_status NUMBER;
4132     l_from_mol_inspection_status NUMBER;
4133     l_rti_inspection_status_code varchar2(80);
4134     l_mol_res_in  cas_mol_rec_tb_tp;
4135     l_mol_res_out cas_mol_rec_tb_tp;
4136 
4137     l_transaction_type_id NUMBER;
4138     l_txn_source_type_id NUMBER;
4139     l_backorder_delivery_detail_id NUMBER;
4140     l_loaded NUMBER;
4141 
4142     l_requisition_line_id    NUMBER;
4143     l_po_header_id           NUMBER;
4144     l_auto_transact_code     VARCHAR2(25);
4145 
4146     l_mol_consumed_full NUMBER;
4147     l_split_sec_qty     NUMBER;
4148     l_split_qty     NUMBER;
4149 
4150     l_pt_inspection_status_code VARCHAR2(20);
4151     l_grand_pt_insp_status_code VARCHAR2(20);
4152     l_grt_gr_parent_insp_stat_code VARCHAR2(20);
4153     l_grt_gr_routing_id      NUMBER;
4154 
4155     l_pt_routing_id NUMBER;
4156     l_grand_pt_routing_id NUMBER;
4157 
4158     l_transfer_sub   VARCHAR2(30);
4159     l_transfer_locator_id NUMBER;
4160     l_mol_transfer_lpn_id NUMBER;
4161     l_qty_detailed        NUMBER;
4162 
4163     L_UPDATE_OR_CLOSE  VARCHAR2(1);
4164 
4165     l_loop_index NUMBER;
4166     l_is_asn     VARCHAR2(1);
4167     l_is_req     VARCHAR2(1) := 'N'; -- Bug 5460505
4168 
4169     l_tmp_qty NUMBER;
4170     l_tmp_qty_dlvd NUMBER;
4171     l_tmp_qty_dtld NUMBER;
4172     l_tmp_uom_code VARCHAR2(3);
4173 
4174     --For calling delete_reservation in REJECT cases
4175     l_rsv_rec      inv_reservation_global.mtl_reservation_rec_type;
4176     l_dummy_serial inv_reservation_global.serial_number_tbl_type;
4177     l_msg_count number;
4178     l_msg_data VARCHAR2(2000);
4179     l_return_status VARCHAR2(1);
4180 
4181     l_conversion_rate NUMBER;  -- Bug 5632202
4182     l_uom_code VARCHAR2(3);  -- bug8283511
4183     l_reason_id NUMBER ; -- Bug No.9099299
4184     l_discrepancy_exist VARCHAR2(1); --13395566
4185     l_mol_sub VARCHAR2(240);--13395566
4186 	l_mol_loc_id NUMBER;--13395566
4187 BEGIN
4188 
4189    x_return_status := g_ret_sts_success;
4190 
4191    x_transaction_id := -1;
4192 
4193    IF (l_debug = 1) THEN
4194       print_debug('Entering MAINTAIN_MO_CON:'||l_progress,1);
4195       print_debug('MAINTAIN_MO_CON - MMTT TEMP ID:'||p_mmtt_temp_id||':'||l_progress,1);
4196       print_debug('MAINTAIN_MO_CON - p_from_subinventory:'||p_from_subinventory||':'||l_progress,1);
4197       print_debug('MAINTAIN_MO_CON - p_from_locator_id:'||p_from_locator_id||':'||l_progress,1);
4198       print_debug('MAINTAIN_MO_CON - p_subinventory:'||p_subinventory||':'||l_progress,1);
4199       print_debug('MAINTAIN_MO_CON - p_locator_id:'||p_locator_id||':'||l_progress,1);
4200       print_debug('MAINTAIN_MO_CON - p_project_id:'||p_project_id||':'||l_progress,1);
4201       print_debug('MAINTAIN_MO_CON - p_task_id:'||p_task_id||':'||l_progress,1);
4202       print_debug('MAINTAIN_MO_CON - p_line_location_id:'||p_po_line_location_id||':'||l_progress,1);
4203       print_debug('MAINTAIN_MO_CON - p_po_distribution_id:'||p_po_distribution_id||':'||l_progress,1);
4204       print_debug('MAINTAIN_MO_CON - p_shipment_line_id:'||p_shipment_line_id||':'||l_progress,1);
4205       print_debug('MAINTAIN_MO_CON - p_asn_line_flag:'||p_asn_line_flag||':'||l_progress,1);
4206       print_debug('MAINTAIN_MO_CON - p_uom_code:'||p_uom_code||':'||l_progress,1);
4207       l_progress := 'WMSINB-40000';
4208    END IF;
4209 
4210    --QUERY RT
4211    BEGIN
4212       l_reason_id  := NULL;  -- Bug No.9099299
4213       SELECT transaction_id
4214 	, transaction_type
4215 	, parent_transaction_id
4216 	, source_document_code
4217         , INSPECTION_STATUS_CODE
4218         , requisition_line_id
4219         , po_header_id
4220         , reason_id  -- Bug No.9099299
4221 	INTO l_transaction_id
4222 	, l_transaction_type
4223 	, l_parent_transaction_id
4224 	, l_source_document_code
4225         , l_rti_inspection_status_code
4226         , l_requisition_line_id
4227         , l_po_header_id
4228         , l_reason_id  -- Bug No.9099299
4229 	FROM rcv_transactions
4230 	WHERE interface_transaction_id = p_rti_id;
4231 
4232    EXCEPTION
4233       WHEN no_data_found THEN
4234 	 --raise error
4235 	 l_progress := 'WMSINB-40010';
4236 	 RAISE fnd_api.g_exc_error;
4237       WHEN OTHERS THEN
4238 	 --raise error
4239 	 l_progress := 'WMSINB-40020';
4240 	 RAISE fnd_api.g_exc_error;
4241    END;
4242 
4243    x_transaction_id := l_transaction_id;
4244 
4245    IF (l_debug = 1) THEN
4246       print_debug('MAINTAIN_MO_CON - TRANSACTION TYPE:'||l_transaction_type||':'||l_progress,1);
4247       print_debug('MAINTAIN_MO_CON - SOURCE DOC CODE:'||l_source_document_code||':'||l_progress,1);
4248       print_debug('MAINTAIN_MO_CON - TRANSACTION ID:'||l_transaction_id||':'||l_progress,1);
4249       print_debug('MAINTAIN_MO_CON - PARENT TRANSACTION ID:'||l_parent_transaction_id||':'||l_progress,1);
4250       print_debug('MAINTAIN_MO_CON - PRIMARY QUANTITY:'||p_primary_quantity||':'||l_progress,1);
4251       -- OPMConvergence
4252       print_debug(l_proc_name||'SECONDARY QUANTITY: '||p_sec_qty||':'||l_progress,1);
4253       print_debug(l_proc_name||'SECONDARY UOM: '||p_sec_uom||':'||l_progress,1);
4254       -- OPMConvergence
4255       l_progress := 'WMSINB-40030';
4256    END IF;
4257 
4258    --QUERY RT TO GET THE GRAND PARENT
4259    IF (l_transaction_type IN ('CORRECT', 'RETURN TO RECEIVING',
4260 			      'RETURN TO VENDOR','RETURN TO CUSTOMER','ACCEPT','REJECT','TRANSFER',
4261                               'DELIVER')) THEN
4262       BEGIN
4263 	 SELECT parent_transaction_id
4264 	   , transaction_type
4265 	   , subinventory
4266 	   , locator_id
4267 	   , inspection_status_code
4268            , routing_header_id
4269 	   INTO l_grand_parent_txn_id
4270 	   , l_parent_txn_type
4271 	   , l_from_sub
4272 	   , l_from_loc_id
4273 	   , l_pt_inspection_status_code
4274            , l_pt_routing_id
4275 	   FROM rcv_transactions
4276 	   WHERE transaction_id = l_parent_transaction_id;
4277       EXCEPTION
4278 	 WHEN no_data_found THEN
4279 	    l_from_sub := NULL; --Review I think no data found in this
4280 	    --case must raise an error.
4281 	    l_from_loc_id := NULL;
4282 	    l_parent_txn_type := '';
4283 	    l_grand_parent_txn_id := -1;
4284       END;
4285 
4286       IF (l_debug = 1) THEN
4287          print_debug('l_pt_inspection_status_code := '||l_pt_inspection_status_code,1);
4288       END IF;
4289 
4290       IF (l_parent_txn_type IN ('RETURN TO VENDOR','RETURN TO CUSTOMER',
4291              'RETURN TO RECEIVING','CORRECT','ACCEPT','REJECT','DELIVER','TRANSFER')) THEN
4292 	 BEGIN
4293 	    SELECT parent_transaction_id
4294 	      , transaction_type
4295               , inspection_status_code
4296               , routing_header_id
4297 	      INTO l_great_grand_parent_txn_id
4298 	      , l_grand_parent_txn_type
4299               , l_grand_pt_insp_status_code
4300               , l_grand_pt_routing_id
4301 	      FROM rcv_transactions
4302 	      WHERE transaction_id = l_grand_parent_txn_id;
4303 	 EXCEPTION
4304 	    WHEN no_data_found THEN
4305 	       l_grand_parent_txn_type := '';
4306 	       l_great_grand_parent_txn_id := -1;
4307                l_grand_pt_insp_status_code := null;
4308                l_grand_pt_routing_id := null;
4309 	 END;
4310 
4311          --  Only for this case the inspection status code needs to be fetched
4312          --  For Great grand parent
4313          IF ( l_transaction_type = 'CORRECT' and
4314               l_parent_txn_type IN ('RETURN TO VENDOR','RETURN TO CUSTOMER',
4315 				'RETURN TO RECEIVING') ) THEN
4316 	    BEGIN
4317                 select inspection_status_code
4318                       ,routing_header_id
4319                   into l_grt_gr_parent_insp_stat_code
4320                       ,l_grt_gr_routing_id
4321                   from rcv_transactions
4322                  where transaction_id = l_great_grand_parent_txn_id;
4323             EXCEPTION
4324 	       WHEN no_data_found THEN
4325                   l_grt_gr_parent_insp_stat_code := null;
4326                   l_grt_gr_routing_id := null;
4327             END;
4328          END IF;
4329        ELSE
4330 	       l_grand_parent_txn_type := '';
4331 	       l_great_grand_parent_txn_id := -1;
4332                l_grand_pt_insp_status_code := null;
4333                l_grt_gr_parent_insp_stat_code := null;
4334                l_grt_gr_routing_id := null;
4335       END IF; --IF (l_parent_txn_type IN ('RETURN TO VENDOR','RETURN TO CUSTOMER',
4336     ELSE
4337 	 BEGIN
4338 	    SELECT parent_transaction_id
4339 	      , transaction_type
4340 	      , subinventory
4341 	      , locator_id
4342 	      INTO l_grand_parent_txn_id
4343 	      , l_parent_txn_type
4344 	      , l_from_sub
4345 	      , l_from_loc_id
4346 	      FROM rcv_transactions
4347 	      WHERE transaction_id = l_parent_transaction_id;
4348 	 EXCEPTION
4349 	    WHEN no_data_found THEN
4350 	       l_from_sub := NULL;
4351 	       l_from_loc_id := NULL;
4352 	       l_parent_txn_type := '';
4353 	       l_grand_parent_txn_id := -1;
4354 	 END;
4355    END IF; --IF (l_transaction_type IN ('CORRECT', 'RETURN TO RECEIVING')) THEN
4356 
4357    IF (l_debug = 1) THEN
4358       print_debug('MAINTAIN_MO_CON - PARENT TRANSACTION TYPE:'||l_parent_txn_type||':'||l_progress,1);
4359       print_debug('MAINTAIN_MO_CON - GRAND PARENT TRANSACTION ID:'||l_grand_parent_txn_id||':'||l_progress,1);
4360       print_debug('MAINTAIN_MO_CON - GRAND PARENT TRANSACTION TYPE:'||l_grand_parent_txn_type||':'||l_progress,1);
4361       print_debug('MAINTAIN_MO_CON - GREAT GRAND PARENT TRANSACTION ID:'||l_great_grand_parent_txn_id||':'||l_progress,1);
4362       print_debug('MAINTAIN_MO_CON - GRAND PARENT INSPECTION STATUS CODE:'||l_grand_pt_insp_status_code||':'||l_progress,1);
4363       l_progress := 'WMSINB-40035';
4364    END IF;
4365 
4366    --update mmtt with the sub/locator etc.
4367    IF (p_mmtt_temp_id IS NOT NULL) THEN
4368       IF (l_debug = 1) THEN
4369 	 print_debug('MAINTAIN_MO_CON - Updating MMTT with following values:',1);
4370 	 print_debug('MAINTAIN_MO_CON - Loc ID:'||p_locator_id,1);
4371 	 print_debug('MAINTAIN_MO_CON = Sub:'||p_subinventory,1);
4372 	 print_debug('MAINTAIN_MO_CON = Xfr LPN ID:'||p_transfer_lpn_id,1);
4373       END IF;
4374 
4375       --For DBI purpose
4376 
4377       --{{
4378       --After TRANSFER and DELIVER, make sure MMT for the transaction are
4379       --updated with the correct values }}
4380       UPDATE mtl_material_transactions_temp
4381 	SET rcv_transaction_id = l_transaction_id
4382 	, transfer_to_location = Decode(transfer_to_location,NULL,transfer_to_location,p_locator_id)
4383 	, transfer_subinventory = Decode(transfer_to_location,NULL,transfer_subinventory,p_subinventory)
4384 	, locator_id = Decode(transfer_to_location,NULL,p_locator_id,locator_id)
4385 	, subinventory_code = Decode(transfer_to_location,NULL,p_subinventory,subinventory_code)
4386 
4387 	--Bug 4082607.. commenting the following line as it is causing data
4388 	--corruption AND IS NOT required.
4389 	--	, lpn_id = Decode(l_transaction_type,'TRANSFER',Decode(p_transfer_lpn_id,NULL,lpn_id,p_transfer_lpn_id),lpn_id)
4390 	, transfer_lpn_id = decode(l_transaction_type,'TRANSFER',p_transfer_lpn_id,'DELIVER',p_transfer_lpn_id,transfer_lpn_id)
4391 	WHERE transaction_temp_id = p_mmtt_temp_id;
4392    END IF;
4393 
4394    l_progress := 'WMSINB-40039';
4395 
4396    -- FETCH THE REFERENCE INFORMATION
4397    --Bug 13891514 Adding ASBN as well because the validations/processing is same for ASN/ASBN
4398    IF p_shipment_line_id IS NOT NULL THEN
4399        BEGIN
4400 	  SELECT rsl.po_line_location_id,rsl.po_distribution_id,
4401 	    Decode(rsh.asn_type,'ASN','Y', 'ASBN','Y','N'),Decode(rsh.receipt_source_code,'INTERNAL ORDER','Y','N')
4402 	    INTO l_po_line_location_id,l_po_distribution_id,l_is_asn,l_is_req
4403 	    FROM rcv_shipment_lines rsl, rcv_shipment_headers rsh
4404 	    WHERE rsl.shipment_line_id = p_shipment_line_id
4405 	    AND   rsl.shipment_header_id = rsh.shipment_header_id;
4406        EXCEPTION
4407 	  WHEN OTHERS THEN
4408 	     IF (l_debug = 1) THEN
4409 		print_debug( 'MAINTAIN_MO_CON: RAISE FND_API.G_EXC_ERROR',4);
4410 	     END IF;
4411 	     RAISE fnd_api.g_exc_error;
4412        END;
4413 
4414        print_debug( 'MAINTAIN_MO_CON PLL ID : '||l_po_line_location_id ||
4415 		    '  POD ID : ' || l_po_distribution_id ||
4416 		    '  IS ASN?: ' || l_is_asn,4);
4417    END IF;
4418 
4419    IF (p_po_line_location_id IS NOT NULL AND l_is_asn = 'N') THEN
4420       --{{
4421       --Test PO transactions.  Also test for ASN transactions and see if
4422       --p_po_line_location_id is passed }}
4423       IF (l_debug = 1) THEN
4424         print_debug('MAINTAIN_MO_CON SETTING REFERENCE INFO for PO_LINE_LOCATION_ID '  , 4);
4425       END IF;
4426 
4427       l_new_reference_id := p_po_line_location_id;
4428       l_new_reference := 'PO_LINE_LOCATION_ID';
4429       l_new_reference_type_code := 4; -- for purchase orders
4430     --14730177 Commenting this code. Now PO_DISTRIBUTION_ID will not be stamped
4431 	--on the MO LINE.
4432    /*ELSIF p_po_distribution_id IS NOT NULL THEN
4433       --{{
4434       --Test direct receipt, MSCA deliver cases, putaway to inventory,
4435       --negative correction of deliver for all items}}
4436 
4437       IF (l_debug = 1) THEN
4438         print_debug('MAINTAIN_MO_CON  SETTING REFERENCE INFO for PO_DISTRIBUTION_ID '  , 4);
4439       END IF;
4440 
4441       l_new_reference_id := p_po_distribution_id;
4442       l_new_reference := 'PO_DISTRIBUTION_ID';
4443       l_new_reference_type_code := 4; -- for purchase orders
4444    */--14730177
4445    ELSIF p_oe_order_line_id IS NOT NULL AND l_is_req = 'N' THEN
4446       --{{
4447       --Test RMA transactions}}
4448 
4449       IF (l_debug = 1) THEN
4450         print_debug('MAINTAIN_MO_CON  SETTING REFERENCE INFO for ORDER_LINE_ID '  , 4);
4451       END IF;
4452 
4453       l_new_reference_id := p_oe_order_line_id;
4454       l_new_reference_type_code := 7; -- for RMA
4455       l_new_reference := 'ORDER_LINE_ID';
4456     ELSIF p_shipment_line_id IS NOT NULL THEN
4457 
4458       --{{
4459       --Test intrasit shipment, internal req.  For ASN, make sure that
4460       --the correct reference type code is stamped}}
4461       IF (l_debug = 1) THEN
4462         print_debug('MAINTAIN_MO_CON  SETTING REFERENCE INFO for SHIPMENT_LINE_ID '  , 4);
4463       END IF;
4464 
4465       l_new_reference_id := p_shipment_line_id;
4466 
4467       IF l_po_line_location_id IS NOT NULL OR l_po_distribution_id IS NOT NULL THEN
4468         l_new_reference_type_code := 4; --Considering the ASN
4469       ELSE
4470         l_new_reference_type_code := 8;
4471       END IF;
4472       l_new_reference := 'SHIPMENT_LINE_ID';
4473 
4474    END IF;
4475 
4476   l_progress := 'WMSINB-40047';
4477 
4478   -- ****************************************************
4479   -- FETCH THE TRANSFER INSPECTION STATUS
4480   -- ***************************************************
4481 
4482   IF (l_debug = 1) THEN
4483       print_debug( 'MAINTAIN_MO_CON p_routing_header_id = ' ||  p_routing_header_id , 4 );
4484   END if;
4485 
4486   if l_transaction_type = 'ACCEPT' then
4487      --{{
4488      --Inspect materials in a LPN that has already some inspected materials}}
4489      l_transfer_inspection_status := 2;
4490   Elsif l_transaction_type = 'REJECT' then
4491      l_transfer_inspection_status := 3;
4492   Else
4493      --IF (p_routing_header_id = 2) THEN
4494      IF (l_transaction_type <> 'RECEIVE') THEN
4495 	--{{
4496 	--Do receipt/transfer of materials whose source is a document
4497 	--with inspection routing into an LPN that have material with
4498 	--mixed inspection status.  Make sure that the correct MOL is
4499 	--picked up}}
4500 
4501          -- Txn TYPE CORRECT THEN TRANSFER INSPECTION STATUS
4502          -- SHOULD BE THE INSPECTION STATUS OF THE PARENT TXN.
4503          -- i,e MATERIAL SHOULD GO BACK TO THE ORIGINAL STATUS
4504          -- of PARENT TXN.
4505 
4506          IF ( (l_transaction_type IN ('CORRECT') and p_qty < 0 )
4507               AND l_parent_txn_type not in ('RETURN TO VENDOR',
4508                               'RETURN TO CUSTOMER','RETURN TO RECEIVING')
4509             )  THEN
4510 
4511              IF (l_debug = 1) THEN
4512                  print_debug( 'transfer insp stat correct and qty < 0 and parent txn not in RTV/ RTR/ RTC ', 4 );
4513              END if;
4514 
4515              IF l_grand_pt_insp_status_code is not null THEN
4516 	        IF    ( l_grand_pt_insp_status_code = 'NOT INSPECTED' and l_grand_pt_routing_id = 2) THEN
4517 	           l_transfer_inspection_status := 1;
4518 	        ELSIF ( l_grand_pt_insp_status_code = 'NOT INSPECTED' and l_grand_pt_routing_id <> 2) THEN
4519 	           l_transfer_inspection_status := null;
4520 	        ELSIF l_grand_pt_insp_status_code = 'ACCEPTED' THEN
4521 	           l_transfer_inspection_status := 2;
4522 	        ELSIF l_grand_pt_insp_status_code = 'REJECTED' THEN
4523 	           l_transfer_inspection_status := 3;
4524                 END IF;
4525              ELSE
4526                 -- There may not be any grand parent existing for this txn
4527                 -- So pick up the inspection status from the Parent txn.
4528                 IF (l_debug = 1) THEN
4529                   print_debug( 'l_grand_pt_insp_status_code is null  ', 4 );
4530                 END if;
4531 
4532 	        l_transfer_inspection_status := null;
4533              END IF;
4534          ELSIF ( ( l_transaction_type IN ('CORRECT') and p_qty > 0 )
4535               AND l_parent_txn_type not in ('RETURN TO VENDOR',
4536                               'RETURN TO CUSTOMER','RETURN TO RECEIVING')
4537                ) THEN
4538 
4539              IF (l_debug = 1) THEN
4540                 print_debug( 'MAINTAIN_MO_CON Setting transfer insp correct and qty > 0 and parent not in RTV / RTR / RTC ', 4 );
4541              END if;
4542 
4543 	     IF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2) THEN
4544 	        l_transfer_inspection_status := 1;
4545 	     ELSIF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2) THEN
4546 	        l_transfer_inspection_status := null;
4547 	     ELSIF l_pt_inspection_status_code = 'ACCEPTED' THEN
4548 	        l_transfer_inspection_status := 2;
4549 	     ELSIF l_pt_inspection_status_code = 'REJECTED' THEN
4550 	        l_transfer_inspection_status := 3;
4551              END IF;
4552 
4553          ELSIF ( (l_transaction_type IN ('CORRECT') and p_qty < 0 )
4554               AND l_parent_txn_type in ('RETURN TO VENDOR',
4555                               'RETURN TO CUSTOMER','RETURN TO RECEIVING')
4556                ) THEN
4557              IF (l_debug = 1) THEN
4558                  print_debug( 'Setting xfr insp correct and qty < 0 and parent in RTV / RTR / RTC ', 4 );
4559              END IF;
4560 
4561 	     IF (l_grt_gr_parent_insp_stat_code = 'NOT INSPECTED' and l_grt_gr_routing_id = 2) THEN
4562 	        l_transfer_inspection_status := 1;
4563 	     ELSIF (l_grt_gr_parent_insp_stat_code = 'NOT INSPECTED' and l_grt_gr_routing_id <> 2) THEN
4564 	        l_transfer_inspection_status := null;
4565 	     ELSIF l_grt_gr_parent_insp_stat_code = 'ACCEPTED' THEN
4566 	        l_transfer_inspection_status := 2;
4567 	     ELSIF  l_grt_gr_parent_insp_stat_code = 'REJECTED' THEN
4568 	        l_transfer_inspection_status := 3;
4569              END IF;
4570 
4571          ELSIF ( (l_transaction_type IN ('CORRECT') and p_qty > 0 )
4572               AND l_parent_txn_type in ('RETURN TO VENDOR',
4573                               'RETURN TO CUSTOMER','RETURN TO RECEIVING')
4574                ) THEN
4575              IF (l_debug = 1) THEN
4576                  print_debug( 'Setting xfr insp correct and qty > 0 and parent in RTV / RTR / RTC ', 4 );
4577              END if;
4578 
4579              l_transfer_inspection_status := null;
4580 
4581          ELSIF l_transaction_type IN ( 'RETURN TO VENDOR',
4582                               'RETURN TO CUSTOMER','RETURN TO RECEIVING' ) THEN
4583 
4584              IF (l_debug = 1) THEN
4585                  print_debug( 'MAINTAIN_MO_CON Setting xfr insp for RTV/ RTR/ RTC ', 4 );
4586              END if;
4587 
4588 	     IF (l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2 ) THEN
4589 	        l_transfer_inspection_status := 1;
4590 	     ELSIF (l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2 ) THEN
4591 	        l_transfer_inspection_status := null;
4592 	     ELSIF l_pt_inspection_status_code = 'ACCEPTED' THEN
4593 	        l_transfer_inspection_status := 2;
4594 	     ELSIF l_pt_inspection_status_code = 'REJECTED' THEN
4595 	        l_transfer_inspection_status := 3;
4596              END IF;
4597          ELSIF l_transaction_type IN ( 'TRANSFER') THEN
4598              IF (l_debug = 1) THEN
4599                  print_debug( 'MAINTAIN_MO_CON Setting xfr insp for TRANSFER TXN ', 4 );
4600              END if;
4601 
4602 	     IF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2) THEN
4603 	        l_transfer_inspection_status := 1;
4604 	     ELSIF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2) THEN
4605 	        l_transfer_inspection_status := null;
4606 	     ELSIF l_pt_inspection_status_code = 'ACCEPTED' THEN
4607 	        l_transfer_inspection_status := 2;
4608 	     ELSIF l_pt_inspection_status_code = 'REJECTED' THEN
4609 	        l_transfer_inspection_status := 3;
4610              END IF;
4611          ELSIF l_transaction_type IN ( 'DELIVER') THEN
4612              IF (l_debug = 1) THEN
4613                  print_debug( 'MAINTAIN_MO_CON DELIVER TXN Setting xfr inspection status ', 4 );
4614              END if;
4615 	     l_transfer_inspection_status := null;
4616          ELSE
4617             IF ( l_rti_inspection_status_code = 'NOT INSPECTED' and p_routing_header_id = 2) THEN
4618               l_transfer_inspection_status := 1;
4619             ELSIF ( l_rti_inspection_status_code = 'NOT INSPECTED' and p_routing_header_id <> 2) THEN
4620               l_transfer_inspection_status := null;
4621             ELSIF l_rti_inspection_status_code = 'ACCEPTED' THEN
4622               l_transfer_inspection_status := 2;
4623             ELSIF l_rti_inspection_status_code = 'REJECTED' THEN
4624               l_transfer_inspection_status := 3;
4625             END IF;
4626          END IF;
4627       ELSE
4628         -- Setting Inspection Status for RECEIVE CASE
4629 	--{{
4630 	--Do receipt/transfer of materials whose source is a document
4631 	--with standard routing into an LPN that have material with
4632 	--mixed inspection status.  Make sure that the correct MOL is
4633 	--picked up}}
4634 
4635         IF (l_debug = 1) THEN
4636             print_debug( 'MAINTAIN_MO_CON Setting xfr insp for RECEIVE ', 4 );
4637         END if;
4638 
4639         IF (p_routing_header_id = 2) THEN
4640 	   l_transfer_inspection_status := 1;
4641         ELSE
4642 	   l_transfer_inspection_status := null;
4643         END IF;
4644       END IF;
4645   End if;
4646 
4647 --Review need to discuss the above. This is not right because if the
4648 --transaction type is anything but accept or reject then we cannot blindly
4649 --  SET it based on the routing. it will also depend on the inspection
4650 --  status the rti/rt.
4651 -- ************************************************
4652 -- FETCH THE FROM INSPECTION STATUS
4653 -- ***********************************************
4654 
4655      IF (l_debug = 1) THEN
4656          print_debug( 'MAINTAIN_MO_CON Setting FROM MOL INSP STATUS', 4 );
4657      END if;
4658 
4659      IF (l_transaction_type IN ('ACCEPT','REJECT')) THEN
4660 	IF (l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2) THEN
4661 	   l_from_mol_inspection_status := 1;
4662 	ELSIF (l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2) THEN
4663 	   l_from_mol_inspection_status := null;
4664 	ELSIF l_pt_inspection_status_code = 'ACCEPTED' THEN
4665 	   l_from_mol_inspection_status := 2;
4666 	ELSIF l_pt_inspection_status_code = 'REJECTED' THEN
4667 	   l_from_mol_inspection_status := 3;
4668 	END IF;
4669      ELSE --RECEIVE/RTV/RTR/TRANSFER/DELIVER/CORRECT txn
4670          IF (l_transaction_type <> 'RECEIVE') THEN
4671 
4672             IF ( (l_transaction_type IN ('CORRECT') and p_qty < 0 )
4673               AND l_parent_txn_type not in ('RETURN TO VENDOR',
4674                               'RETURN TO CUSTOMER','RETURN TO RECEIVING')
4675             )  THEN
4676 
4677                 IF (l_debug = 1) THEN
4678                     print_debug( 'from mol insp stat correct and qty < 0 and parent txn not in RTV/ RTR/ RTC ', 4 );
4679                 END IF;
4680 
4681 	        IF (l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2) THEN
4682 	           l_from_mol_inspection_status := 1;
4683 	        ELSIF (l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2) THEN
4684 	           l_from_mol_inspection_status := null;
4685 	        ELSIF l_pt_inspection_status_code = 'ACCEPTED' THEN
4686 	           l_from_mol_inspection_status := 2;
4687 	        ELSIF l_pt_inspection_status_code = 'REJECTED' THEN
4688 	           l_from_mol_inspection_status := 3;
4689 	        END IF;
4690             ELSIF ( (l_transaction_type IN ('CORRECT') and p_qty > 0 )
4691               AND l_parent_txn_type not in ('RETURN TO VENDOR',
4692                               'RETURN TO CUSTOMER','RETURN TO RECEIVING')
4693                   ) THEN
4694                 IF l_grand_pt_insp_status_code is not null THEN
4695 	           IF ( l_grand_pt_insp_status_code = 'NOT INSPECTED' and l_grand_pt_routing_id = 2) THEN
4696 	              l_from_mol_inspection_status := 1;
4697 	           ELSIF ( l_grand_pt_insp_status_code = 'NOT INSPECTED' and l_grand_pt_routing_id <> 2) THEN
4698 	              l_from_mol_inspection_status := null;
4699 	           ELSIF l_grand_pt_insp_status_code = 'ACCEPTED' THEN
4700 	              l_from_mol_inspection_status := 2;
4701 	           ELSIF l_grand_pt_insp_status_code = 'REJECTED' THEN
4702 	              l_from_mol_inspection_status := 3;
4703                    END IF;
4704                 ELSE
4705                    -- There may not be any grand parent existing for this txn
4706                    -- So pick up the inspection status from the Parent txn.
4707                    IF (l_debug = 1) THEN
4708                      print_debug( 'l_grand_pt_insp_status_code is null  ', 4 );
4709                    END if;
4710 
4711 	           l_from_mol_inspection_status := null;
4712                 END IF;
4713             ELSIF l_transaction_type IN ( 'RETURN TO VENDOR',
4714                               'RETURN TO CUSTOMER','RETURN TO RECEIVING' ) THEN
4715 
4716                 IF (l_debug = 1) THEN
4717                     print_debug( 'MAINTAIN_MO_CON Setting xfr insp for RTV/ RTR/ RTC ', 4 );
4718                 END if;
4719 
4720                 IF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2) THEN
4721                    l_from_mol_inspection_status := 1;
4722                 ELSIF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2) THEN
4723                    l_from_mol_inspection_status := null;
4724                 ELSIF l_pt_inspection_status_code = 'ACCEPTED' THEN
4725                    l_from_mol_inspection_status := 2;
4726                 ELSIF l_pt_inspection_status_code = 'REJECTED' THEN
4727                    l_from_mol_inspection_status := 3;
4728                 END IF;
4729 
4730             ELSIF ( (l_transaction_type IN ('CORRECT') and p_qty < 0 )
4731                  AND l_parent_txn_type in ('RETURN TO VENDOR',
4732                                  'RETURN TO CUSTOMER','RETURN TO RECEIVING')
4733                   ) THEN
4734                 IF (l_debug = 1) THEN
4735                     print_debug( 'Setting from mol insp correct and qty < 0 and parent in RTV / RTR / RTC ', 4 );
4736                 END IF;
4737           -- bug 8201074
4738           /*
4739 	        IF ( l_grt_gr_parent_insp_stat_code = 'NOT INSPECTED' and l_grt_gr_routing_id = 2) THEN
4740 	           l_transfer_inspection_status := 1;
4741 	        ELSIF ( l_grt_gr_parent_insp_stat_code = 'NOT INSPECTED' and l_grt_gr_routing_id <> 2) THEN
4742 	           l_transfer_inspection_status := null;
4743 	        ELSIF l_grt_gr_parent_insp_stat_code = 'ACCEPTED' THEN
4744 	           l_transfer_inspection_status := 2;
4745 	        ELSIF  l_grt_gr_parent_insp_stat_code = 'REJECTED' THEN
4746 	           l_transfer_inspection_status := 3;
4747                 END IF;
4748           */
4749           IF ( l_grand_pt_insp_status_code = 'NOT INSPECTED' and l_grand_pt_routing_id = 2) THEN
4750 	           l_transfer_inspection_status := 1;
4751 	        ELSIF ( l_grand_pt_insp_status_code = 'NOT INSPECTED' and l_grand_pt_routing_id <> 2) THEN
4752 	           l_transfer_inspection_status := null;
4753 	        ELSIF l_grand_pt_insp_status_code = 'ACCEPTED' THEN
4754 	           l_transfer_inspection_status := 2;
4755 	        ELSIF  l_grand_pt_insp_status_code = 'REJECTED' THEN
4756 	           l_transfer_inspection_status := 3;
4757                END IF;
4758           -- end bug 8201074
4759 
4760             ELSIF ( (l_transaction_type IN ('CORRECT') and p_qty > 0 )
4761                  AND l_parent_txn_type in ('RETURN TO VENDOR',
4762                                  'RETURN TO CUSTOMER','RETURN TO RECEIVING')
4763                   ) THEN
4764                 IF (l_debug = 1) THEN
4765                     print_debug( 'Setting from mol insp correct and qty > 0 and parent in RTV / RTR / RTC ', 4 );
4766                 END IF;
4767                 -- Bug 7355205
4768                 -- l_from_mol_inspection_status := null;
4769                 IF ( l_grand_pt_insp_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2) THEN
4770 	           l_from_mol_inspection_status := 1;
4771 	        ELSIF ( l_grand_pt_insp_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2) THEN
4772 	           l_from_mol_inspection_status := null;
4773 	        ELSIF l_grand_pt_insp_status_code = 'ACCEPTED' THEN
4774 	           l_from_mol_inspection_status := 2;
4775 	        ELSIF l_grand_pt_insp_status_code = 'REJECTED' THEN
4776 	           l_from_mol_inspection_status := 3;
4777                 END IF;
4778             ELSIF l_transaction_type IN ( 'TRANSFER') THEN
4779                 IF (l_debug = 1) THEN
4780                     print_debug( 'MAINTAIN_MO_CON Setting from insp for TRANSFER TXN ', 4 );
4781                 END if;
4782 	        IF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2) THEN
4783 	           l_from_mol_inspection_status := 1;
4784 	        ELSIF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2) THEN
4785 	           l_from_mol_inspection_status := null;
4786 	        ELSIF l_pt_inspection_status_code = 'ACCEPTED' THEN
4787 	           l_from_mol_inspection_status := 2;
4788 	        ELSIF l_pt_inspection_status_code = 'REJECTED' THEN
4789 	           l_from_mol_inspection_status := 3;
4790                 END IF;
4791             ELSIF l_transaction_type IN ( 'DELIVER') THEN
4792                 IF (l_debug = 1) THEN
4793                     print_debug( 'MAINTAIN_MO_CON DELIVER TXN Setting from inspection status ', 4 );
4794                 END if;
4795 	        IF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id = 2) THEN
4796 	           l_from_mol_inspection_status := 1;
4797 	        ELSIF ( l_pt_inspection_status_code = 'NOT INSPECTED' and l_pt_routing_id <> 2) THEN
4798 	           l_from_mol_inspection_status := null;
4799 	        ELSIF l_pt_inspection_status_code = 'ACCEPTED' THEN
4800 	           l_from_mol_inspection_status := 2;
4801 	        ELSIF l_pt_inspection_status_code = 'REJECTED' THEN
4802 	           l_from_mol_inspection_status := 3;
4803                 END IF;
4804             END IF;
4805          ELSE
4806              IF (l_debug = 1) THEN
4807                  print_debug( 'MAINTAIN_MO_CON Txn is Receive Setting FROM MOL INSP STATUS TO NULL', 4 );
4808              END if;
4809              l_from_mol_inspection_status := null;
4810          END IF;
4811      END IF;
4812 
4813   --Why are we doing a if on transaction type when the code is
4814   --exactly same for if and else blocks.
4815 
4816   IF (l_debug = 1) THEN
4817       print_debug( 'MAINTAIN_MO_CON l_from_mol_inspection_status = ' ||  l_from_mol_inspection_status , 4 );
4818       print_debug( 'MAINTAIN_MO_CON l_transfer_inspection_status = ' ||  l_transfer_inspection_status , 4 );
4819   END IF;
4820 
4821    -- Now maintain MO
4822    IF (l_transaction_type in ('RECEIVE','MATCH') OR
4823        (l_transaction_type = 'CORRECT' AND
4824 	p_primary_quantity > 0 AND
4825 	l_parent_txn_type = 'RECEIVE')) THEN
4826 
4827       IF (l_debug = 1) THEN
4828           print_debug( 'MAINTAIN_MO_CON l_transfer_inspection_status = ' ||  l_transfer_inspection_status , 4 );
4829       END IF;
4830 
4831       --This is not used in INVRUTLB.  Make sure that this is OK
4832       IF l_source_document_code IN ('INVENTORY','REQ') THEN
4833 	 l_transfer_org_id := p_org_id;
4834       END IF;
4835 
4836       --Get the project and task information
4837 
4838       --{{
4839       --Test receipt and deliver in PJM org}}
4840       IF (p_project_id IS NULL) THEN
4841 
4842 	 --{{
4843 	 --Test receipt and deliver of PO with project/task distribution}}
4844 	 IF (p_po_distribution_id IS NOT NULL) THEN
4845 	    BEGIN
4846 	       SELECT project_id,
4847 	              task_id              -- bug 7218830
4848 		 INTO l_project_id,
4849 		 l_task_id
4850 		 FROM po_distributions_all
4851 		 WHERE po_distribution_id = p_po_distribution_id;
4852 	    EXCEPTION
4853 	       WHEN no_data_found THEN
4854 		  l_project_id := NULL;
4855 		  l_task_id := NULL;
4856 	    END ;
4857             ELSIF (p_po_line_location_id IS NOT NULL) then  -- Bug 6830559
4858             inv_rcv_std_rcpt_apis.get_project_task(
4859                  p_po_line_location_id     => p_po_line_location_id
4860                , p_oe_order_line_id        => NULL
4861                , x_project_id              => l_project_id
4862                , x_task_id                 => l_task_id
4863             );
4864 	 --{{
4865 	 --Test receipt and deliver of RMA with project/task distribution}}
4866 	  ELSIF (p_oe_order_line_id IS NOT NULL) THEN
4867                BEGIN
4868 		  SELECT project_id,
4869 		         task_id                -- bug 7218830
4870 		    INTO l_project_id
4871 		    , l_task_id
4872 		    FROM oe_order_lines_all
4873 		    WHERE line_id = p_oe_order_line_id;
4874 	       EXCEPTION
4875 		  WHEN no_data_found THEN
4876 		     l_project_id := NULL;
4877 		     l_task_id := NULL;
4878 	       END;
4879        -- Bug# 7154105 Picking up the Praject and Task from po_req_distributions_all when
4880        -- a distribution is specified in the Internal Requisition. There can be just one
4881        -- distribution for internally sourced documents
4882        ELSIF p_req_distribution_id IS NOT NULL THEN
4883          BEGIN
4884            select project_id, task_id
4885            into   l_project_id, l_task_id
4886            from   po_req_distributions_all
4887            where  distribution_id = p_req_distribution_id;
4888 
4889            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);
4890          EXCEPTION
4891 		   WHEN no_data_found THEN
4892 		     l_project_id := NULL;
4893 		     l_task_id := NULL;
4894             when too_many_rows then
4895              print_debug('MAINTAIN_MOC_CON - Proj Task Pickup for distributions fetches too many rows : ' || sqlerrm,1);
4896              raise fnd_api.g_exc_unexpected_error;
4897 	     END;
4898          -- End of Bug# 7154105
4899 	 END IF;
4900        ELSE --IF (p_project_id IS NULL) THEN
4901 		  l_project_id := p_project_id;
4902 		  l_task_id := p_task_id;
4903       END IF; --IF (p_project_id IS NULL) THEN
4904 
4905       IF (l_debug = 1) THEN
4906 	 print_debug('MAINTAIN_MOC_CON - Before calling Reservation API:'||l_progress,1);
4907 	 l_progress := 'WMSINB-45050';
4908       END IF;
4909 
4910       -- ******************************************************************
4911       -- CALL THE RESERVATION API HERE
4912       -- l_mol_res_in is returned from the reservation API
4913       -- CHANGE THIS PART ONCE THE RESERVATION API IS COMPLETED.
4914       -- ******************************************************************
4915 
4916       l_mol_res_in(1).transaction_type       := l_transaction_type;
4917       l_mol_res_in(1).organization_id        := p_org_id;
4918       l_mol_res_in(1).lpn_id                 := p_transfer_lpn_id;
4919       l_mol_res_in(1).inventory_item_id      := p_item_id;
4920       l_mol_res_in(1).lot_number             := p_lot_number;
4921       l_mol_res_in(1).item_revision          := p_revision;
4922       l_mol_res_in(1).from_subinventory_code := p_subinventory;
4923       l_mol_res_in(1).from_locator_id        := p_locator_id;
4924 
4925       -- l_mol_res_in(1).cost_group_id          := null; ????
4926 
4927       l_mol_res_in(1).project_id             := l_project_id;
4928       l_mol_res_in(1).task_id                := l_task_id;
4929       l_mol_res_in(1).uom_code               := p_uom_code;
4930       l_mol_res_in(1).quantity               := p_qty;
4931       l_mol_res_in(1).backorder_delivery_detail_id := null;
4932       l_mol_res_in(1).crossdock_type         := null;
4933       l_mol_res_in(1).transfer_org_id        := l_transfer_org_id;
4934       l_mol_res_in(1).secondary_quantity     := p_sec_qty;
4935       l_mol_res_in(1).secondary_uom          := p_sec_uom;
4936       l_mol_res_in(1).inspection_status      := l_transfer_inspection_status ;
4937       l_mol_res_in(1).line_id                := null;
4938       l_mol_res_in(1).primary_uom_code       := p_primary_uom_code;
4939       l_mol_res_in(1).primary_qty            := p_primary_quantity;
4940       l_mol_res_in(1).po_header_id           := l_po_header_id;
4941       l_mol_res_in(1).po_line_location_id    := p_po_line_location_id;
4942       l_mol_res_in(1).shipment_line_id       := p_shipment_line_id;
4943       l_mol_res_in(1).requisition_line_id    := l_requisition_line_id;
4944       l_mol_res_in(1).auto_transact_code     := p_auto_transact_code;
4945       l_mol_res_in(1).wip_supply_type        := null;
4946       l_mol_res_in(1).routing_header_id      := p_routing_header_id;
4947       l_mol_res_in(1).source_document_code   := l_source_document_code;
4948       l_mol_res_in(1).parent_transaction_id  := null;
4949       l_mol_res_in(1).asn_line_flag          := p_asn_line_flag;
4950       l_mol_res_in(1).parent_txn_type        := l_parent_txn_type;
4951 
4952       INV_RCV_RESERVATION_UTIL.maintain_reservations
4953                  (x_return_status => x_return_status
4954                  ,x_msg_count     => x_msg_count
4955                  ,x_msg_data      => x_msg_data
4956                  ,x_mol_tb        => l_mol_res_out
4957                  ,p_cas_mol_tb    => l_mol_res_in
4958        );
4959 
4960        IF (l_debug = 1) THEN
4961                 print_debug(' maintain_reservations - After calling maintain_reservations :'||x_return_status||':'||l_progress,1);
4962                 l_progress := 'WMSINB-45051';
4963        END IF;
4964 
4965        IF (x_return_status <> 'S') THEN
4966               l_progress := 'WMSINB-45052';
4967               RAISE fnd_api.g_exc_error;
4968        END IF;
4969 
4970       l_progress := 'WMSINB-45053';
4971 
4972       l_loop_index := l_mol_res_out.first;
4973 
4974       LOOP
4975 
4976 	 EXIT WHEN l_loop_index IS NULL;
4977 
4978          IF (l_debug = 1) THEN
4979 	    print_debug('MAINTAIN_MOC_CON -Inside MOL CONSL LOOP ',1);
4980 	    print_debug(' l_mol_res_out('||l_loop_index||').lpn_id                       => ' ||l_mol_res_out(l_loop_index).lpn_id,1);
4981 	    print_debug(' l_mol_res_out('||l_loop_index||').inventory_item_id            => ' ||l_mol_res_out(l_loop_index).inventory_item_id,1);
4982 	    print_debug(' l_mol_res_out('||l_loop_index||').lot_number                   => ' ||l_mol_res_out(l_loop_index).lot_number,1);
4983 	    print_debug(' l_mol_res_out('||l_loop_index||').item_revision                => ' ||l_mol_res_out(l_loop_index).item_revision,1);
4984 	    print_debug(' l_mol_res_out('||l_loop_index||').from_subinventory_code       => ' ||l_mol_res_out(l_loop_index).from_subinventory_code,1);
4985 	    print_debug(' l_mol_res_out('||l_loop_index||').from_locator_id              => ' ||l_mol_res_out(l_loop_index).from_locator_id,1);
4986 	    print_debug(' l_mol_res_out('||l_loop_index||').project_id                   => ' ||l_mol_res_out(l_loop_index).project_id,1);
4987 	    print_debug(' l_mol_res_out('||l_loop_index||').task_id                      => ' ||l_mol_res_out(l_loop_index).task_id,1);
4988 	    print_debug(' l_mol_res_out('||l_loop_index||').uom_code                     => ' ||l_mol_res_out(l_loop_index).uom_code,1);
4989 	    print_debug(' l_mol_res_out('||l_loop_index||').quantity                     => ' ||l_mol_res_out(l_loop_index).quantity,1);
4990 	    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);
4991 	    print_debug(' l_mol_res_out('||l_loop_index||').crossdock_type               => ' ||l_mol_res_out(l_loop_index).crossdock_type,1);
4992 	    print_debug(' l_mol_res_out('||l_loop_index||').inspection_status            => ' ||l_mol_res_out(l_loop_index).inspection_status,1);
4993 	 END IF;
4994 
4995 	 --{{
4996 	 --Do multiple receipt with the same conolidation critieria:
4997 	 --1) LPN 2) Item 3) Lot 4)Rev 5) From Sub 6) From Loc
4998 	 --7) Project ID 8) Task_Id 9) Uom_code 10) BDD_ID
4999 	 --11) Crossdock_type 12) Inspection Status }}
5000          open c_transfer_mol(
5001                              l_mol_res_out(l_loop_index).lpn_id
5002                             ,l_mol_res_out(l_loop_index).inventory_item_id
5003                             ,l_mol_res_out(l_loop_index).lot_number
5004                             ,l_mol_res_out(l_loop_index).item_revision
5005                             ,l_mol_res_out(l_loop_index).from_subinventory_code
5006                             ,l_mol_res_out(l_loop_index).from_locator_id
5007                              -- ,l_mol_res_out(l_loop_index).cost_group_id ???
5008                             ,l_mol_res_out(l_loop_index).project_id
5009                             ,l_mol_res_out(l_loop_index).task_id
5010                             ,l_mol_res_out(l_loop_index).uom_code
5011                             ,l_mol_res_out(l_loop_index).backorder_delivery_detail_id
5012                             ,l_mol_res_out(l_loop_index).crossdock_type
5013                             ,l_mol_res_out(l_loop_index).inspection_status
5014 							,l_new_reference   --13935217
5015                             ,l_new_reference_id --13935217
5016                             );
5017         Fetch c_transfer_mol into l_transfer_mol_rec;
5018         close c_transfer_mol;
5019 
5020 	IF (l_debug = 1) THEN
5021 	   print_debug('MAINTAIN_MOC_CON - Move Order Line Found line Id = '|| l_transfer_mol_rec.line_id,1);
5022 	END IF;
5023 
5024         if l_transfer_mol_rec.line_id is not null
5025         then
5026            -- Move Order Line found
5027            -- Check whether MOL is from the same SOURCE
5028            IF (l_debug = 1) THEN
5029 	      print_debug('MAINTAIN_MOC_CON - Move Order Line Found line Id = '|| l_transfer_mol_rec.line_id,1);
5030            END IF;
5031 
5032            check_reference(
5033                             p_old_reference           => l_transfer_mol_rec.reference
5034                            ,p_old_reference_type_code => l_transfer_mol_rec.reference_type_code
5035                            ,p_old_reference_id        => l_transfer_mol_rec.reference_id
5036                            ,p_new_reference           => l_new_reference
5037                            ,p_new_reference_type_code => l_new_reference_type_code
5038                            ,p_new_reference_id        => l_new_reference_id
5039                            ,x_reference               => l_reference
5040                            ,x_reference_type_code     => l_reference_type_code
5041                            ,x_reference_id            => l_reference_id
5042                            ,x_transaction_type_id     => l_transaction_type_id
5043                            ,x_txn_source_type_id      => l_txn_source_type_id
5044                            ,x_return_status           => x_return_status
5045                            ,x_msg_count               => x_msg_count
5046                            ,x_msg_data                => x_msg_data
5047                           );
5048 
5049            IF (l_debug = 1) THEN
5050                 print_debug('CHECK_REFERENCE - After calling check_reference :'||x_return_status||':'||l_progress,1);
5051                 l_progress := 'WMSINB-45056';
5052            END IF;
5053 
5054            IF (x_return_status <> 'S') THEN
5055               l_progress := 'WMSINB-45058';
5056               RAISE fnd_api.g_exc_error;
5057            END IF;
5058 
5059 
5060 	   --{{
5061 	   --Test the case where a matching MOL is found.  Make sure
5062 	   --that l_mol_res_out(l_loop_index).quantity is in the correct
5063 	   --uom -- It should be because of the cosolidation critieria}}
5064 
5065            --
5066            -- UPDATE THE MOVE ORDER LINE HERE
5067            --
5068            update mtl_txn_request_lines
5069 	     set reference = l_reference
5070 	     ,reference_type_code = l_reference_type_code
5071 	     ,reference_id = l_reference_id
5072 	     ,quantity = quantity + l_mol_res_out(l_loop_index).quantity
5073 	     --Review how are you ensuring that this quantity is in the
5074 	     --right uom
5075 	     ,primary_quantity = primary_quantity + l_mol_res_out(l_loop_index).primary_qty
5076 	     ,secondary_quantity = secondary_quantity + l_mol_res_out(l_loop_index).secondary_quantity
5077 	     ,transaction_type_id = nvl(l_transaction_type_id,transaction_type_id)
5078 	     ,transaction_source_type_id = nvl(l_txn_source_type_id,transaction_source_type_id)
5079              where line_id = l_transfer_mol_rec.line_id
5080 	     ;
5081 
5082            l_progress := 'WMSINB-45060';
5083 
5084            --
5085            -- CANCEL THE OPERATION PLAN
5086            -- IF THE LPN IS LOADED AND TASK IS DISPATCHED
5087            -- WE NEED TO FAIL HERE
5088            --
5089 
5090            l_loaded := 0;
5091 
5092 	   --{{
5093 	   --Try to receive into a LPN that is loaded.  This should have
5094 	   --been validated by the ui already}}
5095            BEGIN
5096                     SELECT 1
5097                     INTO l_loaded
5098                     FROM dual
5099                     WHERE exists
5100                     (SELECT 1
5101                      FROM wms_dispatched_tasks wdt
5102                      , mtl_material_transactions_temp mmtt
5103                      WHERE mmtt.move_order_line_id =  l_transfer_mol_rec.line_id
5104                      AND wdt.transaction_temp_id = mmtt.transaction_temp_id
5105                      AND wdt.status IN (3, 4) -- dispached or loaded
5106                      AND wdt.task_type = 2 -- putaway
5107                      );
5108 
5109                   IF (l_debug = 1) THEN
5110                      print_debug('MAINTAIN_MO_CON - TASK ALREADY LOADED FOR '||l_transfer_mol_rec.line_id || ' FAILURE' ,1);
5111                   END IF;
5112 
5113                   l_progress := 'WMSINB-45063';
5114                   RAISE fnd_api.g_exc_error;
5115 
5116            EXCEPTION
5117              WHEN NO_DATA_FOUND THEN
5118                   l_progress := 'WMSINB-45064';
5119                   null;
5120            END;
5121 
5122 	   --{{
5123 	   --Complete 1 step of a multi-step ATF plan.  Receive into that LPN.
5124 	   --Make sure that the operation instance is cancelled for that LPN.}}
5125            call_atf_api(x_return_status => x_return_status,
5126                             x_msg_data => x_msg_data,
5127                             x_msg_count => x_msg_count,
5128                             x_error_code => l_error_code,
5129                             p_source_task_id => NULL,
5130                             p_activity_type_id => 1,
5131                             p_operation_type_id => NULL,
5132                             p_mol_id => l_transfer_mol_rec.line_id,
5133                             p_atf_api_name => g_atf_api_cancel);
5134 
5135            IF (x_return_status <> g_ret_sts_success) THEN
5136                   IF (l_debug = 1) THEN
5137                      print_debug('MAINTAIN_MO_CON - call_atf_api failed:'||l_transfer_mol_rec.line_id,1);
5138                      l_progress := 'WMSINB-45063';
5139                   END IF;
5140                   --raise error
5141                   l_progress := 'WMSINB-45064';
5142                   RAISE fnd_api.g_exc_error;
5143            END IF;
5144 
5145         Else
5146 
5147            -- Move Order Line Not Found Create Move Order
5148 
5149            IF (l_debug = 1) THEN
5150 	      print_debug('MAINTAIN_MOC_CON - Move Order Line Not Found line Id ',1);
5151            END IF;
5152 
5153            --create mol
5154            inv_rcv_std_rcpt_apis.create_move_order(p_move_order_header_id => l_move_order_header_id
5155                                               ,p_po_line_location_id      => p_po_line_location_id
5156                                               ,p_po_distribution_id       => p_po_distribution_id
5157                                               ,p_shipment_line_id         => p_shipment_line_id
5158                                               ,p_oe_order_line_id         => p_oe_order_line_id
5159                                               ,p_routing                  => p_routing_header_id
5160                                               ,p_lot_control_code         => p_lot_control_code
5161                                               ,p_org_id                   => l_mol_res_out(l_loop_index).organization_id
5162                                               ,p_item_id                  => l_mol_res_out(l_loop_index).inventory_item_id
5163                                               ,p_qty                      => l_mol_res_out(l_loop_index).quantity
5164                                               ,p_uom_code                 => l_mol_res_out(l_loop_index).uom_code
5165                                               ,p_lpn                      => l_mol_res_out(l_loop_index).lpn_id
5166                                               ,p_project_id               => l_mol_res_out(l_loop_index).project_id
5167                                               ,p_task_id                  => l_mol_res_out(l_loop_index).task_id
5168                                               ,p_revision                 => l_mol_res_out(l_loop_index).item_revision
5169                                               ,p_inspect                  => l_mol_res_out(l_loop_index).inspection_status
5170                                               ,p_txn_source_id            => null
5171                                               ,x_status                   => x_return_status
5172                                               ,x_message                  => x_msg_data
5173                                               ,p_transfer_org_id          => l_mol_res_out(l_loop_index).transfer_org_id
5174                                               ,p_wms_process_flag         => 1
5175                                               ,p_lot_number               => l_mol_res_out(l_loop_index).lot_number
5176                                               ,p_secondary_quantity       => l_mol_res_out(l_loop_index).secondary_quantity
5177                                               ,p_secondary_uom            => l_mol_res_out(l_loop_index).secondary_uom
5178                                               ,x_line_id                  => l_move_order_line_id
5179                                               );
5180             IF (l_debug = 1) THEN
5181                  print_debug('MAINTAIN_MO_CON - After calling create_move_order:'||x_return_status||':'||l_progress,1);
5182                  print_debug('MAINTAIN_MO_CON - Move Order Header ID:'||l_move_order_header_id||':'||l_progress,1);
5183                  print_debug('MAINTAIN_MO_CON - Move Order Line ID:'||l_move_order_line_id||':'||l_progress,1);
5184             END IF;
5185 
5186             IF (x_return_status <> 'S') THEN
5187                l_progress := 'WMSINB-45064';
5188                RAISE fnd_api.g_exc_error;
5189             END IF;
5190 
5191            --update mol for the sub and loc
5192 	   --{{
5193 	   --Receive into a RCV sub/loc.  Check MOL has these columns
5194 	   --stamped afterwards}}
5195            UPDATE mtl_txn_request_lines
5196               SET from_subinventory_code = Nvl(p_subinventory,from_subinventory_code)
5197               , from_locator_id = Nvl(p_locator_id, from_locator_id)
5198 	      , backorder_delivery_detail_id = l_mol_res_out(l_loop_index).backorder_delivery_detail_id
5199 	      , crossdock_type = l_mol_res_out(l_loop_index).crossdock_type
5200 	     WHERE header_id = l_move_order_header_id
5201                 and line_id = l_move_order_line_id
5202                 and organization_id = p_org_id
5203                 AND inventory_item_id = p_item_id;
5204 
5205 	   -- Call to UPDATE WDD
5206 	   --Review. Shoudn't this be outside the if mol not found block???
5207 	   --{{
5208 	   --Create xdock reservation for the item.  Do receipt.  Make
5209 	   --sure that WDD is updated with the MOL}}
5210 	   IF (l_mol_res_out(l_loop_index).backorder_delivery_detail_id IS NOT NULL
5211 		and l_mol_res_out(l_loop_index).crossdock_type = 1) THEN --bug 9706800 No need to update wdd for OPM batch/WIP; Update only for Sales/Internal Orders
5212 	      inv_rcv_reservation_util.update_wdd
5213 		(x_return_status => x_return_status
5214 		 ,x_msg_count    => x_msg_count
5215 		 ,x_msg_data     => x_msg_data
5216 		 ,p_wdd_id       => l_mol_res_out(l_loop_index).backorder_delivery_detail_id
5217 		 ,p_released_status => null
5218 		 ,p_mol_id          => l_move_order_line_id
5219 		 );
5220 	   END IF;
5221 
5222 
5223            IF (l_debug = 1) THEN
5224                  print_debug('MAINTAIN_MO_CON - After calling update_wdd '||x_return_status||':'||l_progress,1);
5225                  print_debug('MAINTAIN_MO_CON - Move Order Header ID:'||l_move_order_header_id||':'||l_progress,1);
5226            END IF;
5227 
5228            IF (x_return_status <> 'S') THEN
5229                l_progress := 'WMSINB-45064';
5230                RAISE fnd_api.g_exc_error;
5231            END IF;
5232 
5233 
5234         End if;
5235 
5236 
5237 	l_loop_index := l_mol_res_out.next(l_loop_index);
5238       END LOOP;
5239 
5240       --call upd_empty_mixed_flag
5241       IF p_locator_id IS NOT NULL THEN
5242 	 IF (l_debug = 1) THEN
5243 	    print_debug('MAINTAIN_MO_CON - Calling upd_empty_mixed_flag for	CURRENT sub',1);
5244 	 END IF;
5245 
5246 	 inv_loc_wms_utils.upd_empty_mixed_flag_rcv_loc ( x_return_status  => x_return_status
5247 							  ,x_msg_count    => x_msg_count
5248 							  ,x_msg_data     => x_msg_data
5249 							  ,p_subinventory => p_subinventory
5250 							  ,p_locator_id   => p_locator_id
5251 							  ,p_org_id       => p_org_id
5252 							  );
5253 	 IF (x_return_status <> 'S') THEN
5254 	    l_progress := 'WMSINB-45067';
5255       -- Bug 5393727: do not raise an exception if locator API returns an error
5256 	    -- RAISE fnd_api.g_exc_error;
5257 	 END IF;
5258 
5259 	 -- update curr capacity
5260 	 IF (l_debug = 1) THEN
5261 	     print_debug('MAINTAIN_MO_CON - Calling update_loc_curr_capacity FOR CURRENT sub',1);--bug13451495
5262 	 END IF;
5263 
5264 	 --bug13451495
5265 	 inv_loc_wms_utils.update_loc_current_capacity
5266 	   ( x_return_status           => x_return_status
5267 	     ,x_msg_count               => x_msg_count
5268 	     ,x_msg_data                => x_msg_data
5269 	     ,p_organization_id         => p_org_id
5270 	     ,p_inventory_location_id   => p_locator_id
5271 	     ,p_inventory_item_id       => p_item_id
5272 	     ,p_primary_uom_flag        => 'N'
5273 	     ,p_transaction_uom_code    => p_uom_code
5274 	     ,p_quantity                => p_qty
5275 	     ,p_issue_flag              => 'N'
5276 	     );
5277 	 IF (x_return_status <> 'S') THEN
5278 	    l_progress := 'WMSINB-45070';
5279 	    -- Bug 5393727: do not raise an exception if locator API returns an error
5280 	    -- RAISE fnd_api.g_exc_error;
5281 	 END IF;
5282       END IF; --IF p_subinventory IS NOT NULL THEN
5283 
5284 --pregeneration
5285 --Review. Move this pregeneration call to complete_lpn_group !!!
5286 -- R12 commented this call
5287 -- As this has been moved to complete_lpn_group procedure
5288 -- l_call_pregeneration := TRUE;
5289 
5290 --     IF (p_transfer_lpn_id IS NULL) THEN
5291 --	 l_call_pregeneration := FALSE;
5292 --      ELSE
5293 --	 IF p_lot_control_code > 1 THEN
5294 --	    IF p_lot_number IS NULL THEN
5295 --	       l_call_pregeneration := FALSE;
5296 --	    END IF;
5297 --	  ELSIF p_serial_number_control_code IN (2,5,6) THEN
5298 --	    BEGIN
5299 --	       SELECT '1'
5300 --		 INTO l_dummy
5301 --		 FROM mtl_serial_numbers_temp
5302 --		 WHERE product_code = 'RCV'
5303 --		 AND product_transaction_id = p_rti_id
5304 --		 AND ROWNUM < 2;
5305 --	    EXCEPTION
5306 --	       WHEN OTHERS THEN
5307 --		  l_call_pregeneration := FALSE;
5308 --	    END;
5309 --	 END IF;
5310 --    END IF; --IF (p_lpn_id IS NULL) THEN
5311 
5312 --call pregeneration
5313 --     IF l_call_pregeneration THEN
5314 --	 IF (l_debug = 1) THEN
5315 --	    print_debug('MAINTAIN_MO_CON - Before calling start_pregenerate_program:'||l_progress,1);
5316 --	    l_progress := 'WMSINB-45072';
5317 --	 END IF;
5318 --	 wms_putaway_suggestions.start_pregenerate_program
5319 --	   (p_org_id => p_org_id,
5320 --	    p_lpn_id => p_transfer_lpn_id,
5321 --	    x_return_status => x_return_status,
5322 --	    x_msg_count => x_msg_count,
5323 --	    x_msg_data => x_msg_data);
5324 --
5325 --	 IF (l_debug = 1) THEN
5326 --	    print_debug('MAINTAIN_MO_CON - After calling start_pregenerate_program:'||x_return_status||':'||l_progress,1);
5327 --	    l_progress := 'WMSINB-45073';
5328 --	 END IF;
5329 --
5330 --	 IF (x_return_status <> 'S') THEN
5331 --	    x_return_status := 'S';
5332 --  	 END IF;
5333 -- END IF; --IF l_call_pregeneration THEN
5334 -- R12
5335 -- Commented the above call
5336 
5337    END IF; --IF l_transaction_type = 'RECEIVE' THEN
5338 
5339    IF l_transaction_type IN ('ACCEPT','REJECT','TRANSFER') THEN
5340       IF (l_debug = 1) THEN
5341 	 print_debug('MAINTAIN_MO_CON - CASE FOR ACCEP, TREJECT,TRANSFER',1);
5342       END IF;
5343 
5344 
5345       /* Bug 6830559 */
5346       IF (p_project_id IS NULL) THEN
5347 	 IF (p_po_distribution_id IS NOT NULL) THEN
5348 	    BEGIN
5349 	       SELECT project_id,
5350 		 Nvl(task_id, -1)
5351 		 INTO l_project_id,
5352 		 l_task_id
5353 		 FROM po_distributions_all
5354 		 WHERE po_distribution_id = p_po_distribution_id;
5355 	    EXCEPTION
5356 	       WHEN no_data_found THEN
5357 		  l_project_id := NULL;
5358 		  l_task_id := NULL;
5359 	    END ;
5360          ELSIF (p_po_line_location_id IS NOT NULL) then
5361             inv_rcv_std_rcpt_apis.get_project_task(
5362                  p_po_line_location_id     => p_po_line_location_id
5363                , p_oe_order_line_id        => NULL
5364                , x_project_id              => l_project_id
5365                , x_task_id                 => l_task_id
5366             );
5367 	 END IF;
5368        ELSE --IF (p_project_id IS NULL) THEN
5369 		  l_project_id := p_project_id;
5370 		  l_task_id := p_task_id;
5371        END IF; --IF (p_project_id IS NULL) THEN
5372 
5373 
5374 
5375       --{{
5376       --Test:
5377       --1) mobile putaway (there is always have MMTT)
5378       --2) Desktop transfer/deliver (turn pregen off so there is no MMTT)
5379       --3) Mobile inspect (there may or may not have MMTT)
5380       --4) Desktop inspect }}
5381 
5382       IF (p_mmtt_temp_id IS NOT NULL) THEN
5383 
5384 	 OPEN c_mol_mmtt(p_mmtt_temp_id,
5385                          p_item_id,
5386                          p_lpn_id,
5387 			 p_lot_number,
5388                          p_revision,
5389                          p_from_subinventory,
5390                          p_from_locator_id,
5391                          l_project_id, -- p_project_id, /* Bug 6830559 */
5392                          l_task_id, -- p_task_id, /* Bug 6830559 */
5393                          l_from_mol_inspection_status
5394                         );
5395        ELSE
5396 	 OPEN c_mol_no_mmtt(
5397                             p_item_id,
5398                             p_lpn_id,
5399 			    p_lot_number,
5400                             p_revision,
5401                             p_from_subinventory,
5402                             p_from_locator_id,
5403                             -- ,p_cost_group_id ????
5404                             l_project_id, -- p_project_id, -- Bug 6830559
5405                             l_task_id, -- p_task_id, -- Bug 6830559
5406                             l_from_mol_inspection_status ,
5407                             p_uom_code,
5408 							l_new_reference_id  --14133874
5409                            );
5410       END IF;
5411 
5412       --Maneesh
5413       l_mol_res_in(1).transaction_type       := l_transaction_type;
5414       l_mol_res_in(1).organization_id        := p_org_id;
5415       l_mol_res_in(1).lpn_id                 := p_transfer_lpn_id;
5416       l_mol_res_in(1).inventory_item_id      := p_item_id;
5417       l_mol_res_in(1).lot_number             := p_lot_number;
5418       l_mol_res_in(1).item_revision          := p_revision;
5419       l_mol_res_in(1).from_subinventory_code := p_subinventory;
5420       l_mol_res_in(1).from_locator_id        := p_locator_id;
5421       -- l_mol_res_in(1).cost_group_id          := p_cost_group_id; ????
5422       l_mol_res_in(1).project_id             := l_project_id;
5423       l_mol_res_in(1).task_id                := l_task_id;
5424       l_mol_res_in(1).uom_code               := p_uom_code;
5425       l_mol_res_in(1).backorder_delivery_detail_id := null;
5426       l_mol_res_in(1).crossdock_type         := null;
5427       l_mol_res_in(1).transfer_org_id        := l_transfer_org_id;
5428       l_mol_res_in(1).secondary_uom          := p_sec_uom;
5429       l_mol_res_in(1).inspection_status      := l_transfer_inspection_status ;
5430 
5431       -- CHANGES FOR  FROM MOL AND TRANSFER MOL POINTS TO THE SAME MOL
5432       -- IF FROM AND TRANSFER MOL POINTS TO THE SAME MOL LINE i,e NO
5433       -- CHANGES IN THE CONSOLIDATING CRITERIA THEN DON'T DO ANYTHING
5434       -- FOR THE MOVE ORDER LINE FOR THE ABOVE TXNS.
5435 
5436       IF (  nvl(l_mol_res_in(1).lpn_id,-1) = nvl(p_lpn_id ,-1)
5437         and nvl(l_mol_res_in(1).inventory_item_id,-1) = nvl(p_item_id,-1)
5438         and nvl(l_mol_res_in(1).lot_number,'@$#_') = nvl(p_lot_number,'@$#_')
5439         and nvl(l_mol_res_in(1).item_revision,'@$#_') = nvl(p_revision,'@$#_')
5440         and nvl(l_mol_res_in(1).from_subinventory_code,'@$#_') =  nvl(p_from_subinventory,'@$#_')
5441         and nvl(l_mol_res_in(1).from_locator_id,-1) = nvl(p_from_locator_id,-1)
5442         and nvl(l_mol_res_in(1).project_id,-1) = nvl(l_project_id,-1) /* Bug 6830559 */
5443         and nvl(l_mol_res_in(1).task_id,-1) = nvl(l_task_id,-1) /* Bug 6830559 */
5444         and l_mol_res_in(1).uom_code = p_uom_code
5445         and nvl(l_mol_res_in(1).inspection_status,-1) =  nvl(l_from_mol_inspection_status,-1) )
5446      THEN
5447         -- CONSOLIDATING CRITERIA SAME NO CHANGES FOR MOL LINE FOR THIS CASE.
5448         l_update_or_close := 'N';
5449         IF (l_debug = 1) THEN
5450             print_debug('MAINTAIN_MO_CON - UPDATE OR CLOSE: '||l_update_or_close,1);
5451         END IF;
5452      END IF;
5453 
5454 
5455       --{{
5456       --Test cases where there is or is not a MOL line}}
5457 
5458       IF l_update_or_close = 'N' THEN
5459         IF (l_debug = 1) THEN
5460             print_debug('MAINTAIN_MO_CON - NO NEED TO PROCESS FOR THIS CASE',1);
5461         END IF;
5462       ELSE
5463         IF (l_debug = 1) THEN
5464             print_debug('MAINTAIN_MO_CON - OPENING TRANSFER MOL FOR THIS CASE',1);
5465         END IF;
5466         open c_transfer_mol(
5467 			  l_mol_res_in(1).lpn_id
5468 			  ,l_mol_res_in(1).inventory_item_id
5469 			  ,l_mol_res_in(1).lot_number
5470 			  ,l_mol_res_in(1).item_revision
5471 			  ,l_mol_res_in(1).from_subinventory_code
5472 			  ,l_mol_res_in(1).from_locator_id
5473 			  ,l_mol_res_in(1).project_id
5474 			  ,l_mol_res_in(1).task_id
5475 			  ,l_mol_res_in(1).uom_code
5476 			  ,l_mol_res_in(1).backorder_delivery_detail_id
5477 			  ,l_mol_res_in(1).crossdock_type
5478 			  ,l_mol_res_in(1).inspection_status
5479 			  , l_new_reference  --13935217
5480 			  , l_new_reference_id  --13935217
5481 			  );
5482 
5483         Fetch c_transfer_mol into l_transfer_mol_rec;
5484         close c_transfer_mol;
5485 
5486         IF l_transfer_mol_rec.line_id IS NOT NULL THEN
5487          	 l_update_or_close := 'C';
5488 
5489 	 --Move the check to here so that it is done before we
5490 	 --tie MMTT/WDT to the transfer MOL.  This is needed
5491 	 --because we won't call complete_operation_instance
5492 	 --for the MMTT until the end of the API.  Therefore,
5493 	 --the check below would fail if it is done after we
5494 	 --tie MMTT/WDT
5495 
5496 	 --Also, this check is not needed because we should allow
5497 	 --loading materials into a loaded LPN
5498 	   IF (l_transaction_type <> 'TRANSFER') THEN
5499 	      l_loaded := 0;
5500 
5501               BEGIN
5502 	         SELECT 1
5503 	  	 INTO l_loaded
5504 	  	 FROM dual
5505 	  	 WHERE exists
5506 	  	 (SELECT 1
5507 	  	  FROM wms_dispatched_tasks wdt
5508 	  	  , mtl_material_transactions_temp mmtt
5509 	  	  WHERE mmtt.move_order_line_id =  l_transfer_mol_rec.line_id
5510 	  	  AND wdt.transaction_temp_id = mmtt.transaction_temp_id
5511 	  	  AND wdt.status IN (3, 4) -- dispached or loaded
5512 	  	  AND wdt.task_type = 2 -- putaway
5513 		  );
5514 
5515 	         IF (l_debug = 1) THEN
5516 	  	  print_debug('MAINTAIN_MO_CON - TASK ALREADY LOADED FOR '||l_transfer_mol_rec.line_id || ' FAILURE ' ,1);
5517 	         END IF;
5518 
5519 	         l_progress := 'WMSINB-45129';
5520 	         RAISE fnd_api.g_exc_error;
5521 
5522 	      EXCEPTION
5523 	         WHEN NO_DATA_FOUND THEN
5524 	  	  l_progress := 'WMSINB-45130';
5525 	  	  null;
5526 	      END;
5527 	   END IF;
5528 
5529         ELSE
5530   	   l_update_or_close := 'U';
5531         END IF;
5532       END IF; -- IF l_update_or_close = 'N' THEN
5533 
5534       IF (l_debug = 1) THEN
5535 	 print_debug('MAINTAIN_MO_CON - UPDATE OR CLOSE: '||l_update_or_close,1);
5536       END IF;
5537 
5538 
5539     IF l_update_or_close = 'N' THEN
5540        --
5541        IF (l_debug = 1) THEN
5542 	 print_debug('MAINTAIN_MO_CON - NO PROCESSING!!',1);
5543          print_debug('MAINTAIN_MO_CON - UPDATING WMS_PROCESS_FLAG TO 1',1);
5544        END IF;
5545         -- bug 8938083 added code to update wms_process_flag to 1
5546 	LOOP
5547 	 IF (p_mmtt_temp_id IS NOT NULL) THEN
5548 	    FETCH c_mol_mmtt INTO l_mol_rec;
5549 	    EXIT WHEN c_mol_mmtt%notfound;
5550 	  ELSE
5551 	       FETCH c_mol_no_mmtt INTO l_mol_rec;
5552 	       EXIT WHEN c_mol_no_mmtt%notfound;
5553 	 END IF;
5554          UPDATE mtl_txn_request_lines
5555          SET wms_process_flag = 1
5556          WHERE line_id = l_mol_rec.line_id;
5557        END LOOP;
5558 
5559     ELSE
5560 
5561       l_remaining_primary_quantity := p_primary_quantity;
5562       l_remaining_secondary_quantity :=p_sec_qty;--bug12790652
5563       --{{
5564       --For cases where there is no MMTT, make sure that the correct MOL is returned.  }}
5565 
5566 
5567       LOOP
5568 	 IF (p_mmtt_temp_id IS NOT NULL) THEN
5569 	    FETCH c_mol_mmtt INTO l_mol_rec;
5570 	    EXIT WHEN c_mol_mmtt%notfound;
5571 	  ELSE
5572 	       FETCH c_mol_no_mmtt INTO l_mol_rec;
5573 	       EXIT WHEN c_mol_no_mmtt%notfound;
5574 	 END IF;
5575 
5576 	 IF (l_debug = 1) THEN
5577 	    print_debug('MAINTAIN_MO_CON - REMAINING QUANTITY:'||l_remaining_primary_quantity||':'||l_progress,1);
5578 	    print_debug('MAINTAIN_MO_CON - REMAINING SECONDARY QUANTITY:'||l_remaining_secondary_quantity||':'||l_progress,1);--bug12790652
5579 	    print_debug('MAINTAIN_MO_CON - LINE_ID:'||l_mol_rec.line_id||' WMS_PROCESS_FLAG:'||l_mol_rec.wms_process_flag,1);
5580 	    l_progress := 'WMSINB-45075';
5581 	 END IF;
5582 
5583 	 --BUG 4766810: Always add before rounding.  Also, when comparing
5584 	 -- for equality, check if the two number differs by 0.000005
5585 	 -- (round to 5 digits).
5586 	 IF (l_mol_rec.uom_code <> p_primary_uom_code) THEN
5587 	 --commenting below code for bug 13484877--Here the primary mol qty is derived by multiplying the conv factor with trx qty
5588      --But if the trx qty is a rounded off qty, then qty mistmatch will happen. So to avoid that,the  l_mol_qty_in_puom
5589      --can be direectly derived from  l_mol_rec.primary_quantity
5590 	    l_conversion_rate := inv_rcv_cache.get_conversion_rate(l_mol_rec.inventory_item_id,
5591 								   l_mol_rec.uom_code,
5592 								   p_primary_uom_code);
5593 	    --l_mol_qty_in_puom := l_mol_rec.quantity * l_conversion_rate;
5594 		--Added for bug 13484877 START
5595 		l_mol_qty_in_puom := l_mol_rec.primary_quantity;
5596 		IF (l_debug = 1) THEN
5597 	       print_debug('MAINTAIN_MO - MOL l_mol_rec.primary_quantity:'||l_mol_rec.primary_quantity||':'||l_progress,1);
5598 	    END IF;
5599 		--Added for bug 13484877 END
5600 	  ELSE
5601 	    l_mol_qty_in_puom := l_mol_rec.quantity;
5602 	    l_conversion_rate := 1;
5603 	 END IF;
5604 
5605 	 IF (l_debug = 1) THEN
5606 	    print_debug('MAINTAIN_MO - MOL QTY IN PUOM:'||l_mol_qty_in_puom||':'||l_progress,1);
5607 	 END IF;
5608 
5609          l_backorder_delivery_detail_id := null;
5610          l_mol_consumed_full            := 0;
5611 
5612          -- SET THE REFERENCE INFORMATION HERE
5613          l_new_reference           := l_mol_rec.reference;
5614          l_new_reference_type_code := l_mol_rec.reference_type_code;
5615          l_new_reference_id        := l_mol_rec.reference_id;
5616 
5617 	 --BUG 4766810, always round to 5 digits when comparing because
5618 	 --quantity is stored in 5 digits in Inventory
5619 	 IF Round(l_mol_qty_in_puom,5) <= Round(l_remaining_primary_quantity,5) THEN
5620 
5621             -- ***************************************************
5622             -- IF THE LINE IS NOT BACKORDERD THEN CLOSE THE LINE
5623             -- IF THE LINE IS BACKORDERD THEN UPDATED THE LINE
5624             -- ***************************************************
5625 	    IF (l_debug = 1) THEN
5626 	       print_debug('MAINTAIN_MO_CON - mol consumed full ',1);
5627 	    END IF;
5628 
5629             l_backorder_delivery_detail_id := l_mol_rec.backorder_delivery_detail_id;
5630             l_mol_consumed_full            := 1;
5631 
5632             IF (l_backorder_delivery_detail_id is not NULL AND l_transaction_type = 'REJECT') THEN
5633 	       IF (l_debug = 1) THEN
5634 		  print_debug('Reject xdock materials.  Calling inv_reservation_pub.delete_reservation',4);
5635 	       END IF;
5636 
5637 	       l_rsv_rec.demand_source_line_detail := l_backorder_delivery_detail_id;
5638 	       l_rsv_rec.organization_id           := p_org_id;
5639 	       l_rsv_rec.inventory_item_id         := l_mol_rec.inventory_item_id;
5640 
5641 	       inv_reservation_pub.delete_reservation
5642 		 (p_api_version_number       => 1.0
5643 		  , x_return_status          => l_return_status
5644 		  , x_msg_count              => l_msg_count
5645 		  , x_msg_data               => l_msg_data
5646 		  , p_rsv_rec                => l_rsv_rec
5647 		  , p_serial_number          => l_dummy_serial
5648 		  );
5649 
5650 	       IF (l_debug = 1) THEN
5651 		  print_debug('Returned from inv_reservation_pub.delete_reservation',4);
5652 		  print_debug('x_return_status =>'||l_return_status,4);
5653 	       END IF;
5654 
5655 	       IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
5656 		  IF (l_debug = 1) THEN
5657 		     print_debug('x_msg_data:  '||l_msg_data,4);
5658 		     print_debug('x_msg_count: '||l_msg_count,4);
5659 			 print_debug('SQLCODE:'||SQLCODE||' SQLERRM:'||SQLERRM,4);
5660 			 print_debug('Raising Exception!!!',4);
5661 		  END IF;
5662 		  l_progress := '@@@';
5663 		  RAISE fnd_api.g_exc_unexpected_error;
5664 	       END IF;
5665 
5666 	       l_backorder_delivery_detail_id := NULL;
5667 	    END IF; --IF (l_backorder_delivery_detail_id is not NULL AND l_transaction_type = 'REJECT') THEN
5668 
5669 	    IF l_backorder_delivery_detail_id IS NOT NULL THEN
5670 		l_progress := 'WMSINB-45078';
5671 	        --update the mol
5672 
5673 	        IF (l_debug = 1) THEN
5674 	           print_debug('MAINTAIN_MO_CON - l_backorder_delivery_detail_id = '|| l_backorder_delivery_detail_id,1);
5675 	        END IF;
5676 
5677 		--Update quantity with the quantity converted to the UOM in the RTI.  This is changed so
5678 		--that the we honor the UOM entered by the user during
5679 		--Transfer
5680 		IF (l_mol_rec.uom_code <> p_uom_code) THEN
5681 		   l_tmp_qty := inv_rcv_cache.convert_qty(l_mol_rec.inventory_item_id
5682 							  ,l_mol_rec.txn_qty
5683 							  ,l_mol_rec.uom_code
5684 							  ,p_uom_code);
5685 		   l_tmp_qty_dtld := inv_rcv_cache.convert_qty(l_mol_rec.inventory_item_id
5686 							       ,l_mol_rec.quantity_detailed
5687 							       ,l_mol_rec.uom_code
5688 							       ,p_uom_code);
5689 		   l_tmp_qty_dlvd := inv_rcv_cache.convert_qty(l_mol_rec.inventory_item_id
5690 							       ,l_mol_rec.quantity_delivered
5691 							       ,l_mol_rec.uom_code
5692 							       ,p_uom_code);
5693 		   l_tmp_uom_code := p_uom_code;
5694 		 ELSE
5695 		   l_tmp_qty := l_mol_rec.txn_qty;
5696 		   l_tmp_qty_dtld := l_mol_rec.quantity_detailed;
5697 		   l_tmp_qty_dlvd := l_mol_rec.quantity_delivered;
5698 		   l_tmp_uom_code := l_mol_rec.uom_code;
5699 		END IF;
5700 
5701 	        IF (l_debug = 1) THEN
5702 	           print_debug('MAINTAIN_MO_CON - l_tmp_qty:'||l_tmp_qty,4);
5703 		   print_debug('MAINTAIN_MO_CON - l_tmp_qty_dtld:'||l_tmp_qty_dtld,4);
5704 		   print_debug('MAINTAIN_MO_CON - l_tmp_qty_dlvd:'||l_tmp_qty_dlvd,4);
5705 		   print_debug('MAINTAIN_MO_CON - l_tmp_uom_code:'||l_tmp_uom_code,4);
5706 	        END IF;
5707 
5708 		UPDATE mtl_txn_request_lines
5709 	          SET inspection_status = Decode(l_transaction_type,'ACCEPT',2,'REJECT',3,inspection_status)
5710 	          , lpn_id = p_transfer_lpn_id
5711 		  , quantity = l_tmp_qty
5712 	          , quantity_detailed = Decode(l_transaction_type,'TRANSFER',l_tmp_qty_dtld,NULL)
5713 	          , quantity_delivered = Decode(l_transaction_type,'TRANSFER',l_tmp_qty_dlvd,NULL)
5714 		  , uom_code = l_tmp_uom_code
5715                   -- OPMConvergence
5716 	          , secondary_quantity_detailed = Decode(l_transaction_type,'TRANSFER',secondary_quantity_detailed,NULL)
5717                   -- OPMConvergence
5718 	          , lot_number = p_lot_number
5719 	          , revision = p_revision
5720 	          , from_subinventory_code = Nvl(p_subinventory, from_subinventory_code)
5721 	          , from_locator_id = Nvl(p_locator_id, from_locator_id)
5722 	          , wms_process_flag = 1
5723 	          WHERE line_id = l_mol_rec.line_id;
5724             else
5725 	        IF (l_debug = 1) THEN
5726 	           print_debug('MAINTAIN_MO_CON - backorder_delivery_detail_id is null ',1);
5727 	        END IF;
5728 		l_progress := 'WMSINB-45079';
5729 		--If p_mmtt_temp_id is not null then the move order line should
5730 		--not be closed because this unnecessarily leads to
5731 		--cancelling of operation plan. The line should be closed
5732 		--if and only if there is a transfer mol present with the
5733 		--same consolidation criteria. Otherwise it should be
5734 		--updated just like the crossdock mols.
5735 		--Add an extra parameter to transfer_mol cursor. This new
5736 		--parameter will be the current mol id. Transfer mol cursor
5737 		--should not pickup the lines which have line_id = new
5738 		--prameter. Open the transfer mol cursor
5739 
5740 		IF (l_update_or_close = 'C') THEN
5741 
5742 	           IF (l_debug = 1) THEN
5743 	              print_debug('MAINTAIN_MO_CON - before updating mol update or close = C ',1);
5744 	           END IF;
5745 
5746 		   UPDATE mtl_txn_request_lines
5747 		     SET   line_status = inv_globals.G_TO_STATUS_CLOSED
5748 		     , quantity = Nvl(quantity_delivered,0)
5749 		     , quantity_detailed = quantity_delivered
5750 		     , secondary_quantity_detailed = SECONDARY_QUANTITY_DELIVERED
5751 		     --BDD_ID will get NULL out for REJECT cases
5752 		     , backorder_delivery_detail_id = l_backorder_delivery_detail_id
5753 		     , crossdock_type = Decode(l_backorder_delivery_detail_id,NULL,NULL,crossdock_type)
5754 		     , wms_process_flag = 1
5755 		     WHERE line_id = l_mol_rec.line_id;
5756 
5757 		 ELSE
5758 
5759 		   --Update quantity with the quantity converted to the UOM in the RTI.  This is changed so
5760 		   --that the we honor the UOM entered by the user during
5761 		   --Transfer
5762 		   IF (l_mol_rec.uom_code <> p_uom_code) THEN
5763 		   -- Bug 13484877 Start
5764 		        IF (p_primary_uom_code = p_uom_code) THEN
5765 					  l_tmp_qty := l_mol_rec.primary_quantity;
5766 					  IF (l_debug = 1) THEN
5767 							print_debug('MAINTAIN_MO_CON - l_tmp_qty derived from l_mol_rec.primary_quantity'|| l_tmp_qty,1);
5768 					  END IF;
5769                 ELSE   -- End Bug 13484877
5770 					  l_tmp_qty := inv_rcv_cache.convert_qty(l_mol_rec.inventory_item_id
5771 										 ,l_mol_rec.txn_qty
5772 										 ,l_mol_rec.uom_code
5773 										 ,p_uom_code);
5774 				END IF; -- 13484877
5775 		      l_tmp_qty_dtld := inv_rcv_cache.convert_qty(l_mol_rec.inventory_item_id
5776 								  ,l_mol_rec.quantity_detailed
5777 								  ,l_mol_rec.uom_code
5778 								  ,p_uom_code);
5779 		      l_tmp_qty_dlvd := inv_rcv_cache.convert_qty(l_mol_rec.inventory_item_id
5780 								  ,l_mol_rec.quantity_delivered
5781 								  ,l_mol_rec.uom_code
5782 								  ,p_uom_code);
5783 		      l_tmp_uom_code := p_uom_code;
5784 		    ELSE
5785 		      l_tmp_qty := l_mol_rec.txn_qty;
5786 		      l_tmp_qty_dtld := l_mol_rec.quantity_detailed;
5787 		      l_tmp_qty_dlvd := l_mol_rec.quantity_delivered;
5788 		      l_tmp_uom_code := l_mol_rec.uom_code;
5789 		   END IF;
5790 
5791 		   IF (l_debug = 1) THEN
5792 		      print_debug('MAINTAIN_MO_CON - l_tmp_qty:'||l_tmp_qty,4);
5793 		      print_debug('MAINTAIN_MO_CON - l_tmp_qty_dtld:'||l_tmp_qty_dtld,4);
5794 		      print_debug('MAINTAIN_MO_CON - l_tmp_qty_dlvd:'||l_tmp_qty_dlvd,4);
5795 		      print_debug('MAINTAIN_MO_CON - l_tmp_uom_code:'||l_tmp_uom_code,4);
5796 		   END IF;
5797 
5798 	           IF (l_debug = 1) THEN
5799 	              print_debug('MAINTAIN_MO_CON - before updating mol update or clode <> C ',1);
5800 	           END IF;
5801 
5802 		   UPDATE mtl_txn_request_lines
5803 		     SET inspection_status = Decode(l_transaction_type,'ACCEPT',2,'REJECT',3,inspection_status)
5804 		     , lpn_id = p_transfer_lpn_id
5805 		     , quantity = l_tmp_qty
5806 		     , quantity_detailed = Decode(l_transaction_type,'TRANSFER',l_tmp_qty_dtld,NULL)
5807 		     , quantity_delivered = l_tmp_qty_dlvd
5808 		     , uom_code = l_tmp_uom_code
5809 		     -- OPMConvergence
5810 		     , secondary_quantity_detailed = Decode(l_transaction_type,'TRANSFER',secondary_quantity_detailed,NULL)
5811 		     -- OPMConvergence
5812 		     , lot_number = p_lot_number
5813 		     , revision = p_revision
5814 		     , from_subinventory_code = Nvl(p_subinventory, from_subinventory_code)
5815 		     , from_locator_id = Nvl(p_locator_id, from_locator_id)
5816 		     --BDD_ID will get NULL out for REJECT cases
5817 		     , backorder_delivery_detail_id = l_backorder_delivery_detail_id
5818 		     , crossdock_type = Decode(l_backorder_delivery_detail_id,NULL,NULL,crossdock_type)
5819 		     , reason_id = l_reason_id -- Bug No. 9099299
5820                      , wms_process_flag = 1
5821 		     WHERE line_id = l_mol_rec.line_id;
5822 		END IF;
5823 
5824             end if; --  if l_backorder_delivery_detail_id  is not null
5825 
5826 	    l_remaining_primary_quantity := l_remaining_primary_quantity - l_mol_qty_in_puom;
5827 	    l_remaining_secondary_quantity := l_remaining_secondary_quantity - l_mol_rec.secondary_quantity_2;--bug12790652
5828 	    -- Bug 5632202 : Set l_remaining_primary_quantity to zero if it differs from MOL
5829 	    IF (l_debug = 1) THEN
5830 	       print_debug('MAINTAIN_MO_CON -l_remaining_primary_quantity :'||l_remaining_primary_quantity,4);	--bug12790652
5831 	       print_debug('MAINTAIN_MO_CON -l_remaining_secondary_quantity:'||l_remaining_secondary_quantity,4);--bug12790652
5832 	    END IF;--               quantity in sixth decimal place
5833 
5834 	    IF trunc(( l_remaining_primary_quantity/ l_conversion_rate ),5) = 0 THEN
5835 	      l_remaining_primary_quantity := 0;
5836 	      l_remaining_secondary_quantity :=0;--bug12790652
5837 	      IF (l_debug = 1) THEN
5838 		print_debug('MAINTAIN_MO_CON - Setting l_remaining_primary_quantity to zero',1);
5839 	      END IF;
5840 	    END IF;
5841 
5842 	    --cancel_operation_instance should be called only if
5843 	    --p_mmtt_temp_id is NULL
5844 	    IF (p_mmtt_temp_id IS NULL) THEN
5845 	       IF (l_debug = 1) THEN
5846 		  print_debug('MAINTAIN_MO_CON - calling call_atf_api:'||l_mol_rec.line_id,1);
5847 		  l_progress := 'WMSINB-45080';
5848 	       END IF;
5849 
5850 	       call_atf_api(x_return_status => x_return_status,
5851 			    x_msg_data => x_msg_data,
5852 			    x_msg_count => x_msg_count,
5853 			    x_error_code => l_error_code,
5854 			    p_source_task_id => NULL,
5855 			    p_activity_type_id => 1,
5856 			    p_operation_type_id => NULL,
5857 			    p_mol_id => l_mol_rec.line_id,
5858 			    p_atf_api_name => g_atf_api_cancel);
5859 
5860 	       IF (x_return_status <> g_ret_sts_success) THEN
5861 		  IF (l_debug = 1) THEN
5862 		     print_debug('MAINTAIN_MO - call_atf_api failed:'||l_mol_rec.line_id,1);
5863 		     l_progress := 'WMSINB-45085';
5864 		  END IF;
5865 		  --raise error
5866 		  l_progress := 'WMSINB-45090';
5867 		  RAISE fnd_api.g_exc_error;
5868 	       END IF;
5869 	    END IF;
5870 	  ELSE --IF  l_mol_qty_in_puom <= l_remaining_primary_quantity THEN
5871 	    --split_mol
5872 
5873 	    IF (l_debug = 1) THEN
5874 	       print_debug('MAINTAIN_MO_CON - CALLING SPLIT_MO:'||l_remaining_primary_quantity||':'||l_progress,1);
5875 	       print_debug('MAINTAIN_MO_CON - CALLING SPLIT_MO:'||l_remaining_secondary_quantity||':'||l_progress,1);--bug12790652
5876 	       l_progress := 'WMSINB-45108';
5877 	    END IF;
5878 
5879 	    l_mo_split_tb(1).prim_qty := l_remaining_primary_quantity;
5880             -- OPMConvergence
5881             -- Do we need to assign secondary quantity too ?
5882             -- OPMConvergence
5883 	    l_mo_split_tb(1).sec_qty  := l_remaining_secondary_quantity;--bug12790652
5884 	    l_mo_split_tb(1).line_id := NULL;
5885 
5886 	    IF (l_debug = 1) THEN
5887 	       print_debug('MAINTAIN_MO - Finally Calling split_mo',1);
5888 	       l_progress := 'WMSINB-45110';
5889 	    END IF;
5890 
5891 	    IF p_mmtt_temp_id IS NOT NULL THEN
5892 	       -- Call split mo with operation_type DELIVER
5893 	       -- This will split the MO and tied the mmtt
5894 	       -- to the new MO
5895 	       inv_rcv_integration_apis.split_mo
5896 		 (p_orig_mol_id => l_mol_rec.line_id,
5897 		  p_mo_splt_tb => l_mo_split_tb,
5898 		  p_operation_type => 'DELIVER',
5899 		  p_txn_header_id => p_mmtt_temp_id,
5900 		  x_return_status => x_return_status,
5901 		  x_msg_count => x_msg_count,
5902 		  x_msg_data => x_msg_data);
5903 	     ELSE
5904 	       inv_rcv_integration_apis.split_mo
5905 		 (p_orig_mol_id => l_mol_rec.line_id,
5906 		  p_mo_splt_tb => l_mo_split_tb,
5907 		  x_return_status => x_return_status,
5908 		  x_msg_count => x_msg_count,
5909 		  x_msg_data => x_msg_data);
5910 	    END IF;
5911 
5912 	    IF (x_return_status <> 'S') THEN
5913 	       l_progress := 'WMSINB-45112';
5914 	       RAISE fnd_api.g_exc_error;
5915 	    END IF;
5916 
5917 
5918 	    IF (l_debug = 1) THEN
5919 	       print_debug('MAINTAIN_MO_CON - NEW LINE ID:'||l_mo_split_tb(1).line_id||':'||l_progress,1);
5920 	       l_progress := 'WMSINB-45114';
5921 	    END IF;
5922 
5923 
5924             l_mol_consumed_full            := 0;
5925             l_split_qty                    := 0;
5926             l_split_sec_qty                := 0;
5927 
5928             BEGIN
5929                   select  backorder_delivery_detail_id
5930                          ,(mtrl.quantity - Nvl(mtrl.quantity_delivered, 0))
5931                          ,(mtrl.secondary_quantity - Nvl(mtrl.secondary_quantity_delivered, 0))
5932 			 ,uom_code -- bug8283511
5933                     into l_backorder_delivery_detail_id
5934                          ,l_split_qty
5935 			 ,l_split_sec_qty
5936 			 ,l_uom_code -- bug8283511
5937                     from MTL_TXN_REQUEST_LINES mtrl
5938                    where mtrl.line_id = l_mo_split_tb(1).line_id;
5939 
5940 	       l_progress := 'WMSINB-45115';
5941 	       IF (l_debug = 1) THEN
5942 	           print_debug('MAINTAIN_MO_CON - CHECK WHETHER SPLITTED LINE IS BACKORDERD backorder_delivery_detail_id :'||l_backorder_delivery_detail_id,1);
5943 	       END IF;
5944 
5945             EXCEPTION
5946                  WHEN OTHERS THEN
5947                       l_backorder_delivery_detail_id := null;
5948             END;
5949 
5950 
5951             IF (l_backorder_delivery_detail_id is not null AND l_transaction_type = 'REJECT') THEN
5952 	       IF (l_debug = 1) THEN
5953 		  print_debug('Calling inv_reservation_pub.delete_reservation',4);
5954 	       END IF;
5955 
5956 	       l_rsv_rec.demand_source_line_detail := l_backorder_delivery_detail_id;
5957 	       l_rsv_rec.organization_id           := p_org_id;
5958 	       l_rsv_rec.inventory_item_id         := l_mol_rec.inventory_item_id;
5959 
5960 	       inv_reservation_pub.delete_reservation
5961 		 (p_api_version_number       => 1.0
5962 		  , x_return_status          => l_return_status
5963 		  , x_msg_count              => l_msg_count
5964 		  , x_msg_data               => l_msg_data
5965 		  , p_rsv_rec                => l_rsv_rec
5966 		     , p_serial_number          => l_dummy_serial
5967 		  );
5968 
5969 	       IF (l_debug = 1) THEN
5970 		  print_debug('Returned from inv_reservation_pub.delete_reservation',4);
5971 		  print_debug('x_return_status =>'||l_return_status,4);
5972 	       END IF;
5973 
5974 	       IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
5975 		  IF (l_debug = 1) THEN
5976 		     print_debug('x_msg_data:  '||l_msg_data,4);
5977 		     print_debug('x_msg_count: '||l_msg_count,4);
5978 		     print_debug('SQLCODE:'||SQLCODE||' SQLERRM:'||SQLERRM,4);
5979 		     print_debug('Raising Exception!!!',4);
5980 		  END IF;
5981 		  l_progress := '@@@';
5982 		  RAISE fnd_api.g_exc_unexpected_error;
5983 	       END IF;
5984 
5985 	       l_backorder_delivery_detail_id := NULL;
5986 	    END IF;--IF l_backorder_delivery_detail_id is not null AND l_transaction_type = 'REJECT') THEN
5987 
5988 	    IF (l_backorder_delivery_detail_id IS NOT NULL) THEN
5989 	       -- update the txn_source_id and inspection_status,
5990 	       -- lpn_id, wms_process_flag for the new row.
5991 	       -- and wms_process_flag for the old row.
5992 
5993 	       --Update quantity with the quantity converted to the UOM in the RTI.  This is changed so
5994 	       --that the we honor the UOM entered by the user during
5995 	       --Transfer
5996 	       UPDATE mtl_txn_request_lines
5997 	         SET inspection_status = Decode(l_transaction_type,'ACCEPT',2,'REJECT',3,inspection_status)
5998 	         , lpn_id = p_transfer_lpn_id
5999 		 , quantity = Decode(uom_code
6000 				     ,p_uom_code
6001 				     ,quantity
6002 				     ,inv_rcv_cache.convert_qty(inventory_item_id
6003 								,quantity
6004 								,uom_code
6005 								,p_uom_code)
6006 				     )
6007 		 , quantity_detailed = Decode(l_transaction_type
6008 					      ,'TRANSFER'
6009 					      ,Decode(uom_code
6010 						      ,p_uom_code
6011 						      ,quantity_detailed
6012 						      ,inv_rcv_cache.convert_qty(inventory_item_id
6013 										 ,quantity_detailed
6014 										 ,uom_code
6015 										 ,p_uom_code))
6016 					      ,NULL)
6017 		 , quantity_delivered = Decode(l_transaction_type
6018 					       ,'TRANSFER'
6019 					       ,Decode(uom_code
6020 						       ,p_uom_code
6021 						       ,quantity_delivered
6022 						       ,inv_rcv_cache.convert_qty(inventory_item_id
6023 										  ,quantity_delivered
6024 										  ,uom_code
6025 										  ,p_uom_code))
6026 					       ,NULL)
6027 		 , uom_code = p_uom_code
6028                  -- OPMConvergence
6029 	         , secondary_quantity_detailed = Decode(l_transaction_type,'TRANSFER',secondary_quantity_detailed,NULL)
6030                  -- OPMConvergence
6031 	         , lot_number = p_lot_number
6032 	         , revision = p_revision
6033 	         , from_subinventory_code = Nvl(p_subinventory, from_subinventory_code)
6034 	         , from_locator_id = Nvl(p_locator_id, from_locator_id)
6035 	         , wms_process_flag = 1
6036 	         WHERE line_id = l_mo_split_tb(1).line_id;
6037             ELSE
6038 	       -- CLOSE THE SPLITTED LINE IF NOT BACKORDERED
6039 
6040 
6041 	       --???? Should we also update the primary qty here????
6042 	       --If p_mmtt_temp_id is not null then the move order line should
6043 	       --not be closed because this unnecessarily leads to
6044 	       --cancelling of operation plan. The line should be closed
6045 	       --if and only if there is a transfer mol present with the
6046 	       --same consolidation criteria. Otherwise it should be
6047 	       --updated just like the crossdock mols.
6048 
6049 	       IF (l_update_or_close = 'C') THEN
6050 		  UPDATE mtl_txn_request_lines
6051 		    SET   line_status = inv_globals.G_TO_STATUS_CLOSED
6052 		    , quantity = quantity_delivered
6053 		    , quantity_detailed = quantity_delivered
6054 		    , secondary_quantity_detailed = SECONDARY_QUANTITY_DELIVERED
6055 		    , wms_process_flag = 1
6056 		    , backorder_delivery_detail_id = l_backorder_delivery_detail_id
6057 		    , crossdock_type = Decode(l_backorder_delivery_detail_id,NULL,NULL,crossdock_type)
6058 		    WHERE line_id = l_mo_split_tb(1).line_id;
6059 		ELSE
6060 		  UPDATE mtl_txn_request_lines
6061 		    SET inspection_status = Decode(l_transaction_type,'ACCEPT',2,'REJECT',3,inspection_status)
6062 		    , lpn_id = p_transfer_lpn_id
6063 		    , quantity = Decode(p_uom_code,p_primary_uom_code,primary_quantity,uom_code--bug 13484877
6064 					--commenting for bug 13484877,p_uom_code
6065 					,quantity
6066 					,inv_rcv_cache.convert_qty(inventory_item_id
6067 								   ,quantity
6068 								   ,uom_code
6069 								   ,p_uom_code)
6070 					)
6071 		    , quantity_detailed = Decode(l_transaction_type
6072 						 ,'TRANSFER'
6073 						 ,Decode(uom_code
6074 							 ,p_uom_code
6075 							 ,quantity_detailed
6076 							 ,inv_rcv_cache.convert_qty(inventory_item_id
6077 										    ,quantity_detailed
6078 										    ,uom_code
6079 										    ,p_uom_code))
6080 						 ,NULL)
6081 		    , quantity_delivered = Decode(l_transaction_type
6082 						  ,'TRANSFER'
6083 						  ,Decode(uom_code
6084 							 ,p_uom_code
6085 							  ,quantity_delivered
6086 							  ,inv_rcv_cache.convert_qty(inventory_item_id
6087 										     ,quantity_delivered
6088 										     ,uom_code
6089 										     ,p_uom_code))
6090 						  ,NULL)
6091 		    , uom_code = p_uom_code
6092 		    -- OPMConvergence
6093 		    , secondary_quantity_detailed = Decode(l_transaction_type,'TRANSFER',secondary_quantity_detailed,NULL)
6094 		    -- OPMConvergence
6095 		    , lot_number = p_lot_number
6096 		    , revision = p_revision
6097 		    , from_subinventory_code = Nvl(p_subinventory, from_subinventory_code)
6098 		    , from_locator_id = Nvl(p_locator_id, from_locator_id)
6099 		    , wms_process_flag = 1
6100 		    , backorder_delivery_detail_id = l_backorder_delivery_detail_id
6101 		    , crossdock_type = Decode(l_backorder_delivery_detail_id,NULL,NULL,crossdock_type)
6102 		    WHERE line_id = l_mo_split_tb(1).line_id;
6103 	       END IF;
6104 	    END IF;--IF (l_backorder_delivery_detail_id IS NOT NULL) THEN
6105 
6106 	    /* EG. MOL has 6.  RS has 3 and 3.  You do LPN split of 4.
6107 	     * PWB will split MOL into 4 and 2, and the line with 4
6108 	     * will have wms_process_flag of 2.  maintain_mo_con will be
6109 	     * called twice, 1 for 3, the other for 1.  You do not want
6110 	     * to update the wms_process_flag MOL with 4 the first time
6111 	     * time you reach here.  You should only update it when the
6112 	     * qty being processing match the MOL qty (which will done
6113 	     * when maintain_mo_con is called with qty 1 */
6114 	       --UPDATE mtl_txn_request_lines
6115 	       --SET wms_process_flag = 1
6116 	       --WHERE line_id = l_mol_rec.line_id;
6117 
6118 	    l_remaining_primary_quantity := 0;
6119 
6120 	    IF (l_debug = 1) THEN
6121 		  print_debug('MAINTAIN_MO_CON - calling call_atf_api:'||l_mo_split_tb(1).line_id,1);
6122 		  l_progress := 'WMSINB-45116';
6123 	    END IF;
6124 
6125 	    --cancel_operation_instance should be called only if
6126 	    --p_mmtt_temp_id is NULL
6127 	    IF (p_mmtt_temp_id IS NULL) THEN
6128 	       call_atf_api(x_return_status => x_return_status,
6129 			    x_msg_data => x_msg_data,
6130 			    x_msg_count => x_msg_count,
6131 			    x_error_code => l_error_code,
6132 			    p_source_task_id => NULL,
6133 			    p_activity_type_id => 1,
6134 			    p_operation_type_id => NULL,
6135 			    p_mol_id => l_mo_split_tb(1).line_id,
6136 			    p_atf_api_name => g_atf_api_cancel);
6137 
6138 	       IF (x_return_status <> g_ret_sts_success) THEN
6139 		  IF (l_debug = 1) THEN
6140 		     print_debug('MAINTAIN_MO_CON - call_atf_api failed:'||l_mo_split_tb(1).line_id,1);
6141 		     l_progress := 'WMSINB-45118';
6142 		  END IF;
6143 		  --raise error
6144 		  l_progress := 'WMSINB-45120';
6145 		  RAISE fnd_api.g_exc_error;
6146 	       END IF;
6147 	    END IF;
6148 
6149 	 END IF; --IF  l_mol_qty_in_puom <= l_remaining_primary_quantity THEN
6150 
6151          --
6152          -- Consolidate THE LINES FOR THE TRANSFER LPN.
6153          --
6154          if l_backorder_delivery_detail_id is null
6155 	 Then
6156 
6157 	    l_progress := 'WMSINB-45122';
6158 	    -- POPULATE THE RECORD FOR TRANSFER MOL
6159 
6160 	    IF (l_debug = 1) THEN
6161 	        print_debug('MAINTAIN_MO_CON - consolidate lines l_progess =  '|| l_progress,1);
6162 	    END IF;
6163 
6164 	    --.. Moved the open and fetch call above the loop
6165 
6166 	    -- ** SET THE MOL REC QTY HERE ***
6167 	    IF l_mol_consumed_full = 1 then
6168 
6169 	       IF (l_debug = 1) THEN
6170 	           print_debug('MAINTAIN_MO_CON - Setting qty at case 1 ',1);
6171 		   print_debug('l_transfer_mol_rec.uom_code:'||l_transfer_mol_rec.uom_code,1);
6172 		   print_debug('l_mol_rec.uom_code '||l_mol_rec.uom_code,1);
6173 		   print_debug('l_mol_rec.quantity '||l_mol_rec.quantity,1);
6174 
6175 	       END IF;
6176                 --started changes for  bug8283511
6177                IF(l_transfer_mol_rec.uom_code <> l_mol_rec.uom_code) THEN
6178 	            l_mol_res_in(1).quantity := inv_rcv_cache.convert_qty(p_inventory_item_id => p_item_id
6179 		       ,p_from_qty         => l_mol_rec.quantity
6180 		       ,p_from_uom_code    => l_mol_rec.uom_code
6181 		       ,p_to_uom_code      => l_transfer_mol_rec.uom_code
6182 		       ,p_precision        => 5--BUG 4939647
6183 		       );
6184 
6185                       print_debug('l_mol_res_in(1).quantity in if block'||l_mol_res_in(1).quantity,1);
6186                 ELSE
6187 	              l_mol_res_in(1).quantity               := l_mol_rec.quantity;
6188 	              print_debug('l_mol_res_in(1).quantity in else block '||l_mol_res_in(1).quantity,1);
6189 	        END IF;
6190 	        --end changes for  bug8283511
6191 	        -- l_mol_res_in(1).quantity               := l_mol_rec.quantity; --added in upper if-else block for bug8283511
6192 	        l_mol_res_in(1).primary_qty            := l_mol_rec.primary_quantity;
6193 	        l_mol_res_in(1).secondary_quantity     := l_mol_rec.secondary_quantity_2; -- This is the QTY to be transacted
6194 	    ELSE
6195 	       IF (l_debug = 1) THEN
6196 	           print_debug('MAINTAIN_MO_CON - Setting qty at case 2 ',1);
6197 		   print_debug('l_transfer_mol_rec.uom_code:'||l_transfer_mol_rec.uom_code,1);
6198 		   print_debug('l_uom_code '||l_uom_code,1);
6199 		   print_debug('l_split_qty '||l_split_qty,1);
6200 	       END IF;
6201               --started changes for  bug8283511
6202 	       IF(l_transfer_mol_rec.uom_code <>l_uom_code) THEN
6203 	       l_mol_res_in(1).quantity := inv_rcv_cache.convert_qty(p_inventory_item_id => p_item_id
6204 		       ,p_from_qty         => l_split_qty
6205 		       ,p_from_uom_code    => l_uom_code
6206 		       ,p_to_uom_code      => l_transfer_mol_rec.uom_code
6207 		       ,p_precision        => 5--BUG 4939647
6208 		       );
6209                print_debug('l_mol_res_in(1).quantity in if block'||l_mol_res_in(1).quantity,1);
6210                ELSE
6211 	       l_mol_res_in(1).quantity               := l_split_qty;
6212 	       print_debug('l_mol_res_in(1).quantity in else block '||l_mol_res_in(1).quantity,1);
6213 	       END IF;
6214 	       --end changes for  bug8283511
6215 	       --l_mol_res_in(1).quantity               := l_split_qty;--added in upper if-else block for bug8283511
6216 	       l_mol_res_in(1).secondary_quantity     := l_split_sec_qty;
6217 	       l_mol_res_in(1).primary_qty            := get_primary_qty(p_org_id,p_item_id,l_mol_rec.uom_code,l_split_qty);
6218 	    END IF;
6219 
6220 	    if l_transfer_mol_rec.line_id is not null
6221 	    then
6222 	       -- Move Order Line found
6223 	       -- Check whether MOL is from the same SOURCE
6224 
6225 	       l_progress := 'WMSINB-45124';
6226 
6227 	       IF (l_debug = 1) THEN
6228 		  print_debug('MAINTAIN_MOC_CON - Move Order Line Found line Id = '|| l_transfer_mol_rec.line_id,1);
6229 	       END IF;
6230 
6231 	       check_reference(
6232 			       p_old_reference           => l_transfer_mol_rec.reference
6233 			       ,p_old_reference_type_code => l_transfer_mol_rec.reference_type_code
6234 			       ,p_old_reference_id        => l_transfer_mol_rec.reference_id
6235 			       ,p_new_reference           => l_new_reference
6236 			       ,p_new_reference_type_code => l_new_reference_type_code
6237 			       ,p_new_reference_id        => l_new_reference_id
6238 			       ,x_reference               => l_reference
6239 			       ,x_reference_type_code     => l_reference_type_code
6240 			       ,x_reference_id            => l_reference_id
6241 			       ,x_transaction_type_id     => l_transaction_type_id
6242 			       ,x_txn_source_type_id      => l_txn_source_type_id
6243 			       ,x_return_status           => x_return_status
6244 			       ,x_msg_count               => x_msg_count
6245 			       ,x_msg_data                => x_msg_data
6246 			       );
6247 
6248 
6249 	       IF (l_debug = 1) THEN
6250 		  print_debug('CHECK_REFERENCE - After calling check_reference :'||x_return_status||':'||l_progress,1);
6251 		  l_progress := 'WMSINB-45126';
6252 	       END IF;
6253 
6254 	       IF (x_return_status <> 'S') THEN
6255 		  l_progress := 'WMSINB-45127';
6256 		  RAISE fnd_api.g_exc_error;
6257 	       END IF;
6258 
6259 	       --
6260 	       -- UPDATE THE MOVE ORDER LINE HERE
6261 	       --
6262 	       IF (p_mmtt_temp_id IS NOT NULL) THEN
6263 		  UPDATE mtl_material_transactions_temp
6264 		    SET  move_order_line_id = l_transfer_mol_rec.line_id
6265 		    WHERE transaction_temp_id = p_mmtt_temp_id;
6266 
6267 		  l_qty_detailed := l_mol_res_in(1).quantity;
6268 
6269 
6270 		  IF (l_debug = 1) THEN
6271 		     print_debug('NUMBER OF MMTT UPDATED: '||SQL%rowcount,1);
6272 		  END IF;
6273 		ELSE
6274 		  l_qty_detailed := 0;
6275 	       END IF;
6276 
6277 	       update mtl_txn_request_lines
6278 		 set reference = l_reference
6279 		 ,reference_type_code = l_reference_type_code
6280 		 ,reference_id = l_reference_id
6281 		 ,quantity = quantity + l_mol_res_in(1).quantity
6282 		 ,quantity_detailed = quantity_detailed + l_qty_detailed
6283 		 ,primary_quantity = primary_quantity + l_mol_res_in(1).primary_qty
6284 		 ,secondary_quantity = secondary_quantity + l_mol_res_in(1).secondary_quantity
6285 		 ,transaction_type_id = nvl(l_transaction_type_id,transaction_type_id)
6286 		 ,transaction_source_type_id = nvl(l_txn_source_type_id,transaction_source_type_id)
6287 		 ,wms_process_flag = 1
6288 		 where line_id = l_transfer_mol_rec.line_id
6289 		 ;
6290 
6291 	       l_progress := 'WMSINB-45128';
6292 
6293 	       /* Need to modify validate_lpN_info first.  Will revisit
6294 	       call_atf_api(x_return_status => x_return_status,
6295 			    x_msg_data => x_msg_data,
6296 			    x_msg_count => x_msg_count,
6297 			    x_error_code => l_error_code,
6298 			    p_source_task_id => NULL,
6299 			    p_activity_type_id => 1,
6300 			    p_operation_type_id => NULL,
6301 			    p_mol_id => l_transfer_mol_rec.line_id,
6302 			    p_atf_api_name => g_atf_api_cancel);
6303 */
6304 	       IF (x_return_status <> g_ret_sts_success) THEN
6305 		  IF (l_debug = 1) THEN
6306 		     print_debug('MAINTAIN_MO_CON - call_atf_api failed:'||l_transfer_mol_rec.line_id,1);
6307 		     l_progress := 'WMSINB-45131';
6308 		  END IF;
6309 		  l_progress := 'WMSINB-45064';
6310 		  RAISE fnd_api.g_exc_error;
6311 	       END IF;
6312 	    END IF;  --l_transfer_mol_rec.line_id is not null
6313 
6314 	       --... The following code should be commented because
6315 	       --there was no transfer MOL, we would have updated the orig
6316 	       --mol
6317 
6318 
6319 	    -- Else
6320 	    -- Move Order Line Not Found Create Move Order
6321 	    --     IF (l_debug = 1) THEN
6322 	    --print_debug('MAINTAIN_MOC_CON - Move Order Line Not Found line Id ',1);
6323 	    --		     END IF;
6324 
6325 	    --create mol
6326 	    --	     inv_rcv_std_rcpt_apis.create_move_order(p_move_order_header_id => l_move_order_header_id
6327 	    --					     ,p_po_line_location_id      => p_po_line_location_id
6328 	    --				     ,p_po_distribution_id       => p_po_distribution_id
6329 	    --			     ,p_shipment_line_id         => p_shipment_line_id
6330 	    --		     ,p_oe_order_line_id         => p_oe_order_line_id
6331 	    --	     ,p_routing                  => p_routing_header_id
6332 	    --     ,p_lot_control_code         => p_lot_control_code
6333 	    --   ,p_org_id                   => l_mol_res_in(1).organization_id
6334 	    -- ,p_item_id                  => l_mol_res_in(1).inventory_item_id
6335 	    --							     ,p_qty                      => l_mol_res_in(1).quantity
6336 	    --						     ,p_uom_code                 => l_mol_res_in(1).uom_code
6337 	    --					     ,p_lpn                      => l_mol_res_in(1).lpn_id
6338 	    --				     ,p_project_id               => l_mol_res_in(1).project_id
6339 	    --			     ,p_task_id                  => l_mol_res_in(1).task_id
6340 	    --		     ,p_revision                 => l_mol_res_in(1).item_revision
6341 	    --		       ,p_inspect                  => l_mol_res_in(1).inspection_status
6342 	    ---	       ,p_txn_source_id            => null
6343 	    --       ,x_status                   => x_return_status
6344 	    --     ,x_message                  => x_msg_data
6345 	    --   ,p_transfer_org_id          => l_mol_res_in(1).transfer_org_id
6346 	    -- ,p_wms_process_flag         => 1
6347 	    --		       ,p_lot_number               => l_mol_res_in(1).lot_number
6348 	    --	       ,p_secondary_quantity       => l_mol_res_in(1).secondary_quantity
6349 	    --       ,p_secondary_uom            => l_mol_res_in(1).secondary_uom
6350 	    --     ,x_line_id                  => l_move_order_line_id
6351 	    --   );
6352 
6353 	    --		     IF (l_debug = 1) THEN
6354 	    --print_debug('MAINTAIN_MO_CON - After calling create_move_order:'||x_return_status||':'||l_progress,1);
6355 	    --print_debug('MAINTAIN_MO_CON - Move Order Header ID:'||l_move_order_header_id||':'||l_progress,1);
6356 	    --	     END IF;
6357 	    --
6358 	    --   IF (x_return_status <> 'S') THEN
6359 	    --l_progress := 'WMSINB-45070';
6360 	    --			RAISE fnd_api.g_exc_error;
6361 	    --	     END IF;
6362 	    --
6363 	    --   --update mol for the sub and loc
6364 	    -- UPDATE mtl_txn_request_lines
6365 	    -- SET from_subinventory_code = Nvl(p_subinventory,from_subinventory_code)
6366 	    --		       , from_locator_id = Nvl(p_locator_id, from_locator_id)
6367 	    --	       WHERE header_id = l_move_order_header_id
6368 	    --             and organization_id = p_org_id
6369 	    --       AND inventory_item_id = p_item_id;
6370 
6371 	 End if; -- l_backorder_delivery_detail_id is null
6372 
6373 	 IF l_remaining_primary_quantity <= 0 THEN
6374 	       EXIT;
6375 	 END IF;
6376       END LOOP;
6377 
6378       IF c_mol_mmtt%isopen THEN
6379 	 CLOSE c_mol_mmtt;
6380       END IF;
6381 
6382       IF c_mol_no_mmtt%isopen THEN
6383 	 CLOSE c_mol_no_mmtt;
6384       END IF;
6385 
6386       IF (l_debug = 1) THEN
6387 	 print_debug('MAINTAIN_MO - l_remaining_primary_quantity:'||l_remaining_primary_quantity,1);
6388       END IF;
6389 
6390       IF (Round(l_remaining_primary_quantity,5) > 0) THEN
6391 	 IF (l_debug = 1) THEN
6392 	    print_debug('MAINTAIN_MO - QTY STILL REMAINING !!!'||l_remaining_primary_quantity||':'||l_progress,1);
6393 	    l_progress := 'WMSINB-13244';
6394 	 END IF;
6395 	 --raise error
6396 	 l_progress := 'WMSINB-13247';
6397 	 RAISE fnd_api.g_exc_error;
6398       END IF;
6399 
6400       --update capacity and empty flag for locators
6401       IF (Nvl(p_locator_id, Nvl(l_from_loc_id, -1)) <> Nvl(l_from_loc_id, -1)) THEN
6402 	 --call upd_empty_mixed_flag
6403 	 IF p_locator_id IS NOT NULL THEN
6404 	    IF (l_debug = 1) THEN
6405 	       print_debug('MAINTAIN_MO - Calling upd_empty_mixed_flag for	CURRENT sub',1);
6406 	    END IF;
6407 
6408 	    inv_loc_wms_utils.upd_empty_mixed_flag_rcv_loc ( x_return_status  => x_return_status
6409 							     ,x_msg_count    => x_msg_count
6410 							     ,x_msg_data     => x_msg_data
6411 							     ,p_subinventory => p_subinventory
6412 							     ,p_locator_id   => p_locator_id
6413 							     ,p_org_id       => p_org_id
6414 							     );
6415 	    IF (x_return_status <> 'S') THEN
6416 	       l_progress := 'WMSINB-13250';
6417 	       -- Bug 5393727: do not raise an exception if locator API returns an error
6418 	       -- RAISE fnd_api.g_exc_error;
6419 	    END IF;
6420 
6421 	    -- update curr capacity
6422 	    IF (l_debug = 1) THEN
6423 	       print_debug('MAINTAIN_MO - Calling update_loc_curr_capacity FOR CURRENT sub',1); --bug13451495
6424 	    END IF;
6425 
6426 	    --bug13451495
6427             inv_loc_wms_utils.update_loc_current_capacity
6428 	      ( x_return_status           => x_return_status
6429 		,x_msg_count               => x_msg_count
6430 		,x_msg_data                => x_msg_data
6431 		,p_organization_id         => p_org_id
6432 		,p_inventory_location_id   => p_locator_id
6433 		,p_inventory_item_id       => p_item_id
6434 		,p_primary_uom_flag        => 'N'
6435 		,p_transaction_uom_code    => p_uom_code
6436 		,p_quantity                => p_qty
6437 		,p_issue_flag              => 'N'
6438 		);
6439 	    IF (x_return_status <> 'S') THEN
6440 	       l_progress := 'WMSINB-13252';
6441 	       -- Bug 5393727: do not raise an exception if locator API returns an error
6442 	       -- RAISE fnd_api.g_exc_error;
6443 	    END IF;
6444 	 END IF; --IF p_subinventory IS NOT NULL THEN
6445 
6446 	 IF l_from_loc_id IS NOT NULL THEN
6447 	    IF (l_debug = 1) THEN
6448 	       print_debug('MAINTAIN_MO - Calling upd_empty_mixed_flag for FROM sub',1);
6449 	    END IF;
6450 
6451 	    inv_loc_wms_utils.upd_empty_mixed_flag_rcv_loc ( x_return_status  => x_return_status
6452 							     ,x_msg_count    => x_msg_count
6453 							     ,x_msg_data     => x_msg_data
6454 							     ,p_subinventory => l_from_sub
6455 							     ,p_locator_id   => l_from_loc_id
6456 							     ,p_org_id       => p_org_id
6457 							     );
6458 	    IF (x_return_status <> 'S') THEN
6459 	       l_progress := 'WMSINB-13255';
6460 	       -- Bug 5393727: do not raise an exception if locator API returns an error
6461 	       -- RAISE fnd_api.g_exc_error;
6462 	    END IF;
6463 
6464 	    -- update curr capacity
6465 	    IF (l_debug = 1) THEN
6466 	       print_debug('MAINTAIN_MO - Calling update_loc_curr_capacity_nauto FOR FROM sub',1);
6467 	    END IF;
6468 
6469 	    inv_loc_wms_utils.update_loc_curr_capacity_nauto
6470 	      ( x_return_status           => x_return_status
6471 		,x_msg_count               => x_msg_count
6472 		,x_msg_data                => x_msg_data
6473 		,p_organization_id         => p_org_id
6474 		,p_inventory_location_id   => l_from_loc_id
6475 		,p_inventory_item_id       => p_item_id
6476 		,p_primary_uom_flag        => 'N'
6477 		,p_transaction_uom_code    => p_uom_code
6478 		,p_quantity                => p_qty
6479 		,p_issue_flag              => 'Y'
6480 		);
6481 	    IF (x_return_status <> 'S') THEN
6482 	       l_progress := 'WMSINB-13257';
6483 	       -- Bug 5393727: do not raise an exception if locator API returns an error
6484 	       -- RAISE fnd_api.g_exc_error;
6485 	    END IF;
6486 	 END IF; --IF l_from_sub IS NOT NULL THEN
6487       END IF; --IF (Nvl(p_locator_id, Nvl(l_from_loc_id, -1)) <> Nvl(l_from_loc_id, -1)) THEN
6488 
6489     END IF;--  IF l_update_or_close = 'N' THEN
6490 
6491 --Call pregeneration again for accept/reject transactions
6492 -- ... move the pregeneration call to complete lpn group.
6493 --      IF l_transaction_type IN ('ACCEPT', 'REJECT') THEN
6494 --	 l_call_pregeneration := TRUE;
6495 
6496 -- R12 Commented the call to pregeneration
6497 -- As this has been moved to complete_lpn_group
6498 --
6499 --	 IF (p_transfer_lpn_id IS NULL) THEN
6500 --	    l_call_pregeneration := FALSE;
6501 --	  ELSE
6502 --	    IF p_lot_control_code > 1 THEN
6503 --	       IF p_lot_number IS NULL THEN
6504 --		  l_call_pregeneration := FALSE;
6505 --	       END IF;
6506 --	     ELSIF p_serial_number_control_code IN (2,5,6) THEN
6507 --	       BEGIN
6508 --		  SELECT '1'
6509 --		    INTO l_dummy
6510 --		    FROM mtl_serial_numbers_temp
6511 --		    WHERE product_code = 'RCV'
6512 --		    AND product_transaction_id = p_rti_id
6513 --		    AND ROWNUM < 2;
6514 --	       EXCEPTION
6515 --		  WHEN OTHERS THEN
6516 --		     l_call_pregeneration := FALSE;
6517 --	       END;
6518 --	    END IF;
6519 --	 END IF; --IF (p_lpn_id IS NULL) THEN
6520 
6521 	 --call pregeneration
6522 --	 IF l_call_pregeneration THEN
6523 --	    IF (l_debug = 1) THEN
6524 --	       print_debug('MAINTAIN_MO - Before calling start_pregenerate_program:'||l_progress,1);
6525 --	       l_progress := 'WMSINB-13260';
6526 --	    END IF;
6527 --	    wms_putaway_suggestions.start_pregenerate_program
6528 --	      (p_org_id => p_org_id,
6529 --	       p_lpn_id => p_transfer_lpn_id,
6530 --	       x_return_status => x_return_status,
6531 --	       x_msg_count => x_msg_count,
6532 --	       x_msg_data => x_msg_data);
6533 --
6534 --	    IF (l_debug = 1) THEN
6535 --	       print_debug('MAINTAIN_MO - After calling start_pregenerate_program:'||x_return_status||':'||l_progress,1);
6536 --	       l_progress := 'WMSINB-13262';
6537 --	    END IF;
6538 --
6539 --	    IF (x_return_status <> 'S') THEN
6540 --	       x_return_status := 'S';
6541 --	    END IF;
6542 --	 END IF; --IF l_call_pregeneration THEN
6543 
6544 --      END IF; --IF l_transaction_type IN ('ACCEPT','REJECT') THEN
6545 
6546    END IF; --IF l_transaction_type IN ('ACCEPT','REJECT','TRANSFER') THEN
6547 
6548 
6549    IF (l_transaction_type = 'DELIVER' OR
6550        (l_transaction_type = 'CORRECT' AND
6551 	p_primary_quantity > 0 AND
6552 	l_parent_txn_type = 'DELIVER')) THEN
6553       IF (p_mmtt_temp_id IS NOT NULL) THEN
6554          OPEN c_mol_mmtt(p_mmtt_temp_id,
6555                          p_item_id,
6556                          p_lpn_id,
6557                          p_lot_number,
6558                          p_revision,
6559                          p_from_subinventory,
6560                          p_from_locator_id,
6561                          p_project_id,
6562                          p_task_id,
6563                          l_from_mol_inspection_status
6564                         );
6565        ELSE
6566 	 OPEN c_mol_no_mmtt(p_item_id,
6567                             p_lpn_id,
6568 			    p_lot_number,
6569                             p_revision,
6570                             p_from_subinventory,
6571                             p_from_locator_id,
6572                             p_project_id ,
6573                             p_task_id ,
6574                             l_from_mol_inspection_status,
6575                             p_uom_code,
6576 							l_new_reference_id  --14133874
6577 
6578                           );
6579       END IF;
6580 
6581       l_remaining_primary_quantity := p_primary_quantity;
6582 
6583       -- OPMConvergence
6584       l_remaining_secondary_quantity := p_sec_qty;
6585       -- OPMConvergence
6586 
6587       LOOP
6588 	 IF (p_mmtt_temp_id IS NOT NULL) THEN
6589 	    FETCH c_mol_mmtt INTO l_mol_rec;
6590 	    EXIT WHEN c_mol_mmtt%notfound;
6591 	  ELSE
6592 	       FETCH c_mol_no_mmtt INTO l_mol_rec;
6593 	       EXIT WHEN c_mol_no_mmtt%notfound;
6594 	 END IF;
6595 
6596 	 IF (l_debug = 1) THEN
6597 	    print_debug('MAINTAIN_MO - REMAINING QUANTITY:'||l_remaining_primary_quantity||':'||l_progress,1);
6598 
6599 	    l_progress := 'WMSINB-13273';
6600 	 END IF;
6601 
6602 	 --BUG 4766810: Always add before rounding.  Also, when comparing
6603 	 -- for equality, check if the two number differs by 0.000005
6604 	 -- (round to 5 digits).
6605 	 IF (l_mol_rec.uom_code <> p_primary_uom_code) THEN
6606 	    l_conversion_rate := inv_rcv_cache.get_conversion_rate(l_mol_rec.inventory_item_id,
6607 								   l_mol_rec.uom_code,
6608 								   p_primary_uom_code);
6609 	    l_mol_qty_in_puom := l_mol_rec.quantity * l_conversion_rate;
6610 	  ELSE
6611 	    l_mol_qty_in_puom := l_mol_rec.quantity;
6612 	    l_conversion_rate := 1;
6613 	 END IF;
6614 
6615 	 l_quantity_delivered := inv_rcv_cache.convert_qty(p_inventory_item_id => l_mol_rec.inventory_item_id
6616 					     ,p_from_qty         => l_remaining_primary_quantity
6617 					     ,p_from_uom_code    => p_primary_uom_code
6618 					     ,p_to_uom_code      => l_mol_rec.uom_code);
6619 
6620          -- OPMConvergence
6621 
6622          IF l_mol_rec.secondary_uom_code <> p_sec_uom THEN
6623 
6624             l_sec_quantity_delivered := inv_rcv_cache.convert_qty(p_inventory_item_id => l_mol_rec.inventory_item_id
6625 						    ,p_from_qty         => l_remaining_primary_quantity
6626 						    ,p_from_uom_code    => p_sec_uom
6627 						    ,p_to_uom_code      => l_mol_rec.secondary_uom_code);
6628          ELSE
6629 
6630            l_sec_quantity_delivered := l_remaining_secondary_quantity;
6631 
6632          END IF;
6633 
6634          -- OPMConvergence
6635 
6636 	 IF (l_debug = 1) THEN
6637 	    print_debug('MAINTAIN_MO_CON - MOL QTY IN PUOM:'||l_mol_qty_in_puom||':'||l_progress,1);
6638 	    print_debug('MAINTAIN_MO_CON - QUANTITY DELIVERED:'||l_quantity_delivered||':'||l_progress,1);
6639             -- OPMConvergence
6640 	    print_debug(l_proc_name||' SEC QUANTITY DELIVERED:'||l_sec_quantity_delivered||':'||l_progress,1);
6641             -- OPMConvergence
6642 	    l_progress := 'WMSINB-13295';
6643 	 END IF;
6644 
6645 	 IF (p_mmtt_temp_id IS NULL AND l_mol_rec.transaction_temp_id IS NOT NULL) THEN
6646 	    IF (l_debug = 1) THEN
6647 	       print_debug('MAINTAIN_MO - calling call_atf_api:'||l_mol_rec.line_id,1);
6648 	       l_progress := 'WMSINB-13305';
6649 	    END IF;
6650 
6651 	    call_atf_api(x_return_status => x_return_status,
6652 			 x_msg_data => x_msg_data,
6653 			 x_msg_count => x_msg_count,
6654 			 x_error_code => l_error_code,
6655 			 p_source_task_id => NULL,
6656 			 p_activity_type_id => 1,
6657 			 p_operation_type_id => NULL,
6658 			 p_mol_id => l_mol_rec.line_id,
6659 			 p_atf_api_name => g_atf_api_cancel);
6660 	 END IF;
6661 
6662 	 --BUG 4766810, always round to 5 digits when comparing because
6663 	 --quantity is stored in 5 digits in Inventory
6664 	 IF (Round(l_remaining_primary_quantity,5) < Round(l_mol_qty_in_puom,5)) THEN
6665 	    IF (l_debug = 1) THEN
6666 	       print_debug('MAINTAIN_MO_CON - Updating MOL:'||l_mol_rec.line_id||':'||l_progress,1);
6667 	       l_progress := 'WMSINB-13301';
6668 	    END IF;
6669 
6670 	    l_mo_split_tb(1).prim_qty := l_remaining_primary_quantity;
6671 
6672 	    -- OPMConvergence
6673             -- Do we need to assign secondary quantity too ?
6674             -- OPMConvergence
6675 	    l_mo_split_tb(1).line_id := NULL;
6676 
6677 	    IF p_mmtt_temp_id IS NOT NULL THEN
6678 	       -- Call split mo with operation_type DELIVER
6679 	       -- This will split the MO and tied the mmtt
6680 	       -- to the new MO
6681 	       inv_rcv_integration_apis.split_mo
6682 		 (p_orig_mol_id => l_mol_rec.line_id,
6683 		  p_mo_splt_tb => l_mo_split_tb,
6684 		  p_operation_type => 'DELIVER',
6685 		  p_txn_header_id => p_mmtt_temp_id,
6686 		  x_return_status => x_return_status,
6687 		  x_msg_count => x_msg_count,
6688 		  x_msg_data => x_msg_data);
6689 	     ELSE
6690 	       inv_rcv_integration_apis.split_mo
6691 		 (p_orig_mol_id => l_mol_rec.line_id,
6692 		  p_mo_splt_tb => l_mo_split_tb,
6693 		  x_return_status => x_return_status,
6694 		  x_msg_count => x_msg_count,
6695 		  x_msg_data => x_msg_data);
6696 	    END IF;
6697 
6698 	    --Call Reservations
6699             --R12
6700 	    /* Bug 5627083.
6701 	     * We need to pass in the transfer_lpn_id to update the reservation record.
6702 	    */
6703             l_mol_res_in(1).transaction_type       := l_transaction_type;
6704             l_mol_res_in(1).organization_id        := p_org_id;
6705             l_mol_res_in(1).lpn_id                 := p_transfer_lpn_id;
6706             l_mol_res_in(1).inventory_item_id      := p_item_id;
6707 	    l_mol_res_in(1).lot_number             := p_lot_number;
6708             l_mol_res_in(1).item_revision          := p_revision;
6709             l_mol_res_in(1).project_id             := p_project_id;
6710             l_mol_res_in(1).task_id                := p_task_id;
6711             l_mol_res_in(1).uom_code               := NULL;
6712             l_mol_res_in(1).quantity               := 0;
6713             l_mol_res_in(1).backorder_delivery_detail_id := l_mo_split_tb(1).wdd_id;--New field in l_mo_split_tb
6714             l_mol_res_in(1).crossdock_type         := NULL;
6715             l_mol_res_in(1).secondary_quantity     := 0;
6716             l_mol_res_in(1).secondary_uom          := NULL;
6717             l_mol_res_in(1).line_id                := l_mo_split_tb(1).line_id;
6718             l_mol_res_in(1).primary_qty            := l_remaining_primary_quantity;
6719             l_mol_res_in(1).primary_uom_code       := p_primary_uom_code;
6720             l_mol_res_in(1).primary_qty            := l_remaining_primary_quantity;
6721             l_mol_res_in(1).wip_supply_type        := l_mol_rec.wip_supply_type;
6722             l_mol_res_in(1).crossdock_type         := l_mol_rec.crossdock_type;
6723             l_mol_res_in(1).inspection_status      := l_from_mol_inspection_status;
6724 	    l_mol_res_in(1).subinventory_code      := p_subinventory;
6725 	    l_mol_res_in(1).locator_id             := p_locator_id;
6726 	    l_mol_res_in(1).parent_txn_type        := l_parent_txn_type;
6727 
6728 	    INV_RCV_RESERVATION_UTIL.maintain_reservations
6729 	      (x_return_status => x_return_status
6730 	       ,x_msg_count     => x_msg_count
6731 	       ,x_msg_data      => x_msg_data
6732 	       ,x_mol_tb        => l_mol_res_out
6733 	       ,p_cas_mol_tb    => l_mol_res_in
6734 	       );
6735 
6736 	    IF (l_debug = 1) THEN
6737 	       print_debug(' maintain_reservations - After calling maintain_reservations :'||x_return_status||':'||l_progress,1);
6738 	       l_progress := 'WMSINB-45051';
6739 	    END IF;
6740 
6741 	    IF (x_return_status <> 'S') THEN
6742 	       l_progress := 'WMSINB-45052';
6743 	       RAISE fnd_api.g_exc_error;
6744 	    END IF;
6745 
6746 	    l_progress := 'WMSINB-45053';
6747 
6748 
6749 	    --Close line
6750 	    UPDATE mtl_txn_request_lines
6751 	      SET quantity_delivered = Decode(p_mmtt_temp_id,NULL,
6752 					      Nvl(quantity_delivered,0)+l_quantity_delivered,quantity_delivered)
6753 	      ,secondary_quantity_delivered = Decode(p_mmtt_temp_id,NULL,
6754 						     Nvl(secondary_quantity_delivered,0)+l_sec_quantity_delivered,quantity_delivered)
6755 	      , line_status = Decode(p_mmtt_temp_id,NULL,
6756 				     Decode((Nvl(quantity_delivered,0)+l_quantity_delivered),quantity,
6757 					    inv_globals.G_TO_STATUS_CLOSED,line_status),line_status)
6758 	      , wms_process_flag = 1
6759 	      WHERE line_id = l_mo_split_tb(1).line_id;
6760 
6761 	    -- R12
6762 
6763 	    l_remaining_primary_quantity := 0;
6764 
6765             -- OPMConvergence
6766 	    l_remaining_secondary_quantity := 0;
6767             -- OPMConvergence
6768 
6769 	  ELSE --IF (l_remaining_primary_quantity < l_mol_qty_in_puom) THEN
6770 
6771             -- R12
6772 
6773 	    /* Bug 5627083.
6774 	     * We need to pass in the transfer_lpn_id to update the reservation record.
6775 	    */
6776             l_mol_res_in(1).transaction_type       := l_transaction_type;
6777             l_mol_res_in(1).organization_id        := p_org_id;
6778             l_mol_res_in(1).lpn_id                 := p_transfer_lpn_id;
6779             l_mol_res_in(1).inventory_item_id      := p_item_id;
6780 	    l_mol_res_in(1).lot_number             := p_lot_number;
6781 	    l_mol_res_in(1).item_revision          := p_revision;
6782             l_mol_res_in(1).project_id             := p_project_id;
6783             l_mol_res_in(1).task_id                := p_task_id;
6784             l_mol_res_in(1).uom_code               := null;
6785             l_mol_res_in(1).quantity               := 0;
6786             l_mol_res_in(1).backorder_delivery_detail_id := l_mol_rec.backorder_delivery_detail_id;
6787             l_mol_res_in(1).secondary_quantity     := 0;
6788             l_mol_res_in(1).secondary_uom          := null;
6789             l_mol_res_in(1).line_id                := l_mol_rec.line_id;
6790             l_mol_res_in(1).primary_qty            := l_mol_qty_in_puom;
6791             l_mol_res_in(1).primary_uom_code       := p_primary_uom_code;
6792             l_mol_res_in(1).primary_qty            := l_remaining_primary_quantity;
6793             l_mol_res_in(1).inspection_status      := l_from_mol_inspection_status;
6794 
6795             -- Added the below two line also
6796             l_mol_res_in(1).wip_supply_type        := l_mol_rec.wip_supply_type;
6797             l_mol_res_in(1).crossdock_type         := l_mol_rec.crossdock_type;
6798 
6799 	    l_mol_res_in(1).subinventory_code      := p_subinventory;
6800 	    l_mol_res_in(1).locator_id             := p_locator_id;
6801 	    l_mol_res_in(1).parent_txn_type        := l_parent_txn_type;
6802 
6803 	    INV_RCV_RESERVATION_UTIL.maintain_reservations
6804 	      (x_return_status => x_return_status
6805 	       ,x_msg_count     => x_msg_count
6806 	       ,x_msg_data      => x_msg_data
6807 	       ,x_mol_tb        => l_mol_res_out
6808 	       ,p_cas_mol_tb    => l_mol_res_in
6809 	       );
6810 
6811 	    IF (l_debug = 1) THEN
6812 	       print_debug(' maintain_reservations - After calling maintain_reservations :'||x_return_status||':'||l_progress,1);
6813 	       l_progress := 'WMSINB-45051';
6814 	    END IF;
6815 
6816 	    IF (x_return_status <> 'S') THEN
6817 	       l_progress := 'WMSINB-45052';
6818 	       RAISE fnd_api.g_exc_error;
6819 	    END IF;
6820 
6821 	    l_progress := 'WMSINB-45053';
6822 
6823 	    UPDATE mtl_txn_request_lines
6824 	      SET quantity_delivered = Decode(p_mmtt_temp_id,NULL,quantity,quantity_delivered)
6825               -- OPMConvergence
6826 	      , secondary_quantity_delivered = Decode(p_mmtt_temp_id,NULL,secondary_quantity,secondary_quantity_delivered)
6827               -- OPMConvergence
6828 	      , line_status = Decode(p_mmtt_temp_id,NULL,inv_globals.g_to_status_closed,line_status)
6829 	      , wms_process_flag = 1
6830 	      WHERE line_id = l_mol_rec.line_id;
6831 
6832             -- OPMConvergence
6833             l_remaining_secondary_quantity := (l_remaining_primary_quantity - l_mol_qty_in_puom )*
6834                                               (l_remaining_secondary_quantity / l_remaining_primary_quantity );
6835 
6836             -- OPMConvergence
6837 	    l_remaining_primary_quantity := l_remaining_primary_quantity - l_mol_qty_in_puom;
6838 
6839 	    -- Bug 5632202 : Set l_remaining_primary_quantity to zero if it differs from MOL
6840 	    --               quantity in sixth decimal place
6841 	    IF trunc(( l_remaining_primary_quantity/ l_conversion_rate ),5) = 0 THEN
6842 	      l_remaining_primary_quantity := 0;
6843 	      l_remaining_secondary_quantity := 0;
6844 	      IF (l_debug = 1) THEN
6845 		print_debug('MAINTAIN_MO_CON - Setting l_remaining_primary_quantity to zero',1);
6846 	      END IF;
6847 	    END IF;
6848 
6849 	 END IF; --IF (l_remaining_primary_quantity <= l_mol_qty_in_puom) THEN
6850 
6851 	 IF (l_debug = 1) THEN
6852 	    print_debug('MAINTAIN_MO_CON - l_remaining_primary_quantity:'||l_remaining_primary_quantity,1);
6853 	 END IF;
6854 
6855 	 IF (Round(l_remaining_primary_quantity,5) <= 0) THEN
6856 	    EXIT;
6857 	 END IF;
6858 
6859       END LOOP;
6860 
6861       IF c_mol_mmtt%isopen THEN
6862 	 CLOSE c_mol_mmtt;
6863       END IF;
6864 
6865       IF c_mol_no_mmtt%isopen THEN
6866 	 CLOSE c_mol_no_mmtt;
6867       END IF;
6868 
6869       IF (Round(l_remaining_primary_quantity,5) > 0.00005) THEN
6870 	 IF (l_debug = 1) THEN
6871 	    print_debug('MAINTAIN_MO_CON - QTY STILL REMAINING *** HOW ???:'||l_remaining_primary_quantity||':'||l_progress,1);
6872 	    l_progress := 'WMSINB-13342';
6873 	 END IF;
6874 	 --raise error
6875 	 l_progress := 'WMSINB-13345';
6876 	 RAISE fnd_api.g_exc_error;
6877       END IF;
6878 
6879       --call upd_empty_mixed_flag
6880       IF l_from_loc_id IS NOT NULL THEN
6881 	 IF (l_debug = 1) THEN
6882 	    print_debug('MAINTAIN_MO_CON - Calling upd_empty_mixed_flag for	FROM sub',1);
6883 	 END IF;
6884 
6885 	 inv_loc_wms_utils.upd_empty_mixed_flag_rcv_loc ( x_return_status  => x_return_status
6886 							  ,x_msg_count    => x_msg_count
6887 							  ,x_msg_data     => x_msg_data
6888 							  ,p_subinventory => l_from_sub
6889 							  ,p_locator_id   => l_from_loc_id
6890 							  ,p_org_id       => p_org_id
6891 							  );
6892 	 IF (x_return_status <> 'S') THEN
6893 	    l_progress := 'WMSINB-13350';
6894 	    -- Bug 5393727: do not raise an exception if locator API returns an error
6895 	    -- RAISE fnd_api.g_exc_error;
6896 	 END IF;
6897 
6898 	 -- update curr capacity
6899 	 IF (l_debug = 1) THEN
6900 	    print_debug('MAINTAIN_MO_CON - Calling update_loc_curr_capacity_nauto FOR FROM sub',1);
6901 	 END IF;
6902 
6903 	 inv_loc_wms_utils.update_loc_curr_capacity_nauto
6904 	   ( x_return_status           => x_return_status
6905 	     ,x_msg_count               => x_msg_count
6906 	     ,x_msg_data                => x_msg_data
6907 	     ,p_organization_id         => p_org_id
6908 	     ,p_inventory_location_id   => l_from_loc_id
6909 	     ,p_inventory_item_id       => p_item_id
6910 	     ,p_primary_uom_flag        => 'N'
6911 	     ,p_transaction_uom_code    => p_uom_code
6912 	     ,p_quantity                => p_qty
6913 	     ,p_issue_flag              => 'Y'
6914 	     );
6915 	 IF (x_return_status <> 'S') THEN
6916 	    l_progress := 'WMSINB-13357';
6917 	    -- Bug 5393727: do not raise an exception if locator API returns an error
6918 	    -- RAISE fnd_api.g_exc_error;
6919 	 END IF;
6920       END IF; --IF l_from_sub IS NOT NULL THEN
6921 
6922       IF (l_transaction_type = 'CORRECT') THEN
6923 	 --We need to update the wms_process_flag on mol for all the lines for the given lpn as
6924 	 --we update all the mols for the given lpn to 2 in mark_returns
6925 	 UPDATE mtl_txn_request_lines
6926 	   SET wms_process_flag = 1
6927 	   WHERE (lpn_id = p_lpn_id
6928 		  OR lpn_id = p_transfer_lpn_id);
6929       END IF;
6930    END IF; --IF (l_transaction_type = 'DELIVER') THEN
6931 
6932 
6933    IF (l_transaction_type IN ('CORRECT','RETURN TO VENDOR',
6934 			      'RETURN TO CUSTOMER','RETURN TO RECEIVING')
6935        --Treat + Corr of Deliver as DELIVER above
6936        AND (NOT (l_transaction_type = 'CORRECT'
6937 		 AND p_primary_quantity > 0
6938 		 AND l_parent_txn_type = 'DELIVER'))
6939        --Treat + Corr of Receive as RECEIVE above
6940        AND (NOT (l_transaction_type = 'CORRECT'
6941 		 AND p_primary_quantity > 0
6942 		 AND l_parent_txn_type = 'RECEIVE'))
6943        ) THEN
6944 
6945       IF (l_debug = 1) THEN
6946 	 print_debug('MAINTAIN_MO_CON - Case of Return/Correct',1);
6947       END IF;
6948 
6949       /* Bug 6830559 */
6950       IF (p_project_id IS NULL) THEN
6951 	 IF (p_po_distribution_id IS NOT NULL) THEN
6952 	    BEGIN
6953 	       SELECT project_id,
6954 		 Nvl(task_id, '')  -- Bug 7355205
6955 		 INTO l_project_id,
6956 		 l_task_id
6957 		 FROM po_distributions_all
6958 		 WHERE po_distribution_id = p_po_distribution_id;
6959 	    EXCEPTION
6960 	       WHEN no_data_found THEN
6961 		  l_project_id := NULL;
6962 		  l_task_id := NULL;
6963 	    END ;
6964          ELSIF (p_po_line_location_id IS NOT NULL) then
6965             inv_rcv_std_rcpt_apis.get_project_task(
6966                  p_po_line_location_id     => p_po_line_location_id
6967                , p_oe_order_line_id        => NULL
6968                , x_project_id              => l_project_id
6969                , x_task_id                 => l_task_id
6970             );
6971 	 END IF;
6972       ELSE --IF (p_project_id IS NULL) THEN
6973 		  l_project_id := p_project_id;
6974 		  l_task_id := p_task_id;
6975       END IF; --IF (p_project_id IS NULL) THEN
6976 
6977       -- PUT THE VALUES IN THE STRUCTURE HERE
6978       l_mol_res_in(1).transaction_type       := l_transaction_type;
6979       l_mol_res_in(1).organization_id        := p_org_id;
6980       l_mol_res_in(1).inventory_item_id      := p_item_id;
6981       l_mol_res_in(1).lot_number             := p_lot_number;
6982       l_mol_res_in(1).item_revision          := p_revision;
6983 
6984       -- l_mol_res_in(1).cost_group_id          := null; ????
6985 
6986       l_mol_res_in(1).project_id             := l_project_id;
6987       l_mol_res_in(1).task_id                := l_task_id;
6988       l_mol_res_in(1).uom_code               := p_uom_code;
6989       l_mol_res_in(1).quantity               := p_qty;
6990       l_mol_res_in(1).backorder_delivery_detail_id := null;
6991       l_mol_res_in(1).crossdock_type         := null;
6992       l_mol_res_in(1).transfer_org_id        := l_transfer_org_id;
6993       l_mol_res_in(1).secondary_quantity     := p_sec_qty;
6994       l_mol_res_in(1).secondary_uom          := p_sec_uom;
6995 
6996       l_mol_res_in(1).inspection_status      := l_from_mol_inspection_status ;
6997       l_mol_res_in(1).line_id                := null;
6998 
6999       l_mol_res_in(1).primary_uom_code       := p_primary_uom_code;
7000       l_mol_res_in(1).primary_qty            := p_primary_quantity;
7001       l_mol_res_in(1).po_header_id           := l_po_header_id;
7002       l_mol_res_in(1).po_line_location_id    := p_po_line_location_id;
7003       l_mol_res_in(1).shipment_line_id       := p_shipment_line_id;
7004       l_mol_res_in(1).requisition_line_id    := l_requisition_line_id;
7005       l_mol_res_in(1).auto_transact_code     := p_auto_transact_code;
7006       l_mol_res_in(1).wip_supply_type        := null;
7007       l_mol_res_in(1).routing_header_id      := p_routing_header_id;
7008       l_mol_res_in(1).source_document_code   := l_source_document_code;
7009       l_mol_res_in(1).parent_transaction_id  := l_transaction_id;
7010       l_mol_res_in(1).parent_txn_type        := l_parent_txn_type;
7011       l_mol_res_in(1).grand_parent_txn_type  := l_grand_parent_txn_type;
7012       l_mol_res_in(1).asn_line_flag          := p_asn_line_flag;
7013 
7014 
7015       IF ((l_transaction_type = 'CORRECT'
7016 	   AND ((p_primary_quantity < 0 AND l_parent_txn_type IN ('RECEIVE','ACCEPT','REJECT','TRANSFER','RETURN TO RECEIVING'))
7017 		OR (p_primary_quantity > 0 AND ((l_parent_txn_type IN ('ACCEPT','REJECT','TRANSFER','DELIVER'))
7018 						OR (l_parent_txn_type IN ('RETURN TO VENDOR','RETURN TO CUSTOMER')
7019 						    AND l_grand_parent_txn_type <> 'DELIVER')))))
7020 	  OR (l_transaction_type IN ('RETURN TO VENDOR','RETURN TO CUSTOMER') AND l_parent_txn_type <> 'DELIVER')) THEN
7021 
7022          IF (l_debug = 1) THEN
7023                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 1',1);
7024          END IF;
7025 
7026 	 IF (l_parent_txn_type = 'RETURN TO RECEIVING') THEN
7027 
7028             IF (l_debug = 1) THEN
7029                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 2',1);
7030             END IF;
7031 
7032             l_mol_res_in(1).lpn_id          := p_lpn_id;
7033             -- FROM SUB
7034             l_mol_res_in(1).from_subinventory_code := p_from_subinventory;
7035             l_mol_res_in(1).from_locator_id        := p_from_locator_id;
7036             -- DEST SUB/LOC
7037             --l_transfer_sub        := p_subinventory;
7038             --l_transfer_locator_id := p_locator_id ;
7039             --l_mol_transfer_lpn_id := p_transfer_lpn_id;
7040 
7041 	  ELSIF ((l_transaction_type = 'CORRECT' AND p_primary_quantity < 0)
7042 		 AND l_parent_txn_type <> 'RETURN TO RECEIVING') THEN
7043 
7044             IF (l_debug = 1) THEN
7045                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 3',1);
7046             END IF;
7047 
7048             l_mol_res_in(1).lpn_id          := p_transfer_lpn_id;
7049 
7050 	    --See BUG 4502518 Issue 32
7051             l_mol_res_in(1).from_subinventory_code := p_from_subinventory;
7052             l_mol_res_in(1).from_locator_id        := p_from_locator_id;
7053 
7054             -- DEST SUB/LOC
7055             --l_transfer_sub        := p_from_subinventory;
7056             --l_transfer_locator_id := p_from_locator_id ;
7057             --l_mol_transfer_lpn_id :=  p_lpn_id;
7058 
7059 
7060 	  ELSIF (l_transaction_type IN ('RETURN TO CUSTOMER','RETURN TO VENDOR')) THEN
7061 
7062             IF (l_debug = 1) THEN
7063                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 4',1);
7064             END IF;
7065 
7066             l_mol_res_in(1).lpn_id          := p_lpn_id;
7067 
7068             -- FROM SUB
7069             l_mol_res_in(1).from_subinventory_code := p_from_subinventory;
7070             l_mol_res_in(1).from_locator_id        := p_from_locator_id;
7071             -- DEST SUB/LOC
7072             --l_transfer_sub        := p_subinventory;
7073             --l_transfer_locator_id := p_locator_id ;
7074             --l_mol_transfer_lpn_id := p_transfer_lpn_id;
7075 
7076 	  ELSIF (l_transaction_type = 'CORRECT' AND p_primary_quantity > 0) THEN
7077 
7078             IF (l_debug = 1) THEN
7079                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 5',1);
7080             END IF;
7081 
7082             l_mol_res_in(1).lpn_id          := p_lpn_id;
7083             -- FROM SUB
7084             l_mol_res_in(1).from_subinventory_code := p_from_subinventory;
7085             l_mol_res_in(1).from_locator_id        := p_from_locator_id;
7086             -- DEST SUB/LOC
7087             --l_transfer_sub        := p_subinventory;
7088             --l_transfer_locator_id := p_locator_id ;
7089             --l_mol_transfer_lpn_id := p_transfer_lpn_id;
7090 
7091 	 END IF;
7092 
7093 	 IF (l_debug = 1) THEN
7094 	    print_debug('MAINTAIN_MO_CON - Txn ID to Consume MOL:'||l_mol_txn_id,1);
7095 	    print_debug('MAINTAIN_MO_CON - LPN ID to Consume MOL:'||l_mol_lpn_id,1);
7096 	    l_progress := 'WMSINB-00000';
7097 	 END IF;
7098 
7099 	 IF (l_debug = 1) THEN
7100 	    print_debug('MAINTAIN_MO_CON - Primary Quantity: = ',1);
7101 	    l_progress := 'WMSINB-13391';
7102 	 END IF;
7103       END IF; --IF ((p_primary_quantity < 0 AND l_parent_txn_type IN
7104 
7105       IF ((l_transaction_type = 'CORRECT'
7106 	   AND ((p_primary_quantity < 0 AND (l_parent_txn_type IN ('ACCEPT','REJECT','TRANSFER','DELIVER')
7107 					     OR (l_parent_txn_type IN ('RETURN TO VENDOR','RETURN TO CUSTOMER')
7108 						 AND l_grand_parent_txn_type <> 'DELIVER')))
7109 		OR (p_primary_quantity > 0 AND l_parent_txn_type IN
7110 		    ('RECEIVE','ACCEPT','REJECT','TRANSFER','RETURN TO RECEIVING'))))
7111 	  OR (l_transaction_type = 'RETURN TO RECEIVING')) THEN
7112 
7113             IF (l_debug = 1) THEN
7114                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 6',1);
7115             END IF;
7116 
7117 	 IF (l_parent_txn_type = 'RETURN TO RECEIVING') THEN
7118 
7119             IF (l_debug = 1) THEN
7120                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 7',1);
7121             END IF;
7122 
7123             l_mol_res_in(1).lpn_id          := null;
7124             -- FROM SUB
7125             l_mol_res_in(1).from_subinventory_code := null;
7126             l_mol_res_in(1).from_locator_id        := null;
7127             -- DEST SUB/LOC
7128             l_transfer_sub        := p_subinventory;
7129             l_transfer_locator_id := p_locator_id ;
7130             l_mol_transfer_lpn_id := p_transfer_lpn_id;
7131 
7132 	  ELSIF (l_transaction_type = 'CORRECT' AND p_primary_quantity < 0) THEN
7133 
7134             IF (l_debug = 1) THEN
7135                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 8',1);
7136             END IF;
7137 
7138             --l_mol_res_in(1).lpn_id          := p_transfer_lpn_id;
7139             -- FROM SUB
7140             --l_mol_res_in(1).from_subinventory_code := p_subinventory;
7141             --l_mol_res_in(1).from_locator_id        := p_locator_id;
7142 
7143             -- DEST SUB/LOC
7144             -- This does not need to be set if it's a deliver txn.
7145           /*  if l_parent_txn_type = 'DELIVER' then -- 14547482
7146                l_transfer_sub        := null;
7147                l_transfer_locator_id := null ;
7148             else */ --Commented the code to set the sub-inventory and locator in case for -ve correction on delivery transaction also.
7149 	       --See bug 4502518 issue 32
7150                l_transfer_sub        := p_subinventory;
7151                l_transfer_locator_id := p_locator_id;
7152            -- end if;
7153 
7154             l_mol_transfer_lpn_id := p_lpn_id;
7155 
7156 	  ELSIF (l_transaction_type = 'RETURN TO RECEIVING') THEN
7157 
7158             IF (l_debug = 1) THEN
7159                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 9',1);
7160             END IF;
7161 
7162             --l_mol_res_in(1).lpn_id          := p_lpn_id;
7163             -- FROM SUB
7164             --l_mol_res_in(1).from_subinventory_code := p_from_subinventory;
7165             --l_mol_res_in(1).from_locator_id        := p_from_locator_id;
7166 
7167             -- DEST SUB/LOC
7168             l_transfer_sub        := p_subinventory;
7169             l_transfer_locator_id := p_locator_id ;
7170             l_mol_transfer_lpn_id := p_transfer_lpn_id;
7171 
7172 	  ELSIF (l_transaction_type = 'CORRECT' AND p_primary_quantity > 0
7173 		 AND l_parent_txn_type <> 'RETURN TO RECEIVING') THEN
7174 
7175             IF (l_debug = 1) THEN
7176                print_debug('MAINTAIN_MO_CON - Case of Return/Correct Case 10',1);
7177             END IF;
7178 
7179             --l_mol_res_in(1).lpn_id          := p_lpn_id;
7180             -- FROM SUB
7181             --l_mol_res_in(1).from_subinventory_code := p_from_subinventory;
7182             --l_mol_res_in(1).from_locator_id        := p_from_locator_id;
7183 
7184             -- DEST SUB/LOC
7185             l_transfer_sub        := p_subinventory;
7186             l_transfer_locator_id := p_locator_id ;
7187             l_mol_transfer_lpn_id := p_transfer_lpn_id;
7188 
7189 	 END IF;
7190       END IF; --IF ((p_quantity < 0 AND l_parent_txn_type IN
7191 
7192       IF (l_debug = 1) THEN
7193 	    print_debug('MAINTAIN_MO_CON - BEFORE CALLING RESERVATION API' ,1);
7194 
7195 	    print_debug('MAINTAIN_MO_CON - LPN ID :='      || l_mol_res_in(1).lpn_id,1);
7196 	    print_debug('MAINTAIN_MO_CON - FROM SUB :='    || l_mol_res_in(1).from_subinventory_code,1);
7197 	    print_debug('MAINTAIN_MO_CON - FROM LOCATOR :='|| l_mol_res_in(1).from_locator_id,1);
7198 
7199 	    print_debug('MAINTAIN_MO_CON - TRANSFER LPN ID := '||  l_mol_transfer_lpn_id,1);
7200 
7201 	    print_debug('MAINTAIN_MO_CON - DESTINATION SUB :='||l_transfer_sub,1);
7202 	    print_debug('MAINTAIN_MO_CON - DESTINATION LOCATOR :='||l_transfer_locator_id,1);
7203       END IF;
7204 
7205       IF (l_debug = 1) THEN
7206 	    print_debug('MAINTAIN_MO - Before calling RSERVATION'||l_progress,1);
7207 	    l_progress := 'WMSINB-13616';
7208       END IF;
7209 
7210       INV_RCV_RESERVATION_UTIL.maintain_reservations
7211 	(x_return_status => x_return_status
7212 	 ,x_msg_count     => x_msg_count
7213 	 ,x_msg_data      => x_msg_data
7214 	 ,x_mol_tb        => l_mol_res_out
7215 	 ,p_cas_mol_tb    => l_mol_res_in
7216 	 );
7217 
7218       IF (l_debug = 1) THEN
7219 	 print_debug(' maintain_reservations - After calling maintain_reservations :'||x_return_status||':'||l_progress,1);
7220 	 print_debug(' maintain_reservations - l_mol_res_out.count: '||l_mol_res_out.COUNT,1);
7221 	 l_progress := 'WMSINB-45051';
7222       END IF;
7223 
7224       IF (x_return_status <> 'S') THEN
7225 	 l_progress := 'WMSINB-45052';
7226 	 RAISE fnd_api.g_exc_error;
7227       END IF;
7228 
7229       l_progress := 'WMSINB-45053';
7230 
7231       l_loop_index := l_mol_res_out.first;
7232       LOOP
7233 
7234 	EXIT WHEN l_loop_index IS NULL;
7235 
7236         IF (l_debug = 1) THEN
7237                    print_debug('MAINTAIN_MOC_CON -Inside MOL CONSL LOOP ',1);
7238         END IF;
7239 
7240 	--Bug 4286172...BEGIN CHANGES... Null out the lot_number if the transaction is a
7241 	--desktop txn without lpn.
7242 
7243 	IF (p_validation_flag = 'N' AND l_mol_transfer_lpn_id IS NULL) THEN
7244 	   l_mol_res_out(l_loop_index).lot_number := NULL;
7245 	END IF;
7246 
7247 	IF (l_debug = 1) THEN
7248 	   print_debug('MAINTAIN_MO - Lot to Query/Create MOL:'||l_mol_res_out(l_loop_index).lot_number,1);
7249 	END IF;
7250 
7251 	--Bug 4286172...END CHANGES...
7252 
7253         open c_transfer_mol(
7254                              l_mol_transfer_lpn_id
7255                             ,l_mol_res_out(l_loop_index).inventory_item_id
7256                             ,l_mol_res_out(l_loop_index).lot_number
7257                             ,l_mol_res_out(l_loop_index).item_revision
7258                             ,l_transfer_sub
7259                             ,l_transfer_locator_id
7260                             ,l_mol_res_out(l_loop_index).project_id
7261                             ,l_mol_res_out(l_loop_index).task_id
7262                             ,l_mol_res_out(l_loop_index).uom_code
7263                             ,l_mol_res_out(l_loop_index).backorder_delivery_detail_id
7264                             ,l_mol_res_out(l_loop_index).crossdock_type
7265                             ,l_transfer_inspection_status
7266 							, l_new_reference --13935217
7267 							, l_new_reference_id --13935217
7268                             );
7269         Fetch c_transfer_mol into l_transfer_mol_rec;
7270         close c_transfer_mol;
7271 
7272         if l_transfer_mol_rec.line_id is not null
7273         then
7274            -- Move Order Line found
7275            -- Check whether MOL is from the same SOURCE
7276            IF (l_debug = 1) THEN
7277 	      print_debug('MAINTAIN_MOC_CON - Move Order Line Found line Id = '|| l_transfer_mol_rec.line_id,1);
7278            END IF;
7279 
7280            check_reference(
7281                             p_old_reference           => l_transfer_mol_rec.reference
7282                            ,p_old_reference_type_code => l_transfer_mol_rec.reference_type_code
7283                            ,p_old_reference_id        => l_transfer_mol_rec.reference_id
7284                            ,p_new_reference           => l_new_reference
7285                            ,p_new_reference_type_code => l_new_reference_type_code
7286                            ,p_new_reference_id        => l_new_reference_id
7287                            ,x_reference               => l_reference
7288                            ,x_reference_type_code     => l_reference_type_code
7289                            ,x_reference_id            => l_reference_id
7290                            ,x_transaction_type_id     => l_transaction_type_id
7291                            ,x_txn_source_type_id      => l_txn_source_type_id
7292                            ,x_return_status           => x_return_status
7293                            ,x_msg_count               => x_msg_count
7294                            ,x_msg_data                => x_msg_data
7295                           );
7296 
7297            IF (l_debug = 1) THEN
7298                 print_debug('CHECK_REFERENCE - After calling check_reference :'||x_return_status||':'||l_progress,1);
7299                 l_progress := 'WMSINB-45056';
7300            END IF;
7301 
7302            IF (x_return_status <> 'S') THEN
7303               l_progress := 'WMSINB-45058';
7304               RAISE fnd_api.g_exc_error;
7305            END IF;
7306 
7307            --
7308            -- UPDATE THE MOVE ORDER LINE HERE
7309            --
7310            update mtl_txn_request_lines
7311                set reference = l_reference
7312                   ,reference_type_code = l_reference_type_code
7313                   ,reference_id = l_reference_id
7314                   ,quantity = quantity + ABS(l_mol_res_out(l_loop_index).quantity)
7315 	          ,primary_quantity = primary_quantity + ABS(l_mol_res_out(l_loop_index).primary_qty)
7316                   ,secondary_quantity = secondary_quantity + ABS(l_mol_res_out(l_loop_index).secondary_quantity)
7317                   ,transaction_type_id = nvl(l_transaction_type_id,transaction_type_id)
7318                   ,transaction_source_type_id = nvl(l_txn_source_type_id,transaction_source_type_id)
7319              where line_id = l_transfer_mol_rec.line_id
7320            ;
7321 
7322            l_progress := 'WMSINB-45060';
7323 
7324            --
7325            -- CANCEL THE OPERATION PLAN
7326            -- IF THE LPN IS LOADED AND TASK IS DISPATCHED
7327            -- WE NEED TO FAIL HERE
7328            --
7329 
7330            l_loaded := 0;
7331 
7332            BEGIN
7333                     SELECT 1
7334                     INTO l_loaded
7335                     FROM dual
7336                     WHERE exists
7337                     (SELECT 1
7338                      FROM wms_dispatched_tasks wdt
7339                      , mtl_material_transactions_temp mmtt
7340                      WHERE mmtt.move_order_line_id =  l_transfer_mol_rec.line_id
7341                      AND wdt.transaction_temp_id = mmtt.transaction_temp_id
7342                      AND wdt.status IN (3, 4) -- dispached or loaded
7343                      AND wdt.task_type = 2 -- putaway
7344                      );
7345 
7346                   IF (l_debug = 1) THEN
7347                      print_debug('MAINTAIN_MO_CON - TASK ALREADY LOADED FOR '||l_transfer_mol_rec.line_id || ' FAILURE' ,1);
7348                   END IF;
7349 
7350                   l_progress := 'WMSINB-45063';
7351                   RAISE fnd_api.g_exc_error;
7352 
7353            EXCEPTION
7354              WHEN NO_DATA_FOUND THEN
7355                   l_progress := 'WMSINB-45064';
7356                   null;
7357            END;
7358 
7359            call_atf_api(x_return_status => x_return_status,
7360                             x_msg_data => x_msg_data,
7361                             x_msg_count => x_msg_count,
7362                             x_error_code => l_error_code,
7363                             p_source_task_id => NULL,
7364                             p_activity_type_id => 1,
7365                             p_operation_type_id => NULL,
7366                             p_mol_id => l_transfer_mol_rec.line_id,
7367                             p_atf_api_name => g_atf_api_cancel);
7368 
7369            IF (x_return_status <> g_ret_sts_success) THEN
7370                   IF (l_debug = 1) THEN
7371                      print_debug('MAINTAIN_MO_CON - call_atf_api failed:'||l_transfer_mol_rec.line_id,1);
7372                      l_progress := 'WMSINB-45063';
7373                   END IF;
7374                   --raise error
7375                   l_progress := 'WMSINB-45064';
7376                   RAISE fnd_api.g_exc_error;
7377            END IF;
7378 
7379         Else
7380 
7381            -- Move Order Line Not Found Create Move Order
7382 
7383            IF (l_debug = 1) THEN
7384 	      print_debug('MAINTAIN_MOC_CON - Move Order Line Not Found line Id ',1);
7385            END IF;
7386 
7387            --create mol
7388            -- Bug 4508608. Abs of Qty is passed for negative correction when creating MOL
7389 
7390            inv_rcv_std_rcpt_apis.create_move_order(p_move_order_header_id => l_move_order_header_id
7391                                               ,p_po_line_location_id      => p_po_line_location_id
7392                                               ,p_po_distribution_id       => p_po_distribution_id
7393                                               ,p_shipment_line_id         => p_shipment_line_id
7394                                               ,p_oe_order_line_id         => p_oe_order_line_id
7395                                               ,p_routing                  => p_routing_header_id
7396                                               ,p_lot_control_code         => p_lot_control_code
7397                                               ,p_org_id                   => l_mol_res_out(l_loop_index).organization_id
7398                                               ,p_item_id                  => l_mol_res_out(l_loop_index).inventory_item_id
7399                                               ,p_qty                      => ABS(l_mol_res_out(l_loop_index).quantity)
7400                                               ,p_uom_code                 => l_mol_res_out(l_loop_index).uom_code
7401                                               ,p_lpn                      => l_mol_transfer_lpn_id
7402                                               ,p_project_id               => l_mol_res_out(l_loop_index).project_id
7403                                               ,p_task_id                  => l_mol_res_out(l_loop_index).task_id
7404                                               ,p_revision                 => l_mol_res_out(l_loop_index).item_revision
7405                                               ,p_inspect                  => l_transfer_inspection_status
7406                                               ,p_txn_source_id            => null
7407                                               ,x_status                   => x_return_status
7408                                               ,x_message                  => x_msg_data
7409                                               ,p_transfer_org_id          => l_mol_res_out(l_loop_index).transfer_org_id
7410                                               ,p_wms_process_flag         => 1
7411                                               ,p_lot_number               => l_mol_res_out(l_loop_index).lot_number
7412                                               ,p_secondary_quantity       => ABS(l_mol_res_out(l_loop_index).secondary_quantity)
7413                                               ,p_secondary_uom            => l_mol_res_out(l_loop_index).secondary_uom
7414                                               ,x_line_id                  => l_move_order_line_id
7415                                               );
7416             IF (l_debug = 1) THEN
7417                  print_debug('MAINTAIN_MO_CON - After calling create_move_order:'||x_return_status||':'||l_progress,1);
7418                  print_debug('MAINTAIN_MO_CON - Move Order Header ID:'||l_move_order_header_id||':'||l_progress,1);
7419                  print_debug('MAINTAIN_MO_CON - Move Order Line ID:'||l_move_order_line_id||':'||l_progress,1);
7420             END IF;
7421 
7422             IF (x_return_status <> 'S') THEN
7423                l_progress := 'WMSINB-45064';
7424                RAISE fnd_api.g_exc_error;
7425             END IF;
7426 
7427            --update mol for the sub and loc
7428            UPDATE mtl_txn_request_lines
7429               SET from_subinventory_code = Nvl(l_transfer_sub,from_subinventory_code)
7430               , from_locator_id = Nvl(l_transfer_locator_id, from_locator_id)
7431               WHERE header_id = l_move_order_header_id
7432                 and line_id = l_move_order_line_id
7433                 and organization_id = p_org_id
7434                 AND inventory_item_id = p_item_id;
7435 
7436 	   -- Call to UPDATE WDD
7437 	   IF (l_mol_res_out(l_loop_index).backorder_delivery_detail_id IS NOT NULL) THEN
7438 	      inv_rcv_reservation_util.update_wdd
7439 		(x_return_status => x_return_status
7440 		 ,x_msg_count    => x_msg_count
7441 		 ,x_msg_data     => x_msg_data
7442 		 ,p_wdd_id       => l_mol_res_out(l_loop_index).backorder_delivery_detail_id
7443 		 ,p_released_status => null
7444 		 ,p_mol_id          => l_move_order_line_id
7445 		 );
7446 	   END IF;
7447 
7448 
7449            IF (l_debug = 1) THEN
7450                  print_debug('MAINTAIN_MO_CON - After calling update_wdd '||x_return_status||':'||l_progress,1);
7451                  print_debug('MAINTAIN_MO_CON - Move Order Header ID:'||l_move_order_header_id||':'||l_progress,1);
7452            END IF;
7453 
7454            IF (x_return_status <> 'S') THEN
7455                l_progress := 'WMSINB-45064';
7456                RAISE fnd_api.g_exc_error;
7457            END IF;
7458         End if;
7459 
7460 	l_loop_index := l_mol_res_out.next(l_loop_index);
7461       End Loop;
7462 
7463 
7464       --We need to update the wms_process_flag on mol for all the lines for the given lpn as
7465       --we update all the mols for the given lpn to 2 in mark_returns
7466 
7467       UPDATE mtl_txn_request_lines
7468 	SET wms_process_flag = 1
7469 	WHERE (lpn_id = p_lpn_id
7470 	       OR lpn_id = p_transfer_lpn_id);
7471 
7472    END IF; --IF (l_transaction_type = 'CORRECT') THEN
7473 
7474 
7475    -- The transaction is complete so call the complete op instance now
7476    IF (l_transaction_type <> 'DELIVER') THEN
7477       IF p_mmtt_temp_id IS NOT NULL THEN
7478 	 IF (l_debug = 1) THEN
7479 	    print_debug('MAINTAIN_MO - calling call_atf_api:'||p_mmtt_temp_id,1);
7480 	    l_progress := 'WMSINB-13721';
7481 	 END IF;
7482 
7483 	 IF (l_transaction_type IN ('ACCEPT','REJECT')) THEN
7484 	    l_operation_type := wms_globals.g_op_type_inspect;
7485 	  ELSE
7486 	    l_operation_type := NULL;
7487 	 END IF;
7488 
7489 	 call_atf_api(x_return_status => x_return_status,
7490 		      x_msg_data => x_msg_data,
7491 		      x_msg_count => x_msg_count,
7492 		      x_error_code => l_error_code,
7493 		      p_source_task_id => p_mmtt_temp_id,
7494 		      p_activity_type_id => 1,
7495 		      p_operation_type_id => l_operation_type,
7496 		      p_mol_id => NULL,
7497 		      p_atf_api_name => g_atf_api_complete);
7498 
7499 	 IF (l_debug = 1) THEN
7500 	    print_debug('MAINTAIN_MO - Error Code from ATF API:'||l_error_code,1);
7501 	 END IF;
7502 
7503 	 IF (x_return_status <> g_ret_sts_success) THEN
7504 	    IF (l_error_code <> 15 OR l_error_code IS NULL) THEN
7505 	       IF (l_debug = 1) THEN
7506 		  print_debug('MAINTAIN_MO - call_atf_api failed:'||p_mmtt_temp_id,1);
7507 	       END IF;
7508 	       --raise error
7509 	       l_progress := 'WMSINB-13750';
7510 	       RAISE fnd_api.g_exc_error;
7511 	     ELSE --IF (l_error_code <> 15) THEN
7512 	       x_return_status := g_ret_sts_success;
7513 	    END IF; --IF (l_error_code <> 15) THEN
7514 	 END IF;
7515       END IF; --IF p_mmtt_temp_id IS NOT NULL THEN
7516    END IF; --IF (l_transaction_type <> 'DELIVER') THEN
7517 
7518 --Added for 13395566
7519 -- By this time the LPN has been created and the RT and RLS have been posted.
7520 -- We would error out the transaction if the MO Line has quantity <= 0
7521 -- or MTRL Sub/Loc is not same as that stamped on WLPN. The api TXN_COMPLETE
7522 -- will be called with a status FALSE and would Rollback any work done by the TM.
7523    IF p_transfer_lpn_id IS NOT NULL AND l_transaction_type IN ('ACCEPT','REJECT','RECEIVE')--14137465
7524    THEN
7525       BEGIN
7526          IF (l_debug = 1)
7527          THEN
7528             print_debug ('MAINTAIN_MO - p_transfer_lpn_id :'|| p_transfer_lpn_id,1);
7529             print_debug ('MAINTAIN_MO - p_org_id :' || p_org_id, 1);
7530             print_debug ('MAINTAIN_MO - p_lpn_id :' || p_lpn_id, 1);
7531             print_debug ('MAINTAIN_MO - p_subinventory :' || p_subinventory,1);
7532             print_debug ('MAINTAIN_MO - p_locator_id :' || p_locator_id, 1);
7533             print_debug ('MAINTAIN_MO - p_from_subinventory :'|| p_from_subinventory,1);
7534             print_debug ('MAINTAIN_MO - p_from_locator_id :'|| p_from_locator_id,1);
7535          END IF;
7536 
7537          SELECT 'Y', mtrl.from_subinventory_code, mtrl.from_locator_id,
7538                 mtrl.quantity
7539            INTO l_discrepancy_exist, l_mol_sub, l_mol_loc_id,
7540                 l_mol_qty_in_puom
7541            FROM wms_license_plate_numbers wlpn, mtl_txn_request_lines mtrl
7542           WHERE wlpn.lpn_id = p_transfer_lpn_id
7543             AND wlpn.lpn_context = 3
7544             AND wlpn.organization_id = p_org_id
7545             AND wlpn.organization_id = mtrl.organization_id
7546             AND wlpn.lpn_id = mtrl.lpn_id
7547             AND mtrl.line_status = 7
7548             AND (   (    NVL (wlpn.subinventory_code, '@@@') <>
7549                                       NVL (mtrl.from_subinventory_code, '@@@')
7550                      AND NVL (wlpn.locator_id, -999) <>
7551                                                NVL (mtrl.from_locator_id,
7552                                                     -999)
7553                     )
7554                  OR mtrl.quantity <= 0
7555                 )
7556             AND ROWNUM = 1;
7557       EXCEPTION
7558          WHEN OTHERS
7559          THEN
7560             l_discrepancy_exist := 'N';
7561             l_mol_sub := NULL;
7562             l_mol_loc_id := NULL;
7563             l_mol_qty_in_puom := NULL;
7564       END;
7565 
7566       IF (l_debug = 1)
7567       THEN
7568          print_debug ('MAINTAIN_MO - Discrepancy? ' || l_discrepancy_exist,1);
7569       END IF;
7570 
7571       IF l_discrepancy_exist = 'Y'
7572       THEN
7573          IF (l_debug = 1)
7574          THEN
7575             print_debug ('MAINTAIN_MO - MOL Subinventory :'|| l_mol_sub, 1);
7576             print_debug ('MAINTAIN_MO - MOL Locator      :'|| l_mol_loc_id, 1);
7577             print_debug ('MAINTAIN_MO - MOL Quantity     :'|| l_mol_qty_in_puom,1);
7578             print_debug ('MAINTAIN_MO - Discrepancy in MTRL/WLPN - Sub/Loc or MTRL qty <=0. Error Out the Transaction',1);
7579          END IF;
7580 
7581          l_progress := 'WMSINB:MOMIS001';
7582          fnd_message.set_name ('WMS', 'WMS_LPN_SUBLOC_MISMATCH');
7583          fnd_msg_pub.ADD;
7584          RAISE fnd_api.g_exc_error;
7585       END IF;
7586    END IF;
7587  --13395566
7588 
7589 
7590    /* You do not want to update the wms_process_flag here because
7591       another RTI within the same group may want to process the
7592       same MOL, which has been marked by the UI.  Updating the MOL
7593       should have been performed in the logic above.  Note that this
7594       assumes that the UI have marked the correct MOL for processing
7595 
7596    --Update the wms_process_flag for all MOLs for the fiven lpns
7597    UPDATE mtl_txn_request_lines
7598      SET wms_process_flag = 1
7599      WHERE lpn_id = p_lpn_id;
7600 
7601    UPDATE mtl_txn_request_lines
7602      SET wms_process_flag = 1
7603      WHERE lpn_id = p_transfer_lpn_id;
7604      */
7605 EXCEPTION
7606    WHEN fnd_api.g_exc_error THEN
7607       x_return_status  := g_ret_sts_error;
7608       IF (l_debug = 1) THEN
7609 	 print_debug('MAINTAIN_MO - execution error:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
7610       END IF;
7611    WHEN fnd_api.g_exc_unexpected_error THEN
7612       x_return_status  := g_ret_sts_unexp_error;
7613       IF (l_debug = 1) THEN
7614 	 print_debug('MAINTAIN_MO - unexpected error:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
7615       END IF;
7616    WHEN OTHERS THEN
7617       X_RETURN_STATUS  := G_RET_STS_UNEXP_ERROR;
7618       IF (L_DEBUG = 1) THEN
7619 	 PRINT_DEBUG('MAINTAIN_MO - OTHER EXCEPTION:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
7620       END IF;
7621 
7622       IF SQLCODE IS NOT NULL THEN
7623 	 INV_MOBILE_HELPER_FUNCTIONS.SQL_ERROR('INV_RCV_INTERFACE_PVT.MAINTAIN_MO', l_progress,SQLCODE);
7624       END IF;
7625       -- GET MESSAGE COUNT AND DATA
7626       -- FND_MSG_PUB.COUNT_AND_GET(P_ENCODED => G_FALSE, P_COUNT => X_MSG_COUNT, P_DATA => X_MSG_DATA);
7627 END maintain_mo_con;
7628 -- R12
7629 
7630 --bug8731994 check whether the org is wms org or not
7631 Function is_wms_enabled(
7632         p_org_id                IN  NUMBER
7633         ) return boolean
7634 IS
7635 l_wms_enabled  varchar2(1);
7636 success        boolean :=false;
7637 BEGIN
7638 
7639   SELECT NVL(wms_enabled_flag,'N')
7640   INTO   l_wms_enabled
7641   FROM   mtl_parameters
7642   WHERE  organization_id = p_org_id ;
7643 
7644   IF l_wms_enabled <> 'N' THEN
7645     success := true;
7646   END IF;
7647   return success;
7648 
7649   EXCEPTION
7650     WHEN OTHERS then
7651       success := false;
7652       RETURN success;
7653 END is_wms_enabled ;
7654 
7655 PROCEDURE maintain_mo_wrapper(
7656                       p_rti_id IN NUMBER,
7657        		      p_primary_quantity IN NUMBER,
7658        		      p_primary_uom_code IN VARCHAR2,
7659        		      p_mmtt_temp_id IN NUMBER,
7660        		      p_org_id IN NUMBER,
7661        		      p_item_id IN NUMBER,
7662        		      p_revision IN VARCHAR2,
7663        		      p_qty IN NUMBER,
7664        		      p_uom_code IN VARCHAR2,
7665        		      p_lpn_id IN NUMBER,
7666        		      p_transfer_lpn_id IN NUMBER,
7667        		      p_lot_control_code IN NUMBER,
7668        		      p_serial_number_control_code IN NUMBER,
7669        		      p_po_line_location_id IN NUMBER,
7670        		      p_po_distribution_id IN NUMBER,
7671        		      p_shipment_line_id IN NUMBER,
7672        		      p_oe_order_line_id IN NUMBER,
7673        		      p_routing_header_id IN NUMBER,
7674        		      p_subinventory IN VARCHAR2,
7675        		      p_locator_id IN NUMBER,
7676        		      p_from_subinventory IN VARCHAR2,
7677        		      p_from_locator_id IN NUMBER,
7678        		      p_project_id IN NUMBER DEFAULT NULL,
7679        		      p_task_id IN NUMBER DEFAULT NULL,
7680        		      x_transaction_id OUT nocopy NUMBER,
7681        		      x_return_status OUT nocopy VARCHAR2,
7682        		      x_msg_count OUT nocopy NUMBER,
7683        		      x_msg_data OUT nocopy VARCHAR2,
7684                       -- OPMConvergence
7685                       p_sec_qty IN NUMBER DEFAULT NULL,
7686                       p_sec_uom IN VARCHAR2 DEFAULT NULL,
7687                       -- OPMConvergence
7688                       p_auto_transact_code IN VARCHAR2 DEFAULT NULL,
7689                       p_asn_line_flag IN VARCHAR2 DEFAULT NULL ,
7690                       p_validation_flag IN VARCHAR2 DEFAULT NULL,
7691                       -- Bug# 7154105
7692                       p_req_distribution_id IN NUMBER DEFAULT NULL
7693   )
7694   IS
7695      CURSOR c_mtlt(p_product_txn_id NUMBER) IS
7696 	SELECT Ltrim(Rtrim(lot_number)) lot_number,
7697 	  Sum(transaction_quantity) transaction_quantity,    --Sum the three qty for Bug 14117094
7698 	  Sum(primary_quantity) primary_quantity,
7699           -- OPMConvergence
7700           Sum(secondary_quantity) secondary_quantity
7701           -- OPMConvergence
7702 	  FROM mtl_transaction_lots_temp
7703 	  WHERE product_code = 'RCV'
7704 	  AND product_transaction_id = p_product_txn_id
7705     GROUP BY lot_number;
7706 
7707      l_mtlt_rec c_mtlt%ROWTYPE;
7708 
7709      l_num_lot_recs NUMBER := 0;
7710 
7711      l_lot_primary_qty NUMBER := 0;
7712      l_lot_txn_qty NUMBER := 0;
7713 
7714      l_progress VARCHAR2(15) := '00';
7715      L_DEBUG NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
7716      l_proc_name  VARCHAR2(30) := 'MAINTAIN_MO_WRAPPER';
7717 
7718      -- OPMConvergence
7719      l_lot_sec_qty  NUMBER;
7720      -- OPMConvergence
7721 BEGIN
7722    x_return_status := g_ret_sts_success;
7723 
7724    --bug8731994,if non-wms org ,stop move order creation
7725    IF(nvl(g_org_id,-1)=p_org_id and g_org_wms_enabled=false) THEN
7726      IF (l_debug = 1) THEN
7727        PRINT_DEBUG('NON-WMS ORG,STOP CREATING MO', 1);
7728      END IF;
7729      return;
7730    ELSE IF(nvl(g_org_id,-1)<>p_org_id) THEN
7731      g_org_id := p_org_id;
7732      g_org_wms_enabled := is_wms_enabled(p_org_id);
7733      IF(NOT g_org_wms_enabled) THEN
7734        IF (l_debug = 1) THEN
7735          PRINT_DEBUG('NON-WMS ORG,STOP CREATING MO', 1);
7736        END IF;
7737        return;
7738      END IF;
7739     END IF;
7740    END IF;
7741 
7742    IF (l_debug = 1) THEN
7743       PRINT_DEBUG('Entering MAINTAIN_MO_WRAPPER:'||l_progress, 1);
7744       PRINT_DEBUG('MAINTAIN_MO_WRAPPER - LOT CONTROL CODE:'||p_lot_control_code||':'||l_progress, 1);
7745       l_progress := 'WMSINB-13832';
7746    END IF;
7747 
7748    IF p_lot_control_code > 1 THEN
7749       IF (l_debug = 1) THEN
7750 	 PRINT_DEBUG('MAINTAIN_MO_WRAPPER - LOT CONTROLLED:'||l_progress, 1);
7751 	 l_progress := 'WMSINB-13838';
7752       END IF;
7753 
7754       OPEN c_mtlt(p_rti_id);
7755 
7756       l_num_lot_recs := 0;
7757       LOOP
7758 	 FETCH c_mtlt INTO l_mtlt_rec;
7759 	 EXIT WHEN c_mtlt%notfound;
7760 
7761 	 IF (l_debug = 1) THEN
7762 	    PRINT_DEBUG('MAINTAIN_MO_WRAPPER - LOT NUMBER:'||l_mtlt_rec.lot_number||':'||l_progress, 1);
7763 	    PRINT_DEBUG('MAINTAIN_MO_WRAPPER - LOT PRIMARY QTY:'||l_mtlt_rec.primary_quantity||':'||l_progress, 1);
7764             -- OPMConvergence
7765 	    PRINT_DEBUG(l_proc_name||'- LOT SEC QTY:'||l_mtlt_rec.secondary_quantity||':'||l_progress, 1);
7766 	    -- OPMConvergence
7767 	    l_progress := 'WMSINB-13851';
7768 	 END IF;
7769 
7770 	 l_lot_primary_qty := (Sign(p_primary_quantity)) * l_mtlt_rec.primary_quantity;
7771 	 l_lot_txn_qty := (Sign(p_primary_quantity)) * l_mtlt_rec.transaction_quantity;
7772          -- OPMConvergence
7773 	 l_lot_sec_qty := (sign(p_primary_quantity)) * l_mtlt_rec.secondary_quantity;
7774          -- OPMConvergence
7775 	 l_num_lot_recs := l_num_lot_recs + 1;
7776 
7777 
7778 
7779          maintain_mo_con(
7780              p_rti_id => p_rti_id,
7781              p_primary_quantity => l_lot_primary_qty,
7782              p_primary_uom_code => p_primary_uom_code,
7783              p_mmtt_temp_id => p_mmtt_temp_id,
7784              p_org_id => p_org_id,
7785              p_item_id => p_item_id,
7786              p_revision => p_revision,
7787              p_qty => l_lot_txn_qty,
7788              p_uom_code => p_uom_code,
7789              p_lpn_id => p_lpn_id,
7790              p_transfer_lpn_id => p_transfer_lpn_id,
7791              p_lot_control_code => p_lot_control_code,
7792              p_serial_number_control_code => p_serial_number_control_code,
7793              p_lot_number => l_mtlt_rec.lot_number,
7794              p_po_line_location_id => p_po_line_location_id,
7795              p_po_distribution_id => p_po_distribution_id,
7796              p_shipment_line_id => p_shipment_line_id,
7797              p_oe_order_line_id => p_oe_order_line_id,
7798              p_routing_header_id => p_routing_header_id,
7799              p_subinventory => p_subinventory,
7800              p_locator_id => p_locator_id,
7801              p_from_subinventory => p_from_subinventory,
7802              p_from_locator_id => p_from_locator_id,
7803              p_project_id => p_project_id,
7804              p_task_id => p_task_id,
7805              x_transaction_id => x_transaction_id,
7806              x_return_status => x_return_status,
7807              x_msg_count => x_msg_count,
7808              x_msg_data => x_msg_data,
7809              -- OPMConvergence
7810              p_sec_uom => p_sec_uom,
7811              p_sec_qty => l_lot_sec_qty,
7812              -- OPMConvergence
7813 	     p_auto_transact_code => p_auto_transact_code,
7814 	     p_asn_line_flag => p_asn_line_flag,
7815 	     p_validation_flag => p_validation_flag,
7816          -- Bug# 7154105
7817          p_req_distribution_id => p_req_distribution_id
7818 	   );
7819 
7820 	 IF (l_debug = 1) THEN
7821 	    PRINT_DEBUG('MAINTAIN_MO_WRAPPER - MAINTAIN_MO RETURNED:'||x_return_status||':'||l_progress, 1);
7822 	    l_progress := 'WMSINB-13889';
7823 	 END IF;
7824 
7825 	 IF (x_return_status <> 'S') THEN
7826 	    l_progress := 'WMSINB-13893';
7827 	    RAISE fnd_api.g_exc_error;
7828 	 END IF;
7829       END LOOP;
7830 
7831       CLOSE c_mtlt;
7832    END IF;
7833 
7834    IF (l_debug = 1) THEN
7835       PRINT_DEBUG('MAINTAIN_MO_WRAPPER - NUM OF LOT RECS:'||l_num_lot_recs||':'||l_progress, 1);
7836       l_progress := 'WMSINB-13903';
7837    END IF;
7838 
7839    IF (p_lot_control_code = 1 OR l_num_lot_recs = 0) THEN
7840       maintain_mo_con(p_rti_id => p_rti_id,
7841         	  p_primary_quantity => p_primary_quantity,
7842         	  p_primary_uom_code => p_primary_uom_code,
7843         	  p_mmtt_temp_id => p_mmtt_temp_id,
7844         	  p_org_id => p_org_id,
7845         	  p_item_id => p_item_id,
7846         	  p_revision => p_revision,
7847         	  p_qty => p_qty,
7848         	  p_uom_code => p_uom_code,
7849         	  p_lpn_id => p_lpn_id,
7850         	  p_transfer_lpn_id => p_transfer_lpn_id,
7851         	  p_lot_control_code => p_lot_control_code,
7852         	  p_serial_number_control_code => p_serial_number_control_code,
7853         	  p_lot_number => NULL,
7854         	  p_po_line_location_id => p_po_line_location_id,
7855         	  p_po_distribution_id => p_po_distribution_id,
7856         	  p_shipment_line_id => p_shipment_line_id,
7857         	  p_oe_order_line_id => p_oe_order_line_id,
7858         	  p_routing_header_id => p_routing_header_id,
7859         	  p_subinventory => p_subinventory,
7860         	  p_locator_id => p_locator_id,
7861         	  p_from_subinventory => p_from_subinventory,
7862         	  p_from_locator_id => p_from_locator_id,
7863         	  p_project_id => p_project_id,
7864         	  p_task_id => p_task_id,
7865         	  x_transaction_id => x_transaction_id,
7866         	  x_return_status => x_return_status,
7867         	  x_msg_count => x_msg_count,
7868                   x_msg_data => x_msg_data,
7869                   -- OPMConvergence
7870                   p_sec_uom => p_sec_uom,
7871                   p_sec_qty => p_sec_qty,
7872                   -- OPMConvergence
7873 	          p_auto_transact_code => p_auto_transact_code,
7874 	          p_asn_line_flag => p_asn_line_flag,
7875 	          p_validation_flag => p_validation_flag,
7876               -- Bug# 7154105
7877               p_req_distribution_id => p_req_distribution_id
7878                   );
7879       IF (l_debug = 1) THEN
7880 	 PRINT_DEBUG('MAINTAIN_MO_WRAPPER - MAINTAIN_MO RETURNED:'||x_return_status||':'||l_progress, 1);
7881 	 l_progress := 'WMSINB-13937';
7882       END IF;
7883 
7884       IF (x_return_status <> 'S') THEN
7885 	 l_progress := 'WMSINB-13941';
7886 	 RAISE fnd_api.g_exc_error;
7887       END IF;
7888    END IF;
7889 
7890    IF (l_debug = 1) THEN
7891       print_debug('MAINTAIN_MO_WRAPPER - Sucessfull:'||':'||l_progress, 1);
7892    END IF;
7893 
7894 EXCEPTION
7895    WHEN fnd_api.g_exc_error THEN
7896       x_return_status  := g_ret_sts_error;
7897       IF (l_debug = 1) THEN
7898 	 print_debug('MAINTAIN_MO_WRAPPER - execution error:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
7899       END IF;
7900    WHEN fnd_api.g_exc_unexpected_error THEN
7901       x_return_status  := g_ret_sts_unexp_error;
7902       IF (l_debug = 1) THEN
7903 	 print_debug('MAINTAIN_MO_WRAPPER - unexpected error:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
7904       END IF;
7905    WHEN OTHERS THEN
7906       X_RETURN_STATUS  := G_RET_STS_UNEXP_ERROR;
7907       IF (L_DEBUG = 1) THEN
7908 	 PRINT_DEBUG('MAINTAIN_MO_WRAPPER - OTHER EXCEPTION:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
7909       END IF;
7910 
7911       IF SQLCODE IS NOT NULL THEN
7912 	 INV_MOBILE_HELPER_FUNCTIONS.SQL_ERROR('INV_RCV_INTERFACE_PVT.MAINTAIN_MO',l_progress, SQLCODE);
7913       END IF;
7914       -- GET MESSAGE COUNT AND DATA
7915       -- FND_MSG_PUB.COUNT_AND_GET(P_ENCODED => G_FALSE, P_COUNT => X_MSG_COUNT, P_DATA => X_MSG_DATA);
7916 END maintain_mo_wrapper;
7917 
7918 
7919 PROCEDURE process_txn(p_txn_id             IN NUMBER,
7920                       x_return_status            OUT NOCOPY VARCHAR2,
7921                       x_msg_count                OUT NOCOPY NUMBER,
7922                       x_msg_data                 OUT NOCOPY VARCHAR2
7923 		      ) IS
7924 
7925 			 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
7926 			 l_progress VARCHAR2(15) := '10';
7927 
7928 
7929 			 l_primary_uom VARCHAR2(3);
7930 			 l_primary_unit_of_measure VARCHAR2(30);
7931 			 l_lot_control_code NUMBER;
7932 			 l_serial_control_code NUMBER;
7933 			 l_revision_control_flag VARCHAR2(10);
7934                          -- OPMConvergence
7935 			 l_sec_uom_code VARCHAR2(3);
7936                          -- OPMConvergence
7937 			  l_proc_name VARCHAR2(30) := 'PROCESS_TXN';
7938 			  -- 10396979 addition
7939 			  l_wms_return_status VARCHAR2(1);
7940 			  l_wms_msg_count NUMBER;
7941 			  l_wms_msg_data VARCHAR2(2000);
7942 			  l_wms_lot number := 1;
7943 			  l_wms_lot_number varchar2(20);
7944 			  -- 10396979 addition
7945                           l_operation_val NUMBER; --add one variable for bug 13241074
7946                           l_express_receipt_flag VARCHAR2(1) := 'N'; --add one variable for bug 13241074
7947 			 cursor c_rti is
7948 			    select interface_transaction_id
7949 			      ,transaction_type
7950 			      ,item_id
7951 			      ,item_description
7952                   ,item_revision
7953 			      ,lpn_id
7954 			      ,transfer_lpn_id
7955 			      ,license_plate_number
7956 			      ,transfer_license_plate_number
7957 			      ,quantity
7958                   ,uom_code
7959                   ,unit_of_measure
7960 			      ,shipment_header_id
7961                   ,shipment_num
7962 			      ,routing_header_id
7963 			      ,to_organization_id
7964 			      ,from_organization_id
7965 			      ,subinventory
7966 			      ,locator_id
7967 			      ,from_subinventory
7968 			      ,from_locator_id
7969 			      ,parent_transaction_id
7970 			      ,source_document_code
7971                   ,group_id
7972                   ,primary_quantity
7973                   ,mmtt_temp_id
7974 			      ,po_line_location_id
7975 			      ,po_distribution_id
7976 			      ,shipment_line_id
7977 			      ,oe_order_line_id
7978                               ,auto_transact_code
7979 			      ,Nvl(validation_flag,'N') validation_flag
7980 			      ,project_id
7981 			      ,task_id
7982 			      ,Nvl(mobile_txn, 'N') mobile_txn
7983 			      ,inv_transaction_id
7984 			      ,processing_mode_code
7985                               -- OPMConvergence
7986                   ,secondary_quantity
7987                   ,secondary_unit_of_measure
7988                   ,secondary_uom_code
7989                               -- OPMConvergence
7990 			      ,requisition_line_id
7991                   ,EXPRESS_TRANSACTION   --for bug 14235799
7992                   -- Bug# 7154105
7993                   ,req_distribution_id
7994 				  ,lpn_group_id    --14408061
7995 			      from rcv_transactions_interface rti
7996 			      where rti.interface_transaction_id = p_txn_id;
7997 
7998 			 l_rti_rec c_rti%rowtype;
7999 
8000 			 l_parent_txn_type varchar2(30);
8001 			 l_parent_parent_txn_type varchar2(30);
8002 			 l_parent_parent_txn_id NUMBER;
8003 
8004 			 l_from_lpn_state boolean;
8005 			 l_to_lpn_state boolean;
8006 
8007 			 l_lpn_context NUMBER;
8008 			 l_transfer_lpn_context NUMBER;
8009 
8010 			 l_cur_from_parent_lpn_id NUMBER;
8011 			 l_cur_to_parent_lpn_id NUMBER;
8012 
8013 			 l_serial_status NUMBER;
8014 			 l_inspection_status NUMBER;
8015 
8016 			 l_unpack_org_id NUMBER;
8017 
8018 			 l_rt_transaction_id NUMBER;
8019 
8020 			 l_from_org_serial_control NUMBER;
8021 			 l_from_org_lot_control NUMBER;
8022 			 l_from_org_rev_control NUMBER;
8023 			 l_full_unpack BOOLEAN := FALSE;
8024 
8025 			 l_total_lot_qty NUMBER;
8026 			 l_total_serial_qty NUMBER;
8027 
8028 			 l_asn_line_flag VARCHAR2(1) := 'N';
8029 
8030 			 l_trx_type_for_unpack VARCHAR2(30) := NULL;
8031 			 l_int_trx_id_for_unpack NUMBER := NULL;
8032 
8033 			 l_transactions_enabled_flag VARCHAR2(1);
8034 
8035 			 l_sec_txn_for_rtv VARCHAR2(1) := 'N';
8036 
8037                          l_lpn_org NUMBER;
8038 
8039                          l_parent_project_id NUMBER;
8040                          l_parent_task_id    NUMBER;
8041 
8042 			 l_wlpn_source_header_id NUMBER;
8043 			 l_xfr_wlpn_source_header_id NUMBER;
8044 
8045 			 l_intransit_type NUMBER :=0;
8046 			 l_auto_unnest_empty_lpns NUMBER := 1;
8047 
8048 			 --R12
8049 			 l_mol_res_in  cas_mol_rec_tb_tp;
8050 			 l_mol_res_out cas_mol_rec_tb_tp;
8051 			 l_po_header_id NUMBER;
8052 			 l_shipment_header_id NUMBER;
8053 			 l_requisition_line_id NUMBER;
8054 			 --6168447
8055 			 l_current_lpn_context NUMBER;
8056 			 l_ignore_item_controls NUMBER :=2;  -- 12610461
8057 			 l_unpack BOOLEAN := TRUE;--14408061
8058 			 l_lot_code           NUMBER; --15959206
8059 BEGIN
8060    x_return_status := g_ret_sts_success;
8061 
8062    IF (l_debug = 1) THEN
8063       print_debug('Inside PROCESS_TXN', 4);
8064    END IF;
8065 
8066    open c_rti;
8067    Fetch c_rti into l_rti_rec;
8068    Close c_rti;
8069 
8070    IF (l_debug = 1) THEN
8071       print_debug('TRANSACTION_TYPE: '||l_rti_rec.transaction_type,1);
8072       print_debug('VALIDATION_FLAG:  '||l_rti_rec.validation_flag,1);
8073 
8074    END IF;
8075 
8076    IF (l_rti_rec.item_id IS NULL) THEN
8077       IF (l_debug = 1) THEN
8078          print_debug('PROCESS_TXN - One Time Item Exiting...',1);
8079          l_progress := 'WMSINB-14075';
8080       END IF;
8081       RETURN;
8082    END IF;
8083 
8084    IF (l_rti_rec.transaction_type = 'UNORDERED') THEN
8085       IF (l_debug = 1) THEN
8086          print_debug('PROCESS_TXN - Unordered Transaction Exit with success...',1);
8087          l_progress := 'WMSINB-14076';
8088       END IF;
8089       RETURN;
8090    END IF;
8091 
8092    --If the source document is 'REQ' then of the intransit_type in
8093    --mtl_interorg_parameters is set to 'Direct' then exit from this api.
8094    IF (l_rti_rec.source_document_code = 'REQ'
8095        AND l_rti_rec.mobile_txn = 'N'
8096        AND l_rti_rec.transaction_type = 'RECEIVE'
8097        AND l_rti_rec.inv_transaction_id IS NOT NULL
8098        AND l_rti_rec.processing_mode_code = 'ONLINE') THEN
8099       BEGIN
8100          SELECT intransit_type
8101            INTO l_intransit_type
8102            FROM mtl_interorg_parameters
8103           WHERE from_organization_id = l_rti_rec.from_organization_id
8104             AND to_organization_id = l_rti_rec.to_organization_id;
8105 
8106       EXCEPTION
8107          WHEN OTHERS THEN
8108             NULL;
8109       END;
8110 
8111       IF (l_intransit_type = 1) THEN
8112           SELECT primary_uom_code
8113             INTO  l_primary_uom
8114             FROM mtl_system_items
8115             WHERE inventory_item_id = l_rti_rec.item_id
8116             AND organization_id = l_rti_rec.to_organization_id;
8117 
8118           IF (l_debug = 1) THEN
8119              print_debug('PROCESS_TXN - DIRECT REQ RECEIPT. CALLING RSV API',1);
8120              print_debug('l_rti_rec.transaction_type     => '||l_rti_rec.transaction_type,1);
8121              print_debug('l_rti_rec.to_organization_id   => '||l_rti_rec.to_organization_id,1);
8122              print_debug('l_rti_rec.item_id              => '||l_rti_rec.item_id,1);
8123              print_debug('l_rti_rec.item_revision        => '||l_rti_rec.item_revision,1);
8124              print_debug('l_rti_rec.project_id           => '||l_rti_rec.project_id,1);
8125              print_debug('l_rti_rec.task_id              => '||l_rti_rec.task_id,1);
8126              print_debug('l_rti_rec.primary_uom_code     => '||l_primary_uom,1);
8127              print_debug('l_rti_rec.primary_quantity     => '||l_rti_rec.primary_quantity,1);
8128              print_debug('l_rti_rec.requisition_line_id  => '||l_rti_rec.requisition_line_id,1);
8129              print_debug('l_rti_rec.auto_transact_code   => '||'DELIVER',1);
8130           END IF;
8131 
8132           l_mol_res_in(1).transaction_type       := l_rti_rec.transaction_type;
8133           l_mol_res_in(1).organization_id        := l_rti_rec.to_organization_id;
8134           l_mol_res_in(1).inventory_item_id      := l_rti_rec.item_id;
8135           l_mol_res_in(1).item_revision          := l_rti_rec.item_revision;
8136           l_mol_res_in(1).project_id             := l_rti_rec.project_id;
8137           l_mol_res_in(1).task_id                := l_rti_rec.task_id;
8138           l_mol_res_in(1).primary_uom_code       := l_primary_uom;
8139           l_mol_res_in(1).primary_qty            := l_rti_rec.primary_quantity;
8140           l_mol_res_in(1).requisition_line_id    := l_rti_rec.requisition_line_id;
8141           l_mol_res_in(1).auto_transact_code     := 'DELIVER';
8142 
8143           INV_RCV_RESERVATION_UTIL.maintain_reservations
8144             (x_return_status => x_return_status
8145              ,x_msg_count     => x_msg_count
8146              ,x_msg_data      => x_msg_data
8147              ,x_mol_tb        => l_mol_res_out
8148              ,p_cas_mol_tb    => l_mol_res_in
8149              );
8150 
8151           IF (l_debug = 1) THEN
8152              print_debug('PROCESS_TXN - rsv api returns:'||x_return_status,1);
8153           END IF;
8154 
8155           IF (x_return_status <> g_ret_sts_success) THEN
8156              l_progress := 'WMSINB-14998';
8157              RAISE FND_API.G_EXC_ERROR;
8158           END IF;
8159 
8160           RETURN;
8161       END IF;
8162 
8163    END IF; --IF (l_rti_rec.source_document_code = 'REQ') THEN
8164 
8165 
8166    l_progress := 'WMSINB-14080';
8167 
8168    -- Get The Parent Txn Details
8169    BEGIN
8170       select transaction_type,
8171              parent_transaction_id,
8172              project_id,
8173              task_id
8174         into l_parent_txn_type,
8175              l_parent_parent_txn_id,
8176              l_parent_project_id,
8177              l_parent_task_id
8178         from rcv_transactions rt
8179        where rt.transaction_id = l_rti_rec.parent_transaction_id;
8180    Exception
8181       When others then
8182           -- Review Later
8183           -- Set appropiate Message
8184           --
8185           l_progress := 'WMSINB-14095';
8186           null;
8187    End;
8188 
8189    --Bug No.      :  3159152/3101512
8190    --Description  :  The problem was receiving calls process_txn twice for a RTV txn on
8191    --top of a deliver txn - one for the RTR txn they create on
8192    --top of the deliver txn and other time for the RTV txn
8193    --created on top of the RTR txn. This was throwing too many
8194    --rows exception at WMSINB-12888.
8195    --The fix is to return from process_txn for the second time
8196    --they call us and do all the processing the first time itself.
8197    BEGIN
8198       IF l_rti_rec.transaction_type in ('RETURN TO VENDOR','RETURN TO CUSTOMER') AND
8199          l_parent_txn_type = 'DELIVER' THEN
8200           SELECT 'Y'
8201             INTO l_sec_txn_for_rtv
8202             FROM rcv_transactions
8203             WHERE transaction_type = 'RETURN TO RECEIVING'
8204             AND interface_transaction_id = p_txn_id
8205             AND exists (SELECT 1
8206                    FROM rcv_transactions
8207                    WHERE transaction_type IN ('RETURN TO VENDOR','RETURN TO CUSTOMER')
8208                    AND interface_transaction_id = p_txn_id);
8209       END IF;
8210    EXCEPTION
8211       WHEN no_data_found THEN
8212           l_sec_txn_for_rtv := 'N';
8213           l_progress := 'WMSINB-14097';
8214       WHEN OTHERS THEN
8215           l_progress := 'WMSINB-14098';
8216           RAISE fnd_api.g_exc_error;
8217    END;
8218    IF l_sec_txn_for_rtv = 'Y' THEN
8219       l_progress := 'WMSINB-14099';
8220       x_return_status := g_ret_sts_success;
8221       IF (l_debug = 1) THEN
8222           print_debug('PROCESS_TXN returned with success for one step rtv on dlvr txn', 4);
8223       END IF;
8224       RETURN;
8225    END IF;
8226 
8227    -- Get The grand Parent Txn Details
8228    Begin
8229       select transaction_type
8230         into l_parent_parent_txn_type
8231         from rcv_transactions rt
8232        where rt.transaction_id = l_parent_parent_txn_id;
8233    Exception
8234       When others then
8235          -- Review Later
8236          -- Set appropiate Message
8237          --
8238          l_progress := 'WMSINB-14110';
8239          null;
8240    End;
8241 
8242    --bug 4201926 and bug 4286203 code fix begin
8243    IF (l_rti_rec.transaction_type IN ('CORRECT','RETURN TO VENDOR',
8244                                       'RETURN TO CUSTOMER','RETURN TO RECEIVING')
8245        AND (l_parent_txn_type = 'UNORDERED' OR l_parent_parent_txn_type = 'UNORDERED')) THEN
8246       IF (l_debug = 1) THEN
8247           print_debug('PROCESS_TXN - Unordered Transaction Exit with success...',1);
8248           l_progress := 'WMSINB-14115';
8249       END IF;
8250       RETURN;
8251    END IF;
8252    --bug 4201926 and bug 4286203 code fix end
8253 
8254    -- ASN_LINE_FLAG indicates whether it's an ASN or not
8255 
8256    IF (l_rti_rec.shipment_line_id IS NOT NULL
8257        AND l_rti_rec.transaction_type = 'RECEIVE') THEN
8258       BEGIN
8259          -- This part of code is changed to take into account ASN_TYPE
8260          --SELECT Nvl(asn_line_flag, 'N')
8261          --  INTO l_asn_line_flag
8262          --  FROM rcv_shipment_lines
8263          --  WHERE shipment_line_id = l_rti_rec.shipment_line_id;
8264          --
8265         --Bug 13891514 Adding ASBN as well because the validations/processing is same for ASN/ASBN
8266           select decode(ASN_TYPE,'ASN','Y', 'ASBN','Y','N')
8267            into l_asn_line_flag
8268            from rcv_shipment_headers
8269           WHERE shipment_header_id =  l_rti_rec.shipment_header_id;
8270       EXCEPTION
8271           WHEN OTHERS THEN
8272              l_asn_line_flag := 'N';
8273       END;
8274    END IF;
8275 
8276    l_progress := 'WMSINB-14127';
8277 
8278    l_from_lpn_state := get_lpn_id(l_rti_rec.lpn_id,
8279                        l_rti_rec.license_plate_number,
8280                        l_lpn_context,l_cur_from_parent_lpn_id,l_wlpn_source_header_id);
8281 
8282    l_progress := 'WMSINB-14131';
8283 
8284    if (l_from_lpn_state <> TRUE ) then
8285       l_progress := 'WMSINB-14134';
8286       IF (l_debug = 1) THEN
8287          print_debug('Process_txn: lpn_id and license_plate number does not exist' , 1);
8288       END If;
8289       -- MSG no new message just add the one on stack
8290       -- Review Later.
8291       -- Set Appropiate MESSAGE For ERROR
8292       --
8293       l_progress := 'WMSINB-14142';
8294       RAISE FND_API.G_EXC_ERROR;
8295    end if;
8296 
8297    l_progress := 'WMSINB-14146';
8298 
8299    l_to_lpn_state := get_lpn_id(l_rti_rec.transfer_lpn_id,
8300                                 l_rti_rec.transfer_license_plate_number,
8301                                 l_transfer_lpn_context,
8302                                 l_cur_to_parent_lpn_id,
8303                                 l_xfr_wlpn_source_header_id);
8304 
8305    l_progress := 'WMSINB-14153';
8306 
8307    if (l_to_lpn_state <> TRUE ) then
8308       l_progress := 'WMSINB-14156';
8309       IF (l_debug = 1) THEN
8310          print_debug('Process_txn: transfer_lpn_id and transfer_license_plate number does not exist' , 1);
8311       END If;
8312       -- MSG no new message just add the one on stack
8313       -- EXISTING LPN_ID and LICENSE_PLATE_NUMBER COMBINATION IS INVALID
8314       -- Review Later.
8315       -- Set Appropiate MESSAGE For ERROR
8316       --
8317       l_progress := 'WMSINB-14165';
8318       RAISE FND_API.G_EXC_ERROR;
8319    End if;
8320 
8321    l_progress := 'WMSINB-14169';
8322 
8323    SELECT primary_uom_code,
8324      primary_unit_of_measure,
8325      mtl_transactions_enabled_flag,
8326      lot_control_code,
8327      serial_number_control_code,
8328      decode(revision_qty_control_code
8329        ,1, 'N'
8330        ,2, 'Y'
8331        ,'N') item_rev_control_flag,
8332      secondary_uom_code
8333    INTO  l_primary_uom,
8334      l_primary_unit_of_measure,
8335      l_transactions_enabled_flag,
8336      l_lot_control_code,
8337      l_serial_control_code,
8338      l_revision_control_flag,
8339      -- OPMConvergence
8340      l_sec_uom_code
8341      -- OPMConvergence
8342    FROM mtl_system_items
8343    WHERE inventory_item_id = l_rti_rec.item_id
8344      AND organization_id = l_rti_rec.to_organization_id;
8345 
8346    l_progress := 'WMSINB-14190';
8347 
8348    --PO tracks the revision information for non revision controlled items.
8349    --We cannot track revision if revision controll is not on, hence nulling
8350    --it OUT.
8351    IF (l_revision_control_flag = 'N') THEN
8352       l_rti_rec.item_revision := NULL;
8353    END IF;
8354 
8355    IF (l_rti_rec.transaction_type = 'CANCEL') THEN
8356       IF (l_debug = 1) THEN
8357           print_debug('PROCESS_TXN - Calling cancel_asn',1);
8358       END IF;
8359 
8360       cancel_asn(x_return_status => x_return_status
8361                 ,x_msg_count => x_msg_count
8362                 ,x_msg_data => x_msg_data
8363                 ,p_shipment_header_id => l_rti_rec.shipment_header_id
8364                 ,p_shipment_line_id => l_rti_rec.shipment_line_id
8365                 ,p_primary_quantity => l_rti_rec.primary_quantity
8366       );
8367       IF (x_return_status <> g_ret_sts_success) THEN
8368           IF (l_debug = 1) THEN
8369              print_debug('PROCESS_TXN - Cancel ASN Failed...:'||x_return_status,1);
8370           END IF;
8371           --raise an error
8372           --review later
8373           l_progress := 'WMSINB-14209';
8374           RAISE fnd_api.g_exc_error;
8375       END IF;
8376 
8377       IF (l_debug = 1) THEN
8378           print_debug('PROCESS_TXN - Done calling cancel_asn',1);
8379       END IF;
8380    END IF; --IF (l_rti_rec.transaction_type = 'CANCEL') THEN
8381 
8382    IF (l_rti_rec.validation_flag = 'N'
8383        AND l_rti_rec.transaction_type IN ('CORRECT','RETURN TO VENDOR',
8384                                           'RETURN TO CUSTOMER','RETURN TO RECEIVING')) THEN
8385       l_trx_type_for_unpack := l_rti_rec.transaction_type;
8386       l_int_trx_id_for_unpack := l_rti_rec.interface_transaction_id;
8387     ELSE
8388       l_trx_type_for_unpack := NULL;
8389       l_int_trx_id_for_unpack := NULL;
8390    END IF;
8391 
8392    -- Validating Project and Task
8393    -- Currently Validate Project/Task for Deliver
8394    l_progress := 'WMSINB-14210';
8395 
8396    IF ( l_rti_rec.transaction_type in( 'DELIVER','ACCEPT','REJECT','TRANSFER') ) then
8397      IF ( (l_rti_rec.project_id is null and l_parent_project_id is not null) or
8398           (l_rti_rec.task_id is null and l_parent_task_id is not null)
8399         ) then
8400        l_progress := 'WMSINB-14211';
8401        IF (l_debug = 1) THEN
8402           print_debug('PROCESS_TXN - parent rti has proj/task info and txn has no proj/task info ',1);
8403        END IF;
8404        -- Raise Failure
8405        RAISE fnd_api.g_exc_error;
8406      ELSIF (l_rti_rec.project_id is not null or l_rti_rec.task_id is not null) then
8407         if ( (l_parent_project_id is null and l_parent_task_id is null )
8408              or (l_parent_txn_type = 'RECEIVE' and l_rti_rec.transaction_type = 'DELIVER') ) then  -- Bug 14127493 added
8409            l_progress := 'WMSINB-14212';
8410            IF (l_debug = 1) THEN
8411                print_debug('PROCESS_TXN - parent rti has no proj/task info ',1);
8412            END IF;
8413            -- This is ok
8414         Else
8415            if ( ( nvl(l_rti_rec.project_id,0) <> nvl(l_parent_project_id,0) ) or
8416              ( nvl(l_rti_rec.task_id,0) <> nvl(l_parent_task_id,0))
8417               ) then
8418               -- Raise Failure
8419               l_progress := 'WMSINB-14213';
8420               IF (l_debug = 1) THEN
8421                  print_debug('PROCESS_TXN - parent rti has different proj/task info than rti ',1);
8422               END IF;
8423               RAISE fnd_api.g_exc_error;
8424            End if;
8425         End if;
8426      END IF;
8427    END IF;
8428 
8429    l_progress := 'WMSINB-14228';
8430 
8431    IF ( ( l_rti_rec.transaction_type NOT IN
8432         ('SHIP','CORRECT','CANCEL','DELIVER','RETURN TO RECEIVING') )
8433         AND NOT ( l_rti_rec.transaction_type in ('RETURN TO VENDOR','RETURN TO CUSTOMER') and l_parent_txn_type = 'DELIVER' )
8434    )  THEN -- CASE FOR RTV, RTC for a parent RECEIVE TXN, CASE FOR RECEIVE TXN
8435       l_progress := 'WMSINB-14234';
8436 
8437       IF (l_asn_line_flag = 'Y' AND l_rti_rec.transaction_type = 'RECEIVE' ) THEN
8438 
8439          IF (l_debug = 1) THEN
8440             print_debug('PROCESS_TXN - ASN RECEIVE TXN ',1);
8441          END IF;
8442          IF (l_debug = 1) THEN   --add more log when fix bug 14235799
8443                     print_debug('PROCESS_TXN - l_rti_rec.lpn_id = '|| l_rti_rec.lpn_id ,1);
8444                     print_debug('PROCESS_TXN - l_rti_rec.transfer_lpn_id = '|| l_rti_rec.transfer_lpn_id ,1);
8445                     print_debug('PROCESS_TXN - l_rti_rec.EXPRESS_TRANSACTION  = '|| l_rti_rec.EXPRESS_TRANSACTION ,1);
8446          END IF;
8447 
8448          IF (l_rti_rec.lpn_id = Nvl(l_rti_rec.transfer_lpn_id,-1) AND l_rti_rec.EXPRESS_TRANSACTION='Y') THEN -- add the last condition for bug 14235799
8449               l_auto_unnest_empty_lpns := 2;
8450               l_express_receipt_flag := 'Y';
8451          ELSE
8452              l_auto_unnest_empty_lpns := 1;
8453          END IF;
8454 
8455          l_progress := 'WMSINB-14237';
8456        IF (l_express_receipt_flag <>'Y') THEN  -- for bug 14235799
8457          IF l_rti_rec.lpn_id IS NOT NULL THEN
8458             -- Review Later
8459             l_progress := 'WMSINB-14241';
8460 
8461             -- Don't do unpack all but only unpack the REQUIRED QTY /ITEM from here also.
8462             -- This is needed to keep the Nesting
8463             --wms_container_pvt.packunpack_container(
8464             --   p_api_version            => 1.0,
8465             --   p_init_msg_list          => g_false,
8466             --   p_commit                 => g_false,
8467             --   p_validation_level       => fnd_api.g_valid_level_none,
8468             --   x_return_status          => x_return_status,
8469             --   x_msg_count              => x_msg_count,
8470             --   x_msg_data               => x_msg_data,
8471             --   p_lpn_id                 => l_rti_rec.lpn_id,
8472             --   p_organization_id        => l_rti_rec.to_organization_id,
8473             --   p_operation              => 2, --- TO UNPACK
8474             --   p_unpack_all            => 1
8475             --   );
8476             Begin
8477                -- Get the LPN's Org Here
8478                select organization_id
8479                  into l_lpn_org
8480                  from wms_license_plate_numbers wlpn
8481                 where wlpn.lpn_id = l_rti_rec.lpn_id;
8482                --
8483                l_progress := 'WMSINB-14465';
8484             Exception
8485                when others then
8486                  l_progress := 'WMSINB-14466';
8487                  l_lpn_org := null;
8488             End;
8489 
8490             IF (l_rti_rec.lpn_id = Nvl(l_rti_rec.transfer_lpn_id,-1)) THEN
8491                l_auto_unnest_empty_lpns := 2;
8492             ELSE
8493                l_auto_unnest_empty_lpns := 1;
8494 			   /* Start 12610461 */
8495 
8496 
8497 			   IF inv_cache.set_item_rec(l_rti_rec.to_organization_id , l_rti_rec.item_id) THEN  --15959206 start
8498                 l_lot_code := inv_cache.item_rec.lot_control_code;
8499                END IF;
8500 
8501 			   IF l_lot_code = 2 THEN
8502 			   l_ignore_item_controls := 1;
8503 			   END IF; --15959206 end
8504 			   /* End 12610461 */
8505             END IF;
8506 
8507             -- 14408061
8508             l_unpack := TRUE;
8509             IF g_lpn_tbl.EXISTS(l_rti_rec.lpn_id) THEN
8510              IF g_lpn_tbl(l_rti_rec.lpn_id) = l_rti_rec.lpn_group_id THEN
8511                IF (l_debug = 1) THEN
8512                  print_debug('No Need To Unpack ',1);
8513                  print_debug('l_rti_rec.lpn_id '||l_rti_rec.lpn_id,1);
8514                  print_debug('l_rti_rec.lpn_group_id '||l_rti_rec.lpn_group_id,1);
8515                END IF;
8516                l_unpack := FALSE;
8517              END IF;
8518             END IF;
8519             -- 14408061
8520 
8521             IF l_unpack THEN
8522             PackUnpack_wrapper( x_return_status              => x_return_status
8523                               ,x_msg_count                   => x_msg_count
8524                               ,x_msg_data                    => x_msg_data
8525                               ,p_lot_control_code            => l_lot_control_code
8526                               ,p_serial_control_code         => l_serial_control_code
8527                               ,p_product_txn_id              => p_txn_id
8528                               ,p_product_code                => 'RCV'
8529                               ,p_lpn_id                      => l_rti_rec.lpn_id
8530                               ,p_content_lpn_id              => null
8531                               ,p_content_item_id             => l_rti_rec.item_id
8532                               ,p_content_item_desc           => l_rti_rec.item_description
8533                               ,p_revision                    => l_rti_rec.item_revision
8534                               ,p_primary_quantity            => l_rti_rec.primary_quantity
8535                               ,p_primary_uom                 => l_primary_uom
8536                               ,p_organization_id             => l_lpn_org
8537                               ,p_operation                   => 2
8538                               ,p_cost_group_id               => null
8539                               ,p_source_type_id              => null
8540                               ,p_source_header_id            => NULL --l_rti_rec.group_id
8541                               ,p_source_name                 => null
8542                               ,p_source_line_id            => NULL
8543                               ,p_source_line_detail_id     => NULL
8544                               ,p_auto_unnest_empty_lpns    => l_auto_unnest_empty_lpns
8545                               -- OPMConvergence
8546                               ,p_sec_quantity          => l_rti_rec.secondary_quantity
8547                               ,p_sec_uom               => l_sec_uom_code
8548                               -- OPMConvergence
8549                               -- *R12* --
8550                               ,p_txn_quantity          => l_rti_rec.quantity
8551                               ,p_txn_uom_code          => l_rti_rec.uom_code
8552                               -- *R12 *--
8553 							  ,p_ignore_item_controls  =>  l_ignore_item_controls -- 12610461
8554             );
8555 
8556 
8557             -- Check the error status from the above call
8558             if x_return_status <> G_RET_STS_SUCCESS Then
8559                --  Review Late Set Appropiate Message
8560                l_progress := 'WMSINB-14258';
8561                -- Do not error out for ASNs
8562                x_return_status := g_ret_sts_success;
8563                --RAISE FND_API.G_EXC_ERROR;
8564             End if;
8565 
8566             END IF;-- 14408061
8567 
8568          End if; --l_rti_rec.lpn_id is not null
8569 
8570          l_progress := 'WMSINB-14266';
8571 
8572          IF l_rti_rec.transfer_lpn_id IS NOT NULL THEN
8573             --
8574             l_progress := 'WMSINB-14270';
8575 
8576             IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
8577                           l_rti_rec.transfer_lpn_id,
8578                           l_transactions_enabled_flag))
8579             THEN
8580                IF (l_debug = 1) THEN
8581                   print_debug('PROCESS_TXN - Expense and Non Expense Items cannot be Mixed in an LPN',1);
8582                   print_debug('PROCESS_TXN - ORG:LPN:TXNENABLEDFLAG::'||
8583                      l_rti_rec.to_organization_id||':'||l_rti_rec.transfer_lpn_id||
8584                      ':'||l_transactions_enabled_flag,1);
8585                END IF;
8586                l_progress := 'WMSINB-14282';
8587 
8588                --review later
8589                RAISE fnd_api.g_exc_error;
8590             END IF; --IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
8591 
8592             IF (validate_pjm_commingle(l_rti_rec.to_organization_id,
8593                      l_rti_rec.transfer_lpn_id,
8594                      l_rti_rec.project_id,
8595                      l_rti_rec.task_id))
8596             THEN
8597                IF (l_debug = 1) THEN
8598                   print_debug('PROCESS_TXN - Project/Task commingling not allowed in LPN:'||l_rti_rec.transfer_lpn_id,1);
8599                END IF;
8600                l_progress := 'WMSINB-14288';
8601 
8602                RAISE fnd_api.g_exc_error;
8603             END IF; --IF (!validate_pjm_commingle(l_rti_rec.to_organization_id,
8604 
8605             IF (l_debug = 1) THEN
8606                print_debug('PROCESS_TXN - Organization ID:'||l_rti_rec.to_organization_id,1);
8607             END IF;
8608 
8609             --
8610             -- CALL UPDATE TLPN ORGANIZATION LOCATOR FOR WLPN/WLPNC
8611             --
8612 
8613             l_lpn_context := get_lpn_context(p_transaction_type => l_rti_rec.transaction_type
8614                              , p_routing_header_id => l_rti_rec.routing_header_id
8615                              , p_parent_transaction_type => l_parent_txn_type
8616                              , p_parent_parent_txn_type => l_parent_parent_txn_type
8617                              , p_quantity => l_rti_rec.primary_quantity
8618                              , p_auto_transact_code => l_rti_rec.auto_transact_code);
8619 
8620 
8621             l_progress := 'WMSINB-14305';
8622 
8623             update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
8624                                         ,p_sub             => l_rti_rec.SUBINVENTORY
8625                                         ,p_locator         => l_rti_rec.LOCATOR_ID
8626                                         ,p_lpn_context     => l_lpn_context
8627                                         ,p_lpn_id          => l_rti_rec.transfer_lpn_id
8628                                         ,x_return_status   => x_return_status
8629                                         ,x_msg_count       => x_msg_count
8630                                         ,x_msg_data        => x_msg_data ) ;
8631 
8632             l_progress := 'WMSINB-14316';
8633 
8634             -- Check the error status from the above call
8635             if x_return_status <> G_RET_STS_SUCCESS Then
8636                --  Review Late Set Appropiate Message
8637                l_progress := 'WMSINB-14321';
8638                RAISE FND_API.G_EXC_ERROR;
8639             End if;
8640 
8641 
8642             PackUnpack_wrapper( x_return_status               => x_return_status
8643                               ,x_msg_count                   => x_msg_count
8644                               ,x_msg_data                    => x_msg_data
8645                               ,p_lot_control_code            => l_lot_control_code
8646                               ,p_serial_control_code         => l_serial_control_code
8647                               ,p_product_txn_id              => p_txn_id
8648                               ,p_product_code                => 'RCV'
8649                               ,p_lpn_id                      => l_rti_rec.transfer_lpn_id
8650                               ,p_content_lpn_id              => null
8651                               ,p_content_item_id             => l_rti_rec.item_id
8652                               ,p_content_item_desc           => l_rti_rec.item_description
8653                               ,p_revision                    => l_rti_rec.item_revision
8654                               ,p_primary_quantity            => l_rti_rec.primary_quantity
8655                               ,p_primary_uom                 => l_primary_uom
8656                               ,p_organization_id             => l_rti_rec.to_organization_id
8657                               ,p_operation                   => 1
8658                               ,p_cost_group_id               => null
8659                               ,p_source_type_id              => null
8660                               ,p_source_header_id            => null -- l_rti_rec.group_id
8661                               ,p_source_name                 => null
8662                               ,p_source_line_id              => NULL
8663                               ,p_source_line_detail_id     => NULL
8664                               -- OPMConvergence
8665                               ,p_sec_quantity          => l_rti_rec.secondary_quantity
8666                               ,p_sec_uom               => l_sec_uom_code
8667                               -- OPMConvergence
8668                               -- *R12* --
8669                               ,p_txn_quantity          => l_rti_rec.quantity
8670                               ,p_txn_uom_code          => l_rti_rec.uom_code
8671                               -- *R12 *--
8672             );
8673 
8674             -- Check the error status from the above call
8675             if x_return_status <> G_RET_STS_SUCCESS Then
8676                --  Review Late Set Appropiate Message
8677                l_progress := 'WMSINB-14353';
8678                RAISE FND_API.G_EXC_ERROR;
8679             End if;
8680 
8681          END IF; --if l_rti_rec.transfer_lpn_id is not null then
8682        ELSE  -- add for bug 14235799
8683           IF (l_debug = 1) THEN
8684                 print_debug('l_express_receipt_flag= '||l_express_receipt_flag ,1);
8685           END IF;
8686           l_lpn_context := get_lpn_context(p_transaction_type => l_rti_rec.transaction_type
8687                              , p_routing_header_id => l_rti_rec.routing_header_id
8688                              , p_parent_transaction_type => l_parent_txn_type
8689                              , p_parent_parent_txn_type => l_parent_parent_txn_type
8690                              , p_quantity => l_rti_rec.primary_quantity
8691                              , p_auto_transact_code => l_rti_rec.auto_transact_code);
8692 
8693 
8694           l_progress := 'WMSINB-14305';
8695 
8696           update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
8697                                         ,p_sub             => l_rti_rec.SUBINVENTORY
8698                                         ,p_locator         => l_rti_rec.LOCATOR_ID
8699                                         ,p_lpn_context     => l_lpn_context
8700                                         ,p_lpn_id          => l_rti_rec.transfer_lpn_id
8701                                         ,x_return_status   => x_return_status
8702                                         ,x_msg_count       => x_msg_count
8703                                         ,x_msg_data        => x_msg_data ) ;
8704                 -- Check the error status from the above call
8705           if x_return_status <> G_RET_STS_SUCCESS Then
8706                --  Review Late Set Appropiate Message
8707                l_progress := 'WMSINB-14321';
8708                RAISE FND_API.G_EXC_ERROR;
8709 
8710           END IF;
8711 
8712       END IF;--14235799
8713          --
8714          -- **** UPDATE CURRENT STATUS/INSPECTION STATUS/ SUB /LOC/ORG  OF MSN ******
8715 
8716          if l_serial_control_code not in (1,6) then
8717              l_progress := 'WMSINB-14362';
8718              l_serial_status := get_serial_status(p_transaction_type  => l_rti_rec.transaction_type
8719                          , p_auto_transact_code  => l_rti_rec.auto_transact_code
8720                          , p_parent_transaction_type => l_parent_txn_type
8721                          , p_parent_parent_txn_type  => l_parent_parent_txn_type
8722                          , p_quantity => l_rti_rec.primary_quantity);
8723 
8724              l_progress := 'WMSINB-14369';
8725              l_inspection_status := get_inspection_status(p_transaction_type  => l_rti_rec.transaction_type
8726                          , p_routing_header_id  => l_rti_rec.routing_header_id
8727                          , p_parent_transaction_type => l_parent_txn_type
8728                          , p_parent_parent_txn_type  => l_parent_parent_txn_type
8729                          , p_quantity => l_rti_rec.primary_quantity);
8730 
8731              l_progress := 'WMSINB-14376';
8732              update_serial_status ( p_product_txn_id => p_txn_id
8733                         ,p_item_id => l_rti_rec.item_id
8734                         ,p_organization_id => l_rti_rec.to_organization_id
8735                         ,p_serial_status => l_serial_status
8736                         ,p_inspection_status => l_inspection_status
8737                         ,p_sub => l_rti_rec.subinventory
8738                         ,p_locator_id => l_rti_rec.locator_id
8739                         ,x_return_status => x_return_status
8740                         ,x_msg_count => x_msg_count
8741                         ,x_msg_data => x_msg_data );
8742 
8743              -- Check the error status from the above call
8744              if x_return_status <> G_RET_STS_SUCCESS Then
8745                 --  Review Late Set Appropiate Message
8746                 l_progress := 'WMSINB-14389';
8747                 RAISE FND_API.G_EXC_ERROR;
8748              End if;
8749          End if;
8750 
8751       ELSIF (l_rti_rec.source_document_code IN ('INVENTORY','REQ') AND
8752              l_rti_rec.transaction_type = 'RECEIVE') THEN
8753           l_progress := 'WMSINB-14396';
8754 
8755           IF (l_debug = 1) THEN
8756              print_debug('PROCESS_TXN - Case for Intship/REQ Receive ' ,1);
8757              print_debug('PROCESS_TXN - Case for Intship/REQ Receive lpn_id=  '|| l_rti_rec.lpn_id ,1);
8758              print_debug('PROCESS_TXN - Case for Intship/REQ Receive transfer_lpn_id=  '|| l_rti_rec.transfer_lpn_id ,1);
8759           END IF;
8760 
8761           if l_rti_rec.lpn_id is not null then
8762              -- Review Later
8763              l_progress := 'WMSINB-14400';
8764 
8765              get_serial_lot_ctrl_in_src_org
8766                 (p_shipment_line_id => l_rti_rec.shipment_line_id,
8767                  p_org_id => l_rti_rec.to_organization_id,
8768                  x_serial_control_code => l_from_org_serial_control,
8769                  x_lot_control_code => l_from_org_lot_control,
8770                  x_revision_control_code => l_from_org_rev_control,
8771                  x_return_status => x_return_status,
8772                  x_msg_count => x_msg_count,
8773                  x_msg_data => x_msg_data);
8774 
8775              IF (x_return_status <> g_ret_sts_success) THEN
8776                  --Review Later
8777                  l_progress := 'WMSINB-14413';
8778                  RAISE fnd_api.g_exc_error;
8779              END IF;
8780 
8781              IF ((l_lot_control_code = 2 AND l_from_org_lot_control <> 2)
8782                OR (l_lot_control_code <> 2 AND l_from_org_lot_control = 2)
8783                OR (l_serial_control_code > 1
8784                AND l_from_org_serial_control = 1)
8785                OR (l_serial_control_code IN (1,6)   --Bug 6733277
8786                    AND l_from_org_serial_control > 1)
8787                OR (l_from_org_rev_control = 1
8788                    AND l_revision_control_flag = 'Y')
8789                OR (l_from_org_rev_control = 2
8790                    AND l_revision_control_flag = 'N')) THEN
8791               l_progress := 'WMSINB-14423';
8792               l_full_unpack := TRUE;
8793              END IF;
8794 
8795              IF ((l_from_org_lot_control = 2 AND l_lot_control_code = 2)
8796                   OR (l_from_org_serial_control > 1
8797                       AND l_serial_control_code > 1)) THEN
8798                  -- Get total lot qty
8799                  l_progress := 'WMSINB-14431';
8800                  SELECT Nvl(SUM(transaction_quantity),0)
8801                    INTO l_total_lot_qty
8802                    FROM mtl_transaction_lots_temp
8803                    WHERE product_code = 'RCV'
8804                    AND product_transaction_id = l_rti_rec.interface_transaction_id;
8805 
8806                  -- GET the TOTAL SERIAL QTY
8807                  l_progress := 'WMSINB-14439';
8808                  SELECT Nvl(SUM(inv_serial_number_pub.get_serial_diff(fm_serial_number,to_serial_number)),0)
8809                    INTO l_total_serial_qty
8810                    FROM mtl_serial_numbers_temp
8811                    WHERE product_code = 'RCV'
8812                    AND product_transaction_id = l_rti_rec.interface_transaction_id;
8813 
8814                  IF (l_total_lot_qty = 0 AND l_total_serial_qty = 0) THEN
8815                     l_progress := 'WMSINB-14447';
8816                     l_full_unpack := TRUE;
8817                  END IF;
8818 
8819              END IF; --IF ((l_from_org_lot_control = 2 AND l_lot_control_code = 2)
8820 
8821              -- if transfer lpn id is same as LPN Id then we need to do full unpack here
8822              -- otherwise for Express Receipt if you have multiple items in the same lpn then subsequent
8823              -- unpack for next transactions would fail as the LPN's org get changed after the
8824              -- first transaction.
8825              --if (l_rti_rec.lpn_id = nvl(l_rti_rec.transfer_lpn_id,-9999) ) then
8826              --   l_progress := 'WMSINB-14448';
8827              --   l_full_unpack := TRUE;
8828              --   IF (l_debug = 1) THEN
8829              --	    print_debug('PROCESS_TXN - full unpack Flag coming here ' ,1);
8830              --   END IF;
8831              --End if;
8832 
8833              Begin
8834                 -- Get the LPN's Org Here
8835                 select organization_id
8836                   into l_lpn_org
8837                   from wms_license_plate_numbers wlpn
8838                  where wlpn.lpn_id = l_rti_rec.lpn_id;
8839                 --
8840                 l_progress := 'WMSINB-14465';
8841              Exception
8842                 when others then
8843                    l_progress := 'WMSINB-14466';
8844                    l_lpn_org := null;
8845              End;
8846 
8847              IF (l_debug = 1) THEN   --add more log when fix bug 14235799
8848                     print_debug('PROCESS_TXN - l_rti_rec.lpn_id = '|| l_rti_rec.lpn_id ,1);
8849                     print_debug('PROCESS_TXN - l_rti_rec.transfer_lpn_id = '|| l_rti_rec.transfer_lpn_id ,1);
8850                     print_debug('PROCESS_TXN - l_rti_rec.EXPRESS_TRANSACTION  = '|| l_rti_rec.EXPRESS_TRANSACTION ,1);
8851               END IF;
8852 
8853              IF (l_rti_rec.lpn_id = Nvl(l_rti_rec.transfer_lpn_id,-1) AND l_rti_rec.EXPRESS_TRANSACTION='Y') THEN -- add the last condition for bug 14235799
8854                 l_auto_unnest_empty_lpns := 2;
8855                 l_express_receipt_flag := 'Y';  -- add for 13241074
8856              ELSE
8857                 l_auto_unnest_empty_lpns := 1;
8858              END IF;
8859 
8860 
8861              IF l_full_unpack THEN
8862                  IF (l_debug = 1) THEN
8863                     print_debug('PROCESS_TXN - Performing item unpack of LPN = '|| l_rti_rec.lpn_id ,1);
8864                  END IF;
8865 
8866                  -- CASE FOR EXPRESS RECEIPT FOR MULTIPLE ITEMS
8867                  -- For the First Time for rti rows within the same group this API
8868                  -- Gets called the LPN org and the rti from ORG is same so LPN will
8869                  -- get fully unpacked..
8870                  -- For the second time when it comes the LPN org
8871                  -- and the from ORG of rti will be different and we don't need to
8872                  -- unpack in that case as it already got unpacked once before.
8873                  -- if l_rti_rec.from_organization_id = nvl(l_lpn_org,0) then
8874                  -- Don't need the above case anymore here'
8875 
8876                  -- We should not be doing full unpack. Instead if one of
8877                  -- the conditions used to set l_full_unpack to true is
8878                  -- met then we should null out the lot_number on
8879                  -- wms_lpn_contents and null out the lpn_id on mtl_serial_numbers
8880 
8881                  UPDATE wms_lpn_contents
8882                    SET lot_number = NULL,
8883 				   SERIAL_SUMMARY_ENTRY=2,--15951100
8884                    revision = NULL
8885                    WHERE parent_lpn_id = l_rti_rec.lpn_id
8886                    AND inventory_item_id = l_rti_rec.item_id;
8887 
8888                  UPDATE mtl_serial_numbers
8889                    SET lpn_id = NULL
8890                    WHERE inventory_item_id = l_rti_rec.item_id
8891                    AND lpn_id = l_rti_rec.lpn_id
8892 		   AND current_status <> 7;  -- Bug 6902368
8893 
8894                  l_progress := 'WMSINB-14468';
8895                  PackUnpack_wrapper( x_return_status                => x_return_status
8896                               ,x_msg_count                   => x_msg_count
8897                               ,x_msg_data                    => x_msg_data
8898                               ,p_lot_control_code            => 1
8899                               ,p_serial_control_code         => 1
8900                               ,p_product_txn_id              => p_txn_id
8901                               ,p_product_code                => 'RCV'
8902                               ,p_lpn_id                      => l_rti_rec.lpn_id
8903                               ,p_content_lpn_id              => null
8904                               ,p_content_item_id             => l_rti_rec.item_id
8905                               ,p_content_item_desc           => l_rti_rec.item_description
8906                               ,p_revision                    => NULL
8907                               ,p_primary_quantity            => l_rti_rec.primary_quantity
8908                               ,p_primary_uom                 => l_primary_uom
8909                               ,p_organization_id             => l_lpn_org
8910                               ,p_operation                   => 2
8911                               ,p_cost_group_id               => null
8912                               ,p_source_type_id              => null
8913                               ,p_source_header_id            => NULL --l_rti_rec.group_id
8914                               ,p_source_name                 => null
8915                               ,p_source_line_id              => NULL
8916                               ,p_source_line_detail_id       => NULL
8917                               ,p_auto_unnest_empty_lpns      => l_auto_unnest_empty_lpns
8918                               -- OPMConvergence
8919                               ,p_sec_quantity          => l_rti_rec.secondary_quantity
8920                               ,p_sec_uom               => l_sec_uom_code
8921                               -- OPMConvergence
8922                               -- Following 2 line were added for bugfix 5488003
8923                               ,p_txn_quantity          => l_rti_rec.quantity
8924                               ,p_txn_uom_code          => l_rti_rec.uom_code
8925                  );
8926                  -- Check the error status from the above call
8927                  if x_return_status <> G_RET_STS_SUCCESS Then
8928                     --  Review Late Set Appropiate Message
8929                     l_progress := 'WMSINB-14469';
8930                     --Do not error out for Int receipts
8931                     x_return_status := g_ret_sts_success;
8932                     --RAISE FND_API.G_EXC_ERROR;
8933                  End if;
8934 
8935              ELSE
8936 
8937                  -- Always pass the LPN's org in this case for UNPACK
8938                  -- Otherwise multiple items packed in the same LPN
8939                  -- Causing issues
8940 
8941                  l_progress := 'WMSINB-14500';
8942 
8943                  if l_lpn_org is null then
8944                     l_lpn_org :=  l_rti_rec.from_organization_id;
8945                  End if;
8946                  print_debug('before PackUnpack_wrapper l_auto_unnest_empty_lpns='||l_auto_unnest_empty_lpns,1); -- for bug 13241074 start if
8947                  print_debug('before unpack through PackUnpack_wrapper l_express_receipt_flag='||l_express_receipt_flag,1); -- for bug 13241074
8948                  -- for bug 13241074 we do not need to call the unpack operation for express receipt when both lpn and transfer_lpn are same
8949                   -- and if the lot / serial / revision control flag is same in both orgs.
8950                  IF l_express_receipt_flag <> 'Y' THEN
8951                          PackUnpack_wrapper( x_return_status               => x_return_status
8952                                     ,x_msg_count                   => x_msg_count
8953                                     ,x_msg_data                    => x_msg_data
8954                                     ,p_lot_control_code            => l_lot_control_code
8955                                     ,p_serial_control_code         => l_serial_control_code
8956                                     ,p_product_txn_id              => p_txn_id
8957                                     ,p_product_code                => 'RCV'
8958                                     ,p_lpn_id                      => l_rti_rec.lpn_id
8959                                     ,p_content_lpn_id              => null
8960                                     ,p_content_item_id             => l_rti_rec.item_id
8961                                     ,p_content_item_desc           => l_rti_rec.item_description
8962                                     ,p_revision                    => l_rti_rec.item_revision
8963                                     ,p_primary_quantity            => l_rti_rec.primary_quantity
8964                                     ,p_primary_uom                 => l_primary_uom
8965                                     ,p_organization_id             => l_lpn_org
8966                                     ,p_operation                   => 2
8967                                     ,p_cost_group_id               => null
8968                                     ,p_source_type_id              => null
8969                                     ,p_source_header_id            => NULL --l_rti_rec.group_id
8970                                     ,p_source_name                 => null
8971                                     ,p_source_line_id              => NULL
8972                                     ,p_source_line_detail_id       => NULL
8973                                     ,p_auto_unnest_empty_lpns      => l_auto_unnest_empty_lpns
8974                                     -- OPMConvergence
8975                                     ,p_sec_quantity          => l_rti_rec.secondary_quantity
8976                                     ,p_sec_uom               => l_sec_uom_code
8977                                     -- OPMConvergence
8978                                     -- *R12* --
8979                                     ,p_txn_quantity          => l_rti_rec.quantity
8980                                     ,p_txn_uom_code          => l_rti_rec.uom_code
8981                                     -- *R12 *--
8982                           );
8983                  -- Check the error status from the above call
8984                  if x_return_status <> G_RET_STS_SUCCESS Then
8985                     --  Review Late Set Appropiate Message
8986                     l_progress := 'WMSINB-14501';
8987                     --Do not error out for Int Receipts
8988                     x_return_status := g_ret_sts_success;
8989                     --RAISE FND_API.G_EXC_ERROR;
8990                  End if;
8991                END IF; -- for bug 13241074 end if
8992              END IF; --IF l_full_unpack THEN
8993 
8994           End if; --l_rti_rec.lpn_id is not null
8995 
8996           l_progress := 'WMSINB-14510';
8997 
8998           if l_rti_rec.transfer_lpn_id is not null then
8999              --
9000              l_progress := 'WMSINB-14514';
9001 
9002              IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
9003                      l_rti_rec.transfer_lpn_id,
9004                      l_transactions_enabled_flag))
9005              THEN
9006                  IF (l_debug = 1) THEN
9007                     print_debug('PROCESS_TXN - Expense and Non Expense Items cannot be Mixed in an LPN',1);
9008                     print_debug('PROCESS_TXN - ORG:LPN:TXNENABLEDFLAG::'||
9009                          l_rti_rec.to_organization_id||':'||l_rti_rec.transfer_lpn_id||
9010                          ':'||l_transactions_enabled_flag,1);
9011                  END IF;
9012                  l_progress := 'WMSINB-14526';
9013 
9014                  --review later
9015                  RAISE fnd_api.g_exc_error;
9016              END IF; --IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
9017 
9018              IF (validate_pjm_commingle(l_rti_rec.to_organization_id,
9019                        l_rti_rec.transfer_lpn_id,
9020                        l_rti_rec.project_id,
9021                        l_rti_rec.task_id))
9022              THEN
9023                  IF (l_debug = 1) THEN
9024                     print_debug('PROCESS_TXN - Project/Task commingling not allowed in LPN:'||l_rti_rec.transfer_lpn_id,1);
9025                  END IF;
9026                  l_progress := 'WMSINB-14532';
9027 
9028                  RAISE fnd_api.g_exc_error;
9029              END IF; --IF (!validate_pjm_commingle(l_rti_rec.to_organization_id,
9030 
9031              IF (l_debug = 1) THEN
9032                  print_debug('PROCESS_TXN - Organization ID:'||l_rti_rec.to_organization_id,1);
9033              END IF;
9034 
9035              --
9036              -- CALL UPDATE TLPN ORGANIZATION LOCATOR FOR WLPN/WLPNC
9037              --
9038 
9039              l_lpn_context := get_lpn_context(p_transaction_type => l_rti_rec.transaction_type
9040                      , p_routing_header_id => l_rti_rec.routing_header_id
9041                      , p_parent_transaction_type => l_parent_txn_type
9042                      , p_parent_parent_txn_type => l_parent_parent_txn_type
9043                      , p_quantity =>	l_rti_rec.primary_quantity
9044                      , p_auto_transact_code => l_rti_rec.auto_transact_code);
9045 
9046              l_progress := 'WMSINB-14548';
9047 
9048              update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
9049                      ,p_sub             => l_rti_rec.SUBINVENTORY
9050                      ,p_locator         => l_rti_rec.LOCATOR_ID
9051                      ,p_lpn_context     => l_lpn_context
9052                      ,p_lpn_id          => l_rti_rec.transfer_lpn_id
9053                      ,x_return_status   => x_return_status
9054                      ,x_msg_count       => x_msg_count
9055                      ,x_msg_data        => x_msg_data ) ;
9056 
9057              l_progress := 'WMSINB-14559';
9058 
9059              -- Check the error status from the above call
9060              if x_return_status <> G_RET_STS_SUCCESS Then
9061                  --  Review Late Set Appropiate Message
9062                  l_progress := 'WMSINB-14564';
9063                  RAISE FND_API.G_EXC_ERROR;
9064              End if;
9065 
9066           END IF; --if l_rti_rec.transfer_lpn_id is not null then
9067 
9068 	  -- Bug 7534906 : Kept outside the if l_rti_rec.transfer_lpn_id is not null condition
9069 	  IF ( nvl(l_rti_rec.lpn_id,0)  > 0 ) THEN  --6612300
9070 		--Bug 6168447:Update the org of the FROM LPN to that of receiving org.
9071 		--Also null out source_name and source_header_id.
9072 		--This needs to be done only if the LPN is getting unpacked completely.
9073 		SELECT lpn_context
9074 		INTO l_current_lpn_context
9075 		FROM wms_license_plate_numbers
9076 		WHERE lpn_id = l_rti_rec.lpn_id;
9077 
9078 		IF (l_current_lpn_context = 5) THEN
9079 		   IF (l_debug = 1) THEN
9080 		      print_debug('PROCESS_TXN - Updating the oranization of from lpn to that of receiving org',1);
9081 		   END IF;
9082 
9083 		   update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
9084 					,p_sub             => NULL
9085 					,p_locator         => NULL
9086 					,p_lpn_context     => 5
9087 					,p_source_name     => FND_API.G_MISS_CHAR
9088 					,p_lpn_id          => l_rti_rec.lpn_id
9089 					,x_return_status   => x_return_status
9090 					,x_msg_count       => x_msg_count
9091 					,x_msg_data        => x_msg_data ) ;
9092 		   -- Check the error status from the above call
9093 		   if x_return_status <> G_RET_STS_SUCCESS Then
9094 		       --  Review Late Set Appropiate Message
9095 		       l_progress := 'WMSINB-14564a';
9096 		       RAISE FND_API.G_EXC_ERROR;
9097 		   End if;
9098 		END IF;
9099 		--6168447:end
9100 	  END IF;
9101 
9102 
9103           -- **** This needs to be done before packunpack as the
9104           -- **** serials are accessed using the current_organization_id = to_organization_id in the
9105           -- **** in wms_container_pvt.packunpack_container
9106           -- **** and it was unable to  fetch serials
9107           -- **** UPDATE CURRENT STATUS/INSPECTION STATUS/ SUB /LOC/ORG  OF MSN ******
9108 
9109           if l_serial_control_code <> 1 then
9110              l_progress := 'WMSINB-14604';
9111              l_serial_status := get_serial_status(p_transaction_type  => l_rti_rec.transaction_type
9112                                , p_auto_transact_code  => l_rti_rec.auto_transact_code
9113                                , p_parent_transaction_type => l_parent_txn_type
9114                                , p_parent_parent_txn_type  => l_parent_parent_txn_type
9115                                , p_quantity => l_rti_rec.primary_quantity);
9116 
9117              l_progress := 'WMSINB-14611';
9118              l_inspection_status := get_inspection_status(p_transaction_type  => l_rti_rec.transaction_type
9119                                , p_routing_header_id  => l_rti_rec.routing_header_id
9120                                , p_parent_transaction_type => l_parent_txn_type
9121                                , p_parent_parent_txn_type  => l_parent_parent_txn_type
9122                                , p_quantity => l_rti_rec.primary_quantity);
9123 
9124              l_progress := 'WMSINB-14618';
9125              update_serial_status ( p_product_txn_id => p_txn_id
9126                               ,p_item_id => l_rti_rec.item_id
9127                               ,p_organization_id => l_rti_rec.to_organization_id
9128                               ,p_serial_status => l_serial_status
9129                               ,p_inspection_status => l_inspection_status
9130                               ,p_sub => l_rti_rec.subinventory
9131                               ,p_locator_id => l_rti_rec.locator_id
9132                               ,x_return_status => x_return_status
9133                               ,x_msg_count => x_msg_count
9134                               ,x_msg_data => x_msg_data );
9135 
9136              -- Check the error status from the above call
9137              if x_return_status <> G_RET_STS_SUCCESS Then
9138                 --  Review Late Set Appropiate Message
9139                 l_progress := 'WMSINB-14631';
9140                 RAISE FND_API.G_EXC_ERROR;
9141              End if;
9142           End if; -- l_serial_control_code not in (1,6) then
9143           print_debug('secondly PackUnpack_wrapper l_auto_unnest_empty_lpns='||l_auto_unnest_empty_lpns,1); -- for bug 13241074
9144           print_debug('before pack / correct through PackUnpack_wrapper l_express_receipt_flag='||l_express_receipt_flag,1); -- for bug 13241074
9145           if l_rti_rec.transfer_lpn_id is not null then
9146              IF l_express_receipt_flag = 'Y'   -- for bug 13241074/13976923
9147 			 AND NOT ((l_lot_control_code = 2 AND l_from_org_lot_control <> 2) --14459255 begin
9148                OR (l_lot_control_code <> 2 AND l_from_org_lot_control = 2)
9149                OR (l_serial_control_code > 1
9150                AND l_from_org_serial_control = 1)
9151                OR (l_serial_control_code IN (1,6)
9152                    AND l_from_org_serial_control > 1)
9153                OR (l_from_org_rev_control = 1
9154                    AND l_revision_control_flag = 'Y')
9155                OR (l_from_org_rev_control = 2
9156                    AND l_revision_control_flag = 'N')) THEN   -- 14459255  end
9157                 print_debug('Do not call Pack Unpack as it is express receipt case and LPN orgs have already been updated by ModifyLPN call Express Receipt - '||l_express_receipt_flag,1);
9158              ELSE
9159 				print_debug('Call Pack Unpack in Correct Mode as Express Receipt Flag is - '||l_express_receipt_flag,1);
9160              PackUnpack_wrapper( x_return_status               => x_return_status
9161                                ,x_msg_count                   => x_msg_count
9162                                ,x_msg_data                    => x_msg_data
9163                                ,p_lot_control_code            => l_lot_control_code
9164                                ,p_serial_control_code         => l_serial_control_code
9165                                ,p_product_txn_id              => p_txn_id
9166                                ,p_product_code                => 'RCV'
9167                                ,p_lpn_id                      => l_rti_rec.transfer_lpn_id
9168                                ,p_content_lpn_id              => null
9169                                ,p_content_item_id             => l_rti_rec.item_id
9170                                ,p_content_item_desc           => l_rti_rec.item_description
9171                                ,p_revision                    => l_rti_rec.item_revision
9172                                ,p_primary_quantity            => l_rti_rec.primary_quantity
9173                                ,p_primary_uom                 => l_primary_uom
9174                                ,p_organization_id             => l_rti_rec.to_organization_id
9175                                ,p_operation                   => 1
9176                                ,p_cost_group_id               => null
9177                                ,p_source_type_id              => null
9178                                ,p_source_header_id            => null -- l_rti_rec.group_id
9179                                ,p_source_name                 => null
9180                                ,p_source_line_id              => NULL
9181                                ,p_source_line_detail_id     => NULL
9182                                -- OPMConvergence
9183                                ,p_sec_quantity          => l_rti_rec.secondary_quantity
9184                                ,p_sec_uom               => l_sec_uom_code
9185                                -- OPMConvergence
9186                                -- *R12* --
9187                                ,p_txn_quantity          => l_rti_rec.quantity
9188                                ,p_txn_uom_code          => l_rti_rec.uom_code
9189                                -- *R12 *--
9190 								);
9191 			END IF;
9192 
9193              -- Check the error status from the above call
9194              if x_return_status <> G_RET_STS_SUCCESS Then
9195                  --  Review Late Set Appropiate Message
9196                  l_progress := 'WMSINB-14634';
9197                  RAISE FND_API.G_EXC_ERROR;
9198              End if;
9199 
9200           END IF; --if l_rti_rec.transfer_lpn_id is not null then
9201           --
9202           -- **** UPDATE CURRENT STATUS/INSPECTION STATUS/ SUB /LOC/ORG  OF MSN ******
9203           -- **** This part is done above now
9204 
9205       Else --if (l_lpn_context = G_LPN_CONTEXT_VENDOR and l_rti_rec.transaction_type = 'RECEIVE' ) then
9206 
9207           IF (l_debug = 1) THEN
9208               print_debug('PROCESS_TXN - CASE FOR  RECEIVE TXN ',1);
9209           END IF;
9210 
9211           l_progress := 'WMSINB-14637';
9212 
9213 	 /* Bug 7410777 */
9214 	  IF l_rti_rec.transaction_type IN ('ACCEPT', 'REJECT') THEN
9215 	       IF l_rti_rec.uom_code is null then
9216 		  IF (l_debug = 1) THEN
9217 		    print_debug('PROCESS_TXN - Before Pack Unpack Get uom_code from unit_of_measure as Uom_code is null in rti',1);
9218 		    print_debug('PROCESS_TXN - Before Pack Unpack Unit_of_measure = '|| l_rti_rec.unit_of_measure,1);
9219 		  END IF;
9220 
9221 	          BEGIN
9222 		    SELECT uom_code
9223 		    into l_rti_rec.uom_code
9224 		    FROM mtl_item_uoms_view
9225 		    WHERE organization_id = l_rti_rec.to_organization_id
9226 		    AND inventory_item_id =  l_rti_rec.item_id
9227 		    AND unit_of_measure = l_rti_rec.unit_of_measure;
9228 	          EXCEPTION
9229 		    WHEN OTHERS THEN
9230 		    IF (l_debug = 1) THEN
9231 		       print_debug('PROCESS_TXN : Error retrieving uom_code', 1);
9232 		    END IF;
9233 		    l_progress := 'WMSINB-14638';
9234 		    RAISE fnd_api.g_exc_error;
9235 	          END;
9236 	       END IF;
9237 	    END IF;
9238 	     /* End of fix for Bug 7410777*/
9239 
9240           if l_rti_rec.lpn_id is not null then
9241               l_progress := 'WMSINB-14639';
9242               if (l_rti_rec.lpn_id <> nvl(l_rti_rec.transfer_lpn_id,-9999)) then
9243                  -- UNPACK FLPN FOR RTI.ITEM, MTLT.LOTNUM, MSNT.FMSERNUM, MSNT.TOSERNUM
9244                  l_progress := 'WMSINB-14642';
9245                  IF (l_rti_rec.transaction_type = 'RECEIVE') THEN
9246                      l_unpack_org_id := l_rti_rec.from_organization_id;
9247                  ELSE
9248                      l_unpack_org_id := l_rti_rec.to_organization_id;
9249                  END IF;
9250 
9251                  PackUnpack_wrapper( x_return_status               => x_return_status
9252                                     ,x_msg_count                   => x_msg_count
9253                                     ,x_msg_data                    => x_msg_data
9254                                     ,p_lot_control_code            => l_lot_control_code
9255                                     ,p_serial_control_code         => l_serial_control_code
9256                                     ,p_product_txn_id              => p_txn_id
9257                                     ,p_product_code                => 'RCV'
9258                                     ,p_lpn_id                      => l_rti_rec.lpn_id
9259                                     ,p_content_lpn_id              => null
9260                                     ,p_content_item_id             => l_rti_rec.item_id
9261                                     ,p_content_item_desc           => l_rti_rec.item_description
9262                                     ,p_revision                    => l_rti_rec.item_revision
9263                                     ,p_primary_quantity            => l_rti_rec.primary_quantity
9264                                     ,p_primary_uom                 => l_primary_uom
9265                                     ,p_organization_id             => l_unpack_org_id
9266                                     ,p_operation                   => 2
9267                                     ,p_cost_group_id               => null
9268                                     ,p_source_type_id              => NULL
9269                                     ,p_source_header_id            => l_int_trx_id_for_unpack
9270                                     ,p_source_name                 => l_trx_type_for_unpack
9271                                     ,p_source_line_id              => NULL
9272                                     ,p_source_line_detail_id     => NULL
9273                                     -- OPMConvergence
9274                                     ,p_sec_quantity          => l_rti_rec.secondary_quantity
9275                                     ,p_sec_uom               => l_sec_uom_code
9276                                     -- OPMConvergence
9277                                     -- *R12* --
9278                                     ,p_txn_quantity          => l_rti_rec.quantity
9279                                     ,p_txn_uom_code          => l_rti_rec.uom_code
9280                                     -- *R12 *--
9281                  );
9282                  -- Check the error status from the above call
9283                  if x_return_status <> G_RET_STS_SUCCESS Then
9284                      --  Review Late Set Appropiate Message
9285                      l_progress := 'WMSINB-14675';
9286                      RAISE FND_API.G_EXC_ERROR;
9287                  End if;
9288 
9289               End if; -- END OF FLPN AND TLP DIFFERENT
9290           End if; -- END OF l_rti_rec.lpn_id is not null
9291 
9292           l_progress := 'WMSINB-14682';
9293 
9294           if l_rti_rec.transfer_lpn_id is not null then
9295               l_progress := 'WMSINB-14685';
9296               if (l_rti_rec.transfer_lpn_id <> nvl(l_rti_rec.lpn_id,-9999)) then
9297                  l_progress := 'WMSINB-14687';
9298                  IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
9299                            l_rti_rec.transfer_lpn_id,
9300                            l_transactions_enabled_flag))
9301                  THEN
9302                      IF (l_debug = 1) THEN
9303                         print_debug('PROCESS_TXN - Expense and Non Expense Items cannot be Mixed in an LPN',1);
9304                         print_debug('PROCESS_TXN - ORG:LPN:TXNENABLEDFLAG::'||
9305                                l_rti_rec.to_organization_id||':'||l_rti_rec.transfer_lpn_id||
9306                                ':'||l_transactions_enabled_flag,1);
9307                      END IF;
9308                      l_progress := 'WMSINB-14699';
9309 
9310                      --review later
9311                      RAISE fnd_api.g_exc_error;
9312                  END IF; --IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
9313 
9314                  IF (validate_pjm_commingle(l_rti_rec.to_organization_id,
9315                      l_rti_rec.transfer_lpn_id,
9316                      l_rti_rec.project_id,
9317                      l_rti_rec.task_id))
9318                  THEN
9319                     IF (l_debug = 1) THEN
9320                         print_debug('PROCESS_TXN - Project/Task commingling not allowed in LPN:'||l_rti_rec.transfer_lpn_id,1);
9321                     END IF;
9322                     l_progress := 'WMSINB-14705';
9323 
9324                     RAISE fnd_api.g_exc_error;
9325                  END IF; --IF (!validate_pjm_commingle(l_rti_rec.to_organization_id,
9326 
9327                  l_lpn_context := get_lpn_context(p_transaction_type => l_rti_rec.transaction_type
9328                            , p_routing_header_id => l_rti_rec.routing_header_id
9329                            , p_parent_transaction_type => l_parent_txn_type
9330                            , p_parent_parent_txn_type => l_parent_parent_txn_type
9331                            , p_quantity => l_rti_rec.primary_quantity
9332                            , p_auto_transact_code => l_rti_rec.auto_transact_code);
9333 
9334                  IF (l_rti_rec.transaction_type NOT IN ('ACCEPT','REJECT') OR l_transfer_lpn_context = 5) THEN
9335                      l_progress := 'WMSINB-14714';
9336                      update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
9337                          ,p_sub             => l_rti_rec.SUBINVENTORY
9338                          ,p_locator         => l_rti_rec.LOCATOR_ID
9339                          ,p_lpn_context     => l_lpn_context
9340                          ,p_lpn_id          => l_rti_rec.transfer_lpn_id
9341                          ,x_return_status   => x_return_status
9342                          ,x_msg_count       => x_msg_count
9343                          ,x_msg_data        => x_msg_data ) ;
9344 
9345                      -- Check the error status from the above call
9346                      if x_return_status <> G_RET_STS_SUCCESS Then
9347                         --  Review Late Set Appropiate Message
9348                         l_progress := 'WMSINB-14727';
9349                         RAISE FND_API.G_EXC_ERROR;
9350                      End if;
9351                  END IF; --IF (l_rti_rec.transaction_type NOT IN ('ACCEPT','REJECT') OR l_transfer_lpn_context = 5) THEN
9352                  -- This part is changed to call before packunpack_wrapper
9353                  -- because if issued out serials are repacked then they might have
9354                  -- a different org, so packunpack would fail to pack those serials
9355                  -- unless those serials had the org updated first to the current org
9356 
9357                  if l_serial_control_code <> 1 then
9358                      l_progress := 'WMSINB-14764';
9359                      l_serial_status := get_serial_status(p_transaction_type  => l_rti_rec.transaction_type
9360                              , p_auto_transact_code  => l_rti_rec.auto_transact_code
9361                              , p_parent_transaction_type => l_parent_txn_type
9362                              , p_parent_parent_txn_type  => l_parent_parent_txn_type
9363                              , p_quantity => l_rti_rec.primary_quantity);
9364 
9365                      l_progress := 'WMSINB-14771';
9366                      l_inspection_status := get_inspection_status(p_transaction_type  => l_rti_rec.transaction_type
9367                              , p_routing_header_id  => l_rti_rec.routing_header_id
9368                              , p_parent_transaction_type => l_parent_txn_type
9369                              , p_parent_parent_txn_type  => l_parent_parent_txn_type
9370                              , p_quantity => l_rti_rec.primary_quantity);
9371 
9372                      l_progress := 'WMSINB-14778';
9373                      update_serial_status ( p_product_txn_id => p_txn_id
9374                             ,p_item_id => l_rti_rec.item_id
9375                             ,p_organization_id => l_rti_rec.to_organization_id
9376                             ,p_serial_status => l_serial_status
9377                             ,p_inspection_status => l_inspection_status
9378                             ,p_sub => l_rti_rec.subinventory
9379                             ,p_locator_id => l_rti_rec.locator_id
9380                             ,x_return_status => x_return_status
9381                             ,x_msg_count => x_msg_count
9382                             ,x_msg_data => x_msg_data );
9383 
9384                      -- Check the error status from the above call
9385                      if x_return_status <> G_RET_STS_SUCCESS Then
9386                         --  Review Late Set Appropiate Message
9387                         l_progress := 'WMSINB-14791';
9388                         RAISE FND_API.G_EXC_ERROR;
9389                      End if;
9390                  End if;
9391 
9392                  PackUnpack_wrapper( x_return_status               => x_return_status
9393                                     ,x_msg_count                   => x_msg_count
9394                                     ,x_msg_data                    => x_msg_data
9395                                     ,p_lot_control_code            => l_lot_control_code
9396                                     ,p_serial_control_code         => l_serial_control_code
9397                                     ,p_product_txn_id              => p_txn_id
9398                                     ,p_product_code                => 'RCV'
9399                                     ,p_lpn_id                      => l_rti_rec.transfer_lpn_id
9400                                     ,p_content_lpn_id              => null
9401                                     ,p_content_item_id             => l_rti_rec.item_id
9402                                     ,p_content_item_desc           => l_rti_rec.item_description
9403                                     ,p_revision                    => l_rti_rec.item_revision
9404                                     ,p_primary_quantity            => l_rti_rec.primary_quantity
9405                                     ,p_primary_uom                 => l_primary_uom
9406                                     ,p_organization_id             => l_rti_rec.to_organization_id
9407                                     ,p_operation                   => 1
9408                                     ,p_cost_group_id               => null
9409                                     ,p_source_type_id              => null
9410                                     ,p_source_header_id            => null --l_rti_rec.group_id
9411                                     ,p_source_name                 => null
9412                                     ,p_source_line_id              => NULL
9413                                     ,p_source_line_detail_id     => NULL
9414                                     -- OPMConvergence
9415                                     ,p_sec_quantity          => l_rti_rec.secondary_quantity
9416                                     ,p_sec_uom               => l_sec_uom_code
9417                                     -- OPMConvergence
9418                                     -- *R12* --
9419                                     ,p_txn_quantity          => l_rti_rec.quantity
9420                                     ,p_txn_uom_code          => l_rti_rec.uom_code
9421                                     -- *R12 *--
9422                  );
9423 
9424                  -- Check the error status from the above call
9425                  if x_return_status <> G_RET_STS_SUCCESS Then
9426                      --  Review Late Set Appropiate Message
9427                      l_progress := 'WMSINB-14759';
9428                      RAISE FND_API.G_EXC_ERROR;
9429                  End if;
9430 
9431               ELSE -- when FLPN = TLPN
9432                  l_progress := 'WMSINB-14796';
9433 
9434                  IF(l_debug = 1) THEN
9435                      print_debug('PROCESS_TXN - FLPN AND TLPN ARE SAME:'||l_progress,1);
9436                  END IF;
9437 
9438                  l_lpn_context := get_lpn_context(p_transaction_type => l_rti_rec.transaction_type
9439                                     , p_routing_header_id => l_rti_rec.routing_header_id
9440                                     , p_parent_transaction_type => l_parent_txn_type
9441                                     , p_parent_parent_txn_type => l_parent_parent_txn_type
9442                                     , p_quantity => l_rti_rec.primary_quantity
9443                                     , p_auto_transact_code => l_rti_rec.auto_transact_code);
9444 
9445                  IF (l_rti_rec.transaction_type NOT IN ('ACCEPT','REJECT') ) THEN
9446                      l_progress := 'WMSINB-14809';
9447                      update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
9448                                                  ,p_sub             => l_rti_rec.SUBINVENTORY
9449                                                  ,p_locator         => l_rti_rec.LOCATOR_ID
9450                                                  ,p_lpn_context     => l_lpn_context
9451                                                  ,p_lpn_id          => l_rti_rec.transfer_lpn_id
9452                                                  ,x_return_status   => x_return_status
9453                                                  ,x_msg_count       => x_msg_count
9454                                                  ,x_msg_data        => x_msg_data ) ;
9455 
9456                      -- Check the error status from the above call
9457                      if x_return_status <> G_RET_STS_SUCCESS Then
9458                         --  Review Late Set Appropiate Message
9459                         l_progress := 'WMSINB-14822';
9460                         RAISE FND_API.G_EXC_ERROR;
9461                      End if;
9462                  END IF; --IF (l_rti_rec.transaction_type NOT IN ('ACCEPT','REJECT') ) THEN
9463 
9464                  if l_serial_control_code <> 1 then
9465                      l_progress := 'WMSINB-14828';
9466                      l_serial_status := get_serial_status(p_transaction_type  => l_rti_rec.transaction_type
9467                                       , p_auto_transact_code  => l_rti_rec.auto_transact_code
9468                                       , p_parent_transaction_type => l_parent_txn_type
9469                                       , p_parent_parent_txn_type  => l_parent_parent_txn_type
9470                                       , p_quantity => l_rti_rec.primary_quantity);
9471 
9472                      l_progress := 'WMSINB-14835';
9473                      l_inspection_status := get_inspection_status(p_transaction_type  => l_rti_rec.transaction_type
9474                                       , p_routing_header_id  => l_rti_rec.routing_header_id
9475                                       , p_parent_transaction_type => l_parent_txn_type
9476                                       , p_parent_parent_txn_type  => l_parent_parent_txn_type
9477                                       , p_quantity => l_rti_rec.primary_quantity);
9478 
9479                      l_progress := 'WMSINB-14842';
9480                      update_serial_status ( p_product_txn_id => p_txn_id
9481                                      ,p_item_id => l_rti_rec.item_id
9482                                      ,p_organization_id => l_rti_rec.to_organization_id
9483                                      ,p_serial_status => l_serial_status
9484                                      ,p_inspection_status => l_inspection_status
9485                                      ,p_sub => l_rti_rec.subinventory
9486                                      ,p_locator_id => l_rti_rec.locator_id
9487                                      ,x_return_status => x_return_status
9488                                      ,x_msg_count => x_msg_count
9489                                      ,x_msg_data => x_msg_data );
9490 
9491                      -- Check the error status from the above call
9492                      if x_return_status <> G_RET_STS_SUCCESS Then
9493                         --  Review Late Set Appropiate Message
9494                         l_progress := 'WMSINB-14855';
9495                         RAISE FND_API.G_EXC_ERROR;
9496                      End if;
9497                  End if;-- if l_serial_control_code not in (1,6) then
9498               End if; -- END OF FLPN AND TLPN DIFFERENT
9499           ELSE -- ELSE OF l_rti_rec.transfer_lpn_id is not null
9500               if l_serial_control_code <> 1 then
9501                  l_serial_status := get_serial_status(p_transaction_type  => l_rti_rec.transaction_type
9502                                    , p_auto_transact_code  => l_rti_rec.auto_transact_code
9503                                    , p_parent_transaction_type => l_parent_txn_type
9504                                    , p_parent_parent_txn_type  => l_parent_parent_txn_type
9505                                    , p_quantity => l_rti_rec.primary_quantity);
9506 
9507                  l_inspection_status := get_inspection_status(p_transaction_type  => l_rti_rec.transaction_type
9508                                    , p_routing_header_id  => l_rti_rec.routing_header_id
9509                                    , p_parent_transaction_type => l_parent_txn_type
9510                                    , p_parent_parent_txn_type  => l_parent_parent_txn_type
9511                                    , p_quantity => l_rti_rec.primary_quantity);
9512 
9513                  update_serial_status ( p_product_txn_id => p_txn_id
9514                                   ,p_item_id => l_rti_rec.item_id
9515                                   ,p_organization_id => l_rti_rec.to_organization_id
9516                                   ,p_serial_status => l_serial_status
9517                                   ,p_inspection_status => l_inspection_status
9518                                   ,p_sub => l_rti_rec.subinventory
9519                                   ,p_locator_id => l_rti_rec.locator_id
9520                                   ,x_return_status => x_return_status
9521                                   ,x_msg_count => x_msg_count
9522                                   ,x_msg_data => x_msg_data );
9523 
9524                  -- Check the error status from the above call
9525                  if x_return_status <> G_RET_STS_SUCCESS Then
9526                      --  Review Late Set Appropiate Message
9527                      l_progress := 'WMSINB-14860';
9528                      RAISE FND_API.G_EXC_ERROR;
9529                  End if;
9530               End if;-- if l_serial_control_code not in (1,6) then
9531           End if; -- END OF l_rti_rec.transfer_lpn_id is not null
9532       End if; -- END OF l_lpn_context = G_LPN_CONTEXT_VENDOR and l_rti_rec.txntype = 'RECEIVE'
9533 
9534    elsif ( l_rti_rec.transaction_type = 'DELIVER' and  l_rti_rec.source_document_code = 'RMA' ) then
9535        l_progress := 'WMSINB-14864';
9536        -- UPDATE SERIAL STATUS to 4 for serial control code at SO ISUUE CASE
9537        if l_serial_control_code = 6 then
9538           l_progress := 'WMSINB-14867';
9539           update mtl_serial_numbers msn
9540              set msn.current_status = 4
9541              where msn.inventory_item_id       = l_rti_rec.item_id
9542              and msn.current_organization_id = l_rti_rec.to_organization_id
9543              and exists ( select 1
9544                            from mtl_serial_numbers_temp msnt
9545                            where msnt.product_code = 'RCV'
9546                              and msnt.product_transaction_id = p_txn_id
9547                              and msn.serial_number between msnt.fm_serial_number and msnt.to_serial_number
9548                              AND Length(msn.serial_number) = Length(msnt.fm_serial_number)
9549                              AND length(msnt.fm_serial_number)=Length(Nvl(msnt.to_serial_number,msnt.fm_serial_number))  --BUG 3818544
9550                         )
9551           ;
9552        End if;
9553    elsif ( l_rti_rec.transaction_type = 'SHIP' and  l_rti_rec.source_document_code = 'PO' ) then
9554        -- PACK FLPN
9555        --
9556        -- CHECK WHEtheR WE NEED TO POPULATE SOURCE_NAME AS SHIPMENT NUM HERE
9557        --
9558        l_progress := 'WMSINB-14885';
9559 
9560        IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
9561                        l_rti_rec.lpn_id,
9562                        l_transactions_enabled_flag))
9563        THEN
9564           IF (l_debug = 1) THEN
9565               print_debug('PROCESS_TXN - Expense and Non Expense Items cannot be Mixed in an LPN',1);
9566               print_debug('PROCESS_TXN - ORG:LPN:TXNENABLEDFLAG::'||
9567                   l_rti_rec.to_organization_id||':'||l_rti_rec.lpn_id||
9568                   ':'||l_transactions_enabled_flag,1);
9569           END IF;
9570           l_progress := 'WMSINB-14897';
9571 
9572           --review later
9573           RAISE fnd_api.g_exc_error;
9574        END IF; --IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
9575 
9576        l_progress := 'WMSINB-14903';
9577 
9578        IF l_rti_rec.lpn_id IS NOT NULL THEN
9579           l_progress := 'WMSINB-14904';
9580           l_lpn_context := get_lpn_context(p_transaction_type => l_rti_rec.transaction_type
9581                            , p_routing_header_id => l_rti_rec.routing_header_id
9582                            , p_parent_transaction_type => l_parent_txn_type
9583                            , p_parent_parent_txn_type => l_parent_parent_txn_type
9584                            , p_quantity =>	l_rti_rec.primary_quantity
9585                            , p_auto_transact_code => l_rti_rec.auto_transact_code);
9586 
9587           l_progress := 'WMSINB-14911';
9588           update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
9589                            ,p_sub             => l_rti_rec.SUBINVENTORY
9590                            ,p_locator         => l_rti_rec.LOCATOR_ID
9591                            ,p_lpn_context     => l_lpn_context
9592                            ,p_lpn_id          => l_rti_rec.lpn_id
9593                            ,x_return_status   => x_return_status
9594                            ,x_msg_count       => x_msg_count
9595                            ,x_msg_data        => x_msg_data
9596                            ,p_source_name     => l_rti_rec.shipment_num
9597                            ,p_source_header_id => l_rti_rec.shipment_header_id) ;
9598 
9599           -- Check the error status from the above call
9600           if x_return_status <> G_RET_STS_SUCCESS Then
9601               --  Review Late Set Appropiate Message
9602               l_progress := 'WMSINB-14926';
9603               RAISE FND_API.G_EXC_ERROR;
9604           End if;
9605 
9606           PackUnpack_wrapper( x_return_status               => x_return_status
9607                            ,x_msg_count                   => x_msg_count
9608                            ,x_msg_data                    => x_msg_data
9609                            ,p_lot_control_code            => l_lot_control_code
9610                            ,p_serial_control_code         => l_serial_control_code
9611                            ,p_product_txn_id              => p_txn_id
9612                            ,p_product_code                => 'RCV'
9613                            ,p_lpn_id                      => l_rti_rec.lpn_id
9614                            ,p_content_lpn_id              => null
9615                            ,p_content_item_id             => l_rti_rec.item_id
9616                            ,p_content_item_desc           => l_rti_rec.item_description
9617                            ,p_revision                    => l_rti_rec.item_revision
9618                            ,p_primary_quantity            => l_rti_rec.primary_quantity
9619                            ,p_primary_uom                 => l_primary_uom
9620                            ,p_organization_id             => l_rti_rec.to_organization_id
9621                            ,p_operation                   => 1
9622                            ,p_cost_group_id               => null
9623                            ,p_source_type_id              => 1
9624                            ,p_source_header_id            => null --l_rti_rec.shipment_header_id
9625                            ,p_source_name                 => null -- l_rti_rec.shipment_num
9626                            ,p_source_line_id              => NULL
9627                            ,p_source_line_detail_id       => NULL
9628                            -- OPMConvergence
9629                            ,p_sec_quantity          => l_rti_rec.secondary_quantity
9630                            ,p_sec_uom               => l_sec_uom_code
9631                            -- OPMConvergence
9632                            -- *R12* --
9633                            ,p_txn_quantity          => l_rti_rec.quantity
9634                            ,p_txn_uom_code          => l_rti_rec.uom_code
9635                            -- *R12 *--
9636           );
9637 
9638           -- Check the error status from the above call
9639           if x_return_status <> G_RET_STS_SUCCESS Then
9640               --  Review Late Set Appropiate Message
9641               l_progress := 'WMSINB-14957';
9642               RAISE FND_API.G_EXC_ERROR;
9643           End if;
9644        End if; --l_rti_rec.lpn_id IS NOT NULL THEN
9645 
9646 
9647        if l_serial_control_code not in (1,6) then
9648 	   --bug10298326 for serial control items where serial number is not defined, serial_summary_entry is set as 2...need to update to 1
9649 	   --this happens in case of ASN import.
9650 	   update wms_lpn_contents
9651 	   set serial_summary_entry = 1
9652 	   where parent_lpn_id = l_rti_rec.lpn_id
9653 	   and inventory_item_id = l_rti_rec.item_id
9654 	   and organization_id = l_rti_rec.to_organization_id
9655 	   and serial_summary_entry = 2;
9656 
9657 		--Serial status update is required at this point - bug 3487843
9658           l_serial_status := get_serial_status(p_transaction_type  => l_rti_rec.transaction_type
9659                             , p_auto_transact_code  => l_rti_rec.auto_transact_code
9660                             , p_parent_transaction_type => l_parent_txn_type
9661                             , p_parent_parent_txn_type  => l_parent_parent_txn_type
9662                             , p_quantity => l_rti_rec.primary_quantity);
9663 
9664 
9665 
9666           --Bug #4337726
9667           --For a ship transaction with auto transact code 'RECEIVE', set
9668           --inspection status based on routing header id.
9669           IF ( (NVL(l_rti_rec.auto_transact_code, '@#$#$@') = 'RECEIVE') AND
9670                (NVL(l_rti_rec.routing_header_id, 1) = 2)
9671              ) THEN
9672             l_inspection_status := 1;
9673           ELSE
9674             l_inspection_status := null;
9675           END IF;
9676 
9677 
9678 
9679           update_serial_status ( p_product_txn_id => p_txn_id
9680                            ,p_item_id => l_rti_rec.item_id
9681                            ,p_organization_id => l_rti_rec.to_organization_id
9682                            ,p_serial_status => l_serial_status
9683                            ,p_inspection_status => l_inspection_status
9684                            ,p_sub => l_rti_rec.subinventory
9685                            ,p_locator_id => l_rti_rec.locator_id
9686                            ,x_return_status => x_return_status
9687                            ,x_msg_count => x_msg_count
9688                            ,x_msg_data => x_msg_data );
9689 
9690 
9691           -- Check the error status from the above call
9692           if x_return_status <> G_RET_STS_SUCCESS Then
9693               --  Review Late Set Appropiate Message
9694               l_progress := 'WMSINB-14960';
9695               RAISE FND_API.G_EXC_ERROR;
9696           End if;
9697        End if; --if l_serial_control_code not in (1,6) then
9698 
9699        BEGIN
9700           SELECT po_header_id
9701              INTO l_po_header_id
9702              FROM po_line_locations_all
9703              WHERE line_location_id = l_rti_rec.po_line_location_id;
9704        EXCEPTION
9705           WHEN OTHERS THEN
9706               IF (l_debug = 1) THEN
9707                  print_debug('Error retrieving po_header_id',1);
9708               END IF;
9709        END ;
9710 
9711        IF (l_debug = 1) THEN
9712           print_debug('PROCESS_TXN - IMPORT ASN. CALLING RSV API',1);
9713           print_debug('l_rti_rec.transaction_type     => '||l_rti_rec.transaction_type,1);
9714           print_debug('l_rti_rec.source_document_code => '||l_rti_rec.source_document_code,1);
9715           print_debug('l_rti_rec.to_organization_id   => '||l_rti_rec.to_organization_id,1);
9716           print_debug('l_rti_rec.item_id              => '||l_rti_rec.item_id,1);
9717           print_debug('l_rti_rec.item_revision        => '||l_rti_rec.item_revision,1);
9718           print_debug('l_rti_rec.project_id           => '||l_rti_rec.project_id,1);
9719           print_debug('l_rti_rec.task_id              => '||l_rti_rec.task_id,1);
9720           print_debug('l_rti_rec.primary_uom_code     => '||l_primary_uom,1);
9721           print_debug('l_rti_rec.primary_quantity     => '||l_rti_rec.primary_quantity,1);
9722           print_debug('l_po_header_id                 => '||l_po_header_id,1);
9723           print_debug('l_rti_rec.po_line_location_id  => '||l_rti_rec.po_line_location_id,1);
9724           print_debug('l_rti_rec.shipment_line_id     => '||l_rti_rec.shipment_line_id,1);
9725           print_debug('l_rti_rec.asn_line_flag     => '||l_asn_line_flag,1);
9726        END IF;
9727 
9728        /* Bug 5365065.
9729        * In the procedure maintain_reservation, we check whether l_asn_line_flag is Y or N.
9730        * But the table l_mol_res_in was not populated with asn_line_flag. Populated the table
9731        * with l_asn_line_flag.
9732        */
9733        l_mol_res_in(1).transaction_type       := l_rti_rec.transaction_type;
9734        l_mol_res_in(1).source_document_code   := l_rti_rec.source_document_code;
9735        l_mol_res_in(1).organization_id        := l_rti_rec.to_organization_id;
9736        l_mol_res_in(1).inventory_item_id      := l_rti_rec.item_id;
9737        l_mol_res_in(1).item_revision          := l_rti_rec.item_revision;
9738        l_mol_res_in(1).project_id             := l_rti_rec.project_id;
9739        l_mol_res_in(1).task_id                := l_rti_rec.task_id;
9740        l_mol_res_in(1).primary_uom_code       := l_primary_uom;
9741        l_mol_res_in(1).primary_qty            := l_rti_rec.primary_quantity;
9742        l_mol_res_in(1).po_header_id           := l_po_header_id;
9743        l_mol_res_in(1).po_line_location_id    := l_rti_rec.po_line_location_id;
9744        l_mol_res_in(1).shipment_line_id       := l_rti_rec.shipment_line_id;
9745        l_mol_res_in(1).asn_line_flag          := l_asn_line_flag;
9746 
9747        INV_RCV_RESERVATION_UTIL.maintain_reservations
9748          (x_return_status => x_return_status
9749           ,x_msg_count     => x_msg_count
9750           ,x_msg_data      => x_msg_data
9751           ,x_mol_tb        => l_mol_res_out
9752           ,p_cas_mol_tb    => l_mol_res_in
9753           );
9754 
9755        IF (l_debug = 1) THEN
9756           print_debug('PROCESS_TXN - rsv api returns:'||x_return_status,1);
9757        END IF;
9758 
9759        IF (x_return_status <> g_ret_sts_success) THEN
9760           l_progress := 'WMSINB-14998';
9761           RAISE FND_API.G_EXC_ERROR;
9762        END IF;
9763 
9764    elsif ( l_rti_rec.transaction_type = 'CORRECT' and ( l_parent_txn_type not in ( 'DELIVER','RETURN TO RECEIVING')
9765           and NOT (l_parent_txn_type in ('RETURN TO VENDOR', 'RETURN TO CUSTOMER') and l_parent_parent_txn_type =
9766               'DELIVER' )  )
9767          ) then
9768        l_progress := 'WMSINB-14965';
9769        if l_rti_rec.primary_quantity  < 0 then
9770           if l_rti_rec.transfer_lpn_id is not null then
9771              -- fix for bug 5530130: if l_rti_rec.transfer_lpn_id <> nvl(l_rti_rec.lpn_id,-9999 ) then
9772              l_progress := 'WMSINB-14969';
9773              -- UNPACK TLPN FOR RTI.ITEM, MTLT.LOTNUM, MSNT.FMSERNUM, MSNT.TOSERNUM
9774              PackUnpack_wrapper( x_return_status               => x_return_status
9775                                  ,x_msg_count                   => x_msg_count
9776                                  ,x_msg_data                    => x_msg_data
9777                                  ,p_lot_control_code            => l_lot_control_code
9778                                  ,p_serial_control_code         => l_serial_control_code
9779                                  ,p_product_txn_id              => p_txn_id
9780                                  ,p_product_code                => 'RCV'
9781                                  ,p_lpn_id                      => l_rti_rec.transfer_lpn_id
9782                                  ,p_content_lpn_id              => null
9783                                  ,p_content_item_id             => l_rti_rec.item_id
9784                                  ,p_content_item_desc           => l_rti_rec.item_description
9785                                  ,p_revision                    => l_rti_rec.item_revision
9786                                  ,p_primary_quantity            => Abs(l_rti_rec.primary_quantity)
9787                                  ,p_primary_uom                 => l_primary_uom
9788                                  ,p_organization_id             => l_rti_rec.to_organization_id
9789                                  ,p_operation                   => 2
9790                                  ,p_cost_group_id               => null
9791                                  ,p_source_type_id              => null
9792                                  ,p_source_header_id            => l_int_trx_id_for_unpack
9793                                  ,p_source_name                 => l_trx_type_for_unpack
9794                                  ,p_source_line_id              => NULL
9795                                  ,p_source_line_detail_id       => NULL
9796                                  -- OPMConvergence
9797                                  ,p_sec_quantity          => ABS(l_rti_rec.secondary_quantity)
9798                                  ,p_sec_uom               => l_sec_uom_code
9799                                  -- OPMConvergence
9800                                  -- *R12* --
9801                                  ,p_txn_quantity          => ABS(l_rti_rec.quantity)
9802                                  ,p_txn_uom_code          => l_rti_rec.uom_code
9803                                  -- *R12 *--
9804              );
9805 
9806              -- Check the error status from the above call
9807              if x_return_status <> G_RET_STS_SUCCESS Then
9808                   --  Review Late Set Appropiate Message
9809                   l_progress := 'WMSINB-14998';
9810                   RAISE FND_API.G_EXC_ERROR;
9811              End if;
9812              -- fix for bug 5530130:End if;  -- END OF FLPN and TLPN Different
9813           End if; -- END OF l_rti_rec.transfer_lpn_id is not null
9814 
9815           l_progress := 'WMSINB-15004';
9816 
9817           if l_rti_rec.lpn_id is not null then
9818               -- fix for bug 5530130:if l_rti_rec.lpn_id <> nvl(l_rti_rec.transfer_lpn_id,-9999) then
9819               l_progress := 'WMSINB-15008';
9820 
9821               IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
9822                            l_rti_rec.lpn_id,
9823                            l_transactions_enabled_flag))
9824               THEN
9825                   IF (l_debug = 1) THEN
9826                      print_debug('PROCESS_TXN - Expense and Non Expense Items cannot be Mixed in an LPN',1);
9827                      print_debug('PROCESS_TXN - ORG:LPN:TXNENABLEDFLAG::'||
9828                             l_rti_rec.to_organization_id||':'||l_rti_rec.lpn_id||
9829                             ':'||l_transactions_enabled_flag,1);
9830                   END IF;
9831                   l_progress := 'WMSINB-15020';
9832 
9833                   --review later
9834                   RAISE fnd_api.g_exc_error;
9835               END IF; --IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
9836               IF l_rti_rec.project_id IS NOT NULL THEN--Added for Bug 7219754,FP:7259462
9837               IF (validate_pjm_commingle(l_rti_rec.to_organization_id,
9838                      l_rti_rec.lpn_id,
9839                      l_rti_rec.project_id,
9840                      l_rti_rec.task_id))
9841               THEN
9842                   IF (l_debug = 1) THEN
9843                      print_debug('PROCESS_TXN - Project/Task commingling not allowed in LPN:'||l_rti_rec.lpn_id,1);
9844                   END IF;
9845                   l_progress := 'WMSINB-15026';
9846 
9847                   RAISE fnd_api.g_exc_error;
9848               END IF; --IF (!validate_pjm_commingle(l_rti_rec.to_organization_id,
9849               END IF; -- IF l_rti_rec.project_id IS NOT NULL
9850               l_lpn_context := get_lpn_context(p_transaction_type => l_rti_rec.transaction_type
9851                               , p_routing_header_id => l_rti_rec.routing_header_id
9852                               , p_parent_transaction_type => l_parent_txn_type
9853                               , p_parent_parent_txn_type => l_parent_parent_txn_type
9854                               , p_quantity => l_rti_rec.primary_quantity
9855                               , p_auto_transact_code => l_rti_rec.auto_transact_code);
9856 
9857               l_progress := 'WMSINB-15034';
9858               update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
9859                             ,p_sub             => l_rti_rec.SUBINVENTORY
9860                             ,p_locator         => l_rti_rec.LOCATOR_ID
9861                             ,p_lpn_context     => l_lpn_context
9862                             ,p_lpn_id          => l_rti_rec.lpn_id
9863                             ,x_return_status   => x_return_status
9864                             ,x_msg_count       => x_msg_count
9865                             ,x_msg_data        => x_msg_data ) ;
9866 
9867               -- Check the error status from the above call
9868               if x_return_status <> G_RET_STS_SUCCESS Then
9869                   --  Review Late Set Appropiate Message
9870                   l_progress := 'WMSINB-15047';
9871                   RAISE FND_API.G_EXC_ERROR;
9872               End if;
9873 
9874               PackUnpack_wrapper( x_return_status               => x_return_status
9875                               ,x_msg_count                   => x_msg_count
9876                               ,x_msg_data                    => x_msg_data
9877                               ,p_lot_control_code            => l_lot_control_code
9878                               ,p_serial_control_code         => l_serial_control_code
9879                               ,p_product_txn_id              => p_txn_id
9880                               ,p_product_code                => 'RCV'
9881                               ,p_lpn_id                      => l_rti_rec.lpn_id
9882                               ,p_content_lpn_id              => null
9883                               ,p_content_item_id             => l_rti_rec.item_id
9884                               ,p_content_item_desc           => l_rti_rec.item_description
9885                               ,p_revision                    => l_rti_rec.item_revision
9886                               ,p_primary_quantity            => Abs(l_rti_rec.primary_quantity)
9887                               ,p_primary_uom                 => l_primary_uom
9888                               ,p_organization_id             => l_rti_rec.to_organization_id
9889                               ,p_operation                   => 1
9890                               ,p_cost_group_id               => null
9891                               ,p_source_type_id              => null
9892                               ,p_source_header_id            => null -- l_rti_rec.group_id
9893                               ,p_source_name                 => null
9894                               ,p_source_line_id              => NULL
9895                               ,p_source_line_detail_id       => NULL
9896                               -- OPMConvergence
9897                               ,p_sec_quantity          => Abs(l_rti_rec.secondary_quantity)
9898                               ,p_sec_uom               => l_sec_uom_code
9899                               -- OPMConvergence
9900                               -- *R12* --
9901                               ,p_txn_quantity          => Abs(l_rti_rec.quantity)
9902                               ,p_txn_uom_code          => l_rti_rec.uom_code
9903                               -- *R12 *--
9904               );
9905 
9906               -- Check the error status from the above call
9907               if x_return_status <> G_RET_STS_SUCCESS Then
9908                   --  Review Late Set Appropiate Message
9909                   l_progress := 'WMSINB-15078';
9910                   RAISE FND_API.G_EXC_ERROR;
9911               End if;
9912 
9913               -- fix for bug 5530130: END IF; --Endif of FLPN <> TLPN
9914           End if; -- END OF l_rti_rec.lpn_id is not null
9915           l_progress := 'WMSINB-15082';
9916           if l_serial_control_code not in (1,6) then
9917 
9918               l_progress := 'WMSINB-15085';
9919               l_serial_status := get_serial_status(p_transaction_type  => l_rti_rec.transaction_type
9920                             , p_auto_transact_code  => l_rti_rec.auto_transact_code
9921                             , p_parent_transaction_type => l_parent_txn_type
9922                             , p_parent_parent_txn_type  => l_parent_parent_txn_type
9923                             , p_quantity => l_rti_rec.primary_quantity);
9924 
9925               l_progress := 'WMSINB-15092';
9926               l_inspection_status := get_inspection_status(p_transaction_type  => l_rti_rec.transaction_type
9927                             , p_routing_header_id  => l_rti_rec.routing_header_id
9928                             , p_parent_transaction_type => l_parent_txn_type
9929                             , p_parent_parent_txn_type  => l_parent_parent_txn_type
9930                             , p_quantity => l_rti_rec.primary_quantity);
9931 
9932               l_progress := 'WMSINB-15099';
9933 
9934               update_serial_status ( p_product_txn_id => p_txn_id
9935                             ,p_item_id => l_rti_rec.item_id
9936                             ,p_organization_id => l_rti_rec.to_organization_id
9937                             ,p_serial_status => l_serial_status
9938                             ,p_inspection_status => l_inspection_status
9939                             ,p_sub => l_rti_rec.subinventory
9940                             ,p_locator_id => l_rti_rec.locator_id
9941                             ,x_return_status => x_return_status
9942                             ,x_msg_count => x_msg_count
9943                             ,x_msg_data => x_msg_data );
9944 
9945               -- Check the error status from the above call
9946               if x_return_status <> G_RET_STS_SUCCESS Then
9947                  --  Review Late Set Appropiate Message
9948                  l_progress := 'WMSINB-15113';
9949                  RAISE FND_API.G_EXC_ERROR;
9950               End if;
9951           End if; --if l_serial_control_code not in (1,6) then
9952        Else -- QTY > 0
9953           l_progress := 'WMSINB-15120';
9954           if l_rti_rec.lpn_id is not null then
9955               if l_rti_rec.lpn_id <> nvl(l_rti_rec.transfer_lpn_id,-9999) then
9956                  -- UNPACK FLPN FOR RTI.ITEM, MTLT.LOTNUM, MSNT.FMSERNUM, MSNT.TOSERNUM
9957                  l_progress := 'WMSINB-15124';
9958                  PackUnpack_wrapper( x_return_status            => x_return_status
9959                                     ,x_msg_count                   => x_msg_count
9960                                     ,x_msg_data                    => x_msg_data
9961                                     ,p_lot_control_code            => l_lot_control_code
9962                                     ,p_serial_control_code         => l_serial_control_code
9963                                     ,p_product_txn_id              => p_txn_id
9964                                     ,p_product_code                => 'RCV'
9965                                     ,p_lpn_id                      => l_rti_rec.lpn_id
9966                                     ,p_content_lpn_id              => null
9967                                     ,p_content_item_id             => l_rti_rec.item_id
9968                                     ,p_content_item_desc           => l_rti_rec.item_description
9969                                     ,p_revision                    => l_rti_rec.item_revision
9970                                     ,p_primary_quantity            => l_rti_rec.primary_quantity
9971                                     ,p_primary_uom                 => l_primary_uom
9972                                     ,p_organization_id             => l_rti_rec.to_organization_id
9973                                     ,p_operation                   => 2
9974                                     ,p_cost_group_id               => null
9975                                     ,p_source_type_id              => null
9976                                     ,p_source_header_id            => l_int_trx_id_for_unpack
9977                                     ,p_source_name                 => l_trx_type_for_unpack
9978                                     ,p_source_line_id              => NULL
9979                                     ,p_source_line_detail_id       => NULL
9980                                     -- OPMConvergence
9981                                     ,p_sec_quantity          => l_rti_rec.secondary_quantity
9982                                     ,p_sec_uom               => l_sec_uom_code
9983                                     -- OPMConvergence
9984                                     -- *R12* --
9985                                     ,p_txn_quantity          => l_rti_rec.quantity
9986                                     ,p_txn_uom_code          => l_rti_rec.uom_code
9987                                     -- *R12 *--
9988                  );
9989 
9990                  -- Check the error status from the above call
9991                  if x_return_status <> G_RET_STS_SUCCESS Then
9992                      --  Review Late Set Appropiate Message
9993                      l_progress := 'WMSINB-15152';
9994                      RAISE FND_API.G_EXC_ERROR;
9995                  End if;
9996 
9997               End if; -- END OF FLPN and TLPN different
9998           End if; -- END OF l_rti_rec.lpn_id is not null then
9999 
10000           if l_rti_rec.transfer_lpn_id is not null then
10001               if l_rti_rec.transfer_lpn_id <> nvl(l_rti_rec.lpn_id,-9999 ) then
10002                  l_progress := 'WMSINB-15161';
10003 
10004                  IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
10005                            l_rti_rec.transfer_lpn_id,
10006                            l_transactions_enabled_flag))
10007                  THEN
10008                      IF (l_debug = 1) THEN
10009                         print_debug('PROCESS_TXN - Expense and Non Expense Items cannot be Mixed in an LPN',1);
10010                         print_debug('PROCESS_TXN - ORG:LPN:TXNENABLEDFLAG::'||
10011                                l_rti_rec.to_organization_id||':'||l_rti_rec.transfer_lpn_id||
10012                                ':'||l_transactions_enabled_flag,1);
10013                      END IF;
10014                      l_progress := 'WMSINB-15173';
10015 
10016                      --review later
10017                      RAISE fnd_api.g_exc_error;
10018                  END IF; --IF (validate_mixed_expense_items(l_rti_rec.to_organization_id,
10019                  IF l_rti_rec.project_id IS NOT NULL THEN--Added for Bug 7219754,FP:7259462
10020                  IF (validate_pjm_commingle(l_rti_rec.to_organization_id,
10021                      l_rti_rec.transfer_lpn_id,
10022                      l_rti_rec.project_id,
10023                      l_rti_rec.task_id))
10024                  THEN
10025                      IF (l_debug = 1) THEN
10026                         print_debug('PROCESS_TXN - Project/Task commingling not allowed in LPN:'||l_rti_rec.transfer_lpn_id,1);
10027                      END IF;
10028                      l_progress := 'WMSINB-15179';
10029 
10030                      RAISE fnd_api.g_exc_error;
10031                  END IF; --IF (!validate_pjm_commingle(l_rti_rec.to_organization_id,
10032                  END IF; -- IF l_rti_rec.project_id IS NOT NULL
10033                  l_lpn_context := get_lpn_context(p_transaction_type => l_rti_rec.transaction_type
10034                                  , p_routing_header_id => l_rti_rec.routing_header_id
10035                                  , p_parent_transaction_type => l_parent_txn_type
10036                                  , p_parent_parent_txn_type => l_parent_parent_txn_type
10037                                  , p_quantity => l_rti_rec.primary_quantity
10038                                  , p_auto_transact_code => l_rti_rec.auto_transact_code);
10039 
10040                  l_progress := 'WMSINB-15187';
10041 
10042                  update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
10043                                ,p_sub             => l_rti_rec.SUBINVENTORY
10044                                ,p_locator         => l_rti_rec.LOCATOR_ID
10045                                ,p_lpn_context     => l_lpn_context
10046                                ,p_lpn_id          => l_rti_rec.transfer_lpn_id
10047                                ,x_return_status   => x_return_status
10048                                ,x_msg_count       => x_msg_count
10049                                ,x_msg_data        => x_msg_data ) ;
10050 
10051                  -- Check the error status from the above call
10052                  if x_return_status <> G_RET_STS_SUCCESS Then
10053                      --  Review Late Set Appropiate Message
10054                      l_progress := 'WMSINB-15201';
10055                      RAISE FND_API.G_EXC_ERROR;
10056                  End if;
10057 
10058                  PackUnpack_wrapper( x_return_status               => x_return_status
10059                                     ,x_msg_count                   => x_msg_count
10060                                     ,x_msg_data                    => x_msg_data
10061                                     ,p_lot_control_code            => l_lot_control_code
10062                                     ,p_serial_control_code         => l_serial_control_code
10063                                     ,p_product_txn_id              => p_txn_id
10064                                     ,p_product_code                => 'RCV'
10065                                     ,p_lpn_id                      => l_rti_rec.transfer_lpn_id
10066                                     ,p_content_lpn_id              => null
10067                                     ,p_content_item_id             => l_rti_rec.item_id
10068                                     ,p_content_item_desc           => l_rti_rec.item_description
10069                                     ,p_revision                    => l_rti_rec.item_revision
10070                                     ,p_primary_quantity            => l_rti_rec.primary_quantity
10071                                     ,p_primary_uom                 => l_primary_uom
10072                                     ,p_organization_id             => l_rti_rec.to_organization_id
10073                                     ,p_operation                   => 1
10074                                     ,p_cost_group_id               => null
10075                                     ,p_source_type_id              => null
10076                                     ,p_source_header_id            => null -- l_rti_rec.group_id
10077                                     ,p_source_name                 => null
10078                                     ,p_source_line_id              => NULL
10079                                     ,p_source_line_detail_id       => NULL
10080                                     -- OPMConvergence
10081                                     ,p_sec_quantity          => l_rti_rec.secondary_quantity
10082                                     ,p_sec_uom               => l_sec_uom_code
10083                                     -- OPMConvergence
10084                                     -- *R12* --
10085                                     ,p_txn_quantity          => l_rti_rec.quantity
10086                                     ,p_txn_uom_code          => l_rti_rec.uom_code
10087                                     -- *R12 *--
10088                  );
10089 
10090                  -- Check the error status from the above call
10091                  if x_return_status <> G_RET_STS_SUCCESS Then
10092                      --  Review Late Set Appropiate Message
10093                      l_progress := 'WMSINB-15232';
10094                      RAISE FND_API.G_EXC_ERROR;
10095                  End if;
10096 
10097               End if; -- END OF FLPN and TLPN different
10098           End if; -- END OF l_rti_rec.transfer_lpn_id is not null
10099 
10100           if l_serial_control_code not in (1,6) then
10101               l_serial_status := get_serial_status(p_transaction_type  => l_rti_rec.transaction_type
10102                                , p_auto_transact_code  => l_rti_rec.auto_transact_code
10103                                , p_parent_transaction_type => l_parent_txn_type
10104                                , p_parent_parent_txn_type  => l_parent_parent_txn_type
10105                                , p_quantity => l_rti_rec.primary_quantity);
10106 
10107               l_inspection_status := get_inspection_status(p_transaction_type  => l_rti_rec.transaction_type
10108                                , p_routing_header_id  => l_rti_rec.routing_header_id
10109                                , p_parent_transaction_type => l_parent_txn_type
10110                                , p_parent_parent_txn_type  => l_parent_parent_txn_type
10111                                , p_quantity => l_rti_rec.primary_quantity);
10112 
10113               l_progress := 'WMSINB-15249';
10114               update_serial_status ( p_product_txn_id => p_txn_id
10115                                ,p_item_id => l_rti_rec.item_id
10116                                ,p_organization_id => l_rti_rec.to_organization_id
10117                                ,p_serial_status => l_serial_status
10118                                ,p_inspection_status => l_inspection_status
10119                                ,p_sub => l_rti_rec.subinventory
10120                                ,p_locator_id => l_rti_rec.locator_id
10121                                ,x_return_status => x_return_status
10122                                ,x_msg_count => x_msg_count
10123                                ,x_msg_data => x_msg_data );
10124 
10125               -- Check the error status from the above call
10126               if x_return_status <> G_RET_STS_SUCCESS Then
10127                  --  Review Late Set Appropiate Message
10128                  l_progress := 'WMSINB-15262';
10129                  RAISE FND_API.G_EXC_ERROR;
10130               End if;
10131           End if; --if l_serial_control_code not in (1,6) then
10132 
10133        End if; -- END OF l_rti.rec.primary_quantity  < 0
10134        --
10135        --BUG 5095399 (FP of BUG 5095182)
10136    elsif ((l_rti_rec.transaction_type = 'CORRECT') and  (l_parent_txn_type = 'DELIVER')) THEN
10137        IF (l_rti_rec.primary_quantity < 0) and  (l_rti_rec.lpn_id is not null) THEN
10138 
10139           IF (l_debug = 1) THEN
10140             print_debug('PROCESS_TXN - Transaction type CORRECT and Parent DELIVER'||l_lpn_context,1);
10141           END IF;
10142 
10143           l_progress := 'WMSINB-15265';
10144 
10145           l_lpn_context := get_lpn_context(p_transaction_type => l_rti_rec.transaction_type
10146                           , p_routing_header_id => l_rti_rec.routing_header_id
10147                           , p_parent_transaction_type => l_parent_txn_type
10148                           , p_parent_parent_txn_type => l_parent_parent_txn_type
10149                           , p_quantity => l_rti_rec.primary_quantity
10150                           , p_auto_transact_code => l_rti_rec.auto_transact_code);
10151 
10152           l_progress := 'WMSINB-15266';
10153           IF (l_debug = 1) THEN
10154              print_debug('PROCESS_TXN - l_lpn_context='||l_lpn_context,1);
10155           END IF;
10156 
10157           update_lpn_location_context(p_organization_id => l_rti_rec.to_organization_id
10158                                         ,p_sub             => l_rti_rec.SUBINVENTORY
10159                                         ,p_locator         => l_rti_rec.LOCATOR_ID
10160                                         ,p_lpn_context     => l_lpn_context
10161                                         ,p_lpn_id          => l_rti_rec.lpn_id
10162                                         ,x_return_status   => x_return_status
10163                                         ,x_msg_count       => x_msg_count
10164                                         ,x_msg_data        => x_msg_data ) ;
10165 
10166           l_progress := 'WMSINB-15267';
10167 
10168           if x_return_status <> G_RET_STS_SUCCESS Then
10169              --  Review Late Set Appropiate Message
10170              l_progress := 'WMSINB-15268';
10171              RAISE FND_API.G_EXC_ERROR;
10172           End if;
10173        end if; -- IF (l_rti_rec.primary_quantity < 0) and  (l_rti_rec.lpn_id is not null) THEN
10174        --End bug 5095399
10175    END IF;
10176 
10177 
10178    IF (l_debug = 1) THEN
10179       print_debug('PROCESS_TXN - Auto Transact code = '|| l_rti_rec.auto_transact_code,1);
10180    END IF;
10181 
10182    /* Changes for Match Txn as the UOM_CODE might be null in RTI for Match Txn */
10183 
10184    IF l_rti_rec.uom_code is null then
10185       IF (l_debug = 1) THEN
10186          print_debug('PROCESS_TXN - Get uom_code from unit_of_measure as Uom_code is null in rti',1);
10187          print_debug('PROCESS_TXN - Unit_of_measure = '|| l_rti_rec.unit_of_measure,1);
10188       END IF;
10189 
10190       BEGIN
10191           SELECT uom_code
10192           into l_rti_rec.uom_code
10193           FROM mtl_item_uoms_view
10194           WHERE organization_id = l_rti_rec.to_organization_id
10195           AND inventory_item_id =  l_rti_rec.item_id
10196           AND unit_of_measure = l_rti_rec.unit_of_measure;
10197       EXCEPTION
10198           WHEN OTHERS THEN
10199               IF (l_debug = 1) THEN
10200                  print_debug('PROCESS_TXN : Error retrieving uom_code', 1);
10201               END IF;
10202               l_progress := 'WMSINB-15300';
10203               RAISE fnd_api.g_exc_error;
10204       END;
10205       -- OPMConvergence
10206       IF l_rti_rec.secondary_unit_of_measure IS NOT NULL THEN
10207 
10208           BEGIN
10209              SELECT uom_code
10210              INTO   l_rti_rec.secondary_uom_code
10211              FROM   mtl_item_uoms_view
10212              WHERE  organization_id = l_rti_rec.to_organization_id
10213              AND    inventory_item_id = l_rti_rec.item_id
10214              AND    unit_of_measure = l_rti_rec.secondary_unit_of_measure;
10215           EXCEPTION
10216              WHEN OTHERS THEN
10217                IF (l_debug = 1) THEN
10218                  print_debug('CANCEL_ASN: Error retrieving sec_uom_code'||sqlerrm, 1);
10219                END IF;
10220                l_progress := 'WMSINB-11211';
10221                RAISE fnd_api.g_exc_error;
10222           END;
10223 
10224        END IF;
10225                -- OPMConvergence
10226    END IF;
10227 
10228    --BUG 3386801: No need to call maintain_mo_wrapper for CANCEL transactions
10229 
10230    -- 4398331 The CASE FOR SHIP and auto trasact code of DELIVER is also
10231    -- added for the case below.
10232 
10233    IF (l_rti_rec.transaction_type in ('RECEIVE','DELIVER','SHIP') AND
10234        Nvl(l_rti_rec.auto_transact_code, '@#$#$@') = 'DELIVER') THEN
10235       BEGIN
10236           SELECT requisition_line_id
10237             INTO l_requisition_line_id
10238             FROM rcv_transactions
10239             WHERE interface_transaction_id = p_txn_id;
10240       EXCEPTION
10241           WHEN OTHERS THEN
10242              IF (l_debug = 1) THEN
10243                 print_debug('Error retrieving req_line_id',1);
10244              END IF;
10245              l_requisition_line_id := NULL;
10246       END;
10247 
10248       IF (l_rti_rec.po_line_location_id IS NOT NULL) THEN
10249          BEGIN
10250              SELECT po_header_id
10251                INTO l_po_header_id
10252                FROM po_line_locations_all
10253                WHERE line_location_id = l_rti_rec.po_line_location_id;
10254          EXCEPTION
10255              WHEN OTHERS THEN
10256                 IF (l_debug = 1) THEN
10257               print_debug('Error retrieving po_header_id',1);
10258                 END IF;
10259          END ;
10260       ELSE
10261          l_po_header_id := NULL;
10262       END IF;
10263 
10264 
10265       IF (l_debug = 1) THEN
10266           print_debug('PROCESS_TXN - DIRECT RECEIPT. CALLING RSV API',1);
10267           print_debug('l_rti_rec.transaction_type     => '||l_rti_rec.transaction_type,1);
10268           print_debug('l_rti_rec.to_organization_id   => '||l_rti_rec.to_organization_id,1);
10269           print_debug('l_rti_rec.item_id              => '||l_rti_rec.item_id,1);
10270           print_debug('l_rti_rec.item_revision        => '||l_rti_rec.item_revision,1);
10271           print_debug('l_rti_rec.project_id           => '||l_rti_rec.project_id,1);
10272           print_debug('l_rti_rec.task_id              => '||l_rti_rec.task_id,1);
10273           print_debug('l_rti_rec.primary_uom_code     => '||l_primary_uom,1);
10274           print_debug('l_rti_rec.primary_quantity     => '||l_rti_rec.primary_quantity,1);
10275           print_debug('l_po_header_id                 => '||l_po_header_id,1);
10276           print_debug('l_rti_rec.po_line_location_id  => '||l_rti_rec.po_line_location_id,1);
10277           print_debug('l_rti_rec.shipment_line_id     => '||l_rti_rec.shipment_line_id,1);
10278           print_debug('l_requisition_line_id          => '||l_requisition_line_id,1);
10279           print_debug('l_rti_rec.auto_transact_code   => '||l_rti_rec.auto_transact_code,1);
10280           print_debug('l_rti_rec.asn_line_flag        => '||l_asn_line_flag,1);
10281       END IF;
10282 
10283       /* Bug 5365065.
10284        * In the procedure maintain_reservation, we check whether l_asn_line_flag is Y or N.
10285        * But the table l_mol_res_in was not populated with asn_line_flag. Populated the table
10286        * with l_asn_line_flag.
10287        */
10288       l_mol_res_in(1).transaction_type       := l_rti_rec.transaction_type;
10289       l_mol_res_in(1).organization_id        := l_rti_rec.to_organization_id;
10290       l_mol_res_in(1).inventory_item_id      := l_rti_rec.item_id;
10291       l_mol_res_in(1).item_revision          := l_rti_rec.item_revision;
10292       l_mol_res_in(1).project_id             := l_rti_rec.project_id;
10293       l_mol_res_in(1).task_id                := l_rti_rec.task_id;
10294       l_mol_res_in(1).primary_uom_code       := l_primary_uom;
10295       l_mol_res_in(1).primary_qty            := l_rti_rec.primary_quantity;
10296       l_mol_res_in(1).po_header_id           := l_po_header_id;
10297       l_mol_res_in(1).po_line_location_id    := l_rti_rec.po_line_location_id;
10298       l_mol_res_in(1).shipment_line_id       := l_rti_rec.shipment_line_id;
10299       l_mol_res_in(1).requisition_line_id    := l_requisition_line_id;
10300       l_mol_res_in(1).auto_transact_code     := l_rti_rec.auto_transact_code;
10301       l_mol_res_in(1).asn_line_flag          := l_asn_line_flag;
10302        --8833953 added sub/loc
10303       l_mol_res_in(1).subinventory_code      := l_rti_rec.subinventory;
10304       l_mol_res_in(1).locator_id             := l_rti_rec.locator_id;
10305 	  --13784450 added lpn
10306 	  l_mol_res_in(1).lpn_id             := l_rti_rec.transfer_lpn_id;
10307 	  print_debug('l_rti_rec.transfer_lpn_id => '||l_rti_rec.transfer_lpn_id,1);
10308 	  print_debug('l_rti_rec.lpn_id          => '||l_rti_rec.lpn_id,1);
10309 	  print_debug('l_mol_res_in(1).lpn_id    => '||l_mol_res_in(1).lpn_id,1);
10310 	  --13784450
10311 
10312       -- 10396979 addition
10313       if wms_install.check_install(l_wms_return_status,
10314 				    l_wms_msg_count,
10315 				    l_wms_msg_data,
10316 				    l_rti_rec.to_organization_id) then
10317 
10318         print_debug('This is a WMS enabled Org. Changes for bug # 10396979 ',1);
10319 	if l_rti_rec.item_id is not null then
10320 	 begin
10321 	   select LOT_CONTROL_CODE into l_wms_lot
10322 	   from mtl_system_items
10323 	   where inventory_item_id = l_rti_rec.item_id
10324 	   and organization_id = l_rti_rec.to_organization_id
10325 	   and rownum = 1;
10326          exception
10327 	   when others then
10328 	   print_debug('Error while fetching the lot control code ',1);
10329          end;
10330 
10331 	   if l_wms_lot = 2 then
10332               print_debug('This is a lot controlled item ',1);
10333 	      begin
10334 	      SELECT lot_number into l_wms_lot_number
10335 	      FROM mtl_transaction_lots_temp
10336 	      WHERE PRODUCT_TRANSACTION_ID = p_txn_id;
10337 
10338 	      print_debug('Lot number is :=  '||l_wms_lot_number,1);
10339               exception
10340 	       when others then
10341 	       print_debug('Error while fetching the lot number ',1);
10342 	      end;
10343 	      l_mol_res_in(1).lot_number             := l_wms_lot_number;
10344 	   end if;
10345 	end if;
10346       end if;
10347       -- 10396979 addition
10348 
10349       INV_RCV_RESERVATION_UTIL.maintain_reservations
10350          (x_return_status => x_return_status
10351           ,x_msg_count     => x_msg_count
10352           ,x_msg_data      => x_msg_data
10353           ,x_mol_tb        => l_mol_res_out
10354           ,p_cas_mol_tb    => l_mol_res_in
10355           );
10356 
10357       IF (l_debug = 1) THEN
10358          print_debug('PROCESS_TXN - rsv api returns:'||x_return_status,1);
10359       END IF;
10360 
10361       IF (x_return_status <> g_ret_sts_success) THEN
10362          l_progress := 'WMSINB-14998';
10363          RAISE FND_API.G_EXC_ERROR;
10364       END IF;
10365 
10366    ELSIF ((l_rti_rec.transaction_type = 'SHIP'
10367       AND Nvl(l_rti_rec.auto_transact_code, '@#$#$@') <> 'RECEIVE')
10368        OR (l_rti_rec.transaction_type = 'CANCEL')
10369        OR (l_rti_rec.transaction_type IN ('RETURN TO VENDOR','RETURN TO CUSTOMER')
10370       AND l_parent_txn_type = 'DELIVER')) THEN
10371       IF (l_debug = 1) THEN
10372           print_debug('PROCESS_TXN - No Need to call MAINTAIN_MO_WRAPPER for this case ',1);
10373       END IF;
10374    ELSE --IF ((l_rti_rec.transaction_type in ('RECEIVE','DELIVER') AND (SHIP with auto transact code as RECEIVE
10375       IF (l_debug = 1) THEN
10376           print_debug('PROCESS_TXN - Calling MAINTAIN_MO_WRAPPER for this case ',1);
10377           print_debug('PROCESS_TXN - Primary Quantity:'||l_rti_rec.primary_quantity,1);
10378           -- OPMConvergence
10379           print_debug(l_proc_name||'- secondary Quantity:'||l_rti_rec.secondary_quantity,1);
10380           -- OPMConvergence
10381       END IF;
10382 
10383       IF (l_transactions_enabled_flag = 'Y') OR (l_rti_rec.source_document_code = 'PO') THEN --bug9267446
10384 
10385           -- 4398331
10386           -- For ROI Txns with txn type SHIP and auto transact RECEIVE Pass TRANSFER LPN
10387           -- AS LPN ID IF THE TRANSFER LPN ID DOES NOT HAVE ANY VALUE.
10388           -- This needs to be done to satisfy ship and receive in the same LPN.
10389 
10390           IF ( l_rti_rec.transaction_type = 'SHIP'
10391               AND Nvl(l_rti_rec.auto_transact_code, '@#$#$@') = 'RECEIVE' ) THEN
10392 
10393              if l_rti_rec.transfer_lpn_id is null then
10394                 IF (l_debug = 1) THEN
10395                    print_debug('PROCESS_TXN - Resetting transfer lpn id for SHIP and auto transact code Receive',1);
10396                 End if;
10397                 l_rti_rec.transfer_lpn_id := l_rti_rec.lpn_id;
10398              End if;
10399 
10400           END IF;
10401 
10402           maintain_mo_wrapper(p_rti_id => p_txn_id,
10403                   p_primary_quantity => l_rti_rec.primary_quantity,
10404                   p_primary_uom_code => l_primary_uom,
10405                   p_mmtt_temp_id => l_rti_rec.mmtt_temp_id,
10406                   p_org_id => l_rti_rec.to_organization_id,
10407                   p_item_id => l_rti_rec.item_id,
10408                   p_revision => l_rti_rec.item_revision,
10409                   p_qty => l_rti_rec.quantity,
10410                   p_uom_code => l_rti_rec.uom_code,
10411                   p_lpn_id => l_rti_rec.lpn_id,
10412                   p_transfer_lpn_id => l_rti_rec.transfer_lpn_id,
10413                   p_lot_control_code => l_lot_control_code,
10414                   p_serial_number_control_code => l_serial_control_code,
10415                   p_po_line_location_id => l_rti_rec.po_line_location_id,
10416                   p_po_distribution_id => l_rti_rec.po_distribution_id,
10417                   p_shipment_line_id => l_rti_rec.shipment_line_id,
10418                   p_oe_order_line_id => l_rti_rec.oe_order_line_id,
10419                   p_routing_header_id => l_rti_rec.routing_header_id,
10420                   p_subinventory => l_rti_rec.subinventory,
10421                   p_locator_id => l_rti_rec.locator_id,
10422                   p_from_subinventory => l_rti_rec.from_subinventory,
10423                   p_from_locator_id => l_rti_rec.from_locator_id,
10424                   p_project_id => l_rti_rec.project_id,
10425                   p_task_id => l_rti_rec.task_id,
10426                   x_transaction_id => l_rt_transaction_id,
10427                   x_return_status => x_return_status,
10428                   x_msg_count => x_msg_count,
10429                   x_msg_data => x_msg_data,
10430                   -- OPMConvergence
10431                   p_sec_qty => l_rti_rec.secondary_quantity,
10432                   p_sec_uom => l_rti_rec.secondary_uom_code,
10433                   -- OPMConvergence
10434                   p_auto_transact_code => l_rti_rec.auto_transact_code,
10435                   p_asn_line_flag      => l_asn_line_flag,
10436                   p_validation_flag    => l_rti_rec.validation_flag,
10437                   -- Bug# 7154105
10438                   p_req_distribution_id => l_rti_rec.req_distribution_id
10439           );
10440 
10441           IF x_return_status <> G_RET_STS_SUCCESS THEN
10442              --  Review Late Set Appropiate Message
10443              l_progress := 'WMSINB-15321';
10444              RAISE FND_API.G_EXC_ERROR;
10445           END IF;
10446 	 ELSE --IF (l_transactions_enabled_flag = 'Y') THEN
10447           IF (l_debug = 1) THEN
10448              print_debug('PROCESS_TXN - Expense Item. No MOVE ORDERS.',1);
10449           END IF;
10450       END IF; --IF (l_transactions_enabled_flag = 'Y') THEN
10451    END IF; --IF ((l_rti_rec.transaction_type in ('RECEIVE','DELIVER') AND
10452 
10453    IF (l_rti_rec.transaction_type <> 'DELIVER' AND
10454        Nvl(l_rti_rec.auto_transact_code, '@#$#$@') <> 'DELIVER'
10455        AND Nvl(l_parent_txn_type, '@@@@') <> 'DELIVER') THEN
10456       IF (l_debug = 1) THEN
10457           print_debug('PROCESS_TXN - Calling create_lot_serial_history ...',1);
10458           print_debug('PROCESS_TXN - Interface Txn ID:'||l_rti_rec.interface_transaction_id,1);
10459           print_debug('PROCESS_TXN - Txn ID:'||l_rt_transaction_id,1);
10460       END IF;
10461 
10462       create_lot_serial_history(p_prod_txn_tmp_id => l_rti_rec.interface_transaction_id,
10463                p_prod_txn_id => l_rt_transaction_id,
10464                x_return_status => x_return_status,
10465                x_msg_count => x_msg_count,
10466                x_msg_data => x_msg_data);
10467 
10468       IF (x_return_status <> g_ret_sts_success) THEN
10469           l_progress := 'WMSINB-15346';
10470           RAISE fnd_api.g_exc_error;
10471       END IF;
10472 
10473    END IF; --IF (l_rti_rec.transaction_type <> 'DELIVER' AND
10474 
10475    IF (l_debug = 1) THEN
10476       print_debug('PROCESS_TXN - Transaction Status: '||x_return_status,1);
10477      --print_debug('PROCESS_TXN - Transaction processed SUCCESSFULLY... UNBELEIVABLE!!! BELEIVE IT!!!!!',1);
10478    END IF;
10479 
10480 Exception
10481    when others then
10482       x_return_status  := g_ret_sts_unexp_error;
10483       IF (l_debug = 1) THEN
10484           print_debug('PROCESS_TXN : - Exception :'|| l_progress || ' ' ||
10485               TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
10486           print_stacked_messages;
10487       END IF;
10488 
10489       x_msg_data := l_progress;
10490 
10491       IF SQLCODE IS NOT NULL THEN
10492           inv_mobile_helper_functions.sql_error('inv_rcv_integration_pvt.process_txn',l_progress, SQLCODE);
10493       END IF;
10494       -- Get message count and data
10495       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
10496 
10497 END process_txn;
10498 
10499 PROCEDURE insert_msni(p_product_transaction_id   IN NUMBER,
10500                       p_product_code             IN VARCHAR2,
10501                       p_interface_id             IN NUMBER,
10502                       p_item_id                  IN NUMBER,
10503                       p_lot_number               IN VARCHAR2,
10504                       p_fm_serial_number         IN VARCHAR2,
10505                       p_to_serial_number         IN VARCHAR2,
10506                       x_return_status            OUT NOCOPY VARCHAR2,
10507                       x_msg_count                OUT NOCOPY NUMBER,
10508                       x_msg_data                 OUT NOCOPY VARCHAR2
10509 		      ) is
10510 
10511 			 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
10512 
10513 			 l_progress VARCHAR2(15) := '10';
10514 
10515 			 l_msg_count number;
10516 			 l_msg_data VARCHAR2(2000);
10517 
10518 			 l_user_id NUMBER;
10519 			 l_login_id NUMBER;
10520 
10521 BEGIN
10522 
10523    x_return_status := g_ret_sts_success;
10524 
10525    IF (l_debug = 1) THEN
10526       print_debug('Inside INSERT_MSNI', 4);
10527    END IF;
10528 
10529 
10530    l_user_id        := fnd_global.user_id;
10531    l_login_id       := fnd_global.login_id;
10532 
10533    Insert into MTL_SERIAL_NUMBERS_INTERFACE
10534      (
10535       transaction_interface_id,
10536       Source_Code,
10537       Source_Line_Id,
10538       Process_flag, --Is this the same process_flag as above?
10539       Last_Update_Date,
10540       Last_Updated_By,
10541       Creation_Date,
10542       Created_By,
10543       Fm_Serial_Number,
10544       To_Serial_Number,
10545       PRODUCT_CODE,
10546       PRODUCT_TRANSACTION_ID
10547       )
10548      Values
10549      (
10550       p_interface_id,            -- transaction_interface_id
10551       1,                         -- Source_Code,
10552       -1,                        -- Source_Line_Id,
10553       1,                         -- Process_flag,
10554       sysdate,                   -- Last_Update_Date,
10555       l_User_Id,                 -- Last_Updated_By,
10556       sysdate,                   -- Creation_Date,
10557       l_User_Id,                 -- Created_By,
10558       p_fm_Serial_number,        -- from_Serial_Number,
10559       p_to_Serial_number,        -- To_Serial_Number
10560       p_product_code,
10561       p_product_transaction_id
10562       );
10563 
10564    IF (l_debug = 1) THEN
10565       print_debug('INSERT_MSNI Complete without Error', 4);
10566    END IF;
10567 
10568 EXCEPTION
10569    when others then
10570       x_return_status  := g_ret_sts_unexp_error;
10571       IF (l_debug = 1) THEN
10572          print_debug('insert_msni : - other exception:'|| l_progress || ' ' ||
10573 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
10574       END IF;
10575       IF SQLCODE IS NOT NULL THEN
10576 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.insert_msni',l_progress, SQLCODE);
10577       END IF;
10578       --  Get message count and data
10579       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => l_msg_count, p_data => x_msg_data);
10580 
10581 END insert_msni;
10582 
10583 PROCEDURE insert_mtli(p_product_transaction_id  IN NUMBER,
10584                       p_product_code                      IN VARCHAR2,
10585                       p_interface_id                      IN NUMBER,
10586                       p_org_id                            IN NUMBER,
10587                       p_item_id                           IN NUMBER,
10588                       p_lot_number                        IN VARCHAR2,
10589                       p_transaction_quantity              IN NUMBER,
10590                       p_primary_quantity                  IN NUMBER,
10591                       p_serial_interface_id               IN NUMBER,
10592                       x_return_status                     OUT NOCOPY VARCHAR2,
10593                       x_msg_count                         OUT NOCOPY NUMBER,
10594                       x_msg_data                          OUT NOCOPY VARCHAR2,
10595                       p_sec_qty                           IN NUMBER DEFAULT NULL
10596 		      ) is
10597 
10598 			 cursor mln_csr(p_lot_number VARCHAR2, p_item_id  NUMBER, p_org_id in NUMBER ) IS
10599 			    select  mln.inventory_item_id,
10600 			      mln.lot_number, mln.expiration_date, mln.description, mln.vendor_id,mln.vendor_name,
10601 			      mln.supplier_lot_number, mln.territory_code, mln.grade_code, mln.origination_date,
10602 			      mln.date_code, mln.status_id, mln.change_date, mln.age, mln.retest_date, mln.maturity_date,
10603 			      mln.lot_attribute_category, mln.item_size, mln.color, mln.volume, mln.volume_uom,
10604 			      mln.place_of_origin, mln.best_by_date, mln.length, mln.length_uom, mln.recycled_content,
10605 			      mln.thickness, mln.thickness_uom, mln.width, mln.width_uom, mln.curl_wrinkle_fold,
10606 			      mln.c_attribute1, mln.c_Attribute2, mln.c_attribute3, mln.c_attribute4, mln.c_attribute5,
10607 			      mln.c_attribute6, mln.c_attribute7, mln.c_attribute8, mln.c_attribute9, mln.c_attribute10,
10608 			      mln.c_attribute11, mln.c_attribute12, mln.c_attribute13, mln.c_attribute14, mln.c_attribute15,
10609 			      mln.c_attribute16, mln.c_attribute17, mln.c_attribute18, mln.c_attribute19, mln.c_attribute20,
10610 			      mln.d_attribute1, mln.d_attribute2, mln.d_attribute3, mln.d_attribute4, mln.d_attribute5,
10611 			      mln.d_attribute6, mln.d_attribute7, mln.d_attribute8, mln.d_attribute9, mln.d_attribute10,
10612 			      mln.n_attribute1, mln.n_attribute2, mln.n_attribute3, mln.n_attribute4, mln.n_attribute5,
10613 			      mln.n_attribute6, mln.n_attribute7, mln.n_attribute8, mln.n_attribute9, mln.n_attribute10
10614 			      FROM MTL_LOT_NUMBERS MLN
10615 			      WHERE mln.lot_number = Ltrim(Rtrim(p_lot_number))
10616 			      AND mln.organization_id = p_org_id
10617 			      AND mln.inventory_item_id = p_item_id
10618 			      ;
10619 
10620 			 l_mln_rec mln_csr%rowtype;
10621 
10622 			 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
10623 
10624 			 l_progress VARCHAR2(15) := '10';
10625 
10626 			 l_msg_count number;
10627 			 l_msg_data VARCHAR2(2000);
10628 
10629 			 l_user_id NUMBER;
10630 			 l_login_id NUMBER;
10631 
10632 BEGIN
10633 
10634    x_return_status := g_ret_sts_success;
10635 
10636    IF (l_debug = 1) THEN
10637       print_debug('Inside INSERT_MTLI' , 4);
10638    END IF;
10639 
10640 
10641    l_user_id        := fnd_global.user_id;
10642    l_login_id       := fnd_global.login_id;
10643 
10644    open mln_csr(p_lot_number, p_item_id, p_org_id);
10645    Fetch mln_csr into l_mln_rec;
10646    close mln_csr;
10647 
10648    IF (l_debug = 1) THEN
10649       print_debug('p_item_id = '|| p_item_id , 4);
10650       print_debug('p_lot_number = '|| p_lot_number , 4);
10651       print_debug('p_transaction_quantity = '|| p_transaction_quantity , 4);
10652       print_debug('p_primary_quantity = '|| p_primary_quantity , 4);
10653    END IF;
10654 
10655    insert into mtl_transaction_lots_interface (
10656 					       TRANSACTION_INTERFACE_ID,
10657 					       SOURCE_CODE,
10658 					       SOURCE_LINE_ID,
10659 					       LAST_UPDATE_DATE,
10660 					       LAST_UPDATED_BY,
10661 					       CREATION_DATE ,
10662 					       CREATED_BY,
10663 					       LAST_UPDATE_LOGIN,
10664 					       REQUEST_ID,
10665 					       PROGRAM_APPLICATION_ID,
10666 					       PROGRAM_ID,
10667 					       PROGRAM_UPDATE_DATE,
10668 					       LOT_NUMBER,
10669 					       LOT_EXPIRATION_DATE,
10670 					       TRANSACTION_QUANTITY,
10671 					       PRIMARY_QUANTITY,
10672 					       SERIAL_TRANSACTION_TEMP_ID,
10673 					       ERROR_CODE,
10674 					       PROCESS_FLAG,
10675 					       DESCRIPTION,
10676 					       VENDOR_NAME,
10677 					       SUPPLIER_LOT_NUMBER,
10678 					       ORIGINATION_DATE,
10679 					       DATE_CODE,
10680 					       GRADE_CODE,
10681 					       CHANGE_DATE,
10682 					       MATURITY_DATE,
10683 					       STATUS_ID,
10684 					       RETEST_DATE,
10685 					       AGE,
10686 					       ITEM_SIZE,
10687 					       COLOR,
10688 					       VOLUME,
10689 					       VOLUME_UOM,
10690 					       PLACE_OF_ORIGIN,
10691 					       BEST_BY_DATE,
10692 					       LENGTH,
10693      LENGTH_UOM,
10694      RECYCLED_CONTENT,
10695      THICKNESS,
10696      THICKNESS_UOM,
10697      WIDTH,
10698      WIDTH_UOM,
10699      CURL_WRINKLE_FOLD,
10700      LOT_ATTRIBUTE_CATEGORY,
10701      C_ATTRIBUTE1,
10702      C_ATTRIBUTE2,
10703      C_ATTRIBUTE3,
10704      C_ATTRIBUTE4,
10705      C_ATTRIBUTE5,
10706      C_ATTRIBUTE6,
10707      C_ATTRIBUTE7,
10708      C_ATTRIBUTE8,
10709      C_ATTRIBUTE9,
10710      C_ATTRIBUTE10,
10711      C_ATTRIBUTE11,
10712      C_ATTRIBUTE12,
10713      C_ATTRIBUTE13,
10714      C_ATTRIBUTE14,
10715      C_ATTRIBUTE15,
10716      C_ATTRIBUTE16,
10717      C_ATTRIBUTE17,
10718      C_ATTRIBUTE18,
10719      C_ATTRIBUTE19,
10720      C_ATTRIBUTE20,
10721      D_ATTRIBUTE1,
10722      D_ATTRIBUTE2,
10723      D_ATTRIBUTE3,
10724      D_ATTRIBUTE4,
10725      D_ATTRIBUTE5,
10726      D_ATTRIBUTE6,
10727      D_ATTRIBUTE7,
10728      D_ATTRIBUTE8,
10729      D_ATTRIBUTE9,
10730      D_ATTRIBUTE10,
10731      N_ATTRIBUTE1,
10732      N_ATTRIBUTE2,
10733      N_ATTRIBUTE3,
10734      N_ATTRIBUTE4,
10735      N_ATTRIBUTE5,
10736      N_ATTRIBUTE6,
10737      N_ATTRIBUTE7,
10738      N_ATTRIBUTE8,
10739      N_ATTRIBUTE9,
10740      N_ATTRIBUTE10,
10741      VENDOR_ID,
10742      TERRITORY_CODE,
10743      PRODUCT_CODE,
10744      PRODUCT_TRANSACTION_ID,
10745      SECONDARY_TRANSACTION_QUANTITY
10746      ) values
10747      (
10748       p_interface_id,
10749       1,
10750       -1,
10751       sysdate,
10752       l_user_id,
10753       sysdate,
10754       l_user_id,
10755       l_login_id,
10756       null, -- REQUEST_ID
10757       null, -- PROGRAM_APPLICATION_ID
10758       null, -- PROGRAM_ID
10759       null, -- PROGRAM_UPDATE_DATE
10760       Ltrim(Rtrim(p_lot_number)),
10761       l_mln_rec.EXPIRATION_DATE,
10762       P_TRANSACTION_QUANTITY,
10763       P_PRIMARY_QUANTITY,
10764       P_serial_interface_id, -- serial_transaction_temp_id
10765       null, -- ERROR_CODE
10766       null, -- PROCESS_FLAG,
10767       l_mln_rec.DESCRIPTION,
10768       l_mln_rec.VENDOR_NAME,
10769       l_mln_rec.SUPPLIER_LOT_NUMBER,
10770       l_mln_rec.ORIGINATION_DATE,
10771       l_mln_rec.DATE_CODE,
10772       l_mln_rec.GRADE_CODE ,
10773       l_mln_rec.CHANGE_DATE,
10774       l_mln_rec.MATURITY_DATE,
10775       l_mln_rec.STATUS_ID,
10776       l_mln_rec.RETEST_DATE,
10777       l_mln_rec.AGE,
10778       l_mln_rec.ITEM_SIZE,
10779       l_mln_rec.COLOR,
10780       l_mln_rec.VOLUME,
10781       l_mln_rec.VOLUME_UOM,
10782       l_mln_rec.PLACE_OF_ORIGIN,
10783       l_mln_rec.BEST_BY_DATE,
10784       l_mln_rec.LENGTH,
10785      l_mln_rec.LENGTH_UOM,
10786      l_mln_rec.RECYCLED_CONTENT,
10787      l_mln_rec.THICKNESS,
10788      l_mln_rec.THICKNESS_UOM,
10789      l_mln_rec.WIDTH,
10790      l_mln_rec.WIDTH_UOM,
10791      l_mln_rec.CURL_WRINKLE_FOLD,
10792      l_mln_rec.LOT_ATTRIBUTE_CATEGORY,
10793      l_mln_rec.C_ATTRIBUTE1,
10794      l_mln_rec.C_ATTRIBUTE2,
10795      l_mln_rec.C_ATTRIBUTE3,
10796      l_mln_rec.C_ATTRIBUTE4,
10797      l_mln_rec.C_ATTRIBUTE5,
10798      l_mln_rec.C_ATTRIBUTE6,
10799      l_mln_rec.C_ATTRIBUTE7,
10800      l_mln_rec.C_ATTRIBUTE8,
10801      l_mln_rec.C_ATTRIBUTE9,
10802      l_mln_rec.C_ATTRIBUTE10,
10803      l_mln_rec.C_ATTRIBUTE11,
10804      l_mln_rec.C_ATTRIBUTE12,
10805      l_mln_rec.C_ATTRIBUTE13,
10806      l_mln_rec.C_ATTRIBUTE14,
10807      l_mln_rec.C_ATTRIBUTE15,
10808      l_mln_rec.C_ATTRIBUTE16,
10809      l_mln_rec.C_ATTRIBUTE17,
10810      l_mln_rec.C_ATTRIBUTE18,
10811      l_mln_rec.C_ATTRIBUTE19,
10812      l_mln_rec.C_ATTRIBUTE20,
10813      l_mln_rec.D_ATTRIBUTE1 ,
10814      l_mln_rec.D_ATTRIBUTE2,
10815      l_mln_rec.D_ATTRIBUTE3,
10816      l_mln_rec.D_ATTRIBUTE4,
10817      l_mln_rec.D_ATTRIBUTE5,
10818      l_mln_rec.D_ATTRIBUTE6,
10819      l_mln_rec.D_ATTRIBUTE7,
10820      l_mln_rec.D_ATTRIBUTE8,
10821      l_mln_rec.D_ATTRIBUTE9,
10822      l_mln_rec.D_ATTRIBUTE10,
10823      l_mln_rec.N_ATTRIBUTE1,
10824      l_mln_rec.N_ATTRIBUTE2,
10825      l_mln_rec.N_ATTRIBUTE3,
10826      l_mln_rec.N_ATTRIBUTE4,
10827      l_mln_rec.N_ATTRIBUTE5,
10828      l_mln_rec.N_ATTRIBUTE6,
10829      l_mln_rec.N_ATTRIBUTE7,
10830      l_mln_rec.N_ATTRIBUTE8,
10831      l_mln_rec.N_ATTRIBUTE9,
10832      l_mln_rec.N_ATTRIBUTE10,
10833      l_mln_rec.VENDOR_ID,
10834      l_mln_rec.TERRITORY_CODE,
10835      p_PRODUCT_CODE,
10836      p_PRODUCT_TRANSACTION_ID,
10837      p_sec_qty
10838      );
10839 
10840    IF (l_debug = 1) THEN
10841       print_debug('INSERT_MTLI  Commplete without Error ' , 4);
10842    END IF;
10843 
10844 EXCEPTION
10845    when others then
10846       x_return_status  := g_ret_sts_unexp_error;
10847       IF (l_debug = 1) THEN
10848          print_debug('insert_mtli : - other exception:'|| l_progress || ' ' ||
10849 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
10850       END IF;
10851       IF SQLCODE IS NOT NULL THEN
10852 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.insert_mtli',l_progress, SQLCODE);
10853       END IF;
10854       --  Get message count and data
10855       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => l_msg_count, p_data => x_msg_data);
10856 
10857 END insert_mtli;
10858 
10859 -- Description
10860 -- This API creates RTI rows for LPN contents
10861 --
10862 PROCEDURE create_rti_for_lpn(p_transaction_type         IN        VARCHAR2,
10863 			     p_interface_transaction_id IN        NUMBER,
10864                              p_lpn_id                   IN        NUMBER,
10865                              p_item_id                  IN        NUMBER,
10866                              p_org_id                   IN        NUMBER,
10867                              p_to_org_id                IN        NUMBER,
10868                              p_item_desc                IN        VARCHAR2 default null,
10869                              p_item_revision            IN        VARCHAR2 default null,
10870                              p_quantity                 IN        NUMBER,
10871                              p_txn_uom_code             IN        VARCHAR2,
10872                              p_transfer_lpn_id          IN        NUMBER default null,
10873                              p_transfer_lpn             IN        VARCHAR2 default null,
10874                              p_txn_source_id            IN        NUMBER default NULL,
10875                              p_mmtt_temp_id             IN        NUMBER default NULL,
10876   p_project_id               IN         NUMBER DEFAULT NULL,
10877   p_task_id                  IN         NUMBER DEFAULT NULL,
10878   x_interface_transaction_id OUT NOCOPY NUMBER,
10879   x_return_status            OUT NOCOPY VARCHAR2,
10880   x_msg_count                OUT NOCOPY NUMBER,
10881   x_msg_data                 OUT NOCOPY VARCHAR2)
10882   is
10883      l_interface_transaction_id NUMBER;
10884 
10885      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
10886      l_progress VARCHAR2(15) := '10';
10887      l_msg_count number;
10888      l_msg_data VARCHAR2(2000);
10889 
10890 
10891      l_user_id NUMBER;
10892      l_login_id NUMBER;
10893 
10894      l_sysdate DATE := SYSDATE;
10895      l_rti_rowid VARCHAR2 (40);
10896      l_group_id NUMBER;
10897      l_transaction_type VARCHAR2(100);
10898      l_transaction_mode VARCHAR2(100);
10899      l_employee_id NUMBER;
10900      l_auto_transact_code VARCHAR2 ( 30 );
10901      l_shipment_header_id NUMBER;
10902      l_shipment_line_id NUMBER;
10903      l_source_type_code VARCHAR2(30);
10904      l_vendor_id NUMBER;
10905      l_vendor_site_id NUMBER;
10906 
10907      l_primary_uom VARCHAR2(3);
10908      l_primary_unit_of_measure VARCHAR2(30);
10909      l_lot_control_code NUMBER;
10910      l_serial_control_code NUMBER;
10911      l_unit_of_measure VARCHAR2(30);
10912      l_primary_qty  NUMBER;
10913      l_primary_lot_qty  NUMBER;
10914 
10915      l_lot_interface_id NUMBER;
10916      l_serial_interface_id NUMBER;
10917 
10918      l_serial_interface_inserted BOOLEAN;
10919 
10920      l_source_document_code VARCHAR2(25);
10921      l_receipt_source_code VARCHAR2(25);
10922 
10923      l_num_serial_inserted NUMBER;
10924 
10925      --< R12 MOAC>
10926      l_po_header_id       RCV_TRANSACTIONS.PO_HEADER_ID%TYPE;
10927      l_req_line_id        RCV_TRANSACTIONS.REQUISITION_LINE_ID%TYPE;
10928      l_oe_order_header_id RCV_TRANSACTIONS.OE_ORDER_HEADER_ID%TYPE;
10929      l_operating_unit_id  MO_GLOB_ORG_ACCESS_TMP.ORGANIZATION_ID%TYPE;
10930 
10931 
10932 BEGIN
10933 
10934    x_return_status := g_ret_sts_success;
10935 
10936    l_progress := 'WMSINB-15799';
10937 
10938    -- Get the New Interface ID
10939    --
10940    SELECT primary_uom_code,
10941      primary_unit_of_measure,
10942      lot_control_code,
10943      serial_number_control_code
10944      INTO  l_primary_uom,
10945      l_primary_unit_of_measure,
10946      l_lot_control_code,
10947      l_serial_control_code
10948      FROM mtl_system_items
10949      WHERE inventory_item_id = p_item_id
10950      AND organization_id = p_to_org_id;
10951 
10952    l_progress := 'WMSINB-15816';
10953 
10954    SELECT unit_of_measure
10955      into l_unit_of_measure
10956      FROM mtl_item_uoms_view
10957      WHERE organization_id = p_to_org_id
10958      AND inventory_item_id = p_item_id
10959      AND uom_code = p_txn_uom_code;
10960 
10961    l_progress := 'WMSINB-15825';
10962 
10963    IF (l_debug = 1) THEN
10964       print_debug('create_rti_for_lpn:p_item_id = '|| p_item_id , 4);
10965       print_debug('create_rti_for_lpn:l_primary_uom = '|| l_primary_uom , 4);
10966       print_debug('create_rti_for_lpn:l_primary_unit_of_measure = '|| l_primary_unit_of_measure , 4);
10967       print_debug('create_rti_for_lpn:l_unit_of_measure = '|| l_unit_of_measure , 4);
10968       print_debug('create_rti_for_lpn:p_txn_uom_code = '|| p_txn_uom_code , 4);
10969       print_debug('create_rti_for_lpn:p_txn_source_id = '|| p_txn_source_id , 4);
10970       print_debug('create_rti_for_lpn:p_mmtt_temp_id = '|| p_mmtt_temp_id , 4);
10971    END IF;
10972 
10973    IF (p_txn_uom_code <> l_primary_uom) THEN
10974       l_primary_qty :=  inv_rcv_cache.convert_qty(p_inventory_item_id => p_item_id
10975 				    ,p_from_qty         => p_quantity
10976 				    ,p_from_uom_code    => p_txn_uom_code
10977 				    ,p_to_uom_code      => l_primary_uom
10978 				    );
10979     ELSE
10980       l_primary_qty := p_quantity;
10981    END IF;
10982 
10983    IF (l_debug = 1) THEN
10984       print_debug('create_rti_for_lpn:Quantity = '|| p_quantity , 4);
10985       print_debug('create_rti_for_lpn:Primary Qty = '|| l_primary_qty , 4);
10986    END IF;
10987 
10988    l_progress := 'WMSINB-15850';
10989 
10990    SELECT rcv_transactions_interface_s.NEXTVAL
10991      INTO   l_interface_transaction_id
10992      FROM   DUAL;
10993 
10994    l_progress := 'WMSINB-15856';
10995 
10996    l_user_id        := fnd_global.user_id;
10997    l_login_id       := fnd_global.login_id;
10998 
10999    l_progress := 'WMSINB-15861';
11000 
11001    --get the receipt_source_code and source_document_code
11002    IF (p_txn_source_id IS NOT NULL) THEN
11003 
11004       /* R12 MOAC : Fetch the po_header_id, requisition_line_id, oe_order_header_id from
11005       **            rcv_transactions and derive the operating unit id
11006       */
11007 
11008       BEGIN
11009 	 SELECT rt.source_document_code
11010 	   , rsh.receipt_source_code
11011            , rt.po_header_id
11012            , rt.requisition_line_id
11013            , rt.oe_order_header_id
11014 	   INTO l_source_document_code
11015 	   , l_receipt_source_code
11016            , l_po_header_id
11017            , l_req_line_id
11018            , l_oe_order_header_id
11019 	   FROM rcv_transactions rt
11020 	   , rcv_shipment_headers rsh
11021 	   WHERE rt.transaction_id = p_txn_source_id
11022 	   AND rt.shipment_header_id = rsh.shipment_header_id
11023 	   AND rt.organization_id = p_to_org_id
11024 	   AND exists (SELECT '1' FROM rcv_shipment_lines rsl
11025 		       WHERE rsl.shipment_header_id = rsh.shipment_header_id
11026 		       AND rt.organization_id = rsl.to_organization_id);
11027       EXCEPTION
11028 	 WHEN no_data_found THEN
11029 	    --raise an error
11030 	    --review later
11031 	    l_progress := 'WMSINB-15882';
11032 	    RAISE fnd_api.g_exc_error;
11033       END;
11034 
11035       --<R12 MOAC>
11036       l_operating_unit_id := inv_rcv_common_apis.get_operating_unit_id(
11037                                           l_receipt_source_code,
11038                                           l_po_header_id,
11039                                           l_req_line_id,
11040                                           l_oe_order_header_id);
11041 
11042     ELSE --IF (p_txn_source_id IS NOT NULL) THEN
11043       BEGIN
11044 
11045 	--following is as per perfomance fix 8113852 / bug 3631289
11046 
11047 	 SELECT rsh.receipt_source_code,
11048 	   Decode(rsh.receipt_source_code,'INTERNAL
11049 		  ORDER','REQ','INVENTORY','INVENTORY','VENDOR','PO','CUSTOMER','RMA')
11050 		  INTO l_receipt_source_code
11051 		  , l_source_document_code
11052 	  FROM rcv_shipment_headers rsh, wms_license_plate_numbers wlpn
11053 	WHERE RSH.SHIPMENT_HEADER_ID = WLPN.SOURCE_HEADER_ID
11054         	AND WLPN.SOURCE_HEADER_ID IS NOT NULL
11055         	AND wlpn.lpn_id = p_lpn_id
11056         	AND exists (SELECT '1' FROM rcv_shipment_lines rsl
11057                         WHERE rsl.shipment_header_id = rsh.shipment_header_id
11058                         AND wlpn.organization_id = rsl.to_organization_id);
11059 	 EXCEPTION
11060 	      WHEN NO_DATA_FOUND THEN
11061                 BEGIN
11062 		  SELECT rsh.receipt_source_code,
11063 		  Decode(rsh.receipt_source_code,'INTERNAL
11064 			 ORDER','REQ','INVENTORY','INVENTORY','VENDOR','PO','CUSTOMER','RMA')
11065 			 INTO l_receipt_source_code
11066 			 , l_source_document_code
11067 	                FROM rcv_shipment_headers rsh, wms_license_plate_numbers wlpn
11068 			WHERE RSH.SHIPMENT_NUM = WLPN.SOURCE_NAME
11069 	                        AND WLPN.SOURCE_NAME IS NOT NULL
11070 	                        AND wlpn.lpn_id = p_lpn_id
11071 	                        AND exists (SELECT '1' FROM rcv_shipment_lines rsl
11072                                    WHERE rsl.shipment_header_id = rsh.shipment_header_id
11073                                         AND wlpn.organization_id = rsl.to_organization_id);
11074 
11075      	--Two exception blocks as such necessary?
11076 	EXCEPTION
11077 		 WHEN no_data_found THEN
11078 	   	 --raise an error
11079 	    	--review later
11080 	    	l_progress := 'WMSINB-15904';
11081 	    RAISE fnd_api.g_exc_error;
11082 	    END;
11083 	END;
11084    END IF; --IF (p_txn_source_id IS NOT NULL) THEN
11085 
11086    IF (l_debug = 1) THEN
11087       print_debug('create_rti_for_lpn:SOURCE_DOCUMENT_CODE:'||l_source_document_code,1);
11088       print_debug('create_rti_for_lpn:RECEIPT_SOURCE_CODE:'||l_receipt_source_code,1);
11089    END IF;
11090 
11091    l_progress := 'WMSINB-15914';
11092 
11093    -- Fetch the original RTI row
11094    For l_rcv_transaction_rec in (
11095 				 select group_id                       ,
11096 				 lpn_group_id                   ,
11097 				 transaction_type               ,
11098 				 processing_mode_code           ,
11099 				 processing_request_id          ,
11100 				 item_category                  ,
11101 				 quantity                       ,
11102 				 unit_of_measure                ,
11103 				 uom_code                       ,
11104 				 employee_id                    ,
11105 				 auto_transact_code             ,
11106 				 shipment_header_id             ,
11107 				 shipment_line_id               ,
11108 				 ship_to_location_id            ,
11109 				 primary_quantity               ,
11110 				 primary_unit_of_measure        ,
11111 				 receipt_source_code            ,
11112 				 vendor_id                      ,
11113 				 vendor_site_id                 ,
11114 				 from_Organization_Id           ,
11115 				 to_Organization_Id           ,
11116 				 Routing_Header_Id              ,
11117 				 Routing_Step_Id                ,
11118 				 Source_Document_Code           ,
11119 				 Parent_Transaction_Id          ,
11120 				 Po_Header_Id                   ,
11121      Po_Revision_Num                ,
11122      Po_Release_Id                  ,
11123      Po_Line_Id                     ,
11124      Po_Line_Location_Id            ,
11125      Po_Unit_Price                  ,
11126      Currency_Code                  ,
11127      Currency_Conversion_Type       ,
11128      Currency_Conversion_Rate       ,
11129      Currency_Conversion_Date       ,
11130      Po_Distribution_Id             ,
11131      Requisition_Line_Id            ,
11132      Req_Distribution_Id            ,
11133      Charge_Account_Id              ,
11134      Substitute_Unordered_Code      ,
11135      Receipt_Exception_Flag         ,
11136      Accrual_Status_Code            ,
11137      Inspection_Status_Code         ,
11138      Inspection_Quality_Code        ,
11139      Destination_Type_Code          ,
11140      Deliver_To_Person_Id           ,
11141      Location_Id                    ,
11142      Deliver_To_Location_Id         ,
11143      Subinventory                   ,
11144      Locator_Id                     ,
11145      Wip_Entity_Id                  ,
11146      Wip_Line_Id                    ,
11147      Department_Code                ,
11148      Wip_Repetitive_Schedule_Id     ,
11149      Wip_Operation_Seq_Num          ,
11150      Wip_Resource_Seq_Num           ,
11151      Bom_Resource_Id                ,
11152      Shipment_Num                   ,
11153      Freight_Carrier_Code           ,
11154      Bill_Of_Lading                 ,
11155      Packing_Slip                   ,
11156      Shipped_Date                   ,
11157      Expected_Receipt_Date          ,
11158      Actual_Cost                    ,
11159      Transfer_Cost                  ,
11160      Transportation_Cost            ,
11161      Transportation_Account_Id      ,
11162      Num_Of_Containers              ,
11163      Waybill_Airbill_Num            ,
11164      Vendor_Item_Num                ,
11165      Vendor_Lot_Num                 ,
11166      Rma_Reference                  ,
11167      Comments                       ,
11168      Attribute_Category             ,
11169      Attribute1                     ,
11170      Attribute2                     ,
11171      Attribute3                     ,
11172      Attribute4                     ,
11173      Attribute5                     ,
11174      Attribute6                     ,
11175      Attribute7                     ,
11176      Attribute8                     ,
11177      Attribute9                     ,
11178      Attribute10                    ,
11179      Attribute11                    ,
11180      Attribute12                    ,
11181      Attribute13                    ,
11182      Attribute14                    ,
11183      Attribute15                    ,
11184      Ship_Head_Attribute_Category   ,
11185      Ship_Head_Attribute1           ,
11186      Ship_Head_Attribute2           ,
11187      Ship_Head_Attribute3           ,
11188      Ship_Head_Attribute4           ,
11189      Ship_Head_Attribute5           ,
11190      Ship_Head_Attribute6           ,
11191      Ship_Head_Attribute7           ,
11192      Ship_Head_Attribute8           ,
11193      Ship_Head_Attribute9           ,
11194      Ship_Head_Attribute10          ,
11195      Ship_Head_Attribute11          ,
11196      Ship_Head_Attribute12          ,
11197      Ship_Head_Attribute13          ,
11198      Ship_Head_Attribute14          ,
11199      Ship_Head_Attribute15          ,
11200      Ship_Line_Attribute_Category   ,
11201      Ship_Line_Attribute1           ,
11202      Ship_Line_Attribute2           ,
11203      Ship_Line_Attribute3           ,
11204      Ship_Line_Attribute4           ,
11205      Ship_Line_Attribute5           ,
11206      Ship_Line_Attribute6           ,
11207      Ship_Line_Attribute7           ,
11208      Ship_Line_Attribute8           ,
11209      Ship_Line_Attribute9           ,
11210      Ship_Line_Attribute10          ,
11211      Ship_Line_Attribute11          ,
11212      Ship_Line_Attribute12          ,
11213      Ship_Line_Attribute13          ,
11214      Ship_Line_Attribute14          ,
11215      Ship_Line_Attribute15          ,
11216      Ussgl_Transaction_Code         ,
11217      Government_Context             ,
11218      Reason_Id                      ,
11219      Destination_Context            ,
11220      Source_Doc_Quantity            ,
11221      Source_Doc_Unit_Of_Measure     ,
11222      use_mtl_lot                  ,
11223      use_mtl_serial               ,
11224      QA_Collection_Id               ,
11225      Country_of_Origin_Code         ,
11226      oe_order_header_id             ,
11227      oe_order_line_id               ,
11228      customer_item_num              ,
11229      customer_id                    ,
11230      customer_site_id               ,
11231      put_away_rule_id               ,
11232      put_away_strategy_id           ,
11233      lpn_id                         ,
11234      transfer_lpn_id                ,
11235      license_plate_number           ,
11236      transfer_license_plate_number  ,
11237      cost_group_id                  ,
11238      mmtt_temp_id                   ,
11239      mobile_txn                     ,
11240      transfer_cost_group_id         ,
11241      secondary_quantity             ,
11242      secondary_unit_of_measure      ,
11243      org_id                          --<R12 MOAC>
11244      from  rcv_transactions_interface rti
11245      where rti.interface_transaction_id = p_interface_transaction_id )
11246      Loop
11247 	-- Insert the row
11248 	IF (l_debug = 1) THEN
11249 	   print_debug('create_rti_from_lpn : - Before Inserting into RTI' , 1);
11250 	END IF;
11251 
11252 
11253 	-- Needs to be reviewed Later
11254 	-- Fetch Details from parent if necessary for Transfer and Deliver Txn
11255 	--
11256 	--
11257 	--   shipment_line_id
11258 	--    shipment_header_id
11259 	--   oe_order_header_id             ,
11260 	--    oe_order_line_id               ,
11261 	--    Wip_Entity_Id                  ,
11262 	--   Wip_Line_Id                    ,
11263 	--   Department_Code                ,
11264 	--   Wip_Repetitive_Schedule_Id     ,
11265 	--   Wip_Operation_Seq_Num          ,
11266 	--   Wip_Resource_Seq_Num           ,
11267 	--   Po_Header_Id                   ,
11268 	--   Po_Revision_Num                ,
11269 	--   Po_Release_Id                  ,
11270 	--   Po_Line_Id                     ,
11271 	--   Po_Line_Location_Id            ,
11272 	--   Po_Unit_Price                  ,
11273 	--   Po_Distribution_Id             ,
11274 	--  Requisition_Line_Id            ,
11275 	--  Req_Distribution_Id            ,
11276 	--
11277 	--
11278 
11279         l_progress := 'WMSINB-16101';
11280 
11281 	rcv_trx_interface_insert_pkg.insert_row ( l_rti_rowid,
11282 						  l_interface_transaction_id,
11283 						  l_rcv_transaction_rec.group_id,
11284 						  l_sysdate,
11285 						  l_user_id,
11286 						  l_sysdate,            /* Created Date */
11287 						  l_user_id,            /* Created By */
11288 						  l_login_id,           /* last Update Login */
11289 						  l_rcv_transaction_rec.transaction_type,   /* transaction type */
11290 						  l_sysdate ,  /* transaction date */
11291 						  'RUNNING',            /* Processing status code */
11292 						  l_rcv_transaction_rec.processing_mode_code,
11293 						  /* Processing Request id Debug: Not sure how this is used */
11294 						  l_rcv_transaction_rec.processing_request_id ,
11295 						  'PENDING',            /* Transaction status code */
11296 						  NULL,                 /* item_category */
11297 						  p_quantity,
11298 						  l_unit_of_measure,                  /* unit_of_measure */
11299 						  'RCV',                /* interface source code */
11300 						  NULL,                 /* interface source line id */
11301 						  NULL,                 /* inv_transaction id */
11302 	  p_item_id,
11303 	  p_item_desc,
11304 	  p_item_revision,
11305 	  p_txn_uom_code,       /* uom code */
11306 	  l_rcv_transaction_rec.employee_id,
11307 	  l_rcv_transaction_rec.auto_transact_code, /* Auto transact code */
11308 	  l_rcv_transaction_rec.shipment_header_id, /* shipment header id */
11309 	  l_rcv_transaction_rec.shipment_line_id,   /* shipment line id */
11310 	  l_rcv_transaction_rec.ship_to_location_id,
11311 	  l_primary_qty, /* primary quantity */
11312 	  l_primary_unit_of_measure, /* primary uom */
11313 	  l_receipt_source_code, /* receipt source code */
11314 	  l_rcv_transaction_rec.vendor_id,
11315 	  l_rcv_transaction_rec.vendor_site_id,
11316 	  l_rcv_transaction_rec.from_organization_id,   /* from org id */
11317 	  l_rcv_transaction_rec.to_organization_id,       /* to org id */
11318 	  l_rcv_transaction_rec.routing_header_id,
11319 	  l_rcv_transaction_rec.routing_step_id,           /* routing step id */
11320 	  l_source_document_code, /* source document code */
11321 	  nvl(p_txn_source_id,-1) , /* Parent trx id */
11322 	  l_rcv_transaction_rec.po_header_id,
11323 	  NULL,     /* PO Revision number */
11324 	  l_rcv_transaction_rec.po_release_id,
11325 	  l_rcv_transaction_rec.po_line_id,
11326 	  l_rcv_transaction_rec.po_line_location_id,
11327 	  l_rcv_transaction_rec.po_unit_price,
11328 	  l_rcv_transaction_rec.currency_code, /* Currency_Code */
11329 	  l_rcv_transaction_rec.currency_conversion_type,
11330 	  l_rcv_transaction_rec.currency_conversion_rate,
11331 	  l_rcv_transaction_rec.currency_conversion_date,
11332 	  l_rcv_transaction_rec.po_distribution_id,
11333 	  l_rcv_transaction_rec.Requisition_Line_Id,
11334 	  l_rcv_transaction_rec.req_distribution_id,
11335 	  l_rcv_transaction_rec.charge_account_id,   /* Charge_Account_Id */
11336 	  l_rcv_transaction_rec.substitute_unordered_code, /* Substitute_Unordered_Code */
11337 	  l_rcv_transaction_rec.receipt_exception_flag, /* Receipt_Exception_Flag  forms check box?*/
11338 	  l_rcv_transaction_rec.Accrual_Status_Code,    /* Accrual_Status_Code */
11339 	  l_rcv_transaction_rec.Inspection_Status_Code, /* Inspection_Status_Code */
11340 	  l_rcv_transaction_rec.Inspection_Quality_Code, /* Inspection_Quality_Code */
11341 	  l_rcv_transaction_rec.destination_type_code, /* Destination_Type_Code */
11342 	  l_rcv_transaction_rec.deliver_to_person_id, /* Deliver_To_Person_Id */
11343 	  l_rcv_transaction_rec.location_id,   /* Location_Id */
11344 	  l_rcv_transaction_rec.deliver_to_location_id, /* Deliver_To_Location_Id */
11345 	  l_rcv_transaction_rec.subinventory, /* Subinventory */
11346 	  l_rcv_transaction_rec.locator_id,     /* Locator_Id */
11347 	  l_rcv_transaction_rec.wip_entity_id, /* Wip_Entity_Id */
11348 	  l_rcv_transaction_rec.wip_line_id,   /* Wip_Line_Id */
11349 	  l_rcv_transaction_rec.department_code, /* Department_Code */
11350 	  l_rcv_transaction_rec.Wip_Repetitive_Schedule_Id, /* Wip_Repetitive_Schedule_Id */
11351 	  l_rcv_transaction_rec.Wip_Operation_Seq_Num, /* Wip_Operation_Seq_Num */
11352 	  l_rcv_transaction_rec.Wip_Resource_Seq_Num,
11353 	  l_rcv_transaction_rec.Bom_Resource_Id                ,
11354 	  l_rcv_transaction_rec.Shipment_Num                   ,
11355 	  l_rcv_transaction_rec.Freight_Carrier_Code           ,
11356 	  l_rcv_transaction_rec.Bill_Of_Lading                 ,
11357 	  l_rcv_transaction_rec.Packing_Slip                   ,
11358 	  l_rcv_transaction_rec.Shipped_Date                   ,
11359 	  l_rcv_transaction_rec.Expected_Receipt_Date          ,
11360 	  l_rcv_transaction_rec.Actual_Cost                    ,
11361 	  l_rcv_transaction_rec.Transfer_Cost                  ,
11362 	  l_rcv_transaction_rec.Transportation_Cost            ,
11363 	  l_rcv_transaction_rec.Transportation_Account_Id      ,
11364 	  l_rcv_transaction_rec.Num_Of_Containers              ,
11365 	  l_rcv_transaction_rec.Waybill_Airbill_Num            ,
11366 	  l_rcv_transaction_rec.Vendor_Item_Num                ,
11367 	  l_rcv_transaction_rec.Vendor_Lot_Num                 ,
11368 	  l_rcv_transaction_rec.Rma_Reference                  ,
11369 	  l_rcv_transaction_rec.Comments                       ,
11370 	  l_rcv_transaction_rec.Attribute_Category             ,
11371 	  l_rcv_transaction_rec.Attribute1                     ,
11372 	  l_rcv_transaction_rec.Attribute2                     ,
11373 	  l_rcv_transaction_rec.Attribute3                     ,
11374 	  l_rcv_transaction_rec.Attribute4                     ,
11375 	  l_rcv_transaction_rec.Attribute5                     ,
11376 	  l_rcv_transaction_rec.Attribute6                     ,
11377 	  l_rcv_transaction_rec.Attribute7                     ,
11378 	  l_rcv_transaction_rec.Attribute8                     ,
11379 	  l_rcv_transaction_rec.Attribute9                     ,
11380 	  l_rcv_transaction_rec.Attribute10                    ,
11381 	  l_rcv_transaction_rec.Attribute11                    ,
11382 	  l_rcv_transaction_rec.Attribute12                    ,
11383 	  l_rcv_transaction_rec.Attribute13                    ,
11384 	  l_rcv_transaction_rec.Attribute14                    ,
11385 	  l_rcv_transaction_rec.Attribute15                    ,
11386 	  l_rcv_transaction_rec.Ship_Head_Attribute_Category   ,
11387 	  l_rcv_transaction_rec.Ship_Head_Attribute1           ,
11388 	  l_rcv_transaction_rec.Ship_Head_Attribute2           ,
11389 	  l_rcv_transaction_rec.Ship_Head_Attribute3           ,
11390 	  l_rcv_transaction_rec.Ship_Head_Attribute4           ,
11391 	  l_rcv_transaction_rec.Ship_Head_Attribute5           ,
11392 	  l_rcv_transaction_rec.Ship_Head_Attribute6           ,
11393 	  l_rcv_transaction_rec.Ship_Head_Attribute7           ,
11394 	  l_rcv_transaction_rec.Ship_Head_Attribute8           ,
11395 	  l_rcv_transaction_rec.Ship_Head_Attribute9           ,
11396 	  l_rcv_transaction_rec.Ship_Head_Attribute10          ,
11397 	  l_rcv_transaction_rec.Ship_Head_Attribute11          ,
11398 	  l_rcv_transaction_rec.Ship_Head_Attribute12          ,
11399 	  l_rcv_transaction_rec.Ship_Head_Attribute13          ,
11400 	  l_rcv_transaction_rec.Ship_Head_Attribute14          ,
11401 	  l_rcv_transaction_rec.Ship_Head_Attribute15          ,
11402 	  l_rcv_transaction_rec.Ship_Line_Attribute_Category   ,
11403 	  l_rcv_transaction_rec.Ship_Line_Attribute1           ,
11404 	  l_rcv_transaction_rec.Ship_Line_Attribute2           ,
11405 	  l_rcv_transaction_rec.Ship_Line_Attribute3           ,
11406 	  l_rcv_transaction_rec.Ship_Line_Attribute4           ,
11407 	  l_rcv_transaction_rec.Ship_Line_Attribute5           ,
11408 	  l_rcv_transaction_rec.Ship_Line_Attribute6           ,
11409 	  l_rcv_transaction_rec.Ship_Line_Attribute7           ,
11410 	  l_rcv_transaction_rec.Ship_Line_Attribute8           ,
11411 	  l_rcv_transaction_rec.Ship_Line_Attribute9           ,
11412 	  l_rcv_transaction_rec.Ship_Line_Attribute10          ,
11413 	  l_rcv_transaction_rec.Ship_Line_Attribute11          ,
11414 	  l_rcv_transaction_rec.Ship_Line_Attribute12          ,
11415 	  l_rcv_transaction_rec.Ship_Line_Attribute13          ,
11416 	  l_rcv_transaction_rec.Ship_Line_Attribute14          ,
11417 	  l_rcv_transaction_rec.Ship_Line_Attribute15          ,
11418 	  l_rcv_transaction_rec.Ussgl_Transaction_Code         ,
11419 	  l_rcv_transaction_rec.Government_Context             ,
11420 	  l_rcv_transaction_rec.Reason_Id                      ,
11421 	  l_rcv_transaction_rec.Destination_Context            ,
11422 	  l_rcv_transaction_rec.Source_Doc_Quantity            ,
11423 	  l_rcv_transaction_rec.Source_Doc_Unit_Of_Measure     ,
11424 	  l_rcv_transaction_rec.use_mtl_lot                  ,
11425 	  l_rcv_transaction_rec.use_mtl_serial               ,
11426 	  l_rcv_transaction_rec.QA_Collection_Id               ,
11427 	  l_rcv_transaction_rec.Country_of_Origin_Code         ,
11428 	  l_rcv_transaction_rec.oe_order_header_id             ,
11429 	  l_rcv_transaction_rec.oe_order_line_id               ,
11430 	  l_rcv_transaction_rec.customer_item_num              ,
11431 	  l_rcv_transaction_rec.customer_id                    ,
11432 	  l_rcv_transaction_rec.customer_site_id               ,
11433 	  l_rcv_transaction_rec.put_away_rule_id               ,
11434 	  l_rcv_transaction_rec.put_away_strategy_id           ,
11435 	  p_lpn_id                         ,
11436 	  p_transfer_lpn_id                ,
11437 	  l_rcv_transaction_rec.cost_group_id                  ,
11438 	  p_mmtt_temp_id                                       ,
11439 	  l_rcv_transaction_rec.mobile_txn                     ,
11440 	  l_rcv_transaction_rec.transfer_cost_group_id         ,
11441 	  l_rcv_transaction_rec.secondary_quantity             ,
11442 	  l_rcv_transaction_rec.secondary_unit_of_measure      ,
11443 	  l_rcv_transaction_rec.lpn_group_id,
11444 	  nvl(l_operating_unit_id,l_rcv_transaction_rec.org_id)   --<R12 MOAC>
11445 	  );
11446 	-- *****************
11447 	-- This part may not be nneded when license_plate_numbver, transfer_license_plate_number
11448 	-- is inserted by insert_row itself.
11449 	-- added update to validation_flag
11450 	-- *******************
11451 	update rcv_transactions_interface
11452 	  set transfer_license_plate_number = p_transfer_lpn,
11453 	  validation_flag = 'Y',
11454 	  project_id = p_project_id,
11455 	  task_id = p_task_id
11456 	  where interface_transaction_id = l_interface_transaction_id;
11457 
11458 	Exit;
11459      End loop;
11460 
11461      l_progress := 'WMSINB-16280';
11462 
11463      x_interface_transaction_id := l_interface_transaction_id;
11464 
11465 
11466      -- Call the LOT API to insert into LOTS Interface
11467 
11468      l_lot_interface_id := null;
11469      l_serial_interface_id := null;
11470      l_serial_interface_inserted := FALSE;
11471 
11472      IF (l_debug = 1) THEN
11473 	print_debug('create_rti_from_lpn : - after Inserting into RTI' , 1);
11474      END IF;
11475 
11476 
11477      l_progress := 'WMSINB-16296';
11478 
11479      IF (p_transaction_type = 'RECEIVE') THEN
11480 	-- Case where EXPLOSION NEEDS TO HAPPEN FROM WLC
11481 	IF (l_debug = 1) THEN
11482            print_debug('create_rti_from_lpn : - Before Inserting Lots from WLC ' , 1);
11483 	END IF;
11484 
11485         l_progress := 'WMSINB-16604';
11486 
11487 	For l_lot_rec in ( select lot_number,
11488 			   uom_code,
11489 			   sum(quantity) quantity
11490 			   from wms_lpn_contents wlc
11491                            where wlc.inventory_item_id = p_item_id
11492 			   and wlc.organization_id = p_org_id
11493 			   and wlc.parent_lpn_id = p_lpn_id
11494                            group by lot_number, uom_code )
11495 	  Loop
11496 
11497 	     IF (l_lot_rec.uom_code <> l_primary_uom) THEN
11498 		l_primary_lot_qty := inv_rcv_cache.convert_qty(p_inventory_item_id => p_item_id
11499 						 ,p_from_qty         => l_lot_rec.quantity
11500 						 ,p_from_uom_code    => l_lot_rec.uom_code
11501 						 ,p_to_uom_code      => l_primary_uom
11502 						 );
11503 	      ELSE
11504 		l_primary_lot_qty := l_lot_rec.quantity;
11505 	     END IF;
11506 
11507 	     if l_lot_interface_id is null then
11508 		SELECT mtl_material_transactions_s.NEXTVAL
11509                   INTO l_lot_Interface_Id
11510 		  FROM DUAL;
11511 	     End if;
11512 
11513 	     l_serial_interface_id := null;
11514 
11515 	     -- Call insert MSNI for linked Serials Here
11516 	     For l_serial_rec in ( select msn.serial_number
11517 				   from mtl_serial_numbers msn
11518 				   where msn.lpn_id = p_lpn_id
11519 				   and msn.current_organization_id = p_org_id
11520 				   and msn.lot_number = l_lot_rec.lot_number
11521 				   and msn.inventory_item_id = p_item_id
11522 				   )
11523 	       Loop
11524 		  -- Generate the serial interface id here
11525 		  if l_serial_interface_id is null then
11526 		     SELECT mtl_material_transactions_s.NEXTVAL
11527 		       INTO l_serial_Interface_Id
11528 		       FROM DUAL;
11529 		  End if;
11530 
11531 		  insert_msni(p_product_transaction_id   => l_interface_transaction_id,
11532 			      p_product_code             => 'RCV',
11533 			      p_interface_id             => l_serial_Interface_Id,
11534 			      p_item_id                  => p_item_id,
11535 			      p_lot_number               => l_lot_rec.lot_number,
11536 			      p_fm_serial_number         => l_serial_rec.serial_number,
11537 			      p_to_serial_number         => l_serial_rec.serial_number,
11538 			      x_return_status            => x_return_status,
11539 			      x_msg_count                => l_msg_count,
11540 			      x_msg_data                 => l_msg_data
11541 			      );
11542 		  -- Check the error status from the above call
11543 		  if x_return_status <> G_RET_STS_SUCCESS Then
11544 		     -- MSG no new message just add the one on stack
11545 		     --  Review Late Set Appropiate Message
11546 		     exit; -- Exit from the Loop
11547 		  End if;
11548 
11549 		  l_serial_interface_inserted := TRUE;
11550 
11551 	       End Loop;
11552 
11553 	       insert_mtli(p_product_transaction_id   => l_interface_transaction_id,
11554 			   p_product_code             => 'RCV',
11555 			   p_interface_id             => l_lot_Interface_Id,
11556 			   p_org_id                   => p_org_id,
11557 			   p_item_id                  => p_item_id,
11558 			   p_lot_number               => l_lot_rec.lot_number,
11559 			   p_transaction_quantity     => l_lot_rec.quantity,
11560 			   p_primary_quantity         => l_primary_lot_qty,
11561 			   p_serial_interface_id      => l_serial_interface_id,
11562 			   x_return_status            => x_return_status,
11563 			   x_msg_count                => l_msg_count,
11564 			   x_msg_data                 => l_msg_data
11565 			   );
11566 
11567 	       -- Check the error status from the above call
11568 	       if x_return_status <> G_RET_STS_SUCCESS Then
11569 		  -- MSG no new message just add the one on stack
11570 		  --  Review Late Set Appropiate Message
11571 		  null;
11572 	       End if;
11573 	  End Loop;
11574 
11575           l_progress := 'WMSINB-16693';
11576 
11577 	  -- Cases for JUST SERIAL CONTROLLED
11578 	  if (l_serial_interface_inserted <> TRUE ) then
11579 
11580 	     For l_serial_rec in ( select msn.serial_number
11581 				   from mtl_serial_numbers msn
11582 				   where msn.lpn_id = p_lpn_id
11583 				   and msn.current_organization_id = p_org_id
11584 				   and msn.inventory_item_id = p_item_id
11585 				   )
11586 	       Loop
11587 		  -- Generate the serial interface id here
11588 		  if l_serial_interface_id is null then
11589 		     SELECT mtl_material_transactions_s.NEXTVAL
11590 		       INTO l_serial_Interface_Id
11591 		       FROM DUAL;
11592 		  End if;
11593 
11594 		  insert_msni(p_product_transaction_id   => l_interface_transaction_id,
11595 			      p_product_code             => 'RCV',
11596 			      p_interface_id             => l_serial_Interface_Id,
11597 			      p_item_id                  => p_item_id,
11598 			      p_lot_number               => null,
11599 			      p_fm_serial_number         => l_serial_rec.serial_number,
11600 			      p_to_serial_number         => l_serial_rec.serial_number,
11601 			      x_return_status            => x_return_status,
11602 			      x_msg_count                => l_msg_count,
11603 			      x_msg_data                 => l_msg_data
11604 			      );
11605 		  -- Check the error status from the above call
11606 		  if x_return_status <> G_RET_STS_SUCCESS Then
11607 		     -- MSG no new message just add the one on stack
11608 		     --  Review Late Set Appropiate Message
11609 		     exit; -- Exit from the Loop
11610 		  End if;
11611 
11612 		  l_serial_interface_inserted := TRUE;
11613 
11614 	       End Loop;
11615                l_progress := 'WMSINB-16733';
11616 	  End if;
11617      End if;
11618 
11619      IF (l_debug = 1) THEN
11620         print_debug('create_rti_from_lpn : - COMPLETED WITH SUCCESS'  , 1);
11621      END IF;
11622 
11623 EXCEPTION
11624    when others then
11625       x_return_status  := g_ret_sts_unexp_error;
11626       IF (l_debug = 1) THEN
11627          print_debug('create_rti_from_lpn : - other exception:'|| l_progress || ' ' ||
11628 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
11629       END IF;
11630       IF SQLCODE IS NOT NULL THEN
11631 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.create_rti_for_lpn',l_progress, SQLCODE);
11632       END IF;
11633       --  Get message count and data
11634       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => l_msg_count, p_data => x_msg_data);
11635 
11636 END create_rti_for_lpn;
11637 
11638 PROCEDURE explode_lpn_for_xfer_dlvr(p_transaction_type          IN varchar2
11639 				    ,p_lpn_id                    IN NUMBER
11640 				    ,p_rti_id                   IN NUMBER
11641 				    ,p_rti_lpn_id               IN NUMBER
11642 				    ,p_rti_xfer_lpn_id          IN NUMBER
11643 				    ,p_rti_xfer_lpn             IN VARCHAR2
11644 				    ,p_rti_to_organization_id   IN NUMBER
11645 				    ,x_return_status            OUT NOCOPY VARCHAR2
11646 				    ,x_msg_count                OUT NOCOPY NUMBER
11647 				    ,x_msg_data                 OUT NOCOPY VARCHAR2
11648 				    ) IS
11649    CURSOR c_mol_mmtt_ctnt_cur(v_lpn_id NUMBER ) IS
11650       SELECT mmtt.transaction_temp_id txn_tmp_id
11651 	,    mtrl.lpn_id
11652 	,    mtrl.inventory_item_id
11653 	,    mtrl.organization_id
11654 	,    mtrl.revision
11655 	,    mtrl.lot_number
11656 	,    mtrl.project_id
11657 	,    mtrl.task_id
11658 	,    mtrl.inspection_status
11659 	,    Nvl(mmtt.primary_quantity,mtrl.primary_quantity) prim_qty
11660 	,    Nvl(mmtt.transaction_quantity,mtrl.quantity-Nvl(mtrl.quantity_delivered,0)) txn_qty
11661 	,    Nvl(mmtt.transaction_uom,mtrl.uom_code) txn_uom_code
11662 	,    Nvl(mmtt.secondary_transaction_quantity
11663 	,    mtrl.secondary_quantity-Nvl(mtrl.secondary_quantity_delivered,0)) sec_qty --OPM Convergence
11664 	FROM   mtl_material_transactions_temp mmtt, mtl_txn_request_lines mtrl
11665 	WHERE  mmtt.move_order_line_id (+)= mtrl.line_id
11666 	AND    mtrl.lpn_id                = v_lpn_id
11667 	AND    mtrl.line_status           = 7
11668 	AND    mtrl.quantity-Nvl(mtrl.quantity_delivered,0) > 0
11669 	AND    exists (SELECT 1
11670 		       FROM  mtl_txn_request_headers mtrh
11671 		       WHERE mtrh.move_order_type = inv_globals.g_move_order_put_away
11672 		       AND   mtrh.header_id = mtrl.header_id);
11673 
11674    TYPE mol_mmtt_ctnt_tb_tp IS TABLE OF c_mol_mmtt_ctnt_cur%ROWTYPE;
11675    l_mol_mmtt_ctnt_tb mol_mmtt_ctnt_tb_tp;
11676 
11677    CURSOR c_rs_cursor(v_lpn_id NUMBER) IS
11678       SELECT rs.rcv_transaction_id         transaction_id
11679 	,    rs.item_id                inventory_item_id
11680 	,    rs.to_organization_id     organization_id
11681 	,    rs.item_revision          revision
11682 	,    Decode(rls.lot_num
11683 		    ,NULL
11684 		    ,rs.quantity
11685 		    ,rls.quantity)     quantity
11686 	,    rs.unit_of_measure        unit_of_measure
11687 	,    rls.lot_num               lot_number
11688 	,    NULL                      serial_number
11689 	,    Decode(rt.routing_header_id
11690 		    ,2
11691 		    ,Decode(rt.inspection_status_code
11692 			    -- Modified for the bug #: 6598429
11693 			    -- ,'ACCEPT'
11694 			    ,'ACCEPTED'
11695                             -- End of bug #: 6598429
11696 			    ,2
11697 			    ,Decode(rt.inspection_status_code
11698 				   -- Modified for the bug #: 6598429
11699 				   -- ,'REJECT'
11700 				   ,'REJECTED'
11701 				   -- End of bug #: 6598429
11702 				   ,3
11703 				    ,Decode(rt.inspection_status_code
11704 					    ,'NOT INSPECTED'
11705 					    ,1
11706 					    ,0)
11707 				    )
11708 			    )
11709 		    , NULL) inspection_status
11710 	,    rt.project_id             project_id
11711 	,    rt.task_id                task_id
11712 	FROM rcv_supply rs
11713 	,    rcv_lots_supply rls
11714 	,    rcv_transactions rt
11715 	WHERE rs.lpn_id = v_lpn_id
11716 	AND   rs.rcv_transaction_id = rls.transaction_id (+)
11717 	AND   rs.supply_type_code = 'RECEIVING'
11718 	AND   rs.rcv_transaction_id = rt.transaction_id
11719 	AND   NOT exists (SELECT 1
11720 			  FROM   rcv_serials_supply rss
11721 			  WHERE  rss.transaction_id = rs.rcv_transaction_id)
11722 	UNION
11723 	SELECT rs.rcv_transaction_id     transaction_id
11724 	,      rs.item_id                inventory_item_id
11725 	,      rs.to_organization_id     organization_id
11726 	,      rs.item_revision          revision
11727 	,      1
11728 	,      rs.unit_of_measure        unit_of_measure
11729 	,      rss.lot_num               lot_number
11730 	,      rss.serial_num            serial_number
11731 	,      Decode(rt.routing_header_id
11732 		      ,2
11733 		      ,Decode(rt.inspection_status_code
11734 			      -- Modified for the bug #: 6598429
11735 			      -- ,'ACCEPT'
11736 			       ,'ACCEPTED'
11737                               -- End of bug #: 6598429
11738 			      ,2
11739 			      ,Decode(rt.inspection_status_code
11740 				      -- Modified for the bug #: 6598429
11741                                       -- ,'REJECT'
11742 				      ,'REJECTED'
11743                                       -- End of bug #: 6598429
11744 				      ,3
11745 				      ,Decode(rt.inspection_status_code
11746 					      ,'NOT INSPECTED'
11747 					      ,1
11748 					      ,0)
11749 				      )
11750 			      )
11751 		      , NULL) inspection_status
11752 	,    rt.project_id             project_id
11753 	,    rt.task_id                task_id
11754 	FROM rcv_supply rs
11755 	,    rcv_serials_supply rss
11756 	,    rcv_transactions rt
11757 	WHERE rs.lpn_id = v_lpn_id
11758 	AND   rs.rcv_transaction_id = rss.transaction_id
11759 	AND   rs.supply_type_code = 'RECEIVING'
11760 	AND   rs.rcv_transaction_id = rt.transaction_id;
11761 
11762 
11763    TYPE rs_tb_tp IS TABLE OF c_rs_cursor%ROWTYPE;
11764    l_rs_tb rs_tb_tp;
11765 
11766    l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
11767    l_progress VARCHAR2(15) := '10';
11768    l_return_status VARCHAR2(1);
11769    l_msg_count     NUMBER;
11770    l_msg_data      VARCHAR2(2000);
11771    l_rs_index NUMBER;
11772    l_next_rs_index NUMBER;
11773    l_qty_to_match NUMBER;
11774    l_rs_uom_code  VARCHAR2(3);
11775    l_prim_uom_code VARCHAR2(3);
11776    l_avail_rs_qty NUMBER;
11777    l_avail_rs_prim_qty NUMBER;
11778    l_mmtt_to_insert NUMBER;
11779    l_qty_to_insert  NUMBER;
11780    l_xfer_lpn_id_to_insert NUMBER;
11781    l_xfer_lpn_to_insert VARCHAR2(30);
11782    l_transaction_id NUMBER;
11783    l_lot_interface_id NUMBER;
11784    l_serial_interface_id NUMBER;
11785    l_prim_qty_to_insert NUMBER;
11786    l_rti_index NUMBER;
11787    l_rti_serial_index NUMBER;
11788    l_sn_ctrl          NUMBER;
11789 
11790    l_serial_found     NUMBER;
11791    l_delete_rs        NUMBER;
11792 
11793    TYPE num_tb_tp IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
11794 
11795    TYPE rti_rec IS RECORD
11796      (quantity      NUMBER);
11797    TYPE rti_tb_tp IS TABLE OF rti_rec INDEX BY BINARY_INTEGER;
11798    l_rti_tb rti_tb_tp;
11799    TYPE serial_tb IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
11800    TYPE rti_serial_tb IS TABLE OF serial_tb INDEX BY BINARY_INTEGER;
11801    l_rti_serial_tb rti_serial_tb;
11802 BEGIN
11803 
11804    IF (l_debug = 1) THEN
11805       print_debug('Entering explode_lpn_for_xfer_dlvr',4);
11806       print_debug('p_lpn_id                 => '||p_lpn_id,4);
11807       print_debug('p_rti_lpn_id             => '||p_rti_lpn_id,4);
11808       print_debug('p_rti_xfer_lpn_id        => '||p_rti_xfer_lpn_id,4);
11809       print_debug('p_rti_xfer_lpn           => '||p_rti_xfer_lpn,4);
11810       print_debug('p_rti_to_organization_id => '||p_rti_to_organization_id,4);
11811    END IF;
11812 
11813    l_progress := '###';
11814    OPEN c_mol_mmtt_ctnt_cur(p_lpn_id);
11815    l_progress := '###';
11816    FETCH c_mol_mmtt_ctnt_cur bulk collect INTO l_mol_mmtt_ctnt_tb;
11817    l_progress := '###';
11818    CLOSE c_mol_mmtt_ctnt_cur;
11819 
11820    IF l_mol_mmtt_ctnt_tb.COUNT = 0 THEN
11821       IF (l_debug = 1) THEN
11822 	 print_debug('This LPN has no contents.  Returning success',4);
11823 	 RETURN;
11824       END IF;
11825     ELSE
11826       IF (l_debug = 1) THEN
11827 	 print_debug('Number of MOL/MMTT records: '||l_mol_mmtt_ctnt_tb.COUNT,4);
11828       END IF;
11829    END IF;
11830 
11831    l_progress := '###';
11832    OPEN c_rs_cursor(p_lpn_id);
11833    l_progress := '###';
11834    FETCH c_rs_cursor bulk collect INTO l_rs_tb;
11835    l_progress := '###';
11836    CLOSE c_rs_cursor;
11837    l_progress := '###';
11838 
11839    IF l_rs_tb.COUNT = 0 THEN
11840       IF (l_debug = 1) THEN
11841 	 print_debug('There is no RCV records, but LPN has contents.  How?',4);
11842       END IF;
11843       RAISE fnd_api.g_exc_error;
11844     ELSE
11845       IF (l_debug = 1) THEN
11846 	 print_debug('Number of RCV records: '||l_rs_tb.COUNT,4);
11847       END IF;
11848    END IF;
11849 
11850    FOR i IN 1..l_mol_mmtt_ctnt_tb.COUNT LOOP
11851       IF (l_debug = 1) THEN
11852 	 print_debug('i:'||i||
11853 		     ' item_id:'||l_mol_mmtt_ctnt_tb(i).inventory_item_id||
11854 		     ' revision:'||l_mol_mmtt_ctnt_tb(i).revision||
11855 		     ' lot_num:'||l_mol_mmtt_ctnt_tb(i).lot_number||
11856 		     ' qty:'|| l_mol_mmtt_ctnt_tb(i).txn_qty||
11857 		     ' uom:'|| l_mol_mmtt_ctnt_tb(i).txn_uom_code||
11858 		     ' insect_status:'||l_mol_mmtt_ctnt_tb(i).inspection_status||
11859 		     ' txn_tmp_id:'||l_mol_mmtt_ctnt_tb(i).txn_tmp_id
11860 		     ,4);
11861       END IF;
11862 
11863       l_progress := '###';
11864       l_qty_to_match := l_mol_mmtt_ctnt_tb(i).txn_qty;
11865       l_serial_found := 0;
11866       l_rs_index     := l_rs_tb.first;
11867       l_rti_tb.DELETE;
11868       l_rti_serial_tb.DELETE;
11869 
11870       l_prim_uom_code := inv_rcv_cache.get_primary_uom_code
11871 	                    (l_mol_mmtt_ctnt_tb(i).organization_id
11872 			     ,l_mol_mmtt_ctnt_tb(i).inventory_item_id);
11873       l_sn_ctrl := inv_rcv_cache.get_sn_ctrl_code
11874 	              (l_mol_mmtt_ctnt_tb(i).organization_id
11875 		       ,l_mol_mmtt_ctnt_tb(i).inventory_item_id);
11876 
11877       LOOP
11878 	 l_progress := '###';
11879 	 EXIT WHEN l_rs_index IS NULL;
11880 
11881 	 l_delete_rs    := 0;
11882 
11883 	 IF (l_debug = 1) THEN
11884 	    print_debug('l_rs_index:'||l_rs_index||
11885 			' rcv_txn_id:'||l_rs_tb(l_rs_index).transaction_id||
11886 			' item_id:'||l_rs_tb(l_rs_index).inventory_item_id||
11887 			' revision:'||l_rs_tb(l_rs_index).revision||
11888 			' lot_num:'||l_rs_tb(l_rs_index).lot_number||
11889 			' ser_num:'||l_rs_tb(l_rs_index).serial_number||
11890 			' qty:'|| l_rs_tb(l_rs_index).quantity||
11891 			' uom:'|| l_rs_tb(l_rs_index).unit_of_measure||
11892 			' insect_status:'||l_rs_tb(l_rs_index).inspection_status
11893 			,4);
11894 	 END IF;
11895 
11896 	    IF NOT (inv_cache.set_item_rec(l_mol_mmtt_ctnt_tb(i).organization_id,l_mol_mmtt_ctnt_tb(i).inventory_item_id)) THEN
11897            fnd_message.set_name('INV', 'INV_INT_ITMCODE');
11898            fnd_msg_pub.add;
11899            RAISE fnd_api.g_exc_unexpected_error;
11900         END IF;
11901 
11902 
11903 	 IF (l_mol_mmtt_ctnt_tb(i).organization_id = l_rs_tb(l_rs_index).organization_id
11904 	     AND l_mol_mmtt_ctnt_tb(i).inventory_item_id = l_rs_tb(l_rs_index).inventory_item_id
11905 	     AND (Nvl(l_mol_mmtt_ctnt_tb(i).revision,'#$#') = Nvl(l_rs_tb(l_rs_index).revision,'#$#') OR
11906 		 nvl(inv_cache.item_rec.revision_qty_control_code,1) = 1) --BUG13562127
11907 	     AND Nvl(l_mol_mmtt_ctnt_tb(i).lot_number,'#$#') = Nvl(l_rs_tb(l_rs_index).lot_number,'#$#')
11908 	     AND Nvl(l_mol_mmtt_ctnt_tb(i).inspection_status,0) = Nvl(l_rs_tb(l_rs_index).inspection_status,0)
11909 	     AND Nvl(l_mol_mmtt_ctnt_tb(i).project_id,-1) = Nvl(l_rs_tb(l_rs_index).project_id,-1)
11910 	     AND Nvl(l_mol_mmtt_ctnt_tb(i).task_id,-1) = Nvl(l_rs_tb(l_rs_index).task_id,-1))
11911 	   THEN
11912 
11913 	    IF l_rs_tb(l_rs_index).serial_number IS NULL THEN--Non-serialized item
11914 
11915 	       BEGIN
11916 		  SELECT uom_code
11917 		    into l_rs_uom_code
11918 		    FROM mtl_item_uoms_view
11919 		    WHERE organization_id = l_rs_tb(l_rs_index).organization_id
11920 		    AND inventory_item_id = l_rs_tb(l_rs_index).inventory_item_id
11921 		    AND unit_of_measure = l_rs_tb(l_rs_index).unit_of_measure;
11922 	       EXCEPTION
11923 		  WHEN OTHERS THEN
11924 		     IF (l_debug = 1) THEN
11925 			print_debug('Error retrieving uom_code', 1);
11926 		     END IF;
11927 		     l_progress := 'WMSINB-11065';
11928 		     RAISE fnd_api.g_exc_error;
11929 	       END;
11930 
11931 	       IF l_mol_mmtt_ctnt_tb(i).txn_uom_code <> l_rs_uom_code THEN
11932 		  l_avail_rs_qty := inv_rcv_cache.convert_qty(l_rs_tb(l_rs_index).inventory_item_id
11933 						,l_rs_tb(l_rs_index).quantity
11934 						,l_rs_uom_code
11935 						,l_mol_mmtt_ctnt_tb(i).txn_uom_code);
11936 		ELSE
11937 		  l_avail_rs_qty := l_rs_tb(l_rs_index).quantity;
11938 	       END IF;
11939 
11940 	       IF l_qty_to_match > l_avail_rs_qty THEN
11941 
11942 		  IF (l_mol_mmtt_ctnt_tb(i).txn_tmp_id IS NOT NULL) then
11943 		     IF (l_mol_mmtt_ctnt_tb(i).txn_uom_code <> l_prim_uom_code) THEN
11944 			l_avail_rs_prim_qty := inv_rcv_cache.convert_qty(l_rs_tb(l_rs_index).inventory_item_id
11945 							   ,l_avail_rs_qty
11946 							   ,l_mol_mmtt_ctnt_tb(i).txn_uom_code
11947 							   ,l_prim_uom_code);
11948 		      ELSE
11949 			l_avail_rs_prim_qty := l_avail_rs_qty;
11950 		     END IF;
11951 
11952 		     inv_rcv_integration_apis.split_mmtt
11953 		       (p_orig_mmtt_id      => l_mol_mmtt_ctnt_tb(i).txn_tmp_id
11954 			,p_prim_qty_to_splt => l_avail_rs_prim_qty
11955 			,p_prim_uom_code    => l_prim_uom_code
11956 			,x_new_mmtt_id      => l_mmtt_to_insert
11957 			,x_return_status    => l_return_status
11958 			,x_msg_count        => l_msg_count
11959 			,x_msg_data         => l_msg_data
11960 			);
11961 		   ELSE
11962 		     l_mmtt_to_insert := NULL;
11963 		  END IF;--IF (l_mol_mmtt_ctnt_tb(i).txn_tmp_id IS NOT NULL) then
11964 
11965 		  l_qty_to_insert    := l_avail_rs_qty;
11966 		  l_qty_to_match     := l_qty_to_match - l_avail_rs_qty;
11967 
11968 		  l_delete_rs := 1;
11969 		ELSE
11970 		  l_mmtt_to_insert   := l_mol_mmtt_ctnt_tb(i).txn_tmp_id;
11971 		  l_qty_to_insert    := l_qty_to_match;
11972 		  l_qty_to_match     := 0;
11973 
11974 		  IF l_mol_mmtt_ctnt_tb(i).txn_uom_code <> l_rs_uom_code THEN
11975 		     l_rs_tb(l_rs_index).quantity := l_rs_tb(l_rs_index).quantity -
11976 		                                     inv_rcv_cache.convert_qty
11977 		                                        (l_rs_tb(l_rs_index).inventory_item_id
11978 							 ,l_qty_to_match
11979 							 ,l_mol_mmtt_ctnt_tb(i).txn_uom_code
11980 							 ,l_rs_uom_code);
11981 		   ELSE
11982 		     l_rs_tb(l_rs_index).quantity := l_rs_tb(l_rs_index).quantity-l_qty_to_match;
11983 		  END IF;
11984 
11985 		  l_delete_rs := 0;
11986 
11987 	       END IF;--IF l_qty_to_match > l_avail_rs_qty THEN
11988 
11989 	       IF ( p_lpn_id <> p_rti_lpn_id) then
11990 		  -- Create a new RTI row with flpn=childlpn and tlpn = childlpn;
11991 		  l_xfer_lpn_id_to_insert := p_lpn_id;
11992 		  l_xfer_lpn_to_insert := NULL;
11993 		ELSE
11994 		  -- Create a new RTI row with flpn=childlpn and tlpn = tlpn;
11995 		  l_xfer_lpn_id_to_insert := p_rti_xfer_lpn_id;
11996 		  l_xfer_lpn_to_insert := p_rti_xfer_lpn;
11997 	       END IF;
11998 
11999 	       create_rti_for_lpn(p_transaction_type         => p_transaction_type,
12000 				  p_interface_transaction_id => p_rti_id,
12001 				  p_lpn_id                   => l_mol_mmtt_ctnt_tb(i).lpn_id,
12002 				  p_item_id                  => l_mol_mmtt_ctnt_tb(i).inventory_item_id,
12003 				  p_org_id                   => l_mol_mmtt_ctnt_tb(i).organization_id,
12004 				  p_to_org_id                => p_rti_to_organization_id,
12005 				  p_item_desc                => '',
12006 				  p_item_revision            => l_rs_tb(l_rs_index).revision, --BUG13562127
12007 				  p_quantity                 => l_qty_to_insert,
12008 				  p_txn_uom_code             => l_mol_mmtt_ctnt_tb(i).txn_uom_code,
12009 				  p_transfer_lpn_id          => l_xfer_lpn_id_to_insert,
12010 				  p_transfer_lpn             => l_xfer_lpn_to_insert,
12011 				  p_txn_source_id            => l_rs_tb(l_rs_index).transaction_id,
12012 				  p_mmtt_temp_id             => l_mmtt_to_insert,
12013 				  p_project_id               => l_mol_mmtt_ctnt_tb(i).project_id,
12014 				  p_task_id                  => l_mol_mmtt_ctnt_tb(i).task_id,
12015 				  x_interface_transaction_id => l_transaction_id,
12016 		                  x_return_status            => x_return_status,
12017 		                  x_msg_count                => l_msg_count,
12018 		                  x_msg_data                 => l_msg_data
12019 		 );
12020 
12021 	       IF  x_return_status <> G_RET_STS_SUCCESS Then
12022 		  -- MSG no new message just add the one on stack
12023 		  -- Check the Error Status from this call
12024 		  l_progress := 'WMSINB-17580';
12025 		  RAISE FND_API.G_EXC_ERROR;
12026 	       END IF;
12027 
12028 	       IF (l_mol_mmtt_ctnt_tb(i).lot_number IS NOT NULL) THEN
12029 		  IF l_lot_interface_id IS NULL THEN
12030 		     SELECT mtl_material_transactions_s.NEXTVAL
12031 		       INTO l_lot_interface_id
12032 		       FROM DUAL;
12033 		  END IF;
12034 
12035 		  IF (l_mol_mmtt_ctnt_tb(i).txn_uom_code <> l_prim_uom_code) THEN
12036 		     l_prim_qty_to_insert := inv_rcv_cache.convert_qty(l_rs_tb(l_rs_index).inventory_item_id
12037 							,l_qty_to_insert
12038 							,l_mol_mmtt_ctnt_tb(i).txn_uom_code
12039 							,l_prim_uom_code);
12040 		   ELSE
12041 		     l_prim_qty_to_insert := l_qty_to_insert;
12042 		  END IF;
12043 
12044 
12045 		  insert_mtli(p_product_transaction_id   => l_transaction_id,
12046 			      p_product_code             => 'RCV',
12047 			      p_interface_id             => l_lot_Interface_Id,
12048 			      p_org_id                   => l_mol_mmtt_ctnt_tb(i).organization_id,
12049 			      p_item_id                  => l_mol_mmtt_ctnt_tb(i).inventory_item_id,
12050 			      p_lot_number               => l_mol_mmtt_ctnt_tb(i).lot_number,
12051 			      p_transaction_quantity     => l_qty_to_insert,
12052 			      p_primary_quantity         => l_prim_qty_to_insert,
12053 			      p_serial_interface_id      => NULL ,
12054 			      x_return_status            => l_return_status,
12055 			      x_msg_count                => l_msg_count,
12056 			      x_msg_data                 => l_msg_data
12057 			      );
12058 
12059 		  -- Check the error status from the above call
12060 		  IF x_return_status <> G_RET_STS_SUCCESS Then
12061 		     -- MSG no new message just add the one on stack
12062 		     --  Review Late Set Appropiate Message
12063 		     NULL;
12064 		  END IF ;
12065 
12066 	       END IF;--IF (l_mol_mmtt_ctnt_tb(i).lot_number IS NOT NULL) THEN
12067 
12068 	     ELSE --Item is serial controlled
12069 	       l_serial_found := 1;
12070 	       l_rti_index := l_rs_tb(l_rs_index).transaction_id;
12071 
12072 	       IF l_rti_tb.exists(l_rti_index) THEN
12073 		  l_rti_tb(l_rti_index).quantity := l_rti_tb(l_rti_index).quantity + 1;
12074 		ELSE
12075 		  l_rti_tb(l_rti_index).quantity := 1;
12076 	       END IF;
12077 
12078 	       IF l_rti_serial_tb.exists(l_rti_index) THEN
12079 		  l_rti_serial_index := l_rti_serial_tb(l_rti_index).COUNT  + 1;
12080 		ELSE
12081 		  l_rti_serial_index := 1;
12082 	       END IF;
12083 	       l_rti_serial_tb(l_rti_index)(l_rti_serial_index) := l_rs_tb(l_rs_index).serial_number;
12084 	       l_qty_to_match := l_qty_to_match - 1;
12085 	       l_delete_rs := 1;
12086 
12087 	    END IF;--IF l_rs_tb(l_rs_index).serial_number IS NULL THEN
12088 
12089 	    IF (l_delete_rs = 1) THEN
12090 	       l_next_rs_index := l_rs_tb.next(l_rs_index);
12091 	       l_rs_tb.DELETE(l_rs_index);
12092 	       l_rs_index := l_next_rs_index;
12093 	     ELSE
12094 	       l_rs_index := l_rs_tb.next(l_rs_index);
12095 	    END IF;
12096 
12097 	    IF (l_qty_to_match <= 0) THEN
12098 	       EXIT;
12099 	    END IF;
12100 	  ELSE
12101 	       l_rs_index := l_rs_tb.next(l_rs_index);
12102 	 END IF;--IF (l_mol_mmtt_ctnt_tb(i).organization_id = l_rs_tb(l_rs_index).organization_id
12103 
12104 
12105       END LOOP;--l_rs_index := l_rs_tb.first;-
12106 
12107       IF (l_serial_found = 1) THEN
12108 	 l_serial_interface_id := NULL;
12109 	 l_lot_interface_id := NULL;
12110 	 l_rti_index := l_rti_tb.first;
12111 
12112 	 LOOP
12113 	    EXIT WHEN l_rti_index IS NULL OR l_mol_mmtt_ctnt_tb(i).txn_qty <= 0;
12114 
12115 	    l_serial_interface_id := NULL;
12116 	    l_lot_interface_id := NULL;
12117 
12118 	    IF (l_debug = 1) THEN
12119 	       print_debug('Insert rti with txn_id: '||l_rti_index,4);
12120 	    END IF;
12121 
12122 	    IF (l_mol_mmtt_ctnt_tb(i).txn_qty > l_rti_tb(l_rti_index).quantity) THEN
12123 	       IF (l_mol_mmtt_ctnt_tb(i).txn_tmp_id IS NOT NULL) then
12124 		  inv_rcv_integration_apis.split_mmtt
12125 		    (p_orig_mmtt_id      => l_mol_mmtt_ctnt_tb(i).txn_tmp_id
12126 		     ,p_prim_qty_to_splt => l_rti_tb(l_rti_index).quantity
12127 		     ,p_prim_uom_code    => l_prim_uom_code
12128 		     ,x_new_mmtt_id      => l_mmtt_to_insert
12129 		     ,x_return_status    => l_return_status
12130 		     ,x_msg_count        => l_msg_count
12131 		     ,x_msg_data         => l_msg_data
12132 		     );
12133 		ELSE
12134 		  l_mmtt_to_insert := NULL;
12135 	       END IF;
12136 
12137 	       l_mol_mmtt_ctnt_tb(i).txn_qty := l_mol_mmtt_ctnt_tb(i).txn_qty - l_rti_tb(l_rti_index).quantity;
12138 	     ELSE
12139 	       l_mmtt_to_insert := l_mol_mmtt_ctnt_tb(i).txn_tmp_id;
12140 	       l_mol_mmtt_ctnt_tb(i).txn_qty := 0;
12141 	    END IF;
12142 
12143 	    IF ( p_lpn_id <> p_rti_lpn_id) then
12144 	       -- Create a new RTI row with flpn=childlpn and tlpn = childlpn;
12145 	       l_xfer_lpn_id_to_insert := p_lpn_id;
12146 	       l_xfer_lpn_to_insert := NULL;
12147 	     ELSE
12148 	       -- Create a new RTI row with flpn=childlpn and tlpn = tlpn;
12149 	       l_xfer_lpn_id_to_insert := p_rti_xfer_lpn_id;
12150 	       l_xfer_lpn_to_insert := p_rti_xfer_lpn;
12151 	    END IF;
12152 
12153 	    create_rti_for_lpn(p_transaction_type         => p_transaction_type,
12154 			       p_interface_transaction_id => p_rti_id,
12155 			       p_lpn_id                   => l_mol_mmtt_ctnt_tb(i).lpn_id,
12156 			       p_item_id                  => l_mol_mmtt_ctnt_tb(i).inventory_item_id,
12157 			       p_org_id                   => l_mol_mmtt_ctnt_tb(i).organization_id,
12158 			       p_to_org_id                => p_rti_to_organization_id,
12159 			       p_item_desc                => '',
12160 			       p_item_revision            => l_mol_mmtt_ctnt_tb(i).revision,
12161 			       p_quantity                 => l_rti_tb(l_rti_index).quantity,
12162 			       p_txn_uom_code             => l_mol_mmtt_ctnt_tb(i).txn_uom_code,
12163 			       p_transfer_lpn_id          => l_xfer_lpn_id_to_insert,
12164 			       p_transfer_lpn             => l_xfer_lpn_to_insert,
12165 			       p_txn_source_id            => l_rti_index,
12166 			       p_mmtt_temp_id             => l_mmtt_to_insert,
12167 			       p_project_id               => l_mol_mmtt_ctnt_tb(i).project_id,
12168 			       p_task_id                  => l_mol_mmtt_ctnt_tb(i).task_id,
12169 	                       x_interface_transaction_id => l_transaction_id,
12170 	                       x_return_status            => x_return_status,
12171 	                       x_msg_count                => l_msg_count,
12172 	                       x_msg_data                 => l_msg_data
12173 	      );
12174 
12175 	    IF  x_return_status <> G_RET_STS_SUCCESS Then
12176 	       -- MSG no new message just add the one on stack
12177 	       -- Check the Error Status from this call
12178 	       l_progress := 'WMSINB-17580';
12179 	       RAISE FND_API.G_EXC_ERROR;
12180 	    END IF;
12181 
12182 	    FOR j IN 1..l_rti_serial_tb(l_rti_index).COUNT LOOP
12183 	       IF l_serial_interface_id IS NULL THEN
12184 		  SELECT mtl_material_transactions_s.NEXTVAL
12185 		    INTO l_serial_Interface_Id
12186 		    FROM DUAL;
12187 	       END IF;
12188 
12189 	       IF (l_debug = 1) THEN
12190 		  print_debug('Inserting MSNI for serial: '||l_rti_serial_tb(l_rti_index)(j),4);
12191 	       END IF;
12192 
12193 	       insert_msni(p_product_transaction_id   => l_transaction_id,
12194 			   p_product_code             => 'RCV',
12195 			   p_interface_id             => l_serial_interface_id,
12196 			   p_item_id                  => l_mol_mmtt_ctnt_tb(i).inventory_item_id,
12197 			   p_lot_number               => l_mol_mmtt_ctnt_tb(i).lot_number,
12198 			   p_fm_serial_number         => l_rti_serial_tb(l_rti_index)(j),
12199 			   p_to_serial_number         => l_rti_serial_tb(l_rti_index)(j),
12200 			   x_return_status            => l_return_status,
12201 			   x_msg_count                => l_msg_count,
12202 			   x_msg_data                 => l_msg_data
12203 		 );
12204 
12205 	       -- Check the error status from the above call
12206 	       if x_return_status <> G_RET_STS_SUCCESS Then
12207 		  --  Review Late Set Appropiate Message
12208 		  EXIT; -- Exit from the Loop
12209 	       END IF;
12210 	    END LOOP;--FOR j IN 1..l_rti_serial_tb(l_rti_index).COUNT LOOP
12211 
12212 	    IF (l_mol_mmtt_ctnt_tb(i).lot_number IS NOT NULL) THEN
12213 	       IF l_lot_interface_id IS NULL THEN
12214 		  SELECT mtl_material_transactions_s.NEXTVAL
12215 		    INTO l_lot_interface_id
12216 		    FROM DUAL;
12217 	       END IF;
12218 
12219 	       IF (l_debug = 1) THEN
12220 		  print_debug('Inserting MTLI for lot: '||l_mol_mmtt_ctnt_tb(i).lot_number||
12221 			      ' qty: '||l_rti_tb(l_rti_index).quantity,4);
12222 	       END IF;
12223 
12224 	       insert_mtli(p_product_transaction_id   => l_transaction_id,
12225 			   p_product_code             => 'RCV',
12226 			   p_interface_id             => l_lot_Interface_Id,
12227 			   p_org_id                   => l_mol_mmtt_ctnt_tb(i).organization_id,
12228 			   p_item_id                  => l_mol_mmtt_ctnt_tb(i).inventory_item_id,
12229 			   p_lot_number               => l_mol_mmtt_ctnt_tb(i).lot_number,
12230 			   p_transaction_quantity     => l_rti_tb(l_rti_index).quantity,
12231 			   p_primary_quantity         => l_rti_tb(l_rti_index).quantity,
12232 			   p_serial_interface_id      => l_serial_interface_id,
12233 			   x_return_status            => l_return_status,
12234 			   x_msg_count                => l_msg_count,
12235 			   x_msg_data                 => l_msg_data
12236 			   );
12237 
12238 	       -- Check the error status from the above call
12239 	       IF x_return_status <> G_RET_STS_SUCCESS Then
12240 		  -- MSG no new message just add the one on stack
12241 		  --  Review Late Set Appropiate Message
12242 		  NULL;
12243 	       END IF ;
12244 	    END IF;--IF (l_mol_mmtt_ctnt_tb(i).lot_number IS NOT NULL) THEN
12245 
12246 	    l_rti_index := l_rti_tb.next(l_rti_index);
12247 
12248 	 END LOOP;--l_rti_index := l_rti_tb.first;
12249 
12250 	 IF l_qty_to_match > 0 THEN
12251 	    IF (l_debug = 1) THEN
12252 	       print_debug('Have finished looking at RS.  Qty still remaining. how???',4);
12253 	    END IF;
12254 	    RAISE fnd_api.g_exc_error;
12255 	 END IF;
12256 
12257       END IF; --IF (l_serial_found = 1) THEN
12258 
12259    END LOOP; --FOR i IN 1..l_mol_mmtt_ctnt_tb.COUNT LOOP
12260 
12261 EXCEPTION
12262    WHEN OTHERS THEN
12263       x_return_status  := g_ret_sts_unexp_error;
12264       IF (l_debug = 1) THEN
12265          print_debug('explode_lpn_for_xfer_dlvr : - other exception:'|| l_progress || ' ' ||
12266 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
12267       END IF;
12268 END explode_lpn_for_xfer_dlvr;
12269 
12270 -- Description
12271 -- This API create the WLPNI for the VALUES PASSED
12272 -- This is needed only for Changing Parents
12273 PROCEDURE insert_wlpni(              p_LPN_ID                        IN NUMBER ,
12274                                      p_LICENSE_PLATE_NUMBER          IN VARCHAR2 DEFAULT NULL,
12275                                      p_PARENT_LPN_ID                 IN NUMBER,
12276                                      p_PARENT_LICENSE_PLATE_NUMBER   IN VARCHAR2 DEFAULT NULL,
12277                                      p_REQUEST_ID                    IN NUMBER   DEFAULT NULL,
12278                                      p_INVENTORY_ITEM_ID             IN NUMBER   DEFAULT NULL,
12279                                      p_REVISION                      IN VARCHAR2 DEFAULT NULL,
12280                                      p_LOT_NUMBER                    IN VARCHAR2 DEFAULT NULL,
12281                                      p_SERIAL_NUMBER                 IN VARCHAR2 DEFAULT NULL,
12282                                      p_ORGANIZATION_ID               IN NUMBER ,
12283                                      p_SUBINVENTORY_CODE             IN VARCHAR2 DEFAULT NULL,
12284 				     p_LOCATOR_ID                    IN NUMBER   DEFAULT NULL,
12285   p_GROSS_WEIGHT_UOM_CODE         IN VARCHAR2 DEFAULT NULL,
12286   p_GROSS_WEIGHT                  IN NUMBER   DEFAULT NULL,
12287   p_CONTENT_VOLUME_UOM_CODE       IN VARCHAR2 DEFAULT NULL,
12288   p_CONTENT_VOLUME                IN NUMBER   DEFAULT NULL,
12289   p_TARE_WEIGHT_UOM_CODE          IN VARCHAR2 DEFAULT NULL,
12290   p_TARE_WEIGHT                   IN NUMBER   DEFAULT NULL,
12291   p_STATUS_ID                     IN NUMBER   DEFAULT NULL,
12292   p_SEALED_STATUS                 IN NUMBER   DEFAULT NULL,
12293   p_ATTRIBUTE_CATEGORY            IN VARCHAR2 DEFAULT NULL,
12294   p_ATTRIBUTE1                    IN VARCHAR2 DEFAULT NULL,
12295   p_ATTRIBUTE2                    IN VARCHAR2 DEFAULT NULL,
12296   p_ATTRIBUTE3                    IN VARCHAR2 DEFAULT NULL,
12297   p_ATTRIBUTE4                    IN VARCHAR2 DEFAULT NULL,
12298   p_ATTRIBUTE5                    IN VARCHAR2 DEFAULT NULL,
12299   p_ATTRIBUTE6                    IN VARCHAR2 DEFAULT NULL,
12300   p_ATTRIBUTE7                    IN VARCHAR2 DEFAULT NULL,
12301   p_ATTRIBUTE8                    IN VARCHAR2 DEFAULT NULL,
12302   p_ATTRIBUTE9                    IN VARCHAR2 DEFAULT NULL,
12303   p_ATTRIBUTE10                   IN VARCHAR2 DEFAULT NULL,
12304   p_ATTRIBUTE11                   IN VARCHAR2 DEFAULT NULL,
12305   p_ATTRIBUTE12                   IN VARCHAR2 DEFAULT NULL,
12306   p_ATTRIBUTE13                   IN VARCHAR2 DEFAULT NULL,
12307   p_ATTRIBUTE14                   IN VARCHAR2 DEFAULT NULL,
12308   p_ATTRIBUTE15                   IN VARCHAR2 DEFAULT NULL,
12309   p_COST_GROUP_ID                 IN NUMBER   DEFAULT NULL,
12310   p_LPN_CONTEXT                   IN NUMBER   DEFAULT NULL,
12311   p_LPN_REUSABILITY               IN NUMBER   DEFAULT NULL,
12312   p_OUTERMOST_LPN_ID              IN NUMBER   DEFAULT NULL,
12313   p_outermost_lpn                 IN VARCHAR2 DEFAULT NULL,
12314   p_HOMOGENEOUS_CONTAINER         IN NUMBER   DEFAULT NULL,
12315   p_SOURCE_TYPE_ID                IN NUMBER   DEFAULT NULL,
12316   p_SOURCE_HEADER_ID              IN NUMBER   DEFAULT NULL,
12317   p_SOURCE_LINE_ID                IN NUMBER   DEFAULT NULL,
12318   p_SOURCE_LINE_DETAIL_ID         IN NUMBER   DEFAULT NULL,
12319   p_SOURCE_NAME                   IN VARCHAR2 DEFAULT NULL,
12320   p_LPN_GROUP_ID                  IN NUMBER,
12321   x_return_status                 OUT NOCOPY VARCHAR2,
12322   x_msg_count                     OUT NOCOPY NUMBER,
12323   x_msg_data                      OUT NOCOPY VARCHAR2)
12324   is
12325      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
12326      l_progress VARCHAR2(15) := '10';
12327      l_msg_count number;
12328      l_msg_data VARCHAR2(2000);
12329 
12330 
12331      l_sysdate DATE := SYSDATE;
12332      l_user     NUMBER;
12333      l_login_id NUMBER;
12334 
12335 BEGIN
12336    x_return_status := g_ret_sts_success;
12337 
12338    l_progress := 'WMSINB-16824';
12339 
12340    l_user        := fnd_global.user_id;
12341    l_login_id       := fnd_global.login_id;
12342 
12343 
12344    IF (l_debug = 1) THEN
12345       print_debug('insert_wlpni : - WLPNI for LPNID = ' || p_lpn_id || ' LPN =' ||
12346 		  p_license_plate_number || ' '||  TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
12347    END IF;
12348 
12349    insert into wms_lpn_interface (
12350 				   LPN_ID                                 ,
12351 				   LICENSE_PLATE_NUMBER                   ,
12352 				   INVENTORY_ITEM_ID                      ,
12353 				   LAST_UPDATE_DATE                       ,
12354 				   LAST_UPDATED_BY                        ,
12355 				   CREATION_DATE                          ,
12356 				   CREATED_BY                             ,
12357 				   LAST_UPDATE_LOGIN                      ,
12358 				   REQUEST_ID                             ,
12359 				   PROGRAM_APPLICATION_ID                 ,
12360 				   PROGRAM_ID                             ,
12361 				   PROGRAM_UPDATE_DATE                    ,
12362 				   REVISION                               ,
12363 				   LOT_NUMBER                             ,
12364 				   SERIAL_NUMBER                          ,
12365 				   ORGANIZATION_ID                        ,
12366 				   SUBINVENTORY_CODE                      ,
12367 				   LOCATOR_ID                             ,
12368 				   PARENT_LPN_ID                          ,
12369 				   PARENT_LICENSE_PLATE_NUMBER            ,
12370 				   GROSS_WEIGHT_UOM_CODE                  ,
12371      GROSS_WEIGHT                           ,
12372      CONTENT_VOLUME_UOM_CODE                ,
12373      CONTENT_VOLUME                         ,
12374      TARE_WEIGHT_UOM_CODE                   ,
12375      TARE_WEIGHT                            ,
12376      STATUS_ID                              ,
12377      SEALED_STATUS                          ,
12378      ATTRIBUTE_CATEGORY                     ,
12379      ATTRIBUTE1                             ,
12380      ATTRIBUTE2                             ,
12381      ATTRIBUTE3                             ,
12382      ATTRIBUTE4                             ,
12383      ATTRIBUTE5                             ,
12384      ATTRIBUTE6                             ,
12385      ATTRIBUTE7                             ,
12386      ATTRIBUTE8                             ,
12387      ATTRIBUTE9                             ,
12388      ATTRIBUTE10                            ,
12389      ATTRIBUTE11                            ,
12390      ATTRIBUTE12                            ,
12391      ATTRIBUTE13                            ,
12392      ATTRIBUTE14                            ,
12393      ATTRIBUTE15                            ,
12394      COST_GROUP_ID                          ,
12395      LPN_CONTEXT                            ,
12396      LPN_REUSABILITY                        ,
12397      OUTERMOST_LPN_ID                       ,
12398      HOMOGENEOUS_CONTAINER                  ,
12399      SOURCE_TYPE_ID                         ,
12400      SOURCE_HEADER_ID                       ,
12401      SOURCE_LINE_ID                         ,
12402      SOURCE_LINE_DETAIL_ID                  ,
12403      SOURCE_NAME                            ,
12404      SOURCE_GROUP_ID                       )
12405      values
12406      (
12407       p_LPN_ID                                 ,
12408       p_LICENSE_PLATE_NUMBER                   ,
12409       p_INVENTORY_ITEM_ID                      ,
12410       l_sysdate                       ,
12411       l_user                        ,
12412       l_sysdate                          ,
12413       l_user                             ,
12414       l_login_id                      ,
12415       p_REQUEST_ID                             ,
12416       null, --PROGRAM_APPLICATION_ID
12417       null, -- PROGRAM_ID
12418       null, -- PROGRAM_UPDATE_DATE
12419       p_REVISION                               ,
12420       p_LOT_NUMBER                             ,
12421       p_SERIAL_NUMBER                          ,
12422       p_ORGANIZATION_ID                        ,
12423       p_SUBINVENTORY_CODE                      ,
12424       p_LOCATOR_ID                             ,
12425       p_PARENT_LPN_ID                          ,
12426       p_PARENT_LICENSE_PLATE_NUMBER            ,
12427       p_GROSS_WEIGHT_UOM_CODE                  ,
12428      p_GROSS_WEIGHT                           ,
12429      p_CONTENT_VOLUME_UOM_CODE                ,
12430      p_CONTENT_VOLUME                         ,
12431      p_TARE_WEIGHT_UOM_CODE                   ,
12432      p_TARE_WEIGHT                            ,
12433      p_STATUS_ID                              ,
12434      p_SEALED_STATUS                          ,
12435      p_ATTRIBUTE_CATEGORY                     ,
12436      p_ATTRIBUTE1                             ,
12437      p_ATTRIBUTE2                             ,
12438      p_ATTRIBUTE3                             ,
12439      p_ATTRIBUTE4                             ,
12440      p_ATTRIBUTE5                             ,
12441      p_ATTRIBUTE6                             ,
12442      p_ATTRIBUTE7                             ,
12443      p_ATTRIBUTE8                             ,
12444      p_ATTRIBUTE9                             ,
12445      p_ATTRIBUTE10                            ,
12446      p_ATTRIBUTE11                            ,
12447      p_ATTRIBUTE12                            ,
12448      p_ATTRIBUTE13                            ,
12449      p_ATTRIBUTE14                            ,
12450      p_ATTRIBUTE15                            ,
12451      p_COST_GROUP_ID                          ,
12452      p_LPN_CONTEXT                            ,
12453      p_LPN_REUSABILITY                        ,
12454      p_OUTERMOST_LPN_ID                       ,
12455      p_HOMOGENEOUS_CONTAINER                  ,
12456      p_SOURCE_TYPE_ID                         ,
12457      p_SOURCE_HEADER_ID                       ,
12458      p_SOURCE_LINE_ID                         ,
12459      p_SOURCE_LINE_DETAIL_ID                  ,
12460      p_SOURCE_NAME                            ,
12461      p_LPN_GROUP_ID  );
12462 
12463    IF (l_debug = 1) THEN
12464       print_debug('insert_wlpni : - End of Insertioin in WLPNI for LPNID = ' || p_lpn_id || ' LPN =' ||
12465 		  p_license_plate_number || ' '||  TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
12466    END IF;
12467 
12468 EXCEPTION
12469    when others then
12470       x_return_status  := g_ret_sts_unexp_error;
12471       IF (l_debug = 1) THEN
12472          print_debug('insert_wlpni : - other exception:'|| l_progress || ' ' ||
12473 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')|| 'Error =' || SQLCODE, 1);
12474       END IF;
12475       IF SQLCODE IS NOT NULL THEN
12476 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.insert_wlpni',l_progress, SQLCODE);
12477       END IF;
12478       --  Get message count and data
12479       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
12480 
12481 END insert_wlpni;
12482 
12483 
12484 -- Description
12485 -- This procedure creates a LPN from a WLPNI row
12486 --
12487 PROCEDURE create_lpn_from_wlpni(p_license_plate_number IN VARCHAR2,
12488                                 p_lpn_group_id     IN NUMBER,
12489                                 p_organization_id  IN NUMBER,
12490                                 p_lpn_context      IN NUMBER default 5 , -- defined but not used
12491                                 p_source_header_id IN NUMBER default null ,
12492                                 p_source_type_id   IN NUMBER default null ,
12493                                 x_lpn_id           OUT NOCOPY NUMBER,
12494                                 x_return_status    OUT NOCOPY VARCHAR2,
12495                                 x_msg_count        OUT NOCOPY NUMBER,
12496                                 x_msg_data         OUT NOCOPY VARCHAR2)
12497   is
12498 
12499      l_license_plate_number  varchar2(30);
12500      l_subinventory_code     varchar2(30);
12501      l_locator_id            NUMBER;
12502      l_cost_group_id         NUMBER;
12503      l_source_type_id        NUMBER;
12504      l_source_header_id      NUMBER;
12505      l_source_name           VARCHAR2(30);
12506      l_source_line_id        NUMBER;
12507      l_source_line_detail_id NUMBER;
12508      l_parent_lpn_id         NUMBER;
12509 
12510      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
12511      l_progress VARCHAR2(15) := '10';
12512      l_msg_count number;
12513      l_msg_data VARCHAR2(2000);
12514      l_lpn_id   NUMBER;
12515      /*Bug 6600013 */
12516      l_lpn               WMS_CONTAINER_PUB.LPN ;
12517      l_gross_wt_uom      VARCHAR2(3) := NULL;
12518      l_gross_wt          NUMBER	 := NULL;
12519      l_vol_uom           VARCHAR2(3) := NULL;
12520      l_cont_vol          NUMBER      := NULL;
12521      l_tare_wt_uom       VARCHAR2(3) := NULL;
12522      l_tare_wt           NUMBER      := NULL;
12523      l_container_item_id NUMBER      := NULL;
12524      /*Bug 6600013 */
12525 
12526 BEGIN
12527    x_return_status := g_ret_sts_success;
12528 
12529    l_progress := 'WMSINB-17003';
12530 
12531 BEGIN
12532    SELECT DISTINCT
12533      license_plate_number,
12534      subinventory_code,
12535      locator_id,
12536      cost_group_id,
12537      source_type_id,
12538      source_header_id,
12539      source_name,
12540      source_line_id,
12541      source_line_detail_id,
12542      parent_lpn_id,
12543     /*Bug 6600013 */
12544      gross_weight_uom_code,
12545      gross_weight,
12546      content_volume_uom_code,
12547      content_volume,
12548      tare_weight_uom_code,
12549      tare_weight ,
12550      inventory_item_id
12551      /*Bug 6600013 */
12552      INTO
12553      l_license_plate_number,
12554      l_subinventory_code,
12555      l_locator_id,
12556      l_cost_group_id,
12557      l_source_type_id,
12558      l_source_header_id,
12559      l_source_name,
12560      l_source_line_id,
12561      l_source_line_detail_id,
12562      l_parent_lpn_id,
12563     /*Bug 6600013 */
12564      l_gross_wt_uom,
12565      l_gross_wt,
12566      l_vol_uom ,
12567      l_cont_vol,
12568      l_tare_wt_uom,
12569      l_tare_wt,
12570      l_container_item_id
12571      /*Bug 6600013 */
12572      FROM wms_lpn_interface wlpni
12573      WHERE wlpni.license_plate_number = p_license_plate_number
12574      AND wlpni.source_group_id = p_lpn_group_id;
12575 EXCEPTION
12576    WHEN no_data_found THEN
12577       IF (l_debug = 1) THEN
12578 	 print_debug('CREATE_LPN_FROM_WLPNI - WLPNI record does not exist for LPN:'||p_license_plate_number,1);
12579 	 print_debug('CREATE_LPN_FROM_WLPNI - WLPNI record does not exist for lpn_group_id:'||p_lpn_group_id,1);
12580       END IF;
12581       l_progress := 'WMSINB-17020';
12582       RAISE fnd_api.g_exc_error;
12583 END;
12584 
12585 l_progress := 'WMSINB-17021';
12586 -- Overwrite/ set the source_type_id and source_header_id only if not null
12587 if p_source_header_id is not null then
12588    l_source_header_id :=  p_source_header_id;
12589 End if;
12590 
12591 if p_source_type_id is not null then
12592    l_source_type_id :=  p_source_type_id;
12593 End if;
12594 
12595 l_progress := 'WMSINB-17031';
12596 
12597 IF (l_debug = 1) THEN
12598    print_debug('CREATE_LPN_FROM_WLPNI - LPN:'||p_license_plate_number,1);
12599    print_debug('CREATE_LPN_FROM_WLPNI - lpn_group_id:'||p_lpn_group_id,1);
12600    print_debug('CREATE_LPN_FROM_WLPNI - Source header_id:'||l_source_header_id,1);
12601    print_debug('CREATE_LPN_FROM_WLPNI - Source_type_id:'||l_source_type_id,1);
12602    print_debug('CREATE_LPN_FROM_WLPNI - Source_name:'||l_source_name,1);
12603 END IF;
12604 
12605 -- Call Container API to create LPN
12606 wms_container_pvt.create_lpn(
12607 			     p_api_version           => 1.0,
12608 			     p_init_msg_list         => g_false,
12609 			     p_commit                => g_false,
12610 			     p_validation_level      => fnd_api.g_valid_level_full,
12611 			     x_return_status         => x_return_status,
12612 			     x_msg_count             => l_msg_count,
12613 			     x_msg_data              => l_msg_data,
12614 			     p_lpn                   => l_license_plate_number,
12615 			     p_organization_id       => p_organization_id,
12616 			     p_container_item_id     => l_container_item_id, --6600013
12617 			     p_lot_number            => NULL,
12618 			     p_revision              => NULL,
12619 			     p_serial_number         => NULL,
12620 			     p_subinventory          => l_subinventory_code,
12621 			     p_locator_id            => l_locator_id,
12622 			     p_source                => p_lpn_context, -- Maps to lpn_context of wms_license_plate_number
12623 			     p_cost_group_id         => l_cost_group_id,
12624 			     p_parent_lpn_id         => l_parent_lpn_id,
12625 			     p_source_type_id        => l_source_type_id,
12626 			     p_source_header_id      => l_source_header_id,
12627   p_source_name           => l_source_name,
12628   p_source_line_id        => l_source_line_id,
12629   p_source_line_detail_id => l_source_line_detail_id,
12630   x_lpn_id                => l_lpn_id );
12631 
12632 l_progress := 'WMSINB-17060';
12633 
12634 if x_return_status <> G_RET_STS_SUCCESS Then
12635    -- MSG no new message just add the one on stack
12636    -- Check the Error Status from this call
12637    l_progress := 'WMSINB-17065';
12638    RAISE FND_API.G_EXC_ERROR;
12639 End if;
12640 
12641 --Bug#6600013.start of fix
12642 l_progress := 'WMSINB-17070';
12643 
12644 IF ( l_container_item_id IS NULL ) THEN
12645 
12646      l_lpn.lpn_id  :=  l_lpn_id ;
12647      l_lpn.organization_id := p_organization_id ;
12648 
12649      IF ( nvl(l_gross_wt_uom, '###' ) <> '###' ) THEN
12650         l_lpn.gross_weight_uom_code := l_gross_wt_uom;
12651      END IF;
12652      IF  ( nvl(l_gross_wt ,0 ) >  0 ) THEN
12653         l_lpn.gross_weight := l_gross_wt  ;
12654      END IF;
12655      IF (nvl(l_vol_uom,'###') <> '###') THEN
12656         l_lpn.content_volume_uom_code := l_vol_uom  ;
12657      END IF;
12658      IF  ( nvl(l_cont_vol ,0 ) >  0 ) THEN
12659       l_lpn.content_volume:= l_cont_vol ;
12660      END IF;
12661      IF (nvl(l_tare_wt_uom,'###') <> '###') THEN
12662         l_lpn.tare_weight_uom_code:= l_tare_wt_uom;
12663      END IF;
12664      IF  ( nvl(l_tare_wt,0 ) >  0 ) THEN
12665         l_lpn.tare_weight := l_tare_wt  ;
12666      END IF;
12667 
12668      IF (l_debug = 1) THEN
12669 	   print_debug('CREATE_LPN_FROM_WLPNI - l_gross_wt_uom:'||l_gross_wt_uom,1);
12670 	   print_debug('CREATE_LPN_FROM_WLPNI - l_gross_wt:'||l_gross_wt,1);
12671 	   print_debug('CREATE_LPN_FROM_WLPNI - l_vol_uom:'||l_vol_uom,1);
12672 	   print_debug('CREATE_LPN_FROM_WLPNI - l_cont_vol:'||l_cont_vol,1);
12673 	   print_debug('CREATE_LPN_FROM_WLPNI - l_tare_wt_uom:'||l_tare_wt_uom,1);
12674 	   print_debug('CREATE_LPN_FROM_WLPNI - l_tare_wt :'||l_tare_wt,1);
12675      END IF;
12676 
12677      l_progress := 'WMSINB-17075';
12678 
12679      WMS_CONTAINER_PVT.Modify_LPN (
12680 	  p_api_version         => 1.0
12681 	, p_init_msg_list       => fnd_api.g_false
12682 	, p_commit              => fnd_api.g_false
12683 	, p_validation_level    => fnd_api.g_valid_level_full
12684 	, p_lpn                 => l_lpn
12685 	, x_return_status       => x_return_status
12686 	, x_msg_count           => l_msg_count
12687 	, x_msg_data            => l_msg_data
12688 	);
12689 
12690 	IF x_return_status <> G_RET_STS_SUCCESS THEN
12691 	   l_progress := 'WMSINB-17080';
12692 	   RAISE FND_API.G_EXC_ERROR;
12693 	END IF;
12694 	IF (l_debug = 1) THEN
12695 	 print_debug('CREATE_LPN_FROM_WLPNI - Updated LPN with weight,volume details ',1);
12696       END IF;
12697 
12698       l_progress := 'WMSINB-17085';
12699 END IF;
12700 --Bug#6600013.End of fix
12701 
12702 x_lpn_id := l_lpn_id;
12703 
12704 
12705 EXCEPTION
12706    WHEN fnd_api.g_exc_error THEN
12707       x_return_status  := g_ret_sts_error;
12708       IF (l_debug = 1) THEN
12709          print_debug('CREATE_LPN_FROM_WLPNI - Execution Error:'|| l_progress || ':' ||sqlcode, 1);
12710       END IF;
12711 
12712    WHEN OTHERS THEN
12713       x_return_status  := g_ret_sts_unexp_error;
12714       x_lpn_id := NULL;
12715       IF (l_debug = 1) THEN
12716          print_debug('CREATE_LPN_FROM_WLPNI - other exception:'|| l_progress || ' ' ||
12717 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
12718       END IF;
12719       IF SQLCODE IS NOT NULL THEN
12720 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.CREATE_LPN_FROM_WLPNI',l_progress, SQLCODE);
12721       END IF;
12722       --  Get message count and data
12723       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => l_msg_count, p_data => x_msg_data);
12724 END create_lpn_from_wlpni;
12725 
12726 Function validate_rs(p_lpn_id         IN NUMBER default null,
12727                      p_txn_id         IN NUMBER ,
12728                      x_lpn_id         OUT nocopy NUMBER
12729 		     ) return BOOLEAN
12730   is
12731 
12732      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
12733      l_progress VARCHAR2(15) := '10';
12734      l_supply_Exists NUMBER;
12735 
12736 BEGIN
12737 
12738    select lpn_id
12739      into x_lpn_id
12740      from rcv_supply rs
12741      where rs.supply_source_id = p_txn_id
12742      and ( (p_lpn_id is not null and rs.lpn_id = p_lpn_id) or (p_lpn_id is null) )
12743        and rownum = 1 ;
12744 
12745      return TRUE;
12746 
12747 EXCEPTION
12748    WHEN no_data_found THEN
12749       IF (l_debug = 1) THEN
12750 	 print_debug('validate_rs - No row found for txn/lpn:'||p_txn_id||'/'||p_lpn_id,1);
12751       END IF;
12752       RETURN FALSE;
12753    When others then
12754       IF (l_debug = 1) THEN
12755          print_debug('validate_rs - other exception:'|| l_progress || ' ' ||
12756 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||' '||sqlcode, 1);
12757       END IF;
12758       IF SQLCODE IS NOT NULL THEN
12759 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.validate_rs',l_progress, SQLCODE);
12760       END IF;
12761       return FALSE;
12762 End validate_rs;
12763 
12764 Function validate_lpn_context(p_transaction_type         IN VARCHAR2,
12765                               p_auto_transact_code       IN VARCHAR2,
12766                               p_to_lpn_context           IN NUMBER ) return BOOLEAN
12767   is
12768 
12769      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
12770      l_progress VARCHAR2(15) := '10';
12771 
12772 Begin
12773 
12774    -- Validates the TO LPN context for a transaction type
12775 
12776    if p_transaction_type = 'RECEIVE' then
12777       if (nvl(p_auto_transact_code, 'RECEIVE') <> 'DELIVER') then
12778 	 if p_to_lpn_context not in (G_LPN_CONTEXT_RCV ,G_LPN_CONTEXT_PREGENERATED ) then
12779 	    l_progress := 'WMSINB-17140';
12780 	    RAISE FND_API.G_EXC_ERROR;
12781 	 end if;
12782        else
12783 	 if p_to_lpn_context not in (G_LPN_CONTEXT_INV , G_LPN_CONTEXT_PREGENERATED ) then
12784 	    l_progress := 'WMSINB-17145';
12785 	    RAISE FND_API.G_EXC_ERROR;
12786 	 end if;
12787       end if;
12788    end if;
12789 
12790    if p_transaction_type in ('ACCEPT','REJECT') then
12791       if p_to_lpn_context not in (G_LPN_CONTEXT_RCV,G_LPN_CONTEXT_PREGENERATED ) then
12792 	 l_progress := 'WMSINB-17153';
12793 	 RAISE FND_API.G_EXC_ERROR;
12794       end if;
12795    End if;
12796 
12797    if p_transaction_type = 'DELIVER' then
12798       if p_to_lpn_context not in (G_LPN_CONTEXT_INV, G_LPN_CONTEXT_PREGENERATED ,G_LPN_CONTEXT_PICKED) then
12799 	 l_progress := 'WMSINB-17160';
12800 	 RAISE FND_API.G_EXC_ERROR;
12801       end if;
12802    End if;
12803 
12804    if p_transaction_type = 'TRANSFER' then
12805       if p_to_lpn_context not in (G_LPN_CONTEXT_PREGENERATED ,G_LPN_CONTEXT_RCV) then
12806 	 l_progress := 'WMSINB-17167';
12807 	 RAISE FND_API.G_EXC_ERROR;
12808       end if;
12809    End if;
12810 
12811    if p_transaction_type = 'SHIP' then
12812       if p_to_lpn_context not in (G_LPN_CONTEXT_PREGENERATED ) then
12813 	 l_progress := 'WMSINB-17174';
12814 	 RAISE FND_API.G_EXC_ERROR;
12815       end if;
12816    End if;
12817 
12818    return TRUE;
12819 
12820 Exception
12821    When others then
12822       --MSG WMS_CONT_INVALID_LPN_CONTEXT
12823       IF (l_debug = 1) THEN
12824          print_debug('validate_lpn_context - other exception:'|| l_progress || ' ' ||
12825 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
12826       END IF;
12827       IF SQLCODE IS NOT NULL THEN
12828 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.validate_lpn_context',l_progress, SQLCODE);
12829       END IF;
12830 
12831       fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN_CONTEXT');
12832       fnd_msg_pub.ADD;
12833 
12834       return FALSE;
12835 End validate_lpn_context;
12836 
12837 PROCEDURE delete_wlpni(p_lpn_group_id  IN NUMBER,
12838                        p_lpn_id        IN NUMBER,
12839                        p_license_plate_number IN VARCHAR2,
12840 		       x_return_status    OUT NOCOPY VARCHAR2,
12841 		       x_msg_count        OUT NOCOPY NUMBER,
12842 		       x_msg_data         OUT NOCOPY VARCHAR2)
12843   is
12844 Begin
12845    -- Deletes rows from WLPNI for the lpn_group
12846 
12847    -- Initialize API return status to success
12848    x_return_status  := g_ret_sts_success;
12849 
12850    delete from wms_lpn_interface where source_group_id = p_lpn_group_id
12851      and ( ( lpn_id = p_lpn_id ) or (license_plate_number = p_license_plate_number) ) ;
12852 
12853 Exception
12854    When others then null;
12855 End delete_wlpni;
12856 
12857 PROCEDURE Explode_lpn_contents(p_lpn_group_id     IN         NUMBER,
12858 			       x_return_status    OUT NOCOPY VARCHAR2,
12859 			       x_msg_count        OUT NOCOPY NUMBER,
12860 			       x_msg_data         OUT NOCOPY VARCHAR2)
12861   is
12862      cursor c_explode_lpn is
12863 	select interface_transaction_id
12864 	  ,transaction_type
12865 	  ,item_id
12866 	  ,item_description
12867 	  ,lpn_id
12868 	  ,transfer_lpn_id
12869 	  ,license_plate_number
12870 	  ,transfer_license_plate_number
12871 	  ,quantity
12872 	  ,shipment_header_id
12873 	  ,routing_header_id
12874 	  ,to_organization_id
12875 	  ,from_organization_id
12876 	  from rcv_transactions_interface rti
12877 	  where rti.lpn_group_id = p_lpn_group_id
12878 	  and ( Nvl(rti.item_id,-1) = -1 AND rti.item_description is null)
12879           -- Bug 3714354
12880           and ( lpn_id is not null or license_plate_number is not null )
12881 	    order by interface_transaction_id;
12882 
12883 	  l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
12884 
12885 	  l_lpn_rec c_explode_lpn%rowtype;
12886 
12887 	  l_other_txn_exists NUMBER;
12888 
12889 	  l_progress VARCHAR2(15) := '10';
12890 
12891 	  -- 1 => Means that only one type of Transaction exists for this lpn_group
12892 	  -- 0 => Means that Multiple  type of Transaction exists for this lpn_group
12893 
12894 	  l_no_other_txn_type NUMBER := 0;
12895 
12896 	  l_from_lpn_status boolean;
12897 	  l_trasfer_lpn_status boolean;
12898 
12899 	  cursor c_child_lpn(p_child_lpn_id NUMBER) is
12900 	     select distinct lpn_id
12901 	       ,license_plate_number
12902 	       from wms_license_plate_numbers
12903 	       connect by prior lpn_id = parent_lpn_id
12904 	       start with lpn_id = p_child_lpn_id
12905 	       ;
12906 
12907 	  l_child_lpn_rec c_child_lpn%rowtype;
12908 
12909 	  cursor c_lpn_contents(p_child_lpn_id1 NUMBER) is
12910 	     select  wlpn.lpn_id lpn_id
12911 	       ,wlc.inventory_item_id inventory_item_id
12912 	       ,wlc.revision item_revision
12913 	       ,wlc.uom_code mol_uom_code
12914 	       ,NULL mmtt_uom_code
12915 	       ,wlc.organization_id organization_id
12916 	       ,wlc.item_description item_description
12917 	       ,null txn_source_id
12918 	       ,null transaction_temp_id
12919 	       ,NULL project_id
12920 	       ,NULL task_id
12921 	       ,0 mmtt_quantity
12922 	       ,sum(nvl(wlc.quantity,0)) mol_quantity
12923 	       from   wms_license_plate_numbers wlpn,
12924 	       wms_lpn_contents wlc
12925 	       where  wlc.parent_lpn_id = wlpn.lpn_id
12926 	       and    wlpn.lpn_id = p_child_lpn_id1
12927 	       group by
12928 	       wlpn.lpn_id
12929 	       ,wlc.inventory_item_id
12930 	       ,wlc.revision
12931 	       ,wlc.uom_code
12932 	       ,wlc.organization_id
12933 	       ,wlc.item_description
12934 	       ;
12935 
12936 	  l_lpn_contents_rec c_lpn_contents%ROWTYPE;
12937 
12938 	  cursor c_immediate_child(p_lpn_id1 NUMBER) is
12939 	     select lpn_id
12940 	       ,license_plate_number
12941 	       ,parent_lpn_id
12942 	       ,organization_id
12943 	       from wms_license_plate_numbers
12944 	       where parent_lpn_id = p_lpn_id1;
12945 
12946 	  l_immediate_child_rec c_immediate_child%rowtype;
12947 
12948 	  l_msg_count number;
12949 	  l_msg_data VARCHAR2(2000);
12950 
12951 	  l_lpn_context NUMBER;
12952 	  l_transfer_lpn_context NUMBER;
12953 	  l_transaction_id NUMBER;
12954 
12955 	  l_wlpni_exists NUMBER;
12956 
12957 	  l_from_lpn_state BOOLEAN;
12958 	  l_to_lpn_state BOOLEAN;
12959 
12960 	  l_cur_parent_lpn_id NUMBER;
12961 
12962 	  l_wlpn_source_header_id NUMBER;
12963 	  l_xfr_wlpn_source_header_id NUMBER;
12964 
12965 	  l_mmtt_qty_mol_uom NUMBER;
12966 
12967 BEGIN
12968 
12969    x_return_status := g_ret_sts_success;
12970 
12971    l_progress := 'WMSINB-17350';
12972 
12973    IF (l_debug = 1) THEN
12974       print_debug('Explode lpn :'|| l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
12975       print_debug('Explode lpn : lpn_group_id = '|| p_lpn_group_id, 1);
12976    END If;
12977 
12978    select count(distinct decode(rti.TRANSACTION_TYPE,'ACCEPT','INSPECT TXN','REJECT','INSPECT TXN',rti.TRANSACTION_TYPE))
12979      into l_other_txn_exists
12980      from rcv_transactions_interface rti
12981      where rti.lpn_group_id = p_lpn_group_id
12982        -- Bug 3714354
12983        and ( lpn_id is not null or license_plate_number is not null )
12984      ;
12985 
12986    l_progress := 'WMSINB-17362';
12987 
12988    if l_other_txn_exists > 1 then
12989       -- Review Later
12990       -- Set appropiate message DIFFERENT TXN TYPES EXIST FOR THE SAME LPN GROUP
12991       -- MSG INV_INVALID_LPN_GROUP
12992       x_return_status := g_ret_sts_error;
12993       l_progress := 'WMSINB-17369';
12994       RAISE FND_API.G_EXC_ERROR;
12995    end if;
12996 
12997    l_progress := 'WMSINB-17373';
12998 
12999    -- Opens Cursor on RTI based on lpn_group_id
13000    open c_explode_lpn;
13001    Loop
13002       fetch c_explode_lpn into l_lpn_rec;
13003       exit when c_explode_lpn%notfound;
13004       IF (l_debug = 1) THEN
13005          print_debug('Explode_lpn_contents: inside Loop for interface_id = :'|| l_lpn_rec.interface_transaction_id, 1);
13006       END IF;
13007       -- Check whether the TRANSACTIONS Types are all same for this LPN Group ID otherwise throw error.
13008 
13009       if nvl(l_lpn_rec.quantity,0) <> 0 then
13010 	 --
13011 	 -- Quantity is not null so failure return from Here
13012 	 IF (l_debug = 1) THEN
13013 	    print_debug('Explode_lpn_contents:  Qty is not null for this lpn : FAILURE '|| l_lpn_rec.lpn_id , 1);
13014 	    print_debug('Explode_lpn_contents: Qty is not null for this lpn : FAILURE '|| l_lpn_rec.license_plate_number, 1);
13015 	 END If;
13016 
13017 
13018 	 l_progress := 'WMSINB-17395';
13019 	 x_return_status := g_ret_sts_error;
13020 
13021 	 -- Review Later
13022 	 -- Set appropiate Message
13023 
13024 	 exit;
13025        else
13026 	 if (  l_lpn_rec.lpn_id is null and
13027 	       l_lpn_rec.license_plate_number is null
13028 	       ) then
13029 	    IF (l_debug = 1) THEN
13030 	       print_debug('Explode_lpn_contents:  qty lpn item  all are null so FAILURE', 1);
13031 	    END If;
13032 	    l_progress := 'WMSINB-17409';
13033 	    x_return_status := g_ret_sts_error;
13034 	    -- Review Later
13035 	    -- Set appropiate Message
13036 	    exit;
13037 	 end if;
13038 
13039 	 -- Quantity is null so proceed with this row
13040 	 -- **************************************************************
13041 	 -- START CASES  FOR  RECEIPT  TRANSACTION
13042 	 -- **************************************************************
13043 
13044 	 --
13045 	 l_progress := 'WMSINB-17422';
13046 	 --
13047 
13048 	 l_from_lpn_state := get_lpn_id(l_lpn_rec.lpn_id,
13049 					l_lpn_rec.license_plate_number,
13050 					l_lpn_context,l_cur_parent_lpn_id,
13051 					l_wlpn_source_header_id);
13052 
13053 	 if (l_from_lpn_state <> TRUE ) then
13054 	    IF (l_debug = 1) THEN
13055 	       print_debug('Explode_LPN_contents: lpn_id and license_plate number does not exist' , 1);
13056 	    END If;
13057 	    -- MSG no new message just add the one on stack
13058 	    -- Review Later.
13059 	    -- Set Appropiate MESSAGE For ERROR
13060 	    --
13061 	    l_progress := 'WMSINB-17435';
13062 	    RAISE FND_API.G_EXC_ERROR;
13063 	  else
13064             if  l_lpn_rec.lpn_id is null then -- CASE WHERE THERE IS AN INVALID LPN
13065 	       IF (l_debug = 1) THEN
13066 		  print_debug('Explode_LPN_contents: lpn_id and license_plate number does not exist' , 1);
13067 	       END If;
13068 	       -- MSG no new message just add the one on stack
13069 	       -- Review Later.
13070 	       -- Set Appropiate MESSAGE For ERROR
13071 	       --
13072 	       l_progress := 'WMSINB-17446';
13073 	       RAISE FND_API.G_EXC_ERROR;
13074             End if;
13075 	 end if;
13076 	 --
13077 	 -- Call get_lpn_id to get the transfer lpn detials
13078 	 --
13079 	 l_progress := 'WMSINB-17453';
13080 
13081 	 l_to_lpn_state := get_lpn_id(l_lpn_rec.transfer_lpn_id,
13082 				      l_lpn_rec.transfer_license_plate_number,
13083 				      l_transfer_lpn_context,
13084 				      l_cur_parent_lpn_id,
13085 				      l_xfr_wlpn_source_header_id);
13086 
13087 	 if (l_to_lpn_state <> TRUE ) then
13088 	    IF (l_debug = 1) THEN
13089 	       print_debug('Explode_LPN_contents: lpn_id and license_plate number does not exist' , 1);
13090 	    END If;
13091 	    -- MSG no new message just add the one on stack
13092 	    -- EXISTING LPN_ID and LICENSE_PLATE_NUMBER COMBINATION IS INVALID
13093 	    -- Review Later.
13094 	    -- Set Appropiate MESSAGE For ERROR
13095 	    --
13096 	    l_progress := 'WMSINB-17469';
13097 	    RAISE FND_API.G_EXC_ERROR;
13098 	 End if;
13099 
13100 	 l_progress := 'WMSINB-17473';
13101 
13102 	 if ( l_lpn_rec.transaction_type in ( 'TRANSFER','DELIVER','RECEIVE' )) then
13103 	    IF (l_debug = 1) THEN
13104 	       print_debug('Explode_LPN_contents: For Receive Txn ', 1);
13105 	    END If;
13106 	    open c_child_lpn(l_lpn_rec.lpn_id);
13107 	    Loop
13108                IF (l_debug = 1) THEN
13109 		  print_debug('Explode_LPN_contents: Inside Child LPN loop lpn_id = ' || l_lpn_rec.lpn_id , 1);
13110                END If;
13111 
13112                Fetch c_child_lpn into l_child_lpn_rec;
13113                Exit when c_child_lpn%NotFound;
13114 
13115                IF (l_debug = 1) THEN
13116 		  print_debug('Explode LPN: Inside Child LPN loop lpn_id = ' || l_child_lpn_rec.lpn_id , 1);
13117                END If;
13118 
13119 	       IF l_lpn_rec.transaction_type = 'RECEIVE' THEN
13120 		  OPEN c_lpn_contents(l_child_lpn_rec.lpn_id);
13121 		  LOOP
13122 		     IF (l_debug = 1) THEN
13123 			print_debug('Explode LPN: Inside LPN contents loop for RECEIVE', 1);
13124 		     END If;
13125 		     FETCH c_lpn_contents into l_lpn_contents_rec;
13126 		     EXIT WHEN c_lpn_contents%notfound;
13127 		     l_transaction_id := NULL;
13128 
13129 		     IF ( l_child_lpn_rec.lpn_id <> l_lpn_rec.lpn_id) then
13130 
13131 			-- Create a new RTI row with flpn=childlpn and tlpn = childlpn;
13132 			-- Review Later
13133 			-- Call create_rti_for_lpn
13134 
13135 			l_progress := 'WMSINB-17549';
13136 
13137 			create_rti_for_lpn(p_transaction_type         => l_lpn_rec.transaction_type,
13138 					   p_interface_transaction_id => l_lpn_rec.interface_transaction_id,
13139 					   p_lpn_id                   => l_lpn_contents_rec.lpn_id,
13140 					   p_org_id                   => l_lpn_contents_rec.organization_id,
13141 					   p_to_org_id                => l_lpn_rec.to_organization_id,
13142 					   p_item_id                  => l_lpn_contents_rec.inventory_item_id,
13143 					   p_item_desc                => '',
13144 					   p_item_revision            => l_lpn_contents_rec.item_revision,
13145 					   p_quantity                 => l_lpn_contents_rec.mol_quantity,
13146 					   p_txn_uom_code             => l_lpn_contents_rec.mol_uom_code,
13147 					   p_transfer_lpn_id          => l_lpn_contents_rec.lpn_id,
13148 					   p_transfer_lpn             => null ,
13149 					   p_txn_source_id            => l_lpn_contents_rec.txn_source_id,
13150 					   p_mmtt_temp_id             => l_lpn_contents_rec.transaction_temp_id,
13151 					   p_project_id               => l_lpn_contents_rec.project_id,
13152 					   p_task_id                  => l_lpn_contents_rec.task_id,
13153 			                   x_interface_transaction_id => l_transaction_id,
13154 			                   x_return_status            => x_return_status,
13155 			                   x_msg_count                => l_msg_count,
13156 			                   x_msg_data                 => l_msg_data
13157 			  );
13158 			IF x_return_status <> G_RET_STS_SUCCESS Then
13159 			   -- MSG no new message just add the one on stack
13160 			   -- Check the Error Status from this call
13161 			   l_progress := 'WMSINB-17550';
13162 			   RAISE FND_API.G_EXC_ERROR;
13163 			END if;
13164 		      ELSE
13165 			--
13166 			-- Create a new RTI row with flpn=childlpn and tlpn = tlpn;
13167 			-- Review Later
13168 			l_progress := 'WMSINB-17579';
13169 			create_rti_for_lpn(p_transaction_type         => l_lpn_rec.transaction_type,
13170 					   p_interface_transaction_id => l_lpn_rec.interface_transaction_id,
13171 					   p_lpn_id                   => l_lpn_contents_rec.lpn_id,
13172 					   p_item_id                  => l_lpn_contents_rec.inventory_item_id,
13173 					   p_org_id                   => l_lpn_contents_rec.organization_id,
13174 					   p_to_org_id                => l_lpn_rec.to_organization_id,
13175 					   p_item_desc                => '',
13176 					   p_item_revision            => l_lpn_contents_rec.item_revision,
13177 					   p_quantity                 => l_lpn_contents_rec.mol_quantity,
13178 					   p_txn_uom_code             => l_lpn_contents_rec.mol_uom_code,
13179 					   p_transfer_lpn_id          => l_lpn_rec.transfer_lpn_id,
13180 					   p_transfer_lpn             => l_lpn_rec.transfer_license_plate_number,
13181 					   p_txn_source_id            => l_lpn_contents_rec.txn_source_id,
13182 					   p_mmtt_temp_id             => l_lpn_contents_rec.transaction_temp_id,
13183 					   p_project_id               => l_lpn_contents_rec.project_id,
13184 					   p_task_id                  => l_lpn_contents_rec.task_id,
13185 			                   x_interface_transaction_id => l_transaction_id,
13186 			                   x_return_status            => x_return_status,
13187 			                   x_msg_count                => l_msg_count,
13188 			                   x_msg_data                 => l_msg_data
13189 			  );
13190 			IF  x_return_status <> G_RET_STS_SUCCESS Then
13191 			   -- MSG no new message just add the one on stack
13192 			   -- Check the Error Status from this call
13193 			   l_progress := 'WMSINB-17580';
13194 			   RAISE FND_API.G_EXC_ERROR;
13195 			END IF;
13196 		     END IF;
13197 		  END LOOP;
13198 
13199 		  IF c_lpn_contents%isopen THEN
13200 		     CLOSE c_lpn_contents;
13201 		  END IF;
13202 
13203 		ELSIF l_lpn_rec.transaction_type IN ('TRANSFER','DELIVER') THEN
13204 		   explode_lpn_for_xfer_dlvr
13205 		     (p_transaction_type          => l_lpn_rec.transaction_type
13206 		      ,p_lpn_id                   => l_child_lpn_rec.lpn_id
13207 		      ,p_rti_id                   => l_lpn_rec.interface_transaction_id
13208 		      ,p_rti_lpn_id               => l_lpn_rec.lpn_id
13209 		      ,p_rti_xfer_lpn_id          => l_lpn_rec.transfer_lpn_id
13210 		      ,p_rti_xfer_lpn             => l_lpn_rec.transfer_license_plate_number
13211 		      ,p_rti_to_organization_id   => l_lpn_rec.to_organization_id
13212 		      ,x_return_status            => x_return_status
13213 		      ,x_msg_count                => l_msg_count
13214 		      ,x_msg_data                 => l_msg_data
13215 		      );
13216 	       END IF;
13217 	    End Loop;
13218 
13219 	    if c_child_lpn%isopen then
13220                close c_child_lpn;
13221 	    end if;
13222 
13223 	    l_progress := 'WMSINB-17621';
13224 
13225 	    --
13226 	    -- Create WLPNI rows for Explosion if needed
13227 	    --
13228 	    if ( nvl(l_lpn_rec.lpn_id,-1) <> nvl(l_lpn_rec.transfer_lpn_id,-1) ) then
13229 
13230 	       IF (l_debug = 1) THEN
13231 		  print_debug('Explode LPN: Before Immediate Child LPN loop ', 1);
13232 	       END If;
13233 
13234 	       open c_immediate_child (l_lpn_rec.lpn_id);
13235 	       Loop
13236 		  Fetch c_immediate_child into l_immediate_child_rec;
13237 		  Exit when c_immediate_child%notfound;
13238 		  -- Call create WLPNI here
13239 	          l_progress := 'WMSINB-17637';
13240 		  insert_wlpni(  p_LPN_ID => l_immediate_child_rec.lpn_id,
13241 				 p_LICENSE_PLATE_NUMBER => l_immediate_child_rec.license_plate_number,
13242 				 p_PARENT_LPN_ID => l_lpn_rec.transfer_lpn_id,
13243 				 p_PARENT_LICENSE_PLATE_NUMBER => l_lpn_rec.transfer_license_plate_number,
13244 				 p_organization_id => l_lpn_rec.to_organization_id,
13245 				 p_LPN_GROUP_ID                => p_LPN_GROUP_ID,
13246 				 x_return_status               => x_return_status,
13247 				 x_msg_count                   => l_msg_count,
13248 				 x_msg_data                    => l_msg_data
13249 				 );
13250 		  if x_return_status <> G_RET_STS_SUCCESS Then
13251 		     -- MSG no new message just add the one on stack
13252 		     -- Check the Error Status from this call
13253 		     null;
13254 		  End if;
13255 	       End loop;
13256 
13257 	       if c_immediate_child%isopen then
13258 		  close c_immediate_child;
13259 	       End if;
13260              else
13261 		     --
13262 	             l_progress := 'WMSINB-17660';
13263 		     -- Call create WLPNI here
13264 		     IF (l_debug = 1) THEN
13265 			print_debug('Explode LPN: Before insert_wlpni else ', 1);
13266 		     END If;
13267 
13268 		     -- Check Existence of rows in WLPNI
13269 		     -- If not exists then create
13270 
13271 	             l_progress := 'WMSINB-17669';
13272 		     check_lpn_in_wlpni(l_lpn_rec.license_plate_number, l_lpn_rec.lpn_id, p_lpn_group_id, l_wlpni_exists);
13273 
13274 		     if l_wlpni_exists = 0 then
13275 	                l_progress := 'WMSINB-17673';
13276 			insert_wlpni(  p_LPN_ID => l_lpn_rec.lpn_id,
13277 				       p_LICENSE_PLATE_NUMBER => l_lpn_rec.license_plate_number,
13278 				       p_PARENT_LPN_ID => null,
13279 				       p_PARENT_LICENSE_PLATE_NUMBER => null,
13280 				       p_organization_id => l_lpn_rec.to_organization_id,
13281 				       p_LPN_GROUP_ID                => p_LPN_GROUP_ID,
13282 				       x_return_status               => x_return_status,
13283 				       x_msg_count                   => l_msg_count,
13284 				       x_msg_data                    => l_msg_data
13285 				       );
13286 		     End if;
13287 	    end if;
13288 
13289 	    --
13290 	 end if; /* END OF RECEIVE TXN CASE */
13291 
13292 	 /* START OF CASE FOR OTHER TXN TYPE */
13293 	 if ( l_lpn_rec.transaction_type in ( 'ACCEPT','REJECT','RETURN TO CUSTOMER',
13294 					      'CORRECT','SHIP','RETURN TO RECEIVING','RETURN TO VENDOR','UNORDERED' )) then
13295 	    IF (l_debug = 1) THEN
13296 	       print_debug('Explode_lpn_contents:  INSPECT TXN failure txn type is wrong', 1);
13297 	       print_debug('Explode_lpn_contents:  INSPECT TXN failure txn type '|| l_lpn_rec.transaction_type, 1);
13298 	    END If;
13299 	    x_return_status := g_ret_sts_error;
13300 	    -- MSG INV_INVALID_LPN_TXN
13301 	    -- Review Later
13302 	    -- Set appropiate Message
13303 	    exit;
13304 	 end if;  /* END OF CASE FOR OTHER TXN */
13305       end if;    /* END OF QTY = 0 CASE */
13306 
13307    End Loop;
13308 
13309    IF (l_debug = 1) THEN
13310       print_debug('EXPLODE_LPN:',1);
13311    END IF;
13312 
13313 EXCEPTION
13314    WHEN OTHERS THEN
13315       x_return_status  := g_ret_sts_unexp_error;
13316 
13317       if c_lpn_contents%isopen then
13318          close c_lpn_contents;
13319       end if;
13320 
13321       if c_child_lpn%isopen then
13322          close c_child_lpn;
13323       end if;
13324 
13325       if c_immediate_child%isopen then
13326          close c_immediate_child;
13327       End if;
13328 
13329       IF (l_debug = 1) THEN
13330          print_debug('Explode lpn: - other exception:'|| l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS') || 'Error = '|| SQLCODE , 1);
13331       END IF;
13332       IF SQLCODE IS NOT NULL THEN
13333 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.explode_lpn_contents',l_progress, SQLCODE);
13334       END IF;
13335       --  Get message count and data
13336       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => l_msg_count, p_data => l_msg_data);
13337 
13338 END Explode_lpn_contents;
13339 
13340 -- Description
13341 -- Procedure whether the sub, loc,org data passed matches with the LPN
13342 -- Information
13343 PROCEDURE validate_lpn_locator( p_lpn_id IN NUMBER,
13344                                 p_subinventory     IN VARCHAR2,
13345                                 p_locator_id       IN NUMBER,
13346                                 p_organization_id  IN NUMBER,
13347                                 x_lpn_match        OUT NOCOPY VARCHAR2,
13348                                 x_return_status    OUT NOCOPY VARCHAR2,
13349                                 x_msg_count        OUT NOCOPY NUMBER,
13350                                 x_msg_data         OUT NOCOPY VARCHAR2)
13351   is
13352 
13353      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
13354      l_progress VARCHAR2(15) := '10';
13355      l_msg_count number;
13356      l_msg_data VARCHAR2(2000);
13357 
13358      l_sub_match varchar2(1) := 'N';
13359 
13360 BEGIN
13361 
13362    x_return_status := g_ret_sts_success;
13363 
13364    SELECT 'Y'
13365      INTO l_sub_match
13366      FROM wms_license_plate_numbers wlpn
13367      WHERE wlpn.lpn_id = p_lpn_id
13368      AND ((wlpn.lpn_context <> 5
13369 	   AND (Nvl(wlpn.subinventory_code,'@@@') = Nvl(p_subinventory,'@@@'))
13370 	   AND (Nvl(wlpn.locator_id,-1) = Nvl(p_locator_id,-1)))
13371 	  OR wlpn.lpn_context = 5)
13372      AND wlpn.organization_id = p_organization_id
13373      AND ROWNUM = 1
13374      ;
13375 
13376    x_lpn_match := l_sub_match;
13377 
13378 EXCEPTION
13379    when no_data_found then
13380       x_lpn_match := 'N';
13381       -- MSG WMS_CONT_INVALID_LOC
13382    when others then
13383       -- MSG WMS_CONT_INVALID_LOC
13384       x_lpn_match := 'N';
13385       x_return_status  := g_ret_sts_unexp_error;
13386       IF (l_debug = 1) THEN
13387          print_debug('validate_lpn_locator - other exception:'|| l_progress || ' ' ||
13388 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
13389       END IF;
13390       IF SQLCODE IS NOT NULL THEN
13391 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.validate_lp_locator',l_progress, SQLCODE);
13392       END IF;
13393       --  Get message count and data
13394       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => l_msg_count, p_data => x_msg_data);
13395 END validate_lpn_locator;
13396 
13397 
13398 -- Description
13399 -- This Procedure returns the PARENT_LPN_ID
13400 -- from WLPN
13401 PROCEDURE get_parent_lpn(p_license_plate_number IN VARCHAR2,
13402                          x_parent_lpn_id IN OUT NOCOPY NUMBER)
13403   is
13404 BEGIN
13405    select PARENT_LPN_ID
13406      into x_parent_lpn_id
13407      from wms_license_plate_numbers
13408      where license_plate_number = p_license_plate_number
13409      ;
13410 EXCEPTION
13411    WHEN OTHERS THEN
13412       x_parent_lpn_id := null;
13413 END get_parent_lpn;
13414 
13415 -- Description
13416 -- This Procedure returns the PARENT_LPN_ID / PARENT LICENSE_PLATE_NUMBER
13417 -- from WLPNI
13418 PROCEDURE get_parent_lpn_in_wlpni(p_license_plate_number IN VARCHAR2,
13419 				  p_lpn_id               IN NUMBER,
13420 				  p_lpn_group_id         IN NUMBER,
13421 				  x_parent_lpn IN OUT NOCOPY VARCHAR2 ,
13422 				  x_parent_lpn_id IN OUT NOCOPY NUMBER )
13423   is
13424 BEGIN
13425    if p_lpn_id is null then
13426       select PARENT_LPN_ID,
13427 	PARENT_LICENSE_PLATE_NUMBER
13428 	into x_parent_lpn_id,
13429 	x_parent_lpn
13430 	from wms_lpn_interface
13431 	where lpn_id = p_lpn_id
13432 	and source_group_id = p_lpn_group_id
13433 	;
13434     else
13435       select PARENT_LPN_ID,
13436 	PARENT_LICENSE_PLATE_NUMBER
13437 	into x_parent_lpn_id,
13438 	x_parent_lpn
13439 	from wms_lpn_interface
13440 	where license_plate_number = p_license_plate_number
13441 	and source_group_id = p_lpn_group_id;
13442    end if;
13443 EXCEPTION
13444    WHEN OTHERS THEN
13445       x_parent_lpn_id := null;
13446       x_parent_lpn    := null;
13447 END get_parent_lpn_in_wlpni;
13448 
13449 
13450 PROCEDURE VALIDATE_TOTAL_QTY(p_lpn_group_id     IN NUMBER,
13451                              p_from_lpn_id      IN NUMBER,
13452 			     p_parent_lpn_id    IN NUMBER,
13453                              p_transaction_type IN VARCHAR2,
13454                              x_return_status    OUT NOCOPY VARCHAR2,
13455                              x_msg_count        OUT NOCOPY NUMBER,
13456 		             x_msg_data         OUT NOCOPY VARCHAR2
13457 			     ) is
13458 
13459 				l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
13460 				l_progress VARCHAR2(15) := '10';
13461 				l_rti_qty  NUMBER;
13462 
13463 				l_serial_disc NUMBER;
13464 				l_outermost_lpn_id NUMBER;
13465 				l_dummy VARCHAR2(1);
13466 				l_lot_code NUMBER; --15959206
13467 Begin
13468 
13469    -- Initialize API return status to success
13470    x_return_status  := g_ret_sts_success;
13471 
13472    IF (l_debug = 1) THEN
13473       print_debug('VALIDATE_TOTAL_QTY: P_LPN_GROUP_ID = '||p_lpn_group_id,1);
13474       print_debug('VALIDATE_TOTAL_QTY: P_FROM_LPN_ID = '||p_from_lpn_id,1);
13475       print_debug('VALIDATE_TOTAL_QTY: P_PARENT_LPN_ID = '||p_parent_lpn_id,1);
13476       print_debug('VALIDATE_TOTAL_QTY: P_TRANSACTION_TYPE = '||p_transaction_type,1);
13477    END If;
13478 
13479    FOR l_outermost_lpn IN (SELECT lpn_id, license_plate_number,
13480 			   Nvl(parent_lpn_id, outermost_lpn_id) parent_lpn_id
13481 			   FROM wms_license_plate_numbers
13482 			   START WITH lpn_id = p_from_lpn_id
13483 			   CONNECT BY lpn_id = PRIOR parent_lpn_id)
13484      LOOP
13485 	l_outermost_lpn_id := l_outermost_lpn.lpn_id;
13486 
13487 	BEGIN
13488 	   SELECT '1'
13489 	     INTO l_dummy
13490 	     FROM wms_lpn_interface
13491 	     WHERE source_group_id = p_lpn_group_id
13492 	     AND (lpn_id = l_outermost_lpn.lpn_id
13493 		  OR license_plate_number = l_outermost_lpn.license_plate_number)
13494 	     AND Nvl(parent_lpn_id, -1) <> l_outermost_lpn.parent_lpn_id;
13495 
13496 	   EXIT;
13497 	EXCEPTION
13498 	   WHEN OTHERS THEN
13499 	      NULL;
13500 	END;
13501 
13502      END LOOP; --FOR l_outermost_lpn IN
13503 
13504    IF Nvl(p_transaction_type,'@@@') <> 'RECEIVE' THEN
13505       For l_wln_csr in (
13506                     select lpn_id lpn_id,
13507                            license_plate_number license_plate_number
13508                       from wms_license_plate_numbers wlpn
13509                       connect by prior wlpn.lpn_id = wlpn.parent_lpn_id
13510                       start with wlpn.lpn_id = l_outermost_lpn_id
13511                        )
13512       Loop
13513       For l_lpn_contents in (
13514 			     select
13515 			     wlc.parent_lpn_id lpn_id
13516 			     ,l_wln_csr.license_plate_number license_plate_number
13517 			     ,wlc.inventory_item_id inventory_item_id
13518 			     ,wlc.revision item_revision
13519 			     ,wlc.organization_id organization_id
13520 			     --,wlc.item_description item_description
13521 			     ,sum(get_primary_qty(wlc.organization_id, wlc.inventory_item_id, wlc.uom_code,nvl(wlc.quantity,0)))
13522 			     primary_quantity
13523 			     from  wms_lpn_contents wlc
13524                              where  wlc.parent_lpn_id = l_wln_csr.lpn_id
13525                              -- 4507808
13526                              -- Commented the exists statement below
13527                              -- by the l_wln_csr above.
13528 			     -- where  wlc.parent_lpn_id = wln.lpn_id
13529 			     -- AND exists ( select '1' from wms_license_plate_numbers wlpn
13530 			--		  where  wlc.parent_lpn_id = wlpn.lpn_id
13531 			--		  connect by prior wlpn.lpn_id = wlpn.parent_lpn_id
13532 			--		  start with wlpn.lpn_id = l_outermost_lpn_id
13533 					  --union all
13534 					  --select '1' from wms_license_plate_numbers wlpn1
13535 					  --where  wlc.parent_lpn_id = wlpn1.lpn_id
13536 					  --and not exists ( select 1 from wms_lpn_interface wlpni
13537 						--	   where wlpni.lpn_id = p_from_lpn_id and
13538 						--	   Nvl(wlpni.parent_lpn_id, -1) <> Nvl(p_parent_lpn_id, -1)
13539 						--	   )
13540 					  --connect by prior wlpn1.parent_lpn_id = wlpn1.lpn_id
13541 					  --start with wlpn1.lpn_id = p_from_lpn_id
13542 		 	--			  )
13543         group by
13544         wlc.parent_lpn_id
13545         ,l_wln_csr.license_plate_number
13546         ,wlc.inventory_item_id
13547         ,wlc.revision
13548         ,wlc.organization_id
13549         --,wlc.item_description
13550         )
13551         Loop
13552 	   IF (l_debug = 1) THEN
13553 	      print_debug('VALIDATE_TOTAL_QTY: Inventory_Item_Id = '||l_lpn_contents.inventory_item_id,1);
13554 	      print_debug('VALIDATE_TOTAL_QTY: Item_Revision = '||l_lpn_contents.item_revision,1);
13555 	      print_debug('VALIDATE_TOTAL_QTY: Primary_Quantity = '||l_lpn_contents.primary_quantity,1);
13556 	      print_debug('VALIDATE_TOTAL_QTY: License_Plate_Number = '||l_lpn_contents.license_plate_number,1);
13557 	   END If;
13558 
13559 	   -- THERE IS a PROBLEM HERE IF DIFFERENT UOM_CODES EXIST in WLC FOR THE SAME ITEM. ***********
13560 	   -- NOT YET CONVERTED UOM
13561 
13562 	   select sum(primary_quantity)
13563 	     into l_rti_qty
13564 	     from rcv_transactions_interface rti
13565 	     where rti.lpn_group_id = p_lpn_group_id
13566 	     and (rti.lpn_id = l_lpn_contents.lpn_id
13567 	     AND  rti.PROCESSING_STATUS_CODE <> 'WSH_INTERFACED'  --RTV Change 16197273
13568 		  OR rti.license_plate_number = l_lpn_contents.license_plate_number)
13569              -- 3397823
13570 	     -- and rti.transfer_lpn_id = l_lpn_contents.lpn_id
13571 	     and rti.item_id = l_lpn_contents.inventory_item_id
13572 	     and decode(rti.transaction_type,'ACCEPT','INSPECT','REJECT','INSPECT',rti.transaction_type)
13573 	     = decode(p_transaction_type,'ACCEPT','INSPECT','REJECT','INSPECT',p_transaction_type)
13574 	     and ( (l_lpn_contents.item_revision is null) or (rti.item_revision = l_lpn_contents.item_revision))
13575 	       --and ( (l_lpn_contents.item_description is null) or (rti.item_description = l_lpn_contents.item_description ))
13576 		 ;
13577 
13578 	     IF l_rti_qty IS NULL THEN
13579 		l_rti_qty := 0;
13580 	     END IF;
13581 
13582 	     IF (l_debug = 1) THEN
13583 		print_debug('VALIDATE_TOTAL_QTY: L_RTI_QTY = '||l_rti_qty,1);
13584 	     END If;
13585 
13586 	     --BUG 4939647 Need to round rti quantity to 5 decimals as we only store
13587 	     --5 decimals in lpn contents
13588 	     l_rti_qty := Round(l_rti_qty,5);
13589 
13590 	     -- Check the QUANTITY
13591 	     IF l_rti_qty <> 0 THEN
13592 		-- bug 4897277
13593 		-- Use absolute value of transaction qty for checking
13594 		IF ABS(l_rti_qty) <> l_lpn_contents.primary_quantity then
13595 		   IF (l_debug = 1) THEN
13596 		      print_debug('VALIDATE_TOTAL_QTY: QTY MISMATCH l_rti_qty = '|| to_char(l_rti_qty) || ' lpn qty ' ||
13597 				  to_char(l_lpn_contents.primary_quantity) , 1);
13598 		   END If;
13599 		   l_progress := 'WMSINB-17926';
13600 		   RAISE FND_API.G_EXC_ERROR;
13601 		End if;
13602 	     END IF;
13603 
13604         End Loop;
13605         End Loop; --l_wln_csr
13606     ELSE --IF Nvl(p_transaction_type,'@@@') <> 'RECEIVE' THEN
13607       For l_wln_csr in (
13608                     select lpn_id lpn_id,
13609                            license_plate_number license_plate_number
13610                       from wms_license_plate_numbers wlpn
13611                       connect by prior wlpn.lpn_id = wlpn.parent_lpn_id
13612                       start with wlpn.lpn_id = l_outermost_lpn_id
13613                        )
13614       Loop
13615       For l_lpn_contents in (
13616 			     select
13617 			     wlc.parent_lpn_id lpn_id
13618 			     ,l_wln_csr.license_plate_number license_plate_number
13619 			     ,wlc.inventory_item_id inventory_item_id
13620 			     ,wlc.revision item_revision
13621 			     ,wlc.organization_id organization_id
13622 			     --,wlc.item_description item_description
13623 			     ,wlc.lot_number lot_number
13624 			     ,sum(get_primary_qty(wlc.organization_id, wlc.inventory_item_id, wlc.uom_code,nvl(wlc.quantity,0)))
13625 			     primary_quantity
13626 			     from  wms_lpn_contents wlc
13627                              where  wlc.parent_lpn_id = l_wln_csr.lpn_id
13628                              -- 4507808
13629                              -- Commented the exists statement below
13630                              -- and replaced by the outer cursor l_wln_csr
13631 			     -- where  wlc.parent_lpn_id = wln.lpn_id
13632 			     -- AND exists ( select '1' from wms_license_plate_numbers wlpn
13633 			--		  where  wlc.parent_lpn_id = wlpn.lpn_id
13634 			--		  connect by prior wlpn.lpn_id = wlpn.parent_lpn_id
13635 			--		  start with wlpn.lpn_id = l_outermost_lpn_id
13636 					  --union all
13637 					  --select '1' from wms_license_plate_numbers wlpn1
13638 					  --where  wlc.parent_lpn_id = wlpn1.lpn_id
13639 					  --and not exists ( select 1 from wms_lpn_interface wlpni
13640 						--	   where wlpni.lpn_id = p_from_lpn_id and
13641 						--	   Nvl(wlpni.parent_lpn_id, -1) <> Nvl(p_parent_lpn_id, -1)
13642 						--	   )
13643 					  --connect by prior wlpn1.parent_lpn_id = wlpn1.lpn_id
13644 					  --start with wlpn1.lpn_id = p_from_lpn_id
13645 				--	  )
13646 	group by
13647 	wlc.parent_lpn_id
13648 	,l_wln_csr.license_plate_number
13649 	,wlc.inventory_item_id
13650 	,wlc.revision
13651 	,wlc.organization_id
13652 	--,wlc.item_description
13653 	,wlc.lot_number
13654 	)
13655 	Loop
13656 
13657 	 IF inv_cache.set_item_rec(l_lpn_contents.organization_id , l_lpn_contents.inventory_item_id) THEN --15959206
13658            l_lot_code := inv_cache.item_rec.lot_control_code;
13659      END IF;
13660 	   -- THERE IS a PROBLEM HERE IF DIFFERENT UOM_CODES EXIST in WLC FOR THE SAME ITEM. ***********
13661 	   -- NOT YET CONVERTED UOM
13662 	    IF l_lot_code = 1 THEN --15959206
13663 	      select sum(primary_quantity)
13664 		into l_rti_qty
13665 		from rcv_transactions_interface rti
13666 		where rti.lpn_group_id = p_lpn_group_id
13667 		and (rti.lpn_id = l_lpn_contents.lpn_id
13668 		     OR rti.license_plate_number = l_lpn_contents.license_plate_number)
13669                 -- 3397823
13670 		--and rti.transfer_lpn_id = l_lpn_contents.lpn_id
13671 		and rti.item_id = l_lpn_contents.inventory_item_id
13672 		and decode(rti.transaction_type,'ACCEPT','INSPECT','REJECT','INSPECT',rti.transaction_type)
13673 		= decode(p_transaction_type,'ACCEPT','INSPECT','REJECT','INSPECT',p_transaction_type)
13674 		and ( (l_lpn_contents.item_revision is null) or (rti.item_revision = l_lpn_contents.item_revision))
13675 		  --and ( (l_lpn_contents.item_description is null) or (rti.item_description = l_lpn_contents.item_description ))
13676 		    AND l_lpn_contents.lot_number IS NULL;
13677 	    ELSE --IF l_lpn_contents.lot_number IS NULL THEN
13678 	      select sum(mtli.primary_quantity)
13679 		into l_rti_qty
13680 		from rcv_transactions_interface rti
13681 		, mtl_transaction_lots_interface mtli
13682 		where rti.lpn_group_id = p_lpn_group_id
13683 		and (rti.lpn_id = l_lpn_contents.lpn_id
13684 		     OR rti.license_plate_number = l_lpn_contents.license_plate_number)
13685                 -- 3397823
13686 		-- and rti.transfer_lpn_id = l_lpn_contents.lpn_id
13687 		and rti.item_id = l_lpn_contents.inventory_item_id
13688 		and decode(rti.transaction_type,'ACCEPT','INSPECT','REJECT','INSPECT',rti.transaction_type)
13689 		= decode(p_transaction_type,'ACCEPT','INSPECT','REJECT','INSPECT',p_transaction_type)
13690 		and ( (l_lpn_contents.item_revision is null) or (rti.item_revision = l_lpn_contents.item_revision))
13691 		  --and ( (l_lpn_contents.item_description is null) or (rti.item_description = l_lpn_contents.item_description ))
13692 		    AND l_lpn_contents.lot_number = mtli.lot_number
13693 		    AND mtli.product_code = 'RCV'
13694 		    AND mtli.product_transaction_id = rti.interface_transaction_id
13695 		    ;
13696 	   END IF; --IF l_lpn_contents.lot_number IS NULL THEN
13697 
13698 	   IF (l_rti_qty IS NULL) THEN
13699 	      l_rti_qty := 0;
13700 	   END IF;
13701 
13702 	   IF (l_debug = 1) THEN
13703 	      print_debug('VALIDATE_TOTAL_QTY: L_RTI_QTY = '||l_rti_qty,1);
13704 	   END If;
13705 
13706 	   --BUG 4939647 Need to round rti quantity to 5 decimals as we only store
13707 	   --5 decimals in lpn contents
13708 	   l_rti_qty := Round(l_rti_qty,5);
13709 
13710 	   -- Check the QUANTITY
13711           /* Bug 5616019.
13712            * We need to validate the quantities even when l_rti_qty is zero.
13713            * Commenting out the if condition.
13714            * IF (l_rti_qty <> 0) THEN
13715           */
13716 
13717 	      if l_rti_qty <> l_lpn_contents.primary_quantity then
13718 		 IF (l_debug = 1) THEN
13719 		    print_debug('VALIDATE_TOTAL_QTY: QTY MISMATCH l_rti_qty = '|| to_char(l_rti_qty) || ' lpn qty ' ||
13720 				to_char(l_lpn_contents.primary_quantity) , 1);
13721 		 END If;
13722 		 l_progress := 'WMSINB-17927';
13723 		 RAISE FND_API.G_EXC_ERROR;
13724 	      End if;
13725           /* Bug 5616019.
13726            * END IF;
13727           */
13728 
13729 	   l_serial_disc := 1;
13730 
13731 	   For l_test_serial_rec in (
13732 				     select serial_number
13733 				     from mtl_serial_numbers msn
13734 				     WHERE msn.lpn_id = l_lpn_contents.lpn_id
13735 				     AND msn.inventory_item_id = l_lpn_contents.inventory_item_id
13736 				     )
13737 	     Loop
13738 		BEGIN
13739 		   SELECT 1
13740 		     INTO l_serial_disc
13741 		     FROM mtl_serial_numbers_interface msni
13742 		     , rcv_transactions_interface rti
13743 		     where rti.lpn_group_id = p_lpn_group_id
13744 		     and (rti.lpn_id = l_lpn_contents.lpn_id
13745 			  OR rti.license_plate_number = l_lpn_contents.license_plate_number)
13746                      -- 3397823
13747 		     -- and rti.transfer_lpn_id = l_lpn_contents.lpn_id
13748 		     and rti.item_id = l_lpn_contents.inventory_item_id
13749 		     AND msni.product_code = 'RCV'
13750 		     AND msni.product_transaction_id = rti.interface_transaction_id
13751 		     and l_test_serial_rec.serial_number between msni.fm_serial_number and msni.to_serial_number
13752 		     AND Length(l_test_serial_rec.serial_number) = Length(msni.fm_serial_number)
13753 		     AND length(msni.fm_serial_number)=Length(Nvl(msni.to_serial_number,msni.fm_serial_number))  --BUG 3818544
13754 		     and rownum = 1
13755 		     ;
13756 		EXCEPTION
13757 		   WHEN others THEN
13758 		      IF (l_debug = 1) THEN
13759 			 print_debug('VALIDATE_TOTAL_QTY: Serial Mismatched is '|| l_test_serial_rec.serial_number , 1);
13760 		      END If;
13761 		      l_serial_disc := 0;
13762 		      exit;
13763 		END;
13764 	     End Loop;
13765 
13766 	     if l_serial_disc = 0 then
13767 		IF (l_debug = 1) THEN
13768 		   print_debug('VALIDATE_TOTAL_QTY: validate serial mismatch' , 1);
13769 		END If;
13770 		l_progress := 'WMSINB-17928';
13771 		RAISE FND_API.G_EXC_ERROR;
13772 	     End if;
13773 	End Loop;
13774         End Loop; -- l_wln_csr
13775    END IF; --IF Nvl(p_transaction_type,'@@@') <> 'RECEIVE' THEN
13776 
13777 Exception
13778    when fnd_api.g_exc_error THEN
13779       x_return_status  := g_ret_sts_error;
13780 
13781    when others then
13782       x_return_status  := g_ret_sts_unexp_error;
13783       IF (l_debug = 1) THEN
13784          print_debug('validate_quantity - other exception:'|| l_progress || ' ' ||
13785 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
13786       END IF;
13787       IF SQLCODE IS NOT NULL THEN
13788 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.validate_quantity',l_progress, SQLCODE);
13789       END IF;
13790       --  Get message count and data
13791       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
13792 End validate_total_qty;
13793 
13794 PROCEDURE VALIDATE_LPN_INFO(p_lpn_group_id     IN         NUMBER,
13795 			    x_return_status    OUT NOCOPY VARCHAR2,
13796 			    x_msg_count        OUT NOCOPY NUMBER,
13797 			    x_msg_data         OUT NOCOPY VARCHAR2)
13798   is
13799      cursor c_validate_lpn is
13800 	select interface_transaction_id
13801 	  ,transaction_type
13802 	  ,item_id
13803 	  ,item_description
13804 	  ,lpn_id
13805 	  ,transfer_lpn_id
13806 	  ,license_plate_number
13807 	  ,transfer_license_plate_number
13808 	  ,quantity
13809 	  ,shipment_header_id
13810 	  ,shipment_num
13811 	  ,routing_header_id
13812 	  ,to_organization_id
13813 	  ,nvl(from_organization_id,to_organization_id) from_organization_id -- This is needed
13814 	  ,subinventory                   -- as for some txns like ASN Receive, TRANSFER, DELIVER
13815 	  ,locator_id                     -- the from organization_id is null in rti
13816 	  ,from_subinventory              -- so we have to take the to_organization_id
13817 	  ,from_locator_id
13818 	  ,parent_transaction_id
13819 	  ,source_document_code
13820 	  ,auto_transact_code
13821 	  ,Nvl(mobile_txn, 'N') mobile_txn
13822 	  ,processing_mode_code
13823 	  ,inv_transaction_id
13824 	  ,mmtt_temp_id
13825       ,Nvl(express_transaction,'N') express_transaction --Bug 5550783
13826 	  ,item_revision   -- bug 13938607
13827       ,uom_code
13828       ,validation_flag
13829       ,interface_source_line_id --RTV Change 16197273
13830 	  from rcv_transactions_interface rti
13831 	  where rti.lpn_group_id = p_lpn_group_id
13832 	  AND PROCESSING_STATUS_CODE <> 'WSH_INTERFACED' --RTV Change  16197273
13833 	  order by interface_transaction_id;
13834 
13835      cursor c_child_lpn(p_child_lpn_id varchar2) is
13836 	select lpn_id
13837 	  ,license_plate_number
13838 	  from wms_license_plate_numbers
13839 	  where outermost_lpn_id = p_child_lpn_id;
13840 
13841      l_child_lpn_rec c_child_lpn%rowtype;
13842 
13843      cursor c_immd_child_lpn(p_child_lpn_id varchar2) is
13844 	select lpn_id
13845 	  ,license_plate_number
13846 	  from wms_license_plate_numbers
13847 	  where parent_lpn_id = p_child_lpn_id;
13848 
13849      l_immd_child_rec c_immd_child_lpn%rowtype;
13850 
13851      cursor c_lpn_contents(p_child_lpn_id varchar2) is
13852 	select parent_lpn_id
13853 	  ,inventory_item_id
13854 	  ,quantity
13855 	  from wms_lpn_contents
13856 	  where parent_lpn_id = p_child_lpn_id;
13857 
13858      l_lpn_contents_rec c_lpn_contents%rowtype;
13859 
13860 
13861      l_lpn_rec c_validate_lpn%rowtype;
13862 
13863      l_progress varchar2(15) := '00';
13864 
13865      l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
13866 
13867      l_source_header_id NUMBER;
13868      l_asn_type VARCHAR2(10);
13869      l_lpn_context NUMBER;
13870      l_transfer_lpn_context NUMBER;
13871      l_to_lpn_context NUMBER;
13872      l_wlpni_exists NUMBER;
13873      l_insp_mat_exists NUMBER;
13874      l_rti_quantity NUMBER;
13875 
13876      l_msg_count number;
13877      l_msg_data VARCHAR2(2000);
13878 
13879      l_WLPNIQLPN    VARCHAR2(30);
13880      l_WLPNIQLPN_ID NUMBER;
13881      l_WLPNIQLPN_PARENT_LPN_ID NUMBER;
13882 
13883      l_PTLPN    VARCHAR2(30);
13884      l_PTLPN_ID NUMBER;
13885      l_PTLPN_CONTEXT NUMBER;
13886      l_PTLPN_EXISTS NUMBER;
13887 
13888      l_P_PTLPN    VARCHAR2(30);
13889      l_P_PTLPN_ID NUMBER;
13890 
13891      l_from_lpn_state BOOLEAN;
13892      l_to_lpn_state BOOLEAN;
13893      l_lpn_state BOOLEAN;
13894      l_lpn_match varchar2(1);
13895 
13896      l_parent_txn_type varchar2(30);
13897      l_parent_parent_txn_id NUMBER;
13898      l_parent_parent_parent_txn_id NUMBER;
13899      l_parent_parent_txn_type VARCHAR2(30);
13900 
13901      l_rs_ptid_ptid_lpn_id NUMBER;    -- Variable to hold the lpn_id from rcv_supply for parent_parent_txn_id
13902      l_rs_ptid_ptid_exists Boolean;   -- Variable to indicate whether their Exists a supply for the Parent_parent_txn_Id
13903 
13904      l_rs_ptid_ptid_ptid_lpn_id NUMBER;   -- Variable to hold the lpn_id from rcv_supply for parent_parent_txn_id
13905      l_rs_ptid_ptid_ptid_exists Boolean;  -- Variable to indicate whether their
13906      --  Exists a supply for the Parent parent txn Id and the Tranfer LPN
13907 
13908      l_rs_ptid_lpn_id NUMBER;  -- Variable to hold the lpn_id from rcv_supply for parent_txn_id
13909      l_rs_ptid_exists Boolean;   -- Variable to indicate whether their Exists a supply for the parent txn Id
13910 
13911 
13912      l_cur_from_parent_lpn_id NUMBER;
13913      l_cur_to_parent_lpn_id NUMBER;
13914      l_cur_PTLPN_parent_lpn_id NUMBER;
13915 
13916 
13917      l_wlpni_state BOOLEAN;
13918      l_wlpni_lpn   VARCHAR2(30);
13919      l_wlpni_parent_lpn varchar2(30);
13920      l_wlpni_lpn_id NUMBER;
13921      l_wlpni_parent_lpn_id NUMBER;
13922      l_wlpni_lpn_context NUMBER;
13923      l_wlpni_cur_parent_lpn NUMBER;
13924 
13925      l_wlpni_parent_state BOOLEAN;
13926      l_wlpni_parent_lpn_context NUMBER;
13927      l_wlpni_cur_parent_parent_lpn NUMBER;
13928 
13929      l_validate_sub VARCHAR2(10);
13930      l_validate_loc_id NUMBER;
13931 
13932      l_parent_lpn_context NUMBER;
13933      l_parent_source_name VARCHAR2(30);
13934      l_parent_source_header_id NUMBER;
13935      l_parent_source_type_id NUMBER;
13936 
13937      l_update_lpn_id BOOLEAN := FALSE;
13938 
13939      l_miss_num NUMBER := FND_API.G_MISS_NUM;
13940      l_miss_char VARCHAR2(1) := FND_API.G_MISS_CHAR;
13941 
13942      l_lpn_count NUMBER;
13943 
13944      l_asn_source_header_id NUMBER;
13945      l_asn_source_type_id   NUMBER;
13946 
13947      l_lpn_already_processed NUMBER;
13948 
13949      l_parent_sub VARCHAR2(10);
13950      l_parent_locator_id NUMBER;
13951      l_parent_to_organization_id NUMBER;
13952 
13953      l_intransit_type NUMBER := 0;
13954 
13955      l_wlpn_source_header_id NUMBER;
13956      l_xfr_wlpn_source_header_id NUMBER;
13957 
13958      --R12
13959      l_lpn_grp_id                   NUMBER;
13960      l_epc_column                   VARCHAR2(30);
13961      l_epc_value                    VARCHAR2(100);
13962      l_return_status                VARCHAR2(1);
13963      validate_lpn_id                NUMBER;  --Bug:13613257
13964      --R12
13965 
13966 	    -- ADDED FOR BUG 13938607
13967         v_return_status VARCHAR2(1) := 'S';
13968         v_msg_count NUMBER;
13969         v_msg_data VARCHAR2(2000);
13970         l_return_val BOOLEAN;
13971 
13972 BEGIN
13973 
13974    x_return_status := g_ret_sts_success;
13975 
13976    IF (l_debug = 1) THEN
13977       print_debug('VALIDATE_LPN_INFO Entered...:'|| l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
13978    END If;
13979 
13980    l_progress := 'WMSINB-18089';
13981 
13982    -- Opens Cursor on RTI based on lpn_group_id
13983    open c_validate_lpn;
13984    Loop
13985       fetch c_validate_lpn into l_lpn_rec;
13986       exit when c_validate_lpn%notfound;
13987 
13988       IF (l_debug = 1) THEN
13989          print_debug('VALIDATE_LPN_INFO - Express Transaction :'||l_lpn_rec.express_transaction, 1);--Bug 5550783
13990          print_debug('VALIDATE_LPN_INFO - Transaction type :'||l_lpn_rec.transaction_type||':'||l_progress, 1);
13991       END If;
13992 
13993 
13994 	        		-- added for bug 13938607
13995                 IF(l_lpn_rec.validation_flag='Y' AND l_lpn_rec.mobile_txn='N' AND l_lpn_rec.lpn_id IS NOT NULL) THEN
13996                     IF(l_lpn_rec.transaction_type IN('RETURN TO VENDOR', 'RETURN TO RECEIVING')) THEN
13997 
13998                    l_return_val := INV_CACHE.set_item_rec(l_lpn_rec.item_id,l_lpn_rec.from_organization_id);
13999 
14000                          WMS_RETURN_SV.mark_returns(
14001                                     v_return_status,
14002                                     v_msg_count,
14003                                     v_msg_data,
14004                                     l_lpn_rec.interface_transaction_id,
14005                                     l_lpn_rec.transaction_type,    --transaction_type
14006                                     l_lpn_rec.lpn_id,              --lpn_id
14007                                     l_lpn_rec.item_id,             --item_id
14008                                     l_lpn_rec.item_revision,       --item_revision
14009                                     l_lpn_rec.quantity,            --quantity
14010                                     l_lpn_rec.uom_code,             --uom_code
14011                                     INV_CACHE.item_rec.serial_number_control_code,       --serial_control_code
14012                                     INV_CACHE.item_rec.lot_control_code,       --lot_control_code
14013                                     l_lpn_rec.from_organization_id,    --organization_id
14014                                     l_lpn_rec.from_subinventory,    --from_subinventory_code
14015                                     l_lpn_rec.from_locator_id);   --from_locator_id
14016                         IF x_return_status <> 'S' THEN
14017                            IF (l_debug        = 1) THEN
14018 					           print_debug('WMS_RETURN_SV.mark_returns Failed with Error : ' || x_msg_data||' : '||l_progress, 1);
14019 				           END IF;
14020 				           RAISE FND_API.G_EXC_ERROR;
14021                         END IF;
14022 
14023                     END IF;
14024                 END IF;
14025                 -- added for bug 13938607
14026 
14027 	  /*
14028       Changes to  validate the LPN to restrict multiple users doing transactions on same LPN
14029       Added for the Bug:13613257
14030       */
14031 
14032       validate_lpn_id := 0;
14033 
14034 	  IF (l_lpn_rec.transaction_type = 'RECEIVING' AND l_lpn_rec.transfer_lpn_id IS NOT NULL ) THEN
14035 		validate_lpn_id                := l_lpn_rec.transfer_lpn_id;
14036 	  ELSIF (l_lpn_rec.transaction_type = 'INSPECTION' OR
14037 	  (
14038 		l_lpn_rec.transaction_type IN ('CORRECT','RETURN TO VENDOR','RETURN TO RECEIVING', 'RETURN TO CUSTOMER') AND l_parent_txn_type ='INSPECT'
14039 	  )
14040 	  ) THEN
14041 		IF (l_lpn_rec.lpn_id             IS NOT NULL ) THEN
14042 			validate_lpn_id                := l_lpn_rec.lpn_id;
14043 		END IF;
14044 		IF (l_lpn_rec.transfer_lpn_id IS NOT NULL ) THEN
14045 			Validate_Receiving_LPN(l_lpn_rec.transfer_lpn_id,
14046 								   l_lpn_rec.routing_header_id,
14047 								   x_return_status,
14048 								   x_msg_count,
14049 								   x_msg_data) ;
14050 
14051 			IF (x_return_status <> g_ret_sts_success ) THEN
14052 			    IF (l_debug        = 1) THEN
14053 					print_debug('Validate_Receiving_LPN - LPN Validation failed : '||l_lpn_rec.lpn_id||' : '||l_progress, 1);
14054 				END IF;
14055 				RAISE FND_API.G_EXC_ERROR;
14056 			END IF ;
14057 
14058 		END IF ;
14059 	  ELSIF (l_lpn_rec.transaction_type = 'CORRECT' ) THEN
14060 		IF (l_parent_txn_type           = 'RECEIVING' AND l_lpn_rec.transfer_lpn_id IS NOT NULL ) THEN
14061 			validate_lpn_id              := l_lpn_rec.transfer_lpn_id;
14062 		ELSIF (l_parent_txn_type        = 'DELIVER' AND l_lpn_rec.lpn_id IS NOT NULL) THEN
14063 			validate_lpn_id := l_lpn_rec.lpn_id;
14064 		END IF ;
14065 	  ELSIF (l_lpn_rec.transaction_type IN ('RETURN TO VENDOR','RETURN TO RECEIVING','RETURN TO CUSTOMER')) THEN
14066   	    IF (l_parent_txn_type    = 'RECEIVING' AND l_lpn_rec.lpn_id IS NOT NULL ) THEN
14067 			validate_lpn_id       := l_lpn_rec.lpn_id;
14068 	    ELSIF (l_parent_txn_type = 'DELIVER' AND l_lpn_rec.transfer_lpn_id IS NOT NULL ) THEN
14069 			validate_lpn_id := l_lpn_rec.transfer_lpn_id;
14070 	    END IF ;
14071 	  END IF ;
14072 
14073 	  IF (validate_lpn_id>0) THEN
14074 		  Validate_Receiving_LPN(validate_lpn_id,
14075 								 l_lpn_rec.routing_header_id,
14076 								 x_return_status,
14077 								 x_msg_count,
14078 								 x_msg_data) ;
14079 
14080 		  IF (x_return_status <> g_ret_sts_success ) THEN
14081 			  IF (l_debug        = 1) THEN
14082 				print_debug('Validate_Receiving_LPN - LPN Validation failed : '||l_lpn_rec.lpn_id||' : '||l_progress, 1);
14083 			  END IF;
14084 			  RAISE FND_API.G_EXC_ERROR;
14085 		  END IF ;
14086 	  END IF;
14087 
14088 
14089       --END Changes for  the Bug:13613257
14090 
14091 
14092       --If the source document is 'REQ' then of the intransit_type in
14093       --mtl_interorg_parameters is set to 'Direct' then exit from this api.
14094       IF (l_lpn_rec.source_document_code = 'REQ'
14095 	  AND l_lpn_rec.mobile_txn = 'N'
14096 	  AND l_lpn_rec.transaction_type = 'RECEIVE'
14097 	  AND l_lpn_rec.inv_transaction_id IS NOT NULL
14098 	  AND l_lpn_rec.processing_mode_code = 'ONLINE') THEN
14099 	 BEGIN
14100 	    SELECT intransit_type
14101 	      INTO l_intransit_type
14102 	      FROM mtl_interorg_parameters
14103 	      WHERE from_organization_id = l_lpn_rec.from_organization_id
14104 	      AND to_organization_id = l_lpn_rec.to_organization_id;
14105 
14106 	    IF (l_intransit_type = 1) THEN
14107 	       print_debug('VALIDATE_LPN_INFO: Direct Org Transfer ... Exitting...',1);
14108 	       EXIT;
14109 	    END IF;
14110 	 EXCEPTION
14111 	    WHEN OTHERS THEN
14112 	       NULL;
14113 	 END;
14114       END IF; --IF (l_lpn_rec.source_document_code = 'REQ') THEN
14115 
14116       -- Set the ASN variables to null
14117       l_asn_source_header_id := null;
14118       l_asn_source_type_id := null;
14119 
14120       IF ( l_lpn_rec.item_id IS NOT NULL OR l_lpn_rec.item_description IS NOT NULL ) THEN
14121 
14122 	 IF (l_debug = 1) THEN
14123 	    print_debug('VALIDATE_LPN_INFO - item id or description is not null:'||l_lpn_rec.item_id||':'||l_lpn_rec.item_description, 1);
14124 	 END If;
14125 
14126 	 IF ((l_lpn_rec.item_id IS NULL)
14127 	     AND (l_lpn_rec.lpn_id IS NOT NULL
14128 		  OR l_lpn_rec.license_plate_number IS NOT NULL
14129 		  OR l_lpn_rec.transfer_lpn_id IS NOT NULL
14130 		  OR l_lpn_rec.transfer_license_plate_number IS NOT NULL))
14131 		    THEN
14132 	    IF (l_debug = 1) THEN
14133 	       print_debug('VALIDATE_LPN_INFO: LPNS are not supported for one time items.',1);
14134 	    END IF;
14135 	    l_progress := 'WMSINB-18116';
14136 	    RAISE fnd_api.g_exc_error;
14137 	 END IF;
14138 
14139 	 IF NVL(l_lpn_rec.quantity,0) = 0 THEN
14140 	    --
14141 	    -- Quantity is null so failure return from Here
14142 	    --
14143 	    IF (l_debug = 1) THEN
14144 	       print_debug('VALIDATE_LPN_INFO lpn/item Qty is null or zero  for this lpn id:'|| l_lpn_rec.lpn_id , 1);
14145 	       print_debug('VALIDATE_LPN_INFO lpn/item Qty is null or zero for this lpn :'|| l_lpn_rec.license_plate_number, 1);
14146 	    END If;
14147 
14148 	    l_progress := 'WMSINB-18129';
14149 	    x_return_status := g_ret_sts_error;
14150 
14151 	    -- Review Later
14152 	    -- Set appropiate Message
14153 
14154             RAISE FND_API.G_EXC_ERROR;
14155          End if;
14156 
14157 	 -- Quantity is not null so proceed with this row
14158 
14159 	 IF (l_debug = 1) THEN
14160 	    print_debug('VALIDATE_LPN_INFO - Quantity:'||l_lpn_rec.quantity, 1);
14161 	 END If;
14162 
14163 	 -- Initialize Variables
14164 	 l_source_header_id := null;
14165 	 l_asn_type := null;
14166 	 l_lpn_context := null;
14167 	 l_wlpni_exists := 0;
14168 
14169 	 -- See if we need to update the lpn_id or transfer_lpn_id in rti.
14170 	 IF ((l_lpn_rec.lpn_id IS NULL AND l_lpn_rec.license_plate_number IS NOT NULL)
14171 	     OR (l_lpn_rec.transfer_lpn_id IS NULL AND l_lpn_rec.transfer_license_plate_number IS NOT NULL)) THEN
14172 	    l_update_lpn_id := TRUE;
14173 	 END IF;
14174 
14175 	 -- **************************************************************
14176 	 -- Get THE LPN DETAILS for FROM and TRASNFER LPN
14177 	 -- **************************************************************
14178 
14179 	 l_progress := 'WMSINB-18160';
14180 
14181 	 l_from_lpn_state := get_lpn_id(l_lpn_rec.lpn_id,
14182 					l_lpn_rec.license_plate_number,
14183 					l_lpn_context,
14184 					l_cur_from_parent_lpn_id,
14185 					l_wlpn_source_header_id);
14186 
14187 	 if (l_from_lpn_state <> TRUE) then
14188 	    IF (l_debug = 1) THEN
14189 	       print_debug('VALIDATE_LPN_INFO: lpn_id and license_plate number does not exist' , 1);
14190 	    END If;
14191 	    -- Review Later.
14192 	    -- Set Appropiate MESSAGE For ERROR
14193 	    --
14194 	    l_progress := 'WMSINB-18171';
14195 	    RAISE FND_API.G_EXC_ERROR;
14196 	 End if;
14197 
14198 	 IF (l_debug = 1) THEN
14199 	    print_debug('VALIDATE_LPN_INFO - LPN ID:'||l_lpn_rec.lpn_id,1);
14200 	    print_debug('VALIDATE_LPN_INFO - LPN NAME:'||l_lpn_rec.license_plate_number,1);
14201 	    print_debug('VALIDATE_LPN_INFO - LPN Context:'||l_lpn_context,1);
14202 	    print_debug('VALIDATE_LPN_INFO - LPN Parent:'||l_cur_from_parent_lpn_id,1);
14203 	 END If;
14204 
14205 	 --
14206 	 -- Call get_lpn_id to get the transfer lpn detials
14207 	 --
14208 	 l_progress := 'WMSINB-18185';
14209 
14210 	 l_to_lpn_state := get_lpn_id(l_lpn_rec.transfer_lpn_id,
14211 				      l_lpn_rec.transfer_license_plate_number,
14212 				      l_transfer_lpn_context,
14213 				      l_cur_to_parent_lpn_id,
14214 				      l_xfr_wlpn_source_header_id);
14215 
14216 	 if (l_to_lpn_state <> TRUE ) then
14217 	    IF (l_debug = 1) THEN
14218 	       print_debug('VALIDATE_LPN_INFO: lpn_id and license_plate number does not exist' , 1);
14219 	    END If;
14220 	    -- EXISTING LPN_ID and LPN Combination is INVALID
14221 	    -- Review Later.
14222 	    -- Set Appropiate MESSAGE For ERROR
14223 	    --
14224 	    l_progress := 'WMSINB-18200';
14225 	    RAISE fnd_api.g_exc_error;
14226 	 End if;
14227 
14228 	 IF (l_debug = 1) THEN
14229 	    print_debug('VALIDATE_LPN_INFO - Transfer LPN ID:'||l_lpn_rec.transfer_lpn_id,1);
14230 	    print_debug('VALIDATE_LPN_INFO - Transfer LPN NAME:'||l_lpn_rec.transfer_license_plate_number,1);
14231 	    print_debug('VALIDATE_LPN_INFO - Transfer LPN Context:'||l_transfer_lpn_context, 1);
14232 	    print_debug('VALIDATE_LPN_INFO - Transfer LPN Parent:'||l_cur_to_parent_lpn_id,1);
14233 	 END If;
14234 
14235 	 l_progress := 'WMSINB-18211';
14236 
14237 	 if ( ( l_lpn_rec.transaction_type in ( 'RECEIVE', 'ACCEPT','REJECT','DELIVER','TRANSFER') ) or
14238 	      ( l_lpn_rec.transaction_type = 'SHIP' and l_lpn_rec.source_document_code = 'PO') ) then
14239 
14240 
14241 	    -- FROM LPN VALIDATION
14242 	    if (l_from_lpn_state = TRUE) then
14243 	       l_progress := 'WMSINB-18219';
14244 	       if l_lpn_rec.transaction_type in ( 'RECEIVE', 'ACCEPT','REJECT','DELIVER','TRANSFER') then
14245 		  if l_lpn_rec.lpn_id is null and l_lpn_rec.license_plate_number is not null then
14246 		     -- INVALID LPN or non EXISTENT LPN IN THE SYSTEM
14247 		     l_progress := 'WMSINB-18223';
14248 		     RAISE fnd_api.g_exc_error;
14249 		  End if;
14250 	       End if;
14251 	    End if;
14252 
14253 	    l_progress := 'WMSINB-18229';
14254 
14255 	    if ( l_lpn_rec.transaction_type = 'SHIP') then
14256 
14257                -- Check whether it is already processed in the same LPN Group then by pass this step
14258                -- as the context now updated properly by the previous loop
14259                -- This is based on the order by given in lpn_validation loop..
14260                -- if you change the order by in lpn validation loop then change here also..
14261 
14262                l_lpn_already_processed := 0;
14263 
14264                select count(distinct interface_transaction_id)
14265                  into l_lpn_already_processed
14266                  from rcv_transactions_interface rti
14267                 where rti.lpn_group_id = p_lpn_group_id
14268                   and ( ( rti.lpn_id = l_lpn_rec.lpn_id) or (rti.license_plate_number = l_lpn_rec.license_plate_number))
14269                   and rti.interface_transaction_id < l_lpn_rec.interface_transaction_id ;
14270 
14271 	       IF l_lpn_rec.lpn_id is not null THEN
14272 		  IF (l_debug = 1) THEN
14273 		     print_debug('VALIDATE_LPN_INFO - l_lpn_already_processed:'||l_lpn_already_processed,1);
14274 		     print_debug('VALIDATE_LPN_INFO - Shipment Header ID:'||l_lpn_rec.shipment_header_id,1);
14275 		     print_debug('VALIDATE_LPN_INFO - Source Header ID:'||l_wlpn_source_header_id,1);
14276 		  END IF;
14277                   IF (l_lpn_already_processed >= 1
14278 		      OR (l_wlpn_source_header_id =
14279 			  l_lpn_rec.shipment_header_id)) then
14280 		     -- don't need to do any validation
14281 		     IF (l_debug = 1) THEN
14282 			print_debug('VALIDATE_LPN_INFO - LPN Context already validated: '||l_lpn_rec.lpn_id,1);
14283 		     END If;
14284 		     l_progress := 'WMSINB-18230';
14285 		   ELSE
14286 		     IF ( l_lpn_context <> G_LPN_CONTEXT_PREGENERATED ) THEN
14287 			-- FAIL TRANSACTIONS
14288 			-- for SHIP TXNS it should be 6, whereas for ASN's it shoubd be 5
14289 			-- REVIEW LATER
14290 			l_progress := 'WMSINB-18237';
14291 			RAISE FND_API.G_EXC_ERROR;
14292 		     END IF;
14293                   END IF;
14294 		Else
14295 		  l_progress := 'WMSINB-18241';
14296 		  -- Create LPN Here
14297 		  if l_lpn_rec.license_plate_number is not null then
14298 
14299 		     l_progress := 'WMSINB-18244';
14300 
14301                      -- Set the ASN Variables Here
14302 	             if ( l_lpn_rec.transaction_type = 'SHIP'
14303                          and l_lpn_rec.source_document_code = 'PO' ) then
14304                         l_asn_source_header_id := l_lpn_rec.shipment_header_id;
14305                         l_asn_source_type_id   := 1;
14306                      Else
14307                         l_asn_source_header_id := null;
14308                         l_asn_source_type_id   := null;
14309                      End if;
14310 
14311 		     l_progress := 'WMSINB-18245';
14312 
14313 		     create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.license_plate_number,
14314 					   p_lpn_group_id => p_lpn_group_id,
14315 					   p_organization_id => l_lpn_rec.to_organization_id,
14316 					   p_lpn_context => G_LPN_CONTEXT_VENDOR , -- Context should be RESIDES IN VENDOR THIS CASE.
14317                                            p_source_header_id => l_asn_source_header_id,
14318                                            p_source_type_id   => l_asn_source_type_id,
14319 					   x_lpn_id => l_lpn_rec.lpn_id,
14320 					   x_return_status => x_return_status,
14321 					   x_msg_count => l_msg_count,
14322 					   x_msg_data => l_msg_data);
14323 		     -- Check the error status from the above call
14324 		     if x_return_status <> G_RET_STS_SUCCESS Then
14325 			--  Review Late Set Appropiate Message
14326 			l_progress := 'WMSINB-18256';
14327 			RAISE FND_API.G_EXC_ERROR;
14328 		     End if;
14329 
14330 		     IF (l_lpn_rec.transaction_type = 'SHIP' AND l_lpn_rec.source_document_code = 'PO') THEN
14331 			IF (l_debug = 1) THEN
14332 			   print_debug('Need to call populate_outside_epc for asn import',4);
14333 			END IF;
14334 
14335 			get_epc_info(p_mode        => 1
14336 				     ,p_lpn        => l_lpn_rec.license_plate_number
14337 				     ,p_src_grp_id => p_lpn_group_id
14338 				     ,x_epc_column => l_epc_column
14339 				     ,x_epc_value  => l_epc_value
14340 				     );
14341 
14342 			IF (l_debug = 1) THEN
14343 			   print_debug('l_epc_column:'||l_epc_column||' l_epc_value:'||l_epc_value,4);
14344 			END IF;
14345 
14346 			IF (l_epc_column IS NOT NULL) THEN
14347 			   IF (Nvl(g_lpn_group_id,-999) <> p_lpn_group_id) THEN
14348 			      g_lpn_group_id := p_lpn_group_id;
14349 			      SELECT wms_epc_s2.NEXTVAL
14350 				INTO g_epc_group_id
14351 				FROM dual;
14352 			   END IF;
14353 
14354 			   IF (l_debug = 1) THEN
14355 			      print_debug('Calling populate_outside_epc',4);
14356 			      print_debug(' p_group_id       => '||g_epc_group_id,4);
14357 			      print_debug(' p_cross_ref_type => '||1,4);
14358 			      print_debug(' p_epc            => '||l_epc_value,4);
14359 			      print_debug(' p_Lpn_id         => '||l_lpn_rec.lpn_id,4);
14360 			   END IF;
14361 
14362 			   wms_epc_pvt.populate_outside_epc
14363 			     (p_group_id        => g_epc_group_id
14364 			      ,p_cross_ref_type => 1 --LPN-EPC
14365 			      ,p_Lpn_id         => l_lpn_rec.lpn_id
14366 			      ,p_epc            => l_epc_value
14367 			      ,x_return_status  => l_return_status
14368 			      ,x_return_mesg    => l_msg_data
14369 			      );
14370 
14371 			END IF;--IF (l_epc_column IS NOT NULL) THEN
14372 		     END IF;--IF (l_lpn_rec.transaction_type = 'SHIP' AND l_lpn_rec.source_document_code = 'PO') THEN
14373 		  End if;
14374 	       End if;
14375 	    End if;
14376 
14377 	    if ( l_lpn_rec.transaction_type = 'RECEIVE') then
14378 	       --
14379 	       -- Get the Source Name of the LPN
14380 	       --
14381 	       l_progress := 'WMSINB-18267';
14382                Begin
14383 		  if l_lpn_rec.lpn_id is not null then
14384 		     --
14385 		     -- Case where lpn id is present in RTI
14386 		     --
14387 		     l_progress := 'WMSINB-18273';
14388 		     select RSH.shipment_header_id ,
14389 		       RSH.ASN_TYPE,
14390 		       WLPN.LPN_CONTEXT
14391 		       into l_source_header_id ,
14392 		       l_asn_type,
14393 		       l_lpn_context
14394 		       from WMS_LICENSE_PLATE_NUMBERS WLPN,
14395 		       RCV_SHIPMENT_HEADERS RSH
14396 		       where WLPN.lpn_id = l_lpn_rec.lpn_id
14397 		       AND (
14398 		               ((rsh.receipt_source_code IN ('INVENTORY','INTERNAL ORDER')
14399 		                  AND rsh.organization_id = wlpn.organization_id) --BUG 4730474
14400 		                  and  wlpn.source_header_id is null
14401 		                  and  wlpn.source_name=rsh.shipment_num)
14402                                   OR
14403                                  (Nvl(rsh.receipt_source_code,'#$#') NOT IN ('INVENTORY','INTERNAL ORDER')
14404 		                  and rsh.shipment_header_id=wlpn.source_header_id)
14405 			       )
14406                        and rownum = 1 ; --bug 5749200 rearranged the where clause of the query
14407 		   else
14408 		     --
14409 		     -- Case where lpn_id is not valid or null
14410 		     -- Review Later
14411 		     l_progress := 'WMSINB-18291';
14412 		     l_source_header_id := null;
14413 		     l_asn_type := null;
14414 		     l_lpn_context := null;
14415 		  end if;
14416 
14417 	       Exception
14418 		  When others then
14419 		     -- Review Later
14420 		     -- Set appropiate Message
14421 		     l_progress := 'WMSINB-18301';
14422 		     l_source_header_id := null;
14423 		     l_asn_type := null;
14424 		     l_lpn_context := null;
14425 	       End;
14426 
14427 	       IF (l_debug = 1) THEN
14428 		  print_debug('VALIDATE_LPN_INFO - Source Header ID:'||l_source_header_id,1);
14429 		  print_debug('VALIDATE_LPN_INFO - ASN Type:'||l_asn_type,1);
14430 		  print_debug('VALIDATE_LPN_INFO - Shipment Num:'||l_lpn_rec.shipment_num,1);
14431 		  print_debug('VALIDATE_LPN_INFO - Shipment Header ID:'||l_lpn_rec.shipment_header_id,1);
14432 	       END If;
14433 
14434 	       IF (l_lpn_rec.shipment_header_id IS NULL) THEN
14435 		  IF (l_lpn_rec.shipment_num IS NOT NULL) THEN
14436 		     BEGIN
14437 			SELECT shipment_header_id
14438 			  INTO l_lpn_rec.shipment_header_id
14439 			  FROM rcv_shipment_headers
14440 			  WHERE shipment_num = l_lpn_rec.shipment_num;
14441 		     EXCEPTION
14442 			WHEN OTHERS THEN
14443 			   NULL;
14444 		     END;
14445 		  END IF; --IF (l_lpn_rec.shipment_num IS NOT NULL) THEN
14446 	       END IF; --IF (l_lpn_rec.shipment_header_id IS NULL) THEN
14447 
14448 	       IF (l_debug = 1) THEN
14449 		  print_debug('VALIDATE_LPN_INFO - Shipment Header ID NOW:'||l_lpn_rec.shipment_header_id,1);
14450 	       END If;
14451 
14452 	       --
14453 	       -- Case where SOURCE in LPN and  SHIPMENT Info MISMATCH in RTI Generate Error
14454 	       --
14455 	       if (l_source_header_id is not null or l_lpn_rec.shipment_header_id is not null) then
14456 		  IF (l_lpn_rec.lpn_id IS NOT NULL AND
14457 		      nvl(l_source_header_id,0) <> nvl(l_lpn_rec.shipment_header_id,0)) then
14458 		     --
14459 		     -- Review Later
14460 		     -- Set appropiate Message
14461 		     --
14462 		     l_progress := 'WMSINB-18322';
14463 		     RAISE fnd_api.g_exc_error;
14464 		  end if;
14465 	       end if;
14466 	       --
14467            --Bug 13891514 Adding ASBN as well because the validations/processing is same for ASN/ASBN
14468 	       if ( ( Nvl(l_asn_type,'#$#$') in ( 'ASN' , 'ASBN' ) and l_lpn_context not in (G_LPN_CONTEXT_VENDOR ,G_LPN_CONTEXT_PREGENERATED)) or
14469 		    ( l_asn_type is null and l_lpn_context not in (G_LPN_CONTEXT_INTRANSIT ,G_LPN_CONTEXT_PREGENERATED) )) then
14470 		  --
14471 		  -- ASN and LPN_context is not resides in Vendor
14472 		  -- SHIPMENT and LPN_context is not Intransit
14473 		  -- Review Later
14474 		  -- Set appropiate Message
14475 		  --
14476 		  l_progress := 'WMSINB-18335';
14477 		  RAISE fnd_api.g_exc_error;
14478 	       end if;
14479 	    End if; -- Receive
14480 
14481 	    if ( l_lpn_rec.transaction_type in ('ACCEPT','REJECT') ) then
14482 	       if l_lpn_rec.lpn_id IS NOT NULL then
14483 		  if l_lpn_context <> G_LPN_CONTEXT_RCV then
14484 		     l_progress := 'WMSINB-18343';
14485 		     -- FAIL TRANSACTIONS
14486 		     -- REVIEW LATER
14487 		     RAISE FND_API.G_EXC_ERROR;
14488 		  End if;
14489 	       End if;
14490 	    End if;  -- Inspect
14491 
14492 	    l_progress := 'WMSINB-18351';
14493 
14494 	    if ( l_lpn_rec.transaction_type in ('DELIVER','TRANSFER')) then
14495 	       if l_lpn_rec.lpn_id IS NOT NULL then
14496 		  if l_lpn_context <> G_LPN_CONTEXT_RCV then
14497                      if  l_lpn_rec.transaction_type = 'DELIVER' then
14498                        BEGIN
14499 
14500                          -- CHECK WHETHER MULTIPLE ROWS EXIST in RTI FOR THE SAME FROM LPN
14501                          -- THEN FOR SUBSEQUENT LOOPS WITHIN THE SAME LPN GROUP WE
14502                          -- DON't need to validate context for DELIVER TXN because it
14503                          -- might have update the lpn context.
14504 
14505                          select count(*) into l_lpn_Count
14506                            from rcv_transactions_interface
14507                           where lpn_id = l_lpn_rec.lpn_id
14508                             and transaction_type ='DELIVER'
14509                             and interface_transaction_id < l_lpn_rec.interface_transaction_id
14510                             and lpn_group_id = p_lpn_group_id;
14511 
14512                          if l_lpn_count = 0 then
14513 		           l_progress := 'WMSINB-18357';
14514 		           RAISE FND_API.G_EXC_ERROR;
14515                          End if;
14516                        EXCEPTION
14517                          WHEN OTHERS THEN NULL;
14518                        END;
14519                      Else
14520 		       l_progress := 'WMSINB-18358';
14521 		       RAISE FND_API.G_EXC_ERROR;
14522                      End if;
14523 		  End if;
14524 		  --
14525 		  if ( l_lpn_rec.transaction_type = 'DELIVER') then
14526 		     --
14527 		     null;
14528 		     --
14529 		     -- Commented this call as not needed.
14530 		     --
14531 		     -- INSPECTED MATERIAL EXISTS IN FLPN FAIL THE TXN
14532 		     -- Begin
14533 		     --    select 1
14534 		     --      into l_insp_mat_exists
14535 		     --      from mtl_txn_request_lines mol
14536 		     --      where mol.lpn_id = l_lpn_rec.lpn_id
14537 		     --      and nvl(mol.inspection_status,2) = 1
14538 		     --      and rownum = 1;
14539 		     --    if l_insp_mat_exists = 1 then
14540 		     --       -- FAIL TRANSACTIONS
14541 		     --       -- REVIEW LATER
14542 		     --       RAISE FND_API.G_EXC_ERROR;
14543 		     --    End if;
14544 		     -- Exception
14545 		     --    When no_data_found then
14546 		     --       -- No material with Inspection Reqd. exists ok to procedd with this LPN
14547 		     --       null;
14548 		     --    When Others then
14549 		     --       -- Other Error for checking Inspection Reqd Flag.
14550 		     --       -- FAIL TRANSACTIONS
14551 		     --       -- REVIEW LATER
14552 		     --       RAISE FND_API.G_EXC_ERROR;
14553 		     -- End;
14554 		  End if;
14555 	       End if;
14556 	    End if; -- Deliver Transfer
14557 
14558 	    l_progress := 'WMSINB-18395';
14559 
14560 	    IF (l_debug = 1) THEN
14561 	       print_debug('VALIDATE_LPN_INFO - From LPN Validation ***PASSED***', 1);
14562 	    END If;
14563 
14564 	    if ( l_lpn_rec.transfer_license_plate_number is not null or l_lpn_rec.transfer_lpn_id is not null or
14565 		 l_lpn_rec.transaction_type = 'SHIP' ) then
14566 
14567 	       IF (l_debug = 1) THEN
14568 		  print_debug('VALIDATE_LPN_INFO - STARTING Transfer LPN Validation ...', 1);
14569 	       END If;
14570 
14571 	       --For a non-wms org if the transfer_lpn is not null
14572 	       --for a deliver transaction then we should fail the txn.
14573 	       IF (NOT wms_install.check_install(x_return_status,l_msg_count,
14574 					      l_msg_data,l_lpn_rec.to_organization_id)) THEN
14575 		  IF (l_lpn_rec.transaction_type = 'DELIVER' OR
14576 		      l_lpn_rec.auto_transact_code = 'DELIVER') THEN
14577 		     l_progress := 'WMSINB-18400';
14578 		     RAISE fnd_api.g_exc_error;
14579 		  END IF;
14580 	       END IF;
14581 
14582 	       --
14583 	       -- VALIDATION FOR SHIP  TXN
14584 
14585 	       l_progress := 'WMSINB-18415';
14586 
14587 	       if (l_lpn_rec.transaction_type = 'SHIP' ) then
14588 		  if ( l_lpn_rec.transfer_license_plate_number is not null
14589 		       or l_lpn_rec.transfer_lpn_id is not null ) then
14590 		     -- TRANSFER LPN SHOULD BE NULL FOR SHIP TXN
14591 		     -- FAIL TRANSACTIONS
14592 		     -- REVIEW LATER
14593 		     l_progress := 'WMSINB-18423';
14594 		     RAISE FND_API.G_EXC_ERROR;
14595 		  End if;
14596 	       End if;
14597 
14598 	       --
14599 	       -- VALIDATION FOR DELIVER and TRANSFER TXN
14600 	       -- REVIEW LATER
14601 	       --
14602 	       l_progress := 'WMSINB-18432';
14603 
14604 	       -- if l_lpn_rec.transaction_type in ('DELIVER','TRANSFER' ) then
14605 	       if l_lpn_rec.transaction_type in ('DELIVER','TRANSFER','RECEIVE' ) then
14606 
14607                      --Bug 5550783 start
14608                      IF (l_debug = 1) THEN
14609                         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);
14610                      END If;
14611                      --Bug 5550783 end
14612 
14613 		  if ((l_lpn_rec.lpn_id is not null) and (l_lpn_rec.lpn_id = l_lpn_rec.transfer_lpn_id )) then
14614                     x_return_status := g_ret_sts_success; --Bug 5550783
14615                      IF (l_debug = 1) THEN
14616 
14617                         print_debug('l_lpn_rec.express_transaction=' || l_lpn_rec.express_transaction , 1);
14618                         print_debug('VALIDATE_LPN_INFO - l_lpn_rec.express_transaction check ...', 1);
14619                         print_debug('VALIDATE_LPN_INFO - x_return_status=' || x_return_status, 1);
14620                         print_debug('VALIDATE_LPN_INFO - l_lpn_rec.transaction_type=' || l_lpn_rec.transaction_type, 1);
14621                         print_debug('VALIDATE_LPN_INFO - l_lpn_rec.mobile_txn=' || l_lpn_rec.mobile_txn, 1);
14622                      END If;
14623 
14624                     --Do not do the validate_total_qty if it is express transaction and also if it is a Mobil Deliver/Transfer
14625                     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
14626                          IF (l_debug = 1) THEN
14627                             print_debug('l_lpn_rec.express_transaction', 1);
14628                             print_debug('VALIDATE_LPN_INFO - Not doing validate_total_qty ...', 1);
14629                          END If;
14630 
14631                     Else
14632                        --
14633                        -- CALL THE TOTAL QTY VALIDATION API HERE
14634                        --
14635                        --
14636 		       l_progress := 'WMSINB-18440';
14637 
14638 		       IF (l_debug = 1) THEN
14639 
14640 			print_debug('l_lpn_rec.express_transaction', 1);
14641 			print_debug('VALIDATE_LPN_INFO - Before validate_total_qty ...', 1);
14642 		     END If;
14643 
14644 		     validate_total_qty(p_lpn_group_id => p_lpn_group_id,
14645 					p_from_lpn_id => l_lpn_rec.lpn_id,
14646 					p_parent_lpn_id => l_cur_from_parent_lpn_id,
14647 					p_transaction_type => l_lpn_rec.transaction_type,
14648 					x_return_status    => x_return_status,
14649 					x_msg_count        => x_msg_count,
14650 					x_msg_data         => x_msg_data);
14651 
14652 		     IF (l_debug = 1) THEN
14653 			print_debug('VALIDATE_LPN_INFO - After validate_total_qty :'||x_return_status, 1);
14654 		     END If;
14655                      End if;--Bug 5550783
14656 
14657 		     if x_return_status <> G_RET_STS_SUCCESS Then
14658 			if  l_lpn_rec.transaction_type <> 'RECEIVE' then
14659 			   --  Review Late Set Appropiate Message
14660 			   l_progress := 'WMSINB-18460';
14661 			   RAISE FND_API.G_EXC_ERROR;
14662 			 Else
14663 			   -- Unpack all from here
14664 			   l_progress := 'WMSINB-18461';
14665 			   IF (l_debug = 1) THEN
14666 			      print_debug('VALIDATE_LPN_INFO - Case for Full UNPACK as QTY MISMATCH' , 1);
14667 			   END If;
14668 			   wms_container_pvt.packunpack_container(
14669 								  p_api_version            => 1.0,
14670 								  p_init_msg_list          => g_false,
14671 								  p_commit                 => g_false,
14672 								  p_validation_level       => fnd_api.g_valid_level_none,
14673 								  x_return_status          => x_return_status,
14674 								  x_msg_count              => x_msg_count,
14675 								  x_msg_data               => x_msg_data,
14676 								  p_lpn_id                 => l_lpn_rec.lpn_id,
14677 								  p_organization_id        => l_lpn_rec.from_organization_id,
14678 								  p_operation              => 2, --- TO UNPACK
14679 								  p_unpack_all             => 1,
14680 								  p_auto_unnest_empty_lpns => 2
14681 								  );
14682 			   if x_return_status <> G_RET_STS_SUCCESS Then
14683 			      l_progress := 'WMSINB-18462';
14684 			      RAISE FND_API.G_EXC_ERROR;
14685 			   End if;
14686 
14687          -- 14408061 Adding the LPN in a table with the group_id
14688 			IF (l_debug = 1) THEN
14689 			   print_debug('Since the LPN is being unpacked, we do not need to unpack at a later stage' , 1);
14690                print_debug('So storing the lpn and its group id' , 1);
14691                print_debug('l_lpn_rec.lpn_id: '||l_lpn_rec.lpn_id , 1);
14692                print_debug('p_lpn_group_id: '||p_lpn_group_id , 1);
14693 			END If;
14694             g_lpn_tbl(l_lpn_rec.lpn_id) := p_lpn_group_id;
14695          -- 14408061
14696 
14697 			End if;
14698 		     End if;
14699 		  End if;
14700 	       End if;
14701 
14702 	       l_progress := 'WMSINB-18467';
14703 
14704 	       --
14705 	       -- *********************
14706 	       -- Transfer LPN does not already exists in the system
14707 	       -- This validations is not needed for SHIP TXN
14708 	       -- *********************
14709 
14710 	       if (l_lpn_rec.transaction_type <> 'SHIP') then
14711 		  if (l_lpn_rec.transfer_lpn_id is null) then
14712 		     -- Check existence in WLPNI
14713 		     l_progress := 'WMSINB-18478';
14714 		     check_lpn_in_wlpni(l_lpn_rec.transfer_license_plate_number,
14715 					l_lpn_rec.transfer_lpn_id,
14716 					p_lpn_group_id,
14717 					l_wlpni_exists);
14718 		     if (l_wlpni_exists = 0) then
14719 			--
14720 			-- WLPNI does not exists fail the TXN
14721 			-- Review Later
14722 			-- Set appropiate Message
14723 			--
14724 			l_progress := 'WMSINB-18489';
14725 			RAISE FND_API.G_EXC_ERROR;
14726 		      else
14727 			--
14728 			-- WLPNI exists create the LPN
14729 			--
14730 			l_progress := 'WMSINB-18495';
14731 			--
14732 			-- Call API to create LPN
14733 			-- Transfer LPN Context needs to be set properly depending on context.
14734 			--
14735 			-- Call the API get_lpn_context here
14736 
14737 			l_to_lpn_context := get_lpn_context(p_transaction_type => l_lpn_rec.transaction_type
14738 							    , p_auto_transact_code => l_lpn_rec.auto_transact_code);
14739 
14740 			l_progress := 'WMSINB-18504';
14741 
14742 			IF (l_debug = 1) THEN
14743 			   print_debug('VALIDATE_LPN_INFO - NEW LPN - Calling create_lpn_from_wlpni ...', 1);
14744 			END If;
14745 
14746 			create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.transfer_license_plate_number,
14747 					      p_lpn_group_id => p_lpn_group_id,
14748 					      p_organization_id => l_lpn_rec.to_organization_id,
14749 					      p_lpn_context => l_to_lpn_context,
14750 					      x_lpn_id => l_lpn_rec.transfer_lpn_id,
14751 					      x_return_status => x_return_status,
14752 					      x_msg_count => l_msg_count,
14753 					      x_msg_data => l_msg_data);
14754 			-- Check the error status from the above call
14755 			if x_return_status <> G_RET_STS_SUCCESS Then
14756 			   --  Review Late Set Appropiate Message
14757 			   l_progress := 'WMSINB-18521';
14758 			   RAISE FND_API.G_EXC_ERROR;
14759 			End if;
14760 		     end if;
14761 		   else
14762 		     -- *********************
14763 		     -- Transfer LPN already exists in the system
14764 		     -- *********************
14765 
14766 		     -- The following validation needs to be done only when
14767 		     -- from and to lpn is different
14768 		     if (l_lpn_rec.transfer_lpn_id <> nvl(l_lpn_rec.lpn_id,-9999))  then
14769 			-- Validate Locator
14770 			l_progress := 'WMSINB-18534';
14771 			l_lpn_match := 'N';
14772 
14773 			IF (l_debug = 1) THEN
14774 			   print_debug('VALIDATE_LPN_INFO - Calling validate_lpn_locator ...', 1);
14775 			END If;
14776 
14777 			validate_lpn_locator( p_lpn_id => l_lpn_rec.transfer_lpn_id,
14778 					      p_subinventory => l_lpn_rec.subinventory,
14779 					      p_locator_id   => l_lpn_rec.locator_id,
14780 					      p_organization_id  => l_lpn_rec.to_organization_id,
14781 					      x_lpn_match        => l_lpn_match,
14782 					      x_return_status    => x_return_status,
14783 					      x_msg_count        => x_msg_count,
14784 					      x_msg_data         => x_msg_data);
14785 
14786 			if x_return_status <> G_RET_STS_SUCCESS Then
14787 			   --  Review Late Set Appropiate Message
14788 			   l_progress := 'WMSINB-18552';
14789 			   RAISE FND_API.G_EXC_ERROR;
14790 			End if;
14791 
14792 			if l_lpn_match = 'N' then
14793 			   l_progress := 'WMSINB-18557';
14794 			   RAISE FND_API.G_EXC_ERROR;
14795 			End if;
14796 
14797 			-- Check Error Status
14798 			if ( (validate_lpn_context(l_lpn_rec.transaction_type,
14799 						  l_lpn_rec.auto_transact_code,
14800 						  l_transfer_lpn_context ) <> TRUE )
14801 			     OR (l_transfer_lpn_context = g_lpn_context_picked
14802 				 AND l_lpn_rec.mmtt_temp_id IS NULL)) THEN
14803 			   --  Review Late Set Appropiate Message
14804 			   l_progress := 'WMSINB-18566';
14805 			   RAISE FND_API.G_EXC_ERROR;
14806 			End if;
14807 		     End if;
14808 		  End if;
14809 	       End if;
14810 	       --
14811 	       --
14812 	       -- Processing for NESTING
14813 	       --
14814 	       --
14815 
14816 	       l_progress := 'WMSINB-18578';
14817 
14818 	       if l_lpn_rec.transaction_type = 'SHIP' then
14819 		  l_WLPNIQLPN    := l_lpn_rec.license_plate_number;
14820 		  l_WLPNIQLPN_ID := l_lpn_rec.lpn_id;
14821 
14822 		  l_validate_sub := l_lpn_rec.subinventory;
14823 		  l_validate_loc_id := l_lpn_rec.locator_id;
14824 
14825 		  l_parent_source_name := l_lpn_rec.shipment_num;
14826 		  l_parent_source_type_id := 1;
14827 		  l_parent_source_header_id := l_lpn_rec.shipment_header_id;
14828 
14829 		  l_parent_lpn_context := get_lpn_context(p_transaction_type => l_lpn_rec.transaction_type
14830 							  , p_auto_transact_code => l_lpn_rec.auto_transact_code);
14831 		ELSE --if l_lpn_rec.transaction_type = 'SHIP' then
14832 		  l_WLPNIQLPN    := l_lpn_rec.transfer_license_plate_number;
14833 		  l_WLPNIQLPN_ID := l_lpn_rec.transfer_lpn_id;
14834 
14835 		  IF (l_lpn_rec.subinventory IS NULL) THEN
14836 		     BEGIN
14837 			SELECT subinventory_code
14838 			  , locator_id
14839 			  INTO l_validate_sub
14840 			  , l_validate_loc_id
14841 			  FROM wms_license_plate_numbers
14842 			  WHERE lpn_id = l_lpn_rec.transfer_lpn_id
14843 			  OR license_plate_number = l_lpn_rec.transfer_license_plate_number;
14844 		     EXCEPTION
14845 			WHEN OTHERS THEN
14846 			   l_validate_sub := NULL;
14847 			   l_validate_loc_id := NULL;
14848 		     END;
14849 		   ELSE
14850 			   l_validate_sub := l_lpn_rec.subinventory;
14851 			   l_validate_loc_id := l_lpn_rec.locator_id;
14852 		  END IF;
14853 
14854 		  l_parent_source_name := NULL;
14855 		  l_parent_source_type_id := NULL;
14856 		  l_parent_source_header_id := NULL;
14857 
14858 		  l_parent_lpn_context := get_lpn_context(p_transaction_type => l_lpn_rec.transaction_type
14859 							  , p_auto_transact_code => l_lpn_rec.auto_transact_code);
14860 	       END IF; --if l_lpn_rec.transaction_type = 'SHIP' then
14861 
14862 	       IF (l_debug = 1) THEN
14863 		  print_debug('VALIDATE_LPN_INFO - Getting into nesting logic ...', 1);
14864 		  print_debug('VALIDATE_LPN_INFO - WLPNQLPN:'||l_wlpniqlpn,1);
14865 		  print_debug('VALIDATE_LPN_INFO - WLPNQLPN_ID:'||l_wlpniqlpn_id,1);
14866 	       END If;
14867 
14868 	       Loop
14869 		  -- Initialize
14870 		  l_PTLPN_ID := null;
14871 		  l_PTLPN    := null;
14872 		  l_PTLPN_CONTEXT := null;
14873 		  l_PTLPN_EXISTS := 0;
14874 
14875 
14876 		  l_WLPNIQLPN_PARENT_LPN_ID := null;
14877 
14878 		  l_progress := 'WMSINB-18638';
14879 
14880                   Begin
14881 
14882 		     -- We need to make this distinct becasue there might exist multple rows in wlpni
14883 		     -- for the same LPN , but for all those rows the parent should be same
14884 
14885 		     select distinct
14886 		       parent_lpn_id,
14887 		       parent_license_plate_number
14888 		       into l_PTLPN_ID,
14889 		       l_PTLPN
14890 		       from wms_lpn_interface wlpni
14891 		       where ( nvl(wlpni.license_plate_number,'-1') = nvl(l_WLPNIQLPN,'-1') or
14892 			       nvl(wlpni.lpn_id,'-1') = nvl(l_WLPNIQLPN_ID,'-1') )
14893 		       and wlpni.source_group_id = p_lpn_group_id;
14894 
14895 		     l_progress := 'WMSINB-18655';
14896 		  Exception
14897 		     When no_data_found then
14898 			l_progress := 'WMSINB-18658';
14899 			exit;
14900 		     When others then
14901 			l_progress := 'WMSINB-18661';
14902 			-- Review Later
14903 			-- Set appropiate Message
14904 			--
14905 			RAISE FND_API.G_EXC_ERROR;
14906 		  End;
14907 		  --
14908 
14909 		  IF (l_debug = 1) THEN
14910 		     print_debug('VALIDATE_LPN_INFO - FROM WLPNI parent_lpn_id:'||l_PTLPN_ID,1);
14911 		     print_debug('VALIDATE_LPN_INFO - FROM WLPNI parent_lpn:'||l_PTLPN,1);
14912 		  END If;
14913 
14914 		  l_progress := 'WMSINB-18674';
14915 
14916 		  if (l_PTLPN_ID is not null or l_PTLPN is not null) then
14917 		     --
14918 		     -- Call get_lpn_id
14919 
14920 		     l_lpn_state := get_lpn_id(l_PTLPN_ID, l_PTLPN ,
14921 					       l_PTLPN_context,
14922 					       l_cur_ptlpn_parent_lpn_id,
14923 					       l_wlpn_source_header_id) ;
14924 
14925 		     --
14926 
14927 		     IF (l_debug = 1) THEN
14928 			print_debug('VALIDATE_LPN_INFO - l_PTLPN_context:'||l_PTLPN_context,1);
14929 			print_debug('VALIDATE_LPN_INFO - l_cur_PTLPN_parent_lpn_id:'||l_cur_PTLPN_parent_lpn_id,1);
14930 		     END If;
14931 
14932 		     if (l_PTLPN_ID is null ) then
14933 			-- Check existence in WLPNI
14934 			l_progress := 'WMSINB-18691';
14935 			-- Call API to create LPN
14936 
14937 			-- Need to set the CONTEXT properly Here. This part might come for
14938 			-- SHIP TXN so handled here
14939 			-- Call the get_lpn_context to set the conext
14940 
14941 			l_to_lpn_context := get_lpn_context(p_transaction_type => l_lpn_rec.transaction_type
14942 							    , p_auto_transact_code => l_lpn_rec.auto_transact_code);
14943 
14944 			l_progress := 'WMSINB-18700';
14945 
14946 			create_lpn_from_wlpni(p_license_plate_number => l_PTLPN,
14947 					      p_lpn_group_id => p_lpn_group_id,
14948 					      p_organization_id => l_lpn_rec.to_organization_id,
14949 					      p_lpn_context => l_to_lpn_context,
14950                                               p_source_header_id => l_asn_source_header_id,
14951                                               p_source_type_id   => l_asn_source_type_id,
14952 					      x_lpn_id => l_PTLPN_ID,
14953 					      x_return_status => x_return_status,
14954 					      x_msg_count => l_msg_count,
14955 					      x_msg_data => l_msg_data);
14956 			-- Check error status
14957 			-- Check the error status from the above call
14958 			if x_return_status <> G_RET_STS_SUCCESS Then
14959 			   --  Review Late Set Appropiate Message
14960 			   l_progress := 'WMSINB-18714';
14961 			   RAISE FND_API.G_EXC_ERROR;
14962 			End if;
14963 		      else
14964 			-- *********************
14965 			-- PARENT LPN already exists in the system
14966 			-- *********************
14967 			-- Validate Locator
14968 			l_progress := 'WMSINB-18722';
14969 			l_lpn_match := 'N';
14970 			validate_lpn_locator( p_lpn_id => l_PTLPN_ID,
14971 					      p_subinventory => l_validate_sub,
14972 					      p_locator_id   => l_validate_loc_id,
14973 					      p_organization_id  => l_lpn_rec.to_organization_id,
14974 					      x_lpn_match        => l_lpn_match,
14975 					      x_return_status    => x_return_status,
14976 					      x_msg_count        => x_msg_count,
14977 					      x_msg_data         => x_msg_data);
14978 
14979 			if x_return_status <> G_RET_STS_SUCCESS Then
14980 			   --  Review Late Set Appropiate Message
14981 			   l_progress := 'WMSINB-18735';
14982 			   RAISE FND_API.G_EXC_ERROR;
14983 			End if;
14984 
14985 			if l_lpn_match = 'N' then
14986 			   l_progress := 'WMSINB-18740';
14987 			   RAISE FND_API.G_EXC_ERROR;
14988 			End if;
14989 
14990 			IF (l_lpn_rec.transaction_type = 'SHIP'
14991 			    AND	(l_lpn_rec.shipment_header_id = l_wlpn_source_header_id)) THEN
14992 			   IF (l_debug = 1) THEN
14993 			      print_debug('VALIDATE_LPN_INFO - LPN Context already validated: '||l_PTLPN_ID,1);
14994 			   END If;
14995 			 ELSE
14996 			   if ( (validate_lpn_context(l_lpn_rec.transaction_type,
14997 						     l_lpn_rec.auto_transact_code,
14998 						     l_PTLPN_CONTEXT ) <> TRUE)
14999 				OR (l_PTLPN_CONTEXT = g_lpn_context_picked
15000 				    AND l_lpn_rec.mmtt_temp_id IS NULL)
15001 				) then
15002 			      --  Review Late Set Appropiate Message
15003 			      l_progress := 'WMSINB-18748';
15004 			      RAISE FND_API.G_EXC_ERROR;
15005 			   End if;
15006 			END IF; --IF (l_lpn_rec.transaction_type = 'SHIP'
15007 			--
15008 
15009 			IF (l_ptlpn_context = g_lpn_context_picked
15010 			    AND l_lpn_rec.mmtt_temp_id IS NOT NULL
15011 			    AND l_lpn_rec.transaction_type = 'DELIVER') THEN
15012 			   l_parent_lpn_context := l_ptlpn_context;
15013 			END IF;
15014 		     end if;
15015 		     --
15016 		     --
15017 		     l_progress := 'WMSINB-18755';
15018 		     get_parent_lpn(l_WLPNIQLPN, l_WLPNIQLPN_PARENT_LPN_ID);
15019 		     --
15020 		     --
15021 		     --l_progress := 'WMSINB-18759';
15022 		     --get_parent_lpn_in_wlpni(l_PTLPN, l_PTLPN_ID, p_lpn_group_id, l_P_PTLPN, l_P_PTLPN_ID);
15023 		     --
15024 		     -- Review the Organization id in call to packunpack.
15025 
15026 		     IF (l_debug = 1) THEN
15027 			print_debug('VALIDATE_LPN_INFO - FROM WLPN l_WLPNIQLPN_PARENT_LPN_ID:'||l_WLPNIQLPN_PARENT_LPN_ID,1);
15028 		     END If;
15029 
15030 		     if(l_WLPNIQLPN_PARENT_LPN_ID is not null and
15031 			l_WLPNIQLPN_PARENT_LPN_ID <> l_PTLPN_ID )
15032 		       then
15033 			l_progress := 'WMSINB-18771';
15034 			-- Review Later
15035 			-- UNPACK WLPNIQLPN FROM CURRENT PARENT
15036 			-- PACK WLPNIQLPN IN PTLPN
15037 
15038 			wms_container_pvt.packunpack_container(
15039 							       p_api_version            => 1.0,
15040 							       p_init_msg_list          => g_false,
15041 							       p_commit                 => g_false,
15042 							       p_validation_level       => fnd_api.g_valid_level_none,
15043 							       x_return_status          => x_return_status,
15044 							       x_msg_count              => l_msg_count,
15045 							       x_msg_data               => l_msg_data,
15046 							       p_lpn_id                 => l_WLPNIQLPN_PARENT_LPN_ID,
15047 							       p_content_lpn_id         => l_WLPNIQLPN_ID,
15048 							       p_organization_id        => l_lpn_rec.from_organization_id,
15049 							       p_operation              => 2 --- TO UNPACK
15050 							       );
15051 
15052 			IF (x_return_status <> g_ret_sts_success) THEN
15053 			   IF (l_debug = 1) THEN
15054 			      print_debug('VALIDATE_LPN_INFO: packunpack_container failed progress = ' || l_progress,1);
15055 			   END IF;
15056 			   l_progress := 'WMSINB-18794';
15057 			   RAISE fnd_api.g_exc_error;
15058 			END IF;
15059 
15060 			l_progress := 'WMSINB-18798';
15061 
15062 			--we need to update the lpn_context and sub/loc for the
15063 			--transfer lpn right here so that it has the right context.
15064 			--we need to do it before the packunpack
15065 			--otherwise packunpack fails
15066 
15067 			update_lpn_location_context(p_organization_id => NULL
15068 						    ,p_sub => l_lpn_rec.subinventory
15069 						    ,p_locator => l_lpn_rec.locator_id
15070 						    ,p_lpn_context => l_parent_lpn_context
15071 						    ,p_lpn_id => l_WLPNIQLPN_ID
15072 						    ,x_return_status => x_return_status
15073 						    ,x_msg_count => x_msg_count
15074 						    ,x_msg_data => x_msg_data
15075 						    ,p_source_name => l_parent_source_name
15076 						    ,p_source_header_id => l_parent_source_header_id
15077 						    ,p_source_type_id => l_parent_source_type_id);
15078 			IF (x_return_status <> g_ret_sts_success) THEN
15079 			   --raise an error
15080 			   --review later
15081 			   l_progress := 'WMSINB-18818';
15082 			   RAISE fnd_api.g_exc_error;
15083 			END IF;
15084 
15085 
15086 			--we need to update the lpn_context for the
15087 			--parent right here so that it has the right context.
15088 
15089 			update_lpn_location_context(p_organization_id => NULL
15090 						    ,p_sub => l_lpn_rec.subinventory
15091 						    ,p_locator => l_lpn_rec.locator_id
15092 						    ,p_lpn_context => l_parent_lpn_context
15093 						    ,p_lpn_id => l_PTLPN_ID
15094 						    ,x_return_status => x_return_status
15095 						    ,x_msg_count => x_msg_count
15096 						    ,x_msg_data => x_msg_data
15097 						    ,p_source_name => l_parent_source_name
15098 						    ,p_source_header_id => l_parent_source_header_id
15099 						    ,p_source_type_id => l_parent_source_type_id);
15100 			IF (x_return_status <> g_ret_sts_success) THEN
15101 			   --raise an error
15102 			   --review later
15103 			   l_progress := 'WMSINB-18822';
15104 			   RAISE fnd_api.g_exc_error;
15105 			END IF;
15106 
15107 			wms_container_pvt.packunpack_container(
15108 							       p_api_version            => 1.0,
15109 							       p_init_msg_list          => g_false,
15110 							       p_commit                 => g_false,
15111 							       p_validation_level       => fnd_api.g_valid_level_none,
15112 							       x_return_status          => x_return_status,
15113 							       x_msg_count              => l_msg_count,
15114 							       x_msg_data               => l_msg_data,
15115 							       p_lpn_id                 => l_PTLPN_ID,
15116 							       p_content_lpn_id         => l_WLPNIQLPN_ID,
15117 							       p_organization_id        => l_lpn_rec.to_organization_id,
15118 							       p_operation              => 1 --- TO PACK
15119 							       );
15120 			IF (x_return_status <> g_ret_sts_success) THEN
15121 			   IF (l_debug = 1) THEN
15122 			      print_debug('VALIDATE_LPN_INFO: packunpack_container failed progress = ' || l_progress,1);
15123 			   END IF;
15124 			   l_progress := 'WMSINB-18841';
15125 			   RAISE fnd_api.g_exc_error;
15126 			END IF;
15127 
15128 		      else
15129 			l_progress := 'WMSINB-18869';
15130 			if  l_WLPNIQLPN_PARENT_LPN_ID is null then
15131 			   l_progress := 'WMSINB-18871';
15132 
15133 			   --we need to update the lpn_context and sub/loc for the
15134 			   --transfer lpn right here so that it has the right context.
15135 			   --we need to do it before the packunpack
15136 			   --otherwise packunpack fails
15137 			   IF (l_debug = 1) THEN
15138 			      print_debug('Going to update the lpn:'|| l_WLPNIQLPN_ID,1);
15139 			   END IF;
15140 
15141 			   update_lpn_location_context(p_organization_id => NULL
15142 						       ,p_sub => l_lpn_rec.subinventory
15143 						       ,p_locator => l_lpn_rec.locator_id
15144 						       ,p_lpn_context => l_parent_lpn_context
15145 						       ,p_lpn_id => l_WLPNIQLPN_ID
15146 						       ,x_return_status => x_return_status
15147 						       ,x_msg_count => x_msg_count
15148 						       ,x_msg_data => x_msg_data
15149 						       ,p_source_name => l_parent_source_name
15150 						       ,p_source_header_id => l_parent_source_header_id
15151 						       ,p_source_type_id => l_parent_source_type_id);
15152 			   IF (x_return_status <> g_ret_sts_success) THEN
15153 			      --raise an error
15154 			      --review later
15155 			      l_progress := 'WMSINB-18891';
15156 			      RAISE fnd_api.g_exc_error;
15157 			   END IF;
15158 
15159 			   --we need to update the lpn_context for the
15160 			   --parent right here so that it has the right context.
15161 
15162 			   update_lpn_location_context(p_organization_id => NULL
15163 						       ,p_sub => l_lpn_rec.subinventory
15164 						       ,p_locator => l_lpn_rec.locator_id
15165 						       ,p_lpn_context => l_parent_lpn_context
15166 						       ,p_lpn_id => l_PTLPN_ID
15167 						       ,x_return_status => x_return_status
15168 						       ,x_msg_count => x_msg_count
15169 						       ,x_msg_data => x_msg_data
15170 						       ,p_source_name => l_parent_source_name
15171 						       ,p_source_header_id => l_parent_source_header_id
15172 						       ,p_source_type_id => l_parent_source_type_id);
15173 			   IF (x_return_status <> g_ret_sts_success) THEN
15174 			      --raise an error
15175 			      --review later
15176 			      l_progress := 'WMSINB-18895';
15177 			      RAISE fnd_api.g_exc_error;
15178 			   END IF;
15179 
15180 			   -- Review Later
15181 			   --PACK WLPNIQLPN IN PTLPN
15182 			      IF (l_debug = 1) THEN
15183 			     print_debug('Calling packunpack_container',1);
15184   		           END IF;
15185 
15186 		          /* Bug 4624542-Passing the parameters p_source_name and
15187 			   p_source_header_id to packunpack_container */
15188 
15189 			   wms_container_pvt.packunpack_container(
15190 								  p_api_version            => 1.0,
15191 								  p_init_msg_list          => g_false,
15192 								  p_commit                 => g_false,
15193 								  p_validation_level       => fnd_api.g_valid_level_none,
15194 								  x_return_status          => x_return_status,
15195 								  x_msg_count              => l_msg_count,
15196 								  x_msg_data               => l_msg_data,
15197 								  p_lpn_id                 => l_PTLPN_ID,
15198 								  p_content_lpn_id         => l_WLPNIQLPN_ID,
15199 								  p_organization_id        => l_lpn_rec.to_organization_id,
15200 								  p_operation              => 1, --- TO PACK
15201 								  p_source_name            => l_parent_source_name, --Bug 4624542
15202 							          p_source_header_id       => l_parent_source_header_id --Bug 4624542
15203 
15204 								  );
15205 			   IF (x_return_status <> g_ret_sts_success) THEN
15206 			      IF (l_debug = 1) THEN
15207 				 print_debug('VALIDATE_LPN_INFO: packunpack_container failed progress = ' || l_progress,1);
15208 			      END IF;
15209 			      l_progress := 'WMSINB-18917';
15210 			      RAISE fnd_api.g_exc_error;
15211 			   END IF;
15212 			end if;
15213 		     end if;
15214 		   else -- **** where PTLPN and PTLPN_ID is both null in WLPNI
15215 		     --
15216 		     l_progress := 'WMSINB-18944';
15217 		     get_parent_lpn(l_WLPNIQLPN, l_WLPNIQLPN_PARENT_LPN_ID);
15218 		     --
15219 
15220 		     IF (l_debug = 1) THEN
15221 			print_debug('VALIDATE_LPN_INFO - FROM WLPN l_WLPNIQLPN_PARENT_LPN_ID:'||l_WLPNIQLPN_PARENT_LPN_ID,1);
15222 		     END If;
15223 
15224 		     if l_WLPNIQLPN_PARENT_LPN_ID is not null then
15225 			l_progress := 'WMSINB-18953';
15226 			-- Call UNPACK API to unpack this LPN from parent LPN
15227 			-- Review Later
15228 			wms_container_pvt.packunpack_container(
15229 							       p_api_version            => 1.0,
15230 							       p_init_msg_list          => g_false,
15231 							       p_commit                 => g_false,
15232 							       p_validation_level       => fnd_api.g_valid_level_none,
15233 							       x_return_status          => x_return_status,
15234 							       x_msg_count              => l_msg_count,
15235 							       x_msg_data               => l_msg_data,
15236 							       p_lpn_id                 => l_WLPNIQLPN_PARENT_LPN_ID,
15237 							       p_content_lpn_id         => l_WLPNIQLPN_ID,
15238 							       p_organization_id        => l_lpn_rec.to_organization_id,  --bug for 13726378: change: from from_organization_id to to_orgnization_id
15239 							       p_operation              => 2 --- TO UNPACK
15240 							       );
15241 			IF (x_return_status <> g_ret_sts_success) THEN
15242 			   IF (l_debug = 1) THEN
15243 			      print_debug('VALIDATE_LPN_INFO: packunpack_container failed progress = ' || l_progress,1);
15244 			   END IF;
15245 			   l_progress := 'WMSINB-18973';
15246 			   RAISE fnd_api.g_exc_error;
15247 			END IF;
15248 			l_progress := 'WMSINB-18976';
15249 		     end if;
15250 		  end if;
15251 
15252 		  --
15253 		  -- Reinitialize for the next loop
15254 
15255 		  l_progress := 'WMSINB-18983';
15256 
15257 		  IF (l_debug = 1) THEN
15258 		     print_debug('VALIDATE_LPN_INFO: Before deleting wlpni l_progess = '|| l_progress, 1);
15259 		  END If;
15260 
15261 		  delete_wlpni(p_lpn_group_id,l_WLPNIQLPN_ID,l_WLPNIQLPN,x_return_status,x_msg_count,x_msg_data);
15262 
15263 		  l_progress := 'WMSINB-18991';
15264 
15265 		  IF (l_debug = 1) THEN
15266 		     print_debug('VALIDATE_LPN_INFO: after deleting wlpni l_progess = '|| l_progress, 1);
15267 		  END If;
15268 
15269 		  l_WLPNIQLPN    := l_PTLPN;
15270 		  l_WLPNIQLPN_ID := l_PTLPN_ID;
15271 
15272 		  if (l_WLPNIQLPN is null and l_WLPNIQLPN_ID is null ) then
15273 		     -- If PARENT is null, no change in nesting so exit from loop
15274 		     exit;
15275 		  End if;
15276 
15277 	       End Loop;
15278 
15279 	       IF (l_debug = 1) THEN
15280 		  print_debug('VALIDATE_LPN_INFO - Done with Nesting ...',1);
15281 	       END IF;
15282 	       --
15283 	       --
15284 	       -- **** LPN and TRANSFER LPN ARE SAME ************
15285 	       --
15286 	       l_progress := 'WMSINB-19014';
15287 
15288 	       -- The following can happen only in case for existing LPN's so
15289 	       -- in that case both the lpn_id, transfer_lpn_id, lpn, transfer_lpn
15290 	       -- must have been derived by the system
15291 	       --
15292 	       if ( (l_lpn_rec.lpn_id = l_lpn_rec.transfer_lpn_id) and
15293 		    (l_lpn_rec.license_plate_number = l_lpn_rec.transfer_license_plate_number) ) then
15294 		  --
15295 		  l_progress := 'WMSINB-19023';
15296 
15297 		  l_PTLPN := null;
15298 		  l_PTLPN_ID := null;
15299 
15300 		  get_parent_lpn(l_lpn_rec.transfer_license_plate_number, l_PTLPN_ID);
15301 
15302 		  -- Validate Locator
15303 		  l_progress := 'WMSINB-19031';
15304 
15305 		  l_lpn_state := get_lpn_id(l_PTLPN, l_PTLPN_ID,
15306 					    l_PTLPN_CONTEXT,
15307 					    l_cur_ptlpn_parent_lpn_id,
15308 					    l_wlpn_source_header_id);
15309 
15310 		  if (l_PTLPN_ID is not null ) then
15311 		     null;
15312 		  end if;
15313 	       end if;
15314 	    end if;
15315 	 end if; -- End of RECEIVE, DELIVER, TRANSFER, SHIP txn
15316 
15317 
15318 	 if (l_lpn_rec.transaction_type in ('CORRECT','RETURN TO VENDOR','RETURN TO RECEIVING', 'RETURN TO CUSTOMER'))
15319 	   then
15320 
15321 	    l_progress := 'WMSINB-19046';
15322 	    -- Get The Parent Txn Details
15323             Begin
15324 	       select transaction_type
15325 		 into l_parent_txn_type
15326 		 from rcv_transactions rt
15327 		 where rt.transaction_id = l_lpn_rec.parent_transaction_id;
15328 	    Exception
15329 	       When others then
15330 		  -- Review Later
15331 		  -- Set appropiate Message
15332 		  --
15333 		  null;
15334 	    End;
15335 
15336 	    -- Get The Grand Parent Txn Details
15337 	    -- May not be Needed for ALL CASES
15338             Begin
15339 	       select parent_transaction_id
15340 		 into l_parent_parent_txn_id
15341 		 from rcv_transactions rt
15342 		 where rt.transaction_id = l_lpn_rec.parent_transaction_id;
15343 	    Exception
15344 	       When others then
15345 		  null;
15346 	    End;
15347 
15348 	    -- Get The Grand Parent Txn TYPE Details
15349 	    -- May not be Needed for ALL CASES
15350             Begin
15351 	       select transaction_type
15352 		 into l_parent_parent_txn_type
15353 		 from rcv_transactions rt
15354 		 where rt.transaction_id = l_parent_parent_txn_id;
15355 	    Exception
15356 	       When others then
15357 		  null;
15358 	    End;
15359 
15360 	    -- Get The Grand Grand Parent Txn Details
15361 	    -- May not be Needed for ALL CASES
15362             Begin
15363 	       select parent_transaction_id
15364 		 into l_parent_parent_parent_txn_id
15365 		 from rcv_transactions rt
15366 		 where rt.transaction_id = l_parent_parent_txn_id;
15367 	    Exception
15368 	       When others then
15369 		  null;
15370 	    End;
15371 
15372 	    l_progress := 'WMSINB-19097';
15373 
15374 	    l_rs_ptid_exists := validate_rs(null,
15375 					    l_lpn_rec.parent_transaction_id,
15376 					    l_rs_ptid_lpn_id );
15377 
15378 	    l_rs_ptid_ptid_exists := validate_rs(null,
15379 						 l_parent_parent_txn_id,
15380 						 l_rs_ptid_ptid_lpn_id );
15381 
15382 	    l_rs_ptid_ptid_ptid_exists := validate_rs(null,
15383 						      l_parent_parent_parent_txn_id,
15384 						      l_rs_ptid_ptid_ptid_lpn_id );
15385 
15386 	    IF (l_debug = 1) THEN
15387 	       print_debug('VALIDATE_LPN_INFO: l_rs_ptid_lpn_id:'||l_rs_ptid_lpn_id,1);
15388 	       print_debug('VALIDATE_LPN_INFO: l_rs_ptid_ptid_lpn_id:'||l_rs_ptid_ptid_lpn_id,1);
15389 	       print_debug('VALIDATE_LPN_INFO: l_rs_ptid_ptid_ptid_lpn_id:'||l_rs_ptid_ptid_ptid_lpn_id,1);
15390 	    END IF;
15391 
15392 	    l_progress := 'WMSINB-19112';
15393 
15394 	    -- START OF NEGATIVE CORRECTION
15395 	    if (l_lpn_rec.transaction_type = 'CORRECT' and l_lpn_rec.quantity < 0 ) then  -- START OF NEGATIVE CORRECTION
15396 
15397 	       if l_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER','DELIVER') then
15398 
15399 		  if (l_lpn_rec.transfer_license_plate_number is not null or l_lpn_rec.transfer_lpn_id is not null) then
15400 
15401 		     if l_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER') then
15402 			l_progress := 'WMSINB-19122';
15403 			if l_lpn_rec.transfer_lpn_id is null then
15404 			   --  TRANSFER LPN DOES NOT EXIST IN THE SYSTEM
15405 			   -- FAIL the TXN
15406 			   -- Review Later
15407 			   -- Set appropiate Message
15408 			   --
15409 			   l_progress := 'WMSINB-19129';
15410 			   RAISE FND_API.G_EXC_ERROR;
15411 			 else
15412 			   -- TRANSFER LPN EXISTS in THE SYSTEM
15413 			   if l_transfer_lpn_context <> G_LPN_CONTEXT_RCV then
15414 			      -- Transfer LPN Context Invalid for this TXN
15415 			      -- FAIL the TXN
15416 			      -- Review Later
15417 			      -- Set appropiate Message
15418 			      --
15419 			      l_progress := 'WMSINB-19139';
15420 			      RAISE FND_API.G_EXC_ERROR;
15421 			   End if;
15422 			   l_progress := 'WMSINB-19142';
15423 			   --
15424 			   -- START CHECKING IN RCV_SUPPLY
15425 			   -- IF RS.PTID.TLPN NOT EXISTS THEN FAIL TXN
15426 
15427 			   if ( (l_rs_ptid_Exists <> TRUE) or ( nvl(l_lpn_rec.transfer_lpn_id,0) <>
15428 								nvl(l_rs_ptid_lpn_id,-9999)) ) then
15429 			      --
15430 			      -- FAIL the TXN
15431 			      -- Review Later
15432 			      -- Set appropiate Message
15433 			      --
15434 			      l_progress := 'WMSINB-19154';
15435 			      RAISE FND_API.G_EXC_ERROR;
15436 			   End if;
15437 			End if;
15438 		     End if; -- End of RECEIVE','ACCEPT','REJECT','TRANSFER TXN
15439 
15440 		     l_progress := 'WMSINB-19160';
15441 
15442 		     if l_parent_txn_type in ('DELIVER') then
15443 			if l_lpn_rec.transfer_lpn_id is null then
15444 			   --  TRANSFER LPN DOES NOT EXIST IN THE SYSTEM
15445 			   -- FAIL the TXN
15446 			   -- Review Later
15447 			   -- Set appropiate Message
15448 			   --
15449 			   l_progress := 'WMSINB-19169';
15450 			   RAISE FND_API.G_EXC_ERROR;
15451 			 else
15452 			   -- TRANSFER LPN EXISTS in THE SYSTEM
15453 			   if l_transfer_lpn_context <> G_LPN_CONTEXT_INV then
15454 			      -- Transfer LPN Context Invalid for this TXN
15455 			      -- FAIL the TXN
15456 			      -- Review Later
15457 			      -- Set appropiate Message
15458 			      --
15459 			      l_progress := 'WMSINB-19179';
15460 			      RAISE FND_API.G_EXC_ERROR;
15461 			   End if;
15462 
15463 --Start Bug:14805517
15464  IF (l_lpn_rec.lpn_id = l_lpn_rec.transfer_lpn_id) THEN
15465 
15466  l_WLPNIQLPN    := l_lpn_rec.license_plate_number;
15467  l_WLPNIQLPN_ID := l_lpn_rec.lpn_id;
15468 
15469  l_WLPNIQLPN_PARENT_LPN_ID := null;
15470 
15471 
15472 l_progress := 'WMSINB-19180';
15473 
15474 get_parent_lpn(l_WLPNIQLPN, l_WLPNIQLPN_PARENT_LPN_ID);
15475 		     --
15476     IF (l_debug = 1) THEN
15477       print_debug('VALIDATE_LPN_INFO - FROM WLPN l_WLPNIQLPN_PARENT_LPN_ID Inside Negative Correction:'||l_WLPNIQLPN_PARENT_LPN_ID,1);
15478     END If;
15479 
15480 	if l_WLPNIQLPN_PARENT_LPN_ID is not null then
15481 			l_progress := 'WMSINB-19181';
15482 			-- Call UNPACK API to unpack this LPN from parent LPN
15483 			-- Review Later
15484 			wms_container_pvt.packunpack_container(
15485 							       p_api_version            => 1.0,
15486 							       p_init_msg_list          => g_false,
15487 							       p_commit                 => g_false,
15488 							       p_validation_level       => fnd_api.g_valid_level_none,
15489 							       x_return_status          => x_return_status,
15490 							       x_msg_count              => l_msg_count,
15491 							       x_msg_data               => l_msg_data,
15492 							       p_lpn_id                 => l_WLPNIQLPN_PARENT_LPN_ID,
15493 							       p_content_lpn_id         => l_WLPNIQLPN_ID,
15494 							       p_organization_id        => l_lpn_rec.to_organization_id,  --bug for 13726378: change: from from_organization_id to to_orgnization_id
15495 							       p_operation              => 2 --- TO UNPACK
15496 							       );
15497 			IF (x_return_status <> g_ret_sts_success) THEN
15498 			   IF (l_debug = 1) THEN
15499 			      print_debug('VALIDATE_LPN_INFO: packunpack_container failed progress Inside negative Correction = ' || l_progress,1);
15500 			   END IF;
15501 			   l_progress := 'WMSINB-19182';
15502 			   RAISE fnd_api.g_exc_error;
15503 			END IF;
15504 			l_progress := 'WMSINB-19183';
15505 
15506     END IF ;
15507 
15508  END IF;
15509 
15510 --End  Bug:14805517
15511 
15512 
15513 			End if;
15514 		     End if;  -- End of DELIVER TXN
15515 
15516 		   Else -- Transfer LPN is null case
15517 		     if l_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER','DELIVER') then
15518 			if ( l_rs_ptid_lpn_id is not null) then
15519 			   -- FAIL the TXN
15520 			   -- Review Later
15521 			   -- Set appropiate Message
15522 			   --
15523 			   l_progress := 'WMSINB-19192';
15524 			   RAISE FND_API.G_EXC_ERROR;
15525 			End if;
15526 		     End if;
15527 		  End if; -- End of Transfer LPN Not null
15528 
15529 		  l_progress := 'WMSINB-19198';
15530 
15531 		  if (l_lpn_rec.lpn_id is not null or l_lpn_rec.license_plate_number is not null) then
15532 		     if l_parent_txn_type in ('RECEIVE') then
15533 			-- FAIL the TXN
15534 			-- Review Later
15535 			-- Set appropiate Message
15536 			--
15537 			l_progress := 'WMSINB-19206';
15538 			RAISE FND_API.G_EXC_ERROR;
15539 		     End if;
15540 
15541 		     IF ( ( NVL(l_lpn_rec.lpn_id,0) <> NVL(l_lpn_rec.transfer_lpn_id,0) ) OR
15542 			  ( NVL(l_lpn_rec.license_plate_number,'-9999') <> NVL(l_lpn_rec.transfer_license_plate_number,'-9999') )
15543 			  ) THEN
15544 
15545 			IF l_parent_txn_type in ('ACCEPT','REJECT','TRANSFER','DELIVER') THEN
15546 			   IF ( l_rs_ptid_ptid_exists <> TRUE ) THEN
15547 			      IF l_lpn_rec.lpn_id IS NOT NULL THEN
15548 				 IF l_lpn_context NOT IN (G_LPN_CONTEXT_RCV, G_LPN_CONTEXT_PREGENERATED) THEN
15549 				    -- FAIL the TXN
15550 				    -- Review Later
15551 				    -- Set appropiate Message
15552 				    --
15553 				    l_progress := 'WMSINB-19222';
15554 				    RAISE FND_API.G_EXC_ERROR;
15555 				 End if;
15556 				 -- Validate Locator
15557 				 -- Review Later
15558 				 l_lpn_match := 'N';
15559 				 validate_lpn_locator( p_lpn_id => l_lpn_rec.lpn_id,
15560 						       p_subinventory => l_lpn_rec.subinventory,
15561 						       p_locator_id   => l_lpn_rec.locator_id,
15562 						       p_organization_id  => l_lpn_rec.to_organization_id,
15563 						       x_lpn_match        => l_lpn_match,
15564 						       x_return_status    => x_return_status,
15565 						       x_msg_count        => x_msg_count,
15566 						       x_msg_data         => x_msg_data);
15567 
15568 				 l_progress := 'WMSINB-19237';
15569 				 if x_return_status <> G_RET_STS_SUCCESS Then
15570 				    --  Review Late Set Appropiate Message
15571 				    l_progress := 'WMSINB-19240';
15572 				    RAISE FND_API.G_EXC_ERROR;
15573 				 End if;
15574 
15575 				 l_progress := 'WMSINB-19244';
15576 
15577 				 if l_lpn_match = 'N' then
15578 				    l_progress := 'WMSINB-19247';
15579 				    RAISE FND_API.G_EXC_ERROR;
15580 				 End if;
15581 			       Else -- Create LPN with context as 3
15582 				 -- Create LPN Here
15583 				 l_progress := 'WMSINB-19252';
15584 				 create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.license_plate_number,
15585 						       p_lpn_group_id => p_lpn_group_id,
15586 						       p_organization_id => l_lpn_rec.to_organization_id,
15587 						       p_lpn_context => G_LPN_CONTEXT_RCV ,
15588 						       x_lpn_id => l_lpn_rec.lpn_id,
15589 						       x_return_status => x_return_status,
15590 						       x_msg_count => l_msg_count,
15591 						       x_msg_data => l_msg_data);
15592 				 -- Check the error status from the above call
15593 				 if x_return_status <> G_RET_STS_SUCCESS Then
15594 				    --  Review Late Set Appropiate Message
15595 				    l_progress := 'WMSINB-19264';
15596 				    RAISE FND_API.G_EXC_ERROR;
15597 				 End if;
15598 			      End if;
15599 			    Else -- RS.PTID.PTID Exists case supply LPN and FROM LPN SHOULD MATCH
15600 			      if (nvl(l_rs_ptid_ptid_lpn_id,-9999) <> nvl(l_lpn_rec.lpn_id,0) ) then
15601 				 -- FAIL the TXN
15602 				 -- Review Later
15603 				 -- Set appropiate Message
15604 				 --
15605 				 l_progress := 'WMSINB-19274';
15606 				 RAISE FND_API.G_EXC_ERROR;
15607 			      End if;
15608 			   End if;
15609 			End if;  -- END OF ACCEPT/REJECT/TRANSFER/DELIVER
15610 		      Elsif (l_lpn_rec.lpn_id = l_lpn_rec.transfer_lpn_id) then  -- FLPN and TLPN SAME
15611 			if l_parent_txn_type in ('ACCEPT','REJECT','TRANSFER','DELIVER') then
15612 			   if ( l_rs_ptid_ptid_exists = TRUE ) then
15613 			      if (nvl(l_rs_ptid_ptid_lpn_id,-9999) <> l_lpn_rec.lpn_id ) then
15614 				 -- FAIL the TXN
15615 				 -- Review Later
15616 				 -- Set appropiate Message
15617 				 --
15618 				 l_progress := 'WMSINB-19287';
15619 				 RAISE FND_API.G_EXC_ERROR;
15620 			      End if;
15621 			   End if;
15622 			End if;
15623 
15624 			-- Total QTY Validation and LOCATOR validation for Deliver Txn
15625 
15626 			l_progress := 'WMSINB-19295';
15627 			l_lpn_match := 'N';
15628 			validate_lpn_locator( p_lpn_id => l_lpn_rec.lpn_id,
15629 					      p_subinventory => l_lpn_rec.from_subinventory,
15630 					      p_locator_id   => l_lpn_rec.from_locator_id,
15631 					      p_organization_id  => l_lpn_rec.to_organization_id,
15632 					      x_lpn_match        => l_lpn_match,
15633 					      x_return_status    => x_return_status,
15634 					      x_msg_count        => x_msg_count,
15635 					      x_msg_data         => x_msg_data);
15636 
15637 			if x_return_status <> G_RET_STS_SUCCESS Then
15638 			   --  Review Late Set Appropiate Message
15639 			   l_progress := 'WMSINB-19308';
15640 			   RAISE FND_API.G_EXC_ERROR;
15641 			End if;
15642 
15643 			if ( (l_parent_txn_type in ('DELIVER')) or (l_lpn_match = 'N') ) then
15644 			   -- Call Total QTY VALIDATION API HERE
15645 			   validate_total_qty(p_lpn_group_id => p_lpn_group_id,
15646 					      p_from_lpn_id => l_lpn_rec.lpn_id,
15647 					      p_parent_lpn_id => l_cur_from_parent_lpn_id,
15648 					      p_transaction_type => l_lpn_rec.transaction_type,
15649 					      x_return_status    => x_return_status,
15650 					      x_msg_count        => x_msg_count,
15651 					      x_msg_data         => x_msg_data);
15652 
15653 			   l_progress := 'WMSINB-19322';
15654 
15655 			   if x_return_status <> G_RET_STS_SUCCESS Then
15656 			      --  Review Late Set Appropiate Message
15657 			      l_progress := 'WMSINB-19326';
15658 			      RAISE FND_API.G_EXC_ERROR;
15659 			   End if;
15660 			End if;
15661 		     End if;
15662 		  End if; -- End of From LPN not null
15663 
15664 	       End if; -- END OF PARENT TXN TYPE IN RECEIVE ACCEPT REJECT TRANSFER DELIVER
15665 	       --
15666 
15667 	       l_progress := 'WMSINB-19336';
15668 
15669 	       if l_parent_txn_type in ('RETURN TO VENDOR','RETURN TO RECEIVING', 'RETURN TO CUSTOMER') then
15670 
15671 		  l_progress := 'WMSINB-19340';
15672 
15673 		  if (l_lpn_rec.transfer_license_plate_number is not null) then
15674 		     if l_parent_txn_type in ('RETURN TO VENDOR', 'RETURN TO CUSTOMER') then
15675 			-- FAIL THE TXN
15676 			--  Review Late Set Appropiate Message
15677 			l_progress := 'WMSINB-19346';
15678 			RAISE FND_API.G_EXC_ERROR;
15679 		     End if;
15680 
15681 		     if l_parent_txn_type in ('RETURN TO RECEIVING') then
15682 			if l_lpn_rec.transfer_lpn_id is null then
15683 			   -- TRANSFER LPN DOES NOT EXISTS FAIL THE TXN
15684 			   --  Review Late Set Appropiate Message
15685 			   l_progress := 'WMSINB-19354';
15686 			   RAISE FND_API.G_EXC_ERROR;
15687 			 Else
15688 			   -- TRANSFER LPN EXIST
15689 			   if l_transfer_lpn_context <> G_LPN_CONTEXT_RCV then
15690 			      --  Review Late Set Appropiate Message
15691 			      l_progress := 'WMSINB-19360';
15692 			      RAISE FND_API.G_EXC_ERROR;
15693 			   End if;
15694 			   --
15695 			   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
15696 			      --  Review Late Set Appropiate Message
15697 			      l_progress := 'WMSINB-19366';
15698 			      RAISE FND_API.G_EXC_ERROR;
15699 			   End if;
15700 			End if;
15701 		     End if; -- END OF RTR
15702 		   Else    -- TRANSFER LPN NULL
15703 		     if l_parent_txn_type in ('RETURN TO RECEIVING') then
15704 			if l_rs_ptid_ptid_ptid_lpn_id is not null then -- SUPPLY EXISTS WITH LPN SO FAIL THE TXN
15705 			   --  Review Late Set Appropiate Message
15706 			   l_progress := 'WMSINB-19375';
15707 			   RAISE FND_API.G_EXC_ERROR;
15708 			End if;
15709 		     End if;
15710 		  End if; -- END OF TRANSFER LPN NULL
15711 
15712 		  if (l_lpn_rec.lpn_id is not null or l_lpn_rec.license_plate_number is not null ) then
15713 		     if ( ( nvl(l_lpn_rec.lpn_id,0) <> nvl(l_lpn_rec.transfer_lpn_id,0) ) or
15714 			  ( nvl(l_lpn_rec.license_plate_number,'-9999') <> nvl(l_lpn_rec.transfer_license_plate_number,'-9999') )
15715 			  ) then
15716 			if l_parent_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER') then
15717 			   if l_rs_ptid_ptid_exists <> TRUE then
15718 			      if l_lpn_rec.lpn_id is not null then
15719 				 if l_lpn_context not in (G_LPN_CONTEXT_RCV , G_LPN_CONTEXT_PREGENERATED ) then
15720 				    -- FAIL the TXN
15721 				    -- Review Later
15722 				    -- Set appropiate Message
15723 				    --
15724 				    l_progress := 'WMSINB-19393';
15725 				    RAISE FND_API.G_EXC_ERROR;
15726 				 End if;
15727 				 -- Validate Locator
15728 				 -- Review Later
15729 				 l_lpn_match := 'N';
15730 				 validate_lpn_locator( p_lpn_id => l_lpn_rec.lpn_id,
15731 						       p_subinventory => l_lpn_rec.from_subinventory,
15732 						       p_locator_id   => l_lpn_rec.from_locator_id,
15733 						       p_organization_id  => l_lpn_rec.to_organization_id,
15734 						       x_lpn_match        => l_lpn_match,
15735 						       x_return_status    => x_return_status,
15736 						       x_msg_count        => x_msg_count,
15737 						       x_msg_data         => x_msg_data);
15738 
15739 				 if x_return_status <> G_RET_STS_SUCCESS Then
15740 				    --  Review Late Set Appropiate Message
15741 				    l_progress := 'WMSINB-19410';
15742 				    RAISE FND_API.G_EXC_ERROR;
15743 				 End if;
15744 
15745 				 if l_lpn_match = 'N' then
15746 				    l_progress := 'WMSINB-19415';
15747 				    RAISE FND_API.G_EXC_ERROR;
15748 				 End if;
15749 			       Else -- LPN ID NULL CASE
15750 				 -- Create LPN Here
15751 				 create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.license_plate_number,
15752 						       p_lpn_group_id => p_lpn_group_id,
15753 						       p_organization_id => l_lpn_rec.to_organization_id,
15754 						       p_lpn_context => G_LPN_CONTEXT_RCV ,
15755 						       x_lpn_id => l_lpn_rec.lpn_id,
15756 						       x_return_status => x_return_status,
15757 						       x_msg_count => l_msg_count,
15758 						       x_msg_data => l_msg_data);
15759 				 -- Check the error status from the above call
15760 				 if x_return_status <> G_RET_STS_SUCCESS Then
15761 				    --  Review Late Set Appropiate Message
15762 				    l_progress := 'WMSINB-19431';
15763 				    RAISE FND_API.G_EXC_ERROR;
15764 				 End if;
15765 			      End if;
15766 			    Else -- RS.PTID.PTID EXISTS
15767 			      if (nvl(l_rs_ptid_ptid_lpn_id, -9999) <> l_lpn_rec.lpn_id ) then
15768 				 --  Review Late Set Appropiate Message
15769 				 l_progress := 'WMSINB-19438';
15770 				 RAISE FND_API.G_EXC_ERROR;
15771 			      End if;
15772 			   End if;
15773 			End if; -- END OF PTID.PTID.TXNTYPE IN RECEIVE/ACCEPT/REJECT/TRANSFER
15774 
15775 			if l_parent_parent_txn_type in ('DELIVER') then
15776 			   if l_lpn_rec.lpn_id is not null then
15777 			      if l_lpn_context not in (G_LPN_CONTEXT_INV , G_LPN_CONTEXT_PREGENERATED) then
15778 				 -- FAIL the TXN
15779 				 -- Review Later
15780 				 -- Set appropiate Message
15781 				 --
15782 				 l_progress := 'WMSINB-19451';
15783 				 RAISE FND_API.G_EXC_ERROR;
15784 			      End if;
15785 			      -- Validate Locator
15786 			      -- Review Later
15787 			      l_lpn_match := 'N';
15788 			      validate_lpn_locator( p_lpn_id => l_lpn_rec.lpn_id,
15789 						    p_subinventory => l_lpn_rec.from_subinventory,
15790 						    p_locator_id   => l_lpn_rec.from_locator_id,
15791 						    p_organization_id  => l_lpn_rec.to_organization_id,
15792 						    x_lpn_match        => l_lpn_match,
15793 						    x_return_status    => x_return_status,
15794 						    x_msg_count        => x_msg_count,
15795 						    x_msg_data         => x_msg_data);
15796 
15797 			      l_progress := 'WMSINB-19466';
15798 			      if x_return_status <> G_RET_STS_SUCCESS Then
15799 				 --  Review Late Set Appropiate Message
15800 				 l_progress := 'WMSINB-19469';
15801 				 RAISE FND_API.G_EXC_ERROR;
15802 			      End if;
15803 
15804 			      if l_lpn_match = 'N' then
15805 				 l_progress := 'WMSINB-19474';
15806 				 RAISE FND_API.G_EXC_ERROR;
15807 			      End if;
15808 			    Else -- LPN ID NULL CASE
15809 			      -- Create LPN Here
15810 			      l_progress := 'WMSINB-19479';
15811 			      create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.license_plate_number,
15812 						    p_lpn_group_id => p_lpn_group_id,
15813 						    p_organization_id => l_lpn_rec.to_organization_id,
15814 						    p_lpn_context => G_LPN_CONTEXT_INV,
15815 						    x_lpn_id => l_lpn_rec.lpn_id,
15816 						    x_return_status => x_return_status,
15817 						    x_msg_count => l_msg_count,
15818 						    x_msg_data => l_msg_data);
15819 			      -- Check the error status from the above call
15820 			      if x_return_status <> G_RET_STS_SUCCESS Then
15821 				 --  Review Late Set Appropiate Message
15822 				 l_progress := 'WMSINB-19491';
15823 				 RAISE FND_API.G_EXC_ERROR;
15824 			      End if;
15825 			   End if; -- END OF LPN ID NOT NULL CASE
15826 			End if; --END OF PTID.TXNTYPE DELIVER
15827 		      Elsif (l_lpn_rec.lpn_id = l_lpn_rec.transfer_lpn_id) then
15828                      --Bug 5550783 start
15829                      IF (l_debug = 1) THEN
15830                         print_debug('expess_transaction check: ' || l_lpn_rec.express_transaction, 1);
15831                      END If;
15832                      --Bug 5550783 end
15833                      --Do not do the validate_total_qty if it is express transaction and also if it is a Mobil Deliver/Transfer
15834                      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
15835                          IF (l_debug = 1) THEN
15836                             print_debug('l_lpn_rec.express_transaction', 1);
15837                             print_debug('VALIDATE_LPN_INFO - Not doing validate_total_qty ...', 1);
15838                          END If;
15839 
15840                      Else
15841                      print_debug('l_lpn_rec.express_transaction-1', 1);
15842                         -- Call Total QTY VALIDATION API HERE
15843 			l_progress := 'WMSINB-19498';
15844 			validate_total_qty(p_lpn_group_id => p_lpn_group_id,
15845 					   p_from_lpn_id => l_lpn_rec.lpn_id,
15846 					   p_parent_lpn_id => l_cur_from_parent_lpn_id,
15847 					   p_transaction_type => l_lpn_rec.transaction_type,
15848 					   x_return_status    => x_return_status,
15849 					   x_msg_count        => x_msg_count,
15850 					   x_msg_data         => x_msg_data);
15851 
15852 			if x_return_status <> G_RET_STS_SUCCESS Then
15853 			   --  Review Late Set Appropiate Message
15854 			   l_progress := 'WMSINB-19509';
15855 			   RAISE FND_API.G_EXC_ERROR;
15856 			End if;
15857                        End if;--Bug 5550783
15858 		     End if; -- END OF TLPN and FLPN DIFFERENT
15859 		   Else -- FROM LPN NULL
15860 		     l_progress := 'WMSINB-19514';
15861 		     if l_parent_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER') then
15862 			if ( l_rs_ptid_ptid_exists = TRUE and l_rs_ptid_ptid_lpn_id is not null) then
15863 			   --  Review Late Set Appropiate Message
15864 			   l_progress := 'WMSINB-19518';
15865 			   RAISE FND_API.G_EXC_ERROR;
15866 			End if;
15867 		     End if;
15868 		  End if; -- END OF FROM LPN NOT NULL CASE
15869 	       End if; --END OF RTR RTV RTC
15870 
15871 	       -- ******************************************************
15872 	       -- END OF NEGATIVE CORRECTION
15873 	       --************************************************************
15874 
15875 	       -- START OF POSITIVE CORRECTION
15876 
15877 	     Elsif ( ( l_lpn_rec.transaction_type = 'CORRECT' and l_lpn_rec.quantity > 0 )
15878 		     or (l_lpn_rec.transaction_type in ('RETURN TO VENDOR','RETURN TO RECEIVING', 'RETURN TO CUSTOMER')) ) then
15879 
15880 	       l_progress := 'WMSINB-19534';
15881 
15882 	       if l_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER','DELIVER') then
15883 		  l_progress := 'WMSINB-19537';
15884 
15885 		  if ( l_lpn_rec.lpn_id is not null or l_lpn_rec.license_plate_number is not null ) then
15886 		     if (l_parent_txn_type = 'RECEIVE' and l_lpn_rec.transaction_type = 'CORRECT') then
15887 			--  Review Late Set Appropiate Message
15888 			l_progress := 'WMSINB-19542';
15889 			RAISE FND_API.G_EXC_ERROR;
15890 		     End if;
15891 
15892 		     if l_lpn_rec.lpn_id is null then
15893 			--  Review Late Set Appropiate Message
15894 			l_progress := 'WMSINB-19548';
15895 			RAISE FND_API.G_EXC_ERROR;
15896 		      Else -- FLPN Exists
15897 			if l_lpn_rec.transaction_type = 'CORRECT' then
15898 			   if l_lpn_context not in (G_LPN_CONTEXT_RCV ) then
15899 			      --  Review Late Set Appropiate Message
15900 			      l_progress := 'WMSINB-19554';
15901 			      RAISE FND_API.G_EXC_ERROR;
15902 			   End if;
15903 
15904 			   -- Case WHERE FROM LPN and SUPPLY LPN mismatch fail the TXN
15905 			   if (l_lpn_rec.lpn_id <> nvl(l_rs_ptid_ptid_lpn_id,-9999)) then
15906 			      --  Review Late Set Appropiate Message
15907 			      l_progress := 'WMSINB-19561';
15908 			      RAISE FND_API.G_EXC_ERROR;
15909 			   End if;
15910 			 Else -- case for RTV/RTR/RTC
15911 			   if l_parent_txn_type in ('DELIVER') then
15912 			      if l_lpn_context not in (G_LPN_CONTEXT_INV) then
15913 				 --  Review Late Set Appropiate Message
15914 				 l_progress := 'WMSINB-19568';
15915 				 RAISE FND_API.G_EXC_ERROR;
15916 			      End if;
15917 			    Else
15918 			      if l_lpn_context not in (G_LPN_CONTEXT_RCV) then
15919 				 --  Review Late Set Appropiate Message
15920 				 l_progress := 'WMSINB-19574';
15921 				 RAISE FND_API.G_EXC_ERROR;
15922 			      End if;
15923 			      if ( ( l_rs_ptid_exists <> TRUE ) or (l_lpn_rec.lpn_id <> nvl(l_rs_ptid_lpn_id, -9999)) ) then
15924 				 --  Review Late Set Appropiate Message
15925 				 l_progress := 'WMSINB-19579';
15926 				 RAISE FND_API.G_EXC_ERROR;
15927 			      End if;
15928 			   End if; -- END OF parent_txn_type as DELIVER
15929 			End if; -- END OF TXNTYPE CORRECT
15930 		     End if; -- WLPN.FLPN exists CASE
15931 		   Else -- CASE WHERE FLPN IS NULL
15932 		     if l_lpn_rec.transaction_type in ('CORRECT') then
15933 			if (l_rs_ptid_ptid_exists = TRUE) then
15934 			   if (l_rs_ptid_ptid_lpn_id is not null) then
15935 			      --  Review Late Set Appropiate Message
15936 			      l_progress := 'WMSINB-19590';
15937 			      RAISE FND_API.G_EXC_ERROR;
15938 			   End if;
15939 			End if;
15940 		      Else  -- Transaction for RTV/RTR/RTC
15941 			if (l_rs_ptid_exists = TRUE ) then
15942 			   if (l_rs_ptid_ptid_lpn_id is not null ) then
15943 			      --  Review Late Set Appropiate Message
15944 			      l_progress := 'WMSINB-19598';
15945 			      RAISE FND_API.G_EXC_ERROR;
15946 			   End if;
15947 			End if;
15948 		     End if; -- END OF transaction_type CORRECT
15949 		  End if; -- END OF FLPN NOT NULL CASE
15950 
15951 		  if (l_lpn_rec.transfer_lpn_id is not null or l_lpn_rec.transfer_license_plate_number is not null ) then
15952 		     if ( ( nvl(l_lpn_rec.lpn_id,0) <> nvl(l_lpn_rec.transfer_lpn_id,0) ) or
15953 			  ( nvl(l_lpn_rec.license_plate_number,'-9999') <> nvl(l_lpn_rec.transfer_license_plate_number,'-9999') )
15954 			  ) then
15955 			l_progress := 'WMSINB-19609';
15956 			if l_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER') then
15957 			   if l_lpn_rec.transaction_type in ('CORRECT') then
15958 			      if (l_rs_ptid_ptid_exists <> TRUE) then
15959 				 if l_lpn_rec.transfer_lpn_id is not null then
15960 				    if l_transfer_lpn_context not in (G_LPN_CONTEXT_RCV ,G_LPN_CONTEXT_PREGENERATED ) then
15961 				       --  Review Late Set Appropiate Message
15962 				       l_progress := 'WMSINB-19616';
15963 				       RAISE FND_API.G_EXC_ERROR;
15964 				    End if;
15965 
15966 				    -- Validate Locator
15967 				    -- Review Later
15968 				    l_lpn_match := 'N';
15969 				    validate_lpn_locator( p_lpn_id => l_lpn_rec.transfer_lpn_id,
15970 							  p_subinventory => l_lpn_rec.subinventory,
15971 							  p_locator_id   => l_lpn_rec.locator_id,
15972 							  p_organization_id  => l_lpn_rec.to_organization_id,
15973 							  x_lpn_match        => l_lpn_match,
15974 							  x_return_status    => x_return_status,
15975 							  x_msg_count        => x_msg_count,
15976 							  x_msg_data         => x_msg_data);
15977 
15978 				    l_progress := 'WMSINB-19632';
15979 
15980 				    if x_return_status <> G_RET_STS_SUCCESS Then
15981 				       --  Review Late Set Appropiate Message
15982 				       l_progress := 'WMSINB-19636';
15983 				       RAISE FND_API.G_EXC_ERROR;
15984 				    End if;
15985 
15986 				    if l_lpn_match = 'N' then
15987 				       l_progress := 'WMSINB-19641';
15988 				       RAISE FND_API.G_EXC_ERROR;
15989 				    End if;
15990 				  Else
15991 				    -- Create LPN Here
15992 				    l_progress := 'WMSINB-19646';
15993 				    create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.transfer_license_plate_number,
15994 							  p_lpn_group_id => p_lpn_group_id,
15995 							  p_organization_id => l_lpn_rec.to_organization_id,
15996 							  p_lpn_context => G_LPN_CONTEXT_RCV,
15997 							  x_lpn_id => l_lpn_rec.transfer_lpn_id,
15998 							  x_return_status => x_return_status,
15999 							  x_msg_count => l_msg_count,
16000 							  x_msg_data => l_msg_data);
16001 				    -- Check the error status from the above call
16002 				    if x_return_status <> G_RET_STS_SUCCESS Then
16003 				       --  Review Late Set Appropiate Message
16004 				       l_progress := 'WMSINB-19658';
16005 				       RAISE FND_API.G_EXC_ERROR;
16006 				    End if;
16007 				 End if;
16008 			       Else
16009 				 -- CHECK THE LPN IN SUPPLY
16010 				 --BUG 4502518 Issue 34: Positive Correction of Transfer
16011 				 --User can't change LPN if RS exists for the
16012 				 --Transfer txn.  In this case, make sure that
16013 				 --the transfer_lpn_id is tied to that RS.
16014 				 IF (l_rs_ptid_exists = TRUE) THEN
16015 				     if (l_lpn_rec.transfer_lpn_id <> nvl(l_rs_ptid_lpn_id,-9999) ) then
16016 					--  Review Late Set Appropiate Message
16017 					l_progress := 'WMSINB-19666';
16018 					RAISE FND_API.G_EXC_ERROR;
16019 				     END IF;
16020 				 END IF;
16021 			      End if;-- END OF RS EXISTS
16022 			    Else -- THIS PART FOR RTV/RTR/RTC . THIS LPN WILL BE FINALLY ISSUED OUT
16023 			      if l_lpn_rec.transfer_lpn_id is not null then
16024 				 if l_transfer_lpn_context not in (G_LPN_CONTEXT_PREGENERATED) then
16025 				    --  Review Late Set Appropiate Message
16026 				    l_progress := 'WMSINB-19674';
16027 				    RAISE FND_API.G_EXC_ERROR;
16028 				 End if;
16029 			       Else -- TRANSFER LPN DOES NOT EXIST IN THE SYETEM
16030 				 -- Create LPN Here
16031 				 l_progress := 'WMSINB-19679';
16032 				 create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.transfer_license_plate_number,
16033 						       p_lpn_group_id => p_lpn_group_id,
16034 						       p_organization_id => l_lpn_rec.to_organization_id,
16035 						       p_lpn_context => G_LPN_CONTEXT_STORES,
16036 						       x_lpn_id => l_lpn_rec.transfer_lpn_id,
16037 						       x_return_status => x_return_status,
16038 						       x_msg_count => l_msg_count,
16039 						       x_msg_data => l_msg_data);
16040 				 -- Check the error status from the above call
16041 				 if x_return_status <> G_RET_STS_SUCCESS Then
16042 				    --  Review Late Set Appropiate Message
16043 				    l_progress := 'WMSINB-19691';
16044 				    RAISE FND_API.G_EXC_ERROR;
16045 				 End if;
16046 			      End if;
16047 			   End if; -- END OF parent_txn_type CORRECT
16048 			End if; -- END OF 'RECEIVE','ACCEPT','REJECT','TRANSFER'
16049 
16050 			if l_parent_txn_type in ('DELIVER') then
16051 			   if l_lpn_rec.transfer_lpn_id is not null then
16052 			      if l_lpn_rec.transaction_type = 'CORRECT' then
16053 				 if l_transfer_lpn_context not in (G_LPN_CONTEXT_INV ,G_LPN_CONTEXT_PREGENERATED ) then
16054 				    --  Review Late Set Appropiate Message
16055 				    l_progress := 'WMSINB-19703';
16056 				    RAISE FND_API.G_EXC_ERROR;
16057 				 End if;
16058 				 -- Validate Locator
16059 				 -- Review Later
16060 				 l_lpn_match := 'N';
16061 				 validate_lpn_locator( p_lpn_id => l_lpn_rec.transfer_lpn_id,
16062 						       p_subinventory => l_lpn_rec.subinventory,
16063 						       p_locator_id   => l_lpn_rec.locator_id,
16064 						       p_organization_id  => l_lpn_rec.to_organization_id,
16065 						       x_lpn_match        => l_lpn_match,
16066 						       x_return_status    => x_return_status,
16067 						       x_msg_count        => x_msg_count,
16068 						       x_msg_data         => x_msg_data);
16069 
16070 				 l_progress := 'WMSINB-19718';
16071 
16072 				 if x_return_status <> G_RET_STS_SUCCESS Then
16073 				    --  Review Late Set Appropiate Message
16074 				    l_progress := 'WMSINB-19722';
16075 				    RAISE FND_API.G_EXC_ERROR;
16076 				 End if;
16077 
16078 				 if l_lpn_match = 'N' then
16079 				    l_progress := 'WMSINB-19727';
16080 				    RAISE FND_API.G_EXC_ERROR;
16081 				 End if;
16082 			       Elsif l_lpn_rec.transaction_type in ('RETURN TO VENDOR', 'RETURN TO CUSTOMER' ) then
16083 				 if l_transfer_lpn_context not in (G_LPN_CONTEXT_PREGENERATED) then
16084 				    --  Review Late Set Appropiate Message
16085 				    l_progress := 'WMSINB-19733';
16086 				    RAISE FND_API.G_EXC_ERROR;
16087 				 End if;
16088 			       Elsif  l_lpn_rec.transaction_type in ('RETURN TO RECEIVING' ) then
16089 				 if l_rs_ptid_ptid_exists <> TRUE then
16090 				    if l_transfer_lpn_context not in (G_LPN_CONTEXT_PREGENERATED ,G_LPN_CONTEXT_RCV ) then
16091 				       --  Review Late Set Appropiate Message
16092 				       l_progress := 'WMSINB-19740';
16093 				       RAISE FND_API.G_EXC_ERROR;
16094 				    End if;
16095 				    -- Validate Locator
16096 				    -- Review Later
16097 				    l_lpn_match := 'N';
16098 				    l_progress := 'WMSINB-19746';
16099 				    validate_lpn_locator( p_lpn_id => l_lpn_rec.transfer_lpn_id,
16100 							  p_subinventory => l_lpn_rec.subinventory,
16101 							  p_locator_id   => l_lpn_rec.locator_id,
16102 							  p_organization_id  => l_lpn_rec.to_organization_id,
16103 							  x_lpn_match        => l_lpn_match,
16104 							  x_return_status    => x_return_status,
16105 							  x_msg_count        => x_msg_count,
16106 							  x_msg_data         => x_msg_data);
16107 
16108 				    if x_return_status <> G_RET_STS_SUCCESS Then
16109 				       --  Review Late Set Appropiate Message
16110 				       l_progress := 'WMSINB-19758';
16111 				       RAISE FND_API.G_EXC_ERROR;
16112 				    End if;
16113 
16114 				    if l_lpn_match = 'N' then
16115 				       l_progress := 'WMSINB-19763';
16116 				       RAISE FND_API.G_EXC_ERROR;
16117 				    End if;
16118 				  Else
16119 				    if (l_lpn_rec.transfer_lpn_id <> nvl(l_rs_ptid_ptid_lpn_id,-9999) ) then
16120 				       --  Review Late Set Appropiate Message
16121 				       l_progress := 'WMSINB-19769';
16122 				       RAISE FND_API.G_EXC_ERROR;
16123 				    End if;
16124 				 End if;
16125 			      End if; -- END OF RTR
16126 
16127 			    Else -- TRANSFER LPN DOES NOT EXIST IN THE SYSTEM
16128 			      if l_lpn_rec.transaction_type = 'RETURN TO RECEIVING' then
16129 				 if (l_rs_ptid_ptid_exists = TRUE ) then
16130 				    --  Review Late Set Appropiate Message
16131 				    l_progress := 'WMSINB-19779';
16132 				    RAISE FND_API.G_EXC_ERROR;
16133 				 End if;
16134 				 --
16135 				 -- Create NEW LPN For TLPN
16136 				 create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.transfer_license_plate_number,
16137 						       p_lpn_group_id => p_lpn_group_id,
16138 						       p_organization_id => l_lpn_rec.to_organization_id,
16139 						       p_lpn_context => G_LPN_CONTEXT_RCV,
16140 						       x_lpn_id => l_lpn_rec.transfer_lpn_id,
16141 						       x_return_status => x_return_status,
16142 						       x_msg_count => l_msg_count,
16143 						       x_msg_data => l_msg_data);
16144 				 -- Check the error status from the above call
16145 				 if x_return_status <> G_RET_STS_SUCCESS Then
16146 				    --  Review Late Set Appropiate Message
16147 				    l_progress := 'WMSINB-19795';
16148 				    RAISE FND_API.G_EXC_ERROR;
16149 				 End if;
16150 			      End if;
16151 			   End if; -- TRANSFER LPN ID NOT NULL
16152 
16153 			End if; -- END OF DELIVER
16154 
16155 		      Else -- FLPN and TLPN Same
16156 			if l_lpn_rec.transaction_type = 'RETURN TO RECEIVING' then
16157 			   if (l_rs_ptid_ptid_exists = TRUE and l_lpn_rec.transfer_lpn_id <> nvl(l_rs_ptid_ptid_lpn_id,-9999)) then
16158 			      --  Review Late Set Appropiate Message
16159 			      l_progress := 'WMSINB-19807';
16160 			      RAISE FND_API.G_EXC_ERROR;
16161 			   End if;
16162 			 Elsif (l_lpn_rec.transaction_type  = 'CORRECT' and l_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER')) then
16163 			   if l_rs_ptid_exists = TRUE then
16164 			      l_progress := 'WMSINB-19812';
16165 			      if (l_lpn_rec.transfer_lpn_id <> nvl(l_rs_ptid_lpn_id,-9999)) then
16166 				 --  Review Late Set Appropiate Message
16167 				 RAISE FND_API.G_EXC_ERROR;
16168 			      End if;
16169 			   End if;
16170 			End if;
16171 
16172 			-- Total QTY Validation and LOCATOR validation for Deliver Txn
16173 
16174 			l_lpn_match := 'N';
16175 			validate_lpn_locator( p_lpn_id => l_lpn_rec.lpn_id,
16176 					      p_subinventory => l_lpn_rec.from_subinventory,
16177 					      p_locator_id   => l_lpn_rec.from_locator_id,
16178 					      p_organization_id  => l_lpn_rec.to_organization_id,
16179 					      x_lpn_match        => l_lpn_match,
16180 					      x_return_status    => x_return_status,
16181 					      x_msg_count        => x_msg_count,
16182 					      x_msg_data         => x_msg_data);
16183 
16184 			if x_return_status <> G_RET_STS_SUCCESS Then
16185 			   --  Review Late Set Appropiate Message
16186 			   l_progress := 'WMSINB-19834';
16187 			   RAISE FND_API.G_EXC_ERROR;
16188 			End if;
16189 
16190 			if ( (l_parent_txn_type in ('DELIVER')) or (l_lpn_match = 'N') ) then
16191 			   -- Call Total QTY VALIDATION API HERE
16192 			   l_progress := 'WMSINB-19840';
16193 			   validate_total_qty(p_lpn_group_id => p_lpn_group_id,
16194 					      p_from_lpn_id => l_lpn_rec.lpn_id,
16195 					      p_parent_lpn_id => l_cur_from_parent_lpn_id,
16196 					      p_transaction_type => l_lpn_rec.transaction_type,
16197 					      x_return_status    => x_return_status,
16198 					      x_msg_count        => x_msg_count,
16199 					      x_msg_data         => x_msg_data);
16200 
16201 			   if x_return_status <> G_RET_STS_SUCCESS Then
16202 			      --  Review Late Set Appropiate Message
16203 			      l_progress := 'WMSINB-19851';
16204 			      RAISE FND_API.G_EXC_ERROR;
16205 			   End if;
16206 			End if;
16207 
16208 		     End if; --END OF FLPN AND TLPN DIFFERENT
16209 
16210 		   Else --   TLPN NULL CASE
16211 		     if l_lpn_rec.transaction_type = 'RETURN TO RECEIVING' then
16212 			if (l_rs_ptid_ptid_lpn_id is not null) then
16213 			   --  Review Late Set Appropiate Message
16214 			   l_progress := 'WMSINB-19862';
16215 			   RAISE FND_API.G_EXC_ERROR;
16216 			End if;
16217 		      Elsif (l_lpn_rec.transaction_type  = 'CORRECT' and l_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER')) then
16218 			if (l_rs_ptid_lpn_id is not null ) then
16219 			   --  Review Late Set Appropiate Message
16220 			   l_progress := 'WMSINB-19868';
16221 			   RAISE FND_API.G_EXC_ERROR;
16222 			End if;
16223 		     End if;
16224 
16225 		  End if; --END OF TRANSFER LPN NOT NULL CASE
16226 
16227 	       End if; -- END OF parent_txn_type as RECEIVE ACCEPT REJECT TRANSFER DELIVER
16228 
16229 	       if l_parent_txn_type in ('RETURN TO VENDOR','RETURN TO RECEIVING', 'RETURN TO CUSTOMER') then -- ONLY FOR TXNTYPE AS CORRECT THIS WILL HAPPEN
16230 
16231 		  l_progress := 'WMSINB-19879';
16232 
16233 		  if ( l_lpn_rec.lpn_id is not null or l_lpn_rec.license_plate_number is not null ) then
16234 
16235 		     if l_parent_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER') then
16236 			if l_lpn_rec.lpn_id is null then
16237 			   --  Review Late Set Appropiate Message
16238 			   l_progress := 'WMSINB-19886';
16239 			   RAISE FND_API.G_EXC_ERROR;
16240 			 Else
16241 			   if l_lpn_context not in (G_LPN_CONTEXT_RCV) then
16242 			      --  Review Late Set Appropiate Message
16243 			      l_progress := 'WMSINB-19891';
16244 			      RAISE FND_API.G_EXC_ERROR;
16245 			   End if;
16246 			   --
16247 			   if ( l_lpn_rec.lpn_id <> nvl(l_rs_ptid_ptid_lpn_id,-9999)) then
16248 			      --  Review Late Set Appropiate Message
16249 			      l_progress := 'WMSINB-19897';
16250 			      RAISE FND_API.G_EXC_ERROR;
16251 			   End if;
16252 			End if;
16253 		     End if; -- END OF PTID.PTID txntype as RECEIVE ACCEPT REJECT TRANSFER
16254 
16255 		     if l_parent_parent_txn_type in ('DELIVER') then
16256 			if l_lpn_rec.lpn_id is null then
16257 			   --  Review Late Set Appropiate Message
16258 			   l_progress := 'WMSINB-19906';
16259 			   RAISE FND_API.G_EXC_ERROR;
16260 			 Else
16261 			   if l_lpn_context <> G_LPN_CONTEXT_INV then
16262 			      --  Review Late Set Appropiate Message
16263 			      l_progress := 'WMSINB-19911';
16264 			      RAISE FND_API.G_EXC_ERROR;
16265 			   End if;
16266 			End if;
16267 		     End if; --END OF PTID.PTID txntype as DELIVER
16268 		   Else -- FROM LPN NULL
16269 		     if l_parent_parent_txn_type in ('RECEIVE','ACCEPT','REJECT','TRANSFER') then
16270 			if l_rs_ptid_ptid_lpn_id is not null then
16271 			   --  Review Late Set Appropiate Message
16272 			   l_progress := 'WMSINB-19920';
16273 			   RAISE FND_API.G_EXC_ERROR;
16274 			End if;
16275 		     End if;
16276 		  End if; -- END OF FROM LPN NOT NULL
16277 
16278 		  if ( l_lpn_rec.transfer_lpn_id is not null or l_lpn_rec.transfer_license_plate_number is not null ) then
16279 		     if l_parent_txn_type in ('RETURN TO VENDOR','RETURN TO CUSTOMER') then
16280 			--  Review Late Set Appropiate Message
16281 			l_progress := 'WMSINB-19929';
16282 			RAISE FND_API.G_EXC_ERROR;
16283 		     End if;
16284 
16285 		     if ( ( nvl(l_lpn_rec.lpn_id,0) <> nvl(l_lpn_rec.transfer_lpn_id,0) ) or
16286 			  ( nvl(l_lpn_rec.license_plate_number,'-9999') <> nvl(l_lpn_rec.transfer_license_plate_number,'-9999') )
16287 			  ) then
16288 			if l_parent_txn_type in ('RETURN TO RECEIVING') then
16289 			   if (l_rs_ptid_ptid_exists <> TRUE) then
16290 			      if l_lpn_rec.transfer_lpn_id is not null then
16291 
16292 				 if l_transfer_lpn_context not in (G_LPN_CONTEXT_PREGENERATED ,G_LPN_CONTEXT_INV ) then
16293 				    --  Review Late Set Appropiate Message
16294 				    l_progress := 'WMSINB-19942';
16295 				    RAISE FND_API.G_EXC_ERROR;
16296 				 End if;
16297 
16298 				 l_progress := 'WMSINB-19946';
16299 				 -- Validate Locator
16300 				 -- Review Later
16301 				 l_lpn_match := 'N';
16302 				 validate_lpn_locator( p_lpn_id => l_lpn_rec.transfer_lpn_id,
16303 						       p_subinventory => l_lpn_rec.subinventory,
16304 						       p_locator_id   => l_lpn_rec.locator_id,
16305 						       p_organization_id  => l_lpn_rec.to_organization_id,
16306 						       x_lpn_match        => l_lpn_match,
16307 						       x_return_status    => x_return_status,
16308 						       x_msg_count        => x_msg_count,
16309 						       x_msg_data         => x_msg_data);
16310 
16311 				 if x_return_status <> G_RET_STS_SUCCESS Then
16312 				    --  Review Late Set Appropiate Message
16313 				    l_progress := 'WMSINB-19961';
16314 				    RAISE FND_API.G_EXC_ERROR;
16315 				 End if;
16316 
16317 				 if l_lpn_match = 'N' then
16318 				    l_progress := 'WMSINB-19966';
16319 				    RAISE FND_API.G_EXC_ERROR;
16320 				 End if;
16321 
16322 			       Else -- TRANSFER LPN DOES NOT EXIST IN THE SYSTEM
16323 				 -- Create NEW LPN For TLPN
16324 				 l_progress := 'WMSINB-19972';
16325 				 create_lpn_from_wlpni(p_license_plate_number => l_lpn_rec.transfer_license_plate_number,
16326 						       p_lpn_group_id => p_lpn_group_id,
16327 						       p_organization_id => l_lpn_rec.to_organization_id,
16328 						       p_lpn_context => G_LPN_CONTEXT_RCV,
16329 						       x_lpn_id => l_lpn_rec.transfer_lpn_id,
16330 						       x_return_status => x_return_status,
16331 						       x_msg_count => l_msg_count,
16332 						       x_msg_data => l_msg_data);
16333 				 -- Check the error status from the above call
16334 				 if x_return_status <> G_RET_STS_SUCCESS Then
16335 				    --  Review Late Set Appropiate Message
16336 				    l_progress := 'WMSINB-19984';
16337 				    RAISE FND_API.G_EXC_ERROR;
16338 				 End if;
16339 
16340 			      End if;
16341 			    Else -- RS.PTID.PTID Exists
16342 			      l_progress := 'WMSINB-19990';
16343 			      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
16344 				 --  Review Late Set Appropiate Message
16345 				 l_progress := 'WMSINB-19993';
16346 				 RAISE FND_API.G_EXC_ERROR;
16347 			      End if;
16348 			   End if;
16349 			End if; -- END OF RTR
16350 		      Else -- TLPN and FLPN same
16351 			if l_rs_ptid_ptid_ptid_exists = TRUE then
16352 			   if nvl(l_lpn_rec.lpn_id,0) <> nvl(l_rs_ptid_ptid_ptid_lpn_id,-9999) then
16353 			      --  Review Late Set Appropiate Message
16354 			      l_progress := 'WMSINB-20002';
16355 			      RAISE FND_API.G_EXC_ERROR;
16356 			   End if;
16357 			End if;
16358 		     End if; -- END OF TLPN and FLPN Different
16359 
16360 		   Else -- TLPN null CASE
16361 		     l_progress := 'WMSINB-20009';
16362 		     if l_parent_txn_type in ('RETURN TO RECEIVING') then
16363 			if l_rs_ptid_ptid_ptid_exists = TRUE then
16364 			   if l_rs_ptid_ptid_ptid_lpn_id is not null then
16365 			      --  Review Late Set Appropiate Message
16366 			      l_progress := 'WMSINB-20014';
16367 			      RAISE FND_API.G_EXC_ERROR;
16368 			   End if;
16369 			End if;
16370 		     End if;
16371 		  End if; --END OF TLPN not null
16372 	       End if; --END OF RTR RTV RTC
16373 
16374 	    End if;
16375 	    -- END OF POSITIVE CORRECTION
16376 
16377 	 End if; -- END OF CORRECT','RETURN TO VENDOR' RTR and RTC  TXN
16378 	 -- **********************************************************************************************
16379 	 -- FOR item id null case . THIS IS THE CASES FOR EXPENSE ITEM WHERE THERE IS NO ITEM ID PRESENT
16380 	 -- **********************************************************************************************
16381        else
16382 		  -- Check the Quantity and if it is null the return otherwise continue with the Loop
16383 		  if nvl(l_lpn_rec.quantity,0) = 0 then
16384 		     --
16385 		     -- Return Error as qty is null
16386 		     --
16387 		     l_progress := 'WMSINB-20035';
16388 		     --x_return_status := g_ret_sts_error;
16389 		     --
16390 		     -- Review Later
16391 		     -- Set appropiate Message
16392 		     --
16393 		     -- exit;
16394                      -- Bug 3714354
16395                      -- The ABOVE CASE WMSINB-20035 Does not need to be failed here
16396                      -- Becasuse this will be checked by PO's pre-processor , and
16397                      -- for Service Items there may be cases where qty and item both null
16398                      null;
16399 		  end if;
16400 		  -- **************************************************************
16401 		  -- START OF CASES  FOR  RECEIPT  TRANSACTION
16402 		  -- **************************************************************
16403 		  IF (l_debug = 1) THEN
16404 		     print_debug('VALIDATE_LPN_INFO: Case for Expense ITEM :'|| l_lpn_rec.lpn_id , 1);
16405 		  END If;
16406 
16407       end if;
16408 
16409 
16410       IF (l_update_lpn_id = TRUE) THEN
16411 	 UPDATE rcv_transactions_interface
16412 	   SET lpn_id = l_lpn_rec.lpn_id
16413 	   , transfer_lpn_id = l_lpn_rec.transfer_lpn_id
16414 	   WHERE interface_transaction_id = l_lpn_rec.interface_transaction_id;
16415       END IF;
16416 
16417    End loop;
16418 
16419    -- Delete WLPNI rows
16420    -- This call has been moved above
16421    -- delete_wlpni(p_lpn_group_id,p_lpn_id, p_license_plate_number,x_return_status,x_msg_count,x_msg_data);
16422 
16423    close c_validate_lpn;
16424 
16425    --if direct org transfer then return from here.
16426    IF (l_intransit_type = 1) THEN
16427       RETURN;
16428    END IF;
16429 
16430    -- Query the rest of WLPNI for the same group
16431    -- And check if parent needs to be changed
16432 
16433    l_progress := 'WMSINB-20071';
16434    For c_wlpni_rec in ( select lpn_id,
16435 			license_plate_number,
16436 			parent_lpn_id,
16437 			parent_license_plate_number,
16438 			organization_id,
16439 			rowid
16440 			from wms_lpn_interface
16441 			where source_group_id = p_lpn_group_id)
16442      Loop
16443 	l_progress := 'WMSINB-20081';
16444 
16445 	IF (l_debug = 1) THEN
16446 	   print_debug('VALIDATE_LPN_INFO: Inside wlpni loop at End l_progess = '|| l_progress, 1);
16447 	END If;
16448 
16449 	l_wlpni_state := get_lpn_id(c_wlpni_rec.lpn_id,
16450 				    c_wlpni_rec.license_plate_number,l_wlpni_lpn_context,l_wlpni_cur_parent_lpn,
16451 				    l_wlpn_source_header_id);
16452 
16453 	l_wlpni_parent_state := get_lpn_id(c_wlpni_rec.parent_lpn_id,
16454 					   c_wlpni_rec.parent_license_plate_number,
16455 					   l_wlpni_parent_lpn_context,l_wlpni_cur_parent_parent_lpn,
16456 					   l_xfr_wlpn_source_header_id);
16457 
16458 	l_progress := 'WMSINB-20091';
16459 
16460 	IF (l_debug = 1) THEN
16461 	   print_debug('VALIDATE_LPN_INFO:LPN_ID:'||c_wlpni_rec.lpn_id, 1);
16462 	   print_debug('VALIDATE_LPN_INFO:PARENT_LPN_ID:'||l_wlpni_cur_parent_lpn, 1);
16463 	END IF;
16464 
16465 	if (Nvl(l_wlpni_cur_parent_lpn,-1) <>  nvl(c_wlpni_rec.parent_lpn_id,-1)) then
16466 	   -- Unpack the LPN from the current Parent and
16467 	   -- Pack according to wlpni info
16468 	   IF l_wlpni_cur_parent_lpn IS NOT NULL THEN
16469 	      wms_container_pvt.packunpack_container(
16470 						     p_api_version            => 1.0,
16471 						     p_init_msg_list          => g_false,
16472 						     p_commit                 => g_false,
16473 						     p_validation_level       => fnd_api.g_valid_level_none,
16474 						     x_return_status          => x_return_status,
16475 						     x_msg_count              => l_msg_count,
16476 						     x_msg_data               => l_msg_data,
16477 						     p_lpn_id                 => l_wlpni_cur_parent_lpn,
16478 						     p_content_lpn_id         => c_wlpni_rec.LPN_ID,
16479 						     p_organization_id        => c_wlpni_rec.organization_id,
16480 						     p_operation              => 2 --- TO UNPACK
16481 						     );
16482 
16483 	      l_progress := 'WMSINB-20116';
16484 
16485 	      IF (x_return_status <> g_ret_sts_success) THEN
16486 		 IF (l_debug = 1) THEN
16487 		    print_debug('VALIDATE_LPN_INFO: packunpack_container failed progress = ' || l_progress,1);
16488 		 END IF;
16489 		 l_progress := 'WMSINB-20122';
16490 		 RAISE fnd_api.g_exc_error;
16491 	      END IF;
16492 	   END IF; --IF l_wlpni_cur_parent_lpn IS NOT NULL THEN
16493 
16494 	   IF c_wlpni_rec.parent_lpn_id IS NOT NULL THEN
16495               -- Bug 3349931
16496               -- Get the SUB/LOC from RTI and update the LPN before packing the LPN into parent LPN
16497               -- This is needed AS the parent LPN might exist in a diff SUB/LOC than the LPN
16498               -- So the packing might FAIL.
16499               -- This needs to be done only when there is no immediate contents in LPN
16500               Begin
16501                  SELECT rti.subinventory,
16502 		   rti.locator_id,
16503 		   rti.to_organization_id,
16504 		   rti.shipment_header_id,
16505 		   rti.shipment_num,
16506 		   rti.transaction_type
16507                    INTO l_parent_sub,
16508 		   l_parent_locator_id,
16509 		   l_parent_to_organization_id,
16510 		   l_parent_source_header_id,
16511 		   l_parent_source_name,
16512 		   l_parent_txn_type
16513                    FROM rcv_transactions_interface rti
16514 		   WHERE rti.lpn_id = rti.transfer_lpn_id
16515 		   AND rti.lpn_group_id = p_lpn_group_id
16516 		   AND rti.lpn_id IN (SELECT lpn_id
16517 				      FROM wms_license_plate_numbers wlpn2
16518 				      CONNECT BY PRIOR wlpn2.lpn_id = wlpn2.parent_lpn_id
16519 				      START WITH wlpn2.lpn_id =  c_wlpni_rec.LPN_ID
16520                                       )
16521 		   AND NOT exists ( SELECT 'x' FROM wms_lpn_contents
16522 				    WHERE parent_lpn_id =  c_wlpni_rec.LPN_ID
16523 				    )
16524 		   AND ROWNUM = 1
16525                    ;
16526               Exception
16527                  When others then
16528                  -- No need to update SUB / LOC
16529 		 l_progress := 'WMSINB-20123';
16530 		 IF (l_debug = 1) THEN
16531 		    print_debug('VALIDATE_LPN_INFO: No SUB/LOC Found : progress = ' || l_progress,1);
16532 		 END IF;
16533               End;
16534 
16535 	      IF (l_parent_txn_type = 'SHIP') THEN
16536 		 l_parent_source_type_id := 1;
16537 	       ELSE
16538 		 l_parent_source_type_id := NULL;
16539 		 l_parent_source_name := NULL;
16540 		 l_parent_source_header_id := NULL;
16541 	      END IF;
16542 
16543               if (l_parent_sub is not null
16544 		  or l_parent_locator_id is not	NULL
16545 		  OR l_parent_txn_type = 'SHIP') then
16546 		 IF (l_debug = 1) THEN
16547 		    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);
16548 		 END IF;
16549                  update_lpn_location_context(p_organization_id => l_parent_to_organization_id
16550 					     ,p_sub             => l_parent_sub
16551 					     ,p_locator         => l_parent_locator_id
16552 					     ,p_lpn_context     => null
16553 					     ,p_lpn_id          => c_wlpni_rec.lpn_id
16554 					     ,p_source_name     => l_parent_source_name
16555 					     ,p_source_header_id => l_parent_source_header_id
16556 					     ,p_source_type_id => l_parent_source_type_id
16557 					     ,x_return_status   => x_return_status
16558 					     ,x_msg_count       => x_msg_count
16559 					     ,x_msg_data        => x_msg_data ) ;
16560 
16561                   l_progress := 'WMSINB-20124';
16562 
16563                   -- Check the error status from the above call
16564                   if x_return_status <> G_RET_STS_SUCCESS Then
16565                      --  Review Late Set Appropiate Message
16566                      l_progress := 'WMSINB-20125';
16567                      RAISE FND_API.G_EXC_ERROR;
16568                   End if;
16569 
16570 		  --We also need to update sub/loc/sourc_name etc for parent
16571 		  update_lpn_location_context(p_organization_id => l_parent_to_organization_id
16572 					      ,p_sub             => l_parent_sub
16573 					      ,p_locator         => l_parent_locator_id
16574 					      ,p_lpn_context     => null
16575 					      ,p_lpn_id          => c_wlpni_rec.parent_lpn_id
16576 					      ,p_source_name     => l_parent_source_name
16577 					      ,p_source_header_id => l_parent_source_header_id
16578 					      ,p_source_type_id => l_parent_source_type_id
16579 					      ,x_return_status   => x_return_status
16580 					      ,x_msg_count       => x_msg_count
16581 					      ,x_msg_data        => x_msg_data ) ;
16582 
16583                   l_progress := 'WMSINB-20126';
16584 
16585                   -- Check the error status from the above call
16586                   if x_return_status <> G_RET_STS_SUCCESS Then
16587                      --  Review Late Set Appropiate Message
16588                      l_progress := 'WMSINB-20127';
16589                      RAISE FND_API.G_EXC_ERROR;
16590                   End if;
16591               End if;
16592 
16593               l_progress := 'WMSINB-20128';
16594 
16595 	      wms_container_pvt.packunpack_container(   p_api_version            => 1.0,
16596 							p_init_msg_list          => g_false,
16597 							p_commit                 => g_false,
16598 							p_validation_level       => fnd_api.g_valid_level_none,
16599 							x_return_status          => x_return_status,
16600 							x_msg_count              => l_msg_count,
16601 							x_msg_data               => l_msg_data,
16602 							p_lpn_id                 => c_wlpni_rec.parent_lpn_id,
16603 							p_content_lpn_id         => c_wlpni_rec.LPN_ID,
16604 							p_organization_id        => c_wlpni_rec.organization_id,
16605 							p_operation              => 1 --- TO PACK
16606 							);
16607 	      IF (x_return_status <> g_ret_sts_success) THEN
16608 		 IF (l_debug = 1) THEN
16609 		    print_debug('VALIDATE_LPN_INFO: packunpack_container failed progress = ' || l_progress,1);
16610 		 END IF;
16611 		 l_progress := 'WMSINB-20144';
16612 		 RAISE fnd_api.g_exc_error;
16613 	      END IF;
16614 	   END IF; --IF c_wlpni_rec.parent_lpn_id IS NOT NULL THEN
16615 
16616 	End if;
16617      End Loop;
16618 
16619      -- Finally delete the processed rows.
16620      l_progress := 'WMSINB-20153';
16621      delete from wms_lpn_interface where source_group_id = p_lpn_group_id;
16622 
16623 
16624 EXCEPTION
16625    WHEN fnd_api.g_exc_error THEN
16626       x_return_status  := g_ret_sts_error;
16627       IF (l_debug = 1) THEN
16628          print_debug('VALIDATE_LPN_INFO - Execution Error:'|| l_progress || ':' ||sqlcode, 1);
16629 	 print_stacked_messages;
16630       END IF;
16631       x_msg_data := l_progress;
16632 
16633    WHEN OTHERS THEN
16634       x_return_status  := g_ret_sts_unexp_error;
16635       IF (l_debug = 1) THEN
16636          print_debug('VALIDATE_LPN_INFO - OTHER Exception:'|| l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
16637 	 print_stacked_messages;
16638       END IF;
16639 
16640       x_msg_data := l_progress;
16641 
16642       IF SQLCODE IS NOT NULL THEN
16643 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.VALIDATE_LPN_INFO',l_progress, SQLCODE);
16644       END IF;
16645       -- Get message count and data
16646       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => l_msg_count, p_data => l_msg_data);
16647 
16648 END VALIDATE_LPN_INFO;
16649 
16650 PROCEDURE insert_mtli_rowid (p_rowid                  IN ROWID,
16651 			     p_product_txn_id         IN NUMBER,
16652 			     p_new_serial_txn_temp_id IN NUMBER,
16653 			     p_quantity               IN NUMBER,
16654 			     p_primary_quantity       IN NUMBER,
16655 			     x_return_status          OUT NOCOPY VARCHAR2,
16656 			     x_msg_count              OUT NOCOPY NUMBER,
16657 			     x_msg_data               OUT NOCOPY VARCHAR2)
16658   IS
16659      l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
16660 BEGIN
16661 
16662    x_return_status := g_ret_sts_success;
16663 
16664    IF (l_debug = 1) THEN
16665       print_debug('insert_mtli_rowid:010: Entry Stamp :' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
16666    END If;
16667 
16668    INSERT INTO mtl_transaction_lots_interface
16669      (TRANSACTION_INTERFACE_ID,
16670       SOURCE_CODE,
16671       SOURCE_LINE_ID,
16672       LAST_UPDATE_DATE,
16673       LAST_UPDATED_BY,
16674       CREATION_DATE,
16675       CREATED_BY,
16676       LAST_UPDATE_LOGIN,
16677       REQUEST_ID,
16678       PROGRAM_APPLICATION_ID,
16679       PROGRAM_ID,
16680       PROGRAM_UPDATE_DATE,
16681       LOT_NUMBER,
16682       LOT_EXPIRATION_DATE,
16683       TRANSACTION_QUANTITY,
16684       PRIMARY_QUANTITY,
16685       SERIAL_TRANSACTION_TEMP_ID,
16686       ERROR_CODE,
16687       PROCESS_FLAG,
16688       DESCRIPTION,
16689       VENDOR_NAME,
16690       SUPPLIER_LOT_NUMBER,
16691       ORIGINATION_DATE,
16692       DATE_CODE,
16693       GRADE_CODE,
16694       CHANGE_DATE,
16695       MATURITY_DATE,
16696       STATUS_ID,
16697       RETEST_DATE,
16698       AGE,
16699       ITEM_SIZE,
16700       COLOR,
16701       VOLUME,
16702       VOLUME_UOM,
16703       PLACE_OF_ORIGIN,
16704       BEST_BY_DATE,
16705       LENGTH,
16706       LENGTH_UOM,
16707       RECYCLED_CONTENT,
16708       THICKNESS,
16709       THICKNESS_UOM,
16710       WIDTH,
16711       WIDTH_UOM,
16712       CURL_WRINKLE_FOLD,
16713       LOT_ATTRIBUTE_CATEGORY,
16714       C_ATTRIBUTE1,
16715       C_ATTRIBUTE2,
16716       C_ATTRIBUTE3,
16717      C_ATTRIBUTE4,
16718      C_ATTRIBUTE5,
16719      C_ATTRIBUTE6,
16720      C_ATTRIBUTE7,
16721      C_ATTRIBUTE8,
16722      C_ATTRIBUTE9,
16723      C_ATTRIBUTE10,
16724      C_ATTRIBUTE11,
16725      C_ATTRIBUTE12,
16726      C_ATTRIBUTE13,
16727      C_ATTRIBUTE14,
16728      C_ATTRIBUTE15,
16729      C_ATTRIBUTE16,
16730      C_ATTRIBUTE17,
16731      C_ATTRIBUTE18,
16732      C_ATTRIBUTE19,
16733      C_ATTRIBUTE20,
16734      D_ATTRIBUTE1,
16735      D_ATTRIBUTE2,
16736      D_ATTRIBUTE3,
16737      D_ATTRIBUTE4,
16738      D_ATTRIBUTE5,
16739      D_ATTRIBUTE6,
16740      D_ATTRIBUTE7,
16741      D_ATTRIBUTE8,
16742      D_ATTRIBUTE9,
16743      D_ATTRIBUTE10,
16744      N_ATTRIBUTE1,
16745      N_ATTRIBUTE2,
16746      N_ATTRIBUTE3,
16747      N_ATTRIBUTE4,
16748      N_ATTRIBUTE5,
16749      N_ATTRIBUTE6,
16750      N_ATTRIBUTE7,
16751      N_ATTRIBUTE8,
16752      N_ATTRIBUTE9,
16753      N_ATTRIBUTE10,
16754      VENDOR_ID,
16755      TERRITORY_CODE,
16756      /*INVCONV, Remove sublot_num, add other attributes. Punit Kumar */
16757      ---sublot_num,
16758      PARENT_LOT_NUMBER		   ,
16759      ORIGINATION_TYPE         ,
16760      EXPIRATION_ACTION_DATE   ,
16761      EXPIRATION_ACTION_CODE   ,
16762      HOLD_DATE                ,
16763      REASON_ID                ,
16764      /* end INVCONV */
16765 
16766      reason_code,
16767      secondary_transaction_quantity,
16768      PRODUCT_CODE,
16769      product_transaction_id)
16770      (SELECT TRANSACTION_INTERFACE_ID,
16771       SOURCE_CODE,
16772       SOURCE_LINE_ID,
16773       LAST_UPDATE_DATE,
16774       LAST_UPDATED_BY,
16775       CREATION_DATE,
16776       CREATED_BY,
16777       LAST_UPDATE_LOGIN,
16778       REQUEST_ID,
16779       PROGRAM_APPLICATION_ID,
16780       PROGRAM_ID,
16781       PROGRAM_UPDATE_DATE,
16782       Ltrim(Rtrim(lot_number)),
16783       LOT_EXPIRATION_DATE,
16784       p_quantity,
16785       p_primary_quantity, -- Calculate
16786       p_new_serial_txn_temp_id, -- New sequence
16787       ERROR_CODE,
16788       PROCESS_FLAG,
16789       DESCRIPTION,
16790       VENDOR_NAME,
16791       SUPPLIER_LOT_NUMBER,
16792       ORIGINATION_DATE,
16793       DATE_CODE,
16794       GRADE_CODE,
16795       CHANGE_DATE,
16796       MATURITY_DATE,
16797       STATUS_ID,
16798       RETEST_DATE,
16799       AGE,
16800       ITEM_SIZE,
16801       COLOR,
16802       VOLUME,
16803       VOLUME_UOM,
16804       PLACE_OF_ORIGIN,
16805       BEST_BY_DATE,
16806       LENGTH,
16807       LENGTH_UOM,
16808       RECYCLED_CONTENT,
16809       THICKNESS,
16810       THICKNESS_UOM,
16811       WIDTH,
16812       WIDTH_UOM,
16813       CURL_WRINKLE_FOLD,
16814       LOT_ATTRIBUTE_CATEGORY,
16815       C_ATTRIBUTE1,
16816      C_ATTRIBUTE2,
16817      C_ATTRIBUTE3,
16818      C_ATTRIBUTE4,
16819      C_ATTRIBUTE5,
16820      C_ATTRIBUTE6,
16821      C_ATTRIBUTE7,
16822      C_ATTRIBUTE8,
16823      C_ATTRIBUTE9,
16824      C_ATTRIBUTE10,
16825      C_ATTRIBUTE11,
16826      C_ATTRIBUTE12,
16827      C_ATTRIBUTE13,
16828      C_ATTRIBUTE14,
16829      C_ATTRIBUTE15,
16830      C_ATTRIBUTE16,
16831      C_ATTRIBUTE17,
16832      C_ATTRIBUTE18,
16833      C_ATTRIBUTE19,
16834      C_ATTRIBUTE20,
16835      D_ATTRIBUTE1,
16836      D_ATTRIBUTE2,
16837      D_ATTRIBUTE3,
16838      D_ATTRIBUTE4,
16839      D_ATTRIBUTE5,
16840      D_ATTRIBUTE6,
16841      D_ATTRIBUTE7,
16842      D_ATTRIBUTE8,
16843      D_ATTRIBUTE9,
16844      D_ATTRIBUTE10,
16845      N_ATTRIBUTE1,
16846      N_ATTRIBUTE2,
16847      N_ATTRIBUTE3,
16848      N_ATTRIBUTE4,
16849      N_ATTRIBUTE5,
16850      N_ATTRIBUTE6,
16851      N_ATTRIBUTE7,
16852      N_ATTRIBUTE8,
16853      N_ATTRIBUTE9,
16854      N_ATTRIBUTE10,
16855      VENDOR_ID,
16856      TERRITORY_CODE,
16857      /*INVCONV , remove sublot_num, add other attributes.Punit Kumar*/
16858      ----sublot_num,
16859      PARENT_LOT_NUMBER,
16860      ORIGINATION_TYPE ,
16861      EXPIRATION_ACTION_DATE ,
16862      EXPIRATION_ACTION_CODE ,
16863      HOLD_DATE  ,
16864      REASON_ID  ,
16865      /* end INVCONV */
16866      reason_code,
16867      NULL,
16868      PRODUCT_CODE,
16869      p_product_txn_id
16870      FROM mtl_transaction_lots_interface
16871      WHERE ROWID = p_rowid);
16872 
16873    IF (l_debug = 1) THEN
16874       print_debug('insert_mtli_rowid:020: Exit Stamp :' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
16875       /* INVCONV*/
16876       print_debug('INVCONV, removed sublot_num, Added some more parameters in INSERT INTO mtl_transaction_lots_interface (insert_mtli_rowid)', 1);
16877       /*end , INVCONV*/
16878 
16879    END If;
16880 EXCEPTION
16881    WHEN OTHERS THEN
16882       x_return_status  := g_ret_sts_unexp_error;
16883       IF (l_debug = 1) THEN
16884          print_debug('insert_mtli_rowid - other exception: '||
16885 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
16886       END IF;
16887       IF SQLCODE IS NOT NULL THEN
16888 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.insert_mtli_rowid',Sqlerrm,SQLCODE);
16889       END IF;
16890       --  Get message count and data
16891       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
16892 END insert_mtli_rowid;
16893 
16894 
16895 PROCEDURE insert_msni_rowid (p_rowid                  IN ROWID,
16896 			     p_product_txn_id         IN NUMBER,
16897 			     p_new_serial_txn_temp_id IN NUMBER DEFAULT NULL,
16898 			     p_new_fm_ser_num         IN VARCHAR2 DEFAULT NULL,
16899 			     p_new_to_ser_num         IN VARCHAR2 DEFAULT NULL,
16900 			     x_return_status          OUT NOCOPY VARCHAR2,
16901 			     x_msg_count              OUT NOCOPY NUMBER,
16902 			     x_msg_data               OUT NOCOPY VARCHAR2)
16903   IS
16904      l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
16905 BEGIN
16906    x_return_status := g_ret_sts_success;
16907 
16908    IF (l_debug = 1) THEN
16909       print_debug('insert_msni_rowid:010: Entry Stamp :' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
16910    END If;
16911 
16912    INSERT INTO mtl_serial_numbers_interface
16913      (TRANSACTION_INTERFACE_ID,
16914       SOURCE_CODE,
16915       SOURCE_LINE_ID,
16916       LAST_UPDATE_DATE,
16917       LAST_UPDATED_BY,
16918       CREATION_DATE,
16919       CREATED_BY,
16920       LAST_UPDATE_LOGIN,
16921       REQUEST_ID,
16922       PROGRAM_APPLICATION_ID,
16923       PROGRAM_ID,
16924       PROGRAM_UPDATE_DATE,
16925       VENDOR_SERIAL_NUMBER,
16926       VENDOR_LOT_NUMBER,
16927       FM_SERIAL_NUMBER,
16928       TO_SERIAL_NUMBER,
16929       ERROR_CODE,
16930       PROCESS_FLAG,
16931       PARENT_SERIAL_NUMBER,
16932       SERIAL_ATTRIBUTE_CATEGORY,
16933       ORIGINATION_DATE,
16934       C_ATTRIBUTE1,
16935       C_ATTRIBUTE2,
16936       C_ATTRIBUTE3,
16937       C_ATTRIBUTE4,
16938       C_ATTRIBUTE5,
16939       C_ATTRIBUTE6,
16940       C_ATTRIBUTE7,
16941       C_ATTRIBUTE8,
16942       C_ATTRIBUTE9,
16943       C_ATTRIBUTE10,
16944       C_ATTRIBUTE11,
16945       C_ATTRIBUTE12,
16946       C_ATTRIBUTE13,
16947       C_ATTRIBUTE14,
16948       C_ATTRIBUTE15,
16949       C_ATTRIBUTE16,
16950       C_ATTRIBUTE18,
16951       C_ATTRIBUTE19,
16952       C_ATTRIBUTE20,
16953       D_ATTRIBUTE1,
16954       D_ATTRIBUTE2,
16955       D_ATTRIBUTE3,
16956       D_ATTRIBUTE4,
16957       D_ATTRIBUTE5,
16958       D_ATTRIBUTE6,
16959      D_ATTRIBUTE7,
16960      D_ATTRIBUTE8,
16961      D_ATTRIBUTE9,
16962      D_ATTRIBUTE10,
16963      N_ATTRIBUTE1,
16964      N_ATTRIBUTE2,
16965      N_ATTRIBUTE3,
16966      N_ATTRIBUTE4,
16967      N_ATTRIBUTE5,
16968      N_ATTRIBUTE6,
16969      N_ATTRIBUTE7,
16970      N_ATTRIBUTE8,
16971      N_ATTRIBUTE9,
16972      N_ATTRIBUTE10,
16973      STATUS_ID,
16974      TERRITORY_CODE,
16975      TIME_SINCE_NEW,
16976      CYCLES_SINCE_NEW,
16977      TIME_SINCE_OVERHAUL,
16978      CYCLES_SINCE_OVERHAUL,
16979      TIME_SINCE_REPAIR,
16980      CYCLES_SINCE_REPAIR,
16981      TIME_SINCE_VISIT,
16982      CYCLES_SINCE_VISIT,
16983      TIME_SINCE_MARK,
16984      CYCLES_SINCE_MARK,
16985      NUMBER_OF_REPAIRS,
16986      STATUS_NAME,
16987      C_ATTRIBUTE17,
16988      ATTRIBUTE_CATEGORY,
16989      ATTRIBUTE1,
16990      ATTRIBUTE2,
16991      ATTRIBUTE3,
16992      ATTRIBUTE4,
16993      ATTRIBUTE5,
16994      ATTRIBUTE6,
16995      ATTRIBUTE7,
16996      ATTRIBUTE8,
16997      ATTRIBUTE9,
16998      ATTRIBUTE10,
16999      ATTRIBUTE11,
17000      ATTRIBUTE12,
17001      ATTRIBUTE13,
17002      ATTRIBUTE14,
17003      ATTRIBUTE15,
17004      PRODUCT_CODE,
17005      PRODUCT_TRANSACTION_ID)
17006      (SELECT Nvl(p_new_serial_txn_temp_id, transaction_interface_id),
17007       SOURCE_CODE,
17008       SOURCE_LINE_ID,
17009       LAST_UPDATE_DATE,
17010       LAST_UPDATED_BY,
17011       CREATION_DATE,
17012       CREATED_BY,
17013       LAST_UPDATE_LOGIN,
17014       REQUEST_ID,
17015       PROGRAM_APPLICATION_ID,
17016       PROGRAM_ID,
17017       PROGRAM_UPDATE_DATE,
17018       VENDOR_SERIAL_NUMBER,
17019       VENDOR_LOT_NUMBER,
17020       Nvl(p_new_fm_ser_num,fm_serial_number),
17021       Nvl(p_new_to_ser_num, to_serial_number),
17022       ERROR_CODE,
17023       PROCESS_FLAG,
17024       PARENT_SERIAL_NUMBER,
17025       SERIAL_ATTRIBUTE_CATEGORY,
17026       ORIGINATION_DATE,
17027       C_ATTRIBUTE1,
17028       C_ATTRIBUTE2,
17029       C_ATTRIBUTE3,
17030       C_ATTRIBUTE4,
17031       C_ATTRIBUTE5,
17032       C_ATTRIBUTE6,
17033       C_ATTRIBUTE7,
17034       C_ATTRIBUTE8,
17035       C_ATTRIBUTE9,
17036       C_ATTRIBUTE10,
17037       C_ATTRIBUTE11,
17038       C_ATTRIBUTE12,
17039       C_ATTRIBUTE13,
17040       C_ATTRIBUTE14,
17041       C_ATTRIBUTE15,
17042       C_ATTRIBUTE16,
17043       C_ATTRIBUTE18,
17044       C_ATTRIBUTE19,
17045       C_ATTRIBUTE20,
17046       D_ATTRIBUTE1,
17047       D_ATTRIBUTE2,
17048      D_ATTRIBUTE3,
17049      D_ATTRIBUTE4,
17050      D_ATTRIBUTE5,
17051      D_ATTRIBUTE6,
17052      D_ATTRIBUTE7,
17053      D_ATTRIBUTE8,
17054      D_ATTRIBUTE9,
17055      D_ATTRIBUTE10,
17056      N_ATTRIBUTE1,
17057      N_ATTRIBUTE2,
17058      N_ATTRIBUTE3,
17059      N_ATTRIBUTE4,
17060      N_ATTRIBUTE5,
17061      N_ATTRIBUTE6,
17062      N_ATTRIBUTE7,
17063      N_ATTRIBUTE8,
17064      N_ATTRIBUTE9,
17065      N_ATTRIBUTE10,
17066      STATUS_ID,
17067      TERRITORY_CODE,
17068      TIME_SINCE_NEW,
17069      CYCLES_SINCE_NEW,
17070      TIME_SINCE_OVERHAUL,
17071      CYCLES_SINCE_OVERHAUL,
17072      TIME_SINCE_REPAIR,
17073      CYCLES_SINCE_REPAIR,
17074      TIME_SINCE_VISIT,
17075      CYCLES_SINCE_VISIT,
17076      TIME_SINCE_MARK,
17077      CYCLES_SINCE_MARK,
17078      NUMBER_OF_REPAIRS,
17079      STATUS_NAME,
17080      C_ATTRIBUTE17,
17081      ATTRIBUTE_CATEGORY,
17082      ATTRIBUTE1,
17083      ATTRIBUTE2,
17084      ATTRIBUTE3,
17085      ATTRIBUTE4,
17086      ATTRIBUTE5,
17087      ATTRIBUTE6,
17088      ATTRIBUTE7,
17089      ATTRIBUTE8,
17090      ATTRIBUTE9,
17091      ATTRIBUTE10,
17092      ATTRIBUTE11,
17093      ATTRIBUTE12,
17094      ATTRIBUTE13,
17095      ATTRIBUTE14,
17096      ATTRIBUTE15,
17097      PRODUCT_CODE,
17098      p_product_txn_id
17099      FROM mtl_serial_numbers_interface
17100      WHERE ROWID = p_rowid);
17101 
17102    IF (l_debug = 1) THEN
17103       print_debug('insert_msni_rowid:020: Exit Stamp :' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
17104    END If;
17105 EXCEPTION
17106    WHEN OTHERS THEN
17107       x_return_status  := g_ret_sts_unexp_error;
17108       IF (l_debug = 1) THEN
17109          print_debug('insert_msni_rowid - other exception: '||
17110 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
17111       END IF;
17112       IF SQLCODE IS NOT NULL THEN
17113 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.insert_msni_rowid',Sqlerrm, SQLCODE);
17114       END IF;
17115       --  Get message count and data
17116       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
17117 
17118 END insert_msni_rowid;
17119 
17120 PROCEDURE split_lot_serial(p_rti_tb         IN  inv_rcv_integration_apis.child_rec_tb_tp,
17121 			   x_return_status  OUT NOCOPY VARCHAR2,
17122 			   x_msg_count      OUT NOCOPY NUMBER,
17123 			   x_msg_data       OUT NOCOPY VARCHAR2)
17124   IS
17125 	/*
17126 	Issues were found during testing for 13521315
17127     Breaking down the Lot and Serial cursors into two to take care of all the Scenarios
17128 	--13521315
17129 	*/
17130    CURSOR mtli_recs_with_rsl (l_old_rti_id NUMBER,l_shipment_line_id NUMBER) IS --modified for bug 13492777
17131 	SELECT Ltrim(Rtrim(mtli.lot_number)) lot_number,
17132 	       mtli.transaction_quantity,
17133 	       mtli.primary_quantity,
17134 	       mtli.serial_transaction_temp_id,
17135 	       mtli.ROWID
17136 	  FROM mtl_transaction_lots_interface mtli, rcv_lots_supply rls
17137 	 WHERE mtli.product_code = 'RCV'
17138 	   AND mtli.product_transaction_id = l_old_rti_id
17139 	   AND mtli.lot_number = rls.lot_num --14573375 removed outer join
17140 	   AND NVL(rls.shipment_line_id,l_shipment_line_id) = l_shipment_line_id
17141 	 ORDER BY rls.shipment_line_id;
17142 
17143    CURSOR mtli_recs (l_old_rti_id NUMBER) IS --modified for bug 13492777
17144 	SELECT Ltrim(Rtrim(mtli.lot_number)) lot_number,
17145 	       mtli.transaction_quantity,
17146 	       mtli.primary_quantity,
17147 	       mtli.serial_transaction_temp_id,
17148 	       mtli.ROWID
17149 	  FROM mtl_transaction_lots_interface mtli
17150 	 WHERE mtli.product_code = 'RCV'
17151 	   AND mtli.product_transaction_id = l_old_rti_id;
17152 
17153      l_mtli_rec mtli_recs%ROWTYPE;
17154      -- Modified for bug 9679278
17155    CURSOR msni_recs_with_rsl (l_old_rti_id NUMBER,l_shipment_line_id NUMBER) IS
17156 	SELECT msni.fm_serial_number,
17157 	       msni.to_serial_number,
17158 	       msni.ROWID
17159 	  FROM mtl_serial_numbers_interface msni,rcv_serials_supply  rss
17160 	 WHERE msni.product_code = 'RCV'
17161 	   AND msni.product_transaction_id = l_old_rti_id
17162 	   AND msni.fm_serial_number = rss.serial_num(+)
17163 	   AND NVL(rss.shipment_line_id,l_shipment_line_id) = l_shipment_line_id --10248599
17164 	 ORDER BY rss.shipment_line_id;
17165 
17166 	CURSOR msni_recs (l_old_rti_id NUMBER) IS
17167 	 SELECT msni.fm_serial_number,
17168 	        msni.to_serial_number,
17169 	        msni.ROWID
17170 	   FROM mtl_serial_numbers_interface msni
17171 	  WHERE msni.product_code = 'RCV'
17172 	    AND msni.product_transaction_id = l_old_rti_id;
17173 	--13521315
17174      l_msni_rec msni_recs%ROWTYPE;
17175 
17176      CURSOR msni_recs_lotserial(l_serial_transaction_temp_id NUMBER) IS
17177 	SELECT fm_serial_number,
17178 	  to_serial_number,
17179 	  ROWID
17180 	  FROM mtl_serial_numbers_interface
17181 	  WHERE transaction_interface_id = l_serial_transaction_temp_id;
17182 
17183      l_remaining_quantity NUMBER;
17184      l_primary_rem_qty NUMBER;
17185      l_remaining_serial_qty NUMBER;
17186      l_ser_rem_quantity NUMBER;
17187      l_serial_transaction_temp_id NUMBER;
17188 
17189      l_orig_interface_trx_id NUMBER;
17190      l_total_split_qty NUMBER;
17191      l_total_lot_qty NUMBER;
17192      l_total_serial_qty NUMBER;
17193      l_lot_ser_qty NUMBER;
17194      l_serial_quantity NUMBER;
17195 
17196      l_serial_split_done BOOLEAN := false;
17197      l_new_serial_txn_temp_id NUMBER;
17198 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
17199      l_temp_prefix VARCHAR2(80);
17200      l_from_ser_number NUMBER;
17201 
17202      l_new_from_ser_num VARCHAR2(30);
17203      l_new_to_ser_num VARCHAR2(30);
17204 
17205      l_rti_count NUMBER;
17206 
17207      l_progress VARCHAR2(15) := '0';
17208      l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
17209 
17210      -- Bug 3395211
17211      l_to_organization_id NUMBER;
17212      l_item_id            NUMBER;
17213      l_uom_code VARCHAR2(3);
17214      l_unit_of_measure VARCHAR2(25);
17215 	 l_shipment_line_id NUMBER;
17216 	 i NUMBER; --14573375
17217 
17218 BEGIN
17219    x_return_status := g_ret_sts_success;
17220 
17221    IF (l_debug = 1) THEN
17222       print_debug('split_lot_serial:010: Entry Stamp :' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
17223    END If;
17224 
17225    l_serial_split_done := FALSE;
17226 
17227    -- first do the quantity check
17228    l_total_split_qty := 0;
17229    l_orig_interface_trx_id := 0;
17230    l_rti_count := p_rti_tb.COUNT;
17231 
17232    FOR newrti IN 1..l_rti_count LOOP
17233       IF (l_total_split_qty <> 0 AND l_orig_interface_trx_id <>
17234 	  p_rti_tb(newrti).orig_interface_trx_id) THEN
17235 
17236 	 IF (l_debug = 1) THEN
17237 	    print_debug('SPLIT_LOT_SERIAL:l_total_split_qty:'||l_total_split_qty,1);
17238 	 END IF;
17239 
17240 	 BEGIN
17241 	    SELECT SUM(transaction_quantity)
17242 	      INTO l_total_lot_qty
17243 	      FROM mtl_transaction_lots_interface
17244 	      WHERE product_code = 'RCV'
17245 	      AND product_transaction_id = l_orig_interface_trx_id;
17246 	 EXCEPTION
17247 	    WHEN no_data_found THEN
17248 	       l_total_lot_qty := 0;
17249 	 END;
17250 
17251 	 IF l_total_lot_qty IS NULL THEN
17252 	    l_total_lot_qty := 0;
17253 	 END IF;
17254 
17255 	 IF (l_debug = 1) THEN
17256 	    print_debug('SPLIT_LOT_SERIAL:l_total_lot_qty:'||l_total_lot_qty,1);
17257 	 END IF;
17258 
17259          BEGIN
17260 	    SELECT SUM(inv_serial_number_pub.get_serial_diff(fm_serial_number,to_serial_number))
17261 	      INTO l_total_serial_qty
17262 	      FROM mtl_serial_numbers_interface
17263 	      WHERE product_code = 'RCV'
17264 	      AND product_transaction_id = l_orig_interface_trx_id;
17265 	 EXCEPTION
17266 	    WHEN no_data_found THEN
17267 	       l_total_serial_qty := 0;
17268 	 END;
17269 
17270 	 IF l_total_serial_qty IS NULL THEN
17271 	    l_total_serial_qty := 0;
17272 	 END IF;
17273 
17274 	 IF (l_debug = 1) THEN
17275 	    print_debug('SPLIT_LOT_SERIAL:l_total_serial_qty:'||l_total_serial_qty,1);
17276 	 END IF;
17277 
17278 	 IF (l_total_lot_qty <> 0 AND l_total_lot_qty <> l_total_split_qty) THEN
17279 	    IF (l_debug = 1) THEN
17280 	       print_debug('split_lot_serial:020: Lot Quantity Mismatch', 1);
17281 	       print_debug('split_lot_serial:030: total_lot_qty : '||l_total_lot_qty, 1);
17282 	       print_debug('split_lot_serial:040: total_split_qty : '||l_total_split_qty, 1);
17283 	    END If;
17284 
17285 	    -- raise an error
17286 	    l_progress := 'WMSINB-20780';
17287 	    RAISE fnd_api.g_exc_error;
17288 	 END IF;
17289 
17290          -- Bug 3395211
17291          -- Get the UOM code and Organization Id to calculate the primary qty.
17292          -- Bug 3446419
17293          -- This will not be called if values are passed in the record structure
17294 
17295          l_uom_code := p_rti_tb(newrti).uom_code;
17296          l_item_id  := p_rti_tb(newrti).item_id;
17297          l_to_organization_id := p_rti_tb(newrti).to_organization_id;
17298 
17299          if (l_uom_code is null or l_item_id is null or l_to_organization_id is null) then
17300          Begin
17301            select uom_code,
17302                   unit_of_measure,
17303                   item_id,
17304                   to_organization_id
17305              into l_uom_code,
17306                   l_unit_of_measure,
17307                   l_item_id,
17308                   l_to_organization_id
17309              from rcv_transactions_interface rti
17310             where rti.interface_transaction_id = p_rti_tb(newrti).new_interface_trx_id;
17311 
17312             if l_uom_code is null then
17313               BEGIN
17314                SELECT uom_code
17315                  into l_uom_code
17316                  FROM mtl_item_uoms_view
17317                  WHERE organization_id = l_to_organization_id
17318                  AND inventory_item_id =  l_item_id
17319                  AND unit_of_measure = l_unit_of_measure;
17320                EXCEPTION
17321                  WHEN OTHERS THEN
17322                   IF (l_debug = 1) THEN
17323                      print_debug('SPLIT_LOT_SERIAL : Error retrieving UOM inside split_lot_serial', 1);
17324                   END IF;
17325                   l_progress := 'WMSINB-20781';
17326                   RAISE fnd_api.g_exc_error;
17327                END;
17328             End if;
17329          Exception
17330            when others then
17331                   IF (l_debug = 1) THEN
17332                      print_debug('SPLIT_LOT_SERIAL : Error retrieving uom_code inside split_lot_serial ', 1);
17333                   END IF;
17334                   l_progress := 'WMSINB-20782';
17335                   RAISE fnd_api.g_exc_error;
17336          End;
17337          End if;
17338 
17339 	 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
17340 	    IF (l_debug = 1) THEN
17341 	       print_debug('split_lot_serial:050: Serial Quantity Mismatch', 1);
17342 	       print_debug('split_lot_serial:060: total_serial_qty : '||l_total_serial_qty, 1);
17343 	       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);
17344 	    END If;
17345 
17346 	    -- raise an error
17347 	    l_progress := 'WMSINB-20792';
17348 	    RAISE fnd_api.g_exc_error;
17349 	 END IF;
17350 
17351 	 -- one more check for lot/serial items
17352          -- Bug 3395211 A nvl is added on primary_quantity because ideally the serial qty
17353          -- Should match with the primary qty.
17354 
17355 	 BEGIN
17356 	    SELECT SUM(mtli.transaction_quantity)
17357 	      INTO l_lot_ser_qty
17358 	      FROM mtl_transaction_lots_interface mtli
17359 	      WHERE mtli.product_code = 'RCV'
17360 	      AND mtli.product_transaction_id = l_orig_interface_trx_id
17361 	      AND (mtli.serial_transaction_temp_id IS NULL
17362 		   OR nvl(mtli.primary_quantity,
17363                           get_primary_qty(l_to_organization_id,l_item_id,l_uom_code,
17364                           mtli.transaction_quantity)
17365                          )
17366                  = (SELECT SUM(inv_serial_number_pub.get_serial_diff(msni.fm_serial_number,
17367 												    msni.to_serial_number))
17368 						   FROM mtl_serial_numbers_interface msni
17369 						   WHERE  msni.transaction_interface_id = mtli.serial_transaction_temp_id));
17370 	 EXCEPTION
17371 	    WHEN no_data_found then
17372 	       l_lot_ser_qty := 0;
17373 	 END;
17374 
17375 	 IF l_lot_ser_qty IS NULL THEN
17376 	    l_lot_ser_qty := 0;
17377 	 END IF;
17378 
17379 	 IF (l_debug = 1) THEN
17380 	    print_debug('SPLIT_LOT_SERIAL:l_lot_ser_qty:'||l_lot_ser_qty,1);
17381 	 END IF;
17382 
17383 	 IF (l_total_lot_qty <> 0 AND l_total_lot_qty <> l_lot_ser_qty) THEN
17384 	    IF (l_debug = 1) THEN
17385 	       print_debug('split_lot_serial:071: Lot Serial Quantity Mismatch', 1);
17386 	       print_debug('split_lot_serial:072: total_lot_qty : '||l_total_lot_qty, 1);
17387 	       print_debug('split_lot_serial:073: lot_ser_qty : '||l_lot_ser_qty, 1);
17388 	    END If;
17389 
17390 	    -- raise an error
17391 	    l_progress := 'WMSINB-20830';
17392 	    RAISE fnd_api.g_exc_error;
17393 	 END IF;
17394 
17395 	 l_orig_interface_trx_id := p_rti_tb(newrti).orig_interface_trx_id;
17396          /* Need to populate the absolute quantity otherwise fails for -ve correction*/
17397 	 l_total_split_qty := ABS(p_rti_tb(newrti).quantity);
17398        ELSE
17399 	       l_orig_interface_trx_id := p_rti_tb(newrti).orig_interface_trx_id;
17400 	       l_total_split_qty := l_total_split_qty + ABS(p_rti_tb(newrti).quantity);
17401 
17402                -- Bug 3395211
17403                -- Get the UOM code and Organization Id to calculate the primary qty.
17404                -- Bug 3446419
17405                -- This will not be called if values are passed in the record structure
17406 
17407                l_uom_code := p_rti_tb(newrti).uom_code;
17408                l_item_id  := p_rti_tb(newrti).item_id;
17409                l_to_organization_id := p_rti_tb(newrti).to_organization_id;
17410 
17411                if (l_uom_code is null or l_item_id is null or l_to_organization_id is null) then
17412                Begin
17413 	         IF (l_debug = 1) THEN
17414 	           print_debug('split_lot_serial: new_interface_trx_id = '|| p_rti_tb(newrti).new_interface_trx_id, 1);
17415                  End if;
17416 
17417                  select uom_code,
17418                         unit_of_measure,
17419                         item_id,
17420                         to_organization_id
17421                    into l_uom_code,
17422                         l_unit_of_measure,
17423                         l_item_id,
17424                         l_to_organization_id
17425                    from rcv_transactions_interface rti
17426                   where rti.interface_transaction_id = p_rti_tb(newrti).new_interface_trx_id;
17427 
17428                   if l_uom_code is null then
17429                     BEGIN
17430                      SELECT uom_code
17431                        into l_uom_code
17432                        FROM mtl_item_uoms_view
17433                        WHERE organization_id = l_to_organization_id
17434                        AND inventory_item_id =  l_item_id
17435                        AND unit_of_measure = l_unit_of_measure;
17436                      EXCEPTION
17437                        WHEN OTHERS THEN
17438                         IF (l_debug = 1) THEN
17439                            print_debug('SPLIT_LOT_SERIAL : Error retrieving UOM inside split_lot_serial', 1);
17440                         END IF;
17441                         l_progress := 'WMSINB-20835';
17442                         RAISE fnd_api.g_exc_error;
17443                      END;
17444                   End if;
17445                Exception
17446                  when others then
17447                         IF (l_debug = 1) THEN
17448                            print_debug('SPLIT_LOT_SERIAL : Error retrieving uom_code inside split_lot_serial ', 1);
17449                         END IF;
17450                         l_progress := 'WMSINB-20836';
17451                         RAISE fnd_api.g_exc_error;
17452                End;
17453                End if;
17454 
17455 	       IF newrti = l_rti_count THEN
17456 		  IF (l_debug = 1) THEN
17457 		     print_debug('SPLIT_LOT_SERIAL:l_total_split_qty:'||l_total_split_qty,1);
17458 		  END IF;
17459 
17460 	          BEGIN
17461 		     SELECT SUM(transaction_quantity)
17462 		       INTO l_total_lot_qty
17463 		       FROM mtl_transaction_lots_interface
17464 		       WHERE product_code = 'RCV'
17465 		       AND product_transaction_id = l_orig_interface_trx_id
17466                         AND (p_rti_tb(newrti).lot_number IS NULL OR (p_rti_tb(newrti).lot_number IS NOT NULL AND lot_number=p_rti_tb(newrti).lot_number)); -- for  13972742
17467 		  EXCEPTION
17468 		     WHEN no_data_found THEN
17469 			l_total_lot_qty := 0;
17470 		  END;
17471 
17472 		  IF l_total_lot_qty IS NULL THEN
17473 		     l_total_lot_qty := 0;
17474 		  END IF;
17475 
17476 		  IF (l_debug = 1) THEN
17477 		     print_debug('SPLIT_LOT_SERIAL:l_total_lot_qty:'||l_total_lot_qty,1);
17478 		  END IF;
17479 
17480                   BEGIN
17481 		     SELECT SUM(inv_serial_number_pub.get_serial_diff(fm_serial_number,to_serial_number))
17482 		       INTO l_total_serial_qty
17483 		       FROM mtl_serial_numbers_interface
17484 		       WHERE product_code = 'RCV'
17485 		       AND product_transaction_id = l_orig_interface_trx_id;
17486 		  EXCEPTION
17487 		     WHEN no_data_found THEN
17488 			l_total_serial_qty := 0;
17489 		  END;
17490 
17491 		  IF l_total_serial_qty IS NULL THEN
17492 		     l_total_serial_qty := 0;
17493 		  END IF;
17494 
17495 		  IF (l_debug = 1) THEN
17496 		     print_debug('SPLIT_LOT_SERIAL:l_total_serial_qty:'||l_total_serial_qty,1);
17497 		  END IF;
17498 
17499 		  IF (l_total_lot_qty <> 0 AND (abs(l_total_lot_qty - l_total_split_qty) > 0.00005)) THEN
17500 		     IF (l_debug = 1) THEN
17501 			print_debug('split_lot_serial:075.1: Lot Quantity Mismatch', 1);
17502 			print_debug('split_lot_serial:075.2: total_lot_qty : '||l_total_lot_qty, 1);
17503 			print_debug('split_lot_serial:075.3: total_split_qty : '||l_total_split_qty, 1);
17504 		     END If;
17505 
17506 		     -- raise an error
17507 		     l_progress := 'WMSINB-20891';
17508 		     RAISE fnd_api.g_exc_error;
17509 		  END IF;
17510 
17511 		  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
17512 		     IF (l_debug = 1) THEN
17513 			print_debug('split_lot_serial:075.4: Serial Quantity Mismatch', 1);
17514 			print_debug('split_lot_serial:075.5: total_serial_qty : '||l_total_serial_qty, 1);
17515 			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);
17516 			print_debug('SPLIT_LOT_SERIAL : to_organization_id:'||l_to_organization_id, 1);
17517 			print_debug('SPLIT_LOT_SERIAL : item_id:'||l_item_id, 1);
17518 			print_debug('SPLIT_LOT_SERIAL : uom_code:'||l_uom_code, 1);
17519 		     END If;
17520 
17521 		     -- raise an error
17522 		     l_progress := 'WMSINB-20903';
17523 		     RAISE fnd_api.g_exc_error;
17524 		  END IF;
17525 
17526 		  -- one more check for lot/serial items
17527 
17528 	          BEGIN
17529 		     SELECT SUM(mtli.transaction_quantity)
17530 		       INTO l_lot_ser_qty
17531 		       FROM mtl_transaction_lots_interface mtli
17532 		       WHERE mtli.product_code = 'RCV'
17533 		       AND mtli.product_transaction_id = l_orig_interface_trx_id
17534 		       AND (mtli.serial_transaction_temp_id IS NULL
17535 			    OR nvl(mtli.primary_quantity,
17536                                get_primary_qty(l_to_organization_id,l_item_id,l_uom_code,
17537                                mtli.transaction_quantity)
17538                            ) = (SELECT SUM(inv_serial_number_pub.get_serial_diff(msni.fm_serial_number,
17539                                                   msni.to_serial_number))
17540 				    FROM mtl_serial_numbers_interface msni
17541 				    WHERE  msni.transaction_interface_id = mtli.serial_transaction_temp_id))
17542                         AND (p_rti_tb(newrti).lot_number IS NULL OR (p_rti_tb(newrti).lot_number IS NOT NULL AND lot_number=p_rti_tb(newrti).lot_number)); -- for  13972742
17543 		  EXCEPTION
17544 		     WHEN no_data_found then
17545 			l_lot_ser_qty := 0;
17546 		  END;
17547 
17548 		  IF l_lot_ser_qty IS NULL THEN
17549 		     l_lot_ser_qty := 0;
17550 		  END IF;
17551 
17552 		  IF (l_debug = 1) THEN
17553 		     print_debug('SPLIT_LOT_SERIAL:l_lot_ser_qty:'||l_lot_ser_qty,1);
17554 		  END IF;
17555 
17556 		  IF (l_total_lot_qty <> 0 AND l_total_lot_qty <> l_lot_ser_qty) THEN
17557 		     IF (l_debug = 1) THEN
17558 			print_debug('split_lot_serial:075.7: Lot Serial Quantity Mismatch', 1);
17559 			print_debug('split_lot_serial:075.8: total_lot_qty : '||l_total_lot_qty, 1);
17560 			print_debug('split_lot_serial:075.9: lot_ser_qty : '||l_lot_ser_qty, 1);
17561 		     END If;
17562 
17563 		     -- raise an error
17564 		     l_progress := 'WMSINB-20941';
17565 		     RAISE fnd_api.g_exc_error;
17566 		  END IF;
17567 	       END IF; --IF newrti = p_rti_tb.COUNT THEN
17568       END IF;
17569    END LOOP;
17570 
17571    -- Now split the rows
17572    FOR newrti IN 1..p_rti_tb.COUNT LOOP
17573       IF (l_debug = 1) THEN
17574 	 print_debug('split_lot_serial:080: current record '||newrti, 1);
17575 	 print_debug('split_lot_serial:090: orig interface trx id '
17576 		     ||p_rti_tb(newrti).orig_interface_trx_id, 1);
17577 	 print_debug('split_lot_serial:100: new interface trx id '
17578 		     ||p_rti_tb(newrti).new_interface_trx_id, 1);
17579 	 print_debug('split_lot_serial:110: transaction_quantity '
17580 		     ||p_rti_tb(newrti).quantity, 1);
17581 	 --print_debug('split_lot_serial:120: unit of measure '
17582          --||p_rti_tb(newrti).unit_of_measure, 1);
17583       END If;
17584 
17585       -- Bug 3395211
17586       -- Get the UOM code and Organization Id to calculate the primary qty.
17587       -- Bug 3446419
17588       -- This will not be called if values are passed in the record structure
17589 
17590       l_uom_code := p_rti_tb(newrti).uom_code;
17591       l_item_id  := p_rti_tb(newrti).item_id;
17592       l_to_organization_id := p_rti_tb(newrti).to_organization_id;
17593 
17594       if (l_uom_code is null or l_item_id is null or l_to_organization_id is null) then
17595       Begin
17596           IF (l_debug = 1) THEN
17597 	      print_debug('split_lot_serial: new_interface_trx_id = '|| p_rti_tb(newrti).new_interface_trx_id, 1);
17598           End if;
17599 
17600            select uom_code,
17601                unit_of_measure,
17602                item_id,
17603                to_organization_id
17604           into l_uom_code,
17605                l_unit_of_measure,
17606                l_item_id,
17607                l_to_organization_id
17608           from rcv_transactions_interface rti
17609          where rti.interface_transaction_id = p_rti_tb(newrti).new_interface_trx_id;
17610 
17611          if l_uom_code is null then
17612            BEGIN
17613             SELECT uom_code
17614               into l_uom_code
17615               FROM mtl_item_uoms_view
17616               WHERE organization_id = l_to_organization_id
17617               AND inventory_item_id =  l_item_id
17618               AND unit_of_measure = l_unit_of_measure;
17619             EXCEPTION
17620               WHEN OTHERS THEN
17621                IF (l_debug = 1) THEN
17622                   print_debug('SPLIT_LOT_SERIAL : Error retrieving UOM inside split_lot_serial', 1);
17623                END IF;
17624                l_progress := 'WMSINB-20942';
17625                RAISE fnd_api.g_exc_error;
17626             END;
17627          End if;
17628       Exception
17629         when others then
17630                IF (l_debug = 1) THEN
17631                   print_debug('SPLIT_LOT_SERIAL : Error retrieving uom_code inside split_lot_serial ', 1);
17632                END IF;
17633                l_progress := 'WMSINB-20943';
17634                RAISE fnd_api.g_exc_error;
17635       END;
17636       End if;
17637 
17638       IF (p_rti_tb(newrti).new_interface_trx_id <> p_rti_tb(newrti).orig_interface_trx_id) THEN
17639 
17640 	 IF (l_debug = 1) THEN
17641 	    print_debug('split_lot_serial:130: Opening mtli cursor', 1);--13521315
17642 	 END If;
17643 
17644 	 /* Start bug 13492777 */
17645 	 BEGIN
17646 
17647 	 select shipment_line_id
17648 	 into l_shipment_line_id
17649 	 from rcv_transactions_interface
17650 	 where interface_transaction_id = p_rti_tb(newrti).new_interface_trx_id;
17651 	 EXCEPTION
17652 	 WHEN OTHERS THEN
17653 	 l_shipment_line_id := null;
17654 
17655 	 END;
17656 	 /* End bug 13492777 */
17657 
17658 	 --OPEN mtli_recs(p_rti_tb(newrti).orig_interface_trx_id,l_shipment_line_id); --bug 13492777
17659 	 --13521315 Commented the above and added code to open corresponding cursor based on shipment_line_id
17660 
17661      IF (l_debug = 1) THEN
17662       print_debug('split_lot_serial:125: Shipment_line_id '||l_shipment_line_id, 1);
17663      END IF;
17664     /*14573375
17665     The below section has been modified for 14573375.
17666     Issue:
17667     The shipment was from a Non WMS org to a WMS org and the item was non lot controlled
17668     in the source org. Hence there is no RLS record of type shipment while receiving.
17669     The cursor with shipment line works well but if there is an existing record in RLS
17670     with the SAME LOT number for some other shipment line , the cursor fails. Hence the
17671     MTLIs are not updated with the correct product_transaction_id and the transaction fails
17672     since RTP is not able to find the Lot.
17673     Changes done: Wrote an outer loop and run the same maximum twice or till the time
17674     the remaining quantity is <=0.
17675     Note: If the shipment_line_id is not null and the the outer loop runs second time,
17676     this means that the cursor either didnt find any rows or the matching did not happen perfectly.
17677     Hence the second time the loop runs, we null out the shipment_line_id and open the mtli
17678     cursor without shipment line.
17679 	*/
17680     --14573375
17681     l_remaining_quantity := p_rti_tb(newrti).quantity;
17682 	i := 1;
17683     LOOP
17684 	IF (l_debug = 1) THEN
17685         print_debug('split_lot_serial:i: '||i, 1);
17686 		print_debug('split_lot_serial:l_remaining_quantity: '||l_remaining_quantity, 1);
17687 	END If;
17688 	 EXIT WHEN i>2 OR l_remaining_quantity <=0;
17689 
17690 	 IF(l_shipment_line_id IS NULL)THEN
17691 		OPEN mtli_recs(p_rti_tb(newrti).orig_interface_trx_id);
17692 		IF (l_debug = 1) THEN
17693 			print_debug('split_lot_serial:130: Opening mtli_recs cursor', 1);
17694 		END If;
17695 	 ELSE
17696 		OPEN mtli_recs_with_rsl(p_rti_tb(newrti).orig_interface_trx_id,l_shipment_line_id); --bug 13492777
17697 		IF (l_debug = 1) THEN
17698 			print_debug('split_lot_serial:130: Opening mtli_recs_with_rsl cursor', 1);
17699 		END If;
17700 	 END IF;
17701 	 --13521315
17702 	-- l_remaining_quantity := p_rti_tb(newrti).quantity; --14573375 Taken this above.
17703 
17704   	 LOOP
17705 	 --13521315
17706 		IF(l_shipment_line_id IS NULL)THEN
17707 			FETCH mtli_recs INTO l_mtli_rec;
17708 			EXIT WHEN mtli_recs%NOTFOUND;
17709 		ELSE
17710 			FETCH mtli_recs_with_rsl INTO l_mtli_rec;
17711 			IF (mtli_recs_with_rsl%NOTFOUND) THEN --14573375
17712               IF (l_debug = 1) THEN
17713                 print_debug('split_lot_serial: No Lines found with rls cursor.', 1);
17714                 print_debug('split_lot_serial: So making shipment_line as null and looping again', 1);
17715               END IF;
17716 			 l_shipment_line_id :=NULL;
17717 			 EXIT;
17718 			END IF;
17719 		END IF;
17720 	 --13521315
17721 	    IF (l_debug = 1) THEN
17722 		   print_debug('split_lot_serial:135: lot_num '||l_mtli_rec.lot_number, 1);
17723 	       print_debug('split_lot_serial:140: remaining_qty '||l_remaining_quantity, 1);
17724 	       print_debug('split_lot_serial:150: transaction_qty '||l_mtli_rec.transaction_quantity, 1);
17725 	    END If;
17726 
17727 	    l_primary_rem_qty := (l_remaining_quantity*l_mtli_rec.primary_quantity)/l_mtli_rec.transaction_quantity;
17728 
17729 	    IF (l_mtli_rec.transaction_quantity <= l_remaining_quantity) THEN
17730 	       -- update the mtli with new rti id.
17731 	       UPDATE mtl_transaction_lots_interface
17732 		      SET product_transaction_id = p_rti_tb(newrti).new_interface_trx_id
17733 		    WHERE ROWID = l_mtli_rec.ROWID;
17734 
17735 	       IF (l_debug = 1) THEN
17736 		  print_debug('split_lot_serial:160: serial_txn_tmp_id '||l_mtli_rec.serial_transaction_temp_id, 1);
17737 	       END If;
17738 
17739 	       -- update the serial records if exist.
17740 	       IF (l_mtli_rec.serial_transaction_temp_id IS NOT NULL) THEN
17741 		  OPEN msni_recs_lotserial(l_mtli_rec.serial_transaction_temp_id);
17742 
17743 		  l_serial_split_done := TRUE;
17744 
17745 		  LOOP
17746 		     FETCH msni_recs_lotserial INTO l_msni_rec;
17747 		     EXIT WHEN msni_recs_lotserial%notfound;
17748 
17749 		     IF (l_debug = 1) THEN
17750 			print_debug('split_lot_serial:170: update msni ', 1);
17751 		     END If;
17752 		     -- update the msni with new rti id.
17753 		     UPDATE mtl_serial_numbers_interface
17754 		       SET product_transaction_id = p_rti_tb(newrti).new_interface_trx_id
17755 		       WHERE ROWID = l_msni_rec.ROWID;
17756 
17757 		  END LOOP; -- fetch msni_recs_lotserial
17758                   close msni_recs_lotserial;
17759 
17760 	       END IF;
17761 	       l_remaining_quantity := l_remaining_quantity -
17762 		 l_mtli_rec.transaction_quantity;
17763 
17764 	     ELSE
17765 		  -- insert a new row with transaction_quantity = l_remaining
17766 		  -- quantity and new rti id. And update the original row
17767 		  -- with transaction_quantity =
17768 		  -- l_mtli_rec.transaction_quantity - l_remaining_quantity
17769 
17770 		  IF (l_mtli_rec.serial_transaction_temp_id IS NOT NULL)
17771 		    THEN
17772 		     SELECT mtl_material_transactions_s.NEXTVAL
17773 		       INTO l_new_serial_txn_temp_id
17774 		       FROM DUAL;
17775 		   ELSE
17776 		     l_new_serial_txn_temp_id := NULL;
17777 		  END IF;
17778 
17779 		  IF (l_debug = 1) THEN
17780 		     print_debug('split_lot_serial:180: insert mtli rowid ', 1);
17781 		  END If;
17782 
17783 		  insert_mtli_rowid (p_rowid => l_mtli_rec.ROWID,
17784 				     p_product_txn_id => p_rti_tb(newrti).new_interface_trx_id,
17785 				     p_new_serial_txn_temp_id => l_new_serial_txn_temp_id,
17786 				     p_quantity => l_remaining_quantity,
17787 				     p_primary_quantity => l_primary_rem_qty,
17788 				     x_return_status => x_return_status,
17789 				     x_msg_count => x_msg_count,
17790 				     x_msg_data => x_msg_data);
17791 
17792 		  IF (x_return_status <> g_ret_sts_success) THEN
17793 		     IF (l_debug = 1) THEN
17794 			print_debug('split_lot_serial:185: insert mtli rowid failed ', 1);
17795 		     END If;
17796 		     -- raise error
17797 		     l_progress := 'WMSINB-21051';
17798 		     RAISE fnd_api.g_exc_error;
17799 		  END IF;
17800 
17801 		  IF (l_debug = 1) THEN
17802 		     print_debug('split_lot_serial:190: update mtli ', 1);
17803 		  END If;
17804 
17805 		  -- update the original row
17806 		  -- For OPM null out the secondary_transaction_quantity
17807 		  UPDATE mtl_transaction_lots_interface
17808 		    SET transaction_quantity = transaction_quantity -
17809 		    l_remaining_quantity,
17810 		    primary_quantity = primary_quantity - l_primary_rem_qty,
17811 		    secondary_transaction_quantity = NULL
17812 		    WHERE ROWID = l_mtli_rec.ROWID;
17813 
17814 		  IF (l_mtli_rec.serial_transaction_temp_id IS NOT NULL) THEN
17815 		     OPEN msni_recs_lotserial(l_mtli_rec.serial_transaction_temp_id);
17816 
17817 		     l_serial_split_done := TRUE;
17818                      -- Bug 3395211
17819 		     l_remaining_serial_qty := get_primary_qty(l_to_organization_id,l_item_id,l_uom_code,l_remaining_quantity);
17820 
17821 		     LOOP
17822 			FETCH msni_recs_lotserial INTO l_msni_rec;
17823 			EXIT WHEN msni_recs_lotserial%notfound;
17824 
17825 			l_serial_quantity :=
17826 			  inv_serial_number_pub.get_serial_diff(l_msni_rec.fm_serial_number,
17827 								l_msni_rec.to_serial_number);
17828 
17829 			IF (l_debug = 1) THEN
17830 			   print_debug('split_lot_serial:200: serial quantity '||l_serial_quantity, 1);
17831 			END If;
17832 
17833 			IF (l_serial_quantity <= l_remaining_serial_qty)
17834 			  THEN
17835 			   -- update the msni record with new transaction
17836 			   -- id and new serial_transaction_temp_id
17837 			   IF (l_debug = 1) THEN
17838 			      print_debug('split_lot_serial:210: update msni ', 1);
17839 			   END If;
17840 
17841 			   UPDATE mtl_serial_numbers_interface
17842 			     SET product_transaction_id = p_rti_tb(newrti).new_interface_trx_id,
17843 			     transaction_interface_id = l_new_serial_txn_temp_id
17844 			     WHERE ROWID = l_msni_rec.ROWID;
17845 
17846 			   l_remaining_serial_qty := l_remaining_serial_qty
17847 			     - l_serial_quantity;
17848 			 ELSE
17849 			   -- split the msni row
17850 			   inv_validate.number_from_sequence(l_msni_rec.fm_serial_number, l_temp_prefix, l_from_ser_number);
17851 
17852 			   l_new_to_ser_num :=
17853 			     SUBSTR(l_msni_rec.fm_serial_number, 1,
17854 				    LENGTH(l_msni_rec.fm_serial_number) -
17855 				    LENGTH(l_from_ser_number))||(l_from_ser_number+l_remaining_serial_qty-1);
17856 
17857 			   l_new_from_ser_num :=
17858 			     SUBSTR(l_msni_rec.fm_serial_number, 1,
17859 				    LENGTH(l_msni_rec.fm_serial_number) -
17860 				    LENGTH(l_from_ser_number))||(l_from_ser_number+l_remaining_serial_qty);
17861 
17862 			   IF (l_debug = 1) THEN
17863 			      print_debug('split_lot_serial:220: insert	msni rowid', 1);
17864 			   END If;
17865 
17866 			   --insert new msni row.
17867 			   insert_msni_rowid (p_rowid =>l_msni_rec.ROWID,
17868 					      p_product_txn_id => p_rti_tb(newrti).new_interface_trx_id,
17869 					      p_new_serial_txn_temp_id => l_new_serial_txn_temp_id,
17870 					      p_new_fm_ser_num => null,
17871 					      p_new_to_ser_num => l_new_to_ser_num,
17872 					      x_return_status =>x_return_status,
17873 					      x_msg_count => x_msg_count,
17874 					      x_msg_data => x_msg_data);
17875 
17876 			   IF (x_return_status <> g_ret_sts_success) THEN
17877 			      IF (l_debug = 1) THEN
17878 				 print_debug('split_lot_serial:225: insert msni rowid failed ', 1);
17879 			      END If;
17880 			      -- raise error
17881 			      l_progress := 'WMSINB-21134';
17882 			      RAISE fnd_api.g_exc_error;
17883 			   END IF;
17884 
17885 			   -- update the original msni
17886 
17887 			   IF (l_debug = 1) THEN
17888 			      print_debug('split_lot_serial:230: update msni ', 1);
17889 			   END IF;
17890 
17891 			   UPDATE mtl_serial_numbers_interface
17892 			     SET fm_serial_number = l_new_from_ser_num
17893 			     WHERE ROWID = l_msni_rec.ROWID;
17894 
17895 			   l_remaining_serial_qty := 0;
17896 			END IF;
17897 
17898 			IF (l_remaining_serial_qty = 0) THEN
17899 			   EXIT;
17900 			END IF;
17901 
17902 		     END LOOP; -- fetch msni_recs_lotserial
17903                      close msni_recs_lotserial;
17904 		  END IF;
17905 		  l_remaining_quantity := 0;
17906 	    END IF;
17907 
17908 	    IF (l_remaining_quantity <= 0) THEN
17909 	       EXIT;
17910 	    END IF;
17911 
17912 	 END LOOP; -- fetch mtli_recs
17913 	 i:=i+1; --14573375
17914     IF (l_debug = 1) THEN
17915       print_debug('split_lot_serial:i at the END: '||i, 1);
17916     END IF;
17917 
17918 	 --13521315
17919          --close mtli_recs;
17920 		--14573375
17921 		IF(mtli_recs%ISOPEN) THEN
17922 			close mtli_recs;
17923 		END IF;
17924 
17925 		IF(mtli_recs_with_rsl%ISOPEN) THEN
17926 			close mtli_recs_with_rsl;
17927 	 	END IF;
17928 
17929      --13521315
17930 
17931     END LOOP; --14573375
17932 	 -- split the serial rows.
17933 	 IF NOT l_serial_split_done THEN
17934 	 /* Start 9679278 */
17935 	 BEGIN
17936 
17937 	 select shipment_line_id
17938 	 into l_shipment_line_id
17939 	 from rcv_transactions_interface
17940 	 where interface_transaction_id = p_rti_tb(newrti).new_interface_trx_id;
17941 	 EXCEPTION
17942 	 WHEN OTHERS THEN
17943 	 l_shipment_line_id := null;
17944 
17945 	 END;
17946 	 /* End 9679278 */
17947 	    --OPEN msni_recs(p_rti_tb(newrti).orig_interface_trx_id,l_shipment_line_id); --9679278
17948 		--13521315 Commented the above and opening cursor based on Shipment_line_id
17949         IF (l_debug = 1) THEN
17950          print_debug('split_lot_serial:235: Shipment_line_id '||l_shipment_line_id, 1);
17951         END IF;
17952 
17953 		IF(l_shipment_line_id IS NULL) THEN
17954 		  OPEN msni_recs(p_rti_tb(newrti).orig_interface_trx_id);
17955 		ELSE
17956 	      OPEN msni_recs_with_rsl(p_rti_tb(newrti).orig_interface_trx_id,l_shipment_line_id);
17957 		END IF;
17958 		--13521315
17959             -- Bug 3395211
17960 	    l_remaining_quantity := get_primary_qty(l_to_organization_id,l_item_id,l_uom_code,p_rti_tb(newrti).quantity);
17961 
17962 	    LOOP
17963 		--13521315
17964 	      /*FETCH msni_recs INTO l_msni_rec;
17965 	       EXIT WHEN msni_recs%notfound;*/
17966          IF(l_shipment_line_id IS NULL)THEN
17967             FETCH msni_recs INTO l_msni_rec;
17968             EXIT WHEN msni_recs%notfound;
17969          ELSE
17970             FETCH msni_recs_with_rsl INTO l_msni_rec;
17971             EXIT WHEN msni_recs_with_rsl%notfound;
17972          END IF;
17973 		--13521315
17974 	       IF (l_debug = 1) THEN
17975 		    print_debug('split_lot_serial:236: Serial Number '||l_msni_rec.fm_serial_number, 1);
17976             print_debug('split_lot_serial:236: remaining quantity '||l_remaining_quantity, 1);
17977 	       END If;
17978 
17979 	       l_serial_quantity :=
17980 		 inv_serial_number_pub.get_serial_diff(l_msni_rec.fm_serial_number,l_msni_rec.to_serial_number);
17981 
17982 	       IF (l_debug = 1) THEN
17983 		  print_debug('split_lot_serial:237: serial quantity '||l_serial_quantity, 1);
17984 	       END If;
17985 
17986 	       IF (l_serial_quantity <= l_remaining_quantity) THEN
17987 
17988 		  IF (l_debug = 1) THEN
17989 		     print_debug('split_lot_serial:240: update msni ', 1);
17990 		     print_debug('split_lot_serial:241: new rti '||p_rti_tb(newrti).new_interface_trx_id, 1);
17991 		  END If;
17992 
17993 		  UPDATE mtl_serial_numbers_interface
17994 		    SET product_transaction_id = p_rti_tb(newrti).new_interface_trx_id
17995 		    WHERE ROWID = l_msni_rec.ROWID;
17996 
17997 		  l_remaining_quantity := l_remaining_quantity -
17998 		    l_serial_quantity;
17999 		ELSE
18000 		  -- split msni
18001 		  inv_validate.number_from_sequence(l_msni_rec.fm_serial_number, l_temp_prefix, l_from_ser_number);
18002 
18003 		  IF (l_debug = 1) THEN
18004 		     print_debug('split_lot_serial:242: Almost ready to split msni ', 1);
18005 		  END If;
18006 
18007 		  l_new_to_ser_num :=
18008 		    SUBSTR(l_msni_rec.fm_serial_number, 1,
18009 			   LENGTH(l_msni_rec.fm_serial_number) -
18010 			   LENGTH(l_from_ser_number))||(l_from_ser_number+l_remaining_quantity-1);
18011 
18012 		  l_new_from_ser_num :=
18013 		    SUBSTR(l_msni_rec.fm_serial_number, 1,
18014 			   LENGTH(l_msni_rec.fm_serial_number) -
18015 			   LENGTH(l_from_ser_number))||(l_from_ser_number+l_remaining_quantity);
18016 
18017 		  IF (l_debug = 1) THEN
18018 		     print_debug('split_lot_serial:250: insert msni rowid ', 1);
18019 		  END If;
18020 
18021 		  --insert new msni row.
18022 		  insert_msni_rowid (p_rowid =>l_msni_rec.ROWID,
18023 				     p_product_txn_id => p_rti_tb(newrti).new_interface_trx_id,
18024 				     p_new_serial_txn_temp_id => NULL,
18025 				     p_new_fm_ser_num => NULL,
18026 				     p_new_to_ser_num => l_new_to_ser_num,
18027 				     x_return_status =>x_return_status,
18028 				     x_msg_count => x_msg_count,
18029 				     x_msg_data => x_msg_data);
18030 
18031 		  IF (x_return_status <> g_ret_sts_success) THEN
18032 		     IF (l_debug = 1) THEN
18033 			print_debug('split_lot_serial:255: insert msni rowid failed ', 1);
18034 		     END If;
18035 		     -- raise error
18036 		     l_progress := 'WMSINB-21239';
18037 		     RAISE fnd_api.g_exc_error;
18038 		  END IF;
18039 
18040 		  -- update the original msni
18041 
18042 		  IF (l_debug = 1) THEN
18043 		     print_debug('split_lot_serial:260: update msni ', 1);
18044 		  END If;
18045 
18046 		  UPDATE mtl_serial_numbers_interface
18047 		    SET fm_serial_number = l_new_from_ser_num
18048 		    WHERE ROWID = l_msni_rec.ROWID;
18049 
18050 		  l_remaining_quantity := 0;
18051 	       END IF;
18052 
18053 	       IF (l_remaining_quantity <= 0) THEN
18054 		  EXIT;
18055 	       END IF;
18056 
18057 	    END LOOP; -- fetch msni_recs
18058 		  --13521315
18059             --close msni_recs;
18060 			IF(l_shipment_line_id IS NULL)THEN
18061 				close msni_recs;
18062 			ELSE
18063 				close msni_recs_with_rsl;
18064 			END IF;
18065           --13521315
18066 	 END IF;
18067 
18068       END IF;
18069    END LOOP; -- for loop
18070 
18071    IF (l_debug = 1) THEN
18072       print_debug('split_lot_serial:270: Exit Stamp :' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
18073    END If;
18074 
18075 EXCEPTION
18076    WHEN fnd_api.g_exc_error THEN
18077       x_return_status  := g_ret_sts_error;
18078       IF (l_debug = 1) THEN
18079          print_debug('SPLIT_LOT_SERIAL - Execution Error:'||':'||l_progress||':'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
18080 	 print_stacked_messages;
18081       END IF;
18082 
18083       x_msg_data := l_progress;
18084 
18085    WHEN fnd_api.g_exc_unexpected_error THEN
18086       x_return_status  := g_ret_sts_unexp_error;
18087       IF (l_debug = 1) THEN
18088          print_debug('SPLIT_LOT_SERIAL - Unexpected Error:'||':'||l_progress||':'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
18089 	 print_stacked_messages;
18090       END IF;
18091 
18092       x_msg_data := l_progress;
18093 
18094    WHEN OTHERS THEN
18095       x_return_status  := g_ret_sts_unexp_error;
18096       IF (l_debug = 1) THEN
18097          print_debug('SPLIT_LOT_SERIAL - OTHER Exception: '||':'||l_progress||':'||
18098 		     TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
18099 	 print_stacked_messages;
18100       END IF;
18101 
18102       x_msg_data := l_progress;
18103 
18104       IF SQLCODE IS NOT NULL THEN
18105 	 inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.SPLIT_LOT_SERIAL', Sqlerrm,SQLCODE);
18106       END IF;
18107       -- Get message count and data
18108       -- fnd_msg_pub.count_and_get(p_encoded => g_false, p_count => x_msg_count, p_data => x_msg_data);
18109 
18110 END split_lot_serial;
18111 
18112 
18113 --Function to check if the serials were entered for the parent transaction
18114 FUNCTION serial_entered_on_parent (p_parent_txn_id IN NUMBER)
18115   RETURN BOOLEAN
18116   IS
18117      l_dummy VARCHAR2(1);
18118 BEGIN
18119    SELECT '1'
18120      INTO l_dummy
18121      FROM rcv_serials_supply
18122      WHERE transaction_id = p_parent_txn_id
18123      AND ROWNUM = 1;
18124 
18125    RETURN TRUE;
18126 EXCEPTION
18127    WHEN no_data_found THEN
18128       RETURN FALSE;
18129 
18130 END serial_entered_on_parent;
18131 
18132 --Function to check if the lots were entered for the parent transaction
18133 FUNCTION lot_entered_on_parent (p_parent_txn_id IN NUMBER)
18134   RETURN BOOLEAN
18135   IS
18136      l_dummy VARCHAR2(1);
18137 BEGIN
18138    SELECT '1'
18139      INTO l_dummy
18140      FROM rcv_lots_supply
18141      WHERE transaction_id = p_parent_txn_id
18142      AND ROWNUM = 1;
18143 
18144    RETURN TRUE;
18145 EXCEPTION
18146    WHEN no_data_found THEN
18147       RETURN FALSE;
18148 
18149 END lot_entered_on_parent;
18150 
18151 --Function to check if the serials are present for ASN.
18152 FUNCTION rss_exists (p_shipment_header_id IN NUMBER,
18153 		     p_item_id            IN NUMBER)
18154   RETURN BOOLEAN
18155   IS
18156      l_dummy VARCHAR2(1);
18157 BEGIN
18158    SELECT '1'
18159      INTO l_dummy
18160      FROM rcv_serials_supply rss
18161      , rcv_shipment_lines rsl
18162      WHERE rss.shipment_line_id = rsl.shipment_line_id
18163      AND rsl.shipment_header_id = p_shipment_header_id
18164      AND rsl.item_id = p_item_id
18165      AND rss.supply_type_code = 'SHIPMENT'
18166      AND ROWNUM = 1;
18167 
18168    RETURN TRUE;
18169 EXCEPTION
18170    WHEN no_data_found THEN
18171       RETURN FALSE;
18172 END;
18173 
18174 --Function to update the group_mark_id fro serials to -7937
18175 FUNCTION update_group_mark_id(p_item_id IN NUMBER,
18176 			      p_serial_number IN VARCHAR2)
18177   RETURN BOOLEAN
18178   IS
18179 BEGIN
18180    UPDATE mtl_serial_numbers
18181      SET group_mark_id = -7937
18182      WHERE inventory_item_id = p_item_id
18183      AND serial_number = p_serial_number;
18184 
18185    RETURN TRUE;
18186 EXCEPTION
18187    WHEN OTHERS THEN
18188       RETURN FALSE;
18189 END;
18190 
18191 
18192 -- Procedure to move lot/serial info from interface tables to temp tables
18193 PROCEDURE move_lot_serial_info(p_rti_id IN NUMBER,
18194 			       x_return_status OUT nocopy VARCHAR2,
18195 			       x_msg_count OUT nocopy NUMBER,
18196 			       x_msg_data OUT nocopy VARCHAR2)
18197   IS
18198      L_DEBUG NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
18199      l_item_id number;
18200      l_org_id number;
18201      l_uom_code mtl_units_of_measure_vl.uom_code%TYPE;
18202      l_unit_of_measure mtl_units_of_measure_vl.unit_of_measure%TYPE;
18203 
18204      -- Bug 13886318 need to revert bug 12329840
18205      --x_serial_number_control_code NUMBER; -- Bug 12329840
18206 BEGIN
18207 
18208    x_return_status := g_ret_sts_success;
18209    --Bug 9458159 The MTLT primary quantity should be inserted as the corresponding one for transaction quantity in primary uom.
18210    SELECT item_id,to_organization_id,uom_code,unit_of_measure
18211    INTO l_item_id,l_org_id,l_uom_code,l_unit_of_measure
18212    FROM RCV_TRANSACTIONS_INTERFACE
18213    WHERE interface_transaction_id=p_rti_id;
18214 
18215    IF(l_uom_code is null) then
18216         BEGIN
18217         SELECT uom_code
18218           INTO l_uom_code
18219           FROM MTL_UNITS_OF_MEASURE_VL
18220          WHERE unit_of_measure = l_unit_of_measure;
18221 
18222         EXCEPTION
18223              WHEN NO_DATA_FOUND THEN
18224                   print_debug('Unit of measure does not exist ',1);
18225                   fnd_message.set_name('INV', 'INV_UOM_NOTFOUND');
18226                   fnd_message.set_token('UOM', l_unit_of_measure);
18227                   fnd_msg_pub.add;
18228                   RAISE fnd_api.g_exc_error;
18229         END;
18230    END IF;
18231 
18232    INSERT INTO mtl_transaction_lots_temp (TRANSACTION_TEMP_ID,
18233 					  LAST_UPDATE_DATE,
18234 					  LAST_UPDATED_BY,
18235 					  CREATION_DATE,
18236 					  CREATED_BY,
18237 					  LAST_UPDATE_LOGIN,
18238 					  REQUEST_ID,
18239 					  PROGRAM_APPLICATION_ID,
18240 					  PROGRAM_ID,
18241 					  PROGRAM_UPDATE_DATE,
18242 					  TRANSACTION_QUANTITY,
18243 					  PRIMARY_QUANTITY,
18244 					  LOT_NUMBER,
18245 					  LOT_EXPIRATION_DATE,
18246 					  ERROR_CODE,
18247 					  SERIAL_TRANSACTION_TEMP_ID,
18248 					  DESCRIPTION,
18249 					  VENDOR_NAME,
18250 					  SUPPLIER_LOT_NUMBER,
18251 					  ORIGINATION_DATE,
18252 					  DATE_CODE,
18253 					  GRADE_CODE,
18254 					  CHANGE_DATE,
18255 					  MATURITY_DATE,
18256 					  STATUS_ID,
18257 					  RETEST_DATE,
18258 					  AGE,
18259 					  ITEM_SIZE,
18260 					  COLOR,
18261 					  VOLUME,
18262 					  VOLUME_UOM,
18263 					  PLACE_OF_ORIGIN,
18264 					  BEST_BY_DATE,
18265 					  LENGTH,
18266 					  LENGTH_UOM,
18267 					  RECYCLED_CONTENT,
18268 					  THICKNESS,
18269 					  THICKNESS_UOM,
18270 					  WIDTH,
18271 					  WIDTH_UOM,
18272 					  CURL_WRINKLE_FOLD,
18273 					  LOT_ATTRIBUTE_CATEGORY,
18274 					  C_ATTRIBUTE1,
18275 					  C_ATTRIBUTE2,
18276 					  C_ATTRIBUTE3,
18277 					  C_ATTRIBUTE4,
18278      C_ATTRIBUTE5,
18279      C_ATTRIBUTE6,
18280      C_ATTRIBUTE7,
18281      C_ATTRIBUTE8,
18282      C_ATTRIBUTE9,
18283      C_ATTRIBUTE10,
18284      C_ATTRIBUTE11,
18285      C_ATTRIBUTE12,
18286      C_ATTRIBUTE13,
18287      C_ATTRIBUTE14,
18288      C_ATTRIBUTE15,
18289      C_ATTRIBUTE16,
18290      C_ATTRIBUTE17,
18291      C_ATTRIBUTE18,
18292      C_ATTRIBUTE19,
18293      C_ATTRIBUTE20,
18294      D_ATTRIBUTE1,
18295      D_ATTRIBUTE2,
18296      D_ATTRIBUTE3,
18297      D_ATTRIBUTE4,
18298      D_ATTRIBUTE5,
18299      D_ATTRIBUTE6,
18300      D_ATTRIBUTE7,
18301      D_ATTRIBUTE8,
18302      D_ATTRIBUTE9,
18303      D_ATTRIBUTE10,
18304      N_ATTRIBUTE1,
18305      N_ATTRIBUTE2,
18306      N_ATTRIBUTE3,
18307      N_ATTRIBUTE4,
18308      N_ATTRIBUTE5,
18309      N_ATTRIBUTE6,
18310      N_ATTRIBUTE7,
18311      N_ATTRIBUTE8,
18312      N_ATTRIBUTE9,
18313      N_ATTRIBUTE10,
18314      attribute_category,
18315      attribute1,
18316      attribute2,
18317      attribute3,
18318      attribute4,
18319      attribute5,
18320      attribute6,
18321      attribute7,
18322      attribute8,
18323      attribute9,
18324      attribute10,
18325      attribute11,
18326      attribute12,
18327      attribute13,
18328      attribute14,
18329      attribute15,
18330      VENDOR_ID,
18331      TERRITORY_CODE,
18332      PRODUCT_CODE,
18333      PRODUCT_TRANSACTION_ID,
18334      /*INVCONV , Remove sublot_num and add parent parent_lot_number and other attributes, Punit Kumar */
18335 
18336      /** OPM change Bug# 3061052**/
18337      --SUBLOT_NUM             ,
18338      PARENT_LOT_NUMBER        ,
18339      ORIGINATION_TYPE         ,
18340      EXPIRATION_ACTION_DATE   ,
18341      EXPIRATION_ACTION_CODE   ,
18342      HOLD_DATE    ,
18343      REASON_ID    ,
18344      /* end  INVCONV */
18345      SECONDARY_QUANTITY      ,
18346      REASON_CODE                    )
18347      SELECT transaction_interface_id ,
18348      LAST_UPDATE_DATE,
18349      LAST_UPDATED_BY,
18350      CREATION_DATE,
18351      CREATED_BY,
18352      LAST_UPDATE_LOGIN,
18353      REQUEST_ID,
18354      PROGRAM_APPLICATION_ID,
18355      PROGRAM_ID,
18356      PROGRAM_UPDATE_DATE,
18357      TRANSACTION_QUANTITY,
18358      --get_primary_qty(l_org_id,l_item_id,l_uom_code,transaction_quantity),  --Bug 9458159
18359      get_primary_qty(l_org_id,l_item_id,l_uom_code,transaction_quantity,Ltrim(Rtrim(lot_number))), --Bug 13981381, pass lot_number in order to consider lot specific UOM conversion
18360      Ltrim(Rtrim(lot_number)),
18361      LOT_EXPIRATION_DATE,
18362      ERROR_CODE,
18363      SERIAL_TRANSACTION_TEMP_ID,
18364      DESCRIPTION,
18365      VENDOR_NAME,
18366      SUPPLIER_LOT_NUMBER,
18367      ORIGINATION_DATE,
18368      DATE_CODE,
18369      GRADE_CODE,
18370      CHANGE_DATE,
18371      MATURITY_DATE,
18372      STATUS_ID,
18373      RETEST_DATE,
18374      AGE,
18375      ITEM_SIZE,
18376      COLOR,
18377      VOLUME,
18378      VOLUME_UOM,
18379      PLACE_OF_ORIGIN,
18380      BEST_BY_DATE,
18381      LENGTH,
18382      LENGTH_UOM,
18383      RECYCLED_CONTENT,
18384      THICKNESS,
18385      THICKNESS_UOM,
18386      WIDTH,
18387      WIDTH_UOM,
18388      CURL_WRINKLE_FOLD,
18389      LOT_ATTRIBUTE_CATEGORY,
18390      C_ATTRIBUTE1,
18391      C_ATTRIBUTE2,
18392      C_ATTRIBUTE3,
18393      C_ATTRIBUTE4,
18394      C_ATTRIBUTE5,
18395      C_ATTRIBUTE6,
18396      C_ATTRIBUTE7,
18397      C_ATTRIBUTE8,
18398      C_ATTRIBUTE9,
18399      C_ATTRIBUTE10,
18400      C_ATTRIBUTE11,
18401      C_ATTRIBUTE12,
18402      C_ATTRIBUTE13,
18403      C_ATTRIBUTE14,
18404      C_ATTRIBUTE15,
18405      C_ATTRIBUTE16,
18406      C_ATTRIBUTE17,
18407      C_ATTRIBUTE18,
18408      C_ATTRIBUTE19,
18409      C_ATTRIBUTE20,
18410      D_ATTRIBUTE1,
18411      D_ATTRIBUTE2,
18412      D_ATTRIBUTE3,
18413      D_ATTRIBUTE4,
18414      D_ATTRIBUTE5,
18415      D_ATTRIBUTE6,
18416      D_ATTRIBUTE7,
18417      D_ATTRIBUTE8,
18418      D_ATTRIBUTE9,
18419      D_ATTRIBUTE10,
18420      N_ATTRIBUTE1,
18421      N_ATTRIBUTE2,
18422      N_ATTRIBUTE3,
18423      N_ATTRIBUTE4,
18424      N_ATTRIBUTE5,
18425      N_ATTRIBUTE6,
18426      N_ATTRIBUTE7,
18427      N_ATTRIBUTE8,
18428      N_ATTRIBUTE9,
18429      N_ATTRIBUTE10,
18430      attribute_category,
18431      attribute1,
18432      attribute2,
18433      attribute3,
18434      attribute4,
18435      attribute5,
18436      attribute6,
18437      attribute7,
18438      attribute8,
18439      attribute9,
18440      attribute10,
18441      attribute11,
18442      attribute12,
18443      attribute13,
18444      attribute14,
18445      attribute15,
18446      VENDOR_ID,
18447      TERRITORY_CODE,
18448      PRODUCT_CODE,
18449      product_transaction_id,
18450 
18451      /*INVCONV , Remove sublot_num and add parent parent_lot_number and other attributes,
18452      ORIGINATION_TYPE defaulted to 'PURCHASING'. Punit Kumar */
18453 
18454      /** OPM change Bug# 3061052**/
18455      ---sublot_num,
18456 
18457      PARENT_LOT_NUMBER		   ,
18458      3             ,   /* defaulting the value of ORIGINATION_TYPE  to 'PURCHASING'*/
18459      EXPIRATION_ACTION_DATE   ,
18460      EXPIRATION_ACTION_CODE   ,
18461      HOLD_DATE                ,
18462      REASON_ID                ,
18463      /* end INVCONV */
18464      secondary_transaction_quantity,
18465      reason_code
18466      FROM mtl_transaction_lots_interface
18467      WHERE product_code = 'RCV'
18468      AND product_transaction_id = p_rti_id;
18469 
18470 
18471    IF (l_debug = 1) THEN
18472       print_debug('move_lot_serial_info - Number of MTLT Inserted =: '||SQL%ROWCOUNT ||
18473 		  ' with product transaction_id = ' || p_rti_id, 1);
18474       /*INVCONV*/
18475        print_debug('INVCONV, removed sublot_num, Added some more parameters in INSERT INTO mtl_transaction_lots_temp (move_lot_serial_info)', 1);
18476      /*end , INVCONV*/
18477 
18478    END IF;
18479 
18480    -- Bug 13886318 need to revert bug 12329840
18481    /* Bug 12329840 Modified the code so that we are not inserting into MSNT
18482       if the item's serial control code is 1
18483    */
18484 /*   BEGIN
18485        SELECT msi.serial_number_control_code
18486        INTO   x_serial_number_control_code
18487        FROM   mtl_system_items msi, rcv_transactions_interface rti
18488        WHERE  msi.inventory_item_id        = rti.item_id
18489        AND    msi.organization_id          = rti.to_organization_id
18490        AND    rti.interface_transaction_id = p_rti_id;
18491    EXCEPTION
18492        WHEN OTHERS THEN
18493            x_serial_number_control_code := 1;
18494            IF (l_debug = 1) THEN
18495                print_debug('Ignoring exception while retrieving serial number control code', 1);
18496            END IF;
18497    END;
18498 
18499    IF (x_serial_number_control_code <> 1) THEN  */  -- Bug 13886318 need to revert bug 12329840
18500 
18501    INSERT INTO mtl_serial_numbers_temp (TRANSACTION_TEMP_ID,
18502 					LAST_UPDATE_DATE,
18503 					LAST_UPDATED_BY,
18504 					CREATION_DATE,
18505 					CREATED_BY,
18506 					LAST_UPDATE_LOGIN,
18507 					REQUEST_ID,
18508 					PROGRAM_APPLICATION_ID,
18509 					PROGRAM_ID,
18510 					PROGRAM_UPDATE_DATE,
18511 					VENDOR_SERIAL_NUMBER,
18512 					VENDOR_LOT_NUMBER,
18513 					FM_SERIAL_NUMBER,
18514 					TO_SERIAL_NUMBER,
18515 					ERROR_CODE,
18516 					PARENT_SERIAL_NUMBER,
18517 					SERIAL_ATTRIBUTE_CATEGORY,
18518 					ORIGINATION_DATE,
18519 					C_ATTRIBUTE1,
18520 					C_ATTRIBUTE2,
18521 					C_ATTRIBUTE3,
18522 					C_ATTRIBUTE4,
18523 					C_ATTRIBUTE5,
18524 					C_ATTRIBUTE6,
18525 					C_ATTRIBUTE7,
18526 					C_ATTRIBUTE8,
18527 					C_ATTRIBUTE9,
18528 					C_ATTRIBUTE10,
18529 					C_ATTRIBUTE11,
18530 					C_ATTRIBUTE12,
18531 					C_ATTRIBUTE13,
18532 					C_ATTRIBUTE14,
18533 					C_ATTRIBUTE15,
18534 					C_ATTRIBUTE16,
18535 					C_ATTRIBUTE17,
18536 					C_ATTRIBUTE18,
18537 					C_ATTRIBUTE19,
18538 					C_ATTRIBUTE20,
18539 					D_ATTRIBUTE1,
18540 					D_ATTRIBUTE2,
18541 					D_ATTRIBUTE3,
18542 					D_ATTRIBUTE4,
18543 					D_ATTRIBUTE5,
18544 					D_ATTRIBUTE6,
18545 					D_ATTRIBUTE7,
18546 					D_ATTRIBUTE8,
18547 					D_ATTRIBUTE9,
18548 					D_ATTRIBUTE10,
18549 					N_ATTRIBUTE1,
18550      N_ATTRIBUTE2,
18551      N_ATTRIBUTE3,
18552      N_ATTRIBUTE4,
18553      N_ATTRIBUTE5,
18554      N_ATTRIBUTE6,
18555      N_ATTRIBUTE7,
18556      N_ATTRIBUTE8,
18557      N_ATTRIBUTE9,
18558      N_ATTRIBUTE10,
18559      attribute_category,
18560      attribute1,
18561      attribute2,
18562      attribute3,
18563      attribute4,
18564      attribute5,
18565      attribute6,
18566      attribute7,
18567      attribute8,
18568      attribute9,
18569      attribute10,
18570      attribute11,
18571      attribute12,
18572      attribute13,
18573      attribute14,
18574      attribute15,
18575      STATUS_ID,
18576      TERRITORY_CODE,
18577      TIME_SINCE_NEW,
18578      CYCLES_SINCE_NEW,
18579      TIME_SINCE_OVERHAUL,
18580      CYCLES_SINCE_OVERHAUL,
18581      TIME_SINCE_REPAIR,
18582      CYCLES_SINCE_REPAIR,
18583      TIME_SINCE_VISIT,
18584      CYCLES_SINCE_VISIT,
18585      TIME_SINCE_MARK,
18586      CYCLES_SINCE_MARK,
18587      NUMBER_OF_REPAIRS,
18588      PRODUCT_CODE,
18589      product_transaction_id)
18590      SELECT transaction_interface_id,
18591      LAST_UPDATE_DATE,
18592      LAST_UPDATED_BY,
18593      CREATION_DATE,
18594      CREATED_BY,
18595      LAST_UPDATE_LOGIN,
18596      REQUEST_ID,
18597      PROGRAM_APPLICATION_ID,
18598      PROGRAM_ID,
18599      PROGRAM_UPDATE_DATE,
18600      VENDOR_SERIAL_NUMBER,
18601      VENDOR_LOT_NUMBER,
18602      FM_SERIAL_NUMBER,
18603      TO_SERIAL_NUMBER,
18604      ERROR_CODE,
18605      PARENT_SERIAL_NUMBER,
18606      SERIAL_ATTRIBUTE_CATEGORY,
18607      ORIGINATION_DATE,
18608      C_ATTRIBUTE1,
18609      C_ATTRIBUTE2,
18610      C_ATTRIBUTE3,
18611      C_ATTRIBUTE4,
18612      C_ATTRIBUTE5,
18613      C_ATTRIBUTE6,
18614      C_ATTRIBUTE7,
18615      C_ATTRIBUTE8,
18616      C_ATTRIBUTE9,
18617      C_ATTRIBUTE10,
18618      C_ATTRIBUTE11,
18619      C_ATTRIBUTE12,
18620      C_ATTRIBUTE13,
18621      C_ATTRIBUTE14,
18622      C_ATTRIBUTE15,
18623      C_ATTRIBUTE16,
18624      C_ATTRIBUTE17,
18625      C_ATTRIBUTE18,
18626      C_ATTRIBUTE19,
18627      C_ATTRIBUTE20,
18628      D_ATTRIBUTE1,
18629      D_ATTRIBUTE2,
18630      D_ATTRIBUTE3,
18631      D_ATTRIBUTE4,
18632      D_ATTRIBUTE5,
18633      D_ATTRIBUTE6,
18634      D_ATTRIBUTE7,
18635      D_ATTRIBUTE8,
18636      D_ATTRIBUTE9,
18637      D_ATTRIBUTE10,
18638      N_ATTRIBUTE1,
18639      N_ATTRIBUTE2,
18640      N_ATTRIBUTE3,
18641      N_ATTRIBUTE4,
18642      N_ATTRIBUTE5,
18643      N_ATTRIBUTE6,
18644      N_ATTRIBUTE7,
18645      N_ATTRIBUTE8,
18646      N_ATTRIBUTE9,
18647      N_ATTRIBUTE10,
18648      attribute_category,
18649      attribute1,
18650      attribute2,
18651      attribute3,
18652      attribute4,
18653      attribute5,
18654      attribute6,
18655      attribute7,
18656      attribute8,
18657      attribute9,
18658      attribute10,
18659      attribute11,
18660      attribute12,
18661      attribute13,
18662      attribute14,
18663      attribute15,
18664      STATUS_ID,
18665      TERRITORY_CODE,
18666      TIME_SINCE_NEW,
18667      CYCLES_SINCE_NEW,
18668      TIME_SINCE_OVERHAUL,
18669      CYCLES_SINCE_OVERHAUL,
18670      TIME_SINCE_REPAIR,
18671      CYCLES_SINCE_REPAIR,
18672      TIME_SINCE_VISIT,
18673      CYCLES_SINCE_VISIT,
18674      TIME_SINCE_MARK,
18675      CYCLES_SINCE_MARK,
18676      NUMBER_OF_REPAIRS,
18677      PRODUCT_CODE,
18678      product_transaction_id
18679      FROM mtl_serial_numbers_interface
18680      WHERE product_code = 'RCV'
18681      AND product_transaction_id = p_rti_id;
18682 
18683    IF (l_debug = 1) THEN
18684       print_debug('move_lot_serial_info - Number of MSNT Inserted =: '||SQL%ROWCOUNT ||
18685 		  ' with product transaction_id =' || p_rti_id, 1);
18686    END IF;
18687 
18688    -- Bug 13886318 need to revert bug 12329840
18689    -- END IF; -- Bug 12329840
18690 
18691 /* Added By Bug#9713930 */
18692    UPDATE mtl_transaction_lots_temp mtlt
18693    set mtlt.serial_transaction_temp_id =
18694    (Select msni.transaction_interface_id
18695    from mtl_serial_numbers_interface msni where
18696    msni.product_code = 'RCV'
18697    AND msni.product_transaction_id = p_rti_id
18698    and rownum=1)
18699    where mtlt.product_code = 'RCV'
18700    AND mtlt.product_transaction_id = p_rti_id
18701    and mtlt.serial_transaction_temp_id is null;
18702 
18703    --delete mtli and msni
18704    DELETE FROM mtl_transaction_lots_interface
18705      WHERE product_code = 'RCV'
18706      AND product_transaction_id = p_rti_id;
18707 
18708    DELETE FROM mtl_serial_numbers_interface
18709      WHERE product_code = 'RCV'
18710      AND product_transaction_id = p_rti_id;
18711 
18712 EXCEPTION
18713    WHEN OTHERS THEN
18714       IF (l_debug = 1) THEN
18715          print_debug('move_lot_serial_info - Other Exception error = '|| SQLCODE || ' this is ignored ' , 1);
18716       END IF;
18717       NULL;
18718 END move_lot_serial_info;
18719 
18720 
18721 /* The following procedure will be called from RCV processor to validate
18722 lot serials. This procecure will be called once for each RTI row. */
18723 
18724 
18725   PROCEDURE VALIDATE_LOT_SERIAL_INFO (P_RTI_ID IN NUMBER,
18726 				      X_RETURN_STATUS OUT NOCOPY VARCHAR2,
18727 				      X_MSG_COUNT OUT NOCOPY NUMBER,
18728 				      X_MSG_DATA OUT NOCOPY VARCHAR2)
18729   IS
18730      l_lot_status_enabled VARCHAR2(1) := 'Y'; --Bug 4066234
18731      --Bug #3187688 - Fetch the INV attribute category and attributes1-15 from MTLT
18732      CURSOR C_MTLT (L_RTI_ID NUMBER) IS
18733 	SELECT Ltrim(Rtrim(lot_number)) lot_number
18734 	  , SERIAL_TRANSACTION_TEMP_ID
18735 	  , TRANSACTION_QUANTITY
18736 	  , primary_quantity
18737 	  , lot_expiration_date
18738 	  , lot_attribute_category
18739 	  , C_ATTRIBUTE1
18740 	  , C_ATTRIBUTE2
18741 	  , C_ATTRIBUTE3
18742 	  , C_ATTRIBUTE4
18743 	  , C_ATTRIBUTE5
18744 	  , C_ATTRIBUTE6
18745 	  , C_ATTRIBUTE7
18746 	  , C_ATTRIBUTE8
18747 	  , C_ATTRIBUTE9
18748 	  , C_ATTRIBUTE10
18749 	  , C_ATTRIBUTE11
18750 	  , C_ATTRIBUTE12
18751 	  , C_ATTRIBUTE13
18752 	  , C_ATTRIBUTE14
18753 	  , C_ATTRIBUTE15
18754 	  , C_ATTRIBUTE16
18755 	  , C_ATTRIBUTE17
18756 	  , C_ATTRIBUTE18
18757 	  , C_ATTRIBUTE19
18758 	  , C_ATTRIBUTE20
18759 	  , D_ATTRIBUTE1
18760 	  , D_ATTRIBUTE2
18761 	  , D_ATTRIBUTE3
18762 	  , D_ATTRIBUTE4
18763 	  , D_ATTRIBUTE5
18764 	  , D_ATTRIBUTE6
18765 	  , D_ATTRIBUTE7
18766 	  , D_ATTRIBUTE8
18767 	  , D_ATTRIBUTE9
18768 	  , D_ATTRIBUTE10
18769 	  , N_ATTRIBUTE1
18770 	  , N_ATTRIBUTE2
18771 	  , N_ATTRIBUTE3
18772 	  , N_ATTRIBUTE4
18773 	  , N_ATTRIBUTE5
18774 	  , N_ATTRIBUTE6
18775 	  , N_ATTRIBUTE7
18776 	  , N_ATTRIBUTE8
18777 	  , N_ATTRIBUTE9
18778 	  , n_attribute10
18779 	  , grade_code
18780 	  , origination_date
18781 	  , date_code
18782 	  , Decode(l_lot_status_enabled,'Y',status_id,1) status_id --Bug 4066234
18783 	  , change_date
18784 	  , age
18785 	  , retest_date
18786 	  , maturity_date
18787 	  , item_size
18788 	  , color
18789 	  , volume
18790 	  , volume_uom
18791 	  , place_of_origin
18792 	  , best_by_date
18793 	  , Length
18794 	  , length_uom
18795 	  , recycled_content
18796 	  , thickness
18797 	  , thickness_uom
18798 	  , width
18799 	  , width_uom
18800 	  , territory_code
18801 	  , supplier_lot_number
18802 	  , vendor_name
18803 	  /** INVCONV,remove sublot_number, add Parent lot number and SECONDARY_UNIT_OF_MEASURE etc,
18804       Punit Kumar**/
18805 	  ---, Ltrim(Rtrim(sublot_num)) sublot_num
18806      ,Ltrim(Rtrim(PARENT_LOT_NUMBER)) PARENT_LOT_NUMBER
18807      ----,SECONDARY_UNIT_OF_MEASURE
18808      ,REASON_ID
18809      ,LAST_UPDATED_BY
18810      ,CREATED_BY
18811      ,LAST_UPDATE_LOGIN
18812      ,REQUEST_ID
18813      ,PROGRAM_APPLICATION_ID
18814      ,PROGRAM_ID
18815      ,PROGRAM_UPDATE_DATE
18816      ,DESCRIPTION
18817      ,CURL_WRINKLE_FOLD
18818      ,VENDOR_ID
18819      ,ORIGINATION_TYPE
18820      ,EXPIRATION_ACTION_DATE
18821      ,EXPIRATION_ACTION_CODE
18822      ,HOLD_DATE
18823      ----,TRANSACTION_TEMP_ID
18824      /* end INVCONV */
18825 	  , secondary_quantity
18826 	  , reason_code
18827 	  , rowid
18828     , attribute_category
18829     , attribute1
18830     , attribute2
18831     , attribute3
18832     , attribute4
18833     , attribute5
18834     , attribute6
18835     , attribute7
18836     , attribute8
18837     , attribute9
18838     , attribute10
18839     , attribute11
18840     , attribute12
18841     , attribute13
18842     , attribute14
18843     , attribute15
18844 	  FROM MTL_TRANSACTION_LOTS_TEMP
18845 	  WHERE PRODUCT_CODE = 'RCV'
18846 	  AND PRODUCT_TRANSACTION_ID = L_RTI_ID;
18847 
18848      L_MTLT_REC C_MTLT%ROWTYPE;
18849 
18850      CURSOR C_MSNT (L_RTI_ID NUMBER) IS
18851 	SELECT FM_SERIAL_NUMBER
18852 	  , to_serial_number
18853 	  , vendor_serial_number
18854 	  , transaction_temp_id
18855 	  , serial_attribute_category
18856 	  , origination_date
18857 	  , c_attribute1
18858 	  , c_attribute2
18859 	  , c_attribute3
18860 	  , c_attribute4
18861 	  , c_attribute5
18862 	  , c_attribute6
18863 	  , c_attribute7
18864 	  , c_attribute8
18865 	  , c_attribute9
18866 	  , c_attribute10
18867 	  , c_attribute11
18868 	  , c_attribute12
18869 	  , c_attribute13
18870 	  , c_attribute14
18871 	  , c_attribute15
18872 	  , c_attribute16
18873 	  , c_attribute17
18874 	  , c_attribute18
18875 	  , c_attribute19
18876 	  , c_attribute20
18877 	  , d_attribute1
18878 	  , d_attribute2
18879 	  , d_attribute3
18880 	  , d_attribute4
18881 	  , d_attribute5
18882 	  , d_attribute6
18883 	  , d_attribute7
18884 	  , d_attribute8
18885 	  , d_attribute9
18886 	  , d_attribute10
18887 	  , n_attribute1
18888 	  , n_attribute2
18889 	  , n_attribute3
18890 	  , n_attribute4
18891 	  , n_attribute5
18892 	  , n_attribute6
18893 	  , n_attribute7
18894 	  , n_attribute8
18895 	  , n_attribute9
18896 	  , n_attribute10
18897 	  , status_id
18898 	  , territory_code
18899 	  , attribute_category
18900 	  , attribute1
18901 	  , attribute2
18902 	  , attribute3
18903 	  , attribute4
18904 	  , attribute5
18905 	  , attribute6
18906 	  , attribute7
18907 	  , attribute8
18908 	  , attribute9
18909 	  , attribute10
18910 	  , attribute11
18911 	  , attribute12
18912 	  , attribute13
18913 	  , attribute14
18914 	  , attribute15
18915 	  , ROWID
18916 	  FROM MTL_SERIAL_NUMBERS_TEMP
18917 	  WHERE PRODUCT_CODE = 'RCV'
18918 	  AND PRODUCT_TRANSACTION_ID = L_RTI_ID;
18919 
18920      L_MSNT_REC C_MSNT%ROWTYPE;
18921 
18922      CURSOR C_MSNT_LOTSERIAL (L_SERIAL_TXN_ID NUMBER) IS
18923 	SELECT FM_SERIAL_NUMBER
18924 	  , to_serial_number
18925 	  , vendor_serial_number
18926 	  , transaction_temp_id
18927 	  , serial_attribute_category
18928 	  , origination_date
18929 	  , c_attribute1
18930 	  , c_attribute2
18931 	  , c_attribute3
18932 	  , c_attribute4
18933 	  , c_attribute5
18934 	  , c_attribute6
18935 	  , c_attribute7
18936 	  , c_attribute8
18937 	  , c_attribute9
18938 	  , c_attribute10
18939 	  , c_attribute11
18940 	  , c_attribute12
18941 	  , c_attribute13
18942 	  , c_attribute14
18943 	  , c_attribute15
18944 	  , c_attribute16
18945 	  , c_attribute17
18946 	  , c_attribute18
18947 	  , c_attribute19
18948 	  , c_attribute20
18949 	  , d_attribute1
18950 	  , d_attribute2
18951 	  , d_attribute3
18952 	  , d_attribute4
18953 	  , d_attribute5
18954 	  , d_attribute6
18955 	  , d_attribute7
18956 	  , d_attribute8
18957 	  , d_attribute9
18958 	  , d_attribute10
18959 	  , n_attribute1
18960 	  , n_attribute2
18961 	  , n_attribute3
18962 	  , n_attribute4
18963 	  , n_attribute5
18964 	  , n_attribute6
18965 	  , n_attribute7
18966 	  , n_attribute8
18967 	  , n_attribute9
18968 	  , n_attribute10
18969 	  , status_id
18970 	  , territory_code
18971 	  , attribute_category
18972 	  , attribute1
18973       , attribute2
18974       , attribute3
18975       , attribute4
18976       , attribute5
18977       , attribute6
18978       , attribute7
18979       , attribute8
18980       , attribute9
18981       , attribute10
18982       , attribute11
18983       , attribute12
18984       , attribute13
18985       , attribute14
18986       , attribute15
18987 	  , ROWID
18988 	  FROM MTL_SERIAL_NUMBERS_TEMP
18989 	  WHERE PRODUCT_CODE = 'RCV'
18990 	  AND transaction_temp_id = L_SERIAL_TXN_ID;
18991 
18992      l_rti_id NUMBER;
18993 
18994      L_TRANSACTION_TYPE VARCHAR2(25);
18995      L_AUTO_TRANSACT_CODE VARCHAR2(25);
18996      L_SOURCE_DOCUMENT_CODE VARCHAR2(25);
18997      L_ITEM_ID NUMBER;
18998      l_item_revision varchar2(3);
18999      L_LPN_ID NUMBER;
19000      L_TRANSFER_LPN_ID NUMBER;
19001      L_LOT_CONTROL_CODE NUMBER;
19002      L_SERIAL_NUMBER_CONTROL_CODE NUMBER;
19003      L_FROM_ORG_ID NUMBER;
19004      L_ORG_ID NUMBER;
19005      L_SHIPMENT_LINE_ID NUMBER;
19006      L_SHIPMENT_HEADER_ID NUMBER;
19007      L_PARENT_TRANSACTION_ID NUMBER;
19008      L_SUB_CODE VARCHAR2(10);
19009      L_LOC_ID NUMBER;
19010      l_routing_header_id NUMBER;
19011      l_asn_line_flag VARCHAR2(1);
19012      l_rti_primary_qty NUMBER;
19013      l_rti_trans_qty NUMBER; -- Bug# 4225766
19014      l_mobile_txn VARCHAR2(1);
19015      l_inv_txn_id NUMBER;
19016      l_proc_mode_code VARCHAR2(30);
19017 
19018      l_destination_type_code VARCHAR2(30);
19019 
19020      l_transaction_type_id NUMBER;
19021      l_transaction_action_id NUMBER;
19022 
19023      L_NUM_MTLT_RECS NUMBER;
19024      L_NUM_MSNT_RECS NUMBER;
19025      l_tot_mtlt_prim_qty NUMBER;
19026      l_tot_mtlt_trans_qty NUMBER; -- Bug# 4225766
19027      l_tot_msnt_serial_qty NUMBER;
19028 
19029      L_LOT_EXISTS NUMBER := 0;
19030      l_serial_exists NUMBER := 0;
19031 
19032      L_SERIAL_QUANTITY NUMBER;
19033      L_TEMP_PREFIX VARCHAR2(30);
19034      L_FROM_SER_NUMBER NUMBER;
19035      L_TO_SER_NUMBER   NUMBER;
19036      L_SERIAL_NUMBER VARCHAR2(30);
19037      L_CUR_NUMBER     NUMBER;
19038 
19039      L_CURR_ORG_ID NUMBER;
19040      L_CURR_STATUS NUMBER;
19041 -- Increased lot size to 80 Char - Mercy Thomas - B4625329
19042      l_curr_lot_num VARCHAR2(80);
19043      l_curr_lpn_id NUMBER;
19044      l_inspection_status NUMBER;
19045      l_group_mark_id NUMBER;
19046 
19047      L_FROM_ORG_LOT_CTRL NUMBER;
19048      L_FROM_ORG_SER_CRTL NUMBER;
19049      l_from_org_rev_ctrl NUMBER;
19050 
19051      L_DUMMY VARCHAR2(1);
19052      L_ATT_VAL_STATUS VARCHAR2(1);
19053      L_LOT_ENTERED_ON_PARENT BOOLEAN;
19054      L_SERIAL_ENTERED_ON_PARENT BOOLEAN;
19055      L_RLS_PRIMARY_QUANTITY NUMBER;
19056 
19057      L_VALIDATION_STATUS VARCHAR2(1);
19058 
19059      --l_txn_src_type_id NUMBER; /*bug4187663*/
19060 
19061      l_inv_attributes_tbl           inv_lot_api_pub.char_tbl;
19062      l_c_attributes_tbl             inv_lot_api_pub.char_tbl;
19063      l_n_attributes_tbl             inv_lot_api_pub.number_tbl;
19064      l_d_attributes_tbl             inv_lot_api_pub.date_tbl;
19065 
19066      l_serial_attributes_tbl        inv_lot_sel_attr.lot_sel_attributes_tbl_type;
19067 
19068      l_inv_att_index NUMBER;
19069 
19070      l_parent_txn_type VARCHAR2(25);
19071      l_grand_parent_txn_id NUMBER;
19072 
19073      l_grand_parent_txn_type VARCHAR2(25);
19074      l_great_grand_parent_txn_id NUMBER;
19075 
19076      l_object_id NUMBER;
19077 
19078      l_dummy_lpn NUMBER;
19079 
19080      l_restrict_rcpt_ser VARCHAR2(1) := NVL(fnd_profile.value('INV_RESTRICT_RCPT_SER'),'2');
19081 
19082      L_DEBUG NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
19083      l_progress VARCHAR2(15) := '00';
19084 
19085      l_intransit_type NUMBER := 0;
19086 
19087      -- OPM related variables. bug# 3061052
19088      l_discrete_transaction	BOOLEAN := TRUE;
19089      l_opm_lot_ctl		NUMBER(5) := -1;
19090      ----l_opm_sublot_ctl		NUMBER(5) := -1;
19091      l_opm_item_id		NUMBER    := NULL ;
19092      l_item_no			VARCHAR2(32) ;
19093      l_opm_lot_id		NUMBER;
19094      /* INVCONV , added local variables. Punit Kumar */
19095      l_parent_lot_number            VARCHAR2(80);
19096      l_OE_ORDER_HEADER_ID           NUMBER      ;
19097      l_OE_ORDER_LINE_ID             NUMBER      ;
19098      l_rti_SECONDARY_QUANTITY       NUMBER      ;
19099      l_rti_PRIMARY_UNIT_OF_MEASURE  VARCHAR2(25);
19100      l_rti_UNIT_OF_MEASURE          VARCHAR2(25);
19101      l_rti_UOM_CODE                 VARCHAR2(3) ;
19102      l_rti_SECONDARY_UOM_CODE       VARCHAR2(3) ;
19103      l_mln_rec          mtl_lot_numbers%ROWTYPE ;
19104      l_sourcedoc_unit_of_measure    VARCHAR2(25);
19105      l_rti_SEC_UNIT_OF_MEASURE   VARCHAR2(25);
19106      /* end INVCONV */
19107 
19108      --R12: EPC requirements
19109      l_lpn_grp_id                   NUMBER;
19110      l_epc_column                   VARCHAR2(30);
19111      l_epc_value                    VARCHAR2(100);
19112      l_return_status                VARCHAR2(1);
19113      l_msg_data                     VARCHAR2(2000);
19114      --END R12
19115 
19116      l_last_transaction_id       mtl_material_transactions.transaction_id%type; --bug 5168883
19117      l_last_transaction_type_id  mtl_material_transactions.transaction_type_id%type; -- 5168883
19118 
19119      --Serial tagging
19120      l_parent_transaction_type       VARCHAR2(25);
19121      l_serial_tagged                 NUMBER := 1; -- Bug 13886318 added initianlization
19122      l_allow_status_entry VARCHAR2(3)   := NVL(fnd_profile.VALUE('INV_ALLOW_ONHAND_STATUS_ENTRY'), 'N');  -- Material Status Enhancement - Tracking bug: 13519864
19123      l_default_status_id number := NULL; -- Material Status Enhancement - Tracking bug: 13519864
19124 	 l_from_subinventory VARCHAR2(10); -- Bug 14269152
19125      l_from_locator_id NUMBER; -- Bug 14269152
19126 
19127   BEGIN
19128     X_RETURN_STATUS := G_RET_STS_SUCCESS;
19129 
19130     IF (l_debug = 1) THEN
19131         print_debug('VALIDATE_LOT_SERIAL_INFO: RTI_ID =  : '|| P_RTI_ID , 1);
19132     END IF;
19133 
19134     L_RTI_ID := P_RTI_ID;
19135 
19136     l_progress := 'WMSINB-21949';
19137 
19138     --FIRST MOVE MTLI TO MTLT AND MSNI TO MSNT.
19139     MOVE_LOT_SERIAL_INFO(P_RTI_ID => L_RTI_ID,
19140 			  X_RETURN_STATUS => X_RETURN_STATUS,
19141 			  X_MSG_COUNT => X_MSG_COUNT,
19142 			  X_MSG_DATA => X_MSG_DATA);
19143     IF X_RETURN_STATUS <> 'S' THEN
19144         -- RAIse error
19145         l_progress := 'WMSINB-21958';
19146         RAISE fnd_api.g_exc_error;
19147     END IF;
19148 
19149     IF (l_debug = 1) THEN
19150          print_debug('VALIDATE_LOT_SERIAL_INFO: MOVE_LOT_SERIAL_INFO done :'||l_progress, 1);
19151          l_progress := 'WMSINB-21964';
19152     END IF;
19153 
19154     -- QUERY RTI TO GET SOME BASIC INFORMATION FROM RTI
19155     BEGIN
19156         SELECT TRANSACTION_TYPE
19157         , AUTO_TRANSACT_CODE
19158         , SOURCE_DOCUMENT_CODE
19159         , item_id
19160         , item_revision
19161         , LPN_ID
19162         , TRANSFER_LPN_ID
19163         , FROM_ORGANIZATION_ID
19164         , TO_ORGANIZATION_ID
19165         , SHIPMENT_LINE_ID
19166         , PARENT_TRANSACTION_ID
19167         , SUBINVENTORY
19168         , locator_id
19169         , routing_header_id
19170         , Nvl(primary_quantity, quantity)
19171         , quantity -- Bug# 4225766
19172         , shipment_header_id
19173         , destination_type_code
19174         , Nvl(mobile_txn, 'N')
19175         , inv_transaction_id
19176         , processing_mode_code
19177          /* INVCONV , added following , Punit Kumar */
19178         ,OE_ORDER_HEADER_ID
19179         ,OE_ORDER_LINE_ID
19180         ,SECONDARY_QUANTITY
19181         ,PRIMARY_UNIT_OF_MEASURE
19182         ,UOM_CODE
19183         ,SECONDARY_UOM_CODE
19184         ,SOURCE_DOC_UNIT_OF_MEASURE
19185         ,UNIT_OF_MEASURE
19186         ,SECONDARY_UNIT_OF_MEASURE
19187         /* end INVCONV */
19188         ,lpn_group_id
19189         ,from_subinventory -- Bug 14269152
19190         ,from_locator_id -- Bug 14269152
19191         INTO L_TRANSACTION_TYPE
19192         , L_AUTO_TRANSACT_CODE
19193         , L_SOURCE_DOCUMENT_CODE
19194         , l_item_id
19195         , l_item_revision
19196         , L_LPN_ID
19197         , L_TRANSFER_LPN_ID
19198         , L_FROM_ORG_ID
19199         , L_ORG_ID
19200         , L_SHIPMENT_LINE_ID
19201         , L_PARENT_TRANSACTION_ID
19202         , L_SUB_CODE
19203         , l_loc_id
19204         , l_routing_header_id
19205         , l_rti_primary_qty
19206         , l_rti_trans_qty -- Bug# 4225766
19207         , l_shipment_header_id
19208         , l_destination_type_code
19209         , l_mobile_txn
19210         , l_inv_txn_id
19211         , l_proc_mode_code
19212         /* INVCONV , added following , Punit Kumar */
19213         , l_OE_ORDER_HEADER_ID
19214         , l_OE_ORDER_LINE_ID
19215         , l_rti_SECONDARY_QUANTITY
19216         , l_rti_PRIMARY_UNIT_OF_MEASURE
19217         , l_rti_UOM_CODE
19218         , l_rti_SECONDARY_UOM_CODE
19219         , l_sourcedoc_unit_of_measure
19220         , l_rti_UNIT_OF_MEASURE
19221         , l_rti_SEC_UNIT_OF_MEASURE
19222         /* end INVCONV */
19223         , l_lpn_grp_id
19224         , l_from_subinventory -- Bug 14269152
19225         , l_from_locator_id -- Bug 14269152
19226         FROM RCV_TRANSACTIONS_INTERFACE
19227         WHERE INTERFACE_TRANSACTION_ID = L_RTI_ID;
19228 
19229         IF l_shipment_line_id IS NOT NULL THEN
19230             -- THIS IS CHANGED TO TAKE INTO ACCOUNT ASN_TYPE
19231             --SELECT Nvl(asn_line_flag, 'N')
19232             --  INTO l_asn_line_flag
19233             --  FROM rcv_shipment_lines
19234             --  WHERE shipment_line_id = l_shipment_line_id;
19235             --Bug 13891514 Adding ASBN as well because the validations/processing is same for ASN/ASBN
19236             select decode(ASN_TYPE,'ASN','Y', 'ASBN','Y','N')
19237               into l_asn_line_flag
19238               from rcv_shipment_headers
19239               WHERE shipment_header_id =  l_shipment_header_id;
19240         ELSE
19241             l_asn_line_flag := 'N';
19242         END IF;
19243     EXCEPTION
19244       WHEN NO_DATA_FOUND THEN
19245          -- RAISE ERROR
19246          l_progress := 'WMSINB-22014';
19247          RAISE fnd_api.g_exc_error;
19248     END;
19249 
19250     IF (l_debug = 1) THEN
19251          print_debug('VALIDATE_LOT_SERIAL_INFO: RTI query done :'||l_progress, 1);
19252          print_debug('VALIDATE_LOT_SERIAL_INFO: TRANSACTION TYPE: '||l_transaction_type||': '||l_progress, 1);
19253          l_progress := 'WMSINB-22021';
19254     END IF;
19255 
19256     -- If destination_type_Code is EXPENSE then lot/serial information is
19257     -- not required.
19258     IF (Nvl(l_destination_type_code, '@@@@@') IN ('EXPENSE','SHOP FLOOR')) THEN
19259         IF (l_debug = 1) THEN
19260            print_debug('VALIDATE_LOT_SERIAL_INFO: Destination EXPENSE/SHOP FLOOR. Exiting...',1);
19261         END IF;
19262         RETURN;
19263     END IF;
19264 
19265     -- ONE TIME ITEMS CANNOT BE LOT/SERIAL CONTROLLED
19266     IF l_item_id IS NULL THEN
19267         IF (l_debug = 1) THEN
19268            print_debug('VALIDATE_LOT_SERIAL_INFO: One Time Item. Exiting...',1);
19269         END IF;
19270         RETURN;
19271     END IF;
19272 
19273     --If the source document is 'REQ' then of the intransit_type in
19274     --mtl_interorg_parameters is set to 'Direct' then exit from this api.
19275     IF (l_source_document_code = 'REQ'
19276          AND l_mobile_txn = 'N'
19277          AND l_transaction_type = 'RECEIVE'
19278          AND l_inv_txn_id IS NOT NULL
19279          AND l_proc_mode_code = 'ONLINE') THEN
19280         BEGIN
19281            SELECT intransit_type
19282              INTO l_intransit_type
19283              FROM mtl_interorg_parameters
19284              WHERE from_organization_id = l_from_org_id
19285              AND to_organization_id = l_org_id;
19286 
19287            IF (l_intransit_type = 1) THEN
19288               print_debug('VALIDATE_LOT_SERIAL_INFO: Direct Org Transfer ... Exitting...',1);
19289               RETURN;
19290            END IF;
19291         EXCEPTION
19292            WHEN OTHERS THEN
19293               NULL;
19294         END;
19295     END IF; --IF (l_source_document_code = 'REQ') THEN
19296 
19297     /*INVCONV, The code is forked for OPM specific logic.
19298        We shall remove this and merge OPM logic with discrete logic.
19299        Following OPM installation check  needs to be removed, Punit Kumar */
19300 
19301     /*   IF GML_PROCESS_FLAGS.opm_installed = 0 OR
19302           (gml_process_flags.check_process_orgn(p_organization_id =>l_org_id) = 0) THEN
19303         l_discrete_transaction := TRUE;
19304              ELSE
19305         l_discrete_transaction := FALSE; -- OPM transaction
19306             END IF;
19307 
19308          end, INVCONV */
19309 
19310      -- QUERY THE ITEM RECORD TO GET LOT/SERIAL CONTROLS FOR THE ITEM
19311 
19312     BEGIN
19313 
19314       /*INVCONV , OPM specific fork and discrete specific check need to be removed.
19315         Now there shall be one common logic for both.Punit Kumar*/
19316 
19317       /* IF (l_discrete_transaction) THEN */
19318 
19319       SELECT LOT_CONTROL_CODE
19320         , SERIAL_NUMBER_CONTROL_CODE
19321         , lot_status_enabled --Bug 4066234
19322       INTO L_LOT_CONTROL_CODE
19323         , L_SERIAL_NUMBER_CONTROL_CODE
19324         , l_lot_status_enabled --Bug 4066234
19325       FROM MTL_SYSTEM_ITEMS
19326       WHERE INVENTORY_ITEM_ID = L_ITEM_ID
19327 	     AND ORGANIZATION_ID = L_ORG_ID;
19328         /*
19329        ELSE	--IF (l_discrete_transaction) THEN
19330          /** OPM change  bug# 3061052
19331              select iim.lot_ctl,iim.sublot_ctl,iim.item_id,iim.item_no
19332            into l_opm_lot_ctl,l_opm_sublot_ctl,l_opm_item_id,l_item_no
19333            from mtl_system_items msi , ic_item_mst iim
19334            where msi.inventory_item_id = l_item_id
19335            and   msi.organization_id = l_org_id
19336            and   msi.segment1 = iim.item_no ;
19337 
19338       END IF; --IF (l_discrete_transaction) THEN
19339       end , INVCONV **/
19340 
19341     EXCEPTION
19342       WHEN NO_DATA_FOUND THEN
19343          --RAISE ERROR
19344          l_progress := 'WMSINB-22070';
19345          RAISE fnd_api.g_exc_error;
19346     END;
19347 
19348     IF (l_debug = 1) THEN
19349       print_debug('VALIDATE_LOT_SERIAL_INFO: MTL_SYSTEM_ITEMS query done :'||l_progress, 1);
19350       print_debug('INVCONV, Removing OPM specific fork :'||l_progress,1);
19351       --Bug 4066234
19352       print_debug('VALIDATE_LOT_SERIAL_INFO: Lot Control Code:'||l_lot_control_code,1);
19353       print_debug('VALIDATE_LOT_SERIAL_INFO: Serial Number Control Code:'||l_serial_number_control_code,1);
19354       print_debug('VALIDATE_LOT_SERIAL_INFO: Lot Status Enabled:'||l_lot_status_enabled,1);
19355       l_progress := 'WMSINB-22076';
19356     END IF;
19357 
19358     -- if item is not lot controlled, then transaction should fail
19359     -- if the MTLT has been created for the transaction
19360     IF (l_lot_control_code = 1) THEN
19361       BEGIN
19362         SELECT '1'
19363          INTO l_dummy
19364          FROM dual
19365          WHERE exists (SELECT 1
19366            FROM mtl_transaction_lots_temp
19367            WHERE product_code = 'RCV'
19368            AND product_transaction_id = l_rti_id);
19369 
19370         --Fail transaction
19371         IF (l_debug = 1) THEN
19372           print_debug('VALIDATE_LOT_SERIAL_INFO: MTLT exists for non-lot item: '||l_progress, 1);
19373         END IF;
19374 
19375         l_progress := 'WMSINB-22080';
19376         RAISE fnd_api.g_exc_error;
19377       --Bug 13338489 Added the others in the exception block
19378       EXCEPTION
19379          WHEN no_data_found THEN
19380             NULL;
19381          WHEN others THEN
19382             NULL;
19383       END;
19384     END IF; --IF (l_lot_control_code = 1) THEN
19385 
19386     --Serial Tagging
19387     if(l_source_document_code='PO' and (l_transaction_type in ('RETURN TO RECEIVING','RETURN TO VENDOR')))
19388     THEN
19389       select transaction_type
19390       into l_parent_transaction_type
19391       from rcv_transactions
19392       where transaction_id=l_parent_transaction_id;
19393 
19394       if( l_parent_transaction_type='DELIVER') THEN
19395              inv_serial_number_pub.is_serial_controlled(
19396                     p_inventory_item_id     => l_item_id,
19397                     p_organization_id       => l_org_id,
19398                     p_transfer_org_id       => NULL,
19399                     p_txn_type_id           => 36,
19400                     p_txn_src_type_id       => 1,
19401                     p_txn_action_id         => 1,
19402                     p_serial_control        => l_serial_number_control_code,
19403                     p_xfer_serial_control   => NULL,
19404                     x_serial_control        => l_serial_tagged,
19405                     x_return_status         => l_return_status
19406                     );
19407 
19408           IF l_return_status <> 'S' THEN
19409              l_serial_tagged := 1;
19410           END IF;
19411       end if;
19412     end if;
19413      -- if item is not serial controlled, then transaction should fail
19414      -- if the MSNT has been created for the transaction
19415      -- Serial Tagging enhancement: Added condition to check l_serial_tagged
19416     IF (l_serial_number_control_code = 1 and l_serial_tagged <> 2) THEN
19417       BEGIN
19418          SELECT '1'
19419            INTO l_dummy
19420            FROM dual
19421            WHERE exists (SELECT 1
19422              FROM mtl_serial_numbers_temp
19423              WHERE product_code = 'RCV'
19424              AND product_transaction_id = l_rti_id);
19425 
19426          --Fail transaction
19427          IF (l_debug = 1) THEN
19428             print_debug('VALIDATE_LOT_SERIAL_INFO: MSNI exists for non-serial item: '||l_progress, 1);
19429          END IF;
19430 
19431          l_progress := 'WMSINB-22082';
19432          RAISE fnd_api.g_exc_error;
19433       --Bug 13338489 Added the others in the exception block
19434       EXCEPTION
19435          WHEN no_data_found THEN
19436             NULL;
19437          WHEN others THEN
19438             NULL;
19439 
19440       END;
19441     END IF; --IF (l_serial_number_control_code = 1) THEN
19442 
19443     -- FIRST VALIDATE FOR RECEIVE, ACCEPT, REJECT, TRANSFER AND DELIVER
19444     -- TRANSACTIONS
19445     IF (l_transaction_type IN ('RECEIVE','ACCEPT','REJECT','TRANSFER','DELIVER')) THEN
19446       -- CHECK TO SEE IF THE ITEM IS LOT CONTROLLED OR NOT
19447       -- opm change added l_opm_lot_ctl bug# 3061052
19448 
19449       /* INVCONV ,OPM specific separate check needs to be removed. Punit Kumar*/
19450       IF (L_LOT_CONTROL_CODE = 2 /*OR l_opm_lot_ctl = 1 */) THEN
19451       /* end INVCONV */
19452 
19453         IF (l_debug = 1) THEN
19454            print_debug('VALIDATE_LOT_SERIAL_INFO: Lot Controlled :'||l_progress, 1);
19455            l_progress := 'WMSINB-22087';
19456         END IF;
19457 
19458         L_NUM_MTLT_RECS := 0;
19459         l_tot_mtlt_prim_qty := 0;
19460         l_tot_mtlt_trans_qty := 0; -- Bug# 4225766
19461 
19462         OPEN C_MTLT(L_RTI_ID);
19463         LOOP
19464           FETCH C_MTLT INTO L_MTLT_REC;
19465           EXIT WHEN C_MTLT%NOTFOUND;
19466 
19467           /* INVCONV , get L_MTLT_REC values into l_mln_rec which shall be passed to INV_NEW_LOT
19468              for new lot creation */
19469 
19470           l_mln_rec.LOT_NUMBER                := L_MTLT_REC.LOT_NUMBER                    ;
19471           l_mln_rec.LAST_UPDATE_DATE          := SYSDATE                                  ;
19472           l_mln_rec.LAST_UPDATED_BY           := L_MTLT_REC.LAST_UPDATED_BY               ;
19473           l_mln_rec.CREATION_DATE             := SYSDATE                                  ;
19474           l_mln_rec.CREATED_BY                := L_MTLT_REC.CREATED_BY                    ;
19475           l_mln_rec.LAST_UPDATE_LOGIN         := L_MTLT_REC.LAST_UPDATE_LOGIN             ;
19476           l_mln_rec.EXPIRATION_DATE           := L_MTLT_REC.LOT_EXPIRATION_DATE           ;
19477           l_mln_rec.ATTRIBUTE_CATEGORY        := L_MTLT_REC.ATTRIBUTE_CATEGORY            ;
19478           l_mln_rec.ATTRIBUTE1                := L_MTLT_REC.ATTRIBUTE1                    ;
19479           l_mln_rec.ATTRIBUTE2                := L_MTLT_REC.ATTRIBUTE2                    ;
19480           l_mln_rec.ATTRIBUTE3                := L_MTLT_REC.ATTRIBUTE3                    ;
19481           l_mln_rec.ATTRIBUTE4                := L_MTLT_REC.ATTRIBUTE4                    ;
19482           l_mln_rec.ATTRIBUTE5                := L_MTLT_REC.ATTRIBUTE5                    ;
19483           l_mln_rec.ATTRIBUTE6                := L_MTLT_REC.ATTRIBUTE6                    ;
19484           l_mln_rec.ATTRIBUTE7                := L_MTLT_REC.ATTRIBUTE7                    ;
19485           l_mln_rec.ATTRIBUTE8                := L_MTLT_REC.ATTRIBUTE8                    ;
19486           l_mln_rec.ATTRIBUTE9                := L_MTLT_REC.ATTRIBUTE9                    ;
19487           l_mln_rec.ATTRIBUTE10               := L_MTLT_REC.ATTRIBUTE10                   ;
19488           l_mln_rec.ATTRIBUTE11               := L_MTLT_REC.ATTRIBUTE11                   ;
19489           l_mln_rec.ATTRIBUTE12               := L_MTLT_REC.ATTRIBUTE12                   ;
19490           l_mln_rec.ATTRIBUTE13               := L_MTLT_REC.ATTRIBUTE13                   ;
19491           l_mln_rec.ATTRIBUTE14               := L_MTLT_REC.ATTRIBUTE14                   ;
19492           l_mln_rec.ATTRIBUTE15               := L_MTLT_REC.ATTRIBUTE15                   ;
19493           l_mln_rec.REQUEST_ID                := L_MTLT_REC.REQUEST_ID                    ;
19494           l_mln_rec.PROGRAM_APPLICATION_ID    := L_MTLT_REC.PROGRAM_APPLICATION_ID        ;
19495           l_mln_rec.PROGRAM_ID                := L_MTLT_REC.PROGRAM_ID                    ;
19496           l_mln_rec.PROGRAM_UPDATE_DATE       := L_MTLT_REC.PROGRAM_UPDATE_DATE           ;
19497           l_mln_rec.DESCRIPTION               := L_MTLT_REC.DESCRIPTION                   ;
19498           l_mln_rec.VENDOR_NAME               := L_MTLT_REC.VENDOR_NAME                   ;
19499           l_mln_rec.SUPPLIER_LOT_NUMBER       := L_MTLT_REC.SUPPLIER_LOT_NUMBER           ;
19500           l_mln_rec.GRADE_CODE                := L_MTLT_REC.GRADE_CODE                    ;
19501           l_mln_rec.ORIGINATION_DATE          := L_MTLT_REC.ORIGINATION_DATE              ;
19502           l_mln_rec.DATE_CODE                 := L_MTLT_REC.DATE_CODE                     ;
19503           l_mln_rec.STATUS_ID                 := L_MTLT_REC.STATUS_ID                     ;
19504           l_mln_rec.CHANGE_DATE               := L_MTLT_REC.CHANGE_DATE                   ;
19505           l_mln_rec.AGE                       := L_MTLT_REC.AGE                           ;
19506           l_mln_rec.RETEST_DATE               := L_MTLT_REC.RETEST_DATE                   ;
19507           l_mln_rec.MATURITY_DATE             := L_MTLT_REC.MATURITY_DATE                 ;
19508           l_mln_rec.LOT_ATTRIBUTE_CATEGORY    := L_MTLT_REC.LOT_ATTRIBUTE_CATEGORY        ;
19509           l_mln_rec.ITEM_SIZE                 := L_MTLT_REC.ITEM_SIZE                     ;
19510           l_mln_rec.COLOR                     := L_MTLT_REC.COLOR                         ;
19511           l_mln_rec.VOLUME                    := L_MTLT_REC.VOLUME                        ;
19512           l_mln_rec.VOLUME_UOM                := L_MTLT_REC.VOLUME_UOM                    ;
19513           l_mln_rec.PLACE_OF_ORIGIN           := L_MTLT_REC.PLACE_OF_ORIGIN               ;
19514           l_mln_rec.BEST_BY_DATE              := L_MTLT_REC.BEST_BY_DATE                  ;
19515           l_mln_rec.LENGTH                    := L_MTLT_REC.LENGTH                        ;
19516           l_mln_rec.LENGTH_UOM                := L_MTLT_REC.LENGTH_UOM                    ;
19517           l_mln_rec.RECYCLED_CONTENT          := L_MTLT_REC.RECYCLED_CONTENT              ;
19518           l_mln_rec.THICKNESS                 := L_MTLT_REC.THICKNESS                     ;
19519           l_mln_rec.THICKNESS_UOM             := L_MTLT_REC.THICKNESS_UOM                 ;
19520           l_mln_rec.WIDTH                     := L_MTLT_REC.WIDTH                         ;
19521           l_mln_rec.WIDTH_UOM                 := L_MTLT_REC.WIDTH_UOM                     ;
19522           l_mln_rec.CURL_WRINKLE_FOLD         := L_MTLT_REC.CURL_WRINKLE_FOLD             ;
19523           l_mln_rec.C_ATTRIBUTE1              := L_MTLT_REC.C_ATTRIBUTE1                  ;
19524           l_mln_rec.C_ATTRIBUTE2              := L_MTLT_REC.C_ATTRIBUTE2                  ;
19525           l_mln_rec.C_ATTRIBUTE3              := L_MTLT_REC.C_ATTRIBUTE3                  ;
19526           l_mln_rec.C_ATTRIBUTE4              := L_MTLT_REC.C_ATTRIBUTE4                  ;
19527           l_mln_rec.C_ATTRIBUTE5              := L_MTLT_REC.C_ATTRIBUTE5                  ;
19528           l_mln_rec.C_ATTRIBUTE6              := L_MTLT_REC.C_ATTRIBUTE6                  ;
19529           l_mln_rec.C_ATTRIBUTE7              := L_MTLT_REC.C_ATTRIBUTE7                  ;
19530           l_mln_rec.C_ATTRIBUTE8              := L_MTLT_REC.C_ATTRIBUTE8                  ;
19531           l_mln_rec.C_ATTRIBUTE9              := L_MTLT_REC.C_ATTRIBUTE9                  ;
19532           l_mln_rec.C_ATTRIBUTE10             := L_MTLT_REC.C_ATTRIBUTE10                 ;
19533           l_mln_rec.C_ATTRIBUTE11             := L_MTLT_REC.C_ATTRIBUTE11                 ;
19534           l_mln_rec.C_ATTRIBUTE12             := L_MTLT_REC.C_ATTRIBUTE12                 ;
19535           l_mln_rec.C_ATTRIBUTE13             := L_MTLT_REC.C_ATTRIBUTE13                 ;
19536           l_mln_rec.C_ATTRIBUTE14             := L_MTLT_REC.C_ATTRIBUTE14                 ;
19537           l_mln_rec.C_ATTRIBUTE15             := L_MTLT_REC.C_ATTRIBUTE15                 ;
19538           l_mln_rec.C_ATTRIBUTE16             := L_MTLT_REC.C_ATTRIBUTE16                 ;
19539           l_mln_rec.C_ATTRIBUTE17             := L_MTLT_REC.C_ATTRIBUTE17                 ;
19540           l_mln_rec.C_ATTRIBUTE18             := L_MTLT_REC.C_ATTRIBUTE18                 ;
19541           l_mln_rec.C_ATTRIBUTE19             := L_MTLT_REC.C_ATTRIBUTE19                 ;
19542           l_mln_rec.C_ATTRIBUTE20             := L_MTLT_REC.C_ATTRIBUTE20                 ;
19543           l_mln_rec.D_ATTRIBUTE1              := L_MTLT_REC.D_ATTRIBUTE1                  ;
19544           l_mln_rec.D_ATTRIBUTE2              := L_MTLT_REC.D_ATTRIBUTE2                  ;
19545           l_mln_rec.D_ATTRIBUTE3              := L_MTLT_REC.D_ATTRIBUTE3                  ;
19546           l_mln_rec.D_ATTRIBUTE4              := L_MTLT_REC.D_ATTRIBUTE4                  ;
19547           l_mln_rec.D_ATTRIBUTE5              := L_MTLT_REC.D_ATTRIBUTE5                  ;
19548           l_mln_rec.D_ATTRIBUTE6              := L_MTLT_REC.D_ATTRIBUTE6                  ;
19549           l_mln_rec.D_ATTRIBUTE7              := L_MTLT_REC.D_ATTRIBUTE7                  ;
19550           l_mln_rec.D_ATTRIBUTE8              := L_MTLT_REC.D_ATTRIBUTE8                  ;
19551           l_mln_rec.D_ATTRIBUTE9              := L_MTLT_REC.D_ATTRIBUTE9                  ;
19552           l_mln_rec.D_ATTRIBUTE10             := L_MTLT_REC.D_ATTRIBUTE10                 ;
19553           l_mln_rec.N_ATTRIBUTE1              := L_MTLT_REC.N_ATTRIBUTE1                  ;
19554           l_mln_rec.N_ATTRIBUTE2              := L_MTLT_REC.N_ATTRIBUTE2                  ;
19555           l_mln_rec.N_ATTRIBUTE3              := L_MTLT_REC.N_ATTRIBUTE3                  ;
19556           l_mln_rec.N_ATTRIBUTE4              := L_MTLT_REC.N_ATTRIBUTE4                  ;
19557           l_mln_rec.N_ATTRIBUTE5              := L_MTLT_REC.N_ATTRIBUTE5                  ;
19558           l_mln_rec.N_ATTRIBUTE6              := L_MTLT_REC.N_ATTRIBUTE6                  ;
19559           l_mln_rec.N_ATTRIBUTE7              := L_MTLT_REC.N_ATTRIBUTE7                  ;
19560           l_mln_rec.N_ATTRIBUTE8              := L_MTLT_REC.N_ATTRIBUTE8                  ;
19561           l_mln_rec.N_ATTRIBUTE9              := L_MTLT_REC.N_ATTRIBUTE9                  ;
19562           l_mln_rec.N_ATTRIBUTE10             := L_MTLT_REC.N_ATTRIBUTE10                 ;
19563           l_mln_rec.VENDOR_ID                 := L_MTLT_REC.VENDOR_ID                     ;
19564           l_mln_rec.TERRITORY_CODE            := L_MTLT_REC.TERRITORY_CODE                ;
19565           l_mln_rec.PARENT_LOT_NUMBER         := L_MTLT_REC.PARENT_LOT_NUMBER             ;
19566           l_mln_rec.ORIGINATION_TYPE          := L_MTLT_REC.ORIGINATION_TYPE              ;
19567           l_mln_rec.EXPIRATION_ACTION_DATE    := L_MTLT_REC.EXPIRATION_ACTION_DATE        ;
19568           l_mln_rec.EXPIRATION_ACTION_CODE    := L_MTLT_REC.EXPIRATION_ACTION_CODE        ;
19569           l_mln_rec.HOLD_DATE                 := L_MTLT_REC.HOLD_DATE                     ;
19570 
19571           L_NUM_MTLT_RECS := L_NUM_MTLT_RECS + 1;
19572           l_tot_mtlt_prim_qty := l_tot_mtlt_prim_qty + l_mtlt_rec.primary_quantity;
19573           l_tot_mtlt_trans_qty := l_tot_mtlt_trans_qty + l_mtlt_rec.transaction_quantity; -- Bug# 4225766
19574 
19575           IF (l_debug = 1) THEN
19576             print_debug('VALIDATE_LOT_SERIAL_INFO: LOT NUMBER: '||l_mtlt_rec.lot_number||': '||l_progress, 1);
19577               /*
19578               print_debug('VALIDATE_LOT_SERIAL_INFO: SUBLOT NUMBER: '||l_mtlt_rec.sublot_num||': '||l_progress, 1);
19579               */
19580               print_debug('Assigning values fetched from MTLT to l_mln_rec'||l_progress,1);
19581             print_debug('VALIDATE_LOT_SERIAL_INFO: LOT PRIMARY QUANTITY: '||l_mtlt_rec.primary_quantity||': '||l_progress, 1);
19582             l_progress := 'WMSINB-22106';
19583           END IF;
19584            /*bug8429931
19585             after get record from MTLT,should validate
19586             the consistency between transaction_quantity and primary_quantity,
19587             since the transaction UOM not always equal with item primary UOM.*/
19588 
19589           --bug 9367595 uom_code is not always populated, instead unit_of_measure is getting inserted.
19590           --added logic convert the uom_code.
19591           if l_rti_uom_code is null then
19592             BEGIN
19593               SELECT uom_code
19594                 INTO l_rti_uom_code
19595                 FROM MTL_UNITS_OF_MEASURE_VL
19596                WHERE unit_of_measure = l_rti_UNIT_OF_MEASURE;
19597 
19598             EXCEPTION
19599                WHEN NO_DATA_FOUND THEN
19600                   print_debug('Unit of measure does not exist '||l_progress,1);
19601                   fnd_message.set_name('INV', 'INV_UOM_NOTFOUND');
19602                   fnd_message.set_token('UOM', l_rti_PRIMARY_UNIT_OF_MEASURE);
19603                   fnd_msg_pub.add;
19604                   RAISE fnd_api.g_exc_error;
19605             END;
19606           end if;
19607           --end9367595
19608 
19609           /*Bug#9570776 passing the lot number to the procedure, get_primary_qty to get the lot specific conversion */
19610           if(l_mtlt_rec.primary_quantity <> get_primary_qty(l_org_id,l_item_id,
19611                                                                 l_rti_uom_code,l_mtlt_rec.transaction_quantity,l_mtlt_rec.lot_number)) then
19612              fnd_message.set_name ('INV' , 'INV_INVALID_QUANTITY');
19613              fnd_msg_pub.ADD;
19614              RAISE fnd_api.g_exc_error;
19615            end if;
19616            /*INVCONV, Check whether Lot is existing or it's a new Lot .
19617              If it exists then we shall validate its parent lot also.
19618              Remove OPM fork.Add parent_lot_number in discrete query.Punit Kumar*/
19619 
19620             BEGIN
19621             /* IF (l_discrete_transaction) THEN		 */
19622 
19623                 SELECT 1,parent_lot_number
19624                   INTO L_LOT_EXISTS ,l_parent_lot_number
19625                   FROM MTL_LOT_NUMBERS
19626                   WHERE ORGANIZATION_ID = L_ORG_ID
19627                   AND   INVENTORY_ITEM_ID = L_ITEM_ID
19628                   AND LOT_NUMBER = Ltrim(Rtrim(L_MTLT_REC.lot_number));
19629 
19630              /* ELSE -- opm change bug# 3061052 --IF (l_discrete_transaction) THEN
19631                 IF  Ltrim(Rtrim(L_MTLT_REC.sublot_num)) IS NOT NULL THEN
19632                    SELECT 1, LOT_ID
19633                INTO L_LOT_EXISTS , l_opm_lot_id
19634                FROM IC_LOTS_MST
19635                WHERE ITEM_ID = l_opm_item_id
19636                AND LOT_NO = Ltrim(Rtrim(L_MTLT_REC.lot_number))
19637                AND SUBLOT_NO = Ltrim(Rtrim(L_MTLT_REC.sublot_num)) ;
19638                  ELSE
19639                    SELECT 1 , LOT_ID
19640                INTO L_LOT_EXISTS , l_opm_lot_id
19641                FROM IC_LOTS_MST
19642                WHERE ITEM_ID = l_opm_item_id
19643                AND LOT_NO = Ltrim(Rtrim(L_MTLT_REC.lot_number))
19644                AND SUBLOT_NO IS NULL ;
19645                 END IF;
19646               END IF; --IF (l_discrete_transaction) THEN
19647 
19648               end , INVCONV */
19649 
19650             EXCEPTION
19651                WHEN NO_DATA_FOUND THEN
19652                   L_LOT_EXISTS := 0;
19653             END;
19654 
19655             IF (l_debug = 1) THEN
19656               print_debug('VALIDATE_LOT_SERIAL_INFO: LOT EXISTS: '||l_lot_exists||' : '||l_progress, 1);
19657               l_progress := 'WMSINB-22143';
19658               print_debug('INVCONV, Removing OPM specific fork and selecting parent lot number :'||l_progress||':'||l_parent_lot_number,1);
19659             END IF;
19660 
19661             IF L_LOT_EXISTS = 1 THEN
19662 
19663               /*INVCONV , validating for parent lot, Punit Kumar */
19664               IF  L_MTLT_REC.parent_lot_number IS NOT NULL THEN
19665                 IF L_MTLT_REC.parent_lot_number <> l_parent_lot_number THEN
19666                   fnd_message.set_name ('INV' , 'INV_CL_PARENT_INVALID' );
19667                   fnd_msg_pub.ADD;
19668                   l_progress := 'WMSINB-22145';
19669                   RAISE fnd_api.g_exc_error;
19670                 END IF;
19671               ELSE
19672                 L_MTLT_REC.parent_lot_number := l_parent_lot_number;
19673               END IF;
19674 
19675               IF (L_TRANSACTION_TYPE <> 'RECEIVE') THEN
19676                 L_LOT_ENTERED_ON_PARENT := LOT_ENTERED_ON_PARENT(L_PARENT_TRANSACTION_ID);
19677               ELSE
19678                 L_LOT_ENTERED_ON_PARENT := FALSE;
19679               END IF;
19680 
19681               IF (l_debug = 1) THEN
19682                   print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||L_SOURCE_DOCUMENT_CODE||' : '||l_progress, 1);
19683                   print_debug('INVCONV, validating for parent lot :'||l_progress,1);
19684                   l_progress := 'WMSINB-22155';
19685               END IF;
19686 
19687               IF NOT L_LOT_ENTERED_ON_PARENT THEN
19688                   --Validate the lot number and primary quantity for the source org.
19689                 IF (l_debug = 1) THEN
19690                    print_debug('VALIDATE_LOT_SERIAL_INFO: LOT NOT ENTERED ON PARENT: '||l_progress, 1);
19691                    l_progress := 'WMSINB-22161';
19692                 END IF;
19693 
19694                 /* INVCONV , Existing discrete validations. Same will be executed for process org also. Punit Kumar */
19695                 /*IF (l_discrete_transaction) THEN */
19696                 /* end ,INVCONV */
19697 
19698                 IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY', 'REQ')) THEN
19699                 -- GET THE LOT/SERIAL CONTROL IN SOURCE ORG
19700                   GET_SERIAL_LOT_CTRL_IN_SRC_ORG
19701                     (L_SHIPMENT_LINE_ID, L_ORG_ID,
19702                      L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL, l_from_org_rev_ctrl,
19703                      X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
19704 
19705                   IF (l_debug = 1) THEN
19706                      print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CONTROL FROM ORG: '||L_FROM_ORG_LOT_CTRL||' : '||l_progress, 1);
19707                      l_progress := 'WMSINB-22175';
19708                   END IF;
19709 
19710                   IF (L_FROM_ORG_LOT_CTRL = 2) THEN
19711                     BEGIN
19712                       /** Bug:5489462
19713                        *      If a lot number doesn't belong to that shipment line is entered through ROI,
19714                        *      L_RLS_PRIMARY_QUANTITY will be loaded with null value and the 'if' condition
19715                        *      to check the quanity entered in mtlt record exceeds the supply quantity won't
19716                        *      raise the exception, as the comparision is made against a null value.
19717                        *      So, added nvl for the SUM(rls.primary_quantity).
19718                        */
19719                           SELECT nvl(SUM(rls.primary_quantity),0)--Bug:5489462
19720                             INTO L_RLS_PRIMARY_QUANTITY
19721                             FROM rcv_lots_supply rls
19722                             , rcv_shipment_lines rsl
19723                             WHERE rsl.SHIPMENT_LINE_ID = rls.SHIPMENT_LINE_ID
19724                             AND rsl.shipment_header_id = l_shipment_header_id
19725                             --Bug 12348470 Reverted the fix 94466813
19726                             --AND rls.SHIPMENT_LINE_ID = L_SHIPMENT_LINE_ID  --9466813
19727                             AND rsl.item_id = l_item_id
19728                             AND rls.SUPPLY_TYPE_CODE = 'SHIPMENT'
19729                             AND rls.LOT_NUM = Ltrim(Rtrim(L_MTLT_REC.lot_number));
19730 
19731 			   IF ((abs(l_mtlt_rec.primary_quantity - l_rls_primary_quantity) > 0.00005 )
19732 				AND  (l_mtlt_rec.primary_quantity > l_rls_primary_quantity)) THEN  --Bug: 14092221
19733                              --RAISE ERROR
19734                              l_progress := 'WMSINB-22192';
19735                              RAISE fnd_api.g_exc_error;
19736                           END IF;
19737                     EXCEPTION
19738                       WHEN NO_DATA_FOUND THEN
19739                          --RAISE ERROR
19740                          l_progress := 'WMSINB-22198';
19741                          RAISE fnd_api.g_exc_error;
19742                     END;
19743                   END IF; --IF (L_FROM_ORG_LOT_CTRL = 2) THEN
19744 
19745                 END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY', 'REQ')) THEN
19746 
19747                 -- PERFORM MATERIAL_STATUS CHECK
19748                 -- if deliver or direct receipt
19749                 IF (l_transaction_type = 'DELIVER' OR l_auto_transact_code = 'DELIVER') THEN
19750                   IF (l_source_document_code = 'PO') THEN
19751                     l_transaction_type_id := 18;
19752                   ELSIF (l_source_document_code = 'RMA') THEN
19753                     l_transaction_type_id := 15;
19754                   ELSE
19755                     l_transaction_type_id := 61;
19756                   END IF;
19757 
19758                   /*INVCONV, adding a debug message , Punit Kumar*/
19759 
19760                   IF (l_debug = 1) THEN
19761                      print_debug('transaction type id in validate_lot_serial_info is : '||l_transaction_type_id||' : '||l_progress, 1);
19762                   END IF;
19763 
19764                   /* Material Status Enhancement - Tracking bug: 13519864 */
19765 
19766 		  IF (L_MTLT_REC.status_id IS NOT NULL AND l_allow_status_entry = 'Y') THEN
19767 
19768                         if inv_cache.set_org_rec(l_org_id) then
19769                            l_default_status_id :=  inv_cache.org_rec.default_status_id;
19770                         end if;
19771 
19772                         IF (l_default_status_id is not null and l_serial_number_control_code NOT IN (2,5)) THEN  /* Bug 13725126 */
19773 
19774                            BEGIN
19775 
19776 			   SELECT '1'
19777                            INTO l_dummy
19778                            FROM dual
19779                            WHERE EXISTS (SELECT 'comingling exists'
19780                                          from mtl_onhand_quantities_detail moqd,
19781                                               rcv_transactions_interface rti
19782                   	      	       WHERE moqd.organization_id = rti.to_organization_id
19783                   	      	       AND moqd.inventory_item_id = rti.item_id
19784                   	      	       and moqd.subinventory_code = rti.subinventory
19785                   	      	       and nvl(moqd.locator_id, -9999) = nvl(rti.locator_id, -9999)
19786                   	      	       and nvl(moqd.lot_number, '@@@@') = nvl(L_MTLT_REC.lot_number, '@@@@')
19787                   	      	       and nvl(moqd.lpn_id, -9999) = nvl(rti.lpn_id, -9999)
19788                   	      	       and nvl(moqd.status_id, -9999) <> nvl(L_MTLT_REC.status_id, -9999)
19789 				       and rti.interface_transaction_id = L_RTI_ID
19790                   	      	       );
19791 
19792                                   l_progress := 'WMSINB-22200';
19793 
19794                                   --Fail transaction
19795                                   IF (l_debug = 1) THEN
19796                                     print_debug('VALIDATE_LOT_SERIAL_INFO: User entered status causes commingling in SKU: '||l_progress, 1);
19797                                   END IF;
19798 
19799                                   fnd_message.set_name ('INV' , 'INV_STATUS_COMINGLING');
19800                                   fnd_msg_pub.ADD;
19801                                   RAISE fnd_api.g_exc_error;
19802 
19803 			   EXCEPTION
19804 
19805                   	   WHEN no_data_found THEN
19806                   	     NULL;
19807                            END;
19808 
19809 		        end if;
19810                   END IF;
19811 
19812                   INV_LOT_TRX_VALIDATION_PUB.VALIDATE_MATERIAL_STATUS(X_RETURN_STATUS => X_RETURN_STATUS,
19813                                   X_MSG_COUNT => X_MSG_COUNT,
19814                                   X_MSG_DATA => X_MSG_DATA,
19815                                   X_VALIDATION_STATUS => L_VALIDATION_STATUS,
19816                                   P_TRANSACTION_TYPE_ID => l_transaction_type_id,
19817                                   P_ORGANIZATION_ID => L_ORG_ID,
19818                                   P_INVENTORY_ITEM_ID => L_ITEM_ID,
19819                                   P_LOT_NUMBER => L_MTLT_REC.LOT_NUMBER,
19820                                   P_SUBINVENTORY_CODE => L_SUB_CODE,
19821                                   P_LOCATOR_ID => L_LOC_ID,
19822                                   P_STATUS_ID => NULL);
19823                   IF X_RETURN_STATUS <> 'S' THEN
19824                      --RAISE ERROR
19825                      l_progress := 'WMSINB-22225';
19826                      RAISE fnd_api.g_exc_error;
19827                   END IF;
19828 
19829                   IF (l_debug = 1) THEN
19830                      print_debug('VALIDATE_LOT_SERIAL_INFO: LOT MATERIAL VALIDATION STATUS: '||L_VALIDATION_STATUS||' : '||l_progress, 1);
19831                      l_progress := 'WMSINB-22231';
19832                   END IF;
19833 
19834                   IF L_VALIDATION_STATUS <> 'Y' THEN
19835                      --RAISE ERROR
19836                      l_progress := 'WMSINB-22236';
19837                      RAISE fnd_api.g_exc_error;
19838                   END IF;
19839                 END IF; --IF (l_transaction_type = 'DELIVER' OR l_auto_transact_code = 'DELIVER') THEN
19840 
19841                      /*INVCONV , Instead of calling OPM specific API gml_opm_roi_grp.validate_opm_lot,
19842                         we shall now call a new procedure INV_ROI_INTEGRATION_GRP. INV_VALIDATE_LOT.
19843                         This new procedure shall  validate the extra process attributes
19844                         that are being merged for discrete items too.
19845                         Punit Kumar */
19846                      /*
19847                  ELSE --IF (l_discrete_transaction) THEN
19848                 -- opm change bug# 3061052
19849                 gml_opm_roi_grp.validate_opm_lot(p_api_version	 	=> 1.0,
19850                          p_init_msg_lst	 	=> FND_API.G_FALSE,
19851                          p_mtlt_rowid		=> l_mtlt_rec.rowid,
19852                          p_new_lot	 	=> 'N',
19853                          p_opm_item_id		=> l_opm_item_id,
19854                          p_item_no		=> l_item_no,
19855                          p_lots_specified_on_parent => 'N',
19856                          p_lot_id		=> l_opm_lot_id,
19857                          x_return_status 	=> x_return_status,
19858                          x_msg_data      	=> x_msg_data,
19859                          x_msg_count     	=> x_msg_count
19860                          );
19861                     */
19862 
19863                  IF (l_debug = 1) THEN
19864                     print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
19865                     print_debug('transaction type id before calling in validate_lot_serial_info is : '||l_transaction_type_id||' : '||l_progress, 1);
19866                  END IF;
19867 
19868 
19869 
19870 
19871                 INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
19872                                                        x_return_status      		   => x_return_status
19873                                                       ,x_msg_data           		   => x_msg_data
19874                                                       ,x_msg_count          		   => x_msg_count
19875                                                       ,p_api_version	               => 1.0
19876                                                       ,p_init_msg_lst	            => FND_API.G_FALSE
19877                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
19878                                                       ,p_transaction_type_id 	      => l_transaction_type_id
19879                                                       ,p_new_lot			            => 'N'
19880                                                       ,p_item_id	 		            => l_item_id
19881                                                       ,p_to_organization_id		   => L_ORG_ID
19882                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
19883                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
19884                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
19885                                                       ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
19886                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
19887                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
19888                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
19889                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
19890                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
19891                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
19892                                                       ,p_rti_id	                  => L_RTI_ID
19893                                                       ,p_revision             	   => l_item_revision
19894                                                       ,p_subinventory_code  	      => L_SUB_CODE
19895                                                       ,p_locator_id           	   => l_loc_id
19896                                                       ,p_transaction_type           => l_transaction_type
19897                                                       ,p_parent_txn_type            => l_parent_txn_type
19898                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
19899                                                       );
19900                 IF (l_debug = 1) THEN
19901                    print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
19902                 END IF;
19903                 /* end , INVCONV */
19904 
19905                 IF X_RETURN_STATUS <> 'S' THEN
19906                    --RAISE ERROR
19907                    l_progress := 'WMSINB-22256';
19908                    RAISE fnd_api.g_exc_error;
19909                 END IF;
19910 
19911                 /*INVCONV , Changed the debug message*/
19912                 IF (l_debug = 1) THEN
19913                    /*print_debug('VALIDATE_LOT_SERIAL_INFO: VALIDATE_OPM_LOT STATUS: '||x_return_status||' : '||l_progress, 1);*/
19914                    print_debug('INVCONV, VALIDATE_LOT_SERIAL_INFO: VALIDATE_LOT STATUS,x_return_status is : '||x_return_status||' : '||l_progress, 1);
19915                    l_progress := 'WMSINB-22262';
19916                 END IF;
19917 
19918                 /* END IF; -- IF (l_discrete_transaction) THEN */
19919                /*end , INVCONV*/
19920 
19921               ELSE --IF NOT L_LOT_ENTERED_ON_PARENT THEN
19922 		   -- LOT WAS ENTERERED ON THE PARENT SO USER CANNOT ENTER
19923 		   -- ANY OTHER LOT HERE
19924 		   /* bug 10206337 */
19925 		   IF (l_transaction_type = 'DELIVER' OR l_auto_transact_code = 'DELIVER') THEN
19926 		      IF (l_source_document_code = 'PO') THEN
19927 			 l_transaction_type_id := 18;
19928 		       ELSIF (l_source_document_code = 'RMA') THEN
19929 			 l_transaction_type_id := 15;
19930 		       ELSE
19931 			 l_transaction_type_id := 61;
19932 		      END IF;
19933 		   END IF;
19934                  BEGIN
19935 		   /* bug 10206337 */
19936                   -- INVCONV , Remove sublot_num. Punit Kumar
19937 
19938                   SELECT Sum(primary_quantity)   -- Bug 14117094
19939                     INTO l_rls_primary_quantity
19940                     FROM rcv_lots_supply
19941                     WHERE transaction_id = l_parent_transaction_id
19942                     AND lot_num = Ltrim(Rtrim(l_mtlt_rec.lot_number)) ;
19943                      /*
19944                     AND ((sublot_num IS NULL and Ltrim(Rtrim(l_mtlt_rec.sublot_num)) IS NULL)
19945                    OR (sublot_num = Ltrim(Rtrim(l_mtlt_rec.sublot_num)))) ;
19946                   */
19947 				IF (l_debug = 1) THEN
19948                    print_debug('AMO debug msgs, The value of l_mtlt_rec.primary_quantity'||l_mtlt_rec.primary_quantity||' : '||l_progress, 1);
19949 				   print_debug('AMO debug msgs, The value of l_rls_primary_quantity'||l_rls_primary_quantity||' : '||l_progress, 1);
19950                 END IF;
19951 
19952                     IF ((abs(l_mtlt_rec.primary_quantity - l_rls_primary_quantity) > 0.00005 ) AND  (l_mtlt_rec.primary_quantity > l_rls_primary_quantity)) THEN   --bug#10067944
19953                        --raise error
19954                        l_progress := 'WMSINB-22284';
19955                        RAISE fnd_api.g_exc_error;
19956                     END IF;
19957                 EXCEPTION
19958                   WHEN no_data_found THEN
19959                      --raise error
19960                      l_progress := 'WMSINB-22290';
19961                      RAISE fnd_api.g_exc_error;
19962                 END;
19963 
19964                  /*INVCONV , Removing the process specific call. Shall call a new procedure INV_VALIDATE_LOT
19965                    in Package INV_ROI_INTEGRATION_GRP to perform the same set of validations for all.
19966                    Punit Kumar*/
19967                  /*
19968                -- opm change bug# 3061052
19969                IF (NOT l_discrete_transaction) THEN
19970                   gml_opm_roi_grp.validate_opm_lot(p_api_version	 	=> 1.0,
19971                      p_init_msg_lst	 	=> FND_API.G_FALSE,
19972                      p_mtlt_rowid		=> l_mtlt_rec.rowid,
19973                      p_new_lot	 	=> 'N',
19974                      p_opm_item_id		=> l_opm_item_id,
19975                      p_item_no		=> l_item_no,
19976                      p_lots_specified_on_parent => 'Y',
19977                      p_lot_id		=> l_opm_lot_id,
19978                      x_return_status 	=> x_return_status,
19979                      x_msg_data      	=> x_msg_data,
19980                      x_msg_count     	=> x_msg_count
19981                      );
19982                 */
19983                 IF (l_debug = 1) THEN
19984                   print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
19985                 END IF;
19986 
19987                 INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
19988                                                        x_return_status      		   => x_return_status
19989                                                       ,x_msg_data           		   => x_msg_data
19990                                                       ,x_msg_count          		   => x_msg_count
19991                                                       ,p_api_version	               => 1.0
19992                                                       ,p_init_msg_lst	            => FND_API.G_FALSE
19993                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
19994                                                       ,p_transaction_type_id 	      => l_transaction_type_id
19995                                                       ,p_new_lot			            => 'N'
19996                                                       ,p_item_id	 		            => l_item_id
19997                                                       ,p_to_organization_id		   => L_ORG_ID
19998                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
19999                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
20000                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
20001                                                       ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
20002                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
20003                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
20004                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
20005                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
20006                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
20007                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
20008                                                       ,p_rti_id	                  => L_RTI_ID
20009                                                       ,p_revision             	   => l_item_revision
20010                                                       ,p_subinventory_code  	      => L_SUB_CODE
20011                                                       ,p_locator_id           	   => l_loc_id
20012                                                       ,p_transaction_type           => l_transaction_type
20013                                                       ,p_parent_txn_type            => l_parent_txn_type
20014                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
20015                                                       );
20016 
20017                 IF (l_debug = 1) THEN
20018                   print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
20019                 END IF;
20020 
20021                 IF X_RETURN_STATUS <> 'S' THEN
20022                    --RAISE ERROR
20023                    l_progress := 'WMSINB-22310';
20024                    RAISE fnd_api.g_exc_error;
20025                 END IF;
20026 
20027                 /*INVCONV , Changed the debug message*/
20028                 IF (l_debug = 1) THEN
20029                    /*print_debug('VALIDATE_LOT_SERIAL_INFO: VALIDATE_OPM_LOT STATUS: '||x_return_status||' : '||l_progress, 1);*/
20030                    print_debug('VALIDATE_LOT_SERIAL_INFO: VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
20031                 END IF;
20032                /*END IF;--IF (NOT l_discrete_transaction) THEN */
20033 
20034               END IF; --IF NOT L_LOT_ENTERED_ON_PARENT THEN
20035             ELSE --IF L_LOT_EXISTS = 1 THEN
20036               -- MAKE SURE THE LOT WAS NOT ENTERED ON THE PARENT TXN
20037               -- IF LOT WAS ENTERED ON THE PARENT TRANSACTION THEN
20038               -- FAIL THE TRANSACTION
20039               IF (L_TRANSACTION_TYPE <> 'RECEIVE') THEN
20040                  L_LOT_ENTERED_ON_PARENT := LOT_ENTERED_ON_PARENT(L_PARENT_TRANSACTION_ID);
20041               ELSE
20042                  L_LOT_ENTERED_ON_PARENT := FALSE;
20043               END IF;
20044 
20045               IF (l_debug = 1) THEN
20046                  print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||L_SOURCE_DOCUMENT_CODE||' : '||l_progress, 1);
20047                  l_progress := 'WMSINB-22332';
20048               END IF;
20049 
20050               IF NOT l_lot_entered_on_parent THEN
20051                 IF (l_debug = 1) THEN
20052                    print_debug('VALIDATE_LOT_SERIAL_INFO: LOT NOT ENTERED ON PARENT: '||l_progress, 1);
20053                    l_progress := 'WMSINB-22338';
20054                 END IF;
20055 
20056                 -- opm change bug# 3061052
20057                    /*INVCONV , existing discrete validations. Same will be executed for process org,Punit Kumar*/
20058 
20059                    --IF (l_discrete_transaction) THEN
20060 
20061                 IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY', 'REQ')) THEN
20062                   -- GET THE LOT/SERIAL CONTROL IN SOURCE ORG
20063                   GET_SERIAL_LOT_CTRL_IN_SRC_ORG
20064                     (L_SHIPMENT_LINE_ID, L_ORG_ID,
20065                      L_FROM_ORG_SER_CRTL,
20066                      L_FROM_ORG_LOT_CTRL, l_from_org_rev_ctrl,
20067                      X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
20068 
20069                   IF (l_debug = 1) THEN
20070                      print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CONTROL FROM ORG: '||L_FROM_ORG_LOT_CTRL||' : '||l_progress, 1);
20071                      l_progress := 'WMSINB-22352';
20072                   END IF;
20073 
20074                   IF (L_FROM_ORG_LOT_CTRL = 2) THEN
20075                     BEGIN
20076                       SELECT nvl(SUM(rls.primary_quantity),0) --Bug:5489462
20077                       INTO L_RLS_PRIMARY_QUANTITY
20078                       FROM rcv_lots_supply rls
20079                       , rcv_shipment_lines rsl
20080                       WHERE rls.SHIPMENT_LINE_ID = rsl.SHIPMENT_LINE_ID
20081                       AND rsl.shipment_header_id = l_shipment_header_id
20082                       AND rsl.item_id = l_item_id
20083                       AND rls.SUPPLY_TYPE_CODE = 'SHIPMENT'
20084                       AND rls.LOT_NUM = Ltrim(Rtrim(L_MTLT_REC.lot_number));
20085 
20086                       IF ((abs(l_mtlt_rec.primary_quantity - l_rls_primary_quantity) > 0.00005 )
20087 				AND  (l_mtlt_rec.primary_quantity > l_rls_primary_quantity)) THEN  --Bug: 14092221
20088                         --RAISE ERROR
20089                         l_progress :=     'WMSINB-22367';
20090                         RAISE fnd_api.g_exc_error;
20091                       END IF;
20092                     EXCEPTION
20093                       WHEN NO_DATA_FOUND THEN
20094                        --RAISE ERROR
20095                        l_progress :=     'WMSINB-22373';
20096                        RAISE fnd_api.g_exc_error;
20097                     END;
20098                   END IF; --IF (L_FROM_ORG_LOT_CTRL = 2) THEN
20099                 END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY', 'REQ')) THEN
20100                  -- PERFORM NEW LOT VALIDATIONS
20101                  -- CREATE LOT
20102                  -- CALL INV_LOT_API_PUB.CREATE_INV_LOT
20103 
20104                   /*
20105                  l_c_attributes_tbl(1)  := l_mtlt_rec.c_attribute1;
20106                  l_c_attributes_tbl(2)  := l_mtlt_rec.c_attribute2;
20107                  l_c_attributes_tbl(3)  := l_mtlt_rec.c_attribute3;
20108                  l_c_attributes_tbl(4)  := l_mtlt_rec.c_attribute4;
20109                  l_c_attributes_tbl(5)  := l_mtlt_rec.c_attribute5;
20110                  l_c_attributes_tbl(6)  := l_mtlt_rec.c_attribute6;
20111                  l_c_attributes_tbl(7)  := l_mtlt_rec.c_attribute7;
20112                  l_c_attributes_tbl(8)  := l_mtlt_rec.c_attribute8;
20113                  l_c_attributes_tbl(9)  := l_mtlt_rec.c_attribute9;
20114                  l_c_attributes_tbl(10) := l_mtlt_rec.c_attribute10;
20115                  l_c_attributes_tbl(11) := l_mtlt_rec.c_attribute11;
20116                  l_c_attributes_tbl(12) := l_mtlt_rec.c_attribute12;
20117                  l_c_attributes_tbl(13) := l_mtlt_rec.c_attribute13;
20118                  l_c_attributes_tbl(14) := l_mtlt_rec.c_attribute14;
20119                  l_c_attributes_tbl(15) := l_mtlt_rec.c_attribute15;
20120                  l_c_attributes_tbl(16) := l_mtlt_rec.c_attribute16;
20121                  l_c_attributes_tbl(17) := l_mtlt_rec.c_attribute17;
20122                  l_c_attributes_tbl(18) := l_mtlt_rec.c_attribute18;
20123                  l_c_attributes_tbl(19) := l_mtlt_rec.c_attribute19;
20124                  l_c_attributes_tbl(20) := l_mtlt_rec.c_attribute20;
20125                  l_d_attributes_tbl(1)  := l_mtlt_rec.d_attribute1;
20126                  l_d_attributes_tbl(2)  := l_mtlt_rec.d_attribute2;
20127                  l_d_attributes_tbl(3)  := l_mtlt_rec.d_attribute3;
20128                  l_d_attributes_tbl(4)  := l_mtlt_rec.d_attribute4;
20129                  l_d_attributes_tbl(5)  := l_mtlt_rec.d_attribute5;
20130                  l_d_attributes_tbl(6)  := l_mtlt_rec.d_attribute6;
20131                  l_d_attributes_tbl(7)  := l_mtlt_rec.d_attribute7;
20132                  l_d_attributes_tbl(8)  := l_mtlt_rec.d_attribute8;
20133                  l_d_attributes_tbl(9)  := l_mtlt_rec.d_attribute9;
20134                  l_d_attributes_tbl(10) := l_mtlt_rec.d_attribute10;
20135                  l_n_attributes_tbl(1)  := l_mtlt_rec.n_attribute1;
20136                  l_n_attributes_tbl(2)  := l_mtlt_rec.n_attribute2;
20137                  l_n_attributes_tbl(3)  := l_mtlt_rec.n_attribute3;
20138                  l_n_attributes_tbl(4)  := l_mtlt_rec.n_attribute4;
20139                  l_n_attributes_tbl(5)  := l_mtlt_rec.n_attribute5;
20140                  l_n_attributes_tbl(6)  := l_mtlt_rec.n_attribute6;
20141                  l_n_attributes_tbl(7)  := l_mtlt_rec.n_attribute7;
20142                  l_n_attributes_tbl(8)  := l_mtlt_rec.n_attribute8;
20143                  l_n_attributes_tbl(9)  := l_mtlt_rec.n_attribute9;
20144                  l_n_attributes_tbl(10) := l_mtlt_rec.n_attribute10;
20145 
20146                  --Bug #3187688
20147                  --Populate the INV attributes table and pass the attribute cateogry
20148                  l_inv_attributes_tbl(1)  := l_mtlt_rec.attribute1;
20149                  l_inv_attributes_tbl(2)  := l_mtlt_rec.attribute2;
20150                  l_inv_attributes_tbl(3)  := l_mtlt_rec.attribute3;
20151                  l_inv_attributes_tbl(4)  := l_mtlt_rec.attribute4;
20152                  l_inv_attributes_tbl(5)  := l_mtlt_rec.attribute5;
20153                  l_inv_attributes_tbl(6)  := l_mtlt_rec.attribute6;
20154                  l_inv_attributes_tbl(7)  := l_mtlt_rec.attribute7;
20155                  l_inv_attributes_tbl(8)  := l_mtlt_rec.attribute8;
20156                  l_inv_attributes_tbl(9)  := l_mtlt_rec.attribute9;
20157                  l_inv_attributes_tbl(10) := l_mtlt_rec.attribute10;
20158                  l_inv_attributes_tbl(11) := l_mtlt_rec.attribute11;
20159                  l_inv_attributes_tbl(12) := l_mtlt_rec.attribute12;
20160                  l_inv_attributes_tbl(13) := l_mtlt_rec.attribute13;
20161                  l_inv_attributes_tbl(14) := l_mtlt_rec.attribute14;
20162                  l_inv_attributes_tbl(15) := l_mtlt_rec.attribute15;
20163 
20164                  inv_lot_api_pub.create_inv_lot(x_return_status => x_return_status
20165                         , x_msg_count => x_msg_count
20166                         , x_msg_data => x_msg_data
20167                         , p_inventory_item_id => l_item_id
20168                         , p_organization_id => l_org_id
20169                         , p_lot_number => l_mtlt_rec.lot_number
20170                         , p_expiration_date => l_mtlt_rec.lot_expiration_date
20171                         , p_disable_flag => NULL
20172                         , p_attribute_category => l_mtlt_rec.attribute_category
20173                         , p_lot_attribute_category => l_mtlt_rec.lot_attribute_category
20174                         , p_attributes_tbl => l_inv_attributes_tbl
20175                         , p_c_attributes_tbl => l_c_attributes_tbl
20176                         , p_n_attributes_tbl => l_n_attributes_tbl
20177                         , p_d_attributes_tbl => l_d_attributes_tbl
20178                         , p_grade_code => l_mtlt_rec.grade_code
20179                         , p_origination_date => l_mtlt_rec.origination_date
20180                         , p_date_code => l_mtlt_rec.date_code
20181                         , p_status_id => l_mtlt_rec.status_id
20182                         , p_change_date => l_mtlt_rec.change_date
20183                         , p_age => l_mtlt_rec.age
20184                         , p_retest_date => l_mtlt_rec.retest_date
20185                        , p_maturity_date => l_mtlt_rec.maturity_date
20186                        , p_item_size => l_mtlt_rec.item_size
20187                        , p_color => l_mtlt_rec.color
20188                        , p_volume => l_mtlt_rec.volume
20189                        , p_volume_uom => l_mtlt_rec.volume_uom
20190                        , p_place_of_origin => l_mtlt_rec.place_of_origin
20191                        , p_best_by_date => l_mtlt_rec.best_by_date
20192                        , p_length => l_mtlt_rec.Length
20193                        , p_length_uom => l_mtlt_rec.length_uom
20194                        , p_recycled_content => l_mtlt_rec.recycled_content
20195                        , p_thickness => l_mtlt_rec.thickness
20196                        , p_thickness_uom => l_mtlt_rec.thickness_uom
20197                        , p_width => l_mtlt_rec.width
20198                        , p_width_uom => l_mtlt_rec.width_uom
20199                        , p_territory_code => l_mtlt_rec.territory_code
20200                        , p_supplier_lot_number => l_mtlt_rec.supplier_lot_number
20201                        , p_vendor_name => l_mtlt_rec.vendor_name
20202                        , p_source => inv_lot_api_pub.inv);
20203 
20204                 IF (x_return_status <> 'S') THEN
20205                   --raise error
20206                     l_progress :=     'WMSINB-22469';
20207                     RAISE fnd_api.g_exc_error;
20208                 END IF;
20209 
20210                 IF (l_debug = 1) THEN
20211                   print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CREATED: '||l_progress, 1);
20212                   l_progress := 'WMSINB-22475';
20213                 END IF;
20214               ELSE --IF (l_discrete_transaction) THEN
20215                   -- opm change bug# 3061052
20216                 gml_opm_roi_grp.validate_opm_lot(p_api_version	=> 1.0,
20217                          p_init_msg_lst	 	=> FND_API.G_FALSE,
20218                          p_mtlt_rowid		=> l_mtlt_rec.rowid,
20219                          p_new_lot	 	=> 'Y',
20220                          p_opm_item_id		=> l_opm_item_id,
20221                          p_item_no		=> l_item_no,
20222                          p_lots_specified_on_parent => 'N',
20223                          p_lot_id		=> l_opm_lot_id,
20224                          x_return_status 	=> x_return_status,
20225                          x_msg_data      	=> x_msg_data,
20226                          x_msg_count     	=> x_msg_count
20227                          );
20228                     IF X_RETURN_STATUS <> 'S' THEN
20229                    --RAISE ERROR
20230                    l_progress := 'WMSINB-22493';
20231                    RAISE fnd_api.g_exc_error;
20232                     END IF;
20233 
20234                     IF (l_debug = 1) THEN
20235                    print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CREATED: '||x_return_status||' : '||l_progress, 1);
20236                     END IF;
20237               END IF; --IF (l_discrete_transaction) THEN
20238               */
20239 
20240              /*INVCONV , Perform lot validations and create the new lot.
20241                  Call Lot Create API INV_ROI_INTEGRATION_GRP.INV_NEW_LOT to create the new lot.
20242                  This shall also create lot specific conversions after creating the new Lot.
20243               This replaces the existing procedure INV_LOT_API_PUB.CREATE_INV_LOT to create NEW LOT
20244                  Punit Kumar*/
20245               IF (l_debug = 1) THEN
20246                 print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
20247               END IF;
20248 
20249               INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
20250                                                          x_return_status      		   => x_return_status
20251                                                         ,x_msg_data           		   => x_msg_data
20252                                                         ,x_msg_count          		   => x_msg_count
20253                                                         ,p_api_version	               => 1.0
20254                                                         ,p_init_msg_lst	               => FND_API.G_FALSE
20255                                                         ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
20256                                                         ,p_transaction_type_id 	      => l_transaction_type_id
20257                                                         ,p_new_lot			            => 'Y'
20258                                                         ,p_item_id	 		            => l_item_id
20259                                                         ,p_to_organization_id		      => L_ORG_ID
20260                                                         ,p_lot_number			         => L_MTLT_REC.lot_number
20261                                                         ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
20262                                                         ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
20263                                                         ,x_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
20264                                                         ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
20265                                                         ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
20266                                                         ,p_transaction_unit_of_measure => l_rti_UNIT_OF_MEASURE
20267                                                         ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
20268                                                         ,p_OE_ORDER_HEADER_ID	         => l_OE_ORDER_HEADER_ID
20269                                                         ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
20270                                                         ,p_rti_id	                     => L_RTI_ID
20271                                                         ,p_revision             	      => l_item_revision
20272                                                         ,p_subinventory_code  	      => L_SUB_CODE
20273                                                         ,p_locator_id           	      => l_loc_id
20274                                                         ,p_transaction_type           => l_transaction_type
20275                                                         ,p_parent_txn_type            => l_parent_txn_type
20276                                                         ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
20277                                                         );
20278 
20279               IF (l_debug = 1) THEN
20280                 print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
20281               END IF;
20282 
20283               IF X_RETURN_STATUS <> 'S' THEN
20284                 --RAISE ERROR
20285                 l_progress := 'WMSINB-22493';
20286                 RAISE fnd_api.g_exc_error;
20287               END IF;
20288 
20289               /*INVCONV ,*/
20290               IF (l_debug = 1) THEN
20291                 print_debug('VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
20292                 print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
20293               END IF;
20294 
20295 
20296               INV_ROI_INTEGRATION_GRP.INV_NEW_LOT(
20297                                                 x_return_status      		   => x_return_status
20298                                                ,x_msg_count          		   => x_msg_count
20299                                                ,x_msg_data           		   => x_msg_data
20300                                                ,p_api_version	               => 1.0
20301                                                ,p_init_msg_lst	               => FND_API.G_FALSE
20302                                                ,p_source_document_code			=> L_SOURCE_DOCUMENT_CODE
20303                                                ,p_item_id				         => l_item_id
20304                                                ,p_from_organization_id			=> L_FROM_ORG_ID
20305                                                ,p_to_organization_id	         => L_ORG_ID
20306                                                ,p_lot_number				      => L_MTLT_REC.lot_number
20307                                                ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
20308                                                ,p_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
20309                                                ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
20310                                                ,p_primary_unit_of_measure	   => l_rti_PRIMARY_UNIT_OF_MEASURE
20311                                                ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
20312                                                ,p_uom_code	                  => l_rti_UOM_CODE
20313                                                ,p_secondary_uom_code	         => l_rti_SECONDARY_UOM_CODE
20314                                                ,p_reason_id	                  => L_MTLT_REC.REASON_ID
20315                                                ,P_MLN_REC                     => L_MLN_REC
20316                                                ,p_mtlt_rowid	               => L_MTLT_REC.ROWID
20317                                                );
20318 
20319             /*INVCONV ,*/
20320             IF (l_debug = 1) THEN
20321               print_debug('VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_NEW_LOT return status: '||x_return_status||' : '||l_progress, 1);
20322               print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
20323             END IF;
20324 
20325             IF X_RETURN_STATUS <> 'S' THEN
20326               --RAISE ERROR
20327               l_progress := 'WMSINB-22494';
20328               RAISE fnd_api.g_exc_error;
20329             END IF;
20330 
20331           ELSE --IF NOT l_lot_entered_on_parent THEN
20332             --raise error
20333             l_progress := 'WMSINB-22504';
20334             RAISE fnd_api.g_exc_error;
20335           END IF; --IF NOT l_lot_entered_on_parent THEN
20336 	      END IF; --IF L_LOT_EXISTS = 1 THEN
20337 
20338 	      IF (L_SERIAL_NUMBER_CONTROL_CODE IN (2,5,6)) THEN
20339 
20340 		 IF (l_debug = 1) THEN
20341 		    print_debug('VALIDATE_LOT_SERIAL_INFO: LOT AND SERIAL CONTROLLED: '||l_progress, 1);
20342 		    print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROL CODE: '||l_serial_number_control_code||' : '||l_progress, 1);
20343 		    print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||l_source_document_code||' : '||l_progress, 1);
20344 		    l_progress := 'WMSINB-22515';
20345 		 END IF;
20346 
20347 		 L_NUM_MSNT_RECS := 0;
20348 		 l_tot_msnt_serial_qty := 0;
20349 
20350 		 OPEN C_MSNT_LOTSERIAL(L_MTLT_REC.SERIAL_TRANSACTION_TEMP_ID);
20351 
20352 		 LOOP
20353 		    FETCH C_MSNT_LOTSERIAL INTO L_MSNT_REC;
20354 
20355 		    EXIT WHEN C_MSNT_LOTSERIAL%NOTFOUND;
20356 
20357 		    L_NUM_MSNT_RECS := L_NUM_MSNT_RECS + 1;
20358 
20359 		    IF (L_SERIAL_NUMBER_CONTROL_CODE = 6 AND
20360 			L_SOURCE_DOCUMENT_CODE NOT IN ('RMA','REQ','INVENTORY')) THEN
20361 		       -- RAISE AN ERROR. IF SERIAL IS AT SALES ORDER ISSUE THEN
20362 		       -- IT CAN BE ENTERED ONLY FOR A RMA RECEIPT.
20363 		       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20364 		       fnd_msg_pub.ADD;
20365 		       l_progress := 'WMSINB-22536';
20366 		       RAISE fnd_api.g_exc_error;
20367 		    END IF;
20368 
20369 		    L_SERIAL_QUANTITY :=
20370 		      INV_SERIAL_NUMBER_PUB.GET_SERIAL_DIFF(L_MSNT_REC.FM_SERIAL_NUMBER,
20371 							    L_MSNT_REC.TO_SERIAL_NUMBER);
20372 
20373 		    l_tot_msnt_serial_qty := l_tot_msnt_serial_qty +
20374 		      l_serial_quantity;
20375 
20376 		    INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.FM_SERIAL_NUMBER, L_TEMP_PREFIX, L_FROM_SER_NUMBER);
20377 		    INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.TO_SERIAL_NUMBER, L_TEMP_PREFIX, L_TO_SER_NUMBER);
20378 
20379 		    IF (l_debug = 1) THEN
20380 		       print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL QUANTITY: '||l_serial_quantity||' : '||l_progress, 1);
20381 		       l_progress := 'WMSINB-22551';
20382 		    END IF;
20383 
20384 		    --populate attributes table
20385 		    l_serial_attributes_tbl(1).column_name   := 'SERIAL_ATTRIBUTE_CATEGORY';
20386 		    l_serial_attributes_tbl(1).column_value  := l_msnt_rec.serial_attribute_category;
20387 		    l_serial_attributes_tbl(2).column_name   := 'ORIGINATION_DATE';
20388 		    l_serial_attributes_tbl(2).column_value  := l_msnt_rec.origination_date;
20389 		    l_serial_attributes_tbl(3).column_name   := 'C_ATTRIBUTE1';
20390 		    l_serial_attributes_tbl(3).column_value  := l_msnt_rec.c_attribute1;
20391 		    l_serial_attributes_tbl(4).column_name   := 'C_ATTRIBUTE2';
20392 		    l_serial_attributes_tbl(4).column_value  := l_msnt_rec.c_attribute2;
20393 		    l_serial_attributes_tbl(5).column_name   := 'C_ATTRIBUTE3';
20394 		    l_serial_attributes_tbl(5).column_value  := l_msnt_rec.c_attribute3;
20395 		    l_serial_attributes_tbl(6).column_name   := 'C_ATTRIBUTE4';
20396 		    l_serial_attributes_tbl(6).column_value   := l_msnt_rec.c_attribute4;
20397 		    l_serial_attributes_tbl(7).column_name   := 'C_ATTRIBUTE5';
20398 		    l_serial_attributes_tbl(7).column_value   := l_msnt_rec.c_attribute5;
20399 		    l_serial_attributes_tbl(8).column_name   := 'C_ATTRIBUTE6';
20400 		    l_serial_attributes_tbl(8).column_value   := l_msnt_rec.c_attribute6;
20401 		    l_serial_attributes_tbl(9).column_name   := 'C_ATTRIBUTE7';
20402 		    l_serial_attributes_tbl(9).column_value   := l_msnt_rec.c_attribute7;
20403 		    l_serial_attributes_tbl(10).column_name  := 'C_ATTRIBUTE8';
20404 		    l_serial_attributes_tbl(10).column_value  := l_msnt_rec.c_attribute8;
20405 		    l_serial_attributes_tbl(11).column_name  := 'C_ATTRIBUTE9';
20406 		    l_serial_attributes_tbl(11).column_value  := l_msnt_rec.c_attribute9;
20407 		    l_serial_attributes_tbl(12).column_name  := 'C_ATTRIBUTE10';
20408 		    l_serial_attributes_tbl(12).column_value  := l_msnt_rec.c_attribute10;
20409 		    l_serial_attributes_tbl(13).column_name  := 'C_ATTRIBUTE11';
20410 		    l_serial_attributes_tbl(13).column_value  := l_msnt_rec.c_attribute11;
20411 		    l_serial_attributes_tbl(14).column_name  := 'C_ATTRIBUTE12';
20412 		    l_serial_attributes_tbl(14).column_value  := l_msnt_rec.c_attribute12;
20413 		    l_serial_attributes_tbl(15).column_name  := 'C_ATTRIBUTE13';
20414 		    l_serial_attributes_tbl(15).column_value  := l_msnt_rec.c_attribute13;
20415 		    l_serial_attributes_tbl(16).column_name  := 'C_ATTRIBUTE14';
20416 		    l_serial_attributes_tbl(16).column_value  := l_msnt_rec.c_attribute14;
20417 		    l_serial_attributes_tbl(17).column_name  := 'C_ATTRIBUTE15';
20418 		    l_serial_attributes_tbl(17).column_value  := l_msnt_rec.c_attribute15;
20419 		    l_serial_attributes_tbl(18).column_name  := 'C_ATTRIBUTE16';
20420 		    l_serial_attributes_tbl(18).column_value  := l_msnt_rec.c_attribute16;
20421 		    l_serial_attributes_tbl(19).column_name  := 'C_ATTRIBUTE17';
20422 		    l_serial_attributes_tbl(19).column_value  := l_msnt_rec.c_attribute17;
20423 		    l_serial_attributes_tbl(20).column_name  := 'C_ATTRIBUTE18';
20424 		    l_serial_attributes_tbl(20).column_value  := l_msnt_rec.c_attribute18;
20425 		    l_serial_attributes_tbl(21).column_name  := 'C_ATTRIBUTE19';
20426 		    l_serial_attributes_tbl(21).column_value  := l_msnt_rec.c_attribute19;
20427 		    l_serial_attributes_tbl(22).column_name  := 'C_ATTRIBUTE20';
20428 		    l_serial_attributes_tbl(22).column_value  := l_msnt_rec.c_attribute20;
20429 		    l_serial_attributes_tbl(23).column_name  := 'D_ATTRIBUTE1';
20430 		    l_serial_attributes_tbl(23).column_value  := l_msnt_rec.d_attribute1;
20431 		    l_serial_attributes_tbl(24).column_name  := 'D_ATTRIBUTE2';
20432 		    l_serial_attributes_tbl(24).column_value  := l_msnt_rec.d_attribute2;
20433 		    l_serial_attributes_tbl(25).column_name  := 'D_ATTRIBUTE3';
20434 		    l_serial_attributes_tbl(25).column_value  := l_msnt_rec.d_attribute3;
20435 		    l_serial_attributes_tbl(26).column_name  := 'D_ATTRIBUTE4';
20436 		    l_serial_attributes_tbl(26).column_value  := l_msnt_rec.d_attribute4;
20437 		    l_serial_attributes_tbl(27).column_name  := 'D_ATTRIBUTE5';
20438 		    l_serial_attributes_tbl(27).column_value  := l_msnt_rec.d_attribute5;
20439 		    l_serial_attributes_tbl(28).column_name  := 'D_ATTRIBUTE6';
20440 		    l_serial_attributes_tbl(28).column_value  := l_msnt_rec.d_attribute6;
20441 		    l_serial_attributes_tbl(29).column_name  := 'D_ATTRIBUTE7';
20442 		    l_serial_attributes_tbl(29).column_value  := l_msnt_rec.d_attribute7;
20443 		    l_serial_attributes_tbl(30).column_name  := 'D_ATTRIBUTE8';
20444 		    l_serial_attributes_tbl(30).column_value  := l_msnt_rec.d_attribute8;
20445 		    l_serial_attributes_tbl(31).column_name  := 'D_ATTRIBUTE9';
20446 		    l_serial_attributes_tbl(31).column_value  := l_msnt_rec.d_attribute9;
20447 		    l_serial_attributes_tbl(32).column_name  := 'D_ATTRIBUTE10';
20448 		    l_serial_attributes_tbl(32).column_value  := l_msnt_rec.d_attribute10;
20449 		    l_serial_attributes_tbl(33).column_name  := 'N_ATTRIBUTE1';
20450 		    l_serial_attributes_tbl(33).column_value  := l_msnt_rec.n_attribute1;
20451 		    l_serial_attributes_tbl(34).column_name  := 'N_ATTRIBUTE2';
20452 		    l_serial_attributes_tbl(34).column_value  := l_msnt_rec.n_attribute2;
20453 		    l_serial_attributes_tbl(35).column_name  := 'N_ATTRIBUTE3';
20454 		    l_serial_attributes_tbl(35).column_value  := l_msnt_rec.n_attribute3;
20455 		    l_serial_attributes_tbl(36).column_name  := 'N_ATTRIBUTE4';
20456 		    l_serial_attributes_tbl(36).column_value  := l_msnt_rec.n_attribute4;
20457 		    l_serial_attributes_tbl(37).column_name  := 'N_ATTRIBUTE5';
20458 		    l_serial_attributes_tbl(37).column_value := l_msnt_rec.n_attribute5;
20459 		    l_serial_attributes_tbl(38).column_name  := 'N_ATTRIBUTE6';
20460 		    l_serial_attributes_tbl(38).column_value := l_msnt_rec.n_attribute6;
20461 		    l_serial_attributes_tbl(39).column_name  := 'N_ATTRIBUTE7';
20462 		    l_serial_attributes_tbl(39).column_value := l_msnt_rec.n_attribute7;
20463 		    l_serial_attributes_tbl(40).column_name  := 'N_ATTRIBUTE8';
20464 		    l_serial_attributes_tbl(40).column_value := l_msnt_rec.n_attribute8;
20465 		    l_serial_attributes_tbl(41).column_name  := 'N_ATTRIBUTE9';
20466 		    l_serial_attributes_tbl(41).column_value := l_msnt_rec.n_attribute9;
20467 		    l_serial_attributes_tbl(42).column_name  := 'N_ATTRIBUTE10';
20468 		    l_serial_attributes_tbl(42).column_value := l_msnt_rec.n_attribute10;
20469 		    l_serial_attributes_tbl(43).column_name  := 'STATUS_ID';
20470 		    l_serial_attributes_tbl(43).column_value := l_msnt_rec.status_id;
20471 		    l_serial_attributes_tbl(44).column_name  := 'TERRITORY_CODE';
20472 		    l_serial_attributes_tbl(44).column_value := l_msnt_rec.territory_code;
20473 			l_serial_attributes_tbl(45).column_name   := 'ATTRIBUTE_CATEGORY';
20474 		    l_serial_attributes_tbl(45).column_value  := l_msnt_rec.attribute_category;
20475 		    l_serial_attributes_tbl(46).column_name   := 'ATTRIBUTE1';
20476 		    l_serial_attributes_tbl(46).column_value  := l_msnt_rec.attribute1;
20477 		    l_serial_attributes_tbl(47).column_name   := 'ATTRIBUTE2';
20478 		    l_serial_attributes_tbl(47).column_value  := l_msnt_rec.attribute2;
20479 		    l_serial_attributes_tbl(48).column_name   := 'ATTRIBUTE3';
20480 		    l_serial_attributes_tbl(48).column_value  := l_msnt_rec.attribute3;
20481 		    l_serial_attributes_tbl(49).column_name   := 'ATTRIBUTE4';
20482 		    l_serial_attributes_tbl(49).column_value   := l_msnt_rec.attribute4;
20483 		    l_serial_attributes_tbl(50).column_name   := 'ATTRIBUTE5';
20484 		    l_serial_attributes_tbl(50).column_value   := l_msnt_rec.attribute5;
20485 		    l_serial_attributes_tbl(51).column_name   := 'ATTRIBUTE6';
20486 		    l_serial_attributes_tbl(51).column_value   := l_msnt_rec.attribute6;
20487 		    l_serial_attributes_tbl(52).column_name   := 'ATTRIBUTE7';
20488 		    l_serial_attributes_tbl(52).column_value   := l_msnt_rec.attribute7;
20489 		    l_serial_attributes_tbl(53).column_name  := 'ATTRIBUTE8';
20490 		    l_serial_attributes_tbl(53).column_value  := l_msnt_rec.attribute8;
20491 		    l_serial_attributes_tbl(54).column_name  := 'ATTRIBUTE9';
20492 		    l_serial_attributes_tbl(54).column_value  := l_msnt_rec.attribute9;
20493 		    l_serial_attributes_tbl(55).column_name  := 'ATTRIBUTE10';
20494 		    l_serial_attributes_tbl(55).column_value  := l_msnt_rec.attribute10;
20495 		    l_serial_attributes_tbl(56).column_name  := 'ATTRIBUTE11';
20496 		    l_serial_attributes_tbl(56).column_value  := l_msnt_rec.attribute11;
20497 		    l_serial_attributes_tbl(57).column_name  := 'ATTRIBUTE12';
20498 		    l_serial_attributes_tbl(57).column_value  := l_msnt_rec.attribute12;
20499 		    l_serial_attributes_tbl(58).column_name  := 'ATTRIBUTE13';
20500 		    l_serial_attributes_tbl(58).column_value  := l_msnt_rec.attribute13;
20501 		    l_serial_attributes_tbl(59).column_name  := 'ATTRIBUTE14';
20502 		    l_serial_attributes_tbl(59).column_value  := l_msnt_rec.attribute14;
20503 		    l_serial_attributes_tbl(60).column_name  := 'ATTRIBUTE15';
20504 		    l_serial_attributes_tbl(60).column_value  := l_msnt_rec.attribute15;
20505 
20506 
20507 		    --Validate the serials
20508 		    FOR SERIALQTY IN 1..L_SERIAL_QUANTITY LOOP
20509 
20510 		       l_progress := 'WMSINB-22557';
20511 
20512                        L_CUR_NUMBER := L_FROM_SER_NUMBER+SERIALQTY -1;
20513                        if L_FROM_SER_NUMBER = -1 and  L_TO_SER_NUMBER = -1 then
20514 	                    L_SERIAL_NUMBER  := L_MSNT_REC.fm_serial_number;
20515 		       else
20516 		            L_SERIAL_NUMBER :=
20517 			      SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
20518 				LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
20519 				LENGTH(L_CUR_NUMBER))
20520 			      ||L_CUR_NUMBER;
20521                        End if;
20522 
20523 		       l_progress := 'WMSINB-22565';
20524 
20525 		       BEGIN
20526 			  SELECT CURRENT_ORGANIZATION_ID
20527 			    , current_status
20528 			    , lot_number
20529 			    , Decode(lpn_id,0,NULL,lpn_id)
20530 			    , inspection_status
20531 			    , group_mark_id
20532 			    INTO L_CURR_ORG_ID
20533 			    , l_curr_status
20534 			    , l_curr_lot_num
20535 			    , l_curr_lpn_id
20536 			    , l_inspection_status
20537 			    , l_group_mark_id
20538 			    FROM MTL_SERIAL_NUMBERS
20539 			    WHERE SERIAL_NUMBER = l_serial_number
20540 			    AND inventory_item_id = l_item_id;
20541 
20542 			  l_serial_exists := 1;
20543 			  l_progress := 'WMSINB-22585';
20544 		       EXCEPTION
20545 			  WHEN no_data_found THEN
20546 			     l_serial_exists := 0;
20547 			     l_progress := 'WMSINB-22589';
20548 		       END;
20549 
20550 		       IF (l_debug = 1) THEN
20551 			  print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL EXISTS: '||l_serial_exists||' : '||l_progress, 1);
20552 			  print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NUMBER: '||l_serial_number||' : '||l_progress, 1);
20553 			  print_debug('VALIDATE_LOT_SERIAL_INFO: CURR STATUS: '||l_curr_status||' : '||l_progress, 1);
20554 			  print_debug('VALIDATE_LOT_SERIAL_INFO: CURR ORG ID: '||l_curr_org_id||' : '||l_progress, 1);
20555 			  print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LPN ID: '||l_curr_lpn_id||' : '||l_progress, 1);
20556 			  print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LOT NUM: '||l_curr_lot_num||' : '||l_progress, 1);
20557 			  print_debug('VALIDATE_LOT_SERIAL_INFO: INSPECT STS: '||l_inspection_status||' : '||l_progress, 1);
20558 			  print_debug('VALIDATE_LOT_SERIAL_INFO: GROUP MARK ID: '||l_group_mark_id||' : '||l_progress, 1);
20559 			  print_debug('VALIDATE_LOT_SERIAL_INFO: RESTRICT RCPT SER: '||l_restrict_rcpt_ser||' : '||l_progress, 1);
20560 			  l_progress := 'WMSINB-22602';
20561 		       END IF;
20562 
20563 		       l_progress := 'WMSINB-22605';
20564 
20565 		       IF (L_TRANSACTION_TYPE <> 'RECEIVE') THEN
20566 			  L_SERIAL_ENTERED_ON_PARENT := SERIAL_ENTERED_ON_PARENT(L_PARENT_TRANSACTION_ID);
20567 			ELSE
20568 			  L_SERIAL_ENTERED_ON_PARENT := FALSE;
20569 		       END IF;
20570 
20571 		       IF (l_debug = 1) THEN
20572 			  print_debug('VALIDATE_LOT_SERIAL_INFO: ASN LINE FLAG: '||l_asn_line_flag||' : '||l_progress, 1);
20573 			  l_progress := 'WMSINB-22615';
20574 		       END IF;
20575 
20576 		       IF NOT L_SERIAL_ENTERED_ON_PARENT THEN
20577 			  IF (l_debug = 1) THEN
20578 			     print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NOT ENTERED ON PARENT: '||l_progress, 1);
20579 			     l_progress := 'WMSINB-22621';
20580 			  END IF;
20581 
20582 			  IF (l_serial_number_control_code IN (2,5)
20583 			      OR (l_serial_number_control_code = 6
20584 				  AND l_source_document_code IN
20585 				  ('INVENTORY','REQ'))) THEN
20586 			     IF l_serial_exists = 1 THEN
20587 				IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')
20588 				    OR l_asn_line_flag = 'Y') THEN
20589 
20590 				   IF (l_asn_line_flag = 'Y') THEN
20591 				      IF ((l_curr_org_id <> l_org_id) and not (l_restrict_rcpt_ser = '2'
20592 									       and l_curr_status = 4 ))  THEN
20593 					 --raise error
20594 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20595 					 fnd_msg_pub.ADD;
20596 					 l_progress := 'WMSINB-22634';
20597 					 RAISE fnd_api.g_exc_error;
20598 				       ELSE
20599 					 IF ((l_curr_lot_num IS NOT NULL)
20600 					     AND (l_curr_lot_num <>
20601 						  l_mtlt_rec.lot_number)
20602 					     AND (Nvl(l_curr_status,1) NOT
20603 						  IN (1,4))) THEN
20604 					    --raise error
20605 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20606 					    fnd_msg_pub.ADD;
20607 					    l_progress := 'WMSINB-22641';
20608 					    RAISE fnd_api.g_exc_error;
20609 					 END IF;
20610 				      END IF;
20611 
20612 				      IF (rss_exists(l_shipment_header_id,l_item_id)) THEN
20613 				         BEGIN
20614 					    SELECT '1'
20615 					      INTO l_dummy
20616 					      FROM rcv_serials_supply rss
20617 					      , rcv_shipment_lines rsl
20618 					      WHERE rss.shipment_line_id = rsl.shipment_line_id
20619 					      AND rsl.shipment_header_id = l_shipment_header_id
20620 					      AND rsl.item_id = l_item_id
20621 					      AND rss.supply_type_code = 'SHIPMENT'
20622 					      AND rss.serial_num = l_serial_number;
20623 
20624 					    IF (l_debug = 1) THEN
20625 					       print_debug('VALIDATE_LOT_SERIAL_INFO: RSS EXISTS: '||l_progress, 1);
20626 					       l_progress := 'WMSINB-22657';
20627 					    END IF;
20628 
20629 					    IF l_curr_status <> 5 THEN
20630 					       --raise error
20631 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20632 					       fnd_msg_pub.ADD;
20633 					       l_progress := 'WMSINB-22664';
20634 					       RAISE fnd_api.g_exc_error;
20635 					    END IF;
20636 					 EXCEPTION
20637 					    WHEN no_data_found THEN
20638 					       IF l_restrict_rcpt_ser = '2' THEN
20639 						  IF l_curr_status NOT IN
20640 						    (1,4,6) THEN
20641 						     --raise error
20642 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20643 						     fnd_msg_pub.ADD;
20644 						     l_progress := 'WMSINB-22675';
20645 						     RAISE fnd_api.g_exc_error;
20646 						  END IF;
20647 						ELSE --IF l_restrict_rcpt_ser = '2' THEN
20648 						  IF l_curr_status NOT IN
20649 						    (1,6) THEN
20650 						     --raise error
20651 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20652 						     fnd_msg_pub.ADD;
20653 						     l_progress := 'WMSINB-22684';
20654 						     RAISE fnd_api.g_exc_error;
20655 						  END IF;
20656 					       END IF; --IF l_restrict_rcpt_ser = '2' THEN
20657 					 END;
20658 				       ELSE --IF (rss_exists(l_shipment_header_id,l_item_id)) THEN
20659 					       IF l_restrict_rcpt_ser = '2' THEN
20660 						  IF l_curr_status NOT IN
20661 						    (1,4,6) THEN
20662 						     --raise error
20663 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20664 						     fnd_msg_pub.ADD;
20665 						     l_progress := 'WMSINB-22696';
20666 						     RAISE fnd_api.g_exc_error;
20667 						  END IF;
20668 						ELSE --IF l_restrict_rcpt_ser = '2' THEN
20669 						  IF l_curr_status NOT IN
20670 						    (1,6) THEN
20671 						     --raise error
20672 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20673 						     fnd_msg_pub.ADD;
20674 						     l_progress := 'WMSINB-22705';
20675 						     RAISE fnd_api.g_exc_error;
20676 						  END IF;
20677 					       END IF; --IF l_restrict_rcpt_ser = '2' THEN
20678 				      END IF; --IF (rss_exists(l_shipment_header_id,l_item_id)) THEN
20679 				   END IF; --IF (l_asn_line_flag = 'Y') THEN
20680 
20681 				   IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
20682 				      -- CHECK TO SEE IF THE ITEM IS SERIAL
20683 				      -- CONTROLLED IN SOURCE ORG
20684 
20685 				      GET_SERIAL_LOT_CTRL_IN_SRC_ORG
20686 					(L_SHIPMENT_LINE_ID, L_ORG_ID,
20687 					 L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
20688 					 l_from_org_rev_ctrl, X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
20689 
20690 				      IF ((L_FROM_ORG_SER_CRTL IN (2,5,6)
20691 					   AND l_source_document_code = 'REQ')
20692 					  OR (l_from_org_ser_crtl IN (2,5)
20693 					      AND l_source_document_code = 'INVENTORY')
20694 					  ) THEN
20695 
20696                                          /*****bug4187663, comment out the call to serial uniqueness check, the check will be in TM
20697 					 IF (l_source_document_code = 'REQ') THEN
20698 					    l_txn_src_type_id := 7;
20699 					  ELSE
20700 					    l_txn_src_type_id := 13;
20701 					 END IF;
20702 
20703 					 --Validate Serial Uniqueness in
20704 					 --current org.
20705 					 IF (l_debug = 1) THEN
20706 					    print_debug('VALIDATE_LOT_SERIAL_INFO: CALLING IS_SERNUM_UNIQUE...', 1);
20707 					 END IF;
20708 
20709 					 IF
20710 					   (is_sernum_unique(l_org_id,l_item_id,l_serial_number,l_txn_src_type_id,12,x_msg_data)<>0) THEN
20711 					      --raise error
20712 					      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20713 					      fnd_msg_pub.ADD;
20714 					      l_progress := 'WMSINB-22725';
20715 					      RAISE fnd_api.g_exc_error;
20716 					   END IF;
20717 
20718 					   IF (l_debug = 1) THEN
20719 					      print_debug('VALIDATE_LOT_SERIAL_INFO: CALLING IS_SERNUM_UNIQUE...DONE', 1);
20720 					   END IF;
20721                                            *****end of bug4187663*****/
20722 
20723 					   IF l_curr_org_id <> l_from_org_id THEN
20724 					      --raise error
20725 					      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20726 					      fnd_msg_pub.ADD;
20727 					      l_progress := 'WMSINB-22726';
20728 					      RAISE fnd_api.g_exc_error;
20729 					    ELSE
20730 					      IF ((l_curr_lot_num IS NOT NULL) AND
20731 						  (l_curr_lot_num <>
20732 						   l_mtlt_rec.lot_number)
20733 						  AND (Nvl(l_curr_status,1)
20734 						       NOT IN (1,4))) THEN
20735 						 --raise error
20736 						 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20737 						 fnd_msg_pub.ADD;
20738 						 l_progress := 'WMSINB-22734';
20739 						 RAISE fnd_api.g_exc_error;
20740 					      END IF;
20741 					   END IF;
20742 
20743 				         BEGIN
20744 					    SELECT '1'
20745 					      INTO L_DUMMY
20746 					      FROM rcv_serials_supply rss
20747 					      , rcv_shipment_lines rsl
20748 					      WHERE rss.SHIPMENT_LINE_ID = rsl.SHIPMENT_LINE_ID
20749 					      AND rsl.shipment_header_id = l_shipment_header_id
20750 					      AND rsl.item_id = l_item_id
20751 					      AND rss.SUPPLY_TYPE_CODE = 'SHIPMENT'
20752 					      AND rss.serial_num = l_serial_number;
20753 
20754 					    IF L_CURR_STATUS <> 5 THEN
20755 					       -- RAISE AN ERROR
20756 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20757 					       fnd_msg_pub.ADD;
20758 					       l_progress := 'WMSINB-22751';
20759 					       RAISE fnd_api.g_exc_error;
20760 					    END IF;
20761 
20762 					 EXCEPTION
20763 					    WHEN NO_DATA_FOUND THEN
20764 					       -- RAISE AN ERROR
20765 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20766 					       fnd_msg_pub.ADD;
20767 					       l_progress := 'WMSINB-22760';
20768 					       RAISE fnd_api.g_exc_error;
20769 					 END;
20770 				       ELSE --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
20771                 --BUG 5524134
20772                 /* For lot serials with serial numbers in status 4
20773                   i.e. issued out of stores, we need to
20774                   honor the INV_RESTRICT_RCPT_SER profile.
20775                   And for serial status defined but not used
20776                   error out only if the org id in MSN is equal to
20777                   that present in the RSL.
20778                   */
20779 					       IF L_CURR_ORG_ID <> l_org_id THEN
20780                     BEGIN
20781                            SELECT from_organization_id INTO l_from_org_id
20782                            FROM rcv_shipment_lines
20783                            WHERE shipment_line_id = L_SHIPMENT_LINE_ID;
20784                     EXCEPTION
20785                            WHEN NO_DATA_FOUND THEN
20786                            -- RAISE AN ERROR
20787                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20788                            fnd_msg_pub.ADD;
20789                            l_progress := 'WMSINB-22765';
20790                            RAISE fnd_api.g_exc_error;
20791                     END;
20792                     IF L_SOURCE_DOCUMENT_CODE IN ( 'INVENTORY' , 'REQ' ) THEN
20793                        IF NOT (
20794                                ( L_CURR_STATUS = 1 AND L_CURR_ORG_ID = l_from_org_id)
20795                             OR ( L_CURR_STATUS = 4 AND l_restrict_rcpt_ser = '2' )
20796                               )
20797                              THEN
20798                              l_progress := 'WMSINB-22761';
20799                              IF (l_debug = 1) THEN
20800                                   print_debug('For Intransit receipt the serial number org does not match the sending org!', 1);
20801                              END IF;
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             ELSE
20807     						  --raise error
20808     						  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20809     						  fnd_msg_pub.ADD;
20810     						  l_progress := 'WMSINB-22768';
20811     						  RAISE fnd_api.g_exc_error;
20812 				    END IF;
20813 						ELSE
20814 						  IF ((l_curr_lot_num IS
20815 						       NOT NULL)
20816 						      AND (l_curr_lot_num
20817 							   <>
20818 							   l_mtlt_rec.lot_number)
20819 						      AND
20820 						      (Nvl(l_curr_status,1)
20821 						       NOT IN (1,4))) THEN
20822 						     --raise error
20823 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20824 						     fnd_msg_pub.ADD;
20825 						     l_progress := 'WMSINB-22776';
20826 						     RAISE fnd_api.g_exc_error;
20827 						  END IF;
20828 					       END IF;
20829 					       /* Bug: 5524134
20830                     In case of serial numbers that are in status
20831 					          4 i.e. issued out of stores, we need to
20832                     honor the INV_RESTRICT_RCPT_SER profile.
20833                   */
20834 					       IF (L_CURR_STATUS NOT IN (1,6)
20835                      AND NOT (l_restrict_rcpt_ser = '2'and l_curr_status = 4)
20836                     ) THEN
20837 						  -- RAISE AN ERROR
20838 						  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20839 						  fnd_msg_pub.ADD;
20840 						  l_progress := 'WMSINB-22785';
20841 						  RAISE fnd_api.g_exc_error;
20842 					       END IF;
20843 				      END IF; --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
20844 				   END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
20845 				 ELSE  --IF (L_SOURCE_DOCUMENT_CODE IN
20846 				      --('INVENTORY','REQ') OR l_asn_line_flag = 'Y') THEN
20847 				      IF (( (L_SOURCE_DOCUMENT_CODE <> 'RMA' AND l_curr_org_id <> l_org_id) )
20848                            and not (l_restrict_rcpt_ser = '2'and l_curr_status = 4 ))  THEN
20849 					 --raise error
20850 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20851 					 fnd_msg_pub.ADD;
20852 					 l_progress := 'WMSINB-22796';
20853 					 RAISE fnd_api.g_exc_error;
20854 				       ELSE
20855 					 IF ((l_curr_lot_num IS NOT NULL)
20856 					     AND (l_curr_lot_num <>
20857 						  l_mtlt_rec.lot_number)
20858 					     AND (Nvl(l_curr_status,1) NOT
20859 						  IN (1,4))) THEN
20860 					    --raise error
20861 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20862 					    fnd_msg_pub.ADD;
20863 					    l_progress := 'WMSINB-22803';
20864 					    RAISE fnd_api.g_exc_error;
20865 					 END IF;
20866 				      END IF;
20867 
20868 				      IF l_restrict_rcpt_ser = '2' THEN
20869 					 IF l_curr_status NOT IN (1,4,6) THEN
20870 					    --raise error
20871 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20872 					    fnd_msg_pub.ADD;
20873 					    l_progress := 'WMSINB-22813';
20874 					    RAISE fnd_api.g_exc_error;
20875 					 END IF;
20876 /* Bug 6847337:
20877  * Fix done to allow the re-using of serials after the
20878  * correction of a PO receipt by handling the transaction type
20879  * for correction(71) and return to vendor(36) in the following
20880  * ELSE condition when the INV: Restrict Receipt of Serials = 'Yes'.
20881  */
20882 				       ELSE --IF l_restrict_rcpt_ser = '2' THEN
20883 					 IF ((l_curr_status NOT IN (1,6))
20884 					     AND NOT (l_curr_status = 4 and
20885 						     (l_source_document_code = 'RMA' OR
20886 						        (l_source_document_code = 'PO'
20887 						           and l_last_transaction_type_id in (36,71))))) THEN
20888 					    --raise error
20889 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20890 					    fnd_msg_pub.ADD;
20891 					    l_progress := 'WMSINB-22821';
20892 					    RAISE fnd_api.g_exc_error;
20893 					 END IF;
20894 				      END IF; --IF l_restrict_rcpt_ser = '2' THEN
20895 
20896 				END IF; --IF (L_SOURCE_DOCUMENT_CODE IN
20897 				--('INVENTORY','REQ') OR l_asn_line_flag = 'Y') THEN
20898 
20899 				--Validate serial/LPN
20900 				IF l_transaction_type = 'RECEIVE' THEN
20901 				   IF (l_source_document_code IN ('INVENTORY', 'REQ')) then
20902 				      IF (Nvl(l_curr_lpn_id, -9999) <>
20903 					  Nvl(l_lpn_id, -9999)
20904 					  AND (
20905                  Nvl(l_curr_status,1) NOT IN (1,5, 6))  ----bug 7112775 (Added status 6 also)
20906                  AND NOT (l_curr_status = 4 and l_restrict_rcpt_ser = '2') --Bug: 5524134
20907                  ) THEN
20908 					 --raise error
20909 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20910 					 fnd_msg_pub.ADD;
20911 					 l_progress := 'WMSINB-22837';
20912 					 RAISE fnd_api.g_exc_error;
20913 				      END IF;
20914 				   END IF;
20915 				 ELSE
20916 				   IF ((Nvl(l_curr_lpn_id, -9999) <>
20917 					Nvl(l_lpn_id, -9999))
20918 					AND Nvl(l_curr_status,1) <> 4) THEN
20919 				      --raise error
20920 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20921 				      fnd_msg_pub.ADD;
20922 				      l_progress := 'WMSINB-22847';
20923 				      RAISE fnd_api.g_exc_error;
20924 				   END IF;
20925 				END IF;
20926 
20927 				--Validate Serial/Inspection_status
20928 		 /*  Commented for bug 6269102
20929                   *  To allow the inspection done again
20930 		  *  on an inspection transaction to succeed
20931 		  *  as it was failing because of the
20932 		  *  inspection status <> 1
20933 
20934 				IF l_transaction_type IN ('ACCEPT', 'REJECT') THEN
20935 				   IF (Nvl(l_inspection_status, 1) <> 1) THEN
20936 				      --raise error
20937 				      l_progress := 'WMSINB-22856';
20938 				      RAISE fnd_api.g_exc_error;
20939 				   END IF;
20940 				 ELS*/
20941                                  -- Bug 9569977: Commenting following since l_serial_entered_on_parent
20942                                  --              is false
20943 				 /*IF (l_transaction_type = 'DELIVER') THEN
20944 				   IF (l_routing_header_id = 2) THEN
20945 				      IF l_inspection_status IS NOT NULL AND l_inspection_status = 1 THEN
20946 					 --raise error
20947 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20948 					 fnd_msg_pub.ADD;
20949 					 l_progress := 'WMSINB-22865';
20950 					 RAISE fnd_api.g_exc_error;
20951 				      END IF;
20952 				   END IF;
20953 				END IF;*/
20954 
20955 				--Validate serial/group_mark_id to prevent
20956 				--entering of duplicate serials
20957 
20958 				IF (Nvl(l_group_mark_id, -99) = -7937) THEN
20959 				   --raise error
20960 				   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20961 				   fnd_msg_pub.ADD;
20962 				   l_progress := 'WMSINB-22878';
20963 				   RAISE fnd_api.g_exc_error;
20964 				END IF;
20965 
20966 				IF (Nvl(l_curr_status, 1) IN (1,6)) THEN
20967 				   --validate and update the attributes.
20968 				   inv_serial_number_pub.validate_update_serial_att
20969 				     (x_return_status     => x_return_status,
20970 				      x_msg_count         => x_msg_count,
20971 				      x_msg_data          => x_msg_data,
20972 				      x_validation_status => l_validation_status,
20973 				      p_serial_number     => l_serial_number,
20974 				      p_organization_id   => l_org_id,
20975 				      p_inventory_item_id => l_item_id,
20976 				      p_serial_att_tbl    => l_serial_attributes_tbl,
20977 				      p_validate_only     => FALSE
20978 				      );
20979 
20980 				   IF (l_validation_status <> 'Y'
20981 				       OR x_return_status <> g_ret_sts_success) THEN
20982 				      --raise error
20983 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20984 				      fnd_msg_pub.ADD;
20985 				      l_progress := 'WMSINB-22880';
20986 				      RAISE fnd_api.g_exc_error;
20987 				   END IF;
20988 				END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
20989 
20990 				--UPDATE GROUP_MARK_ID TO -7937
20991 				IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
20992 				   --raise error
20993 				   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
20994 				   fnd_msg_pub.ADD;
20995 				   l_progress := 'WMSINB-22887';
20996 				   RAISE fnd_api.g_exc_error;
20997 				END IF;
20998 
20999 			      ELSE --IF l_serial_exists = 1 THEN
21000 				      IF (l_source_document_code IN ('INVENTORY','REQ')) THEN
21001 					 GET_SERIAL_LOT_CTRL_IN_SRC_ORG
21002 					   (L_SHIPMENT_LINE_ID, L_ORG_ID,
21003 					    L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
21004 					    l_from_org_rev_ctrl, X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
21005 
21006 					 IF ((L_FROM_ORG_SER_CRTL IN (2,5,6)
21007 					      AND l_source_document_code = 'REQ')
21008 					     OR (l_from_org_ser_crtl IN (2,5)
21009 						 AND l_source_document_code = 'INVENTORY')
21010 					     ) THEN
21011 					    --raise error
21012 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21013 					    fnd_msg_pub.ADD;
21014 					    l_progress := 'WMSINB-22902';
21015 					    RAISE fnd_api.g_exc_error;
21016 					 END IF;
21017 				      END IF;
21018 
21019 				      IF l_serial_number_control_code = 5 THEN
21020 					 --PERFORM SERIAL VALIDATION FOR NEW SERIAL
21021 					 --(INCLUDING ATT VALIDATION)
21022 					 --CREATE MSN
21023 
21024 					 inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
21025 										   , p_inventory_item_id => l_item_id
21026 										   , p_organization_id => l_org_id
21027 										   , p_from_serial_number => l_serial_number
21028 										   , p_to_serial_number => l_serial_number
21029 										   , p_initialization_date => SYSDATE
21030 										   , p_completion_date => NULL
21031 										   , p_ship_date => NULL
21032 										   , p_revision => l_item_revision
21033 										   , p_lot_number => l_mtlt_rec.lot_number
21034 										   , p_current_locator_id => l_loc_id
21035 										   , p_subinventory_code => l_sub_code
21036 										   , p_trx_src_id => NULL
21037 										   , p_unit_vendor_id => NULL
21038 										   , p_vendor_lot_number => l_mtlt_rec.supplier_lot_number
21039 										   , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
21040 										   , p_receipt_issue_type => NULL
21041 										   , p_txn_src_id => NULL
21042 										   , p_txn_src_name => NULL
21043 										   , p_txn_src_type_id => NULL
21044 										   , p_transaction_id => NULL
21045 										   , p_current_status => 1
21046 					   , p_parent_item_id => NULL
21047 					   , p_parent_serial_number => NULL
21048 					   , p_cost_group_id => NULL
21049 					   , p_transaction_action_id => 27
21050 					   , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
21051 					   , p_status_id => NULL
21052 					   , p_inspection_status => NULL
21053 					   , x_object_id => l_object_id
21054 					   , x_return_status => x_return_status
21055 					   , x_msg_count => x_msg_count
21056 					   , x_msg_data => x_msg_data);
21057 
21058 					 IF (x_return_status <> g_ret_sts_success) THEN
21059 					    --raise error
21060 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21061 					    fnd_msg_pub.ADD;
21062 					    l_progress := 'WMSINB-22911';
21063 					    RAISE fnd_api.g_exc_error;
21064 					 END IF;
21065 
21066 					 --validate and update the attributes.
21067 					 inv_serial_number_pub.validate_update_serial_att
21068 					   (x_return_status     => x_return_status,
21069 					    x_msg_count         => x_msg_count,
21070 					    x_msg_data          => x_msg_data,
21071 					    x_validation_status => l_validation_status,
21072 					    p_serial_number     => l_serial_number,
21073 					    p_organization_id   => l_org_id,
21074 					    p_inventory_item_id => l_item_id,
21075 					    p_serial_att_tbl    => l_serial_attributes_tbl,
21076 					    p_validate_only     => FALSE
21077 					    );
21078 
21079 					 IF (l_validation_status <> 'Y'
21080 					     OR x_return_status <> g_ret_sts_success) THEN
21081 					    --raise error
21082 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21083 					    fnd_msg_pub.ADD;
21084 					    l_progress := 'WMSINB-22941';
21085 					    RAISE fnd_api.g_exc_error;
21086 					 END IF;
21087 
21088 					 --UPDATE GROUP_MARK_ID TO -7937
21089 					 IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
21090 					    --raise error
21091 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21092 					    fnd_msg_pub.ADD;
21093 					    l_progress := 'WMSINB-22951';
21094 					    RAISE fnd_api.g_exc_error;
21095 					 END IF;
21096 				       ELSE
21097 					 --raise error
21098 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21099 					 fnd_msg_pub.ADD;
21100 					 l_progress := 'WMSINB-22958';
21101 					 RAISE fnd_api.g_exc_error;
21102 				      END IF;
21103 			     END IF; --IF l_serial_exists = 1 THEN
21104 			   ELSIF (l_serial_number_control_code = 6 AND
21105 				  l_source_document_code = 'RMA') THEN
21106 				   IF l_serial_exists = 1 THEN
21107                   --bug#3571808 removed the current_org_id check
21108                   /*
21109 				      IF ((l_curr_org_id <> l_org_id) and not (l_restrict_rcpt_ser = '2'
21110 									       and l_curr_status = 4 ))  THEN
21111 					 --raise error
21112 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21113 					 fnd_msg_pub.ADD;
21114 					 l_progress := 'WMSINB-22969';
21115 					 RAISE fnd_api.g_exc_error;
21116 				       ELSE */
21117 					 IF ((l_curr_lot_num IS NOT NULL)
21118 					     AND (l_curr_lot_num <> l_mtlt_rec.lot_number)
21119 					     AND (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
21120 					    --raise error
21121 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21122 					    fnd_msg_pub.ADD;
21123 					    l_progress := 'WMSINB-22976';
21124 					    RAISE fnd_api.g_exc_error;
21125 					 END IF;
21126 				      --END IF;
21127 
21128 
21129 				      IF l_curr_status NOT IN (1,4,6) THEN
21130 					 --raise error
21131 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21132 					 fnd_msg_pub.ADD;
21133 					 l_progress := 'WMSINB-22985';
21134 					 RAISE fnd_api.g_exc_error;
21135 				      END IF;
21136 
21137 				      -- see if we need to restrict 4's based on
21138 				      -- inv_restrict_rcpt profile
21139 				      -- REVIEW at CODE REVIEW
21140 				      IF l_restrict_rcpt_ser <> 2 THEN
21141 					 l_dummy := '0';
21142 				         BEGIN
21143 					    SELECT '1'
21144 					      INTO l_dummy
21145 					      FROM dual
21146 					      WHERE exists (SELECT '1'
21147 							    FROM   mtl_serial_numbers
21148 							    WHERE  inventory_item_id = l_item_id
21149 							    AND    current_organization_id = l_org_id
21150 							    AND    current_status IN (1, 4) --Do we need 4 here
21151 							    AND    serial_number = l_serial_number
21152 							    AND    LAST_TXN_SOURCE_TYPE_ID = 12);
21153 
21154 					    IF l_dummy <> '0' THEN
21155 					       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21156 					       fnd_msg_pub.ADD;
21157 					       l_progress := 'WMSINB-23009';
21158 					       RAISE fnd_api.g_exc_error;
21159 					    END IF;
21160 
21161 					 EXCEPTION
21162 					    WHEN no_data_found THEN
21163 					       NULL;
21164 					 END;
21165 				      END IF;
21166 
21167 				      IF (Nvl(l_group_mark_id, -99) = -7937) THEN
21168 					 --raise error
21169 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21170 					 fnd_msg_pub.ADD;
21171 					 l_progress := 'WMSINB-23023';
21172 					 RAISE fnd_api.g_exc_error;
21173 				      END IF;
21174 
21175 				      IF (Nvl(l_curr_status, 1) in (1,6)) THEN
21176 					 --validate and update the attributes.
21177 					 inv_serial_number_pub.validate_update_serial_att
21178 					   (x_return_status     => x_return_status,
21179 					    x_msg_count         => x_msg_count,
21180 					    x_msg_data          => x_msg_data,
21181 					    x_validation_status => l_validation_status,
21182 					    p_serial_number     => l_serial_number,
21183 					    p_organization_id   => l_org_id,
21184 					    p_inventory_item_id => l_item_id,
21185 					    p_serial_att_tbl    => l_serial_attributes_tbl,
21186 					    p_validate_only     => FALSE
21187 					    );
21188 
21189 					 IF (l_validation_status <> 'Y'
21190 					     OR x_return_status <> g_ret_sts_success) THEN
21191 					    --raise error
21192 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21193 					    fnd_msg_pub.ADD;
21194 					    l_progress := 'WMSINB-23030';
21195 					    RAISE fnd_api.g_exc_error;
21196 					 END IF;
21197 				      END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
21198 
21199 				      --UPDATE GROUP_MARK_ID TO -7937
21200 				      IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
21201 					 --raise error
21202 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21203 					 fnd_msg_pub.ADD;
21204 					 l_progress := 'WMSINB-23032';
21205 					 RAISE fnd_api.g_exc_error;
21206 				      END IF;
21207 				    ELSE --IF l_serial_exists = 1 THEN
21208 					 --PERFORM SERIAL VALIDATION FOR NEW SERIAL
21209 					 --(INCLUDING ATT VALIDATION)
21210 					 --CREATE MSN
21211 
21212 					 inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
21213 										   , p_inventory_item_id => l_item_id
21214 										   , p_organization_id => l_org_id
21215 										   , p_from_serial_number => l_serial_number
21216 										   , p_to_serial_number => l_serial_number
21217 										   , p_initialization_date => SYSDATE
21218 										   , p_completion_date => NULL
21219 										   , p_ship_date => NULL
21220 										   , p_revision => l_item_revision
21221 										   , p_lot_number => l_mtlt_rec.lot_number
21222 										   , p_current_locator_id => l_loc_id
21223 										   , p_subinventory_code => l_sub_code
21224 										   , p_trx_src_id => NULL
21225 										   , p_unit_vendor_id => NULL
21226 										   , p_vendor_lot_number => l_mtlt_rec.supplier_lot_number
21227 										   , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
21228 										   , p_receipt_issue_type => NULL
21229 										   , p_txn_src_id => NULL
21230 										   , p_txn_src_name => NULL
21231 										   , p_txn_src_type_id => NULL
21232 										   , p_transaction_id => NULL
21233 										   , p_current_status => 1
21234 					   , p_parent_item_id => NULL
21235 					   , p_parent_serial_number => NULL
21236 					   , p_cost_group_id => NULL
21237 					   , p_transaction_action_id => 27
21238 					   , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
21239 					   , p_status_id => NULL
21240 					   , p_inspection_status => NULL
21241 					   , x_object_id => l_object_id
21242 					   , x_return_status => x_return_status
21243 					   , x_msg_count => x_msg_count
21244 					   , x_msg_data => x_msg_data);
21245 
21246 
21247 					 IF (x_return_status <> g_ret_sts_success) THEN
21248 					    --raise error
21249 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21250 					    fnd_msg_pub.ADD;
21251 					    l_progress := 'WMSINB-23035';
21252 					    RAISE fnd_api.g_exc_error;
21253 					 END IF;
21254 
21255 					 --validate and update the attributes.
21256 					 inv_serial_number_pub.validate_update_serial_att
21257 					   (x_return_status     => x_return_status,
21258 					    x_msg_count         => x_msg_count,
21259 					    x_msg_data          => x_msg_data,
21260 					    x_validation_status => l_validation_status,
21261 					    p_serial_number     => l_serial_number,
21262 					    p_organization_id   => l_org_id,
21263 					    p_inventory_item_id => l_item_id,
21264 					    p_serial_att_tbl    => l_serial_attributes_tbl,
21265 					    p_validate_only     => FALSE
21266 					    );
21267 
21268 					 IF (l_validation_status <> 'Y'
21269 					     OR x_return_status <> g_ret_sts_success) THEN
21270 					    --raise error
21271 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21272 					    fnd_msg_pub.ADD;
21273 					    l_progress := 'WMSINB-23069';
21274 					    RAISE fnd_api.g_exc_error;
21275 					 END IF;
21276 
21277 					 --UPDATE GROUP_MARK_ID TO -7937
21278 					 IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
21279 					    --raise error
21280 					    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21281 					    fnd_msg_pub.ADD;
21282 					    l_progress := 'WMSINB-23079';
21283 					    RAISE fnd_api.g_exc_error;
21284 					 END IF;
21285 				   END IF; --IF l_serial_exists = 1 THEN
21286 			  END IF; --IF l_serial_number_control_code IN (2,5) THEN
21287 			ELSE --IF NOT L_SERIAL_ENTERED_ON_PARENT THEN
21288 			   BEGIN
21289 			      SELECT '1'
21290 				INTO L_DUMMY
21291 				FROM RCV_SERIALS_SUPPLY
21292 				WHERE TRANSACTION_ID = L_PARENT_TRANSACTION_ID
21293 				AND SERIAL_NUM = L_SERIAL_NUMBER;
21294 
21295 			      IF (l_curr_status <> 7) THEN
21296 				 --raise error
21297 				 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21298 				 fnd_msg_pub.ADD;
21299 				 l_progress := 'WMSINB-23096';
21300 				 RAISE fnd_api.g_exc_error;
21301 			      END IF;
21302 
21303 			      --Validate Serial/Inspection_status
21304                          /*  Commented for bug 6269102
21305                           *  To allow the inspection done again
21306                 	  *  on an inspection transaction to succeed
21307 		          *  as it was failing because of the
21308         		  *  inspection status <> 1
21309 
21310 			      IF l_transaction_type IN ('ACCEPT', 'REJECT') THEN
21311 				 IF (Nvl(l_inspection_status, 1) <> 1) THEN
21312 				    --raise error
21313 				    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21314 				    fnd_msg_pub.ADD;
21315 				    l_progress := 'WMSINB-23106';
21316 				    RAISE fnd_api.g_exc_error;
21317 				 END IF;
21318 			       ELS */
21319 			       IF l_transaction_type = 'DELIVER' THEN
21320 				 IF (l_routing_header_id = 2) THEN
21321 				    IF l_inspection_status IS NOT NULL AND l_inspection_status = 1 THEN
21322 				       --raise error
21323 				       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21324 				       fnd_msg_pub.ADD;
21325 				       l_progress := 'WMSINB-23115';
21326 				       RAISE fnd_api.g_exc_error;
21327 				    END IF;
21328 				 END IF;
21329 			      END IF;
21330 
21331 			      --Validate serial/group_mark_id to prevent
21332 			      --entering of duplicate serials
21333 
21334 			      IF (Nvl(l_group_mark_id, -99) = -7937) THEN
21335 				 --raise error
21336 				 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21337 				 fnd_msg_pub.ADD;
21338 				 l_progress := 'WMSINB-23128';
21339 				 RAISE fnd_api.g_exc_error;
21340 			      END IF;
21341 
21342 			      --UPDATE GROUP_MARK_ID TO -7937
21343 			      IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
21344 				 --raise error
21345 				 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21346 				 fnd_msg_pub.ADD;
21347 				 l_progress := 'WMSINB-23137';
21348 				 RAISE fnd_api.g_exc_error;
21349 			      END IF;
21350 			   EXCEPTION
21351 			      WHEN NO_DATA_FOUND THEN
21352 				 -- RAISE ERROR
21353 				 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21354 				 fnd_msg_pub.ADD;
21355 				 l_progress := 'WMSINB-23145';
21356 				 RAISE fnd_api.g_exc_error;
21357 			   END;
21358 		       END IF; --IF NOT L_SERIAL_ENTERED_ON_PARENT THEN
21359 		    END LOOP; -- FOR 1..L_SERIAL_QUANTITY
21360 		 END LOOP; --FETCH C_MSNT_LOTSERIAL INTO L_MSNT_REC;
21361 
21362 		 CLOSE c_msnt_lotserial;
21363 
21364 		 IF (l_num_msnt_recs > 0) THEN
21365 		    IF l_mtlt_rec.primary_quantity <> l_tot_msnt_serial_qty THEN
21366 		       --raise error
21367 		       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21368 		       fnd_msg_pub.ADD;
21369 		       l_progress := 'WMSINB-23159';
21370 		       RAISE fnd_api.g_exc_error;
21371 		    END IF;
21372 		  ELSE
21373 
21374 		    IF l_source_document_code IN ('INVENTORY', 'REQ') THEN
21375 		       GET_SERIAL_LOT_CTRL_IN_SRC_ORG
21376 			 (L_SHIPMENT_LINE_ID, L_ORG_ID,
21377 			  L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
21378 			  l_from_org_rev_ctrl,
21379 			  X_RETURN_STATUS, X_MSG_COUNT,
21380 			  x_msg_data);
21381 		    END IF;
21382 
21383 		    IF (l_serial_number_control_code IN (2,5)
21384 			OR (l_serial_number_control_code = 6
21385 			    AND l_source_document_code IN ('RMA'))
21386 			OR (l_serial_number_control_code = 6
21387 			    AND l_source_document_code = 'INVENTORY'
21388 			    AND l_from_org_ser_crtl IN (2,5))
21389 			--BUG 3644289: Do the following check for INTREQ
21390 			OR (l_serial_number_control_code = 6
21391 			    AND l_from_org_ser_crtl IN (2,5,6)
21392 			    AND l_source_document_code = 'REQ')) THEN
21393 		       --raise error
21394 		       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21395 		       fnd_msg_pub.ADD;
21396 		       l_progress := 'WMSINB-23166';
21397 		       RAISE fnd_api.g_exc_error;
21398 		    END IF;
21399 		 END IF;
21400 
21401 	      END IF; -- IF (L_SERIAL_NUMBER_CONTROL_CODE IN (2,5,6)) THEN
21402 	   END LOOP; --FETCH C_MTLT INTO L_MTLT_REC;
21403 
21404 	   CLOSE c_mtlt;
21405 
21406         /* Bug 4546519 : l_tot_mtlt_prim_qty is a computed floating point number.
21407          **  In the following condition, it is necessary to use round function for
21408          **  comparing the floating point values.
21409          */
21410 
21411 	   IF (l_num_mtlt_recs > 0) THEN
21412 	   --Bug#8488484 Round by 6,not 5
21413       --Bug 9113637 The change done for bug 8488484 is not correct.
21414 	      IF (ROUND(l_tot_mtlt_prim_qty,5) <> ROUND(l_rti_primary_qty,5)) THEN
21415 		-- Bug# 4225766 Compare transaction qty there can be a difference in primary qty
21416 		-- if there is a lot specific conversion
21417 		IF (ROUND(l_tot_mtlt_trans_qty,5) <> ROUND(l_rti_trans_qty,5)) THEN -- Bug# 4225766
21418 			--raise error
21419 			l_progress := 'WMSINB-23178';
21420 			RAISE fnd_api.g_exc_error;
21421 		END IF; -- Bug# 4225766
21422 	      END IF;
21423 	    ELSE
21424 	      IF (l_transaction_type = 'DELIVER'
21425 		  OR Nvl(l_auto_transact_code,'@@@@') = 'DELIVER') THEN
21426 		 --raise error;
21427 		 l_progress := 'WMSINB-23184';
21428 		 RAISE fnd_api.g_exc_error;
21429 	       ELSIF (lot_entered_on_parent(l_parent_transaction_id)) THEN
21430 		 --raise error;
21431 		 l_progress := 'WMSINB-23188';
21432 		 RAISE fnd_api.g_exc_error;
21433 	      END IF;
21434 	   END IF;
21435 	 ELSIF l_serial_number_control_code IN (2,5,6) THEN --IF (L_LOT_CONTROL_CODE = 2) THEN
21436 
21437 				IF (l_debug = 1) THEN
21438 				   print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROLLED: '||l_progress, 1);
21439 				   print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROL CODE: '||l_serial_number_control_code||' : '||l_progress, 1);
21440 				   print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||l_source_document_code||' : '||l_progress, 1);
21441 				   l_progress := 'WMSINB-23198';
21442 				END IF;
21443 				L_NUM_MSNT_RECS := 0;
21444 				l_tot_msnt_serial_qty := 0;
21445 
21446 				OPEN C_MSNT(L_RTI_ID);
21447 
21448 				LOOP
21449 				   FETCH C_MSNT INTO L_MSNT_REC;
21450 
21451 				   EXIT WHEN C_MSNT%NOTFOUND;
21452 
21453 				   L_NUM_MSNT_RECS := L_NUM_MSNT_RECS + 1;
21454 
21455 				   IF (L_SERIAL_NUMBER_CONTROL_CODE = 6 AND
21456 				       L_SOURCE_DOCUMENT_CODE NOT IN ('RMA','REQ','INVENTORY')) THEN
21457 				      -- RAISE AN ERROR. IF SERIAL IS AT SALES ORDER ISSUE THEN
21458 				      -- IT CAN BE ENTERED ONLY FOR A RMA RECEIPT.
21459 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21460 				      fnd_msg_pub.ADD;
21461 				      l_progress := 'WMSINB-23218';
21462 				      RAISE fnd_api.g_exc_error;
21463 				   END IF;
21464 
21465 				   L_SERIAL_QUANTITY :=
21466 				     INV_SERIAL_NUMBER_PUB.GET_SERIAL_DIFF(L_MSNT_REC.FM_SERIAL_NUMBER,
21467 									   L_MSNT_REC.TO_SERIAL_NUMBER);
21468 
21469 				   l_tot_msnt_serial_qty := l_tot_msnt_serial_qty +
21470 				     l_serial_quantity;
21471 
21472 				   INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.FM_SERIAL_NUMBER, L_TEMP_PREFIX, L_FROM_SER_NUMBER);
21473 		                   INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.TO_SERIAL_NUMBER, L_TEMP_PREFIX, L_TO_SER_NUMBER);
21474 
21475 				   IF (l_debug = 1) THEN
21476 				      print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL QUANTITY: '||l_serial_quantity||' : '||l_progress, 1);
21477 				      l_progress := 'WMSINB-23233';
21478 				   END IF;
21479 
21480 				   --populate attributes table
21481 				   l_serial_attributes_tbl(1).column_name   := 'SERIAL_ATTRIBUTE_CATEGORY';
21482 				   l_serial_attributes_tbl(1).column_value  := l_msnt_rec.serial_attribute_category;
21483 				   l_serial_attributes_tbl(2).column_name   := 'ORIGINATION_DATE';
21484 				   l_serial_attributes_tbl(2).column_value  := l_msnt_rec.origination_date;
21485 				   l_serial_attributes_tbl(3).column_name   := 'C_ATTRIBUTE1';
21486 				   l_serial_attributes_tbl(3).column_value  := l_msnt_rec.c_attribute1;
21487 				   l_serial_attributes_tbl(4).column_name   := 'C_ATTRIBUTE2';
21488 				   l_serial_attributes_tbl(4).column_value  := l_msnt_rec.c_attribute2;
21489 				   l_serial_attributes_tbl(5).column_name   := 'C_ATTRIBUTE3';
21490 				   l_serial_attributes_tbl(5).column_value  := l_msnt_rec.c_attribute3;
21491 				   l_serial_attributes_tbl(6).column_name   := 'C_ATTRIBUTE4';
21492 				   l_serial_attributes_tbl(6).column_value   := l_msnt_rec.c_attribute4;
21493 				   l_serial_attributes_tbl(7).column_name   := 'C_ATTRIBUTE5';
21494 				   l_serial_attributes_tbl(7).column_value   := l_msnt_rec.c_attribute5;
21495 				   l_serial_attributes_tbl(8).column_name   := 'C_ATTRIBUTE6';
21496 				   l_serial_attributes_tbl(8).column_value   := l_msnt_rec.c_attribute6;
21497 				   l_serial_attributes_tbl(9).column_name   := 'C_ATTRIBUTE7';
21498 				   l_serial_attributes_tbl(9).column_value   := l_msnt_rec.c_attribute7;
21499 				   l_serial_attributes_tbl(10).column_name  := 'C_ATTRIBUTE8';
21500 				   l_serial_attributes_tbl(10).column_value  := l_msnt_rec.c_attribute8;
21501 				   l_serial_attributes_tbl(11).column_name  := 'C_ATTRIBUTE9';
21502 				   l_serial_attributes_tbl(11).column_value  := l_msnt_rec.c_attribute9;
21503 				   l_serial_attributes_tbl(12).column_name  := 'C_ATTRIBUTE10';
21504 				   l_serial_attributes_tbl(12).column_value  := l_msnt_rec.c_attribute10;
21505 				   l_serial_attributes_tbl(13).column_name  := 'C_ATTRIBUTE11';
21506 				   l_serial_attributes_tbl(13).column_value  := l_msnt_rec.c_attribute11;
21507 				   l_serial_attributes_tbl(14).column_name  := 'C_ATTRIBUTE12';
21508 				   l_serial_attributes_tbl(14).column_value  := l_msnt_rec.c_attribute12;
21509 				   l_serial_attributes_tbl(15).column_name  := 'C_ATTRIBUTE13';
21510 				   l_serial_attributes_tbl(15).column_value  := l_msnt_rec.c_attribute13;
21511 				   l_serial_attributes_tbl(16).column_name  := 'C_ATTRIBUTE14';
21512 				   l_serial_attributes_tbl(16).column_value  := l_msnt_rec.c_attribute14;
21513 				   l_serial_attributes_tbl(17).column_name  := 'C_ATTRIBUTE15';
21514 				   l_serial_attributes_tbl(17).column_value  := l_msnt_rec.c_attribute15;
21515 				   l_serial_attributes_tbl(18).column_name  := 'C_ATTRIBUTE16';
21516 				   l_serial_attributes_tbl(18).column_value  := l_msnt_rec.c_attribute16;
21517 				   l_serial_attributes_tbl(19).column_name  := 'C_ATTRIBUTE17';
21518 				   l_serial_attributes_tbl(19).column_value  := l_msnt_rec.c_attribute17;
21519 				   l_serial_attributes_tbl(20).column_name  := 'C_ATTRIBUTE18';
21520 				   l_serial_attributes_tbl(20).column_value  := l_msnt_rec.c_attribute18;
21521 				   l_serial_attributes_tbl(21).column_name  := 'C_ATTRIBUTE19';
21522 				   l_serial_attributes_tbl(21).column_value  := l_msnt_rec.c_attribute19;
21523 				   l_serial_attributes_tbl(22).column_name  := 'C_ATTRIBUTE20';
21524 				   l_serial_attributes_tbl(22).column_value  := l_msnt_rec.c_attribute20;
21525 				   l_serial_attributes_tbl(23).column_name  := 'D_ATTRIBUTE1';
21526 				   l_serial_attributes_tbl(23).column_value  := l_msnt_rec.d_attribute1;
21527 				   l_serial_attributes_tbl(24).column_name  := 'D_ATTRIBUTE2';
21528 				   l_serial_attributes_tbl(24).column_value  := l_msnt_rec.d_attribute2;
21529 				   l_serial_attributes_tbl(25).column_name  := 'D_ATTRIBUTE3';
21530 				   l_serial_attributes_tbl(25).column_value  := l_msnt_rec.d_attribute3;
21531 				   l_serial_attributes_tbl(26).column_name  := 'D_ATTRIBUTE4';
21532 				   l_serial_attributes_tbl(26).column_value  := l_msnt_rec.d_attribute4;
21533 				   l_serial_attributes_tbl(27).column_name  := 'D_ATTRIBUTE5';
21534 				   l_serial_attributes_tbl(27).column_value  := l_msnt_rec.d_attribute5;
21535 				   l_serial_attributes_tbl(28).column_name  := 'D_ATTRIBUTE6';
21536 				   l_serial_attributes_tbl(28).column_value  := l_msnt_rec.d_attribute6;
21537 				   l_serial_attributes_tbl(29).column_name  := 'D_ATTRIBUTE7';
21538 				   l_serial_attributes_tbl(29).column_value  := l_msnt_rec.d_attribute7;
21539 				   l_serial_attributes_tbl(30).column_name  := 'D_ATTRIBUTE8';
21540 				   l_serial_attributes_tbl(30).column_value  := l_msnt_rec.d_attribute8;
21541 				   l_serial_attributes_tbl(31).column_name  := 'D_ATTRIBUTE9';
21542 				   l_serial_attributes_tbl(31).column_value  := l_msnt_rec.d_attribute9;
21543 				   l_serial_attributes_tbl(32).column_name  := 'D_ATTRIBUTE10';
21544 				   l_serial_attributes_tbl(32).column_value  := l_msnt_rec.d_attribute10;
21545 				   l_serial_attributes_tbl(33).column_name  := 'N_ATTRIBUTE1';
21546 				   l_serial_attributes_tbl(33).column_value  := l_msnt_rec.n_attribute1;
21547 				   l_serial_attributes_tbl(34).column_name  := 'N_ATTRIBUTE2';
21548 				   l_serial_attributes_tbl(34).column_value  := l_msnt_rec.n_attribute2;
21549 				   l_serial_attributes_tbl(35).column_name  := 'N_ATTRIBUTE3';
21550 				   l_serial_attributes_tbl(35).column_value  := l_msnt_rec.n_attribute3;
21551 				   l_serial_attributes_tbl(36).column_name  := 'N_ATTRIBUTE4';
21552 				   l_serial_attributes_tbl(36).column_value  := l_msnt_rec.n_attribute4;
21553 				   l_serial_attributes_tbl(37).column_name  := 'N_ATTRIBUTE5';
21554 				   l_serial_attributes_tbl(37).column_value := l_msnt_rec.n_attribute5;
21555 				   l_serial_attributes_tbl(38).column_name  := 'N_ATTRIBUTE6';
21556 				   l_serial_attributes_tbl(38).column_value := l_msnt_rec.n_attribute6;
21557 				   l_serial_attributes_tbl(39).column_name  := 'N_ATTRIBUTE7';
21558 				   l_serial_attributes_tbl(39).column_value := l_msnt_rec.n_attribute7;
21559 				   l_serial_attributes_tbl(40).column_name  := 'N_ATTRIBUTE8';
21560 				   l_serial_attributes_tbl(40).column_value := l_msnt_rec.n_attribute8;
21561 				   l_serial_attributes_tbl(41).column_name  := 'N_ATTRIBUTE9';
21562 				   l_serial_attributes_tbl(41).column_value := l_msnt_rec.n_attribute9;
21563 				   l_serial_attributes_tbl(42).column_name  := 'N_ATTRIBUTE10';
21564 				   l_serial_attributes_tbl(42).column_value := l_msnt_rec.n_attribute10;
21565 				   l_serial_attributes_tbl(43).column_name  := 'STATUS_ID';
21566 				   l_serial_attributes_tbl(43).column_value := l_msnt_rec.status_id;
21567 				   l_serial_attributes_tbl(44).column_name  := 'TERRITORY_CODE';
21568 				   l_serial_attributes_tbl(44).column_value := l_msnt_rec.territory_code;
21569 				    l_serial_attributes_tbl(45).column_name   := 'ATTRIBUTE_CATEGORY';
21570 					l_serial_attributes_tbl(45).column_value  := l_msnt_rec.attribute_category;
21571 					l_serial_attributes_tbl(46).column_name   := 'ATTRIBUTE1';
21572 					l_serial_attributes_tbl(46).column_value  := l_msnt_rec.attribute1;
21573 					l_serial_attributes_tbl(47).column_name   := 'ATTRIBUTE2';
21574 					l_serial_attributes_tbl(47).column_value  := l_msnt_rec.attribute2;
21575 					l_serial_attributes_tbl(48).column_name   := 'ATTRIBUTE3';
21576 					l_serial_attributes_tbl(48).column_value  := l_msnt_rec.attribute3;
21577 					l_serial_attributes_tbl(49).column_name   := 'ATTRIBUTE4';
21578 					l_serial_attributes_tbl(49).column_value   := l_msnt_rec.attribute4;
21579 					l_serial_attributes_tbl(50).column_name   := 'ATTRIBUTE5';
21580 					l_serial_attributes_tbl(50).column_value   := l_msnt_rec.attribute5;
21581 					l_serial_attributes_tbl(51).column_name   := 'ATTRIBUTE6';
21582 					l_serial_attributes_tbl(51).column_value   := l_msnt_rec.attribute6;
21583 					l_serial_attributes_tbl(52).column_name   := 'ATTRIBUTE7';
21584 					l_serial_attributes_tbl(52).column_value   := l_msnt_rec.attribute7;
21585 					l_serial_attributes_tbl(53).column_name  := 'ATTRIBUTE8';
21586 					l_serial_attributes_tbl(53).column_value  := l_msnt_rec.attribute8;
21587 					l_serial_attributes_tbl(54).column_name  := 'ATTRIBUTE9';
21588 					l_serial_attributes_tbl(54).column_value  := l_msnt_rec.attribute9;
21589 					l_serial_attributes_tbl(55).column_name  := 'ATTRIBUTE10';
21590 					l_serial_attributes_tbl(55).column_value  := l_msnt_rec.attribute10;
21591 					l_serial_attributes_tbl(56).column_name  := 'ATTRIBUTE11';
21592 					l_serial_attributes_tbl(56).column_value  := l_msnt_rec.attribute11;
21593 					l_serial_attributes_tbl(57).column_name  := 'ATTRIBUTE12';
21594 					l_serial_attributes_tbl(57).column_value  := l_msnt_rec.attribute12;
21595 					l_serial_attributes_tbl(58).column_name  := 'ATTRIBUTE13';
21596 					l_serial_attributes_tbl(58).column_value  := l_msnt_rec.attribute13;
21597 					l_serial_attributes_tbl(59).column_name  := 'ATTRIBUTE14';
21598 					l_serial_attributes_tbl(59).column_value  := l_msnt_rec.attribute14;
21599 					l_serial_attributes_tbl(60).column_name  := 'ATTRIBUTE15';
21600 					l_serial_attributes_tbl(60).column_value  := l_msnt_rec.attribute15;
21601 
21602 				   --Validate the serials
21603 				   FOR SERIALQTY IN 1..L_SERIAL_QUANTITY LOOP
21604                                     L_CUR_NUMBER := L_FROM_SER_NUMBER+SERIALQTY -1;
21605                                     if L_FROM_SER_NUMBER = -1 and  L_TO_SER_NUMBER = -1 then
21606 	                                 L_SERIAL_NUMBER  := L_MSNT_REC.fm_serial_number;
21607 		                    else
21608 		                         L_SERIAL_NUMBER :=
21609 			                   SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
21610 				             LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
21611 				             LENGTH(L_CUR_NUMBER))
21612 			                   ||L_CUR_NUMBER;
21613                                     End if;
21614 
21615 				      --L_SERIAL_NUMBER :=
21616 					--SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
21617 					 --      LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
21618 					  --     LENGTH(L_FROM_SER_NUMBER))
21619 					--||(L_FROM_SER_NUMBER+SERIALQTY -1);
21620 
21621 	                              BEGIN
21622 					 SELECT CURRENT_ORGANIZATION_ID
21623 					   , current_status
21624 					   , lot_number
21625 					   , Decode(lpn_id,0,NULL,lpn_id)
21626 					   , inspection_status
21627 					   , group_mark_id
21628 					   , last_transaction_id --bug 5168883
21629 					   INTO L_CURR_ORG_ID
21630 					   , l_curr_status
21631 					   , l_curr_lot_num
21632 					   , l_curr_lpn_id
21633 					   , l_inspection_status
21634 					   , l_group_mark_id
21635 					   , l_last_transaction_id --bug 5168883
21636 					   FROM MTL_SERIAL_NUMBERS
21637 					   WHERE SERIAL_NUMBER = l_serial_number
21638 					   AND inventory_item_id = l_item_id;
21639 
21640 					 l_serial_exists := 1;
21641 				      EXCEPTION
21642 					 WHEN no_data_found THEN
21643 					    l_serial_exists := 0;
21644 				      END;
21645 
21646 				      IF (l_debug = 1) THEN
21647 					 print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL EXISTS: '||l_serial_exists||' : '||l_progress, 1);
21648 					 print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NUMBER: '||l_serial_number||' : '||l_progress, 1);
21649 					 print_debug('VALIDATE_LOT_SERIAL_INFO: CURR STATUS: '||l_curr_status||' : '||l_progress, 1);
21650 					 print_debug('VALIDATE_LOT_SERIAL_INFO: CURR ORG ID: '||l_curr_org_id||' : '||l_progress, 1);
21651 					 print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LPN ID: '||l_curr_lpn_id||' : '||l_progress, 1);
21652 					 print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LOT NUM: '||l_curr_lot_num||' : '||l_progress, 1);
21653 					 print_debug('VALIDATE_LOT_SERIAL_INFO: INSPECT STS: '||l_inspection_status||' : '||l_progress, 1);
21654 					 print_debug('VALIDATE_LOT_SERIAL_INFO: GROUP MARK ID: '||l_group_mark_id||' : '||l_progress, 1);
21655 					 print_debug('VALIDATE_LOT_SERIAL_INFO: RESTRICT RCPT SER: '||l_restrict_rcpt_ser||' : '||l_progress, 1);
21656 					 l_progress := 'WMSINB-23276';
21657 				      END IF;
21658 
21659 				      IF (L_TRANSACTION_TYPE <> 'RECEIVE') THEN
21660 					 L_SERIAL_ENTERED_ON_PARENT := SERIAL_ENTERED_ON_PARENT(L_PARENT_TRANSACTION_ID);
21661 				       ELSE
21662 					 L_SERIAL_ENTERED_ON_PARENT := FALSE;
21663 				      END IF;
21664 
21665 				      IF (l_debug = 1) THEN
21666 					 print_debug('VALIDATE_LOT_SERIAL_INFO: ASN LINE FLAG: '||l_asn_line_flag||' : '||l_progress, 1);
21667 					 l_progress := 'WMSINB-23287';
21668 				      END IF;
21669 
21670 				      IF NOT L_SERIAL_ENTERED_ON_PARENT THEN
21671 					 IF (l_debug = 1) THEN
21672 					    print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NOT ENTERED ON PARENT: '||l_progress, 1);
21673 					    l_progress := 'WMSINB-23293';
21674 					 END IF;
21675 					 IF (l_serial_number_control_code IN (2,5)
21676 					     OR (l_serial_number_control_code = 6
21677 						 AND l_source_document_code IN ('INVENTORY','REQ'))) THEN
21678 					    IF l_serial_exists = 1 THEN
21679 					       IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')
21680 						   OR l_asn_line_flag = 'Y') THEN
21681 
21682 						  IF (l_asn_line_flag = 'Y') THEN
21683 						     IF ((l_curr_org_id <> l_org_id) and not (l_restrict_rcpt_ser = '2'
21684 											      and l_curr_status = 4 ))  THEN
21685 							--raise error
21686 							l_progress := 'WMSINB-23303';
21687 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21688 							fnd_msg_pub.ADD;
21689 							l_progress := 'WMSINB-23306';
21690 							RAISE fnd_api.g_exc_error;
21691 						      ELSE
21692 							IF (l_curr_lot_num IS NOT NULL) THEN
21693 							   --raise error
21694 							   l_progress := 'WMSINB-23311';
21695 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21696 							   fnd_msg_pub.ADD;
21697 							   l_progress := 'WMSINB-23314';
21698 							   RAISE fnd_api.g_exc_error;
21699 							END IF;
21700 						     END IF;
21701 
21702 						     IF (rss_exists(l_shipment_header_id,l_item_id)) THEN
21703 			                                BEGIN
21704 							   SELECT '1'
21705 							     INTO l_dummy
21706 							     FROM rcv_serials_supply rss
21707 							     , rcv_shipment_lines rsl
21708 							     WHERE rss.SHIPMENT_LINE_ID = rsl.SHIPMENT_LINE_ID
21709 							     AND rsl.shipment_header_id = l_shipment_header_id
21710 							     AND rsl.item_id = l_item_id
21711 							     AND rss.supply_type_code = 'SHIPMENT'
21712 							     AND rss.serial_num = l_serial_number;
21713 
21714 							   IF (l_debug = 1) THEN
21715 							      print_debug('VALIDATE_LOT_SERIAL_INFO: RSS EXISTS: '||l_progress, 1);
21716 							      l_progress := 'WMSINB-23330';
21717 							   END IF;
21718 
21719 							   IF l_curr_status <> 5 THEN
21720 							      --raise error
21721 							      l_progress := 'WMSINB-23335';
21722 							      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21723 							      fnd_msg_pub.ADD;
21724 							      RAISE fnd_api.g_exc_error;
21725 							   END IF;
21726 							EXCEPTION
21727 							   WHEN no_data_found THEN
21728 							      IF l_restrict_rcpt_ser = '2' THEN
21729 								 IF l_curr_status NOT IN
21730 								   (1,4,6) THEN
21731 								    --raise error
21732 								    l_progress := 'WMSINB-23346';
21733 								    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21734 								    fnd_msg_pub.ADD;
21735 								    RAISE fnd_api.g_exc_error;
21736 								 END IF;
21737 							       ELSE --IF l_restrict_rcpt_ser = '2' THEN
21738 								 IF l_curr_status NOT IN
21739 								   (1,6) THEN
21740 								    --raise error
21741 								    l_progress := 'WMSINB-23355';
21742 								    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21743 								    fnd_msg_pub.ADD;
21744 								    RAISE fnd_api.g_exc_error;
21745 								 END IF;
21746 							      END IF; --IF l_restrict_rcpt_ser = '2' THEN
21747 							END;
21748 						      ELSE --IF (rss_exists(l_shipment_header_id,l_item_id)) THEN
21749 							      IF l_restrict_rcpt_ser = '2' THEN
21750 								 IF l_curr_status NOT IN
21751 								   (1,4,6) THEN
21752 								    --raise error
21753 								    l_progress := 'WMSINB-23367';
21754 								    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21755 								    fnd_msg_pub.ADD;
21756 								    RAISE fnd_api.g_exc_error;
21757 								 END IF;
21758 							       ELSE --IF l_restrict_rcpt_ser = '2' THEN
21759 								 IF l_curr_status NOT IN
21760 								   (1,6) THEN
21761 								    --raise error
21762 								    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21763 								    fnd_msg_pub.ADD;
21764 								    l_progress := 'WMSINB-23378';
21765 								    RAISE fnd_api.g_exc_error;
21766 								 END IF;
21767 							      END IF; --IF l_restrict_rcpt_ser = '2' THEN
21768 						     END IF; --IF (rss_exists(l_shipment_header_id,l_item_id)) THEN
21769 						  END IF; --IF (l_asn_line_flag = 'Y') THEN
21770 
21771 						  IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
21772 						     -- CHECK TO SEE IF THE ITEM IS SERIAL
21773 						     -- CONTROLLED IN SOURCE ORG
21774 
21775 						     GET_SERIAL_LOT_CTRL_IN_SRC_ORG
21776 						       (L_SHIPMENT_LINE_ID, L_ORG_ID,
21777 							L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
21778 							l_from_org_rev_ctrl, X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
21779 
21780 						     IF ((L_FROM_ORG_SER_CRTL IN (2,5,6)
21781 							  AND l_source_document_code = 'REQ')
21782 							 OR (l_from_org_ser_crtl IN (2,5)
21783 							     AND l_source_document_code = 'INVENTORY')
21784 							 ) THEN
21785 
21786                                                         /*****bug4187663, comment out the call to serial uniqueness check, the check will be in TM
21787 							IF (l_source_document_code = 'REQ') THEN
21788 							   l_txn_src_type_id := 7;
21789 							 ELSE
21790 							   l_txn_src_type_id := 13;
21791 							END IF;
21792 
21793 							--Validate Serial Uniqueness in current org.
21794 							IF (l_debug = 1) THEN
21795 							   print_debug('VALIDATE_LOT_SERIAL_INFO: CALLING IS_SERNUM_UNIQUE...', 1);
21796 							END IF;
21797 
21798 							IF (is_sernum_unique(l_org_id, l_item_id,l_serial_number,l_txn_src_type_id,12,x_msg_data)<>0) THEN
21799 							   --raise error
21800 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21801 							   fnd_msg_pub.ADD;
21802 							   l_progress := 'WMSINB-22725';
21803 							   RAISE fnd_api.g_exc_error;
21804 							END IF;
21805 
21806 							IF (l_debug = 1) THEN
21807 							   print_debug('VALIDATE_LOT_SERIAL_INFO: CALLING IS_SERNUM_UNIQUE...DONE', 1);
21808 							END IF;
21809                                                         *****end of bug4187663*****/
21810 
21811 							IF l_curr_org_id <> l_from_org_id THEN
21812 							   --raise error
21813 							   l_progress := 'WMSINB-23397';
21814 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21815 							   fnd_msg_pub.ADD;
21816 							   RAISE fnd_api.g_exc_error;
21817 							 ELSE
21818 							   IF (l_curr_lot_num IS NOT NULL) THEN
21819 
21820                            if (L_FROM_ORG_LOT_CTRL = 1 ) then
21821 							      --raise error
21822 							         l_progress := 'WMSINB-23404';
21823 							         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21824 							         fnd_msg_pub.ADD;
21825 							         RAISE fnd_api.g_exc_error;
21826                            else
21827 							         --update the serial row
21828 							         IF (l_debug = 1) THEN
21829 							            print_debug('VALIDATE_LOT_SERIAL_INFO: UPDATING LOT_NUMBER to null as destination org is not lot controlled', 1);
21830 							         END IF;
21831                                                                  update mtl_serial_numbers msn
21832                                                                     set lot_number = null
21833                                                                   where msn.serial_number = l_serial_number
21834                                                                     AND inventory_item_id = l_item_id;
21835                                                               end if;
21836 							   END IF;
21837 							END IF;
21838 
21839 			                                BEGIN
21840 							   SELECT '1'
21841 							     INTO L_DUMMY
21842 							     FROM rcv_serials_supply rss
21843 							     , rcv_shipment_lines rsl
21844 							     WHERE rss.SHIPMENT_LINE_ID = rsl.SHIPMENT_LINE_ID
21845 							     AND rsl.shipment_header_id = l_shipment_header_id
21846 							     AND rsl.item_id = l_item_id
21847 							     AND rss.SUPPLY_TYPE_CODE = 'SHIPMENT'
21848 							     AND rss.serial_num = l_serial_number;
21849 
21850 							   IF L_CURR_STATUS <> 5 THEN
21851 							      -- RAISE AN ERROR
21852 							      l_progress := 'WMSINB-23421';
21853 							      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21854 							      fnd_msg_pub.ADD;
21855 							      RAISE fnd_api.g_exc_error;
21856 							   END IF;
21857 
21858 							EXCEPTION
21859 							   WHEN NO_DATA_FOUND THEN
21860 							      -- RAISE AN ERROR
21861 							      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21862 							      fnd_msg_pub.ADD;
21863 							      l_progress := 'WMSINB-23432';
21864 							      RAISE fnd_api.g_exc_error;
21865 							END;
21866 						      ELSE --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
21867 							      IF L_CURR_ORG_ID <> l_org_id THEN
21868                       --BUG 5524134
21869                       /* In case of serial numbers in status 4
21870                       i.e. issued out of stores, we need to
21871                       honor the INV_RESTRICT_RCPT_SER profile.
21872                       And for serial status defined but not used
21873                       error out only if the org id in MSN is equal to
21874                       that present in the RSL.
21875                       */
21876                       BEGIN
21877                            SELECT from_organization_id
21878                            INTO l_from_org_id
21879                            FROM rcv_shipment_lines
21880                            WHERE shipment_line_id = L_SHIPMENT_LINE_ID;
21881                       EXCEPTION
21882                         WHEN NO_DATA_FOUND THEN
21883                         -- RAISE AN ERROR
21884                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21885                         fnd_msg_pub.ADD;
21886                         l_progress := 'WMSINB-23433';
21887                         RAISE fnd_api.g_exc_error;
21888                       END;
21889                       --BEGIN Bug: 5524134
21890                       IF L_SOURCE_DOCUMENT_CODE IN ( 'INVENTORY' , 'REQ' ) THEN
21891                          IF NOT (
21892                                  ( L_CURR_STATUS = 1 AND L_CURR_ORG_ID = l_from_org_id)
21893                               OR ( L_CURR_STATUS = 4 AND l_restrict_rcpt_ser = '2' )
21894                                 )
21895                                THEN
21896                                l_progress := 'WMSINB-23435';
21897                                IF (l_debug = 1) THEN
21898                                     print_debug('For Intransit receipt the serial number org does not match the sending org!', 1);
21899                                END IF;
21900         								 --raise error
21901         								 l_progress := 'WMSINB-23438';
21902         								 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21903         								 fnd_msg_pub.ADD;
21904         								 RAISE fnd_api.g_exc_error;
21905                          END IF;
21906                      ELSE
21907                          l_progress := 'WMSINB-23438';
21908                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21909                          fnd_msg_pub.ADD;
21910                          RAISE fnd_api.g_exc_error;
21911                      END IF;
21912                      --END Bug: 5524134
21913 							       ELSE
21914 								 IF (l_curr_lot_num IS NOT NULL) THEN
21915 								    --raise error
21916 								    l_progress := 'WMSINB-23445';
21917 								    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21918 								    fnd_msg_pub.ADD;
21919 								    RAISE fnd_api.g_exc_error;
21920 								 END IF;
21921 							      END IF;
21922 
21923 							      IF L_CURR_STATUS NOT IN (1,6)
21924                        AND NOT (l_restrict_rcpt_ser = '2'and l_curr_status = 4 ) --Bug: 5524134
21925                        THEN
21926 								 -- RAISE AN ERROR
21927 								 l_progress := 'WMSINB-23454';
21928 								 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21929 								 fnd_msg_pub.ADD;
21930 								 RAISE fnd_api.g_exc_error;
21931 							      END IF;
21932 						     END IF; --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
21933 						  END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
21934 						ELSE  --IF (L_SOURCE_DOCUMENT_CODE IN
21935 						     --('INVENTORY','REQ') OR l_asn_line_flag = 'Y') THEN
21936 						     IF ((L_SOURCE_DOCUMENT_CODE <> 'RMA' AND l_curr_org_id <> l_org_id )
21937                            and not (l_restrict_rcpt_ser = '2'and l_curr_status = 4 ) )  THEN
21938 							--raise error
21939 							l_progress := 'WMSINB-23465';
21940 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21941 							fnd_msg_pub.ADD;
21942 							RAISE fnd_api.g_exc_error;
21943 
21944                                                       --BUG 5114851 (FP of BUG 5060131):
21945                                                       --For RMA, the item for the original org of
21946                                                       --the serial number may be lot serial controlled, while
21947                                                       --the receiving org is not lot controlled.  So bypass
21948                                                       --the lot check for RMA
21949 						      --ELSIF (l_source_document_code <> 'RMA') THEN
21950                                                       -- bug 5259803
21951                                                       ELSIF ((l_source_document_code <> 'RMA')
21952                                                        AND NOT (l_source_document_code = 'PO' AND l_restrict_rcpt_ser = '2' AND l_curr_status = 4 )) THEN
21953 							IF (l_curr_lot_num IS NOT NULL) THEN
21954 							   --raise error
21955 							   l_progress := 'WMSINB-23472';
21956 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21957 							   fnd_msg_pub.ADD;
21958 							   RAISE fnd_api.g_exc_error;
21959 							END IF;
21960 						     END IF;
21961 
21962 						     --bug 5168883
21963 						     BEGIN
21964 						       select transaction_type_id
21965 						       into   l_last_transaction_type_id
21966 						       from   mtl_material_transactions
21967 						       where  transaction_id = l_last_transaction_id;
21968 						     EXCEPTION
21969 						       when others then
21970 						         l_last_transaction_type_id := null;
21971 						     END;
21972 						     -- end bug 5168883
21973 
21974 						     IF l_restrict_rcpt_ser = '2' THEN
21975 							IF l_curr_status NOT IN (1,4,6) THEN
21976 							   --raise error
21977 							   l_progress := 'WMSINB-23482';
21978 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21979 							   fnd_msg_pub.ADD;
21980 							   RAISE fnd_api.g_exc_error;
21981 							END IF;
21982 
21983    /* Bug 6847337:
21984     * Fix done to allow the re-using of serials after the
21985     * correction of a PO receipt by handling the transaction type
21986     * for correction(71) along with return to vendor(36) in
21987     * the following ELSE condition.
21988     */
21989 						      ELSE --IF l_restrict_rcpt_ser = '2' THEN
21990 							IF ((l_curr_status NOT IN (1,6))
21991 							    AND NOT (l_curr_status = 4 and
21992 								     (l_source_document_code = 'RMA'
21993 								      OR (l_source_document_code = 'PO'
21994 								          and l_last_transaction_type_id in(36,71))))) THEN --bug 5168883
21995 							   --raise error
21996 							   l_progress := 'WMSINB-23490';
21997 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
21998 							   fnd_msg_pub.ADD;
21999 							   RAISE fnd_api.g_exc_error;
22000 							END IF;
22001 						     END IF; --IF l_restrict_rcpt_ser = '2' THEN
22002 
22003 					       END IF; --IF (L_SOURCE_DOCUMENT_CODE IN
22004 					       --('INVENTORY','REQ') OR l_asn_line_flag = 'Y') THEN
22005 
22006 					       --Validate serial/LPN
22007 					       IF l_transaction_type = 'RECEIVE' THEN
22008 						  IF (l_source_document_code IN ('INVENTORY', 'REQ')) then
22009 						     IF (Nvl(l_curr_lpn_id, -9999) <>
22010 							 Nvl(l_lpn_id, -9999)
22011 							 AND
22012 							  ( Nvl(l_curr_status,1) NOT IN (1,5,6)
22013 							    AND NOT (l_restrict_rcpt_ser = '2'and l_curr_status = 4 ) --Bug 5524134 --Bug 14596053 --14057324
22014 					      )
22015                ) THEN --bug 5235808 changed from 4 to 5
22016 							--raise error
22017 							l_progress := 'WMSINB-23506';
22018 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22019 							fnd_msg_pub.ADD;
22020 							RAISE fnd_api.g_exc_error;
22021 						     END IF;
22022 						  END IF;
22023 						ELSE
22024 						  IF (Nvl(l_curr_lpn_id, -9999) <>
22025 						      Nvl(l_lpn_id, -9999)
22026 						      AND Nvl(l_curr_status,1) <> 4) THEN
22027 						     --raise error
22028 						     l_progress := 'WMSINB-23516';
22029 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22030 						     fnd_msg_pub.ADD;
22031 						     RAISE fnd_api.g_exc_error;
22032 						  END IF;
22033 					       END IF;
22034 
22035 					       --Validate Serial/Inspection_status
22036                            /*  Commented for bug 6269102
22037                           *  To allow the inspection done again
22038                 	  *  on an inspection transaction to succeed
22039 		          *  as it was failing because of the
22040         		  *  inspection status <> 1
22041 
22042 					       IF l_transaction_type IN ('ACCEPT', 'REJECT') THEN
22043 						  IF (Nvl(l_inspection_status, 1) <> 1) THEN
22044 						     --raise error
22045 						     l_progress := 'WMSINB-23527';
22046 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22047 						     fnd_msg_pub.ADD;
22048 						     RAISE fnd_api.g_exc_error;
22049 						  END IF;
22050 						ELS */
22051                                                 -- Bug 9569977: Commenting following since l_serial_entered_on_parent
22052                                                 --              is false
22053 						/*IF l_transaction_type = 'DELIVER' THEN
22054 						  IF (l_routing_header_id = 2) THEN
22055 						     IF l_inspection_status IS NOT NULL AND l_inspection_status = 1 THEN
22056 						       --raise error
22057 							l_progress := 'WMSINB-23536';
22058 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22059 							fnd_msg_pub.ADD;
22060 							RAISE fnd_api.g_exc_error;
22061 						     END IF;
22062 						  END IF;
22063 					       END IF;*/
22064 
22065 					       --Validate serial/group_mark_id to prevent
22066 					       --entering of duplicate serials
22067 
22068 					       IF (Nvl(l_group_mark_id, -99) = -7937) THEN
22069 						  --raise error
22070 						  l_progress := 'WMSINB-23549';
22071 						  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22072 						  fnd_msg_pub.ADD;
22073 						  RAISE fnd_api.g_exc_error;
22074 					       END IF;
22075 
22076 					       IF (Nvl(l_curr_status, 1) in (1,6)) THEN
22077 						  --validate and update the attributes.
22078 						  inv_serial_number_pub.validate_update_serial_att
22079 						    (x_return_status     => x_return_status,
22080 						     x_msg_count         => x_msg_count,
22081 						     x_msg_data          => x_msg_data,
22082 						     x_validation_status => l_validation_status,
22083 						     p_serial_number     => l_serial_number,
22084 						     p_organization_id   => l_org_id,
22085 						     p_inventory_item_id => l_item_id,
22086 						     p_serial_att_tbl    => l_serial_attributes_tbl,
22087 						     p_validate_only     => FALSE
22088 						     );
22089 
22090 						  IF (l_validation_status <> 'Y'
22091 						      OR x_return_status <> g_ret_sts_success) THEN
22092 						     --raise error
22093 						     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22094 						     fnd_msg_pub.ADD;
22095 						     l_progress := 'WMSINB-22555';
22096 						     RAISE fnd_api.g_exc_error;
22097 						  END IF;
22098 					       END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
22099 
22100 					       --UPDATE GROUP_MARK_ID TO -7937
22101 					       IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
22102 						  --raise error
22103 						  l_progress := 'WMSINB-23558';
22104 						  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22105 						  fnd_msg_pub.ADD;
22106 						  RAISE fnd_api.g_exc_error;
22107 					       END IF;
22108 
22109 					     ELSE --IF l_serial_exists = 1 THEN
22110 						     IF (l_source_document_code IN ('INVENTORY','REQ')) THEN
22111 							GET_SERIAL_LOT_CTRL_IN_SRC_ORG
22112 							  (L_SHIPMENT_LINE_ID, L_ORG_ID,
22113 							   L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
22114 							   l_from_org_rev_ctrl, X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
22115 
22116 							IF ((L_FROM_ORG_SER_CRTL IN (2,5,6)
22117 							     AND l_source_document_code = 'REQ')
22118 							    OR (l_from_org_ser_crtl IN (2,5)
22119 								AND l_source_document_code = 'INVENTORY')
22120 							    ) THEN
22121 							   --raise error
22122 							   l_progress := 'WMSINB-23573';
22123 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22124 							   fnd_msg_pub.ADD;
22125 							   RAISE fnd_api.g_exc_error;
22126 							END IF;
22127 						     END IF;
22128 
22129 						     IF l_serial_number_control_code = 5 THEN
22130 							--PERFORM SERIAL VALIDATION FOR NEW SERIAL
22131 							--(INCLUDING ATT VALIDATION)
22132 							--CREATE MSN
22133 
22134 							inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
22135 												  , p_inventory_item_id => l_item_id
22136 												  , p_organization_id => l_org_id
22137 												  , p_from_serial_number => l_serial_number
22138 												  , p_to_serial_number => l_serial_number
22139 												  , p_initialization_date => SYSDATE
22140 												  , p_completion_date => NULL
22141 												  , p_ship_date => NULL
22142 												  , p_revision => l_item_revision
22143 												  , p_lot_number => NULL
22144 												  , p_current_locator_id => l_loc_id
22145 												  , p_subinventory_code => l_sub_code
22146 												  , p_trx_src_id => NULL
22147 												  , p_unit_vendor_id => NULL
22148 												  , p_vendor_lot_number => NULL
22149 												  , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
22150 												  , p_receipt_issue_type => NULL
22151 												  , p_txn_src_id => NULL
22152 												  , p_txn_src_name => NULL
22153 												  , p_txn_src_type_id => NULL
22154 												  , p_transaction_id => NULL
22155 												  , p_current_status => 1
22156 												  , p_parent_item_id => NULL
22157 							  , p_parent_serial_number => NULL
22158 							  , p_cost_group_id => NULL
22159 							  , p_transaction_action_id => 27
22160 							  , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
22161 							  , p_status_id => NULL
22162 							  , p_inspection_status => NULL
22163 							  , x_object_id => l_object_id
22164 							  , x_return_status => x_return_status
22165 							  , x_msg_count => x_msg_count
22166 							  , x_msg_data => x_msg_data);
22167 
22168 							IF (x_return_status <> g_ret_sts_success) THEN
22169 							   --raise error
22170 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22171 							   fnd_msg_pub.ADD;
22172 							   l_progress := 'WMSINB-23580';
22173 							   RAISE fnd_api.g_exc_error;
22174 							END IF;
22175 
22176 							--validate and update the attributes.
22177 							inv_serial_number_pub.validate_update_serial_att
22178 							  (x_return_status     => x_return_status,
22179 							   x_msg_count         => x_msg_count,
22180 							   x_msg_data          => x_msg_data,
22181 							   x_validation_status => l_validation_status,
22182 							   p_serial_number     => l_serial_number,
22183 							   p_organization_id   => l_org_id,
22184 							   p_inventory_item_id => l_item_id,
22185 							   p_serial_att_tbl    => l_serial_attributes_tbl,
22186 							   p_validate_only     => FALSE
22187 							   );
22188 
22189 							IF (l_validation_status <> 'Y'
22190 							    OR x_return_status <> g_ret_sts_success) THEN
22191 							   --raise error
22192 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22193 							   fnd_msg_pub.ADD;
22194 							   l_progress := 'WMSINB-23615';
22195 							   RAISE fnd_api.g_exc_error;
22196 							END IF;
22197 
22198 
22199 							--UPDATE GROUP_MARK_ID TO -7937
22200 							IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
22201 							   --raise error
22202 							   l_progress := 'WMSINB-23622';
22203 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22204 							   fnd_msg_pub.ADD;
22205 							   RAISE fnd_api.g_exc_error;
22206 							END IF;
22207 						      ELSE
22208 							--raise error
22209 							l_progress := 'WMSINB-23629';
22210 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22211 							fnd_msg_pub.ADD;
22212 							RAISE fnd_api.g_exc_error;
22213 						     END IF;
22214 					    END IF; --IF l_serial_exists = 1 THEN
22215 					  ELSIF (l_serial_number_control_code = 6 AND
22216 						 l_source_document_code = 'RMA') THEN
22217 						  IF l_serial_exists = 1 THEN
22218                        --bug#3571808 removed the current_org_id check
22219                        /*
22220 						     IF ((l_curr_org_id <> l_org_id) and not (l_restrict_rcpt_ser = '2'
22221 											      and l_curr_status = 4 ))  THEN
22222 							--raise error
22223 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22224 							fnd_msg_pub.ADD;
22225 							l_progress := 'WMSINB-23642';
22226 							RAISE fnd_api.g_exc_error;
22227 						      ELSE*/
22228 							IF (l_curr_lot_num IS NOT NULL
22229                          AND (Nvl(l_curr_status,1) NOT IN (1,4) )) THEN
22230 							   --raise error
22231 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22232 							   fnd_msg_pub.ADD;
22233 							   l_progress := 'WMSINB-23649';
22234 							   RAISE fnd_api.g_exc_error;
22235 							END IF;
22236 						     --END IF;
22237 
22238 						     IF l_curr_status NOT IN (1,4,6) THEN
22239 							--raise error
22240 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22241 							fnd_msg_pub.ADD;
22242 							l_progress := 'WMSINB-23658';
22243 							RAISE fnd_api.g_exc_error;
22244 						     END IF;
22245 
22246 						     -- see if we need to restrict 4's based on
22247 						     -- inv_restrict_rcpt profile
22248 						     -- REVIEW at CODE REVIEW
22249 						     IF l_restrict_rcpt_ser <> 2 THEN
22250 							l_dummy := '0';
22251 			                                BEGIN
22252 							   SELECT '1'
22253 							     INTO l_dummy
22254 							     FROM dual
22255 							     WHERE exists (SELECT '1'
22256 									   FROM   mtl_serial_numbers
22257 									   WHERE  inventory_item_id = l_item_id
22258 									   AND    current_organization_id = l_org_id
22259 									   AND    current_status IN (1, 4) --Do we need 4 here
22260 									   AND    serial_number = l_serial_number
22261 									   AND    LAST_TXN_SOURCE_TYPE_ID = 12);
22262 
22263 							   IF l_dummy <> '0' THEN
22264 							      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22265 							      fnd_msg_pub.ADD;
22266 							      l_progress := 'WMSINB-23682';
22267 							      RAISE fnd_api.g_exc_error;
22268 							   END IF;
22269 
22270 							EXCEPTION
22271 							   WHEN no_data_found THEN
22272 							      NULL;
22273 							END;
22274 						     END IF;
22275 
22276 						     IF (Nvl(l_group_mark_id, -99) = -7937) THEN
22277 							--raise error
22278 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22279 							fnd_msg_pub.ADD;
22280 							l_progress := 'WMSINB-23696';
22281 							RAISE fnd_api.g_exc_error;
22282 						     END IF;
22283 
22284 						     IF (Nvl(l_curr_status, 1) in (1,6)) THEN
22285 							--validate and update the attributes.
22286 							inv_serial_number_pub.validate_update_serial_att
22287 							  (x_return_status     => x_return_status,
22288 							   x_msg_count         => x_msg_count,
22289 							   x_msg_data          => x_msg_data,
22290 							   x_validation_status => l_validation_status,
22291 							   p_serial_number     => l_serial_number,
22292 							   p_organization_id   => l_org_id,
22293 							   p_inventory_item_id => l_item_id,
22294 							   p_serial_att_tbl    => l_serial_attributes_tbl,
22295 							   p_validate_only     => FALSE
22296 							   );
22297 
22298 							IF (l_validation_status <> 'Y'
22299 							    OR x_return_status <> g_ret_sts_success) THEN
22300 							   --raise error
22301 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22302 							   fnd_msg_pub.ADD;
22303 							   l_progress := 'WMSINB-23702';
22304 							   RAISE fnd_api.g_exc_error;
22305 							END IF;
22306 						     END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
22307 
22308 						     --UPDATE GROUP_MARK_ID TO -7937
22309 						     IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
22310 							--raise error
22311 							fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22312 							fnd_msg_pub.ADD;
22313 							l_progress := 'WMSINB-23705';
22314 							RAISE fnd_api.g_exc_error;
22315 						     END IF;
22316 						   ELSE --IF l_serial_exists = 1 THEN
22317 							--PERFORM SERIAL VALIDATION FOR NEW SERIAL
22318 							--(INCLUDING ATT VALIDATION)
22319 							--CREATE MSN
22320 
22321 							inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
22322 												  , p_inventory_item_id => l_item_id
22323 												  , p_organization_id => l_org_id
22324 												  , p_from_serial_number => l_serial_number
22325 												  , p_to_serial_number => l_serial_number
22326 												  , p_initialization_date => SYSDATE
22327 												  , p_completion_date => NULL
22328 												  , p_ship_date => NULL
22329 												  , p_revision => l_item_revision
22330 												  , p_lot_number => NULL
22331 												  , p_current_locator_id => l_loc_id
22332 												  , p_subinventory_code => l_sub_code
22333 												  , p_trx_src_id => NULL
22334 												  , p_unit_vendor_id => NULL
22335 												  , p_vendor_lot_number => NULL
22336 												  , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
22337 												  , p_receipt_issue_type => NULL
22338 												  , p_txn_src_id => NULL
22339 												  , p_txn_src_name => NULL
22340 												  , p_txn_src_type_id => NULL
22341 												  , p_transaction_id => NULL
22342 												  , p_current_status => 1
22343 												  , p_parent_item_id => NULL
22344 							  , p_parent_serial_number => NULL
22345 							  , p_cost_group_id => NULL
22346 							  , p_transaction_action_id => 27
22347 							  , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
22348 							  , p_status_id => NULL
22349 							  , p_inspection_status => NULL
22350 							  , x_object_id => l_object_id
22351 							  , x_return_status => x_return_status
22352 							  , x_msg_count => x_msg_count
22353 							  , x_msg_data => x_msg_data);
22354 
22355 							IF (x_return_status <> g_ret_sts_success) THEN
22356 							   --raise error
22357 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22358 							   fnd_msg_pub.ADD;
22359 							   l_progress := 'WMSINB-23710';
22360 							   RAISE fnd_api.g_exc_error;
22361 							END IF;
22362 
22363 							--validate and update the attributes.
22364 							inv_serial_number_pub.validate_update_serial_att
22365 							  (x_return_status     => x_return_status,
22366 							   x_msg_count         => x_msg_count,
22367 							   x_msg_data          => x_msg_data,
22368 							   x_validation_status => l_validation_status,
22369 							   p_serial_number     => l_serial_number,
22370 							   p_organization_id   => l_org_id,
22371 							   p_inventory_item_id => l_item_id,
22372 							   p_serial_att_tbl    => l_serial_attributes_tbl,
22373 							   p_validate_only     => FALSE
22374 							   );
22375 
22376 							IF (l_validation_status <> 'Y'
22377 							    OR x_return_status <> g_ret_sts_success) THEN
22378 							   --raise error
22379 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22380 							   fnd_msg_pub.ADD;
22381 							   l_progress := 'WMSINB-23745';
22382 							   RAISE fnd_api.g_exc_error;
22383 							END IF;
22384 
22385 							--UPDATE GROUP_MARK_ID TO -7937
22386 							IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
22387 							   --raise error
22388 							   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22389 							   fnd_msg_pub.ADD;
22390 							   l_progress := 'WMSINB-23752';
22391 							   RAISE fnd_api.g_exc_error;
22392 							END IF;
22393 						  END IF; --IF l_serial_exists = 1 THEN
22394 					 END IF; --IF l_serial_number_control_code IN (2,5) THEN
22395 				       ELSE --IF NOT L_SERIAL_ENTERED_ON_PARENT THEN
22396 		                          BEGIN
22397 					     SELECT '1'
22398 					       INTO L_DUMMY
22399 					       FROM RCV_SERIALS_SUPPLY
22400 					       WHERE TRANSACTION_ID = L_PARENT_TRANSACTION_ID
22401 					       AND SERIAL_NUM = L_SERIAL_NUMBER;
22402 
22403 					     IF (l_curr_status <> 7) THEN
22404 						--raise error
22405 						fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22406 						fnd_msg_pub.ADD;
22407 						l_progress := 'WMSINB-23769';
22408 						RAISE fnd_api.g_exc_error;
22409 					     END IF;
22410 
22411 					     --Validate Serial/Inspection_status
22412 		        /*  Commented for bug 6269102
22413                           *  To allow the inspection done again
22414                 	  *  on an inspection transaction to succeed
22415 		          *  as it was failing because of the
22416         		  *  inspection status <> 1
22417 
22418 					     IF l_transaction_type IN ('ACCEPT', 'REJECT') THEN
22419 						IF (Nvl(l_inspection_status, 1) <> 1) THEN
22420 						   --raise error
22421 						   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22422 						   fnd_msg_pub.ADD;
22423 						   l_progress := 'WMSINB-23779';
22424 						   RAISE fnd_api.g_exc_error;
22425 						END IF;
22426 					      ELS */
22427 					      IF l_transaction_type = 'DELIVER' THEN
22428 						IF (l_routing_header_id = 2) THEN
22429 						   IF l_inspection_status IS NOT NULL AND l_inspection_status = 1 THEN
22430 						      --raise error
22431 						      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22432 						      fnd_msg_pub.ADD;
22433 						      l_progress := 'WMSINB-23788';
22434 						      RAISE fnd_api.g_exc_error;
22435 						   END IF;
22436 						END IF;
22437 					     END IF;
22438 
22439 					     --Validate serial/group_mark_id to prevent
22440 					     --entering of duplicate serials
22441 
22442 					     IF (Nvl(l_group_mark_id, -99) = -7937) THEN
22443 						--raise error
22444 						fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22445 						fnd_msg_pub.ADD;
22446 						l_progress := 'WMSINB-23801';
22447 						RAISE fnd_api.g_exc_error;
22448 					     END IF;
22449 
22450 					     --UPDATE GROUP_MARK_ID TO -7937
22451 					     IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
22452 						--raise error
22453 						fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22454 						fnd_msg_pub.ADD;
22455 						l_progress := 'WMSINB-23810';
22456 						RAISE fnd_api.g_exc_error;
22457 					     END IF;
22458 					  EXCEPTION
22459 					     WHEN NO_DATA_FOUND THEN
22460 						-- RAISE ERROR
22461 						fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22462 						fnd_msg_pub.ADD;
22463 						l_progress := 'WMSINB-23818';
22464 						RAISE fnd_api.g_exc_error;
22465 					  END;
22466 				      END IF; --IF NOT L_SERIAL_ENTERED_ON_PARENT THEN
22467 				   END LOOP; -- FOR 1..L_SERIAL_QUANTITY
22468 				END LOOP; --FETCH C_MSNT INTO L_MSNT_REC;
22469 
22470 				CLOSE c_msnt;
22471 
22472 				IF (l_num_msnt_recs > 0) THEN
22473 				   IF l_tot_msnt_serial_qty <> l_rti_primary_qty THEN
22474 				      --raise error
22475 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22476 				      fnd_msg_pub.ADD;
22477 				      l_progress := 'WMSINB-23832';
22478 				      RAISE fnd_api.g_exc_error;
22479 				   END IF;
22480 				 ELSE
22481 				   IF (l_transaction_type = 'DELIVER'
22482 				       OR Nvl(l_auto_transact_code,'@@@@') = 'DELIVER') THEN
22483 
22484 				      IF l_source_document_code IN ('INVENTORY', 'REQ') THEN
22485 					 GET_SERIAL_LOT_CTRL_IN_SRC_ORG
22486 					   (L_SHIPMENT_LINE_ID, L_ORG_ID,
22487 					    L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
22488 					    l_from_org_rev_ctrl,
22489 					    X_RETURN_STATUS, X_MSG_COUNT,
22490 					    x_msg_data);
22491 				      END IF;
22492 
22493 				      IF (l_serial_number_control_code IN (2,5)
22494 					  OR (l_serial_number_control_code = 6
22495 					      AND l_source_document_code IN ('RMA'))
22496 					  OR (l_serial_number_control_code = 6
22497 					      AND l_source_document_code = 'INVENTORY'
22498 					      AND l_from_org_ser_crtl NOT IN (1, 6))
22499 					  --BUG 3644289: Do the following check for INTREQ
22500 					  OR (l_serial_number_control_code = 6
22501 					      AND l_from_org_ser_crtl IN (2,5,6)
22502 					      AND l_source_document_code = 'REQ'))
22503 					THEN
22504 					 --raise error
22505 					 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22506 					 fnd_msg_pub.ADD;
22507 					 l_progress := 'WMSINB-23840';
22508 					 RAISE fnd_api.g_exc_error;
22509 				      END IF;
22510 				    ELSIF (serial_entered_on_parent(l_parent_transaction_id)) THEN
22511 				      --raise error
22512 				      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
22513 				      fnd_msg_pub.ADD;
22514 				      l_progress := 'WMSINB-23846';
22515 				      RAISE fnd_api.g_exc_error;
22516 				   END IF;
22517 				END IF;
22518 
22519       END IF; -- IF (L_LOT_CONTROL_CODE = 2) THEN
22520     END IF;--IF (l_transaction_type IN ('RECEIVE','ACCEPT','REJECT','TRANSFER','DELIVER')) THEN
22521 
22522     --Validate lot/serial for ASN import.
22523 
22524     IF (l_transaction_type = 'SHIP' AND l_source_document_code = 'PO') THEN
22525     -- opm change bug# 3061052 added l_opm_lot_ctl check
22526 
22527     /*INVCONV, Remove the separate lot control check for OPM items.
22528       To be checked only once for all items.Punit Kumar */
22529 
22530       IF (l_lot_control_code = 2 /* OR l_opm_lot_ctl = 1  */) THEN
22531         IF (l_debug = 1) THEN
22532           print_debug('VALIDATE_LOT_SERIAL_INFO: Lot Controlled :'||l_progress, 1);
22533           l_progress := 'WMSINB-23861';
22534         END IF;
22535 
22536         l_num_mtlt_recs := 0;
22537         l_tot_mtlt_prim_qty := 0;
22538         l_tot_mtlt_trans_qty := 0; -- Bug# 4225766
22539 
22540         OPEN C_MTLT(L_RTI_ID);
22541         LOOP
22542           FETCH C_MTLT INTO L_MTLT_REC;
22543           EXIT WHEN C_MTLT%NOTFOUND;
22544 
22545        /* INVCONV , get L_MTLT_REC values into l_mln_rec which shall be passed to INV_NEW_LOT
22546           for lot creation */
22547           IF (l_debug = 1) THEN
22548              print_debug('INVCONV, Assigning values fetched from MTLT to l_mln_rec'||l_progress,1);
22549           END IF;
22550 
22551          	l_mln_rec.LOT_NUMBER                := L_MTLT_REC.LOT_NUMBER                    ;
22552           l_mln_rec.LAST_UPDATE_DATE          := SYSDATE                                  ;
22553           l_mln_rec.LAST_UPDATED_BY           := L_MTLT_REC.LAST_UPDATED_BY               ;
22554           l_mln_rec.CREATION_DATE             := SYSDATE                                  ;
22555           l_mln_rec.CREATED_BY                := L_MTLT_REC.CREATED_BY                    ;
22556           l_mln_rec.LAST_UPDATE_LOGIN         := L_MTLT_REC.LAST_UPDATE_LOGIN             ;
22557           l_mln_rec.EXPIRATION_DATE           := L_MTLT_REC.LOT_EXPIRATION_DATE               ;
22558           l_mln_rec.ATTRIBUTE_CATEGORY        := L_MTLT_REC.ATTRIBUTE_CATEGORY            ;
22559           l_mln_rec.ATTRIBUTE1                := L_MTLT_REC.ATTRIBUTE1                    ;
22560           l_mln_rec.ATTRIBUTE2                := L_MTLT_REC.ATTRIBUTE2                    ;
22561           l_mln_rec.ATTRIBUTE3                := L_MTLT_REC.ATTRIBUTE3                    ;
22562           l_mln_rec.ATTRIBUTE4                := L_MTLT_REC.ATTRIBUTE4                    ;
22563           l_mln_rec.ATTRIBUTE5                := L_MTLT_REC.ATTRIBUTE5                    ;
22564           l_mln_rec.ATTRIBUTE6                := L_MTLT_REC.ATTRIBUTE6                    ;
22565           l_mln_rec.ATTRIBUTE7                := L_MTLT_REC.ATTRIBUTE7                    ;
22566           l_mln_rec.ATTRIBUTE8                := L_MTLT_REC.ATTRIBUTE8                    ;
22567           l_mln_rec.ATTRIBUTE9                := L_MTLT_REC.ATTRIBUTE9                    ;
22568           l_mln_rec.ATTRIBUTE10               := L_MTLT_REC.ATTRIBUTE10                   ;
22569           l_mln_rec.ATTRIBUTE11               := L_MTLT_REC.ATTRIBUTE11                   ;
22570           l_mln_rec.ATTRIBUTE12               := L_MTLT_REC.ATTRIBUTE12                   ;
22571           l_mln_rec.ATTRIBUTE13               := L_MTLT_REC.ATTRIBUTE13                   ;
22572           l_mln_rec.ATTRIBUTE14               := L_MTLT_REC.ATTRIBUTE14                   ;
22573           l_mln_rec.ATTRIBUTE15               := L_MTLT_REC.ATTRIBUTE15                   ;
22574           l_mln_rec.REQUEST_ID                := L_MTLT_REC.REQUEST_ID                    ;
22575           l_mln_rec.PROGRAM_APPLICATION_ID    := L_MTLT_REC.PROGRAM_APPLICATION_ID        ;
22576           l_mln_rec.PROGRAM_ID                := L_MTLT_REC.PROGRAM_ID                    ;
22577           l_mln_rec.PROGRAM_UPDATE_DATE       := L_MTLT_REC.PROGRAM_UPDATE_DATE           ;
22578           l_mln_rec.DESCRIPTION               := L_MTLT_REC.DESCRIPTION                   ;
22579           l_mln_rec.VENDOR_NAME               := L_MTLT_REC.VENDOR_NAME                   ;
22580           l_mln_rec.SUPPLIER_LOT_NUMBER       := L_MTLT_REC.SUPPLIER_LOT_NUMBER           ;
22581           l_mln_rec.GRADE_CODE                := L_MTLT_REC.GRADE_CODE                    ;
22582           l_mln_rec.ORIGINATION_DATE          := L_MTLT_REC.ORIGINATION_DATE              ;
22583           l_mln_rec.DATE_CODE                 := L_MTLT_REC.DATE_CODE                     ;
22584           l_mln_rec.STATUS_ID                 := L_MTLT_REC.STATUS_ID                     ;
22585           l_mln_rec.CHANGE_DATE               := L_MTLT_REC.CHANGE_DATE                   ;
22586           l_mln_rec.AGE                       := L_MTLT_REC.AGE                           ;
22587           l_mln_rec.RETEST_DATE               := L_MTLT_REC.RETEST_DATE                   ;
22588           l_mln_rec.MATURITY_DATE             := L_MTLT_REC.MATURITY_DATE                 ;
22589           l_mln_rec.LOT_ATTRIBUTE_CATEGORY    := L_MTLT_REC.LOT_ATTRIBUTE_CATEGORY        ;
22590           l_mln_rec.ITEM_SIZE                 := L_MTLT_REC.ITEM_SIZE                     ;
22591           l_mln_rec.COLOR                     := L_MTLT_REC.COLOR                         ;
22592           l_mln_rec.VOLUME                    := L_MTLT_REC.VOLUME                        ;
22593           l_mln_rec.VOLUME_UOM                := L_MTLT_REC.VOLUME_UOM                    ;
22594           l_mln_rec.PLACE_OF_ORIGIN           := L_MTLT_REC.PLACE_OF_ORIGIN               ;
22595           l_mln_rec.BEST_BY_DATE              := L_MTLT_REC.BEST_BY_DATE                  ;
22596           l_mln_rec.LENGTH                    := L_MTLT_REC.LENGTH                        ;
22597           l_mln_rec.LENGTH_UOM                := L_MTLT_REC.LENGTH_UOM                    ;
22598           l_mln_rec.RECYCLED_CONTENT          := L_MTLT_REC.RECYCLED_CONTENT              ;
22599           l_mln_rec.THICKNESS                 := L_MTLT_REC.THICKNESS                     ;
22600           l_mln_rec.THICKNESS_UOM             := L_MTLT_REC.THICKNESS_UOM                 ;
22601           l_mln_rec.WIDTH                     := L_MTLT_REC.WIDTH                         ;
22602           l_mln_rec.WIDTH_UOM                 := L_MTLT_REC.WIDTH_UOM                     ;
22603           l_mln_rec.CURL_WRINKLE_FOLD         := L_MTLT_REC.CURL_WRINKLE_FOLD             ;
22604           l_mln_rec.C_ATTRIBUTE1              := L_MTLT_REC.C_ATTRIBUTE1                  ;
22605           l_mln_rec.C_ATTRIBUTE2              := L_MTLT_REC.C_ATTRIBUTE2                  ;
22606           l_mln_rec.C_ATTRIBUTE3              := L_MTLT_REC.C_ATTRIBUTE3                  ;
22607           l_mln_rec.C_ATTRIBUTE4              := L_MTLT_REC.C_ATTRIBUTE4                  ;
22608           l_mln_rec.C_ATTRIBUTE5              := L_MTLT_REC.C_ATTRIBUTE5                  ;
22609           l_mln_rec.C_ATTRIBUTE6              := L_MTLT_REC.C_ATTRIBUTE6                  ;
22610           l_mln_rec.C_ATTRIBUTE7              := L_MTLT_REC.C_ATTRIBUTE7                  ;
22611           l_mln_rec.C_ATTRIBUTE8              := L_MTLT_REC.C_ATTRIBUTE8                  ;
22612           l_mln_rec.C_ATTRIBUTE9              := L_MTLT_REC.C_ATTRIBUTE9                  ;
22613           l_mln_rec.C_ATTRIBUTE10             := L_MTLT_REC.C_ATTRIBUTE10                 ;
22614           l_mln_rec.C_ATTRIBUTE11             := L_MTLT_REC.C_ATTRIBUTE11                 ;
22615           l_mln_rec.C_ATTRIBUTE12             := L_MTLT_REC.C_ATTRIBUTE12                 ;
22616           l_mln_rec.C_ATTRIBUTE13             := L_MTLT_REC.C_ATTRIBUTE13                 ;
22617           l_mln_rec.C_ATTRIBUTE14             := L_MTLT_REC.C_ATTRIBUTE14                 ;
22618           l_mln_rec.C_ATTRIBUTE15             := L_MTLT_REC.C_ATTRIBUTE15                 ;
22619           l_mln_rec.C_ATTRIBUTE16             := L_MTLT_REC.C_ATTRIBUTE16                 ;
22620           l_mln_rec.C_ATTRIBUTE17             := L_MTLT_REC.C_ATTRIBUTE17                 ;
22621           l_mln_rec.C_ATTRIBUTE18             := L_MTLT_REC.C_ATTRIBUTE18                 ;
22622           l_mln_rec.C_ATTRIBUTE19             := L_MTLT_REC.C_ATTRIBUTE19                 ;
22623           l_mln_rec.C_ATTRIBUTE20             := L_MTLT_REC.C_ATTRIBUTE20                 ;
22624           l_mln_rec.D_ATTRIBUTE1              := L_MTLT_REC.D_ATTRIBUTE1                  ;
22625           l_mln_rec.D_ATTRIBUTE2              := L_MTLT_REC.D_ATTRIBUTE2                  ;
22626           l_mln_rec.D_ATTRIBUTE3              := L_MTLT_REC.D_ATTRIBUTE3                  ;
22627           l_mln_rec.D_ATTRIBUTE4              := L_MTLT_REC.D_ATTRIBUTE4                  ;
22628           l_mln_rec.D_ATTRIBUTE5              := L_MTLT_REC.D_ATTRIBUTE5                  ;
22629           l_mln_rec.D_ATTRIBUTE6              := L_MTLT_REC.D_ATTRIBUTE6                  ;
22630           l_mln_rec.D_ATTRIBUTE7              := L_MTLT_REC.D_ATTRIBUTE7                  ;
22631           l_mln_rec.D_ATTRIBUTE8              := L_MTLT_REC.D_ATTRIBUTE8                  ;
22632           l_mln_rec.D_ATTRIBUTE9              := L_MTLT_REC.D_ATTRIBUTE9                  ;
22633           l_mln_rec.D_ATTRIBUTE10             := L_MTLT_REC.D_ATTRIBUTE10                 ;
22634           l_mln_rec.N_ATTRIBUTE1              := L_MTLT_REC.N_ATTRIBUTE1                  ;
22635           l_mln_rec.N_ATTRIBUTE2              := L_MTLT_REC.N_ATTRIBUTE2                  ;
22636           l_mln_rec.N_ATTRIBUTE3              := L_MTLT_REC.N_ATTRIBUTE3                  ;
22637           l_mln_rec.N_ATTRIBUTE4              := L_MTLT_REC.N_ATTRIBUTE4                  ;
22638           l_mln_rec.N_ATTRIBUTE5              := L_MTLT_REC.N_ATTRIBUTE5                  ;
22639           l_mln_rec.N_ATTRIBUTE6              := L_MTLT_REC.N_ATTRIBUTE6                  ;
22640           l_mln_rec.N_ATTRIBUTE7              := L_MTLT_REC.N_ATTRIBUTE7                  ;
22641           l_mln_rec.N_ATTRIBUTE8              := L_MTLT_REC.N_ATTRIBUTE8                  ;
22642           l_mln_rec.N_ATTRIBUTE9              := L_MTLT_REC.N_ATTRIBUTE9                  ;
22643           l_mln_rec.N_ATTRIBUTE10             := L_MTLT_REC.N_ATTRIBUTE10                 ;
22644           l_mln_rec.VENDOR_ID                 := L_MTLT_REC.VENDOR_ID                     ;
22645           l_mln_rec.TERRITORY_CODE            := L_MTLT_REC.TERRITORY_CODE                ;
22646           l_mln_rec.PARENT_LOT_NUMBER         := L_MTLT_REC.PARENT_LOT_NUMBER             ;
22647           l_mln_rec.ORIGINATION_TYPE          := L_MTLT_REC.ORIGINATION_TYPE              ;
22648           l_mln_rec.EXPIRATION_ACTION_DATE    := L_MTLT_REC.EXPIRATION_ACTION_DATE        ;
22649           l_mln_rec.EXPIRATION_ACTION_CODE    := L_MTLT_REC.EXPIRATION_ACTION_CODE        ;
22650           l_mln_rec.HOLD_DATE                 := L_MTLT_REC.HOLD_DATE                     ;
22651 
22652          /*end , INVCONV*/
22653 
22654 
22655           L_NUM_MTLT_RECS := L_NUM_MTLT_RECS + 1;
22656           l_tot_mtlt_prim_qty := l_tot_mtlt_prim_qty + l_mtlt_rec.primary_quantity;
22657           l_tot_mtlt_trans_qty := l_tot_mtlt_trans_qty + l_mtlt_rec.transaction_quantity; -- Bug# 4225766
22658 
22659           IF (l_debug = 1) THEN
22660             print_debug('VALIDATE_LOT_SERIAL_INFO: LOT NUMBER: '||l_mtlt_rec.lot_number||': '||l_progress, 1);
22661             print_debug('VALIDATE_LOT_SERIAL_INFO: LOT PRIMARY QUANTITY: '||l_mtlt_rec.primary_quantity||': '||l_progress, 1);
22662             print_debug('INVCONV , Finished Assigning values fetched from MTLT to l_mln_rec'||l_progress,1);		 l_progress := 'WMSINB-23879';
22663             l_progress := 'WMSINB-23879';
22664           END IF;
22665 
22666           BEGIN
22667             /* INVCONV, Remove OPM specific ic_lots_mst logic
22668               Validation of Lot existence for OPM items shall be done from
22669               MTL_LOT_NUMBERS as is done for discrete items.
22670               If it exists then we shall validate its parent lot also.
22671               Remove OPM fork.Add parent_lot_number in discrete query.Punit Kumar */
22672 
22673             /*IF (l_discrete_transaction) THEN		 */
22674             SELECT 1,parent_lot_number
22675                  INTO L_LOT_EXISTS ,l_parent_lot_number
22676                  FROM MTL_LOT_NUMBERS
22677                  WHERE ORGANIZATION_ID = L_ORG_ID
22678                  AND   INVENTORY_ITEM_ID = L_ITEM_ID
22679                  AND LOT_NUMBER = Ltrim(Rtrim(L_MTLT_REC.lot_number));
22680 
22681                 /* ELSE -- opm change bug# 3061052 --IF (l_discrete_transaction) THEN
22682                   IF Ltrim(Rtrim(L_MTLT_REC.sublot_num)) IS NOT NULL THEN
22683                      SELECT 1, LOT_ID
22684                  INTO L_LOT_EXISTS , l_opm_lot_id
22685                  FROM IC_LOTS_MST
22686                  WHERE ITEM_ID = l_opm_item_id
22687                  AND LOT_NO = Ltrim(Rtrim(L_MTLT_REC.lot_number))
22688                  AND SUBLOT_NO = Ltrim(Rtrim(L_MTLT_REC.sublot_num)) ;
22689                    ELSE
22690                      SELECT 1, LOT_ID
22691                  INTO L_LOT_EXISTS , l_opm_lot_id
22692                  FROM IC_LOTS_MST
22693                  WHERE ITEM_ID = l_opm_item_id
22694                  AND LOT_NO = Ltrim(Rtrim(L_MTLT_REC.lot_number))
22695                  AND SUBLOT_NO IS NULL ;
22696                   END IF;
22697                END IF; --IF (l_discrete_transaction) THEN
22698               */
22699           EXCEPTION
22700              WHEN NO_DATA_FOUND THEN
22701                 L_LOT_EXISTS := 0;
22702           END;
22703 
22704           IF (l_debug = 1) THEN
22705             print_debug('VALIDATE_LOT_SERIAL_INFO: LOT EXISTS: '||l_lot_exists||' : '||l_progress, 1);
22706             print_debug('INVCONV, Removing OPM specific fork :'||l_progress,1);
22707             l_progress := 'WMSINB-23915';
22708           END IF;
22709 
22710           IF L_LOT_EXISTS = 1 THEN
22711 
22712             /*INVCONV , validating for parent lot, Punit Kumar */
22713             IF  L_MTLT_REC.parent_lot_number IS NOT NULL THEN
22714                IF L_MTLT_REC.parent_lot_number <> l_parent_lot_number THEN
22715                   fnd_message.set_name ('INV' , 'INV_CL_PARENT_INVALID' );
22716              fnd_msg_pub.ADD;
22717                   RAISE fnd_api.g_exc_error;
22718                END IF;
22719             ELSE
22720                L_MTLT_REC.parent_lot_number := l_parent_lot_number;
22721             END IF;
22722             /*end , INVCONV */
22723 
22724             /*INVCONV , Remove the process specific call as now we shall validate the proces
22725               attributes for discrete items too. Punit Kumar */
22726 
22727              /*IF (l_discrete_transaction) THEN */
22728               /* end , INVCONV */
22729 
22730                /* The below code was already commented.  It has nothing to do with INVCONV */
22731 
22732               -- This is NOT required for a SHIP transaction.
22733               -- perform material status check
22734               --INV_LOT_TRX_VALIDATION_PUB.VALIDATE_MATERIAL_STATUS(X_RETURN_STATUS => X_RETURN_STATUS,
22735               --X_MSG_COUNT => X_MSG_COUNT,
22736               --X_MSG_DATA => X_MSG_DATA,
22737               --X_VALIDATION_STATUS => L_VALIDATION_STATUS,
22738               --P_TRANSACTION_TYPE_ID => 18,
22739               --P_ORGANIZATION_ID => L_ORG_ID,
22740               --P_INVENTORY_ITEM_ID => L_ITEM_ID,
22741               --P_LOT_NUMBER => L_MTLT_REC.LOT_NUMBER,
22742               --P_SUBINVENTORY_CODE => l_sub_code,
22743               --P_LOCATOR_ID => l_loc_id,
22744               --P_STATUS_ID => NULL);
22745               --IF X_RETURN_STATUS <> 'S' THEN
22746               --RAISE ERROR
22747               --l_progress := 'WMSINB-23934';
22748               --RAISE fnd_api.g_exc_error;
22749               --END IF;
22750 
22751               --IF (l_debug = 1) THEN
22752               --print_debug('VALIDATE_LOT_SERIAL_INFO: LOT MATERIAL VALIDATION STATUS: '||L_VALIDATION_STATUS||' : '||l_progress, 1);
22753               --l_progress := 'WMSINB-23940';
22754               --END IF;
22755 
22756               --IF L_VALIDATION_STATUS <> 'Y' THEN
22757               --RAISE ERROR
22758               --l_progress := 'WMSINB-23945';
22759               --RAISE fnd_api.g_exc_error;
22760               --END IF;
22761 
22762             /* end , The above code was already commented.  It has nothing to do with INVCONV */
22763 
22764             NULL;
22765 
22766              /* INVCONV */
22767 
22768           /*  ELSE --IF (l_discrete_transaction) THEN
22769               -- opm change bug# 3061052
22770               gml_opm_roi_grp.validate_opm_lot(p_api_version	 	=> 1.0,
22771                        p_init_msg_lst	 	=> FND_API.G_FALSE,
22772                        p_mtlt_rowid		=> l_mtlt_rec.rowid,
22773                        p_new_lot	 	=> 'N',
22774                        p_opm_item_id		=> l_opm_item_id,
22775                        p_item_no		=> l_item_no,
22776                        p_lots_specified_on_parent => 'N',
22777                        p_lot_id		=> l_opm_lot_id,
22778                        x_return_status 	=> x_return_status,
22779                        x_msg_data      	=> x_msg_data,
22780                        x_msg_count     	=> x_msg_count
22781                        );
22782 
22783                end , INVCONV */
22784 
22785             /*INVCONV ,*/
22786             IF (l_debug = 1) THEN
22787                print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
22788             END IF;
22789 
22790             INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
22791                                                        x_return_status      		   => x_return_status
22792                                                       ,x_msg_data           		   => x_msg_data
22793                                                       ,x_msg_count          		   => x_msg_count
22794                                                       ,p_api_version	               => 1.0
22795                                                       ,p_init_msg_lst	            => FND_API.G_FALSE
22796                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
22797                                                       ,p_transaction_type_id 	      => l_transaction_type_id
22798                                                       ,p_new_lot			            => 'N'
22799                                                       ,p_item_id	 		            => l_item_id
22800                                                       ,p_to_organization_id		   => L_ORG_ID
22801                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
22802                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
22803                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
22804                                                       ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
22805                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
22806                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
22807                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
22808                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
22809                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
22810                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
22811                                                       ,p_rti_id	                  => L_RTI_ID
22812                                                       ,p_revision             	   => l_item_revision
22813                                                       ,p_subinventory_code  	      => L_SUB_CODE
22814                                                       ,p_locator_id           	   => l_loc_id
22815                                                       ,p_transaction_type           => l_transaction_type
22816                                                       ,p_parent_txn_type            => l_parent_txn_type
22817                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
22818                                                       );
22819             /*INVCONV ,*/
22820             IF (l_debug = 1) THEN
22821                print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
22822                print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
22823             END IF;
22824 
22825             IF X_RETURN_STATUS <> 'S' THEN
22826                --RAISE ERROR
22827                l_progress := 'WMSINB-23964';
22828                RAISE fnd_api.g_exc_error;
22829             END IF;
22830 
22831             IF (l_debug = 1) THEN
22832                print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
22833             END IF;
22834 
22835          /*END IF; --IF (l_discrete_transaction) THEN */
22836 
22837           ELSE --IF L_LOT_EXISTS = 1 THEN
22838 
22839 
22840             /* IF (l_discrete_transaction) THEN
22841               --call CREATE_INV_LOT
22842               --FOR l_inv_att_index IN 1..15 LOOP
22843               -- l_inv_attributes_tbl(l_inv_att_index) := NULL;
22844               --END LOOP;
22845 
22846               l_c_attributes_tbl(1)  := l_mtlt_rec.c_attribute1;
22847               l_c_attributes_tbl(2)  := l_mtlt_rec.c_attribute2;
22848               l_c_attributes_tbl(3)  := l_mtlt_rec.c_attribute3;
22849               l_c_attributes_tbl(4)  := l_mtlt_rec.c_attribute4;
22850               l_c_attributes_tbl(5)  := l_mtlt_rec.c_attribute5;
22851               l_c_attributes_tbl(6)  := l_mtlt_rec.c_attribute6;
22852               l_c_attributes_tbl(7)  := l_mtlt_rec.c_attribute7;
22853               l_c_attributes_tbl(8)  := l_mtlt_rec.c_attribute8;
22854               l_c_attributes_tbl(9)  := l_mtlt_rec.c_attribute9;
22855               l_c_attributes_tbl(10) := l_mtlt_rec.c_attribute10;
22856               l_c_attributes_tbl(11) := l_mtlt_rec.c_attribute11;
22857               l_c_attributes_tbl(12) := l_mtlt_rec.c_attribute12;
22858               l_c_attributes_tbl(13) := l_mtlt_rec.c_attribute13;
22859               l_c_attributes_tbl(14) := l_mtlt_rec.c_attribute14;
22860               l_c_attributes_tbl(15) := l_mtlt_rec.c_attribute15;
22861               l_c_attributes_tbl(16) := l_mtlt_rec.c_attribute16;
22862               l_c_attributes_tbl(17) := l_mtlt_rec.c_attribute17;
22863               l_c_attributes_tbl(18) := l_mtlt_rec.c_attribute18;
22864               l_c_attributes_tbl(19) := l_mtlt_rec.c_attribute19;
22865               l_c_attributes_tbl(20) := l_mtlt_rec.c_attribute20;
22866               l_d_attributes_tbl(1)  := l_mtlt_rec.d_attribute1;
22867               l_d_attributes_tbl(2)  := l_mtlt_rec.d_attribute2;
22868               l_d_attributes_tbl(3)  := l_mtlt_rec.d_attribute3;
22869               l_d_attributes_tbl(4)  := l_mtlt_rec.d_attribute4;
22870               l_d_attributes_tbl(5)  := l_mtlt_rec.d_attribute5;
22871               l_d_attributes_tbl(6)  := l_mtlt_rec.d_attribute6;
22872               l_d_attributes_tbl(7)  := l_mtlt_rec.d_attribute7;
22873               l_d_attributes_tbl(8)  := l_mtlt_rec.d_attribute8;
22874               l_d_attributes_tbl(9)  := l_mtlt_rec.d_attribute9;
22875               l_d_attributes_tbl(10) := l_mtlt_rec.d_attribute10;
22876               l_n_attributes_tbl(1)  := l_mtlt_rec.n_attribute1;
22877               l_n_attributes_tbl(2)  := l_mtlt_rec.n_attribute2;
22878               l_n_attributes_tbl(3)  := l_mtlt_rec.n_attribute3;
22879               l_n_attributes_tbl(4)  := l_mtlt_rec.n_attribute4;
22880               l_n_attributes_tbl(5)  := l_mtlt_rec.n_attribute5;
22881               l_n_attributes_tbl(6)  := l_mtlt_rec.n_attribute6;
22882               l_n_attributes_tbl(7)  := l_mtlt_rec.n_attribute7;
22883               l_n_attributes_tbl(8)  := l_mtlt_rec.n_attribute8;
22884               l_n_attributes_tbl(9)  := l_mtlt_rec.n_attribute9;
22885               l_n_attributes_tbl(10) := l_mtlt_rec.n_attribute10;
22886 
22887              --Bug #3187688
22888              --Populate the INV attributes table and pass the attribute cateogry
22889              l_inv_attributes_tbl(1)  := l_mtlt_rec.attribute1;
22890              l_inv_attributes_tbl(2)  := l_mtlt_rec.attribute2;
22891              l_inv_attributes_tbl(3)  := l_mtlt_rec.attribute3;
22892              l_inv_attributes_tbl(4)  := l_mtlt_rec.attribute4;
22893              l_inv_attributes_tbl(5)  := l_mtlt_rec.attribute5;
22894              l_inv_attributes_tbl(6)  := l_mtlt_rec.attribute6;
22895              l_inv_attributes_tbl(7)  := l_mtlt_rec.attribute7;
22896              l_inv_attributes_tbl(8)  := l_mtlt_rec.attribute8;
22897              l_inv_attributes_tbl(9)  := l_mtlt_rec.attribute9;
22898              l_inv_attributes_tbl(10) := l_mtlt_rec.attribute10;
22899              l_inv_attributes_tbl(11) := l_mtlt_rec.attribute11;
22900              l_inv_attributes_tbl(12) := l_mtlt_rec.attribute12;
22901              l_inv_attributes_tbl(13) := l_mtlt_rec.attribute13;
22902              l_inv_attributes_tbl(14) := l_mtlt_rec.attribute14;
22903              l_inv_attributes_tbl(15) := l_mtlt_rec.attribute15;
22904 
22905               inv_lot_api_pub.create_inv_lot(x_return_status => x_return_status
22906                      , x_msg_count => x_msg_count
22907                      , x_msg_data => x_msg_data
22908                      , p_inventory_item_id => l_item_id
22909                      , p_organization_id => l_org_id
22910                      , p_lot_number => l_mtlt_rec.lot_number
22911                      , p_expiration_date => l_mtlt_rec.lot_expiration_date
22912                      , p_disable_flag => NULL
22913                      , p_attribute_category => l_mtlt_rec.attribute_category
22914                      , p_lot_attribute_category => l_mtlt_rec.lot_attribute_category
22915                      , p_attributes_tbl => l_inv_attributes_tbl
22916                      , p_c_attributes_tbl => l_c_attributes_tbl
22917                      , p_n_attributes_tbl => l_n_attributes_tbl
22918                      , p_d_attributes_tbl => l_d_attributes_tbl
22919                      , p_grade_code => l_mtlt_rec.grade_code
22920                      , p_origination_date => l_mtlt_rec.origination_date
22921                      , p_date_code => l_mtlt_rec.date_code
22922                      , p_status_id => l_mtlt_rec.status_id
22923                      , p_change_date => l_mtlt_rec.change_date
22924                      , p_age => l_mtlt_rec.age
22925                      , p_retest_date => l_mtlt_rec.retest_date
22926                 , p_maturity_date => l_mtlt_rec.maturity_date
22927                 , p_item_size => l_mtlt_rec.item_size
22928                 , p_color => l_mtlt_rec.color
22929                 , p_volume => l_mtlt_rec.volume
22930                 , p_volume_uom => l_mtlt_rec.volume_uom
22931                 , p_place_of_origin => l_mtlt_rec.place_of_origin
22932                 , p_best_by_date => l_mtlt_rec.best_by_date
22933                 , p_length => l_mtlt_rec.Length
22934                 , p_length_uom => l_mtlt_rec.length_uom
22935                 , p_recycled_content => l_mtlt_rec.recycled_content
22936                 , p_thickness => l_mtlt_rec.thickness
22937                 , p_thickness_uom => l_mtlt_rec.thickness_uom
22938                 , p_width => l_mtlt_rec.width
22939                 , p_width_uom => l_mtlt_rec.width_uom
22940                 , p_territory_code => l_mtlt_rec.territory_code
22941                 , p_supplier_lot_number => l_mtlt_rec.supplier_lot_number
22942                 , p_vendor_name => l_mtlt_rec.vendor_name
22943                 , p_source => inv_lot_api_pub.inv);
22944 
22945               IF (x_return_status <> 'S') THEN
22946                  --raise error
22947                  l_progress := 'WMSINB-24062';
22948                  RAISE fnd_api.g_exc_error;
22949               END IF;
22950 
22951               IF (l_debug = 1) THEN
22952                  print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CREATED: '||l_progress, 1);
22953                  l_progress := 'WMSINB-24068';
22954               END IF;
22955             ELSE --IF (l_discrete_transaction) THEN
22956               -- opm change bug# 3061052
22957               gml_opm_roi_grp.validate_opm_lot(p_api_version	 	=> 1.0,
22958                        p_init_msg_lst	 	=> FND_API.G_FALSE,
22959                        p_mtlt_rowid		=> l_mtlt_rec.rowid,
22960                        p_new_lot	 	=> 'Y',
22961                        p_opm_item_id		=> l_opm_item_id,
22962                        p_item_no		=> l_item_no,
22963                        p_lots_specified_on_parent => 'N',
22964                        p_lot_id		=> l_opm_lot_id,
22965                        x_return_status 	=> x_return_status,
22966                        x_msg_data      	=> x_msg_data,
22967                        x_msg_count     	=> x_msg_count
22968                        );
22969               IF X_RETURN_STATUS <> 'S' THEN
22970                  --RAISE ERROR
22971                  l_progress := 'WMSINB-24086';
22972                  RAISE fnd_api.g_exc_error;
22973               END IF;
22974 
22975               IF (l_debug = 1) THEN
22976                  print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CREATED: '||x_return_status||' : '||l_progress, 1);
22977               END IF;
22978            END IF; --IF (l_discrete_transaction) THEN
22979 
22980 
22981             /*INVCONV , Perform lot validations and create the new lot.
22982                Call Lot Create API INV_ROI_INTEGRATION_GRP.INV_NEW_LOT to create the new lot.
22983                This shall also create lot specific conversions after creating the new Lot.
22984 			      This replaces the existing procedure INV_LOT_API_PUB.CREATE_INV_LOT to create NEW LOT
22985                Punit Kumar*/
22986 
22987             /*INVCONV ,*/
22988             IF (l_debug = 1) THEN
22989                 print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
22990             END IF;
22991 
22992             INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
22993                                                          x_return_status      		   => x_return_status
22994                                                          ,x_msg_data           		   => x_msg_data
22995                                                          ,x_msg_count          		   => x_msg_count
22996                                                         ,p_api_version	               => 1.0
22997                                                         ,p_init_msg_lst	               => FND_API.G_FALSE
22998                                                         ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
22999                                                         ,p_transaction_type_id 	      => l_transaction_type_id
23000                                                         ,p_new_lot			            => 'Y'
23001                                                         ,p_item_id	 		            => l_item_id
23002                                                         ,p_to_organization_id		      => L_ORG_ID
23003                                                         ,p_lot_number			         => L_MTLT_REC.lot_number
23004                                                         ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
23005                                                         ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
23006                                                         ,x_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
23007                                                         ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
23008                                                         ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
23009                                                         ,p_transaction_unit_of_measure => l_rti_UNIT_OF_MEASURE
23010                                                         ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
23011                                                         ,p_OE_ORDER_HEADER_ID	         => l_OE_ORDER_HEADER_ID
23012                                                         ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
23013                                                         ,p_rti_id	                     => L_RTI_ID
23014                                                         ,p_revision             	      => l_item_revision
23015                                                         ,p_subinventory_code  	      => L_SUB_CODE
23016                                                         ,p_locator_id           	      => l_loc_id
23017                                                         ,p_transaction_type           => l_transaction_type
23018                                                         ,p_parent_txn_type            => l_parent_txn_type
23019                                                         ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
23020                                                         );
23021             /*INVCONV ,*/
23022             IF (l_debug = 1) THEN
23023                print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
23024                print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
23025             END IF;
23026 
23027             IF (x_return_status <> 'S') THEN
23028                --raise error
23029                l_progress := 'WMSINB-24062';
23030                RAISE fnd_api.g_exc_error;
23031             END IF;
23032 
23033             /*INVCONV ,*/
23034             IF (l_debug = 1) THEN
23035                print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
23036             END IF;
23037 
23038             INV_ROI_INTEGRATION_GRP.INV_NEW_LOT(
23039                                                 x_return_status      		   => x_return_status
23040                                                ,x_msg_count          		   => x_msg_count
23041                                                ,x_msg_data           		   => x_msg_data
23042                                                ,p_api_version	               => 1.0
23043                                                ,p_init_msg_lst	               => FND_API.G_FALSE
23044                                                ,p_source_document_code			=> L_SOURCE_DOCUMENT_CODE
23045                                                ,p_item_id				         => l_item_id
23046                                                ,p_from_organization_id			=> L_FROM_ORG_ID
23047                                                ,p_to_organization_id	         => L_ORG_ID
23048                                                ,p_lot_number				      => L_MTLT_REC.lot_number
23049                                                ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
23050                                                ,p_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
23051                                                ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
23052                                                ,p_primary_unit_of_measure	   => l_rti_PRIMARY_UNIT_OF_MEASURE
23053                                                ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
23054                                                ,p_uom_code	                  => l_rti_UOM_CODE
23055                                                ,p_secondary_uom_code	         => l_rti_SECONDARY_UOM_CODE
23056                                                ,p_reason_id	                  => L_MTLT_REC.REASON_ID
23057                                                ,P_MLN_REC                     => L_MLN_REC
23058                                                ,p_mtlt_rowid	               => L_MTLT_REC.ROWID
23059                                                 );
23060              /*INVCONV ,*/
23061              IF (l_debug = 1) THEN
23062                 print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
23063                 print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_NEW_LOT return status: '||x_return_status||' : '||l_progress, 1);
23064              END IF;
23065 
23066             IF X_RETURN_STATUS <> 'S' THEN
23067                --RAISE ERROR
23068                l_progress := 'WMSINB-24086';
23069                RAISE fnd_api.g_exc_error;
23070             END IF;
23071 
23072             IF (l_debug = 1) THEN
23073                print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CREATED: '||x_return_status||' : '||l_progress, 1);
23074             END IF;
23075           END IF;--IF L_LOT_EXISTS = 1 THEN
23076 
23077           IF (L_SERIAL_NUMBER_CONTROL_CODE IN (2,5)) THEN
23078 
23079             IF (l_debug = 1) THEN
23080                print_debug('VALIDATE_LOT_SERIAL_INFO: LOT AND SERIAL CONTROLLED: '||l_progress, 1);
23081                print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROL CODE: '||l_serial_number_control_code||' : '||l_progress, 1);
23082                print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||l_source_document_code||' : '||l_progress, 1);
23083                l_progress := 'WMSINB-24102';
23084             END IF;
23085 
23086             L_NUM_MSNT_RECS := 0;
23087             l_tot_msnt_serial_qty := 0;
23088 
23089             OPEN C_MSNT_LOTSERIAL(L_MTLT_REC.SERIAL_TRANSACTION_TEMP_ID);
23090 
23091             LOOP
23092               FETCH C_MSNT_LOTSERIAL INTO L_MSNT_REC;
23093               EXIT WHEN C_MSNT_LOTSERIAL%NOTFOUND;
23094 
23095               L_NUM_MSNT_RECS := L_NUM_MSNT_RECS + 1;
23096 
23097               L_SERIAL_QUANTITY :=
23098                 INV_SERIAL_NUMBER_PUB.GET_SERIAL_DIFF(L_MSNT_REC.FM_SERIAL_NUMBER,
23099                                   L_MSNT_REC.TO_SERIAL_NUMBER);
23100 
23101               l_tot_msnt_serial_qty := l_tot_msnt_serial_qty + l_serial_quantity;
23102 
23103               INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.FM_SERIAL_NUMBER, L_TEMP_PREFIX, L_FROM_SER_NUMBER);
23104               INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.TO_SERIAL_NUMBER, L_TEMP_PREFIX, L_TO_SER_NUMBER);
23105 
23106               IF (l_debug = 1) THEN
23107                  print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL QUANTITY: '||l_serial_quantity||' : '||l_progress, 1);
23108                  l_progress := 'WMSINB-24127';
23109               END IF;
23110 
23111               --populate attributes table
23112               l_serial_attributes_tbl(1).column_name   := 'SERIAL_ATTRIBUTE_CATEGORY';
23113               l_serial_attributes_tbl(1).column_value  := l_msnt_rec.serial_attribute_category;
23114               l_serial_attributes_tbl(2).column_name   := 'ORIGINATION_DATE';
23115               l_serial_attributes_tbl(2).column_value  := l_msnt_rec.origination_date;
23116               l_serial_attributes_tbl(3).column_name   := 'C_ATTRIBUTE1';
23117               l_serial_attributes_tbl(3).column_value  := l_msnt_rec.c_attribute1;
23118               l_serial_attributes_tbl(4).column_name   := 'C_ATTRIBUTE2';
23119               l_serial_attributes_tbl(4).column_value  := l_msnt_rec.c_attribute2;
23120               l_serial_attributes_tbl(5).column_name   := 'C_ATTRIBUTE3';
23121               l_serial_attributes_tbl(5).column_value  := l_msnt_rec.c_attribute3;
23122               l_serial_attributes_tbl(6).column_name   := 'C_ATTRIBUTE4';
23123               l_serial_attributes_tbl(6).column_value   := l_msnt_rec.c_attribute4;
23124               l_serial_attributes_tbl(7).column_name   := 'C_ATTRIBUTE5';
23125               l_serial_attributes_tbl(7).column_value   := l_msnt_rec.c_attribute5;
23126               l_serial_attributes_tbl(8).column_name   := 'C_ATTRIBUTE6';
23127               l_serial_attributes_tbl(8).column_value   := l_msnt_rec.c_attribute6;
23128               l_serial_attributes_tbl(9).column_name   := 'C_ATTRIBUTE7';
23129               l_serial_attributes_tbl(9).column_value   := l_msnt_rec.c_attribute7;
23130               l_serial_attributes_tbl(10).column_name  := 'C_ATTRIBUTE8';
23131               l_serial_attributes_tbl(10).column_value  := l_msnt_rec.c_attribute8;
23132               l_serial_attributes_tbl(11).column_name  := 'C_ATTRIBUTE9';
23133               l_serial_attributes_tbl(11).column_value  := l_msnt_rec.c_attribute9;
23134               l_serial_attributes_tbl(12).column_name  := 'C_ATTRIBUTE10';
23135               l_serial_attributes_tbl(12).column_value  := l_msnt_rec.c_attribute10;
23136               l_serial_attributes_tbl(13).column_name  := 'C_ATTRIBUTE11';
23137               l_serial_attributes_tbl(13).column_value  := l_msnt_rec.c_attribute11;
23138               l_serial_attributes_tbl(14).column_name  := 'C_ATTRIBUTE12';
23139               l_serial_attributes_tbl(14).column_value  := l_msnt_rec.c_attribute12;
23140               l_serial_attributes_tbl(15).column_name  := 'C_ATTRIBUTE13';
23141               l_serial_attributes_tbl(15).column_value  := l_msnt_rec.c_attribute13;
23142               l_serial_attributes_tbl(16).column_name  := 'C_ATTRIBUTE14';
23143               l_serial_attributes_tbl(16).column_value  := l_msnt_rec.c_attribute14;
23144               l_serial_attributes_tbl(17).column_name  := 'C_ATTRIBUTE15';
23145               l_serial_attributes_tbl(17).column_value  := l_msnt_rec.c_attribute15;
23146               l_serial_attributes_tbl(18).column_name  := 'C_ATTRIBUTE16';
23147               l_serial_attributes_tbl(18).column_value  := l_msnt_rec.c_attribute16;
23148               l_serial_attributes_tbl(19).column_name  := 'C_ATTRIBUTE17';
23149               l_serial_attributes_tbl(19).column_value  := l_msnt_rec.c_attribute17;
23150               l_serial_attributes_tbl(20).column_name  := 'C_ATTRIBUTE18';
23151               l_serial_attributes_tbl(20).column_value  := l_msnt_rec.c_attribute18;
23152               l_serial_attributes_tbl(21).column_name  := 'C_ATTRIBUTE19';
23153               l_serial_attributes_tbl(21).column_value  := l_msnt_rec.c_attribute19;
23154               l_serial_attributes_tbl(22).column_name  := 'C_ATTRIBUTE20';
23155               l_serial_attributes_tbl(22).column_value  := l_msnt_rec.c_attribute20;
23156               l_serial_attributes_tbl(23).column_name  := 'D_ATTRIBUTE1';
23157               l_serial_attributes_tbl(23).column_value  := l_msnt_rec.d_attribute1;
23158               l_serial_attributes_tbl(24).column_name  := 'D_ATTRIBUTE2';
23159               l_serial_attributes_tbl(24).column_value  := l_msnt_rec.d_attribute2;
23160               l_serial_attributes_tbl(25).column_name  := 'D_ATTRIBUTE3';
23161               l_serial_attributes_tbl(25).column_value  := l_msnt_rec.d_attribute3;
23162               l_serial_attributes_tbl(26).column_name  := 'D_ATTRIBUTE4';
23163               l_serial_attributes_tbl(26).column_value  := l_msnt_rec.d_attribute4;
23164               l_serial_attributes_tbl(27).column_name  := 'D_ATTRIBUTE5';
23165               l_serial_attributes_tbl(27).column_value  := l_msnt_rec.d_attribute5;
23166               l_serial_attributes_tbl(28).column_name  := 'D_ATTRIBUTE6';
23167               l_serial_attributes_tbl(28).column_value  := l_msnt_rec.d_attribute6;
23168               l_serial_attributes_tbl(29).column_name  := 'D_ATTRIBUTE7';
23169               l_serial_attributes_tbl(29).column_value  := l_msnt_rec.d_attribute7;
23170               l_serial_attributes_tbl(30).column_name  := 'D_ATTRIBUTE8';
23171               l_serial_attributes_tbl(30).column_value  := l_msnt_rec.d_attribute8;
23172               l_serial_attributes_tbl(31).column_name  := 'D_ATTRIBUTE9';
23173               l_serial_attributes_tbl(31).column_value  := l_msnt_rec.d_attribute9;
23174               l_serial_attributes_tbl(32).column_name  := 'D_ATTRIBUTE10';
23175               l_serial_attributes_tbl(32).column_value  := l_msnt_rec.d_attribute10;
23176               l_serial_attributes_tbl(33).column_name  := 'N_ATTRIBUTE1';
23177               l_serial_attributes_tbl(33).column_value  := l_msnt_rec.n_attribute1;
23178               l_serial_attributes_tbl(34).column_name  := 'N_ATTRIBUTE2';
23179               l_serial_attributes_tbl(34).column_value  := l_msnt_rec.n_attribute2;
23180               l_serial_attributes_tbl(35).column_name  := 'N_ATTRIBUTE3';
23181               l_serial_attributes_tbl(35).column_value  := l_msnt_rec.n_attribute3;
23182               l_serial_attributes_tbl(36).column_name  := 'N_ATTRIBUTE4';
23183               l_serial_attributes_tbl(36).column_value  := l_msnt_rec.n_attribute4;
23184               l_serial_attributes_tbl(37).column_name  := 'N_ATTRIBUTE5';
23185               l_serial_attributes_tbl(37).column_value := l_msnt_rec.n_attribute5;
23186               l_serial_attributes_tbl(38).column_name  := 'N_ATTRIBUTE6';
23187               l_serial_attributes_tbl(38).column_value := l_msnt_rec.n_attribute6;
23188               l_serial_attributes_tbl(39).column_name  := 'N_ATTRIBUTE7';
23189               l_serial_attributes_tbl(39).column_value := l_msnt_rec.n_attribute7;
23190               l_serial_attributes_tbl(40).column_name  := 'N_ATTRIBUTE8';
23191               l_serial_attributes_tbl(40).column_value := l_msnt_rec.n_attribute8;
23192               l_serial_attributes_tbl(41).column_name  := 'N_ATTRIBUTE9';
23193               l_serial_attributes_tbl(41).column_value := l_msnt_rec.n_attribute9;
23194               l_serial_attributes_tbl(42).column_name  := 'N_ATTRIBUTE10';
23195               l_serial_attributes_tbl(42).column_value := l_msnt_rec.n_attribute10;
23196               l_serial_attributes_tbl(43).column_name  := 'STATUS_ID';
23197               l_serial_attributes_tbl(43).column_value := l_msnt_rec.status_id;
23198               l_serial_attributes_tbl(44).column_name  := 'TERRITORY_CODE';
23199               l_serial_attributes_tbl(44).column_value := l_msnt_rec.territory_code;
23200               l_serial_attributes_tbl(45).column_name   := 'ATTRIBUTE_CATEGORY';
23201               l_serial_attributes_tbl(45).column_value  := l_msnt_rec.attribute_category;
23202               l_serial_attributes_tbl(46).column_name   := 'ATTRIBUTE1';
23203               l_serial_attributes_tbl(46).column_value  := l_msnt_rec.attribute1;
23204               l_serial_attributes_tbl(47).column_name   := 'ATTRIBUTE2';
23205               l_serial_attributes_tbl(47).column_value  := l_msnt_rec.attribute2;
23206               l_serial_attributes_tbl(48).column_name   := 'ATTRIBUTE3';
23207               l_serial_attributes_tbl(48).column_value  := l_msnt_rec.attribute3;
23208               l_serial_attributes_tbl(49).column_name   := 'ATTRIBUTE4';
23209               l_serial_attributes_tbl(49).column_value   := l_msnt_rec.attribute4;
23210               l_serial_attributes_tbl(50).column_name   := 'ATTRIBUTE5';
23211               l_serial_attributes_tbl(50).column_value   := l_msnt_rec.attribute5;
23212               l_serial_attributes_tbl(51).column_name   := 'ATTRIBUTE6';
23213               l_serial_attributes_tbl(51).column_value   := l_msnt_rec.attribute6;
23214               l_serial_attributes_tbl(52).column_name   := 'ATTRIBUTE7';
23215               l_serial_attributes_tbl(52).column_value   := l_msnt_rec.attribute7;
23216               l_serial_attributes_tbl(53).column_name  := 'ATTRIBUTE8';
23217               l_serial_attributes_tbl(53).column_value  := l_msnt_rec.attribute8;
23218               l_serial_attributes_tbl(54).column_name  := 'ATTRIBUTE9';
23219               l_serial_attributes_tbl(54).column_value  := l_msnt_rec.attribute9;
23220               l_serial_attributes_tbl(55).column_name  := 'ATTRIBUTE10';
23221               l_serial_attributes_tbl(55).column_value  := l_msnt_rec.attribute10;
23222               l_serial_attributes_tbl(56).column_name  := 'ATTRIBUTE11';
23223               l_serial_attributes_tbl(56).column_value  := l_msnt_rec.attribute11;
23224               l_serial_attributes_tbl(57).column_name  := 'ATTRIBUTE12';
23225               l_serial_attributes_tbl(57).column_value  := l_msnt_rec.attribute12;
23226               l_serial_attributes_tbl(58).column_name  := 'ATTRIBUTE13';
23227               l_serial_attributes_tbl(58).column_value  := l_msnt_rec.attribute13;
23228               l_serial_attributes_tbl(59).column_name  := 'ATTRIBUTE14';
23229               l_serial_attributes_tbl(59).column_value  := l_msnt_rec.attribute14;
23230               l_serial_attributes_tbl(60).column_name  := 'ATTRIBUTE15';
23231               l_serial_attributes_tbl(60).column_value  := l_msnt_rec.attribute15;
23232 
23233               --R12: Get the EPC info for this MSNT
23234               get_epc_info(p_mode          => 2
23235                    ,p_ser_if_rowid => l_msnt_rec.ROWID
23236                    ,x_epc_column   => l_epc_column
23237                    ,x_epc_value    => l_epc_value
23238                    );
23239 
23240               IF (l_debug = 1) THEN
23241                  print_debug('l_epc_column:'||l_epc_column||' l_epc_value:'||l_epc_value,4);
23242               END IF;
23243 
23244               --Validate the serials
23245               FOR SERIALQTY IN 1..L_SERIAL_QUANTITY LOOP
23246 
23247                 l_progress := 'WMSINB-24133';
23248 
23249                 L_CUR_NUMBER := L_FROM_SER_NUMBER+SERIALQTY -1;
23250                 if L_FROM_SER_NUMBER = -1 and  L_TO_SER_NUMBER = -1 then
23251                       L_SERIAL_NUMBER  := L_MSNT_REC.fm_serial_number;
23252                 else
23253                       L_SERIAL_NUMBER :=
23254                     SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
23255                   LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
23256                   LENGTH(L_CUR_NUMBER))
23257                     ||L_CUR_NUMBER;
23258                 End if;
23259 
23260                 l_progress := 'WMSINB-24141';
23261 
23262                 BEGIN
23263                   SELECT CURRENT_ORGANIZATION_ID
23264                     , current_status
23265                     , lot_number
23266                     , Decode(lpn_id,0,NULL,lpn_id)
23267                     , inspection_status
23268                     , group_mark_id
23269                     INTO L_CURR_ORG_ID
23270                     , l_curr_status
23271                     , l_curr_lot_num
23272                     , l_curr_lpn_id
23273                     , l_inspection_status
23274                     , l_group_mark_id
23275                     FROM MTL_SERIAL_NUMBERS
23276                     WHERE SERIAL_NUMBER = l_serial_number
23277                     AND inventory_item_id = l_item_id;
23278 
23279                   l_serial_exists := 1;
23280                   l_progress := 'WMSINB-24161';
23281                 EXCEPTION
23282                   WHEN no_data_found THEN
23283                      l_serial_exists := 0;
23284                      l_progress := 'WMSINB-24165';
23285                 END;
23286 
23287                 IF (l_debug = 1) THEN
23288                   print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL EXISTS: '||l_serial_exists||' : '||l_progress, 1);
23289                   print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NUMBER: '||l_serial_number||' : '||l_progress, 1);
23290                   print_debug('VALIDATE_LOT_SERIAL_INFO: CURR STATUS: '||l_curr_status||' : '||l_progress, 1);
23291                   print_debug('VALIDATE_LOT_SERIAL_INFO: CURR ORG ID: '||l_curr_org_id||' : '||l_progress, 1);
23292                   print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LPN ID: '||l_curr_lpn_id||' : '||l_progress, 1);
23293                   print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LOT NUM: '||l_curr_lot_num||' : '||l_progress, 1);
23294                   print_debug('VALIDATE_LOT_SERIAL_INFO: INSPECT STS: '||l_inspection_status||' : '||l_progress, 1);
23295                   print_debug('VALIDATE_LOT_SERIAL_INFO: GROUP MARK ID: '||l_group_mark_id||' : '||l_progress, 1);
23296                   print_debug('VALIDATE_LOT_SERIAL_INFO: RESTRICT RCPT SER: '||l_restrict_rcpt_ser||' : '||l_progress, 1);
23297                   l_progress := 'WMSINB-24178';
23298                 END IF;
23299 
23300                 IF (l_serial_exists = 1) THEN
23301                   IF l_curr_org_id <> l_org_id THEN
23302                      --raise error
23303                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23304                      fnd_msg_pub.ADD;
23305                      l_progress := 'WMSINB-24186';
23306                      RAISE fnd_api.g_exc_error;
23307                   ELSE
23308                     IF ((l_curr_lot_num IS NOT NULL) AND
23309                       (l_curr_lot_num <> l_mtlt_rec.lot_number)
23310                       AND (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
23311                         --raise error
23312                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23313                         fnd_msg_pub.ADD;
23314                         l_progress := 'WMSINB-24193';
23315                         RAISE fnd_api.g_exc_error;
23316                     END IF;
23317                   END IF;
23318 
23319                   /* Bug#6670394
23320                      * In order to allow the Issued out Serial numbers during
23321                      * ASN import transaction made the following changes.
23322                      */
23323                   IF l_curr_status NOT IN (1,4,6) THEN --Bug#6670394
23324                      --raise error
23325                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23326                      fnd_msg_pub.ADD;
23327                      l_progress := 'WMSINB-24202';
23328                      RAISE fnd_api.g_exc_error;
23329                   END IF;
23330 
23331                   IF (Nvl(l_group_mark_id, -99) = -7937) THEN
23332                      --raise error
23333                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23334                      fnd_msg_pub.ADD;
23335                      l_progress := 'WMSINB-24210';
23336                      RAISE fnd_api.g_exc_error;
23337                   END IF;
23338 
23339                   IF (Nvl(l_curr_status, 1) IN (1,6)) THEN
23340                      --validate and update the attributes.
23341                      inv_serial_number_pub.validate_update_serial_att
23342                        (x_return_status     => x_return_status,
23343                     x_msg_count         => x_msg_count,
23344                     x_msg_data          => x_msg_data,
23345                     x_validation_status => l_validation_status,
23346                     p_serial_number     => l_serial_number,
23347                     p_organization_id   => l_org_id,
23348                     p_inventory_item_id => l_item_id,
23349                     p_serial_att_tbl    => l_serial_attributes_tbl,
23350                     p_validate_only     => FALSE
23351                     );
23352 
23353                      IF (l_validation_status <> 'Y'
23354                      OR x_return_status <> g_ret_sts_success) THEN
23355                     --raise error
23356                     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23357                     fnd_msg_pub.ADD;
23358                     l_progress := 'WMSINB-24215';
23359                     RAISE fnd_api.g_exc_error;
23360                      END IF;
23361                   END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
23362 
23363                   --UPDATE GROUP_MARK_ID TO -7937
23364                   IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
23365                      --raise error
23366                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23367                      fnd_msg_pub.ADD;
23368                      l_progress := 'WMSINB-24219';
23369                      RAISE fnd_api.g_exc_error;
23370                   END IF;
23371                 ELSE --IF (l_serial_exists = 1) THEN
23372                   IF l_serial_number_control_code = 5 THEN
23373                      --PERFORM SERIAL VALIDATION FOR NEW SERIAL
23374                      --(INCLUDING ATT VALIDATION)
23375                      --CREATE MSN
23376 
23377                     inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
23378                                            , p_inventory_item_id => l_item_id
23379                                            , p_organization_id => l_org_id
23380                                            , p_from_serial_number => l_serial_number
23381                                            , p_to_serial_number => l_serial_number
23382                                            , p_initialization_date => SYSDATE
23383                                            , p_completion_date => NULL
23384                                            , p_ship_date => NULL
23385                                            , p_revision => l_item_revision
23386                                            , p_lot_number => l_mtlt_rec.lot_number
23387                                            , p_current_locator_id => l_loc_id
23388                                            , p_subinventory_code => l_sub_code
23389                                            , p_trx_src_id => NULL
23390                                            , p_unit_vendor_id => NULL
23391                                            , p_vendor_lot_number => l_mtlt_rec.supplier_lot_number
23392                                            , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
23393                                            , p_receipt_issue_type => NULL
23394                                            , p_txn_src_id => NULL
23395                                            , p_txn_src_name => NULL
23396                                            , p_txn_src_type_id => NULL
23397                                            , p_transaction_id => NULL
23398                                            , p_current_status => 1
23399                                            , p_parent_item_id => NULL
23400                                            , p_parent_serial_number => NULL
23401                                            , p_cost_group_id => NULL
23402                                            , p_transaction_action_id => 27
23403                                            , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
23404                                            , p_status_id => NULL
23405                                            , p_inspection_status => NULL
23406                                            , x_object_id => l_object_id
23407                                            , x_return_status => x_return_status
23408                                            , x_msg_count => x_msg_count
23409                                            , x_msg_data => x_msg_data);
23410 
23411                     IF (x_return_status <> g_ret_sts_success) THEN
23412                       --raise error
23413                       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23414                       fnd_msg_pub.ADD;
23415                       l_progress := 'WMSINB-24225';
23416                       RAISE fnd_api.g_exc_error;
23417                     END IF;
23418 
23419                     --validate and update the attributes.
23420                     inv_serial_number_pub.validate_update_serial_att
23421                        (x_return_status     => x_return_status,
23422                         x_msg_count         => x_msg_count,
23423                         x_msg_data          => x_msg_data,
23424                         x_validation_status => l_validation_status,
23425                         p_serial_number     => l_serial_number,
23426                         p_organization_id   => l_org_id,
23427                         p_inventory_item_id => l_item_id,
23428                         p_serial_att_tbl    => l_serial_attributes_tbl,
23429                         p_validate_only     => FALSE
23430                         );
23431 
23432                     IF (l_validation_status <> 'Y'
23433                       OR x_return_status <> g_ret_sts_success) THEN
23434                       --raise error
23435                       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23436                       fnd_msg_pub.ADD;
23437                       l_progress := 'WMSINB-24260';
23438                       RAISE fnd_api.g_exc_error;
23439                     END IF;
23440 
23441                     --UPDATE GROUP_MARK_ID TO -7937
23442                     IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
23443                       --raise error
23444                       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23445                       fnd_msg_pub.ADD;
23446                       l_progress := 'WMSINB-24267';
23447                       RAISE fnd_api.g_exc_error;
23448                     END IF;
23449                   ELSE
23450                      --raise error
23451                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23452                      fnd_msg_pub.ADD;
23453                      l_progress := 'WMSINB-24274';
23454                      RAISE fnd_api.g_exc_error;
23455                   END IF;
23456                 END IF; --IF (l_serial_exists = 1) THEN
23457 
23458                 --Call EPC API here for ASN Import
23459                 IF (l_epc_column IS NOT NULL) THEN
23460                   IF (Nvl(g_lpn_group_id,-999) <> l_lpn_grp_id) THEN
23461                      g_lpn_group_id := l_lpn_grp_id;
23462                      SELECT wms_epc_s2.NEXTVAL
23463                        INTO g_epc_group_id
23464                        FROM dual;
23465                   END IF;
23466 
23467                   IF (l_debug = 1) THEN
23468                      print_debug('Calling populate_outside_epc',4);
23469                      print_debug(' p_group_id       => '||g_epc_group_id,4);
23470                      print_debug(' p_cross_ref_type => '||2,4);
23471                      print_debug(' p_epc            => '||l_epc_value,4);
23472                      print_debug(' p_serial_number  => '||l_serial_number,4);
23473                   END IF;
23474 
23475                   wms_epc_pvt.populate_outside_epc
23476                     (p_group_id        => g_epc_group_id
23477                      ,p_cross_ref_type => 2 --LPN-EPC
23478                      ,p_serial_number  => l_serial_number
23479                      ,p_epc            => l_epc_value
23480                      ,x_return_status  => l_return_status
23481                      ,x_return_mesg    => l_msg_data
23482                      );
23483 
23484                 END IF;--IF (l_epc_column IS NOT NULL) THEN
23485               END LOOP; -- FOR 1..L_SERIAL_QUANTITY
23486             END LOOP; --FETCH C_MSNT_LOTSERIAL INTO L_MSNT_REC;
23487 
23488             CLOSE c_msnt_lotserial;
23489 
23490             IF (l_num_msnt_recs > 0) THEN
23491                 IF l_mtlt_rec.primary_quantity <> l_tot_msnt_serial_qty THEN
23492                    --raise error
23493                    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23494                    fnd_msg_pub.ADD;
23495                    l_progress := 'WMSINB-24288';
23496                    RAISE fnd_api.g_exc_error;
23497                 END IF;
23498             ELSE
23499                 IF (l_serial_number_control_code IN (2,5)
23500                 OR (l_serial_number_control_code = 6
23501                     AND l_source_document_code IN ('RMA','REQ','INVENTORY'))) THEN
23502                    --raise error
23503                    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23504                    fnd_msg_pub.ADD;
23505                    l_progress := 'WMSINB-24295';
23506                    RAISE fnd_api.g_exc_error;
23507                 END IF;
23508             END IF;
23509 
23510           END IF; -- IF (L_SERIAL_NUMBER_CONTROL_CODE IN (2,5)) THEN
23511         END LOOP; --FETCH C_MTLT INTO L_MTLT_REC;
23512 
23513         CLOSE c_mtlt;
23514 
23515           /* Bug 4546519 : l_tot_mtlt_prim_qty is a computed floating point number.
23516            **  In the following condition, it is necessary to use round function for
23517            **  comparing the floating point values.
23518            */
23519         IF (l_num_mtlt_recs > 0) THEN
23520           IF (ROUND(l_tot_mtlt_prim_qty,5) <> ROUND(l_rti_primary_qty,5)) THEN
23521             -- Bug# 4225766 Compare transaction qty there can be a difference in primary qty
23522             -- if there is a lot specific conversion
23523             IF (ROUND(l_tot_mtlt_trans_qty,5) <> ROUND(l_rti_trans_qty,5)) THEN -- Bug# 4225766
23524                 --raise error
23525                 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23526                 fnd_msg_pub.ADD;
23527                 l_progress := 'WMSINB-24309';
23528                 RAISE fnd_api.g_exc_error;
23529             END IF; -- Bug# 4225766
23530           END IF;
23531         END IF;
23532       ELSIF l_serial_number_control_code IN (2,5) THEN --IF (L_LOT_CONTROL_CODE = 2) THEN
23533 
23534         IF (l_debug = 1) THEN
23535               print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROLLED: '||l_progress, 1);
23536               print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROL CODE: '||l_serial_number_control_code||' : '||l_progress, 1);
23537               print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||l_source_document_code||' : '||l_progress, 1);
23538               l_progress := 'WMSINB-24319';
23539         END IF;
23540         L_NUM_MSNT_RECS := 0;
23541         l_tot_msnt_serial_qty := 0;
23542 
23543         OPEN C_MSNT(L_RTI_ID);
23544         LOOP
23545           FETCH C_MSNT INTO L_MSNT_REC;
23546 
23547           EXIT WHEN C_MSNT%NOTFOUND;
23548 
23549           L_NUM_MSNT_RECS := L_NUM_MSNT_RECS + 1;
23550 
23551           L_SERIAL_QUANTITY :=
23552             INV_SERIAL_NUMBER_PUB.GET_SERIAL_DIFF(L_MSNT_REC.FM_SERIAL_NUMBER,
23553                               L_MSNT_REC.TO_SERIAL_NUMBER);
23554 
23555           l_tot_msnt_serial_qty := l_tot_msnt_serial_qty + l_serial_quantity;
23556 
23557           INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.FM_SERIAL_NUMBER, L_TEMP_PREFIX, L_FROM_SER_NUMBER);
23558           INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.TO_SERIAL_NUMBER, L_TEMP_PREFIX, L_TO_SER_NUMBER);
23559 
23560           IF (l_debug = 1) THEN
23561              print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL QUANTITY: '||l_serial_quantity||' : '||l_progress, 1);
23562              print_debug('VALIDATE_LOT_SERIAL_INFO: L_TEMP_PREFIX: '||L_TEMP_PREFIX, 1);
23563              l_progress := 'WMSINB-24343';
23564           END IF;
23565 
23566           --populate attributes table
23567           l_serial_attributes_tbl(1).column_name   := 'SERIAL_ATTRIBUTE_CATEGORY';
23568           l_serial_attributes_tbl(1).column_value  := l_msnt_rec.serial_attribute_category;
23569           l_serial_attributes_tbl(2).column_name   := 'ORIGINATION_DATE';
23570           l_serial_attributes_tbl(2).column_value  := l_msnt_rec.origination_date;
23571           l_serial_attributes_tbl(3).column_name   := 'C_ATTRIBUTE1';
23572           l_serial_attributes_tbl(3).column_value  := l_msnt_rec.c_attribute1;
23573           l_serial_attributes_tbl(4).column_name   := 'C_ATTRIBUTE2';
23574           l_serial_attributes_tbl(4).column_value  := l_msnt_rec.c_attribute2;
23575           l_serial_attributes_tbl(5).column_name   := 'C_ATTRIBUTE3';
23576           l_serial_attributes_tbl(5).column_value  := l_msnt_rec.c_attribute3;
23577           l_serial_attributes_tbl(6).column_name   := 'C_ATTRIBUTE4';
23578           l_serial_attributes_tbl(6).column_value   := l_msnt_rec.c_attribute4;
23579           l_serial_attributes_tbl(7).column_name   := 'C_ATTRIBUTE5';
23580           l_serial_attributes_tbl(7).column_value   := l_msnt_rec.c_attribute5;
23581           l_serial_attributes_tbl(8).column_name   := 'C_ATTRIBUTE6';
23582           l_serial_attributes_tbl(8).column_value   := l_msnt_rec.c_attribute6;
23583           l_serial_attributes_tbl(9).column_name   := 'C_ATTRIBUTE7';
23584           l_serial_attributes_tbl(9).column_value   := l_msnt_rec.c_attribute7;
23585           l_serial_attributes_tbl(10).column_name  := 'C_ATTRIBUTE8';
23586           l_serial_attributes_tbl(10).column_value  := l_msnt_rec.c_attribute8;
23587           l_serial_attributes_tbl(11).column_name  := 'C_ATTRIBUTE9';
23588           l_serial_attributes_tbl(11).column_value  := l_msnt_rec.c_attribute9;
23589           l_serial_attributes_tbl(12).column_name  := 'C_ATTRIBUTE10';
23590           l_serial_attributes_tbl(12).column_value  := l_msnt_rec.c_attribute10;
23591           l_serial_attributes_tbl(13).column_name  := 'C_ATTRIBUTE11';
23592           l_serial_attributes_tbl(13).column_value  := l_msnt_rec.c_attribute11;
23593           l_serial_attributes_tbl(14).column_name  := 'C_ATTRIBUTE12';
23594           l_serial_attributes_tbl(14).column_value  := l_msnt_rec.c_attribute12;
23595           l_serial_attributes_tbl(15).column_name  := 'C_ATTRIBUTE13';
23596           l_serial_attributes_tbl(15).column_value  := l_msnt_rec.c_attribute13;
23597           l_serial_attributes_tbl(16).column_name  := 'C_ATTRIBUTE14';
23598           l_serial_attributes_tbl(16).column_value  := l_msnt_rec.c_attribute14;
23599           l_serial_attributes_tbl(17).column_name  := 'C_ATTRIBUTE15';
23600           l_serial_attributes_tbl(17).column_value  := l_msnt_rec.c_attribute15;
23601           l_serial_attributes_tbl(18).column_name  := 'C_ATTRIBUTE16';
23602           l_serial_attributes_tbl(18).column_value  := l_msnt_rec.c_attribute16;
23603           l_serial_attributes_tbl(19).column_name  := 'C_ATTRIBUTE17';
23604           l_serial_attributes_tbl(19).column_value  := l_msnt_rec.c_attribute17;
23605           l_serial_attributes_tbl(20).column_name  := 'C_ATTRIBUTE18';
23606           l_serial_attributes_tbl(20).column_value  := l_msnt_rec.c_attribute18;
23607           l_serial_attributes_tbl(21).column_name  := 'C_ATTRIBUTE19';
23608           l_serial_attributes_tbl(21).column_value  := l_msnt_rec.c_attribute19;
23609           l_serial_attributes_tbl(22).column_name  := 'C_ATTRIBUTE20';
23610           l_serial_attributes_tbl(22).column_value  := l_msnt_rec.c_attribute20;
23611           l_serial_attributes_tbl(23).column_name  := 'D_ATTRIBUTE1';
23612           l_serial_attributes_tbl(23).column_value  := l_msnt_rec.d_attribute1;
23613           l_serial_attributes_tbl(24).column_name  := 'D_ATTRIBUTE2';
23614           l_serial_attributes_tbl(24).column_value  := l_msnt_rec.d_attribute2;
23615           l_serial_attributes_tbl(25).column_name  := 'D_ATTRIBUTE3';
23616           l_serial_attributes_tbl(25).column_value  := l_msnt_rec.d_attribute3;
23617           l_serial_attributes_tbl(26).column_name  := 'D_ATTRIBUTE4';
23618           l_serial_attributes_tbl(26).column_value  := l_msnt_rec.d_attribute4;
23619           l_serial_attributes_tbl(27).column_name  := 'D_ATTRIBUTE5';
23620           l_serial_attributes_tbl(27).column_value  := l_msnt_rec.d_attribute5;
23621           l_serial_attributes_tbl(28).column_name  := 'D_ATTRIBUTE6';
23622           l_serial_attributes_tbl(28).column_value  := l_msnt_rec.d_attribute6;
23623           l_serial_attributes_tbl(29).column_name  := 'D_ATTRIBUTE7';
23624           l_serial_attributes_tbl(29).column_value  := l_msnt_rec.d_attribute7;
23625           l_serial_attributes_tbl(30).column_name  := 'D_ATTRIBUTE8';
23626           l_serial_attributes_tbl(30).column_value  := l_msnt_rec.d_attribute8;
23627           l_serial_attributes_tbl(31).column_name  := 'D_ATTRIBUTE9';
23628           l_serial_attributes_tbl(31).column_value  := l_msnt_rec.d_attribute9;
23629           l_serial_attributes_tbl(32).column_name  := 'D_ATTRIBUTE10';
23630           l_serial_attributes_tbl(32).column_value  := l_msnt_rec.d_attribute10;
23631           l_serial_attributes_tbl(33).column_name  := 'N_ATTRIBUTE1';
23632           l_serial_attributes_tbl(33).column_value  := l_msnt_rec.n_attribute1;
23633           l_serial_attributes_tbl(34).column_name  := 'N_ATTRIBUTE2';
23634           l_serial_attributes_tbl(34).column_value  := l_msnt_rec.n_attribute2;
23635           l_serial_attributes_tbl(35).column_name  := 'N_ATTRIBUTE3';
23636           l_serial_attributes_tbl(35).column_value  := l_msnt_rec.n_attribute3;
23637           l_serial_attributes_tbl(36).column_name  := 'N_ATTRIBUTE4';
23638           l_serial_attributes_tbl(36).column_value  := l_msnt_rec.n_attribute4;
23639           l_serial_attributes_tbl(37).column_name  := 'N_ATTRIBUTE5';
23640           l_serial_attributes_tbl(37).column_value := l_msnt_rec.n_attribute5;
23641           l_serial_attributes_tbl(38).column_name  := 'N_ATTRIBUTE6';
23642           l_serial_attributes_tbl(38).column_value := l_msnt_rec.n_attribute6;
23643           l_serial_attributes_tbl(39).column_name  := 'N_ATTRIBUTE7';
23644           l_serial_attributes_tbl(39).column_value := l_msnt_rec.n_attribute7;
23645           l_serial_attributes_tbl(40).column_name  := 'N_ATTRIBUTE8';
23646           l_serial_attributes_tbl(40).column_value := l_msnt_rec.n_attribute8;
23647           l_serial_attributes_tbl(41).column_name  := 'N_ATTRIBUTE9';
23648           l_serial_attributes_tbl(41).column_value := l_msnt_rec.n_attribute9;
23649           l_serial_attributes_tbl(42).column_name  := 'N_ATTRIBUTE10';
23650           l_serial_attributes_tbl(42).column_value := l_msnt_rec.n_attribute10;
23651           l_serial_attributes_tbl(43).column_name  := 'STATUS_ID';
23652           l_serial_attributes_tbl(43).column_value := l_msnt_rec.status_id;
23653           l_serial_attributes_tbl(44).column_name  := 'TERRITORY_CODE';
23654           l_serial_attributes_tbl(44).column_value := l_msnt_rec.territory_code;
23655           l_serial_attributes_tbl(45).column_name   := 'ATTRIBUTE_CATEGORY';
23656           l_serial_attributes_tbl(45).column_value  := l_msnt_rec.attribute_category;
23657           l_serial_attributes_tbl(46).column_name   := 'ATTRIBUTE1';
23658           l_serial_attributes_tbl(46).column_value  := l_msnt_rec.attribute1;
23659           l_serial_attributes_tbl(47).column_name   := 'ATTRIBUTE2';
23660           l_serial_attributes_tbl(47).column_value  := l_msnt_rec.attribute2;
23661           l_serial_attributes_tbl(48).column_name   := 'ATTRIBUTE3';
23662           l_serial_attributes_tbl(48).column_value  := l_msnt_rec.attribute3;
23663           l_serial_attributes_tbl(49).column_name   := 'ATTRIBUTE4';
23664           l_serial_attributes_tbl(49).column_value   := l_msnt_rec.attribute4;
23665           l_serial_attributes_tbl(50).column_name   := 'ATTRIBUTE5';
23666           l_serial_attributes_tbl(50).column_value   := l_msnt_rec.attribute5;
23667           l_serial_attributes_tbl(51).column_name   := 'ATTRIBUTE6';
23668           l_serial_attributes_tbl(51).column_value   := l_msnt_rec.attribute6;
23669           l_serial_attributes_tbl(52).column_name   := 'ATTRIBUTE7';
23670           l_serial_attributes_tbl(52).column_value   := l_msnt_rec.attribute7;
23671           l_serial_attributes_tbl(53).column_name  := 'ATTRIBUTE8';
23672           l_serial_attributes_tbl(53).column_value  := l_msnt_rec.attribute8;
23673           l_serial_attributes_tbl(54).column_name  := 'ATTRIBUTE9';
23674           l_serial_attributes_tbl(54).column_value  := l_msnt_rec.attribute9;
23675           l_serial_attributes_tbl(55).column_name  := 'ATTRIBUTE10';
23676           l_serial_attributes_tbl(55).column_value  := l_msnt_rec.attribute10;
23677           l_serial_attributes_tbl(56).column_name  := 'ATTRIBUTE11';
23678           l_serial_attributes_tbl(56).column_value  := l_msnt_rec.attribute11;
23679           l_serial_attributes_tbl(57).column_name  := 'ATTRIBUTE12';
23680           l_serial_attributes_tbl(57).column_value  := l_msnt_rec.attribute12;
23681           l_serial_attributes_tbl(58).column_name  := 'ATTRIBUTE13';
23682           l_serial_attributes_tbl(58).column_value  := l_msnt_rec.attribute13;
23683           l_serial_attributes_tbl(59).column_name  := 'ATTRIBUTE14';
23684           l_serial_attributes_tbl(59).column_value  := l_msnt_rec.attribute14;
23685           l_serial_attributes_tbl(60).column_name  := 'ATTRIBUTE15';
23686           l_serial_attributes_tbl(60).column_value  := l_msnt_rec.attribute15;
23687 
23688 
23689           --R12: Get the EPC info for this MSNT
23690           get_epc_info(p_mode          => 2
23691                    ,p_ser_if_rowid => l_msnt_rec.ROWID
23692                    ,x_epc_column   => l_epc_column
23693                    ,x_epc_value    => l_epc_value
23694                    );
23695 
23696           IF (l_debug = 1) THEN
23697              print_debug('l_epc_column:'||l_epc_column||' l_epc_value:'||l_epc_value,4);
23698           END IF;
23699 
23700           --Validate the serials
23701           FOR SERIALQTY IN 1..L_SERIAL_QUANTITY LOOP
23702 
23703             L_CUR_NUMBER := L_FROM_SER_NUMBER+SERIALQTY -1;
23704 
23705             if L_FROM_SER_NUMBER = -1 and  L_TO_SER_NUMBER = -1 then
23706               L_SERIAL_NUMBER  := L_MSNT_REC.fm_serial_number;
23707             else
23708               L_SERIAL_NUMBER :=
23709                 SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
23710                   LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
23711                   LENGTH(L_CUR_NUMBER))
23712                 ||L_CUR_NUMBER;
23713             End if;
23714 
23715             --L_SERIAL_NUMBER :=
23716             --  SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
23717             -- LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
23718             -- LENGTH(L_FROM_SER_NUMBER))
23719             -- ||(L_FROM_SER_NUMBER+SERIALQTY -1);
23720 
23721             BEGIN
23722                 SELECT CURRENT_ORGANIZATION_ID
23723                   , current_status
23724                   , lot_number
23725                   , Decode(lpn_id,0,NULL,lpn_id)
23726                   , inspection_status
23727                   , group_mark_id
23728                   INTO L_CURR_ORG_ID
23729                   , l_curr_status
23730                   , l_curr_lot_num
23731                   , l_curr_lpn_id
23732                   , l_inspection_status
23733                   , l_group_mark_id
23734                   FROM MTL_SERIAL_NUMBERS
23735                   WHERE SERIAL_NUMBER = l_serial_number
23736                   AND inventory_item_id = l_item_id;
23737 
23738                 l_serial_exists := 1;
23739             EXCEPTION
23740                 WHEN no_data_found THEN
23741                    l_serial_exists := 0;
23742             END;
23743 
23744             IF (l_debug = 1) THEN
23745                 print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL EXISTS: '||l_serial_exists||' : '||l_progress, 1);
23746                 print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NUMBER: '||l_serial_number||' : '||l_progress, 1);
23747                 print_debug('VALIDATE_LOT_SERIAL_INFO: CURR STATUS: '||l_curr_status||' : '||l_progress, 1);
23748                 print_debug('VALIDATE_LOT_SERIAL_INFO: CURR ORG ID: '||l_curr_org_id||' : '||l_progress, 1);
23749                 print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LPN ID: '||l_curr_lpn_id||' : '||l_progress, 1);
23750                 print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LOT NUM: '||l_curr_lot_num||' : '||l_progress, 1);
23751                 print_debug('VALIDATE_LOT_SERIAL_INFO: INSPECT STS: '||l_inspection_status||' : '||l_progress, 1);
23752                 print_debug('VALIDATE_LOT_SERIAL_INFO: GROUP MARK ID: '||l_group_mark_id||' : '||l_progress, 1);
23753                 print_debug('VALIDATE_LOT_SERIAL_INFO: RESTRICT RCPT SER: '||l_restrict_rcpt_ser||' : '||l_progress, 1);
23754                 l_progress := 'WMSINB-24386';
23755             END IF;
23756 
23757             IF (l_serial_exists = 1) THEN
23758               IF l_curr_org_id <> l_org_id THEN
23759                  --raise error
23760                  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23761                  fnd_msg_pub.ADD;
23762                  l_progress := 'WMSINB-24394';
23763                  RAISE fnd_api.g_exc_error;
23764               ELSE
23765                    IF (l_curr_lot_num IS NOT NULL) THEN
23766                       --raise error
23767                       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23768                       fnd_msg_pub.ADD;
23769                       l_progress := 'WMSINB-24401';
23770                       RAISE fnd_api.g_exc_error;
23771                    END IF;
23772               END IF;
23773 
23774               IF l_curr_status NOT IN (1,4,6) THEN --Bug#6670394
23775                  --raise error
23776                  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23777                  fnd_msg_pub.ADD;
23778                  l_progress := 'WMSINB-24410';
23779                  RAISE fnd_api.g_exc_error;
23780               END IF;
23781 
23782               IF (Nvl(l_group_mark_id, -99) = -7937) THEN
23783                  --raise error
23784                  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23785                  fnd_msg_pub.ADD;
23786                  l_progress := 'WMSINB-24418';
23787                  RAISE fnd_api.g_exc_error;
23788               END IF;
23789 
23790               IF (Nvl(l_curr_status, 1) in (1,6)) THEN
23791                  --validate and update the attributes.
23792                  inv_serial_number_pub.validate_update_serial_att
23793                    (x_return_status     => x_return_status,
23794                     x_msg_count         => x_msg_count,
23795                     x_msg_data          => x_msg_data,
23796                     x_validation_status => l_validation_status,
23797                     p_serial_number     => l_serial_number,
23798                     p_organization_id   => l_org_id,
23799                     p_inventory_item_id => l_item_id,
23800                     p_serial_att_tbl    => l_serial_attributes_tbl,
23801                     p_validate_only     => FALSE
23802                     );
23803 
23804                  IF (l_validation_status <> 'Y'
23805                      OR x_return_status <> g_ret_sts_success) THEN
23806                     --raise error
23807                     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23808                     fnd_msg_pub.ADD;
23809                     l_progress := 'WMSINB-24424';
23810                     RAISE fnd_api.g_exc_error;
23811                  END IF;
23812               END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
23813 
23814               --UPDATE GROUP_MARK_ID TO -7937
23815               IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
23816                  --raise error
23817                  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23818                  fnd_msg_pub.ADD;
23819                  l_progress := 'WMSINB-24427';
23820                  RAISE fnd_api.g_exc_error;
23821               END IF;
23822             ELSE --IF (l_serial_exists = 1) THEN
23823               IF l_serial_number_control_code = 5 THEN
23824                  --PERFORM SERIAL VALIDATION FOR NEW SERIAL
23825                  --(INCLUDING ATT VALIDATION)
23826                  --CREATE MSN
23827 
23828                 inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
23829                                        , p_inventory_item_id => l_item_id
23830                                        , p_organization_id => l_org_id
23831                                        , p_from_serial_number => l_serial_number
23832                                        , p_to_serial_number => l_serial_number
23833                                        , p_initialization_date => SYSDATE
23834                                        , p_completion_date => NULL
23835                                        , p_ship_date => NULL
23836                                        , p_revision => l_item_revision
23837                                        , p_lot_number => NULL
23838                                        , p_current_locator_id => l_loc_id
23839                                        , p_subinventory_code => l_sub_code
23840                                        , p_trx_src_id => NULL
23841                                        , p_unit_vendor_id => NULL
23842                                        , p_vendor_lot_number => NULL
23843                                        , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
23844                                        , p_receipt_issue_type => NULL
23845                                        , p_txn_src_id => NULL
23846                                        , p_txn_src_name => NULL
23847                                        , p_txn_src_type_id => NULL
23848                                        , p_transaction_id => NULL
23849                                        , p_current_status => 1
23850                                        , p_parent_item_id => NULL
23851                                        , p_parent_serial_number => NULL
23852                                        , p_cost_group_id => NULL
23853                                        , p_transaction_action_id => 27
23854                                        , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
23855                                        , p_status_id => NULL
23856                                        , p_inspection_status => NULL
23857                                        , x_object_id => l_object_id
23858                                        , x_return_status => x_return_status
23859                                        , x_msg_count => x_msg_count
23860                                        , x_msg_data => x_msg_data);
23861 
23862                 IF (x_return_status <> g_ret_sts_success) THEN
23863                    --raise error
23864                    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23865                    fnd_msg_pub.ADD;
23866                    l_progress := 'WMSINB-24430';
23867                    RAISE fnd_api.g_exc_error;
23868                 END IF;
23869 
23870                 --validate and update the attributes.
23871                 inv_serial_number_pub.validate_update_serial_att
23872                   (x_return_status     => x_return_status,
23873                    x_msg_count         => x_msg_count,
23874                    x_msg_data          => x_msg_data,
23875                    x_validation_status => l_validation_status,
23876                    p_serial_number     => l_serial_number,
23877                    p_organization_id   => l_org_id,
23878                    p_inventory_item_id => l_item_id,
23879                    p_serial_att_tbl    => l_serial_attributes_tbl,
23880                    p_validate_only     => FALSE
23881                    );
23882 
23883                 IF (l_validation_status <> 'Y'
23884                     OR x_return_status <> g_ret_sts_success) THEN
23885                    --raise error
23886                    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23887                    fnd_msg_pub.ADD;
23888                    l_progress := 'WMSINB-24470';
23889                    RAISE fnd_api.g_exc_error;
23890                 END IF;
23891 
23892                 --UPDATE GROUP_MARK_ID TO -7937
23893                 IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
23894                    --raise error
23895                    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23896                    fnd_msg_pub.ADD;
23897                    l_progress := 'WMSINB-24475';
23898                    RAISE fnd_api.g_exc_error;
23899                 END IF;
23900               ELSE
23901                    --raise error
23902                    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23903                    fnd_msg_pub.ADD;
23904                    l_progress := 'WMSINB-24482';
23905                    RAISE fnd_api.g_exc_error;
23906               END IF;
23907             END IF; --IF (l_serial_exists = 1) THEN
23908             --Call EPC API here for ASN Import
23909             IF (l_epc_column IS NOT NULL) THEN
23910               IF (Nvl(g_lpn_group_id,-999) <> l_lpn_grp_id) THEN
23911                  g_lpn_group_id := l_lpn_grp_id;
23912                  SELECT wms_epc_s2.NEXTVAL
23913                    INTO g_epc_group_id
23914                    FROM dual;
23915               END IF;
23916 
23917               IF (l_debug = 1) THEN
23918                  print_debug('Calling populate_outside_epc',4);
23919                  print_debug(' p_group_id       => '||g_epc_group_id,4);
23920                  print_debug(' p_cross_ref_type => '||2,4);
23921                  print_debug(' p_epc            => '||l_epc_value,4);
23922                  print_debug(' p_serial_number  => '||l_serial_number,4);
23923               END IF;
23924 
23925               wms_epc_pvt.populate_outside_epc
23926                 (p_group_id        => g_epc_group_id
23927                  ,p_cross_ref_type => 2 --LPN-EPC
23928                  ,p_serial_number  => l_serial_number
23929                  ,p_epc            => l_epc_value
23930                  ,x_return_status  => l_return_status
23931                  ,x_return_mesg    => l_msg_data
23932                  );
23933 
23934             END IF;--IF (l_epc_column IS NOT NULL) THEN
23935 
23936           END LOOP; -- FOR 1..L_SERIAL_QUANTITY
23937         END LOOP; --FETCH C_MSNT INTO L_MSNT_REC;
23938 
23939         CLOSE c_msnt;
23940 
23941         IF (l_num_msnt_recs > 0) THEN
23942               IF l_tot_msnt_serial_qty <> l_rti_primary_qty THEN
23943                  --raise error
23944                  fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
23945                  fnd_msg_pub.ADD;
23946                  l_progress := 'WMSINB-24496';
23947                  RAISE fnd_api.g_exc_error;
23948               END IF;
23949         END IF;
23950       END IF;--IF (l_lot_control_code = 2) THEN
23951     END IF;--IF (l_transaction_type = 'SHIP' AND l_source_document_code = 'PO') THEN
23952 
23953      --Validate lot/serial for returns/corrections
23954 
23955     IF (l_transaction_type IN ('CORRECT',G_RTR,G_RTV,G_RTC)) THEN
23956     --Query the parent txn type
23957       BEGIN
23958        SELECT transaction_type
23959          , parent_transaction_id
23960          INTO l_parent_txn_type
23961          , l_grand_parent_txn_id
23962          FROM rcv_transactions
23963          WHERE transaction_id = l_parent_transaction_id;
23964       EXCEPTION
23965        WHEN no_data_found THEN
23966           --raise an error
23967           l_progress := 'WMSINB-24517';
23968           RAISE fnd_api.g_exc_error;
23969       END;
23970 
23971       IF (l_debug = 1) THEN
23972          print_debug('VALIDATE_LOT_SERIAL_INFO: Parent Txn Type:'||l_parent_txn_type,1);
23973          print_debug('VALIDATE_LOT_SERIAL_INFO: Grand Parent Txn ID:'||l_grand_parent_txn_id,1);
23974          l_progress := 'WMSINB-24524';
23975       END IF;
23976 
23977       IF (l_grand_parent_txn_id > 0) THEN
23978         BEGIN
23979           SELECT transaction_type
23980           , parent_transaction_id
23981           INTO l_grand_parent_txn_type
23982           , l_great_grand_parent_txn_id
23983           FROM rcv_transactions
23984           WHERE transaction_id = l_grand_parent_txn_id;
23985         EXCEPTION
23986           WHEN no_data_found THEN
23987              --raise an error
23988              l_progress := 'WMSINB-24538';
23989              RAISE fnd_api.g_exc_error;
23990         END;
23991       END IF; --IF (l_grand_parent_txn_id > 0) THEN
23992 
23993       IF (l_debug = 1) THEN
23994          print_debug('VALIDATE_LOT_SERIAL_INFO: Grand Parent Txn Type:'||l_grand_parent_txn_type,1);
23995          print_debug('VALIDATE_LOT_SERIAL_INFO: Great Grand Parent Txn ID:'||l_great_grand_parent_txn_id,1);
23996          l_progress := 'WMSINB-24546';
23997       END IF;
23998 
23999       IF ((l_transaction_type = 'CORRECT' AND l_rti_primary_qty < 0)
24000           OR l_transaction_type IN (G_RTR,G_RTV,G_RTC)) THEN
24001          -- opm change bug# 3061052 added l_opm_lot_ctl check.
24002          /** INVCONV, Remove OPM specific lot control check  Punit Kumar */
24003         IF (l_lot_control_code = 2 /* OR l_opm_lot_ctl = 1 */) THEN
24004           IF (l_debug = 1) THEN
24005             print_debug('VALIDATE_LOT_SERIAL_INFO: Lot Controlled :'||l_progress, 1);
24006             l_progress := 'WMSINB-24555';
24007           END IF;
24008 
24009           l_num_mtlt_recs := 0;
24010           l_tot_mtlt_prim_qty := 0;
24011           l_tot_mtlt_trans_qty := 0; -- Bug# 4225766
24012 
24013           OPEN C_MTLT(L_RTI_ID);
24014           LOOP
24015             FETCH C_MTLT INTO L_MTLT_REC;
24016             EXIT WHEN C_MTLT%NOTFOUND;
24017 
24018             /* INVCONV , get L_MTLT_REC values into l_mln_rec which shall be passed to INV_NEW_LOT for lot creation */
24019 
24020             IF (l_debug = 1) THEN
24021                print_debug('INVCONV,Assigning values fetched from MTLT to l_mln_rec'||l_progress,1);
24022             END IF;
24023 
24024               l_mln_rec.LOT_NUMBER                := L_MTLT_REC.LOT_NUMBER                    ;
24025               l_mln_rec.LAST_UPDATE_DATE          := SYSDATE                                  ;
24026               l_mln_rec.LAST_UPDATED_BY           := L_MTLT_REC.LAST_UPDATED_BY               ;
24027               l_mln_rec.CREATION_DATE             := SYSDATE                                  ;
24028               l_mln_rec.CREATED_BY                := L_MTLT_REC.CREATED_BY                    ;
24029               l_mln_rec.LAST_UPDATE_LOGIN         := L_MTLT_REC.LAST_UPDATE_LOGIN             ;
24030               l_mln_rec.EXPIRATION_DATE           := L_MTLT_REC.LOT_EXPIRATION_DATE               ;
24031               l_mln_rec.ATTRIBUTE_CATEGORY        := L_MTLT_REC.ATTRIBUTE_CATEGORY            ;
24032               l_mln_rec.ATTRIBUTE1                := L_MTLT_REC.ATTRIBUTE1                    ;
24033               l_mln_rec.ATTRIBUTE2                := L_MTLT_REC.ATTRIBUTE2                    ;
24034               l_mln_rec.ATTRIBUTE3                := L_MTLT_REC.ATTRIBUTE3                    ;
24035               l_mln_rec.ATTRIBUTE4                := L_MTLT_REC.ATTRIBUTE4                    ;
24036               l_mln_rec.ATTRIBUTE5                := L_MTLT_REC.ATTRIBUTE5                    ;
24037               l_mln_rec.ATTRIBUTE6                := L_MTLT_REC.ATTRIBUTE6                    ;
24038               l_mln_rec.ATTRIBUTE7                := L_MTLT_REC.ATTRIBUTE7                    ;
24039               l_mln_rec.ATTRIBUTE8                := L_MTLT_REC.ATTRIBUTE8                    ;
24040               l_mln_rec.ATTRIBUTE9                := L_MTLT_REC.ATTRIBUTE9                    ;
24041               l_mln_rec.ATTRIBUTE10               := L_MTLT_REC.ATTRIBUTE10                   ;
24042               l_mln_rec.ATTRIBUTE11               := L_MTLT_REC.ATTRIBUTE11                   ;
24043               l_mln_rec.ATTRIBUTE12               := L_MTLT_REC.ATTRIBUTE12                   ;
24044               l_mln_rec.ATTRIBUTE13               := L_MTLT_REC.ATTRIBUTE13                   ;
24045               l_mln_rec.ATTRIBUTE14               := L_MTLT_REC.ATTRIBUTE14                   ;
24046               l_mln_rec.ATTRIBUTE15               := L_MTLT_REC.ATTRIBUTE15                   ;
24047               l_mln_rec.REQUEST_ID                := L_MTLT_REC.REQUEST_ID                    ;
24048               l_mln_rec.PROGRAM_APPLICATION_ID    := L_MTLT_REC.PROGRAM_APPLICATION_ID        ;
24049               l_mln_rec.PROGRAM_ID                := L_MTLT_REC.PROGRAM_ID                    ;
24050               l_mln_rec.PROGRAM_UPDATE_DATE       := L_MTLT_REC.PROGRAM_UPDATE_DATE           ;
24051               l_mln_rec.DESCRIPTION               := L_MTLT_REC.DESCRIPTION                   ;
24052               l_mln_rec.VENDOR_NAME               := L_MTLT_REC.VENDOR_NAME                   ;
24053               l_mln_rec.SUPPLIER_LOT_NUMBER       := L_MTLT_REC.SUPPLIER_LOT_NUMBER           ;
24054               l_mln_rec.GRADE_CODE                := L_MTLT_REC.GRADE_CODE                    ;
24055               l_mln_rec.ORIGINATION_DATE          := L_MTLT_REC.ORIGINATION_DATE              ;
24056               l_mln_rec.DATE_CODE                 := L_MTLT_REC.DATE_CODE                     ;
24057               l_mln_rec.STATUS_ID                 := L_MTLT_REC.STATUS_ID                     ;
24058               l_mln_rec.CHANGE_DATE               := L_MTLT_REC.CHANGE_DATE                   ;
24059               l_mln_rec.AGE                       := L_MTLT_REC.AGE                           ;
24060               l_mln_rec.RETEST_DATE               := L_MTLT_REC.RETEST_DATE                   ;
24061               l_mln_rec.MATURITY_DATE             := L_MTLT_REC.MATURITY_DATE                 ;
24062               l_mln_rec.LOT_ATTRIBUTE_CATEGORY    := L_MTLT_REC.LOT_ATTRIBUTE_CATEGORY        ;
24063               l_mln_rec.ITEM_SIZE                 := L_MTLT_REC.ITEM_SIZE                     ;
24064               l_mln_rec.COLOR                     := L_MTLT_REC.COLOR                         ;
24065               l_mln_rec.VOLUME                    := L_MTLT_REC.VOLUME                        ;
24066               l_mln_rec.VOLUME_UOM                := L_MTLT_REC.VOLUME_UOM                    ;
24067               l_mln_rec.PLACE_OF_ORIGIN           := L_MTLT_REC.PLACE_OF_ORIGIN               ;
24068               l_mln_rec.BEST_BY_DATE              := L_MTLT_REC.BEST_BY_DATE                  ;
24069               l_mln_rec.LENGTH                    := L_MTLT_REC.LENGTH                        ;
24070               l_mln_rec.LENGTH_UOM                := L_MTLT_REC.LENGTH_UOM                    ;
24071               l_mln_rec.RECYCLED_CONTENT          := L_MTLT_REC.RECYCLED_CONTENT              ;
24072               l_mln_rec.THICKNESS                 := L_MTLT_REC.THICKNESS                     ;
24073               l_mln_rec.THICKNESS_UOM             := L_MTLT_REC.THICKNESS_UOM                 ;
24074               l_mln_rec.WIDTH                     := L_MTLT_REC.WIDTH                         ;
24075               l_mln_rec.WIDTH_UOM                 := L_MTLT_REC.WIDTH_UOM                     ;
24076               l_mln_rec.CURL_WRINKLE_FOLD         := L_MTLT_REC.CURL_WRINKLE_FOLD             ;
24077               l_mln_rec.C_ATTRIBUTE1              := L_MTLT_REC.C_ATTRIBUTE1                  ;
24078               l_mln_rec.C_ATTRIBUTE2              := L_MTLT_REC.C_ATTRIBUTE2                  ;
24079               l_mln_rec.C_ATTRIBUTE3              := L_MTLT_REC.C_ATTRIBUTE3                  ;
24080               l_mln_rec.C_ATTRIBUTE4              := L_MTLT_REC.C_ATTRIBUTE4                  ;
24081               l_mln_rec.C_ATTRIBUTE5              := L_MTLT_REC.C_ATTRIBUTE5                  ;
24082               l_mln_rec.C_ATTRIBUTE6              := L_MTLT_REC.C_ATTRIBUTE6                  ;
24083               l_mln_rec.C_ATTRIBUTE7              := L_MTLT_REC.C_ATTRIBUTE7                  ;
24084               l_mln_rec.C_ATTRIBUTE8              := L_MTLT_REC.C_ATTRIBUTE8                  ;
24085               l_mln_rec.C_ATTRIBUTE9              := L_MTLT_REC.C_ATTRIBUTE9                  ;
24086               l_mln_rec.C_ATTRIBUTE10             := L_MTLT_REC.C_ATTRIBUTE10                 ;
24087               l_mln_rec.C_ATTRIBUTE11             := L_MTLT_REC.C_ATTRIBUTE11                 ;
24088               l_mln_rec.C_ATTRIBUTE12             := L_MTLT_REC.C_ATTRIBUTE12                 ;
24089               l_mln_rec.C_ATTRIBUTE13             := L_MTLT_REC.C_ATTRIBUTE13                 ;
24090               l_mln_rec.C_ATTRIBUTE14             := L_MTLT_REC.C_ATTRIBUTE14                 ;
24091               l_mln_rec.C_ATTRIBUTE15             := L_MTLT_REC.C_ATTRIBUTE15                 ;
24092               l_mln_rec.C_ATTRIBUTE16             := L_MTLT_REC.C_ATTRIBUTE16                 ;
24093               l_mln_rec.C_ATTRIBUTE17             := L_MTLT_REC.C_ATTRIBUTE17                 ;
24094               l_mln_rec.C_ATTRIBUTE18             := L_MTLT_REC.C_ATTRIBUTE18                 ;
24095               l_mln_rec.C_ATTRIBUTE19             := L_MTLT_REC.C_ATTRIBUTE19                 ;
24096               l_mln_rec.C_ATTRIBUTE20             := L_MTLT_REC.C_ATTRIBUTE20                 ;
24097               l_mln_rec.D_ATTRIBUTE1              := L_MTLT_REC.D_ATTRIBUTE1                  ;
24098               l_mln_rec.D_ATTRIBUTE2              := L_MTLT_REC.D_ATTRIBUTE2                  ;
24099               l_mln_rec.D_ATTRIBUTE3              := L_MTLT_REC.D_ATTRIBUTE3                  ;
24100               l_mln_rec.D_ATTRIBUTE4              := L_MTLT_REC.D_ATTRIBUTE4                  ;
24101               l_mln_rec.D_ATTRIBUTE5              := L_MTLT_REC.D_ATTRIBUTE5                  ;
24102               l_mln_rec.D_ATTRIBUTE6              := L_MTLT_REC.D_ATTRIBUTE6                  ;
24103               l_mln_rec.D_ATTRIBUTE7              := L_MTLT_REC.D_ATTRIBUTE7                  ;
24104               l_mln_rec.D_ATTRIBUTE8              := L_MTLT_REC.D_ATTRIBUTE8                  ;
24105               l_mln_rec.D_ATTRIBUTE9              := L_MTLT_REC.D_ATTRIBUTE9                  ;
24106               l_mln_rec.D_ATTRIBUTE10             := L_MTLT_REC.D_ATTRIBUTE10                 ;
24107               l_mln_rec.N_ATTRIBUTE1              := L_MTLT_REC.N_ATTRIBUTE1                  ;
24108               l_mln_rec.N_ATTRIBUTE2              := L_MTLT_REC.N_ATTRIBUTE2                  ;
24109               l_mln_rec.N_ATTRIBUTE3              := L_MTLT_REC.N_ATTRIBUTE3                  ;
24110               l_mln_rec.N_ATTRIBUTE4              := L_MTLT_REC.N_ATTRIBUTE4                  ;
24111               l_mln_rec.N_ATTRIBUTE5              := L_MTLT_REC.N_ATTRIBUTE5                  ;
24112               l_mln_rec.N_ATTRIBUTE6              := L_MTLT_REC.N_ATTRIBUTE6                  ;
24113               l_mln_rec.N_ATTRIBUTE7              := L_MTLT_REC.N_ATTRIBUTE7                  ;
24114               l_mln_rec.N_ATTRIBUTE8              := L_MTLT_REC.N_ATTRIBUTE8                  ;
24115               l_mln_rec.N_ATTRIBUTE9              := L_MTLT_REC.N_ATTRIBUTE9                  ;
24116               l_mln_rec.N_ATTRIBUTE10             := L_MTLT_REC.N_ATTRIBUTE10                 ;
24117               l_mln_rec.VENDOR_ID                 := L_MTLT_REC.VENDOR_ID                     ;
24118               l_mln_rec.TERRITORY_CODE            := L_MTLT_REC.TERRITORY_CODE                ;
24119               l_mln_rec.PARENT_LOT_NUMBER         := L_MTLT_REC.PARENT_LOT_NUMBER             ;
24120               l_mln_rec.ORIGINATION_TYPE          := L_MTLT_REC.ORIGINATION_TYPE              ;
24121               l_mln_rec.EXPIRATION_ACTION_DATE    := L_MTLT_REC.EXPIRATION_ACTION_DATE        ;
24122               l_mln_rec.EXPIRATION_ACTION_CODE    := L_MTLT_REC.EXPIRATION_ACTION_CODE        ;
24123               l_mln_rec.HOLD_DATE                 := L_MTLT_REC.HOLD_DATE                     ;
24124 
24125               L_NUM_MTLT_RECS := L_NUM_MTLT_RECS + 1;
24126               l_tot_mtlt_prim_qty := l_tot_mtlt_prim_qty + l_mtlt_rec.primary_quantity;
24127               l_tot_mtlt_trans_qty := l_tot_mtlt_trans_qty + l_mtlt_rec.transaction_quantity; -- Bug# 4225766
24128 
24129               IF (l_debug = 1) THEN
24130                 print_debug('VALIDATE_LOT_SERIAL_INFO: LOT NUMBER: '||l_mtlt_rec.lot_number||': '||l_progress, 1);
24131                 print_debug('VALIDATE_LOT_SERIAL_INFO: LOT PRIMARY QUANTITY: '||l_mtlt_rec.primary_quantity||': '||l_progress, 1);
24132                 l_progress := 'WMSINB-24573';
24133                 print_debug('INVCONV,Finished Assigning values fetched from MTLT to l_mln_rec'||l_progress,1);
24134               END IF;
24135 
24136               IF (l_parent_txn_type IN (g_rtv,g_rtr,g_rtc)) THEN
24137                 IF (l_grand_parent_txn_type <> 'DELIVER') THEN
24138                    IF NOT (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
24139                   --raise an error
24140                   l_progress := 'WMSINB-24580';
24141                   RAISE fnd_api.g_exc_error;
24142                    END IF; --IF NOT (lot_entered_on_parent(l_grand_parent_txn_id))
24143                 END IF; --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
24144               ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtr,g_rtc)) THEN
24145                 IF (l_parent_txn_type <> 'DELIVER') THEN
24146                    IF NOT (lot_entered_on_parent(l_parent_transaction_id)) THEN
24147                   --raise an error
24148                   l_progress := 'WMSINB-24588';
24149                   RAISE fnd_api.g_exc_error;
24150                    END IF;
24151                 END IF; --IF (l_parent_txn_type <> 'DELIVER') THEN
24152               END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtr,g_rtc)) THEN
24153 
24154               /*INVCONV , removed OPM specific fork*/
24155               BEGIN
24156                 ----IF (l_discrete_transaction) THEN
24157                 SELECT 1,parent_lot_number
24158                   INTO L_LOT_EXISTS ,l_parent_lot_number
24159                   FROM MTL_LOT_NUMBERS
24160                   WHERE ORGANIZATION_ID = L_ORG_ID
24161                   AND   INVENTORY_ITEM_ID = L_ITEM_ID
24162                   AND LOT_NUMBER = Ltrim(Rtrim(L_MTLT_REC.lot_number));
24163 
24164                 /*
24165                  ELSE -- opm change bug# 3061052 --IF (l_discrete_transaction) THEN
24166                    IF  Ltrim(Rtrim(L_MTLT_REC.sublot_num)) IS NOT NULL THEN
24167                   SELECT 1, LOT_ID
24168                     INTO L_LOT_EXISTS , l_opm_lot_id
24169                     FROM IC_LOTS_MST
24170                     WHERE ITEM_ID = l_opm_item_id
24171                     AND LOT_NO = Ltrim(Rtrim(L_MTLT_REC.lot_number))
24172                     AND SUBLOT_NO = Ltrim(Rtrim(L_MTLT_REC.sublot_num)) ;
24173                 ELSE
24174                   SELECT 1, LOT_ID
24175                     INTO L_LOT_EXISTS , l_opm_lot_id
24176                     FROM IC_LOTS_MST
24177                     WHERE ITEM_ID = l_opm_item_id
24178                     AND LOT_NO = Ltrim(Rtrim(L_MTLT_REC.lot_number))
24179                     AND SUBLOT_NO IS NULL ;
24180                    END IF;
24181                 END IF; --IF (l_discrete_transaction) THEN
24182               */
24183 
24184               EXCEPTION
24185                 WHEN NO_DATA_FOUND THEN
24186                   L_LOT_EXISTS := 0;
24187               END;
24188 
24189               IF (l_lot_exists = 1) THEN
24190 
24191                 /*INVCONV , validating for parent lot*/
24192                 IF  L_MTLT_REC.parent_lot_number IS NOT NULL THEN
24193                   IF L_MTLT_REC.parent_lot_number <> l_parent_lot_number THEN
24194                     fnd_message.set_name ('INV' , 'INV_CL_PARENT_INVALID' );
24195                     fnd_msg_pub.ADD;
24196                     RAISE fnd_api.g_exc_error;
24197                   END IF;
24198                 ELSE
24199                   L_MTLT_REC.parent_lot_number := l_parent_lot_number;
24200                 END IF;
24201 
24202 
24203                 IF (l_parent_txn_type IN (g_rtv, g_rtc)) THEN
24204                   IF (l_grand_parent_txn_type = 'DELIVER') THEN
24205 
24206                     /*INVCONV , remove OPM specific fork */
24207                     /*IF (l_discrete_transaction) THEN	 */
24208 
24209                     --PERFORM LOT MATERIAL STATUS CHECK
24210                     IF (l_transaction_type = g_rtv) THEN
24211                       l_transaction_type_id := 36;
24212                     ELSIF (l_transaction_type = g_rtc) THEN
24213                       l_transaction_type_id := 37;
24214                     ELSIF (l_transaction_type = g_rtr) THEN
24215                       IF (l_source_document_code = 'PO') THEN
24216                          l_transaction_type_id := 36;
24217                       ELSE
24218                          l_transaction_type_id := 37; --For RMA
24219                       END IF;
24220                     ELSE
24221                       IF (l_source_document_code = 'PO') THEN
24222                         l_transaction_type_id := 71;
24223                       ELSE
24224                         l_transaction_type_id := 72;
24225                       END IF;
24226                     END IF;
24227 
24228                     INV_LOT_TRX_VALIDATION_PUB.VALIDATE_MATERIAL_STATUS(X_RETURN_STATUS => X_RETURN_STATUS,
24229                                       X_MSG_COUNT => X_MSG_COUNT,
24230                                       X_MSG_DATA => X_MSG_DATA,
24231                                       X_VALIDATION_STATUS => L_VALIDATION_STATUS,
24232                                       P_TRANSACTION_TYPE_ID => l_transaction_type_id,
24233                                       P_ORGANIZATION_ID => L_ORG_ID,
24234                                       P_INVENTORY_ITEM_ID => L_ITEM_ID,
24235                                       P_LOT_NUMBER => L_MTLT_REC.LOT_NUMBER,
24236                                       P_SUBINVENTORY_CODE => L_SUB_CODE,
24237                                       P_LOCATOR_ID => L_LOC_ID,
24238                                       P_STATUS_ID => NULL);
24239                     IF X_RETURN_STATUS <> 'S' THEN
24240                       --RAISE ERROR
24241                       l_progress     := 'WMSINB-24661';
24242                       RAISE fnd_api.g_exc_error;
24243                     END IF;
24244 
24245                     IF (l_debug = 1) THEN
24246                       print_debug('VALIDATE_LOT_SERIAL_INFO: LOT MATERIAL VALIDATION STATUS: '||L_VALIDATION_STATUS||' : '||l_progress, 1);
24247                       l_progress := 'WMSINB-24667';
24248                     END IF;
24249 
24250                     IF L_VALIDATION_STATUS <> 'Y' THEN
24251                       --RAISE ERROR
24252                       l_progress     := 'WMSINB-24672';
24253                       RAISE fnd_api.g_exc_error;
24254                     END IF;
24255                     /* ELSE --IF (l_discrete_transaction) THEN
24256                      -- opm change bug# 3061052
24257                      gml_opm_roi_grp.validate_opm_lot(p_api_version	 	=> 1.0,
24258                               p_init_msg_lst	 	=> FND_API.G_FALSE,
24259                               p_mtlt_rowid		=> l_mtlt_rec.rowid,
24260                               p_new_lot	 	=> 'N',
24261                               p_opm_item_id		=> l_opm_item_id,
24262                               p_item_no		=> l_item_no,
24263                               p_lots_specified_on_parent => 'Y',
24264                               p_lot_id		=> l_opm_lot_id,
24265                               p_parent_txn_type	=> l_parent_txn_type,
24266                               p_grand_parent_txn_type => l_grand_parent_txn_type,
24267                               x_return_status 	=> x_return_status,
24268                               x_msg_data      	=> x_msg_data,
24269                               x_msg_count     	=> x_msg_count
24270                               );
24271 
24272                       */
24273                     IF (l_debug = 1) THEN
24274                       print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
24275                     END IF;
24276 
24277                     INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
24278                                                        x_return_status      		   => x_return_status
24279                                                       ,x_msg_data           		   => x_msg_data
24280                                                       ,x_msg_count          		   => x_msg_count
24281                                                       ,p_api_version	               => 1.0
24282                                                       ,p_init_msg_lst	            => FND_API.G_FALSE
24283                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
24284                                                       ,p_transaction_type_id 	      => l_transaction_type_id
24285                                                       ,p_new_lot			            => 'N'
24286                                                       ,p_item_id	 		            => l_item_id
24287                                                       ,p_to_organization_id		   => L_ORG_ID
24288                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
24289                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
24290                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
24291                                                       ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
24292                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
24293                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
24294                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
24295                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
24296                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
24297                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
24298                                                       ,p_rti_id	                  => L_RTI_ID
24299                                                       ,p_revision             	   => l_item_revision
24300                                                       ,p_subinventory_code  	      => L_SUB_CODE
24301                                                       ,p_locator_id           	   => l_loc_id
24302                                                       ,p_transaction_type           => l_transaction_type
24303                                                       ,p_parent_txn_type            => l_parent_txn_type
24304                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
24305                                                       );
24306 
24307                     /*INVCONV ,*/
24308                     IF (l_debug = 1) THEN
24309                        print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
24310                        print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
24311                     END IF;
24312 
24313                     IF X_RETURN_STATUS <> 'S' THEN
24314                       --RAISE ERROR
24315                       l_progress := 'WMSINB-24693';
24316                       RAISE fnd_api.g_exc_error;
24317                     END IF;
24318 
24319                     IF (l_debug = 1) THEN
24320                       print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
24321                     END IF;
24322                     /*END IF; --IF (l_discrete_transaction) THEN*/
24323                   ELSE --IF (l_grand_parent_txn_type = 'DELIVER') THEN
24324                     IF (validate_rs(NULL,l_grand_parent_txn_id,l_dummy_lpn)) THEN
24325                        IF NOT (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
24326                     --raise error
24327                     l_progress := 'WMSINB-24705';
24328                     RAISE fnd_api.g_exc_error;
24329                        END IF;
24330                     END IF;
24331 
24332                      /*INVCONV , remove OPM specific fork, Punit Kumar */
24333                     /*IF (NOT l_discrete_transaction) THEN
24334 
24335                        -- opm change bug# 3061052
24336                        gml_opm_roi_grp.validate_opm_lot(p_api_version	 	=> 1.0,
24337                                 p_init_msg_lst	 	=> FND_API.G_FALSE,
24338                                 p_mtlt_rowid		=> l_mtlt_rec.rowid,
24339                                 p_new_lot	 	=> 'N',
24340                                 p_opm_item_id		=> l_opm_item_id,
24341                                 p_item_no		=> l_item_no,
24342                                 p_lots_specified_on_parent => 'Y',
24343                                 p_lot_id		=> l_opm_lot_id,
24344                                 p_parent_txn_type	=> l_parent_txn_type,
24345                                 p_grand_parent_txn_type => l_grand_parent_txn_type,
24346                                 x_return_status 	=> x_return_status,
24347                                 x_msg_data      	=> x_msg_data,
24348                                 x_msg_count     	=> x_msg_count
24349                                 );
24350                         */
24351                     IF (l_debug = 1) THEN
24352                       print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
24353                     END IF;
24354 
24355                     INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
24356                                                        x_return_status      		   => x_return_status
24357                                                       ,x_msg_data           		   => x_msg_data
24358                                                       ,x_msg_count          		   => x_msg_count
24359                                                       ,p_api_version	               => 1.0
24360                                                       ,p_init_msg_lst	            => FND_API.G_FALSE
24361                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
24362                                                       ,p_transaction_type_id 	      => l_transaction_type_id
24363                                                       ,p_new_lot			            => 'N'
24364                                                       ,p_item_id	 		            => l_item_id
24365                                                       ,p_to_organization_id		   => L_ORG_ID
24366                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
24367                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
24368                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
24369                                                       ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
24370                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
24371                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
24372                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
24373                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
24374                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
24375                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
24376                                                       ,p_rti_id	                  => L_RTI_ID
24377                                                       ,p_revision             	   => l_item_revision
24378                                                       ,p_subinventory_code  	      => L_SUB_CODE
24379                                                       ,p_locator_id           	   => l_loc_id
24380                                                       ,p_transaction_type           => l_transaction_type
24381                                                       ,p_parent_txn_type            => l_parent_txn_type
24382                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
24383                                                       );
24384 
24385                     /*INVCONV ,*/
24386                     IF (l_debug = 1) THEN
24387                       print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
24388                       print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
24389                     END IF;
24390 
24391                     IF X_RETURN_STATUS <> 'S' THEN
24392                       --RAISE ERROR
24393                       l_progress := 'WMSINB-24728';
24394                       RAISE fnd_api.g_exc_error;
24395                     END IF;
24396 
24397                     IF (l_debug = 1) THEN
24398                       print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
24399                     END IF;
24400                     /*END IF; --IF (NOT l_discrete_transaction) THEN*/
24401 
24402                   END IF; --IF (l_grand_parent_txn_type = 'DELIVER') THEN
24403                 ELSIF (l_parent_txn_type = g_rtr) THEN --IF (l_parent_txn_type IN (g_rtv, g_rtc)) THEN
24404                   IF (lot_entered_on_parent(l_great_grand_parent_txn_id)) THEN
24405                     BEGIN
24406 
24407                     /*INVCONV, Remove the sublot no check in SQL */
24408                       SELECT primary_quantity
24409                         INTO l_rls_primary_quantity
24410                         FROM rcv_lots_supply
24411                        WHERE transaction_id = l_great_grand_parent_txn_id
24412                          AND lot_num = Ltrim(Rtrim(l_mtlt_rec.lot_number)) ;
24413                          /*AND ((sublot_num IS NULL and Ltrim(Rtrim(l_mtlt_rec.sublot_num)) IS NULL)
24414                            OR (sublot_num = Ltrim(Rtrim(l_mtlt_rec.sublot_num)))) ;*/
24415 
24416                       IF (l_mtlt_rec.primary_quantity > l_rls_primary_quantity) THEN
24417                         --raise error
24418                         l_progress := 'WMSINB-24752';
24419                         RAISE fnd_api.g_exc_error;
24420                       END IF;
24421                     EXCEPTION
24422                       WHEN no_data_found THEN
24423                       --raise error
24424                       l_progress := 'WMSINB-24758';
24425                       RAISE fnd_api.g_exc_error;
24426                     END;
24427                   END IF; --IF (lot_entered_on_parent(l_great_grand_parent_txn_id)) THEN
24428 
24429                   /*INVCONV , existing discrete validations. Same will be executed for process org */
24430                   /*IF (l_discrete_transaction) THEN*/
24431                   --PERFORM MATERIAL STATUS CHECK FOR LOT
24432                   IF (l_transaction_type = g_rtv) THEN
24433                      l_transaction_type_id := 36;
24434                   ELSIF (l_transaction_type = g_rtc) THEN
24435                      l_transaction_type_id := 37;
24436                   ELSIF (l_transaction_type = g_rtr) THEN
24437                     IF (l_source_document_code = 'PO') THEN
24438                       l_transaction_type_id := 36;
24439                     ELSE
24440                       l_transaction_type_id := 37; --For RMA
24441                     END IF;
24442                   ELSE
24443                     IF (l_source_document_code = 'PO') THEN
24444                       l_transaction_type_id := 71;
24445                     ELSE
24446                       l_transaction_type_id := 72;
24447                     END IF;
24448                   END IF;
24449 
24450                   INV_LOT_TRX_VALIDATION_PUB.VALIDATE_MATERIAL_STATUS(X_RETURN_STATUS => X_RETURN_STATUS,
24451                                   X_MSG_COUNT => X_MSG_COUNT,
24452                                   X_MSG_DATA => X_MSG_DATA,
24453                                   X_VALIDATION_STATUS => L_VALIDATION_STATUS,
24454                                   P_TRANSACTION_TYPE_ID => l_transaction_type_id,
24455                                   P_ORGANIZATION_ID => L_ORG_ID,
24456                                   P_INVENTORY_ITEM_ID => L_ITEM_ID,
24457                                   P_LOT_NUMBER => L_MTLT_REC.LOT_NUMBER,
24458                                   P_SUBINVENTORY_CODE => L_SUB_CODE,
24459                                   P_LOCATOR_ID => L_LOC_ID,
24460                                   P_STATUS_ID => NULL);
24461                   IF X_RETURN_STATUS <> 'S' THEN
24462                      --RAISE ERROR
24463                      l_progress := 'WMSINB-24796';
24464                      RAISE fnd_api.g_exc_error;
24465                   END IF;
24466 
24467                   IF (l_debug = 1) THEN
24468                      print_debug('VALIDATE_LOT_SERIAL_INFO: LOT MATERIAL VALIDATION STATUS: '||L_VALIDATION_STATUS||' : '||l_progress, 1);
24469                      l_progress := 'WMSINB-24802';
24470                   END IF;
24471 
24472                   IF L_VALIDATION_STATUS <> 'Y' THEN
24473                      --RAISE ERROR
24474                      l_progress := 'WMSINB-24807';
24475                      RAISE fnd_api.g_exc_error;
24476                   END IF;
24477 
24478 
24479                    /*
24480                     ELSE --IF (l_discrete_transaction) THEN
24481                       -- opm change bug# 3061052
24482                       gml_opm_roi_grp.validate_opm_lot(p_api_version	 	=> 1.0,
24483                                p_init_msg_lst	 	=> FND_API.G_FALSE,
24484                                p_mtlt_rowid		=> l_mtlt_rec.rowid,
24485                                p_new_lot	 	=> 'N',
24486                                p_opm_item_id		=> l_opm_item_id,
24487                                p_item_no		=> l_item_no,
24488                                p_lots_specified_on_parent => 'Y',
24489                                p_lot_id		=> l_opm_lot_id,
24490                                p_parent_txn_type	=> l_parent_txn_type,
24491                                p_grand_parent_txn_type => l_grand_parent_txn_type,
24492                                x_return_status 	=> x_return_status,
24493                                x_msg_data      	=> x_msg_data,
24494                                x_msg_count     	=> x_msg_count
24495                                );
24496                     */
24497                     IF (l_debug = 1) THEN
24498                        print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
24499                     END IF;
24500 
24501                     INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
24502                                                        x_return_status      		   => x_return_status
24503                                                       ,x_msg_data           		   => x_msg_data
24504                                                       ,x_msg_count          		   => x_msg_count
24505                                                       ,p_api_version	               => 1.0
24506                                                       ,p_init_msg_lst	            => FND_API.G_FALSE
24507                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
24508                                                       ,p_transaction_type_id 	      => l_transaction_type_id
24509                                                       ,p_new_lot			            => 'N'
24510                                                       ,p_item_id	 		            => l_item_id
24511                                                       ,p_to_organization_id		   => L_ORG_ID
24512                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
24513                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
24514                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
24515                                                       ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
24516                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
24517                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
24518                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
24519                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
24520                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
24521                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
24522                                                       ,p_rti_id	                  => L_RTI_ID
24523                                                       ,p_revision             	   => l_item_revision
24524                                                       ,p_subinventory_code  	      => L_SUB_CODE
24525                                                       ,p_locator_id           	   => l_loc_id
24526                                                       ,p_transaction_type           => l_transaction_type
24527                                                       ,p_parent_txn_type            => l_parent_txn_type
24528                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
24529                                                       );
24530 
24531                     IF (l_debug = 1) THEN
24532                        print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
24533                        print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
24534                     END IF;
24535 
24536                     IF X_RETURN_STATUS <> 'S' THEN
24537                        --RAISE ERROR
24538                        l_progress := 'WMSINB-24828';
24539                        RAISE fnd_api.g_exc_error;
24540                     END IF;
24541 
24542                     IF (l_debug = 1) THEN
24543                        print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
24544                     END IF;
24545                     /*END IF;  --IF (l_discrete_transaction) THEN*/
24546 
24547                   ELSE --	ELSIF (l_parent_txn_type = g_rtr)
24548                     IF l_parent_txn_type <> 'DELIVER' THEN
24549                       BEGIN
24550 
24551                         /* INVCONV , Remove Sublot Num from SQL , Punit Kumar*/
24552 
24553                         SELECT primary_quantity
24554                           INTO l_rls_primary_quantity
24555                           FROM rcv_lots_supply
24556                           WHERE transaction_id = l_parent_transaction_id
24557                           AND lot_num = Ltrim(Rtrim(l_mtlt_rec.lot_number));
24558 
24559                           /*  AND ((sublot_num IS NULL and Ltrim(Rtrim(l_mtlt_rec.sublot_num)) IS NULL)
24560                              OR (sublot_num = Ltrim(Rtrim(l_mtlt_rec.sublot_num)))) ;*/
24561 
24562                         IF (l_mtlt_rec.primary_quantity > l_rls_primary_quantity) THEN
24563                            --raise error
24564                            l_progress := 'WMSINB-24851';
24565                            RAISE fnd_api.g_exc_error;
24566                         END IF;
24567                       EXCEPTION
24568                         WHEN no_data_found THEN
24569                            --raise error
24570                            l_progress := 'WMSINB-24857';
24571                            RAISE fnd_api.g_exc_error;
24572                       END;
24573 
24574                       /*  IF (NOT l_discrete_transaction) THEN
24575                       -- opm change bug# 3061052.
24576                       gml_opm_roi_grp.validate_opm_lot(p_api_version	=> 1.0,
24577                                p_init_msg_lst	 	=> FND_API.G_FALSE,
24578                                p_mtlt_rowid		=> l_mtlt_rec.rowid,
24579                                p_new_lot	 	=> 'N',
24580                                p_opm_item_id		=> l_opm_item_id,
24581                                p_item_no		=> l_item_no,
24582                                p_lots_specified_on_parent => 'Y',
24583                                p_lot_id		=> l_opm_lot_id,
24584                                p_parent_txn_type	=> l_parent_txn_type,
24585                                p_grand_parent_txn_type => l_grand_parent_txn_type,
24586                                x_return_status 	=> x_return_status,
24587                                x_msg_data      	=> x_msg_data,
24588                                x_msg_count     	=> x_msg_count
24589                                );
24590                                */
24591                       IF (l_debug = 1) THEN
24592                          print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
24593                       END IF;
24594 
24595                       INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
24596                                                           x_return_status      		   => x_return_status
24597                                                          ,x_msg_data           		   => x_msg_data
24598                                                          ,x_msg_count          		   => x_msg_count
24599                                                          ,p_api_version	               => 1.0
24600                                                          ,p_init_msg_lst	            => FND_API.G_FALSE
24601                                                          ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
24602                                                          ,p_transaction_type_id 	      => l_transaction_type_id
24603                                                          ,p_new_lot			            => 'N'
24604                                                          ,p_item_id	 		            => l_item_id
24605                                                          ,p_to_organization_id		   => L_ORG_ID
24606                                                          ,p_lot_number			         => L_MTLT_REC.lot_number
24607                                                          ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
24608                                                          ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
24609                                                          ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
24610                                                          ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
24611                                                          ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
24612                                                          ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
24613                                                          ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
24614                                                          ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
24615                                                          ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
24616                                                          ,p_rti_id	                  => L_RTI_ID
24617                                                          ,p_revision             	   => l_item_revision
24618                                                          ,p_subinventory_code  	      => L_SUB_CODE
24619                                                          ,p_locator_id           	   => l_loc_id
24620                                                          ,p_transaction_type           => l_transaction_type
24621                                                          ,p_parent_txn_type            => l_parent_txn_type
24622                                                          ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
24623                                                          );
24624 
24625                       IF (l_debug = 1) THEN
24626                          print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
24627                          print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
24628                       END IF;
24629 
24630                       IF X_RETURN_STATUS <> 'S' THEN
24631                         --RAISE ERROR
24632                         l_progress := 'WMSINB-24880';
24633                         RAISE fnd_api.g_exc_error;
24634                       END IF;
24635 
24636                       IF (l_debug = 1) THEN
24637                          print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
24638                       END IF;
24639                       /*END IF; --IF (NOT l_discrete_transaction) THEN*/
24640                     ELSE --IF l_parent_txn_type <> 'DELIVER' THEN
24641 
24642                       /*INVCONV , Remove OPM specific fork*/
24643                       /*IF (l_discrete_transaction) THEN */
24644 
24645                       --PERFORM MATERIAL STATUS CHECK FOR LOT
24646                       IF (l_transaction_type = g_rtv) THEN
24647                         l_transaction_type_id := 36;
24648                       ELSIF (l_transaction_type = g_rtc) THEN
24649                         l_transaction_type_id := 37;
24650                       ELSIF (l_transaction_type = g_rtr) THEN
24651                         IF (l_source_document_code = 'PO') THEN
24652                           l_transaction_type_id := 36;
24653                         ELSE
24654                           l_transaction_type_id := 37; --For RMA
24655                         END IF;
24656                       ELSE
24657                         IF (l_source_document_code = 'PO') THEN
24658                           l_transaction_type_id := 71;
24659                         ELSE
24660                           l_transaction_type_id := 72;
24661                         END IF;
24662                       END IF;
24663 
24664 					   -- This code is added for bug 14269152
24665                       IF(l_transaction_type IN(g_rtv,g_rtc,g_rtr)) THEN
24666 
24667                       print_debug(' Call to INV_LOT_TRX_VALIDATION_PUB.VALIDATE_MATERIAL_STATUS ' , 1); -- Bug 14269152
24668 
24669                       INV_LOT_TRX_VALIDATION_PUB.VALIDATE_MATERIAL_STATUS(X_RETURN_STATUS => X_RETURN_STATUS,
24670                           X_MSG_COUNT => X_MSG_COUNT,
24671                           X_MSG_DATA => X_MSG_DATA,
24672                           X_VALIDATION_STATUS => L_VALIDATION_STATUS,
24673                           P_TRANSACTION_TYPE_ID => l_transaction_type_id,
24674                           P_ORGANIZATION_ID => L_ORG_ID,
24675                           P_INVENTORY_ITEM_ID => L_ITEM_ID,
24676                           P_LOT_NUMBER => L_MTLT_REC.LOT_NUMBER,
24677                           P_SUBINVENTORY_CODE => l_from_subinventory, -- 14269152
24678                           P_LOCATOR_ID => l_from_locator_id, -- 14269152
24679                           P_STATUS_ID => NULL,
24680                           P_LPN_ID    => L_LPN_ID);     -- bug 14269152
24681                       IF X_RETURN_STATUS <> 'S' THEN
24682                          --RAISE ERROR
24683                          l_progress := 'WMSINB-24921';
24684                          RAISE fnd_api.g_exc_error;
24685                       END IF;
24686 
24687                       ELSE
24688 
24689                       INV_LOT_TRX_VALIDATION_PUB.VALIDATE_MATERIAL_STATUS(X_RETURN_STATUS => X_RETURN_STATUS,
24690                           X_MSG_COUNT => X_MSG_COUNT,
24691                           X_MSG_DATA => X_MSG_DATA,
24692                           X_VALIDATION_STATUS => L_VALIDATION_STATUS,
24693                           P_TRANSACTION_TYPE_ID => l_transaction_type_id,
24694                           P_ORGANIZATION_ID => L_ORG_ID,
24695                           P_INVENTORY_ITEM_ID => L_ITEM_ID,
24696                           P_LOT_NUMBER => L_MTLT_REC.LOT_NUMBER,
24697                           P_SUBINVENTORY_CODE => L_SUB_CODE,
24698                           P_LOCATOR_ID => L_LOC_ID,
24699                           P_STATUS_ID => NULL);
24700                       IF X_RETURN_STATUS <> 'S' THEN
24701                          --RAISE ERROR
24702                          l_progress := 'WMSINB-24922';
24703                          RAISE fnd_api.g_exc_error;
24704                       END IF;
24705 
24706 					  END IF;
24707 
24708                       IF (l_debug = 1) THEN
24709                         print_debug('VALIDATE_LOT_SERIAL_INFO: LOT MATERIAL VALIDATION STATUS: '||L_VALIDATION_STATUS||' : '||l_progress, 1);
24710                         l_progress := 'WMSINB-24928';
24711                       END IF;
24712 
24713                       IF L_VALIDATION_STATUS <> 'Y' THEN
24714                         --RAISE ERROR
24715                         l_progress := 'WMSINB-24933';
24716                         RAISE fnd_api.g_exc_error;
24717                       END IF;
24718 
24719                       /*ELSE --IF (l_discrete_transaction) THEN
24720                       -- opm change bug# 3061052
24721                       gml_opm_roi_grp.validate_opm_lot(p_api_version	=> 1.0,
24722                                p_init_msg_lst	 	=> FND_API.G_FALSE,
24723                                p_mtlt_rowid		=> l_mtlt_rec.rowid,
24724                                p_new_lot	 	=> 'N',
24725                                p_opm_item_id		=> l_opm_item_id,
24726                                p_item_no		=> l_item_no,
24727                                p_lots_specified_on_parent => 'Y',
24728                                p_lot_id		=> l_opm_lot_id,
24729                                p_parent_txn_type	=> l_parent_txn_type,
24730                                p_grand_parent_txn_type => l_grand_parent_txn_type,
24731                                x_return_status 	=> x_return_status,
24732                                x_msg_data      	=> x_msg_data,
24733                                x_msg_count     	=> x_msg_count
24734                                );*/
24735                       IF (l_debug = 1) THEN
24736                          print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
24737                       END IF;
24738 
24739                       INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
24740                                                           x_return_status      		   => x_return_status
24741                                                          ,x_msg_data           		   => x_msg_data
24742                                                          ,x_msg_count          		   => x_msg_count
24743                                                          ,p_api_version	               => 1.0
24744                                                          ,p_init_msg_lst	            => FND_API.G_FALSE
24745                                                          ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
24746                                                          ,p_transaction_type_id 	      => l_transaction_type_id
24747                                                          ,p_new_lot			            => 'N'
24748                                                          ,p_item_id	 		            => l_item_id
24749                                                          ,p_to_organization_id		   => L_ORG_ID
24750                                                          ,p_lot_number			         => L_MTLT_REC.lot_number
24751                                                          ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
24752                                                          ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
24753                                                          ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
24754                                                          ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
24755                                                          ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
24756                                                          ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
24757                                                          ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
24758                                                          ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
24759                                                          ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
24760                                                          ,p_rti_id	                  => L_RTI_ID
24761                                                          ,p_revision             	   => l_item_revision
24762                                                          ,p_subinventory_code  	      => L_SUB_CODE
24763                                                          ,p_locator_id           	   => l_loc_id
24764                                                          ,p_transaction_type           => l_transaction_type
24765                                                          ,p_parent_txn_type            => l_parent_txn_type
24766                                                          ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
24767                                                          );
24768 
24769                       /*INVCONV ,*/
24770                       IF (l_debug = 1) THEN
24771                          print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
24772                          print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
24773                       END IF;
24774 
24775                       IF X_RETURN_STATUS <> 'S' THEN
24776                          --RAISE ERROR
24777                          l_progress := 'WMSINB-24955';
24778                          RAISE fnd_api.g_exc_error;
24779                       END IF;
24780 
24781                       IF (l_debug = 1) THEN
24782                         print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
24783                       END IF;
24784                       /*END IF; -- IF (l_discrete_transaction) THEN*/
24785                     END IF; --IF l_parent_txn_type <> 'DELIVER' THEN
24786                   END IF; --IF (l_parent_txn_type IN (g_rtv, g_rtc)) THEN
24787                 ELSE --IF (l_lot_exists = 1) THEN
24788               IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
24789                  IF (l_grand_parent_txn_type = 'DELIVER') THEN
24790                     -- opm change bug# 3061052
24791                     /* INVCONV, replace the existing create_inv_lot call with a new call */
24792                     /*INVCONV , Perform lot validations and create the new lot.
24793                       Call Lot Create API INV_ROI_INTEGRATION_GRP.INV_NEW_LOT to create the new lot.
24794                       This shall also create lot specific conversions after creating the new Lot.
24795                       This replaces the existing procedure INV_LOT_API_PUB.CREATE_INV_LOT to create NEW LOT */
24796 
24797                     IF (l_debug = 1) THEN
24798                        print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
24799                     END IF;
24800 
24801                     INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
24802                                                          x_return_status      		   => x_return_status
24803                                                         ,x_msg_data           		   => x_msg_data
24804                                                         ,x_msg_count          		   => x_msg_count
24805                                                         ,p_api_version	               => 1.0
24806                                                         ,p_init_msg_lst	               => FND_API.G_FALSE
24807                                                         ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
24808                                                         ,p_transaction_type_id 	      => l_transaction_type_id
24809                                                         ,p_new_lot			            => 'Y'
24810                                                         ,p_item_id	 		            => l_item_id
24811                                                         ,p_to_organization_id		      => L_ORG_ID
24812                                                         ,p_lot_number			         => L_MTLT_REC.lot_number
24813                                                         ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
24814                                                         ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
24815                                                         ,x_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
24816                                                         ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
24817                                                         ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
24818                                                         ,p_transaction_unit_of_measure => l_rti_UNIT_OF_MEASURE
24819                                                         ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
24820                                                         ,p_OE_ORDER_HEADER_ID	         => l_OE_ORDER_HEADER_ID
24821                                                         ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
24822                                                         ,p_rti_id	                     => L_RTI_ID
24823                                                         ,p_revision             	      => l_item_revision
24824                                                         ,p_subinventory_code  	      => L_SUB_CODE
24825                                                         ,p_locator_id           	      => l_loc_id
24826                                                         ,p_transaction_type           => l_transaction_type
24827                                                         ,p_parent_txn_type            => l_parent_txn_type
24828                                                         ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
24829                                                         );
24830 
24831                     IF (l_debug = 1) THEN
24832                        print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
24833                        print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
24834                     END IF;
24835 
24836                     IF (x_return_status <> 'S') THEN
24837                        --raise error
24838                        l_progress := 'WMSINB-25058';
24839                        RAISE fnd_api.g_exc_error;
24840                     END IF;
24841 
24842                     /*INVCONV ,*/
24843                     IF (l_debug = 1) THEN
24844                        print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
24845                     END IF;
24846 
24847                     INV_ROI_INTEGRATION_GRP.INV_NEW_LOT(
24848                                                 x_return_status      		   => x_return_status
24849                                                ,x_msg_count          		   => x_msg_count
24850                                                ,x_msg_data           		   => x_msg_data
24851                                                ,p_api_version	               => 1.0
24852                                                ,p_init_msg_lst	               => FND_API.G_FALSE
24853                                                ,p_source_document_code			=> L_SOURCE_DOCUMENT_CODE
24854                                                ,p_item_id				         => l_item_id
24855                                                ,p_from_organization_id			=> L_FROM_ORG_ID
24856                                                ,p_to_organization_id	         => L_ORG_ID
24857                                                ,p_lot_number				      => L_MTLT_REC.lot_number
24858                                                ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
24859                                                ,p_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
24860                                                ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
24861                                                ,p_primary_unit_of_measure	   => l_rti_PRIMARY_UNIT_OF_MEASURE
24862                                                ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
24863                                                ,p_uom_code	                  => l_rti_UOM_CODE
24864                                                ,p_secondary_uom_code	         => l_rti_SECONDARY_UOM_CODE
24865                                                ,p_reason_id	                  => L_MTLT_REC.REASON_ID
24866                                                ,P_MLN_REC                     => L_MLN_REC
24867                                                ,p_mtlt_rowid	               => L_MTLT_REC.ROWID
24868                                                );
24869 
24870                     /*INVCONV ,*/
24871                     IF (l_debug = 1) THEN
24872                       print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
24873                       print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_NEW_LOT return status: '||x_return_status||' : '||l_progress, 1);
24874                     END IF;
24875 
24876                     IF X_RETURN_STATUS <> 'S' THEN
24877                       --RAISE ERROR
24878                       l_progress := 'WMSINB-25085';
24879                       RAISE fnd_api.g_exc_error;
24880                     END IF;
24881 
24882                     IF (l_debug = 1) THEN
24883                       print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
24884                     END IF;
24885                     /*END IF; --IF (l_discrete_transaction) THEN*/
24886                   ELSE --IF (l_grand_parent_txn_type = 'DELIVER') THEN
24887                     IF (validate_rs(NULL,l_grand_parent_txn_id,l_dummy_lpn)) THEN
24888                       IF NOT (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
24889                         --raise an error
24890                         l_progress := 'WMSINB-25097';
24891                         RAISE fnd_api.g_exc_error;
24892                       END IF;
24893                     END IF;
24894 
24895                     /*INVCONV, Replace existing create lot call with a new call */
24896                     IF (l_debug = 1) THEN
24897                        print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
24898                     END IF;
24899 
24900                     INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
24901                                                        x_return_status      		   => x_return_status
24902                                                       ,x_msg_data           		   => x_msg_data
24903                                                       ,x_msg_count          		   => x_msg_count
24904                                                       ,p_api_version	               => 1.0
24905                                                       ,p_init_msg_lst	               => FND_API.G_FALSE
24906                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
24907                                                       ,p_transaction_type_id 	      => l_transaction_type_id
24908                                                       ,p_new_lot			            => 'Y'
24909                                                       ,p_item_id	 		            => l_item_id
24910                                                       ,p_to_organization_id		   => L_ORG_ID
24911                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
24912                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
24913                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
24914                                                       ,x_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
24915                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
24916                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
24917                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
24918                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
24919                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
24920                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
24921                                                       ,p_rti_id	                  => L_RTI_ID
24922                                                       ,p_revision             	   => l_item_revision
24923                                                       ,p_subinventory_code  	      => L_SUB_CODE
24924                                                       ,p_locator_id           	   => l_loc_id
24925                                                       ,p_transaction_type           => l_transaction_type
24926                                                       ,p_parent_txn_type            => l_parent_txn_type
24927                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
24928                                                       );
24929 
24930                     IF (l_debug = 1) THEN
24931                         print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
24932                         print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
24933                     END IF;
24934 
24935                     IF (x_return_status <> 'S') THEN
24936                       --raise error
24937                       l_progress := 'WMSINB-25193';
24938                       RAISE fnd_api.g_exc_error;
24939                     END IF;
24940 
24941                     IF (l_debug = 1) THEN
24942                       print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
24943                     END IF;
24944 
24945                     INV_ROI_INTEGRATION_GRP.INV_NEW_LOT(
24946                                                 x_return_status      		   => x_return_status
24947                                                ,x_msg_count          		   => x_msg_count
24948                                                ,x_msg_data           		   => x_msg_data
24949                                                ,p_api_version	               => 1.0
24950                                                ,p_init_msg_lst	               => FND_API.G_FALSE
24951                                                ,p_source_document_code			=> L_SOURCE_DOCUMENT_CODE
24952                                                ,p_item_id				         => l_item_id
24953                                                ,p_from_organization_id			=> L_FROM_ORG_ID
24954                                                ,p_to_organization_id	         => L_ORG_ID
24955                                                ,p_lot_number				      => L_MTLT_REC.lot_number
24956                                                ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
24957                                                ,p_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
24958                                                ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
24959                                                ,p_primary_unit_of_measure	   => l_rti_PRIMARY_UNIT_OF_MEASURE
24960                                                ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
24961                                                ,p_uom_code	                  => l_rti_UOM_CODE
24962                                                ,p_secondary_uom_code	         => l_rti_SECONDARY_UOM_CODE
24963                                                ,p_reason_id	                  => L_MTLT_REC.REASON_ID
24964                                                ,P_MLN_REC                     => L_MLN_REC
24965                                                ,p_mtlt_rowid	               => L_MTLT_REC.ROWID
24966                                                );
24967 
24968                     /*INVCONV ,*/
24969                     IF (l_debug = 1) THEN
24970                         print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
24971                         print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_NEW_LOT return status: '||x_return_status||' : '||l_progress, 1);
24972                     END IF;
24973 
24974 
24975                     IF X_RETURN_STATUS <> 'S' THEN
24976                        --RAISE ERROR
24977                        l_progress := 'WMSINB-25220';
24978                        RAISE fnd_api.g_exc_error;
24979                     END IF;
24980 
24981                     IF (l_debug = 1) THEN
24982                        print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
24983                     END IF;
24984                     /*END IF; --IF (l_discrete_transaction) THEN*/
24985                   END IF; --IF (l_grand_parent_txn_type = 'DELIVER') THEN
24986                 ELSIF (l_parent_txn_type = g_rtr) THEN --IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
24987                   IF (lot_entered_on_parent(l_great_grand_parent_txn_id)) THEN
24988                     --raise an error
24989                     l_progress := 'WMSINB-25232';
24990                     RAISE fnd_api.g_exc_error;
24991                   ELSE
24992                     --CALL CREATE_INV_LOT
24993                     /* INVCONV, replace the existing create_inv_lot call with a new call */
24994                     /*INVCONV , Perform lot validations and create the new lot.
24995                       Call Lot Create API INV_ROI_INTEGRATION_GRP.INV_NEW_LOT to create the new lot.
24996                       This shall also create lot specific conversions after creating the new Lot.
24997                       This replaces the existing procedure INV_LOT_API_PUB.CREATE_INV_LOT to create NEW LOT*/
24998 
24999                     IF (l_debug = 1) THEN
25000                        print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
25001                     END IF;
25002 
25003                     INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
25004                                                           x_return_status      		   => x_return_status
25005                                                          ,x_msg_data           		   => x_msg_data
25006                                                          ,x_msg_count          		   => x_msg_count
25007                                                          ,p_api_version	               => 1.0
25008                                                          ,p_init_msg_lst	            => FND_API.G_FALSE
25009                                                          ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
25010                                                          ,p_transaction_type_id 	      => l_transaction_type_id
25011                                                          ,p_new_lot			            => 'Y'
25012                                                          ,p_item_id	 		            => l_item_id
25013                                                          ,p_to_organization_id		   => L_ORG_ID
25014                                                          ,p_lot_number			         => L_MTLT_REC.lot_number
25015                                                          ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
25016                                                          ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
25017                                                          ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
25018                                                          ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
25019                                                          ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
25020                                                          ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
25021                                                          ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
25022                                                          ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
25023                                                          ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
25024                                                          ,p_rti_id	                  => L_RTI_ID
25025                                                          ,p_revision             	   => l_item_revision
25026                                                          ,p_subinventory_code  	      => L_SUB_CODE
25027                                                          ,p_locator_id           	   => l_loc_id
25028                                                          ,p_transaction_type           => l_transaction_type
25029                                                          ,p_parent_txn_type            => l_parent_txn_type
25030                                                          ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
25031                                                          );
25032 
25033                     /*INVCONV ,*/
25034                     IF (l_debug = 1) THEN
25035                        print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
25036                        print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
25037                     END IF;
25038 
25039                     IF (x_return_status <> 'S') THEN
25040                       --raise error
25041                       l_progress := 'WMSINB-25325';
25042                       RAISE fnd_api.g_exc_error;
25043                     END IF;
25044 
25045                     IF (l_debug = 1) THEN
25046                       print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
25047                     END IF;
25048 
25049                     INV_ROI_INTEGRATION_GRP.INV_NEW_LOT(
25050                                                 x_return_status      		   => x_return_status
25051                                                ,x_msg_count          		   => x_msg_count
25052                                                ,x_msg_data           		   => x_msg_data
25053                                                ,p_api_version	               => 1.0
25054                                                ,p_init_msg_lst	               => FND_API.G_FALSE
25055                                                ,p_source_document_code			=> L_SOURCE_DOCUMENT_CODE
25056                                                ,p_item_id				         => l_item_id
25057                                                ,p_from_organization_id			=> L_FROM_ORG_ID
25058                                                ,p_to_organization_id	         => L_ORG_ID
25059                                                ,p_lot_number				      => L_MTLT_REC.lot_number
25060                                                ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
25061                                                ,p_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
25062                                                ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
25063                                                ,p_primary_unit_of_measure	   => l_rti_PRIMARY_UNIT_OF_MEASURE
25064                                                ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
25065                                                ,p_uom_code	                  => l_rti_UOM_CODE
25066                                                ,p_secondary_uom_code	         => l_rti_SECONDARY_UOM_CODE
25067                                                ,p_reason_id	                  => L_MTLT_REC.REASON_ID
25068                                                ,P_MLN_REC                     => L_MLN_REC
25069                                                ,p_mtlt_rowid	               => L_MTLT_REC.ROWID
25070                                                );
25071 
25072                     /*INVCONV ,*/
25073                     IF (l_debug = 1) THEN
25074                       print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
25075                       print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_NEW_LOT return status: '||x_return_status||' : '||l_progress, 1);
25076                     END IF;
25077 
25078                     IF X_RETURN_STATUS <> 'S' THEN
25079                        --RAISE ERROR
25080                        l_progress := 'WMSINB-25352';
25081                        RAISE fnd_api.g_exc_error;
25082                     END IF;
25083 
25084                     IF (l_debug = 1) THEN
25085                        print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
25086                     END IF;
25087                     /* END IF ; --   IF (l_discrete_transaction) THEN*/
25088                   END IF; ---- IF (lot_entered_on_parent(l_great_grand_parent_txn_id)) THEN
25089                   /*the comment for above end if was wrong*/
25090                 ELSE --ELSIF (l_parent_txn_type = g_rtr) THEN
25091                   --raise an error
25092                   l_progress := 'WMSINB-25363';
25093                   RAISE fnd_api.g_exc_error;
25094                 END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
25095               END IF;--IF (l_lot_exists = 1) THEN
25096 
25097               IF (l_serial_number_control_code IN (2,5,6)) THEN
25098                 IF (l_debug = 1) THEN
25099                    print_debug('VALIDATE_LOT_SERIAL_INFO: LOT AND SERIAL CONTROLLED: '||l_progress, 1);
25100                    print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROL CODE: '||l_serial_number_control_code||' : '||l_progress, 1);
25101                    print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||l_source_document_code||' : '||l_progress, 1);
25102                    l_progress := 'WMSINB-25373';
25103                 END IF;
25104 
25105                 L_NUM_MSNT_RECS := 0;
25106                 l_tot_msnt_serial_qty := 0;
25107 
25108                 OPEN C_MSNT_LOTSERIAL(L_MTLT_REC.SERIAL_TRANSACTION_TEMP_ID);
25109                 LOOP
25110                   FETCH C_MSNT_LOTSERIAL INTO L_MSNT_REC;
25111                   EXIT WHEN C_MSNT_LOTSERIAL%NOTFOUND;
25112 
25113                   L_NUM_MSNT_RECS := L_NUM_MSNT_RECS + 1;
25114                   L_SERIAL_QUANTITY := INV_SERIAL_NUMBER_PUB.GET_SERIAL_DIFF(L_MSNT_REC.FM_SERIAL_NUMBER,
25115                                                                              L_MSNT_REC.TO_SERIAL_NUMBER);
25116 
25117                   l_tot_msnt_serial_qty := l_tot_msnt_serial_qty + l_serial_quantity;
25118 
25119                   INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.FM_SERIAL_NUMBER, L_TEMP_PREFIX, L_FROM_SER_NUMBER);
25120                   INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.TO_SERIAL_NUMBER, L_TEMP_PREFIX, L_TO_SER_NUMBER);
25121 
25122                   IF (l_debug = 1) THEN
25123                     print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL QUANTITY: '||l_serial_quantity||' : '||l_progress, 1);
25124                     l_progress := 'WMSINB-25398';
25125                   END IF;
25126 
25127                   --populate attributes table
25128                   l_serial_attributes_tbl(1).column_name   := 'SERIAL_ATTRIBUTE_CATEGORY';
25129                   l_serial_attributes_tbl(1).column_value  := l_msnt_rec.serial_attribute_category;
25130                   l_serial_attributes_tbl(2).column_name   := 'ORIGINATION_DATE';
25131                   l_serial_attributes_tbl(2).column_value  := l_msnt_rec.origination_date;
25132                   l_serial_attributes_tbl(3).column_name   := 'C_ATTRIBUTE1';
25133                   l_serial_attributes_tbl(3).column_value  := l_msnt_rec.c_attribute1;
25134                   l_serial_attributes_tbl(4).column_name   := 'C_ATTRIBUTE2';
25135                   l_serial_attributes_tbl(4).column_value  := l_msnt_rec.c_attribute2;
25136                   l_serial_attributes_tbl(5).column_name   := 'C_ATTRIBUTE3';
25137                   l_serial_attributes_tbl(5).column_value  := l_msnt_rec.c_attribute3;
25138                   l_serial_attributes_tbl(6).column_name   := 'C_ATTRIBUTE4';
25139                   l_serial_attributes_tbl(6).column_value   := l_msnt_rec.c_attribute4;
25140                   l_serial_attributes_tbl(7).column_name   := 'C_ATTRIBUTE5';
25141                   l_serial_attributes_tbl(7).column_value   := l_msnt_rec.c_attribute5;
25142                   l_serial_attributes_tbl(8).column_name   := 'C_ATTRIBUTE6';
25143                   l_serial_attributes_tbl(8).column_value   := l_msnt_rec.c_attribute6;
25144                   l_serial_attributes_tbl(9).column_name   := 'C_ATTRIBUTE7';
25145                   l_serial_attributes_tbl(9).column_value   := l_msnt_rec.c_attribute7;
25146                   l_serial_attributes_tbl(10).column_name  := 'C_ATTRIBUTE8';
25147                   l_serial_attributes_tbl(10).column_value  := l_msnt_rec.c_attribute8;
25148                   l_serial_attributes_tbl(11).column_name  := 'C_ATTRIBUTE9';
25149                   l_serial_attributes_tbl(11).column_value  := l_msnt_rec.c_attribute9;
25150                   l_serial_attributes_tbl(12).column_name  := 'C_ATTRIBUTE10';
25151                   l_serial_attributes_tbl(12).column_value  := l_msnt_rec.c_attribute10;
25152                   l_serial_attributes_tbl(13).column_name  := 'C_ATTRIBUTE11';
25153                   l_serial_attributes_tbl(13).column_value  := l_msnt_rec.c_attribute11;
25154                   l_serial_attributes_tbl(14).column_name  := 'C_ATTRIBUTE12';
25155                   l_serial_attributes_tbl(14).column_value  := l_msnt_rec.c_attribute12;
25156                   l_serial_attributes_tbl(15).column_name  := 'C_ATTRIBUTE13';
25157                   l_serial_attributes_tbl(15).column_value  := l_msnt_rec.c_attribute13;
25158                   l_serial_attributes_tbl(16).column_name  := 'C_ATTRIBUTE14';
25159                   l_serial_attributes_tbl(16).column_value  := l_msnt_rec.c_attribute14;
25160                   l_serial_attributes_tbl(17).column_name  := 'C_ATTRIBUTE15';
25161                   l_serial_attributes_tbl(17).column_value  := l_msnt_rec.c_attribute15;
25162                   l_serial_attributes_tbl(18).column_name  := 'C_ATTRIBUTE16';
25163                   l_serial_attributes_tbl(18).column_value  := l_msnt_rec.c_attribute16;
25164                   l_serial_attributes_tbl(19).column_name  := 'C_ATTRIBUTE17';
25165                   l_serial_attributes_tbl(19).column_value  := l_msnt_rec.c_attribute17;
25166                   l_serial_attributes_tbl(20).column_name  := 'C_ATTRIBUTE18';
25167                   l_serial_attributes_tbl(20).column_value  := l_msnt_rec.c_attribute18;
25168                   l_serial_attributes_tbl(21).column_name  := 'C_ATTRIBUTE19';
25169                   l_serial_attributes_tbl(21).column_value  := l_msnt_rec.c_attribute19;
25170                   l_serial_attributes_tbl(22).column_name  := 'C_ATTRIBUTE20';
25171                   l_serial_attributes_tbl(22).column_value  := l_msnt_rec.c_attribute20;
25172                   l_serial_attributes_tbl(23).column_name  := 'D_ATTRIBUTE1';
25173                   l_serial_attributes_tbl(23).column_value  := l_msnt_rec.d_attribute1;
25174                   l_serial_attributes_tbl(24).column_name  := 'D_ATTRIBUTE2';
25175                   l_serial_attributes_tbl(24).column_value  := l_msnt_rec.d_attribute2;
25176                   l_serial_attributes_tbl(25).column_name  := 'D_ATTRIBUTE3';
25177                   l_serial_attributes_tbl(25).column_value  := l_msnt_rec.d_attribute3;
25178                   l_serial_attributes_tbl(26).column_name  := 'D_ATTRIBUTE4';
25179                   l_serial_attributes_tbl(26).column_value  := l_msnt_rec.d_attribute4;
25180                   l_serial_attributes_tbl(27).column_name  := 'D_ATTRIBUTE5';
25181                   l_serial_attributes_tbl(27).column_value  := l_msnt_rec.d_attribute5;
25182                   l_serial_attributes_tbl(28).column_name  := 'D_ATTRIBUTE6';
25183                   l_serial_attributes_tbl(28).column_value  := l_msnt_rec.d_attribute6;
25184                   l_serial_attributes_tbl(29).column_name  := 'D_ATTRIBUTE7';
25185                   l_serial_attributes_tbl(29).column_value  := l_msnt_rec.d_attribute7;
25186                   l_serial_attributes_tbl(30).column_name  := 'D_ATTRIBUTE8';
25187                   l_serial_attributes_tbl(30).column_value  := l_msnt_rec.d_attribute8;
25188                   l_serial_attributes_tbl(31).column_name  := 'D_ATTRIBUTE9';
25189                   l_serial_attributes_tbl(31).column_value  := l_msnt_rec.d_attribute9;
25190                   l_serial_attributes_tbl(32).column_name  := 'D_ATTRIBUTE10';
25191                   l_serial_attributes_tbl(32).column_value  := l_msnt_rec.d_attribute10;
25192                   l_serial_attributes_tbl(33).column_name  := 'N_ATTRIBUTE1';
25193                   l_serial_attributes_tbl(33).column_value  := l_msnt_rec.n_attribute1;
25194                   l_serial_attributes_tbl(34).column_name  := 'N_ATTRIBUTE2';
25195                   l_serial_attributes_tbl(34).column_value  := l_msnt_rec.n_attribute2;
25196                   l_serial_attributes_tbl(35).column_name  := 'N_ATTRIBUTE3';
25197                   l_serial_attributes_tbl(35).column_value  := l_msnt_rec.n_attribute3;
25198                   l_serial_attributes_tbl(36).column_name  := 'N_ATTRIBUTE4';
25199                   l_serial_attributes_tbl(36).column_value  := l_msnt_rec.n_attribute4;
25200                   l_serial_attributes_tbl(37).column_name  := 'N_ATTRIBUTE5';
25201                   l_serial_attributes_tbl(37).column_value := l_msnt_rec.n_attribute5;
25202                   l_serial_attributes_tbl(38).column_name  := 'N_ATTRIBUTE6';
25203                   l_serial_attributes_tbl(38).column_value := l_msnt_rec.n_attribute6;
25204                   l_serial_attributes_tbl(39).column_name  := 'N_ATTRIBUTE7';
25205                   l_serial_attributes_tbl(39).column_value := l_msnt_rec.n_attribute7;
25206                   l_serial_attributes_tbl(40).column_name  := 'N_ATTRIBUTE8';
25207                   l_serial_attributes_tbl(40).column_value := l_msnt_rec.n_attribute8;
25208                   l_serial_attributes_tbl(41).column_name  := 'N_ATTRIBUTE9';
25209                   l_serial_attributes_tbl(41).column_value := l_msnt_rec.n_attribute9;
25210                   l_serial_attributes_tbl(42).column_name  := 'N_ATTRIBUTE10';
25211                   l_serial_attributes_tbl(42).column_value := l_msnt_rec.n_attribute10;
25212                   l_serial_attributes_tbl(43).column_name  := 'STATUS_ID';
25213                   l_serial_attributes_tbl(43).column_value := l_msnt_rec.status_id;
25214                   l_serial_attributes_tbl(44).column_name  := 'TERRITORY_CODE';
25215                   l_serial_attributes_tbl(44).column_value := l_msnt_rec.territory_code;
25216                   l_serial_attributes_tbl(45).column_name   := 'ATTRIBUTE_CATEGORY';
25217                   l_serial_attributes_tbl(45).column_value  := l_msnt_rec.attribute_category;
25218                   l_serial_attributes_tbl(46).column_name   := 'ATTRIBUTE1';
25219                   l_serial_attributes_tbl(46).column_value  := l_msnt_rec.attribute1;
25220                   l_serial_attributes_tbl(47).column_name   := 'ATTRIBUTE2';
25221                   l_serial_attributes_tbl(47).column_value  := l_msnt_rec.attribute2;
25222                   l_serial_attributes_tbl(48).column_name   := 'ATTRIBUTE3';
25223                   l_serial_attributes_tbl(48).column_value  := l_msnt_rec.attribute3;
25224                   l_serial_attributes_tbl(49).column_name   := 'ATTRIBUTE4';
25225                   l_serial_attributes_tbl(49).column_value   := l_msnt_rec.attribute4;
25226                   l_serial_attributes_tbl(50).column_name   := 'ATTRIBUTE5';
25227                   l_serial_attributes_tbl(50).column_value   := l_msnt_rec.attribute5;
25228                   l_serial_attributes_tbl(51).column_name   := 'ATTRIBUTE6';
25229                   l_serial_attributes_tbl(51).column_value   := l_msnt_rec.attribute6;
25230                   l_serial_attributes_tbl(52).column_name   := 'ATTRIBUTE7';
25231                   l_serial_attributes_tbl(52).column_value   := l_msnt_rec.attribute7;
25232                   l_serial_attributes_tbl(53).column_name  := 'ATTRIBUTE8';
25233                   l_serial_attributes_tbl(53).column_value  := l_msnt_rec.attribute8;
25234                   l_serial_attributes_tbl(54).column_name  := 'ATTRIBUTE9';
25235                   l_serial_attributes_tbl(54).column_value  := l_msnt_rec.attribute9;
25236                   l_serial_attributes_tbl(55).column_name  := 'ATTRIBUTE10';
25237                   l_serial_attributes_tbl(55).column_value  := l_msnt_rec.attribute10;
25238                   l_serial_attributes_tbl(56).column_name  := 'ATTRIBUTE11';
25239                   l_serial_attributes_tbl(56).column_value  := l_msnt_rec.attribute11;
25240                   l_serial_attributes_tbl(57).column_name  := 'ATTRIBUTE12';
25241                   l_serial_attributes_tbl(57).column_value  := l_msnt_rec.attribute12;
25242                   l_serial_attributes_tbl(58).column_name  := 'ATTRIBUTE13';
25243                   l_serial_attributes_tbl(58).column_value  := l_msnt_rec.attribute13;
25244                   l_serial_attributes_tbl(59).column_name  := 'ATTRIBUTE14';
25245                   l_serial_attributes_tbl(59).column_value  := l_msnt_rec.attribute14;
25246                   l_serial_attributes_tbl(60).column_name  := 'ATTRIBUTE15';
25247                   l_serial_attributes_tbl(60).column_value  := l_msnt_rec.attribute15;
25248 
25249                   --validate the serials
25250                   FOR SERIALQTY IN 1..L_SERIAL_QUANTITY LOOP
25251                     l_progress := 'WMSINB-25404';
25252                     L_CUR_NUMBER := L_FROM_SER_NUMBER+SERIALQTY -1;
25253                     if L_FROM_SER_NUMBER = -1 and  L_TO_SER_NUMBER = -1 then
25254                        L_SERIAL_NUMBER  := L_MSNT_REC.fm_serial_number;
25255                     else
25256                       L_SERIAL_NUMBER := SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
25257                                             LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -LENGTH(L_CUR_NUMBER))
25258                                          ||L_CUR_NUMBER;
25259                     End if;
25260                     l_progress := 'WMSINB-25412';
25261 
25262                     BEGIN
25263                        SELECT CURRENT_ORGANIZATION_ID
25264                          , current_status
25265                          , lot_number
25266                          , Decode(lpn_id,0,NULL,lpn_id)
25267                          , inspection_status
25268                          , group_mark_id
25269                          INTO L_CURR_ORG_ID
25270                          , l_curr_status
25271                          , l_curr_lot_num
25272                          , l_curr_lpn_id
25273                          , l_inspection_status
25274                          , l_group_mark_id
25275                          FROM MTL_SERIAL_NUMBERS
25276                          WHERE SERIAL_NUMBER = l_serial_number
25277                          AND inventory_item_id = l_item_id;
25278 
25279                        l_serial_exists := 1;
25280                        l_progress := 'WMSINB-25432';
25281                     EXCEPTION
25282                        WHEN no_data_found THEN
25283                           l_serial_exists := 0;
25284                           l_progress := 'WMSINB-25436';
25285                     END;
25286 
25287                     IF (l_debug = 1) THEN
25288                        print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL EXISTS: '||l_serial_exists||' : '||l_progress, 1);
25289                        print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NUMBER: '||l_serial_number||' : '||l_progress, 1);
25290                        print_debug('VALIDATE_LOT_SERIAL_INFO: CURR STATUS: '||l_curr_status||' : '||l_progress, 1);
25291                        print_debug('VALIDATE_LOT_SERIAL_INFO: CURR ORG ID: '||l_curr_org_id||' : '||l_progress, 1);
25292                        print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LPN ID: '||l_curr_lpn_id||' : '||l_progress, 1);
25293                        print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LOT NUM: '||l_curr_lot_num||' : '||l_progress, 1);
25294                        print_debug('VALIDATE_LOT_SERIAL_INFO: INSPECT STS: '||l_inspection_status||' : '||l_progress, 1);
25295                        print_debug('VALIDATE_LOT_SERIAL_INFO: GROUP MARK ID: '||l_group_mark_id||' : '||l_progress, 1);
25296                        print_debug('VALIDATE_LOT_SERIAL_INFO: RESTRICT RCPT SER: '||l_restrict_rcpt_ser||' : '||l_progress, 1);
25297                        l_progress := 'WMSINB-25449';
25298                     END IF;
25299 
25300                     IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
25301                        IF (l_grand_parent_txn_type <> 'DELIVER') THEN
25302                     IF NOT (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
25303                        --raise an error
25304                        l_progress := 'WMSINB-25456';
25305                        RAISE fnd_api.g_exc_error;
25306                     END IF;
25307                   END IF; --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
25308 
25309                   IF (l_serial_exists = 1) THEN
25310                     IF l_curr_org_id <> l_org_id THEN
25311                        --raise error
25312                        fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25313                        fnd_msg_pub.ADD;
25314                        l_progress := 'WMSINB-25466';
25315                        RAISE fnd_api.g_exc_error;
25316                     ELSE
25317                        IF ((l_curr_lot_num IS NOT NULL) AND
25318                            (l_curr_lot_num <> l_mtlt_rec.lot_number)
25319                            AND (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
25320                           --raise error
25321                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25322                           fnd_msg_pub.ADD;
25323                           l_progress := 'WMSINB-25473';
25324                           RAISE fnd_api.g_exc_error;
25325                        END IF;
25326                     END IF;
25327 
25328                     IF l_curr_status NOT IN (1,6) THEN
25329                        --raise error
25330                        fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25331                        fnd_msg_pub.ADD;
25332                        l_progress := 'WMSINB-25482';
25333                        RAISE fnd_api.g_exc_error;
25334                     END IF;
25335 
25336                     IF (Nvl(l_group_mark_id, -99) = -7937) THEN
25337                        --raise error
25338                        fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25339                        fnd_msg_pub.ADD;
25340                        l_progress := 'WMSINB-25490';
25341                        RAISE fnd_api.g_exc_error;
25342                     END IF;
25343 
25344                     IF (Nvl(l_curr_status, 1) in (1,6)) THEN
25345                        --validate and update the attributes.
25346                        inv_serial_number_pub.validate_update_serial_att
25347                          (x_return_status     => x_return_status,
25348                           x_msg_count         => x_msg_count,
25349                           x_msg_data          => x_msg_data,
25350                           x_validation_status => l_validation_status,
25351                           p_serial_number     => l_serial_number,
25352                           p_organization_id   => l_org_id,
25353                           p_inventory_item_id => l_item_id,
25354                           p_serial_att_tbl    => l_serial_attributes_tbl,
25355                           p_validate_only     => FALSE
25356                           );
25357 
25358                        IF (l_validation_status <> 'Y'
25359                            OR x_return_status <> g_ret_sts_success) THEN
25360                           --raise error
25361                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25362                           fnd_msg_pub.ADD;
25363                           l_progress := 'WMSINB-254960';
25364                           RAISE fnd_api.g_exc_error;
25365                        END IF;
25366                     END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
25367 
25368                     --UPDATE GROUP_MARK_ID TO -7937
25369                     IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
25370                        --raise error
25371                        fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25372                        fnd_msg_pub.ADD;
25373                        l_progress := 'WMSINB-25499';
25374                        RAISE fnd_api.g_exc_error;
25375                     END IF;
25376                         ELSE --IF (l_serial_exists = 1) THEN
25377                     IF l_serial_number_control_code = 5 THEN
25378                        --PERFORM SERIAL VALIDATION FOR NEW SERIAL
25379                        --(INCLUDING ATT VALIDATION)
25380                        --CREATE MSN
25381                       IF (l_transaction_type = 'CORRECT') THEN
25382                           l_transaction_action_id := 29;
25383                       ELSE
25384                           l_transaction_action_id := 1;
25385                       END IF;
25386 
25387                       inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
25388                                    , p_inventory_item_id => l_item_id
25389                                    , p_organization_id => l_org_id
25390                                    , p_from_serial_number => l_serial_number
25391                                    , p_to_serial_number => l_serial_number
25392                                    , p_initialization_date => SYSDATE
25393                                    , p_completion_date => NULL
25394                                    , p_ship_date => NULL
25395                                    , p_revision => l_item_revision
25396                                    , p_lot_number => l_mtlt_rec.lot_number
25397                                    , p_current_locator_id => l_loc_id
25398                                    , p_subinventory_code => l_sub_code
25399                                    , p_trx_src_id => NULL
25400                                    , p_unit_vendor_id => NULL
25401                                    , p_vendor_lot_number => l_mtlt_rec.supplier_lot_number
25402                                    , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
25403                                    , p_receipt_issue_type => NULL
25404                                    , p_txn_src_id => NULL
25405                                    , p_txn_src_name => NULL
25406                                    , p_txn_src_type_id => NULL
25407                                    , p_transaction_id => NULL
25408                                    , p_current_status => 1
25409                                    , p_parent_item_id => NULL
25410                                    , p_parent_serial_number => NULL
25411                                    , p_cost_group_id => NULL
25412                                    , p_transaction_action_id => l_transaction_action_id
25413                                    , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
25414                                    , p_status_id => NULL
25415                                    , p_inspection_status => NULL
25416                                    , x_object_id => l_object_id
25417                                    , x_return_status => x_return_status
25418                                    , x_msg_count => x_msg_count
25419                                    , x_msg_data => x_msg_data);
25420 
25421                       IF (x_return_status <> g_ret_sts_success) THEN
25422                         --raise error
25423                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25424                         fnd_msg_pub.ADD;
25425                         l_progress := 'WMSINB-25505';
25426                         RAISE fnd_api.g_exc_error;
25427                       END IF;
25428 
25429                       --validate and update the attributes.
25430                       inv_serial_number_pub.validate_update_serial_att
25431                         (x_return_status     => x_return_status,
25432                          x_msg_count         => x_msg_count,
25433                          x_msg_data          => x_msg_data,
25434                          x_validation_status => l_validation_status,
25435                          p_serial_number     => l_serial_number,
25436                          p_organization_id   => l_org_id,
25437                          p_inventory_item_id => l_item_id,
25438                          p_serial_att_tbl    => l_serial_attributes_tbl,
25439                          p_validate_only     => FALSE
25440                          );
25441 
25442                       IF (l_validation_status <> 'Y'
25443                           OR x_return_status <> g_ret_sts_success) THEN
25444                          --raise error
25445                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25446                          fnd_msg_pub.ADD;
25447                          l_progress := 'WMSINB-25545';
25448                          RAISE fnd_api.g_exc_error;
25449                       END IF;
25450 
25451                       --UPDATE GROUP_MARK_ID TO -7937
25452                       IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
25453                          --raise error
25454                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25455                          fnd_msg_pub.ADD;
25456                          l_progress := 'WMSINB-25552';
25457                          RAISE fnd_api.g_exc_error;
25458                       END IF;
25459                     ELSE --IF l_serial_number_control_code = 5 THEN
25460                        --raise error
25461                        fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25462                        fnd_msg_pub.ADD;
25463                        l_progress := 'WMSINB-25559';
25464                        RAISE fnd_api.g_exc_error;
25465                     END IF; --IF l_serial_number_control_code = 5 THEN
25466                   END IF; --IF (l_serial_exists = 1) THEN
25467                 ELSIF (l_parent_txn_type = g_rtr) THEN --IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
25468                   IF (serial_entered_on_parent(l_great_grand_parent_txn_id)) THEN
25469                     BEGIN
25470                        SELECT '1'
25471                          INTO L_DUMMY
25472                          FROM RCV_SERIALS_SUPPLY
25473                          WHERE TRANSACTION_ID = l_great_grand_parent_txn_id
25474                          AND SERIAL_NUM = L_SERIAL_NUMBER;
25475 
25476                        IF (l_curr_status <> 7) THEN
25477                           --raise error
25478                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25479                           fnd_msg_pub.ADD;
25480                           l_progress := 'WMSINB-25576';
25481                           RAISE fnd_api.g_exc_error;
25482                        END IF;
25483 
25484                       --Validate serial/group_mark_id to prevent entering duplicate serials
25485                       IF (Nvl(l_group_mark_id, -99) = -7937) THEN
25486                         --raise error
25487                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25488                         fnd_msg_pub.ADD;
25489                         l_progress := 'WMSINB-25587';
25490                         RAISE fnd_api.g_exc_error;
25491                       END IF;
25492 
25493                       --UPDATE GROUP_MARK_ID TO -7937
25494                       IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
25495                           --raise error
25496                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25497                           fnd_msg_pub.ADD;
25498                           l_progress := 'WMSINB-25596';
25499                           RAISE fnd_api.g_exc_error;
25500                       END IF;
25501                     EXCEPTION
25502                        WHEN NO_DATA_FOUND THEN
25503                           -- RAISE ERROR
25504                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25505                           fnd_msg_pub.ADD;
25506                           l_progress := 'WMSINB-25604';
25507                           RAISE fnd_api.g_exc_error;
25508                     END;
25509                   ELSE --IF (serial_entered_on_parent(l_great_grand_parent_txn_id)) THEN
25510                     IF (l_serial_exists = 1) THEN
25511                       IF l_curr_org_id <> l_org_id THEN
25512                         --raise error
25513                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25514                         fnd_msg_pub.ADD;
25515                         l_progress := 'WMSINB-25613';
25516                         RAISE fnd_api.g_exc_error;
25517                       ELSE
25518                         IF ((l_curr_lot_num IS NOT NULL) AND (l_curr_lot_num <> l_mtlt_rec.lot_number)
25519                             AND (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
25520                              --raise error
25521                              fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25522                              fnd_msg_pub.ADD;
25523                              l_progress := 'WMSINB-25620';
25524                              RAISE fnd_api.g_exc_error;
25525                         END IF;
25526                       END IF;
25527 
25528                       IF l_curr_status NOT IN (1,6) THEN
25529                          --raise error
25530                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25531                          fnd_msg_pub.ADD;
25532                          l_progress := 'WMSINB-25629';
25533                          RAISE fnd_api.g_exc_error;
25534                       END IF;
25535 
25536                       IF (Nvl(l_group_mark_id, -99) = -7937) THEN
25537                          --raise error
25538                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25539                          fnd_msg_pub.ADD;
25540                          l_progress := 'WMSINB-25637';
25541                          RAISE fnd_api.g_exc_error;
25542                       END IF;
25543 
25544                       IF (Nvl(l_curr_status, 1) in (1,6)) THEN
25545                         --validate and update the attributes.
25546                         inv_serial_number_pub.validate_update_serial_att
25547                           (x_return_status     => x_return_status,
25548                            x_msg_count         => x_msg_count,
25549                            x_msg_data          => x_msg_data,
25550                            x_validation_status => l_validation_status,
25551                            p_serial_number     => l_serial_number,
25552                            p_organization_id   => l_org_id,
25553                            p_inventory_item_id => l_item_id,
25554                            p_serial_att_tbl    => l_serial_attributes_tbl,
25555                            p_validate_only     => FALSE
25556                            );
25557 
25558                         IF (l_validation_status <> 'Y'
25559                           OR x_return_status <> g_ret_sts_success) THEN
25560                            --raise error
25561                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25562                            fnd_msg_pub.ADD;
25563                            l_progress := 'WMSINB-25642';
25564                            RAISE fnd_api.g_exc_error;
25565                         END IF;
25566                       END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
25567 
25568                       --UPDATE GROUP_MARK_ID TO -7937
25569                       IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
25570                         --raise error
25571                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25572                         fnd_msg_pub.ADD;
25573                         l_progress := 'WMSINB-25646';
25574                         RAISE fnd_api.g_exc_error;
25575                       END IF;
25576                     ELSE --IF (l_serial_exists = 1) THEN
25577                       IF l_serial_number_control_code = 5 THEN
25578                         --PERFORM SERIAL VALIDATION FOR NEW SERIAL
25579                         --(INCLUDING ATT VALIDATION)
25580                         --CREATE MSN
25581                         IF (l_transaction_type = 'CORRECT') THEN
25582                            l_transaction_action_id := 29;
25583                         ELSE
25584                            l_transaction_action_id := 1;
25585                         END IF;
25586 
25587                         inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
25588                                         , p_inventory_item_id => l_item_id
25589                                         , p_organization_id => l_org_id
25590                                         , p_from_serial_number => l_serial_number
25591                                         , p_to_serial_number => l_serial_number
25592                                         , p_initialization_date => SYSDATE
25593                                         , p_completion_date => NULL
25594                                         , p_ship_date => NULL
25595                                         , p_revision => l_item_revision
25596                                         , p_lot_number => l_mtlt_rec.lot_number
25597                                         , p_current_locator_id => l_loc_id
25598                                         , p_subinventory_code => l_sub_code
25599                                         , p_trx_src_id => NULL
25600                                         , p_unit_vendor_id => NULL
25601                                         , p_vendor_lot_number => l_mtlt_rec.supplier_lot_number
25602                                         , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
25603                                         , p_receipt_issue_type => NULL
25604                                         , p_txn_src_id => NULL
25605                                         , p_txn_src_name => NULL
25606                                         , p_txn_src_type_id => NULL
25607                                         , p_transaction_id => NULL
25608                                         , p_current_status => 1
25609                                         , p_parent_item_id => NULL
25610                                         , p_parent_serial_number => NULL
25611                                         , p_cost_group_id => NULL
25612                                         , p_transaction_action_id => l_transaction_action_id
25613                                         , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
25614                                         , p_status_id => NULL
25615                                         , p_inspection_status => NULL
25616                                         , x_object_id => l_object_id
25617                                         , x_return_status => x_return_status
25618                                         , x_msg_count => x_msg_count
25619                                         , x_msg_data => x_msg_data);
25620 
25621                         IF (x_return_status <> g_ret_sts_success) THEN
25622                           --raise error
25623                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25624                           fnd_msg_pub.ADD;
25625                           l_progress := 'WMSINB-25650';
25626                           RAISE fnd_api.g_exc_error;
25627                         END IF;
25628 
25629                         --validate and update the attributes.
25630                         inv_serial_number_pub.validate_update_serial_att
25631                           (x_return_status     => x_return_status,
25632                            x_msg_count         => x_msg_count,
25633                            x_msg_data          => x_msg_data,
25634                            x_validation_status => l_validation_status,
25635                            p_serial_number     => l_serial_number,
25636                            p_organization_id   => l_org_id,
25637                            p_inventory_item_id => l_item_id,
25638                            p_serial_att_tbl    => l_serial_attributes_tbl,
25639                            p_validate_only     => FALSE
25640                            );
25641 
25642                         IF (l_validation_status <> 'Y' OR x_return_status <> g_ret_sts_success) THEN
25643                            --raise error
25644                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25645                            fnd_msg_pub.ADD;
25646                            l_progress := 'WMSINB-25691';
25647                            RAISE fnd_api.g_exc_error;
25648                         END IF;
25649 
25650                         --UPDATE GROUP_MARK_ID TO -7937
25651                         IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
25652                            --raise error
25653                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25654                            fnd_msg_pub.ADD;
25655                            l_progress := 'WMSINB-25699';
25656                            RAISE fnd_api.g_exc_error;
25657                         END IF;
25658                       ELSE --IF l_serial_number_control_code = 5 THEN
25659                         --raise error
25660                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25661                         fnd_msg_pub.ADD;
25662                         l_progress := 'WMSINB-25706';
25663                         RAISE fnd_api.g_exc_error;
25664                       END IF; --IF l_serial_number_control_code = 5 THEN
25665                     END IF; --IF (l_serial_exists = 1) THEN
25666                   END IF; --IF (serial_entered_on_parent(l_great_grand_parent_txn_id)) THEN
25667                 ELSE --ELSIF (l_parent_txn_type = g_rtr) THEN
25668                   IF (l_parent_txn_type <> 'DELIVER') THEN
25669                     IF NOT (serial_entered_on_parent(l_parent_transaction_id)) THEN
25670                       --raise an error
25671                       l_progress := 'WMSINB-25715';
25672                       RAISE fnd_api.g_exc_error;
25673                     ELSE
25674                       BEGIN
25675                         SELECT '1'
25676                           INTO L_DUMMY
25677                           FROM RCV_SERIALS_SUPPLY
25678                           WHERE TRANSACTION_ID = l_parent_transaction_id
25679                           AND SERIAL_NUM = L_SERIAL_NUMBER;
25680 
25681                         IF (l_curr_status <> 7) THEN
25682                            --raise error
25683                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25684                            fnd_msg_pub.ADD;
25685                            l_progress := 'WMSINB-25729';
25686                            RAISE fnd_api.g_exc_error;
25687                         END IF;
25688 
25689                         --Validate serial/group_mark_id to prevent
25690                         --entering of duplicate serials
25691 
25692                         IF (Nvl(l_group_mark_id, -99) = -7937) THEN
25693                            --raise error
25694                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25695                            fnd_msg_pub.ADD;
25696                            l_progress := 'WMSINB-25740';
25697                            RAISE fnd_api.g_exc_error;
25698                         END IF;
25699 
25700                         --UPDATE GROUP_MARK_ID TO -7937
25701                         IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
25702                            --raise error
25703                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25704                            fnd_msg_pub.ADD;
25705                            l_progress := 'WMSINB-25749';
25706                            RAISE fnd_api.g_exc_error;
25707                         END IF;
25708                       EXCEPTION
25709                         WHEN NO_DATA_FOUND THEN
25710                            -- RAISE ERROR
25711                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25712                            fnd_msg_pub.ADD;
25713                            l_progress := 'WMSINB-25757';
25714                            RAISE fnd_api.g_exc_error;
25715                        END;
25716                     END IF; --IF NOT (serial_entered_on_parent(l_parent_transaction_id)) THEN
25717                   ELSE --IF (l_parent_txn_type <> 'DELIVER') THEN
25718                     IF l_curr_org_id <> l_org_id THEN
25719                        --raise error
25720                        fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25721                        fnd_msg_pub.ADD;
25722                        l_progress := 'WMSINB-25766';
25723                        RAISE fnd_api.g_exc_error;
25724                     ELSE
25725                        IF ((l_curr_lot_num IS NOT NULL)
25726                            AND (l_curr_lot_num <>
25727                           l_mtlt_rec.lot_number)
25728                            AND (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
25729                           --raise error
25730                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25731                           fnd_msg_pub.ADD;
25732                           l_progress := 'WMSINB-25773';
25733                           RAISE fnd_api.g_exc_error;
25734                        END IF;
25735                     END IF;
25736 
25737                     IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
25738                        IF l_curr_status NOT IN (1,6) THEN
25739                           --raise error
25740                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25741                           fnd_msg_pub.ADD;
25742                           l_progress := 'WMSINB-25783';
25743                           RAISE fnd_api.g_exc_error;
25744                        END IF;
25745                     --Serial tagging: modified condition to validate current_status 3 for serial controlled items
25746                     --ELSE --IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
25747                     ELSIF l_serial_number_control_code in (2,5) THEN
25748                        IF (l_curr_status <> 3) THEN
25749                           --raise error
25750                           fnd_message.set_name('INV','INV_FAIL_VALIDATE_SERIAL');
25751                           fnd_msg_pub.ADD;
25752                           l_progress := 'WMSINB-25791';
25753                           RAISE fnd_api.g_exc_error;
25754                        END IF;
25755                     END IF; --IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
25756 
25757                     IF (Nvl(l_group_mark_id, -99) = -7937) THEN
25758                        --raise error
25759                        fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25760                        fnd_msg_pub.ADD;
25761                        l_progress := 'WMSINB-25800';
25762                        RAISE fnd_api.g_exc_error;
25763                     END IF;
25764 
25765                     IF (Nvl(l_curr_status, 1) in (1,6)) THEN
25766                        --validate and update the attributes.
25767                        inv_serial_number_pub.validate_update_serial_att
25768                          (x_return_status     => x_return_status,
25769                           x_msg_count         => x_msg_count,
25770                           x_msg_data          => x_msg_data,
25771                           x_validation_status => l_validation_status,
25772                           p_serial_number     => l_serial_number,
25773                           p_organization_id   => l_org_id,
25774                           p_inventory_item_id => l_item_id,
25775                           p_serial_att_tbl    => l_serial_attributes_tbl,
25776                           p_validate_only     => FALSE
25777                           );
25778 
25779                        IF (l_validation_status <> 'Y'
25780                            OR x_return_status <> g_ret_sts_success) THEN
25781                           --raise error
25782                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25783                           fnd_msg_pub.ADD;
25784                           l_progress := 'WMSINB-25805';
25785                           RAISE fnd_api.g_exc_error;
25786                        END IF;
25787                     END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
25788 
25789                     --UPDATE GROUP_MARK_ID TO -7937
25790                     IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
25791                        --raise error
25792                        fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25793                        fnd_msg_pub.ADD;
25794                        l_progress := 'WMSINB-25809';
25795                        RAISE fnd_api.g_exc_error;
25796                     END IF;
25797                   END IF; --IF (l_parent_txn_type <> 'DELIVER') THEN
25798                 END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
25799               END LOOP; -- FOR 1..L_SERIAL_QUANTITY
25800             END LOOP; --FETCH C_MSNT_LOTSERIAL INTO L_MSNT_REC;
25801 
25802             CLOSE c_msnt_lotserial;
25803 
25804             IF (l_num_msnt_recs > 0) THEN
25805               IF l_mtlt_rec.primary_quantity <> l_tot_msnt_serial_qty THEN
25806                 --raise error
25807                 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25808                 fnd_msg_pub.ADD;
25809                 l_progress := 'WMSINB-25824';
25810                 RAISE fnd_api.g_exc_error;
25811               END IF;
25812             ELSE
25813                IF (l_serial_number_control_code IN (2,5)
25814                   OR (l_serial_number_control_code = 6 AND l_source_document_code IN ('RMA','REQ','INVENTORY')))
25815                THEN
25816                   --raise error
25817                   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25818                   fnd_msg_pub.ADD;
25819                   l_progress := 'WMSINB-25831';
25820                   RAISE fnd_api.g_exc_error;
25821                END IF;
25822             END IF;
25823 
25824           END IF; -- IF (L_SERIAL_NUMBER_CONTROL_CODE IN (2,5,6)) THEN
25825         END LOOP; --FETCH C_MTLT INTO L_MTLT_REC;
25826 
25827         CLOSE c_mtlt;
25828 
25829         /* Bug 4546519 : l_tot_mtlt_prim_qty is a computed floating point number.
25830          **  In the following condition, it is necessary to use round function for
25831          **  comparing the floating point values.
25832          */
25833 
25834         IF (l_num_mtlt_recs > 0) THEN
25835           IF (ROUND(l_tot_mtlt_prim_qty,5) <> ROUND(Abs(l_rti_primary_qty),5)) THEN
25836             -- Bug# 4225766 Compare transaction qty there can be a difference in primary qty
25837             -- if there is a lot specific conversion
25838             IF (ROUND(l_tot_mtlt_trans_qty,5) <> ROUND(Abs(l_rti_trans_qty),5)) THEN -- Bug# 4225766
25839               --raise error
25840               fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25841               fnd_msg_pub.ADD;
25842               l_progress := 'WMSINB-25845';
25843               RAISE fnd_api.g_exc_error;
25844             END IF; -- Bug# 4225766
25845           END IF;
25846         ELSE
25847           IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
25848             IF (l_grand_parent_txn_type = 'DELIVER') THEN
25849                --raise an error
25850                l_progress := 'WMSINB-25852';
25851                RAISE fnd_api.g_exc_error;
25852             ELSE
25853               IF (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
25854                 --raise error;
25855                 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
25856                 fnd_msg_pub.ADD;
25857                 l_progress := 'WMSINB-25859';
25858                 RAISE fnd_api.g_exc_error;
25859               END IF;
25860             END IF; --IF (l_grand_parent_txn_type = 'DELIVER') THEN
25861           ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
25862             IF (l_parent_txn_type <> 'DELIVER') THEN
25863               IF (lot_entered_on_parent(l_parent_transaction_id)) THEN
25864                 --raise an error
25865                 l_progress := 'WMSINB-25867';
25866                 RAISE fnd_api.g_exc_error;
25867               END IF;
25868             ELSE
25869                --raise an error
25870                l_progress := 'WMSINB-25872';
25871                RAISE fnd_api.g_exc_error;
25872             END IF; -- IF (l_parent_txn_type <> 'DELIVER') THEN
25873           END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
25874         END IF; --IF (l_num_mtlt_recs > 0) THEN
25875       ELSIF (l_serial_number_control_code IN (2,5,6)) THEN -- IF (l_lot_control_code = 2) THEN
25876         IF (l_debug = 1) THEN
25877           print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROLLED: '||l_progress, 1);
25878           print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROL CODE: '||l_serial_number_control_code||' : '||l_progress, 1);
25879           print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||l_source_document_code||' : '||l_progress, 1);
25880           l_progress := 'WMSINB-25882';
25881         END IF;
25882 
25883         L_NUM_MSNT_RECS := 0;
25884         l_tot_msnt_serial_qty := 0;
25885 
25886         OPEN C_MSNT(L_RTI_ID);
25887         LOOP
25888           FETCH C_MSNT INTO L_MSNT_REC;
25889           EXIT WHEN C_MSNT%NOTFOUND;
25890 
25891           L_NUM_MSNT_RECS := L_NUM_MSNT_RECS + 1;
25892           L_SERIAL_QUANTITY := INV_SERIAL_NUMBER_PUB.GET_SERIAL_DIFF(L_MSNT_REC.FM_SERIAL_NUMBER,
25893                                                                      L_MSNT_REC.TO_SERIAL_NUMBER);
25894           l_tot_msnt_serial_qty := l_tot_msnt_serial_qty + l_serial_quantity;
25895 
25896           INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.FM_SERIAL_NUMBER, L_TEMP_PREFIX, L_FROM_SER_NUMBER);
25897           INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.TO_SERIAL_NUMBER, L_TEMP_PREFIX, L_TO_SER_NUMBER);
25898 
25899           IF (l_debug = 1) THEN
25900             print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL QUANTITY: '||l_serial_quantity||' : '||l_progress, 1);
25901             l_progress := 'WMSINB-25907';
25902           END IF;
25903 
25904           --populate attributes table
25905           l_serial_attributes_tbl(1).column_name   := 'SERIAL_ATTRIBUTE_CATEGORY';
25906           l_serial_attributes_tbl(1).column_value  := l_msnt_rec.serial_attribute_category;
25907           l_serial_attributes_tbl(2).column_name   := 'ORIGINATION_DATE';
25908           l_serial_attributes_tbl(2).column_value  := l_msnt_rec.origination_date;
25909           l_serial_attributes_tbl(3).column_name   := 'C_ATTRIBUTE1';
25910           l_serial_attributes_tbl(3).column_value  := l_msnt_rec.c_attribute1;
25911           l_serial_attributes_tbl(4).column_name   := 'C_ATTRIBUTE2';
25912           l_serial_attributes_tbl(4).column_value  := l_msnt_rec.c_attribute2;
25913           l_serial_attributes_tbl(5).column_name   := 'C_ATTRIBUTE3';
25914           l_serial_attributes_tbl(5).column_value  := l_msnt_rec.c_attribute3;
25915           l_serial_attributes_tbl(6).column_name   := 'C_ATTRIBUTE4';
25916           l_serial_attributes_tbl(6).column_value   := l_msnt_rec.c_attribute4;
25917           l_serial_attributes_tbl(7).column_name   := 'C_ATTRIBUTE5';
25918           l_serial_attributes_tbl(7).column_value   := l_msnt_rec.c_attribute5;
25919           l_serial_attributes_tbl(8).column_name   := 'C_ATTRIBUTE6';
25920           l_serial_attributes_tbl(8).column_value   := l_msnt_rec.c_attribute6;
25921           l_serial_attributes_tbl(9).column_name   := 'C_ATTRIBUTE7';
25922           l_serial_attributes_tbl(9).column_value   := l_msnt_rec.c_attribute7;
25923           l_serial_attributes_tbl(10).column_name  := 'C_ATTRIBUTE8';
25924           l_serial_attributes_tbl(10).column_value  := l_msnt_rec.c_attribute8;
25925           l_serial_attributes_tbl(11).column_name  := 'C_ATTRIBUTE9';
25926           l_serial_attributes_tbl(11).column_value  := l_msnt_rec.c_attribute9;
25927           l_serial_attributes_tbl(12).column_name  := 'C_ATTRIBUTE10';
25928           l_serial_attributes_tbl(12).column_value  := l_msnt_rec.c_attribute10;
25929           l_serial_attributes_tbl(13).column_name  := 'C_ATTRIBUTE11';
25930           l_serial_attributes_tbl(13).column_value  := l_msnt_rec.c_attribute11;
25931           l_serial_attributes_tbl(14).column_name  := 'C_ATTRIBUTE12';
25932           l_serial_attributes_tbl(14).column_value  := l_msnt_rec.c_attribute12;
25933           l_serial_attributes_tbl(15).column_name  := 'C_ATTRIBUTE13';
25934           l_serial_attributes_tbl(15).column_value  := l_msnt_rec.c_attribute13;
25935           l_serial_attributes_tbl(16).column_name  := 'C_ATTRIBUTE14';
25936           l_serial_attributes_tbl(16).column_value  := l_msnt_rec.c_attribute14;
25937           l_serial_attributes_tbl(17).column_name  := 'C_ATTRIBUTE15';
25938           l_serial_attributes_tbl(17).column_value  := l_msnt_rec.c_attribute15;
25939           l_serial_attributes_tbl(18).column_name  := 'C_ATTRIBUTE16';
25940           l_serial_attributes_tbl(18).column_value  := l_msnt_rec.c_attribute16;
25941           l_serial_attributes_tbl(19).column_name  := 'C_ATTRIBUTE17';
25942           l_serial_attributes_tbl(19).column_value  := l_msnt_rec.c_attribute17;
25943           l_serial_attributes_tbl(20).column_name  := 'C_ATTRIBUTE18';
25944           l_serial_attributes_tbl(20).column_value  := l_msnt_rec.c_attribute18;
25945           l_serial_attributes_tbl(21).column_name  := 'C_ATTRIBUTE19';
25946           l_serial_attributes_tbl(21).column_value  := l_msnt_rec.c_attribute19;
25947           l_serial_attributes_tbl(22).column_name  := 'C_ATTRIBUTE20';
25948           l_serial_attributes_tbl(22).column_value  := l_msnt_rec.c_attribute20;
25949           l_serial_attributes_tbl(23).column_name  := 'D_ATTRIBUTE1';
25950           l_serial_attributes_tbl(23).column_value  := l_msnt_rec.d_attribute1;
25951           l_serial_attributes_tbl(24).column_name  := 'D_ATTRIBUTE2';
25952           l_serial_attributes_tbl(24).column_value  := l_msnt_rec.d_attribute2;
25953           l_serial_attributes_tbl(25).column_name  := 'D_ATTRIBUTE3';
25954           l_serial_attributes_tbl(25).column_value  := l_msnt_rec.d_attribute3;
25955           l_serial_attributes_tbl(26).column_name  := 'D_ATTRIBUTE4';
25956           l_serial_attributes_tbl(26).column_value  := l_msnt_rec.d_attribute4;
25957           l_serial_attributes_tbl(27).column_name  := 'D_ATTRIBUTE5';
25958           l_serial_attributes_tbl(27).column_value  := l_msnt_rec.d_attribute5;
25959           l_serial_attributes_tbl(28).column_name  := 'D_ATTRIBUTE6';
25960           l_serial_attributes_tbl(28).column_value  := l_msnt_rec.d_attribute6;
25961           l_serial_attributes_tbl(29).column_name  := 'D_ATTRIBUTE7';
25962           l_serial_attributes_tbl(29).column_value  := l_msnt_rec.d_attribute7;
25963           l_serial_attributes_tbl(30).column_name  := 'D_ATTRIBUTE8';
25964           l_serial_attributes_tbl(30).column_value  := l_msnt_rec.d_attribute8;
25965           l_serial_attributes_tbl(31).column_name  := 'D_ATTRIBUTE9';
25966           l_serial_attributes_tbl(31).column_value  := l_msnt_rec.d_attribute9;
25967           l_serial_attributes_tbl(32).column_name  := 'D_ATTRIBUTE10';
25968           l_serial_attributes_tbl(32).column_value  := l_msnt_rec.d_attribute10;
25969           l_serial_attributes_tbl(33).column_name  := 'N_ATTRIBUTE1';
25970           l_serial_attributes_tbl(33).column_value  := l_msnt_rec.n_attribute1;
25971           l_serial_attributes_tbl(34).column_name  := 'N_ATTRIBUTE2';
25972           l_serial_attributes_tbl(34).column_value  := l_msnt_rec.n_attribute2;
25973           l_serial_attributes_tbl(35).column_name  := 'N_ATTRIBUTE3';
25974           l_serial_attributes_tbl(35).column_value  := l_msnt_rec.n_attribute3;
25975           l_serial_attributes_tbl(36).column_name  := 'N_ATTRIBUTE4';
25976           l_serial_attributes_tbl(36).column_value  := l_msnt_rec.n_attribute4;
25977           l_serial_attributes_tbl(37).column_name  := 'N_ATTRIBUTE5';
25978           l_serial_attributes_tbl(37).column_value := l_msnt_rec.n_attribute5;
25979           l_serial_attributes_tbl(38).column_name  := 'N_ATTRIBUTE6';
25980           l_serial_attributes_tbl(38).column_value := l_msnt_rec.n_attribute6;
25981           l_serial_attributes_tbl(39).column_name  := 'N_ATTRIBUTE7';
25982           l_serial_attributes_tbl(39).column_value := l_msnt_rec.n_attribute7;
25983           l_serial_attributes_tbl(40).column_name  := 'N_ATTRIBUTE8';
25984           l_serial_attributes_tbl(40).column_value := l_msnt_rec.n_attribute8;
25985           l_serial_attributes_tbl(41).column_name  := 'N_ATTRIBUTE9';
25986           l_serial_attributes_tbl(41).column_value := l_msnt_rec.n_attribute9;
25987           l_serial_attributes_tbl(42).column_name  := 'N_ATTRIBUTE10';
25988           l_serial_attributes_tbl(42).column_value := l_msnt_rec.n_attribute10;
25989           l_serial_attributes_tbl(43).column_name  := 'STATUS_ID';
25990           l_serial_attributes_tbl(43).column_value := l_msnt_rec.status_id;
25991           l_serial_attributes_tbl(44).column_name  := 'TERRITORY_CODE';
25992           l_serial_attributes_tbl(44).column_value := l_msnt_rec.territory_code;
25993           l_serial_attributes_tbl(45).column_name   := 'ATTRIBUTE_CATEGORY';
25994           l_serial_attributes_tbl(45).column_value  := l_msnt_rec.attribute_category;
25995           l_serial_attributes_tbl(46).column_name   := 'ATTRIBUTE1';
25996           l_serial_attributes_tbl(46).column_value  := l_msnt_rec.attribute1;
25997           l_serial_attributes_tbl(47).column_name   := 'ATTRIBUTE2';
25998           l_serial_attributes_tbl(47).column_value  := l_msnt_rec.attribute2;
25999           l_serial_attributes_tbl(48).column_name   := 'ATTRIBUTE3';
26000           l_serial_attributes_tbl(48).column_value  := l_msnt_rec.attribute3;
26001           l_serial_attributes_tbl(49).column_name   := 'ATTRIBUTE4';
26002           l_serial_attributes_tbl(49).column_value   := l_msnt_rec.attribute4;
26003           l_serial_attributes_tbl(50).column_name   := 'ATTRIBUTE5';
26004           l_serial_attributes_tbl(50).column_value   := l_msnt_rec.attribute5;
26005           l_serial_attributes_tbl(51).column_name   := 'ATTRIBUTE6';
26006           l_serial_attributes_tbl(51).column_value   := l_msnt_rec.attribute6;
26007           l_serial_attributes_tbl(52).column_name   := 'ATTRIBUTE7';
26008           l_serial_attributes_tbl(52).column_value   := l_msnt_rec.attribute7;
26009           l_serial_attributes_tbl(53).column_name  := 'ATTRIBUTE8';
26010           l_serial_attributes_tbl(53).column_value  := l_msnt_rec.attribute8;
26011           l_serial_attributes_tbl(54).column_name  := 'ATTRIBUTE9';
26012           l_serial_attributes_tbl(54).column_value  := l_msnt_rec.attribute9;
26013           l_serial_attributes_tbl(55).column_name  := 'ATTRIBUTE10';
26014           l_serial_attributes_tbl(55).column_value  := l_msnt_rec.attribute10;
26015           l_serial_attributes_tbl(56).column_name  := 'ATTRIBUTE11';
26016           l_serial_attributes_tbl(56).column_value  := l_msnt_rec.attribute11;
26017           l_serial_attributes_tbl(57).column_name  := 'ATTRIBUTE12';
26018           l_serial_attributes_tbl(57).column_value  := l_msnt_rec.attribute12;
26019           l_serial_attributes_tbl(58).column_name  := 'ATTRIBUTE13';
26020           l_serial_attributes_tbl(58).column_value  := l_msnt_rec.attribute13;
26021           l_serial_attributes_tbl(59).column_name  := 'ATTRIBUTE14';
26022           l_serial_attributes_tbl(59).column_value  := l_msnt_rec.attribute14;
26023           l_serial_attributes_tbl(60).column_name  := 'ATTRIBUTE15';
26024           l_serial_attributes_tbl(60).column_value  := l_msnt_rec.attribute15;
26025 
26026           --Validate the serials
26027           FOR SERIALQTY IN 1..L_SERIAL_QUANTITY LOOP
26028 
26029             l_progress := 'WMSINB-25913';
26030             L_CUR_NUMBER := L_FROM_SER_NUMBER+SERIALQTY -1;
26031             if L_FROM_SER_NUMBER = -1 and  L_TO_SER_NUMBER = -1 then
26032               L_SERIAL_NUMBER  := L_MSNT_REC.fm_serial_number;
26033             else
26034               L_SERIAL_NUMBER :=  SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
26035                                     LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) - LENGTH(L_CUR_NUMBER))
26036                                   ||L_CUR_NUMBER;
26037             End if;
26038 
26039             l_progress := 'WMSINB-25921';
26040 
26041             BEGIN
26042               SELECT CURRENT_ORGANIZATION_ID
26043               , current_status
26044               , lot_number
26045               , Decode(lpn_id,0,NULL,lpn_id)
26046               , inspection_status
26047               , group_mark_id
26048               INTO L_CURR_ORG_ID
26049               , l_curr_status
26050               , l_curr_lot_num
26051               , l_curr_lpn_id
26052               , l_inspection_status
26053               , l_group_mark_id
26054               FROM MTL_SERIAL_NUMBERS
26055               WHERE SERIAL_NUMBER = l_serial_number
26056               AND inventory_item_id = l_item_id;
26057 
26058               l_serial_exists := 1;
26059               l_progress := 'WMSINB-25941';
26060             EXCEPTION
26061               WHEN no_data_found THEN
26062                 l_serial_exists := 0;
26063                 l_progress := 'WMSINB-25945';
26064             END;
26065 
26066             IF (l_debug = 1) THEN
26067               print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL EXISTS: '||l_serial_exists||' : '||l_progress, 1);
26068               print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NUMBER: '||l_serial_number||' : '||l_progress, 1);
26069               print_debug('VALIDATE_LOT_SERIAL_INFO: CURR STATUS: '||l_curr_status||' : '||l_progress, 1);
26070               print_debug('VALIDATE_LOT_SERIAL_INFO: CURR ORG ID: '||l_curr_org_id||' : '||l_progress, 1);
26071               print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LPN ID: '||l_curr_lpn_id||' : '||l_progress, 1);
26072               print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LOT NUM: '||l_curr_lot_num||' : '||l_progress, 1);
26073               print_debug('VALIDATE_LOT_SERIAL_INFO: INSPECT STS: '||l_inspection_status||' : '||l_progress, 1);
26074               print_debug('VALIDATE_LOT_SERIAL_INFO: GROUP MARK ID: '||l_group_mark_id||' : '||l_progress, 1);
26075               print_debug('VALIDATE_LOT_SERIAL_INFO: RESTRICT RCPT SER: '||l_restrict_rcpt_ser||' : '||l_progress, 1);
26076               l_progress := 'WMSINB-25958';
26077             END IF;
26078 
26079             IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
26080               IF (l_grand_parent_txn_type <> 'DELIVER') THEN
26081                 IF NOT (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
26082                   --raise an error
26083                   l_progress := 'WMSINB-25965';
26084                   RAISE fnd_api.g_exc_error;
26085                 END IF;
26086               END IF; --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
26087 
26088               IF (l_serial_exists = 1) THEN
26089                 IF l_curr_org_id <> l_org_id THEN
26090                   --raise error
26091                   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26092                   fnd_msg_pub.ADD;
26093                   l_progress := 'WMSINB-25975';
26094                   RAISE fnd_api.g_exc_error;
26095                 ELSE
26096                   IF (l_curr_lot_num IS NOT NULL) THEN
26097                      --raise error
26098                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26099                      fnd_msg_pub.ADD;
26100                      l_progress := 'WMSINB-25982';
26101                      RAISE fnd_api.g_exc_error;
26102                   END IF;
26103                 END IF;
26104 
26105                 IF l_curr_status NOT IN (1,6) THEN
26106                     --raise error
26107                     fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26108                     fnd_msg_pub.ADD;
26109                     l_progress := 'WMSINB-25991';
26110                     RAISE fnd_api.g_exc_error;
26111                 END IF;
26112 
26113                 IF (Nvl(l_group_mark_id, -99) = -7937) THEN
26114                   --raise error
26115                   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26116                   fnd_msg_pub.ADD;
26117                   l_progress := 'WMSINB-25999';
26118                   RAISE fnd_api.g_exc_error;
26119                 END IF;
26120 
26121                 IF (Nvl(l_curr_status, 1) in (1,6)) THEN
26122                    --validate and update the attributes.
26123                    inv_serial_number_pub.validate_update_serial_att
26124                      (x_return_status     => x_return_status,
26125                       x_msg_count         => x_msg_count,
26126                       x_msg_data          => x_msg_data,
26127                       x_validation_status => l_validation_status,
26128                       p_serial_number     => l_serial_number,
26129                       p_organization_id   => l_org_id,
26130                       p_inventory_item_id => l_item_id,
26131                       p_serial_att_tbl    => l_serial_attributes_tbl,
26132                       p_validate_only     => FALSE
26133                       );
26134 
26135                    IF (l_validation_status <> 'Y'
26136                        OR x_return_status <> g_ret_sts_success) THEN
26137                       --raise error
26138                       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26139                       fnd_msg_pub.ADD;
26140                       l_progress := 'WMSINB-26005';
26141                       RAISE fnd_api.g_exc_error;
26142                    END IF;
26143                 END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
26144 
26145                 --UPDATE GROUP_MARK_ID TO -7937
26146                 IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
26147                    --raise error
26148                    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26149                    fnd_msg_pub.ADD;
26150                    l_progress := 'WMSINB-26008';
26151                    RAISE fnd_api.g_exc_error;
26152                 END IF;
26153               ELSE --IF (l_serial_exists = 1) THEN
26154                 IF l_serial_number_control_code = 5 THEN
26155                   --PERFORM SERIAL VALIDATION FOR NEW SERIAL
26156                   --(INCLUDING ATT VALIDATION)
26157                   --CREATE MSN
26158                   IF (l_transaction_type = 'CORRECT') THEN
26159                      l_transaction_action_id := 29;
26160                   ELSE
26161                      l_transaction_action_id := 1;
26162                   END IF;
26163 
26164                   inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
26165                           , p_inventory_item_id => l_item_id
26166                           , p_organization_id => l_org_id
26167                           , p_from_serial_number => l_serial_number
26168                           , p_to_serial_number => l_serial_number
26169                           , p_initialization_date => SYSDATE
26170                           , p_completion_date => NULL
26171                           , p_ship_date => NULL
26172                           , p_revision => l_item_revision
26173                           , p_lot_number => NULL
26174                           , p_current_locator_id => l_loc_id
26175                           , p_subinventory_code => l_sub_code
26176                           , p_trx_src_id => NULL
26177                           , p_unit_vendor_id => NULL
26178                           , p_vendor_lot_number => NULL
26179                           , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
26180                           , p_receipt_issue_type => NULL
26181                           , p_txn_src_id => NULL
26182                           , p_txn_src_name => NULL
26183                           , p_txn_src_type_id => NULL
26184                           , p_transaction_id => NULL
26185                           , p_current_status => 1
26186                           , p_parent_item_id => NULL
26187                           , p_parent_serial_number => NULL
26188                           , p_cost_group_id => NULL
26189                           , p_transaction_action_id => l_transaction_action_id
26190                           , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
26191                           , p_status_id => NULL
26192                           , p_inspection_status => NULL
26193                           , x_object_id => l_object_id
26194                           , x_return_status => x_return_status
26195                           , x_msg_count => x_msg_count
26196                           , x_msg_data => x_msg_data);
26197 
26198                   IF (x_return_status <> g_ret_sts_success) THEN
26199                      --raise error
26200                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26201                      fnd_msg_pub.ADD;
26202                      l_progress := 'WMSINB-26015';
26203                      RAISE fnd_api.g_exc_error;
26204                   END IF;
26205 
26206                   --validate and update the attributes.
26207                   inv_serial_number_pub.validate_update_serial_att
26208                     (x_return_status     => x_return_status,
26209                      x_msg_count         => x_msg_count,
26210                      x_msg_data          => x_msg_data,
26211                      x_validation_status => l_validation_status,
26212                      p_serial_number     => l_serial_number,
26213                      p_organization_id   => l_org_id,
26214                      p_inventory_item_id => l_item_id,
26215                      p_serial_att_tbl    => l_serial_attributes_tbl,
26216                      p_validate_only     => FALSE
26217                      );
26218 
26219                   IF (l_validation_status <> 'Y' OR x_return_status <> g_ret_sts_success) THEN
26220                      --raise error
26221                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26222                      fnd_msg_pub.ADD;
26223                      l_progress := 'WMSINB-29051';
26224                      RAISE fnd_api.g_exc_error;
26225                   END IF;
26226 
26227                   --UPDATE GROUP_MARK_ID TO -7937
26228                   IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
26229                      --raise error
26230                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26231                      fnd_msg_pub.ADD;
26232                      l_progress := 'WMSINB-26061';
26233                      RAISE fnd_api.g_exc_error;
26234                   END IF;
26235                 ELSE --IF l_serial_number_control_code = 5 THEN
26236                   --raise error
26237                   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26238                   fnd_msg_pub.ADD;
26239                   l_progress := 'WMSINB-26068';
26240                   RAISE fnd_api.g_exc_error;
26241                 END IF; --IF l_serial_number_control_code = 5 THEN
26242               END IF; --IF (l_serial_exists = 1) THEN
26243             ELSIF (l_parent_txn_type = g_rtr) THEN --IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
26244               IF (serial_entered_on_parent(l_great_grand_parent_txn_id)) THEN
26245                 BEGIN
26246                   SELECT '1'
26247                     INTO L_DUMMY
26248                     FROM RCV_SERIALS_SUPPLY
26249                     WHERE TRANSACTION_ID = l_great_grand_parent_txn_id
26250                     AND SERIAL_NUM = L_SERIAL_NUMBER;
26251 
26252                   IF (l_curr_status <> 7) THEN
26253                      --raise error
26254                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26255                      fnd_msg_pub.ADD;
26256                      l_progress := 'WMSINB-26085';
26257                      RAISE fnd_api.g_exc_error;
26258                   END IF;
26259 
26260                   --Validate serial/group_mark_id to prevent entering of duplicate serials
26261                   IF (Nvl(l_group_mark_id, -99) = -7937) THEN
26262                      --raise error
26263                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26264                      fnd_msg_pub.ADD;
26265                      l_progress := 'WMSINB-26096';
26266                      RAISE fnd_api.g_exc_error;
26267                   END IF;
26268 
26269                   --UPDATE GROUP_MARK_ID TO -7937
26270                   IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
26271                      --raise error
26272                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26273                      fnd_msg_pub.ADD;
26274                      l_progress := 'WMSINB-26105';
26275                      RAISE fnd_api.g_exc_error;
26276                   END IF;
26277                 EXCEPTION
26278                   WHEN NO_DATA_FOUND THEN
26279                      -- RAISE ERROR
26280                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26281                      fnd_msg_pub.ADD;
26282                      l_progress := 'WMSINB-26113';
26283                      RAISE fnd_api.g_exc_error;
26284                 END;
26285               ELSE --IF (serial_entered_on_parent(l_great_grand_parent_txn_id)) THEN
26286                 IF (l_serial_exists = 1) THEN
26287                   IF l_curr_org_id <> l_org_id THEN
26288                      --raise error
26289                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26290                      fnd_msg_pub.ADD;
26291                      l_progress := 'WMSINB-26122';
26292                      RAISE fnd_api.g_exc_error;
26293                   ELSE
26294                      IF (l_curr_lot_num IS NOT NULL) THEN
26295                         --raise error
26296                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26297                         fnd_msg_pub.ADD;
26298                         l_progress := 'WMSINB-26129';
26299                         RAISE fnd_api.g_exc_error;
26300                      END IF;
26301                   END IF;
26302 
26303                   IF l_curr_status NOT IN (1,6) THEN
26304                      --raise error
26305                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26306                      fnd_msg_pub.ADD;
26307                      l_progress := 'WMSINB-26138';
26308                      RAISE fnd_api.g_exc_error;
26309                   END IF;
26310 
26311                   IF (Nvl(l_group_mark_id, -99) = -7937) THEN
26312                      --raise error
26313                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26314                      fnd_msg_pub.ADD;
26315                      l_progress := 'WMSINB-26146';
26316                      RAISE fnd_api.g_exc_error;
26317                   END IF;
26318 
26319                   IF (Nvl(l_curr_status, 1) in (1,6)) THEN
26320                      --validate and update the attributes.
26321                      inv_serial_number_pub.validate_update_serial_att
26322                        (x_return_status     => x_return_status,
26323                         x_msg_count         => x_msg_count,
26324                         x_msg_data          => x_msg_data,
26325                         x_validation_status => l_validation_status,
26326                         p_serial_number     => l_serial_number,
26327                         p_organization_id   => l_org_id,
26328                         p_inventory_item_id => l_item_id,
26329                         p_serial_att_tbl    => l_serial_attributes_tbl,
26330                         p_validate_only     => FALSE
26331                         );
26332 
26333                      IF (l_validation_status <> 'Y'
26334                          OR x_return_status <> g_ret_sts_success) THEN
26335                         --raise error
26336                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26337                         fnd_msg_pub.ADD;
26338                         l_progress := 'WMSINB-26152';
26339                         RAISE fnd_api.g_exc_error;
26340                      END IF;
26341                   END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
26342 
26343                   --UPDATE GROUP_MARK_ID TO -7937
26344                   IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
26345                      --raise error
26346                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26347                      fnd_msg_pub.ADD;
26348                      l_progress := 'WMSINB-26155';
26349                      RAISE fnd_api.g_exc_error;
26350                   END IF;
26351                 ELSE --IF (l_serial_exists = 1) THEN
26352                   IF l_serial_number_control_code = 5 THEN
26353                      --PERFORM SERIAL VALIDATION FOR NEW SERIAL
26354                      --(INCLUDING ATT VALIDATION)
26355                      --CREATE MSN
26356                     IF (l_transaction_type = 'CORRECT') THEN
26357                       l_transaction_action_id := 29;
26358                     ELSE
26359                       l_transaction_action_id := 1;
26360                     END IF;
26361 
26362                     inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
26363                                , p_inventory_item_id => l_item_id
26364                                , p_organization_id => l_org_id
26365                                , p_from_serial_number => l_serial_number
26366                                , p_to_serial_number => l_serial_number
26367                                , p_initialization_date => SYSDATE
26368                                , p_completion_date => NULL
26369                                , p_ship_date => NULL
26370                                , p_revision => l_item_revision
26371                                , p_lot_number => NULL
26372                                , p_current_locator_id => l_loc_id
26373                                , p_subinventory_code => l_sub_code
26374                                , p_trx_src_id => NULL
26375                                , p_unit_vendor_id => NULL
26376                                , p_vendor_lot_number => NULL
26377                                , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
26378                                , p_receipt_issue_type => NULL
26379                                , p_txn_src_id => NULL
26380                                , p_txn_src_name => NULL
26381                                , p_txn_src_type_id => NULL
26382                                , p_transaction_id => NULL
26383                                , p_current_status => 1
26384                                , p_parent_item_id => NULL
26385                                , p_parent_serial_number => NULL
26386                                , p_cost_group_id => NULL
26387                                , p_transaction_action_id => l_transaction_action_id
26388                                , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
26389                                , p_status_id => NULL
26390                                , p_inspection_status => NULL
26391                                , x_object_id => l_object_id
26392                                , x_return_status => x_return_status
26393                                , x_msg_count => x_msg_count
26394                                , x_msg_data => x_msg_data);
26395 
26396                     IF (x_return_status <> g_ret_sts_success) THEN
26397                       --raise error
26398                       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26399                       fnd_msg_pub.ADD;
26400                       l_progress := 'WMSINB-26160';
26401                       RAISE fnd_api.g_exc_error;
26402                     END IF;
26403 
26404                     --validate and update the attributes.
26405                     inv_serial_number_pub.validate_update_serial_att
26406                          (x_return_status     => x_return_status,
26407                           x_msg_count         => x_msg_count,
26408                           x_msg_data          => x_msg_data,
26409                           x_validation_status => l_validation_status,
26410                           p_serial_number     => l_serial_number,
26411                           p_organization_id   => l_org_id,
26412                           p_inventory_item_id => l_item_id,
26413                           p_serial_att_tbl    => l_serial_attributes_tbl,
26414                           p_validate_only     => FALSE
26415                           );
26416 
26417                     IF (l_validation_status <> 'Y' OR x_return_status <> g_ret_sts_success) THEN
26418                       --raise error
26419                       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26420                       fnd_msg_pub.ADD;
26421                       l_progress := 'WMSINB-26200';
26422                       RAISE fnd_api.g_exc_error;
26423                     END IF;
26424 
26425                     --UPDATE GROUP_MARK_ID TO -7937
26426                     IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
26427                       --raise error
26428                       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26429                       fnd_msg_pub.ADD;
26430                       l_progress := 'WMSINB-26208';
26431                       RAISE fnd_api.g_exc_error;
26432                     END IF;
26433                   ELSE --IF l_serial_number_control_code = 5 THEN
26434                     --raise error
26435                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26436                      fnd_msg_pub.ADD;
26437                      l_progress := 'WMSINB-26215';
26438                      RAISE fnd_api.g_exc_error;
26439                   END IF; --IF l_serial_number_control_code = 5 THEN
26440                 END IF; --IF (l_serial_exists = 1) THEN
26441               END IF; --IF (serial_entered_on_parent(l_great_grand_parent_txn_id)) THEN
26442             ELSE --ELSIF (l_parent_txn_type = g_rtr) THEN
26443               IF (l_parent_txn_type <> 'DELIVER') THEN
26444                 IF NOT (serial_entered_on_parent(l_parent_transaction_id)) THEN
26445                   --raise an error
26446                   l_progress := 'WMSINB-26224';
26447                   RAISE fnd_api.g_exc_error;
26448                 ELSE
26449                   BEGIN
26450                      SELECT '1'
26451                        INTO L_DUMMY
26452                        FROM RCV_SERIALS_SUPPLY
26453                        WHERE TRANSACTION_ID = l_parent_transaction_id
26454                        AND SERIAL_NUM = L_SERIAL_NUMBER;
26455 
26456                      IF (l_curr_status <> 7) THEN
26457                         --raise error
26458                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26459                         fnd_msg_pub.ADD;
26460                         l_progress := 'WMSINB-26238';
26461                         RAISE fnd_api.g_exc_error;
26462                      END IF;
26463 
26464                      --Validate serial/group_mark_id to prevent
26465                      --entering of duplicate serials
26466 
26467                      IF (Nvl(l_group_mark_id, -99) = -7937) THEN
26468                         --raise error
26469                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26470                         fnd_msg_pub.ADD;
26471                         l_progress := 'WMSINB-26249';
26472                         RAISE fnd_api.g_exc_error;
26473                      END IF;
26474 
26475                      --UPDATE GROUP_MARK_ID TO -7937
26476                      IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
26477                         --raise error
26478                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26479                         fnd_msg_pub.ADD;
26480                         l_progress := 'WMSINB-26258';
26481                         RAISE fnd_api.g_exc_error;
26482                      END IF;
26483                   EXCEPTION
26484                      WHEN NO_DATA_FOUND THEN
26485                         -- RAISE ERROR
26486                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26487                         fnd_msg_pub.ADD;
26488                         l_progress := 'WMSINB-26266';
26489                         RAISE fnd_api.g_exc_error;
26490                   END;
26491                 END IF;  --IF NOT (serial_entered_on_parent(l_parent_transaction_id)) THEN
26492               ELSE --IF (l_parent_txn_type <> 'DELIVER') THEN
26493                 IF l_curr_org_id <> l_org_id THEN
26494                   --raise error
26495                   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26496                   fnd_msg_pub.ADD;
26497                   l_progress := 'WMSINB-26275';
26498                   RAISE fnd_api.g_exc_error;
26499                 ELSE
26500                   IF (l_curr_lot_num IS NOT NULL) THEN
26501                      --raise error
26502                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26503                      fnd_msg_pub.ADD;
26504                      l_progress := 'WMSINB-26282';
26505                      RAISE fnd_api.g_exc_error;
26506                   END IF;
26507                 END IF;
26508 
26509                 IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
26510                   IF l_curr_status NOT IN (1,6) THEN
26511                      --raise error
26512                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26513                      fnd_msg_pub.ADD;
26514                      l_progress := 'WMSINB-26292';
26515                      RAISE fnd_api.g_exc_error;
26516                   END IF;
26517                 --Serial tagging: modified condition to validate current_status 3 for serial controlled items
26518                 ELSIF l_serial_number_control_code in (2,5) THEN
26519                   --IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
26520                   IF (l_curr_status <> 3) THEN
26521                      --raise error
26522                      fnd_message.set_name('INV','INV_FAIL_VALIDATE_SERIAL');
26523                      fnd_msg_pub.ADD;
26524                      l_progress := 'WMSINB-26300';
26525                      RAISE fnd_api.g_exc_error;
26526                   END IF;
26527                 END IF; --IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
26528 
26529                 IF (Nvl(l_group_mark_id, -99) = -7937) THEN
26530                   --raise error
26531                   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26532                   fnd_msg_pub.ADD;
26533                   l_progress := 'WMSINB-26309';
26534                   RAISE fnd_api.g_exc_error;
26535                 END IF;
26536 
26537                 IF (Nvl(l_curr_status, 1) in (1,6)) THEN
26538                    --validate and update the attributes.
26539                    inv_serial_number_pub.validate_update_serial_att
26540                      (x_return_status     => x_return_status,
26541                       x_msg_count         => x_msg_count,
26542                       x_msg_data          => x_msg_data,
26543                       x_validation_status => l_validation_status,
26544                       p_serial_number     => l_serial_number,
26545                       p_organization_id   => l_org_id,
26546                       p_inventory_item_id => l_item_id,
26547                       p_serial_att_tbl    => l_serial_attributes_tbl,
26548                       p_validate_only     => FALSE
26549                       );
26550 
26551                    IF (l_validation_status <> 'Y' OR x_return_status <> g_ret_sts_success) THEN
26552                       --raise error
26553                       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26554                       fnd_msg_pub.ADD;
26555                       l_progress := 'WMSINB-26315';
26556                       RAISE fnd_api.g_exc_error;
26557                    END IF;
26558                 END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
26559 
26560                 --UPDATE GROUP_MARK_ID TO -7937
26561                 IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
26562                   --raise error
26563                   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26564                   fnd_msg_pub.ADD;
26565                   l_progress := 'WMSINB-26318';
26566                   RAISE fnd_api.g_exc_error;
26567                 END IF;
26568               END IF; --IF (l_parent_txn_type <> 'DELIVER') THEN
26569             END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc)) THEN
26570           END LOOP; -- FOR 1..L_SERIAL_QUANTITY
26571         END LOOP; --FETCH C_MSNT INTO L_MSNT_REC;
26572 
26573         CLOSE c_msnt;
26574 
26575         IF (l_num_msnt_recs > 0) THEN
26576           IF Abs(l_rti_primary_qty) <> l_tot_msnt_serial_qty THEN
26577             --raise error
26578              fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
26579              fnd_msg_pub.ADD;
26580              l_progress := 'WMSINB-26333';
26581              RAISE fnd_api.g_exc_error;
26582           END IF;
26583         ELSE
26584           IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
26585             IF (l_grand_parent_txn_type = 'DELIVER') THEN
26586               --raise an error
26587               l_progress := 'WMSINB-26340';
26588               RAISE fnd_api.g_exc_error;
26589             ELSE --IF (l_grand_parent_txn_type = 'DELIVER') THEN
26590               IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
26591                  --raise on error
26592                  l_progress := 'WMSINB-26345';
26593                  RAISE fnd_api.g_exc_error;
26594               END IF;
26595             END IF; --IF (l_grand_parent_txn_type = 'DELIVER') THEN
26596           ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
26597             IF (l_parent_txn_type = 'DELIVER') THEN
26598               IF (l_serial_number_control_code IN (2,5)
26599                 OR (l_serial_number_control_code = 6
26600                 AND l_source_document_code = 'RMA')) THEN
26601                    --raise an error
26602                    l_progress := 'WMSINB-26352';
26603                    RAISE fnd_api.g_exc_error;
26604               END IF;
26605             ELSE
26606               IF (serial_entered_on_parent(l_parent_transaction_id)) THEN
26607                  --raise an error
26608                  l_progress := 'WMSINB-26357';
26609                  RAISE fnd_api.g_exc_error;
26610               END IF;
26611             END IF; --IF (l_parent_txn_type = 'DELIVER') THEN
26612           END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
26613         END IF; --IF (l_num_msnt_recs > 0) THEN
26614       END IF; --IF (l_lot_control_code = 2) THEN
26615     ELSIF (l_transaction_type = 'CORRECT' AND l_rti_primary_qty > 0) THEN
26616 	                              -- opm change bug# 3061052 added l_opm_lot_ctl check
26617            /*INVCONV , Remove OPM specific l_opm_lot_ctl check , Punit Kumar*/
26618       IF (l_lot_control_code = 2 /* or l_opm_lot_ctl=1 */) THEN
26619         IF (l_debug = 1) THEN
26620           print_debug('VALIDATE_LOT_SERIAL_INFO: Lot Controlled :'||l_progress, 1);
26621           l_progress := 'WMSINB-26368';
26622         END IF;
26623 
26624         l_num_mtlt_recs := 0;
26625         l_tot_mtlt_prim_qty := 0;
26626         l_tot_mtlt_trans_qty := 0; -- Bug# 4225766
26627 
26628         OPEN C_MTLT(L_RTI_ID);
26629         LOOP
26630           FETCH C_MTLT INTO L_MTLT_REC;
26631           EXIT WHEN C_MTLT%NOTFOUND;
26632            /* INVCONV , get L_MTLT_REC values into l_mln_rec which shall be passed to INV_NEW_LOT for lot creation */
26633           IF (l_debug = 1) THEN
26634               print_debug('INVCONV,Assigning values fetched from MTLT to l_mln_rec'||l_progress,1);
26635           END IF;
26636 
26637           l_mln_rec.LOT_NUMBER                := L_MTLT_REC.LOT_NUMBER                    ;
26638           l_mln_rec.LAST_UPDATE_DATE          := SYSDATE                                  ;
26639           l_mln_rec.LAST_UPDATED_BY           := L_MTLT_REC.LAST_UPDATED_BY               ;
26640           l_mln_rec.CREATION_DATE             := SYSDATE                                  ;
26641           l_mln_rec.CREATED_BY                := L_MTLT_REC.CREATED_BY                    ;
26642           l_mln_rec.LAST_UPDATE_LOGIN         := L_MTLT_REC.LAST_UPDATE_LOGIN             ;
26643           l_mln_rec.EXPIRATION_DATE           := L_MTLT_REC.LOT_EXPIRATION_DATE               ;
26644           l_mln_rec.ATTRIBUTE_CATEGORY        := L_MTLT_REC.ATTRIBUTE_CATEGORY            ;
26645           l_mln_rec.ATTRIBUTE1                := L_MTLT_REC.ATTRIBUTE1                    ;
26646           l_mln_rec.ATTRIBUTE2                := L_MTLT_REC.ATTRIBUTE2                    ;
26647           l_mln_rec.ATTRIBUTE3                := L_MTLT_REC.ATTRIBUTE3                    ;
26648           l_mln_rec.ATTRIBUTE4                := L_MTLT_REC.ATTRIBUTE4                    ;
26649           l_mln_rec.ATTRIBUTE5                := L_MTLT_REC.ATTRIBUTE5                    ;
26650           l_mln_rec.ATTRIBUTE6                := L_MTLT_REC.ATTRIBUTE6                    ;
26651           l_mln_rec.ATTRIBUTE7                := L_MTLT_REC.ATTRIBUTE7                    ;
26652           l_mln_rec.ATTRIBUTE8                := L_MTLT_REC.ATTRIBUTE8                    ;
26653           l_mln_rec.ATTRIBUTE9                := L_MTLT_REC.ATTRIBUTE9                    ;
26654           l_mln_rec.ATTRIBUTE10               := L_MTLT_REC.ATTRIBUTE10                   ;
26655           l_mln_rec.ATTRIBUTE11               := L_MTLT_REC.ATTRIBUTE11                   ;
26656           l_mln_rec.ATTRIBUTE12               := L_MTLT_REC.ATTRIBUTE12                   ;
26657           l_mln_rec.ATTRIBUTE13               := L_MTLT_REC.ATTRIBUTE13                   ;
26658           l_mln_rec.ATTRIBUTE14               := L_MTLT_REC.ATTRIBUTE14                   ;
26659           l_mln_rec.ATTRIBUTE15               := L_MTLT_REC.ATTRIBUTE15                   ;
26660           l_mln_rec.REQUEST_ID                := L_MTLT_REC.REQUEST_ID                    ;
26661           l_mln_rec.PROGRAM_APPLICATION_ID    := L_MTLT_REC.PROGRAM_APPLICATION_ID        ;
26662           l_mln_rec.PROGRAM_ID                := L_MTLT_REC.PROGRAM_ID                    ;
26663           l_mln_rec.PROGRAM_UPDATE_DATE       := L_MTLT_REC.PROGRAM_UPDATE_DATE           ;
26664           l_mln_rec.DESCRIPTION               := L_MTLT_REC.DESCRIPTION                   ;
26665           l_mln_rec.VENDOR_NAME               := L_MTLT_REC.VENDOR_NAME                   ;
26666           l_mln_rec.SUPPLIER_LOT_NUMBER       := L_MTLT_REC.SUPPLIER_LOT_NUMBER           ;
26667           l_mln_rec.GRADE_CODE                := L_MTLT_REC.GRADE_CODE                    ;
26668           l_mln_rec.ORIGINATION_DATE          := L_MTLT_REC.ORIGINATION_DATE              ;
26669           l_mln_rec.DATE_CODE                 := L_MTLT_REC.DATE_CODE                     ;
26670           l_mln_rec.STATUS_ID                 := L_MTLT_REC.STATUS_ID                     ;
26671           l_mln_rec.CHANGE_DATE               := L_MTLT_REC.CHANGE_DATE                   ;
26672           l_mln_rec.AGE                       := L_MTLT_REC.AGE                           ;
26673           l_mln_rec.RETEST_DATE               := L_MTLT_REC.RETEST_DATE                   ;
26674           l_mln_rec.MATURITY_DATE             := L_MTLT_REC.MATURITY_DATE                 ;
26675           l_mln_rec.LOT_ATTRIBUTE_CATEGORY    := L_MTLT_REC.LOT_ATTRIBUTE_CATEGORY        ;
26676           l_mln_rec.ITEM_SIZE                 := L_MTLT_REC.ITEM_SIZE                     ;
26677           l_mln_rec.COLOR                     := L_MTLT_REC.COLOR                         ;
26678           l_mln_rec.VOLUME                    := L_MTLT_REC.VOLUME                        ;
26679           l_mln_rec.VOLUME_UOM                := L_MTLT_REC.VOLUME_UOM                    ;
26680           l_mln_rec.PLACE_OF_ORIGIN           := L_MTLT_REC.PLACE_OF_ORIGIN               ;
26681           l_mln_rec.BEST_BY_DATE              := L_MTLT_REC.BEST_BY_DATE                  ;
26682           l_mln_rec.LENGTH                    := L_MTLT_REC.LENGTH                        ;
26683           l_mln_rec.LENGTH_UOM                := L_MTLT_REC.LENGTH_UOM                    ;
26684           l_mln_rec.RECYCLED_CONTENT          := L_MTLT_REC.RECYCLED_CONTENT              ;
26685           l_mln_rec.THICKNESS                 := L_MTLT_REC.THICKNESS                     ;
26686           l_mln_rec.THICKNESS_UOM             := L_MTLT_REC.THICKNESS_UOM                 ;
26687           l_mln_rec.WIDTH                     := L_MTLT_REC.WIDTH                         ;
26688           l_mln_rec.WIDTH_UOM                 := L_MTLT_REC.WIDTH_UOM                     ;
26689           l_mln_rec.CURL_WRINKLE_FOLD         := L_MTLT_REC.CURL_WRINKLE_FOLD             ;
26690           l_mln_rec.C_ATTRIBUTE1              := L_MTLT_REC.C_ATTRIBUTE1                  ;
26691           l_mln_rec.C_ATTRIBUTE2              := L_MTLT_REC.C_ATTRIBUTE2                  ;
26692           l_mln_rec.C_ATTRIBUTE3              := L_MTLT_REC.C_ATTRIBUTE3                  ;
26693           l_mln_rec.C_ATTRIBUTE4              := L_MTLT_REC.C_ATTRIBUTE4                  ;
26694           l_mln_rec.C_ATTRIBUTE5              := L_MTLT_REC.C_ATTRIBUTE5                  ;
26695           l_mln_rec.C_ATTRIBUTE6              := L_MTLT_REC.C_ATTRIBUTE6                  ;
26696           l_mln_rec.C_ATTRIBUTE7              := L_MTLT_REC.C_ATTRIBUTE7                  ;
26697           l_mln_rec.C_ATTRIBUTE8              := L_MTLT_REC.C_ATTRIBUTE8                  ;
26698           l_mln_rec.C_ATTRIBUTE9              := L_MTLT_REC.C_ATTRIBUTE9                  ;
26699           l_mln_rec.C_ATTRIBUTE10             := L_MTLT_REC.C_ATTRIBUTE10                 ;
26700           l_mln_rec.C_ATTRIBUTE11             := L_MTLT_REC.C_ATTRIBUTE11                 ;
26701           l_mln_rec.C_ATTRIBUTE12             := L_MTLT_REC.C_ATTRIBUTE12                 ;
26702           l_mln_rec.C_ATTRIBUTE13             := L_MTLT_REC.C_ATTRIBUTE13                 ;
26703           l_mln_rec.C_ATTRIBUTE14             := L_MTLT_REC.C_ATTRIBUTE14                 ;
26704           l_mln_rec.C_ATTRIBUTE15             := L_MTLT_REC.C_ATTRIBUTE15                 ;
26705           l_mln_rec.C_ATTRIBUTE16             := L_MTLT_REC.C_ATTRIBUTE16                 ;
26706           l_mln_rec.C_ATTRIBUTE17             := L_MTLT_REC.C_ATTRIBUTE17                 ;
26707           l_mln_rec.C_ATTRIBUTE18             := L_MTLT_REC.C_ATTRIBUTE18                 ;
26708           l_mln_rec.C_ATTRIBUTE19             := L_MTLT_REC.C_ATTRIBUTE19                 ;
26709           l_mln_rec.C_ATTRIBUTE20             := L_MTLT_REC.C_ATTRIBUTE20                 ;
26710           l_mln_rec.D_ATTRIBUTE1              := L_MTLT_REC.D_ATTRIBUTE1                  ;
26711           l_mln_rec.D_ATTRIBUTE2              := L_MTLT_REC.D_ATTRIBUTE2                  ;
26712           l_mln_rec.D_ATTRIBUTE3              := L_MTLT_REC.D_ATTRIBUTE3                  ;
26713           l_mln_rec.D_ATTRIBUTE4              := L_MTLT_REC.D_ATTRIBUTE4                  ;
26714           l_mln_rec.D_ATTRIBUTE5              := L_MTLT_REC.D_ATTRIBUTE5                  ;
26715           l_mln_rec.D_ATTRIBUTE6              := L_MTLT_REC.D_ATTRIBUTE6                  ;
26716           l_mln_rec.D_ATTRIBUTE7              := L_MTLT_REC.D_ATTRIBUTE7                  ;
26717           l_mln_rec.D_ATTRIBUTE8              := L_MTLT_REC.D_ATTRIBUTE8                  ;
26718           l_mln_rec.D_ATTRIBUTE9              := L_MTLT_REC.D_ATTRIBUTE9                  ;
26719           l_mln_rec.D_ATTRIBUTE10             := L_MTLT_REC.D_ATTRIBUTE10                 ;
26720           l_mln_rec.N_ATTRIBUTE1              := L_MTLT_REC.N_ATTRIBUTE1                  ;
26721           l_mln_rec.N_ATTRIBUTE2              := L_MTLT_REC.N_ATTRIBUTE2                  ;
26722           l_mln_rec.N_ATTRIBUTE3              := L_MTLT_REC.N_ATTRIBUTE3                  ;
26723           l_mln_rec.N_ATTRIBUTE4              := L_MTLT_REC.N_ATTRIBUTE4                  ;
26724           l_mln_rec.N_ATTRIBUTE5              := L_MTLT_REC.N_ATTRIBUTE5                  ;
26725           l_mln_rec.N_ATTRIBUTE6              := L_MTLT_REC.N_ATTRIBUTE6                  ;
26726           l_mln_rec.N_ATTRIBUTE7              := L_MTLT_REC.N_ATTRIBUTE7                  ;
26727           l_mln_rec.N_ATTRIBUTE8              := L_MTLT_REC.N_ATTRIBUTE8                  ;
26728           l_mln_rec.N_ATTRIBUTE9              := L_MTLT_REC.N_ATTRIBUTE9                  ;
26729           l_mln_rec.N_ATTRIBUTE10             := L_MTLT_REC.N_ATTRIBUTE10                 ;
26730           l_mln_rec.VENDOR_ID                 := L_MTLT_REC.VENDOR_ID                     ;
26731           l_mln_rec.TERRITORY_CODE            := L_MTLT_REC.TERRITORY_CODE                ;
26732           l_mln_rec.PARENT_LOT_NUMBER         := L_MTLT_REC.PARENT_LOT_NUMBER             ;
26733           l_mln_rec.ORIGINATION_TYPE          := L_MTLT_REC.ORIGINATION_TYPE              ;
26734           l_mln_rec.EXPIRATION_ACTION_DATE    := L_MTLT_REC.EXPIRATION_ACTION_DATE        ;
26735           l_mln_rec.EXPIRATION_ACTION_CODE    := L_MTLT_REC.EXPIRATION_ACTION_CODE        ;
26736           l_mln_rec.HOLD_DATE                 := L_MTLT_REC.HOLD_DATE                     ;
26737 
26738           L_NUM_MTLT_RECS := L_NUM_MTLT_RECS + 1;
26739           l_tot_mtlt_prim_qty := l_tot_mtlt_prim_qty + l_mtlt_rec.primary_quantity;
26740           l_tot_mtlt_trans_qty := l_tot_mtlt_trans_qty + l_mtlt_rec.transaction_quantity; -- Bug# 4225766
26741 
26742           IF (l_debug = 1) THEN
26743              print_debug('VALIDATE_LOT_SERIAL_INFO: LOT NUMBER: '||l_mtlt_rec.lot_number||': '||l_progress, 1);
26744              print_debug('VALIDATE_LOT_SERIAL_INFO: LOT PRIMARY QUANTITY: '||l_mtlt_rec.primary_quantity||': '||l_progress, 1);
26745              l_progress := 'WMSINB-26386';
26746                   print_debug('INVCONV,Finished Assigning values fetched from MTLT to l_mln_rec'||l_progress,1);
26747           END IF;
26748 
26749           IF (l_parent_txn_type IN (g_rtv,g_rtr,g_rtc)) THEN
26750             IF (l_grand_parent_txn_type <> 'DELIVER') THEN
26751               IF NOT (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
26752                  --raise an error
26753                  l_progress := 'WMSINB-26393';
26754                  RAISE fnd_api.g_exc_error;
26755               END IF; --IF NOT (lot_entered_on_parent(l_grand_parent_txn_id))
26756             END IF; --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
26757           ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtr,g_rtc)) THEN
26758             IF (l_parent_txn_type <> 'DELIVER') THEN
26759               IF (validate_rs(NULL,l_parent_transaction_id,l_dummy_lpn)) THEN
26760                 IF NOT (lot_entered_on_parent(l_parent_transaction_id)) THEN
26761                   --raise an error
26762                   l_progress := 'WMSINB-26402';
26763                   RAISE fnd_api.g_exc_error;
26764                 END IF;
26765               END IF;
26766             END IF; --IF (l_parent_txn_type <> 'DELIVER') THEN
26767           END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtr,g_rtc)) THEN
26768 
26769           BEGIN
26770              /*INVCONV , Remove OPM specific ic_lots_mst logic , Punit Kumar */
26771             ----- IF (l_discrete_transaction) THEN
26772 
26773             SELECT 1,parent_lot_number
26774              INTO L_LOT_EXISTS ,l_parent_lot_number
26775              FROM MTL_LOT_NUMBERS
26776              WHERE ORGANIZATION_ID = L_ORG_ID
26777              AND   INVENTORY_ITEM_ID = L_ITEM_ID
26778              AND LOT_NUMBER = Ltrim(Rtrim(L_MTLT_REC.lot_number));
26779 
26780             /*
26781             ELSE -- opm change bug# 3061052 --IF (l_discrete_transaction) THEN
26782               IF  Ltrim(Rtrim(L_MTLT_REC.sublot_num)) IS NOT NULL THEN
26783                  SELECT 1, LOT_ID
26784                    INTO L_LOT_EXISTS , L_OPM_LOT_ID
26785                    FROM IC_LOTS_MST
26786                    WHERE ITEM_ID = l_opm_item_id
26787                    AND LOT_NO = Ltrim(Rtrim(L_MTLT_REC.lot_number))
26788                    AND SUBLOT_NO = Ltrim(Rtrim(L_MTLT_REC.sublot_num)) ;
26789                ELSE
26790                  SELECT 1 , lot_id
26791                    INTO L_LOT_EXISTS , L_OPM_LOT_ID
26792                    FROM IC_LOTS_MST
26793                    WHERE ITEM_ID = l_opm_item_id
26794                    AND LOT_NO = Ltrim(Rtrim(L_MTLT_REC.lot_number))
26795                    AND SUBLOT_NO IS NULL ;
26796               END IF;
26797              END IF; --IF (l_discrete_transaction) THEN */
26798 
26799             IF (l_debug = 1) THEN
26800                print_debug('INVCONV, Removing OPM specific fork :'||l_progress,1);
26801             END IF;
26802           EXCEPTION
26803              WHEN NO_DATA_FOUND THEN
26804                L_LOT_EXISTS := 0;
26805           END;
26806 
26807           IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
26808             IF (l_grand_parent_txn_type <> 'DELIVER') THEN
26809               BEGIN
26810                 -- opm change bug# 3061052. added SUBLOT_NO
26811                 /* INVCONV, Remove sublot Num , Punit Kumar */
26812 
26813                  SELECT primary_quantity
26814                    INTO l_rls_primary_quantity
26815                    FROM rcv_lots_supply
26816                   WHERE transaction_id = l_grand_parent_txn_id
26817                     AND lot_num = Ltrim(Rtrim(l_mtlt_rec.lot_number)) ;
26818 
26819                    /* AND ((sublot_num IS NULL and Ltrim(Rtrim(l_mtlt_rec.sublot_num)) IS NULL)
26820                       OR (sublot_num = Ltrim(Rtrim(l_mtlt_rec.sublot_num)))) ;*/
26821 
26822                   IF (l_mtlt_rec.primary_quantity > l_rls_primary_quantity) THEN
26823                     --raise error
26824                     l_progress := 'WMSINB-26454';
26825                     RAISE fnd_api.g_exc_error;
26826                   END IF;
26827               EXCEPTION
26828                 WHEN no_data_found THEN
26829                 --raise error
26830                   l_progress := 'WMSINB-26460';
26831                   RAISE fnd_api.g_exc_error;
26832               END;
26833 
26834               -- opm change bug# 3061052
26835               /*IF (NOT l_discrete_transaction) THEN
26836                gml_opm_roi_grp.validate_opm_lot(p_api_version	=> 1.0,
26837                         p_init_msg_lst	 	=> FND_API.G_FALSE,
26838                         p_mtlt_rowid		=> l_mtlt_rec.rowid,
26839                         p_new_lot	 	=> 'N',
26840                         p_opm_item_id		=> l_opm_item_id,
26841                         p_item_no		=> l_item_no,
26842                         p_lots_specified_on_parent => 'Y',
26843                         p_lot_id		=> l_opm_lot_id,
26844                         p_parent_txn_type	=> l_parent_txn_type,
26845                         p_grand_parent_txn_type => l_grand_parent_txn_type,
26846                         x_return_status 	=> x_return_status,
26847                         x_msg_data      	=> x_msg_data,
26848                         x_msg_count     	=> x_msg_count
26849                         );*/
26850 
26851               IF (l_debug = 1) THEN
26852                 print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
26853               END IF;
26854 
26855               INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
26856                                                        x_return_status      		   => x_return_status
26857                                                       ,x_msg_data           		   => x_msg_data
26858                                                       ,x_msg_count          		   => x_msg_count
26859                                                       ,p_api_version	               => 1.0
26860                                                       ,p_init_msg_lst	            => FND_API.G_FALSE
26861                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
26862                                                       ,p_transaction_type_id 	      => l_transaction_type_id
26863                                                       ,p_new_lot			            => 'N'
26864                                                       ,p_item_id	 		            => l_item_id
26865                                                       ,p_to_organization_id		   => L_ORG_ID
26866                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
26867                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
26868                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
26869                                                       ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
26870                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
26871                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
26872                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
26873                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
26874                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
26875                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
26876                                                       ,p_rti_id	                  => L_RTI_ID
26877                                                       ,p_revision             	   => l_item_revision
26878                                                       ,p_subinventory_code  	      => L_SUB_CODE
26879                                                       ,p_locator_id           	   => l_loc_id
26880                                                       ,p_transaction_type           => l_transaction_type
26881                                                       ,p_parent_txn_type            => l_parent_txn_type
26882                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
26883                                                       );
26884 
26885               /*INVCONV ,*/
26886               IF (l_debug = 1) THEN
26887                 print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
26888                 print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
26889               END IF;
26890 
26891               IF X_RETURN_STATUS <> 'S' THEN
26892                 --RAISE ERROR
26893                 l_progress := 'WMSINB-26483';
26894                 RAISE fnd_api.g_exc_error;
26895               END IF;
26896 
26897               IF (l_debug = 1) THEN
26898                 print_debug('VALIDATE_LOT_SERIAL_INFO: VALIDATE_OPM_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
26899               END IF;
26900               /* END IF; --IF (NOT l_discrete_transaction) THEN*/
26901             ELSE --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
26902               IF (l_lot_exists = 1) THEN
26903                 /*INVCONV , validating for parent lot, Punit Kumar */
26904                 IF  L_MTLT_REC.parent_lot_number IS NOT NULL THEN
26905                   IF L_MTLT_REC.parent_lot_number <> l_parent_lot_number THEN
26906                     fnd_message.set_name ('INV' , 'INV_CL_PARENT_INVALID' );
26907                     fnd_msg_pub.ADD;
26908                     RAISE fnd_api.g_exc_error;
26909                   END IF;
26910                 ELSE
26911                   L_MTLT_REC.parent_lot_number := l_parent_lot_number;
26912                 END IF;
26913                 /*end , INVCONV */
26914 
26915                 -- opm change bug# 3061052
26916                 -- this combination not possible
26917                 /*INVCONV , existing discrete validations. Same will be executed for process org*/
26918                 --------IF (l_discrete_transaction) THEN
26919 
26920                 --PERFORM MATERIAL STATUS CHECK FOR LOT
26921                 IF (l_source_document_code = 'PO') THEN
26922                   l_transaction_type_id := 71;
26923                 ELSE
26924                   l_transaction_type_id := 72;
26925                 END IF;
26926 
26927                 INV_LOT_TRX_VALIDATION_PUB.VALIDATE_MATERIAL_STATUS(X_RETURN_STATUS => X_RETURN_STATUS,
26928                                 X_MSG_COUNT => X_MSG_COUNT,
26929                                 X_MSG_DATA => X_MSG_DATA,
26930                                 X_VALIDATION_STATUS => L_VALIDATION_STATUS,
26931                                 P_TRANSACTION_TYPE_ID => l_transaction_type_id,
26932                                 P_ORGANIZATION_ID => L_ORG_ID,
26933                                 P_INVENTORY_ITEM_ID => L_ITEM_ID,
26934                                 P_LOT_NUMBER => L_MTLT_REC.LOT_NUMBER,
26935                                 P_SUBINVENTORY_CODE => L_SUB_CODE,
26936                                 P_LOCATOR_ID => L_LOC_ID,
26937                                 P_STATUS_ID => NULL);
26938                 IF X_RETURN_STATUS <> 'S' THEN
26939                   --RAISE an ERROR
26940                   l_progress := 'WMSINB-26517';
26941                   RAISE fnd_api.g_exc_error;
26942                 END IF;
26943 
26944                 IF (l_debug = 1) THEN
26945                   print_debug('VALIDATE_LOT_SERIAL_INFO: LOT MATERIAL VALIDATION STATUS: '||L_VALIDATION_STATUS||' : '||l_progress, 1);
26946                   l_progress := 'WMSINB-26523';
26947                 END IF;
26948 
26949                 IF L_VALIDATION_STATUS <> 'Y' THEN
26950                    --RAISE an ERROR
26951                    l_progress := 'WMSINB-26528';
26952                    RAISE fnd_api.g_exc_error;
26953                 END IF;
26954 
26955                 /*ELSE --IF (l_discrete_transaction) THEN
26956                         gml_opm_roi_grp.validate_opm_lot(p_api_version	=> 1.0,
26957                            p_init_msg_lst	 	=> FND_API.G_FALSE,
26958                            p_mtlt_rowid		=> l_mtlt_rec.rowid,
26959                            p_new_lot	 	=> 'N',
26960                            p_opm_item_id		=> l_opm_item_id,
26961                            p_item_no		=> l_item_no,
26962                            p_lots_specified_on_parent => 'Y',
26963                            p_lot_id		=> l_opm_lot_id,
26964                            p_parent_txn_type	=> l_parent_txn_type,
26965                            p_grand_parent_txn_type => l_grand_parent_txn_type,
26966                            x_return_status 	=> x_return_status,
26967                            x_msg_data      	=> x_msg_data,
26968                            x_msg_count     	=> x_msg_count
26969                            );*/
26970                 IF (l_debug = 1) THEN
26971                   print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
26972                 END IF;
26973 
26974                 INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
26975                                                        x_return_status      		   => x_return_status
26976                                                       ,x_msg_data           		   => x_msg_data
26977                                                       ,x_msg_count          		   => x_msg_count
26978                                                       ,p_api_version	               => 1.0
26979                                                       ,p_init_msg_lst	            => FND_API.G_FALSE
26980                                                       ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
26981                                                       ,p_transaction_type_id 	      => l_transaction_type_id
26982                                                       ,p_new_lot			            => 'N'
26983                                                       ,p_item_id	 		            => l_item_id
26984                                                       ,p_to_organization_id		   => L_ORG_ID
26985                                                       ,p_lot_number			         => L_MTLT_REC.lot_number
26986                                                       ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
26987                                                       ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
26988                                                       ,x_lot_secondary_quantity     => L_MTLT_REC.SECONDARY_QUANTITY
26989                                                       ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
26990                                                       ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
26991                                                       ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
26992                                                       ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
26993                                                       ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
26994                                                       ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
26995                                                       ,p_rti_id	                  => L_RTI_ID
26996                                                       ,p_revision             	   => l_item_revision
26997                                                       ,p_subinventory_code  	      => L_SUB_CODE
26998                                                       ,p_locator_id           	   => l_loc_id
26999                                                       ,p_transaction_type           => l_transaction_type
27000                                                       ,p_parent_txn_type            => l_parent_txn_type
27001                                                       ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
27002                                                       );
27003 
27004                 /*INVCONV ,*/
27005                 IF (l_debug = 1) THEN
27006                    print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
27007                    print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
27008                 END IF;
27009 
27010                 IF X_RETURN_STATUS <> 'S' THEN
27011                   --RAISE ERROR
27012                   l_progress := 'WMSINB-26549';
27013                   RAISE fnd_api.g_exc_error;
27014                 END IF;
27015 
27016                 IF (l_debug = 1) THEN
27017                   print_debug('VALIDATE_LOT_SERIAL_INFO: INV_VALIDATE_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
27018                 END IF;
27019                 /*END IF; -- IF (l_discrete_transaction) THEN	*/
27020               ELSE --IF (l_lot_exists = 1) THEN
27021                 --raise an error
27022                 l_progress := 'WMSINB-26560';
27023                 RAISE fnd_api.g_exc_error;
27024               END IF; --IF (l_lot_exists = 1) THEN
27025             END IF; --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
27026           ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
27027             IF (l_parent_txn_type <> 'RECEIVE') THEN
27028               IF (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
27029                 BEGIN
27030                   -- opm change bug# 3061052 added SUBLOT_NO
27031                     /*INVCONV , Remove Sublot Num , Punit Kumar*/
27032 
27033                    SELECT primary_quantity
27034                      INTO l_rls_primary_quantity
27035                      FROM rcv_lots_supply
27036                      WHERE transaction_id = l_grand_parent_txn_id
27037                      AND lot_num = Ltrim(Rtrim(l_mtlt_rec.lot_number));
27038                          /*
27039                      AND ((sublot_num IS NULL and Ltrim(Rtrim(l_mtlt_rec.sublot_num)) IS NULL)
27040                     OR (sublot_num = Ltrim(Rtrim(l_mtlt_rec.sublot_num)))) ;
27041                   */
27042 
27043                   IF (l_mtlt_rec.primary_quantity > l_rls_primary_quantity) THEN
27044                     --raise error
27045                     l_progress := 'WMSINB-26579';
27046                     RAISE fnd_api.g_exc_error;
27047                   END IF;
27048                 EXCEPTION
27049                   WHEN no_data_found THEN
27050                     --raise error
27051                     l_progress := 'WMSINB-26585';
27052                     RAISE fnd_api.g_exc_error;
27053                 END;
27054               END IF; --IF (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
27055             ELSE --IF (l_parent_txn_type <> 'RECEIVE') THEN
27056               /* INVCONV , remove OPM specific fork , Punit Kumar*/
27057                 ----IF (l_discrete_transaction) THEN
27058 
27059               IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY', 'REQ')) THEN
27060                 -- GET THE LOT/SERIAL CONTROL IN SOURCE ORG
27061                 GET_SERIAL_LOT_CTRL_IN_SRC_ORG
27062                   (L_SHIPMENT_LINE_ID, L_ORG_ID,
27063                    L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
27064                    l_from_org_rev_ctrl, X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
27065 
27066                 IF (l_debug = 1) THEN
27067                   print_debug('VALIDATE_LOT_SERIAL_INFO: LOT CONTROL FROM ORG: '||L_FROM_ORG_LOT_CTRL||' : '||l_progress, 1);
27068                   l_progress := 'WMSINB-26600';
27069                 END IF;
27070 
27071                 IF (L_FROM_ORG_LOT_CTRL = 2) THEN
27072                   BEGIN
27073                     SELECT nvl(SUM(rls.primary_quantity),0) --Bug:5489462
27074                     INTO L_RLS_PRIMARY_QUANTITY
27075                     FROM rcv_lots_supply rls
27076                     , rcv_shipment_lines rsl
27077                     WHERE rsl.SHIPMENT_LINE_ID = rls.SHIPMENT_LINE_ID
27078                     AND rsl.shipment_header_id = l_shipment_header_id
27079                     AND rsl.item_id = l_item_id
27080                     AND rls.SUPPLY_TYPE_CODE = 'SHIPMENT'
27081                     AND rls.LOT_NUM = Ltrim(Rtrim(L_MTLT_REC.lot_number));
27082 
27083                     IF ((abs(l_mtlt_rec.primary_quantity - l_rls_primary_quantity) > 0.00005 )
27084 				AND  (l_mtlt_rec.primary_quantity > l_rls_primary_quantity)) THEN  --Bug: 14092221
27085                        --RAISE ERROR
27086                        l_progress := 'WMSINB-26617';
27087                        RAISE fnd_api.g_exc_error;
27088                     END IF;
27089                   EXCEPTION
27090                     WHEN NO_DATA_FOUND THEN
27091                        --RAISE ERROR
27092                        l_progress := 'WMSINB-26623';
27093                        RAISE fnd_api.g_exc_error;
27094                   END;
27095                 END IF; --IF (L_FROM_ORG_LOT_CTRL = 2) THEN
27096               END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY', 'REQ')) THEN
27097               /* END IF; --  IF (l_discrete_transaction) THEN*/
27098             END IF; --IF (l_parent_txn_type <> 'RECEIVE') THEN
27099 
27100             IF (l_lot_exists = 1) THEN
27101                /*INVCONV, Remove descrete specific call*/
27102                -- opm change bug# 3061052
27103                /*IF (l_discrete_transaction) THEN */
27104               --PERFORM MATERIAL STATUS CHECK FOR LOT
27105               IF (l_source_document_code = 'PO') THEN
27106                 l_transaction_type_id := 71;
27107               ELSE
27108                 l_transaction_type_id := 72;
27109               END IF;
27110 
27111               INV_LOT_TRX_VALIDATION_PUB.validate_material_status
27112                   (X_RETURN_STATUS => X_RETURN_STATUS,
27113                    X_MSG_COUNT => X_MSG_COUNT,
27114                    X_MSG_DATA => X_MSG_DATA,
27115                    X_VALIDATION_STATUS => L_VALIDATION_STATUS,
27116                    P_TRANSACTION_TYPE_ID => l_transaction_type_id,
27117                    P_ORGANIZATION_ID => L_ORG_ID,
27118                    P_INVENTORY_ITEM_ID => L_ITEM_ID,
27119                    P_LOT_NUMBER => L_MTLT_REC.LOT_NUMBER,
27120                    P_SUBINVENTORY_CODE => L_SUB_CODE,
27121                    P_LOCATOR_ID => L_LOC_ID,
27122                    P_STATUS_ID => NULL);
27123               IF X_RETURN_STATUS <> 'S' THEN
27124                  --RAISE an ERROR
27125                  l_progress := 'WMSINB-26656';
27126                  RAISE fnd_api.g_exc_error;
27127               END IF;
27128 
27129               IF (l_debug = 1) THEN
27130                  print_debug('VALIDATE_LOT_SERIAL_INFO: LOT MATERIAL VALIDATION STATUS: '||L_VALIDATION_STATUS||' : '||l_progress, 1);
27131                  l_progress := 'WMSINB-26662';
27132               END IF;
27133 
27134               IF L_VALIDATION_STATUS <> 'Y' THEN
27135                  --RAISE an ERROR
27136                  l_progress := 'WMSINB-26667';
27137                  RAISE fnd_api.g_exc_error;
27138               END IF;
27139 
27140                /*
27141               ELSE --IF (l_discrete_transaction) THEN
27142               -- opm change bug# 3061052
27143 
27144               gml_opm_roi_grp.validate_opm_lot(p_api_version => 1.0,
27145                    p_init_msg_lst	 	=> FND_API.G_FALSE,
27146                    p_mtlt_rowid		=> l_mtlt_rec.rowid,
27147                    p_new_lot	 	=> 'N',
27148                    p_opm_item_id		=> l_opm_item_id,
27149                    p_item_no		=> l_item_no,
27150                    p_lots_specified_on_parent => 'Y',
27151                    p_lot_id		=> l_opm_lot_id,
27152                    p_parent_txn_type	=> l_parent_txn_type,
27153                    p_grand_parent_txn_type => l_grand_parent_txn_type,
27154                    x_return_status 	=> x_return_status,
27155                    x_msg_data      	=> x_msg_data,
27156                    x_msg_count     	=> x_msg_count
27157                    );*/
27158               IF (l_debug = 1) THEN
27159                 print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
27160               END IF;
27161 
27162               INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
27163                                                         x_return_status      		   => x_return_status
27164                                                        ,x_msg_data           		   => x_msg_data
27165                                                        ,x_msg_count          		   => x_msg_count
27166                                                        ,p_api_version	               => 1.0
27167                                                        ,p_init_msg_lst	            => FND_API.G_FALSE
27168                                                        ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
27169                                                        ,p_transaction_type_id 	   => l_transaction_type_id
27170                                                        ,p_new_lot			            => 'N'
27171                                                        ,p_item_id	 		            => l_item_id
27172                                                        ,p_to_organization_id		   => L_ORG_ID
27173                                                        ,p_lot_number			         => L_MTLT_REC.lot_number
27174                                                        ,p_parent_lot_number			=> L_MTLT_REC.parent_lot_number
27175                                                        ,p_lot_quantity			      => L_MTLT_REC.TRANSACTION_QUANTITY
27176                                                        ,x_lot_secondary_quantity    => L_MTLT_REC.SECONDARY_QUANTITY
27177                                                        ,p_line_secondary_quantity	=> l_rti_SECONDARY_QUANTITY
27178                                                        ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
27179                                                        ,p_transaction_unit_of_measure=> l_rti_UNIT_OF_MEASURE
27180                                                        ,p_source_document_code	   => L_SOURCE_DOCUMENT_CODE
27181                                                        ,p_OE_ORDER_HEADER_ID	      => l_OE_ORDER_HEADER_ID
27182                                                        ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
27183                                                        ,p_rti_id	                  => L_RTI_ID
27184                                                        ,p_revision             	   => l_item_revision
27185                                                        ,p_subinventory_code  	      => L_SUB_CODE
27186                                                        ,p_locator_id           	   => l_loc_id
27187                                                        ,p_transaction_type           => l_transaction_type
27188                                                        ,p_parent_txn_type            => l_parent_txn_type
27189                                                        ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
27190                                                        );
27191 
27192 
27193               /*INVCONV ,*/
27194               IF (l_debug = 1) THEN
27195                 print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
27196                 print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
27197               END IF;
27198 
27199               IF X_RETURN_STATUS <> 'S' THEN
27200                  --RAISE ERROR
27201                  l_progress := 'WMSINB-26690';
27202                  RAISE fnd_api.g_exc_error;
27203               END IF;
27204 
27205               IF (l_debug = 1) THEN
27206                  print_debug('VALIDATE_LOT_SERIAL_INFO: VALIDATE_OPM_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
27207               END IF;
27208 
27209               /* END IF; --IF (l_discrete_transaction) THEN*/
27210             ELSE --IF (l_lot_exists = 1) THEN
27211               -- opm change bug# 3061052
27212                /*
27213                 IF (l_discrete_transaction) THEN */
27214                 --call CREATE_INV_LOT
27215 
27216                  /*INVCONV , Perform lot validations and create the new lot.
27217                   Call Lot Create API INV_ROI_INTEGRATION_GRP.INV_NEW_LOT to create the new lot.
27218                   This shall also create lot specific conversions after creating the new Lot.
27219                   This replaces the existing procedure INV_LOT_API_PUB.CREATE_INV_LOT to create NEW LOT
27220                   Punit Kumar*/
27221 
27222               IF (l_debug = 1) THEN
27223                  print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
27224               END IF;
27225 
27226               INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT(
27227                                                          x_return_status      		   => x_return_status
27228                                                         ,x_msg_data           		   => x_msg_data
27229                                                         ,x_msg_count          		   => x_msg_count
27230                                                         ,p_api_version	               => 1.0
27231                                                         ,p_init_msg_lst	               => FND_API.G_FALSE
27232                                                         ,p_mtlt_rowid	 		         => L_MTLT_REC.ROWID
27233                                                         ,p_transaction_type_id 	      => l_transaction_type_id
27234                                                         ,p_new_lot			            => 'Y'
27235                                                         ,p_item_id	 		            => l_item_id
27236                                                         ,p_to_organization_id		      => L_ORG_ID
27237                                                         ,p_lot_number			         => L_MTLT_REC.lot_number
27238                                                         ,p_parent_lot_number			   => L_MTLT_REC.parent_lot_number
27239                                                         ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
27240                                                         ,x_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
27241                                                         ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
27242                                                         ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
27243                                                         ,p_transaction_unit_of_measure => l_rti_UNIT_OF_MEASURE
27244                                                         ,p_source_document_code	      => L_SOURCE_DOCUMENT_CODE
27245                                                         ,p_OE_ORDER_HEADER_ID	         => l_OE_ORDER_HEADER_ID
27246                                                         ,p_OE_ORDER_LINE_ID	         => l_OE_ORDER_LINE_ID
27247                                                         ,p_rti_id	                     => L_RTI_ID
27248                                                         ,p_revision             	      => l_item_revision
27249                                                         ,p_subinventory_code  	      => L_SUB_CODE
27250                                                         ,p_locator_id           	      => l_loc_id
27251                                                         ,p_transaction_type           => l_transaction_type
27252                                                         ,p_parent_txn_type            => l_parent_txn_type
27253                                                         ,p_lot_primary_qty            => l_mtlt_rec.primary_quantity -- Bug# 4233182
27254                                                         );
27255 
27256                /*INVCONV ,*/
27257                IF (l_debug = 1) THEN
27258                   print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT :'||l_progress,1);
27259                   print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_VALIDATE_LOT return status: '||x_return_status||' : '||l_progress, 1);
27260                END IF;
27261 
27262               IF (x_return_status <> 'S') THEN
27263                  --raise error
27264                  l_progress := 'WMSINB-26790';
27265                  RAISE fnd_api.g_exc_error;
27266               END IF;
27267 
27268               /*INVCONV ,*/
27269               IF (l_debug = 1) THEN
27270                  print_debug('INVCONV, Before calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
27271               END IF;
27272 
27273               INV_ROI_INTEGRATION_GRP.INV_NEW_LOT(
27274                                                 x_return_status      		   => x_return_status
27275                                                ,x_msg_count          		   => x_msg_count
27276                                                ,x_msg_data           		   => x_msg_data
27277                                                ,p_api_version	               => 1.0
27278                                                ,p_init_msg_lst	               => FND_API.G_FALSE
27279                                                ,p_source_document_code			=> L_SOURCE_DOCUMENT_CODE
27280                                                ,p_item_id				         => l_item_id
27281                                                ,p_from_organization_id			=> L_FROM_ORG_ID
27282                                                ,p_to_organization_id	         => L_ORG_ID
27283                                                ,p_lot_number				      => L_MTLT_REC.lot_number
27284                                                ,p_lot_quantity			         => L_MTLT_REC.TRANSACTION_QUANTITY
27285                                                ,p_lot_secondary_quantity      => L_MTLT_REC.SECONDARY_QUANTITY
27286                                                ,p_line_secondary_quantity	   => l_rti_SECONDARY_QUANTITY
27287                                                ,p_primary_unit_of_measure	   => l_rti_PRIMARY_UNIT_OF_MEASURE
27288                                                ,p_secondary_unit_of_measure	=> l_rti_SEC_UNIT_OF_MEASURE
27289                                                ,p_uom_code	                  => l_rti_UOM_CODE
27290                                                ,p_secondary_uom_code	         => l_rti_SECONDARY_UOM_CODE
27291                                                ,p_reason_id	                  => L_MTLT_REC.REASON_ID
27292                                                ,P_MLN_REC                     => L_MLN_REC
27293                                                ,p_mtlt_rowid	               => L_MTLT_REC.ROWID
27294                                                );
27295 
27296                /*INVCONV ,*/
27297                IF (l_debug = 1) THEN
27298                   print_debug('INVCONV, After calling INV_ROI_INTEGRATION_GRP.INV_NEW_LOT :'||l_progress,1);
27299                   print_debug('INVCONV,VALIDATE_LOT_SERIAL_INFO: INV_ROI_INTEGRATION_GRP.INV_NEW_LOT return status: '||x_return_status||' : '||l_progress, 1);
27300                END IF;
27301 
27302                IF X_RETURN_STATUS <> 'S' THEN
27303                   --RAISE ERROR
27304                   l_progress := 'WMSINB-26817';
27305                   RAISE fnd_api.g_exc_error;
27306                END IF;
27307 
27308               IF (l_debug = 1) THEN
27309                  print_debug('VALIDATE_LOT_SERIAL_INFO: VALIDATE_OPM_LOT STATUS: '||x_return_status||' : '||l_progress, 1);
27310               END IF;
27311 
27312               /*END IF; -- IF (l_discrete_transaction) THEN*/
27313             END IF; --IF (l_lot_exists = 1) THEN
27314           END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
27315 
27316           IF (l_serial_number_control_code IN (2,5,6)) THEN
27317             IF (l_debug = 1) THEN
27318                 print_debug('VALIDATE_LOT_SERIAL_INFO: LOT AND SERIAL CONTROLLED: '||l_progress, 1);
27319                 print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROL CODE: '||l_serial_number_control_code||' : '||l_progress, 1);
27320                 print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||l_source_document_code||' : '||l_progress, 1);
27321                 l_progress := 'WMSINB-26834';
27322             END IF;
27323 
27324             L_NUM_MSNT_RECS := 0;
27325             l_tot_msnt_serial_qty := 0;
27326 
27327             OPEN C_MSNT_LOTSERIAL(L_MTLT_REC.SERIAL_TRANSACTION_TEMP_ID);
27328             LOOP
27329               FETCH C_MSNT_LOTSERIAL INTO L_MSNT_REC;
27330               EXIT WHEN C_MSNT_LOTSERIAL%NOTFOUND;
27331 
27332               L_NUM_MSNT_RECS := L_NUM_MSNT_RECS + 1;
27333               L_SERIAL_QUANTITY := INV_SERIAL_NUMBER_PUB.GET_SERIAL_DIFF(L_MSNT_REC.FM_SERIAL_NUMBER,
27334                       L_MSNT_REC.TO_SERIAL_NUMBER);
27335               l_tot_msnt_serial_qty := l_tot_msnt_serial_qty + l_serial_quantity;
27336               INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.FM_SERIAL_NUMBER, L_TEMP_PREFIX, L_FROM_SER_NUMBER);
27337                                         INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.TO_SERIAL_NUMBER, L_TEMP_PREFIX, L_TO_SER_NUMBER);
27338 
27339               IF (l_debug = 1) THEN
27340                  print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL QUANTITY: '||l_serial_quantity||' : '||l_progress, 1);
27341                  l_progress := 'WMSINB-26859';
27342               END IF;
27343 
27344               --populate attributes table
27345               l_serial_attributes_tbl(1).column_name   := 'SERIAL_ATTRIBUTE_CATEGORY';
27346               l_serial_attributes_tbl(1).column_value  := l_msnt_rec.serial_attribute_category;
27347               l_serial_attributes_tbl(2).column_name   := 'ORIGINATION_DATE';
27348               l_serial_attributes_tbl(2).column_value  := l_msnt_rec.origination_date;
27349               l_serial_attributes_tbl(3).column_name   := 'C_ATTRIBUTE1';
27350               l_serial_attributes_tbl(3).column_value  := l_msnt_rec.c_attribute1;
27351               l_serial_attributes_tbl(4).column_name   := 'C_ATTRIBUTE2';
27352               l_serial_attributes_tbl(4).column_value  := l_msnt_rec.c_attribute2;
27353               l_serial_attributes_tbl(5).column_name   := 'C_ATTRIBUTE3';
27354               l_serial_attributes_tbl(5).column_value  := l_msnt_rec.c_attribute3;
27355               l_serial_attributes_tbl(6).column_name   := 'C_ATTRIBUTE4';
27356               l_serial_attributes_tbl(6).column_value   := l_msnt_rec.c_attribute4;
27357               l_serial_attributes_tbl(7).column_name   := 'C_ATTRIBUTE5';
27358               l_serial_attributes_tbl(7).column_value   := l_msnt_rec.c_attribute5;
27359               l_serial_attributes_tbl(8).column_name   := 'C_ATTRIBUTE6';
27360               l_serial_attributes_tbl(8).column_value   := l_msnt_rec.c_attribute6;
27361               l_serial_attributes_tbl(9).column_name   := 'C_ATTRIBUTE7';
27362               l_serial_attributes_tbl(9).column_value   := l_msnt_rec.c_attribute7;
27363               l_serial_attributes_tbl(10).column_name  := 'C_ATTRIBUTE8';
27364               l_serial_attributes_tbl(10).column_value  := l_msnt_rec.c_attribute8;
27365               l_serial_attributes_tbl(11).column_name  := 'C_ATTRIBUTE9';
27366               l_serial_attributes_tbl(11).column_value  := l_msnt_rec.c_attribute9;
27367               l_serial_attributes_tbl(12).column_name  := 'C_ATTRIBUTE10';
27368               l_serial_attributes_tbl(12).column_value  := l_msnt_rec.c_attribute10;
27369               l_serial_attributes_tbl(13).column_name  := 'C_ATTRIBUTE11';
27370               l_serial_attributes_tbl(13).column_value  := l_msnt_rec.c_attribute11;
27371               l_serial_attributes_tbl(14).column_name  := 'C_ATTRIBUTE12';
27372               l_serial_attributes_tbl(14).column_value  := l_msnt_rec.c_attribute12;
27373               l_serial_attributes_tbl(15).column_name  := 'C_ATTRIBUTE13';
27374               l_serial_attributes_tbl(15).column_value  := l_msnt_rec.c_attribute13;
27375               l_serial_attributes_tbl(16).column_name  := 'C_ATTRIBUTE14';
27376               l_serial_attributes_tbl(16).column_value  := l_msnt_rec.c_attribute14;
27377               l_serial_attributes_tbl(17).column_name  := 'C_ATTRIBUTE15';
27378               l_serial_attributes_tbl(17).column_value  := l_msnt_rec.c_attribute15;
27379               l_serial_attributes_tbl(18).column_name  := 'C_ATTRIBUTE16';
27380               l_serial_attributes_tbl(18).column_value  := l_msnt_rec.c_attribute16;
27381               l_serial_attributes_tbl(19).column_name  := 'C_ATTRIBUTE17';
27382               l_serial_attributes_tbl(19).column_value  := l_msnt_rec.c_attribute17;
27383               l_serial_attributes_tbl(20).column_name  := 'C_ATTRIBUTE18';
27384               l_serial_attributes_tbl(20).column_value  := l_msnt_rec.c_attribute18;
27385               l_serial_attributes_tbl(21).column_name  := 'C_ATTRIBUTE19';
27386               l_serial_attributes_tbl(21).column_value  := l_msnt_rec.c_attribute19;
27387               l_serial_attributes_tbl(22).column_name  := 'C_ATTRIBUTE20';
27388               l_serial_attributes_tbl(22).column_value  := l_msnt_rec.c_attribute20;
27389               l_serial_attributes_tbl(23).column_name  := 'D_ATTRIBUTE1';
27390               l_serial_attributes_tbl(23).column_value  := l_msnt_rec.d_attribute1;
27391               l_serial_attributes_tbl(24).column_name  := 'D_ATTRIBUTE2';
27392               l_serial_attributes_tbl(24).column_value  := l_msnt_rec.d_attribute2;
27393               l_serial_attributes_tbl(25).column_name  := 'D_ATTRIBUTE3';
27394               l_serial_attributes_tbl(25).column_value  := l_msnt_rec.d_attribute3;
27395               l_serial_attributes_tbl(26).column_name  := 'D_ATTRIBUTE4';
27396               l_serial_attributes_tbl(26).column_value  := l_msnt_rec.d_attribute4;
27397               l_serial_attributes_tbl(27).column_name  := 'D_ATTRIBUTE5';
27398               l_serial_attributes_tbl(27).column_value  := l_msnt_rec.d_attribute5;
27399               l_serial_attributes_tbl(28).column_name  := 'D_ATTRIBUTE6';
27400               l_serial_attributes_tbl(28).column_value  := l_msnt_rec.d_attribute6;
27401               l_serial_attributes_tbl(29).column_name  := 'D_ATTRIBUTE7';
27402               l_serial_attributes_tbl(29).column_value  := l_msnt_rec.d_attribute7;
27403               l_serial_attributes_tbl(30).column_name  := 'D_ATTRIBUTE8';
27404               l_serial_attributes_tbl(30).column_value  := l_msnt_rec.d_attribute8;
27405               l_serial_attributes_tbl(31).column_name  := 'D_ATTRIBUTE9';
27406               l_serial_attributes_tbl(31).column_value  := l_msnt_rec.d_attribute9;
27407               l_serial_attributes_tbl(32).column_name  := 'D_ATTRIBUTE10';
27408               l_serial_attributes_tbl(32).column_value  := l_msnt_rec.d_attribute10;
27409               l_serial_attributes_tbl(33).column_name  := 'N_ATTRIBUTE1';
27410               l_serial_attributes_tbl(33).column_value  := l_msnt_rec.n_attribute1;
27411               l_serial_attributes_tbl(34).column_name  := 'N_ATTRIBUTE2';
27412               l_serial_attributes_tbl(34).column_value  := l_msnt_rec.n_attribute2;
27413               l_serial_attributes_tbl(35).column_name  := 'N_ATTRIBUTE3';
27414               l_serial_attributes_tbl(35).column_value  := l_msnt_rec.n_attribute3;
27415               l_serial_attributes_tbl(36).column_name  := 'N_ATTRIBUTE4';
27416               l_serial_attributes_tbl(36).column_value  := l_msnt_rec.n_attribute4;
27417               l_serial_attributes_tbl(37).column_name  := 'N_ATTRIBUTE5';
27418               l_serial_attributes_tbl(37).column_value := l_msnt_rec.n_attribute5;
27419               l_serial_attributes_tbl(38).column_name  := 'N_ATTRIBUTE6';
27420               l_serial_attributes_tbl(38).column_value := l_msnt_rec.n_attribute6;
27421               l_serial_attributes_tbl(39).column_name  := 'N_ATTRIBUTE7';
27422               l_serial_attributes_tbl(39).column_value := l_msnt_rec.n_attribute7;
27423               l_serial_attributes_tbl(40).column_name  := 'N_ATTRIBUTE8';
27424               l_serial_attributes_tbl(40).column_value := l_msnt_rec.n_attribute8;
27425               l_serial_attributes_tbl(41).column_name  := 'N_ATTRIBUTE9';
27426               l_serial_attributes_tbl(41).column_value := l_msnt_rec.n_attribute9;
27427               l_serial_attributes_tbl(42).column_name  := 'N_ATTRIBUTE10';
27428               l_serial_attributes_tbl(42).column_value := l_msnt_rec.n_attribute10;
27429               l_serial_attributes_tbl(43).column_name  := 'STATUS_ID';
27430               l_serial_attributes_tbl(43).column_value := l_msnt_rec.status_id;
27431               l_serial_attributes_tbl(44).column_name  := 'TERRITORY_CODE';
27432               l_serial_attributes_tbl(44).column_value := l_msnt_rec.territory_code;
27433 
27434               --Validate the serials
27435               FOR SERIALQTY IN 1..L_SERIAL_QUANTITY LOOP
27436 
27437                 l_progress := 'WMSINB-26865';
27438                 L_CUR_NUMBER := L_FROM_SER_NUMBER+SERIALQTY -1;
27439                 if L_FROM_SER_NUMBER = -1 and  L_TO_SER_NUMBER = -1 then
27440                   L_SERIAL_NUMBER := L_MSNT_REC.fm_serial_number;
27441                 else
27442                   L_SERIAL_NUMBER := SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
27443                                         LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) - LENGTH(L_CUR_NUMBER))
27444                                       ||L_CUR_NUMBER;
27445                 End if;
27446 
27447                 l_progress := 'WMSINB-26873';
27448 
27449                 BEGIN
27450                   SELECT CURRENT_ORGANIZATION_ID
27451                     , current_status
27452                     , lot_number
27453                     , Decode(lpn_id,0,NULL,lpn_id)
27454                     , inspection_status
27455                     , group_mark_id
27456                     INTO L_CURR_ORG_ID
27457                     , l_curr_status
27458                     , l_curr_lot_num
27459                     , l_curr_lpn_id
27460                     , l_inspection_status
27461                     , l_group_mark_id
27462                     FROM MTL_SERIAL_NUMBERS
27463                     WHERE SERIAL_NUMBER = l_serial_number
27464                     AND inventory_item_id = l_item_id;
27465 
27466                   l_serial_exists := 1;
27467                   l_progress := 'WMSINB-26893';
27468                 EXCEPTION
27469                   WHEN no_data_found THEN
27470                      l_serial_exists := 0;
27471                      l_progress := 'WMSINB-26897';
27472                 END;
27473 
27474                 IF (l_debug = 1) THEN
27475                   print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL EXISTS: '||l_serial_exists||' : '||l_progress, 1);
27476                   print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NUMBER: '||l_serial_number||' : '||l_progress, 1);
27477                   print_debug('VALIDATE_LOT_SERIAL_INFO: CURR STATUS: '||l_curr_status||' : '||l_progress, 1);
27478                   print_debug('VALIDATE_LOT_SERIAL_INFO: CURR ORG ID: '||l_curr_org_id||' : '||l_progress, 1);
27479                   print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LPN ID: '||l_curr_lpn_id||' : '||l_progress, 1);
27480                   print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LOT NUM: '||l_curr_lot_num||' : '||l_progress, 1);
27481                   print_debug('VALIDATE_LOT_SERIAL_INFO: INSPECT STS: '||l_inspection_status||' : '||l_progress, 1);
27482                   print_debug('VALIDATE_LOT_SERIAL_INFO: GROUP MARK ID: '||l_group_mark_id||' : '||l_progress, 1);
27483                   print_debug('VALIDATE_LOT_SERIAL_INFO: RESTRICT RCPT SER: '||l_restrict_rcpt_ser||' : '||l_progress, 1);
27484                   l_progress := 'WMSINB-26910';
27485                 END IF;
27486 
27487                 IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
27488                   IF (l_grand_parent_txn_type <> 'DELIVER') THEN
27489                     IF NOT (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
27490                       --raise an error
27491                       l_progress := 'WMSINB-26915';
27492                       RAISE fnd_api.g_exc_error;
27493                     ELSE --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
27494                       BEGIN
27495                         SELECT '1'
27496                           INTO L_DUMMY
27497                           FROM RCV_SERIALS_SUPPLY
27498                           WHERE TRANSACTION_ID = l_grand_parent_txn_id
27499                           AND SERIAL_NUM = L_SERIAL_NUMBER;
27500 
27501                         IF (l_curr_status <> 7) THEN
27502                            --raise error
27503                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27504                            fnd_msg_pub.ADD;
27505                            l_progress := 'WMSINB-26931';
27506                            RAISE fnd_api.g_exc_error;
27507                         END IF;
27508 
27509                         --Validate serial/group_mark_id to prevent
27510                         --entering of duplicate serials
27511 
27512                         IF (Nvl(l_group_mark_id, -99) = -7937) THEN
27513                            --raise error
27514                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27515                            fnd_msg_pub.ADD;
27516                            l_progress := 'WMSINB-26942';
27517                            RAISE fnd_api.g_exc_error;
27518                         END IF;
27519 
27520                         --UPDATE GROUP_MARK_ID TO -7937
27521                         IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
27522                            --raise error
27523                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27524                            fnd_msg_pub.ADD;
27525                            l_progress := 'WMSINB-26951';
27526                            RAISE fnd_api.g_exc_error;
27527                         END IF;
27528                       EXCEPTION
27529                         WHEN NO_DATA_FOUND THEN
27530                            -- RAISE ERROR
27531                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27532                            fnd_msg_pub.ADD;
27533                            l_progress := 'WMSINB-26959';
27534                            RAISE fnd_api.g_exc_error;
27535                       END;
27536                     END IF; --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
27537                   ELSE --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
27538                     IF l_curr_org_id <> l_org_id THEN
27539                        --raise error
27540                        fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27541                        fnd_msg_pub.ADD;
27542                        l_progress := 'WMSINB-26968';
27543                        RAISE fnd_api.g_exc_error;
27544                     ELSE
27545                        IF
27546                          ((l_curr_lot_num IS NOT NULL) AND (l_curr_lot_num <> l_mtlt_rec.lot_number)
27547                           AND
27548                           (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
27549                           --raise error
27550                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27551                           fnd_msg_pub.ADD;
27552                           l_progress := 'WMSINB-26975';
27553                           RAISE fnd_api.g_exc_error;
27554                        END IF;
27555                     END IF;
27556 
27557                     IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
27558                        IF l_curr_status NOT IN (1,6) THEN
27559                           --raise error
27560                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27561                           fnd_msg_pub.ADD;
27562                           l_progress := 'WMSINB-26985';
27563                           RAISE fnd_api.g_exc_error;
27564                        END IF;
27565                     ELSE --IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
27566                        IF (l_curr_status <> 3) THEN
27567                           --raise error
27568                           fnd_message.set_name('INV','INV_FAIL_VALIDATE_SERIAL');
27569                           fnd_msg_pub.ADD;
27570                           l_progress := 'WMSINB-26993';
27571                           RAISE fnd_api.g_exc_error;
27572                        END IF;
27573                     END IF; --IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
27574 
27575                     IF (Nvl(l_group_mark_id, -99) = -7937) THEN
27576                        --raise error
27577                        fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27578                        fnd_msg_pub.ADD;
27579                        l_progress := 'WMSINB-27002';
27580                        RAISE fnd_api.g_exc_error;
27581                     END IF;
27582 
27583                     IF (Nvl(l_curr_status, 1) in (1,6)) THEN
27584                        --validate and update the attributes.
27585                        inv_serial_number_pub.validate_update_serial_att
27586                          (x_return_status     => x_return_status,
27587                           x_msg_count         => x_msg_count,
27588                           x_msg_data          => x_msg_data,
27589                           x_validation_status => l_validation_status,
27590                           p_serial_number     => l_serial_number,
27591                           p_organization_id   => l_org_id,
27592                           p_inventory_item_id => l_item_id,
27593                           p_serial_att_tbl    => l_serial_attributes_tbl,
27594                           p_validate_only     => FALSE
27595                           );
27596 
27597                        IF (l_validation_status <> 'Y'
27598                            OR x_return_status <> g_ret_sts_success) THEN
27599                           --raise error
27600                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27601                           fnd_msg_pub.ADD;
27602                           l_progress := 'WMSINB-27008';
27603                           RAISE fnd_api.g_exc_error;
27604                        END IF;
27605                     END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
27606 
27607                     --UPDATE GROUP_MARK_ID TO -7937
27608                     IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
27609                       --raise error
27610                        fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27611                        fnd_msg_pub.ADD;
27612                        l_progress := 'WMSINB-27011';
27613                        RAISE fnd_api.g_exc_error;
27614                     END IF;
27615                   END IF; --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
27616                 ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
27617                   IF (l_parent_txn_type <> 'RECEIVE') THEN
27618                     IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
27619                       BEGIN
27620                         SELECT '1'
27621                           INTO L_DUMMY
27622                           FROM RCV_SERIALS_SUPPLY
27623                           WHERE TRANSACTION_ID = l_grand_parent_txn_id
27624                           AND SERIAL_NUM = L_SERIAL_NUMBER;
27625 
27626                         IF (l_curr_status <> 7) THEN
27627                            --raise error
27628                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27629                            fnd_msg_pub.ADD;
27630                            l_progress := 'WMSINB-27029';
27631                            RAISE fnd_api.g_exc_error;
27632                         END IF;
27633 
27634                         --Validate serial/group_mark_id to prevent
27635                         --entering of duplicate serials
27636 
27637                         IF (Nvl(l_group_mark_id, -99) = -7937) THEN
27638                            --raise error
27639                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27640                            fnd_msg_pub.ADD;
27641                            l_progress := 'WMSINB-27040';
27642                            RAISE fnd_api.g_exc_error;
27643                         END IF;
27644 
27645                         --UPDATE GROUP_MARK_ID TO -7937
27646                         IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
27647                            --raise error
27648                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27649                            fnd_msg_pub.ADD;
27650                            l_progress := 'WMSINB-27049';
27651                            RAISE fnd_api.g_exc_error;
27652                         END IF;
27653                       EXCEPTION
27654                           WHEN NO_DATA_FOUND THEN
27655                              -- RAISE ERROR
27656                              fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27657                              fnd_msg_pub.ADD;
27658                              l_progress := 'WMSINB-27057';
27659                              RAISE fnd_api.g_exc_error;
27660                       END;
27661                     ELSE --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
27662                       IF (l_serial_exists = 1) THEN
27663                         IF l_curr_org_id <> l_org_id THEN
27664                            --raise error
27665                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27666                            fnd_msg_pub.ADD;
27667                            l_progress := 'WMSINB-27066';
27668                            RAISE fnd_api.g_exc_error;
27669                         ELSE
27670                           IF ((l_curr_lot_num IS NOT NULL) AND (l_curr_lot_num <> l_mtlt_rec.lot_number)
27671                             AND (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
27672                             --raise error
27673                             fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27674                             fnd_msg_pub.ADD;
27675                             l_progress := 'WMSINB-27073';
27676                             RAISE fnd_api.g_exc_error;
27677                           END IF;
27678                         END IF;
27679 
27680                       /* Bug#6450814
27681                          * In order to receive the Issued out Serial numbers during
27682                          * Positive Correction transaction made the following changes.
27683                          */
27684                         IF l_curr_status NOT IN (1,4,6) THEN--Bug: 6450814
27685                            --raise error
27686                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27687                            fnd_msg_pub.ADD;
27688                            l_progress := 'WMSINB-27082';
27689                            RAISE fnd_api.g_exc_error;
27690                         END IF;
27691 
27692                         IF (Nvl(l_group_mark_id, -99) = -7937) THEN
27693                            --raise error
27694                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27695                            fnd_msg_pub.ADD;
27696                            l_progress := 'WMSINB-27090';
27697                            RAISE fnd_api.g_exc_error;
27698                         END IF;
27699 
27700                         IF (Nvl(l_curr_status, 1) in (1,6)) THEN
27701                            --validate and update the attributes.
27702                            inv_serial_number_pub.validate_update_serial_att
27703                              (x_return_status     => x_return_status,
27704                               x_msg_count         => x_msg_count,
27705                               x_msg_data          => x_msg_data,
27706                               x_validation_status => l_validation_status,
27707                               p_serial_number     => l_serial_number,
27708                               p_organization_id   => l_org_id,
27709                               p_inventory_item_id => l_item_id,
27710                               p_serial_att_tbl    => l_serial_attributes_tbl,
27711                               p_validate_only     => FALSE
27712                               );
27713 
27714                            IF (l_validation_status <> 'Y'
27715                                OR x_return_status <> g_ret_sts_success) THEN
27716                               --raise error
27717                               fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27718                               fnd_msg_pub.ADD;
27719                               l_progress := 'WMSINB-27095';
27720                               RAISE fnd_api.g_exc_error;
27721                            END IF;
27722                         END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
27723 
27724                         --UPDATE GROUP_MARK_ID TO -7937
27725                         IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
27726                            --raise error
27727                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27728                            fnd_msg_pub.ADD;
27729                            l_progress := 'WMSINB-27099';
27730                            RAISE fnd_api.g_exc_error;
27731                         END IF;
27732                       ELSE --IF (l_serial_exists = 1) THEN
27733                         IF l_serial_number_control_code = 5 THEN
27734                            --PERFORM SERIAL VALIDATION FOR NEW SERIAL
27735                            --(INCLUDING ATT VALIDATION)
27736                            --CREATE MSN
27737                           IF (l_transaction_type = 'CORRECT') THEN
27738                             l_transaction_action_id := 29;
27739                           ELSE
27740                             l_transaction_action_id := 1;
27741                           END IF;
27742 
27743                           inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
27744                                      , p_inventory_item_id => l_item_id
27745                                      , p_organization_id => l_org_id
27746                                      , p_from_serial_number => l_serial_number
27747                                      , p_to_serial_number => l_serial_number
27748                                      , p_initialization_date => SYSDATE
27749                                      , p_completion_date => NULL
27750                                      , p_ship_date => NULL
27751                                      , p_revision => l_item_revision
27752                                      , p_lot_number => l_mtlt_rec.lot_number
27753                                      , p_current_locator_id => l_loc_id
27754                                      , p_subinventory_code => l_sub_code
27755                                      , p_trx_src_id => NULL
27756                                      , p_unit_vendor_id => NULL
27757                                      , p_vendor_lot_number => l_mtlt_rec.supplier_lot_number
27758                                      , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
27759                                      , p_receipt_issue_type => NULL
27760                                      , p_txn_src_id => NULL
27761                                      , p_txn_src_name => NULL
27762                                      , p_txn_src_type_id => NULL
27763                                      , p_transaction_id => NULL
27764                                      , p_current_status => 1
27765                                      , p_parent_item_id => NULL
27766                                      , p_parent_serial_number => NULL
27767                                      , p_cost_group_id => NULL
27768                                      , p_transaction_action_id => l_transaction_action_id
27769                                      , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
27770                                      , p_status_id => NULL
27771                                      , p_inspection_status => NULL
27772                                      , x_object_id => l_object_id
27773                                      , x_return_status => x_return_status
27774                                      , x_msg_count => x_msg_count
27775                                      , x_msg_data => x_msg_data);
27776 
27777                           IF (x_return_status <> g_ret_sts_success) THEN
27778                             --raise error
27779                             fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27780                             fnd_msg_pub.ADD;
27781                             l_progress := 'WMSINB-27105';
27782                             RAISE fnd_api.g_exc_error;
27783                           END IF;
27784 
27785                           --validate and update the attributes.
27786                           inv_serial_number_pub.validate_update_serial_att
27787                              (x_return_status     => x_return_status,
27788                               x_msg_count         => x_msg_count,
27789                               x_msg_data          => x_msg_data,
27790                               x_validation_status => l_validation_status,
27791                               p_serial_number     => l_serial_number,
27792                               p_organization_id   => l_org_id,
27793                               p_inventory_item_id => l_item_id,
27794                               p_serial_att_tbl    => l_serial_attributes_tbl,
27795                               p_validate_only     => FALSE
27796                             );
27797 
27798                           IF (l_validation_status <> 'Y'
27799                              OR x_return_status <> g_ret_sts_success) THEN
27800                             --raise error
27801                             fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27802                             fnd_msg_pub.ADD;
27803                             l_progress := 'WMSINB-27145';
27804                             RAISE fnd_api.g_exc_error;
27805                           END IF;
27806 
27807                           --UPDATE GROUP_MARK_ID TO -7937
27808                           IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
27809                             --raise error
27810                             fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27811                             fnd_msg_pub.ADD;
27812                             l_progress := 'WMSINB-27152';
27813                             RAISE fnd_api.g_exc_error;
27814                           END IF;
27815                         ELSE   --IF l_serial_number_control_code = 5 THEN
27816                            --raise error
27817                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27818                            fnd_msg_pub.ADD;
27819                            l_progress := 'WMSINB-27159';
27820                            RAISE fnd_api.g_exc_error;
27821                         END IF; --IF l_serial_number_control_code = 5 THEN
27822                       END IF; --IF (l_serial_exists = 1) THEN
27823                     END IF; --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
27824                   ELSE --IF (l_parent_txn_type <> 'RECEIVE') THEN
27825                     IF (l_serial_exists = 1) THEN
27826                       IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
27827                         -- CHECK TO SEE IF THE ITEM IS SERIAL
27828                         -- CONTROLLED IN SOURCE ORG
27829 
27830                         GET_SERIAL_LOT_CTRL_IN_SRC_ORG
27831                            (L_SHIPMENT_LINE_ID, L_ORG_ID,
27832                             L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
27833                             l_from_org_rev_ctrl, X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
27834 
27835                         IF ((L_FROM_ORG_SER_CRTL IN (2,5,6)
27836                             AND l_source_document_code = 'REQ')
27837                             OR (l_from_org_ser_crtl IN (2,5)
27838                                AND l_source_document_code = 'INVENTORY')
27839                            ) THEN
27840                           IF l_curr_org_id <> l_from_org_id THEN
27841                              --raise error
27842                              fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27843                              fnd_msg_pub.ADD;
27844                              l_progress := 'WMSINB-27180';
27845                              RAISE fnd_api.g_exc_error;
27846                           ELSE --IF l_curr_org_id <> l_from_org_id THEN
27847                             IF ((l_curr_lot_num IS NOT NULL) AND
27848                              (l_curr_lot_num <> l_mtlt_rec.lot_number)
27849                               AND (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
27850                               --raise error
27851                               fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27852                               fnd_msg_pub.ADD;
27853                               l_progress := 'WMSINB-27188';
27854                               RAISE fnd_api.g_exc_error;
27855                             END IF;
27856                           END IF; --IF l_curr_org_id <> l_from_org_id THEN
27857 
27858                           BEGIN
27859                              SELECT '1'
27860                                INTO L_DUMMY
27861                                FROM rcv_serials_supply rss
27862                                , rcv_shipment_lines rsl
27863                                WHERE rss.SHIPMENT_LINE_ID = rsl.SHIPMENT_LINE_ID
27864                                AND rsl.shipment_header_id = l_shipment_header_id
27865                                AND rsl.item_id = l_item_id
27866                                AND rss.SUPPLY_TYPE_CODE = 'SHIPMENT'
27867                                AND rss.serial_num = l_serial_number;
27868 
27869                              IF L_CURR_STATUS <> 5 THEN
27870                                 -- RAISE AN ERROR
27871                                 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27872                                 fnd_msg_pub.ADD;
27873                                 l_progress := 'WMSINB-27205';
27874                                 RAISE fnd_api.g_exc_error;
27875                              END IF;
27876 
27877                           EXCEPTION
27878                              WHEN NO_DATA_FOUND THEN
27879                                 -- RAISE AN ERROR
27880                                 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27881                                 fnd_msg_pub.ADD;
27882                                 l_progress := 'WMSINB-27214';
27883                                 RAISE fnd_api.g_exc_error;
27884                           END;
27885                         ELSE --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
27886                           IF l_curr_org_id <> l_org_id THEN
27887                              --raise error
27888                              fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27889                              fnd_msg_pub.ADD;
27890                              l_progress := 'WMSINB-27222';
27891                              RAISE fnd_api.g_exc_error;
27892                           ELSE
27893                             IF ((l_curr_lot_num IS NOT NULL) AND (l_curr_lot_num <> l_mtlt_rec.lot_number)
27894                               AND (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
27895                               --raise error
27896                               fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27897                               fnd_msg_pub.ADD;
27898                               l_progress := 'WMSINB-27229';
27899                               RAISE fnd_api.g_exc_error;
27900                             END IF;
27901                           END IF;
27902 
27903                           IF l_curr_status NOT IN (1,6) THEN
27904                              --raise error
27905                              fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27906                              fnd_msg_pub.ADD;
27907                              l_progress := 'WMSINB-27238';
27908                              RAISE fnd_api.g_exc_error;
27909                           END IF;
27910 
27911                           IF (Nvl(l_group_mark_id, -99) = -7937) THEN
27912                              --raise error
27913                              fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27914                              fnd_msg_pub.ADD;
27915                              l_progress := 'WMSINB-27246';
27916                              RAISE fnd_api.g_exc_error;
27917                           END IF;
27918 
27919                           IF (Nvl(l_curr_status, 1) in (1,6)) THEN
27920                              --validate and update the attributes.
27921                              inv_serial_number_pub.validate_update_serial_att
27922                                (x_return_status     => x_return_status,
27923                                 x_msg_count         => x_msg_count,
27924                                 x_msg_data          => x_msg_data,
27925                                 x_validation_status => l_validation_status,
27926                                 p_serial_number     => l_serial_number,
27927                                 p_organization_id   => l_org_id,
27928                                 p_inventory_item_id => l_item_id,
27929                                 p_serial_att_tbl    => l_serial_attributes_tbl,
27930                                 p_validate_only     => FALSE
27931                                 );
27932 
27933                              IF (l_validation_status <> 'Y'
27934                                  OR x_return_status <> g_ret_sts_success) THEN
27935                                 --raise error
27936                                 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27937                                 fnd_msg_pub.ADD;
27938                                 l_progress := 'WMSINB-27251';
27939                                 RAISE fnd_api.g_exc_error;
27940                              END IF;
27941                           END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
27942 
27943                           --UPDATE GROUP_MARK_ID TO -7937
27944                           IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
27945                              --raise error
27946                              fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27947                              fnd_msg_pub.ADD;
27948                              l_progress := 'WMSINB-27255';
27949                              RAISE fnd_api.g_exc_error;
27950                           END IF;
27951                              END IF; --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
27952                            ELSE --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
27953                           IF l_curr_org_id <> l_org_id THEN
27954                              --raise error
27955                              fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27956                              fnd_msg_pub.ADD;
27957                              l_progress := 'WMSINB-27264';
27958                              RAISE fnd_api.g_exc_error;
27959                            ELSE
27960                              IF ((l_curr_lot_num IS NOT NULL) AND (l_curr_lot_num <> l_mtlt_rec.lot_number)
27961                            AND (Nvl(l_curr_status,1) NOT IN (1,4))) THEN
27962                           --raise error
27963                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27964                           fnd_msg_pub.ADD;
27965                           l_progress := 'WMSINB-27271';
27966                           RAISE fnd_api.g_exc_error;
27967                              END IF;
27968                           END IF;
27969 
27970                           IF l_curr_status NOT IN (1,4,6) THEN--Bug: 6450814
27971                              --raise error
27972                              fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27973                              fnd_msg_pub.ADD;
27974                              l_progress := 'WMSINB-27280';
27975                              RAISE fnd_api.g_exc_error;
27976                           END IF;
27977 
27978                           IF (Nvl(l_group_mark_id, -99) = -7937) THEN
27979                              --raise error
27980                              fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
27981                              fnd_msg_pub.ADD;
27982                              l_progress := 'WMSINB-27288';
27983                              RAISE fnd_api.g_exc_error;
27984                           END IF;
27985 
27986                           IF (Nvl(l_curr_status, 1) in (1,6)) THEN
27987                              --validate and update the attributes.
27988                              inv_serial_number_pub.validate_update_serial_att
27989                                (x_return_status     => x_return_status,
27990                                 x_msg_count         => x_msg_count,
27991                                 x_msg_data          => x_msg_data,
27992                                 x_validation_status => l_validation_status,
27993                                 p_serial_number     => l_serial_number,
27994                                 p_organization_id   => l_org_id,
27995                                 p_inventory_item_id => l_item_id,
27996                                 p_serial_att_tbl    => l_serial_attributes_tbl,
27997                                 p_validate_only     => FALSE
27998                                 );
27999 
28000                              IF (l_validation_status <> 'Y'
28001                                  OR x_return_status <> g_ret_sts_success) THEN
28002                                 --raise error
28003                                 fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28004                                 fnd_msg_pub.ADD;
28005                                 l_progress := 'WMSINB-27294';
28006                                 RAISE fnd_api.g_exc_error;
28007                              END IF;
28008                           END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
28009 
28010                           --UPDATE GROUP_MARK_ID TO -7937
28011                           IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
28012                              --raise error
28013                              fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28014                              fnd_msg_pub.ADD;
28015                              l_progress := 'WMSINB-27297';
28016                              RAISE fnd_api.g_exc_error;
28017                           END IF;
28018                         END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
28019                       ELSE --IF (l_serial_exists = 1) THEN
28020                         IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
28021                           -- CHECK TO SEE IF THE ITEM IS SERIAL
28022                           -- CONTROLLED IN SOURCE ORG
28023 
28024                           GET_SERIAL_LOT_CTRL_IN_SRC_ORG
28025                             (L_SHIPMENT_LINE_ID, L_ORG_ID,
28026                              L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
28027                              l_from_org_rev_ctrl, X_RETURN_STATUS, X_MSG_COUNT, X_MSG_DATA);
28028 
28029                           IF ((L_FROM_ORG_SER_CRTL IN (2,5,6)
28030                                AND l_source_document_code = 'REQ')
28031                               OR (l_from_org_ser_crtl IN (2,5)
28032                             AND l_source_document_code = 'INVENTORY')
28033                               ) THEN
28034                              --raise error
28035                              fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28036                              fnd_msg_pub.ADD;
28037                              l_progress := 'WMSINB-27315';
28038                              RAISE fnd_api.g_exc_error;
28039                           END IF; --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
28040                         END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
28041 
28042                         IF l_serial_number_control_code = 5 THEN
28043                           --PERFORM SERIAL VALIDATION FOR NEW SERIAL
28044                           --(INCLUDING ATT VALIDATION)
28045                           --CREATE MSN
28046                           IF (l_transaction_type = 'CORRECT') THEN
28047                              l_transaction_action_id := 29;
28048                           ELSE
28049                              l_transaction_action_id := 1;
28050                           END IF;
28051 
28052                           inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
28053                                       , p_inventory_item_id => l_item_id
28054                                       , p_organization_id => l_org_id
28055                                       , p_from_serial_number => l_serial_number
28056                                       , p_to_serial_number => l_serial_number
28057                                       , p_initialization_date => SYSDATE
28058                                       , p_completion_date => NULL
28059                                       , p_ship_date => NULL
28060                                       , p_revision => l_item_revision
28061                                       , p_lot_number => l_mtlt_rec.lot_number
28062                                       , p_current_locator_id => l_loc_id
28063                                       , p_subinventory_code => l_sub_code
28064                                       , p_trx_src_id => NULL
28065                                       , p_unit_vendor_id => NULL
28066                                       , p_vendor_lot_number => l_mtlt_rec.supplier_lot_number
28067                                       , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
28068                                       , p_receipt_issue_type => NULL
28069                                       , p_txn_src_id => NULL
28070                                       , p_txn_src_name => NULL
28071                                       , p_txn_src_type_id => NULL
28072                                       , p_transaction_id => NULL
28073                                       , p_current_status => 1
28074                                       , p_parent_item_id => NULL
28075                                       , p_parent_serial_number => NULL
28076                                       , p_cost_group_id => NULL
28077                                       , p_transaction_action_id => l_transaction_action_id
28078                                       , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
28079                                       , p_status_id => NULL
28080                                       , p_inspection_status => NULL
28081                                       , x_object_id => l_object_id
28082                                       , x_return_status => x_return_status
28083                                       , x_msg_count => x_msg_count
28084                                       , x_msg_data => x_msg_data);
28085 
28086                           IF (x_return_status <> g_ret_sts_success) THEN
28087                               --raise error
28088                               fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28089                               fnd_msg_pub.ADD;
28090                               l_progress := 'WMSINB-27320';
28091                               RAISE fnd_api.g_exc_error;
28092                           END IF;
28093 
28094                            --validate and update the attributes.
28095                            inv_serial_number_pub.validate_update_serial_att
28096                              (x_return_status     => x_return_status,
28097                               x_msg_count         => x_msg_count,
28098                               x_msg_data          => x_msg_data,
28099                               x_validation_status => l_validation_status,
28100                               p_serial_number     => l_serial_number,
28101                               p_organization_id   => l_org_id,
28102                               p_inventory_item_id => l_item_id,
28103                               p_serial_att_tbl    => l_serial_attributes_tbl,
28104                               p_validate_only     => FALSE
28105                               );
28106 
28107                            IF (l_validation_status <> 'Y'
28108                                OR x_return_status <> g_ret_sts_success) THEN
28109                               --raise error
28110                               fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28111                               fnd_msg_pub.ADD;
28112                               l_progress := 'WMSINB-27360';
28113                               RAISE fnd_api.g_exc_error;
28114                            END IF;
28115 
28116                           --UPDATE GROUP_MARK_ID TO -7937
28117                           IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
28118                              --raise error
28119                              fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28120                              fnd_msg_pub.ADD;
28121                              l_progress := 'WMSINB-27369';
28122                              RAISE fnd_api.g_exc_error;
28123                           END IF;
28124                         ELSE --IF l_serial_number_control_code = 5 THEN
28125                           --raise error
28126                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28127                           fnd_msg_pub.ADD;
28128                           l_progress := 'WMSINB-27376';
28129                           RAISE fnd_api.g_exc_error;
28130                         END IF; --IF l_serial_number_control_code = 5 THEN
28131                       END IF; --IF (l_serial_exists = 1) THEN
28132                     END IF; --IF (l_parent_txn_type <> 'RECEIVE') THEN
28133                   END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
28134                 END LOOP; -- FOR 1..L_SERIAL_QUANTITY
28135               END LOOP; --FETCH C_MSNT_LOTSERIAL INTO L_MSNT_REC;
28136 
28137               CLOSE c_msnt_lotserial;
28138 
28139               IF (l_num_msnt_recs > 0) THEN
28140                 IF l_mtlt_rec.primary_quantity <> l_tot_msnt_serial_qty THEN
28141                   --raise error
28142                   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28143                   fnd_msg_pub.ADD;
28144                   l_progress := 'WMSINB-27392';
28145                   RAISE fnd_api.g_exc_error;
28146                 END IF;
28147               ELSE
28148                 IF (l_serial_number_control_code IN (2,5)
28149                     OR (l_serial_number_control_code = 6
28150                     AND l_source_document_code IN ('RMA','REQ','INVENTORY'))) THEN
28151                   --raise error
28152                   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28153                   fnd_msg_pub.ADD;
28154                   l_progress := 'WMSINB-27399';
28155                   RAISE fnd_api.g_exc_error;
28156                 END IF;
28157               END IF;
28158             END IF; -- IF (L_SERIAL_NUMBER_CONTROL_CODE IN (2,5,6)) THEN
28159           END LOOP; --FETCH C_MTLT INTO L_MTLT_REC;
28160 
28161           CLOSE c_mtlt;
28162 
28163          /* Bug 4546519 : l_tot_mtlt_prim_qty is a computed floating point number.
28164           **  In the following condition, it is necessary to use round function for
28165           **  comparing the floating point values.
28166           */
28167 
28168           IF (l_num_mtlt_recs > 0) THEN
28169             IF (ROUND(l_tot_mtlt_prim_qty,5) <> ROUND(l_rti_primary_qty,5)) THEN
28170               -- Bug# 4225766 Compare transaction qty there can be a difference in primary qty
28171               --   if there is a lot specific conversion
28172                 IF (ROUND(l_tot_mtlt_trans_qty,5) <> ROUND(l_rti_trans_qty,5)) THEN -- Bug# 4225766
28173                   --raise error
28174                   fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28175                   fnd_msg_pub.ADD;
28176                   l_progress := 'WMSINB-27413';
28177                   RAISE fnd_api.g_exc_error;
28178                 END IF; -- Bug# 4225766
28179             END IF;
28180           ELSE
28181             IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
28182               IF (l_grand_parent_txn_type = 'DELIVER') THEN
28183                   --raise an error
28184                   l_progress := 'WMSINB-27420';
28185                   RAISE fnd_api.g_exc_error;
28186               ELSE
28187                 IF (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
28188                    --raise error;
28189                    fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28190                    fnd_msg_pub.ADD;
28191                    l_progress := 'WMSINB-27427';
28192                    RAISE fnd_api.g_exc_error;
28193                 END IF;
28194               END IF; --IF (l_grand_parent_txn_type = 'DELIVER') THEN
28195             ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
28196               IF (l_parent_txn_type <> 'DELIVER') THEN
28197                 IF (validate_rs(NULL,l_parent_transaction_id,l_dummy_lpn)) THEN
28198                   IF (lot_entered_on_parent(l_parent_transaction_id)) THEN
28199                     --raise an error
28200                     l_progress := 'WMSINB-27436';
28201                     RAISE fnd_api.g_exc_error;
28202                   END IF;
28203                 ELSE --IF (validate_rs(NULL,l_parent_transaction_id,l_dummy_lpn)) THEN
28204                   IF (l_parent_txn_type <> 'RECEIVE') THEN
28205                     IF (lot_entered_on_parent(l_grand_parent_txn_id)) THEN
28206                        --raise an error
28207                        l_progress := 'WMSINB-27443';
28208                        RAISE fnd_api.g_exc_error;
28209                     END IF;
28210                   END IF;
28211                 END IF; --IF (validate_rs(NULL,l_parent_transaction_id,l_dummy_lpn)) THEN
28212               ELSE --IF (l_parent_txn_type <> 'DELIVER') THEN
28213                 --raise an error
28214                 l_progress := 'WMSINB-27450';
28215                 RAISE fnd_api.g_exc_error;
28216               END IF; -- IF (l_parent_txn_type <> 'DELIVER') THEN
28217             END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
28218           END IF; --IF (l_num_mtlt_recs > 0) THEN
28219         ELSIF (l_serial_number_control_code IN (2,5,6)) THEN --IF (l_lot_control_code = 2) THEN
28220           IF (l_debug = 1) THEN
28221               print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROLLED: '||l_progress, 1);
28222               print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL CONTROL CODE: '||l_serial_number_control_code||' : '||l_progress, 1);
28223               print_debug('VALIDATE_LOT_SERIAL_INFO: SOURCE DOCUMENT CODE: '||l_source_document_code||' : '||l_progress, 1);
28224               l_progress := 'WMSINB-27460';
28225           END IF;
28226 
28227           L_NUM_MSNT_RECS := 0;
28228           l_tot_msnt_serial_qty := 0;
28229 
28230           OPEN C_MSNT(L_RTI_ID);
28231 
28232           LOOP
28233             FETCH C_MSNT INTO L_MSNT_REC;
28234 
28235             EXIT WHEN C_MSNT%NOTFOUND;
28236 
28237             L_NUM_MSNT_RECS := L_NUM_MSNT_RECS + 1;
28238             L_SERIAL_QUANTITY :=
28239                       INV_SERIAL_NUMBER_PUB.GET_SERIAL_DIFF(L_MSNT_REC.FM_SERIAL_NUMBER,
28240                       L_MSNT_REC.TO_SERIAL_NUMBER);
28241 
28242             l_tot_msnt_serial_qty := l_tot_msnt_serial_qty + l_serial_quantity;
28243             INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.FM_SERIAL_NUMBER, L_TEMP_PREFIX, L_FROM_SER_NUMBER);
28244                                           INV_VALIDATE.NUMBER_FROM_SEQUENCE(L_MSNT_REC.TO_SERIAL_NUMBER, L_TEMP_PREFIX, L_TO_SER_NUMBER);
28245 
28246             IF (l_debug = 1) THEN
28247               print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL QUANTITY: '||l_serial_quantity||' : '||l_progress, 1);
28248               l_progress := 'WMSINB-27485';
28249             END IF;
28250 
28251             --populate attributes table
28252             l_serial_attributes_tbl(1).column_name   := 'SERIAL_ATTRIBUTE_CATEGORY';
28253             l_serial_attributes_tbl(1).column_value  := l_msnt_rec.serial_attribute_category;
28254             l_serial_attributes_tbl(2).column_name   := 'ORIGINATION_DATE';
28255             l_serial_attributes_tbl(2).column_value  := l_msnt_rec.origination_date;
28256             l_serial_attributes_tbl(3).column_name   := 'C_ATTRIBUTE1';
28257             l_serial_attributes_tbl(3).column_value  := l_msnt_rec.c_attribute1;
28258             l_serial_attributes_tbl(4).column_name   := 'C_ATTRIBUTE2';
28259             l_serial_attributes_tbl(4).column_value  := l_msnt_rec.c_attribute2;
28260             l_serial_attributes_tbl(5).column_name   := 'C_ATTRIBUTE3';
28261             l_serial_attributes_tbl(5).column_value  := l_msnt_rec.c_attribute3;
28262             l_serial_attributes_tbl(6).column_name   := 'C_ATTRIBUTE4';
28263             l_serial_attributes_tbl(6).column_value   := l_msnt_rec.c_attribute4;
28264             l_serial_attributes_tbl(7).column_name   := 'C_ATTRIBUTE5';
28265             l_serial_attributes_tbl(7).column_value   := l_msnt_rec.c_attribute5;
28266             l_serial_attributes_tbl(8).column_name   := 'C_ATTRIBUTE6';
28267             l_serial_attributes_tbl(8).column_value   := l_msnt_rec.c_attribute6;
28268             l_serial_attributes_tbl(9).column_name   := 'C_ATTRIBUTE7';
28269             l_serial_attributes_tbl(9).column_value   := l_msnt_rec.c_attribute7;
28270             l_serial_attributes_tbl(10).column_name  := 'C_ATTRIBUTE8';
28271             l_serial_attributes_tbl(10).column_value  := l_msnt_rec.c_attribute8;
28272             l_serial_attributes_tbl(11).column_name  := 'C_ATTRIBUTE9';
28273             l_serial_attributes_tbl(11).column_value  := l_msnt_rec.c_attribute9;
28274             l_serial_attributes_tbl(12).column_name  := 'C_ATTRIBUTE10';
28275             l_serial_attributes_tbl(12).column_value  := l_msnt_rec.c_attribute10;
28276             l_serial_attributes_tbl(13).column_name  := 'C_ATTRIBUTE11';
28277             l_serial_attributes_tbl(13).column_value  := l_msnt_rec.c_attribute11;
28278             l_serial_attributes_tbl(14).column_name  := 'C_ATTRIBUTE12';
28279             l_serial_attributes_tbl(14).column_value  := l_msnt_rec.c_attribute12;
28280             l_serial_attributes_tbl(15).column_name  := 'C_ATTRIBUTE13';
28281             l_serial_attributes_tbl(15).column_value  := l_msnt_rec.c_attribute13;
28282             l_serial_attributes_tbl(16).column_name  := 'C_ATTRIBUTE14';
28283             l_serial_attributes_tbl(16).column_value  := l_msnt_rec.c_attribute14;
28284             l_serial_attributes_tbl(17).column_name  := 'C_ATTRIBUTE15';
28285             l_serial_attributes_tbl(17).column_value  := l_msnt_rec.c_attribute15;
28286             l_serial_attributes_tbl(18).column_name  := 'C_ATTRIBUTE16';
28287             l_serial_attributes_tbl(18).column_value  := l_msnt_rec.c_attribute16;
28288             l_serial_attributes_tbl(19).column_name  := 'C_ATTRIBUTE17';
28289             l_serial_attributes_tbl(19).column_value  := l_msnt_rec.c_attribute17;
28290             l_serial_attributes_tbl(20).column_name  := 'C_ATTRIBUTE18';
28291             l_serial_attributes_tbl(20).column_value  := l_msnt_rec.c_attribute18;
28292             l_serial_attributes_tbl(21).column_name  := 'C_ATTRIBUTE19';
28293             l_serial_attributes_tbl(21).column_value  := l_msnt_rec.c_attribute19;
28294             l_serial_attributes_tbl(22).column_name  := 'C_ATTRIBUTE20';
28295             l_serial_attributes_tbl(22).column_value  := l_msnt_rec.c_attribute20;
28296             l_serial_attributes_tbl(23).column_name  := 'D_ATTRIBUTE1';
28297             l_serial_attributes_tbl(23).column_value  := l_msnt_rec.d_attribute1;
28298             l_serial_attributes_tbl(24).column_name  := 'D_ATTRIBUTE2';
28299             l_serial_attributes_tbl(24).column_value  := l_msnt_rec.d_attribute2;
28300             l_serial_attributes_tbl(25).column_name  := 'D_ATTRIBUTE3';
28301             l_serial_attributes_tbl(25).column_value  := l_msnt_rec.d_attribute3;
28302             l_serial_attributes_tbl(26).column_name  := 'D_ATTRIBUTE4';
28303             l_serial_attributes_tbl(26).column_value  := l_msnt_rec.d_attribute4;
28304             l_serial_attributes_tbl(27).column_name  := 'D_ATTRIBUTE5';
28305             l_serial_attributes_tbl(27).column_value  := l_msnt_rec.d_attribute5;
28306             l_serial_attributes_tbl(28).column_name  := 'D_ATTRIBUTE6';
28307             l_serial_attributes_tbl(28).column_value  := l_msnt_rec.d_attribute6;
28308             l_serial_attributes_tbl(29).column_name  := 'D_ATTRIBUTE7';
28309             l_serial_attributes_tbl(29).column_value  := l_msnt_rec.d_attribute7;
28310             l_serial_attributes_tbl(30).column_name  := 'D_ATTRIBUTE8';
28311             l_serial_attributes_tbl(30).column_value  := l_msnt_rec.d_attribute8;
28312             l_serial_attributes_tbl(31).column_name  := 'D_ATTRIBUTE9';
28313             l_serial_attributes_tbl(31).column_value  := l_msnt_rec.d_attribute9;
28314             l_serial_attributes_tbl(32).column_name  := 'D_ATTRIBUTE10';
28315             l_serial_attributes_tbl(32).column_value  := l_msnt_rec.d_attribute10;
28316             l_serial_attributes_tbl(33).column_name  := 'N_ATTRIBUTE1';
28317             l_serial_attributes_tbl(33).column_value  := l_msnt_rec.n_attribute1;
28318             l_serial_attributes_tbl(34).column_name  := 'N_ATTRIBUTE2';
28319             l_serial_attributes_tbl(34).column_value  := l_msnt_rec.n_attribute2;
28320             l_serial_attributes_tbl(35).column_name  := 'N_ATTRIBUTE3';
28321             l_serial_attributes_tbl(35).column_value  := l_msnt_rec.n_attribute3;
28322             l_serial_attributes_tbl(36).column_name  := 'N_ATTRIBUTE4';
28323             l_serial_attributes_tbl(36).column_value  := l_msnt_rec.n_attribute4;
28324             l_serial_attributes_tbl(37).column_name  := 'N_ATTRIBUTE5';
28325             l_serial_attributes_tbl(37).column_value := l_msnt_rec.n_attribute5;
28326             l_serial_attributes_tbl(38).column_name  := 'N_ATTRIBUTE6';
28327             l_serial_attributes_tbl(38).column_value := l_msnt_rec.n_attribute6;
28328             l_serial_attributes_tbl(39).column_name  := 'N_ATTRIBUTE7';
28329             l_serial_attributes_tbl(39).column_value := l_msnt_rec.n_attribute7;
28330             l_serial_attributes_tbl(40).column_name  := 'N_ATTRIBUTE8';
28331             l_serial_attributes_tbl(40).column_value := l_msnt_rec.n_attribute8;
28332             l_serial_attributes_tbl(41).column_name  := 'N_ATTRIBUTE9';
28333             l_serial_attributes_tbl(41).column_value := l_msnt_rec.n_attribute9;
28334             l_serial_attributes_tbl(42).column_name  := 'N_ATTRIBUTE10';
28335             l_serial_attributes_tbl(42).column_value := l_msnt_rec.n_attribute10;
28336             l_serial_attributes_tbl(43).column_name  := 'STATUS_ID';
28337             l_serial_attributes_tbl(43).column_value := l_msnt_rec.status_id;
28338             l_serial_attributes_tbl(44).column_name  := 'TERRITORY_CODE';
28339             l_serial_attributes_tbl(44).column_value := l_msnt_rec.territory_code;
28340             l_serial_attributes_tbl(45).column_name   := 'ATTRIBUTE_CATEGORY';
28341             l_serial_attributes_tbl(45).column_value  := l_msnt_rec.attribute_category;
28342             l_serial_attributes_tbl(46).column_name   := 'ATTRIBUTE1';
28343             l_serial_attributes_tbl(46).column_value  := l_msnt_rec.attribute1;
28344             l_serial_attributes_tbl(47).column_name   := 'ATTRIBUTE2';
28345             l_serial_attributes_tbl(47).column_value  := l_msnt_rec.attribute2;
28346             l_serial_attributes_tbl(48).column_name   := 'ATTRIBUTE3';
28347             l_serial_attributes_tbl(48).column_value  := l_msnt_rec.attribute3;
28348             l_serial_attributes_tbl(49).column_name   := 'ATTRIBUTE4';
28349             l_serial_attributes_tbl(49).column_value   := l_msnt_rec.attribute4;
28350             l_serial_attributes_tbl(50).column_name   := 'ATTRIBUTE5';
28351             l_serial_attributes_tbl(50).column_value   := l_msnt_rec.attribute5;
28352             l_serial_attributes_tbl(51).column_name   := 'ATTRIBUTE6';
28353             l_serial_attributes_tbl(51).column_value   := l_msnt_rec.attribute6;
28354             l_serial_attributes_tbl(52).column_name   := 'ATTRIBUTE7';
28355             l_serial_attributes_tbl(52).column_value   := l_msnt_rec.attribute7;
28356             l_serial_attributes_tbl(53).column_name  := 'ATTRIBUTE8';
28357             l_serial_attributes_tbl(53).column_value  := l_msnt_rec.attribute8;
28358             l_serial_attributes_tbl(54).column_name  := 'ATTRIBUTE9';
28359             l_serial_attributes_tbl(54).column_value  := l_msnt_rec.attribute9;
28360             l_serial_attributes_tbl(55).column_name  := 'ATTRIBUTE10';
28361             l_serial_attributes_tbl(55).column_value  := l_msnt_rec.attribute10;
28362             l_serial_attributes_tbl(56).column_name  := 'ATTRIBUTE11';
28363             l_serial_attributes_tbl(56).column_value  := l_msnt_rec.attribute11;
28364             l_serial_attributes_tbl(57).column_name  := 'ATTRIBUTE12';
28365             l_serial_attributes_tbl(57).column_value  := l_msnt_rec.attribute12;
28366             l_serial_attributes_tbl(58).column_name  := 'ATTRIBUTE13';
28367             l_serial_attributes_tbl(58).column_value  := l_msnt_rec.attribute13;
28368             l_serial_attributes_tbl(59).column_name  := 'ATTRIBUTE14';
28369             l_serial_attributes_tbl(59).column_value  := l_msnt_rec.attribute14;
28370             l_serial_attributes_tbl(60).column_name  := 'ATTRIBUTE15';
28371             l_serial_attributes_tbl(60).column_value  := l_msnt_rec.attribute15;
28372 
28373             --Validate the serials
28374             FOR SERIALQTY IN 1..L_SERIAL_QUANTITY LOOP
28375 
28376               l_progress := 'WMSINB-27491';
28377 
28378               L_CUR_NUMBER := L_FROM_SER_NUMBER+SERIALQTY -1;
28379               if L_FROM_SER_NUMBER = -1 and  L_TO_SER_NUMBER = -1 then
28380                 L_SERIAL_NUMBER  := L_MSNT_REC.fm_serial_number;
28381               else
28382                   L_SERIAL_NUMBER := SUBSTR(L_MSNT_REC.FM_SERIAL_NUMBER, 1,
28383                                       LENGTH(L_MSNT_REC.FM_SERIAL_NUMBER) -
28384                                       LENGTH(L_CUR_NUMBER))
28385                                         ||L_CUR_NUMBER;
28386               End if;
28387 
28388               l_progress := 'WMSINB-27499';
28389               BEGIN
28390                 SELECT CURRENT_ORGANIZATION_ID
28391                   , current_status
28392                   , lot_number
28393                   , Decode(lpn_id,0,NULL,lpn_id)
28394                   , inspection_status
28395                   , group_mark_id
28396                   INTO L_CURR_ORG_ID
28397                   , l_curr_status
28398                   , l_curr_lot_num
28399                   , l_curr_lpn_id
28400                   , l_inspection_status
28401                   , l_group_mark_id
28402                   FROM MTL_SERIAL_NUMBERS
28403                   WHERE SERIAL_NUMBER = l_serial_number
28404                   AND inventory_item_id = l_item_id;
28405 
28406                 l_serial_exists := 1;
28407                 l_progress := 'WMSINB-27519';
28408               EXCEPTION
28409                 WHEN no_data_found THEN
28410                    l_serial_exists := 0;
28411                    l_progress := 'WMSINB-27523';
28412               END;
28413 
28414               IF (l_debug = 1) THEN
28415                   print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL EXISTS: '||l_serial_exists||' : '||l_progress, 1);
28416                   print_debug('VALIDATE_LOT_SERIAL_INFO: SERIAL NUMBER: '||l_serial_number||' : '||l_progress, 1);
28417                   print_debug('VALIDATE_LOT_SERIAL_INFO: CURR STATUS: '||l_curr_status||' : '||l_progress, 1);
28418                   print_debug('VALIDATE_LOT_SERIAL_INFO: CURR ORG ID: '||l_curr_org_id||' : '||l_progress, 1);
28419                   print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LPN ID: '||l_curr_lpn_id||' : '||l_progress, 1);
28420                   print_debug('VALIDATE_LOT_SERIAL_INFO: CURR LOT NUM: '||l_curr_lot_num||' : '||l_progress, 1);
28421                   print_debug('VALIDATE_LOT_SERIAL_INFO: INSPECT STS: '||l_inspection_status||' : '||l_progress, 1);
28422                   print_debug('VALIDATE_LOT_SERIAL_INFO: GROUP MARK ID: '||l_group_mark_id||' : '||l_progress, 1);
28423                   print_debug('VALIDATE_LOT_SERIAL_INFO: RESTRICT RCPT SER: '||l_restrict_rcpt_ser||' : '||l_progress, 1);
28424                   l_progress := 'WMSINB-27536';
28425               END IF;
28426 
28427               IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
28428                 IF (l_grand_parent_txn_type <> 'DELIVER') THEN
28429                   IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
28430                     --raise an error
28431                     RAISE fnd_api.g_exc_error;
28432                   ELSE --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
28433                     BEGIN
28434                       SELECT '1'
28435                       INTO L_DUMMY
28436                       FROM RCV_SERIALS_SUPPLY
28437                       WHERE TRANSACTION_ID = l_grand_parent_txn_id
28438                       AND SERIAL_NUM = L_SERIAL_NUMBER;
28439 
28440                       IF (l_curr_status <> 7) THEN
28441                          --raise error
28442                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28443                          fnd_msg_pub.ADD;
28444                          l_progress := 'WMSINB-27557';
28445                          RAISE fnd_api.g_exc_error;
28446                       END IF;
28447 
28448                       --Validate serial/group_mark_id to prevent
28449                       --entering of duplicate serials
28450 
28451                       IF (Nvl(l_group_mark_id, -99) = -7937) THEN
28452                          --raise error
28453                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28454                          fnd_msg_pub.ADD;
28455                          l_progress := 'WMSINB-27568';
28456                          RAISE fnd_api.g_exc_error;
28457                       END IF;
28458 
28459                       --UPDATE GROUP_MARK_ID TO -7937
28460                       IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
28461                          --raise error
28462                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28463                          fnd_msg_pub.ADD;
28464                          l_progress := 'WMSINB-27577';
28465                          RAISE fnd_api.g_exc_error;
28466                       END IF;
28467                     EXCEPTION
28468                       WHEN NO_DATA_FOUND THEN
28469                          -- RAISE ERROR
28470                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28471                          fnd_msg_pub.ADD;
28472                          l_progress := 'WMSINB-27585';
28473                          RAISE fnd_api.g_exc_error;
28474                     END;
28475                   END IF; --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
28476                 ELSE --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
28477                   IF l_curr_org_id <> l_org_id THEN
28478                      --raise error
28479                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28480                      fnd_msg_pub.ADD;
28481                      l_progress := 'WMSINB-27594';
28482                      RAISE fnd_api.g_exc_error;
28483                   ELSE
28484                      IF (l_curr_lot_num IS NOT NULL) THEN
28485                         --raise error
28486                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28487                         fnd_msg_pub.ADD;
28488                         l_progress := 'WMSINB-27601';
28489                         RAISE fnd_api.g_exc_error;
28490                      END IF;
28491                   END IF;
28492 
28493                   IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
28494                      IF l_curr_status NOT IN (1,6) THEN
28495                         --raise error
28496                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28497                         fnd_msg_pub.ADD;
28498                         l_progress := 'WMSINB-27611';
28499                         RAISE fnd_api.g_exc_error;
28500                      END IF;
28501                   ELSE --IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
28502                      IF (l_curr_status <> 3) THEN
28503                         --raise error
28504                         fnd_message.set_name('INV','INV_FAIL_VALIDATE_SERIAL');
28505                         fnd_msg_pub.ADD;
28506                         l_progress := 'WMSINB-27619';
28507                         RAISE fnd_api.g_exc_error;
28508                      END IF;
28509                   END IF; --IF (l_source_document_code = 'RMA' AND l_serial_number_control_code = 6) THEN
28510 
28511                   IF (Nvl(l_group_mark_id, -99) = -7937) THEN
28512                      --raise error
28513                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28514                      fnd_msg_pub.ADD;
28515                      l_progress := 'WMSINB-27628';
28516                      RAISE fnd_api.g_exc_error;
28517                   END IF;
28518 
28519                   IF (Nvl(l_curr_status, 1) in (1,6)) THEN
28520                      --validate and update the attributes.
28521                      inv_serial_number_pub.validate_update_serial_att
28522                        (x_return_status     => x_return_status,
28523                         x_msg_count         => x_msg_count,
28524                         x_msg_data          => x_msg_data,
28525                         x_validation_status => l_validation_status,
28526                         p_serial_number     => l_serial_number,
28527                         p_organization_id   => l_org_id,
28528                         p_inventory_item_id => l_item_id,
28529                         p_serial_att_tbl    => l_serial_attributes_tbl,
28530                         p_validate_only     => FALSE
28531                         );
28532 
28533                      IF (l_validation_status <> 'Y'
28534                          OR x_return_status <> g_ret_sts_success) THEN
28535                         --raise error
28536                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28537                         fnd_msg_pub.ADD;
28538                         l_progress := 'WMSINB-27634';
28539                         RAISE fnd_api.g_exc_error;
28540                      END IF;
28541                   END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
28542 
28543                   --UPDATE GROUP_MARK_ID TO -7937
28544                   IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
28545                      --raise error
28546                      fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28547                      fnd_msg_pub.ADD;
28548                      l_progress := 'WMSINB-27637';
28549                      RAISE fnd_api.g_exc_error;
28550                   END IF;
28551                 END IF; --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
28552               ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
28553                 IF (l_parent_txn_type <> 'RECEIVE') THEN
28554                   IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
28555                     BEGIN
28556                       SELECT '1'
28557                         INTO L_DUMMY
28558                         FROM RCV_SERIALS_SUPPLY
28559                         WHERE TRANSACTION_ID = l_grand_parent_txn_id
28560                         AND SERIAL_NUM = L_SERIAL_NUMBER;
28561 
28562                       IF (l_curr_status <> 7) THEN
28563                          --raise error
28564                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28565                          fnd_msg_pub.ADD;
28566                          l_progress := 'WMSINB-27655';
28567                          RAISE fnd_api.g_exc_error;
28568                       END IF;
28569 
28570                       --Validate serial/group_mark_id to prevent
28571                       --entering of duplicate serials
28572 
28573                       IF (Nvl(l_group_mark_id, -99) = -7937) THEN
28574                          --raise error
28575                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28576                          fnd_msg_pub.ADD;
28577                          l_progress := 'WMSINB-27666';
28578                          RAISE fnd_api.g_exc_error;
28579                       END IF;
28580 
28581                       --UPDATE GROUP_MARK_ID TO -7937
28582                       IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
28583                          --raise error
28584                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28585                          fnd_msg_pub.ADD;
28586                          l_progress := 'WMSINB-27675';
28587                          RAISE fnd_api.g_exc_error;
28588                       END IF;
28589                     EXCEPTION
28590                       WHEN NO_DATA_FOUND THEN
28591                          -- RAISE ERROR
28592                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28593                          fnd_msg_pub.ADD;
28594                          l_progress := 'WMSINB-27683';
28595                          RAISE fnd_api.g_exc_error;
28596                     END;
28597                   ELSE --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
28598                     IF (l_serial_exists = 1) THEN
28599                       IF l_curr_org_id <> l_org_id THEN
28600                          --raise error
28601                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28602                          fnd_msg_pub.ADD;
28603                          l_progress := 'WMSINB-27692';
28604                          RAISE fnd_api.g_exc_error;
28605                       ELSE
28606                         IF (l_curr_lot_num IS NOT NULL) THEN
28607                           --raise error
28608                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28609                           fnd_msg_pub.ADD;
28610                           l_progress := 'WMSINB-27699';
28611                           RAISE fnd_api.g_exc_error;
28612                         END IF;
28613                       END IF;
28614 
28615                       IF l_curr_status NOT IN (1,4,6) THEN -- Bug 6177465
28616                          --raise error
28617                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28618                          fnd_msg_pub.ADD;
28619                          l_progress := 'WMSINB-27708';
28620                          RAISE fnd_api.g_exc_error;
28621                       END IF;
28622 
28623                       IF (Nvl(l_group_mark_id, -99) = -7937) THEN
28624                          --raise error
28625                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28626                          fnd_msg_pub.ADD;
28627                          l_progress := 'WMSINB-27716';
28628                          RAISE fnd_api.g_exc_error;
28629                       END IF;
28630 
28631                       IF (Nvl(l_curr_status, 1) in (1,6)) THEN
28632                          --validate and update the attributes.
28633                          inv_serial_number_pub.validate_update_serial_att
28634                            (x_return_status     => x_return_status,
28635                             x_msg_count         => x_msg_count,
28636                             x_msg_data          => x_msg_data,
28637                             x_validation_status => l_validation_status,
28638                             p_serial_number     => l_serial_number,
28639                             p_organization_id   => l_org_id,
28640                             p_inventory_item_id => l_item_id,
28641                             p_serial_att_tbl    => l_serial_attributes_tbl,
28642                             p_validate_only     => FALSE
28643                             );
28644 
28645                          IF (l_validation_status <> 'Y'
28646                              OR x_return_status <> g_ret_sts_success) THEN
28647                             --raise error
28648                             fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28649                             fnd_msg_pub.ADD;
28650                             l_progress := 'WMSINB-27721';
28651                             RAISE fnd_api.g_exc_error;
28652                          END IF;
28653                       END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
28654 
28655                       --UPDATE GROUP_MARK_ID TO -7937
28656                       IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
28657                        --raise error
28658                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28659                            fnd_msg_pub.ADD;
28660                            l_progress := 'WMSINB-27725';
28661                            RAISE fnd_api.g_exc_error;
28662                       END IF;
28663                     ELSE --IF (l_serial_exists = 1) THEN
28664                       IF l_serial_number_control_code = 5 THEN
28665                         --PERFORM SERIAL VALIDATION FOR NEW SERIAL
28666                         --(INCLUDING ATT VALIDATION)
28667                         --CREATE MSN
28668                         IF (l_transaction_type = 'CORRECT') THEN
28669                           l_transaction_action_id := 29;
28670                         ELSE
28671                           l_transaction_action_id := 1;
28672                         END IF;
28673 
28674                         inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
28675                                      , p_inventory_item_id => l_item_id
28676                                      , p_organization_id => l_org_id
28677                                      , p_from_serial_number => l_serial_number
28678                                      , p_to_serial_number => l_serial_number
28679                                      , p_initialization_date => SYSDATE
28680                                      , p_completion_date => NULL
28681                                      , p_ship_date => NULL
28682                                      , p_revision => l_item_revision
28683                                      , p_lot_number => NULL
28684                                      , p_current_locator_id => l_loc_id
28685                                      , p_subinventory_code => l_sub_code
28686                                      , p_trx_src_id => NULL
28687                                      , p_unit_vendor_id => NULL
28688                                      , p_vendor_lot_number => NULL
28689                                      , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
28690                                      , p_receipt_issue_type => NULL
28691                                      , p_txn_src_id => NULL
28692                                      , p_txn_src_name => NULL
28693                                      , p_txn_src_type_id => NULL
28694                                      , p_transaction_id => NULL
28695                                      , p_current_status => 1
28696                                      , p_parent_item_id => NULL
28697                                      , p_parent_serial_number => NULL
28698                                      , p_cost_group_id => NULL
28699                                      , p_transaction_action_id => l_transaction_action_id
28700                                      , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
28701                                      , p_status_id => NULL
28702                                      , p_inspection_status => NULL
28703                                      , x_object_id => l_object_id
28704                                      , x_return_status => x_return_status
28705                                      , x_msg_count => x_msg_count
28706                                      , x_msg_data => x_msg_data);
28707 
28708                         IF (x_return_status <> g_ret_sts_success) THEN
28709                           --raise error
28710                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28711                           fnd_msg_pub.ADD;
28712                           l_progress := 'WMSINB-27730';
28713                           RAISE fnd_api.g_exc_error;
28714                         END IF;
28715 
28716                         --validate and update the attributes.
28717                         inv_serial_number_pub.validate_update_serial_att
28718                            (x_return_status     => x_return_status,
28719                             x_msg_count         => x_msg_count,
28720                             x_msg_data          => x_msg_data,
28721                             x_validation_status => l_validation_status,
28722                             p_serial_number     => l_serial_number,
28723                             p_organization_id   => l_org_id,
28724                             p_inventory_item_id => l_item_id,
28725                             p_serial_att_tbl    => l_serial_attributes_tbl,
28726                             p_validate_only     => FALSE
28727                             );
28728 
28729                         IF (l_validation_status <> 'Y'
28730                            OR x_return_status <> g_ret_sts_success) THEN
28731                           --raise error
28732                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28733                           fnd_msg_pub.ADD;
28734                           l_progress := 'WMSINB-27770';
28735                           RAISE fnd_api.g_exc_error;
28736                         END IF;
28737 
28738                         --UPDATE GROUP_MARK_ID TO -7937
28739                         IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
28740                           --raise error
28741                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28742                           fnd_msg_pub.ADD;
28743                           l_progress := 'WMSINB-27778';
28744                           RAISE fnd_api.g_exc_error;
28745                         END IF;
28746                       ELSE --IF l_serial_number_control_code = 5 THEN
28747                         --raise error
28748                         fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28749                         fnd_msg_pub.ADD;
28750                         l_progress := 'WMSINB-27785';
28751                         RAISE fnd_api.g_exc_error;
28752                       END IF; --IF l_serial_number_control_code = 5 THEN
28753                     END IF; --IF (l_serial_exists = 1) THEN
28754                   END IF; --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
28755                 ELSE --IF (l_parent_txn_type <> 'RECEIVE') THEN
28756                   IF (l_serial_exists = 1) THEN
28757                     IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
28758                       -- CHECK TO SEE IF THE ITEM IS SERIAL
28759                       -- CONTROLLED IN SOURCE ORG
28760 
28761                       GET_SERIAL_LOT_CTRL_IN_SRC_ORG
28762                          (L_SHIPMENT_LINE_ID, L_ORG_ID,
28763                           L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
28764                           l_from_org_rev_ctrl, X_RETURN_STATUS,
28765                           X_MSG_COUNT, X_MSG_DATA);
28766 
28767                       IF ((L_FROM_ORG_SER_CRTL IN (2,5,6) AND l_source_document_code = 'REQ')
28768                            OR (l_from_org_ser_crtl IN (2,5) AND l_source_document_code = 'INVENTORY')
28769                          ) THEN
28770                         IF l_curr_org_id <> l_from_org_id THEN
28771                            --raise error
28772                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28773                            fnd_msg_pub.ADD;
28774                            l_progress := 'WMSINB-27806';
28775                            RAISE fnd_api.g_exc_error;
28776                         ELSE --IF l_curr_org_id <> l_from_org_id THEN
28777                           IF (l_curr_lot_num IS NOT NULL) THEN
28778                             --raise error
28779                             fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28780                             fnd_msg_pub.ADD;
28781                             l_progress := 'WMSINB-27813';
28782                             RAISE fnd_api.g_exc_error;
28783                           END IF;
28784                         END IF; --IF l_curr_org_id <> l_from_org_id THEN
28785 
28786                         BEGIN
28787                            SELECT '1'
28788                              INTO L_DUMMY
28789                              FROM rcv_serials_supply rss
28790                              , rcv_shipment_lines rsl
28791                              WHERE rss.SHIPMENT_LINE_ID = rsl.SHIPMENT_LINE_ID
28792                              AND rsl.shipment_header_id = l_shipment_header_id
28793                              AND rsl.item_id = l_item_id
28794                              AND rss.SUPPLY_TYPE_CODE = 'SHIPMENT'
28795                              AND rss.serial_num = l_serial_number;
28796 
28797                           IF L_CURR_STATUS <> 5 THEN
28798                             -- RAISE AN ERROR
28799                             fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28800                             fnd_msg_pub.ADD;
28801                             l_progress := 'WMSINB-27830';
28802                             RAISE fnd_api.g_exc_error;
28803                           END IF;
28804 
28805                         EXCEPTION
28806                           WHEN NO_DATA_FOUND THEN
28807                             -- RAISE AN ERROR
28808                             fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28809                             fnd_msg_pub.ADD;
28810                             l_progress := 'WMSINB-27839';
28811                             RAISE fnd_api.g_exc_error;
28812                         END;
28813                       ELSE --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
28814                         IF l_curr_org_id <> l_org_id THEN
28815                            --raise error
28816                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28817                            fnd_msg_pub.ADD;
28818                            l_progress := 'WMSINB-27847';
28819                            RAISE fnd_api.g_exc_error;
28820                         ELSE
28821                           IF (l_curr_lot_num IS NOT NULL) THEN
28822                             --raise error
28823                             fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28824                             fnd_msg_pub.ADD;
28825                             l_progress := 'WMSINB-27854';
28826                             RAISE fnd_api.g_exc_error;
28827                           END IF;
28828                         END IF;
28829 
28830                         IF l_curr_status NOT IN (1,6) THEN
28831                            --raise error
28832                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28833                            fnd_msg_pub.ADD;
28834                            l_progress := 'WMSINB-27863';
28835                            RAISE fnd_api.g_exc_error;
28836                         END IF;
28837 
28838                         IF (Nvl(l_group_mark_id, -99) = -7937) THEN
28839                            --raise error
28840                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28841                            fnd_msg_pub.ADD;
28842                            l_progress := 'WMSINB-27871';
28843                            RAISE fnd_api.g_exc_error;
28844                         END IF;
28845 
28846                         IF (Nvl(l_curr_status, 1) in (1,6)) THEN
28847                            --validate and update the attributes.
28848                            inv_serial_number_pub.validate_update_serial_att
28849                              (x_return_status     => x_return_status,
28850                               x_msg_count         => x_msg_count,
28851                               x_msg_data          => x_msg_data,
28852                               x_validation_status => l_validation_status,
28853                               p_serial_number     => l_serial_number,
28854                               p_organization_id   => l_org_id,
28855                               p_inventory_item_id => l_item_id,
28856                               p_serial_att_tbl    => l_serial_attributes_tbl,
28857                               p_validate_only     => FALSE
28858                               );
28859 
28860                            IF (l_validation_status <> 'Y'
28861                                OR x_return_status <> g_ret_sts_success) THEN
28862                               --raise error
28863                               fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28864                               fnd_msg_pub.ADD;
28865                               l_progress := 'WMSINB-27876';
28866                               RAISE fnd_api.g_exc_error;
28867                            END IF;
28868                         END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
28869 
28870                         --UPDATE GROUP_MARK_ID TO -7937
28871                         IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
28872                            --raise error
28873                            fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28874                            fnd_msg_pub.ADD;
28875                            l_progress := 'WMSINB-27880';
28876                            RAISE fnd_api.g_exc_error;
28877                         END IF;
28878                       END IF; --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
28879                     ELSE --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
28880                       IF l_curr_org_id <> l_org_id THEN
28881                          --raise error
28882                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28883                          fnd_msg_pub.ADD;
28884                          l_progress := 'WMSINB-27889';
28885                          RAISE fnd_api.g_exc_error;
28886                       ELSE
28887                         IF (l_curr_lot_num IS NOT NULL) THEN
28888                           --raise error
28889                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28890                           fnd_msg_pub.ADD;
28891                           l_progress := 'WMSINB-27896';
28892                           RAISE fnd_api.g_exc_error;
28893                         END IF;
28894                       END IF;
28895 
28896                       IF l_curr_status NOT IN (1,4,6) THEN--Bug: 6450814
28897                          --raise error
28898                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28899                          fnd_msg_pub.ADD;
28900                          l_progress := 'WMSINB-27905';
28901                          RAISE fnd_api.g_exc_error;
28902                       END IF;
28903 
28904                       IF (Nvl(l_group_mark_id, -99) = -7937) THEN
28905                          --raise error
28906                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28907                          fnd_msg_pub.ADD;
28908                          l_progress := 'WMSINB-27913';
28909                          RAISE fnd_api.g_exc_error;
28910                       END IF;
28911 
28912                       IF (Nvl(l_curr_status, 1) in (1,6)) THEN
28913                          --validate and update the attributes.
28914                          inv_serial_number_pub.validate_update_serial_att
28915                            (x_return_status     => x_return_status,
28916                             x_msg_count         => x_msg_count,
28917                             x_msg_data          => x_msg_data,
28918                             x_validation_status => l_validation_status,
28919                             p_serial_number     => l_serial_number,
28920                             p_organization_id   => l_org_id,
28921                             p_inventory_item_id => l_item_id,
28922                             p_serial_att_tbl    => l_serial_attributes_tbl,
28923                             p_validate_only     => FALSE
28924                             );
28925 
28926                          IF (l_validation_status <> 'Y'
28927                              OR x_return_status <> g_ret_sts_success) THEN
28928                             --raise error
28929                             fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28930                             fnd_msg_pub.ADD;
28931                             l_progress := 'WMSINB-27918';
28932                             RAISE fnd_api.g_exc_error;
28933                          END IF;
28934                       END IF; --IF (Nvl(l_curr_status, 1) = 1) THEN
28935 
28936                       --UPDATE GROUP_MARK_ID TO -7937
28937                       IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
28938                          --raise error
28939                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28940                          fnd_msg_pub.ADD;
28941                          l_progress := 'WMSINB-27922';
28942                          RAISE fnd_api.g_exc_error;
28943                       END IF;
28944                     END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
28945                   ELSE --IF (l_serial_exists = 1) THEN
28946                     IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
28947                         -- CHECK TO SEE IF THE ITEM IS SERIAL
28948                         -- CONTROLLED IN SOURCE ORG
28949 
28950                         GET_SERIAL_LOT_CTRL_IN_SRC_ORG
28951                           (L_SHIPMENT_LINE_ID, L_ORG_ID,
28952                            L_FROM_ORG_SER_CRTL, L_FROM_ORG_LOT_CTRL,
28953                            l_from_org_rev_ctrl, X_RETURN_STATUS,
28954                            X_MSG_COUNT, X_MSG_DATA);
28955 
28956                       IF ((L_FROM_ORG_SER_CRTL IN (2,5,6)
28957                             AND l_source_document_code = 'REQ')
28958                           OR (l_from_org_ser_crtl IN (2,5)
28959                               AND l_source_document_code = 'INVENTORY')
28960                          ) THEN
28961                          --raise error
28962                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
28963                          fnd_msg_pub.ADD;
28964                          l_progress := 'WMSINB-27940';
28965                          RAISE fnd_api.g_exc_error;
28966                       END IF; --IF (L_FROM_ORG_SER_CRTL IN (2,5,6)) THEN
28967                     END IF; --IF (L_SOURCE_DOCUMENT_CODE IN ('INVENTORY','REQ')) THEN
28968 
28969                     IF l_serial_number_control_code = 5 THEN
28970                       --PERFORM SERIAL VALIDATION FOR NEW SERIAL
28971                       --(INCLUDING ATT VALIDATION)
28972                       --CREATE MSN
28973                       IF (l_transaction_type = 'CORRECT') THEN
28974                         l_transaction_action_id := 29;
28975                       ELSE
28976                         l_transaction_action_id := 1;
28977                       END IF;
28978 
28979                       inv_serial_number_pub.insert_range_serial(p_api_version => 1.0
28980                             , p_inventory_item_id => l_item_id
28981                             , p_organization_id => l_org_id
28982                             , p_from_serial_number => l_serial_number
28983                             , p_to_serial_number => l_serial_number
28984                             , p_initialization_date => SYSDATE
28985                             , p_completion_date => NULL
28986                             , p_ship_date => NULL
28987                             , p_revision => l_item_revision
28988                             , p_lot_number => NULL
28989                             , p_current_locator_id => l_loc_id
28990                             , p_subinventory_code => l_sub_code
28991                             , p_trx_src_id => NULL
28992                             , p_unit_vendor_id => NULL
28993                             , p_vendor_lot_number => NULL
28994                             , p_vendor_serial_number => l_msnt_rec.vendor_serial_number
28995                             , p_receipt_issue_type => NULL
28996                             , p_txn_src_id => NULL
28997                             , p_txn_src_name => NULL
28998                             , p_txn_src_type_id => NULL
28999                             , p_transaction_id => NULL
29000                             , p_current_status => 1
29001                             , p_parent_item_id => NULL
29002                             , p_parent_serial_number => NULL
29003                             , p_cost_group_id => NULL
29004                             , p_transaction_action_id => l_transaction_action_id
29005                             , p_transaction_temp_id => l_msnt_rec.transaction_temp_id
29006                             , p_status_id => NULL
29007                             , p_inspection_status => NULL
29008                             , x_object_id => l_object_id
29009                             , x_return_status => x_return_status
29010                             , x_msg_count => x_msg_count
29011                             , x_msg_data => x_msg_data);
29012 
29013                       IF (x_return_status <> g_ret_sts_success) THEN
29014                           --raise error
29015                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
29016                           fnd_msg_pub.ADD;
29017                           l_progress := 'WMSINB-27950';
29018                           RAISE fnd_api.g_exc_error;
29019                       END IF;
29020 
29021                       --validate and update the attributes.
29022                       inv_serial_number_pub.validate_update_serial_att
29023                          (x_return_status     => x_return_status,
29024                           x_msg_count         => x_msg_count,
29025                           x_msg_data          => x_msg_data,
29026                           x_validation_status => l_validation_status,
29027                           p_serial_number     => l_serial_number,
29028                           p_organization_id   => l_org_id,
29029                           p_inventory_item_id => l_item_id,
29030                           p_serial_att_tbl    => l_serial_attributes_tbl,
29031                           p_validate_only     => FALSE
29032                           );
29033 
29034                       IF (l_validation_status <> 'Y'
29035                            OR x_return_status <> g_ret_sts_success) THEN
29036                           --raise error
29037                           fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
29038                           fnd_msg_pub.ADD;
29039                           l_progress := 'WMSINB-27985';
29040                           RAISE fnd_api.g_exc_error;
29041                       END IF;
29042 
29043                       --UPDATE GROUP_MARK_ID TO -7937
29044                       IF NOT (update_group_mark_id(l_item_id,l_serial_number)) THEN
29045                          --raise error
29046                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
29047                          fnd_msg_pub.ADD;
29048                          l_progress := 'WMSINB-27994';
29049                          RAISE fnd_api.g_exc_error;
29050                       END IF;
29051                     ELSE --IF l_serial_number_control_code = 5 THEN
29052                       --raise error
29053                       fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
29054                       fnd_msg_pub.ADD;
29055                       l_progress := 'WMSINB-28001';
29056                       RAISE fnd_api.g_exc_error;
29057                     END IF; --IF l_serial_number_control_code = 5 THEN
29058                   END IF; --IF (l_serial_exists = 1) THEN
29059                 END IF; --IF (l_parent_txn_type <> 'RECEIVE') THEN
29060               END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
29061             END LOOP; -- FOR 1..L_SERIAL_QUANTITY
29062           END LOOP; --FETCH C_MSNT INTO L_MSNT_REC;
29063 
29064           CLOSE c_msnt;
29065 
29066           IF (l_num_msnt_recs > 0) THEN
29067             IF l_mtlt_rec.primary_quantity <> l_tot_msnt_serial_qty THEN
29068                --raise error
29069                fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
29070                fnd_msg_pub.ADD;
29071                l_progress := 'WMSINB-28017';
29072                RAISE fnd_api.g_exc_error;
29073             END IF;
29074           ELSE --IF (l_num_msnt_recs > 0) THEN
29075             IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
29076               IF (l_grand_parent_txn_type <> 'DELIVER') THEN
29077                 IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
29078                    --raise an error
29079                    fnd_message.set_name('INV' , 'INV_FAIL_VALIDATE_SERIAL');
29080                    fnd_msg_pub.ADD;
29081                    l_progress := 'WMSINB-28027';
29082                    RAISE fnd_api.g_exc_error;
29083                 END IF; --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
29084               ELSE --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
29085                 --raise an error
29086                 fnd_message.set_name('INV' , 'INV_FAIL_VALIDATE_SERIAL');
29087                 fnd_msg_pub.ADD;
29088                 l_progress := 'WMSINB-28034';
29089                 RAISE fnd_api.g_exc_error;
29090               END IF; --IF (l_grand_parent_txn_type <> 'DELIVER') THEN
29091             ELSE --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
29092               IF (l_parent_txn_type <> 'DELIVER') THEN
29093                 IF (validate_rs(NULL,l_parent_transaction_id,l_dummy_lpn)) THEN
29094                   IF (serial_entered_on_parent(l_parent_transaction_id)) THEN
29095                     --raise an error
29096                     fnd_message.set_name('INV' , 'INV_FAIL_VALIDATE_SERIAL');
29097                     fnd_msg_pub.ADD;
29098                     l_progress := 'WMSINB-28044';
29099                     RAISE fnd_api.g_exc_error;
29100                   END IF; --IF (serial_entered_on_parent(l_parent_transaction_id)) THEN
29101                 ELSE --IF (validate_rs(NULL,l_parent_transaction_id,l_dummy_lpn)) THEN
29102                   IF (l_parent_txn_type <> 'RECEIVE') THEN
29103                     IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
29104                        --raise an error
29105                        fnd_message.set_name('INV' , 'INV_FAIL_VALIDATE_SERIAL');
29106                        fnd_msg_pub.ADD;
29107                        l_progress := 'WMSINB-28053';
29108                        RAISE fnd_api.g_exc_error;
29109                     END IF; --IF (serial_entered_on_parent(l_grand_parent_txn_id)) THEN
29110                   END IF; --IF (l_parent_txn_type <> 'RECEIVE') THEN
29111                 END IF; --IF (validate_rs(NULL,l_parent_transaction_id,l_dummy_lpn)) THEN
29112               ELSE --IF (l_parent_txn_type <> 'DELIVER') THEN
29113                 IF (l_serial_number_control_code IN (2,5)
29114                     OR (l_serial_number_control_code = 6
29115                         AND l_source_document_code = 'RMA')) THEN
29116                        --raise error
29117                          fnd_message.set_name ('INV' , 'INV_FAIL_VALIDATE_SERIAL' );
29118                          fnd_msg_pub.ADD;
29119                          l_progress := 'WMSINB-28062';
29120                          RAISE fnd_api.g_exc_error;
29121                 END IF;
29122               END IF; --IF (l_parent_txn_type <> 'DELIVER') THEN
29123             END IF; --IF (l_parent_txn_type IN (g_rtv,g_rtc,g_rtr)) THEN
29124           END IF; --IF (l_num_msnt_recs > 0) THEN
29125         END IF; --IF (l_lot_control_code = 2) THEN
29126       END IF; --IF ((l_transaction_type = 'CORRECT' AND l_rti_primary_qty < 0)
29127     END IF; --IF (l_transaction_type IN ('CORRECT',G_RTR,G_RTV,G_RTC)) THEN
29128 
29129     IF (l_debug = 1) THEN
29130       --print_debug('VALIDATE_LOT_SERIAL_INFO: What a relief !!! Completed succesfully !!!',1);
29131       print_debug('VALIDATE_LOT_SERIAL_INFO:Completed succesfully!',1);
29132     END IF;
29133 
29134   EXCEPTION
29135      WHEN fnd_api.g_exc_error THEN
29136         x_return_status  := g_ret_sts_error;
29137         IF (l_debug = 1) THEN
29138            print_debug('Exitting VALIDATE_LOT_SERIAL_INFO - execution error:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
29139            print_stacked_messages;
29140         END IF;
29141         x_msg_data := l_progress;
29142      WHEN fnd_api.g_exc_unexpected_error THEN
29143         x_return_status  := g_ret_sts_unexp_error;
29144         IF (l_debug = 1) THEN
29145            print_debug('Exitting VALIDATE_LOT_SERIAL_INFO - unexpected error:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
29146            print_stacked_messages;
29147         END IF;
29148         x_msg_data := l_progress;
29149      WHEN OTHERS THEN
29150         X_RETURN_STATUS  := G_RET_STS_UNEXP_ERROR;
29151         IF (L_DEBUG = 1) THEN
29152            PRINT_DEBUG('Exitting VALIDATE_LOT_SERIAL_INFO - OTHER EXCEPTION:'||TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')||':'||l_progress, 1);
29153            print_stacked_messages;
29154         END IF;
29155 
29156         x_msg_data := l_progress;
29157 
29158         IF SQLCODE IS NOT NULL THEN
29159            INV_MOBILE_HELPER_FUNCTIONS.SQL_ERROR('INV_RCV_INTERFACE_PVT.VALIDATE_LOT_SERIAL_INFO', Sqlerrm, SQLCODE);
29160         END IF;
29161         -- GET MESSAGE COUNT AND DATA
29162         -- FND_MSG_PUB.COUNT_AND_GET(P_ENCODED => G_FALSE, P_COUNT => X_MSG_COUNT, P_DATA => X_MSG_DATA);
29163   END VALIDATE_LOT_SERIAL_INFO;
29164 
29165 	/*
29166 	This processdure validates the LPN to restric the multiple users doing transactions on same LPN
29167 	Added for the Bug:13613257
29168   */
29169 
29170 
29171   PROCEDURE Validate_Receiving_LPN(
29172   	p_lpn_id     IN NUMBER,
29173   	p_routing_id IN NUMBER,
29174   	x_return_status OUT NOCOPY VARCHAR2,
29175   	x_msg_count OUT NOCOPY     NUMBER,
29176   	x_msg_data OUT NOCOPY      VARCHAR2)
29177   IS
29178 	  CURSOR c_validate_loaded_lpn
29179 	  IS
29180 		SELECT
29181 		  1
29182 		FROM
29183 		  WMS_DISPATCHED_TASKS WDT,
29184 		  MTL_MATERIAL_TRANSACTIONS_TEMP MMTT
29185 		WHERE
29186 		  NVL(MMTT.content_lpn_id, MMTT.lpn_id)                = p_lpn_id
29187 		AND MMTT.transaction_temp_id = WDT.transaction_temp_id
29188 		AND WDT.STATUS               = 4 ;
29189 
29190 	  CURSOR c_validate_rec_lpn
29191 	  IS
29192 		SELECT
29193 		  lpn_context, license_plate_number
29194 		FROM
29195 		  WMS_LICENSE_PLATE_NUMBERS WLPN
29196 		WHERE
29197 		  WLPN.LPN_ID          = p_lpn_id ;
29198 	  l_progress    VARCHAR2(15) := '00';
29199 	  l_debug       NUMBER       := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
29200 	  l_exit        NUMBER ;
29201 	  l_lpn_context NUMBER;
29202 	  l_lpn 		VARCHAR2(200);
29203 	  l_lpn_rec c_validate_rec_lpn%rowTYPE;
29204 	  l_lpn_lod c_validate_loaded_lpn%rowTYPE;
29205   BEGIN
29206       x_return_status := g_ret_sts_success;
29207       x_msg_count     := 0 ;
29208 
29209       IF (l_debug      = 1) THEN
29210         print_debug('VALIDATE_LPN Entered...:'|| l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
29211         print_debug('VALIDATE_LPN p_lpn_id...: '|| p_lpn_id, 1);
29212         print_debug('VALIDATE_LPN p_routing_id...: '|| p_routing_id, 1);
29213       END IF;
29214 
29215       IF (p_lpn_id IS NULL OR p_lpn_id<0) THEN
29216         fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
29217         --fnd_message.set_token('LPN', l_lpn);
29218         fnd_msg_pub.add;
29219         x_return_status := g_ret_sts_error;
29220         RETURN;
29221       END IF;
29222 
29223       IF (p_lpn_id=0) THEN
29224          IF (l_debug      = 1) THEN
29225           print_debug('VALIDATE_LPN lpn_id is 0 hence no need to validate... ', 1);
29226         END IF;
29227         RETURN;
29228       END IF;
29229 	 /*
29230 	  SELECT license_plate_number
29231 		INTO l_lpn
29232 		FROM WMS_LICENSE_PLATE_NUMBERS
29233 	   WHERE LPN_ID          = p_lpn_id ;*/
29234 
29235       IF (l_debug = 1) THEN
29236         print_debug('VALIDATE_LPN - Checking LPN '||l_lpn||' is in receiving or not' || l_progress || '' || p_lpn_id,1 );
29237       END IF;
29238 
29239       OPEN c_validate_rec_lpn;
29240       FETCH c_validate_rec_lpn INTO	l_lpn_rec;
29241 
29242       IF (c_validate_rec_lpn%FOUND ) THEN
29243 
29244         IF (l_lpn_rec.lpn_context IN (5,6,7))THEN
29245           IF (l_debug      = 1) THEN
29246             print_debug('VALIDATE_LPN lpn_id is in context 5 or 6 or 7. Hence no need to validate... ', 1);
29247           END IF;
29248           CLOSE c_validate_rec_lpn;
29249           RETURN;
29250         END IF;
29251 
29252         IF (p_routing_id                <> 3 ) THEN
29253           IF (l_lpn_rec.lpn_context <> 3 ) THEN
29254             IF (l_debug                  = 1) THEN
29255               print_debug('VALIDATE_LPN - This is not a Receiving LPN' ||l_progress || '' || p_lpn_id,1 );
29256             END IF;
29257 
29258             fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
29259             --fnd_message.set_token('LPN', l_lpn);
29260             fnd_msg_pub.add;
29261 
29262             x_return_status := g_ret_sts_error;
29263             x_msg_count := 1;
29264             CLOSE c_validate_rec_lpn;
29265             RETURN;
29266           ELSE
29267             IF (l_debug = 1) THEN
29268               print_debug('VALIDATE_LPN - LPN '||l_lpn||' is a receiving LPN' ||l_progress || '' || p_lpn_id,1 );
29269             END IF;
29270           END IF;
29271         ELSIF (l_lpn_rec.lpn_context <> 1)THEN
29272           IF (l_debug                 = 1) THEN
29273             print_debug('VALIDATE_LPN - This is Direct routing and LPN '||l_lpn||' is not in Inventory' || l_progress || '' || p_lpn_id,1 );
29274           END IF;
29275 
29276           fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
29277           --fnd_message.set_token('LPN', l_lpn);
29278           fnd_msg_pub.add;
29279 
29280           x_return_status := g_ret_sts_error;
29281           x_msg_count :=1;
29282           CLOSE c_validate_rec_lpn;
29283           RETURN;
29284         END IF ;
29285       ELSE
29286         IF (l_debug = 1) THEN
29287 		  print_debug('Cursor c_validate_rec_lpn not found' ||l_progress || '' ||
29288 		  p_lpn_id,1 );
29289         END IF;
29290 
29291         fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
29292         --fnd_message.set_token('LPN', l_lpn);
29293         fnd_msg_pub.add;
29294 
29295         x_return_status := g_ret_sts_error;
29296         x_msg_count := 1;
29297         CLOSE c_validate_rec_lpn;
29298         RETURN;
29299       END IF ;
29300 
29301 	  CLOSE c_validate_rec_lpn;
29302 
29303       IF (l_debug = 1) THEN
29304         print_debug('VALIDATE_LPN - Checking LPN '||l_lpn||' is loaded or not' ||l_progress || '' || p_lpn_id,1 );
29305       END IF;
29306 
29307       OPEN c_validate_loaded_lpn;
29308       FETCH c_validate_loaded_lpn INTO l_lpn_lod;
29309       IF (c_validate_loaded_lpn%FOUND ) THEN
29310         l_progress := 'WMSINB-001';
29311 
29312     	IF (l_debug = 1) THEN
29313           print_debug('VALIDATE_LPN - LPN '||l_lpn||' IS Loaded : ' ||l_progress || ' : ' || p_lpn_id ,1 );
29314         END IF;
29315 
29316         fnd_message.set_name('WMS', 'WMS_LPN_ALREADY_ENTERED');
29317         fnd_message.set_token('LPN_NAME', l_lpn_rec.license_plate_number);
29318         fnd_msg_pub.add;
29319 
29320         x_return_status := g_ret_sts_error;
29321         x_msg_count :=1;
29322       ELSE
29323         IF (l_debug = 1) THEN
29324           print_debug('VALIDATE_LPN - LPN '||l_lpn||' is not  Loaded' ||l_progress || '' ||  p_lpn_id,1 );
29325         END IF;
29326       END IF ;
29327       CLOSE c_validate_loaded_lpn;
29328 
29329   EXCEPTION
29330     WHEN fnd_api.g_exc_error THEN
29331       x_return_status := g_ret_sts_error;
29332       IF (l_debug      = 1) THEN
29333         print_debug('VALIDATE_LPN - Execution Error:'|| l_progress || ':' ||SQLCODE, 1);
29334         print_stacked_messages;
29335       END IF;
29336       x_msg_data := l_progress;
29337     WHEN OTHERS THEN
29338       x_return_status := g_ret_sts_unexp_error;
29339       IF (l_debug      = 1) THEN
29340         print_debug('VALIDATE_LPN - OTHER Exception:'|| l_progress || ' ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), 1);
29341         print_stacked_messages;
29342       END IF;
29343       x_msg_data := l_progress;
29344       IF SQLCODE IS NOT NULL THEN
29345         inv_mobile_helper_functions.sql_error('INV_RCV_INTEGRATION_PVT.VALIDATE_LPN',l_progress, SQLCODE);
29346       END IF;
29347   END Validate_Receiving_LPN;
29348 
29349 --14615225
29350 
29351 
29352    FUNCTION get_uom_code(p_uom IN VARCHAR2)
29353    RETURN VARCHAR2
29354    IS
29355    l_uom_code VARCHAR2(30) ;
29356 
29357    BEGIN
29358 
29359    print_debug( 'In get_UOM_CODE ' || p_uom ,1);
29360     l_uom_code := NULL ;
29361 
29362     IF p_uom is not NULL
29363     THEN
29364       BEGIN
29365         SELECT uom_code
29366           INTO l_uom_code
29367           FROM mtl_units_of_measure
29368          WHERE unit_of_measure = p_uom ;
29369 
29370         EXCEPTION
29371         WHEN  NO_DATA_FOUND
29372          THEN
29373            l_uom_code := '@@@' ;
29374 
29375          WHEN TOO_MANY_ROWS
29376          THEN
29377            l_uom_code := '@@@' ;
29378       END ;
29379 
29380    END IF;
29381   RETURN( l_uom_code );
29382   END;
29383 
29384    PROCEDURE check_over_receipt(p_lpn_id          IN NUMBER,
29385                                 p_item_id         IN NUMBER,
29386                                 p_organization_id IN NUMBER,
29387                                 p_qty_entered     IN NUMBER,
29388                                 p_transaction_uom IN VARCHAR2,
29389                                 x_qty_left        OUT NOCOPY VARCHAR2,
29390                                 x_return_status   OUT NOCOPY VARCHAR2)
29391    IS
29392    l_pr_UoM_code         VARCHAR2(5);
29393 
29394    l_shipped_pr_quantity NUMBER :=0;
29395    l_recd_pr_quantity    NUMBER :=0;
29396    l_rti_pr_qty          NUMBER :=0;
29397    l_debug               NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
29398    l_progress            VARCHAR2(25);
29399    l_rsl_UoM             VARCHAR2(3);
29400    l_rsl_pr_UoM          VARCHAR2(3);
29401    l_shipped_quantity_tr_uom NUMBER :=0;
29402    l_recd_quantity_tr_uom    NUMBER :=0;
29403    l_rti_quantity_tr_uom     NUMBER :=0;
29404    l_rti_UoM                 VARCHAR2(3);
29405    l_comp_pr                 BOOLEAN :=FALSE;
29406    l_qty_entered_pr_uom      NUMBER;
29407 
29408 
29409    CURSOR c_rsl_cursor IS
29410    SELECT Sum(rsl.quantity_shipped) quantity_shipped ,
29411           Sum(rsl.quantity_received) quantity_received,
29412           rsl.unit_of_measure
29413      FROM rcv_shipment_lines rsl
29414     WHERE rsl.asn_lpn_id         = p_lpn_id
29415       AND rsl.to_organization_id = p_organization_id
29416       AND rsl.item_id            = p_item_id
29417 	GROUP BY rsl.item_id , rsl.to_organization_id, rsl.asn_lpn_id, rsl.unit_of_measure;
29418 
29419 	CURSOR c_rti_cursor IS
29420    SELECT SUM(rti.primary_quantity) primary_quantity,
29421           SUM(rti.quantity) quantity,
29422 		  rti.unit_of_measure
29423      FROM rcv_transactions_interface rti
29424 	WHERE rti.lpn_id             = p_lpn_id
29425       AND rti.item_id            = p_item_id
29426       AND rti.to_organization_id = p_organization_id
29427       AND(rti.transaction_status_code = 'PENDING'
29428           AND rti.processing_status_code <> 'ERROR')
29429       AND rti.transaction_type  = 'RECEIVE'
29430 	GROUP BY rti.lpn_id , rti.to_organization_id, rti.item_id , rti.unit_of_measure;
29431 
29432    BEGIN
29433     x_return_status := G_RET_STS_SUCCESS;
29434 	x_qty_left := 'N';
29435      print_debug('CHECK_OVER_RECEIPT - p_lpn_id           '||p_lpn_id, 1);
29436 	 print_debug('CHECK_OVER_RECEIPT - p_transaction_uom  '||p_transaction_uom, 1);
29437 	 print_debug('CHECK_OVER_RECEIPT - p_qty_entered      '||p_qty_entered, 1);
29438 	 print_debug('CHECK_OVER_RECEIPT - p_item_id          '||p_item_id, 1);
29439 	 print_debug('CHECK_OVER_RECEIPT - p_organization_id  '||p_organization_id, 1);
29440 
29441     l_progress :=10;
29442 
29443   IF p_lpn_id IS NOT NULL
29444   THEN
29445 
29446     SELECT primary_uom_code
29447       INTO l_pr_UoM_code
29448       FROM mtl_system_items
29449      WHERE inventory_item_id =  p_item_id
29450        AND organization_id = p_organization_id ;
29451 
29452     l_progress :=20;
29453 
29454 	l_comp_pr := FALSE;
29455 
29456 	FOR l_rsl_rec IN c_rsl_cursor
29457     LOOP
29458 	 l_rsl_UoM    := get_uom_code(l_rsl_rec.unit_of_measure);
29459 
29460      print_debug('CHECK_OVER_RECEIPT - UoM of the shipment  '||l_rsl_UoM, 1);
29461 
29462 	 IF (l_rsl_UoM = p_transaction_uom AND NOT (l_comp_pr))
29463 	 THEN
29464 	  l_shipped_quantity_tr_uom := l_shipped_quantity_tr_uom + l_rsl_rec.quantity_shipped;
29465 	  l_recd_quantity_tr_uom    := l_recd_quantity_tr_uom    + l_rsl_rec.quantity_received;
29466      ELSE/*IF (l_rsl_UoM <> l_pr_UoM_code)*/
29467 	 --THEN
29468       l_comp_pr := TRUE;
29469 	  l_shipped_quantity_tr_uom := 0;
29470 	  l_recd_quantity_tr_uom    := 0;
29471 	 END IF;
29472 
29473 	  l_shipped_pr_quantity := l_shipped_pr_quantity + inv_convert.inv_um_convert (p_item_id
29474                                                                                   ,null
29475                                                                                   ,l_rsl_rec.quantity_shipped
29476                                                                                   ,l_rsl_UoM
29477                                                                                   ,l_pr_UoM_code
29478                                                                                   ,null
29479                                                                                   ,null );
29480 
29481 	  l_recd_pr_quantity := l_recd_pr_quantity + inv_convert.inv_um_convert (p_item_id
29482                                                                             ,null
29483                                                                             ,l_rsl_rec.quantity_received
29484                                                                             ,l_rsl_UoM
29485                                                                             ,l_pr_UoM_code
29486                                                                             ,null
29487                                                                             ,null );
29488     END LOOP;
29489     l_progress :=30;
29490 
29491     print_debug('CHECK_OVER_RECEIPT - Finally Shipped Qty After converting to primary '||l_shipped_pr_quantity, 1);
29492     print_debug('CHECK_OVER_RECEIPT - Finally Recd Qty After converting to primary '||l_recd_pr_quantity, 1);
29493     print_debug('CHECK_OVER_RECEIPT - Finally Shipped Qty After converting to transaction '||l_shipped_quantity_tr_uom, 1);
29494     print_debug('CHECK_OVER_RECEIPT - Finally Recd Qty After converting to transaction '||l_recd_quantity_tr_uom, 1);
29495 
29496 
29497 	FOR l_rti_rec IN c_rti_cursor
29498 	LOOP
29499 	 l_rti_UoM    := get_uom_code(l_rti_rec.unit_of_measure);
29500 	 IF (l_rti_UoM = p_transaction_uom AND NOT (l_comp_pr))
29501 	 THEN
29502 	  l_rti_quantity_tr_uom := l_rti_quantity_tr_uom + l_rti_rec.quantity;
29503      ELSE
29504 	 --THEN
29505       l_rti_quantity_tr_uom :=0;
29506       l_comp_pr := TRUE;
29507 	  l_rti_pr_qty := l_rti_pr_qty + l_rti_rec.primary_quantity;
29508 	 END IF;
29509 
29510 	END LOOP;
29511     l_progress :=50;
29512 
29513     IF (p_transaction_uom <> l_pr_UoM_code) THEN
29514      l_qty_entered_pr_uom :=    inv_convert.inv_um_convert (p_item_id
29515                                                            ,null
29516                                                            ,p_qty_entered
29517                                                            ,p_transaction_uom
29518                                                            ,l_pr_UoM_code
29519                                                            ,null
29520                                                            ,null );
29521     ELSE
29522      l_qty_entered_pr_uom := p_qty_entered;
29523 	END IF;
29524 
29525     print_debug('CHECK_OVER_RECEIPT - Primary UoM', 1);
29526     print_debug('CHECK_OVER_RECEIPT - ------------------------------------', 1);
29527     print_debug('CHECK_OVER_RECEIPT - Qty Entered in Primary UoM          '||l_qty_entered_pr_uom, 1);
29528     print_debug('CHECK_OVER_RECEIPT - Already received qty in Primary UoM '||l_recd_pr_quantity, 1);
29529     print_debug('CHECK_OVER_RECEIPT - Existing RTI qty in Primary UoM     '||l_rti_pr_qty, 1);
29530     print_debug('CHECK_OVER_RECEIPT - Total Shipped qty in Primary UoM    '||l_shipped_pr_quantity, 1);
29531     print_debug('CHECK_OVER_RECEIPT - *************************************', 1);
29532     print_debug('CHECK_OVER_RECEIPT - Transaction UoM', 1);
29533     print_debug('CHECK_OVER_RECEIPT - ----------------------------------------', 1);
29534     print_debug('CHECK_OVER_RECEIPT - Qty Entered in Transaction UoM          '||p_qty_entered, 1);
29535     print_debug('CHECK_OVER_RECEIPT - Already received qty in Transaction UoM '||l_recd_quantity_tr_uom, 1);
29536     print_debug('CHECK_OVER_RECEIPT - Existing RTI qty in Transaction UoM     '||l_rti_quantity_tr_uom, 1);
29537     print_debug('CHECK_OVER_RECEIPT - Total Shipped qty in Transaction UoM    '||l_shipped_quantity_tr_uom, 1);
29538 
29539    IF (l_comp_pr)
29540    THEN
29541     print_debug('CHECK_OVER_RECEIPT - l_comp_pr IS TRUE Compating quantities in Primary UoM ', 1);
29542     IF ( Round((l_qty_entered_pr_uom + l_recd_pr_quantity + l_rti_pr_qty) - l_shipped_pr_quantity ,5) > 0.00005)
29543     THEN
29544      x_return_status := G_RET_STS_ERROR;
29545 	 IF ((l_shipped_pr_quantity - l_recd_pr_quantity - l_rti_pr_qty)> 0.00005)
29546 	  THEN
29547 	  x_qty_left := 'Y';
29548 	 END IF;
29549      fnd_message.set_name('WMS', 'WMS_SHIPMENT_OVER_RECEIPT');
29550      fnd_msg_pub.ADD;
29551 	 print_debug('CHECK_OVER_RECEIPT - The shipment is being over received. Set Warning '||l_progress, 1);
29552     END IF;
29553 
29554    ELSE
29555    print_debug('CHECK_OVER_RECEIPT - Comparing the quantities in Transaction UoM ', 1);
29556    IF ( Round((p_qty_entered + l_recd_quantity_tr_uom + l_rti_quantity_tr_uom) - l_shipped_quantity_tr_uom ,5) > 0.00005)
29557    THEN
29558      x_return_status := G_RET_STS_ERROR;
29559 	 IF ((l_shipped_quantity_tr_uom - l_recd_quantity_tr_uom - l_rti_quantity_tr_uom) > 0.00005)
29560 	  THEN
29561 	  x_qty_left := 'Y';
29562 	 END IF;
29563      fnd_message.set_name('WMS', 'WMS_SHIPMENT_OVER_RECEIPT');
29564      fnd_msg_pub.ADD;
29565 	 print_debug('CHECK_OVER_RECEIPT - The shipment is being over received. Set Warning '||l_progress, 1);
29566    END IF;
29567    END IF;
29568 
29569   END IF; --lpn_id NULL
29570    EXCEPTION
29571    WHEN OTHERS THEN
29572      print_debug('CHECK_OVER_RECEIPT - Others Exception SQLCODE '||SQLCODE||' SQLERRM '||SQLERRM, 1);
29573 	 print_debug('CHECK_OVER_RECEIPT - l_progress '||l_progress, 1);
29574      x_return_status := G_RET_STS_UNEXP_ERROR;
29575 
29576    END check_over_receipt;
29577 
29578 --14615225
29579 
29580 END inv_rcv_integration_pvt;