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