[Home] [Help]
PACKAGE BODY: APPS.WMS_PICK_DROP_PVT
Source
1 PACKAGE BODY wms_pick_drop_pvt AS
2 /* $Header: WMSPKDPB.pls 120.28.12020000.3 2013/01/31 12:14:24 blavu ship $ */
3
4 g_pkg_body_ver CONSTANT VARCHAR2(100) := '$Header: WMSPKDPB.pls 120.28.12020000.3 2013/01/31 12:14:24 blavu ship $';
5 g_newline CONSTANT VARCHAR2(10) := fnd_global.newline;
6
7 g_gtin_cross_ref_type VARCHAR2(25) := fnd_profile.value('INV:GTIN_CROSS_REFERENCE_TYPE');
8
9 g_xfer_to_lpn_id NUMBER := NULL; --Added for bug 10139672
10 --This variable is used to store the "To LPN" value and assigned in procedure validate_xfer_to_lpn and it will be used in
11 --pick_drop procedure
12
13 --
14 -- These tables type store the current list of temp IDs
15 -- for a drop LPN, and the groups they belong to
16 --
17 TYPE g_temp_id_status IS TABLE OF VARCHAR2(10) INDEX BY LONG; --For bug 8552027
18 TYPE g_temp_id_tbl IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
19
20 TYPE g_temp_id_group_ref_tbl IS TABLE OF NUMBER INDEX BY LONG; --For bug 8552027
21
22 --
23 -- Current pending temp IDs
24 --
25 g_cur_pend_temp g_temp_id_tbl;
26
27 --
28 -- This record type stores information about the current
29 -- drop LPN, including the list of temp IDs to be passed
30 -- to the TM.
31 --
32 TYPE drop_lpn_rec_type IS RECORD
33 ( lpn_id NUMBER := 0
34 , organization_id NUMBER := 0
35 , multiple_drops VARCHAR2(10) := ''
36 , drop_lpn_option NUMBER := 1
37 , current_drop_list g_temp_id_status
38 , temp_id_group_ref g_temp_id_group_ref_tbl --For bug 8552027
39 );
40
41 g_current_drop_lpn drop_lpn_rec_type;
42
43 g_suggestion_drop VARCHAR2(50) :='NONE'; -- Added for bug 12853197
44 g_total_qty number :=0; -- Added for bug 12853197
45 g_chk_mult_subinv VARCHAR2(2) := NULL; -- Added for bug 12853197
46
47
48 PROCEDURE print_debug
49 ( p_msg IN VARCHAR2
50 , p_api_name IN VARCHAR2
51 ) IS
52 BEGIN
53 inv_log_util.trace
54 ( p_message => p_msg
55 , p_module => g_pkg_name || '.' || p_api_name
56 , p_level => 4
57 );
58 END print_debug;
59
60
61
62 PROCEDURE print_version_info
63 IS
64 BEGIN
65 print_debug ('Spec:: ' || g_pkg_spec_ver, 'print_version_info');
66 print_debug ('Body:: ' || g_pkg_body_ver, 'print_version_info');
67 END print_version_info;
68
69
70
71 PROCEDURE clear_lpn_cache
72 ( x_return_status OUT NOCOPY VARCHAR2
73 ) IS
74 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
75 BEGIN
76 x_return_status := fnd_api.g_ret_sts_success;
77
78 g_current_drop_lpn.current_drop_list.DELETE;
79 g_current_drop_lpn.temp_id_group_ref.DELETE;
80
81
82 g_cur_pend_temp.DELETE;
83
84 g_current_drop_lpn.lpn_id := NULL;
85 g_current_drop_lpn.organization_id := NULL;
86 g_current_drop_lpn.multiple_drops := NULL;
87 g_current_drop_lpn.drop_lpn_option := 1;
88
89 EXCEPTION
90 WHEN OTHERS THEN
91 x_return_status := fnd_api.g_ret_sts_unexp_error;
92
93 IF l_debug = 1 THEN
94 print_debug (sqlerrm, 'clear_lpn_cache');
95 END IF;
96
97 END clear_lpn_cache;
98
99
100
101 PROCEDURE get_drop_type
102 ( x_drop_type OUT NOCOPY VARCHAR2
103 , x_return_status OUT NOCOPY VARCHAR2
104 , p_temp_id IN NUMBER
105 ) IS
106
107 l_api_name VARCHAR2(30) := 'get_drop_type';
108 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
109
110 CURSOR c_txn_info
111 ( p_txn_tmp_id IN NUMBER
112 ) IS
113 SELECT mmtt.move_order_line_id
114 , mmtt.transaction_source_type_id
115 , mmtt.transaction_action_id
116 , mmtt.wms_task_type
117 FROM mtl_material_transactions_temp mmtt
118 WHERE mmtt.transaction_temp_id = p_txn_tmp_id;
119
120 CURSOR c_mo_type
121 ( p_mo_line_id IN NUMBER
122 ) IS
123 SELECT mtrh.move_order_type
124 , mtrl.line_status
125 FROM mtl_txn_request_lines mtrl
126 , mtl_txn_request_headers mtrh
127 WHERE mtrl.line_id = p_mo_line_id
128 AND mtrl.header_id = mtrh.header_id;
129
130 l_mo_line_id NUMBER;
131 l_txn_src_type_id NUMBER;
132 l_txn_action_id NUMBER;
133 l_move_order_type NUMBER;
134 l_mo_line_stat NUMBER;
135 l_wms_task_type NUMBER;
136
137 BEGIN
138
139 x_return_status := fnd_api.g_ret_sts_success;
140
141 IF l_debug = 1 THEN
142 print_debug
143 ( 'Entered with parameters: ' || g_newline ||
144 'p_temp_id => ' || to_char(p_temp_id)
145 , l_api_name
146 );
147 END IF;
148
149 OPEN c_txn_info (p_temp_id);
150 FETCH c_txn_info
151 INTO l_mo_line_id
152 , l_txn_src_type_id
153 , l_txn_action_id
154 , l_wms_task_type;
155
156 IF c_txn_info%NOTFOUND THEN
157 IF l_debug = 1 THEN
158 print_debug
159 ( 'Passed-in temp ID is invalid: ' || to_char(p_temp_id)
160 , l_api_name
161 );
162 END IF;
163 CLOSE c_txn_info;
164 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
165 ELSE
166 IF l_debug = 1 THEN
167 print_debug
168 ( 'l_mo_line_id: ' || to_char(l_mo_line_id) ||
169 ', l_txn_src_type_id: ' || to_char(l_txn_src_type_id) ||
170 ', l_txn_action_id: ' || to_char(l_txn_action_id) ||
171 ', l_wms_task_type: ' || to_char(l_wms_task_type)
172 , l_api_name
173 );
174 END IF;
175 END IF;
176
177 CLOSE c_txn_info;
178
179 IF l_mo_line_id IS NOT NULL THEN
180 OPEN c_mo_type (l_mo_line_id);
181 FETCH c_mo_type
182 INTO l_move_order_type
183 , l_mo_line_stat;
184 CLOSE c_mo_type;
185
186 IF l_debug = 1 THEN
187 print_debug
188 ( 'l_move_order_type: ' || to_char(l_move_order_type) ||
189 ', l_mo_line_stat: ' || to_char(l_mo_line_stat)
190 , l_api_name
191 );
192 END IF;
193
194 IF l_mo_line_stat = INV_GLOBALS.G_TO_STATUS_CANCEL_BY_SOURCE
195 THEN
196 x_drop_type := 'CANCELLED';
197 ELSIF l_txn_action_id = INV_GLOBALS.G_ACTION_STGXFR THEN
198 x_drop_type := 'STG_XFER';
199 ELSIF l_move_order_type = INV_GLOBALS.G_MOVE_ORDER_MFG_PICK
200 AND l_txn_action_id = INV_GLOBALS.G_ACTION_ISSUE THEN
201 x_drop_type := 'WIP_ISSUE';
202 ELSIF l_move_order_type = INV_GLOBALS.G_MOVE_ORDER_MFG_PICK
203 AND l_txn_action_id = INV_GLOBALS.G_ACTION_SUBXFR THEN
204 x_drop_type := 'WIP_SUB_XFER';
205 ELSIF l_txn_action_id = INV_GLOBALS.G_ACTION_SUBXFR THEN
206 x_drop_type := 'SUB_XFER';
207 END IF;
208 ELSIF l_wms_task_type = 7 THEN
209 x_drop_type := 'CONS_STG_MV';
210 ELSIF l_txn_action_id = INV_GLOBALS.G_ACTION_SUBXFR THEN
211 x_drop_type := 'OVERPICK';
212 END IF;
213
214 IF x_drop_type IS NULL THEN
215 IF l_debug = 1 THEN
216 print_debug
217 ( 'Unable to determine drop type:'
218 || g_newline || 'p_temp_id: ' || to_char(p_temp_id)
219 || g_newline || 'l_mo_line_id: ' || to_char(l_mo_line_id)
220 || g_newline || 'l_txn_src_type_id: ' || to_char(l_txn_src_type_id)
221 || g_newline || 'l_txn_action_id: ' || to_char(l_txn_action_id)
222 || g_newline || 'l_move_order_type: ' || to_char(l_move_order_type)
223 || g_newline || 'l_mo_line_stat: ' || to_char(l_mo_line_stat)
224 , l_api_name
225 );
226 END IF;
227 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
228 ELSE
229 IF l_debug = 1 THEN
230 print_debug
231 ( 'Drop type: ' || x_drop_type
232 , l_api_name
233 );
234 END IF;
235 END IF;
236
237 EXCEPTION
238 WHEN OTHERS THEN
239 x_return_status := fnd_api.g_ret_sts_unexp_error;
240
241 IF l_debug = 1 THEN
242 print_debug ('Other error: ' || sqlerrm, l_api_name);
243 END IF;
244
245 END get_drop_type;
246
247
248
249 PROCEDURE get_delivery_id
250 ( x_delivery_id OUT NOCOPY NUMBER
251 , x_return_status OUT NOCOPY VARCHAR2
252 , p_drop_type IN VARCHAR2
253 , p_temp_id IN NUMBER
254 ) IS
255
256 l_api_name VARCHAR2(30) := 'get_delivery_id';
257 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
258
259 l_delivery_id NUMBER := NULL;
260
261 CURSOR c_get_deliv_id
262 ( p_tmp_id IN NUMBER
263 ) IS
264 SELECT wda.delivery_id
265 FROM wsh_delivery_assignments_v wda,
266 wsh_delivery_details_ob_grp_v wdd,
267 mtl_material_transactions_temp mmtt
268 WHERE wda.delivery_detail_id = wdd.delivery_detail_id
269 AND wdd.move_order_line_id = mmtt.move_order_line_id
270 AND wdd.organization_id = mmtt.organization_id
271 AND mmtt.transaction_temp_id = p_tmp_id;
272
273 BEGIN
274 x_return_status := fnd_api.g_ret_sts_success;
275
276 IF l_debug = 1 THEN
277 print_debug
278 ( 'Entered with parameters: ' || g_newline ||
279 'p_temp_id => ' || to_char(p_temp_id) || g_newline ||
280 'p_drop_type => ' || p_drop_type
281 , l_api_name
282 );
283 END IF;
284 x_delivery_id := 0;
285
286 IF p_drop_type = 'CONS_STG_MV' THEN
287 SELECT wda.delivery_id
288 INTO x_delivery_id
289 FROM wsh_delivery_assignments_v wda,
290 wsh_delivery_details_ob_grp_v wdd,
291 mtl_material_transactions_temp mmtt
292 WHERE wda.delivery_detail_id = wdd.delivery_detail_id
293 AND wdd.organization_id = mmtt.organization_id
294 AND mmtt.transaction_temp_id = p_temp_id
295 AND mmtt.transfer_lpn_id = wdd.lpn_id
296 AND ROWNUM = 1;
297 IF l_debug = 1 THEN print_debug ( 'x_delivery_id : ' || x_delivery_id , l_api_name); END IF;
298 ELSE
299 OPEN c_get_deliv_id (p_temp_id);
300 FETCH c_get_deliv_id INTO l_delivery_id;
301
302 IF c_get_deliv_id%NOTFOUND
303 OR
304 l_delivery_id IS NULL
305 THEN
306 x_delivery_id := 0;
307 ELSE
308 x_delivery_id := l_delivery_id;
309 END IF;
310
311 CLOSE c_get_deliv_id;
312 IF l_debug = 1 THEN print_debug ( 'Cursor: x_delivery_id : ' || x_delivery_id , l_api_name); END IF;
313 END IF ;
314
315 EXCEPTION
316 WHEN OTHERS THEN
317 x_return_status := fnd_api.g_ret_sts_unexp_error;
318
319 IF c_get_deliv_id%ISOPEN THEN
320 CLOSE c_get_deliv_id;
321 END IF;
322
323 IF l_debug = 1 THEN
324 print_debug ('Other error: ' || sqlerrm, l_api_name);
325 END IF;
326 END get_delivery_id;
327
328
329
330 PROCEDURE gen_lock_handle
331 ( x_lock_handle OUT NOCOPY VARCHAR2
332 , x_return_status OUT NOCOPY VARCHAR2
333 , p_organization_id IN NUMBER
334 , p_transfer_lpn_id IN NUMBER
335 ) IS
336
337 PRAGMA AUTONOMOUS_TRANSACTION;
338
339 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
340 l_api_name VARCHAR2(30) := 'gen_lock_handle';
341
342 l_lock_name VARCHAR2(128);
343 l_lock_handle VARCHAR2(128);
344
345 l_first_temp_id NUMBER;
346 l_last_temp_id NUMBER;
347
348 BEGIN
349 x_return_status := fnd_api.g_ret_sts_success;
350
351 IF l_debug = 1 THEN
352 print_debug
353 ( 'Entered with parameters: ' || g_newline ||
354 'p_organization_id => ' || to_char(p_organization_id) || g_newline ||
355 'p_transfer_lpn_id => ' || to_char(p_transfer_lpn_id)
356 , l_api_name
357 );
358 END IF;
359
360 l_lock_name := 'WMS_PICK_DROP'
361 || '-' || to_char(p_organization_id)
362 || '-' || to_char(p_transfer_lpn_id);
363
364 IF l_debug = 1 THEN
365 print_debug
366 ( 'Lock name: ' || l_lock_name || ', ' ||
367 'length: ' || LENGTH(l_lock_name)
368 , l_api_name
369 );
370 END IF;
371
372 --
373 -- Set expiration to 30 minutes
374 --
375 dbms_lock.allocate_unique
376 ( lockname => l_lock_name
377 , lockhandle => l_lock_handle
378 , expiration_secs => 1800
379 );
380
381 IF l_debug = 1 THEN
382 print_debug
383 ( 'Lock handle: ' || l_lock_handle
384 , l_api_name
385 );
386 END IF;
387
388 EXCEPTION
389 WHEN OTHERS THEN
390 x_return_status := fnd_api.g_ret_sts_unexp_error;
391
392 IF l_debug = 1 THEN
393 print_debug (sqlerrm, l_api_name);
394 END IF;
395
396 END gen_lock_handle;
397
398
399
400 PROCEDURE lock_lpn
401 ( x_return_status OUT NOCOPY VARCHAR2
402 , p_org_id IN NUMBER
403 , p_xfer_lpn_id IN NUMBER
404 ) IS
405
406 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
407 l_api_name VARCHAR2(30) := 'lock_lpn';
408
409 l_lock_handle VARCHAR2(128);
410 l_api_return_status VARCHAR2(1);
411 l_lock_req_stat NUMBER;
412
413 BEGIN
414 x_return_status := fnd_api.g_ret_sts_success;
415
416 IF l_debug = 1 THEN
417 print_debug
418 ( 'Entered with parameters: ' || g_newline ||
419 'p_org_id => ' || to_char(p_org_id) || g_newline ||
420 'p_xfer_lpn_id => ' || to_char(p_xfer_lpn_id)
421 , l_api_name
422 );
423 END IF;
424
425 /* l_api_return_status := fnd_api.g_ret_sts_success;
426
427 gen_lock_handle
428 ( x_lock_handle => l_lock_handle
429 , x_return_status => l_api_return_status
430 , p_organization_id => p_org_id
431 , p_transfer_lpn_id => p_xfer_lpn_id
432 );
433
434 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
435 IF l_debug = 1 THEN
436 print_debug
437 ( 'Error status from gen_lock_handle: ' || l_api_return_status
438 , l_api_name
439 );
440 END IF;
441 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
442 END IF;
443
444 l_lock_req_stat := dbms_lock.request
445 ( lockhandle => l_lock_handle
446 , lockmode => dbms_lock.x_mode
447 , timeout => 1
448 , release_on_commit => TRUE
449 );
450
451 IF l_lock_req_stat = 1 THEN
452 x_return_status := 'L';
453 ELSIF l_lock_req_stat NOT IN (0,4) THEN
454 IF l_debug = 1 THEN
455 print_debug
456 ( 'Error status from dbms_lock.request: ' ||
457 to_char(l_lock_req_stat)
458 , l_api_name
459 );
460 END IF;
461 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
462 END IF;
463 */
464 EXCEPTION
465 WHEN OTHERS THEN
466 x_return_status := fnd_api.g_ret_sts_unexp_error;
467
468 IF l_debug = 1 THEN
469 print_debug (sqlerrm, l_api_name);
470 END IF;
471
472 END lock_lpn;
473
474
475
476 PROCEDURE get_group_info
477 ( x_drop_type OUT NOCOPY VARCHAR2
478 , x_bulk_pick OUT NOCOPY VARCHAR2
479 , x_delivery_id OUT NOCOPY NUMBER
480 , x_task_type OUT NOCOPY NUMBER
481 , x_return_status OUT NOCOPY VARCHAR2
482 , p_txn_temp_id IN NUMBER
483 ) IS
484
485 l_api_name VARCHAR2(30) := 'get_group_info';
486 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
487 l_api_return_status VARCHAR2(1);
488
489 l_parent_temp_id NUMBER;
490 l_task_type NUMBER;
491
492 CURSOR c_get_parent_id
493 ( p_temp_id IN NUMBER
494 ) IS
495 SELECT mmtt.parent_line_id
496 FROM mtl_material_transactions_temp mmtt
497 WHERE mmtt.transaction_temp_id = p_temp_id;
498
499 CURSOR c_get_task_type
500 ( p_temp_id IN NUMBER
501 ) IS
502 SELECT wdt.task_type
503 FROM wms_dispatched_tasks wdt
504 WHERE wdt.transaction_temp_id = p_temp_id;
505
506 BEGIN
507 x_return_status := fnd_api.g_ret_sts_success;
508
509 IF l_debug = 1 THEN
510 print_debug
511 ( 'Entered with temp ID: ' || to_char(p_txn_temp_id)
512 , l_api_name
513 );
514 END IF;
515
516 --
517 -- Derive the drop type
518 --
519 l_api_return_status := fnd_api.g_ret_sts_success;
520 get_drop_type
521 ( x_drop_type => x_drop_type
522 , x_return_status => l_api_return_status
523 , p_temp_id => p_txn_temp_id
524 );
525
526 IF l_api_return_status <> fnd_api.g_ret_sts_success
527 THEN
528 IF l_debug = 1 THEN
529 print_debug
530 ( 'Error from get_drop_type'
531 , l_api_name
532 );
533 END IF;
534 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
535 ELSE
536 IF l_debug = 1 THEN
537 print_debug
538 ( 'Drop type: ' || x_drop_type
539 , l_api_name
540 );
541 END IF;
542 END IF;
543
544 --
545 -- Check if bulk
546 --
547 OPEN c_get_parent_id (p_txn_temp_id);
548 FETCH c_get_parent_id INTO l_parent_temp_id;
549 CLOSE c_get_parent_id;
550
551 IF l_parent_temp_id IS NOT NULL
552 THEN
553 x_bulk_pick := 'TRUE';
554 ELSE
555 x_bulk_pick := 'FALSE';
556 END IF;
557
558 IF l_debug = 1 THEN
559 print_debug
560 ( 'Bulk pick? ' || x_bulk_pick
561 , l_api_name
562 );
563 END IF;
564
565 --
566 -- Get delivery ID if staging xfer
567 --
568
569 IF l_debug = 1 THEN print_debug ( 'Outside ..Stg xfer or stg mv ' || x_drop_type , l_api_name); END IF;
570 IF x_drop_type = 'STG_XFER' OR x_drop_type = 'CONS_STG_MV' THEN
571 -- mrana : added staging move too
572 IF l_debug = 1 THEN print_debug ( 'Stg xfer or stg mv ' , l_api_name); END IF;
573 l_api_return_status := fnd_api.g_ret_sts_success;
574 get_delivery_id
575 ( x_delivery_id => x_delivery_id
576 , x_return_status => l_api_return_status
577 , p_drop_type => x_drop_type
578 , p_temp_id => p_txn_temp_id
579 );
580
581 IF l_api_return_status <> fnd_api.g_ret_sts_success
582 THEN
583 IF l_debug = 1 THEN
584 print_debug
585 ( 'Error from get_delivery_id'
586 , l_api_name
587 );
588 END IF;
589 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
590 ELSE
591 IF l_debug = 1 THEN
592 print_debug
593 ( 'Delivery ID: ' || to_char(x_delivery_id)
594 , l_api_name
595 );
596 END IF;
597 END IF;
598 END IF;
599
600 IF x_bulk_pick = 'TRUE'
601 THEN
602 OPEN c_get_task_type (l_parent_temp_id);
603 FETCH c_get_task_type INTO l_task_type;
604 CLOSE c_get_task_type;
605 ELSE
606 IF x_drop_type = 'CANCELLED'
607 OR
608 x_drop_type = 'OVERPICK'
609 THEN
610 l_task_type := 1;
611 ELSE
612 OPEN c_get_task_type (p_txn_temp_id);
613 FETCH c_get_task_type INTO l_task_type;
614 CLOSE c_get_task_type;
615 END IF;
616 END IF;
617 x_task_type := l_task_type;
618
619 IF l_debug = 1 THEN
620 print_debug
621 ( 'Task type: ' || to_char(l_task_type)
622 , l_api_name
623 );
624 END IF;
625
626 EXCEPTION
627 WHEN OTHERS THEN
628 x_return_status := fnd_api.g_ret_sts_unexp_error;
629
630 IF l_debug = 1 THEN
631 print_debug ('Other error: ' || sqlerrm, l_api_name);
632 END IF;
633
634 END get_group_info;
635
636
637
638 PROCEDURE insert_wdt
639 ( x_return_status OUT NOCOPY VARCHAR2
640 , p_organization_id IN NUMBER
641 , p_transfer_lpn_id IN NUMBER
642 ) IS
643
644 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
645 l_api_name VARCHAR2(30) := 'insert_wdt';
646
647 l_api_return_status VARCHAR2(1);
648
649 CURSOR c_parent_task_details
650 ( p_org_id IN NUMBER
651 , p_lpn_id IN NUMBER
652 ) IS
653 SELECT pmmtt.transaction_temp_id
654 , wdt.user_task_type
655 , wdt.person_id
656 , wdt.effective_start_date
657 , wdt.effective_end_date
658 , wdt.equipment_id
659 , wdt.equipment_instance
660 , wdt.person_resource_id
661 , wdt.machine_resource_id
662 , wdt.dispatched_time
663 , wdt.last_updated_by
664 , wdt.created_by
665 , wdt.task_type
666 , wdt.loaded_time
667 FROM mtl_material_transactions_temp pmmtt
668 , wms_dispatched_tasks wdt
669 WHERE pmmtt.organization_id = p_org_id
670 AND pmmtt.transfer_lpn_id = p_lpn_id
671 AND pmmtt.transaction_temp_id = NVL(pmmtt.parent_line_id,0)
672 AND wdt.transaction_temp_id = pmmtt.parent_line_id;
673
674 c_parent_task_rec c_parent_task_details%ROWTYPE;
675
676 BEGIN
677 x_return_status := fnd_api.g_ret_sts_success;
678
679 IF l_debug = 1 THEN
680 print_debug
681 ( 'Entered with parameters: ' || g_newline ||
682 'p_organization_id => ' || to_char(p_organization_id) || g_newline ||
683 'p_transfer_lpn_id => ' || to_char(p_transfer_lpn_id)
684 , l_api_name
685 );
686 END IF;
687
688 SAVEPOINT insert_task_sp;
689
690 FOR c_parent_task_rec IN c_parent_task_details( p_organization_id
691 , p_transfer_lpn_id)
692 LOOP
693 IF l_debug = 1 THEN
694 print_debug
695 ( 'Processing parent MMTT: ' || c_parent_task_rec.transaction_temp_id
696 , l_api_name
697 );
698 END IF;
699
700 INSERT INTO wms_dispatched_tasks
701 ( task_id
702 , transaction_temp_id
703 , organization_id
704 , user_task_type
705 , person_id
706 , effective_start_date
707 , effective_end_date
708 , equipment_id
709 , equipment_instance
710 , person_resource_id
711 , machine_resource_id
712 , status
713 , dispatched_time
714 , last_update_date
715 , last_updated_by
716 , creation_date
717 , created_by
718 , task_type
719 , loaded_time
720 , operation_plan_id
721 , move_order_line_id
722 )
723 ( SELECT wms_dispatched_tasks_s.NEXTVAL
724 , mmtt.transaction_temp_id
725 , mmtt.organization_id
726 , c_parent_task_rec.user_task_type
727 , c_parent_task_rec.person_id
728 , c_parent_task_rec.effective_start_date
729 , c_parent_task_rec.effective_end_date
730 , c_parent_task_rec.equipment_id
731 , c_parent_task_rec.equipment_instance
732 , c_parent_task_rec.person_resource_id
733 , c_parent_task_rec.machine_resource_id
734 , 4
735 , c_parent_task_rec.dispatched_time
736 , SYSDATE
737 , c_parent_task_rec.last_updated_by
738 , SYSDATE
739 , c_parent_task_rec.created_by
740 , c_parent_task_rec.task_type
741 , c_parent_task_rec.loaded_time
742 , mmtt.operation_plan_id
743 , mmtt.move_order_line_id
744 FROM mtl_material_transactions_temp mmtt
745 WHERE mmtt.parent_line_id = c_parent_task_rec.transaction_temp_id
746 AND mmtt.parent_line_id <> mmtt.transaction_temp_id
747 AND NOT EXISTS
748 ( SELECT 'x'
749 FROM wms_dispatched_tasks wdt2
750 WHERE wdt2.transaction_temp_id = mmtt.transaction_temp_id
751 )
752 );
753
754 IF l_debug = 1 THEN
755 print_debug
756 ( 'No. of WDT records inserted: ' || SQL%ROWCOUNT
757 , l_api_name
758 );
759 END IF;
760
761 END LOOP;
762
763 EXCEPTION
764 WHEN OTHERS THEN
765 ROLLBACK TO insert_task_sp;
766
767 x_return_status := fnd_api.g_ret_sts_unexp_error;
768
769 IF l_debug = 1 THEN
770 print_debug (sqlerrm, l_api_name);
771 END IF;
772
773 END insert_wdt;
774
775
776
777 PROCEDURE chk_if_deconsolidate
778 ( x_multiple_drops OUT NOCOPY VARCHAR2
779 , x_drop_type OUT NOCOPY VARCHAR2
780 , x_bulk_pick OUT NOCOPY VARCHAR2
781 , x_drop_lpn_option OUT NOCOPY NUMBER
782 , x_delivery_id OUT NOCOPY NUMBER
783 , x_first_temp_id OUT NOCOPY NUMBER
784 , x_task_type OUT NOCOPY NUMBER
785 , x_txn_type_id OUT NOCOPY NUMBER
786 , x_return_status OUT NOCOPY VARCHAR2
787 , p_organization_id IN NUMBER
788 , p_transfer_lpn_id IN NUMBER
789 , p_suggestion_drop IN VARCHAR2 -- Added for bug 12853197
790 ) IS
791
792 l_api_name VARCHAR2(30) := 'chk_if_deconsolidate';
793 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
794
795 l_drop_count NUMBER := 0;
796 l_drop_lpn_option NUMBER;
797
798 l_api_return_status VARCHAR2(1);
799 l_dummy VARCHAR2(1);
800 l_msg_count NUMBER;
801 l_msg_data VARCHAR2(2000);
802 l_message VARCHAR2(2000);
803
804 l_progress NUMBER := 0;
805
806 l_txn_type_id NUMBER;
807 l_txn_src_type_id NUMBER;
808 l_txn_action_id NUMBER;
809 l_txn_temp_id NUMBER;
810 -- bug#10062741
811 l_delivery_cnt NUMBER := 0; --Bug 10062741
812 l_line_rows WSH_UTIL_CORE.id_tab_type; --Bug 10062741
813 l_grouping_rows WSH_UTIL_CORE.id_tab_type; --Bug 10062741
814 l_same_carton_grouping BOOLEAN := FALSE; --Bug 10062741
815 l_return_status VARCHAR2(2); --Bug 10062741
816
817
818 CURSOR c_check_txns
819 ( p_org_id IN NUMBER
820 , p_lpn_id IN NUMBER
821 ) IS
822 SELECT 'x'
823 FROM dual
824 WHERE EXISTS
825 ( SELECT 'x'
826 FROM mtl_material_transactions_temp mmtt
827 WHERE mmtt.organization_id = p_org_id
828 AND mmtt.transfer_lpn_id = p_lpn_id
829 )
830 --Added for Bug 6717052
831 UNION ALL
832 SELECT 'x'
833 FROM dual
834 WHERE EXISTS
835 ( SELECT 'x'
836 FROM mtl_material_transactions_temp mmtt
837 WHERE mmtt.organization_id = p_org_id
838 AND mmtt.transfer_lpn_id IN (SELECT wlpn.lpn_id FROM wms_license_plate_numbers wlpn
839 WHERE wlpn.outermost_lpn_id = p_lpn_id));
840
841
842 CURSOR c_get_temp_txn_id
843 ( p_org_id IN NUMBER
844 , p_lpn_id IN NUMBER
845 ) IS
846 SELECT mmtt.transaction_temp_id
847 , mmtt.transaction_type_id
848 FROM mtl_material_transactions_temp mmtt
849 WHERE mmtt.organization_id = p_org_id
850 AND mmtt.transfer_lpn_id = p_lpn_id
851 AND (mmtt.parent_line_id IS NULL
852 OR
853 (mmtt.parent_line_id IS NOT NULL
854 AND
855 mmtt.parent_line_ID <> mmtt.transaction_temp_id
856 )
857 )
858 --Added for Bug 6717052
859 UNION ALL
860 SELECT mmtt.transaction_temp_id
861 , mmtt.transaction_type_id
862 FROM mtl_material_transactions_temp mmtt
863 WHERE mmtt.organization_id = p_org_id
864 AND mmtt.transfer_lpn_id IN (SELECT wlpn.lpn_id FROM wms_license_plate_numbers wlpn
865 WHERE wlpn.outermost_lpn_id = p_lpn_id)
866 AND (mmtt.parent_line_id IS NULL
867 OR
868 (mmtt.parent_line_id IS NOT NULL
869 AND
870 mmtt.parent_line_ID <> mmtt.transaction_temp_id
871 )
872 );
873
874
875
876 CURSOR c_num_mo_types
877 ( p_org_id IN NUMBER
878 , p_lpn_id IN NUMBER
879 ) IS
880 SELECT COUNT (DISTINCT (to_char(mtrh.move_order_type)
881 ||';'||
882 to_char(mtrl.line_status)
883 )
884 )
885 FROM mtl_material_transactions_temp mmtt
886 , mtl_txn_request_lines mtrl
887 , mtl_txn_request_headers mtrh
888 WHERE mmtt.organization_id = p_org_id
889 --Modified for Bug 6717052
890 AND (mmtt.transfer_lpn_id = p_lpn_id OR mmtt.transfer_lpn_id IN (SELECT wlpn.lpn_id FROM wms_license_plate_numbers wlpn
891 WHERE wlpn.outermost_lpn_id = p_lpn_id))
892 AND mmtt.move_order_line_id = mtrl.line_id
893 AND mtrl.header_id = mtrh.header_id;
894
895 CURSOR c_num_txn_actions
896 ( p_org_id IN NUMBER
897 , p_lpn_id IN NUMBER
898 ) IS
899 SELECT COUNT (DISTINCT mmtt.transaction_action_id)
900 FROM mtl_material_transactions_temp mmtt
901 WHERE mmtt.organization_id = p_org_id
902 --Added for Bug 6717052
903 AND (mmtt.transfer_lpn_id = p_lpn_id OR mmtt.transfer_lpn_id IN (SELECT wlpn.lpn_id FROM wms_license_plate_numbers wlpn
904 WHERE wlpn.outermost_lpn_id = p_lpn_id))
905 AND (mmtt.parent_line_id IS NULL
906 OR
907 (mmtt.parent_line_id IS NOT NULL
908 AND
909 mmtt.parent_line_ID <> mmtt.transaction_temp_id
910 )
911 );
912
913
914 CURSOR c_get_txn_type_details
915 ( p_org_id IN NUMBER
916 , p_lpn_id IN NUMBER
917 ) IS
918 SELECT mmtt.transaction_type_id
919 , mmtt.transaction_source_type_id
920 , mmtt.transaction_action_id
921 FROM mtl_material_transactions_temp mmtt
922 WHERE mmtt.organization_id = p_org_id
923 AND mmtt.transfer_lpn_id = p_lpn_id
924 AND (mmtt.parent_line_id IS NULL
925 OR
926 (mmtt.parent_line_id IS NOT NULL
927 AND
928 mmtt.parent_line_ID <> mmtt.transaction_temp_id
929 )
930 )
931 --Added for Bug 6717052
932 UNION ALL
933 SELECT mmtt.transaction_type_id
934 , mmtt.transaction_source_type_id
935 , mmtt.transaction_action_id
936 FROM mtl_material_transactions_temp mmtt
937 WHERE mmtt.organization_id = p_org_id
938 AND mmtt.transfer_lpn_id IN (SELECT wlpn.lpn_id FROM wms_license_plate_numbers wlpn
939 WHERE wlpn.outermost_lpn_id = p_lpn_id)
940 AND (mmtt.parent_line_id IS NULL
941 OR
942 (mmtt.parent_line_id IS NOT NULL
943 AND
944 mmtt.parent_line_ID <> mmtt.transaction_temp_id
945 )
946 );
947
948
949 CURSOR c_num_stg_xfers
950 ( p_org_id IN NUMBER
951 , p_lpn_id IN NUMBER
952 ) IS
953 SELECT COUNT (DISTINCT( mmtt.transfer_subinventory
954 ||';'||
955 to_char(mmtt.transfer_to_location)
956 ||';'||
957 to_char(NVL( wda.delivery_id
958 , -1 -- bug#10062741 mtrl.carton_grouping_id
959 )
960 )
961 )
962 )
963 FROM mtl_material_transactions_temp mmtt
964 , mtl_txn_request_lines mtrl
965 , wsh_delivery_details_ob_grp_v wdd
966 , wsh_delivery_assignments_v wda
967 WHERE mmtt.organization_id = p_org_id
968 --Modified for Bug 6717052
969 AND (mmtt.transfer_lpn_id = p_lpn_id OR mmtt.transfer_lpn_id IN (SELECT wlpn.lpn_id FROM wms_license_plate_numbers wlpn
970 WHERE wlpn.outermost_lpn_id = p_lpn_id))
971 AND ( (mmtt.parent_line_id IS NOT NULL
972 AND
973 mmtt.parent_line_id <> mmtt.transaction_temp_id
974 )
975 OR
976 mmtt.parent_line_id IS NULL
977 )
978 AND mtrl.line_id = mmtt.move_order_line_id
979 AND wdd.organization_id = mtrl.organization_id
980 AND wdd.move_order_line_id = mtrl.line_id
981 AND wda.delivery_detail_id = wdd.delivery_detail_id
982 AND wdd.released_status NOT IN ('Y','C','D','I','L','P');--Bug 13644027 [Y-picked,C-shipped,D-cancelled,I-interfaced,L-closed,P-purged]
983
984 --Bug 13644027- Adding cursor to calculate the l_delivery_cnt START
985 CURSOR c_delivery_cnt
986 ( p_org_id IN NUMBER
987 , p_lpn_id IN NUMBER
988 ) IS
989 SELECT Count(DISTINCT wda.delivery_id)
990 FROM mtl_material_transactions_temp mmtt
991 , mtl_txn_request_lines mtrl
992 , wsh_delivery_details_ob_grp_v wdd
993 , wsh_delivery_assignments_v wda
994 WHERE mmtt.organization_id = p_org_id
995 AND mmtt.transfer_lpn_id = p_lpn_id
996 AND ( (mmtt.parent_line_id IS NOT NULL
997 AND
998 mmtt.parent_line_id <> mmtt.transaction_temp_id
999 )
1000 OR
1001 mmtt.parent_line_id IS NULL
1002 )
1003 AND mtrl.line_id = mmtt.move_order_line_id
1004 AND wdd.organization_id = mtrl.organization_id
1005 AND wdd.move_order_line_id = mtrl.line_id
1006 AND wda.delivery_detail_id = wdd.delivery_detail_id
1007 AND wdd.released_status NOT IN ('Y','C','D','I','L','P');
1008
1009 --Bug 13644027- Adding cursor to calculate the l_delivery_cnt END
1010
1011 CURSOR c_stg_delivery_details -- bug#10062741
1012 ( p_org_id IN NUMBER
1013 , p_lpn_id IN NUMBER
1014 ) IS
1015 SELECT DISTINCT delivery_detail_id
1016 FROM mtl_material_transactions_temp mmtt
1017 , mtl_txn_request_lines mtrl
1018 , wsh_delivery_details wdd
1019 WHERE mmtt.organization_id = p_org_id
1020 AND mmtt.transfer_lpn_id = p_lpn_id
1021 AND ( (mmtt.parent_line_id IS NOT NULL
1022 AND
1023 mmtt.parent_line_id <> mmtt.transaction_temp_id
1024 )
1025 OR
1026 mmtt.parent_line_id IS NULL
1027 )
1028 AND mtrl.line_id = mmtt.move_order_line_id
1029 AND wdd.organization_id = mtrl.organization_id
1030 AND wdd.move_order_line_id = mtrl.line_id
1031 AND wdd.released_status NOT IN ('Y', 'C'); --Bug 5768776
1032
1033
1034 CURSOR c_num_wip_issue_drops
1035 ( p_org_id IN NUMBER
1036 , p_lpn_id IN NUMBER
1037 ) IS
1038 SELECT COUNT (DISTINCT (to_char(mtrl.txn_source_id)
1039 ||';'||
1040 to_char(mtrl.txn_source_line_id)
1041 ||';'||
1042 to_char(mtrl.reference_id)
1043 )
1044 )
1045 FROM mtl_material_transactions_temp mmtt
1046 , mtl_txn_request_lines mtrl
1047 WHERE mmtt.organization_id = p_org_id
1048 AND mmtt.transfer_lpn_id = p_lpn_id
1049 AND mmtt.move_order_line_id = mtrl.line_id;
1050
1051 -- Added for bug 12853197
1052 CURSOR c_chk_mult_subinv
1053 ( p_org_id IN NUMBER
1054 , p_lpn_id IN NUMBER
1055 ) IS
1056 SELECT Decode (Count(DISTINCT transfer_subinventory||' '||transfer_to_location),1,'N','Y')
1057 FROM mtl_material_transactions_temp mmtt
1058 WHERE mmtt.organization_id = p_org_id
1059 AND mmtt.transfer_lpn_id = p_lpn_id
1060 AND ((mmtt.parent_line_id IS NOT NULL
1061 AND mmtt.parent_line_id <> mmtt.transaction_temp_id
1062 ) OR
1063 mmtt.parent_line_id IS NULL
1064 );
1065
1066
1067 CURSOR c_num_sub_xfers
1068 ( p_org_id IN NUMBER
1069 , p_lpn_id IN NUMBER
1070 ) IS
1071 SELECT COUNT (DISTINCT (mmtt.transfer_subinventory
1072 ||';'||
1073 to_char(mmtt.transfer_to_location)
1074 ||';'||
1075 To_Char(Decode(g_chk_mult_subinv,'N','1',Decode(g_suggestion_drop,'NONE','1',mmtt.INVENTORY_ITEM_ID||';'||mmtt.revision))) -- Added for bug 12853197
1076 )
1077 )
1078 FROM mtl_material_transactions_temp mmtt
1079 WHERE mmtt.organization_id = p_org_id
1080 AND mmtt.transfer_lpn_id = p_lpn_id
1081 AND ( (mmtt.parent_line_id IS NOT NULL
1082 AND
1083 mmtt.parent_line_id <> mmtt.transaction_temp_id
1084 )
1085 OR
1086 mmtt.parent_line_id IS NULL
1087 );
1088
1089 BEGIN
1090 x_return_status := fnd_api.g_ret_sts_success;
1091
1092 fnd_msg_pub.initialize;
1093
1094 IF l_debug = 1 THEN
1095 print_version_info;
1096 print_debug
1097 ( 'Entered with parameters: ' || g_newline ||
1098 'p_organization_id => ' || to_char(p_organization_id) || g_newline ||
1099 'p_transfer_lpn_id => ' || to_char(p_transfer_lpn_id) || g_newline ||
1100 'p_suggestion_drop => ' || to_char(p_suggestion_drop) -- Added for bug 12853197
1101 , l_api_name
1102 );
1103 END IF;
1104
1105 SAVEPOINT chk_if_d_sp;
1106
1107 -- Added for bug 12853197
1108 IF p_suggestion_drop IS NOT NULL AND Length(Trim(p_suggestion_drop))>0 then
1109 g_suggestion_drop:=p_suggestion_drop;
1110 END IF;
1111
1112 l_progress := 10;
1113
1114 --
1115 -- Attempt to get a lock on this LPN
1116 --
1117 l_api_return_status := fnd_api.g_ret_sts_success;
1118 lock_lpn
1119 ( x_return_status => l_api_return_status
1120 , p_org_id => p_organization_id
1121 , p_xfer_lpn_id => p_transfer_lpn_id
1122 );
1123
1124 IF l_api_return_status = 'L'
1125 THEN
1126 IF l_debug = 1 THEN
1127 print_debug
1128 ( 'Failed to lock lpn'
1129 , l_api_name
1130 );
1131 END IF;
1132 fnd_message.set_name('WMS', 'WMS_DROP_LPN_LOCKED');
1133 fnd_msg_pub.ADD;
1134 RAISE FND_API.G_EXC_ERROR;
1135 ELSIF l_api_return_status <> fnd_api.g_ret_sts_success
1136 THEN
1137 IF l_debug = 1 THEN
1138 print_debug
1139 ( 'Error from lock_lpn'
1140 , l_api_name
1141 );
1142 END IF;
1143 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1144 END IF;
1145
1146 --
1147 -- Verify this LPNs has associated transactions
1148 --
1149 OPEN c_check_txns (p_organization_id, p_transfer_lpn_id);
1150 FETCH c_check_txns INTO l_dummy;
1151 IF c_check_txns%NOTFOUND THEN
1152 IF l_debug = 1 THEN
1153 print_debug
1154 ( 'This LPN has no MMTT records left to process.'
1155 , l_api_name
1156 );
1157 END IF;
1158 CLOSE c_check_txns;
1159
1160 fnd_message.set_name('WMS', 'WMS_DROP_LPN_NO_MTL');
1161 fnd_msg_pub.ADD;
1162 RAISE FND_API.G_EXC_ERROR;
1163 END IF;
1164 CLOSE c_check_txns;
1165
1166 l_progress := 20;
1167
1168 --
1169 -- Bug 4884284: insert WDT records for child MMTT records
1170 -- prior to calling ATF locator suggestion
1171 --
1172 l_api_return_status := fnd_api.g_ret_sts_success;
1173 insert_wdt
1174 ( x_return_status => l_api_return_status
1175 , p_organization_id => p_organization_id
1176 , p_transfer_lpn_id => p_transfer_lpn_id
1177 );
1178
1179 IF l_api_return_status <> fnd_api.g_ret_sts_success
1180 THEN
1181 IF l_debug = 1 THEN
1182 print_debug
1183 ( 'Error from insert_wdt'
1184 , l_api_name
1185 );
1186 END IF;
1187 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1188 END IF;
1189
1190 --
1191 -- This API just updates transfer_locator of each MMTT record for
1192 -- passed in transfer_lpn_id. If it fails, MMTT will not be updated
1193 -- and pick drop will continue.
1194 --
1195 -- This API needs to be called even if the LPN is cached since
1196 -- the updates to MMTT would be lost due to a rollback.
1197 --
1198 l_api_return_status := fnd_api.g_ret_sts_success;
1199 wms_op_runtime_pub_apis.update_drop_locator_for_task
1200 ( x_return_status => l_api_return_status
1201 , x_message => l_message
1202 , x_drop_lpn_option => l_drop_lpn_option
1203 , p_transfer_lpn_id => p_transfer_lpn_id
1204 );
1205
1206 IF l_debug = 1 THEN
1207 print_debug
1208 ( 'Return status from wms_op_runtime_pub_apis.update_drop_locator_for_task: ' ||
1209 g_newline || 'l_api_return_status: ' || l_api_return_status ||
1210 g_newline || 'l_message: ' || l_message ||
1211 g_newline || 'l_drop_lpn_option: ' || to_char(l_drop_lpn_option)
1212 , l_api_name
1213 );
1214 END IF;
1215
1216 IF l_api_return_status NOT IN (fnd_api.g_ret_sts_success,'W') THEN
1217 IF (l_debug = 1) THEN
1218 print_debug('Error status from update_drop_locator_for_task: ' || l_api_return_status
1219 , l_api_name);
1220 END IF;
1221
1222 IF l_api_return_status = fnd_api.g_ret_sts_error THEN
1223 RAISE fnd_api.g_exc_error;
1224 ELSE
1225 RAISE fnd_api.g_exc_unexpected_error;
1226 END IF;
1227 ELSE
1228 IF (l_debug = 1) THEN
1229 print_debug('update_drop_locator_for_task returned success', l_api_name);
1230 END IF;
1231 END IF;
1232
1233 g_current_drop_lpn.drop_lpn_option := l_drop_lpn_option;
1234
1235 --
1236 -- Set drop lpn option and return status
1237 -- in case this LPN only has one drop
1238 --
1239 x_drop_lpn_option := l_drop_lpn_option;
1240 x_return_status := l_api_return_status;
1241
1242 l_progress := 30;
1243
1244 --
1245 -- Get the drop type and other info here
1246 -- in case there is only one drop on this LPN
1247 --
1248 OPEN c_get_temp_txn_id (p_organization_id, p_transfer_lpn_id);
1249 FETCH c_get_temp_txn_id INTO l_txn_temp_id, l_txn_type_id;
1250 CLOSE c_get_temp_txn_id;
1251
1252 IF l_debug = 1 THEN
1253 print_debug
1254 ( ' Fetched temp ID: ' || to_char(l_txn_temp_id)
1255 || ' with txn type ' || to_char(l_txn_type_id)
1256 , l_api_name
1257 );
1258 END IF;
1259
1260 IF l_txn_temp_id IS NULL THEN
1261 IF l_debug = 1 THEN
1262 print_debug
1263 ( 'This LPN has no MMTT records left to process.'
1264 , l_api_name
1265 );
1266 END IF;
1267
1268 fnd_message.set_name('WMS', 'WMS_DROP_LPN_NO_MTL');
1269 fnd_msg_pub.ADD;
1270 RAISE FND_API.G_EXC_ERROR;
1271 ELSE
1272 x_first_temp_id := l_txn_temp_id;
1273 x_txn_type_id := l_txn_type_id;
1274 END IF;
1275
1276 l_api_return_status := fnd_api.g_ret_sts_success;
1277 get_group_info
1278 ( x_drop_type => x_drop_type
1279 , x_bulk_pick => x_bulk_pick
1280 , x_delivery_id => x_delivery_id
1281 , x_task_type => x_task_type
1282 , x_return_status => l_api_return_status
1283 , p_txn_temp_id => l_txn_temp_id
1284 );
1285
1286 IF l_api_return_status <> fnd_api.g_ret_sts_success
1287 THEN
1288 IF l_debug = 1 THEN
1289 print_debug
1290 ( 'Error from get_group_info'
1291 , l_api_name
1292 );
1293 END IF;
1294 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1295 END IF;
1296
1297 l_progress := 45;
1298
1299 --
1300 -- IF LPN info already cached, then return cached details
1301 --
1302 IF g_current_drop_lpn.organization_id = p_organization_id
1303 AND
1304 g_current_drop_lpn.lpn_id = p_transfer_lpn_id
1305 THEN
1306 x_multiple_drops := g_current_drop_lpn.multiple_drops;
1307 g_current_drop_lpn.current_drop_list(l_txn_temp_id) := 'PENDING';
1308 g_current_drop_lpn.temp_id_group_ref(l_txn_temp_id) := 1;
1309 IF l_debug = 1 THEN print_debug ( 'LPN info already cached ..RETURN' , l_api_name); END IF;
1310 RETURN;
1311 ELSIF g_current_drop_lpn.organization_id IS NOT NULL
1312 AND
1313 g_current_drop_lpn.lpn_id IS NOT NULL
1314 AND
1315 ( g_current_drop_lpn.organization_id <> p_organization_id
1316 OR
1317 g_current_drop_lpn.lpn_id <> p_transfer_lpn_id
1318 )
1319 THEN
1320 --
1321 -- LPN in cache is different from passed in LPN
1322 --
1323 IF l_debug = 1 THEN print_debug ( 'ELSE LPN info already cached ..clear_lpn_cache' , l_api_name); END IF;
1324 l_api_return_status := fnd_api.g_ret_sts_success;
1325 clear_lpn_cache(l_api_return_status);
1326
1327 IF l_api_return_status <> fnd_api.g_ret_sts_success
1328 THEN
1329 IF l_debug = 1 THEN
1330 print_debug ('Error from clear_lpn_cache', l_api_name);
1331 END IF;
1332 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1333 END IF;
1334 END IF;
1335
1336 g_current_drop_lpn.lpn_id := p_transfer_lpn_id;
1337 g_current_drop_lpn.organization_id := p_organization_id;
1338 g_current_drop_lpn.multiple_drops := 'FALSE';
1339 g_current_drop_lpn.drop_lpn_option := l_drop_lpn_option;
1340
1341 g_current_drop_lpn.current_drop_list.DELETE;
1342 g_current_drop_lpn.temp_id_group_ref.DELETE;
1343 g_current_drop_lpn.current_drop_list(l_txn_temp_id) := 'PENDING';
1344 g_current_drop_lpn.temp_id_group_ref(l_txn_temp_id) := 1;
1345
1346 x_multiple_drops := 'FALSE';
1347
1348 l_progress := 60;
1349
1350 --
1351 -- If staging move, return
1352 --
1353 IF x_drop_type = 'CONS_STG_MV'
1354 THEN
1355 g_current_drop_lpn.multiple_drops := 'FALSE';
1356 x_multiple_drops := 'FALSE';
1357 RETURN;
1358 END IF;
1359
1360 --
1361 -- Check number of drops on this LPN
1362 --
1363 OPEN c_num_mo_types (p_organization_id, p_transfer_lpn_id);
1364 FETCH c_num_mo_types INTO l_drop_count;
1365 CLOSE c_num_mo_types;
1366
1367 IF l_debug = 1 THEN
1368 print_debug
1369 ( '# of mo types, statuses: ' || to_char(l_drop_count)
1370 , l_api_name
1371 );
1372 END IF;
1373
1374 IF l_drop_count > 1 THEN
1375 g_current_drop_lpn.multiple_drops := 'TRUE';
1376 x_multiple_drops := 'TRUE';
1377 x_return_status := fnd_api.g_ret_sts_success;
1378 RETURN;
1379 END IF;
1380
1381 l_progress := 70;
1382
1383 OPEN c_num_txn_actions (p_organization_id, p_transfer_lpn_id);
1384 FETCH c_num_txn_actions INTO l_drop_count;
1385 CLOSE c_num_txn_actions;
1386
1387 IF l_debug = 1 THEN
1388 print_debug
1389 ( '# of txn actions: ' || to_char(l_drop_count)
1390 , l_api_name
1391 );
1392 END IF;
1393
1394 IF l_drop_count > 1 THEN
1395 g_current_drop_lpn.multiple_drops := 'TRUE';
1396 x_multiple_drops := 'TRUE';
1397 x_return_status := fnd_api.g_ret_sts_success;
1398 RETURN;
1399 END IF;
1400
1401 l_progress := 80;
1402
1403 OPEN c_get_txn_type_details (p_organization_id, p_transfer_lpn_id);
1404 FETCH c_get_txn_type_details
1405 INTO l_txn_type_id
1406 , l_txn_src_type_id
1407 , l_txn_action_id;
1408 CLOSE c_get_txn_type_details;
1409
1410 IF l_debug = 1 THEN
1411 print_debug
1412 ( 'Txn type: ' || to_char(l_txn_type_id) ||
1413 ' txn src type: ' || to_char(l_txn_src_type_id) ||
1414 ' txn action: ' || to_char(l_txn_action_id)
1415 , l_api_name
1416 );
1417 END IF;
1418
1419 l_progress := 90;
1420
1421 IF l_txn_action_id = INV_GLOBALS.G_ACTION_STGXFR
1422 AND
1423 x_drop_type <> 'CANCELLED'
1424 THEN
1425 OPEN c_num_stg_xfers (p_organization_id, p_transfer_lpn_id);
1426 FETCH c_num_stg_xfers INTO l_drop_count;
1427 CLOSE c_num_stg_xfers;
1428 --Bug 13644027 START
1429 OPEN c_delivery_cnt (p_organization_id, p_transfer_lpn_id);
1430 FETCH c_delivery_cnt INTO l_delivery_cnt;
1431 CLOSE c_delivery_cnt;
1432 IF (l_debug = 1) THEN
1433 print_debug('Before calling WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping(),Printing l_delivery_cnt:::'||l_delivery_cnt, l_api_name);
1434 END IF;
1435 --Bug 13644027 END
1436 -- bug#10062741
1437 IF (l_drop_count = 1 AND l_delivery_cnt = 0) THEN
1438
1439 OPEN c_stg_delivery_details (p_organization_id, p_transfer_lpn_id);
1440 FETCH c_stg_delivery_details BULK COLLECT INTO l_line_rows;
1441 CLOSE c_stg_delivery_details;
1442
1443 IF (l_debug = 1) THEN
1444 print_debug('Before calling WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping() to decide if we can drop into 1 LPN', l_api_name);
1445 END IF;
1446 --
1447 -- call to the shipping API.
1448 --
1449 WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping(
1450 p_line_rows => l_line_rows,
1451 x_grouping_rows => l_grouping_rows,
1452 x_return_status => l_return_status);
1453 --
1454 IF (l_return_status = FND_API.G_RET_STS_SUCCESS) THEN
1455 l_same_carton_grouping := TRUE;
1456 FOR i IN (l_grouping_rows.FIRST+1) .. l_grouping_rows.LAST LOOP
1457 IF (l_grouping_rows(i-1) <> l_grouping_rows(i)) THEN
1458 l_same_carton_grouping := FALSE;
1459 EXIT;
1460 END IF;
1461 END LOOP;
1462 ELSE
1463 l_same_carton_grouping := FALSE;
1464 END IF;
1465
1466 IF NOT(l_same_carton_grouping) THEN
1467 l_drop_count := 2;
1468 END IF;
1469
1470 END IF; --End Bug 10062741
1471
1472 IF l_debug = 1 THEN
1473 print_debug
1474 ( '# of sales order/internal order drops: ' || to_char(l_drop_count)
1475 , l_api_name
1476 );
1477 END IF;
1478 ELSIF l_txn_src_type_id = INV_GLOBALS.G_SOURCETYPE_WIP
1479 AND
1480 l_txn_action_id = INV_GLOBALS.G_ACTION_ISSUE
1481 THEN
1482 OPEN c_num_wip_issue_drops (p_organization_id, p_transfer_lpn_id);
1483 FETCH c_num_wip_issue_drops INTO l_drop_count;
1484 CLOSE c_num_wip_issue_drops;
1485
1486 IF l_debug = 1 THEN
1487 print_debug
1488 ( '# of work order drops: ' || to_char(l_drop_count)
1489 , l_api_name
1490 );
1491 END IF;
1492 ELSIF x_drop_type = 'CANCELLED'
1493 OR
1494 x_drop_type = 'OVERPICK'
1495 THEN
1496 --
1497 -- Force deconsolidation
1498 --
1499 l_drop_count := 2;
1500 ELSIF l_txn_action_id = INV_GLOBALS.G_ACTION_SUBXFR
1501 THEN
1502 -- Added for bug 12853197
1503 OPEN c_chk_mult_subinv (p_organization_id, p_transfer_lpn_id);
1504 FETCH c_chk_mult_subinv INTO g_chk_mult_subinv;
1505 IF c_chk_mult_subinv%NOTFOUND THEN
1506 g_chk_mult_subinv := 'Y';
1507 END IF;
1508 CLOSE c_chk_mult_subinv;
1509
1510 OPEN c_num_sub_xfers (p_organization_id, p_transfer_lpn_id);
1511 FETCH c_num_sub_xfers INTO l_drop_count;
1512 CLOSE c_num_sub_xfers;
1513
1514 IF l_debug = 1 THEN
1515 print_debug
1516 ( '# of sub xfers: ' || to_char(l_drop_count)||' Check Multiple Subinv exists for LPN :' || to_char(g_chk_mult_subinv) -- Modified for bug 12853197
1517 , l_api_name
1518 );
1519 END IF;
1520 ELSE
1521 IF l_debug = 1 THEN
1522 print_debug ('Unknown transaction', l_api_name);
1523 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1524 END IF;
1525 END IF;
1526
1527 l_progress := 100;
1528
1529 IF l_drop_count > 1 THEN
1530 g_current_drop_lpn.multiple_drops := 'TRUE';
1531 x_multiple_drops := 'TRUE';
1532 x_return_status := fnd_api.g_ret_sts_success;
1533 ELSIF l_drop_count = 1 THEN
1534 g_current_drop_lpn.multiple_drops := 'FALSE';
1535 x_multiple_drops := 'FALSE';
1536 ELSIF l_drop_count = 0 THEN
1537 IF l_debug = 1 THEN
1538 print_debug
1539 ( 'LPN has leftover MMTT records that cannot be processed'
1540 , l_api_name
1541 );
1542 END IF;
1543 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1544 ELSE
1545 IF l_debug = 1 THEN
1546 print_debug
1547 ( 'Invalid drop count: ' || to_char(l_drop_count)
1548 , l_api_name
1549 );
1550 END IF;
1551 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1552 END IF;
1553
1554 EXCEPTION
1555 WHEN fnd_api.g_exc_error THEN
1556 ROLLBACK TO chk_if_d_sp;
1557
1558 x_return_status := fnd_api.g_ret_sts_error;
1559
1560 fnd_msg_pub.count_and_get
1561 ( p_count => l_msg_count
1562 , p_data => l_msg_data
1563 , p_encoded => fnd_api.g_false
1564 );
1565
1566 IF l_debug = 1 THEN
1567 print_debug (l_msg_data, l_api_name);
1568 print_debug ('l_progress = ' || to_char(l_progress), l_api_name);
1569 END IF;
1570
1571 WHEN OTHERS THEN
1572 ROLLBACK TO chk_if_d_sp;
1573
1574 x_return_status := fnd_api.g_ret_sts_unexp_error;
1575
1576 IF l_debug = 1 THEN
1577 print_debug ('Other error: ' || sqlerrm, l_api_name);
1578 print_debug ('l_progress = ' || to_char(l_progress), l_api_name);
1579 END IF;
1580
1581 END chk_if_deconsolidate;
1582
1583
1584
1585 PROCEDURE group_drop_details
1586 ( p_drop_type IN VARCHAR2
1587 , x_return_status OUT NOCOPY VARCHAR2
1588 ) IS
1589
1590 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
1591 l_api_name VARCHAR2(30) := 'group_drop_details';
1592
1593 ii NUMBER := 0;
1594 jj NUMBER := 0;
1595
1596 l_dum_lpn VARCHAR2(31) := '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@';
1597
1598 l_dummy VARCHAR2(1) := NULL;
1599 l_transaction_temp_id NUMBER := NULL;
1600 l_orig_item_id NUMBER := NULL;
1601 l_content_lpn VARCHAR2(30) := NULL;
1602 l_inner_lpn_id NUMBER := NULL; --Bug6913674
1603 l_inner_lpn VARCHAR2(30) := NULL;
1604 l_serial_alloc VARCHAR2(1) := NULL;
1605 l_lot_alloc VARCHAR2(1) := NULL;
1606 l_inner_lpn_exists VARCHAR2(1) := NULL;
1607 l_loose_exists VARCHAR2(1) := NULL;
1608
1609 l_group_num NUMBER;
1610 l_cur_group_num NUMBER := 0;
1611
1612 CURSOR c_mmtt_info
1613 ( p_temp_id IN NUMBER
1614 ) IS
1615 SELECT mmtt.lpn_id
1616 , mmtt.content_lpn_id
1617 , mmtt.transfer_lpn_id
1618 , mmtt.inventory_item_id
1619 , mmtt.revision
1620 , mmtt.primary_quantity
1621 , mmtt.parent_line_id
1622 , mmtt.serial_allocated_flag
1623 FROM mtl_material_transactions_temp mmtt
1624 WHERE mmtt.transaction_temp_id = p_temp_id;
1625
1626 c_mmtt_rec c_mmtt_info%ROWTYPE;
1627
1628 CURSOR c_item_info
1629 ( p_org_id IN NUMBER
1630 , p_item_id IN NUMBER
1631 ) IS
1632 SELECT msik.concatenated_segments item_num
1633 , msik.lot_control_code lot_control
1634 , msik.serial_number_control_code serial_control
1635 , msik.primary_uom_code primary_uom_code
1636 , NVL(msik.allowed_units_lookup_code,2) uom_lookup_code
1637 FROM mtl_system_items_kfv msik
1638 WHERE msik.organization_id = p_org_id
1639 AND msik.inventory_item_id = p_item_id;
1640
1641 c_item_rec c_item_info%ROWTYPE;
1642
1643 CURSOR c_get_lpn
1644 ( p_lpn_id IN NUMBER
1645 ) IS
1646 SELECT license_plate_number
1647 FROM wms_license_plate_numbers wlpn
1648 WHERE wlpn.lpn_id = p_lpn_id;
1649
1650
1651 CURSOR c_chk_nested_bulk
1652 ( p_lpn_id IN NUMBER
1653 , p_outer_lpn_id IN NUMBER
1654 , p_org_id IN NUMBER
1655 ) IS
1656 SELECT 'x'
1657 FROM dual
1658 WHERE EXISTS
1659 ( SELECT 'x'
1660 FROM mtl_material_transactions_temp mmtt
1661 WHERE mmtt.organization_id = p_org_id
1662 AND mmtt.transfer_lpn_id = p_outer_lpn_id
1663 AND mmtt.parent_line_id = mmtt.transaction_temp_id
1664 AND mmtt.content_lpn_id = p_lpn_id
1665 );
1666
1667
1668 CURSOR c_lot_details
1669 ( p_temp_id IN NUMBER
1670 ) IS
1671 SELECT mtlt.lot_number
1672 , mtlt.primary_quantity
1673 , mtlt.serial_transaction_temp_id
1674 FROM mtl_transaction_lots_temp mtlt
1675 WHERE mtlt.transaction_temp_id = p_temp_id;
1676
1677 c_lot_dtl_rec c_lot_details%ROWTYPE;
1678
1679
1680 CURSOR c_srl_lot_details
1681 ( p_temp_id IN NUMBER
1682 ) IS
1683 SELECT msnt.fm_serial_number
1684 FROM mtl_serial_numbers_temp msnt
1685 WHERE msnt.transaction_temp_id = p_temp_id;
1686
1687
1688 CURSOR c_srl_numbers
1689 ( p_temp_id IN NUMBER
1690 ) IS
1691 SELECT msnt.fm_serial_number
1692 FROM mtl_serial_numbers_temp msnt
1693 WHERE msnt.transaction_temp_id = p_temp_id;
1694
1695 BEGIN
1696 x_return_status := fnd_api.g_ret_sts_success;
1697
1698 IF l_debug = 1 THEN
1699 print_debug
1700 ( 'Entered with parameters: ' || g_newline ||
1701 'p_drop_type => ' || p_drop_type
1702 , l_api_name
1703 );
1704 END IF;
1705
1706 SAVEPOINT group_drop_det_sp;
1707
1708 ii := g_current_drop_lpn.current_drop_list.FIRST;
1709 jj := g_current_drop_lpn.current_drop_list.LAST;
1710
1711 l_transaction_temp_id := ii;
1712
1713 IF l_debug =1 THEN
1714 print_debug
1715 ( '# of temp IDs in group: '
1716 || to_char(g_current_drop_lpn.current_drop_list.COUNT)
1717 || ', first temp ID: ' || to_char(ii)
1718 || ', last temp ID: ' || to_char(jj)
1719 , l_api_name
1720 );
1721 END IF;
1722
1723 DELETE mtl_allocations_gtmp;
1724
1725 WHILE (ii <= jj)
1726 LOOP
1727
1728 OPEN c_mmtt_info (l_transaction_temp_id);
1729 FETCH c_mmtt_info INTO c_mmtt_rec;
1730
1731 IF c_mmtt_info%NOTFOUND THEN
1732 IF l_debug = 1 THEN
1733 print_debug
1734 ( 'Invalid temp ID: ' || to_char(l_transaction_temp_id)
1735 , l_api_name
1736 );
1737 END IF;
1738 CLOSE c_mmtt_info;
1739 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1740 ELSE
1741 IF l_debug = 1 THEN
1742 print_debug
1743 ( 'Fetched temp ID: ' || to_char(l_transaction_temp_id) || g_newline ||
1744 'LPN ID: ' || to_char(c_mmtt_rec.lpn_id) || g_newline ||
1745 'Content LPN ID: ' || to_char(c_mmtt_rec.content_lpn_id) || g_newline ||
1746 'Xfer LPN ID: ' || to_char(c_mmtt_rec.transfer_lpn_id) || g_newline ||
1747 'Item ID: ' || to_char(c_mmtt_rec.inventory_item_id) || g_newline ||
1748 'Revision: ' || c_mmtt_rec.revision || g_newline ||
1749 'Primary qty: ' || to_char(c_mmtt_rec.primary_quantity) || g_newline ||
1750 'Parent line ID: ' || to_char(c_mmtt_rec.parent_line_id) || g_newline ||
1751 'Serial alloc flag: ' || c_mmtt_rec.serial_allocated_flag
1752 , l_api_name
1753 );
1754 END IF;
1755 END IF;
1756 CLOSE c_mmtt_info;
1757
1758 IF c_mmtt_rec.inventory_item_id <> NVL(l_orig_item_id,0) THEN
1759 OPEN c_item_info
1760 ( g_current_drop_lpn.organization_id
1761 , c_mmtt_rec.inventory_item_id
1762 );
1763 FETCH c_item_info INTO c_item_rec;
1764 CLOSE c_item_info;
1765
1766 --
1767 -- Check if serials allocated
1768 --
1769 IF c_item_rec.serial_control > 1
1770 AND
1771 c_item_rec.serial_control <> 6
1772 THEN
1773 IF c_mmtt_rec.parent_line_id IS NOT NULL
1774 THEN
1775 l_serial_alloc := c_mmtt_rec.serial_allocated_flag;
1776 ELSE
1777 l_serial_alloc := 'Y';
1778 END IF;
1779 END IF;
1780
1781 IF c_item_rec.lot_control > 1
1782 THEN
1783 l_lot_alloc := 'Y';
1784 ELSE
1785 l_lot_alloc := NULL;
1786 END IF;
1787
1788 l_orig_item_id := c_mmtt_rec.inventory_item_id;
1789 END IF;
1790
1791 IF l_debug = 1 THEN
1792 print_debug
1793 ( 'Item #: ' || c_item_rec.item_num || g_newline ||
1794 'Lot control code: ' || to_char(c_item_rec.lot_control) || g_newline ||
1795 'Serial control code: ' || to_char(c_item_rec.serial_control) || g_newline ||
1796 'Primary UOM code: ' || c_item_rec.primary_uom_code || g_newline ||
1797 'Allowed units code: ' || to_char(c_item_rec.uom_lookup_code) || g_newline ||
1798 'l_serial_alloc: ' || l_serial_alloc || g_newline ||
1799 'l_lot_alloc: ' || l_lot_alloc
1800 , l_api_name
1801 );
1802 END IF;
1803
1804 --
1805 -- Check if dropping content/inner LPN
1806 -- As of 11.5.10 LPNs can nest on Pick Load
1807 -- only if the entire LPN is picked
1808 --
1809 IF c_mmtt_rec.content_lpn_id IS NOT NULL
1810 AND
1811 c_mmtt_rec.content_lpn_id <> c_mmtt_rec.transfer_lpn_id
1812 THEN
1813 OPEN c_get_lpn (c_mmtt_rec.content_lpn_id);
1814 FETCH c_get_lpn INTO l_content_lpn;
1815 CLOSE c_get_lpn;
1816 ELSIF c_mmtt_rec.parent_line_id IS NOT NULL
1817 AND
1818 c_mmtt_rec.lpn_id IS NOT NULL
1819 AND
1820 c_mmtt_rec.lpn_id <> g_current_drop_lpn.lpn_id
1821 AND
1822 (
1823 ( NVL(l_lot_alloc,'N') = 'Y'
1824 OR
1825 NVL(l_serial_alloc,'N') = 'Y'
1826 )
1827 OR
1828 ( p_drop_type = 'WIP_ISSUE'
1829 OR
1830 p_drop_type = 'WIP_SUB_XFER'
1831 )
1832 )
1833 THEN
1834 OPEN c_chk_nested_bulk
1835 ( c_mmtt_rec.lpn_id
1836 , g_current_drop_lpn.lpn_id
1837 , g_current_drop_lpn.organization_id
1838 );
1839 FETCH c_chk_nested_bulk INTO l_dummy;
1840
1841 IF c_chk_nested_bulk%FOUND THEN
1842 OPEN c_get_lpn (c_mmtt_rec.lpn_id);
1843 FETCH c_get_lpn INTO l_inner_lpn;
1844 CLOSE c_get_lpn;
1845
1846 -- Bug5659809: update last_update_date and last_update_by as well
1847 UPDATE wms_license_plate_numbers
1848 SET lpn_context = WMS_Container_PUB.LPN_CONTEXT_INV
1849 , last_update_date = SYSDATE
1850 , last_updated_by = fnd_global.user_id
1851 WHERE lpn_id = c_mmtt_rec.lpn_id;
1852
1853 IF l_debug = 1 THEN
1854 print_debug
1855 ( 'Updated LPN context back to 1 for LPN ' || l_inner_lpn
1856 , l_api_name
1857 );
1858 END IF;
1859
1860 END IF;
1861
1862 CLOSE c_chk_nested_bulk;
1863 END IF;
1864
1865 IF l_debug = 1 THEN
1866 print_debug
1867 ( 'Content LPN: ' || l_content_lpn ||
1868 ', inner LPN: ' || l_inner_lpn
1869 , l_api_name
1870 );
1871 END IF;
1872
1873 IF l_content_lpn IS NOT NULL
1874 AND
1875 p_drop_type <> 'WIP_ISSUE'
1876 AND
1877 p_drop_type <> 'WIP_SUB_XFER'
1878 THEN
1879 BEGIN
1880 IF l_debug = 1 THEN
1881 print_debug
1882 ( 'Inserting content LPN ' || l_content_lpn
1883 , l_api_name
1884 );
1885 END IF;
1886
1887 l_cur_group_num := l_cur_group_num + 1;
1888 g_current_drop_lpn.temp_id_group_ref(l_transaction_temp_id)
1889 := l_cur_group_num;
1890
1891 INSERT INTO mtl_allocations_gtmp
1892 ( inventory_item_id
1893 , item_number
1894 , group_number
1895 , content_lpn
1896 , inner_lpn
1897 , revision
1898 , lot_number
1899 , serial_number
1900 , lot_alloc
1901 , serial_alloc
1902 , primary_quantity
1903 , primary_uom_code
1904 , uom_lookup_code
1905 )
1906 VALUES
1907 ( c_mmtt_rec.inventory_item_id --9593852
1908 , NULL
1909 , l_cur_group_num
1910 , l_content_lpn
1911 , NULL
1912 , NULL
1913 , NULL
1914 , NULL
1915 , NULL
1916 , NULL
1917 , NULL
1918 , NULL
1919 , NULL
1920 );
1921 EXCEPTION
1922 WHEN OTHERS THEN
1923 IF l_debug = 1 THEN
1924 print_debug
1925 ( 'Unexpected error inserting content LPN: ' || sqlerrm
1926 , l_api_name
1927 );
1928 END IF;
1929 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1930 END;
1931 ELSIF p_drop_type = 'WIP_ISSUE'
1932 OR
1933 p_drop_type = 'WIP_SUB_XFER'
1934 THEN
1935 BEGIN
1936 SELECT group_number
1937 INTO l_group_num
1938 FROM mtl_allocations_gtmp mtg
1939 WHERE mtg.inventory_item_id = c_mmtt_rec.inventory_item_id
1940 AND NVL(mtg.revision,'@@@@') = NVL(c_mmtt_rec.revision,'@@@@')
1941 AND NVL(mtg.inner_lpn,l_dum_lpn)
1942 = NVL(l_content_lpn, NVL(l_inner_lpn,l_dum_lpn))
1943 AND mtg.content_lpn IS NULL;
1944
1945 IF l_debug = 1 THEN
1946 print_debug
1947 ( 'Updating item ' || c_item_rec.item_num ||
1948 ', group number ' || to_char(l_group_num) ||
1949 ', revision ' || c_mmtt_rec.revision ||
1950 ' with primary qty ' || to_char(c_mmtt_rec.primary_quantity)
1951 , l_api_name
1952 );
1953 END IF;
1954
1955 g_current_drop_lpn.temp_id_group_ref(l_transaction_temp_id)
1956 := l_group_num;
1957
1958 UPDATE mtl_allocations_gtmp
1959 SET primary_quantity
1960 = primary_quantity + c_mmtt_rec.primary_quantity
1961 WHERE group_number = l_group_num;
1962
1963 EXCEPTION
1964 WHEN NO_DATA_FOUND THEN
1965 IF l_debug = 1 THEN
1966 print_debug
1967 ( 'Inserting item ' || c_item_rec.item_num ||
1968 ', revision ' || c_mmtt_rec.revision ||
1969 ' with primary qty ' || to_char(c_mmtt_rec.primary_quantity) ||
1970 ' and primary uom ' || c_item_rec.primary_uom_code
1971 , l_api_name
1972 );
1973 END IF;
1974
1975 l_cur_group_num := l_cur_group_num + 1;
1976 g_current_drop_lpn.temp_id_group_ref(l_transaction_temp_id)
1977 := l_cur_group_num;
1978
1979 INSERT INTO mtl_allocations_gtmp
1980 ( inventory_item_id
1981 , item_number
1982 , group_number
1983 , content_lpn
1984 , inner_lpn
1985 , revision
1986 , lot_number
1987 , serial_number
1988 , lot_alloc
1989 , serial_alloc
1990 , primary_quantity
1991 , primary_uom_code
1992 , uom_lookup_code
1993 )
1994 VALUES
1995 ( c_mmtt_rec.inventory_item_id
1996 , c_item_rec.item_num
1997 , l_cur_group_num
1998 , NULL
1999 , NVL(l_content_lpn, l_inner_lpn)
2000 , c_mmtt_rec.revision
2001 , NULL
2002 , NULL
2003 , l_lot_alloc
2004 , l_serial_alloc
2005 , c_mmtt_rec.primary_quantity
2006 , c_item_rec.primary_uom_code
2007 , c_item_rec.uom_lookup_code
2008 );
2009
2010 WHEN OTHERS THEN
2011 IF l_debug = 1 THEN
2012 print_debug
2013 ( 'Unexpected error updating record for WIP drop ' || sqlerrm
2014 , l_api_name
2015 );
2016 END IF;
2017 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2018 END;
2019 ELSIF NVL(l_lot_alloc,'N') = 'Y'
2020 THEN
2021 OPEN c_lot_details (l_transaction_temp_id);
2022 FETCH c_lot_details INTO c_lot_dtl_rec;
2023
2024 IF c_lot_details%NOTFOUND
2025 THEN
2026 IF l_debug = 1 THEN
2027 print_debug
2028 ( 'No MTLT record found for temp ID '
2029 || to_char(l_transaction_temp_id)
2030 , l_api_name
2031 );
2032 END IF;
2033 CLOSE c_lot_details;
2034 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2035 END IF;
2036
2037 IF c_lot_details%ISOPEN
2038 THEN
2039 CLOSE c_lot_details;
2040 END IF;
2041
2042 BEGIN
2043 SELECT group_number
2044 INTO l_group_num
2045 FROM mtl_allocations_gtmp mtg
2046 WHERE mtg.inventory_item_id = c_mmtt_rec.inventory_item_id
2047 AND mtg.lot_number = c_lot_dtl_rec.lot_number
2048 AND NVL(mtg.inner_lpn, l_dum_lpn)
2049 = NVL(l_inner_lpn, l_dum_lpn)
2050 AND NVL(mtg.revision,'@@@@')
2051 = NVL(c_mmtt_rec.revision,'@@@@')
2052 AND mtg.content_lpn IS NULL
2053 AND rownum < 2 ; --Bug#12853197
2054
2055 IF l_debug = 1 THEN
2056 print_debug
2057 ( 'Found group number ' || to_char(l_group_num) ||
2058 ' for item ' || c_item_rec.item_num ||
2059 ', revision ' || c_mmtt_rec.revision ||
2060 ', lot number ' || c_lot_dtl_rec.lot_number ||
2061 ', serial temp ID ' || to_char(c_lot_dtl_rec.serial_transaction_temp_id)
2062 , l_api_name
2063 );
2064 END IF;
2065
2066 g_current_drop_lpn.temp_id_group_ref(l_transaction_temp_id)
2067 := l_group_num;
2068
2069 IF NVL(l_serial_alloc,'N') = 'N'
2070 THEN
2071 IF l_debug = 1 THEN
2072 print_debug
2073 ( 'Updating item ' || c_item_rec.item_num ||
2074 ', revision ' || c_mmtt_rec.revision ||
2075 ', lot number ' || c_lot_dtl_rec.lot_number ||
2076 ' with primary qty ' || to_char(c_lot_dtl_rec.primary_quantity)
2077 , l_api_name
2078 );
2079 END IF;
2080
2081 UPDATE mtl_allocations_gtmp
2082 SET primary_quantity
2083 = primary_quantity + c_lot_dtl_rec.primary_quantity
2084 WHERE group_number = l_group_num;
2085 END IF;
2086
2087 EXCEPTION
2088 WHEN NO_DATA_FOUND THEN
2089 l_cur_group_num := l_cur_group_num + 1;
2090 g_current_drop_lpn.temp_id_group_ref(l_transaction_temp_id)
2091 := l_cur_group_num;
2092 l_group_num := l_cur_group_num;
2093
2094 IF NVL(l_serial_alloc,'N') = 'N'
2095 THEN
2096 IF l_debug = 1 THEN
2097 print_debug
2098 ( 'Inserting item ' || c_item_rec.item_num ||
2099 ', group number ' || to_char(l_group_num) ||
2100 ', revision ' || c_mmtt_rec.revision ||
2101 ', lot number ' || c_lot_dtl_rec.lot_number ||
2102 ', primary qty ' || to_char(c_lot_dtl_rec.primary_quantity) ||
2103 ', primary uom code ' || c_item_rec.primary_uom_code
2104 , l_api_name
2105 );
2106 END IF;
2107
2108 INSERT INTO mtl_allocations_gtmp
2109 ( inventory_item_id
2110 , item_number
2111 , group_number
2112 , content_lpn
2113 , inner_lpn
2114 , loose_qty_exists
2115 , revision
2116 , lot_number
2117 , serial_number
2118 , lot_alloc
2119 , serial_alloc
2120 , transaction_quantity
2121 , primary_quantity
2122 , primary_uom_code
2123 , uom_lookup_code
2124 )
2125 VALUES
2126 ( c_mmtt_rec.inventory_item_id
2127 , c_item_rec.item_num
2128 , l_group_num
2129 , NULL
2130 , l_inner_lpn
2131 , 'Y'
2132 , c_mmtt_rec.revision
2133 , c_lot_dtl_rec.lot_number
2134 , NULL
2135 , l_lot_alloc
2136 , l_serial_alloc
2137 , NULL
2138 , c_mmtt_rec.primary_quantity
2139 , c_item_rec.primary_uom_code
2140 , c_item_rec.uom_lookup_code
2141 );
2142 END IF;
2143
2144 WHEN OTHERS THEN
2145 IF l_debug = 1 THEN
2146 print_debug
2147 ( 'Unexpected error checking if lot exists: ' || sqlerrm
2148 , l_api_name
2149 );
2150 END IF;
2151 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2152 END;
2153
2154 IF NVL(l_serial_alloc,'N') = 'Y'
2155 THEN
2156 FOR c_srl_lot_dtl_rec IN c_srl_lot_details (c_lot_dtl_rec.serial_transaction_temp_id)
2157 LOOP
2158 BEGIN
2159 IF l_debug = 1 THEN
2160 print_debug
2161 ( 'Inserting item ' || c_item_rec.item_num ||
2162 ', group # ' || to_char(l_group_num) ||
2163 ', lot number ' || c_lot_dtl_rec.lot_number ||
2164 ', serial # ' || c_srl_lot_dtl_rec.fm_serial_number
2165 , l_api_name
2166 );
2167 END IF;
2168
2169 INSERT INTO mtl_allocations_gtmp
2170 ( inventory_item_id
2171 , item_number
2172 , group_number
2173 , content_lpn
2174 , inner_lpn
2175 , loose_qty_exists
2176 , revision
2177 , lot_number
2178 , serial_number
2179 , lot_alloc
2180 , serial_alloc
2181 , transaction_quantity
2182 , primary_quantity
2183 , primary_uom_code
2184 , uom_lookup_code
2185 )
2186 VALUES
2187 ( c_mmtt_rec.inventory_item_id
2188 , c_item_rec.item_num
2189 , l_group_num
2190 , NULL
2191 , l_inner_lpn
2192 , 'Y'
2193 , c_mmtt_rec.revision
2194 , c_lot_dtl_rec.lot_number
2195 , c_srl_lot_dtl_rec.fm_serial_number
2196 , l_lot_alloc
2197 , l_serial_alloc
2198 , NULL
2199 , 1
2200 , c_item_rec.primary_uom_code
2201 , c_item_rec.uom_lookup_code
2202 );
2203 EXCEPTION
2204 WHEN OTHERS THEN
2205 IF l_debug = 1 THEN
2206 print_debug
2207 ( 'Unexpected error inserting allocated serials: ' || sqlerrm
2208 , l_api_name
2209 );
2210 END IF;
2211 IF c_srl_lot_details%ISOPEN THEN
2212 CLOSE c_srl_lot_details;
2213 END IF;
2214 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2215 END;
2216 END LOOP;
2217 END IF; -- end if serials allocated for lot item
2218 ELSIF NVL(l_serial_alloc,'N') = 'Y' THEN
2219 --
2220 -- Serial allocated (not lot controlled)
2221 --
2222 BEGIN
2223 SELECT group_number
2224 INTO l_group_num
2225 FROM mtl_allocations_gtmp mtg
2226 WHERE mtg.inventory_item_id = c_mmtt_rec.inventory_item_id
2227 AND NVL(mtg.revision,'@@@@') = NVL(c_mmtt_rec.revision,'@@@@')
2228 AND NVL(mtg.inner_lpn, l_dum_lpn)
2229 = NVL(l_inner_lpn, l_dum_lpn)
2230 AND mtg.content_lpn IS NULL
2231 AND ROWNUM<2; --Bug#12853197
2232
2233 IF l_debug = 1 THEN
2234 print_debug
2235 ( 'Found item ' || c_item_rec.item_num ||
2236 ', group number ' || to_char(l_group_num) ||
2237 ', revision ' || c_mmtt_rec.revision ||
2238 ' with inner LPN ' || l_inner_lpn
2239 , l_api_name
2240 );
2241 END IF;
2242
2243 g_current_drop_lpn.temp_id_group_ref(l_transaction_temp_id)
2244 := l_group_num;
2245
2246 EXCEPTION
2247 WHEN NO_DATA_FOUND THEN
2248 l_cur_group_num := l_cur_group_num + 1;
2249 g_current_drop_lpn.temp_id_group_ref(l_transaction_temp_id)
2250 := l_cur_group_num;
2251 l_group_num := l_cur_group_num;
2252 END;
2253
2254 FOR c_srl_numbers_rec IN c_srl_numbers (l_transaction_temp_id)
2255 LOOP
2256 BEGIN
2257 IF l_debug = 1 THEN
2258 print_debug
2259 ( 'Inserting item ' || c_item_rec.item_num ||
2260 ', serial # ' || c_srl_numbers_rec.fm_serial_number
2261 , l_api_name
2262 );
2263 END IF;
2264
2265 INSERT INTO mtl_allocations_gtmp
2266 ( inventory_item_id
2267 , item_number
2268 , group_number
2269 , content_lpn
2270 , inner_lpn
2271 , loose_qty_exists
2272 , revision
2273 , lot_number
2274 , serial_number
2275 , lot_alloc
2276 , serial_alloc
2277 , transaction_quantity
2278 , primary_quantity
2279 , primary_uom_code
2280 , uom_lookup_code
2281 )
2282 VALUES
2283 ( c_mmtt_rec.inventory_item_id
2284 , c_item_rec.item_num
2285 , l_group_num
2286 , NULL
2287 , l_inner_lpn
2288 , 'Y'
2289 , c_mmtt_rec.revision
2290 , NULL
2291 , c_srl_numbers_rec.fm_serial_number
2292 , l_lot_alloc
2293 , l_serial_alloc
2294 , NULL
2295 , 1
2296 , c_item_rec.primary_uom_code
2297 , c_item_rec.uom_lookup_code
2298 );
2299 EXCEPTION
2300 WHEN OTHERS THEN
2301 IF l_debug = 1 THEN
2302 print_debug
2303 ( 'Unexpected error inserting allocated serials: ' || sqlerrm
2304 , l_api_name
2305 );
2306 END IF;
2307 IF c_srl_numbers%ISOPEN THEN
2308 CLOSE c_srl_numbers;
2309 END IF;
2310 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2311 END;
2312 END LOOP;
2313 ELSE
2314 --
2315 -- No lots or serials allocated, or item is vanilla
2316 -- or revision controlled
2317 --
2318
2319 --
2320 -- For bulk picks null out LPN stamped by Pick Load
2321 -- on the child record
2322 -- Bug6913674 removed SUB & LOC from being nulled out
2323 IF c_mmtt_rec.parent_line_id IS NOT NULL
2324 THEN
2325 UPDATE mtl_material_transactions_temp mmtt
2326 SET lpn_id = NULL
2327 , content_lpn_id = NULL
2328 WHERE mmtt.transaction_temp_id = l_transaction_temp_id;
2329 END IF;
2330
2331 BEGIN
2332 SELECT group_number
2333 INTO l_group_num
2334 FROM mtl_allocations_gtmp mtg
2335 WHERE mtg.inventory_item_id = c_mmtt_rec.inventory_item_id
2336 AND NVL(mtg.revision,'@@@@') = NVL(c_mmtt_rec.revision,'@@@@')
2337 AND mtg.inner_lpn IS NULL
2338 AND mtg.content_lpn IS NULL;
2339
2340 IF l_debug = 1 THEN
2341 print_debug
2342 ( 'Updating item ' || c_item_rec.item_num ||
2343 ', group number ' || to_char(l_group_num) ||
2344 ', revision ' || c_mmtt_rec.revision ||
2345 ' with primary qty ' || to_char(c_mmtt_rec.primary_quantity)
2346 , l_api_name
2347 );
2348 END IF;
2349
2350 g_current_drop_lpn.temp_id_group_ref(l_transaction_temp_id)
2351 := l_group_num;
2352
2353 UPDATE mtl_allocations_gtmp
2354 SET primary_quantity
2355 = primary_quantity + c_mmtt_rec.primary_quantity
2356 WHERE group_number = l_group_num;
2357
2358 EXCEPTION
2359 WHEN NO_DATA_FOUND THEN
2360 IF l_debug = 1 THEN
2361 print_debug
2362 ( 'Inserting item ' || c_item_rec.item_num ||
2363 ', revision ' || c_mmtt_rec.revision ||
2364 ' with primary qty ' || to_char(c_mmtt_rec.primary_quantity) ||
2365 ', primary uom code ' || c_item_rec.primary_uom_code
2366 , l_api_name
2367 );
2368 END IF;
2369
2370 IF c_mmtt_rec.parent_line_id IS NOT NULL
2371 AND
2372 p_drop_type <> 'WIP_ISSUE'
2373 AND
2374 p_drop_type <> 'WIP_SUB_XFER'
2375 THEN
2376 BEGIN
2377 SELECT 'x'
2378 INTO l_dummy
2379 FROM dual
2380 WHERE EXISTS
2381 ( SELECT 'x'
2382 FROM mtl_material_transactions_temp mmtt
2383 WHERE mmtt.organization_id = g_current_drop_lpn.organization_id
2384 AND mmtt.transfer_lpn_id = g_current_drop_lpn.lpn_id
2385 AND mmtt.parent_line_id = mmtt.transaction_temp_id
2386 AND mmtt.transaction_quantity > 0
2387 AND mmtt.inventory_item_id = c_mmtt_rec.inventory_item_id
2388 AND NVL(mmtt.revision,'@@@@') = NVL(c_mmtt_rec.revision,'@@@@')
2389 AND mmtt.content_lpn_id IS NOT NULL
2390 AND mmtt.content_lpn_id <> mmtt.transfer_lpn_id
2391 );
2392 l_inner_lpn_exists := 'Y';
2393 EXCEPTION
2394 WHEN NO_DATA_FOUND THEN
2395 l_inner_lpn_exists := 'N';
2396 END;
2397
2398 BEGIN
2399 SELECT 'x'
2400 INTO l_dummy
2401 FROM dual
2402 WHERE EXISTS
2403 ( SELECT 'x'
2404 FROM mtl_material_transactions_temp mmtt
2405 WHERE mmtt.organization_id = g_current_drop_lpn.organization_id
2406 AND mmtt.transfer_lpn_id = g_current_drop_lpn.lpn_id
2407 AND mmtt.parent_line_id = mmtt.transaction_temp_id
2408 AND mmtt.transaction_quantity > 0
2409 AND mmtt.inventory_item_id = c_mmtt_rec.inventory_item_id
2410 AND NVL(mmtt.revision,'@@@@') = NVL(c_mmtt_rec.revision,'@@@@')
2411 AND ( mmtt.content_lpn_id IS NULL
2412 OR
2413 mmtt.content_lpn_id = mmtt.transfer_lpn_id
2414 )
2415 );
2416 l_loose_exists := 'Y';
2417 EXCEPTION
2418 WHEN NO_DATA_FOUND THEN
2419 l_loose_exists := 'N';
2420 END;
2421
2422 IF l_inner_lpn_exists = 'N'
2423 AND
2424 l_loose_exists = 'N'
2425 THEN
2426 IF l_debug = 1 THEN
2427 print_debug
2428 ( 'No loose or packed quantities available.'
2429 , l_api_name
2430 );
2431 END IF;
2432
2433 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2434 END IF;
2435
2436 END IF;
2437
2438 IF l_debug = 1 THEN
2439 print_debug
2440 ( 'l_inner_lpn_exists: ' || l_inner_lpn_exists || ', ' ||
2441 'l_loose_exists: ' || l_loose_exists
2442 , l_api_name
2443 );
2444 END IF;
2445
2446
2447 IF l_inner_lpn_exists = 'Y'
2448 THEN
2449 --Bug6913674
2450 SELECT mmtt.content_lpn_id INTO l_inner_lpn_id
2451 FROM mtl_material_transactions_temp mmtt
2452 WHERE mmtt.organization_id = g_current_drop_lpn.organization_id
2453 AND mmtt.transfer_lpn_id = g_current_drop_lpn.lpn_id
2454 AND mmtt.parent_line_id = mmtt.transaction_temp_id
2455 AND mmtt.transaction_quantity > 0
2456 AND mmtt.inventory_item_id = c_mmtt_rec.inventory_item_id
2457 AND NVL(mmtt.revision,'@@@@') = NVL(c_mmtt_rec.revision,'@@@@')
2458 AND mmtt.content_lpn_id IS NOT NULL
2459 AND mmtt.content_lpn_id <> mmtt.transfer_lpn_id ;
2460 OPEN c_get_lpn (l_inner_lpn_id);
2461 FETCH c_get_lpn INTO l_inner_lpn;
2462 CLOSE c_get_lpn;
2463 --Bug6913674
2464
2465
2466 -- Bug5659809: update last_update_date and last_update_by as well
2467 UPDATE wms_license_plate_numbers
2468 SET lpn_context = WMS_Container_PUB.LPN_CONTEXT_INV
2469 , last_update_date = SYSDATE
2470 , last_updated_by = fnd_global.user_id
2471 WHERE lpn_id IN
2472 ( SELECT mmtt.content_lpn_id
2473 FROM mtl_material_transactions_temp mmtt
2474 WHERE mmtt.organization_id = g_current_drop_lpn.organization_id
2475 AND mmtt.transfer_lpn_id = g_current_drop_lpn.lpn_id
2476 AND mmtt.parent_line_id = mmtt.transaction_temp_id
2477 AND mmtt.content_lpn_id IS NOT NULL
2478 AND mmtt.content_lpn_id <> mmtt.transfer_lpn_id
2479 AND mmtt.inventory_item_id = c_mmtt_rec.inventory_item_id
2480 AND NVL(mmtt.revision,'@@@@') = NVL(c_mmtt_rec.revision,'@@@@')
2481 );
2482
2483 IF l_debug = 1 AND SQL%FOUND
2484 THEN
2485 print_debug
2486 ( 'Updated LPN context back to 1 for nested LPN(s)'
2487 , l_api_name
2488 );
2489 END IF;
2490 END IF;
2491
2492 IF l_loose_exists = 'Y'
2493 THEN
2494 -- Bug5659809: update last_update_date and last_update_by as well
2495 UPDATE wms_license_plate_numbers
2496 SET lpn_context = WMS_Container_PUB.LPN_CONTEXT_INV
2497 , last_update_date = SYSDATE
2498 , last_updated_by = fnd_global.user_id
2499 WHERE lpn_id IN
2500 ( SELECT mmtt.content_lpn_id
2501 FROM mtl_material_transactions_temp mmtt
2502 WHERE mmtt.organization_id = g_current_drop_lpn.organization_id
2503 AND mmtt.transfer_lpn_id = g_current_drop_lpn.lpn_id
2504 AND mmtt.parent_line_id = mmtt.transaction_temp_id
2505 AND mmtt.content_lpn_id IS NOT NULL
2506 AND mmtt.content_lpn_id = mmtt.transfer_lpn_id
2507 AND mmtt.inventory_item_id = c_mmtt_rec.inventory_item_id
2508 AND NVL(mmtt.revision,'@@@@') = NVL(c_mmtt_rec.revision,'@@@@')
2509 );
2510
2511 IF l_debug = 1 AND SQL%FOUND
2512 THEN
2513 print_debug
2514 ( 'Updated LPN context back to 1 for content/transfer LPN'
2515 , l_api_name
2516 );
2517 END IF;
2518 END IF;
2519
2520 l_cur_group_num := l_cur_group_num + 1;
2521 g_current_drop_lpn.temp_id_group_ref(l_transaction_temp_id)
2522 := l_cur_group_num;
2523
2524 INSERT INTO mtl_allocations_gtmp
2525 ( inventory_item_id
2526 , item_number
2527 , group_number
2528 , content_lpn
2529 , inner_lpn
2530 , inner_lpn_exists
2531 , loose_qty_exists
2532 , revision
2533 , lot_number
2534 , serial_number
2535 , lot_alloc
2536 , serial_alloc
2537 , transaction_quantity
2538 , primary_quantity
2539 , primary_uom_code
2540 , uom_lookup_code
2541 )
2542 VALUES
2543 ( c_mmtt_rec.inventory_item_id
2544 , c_item_rec.item_num
2545 , l_cur_group_num
2546 , NULL
2547 , l_inner_lpn --Bug6913674
2548 , l_inner_lpn_exists
2549 , l_loose_exists
2550 , c_mmtt_rec.revision
2551 , NULL
2552 , NULL
2553 , l_lot_alloc
2554 , l_serial_alloc
2555 , NULL
2556 , c_mmtt_rec.primary_quantity
2557 , c_item_rec.primary_uom_code
2558 , c_item_rec.uom_lookup_code
2559 );
2560
2561 WHEN OTHERS THEN
2562 IF l_debug = 1 THEN
2563 print_debug
2564 ( 'Unexpected error checking if record for ' ||
2565 'vanilla/revision/serial (not allocated) exists: ' || sqlerrm
2566 , l_api_name
2567 );
2568 END IF;
2569 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
2570 END;
2571 END IF;
2572
2573 IF ii < jj THEN
2574 ii := g_current_drop_lpn.current_drop_list.NEXT(ii);
2575 l_transaction_temp_id := ii;
2576 ELSE
2577 EXIT;
2578 END IF;
2579
2580 IF l_debug = 1 THEN
2581 print_debug
2582 ( 'ii = ' || to_char(ii)
2583 , l_api_name
2584 );
2585 END IF;
2586
2587 END LOOP;
2588
2589 EXCEPTION
2590 WHEN OTHERS THEN
2591 ROLLBACK to group_drop_det_sp;
2592
2593 x_return_status := fnd_api.g_ret_sts_unexp_error;
2594
2595 IF l_debug = 1 THEN
2596 print_debug ('Other error: ' || sqlerrm, l_api_name);
2597 END IF;
2598
2599 IF c_mmtt_info%ISOPEN THEN
2600 CLOSE c_mmtt_info;
2601 END IF;
2602
2603 END group_drop_details;
2604
2605
2606
2607 PROCEDURE split_mmtt
2608 ( x_new_temp_id OUT NOCOPY NUMBER
2609 , x_return_status OUT NOCOPY VARCHAR2
2610 , p_temp_id IN NUMBER
2611 ) IS
2612
2613 l_api_name VARCHAR2(30) := 'split_mmtt';
2614 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
2615
2616 l_new_temp_id NUMBER;
2617
2618 BEGIN
2619 x_return_status := fnd_api.g_ret_sts_success;
2620
2621 IF l_debug = 1 THEN
2622 print_debug
2623 ( 'Entered with p_temp_id => ' || to_char(p_temp_id)
2624 , l_api_name
2625 );
2626 END IF;
2627
2628 SAVEPOINT split_mmtt_sp;
2629
2630 SELECT mtl_material_transactions_s.NEXTVAL
2631 INTO l_new_temp_id
2632 FROM dual;
2633
2634 IF l_debug = 1 THEN
2635 print_debug
2636 ( 'About to insert temp ID ' || to_char(l_new_temp_id)
2637 , l_api_name
2638 );
2639 END IF;
2640
2641 INSERT INTO mtl_material_transactions_temp
2642 ( transaction_header_id
2643 , transaction_temp_id
2644 , source_code
2645 , source_line_id
2646 , transaction_mode
2647 , lock_flag
2648 , last_update_date
2649 , last_updated_by
2650 , creation_date
2651 , created_by
2652 , last_update_login
2653 , request_id
2654 , program_application_id
2655 , program_id
2656 , program_update_date
2657 , inventory_item_id
2658 , revision
2659 , organization_id
2660 , subinventory_code
2661 , locator_id
2662 , transaction_quantity
2663 , primary_quantity
2664 , transaction_uom
2665 , transaction_cost
2666 , transaction_type_id
2667 , transaction_action_id
2668 , transaction_source_type_id
2669 , transaction_source_id
2670 , transaction_source_name
2671 , transaction_date
2672 , acct_period_id
2673 , distribution_account_id
2674 , transaction_reference
2675 , requisition_line_id
2676 , requisition_distribution_id
2677 , reason_id
2678 , lot_number
2679 , lot_expiration_date
2680 , serial_number
2681 , receiving_document
2682 , demand_id
2683 , rcv_transaction_id
2684 , move_transaction_id
2685 , completion_transaction_id
2686 , wip_entity_type
2687 , schedule_id
2688 , repetitive_line_id
2689 , employee_code
2690 , primary_switch
2691 , schedule_update_code
2692 , setup_teardown_code
2693 , item_ordering
2694 , negative_req_flag
2695 , operation_seq_num
2696 , picking_line_id
2697 , trx_source_line_id
2698 , trx_source_delivery_id
2699 , physical_adjustment_id
2700 , cycle_count_id
2701 , rma_line_id
2702 , customer_ship_id
2703 , currency_code
2704 , currency_conversion_rate
2705 , currency_conversion_type
2706 , currency_conversion_date
2707 , ussgl_transaction_code
2708 , vendor_lot_number
2709 , encumbrance_account
2710 , encumbrance_amount
2711 , ship_to_location
2712 , shipment_number
2713 , transfer_cost
2714 , transportation_cost
2715 , transportation_account
2716 , freight_code
2717 , containers
2718 , waybill_airbill
2719 , expected_arrival_date
2720 , transfer_subinventory
2721 , transfer_organization
2722 , transfer_to_location
2723 , new_average_cost
2724 , value_change
2725 , percentage_change
2726 , material_allocation_temp_id
2727 , demand_source_header_id
2728 , demand_source_line
2729 , demand_source_delivery
2730 , item_segments
2731 , item_description
2732 , item_trx_enabled_flag
2733 , item_location_control_code
2734 , item_restrict_subinv_code
2735 , item_restrict_locators_code
2736 , item_revision_qty_control_code
2737 , item_primary_uom_code
2738 , item_uom_class
2739 , item_shelf_life_code
2740 , item_shelf_life_days
2741 , item_lot_control_code
2742 , item_serial_control_code
2743 , item_inventory_asset_flag
2744 , allowed_units_lookup_code
2745 , department_id
2746 , department_code
2747 , wip_supply_type
2748 , supply_subinventory
2749 , supply_locator_id
2750 , valid_subinventory_flag
2751 , valid_locator_flag
2752 , locator_segments
2753 , current_locator_control_code
2754 , number_of_lots_entered
2755 , wip_commit_flag
2756 , next_lot_number
2757 , lot_alpha_prefix
2758 , next_serial_number
2759 , serial_alpha_prefix
2760 , shippable_flag
2761 , posting_flag
2762 , required_flag
2763 , process_flag
2764 , error_code
2765 , error_explanation
2766 , attribute_category
2767 , attribute1
2768 , attribute2
2769 , attribute3
2770 , attribute4
2771 , attribute5
2772 , attribute6
2773 , attribute7
2774 , attribute8
2775 , attribute9
2776 , attribute10
2777 , attribute11
2778 , attribute12
2779 , attribute13
2780 , attribute14
2781 , attribute15
2782 , movement_id
2783 , reservation_quantity
2784 , shipped_quantity
2785 , transaction_line_number
2786 , task_id
2787 , to_task_id
2788 , source_task_id
2789 , project_id
2790 , source_project_id
2791 , pa_expenditure_org_id
2792 , to_project_id
2793 , expenditure_type
2794 , final_completion_flag
2795 , transfer_percentage
2796 , transaction_sequence_id
2797 , material_account
2798 , material_overhead_account
2799 , resource_account
2800 , outside_processing_account
2801 , overhead_account
2802 , flow_schedule
2803 , cost_group_id
2804 , demand_class
2805 , qa_collection_id
2806 , kanban_card_id
2807 , overcompletion_transaction_id
2808 , overcompletion_primary_qty
2809 , overcompletion_transaction_qty
2810 , end_item_unit_number
2811 , scheduled_payback_date
2812 , line_type_code
2813 , parent_transaction_temp_id
2814 , put_away_strategy_id
2815 , put_away_rule_id
2816 , pick_strategy_id
2817 , pick_rule_id
2818 , common_bom_seq_id
2819 , common_routing_seq_id
2820 , cost_type_id
2821 , org_cost_group_id
2822 , move_order_line_id
2823 , task_group_id
2824 , pick_slip_number
2825 , reservation_id
2826 , transaction_status
2827 , parent_line_id
2828 , transfer_cost_group_id
2829 , lpn_id
2830 , transfer_lpn_id
2831 , content_lpn_id
2832 , operation_plan_id
2833 , move_order_header_id
2834 , serial_allocated_flag
2835 )
2836 ( SELECT transaction_header_id
2837 , l_new_temp_id
2838 , source_code
2839 , source_line_id
2840 , transaction_mode
2841 , lock_flag
2842 , SYSDATE
2843 , fnd_global.user_id
2844 , SYSDATE
2845 , fnd_global.user_id
2846 , fnd_global.login_id
2847 , request_id
2848 , program_application_id
2849 , program_id
2850 , program_update_date
2851 , inventory_item_id
2852 , revision
2853 , organization_id
2854 , subinventory_code
2855 , locator_id
2856 , transaction_quantity
2857 , primary_quantity
2858 , transaction_uom
2859 , transaction_cost
2860 , transaction_type_id
2861 , transaction_action_id
2862 , transaction_source_type_id
2863 , transaction_source_id
2864 , transaction_source_name
2865 , transaction_date
2866 , acct_period_id
2867 , distribution_account_id
2868 , transaction_reference
2869 , requisition_line_id
2870 , requisition_distribution_id
2871 , reason_id
2872 , lot_number
2873 , lot_expiration_date
2874 , serial_number
2875 , receiving_document
2876 , demand_id
2877 , rcv_transaction_id
2878 , move_transaction_id
2879 , completion_transaction_id
2880 , wip_entity_type
2881 , schedule_id
2882 , repetitive_line_id
2883 , employee_code
2884 , primary_switch
2885 , schedule_update_code
2886 , setup_teardown_code
2887 , item_ordering
2888 , negative_req_flag
2889 , operation_seq_num
2890 , picking_line_id
2891 , trx_source_line_id
2892 , trx_source_delivery_id
2893 , physical_adjustment_id
2894 , cycle_count_id
2895 , rma_line_id
2896 , customer_ship_id
2897 , currency_code
2898 , currency_conversion_rate
2899 , currency_conversion_type
2900 , currency_conversion_date
2901 , ussgl_transaction_code
2902 , vendor_lot_number
2903 , encumbrance_account
2904 , encumbrance_amount
2905 , ship_to_location
2906 , shipment_number
2907 , transfer_cost
2908 , transportation_cost
2909 , transportation_account
2910 , freight_code
2911 , containers
2912 , waybill_airbill
2913 , expected_arrival_date
2914 , transfer_subinventory
2915 , transfer_organization
2916 , transfer_to_location
2917 , new_average_cost
2918 , value_change
2919 , percentage_change
2920 , material_allocation_temp_id
2921 , demand_source_header_id
2922 , demand_source_line
2923 , demand_source_delivery
2924 , item_segments
2925 , item_description
2926 , item_trx_enabled_flag
2927 , item_location_control_code
2928 , item_restrict_subinv_code
2929 , item_restrict_locators_code
2930 , item_revision_qty_control_code
2931 , item_primary_uom_code
2932 , item_uom_class
2933 , item_shelf_life_code
2934 , item_shelf_life_days
2935 , item_lot_control_code
2936 , item_serial_control_code
2937 , item_inventory_asset_flag
2938 , allowed_units_lookup_code
2939 , department_id
2940 , department_code
2941 , wip_supply_type
2942 , supply_subinventory
2943 , supply_locator_id
2944 , valid_subinventory_flag
2945 , valid_locator_flag
2946 , locator_segments
2947 , current_locator_control_code
2948 , number_of_lots_entered
2949 , wip_commit_flag
2950 , next_lot_number
2951 , lot_alpha_prefix
2952 , next_serial_number
2953 , serial_alpha_prefix
2954 , shippable_flag
2955 , posting_flag
2956 , required_flag
2957 , process_flag
2958 , error_code
2959 , error_explanation
2960 , attribute_category
2961 , attribute1
2962 , attribute2
2963 , attribute3
2964 , attribute4
2965 , attribute5
2966 , attribute6
2967 , attribute7
2968 , attribute8
2969 , attribute9
2970 , attribute10
2971 , attribute11
2972 , attribute12
2973 , attribute13
2974 , attribute14
2975 , attribute15
2976 , movement_id
2977 , reservation_quantity
2978 , shipped_quantity
2979 , transaction_line_number
2980 , task_id
2981 , to_task_id
2982 , source_task_id
2983 , project_id
2984 , source_project_id
2985 , pa_expenditure_org_id
2986 , to_project_id
2987 , expenditure_type
2988 , final_completion_flag
2989 , transfer_percentage
2990 , transaction_sequence_id
2991 , material_account
2992 , material_overhead_account
2993 , resource_account
2994 , outside_processing_account
2995 , overhead_account
2996 , flow_schedule
2997 , cost_group_id
2998 , demand_class
2999 , qa_collection_id
3000 , kanban_card_id
3001 , overcompletion_transaction_id
3002 , overcompletion_primary_qty
3003 , overcompletion_transaction_qty
3004 , end_item_unit_number
3005 , scheduled_payback_date
3006 , line_type_code
3007 , parent_transaction_temp_id
3008 , put_away_strategy_id
3009 , put_away_rule_id
3010 , pick_strategy_id
3011 , pick_rule_id
3012 , common_bom_seq_id
3013 , common_routing_seq_id
3014 , cost_type_id
3015 , org_cost_group_id
3016 , move_order_line_id
3017 , task_group_id
3018 , pick_slip_number
3019 , reservation_id
3020 , transaction_status
3021 , parent_line_id
3022 , transfer_cost_group_id
3023 , NULL
3024 , transfer_lpn_id
3025 , NULL
3026 , operation_plan_id
3027 , move_order_header_id
3028 , serial_allocated_flag
3029 FROM mtl_material_transactions_temp
3030 WHERE transaction_temp_id = p_temp_id
3031 );
3032
3033 g_current_drop_lpn.current_drop_list(l_new_temp_id) := 'PENDING';
3034
3035 IF l_debug = 1 THEN
3036 print_debug( 'About to insert WDT record', l_api_name);
3037 END IF;
3038
3039 -- Bug 4884284: insert WDT record for new child MMTT
3040 INSERT INTO wms_dispatched_tasks
3041 ( task_id
3042 , transaction_temp_id
3043 , organization_id
3044 , user_task_type
3045 , person_id
3046 , effective_start_date
3047 , effective_end_date
3048 , equipment_id
3049 , equipment_instance
3050 , person_resource_id
3051 , machine_resource_id
3052 , status
3053 , dispatched_time
3054 , last_update_date
3055 , last_updated_by
3056 , creation_date
3057 , created_by
3058 , task_type
3059 , loaded_time
3060 , operation_plan_id
3061 , move_order_line_id
3062 )
3063 ( SELECT wms_dispatched_tasks_s.NEXTVAL
3064 , l_new_temp_id
3065 , mmtt.organization_id
3066 , wdt.user_task_type
3067 , wdt.person_id
3068 , wdt.effective_start_date
3069 , wdt.effective_end_date
3070 , wdt.equipment_id
3071 , wdt.equipment_instance
3072 , wdt.person_resource_id
3073 , wdt.machine_resource_id
3074 , 4
3075 , wdt.dispatched_time
3076 , SYSDATE
3077 , wdt.last_updated_by
3078 , SYSDATE
3079 , wdt.created_by
3080 , wdt.task_type
3081 , wdt.loaded_time
3082 , mmtt.operation_plan_id
3083 , mmtt.move_order_line_id
3084 FROM wms_dispatched_tasks wdt
3085 , mtl_material_transactions_temp mmtt
3086 WHERE mmtt.transaction_temp_id = p_temp_id
3087 AND wdt.transaction_temp_id = mmtt.transaction_temp_id
3088 );
3089
3090 -- Bug 3902766
3091 IF g_current_drop_lpn.temp_id_group_ref.exists(p_temp_id) THEN
3092 g_current_drop_lpn.temp_id_group_ref(l_new_temp_id) := g_current_drop_lpn.temp_id_group_ref(p_temp_id);
3093 END IF;
3094
3095 x_new_temp_id := l_new_temp_id;
3096
3097 EXCEPTION
3098 WHEN OTHERS THEN
3099 ROLLBACK to split_mmtt_sp;
3100
3101 x_return_status := fnd_api.g_ret_sts_unexp_error;
3102
3103 IF l_debug = 1 THEN
3104 print_debug ('Other error: ' || sqlerrm, l_api_name);
3105 END IF;
3106
3107 END split_mmtt;
3108
3109
3110
3111 PROCEDURE get_temp_list
3112 ( x_temp_tbl OUT NOCOPY g_temp_id_tbl
3113 , x_return_status OUT NOCOPY VARCHAR2
3114 , p_group_num IN NUMBER DEFAULT NULL
3115 , p_status IN VARCHAR2 DEFAULT NULL
3116 ) IS
3117
3118 l_api_name VARCHAR2(30) := 'get_temp_list';
3119 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3120
3121 ii NUMBER;
3122 l_transaction_temp_id NUMBER;
3123
3124 l_group_match BOOLEAN;
3125 l_status_match BOOLEAN;
3126
3127 l_temp_ids VARCHAR2(4000); -- For bug#9247514
3128 l_mmtt_cur_str VARCHAR2(4000); -- For bug#9247514
3129
3130 TYPE cur_typ IS REF CURSOR; -- For bug#9247514
3131 l_mmtt_cur cur_typ; -- For bug#9247514
3132
3133 BEGIN
3134 x_return_status := fnd_api.g_ret_sts_success;
3135
3136 IF l_debug = 1 THEN
3137 print_debug
3138 ( 'Entered with parameters: ' || g_newline ||
3139 'p_group_num => ' || to_char(p_group_num) || g_newline ||
3140 'p_status => ' || p_status
3141 , l_api_name
3142 );
3143 END IF;
3144
3145 x_temp_tbl.DELETE;
3146
3147 l_transaction_temp_id := g_current_drop_lpn.current_drop_list.FIRST;
3148
3149 /* Added for bug#9247514 */
3150
3151 l_temp_ids:=To_Char(l_transaction_temp_id);
3152
3153 LOOP
3154
3155 IF l_transaction_temp_id = g_current_drop_lpn.current_drop_list.LAST
3156 THEN
3157 EXIT;
3158 ELSE
3159 l_transaction_temp_id := g_current_drop_lpn.current_drop_list.NEXT(l_transaction_temp_id);
3160 END IF;
3161
3162 l_temp_ids:=l_temp_ids||', '||To_Char(l_transaction_temp_id);
3163
3164 END LOOP;
3165
3166 l_transaction_temp_id:=NULL;
3167
3168 l_mmtt_cur_str :='SELECT mmtt.TRANSACTION_TEMP_ID FROM mtl_material_transactions_temp mmtt, wms_dispatched_tasks wdt '||
3169 ' WHERE mmtt.TRANSACTION_TEMP_ID=wdt.TRANSACTION_TEMP_ID(+) and mmtt.TRANSACTION_TEMP_ID in ('||l_temp_ids||') ORDER BY wdt.loaded_time';
3170
3171 ii := 1;
3172
3173 IF l_debug = 1 THEN
3174 print_debug(l_mmtt_cur_str, l_api_name);
3175 END IF;
3176
3177 OPEN l_mmtt_cur FOR l_mmtt_cur_str; -- For bug#9247514
3178
3179 LOOP
3180
3181 FETCH l_mmtt_cur INTO l_transaction_temp_id; -- For bug#9247514
3182 EXIT WHEN l_mmtt_cur%NOTFOUND; -- For bug#9247514
3183
3184 IF l_debug = 1 THEN
3185 print_debug ('l_transaction_temp_id: ' || l_transaction_temp_id, l_api_name);
3186 END IF;
3187
3188 l_group_match := FALSE;
3189 l_status_match := FALSE;
3190
3191 IF ( ( p_group_num IS NOT NULL
3192 AND
3193 p_group_num = g_current_drop_lpn.temp_id_group_ref(l_transaction_temp_id)
3194 )
3195 OR
3196 p_group_num IS NULL
3197 )
3198 THEN
3199 l_group_match := TRUE;
3200 ELSE
3201 l_group_match := FALSE;
3202 END IF;
3203
3204 IF ( ( p_status IS NOT NULL
3205 AND
3206 p_status = g_current_drop_lpn.current_drop_list(l_transaction_temp_id)
3207 )
3208 OR
3209 p_status IS NULL
3210 )
3211 THEN
3212 l_status_match := TRUE;
3213 ELSE
3214 l_status_match := FALSE;
3215 END IF;
3216
3217 IF l_group_match AND l_status_match
3218 THEN
3219 x_temp_tbl(ii) := l_transaction_temp_id;
3220 ii := ii + 1;
3221 END IF;
3222
3223 /* IF l_transaction_temp_id = g_current_drop_lpn.current_drop_list.LAST
3224 THEN
3225 EXIT;
3226 ELSE
3227 l_transaction_temp_id := g_current_drop_lpn.current_drop_list.NEXT(l_transaction_temp_id);
3228 END IF; */ -- For bug#9247514
3229
3230 END LOOP;
3231
3232 EXCEPTION
3233 WHEN OTHERS THEN
3234 x_return_status := fnd_api.g_ret_sts_unexp_error;
3235
3236 IF l_debug = 1 THEN
3237 print_debug ('Other error: ' || sqlerrm, l_api_name);
3238 END IF;
3239
3240 END get_temp_list;
3241
3242
3243
3244 PROCEDURE split_lots
3245 ( x_return_status OUT NOCOPY VARCHAR2
3246 ) IS
3247
3248 l_api_name VARCHAR2(30) := 'split_lots';
3249 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3250 l_api_return_status VARCHAR2(1);
3251
3252 l_temp_tbl g_temp_id_tbl;
3253 l_transaction_temp_id NUMBER;
3254 l_count NUMBER;
3255 l_orig_temp_id NUMBER;
3256
3257 ii NUMBER;
3258 jj NUMBER;
3259
3260
3261 CURSOR c_get_lot_count
3262 ( p_temp_id IN NUMBER
3263 ) IS
3264 SELECT COUNT(*)
3265 FROM mtl_transaction_lots_temp mtlt
3266 WHERE mtlt.transaction_temp_id = p_temp_id;
3267
3268
3269 CURSOR c_get_lot_details
3270 ( p_temp_id IN NUMBER
3271 ) IS
3272 SELECT mtlt.rowid
3273 , mtlt.lot_number
3274 , mtlt.transaction_quantity
3275 , mtlt.primary_quantity
3276 FROM mtl_transaction_lots_temp mtlt
3277 WHERE mtlt.transaction_temp_id = p_temp_id;
3278
3279 lot_dtl_rec c_get_lot_details%ROWTYPE;
3280
3281 BEGIN
3282 x_return_status := fnd_api.g_ret_sts_success;
3283
3284 SAVEPOINT split_lots_sp;
3285
3286 l_api_return_status := fnd_api.g_ret_sts_success;
3287 get_temp_list
3288 ( x_temp_tbl => l_temp_tbl
3289 , x_return_status => l_api_return_status
3290 , p_group_num => NULL
3291 , p_status => NULL
3292 );
3293
3294 IF l_api_return_status <> fnd_api.g_ret_sts_success
3295 THEN
3296 IF l_debug = 1 THEN
3297 print_debug ('Error from get_temp_list', l_api_name);
3298 END IF;
3299 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3300 END IF;
3301
3302 IF l_temp_tbl.COUNT > 0 THEN
3303 ii := l_temp_tbl.FIRST;
3304 jj := l_temp_tbl.LAST;
3305
3306 IF l_debug = 1 THEN
3307 print_debug
3308 ( 'ii = ' || to_char(ii) || ', jj = ' || to_char(jj)
3309 , l_api_name
3310 );
3311 END IF;
3312
3313 l_transaction_temp_id := l_temp_tbl(ii);
3314 WHILE (ii <= jj)
3315 LOOP
3316 IF l_debug = 1 THEN
3317 print_debug
3318 ( 'Checking temp ID ' || to_char(l_transaction_temp_id)
3319 , l_api_name
3320 );
3321 END IF;
3322
3323 OPEN c_get_lot_count (l_transaction_temp_id);
3324 FETCH c_get_lot_count INTO l_count;
3325 CLOSE c_get_lot_count;
3326
3327 IF l_count > 1 THEN
3328
3329 IF l_debug = 1 THEN
3330 print_debug
3331 ( 'Lot count: ' || to_char(l_count)
3332 , l_api_name
3333 );
3334 END IF;
3335
3336 l_orig_temp_id := l_transaction_temp_id;
3337
3338 OPEN c_get_lot_details (l_orig_temp_id);
3339 FETCH c_get_lot_details INTO lot_dtl_rec;
3340
3341 --
3342 -- Discard the first row
3343 --
3344 FETCH c_get_lot_details INTO lot_dtl_rec;
3345
3346 IF l_debug = 1 THEN
3347 print_debug
3348 ( 'Fetched lot #: ' || lot_dtl_rec.lot_number
3349 || ', txn qty: ' || to_char(lot_dtl_rec.transaction_quantity)
3350 || ', primary qty: ' || to_char(lot_dtl_rec.primary_quantity)
3351 , l_api_name
3352 );
3353 END IF;
3354
3355 WHILE (c_get_lot_details%FOUND)
3356 LOOP
3357 l_api_return_status := fnd_api.g_ret_sts_success;
3358 split_mmtt
3359 ( x_new_temp_id => l_transaction_temp_id
3360 , x_return_status => l_api_return_status
3361 , p_temp_id => l_orig_temp_id
3362 );
3363
3364 IF l_api_return_status <> fnd_api.g_ret_sts_success
3365 THEN
3366 IF l_debug = 1 THEN
3367 print_debug ('Error from split_mmtt', l_api_name);
3368 END IF;
3369 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
3370 END IF;
3371
3372 UPDATE mtl_material_transactions_temp
3373 SET transaction_quantity = transaction_quantity
3374 - lot_dtl_rec.transaction_quantity
3375 , primary_quantity = primary_quantity
3376 - lot_dtl_rec.primary_quantity
3377 , reservation_quantity = DECODE( reservation_quantity
3378 , NULL, NULL
3379 , reservation_quantity
3380 - lot_dtl_rec.primary_quantity
3381 )
3382 WHERE transaction_temp_id = l_orig_temp_id;
3383
3384 IF l_debug = 1 THEN
3385 print_debug
3386 ( 'Reduced txn and primary qty for original temp ID '
3387 || to_char(l_orig_temp_id)
3388 , l_api_name
3389 );
3390 END IF;
3391
3392 UPDATE mtl_material_transactions_temp
3393 SET transaction_quantity = lot_dtl_rec.transaction_quantity
3394 , primary_quantity = lot_dtl_rec.primary_quantity
3395 , reservation_quantity = DECODE( reservation_quantity
3396 , NULL, NULL
3397 , lot_dtl_rec.primary_quantity
3398 )
3399 WHERE transaction_temp_id = l_transaction_temp_id;
3400
3401 IF l_debug = 1 THEN
3402 print_debug
3403 ('Updated new temp ID ' || to_char(l_transaction_temp_id)
3404 , l_api_name
3405 );
3406 END IF;
3407
3408 UPDATE mtl_transaction_lots_temp
3409 SET transaction_temp_id = l_transaction_temp_id
3410 WHERE rowid = lot_dtl_rec.rowid;
3411
3412 IF l_debug = 1 THEN
3413 print_debug
3414 ( 'Updated MTLT record for lot ' || lot_dtl_rec.lot_number
3415 || ' to new temp ID ' || to_char(l_transaction_temp_id)
3416 , l_api_name
3417 );
3418 END IF;
3419
3420 FETCH c_get_lot_details INTO lot_dtl_rec;
3421
3422 END LOOP;
3423
3424 CLOSE c_get_lot_details;
3425 END IF; -- end if l_count > 1;
3426
3427 IF ii < jj THEN
3428 ii := l_temp_tbl.NEXT(ii);
3429 l_transaction_temp_id := l_temp_tbl(ii);
3430 ELSE
3431 EXIT;
3432 END IF;
3433
3434 IF l_debug = 1 THEN
3435 print_debug
3436 ( 'Fetched next temp ID: ' || to_char(l_transaction_temp_id)
3437 , l_api_name
3438 );
3439 END IF;
3440 END LOOP;
3441 END IF; -- end IF l_temp_tbl.COUNT > 0
3442
3443 l_temp_tbl.DELETE;
3444
3445 EXCEPTION
3446 WHEN OTHERS THEN
3447 ROLLBACK to split_lots_sp;
3448
3449 x_return_status := fnd_api.g_ret_sts_unexp_error;
3450
3451 IF c_get_lot_details%ISOPEN
3452 THEN
3453 CLOSE c_get_lot_details;
3454 END IF;
3455
3456 IF l_debug = 1 THEN
3457 print_debug ('Other error: ' || sqlerrm, l_api_name);
3458 END IF;
3459
3460 END split_lots;
3461
3462
3463
3464 --
3465 -- Name
3466 -- PROCEDURE FETCH_NEXT_DROP
3467 --
3468 -- Purpose
3469 -- This API returns details for the next available drop
3470 -- (called only if the LPN requires deconsolidation)
3471 --
3472 -- Input Parameters
3473 -- p_organization_id - Org ID
3474 -- p_transfer_lpn_id - LPN being dropped
3475 --
3476 -- Output Parameters
3477 -- x_return_status - fnd_api.g_ret_sts_error
3478 -- - fnd_api.g_ret_sts_unexp_error
3479 --
3480
3481 PROCEDURE fetch_next_drop
3482 ( x_drop_type OUT NOCOPY VARCHAR2
3483 , x_bulk_pick OUT NOCOPY VARCHAR2
3484 , x_drop_lpn_option OUT NOCOPY NUMBER
3485 , x_delivery_id OUT NOCOPY NUMBER
3486 , x_tasks OUT NOCOPY t_genref
3487 , x_lpn_done OUT NOCOPY VARCHAR2
3488 , x_first_temp_id OUT NOCOPY NUMBER
3489 , x_total_qty OUT NOCOPY NUMBER -- Added for bug 12853197
3490 , x_task_type OUT NOCOPY NUMBER
3491 , x_txn_type_id OUT NOCOPY NUMBER
3492 , x_return_status OUT NOCOPY VARCHAR2
3493 , p_organization_id IN NUMBER
3494 , p_transfer_lpn_id IN NUMBER
3495 ) IS
3496
3497 l_api_name VARCHAR2(30) := 'fetch_next_drop';
3498 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
3499
3500 l_msg_count NUMBER;
3501 l_msg_data VARCHAR2(2000);
3502 l_api_return_status VARCHAR2(1);
3503
3504 l_progress NUMBER := 0;
3505
3506 l_details_done BOOLEAN := FALSE;
3507 l_group_end BOOLEAN;
3508
3509 l_transaction_temp_id NUMBER;
3510 l_parent_temp_id NUMBER;
3511 l_task_type NUMBER;
3512 l_txn_type_id NUMBER;
3513 l_count NUMBER := 0;
3514 -- bug#10062741
3515 l_line_rows WSH_UTIL_CORE.id_tab_type; --Bug 10062741
3516 l_grouping_rows WSH_UTIL_CORE.id_tab_type; --Bug 10062741
3517 l_return_status VARCHAR2(2) ; --Bug 10062741
3518
3519 CURSOR c_remaining_tasks
3520 ( p_org_id IN NUMBER
3521 , p_lpn_id IN NUMBER
3522 ) IS
3523 -- Staging xfers not in cancelled status
3524 SELECT 1 line_type
3525 , NVL(msi.dropping_order, 0) sub_dropping_order
3526 , NVL(msi.picking_order, 0) sub_picking_order
3527 , mmtt.transfer_subinventory transfer_subinventory
3528 , NVL(mil.dropping_order, 0) loc_dropping_order
3529 , NVL(mil.picking_order, 0) loc_picking_order
3530 , mmtt.transfer_to_location transfer_to_location
3531 , null loaded_time -- Added for bug 12853197
3532 , NVL(wda.delivery_id,-1)-- bug#10062741 NVL(wda.delivery_id,NVL(mtrl.carton_grouping_id,0))
3533 delivery_id
3534 ,wdd.delivery_detail_id delivery_detail_id --Bug 10062741
3535 , 0 txn_source_id
3536 , 0 txn_source_line_id
3537 , 0 reference_id
3538 , mmtt.transaction_temp_id
3539 , mmtt.inventory_item_id inventory_item_id
3540 , mmtt.revision revision
3541 , DECODE( mmtt.parent_line_id
3542 , NULL, 0
3543 , 1
3544 ) parent_line_id
3545 FROM mtl_material_transactions_temp mmtt
3546 , mtl_secondary_inventories msi
3547 , mtl_item_locations mil
3548 , mtl_txn_request_lines mtrl
3549 , wsh_delivery_details_ob_grp_v wdd
3550 , wsh_delivery_assignments_v wda
3551 WHERE mmtt.organization_id = p_org_id
3552 AND mmtt.transfer_lpn_id = p_lpn_id
3553 AND mmtt.transaction_action_id = 28
3554 AND ( (mmtt.parent_line_id IS NOT NULL
3555 AND
3556 mmtt.parent_line_id <> mmtt.transaction_temp_id
3557 )
3558 OR
3559 mmtt.parent_line_id IS NULL
3560 )
3561 AND mmtt.organization_id = msi.organization_id
3562 AND mmtt.transfer_subinventory = msi.secondary_inventory_name
3563 AND mmtt.organization_id = mil.organization_id
3564 AND mmtt.transfer_subinventory = mil.subinventory_code
3565 AND mmtt.transfer_to_location = mil.inventory_location_id
3566 AND mmtt.move_order_line_id = mtrl.line_id
3567 AND mtrl.line_status <> 9
3568 AND mtrl.organization_id = wdd.organization_id
3569 AND mtrl.line_id = wdd.move_order_line_id
3570 and wdd.delivery_detail_id = wda.delivery_detail_id
3571 UNION ALL
3572 -- Non-WIP sub xfers, not in cancelled status
3573 SELECT 2 line_type
3574 , NVL(msi.dropping_order, 0) sub_dropping_order
3575 , NVL(msi.picking_order, 0) sub_picking_order
3576 , mmtt.transfer_subinventory transfer_subinventory
3577 , NVL(mil.dropping_order, 0) loc_dropping_order
3578 , NVL(mil.picking_order, 0) loc_picking_order
3579 , mmtt.transfer_to_location transfer_to_location
3580 , max(wdt.loaded_time) over (PARTITION BY mmtt.transfer_subinventory, mmtt.transfer_to_location, mmtt.inventory_item_id, mmtt.revision) loaded_time --Bug#12853197
3581 , 0 delivery_id
3582 , 0 delivery_detail_id --Bug 10062741
3583 , 0 txn_source_id
3584 , 0 txn_source_line_id
3585 , 0 reference_id
3586 , mmtt.transaction_temp_id
3587 , mmtt.inventory_item_id inventory_item_id
3588 , mmtt.revision revision
3589 , DECODE( mmtt.parent_line_id
3590 , NULL, 0
3591 , 1
3592 ) parent_line_id
3593 FROM mtl_material_transactions_temp mmtt
3594 , mtl_secondary_inventories msi
3595 , mtl_item_locations mil
3596 , mtl_txn_request_lines mtrl
3597 , mtl_txn_request_headers mtrh
3598 , wms_dispatched_tasks wdt -- Added for bug 12853197
3599 WHERE mmtt.organization_id = p_org_id
3600 AND mmtt.transfer_lpn_id = p_lpn_id
3601 AND mmtt.transaction_action_id = 2
3602 AND ( (mmtt.parent_line_id IS NOT NULL
3603 AND
3604 mmtt.parent_line_id <> mmtt.transaction_temp_id
3605 )
3606 OR
3607 mmtt.parent_line_id IS NULL
3608 )
3609 AND mmtt.organization_id = msi.organization_id
3610 AND mmtt.transfer_subinventory = msi.secondary_inventory_name
3611 AND mmtt.organization_id = mil.organization_id
3612 AND mmtt.transfer_subinventory = mil.subinventory_code
3613 AND mmtt.transfer_to_location = mil.inventory_location_id
3614 AND mmtt.move_order_line_id = mtrl.line_id
3615 AND mtrl.line_status <> 9
3616 AND mtrl.header_id = mtrh.header_id
3617 AND mtrh.move_order_type <> 5
3618 AND wdt.transaction_temp_id(+) = mmtt.transaction_temp_id -- Added for bug 12853197
3619 UNION ALL
3620 -- WIP sub xfers, not in cancelled status
3621 SELECT 3 line_type
3622 , NVL(msi.dropping_order, 0) sub_dropping_order
3623 , NVL(msi.picking_order, 0) sub_picking_order
3624 , mmtt.transfer_subinventory transfer_subinventory
3625 , NVL(mil.dropping_order, 0) loc_dropping_order
3626 , NVL(mil.picking_order, 0) loc_picking_order
3627 , mmtt.transfer_to_location transfer_to_location
3628 , null loaded_time -- Added for bug 12853197
3629 , 0 delivery_id
3630 , 0 delivery_detail_id --Bug 10062741
3631 , 0 txn_source_id
3632 , 0 txn_source_line_id
3633 , 0 reference_id
3634 , mmtt.transaction_temp_id
3635 , mmtt.inventory_item_id inventory_item_id
3636 , mmtt.revision revision
3637 , DECODE( mmtt.parent_line_id
3638 , NULL, 0
3639 , 1
3640 ) parent_line_id
3641 FROM mtl_material_transactions_temp mmtt
3642 , mtl_secondary_inventories msi
3643 , mtl_item_locations mil
3644 , mtl_txn_request_lines mtrl
3645 , mtl_txn_request_headers mtrh
3646 WHERE mmtt.organization_id = p_org_id
3647 AND mmtt.transfer_lpn_id = p_lpn_id
3648 AND mmtt.transaction_action_id = 2
3649 AND ( (mmtt.parent_line_id IS NOT NULL
3650 AND
3651 mmtt.parent_line_id <> mmtt.transaction_temp_id
3652 )
3653 OR
3654 mmtt.parent_line_id IS NULL
3655 )
3656 AND mmtt.organization_id = msi.organization_id
3657 AND mmtt.transfer_subinventory = msi.secondary_inventory_name
3658 AND mmtt.organization_id = mil.organization_id
3659 AND mmtt.transfer_subinventory = mil.subinventory_code
3660 AND mmtt.transfer_to_location = mil.inventory_location_id
3661 AND mmtt.move_order_line_id = mtrl.line_id
3662 AND mtrl.line_status <> 9
3663 AND mtrl.header_id = mtrh.header_id
3664 AND mtrh.move_order_type = 5
3665 UNION ALL
3666 -- WIP issues, not in cancelled status
3667 SELECT 4 line_type
3668 , 0 sub_dropping_order
3669 , 0 sub_picking_order
3670 , to_char(NULL) transfer_subinventory
3671 , 0 loc_dropping_order
3672 , 0 loc_picking_order
3673 , 0 transfer_to_location
3674 , null loaded_time -- Added for bug 12853197
3675 , 0 delivery_id
3676 , 0 delivery_detail_id --Bug 10062741
3677 , mtrl.txn_source_id
3678 , mtrl.txn_source_line_id
3679 , mtrl.reference_id
3680 , mmtt.transaction_temp_id
3681 , mmtt.inventory_item_id
3682 , mmtt.revision
3683 , DECODE( mmtt.parent_line_id
3684 , NULL, 0
3685 , 1
3686 ) parent_line_id
3687 FROM mtl_material_transactions_temp mmtt
3688 , mtl_txn_request_lines mtrl
3689 WHERE mmtt.organization_id = p_org_id
3690 AND mmtt.transfer_lpn_id = p_lpn_id
3691 AND mmtt.transaction_action_id = 1
3692 AND mmtt.transaction_source_type_id = 5
3693 AND ( (mmtt.parent_line_id IS NOT NULL
3694 AND
3695 mmtt.parent_line_id <> mmtt.transaction_temp_id
3696 )
3697 OR
3698 mmtt.parent_line_id IS NULL
3699 )
3700 AND mmtt.move_order_line_id = mtrl.line_id
3701 AND mtrl.line_status <> 9
3702 UNION ALL
3703 -- Cancelled lines
3704 SELECT 5 line_type
3705 , 0 sub_dropping_order
3706 , 0 sub_picking_order
3707 , to_char(NULL) transfer_subinventory
3708 , 0 loc_dropping_order
3709 , 0 loc_picking_order
3710 , 0 transfer_to_location
3711 , null loaded_time -- Added for bug 12853197
3712 , 0 delivery_id
3713 , 0 delivery_detail_id --Bug 10062741
3714 , 0 txn_source_id
3715 , 0 txn_source_line_id
3716 , 0 reference_id
3717 , mmtt.transaction_temp_id
3718 , mmtt.inventory_item_id
3719 , mmtt.revision
3720 , DECODE( mmtt.parent_line_id
3721 , NULL, 0
3722 , 1
3723 ) parent_line_id
3724 FROM mtl_material_transactions_temp mmtt
3725 , mtl_txn_request_lines mtrl
3726 WHERE mmtt.organization_id = p_org_id
3727 AND mmtt.transfer_lpn_id = p_lpn_id
3728 AND mmtt.transaction_action_id IN (2,28)
3729 AND mmtt.move_order_line_id = mtrl.line_id
3730 AND ( (mmtt.parent_line_id IS NOT NULL
3731 AND
3732 mmtt.parent_line_id <> mmtt.transaction_temp_id
3733 )
3734 OR
3735 mmtt.parent_line_id IS NULL
3736 )
3737 AND mtrl.line_status = 9
3738 UNION ALL
3739 -- Overpicked lines, other sub xfers without move orders
3740 SELECT 6 line_type
3741 , 0 sub_dropping_order
3742 , 0 sub_picking_order
3743 , to_char(NULL) transfer_subinventory
3744 , 0 loc_dropping_order
3745 , 0 loc_picking_order
3746 , 0 transfer_to_location
3747 , null loaded_time -- Added for bug 12853197
3748 , 0 delivery_id
3749 , 0 delivery_detail_id --Bug 10062741
3750 , 0 txn_source_id
3751 , 0 txn_source_line_id
3752 , 0 reference_id
3753 , mmtt.transaction_temp_id
3754 , mmtt.inventory_item_id
3755 , mmtt.revision
3756 , DECODE( mmtt.parent_line_id
3757 , NULL, 0
3758 , 1
3759 ) parent_line_id
3760 FROM mtl_material_transactions_temp mmtt
3761 WHERE mmtt.organization_id = p_org_id
3762 AND mmtt.transfer_lpn_id = p_lpn_id
3763 AND mmtt.transaction_action_id = 2
3764 AND mmtt.move_order_line_id IS NULL
3765 AND ( (mmtt.parent_line_id IS NOT NULL
3766 AND
3767 mmtt.parent_line_id <> mmtt.transaction_temp_id
3768 )
3769 OR
3770 mmtt.parent_line_id IS NULL
3771 )
3772 ORDER BY 1,2,3,4,5,6,7,8 desc,9,10,11,13,14,15; -- Modified for bug 12853197
3773
3774 c_tasks_curr_rec c_remaining_tasks%ROWTYPE;
3775 c_tasks_orig_rec c_remaining_tasks%ROWTYPE;
3776
3777
3778 CURSOR c_get_txn_type
3779 ( p_temp_id IN NUMBER
3780 ) IS
3781 SELECT mmtt.transaction_type_id
3782 FROM mtl_material_transactions_temp mmtt
3783 WHERE mmtt.transaction_temp_id = p_temp_id;
3784
3785 BEGIN
3786
3787 x_return_status := fnd_api.g_ret_sts_success;
3788
3789 IF l_debug = 1 THEN
3790 print_debug
3791 ( 'Entered with parameters: ' || g_newline ||
3792 'p_organization_id => ' || to_char(p_organization_id) || g_newline ||
3793 'p_transfer_lpn_id => ' || to_char(p_transfer_lpn_id)
3794 , l_api_name
3795 );
3796 END IF;
3797
3798 l_progress := 10;
3799
3800 OPEN c_remaining_tasks(p_organization_id, p_transfer_lpn_id);
3801 FETCH c_remaining_tasks INTO c_tasks_curr_rec;
3802
3803 l_progress := 20;
3804
3805 IF c_remaining_tasks%FOUND
3806 THEN
3807 g_current_drop_lpn.current_drop_list.DELETE;
3808 g_current_drop_lpn.temp_id_group_ref.DELETE;
3809 g_current_drop_lpn.current_drop_list(c_tasks_curr_rec.transaction_temp_id) := 'PENDING';
3810
3811 c_tasks_orig_rec := c_tasks_curr_rec;
3812
3813 OPEN c_get_txn_type (c_tasks_curr_rec.transaction_temp_id);
3814 FETCH c_get_txn_type INTO l_txn_type_id;
3815 CLOSE c_get_txn_type;
3816 x_txn_type_id := l_txn_type_id;
3817
3818 x_drop_lpn_option := g_current_drop_lpn.drop_lpn_option;
3819
3820 l_progress := 30;
3821
3822 LOOP
3823 l_group_end := FALSE;
3824
3825 IF l_debug = 1 THEN
3826 print_debug
3827 ( 'Original record: ' || g_newline ||
3828 'Txn temp ID: ' || to_char(c_tasks_orig_rec.transaction_temp_id) ||
3829 g_newline ||
3830 'Line type: ' || to_char(c_tasks_orig_rec.line_type) ||
3831 g_newline ||
3832 'Sub drop order: ' || to_char(c_tasks_orig_rec.sub_dropping_order) ||
3833 g_newline ||
3834 'Sub pick order: ' || to_char(c_tasks_orig_rec.sub_picking_order) ||
3835 g_newline ||
3836 'Xfer sub: ' || c_tasks_orig_rec.transfer_subinventory ||
3837 g_newline ||
3838 'Loc drop order: ' || to_char(c_tasks_orig_rec.loc_dropping_order) ||
3839 g_newline ||
3840 'Loc pick order: ' || to_char(c_tasks_orig_rec.loc_picking_order) ||
3841 g_newline ||
3842 'Xfer loc: ' || to_char(c_tasks_orig_rec.transfer_to_location) ||
3843 g_newline ||
3844 'Delivery ID: ' || to_char(c_tasks_orig_rec.delivery_id) ||
3845 g_newline ||
3846 'Txn src ID: ' || to_char(c_tasks_orig_rec.txn_source_id) ||
3847 g_newline ||
3848 'Txn src line ID: ' || to_char(c_tasks_orig_rec.txn_source_line_id) ||
3849 g_newline ||
3850 'Reference ID: ' || to_char(c_tasks_orig_rec.reference_id) ||
3851 g_newline ||
3852 'Item ID: ' || to_char(c_tasks_orig_rec.inventory_item_id) ||
3853 g_newline ||
3854 'Revision: ' || c_tasks_orig_rec.revision ||
3855 g_newline ||
3856 'Parent line ID: ' || to_char(c_tasks_orig_rec.parent_line_id)
3857 , l_api_name
3858 );
3859 END IF;
3860
3861 FETCH c_remaining_tasks INTO c_tasks_curr_rec;
3862 EXIT WHEN c_remaining_tasks%NOTFOUND;
3863
3864 IF l_debug = 1 THEN
3865 print_debug
3866 ( 'New record: ' || g_newline ||
3867 'Txn temp ID: ' || to_char(c_tasks_curr_rec.transaction_temp_id) ||
3868 g_newline ||
3869 'Line type: ' || to_char(c_tasks_curr_rec.line_type) ||
3870 g_newline ||
3871 'Sub drop order: ' || to_char(c_tasks_curr_rec.sub_dropping_order) ||
3872 g_newline ||
3873 'Sub pick order: ' || to_char(c_tasks_curr_rec.sub_picking_order) ||
3874 g_newline ||
3875 'Xfer sub: ' || c_tasks_curr_rec.transfer_subinventory ||
3876 g_newline ||
3877 'Loc drop order: ' || to_char(c_tasks_curr_rec.loc_dropping_order) ||
3878 g_newline ||
3879 'Loc pick order: ' || to_char(c_tasks_curr_rec.loc_picking_order) ||
3880 g_newline ||
3881 'Xfer loc: ' || to_char(c_tasks_curr_rec.transfer_to_location) ||
3882 g_newline ||
3883 'Delivery ID: ' || to_char(c_tasks_curr_rec.delivery_id) ||
3884 g_newline ||
3885 'Txn src ID: ' || to_char(c_tasks_curr_rec.txn_source_id) ||
3886 g_newline ||
3887 'Txn src line ID: ' || to_char(c_tasks_curr_rec.txn_source_line_id) ||
3888 g_newline ||
3889 'Reference ID: ' || to_char(c_tasks_curr_rec.reference_id) ||
3890 g_newline ||
3891 'Item ID: ' || to_char(c_tasks_curr_rec.inventory_item_id) ||
3892 g_newline ||
3893 'Revision: ' || c_tasks_curr_rec.revision ||
3894 g_newline ||
3895 'Parent line ID: ' || to_char(c_tasks_curr_rec.parent_line_id)
3896 , l_api_name
3897 );
3898 END IF;
3899
3900 IF c_tasks_curr_rec.line_type <> c_tasks_orig_rec.line_type
3901 OR
3902 NVL(c_tasks_curr_rec.transfer_subinventory,'@@@@@@@@@@@') <>
3903 NVL(c_tasks_orig_rec.transfer_subinventory,'@@@@@@@@@@@')
3904 OR
3905 c_tasks_curr_rec.transfer_to_location <> c_tasks_orig_rec.transfer_to_location
3906 OR
3907 c_tasks_curr_rec.delivery_id <> c_tasks_orig_rec.delivery_id
3908 OR
3909 c_tasks_curr_rec.txn_source_id <> c_tasks_orig_rec.txn_source_id
3910 OR
3911 c_tasks_curr_rec.txn_source_line_id <> c_tasks_orig_rec.txn_source_line_id
3912 OR
3913 c_tasks_curr_rec.reference_id <> c_tasks_orig_rec.reference_id
3914 OR
3915 -- bug 12853197
3916 (g_suggestion_drop <>'NONE'
3917 AND
3918 g_chk_mult_subinv <>'N'
3919 AND
3920 c_tasks_curr_rec.line_type = c_tasks_orig_rec.line_type
3921 AND
3922 c_tasks_curr_rec.inventory_item_id = c_tasks_orig_rec.inventory_item_id
3923 AND
3924 NVL(c_tasks_curr_rec.revision,'@@@@') <> NVL(c_tasks_orig_rec.revision,'@@@@')
3925 )
3926 OR
3927 (g_suggestion_drop <>'NONE'
3928 AND
3929 g_chk_mult_subinv <>'N'
3930 AND
3931 c_tasks_curr_rec.line_type = c_tasks_orig_rec.line_type
3932 AND
3933 c_tasks_curr_rec.inventory_item_id <> c_tasks_orig_rec.inventory_item_id
3934 )
3935 OR
3936 (c_tasks_curr_rec.line_type IN (3,4)
3937 AND
3938 c_tasks_curr_rec.line_type = c_tasks_orig_rec.line_type
3939 AND
3940 c_tasks_curr_rec.inventory_item_id <> c_tasks_orig_rec.inventory_item_id
3941 )
3942 OR
3943 (c_tasks_curr_rec.line_type IN (3,4)
3944 AND
3945 c_tasks_curr_rec.line_type = c_tasks_orig_rec.line_type
3946 AND
3947 c_tasks_curr_rec.inventory_item_id = c_tasks_orig_rec.inventory_item_id
3948 AND
3949 NVL(c_tasks_curr_rec.revision,'@@@@') <> NVL(c_tasks_orig_rec.revision,'@@@@')
3950 )
3951 OR
3952 NVL(c_tasks_curr_rec.parent_line_id,0) <> NVL(c_tasks_orig_rec.parent_line_id,0)
3953 THEN
3954 IF l_debug = 1 THEN
3955 print_debug
3956 ( 'Current record is a new group, so exit inner loop'
3957 , l_api_name
3958 );
3959 END IF;
3960 l_group_end := TRUE;
3961 ELSE
3962
3963 --Bug 10062741
3964 IF (c_tasks_orig_rec.delivery_id = -1 AND c_tasks_curr_rec.delivery_id = -1) THEN
3965 l_line_rows(1) := c_tasks_orig_rec.delivery_detail_id;
3966 l_line_rows(2) := c_tasks_curr_rec.delivery_detail_id;
3967
3968 IF (l_debug = 1) THEN
3969 print_debug('Before calling WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping() to decide if we can drop in the same task', l_api_name);
3970 print_debug('Parameters : delivery_detail_id(1):'|| l_line_rows(1) ||' , delivery_detail_id(2) :'||l_line_rows(2), l_api_name);
3971 END IF;
3972 --
3973 -- call to the shipping API.
3974 --
3975 WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping(
3976 p_line_rows => l_line_rows,
3977 x_grouping_rows => l_grouping_rows,
3978 x_return_status => l_return_status);
3979 --
3980 IF (l_return_status = FND_API.G_RET_STS_SUCCESS
3981 AND l_grouping_rows (1) = l_grouping_rows(2) ) THEN
3982
3983 IF l_debug = 1 THEN
3984 print_debug
3985 ( 'Current record is in the same group'
3986 , l_api_name
3987 );
3988 END IF;
3989 g_current_drop_lpn.current_drop_list(c_tasks_curr_rec.transaction_temp_id) := 'PENDING';
3990 c_tasks_orig_rec := c_tasks_curr_rec;
3991 ELSE
3992
3993 IF l_debug = 1 THEN
3994 print_debug
3995 ( 'Current record is a new group, so exit inner loop'
3996 , l_api_name
3997 );
3998 END IF;
3999 l_group_end := TRUE;
4000
4001 END IF;
4002 ELSE
4003 IF l_debug = 1 THEN
4004 print_debug
4005 ( 'Current record is in the same group'
4006 , l_api_name
4007 );
4008 END IF;
4009 g_current_drop_lpn.current_drop_list(c_tasks_curr_rec.transaction_temp_id) := 'PENDING';
4010 c_tasks_orig_rec := c_tasks_curr_rec;
4011 END IF;
4012 END IF;
4013 EXIT WHEN l_group_end;
4014 END LOOP;
4015
4016 IF l_debug = 1 THEN
4017 print_debug
4018 ( '# of temp IDs in group: ' ||
4019 to_char(g_current_drop_lpn.current_drop_list.COUNT)
4020 , l_api_name
4021 );
4022 END IF;
4023
4024 IF NOT g_current_drop_lpn.current_drop_list.COUNT > 0
4025 THEN
4026 fnd_message.set_name('WMS', 'WMS_DROP_LPN_NO_MTL');
4027 fnd_msg_pub.ADD;
4028 RAISE FND_API.G_EXC_ERROR;
4029 END IF;
4030
4031 ELSE
4032 IF l_debug = 1 THEN
4033 print_debug
4034 ( 'No material available on this LPN for drop'
4035 , l_api_name
4036 );
4037 END IF;
4038
4039 fnd_message.set_name('WMS', 'WMS_DROP_LPN_NO_MTL');
4040 fnd_msg_pub.ADD;
4041 RAISE FND_API.G_EXC_ERROR;
4042 END IF; -- end if c_remaining_tasks%FOUND
4043
4044 l_progress := 40;
4045
4046 IF c_remaining_tasks%NOTFOUND
4047 THEN
4048 x_lpn_done := 'TRUE';
4049 ELSE
4050 x_lpn_done := 'FALSE';
4051 END IF;
4052 CLOSE c_remaining_tasks;
4053
4054 l_progress := 50;
4055
4056 --
4057 -- Derive drop type, etc.
4058 --
4059 l_transaction_temp_id := g_current_drop_lpn.current_drop_list.FIRST;
4060
4061 x_first_temp_id := l_transaction_temp_id;
4062
4063 l_api_return_status := fnd_api.g_ret_sts_success;
4064 get_group_info
4065 ( x_drop_type => x_drop_type
4066 , x_bulk_pick => x_bulk_pick
4067 , x_delivery_id => x_delivery_id
4068 , x_task_type => x_task_type
4069 , x_return_status => l_api_return_status
4070 , p_txn_temp_id => l_transaction_temp_id
4071 );
4072
4073 IF l_api_return_status <> fnd_api.g_ret_sts_success
4074 THEN
4075 IF l_debug = 1 THEN
4076 print_debug
4077 ( 'Error from get_group_info'
4078 , l_api_name
4079 );
4080 END IF;
4081 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4082 END IF;
4083
4084 --
4085 -- Don't deconsolidate replenishments
4086 -- and move order sub xfers
4087 --
4088 -- Deconsolidating for sub xfers if destination sub is not LPN controlled. bug 12853197
4089
4090 IF x_drop_type <> 'SUB_XFER' OR (g_suggestion_drop <>'NONE' AND g_chk_mult_subinv <>'N') -- Modified for bug 12853197
4091 THEN
4092 --
4093 -- Process mtlt records for all temp IDs in current drop
4094 -- This is required so that we do not have more than
4095 -- one lot/revision per temp ID, and one temp ID
4096 -- will only belong to one group in the drop page.
4097 --
4098 l_api_return_status := fnd_api.g_ret_sts_success;
4099 split_lots(x_return_status => l_api_return_status);
4100
4101 IF l_api_return_status <> fnd_api.g_ret_sts_success
4102 THEN
4103 IF l_debug = 1 THEN
4104 print_debug
4105 ( 'Error from split_lots'
4106 , l_api_name
4107 );
4108 END IF;
4109 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4110 END IF;
4111
4112 l_api_return_status := fnd_api.g_ret_sts_success;
4113 group_drop_details(x_drop_type, l_api_return_status);
4114
4115 IF l_api_return_status <> fnd_api.g_ret_sts_success
4116 THEN
4117 IF l_debug = 1 THEN
4118 print_debug
4119 ( 'Error from group_drop_details'
4120 , l_api_name
4121 );
4122 END IF;
4123 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4124 END IF;
4125
4126 BEGIN
4127 SELECT count(*)
4128 INTO l_count
4129 FROM mtl_allocations_gtmp;
4130
4131 IF l_debug = 1 THEN
4132 print_debug
4133 ( 'Count from mtl_allocations_gtmp: ' || to_char(l_count)
4134 , l_api_name
4135 );
4136 END IF;
4137
4138 EXCEPTION
4139 WHEN OTHERS THEN
4140 l_count := 0;
4141 IF l_debug = 1 THEN
4142 print_debug
4143 ( 'Exception when checking record count in temp table: ' || sqlerrm
4144 , l_api_name
4145 );
4146 END IF;
4147 END;
4148
4149 IF l_count > 0 THEN
4150 OPEN x_tasks FOR -- Modified for bug 12853197
4151 SELECT mag.inventory_item_id
4152 , mag.item_number
4153 , mag.group_number
4154 , mag.content_lpn
4155 , mag.inner_lpn
4156 , mag.inner_lpn_exists
4157 , mag.loose_qty_exists
4158 , mag.revision
4159 , mag.lot_number
4160 , mag.serial_number
4161 , mag.lot_alloc
4162 , mag.serial_alloc
4163 , mag.primary_quantity
4164 , mag.primary_uom_code
4165 , mag.uom_lookup_code
4166 , msi.description
4167 FROM mtl_allocations_gtmp mag, mtl_system_items_vl msi
4168 WHERE mag.inventory_item_id = msi.inventory_item_id
4169 AND msi.ORGANIZATION_ID = p_organization_id
4170 ORDER BY group_number;
4171
4172 -- Added for bug 12853197
4173 SELECT Sum(primary_quantity)
4174 INTO g_total_qty
4175 FROM mtl_allocations_gtmp;
4176 ELSE
4177 IF l_debug = 1 THEN
4178 print_debug
4179 ( 'Invalid count of records in mtl_allocations_gtmp: '
4180 || to_char(l_count)
4181 , l_api_name
4182 );
4183 END IF;
4184 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4185 END IF;
4186 END IF;
4187
4188 x_total_qty:=g_total_qty; -- Added for bug 12853197
4189
4190 EXCEPTION
4191 WHEN fnd_api.g_exc_error THEN
4192 x_return_status := fnd_api.g_ret_sts_error;
4193
4194 fnd_msg_pub.count_and_get
4195 ( p_count => l_msg_count
4196 , p_data => l_msg_data
4197 , p_encoded => fnd_api.g_false
4198 );
4199
4200 IF l_debug = 1 THEN
4201 print_debug (l_msg_data, l_api_name);
4202 print_debug ('l_progress = ' || to_char(l_progress), l_api_name);
4203 END IF;
4204
4205 IF c_remaining_tasks%ISOPEN THEN
4206 CLOSE c_remaining_tasks;
4207 END IF;
4208
4209 x_total_qty:=g_total_qty; -- Added for bug 12853197
4210
4211 WHEN OTHERS THEN
4212 x_return_status := fnd_api.g_ret_sts_unexp_error;
4213
4214 IF l_debug = 1 THEN
4215 print_debug ('Other error: ' || sqlerrm, l_api_name);
4216 print_debug ('l_progress = ' || to_char(l_progress), l_api_name);
4217 END IF;
4218
4219 IF c_remaining_tasks%ISOPEN THEN
4220 CLOSE c_remaining_tasks;
4221 END IF;
4222
4223 x_total_qty:=g_total_qty; -- Added for bug 12853197
4224
4225 END fetch_next_drop;
4226
4227
4228
4229 PROCEDURE get_wip_job_info
4230 ( x_entity_type OUT NOCOPY NUMBER
4231 , x_job OUT NOCOPY VARCHAR2
4232 , x_line OUT NOCOPY VARCHAR2
4233 , x_dept OUT NOCOPY VARCHAR2
4234 , x_operation_seq_num OUT NOCOPY NUMBER
4235 , x_start_date OUT NOCOPY DATE
4236 , x_schedule OUT NOCOPY VARCHAR2
4237 , x_assembly OUT NOCOPY VARCHAR2
4238 , x_return_status OUT NOCOPY VARCHAR2
4239 , p_organization_id IN NUMBER
4240 , p_transfer_lpn_id IN NUMBER
4241 ) IS
4242
4243 l_api_name VARCHAR2(30) := 'get_wip_job_info';
4244 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4245
4246 l_msg_count NUMBER;
4247 l_msg_data VARCHAR2(2000);
4248 l_api_return_status VARCHAR2(1);
4249
4250 l_transaction_temp_id NUMBER;
4251 l_wip_entity_type NUMBER := NULL;
4252
4253 CURSOR c_get_entity_type
4254 ( p_temp_id IN NUMBER
4255 ) IS
4256 SELECT wip_entity_type
4257 FROM mtl_material_transactions_temp mmtt
4258 , mtl_txn_request_lines mtrl
4259 , wip_entities we
4260 WHERE mmtt.transaction_temp_id = p_temp_id
4261 AND mmtt.transaction_source_type_id = 5
4262 AND mmtt.transaction_action_id = 1
4263 AND mmtt.move_order_line_id = mtrl.line_id
4264 AND mtrl.txn_source_id = we.wip_entity_id
4265 AND mtrl.organization_id = we.organization_id;
4266
4267 BEGIN
4268 x_return_status := fnd_api.g_ret_sts_success;
4269
4270 IF l_debug = 1 THEN
4271 print_debug
4272 ( 'Entered with parameters: ' || g_newline ||
4273 'p_organization_id => ' || to_char(p_organization_id) || g_newline ||
4274 'p_transfer_lpn_id => ' || to_char(p_transfer_lpn_id)
4275 , l_api_name
4276 );
4277 END IF;
4278
4279 --
4280 -- Validate passed in Org and LPN
4281 --
4282 IF p_organization_id <> g_current_drop_lpn.organization_id
4283 OR
4284 p_transfer_lpn_id <> g_current_drop_lpn.lpn_id
4285 THEN
4286 IF l_debug = 1 THEN
4287 print_debug
4288 ( 'Passed in org or LPN did not match cached info: '
4289 || g_newline || 'p_organization_id: ' || to_char(p_organization_id)
4290 || g_newline || 'p_transfer_lpn_id: ' || to_char(p_transfer_lpn_id)
4291 || g_newline || 'Cached Org ID: ' || to_char(g_current_drop_lpn.organization_id)
4292 || g_newline || 'Cached LPN ID: ' || to_char(g_current_drop_lpn.lpn_id)
4293 , l_api_name
4294 );
4295 END IF;
4296 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4297 END IF;
4298
4299 l_transaction_temp_id := g_current_drop_lpn.current_drop_list.FIRST;
4300
4301 IF l_debug = 1 THEN
4302 print_debug
4303 ( 'Transaction temp ID: ' || to_char(l_transaction_temp_id)
4304 , l_api_name
4305 );
4306 END IF;
4307
4308 OPEN c_get_entity_type (l_transaction_temp_id);
4309 FETCH c_get_entity_type INTO l_wip_entity_type;
4310 CLOSE c_get_entity_type;
4311
4312 IF l_wip_entity_type IS NULL THEN
4313 IF l_debug = 1 THEN
4314 print_debug
4315 ( 'Unable to determine entity type'
4316 , l_api_name
4317 );
4318 END IF;
4319 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4320 END IF;
4321
4322 x_entity_type := l_wip_entity_type;
4323
4324 l_api_return_status := fnd_api.g_ret_sts_success;
4325 wms_wip_integration.get_wip_job_info
4326 ( p_temp_id => l_transaction_temp_id
4327 , p_wip_entity_type => l_wip_entity_type
4328 , x_job => x_job
4329 , x_line => x_line
4330 , x_dept => x_dept
4331 , x_operation_seq_num => x_operation_seq_num
4332 , x_start_date => x_start_date
4333 , x_schedule => x_schedule
4334 , x_assembly => x_assembly
4335 , x_return_status => l_api_return_status
4336 , x_msg_count => l_msg_count
4337 , x_msg_data => l_msg_data
4338 );
4339
4340 IF l_api_return_status <> fnd_api.g_ret_sts_success
4341 THEN
4342 IF l_debug = 1 THEN
4343 print_debug
4344 ( 'wms_wip_integration.get_wip_job_info returned status '
4345 || l_api_return_status
4346 , l_api_name
4347 );
4348 END IF;
4349 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4350 ELSE
4351 IF l_debug = 1 THEN
4352 print_debug
4353 ( 'Return values from wms_wip_integration.get_wip_job_info: '
4354 || g_newline || 'x_job: ' || x_job
4355 || g_newline || 'x_line: ' || x_line
4356 || g_newline || 'x_dept: ' || x_dept
4357 || g_newline || 'x_operation_seq_num: ' || to_char(x_operation_seq_num)
4358 || g_newline || 'x_start_date: ' || to_char(x_start_date, 'DD-MON-YYYY HH24:MI:SS')
4359 || g_newline || 'x_schedule: ' || x_schedule
4360 || g_newline || 'x_assembly: ' || x_assembly
4361 , l_api_name
4362 );
4363 END IF;
4364 END IF;
4365
4366 EXCEPTION
4367 WHEN fnd_api.g_exc_error THEN
4368 x_return_status := fnd_api.g_ret_sts_error;
4369
4370 fnd_msg_pub.count_and_get
4371 ( p_count => l_msg_count
4372 , p_data => l_msg_data
4373 , p_encoded => fnd_api.g_false
4374 );
4375
4376 IF l_debug = 1 THEN
4377 print_debug (l_msg_data, l_api_name);
4378 END IF;
4379
4380 WHEN OTHERS THEN
4381 x_return_status := fnd_api.g_ret_sts_unexp_error;
4382
4383 IF l_debug = 1 THEN
4384 print_debug ('Other error: ' || sqlerrm, l_api_name);
4385 END IF;
4386
4387 END get_wip_job_info;
4388
4389
4390 PROCEDURE get_sub_xfer_dest_info
4391 (x_to_sub OUT NOCOPY VARCHAR2,
4392 x_to_loc OUT NOCOPY VARCHAR2,
4393 x_to_loc_id OUT NOCOPY NUMBER,
4394 x_project_num OUT NOCOPY VARCHAR2,
4395 x_prj_id OUT NOCOPY VARCHAR2,
4396 x_task_num OUT NOCOPY VARCHAR2,
4397 x_tsk_id OUT NOCOPY VARCHAR2,
4398 x_return_status OUT NOCOPY VARCHAR2,
4399 p_organization_id IN NUMBER,
4400 p_transfer_lpn_id IN NUMBER,
4401 x_transfer_lpn_id OUT nocopy NUMBER,
4402 x_transfer_lpn OUT nocopy VARCHAR2) IS
4403
4404 l_api_name VARCHAR2(30) := 'get_sub_xfer_dest_info';
4405 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4406
4407 l_msg_count NUMBER;
4408 l_msg_data VARCHAR2(2000);
4409
4410 l_transaction_temp_id NUMBER;
4411 l_subinventory_code VARCHAR2(20);
4412 l_locator_id NUMBER;
4413
4414 CURSOR c_get_mmtt_info(p_temp_id NUMBER) IS
4415 SELECT mmtt.transfer_subinventory, mmtt.transfer_to_location,
4416 decode(transaction_action_id, 28,mmtt.cartonization_id, NULL)
4417 --mmtt.cartonization_id has the LPN suggested by MDC
4418 --IT is applicable only to MDC case for staging transfer PickDrops
4419 -- For all others, it should be null
4420 FROM mtl_material_transactions_temp mmtt
4421 WHERE mmtt.transaction_temp_id = p_temp_id;
4422
4423 BEGIN
4424 x_return_status := fnd_api.g_ret_sts_success;
4425
4426 IF l_debug = 1 THEN
4427 print_debug
4428 ('Entered with parameters: ' || g_newline ||
4429 'p_organization_id => ' || to_char(p_organization_id) || g_newline ||
4430 'p_transfer_lpn_id => ' || to_char(p_transfer_lpn_id)
4431 , l_api_name);
4432 END IF;
4433
4434 --
4435 -- Validate passed in Org and LPN
4436 --
4437 IF p_organization_id <> g_current_drop_lpn.organization_id OR
4438 p_transfer_lpn_id <> g_current_drop_lpn.lpn_id THEN
4439 IF l_debug = 1 THEN
4440 print_debug
4441 ( 'Passed in org or LPN did not match cached info: '
4442 || g_newline || 'p_organization_id: ' || to_char(p_organization_id)
4443 || g_newline || 'p_transfer_lpn_id: ' || to_char(p_transfer_lpn_id)
4444 || g_newline || 'Cached Org ID: ' || to_char(g_current_drop_lpn.organization_id)
4445 || g_newline || 'Cached LPN ID: ' || to_char(g_current_drop_lpn.lpn_id)
4446 , l_api_name);
4447 END IF;
4448 RAISE fnd_api.g_exc_unexpected_error;
4449 END IF;
4450
4451 l_transaction_temp_id := g_current_drop_lpn.current_drop_list.FIRST;
4452
4453 IF l_debug = 1 THEN
4454 print_debug
4455 ('Transaction temp ID: ' || to_char(l_transaction_temp_id), l_api_name);
4456 END IF;
4457
4458 OPEN c_get_mmtt_info (l_transaction_temp_id);
4459 FETCH c_get_mmtt_info INTO l_subinventory_code, l_locator_id, x_transfer_lpn_id;
4460 CLOSE c_get_mmtt_info;
4461
4462 IF l_debug = 1 THEN
4463 print_debug
4464 ('c_get_mmtt_info returned To Subinventory ' || l_subinventory_code ||
4465 ', To Locator ID ' || to_char(l_locator_id) ||
4466 ', To LPN ID ' || x_transfer_lpn_id
4467 , l_api_name);
4468 END IF;
4469
4470 x_to_sub := l_subinventory_code;
4471 x_to_loc := inv_project.get_locsegs(l_locator_id, p_organization_id);
4472 x_to_loc_id := l_locator_id;
4473
4474 x_project_num := inv_project.get_project_number;
4475 x_prj_id := inv_project.get_project_id;
4476 x_task_num := inv_project.get_task_number;
4477 x_tsk_id := inv_project.get_task_id;
4478
4479 IF x_transfer_lpn_id IS NOT NULL THEN
4480 SELECT license_plate_number
4481 INTO x_transfer_lpn
4482 FROM wms_license_plate_numbers
4483 WHERE lpn_id = x_transfer_lpn_id;
4484 END IF;
4485
4486 IF l_debug = 1 THEN
4487 print_debug
4488 ( 'Return values from inv_project: '
4489 || g_newline || 'x_to_loc: ' || x_to_loc
4490 || g_newline || 'x_project_num: ' || x_project_num
4491 || g_newline || 'x_prj_id ' || x_prj_id
4492 || g_newline || 'x_task_num: ' || x_task_num
4493 || g_newline || 'x_tsk_id: ' || x_tsk_id
4494 , l_api_name);
4495 END IF;
4496
4497 EXCEPTION
4498 WHEN OTHERS THEN
4499 x_return_status := fnd_api.g_ret_sts_unexp_error;
4500
4501 IF l_debug = 1 THEN
4502 print_debug ('Other error: ' || sqlerrm, l_api_name);
4503 END IF;
4504
4505 END get_sub_xfer_dest_info;
4506
4507
4508 PROCEDURE get_default_drop_lpn
4509 ( x_drop_lpn_num OUT NOCOPY VARCHAR2
4510 , x_return_status OUT NOCOPY VARCHAR2
4511 , p_organization_id IN NUMBER
4512 , p_delivery_id IN NUMBER
4513 , p_to_sub IN VARCHAR2
4514 , p_to_loc IN NUMBER
4515 ) IS
4516
4517 l_api_name VARCHAR2(30) := 'get_default_drop_lpn';
4518 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4519
4520 l_lpn_id NUMBER;
4521 l_lpn_num VARCHAR2(30) := NULL;
4522
4523 CURSOR c_get_drop_lpn_id
4524 ( p_org_id IN NUMBER
4525 , p_deliv_id IN NUMBER
4526 , p_subinv IN VARCHAR2
4527 , p_loc_id IN NUMBER
4528 ) IS
4529 SELECT wlpn.outermost_lpn_id
4530 FROM wsh_delivery_assignments_v wda
4531 , wsh_delivery_details_ob_grp_v wdd
4532 , wms_license_plate_numbers wlpn
4533 WHERE wda.delivery_id = p_deliv_id
4534 AND wda.parent_delivery_detail_id = wdd.delivery_detail_id
4535 AND wdd.organization_id = p_org_id
4536 AND wdd.lpn_id = wlpn.lpn_id
4537 AND wlpn.subinventory_code = p_subinv
4538 AND wlpn.locator_id = p_loc_id
4539 AND wlpn.lpn_context = 11
4540 ORDER BY wda.CREATION_DATE DESC;
4541
4542 CURSOR c_get_lpn
4543 ( p_lpn_id IN NUMBER
4544 ) IS
4545 SELECT license_plate_number
4546 FROM wms_license_plate_numbers wlpn
4547 WHERE wlpn.lpn_id = p_lpn_id;
4548
4549 BEGIN
4550 x_return_status := fnd_api.g_ret_sts_success;
4551 x_drop_lpn_num := NULL;
4552
4553 fnd_msg_pub.initialize;
4554
4555 IF l_debug = 1 THEN
4556 print_debug
4557 ( 'Entered with parameters: ' || g_newline ||
4558 'p_organization_id => ' || to_char(p_organization_id) || g_newline ||
4559 'p_delivery_id => ' || to_char(p_delivery_id) || g_newline ||
4560 'p_to_sub => ' || p_to_sub || g_newline ||
4561 'p_to_loc => ' || to_char(p_to_loc)
4562 , l_api_name
4563 );
4564 END IF;
4565
4566 OPEN c_get_drop_lpn_id
4567 ( p_organization_id
4568 , p_delivery_id
4569 , p_to_sub
4570 , p_to_loc
4571 );
4572 FETCH c_get_drop_lpn_id INTO l_lpn_id;
4573 CLOSE c_get_drop_lpn_id;
4574
4575 IF l_lpn_id IS NOT NULL THEN
4576 OPEN c_get_lpn (l_lpn_id);
4577 FETCH c_get_lpn INTO l_lpn_num;
4578 CLOSE c_get_lpn;
4579 END IF;
4580
4581 IF l_lpn_num IS NOT NULL THEN
4582 x_drop_lpn_num := l_lpn_num;
4583 END IF;
4584
4585 EXCEPTION
4586 WHEN OTHERS THEN
4587 x_return_status := fnd_api.g_ret_sts_unexp_error;
4588
4589 IF l_debug = 1 THEN
4590 print_debug ('Other error: ' || sqlerrm, l_api_name);
4591 END IF;
4592
4593 IF c_get_drop_lpn_id%ISOPEN THEN
4594 CLOSE c_get_drop_lpn_id;
4595 END IF;
4596
4597 IF c_get_lpn%ISOPEN THEN
4598 CLOSE c_get_lpn;
4599 END IF;
4600
4601 END get_default_drop_lpn;
4602
4603
4604
4605 PROCEDURE get_lot_lov
4606 ( x_lot_lov OUT NOCOPY t_genref
4607 , p_item_id IN NUMBER
4608 , p_revision IN VARCHAR2
4609 , p_inner_lpn IN VARCHAR2
4610 , p_conf_uom_code IN VARCHAR2
4611 , p_lot_num IN VARCHAR2
4612 ) IS
4613
4614 l_api_name VARCHAR2(30) := 'get_lot_lov';
4615 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4616
4617 l_dum_lpn VARCHAR2(31) := '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@';
4618
4619 BEGIN
4620
4621 IF l_debug = 1 THEN
4622 print_debug
4623 ( 'Entered with parameters: ' || g_newline ||
4624 'p_item_id => ' || to_char(p_item_id) || g_newline ||
4625 'p_revision => ' || p_revision || g_newline ||
4626 'p_inner_lpn => ' || p_inner_lpn || g_newline ||
4627 'p_conf_uom_code => ' || p_conf_uom_code || g_newline ||
4628 'p_lot_num => ' || p_lot_num
4629 , l_api_name
4630 );
4631 END IF;
4632
4633 IF p_conf_uom_code IS NULL THEN
4634 OPEN x_lot_lov FOR
4635 SELECT lot_number
4636 , primary_quantity
4637 FROM mtl_allocations_gtmp
4638 WHERE inventory_item_id = p_item_id
4639 AND NVL(revision,'@@@@') = NVL(p_revision, '@@@@')
4640 AND NVL(inner_lpn,l_dum_lpn) = NVL(p_inner_lpn,l_dum_lpn)
4641 AND lot_number LIKE (p_lot_num);
4642 ELSE
4643 OPEN x_lot_lov FOR
4644 SELECT lot_number
4645 , inv_convert.inv_um_convert
4646 ( p_item_id
4647 , NULL
4648 , primary_quantity
4649 , primary_uom_code
4650 , p_conf_uom_code
4651 , NULL
4652 , NULL
4653 ) lot_qty
4654 FROM mtl_allocations_gtmp
4655 WHERE inventory_item_id = p_item_id
4656 AND NVL(revision,'@@@@') = NVL(p_revision, '@@@@')
4657 AND NVL(inner_lpn,l_dum_lpn) = NVL(p_inner_lpn,l_dum_lpn)
4658 AND lot_number LIKE (p_lot_num);
4659 END IF;
4660 EXCEPTION
4661 WHEN OTHERS THEN
4662 IF l_debug = 1 THEN
4663 print_debug
4664 ( 'Error in get_lot_lov: ' || sqlerrm
4665 , l_api_name
4666 );
4667 END IF;
4668 RAISE;
4669 END get_lot_lov;
4670
4671
4672
4673 PROCEDURE get_serial_lov
4674 ( x_serial_lov OUT NOCOPY t_genref
4675 , p_item_id IN NUMBER
4676 , p_revision IN VARCHAR2
4677 , p_inner_lpn IN VARCHAR2
4678 , p_lot_num IN VARCHAR2
4679 , p_serial IN VARCHAR2
4680 ) IS
4681
4682 l_api_name VARCHAR2(30) := 'get_serial_lov';
4683 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4684
4685 l_dum_lpn VARCHAR2(31) := '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@';
4686
4687 BEGIN
4688
4689 IF l_debug = 1 THEN
4690 print_debug
4691 ( 'Entered with parameters: ' || g_newline ||
4692 'p_item_id => ' || to_char(p_item_id) || g_newline ||
4693 'p_revision => ' || p_revision || g_newline ||
4694 'p_inner_lpn => ' || p_inner_lpn || g_newline ||
4695 'p_lot_num => ' || p_lot_num || g_newline ||
4696 'p_serial => ' || p_serial
4697 , l_api_name
4698 );
4699 END IF;
4700
4701 OPEN x_serial_lov FOR
4702 SELECT serial_number
4703 FROM mtl_allocations_gtmp
4704 WHERE inventory_item_id = p_item_id
4705 AND NVL(revision,'@@@@') = NVL(p_revision, '@@@@')
4706 AND NVL(inner_lpn,l_dum_lpn) = NVL(p_inner_lpn,l_dum_lpn)
4707 AND NVL(lot_number,'@@@@') = NVL(p_lot_num, '@@@@')
4708 AND serial_number LIKE (p_serial);
4709 EXCEPTION
4710 WHEN OTHERS THEN
4711 IF l_debug = 1 THEN
4712 print_debug
4713 ( 'Error in get_serial_lov: ' || sqlerrm
4714 , l_api_name
4715 );
4716 END IF;
4717 RAISE;
4718 END get_serial_lov;
4719
4720
4721
4722 PROCEDURE insert_child_msnt
4723 ( x_return_status OUT NOCOPY VARCHAR2
4724 , p_temp_id IN NUMBER
4725 , p_parent_tmp_id IN NUMBER
4726 , p_txn_header_id IN NUMBER
4727 ) IS
4728
4729 l_api_name VARCHAR2(30) := 'insert_child_msnt';
4730 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
4731
4732 l_dummy VARCHAR2(1) := NULL;
4733 l_lot_controlled BOOLEAN;
4734 l_srl_qty NUMBER;
4735
4736 l_serial_number VARCHAR2(30);
4737 l_serial_temp_id NUMBER;
4738
4739
4740 CURSOR c_get_mmtt_info
4741 ( p_tmp_id IN NUMBER
4742 ) IS
4743 SELECT mmtt.primary_quantity
4744 , mmtt.inventory_item_id
4745 , mmtt.organization_id
4746 , mmtt.revision
4747 FROM mtl_material_transactions_temp mmtt
4748 WHERE mmtt.transaction_temp_id = p_tmp_id;
4749
4750 mmtt_info_rec c_get_mmtt_info%ROWTYPE;
4751
4752
4753 CURSOR c_get_msnt
4754 ( p_parent_id IN NUMBER
4755 ) IS
4756 SELECT rowid
4757 , fm_serial_number
4758 FROM mtl_serial_numbers_temp
4759 WHERE transaction_temp_id = p_parent_id;
4760
4761 msnt_rec c_get_msnt%ROWTYPE;
4762
4763
4764 CURSOR c_get_lot_msnt
4765 ( p_parent_id IN NUMBER
4766 , p_lot_num IN VARCHAR2
4767 ) IS
4768 SELECT msnt.rowid
4769 , msnt.fm_serial_number
4770 FROM mtl_transaction_lots_temp mtlt
4771 , mtl_serial_numbers_temp msnt
4772 WHERE mtlt.transaction_temp_id = p_parent_id
4773 AND mtlt.lot_number = p_lot_num
4774 AND msnt.transaction_temp_id = mtlt.serial_transaction_temp_id;
4775
4776 lot_msnt_rec c_get_lot_msnt%ROWTYPE;
4777
4778
4779 CURSOR c_get_lot_records
4780 ( p_tmp_id IN NUMBER
4781 ) IS
4782 SELECT mtlt.rowid
4783 , mtlt.lot_number
4784 , mtlt.primary_quantity
4785 FROM mtl_transaction_lots_temp mtlt
4786 WHERE mtlt.transaction_temp_id = p_tmp_id;
4787
4788 lot_details_rec c_get_lot_records%ROWTYPE;
4789
4790 BEGIN
4791 x_return_status := fnd_api.g_ret_sts_success;
4792
4793 IF l_debug = 1 THEN
4794 print_debug
4795 ( 'Entered with parameters: ' || g_newline ||
4796 'p_temp_id => ' || to_char(p_temp_id) || g_newline ||
4797 'p_parent_tmp_id => ' || to_char(p_parent_tmp_id) || g_newline ||
4798 'p_txn_header_id => ' || to_char(p_txn_header_id)
4799 , l_api_name
4800 );
4801 END IF;
4802
4803 SAVEPOINT insert_msnt_sp;
4804
4805 OPEN c_get_mmtt_info (p_temp_id);
4806 FETCH c_get_mmtt_info INTO mmtt_info_rec;
4807 CLOSE c_get_mmtt_info;
4808
4809 IF l_debug = 1 THEN
4810 print_debug
4811 ( 'Serial qty: ' || to_char(mmtt_info_rec.primary_quantity) ||
4812 ', Item ID: ' || to_char(mmtt_info_rec.inventory_item_id) ||
4813 ', Revision: ' || mmtt_info_rec.revision ||
4814 ', Org ID: ' || to_char(mmtt_info_rec.organization_id)
4815 , l_api_name
4816 );
4817 END IF;
4818
4819 BEGIN
4820 SELECT 'x'
4821 INTO l_dummy
4822 FROM dual
4823 WHERE EXISTS
4824 ( SELECT 'x'
4825 FROM mtl_transaction_lots_temp mtlt
4826 WHERE mtlt.transaction_temp_id = p_temp_id
4827 );
4828
4829 IF l_debug = 1 THEN
4830 print_debug
4831 ( 'MTLT records exist for this temp ID'
4832 , l_api_name
4833 );
4834 END IF;
4835
4836 l_lot_controlled := TRUE;
4837
4838 EXCEPTION
4839 WHEN NO_DATA_FOUND THEN
4840 l_lot_controlled := FALSE;
4841
4842 WHEN OTHERS THEN
4843 IF l_debug = 1 THEN
4844 print_debug
4845 ( 'Exception trying to determine if MTLT records exist: '
4846 || sqlerrm
4847 , l_api_name
4848 );
4849 END IF;
4850
4851 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4852 END;
4853
4854 IF NOT l_lot_controlled
4855 THEN
4856 l_srl_qty := mmtt_info_rec.primary_quantity;
4857
4858 OPEN c_get_msnt (p_parent_tmp_id);
4859 FETCH c_get_msnt INTO msnt_rec;
4860
4861 IF c_get_msnt%NOTFOUND THEN
4862 IF l_debug = 1 THEN
4863 print_debug
4864 ( 'No parent serial records found.'
4865 , l_api_name
4866 );
4867 END IF;
4868 CLOSE c_get_msnt;
4869 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4870 END IF;
4871
4872 WHILE ( (c_get_msnt%FOUND)
4873 AND
4874 (l_srl_qty > 0)
4875 )
4876 LOOP
4877 UPDATE mtl_serial_numbers_temp msnt
4878 SET transaction_temp_id = p_temp_id
4879 WHERE rowid = msnt_rec.rowid;
4880
4881 l_srl_qty := l_srl_qty - 1;
4882
4883 IF l_debug = 1 THEN
4884 print_debug
4885 ( 'Updated serial ' || msnt_rec.fm_serial_number ||
4886 ', l_srl_qty is now: ' || to_char(l_srl_qty)
4887 , l_api_name
4888 );
4889 END IF;
4890
4891 UPDATE mtl_serial_numbers
4892 SET group_mark_id = p_txn_header_id
4893 WHERE current_organization_id = mmtt_info_rec.organization_id
4894 AND inventory_item_id = mmtt_info_rec.inventory_item_id
4895 AND NVL(revision,'@@@@') = NVL(mmtt_info_rec.revision,'@@@@')
4896 AND serial_number = msnt_rec.fm_serial_number;
4897
4898 FETCH c_get_msnt INTO msnt_rec;
4899
4900 END LOOP;
4901
4902 IF c_get_msnt%ISOPEN THEN
4903 CLOSE c_get_msnt;
4904 END IF;
4905
4906 IF l_srl_qty > 0 THEN
4907 IF l_debug = 1 THEN
4908 print_debug
4909 ( 'Still have qty on child with no MSNT: '
4910 || to_char(l_srl_qty)
4911 , l_api_name
4912 );
4913 END IF;
4914 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4915 END IF;
4916
4917 ELSE
4918 --
4919 -- Lot controlled
4920 --
4921 OPEN c_get_lot_records (p_temp_id);
4922 FETCH c_get_lot_records INTO lot_details_rec;
4923
4924 WHILE (c_get_lot_records%FOUND)
4925 LOOP
4926 IF l_debug = 1 THEN
4927 print_debug
4928 ( 'Processing lot ' || lot_details_rec.lot_number ||
4929 ' with quantity ' || to_char(lot_details_rec.primary_quantity)
4930 , l_api_name
4931 );
4932 END IF;
4933
4934 l_srl_qty := lot_details_rec.primary_quantity;
4935
4936 OPEN c_get_lot_msnt
4937 ( p_parent_tmp_id
4938 , lot_details_rec.lot_number
4939 );
4940 FETCH c_get_lot_msnt INTO lot_msnt_rec;
4941
4942 IF c_get_lot_msnt%NOTFOUND THEN
4943 IF l_debug = 1 THEN
4944 print_debug
4945 ( 'No parent serial records found.'
4946 , l_api_name
4947 );
4948 END IF;
4949 CLOSE c_get_lot_msnt;
4950 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
4951 ELSE
4952 IF l_debug = 1 THEN
4953 print_debug
4954 ( 'Fetched serial record for lot ' || lot_details_rec.lot_number
4955 , l_api_name
4956 );
4957 END IF;
4958 END IF;
4959
4960 SELECT mtl_material_transactions_s.NEXTVAL
4961 INTO l_serial_temp_id
4962 FROM dual;
4963
4964 IF l_debug = 1 THEN
4965 print_debug
4966 ( 'Generated new serial temp ID: ' || to_char(l_serial_temp_id)
4967 , l_api_name
4968 );
4969 END IF;
4970
4971 UPDATE mtl_transaction_lots_temp
4972 SET serial_transaction_temp_id = l_serial_temp_id
4973 WHERE rowid = lot_details_rec.rowid;
4974
4975 WHILE ( (c_get_lot_msnt%FOUND)
4976 AND
4977 (l_srl_qty > 0)
4978 )
4979 LOOP
4980 UPDATE mtl_serial_numbers_temp msnt
4981 SET transaction_temp_id = l_serial_temp_id
4982 WHERE rowid = lot_msnt_rec.rowid;
4983
4984 l_srl_qty := l_srl_qty - 1;
4985
4986 IF l_debug = 1 THEN
4987 print_debug
4988 ( 'Updated serial ' || lot_msnt_rec.fm_serial_number ||
4989 ', l_srl_qty is now: ' || to_char(l_srl_qty)
4990 , l_api_name
4991 );
4992 END IF;
4993
4994 UPDATE mtl_serial_numbers
4995 SET group_mark_id = p_txn_header_id
4996 WHERE current_organization_id = mmtt_info_rec.organization_id
4997 AND inventory_item_id = mmtt_info_rec.inventory_item_id
4998 AND NVL(revision,'@@@@') = NVL(mmtt_info_rec.revision,'@@@@')
4999 AND serial_number = lot_msnt_rec.fm_serial_number;
5000
5001 FETCH c_get_lot_msnt INTO lot_msnt_rec;
5002
5003 END LOOP;
5004
5005 IF c_get_lot_msnt%ISOPEN THEN
5006 CLOSE c_get_lot_msnt;
5007 END IF;
5008
5009 IF l_srl_qty > 0 THEN
5010 IF l_debug = 1 THEN
5011 print_debug
5012 ( 'Still have qty on child with no MSNT: '
5013 || to_char(l_srl_qty)
5014 , l_api_name
5015 );
5016 END IF;
5017 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5018 END IF;
5019
5020 FETCH c_get_lot_records INTO lot_details_rec;
5021 END LOOP; -- done looping through lots
5022 END IF; -- end ELSE if lot controlled
5023
5024 EXCEPTION
5025 WHEN OTHERS THEN
5026 ROLLBACK TO insert_msnt_sp;
5027
5028 x_return_status := fnd_api.g_ret_sts_unexp_error;
5029
5030 IF l_debug = 1 THEN
5031 print_debug ('Other error: ' || sqlerrm, l_api_name);
5032 END IF;
5033
5034 END insert_child_msnt;
5035
5036
5037
5038 PROCEDURE process_inner_lpn
5039 ( x_ret_code OUT NOCOPY NUMBER
5040 , x_remaining_qty OUT NOCOPY NUMBER
5041 , x_inner_lpn_exists OUT NOCOPY VARCHAR2
5042 , x_return_status OUT NOCOPY VARCHAR2
5043 , p_lpn IN VARCHAR2
5044 , p_group_number IN NUMBER
5045 , p_item_id IN NUMBER
5046 , p_revision IN VARCHAR2
5047 , p_qty IN NUMBER
5048 , p_primary_uom IN VARCHAR2
5049 , p_serial_control IN VARCHAR2
5050 ) IS
5051
5052 l_api_name VARCHAR2(30) := 'process_inner_lpn';
5053 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5054 l_api_return_status VARCHAR2(1);
5055
5056 l_temp_tbl g_temp_id_tbl;
5057
5058 l_msg_count NUMBER;
5059 l_msg_data VARCHAR2(2000);
5060
5061 l_inner_lpn_id NUMBER;
5062 l_parent_temp_id NUMBER;
5063 l_lpn_pri_qty NUMBER;
5064 l_from_sub VARCHAR2(30);
5065 l_from_loc_id NUMBER;
5066
5067 l_transaction_temp_id NUMBER;
5068 l_txn_header_id NUMBER;
5069 l_new_temp_id NUMBER;
5070 l_mmtt_qty NUMBER := 0;
5071 l_tot_mmtt_qty NUMBER := 0;
5072
5073 l_remaining_qty NUMBER;
5074 l_txn_qty NUMBER;
5075 l_pri_qty NUMBER;
5076
5077 ii NUMBER;
5078 jj NUMBER;
5079
5080 l_dummy VARCHAR2(1) := NULL;
5081 l_inner_lpn_exists VARCHAR2(1) := NULL;
5082
5083 CURSOR c_get_inner_lpn_details
5084 ( p_inner_lpn IN VARCHAR2
5085 , p_outer_lpn_id IN NUMBER
5086 , p_org_id IN NUMBER
5087 ) IS
5088 SELECT wlpn.lpn_id
5089 , mmtt.transaction_temp_id
5090 , mmtt.primary_quantity
5091 , mmtt.subinventory_code
5092 , mmtt.locator_id
5093 FROM wms_license_plate_numbers wlpn
5094 , mtl_material_transactions_temp mmtt
5095 WHERE wlpn.license_plate_number = p_inner_lpn
5096 AND wlpn.organization_id = p_org_id
5097 AND mmtt.transfer_lpn_id = p_outer_lpn_id
5098 AND mmtt.organization_id = p_org_id
5099 AND mmtt.parent_line_id = mmtt.transaction_temp_id
5100 AND mmtt.content_lpn_id <> mmtt.transfer_lpn_id
5101 AND mmtt.content_lpn_id = wlpn.lpn_id;
5102
5103 BEGIN
5104 x_return_status := fnd_api.g_ret_sts_success;
5105
5106 fnd_msg_pub.initialize;
5107
5108 IF l_debug = 1 THEN
5109 print_debug
5110 ( 'Entered with parameters: ' || g_newline ||
5111 'p_lpn => ' || p_lpn || g_newline ||
5112 'p_group_number => ' || to_char(p_group_number) || g_newline ||
5113 'p_item_id => ' || to_char(p_item_id) || g_newline ||
5114 'p_revision => ' || p_revision || g_newline ||
5115 'p_qty => ' || to_char(p_qty) || g_newline ||
5116 'p_primary_uom => ' || p_primary_uom || g_newline ||
5117 'p_serial_control => ' || p_serial_control
5118 , l_api_name
5119 );
5120 END IF;
5121
5122 SAVEPOINT process_lpn_sp;
5123
5124 OPEN c_get_inner_lpn_details
5125 ( p_lpn
5126 , g_current_drop_lpn.lpn_id
5127 , g_current_drop_lpn.organization_id
5128 );
5129 FETCH c_get_inner_lpn_details INTO l_inner_lpn_id
5130 , l_parent_temp_id
5131 , l_lpn_pri_qty
5132 , l_from_sub
5133 , l_from_loc_id;
5134
5135 IF c_get_inner_lpn_details%NOTFOUND THEN
5136 CLOSE c_get_inner_lpn_details;
5137 IF l_debug = 1 THEN
5138 print_debug
5139 ( 'Cannot find scanned LPN ' || p_lpn ||
5140 ' in outer LPN ID ' || to_char(g_current_drop_lpn.lpn_id)
5141 , l_api_name
5142 );
5143 END IF;
5144
5145 fnd_message.set_name('WMS', 'WMS_LPN_NOT_IN_OUTER');
5146 fnd_msg_pub.ADD;
5147 RAISE FND_API.G_EXC_ERROR;
5148 ELSE
5149 IF l_debug = 1 THEN
5150 print_debug
5151 ( 'Found scanned LPN ' || p_lpn ||
5152 '. LPN ID is ' || to_char(l_inner_lpn_id) ||
5153 '. Primary qty is ' || to_char(l_lpn_pri_qty) ||
5154 '. Parent temp ID is ' || to_char(l_parent_temp_id)
5155 , l_api_name
5156 );
5157 END IF;
5158 END IF;
5159
5160 IF c_get_inner_lpn_details%ISOPEN
5161 THEN
5162 CLOSE c_get_inner_lpn_details;
5163 END IF;
5164
5165 l_api_return_status := fnd_api.g_ret_sts_success;
5166 get_temp_list
5167 ( x_temp_tbl => l_temp_tbl
5168 , x_return_status => l_api_return_status
5169 , p_group_num => p_group_number
5170 , p_status => 'PENDING'
5171 );
5172
5173 IF l_api_return_status <> fnd_api.g_ret_sts_success
5174 THEN
5175 IF l_debug = 1 THEN
5176 print_debug ('Error from get_temp_list', l_api_name);
5177 END IF;
5178 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5179 ELSIF NOT (l_temp_tbl.COUNT > 0)
5180 THEN
5181 IF l_debug = 1 THEN
5182 print_debug ('get_temp_list returned no MMTT records', l_api_name);
5183 END IF;
5184 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5185 ELSE
5186 IF l_debug = 1 THEN
5187 print_debug
5188 ( 'MMTT record count from get_temp_list: '
5189 || to_char(l_temp_tbl.COUNT)
5190 , l_api_name
5191 );
5192 END IF;
5193 END IF;
5194
5195 IF l_lpn_pri_qty >= p_qty
5196 THEN
5197 IF l_lpn_pri_qty > p_qty
5198 THEN
5199 x_ret_code := 1;
5200 ELSE
5201 x_ret_code := 2;
5202 END IF;
5203
5204 x_remaining_qty := 0;
5205
5206 ii := l_temp_tbl.FIRST;
5207 jj := l_temp_tbl.LAST;
5208
5209 l_transaction_temp_id := l_temp_tbl(ii);
5210
5211 IF l_debug = 1 THEN
5212 print_debug
5213 ( 'ii = ' || to_char(ii) || ', jj = ' || to_char(jj)
5214 , l_api_name
5215 );
5216 END IF;
5217
5218 WHILE (ii <= jj)
5219 LOOP
5220 IF l_debug = 1 THEN
5221 print_debug
5222 ( ' Updating lpn_id on temp ID ' || to_char(l_transaction_temp_id)
5223 , l_api_name
5224 );
5225 END IF;
5226
5227 UPDATE mtl_material_transactions_temp mmtt
5228 SET lpn_id = l_inner_lpn_id
5229 , transfer_lpn_id = DECODE( x_ret_code
5230 , 2, l_inner_lpn_id
5231 , NULL
5232 )
5233 , subinventory_code = l_from_sub
5234 , locator_id = l_from_loc_id
5235 WHERE mmtt.transaction_temp_id = l_transaction_temp_id
5236 RETURNING mmtt.primary_quantity
5237 , mmtt.transaction_header_id
5238 INTO l_mmtt_qty
5239 , l_txn_header_id;
5240
5241 l_tot_mmtt_qty := l_tot_mmtt_qty + NVL(l_mmtt_qty,0);
5242
5243 IF l_debug = 1 THEN
5244 print_debug
5245 ( 'Updated temp ID ' || to_char(l_transaction_temp_id) ||
5246 ' having qty ' || to_char(l_mmtt_qty) ||
5247 ' and txn hdr ID ' || to_char(l_txn_header_id) ||
5248 '. Total qty is ' || to_char(l_tot_mmtt_qty)
5249 , l_api_name
5250 );
5251 END IF;
5252
5253 IF x_ret_code = 1
5254 THEN
5255 g_current_drop_lpn.current_drop_list(l_transaction_temp_id) := 'LPN_DONE';
5256 ELSIF x_ret_code = 2
5257 THEN
5258 g_current_drop_lpn.current_drop_list(l_transaction_temp_id) := 'DONE';
5259
5260 -- Start change for Bug 5620764
5261 -- Updates LPN context to "Packing Content" since entire LPN is consumed
5262 -- Bug5659809: update last_update_date and last_update_by as well
5263 UPDATE wms_license_plate_numbers
5264 SET lpn_context = WMS_Container_PUB.LPN_CONTEXT_PACKING
5265 , last_update_date = SYSDATE
5266 , last_updated_by = fnd_global.user_id
5267 WHERE lpn_id = l_inner_lpn_id;
5268
5269 IF l_debug = 1 THEN
5270 print_debug ('Updated LPN context to pack since entire LPN is
5271 consumed for LPN ' || l_inner_lpn_id
5272 , l_api_name);
5273 END IF;
5274 -- End change for bug 5620764
5275 END IF;
5276
5277 IF x_ret_code = 2
5278 AND
5279 p_serial_control = 'TRUE'
5280 THEN
5281 l_api_return_status := fnd_api.g_ret_sts_success;
5282 insert_child_msnt
5283 ( x_return_status => l_api_return_status
5284 , p_temp_id => l_transaction_temp_id
5285 , p_parent_tmp_id => l_parent_temp_id
5286 , p_txn_header_id => l_txn_header_id
5287 );
5288 IF l_api_return_status <> fnd_api.g_ret_sts_success
5289 THEN
5290 IF l_debug = 1 THEN
5291 print_debug ('Error from insert_child_msnt', l_api_name);
5292 END IF;
5293 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5294 ELSE
5295 IF l_debug = 1 THEN
5296 print_debug ('Success status from insert_child_msnt', l_api_name);
5297 END IF;
5298 END IF;
5299 END IF;
5300
5301 IF l_debug = 1 THEN
5302 print_debug
5303 ( ' Done processing temp ID ' || to_char(l_transaction_temp_id)
5304 , l_api_name
5305 );
5306 END IF;
5307
5308 IF ii < jj THEN
5309 ii := l_temp_tbl.NEXT(ii);
5310 l_transaction_temp_id := l_temp_tbl(ii);
5311 ELSE
5312 EXIT;
5313 END IF;
5314
5315 IF l_debug = 1 THEN
5316 print_debug
5317 ( 'Fetched next temp ID: ' || to_char(l_transaction_temp_id)
5318 , l_api_name
5319 );
5320 END IF;
5321 END LOOP;
5322 ELSE
5323 --
5324 -- l_lpn_pri_qty < p_qty
5325 --
5326 x_ret_code := 3;
5327 x_remaining_qty := p_qty - l_lpn_pri_qty;
5328
5329 l_remaining_qty := l_lpn_pri_qty;
5330
5331 ii := l_temp_tbl.FIRST;
5332 jj := l_temp_tbl.LAST;
5333
5334 l_transaction_temp_id := l_temp_tbl(ii);
5335
5336 IF l_debug = 1 THEN
5337 print_debug
5338 ( 'ii = ' || to_char(ii) || ', jj = ' || to_char(jj) ||
5339 ', l_remaining_qty: ' || to_char(l_remaining_qty)
5340 , l_api_name
5341 );
5342 END IF;
5343
5344 WHILE ( (ii <= jj)
5345 AND
5346 (l_remaining_qty > 0)
5347 )
5348 LOOP
5349 IF l_debug = 1 THEN
5350 print_debug
5351 ( ' Updating lpn_id on temp ID ' || to_char(l_transaction_temp_id)
5352 , l_api_name
5353 );
5354 END IF;
5355
5356 UPDATE mtl_material_transactions_temp mmtt
5357 SET lpn_id = l_inner_lpn_id
5358 , transfer_lpn_id = l_inner_lpn_id
5359 , subinventory_code = l_from_sub
5360 , locator_id = l_from_loc_id
5361 WHERE mmtt.transaction_temp_id = l_transaction_temp_id
5362 RETURNING mmtt.primary_quantity
5363 , mmtt.transaction_header_id
5364 INTO l_mmtt_qty
5365 , l_txn_header_id;
5366
5367 IF l_debug = 1 THEN
5368 print_debug
5369 ( ' Updated temp ID ' || to_char(l_transaction_temp_id)
5370 || ', primary qty is ' || to_char(l_mmtt_qty)
5371 || ', txn hdr ID is ' || to_char(l_txn_header_id)
5372 , l_api_name
5373 );
5374 END IF;
5375
5376 IF l_mmtt_qty <= l_remaining_qty
5377 THEN
5378 l_remaining_qty := l_remaining_qty - l_mmtt_qty;
5379
5380 IF l_debug = 1 THEN
5381 print_debug
5382 ( 'Current MMTT qty <= remaining. '
5383 || 'Remaining is now: ' || to_char(l_remaining_qty)
5384 , l_api_name
5385 );
5386 END IF;
5387
5388 ELSE
5389 l_api_return_status := fnd_api.g_ret_sts_success;
5390 split_mmtt
5391 ( x_new_temp_id => l_new_temp_id
5392 , x_return_status => l_api_return_status
5393 , p_temp_id => l_transaction_temp_id
5394 );
5395
5396 IF l_api_return_status <> fnd_api.g_ret_sts_success
5397 THEN
5398 IF l_debug = 1 THEN
5399 print_debug
5400 ( 'split_mmtt returned status ' || l_api_return_status
5401 , l_api_name
5402 );
5403 END IF;
5404 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5405 END IF;
5406
5407 UPDATE mtl_material_transactions_temp
5408 SET transaction_quantity = DECODE( transaction_uom
5409 , p_primary_uom, l_remaining_qty
5410 , inv_convert.inv_um_convert
5411 ( p_item_id
5412 , NULL
5413 , l_remaining_qty
5414 , p_primary_uom
5415 , transaction_uom
5416 , NULL
5417 , NULL
5418 )
5419 )
5420 , primary_quantity = l_remaining_qty
5421 , reservation_quantity = DECODE( reservation_quantity
5422 , NULL, NULL
5423 , l_remaining_qty
5424 )
5425 WHERE transaction_temp_id = l_transaction_temp_id
5426 RETURNING transaction_quantity INTO l_txn_qty;
5427
5428 IF l_debug = 1 THEN
5429 print_debug
5430 ('Reduced qty for temp ID ' || to_char(l_transaction_temp_id)
5431 || ' to ' || to_char(l_remaining_qty)
5432 , l_api_name
5433 );
5434 END IF;
5435
5436 UPDATE mtl_material_transactions_temp
5437 SET transaction_quantity = transaction_quantity - l_txn_qty
5438 , primary_quantity = primary_quantity - l_remaining_qty
5439 , reservation_quantity = DECODE( reservation_quantity
5440 , NULL, NULL
5441 , reservation_quantity - l_remaining_qty
5442 )
5443 , lpn_id = NULL
5444 , transfer_lpn_id = NULL
5445 , subinventory_code = NULL
5446 , locator_id = NULL
5447 WHERE transaction_temp_id = l_new_temp_id
5448 RETURNING primary_quantity INTO l_pri_qty;
5449
5450 IF l_debug = 1 THEN
5451 print_debug
5452 ('Updated new temp ID ' || to_char(l_new_temp_id) ||
5453 ' with qty : ' || to_char(l_pri_qty)
5454 , l_api_name
5455 );
5456 END IF;
5457
5458 l_mmtt_qty := l_remaining_qty;
5459 l_remaining_qty := 0;
5460
5461 END IF;
5462
5463 l_tot_mmtt_qty := l_tot_mmtt_qty + NVL(l_mmtt_qty,0);
5464 g_current_drop_lpn.current_drop_list(l_transaction_temp_id) := 'DONE';
5465
5466 IF p_serial_control = 'TRUE'
5467 THEN
5468 l_api_return_status := fnd_api.g_ret_sts_success;
5469 insert_child_msnt
5470 ( x_return_status => l_api_return_status
5471 , p_temp_id => l_transaction_temp_id
5472 , p_parent_tmp_id => l_parent_temp_id
5473 , p_txn_header_id => l_txn_header_id
5474 );
5475 IF l_api_return_status <> fnd_api.g_ret_sts_success
5476 THEN
5477 IF l_debug = 1 THEN
5478 print_debug ('Error from insert_child_msnt', l_api_name);
5479 END IF;
5480 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5481 ELSE
5482 IF l_debug = 1 THEN
5483 print_debug ('Success status from insert_child_msnt', l_api_name);
5484 END IF;
5485 END IF;
5486 END IF; -- if item is serial controlled
5487
5488 IF l_debug = 1 THEN
5489 print_debug
5490 ( ' Done processing temp ID ' || to_char(l_transaction_temp_id)
5491 , l_api_name
5492 );
5493 END IF;
5494
5495 IF ii < jj THEN
5496 ii := l_temp_tbl.NEXT(ii);
5497 l_transaction_temp_id := l_temp_tbl(ii);
5498 ELSE
5499 EXIT;
5500 END IF;
5501
5502 IF l_debug = 1 THEN
5503 print_debug
5504 ( 'Fetched next temp ID: ' || to_char(l_transaction_temp_id)
5505 , l_api_name
5506 );
5507 END IF;
5508 END LOOP;
5509
5510 IF l_remaining_qty > 0
5511 THEN
5512 IF l_debug = 1 THEN
5513 print_debug
5514 ( 'Some qty remaining: ' || to_char(l_remaining_qty)
5515 , l_api_name
5516 );
5517 END IF;
5518 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5519 END IF;
5520
5521 END IF; -- checking LPN avail qty against entered qty
5522
5523 IF x_ret_code IN (2,3)
5524 THEN
5525 UPDATE mtl_material_transactions_temp mmtt
5526 SET content_lpn_id = NULL
5527 , transaction_quantity = 0
5528 , primary_quantity = 0
5529 , reservation_quantity = 0
5530 WHERE mmtt.transaction_temp_id = l_parent_temp_id;
5531 ELSE
5532 UPDATE mtl_material_transactions_temp mmtt
5533 SET transaction_quantity = DECODE( transaction_uom
5534 , p_primary_uom, (primary_quantity - l_tot_mmtt_qty)
5535 , inv_convert.inv_um_convert
5536 ( p_item_id
5537 , NULL
5538 , primary_quantity - l_tot_mmtt_qty
5539 , p_primary_uom
5540 , transaction_uom
5541 , NULL
5542 , NULL
5543 )
5544 )
5545 , primary_quantity = primary_quantity - l_tot_mmtt_qty
5546 , reservation_quantity = DECODE( reservation_quantity
5547 , NULL, NULL
5548 , reservation_quantity - l_tot_mmtt_qty
5549 )
5550 WHERE mmtt.transaction_temp_id = l_parent_temp_id;
5551 END IF;
5552
5553 IF x_ret_code = 3
5554 THEN
5555 BEGIN
5556 SELECT 'x'
5557 INTO l_dummy
5558 FROM dual
5559 WHERE EXISTS
5560 ( SELECT 'x'
5561 FROM mtl_material_transactions_temp mmtt
5562 WHERE mmtt.organization_id = g_current_drop_lpn.organization_id
5563 AND mmtt.transfer_lpn_id = g_current_drop_lpn.lpn_id
5564 AND mmtt.parent_line_id = mmtt.transaction_temp_id
5565 AND mmtt.transaction_quantity > 0
5566 AND mmtt.inventory_item_id = p_item_id
5567 AND NVL(mmtt.revision,'@@@@') = NVL(p_revision,'@@@@')
5568 AND mmtt.content_lpn_id IS NOT NULL
5569 AND mmtt.content_lpn_id <> mmtt.transfer_lpn_id
5570 );
5571 l_inner_lpn_exists := 'Y';
5572 EXCEPTION
5573 WHEN NO_DATA_FOUND THEN
5574 l_inner_lpn_exists := 'N';
5575 END;
5576 END IF;
5577 x_inner_lpn_exists := l_inner_lpn_exists;
5578
5579 l_temp_tbl.DELETE;
5580
5581 EXCEPTION
5582 WHEN fnd_api.g_exc_error THEN
5583 ROLLBACK to process_lpn_sp;
5584
5585 x_return_status := fnd_api.g_ret_sts_error;
5586
5587 fnd_msg_pub.count_and_get
5588 ( p_count => l_msg_count
5589 , p_data => l_msg_data
5590 , p_encoded => fnd_api.g_false
5591 );
5592
5593 IF l_debug = 1 THEN
5594 print_debug (l_msg_data, l_api_name);
5595 END IF;
5596
5597 WHEN OTHERS THEN
5598 ROLLBACK to process_lpn_sp;
5599
5600 x_return_status := fnd_api.g_ret_sts_unexp_error;
5601
5602 IF l_debug = 1 THEN
5603 print_debug ('Other error: ' || sqlerrm, l_api_name);
5604 END IF;
5605
5606 END process_inner_lpn;
5607
5608
5609
5610 PROCEDURE process_loose_qty
5611 ( x_loose_qty_exists OUT NOCOPY VARCHAR2
5612 , x_return_status OUT NOCOPY VARCHAR2
5613 , p_group_number IN NUMBER
5614 , p_item_id IN NUMBER
5615 , p_revision IN VARCHAR2
5616 , p_qty IN NUMBER
5617 , p_primary_uom IN VARCHAR2
5618 ) IS
5619
5620 l_api_name VARCHAR2(30) := 'process_loose_qty';
5621 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
5622 l_api_return_status VARCHAR2(1);
5623
5624 l_available_qty NUMBER;
5625
5626 l_temp_tbl g_temp_id_tbl;
5627 l_process_tbl g_temp_id_tbl;
5628 l_parent_tbl g_temp_id_tbl;
5629
5630 l_mmtt_qty NUMBER := 0;
5631 l_transaction_temp_id NUMBER;
5632 l_remaining_qty NUMBER;
5633 l_new_temp_id NUMBER;
5634 l_txn_qty NUMBER;
5635 l_pri_qty NUMBER;
5636 l_parent_temp_id NUMBER;
5637
5638 l_msg_count NUMBER;
5639 l_msg_data VARCHAR2(2000);
5640
5641 ii NUMBER;
5642 jj NUMBER;
5643 kk NUMBER;
5644
5645 l_dummy VARCHAR2(1) := NULL;
5646 l_loose_qty_exists VARCHAR2(1) := NULL;
5647
5648 CURSOR c_get_available_loose_qty
5649 ( p_outer_lpn_id IN NUMBER
5650 , p_org_id IN NUMBER
5651 , p_itm_id IN NUMBER
5652 , p_rev IN VARCHAR2
5653 ) IS
5654 SELECT NVL(SUM(mmtt.primary_quantity),0)
5655 FROM mtl_material_transactions_temp mmtt
5656 WHERE mmtt.transfer_lpn_id = p_outer_lpn_id
5657 AND mmtt.organization_id = p_org_id
5658 AND mmtt.parent_line_id = mmtt.transaction_temp_id
5659 AND mmtt.transaction_quantity > 0
5660 AND mmtt.inventory_item_id = p_itm_id
5661 AND NVL(mmtt.revision,'@@@@') = NVL(p_rev,'@@@@')
5662 AND ( mmtt.content_lpn_id IS NULL
5663 OR
5664 mmtt.content_lpn_id = mmtt.transfer_lpn_id
5665 );
5666
5667
5668 CURSOR c_get_mmtt_qty
5669 ( p_temp_id IN NUMBER
5670 ) IS
5671 SELECT primary_quantity
5672 FROM mtl_material_transactions_temp
5673 WHERE transaction_temp_id = p_temp_id;
5674
5675
5676 CURSOR c_get_parents
5677 ( p_outer_lpn_id IN NUMBER
5678 , p_org_id IN NUMBER
5679 , p_itm_id IN NUMBER
5680 , p_rev IN VARCHAR2
5681 ) IS
5682 SELECT mmtt.transaction_temp_id
5683 FROM mtl_material_transactions_temp mmtt
5684 WHERE mmtt.transfer_lpn_id = p_outer_lpn_id
5685 AND mmtt.organization_id = p_org_id
5686 AND mmtt.parent_line_id = mmtt.transaction_temp_id
5687 AND mmtt.transaction_quantity > 0
5688 AND mmtt.inventory_item_id = p_itm_id
5689 AND NVL(mmtt.revision,'@@@@') = NVL(p_rev,'@@@@')
5690 AND ( mmtt.content_lpn_id IS NULL
5691 OR
5692 mmtt.content_lpn_id = mmtt.transfer_lpn_id
5693 );
5694
5695
5696 CURSOR c_get_parent_attributes
5697 ( p_temp_id IN NUMBER
5698 ) IS
5699 SELECT mmtt.lpn_id
5700 , mmtt.content_lpn_id
5701 , mmtt.subinventory_code
5702 , mmtt.locator_id
5703 , mmtt.primary_quantity
5704 FROM mtl_material_transactions_temp mmtt
5705 WHERE mmtt.transaction_temp_id = p_temp_id;
5706
5707 parent_rec c_get_parent_attributes%ROWTYPE;
5708
5709 BEGIN
5710 x_return_status := fnd_api.g_ret_sts_success;
5711
5712 fnd_msg_pub.initialize;
5713
5714 IF l_debug = 1 THEN
5715 print_debug
5716 ( 'Entered with parameters: ' || g_newline ||
5717 'p_group_number => ' || to_char(p_group_number) || g_newline ||
5718 'p_item_id => ' || to_char(p_item_id) || g_newline ||
5719 'p_revision => ' || p_revision || g_newline ||
5720 'p_qty => ' || to_char(p_qty) || g_newline ||
5721 'p_primary_uom => ' || p_primary_uom
5722 , l_api_name
5723 );
5724 END IF;
5725
5726 SAVEPOINT process_loose_sp;
5727
5728 OPEN c_get_available_loose_qty
5729 ( g_current_drop_lpn.lpn_id
5730 , g_current_drop_lpn.organization_id
5731 , p_item_id
5732 , p_revision
5733 );
5734 FETCH c_get_available_loose_qty INTO l_available_qty;
5735 CLOSE c_get_available_loose_qty;
5736
5737 IF l_available_qty < p_qty
5738 THEN
5739 IF l_debug = 1 THEN
5740 print_debug
5741 ( 'Not enough loose quantity available: '
5742 || to_char(l_available_qty)
5743 , l_api_name
5744 );
5745 END IF;
5746
5747 fnd_message.set_name('WMS', 'WMS_NOT_ENOUGH_LOOSE_QTY');
5748 fnd_msg_pub.ADD;
5749 RAISE FND_API.G_EXC_ERROR;
5750 ELSE
5751 IF l_debug = 1 THEN
5752 print_debug
5753 ( 'Available loose qty: ' || to_char(l_available_qty)
5754 , l_api_name
5755 );
5756 END IF;
5757 END IF;
5758
5759 l_api_return_status := fnd_api.g_ret_sts_success;
5760 get_temp_list
5761 ( x_temp_tbl => l_temp_tbl
5762 , x_return_status => l_api_return_status
5763 , p_group_num => p_group_number
5764 , p_status => 'PENDING'
5765 );
5766
5767 IF l_api_return_status <> fnd_api.g_ret_sts_success
5768 THEN
5769 IF l_debug = 1 THEN
5770 print_debug ('Error from get_temp_list', l_api_name);
5771 END IF;
5772 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5773 ELSIF NOT (l_temp_tbl.COUNT > 0)
5774 THEN
5775 IF l_debug = 1 THEN
5776 print_debug ('get_temp_list returned no MMTT records', l_api_name);
5777 END IF;
5778 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5779 ELSE
5780 IF l_debug = 1 THEN
5781 print_debug
5782 ( 'MMTT record count from get_temp_list: '
5783 || to_char(l_temp_tbl.COUNT)
5784 , l_api_name
5785 );
5786 END IF;
5787 END IF;
5788
5789 l_remaining_qty := p_qty;
5790
5791 ii := l_temp_tbl.FIRST;
5792 jj := l_temp_tbl.LAST;
5793
5794 kk := 1;
5795
5796 l_transaction_temp_id := l_temp_tbl(ii);
5797
5798 IF l_debug = 1 THEN
5799 print_debug
5800 ( 'ii = ' || to_char(ii) || ', jj = ' || to_char(jj) ||
5801 ', l_remaining_qty: ' || to_char(l_remaining_qty)
5802 , l_api_name
5803 );
5804 END IF;
5805
5806 WHILE ( (ii <= jj)
5807 AND
5808 (l_remaining_qty > 0)
5809 )
5810 LOOP
5811 IF l_debug = 1 THEN
5812 print_debug
5813 ( ' Checking temp ID ' || to_char(l_transaction_temp_id)
5814 , l_api_name
5815 );
5816 END IF;
5817
5818 OPEN c_get_mmtt_qty (l_transaction_temp_id);
5819 FETCH c_get_mmtt_qty INTO l_mmtt_qty;
5820 CLOSE c_get_mmtt_qty;
5821
5822 IF l_debug = 1 THEN
5823 print_debug
5824 ( 'Primary qty is ' || to_char(l_mmtt_qty)
5825 , l_api_name
5826 );
5827 END IF;
5828
5829 IF l_mmtt_qty <= l_remaining_qty
5830 THEN
5831 l_remaining_qty := l_remaining_qty - l_mmtt_qty;
5832
5833 IF l_debug = 1 THEN
5834 print_debug
5835 ( 'Current MMTT qty <= remaining. '
5836 || 'Remaining is now: ' || to_char(l_remaining_qty)
5837 , l_api_name
5838 );
5839 END IF;
5840
5841 l_process_tbl(kk) := l_transaction_temp_id;
5842 kk := kk + 1;
5843
5844 ELSE
5845 l_api_return_status := fnd_api.g_ret_sts_success;
5846 split_mmtt
5847 ( x_new_temp_id => l_new_temp_id
5848 , x_return_status => l_api_return_status
5849 , p_temp_id => l_transaction_temp_id
5850 );
5851
5852 IF l_api_return_status <> fnd_api.g_ret_sts_success
5853 THEN
5854 IF l_debug = 1 THEN
5855 print_debug
5856 ( 'split_mmtt returned status ' || l_api_return_status
5857 , l_api_name
5858 );
5859 END IF;
5860 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5861 END IF;
5862
5863 UPDATE mtl_material_transactions_temp
5864 SET transaction_quantity = DECODE( transaction_uom
5865 , p_primary_uom, l_remaining_qty
5866 , inv_convert.inv_um_convert
5867 ( p_item_id
5868 , NULL
5869 , l_remaining_qty
5870 , p_primary_uom
5871 , transaction_uom
5872 , NULL
5873 , NULL
5874 )
5875 )
5876 , primary_quantity = l_remaining_qty
5877 , reservation_quantity = DECODE( reservation_quantity
5878 , NULL, NULL
5879 , l_remaining_qty
5880 )
5881 WHERE transaction_temp_id = l_transaction_temp_id
5882 RETURNING transaction_quantity INTO l_txn_qty;
5883
5884 IF l_debug = 1 THEN
5885 print_debug
5886 ('Reduced qty for temp ID ' || to_char(l_transaction_temp_id)
5887 || ' to ' || to_char(l_remaining_qty)
5888 , l_api_name
5889 );
5890 END IF;
5891
5892 UPDATE mtl_material_transactions_temp
5893 SET transaction_quantity = transaction_quantity - l_txn_qty
5894 , primary_quantity = primary_quantity - l_remaining_qty
5895 , reservation_quantity = DECODE( reservation_quantity
5896 , NULL, NULL
5897 , reservation_quantity - l_remaining_qty
5898 )
5899 , lpn_id = NULL
5900 , transfer_lpn_id = NULL
5901 , subinventory_code = NULL
5902 , locator_id = NULL
5903 WHERE transaction_temp_id = l_new_temp_id
5904 RETURNING primary_quantity INTO l_pri_qty;
5905
5906 IF l_debug = 1 THEN
5907 print_debug
5908 ('Updated new temp ID ' || to_char(l_new_temp_id) ||
5909 ' with qty : ' || to_char(l_pri_qty)
5910 , l_api_name
5911 );
5912 END IF;
5913
5914 l_process_tbl(kk) := l_transaction_temp_id;
5915 l_remaining_qty := 0;
5916 END IF;
5917
5918 IF ii < jj THEN
5919 ii := l_temp_tbl.NEXT(ii);
5920 l_transaction_temp_id := l_temp_tbl(ii);
5921 ELSE
5922 EXIT;
5923 END IF;
5924
5925 IF l_debug = 1 THEN
5926 print_debug
5927 ( 'Fetched next temp ID: ' || to_char(l_transaction_temp_id)
5928 , l_api_name
5929 );
5930 END IF;
5931 END LOOP;
5932
5933 l_temp_tbl.DELETE;
5934
5935 IF l_remaining_qty > 0
5936 THEN
5937 IF l_debug = 1 THEN
5938 print_debug
5939 ( 'Some qty remaining: ' || to_char(l_remaining_qty)
5940 , l_api_name
5941 );
5942 END IF;
5943 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5944 END IF;
5945
5946 OPEN c_get_parents
5947 ( g_current_drop_lpn.lpn_id
5948 , g_current_drop_lpn.organization_id
5949 , p_item_id
5950 , p_revision
5951 );
5952 FETCH c_get_parents BULK COLLECT INTO l_parent_tbl;
5953 CLOSE c_get_parents;
5954
5955 IF NOT (l_parent_tbl.COUNT > 0)
5956 THEN
5957 IF l_debug = 1 THEN
5958 print_debug ('No parent MMTT records found', l_api_name);
5959 END IF;
5960 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
5961 ELSE
5962 IF l_debug = 1 THEN
5963 print_debug
5964 ( 'MMTT parent record count: '
5965 || to_char(l_parent_tbl.COUNT)
5966 , l_api_name
5967 );
5968 END IF;
5969 END IF;
5970
5971 kk := l_parent_tbl.FIRST;
5972 l_parent_temp_id := l_parent_tbl(kk);
5973
5974 OPEN c_get_parent_attributes (l_parent_temp_id);
5975 FETCH c_get_parent_attributes INTO parent_rec;
5976 CLOSE c_get_parent_attributes;
5977
5978 l_remaining_qty := parent_rec.primary_quantity;
5979
5980 ii := l_process_tbl.FIRST;
5981 jj := l_process_tbl.LAST;
5982
5983 l_transaction_temp_id := l_process_tbl(ii);
5984
5985 IF l_debug = 1 THEN
5986 print_debug
5987 ( 'ii = ' || to_char(ii) || ', jj = ' || to_char(jj) ||
5988 ', l_remaining_qty: ' || to_char(l_remaining_qty)
5989 , l_api_name
5990 );
5991 END IF;
5992
5993 LOOP
5994 IF l_debug = 1 THEN
5995 print_debug
5996 ( 'Updating temp ID ' || to_char(l_transaction_temp_id) ||
5997 ' with parent attr ' || to_char(l_parent_temp_id)
5998 , l_api_name
5999 );
6000 END IF;
6001
6002 UPDATE mtl_material_transactions_temp mmtt
6003 SET lpn_id = NVL(parent_rec.content_lpn_id,parent_rec.lpn_id)
6004 , subinventory_code = parent_rec.subinventory_code
6005 , locator_id = parent_rec.locator_id
6006 WHERE mmtt.transaction_temp_id = l_transaction_temp_id
6007 RETURNING mmtt.primary_quantity
6008 INTO l_mmtt_qty;
6009
6010 IF l_debug = 1 THEN
6011 print_debug
6012 ( ' Updated temp ID ' || to_char(l_transaction_temp_id)
6013 || ', primary qty is ' || to_char(l_mmtt_qty)
6014 , l_api_name
6015 );
6016 END IF;
6017
6018 IF l_mmtt_qty <= l_remaining_qty
6019 THEN
6020 l_remaining_qty := l_remaining_qty - l_mmtt_qty;
6021
6022 IF l_debug = 1 THEN
6023 print_debug
6024 ( 'Current MMTT qty <= remaining. '
6025 || 'Remaining is now: ' || to_char(l_remaining_qty)
6026 , l_api_name
6027 );
6028 END IF;
6029
6030 UPDATE mtl_material_transactions_temp mmtt
6031 SET transaction_quantity = DECODE( transaction_uom
6032 , p_primary_uom, (primary_quantity - l_mmtt_qty)
6033 , inv_convert.inv_um_convert
6034 ( p_item_id
6035 , NULL
6036 , primary_quantity - l_mmtt_qty
6037 , p_primary_uom
6038 , transaction_uom
6039 , NULL
6040 , NULL
6041 )
6042 )
6043 , primary_quantity = primary_quantity - l_mmtt_qty
6044 , reservation_quantity = DECODE( reservation_quantity
6045 , NULL, NULL
6046 , reservation_quantity - l_mmtt_qty
6047 )
6048 WHERE mmtt.transaction_temp_id = l_parent_temp_id;
6049 ELSE
6050 l_api_return_status := fnd_api.g_ret_sts_success;
6051 split_mmtt
6052 ( x_new_temp_id => l_new_temp_id
6053 , x_return_status => l_api_return_status
6054 , p_temp_id => l_transaction_temp_id
6055 );
6056
6057 IF l_api_return_status <> fnd_api.g_ret_sts_success
6058 THEN
6059 IF l_debug = 1 THEN
6060 print_debug
6061 ( 'split_mmtt returned status ' || l_api_return_status
6062 , l_api_name
6063 );
6064 END IF;
6065 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6066 END IF;
6067
6068 UPDATE mtl_material_transactions_temp
6069 SET transaction_quantity = DECODE( transaction_uom
6070 , p_primary_uom, l_remaining_qty
6071 , inv_convert.inv_um_convert
6072 ( p_item_id
6073 , NULL
6074 , l_remaining_qty
6075 , p_primary_uom
6076 , transaction_uom
6077 , NULL
6078 , NULL
6079 )
6080 )
6081 , primary_quantity = l_remaining_qty
6082 , reservation_quantity = DECODE( reservation_quantity
6083 , NULL, NULL
6084 , l_remaining_qty
6085 )
6086 WHERE transaction_temp_id = l_transaction_temp_id
6087 RETURNING transaction_quantity INTO l_txn_qty;
6088
6089 IF l_debug = 1 THEN
6090 print_debug
6091 ('Reduced qty for temp ID ' || to_char(l_transaction_temp_id)
6092 || ' to ' || to_char(l_remaining_qty)
6093 , l_api_name
6094 );
6095 END IF;
6096
6097 UPDATE mtl_material_transactions_temp
6098 SET transaction_quantity = transaction_quantity - l_txn_qty
6099 , primary_quantity = primary_quantity - l_remaining_qty
6100 , reservation_quantity = DECODE( reservation_quantity
6101 , NULL, NULL
6102 , reservation_quantity - l_remaining_qty
6103 )
6104 , lpn_id = NULL
6105 , transfer_lpn_id = NULL
6106 , subinventory_code = NULL
6107 , locator_id = NULL
6108 WHERE transaction_temp_id = l_new_temp_id
6109 RETURNING primary_quantity INTO l_pri_qty;
6110
6111 IF l_debug = 1 THEN
6112 print_debug
6113 ('Updated new temp ID ' || to_char(l_new_temp_id) ||
6114 ' with qty : ' || to_char(l_pri_qty)
6115 , l_api_name
6116 );
6117 END IF;
6118
6119 jj := jj + 1;
6120 l_process_tbl(jj) := l_new_temp_id;
6121
6122 UPDATE mtl_material_transactions_temp mmtt
6123 SET transaction_quantity = 0
6124 , primary_quantity = 0
6125 , reservation_quantity = 0
6126 WHERE mmtt.transaction_temp_id = l_parent_temp_id;
6127
6128 l_remaining_qty := 0;
6129
6130 END IF;
6131
6132 g_current_drop_lpn.current_drop_list(l_transaction_temp_id) := 'LSE_DONE';
6133
6134 IF l_debug = 1 THEN
6135 print_debug
6136 ( ' Done processing temp ID ' || to_char(l_transaction_temp_id)
6137 , l_api_name
6138 );
6139 END IF;
6140
6141 IF ii < jj THEN
6142 ii := l_process_tbl.NEXT(ii);
6143 l_transaction_temp_id := l_process_tbl(ii);
6144
6145 IF l_remaining_qty = 0
6146 THEN
6147 kk := l_parent_tbl.NEXT(kk);
6148 IF kk IS NOT NULL
6149 THEN
6150 l_parent_temp_id := l_parent_tbl(kk);
6151 ELSE
6152 IF l_debug = 1 THEN
6153 print_debug
6154 ( 'No parent records remaining, and not all child records processed.'
6155 , l_api_name
6156 );
6157 END IF;
6158 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6159 END IF;
6160
6161 OPEN c_get_parent_attributes (l_parent_temp_id);
6162 FETCH c_get_parent_attributes INTO parent_rec;
6163 CLOSE c_get_parent_attributes;
6164
6165 l_remaining_qty := parent_rec.primary_quantity;
6166 END IF;
6167
6168 ELSE
6169 EXIT;
6170 END IF;
6171
6172 IF l_debug = 1 THEN
6173 print_debug
6174 ( 'Fetched next temp ID: ' || to_char(l_transaction_temp_id)
6175 , l_api_name
6176 );
6177 END IF;
6178 END LOOP;
6179
6180 BEGIN
6181 SELECT 'x'
6182 INTO l_dummy
6183 FROM dual
6184 WHERE EXISTS
6185 ( SELECT 'x'
6186 FROM mtl_material_transactions_temp mmtt
6187 WHERE mmtt.organization_id = g_current_drop_lpn.organization_id
6188 AND mmtt.transfer_lpn_id = g_current_drop_lpn.lpn_id
6189 AND mmtt.parent_line_id = mmtt.transaction_temp_id
6190 AND mmtt.transaction_quantity > 0
6191 AND mmtt.inventory_item_id = p_item_id
6192 AND NVL(mmtt.revision,'@@@@') = NVL(p_revision,'@@@@')
6193 AND ( mmtt.content_lpn_id IS NULL
6194 OR
6195 mmtt.content_lpn_id = mmtt.transfer_lpn_id
6196 )
6197 );
6198 l_loose_qty_exists := 'Y';
6199 EXCEPTION
6200 WHEN NO_DATA_FOUND THEN
6201 l_loose_qty_exists := 'N';
6202 END;
6203
6204 x_loose_qty_exists := l_loose_qty_exists;
6205
6206 l_process_tbl.DELETE;
6207 l_parent_tbl.DELETE;
6208
6209 EXCEPTION
6210 WHEN fnd_api.g_exc_error THEN
6211 ROLLBACK to process_loose_sp;
6212
6213 x_return_status := fnd_api.g_ret_sts_error;
6214
6215 fnd_msg_pub.count_and_get
6216 ( p_count => l_msg_count
6217 , p_data => l_msg_data
6218 , p_encoded => fnd_api.g_false
6219 );
6220
6221 IF l_debug = 1 THEN
6222 print_debug (l_msg_data, l_api_name);
6223 END IF;
6224
6225 WHEN OTHERS THEN
6226 ROLLBACK to process_loose_sp;
6227
6228 x_return_status := fnd_api.g_ret_sts_unexp_error;
6229
6230 IF l_debug = 1 THEN
6231 print_debug ('Other error: ' || sqlerrm, l_api_name);
6232 END IF;
6233
6234 END process_loose_qty;
6235
6236
6237
6238 PROCEDURE process_serial
6239 ( x_loose_qty_exists OUT NOCOPY VARCHAR2
6240 , x_return_status OUT NOCOPY VARCHAR2
6241 , p_organization_id IN NUMBER
6242 , p_transfer_lpn_id IN NUMBER
6243 , p_lpn IN VARCHAR2
6244 , p_item_id IN NUMBER
6245 , p_revision IN VARCHAR2
6246 , p_lot_number IN VARCHAR2
6247 , p_serial_number IN VARCHAR2
6248 , p_group_number IN NUMBER
6249 ) IS
6250
6251 l_api_name VARCHAR2(30) := 'process_serial';
6252 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
6253
6254 l_api_return_status VARCHAR2(1);
6255 l_msg_count NUMBER;
6256 l_msg_data VARCHAR2(2000);
6257
6258 l_inner_lpn_id NUMBER := NULL;
6259 l_transaction_temp_id NUMBER;
6260 l_orig_temp_id NUMBER;
6261 l_parent_line_id NUMBER;
6262 l_txn_header_id NUMBER;
6263 l_parent_found BOOLEAN;
6264 l_srl_temp_id NUMBER;
6265 l_primary_qty NUMBER;
6266 l_serial_count NUMBER;
6267 l_temp_id NUMBER;
6268 l_temp_found BOOLEAN;
6269
6270 l_old_mtlt_rowid ROWID;
6271 l_mtlt_rec mtl_transaction_lots_temp%ROWTYPE;
6272
6273 ii NUMBER;
6274 jj NUMBER;
6275
6276 l_dummy VARCHAR2(1) := NULL;
6277 l_loose_qty_exists VARCHAR2(1) := NULL;
6278
6279
6280 CURSOR c_get_inner_lpn_id
6281 ( p_inner_lpn IN VARCHAR2
6282 , p_outer_lpn_id IN NUMBER
6283 , p_org_id IN NUMBER
6284 ) IS
6285 SELECT wlpn.lpn_id
6286 FROM wms_license_plate_numbers wlpn
6287 , mtl_material_transactions_temp mmtt
6288 WHERE wlpn.license_plate_number = p_inner_lpn
6289 AND wlpn.organization_id = p_org_id
6290 AND mmtt.transfer_lpn_id = p_outer_lpn_id
6291 AND mmtt.organization_id = p_org_id
6292 AND mmtt.parent_line_id = mmtt.transaction_temp_id
6293 AND mmtt.content_lpn_id = wlpn.lpn_id;
6294
6295
6296 CURSOR c_get_loose_msnt
6297 ( p_xfer_lpn_id IN NUMBER
6298 , p_org_id IN NUMBER
6299 , p_serial_num IN VARCHAR2
6300 ) IS
6301 SELECT msnt.rowid
6302 , mmtt.transaction_temp_id
6303 FROM mtl_material_transactions_temp mmtt
6304 , mtl_serial_numbers_temp msnt
6305 WHERE mmtt.organization_id = p_org_id
6306 AND mmtt.transfer_lpn_id = p_xfer_lpn_id
6307 AND mmtt.transaction_temp_id = mmtt.parent_line_id
6308 AND ( mmtt.content_lpn_id IS NULL
6309 OR
6310 mmtt.content_lpn_id = mmtt.transfer_lpn_id
6311 )
6312 AND mmtt.transaction_temp_id = msnt.transaction_temp_id
6313 AND msnt.fm_serial_number = p_serial_num;
6314
6315 msnt_rec c_get_loose_msnt%ROWTYPE;
6316
6317 CURSOR c_get_lpn_msnt
6318 ( p_xfer_lpn_id IN NUMBER
6319 , p_org_id IN NUMBER
6320 , p_serial_num IN VARCHAR2
6321 , p_lpn_id IN NUMBER
6322 ) IS
6323 SELECT msnt.rowid
6324 , mmtt.transaction_temp_id
6325 FROM mtl_material_transactions_temp mmtt
6326 , mtl_serial_numbers_temp msnt
6327 WHERE mmtt.organization_id = p_org_id
6328 AND mmtt.transfer_lpn_id = p_xfer_lpn_id
6329 AND mmtt.transaction_temp_id = mmtt.parent_line_id
6330 AND mmtt.content_lpn_id = p_lpn_id
6331 AND mmtt.transaction_temp_id = msnt.transaction_temp_id
6332 AND msnt.fm_serial_number = p_serial_num;
6333
6334
6335 CURSOR c_get_lot_msnt
6336 ( p_xfer_lpn_id IN NUMBER
6337 , p_org_id IN NUMBER
6338 , p_lot_num IN VARCHAR2
6339 , p_serial_num IN VARCHAR2
6340 , p_lpn_id IN NUMBER
6341 ) IS
6342 SELECT msnt.rowid
6343 , mmtt.transaction_temp_id transaction_temp_id
6344 FROM mtl_material_transactions_temp mmtt
6345 , mtl_transaction_lots_temp mtlt
6346 , mtl_serial_numbers_temp msnt
6347 WHERE mmtt.organization_id = p_org_id
6348 AND mmtt.transfer_lpn_id = p_xfer_lpn_id
6349 AND mmtt.transaction_temp_id = mmtt.parent_line_id
6350 AND NVL(mmtt.content_lpn_id,0) = NVL(p_lpn_id,0)
6351 AND mmtt.transaction_temp_id = mtlt.transaction_temp_id
6352 AND mtlt.lot_number = p_lot_num
6353 AND msnt.transaction_temp_id = mtlt.serial_transaction_temp_id
6354 AND msnt.fm_serial_number = p_serial_num;
6355
6356 lot_msnt_rec c_get_lot_msnt%ROWTYPE;
6357
6358
6359 CURSOR c_get_parent
6360 ( p_temp_id IN NUMBER
6361 ) IS
6362 SELECT parent_line_id
6363 FROM mtl_material_transactions_temp mmtt
6364 WHERE mmtt.transaction_temp_id = p_temp_id;
6365
6366
6367 CURSOR c_get_parent_attributes
6368 ( p_temp_id IN NUMBER
6369 ) IS
6370 SELECT mmtt.lpn_id
6371 , mmtt.content_lpn_id
6372 , mmtt.subinventory_code
6373 , mmtt.locator_id
6374 FROM mtl_material_transactions_temp mmtt
6375 WHERE mmtt.transaction_temp_id = p_temp_id;
6376
6377 parent_rec c_get_parent_attributes%ROWTYPE;
6378
6379
6380 CURSOR c_get_lot_srl_count
6381 ( p_temp_id IN NUMBER
6382 , p_lot_num IN VARCHAR2
6383 ) IS
6384 SELECT mtlt.primary_quantity
6385 , COUNT(msnt.fm_serial_number) srl_count
6386 FROM mtl_material_transactions_temp mmtt
6387 , mtl_transaction_lots_temp mtlt
6388 , mtl_serial_numbers_temp msnt
6389 WHERE mmtt.transaction_temp_id = p_temp_id
6390 AND mmtt.transaction_temp_id = mtlt.transaction_temp_id
6391 AND mtlt.lot_number = p_lot_num
6392 AND msnt.transaction_temp_id (+) = mtlt.serial_transaction_temp_id
6393 GROUP BY mtlt.primary_quantity;
6394
6395
6396 CURSOR c_get_serial_count
6397 ( p_temp_id IN NUMBER
6398 ) IS
6399 SELECT mmtt.primary_quantity
6400 , COUNT(msnt.fm_serial_number) srl_count
6401 FROM mtl_material_transactions_temp mmtt
6402 , mtl_serial_numbers_temp msnt
6403 WHERE mmtt.transaction_temp_id = p_temp_id
6404 AND msnt.transaction_temp_id (+) = mmtt.transaction_temp_id
6405 GROUP BY mmtt.primary_quantity;
6406
6407
6408 BEGIN
6409 x_return_status := fnd_api.g_ret_sts_success;
6410
6411 fnd_msg_pub.initialize;
6412
6413 IF l_debug = 1 THEN
6414 print_debug
6415 ( 'Entered with parameters: ' || g_newline ||
6416 'p_organization_id => ' || to_char(p_organization_id) || g_newline ||
6417 'p_transfer_lpn_id => ' || to_char(p_transfer_lpn_id) || g_newline ||
6418 'p_lpn => ' || p_lpn || g_newline ||
6419 'p_item_id => ' || to_char(p_item_id) || g_newline ||
6420 'p_revision => ' || p_revision || g_newline ||
6421 'p_lot_number => ' || p_lot_number || g_newline ||
6422 'p_serial_number => ' || p_serial_number || g_newline ||
6423 'p_group_number => ' || to_char(p_group_number)
6424 , l_api_name
6425 );
6426 END IF;
6427
6428 SAVEPOINT process_serial_sp;
6429
6430 --
6431 -- Validate passed in Org and LPN
6432 --
6433 IF p_organization_id <> g_current_drop_lpn.organization_id
6434 OR
6435 p_transfer_lpn_id <> g_current_drop_lpn.lpn_id
6436 THEN
6437 IF l_debug = 1 THEN
6438 print_debug
6439 ( 'Passed in org or LPN did not match cached info: '
6440 || g_newline || 'p_organization_id: ' || to_char(p_organization_id)
6441 || g_newline || 'p_transfer_lpn_id: ' || to_char(p_transfer_lpn_id)
6442 || g_newline || 'Cached Org ID: ' || to_char(g_current_drop_lpn.organization_id)
6443 || g_newline || 'Cached LPN ID: ' || to_char(g_current_drop_lpn.lpn_id)
6444 , l_api_name
6445 );
6446 END IF;
6447 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6448 END IF;
6449
6450 IF p_lpn IS NOT NULL
6451 THEN
6452 OPEN c_get_inner_lpn_id
6453 ( p_lpn
6454 , g_current_drop_lpn.lpn_id
6455 , g_current_drop_lpn.organization_id
6456 );
6457 FETCH c_get_inner_lpn_id INTO l_inner_lpn_id;
6458
6459 IF c_get_inner_lpn_id%NOTFOUND THEN
6460 CLOSE c_get_inner_lpn_id;
6461 IF l_debug = 1 THEN
6462 print_debug
6463 ( 'Cannot find nested LPN ' || p_lpn ||
6464 ' in outer LPN ID ' || to_char(g_current_drop_lpn.lpn_id)
6465 , l_api_name
6466 );
6467 END IF;
6468
6469 fnd_message.set_name('WMS', 'WMS_LPN_NOT_IN_OUTER');
6470 fnd_msg_pub.ADD;
6471 RAISE FND_API.G_EXC_ERROR;
6472 ELSE
6473 IF l_debug = 1 THEN
6474 print_debug
6475 ( 'Found scanned LPN ' || p_lpn ||
6476 '. LPN ID is ' || to_char(l_inner_lpn_id)
6477 , l_api_name
6478 );
6479 END IF;
6480 END IF;
6481 END IF;
6482
6483 IF p_lot_number IS NOT NULL
6484 THEN
6485 OPEN c_get_lot_msnt
6486 ( p_transfer_lpn_id
6487 , p_organization_id
6488 , p_lot_number
6489 , p_serial_number
6490 , l_inner_lpn_id
6491 );
6492 FETCH c_get_lot_msnt INTO lot_msnt_rec;
6493
6494 IF c_get_lot_msnt%NOTFOUND THEN
6495 IF l_debug = 1 THEN
6496 print_debug
6497 ( 'Serial number not found'
6498 , l_api_name
6499 );
6500 END IF;
6501 CLOSE c_get_lot_msnt;
6502 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SER');
6503 fnd_msg_pub.ADD;
6504 RAISE FND_API.G_EXC_ERROR;
6505 END IF;
6506 IF c_get_lot_msnt%ISOPEN THEN
6507 CLOSE c_get_lot_msnt;
6508 END IF;
6509 ELSE
6510 IF p_lpn IS NULL
6511 THEN
6512 OPEN c_get_loose_msnt
6513 ( p_transfer_lpn_id
6514 , p_organization_id
6515 , p_serial_number
6516 );
6517 FETCH c_get_loose_msnt INTO msnt_rec;
6518
6519 IF c_get_loose_msnt%NOTFOUND THEN
6520 IF l_debug = 1 THEN
6521 print_debug
6522 ( 'Serial number not found'
6523 , l_api_name
6524 );
6525 END IF;
6526 CLOSE c_get_loose_msnt;
6527 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SER');
6528 fnd_msg_pub.ADD;
6529 RAISE FND_API.G_EXC_ERROR;
6530 END IF;
6531 IF c_get_loose_msnt%ISOPEN THEN
6532 CLOSE c_get_loose_msnt;
6533 END IF;
6534 ELSE
6535 OPEN c_get_lpn_msnt
6536 ( p_transfer_lpn_id
6537 , p_organization_id
6538 , p_serial_number
6539 , l_inner_lpn_id
6540 );
6541 FETCH c_get_lpn_msnt INTO msnt_rec;
6542
6543 IF c_get_lpn_msnt%NOTFOUND THEN
6544 IF l_debug = 1 THEN
6545 print_debug
6546 ( 'Serial number not found'
6547 , l_api_name
6548 );
6549 END IF;
6550 CLOSE c_get_lpn_msnt;
6551 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_SER');
6552 fnd_msg_pub.ADD;
6553 RAISE FND_API.G_EXC_ERROR;
6554 END IF;
6555 IF c_get_lpn_msnt%ISOPEN THEN
6556 CLOSE c_get_lpn_msnt;
6557 END IF;
6558 END IF;
6559 END IF;
6560
6561 IF l_debug = 1 THEN
6562 print_debug( 'Serial number found', l_api_name);
6563 END IF;
6564
6565 IF (NOT (g_cur_pend_temp.COUNT > 0)) THEN
6566 l_api_return_status := fnd_api.g_ret_sts_success;
6567
6568 IF p_lpn IS NOT NULL
6569 THEN
6570 get_temp_list
6571 ( x_temp_tbl => g_cur_pend_temp
6572 , x_return_status => l_api_return_status
6573 , p_group_num => p_group_number
6574 , p_status => 'LPN_DONE'
6575 );
6576 ELSE
6577 get_temp_list
6578 ( x_temp_tbl => g_cur_pend_temp
6579 , x_return_status => l_api_return_status
6580 , p_group_num => p_group_number
6581 , p_status => 'PENDING'
6582 );
6583 END IF;
6584
6585 IF l_api_return_status <> fnd_api.g_ret_sts_success
6586 THEN
6587 IF l_debug = 1 THEN
6588 print_debug ('Error from get_temp_list', l_api_name);
6589 END IF;
6590 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6591 END IF;
6592 END IF;
6593
6594 IF (NOT (g_cur_pend_temp.COUNT > 0)) THEN
6595 IF l_debug = 1 THEN
6596 print_debug ('No temp IDs found', l_api_name);
6597 END IF;
6598 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6599 END IF;
6600
6601 ii := g_cur_pend_temp.FIRST;
6602 jj := g_cur_pend_temp.LAST;
6603
6604 IF l_debug = 1 THEN
6605 print_debug
6606 ( 'ii = ' || to_char(ii) || ', jj = ' || to_char(jj)
6607 , l_api_name
6608 );
6609 END IF;
6610
6611 l_parent_found := FALSE;
6612 l_transaction_temp_id := g_cur_pend_temp(ii);
6613 WHILE ( (ii <= jj)
6614 AND
6615 (NOT l_parent_found)
6616 )
6617 LOOP
6618 OPEN c_get_parent(l_transaction_temp_id);
6619 FETCH c_get_parent INTO l_parent_line_id;
6620 CLOSE c_get_parent;
6621
6622 IF l_debug = 1 THEN
6623 print_debug
6624 ( 'Temp ID: ' || to_char(l_transaction_temp_id) ||
6625 ', parent: ' || to_char(l_parent_line_id)
6626 , l_api_name
6627 );
6628 END IF;
6629
6630 IF p_lot_number IS NOT NULL
6631 THEN
6632 IF l_parent_line_id = lot_msnt_rec.transaction_temp_id
6633 THEN
6634 l_parent_found := TRUE;
6635 EXIT;
6636 END IF;
6637 ELSE
6638 IF l_parent_line_id = msnt_rec.transaction_temp_id
6639 THEN
6640 l_parent_found := TRUE;
6641 EXIT;
6642 END IF;
6643 END IF;
6644
6645 IF NOT l_parent_found THEN
6646 IF ii < jj THEN
6647 ii := g_cur_pend_temp.NEXT(ii);
6648 l_transaction_temp_id := g_cur_pend_temp(ii);
6649 ELSE
6650 EXIT;
6651 END IF;
6652 END IF;
6653 END LOOP;
6654
6655 IF NOT l_parent_found THEN
6656 l_orig_temp_id := g_cur_pend_temp(g_cur_pend_temp.FIRST);
6657
6658 l_api_return_status := fnd_api.g_ret_sts_success;
6659 split_mmtt
6660 ( x_new_temp_id => l_transaction_temp_id
6661 , x_return_status => l_api_return_status
6662 , p_temp_id => l_orig_temp_id
6663 );
6664
6665 IF l_api_return_status <> fnd_api.g_ret_sts_success
6666 THEN
6667 IF l_debug = 1 THEN
6668 print_debug ('Error from split_mmtt', l_api_name);
6669 END IF;
6670 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6671 END IF;
6672
6673 UPDATE mtl_material_transactions_temp
6674 SET transaction_quantity = transaction_quantity - 1
6675 , primary_quantity = primary_quantity - 1
6676 , reservation_quantity = DECODE( reservation_quantity
6677 , NULL, NULL
6678 , reservation_quantity - 1
6679 )
6680 WHERE transaction_temp_id = l_orig_temp_id;
6681
6682 IF l_debug = 1 THEN
6683 print_debug
6684 ('Reduced qty by 1 for temp ID ' || to_char(l_orig_temp_id)
6685 , l_api_name
6686 );
6687 END IF;
6688
6689 IF p_lot_number IS NOT NULL
6690 THEN
6691 BEGIN
6692 SELECT mtlt.rowid
6693 INTO l_old_mtlt_rowid
6694 FROM mtl_transaction_lots_temp mtlt
6695 WHERE mtlt.transaction_temp_id = l_orig_temp_id
6696 AND mtlt.lot_number = p_lot_number
6697 AND rownum < 2;
6698
6699 IF l_debug = 1 THEN
6700 print_debug ('Found rowid for old MTLT record', l_api_name);
6701 END IF;
6702
6703 UPDATE mtl_transaction_lots_temp
6704 SET transaction_quantity = transaction_quantity - 1
6705 , primary_quantity = primary_quantity - 1
6706 WHERE rowid = l_old_mtlt_rowid;
6707
6708 IF l_debug = 1 AND SQL%FOUND
6709 THEN
6710 print_debug ('Reduced qty by 1 for old MTLT record', l_api_name);
6711 END IF;
6712
6713 OPEN c_get_parent_attributes (lot_msnt_rec.transaction_temp_id);
6714 FETCH c_get_parent_attributes INTO parent_rec;
6715 CLOSE c_get_parent_attributes;
6716
6717 UPDATE mtl_material_transactions_temp
6718 SET transaction_quantity = 1
6719 , primary_quantity = 1
6720 , reservation_quantity = DECODE( reservation_quantity
6721 , NULL, NULL
6722 , 1
6723 )
6724 , parent_line_id = lot_msnt_rec.transaction_temp_id
6725 , subinventory_code = parent_rec.subinventory_code
6726 , locator_id = parent_rec.locator_id
6727 , lpn_id = NVL( l_inner_lpn_id
6728 , NVL( parent_rec.content_lpn_id
6729 , parent_rec.lpn_id
6730 )
6731 )
6732 WHERE transaction_temp_id = l_transaction_temp_id;
6733
6734 IF l_debug = 1 AND SQL%FOUND
6735 THEN
6736 print_debug
6737 ('Updated new temp ID ' || to_char(l_transaction_temp_id) ||
6738 ' with qty 1, sub ' || parent_rec.subinventory_code ||
6739 ', locator ID: ' || to_char(parent_rec.locator_id) ||
6740 ', LPN ID: ' || to_char( NVL( l_inner_lpn_id
6741 , NVL( parent_rec.content_lpn_id
6742 , parent_rec.lpn_id
6743 )
6744 )
6745 ) ||
6746 ', parent line ID: ' || to_char(lot_msnt_rec.transaction_temp_id)
6747 , l_api_name
6748 );
6749 END IF;
6750
6751 SELECT *
6752 INTO l_mtlt_rec
6753 FROM mtl_transaction_lots_temp
6754 WHERE rowid = l_old_mtlt_rowid;
6755
6756 INSERT INTO mtl_transaction_lots_temp
6757 ( TRANSACTION_TEMP_ID
6758 , LAST_UPDATE_DATE
6759 , LAST_UPDATED_BY
6760 , CREATION_DATE
6761 , CREATED_BY
6762 , LAST_UPDATE_LOGIN
6763 , REQUEST_ID
6764 , PROGRAM_APPLICATION_ID
6765 , PROGRAM_ID
6766 , PROGRAM_UPDATE_DATE
6767 , TRANSACTION_QUANTITY
6768 , PRIMARY_QUANTITY
6769 , LOT_NUMBER
6770 , LOT_EXPIRATION_DATE
6771 , ERROR_CODE
6772 , SERIAL_TRANSACTION_TEMP_ID
6773 , GROUP_HEADER_ID
6774 , PUT_AWAY_RULE_ID
6775 , PICK_RULE_ID
6776 , DESCRIPTION
6777 , VENDOR_NAME
6778 , SUPPLIER_LOT_NUMBER
6779 , ORIGINATION_DATE
6780 , DATE_CODE
6781 , GRADE_CODE
6782 , CHANGE_DATE
6783 , MATURITY_DATE
6784 , STATUS_ID
6785 , RETEST_DATE
6786 , AGE
6787 , ITEM_SIZE
6788 , COLOR
6789 , VOLUME
6790 , VOLUME_UOM
6791 , PLACE_OF_ORIGIN
6792 , BEST_BY_DATE
6793 , LENGTH
6794 , LENGTH_UOM
6795 , RECYCLED_CONTENT
6796 , THICKNESS
6797 , THICKNESS_UOM
6798 , WIDTH
6799 , WIDTH_UOM
6800 , CURL_WRINKLE_FOLD
6801 , LOT_ATTRIBUTE_CATEGORY
6802 , C_ATTRIBUTE1
6803 , C_ATTRIBUTE2
6804 , C_ATTRIBUTE3
6805 , C_ATTRIBUTE4
6806 , C_ATTRIBUTE5
6807 , C_ATTRIBUTE6
6808 , C_ATTRIBUTE7
6809 , C_ATTRIBUTE8
6810 , C_ATTRIBUTE9
6811 , C_ATTRIBUTE10
6812 , C_ATTRIBUTE11
6813 , C_ATTRIBUTE12
6814 , C_ATTRIBUTE13
6815 , C_ATTRIBUTE14
6816 , C_ATTRIBUTE15
6817 , C_ATTRIBUTE16
6818 , C_ATTRIBUTE17
6819 , C_ATTRIBUTE18
6820 , C_ATTRIBUTE19
6821 , C_ATTRIBUTE20
6822 , D_ATTRIBUTE1
6823 , D_ATTRIBUTE2
6824 , D_ATTRIBUTE3
6825 , D_ATTRIBUTE4
6826 , D_ATTRIBUTE5
6827 , D_ATTRIBUTE6
6828 , D_ATTRIBUTE7
6829 , D_ATTRIBUTE8
6830 , D_ATTRIBUTE9
6831 , D_ATTRIBUTE10
6832 , N_ATTRIBUTE1
6833 , N_ATTRIBUTE2
6834 , N_ATTRIBUTE3
6835 , N_ATTRIBUTE4
6836 , N_ATTRIBUTE5
6837 , N_ATTRIBUTE6
6838 , N_ATTRIBUTE7
6839 , N_ATTRIBUTE8
6840 , N_ATTRIBUTE9
6841 , N_ATTRIBUTE10
6842 , VENDOR_ID
6843 , TERRITORY_CODE
6844 , SUBLOT_NUM
6845 , SECONDARY_QUANTITY
6846 , SECONDARY_UNIT_OF_MEASURE
6847 , QC_GRADE
6848 , REASON_CODE
6849 , PRODUCT_CODE
6850 , PRODUCT_TRANSACTION_ID
6851 , ATTRIBUTE_CATEGORY
6852 , ATTRIBUTE1
6853 , ATTRIBUTE2
6854 , ATTRIBUTE3
6855 , ATTRIBUTE4
6856 , ATTRIBUTE5
6857 , ATTRIBUTE6
6858 , ATTRIBUTE7
6859 , ATTRIBUTE8
6860 , ATTRIBUTE9
6861 , ATTRIBUTE10
6862 , ATTRIBUTE11
6863 , ATTRIBUTE12
6864 , ATTRIBUTE13
6865 , ATTRIBUTE14
6866 , ATTRIBUTE15
6867 )
6868 VALUES
6869 ( l_transaction_temp_id
6870 , l_mtlt_rec.LAST_UPDATE_DATE
6871 , l_mtlt_rec.LAST_UPDATED_BY
6872 , l_mtlt_rec.CREATION_DATE
6873 , l_mtlt_rec.CREATED_BY
6874 , l_mtlt_rec.LAST_UPDATE_LOGIN
6875 , l_mtlt_rec.REQUEST_ID
6876 , l_mtlt_rec.PROGRAM_APPLICATION_ID
6877 , l_mtlt_rec.PROGRAM_ID
6878 , l_mtlt_rec.PROGRAM_UPDATE_DATE
6879 , 1
6880 , 1
6881 , l_mtlt_rec.LOT_NUMBER
6882 , l_mtlt_rec.LOT_EXPIRATION_DATE
6883 , l_mtlt_rec.ERROR_CODE
6884 , l_mtlt_rec.SERIAL_TRANSACTION_TEMP_ID
6885 , l_mtlt_rec.GROUP_HEADER_ID
6886 , l_mtlt_rec.PUT_AWAY_RULE_ID
6887 , l_mtlt_rec.PICK_RULE_ID
6888 , l_mtlt_rec.DESCRIPTION
6889 , l_mtlt_rec.VENDOR_NAME
6890 , l_mtlt_rec.SUPPLIER_LOT_NUMBER
6891 , l_mtlt_rec.ORIGINATION_DATE
6892 , l_mtlt_rec.DATE_CODE
6893 , l_mtlt_rec.GRADE_CODE
6894 , l_mtlt_rec.CHANGE_DATE
6895 , l_mtlt_rec.MATURITY_DATE
6896 , l_mtlt_rec.STATUS_ID
6897 , l_mtlt_rec.RETEST_DATE
6898 , l_mtlt_rec.AGE
6899 , l_mtlt_rec.ITEM_SIZE
6900 , l_mtlt_rec.COLOR
6901 , l_mtlt_rec.VOLUME
6902 , l_mtlt_rec.VOLUME_UOM
6903 , l_mtlt_rec.PLACE_OF_ORIGIN
6904 , l_mtlt_rec.BEST_BY_DATE
6905 , l_mtlt_rec.LENGTH
6906 , l_mtlt_rec.LENGTH_UOM
6907 , l_mtlt_rec.RECYCLED_CONTENT
6908 , l_mtlt_rec.THICKNESS
6909 , l_mtlt_rec.THICKNESS_UOM
6910 , l_mtlt_rec.WIDTH
6911 , l_mtlt_rec.WIDTH_UOM
6912 , l_mtlt_rec.CURL_WRINKLE_FOLD
6913 , l_mtlt_rec.LOT_ATTRIBUTE_CATEGORY
6914 , l_mtlt_rec.C_ATTRIBUTE1
6915 , l_mtlt_rec.C_ATTRIBUTE2
6916 , l_mtlt_rec.C_ATTRIBUTE3
6917 , l_mtlt_rec.C_ATTRIBUTE4
6918 , l_mtlt_rec.C_ATTRIBUTE5
6919 , l_mtlt_rec.C_ATTRIBUTE6
6920 , l_mtlt_rec.C_ATTRIBUTE7
6921 , l_mtlt_rec.C_ATTRIBUTE8
6922 , l_mtlt_rec.C_ATTRIBUTE9
6923 , l_mtlt_rec.C_ATTRIBUTE10
6924 , l_mtlt_rec.C_ATTRIBUTE11
6925 , l_mtlt_rec.C_ATTRIBUTE12
6926 , l_mtlt_rec.C_ATTRIBUTE13
6927 , l_mtlt_rec.C_ATTRIBUTE14
6928 , l_mtlt_rec.C_ATTRIBUTE15
6929 , l_mtlt_rec.C_ATTRIBUTE16
6930 , l_mtlt_rec.C_ATTRIBUTE17
6931 , l_mtlt_rec.C_ATTRIBUTE18
6932 , l_mtlt_rec.C_ATTRIBUTE19
6933 , l_mtlt_rec.C_ATTRIBUTE20
6934 , l_mtlt_rec.D_ATTRIBUTE1
6935 , l_mtlt_rec.D_ATTRIBUTE2
6936 , l_mtlt_rec.D_ATTRIBUTE3
6937 , l_mtlt_rec.D_ATTRIBUTE4
6938 , l_mtlt_rec.D_ATTRIBUTE5
6939 , l_mtlt_rec.D_ATTRIBUTE6
6940 , l_mtlt_rec.D_ATTRIBUTE7
6941 , l_mtlt_rec.D_ATTRIBUTE8
6942 , l_mtlt_rec.D_ATTRIBUTE9
6943 , l_mtlt_rec.D_ATTRIBUTE10
6944 , l_mtlt_rec.N_ATTRIBUTE1
6945 , l_mtlt_rec.N_ATTRIBUTE2
6946 , l_mtlt_rec.N_ATTRIBUTE3
6947 , l_mtlt_rec.N_ATTRIBUTE4
6948 , l_mtlt_rec.N_ATTRIBUTE5
6949 , l_mtlt_rec.N_ATTRIBUTE6
6950 , l_mtlt_rec.N_ATTRIBUTE7
6951 , l_mtlt_rec.N_ATTRIBUTE8
6952 , l_mtlt_rec.N_ATTRIBUTE9
6953 , l_mtlt_rec.N_ATTRIBUTE10
6954 , l_mtlt_rec.VENDOR_ID
6955 , l_mtlt_rec.TERRITORY_CODE
6956 , l_mtlt_rec.SUBLOT_NUM
6957 , l_mtlt_rec.SECONDARY_QUANTITY
6958 , l_mtlt_rec.SECONDARY_UNIT_OF_MEASURE
6959 , l_mtlt_rec.QC_GRADE
6960 , l_mtlt_rec.REASON_CODE
6961 , l_mtlt_rec.PRODUCT_CODE
6962 , l_mtlt_rec.PRODUCT_TRANSACTION_ID
6963 , l_mtlt_rec.ATTRIBUTE_CATEGORY
6964 , l_mtlt_rec.ATTRIBUTE1
6965 , l_mtlt_rec.ATTRIBUTE2
6966 , l_mtlt_rec.ATTRIBUTE3
6967 , l_mtlt_rec.ATTRIBUTE4
6968 , l_mtlt_rec.ATTRIBUTE5
6969 , l_mtlt_rec.ATTRIBUTE6
6970 , l_mtlt_rec.ATTRIBUTE7
6971 , l_mtlt_rec.ATTRIBUTE8
6972 , l_mtlt_rec.ATTRIBUTE9
6973 , l_mtlt_rec.ATTRIBUTE10
6974 , l_mtlt_rec.ATTRIBUTE11
6975 , l_mtlt_rec.ATTRIBUTE12
6976 , l_mtlt_rec.ATTRIBUTE13
6977 , l_mtlt_rec.ATTRIBUTE14
6978 , l_mtlt_rec.ATTRIBUTE15
6979 );
6980
6981 IF l_debug = 1 AND SQL%FOUND
6982 THEN
6983 print_debug ('Inserted new MTLT', l_api_name);
6984 END IF;
6985
6986 EXCEPTION
6987 WHEN OTHERS THEN
6988 IF l_debug = 1 THEN
6989 print_debug
6990 ( 'Exception processing MTLT records: ' || sqlerrm
6991 , l_api_name
6992 );
6993 END IF;
6994 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
6995 END;
6996 ELSE
6997 --
6998 -- Not lot controlled
6999 --
7000 OPEN c_get_parent_attributes (msnt_rec.transaction_temp_id);
7001 FETCH c_get_parent_attributes INTO parent_rec;
7002 CLOSE c_get_parent_attributes;
7003
7004 UPDATE mtl_material_transactions_temp
7005 SET transaction_quantity = 1
7006 , primary_quantity = 1
7007 , reservation_quantity = DECODE( reservation_quantity
7008 , NULL, NULL
7009 , 1
7010 )
7011 , parent_line_id = msnt_rec.transaction_temp_id
7012 , subinventory_code = parent_rec.subinventory_code
7013 , locator_id = parent_rec.locator_id
7014 , lpn_id = NVL( l_inner_lpn_id
7015 , NVL( parent_rec.content_lpn_id
7016 , parent_rec.lpn_id
7017 )
7018 )
7019 WHERE transaction_temp_id = l_transaction_temp_id;
7020
7021 IF l_debug = 1 THEN
7022 print_debug
7023 ('Updated new temp ID ' || to_char(l_transaction_temp_id) ||
7024 ' with qty 1, sub ' || parent_rec.subinventory_code ||
7025 ', locator ID: ' || to_char(parent_rec.locator_id) ||
7026 ', LPN ID: ' || to_char( NVL( l_inner_lpn_id
7027 , NVL( parent_rec.content_lpn_id
7028 , parent_rec.lpn_id
7029 )
7030 )
7031 ) ||
7032 ', parent line ID: ' || to_char(msnt_rec.transaction_temp_id)
7033 , l_api_name
7034 );
7035 END IF;
7036 END IF; -- end if lot controlled
7037 ELSE
7038 IF p_lot_number IS NULL
7039 AND
7040 p_lpn IS NULL
7041 THEN
7042 OPEN c_get_parent_attributes (msnt_rec.transaction_temp_id);
7043 FETCH c_get_parent_attributes INTO parent_rec;
7044 CLOSE c_get_parent_attributes;
7045
7046 UPDATE mtl_material_transactions_temp
7047 SET subinventory_code = parent_rec.subinventory_code
7048 , locator_id = parent_rec.locator_id
7049 , lpn_id = NVL(parent_rec.content_lpn_id,parent_rec.lpn_id)
7050 WHERE transaction_temp_id = l_transaction_temp_id;
7051
7052 IF l_debug = 1 AND SQL%FOUND
7053 THEN
7054 print_debug
7055 ('Updated temp ID ' || to_char(l_transaction_temp_id) ||
7056 ' with subinventory ' || parent_rec.subinventory_code ||
7057 ', locator ID: ' || to_char(parent_rec.locator_id) ||
7058 ' and LPN ID: ' || to_char(NVL( parent_rec.content_lpn_id
7059 , parent_rec.lpn_id
7060 )
7061 )
7062 , l_api_name
7063 );
7064 END IF;
7065 END IF;
7066 END IF; -- end if parent NOT found
7067
7068 --
7069 -- Transfer the MSNT record to child
7070 --
7071 IF p_lot_number IS NOT NULL
7072 THEN
7073 --
7074 -- Get serial temp ID or generate new
7075 --
7076 BEGIN
7077 SELECT mtlt.serial_transaction_temp_id
7078 INTO l_srl_temp_id
7079 FROM mtl_transaction_lots_temp mtlt
7080 WHERE mtlt.transaction_temp_id = l_transaction_temp_id
7081 AND mtlt.lot_number = p_lot_number;
7082
7083 IF l_debug = 1 THEN
7084 print_debug
7085 ( 'Serial temp ID is: ' || to_char(l_srl_temp_id)
7086 , l_api_name
7087 );
7088 END IF;
7089 EXCEPTION
7090 WHEN OTHERS THEN
7091 IF l_debug = 1 THEN
7092 print_debug
7093 ( 'Exception getting serial temp ID for ' ||
7094 ' lot number ' || p_lot_number ||
7095 ' and temp ID' || to_char(l_transaction_temp_id) ||
7096 ': ' || sqlerrm
7097 , l_api_name
7098 );
7099 END IF;
7100 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7101 END;
7102
7103 IF l_srl_temp_id IS NULL
7104 THEN
7105 SELECT mtl_material_transactions_s.NEXTVAL
7106 INTO l_srl_temp_id
7107 FROM dual;
7108
7109 IF l_debug = 1 THEN
7110 print_debug
7111 ( 'New srl temp ID: ' || to_char(l_srl_temp_id)
7112 , l_api_name
7113 );
7114 END IF;
7115
7116 UPDATE mtl_transaction_lots_temp mtlt
7117 SET mtlt.serial_transaction_temp_id = l_srl_temp_id
7118 WHERE mtlt.transaction_temp_id = l_transaction_temp_id
7119 AND mtlt.lot_number = p_lot_number;
7120 END IF;
7121
7122 UPDATE mtl_serial_numbers_temp msnt
7123 SET transaction_temp_id = l_srl_temp_id
7124 WHERE rowid = lot_msnt_rec.rowid;
7125
7126 ELSE
7127 UPDATE mtl_serial_numbers_temp msnt
7128 SET transaction_temp_id = l_transaction_temp_id
7129 WHERE rowid = msnt_rec.rowid;
7130
7131 END IF;
7132
7133 IF l_debug = 1 AND SQL%FOUND
7134 THEN
7135 print_debug
7136 ( 'Updated MSNT record for serial ' || p_serial_number
7137 , l_api_name
7138 );
7139 END IF;
7140
7141 --
7142 -- Now update the parent
7143 --
7144 BEGIN
7145 UPDATE mtl_material_transactions_temp
7146 SET transaction_quantity = transaction_quantity - 1
7147 , primary_quantity = primary_quantity - 1
7148 WHERE transaction_temp_id = l_parent_line_id;
7149
7150 IF l_debug = 1 AND SQL%FOUND
7151 THEN
7152 print_debug
7153 ( 'Decremented txn/primary qty on parent MMTT record '
7154 || to_char(l_parent_line_id)
7155 , l_api_name
7156 );
7157 END IF;
7158
7159 IF p_lot_number IS NOT NULL
7160 THEN
7161 UPDATE mtl_transaction_lots_temp
7162 SET transaction_quantity = transaction_quantity - 1
7163 , primary_quantity = primary_quantity - 1
7164 WHERE transaction_temp_id = l_parent_line_id
7165 AND lot_number = p_lot_number;
7166
7167 IF l_debug = 1 AND SQL%FOUND
7168 THEN
7169 print_debug
7170 ( 'Decremented txn/primary qty on parent record for lot '
7171 || p_lot_number
7172 , l_api_name
7173 );
7174 END IF;
7175 END IF;
7176 EXCEPTION
7177 WHEN OTHERS THEN
7178 IF l_debug = 1 THEN
7179 print_debug
7180 ( 'Error updating txn/primary quantity: ' || sqlerrm
7181 , l_api_name
7182 );
7183 END IF;
7184 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7185 END;
7186
7187 BEGIN
7188 SELECT mmtt.transaction_header_id
7189 INTO l_txn_header_id
7190 FROM mtl_material_transactions_temp mmtt
7191 WHERE mmtt.transaction_temp_id = l_transaction_temp_id;
7192 EXCEPTION
7193 WHEN OTHERS THEN
7194 IF l_debug = 1 THEN
7195 print_debug
7196 ( 'Error getting txn header ID: ' || sqlerrm
7197 , l_api_name
7198 );
7199 END IF;
7200 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7201 END;
7202
7203 UPDATE mtl_serial_numbers
7204 SET group_mark_id = l_txn_header_id
7205 WHERE current_organization_id = p_organization_id
7206 AND inventory_item_id = p_item_id
7207 AND NVL(revision,'@@@@') = NVL(p_revision,'@@@@')
7208 AND serial_number = p_serial_number;
7209
7210 IF l_debug = 1 THEN
7211 print_debug
7212 ( 'Updated MSN record with header_id ' || to_char(l_txn_header_id)
7213 , l_api_name
7214 );
7215 END IF;
7216
7217 IF NOT l_parent_found
7218 THEN
7219 g_current_drop_lpn.current_drop_list(l_transaction_temp_id) := 'SRL_DONE';
7220 IF l_debug = 1 THEN
7221 print_debug
7222 ( 'Marking new temp ID ' || to_char(l_transaction_temp_id) ||
7223 ' as SRL_DONE.'
7224 , l_api_name
7225 );
7226 END IF;
7227
7228 l_transaction_temp_id := l_orig_temp_id;
7229
7230 IF l_debug = 1 THEN
7231 print_debug
7232 ( 'l_transaction_temp_id is now ' || to_char(l_transaction_temp_id)
7233 , l_api_name
7234 );
7235 END IF;
7236 END IF;
7237
7238 IF p_lot_number IS NOT NULL
7239 THEN
7240 OPEN c_get_lot_srl_count
7241 ( l_transaction_temp_id
7242 , p_lot_number
7243 );
7244 FETCH c_get_lot_srl_count
7245 INTO l_primary_qty
7246 , l_serial_count;
7247
7248 IF c_get_lot_srl_count%NOTFOUND
7249 THEN
7250 IF l_debug = 1 THEN
7251 print_debug
7252 ( 'c_get_lot_srl_count returned no records'
7253 , l_api_name
7254 );
7255 END IF;
7256 CLOSE c_get_lot_srl_count;
7257 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7258 END IF;
7259
7260 IF c_get_lot_srl_count%ISOPEN
7261 THEN
7262 CLOSE c_get_lot_srl_count;
7263 END IF;
7264 ELSE
7265 OPEN c_get_serial_count (l_transaction_temp_id);
7266 FETCH c_get_serial_count
7267 INTO l_primary_qty
7268 , l_serial_count;
7269
7270 IF c_get_serial_count%NOTFOUND
7271 THEN
7272 IF l_debug = 1 THEN
7273 print_debug
7274 ( 'c_get_serial_count returned no records'
7275 , l_api_name
7276 );
7277 END IF;
7278 CLOSE c_get_serial_count;
7279 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7280 END IF;
7281
7282 IF c_get_serial_count%ISOPEN
7283 THEN
7284 CLOSE c_get_serial_count;
7285 END IF;
7286 END IF;
7287
7288 IF l_debug = 1 THEN
7289 print_debug
7290 ( 'l_primary_qty: ' || to_char(l_primary_qty) ||
7291 ', l_serial_count: ' || to_char(l_serial_count)
7292 , l_api_name
7293 );
7294 END IF;
7295
7296 IF (NOT (l_primary_qty > l_serial_count))
7297 THEN
7298 --
7299 -- Set status to SRL_DONE, remove from serial cache
7300 --
7301 g_current_drop_lpn.current_drop_list(l_transaction_temp_id)
7302 := 'SRL_DONE';
7303
7304 ii := g_cur_pend_temp.FIRST;
7305 jj := g_cur_pend_temp.LAST;
7306
7307 IF l_debug = 1 THEN
7308 print_debug
7309 ( 'ii = ' || to_char(ii) || ', jj = ' || to_char(jj)
7310 , l_api_name
7311 );
7312 END IF;
7313
7314 l_temp_found := FALSE;
7315 l_temp_id := g_cur_pend_temp(ii);
7316
7317 WHILE ( (ii <= jj)
7318 AND
7319 (NOT l_temp_found)
7320 )
7321 LOOP
7322 IF l_temp_id = l_transaction_temp_id
7323 THEN
7324 l_temp_found := TRUE;
7325 EXIT;
7326 END IF;
7327
7328 IF NOT l_temp_found THEN
7329 IF ii < jj THEN
7330 ii := g_cur_pend_temp.NEXT(ii);
7331 l_temp_id := g_cur_pend_temp(ii);
7332 ELSE
7333 EXIT;
7334 END IF;
7335 END IF;
7336 END LOOP;
7337
7338 IF NOT l_temp_found
7339 THEN
7340 IF l_debug = 1 THEN
7341 print_debug
7342 ( 'Cannot find temp ID ' || to_char(l_transaction_temp_id) ||
7343 ' in g_cur_pend_temp'
7344 , l_api_name
7345 );
7346 END IF;
7347 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7348 ELSE
7349 IF l_debug = 1 THEN
7350 print_debug
7351 ( 'Found temp ID ' || g_cur_pend_temp(ii)
7352 || ' in g_cur_pend_temp, which matches '
7353 || to_char(l_transaction_temp_id)
7354 || '. Deleting...'
7355 , l_api_name
7356 );
7357 END IF;
7358 g_cur_pend_temp.DELETE(ii);
7359 END IF;
7360 END IF; -- end if MMTT qty matches serial count
7361
7362 IF ( (p_lpn IS NULL)
7363 AND
7364 (p_lot_number IS NULL)
7365 )
7366 THEN
7367 BEGIN
7368 SELECT 'x'
7369 INTO l_dummy
7370 FROM dual
7371 WHERE EXISTS
7372 ( SELECT 'x'
7373 FROM mtl_material_transactions_temp mmtt
7374 WHERE mmtt.organization_id = g_current_drop_lpn.organization_id
7375 AND mmtt.transfer_lpn_id = g_current_drop_lpn.lpn_id
7376 AND mmtt.parent_line_id = mmtt.transaction_temp_id
7377 AND mmtt.transaction_quantity > 0
7378 AND mmtt.inventory_item_id = p_item_id
7379 AND NVL(mmtt.revision,'@@@@') = NVL(p_revision,'@@@@')
7380 AND ( mmtt.content_lpn_id IS NULL
7381 OR
7382 mmtt.content_lpn_id = mmtt.transfer_lpn_id
7383 )
7384 );
7385 l_loose_qty_exists := 'Y';
7386 EXCEPTION
7387 WHEN NO_DATA_FOUND THEN
7388 l_loose_qty_exists := 'N';
7389 END;
7390
7391 x_loose_qty_exists := l_loose_qty_exists;
7392 END IF;
7393
7394 EXCEPTION
7395 WHEN fnd_api.g_exc_error THEN
7396 ROLLBACK to process_serial_sp;
7397
7398 x_return_status := fnd_api.g_ret_sts_error;
7399
7400 fnd_msg_pub.count_and_get
7401 ( p_count => l_msg_count
7402 , p_data => l_msg_data
7403 , p_encoded => fnd_api.g_false
7404 );
7405
7406 IF l_debug = 1 THEN
7407 print_debug (l_msg_data, l_api_name);
7408 END IF;
7409
7410 WHEN OTHERS THEN
7411 ROLLBACK to process_serial_sp;
7412
7413 x_return_status := fnd_api.g_ret_sts_unexp_error;
7414
7415 IF l_debug = 1 THEN
7416 print_debug ('Other error: ' || sqlerrm, l_api_name);
7417 END IF;
7418
7419 END process_serial;
7420
7421
7422
7423 PROCEDURE cancel_task
7424 ( x_return_status OUT NOCOPY VARCHAR2
7425 , p_organization_id IN NUMBER
7426 , p_transfer_lpn_id IN NUMBER
7427 ) IS
7428
7429 l_api_name VARCHAR2(30) := 'cancel_task';
7430 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
7431
7432 l_api_return_status VARCHAR2(1);
7433
7434 CURSOR c_get_temp_ids
7435 ( p_org_id IN NUMBER
7436 , p_lpn_id IN NUMBER
7437 ) IS
7438 SELECT mmtt.transaction_temp_id
7439 , wdt.suggested_dest_subinventory
7440 , wdt.suggested_dest_locator_id
7441 FROM ( SELECT mmtt2.transaction_temp_id
7442 FROM mtl_material_transactions_temp mmtt2
7443 WHERE mmtt2.organization_id = p_org_id
7444 AND mmtt2.transfer_lpn_id = p_lpn_id
7445 AND mmtt2.parent_line_id IS NULL
7446 UNION
7447 SELECT mmtt3.transaction_temp_id
7448 FROM mtl_material_transactions_temp mmtt3
7449 WHERE mmtt3.parent_line_id IS NOT NULL
7450 AND mmtt3.transaction_temp_id <> mmtt3.parent_line_id
7451 AND mmtt3.transaction_temp_id IN
7452 ( SELECT mmtt4.transaction_temp_id
7453 FROM mtl_material_transactions_temp mmtt4
7454 WHERE mmtt4.organization_id = p_org_id
7455 AND mmtt4.transfer_lpn_id = p_lpn_id
7456 START WITH
7457 mmtt4.transaction_temp_id = mmtt4.parent_line_id
7458 CONNECT BY
7459 ( mmtt4.parent_line_id = PRIOR mmtt4.transaction_temp_id
7460 AND
7461 mmtt4.parent_line_id <> mmtt4.transaction_temp_id
7462 )
7463 )
7464 ) mmtt
7465 , wms_dispatched_tasks wdt
7466 WHERE wdt.transaction_temp_id = mmtt.transaction_temp_id
7467 AND wdt.suggested_dest_subinventory IS NOT NULL
7468 AND wdt.suggested_dest_locator_id IS NOT NULL;
7469
7470 TYPE TempIDTable IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
7471 TYPE SubCodeTable IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
7472 TYPE LocIDTable IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
7473
7474 v_temp_id_tbl TempIDTable;
7475 v_sub_tbl SubCodeTable;
7476 v_loc_id_tbl LocIDTable;
7477
7478 BEGIN
7479 x_return_status := fnd_api.g_ret_sts_success;
7480
7481 IF l_debug = 1 THEN
7482 print_debug
7483 ( 'Entered with parameters: ' || g_newline ||
7484 'p_organization_id => ' || to_char(p_organization_id) || g_newline ||
7485 'p_transfer_lpn_id => ' || to_char(p_transfer_lpn_id)
7486 , l_api_name
7487 );
7488 END IF;
7489
7490 fnd_msg_pub.initialize;
7491
7492 --
7493 -- Validate passed in Org and LPN
7494 --
7495 IF p_organization_id <> g_current_drop_lpn.organization_id
7496 OR
7497 p_transfer_lpn_id <> g_current_drop_lpn.lpn_id
7498 THEN
7499 IF l_debug = 1 THEN
7500 print_debug
7501 ( 'Passed in org or LPN did not match cached info: '
7502 || g_newline || 'p_organization_id: ' || to_char(p_organization_id)
7503 || g_newline || 'p_transfer_lpn_id: ' || to_char(p_transfer_lpn_id)
7504 || g_newline || 'Cached Org ID: ' || to_char(g_current_drop_lpn.organization_id)
7505 || g_newline || 'Cached LPN ID: ' || to_char(g_current_drop_lpn.lpn_id)
7506 , l_api_name
7507 );
7508 END IF;
7509 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7510 END IF;
7511
7512 ROLLBACK;
7513
7514 SAVEPOINT cancel_tsk_sp;
7515
7516 --
7517 -- Bug 4884372: Restore original destination sub/loc to MMTT
7518 -- and null out suggested sub/loc on WDT
7519 --
7520 OPEN c_get_temp_ids (p_organization_id, p_transfer_lpn_id);
7521 FETCH c_get_temp_ids BULK COLLECT INTO v_temp_id_tbl, v_sub_tbl, v_loc_id_tbl;
7522 CLOSE c_get_temp_ids;
7523
7524 FORALL ii IN v_temp_id_tbl.FIRST..v_temp_id_tbl.LAST
7525 UPDATE mtl_material_transactions_temp
7526 SET transfer_subinventory = v_sub_tbl(ii)
7527 , transfer_to_location = v_loc_id_tbl(ii)
7528 WHERE transaction_temp_id = v_temp_id_tbl(ii);
7529
7530 IF l_debug = 1 THEN
7531 print_debug('Updated dest sub, dest loc on MMTTs', l_api_name);
7532 END IF;
7533
7534 FORALL jj IN v_temp_id_tbl.FIRST..v_temp_id_tbl.LAST
7535 UPDATE wms_dispatched_tasks
7536 SET suggested_dest_subinventory = NULL
7537 , suggested_dest_locator_id = NULL
7538 WHERE transaction_temp_id = v_temp_id_tbl(jj);
7539
7540 IF l_debug = 1 THEN
7541 print_debug('Updated suggested dest sub/loc on WDTs to NULL', l_api_name);
7542 END IF;
7543
7544 -- Bug 4884284: Delete child WDT records
7545 DELETE wms_dispatched_tasks
7546 WHERE transaction_temp_id IN
7547 ( SELECT transaction_temp_id
7548 FROM mtl_material_transactions_temp mmtt
7549 WHERE mmtt.parent_line_id IS NOT NULL
7550 AND mmtt.transaction_temp_id <> NVL(mmtt.parent_line_id,0)
7551 AND mmtt.transaction_temp_id IN
7552 ( SELECT mmtt2.transaction_temp_id
7553 FROM mtl_material_transactions_temp mmtt2
7554 WHERE mmtt2.organization_id = p_organization_id
7555 AND mmtt2.transfer_lpn_id = p_transfer_lpn_id
7556 START WITH
7557 mmtt2.transaction_temp_id = mmtt2.parent_line_id
7558 CONNECT BY
7559 ( mmtt2.parent_line_id = PRIOR mmtt2.transaction_temp_id
7560 AND
7561 mmtt2.parent_line_id <> mmtt2.transaction_temp_id
7562 )
7563 )
7564 );
7565
7566 IF l_debug = 1 THEN
7567 print_debug ('No. of child WDT records deleted: ' || SQL%ROWCOUNT, l_api_name);
7568 END IF;
7569
7570 l_api_return_status := fnd_api.g_ret_sts_success;
7571 clear_lpn_cache(l_api_return_status);
7572
7573 IF l_api_return_status <> fnd_api.g_ret_sts_success
7574 THEN
7575 IF l_debug = 1 THEN
7576 print_debug ('Error from clear_lpn_cache', l_api_name);
7577 END IF;
7578 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7579 END IF;
7580
7581 -- Start change for Bug 5620764
7582 -- Restore LPN context for bulk picked content LPNs back to "Packing Content" from "In Inventory"
7583 -- Bug5659809: update last_update_date and last_update_by as well
7584 UPDATE wms_license_plate_numbers wlpn1
7585 SET wlpn1.lpn_context = WMS_Container_PUB.LPN_CONTEXT_PACKING
7586 , last_update_date = SYSDATE
7587 , last_updated_by = fnd_global.user_id
7588 WHERE wlpn1.lpn_id IN
7589 ( SELECT mmtt.content_lpn_id
7590 FROM mtl_material_transactions_temp mmtt
7591 , wms_license_plate_numbers wlpn2
7592 WHERE mmtt.transfer_lpn_id = p_transfer_lpn_id
7593 AND mmtt.organization_id = p_organization_id
7594 AND mmtt.parent_line_id = mmtt.transaction_temp_id
7595 AND mmtt.content_lpn_id = wlpn2.lpn_id
7596 AND mmtt.organization_id = wlpn2.organization_id
7597 AND wlpn2.lpn_context = WMS_Container_PUB.LPN_CONTEXT_INV
7598 );
7599
7600 IF l_debug = 1 AND SQL%FOUND THEN
7601 print_debug ('Restored LPN context of bulk-picked content LPN', l_api_name);
7602 END IF;
7603 -- End change for Bug 5620764
7604
7605 COMMIT;
7606
7607 EXCEPTION
7608 WHEN OTHERS THEN
7609 ROLLBACK TO cancel_tsk_sp;
7610
7611 x_return_status := fnd_api.g_ret_sts_unexp_error;
7612
7613 IF l_debug = 1 THEN
7614 print_debug ('Other error: ' || sqlerrm, l_api_name);
7615 END IF;
7616
7617 END cancel_task;
7618
7619
7620
7621 PROCEDURE validate_xfer_to_lpn
7622 ( x_return_status OUT NOCOPY VARCHAR2
7623 , p_organization_id IN NUMBER
7624 , p_transfer_lpn_id IN NUMBER
7625 , p_group_number IN NUMBER
7626 , p_outer_lpn_done IN VARCHAR2
7627 , p_xfer_to_lpn IN VARCHAR2
7628 , p_dest_sub IN VARCHAR2
7629 , p_dest_loc_id IN NUMBER
7630 , p_delivery_id IN NUMBER
7631 ) IS
7632
7633 l_api_name VARCHAR2(30) := 'validate_xfer_to_lpn';
7634 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
7635
7636 l_api_return_status VARCHAR2(1);
7637 l_msg_count NUMBER;
7638 l_msg_data VARCHAR2(2000);
7639
7640 l_lpn_id NUMBER := NULL;
7641 l_lpn_delivery_id NUMBER;
7642 l_process_id NUMBER;
7643 l_primary_qty NUMBER;
7644
7645 l_lpn_carton_grp_id NUMBER;
7646 l_cur_carton_grp_id NUMBER;
7647 l_transaction_temp_id NUMBER;
7648
7649 ii NUMBER;
7650 jj NUMBER;
7651
7652 l_temp_tbl g_temp_id_tbl;
7653
7654 l_allow_packing NUMBER;
7655
7656 CURSOR c_lpn_info
7657 ( p_lpn IN VARCHAR2
7658 , p_org_id IN NUMBER
7659 ) IS
7660 SELECT lpn_id
7661 , lpn_context
7662 , subinventory_code
7663 , locator_id
7664 FROM wms_license_plate_numbers
7665 WHERE organization_id = p_org_id
7666 AND license_plate_number = p_lpn;
7667
7668 to_lpn_rec c_lpn_info%ROWTYPE;
7669
7670
7671 CURSOR c_get_lpn_delivery
7672 ( p_lpn_id IN NUMBER
7673 , p_org_id IN NUMBER
7674 ) IS
7675 SELECT wda.delivery_id
7676 FROM wsh_delivery_details_ob_grp_v wdd
7677 , wsh_delivery_assignments_v wda
7678 WHERE wdd.lpn_id = p_lpn_id
7679 AND wdd.released_status = 'X' -- For LPN reuse ER : 6845650
7680 AND wdd.organization_id = p_org_id
7681 AND wdd.delivery_detail_id = wda.parent_delivery_detail_id;
7682
7683
7684 CURSOR c_get_mmtt_lpn_info
7685 ( p_lpn_id IN NUMBER
7686 , p_org_id IN NUMBER
7687 ) IS
7688 SELECT mmtt.transfer_subinventory
7689 , mmtt.transfer_to_location
7690 , mtrl.carton_grouping_id
7691 , wda.delivery_id
7692 FROM mtl_material_transactions_temp mmtt
7693 , mtl_txn_request_lines mtrl
7694 , wsh_delivery_details_ob_grp_v wdd
7695 , wsh_delivery_assignments_v wda
7696 WHERE mmtt.organization_id = p_org_id
7697 AND mmtt.transfer_lpn_id = p_lpn_id
7698 AND mmtt.move_order_line_id = mtrl.line_id
7699 AND mtrl.line_id = wdd.move_order_line_id (+)
7700 AND wdd.delivery_detail_id = wda.delivery_detail_id (+);
7701
7702 mmtt_lpn_rec c_get_mmtt_lpn_info%ROWTYPE;
7703
7704
7705 CURSOR c_get_lpn_carton_grp
7706 ( p_lpn_id IN NUMBER
7707 , p_org_id IN NUMBER
7708 ) IS
7709 SELECT mtrl.carton_grouping_id
7710 FROM wsh_delivery_details_ob_grp_v wdd
7711 , wsh_delivery_assignments_v wda
7712 , wsh_delivery_details_ob_grp_v wdd2
7713 , mtl_txn_request_lines mtrl
7714 WHERE wdd.lpn_id = p_lpn_id
7715 AND wdd.released_status = 'X' -- For LPN reuse ER : 6845650
7716 AND wdd.organization_id = p_org_id
7717 AND wdd.delivery_detail_id = wda.parent_delivery_detail_id
7718 AND wda.delivery_detail_id = wdd2.delivery_detail_id
7719 AND wdd2.move_order_line_id = mtrl.line_id;
7720
7721
7722 CURSOR c_get_cur_carton_grp
7723 ( p_temp_id IN NUMBER
7724 ) IS
7725 SELECT mtrl.carton_grouping_id
7726 FROM mtl_material_transactions_temp mmtt
7727 , mtl_txn_request_lines mtrl
7728 WHERE mmtt.transaction_temp_id = p_temp_id
7729 AND mmtt.move_order_line_id = mtrl.line_id;
7730
7731 BEGIN
7732 x_return_status := fnd_api.g_ret_sts_success;
7733
7734 IF l_debug = 1 THEN
7735 print_debug
7736 ( 'Entered with parameters: ' || g_newline ||
7737 'p_organization_id => ' || to_char(p_organization_id) || g_newline ||
7738 'p_transfer_lpn_id => ' || to_char(p_transfer_lpn_id) || g_newline ||
7739 'p_group_number => ' || to_char(p_group_number) || g_newline ||
7740 'p_outer_lpn_done => ' || p_outer_lpn_done || g_newline ||
7741 'p_xfer_to_lpn => ' || p_xfer_to_lpn || g_newline ||
7742 'p_dest_sub => ' || p_dest_sub || g_newline ||
7743 'p_dest_loc_id => ' || to_char(p_dest_loc_id) || g_newline ||
7744 'p_delivery_id => ' || to_char(p_delivery_id)
7745 , l_api_name
7746 );
7747 END IF;
7748
7749 fnd_msg_pub.initialize;
7750
7751 SAVEPOINT validate_xfer_sp;
7752
7753 --
7754 -- Validate passed in Org and LPN
7755 --
7756 IF p_organization_id <> g_current_drop_lpn.organization_id
7757 OR
7758 p_transfer_lpn_id <> g_current_drop_lpn.lpn_id
7759 THEN
7760 IF l_debug = 1 THEN
7761 print_debug
7762 ( 'Passed in org or LPN did not match cached info: '
7763 || g_newline || 'p_organization_id: ' || to_char(p_organization_id)
7764 || g_newline || 'p_transfer_lpn_id: ' || to_char(p_transfer_lpn_id)
7765 || g_newline || 'Cached Org ID: ' || to_char(g_current_drop_lpn.organization_id)
7766 || g_newline || 'Cached LPN ID: ' || to_char(g_current_drop_lpn.lpn_id)
7767 , l_api_name
7768 );
7769 END IF;
7770 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7771 END IF;
7772
7773 --
7774 -- Check if new
7775 --
7776 OPEN c_lpn_info (p_xfer_to_lpn, p_organization_id);
7777 FETCH c_lpn_info into to_lpn_rec;
7778
7779 IF c_lpn_info%NOTFOUND
7780 THEN
7781 IF (l_debug = 1) THEN
7782 print_debug ('Xfer LPN is new.', l_api_name);
7783 END IF;
7784
7785 l_api_return_status := fnd_api.g_ret_sts_success;
7786 wms_container_pub.create_lpn
7787 ( p_api_version => 1.0
7788 , x_return_status => l_api_return_status
7789 , x_msg_count => l_msg_count
7790 , x_msg_data => l_msg_data
7791 , p_lpn => p_xfer_to_lpn
7792 , p_organization_id => p_organization_id
7793 , x_lpn_id => l_lpn_id
7794 , p_source => wms_container_pub.lpn_context_pregenerated
7795 );
7796
7797 IF l_api_return_status <> fnd_api.g_ret_sts_success
7798 THEN
7799 IF l_debug = 1 THEN
7800 print_debug
7801 ( 'Error from WMS_Container_PUB.create_lpn: ' || l_msg_data
7802 , l_api_name);
7803 END IF;
7804 RAISE FND_API.G_EXC_ERROR;
7805 ELSE
7806 IF l_debug = 1 THEN
7807 print_debug
7808 ( 'WMS_Container_PUB.create_lpn returned LPN '
7809 || to_char(l_lpn_id)
7810 , l_api_name);
7811 END IF;
7812 END IF;
7813
7814 --
7815 -- Check if pre-generated
7816 --
7817 ELSIF to_lpn_rec.lpn_context = wms_container_pub.lpn_context_pregenerated
7818 THEN
7819 IF (l_debug = 1) THEN
7820 print_debug ('Xfer LPN is pre-generated.', l_api_name);
7821 END IF;
7822
7823 ELSIF to_lpn_rec.lpn_id = p_transfer_lpn_id
7824 AND
7825 p_outer_lpn_done <> 'TRUE'
7826 THEN
7827 IF (l_debug = 1) THEN
7828 print_debug ('LPN is outermost LPN, but not done', l_api_name);
7829 END IF;
7830
7831 fnd_message.set_name('WMS', 'WMS_LPN_HAS_MORE_DROP_MTL');
7832 fnd_msg_pub.ADD;
7833 RAISE FND_API.G_EXC_ERROR;
7834
7835 ELSIF to_lpn_rec.lpn_context <> wms_container_pub.lpn_context_picked
7836 THEN
7837 IF (l_debug = 1) THEN
7838 print_debug
7839 ( 'LPN has an invalid context: '
7840 || to_char(to_lpn_rec.lpn_context)
7841 , l_api_name
7842 );
7843 END IF;
7844
7845 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN_CONTEXT');
7846 fnd_msg_pub.ADD;
7847 RAISE FND_API.G_EXC_ERROR;
7848
7849 ELSE
7850 --
7851 -- Check if staged in another sub/loc
7852 -- or for a different delivery
7853 --
7854 IF to_lpn_rec.subinventory_code <> p_dest_sub
7855 OR
7856 to_lpn_rec.locator_id <> p_dest_loc_id
7857 THEN
7858 IF (l_debug = 1) THEN
7859 print_debug
7860 ( 'Scanned LPN resides in a diff sub/loc: '
7861 || to_lpn_rec.subinventory_code || '/'
7862 || to_char(to_lpn_rec.locator_id)
7863 , l_api_name
7864 );
7865 END IF;
7866
7867 fnd_message.set_name('WMS', 'WMS_XFER_LPN_DIFF_SUBINV');
7868 fnd_msg_pub.ADD;
7869 RAISE FND_API.G_EXC_ERROR;
7870 ELSE
7871 OPEN c_get_lpn_delivery (to_lpn_rec.lpn_id, p_organization_id);
7872 FETCH c_get_lpn_delivery INTO l_lpn_delivery_id;
7873 CLOSE c_get_lpn_delivery;
7874
7875 IF NVL(p_delivery_id,0) <> NVL(l_lpn_delivery_id,0) THEN
7876 IF (l_debug = 1) THEN
7877 print_debug
7878 ( 'LPN belongs to a diff delivery: '
7879 || to_char(l_lpn_delivery_id)
7880 , l_api_name
7881 );
7882 END IF;
7883
7884 fnd_message.set_name('WMS', 'WMS_DROP_LPN_DIFF_DELIV');
7885 fnd_msg_pub.ADD;
7886 RAISE FND_API.G_EXC_ERROR;
7887 END IF;
7888
7889 IF NVL(p_delivery_id,0) = 0 AND NVL(l_lpn_delivery_id,0) = 0 THEN
7890 OPEN c_get_lpn_carton_grp (to_lpn_rec.lpn_id, p_organization_id);
7891 FETCH c_get_lpn_carton_grp INTO l_lpn_carton_grp_id;
7892 CLOSE c_get_lpn_carton_grp;
7893
7894 IF (l_debug = 1) THEN
7895 print_debug
7896 ( 'LPN carton group ID: '
7897 || to_char(l_lpn_carton_grp_id)
7898 , l_api_name
7899 );
7900 END IF;
7901
7902 l_transaction_temp_id := g_current_drop_lpn.current_drop_list.FIRST;
7903 OPEN c_get_cur_carton_grp (l_transaction_temp_id);
7904 FETCH c_get_cur_carton_grp INTO l_cur_carton_grp_id;
7905 CLOSE c_get_cur_carton_grp;
7906
7907 IF (l_debug = 1) THEN
7908 print_debug
7909 ( 'Current carton group ID: '
7910 || to_char(l_cur_carton_grp_id)
7911 , l_api_name
7912 );
7913 END IF;
7914
7915 IF NVL(l_lpn_carton_grp_id,0) <> NVL(l_cur_carton_grp_id,0)
7916 THEN
7917 IF (l_debug = 1) THEN
7918 print_debug
7919 ( 'LPN has a diff carton grouping ID'
7920 , l_api_name
7921 );
7922 END IF;
7923
7924 fnd_message.set_name('WMS', 'WMS_INVALID_PACK_DELIVERY');
7925 fnd_msg_pub.ADD;
7926 RAISE FND_API.G_EXC_ERROR;
7927 END IF;
7928
7929 END IF;
7930 END IF;
7931 END IF;
7932
7933 IF c_lpn_info%ISOPEN
7934 THEN
7935 CLOSE c_lpn_info;
7936 END IF;
7937
7938 --Start: Added for bug 10139672
7939 IF NVL(l_lpn_id,0) = 0
7940 THEN
7941 g_xfer_to_lpn_id := to_lpn_rec.lpn_id;
7942 ELSE
7943 g_xfer_to_lpn_id := l_lpn_id;
7944 END IF;
7945
7946 IF (l_debug = 1) THEN
7947 print_debug
7948 ( 'Xfer To LPN ID g_xfer_to_lpn_id:'|| to_char(g_xfer_to_lpn_id)
7949 , l_api_name
7950 );
7951 END IF;
7952 --END: Added for bug 10139672
7953
7954 --
7955 -- Update MMTT records that are PENDING
7956 --
7957 l_api_return_status := fnd_api.g_ret_sts_success;
7958 get_temp_list
7959 ( x_temp_tbl => l_temp_tbl
7960 , x_return_status => l_api_return_status
7961 , p_group_num => p_group_number
7962 , p_status => 'PENDING'
7963 );
7964
7965 IF l_api_return_status <> fnd_api.g_ret_sts_success
7966 THEN
7967 IF l_debug = 1 THEN
7968 print_debug ('Error from get_temp_list', l_api_name);
7969 END IF;
7970 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
7971 END IF;
7972
7973 IF l_temp_tbl.COUNT > 0 THEN
7974 ii := l_temp_tbl.FIRST;
7975 jj := l_temp_tbl.LAST;
7976
7977 l_transaction_temp_id := l_temp_tbl(ii);
7978
7979 IF l_debug = 1 THEN
7980 print_debug
7981 ( 'Processing PENDING records: ii = ' || to_char(ii)
7982 || ', jj = ' || to_char(jj)
7983 || ', temp ID = ' || to_char(l_transaction_temp_id)
7984 || ', l_lpn_id = ' || to_char(l_lpn_id)
7985 || ', ID in LPN rec = ' || to_char(to_lpn_rec.lpn_id)
7986 , l_api_name
7987 );
7988 END IF;
7989
7990 WHILE (ii <= jj)
7991 LOOP
7992 UPDATE mtl_material_transactions_temp mmtt
7993 SET mmtt.transfer_lpn_id = NVL(l_lpn_id,to_lpn_rec.lpn_id)
7994 WHERE mmtt.transaction_temp_id = l_transaction_temp_id
7995 RETURNING primary_quantity
7996 INTO l_primary_qty;
7997
7998 IF l_primary_qty > 0
7999 THEN
8000 g_current_drop_lpn.current_drop_list(l_transaction_temp_id)
8001 := 'DONE';
8002 ELSE
8003 DELETE mtl_material_transactions_temp
8004 WHERE transaction_temp_id = l_transaction_temp_id;
8005
8006 g_current_drop_lpn.current_drop_list.DELETE(l_transaction_temp_id);
8007
8008 IF l_debug = 1 THEN
8009 print_debug
8010 ( 'Deleted temp ID: ' || to_char(l_transaction_temp_id)
8011 , l_api_name
8012 );
8013 END IF;
8014 END IF;
8015
8016 IF ii < jj THEN
8017 ii := l_temp_tbl.NEXT(ii);
8018 l_transaction_temp_id := l_temp_tbl(ii);
8019 ELSE
8020 EXIT;
8021 END IF;
8022
8023 IF l_debug = 1 THEN
8024 print_debug
8025 ( 'Fetched next temp ID: ' || to_char(l_transaction_temp_id)
8026 , l_api_name
8027 );
8028 END IF;
8029 END LOOP;
8030
8031 END IF; -- end if l_temp_tbl.COUNT > 0
8032
8033 l_temp_tbl.DELETE;
8034
8035 --
8036 -- Update MMTT records for which serials have been processed
8037 --
8038 l_api_return_status := fnd_api.g_ret_sts_success;
8039 get_temp_list
8040 ( x_temp_tbl => l_temp_tbl
8041 , x_return_status => l_api_return_status
8042 , p_group_num => p_group_number
8043 , p_status => 'SRL_DONE'
8044 );
8045
8046 IF l_api_return_status <> fnd_api.g_ret_sts_success
8047 THEN
8048 IF l_debug = 1 THEN
8049 print_debug ('Error from get_temp_list', l_api_name);
8050 END IF;
8051 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8052 END IF;
8053
8054 IF l_temp_tbl.COUNT > 0 THEN
8055 ii := l_temp_tbl.FIRST;
8056 jj := l_temp_tbl.LAST;
8057
8058 l_transaction_temp_id := l_temp_tbl(ii);
8059
8060 IF l_debug = 1 THEN
8061 print_debug
8062 ( 'Processing records in SRL_DONE status: ii = ' || to_char(ii)
8063 || ', jj = ' || to_char(jj)
8064 || ', temp ID = ' || to_char(l_transaction_temp_id)
8065 || ', l_lpn_id = ' || to_char(l_lpn_id)
8066 || ', ID in LPN rec = ' || to_char(to_lpn_rec.lpn_id)
8067 , l_api_name
8068 );
8069 END IF;
8070
8071 WHILE (ii <= jj)
8072 LOOP
8073 UPDATE mtl_material_transactions_temp mmtt
8074 SET mmtt.transfer_lpn_id = NVL(l_lpn_id,to_lpn_rec.lpn_id)
8075 WHERE mmtt.transaction_temp_id = l_transaction_temp_id
8076 RETURNING primary_quantity
8077 INTO l_primary_qty;
8078
8079 IF l_primary_qty > 0
8080 THEN
8081 g_current_drop_lpn.current_drop_list(l_transaction_temp_id)
8082 := 'DONE';
8083 ELSE
8084 DELETE mtl_material_transactions_temp
8085 WHERE transaction_temp_id = l_transaction_temp_id;
8086
8087 g_current_drop_lpn.current_drop_list.DELETE(l_transaction_temp_id);
8088
8089 IF l_debug = 1 THEN
8090 print_debug
8091 ( 'Deleted temp ID: ' || to_char(l_transaction_temp_id)
8092 , l_api_name
8093 );
8094 END IF;
8095 END IF;
8096
8097 IF ii < jj THEN
8098 ii := l_temp_tbl.NEXT(ii);
8099 l_transaction_temp_id := l_temp_tbl(ii);
8100 ELSE
8101 EXIT;
8102 END IF;
8103
8104 IF l_debug = 1 THEN
8105 print_debug
8106 ( 'Fetched next temp ID: ' || to_char(l_transaction_temp_id)
8107 , l_api_name
8108 );
8109 END IF;
8110 END LOOP;
8111
8112 END IF; -- end if l_temp_tbl.COUNT > 0
8113
8114 l_temp_tbl.DELETE;
8115
8116 --
8117 -- Update MMTT records for which from LPN has been stamped
8118 --
8119 l_api_return_status := fnd_api.g_ret_sts_success;
8120 get_temp_list
8121 ( x_temp_tbl => l_temp_tbl
8122 , x_return_status => l_api_return_status
8123 , p_group_num => p_group_number
8124 , p_status => 'LPN_DONE'
8125 );
8126
8127 IF l_api_return_status <> fnd_api.g_ret_sts_success
8128 THEN
8129 IF l_debug = 1 THEN
8130 print_debug ('Error from get_temp_list', l_api_name);
8131 END IF;
8132 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8133 END IF;
8134
8135 IF l_temp_tbl.COUNT > 0 THEN
8136 ii := l_temp_tbl.FIRST;
8137 jj := l_temp_tbl.LAST;
8138
8139 l_transaction_temp_id := l_temp_tbl(ii);
8140
8141 IF l_debug = 1 THEN
8142 print_debug
8143 ( 'Processing records in LPN_DONE status: ii = ' || to_char(ii)
8144 || ', jj = ' || to_char(jj)
8145 || ', temp ID = ' || to_char(l_transaction_temp_id)
8146 || ', l_lpn_id = ' || to_char(l_lpn_id)
8147 || ', ID in LPN rec = ' || to_char(to_lpn_rec.lpn_id)
8148 , l_api_name
8149 );
8150 END IF;
8151
8152 WHILE (ii <= jj)
8153 LOOP
8154 UPDATE mtl_material_transactions_temp mmtt
8155 SET mmtt.transfer_lpn_id = NVL(l_lpn_id,to_lpn_rec.lpn_id)
8156 WHERE mmtt.transaction_temp_id = l_transaction_temp_id
8157 RETURNING primary_quantity
8158 INTO l_primary_qty;
8159
8160 IF l_primary_qty > 0
8161 THEN
8162 g_current_drop_lpn.current_drop_list(l_transaction_temp_id)
8163 := 'DONE';
8164 ELSE
8165 DELETE mtl_material_transactions_temp
8166 WHERE transaction_temp_id = l_transaction_temp_id;
8167
8168 g_current_drop_lpn.current_drop_list.DELETE(l_transaction_temp_id);
8169
8170 IF l_debug = 1 THEN
8171 print_debug
8172 ( 'Deleted temp ID: ' || to_char(l_transaction_temp_id)
8173 , l_api_name
8174 );
8175 END IF;
8176 END IF;
8177
8178 IF ii < jj THEN
8179 ii := l_temp_tbl.NEXT(ii);
8180 l_transaction_temp_id := l_temp_tbl(ii);
8181 ELSE
8182 EXIT;
8183 END IF;
8184
8185 IF l_debug = 1 THEN
8186 print_debug
8187 ( 'Fetched next temp ID: ' || to_char(l_transaction_temp_id)
8188 , l_api_name
8189 );
8190 END IF;
8191 END LOOP;
8192
8193 END IF; -- end if l_temp_tbl.COUNT > 0
8194
8195 l_temp_tbl.DELETE;
8196
8197 --
8198 -- Update MMTT records for which from loose qty
8199 -- has been processed
8200 --
8201 l_api_return_status := fnd_api.g_ret_sts_success;
8202 get_temp_list
8203 ( x_temp_tbl => l_temp_tbl
8204 , x_return_status => l_api_return_status
8205 , p_group_num => p_group_number
8206 , p_status => 'LSE_DONE'
8207 );
8208
8209 IF l_api_return_status <> fnd_api.g_ret_sts_success
8210 THEN
8211 IF l_debug = 1 THEN
8212 print_debug ('Error from get_temp_list', l_api_name);
8213 END IF;
8214 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8215 END IF;
8216
8217 IF l_temp_tbl.COUNT > 0 THEN
8218 ii := l_temp_tbl.FIRST;
8219 jj := l_temp_tbl.LAST;
8220
8221 l_transaction_temp_id := l_temp_tbl(ii);
8222
8223 IF l_debug = 1 THEN
8224 print_debug
8225 ( 'Processing records in LSE_DONE status: ii = ' || to_char(ii)
8226 || ', jj = ' || to_char(jj)
8227 || ', temp ID = ' || to_char(l_transaction_temp_id)
8228 || ', l_lpn_id = ' || to_char(l_lpn_id)
8229 || ', ID in LPN rec = ' || to_char(to_lpn_rec.lpn_id)
8230 , l_api_name
8231 );
8232 END IF;
8233
8234 WHILE (ii <= jj)
8235 LOOP
8236 UPDATE mtl_material_transactions_temp mmtt
8237 SET mmtt.transfer_lpn_id = NVL(l_lpn_id,to_lpn_rec.lpn_id)
8238 WHERE mmtt.transaction_temp_id = l_transaction_temp_id
8239 RETURNING primary_quantity
8240 INTO l_primary_qty;
8241
8242 IF l_primary_qty > 0
8243 THEN
8244 g_current_drop_lpn.current_drop_list(l_transaction_temp_id)
8245 := 'DONE';
8246 ELSE
8247 DELETE mtl_material_transactions_temp
8248 WHERE transaction_temp_id = l_transaction_temp_id;
8249
8250 g_current_drop_lpn.current_drop_list.DELETE(l_transaction_temp_id);
8251
8252 IF l_debug = 1 THEN
8253 print_debug
8254 ( 'Deleted temp ID: ' || to_char(l_transaction_temp_id)
8255 , l_api_name
8256 );
8257 END IF;
8258 END IF;
8259
8260 IF ii < jj THEN
8261 ii := l_temp_tbl.NEXT(ii);
8262 l_transaction_temp_id := l_temp_tbl(ii);
8263 ELSE
8264 EXIT;
8265 END IF;
8266
8267 IF l_debug = 1 THEN
8268 print_debug
8269 ( 'Fetched next temp ID: ' || to_char(l_transaction_temp_id)
8270 , l_api_name
8271 );
8272 END IF;
8273 END LOOP;
8274
8275 END IF; -- end if l_temp_tbl.COUNT > 0
8276
8277 l_temp_tbl.DELETE;
8278
8279 EXCEPTION
8280 WHEN fnd_api.g_exc_error THEN
8281 ROLLBACK to validate_xfer_sp;
8282
8283 x_return_status := fnd_api.g_ret_sts_error;
8284
8285 fnd_msg_pub.count_and_get
8286 ( p_count => l_msg_count
8287 , p_data => l_msg_data
8288 , p_encoded => fnd_api.g_false
8289 );
8290
8291 IF l_debug = 1 THEN
8292 print_debug (l_msg_data, l_api_name);
8293 END IF;
8294
8295 WHEN OTHERS THEN
8296 ROLLBACK to validate_xfer_sp;
8297
8298 x_return_status := fnd_api.g_ret_sts_unexp_error;
8299
8300 IF l_debug = 1 THEN
8301 print_debug ('Other error: ' || sqlerrm, l_api_name);
8302 END IF;
8303
8304 END validate_xfer_to_lpn;
8305
8306
8307
8308 PROCEDURE insert_mmtt_pack
8309 ( x_pack_temp_id OUT NOCOPY NUMBER
8310 , x_return_status OUT NOCOPY VARCHAR2
8311 , p_parent_temp_id IN NUMBER
8312 , p_lpn_id IN NUMBER
8313 , p_outer_lpn_id IN NUMBER
8314 ) IS
8315
8316 l_api_name VARCHAR2(30) := 'insert_mmtt_pack';
8317 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
8318
8319 l_msg_count NUMBER;
8320 l_msg_data VARCHAR2(2000);
8321
8322 l_child_temp_id NUMBER;
8323 l_pack_temp_id NUMBER;
8324
8325 BEGIN
8326 x_return_status := fnd_api.g_ret_sts_success;
8327
8328 IF l_debug = 1 THEN
8329 print_debug
8330 ( 'Entered with parameters: ' || g_newline ||
8331 'p_parent_temp_id => ' || to_char(p_parent_temp_id) || g_newline ||
8332 'p_lpn_id => ' || to_char(p_lpn_id) || g_newline ||
8333 'p_outer_lpn_id => ' || to_char(p_outer_lpn_id)
8334 , l_api_name
8335 );
8336 END IF;
8337
8338 SAVEPOINT insert_pack_sp;
8339
8340 BEGIN
8341 SELECT mmtt.transaction_temp_id
8342 INTO l_child_temp_id
8343 FROM mtl_material_transactions_temp mmtt
8344 WHERE mmtt.parent_line_id = p_parent_temp_id
8345 AND mmtt.parent_line_id <> mmtt.transaction_temp_id
8346 AND ROWNUM < 2;
8347
8348 IF l_debug = 1 THEN
8349 print_debug
8350 ( 'Found child temp ID: ' || to_char(l_child_temp_id)
8351 , l_api_name
8352 );
8353 END IF;
8354
8355 EXCEPTION
8356 WHEN OTHERS THEN
8357 IF l_debug = 1 THEN
8358 print_debug
8359 ( 'Exception fetching child temp ID: ' || sqlerrm
8360 , l_api_name
8361 );
8362 END IF;
8363 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8364 END;
8365
8366 SELECT mtl_material_transactions_s.NEXTVAL
8367 INTO l_pack_temp_id
8368 FROM DUAL;
8369
8370 IF l_debug = 1 THEN
8371 print_debug
8372 ( 'About to insert pack txn with temp ID: '
8373 || to_char(l_pack_temp_id)
8374 , l_api_name
8375 );
8376 END IF;
8377
8378 INSERT INTO mtl_material_transactions_temp
8379 ( transaction_header_id
8380 , transaction_temp_id
8381 , source_code
8382 , source_line_id
8383 , transaction_mode
8384 , lock_flag
8385 , last_update_date
8386 , last_updated_by
8387 , creation_date
8388 , created_by
8389 , last_update_login
8390 , request_id
8391 , program_application_id
8392 , program_id
8393 , program_update_date
8394 , inventory_item_id
8395 , revision
8396 , organization_id
8397 , subinventory_code
8398 , locator_id
8399 , transaction_quantity
8400 , primary_quantity
8401 , transaction_uom
8402 , transaction_cost
8403 , transaction_type_id
8404 , transaction_action_id
8405 , transaction_source_type_id
8406 , transaction_source_id
8407 , transaction_source_name
8408 , transaction_date
8409 , acct_period_id
8410 , distribution_account_id
8411 , transaction_reference
8412 , requisition_line_id
8413 , requisition_distribution_id
8414 , reason_id
8415 , lot_number
8416 , lot_expiration_date
8417 , serial_number
8418 , receiving_document
8419 , demand_id
8420 , rcv_transaction_id
8421 , move_transaction_id
8422 , completion_transaction_id
8423 , wip_entity_type
8424 , schedule_id
8425 , repetitive_line_id
8426 , employee_code
8427 , primary_switch
8428 , schedule_update_code
8429 , setup_teardown_code
8430 , item_ordering
8431 , negative_req_flag
8432 , operation_seq_num
8433 , picking_line_id
8434 , trx_source_line_id
8435 , trx_source_delivery_id
8436 , physical_adjustment_id
8437 , cycle_count_id
8438 , rma_line_id
8439 , customer_ship_id
8440 , currency_code
8441 , currency_conversion_rate
8442 , currency_conversion_type
8443 , currency_conversion_date
8444 , ussgl_transaction_code
8445 , vendor_lot_number
8446 , encumbrance_account
8447 , encumbrance_amount
8448 , ship_to_location
8449 , shipment_number
8450 , transfer_cost
8451 , transportation_cost
8452 , transportation_account
8453 , freight_code
8454 , containers
8455 , waybill_airbill
8456 , expected_arrival_date
8457 , transfer_subinventory
8458 , transfer_organization
8459 , transfer_to_location
8460 , new_average_cost
8461 , value_change
8462 , percentage_change
8463 , material_allocation_temp_id
8464 , demand_source_header_id
8465 , demand_source_line
8466 , demand_source_delivery
8467 , item_segments
8468 , item_description
8469 , item_trx_enabled_flag
8470 , item_location_control_code
8471 , item_restrict_subinv_code
8472 , item_restrict_locators_code
8473 , item_revision_qty_control_code
8474 , item_primary_uom_code
8475 , item_uom_class
8476 , item_shelf_life_code
8477 , item_shelf_life_days
8478 , item_lot_control_code
8479 , item_serial_control_code
8480 , item_inventory_asset_flag
8481 , allowed_units_lookup_code
8482 , department_id
8483 , department_code
8484 , wip_supply_type
8485 , supply_subinventory
8486 , supply_locator_id
8487 , valid_subinventory_flag
8488 , valid_locator_flag
8489 , locator_segments
8490 , current_locator_control_code
8491 , number_of_lots_entered
8492 , wip_commit_flag
8493 , next_lot_number
8494 , lot_alpha_prefix
8495 , next_serial_number
8496 , serial_alpha_prefix
8497 , shippable_flag
8498 , posting_flag
8499 , required_flag
8500 , process_flag
8501 , ERROR_CODE
8502 , error_explanation
8503 , attribute_category
8504 , attribute1
8505 , attribute2
8506 , attribute3
8507 , attribute4
8508 , attribute5
8509 , attribute6
8510 , attribute7
8511 , attribute8
8512 , attribute9
8513 , attribute10
8514 , attribute11
8515 , attribute12
8516 , attribute13
8517 , attribute14
8518 , attribute15
8519 , movement_id
8520 , reservation_quantity
8521 , shipped_quantity
8522 , transaction_line_number
8523 , task_id
8524 , to_task_id
8525 , source_task_id
8526 , project_id
8527 , source_project_id
8528 , pa_expenditure_org_id
8529 , to_project_id
8530 , expenditure_type
8531 , final_completion_flag
8532 , transfer_percentage
8533 , transaction_sequence_id
8534 , material_account
8535 , material_overhead_account
8536 , resource_account
8537 , outside_processing_account
8538 , overhead_account
8539 , flow_schedule
8540 , cost_group_id
8541 , demand_class
8542 , qa_collection_id
8543 , kanban_card_id
8544 , overcompletion_transaction_id
8545 , overcompletion_primary_qty
8546 , overcompletion_transaction_qty
8547 , end_item_unit_number
8548 , scheduled_payback_date
8549 , line_type_code
8550 , parent_transaction_temp_id
8551 , put_away_strategy_id
8552 , put_away_rule_id
8553 , pick_strategy_id
8554 , pick_rule_id
8555 , common_bom_seq_id
8556 , common_routing_seq_id
8557 , cost_type_id
8558 , org_cost_group_id
8559 , move_order_line_id
8560 , task_group_id
8561 , pick_slip_number
8562 , reservation_id
8563 , transaction_status
8564 , transfer_cost_group_id
8565 , lpn_id
8566 , transfer_lpn_id
8567 , content_lpn_id
8568 , operation_plan_id
8569 , transaction_batch_id
8570 , transaction_batch_seq
8571 )
8572 (SELECT transaction_header_id
8573 , l_pack_temp_id
8574 , source_code
8575 , source_line_id
8576 , transaction_mode
8577 , lock_flag
8578 , last_update_date
8579 , last_updated_by
8580 , creation_date
8581 , created_by
8582 , last_update_login
8583 , request_id
8584 , program_application_id
8585 , program_id
8586 , program_update_date
8587 , inventory_item_id
8588 , revision
8589 , organization_id
8590 , transfer_subinventory
8591 , transfer_to_location
8592 , 1
8593 , 1
8594 , transaction_uom
8595 , transaction_cost
8596 , INV_GLOBALS.G_TYPE_CONTAINER_PACK
8597 , INV_GLOBALS.G_ACTION_CONTAINERPACK
8598 , INV_GLOBALS.G_SOURCETYPE_INVENTORY
8599 , NULL
8600 , NULL
8601 , SYSDATE
8602 , acct_period_id
8603 , distribution_account_id
8604 , transaction_reference
8605 , requisition_line_id
8606 , requisition_distribution_id
8607 , reason_id
8608 , lot_number
8609 , lot_expiration_date
8610 , serial_number
8611 , receiving_document
8612 , demand_id
8613 , rcv_transaction_id
8614 , move_transaction_id
8615 , completion_transaction_id
8616 , wip_entity_type
8617 , schedule_id
8618 , repetitive_line_id
8619 , employee_code
8620 , primary_switch
8621 , schedule_update_code
8622 , setup_teardown_code
8623 , item_ordering
8624 , negative_req_flag
8625 , operation_seq_num
8626 , picking_line_id
8627 , trx_source_line_id
8628 , trx_source_delivery_id
8629 , physical_adjustment_id
8630 , cycle_count_id
8631 , rma_line_id
8632 , customer_ship_id
8633 , currency_code
8634 , currency_conversion_rate
8635 , currency_conversion_type
8636 , currency_conversion_date
8637 , ussgl_transaction_code
8638 , vendor_lot_number
8639 , encumbrance_account
8640 , encumbrance_amount
8641 , ship_to_location
8642 , shipment_number
8643 , transfer_cost
8644 , transportation_cost
8645 , transportation_account
8646 , freight_code
8647 , containers
8648 , waybill_airbill
8649 , expected_arrival_date
8650 , transfer_subinventory
8651 , transfer_organization
8652 , transfer_to_location
8653 , new_average_cost
8654 , value_change
8655 , percentage_change
8656 , material_allocation_temp_id
8657 , demand_source_header_id
8658 , demand_source_line
8659 , demand_source_delivery
8660 , item_segments
8661 , item_description
8662 , item_trx_enabled_flag
8663 , item_location_control_code
8664 , item_restrict_subinv_code
8665 , item_restrict_locators_code
8666 , item_revision_qty_control_code
8667 , item_primary_uom_code
8668 , item_uom_class
8669 , item_shelf_life_code
8670 , item_shelf_life_days
8671 , item_lot_control_code
8672 , item_serial_control_code
8673 , item_inventory_asset_flag
8674 , allowed_units_lookup_code
8675 , department_id
8676 , department_code
8677 , wip_supply_type
8678 , supply_subinventory
8679 , supply_locator_id
8680 , valid_subinventory_flag
8681 , valid_locator_flag
8682 , locator_segments
8683 , current_locator_control_code
8684 , number_of_lots_entered
8685 , wip_commit_flag
8686 , next_lot_number
8687 , lot_alpha_prefix
8688 , next_serial_number
8689 , serial_alpha_prefix
8690 , shippable_flag
8691 , posting_flag
8692 , required_flag
8693 , process_flag
8694 , ERROR_CODE
8695 , error_explanation
8696 , attribute_category
8697 , attribute1
8698 , attribute2
8699 , attribute3
8700 , attribute4
8701 , attribute5
8702 , attribute6
8703 , attribute7
8704 , attribute8
8705 , attribute9
8706 , attribute10
8707 , attribute11
8708 , attribute12
8709 , attribute13
8710 , attribute14
8711 , attribute15
8712 , movement_id
8713 , reservation_quantity
8714 , shipped_quantity
8715 , transaction_line_number
8716 , task_id
8717 , to_task_id
8718 , source_task_id
8719 , project_id
8720 , source_project_id
8721 , pa_expenditure_org_id
8722 , to_project_id
8723 , expenditure_type
8724 , final_completion_flag
8725 , transfer_percentage
8726 , transaction_sequence_id
8727 , material_account
8728 , material_overhead_account
8729 , resource_account
8730 , outside_processing_account
8731 , overhead_account
8732 , flow_schedule
8733 , cost_group_id
8734 , demand_class
8735 , qa_collection_id
8736 , kanban_card_id
8737 , overcompletion_transaction_id
8738 , overcompletion_primary_qty
8739 , overcompletion_transaction_qty
8740 , end_item_unit_number
8741 , scheduled_payback_date
8742 , line_type_code
8743 , parent_transaction_temp_id
8744 , put_away_strategy_id
8745 , put_away_rule_id
8746 , pick_strategy_id
8747 , pick_rule_id
8748 , common_bom_seq_id
8749 , common_routing_seq_id
8750 , cost_type_id
8751 , org_cost_group_id
8752 , NULL
8753 , task_group_id
8754 , pick_slip_number
8755 , NULL
8756 , 3
8757 , transfer_cost_group_id
8758 , NULL
8759 , p_outer_lpn_id
8760 , p_lpn_id
8761 , operation_plan_id
8762 , transaction_header_id
8763 , l_pack_temp_id
8764 FROM mtl_material_transactions_temp
8765 WHERE transaction_temp_id = l_child_temp_id
8766 );
8767
8768 x_pack_temp_id := l_pack_temp_id;
8769
8770 EXCEPTION
8771 WHEN fnd_api.g_exc_error THEN
8772 ROLLBACK to insert_pack_sp;
8773
8774 x_return_status := fnd_api.g_ret_sts_error;
8775
8776 fnd_msg_pub.count_and_get
8777 ( p_count => l_msg_count
8778 , p_data => l_msg_data
8779 , p_encoded => fnd_api.g_false
8780 );
8781
8782 IF l_debug = 1 THEN
8783 print_debug (l_msg_data, l_api_name);
8784 END IF;
8785
8786 WHEN OTHERS THEN
8787 ROLLBACK to insert_pack_sp;
8788
8789 x_return_status := fnd_api.g_ret_sts_unexp_error;
8790
8791 IF l_debug = 1 THEN
8792 print_debug ('Other error: ' || sqlerrm, l_api_name);
8793 END IF;
8794
8795 END insert_mmtt_pack;
8796
8797
8798
8799 PROCEDURE preprocess_bulk_drop
8800 ( x_temp_tbl OUT NOCOPY g_temp_id_tbl
8801 , x_pack_txn_exists OUT NOCOPY BOOLEAN
8802 , x_return_status OUT NOCOPY VARCHAR2
8803 , p_orgn_id IN NUMBER
8804 , p_xfer_lpn_id IN NUMBER
8805 , p_drop_lpn IN VARCHAR2
8806 ) IS
8807
8808 l_api_name VARCHAR2(30) := 'preprocess_bulk_drop';
8809 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
8810
8811 l_api_return_status VARCHAR2(1);
8812 l_msg_count NUMBER;
8813 l_msg_data VARCHAR2(2000);
8814
8815 l_parent_temp_id NUMBER;
8816 l_pack_temp_id NUMBER;
8817 l_outer_most_lpn_id NUMBER;
8818 ii NUMBER;
8819
8820 l_pack_txn_ok BOOLEAN;
8821 l_dummy VARCHAR2(1);
8822
8823
8824 CURSOR c_get_bulk_tasks
8825 ( p_org_id IN NUMBER
8826 , p_lpn_id IN NUMBER
8827 ) IS
8828 -- Material unpacked from nested LPNs
8829 SELECT mmtt.transaction_temp_id
8830 FROM mtl_material_transactions_temp mmtt
8831 WHERE mmtt.organization_id = p_org_id
8832 AND mmtt.transfer_lpn_id = p_lpn_id
8833 AND mmtt.parent_line_id IS NOT NULL
8834 AND mmtt.parent_line_id <> mmtt.transaction_temp_id
8835 AND mmtt.content_lpn_id IS NULL
8836 AND mmtt.lpn_id IS NOT NULL
8837 AND EXISTS
8838 ( SELECT 'x'
8839 FROM mtl_material_transactions_temp mmtt2
8840 WHERE mmtt2.organization_id = p_org_id
8841 AND mmtt2.transfer_lpn_id = p_lpn_id
8842 AND mmtt2.content_lpn_id = mmtt.lpn_id
8843 AND mmtt2.transaction_temp_id = mmtt2.parent_line_id
8844 AND mmtt2.parent_line_id <> mmtt.parent_line_id
8845 )
8846 UNION ALL
8847 -- Nested LPNs
8848 SELECT mmtt.transaction_temp_id
8849 FROM mtl_material_transactions_temp mmtt
8850 WHERE mmtt.organization_id = p_org_id
8851 AND mmtt.transfer_lpn_id = p_lpn_id
8852 AND mmtt.parent_line_id IS NOT NULL
8853 AND mmtt.parent_line_id <> mmtt.transaction_temp_id
8854 AND mmtt.content_lpn_id IS NULL
8855 AND mmtt.lpn_id IS NOT NULL
8856 AND EXISTS
8857 ( SELECT 'x'
8858 FROM mtl_material_transactions_temp mmtt2
8859 WHERE mmtt2.organization_id = p_org_id
8860 AND mmtt2.transfer_lpn_id = p_lpn_id
8861 AND mmtt2.content_lpn_id = mmtt.lpn_id
8862 AND mmtt2.transaction_temp_id = mmtt2.parent_line_id
8863 AND mmtt2.parent_line_id = mmtt.parent_line_id
8864 )
8865 UNION ALL
8866 -- Picked from LPN that is not a nested LPN
8867 SELECT mmtt.transaction_temp_id
8868 FROM mtl_material_transactions_temp mmtt
8869 WHERE mmtt.organization_id = p_org_id
8870 AND mmtt.transfer_lpn_id = p_lpn_id
8871 AND mmtt.parent_line_id IS NOT NULL
8872 AND mmtt.parent_line_id <> mmtt.transaction_temp_id
8873 AND mmtt.content_lpn_id IS NULL
8874 AND mmtt.lpn_id IS NOT NULL
8875 AND NOT EXISTS
8876 ( SELECT 'x'
8877 FROM mtl_material_transactions_temp mmtt2
8878 WHERE mmtt2.organization_id = p_org_id
8879 AND mmtt2.transfer_lpn_id = p_lpn_id
8880 AND mmtt2.content_lpn_id = mmtt.lpn_id
8881 AND mmtt2.transaction_temp_id = mmtt2.parent_line_id
8882 )
8883 UNION ALL
8884 -- Loose material
8885 SELECT mmtt.transaction_temp_id
8886 FROM mtl_material_transactions_temp mmtt
8887 WHERE mmtt.organization_id = p_org_id
8888 AND mmtt.transfer_lpn_id = p_lpn_id
8889 AND mmtt.parent_line_id IS NOT NULL
8890 AND mmtt.parent_line_id <> mmtt.transaction_temp_id
8891 AND mmtt.content_lpn_id IS NULL
8892 AND mmtt.lpn_id IS NULL;
8893
8894
8895 CURSOR c_get_nested_lpns
8896 ( p_org_id IN NUMBER
8897 , p_lpn_id IN NUMBER
8898 ) IS
8899 SELECT mmtt.transaction_temp_id
8900 , mmtt.content_lpn_id
8901 FROM mtl_material_transactions_temp mmtt
8902 WHERE mmtt.organization_id = p_org_id
8903 AND mmtt.transfer_lpn_id = p_lpn_id
8904 AND mmtt.parent_line_id = mmtt.transaction_temp_id
8905 AND mmtt.content_lpn_id IS NOT NULL;
8906
8907
8908 CURSOR c_chk_child_records
8909 ( p_parent_temp_id IN NUMBER
8910 ) IS
8911 SELECT 'x'
8912 FROM mtl_material_transactions_temp mmtt
8913 WHERE mmtt.parent_line_id = p_parent_temp_id
8914 AND mmtt.parent_line_id <> mmtt.transaction_temp_id
8915 AND mmtt.transaction_action_id in (2,28)
8916 AND EXISTS
8917 ( SELECT 'x'
8918 FROM mtl_secondary_inventories msi
8919 WHERE msi.secondary_inventory_name = mmtt.transfer_subinventory
8920 AND msi.organization_id = mmtt.organization_id
8921 AND NVL(msi.disable_date,sysdate + 1)
8922 > sysdate
8923 AND msi.lpn_controlled_flag = 1
8924 );
8925
8926
8927 BEGIN
8928 x_return_status := fnd_api.g_ret_sts_success;
8929
8930 IF l_debug = 1 THEN
8931 print_debug
8932 ( 'Entered with parameters: ' || g_newline ||
8933 'p_orgn_id => ' || to_char(p_orgn_id) || g_newline ||
8934 'p_xfer_lpn_id => ' || to_char(p_xfer_lpn_id)
8935 , l_api_name
8936 );
8937 END IF;
8938
8939 x_pack_txn_exists := FALSE;
8940
8941 SAVEPOINT preprocess_bulk_sp;
8942
8943 OPEN c_get_bulk_tasks (p_orgn_id, p_xfer_lpn_id);
8944 FETCH c_get_bulk_tasks BULK COLLECT INTO x_temp_tbl;
8945 CLOSE c_get_bulk_tasks;
8946
8947 IF NOT (x_temp_tbl.COUNT > 0)
8948 THEN
8949 IF l_debug = 1 THEN
8950 print_debug ('c_get_bulk_tasks returned no MMTT records', l_api_name);
8951 END IF;
8952 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
8953 END IF;
8954
8955 --
8956 -- Process nested LPNs:
8957 -- Update transfer_lpn_id on child records
8958 -- Update LPN context
8959 -- Insert pack transactions
8960 -- Add pack transaction to x_temp_tbl
8961 --
8962 FOR nested_lpn_rec IN c_get_nested_lpns (p_orgn_id, p_xfer_lpn_id)
8963 LOOP
8964 l_pack_txn_ok := FALSE;
8965 BEGIN
8966 IF l_debug = 1
8967 THEN
8968 print_debug
8969 ('Processing parent temp ID: '
8970 || to_char(nested_lpn_rec.transaction_temp_id)
8971 || ', with content LPN ID: '
8972 || to_char(nested_lpn_rec.content_lpn_id)
8973 , l_api_name
8974 );
8975 END IF;
8976
8977 -- Start change for Bug 5620764
8978 -- This is not required, since entire LPN is being consumed
8979 --UPDATE wms_license_plate_numbers wlpn
8980 -- SET wlpn.lpn_context = WMS_Container_PUB.LPN_CONTEXT_INV
8981 -- WHERE wlpn.lpn_id = nested_lpn_rec.content_lpn_id
8982 -- AND wlpn.lpn_context = WMS_Container_PUB.LPN_CONTEXT_PACKING
8983 -- AND wlpn.organization_id = p_orgn_id;
8984
8985 --IF l_debug = 1 AND SQL%FOUND
8986 --THEN
8987 -- print_debug
8988 -- ('Updated LPN context from packing to INV for LPN ID '
8989 -- || to_char(nested_lpn_rec.content_lpn_id)
8990 -- , l_api_name
8991 -- );
8992 --END IF;
8993 -- End change for Bug 5620764
8994
8995 OPEN c_chk_child_records (nested_lpn_rec.transaction_temp_id);
8996 FETCH c_chk_child_records INTO l_dummy;
8997
8998 IF c_chk_child_records%FOUND
8999 THEN
9000 l_pack_txn_ok := TRUE;
9001 END IF;
9002
9003 CLOSE c_chk_child_records;
9004
9005 IF nested_lpn_rec.content_lpn_id <> p_xfer_lpn_id
9006 THEN
9007 UPDATE mtl_material_transactions_temp mmtt
9008 SET mmtt.transfer_lpn_id = nested_lpn_rec.content_lpn_id
9009 , mmtt.lpn_id = NVL(mmtt.lpn_id,nested_lpn_rec.content_lpn_id) -- Bug 5620764
9010 WHERE mmtt.parent_line_id = nested_lpn_rec.transaction_temp_id
9011 AND mmtt.parent_line_id <> mmtt.transaction_temp_id;
9012
9013 IF l_debug = 1 AND SQL%FOUND
9014 THEN
9015 print_debug
9016 ('Updated transfer LPN on child records for parent '
9017 || to_char(nested_lpn_rec.transaction_temp_id)
9018 , l_api_name
9019 );
9020 END IF;
9021
9022 IF l_pack_txn_ok
9023 THEN
9024 l_api_return_status := fnd_api.g_ret_sts_success;
9025 insert_mmtt_pack
9026 ( x_pack_temp_id => l_pack_temp_id
9027 , x_return_status => l_api_return_status
9028 , p_parent_temp_id => nested_lpn_rec.transaction_temp_id
9029 , p_lpn_id => nested_lpn_rec.content_lpn_id
9030 , p_outer_lpn_id => p_xfer_lpn_id
9031 );
9032
9033 IF l_api_return_status <> fnd_api.g_ret_sts_success
9034 THEN
9035 IF l_debug = 1 THEN
9036 print_debug ('insert_mmtt_pack returned an error', l_api_name);
9037 END IF;
9038 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9039 END IF;
9040
9041 ii := x_temp_tbl.LAST + 1;
9042 x_temp_tbl(ii) := l_pack_temp_id;
9043
9044 IF l_debug = 1
9045 THEN
9046 print_debug
9047 ('Added packing txn temp ID ' || to_char(l_pack_temp_id) ||
9048 ' to x_temp_tbl at index ' || to_char(ii)
9049 , l_api_name
9050 );
9051 END IF;
9052
9053 IF NOT x_pack_txn_exists
9054 THEN
9055 x_pack_txn_exists := TRUE;
9056 l_parent_temp_id := nested_lpn_rec.transaction_temp_id;
9057 END IF;
9058 END IF; -- end if l_pack_txn_ok
9059 END IF; -- end if content_lpn_id <> p_xfer_lpn_id
9060
9061 EXCEPTION
9062 WHEN OTHERS THEN
9063 IF l_debug = 1 THEN
9064 print_debug
9065 ( 'Exception processing nested LPNs: ' || sqlerrm
9066 , l_api_name
9067 );
9068 END IF;
9069 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9070
9071 END;
9072 END LOOP;
9073
9074 IF x_pack_txn_exists
9075 AND
9076 p_drop_lpn IS NOT NULL
9077 THEN
9078 BEGIN
9079 SELECT wlpn.lpn_id
9080 INTO l_outer_most_lpn_id
9081 FROM wms_license_plate_numbers wlpn
9082 WHERE wlpn.license_plate_number = p_drop_lpn;
9083
9084 IF l_debug = 1
9085 THEN
9086 print_debug
9087 ('Drop LPN ' || p_drop_lpn ||
9088 ' has ID ' || to_char(l_outer_most_lpn_id)
9089 , l_api_name
9090 );
9091 END IF;
9092
9093 EXCEPTION
9094 WHEN OTHERS THEN
9095 IF l_debug = 1 THEN
9096 print_debug
9097 ( 'Exception getting outermost LPN ID: ' || sqlerrm
9098 , l_api_name
9099 );
9100 END IF;
9101 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9102 END;
9103
9104 l_api_return_status := fnd_api.g_ret_sts_success;
9105 insert_mmtt_pack
9106 ( x_pack_temp_id => l_pack_temp_id
9107 , x_return_status => l_api_return_status
9108 , p_parent_temp_id => l_parent_temp_id
9109 , p_lpn_id => p_xfer_lpn_id
9110 , p_outer_lpn_id => l_outer_most_lpn_id
9111 );
9112
9113 IF l_api_return_status <> fnd_api.g_ret_sts_success
9114 THEN
9115 IF l_debug = 1 THEN
9116 print_debug ('insert_mmtt_pack returned an error', l_api_name);
9117 END IF;
9118 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9119 END IF;
9120
9121 ii := x_temp_tbl.LAST + 1;
9122 x_temp_tbl(ii) := l_pack_temp_id;
9123
9124 IF l_debug = 1
9125 THEN
9126 print_debug
9127 ('Added packing txn temp ID ' || to_char(l_pack_temp_id) ||
9128 ' to x_temp_tbl at index ' || to_char(ii)
9129 , l_api_name
9130 );
9131 END IF;
9132 END IF;
9133
9134 EXCEPTION
9135 WHEN fnd_api.g_exc_error THEN
9136 ROLLBACK TO preprocess_bulk_sp;
9137
9138 x_return_status := fnd_api.g_ret_sts_error;
9139
9140 fnd_msg_pub.count_and_get
9141 ( p_count => l_msg_count
9142 , p_data => l_msg_data
9143 , p_encoded => fnd_api.g_false
9144 );
9145
9146 IF l_debug = 1 THEN
9147 print_debug (l_msg_data, l_api_name);
9148 END IF;
9149
9150 WHEN OTHERS THEN
9151 ROLLBACK TO preprocess_bulk_sp;
9152
9153 x_return_status := fnd_api.g_ret_sts_unexp_error;
9154
9155 IF l_debug = 1 THEN
9156 print_debug ('Other error: ' || sqlerrm, l_api_name);
9157 END IF;
9158
9159 END preprocess_bulk_drop;
9160
9161
9162
9163 PROCEDURE pick_drop
9164 ( x_return_status OUT NOCOPY VARCHAR2
9165 , p_organization_id IN NUMBER
9166 , p_transfer_lpn_id IN NUMBER
9167 , p_emp_id IN NUMBER
9168 , p_drop_lpn IN VARCHAR2
9169 , p_orig_subinv IN VARCHAR2
9170 , p_subinventory IN VARCHAR2
9171 , p_orig_locid IN VARCHAR2
9172 , p_loc_id IN NUMBER
9173 , p_reason_id IN NUMBER
9174 , p_task_type IN NUMBER
9175 , p_outer_lpn_done IN VARCHAR2
9176 , p_bulk_drop IN VARCHAR2
9177 ) IS
9178
9179 l_api_name VARCHAR2(30) := 'pick_drop';
9180 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
9181
9182 l_api_return_status VARCHAR2(1);
9183 l_msg_count NUMBER;
9184 l_msg_data VARCHAR2(2000);
9185 l_ok_to_process VARCHAR2(10) := NULL;
9186 l_dummy VARCHAR2(1) := NULL;
9187 l_srl_stat VARCHAR2(1) := NULL;
9188
9189 l_temp_tbl g_temp_id_tbl;
9190 l_task_tbl g_temp_id_tbl;
9191
9192 l_txn_header_id NUMBER;
9193 l_transaction_temp_id NUMBER;
9194 l_first_temp_id NUMBER;
9195 l_task_id NUMBER;
9196 l_parent_line_id NUMBER;
9197 l_txn_type_id NUMBER;
9198 l_parent_task_id NUMBER;
9199 l_parent_txn_id NUMBER;
9200 l_curr_xfer_lpn_id NUMBER;
9201 l_next_xfer_lpn_id NUMBER;
9202 l_batch_seq_id NUMBER;
9203
9204 l_inventory_item_id NUMBER;
9205 l_transaction_qty NUMBER;
9206 l_transaction_uom VARCHAR2(3);
9207
9208 ii NUMBER;
9209 jj NUMBER;
9210 kk NUMBER;
9211
9212 l_parent_done BOOLEAN;
9213 l_curr_lpn_done BOOLEAN;
9214 l_xfer_lpn_used BOOLEAN;
9215 l_pack_txn_exists BOOLEAN;
9216
9217
9218 -- MDC variables
9219 l_allow_packing VARCHAR2(1);
9220 l_to_loc_type NUMBER;
9221 l_drop_lpn_id NUMBER;
9222 l_move_order_type NUMBER;
9223 l_move_order_line_id NUMBER;
9224 l_line_status NUMBER;
9225 l_xfer_to_lpn_id NUMBER; --added for bug 10139672
9226
9227 CURSOR c_get_nonbulk_tasks -- Modified for bug#9247514
9228 ( p_org_id IN NUMBER
9229 , p_lpn_id IN NUMBER
9230 ) IS
9231 SELECT mmtt.transaction_temp_id --bug#6323330. Added org,item,revision,sub,loc in SELECT clause.
9232 FROM (
9233 -- Material unpacked from nested LPNs
9234 SELECT mmtt.transaction_temp_id,
9235 mmtt.organization_id,
9236 mmtt.inventory_item_id,
9237 mmtt.revision ,
9238 mmtt.subinventory_code,
9239 mmtt.locator_id,
9240 mmtt.transaction_date
9241 FROM mtl_material_transactions_temp mmtt
9242 WHERE mmtt.organization_id = p_org_id
9243 AND mmtt.transfer_lpn_id = p_lpn_id
9244 AND mmtt.parent_line_id IS NULL
9245 AND mmtt.content_lpn_id IS NULL
9246 AND mmtt.lpn_id IS NOT NULL
9247 AND EXISTS
9248 ( SELECT 'x'
9249 FROM mtl_material_transactions_temp mmtt2
9250 WHERE mmtt2.organization_id = p_org_id
9251 AND mmtt2.transfer_lpn_id = p_lpn_id
9252 AND mmtt2.content_lpn_id = mmtt.lpn_id
9253 AND mmtt2.transaction_temp_id <> mmtt.transaction_temp_id
9254 )
9255 UNION ALL
9256 -- Nested LPNs
9257 SELECT mmtt.transaction_temp_id ,
9258 mmtt.organization_id,
9259 mmtt.inventory_item_id,
9260 mmtt.revision ,
9261 mmtt.subinventory_code,
9262 mmtt.locator_id,
9263 mmtt.transaction_date
9264 FROM mtl_material_transactions_temp mmtt
9265 WHERE mmtt.organization_id = p_org_id
9266 AND mmtt.transfer_lpn_id = p_lpn_id
9267 AND mmtt.parent_line_id IS NULL
9268 AND mmtt.content_lpn_id IS NOT NULL
9269 UNION ALL
9270 -- Picked from LPN that is not a nested LPN
9271 SELECT mmtt.transaction_temp_id,
9272 mmtt.organization_id,
9273 mmtt.inventory_item_id,
9274 mmtt.revision ,
9275 mmtt.subinventory_code,
9276 mmtt.locator_id,
9277 mmtt.transaction_date
9278 FROM mtl_material_transactions_temp mmtt
9279 WHERE mmtt.organization_id = p_org_id
9280 AND mmtt.transfer_lpn_id = p_lpn_id
9281 AND mmtt.parent_line_id IS NULL
9282 AND mmtt.content_lpn_id IS NULL
9283 AND mmtt.lpn_id IS NOT NULL
9284 AND NOT EXISTS
9285 ( SELECT 'x'
9286 FROM mtl_material_transactions_temp mmtt2
9287 WHERE mmtt2.organization_id = p_org_id
9288 AND mmtt2.transfer_lpn_id = p_lpn_id
9289 AND mmtt2.content_lpn_id = mmtt.lpn_id
9290 AND mmtt2.transaction_temp_id <> mmtt.transaction_temp_id
9291 )
9292 UNION ALL
9293 --Added for Bug 6717052
9294 SELECT mmtt.transaction_temp_id ,
9295 mmtt.organization_id,
9296 mmtt.inventory_item_id,
9297 mmtt.revision ,
9298 mmtt.subinventory_code,
9299 mmtt.locator_id,
9300 mmtt.transaction_date
9301 FROM mtl_material_transactions_temp mmtt
9302 WHERE mmtt.organization_id = p_org_id
9303 AND mmtt.transfer_lpn_id IN (SELECT lpn_id FROM wms_license_plate_numbers
9304 WHERE outermost_lpn_id = p_lpn_id AND lpn_id <> outermost_lpn_id)
9305 AND mmtt.parent_line_id IS NULL
9306 UNION ALL
9307 -- Loose material
9308 SELECT mmtt.transaction_temp_id,
9309 mmtt.organization_id,
9310 mmtt.inventory_item_id,
9311 mmtt.revision ,
9312 mmtt.subinventory_code,
9313 mmtt.locator_id,
9314 mmtt.transaction_date
9315 FROM mtl_material_transactions_temp mmtt
9316 WHERE mmtt.organization_id = p_org_id
9317 AND mmtt.transfer_lpn_id = p_lpn_id
9318 AND mmtt.parent_line_id IS NULL
9319 AND mmtt.content_lpn_id IS NULL
9320 AND mmtt.lpn_id IS NULL
9321 ORDER BY 2,3,4,5,6,7 ) mmtt, wms_dispatched_tasks wdt
9322 WHERE mmtt.TRANSACTION_TEMP_ID=wdt.TRANSACTION_TEMP_ID(+)
9323 ORDER BY mmtt.organization_id,
9324 mmtt.inventory_item_id,
9325 mmtt.revision ,
9326 mmtt.subinventory_code,
9327 mmtt.locator_id,
9328 mmtt.transaction_date,
9329 wdt.loaded_time; --Bug#6267350 -- Modified for bug#9247514
9330
9331
9332
9333 CURSOR c_get_txn_info
9334 ( p_temp_id IN NUMBER
9335 ) IS
9336 SELECT mmtt.parent_line_id
9337 , mmtt.transaction_type_id
9338 FROM mtl_material_transactions_temp mmtt
9339 WHERE mmtt.transaction_temp_id = p_temp_id;
9340
9341
9342 CURSOR c_get_parent_tasks
9343 ( p_org_id IN NUMBER
9344 , p_lpn_id IN NUMBER
9345 ) IS
9346 SELECT mmtt.transaction_temp_id
9347 , wdt.task_id
9348 FROM mtl_material_transactions_temp mmtt
9349 , wms_dispatched_tasks wdt
9350 WHERE mmtt.organization_id = p_org_id
9351 AND mmtt.transfer_lpn_id = p_lpn_id
9352 AND mmtt.parent_line_id IS NOT NULL
9353 AND mmtt.parent_line_id = mmtt.transaction_temp_id
9354 AND wdt.transaction_temp_id = mmtt.transaction_temp_id;
9355
9356
9357 CURSOR c_get_srl_alloc_stat
9358 ( p_temp_id IN NUMBER
9359 ) IS
9360 SELECT mmtt.serial_allocated_flag
9361 FROM mtl_material_transactions_temp mmtt
9362 WHERE transaction_temp_id = p_temp_id;
9363
9364 BEGIN
9365 x_return_status := fnd_api.g_ret_sts_success;
9366
9367 IF l_debug = 1 THEN
9368 print_debug
9369 ( '...Entered with parameters: ' || g_newline ||
9370 'p_organization_id => ' || to_char(p_organization_id) || g_newline ||
9371 'p_transfer_lpn_id => ' || to_char(p_transfer_lpn_id) || g_newline ||
9372 'p_emp_id => ' || to_char(p_emp_id) || g_newline ||
9373 'p_drop_lpn => ' || p_drop_lpn || g_newline ||
9374 'p_orig_subinv => ' || p_orig_subinv || g_newline ||
9375 'p_subinventory => ' || p_subinventory || g_newline ||
9376 'p_orig_locid => ' || p_orig_locid || g_newline ||
9377 'p_loc_id => ' || to_char(p_loc_id) || g_newline ||
9378 'p_reason_id => ' || to_char(p_reason_id) || g_newline ||
9379 'p_task_type => ' || to_char(p_task_type) || g_newline ||
9380 'p_outer_lpn_done => ' || p_outer_lpn_done || g_newline ||
9381 'p_bulk_drop => ' || to_char(p_bulk_drop)
9382 , l_api_name
9383 );
9384 END IF;
9385
9386 SAVEPOINT pick_drop_sp;
9387
9388 IF p_drop_lpn IS NOT NULL THEN
9389 IF l_debug = 1 THEN print_debug ('find l_drop_lpn_id: ' , l_api_name); END IF;
9390 BEGIN
9391 SELECT wlpn.lpn_id
9392 INTO l_drop_lpn_id
9393 FROM wms_license_plate_numbers wlpn
9394 WHERE wlpn.license_plate_number = p_drop_lpn
9395 AND wlpn.organization_id = p_organization_id
9396 AND ROWNUM=1;
9397 IF l_debug = 1 THEN print_debug ('find l_drop_lpn_id: ' || l_drop_lpn_id , l_api_name); END IF;
9398 EXCEPTION
9399 WHEN NO_DATA_FOUND THEN
9400 IF l_debug = 1 THEN
9401 print_debug ('l_drop_lpn_id: not found ' , l_api_name);
9402 print_debug ('Drop LPN is new.' || p_drop_lpn, l_api_name);
9403 END IF;
9404
9405 /* mrana: Bug: 5049145 : If drop LPN is a user-keyed in value, we still
9406 * need to do MDC validations and for that we must create this LPN before
9407 * calling MDC API */
9408 -- Start of 5049145
9409 wms_container_pub.create_lpn
9410 ( p_api_version => 1.0
9411 , x_return_status => l_api_return_status
9412 , x_msg_count => l_msg_count
9413 , x_msg_data => l_msg_data
9414 , p_lpn => p_drop_lpn
9415 , p_organization_id => p_organization_id
9416 , x_lpn_id => l_drop_lpn_id
9417 , p_source => wms_container_pub.lpn_context_pregenerated
9418 );
9419
9420 IF l_api_return_status <> fnd_api.g_ret_sts_success
9421 THEN
9422 IF l_debug = 1 THEN
9423 print_debug
9424 ( 'Error from WMS_Container_PUB.create_lpn: ' || l_msg_data
9425 , l_api_name);
9426 END IF;
9427 RAISE FND_API.G_EXC_ERROR;
9428 ELSE
9429 IF l_debug = 1 THEN
9430 print_debug
9431 ( 'WMS_Container_PUB.create_lpn returned LPN '
9432 || to_char(l_drop_lpn_id)
9433 , l_api_name);
9434 END IF;
9435 END IF;
9436 -- End of 5049145
9437 END ;
9438 END IF;
9439
9440 IF l_debug = 1 THEN
9441 print_debug ('l_drop_lpn_id: ' || l_drop_lpn_id , l_api_name);
9442 END IF;
9443
9444 -- Added the following if condition for bug 5186375
9445 IF l_drop_lpn_id IS NOT NULL AND
9446 l_drop_lpn_id <> 0
9447 THEN
9448
9449 --Start-Added the following for bug 10139672
9450 IF nvl(g_xfer_to_lpn_id,0) <> 0 AND
9451 g_xfer_to_lpn_id <> p_transfer_lpn_id
9452 THEN
9453 l_xfer_to_lpn_id := g_xfer_to_lpn_id;
9454 ELSE
9455 l_xfer_to_lpn_id := Nvl(p_transfer_lpn_id,0);
9456 END IF;
9457
9458 IF l_debug = 1 THEN
9459 print_debug ('xfer_to_lpn_id passed to wms_mdc_pvt.validate_to_lpn' || l_xfer_to_lpn_id , l_api_name);
9460 END IF;
9461 --END-Added the following for bug 10139672
9462
9463 wms_mdc_pvt.validate_to_lpn
9464 (--p_from_lpn_id => nvl(p_transfer_lpn_id,0),commented for bug 10139672
9465 p_from_lpn_id => nvl(l_xfer_to_lpn_id,0), --added for bug 10139672
9466 p_from_delivery_id => null,
9467 p_to_lpn_id => nvl(l_drop_lpn_id,0),
9468 p_is_from_to_delivery_same => 'U',
9469 p_to_sub => p_subinventory,
9470 p_to_locator_id => nvl(p_loc_id,0),
9471 x_allow_packing => l_allow_packing,
9472 x_return_status => l_api_return_status,
9473 x_msg_count => l_msg_count,
9474 x_msg_data => l_msg_data);
9475
9476 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
9477 IF l_debug = 1 THEN
9478 print_debug('Error from wms_mdc_pvt.validate_to_lpn: ' || l_msg_data, l_api_name);
9479 END IF;
9480 RAISE fnd_api.g_exc_error;
9481 ELSE
9482 IF l_debug = 1 THEN
9483 print_debug('wms_mdc_pvt.validate_to_lpn returned: ' || l_allow_packing, l_api_name);
9484 END IF;
9485
9486 IF l_allow_packing = 'N' THEN
9487 RAISE fnd_api.g_exc_error;
9488 END IF;
9489
9490 END IF;
9491
9492 IF l_allow_packing = 'C' THEN -- one of the from LPNs is a consol LPN
9493 IF p_drop_lpn IS NULL OR p_drop_lpn = 0 THEN
9494 BEGIN
9495 SELECT mil.inventory_location_type
9496 INTO l_to_loc_type
9497 FROM mtl_item_locations mil
9498 WHERE mil.organization_id = p_organization_id
9499 AND mil.subinventory_code = p_subinventory
9500 AND mil.inventory_location_id = p_loc_id;
9501 IF (l_debug = 1) THEN print_debug('l_to_loc_type' || l_to_loc_type , l_api_name); END IF;
9502 EXCEPTION WHEN NO_DATA_FOUND THEN
9503 IF (l_debug = 1) THEN print_debug('exception selecting to_loc_type', l_api_name ); END IF;
9504 RAISE FND_API.G_exc_unexpected_error;
9505 END ;
9506 IF l_to_loc_type <> inv_globals.g_loc_type_staging_lane THEN
9507 fnd_message.set_name('WMS', 'WMS_STAGE_FROM_CONSOL_LPN');
9508 fnd_msg_pub.ADD;
9509 IF l_debug = 1 THEN
9510 print_debug('WMS_STAGE_FROM_CONSOL_LPN : Destination Locator must be ' ||
9511 'staging locator when one of the From LPNs is a consol LPN'
9512 , l_api_name );
9513 -- {{- Destination Locator must be staging locator when one of the From LPNs is a consol LPN }}
9514
9515 END IF;
9516 RAISE fnd_api.g_exc_error;
9517 END IF ;
9518 END IF ;
9519 END IF;
9520 END IF;
9521
9522 fnd_msg_pub.initialize;
9523
9524 --
9525 -- Validate passed in Org and LPN
9526 --
9527 IF p_organization_id <> g_current_drop_lpn.organization_id
9528 OR
9529 p_transfer_lpn_id <> g_current_drop_lpn.lpn_id
9530 THEN
9531 IF l_debug = 1 THEN
9532 print_debug
9533 ( 'Passed in org or LPN did not match cached info: '
9534 || g_newline || 'p_organization_id: ' || to_char(p_organization_id)
9535 || g_newline || 'p_transfer_lpn_id: ' || to_char(p_transfer_lpn_id)
9536 || g_newline || 'Cached Org ID: ' || to_char(g_current_drop_lpn.organization_id)
9537 || g_newline || 'Cached LPN ID: ' || to_char(g_current_drop_lpn.lpn_id)
9538 , l_api_name
9539 );
9540 END IF;
9541 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9542 END IF;
9543
9544 l_pack_txn_exists := FALSE;
9545 IF l_debug = 1 THEN
9546 print_debug ('g_current_drop_lpn.multiple_drops ' || g_current_drop_lpn.multiple_drops, l_api_name);
9547 print_debug ('p_bulk_drop ' || p_bulk_drop, l_api_name);
9548 END IF;
9549 IF g_current_drop_lpn.multiple_drops = 'TRUE'
9550 THEN
9551 l_api_return_status := fnd_api.g_ret_sts_success;
9552 get_temp_list
9553 ( x_temp_tbl => l_temp_tbl
9554 , x_return_status => l_api_return_status
9555 , p_group_num => NULL
9556 , p_status => NULL
9557 );
9558
9559 IF l_api_return_status <> fnd_api.g_ret_sts_success
9560 THEN
9561 IF l_debug = 1 THEN
9562 print_debug ('Error from get_temp_list', l_api_name);
9563 END IF;
9564 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9565 END IF;
9566 l_xfer_lpn_used := FALSE;
9567 ELSE
9568 IF p_bulk_drop = 'TRUE'
9569 THEN
9570 l_api_return_status := fnd_api.g_ret_sts_success;
9571
9572 preprocess_bulk_drop
9573 ( x_temp_tbl => l_temp_tbl
9574 , x_pack_txn_exists => l_pack_txn_exists
9575 , x_return_status => l_api_return_status
9576 , p_orgn_id => p_organization_id
9577 , p_xfer_lpn_id => p_transfer_lpn_id
9578 , p_drop_lpn => p_drop_lpn
9579 );
9580
9581 IF l_api_return_status <> fnd_api.g_ret_sts_success
9582 THEN
9583 IF l_debug = 1 THEN
9584 print_debug ('Error from preprocess_bulk_drop', l_api_name);
9585 END IF;
9586 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9587 END IF;
9588 ELSE
9589 OPEN c_get_nonbulk_tasks (p_organization_id, p_transfer_lpn_id);
9590 FETCH c_get_nonbulk_tasks BULK COLLECT INTO l_temp_tbl;
9591 CLOSE c_get_nonbulk_tasks;
9592 END IF;
9593 l_xfer_lpn_used := TRUE;
9594 END IF;
9595
9596 WHILE l_temp_tbl.COUNT > 0
9597 LOOP
9598 ii := l_temp_tbl.FIRST;
9599 jj := l_temp_tbl.LAST;
9600
9601 l_batch_seq_id := 1;
9602
9603 IF l_debug = 1 THEN
9604 print_debug
9605 ( 'ii = ' || to_char(ii) || ', jj = ' || to_char(jj)
9606 , l_api_name
9607 );
9608 END IF;
9609
9610 l_transaction_temp_id := l_temp_tbl(ii);
9611 l_first_temp_id := l_transaction_temp_id;
9612
9613
9614 BEGIN
9615 SELECT mmtt.transfer_lpn_id,
9616 mmtt.inventory_item_id,
9617 mmtt.transaction_uom,
9618 mmtt.transaction_quantity
9619 INTO l_curr_xfer_lpn_id, l_inventory_item_id, l_transaction_uom, l_transaction_qty
9620 FROM mtl_material_transactions_temp mmtt
9621 WHERE mmtt.transaction_temp_id = l_transaction_temp_id;
9622
9623 IF l_debug = 1 THEN
9624 print_debug
9625 ('Temp ID ' || to_char(l_transaction_temp_id) ||
9626 ' has Xfer lpn ID: ' || to_char(l_curr_xfer_lpn_id)
9627 , l_api_name
9628 );
9629 END IF;
9630
9631 IF ( (NOT l_xfer_lpn_used)
9632 AND
9633 (l_curr_xfer_lpn_id = p_transfer_lpn_id)
9634 )
9635 THEN
9636 l_xfer_lpn_used := TRUE;
9637 END IF;
9638 EXCEPTION
9639 WHEN OTHERS THEN
9640 IF l_debug = 1 THEN
9641 print_debug
9642 ('Error getting MMTT xfer LPN ID: ' || sqlerrm
9643 , l_api_name
9644 );
9645 END IF;
9646 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9647 END;
9648
9649 IF (to_number(p_orig_locid) <> p_loc_id) AND (to_number(p_orig_locid) <> 0) THEN
9650 inv_loc_wms_utils.revert_loc_suggested_capacity(x_return_status => l_api_return_status,
9651 x_msg_count => l_msg_count,
9652 x_msg_data => l_msg_data,
9653 p_organization_id => p_organization_id,
9654 p_inventory_location_id => To_number(p_orig_locid),
9655 p_inventory_item_id => l_inventory_item_id,
9656 p_primary_uom_flag => 'N',
9657 p_transaction_uom_code => l_transaction_uom,
9658 p_quantity => l_transaction_qty);
9659
9660
9661 IF l_api_return_status <> fnd_api.g_ret_sts_success
9662 THEN
9663 IF l_debug = 1 THEN
9664 print_debug('Error from revert_loc_suggested_capacity', l_api_name);
9665 END IF;
9666 -- Bug 5393727: do not raise an exception if locator API returns an error
9667 -- RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9668 END IF;
9669
9670 END IF;
9671
9672 --
9673 -- Update LPN context if required
9674 --
9675 -- Bug5659809: update last_update_date and last_update_by as well
9676 UPDATE wms_license_plate_numbers wlpn
9677 SET wlpn.lpn_context = WMS_Container_PUB.LPN_CONTEXT_PACKING
9678 , last_update_date = SYSDATE
9679 , last_updated_by = fnd_global.user_id
9680 WHERE wlpn.lpn_id = l_curr_xfer_lpn_id
9681 AND wlpn.lpn_context = WMS_Container_PUB.LPN_CONTEXT_PREGENERATED;
9682
9683 IF l_debug = 1 AND SQL%FOUND
9684 THEN
9685 print_debug
9686 ('Updated LPN context to packing for LPN ID ' || to_char(l_curr_xfer_lpn_id)
9687 , l_api_name
9688 );
9689 END IF;
9690
9691 --
9692 -- Generate a new transaction header ID
9693 --
9694 SELECT mtl_material_transactions_s.NEXTVAL
9695 INTO l_txn_header_id
9696 FROM dual;
9697
9698 IF l_debug = 1 THEN
9699 print_debug
9700 ( 'Generated header ID: ' || to_char(l_txn_header_id)
9701 , l_api_name
9702 );
9703 END IF;
9704
9705 l_curr_lpn_done := FALSE;
9706 WHILE (NOT l_curr_lpn_done)
9707 LOOP
9708 IF l_debug = 1 THEN
9709 print_debug
9710 ( 'Processing temp ID: ' || to_char(l_transaction_temp_id)
9711 , l_api_name
9712 );
9713 END IF;
9714
9715 OPEN c_get_txn_info (l_transaction_temp_id);
9716 FETCH c_get_txn_info INTO l_parent_line_id, l_txn_type_id;
9717 CLOSE c_get_txn_info;
9718
9719 IF l_debug = 1 THEN
9720 print_debug
9721 ( 'l_parent_line_id: ' || to_char(l_parent_line_id) ||
9722 ', l_txn_type_id: ' || to_char(l_txn_type_id)
9723 , l_api_name
9724 );
9725 END IF;
9726
9727 IF l_parent_line_id IS NOT NULL
9728 THEN
9729 IF l_debug = 1 THEN
9730 print_debug
9731 ( ' Creating WDT record for temp ID: ' || to_char(l_transaction_temp_id)
9732 , l_api_name
9733 );
9734 END IF;
9735
9736 IF g_current_drop_lpn.multiple_drops <> 'TRUE'
9737 THEN
9738 OPEN c_get_srl_alloc_stat (l_transaction_temp_id);
9739 FETCH c_get_srl_alloc_stat INTO l_srl_stat;
9740 CLOSE c_get_srl_alloc_stat;
9741
9742 IF l_srl_stat = 'N' THEN
9743 l_api_return_status := fnd_api.g_ret_sts_success;
9744 insert_child_msnt
9745 ( x_return_status => l_api_return_status
9746 , p_temp_id => l_transaction_temp_id
9747 , p_parent_tmp_id => l_parent_line_id
9748 , p_txn_header_id => l_txn_header_id
9749 );
9750 IF l_api_return_status <> fnd_api.g_ret_sts_success
9751 THEN
9752 IF l_debug = 1 THEN
9753 print_debug ('Error from insert_child_msnt', l_api_name);
9754 END IF;
9755 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9756 ELSE
9757 IF l_debug = 1 THEN
9758 print_debug ('Success status from insert_child_msnt', l_api_name);
9759 END IF;
9760 END IF;
9761 END IF;
9762 END IF;
9763
9764 BEGIN
9765 BEGIN
9766 SELECT wdt.task_id
9767 INTO l_task_id
9768 FROM wms_dispatched_tasks wdt
9769 WHERE wdt.transaction_temp_id = l_transaction_temp_id;
9770 EXCEPTION
9771 WHEN NO_DATA_FOUND THEN
9772 INSERT INTO wms_dispatched_tasks
9773 ( task_id
9774 , transaction_temp_id
9775 , organization_id
9776 , user_task_type
9777 , person_id
9778 , effective_start_date
9779 , effective_end_date
9780 , equipment_id
9781 , equipment_instance
9782 , person_resource_id
9783 , machine_resource_id
9784 , status
9785 , dispatched_time
9786 , last_update_date
9787 , last_updated_by
9788 , creation_date
9789 , created_by
9790 , task_type
9791 , loaded_time
9792 , operation_plan_id
9793 , move_order_line_id
9794 , suggested_dest_subinventory --bug 7319244
9795 , suggested_dest_locator_id --bug 7319244
9796 )
9797 ( SELECT wms_dispatched_tasks_s.NEXTVAL
9798 , l_transaction_temp_id
9799 , mmtt.organization_id
9800 , wdt.user_task_type
9801 , wdt.person_id
9802 , wdt.effective_start_date
9803 , wdt.effective_end_date
9804 , wdt.equipment_id
9805 , wdt.equipment_instance
9806 , wdt.person_resource_id
9807 , wdt.machine_resource_id
9808 , 4
9809 , wdt.dispatched_time
9810 , SYSDATE
9811 , p_emp_id
9812 , SYSDATE
9813 , p_emp_id
9814 , wdt.task_type
9815 , SYSDATE
9816 , mmtt.operation_plan_id
9817 , mmtt.move_order_line_id
9818 , mmtt.transfer_subinventory --bug 7319244
9819 , mmtt.transfer_to_location --bug 7319244
9820 FROM wms_dispatched_tasks wdt
9821 , mtl_material_transactions_temp mmtt
9822 WHERE wdt.transaction_temp_id = l_parent_line_id
9823 AND mmtt.transaction_temp_id = l_transaction_temp_id
9824 AND rownum = 1
9825 );
9826
9827 SELECT wdt.task_id
9828 INTO l_task_id
9829 FROM wms_dispatched_tasks wdt
9830 WHERE wdt.transaction_temp_id = l_transaction_temp_id;
9831
9832 WHEN OTHERS THEN
9833 IF l_debug = 1 THEN
9834 print_debug
9835 ( 'Exception querying WDT: ' || sqlerrm
9836 , l_api_name
9837 );
9838 END IF;
9839 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9840 END;
9841
9842 IF l_debug = 1 THEN
9843 print_debug
9844 ( 'Task ID: ' || to_char(l_task_id)
9845 , l_api_name
9846 );
9847 END IF;
9848
9849 l_task_tbl(l_task_id) := l_parent_line_id;
9850
9851 EXCEPTION
9852 WHEN OTHERS THEN
9853 IF l_debug = 1 THEN
9854 print_debug
9855 ( 'Exception when processing child WDT: '
9856 || sqlerrm
9857 , l_api_name
9858 );
9859 END IF;
9860 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9861 END;
9862
9863 --
9864 -- Update parent line to NULL
9865 --
9866 BEGIN
9867 UPDATE mtl_material_transactions_temp mmtt
9868 SET mmtt.parent_line_id = NULL
9869 WHERE transaction_temp_id = l_transaction_temp_id;
9870
9871 IF l_debug = 1 THEN
9872 print_debug( 'Updated MMTT', l_api_name);
9873 END IF;
9874
9875 EXCEPTION
9876 WHEN OTHERS THEN
9877 IF l_debug = 1 THEN
9878 print_debug
9879 ( 'Exception updating MMTT: ' || sqlerrm
9880 , l_api_name
9881 );
9882 END IF;
9883 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9884 END;
9885 END IF; -- IF l_parent_line_id IS NOT NULL
9886
9887 --
9888 -- Call complete_pick
9889 --
9890 IF l_txn_type_id <> INV_GLOBALS.G_TYPE_CONTAINER_PACK
9891 THEN
9892 l_api_return_status := fnd_api.g_ret_sts_success;
9893 wms_task_dispatch_gen.complete_pick
9894 ( p_lpn => p_drop_lpn
9895 , p_container_item_id => NULL
9896 , p_org_id => p_organization_id
9897 , p_temp_id => l_transaction_temp_id
9898 , p_loc => p_loc_id
9899 , p_sub => p_subinventory
9900 , p_from_lpn_id => l_curr_xfer_lpn_id
9901 , p_txn_hdr_id => l_txn_header_id
9902 , p_user_id => fnd_global.user_id -- 9798240,p_emp_id
9903 , x_return_status => l_api_return_status
9904 , x_msg_count => l_msg_count
9905 , x_msg_data => l_msg_data
9906 , p_ok_to_process => l_ok_to_process
9907 );
9908
9909 IF l_api_return_status <> fnd_api.g_ret_sts_success
9910 THEN
9911 IF l_debug = 1 THEN
9912 print_debug
9913 ('Error from wms_task_dispatch_gen.complete_pick'
9914 , l_api_name
9915 );
9916 END IF;
9917 RAISE FND_API.G_EXC_ERROR;
9918 END IF;
9919
9920 IF l_ok_to_process = 'false'
9921 THEN
9922 IF l_debug = 1 THEN
9923 print_debug
9924 ( 'wms_task_dispatch_gen.complete_pick returned not_ok_to_process'
9925 , l_api_name
9926 );
9927 END IF;
9928 fnd_message.set_name('INV', 'INV-SUBINV NOT RESERVABLE');
9929 fnd_msg_pub.ADD;
9930 RAISE FND_API.G_EXC_ERROR;
9931 END IF;
9932 END IF;
9933
9934 BEGIN
9935 IF l_txn_type_id = INV_GLOBALS.G_TYPE_CONTAINER_PACK
9936 THEN
9937 UPDATE mtl_material_transactions_temp mmtt
9938 SET mmtt.transaction_header_id = l_txn_header_id
9939 , mmtt.subinventory_code = p_subinventory
9940 , mmtt.locator_id = p_loc_id
9941 , mmtt.transfer_subinventory = p_subinventory
9942 , mmtt.transfer_to_location = p_loc_id
9943 , mmtt.transaction_batch_id = l_txn_header_id
9944 , mmtt.transaction_batch_seq = l_batch_seq_id
9945 WHERE transaction_temp_id = l_transaction_temp_id;
9946
9947 IF l_debug = 1 THEN
9948 print_debug
9949 ( 'Updated packing txn ' || to_char(l_transaction_temp_id) ||
9950 ' - set batch/header ID to ' || to_char(l_txn_header_id) ||
9951 ', batch sequence to ' || to_char(l_batch_seq_id) ||
9952 ', sub and xfer sub to ' || p_subinventory ||
9953 ', loc and xfer loc to ' || to_char(p_loc_id)
9954 , l_api_name
9955 );
9956 END IF;
9957 ELSIF l_txn_type_id = 2 THEN -- Sub Transfer Transaction created by bulk overpick
9958 UPDATE mtl_material_transactions_temp mmtt
9959 SET mmtt.transfer_subinventory = p_subinventory,
9960 mmtt.transfer_to_location = p_loc_id,
9961 mmtt.transaction_batch_id = l_txn_header_id,
9962 mmtt.transaction_batch_seq = l_batch_seq_id
9963 WHERE transaction_temp_id = l_transaction_temp_id;
9964
9965 IF l_debug = 1 THEN
9966 print_debug
9967 ( 'Updated subtransfer txn ' || to_char(l_transaction_temp_id) ||
9968 ' - set batch/header ID to ' || to_char(l_txn_header_id) ||
9969 ', batch sequence to ' || to_char(l_batch_seq_id) ||
9970 ', xfer sub to ' || p_subinventory ||
9971 ', xfer loc to ' || to_char(p_loc_id)
9972 , l_api_name);
9973 END IF;
9974 ELSE
9975 UPDATE mtl_material_transactions_temp mmtt
9976 SET mmtt.transaction_batch_seq = l_batch_seq_id
9977 WHERE transaction_temp_id = l_transaction_temp_id;
9978
9979 IF l_debug = 1 THEN
9980 print_debug
9981 ( 'Updated temp ID ' || to_char(l_transaction_temp_id) ||
9982 ' - set batch sequence to ' || to_char(l_batch_seq_id)
9983 , l_api_name
9984 );
9985 END IF;
9986 END IF;
9987
9988 l_batch_seq_id := l_batch_seq_id + 1;
9989
9990 EXCEPTION
9991 WHEN OTHERS THEN
9992 IF l_debug = 1 THEN
9993 print_debug
9994 ( 'Exception updating batch sequence on MMTT: ' || sqlerrm
9995 , l_api_name
9996 );
9997 END IF;
9998 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
9999 END;
10000
10001 IF ii = jj THEN
10002 l_temp_tbl.DELETE(ii);
10003 l_curr_lpn_done := TRUE;
10004 ELSE
10005 kk := ii;
10006 ii := l_temp_tbl.NEXT(ii);
10007 l_temp_tbl.DELETE(kk);
10008
10009 WHILE (ii <= jj)
10010 LOOP
10011 l_transaction_temp_id := l_temp_tbl(ii);
10012 BEGIN
10013 SELECT mmtt.transfer_lpn_id
10014 INTO l_next_xfer_lpn_id
10015 FROM mtl_material_transactions_temp mmtt
10016 WHERE mmtt.transaction_temp_id = l_transaction_temp_id;
10017
10018 IF l_debug = 1 THEN
10019 print_debug
10020 ('Temp ID ' || to_char(l_transaction_temp_id) ||
10021 ' has Xfer lpn ID: ' || to_char(l_next_xfer_lpn_id)
10022 , l_api_name
10023 );
10024 END IF;
10025
10026 EXCEPTION
10027 WHEN OTHERS THEN
10028 IF l_debug = 1 THEN
10029 print_debug
10030 ('Error getting MMTT xfer LPN ID: ' || sqlerrm
10031 , l_api_name
10032 );
10033 END IF;
10034 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10035 END;
10036
10037 IF l_next_xfer_lpn_id = l_curr_xfer_lpn_id
10038 THEN
10039 EXIT;
10040 ELSE
10041 IF ii < jj THEN
10042 ii := l_temp_tbl.NEXT(ii);
10043 ELSE
10044 l_curr_lpn_done := TRUE;
10045 EXIT;
10046 END IF;
10047 END IF;
10048 END LOOP;
10049 END IF;
10050 END LOOP; -- end LOOP l_curr_lpn_done
10051
10052 --
10053 -- Call pick_drop
10054 --
10055 l_api_return_status := fnd_api.g_ret_sts_success;
10056
10057 IF g_current_drop_lpn.multiple_drops = 'FALSE'
10058 AND
10059 p_bulk_drop = 'TRUE'
10060 AND
10061 l_pack_txn_exists
10062 THEN
10063 wms_task_dispatch_gen.pick_drop
10064 ( p_temp_id => l_first_temp_id
10065 , p_txn_header_id => l_txn_header_id
10066 , p_org_id => p_organization_id
10067 , x_return_status => l_api_return_status
10068 , x_msg_count => l_msg_count
10069 , x_msg_data => l_msg_data
10070 , p_from_lpn_id => l_curr_xfer_lpn_id
10071 , p_drop_lpn => NULL
10072 , p_loc_reason_id => 0
10073 , p_sub => p_subinventory
10074 , p_loc => p_loc_id
10075 , p_orig_sub => p_orig_subinv
10076 , p_orig_loc => p_orig_locid
10077 , p_user_id => p_emp_id
10078 , p_task_type => p_task_type
10079 , p_commit => 'N'
10080 );
10081 ELSE
10082 wms_task_dispatch_gen.pick_drop
10083 ( p_temp_id => l_first_temp_id
10084 , p_txn_header_id => l_txn_header_id
10085 , p_org_id => p_organization_id
10086 , x_return_status => l_api_return_status
10087 , x_msg_count => l_msg_count
10088 , x_msg_data => l_msg_data
10089 , p_from_lpn_id => l_curr_xfer_lpn_id
10090 , p_drop_lpn => p_drop_lpn
10091 , p_loc_reason_id => p_reason_id
10092 , p_sub => p_subinventory
10093 , p_loc => p_loc_id
10094 , p_orig_sub => p_orig_subinv
10095 , p_orig_loc => p_orig_locid
10096 , p_user_id => p_emp_id
10097 , p_task_type => p_task_type
10098 , p_commit => 'N'
10099 );
10100 END IF;
10101
10102 IF l_api_return_status <> fnd_api.g_ret_sts_success
10103 THEN
10104 IF l_debug = 1 THEN
10105 print_debug ('Error from wms_task_dispatch_gen.pick_drop', l_api_name);
10106 END IF;
10107 RAISE FND_API.G_EXC_ERROR;
10108 END IF;
10109
10110 END LOOP; -- end WHILE l_temp_tbl.COUNT > 0
10111
10112 IF l_task_tbl.COUNT > 0 THEN
10113 ii := l_task_tbl.FIRST;
10114 jj := l_task_tbl.LAST;
10115
10116 IF l_debug = 1 THEN
10117 print_debug
10118 ( 'Updating WDTH: ii = ' || to_char(ii)
10119 || ', jj = ' || to_char(jj)
10120 , l_api_name
10121 );
10122 END IF;
10123
10124 l_task_id := ii;
10125 l_parent_line_id := l_task_tbl(ii);
10126
10127 WHILE (ii <= jj)
10128 LOOP
10129 --
10130 -- Update parent_transaction_id in WDTH
10131 --
10132 BEGIN
10133 UPDATE wms_dispatched_tasks_history wdth
10134 SET wdth.parent_transaction_id = l_parent_line_id
10135 , wdth.is_parent = 'N'
10136 WHERE task_id = l_task_id;
10137
10138 IF l_debug = 1 THEN
10139 print_debug
10140 ( 'Updated WDTH: set parent_transaction_id = '
10141 || to_char(l_parent_line_id)
10142 , l_api_name
10143 );
10144 END IF;
10145
10146 EXCEPTION
10147 WHEN OTHERS THEN
10148 IF l_debug = 1 THEN
10149 print_debug
10150 ( 'Exception updating WDTH: ' || sqlerrm
10151 , l_api_name
10152 );
10153 END IF;
10154 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10155 END;
10156
10157 IF ii < jj THEN
10158 ii := l_task_tbl.NEXT(ii);
10159 l_task_id := ii;
10160 l_parent_line_id := l_task_tbl(ii);
10161 ELSE
10162 EXIT;
10163 END IF;
10164
10165 IF l_debug = 1 THEN
10166 print_debug
10167 ( 'Fetched next task ID: ' || to_char(l_task_id)
10168 , l_api_name
10169 );
10170 END IF;
10171 END LOOP;
10172 END IF;
10173
10174 IF p_outer_lpn_done = 'TRUE'
10175 THEN
10176 FOR parent_rec IN c_get_parent_tasks(p_organization_id, p_transfer_lpn_id)
10177 LOOP
10178 IF l_debug = 1 THEN
10179 print_debug
10180 ( 'Processing parent: ' || to_char(parent_rec.transaction_temp_id)
10181 || ', task ID = ' || to_char(parent_rec.task_id)
10182 , l_api_name
10183 );
10184 END IF;
10185
10186 SELECT mtl_material_transactions_s.NEXTVAL
10187 INTO l_txn_header_id
10188 FROM dual;
10189
10190 IF l_debug = 1 THEN
10191 print_debug
10192 ( 'Generated header ID: ' || to_char(l_txn_header_id)
10193 , l_api_name
10194 );
10195 END IF;
10196
10197 l_api_return_status := fnd_api.g_ret_sts_success;
10198 wms_task_dispatch_put_away.archive_task
10199 ( p_temp_id => parent_rec.transaction_temp_id
10200 , p_org_id => p_organization_id
10201 , x_return_status => l_api_return_status
10202 , x_msg_count => l_msg_count
10203 , x_msg_data => l_msg_data
10204 , p_delete_mmtt_flag => 'Y'
10205 , p_txn_header_id => l_txn_header_id
10206 , p_transfer_lpn_id => p_transfer_lpn_id
10207 );
10208
10209 IF l_api_return_status <> fnd_api.g_ret_sts_success
10210 THEN
10211 IF l_debug = 1 THEN
10212 print_debug
10213 ( 'Error from wms_task_dispatch_put_away.archive_task: '
10214 || l_msg_data
10215 , l_api_name
10216 );
10217 END IF;
10218 RAISE FND_API.G_EXC_ERROR;
10219 END IF;
10220
10221 --
10222 -- Update parent_transaction_id in WDTH
10223 --
10224 BEGIN
10225 UPDATE wms_dispatched_tasks_history wdth
10226 SET wdth.parent_transaction_id = wdth.transaction_id
10227 , wdth.is_parent = 'Y'
10228 WHERE wdth.task_id = parent_rec.task_id
10229 RETURNING wdth.transaction_id INTO l_parent_txn_id;
10230
10231 IF l_debug = 1 THEN
10232 print_debug
10233 ( 'Updated WDTH. Parent transaction ID is: '
10234 || to_char(l_parent_txn_id)
10235 , l_api_name
10236 );
10237 END IF;
10238
10239 EXCEPTION
10240 WHEN OTHERS THEN
10241 IF l_debug = 1 THEN
10242 print_debug
10243 ( 'Exception updating WDTH: ' || sqlerrm
10244 , l_api_name
10245 );
10246 END IF;
10247 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10248 END;
10249
10250 --
10251 -- Update child lines
10252 --
10253 BEGIN
10254 UPDATE wms_dispatched_tasks_history wdth
10255 SET wdth.parent_transaction_id = l_parent_txn_id
10256 WHERE wdth.parent_transaction_id = parent_rec.transaction_temp_id;
10257
10258 IF l_debug = 1 THEN
10259 print_debug
10260 ( 'Updated WDTH for child records.'
10261 , l_api_name
10262 );
10263 END IF;
10264
10265 EXCEPTION
10266 WHEN OTHERS THEN
10267 IF l_debug = 1 THEN
10268 print_debug
10269 ( 'Exception updating WDTH: ' || sqlerrm
10270 , l_api_name
10271 );
10272 END IF;
10273 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10274 END;
10275 END LOOP;
10276 END IF;
10277
10278 l_task_tbl.DELETE;
10279
10280 DELETE mtl_allocations_gtmp;
10281
10282 IF p_outer_lpn_done = 'TRUE'
10283 THEN
10284 IF ( (g_current_drop_lpn.multiple_drops = 'TRUE')
10285 AND
10286 (NOT l_xfer_lpn_used)
10287 )
10288 THEN
10289 l_api_return_status := fnd_api.g_ret_sts_success;
10290 wms_container_pub.modify_lpn_wrapper
10291 ( p_api_version => '1.0'
10292 , x_return_status => l_api_return_status
10293 , x_msg_count => l_msg_count
10294 , x_msg_data => l_msg_data
10295 , p_lpn_id => p_transfer_lpn_id
10296 , p_lpn_context => WMS_Container_PUB.LPN_CONTEXT_PREGENERATED
10297 );
10298
10299 IF l_api_return_status <> fnd_api.g_ret_sts_success
10300 THEN
10301 IF l_debug = 1 THEN
10302 print_debug
10303 ( 'Error from modify_lpn_wrapper: ' || l_msg_data
10304 , l_api_name
10305 );
10306 END IF;
10307 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10308 END IF;
10309 END IF;
10310
10311 l_api_return_status := fnd_api.g_ret_sts_success;
10312 clear_lpn_cache(l_api_return_status);
10313
10314 IF l_api_return_status <> fnd_api.g_ret_sts_success
10315 THEN
10316 IF l_debug = 1 THEN
10317 print_debug ('Error from clear_lpn_cache', l_api_name);
10318 END IF;
10319 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10320 END IF;
10321 ELSE
10322 g_current_drop_lpn.current_drop_list.DELETE;
10323 g_current_drop_lpn.temp_id_group_ref.DELETE;
10324 END IF;
10325
10326 COMMIT;
10327
10328 EXCEPTION
10329 WHEN fnd_api.g_exc_error THEN
10330 ROLLBACK TO pick_drop_sp;
10331
10332 x_return_status := fnd_api.g_ret_sts_error;
10333
10334 fnd_msg_pub.count_and_get
10335 ( p_count => l_msg_count
10336 , p_data => l_msg_data
10337 , p_encoded => fnd_api.g_false
10338 );
10339
10340 IF l_debug = 1 THEN
10341 print_debug (l_msg_data, l_api_name);
10342 END IF;
10343
10344 WHEN OTHERS THEN
10345 ROLLBACK TO pick_drop_sp;
10346
10347 x_return_status := fnd_api.g_ret_sts_unexp_error;
10348
10349 IF l_debug = 1 THEN
10350 print_debug ('Other error: ' || sqlerrm, l_api_name);
10351 END IF;
10352
10353 END pick_drop;
10354
10355
10356
10357 PROCEDURE create_temp_id_list
10358 ( x_temp_id_list OUT NOCOPY VARCHAR2
10359 , x_return_status OUT NOCOPY VARCHAR2
10360 , p_organization_id IN NUMBER
10361 , p_transfer_lpn_id IN NUMBER
10362 ) IS
10363
10364 l_api_name VARCHAR2(30) := 'create_temp_id_list';
10365 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
10366
10367 l_temp_tbl g_temp_id_tbl;
10368
10369 l_api_return_status VARCHAR2(1);
10370 l_transaction_temp_id NUMBER;
10371 l_temp_id_list VARCHAR2(32767) := NULL; -- Set size to maximum allowed
10372
10373 ii NUMBER;
10374 jj NUMBER;
10375
10376 CURSOR c_get_tasks
10377 ( p_org_id IN NUMBER
10378 , p_lpn_id IN NUMBER
10379 ) IS
10380 SELECT mmtt.transaction_temp_id
10381 FROM mtl_material_transactions_temp mmtt
10382 WHERE mmtt.organization_id = p_org_id
10383 AND mmtt.transfer_lpn_id = p_lpn_id
10384 AND ( (mmtt.parent_line_id IS NOT NULL
10385 AND
10386 mmtt.parent_line_id <> mmtt.transaction_temp_id
10387 )
10388 OR
10389 mmtt.parent_line_id IS NULL
10390 );
10391
10392 BEGIN
10393 x_return_status := fnd_api.g_ret_sts_success;
10394
10395 IF l_debug = 1 THEN
10396 print_debug
10397 ( 'Entered with parameters: ' || g_newline ||
10398 'p_organization_id => ' || to_char(p_organization_id) || g_newline ||
10399 'p_transfer_lpn_id => ' || to_char(p_transfer_lpn_id)
10400 , l_api_name
10401 );
10402 END IF;
10403
10404 --
10405 -- Validate passed in Org and LPN
10406 --
10407 IF p_organization_id <> g_current_drop_lpn.organization_id
10408 OR
10409 p_transfer_lpn_id <> g_current_drop_lpn.lpn_id
10410 THEN
10411 IF l_debug = 1 THEN
10412 print_debug
10413 ( 'Passed in org or LPN did not match cached info: '
10414 || g_newline || 'p_organization_id: ' || to_char(p_organization_id)
10415 || g_newline || 'p_transfer_lpn_id: ' || to_char(p_transfer_lpn_id)
10416 || g_newline || 'Cached Org ID: ' || to_char(g_current_drop_lpn.organization_id)
10417 || g_newline || 'Cached LPN ID: ' || to_char(g_current_drop_lpn.lpn_id)
10418 , l_api_name
10419 );
10420 END IF;
10421 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10422 END IF;
10423
10424 IF g_current_drop_lpn.multiple_drops = 'TRUE'
10425 THEN
10426 l_api_return_status := fnd_api.g_ret_sts_success;
10427 get_temp_list
10428 ( x_temp_tbl => l_temp_tbl
10429 , x_return_status => l_api_return_status
10430 , p_group_num => NULL
10431 , p_status => NULL
10432 );
10433
10434 IF l_api_return_status <> fnd_api.g_ret_sts_success
10435 THEN
10436 IF l_debug = 1 THEN
10437 print_debug ('Error from get_temp_list', l_api_name);
10438 END IF;
10439 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10440 END IF;
10441 ELSE
10442 OPEN c_get_tasks (p_organization_id, p_transfer_lpn_id);
10443 FETCH c_get_tasks BULK COLLECT INTO l_temp_tbl;
10444 CLOSE c_get_tasks;
10445 END IF;
10446
10447 IF l_temp_tbl.COUNT > 0 THEN
10448 ii := l_temp_tbl.FIRST;
10449 jj := l_temp_tbl.LAST;
10450
10451 IF l_debug = 1 THEN
10452 print_debug
10453 ( 'ii = ' || to_char(ii) || ', jj = ' || to_char(jj)
10454 , l_api_name
10455 );
10456 END IF;
10457
10458 l_transaction_temp_id := l_temp_tbl(ii);
10459 l_temp_id_list := to_char(l_transaction_temp_id);
10460
10461 WHILE (ii <= jj)
10462 LOOP
10463 IF ii < jj THEN
10464 ii := l_temp_tbl.NEXT(ii);
10465 l_transaction_temp_id := l_temp_tbl(ii);
10466 l_temp_id_list := l_temp_id_list
10467 || ','
10468 || to_char(l_transaction_temp_id);
10469 ELSE
10470 EXIT;
10471 END IF;
10472 END LOOP;
10473 END IF;
10474
10475 IF l_debug = 1 THEN
10476 print_debug
10477 ( 'Temp ID list: ' || l_temp_id_list
10478 , l_api_name
10479 );
10480 END IF;
10481
10482 l_temp_tbl.DELETE;
10483
10484 x_temp_id_list := l_temp_id_list;
10485
10486 EXCEPTION
10487 WHEN OTHERS THEN
10488 x_return_status := fnd_api.g_ret_sts_unexp_error;
10489
10490 IF l_debug = 1 THEN
10491 print_debug ('Other error: ' || sqlerrm, l_api_name);
10492 END IF;
10493
10494 END create_temp_id_list;
10495
10496
10497
10498 PROCEDURE get_delivery_info
10499 ( x_delivery_name OUT NOCOPY VARCHAR2
10500 , x_order_number OUT NOCOPY VARCHAR2
10501 , x_return_status OUT NOCOPY VARCHAR2
10502 , p_organization_id IN NUMBER
10503 , p_transfer_lpn_id IN NUMBER
10504 , p_delivery_id IN NUMBER
10505 ) IS
10506
10507 l_api_name VARCHAR2(30) := 'get_delivery_info';
10508 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
10509
10510 l_delivery_name VARCHAR2(30);
10511 l_order_number NUMBER;
10512 l_count NUMBER;
10513
10514 CURSOR c_get_delivery_name
10515 ( p_del_id IN NUMBER
10516 ) IS
10517 SELECT name
10518 FROM wsh_new_deliveries_ob_grp_v wnd
10519 WHERE wnd.delivery_id = p_del_id;
10520
10521
10522 CURSOR c_get_order_number
10523 ( p_del_id IN NUMBER
10524 ) IS
10525 SELECT MIN(ooha.order_number)
10526 , COUNT(DISTINCT ooha.order_number)
10527 FROM wsh_delivery_assignments_v wda
10528 , wsh_delivery_details_ob_grp_v wdd
10529 , oe_order_lines_all oola
10530 , oe_order_headers_all ooha
10531 WHERE wda.delivery_id = p_del_id
10532 AND wda.delivery_detail_id = wdd.delivery_detail_id
10533 AND wdd.source_line_id = oola.line_id
10534 AND oola.header_id = ooha.header_id;
10535
10536 BEGIN
10537 x_return_status := fnd_api.g_ret_sts_success;
10538
10539 IF l_debug = 1 THEN
10540 print_debug
10541 ( 'Entered with parameters: ' || g_newline ||
10542 'p_organization_id => ' || to_char(p_organization_id) || g_newline ||
10543 'p_transfer_lpn_id => ' || to_char(p_transfer_lpn_id) || g_newline ||
10544 'p_delivery_id => ' || to_char(p_delivery_id)
10545 , l_api_name
10546 );
10547 END IF;
10548
10549 --
10550 -- Validate passed in Org and LPN
10551 --
10552 IF p_organization_id <> g_current_drop_lpn.organization_id
10553 OR
10554 p_transfer_lpn_id <> g_current_drop_lpn.lpn_id
10555 THEN
10556 IF l_debug = 1 THEN
10557 print_debug
10558 ( 'Passed in org or LPN did not match cached info: '
10559 || g_newline || 'p_organization_id: ' || to_char(p_organization_id)
10560 || g_newline || 'p_transfer_lpn_id: ' || to_char(p_transfer_lpn_id)
10561 || g_newline || 'Cached Org ID: ' || to_char(g_current_drop_lpn.organization_id)
10562 || g_newline || 'Cached LPN ID: ' || to_char(g_current_drop_lpn.lpn_id)
10563 , l_api_name
10564 );
10565 END IF;
10566 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10567 END IF;
10568
10569 OPEN c_get_delivery_name (p_delivery_id);
10570 FETCH c_get_delivery_name INTO l_delivery_name;
10571 CLOSE c_get_delivery_name;
10572
10573 x_delivery_name := l_delivery_name;
10574
10575 OPEN c_get_order_number (p_delivery_id);
10576 FETCH c_get_order_number INTO l_order_number, l_count;
10577 CLOSE c_get_order_number;
10578
10579 IF l_count > 1 THEN
10580 x_order_number := NULL;
10581 ELSIF l_count = 1 THEN
10582 x_order_number := l_order_number;
10583 ELSE
10584 x_order_number := NULL;
10585 END IF;
10586
10587 EXCEPTION
10588 WHEN OTHERS THEN
10589 x_return_status := fnd_api.g_ret_sts_unexp_error;
10590
10591 IF l_debug = 1 THEN
10592 print_debug ('Other error: ' || sqlerrm, l_api_name);
10593 END IF;
10594
10595 END get_delivery_info;
10596
10597
10598
10599 PROCEDURE process_conf_item
10600 ( x_is_xref OUT NOCOPY VARCHAR2
10601 , x_item_segs OUT NOCOPY VARCHAR2
10602 , x_revision OUT NOCOPY VARCHAR2
10603 , x_uom_code OUT NOCOPY VARCHAR2
10604 , x_return_status OUT NOCOPY VARCHAR2
10605 , p_organization_id IN NUMBER
10606 , p_transfer_lpn_id IN NUMBER
10607 , p_conf_item IN VARCHAR2
10608 ) IS
10609
10610 l_api_name VARCHAR2(30) := 'process_conf_item';
10611 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
10612
10613 l_count NUMBER;
10614 l_item_segs VARCHAR2(1000);
10615
10616
10617 CURSOR c_get_item_xref
10618 ( p_org_id IN NUMBER
10619 , p_xref IN VARCHAR2
10620 , p_ref_type IN VARCHAR2
10621 ) IS
10622 SELECT mcr.inventory_item_id
10623 , mcr.uom_code
10624 , mir.revision
10625 FROM mtl_cross_references mcr
10626 , mtl_item_revisions mir
10627 WHERE mcr.organization_id = mir.organization_id (+)
10628 AND mcr.inventory_item_id = mir.inventory_item_id (+)
10629 AND mcr.revision_id = mir.revision_id (+)
10630 AND mcr.cross_reference_type = p_ref_type
10631 AND mcr.cross_reference = p_xref
10632 AND (mcr.organization_id = p_org_id
10633 OR
10634 mcr.org_independent_flag = 'Y'
10635 );
10636
10637 c_xref_rec c_get_item_xref%ROWTYPE;
10638
10639
10640 CURSOR c_get_segments
10641 ( p_org_id IN NUMBER
10642 , p_item_id IN NUMBER
10643 ) IS
10644 SELECT concatenated_segments
10645 FROM mtl_system_items_kfv msik
10646 WHERE msik.organization_id = p_org_id
10647 AND msik.inventory_item_id = p_item_id;
10648
10649
10650 BEGIN
10651 x_return_status := fnd_api.g_ret_sts_success;
10652
10653 IF l_debug = 1 THEN
10654 print_debug
10655 ( 'Entered with parameters: ' || g_newline ||
10656 'p_organization_id => ' || to_char(p_organization_id) || g_newline ||
10657 'p_transfer_lpn_id => ' || to_char(p_transfer_lpn_id) || g_newline ||
10658 'p_conf_item => ' || p_conf_item || g_newline ||
10659 'g_gtin_cross_ref_type => ' || g_gtin_cross_ref_type
10660 , l_api_name
10661 );
10662 END IF;
10663
10664 --
10665 -- Validate passed in Org and LPN
10666 --
10667 IF p_organization_id <> g_current_drop_lpn.organization_id
10668 OR
10669 p_transfer_lpn_id <> g_current_drop_lpn.lpn_id
10670 THEN
10671 IF l_debug = 1 THEN
10672 print_debug
10673 ( 'Passed in org or LPN did not match cached info: '
10674 || g_newline || 'p_organization_id: ' || to_char(p_organization_id)
10675 || g_newline || 'p_transfer_lpn_id: ' || to_char(p_transfer_lpn_id)
10676 || g_newline || 'Cached Org ID: ' || to_char(g_current_drop_lpn.organization_id)
10677 || g_newline || 'Cached LPN ID: ' || to_char(g_current_drop_lpn.lpn_id)
10678 , l_api_name
10679 );
10680 END IF;
10681 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10682 END IF;
10683
10684 OPEN c_get_item_xref
10685 ( p_organization_id
10686 , p_conf_item
10687 , g_gtin_cross_ref_type
10688 );
10689 FETCH c_get_item_xref INTO c_xref_rec;
10690
10691 IF c_get_item_xref%NOTFOUND
10692 THEN
10693 x_is_xref := 'FALSE';
10694 ELSE
10695 x_is_xref := 'TRUE';
10696 END IF;
10697 CLOSE c_get_item_xref;
10698
10699 IF x_is_xref = 'TRUE'
10700 THEN
10701 OPEN c_get_segments (p_organization_id, c_xref_rec.inventory_item_id);
10702 FETCH c_get_segments INTO l_item_segs;
10703 CLOSE c_get_segments;
10704 --
10705 -- Set the return values
10706 --
10707 x_item_segs := l_item_segs;
10708 x_revision := c_xref_rec.revision;
10709 x_uom_code := c_xref_rec.uom_code;
10710 END IF;
10711
10712 IF l_debug = 1 THEN
10713 print_debug
10714 ( 'Returning the following values: '
10715 || g_newline || 'x_is_xref: ' || x_is_xref
10716 || g_newline || 'x_item_segs: ' || x_item_segs
10717 || g_newline || 'x_revision: ' || x_revision
10718 || g_newline || 'x_uom_code: ' || x_uom_code
10719 , l_api_name
10720 );
10721 END IF;
10722
10723 EXCEPTION
10724 WHEN OTHERS THEN
10725 x_return_status := fnd_api.g_ret_sts_unexp_error;
10726
10727 IF l_debug = 1 THEN
10728 print_debug ('Other error: ' || sqlerrm, l_api_name);
10729 END IF;
10730
10731 END process_conf_item;
10732
10733 PROCEDURE validate_pick_drop_lpn
10734 ( x_return_status OUT NOCOPY VARCHAR2
10735 , p_organization_id IN NUMBER
10736 , p_transfer_lpn_id IN NUMBER
10737 , p_outer_lpn_done IN VARCHAR2
10738 , p_drop_lpn IN VARCHAR2
10739 , p_drop_sub IN VARCHAR2
10740 , p_drop_loc_id IN NUMBER
10741 , p_delivery_id IN NUMBER
10742 ) IS
10743
10744 l_api_name VARCHAR2(30) := 'validate_pick_drop_lpn';
10745 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
10746
10747 l_api_return_status VARCHAR2(1);
10748 l_msg_count NUMBER;
10749 l_msg_data VARCHAR2(2000);
10750
10751 l_temp_tbl g_temp_id_tbl;
10752 l_transaction_temp_id NUMBER;
10753 l_xfer_lpn_id NUMBER;
10754 l_delivery_id NUMBER;
10755
10756 ii NUMBER;
10757 jj NUMBER;
10758
10759 l_line_rows WSH_UTIL_CORE.id_tab_type; -- Added for bug#4106176
10760 l_grouping_rows WSH_UTIL_CORE.id_tab_type; -- Added for bug#4106176
10761
10762 l_allow_packing VARCHAR2(1);
10763
10764 CURSOR c_drop_lpn_cursor
10765 ( p_lpn IN VARCHAR2
10766 , p_org_id IN NUMBER
10767 ) IS
10768 SELECT wlpn.lpn_id
10769 , wlpn.lpn_context
10770 , wlpn.subinventory_code
10771 , wlpn.locator_id
10772 FROM wms_license_plate_numbers wlpn
10773 WHERE wlpn.license_plate_number = p_lpn
10774 AND wlpn.organization_id = p_org_id;
10775
10776 drop_lpn_rec c_drop_lpn_cursor%ROWTYPE;
10777
10778
10779 CURSOR c_xfer_lpn_id
10780 ( p_temp_id IN NUMBER
10781 ) IS
10782 SELECT mmtt.transfer_lpn_id
10783 FROM mtl_material_transactions_temp mmtt
10784 WHERE mmtt.transaction_temp_id = p_temp_id;
10785
10786
10787 CURSOR c_drop_delivery
10788 ( p_lpn_id IN NUMBER
10789 , p_org_id IN NUMBER
10790 ) IS
10791 SELECT wda.delivery_id
10792 FROM wsh_delivery_assignments_v wda
10793 , wsh_delivery_details_ob_grp_v wdd
10794 , wms_license_plate_numbers lpn
10795 WHERE wda.parent_delivery_detail_id = wdd.delivery_detail_id
10796 AND wdd.organization_id = p_org_id
10797 AND wdd.lpn_id = lpn.lpn_id
10798 AND wdd.released_status = 'X' -- For LPN reuse ER : 6845650
10799 AND lpn.outermost_lpn_id = p_lpn_id
10800 ORDER BY wda.delivery_id;
10801
10802
10803 BEGIN
10804 x_return_status := fnd_api.g_ret_sts_success;
10805
10806 IF l_debug = 1 THEN
10807 print_debug
10808 ( 'Entered with parameters: ' || g_newline ||
10809 'p_organization_id => ' || to_char(p_organization_id) || g_newline ||
10810 'p_transfer_lpn_id => ' || to_char(p_transfer_lpn_id) || g_newline ||
10811 'p_outer_lpn_done => ' || p_outer_lpn_done || g_newline ||
10812 'p_drop_lpn => ' || p_drop_lpn || g_newline ||
10813 'p_drop_sub => ' || p_drop_sub || g_newline ||
10814 'p_drop_loc_id => ' || to_char(p_drop_loc_id) || g_newline ||
10815 'p_delivery_id => ' || to_char(p_delivery_id)
10816 , l_api_name
10817 );
10818 END IF;
10819
10820 --
10821 -- Validate passed in Org and LPN
10822 --
10823 IF p_organization_id <> g_current_drop_lpn.organization_id
10824 OR
10825 p_transfer_lpn_id <> g_current_drop_lpn.lpn_id
10826 THEN
10827 IF l_debug = 1 THEN
10828 print_debug
10829 ( 'Passed in org or LPN did not match cached info: '
10830 || g_newline || 'p_organization_id: ' || to_char(p_organization_id)
10831 || g_newline || 'p_transfer_lpn_id: ' || to_char(p_transfer_lpn_id)
10832 || g_newline || 'Cached Org ID: ' || to_char(g_current_drop_lpn.organization_id)
10833 || g_newline || 'Cached LPN ID: ' || to_char(g_current_drop_lpn.lpn_id)
10834 , l_api_name
10835 );
10836 END IF;
10837 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10838 END IF;
10839
10840 OPEN c_drop_lpn_cursor (p_drop_lpn, p_organization_id);
10841 FETCH c_drop_lpn_cursor INTO drop_lpn_rec;
10842
10843 IF c_drop_lpn_cursor%NOTFOUND
10844 THEN
10845 CLOSE c_drop_lpn_cursor;
10846 IF l_debug = 1 THEN
10847 print_debug
10848 ( 'Drop LPN is new. No validations required.'
10849 , l_api_name
10850 );
10851 END IF;
10852 RETURN;
10853 ELSIF drop_lpn_rec.lpn_context =
10854 WMS_Container_PUB.LPN_CONTEXT_PREGENERATED
10855 THEN
10856 CLOSE c_drop_lpn_cursor;
10857 IF l_debug = 1 THEN
10858 print_debug
10859 ( 'Drop LPN is pre-generated. No validations required.'
10860 , l_api_name
10861 );
10862 END IF;
10863 RETURN;
10864 ELSIF drop_lpn_rec.lpn_id = p_transfer_lpn_id
10865 THEN
10866 --Start change for bug 5620764: disallow using outer LPN as drop LPN
10867 CLOSE c_drop_lpn_cursor;
10868 IF l_debug = 1 THEN
10869 print_debug
10870 ( 'Cannot use outer LPN as drop LPN'
10871 , l_api_name
10872 );
10873 END IF;
10874 fnd_message.set_name('WMS', 'WMS_DROP_PICK_LPN_SAME');
10875 fnd_msg_pub.ADD;
10876 RAISE FND_API.G_EXC_ERROR;
10877 RETURN;
10878 /*
10879 IF g_current_drop_lpn.multiple_drops = 'TRUE'
10880 AND
10881 p_outer_lpn_done <> 'TRUE'
10882 THEN
10883 CLOSE c_drop_lpn_cursor;
10884 IF l_debug = 1 THEN
10885 print_debug
10886 ( 'Outer LPN is not fully deconsolidated, so cannot use that as drop LPN'
10887 , l_api_name
10888 );
10889 END IF;
10890 fnd_message.set_name('WMS', 'WMS_LPN_HAS_MORE_DROP_MTL');
10891 fnd_msg_pub.ADD;
10892 RAISE FND_API.G_EXC_ERROR;
10893 ELSIF g_current_drop_lpn.multiple_drops <> 'TRUE'
10894 THEN
10895 CLOSE c_drop_lpn_cursor;
10896 IF l_debug = 1 THEN
10897 print_debug
10898 ( 'No deconsolidation, so cannot reuse outer as drop LPN'
10899 , l_api_name
10900 );
10901 END IF;
10902 fnd_message.set_name('WMS', 'WMS_DROP_PICK_LPN_SAME');
10903 fnd_msg_pub.ADD;
10904 RAISE FND_API.G_EXC_ERROR;
10905 END IF;
10906 RETURN; -- multiple drops is TRUE and outer LPN done
10907 */
10908 -- End change for bug 5620764
10909 ELSIF drop_lpn_rec.lpn_context =
10910 WMS_Container_PUB.lpn_context_picked
10911 THEN
10912 IF drop_lpn_rec.subinventory_code <> p_drop_sub
10913 OR
10914 drop_lpn_rec.locator_id <> p_drop_loc_id
10915 THEN
10916 CLOSE c_drop_lpn_cursor;
10917 IF l_debug = 1 THEN
10918 print_debug
10919 ( 'Drop LPN resides in sub/loc '
10920 || drop_lpn_rec.subinventory_code || '/'
10921 || to_char(drop_lpn_rec.locator_id)
10922 || ', which is different from ' || p_drop_sub
10923 || '/' || to_char(p_drop_loc_id)
10924 , l_api_name
10925 );
10926 END IF;
10927 fnd_message.set_name('WMS', 'WMS_DROP_LPN_SUBLOC_MISMATCH');
10928 fnd_msg_pub.ADD;
10929 RAISE FND_API.G_EXC_ERROR;
10930 END IF;
10931 ELSIF drop_lpn_rec.lpn_context =
10932 WMS_Container_PUB.LPN_LOADED_FOR_SHIPMENT
10933 THEN
10934 CLOSE c_drop_lpn_cursor;
10935 IF l_debug = 1 THEN
10936 print_debug
10937 ( 'Drop LPN is loaded to dock door already'
10938 , l_api_name
10939 );
10940 END IF;
10941 fnd_message.set_name('WMS', 'WMS_DROP_LPN_LOADED');
10942 fnd_msg_pub.ADD;
10943 RAISE FND_API.G_EXC_ERROR;
10944 END IF;
10945
10946 IF c_drop_lpn_cursor%ISOPEN
10947 THEN
10948 CLOSE c_drop_lpn_cursor;
10949 END IF;
10950
10951 IF g_current_drop_lpn.multiple_drops = 'TRUE'
10952 THEN
10953 l_api_return_status := fnd_api.g_ret_sts_success;
10954 get_temp_list
10955 ( x_temp_tbl => l_temp_tbl
10956 , x_return_status => l_api_return_status
10957 , p_group_num => NULL
10958 , p_status => NULL
10959 );
10960
10961 IF l_api_return_status <> fnd_api.g_ret_sts_success
10962 THEN
10963 IF l_debug = 1 THEN
10964 print_debug ('Error from get_temp_list', l_api_name);
10965 END IF;
10966 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10967 END IF;
10968
10969 --
10970 -- Check if transfer_lpn_id on any record matches
10971 -- drop LPN Id
10972 --
10973 IF l_temp_tbl.COUNT > 0 THEN
10974 ii := l_temp_tbl.FIRST;
10975 jj := l_temp_tbl.LAST;
10976
10977 IF l_debug = 1 THEN
10978 print_debug
10979 ( 'ii = ' || to_char(ii) || ', jj = ' || to_char(jj)
10980 , l_api_name
10981 );
10982 END IF;
10983
10984 l_transaction_temp_id := l_temp_tbl(ii);
10985 WHILE (ii <= jj)
10986 LOOP
10987 IF l_debug = 1 THEN
10988 print_debug
10989 ( ' Calling transfer_lpn_id on temp ID: '
10990 || to_char(l_transaction_temp_id)
10991 , l_api_name
10992 );
10993 END IF;
10994
10995 OPEN c_xfer_lpn_id (l_transaction_temp_id);
10996 FETCH c_xfer_lpn_id INTO l_xfer_lpn_id;
10997 IF c_xfer_lpn_id%NOTFOUND
10998 THEN
10999 CLOSE c_xfer_lpn_id;
11000 IF l_debug = 1 THEN
11001 print_debug
11002 ( 'No MMTT record found for temp ID: '
11003 || to_char(l_transaction_temp_id)
11004 , l_api_name
11005 );
11006 END IF;
11007 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11008 END IF;
11009
11010 IF c_xfer_lpn_id%ISOPEN
11011 THEN
11012 CLOSE c_xfer_lpn_id;
11013 END IF;
11014
11015 IF l_xfer_lpn_id = drop_lpn_rec.lpn_id
11016 THEN
11017 IF l_debug = 1 THEN
11018 print_debug
11019 ( 'Xfer LPN ' || to_char(l_xfer_lpn_id)
11020 || ' on temp ID ' || to_char(l_transaction_temp_id)
11021 || ' matches drop LPN'
11022 , l_api_name
11023 );
11024 END IF;
11025
11026 l_temp_tbl.DELETE;
11027
11028 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
11029 fnd_msg_pub.ADD;
11030 RAISE FND_API.G_EXC_ERROR;
11031 END IF;
11032
11033 IF ii < jj THEN
11034 ii := l_temp_tbl.NEXT(ii);
11035 l_transaction_temp_id := l_temp_tbl(ii);
11036 ELSE
11037 EXIT;
11038 END IF;
11039
11040 IF l_debug = 1 THEN
11041 print_debug
11042 ( 'Fetched next temp ID: ' || to_char(l_transaction_temp_id)
11043 , l_api_name
11044 );
11045 END IF;
11046 END LOOP;
11047 END IF;
11048
11049 l_temp_tbl.DELETE;
11050 END IF;
11051
11052 IF drop_lpn_rec.lpn_context <> WMS_Container_PUB.lpn_context_picked
11053 THEN
11054 IF l_debug = 1 THEN
11055 print_debug
11056 ( 'Invalid LPN context: ' || to_char(drop_lpn_rec.lpn_context)
11057 , l_api_name
11058 );
11059 END IF;
11060 fnd_message.set_name('WMS', 'WMS_INVALID_LPN_STATUS');
11061 fnd_msg_pub.ADD;
11062 RAISE FND_API.G_EXC_ERROR;
11063 END IF;
11064
11065 --**MRANA temporary code for double validations and avoid data corruption
11066
11067 wms_mdc_pvt.validate_to_lpn(p_from_lpn_id => p_transfer_lpn_id,
11068 p_from_delivery_id => p_delivery_id,
11069 p_to_lpn_id => drop_lpn_rec.lpn_id,
11070 p_is_from_to_delivery_same => 'U',
11071 x_allow_packing => l_allow_packing,
11072 x_return_status => l_api_return_status,
11073 x_msg_count => l_msg_count,
11074 x_msg_data => l_msg_data);
11075
11076 IF l_api_return_status <> fnd_api.g_ret_sts_success THEN
11077 IF l_debug = 1 THEN
11078 print_debug('Error from wms_mdc_pvt.validate_to_lpn: ' || l_msg_data, l_api_name);
11079 END IF;
11080 RAISE fnd_api.g_exc_error;
11081 ELSE
11082 IF l_debug = 1 THEN
11083 print_debug('wms_mdc_pvt.validate_to_lpn returned: ' || l_allow_packing, l_api_name);
11084 END IF;
11085
11086 IF l_allow_packing = 'N' THEN
11087 RAISE fnd_api.g_exc_error;
11088 END IF;
11089
11090 END IF;
11091
11092
11093 -- MR: wms_mdc_pvt.validate_to_lpn API, returns l_allow_packing = 'N', if
11094 -- {{- either from or To do not have a delivery id . Therefor, MDC is not }}
11095 -- {{ allowed if either of the 2 is NULL }} */
11096 --mrana IF l_allow_packing = 'U' THEN -- Both from LPN and to LPN are not tied to any delivery
11097 /*Bug#4106176.The following block is added.*/
11098 /* BEGIN -- mrana: need to figure this out later
11099 SELECT delivery_detail_id
11100 INTO l_line_rows(1)
11101 FROM wsh_delivery_details_ob_grp_v
11102 WHERE lpn_id = drop_lpn_rec.lpn_id
11103 AND rownum = 1 ;
11104
11105 SELECT wdd.delivery_detail_id
11106 INTO l_line_rows(2)
11107 FROM wsh_delivery_details_ob_grp_v wdd, Mtl_material_transactions_temp mmtt
11108 WHERE mmtt.move_order_line_id = wdd.move_order_line_id
11109 AND wdd.organization_id = mmtt.organization_id
11110 AND mmtt.organization_id= p_organization_id
11111 AND mmtt.transfer_lpn_id= p_transfer_lpn_id
11112 AND rownum = 1 ;
11113
11114 --call to the shipping API.
11115 WSH_DELIVERY_DETAILS_GRP.Get_Carton_Grouping( p_line_rows => l_line_rows,
11116 x_grouping_rows => l_grouping_rows,
11117 x_return_status => x_return_status);
11118 IF (l_debug = 1) THEN
11119 print_debug ('parameters : l_line_rows(1) :'||l_line_rows(1) ||',l_line_rows(2) :' || l_line_rows(2), l_api_name);
11120 print_debug('count l_grp_rows'|| l_grouping_rows.count, l_api_name);
11121 print_debug('l_grp_rows(1) : '||l_grouping_rows(1) ||',l_grp_rows(2) : '||l_grouping_rows(2), l_api_name);
11122 END IF;
11123
11124 IF (x_return_status = FND_API.G_RET_STS_SUCCESS AND l_grouping_rows(1) = l_grouping_rows(2) ) THEN
11125 IF (l_debug = 1) THEN
11126 print_debug('The LPN can be dropped into LPN_ID '||drop_lpn_rec.lpn_id, l_api_name);
11127 END IF;
11128 ELSE
11129 IF (l_debug = 1) THEN
11130 print_debug('Picked LPN does not belong to same delivery as Drop LPN. So cannot be dropped', l_api_name);
11131 END IF;
11132 fnd_message.set_name('WMS', 'WMS_DROP_LPN_DIFF_DELIV');
11133 fnd_msg_pub.ADD;
11134 RAISE FND_API.G_EXC_ERROR;
11135 END IF;
11136
11137 EXCEPTION
11138 WHEN NO_DATA_FOUND THEN
11139 IF (l_debug = 1) THEN
11140 print_debug('No Data found Exception raised when checking for delivery grouping', l_api_name);
11141 print_debug('Picked LPN is not associated with a delivery, so dont show ANY lpn.', l_api_name);
11142 END IF;
11143 RAISE FND_API.G_EXC_ERROR;
11144 WHEN OTHERS THEN
11145 IF (l_debug = 1) THEN
11146 print_debug('Other Exception raised when checking for delivery grouping', l_api_name);
11147 print_debug('Picked LPN is not associated with a delivery, so dont show ANY lpn.', l_api_name);
11148 END IF;
11149 RAISE FND_API.G_EXC_ERROR;
11150 END; */ --End of Fix for bug#4106176 */
11151 --mrana END IF;
11152
11153 EXCEPTION
11154 WHEN fnd_api.g_exc_error THEN
11155 x_return_status := fnd_api.g_ret_sts_error;
11156
11157 fnd_msg_pub.count_and_get
11158 ( p_count => l_msg_count
11159 , p_data => l_msg_data
11160 , p_encoded => fnd_api.g_false
11161 );
11162
11163 IF l_debug = 1 THEN
11164 print_debug (l_msg_data, l_api_name);
11165 END IF;
11166
11167 WHEN OTHERS THEN
11168 x_return_status := fnd_api.g_ret_sts_unexp_error;
11169
11170 IF l_debug = 1 THEN
11171 print_debug ('Other error: ' || sqlerrm, l_api_name);
11172 END IF;
11173
11174 END validate_pick_drop_lpn;
11175
11176
11177 END wms_pick_drop_pvt;