1 PACKAGE BODY WMS_PUTAWAY_UTILS AS
2 /* $Header: WMSPUTLB.pls 120.40.12010000.5 2008/10/10 08:03:59 abasheer ship $*/
3
4
5 --WMS_PUTAWAY_UTILS Package
6 -- File : WMSPUTLB.pls
7 -- Content :
8 -- Description :
9 /**
10 * This is a new package created in 11510 (FPJ)
11 * This Contains Procedures/Functions for putaway utilites.
12 **/
13 -- Notes : This package will contain the wrappers (which will be called from the java files)
14 -- for putaway.
15 -- This will also contain the grouping logic stuff which will populate the global
16 -- temp table WMS_PUTAWAY_GROUP_TASKS_GTEMP
17 -- Modified : Mon Jul 28 18:08:27 GMT+05:30 2003
18
19
20 -- Global Variables definition section
21
22 --Commonly used variables
23 g_version_printed BOOLEAN := FALSE;
24 g_pkg_name VARCHAR2(30) := 'WMS_PUTAWAY_UTILS';
25 --l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
26
27 G_DT_CONSOLIDATED_DROP CONSTANT VARCHAR2(2) := 'CD';
28 G_DT_ITEM_DROP CONSTANT VARCHAR2(2) := 'ID';
29 G_DT_USER_DROP CONSTANT VARCHAR2(2) := 'UD';
30 G_DT_MANUAL_DROP CONSTANT VARCHAR2(2) := 'MD';
31 G_DT_DROP_ALL CONSTANT VARCHAR2(2) := 'DA';
32
33 G_OK_TO_PROCESS CONSTANT VARCHAR2(10) := 'Y';
34
35 G_ROW_TP_ALL_TASK CONSTANT VARCHAR2(15) := 'All Task';
36 G_ROW_TP_GROUP_TASK CONSTANT VARCHAR2(15) := 'Group Task';
37 G_ROW_TP_LPN_TASK CONSTANT VARCHAR2(15) := 'LPN Task';
38
39 G_LPN_CONTEXT_INV CONSTANT NUMBER := 1;
40 G_LPN_CONTEXT_WIP CONSTANT NUMBER := 2;
41 G_LPN_CONTEXT_RCV CONSTANT NUMBER := 3;
42
43 -- ATF Related constants
44 G_ATF_ACTIVATE_PLAN CONSTANT NUMBER := 1;
45 G_ATF_ABORT_PLAN CONSTANT NUMBER := 2;
46 G_ATF_CANCEL_PLAN CONSTANT NUMBER := 3;
47
48 G_OP_TYPE_LOAD CONSTANT NUMBER := wms_globals.g_op_type_load;
49 G_OP_TYPE_DROP CONSTANT NUMBER := wms_globals.G_OP_TYPE_DROP;
50 G_OP_TYPE_INSPECT CONSTANT NUMBER := wms_globals.G_OP_TYPE_INSPECT;
51 G_OP_TYPE_PACK CONSTANT NUMBER := wms_globals.G_OP_TYPE_PACK;
52 G_OP_TYPE_CROSSDOCK CONSTANT NUMBER := wms_globals.G_OP_TYPE_CROSSDOCK;
53
54 G_OP_ACTIVITY_INBOUND CONSTANT NUMBER := wms_globals.G_OP_ACTIVITY_INBOUND;
55 G_TASK_STATUS_DISPATCHED CONSTANT NUMBER := 3;
56 G_TASK_STATUS_LOADED CONSTANT NUMBER := 4;
57
58 /*
59 G_OP_INS_STAT_PENDING CONSTANT NUMBER := wms_globals.G_OP_INS_STAT_PENDING;
60 G_OP_INS_STAT_ACTIVE CONSTANT NUMBER := wms_globals.G_OP_INS_STAT_ACTIVE;
61 G_OP_INS_STAT_COMPLETED CONSTANT NUMBER := wms_globals.G_OP_INS_STAT_COMPLETED;
62 G_OP_INS_STAT_ABORTED CONSTANT NUMBER := WMS_GLOBALS.G_OP_INS_STAT_ABORTED;
63 G_OP_INS_STAT_CANCELLED CONSTANT NUMBER := WMS_GLOBALS.G_OP_INS_STAT_CANCELLED;
64 */
65
66 --Constant to hold values for call type param
67 G_CT_NORMAL_LOAD CONSTANT NUMBER := 1;
68 G_CT_NORMAL_DROP CONSTANT NUMBER := 2;
69 G_CT_SINGLE_STEP_DROP CONSTANT NUMBER := 3;
70 G_CT_INSPECT_TM_FAILED CONSTANT NUMBER := 4;
71 G_CT_INSPECT_B4_TM CONSTANT NUMBER := 5;
72
73 -- Bulk fetch limit.
74 -- This limit will be used wherever bulk collect is used in this package
75 -- It is hardcoded to 2000, but later it can be changed to suit the requirements
76 l_limit NUMBER := 2000;
77
78
79 -- Define collections for commonly used datatypes. These collections will be
80 -- used for bulk fetch.
81
82 TYPE lpn_name_tab IS TABLE OF WMS_LICENSE_PLATE_NUMBERS.LICENSE_PLATE_NUMBER%TYPE
83 INDEX BY BINARY_INTEGER;
84 TYPE sub_name_tab IS TABLE OF MTL_SECONDARY_INVENTORIES.SECONDARY_INVENTORY_NAME%TYPE
85 INDEX BY BINARY_INTEGER;
86 TYPE row_type_tab IS TABLE OF WMS_PUTAWAY_GROUP_TASKS_GTMP.ROW_TYPE%TYPE
87 INDEX BY BINARY_INTEGER;
88 TYPE item_tab IS TABLE OF MTL_SYSTEM_ITEMS_KFV.CONCATENATED_SEGMENTS%TYPE
89 INDEX BY BINARY_INTEGER;
90
91
92 TYPE num_tab IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
93 TYPE date_tab IS TABLE OF DATE INDEX BY BINARY_INTEGER;
94 TYPE rowid_tab IS TABLE OF urowid INDEX BY BINARY_INTEGER;
95 TYPE varchar240_tab IS TABLE OF VARCHAR2(240) INDEX BY BINARY_INTEGER;
96
97 TYPE uom_tab IS TABLE OF MTL_UNITS_OF_MEASURE_TL.UOM_CODE%TYPE INDEX BY BINARY_INTEGER;
98 TYPE lot_tab IS TABLE OF MTL_LOT_NUMBERS.LOT_NUMBER%TYPE INDEX BY BINARY_INTEGER;
99 TYPE rev_tab IS TABLE OF MTL_ITEM_REVISIONS.REVISION%TYPE INDEX BY BINARY_INTEGER;
100
101 TYPE entity_tab IS TABLE OF WIP_ENTITIES.WIP_ENTITY_NAME%TYPE INDEX BY BINARY_INTEGER;
102 TYPE line_tab IS TABLE OF WIP_LINES.LINE_CODE%TYPE INDEX BY BINARY_INTEGER;
103 TYPE dept_tab IS TABLE OF BOM_DEPARTMENTS.DEPARTMENT_CODE%TYPE INDEX BY BINARY_INTEGER;
104 TYPE schedule_tab IS TABLE OF WIP_ENTITIES.WIP_ENTITY_NAME%TYPE INDEX BY BINARY_INTEGER;
105
106 TYPE ser_num_tab IS TABLE OF mtl_serial_numbers.serial_number%TYPE
107 INDEX BY BINARY_INTEGER;
108 TYPE ser_mark_tab IS TABLE OF VARCHAR2(1) INDEX BY BINARY_INTEGER;
109
110 TYPE mol_in_rec IS RECORD(
111 line_id NUMBER
112 , prim_qty NUMBER
113 );
114 TYPE split_mo_tb_tp IS TABLE OF mol_in_rec INDEX BY BINARY_INTEGER;
115
116 -- Task Record
117 SUBTYPE task_rec IS wms_dispatched_tasks%ROWTYPE;
118
119 --Added for bug 5286880
120 g_line_rows WSH_UTIL_CORE.id_tab_type;
121 g_grouping_rows WSH_UTIL_CORE.id_tab_type;
122
123
124 /**
125 * This procedure will call the inv_log_util package to log the messages
126 * This will prepend package name and the module (which is passed) to the log message
127 * This will also print the version of the file during the first execution only.
128
129 * @param p_message The message which is to be logged
130 * @param p_module Procedure/Function from which this is called
131 * @param p_level Log level, if it is not passed a default value of 9 will be assumed.
132 **/
133 PROCEDURE DEBUG(p_message IN VARCHAR2,
134 p_module IN VARCHAR2 := ' ',
135 p_level IN NUMBER := 9 ) IS
136 BEGIN
137
138 IF NOT g_version_printed THEN
139 inv_log_util.trace('$Header: WMSPUTLB.pls 120.40.12010000.5 2008/10/10 08:03:59 abasheer ship $',g_pkg_name, 9);
140 g_version_printed := TRUE;
141 END IF;
142
143 inv_log_util.trace(p_message, g_pkg_name || '.' || p_module,p_level);
144 --dbms_output.put_line(substr(g_pkg_name || p_module || p_message,1,255) );
145 END DEBUG; -- Procedure debug
146
147
148
149 /**
150 * This function will return the subinventory_type for the
151 * subinventory and org combination passed as input. It will
152 * return the following values
153 * 1 -- Storage Subinventory.
154 * 2 -- Receiving Subinventory.
155
156 * @param p_organization_id Organization ID
157 * @param p_subinventory_code Subinventory Code
158 * @ RETURN number
159
160
161 **/
162 FUNCTION Get_Subinventory_Type(
163 p_organization_id IN NUMBER,
164 p_subinventory_code IN VARCHAR2)
165 RETURN NUMBER
166 IS
167 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
168 l_progress VARCHAR2(10) := '10';
169 l_proc_name VARCHAR2(30) := 'Get_Subinventory_Type:';
170 l_sub_type NUMBER := 1;
171 BEGIN
172
173 IF (l_debug = 1) THEN
174 DEBUG(' Function Entered at ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
175 DEBUG(' p_organization_id => '||p_organization_id,l_proc_name , 4);
176 DEBUG(' p_subinventory_code => '||p_subinventory_code,l_proc_name, 4);
177 END IF;
178
179 l_progress := '100';
180 BEGIN
181
182 l_progress := '110';
183 -- Get teh subinventory type for the passed sub_code
184
185 SELECT nvl(subinventory_type,1)
186 INTO l_sub_type
187 FROM mtl_secondary_inventories
188 WHERE organization_id = p_organization_id
189 AND secondary_inventory_name = p_subinventory_code;
190
191 l_progress := '120';
192
193 EXCEPTION
194 WHEN OTHERS THEN
195 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
196 DEBUG(SQLERRM,l_proc_name,1);
197 l_sub_type := -1;
198 END;
199
200 l_progress := '150';
201 IF (l_debug = 1) THEN
202 DEBUG(' l_sub_type => '|| l_sub_type,l_proc_name,4);
203 DEBUG(' Function Exited at ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
204 END IF;
205 l_progress := '160';
206
207 -- Return the subinventory type for the i/p parameters passed
208 RETURN l_sub_type;
209
210 EXCEPTION
211 WHEN OTHERS THEN
212 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
213 DEBUG(SQLERRM,l_proc_name,1);
214 RETURN -1;
215 END get_subinventory_type; --Function get_subinventory_type
216
217
218
219
220 /**
221 * This function will get the count of number of rows in the
222 * global temporary table WMS_PUTAWAY_GROUP_TASKS_GTMP
223 * The rows counted will depend on the mode for which it is called
224 * Mode Meaning
225 * ----------------------------------------------------------------
226 * 1 Get the count of all the rows in the temp table
227 * 2 Get the count of only 'All Task' rows in the temp table
228 * 3 Get the count of only 'Group Task' rows in the temp table
229 * 4 Get the count of only 'LPN Task' rows in the temp table
230
231 * @param p_mode Mode of count
232 * @ RETURN NUMBER
233
234
235 **/
236 FUNCTION Get_Row_Count (p_mode IN NUMBER)
237 RETURN NUMBER
238 IS
239 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
240 l_progress VARCHAR2(10) := '10';
241 l_proc_name VARCHAR2(30) := 'Get_Row_Count:';
242 l_rec_count NUMBER := 0;
243 BEGIN
244
245 IF (l_debug = 1) THEN
246 DEBUG(' Function Entered at ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
247 DEBUG(' p_mode ==> ' || p_mode,l_proc_name,4);
248 END IF;
249
250 l_progress := '90';
251
252 IF (p_mode = 1) THEN --check for p_mode
253
254 -- Get the count of all rows in the temp table
255 l_progress := '100';
256 SELECT count(ROWID)
257 INTO l_rec_count
258 FROM WMS_PUTAWAY_GROUP_TASKS_GTMP;
259 l_progress := '110';
260
261 ELSIF (p_mode = 2) THEN
262
263 -- Get the count of all 'All Task' Rows in the temp table
264 l_progress := '200';
265 SELECT count(ROWID)
266 INTO l_rec_count
267 FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
268 WHERE row_type = G_ROW_TP_ALL_TASK;
269 l_progress := '210';
270
271 ELSIF (p_mode = 3) THEN
272
273 -- Get the count of all 'Group Task' Rows in the temp table
274 l_progress := '300';
275 SELECT count(ROWID)
276 INTO l_rec_count
277 FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
278 WHERE row_type = G_ROW_TP_GROUP_TASK;
279 l_progress := '310';
280
281 ELSIF (p_mode = 4) THEN
282
283 -- Get the count of all 'LPN Task' Rows in the temp table
284 l_progress := '400';
285 SELECT count(ROWID)
286 INTO l_rec_count
287 FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
288 WHERE row_type = G_ROW_TP_LPN_TASK;
289 l_progress := '410';
290
291 ELSE
292 -- Invalid input passed for p_mode and hence error out
293 l_rec_count := -1;
294 END IF; --check for p_mode
295
296
297 --This function can be later modified to return the follwing information
298 -- Item drop count
299 -- Consolidated LPN drop count
300 -- Group task records alone
301 -- All task records
302
303 l_progress := '900';
304 IF (l_debug = 1) THEN
305 DEBUG(' l_rec_count => '|| l_rec_count,l_proc_name,4);
306 DEBUG(' Function Exited at ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
307 END IF;
308 l_progress := '910';
309
310 -- Retrun the number of rows in the temp table
311 RETURN l_rec_count;
312
313 EXCEPTION
314 WHEN OTHERS THEN
315 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
316 DEBUG(SQLERRM,l_proc_name);
317 RETURN -1;
318 END get_row_count; --Function get_row_count
319
320
321
322
323 /**
324 * This function will remove all the records in the temporary
325 * table WMS_PUTAWAY_GROUP_TASKS_GTMP
326 * The rows that has to be deleted depends on the i/p parameter
327 * p_del_type
328 *
329 * p_del_type Action
330 * ------------------------------------------------------------
331 * 1 -- Delete tasks belonging to the group which is passed as input.
332 * 2 -- Delete dummy rows which has been inserted for LPNs without contents
333 * 3 -- Deletes all the records in the temp table.
334 * This Funciton will delete both the group_tasks and all_task
335 * rows.
336 * It will return the number of rows deleted
337 * -1 in case of failure.
338
339 * @param p_group_id Group ID for which the records has to be deleted
340 * @ RETURN NUMBER
341
342
343 **/
344 FUNCTION Remove_Tasks_In_Group(
345 p_del_type IN NUMBER
346 ,p_group_id IN NUMBER )
347 RETURN NUMBER
348 IS
349 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
350 l_progress VARCHAR2(10) := '10';
351 l_proc_name VARCHAR2(30) := 'Remove_Tasks_In_Group:';
352 l_rec_count NUMBER := 0;
353
354 l_rowid_tab rowid_tab;
355
356 -- This cursor will select the dummy rows in the temp table which can be deleted
357 CURSOR c_dummy_task IS
358 SELECT ROWID
359 FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
360 WHERE row_type = G_ROW_TP_LPN_TASK;
361
362
363 BEGIN
364
365 IF (l_debug = 1) THEN
366 DEBUG(' Function Entered at ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
367 END IF;
368
369 IF (l_debug = 1) THEN
370 DEBUG(' p_del_type ==> '||p_del_type,l_proc_name,4);
371 DEBUG(' p_group_id ==> '||p_group_id,l_proc_name,4);
372 END IF;
373
374 l_progress := '100';
375
376 IF p_del_type = 1 THEN
377 -- Delete the tasks for the group_id passed
378 l_progress := '105';
379 IF (l_debug = 1) THEN
380 DEBUG(' Deleting tasks for the group id passed',l_proc_name,9);
381 END IF;
382
383 IF p_group_id = -1 THEN
384 IF (l_debug = 1) THEN
385 DEBUG(' Group ID is -1 and returning -1 ',l_proc_name,9);
386 END IF;
387 RETURN -1;
388 END IF;
389
390 l_progress := '110';
391 DELETE FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
392 WHERE group_id = p_group_id;
393 l_progress := '120';
394
395 -- Get the number of rows processed by the above SQL
396 l_progress := '130';
397 l_rec_count := SQL%rowcount;
398 l_progress := '140';
399
400 ELSIF p_del_type = 2 THEN
401 -- Delete the dummy records which has been inserted for LPNs without contents
402
403 l_progress := '205';
404 IF (l_debug = 1) THEN
405 DEBUG(' Deleting tasks for the group id passed',l_proc_name,9);
406 END IF;
407
408 l_progress := '210';
409 OPEN c_dummy_task;
410 l_progress := '220';
411
412 LOOP --dummy_task_cursor
413
414 EXIT WHEN c_dummy_task%NOTFOUND;
415 l_progress := '230';
416
417 -- Fetch the records which needs to be deleted
418 l_progress := '240';
419 FETCH c_dummy_task
420 BULK COLLECT
421 INTO l_rowid_tab
422 LIMIT l_limit;
423 l_progress := '250';
424
425
426 -- Bulk delete the dummy records
427 FORALL i IN 1 .. l_rowid_tab.COUNT
428 DELETE FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
429 WHERE ROWID = l_rowid_tab(i);
430
431 l_progress := '260';
432 END LOOP; --dummy_task_cursor
433
434 l_progress := '270';
435 CLOSE c_dummy_task;
436 l_progress := '280';
437
438
439 ELSIF p_del_type = 3 THEN
440 --Delete all records from WMS_PUTAWAY_GROUP_TASKS_GTMP
441
442 l_progress := '305';
443 IF (l_debug = 1) THEN
444 DEBUG(' Deleting all the rows from the global temp table',l_proc_name,9);
445 END IF;
446
447 l_progress := '310';
448 DELETE FROM WMS_PUTAWAY_GROUP_TASKS_GTMP;
449 l_progress := '320';
450
451 -- Get the number of rows processed by the above SQL
452 l_progress := '330';
453 l_rec_count := SQL%rowcount;
454 l_progress := '340';
455
456 ELSE
457 l_progress := '800';
458 IF (l_debug = 1) THEN
459 DEBUG(' Invalid value for p_',l_proc_name,9);
460 END IF;
461
462 l_rec_count := -1;
463 END IF; -- p_del_type check
464
465 l_progress := '900';
466 IF (l_debug = 1) THEN
467 DEBUG(' l_rec_count => '|| l_rec_count,l_proc_name,4);
468 DEBUG(' Function Exited at ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
469 END IF;
470
471 -- return the number of rows deleted
472 RETURN l_rec_count;
473
474 EXCEPTION
475 WHEN OTHERS THEN
476 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
477 DEBUG(SQLERRM,l_proc_name);
478
479 -- Close the cursors if they are open
480 IF c_dummy_task%isopen THEN
481 CLOSE c_dummy_task;
482 END IF;
483
484 RETURN -1;
485 END Remove_Tasks_In_Group;
486
487
488
489
490 /**
491 * This function will update the transaction_header_id of the
492 * group(both in the global temp table and in MMTT) with same
493 * value.
494 * It will also stamp a common group_id for the group.
495
496 * @ RETURN NUMBER
497
498 **/
499 FUNCTION Sync_Group_Tasks
500 RETURN NUMBER
501 IS
502 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
503 l_progress VARCHAR2(10) := '10';
504 l_proc_name VARCHAR2(30) := 'Sync_Group_Tasks:';
505 l_rec_count NUMBER := 0;
506
507 l_drop_order NUMBER;
508 l_txn_header_id NUMBER;
509
510 l_txn_temp_id_tab num_tab;
511
512 CURSOR c_all_group_tasks_cursor IS
513 SELECT drop_order
514 FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
515 WHERE row_type = G_ROW_TP_GROUP_TASK;
516
517 BEGIN
518
519 IF (l_debug = 1) THEN
520 DEBUG(' Function Entered at ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
521 END IF;
522 l_progress := '100';
523
524 BEGIN
525 OPEN c_all_group_tasks_cursor;
526 l_progress := '110';
527
528 LOOP --c_all_group_tasks_cursor loop
529 FETCH c_all_group_tasks_cursor
530 INTO l_drop_order;
531 l_progress := '120';
532
533 EXIT WHEN c_all_group_tasks_cursor%NOTFOUND;
534 l_progress := '130';
535
536 --l_txn_header_id := MTL_MATERIAL_TRANSACTIONS_S.NEXTVAL;
537
538 SELECT MTL_MATERIAL_TRANSACTIONS_S.NEXTVAL
539 INTO l_txn_header_id
540 FROM dual;
541 l_progress := '140';
542
543 UPDATE WMS_PUTAWAY_GROUP_TASKS_GTMP
544 SET transaction_header_id = l_txn_header_id
545 ,group_id = l_drop_order
546 WHERE drop_order = l_drop_order
547 RETURNING transaction_temp_id
548 BULK COLLECT INTO l_txn_temp_id_tab;
549 l_progress := '150';
550
551 l_rec_count := l_rec_count + SQL%rowcount;
552 IF (l_debug = 1) THEN
553 DEBUG(sql%rowcount || ' Row(s) updated in WMS_PUTAWAY_GROUP_TASKS_GTMP with txn_header_id = ' || l_txn_header_id ||
554 ' and group_id = ' || l_drop_order
555 ,l_proc_name,9);
556 END IF;
557 l_progress := '160';
558
559
560 FORALL i IN 1 ..l_txn_temp_id_tab.COUNT
561 UPDATE MTL_MATERIAL_TRANSACTIONS_TEMP
562 SET transaction_header_id = l_txn_header_id
563 WHERE transaction_temp_id = l_txn_temp_id_tab(i);
564 l_progress := '170';
565
566 l_rec_count := l_rec_count + SQL%rowcount;
567 IF (l_debug = 1) THEN
568 DEBUG(sql%rowcount || ' Row(s) updated in WMS_PUTAWAY_GROUP_TASKS_GTMP with txn_header_id= ' || l_txn_header_id ,l_proc_name,9);
569 END IF;
570 l_progress := '180';
571
572
573 END LOOP;--c_all_group_tasks_cursor loop
574
575 CLOSE c_all_group_tasks_cursor;
576 l_progress := '190';
577
578 EXCEPTION
579 WHEN OTHERS THEN
580 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
581 DEBUG(SQLERRM,l_proc_name);
582
583 IF c_all_group_tasks_cursor%ISOPEN THEN
584 CLOSE c_all_group_tasks_cursor;
585 END IF;
586
587 RETURN -1;
588 END;
589
590 IF (l_debug = 1) THEN
591 DEBUG(' Function Exited at ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
592 END IF;
593 l_progress := '490';
594
595 RETURN l_rec_count;
596 l_progress := '500';
597 EXCEPTION
598 WHEN OTHERS THEN
599 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
600 DEBUG(SQLERRM,l_proc_name);
601 RETURN -1;
602
603 END Sync_Group_Tasks;
604
605
606
607 /**
608 * This function will mark the consolidated LPN of all the
609 * child records of the lpn_id and lpn_name passed.
610 * This will also mark the drop_order with the minimum
611 * drop_order in that group.
612 * This will return the number of rows processed. This will
613 * return -1 in case of failure.
614
615 * @param p_lpn_id LPN ID for whose childs the allocated LPN has to be marked.
616 * @ RETURN NUMBER
617
618
619 **/
620 FUNCTION Mark_Consolidated_LPN( p_lpn_id IN NUMBER
621 ,p_lpn_name IN VARCHAR2 )
622 RETURN NUMBER
623 IS
624
625 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
626 l_progress VARCHAR2(10) := '10';
627 l_proc_name VARCHAR2(30) := 'Mark_Consolidated_LPN:';
628 l_rec_count NUMBER := 0;
629 l_min_drop_order NUMBER;
630
631 l_lpn_id_tab num_tab;
632
633 --This cursor will fetch all the child LPNs for the LPN Passed
634 CURSOR c_child_lpn_cursor IS
635 SELECT lpn_id
636 FROM wms_license_plate_numbers
637 START WITH lpn_id = p_lpn_id
638 CONNECT BY PRIOR lpn_id = parent_lpn_id;
639
640 BEGIN
641
642 l_progress := '100';
643
644 IF (l_debug = 1) THEN
645 DEBUG(' p_lpn_id ==> '||p_lpn_id,l_proc_name,4);
646 DEBUG(' p_lpn_name ==> '||p_lpn_name,l_proc_name,4);
647 END IF;
648
649 l_progress := '130';
650 OPEN c_child_lpn_cursor;
651 l_progress := '140';
652
653 FETCH c_child_lpn_cursor
654 BULK COLLECT INTO l_lpn_id_tab;
655 l_progress := '150';
656
657 CLOSE c_child_lpn_cursor;
658 l_progress := '160';
659
660 SELECT MIN(drop_order)
661 INTO l_min_drop_order
662 FROM wms_putaway_group_tasks_gtmp
663 WHERE lpn_id = p_lpn_id
664 OR lpn_id IN ( SELECT lpn_id
665 FROM wms_license_plate_numbers
666 START WITH lpn_id = p_lpn_id
667 CONNECT BY PRIOR lpn_id = parent_lpn_id
668 );
669 l_progress := '170';
670
671 --Update the cosolidated lpn for the child LPNs with the lpn passed
672 /* UPDATE wms_putaway_group_tasks_gtmp
673 SET consolidated_lpn_id = p_lpn_id
674 ,consolidated_lpn_name = l_lpn_name
675 ,drop_order = p_drop_order
676 WHERE lpn_id IN (SELECT lpn_id
677 FROM wms_license_plate_numbers
678 START WITH lpn_id = p_lpn_id
679 CONNECT BY PRIOR lpn_id = parent_lpn_id
680 );*/
681
682
683 -- Do bulk update for all LPN and all itz child the consolidated LPN and the min drop order in that group
684 FORALL i IN 1 .. l_lpn_id_tab.COUNT
685 UPDATE wms_putaway_group_tasks_gtmp
686 SET consolidated_lpn_id = p_lpn_id
687 ,consolidated_lpn_name = p_lpn_name
688 ,drop_order = l_min_drop_order
689 WHERE lpn_id = l_lpn_id_tab(i);
690
691 l_progress := '240';
692
693 IF (l_debug = 1) THEN
694 DEBUG('Updated the consolidated LPN columns for the children ',l_proc_name,9);
695 END IF;
696
697
698 l_progress := '250';
699 l_rec_count := SQL%rowcount;
700 l_progress := '160';
701
702 IF (l_debug = 1) THEN
703 DEBUG(' l_rec_count => '|| l_rec_count,l_proc_name,4);
704 DEBUG(' Function Exited at ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
705 END IF;
706 l_progress := '280';
707
708 -- Return the number of rows updated for consolidated drop
709 RETURN l_rec_count;
710
711 EXCEPTION
712 WHEN OTHERS THEN
713 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
714 DEBUG(SQLERRM,l_proc_name,1);
715 RETURN -1;
716 END Mark_Consolidated_LPN;
717
718
719
720
721 /**
722 * This function will mark drop_type as 'ID'(Item Drop) for
723 * all the contents of the lpn which is passed as input and
724 * all its parents. This will call the same function
725 * recursively till it doesn't find parent lpn.
726 * This function will return the number of rows updated as
727 * Item Drop. This will retun -1 in case of a failure.
728
729 * @ RETURN NUMBER
730
731
732 **/
733 FUNCTION Mark_Item_Drop(p_lpn_id IN NUMBER)
734 RETURN NUMBER
735 IS
736 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
737 l_progress VARCHAR2(10) := '10';
738 l_proc_name VARCHAR2(30) := 'Mark_Item_Drop:';
739 l_rec_count NUMBER := 0;
740 l_temp NUMBER := 0;
741 l_parent_lpn_id NUMBER;
742 BEGIN
743 IF (l_debug = 1) THEN
744 DEBUG(' p_lpn_id ==> '||p_lpn_id,'Mark_Item_Drop',4);
745 END IF;
746
747 BEGIN --ID Marking
748 -- Select the parent lpn id of the passed lpn
749 l_progress := '100';
750 SELECT parent_lpn_id
751 INTO l_parent_lpn_id
752 FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
753 WHERE lpn_id = p_lpn_id
754 AND ROWNUM < 2;
755 l_progress := '110';
756
757 -- Set the drop type to 'ID' for all the contents of the lpn passed
758 l_progress := '120';
759 UPDATE WMS_PUTAWAY_GROUP_TASKS_GTMP
760 SET drop_type = G_DT_ITEM_DROP
761 WHERE lpn_id = p_lpn_id;
762 l_progress := '130';
763
764 l_progress := '135';
765 l_rec_count := SQL%rowcount;
766 l_progress := '138';
767
768 EXCEPTION
769 WHEN no_data_found THEN
770 l_progress := '139';
771 -- Parent LPN is not in GTMP so mark the parent as null so that the recursion ends.
772 l_parent_lpn_id := NULL;
773
774 WHEN OTHERS THEN
775 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
776 DEBUG(SQLERRM,l_proc_name,1);
777 RETURN -1;
778 END; --ID Marking
779
780
781 IF l_parent_lpn_id IS NOT NULL THEN
782
783 l_progress := '140';
784 -- Call Mark_Item_Drop for the parent LPN
785 l_temp := Mark_Item_Drop(l_parent_lpn_id);
786 l_progress := '150';
787
788 IF l_temp <> -1 THEN
789 --Increment the record updated counter
790 l_progress := '160';
791 l_rec_count := l_rec_count + l_temp;
792
793 ELSE
794 --returned -1 and hence error so fail
795 l_progress := '170';
796 RETURN -1;
797 END IF;
798
799 END IF;
800
801 IF (l_debug = 1) THEN
802 DEBUG(' l_rec_count => '|| l_rec_count,l_proc_name,4);
803 DEBUG(' Function Exited at ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
804 END IF;
805 l_progress := '180';
806
807
808 -- Return the number of rows marked for item drop
809 RETURN l_rec_count;
810
811 EXCEPTION
812 WHEN OTHERS THEN
813 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
814 DEBUG(SQLERRM,l_proc_name,1);
815 RETURN -1;
816 END Mark_Item_Drop;
817
818
819 /**
820 * This function will create the group task row in the global temp table
821 * With the data passed as input
822 *
823 * This will return the number of rows inserted as output.
824 * This will return -1 in case of failure.
825 * @ RETURN NUMBER
826
827 **/
828 FUNCTION Insert_Group_Tasks (
829 l_rowid_tab IN rowid_tab
830 ,l_txn_qty_tab IN num_tab
831 ,l_pri_qty_tab IN num_tab
832 ,l_drop_order_tab IN num_tab
833 ,l_show_message_tab IN num_tab --R12
834 ,l_error_code_tab IN varchar240_tab
835 ,l_drop_lpn_option_tab IN num_tab
836 ,l_consolidation_method_id_tab IN num_tab )
837 RETURN NUMBER
838 IS
839 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
840 l_progress VARCHAR2(10) := '10';
841 l_proc_name VARCHAR2(30) := 'Insert_Group_Tasks:';
842 l_rec_count NUMBER := 0;
843
844 BEGIN
845
846 IF (l_debug = 1) THEN
847 DEBUG('Start of Function ', l_proc_name,9);
848 END IF;
849 l_progress := '100';
850
851 -- Printing the i/p parameters
852 IF (l_debug = 1) THEN
853 FOR i IN 1 .. l_rowid_tab.COUNT
854 LOOP
855 DEBUG('l_txn_qty_tab ==> ' || l_txn_qty_tab(i),l_proc_name,4);
856 DEBUG('l_pri_qty_tab ==> ' || l_pri_qty_tab(i),l_proc_name,4);
857 DEBUG('l_drop_order_tab ==> ' || l_drop_order_tab(i),l_proc_name,4);
858 DEBUG('l_show_message_tab ==> ' || l_show_message_tab(i),l_proc_name,4);
859 DEBUG('l_error_code_tab ==> ' || l_error_code_tab(i),l_proc_name,4);
860 END LOOP;
861 END IF; -- Printing the i/p parameters
862 l_progress := '110';
863
864 -- This will bulk insert consolidated records for group tasks into the temp table
865 FORALL i IN 1 .. l_rowid_tab.COUNT
866 INSERT INTO WMS_PUTAWAY_GROUP_TASKS_GTMP
867 (
868 ORGANIZATION_ID
869 ,TRANSACTION_TEMP_ID
870 ,TRANSACTION_HEADER_ID
871 ,LPN_ID
872 ,LPN_NAME
873 ,LPN_CONTEXT
874 ,PARENT_LPN_ID
875 ,PARENT_LPN_NAME
876 ,OUTERMOST_LPN_ID
877 ,OUTERMOST_LPN_NAME
878 ,CONSOLIDATED_LPN_ID
879 ,CONSOLIDATED_LPN_NAME
880 ,INTO_LPN_ID
881 ,INTO_LPN_NAME
882 ,DROP_TYPE
883 ,DROP_ORDER
884 ,INVENTORY_ITEM_ID
885 ,ITEM
886 ,GROUP_ID
887 ,LOT_NUMBER
888 ,REVISION
889 ,TRANSACTION_QUANTITY
890 ,TRANSACTION_UOM
891 ,LOCATOR
892 ,PRIMARY_UOM_CODE
893 ,DEST_SUBINVENTORY
894 ,DEST_LOCATOR
895 ,REVISION_QTY_CONTROL_CODE
896 ,LOT_CONTROL_CODE
897 ,SERIAL_NUMBER_CONTROL_CODE
898 ,RESTRICT_SUBINVENTORIES_CODE
899 ,RESTRICT_LOCATORS_CODE
900 ,LOCATION_CONTROL_CODE
901 ,ALLOWED_UNITS_LOOKUP_CODE
902 ,BACKORDER_DELIVERY_DETAIL
903 ,CROSSDOCK_TYPE
904 ,WIP_SUPPLY_TYPE
905 ,FROM_SUBINVENTORY
906 ,FROM_LOCATOR
907 ,TRANSFER_SUBINVENTORY
908 ,TRANSFER_TO_LOCATION
909 ,TRANSFER_ORGANIZATION
910 ,TRANSACTION_ACTION_ID
911 ,REFERENCE
912 ,LOC_DROPPING_ORDER
913 ,SUB_DROPPING_ORDER
914 ,ROW_TYPE
915 ,MOVE_ORDER_LINE_ID
916 ,PROJECT_ID
917 ,TASK_ID
918 ,TXN_SOURCE_ID
919 ,PRIMARY_QUANTITY
920 ,PROCESS_FLAG
921 ,WIP_JOB
922 ,WIP_LINE
923 ,WIP_DEPT
924 ,WIP_OP_SEQ
925 ,WIP_ENTITY_TYPE
926 ,WIP_START_DATE
927 ,WIP_SCHEDULE
928 ,WIP_ASSEMBLY
929 ,SECONDARY_QUANTITY --OPM Convergence
930 ,SECONDARY_UOM --OPM Convergence
931 ,show_message -- R12
932 ,error_code --R12
933 ,drop_lpn_option --R12
934 ,consolidation_method_id --R12
935 ,sub_lpn_controlled_flag --R12
936 )
937 SELECT
938 ORGANIZATION_ID
939 ,TRANSACTION_TEMP_ID
940 ,TRANSACTION_HEADER_ID
941 ,LPN_ID
942 ,LPN_NAME
943 ,LPN_CONTEXT
944 ,PARENT_LPN_ID
945 ,PARENT_LPN_NAME
946 ,OUTERMOST_LPN_ID
947 ,OUTERMOST_LPN_NAME
948 ,CONSOLIDATED_LPN_ID
949 ,CONSOLIDATED_LPN_NAME
950 ,INTO_LPN_ID
951 ,INTO_LPN_NAME
952 ,DROP_TYPE
953 ,l_drop_order_tab(i)
954 ,INVENTORY_ITEM_ID
955 ,ITEM
956 ,GROUP_ID
957 ,LOT_NUMBER
958 ,REVISION
959 ,l_txn_qty_tab(i)
960 ,TRANSACTION_UOM
961 ,LOCATOR
962 ,PRIMARY_UOM_CODE
963 ,DEST_SUBINVENTORY
964 ,DEST_LOCATOR
965 ,REVISION_QTY_CONTROL_CODE
966 ,LOT_CONTROL_CODE
967 ,SERIAL_NUMBER_CONTROL_CODE
968 ,RESTRICT_SUBINVENTORIES_CODE
969 ,RESTRICT_LOCATORS_CODE
970 ,LOCATION_CONTROL_CODE
971 ,ALLOWED_UNITS_LOOKUP_CODE
972 -- ,BACKORDER_DELIVERY_DETAIL
973 ,DECODE(backorder_delivery_detail,NULL,NULL,0,0,get_grouping(backorder_delivery_detail)) --Added for bug 5286880
974 ,CROSSDOCK_TYPE
975 ,WIP_SUPPLY_TYPE
976 ,FROM_SUBINVENTORY
977 ,FROM_LOCATOR
978 ,TRANSFER_SUBINVENTORY
979 ,TRANSFER_TO_LOCATION
980 ,TRANSFER_ORGANIZATION
981 ,TRANSACTION_ACTION_ID
982 ,REFERENCE
983 ,LOC_DROPPING_ORDER
984 ,SUB_DROPPING_ORDER
985 ,G_ROW_TP_GROUP_TASK
986 ,MOVE_ORDER_LINE_ID
987 ,PROJECT_ID
988 ,TASK_ID
989 ,TXN_SOURCE_ID
990 ,l_pri_qty_tab(i)
991 ,PROCESS_FLAG
992 ,WIP_JOB
993 ,WIP_LINE
994 ,WIP_DEPT
995 ,WIP_OP_SEQ
996 ,WIP_ENTITY_TYPE
997 ,WIP_START_DATE
998 ,WIP_SCHEDULE
999 ,WIP_ASSEMBLY
1000 ,SECONDARY_QUANTITY --OPM Convergence
1001 ,SECONDARY_UOM --OPM Convergence
1002 ,l_show_message_tab(i) --R12
1003 ,l_error_code_tab(i) --R12
1004 ,l_drop_lpn_option_tab(i) --R12
1005 ,l_consolidation_method_id_tab(i) --R12
1006 ,sub_lpn_controlled_flag --R12
1007 FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
1008 WHERE ROWID = l_rowid_tab(i);
1009 l_progress := '120';
1010
1011 l_rec_count := SQL%rowcount;
1012 l_progress := '150';
1013
1014 IF (l_debug = 1) THEN
1015 DEBUG('l_rec_count = ' || l_rec_count, l_proc_name,9);
1016 END IF;
1017 l_progress := '990';
1018 RETURN l_rec_count;
1019
1020 EXCEPTION
1021 WHEN OTHERS THEN
1022 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
1023 DEBUG(SQLERRM,l_proc_name,1);
1024 RETURN -1;
1025
1026 END Insert_Group_Tasks;
1027
1028
1029 /**
1030 * This function will insert the group_task rows
1031 * This will insert one group task row per group.
1032 *
1033 *
1034 * This will return the number of groups created as
1035 * output.This will return -1 in case of failure.
1036
1037 * @ RETURN NUMBER
1038
1039
1040 **/
1041 FUNCTION Group_Consolidated_Drop_Tasks
1042 RETURN NUMBER
1043 IS
1044 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1045 l_progress VARCHAR2(10) := '10';
1046 l_proc_name VARCHAR2(30) := 'Group_Consolidated_Drop_Task:';
1047 l_rec_count NUMBER := 0;
1048 l_cur_count NUMBER := 0;
1049
1050 l_rowid_tab rowid_tab;
1051 l_txn_qty_tab num_tab;
1052 l_pri_qty_tab num_tab;
1053 l_drop_order_tab num_tab;
1054 l_sec_qty_tab num_tab; --OPM Convergence
1055 l_show_message_tab num_tab;--R12
1056 l_error_code_tab varchar240_tab;
1057 l_drop_lpn_option_tab num_tab;
1058 l_consolidation_method_id_tab num_tab;
1059
1060 CURSOR c_group_tasks_cursor IS
1061 SELECT min(ROWID)
1062 ,SUM(transaction_quantity)
1063 ,SUM(primary_quantity)
1064 ,drop_order
1065 ,SUM(secondary_quantity) --OPM Convergence
1066 ,MAX(show_message) --R12
1067 ,MAX(error_code) --R12
1068 ,MAX(drop_lpn_option) --R12: This value should be unique per group
1069 ,MAX(consolidation_method_id) --R12: This value should be unique per group
1070 FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
1071 WHERE row_type IN (G_ROW_TP_ALL_TASK, G_ROW_TP_LPN_TASK)
1072 AND drop_type = G_DT_CONSOLIDATED_DROP
1073 GROUP BY drop_order;
1074
1075 BEGIN
1076
1077 IF (l_debug = 1) THEN
1078 DEBUG('Start of Function ', l_proc_name,9);
1079 END IF;
1080 l_progress := '100';
1081
1082 -- Actual logic here
1083 OPEN c_group_tasks_cursor;
1084 l_progress := '110';
1085
1086 LOOP --c_group_tasks_cursor
1087
1088 EXIT WHEN c_group_tasks_cursor%NOTFOUND;
1089 l_progress := '200';
1090
1091 FETCH c_group_tasks_cursor
1092 BULK COLLECT
1093 INTO l_rowid_tab
1094 ,l_txn_qty_tab
1095 ,l_pri_qty_tab
1096 ,l_drop_order_tab
1097 ,l_sec_qty_tab --OPM Convergence
1098 ,l_show_message_tab --R12
1099 ,l_error_code_tab --R12
1100 ,l_drop_lpn_option_tab --R12
1101 ,l_consolidation_method_id_tab --R12
1102 LIMIT l_limit;
1103 l_progress := '210';
1104
1105 -- Insert group task row into temp table
1106 /* Note: Not passing l_sec_qty_tab as input to insert_group_tasks
1107 since only l_rowid_tab is used in this function to fetch
1108 the corresponding records from the gtmp table. Infact all
1109 the other tables are not needed to pass as inputs to this
1110 Function
1111 */
1112 l_cur_count := Insert_Group_Tasks (
1113 l_rowid_tab => l_rowid_tab
1114 ,l_txn_qty_tab => l_txn_qty_tab
1115 ,l_pri_qty_tab => l_pri_qty_tab
1116 ,l_drop_order_tab => l_drop_order_tab
1117 ,l_show_message_tab=> l_show_message_tab --R12
1118 ,l_error_code_tab => l_error_code_tab --R12
1119 ,l_drop_lpn_option_tab => l_drop_lpn_option_tab --R12
1120 ,l_consolidation_method_id_tab => l_consolidation_method_id_tab); --R12
1121 l_progress := '230';
1122
1123 -- Check for errors while inserting group task row
1124 IF l_cur_count = -1 THEN
1125 l_progress := '232';
1126 RAISE fnd_api.g_exc_unexpected_error;
1127 END IF;
1128
1129 l_rec_count := l_rec_count + l_cur_count;
1130 l_progress := '235';
1131
1132 IF (l_debug = 1) THEN
1133 DEBUG( l_cur_count|| ' Group task Row(s) inserted in WMS_PUTAWAY_GROUP_TASKS_GTMP '
1134 ,l_proc_name,9);
1135 END IF;
1136 l_progress := '240';
1137
1138 l_rec_count := l_rec_count + l_cur_count;
1139 l_progress := '250';
1140
1141 END LOOP;--c_group_tasks_cursor
1142
1143
1144 IF (l_debug = 1) THEN
1145 DEBUG(' l_rec_count => '|| l_rec_count,l_proc_name,4);
1146 DEBUG(' Function Exited at ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
1147 END IF;
1148
1149 l_progress := '990';
1150 CLOSE c_group_tasks_cursor;
1151 l_progress := '1000';
1152
1153 RETURN l_rec_count;
1154
1155 EXCEPTION
1156
1157 WHEN fnd_api.g_exc_unexpected_error THEN
1158 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
1159 DEBUG(SQLERRM,l_proc_name,1);
1160
1161 IF c_group_tasks_cursor%isopen THEN
1162 CLOSE c_group_tasks_cursor;
1163 END IF;
1164
1165 RETURN -1;
1166
1167 WHEN OTHERS THEN
1168 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
1169 DEBUG(SQLERRM,l_proc_name,1);
1170
1171 IF c_group_tasks_cursor%isopen THEN
1172 CLOSE c_group_tasks_cursor;
1173 END IF;
1174
1175 RETURN -1;
1176
1177 END Group_Consolidated_Drop_Tasks;
1178
1179
1180
1181 /**
1182 * This function will group the MMTTs which are marked as
1183 * 'ID' -- Item Drop
1184 *
1185 * This will return the number of rows processed as
1186 * output.This will return -1 in case of failure.
1187
1188 * @ RETURN NUMBER
1189
1190
1191 **/
1192 FUNCTION Group_Item_Drop_Tasks
1193 RETURN NUMBER
1194 IS
1195 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1196 l_progress VARCHAR2(10) := '10';
1197 l_proc_name VARCHAR2(30) := 'Group_Item_Drop_Tasks:';
1198 l_rec_count NUMBER := 0;
1199 l_cur_count NUMBER := 0;
1200
1201 l_rowid_tab rowid_tab;
1202 l_tempid_tab num_tab;
1203 l_txn_qty_tab num_tab;
1204 l_pri_qty_tab num_tab;
1205 l_drop_order_tab num_tab;
1206 l_sec_qty_tab num_tab; --OPM Convergence
1207
1208 l_lpn_id_tab num_tab;
1209 l_inventory_item_id_tab num_tab;
1210 l_transaction_uom_tab uom_tab;
1211 l_revision_tab rev_tab;
1212 l_lot_number_tab lot_tab;
1213 l_dest_locator_tab num_tab;
1214 l_bk_dl_detail_tab num_tab;
1215 l_into_lpn_id_tab num_tab;
1216 l_out_drop_order_tab num_tab;
1217 l_show_message_tab num_tab;
1218 l_error_code_tab varchar240_tab;
1219 l_drop_lpn_option_tab num_tab;
1220 l_consolidation_method_id_tab num_tab;
1221
1222 -- WIP related variables
1223 l_wip_entity_type_tab num_tab;
1224 l_job_tab entity_tab;
1225 l_line_tab line_tab;
1226 l_dept_tab dept_tab;
1227 l_operation_seq_num_tab num_tab;
1228 l_start_date_tab date_tab;
1229 l_schedule_tab entity_tab;
1230 l_assembly_tab item_tab;
1231 l_wip_entity_id_tab num_tab;
1232
1233 l_return_status VARCHAR2(30);
1234 l_msg_count NUMBER;
1235 l_msg_data VARCHAR2(10000);
1236
1237 -- This cursor will group the all task rows where drop tpe = 'ID' based on the grouping criteria
1238 -- This will ignore the rows which are cross-docked to WIP Issue
1239 CURSOR c_group_item_drop_tasks_cursor IS
1240 SELECT MIN(ROWID)
1241 ,MIN(drop_order)
1242 ,SUM(transaction_quantity)
1243 ,SUM(primary_quantity)
1244 ,SUM(secondary_quantity) --OPM Convergence
1245 ,MAX(show_message)
1246 ,MAX(error_code)
1247 ,MAX(drop_lpn_option) --R12: This value should be unique per group
1248 ,MAX(consolidation_method_id) --R12: This value should be unique per group
1249 FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
1250 WHERE row_type = G_ROW_TP_ALL_TASK
1251 AND drop_type = G_DT_ITEM_DROP
1252 AND NOT (crossdock_type > 1
1253 AND backorder_delivery_detail > 0
1254 AND wip_supply_type = 1
1255 )
1256 GROUP BY lpn_id
1257 ,inventory_item_id
1258 ,transaction_uom
1259 ,revision
1260 ,lot_number
1261 ,dest_locator
1262 ,into_lpn_id
1263 --,backorder_delivery_detail; --R12
1264 ,decode(BACKORDER_DELIVERY_DETAIL,null,null,0,0,get_grouping(BACKORDER_DELIVERY_DETAIL)); --Added for bug 5286880
1265
1266 -- This cursor will group the all task rows where drop tpe = 'ID' based on the grouping criteria
1267 -- This will consider only the rows which are cross-docked to WIP Issue
1268 CURSOR c_wip_item_drop_tasks_cursor IS
1269 SELECT MIN(ROWID)
1270 ,MIN(drop_order)
1271 ,SUM(transaction_quantity)
1272 ,SUM(primary_quantity)
1273 ,SUM(secondary_quantity) --OPM Convergence
1274 ,MAX(show_message)
1275 ,MAX(error_code)
1276 ,MAX(drop_lpn_option) --R12: This value should be unique per group
1277 ,MAX(consolidation_method_id) --R12: This value should be unique per group
1278 FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
1279 WHERE row_type = G_ROW_TP_ALL_TASK
1280 AND drop_type = G_DT_ITEM_DROP
1281 AND crossdock_type > 1
1282 AND backorder_delivery_detail > 0
1283 AND wip_supply_type = 1
1284 GROUP BY lpn_id
1285 ,inventory_item_id
1286 ,transaction_uom
1287 ,revision
1288 ,lot_number
1289 ,dest_locator
1290 ,into_lpn_id
1291 ,BACKORDER_DELIVERY_DETAIL
1292 ,WIP_JOB
1293 ,WIP_LINE
1294 ,WIP_DEPT
1295 ,WIP_OP_SEQ
1296 ,WIP_ENTITY_TYPE
1297 ,WIP_START_DATE
1298 ,WIP_SCHEDULE
1299 ,WIP_ASSEMBLY;
1300
1301 CURSOR c_group_tasks_cursor IS
1302 SELECT lpn_id
1303 ,inventory_item_id
1304 ,transaction_uom
1305 ,revision
1306 ,lot_number
1307 ,dest_locator
1308 ,BACKORDER_DELIVERY_DETAIL
1309 ,into_lpn_id
1310 ,drop_order
1311 ,WIP_JOB
1312 ,WIP_LINE
1313 ,WIP_DEPT
1314 ,WIP_OP_SEQ
1315 ,WIP_ENTITY_TYPE
1316 ,WIP_START_DATE
1317 ,WIP_SCHEDULE
1318 ,WIP_ASSEMBLY
1319 FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
1320 WHERE drop_type = G_DT_ITEM_DROP
1321 AND row_type = G_ROW_TP_GROUP_TASK;
1322
1323 BEGIN
1324
1325 IF (l_debug = 1) THEN
1326 DEBUG('Start of Function ', l_proc_name,9);
1327 END IF;
1328 l_progress := '100';
1329
1330
1331 -- Actual logic here
1332 -- Insert the group task rows -- first for the normal tasks
1333 -- and then for tasks that are cross docked to wip issue
1334
1335 OPEN c_group_item_drop_tasks_cursor;
1336 l_progress := '110';
1337
1338 LOOP --c_group_item_drop_tasks_cursor
1339
1340 EXIT WHEN c_group_item_drop_tasks_cursor%NOTFOUND;
1341 l_progress := '200';
1342
1343 FETCH c_group_item_drop_tasks_cursor
1344 BULK COLLECT
1345 INTO l_rowid_tab
1346 ,l_drop_order_tab
1347 ,l_txn_qty_tab
1348 ,l_pri_qty_tab
1349 ,l_sec_qty_tab --OPM Convergence
1350 ,l_show_message_tab --R12
1351 ,l_error_code_tab --R12
1352 ,l_drop_lpn_option_tab --R12
1353 ,l_consolidation_method_id_tab --R12
1354 LIMIT l_limit;
1355 l_progress := '210';
1356
1357 -- Insert group task row into temp table
1358 /* Note: OPM Convergence Not passing l_sec_qty_tabl to insert_group_tasks,
1359 since this table will not be used in that function
1360 */
1361 l_cur_count := Insert_Group_Tasks (
1362 l_rowid_tab => l_rowid_tab
1363 ,l_txn_qty_tab => l_txn_qty_tab
1364 ,l_pri_qty_tab => l_pri_qty_tab
1365 ,l_drop_order_tab => l_drop_order_tab
1366 ,l_show_message_tab=> l_show_message_tab --R12
1367 ,l_error_code_tab => l_error_code_tab --R12
1368 ,l_drop_lpn_option_tab => l_drop_lpn_option_tab --R12
1369 ,l_consolidation_method_id_tab => l_consolidation_method_id_tab); --R12
1370
1371 l_progress := '230';
1372
1373 -- Check for errors while inserting group task row
1374 IF l_cur_count = -1 THEN
1375 l_progress := '232';
1376 RAISE fnd_api.g_exc_unexpected_error;
1377 END IF;
1378
1379 l_rec_count := l_rec_count + l_cur_count;
1380 l_progress := '235';
1381
1382 IF (l_debug = 1) THEN
1383 DEBUG( l_cur_count|| ' Group task Row(s) inserted in WMS_PUTAWAY_GROUP_TASKS_GTMP '
1384 ,l_proc_name,9);
1385 END IF;
1386 l_progress := '240';
1387
1388 END LOOP;--c_group_item_drop_tasks_cursor
1389
1390 l_progress := '250';
1391 CLOSE c_group_item_drop_tasks_cursor;
1392 l_progress := '260';
1393
1394
1395 OPEN c_wip_item_drop_tasks_cursor;
1396 l_progress := '305';
1397
1398 LOOP --c_wip_item_drop_tasks_cursor
1399
1400 EXIT WHEN c_wip_item_drop_tasks_cursor%NOTFOUND;
1401 l_progress := '308';
1402
1403 FETCH c_wip_item_drop_tasks_cursor
1404 BULK COLLECT
1405 INTO l_rowid_tab
1406 ,l_drop_order_tab
1407 ,l_txn_qty_tab
1408 ,l_pri_qty_tab
1409 ,l_sec_qty_tab --OPM Convergence
1410 ,l_show_message_tab --R12
1411 ,l_error_code_tab --R12
1412 ,l_drop_lpn_option_tab --R12
1413 ,l_consolidation_method_id_tab --R12
1414 LIMIT l_limit;
1415 l_progress := '310';
1416
1417 -- Reset the counter for cur tasks count
1418 l_cur_count := 0;
1419 l_progress := '320';
1420
1421 -- Insert group task row into temp table
1422 l_cur_count := Insert_Group_Tasks (
1423 l_rowid_tab => l_rowid_tab
1424 ,l_txn_qty_tab => l_txn_qty_tab
1425 ,l_pri_qty_tab => l_pri_qty_tab
1426 ,l_drop_order_tab => l_drop_order_tab
1427 ,l_show_message_tab=> l_show_message_tab
1428 ,l_error_code_tab => l_error_code_tab
1429 ,l_drop_lpn_option_tab => l_drop_lpn_option_tab --R12
1430 ,l_consolidation_method_id_tab => l_consolidation_method_id_tab); --R12
1431 l_progress := '330';
1432
1433 -- Check for errors while inserting group task row
1434 IF l_cur_count = -1 THEN
1435 l_progress := '332';
1436 RAISE fnd_api.g_exc_unexpected_error;
1437 END IF;
1438
1439 l_rec_count := l_rec_count + l_cur_count;
1440 l_progress := '335';
1441
1442 IF (l_debug = 1) THEN
1443 DEBUG( l_cur_count|| ' Group task Row(s) inserted in WMS_PUTAWAY_GROUP_TASKS_GTMP for crossdocked to WIP ISSUE tasks'
1444 ,l_proc_name,9);
1445 END IF;
1446 l_progress := '340';
1447
1448 END LOOP;--c_wip_item_drop_tasks_cursor
1449
1450 l_progress := '350';
1451 CLOSE c_wip_item_drop_tasks_cursor;
1452 l_progress := '360';
1453
1454 BEGIN -- This will create link between 'Group Task' which was inserteed above with its corresponding 'All Task' rows
1455
1456 OPEN c_group_tasks_cursor;
1457 l_progress := '600';
1458
1459 LOOP --c_group_tasks_cursor
1460
1461 EXIT WHEN c_group_tasks_cursor%NOTFOUND;
1462 l_progress := '610';
1463
1464 FETCH c_group_tasks_cursor
1465 BULK COLLECT
1466 INTO l_lpn_id_tab
1467 ,l_inventory_item_id_tab
1468 ,l_transaction_uom_tab
1469 ,l_revision_tab
1470 ,l_lot_number_tab
1471 ,l_dest_locator_tab
1472 ,l_bk_dl_detail_tab
1473 ,l_into_lpn_id_tab
1474 ,l_out_drop_order_tab
1475 ,l_job_tab
1476 ,l_line_tab
1477 ,l_dept_tab
1478 ,l_operation_seq_num_tab
1479 ,l_wip_entity_type_tab
1480 ,l_start_date_tab
1481 ,l_schedule_tab
1482 ,l_assembly_tab
1483 LIMIT l_limit;
1484 l_progress := '620';
1485
1486
1487 FORALL i IN 1 ..l_lpn_id_tab.COUNT
1488 UPDATE WMS_PUTAWAY_GROUP_TASKS_GTMP
1489 SET drop_order = l_out_drop_order_tab(i)
1490 WHERE drop_type = G_DT_ITEM_DROP
1491 AND lpn_id = l_lpn_id_tab(i)
1492 AND inventory_item_id = l_inventory_item_id_tab(i)
1493 AND transaction_uom = l_transaction_uom_tab(i)
1494 AND NVL(revision,'@@@') = NVL(l_revision_tab(I), '@@@')
1495 AND NVL(lot_number,'@@@') = NVL(l_lot_number_tab(i),'@@@')
1496 AND NVL(dest_locator,-999) = NVL(l_dest_locator_tab(i),-999)
1497 --AND NVL(BACKORDER_DELIVERY_DETAIL,-999) = NVL(l_bk_dl_detail_tab(i),-999) --Commented for bug 5286880
1498 AND Decode(BACKORDER_DELIVERY_DETAIL,NULL,-999,0,-999,Decode(row_type,g_row_tp_all_task,get_grouping(backorder_delivery_detail),backorder_delivery_detail)) = NVL(l_bk_dl_detail_tab(i),-999)
1499 AND NVL(into_lpn_id,-999) = NVL(l_into_lpn_id_tab(i),-999)
1500 AND NVL(wip_job,'@@@') = NVL(l_job_tab(i),'@@@')
1501 AND NVL(wip_line,'@@@') = NVL(l_line_tab(i),'@@@')
1502 AND NVL(wip_dept,'@@@') = NVL(l_dept_tab(i),'@@@')
1503 AND NVL(wip_op_seq,-999) = NVL(l_operation_seq_num_tab(i),-999)
1504 AND NVL(wip_entity_type,-999) = NVL(l_wip_entity_type_tab(i),-999)
1505 AND NVL(wip_start_date,SYSDATE) = NVL(l_start_date_tab(i),SYSDATE)
1506 AND NVL(wip_schedule,'@@@') = NVL(l_schedule_tab(i),'@@@')
1507 AND NVL(wip_assembly,'@@@') = NVL(l_assembly_tab(i),'@@@');
1508
1509 l_progress := '640';
1510
1511 l_rec_count := l_rec_count + sql%rowcount;
1512 IF (l_debug = 1) THEN
1513 DEBUG(sql%rowcount || ' Group task Row(s) updated in WMS_PUTAWAY_GROUP_TASKS_GTMP '
1514 ,l_proc_name,9);
1515 END IF;
1516
1517 l_progress := '650';
1518
1519 END LOOP; --loop through all the group tasks
1520
1521 CLOSE c_group_tasks_cursor;
1522 l_progress := '680';
1523
1524
1525 EXCEPTION
1526 WHEN OTHERS THEN
1527 RAISE fnd_api.g_exc_unexpected_error;
1528 END;
1529
1530
1531 IF (l_debug = 1) THEN
1532 DEBUG(' l_rec_count => '|| l_rec_count,l_proc_name,4);
1533 DEBUG(' Function Exited at ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
1534 END IF;
1535
1536 l_progress := '1000';
1537 RETURN l_rec_count;
1538
1539 EXCEPTION
1540 WHEN fnd_api.g_exc_unexpected_error THEN
1541 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
1542 DEBUG(SQLERRM,l_proc_name,1);
1543
1544 IF c_group_item_drop_tasks_cursor%isopen THEN
1545 CLOSE c_group_item_drop_tasks_cursor;
1546 END IF;
1547
1548 IF c_group_tasks_cursor%isopen THEN
1549 CLOSE c_group_tasks_cursor;
1550 END IF;
1551
1552 IF c_wip_item_drop_tasks_cursor%isopen THEN
1553 CLOSE c_wip_item_drop_tasks_cursor;
1554 END IF;
1555
1556 RETURN -1;
1557
1558
1559 WHEN OTHERS THEN
1560 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
1561 DEBUG(SQLERRM,l_proc_name,1);
1562
1563 IF c_group_item_drop_tasks_cursor%isopen THEN
1564 CLOSE c_group_item_drop_tasks_cursor;
1565 END IF;
1566
1567 IF c_group_tasks_cursor%isopen THEN
1568 CLOSE c_group_tasks_cursor;
1569 END IF;
1570
1571 IF c_wip_item_drop_tasks_cursor%isopen THEN
1572 CLOSE c_wip_item_drop_tasks_cursor;
1573 END IF;
1574
1575 RETURN -1;
1576 END Group_Item_Drop_Tasks;
1577
1578
1579
1580 /**
1581 * This function will group the tasks and will stamp the
1582 * drop_type properly as item drop/consolidated
1583 * drop('ID'/'CD'). The logic is
1584 *
1585 * Loop through all the lpns starting from the innermost LPN
1586 * If drop type = consolidated drop then
1587 * Mark item drop if the contents go to diff location or
1588 * has different to lpn.
1589 * Mark item drop if there are some contents which
1590 * doesn't have allocations (under allocation case)
1591 *
1592 * If parent exists
1593 * get drop_type, dest sub/loc of parent
1594 *
1595 * if drop type = consolidated then
1596 * if the dest sub/loc is null then
1597 * update it with childs dest sub/loc
1598 * else if it is different from childs
1599 * mark item drop for the parent
1600 *
1601 * This will return the number of rows processed as
1602 * output.This will return -1 in case of failure.
1603
1604 * @ RETURN NUMBER
1605
1606
1607 **/
1608 FUNCTION Populate_Drop_Type
1609 RETURN NUMBER
1610 IS
1611 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
1612 l_progress VARCHAR2(10) := '10';
1613 l_proc_name VARCHAR2(30) := 'Populate_Drop_Type:';
1614 l_rec_count NUMBER := 0;
1615
1616 l_lpn_id_tab num_tab;
1617 l_into_lpn_id_tab num_tab;
1618 l_into_lpn_name_tab lpn_name_tab;
1619 l_parent_lpn_id_tab num_tab;
1620 l_dest_sub_tab sub_name_tab;
1621 l_dest_loc_tab num_tab;
1622 l_lpn_level_tab num_tab;
1623 l_row_type_tab row_type_tab;
1624 l_rowid_tab rowid_tab;
1625
1626 l_parent_dest_sub VARCHAR2(10);
1627 l_parent_dest_loc NUMBER;
1628 l_parent_drop_order NUMBER;
1629 l_parent_into_lpn_id NUMBER;
1630 l_drop_order NUMBER := 0;
1631 l_parent_into_lpn_name VARCHAR2(30);
1632
1633 l_rowid urowid;
1634
1635 l_loc_count NUMBER := 0;
1636 l_to_lpn_count NUMBER := 0;
1637 l_qty_disc_count NUMBER := 0;
1638
1639
1640 -- WIP related variables
1641
1642 l_del_detail_id_count NUMBER := 0;
1643 l_wip_job_count NUMBER := 0;
1644 l_wip_line_count NUMBER := 0;
1645 l_wip_dept_count NUMBER := 0;
1646 l_wip_op_seq_count NUMBER := 0;
1647 l_wip_entity_type_count NUMBER := 0;
1648 l_wip_start_date_count NUMBER := 0;
1649 l_wip_schedule_count NUMBER := 0;
1650 l_wip_assembly_count NUMBER := 0;
1651
1652 l_job WIP_ENTITIES.WIP_ENTITY_NAME%TYPE;
1653 l_line WIP_LINES.LINE_CODE%TYPE;
1654 l_dept BOM_DEPARTMENTS.DEPARTMENT_CODE%TYPE;
1655 l_operation_seq_num NUMBER;
1656 l_wip_entity_type NUMBER;
1657 l_start_date DATE;
1658 l_schedule WIP_ENTITIES.WIP_ENTITY_NAME%TYPE;
1659 l_assembly MTL_SYSTEM_ITEMS_KFV.CONCATENATED_SEGMENTS%TYPE;
1660 l_wip_entity_id NUMBER;
1661
1662 l_crossdock_type NUMBER;
1663 l_backorder_delivery_detail NUMBER;
1664 l_wip_supply_type NUMBER;
1665
1666 l_crossdock_type_tab num_tab;
1667 l_bk_dl_detail_tab num_tab;
1668 l_wip_supply_type_tab num_tab;
1669 l_wip_entity_type_tab num_tab;
1670 l_job_tab entity_tab;
1671 l_line_tab line_tab;
1672 l_dept_tab dept_tab;
1673 l_operation_seq_num_tab num_tab;
1674 l_start_date_tab date_tab;
1675 l_schedule_tab entity_tab;
1676 l_assembly_tab item_tab;
1677 l_wip_entity_id_tab num_tab;
1678
1679 l_drop_order_tab num_tab;
1680 l_outermost_lpn_id_tab num_tab;
1681
1682 --BUG 3435079: Used to retrieve WLPN info
1683 l_wpgtt_lpn_id_tab lpn_name_tab;
1684
1685 l_lpn_name_tab lpn_name_tab;
1686 l_parent_lpn_name_tab lpn_name_tab;
1687 l_outermost_lpn_name_tab lpn_name_tab;
1688
1689 --Bug 5286880
1690 l_grouping_count NUMBER;
1691 l_count NUMBER;
1692
1693
1694 -- This cursor will select all the levels in the temp table
1695 -- For which the drop type is 'CD'
1696 CURSOR c_lpn_level_cursor IS
1697 SELECT DISTINCT
1698 lpn_level
1699 FROM wms_putaway_group_tasks_gtmp
1700 WHERE drop_type = G_DT_CONSOLIDATED_DROP
1701 ORDER BY lpn_level DESC;
1702
1703 -- This cursor will get all the LPNs, their dest sub/loc and its parent lpn id where drop_type is CD
1704 -- For the level passed
1705 CURSOR c_lpn_cursor(v_lpn_level NUMBER) IS
1706 SELECT DISTINCT
1707 lpn_id
1708 ,parent_lpn_id
1709 ,dest_subinventory
1710 ,dest_locator
1711 ,into_lpn_id
1712 ,into_lpn_name
1713 ,row_type
1714 ,crossdock_type
1715 ,backorder_delivery_detail
1716 ,wip_supply_type
1717 ,WIP_JOB
1718 ,WIP_LINE
1719 ,WIP_DEPT
1720 ,WIP_OP_SEQ
1721 ,WIP_ENTITY_TYPE
1722 ,WIP_START_DATE
1723 ,WIP_SCHEDULE
1724 ,WIP_ASSEMBLY
1725 FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
1726 WHERE drop_type = G_DT_CONSOLIDATED_DROP
1727 AND lpn_level = v_lpn_level;
1728
1729 -- This cursor will get the rowid, dest sub/loc for the lpn passed where drop type is CD
1730 CURSOR c_parent_lpn_cursor(v_parent_lpn_id NUMBER) IS
1731 SELECT ROWID
1732 ,dest_subinventory
1733 ,dest_locator
1734 ,into_lpn_id
1735 ,into_lpn_name
1736 ,crossdock_type
1737 ,backorder_delivery_detail
1738 ,wip_supply_type
1739 ,WIP_JOB
1740 ,WIP_LINE
1741 ,WIP_DEPT
1742 ,WIP_OP_SEQ
1743 ,WIP_ENTITY_TYPE
1744 ,WIP_START_DATE
1745 ,WIP_SCHEDULE
1746 ,WIP_ASSEMBLY
1747 FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
1748 WHERE lpn_id = v_parent_lpn_id
1749 AND drop_type = G_DT_CONSOLIDATED_DROP
1750 AND ROWNUM < 2;
1751
1752 -- This cursor will get the tasks in proper order and will also be used to resolve
1753 -- the LPN columns.
1754
1755 --BUG 3435079: For performance reason, do not join with WLPN here,
1756 --because the 'order by' clauses forces the DB to do a full table
1757 --scan of WLPN. Retrieval of WLPN info will be done later.
1758 CURSOR c_group_tasks_order_by IS
1759 SELECT wpgtt.ROWID
1760 ,ROWNUM
1761 ,wpgtt.lpn_id lpn_id
1762 FROM wms_putaway_group_tasks_gtmp wpgtt
1763 ORDER BY wpgtt.sub_dropping_order,
1764 wpgtt.dest_subinventory,
1765 wpgtt.loc_dropping_order,
1766 wpgtt.LOCATOR,
1767 wpgtt.inventory_item_id,
1768 wpgtt.revision,
1769 wpgtt.lot_number;
1770
1771
1772 BEGIN
1773 IF (l_debug = 1) THEN
1774 DEBUG('Start of Function ', l_proc_name,9);
1775 END IF;
1776
1777 BEGIN --Block to stamp the drop_order
1778
1779 IF (l_debug = 1) THEN
1780 DEBUG('Stamping the drop_order and resolving the lpn columns ',l_proc_name,9);
1781 END IF;
1782
1783 l_progress := '20';
1784 OPEN c_group_tasks_order_by;
1785 l_progress := '30';
1786
1787 LOOP -- c_group_tasks_order_by cursor
1788
1789 EXIT WHEN c_group_tasks_order_by%NOTFOUND;
1790
1791 l_progress := '40';
1792 FETCH c_group_tasks_order_by
1793 BULK COLLECT
1794 INTO l_rowid_tab
1795 ,l_drop_order_tab
1796 ,l_wpgtt_lpn_id_tab
1797 LIMIT l_limit;
1798 l_progress := '50';
1799
1800 --Stamp the drop_order in the temp table
1801 FOR i IN 1..l_rowid_tab.COUNT
1802 LOOP
1803
1804 -- Increment the drop order
1805 l_drop_order := l_drop_order + 1;
1806 l_progress := '60';
1807
1808 --BUG 3435079: For performance reason, get the
1809 --LPN info here, instead of getting it in the
1810 --c_group_tasks_order_by cursor
1811 BEGIN
1812 SELECT
1813 wlpn1.license_plate_number lpn_name
1814 ,wlpn2.lpn_id parent_lpn_id
1815 ,wlpn2.license_plate_number parent_lpn_name
1816 ,wlpn3.lpn_id outermost_lpn_id
1817 ,wlpn3.license_plate_number outermost_lpn_name
1818 INTO
1819 l_lpn_name_tab(i)
1820 ,l_parent_lpn_id_tab(i)
1821 ,l_parent_lpn_name_tab(i)
1822 ,l_outermost_lpn_id_tab(i)
1823 ,l_outermost_lpn_name_tab(i)
1824 FROM
1825 wms_license_plate_numbers wlpn1
1826 ,wms_license_plate_numbers wlpn2
1827 ,wms_license_plate_numbers wlpn3
1828 WHERE
1829 wlpn1.lpn_id = l_wpgtt_lpn_id_tab(i)
1830 AND wlpn1.outermost_lpn_id = wlpn3.lpn_id
1831 AND wlpn2.lpn_id(+) = wlpn1.parent_lpn_id;
1832 EXCEPTION
1833 WHEN too_many_rows THEN
1834 IF (l_debug = 1) THEN
1835 DEBUG('Too many rows returned when getting LPN, parent lpn, outermost lpn info' || l_parent_lpn_id_tab(i),l_proc_name,9);
1836 END IF;
1837 WHEN no_data_found THEN
1838 IF (l_debug = 1) THEN
1839 DEBUG('No rows returned when getting LPN, parent lpn, outermost lpn info' || l_parent_lpn_id_tab(i),l_proc_name,9);
1840 END IF;
1841 WHEN OTHERS THEN
1842 IF (l_debug = 1) THEN
1843 DEBUG('Other exception occurred when getting LPN, parent lpn, outermost lpn info' || l_parent_lpn_id_tab(i),l_proc_name,9);
1844 END IF;
1845 END;
1846
1847 -- update the drop order and LPN columns back to temp table
1848 UPDATE wms_putaway_group_tasks_gtmp
1849 SET drop_order = l_drop_order
1850 ,lpn_name = l_lpn_name_tab(i)
1851 ,parent_lpn_id = l_parent_lpn_id_tab(i)
1852 ,parent_lpn_name = l_parent_lpn_name_tab(i)
1853 ,outermost_lpn_id = l_outermost_lpn_id_tab(i)
1854 ,outermost_lpn_name = l_outermost_lpn_name_tab(i)
1855 WHERE ROWID = l_rowid_tab(i);
1856 l_progress := '65';
1857 END LOOP;
1858
1859 l_progress := '70';
1860
1861 END LOOP; -- c_group_tasks_order_by cursor
1862
1863 CLOSE c_group_tasks_order_by;
1864 l_progress := '75';
1865
1866 EXCEPTION
1867 WHEN OTHERS THEN
1868 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
1869 DEBUG(SQLERRM,l_proc_name,1);
1870
1871 IF c_group_tasks_order_by%isopen THEN
1872 CLOSE c_group_tasks_order_by;
1873 END IF;
1874
1875 RETURN -1;
1876 END; --Block to stamp the drop_order
1877
1878
1879 OPEN c_lpn_level_cursor;
1880
1881 FETCH c_lpn_level_cursor
1882 BULK COLLECT INTO
1883 l_lpn_level_tab;
1884
1885 CLOSE c_lpn_level_cursor;
1886
1887
1888 FOR i IN 1 .. l_lpn_level_tab.COUNT
1889 LOOP --lpn level cursor
1890
1891 l_progress := '100';
1892 OPEN c_lpn_cursor(l_lpn_level_tab(i));
1893
1894 l_progress := '110';
1895
1896 LOOP --c_lpn_cursor loop
1897
1898
1899 EXIT WHEN c_lpn_cursor%NOTFOUND;
1900 l_progress := '120';
1901
1902 l_progress := '130';
1903 FETCH c_lpn_cursor
1904 BULK COLLECT
1905 INTO l_lpn_id_tab
1906 ,l_parent_lpn_id_tab
1907 ,l_dest_sub_tab
1908 ,l_dest_loc_tab
1909 ,l_into_lpn_id_tab
1910 ,l_into_lpn_name_tab
1911 ,l_row_type_tab
1912 ,l_crossdock_type_tab
1913 ,l_bk_dl_detail_tab
1914 ,l_wip_supply_type_tab
1915 ,l_job_tab
1916 ,l_line_tab
1917 ,l_dept_tab
1918 ,l_operation_seq_num_tab
1919 ,l_wip_entity_type_tab
1920 ,l_start_date_tab
1921 ,l_schedule_tab
1922 ,l_assembly_tab
1923 LIMIT l_limit;
1924 l_progress := '140';
1925
1926
1927 FOR i IN 1 .. l_lpn_id_tab.COUNT
1928 LOOP --lpn_cursor_bulk collect loop
1929
1930 -- Do all the checks only if the drop type is consolidated drop
1931 --IF l_drop_type = G_DT_CONSOLIDATED_DROP THEN
1932
1933 -- Check whether all the contents go to the same location
1934 -- and whether the suggested to_lpn is same for all the contents within that LPN
1935 BEGIN -- Check for destination locator/LPN
1936
1937 --Don't do these checks for a dummy LPN record since it won't have any contents, MTRL or MMTT
1938 IF l_row_type_tab(i) <> G_ROW_TP_LPN_TASK THEN --dummy record check
1939
1940 IF (l_debug = 1) THEN
1941 DEBUG('Checking whether CD is possible (check for dest loc/LPN Discrepancy) for LPN ' || l_lpn_id_tab(i),l_proc_name,9);
1942 END IF;
1943
1944 l_progress := 145;
1945 SELECT COUNT(DISTINCT NVL(transfer_to_location,locator_id))
1946 ,COUNT(DISTINCT cartonization_id)
1947 INTO l_loc_count
1948 ,l_to_lpn_count
1949 FROM mtl_material_transactions_temp mmtt
1950 ,mtl_txn_request_lines mtrl
1951 WHERE mmtt.move_order_line_id = mtrl.line_id
1952 AND mtrl.lpn_id = l_lpn_id_tab(i);
1953 l_progress := '150';
1954
1955 --Begin bug 5286880
1956 l_count := populate_grouping_rows(l_lpn_id_tab(i));
1957 l_grouping_count := get_grouping_count(g_grouping_rows);
1958 IF (l_debug = 1) THEN
1959 debug('l_grouping_count='||l_grouping_count, l_proc_name, 9);
1960 END IF;
1961 --End bug 5286880
1962
1963
1964 -- If there are no suggestions. This case maynot be possible
1965 -- but still checking this for safety
1966 IF l_loc_count = 0 THEN
1967 l_progress := '160';
1968
1969 IF (l_debug = 1) THEN
1970 DEBUG('There are no MMTTs for this LPN and hence erroring out ' || l_lpn_id_tab(i),l_proc_name,9);
1971 END IF;
1972
1973 RETURN -1;
1974 END IF;
1975
1976 --IF l_loc_count > 1 OR l_to_lpn_count > 1 THEN
1977 --Commented for bug 5286880 and added one more condition for l_grouping_count
1978 IF l_loc_count > 1 OR l_to_lpn_count > 1 OR l_grouping_count > 1 THEN
1979
1980 IF (l_debug = 1) THEN
1981 DEBUG('Either locator or LPN Discrepancy. Hence calling Mark Item Drop for LPN ' || l_lpn_id_tab(i),l_proc_name,9);
1982 END IF;
1983
1984 l_progress := '170';
1985
1986 -- The contents either doesn't go to same location or same TO LPN
1987 -- and hence can't be dropped by consolidated drop. So mark item drop
1988 -- for the lpn and its parents.
1989 l_rec_count := l_rec_count + Mark_Item_Drop(l_lpn_id_tab(i));
1990
1991 l_progress := '180';
1992
1993
1994 IF l_rec_count = -1 THEN
1995 l_progress := '190';
1996
1997 IF (l_debug = 1) THEN
1998 DEBUG('Mark Item Drop Returned Error and hence Exiting.. ',l_proc_name,9);
1999 END IF;
2000
2001 RETURN -1;
2002 END IF;
2003
2004 END IF; --loc/to_lpn count check
2005 END IF; --dummy record check
2006 EXCEPTION
2007 WHEN OTHERS THEN
2008 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
2009 DEBUG(SQLERRM,l_proc_name,1);
2010 RETURN -1;
2011 END; -- Check for destination locator/LPN
2012
2013
2014 -- Check whether there are any other contents in that LPN
2015 -- which don't have MMTT or allocations is less.
2016 -- In this case we can't do a consolidated drop but have to do an item drop.
2017 BEGIN -- Check for other contents/under allocation of the LPN
2018
2019 BEGIN
2020 l_progress := '200';
2021
2022 --Don't do these checks for a dummy LPN record since it won't have any contents, MTRL or MMTT
2023 IF l_row_type_tab(i) <> G_ROW_TP_LPN_TASK THEN --dummy record check
2024
2025 IF (l_debug = 1) THEN
2026 DEBUG('Checking whether CD is possible (check qty disc) for LPN ' || l_lpn_id_tab(i),l_proc_name,9);
2027 END IF;
2028
2029 -- This SQL will check whether there are any incomplete allocations for the LPn passed
2030 -- Incomplete allocation may be partial allocation or no allocation.
2031 l_progress := '205';
2032
2033 SELECT 1
2034 INTO l_qty_disc_count
2035 FROM dual
2036 WHERE EXISTS (
2037 SELECT mtrl.line_id
2038 FROM mtl_txn_request_lines mtrl
2039 ,mtl_txn_request_headers mtrh
2040 WHERE 1 = 1
2041 AND mtrl.header_id = mtrh.header_id
2042 AND mtrh.move_order_type = 6
2043 AND mtrl.lpn_id = l_lpn_id_tab(i)
2044 AND mtrl.line_status = 7 --BUG 3352572
2045 AND ((NOT exists
2046 (SELECT 1
2047 FROM mtl_material_transactions_temp mmtt1
2048 WHERE mtrl.line_status = 7
2049 AND mmtt1.move_order_line_id = mtrl.line_id)
2050 ) OR
2051 (( (NVL(quantity,0) - NVL(quantity_delivered,0) ) )
2052 > (SELECT SUM(transaction_quantity)
2053 FROM mtl_material_transactions_temp mmtt
2054 WHERE mtrl.line_status = 7
2055 AND mmtt.move_order_line_id = mtrl.line_id
2056 ))
2057 )
2058 );
2059
2060
2061 l_progress := '210';
2062 END IF;--dummy record check
2063 EXCEPTION
2064 WHEN no_data_found THEN
2065 l_qty_disc_count :=0;
2066 l_progress := '215';
2067 END;
2068
2069
2070 IF l_qty_disc_count = 1 THEN
2071 -- reset the flag
2072 l_qty_disc_count := 0;
2073
2074 IF (l_debug = 1) THEN
2075 DEBUG('Quantity Discrepancy and hence calling Mark Item Drop for LPN ' || l_lpn_id_tab(i),l_proc_name,9);
2076 END IF;
2077
2078
2079 l_progress := '220';
2080
2081 -- The contents haven't been allocated fully
2082 -- and hence can't be dropped by consolidated drop. So mark item drop
2083 -- for the lpn and its parents.
2084 l_rec_count := l_rec_count + Mark_Item_Drop(l_lpn_id_tab(i));
2085 l_progress := '230';
2086
2087 END IF;
2088
2089 EXCEPTION
2090 WHEN OTHERS THEN
2091 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
2092 DEBUG(SQLERRM,l_proc_name,1);
2093 RETURN -1;
2094 END; -- Check for other contents/under allocation of the LPN
2095
2096
2097 BEGIN --wip_integration
2098
2099 -- Get the count of crossdocks for all those rows which crossdocked to wip issue
2100 -- for the current lpn being processed
2101 l_progress := '250';
2102 SELECT COUNT(DISTINCT BACKORDER_DELIVERY_DETAIL)
2103 ,COUNT(DISTINCT WIP_JOB)
2104 ,COUNT(DISTINCT WIP_LINE)
2105 ,COUNT(DISTINCT WIP_DEPT)
2106 ,COUNT(DISTINCT WIP_OP_SEQ)
2107 ,COUNT(DISTINCT WIP_ENTITY_TYPE)
2108 ,COUNT(DISTINCT WIP_START_DATE)
2109 ,COUNT(DISTINCT WIP_SCHEDULE)
2110 ,COUNT(DISTINCT WIP_ASSEMBLY)
2111 INTO l_del_detail_id_count
2112 ,l_wip_job_count
2113 ,l_wip_line_count
2114 ,l_wip_dept_count
2115 ,l_wip_op_seq_count
2116 ,l_wip_entity_type_count
2117 ,l_wip_start_date_count
2118 ,l_wip_schedule_count
2119 ,l_wip_assembly_count
2120 FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
2121 WHERE row_type = G_ROW_TP_ALL_TASK
2122 AND crossdock_type > 1
2123 AND backorder_delivery_detail > 0
2124 AND wip_supply_type = 1
2125 AND lpn_id = l_lpn_id_tab(i);
2126
2127 l_progress := '260';
2128
2129 -- Check for consolidation drop based on number of crossdocks
2130 IF(l_del_detail_id_count > 1 OR
2131 l_wip_job_count > 1 OR
2132 l_wip_line_count > 1 OR
2133 l_wip_dept_count > 1 OR
2134 l_wip_op_seq_count > 1 OR
2135 l_wip_entity_type_count > 1 OR
2136 l_wip_start_date_count > 1 OR
2137 l_wip_schedule_count > 1 OR
2138 l_wip_assembly_count > 1
2139 ) THEN
2140
2141 -- Crossdocked to diff job/schedule/assembly/.... hence it is item drop
2142 l_progress := '265';
2143
2144 IF (l_debug = 1) THEN
2145 DEBUG('Cross docked to different job/schedule/op seq/assmebly... and hence calling Mark Item Drop for LPN ' || l_lpn_id_tab(i),l_proc_name,9);
2146 END IF;
2147
2148 l_rec_count := l_rec_count + Mark_Item_Drop(l_lpn_id_tab(i));
2149 l_progress := '270';
2150
2151 END IF; -- same job details check
2152
2153 EXCEPTION
2154 WHEN OTHERS THEN
2155 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
2156 DEBUG(SQLERRM,l_proc_name,1);
2157 RETURN -1;
2158 END; --wip_integration
2159
2160
2161 -- Get the parent record
2162 BEGIN
2163 l_progress := '300';
2164
2165 IF l_parent_lpn_id_tab(i) IS NOT NULL THEN
2166
2167 l_progress := '310';
2168 -- Get the details of the parent lpn record
2169 OPEN c_parent_lpn_cursor(l_parent_lpn_id_tab(i));
2170 l_progress := '320';
2171
2172 FETCH c_parent_lpn_cursor
2173 INTO l_rowid
2174 ,l_parent_dest_sub
2175 ,l_parent_dest_loc
2176 ,l_parent_into_lpn_id
2177 ,l_parent_into_lpn_name
2178 ,l_crossdock_type
2179 ,l_backorder_delivery_detail
2180 ,l_wip_supply_type
2181 ,l_job
2182 ,l_line
2183 ,l_dept
2184 ,l_operation_seq_num
2185 ,l_wip_entity_type
2186 ,l_start_date
2187 ,l_schedule
2188 ,l_assembly;
2189 l_progress := '330';
2190
2191 CLOSE c_parent_lpn_cursor;
2192
2193 -- If there is no parent, check that case and we should not exit out of the loop
2194 -- We should proceed with the next record and hence the exit is commented out.
2195 --EXIT WHEN c_parent_lpn_cursor%NOTFOUND;
2196
2197 -- If the parent record exists
2198 IF l_rowid IS NOT NULL THEN
2199 l_progress := '340';
2200
2201 -- Check if the dest locator is null or into LPN is null for the parent
2202 -- Parent dest loc can be null only if it is a dummy row in that case even the into lpn id will be null
2203 -- checking it again for safety
2204 -- wip_supply_type <> 1 check was added to ensure that you select the dummy rows alone
2205 -- for LPNs which are crossdocked to wip issue (since dest_loc_id and dest_lpn_id can be null for this case)
2206 IF ( (l_parent_dest_loc IS NULL) AND
2207 (l_parent_into_lpn_id IS NULL) AND
2208 (l_wip_supply_type <> 1) ) THEN
2209 l_progress := '350';
2210
2211 -- Dest sub/loc of the parent is null and hence update the dest sub/loc with that of childs
2212 UPDATE WMS_PUTAWAY_GROUP_TASKS_GTMP
2213 SET dest_subinventory = l_dest_sub_tab(i)
2214 ,dest_locator = l_dest_loc_tab(i)
2215 ,into_lpn_id = l_into_lpn_id_tab(i)
2216 ,into_lpn_name = l_into_lpn_name_tab(i)
2217 ,crossdock_type = l_crossdock_type_tab(i)
2218 ,backorder_delivery_detail = l_bk_dl_detail_tab(i)
2219 ,wip_supply_type = l_wip_supply_type_tab(i)
2220 ,WIP_JOB = l_job_tab(i)
2221 ,WIP_LINE = l_line_tab(i)
2222 ,WIP_DEPT = l_dept_tab(i)
2223 ,WIP_OP_SEQ = l_operation_seq_num_tab(i)
2224 ,WIP_ENTITY_TYPE = l_wip_entity_type_tab(i)
2225 ,WIP_START_DATE = l_start_date_tab(i)
2226 ,WIP_SCHEDULE = l_schedule_tab(i)
2227 ,WIP_ASSEMBLY = l_assembly_tab(i)
2228 WHERE ROWID = l_rowid;
2229 l_progress := '360';
2230
2231 IF (l_debug = 1) THEN
2232 DEBUG('Parent Dest loc for LPN ' || l_lpn_id_tab(i) || ' updated with dest_locator ' || l_dest_loc_tab(i) ,l_proc_name,9);
2233 DEBUG('Parent Dest LPN for LPN ' || l_lpn_id_tab(i) || ' updated with into_lpn ' || l_into_lpn_id_tab(i) ,l_proc_name,9);
2234 DEBUG('Parent crossdock_type for LPN ' || l_lpn_id_tab(i) || ' updated with ' || l_crossdock_type_tab(i) ,l_proc_name,9);
2235 DEBUG('Parent backorder_delivery_detail for LPN ' || l_lpn_id_tab(i) || ' updated with ' || l_bk_dl_detail_tab(i) ,l_proc_name,9);
2236 DEBUG('Parent wip_supply_type for LPN ' || l_lpn_id_tab(i) || ' updated with ' || l_wip_supply_type_tab(i) ,l_proc_name,9);
2237 DEBUG('Parent WIP_JOB for LPN ' || l_lpn_id_tab(i) || ' updated with ' || l_job_tab(i) ,l_proc_name,9);
2238 DEBUG('Parent WIP_LINE for LPN ' || l_lpn_id_tab(i) || ' updated with ' || l_line_tab(i) ,l_proc_name,9);
2239 DEBUG('Parent WIP_DEPT for LPN ' || l_lpn_id_tab(i) || ' updated with ' || l_dept_tab(i) ,l_proc_name,9);
2240 DEBUG('Parent WIP_OP_SEQ for LPN ' || l_lpn_id_tab(i) || ' updated with ' || l_operation_seq_num_tab(i) ,l_proc_name,9);
2241 DEBUG('Parent WIP_ENTITY_TYPE for LPN ' || l_lpn_id_tab(i) || ' updated with ' || l_wip_entity_type_tab(i) ,l_proc_name,9);
2242 DEBUG('Parent WIP_START_DATE for LPN ' || l_lpn_id_tab(i) || ' updated with ' || l_start_date_tab(i) ,l_proc_name,9);
2243 DEBUG('Parent WIP_SCHEDULE for LPN ' || l_lpn_id_tab(i) || ' updated with ' || l_schedule_tab(i) ,l_proc_name,9);
2244 DEBUG('Parent WIP_ASSEMBLY for LPN ' || l_lpn_id_tab(i) || ' updated with ' || l_assembly_tab(i) ,l_proc_name,9);
2245 END IF;
2246
2247
2248 -- Parent record has dest locator/into LPN
2249 ELSE
2250 l_progress := '370';
2251
2252 -- Check the dest loc/into lpn of parent with the child
2253 IF ( (l_parent_dest_loc <> l_dest_loc_tab(i)) OR
2254 (NVL(l_parent_into_lpn_id,-999) <> NVL(l_into_lpn_id_tab(i),-999) ) ) THEN
2255 l_progress := '380';
2256
2257 IF (l_debug = 1) THEN
2258 DEBUG('Loc/Into LPN mismatch with the parent and hence calling Mark Item Drop for parent ' || l_parent_lpn_id_tab(i),l_proc_name,9);
2259 END IF;
2260
2261 -- Dest loc / Into LPN of parent is not equal that of child and hence
2262 -- can't be dropped by consolidated drop. So mark item drop for the Parent.
2263
2264 l_rec_count := l_rec_count + Mark_Item_Drop(l_parent_lpn_id_tab(i));
2265
2266 l_progress := '390';
2267
2268 END IF; -- Dest loc check with child
2269
2270
2271 -- wip_integration
2272 -- WIP Crossdock check (do only if it is crossdocked to wip for a push type
2273 IF ( l_crossdock_type_tab(i) > 1 AND
2274 l_bk_dl_detail_tab(i) > 0 AND
2275 l_wip_supply_type_tab(i) = 1
2276 ) THEN
2277
2278 l_progress := '400';
2279
2280 --Check if parent goes to same job/line/schedule etc.., as that of the child
2281 IF ( l_crossdock_type <> l_crossdock_type_tab(i) OR
2282 l_backorder_delivery_detail <> l_bk_dl_detail_tab(i) OR
2283 l_wip_supply_type <> l_wip_supply_type_tab(i) OR
2284 l_job <> l_job_tab(i) OR
2285 l_line <> l_line_tab(i) OR
2286 l_dept <> l_dept_tab(i) OR
2287 l_operation_seq_num <> l_operation_seq_num_tab(i) OR
2288 l_wip_entity_type <> l_wip_entity_type_tab(i) OR
2289 l_start_date <> l_start_date_tab(i) OR
2290 l_schedule <> l_schedule_tab(i) OR
2291 l_assembly <> l_assembly_tab(i)
2292 ) THEN
2293 -- Dest loc / Into LPN of parent is not equal that of child and hence
2294 -- can't be dropped by consolidated drop. So mark item drop for the Parent.
2295 l_progress := '410';
2296
2297 IF (l_debug = 1) THEN
2298 DEBUG('WIP Details mismatch with the parent and hence calling Mark Item Drop for parent LPN ' || l_parent_lpn_id_tab(i),l_proc_name,9);
2299 END IF;
2300
2301 l_rec_count := l_rec_count + Mark_Item_Drop(l_parent_lpn_id_tab(i));
2302 l_progress := '420';
2303 END IF; --check for parents job/line/schedule etc..,
2304
2305 END IF; --WIP Crosdock check
2306
2307
2308 END IF;-- dest loc / into LPN not null check
2309
2310 END IF; -- l_rowid not null check
2311
2312
2313 END IF; -- parent_lpn_id not null check
2314 l_progress := '400';
2315
2316 EXCEPTION
2317 WHEN OTHERS THEN
2318 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
2319 DEBUG(SQLERRM,l_proc_name,1);
2320
2321 IF c_parent_lpn_cursor%isopen THEN
2322 CLOSE c_parent_lpn_cursor;
2323 END IF;
2324
2325 IF c_lpn_cursor%isopen THEN
2326 CLOSE c_lpn_cursor;
2327 END IF;
2328
2329 RETURN -1;
2330 END;
2331
2332 -- END IF; -- drop type check
2333
2334 END LOOP; --lpn_cursor_bulk collect loop
2335
2336
2337 END LOOP; --c_lpn_cursor loop
2338
2339 CLOSE c_lpn_cursor;
2340
2341 END LOOP;--lpn level cursor
2342
2343
2344 --R12: Revert MDC suggestions for all tasks that is flagged as item drop
2345 BEGIN
2346 UPDATE mtl_material_transactions_temp
2347 SET cartonization_id = NULL
2348 WHERE transaction_temp_id IN (SELECT gtmp.transaction_temp_id
2349 FROM wms_putaway_group_tasks_gtmp gtmp
2350 WHERE gtmp.consolidation_method_id = 1 --???MDC
2351 AND gtmp.drop_type = g_dt_item_drop);
2352
2353 IF (l_debug = 1) THEN
2354 DEBUG('Num of MMTT rows updated:' ||SQL%rowcount,l_proc_name,4);
2355 END IF;
2356
2357 UPDATE wms_putaway_group_tasks_gtmp
2358 SET consolidation_method_id = 0
2359 WHERE consolidation_method_id = 1
2360 AND drop_type = g_dt_item_drop;
2361
2362 IF (l_debug = 1) THEN
2363 DEBUG('Num of GTMP rows updated:' ||SQL%rowcount,l_proc_name,4);
2364 END IF;
2365
2366 EXCEPTION
2367 WHEN OTHERS THEN
2368 IF (l_debug = 1) THEN
2369 DEBUG('ERROR REVERTING MDC SUGGESTIONS',l_proc_name,4);
2370 END IF;
2371 RAISE fnd_api.g_exc_unexpected_error;
2372 END;
2373 --R12 END
2374
2375 l_progress := '500';
2376 IF (l_debug = 1) THEN
2377 DEBUG(' l_rec_count => '|| l_rec_count,l_proc_name,4);
2378 DEBUG(' Function Exited at ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
2379 END IF;
2380 l_progress := '510';
2381
2382 IF c_parent_lpn_cursor%isopen THEN
2383 CLOSE c_parent_lpn_cursor;
2384 END IF;
2385 l_progress := '515';
2386
2387 IF c_lpn_cursor%isopen THEN
2388 CLOSE c_lpn_cursor;
2389 END IF;
2390 l_progress := '520';
2391
2392 -- Return the number of rows populated as item drop in total
2393 RETURN l_rec_count;
2394
2395 EXCEPTION
2396 WHEN OTHERS THEN
2397 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
2398 DEBUG(SQLERRM,l_proc_name,1);
2399
2400 IF c_parent_lpn_cursor%isopen THEN
2401 CLOSE c_parent_lpn_cursor;
2402 END IF;
2403
2404 IF c_lpn_cursor%isopen THEN
2405 CLOSE c_lpn_cursor;
2406 END IF;
2407
2408 RETURN -1;
2409 END Populate_Drop_Type;
2410
2411
2412
2413
2414 /**
2415 * This function will populate the global temporary table
2416 * WMS_PUTAWAY_GROUP_TASKS_GTMP with the required data and
2417 * will return the count of rows in the temporary table as
2418 * output.
2419
2420 * This method will also insert the dummy records for those
2421 * LPN which doesnt have contents
2422
2423 * Drop all scenario is also taken care while inserting
2424 * For drop all case, we will always start with the outermost lpn id.
2425 * because we should be suggesting the consolidated lpn wherever possible
2426
2427 * @param p_org_id Organization ID
2428 * @param p_drop_type Drop Type
2429 * @param p_emp_id Employee ID
2430 * @param p_lpn_id LPN ID
2431 * @ RETURN NUMBER
2432
2433
2434 **/
2435 FUNCTION Populate_Group_Tasks(
2436 p_org_id IN NUMBER,
2437 p_drop_type IN VARCHAR2,
2438 p_emp_id IN NUMBER,
2439 p_lpn_id IN NUMBER,
2440 p_item_drop_flag IN VARCHAR2)
2441 RETURN NUMBER
2442 IS
2443 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
2444 l_progress VARCHAR2(10) := '10';
2445 l_proc_name VARCHAR2(30) := 'Populate_Group_Tasks:';
2446 l_rec_count NUMBER := 0;
2447
2448 l_rowid_tab rowid_tab;
2449 l_tempid_tab num_tab;
2450 l_orgid_tab num_tab;
2451 l_parent_lpn_id_tab num_tab;
2452
2453 l_lpn_id_tab num_tab;
2454 l_lpn_level_tab num_tab;
2455 l_lpn_context_tab num_tab;
2456
2457 l_has_contents NUMBER := 0;
2458
2459 -- WIP related variables
2460 l_xdock_type_tab num_tab;
2461 l_wip_supply_type_tab num_tab;
2462 l_wip_entity_type_tab num_tab;
2463 l_job_tab entity_tab;
2464 l_line_tab line_tab;
2465 l_dept_tab dept_tab;
2466 l_operation_seq_num_tab num_tab;
2467 l_start_date_tab date_tab;
2468 l_schedule_tab entity_tab;
2469 l_assembly_tab item_tab;
2470 l_wip_entity_id_tab num_tab;
2471
2472 l_return_status VARCHAR2(30);
2473 l_msg_count NUMBER;
2474 l_msg_data VARCHAR2(10000);
2475
2476 l_error_code NUMBER;
2477 l_prim_qty NUMBER;
2478 l_inspection_flag NUMBER;
2479 l_load_flag NUMBER;
2480 l_drop_flag NUMBER;
2481 l_crossdock_flag NUMBER;
2482 l_load_prim_quantity NUMBER;
2483 l_inspect_prim_quantity NUMBER;
2484 l_drop_prim_quantity NUMBER;
2485 l_xdock_prim_quantity NUMBER;
2486 b_iscrossdocked BOOLEAN := FALSE;
2487
2488 -- This cursor will fetch all the lpns starting with the LPN passed
2489 -- For drop all, this will get all the LPNs which the user has loaded
2490 -- This cursor will also select the dummy LPN rows (lpn without contents)
2491 -- and also the level of the LPN
2492 CURSOR c_all_lpn_cursor IS
2493 SELECT lpn_id
2494 ,parent_lpn_id
2495 ,LEVEL
2496 ,lpn_context
2497 FROM wms_license_plate_numbers wln
2498 START WITH LPN_ID IN (
2499 SELECT wln.lpn_id
2500 FROM wms_license_plate_numbers wln
2501 WHERE p_drop_type <> G_DT_DROP_ALL
2502 AND wln.lpn_id = p_lpn_id
2503 UNION ALL
2504 SELECT wln.outermost_lpn_id
2505 FROM wms_dispatched_tasks wdt
2506 ,mtl_txn_request_lines mtrl
2507 ,mtl_material_transactions_temp mmtt
2508 ,mtl_txn_request_headers mtrh
2509 ,wms_license_plate_numbers wln
2510 WHERE p_drop_type = G_DT_DROP_ALL
2511 AND mtrh.header_id = mtrl.header_id
2512 AND mtrh.move_order_type = 6
2513 AND mtrl.line_status = 7
2514 AND wdt.transaction_temp_id = mmtt.transaction_temp_id
2515 AND mmtt.move_order_line_id = mtrl.line_id
2516 AND wdt.STATUS = 4
2517 AND wdt.person_id = p_emp_id
2518 AND wln.lpn_id = mtrl.lpn_id
2519 )
2520 CONNECT BY PRIOR wln.lpn_id = wln.parent_lpn_id;
2521
2522 -- This cursor will get the temp ids of all the MMTTs in the temp table
2523 -- which are crossdocked to WIP Issue.
2524 CURSOR c_back_ordered_cursor IS
2525 SELECT ROWID
2526 ,transaction_temp_id
2527 ,organization_id
2528 ,Nvl(crossdock_type,0)
2529 ,Nvl(wip_supply_type,0)
2530 FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
2531 WHERE 1 = 1
2532 AND row_type = G_ROW_TP_ALL_TASK
2533 --AND crossdock_type > 1
2534 AND backorder_delivery_detail > 0;
2535 --AND wip_supply_type = 1;
2536
2537 BEGIN
2538 --Printing the input parameters
2539 IF (l_debug = 1) THEN
2540 DEBUG(' Function Entered at ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
2541 DEBUG(' p_org_id => '||p_org_id,l_proc_name,4);
2542 DEBUG(' p_drop_type => '||p_drop_type,l_proc_name,4);
2543 DEBUG(' p_emp_id => '||p_emp_id,l_proc_name,4);
2544 DEBUG(' p_lpn_id => '||p_lpn_id,l_proc_name,4);
2545 END IF;
2546
2547 l_progress := '15';
2548
2549 BEGIN --Block to insert the 'All Task' rows
2550
2551 OPEN c_all_lpn_cursor;
2552 l_progress := '20';
2553 LOOP --c_all_lpn_cursor cursor
2554 EXIT WHEN c_all_lpn_cursor%NOTFOUND;
2555 l_progress := '22';
2556
2557 FETCH c_all_lpn_cursor
2558 BULK COLLECT
2559 INTO l_lpn_id_tab
2560 ,l_parent_lpn_id_tab
2561 ,l_lpn_level_tab
2562 ,l_lpn_context_tab
2563 LIMIT l_limit;
2564 l_progress := '25';
2565
2566 FOR i IN 1..l_lpn_id_tab.COUNT
2567 LOOP -- all LPNs loop
2568 l_progress := '27';
2569 BEGIN -- Check Whether contents exists for this lpn
2570 l_progress := '30';
2571 SELECT 1
2572 INTO l_has_contents
2573 FROM wms_lpn_contents
2574 WHERE parent_lpn_id = l_lpn_id_tab(i)
2575 AND ROWNUM < 2;
2576 l_progress := '31';
2577
2578 EXCEPTION
2579 WHEN no_data_found THEN
2580 l_progress := '33';
2581 l_has_contents := 0;
2582 WHEN OTHERS THEN
2583 l_progress := '35';
2584 RAISE fnd_api.g_exc_unexpected_error;
2585 END;-- Check Whether contents exists for this lpn
2586
2587 --Check for contents
2588 IF l_has_contents = 0 THEN
2589 l_progress := '40';
2590
2591 -- Don't insert dummy rows for all item drops
2592 -- In case of all item drop the consolidated lpn will be same as that of the lpn and
2593 -- drop type will be ID so we don't need dummy rows.
2594 IF p_item_drop_flag <> 'Y' THEN
2595
2596 l_progress := '45';
2597 -- LPN don't have contents, so insert a dummy row
2598 INSERT INTO WMS_PUTAWAY_GROUP_TASKS_GTMP
2599 (
2600 ORGANIZATION_ID
2601 ,LPN_ID
2602 ,PARENT_LPN_ID
2603 ,DROP_TYPE
2604 ,ROW_TYPE
2605 ,LPN_LEVEL
2606 ,LPN_CONTEXT
2607 ,WIP_SUPPLY_TYPE
2608 )
2609 VALUES
2610 (
2611 p_org_id
2612 ,l_lpn_id_tab(i)
2613 ,l_parent_lpn_id_tab(i)
2614 ,G_DT_CONSOLIDATED_DROP
2615 ,G_ROW_TP_LPN_TASK
2616 ,l_lpn_level_tab(i)
2617 ,l_lpn_context_tab(I)
2618 ,0
2619 );
2620 l_progress := '46';
2621
2622 IF (l_debug = 1) THEN
2623 DEBUG('Inserted dummy row for lpn id ' || l_lpn_id_tab(i),l_proc_name,9);
2624 END IF;
2625
2626 END IF;
2627
2628
2629 ELSIF l_has_contents = 1 THEN
2630 -- LPN has contents so query from MTRL,WDT and insert into temp table
2631
2632 l_progress := '50';
2633 --Data has to be ordered in the temp table later before processing, because ORDER BY during insert is not supported
2634 INSERT INTO WMS_PUTAWAY_GROUP_TASKS_GTMP
2635 (
2636 ORGANIZATION_ID
2637 ,TRANSACTION_TEMP_ID
2638 ,TRANSACTION_HEADER_ID
2639 ,LPN_ID
2640 ,LPN_NAME
2641 ,LPN_CONTEXT
2642 ,PARENT_LPN_ID
2643 ,PARENT_LPN_NAME
2644 ,OUTERMOST_LPN_ID
2645 ,OUTERMOST_LPN_NAME
2646 ,CONSOLIDATED_LPN_ID
2647 ,CONSOLIDATED_LPN_NAME
2648 ,INTO_LPN_ID
2649 ,INTO_LPN_NAME
2650 ,DROP_TYPE
2651 ,DROP_ORDER
2652 ,INVENTORY_ITEM_ID
2653 ,ITEM
2654 ,GROUP_ID
2655 ,LOT_NUMBER
2656 ,REVISION
2657 ,TRANSACTION_QUANTITY
2658 ,TRANSACTION_UOM
2659 ,LOCATOR
2660 ,PRIMARY_UOM_CODE
2661 ,DEST_SUBINVENTORY
2662 ,DEST_LOCATOR
2663 ,REVISION_QTY_CONTROL_CODE
2664 ,LOT_CONTROL_CODE
2665 ,SERIAL_NUMBER_CONTROL_CODE
2666 ,RESTRICT_SUBINVENTORIES_CODE
2667 ,RESTRICT_LOCATORS_CODE
2668 ,LOCATION_CONTROL_CODE
2669 ,ALLOWED_UNITS_LOOKUP_CODE
2670 ,BACKORDER_DELIVERY_DETAIL
2671 ,CROSSDOCK_TYPE
2672 ,WIP_SUPPLY_TYPE
2673 ,FROM_SUBINVENTORY
2674 ,FROM_LOCATOR
2675 ,TRANSFER_SUBINVENTORY
2676 ,TRANSFER_TO_LOCATION
2677 ,TRANSFER_ORGANIZATION
2678 ,TRANSACTION_ACTION_ID
2679 ,REFERENCE
2680 ,LOC_DROPPING_ORDER
2681 ,SUB_DROPPING_ORDER
2682 ,ROW_TYPE
2683 ,MOVE_ORDER_LINE_ID
2684 ,PROJECT_ID
2685 ,TASK_ID
2686 ,TXN_SOURCE_ID
2687 ,PRIMARY_QUANTITY
2688 ,LPN_LEVEL
2689 ,SECONDARY_QUANTITY --OPM Convergence
2690 ,SECONDARY_UOM --OPM Convergence
2691 ,show_message --R12
2692 ,error_code --R12
2693 ,error_explanation --R12
2694 )
2695
2696 SELECT DISTINCT
2697 mmtt.organization_id,
2698 mmtt.transaction_temp_id,
2699 mmtt.transaction_header_id,
2700 mtrl.lpn_id,
2701 NULL, --lpn_name
2702 l_lpn_context_tab(i),
2703 --TO_NUMBER(NULL), --Parent LPN ID
2704 l_parent_lpn_id_tab(i), --Parent LPN ID
2705 NULL, --Parent LPN Name
2706 TO_NUMBER(NULL), --Outermost LPN ID
2707 NULL, --Outermost LPN Name
2708 TO_NUMBER(NULL), --Consolidated LPN ID
2709 NULL, --Consolidated LPN Name
2710 mmtt.cartonization_id, --INTO LPN ID
2711 NULL, --INTO LPN Name
2712 decode(p_item_drop_flag,'Y',G_DT_ITEM_DROP,G_DT_CONSOLIDATED_DROP), --Drop Type
2713 ROWNUM, --Drop Order
2714 mmtt.inventory_item_id,
2715 msik.concatenated_segments item, --Item
2716 TO_NUMBER(NULL), --Group ID
2717 mtrl.lot_number,
2718 mmtt.revision,
2719 mmtt.transaction_quantity,
2720 mmtt.transaction_uom,
2721 NULL LOCATOR, --inv_project.get_locsegs (milk.inventory_location_id, milk.organization_id ) LOCATOR,
2722 msik.primary_uom_code,
2723 --DECODE (transaction_action_id, 2, mmtt.transfer_subinventory,mmtt.subinventory_code) dest_subinventory,
2724 --DECODE (transaction_action_id, 2, mmtt.transfer_to_location, mmtt.locator_id) dest_locator,
2725 NVL(mmtt.transfer_subinventory,mmtt.subinventory_code) dest_subinventory,
2726 NVL(mmtt.transfer_to_location, mmtt.locator_id) dest_locator,
2727 NVL (msik.revision_qty_control_code, 1),
2728 NVL (msik.lot_control_code, 1),
2729 NVL (msik.serial_number_control_code, 1),
2730 NVL (msik.restrict_subinventories_code, 2),
2731 NVL (msik.restrict_locators_code, 2),
2732 NVL (msik.location_control_code, 1),
2733 NVL (msik.allowed_units_lookup_code, 2),
2734 NVL (mtrl.backorder_delivery_detail_id, 0),
2735 NVL (mtrl.crossdock_type, 0),
2736 NVL (mmtt.wip_supply_type, 0),
2737 mmtt.subinventory_code from_subinventory,
2738 mmtt.locator_id from_locator,
2739 mmtt.transfer_subinventory,
2740 mmtt.transfer_to_location,
2741 mmtt.transfer_organization,
2742 mmtt.transaction_action_id,
2743 mtrl.REFERENCE,
2744 to_number(null), -- milk.dropping_order,
2745 to_number(NULL), -- msi.dropping_order,
2746 G_ROW_TP_ALL_TASK,
2747 mtrl.line_id,
2748 mtrl.project_id,
2749 mtrl.task_id,
2750 mtrl.txn_source_id,
2751 mmtt.primary_quantity,
2752 l_lpn_level_tab(i),
2753 mmtt.secondary_transaction_quantity, --OPM Convergence
2754 mmtt.secondary_uom_code, --OPM Convergence
2755
2756 --R12: Change Management: If suggested loc = wlpn.loc, should show iser wanring message
2757 Decode(wln.locator_id,NVL(mmtt.transfer_to_location, mmtt.locator_id),1,0) show_message,
2758 mmtt.error_code,
2759 mmtt.error_explanation
2760 --R12 End
2761 FROM mtl_material_transactions_temp mmtt
2762 ,mtl_txn_request_lines mtrl
2763 ,wms_dispatched_tasks wdt
2764 --,mtl_item_locations milk
2765 ,mtl_system_items_kfv msik
2766 ,mtl_txn_request_headers mtrh
2767 ,wms_license_plate_numbers wln
2768 --,mtl_secondary_inventories msi
2769 WHERE wdt.organization_id = p_org_id
2770 -- kajain
2771 -- added the decode since a lpn loaded by someone
2772 -- should be eligible to be dropped by some other user
2773 -- also added a check to make sure that wdt.status = 4
2774 AND wdt.person_id = Decode(p_drop_type, g_dt_drop_all,p_emp_id,wdt.person_id)
2775 AND wdt.status = 4
2776 AND wdt.task_type = 2
2777 AND wdt.transaction_temp_id = mmtt.transaction_temp_id
2778 AND mmtt.move_order_line_id = mtrl.line_id
2779 AND NVL (mmtt.wms_task_type, 0) <> -1
2780 AND mtrl.lpn_id = l_lpn_id_tab(i)
2781 AND wln.organization_id = p_org_id
2782 AND mtrl.lpn_id = wln.lpn_id
2783 AND mtrl.header_id = mtrh.header_id
2784 AND mtrh.move_order_type = 6
2785 --AND NVL(mmtt.transfer_to_location,mmtt.locator_id) = milk.inventory_location_id(+)
2786 --AND msi.organization_id(+) = mmtt.organization_id
2787 --AND NVL(mmtt.transfer_subinventory,mmtt.subinventory_code) = msi.secondary_inventory_name(+)
2788 --AND mmtt.organization_id = milk.organization_id(+)
2789 AND mmtt.organization_id = msik.organization_id
2790 AND mmtt.inventory_item_id = msik.inventory_item_id;
2791
2792 l_progress := '51';
2793
2794
2795 IF (l_debug = 1) THEN
2796 DEBUG('Inserted ' || SQL%rowcount || ' all task rows for lpn id ' || l_lpn_id_tab(i),l_proc_name,9);
2797 END IF;
2798
2799 END IF;
2800 --Check for contents
2801
2802 END LOOP; -- all LPNs loop
2803
2804 END LOOP; --c_all_lpn_cursor cursor
2805
2806 IF c_all_lpn_cursor%ISOPEN THEN
2807 l_progress := '60';
2808 CLOSE c_all_lpn_cursor;
2809 l_progress := '61';
2810 END IF;
2811
2812
2813 EXCEPTION
2814 WHEN OTHERS THEN
2815 l_progress := '90';
2816 RAISE fnd_api.g_exc_unexpected_error;
2817 END; --Block to insert the 'All Task' rows
2818
2819
2820 BEGIN -- WIP Integration
2821
2822 l_progress := '300';
2823
2824 IF (l_debug = 1) THEN
2825 DEBUG('Checking whether WIP Crossdock is possible ' ,l_proc_name,9);
2826 END IF;
2827
2828 OPEN c_back_ordered_cursor;
2829 l_progress := '310';
2830
2831 FETCH c_back_ordered_cursor
2832 BULK COLLECT
2833 INTO l_rowid_tab
2834 ,l_tempid_tab
2835 ,l_orgid_tab
2836 ,l_xdock_type_tab
2837 ,l_wip_supply_type_tab;
2838 l_progress := '320';
2839
2840 CLOSE c_back_ordered_cursor;
2841 l_progress := '330';
2842
2843 FOR i IN 1 .. l_rowid_tab.COUNT
2844 LOOP -- x-dock info loop
2845
2846 -- Call Validate_Operation for this MMTT to check whetehr the current step is crossdock.
2847 -- Call the WIP Integration APIs only if the current step is crossdock
2848 -- Else reset the WIP Related columns in the temp table.
2849 -- If this is any other xdock reset the xdock columns as well
2850 wms_atf_runtime_pub_apis.validate_operation
2851 ( x_return_status => l_return_status
2852 ,x_msg_data => l_msg_data
2853 ,x_msg_count => l_msg_count
2854 ,x_error_code => l_error_code
2855 ,x_inspection_flag => l_inspection_flag
2856 ,x_load_flag => l_load_flag
2857 ,x_drop_flag => l_drop_flag
2858 ,x_crossdock_flag => l_crossdock_flag
2859 ,x_load_prim_quantity => l_load_prim_quantity
2860 ,x_drop_prim_quantity => l_drop_prim_quantity
2861 ,x_inspect_prim_quantity => l_inspect_prim_quantity
2862 ,x_crossdock_prim_quantity => l_xdock_prim_quantity
2863 ,p_source_task_id => l_tempid_tab(i)
2864 ,p_move_order_line_id => NULL
2865 ,p_inventory_item_id => NULL
2866 ,p_lpn_id => NULL
2867 ,p_activity_type_id => G_OP_ACTIVITY_INBOUND
2868 ,p_organization_id => l_orgid_tab(i));
2869
2870 l_progress := '331';
2871 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
2872 IF (l_debug = 1) THEN
2873 DEBUG(' Validate Operation failed for MMTT = ' || l_tempid_tab(i) || ' hence erroring out' ,l_proc_name,1);
2874 DEBUG(' Error = ' || l_msg_data,l_proc_name,1);
2875 END IF;
2876 --RAISE fnd_api.g_exc_error;
2877 RETURN -1;
2878 ELSE
2879 -- Successful execution. Check whether this step if crossdocked/not
2880 IF (l_debug = 1) THEN
2881 debug(' l_crossdock_flag is : ' || l_crossdock_flag,l_proc_name,1);
2882 END IF;
2883
2884 IF (l_crossdock_flag = 1) THEN
2885 b_iscrossdocked := FALSE;
2886 ELSE
2887 b_iscrossdocked := TRUE;
2888 END IF;
2889
2890 END IF;
2891 l_progress := '332';
2892
2893 IF (l_debug = 1) THEN
2894 DEBUG(' API for temp_id ' || l_tempid_tab(i) ,l_proc_name,9);
2895 END IF;
2896
2897 IF (b_iscrossdocked) THEN --iscrossdocked
2898
2899 l_progress := '332.1';
2900 IF (l_debug = 1) THEN
2901 DEBUG('XDOCK TYPE: ' || l_xdock_type_tab(i) ,l_proc_name,9);
2902 DEBUG('WIP_SUPPLY_TYPE: ' || l_wip_supply_type_tab(i) ,l_proc_name,9);
2903 DEBUG('TEMP_ID: ' || l_tempid_tab(i) ,l_proc_name,9);
2904 END IF;
2905
2906 IF l_xdock_type_tab(i) = 2 AND l_wip_supply_type_tab(i) = 1 THEN
2907 IF (l_debug = 1) THEN
2908 DEBUG('Calling WIP Integration API for temp_id ' || l_tempid_tab(i) ,l_proc_name,9);
2909 END IF;
2910 l_progress := '333';
2911
2912 wms_wip_integration.get_wip_info_for_putaway
2913 (
2914 p_temp_id => l_tempid_tab(i)
2915 ,x_wip_entity_type => l_wip_entity_type_tab(i)
2916 ,x_job => l_job_tab(i)
2917 ,x_line => l_line_tab(i)
2918 ,x_dept => l_dept_tab(i)
2919 ,x_operation_seq_num => l_operation_seq_num_tab(i)
2920 ,x_start_date => l_start_date_tab(i)
2921 ,x_schedule => l_schedule_tab(i)
2922 ,x_assembly => l_assembly_tab(i)
2923 ,x_wip_entity_id => l_wip_entity_id_tab(i)
2924 ,x_return_status => l_return_status
2925 ,x_msg_count => l_msg_count
2926 ,x_msg_data => l_msg_data
2927 );
2928 l_progress := '334';
2929
2930 IF (l_return_status <> fnd_api.g_ret_sts_success) THEN
2931 IF (l_debug = 1) THEN
2932 DEBUG('WIP info for putaway failed for MMTT = ' || l_tempid_tab(i) ,l_proc_name,1);
2933 DEBUG('Error = ' || l_msg_data,l_proc_name,1);
2934 END IF;
2935 --RAISE fnd_api.g_exc_error;
2936 RETURN -1;
2937 l_progress := '340';
2938 END IF;
2939 ELSE
2940 --not crossdocked to WIP Issue
2941 l_wip_entity_type_tab(i) := 0;
2942 l_job_tab(i) := NULL;
2943 l_line_tab(i) := NULL;
2944 l_dept_tab(i) := NULL;
2945 l_operation_seq_num_tab(i) := NULL;
2946 l_wip_entity_type_tab(i) := NULL;
2947 l_start_date_tab(i) := NULL;
2948 l_schedule_tab(i) := NULL;
2949 l_assembly_tab(i) := NULL;
2950 END IF;
2951 ELSE
2952 -- The current step is not crossdock for this operation.
2953 -- so reset the crossdock related columns in the temp table.
2954 l_progress := '350';
2955 IF (l_debug = 1) THEN
2956 DEBUG('Resetting the xdock related cols for temp_id ' || l_tempid_tab(i) ,l_proc_name,9);
2957 END IF;
2958
2959 UPDATE WMS_PUTAWAY_GROUP_TASKS_GTMP
2960 SET wip_supply_type = 0
2961 ,backorder_delivery_detail = 0
2962 ,crossdock_type = 0
2963 WHERE transaction_temp_id = l_tempid_tab(i);
2964 l_progress := '355';
2965
2966 -- Setting these wip related columns explicitly to null
2967 -- so that the a row is created in the pl/sql table for that rowid
2968 -- and hence the bulk update below won't fail.
2969 l_wip_entity_type_tab(i) := 0;
2970 l_job_tab(i) := NULL;
2971 l_line_tab(i) := NULL;
2972 l_dept_tab(i) := NULL;
2973 l_operation_seq_num_tab(i) := NULL;
2974 l_wip_entity_type_tab(i) := NULL;
2975 l_start_date_tab(i) := NULL;
2976 l_schedule_tab(i) := NULL;
2977 l_assembly_tab(i) := NULL;
2978
2979 l_progress := '360';
2980
2981 END IF; --iscrossdocked
2982
2983 END LOOP; -- WIP info loop
2984
2985 l_progress := '370';
2986
2987 -- Update back these details into the temp table
2988 FORALL i IN 1 .. l_rowid_tab.COUNT
2989 UPDATE WMS_PUTAWAY_GROUP_TASKS_GTMP
2990 SET WIP_JOB = l_job_tab(i)
2991 ,WIP_LINE = l_line_tab(i)
2992 ,WIP_DEPT = l_dept_tab(i)
2993 ,WIP_OP_SEQ = l_operation_seq_num_tab(i)
2994 ,WIP_ENTITY_TYPE = l_wip_entity_type_tab(i)
2995 ,WIP_START_DATE = l_start_date_tab(i)
2996 ,WIP_SCHEDULE = l_schedule_tab(i)
2997 ,WIP_ASSEMBLY = l_assembly_tab(i)
2998 ,BACKORDER_DELIVERY_DETAIL = l_wip_entity_type_tab(i)
2999 WHERE ROWID = l_rowid_tab(i)
3000 AND Nvl(crossdock_type,1) = 2
3001 AND wip_supply_type = 1;
3002
3003 l_progress := '380';
3004
3005 IF (l_debug = 1) THEN
3006 DEBUG('After updating the WIP related for ' || l_rowid_tab.COUNT || ' row(s) ' ,l_proc_name,9);
3007 END IF;
3008 l_progress := '390';
3009
3010 EXCEPTION
3011 WHEN OTHERS THEN
3012 RAISE fnd_api.g_exc_unexpected_error;
3013 END; -- WIP Integration
3014
3015
3016 IF (l_debug = 1) THEN
3017 DEBUG(' Before calling pvt function get_row_count ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,9);
3018 END IF;
3019
3020 l_progress := '500';
3021 --Calling get_row_count to get the number of rows in global temp table
3022 l_rec_count := get_row_count(p_mode => 2);
3023 l_progress := '510';
3024
3025 IF (l_debug = 1) THEN
3026 DEBUG(' After calling pvt function get_row_count ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,9);
3027 DEBUG(' l_rec_count => '|| l_rec_count,l_proc_name,4);
3028 END IF;
3029
3030
3031 l_progress := '900';
3032 IF (l_debug = 1) THEN
3033 DEBUG(' l_rec_count => '|| l_rec_count,l_proc_name,4);
3034 DEBUG(' Function Exited at ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
3035 END IF;
3036 l_progress := '910';
3037
3038 -- Return the number of rows in the temp table after populate
3039 RETURN l_rec_count;
3040
3041
3042 EXCEPTION
3043 WHEN fnd_api.g_exc_error THEN
3044 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
3045 DEBUG(SQLERRM,l_proc_name,1);
3046
3047 IF c_all_lpn_cursor%ISOPEN THEN
3048 CLOSE c_all_lpn_cursor;
3049 END IF;
3050
3051 IF c_back_ordered_cursor%ISOPEN THEN
3052 CLOSE c_back_ordered_cursor;
3053 END IF;
3054
3055 RETURN -1;
3056
3057
3058 WHEN fnd_api.g_exc_unexpected_error THEN
3059 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
3060 DEBUG(SQLERRM,l_proc_name,1);
3061
3062 IF c_all_lpn_cursor%ISOPEN THEN
3063 CLOSE c_all_lpn_cursor;
3064 END IF;
3065
3066 IF c_back_ordered_cursor%ISOPEN THEN
3067 CLOSE c_back_ordered_cursor;
3068 END IF;
3069
3070 RETURN -1;
3071
3072
3073 WHEN OTHERS THEN
3074 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
3075 DEBUG(SQLERRM,l_proc_name,1);
3076
3077 IF c_all_lpn_cursor%ISOPEN THEN
3078 CLOSE c_all_lpn_cursor;
3079 END IF;
3080
3081 IF c_back_ordered_cursor%ISOPEN THEN
3082 CLOSE c_back_ordered_cursor;
3083 END IF;
3084
3085 RETURN -1;
3086 END Populate_group_tasks;
3087
3088
3089 /**
3090 * This function will call the ATF API to activate the
3091 * operation instance for load. It will call the ATF API
3092 * wms_atf_runtime_pub_apis.activate_operation_instance for
3093 * each MMTT. For the immediate and the child contents of the
3094 * LPN being passed.
3095 *
3096 * It returns the number of rows for which the plan is
3097 * activated, will return -1 in case of failure.
3098
3099 * @param x_return_status Return status of the function - Success, Error, Unexpected Error, Warning etc.,
3100 * @param x_msg_count Count of messages in the stack
3101 * @param x_msg_data Actual message if the count = 1 else it will be null.
3102 * @param p_org_id Organization Identifier
3103 * @param p_lpn_id LPN Identifier
3104 * @param p_emp_id Employee Identifier
3105 * @ RETURN NUMBER
3106
3107
3108 **/
3109 FUNCTION Activate_Plan_For_Load(
3110 x_return_status OUT NOCOPY VARCHAR2
3111 ,x_msg_count OUT NOCOPY NUMBER
3112 ,x_msg_data OUT NOCOPY VARCHAR2
3113 ,p_org_id IN NUMBER
3114 ,p_lpn_id IN NUMBER
3115 ,p_emp_id IN NUMBER )
3116 RETURN NUMBER
3117 IS
3118
3119 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3120 l_progress VARCHAR2(10) := '10';
3121 l_rec_count NUMBER := 0;
3122 l_proc_name VARCHAR2(30) := 'Activate_Plan_For_Load:';
3123
3124 l_error_code NUMBER;
3125 l_task_rec task_rec := NULL;
3126 l_tempid_tab num_tab;
3127
3128 l_consolidation_method_id NUMBER;
3129 l_drop_lpn_option NUMBER;
3130
3131 -- This cursor will get the MMTTs assoicated with the contents of the LPN passed
3132 -- along with the MMTTs of the contents of all its child LPNs also.
3133 --Bug5723418.Performance fix.Moved wlpn to FROM clause. Added hint
3134 -- Performane fix as a part of bug 7143123
3135 CURSOR c_all_mmtt_cursor IS
3136 SELECT /*+ ORDERED USE_NL(WLPN MTRL MMTT) INDEX(MTRL MTL_TXN_REQUEST_LINES_N7) */
3137 MMTT.TRANSACTION_TEMP_ID
3138 FROM
3139 ( SELECT LPN_ID
3140 FROM WMS_LICENSE_PLATE_NUMBERS START WITH LPN_ID = p_lpn_id CONNECT BY PRIOR LPN_ID = PARENT_LPN_ID ) WLPN,
3141 MTL_TXN_REQUEST_LINES MTRL,
3142 MTL_MATERIAL_TRANSACTIONS_TEMP MMTT
3143 WHERE MTRL.LINE_ID = MMTT.MOVE_ORDER_LINE_ID
3144 AND LINE_STATUS = 7
3145 AND MTRL.LPN_ID = WLPN.LPN_ID ;
3146
3147 BEGIN
3148
3149 IF (l_debug = 1) THEN
3150 DEBUG('Start of function ' || l_proc_name ,l_proc_name,9);
3151 DEBUG(' p_org_id ==> '|| p_org_id,l_proc_name,4);
3152 DEBUG(' p_lpn_id ==> '|| p_lpn_id,l_proc_name,4);
3153 DEBUG(' p_emp_id ==> '|| p_emp_id,l_proc_name,4);
3154 END IF;
3155
3156 -- Set the return status to success.
3157 l_progress := '20';
3158 x_return_status := fnd_api.g_ret_sts_success;
3159 l_progress := '30';
3160
3161 -- Setting the values for the task record
3162 -- Neednot set these values for drop since there ia already WDT,
3163 -- ATF will just change the status of this WDT record
3164
3165 l_task_rec.person_id := p_emp_id;
3166 l_task_rec.organization_id := p_org_id;
3167 l_task_rec.user_task_type := -1;
3168
3169 l_progress := '100';
3170 OPEN c_all_mmtt_cursor;
3171 l_progress := '110';
3172
3173 LOOP -- c_all_mmtt_cursor loop
3174
3175 EXIT WHEN c_all_mmtt_cursor%NOTFOUND;
3176 l_progress := '200';
3177
3178 FETCH c_all_mmtt_cursor
3179 BULK COLLECT
3180 INTO l_tempid_tab
3181 LIMIT l_limit;
3182 l_progress := '210';
3183
3184 l_rec_count := l_rec_count + l_tempid_tab.COUNT;
3185 l_progress := '220';
3186
3187 -- Activate each MMTT's
3188 FOR i IN 1 .. l_tempid_tab.COUNT
3189 LOOP --All temp ids loop
3190
3191 IF (l_debug = 1) THEN
3192 DEBUG('Calling activate_operation_instance with ...',l_proc_name,9);
3193 DEBUG('p_source_task_id => ' || l_tempid_tab(i),l_proc_name,9);
3194 DEBUG('p_activity_type_id => ' || G_OP_ACTIVITY_INBOUND,l_proc_name,9);
3195 DEBUG('p_task_execute_rec => l_task_rec',l_proc_name,9);
3196 DEBUG('p_operation_type_id => ' || G_OP_TYPE_DROP,l_proc_name,9);
3197 END IF;
3198 l_progress := '300';
3199
3200 wms_atf_runtime_pub_apis.activate_operation_instance
3201 ( p_source_task_id => l_tempid_tab(i)
3202 ,p_activity_id => G_OP_ACTIVITY_INBOUND
3203 ,p_task_execute_rec => l_task_rec
3204 ,p_operation_type_id => G_OP_TYPE_LOAD
3205 ,x_return_status => x_return_status
3206 ,x_msg_data => x_msg_data
3207 ,x_msg_count => x_msg_count
3208 ,x_error_code => l_error_code
3209 ,x_consolidation_method_id => l_consolidation_method_id
3210 ,x_drop_lpn_option => l_drop_lpn_option
3211 );
3212 l_progress := '310';
3213
3214 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
3215 IF (l_debug = 1) THEN
3216 DEBUG(l_error_code || ' Error in activate_operation_instance ' ,l_proc_name,1);
3217 END IF;
3218 l_progress := '320';
3219
3220 RAISE fnd_api.g_exc_error;
3221 END IF;
3222
3223 END LOOP; --All temp ids loop
3224
3225 END LOOP; -- c_all_mmtt_cursor loop
3226
3227
3228 IF c_all_mmtt_cursor%ISOPEN THEN
3229 CLOSE c_all_mmtt_cursor;
3230 END IF;
3231
3232 l_progress := '990';
3233 --Return the count of rows processed
3234 RETURN l_rec_count;
3235
3236 EXCEPTION
3237 WHEN fnd_api.g_exc_error THEN
3238 x_return_status := fnd_api.g_ret_sts_error;
3239 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
3240 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
3241 DEBUG(SQLERRM,l_proc_name,1);
3242
3243 IF c_all_mmtt_cursor%ISOPEN THEN
3244 CLOSE c_all_mmtt_cursor;
3245 END IF;
3246
3247 RETURN -1;
3248
3249
3250 WHEN fnd_api.g_exc_unexpected_error THEN
3251 x_return_status := fnd_api.g_ret_sts_unexp_error;
3252 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
3253
3254 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
3255 DEBUG(SQLERRM,l_proc_name,1);
3256
3257 IF c_all_mmtt_cursor%ISOPEN THEN
3258 CLOSE c_all_mmtt_cursor;
3259 END IF;
3260
3261 RETURN -1;
3262
3263
3264 WHEN OTHERS THEN
3265 x_return_status := fnd_api.g_ret_sts_unexp_error;
3266 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
3267 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
3268 DEBUG(SQLERRM,l_proc_name,1);
3269
3270 IF c_all_mmtt_cursor%ISOPEN THEN
3271 CLOSE c_all_mmtt_cursor;
3272 END IF;
3273
3274 RETURN -1;
3275
3276 END Activate_Plan_For_Load;
3277
3278
3279 /**
3280 * This function will call the ATF API to complete the operation instance for load.
3281 * It will call the ATF API wms_atf_runtime_pub_apis.activate_operation_instance for
3282 * each MMTT. For the immediate and the child contents of the LPN being passed.
3283 *
3284 * It returns the number of rows for which the plan is completed. will return -1 in case of failure.
3285
3286 * @param x_return_status Return status of the function - Success, Error, Unexpected Error, Warning etc.,
3287 * @param x_msg_count Count of messages in the stack
3288 * @param x_msg_data Actual message if the count = 1 else it will be null.
3289 * @param p_org_id Organization Identifier
3290 * @param p_lpn_id LPN Identifier
3291 * @param p_emp_id Employee Identifier
3292 * @ RETURN NUMBER
3293
3294
3295 **/
3296 FUNCTION Complete_Plan_For_Load(
3297 x_return_status OUT NOCOPY VARCHAR2
3298 ,x_msg_count OUT NOCOPY NUMBER
3299 ,x_msg_data OUT NOCOPY VARCHAR2
3300 ,p_org_id IN NUMBER
3301 ,p_lpn_id IN NUMBER
3302 ,p_emp_id IN NUMBER )
3303 RETURN NUMBER
3304 IS
3305
3306 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3307 l_progress VARCHAR2(10) := '10';
3308 l_rec_count NUMBER := 0;
3309 l_proc_name VARCHAR2(30) := 'Complete_Plan_For_Load:';
3310
3311 l_error_code NUMBER;
3312 l_tempid_tab num_tab;
3313
3314 -- This cursor will get the MMTTs assoicated with the contents of the LPN passed
3315 -- along with the MMTTs of the contents of all its child LPNs also.
3316 --Bug5723418.Performance fix.Moved wlpn to FROM clause.Also added hint
3317 -- Performane fix as a part of bug 7143123
3318 CURSOR c_all_mmtt_cursor IS
3319 SELECT /*+ ORDERED USE_NL(WLPN MTRL MMTT) INDEX(MTRL MTL_TXN_REQUEST_LINES_N7) */
3320 MMTT.TRANSACTION_TEMP_ID
3321 FROM
3322 ( SELECT LPN_ID
3323 FROM WMS_LICENSE_PLATE_NUMBERS START WITH LPN_ID = p_lpn_id CONNECT BY PRIOR LPN_ID = PARENT_LPN_ID ) WLPN,
3324 MTL_TXN_REQUEST_LINES MTRL,
3325 MTL_MATERIAL_TRANSACTIONS_TEMP MMTT
3326 WHERE MTRL.LINE_ID = MMTT.MOVE_ORDER_LINE_ID
3327 AND LINE_STATUS = 7
3328 AND MTRL.LPN_ID = WLPN.LPN_ID ;
3329
3330 BEGIN
3331
3332 IF (l_debug = 1) THEN
3333 DEBUG('Start of function ' || l_proc_name ,l_proc_name,9);
3334 DEBUG(' p_org_id ==> '|| p_org_id,l_proc_name,4);
3335 DEBUG(' p_lpn_id ==> '|| p_lpn_id,l_proc_name,4);
3336 DEBUG(' p_emp_id ==> '|| p_emp_id,l_proc_name,4);
3337 END IF;
3338
3339 -- Set the return status to success.
3340 l_progress := '20';
3341 x_return_status := fnd_api.g_ret_sts_success;
3342 l_progress := '30';
3343
3344 l_progress := '100';
3345 OPEN c_all_mmtt_cursor;
3346 l_progress := '110';
3347
3348 LOOP -- c_all_mmtt_cursor loop
3349
3350 EXIT WHEN c_all_mmtt_cursor%NOTFOUND;
3351 l_progress := '200';
3352
3353 FETCH c_all_mmtt_cursor
3354 BULK COLLECT
3355 INTO l_tempid_tab
3356 LIMIT l_limit;
3357 l_progress := '210';
3358
3359 l_rec_count := l_rec_count + l_tempid_tab.COUNT;
3360 l_progress := '220';
3361
3362 -- Complete the Load Operation for each MMTT's
3363 FOR i IN 1 .. l_tempid_tab.COUNT
3364 LOOP --All temp ids loop
3365
3366 IF (l_debug = 1) THEN
3367 DEBUG('Calling complete_operation_instance with ...',l_proc_name,9);
3368 DEBUG('p_source_task_id => ' || l_tempid_tab(i),l_proc_name,9);
3369 DEBUG('p_activity_type_id => ' || G_OP_ACTIVITY_INBOUND,l_proc_name,9);
3370 DEBUG('p_task_execute_rec => l_task_rec',l_proc_name,9);
3371 DEBUG('p_operation_type_id => ' || G_OP_TYPE_DROP,l_proc_name,9);
3372 END IF;
3373 l_progress := '300';
3374
3375 wms_atf_runtime_pub_apis.complete_operation_instance
3376 ( p_source_task_id => l_tempid_tab(i)
3377 ,p_activity_id => G_OP_ACTIVITY_INBOUND
3378 ,p_operation_type_id => G_OP_TYPE_LOAD
3379 ,x_return_status => x_return_status
3380 ,x_msg_data => x_msg_data
3381 ,x_msg_count => x_msg_count
3382 ,x_error_code => l_error_code
3383 );
3384 l_progress := '310';
3385
3386 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
3387 IF (l_debug = 1) THEN
3388 DEBUG(l_error_code || ' Error in complete_operation_instance ' ,l_proc_name,1);
3389 END IF;
3390 l_progress := '320';
3391
3392 RAISE fnd_api.g_exc_error;
3393 END IF;
3394
3395 END LOOP; --All temp ids loop
3396
3397 END LOOP; -- c_all_mmtt_cursor loop
3398
3399
3400 IF c_all_mmtt_cursor%ISOPEN THEN
3401 CLOSE c_all_mmtt_cursor;
3402 END IF;
3403
3404 l_progress := '990';
3405 --Return the count of rows processed
3406 RETURN l_rec_count;
3407
3408 EXCEPTION
3409 WHEN fnd_api.g_exc_error THEN
3410 x_return_status := fnd_api.g_ret_sts_error;
3411 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
3412 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
3413 DEBUG(SQLERRM,l_proc_name,1);
3414
3415 IF c_all_mmtt_cursor%ISOPEN THEN
3416 CLOSE c_all_mmtt_cursor;
3417 END IF;
3418
3419 RETURN -1;
3420
3421
3422 WHEN fnd_api.g_exc_unexpected_error THEN
3423 x_return_status := fnd_api.g_ret_sts_unexp_error;
3424 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
3425
3426 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
3427 DEBUG(SQLERRM,l_proc_name,1);
3428
3429 IF c_all_mmtt_cursor%ISOPEN THEN
3430 CLOSE c_all_mmtt_cursor;
3431 END IF;
3432
3433 RETURN -1;
3434
3435
3436 WHEN OTHERS THEN
3437 x_return_status := fnd_api.g_ret_sts_unexp_error;
3438 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
3439 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
3440 DEBUG(SQLERRM,l_proc_name,1);
3441
3442 IF c_all_mmtt_cursor%ISOPEN THEN
3443 CLOSE c_all_mmtt_cursor;
3444 END IF;
3445
3446 RETURN -1;
3447
3448 END Complete_Plan_For_Load;
3449
3450
3451
3452
3453 /**
3454 * This Procedure will do the ATF integration for the LOAD operation
3455 * in case of single step drop or load portion of manual drop.
3456 *
3457 * This procedure inturn will call Activate_Plan_For_Load to activate
3458 * the plan for load and then will call Complete_Plan_For_Load to complete the LOAD step.
3459 *
3460 * This procedure will be called from create_grouped_tasks in case of single step drop
3461 * ie the LPN which has to be dropped is not loaded already.
3462 *
3463 * @param x_return_status Return status of the function - Success, Error, Unexpected Error, Warning etc.,
3464 * @param x_msg_count Count of messages in the stack
3465 * @param x_msg_data Actual message if the count = 1 else it will be null.
3466 * @param p_org_id Organization Identifier
3467 * @param p_lpn_id LPN Identifier
3468 * @param p_emp_id Employee Identifier
3469 * @ RETURN NUMBER
3470
3471
3472 **/
3473 PROCEDURE Complete_ATF_Load(
3474 x_return_status OUT NOCOPY VARCHAR2
3475 ,x_msg_count OUT NOCOPY NUMBER
3476 ,x_msg_data OUT NOCOPY VARCHAR2
3477 ,p_org_id IN NUMBER
3478 ,p_lpn_id IN NUMBER
3479 ,p_emp_id IN NUMBER )
3480 IS
3481
3482 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3483 l_progress VARCHAR2(10) := '10';
3484 l_rec_count NUMBER := 0;
3485 l_proc_name VARCHAR2(30) := 'Complete_ATF_Load:';
3486
3487 l_tempid_tab num_tab;
3488
3489 BEGIN
3490
3491 IF (l_debug = 1) THEN
3492 DEBUG('Start of Procedure ' || l_proc_name ,l_proc_name,9);
3493 DEBUG(' p_org_id ==> '|| p_org_id,l_proc_name,4);
3494 DEBUG(' p_lpn_id ==> '|| p_lpn_id,l_proc_name,4);
3495 DEBUG(' p_emp_id ==> '|| p_emp_id,l_proc_name,4);
3496 END IF;
3497
3498 -- Set the return status to success.
3499 l_progress := '20';
3500 x_return_status := fnd_api.g_ret_sts_success;
3501 l_progress := '30';
3502
3503 IF (l_debug = 1) THEN
3504 DEBUG(' Calling Activate Instance for the LOAD Operation ... ' || x_msg_data ,l_proc_name,9);
3505 END IF;
3506
3507 l_progress := '100';
3508 -- Activate the LOAD operation
3509 l_rec_count := Activate_Plan_For_Load(
3510 x_return_status => x_return_status
3511 ,x_msg_count => x_msg_count
3512 ,x_msg_data => x_msg_data
3513 ,p_org_id => p_org_id
3514 ,p_lpn_id => p_lpn_id
3515 ,p_emp_id => p_emp_id);
3516
3517 l_progress := '110';
3518
3519 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
3520 IF (l_debug = 1) THEN
3521 DEBUG(' Error in Activate_Plan_For_Load ' || x_msg_data ,l_proc_name,1);
3522 END IF;
3523 l_progress := '120';
3524
3525 RAISE fnd_api.g_exc_error;
3526 ELSE
3527 IF (l_debug = 1) THEN
3528 DEBUG('Successfully called Activate_Plan_For_Load for ' || l_rec_count || ' row(s)' ,l_proc_name,9);
3529 END IF;
3530 l_progress := '130';
3531
3532 END IF;
3533
3534 IF (l_debug = 1) THEN
3535 DEBUG(' Calling Complete Instance for the LOAD Operation ... ' || x_msg_data ,l_proc_name,9);
3536 END IF;
3537
3538 l_progress := '200';
3539 -- Complete the LOAD operation
3540 l_rec_count := Complete_Plan_For_Load(
3541 x_return_status => x_return_status
3542 ,x_msg_count => x_msg_count
3543 ,x_msg_data => x_msg_data
3544 ,p_org_id => p_org_id
3545 ,p_lpn_id => p_lpn_id
3546 ,p_emp_id => p_emp_id);
3547
3548 l_progress := '210';
3549
3550 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
3551 IF (l_debug = 1) THEN
3552 DEBUG(' Error in Complete_Plan_For_Load ' || x_msg_data ,l_proc_name,1);
3553 END IF;
3554 l_progress := '220';
3555
3556 RAISE fnd_api.g_exc_error;
3557 ELSE
3558 IF (l_debug = 1) THEN
3559 DEBUG('Successfully called Complete_Plan_For_Load for ' || l_rec_count || ' row(s)' ,l_proc_name,9);
3560 END IF;
3561 l_progress := '130';
3562
3563 END IF;
3564
3565 l_progress := '990';
3566
3567 EXCEPTION
3568 WHEN fnd_api.g_exc_error THEN
3569 x_return_status := fnd_api.g_ret_sts_error;
3570 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
3571 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
3572 DEBUG(SQLERRM,l_proc_name,1);
3573
3574 WHEN fnd_api.g_exc_unexpected_error THEN
3575 x_return_status := fnd_api.g_ret_sts_unexp_error;
3576 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
3577 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
3578 DEBUG(SQLERRM,l_proc_name,1);
3579
3580 WHEN OTHERS THEN
3581 x_return_status := fnd_api.g_ret_sts_unexp_error;
3582 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
3583 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
3584 DEBUG(SQLERRM,l_proc_name,1);
3585
3586 END Complete_ATF_Load;
3587
3588
3589
3590
3591
3592 /**
3593 * This function will call the ATF API to activate the operation instance for drop
3594 * It will call the ATF API wms_atf_runtime_pub_apis.activate_operation_instance
3595 * for each 'All Task' row in the temp table.
3596 *
3597 * After call to ATF API the new dest sub/loc/LPN will be updated back to the
3598 * global temp table.
3599 *
3600 * It returns the number of rows for which the plan is activated
3601 * will return -1 in case of failure.
3602
3603 * @param x_return_status Return status of the function - Success, Error, Unexpected Error, Warning etc.,
3604 * @param x_msg_count Count of messages in the stack
3605 * @param x_msg_data Actual message if the count = 1 else it will be null.
3606 *
3607 * @ RETURN number
3608
3609
3610 **/
3611 FUNCTION Activate_Plan_For_Drop(
3612 x_return_status OUT NOCOPY VARCHAR2,
3613 x_msg_count OUT NOCOPY NUMBER,
3614 x_msg_data OUT NOCOPY VARCHAR2 )
3615
3616 RETURN NUMBER
3617 IS
3618 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3619 l_progress VARCHAR2(10) := '10';
3620 l_rec_count NUMBER := 0;
3621 l_proc_name VARCHAR2(30) := 'Activate_Plan_For_Drop:';
3622
3623 l_error_code NUMBER;
3624 l_task_rec task_rec := NULL;
3625 l_rowid_tab rowid_tab;
3626 l_tempid_tab num_tab;
3627 l_into_lpn_id_tab num_tab;
3628 l_into_lpn_name_tab lpn_name_tab;
3629 l_dest_sub_tab sub_name_tab;
3630 l_dest_loc_tab num_tab;
3631 l_sub_drop_order_tab num_tab;
3632 l_loc_drop_order_tab num_tab;
3633 l_show_message_tab num_tab;--R12
3634 l_error_code_tab varchar240_tab;
3635 l_drop_lpn_option_tab num_tab;
3636 l_consolidation_method_id_tab num_tab;
3637 l_lpn_controlled_flag_tab num_tab;
3638 l_lpn_locator_tab num_tab;
3639
3640 l_drop_lpn_option NUMBER;
3641
3642 l_consolidation_method_id NUMBER;
3643 -- This cursor will get the transaction_temp_id of all the MMTTs which are going to
3644 -- be processed for this drop.
3645 -- The rowid is also selected inorder to update back the dest sub/loc/LPN to the temp table.
3646 CURSOR c_all_tasks_cursor IS
3647 SELECT ROWID
3648 ,transaction_temp_id
3649 ,show_message
3650 ,error_code
3651 FROM wms_putaway_group_tasks_gtmp
3652 WHERE row_type = G_ROW_TP_ALL_TASK;
3653
3654 -- This cursor will get the MMTT details for the temp id passed
3655 CURSOR c_mmtt_cursor(v_transaction_temp_id NUMBER) IS
3656 SELECT NVL(mmtt.transfer_subinventory,mmtt.subinventory_code) dest_subinventory
3657 ,NVL(mmtt.transfer_to_location, mmtt.locator_id) dest_locator
3658 ,mmtt.cartonization_id into_lpn_id
3659 ,wlpn.license_plate_number into_lpn_name
3660 ,msi.dropping_order sub_dropping_order
3661 ,milk.dropping_order loc_dropping_order
3662 ,Nvl(msi.lpn_controlled_flag,2) lpn_controlled_flag
3663 FROM mtl_material_transactions_temp mmtt
3664 ,wms_license_plate_numbers wlpn
3665 ,mtl_secondary_inventories msi
3666 ,mtl_item_locations_kfv milk
3667 WHERE mmtt.transaction_temp_id = v_transaction_temp_id
3668 AND mmtt.cartonization_id = wlpn.lpn_id(+)
3669 AND NVL(mmtt.transfer_to_location,mmtt.locator_id) = milk.inventory_location_id(+)
3670 AND msi.organization_id(+) = mmtt.organization_id
3671 AND NVL(mmtt.transfer_subinventory,mmtt.subinventory_code) = msi.secondary_inventory_name(+)
3672 AND mmtt.organization_id = milk.organization_id(+);
3673
3674 BEGIN
3675
3676 IF (l_debug = 1) THEN
3677 DEBUG('Start of function ' || l_proc_name ,l_proc_name,9);
3678 END IF;
3679
3680
3681 -- Set the return status to success.
3682 l_progress := '20';
3683 x_return_status := fnd_api.g_ret_sts_success;
3684 l_progress := '30';
3685
3686 -- Setting the values for the task record
3687 -- Neednot set these values for drop since there ia already WDT,
3688 -- ATF will just change the status of this WDT record
3689 /*
3690 l_task_rec.person_id := p_emp_id;
3691 l_task_rec.organization_id := p_org_id;
3692 l_task_rec.user_task_type := -1;
3693 */
3694
3695 l_progress := '100';
3696 OPEN c_all_tasks_cursor;
3697 l_progress := '110';
3698
3699 LOOP -- c_all_tasks_cursor loop
3700
3701 EXIT WHEN c_all_tasks_cursor%NOTFOUND;
3702 l_progress := '200';
3703
3704 FETCH c_all_tasks_cursor
3705 BULK COLLECT
3706 INTO l_rowid_tab
3707 ,l_tempid_tab
3708 ,l_show_message_tab
3709 ,l_error_code_tab
3710 LIMIT l_limit;
3711 l_progress := '210';
3712
3713 l_rec_count := l_rec_count + l_tempid_tab.COUNT;
3714 l_progress := '220';
3715
3716 -- Activate each MMTT's
3717 FOR i IN 1 .. l_tempid_tab.COUNT
3718 LOOP --All temp ids loop
3719
3720 IF (l_debug = 1) THEN
3721 DEBUG('Calling activate_operation_instance with ...',l_proc_name,9);
3722 DEBUG('p_source_task_id => ' || l_tempid_tab(i),l_proc_name,9);
3723 DEBUG('p_activity_type_id => ' || G_OP_ACTIVITY_INBOUND,l_proc_name,9);
3724 DEBUG('p_task_execute_rec => l_task_rec',l_proc_name,9);
3725 DEBUG('p_operation_type_id => ' || G_OP_TYPE_DROP,l_proc_name,9);
3726 END IF;
3727 l_progress := '300';
3728
3729 wms_atf_runtime_pub_apis.activate_operation_instance
3730 ( p_source_task_id => l_tempid_tab(i)
3731 ,p_activity_id => G_OP_ACTIVITY_INBOUND
3732 ,p_task_execute_rec => l_task_rec
3733 ,p_operation_type_id => G_OP_TYPE_DROP
3734 ,x_return_status => x_return_status
3735 ,x_msg_data => x_msg_data
3736 ,x_msg_count => x_msg_count
3737 ,x_error_code => l_error_code
3738 ,x_consolidation_method_id => l_consolidation_method_id
3739 ,x_drop_lpn_option => l_drop_lpn_option
3740 );
3741 l_progress := '310';
3742
3743 IF (l_debug = 1) THEN
3744 DEBUG('activate_operation_instance returned',l_proc_name,9);
3745 DEBUG('x_return_status => '||x_return_status,l_proc_name,9);
3746 DEBUG('x_consolidation_method_id => '||l_consolidation_method_id,l_proc_name,9);
3747 debug('x_drop_lpn_option => '||l_drop_lpn_option,l_proc_name,9);
3748 debug('x_msg_data => '||x_msg_data,l_proc_name,9);
3749 debug('x_msg_count => '||x_msg_count,l_proc_name,9);
3750 debug('x_error_code => '||l_error_code,l_proc_name,9);
3751 END IF;
3752
3753 --R12: ATF will pass back the status 'W' if all the
3754 --consolidation locators are full. If so, get the message from
3755 --the stack and store it in the GTMP
3756 IF (x_return_status = 'W') THEN
3757 l_show_message_tab(i) := 2;
3758 --Assume that x_msg_data stores the translated string, so
3759 --the UI just needs to show the string without any translation
3760 l_error_code_tab(i) := x_msg_data;
3761
3762 ELSIF (x_return_status <> fnd_api.g_ret_sts_success) THEN
3763 IF (l_debug = 1) THEN
3764 DEBUG(l_error_code || ' Error in activate_operation_instance ' ,l_proc_name,1);
3765 END IF;
3766 l_progress := '320';
3767
3768 RAISE fnd_api.g_exc_error;
3769 END IF;
3770
3771 l_drop_lpn_option_tab(i) := l_drop_lpn_option;
3772 l_consolidation_method_id_tab(i) := l_consolidation_method_id;
3773
3774 -- ATF would have updated the dest sub/loc/LPN in MMTT. So query it and sync it with the temp table.
3775
3776 -- Querying the dest sub/loc/LPN for the acitvated row
3777 l_progress := '400';
3778 OPEN c_mmtt_cursor(l_tempid_tab(i));
3779 l_progress := '410';
3780
3781 IF (l_debug = 1) THEN
3782 DEBUG(' Getting the details of the activated row ' ,l_proc_name,9);
3783 END IF;
3784
3785 FETCH c_mmtt_cursor
3786 INTO l_dest_sub_tab(i)
3787 ,l_dest_loc_tab(i)
3788 ,l_into_lpn_id_tab(i)
3789 ,l_into_lpn_name_tab(i)
3790 ,l_sub_drop_order_tab(i)
3791 ,l_loc_drop_order_tab(i)
3792 ,l_lpn_controlled_flag_tab(i);
3793
3794 IF (l_debug = 1) THEN
3795 DEBUG('show_message: '||l_show_message_tab(i),l_proc_name,9);
3796 END IF;
3797
3798 l_progress := '420';
3799
3800 CLOSE c_mmtt_cursor;
3801 l_progress := '430';
3802
3803 END LOOP; --All temp ids loop
3804
3805 IF (l_debug = 1) THEN
3806 DEBUG('Doing a BULK update of temp table with the ATF suggested dest sub/loc/LPN ' ,l_proc_name,9);
3807 END IF;
3808
3809 -- Do the bulk update on the temp table with the ATF suggested dest sub/loc/lpn
3810 FORALL i IN 1 .. l_tempid_tab.COUNT
3811 UPDATE wms_putaway_group_tasks_gtmp
3812 SET dest_subinventory = l_dest_sub_tab(i)
3813 ,dest_locator = l_dest_loc_tab(i)
3814 ,into_lpn_id = l_into_lpn_id_tab(i)
3815 ,into_lpn_name = l_into_lpn_name_tab(i)
3816 ,locator = inv_project.get_locsegs (l_dest_loc_tab(i), organization_id)
3817 ,sub_dropping_order = l_sub_drop_order_tab(i)
3818 ,loc_dropping_order = l_loc_drop_order_tab(i)
3819 ,show_message = l_show_message_tab(i) --R12
3820 ,error_code = l_error_code_tab(i) --???
3821 ,drop_lpn_option = l_drop_lpn_option_tab(i) --R12
3822 ,consolidation_method_id = l_consolidation_method_id_tab(i) --R12
3823 ,sub_lpn_controlled_flag = l_lpn_controlled_flag_tab(i) --R12
3824 WHERE ROWID = l_rowid_tab(i);
3825 l_progress := '440';
3826
3827 IF (l_debug = 1) THEN
3828 DEBUG('Done a BULK update of this set of acivated MMTTs. rows = ' || SQL%ROWCOUNT ,l_proc_name,9);
3829 END IF;
3830
3831
3832 END LOOP; -- c_all_tasks_cursor loop
3833
3834 -- Close all the open cursors if any.
3835 IF c_all_tasks_cursor%ISOPEN THEN
3836 l_progress := '500';
3837 CLOSE c_all_tasks_cursor;
3838 END IF;
3839
3840 IF c_mmtt_cursor%ISOPEN THEN
3841 l_progress := '510';
3842 CLOSE c_mmtt_cursor;
3843 END IF;
3844
3845 l_progress := '990';
3846 --Return the count of rows processed
3847 RETURN l_rec_count;
3848
3849 EXCEPTION
3850 WHEN fnd_api.g_exc_error THEN
3851 x_return_status := fnd_api.g_ret_sts_error;
3852 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
3853 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
3854 DEBUG(SQLERRM,l_proc_name,1);
3855
3856 IF c_all_tasks_cursor%ISOPEN THEN
3857 CLOSE c_all_tasks_cursor;
3858 END IF;
3859
3860 IF c_mmtt_cursor%ISOPEN THEN
3861 CLOSE c_mmtt_cursor;
3862 END IF;
3863
3864 RETURN -1;
3865
3866
3867 WHEN fnd_api.g_exc_unexpected_error THEN
3868 x_return_status := fnd_api.g_ret_sts_unexp_error;
3869 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
3870
3871 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
3872 DEBUG(SQLERRM,l_proc_name,1);
3873
3874 IF c_all_tasks_cursor%ISOPEN THEN
3875 CLOSE c_all_tasks_cursor;
3876 END IF;
3877
3878 IF c_mmtt_cursor%ISOPEN THEN
3879 CLOSE c_mmtt_cursor;
3880 END IF;
3881
3882 RETURN -1;
3883
3884
3885 WHEN OTHERS THEN
3886 x_return_status := fnd_api.g_ret_sts_unexp_error;
3887 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
3888 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
3889 DEBUG(SQLERRM,l_proc_name,1);
3890
3891 IF c_all_tasks_cursor%ISOPEN THEN
3892 CLOSE c_all_tasks_cursor;
3893 END IF;
3894
3895 IF c_mmtt_cursor%ISOPEN THEN
3896 CLOSE c_mmtt_cursor;
3897 END IF;
3898
3899 RETURN -1;
3900
3901 END Activate_Plan_For_Drop;
3902
3903
3904 /**
3905 * This procedure will lock the LPNs which are in the temp table.
3906 * Though the LPN is locked in the method Check_LPN_Validity,
3907 * We are locking it again since the commits in between will releive the locks.
3908
3909 * @param x_return_status Return status of the procedure - Success, Error, Unexpected Error, Warning etc.,
3910 * @param x_msg_count Count of messages in the stack
3911 * @param x_msg_data Actual message if the count = 1 else it will be null.
3912 **/
3913 PROCEDURE Lock_LPNs(
3914 x_return_status OUT NOCOPY VARCHAR2
3915 ,x_msg_count OUT NOCOPY NUMBER
3916 ,x_msg_data OUT NOCOPY VARCHAR2 )
3917 IS
3918
3919 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
3920 l_progress VARCHAR2(10) := '10';
3921 l_proc_name VARCHAR2(30) := 'Lock_LPNs:';
3922 l_rec_count NUMBER := 0;
3923
3924 -- Need to trap the error returned when
3925 -- unable to lock the lpn record.
3926 record_locked EXCEPTION;
3927 PRAGMA EXCEPTION_INIT(record_locked, -54);
3928
3929 l_lpn_id_tab num_tab;
3930
3931 BEGIN
3932
3933 IF (l_debug = 1) THEN
3934 debug(' Start of procedure. Trying to lock all the LPNs in the temp table', l_proc_name,1);
3935 END IF;
3936
3937 l_progress := '100';
3938 x_return_status := fnd_api.g_ret_sts_success;
3939 l_progress := '110';
3940
3941 -- Bulk Lock all LPNs which are in the temp table.
3942 -- So that other user can't work on them
3943
3944 -- Bug#3821032 We need not lock the LPNs in receiving since it will cause deadlock if called in concurrent mode
3945 -- For receiving LPNs the Check_LPN_Validity wrapper takes care of locking Operation Instance records.
3946 -- So that other user(s) can't work on this LPN.
3947 SELECT lpn_id
3948 BULK COLLECT
3949 INTO l_lpn_id_tab
3950 FROM WMS_LICENSE_PLATE_NUMBERS
3951 WHERE lpn_id IN ( SELECT DISTINCT lpn_id
3952 FROM wms_putaway_group_tasks_gtmp
3953 WHERE row_type = G_ROW_TP_ALL_TASK
3954 AND lpn_context <> 3
3955 )
3956 FOR UPDATE NOWAIT;
3957
3958 l_progress := '120';
3959
3960 IF (l_debug = 1) THEN
3961 debug(' End of procedure:' || SQL%rowcount || ' LPN(s) locked ', l_proc_name,1);
3962 END IF;
3963
3964 l_progress := '200';
3965
3966 EXCEPTION
3967 WHEN no_data_found THEN
3968 debug(' No LPNs found in the temp table for locking', l_proc_name,1);
3969 x_return_status := fnd_api.g_ret_sts_success;
3970
3971 WHEN record_locked THEN
3972 debug(' LPN Already locked by someone else', l_proc_name,1);
3973 x_return_status := fnd_api.g_ret_sts_error;
3974
3975 fnd_message.set_name('WMS', 'WMS_LPN_UNAVAIL');
3976 fnd_msg_pub.ADD;
3977 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
3978
3979 WHEN OTHERS THEN
3980 debug(' Exception while trying to lock LPN(s) ' || SQLERRM, l_proc_name,1);
3981 x_return_status := fnd_api.g_ret_sts_unexp_error;
3982 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
3983
3984 END Lock_LPNs;
3985
3986
3987 /**
3988 * This procedure will populate the grouped tasks temporary
3989 * table (WMS_PUTAWAY_GROUP_TASKS_GTEMP with the required data
3990 * and also it will stamp the drop type for the tasks and will
3991 * group them based on various criterias.
3992
3993 * @param x_return_status Return status of the procedure - Success, Error, Unexpected Error, Warning etc.,
3994 * @param x_msg_count Count of messages in the stack
3995 * @param x_msg_data Actual message if the count = 1 else it will be null.
3996 * @param p_org_id Organization Id
3997 * @param p_drop_type This indicates for which type of drop the temp table should be populated.
3998 * This can have the values
3999 * SD - 'System Drop'
4000 * DA - 'Drop All'
4001 * ED - 'Existing Putaway Drop'
4002 * @param p_emp_id Employee identifier
4003 * @param p_lpn_id LPN for which this procedure is called.
4004 * @param p_item_drop_flag Whether it is called for all item drops or not
4005 * @param p_lpn_is_loaded Whether the LPN is already loaded or not.
4006
4007 **/
4008 PROCEDURE Create_Grouped_Tasks(
4009 x_return_status OUT NOCOPY VARCHAR2
4010 ,x_msg_count OUT NOCOPY NUMBER
4011 ,x_msg_data OUT NOCOPY VARCHAR2
4012 ,p_org_id IN NUMBER
4013 ,p_drop_type IN VARCHAR2
4014 ,p_emp_id IN NUMBER
4015 ,p_lpn_id IN NUMBER
4016 ,p_item_drop_flag IN VARCHAR2
4017 ,p_lpn_is_loaded IN VARCHAR2 )
4018 IS
4019 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
4020 l_progress VARCHAR2(10) := '10';
4021 l_proc_name VARCHAR2(30) := 'Create_Grouped_Tasks:';
4022 l_rec_count NUMBER := 0;
4023 l_del_count NUMBER := 0;
4024
4025 l_rowid_tab rowid_tab;
4026 l_drop_order_tab num_tab;
4027 l_lpn_id_tab num_tab;
4028 l_lpn_name_tab lpn_name_tab;
4029 l_lpn_level_tab num_tab;
4030 l_parent_lpn_id NUMBER;
4031
4032 -- This cursor will get all the LPNs and their drop_order where drop_type is CD.
4033 -- This cursor will be used to mark the consolidated LPN of all itz children with the current lpn.
4034 -- Start with the outermost LPN first and progress towards the childs.
4035
4036 -- For optimization we are marking the consolidated LPN from top down (order by lpn_level asc)
4037 -- and hence if consolidated lpn is marked we neednot mark it again for the children (since Mark Consolidated lpn
4038 -- would have already marked the consolidated lpn to the childs also)
4039 CURSOR c_lpn_cursor IS
4040 SELECT DISTINCT
4041 lpn_id
4042 ,lpn_name
4043 ,lpn_level
4044 FROM WMS_PUTAWAY_GROUP_TASKS_GTMP
4045 WHERE consolidated_lpn_id IS NULL
4046 AND drop_type = G_DT_CONSOLIDATED_DROP
4047 ORDER BY lpn_level ASC;
4048
4049
4050 BEGIN
4051
4052 IF (l_debug = 1) THEN
4053 DEBUG(' Procedure Entered at ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
4054 DEBUG(' p_org_id => '||p_org_id, l_proc_name,4);
4055 DEBUG(' p_drop_type => '||p_drop_type,l_proc_name,4);
4056 DEBUG(' p_emp_id => '||p_emp_id, l_proc_name,4);
4057 DEBUG(' p_lpn_id => '||p_lpn_id, l_proc_name,4);
4058 DEBUG(' p_item_drop_flag => '||p_item_drop_flag, l_proc_name,4);
4059 DEBUG(' p_lpn_is_loaded => '||p_lpn_is_loaded, l_proc_name,4);
4060 END IF;
4061
4062 l_progress := '20';
4063 x_return_status := fnd_api.g_ret_sts_success;
4064 l_progress := '30';
4065
4066 -- Always delete the existing records in the temp table before creating it.
4067 -- This code has to be later forked if the grouping logic has to be called for
4068 -- Restamping the drop type. In that case both delete and populate_group_tasks functions
4069 -- should not be called.
4070
4071 BEGIN -- Delete Existing rows in the temp table
4072
4073 l_progress := '40';
4074 -- Delete all the rows in the temp table
4075 l_del_count := Remove_Tasks_In_Group(
4076 p_del_type => 3
4077 );
4078 l_progress := '50';
4079
4080 IF l_del_count = -1 THEN
4081 --Deletion has failed so raise error.
4082 RAISE fnd_api.g_exc_unexpected_error;
4083 END IF;
4084
4085 l_progress := '60';
4086
4087 EXCEPTION
4088 WHEN OTHERS THEN
4089 RAISE fnd_api.g_exc_unexpected_error;
4090 END; -- Delete Existing rows in the temp table
4091
4092
4093 -- Check whether the LPN is already loaded or not.
4094 -- If already loaded procced with grouping logic,
4095 -- else call the ATF APIs to simulate the LOAD operation.
4096
4097 --LPN already loaded check
4098 IF p_lpn_is_loaded <> 'Y' THEN
4099
4100 l_progress := '100';
4101 -- We have to call the ATF APis to simulate the LOAD operation in case of single step drop
4102 BEGIN -- Simulate LOAAD
4103
4104 --BUG 3495726 Issue 25: Unpack from parent LPN first
4105 SELECT parent_lpn_id
4106 INTO l_parent_lpn_id
4107 FROM wms_license_plate_numbers
4108 WHERE lpn_id = p_lpn_id;
4109
4110 IF (l_parent_lpn_id IS NOT NULL) THEN
4111 IF (l_debug = 1) THEN
4112 DEBUG(' Unpacking LPN from Parent LPN' ,l_proc_name,9);
4113 END IF;
4114 wms_container_pvt.packunpack_container
4115 (p_api_version => 1.0
4116 ,p_content_lpn_id => p_lpn_id
4117 ,p_lpn_id => l_parent_lpn_id
4118 ,p_operation => 2 /* Unpack */
4119 ,p_organization_id => p_org_id
4120 ,x_return_status => x_return_status
4121 ,x_msg_count => x_msg_count
4122 ,x_msg_data => x_msg_data
4123 );
4124 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
4125 IF (l_debug = 1) THEN
4126 DEBUG(' Error Unpacking LPN from Parent LPN' ,l_proc_name,9);
4127 END IF;
4128 RAISE fnd_api.g_exc_error;
4129 END IF;
4130 END IF;
4131
4132 IF (l_debug = 1) THEN
4133 DEBUG(' Calling Complete Instance for the LOAD Operation ... ' || x_msg_data ,l_proc_name,9);
4134 END IF;
4135
4136 l_progress := '110';
4137 Complete_ATF_Load (x_return_status => x_return_status
4138 ,x_msg_count => x_msg_count
4139 ,x_msg_data => x_msg_data
4140 ,p_org_id => p_org_id
4141 ,p_lpn_id => p_lpn_id
4142 ,p_emp_id => p_emp_id );
4143 l_progress := '120';
4144
4145
4146 -- Check for the return status
4147 IF x_return_status = fnd_api.g_ret_sts_success THEN
4148 -- Activate completed successfully.
4149 NULL;
4150
4151 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
4152 RAISE fnd_api.g_exc_error;
4153
4154 ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4155 RAISE fnd_api.g_exc_unexpected_error;
4156
4157 END IF;
4158
4159 l_progress := '130';
4160
4161 EXCEPTION
4162 WHEN OTHERS THEN
4163 RAISE fnd_api.g_exc_unexpected_error;
4164 END; -- Simulate LOAAD
4165
4166 END IF; --LPN already loaded check
4167
4168
4169
4170
4171 --Grouping logic
4172 /* This procedure is the starting point for groupping logic
4173 * This inturn will do the following
4174 *
4175 * 1. Populate group tasks with the required data
4176 * 2. Order the temp table and stamp the drop_order
4177 * 3. Resolve the columns like parent_lpn_id, outermost_lpn_id and LPN_NAME etc.,
4178 * 4. Group the tasks
4179 */
4180
4181 IF (l_debug = 1) THEN
4182 DEBUG(' Before calling pvt function Populate_group_tasks ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,9);
4183 DEBUG(' p_org_id => '||p_org_id, l_proc_name,4);
4184 DEBUG(' p_drop_type => '||p_drop_type,l_proc_name,4);
4185 DEBUG(' p_emp_id => '||p_emp_id, l_proc_name,4);
4186 DEBUG(' p_lpn_id => '||p_lpn_id, l_proc_name,4);
4187 END IF;
4188
4189 --Calling Populate_group_tasks to populate the global temp table
4190 l_progress := '200';
4191 l_rec_count := Populate_group_tasks( p_org_id => p_org_id
4192 ,p_drop_type => p_drop_type
4193 ,p_emp_id => p_emp_id
4194 ,p_lpn_id => p_lpn_id
4195 ,p_item_drop_flag => p_item_drop_flag
4196 );
4197 l_progress := '210';
4198
4199 IF (l_debug = 1) THEN
4200 DEBUG(' After calling pvt function Populate_group_tasks ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,9);
4201 DEBUG(' l_rec_count => '|| l_rec_count,l_proc_name,4);
4202 END IF;
4203
4204 -- Record count take the following values after calling Populate_group_tasks
4205 -- -1 --> In case of failure
4206 -- 0 --> No rows found
4207 -- >1 --> In case of success.
4208
4209 -- Error out since it is failure case
4210 IF l_rec_count = -1 THEN
4211 l_progress := '220';
4212 RAISE fnd_api.g_exc_error;
4213 END IF;
4214
4215 -- No tasks available. Set the message and display it in the UI
4216 IF l_rec_count = 0 THEN
4217 l_progress := '225';
4218 -- No Tasks found for the data passed
4219 -- Set error message and raise error handle it in exception block.
4220 FND_MESSAGE.SET_NAME('WMS','WMS_NO_TASKS');
4221 fnd_msg_pub.ADD;
4222 -- Instead of raising an error, return with success
4223 RETURN;
4224 END IF;
4225
4226
4227 --Call ATF API for stamping the dest sub/loc/LPN
4228 BEGIN --ATF Call to Activate
4229
4230 l_progress := '250';
4231 l_rec_count := Activate_Plan_For_Drop (x_return_status => x_return_status
4232 ,x_msg_count => x_msg_count
4233 ,x_msg_data => x_msg_data );
4234 l_progress := '260';
4235
4236
4237 -- Check for the return status
4238 IF x_return_status = fnd_api.g_ret_sts_success THEN
4239 -- Activate completed successfully.
4240 NULL;
4241
4242 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
4243 RAISE fnd_api.g_exc_error;
4244
4245 ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
4246 RAISE fnd_api.g_exc_unexpected_error;
4247
4248 ELSIF l_rec_count = -1 THEN
4249 RAISE fnd_api.g_exc_unexpected_error;
4250
4251 END IF;
4252
4253
4254 EXCEPTION
4255 WHEN OTHERS THEN
4256 RAISE fnd_api.g_exc_unexpected_error;
4257
4258 END; --ATF Call to Activate
4259
4260 -- Core Grouping logic
4261 -- call the grouping function for consolidating drop
4262 -- call the API for stamping the consolidated lpn
4263 -- call the grouping function for grouping the MMTTs for item drop
4264 -- call the function to insert group tasks rows
4265
4266 -- Call the function which will populate the drop type correctly and
4267 -- group the tasks
4268
4269 --IF p_item_drop_flag <> 'Y' THEN --p_item_drop_flag check
4270 BEGIN --Populating the drop type
4271
4272 l_progress := '300';
4273
4274 IF (l_debug = 1) THEN
4275 DEBUG(' Before calling pvt function Populate_Drop_type ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,9);
4276 END IF;
4277
4278 -- This function call will group the tasks and populate the drop type correctly
4279 -- After this function call, the temp table will have the tasks grouped correctly.
4280 l_progress := '310';
4281 l_rec_count := Populate_Drop_Type;
4282 l_progress := '320';
4283
4284 IF (l_debug = 1) THEN
4285 DEBUG(' After calling pvt function Populate_Drop_type ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,9);
4286 END IF;
4287
4288 IF l_rec_count = -1 THEN -- l_rec_count check
4289 l_progress := '330';
4290 IF (l_debug = 1) THEN
4291 DEBUG('Populate_Drop_type returned error and hence raising exception ',l_proc_name,1);
4292 END IF;
4293
4294 l_progress := '340';
4295 RAISE fnd_api.g_exc_error;
4296 END IF; -- l_rec_count check
4297
4298 l_progress := '350';
4299 EXCEPTION
4300 WHEN OTHERS THEN
4301 RAISE fnd_api.g_exc_unexpected_error;
4302 END;--Populating the drop type
4303
4304 -- END IF; --p_item_drop_flag check
4305
4306
4307 -- Call the function which will mark the consolidated LPN and the drop_order
4308 -- This function will be called only for those LPNs which have drop_type as 'CD'
4309 BEGIN -- Mark Consolidated LPN
4310
4311 l_progress := '400';
4312 OPEN c_lpn_cursor;
4313 l_progress := '410';
4314
4315 LOOP -- c_lpn_cursor
4316
4317 --BUG 5187983: Requery c_lpn_cursor everytime
4318 --so that it will won't pick up the same lines
4319 --already marked by Mark_Consolidated_LPN
4320 l_lpn_id_tab.delete;
4321 l_lpn_name_tab.delete;
4322 l_lpn_level_tab.delete;
4323
4324 FETCH c_lpn_cursor
4325 INTO l_lpn_id_tab(1)
4326 ,l_lpn_name_tab(1)
4327 ,l_lpn_level_tab(1);
4328
4329 EXIT WHEN c_lpn_cursor%NOTFOUND;
4330 l_progress := '405';
4331
4332 CLOSE c_lpn_cursor;
4333
4334 IF (l_debug = 1) Then
4335 DEBUG('COUNT:'||l_lpn_id_tab.COUNT,l_proc_name,9);
4336 DEBUG('LPN_ID:'||l_lpn_id_tab(1));
4337 DEBUG('LPN_NAME:'||l_lpn_name_tab(1));
4338 DEBUG('LPN_LEVEL:'||l_lpn_level_tab(1));
4339 END IF;
4340
4341 l_progress := '460';
4342
4343 IF (l_debug = 1) THEN
4344 DEBUG(' Before calling pvt function Mark_Consolidated_LPN ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,9);
4345 END IF;
4346
4347 -- This function call will group the tasks and populate the drop type correctly
4348 -- After this function call, the temp table will have the tasks grouped correctly.
4349 l_progress := '470';
4350 l_rec_count := Mark_Consolidated_LPN( p_lpn_id => l_lpn_id_tab(1)
4351 ,p_lpn_name => l_lpn_name_tab(1)
4352 );
4353 l_progress := '480';
4354
4355 IF (l_debug = 1) THEN
4356 DEBUG(' After calling pvt function Mark_Consolidated_LPN ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,9);
4357 END IF;
4358
4359 l_progress := '490';
4360
4361 IF l_rec_count = -1 THEN -- l_rec_count check
4362 l_progress := '500';
4363 IF (l_debug = 1) THEN
4364 DEBUG('Mark_Consolidated_LPN returned error and hence raising exception ',l_proc_name,1);
4365 END IF;
4366
4367 l_progress := '510';
4368 RAISE fnd_api.g_exc_error;
4369 END IF; -- l_rec_count check
4370
4371 OPEN c_lpn_cursor;
4372 -- END BUG 5187983
4373 END LOOP; -- c_lpn_cursor
4374
4375 l_progress := '520';
4376 CLOSE c_lpn_cursor;
4377 l_progress := '525';
4378
4379
4380 EXCEPTION
4381 WHEN OTHERS THEN
4382 RAISE fnd_api.g_exc_unexpected_error;
4383 END;-- Mark Consolidated LPN
4384
4385
4386 BEGIN --Group_Item_Drop_Tasks
4387
4388 -- Calling the method to insert the consolidate group tasks
4389 l_rec_count := Group_Item_Drop_Tasks;
4390 l_progress := '620';
4391
4392 IF l_rec_count = -1 THEN -- l_rec_count check
4393 l_progress := '630';
4394 IF (l_debug = 1) THEN
4395 DEBUG('Group_Item_Drop_Tasks returned error and hence raising exception ',l_proc_name,1);
4396 END IF;
4397
4398 l_progress := '640';
4399 RAISE fnd_api.g_exc_error;
4400 END IF; -- l_rec_count check
4401
4402 l_progress := '650';
4403
4404 EXCEPTION
4405 WHEN OTHERS THEN
4406 RAISE fnd_api.g_exc_unexpected_error;
4407 END;--Group_Item_Drop_Tasks
4408
4409
4410
4411 BEGIN --Group_Consolidated_Drop_Tasks
4412
4413 -- Calling the method to insert the consolidate group tasks
4414 l_rec_count := Group_Consolidated_Drop_Tasks;
4415 l_progress := '720';
4416
4417 IF l_rec_count = -1 THEN -- l_rec_count check
4418 l_progress := '730';
4419 IF (l_debug = 1) THEN
4420 DEBUG('Group_Consolidated_Drop_Tasks returned error and hence raising exception ',l_proc_name,1);
4421 END IF;
4422
4423 l_progress := '740';
4424 RAISE fnd_api.g_exc_error;
4425 END IF; -- l_rec_count check
4426
4427 l_progress := '750';
4428
4429 EXCEPTION
4430 WHEN OTHERS THEN
4431 RAISE fnd_api.g_exc_unexpected_error;
4432 END;--Group_Consolidated_Drop_Tasks
4433
4434
4435 BEGIN --Sync_Group_Tasks
4436
4437 -- Calling the method to insert common transaction_header_id and group_id for a group
4438 l_rec_count := Sync_Group_Tasks;
4439 l_progress := '820';
4440
4441 IF l_rec_count = -1 THEN -- l_rec_count check
4442 l_progress := '830';
4443 IF (l_debug = 1) THEN
4444 DEBUG('Sync_Group_Tasks returned error and hence raising exception ',l_proc_name,1);
4445 END IF;
4446
4447 l_progress := '840';
4448 RAISE fnd_api.g_exc_error;
4449 END IF; -- l_rec_count check
4450
4451 l_progress := '850';
4452
4453 EXCEPTION
4454 WHEN OTHERS THEN
4455 RAISE fnd_api.g_exc_unexpected_error;
4456 END;--Sync_Group_Tasks
4457
4458
4459 -- Done with the grouping logic, so go ahead and delete the dummy rows
4460 BEGIN --Delete dummy rows
4461
4462 l_progress := '940';
4463 -- Delete all the rows in the temp table
4464 l_del_count := Remove_Tasks_In_Group(
4465 p_del_type => 2
4466 );
4467 l_progress := '950';
4468
4469 EXCEPTION
4470 WHEN OTHERS THEN
4471 NULL;
4472 END; --Delete dummy rows
4473
4474 l_progress := '960';
4475 -- Building the temp table is successful.. go ahead and commit the changes
4476 COMMIT;
4477 l_progress := '965';
4478
4479 -- Lock all the LPNs the user is currently working on
4480 -- We are re-locking again since the commit above would have relieved the lock.
4481 Lock_LPNs( x_return_status => x_return_status
4482 ,x_msg_count => x_msg_count
4483 ,x_msg_data => x_msg_data );
4484
4485 l_progress := '970';
4486
4487 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
4488 IF (l_debug = 1) THEN
4489 DEBUG(' Error in locking LPNs ' || x_msg_data ,l_proc_name,1);
4490 END IF;
4491
4492 l_progress := '980';
4493 RAISE fnd_api.g_exc_error;
4494 END IF;
4495
4496
4497 IF (l_debug = 1) THEN
4498 DEBUG(' x_return_status => '|| x_return_status,l_proc_name,4);
4499 DEBUG(' x_msg_count => '|| x_msg_count,l_proc_name,4);
4500 DEBUG(' x_msg_data => '|| x_msg_data,l_proc_name,4);
4501 DEBUG(' Procedure Exited at ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
4502 END IF;
4503
4504 l_progress := '1000';
4505
4506 EXCEPTION
4507 WHEN fnd_api.g_exc_error THEN
4508 x_return_status := fnd_api.g_ret_sts_error;
4509 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
4510 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
4511 DEBUG(SQLERRM,l_proc_name,1);
4512
4513 IF c_lpn_cursor%isopen THEN
4514 CLOSE c_lpn_cursor;
4515 END IF;
4516
4517 WHEN fnd_api.g_exc_unexpected_error THEN
4518 x_return_status := fnd_api.g_ret_sts_unexp_error;
4519 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
4520 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
4521 DEBUG(SQLERRM,l_proc_name,1);
4522
4523 IF c_lpn_cursor%isopen THEN
4524 CLOSE c_lpn_cursor;
4525 END IF;
4526
4527
4528 WHEN OTHERS THEN
4529 x_return_status := fnd_api.g_ret_sts_unexp_error;
4530 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
4531 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
4532 DEBUG(SQLERRM,l_proc_name,1);
4533
4534 IF c_lpn_cursor%isopen THEN
4535 CLOSE c_lpn_cursor;
4536 END IF;
4537
4538
4539 END Create_grouped_tasks; -- Procedure Create_grouped_tasks
4540
4541
4542 /**
4543 * This procedure will explode the LPN passed and will get all the MMTTs
4544 * for its contents (including childs contents) and will call the ATF API to
4545 * Abort the operation instance.
4546 *
4547 * The parameter p_call_type will decide what ATF API to call
4548 * p_call_type Gloabl Constant Meaning
4549 * 1 G_ATF_ACTIVATE_PLAN Activate Plan
4550 * 2 G_ATF_ABORT_PLAN Abort Plan
4551 *
4552 * @param p_call_type Mode for which the procedure is called
4553 * @param p_org_id Organization Identifier
4554 * @param p_lpn_id LPN identifier
4555 * @param p_emp_id Employee identifier
4556 *
4557 * @param x_return_status Return status of the function - Success, Error, Unexpected Error, Warning etc.,
4558 * @param x_msg_count Count of messages in the stack
4559 * @param x_msg_data Actual message if the count = 1 else it will be null.
4560 *
4561 **/
4562
4563 -- In case of Manual/User Drop the ATF API's will be still used to create WDTs and WDTH.
4564 -- Before that the existing WDTs, Plans etc has to be deleted and hence Abort plan has to be called first.
4565 PROCEDURE ATF_For_Manual_Drop(
4566 x_return_status OUT NOCOPY VARCHAR2
4567 ,x_msg_count OUT NOCOPY NUMBER
4568 ,x_msg_data OUT NOCOPY VARCHAR2
4569 ,p_call_type IN NUMBER
4570 ,p_org_id IN NUMBER
4571 ,p_lpn_id IN NUMBER
4572 ,p_emp_id IN NUMBER
4573 ) IS
4574 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
4575 l_progress VARCHAR2(10) := '10';
4576 l_rec_count NUMBER := 0;
4577 l_proc_name VARCHAR2(30) := 'ATF_For_Manual_Drop:';
4578
4579 l_error_code NUMBER;
4580 l_tempid_tab num_tab;
4581 l_task_rec task_rec := NULL;
4582
4583 l_consolidation_method_id NUMBER;
4584 l_drop_lpn_option NUMBER;
4585
4586 -- This cursor will get the MMTTs assoicated with the contents of the LPN passed
4587 -- along with the MMTTs of the contents of all its child LPNs also.
4588 --Bug5723418.Performance fix.Moved wlpn to FROM clause.
4589 -- Performane fix as a part of bug 7143123
4590 CURSOR c_all_mmtt_cursor IS
4591 SELECT /*+ ORDERED USE_NL(WLPN MTRL MMTT) INDEX(MTRL MTL_TXN_REQUEST_LINES_N7) */
4592 MMTT.TRANSACTION_TEMP_ID
4593 FROM
4594 ( SELECT LPN_ID
4595 FROM WMS_LICENSE_PLATE_NUMBERS START WITH LPN_ID = p_lpn_id CONNECT BY PRIOR LPN_ID = PARENT_LPN_ID ) WLPN,
4596 MTL_TXN_REQUEST_LINES MTRL,
4597 MTL_MATERIAL_TRANSACTIONS_TEMP MMTT
4598 WHERE MTRL.LINE_ID = MMTT.MOVE_ORDER_LINE_ID
4599 AND LINE_STATUS = 7
4600 AND MTRL.LPN_ID = WLPN.LPN_ID ;
4601
4602
4603 BEGIN
4604
4605 IF (l_debug = 1) THEN
4606 DEBUG('Start of function ' || l_proc_name ,l_proc_name,9);
4607 END IF;
4608
4609 -- Set the return status to success.
4610 l_progress := '20';
4611 x_return_status := fnd_api.g_ret_sts_success;
4612 l_progress := '30';
4613
4614 -- Setting the values for the task record
4615 -- Thought this is for Drop, The existing WDTs if any for load would have been deleted
4616 -- and hence these records has to be created afresh.
4617 l_task_rec.person_id := p_emp_id;
4618 l_task_rec.organization_id := p_org_id;
4619 l_task_rec.user_task_type := -1;
4620
4621
4622 l_progress := '100';
4623 OPEN c_all_mmtt_cursor;
4624 l_progress := '110';
4625
4626 LOOP -- c_all_tasks_cursor loop
4627
4628 EXIT WHEN c_all_mmtt_cursor%NOTFOUND;
4629 l_progress := '200';
4630
4631 FETCH c_all_mmtt_cursor
4632 BULK COLLECT
4633 INTO l_tempid_tab
4634 LIMIT l_limit;
4635 l_progress := '210';
4636
4637 l_rec_count := l_rec_count + l_tempid_tab.COUNT;
4638 l_progress := '220';
4639
4640 -- Activate each MMTT's
4641 FOR i IN 1 .. l_tempid_tab.COUNT
4642 LOOP --All temp ids loop
4643
4644 -- Check the mode for which the integration API is called
4645 IF p_call_type = G_ATF_ABORT_PLAN THEN
4646
4647 IF (l_debug = 1) THEN
4648 DEBUG('Calling abort_operation_instance with ...',l_proc_name,9);
4649 DEBUG('p_source_task_id => ' || l_tempid_tab(i),l_proc_name,9);
4650 DEBUG('p_activity_type_id => ' || G_OP_ACTIVITY_INBOUND,l_proc_name,9);
4651 END IF;
4652 l_progress := '300';
4653
4654 --BUG 3666138: Pass in 1 more parameter, p_for_manual_drop, so
4655 --that ATF would call revert_loc_sugg_capacity with an
4656 --autonomous commit
4657 wms_atf_runtime_pub_apis.Abort_Operation_Plan
4658 ( p_source_task_id => l_tempid_tab(i)
4659 ,p_activity_type_id => G_OP_ACTIVITY_INBOUND
4660 ,x_return_status => x_return_status
4661 ,x_msg_data => x_msg_data
4662 ,x_msg_count => x_msg_count
4663 ,x_error_code => l_error_code
4664 ,p_for_manual_drop => true
4665 );
4666
4667 l_progress := '310';
4668
4669 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
4670 IF (l_debug = 1) THEN
4671 DEBUG(l_error_code || ' Error in abort_operation_instance ' ,l_proc_name,1);
4672 END IF;
4673 l_progress := '320';
4674
4675 RAISE fnd_api.g_exc_error;
4676 END IF;
4677
4678 ELSIF p_call_type = g_atf_cancel_plan THEN
4679 IF (l_debug = 1) THEN
4680 DEBUG('Calling cancel_operation_plan with ...',l_proc_name,9);
4681 DEBUG('p_source_task_id => ' || l_tempid_tab(i),l_proc_name,9);
4682 DEBUG('p_activity_type_id => ' || G_OP_ACTIVITY_INBOUND,l_proc_name,9);
4683 END IF;
4684 l_progress := '330';
4685
4686 wms_atf_runtime_pub_apis.cancel_operation_plan
4687 ( p_source_task_id => l_tempid_tab(i)
4688 ,p_activity_type_id => G_OP_ACTIVITY_INBOUND
4689 ,x_return_status => x_return_status
4690 ,x_msg_data => x_msg_data
4691 ,x_msg_count => x_msg_count
4692 ,x_error_code => l_error_code
4693 );
4694 l_progress := '340';
4695
4696 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
4697 IF (l_debug = 1) THEN
4698 DEBUG(l_error_code || ' Error in cancel_operation_plan ' ,l_proc_name,1);
4699 END IF;
4700 l_progress := '350';
4701
4702 RAISE fnd_api.g_exc_error;
4703 END IF;
4704 ELSIF p_call_type = G_ATF_ACTIVATE_PLAN THEN
4705 IF (l_debug = 1) THEN
4706 DEBUG('Calling activate_operation_instance with ...',l_proc_name,9);
4707 DEBUG('p_source_task_id => ' || l_tempid_tab(i),l_proc_name,9);
4708 DEBUG('p_activity_type_id => ' || G_OP_ACTIVITY_INBOUND,l_proc_name,9);
4709 DEBUG('p_task_execute_rec => l_task_rec',l_proc_name,9);
4710 DEBUG('p_operation_type_id => ' || G_OP_TYPE_DROP,l_proc_name,9);
4711 END IF;
4712 l_progress := '330';
4713
4714 wms_atf_runtime_pub_apis.activate_operation_instance
4715 ( p_source_task_id => l_tempid_tab(i)
4716 ,p_activity_id => G_OP_ACTIVITY_INBOUND
4717 ,p_task_execute_rec => l_task_rec
4718 ,p_operation_type_id => G_OP_TYPE_DROP
4719 ,x_return_status => x_return_status
4720 ,x_msg_data => x_msg_data
4721 ,x_msg_count => x_msg_count
4722 ,x_error_code => l_error_code
4723 ,x_consolidation_method_id => l_consolidation_method_id
4724 ,x_drop_lpn_option => l_drop_lpn_option
4725 );
4726 l_progress := '340';
4727
4728 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
4729 IF (l_debug = 1) THEN
4730 DEBUG(l_error_code || ' Error in activate_operation_instance ' ,l_proc_name,1);
4731 END IF;
4732 l_progress := '350';
4733
4734 RAISE fnd_api.g_exc_error;
4735 END IF;
4736
4737 ELSE
4738 -- Invalid value for mode, return error
4739 RAISE fnd_api.g_exc_error;
4740
4741 END IF; -- Check the mode for which the integration API is called
4742
4743
4744 END LOOP; --All temp ids loop
4745
4746 END LOOP; -- c_all_tasks_cursor loop
4747
4748 -- Close all the open cursors if any.
4749 IF c_all_mmtt_cursor%ISOPEN THEN
4750 l_progress := '500';
4751 CLOSE c_all_mmtt_cursor;
4752 END IF;
4753
4754
4755 EXCEPTION
4756
4757 WHEN fnd_api.g_exc_error THEN
4758 x_return_status := fnd_api.g_ret_sts_error;
4759 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
4760 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
4761 DEBUG(SQLERRM,l_proc_name,1);
4762
4763 IF c_all_mmtt_cursor%isopen THEN
4764 CLOSE c_all_mmtt_cursor;
4765 END IF;
4766
4767 WHEN fnd_api.g_exc_unexpected_error THEN
4768 x_return_status := fnd_api.g_ret_sts_unexp_error;
4769 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
4770 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
4771 DEBUG(SQLERRM,l_proc_name,1);
4772
4773 IF c_all_mmtt_cursor%isopen THEN
4774 CLOSE c_all_mmtt_cursor;
4775 END IF;
4776
4777
4778 WHEN OTHERS THEN
4779 x_return_status := fnd_api.g_ret_sts_unexp_error;
4780 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
4781 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
4782 DEBUG(SQLERRM,l_proc_name,1);
4783
4784 IF c_all_mmtt_cursor%isopen THEN
4785 CLOSE c_all_mmtt_cursor;
4786 END IF;
4787
4788 END ATF_For_Manual_Drop;
4789
4790
4791
4792 /**
4793 * This function will call the ATF API to activate the operation instance for inspect.
4794 * It will call the ATF API wms_atf_runtime_pub_apis.activate_operation_instance for
4795 * each MMTT. For the Move Order Line passed.
4796 *
4797 * ATF will check whether the current step. If it is not inspect, it will inturn call
4798 * the Abort operation instance to abort the current plan in progress. So we need not
4799 * call Abort Explicitly in this case.
4800 *
4801 * It returns the number of rows for which the plan is
4802 * activated, will return -1 in case of failure.
4803
4804 * @param x_return_status Return status of the function - Success, Error, Unexpected Error, Warning etc.,
4805 * @param x_msg_count Count of messages in the stack
4806 * @param x_msg_data Actual message if the count = 1 else it will be null.
4807 * @param p_org_id Organization Identifier
4808 * @param p_lpn_id LPN Identifier
4809 * @param p_emp_id Employee Identifier
4810 *
4811 * @ RETURN NUMBER
4812
4813
4814 **/
4815 FUNCTION Activate_Plan_For_Inspect(
4816 x_return_status OUT NOCOPY VARCHAR2
4817 ,x_msg_count OUT NOCOPY NUMBER
4818 ,x_msg_data OUT NOCOPY VARCHAR2
4819 ,p_org_id IN NUMBER
4820 ,p_mo_line_id IN NUMBER )
4821 RETURN NUMBER
4822 IS
4823
4824 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
4825 l_progress VARCHAR2(10) := '10';
4826 l_rec_count NUMBER := 0;
4827 l_proc_name VARCHAR2(30) := 'Activate_Plan_For_Inspect:';
4828
4829 l_error_code NUMBER;
4830 l_task_rec task_rec := NULL;
4831 l_tempid_tab num_tab;
4832 l_user_id NUMBER := fnd_global.user_id;
4833 l_emp_id NUMBER;
4834
4835 l_consolidation_method_id NUMBER;
4836 l_drop_lpn_option NUMBER;
4837
4838 -- This cursor will get the MMTTs assoicated with the move order line passed
4839 CURSOR c_mol_mmtt_cursor IS
4840 SELECT mmtt.transaction_temp_id
4841 FROM mtl_material_transactions_temp mmtt
4842 ,mtl_txn_request_lines mtrl
4843 WHERE mtrl.line_id = mmtt.move_order_line_id
4844 AND mtrl.line_id = p_mo_line_id
4845 AND mtrl.line_status = 7
4846 AND mtrl.organization_id = p_org_id;
4847
4848 BEGIN
4849
4850 IF (l_debug = 1) THEN
4851 DEBUG('Start of function ' || l_proc_name ,l_proc_name,9);
4852 DEBUG(' p_org_id ==> '|| p_org_id,l_proc_name,4);
4853 DEBUG(' p_mo_line_id ==> '|| p_mo_line_id,l_proc_name,4);
4854 END IF;
4855
4856 -- Set the return status to success.
4857 l_progress := '20';
4858 x_return_status := fnd_api.g_ret_sts_success;
4859 l_progress := '30';
4860
4861 -- Get the employee ID so we can populate
4862 -- the person_id column in WDT properly.
4863 BEGIN -- Get the employee id
4864
4865 l_progress := '30';
4866 SELECT NVL(employee_id, -1)
4867 INTO l_emp_id
4868 FROM fnd_user
4869 WHERE user_id = l_user_id;
4870 l_progress := '40';
4871
4872 IF (l_debug = 1) THEN
4873 DEBUG(' Got the employee id = '|| l_emp_id || ' for the user ' || l_user_id,l_proc_name,9);
4874 END IF;
4875
4876 EXCEPTION
4877 WHEN NO_DATA_FOUND THEN
4878 DEBUG('Couldnot get the employee id and hence setting it to null ' ,l_proc_name,1);
4879 l_emp_id := NULL;
4880 l_progress := '50';
4881
4882 END; -- Get the employee id
4883 l_progress := '60';
4884
4885
4886 -- Setting the values for the task record
4887 -- Neednot set these values for drop since there ia already WDT,
4888 -- ATF will just change the status of this WDT record
4889 l_task_rec.person_id := l_emp_id;
4890 l_task_rec.organization_id := p_org_id;
4891 l_task_rec.user_task_type := -1;
4892
4893 l_progress := '100';
4894 OPEN c_mol_mmtt_cursor;
4895 l_progress := '110';
4896
4897 LOOP -- c_all_mmtt_cursor loop
4898
4899 EXIT WHEN c_mol_mmtt_cursor%NOTFOUND;
4900 l_progress := '200';
4901
4902 FETCH c_mol_mmtt_cursor
4903 BULK COLLECT
4904 INTO l_tempid_tab
4905 LIMIT l_limit;
4906 l_progress := '210';
4907
4908 l_rec_count := l_rec_count + l_tempid_tab.COUNT;
4909 l_progress := '220';
4910
4911 -- Activate each MMTT's
4912 FOR i IN 1 .. l_tempid_tab.COUNT
4913 LOOP --All temp ids loop
4914
4915 IF (l_debug = 1) THEN
4916 DEBUG('Calling activate_operation_instance with ...',l_proc_name,9);
4917 DEBUG('p_source_task_id => ' || l_tempid_tab(i),l_proc_name,9);
4918 DEBUG('p_activity_type_id => ' || G_OP_ACTIVITY_INBOUND,l_proc_name,9);
4919 DEBUG('p_task_execute_rec => l_task_rec',l_proc_name,9);
4920 DEBUG('p_operation_type_id => ' || G_OP_TYPE_DROP,l_proc_name,9);
4921 END IF;
4922 l_progress := '300';
4923
4924 wms_atf_runtime_pub_apis.activate_operation_instance
4925 ( p_source_task_id => l_tempid_tab(i)
4926 ,p_activity_id => G_OP_ACTIVITY_INBOUND
4927 ,p_task_execute_rec => l_task_rec
4928 ,p_operation_type_id => G_OP_TYPE_INSPECT
4929 ,x_return_status => x_return_status
4930 ,x_msg_data => x_msg_data
4931 ,x_msg_count => x_msg_count
4932 ,x_error_code => l_error_code
4933 ,x_consolidation_method_id => l_consolidation_method_id
4934 ,x_drop_lpn_option => l_drop_lpn_option
4935 );
4936 l_progress := '310';
4937
4938 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
4939 IF (l_debug = 1) THEN
4940 DEBUG(l_error_code || ' Error in activate_operation_instance ' ,l_proc_name,1);
4941 END IF;
4942 l_progress := '320';
4943
4944 RAISE fnd_api.g_exc_error;
4945 END IF;
4946
4947 END LOOP; --All temp ids loop
4948
4949 END LOOP; -- c_all_mmtt_cursor loop
4950
4951
4952 IF c_mol_mmtt_cursor%ISOPEN THEN
4953 CLOSE c_mol_mmtt_cursor;
4954 END IF;
4955
4956 l_progress := '990';
4957 --Return the count of rows processed
4958 RETURN l_rec_count;
4959
4960 EXCEPTION
4961 WHEN fnd_api.g_exc_error THEN
4962 x_return_status := fnd_api.g_ret_sts_error;
4963 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
4964 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
4965 DEBUG(SQLERRM,l_proc_name,1);
4966
4967 IF c_mol_mmtt_cursor%ISOPEN THEN
4968 CLOSE c_mol_mmtt_cursor;
4969 END IF;
4970
4971 RETURN -1;
4972
4973
4974 WHEN fnd_api.g_exc_unexpected_error THEN
4975 x_return_status := fnd_api.g_ret_sts_unexp_error;
4976 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
4977
4978 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
4979 DEBUG(SQLERRM,l_proc_name,1);
4980
4981 IF c_mol_mmtt_cursor%ISOPEN THEN
4982 CLOSE c_mol_mmtt_cursor;
4983 END IF;
4984
4985 RETURN -1;
4986
4987
4988 WHEN OTHERS THEN
4989 x_return_status := fnd_api.g_ret_sts_unexp_error;
4990 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
4991 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
4992 DEBUG(SQLERRM,l_proc_name,1);
4993
4994 IF c_mol_mmtt_cursor%ISOPEN THEN
4995 CLOSE c_mol_mmtt_cursor;
4996 END IF;
4997
4998 RETURN -1;
4999
5000 END Activate_Plan_For_Inspect;
5001
5002
5003 /**
5004 * This function will call the ATF API to cleanup / rollback
5005 * the operation instance for load / drop / single step drop.
5006 *
5007 * It will call the ATF APIs for each MMTT in the temp table
5008 * if group_id is not passed else it will call ATF APIs only
5009 * for that group in the temp table.
5010 *
5011 * It returns the number of rows for which the plan is
5012 * cleanedup / rolled back, will return -1 in case of failure.
5013 *
5014 * The parameter p_call_type will decide what ATF API to call
5015 * p_call_type Gloabl Constant Meaning
5016 * ----------------------------------------------------------
5017 * 1 G_CT_NORMAL_LOAD Called from Load scenario (Manual Load)
5018 * 2 G_CT_NORMAL_DROP Called from Drop (LPN already loaded)
5019 * 3 G_CT_SINGLE_STEP_DROP Called from Drop (LPN already loaded)
5020 * 4 G_CT_INSPECT_TM_FAILED Called from Inspect when it is after tm failure
5021 * 5 G_CT_INSPECT_B4_TM Called from Inspect when it is before calling TM
5022 *
5023 * if p_call_type = 3, Rollback_operation_plan will be called
5024 * else Cleanup_Operation_Instance will be called.
5025 *
5026 *
5027 * @param x_return_status Return status of the function - Success, Error, Unexpected Error,
5028 * Warning etc.,
5029 * @param x_msg_count Count of messages in the stack
5030 * @param x_msg_data Actual message if the count = 1 else it will be null.
5031 * @param p_org_id Organization Identifier
5032 * @param p_call_type Whether cleanup is called for load, drop or single step drop
5033 * @param p_lpn_id LPN Identifier
5034 * @param p_group_id Group ID for which cleanup has to be called.
5035 * Can have following values:
5036 * -1: Called when one of the tasks failed and
5037 * user decided to quit all tasks
5038 * -2: Called at the end of all tasks to clean up
5039 * task split during partial drop
5040 * NULL: Called in cases of Manual Drop, Inspection,
5041 * Manual Load
5042 * Others: Called when one of the tasks failed and
5043 * user wants to cancel just this task
5044 * @ RETURN NUMBER
5045
5046
5047 **/
5048 PROCEDURE Cleanup_ATF(
5049 x_return_status OUT NOCOPY VARCHAR2
5050 ,x_msg_count OUT NOCOPY NUMBER
5051 ,x_msg_data OUT NOCOPY VARCHAR2
5052 ,p_org_id IN NUMBER
5053 ,p_call_type IN NUMBER
5054 ,p_lpn_id IN NUMBER
5055 ,p_group_id IN NUMBER
5056 ,p_parent_lpn_id IN NUMBER
5057 ,p_drop_all IN VARCHAR2 --BUG 5075410
5058 ,p_emp_id IN NUMBER) --BUG 5075410
5059 IS
5060 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
5061 l_progress VARCHAR2(10) := '10';
5062 l_rec_count NUMBER := 0;
5063 l_proc_name VARCHAR2(30) := 'Cleanup_ATF:';
5064
5065 l_error_code NUMBER;
5066 l_tempid_tab num_tab;
5067
5068 l_op_plan_id NUMBER;
5069 l_lpn_context NUMBER;
5070 l_mmtt_item_id NUMBER;
5071 l_mmtt_uom VARCHAR2(3);
5072 l_mmtt_qty NUMBER;
5073 l_mol_id NUMBER;
5074 l_mol_uom VARCHAR2(3);
5075 l_mmtt_qty_mol_uom NUMBER;
5076 l_wms_process_flag NUMBER;
5077 l_outermost_lpn_id NUMBER;
5078
5079 -- This cursor will get the all the MMTTs assoicated with the lpn_id passed.
5080 -- Cleanup shouldn't be called if there is not WDT and hence added a join with WDT.
5081 CURSOR c_mol_mmtt_cursor IS
5082 SELECT mmtt.transaction_temp_id
5083 FROM mtl_material_transactions_temp mmtt
5084 ,mtl_txn_request_lines mtrl
5085 ,wms_dispatched_tasks wdt
5086 ,(SELECT lpn_id FROM wms_license_plate_numbers /*Bug5723418.*/
5087 START WITH lpn_id = p_lpn_id
5088 CONNECT BY PRIOR lpn_id = parent_lpn_id
5089 ) wlpn
5090 WHERE wdt.transaction_temp_id = mmtt.transaction_temp_id
5091 -- BUG 5075410: WDT MOL is not being kept in sync when split.
5092 -- Querying through WDT->MMTT->MTRL should be enough
5093 -- AND wdt.move_order_line_id = mtrl.line_id
5094 AND mtrl.line_id = mmtt.move_order_line_id
5095 AND mtrl.line_status = 7
5096 AND mtrl.organization_id = p_org_id
5097 AND mtrl.lpn_id = wlpn.lpn_id;
5098
5099
5100 -- This cursor will get the MMTTs assoicated with the group_id passed from the temp table
5101 CURSOR c_tmp_mmtt_cursor IS
5102 SELECT transaction_temp_id
5103 FROM wms_putaway_group_tasks_gtmp
5104 WHERE group_id = p_group_id
5105 AND row_type = G_ROW_TP_ALL_TASK;
5106
5107 --BUG 5075410: The c_all_mmtt_cursor is used in the following scenarios:
5108 --1) When user finishes all tasks (p_group_id = -2), system only needs
5109 -- to cleanup the tasks split when User performed partial. So join
5110 -- on task_type/wms_process_flag/transaction_status so that the txn
5111 -- submitted from transaction is picked up
5112 --2) When user presses F2 (p_group_id = -1)
5113 --3) When user encounter an error, and he decides to quit all tasks
5114 -- (p_group_id = -1). In this cursor, select all the tasks that
5115 -- have drop active op plan or tasks that have wdt status 4 (loaded).
5116 CURSOR c_all_mmtt_cursor IS
5117 SELECT mmtt.transaction_temp_id
5118 FROM wms_dispatched_tasks wdt
5119 ,mtl_txn_request_lines mtrl
5120 ,mtl_material_transactions_temp mmtt
5121 ,mtl_txn_request_headers mtrh
5122 WHERE mtrh.header_id = mtrl.header_id
5123 AND mtrh.move_order_type = 6
5124 AND mtrl.line_status = 7
5125 AND wdt.transaction_temp_id = mmtt.transaction_temp_id
5126 AND mmtt.move_order_line_id = mtrl.line_id
5127 AND ((p_group_id = -2
5128 AND Nvl(mtrl.wms_process_flag,1) <> 2 --RCV would set this to 2 for mol being processed
5129 AND Nvl(mmtt.wms_task_type,2) <> -1 --RCV would set this to -1 for MMTT being processed
5130 AND Nvl(mmtt.transaction_status,2) <> 3 --WIP would set this to 3 for MMTT being processed
5131 ) OR
5132 (p_group_id = -1))
5133 AND wdt.STATUS = 4
5134 AND wdt.task_type = 2
5135 AND mtrl.lpn_id IN (SELECT lpn_id
5136 FROM wms_license_plate_numbers
5137 START WITH lpn_id = l_outermost_lpn_id
5138 CONNECT BY PRIOR lpn_id = parent_lpn_id
5139 )
5140 AND ((mmtt.operation_plan_id IS NOT NULL
5141 AND exists (SELECT 1
5142 FROM wms_op_operation_instances wooi
5143 WHERE wooi.source_task_id = mmtt.transaction_temp_id
5144 AND wooi.operation_status = 2
5145 AND wooi.operation_type_id = 2))
5146 OR
5147 (mmtt.operation_plan_id IS NULL))
5148 AND p_drop_all <> 'Y'
5149 UNION ALL
5150 SELECT mmtt.transaction_temp_id
5151 FROM wms_dispatched_tasks wdt
5152 ,mtl_txn_request_lines mtrl
5153 ,mtl_material_transactions_temp mmtt
5154 ,mtl_txn_request_headers mtrh
5155 WHERE mtrh.header_id = mtrl.header_id
5156 AND mtrh.move_order_type = 6
5157 AND mtrl.line_status = 7
5158 AND wdt.transaction_temp_id = mmtt.transaction_temp_id
5159 AND mmtt.move_order_line_id = mtrl.line_id
5160 AND ((p_group_id = -2
5161 AND Nvl(mtrl.wms_process_flag,1) <> 2 --RCV would set this to 2 for mol being processed
5162 AND Nvl(mmtt.wms_task_type,2) <> -1 --RCV would set this to -1 for MMTT being processed
5163 AND Nvl(mmtt.transaction_status,2) <> 3 --WIP would set this to 3 for MMTT being processed
5164 ) OR
5165 (p_group_id = -1))
5166 AND wdt.task_type = 2
5167 AND wdt.STATUS = 4
5168 AND wdt.person_id = p_emp_id
5169 AND ((mmtt.operation_plan_id IS NOT NULL
5170 AND exists (SELECT 1
5171 FROM wms_op_operation_instances wooi
5172 WHERE wooi.source_task_id = mmtt.transaction_temp_id
5173 AND wooi.operation_status = 2
5174 AND wooi.operation_type_id = 2))
5175 OR
5176 (mmtt.operation_plan_id IS NULL))
5177 AND p_drop_all = 'Y';
5178
5179 BEGIN
5180
5181 --Part of bugfix 4114695 - should initialize this variable so that
5182 --calls from java aren't mislead to think this failed when indeed
5183 --it was a clean exit. Upon EXCEPTION, this flag is changedw
5184 x_return_status := fnd_api.g_ret_sts_success;
5185
5186 IF (l_debug = 1) THEN
5187 DEBUG('Start of function ' || l_proc_name ,l_proc_name,9);
5188 DEBUG(' p_call_type ==> '|| p_call_type,l_proc_name,4);
5189 DEBUG(' p_lpn_id ==> '|| p_lpn_id,l_proc_name,4);
5190 DEBUG(' p_group_id ==> '|| p_group_id,l_proc_name,4);
5191 DEBUG(' p_parent_lpn_id ==> '|| p_parent_lpn_id,l_proc_name,4);
5192 DEBUG(' p_drop_all ==> '|| p_drop_all,l_proc_name,4);
5193 DEBUG(' p_emp_id ==> '|| p_emp_id,l_proc_name,4);
5194 END IF;
5195
5196
5197 -- Check which cursor to open
5198 IF p_group_id IS NOT NULL THEN
5199 -- user has passed group id hence fetch from the temp table
5200 l_progress := '100';
5201
5202 IF (p_group_id in (-1,-2)) THEN
5203 BEGIN
5204 SELECT outermost_lpn_id
5205 , lpn_context
5206 INTO l_outermost_lpn_id
5207 , l_lpn_context
5208 FROM wms_license_plate_numbers
5209 WHERE lpn_id = p_lpn_id;
5210 EXCEPTION
5211 WHEN OTHERS THEN
5212 IF (l_debug = 1) THEN
5213 DEBUG('Error querying WLPN. SQLCODE:'||SQLCODE||' SQLERRM:'||SQLERRM,l_proc_name,9);
5214 END IF;
5215 RAISE fnd_api.g_exc_error;
5216 END;
5217
5218 IF (l_debug = 1) THEN
5219 DEBUG('Outermost LPN_ID:'||l_outermost_lpn_id,l_proc_name,9);
5220 END IF;
5221
5222 OPEN c_all_mmtt_cursor;
5223 ELSE
5224 OPEN c_tmp_mmtt_cursor;
5225 END IF;
5226
5227 l_progress := '110';
5228
5229 IF (p_group_id IN (-1,-2)) THEN
5230 FETCH c_all_mmtt_cursor
5231 BULK COLLECT
5232 INTO l_tempid_tab;
5233 ELSE
5234 FETCH c_tmp_mmtt_cursor
5235 BULK COLLECT
5236 INTO l_tempid_tab;
5237 END IF;
5238
5239 l_progress := '120';
5240
5241 IF (p_group_id IN (-1,-2)) THEN
5242 CLOSE c_all_mmtt_cursor;
5243 ELSE
5244 CLOSE c_tmp_mmtt_cursor;
5245 END IF;
5246
5247 l_progress := '130';
5248
5249 l_rec_count := l_tempid_tab.COUNT;
5250 l_progress := '140';
5251
5252 ELSIF p_lpn_id IS NOT NULL THEN
5253 -- user has not passed the group id but passed the lpn id hence fetch from MMTT/MTRL
5254
5255 l_progress := '200';
5256 OPEN c_mol_mmtt_cursor;
5257 l_progress := '210';
5258
5259 FETCH c_mol_mmtt_cursor
5260 BULK COLLECT
5261 INTO l_tempid_tab;
5262 l_progress := '220';
5263
5264 CLOSE c_mol_mmtt_cursor;
5265 l_progress := '230';
5266
5267 l_rec_count := l_tempid_tab.COUNT;
5268 l_progress := '240';
5269
5270 ELSE
5271 -- Invalid inputs passed hence error out
5272 l_progress := '299';
5273 RAISE fnd_api.g_exc_error;
5274
5275 END IF; -- Check which cursor to open
5276
5277
5278 IF p_call_type = G_CT_SINGLE_STEP_DROP THEN
5279 -- Single step drop hence we have to call Rollback_operation_plan
5280
5281 -- For single step drop, if the LPN is originally nested inside
5282 -- another LPN, during simulation of load, it will get unpacked
5283 -- from the outer LPN. So we must pack it back during the cleanup
5284 -- here.
5285 IF (Nvl(p_parent_lpn_id, 0) <> 0 AND Nvl(p_lpn_id, 0) <> 0) THEN
5286 IF (l_debug = 1) THEN
5287 DEBUG('Packing LPN ' || Nvl(p_lpn_id, -999) ||
5288 ' into Parent LPN ' || Nvl(p_parent_lpn_id, -999), l_proc_name,9);
5289 END IF;
5290
5291 wms_container_pvt.packunpack_container
5292 (p_api_version => 1.0
5293 ,p_content_lpn_id => p_lpn_id
5294 ,p_lpn_id => p_parent_lpn_id
5295 ,p_operation => 1 -- Pack
5296 ,p_organization_id => p_org_id
5297 ,x_return_status => x_return_status
5298 ,x_msg_count => x_msg_count
5299 ,x_msg_data => x_msg_data
5300 );
5301 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
5302 IF (l_debug = 1) THEN
5303 DEBUG('Error packing LPN into original parent...', l_proc_name,9);
5304 END IF;
5305 RAISE fnd_api.g_exc_error;
5306 END IF;
5307 END IF;
5308
5309 l_lpn_context := NULL;
5310
5311 -- All MMTTs loop
5312 FOR i IN 1..l_tempid_tab.COUNT
5313 LOOP
5314
5315 IF (l_debug = 1) THEN
5316 DEBUG('Calling Rollback_operation_plan with ...',l_proc_name,9);
5317 DEBUG('p_source_task_id => ' || l_tempid_tab(i),l_proc_name,9);
5318 DEBUG('p_activity_type_id => ' || G_OP_ACTIVITY_INBOUND,l_proc_name,9);
5319 END IF;
5320 l_progress := '300';
5321
5322 wms_atf_runtime_pub_apis.Rollback_operation_plan
5323 ( p_source_task_id => l_tempid_tab(i)
5324 ,p_activity_type_id => G_OP_ACTIVITY_INBOUND
5325 ,x_return_status => x_return_status
5326 ,x_msg_data => x_msg_data
5327 ,x_msg_count => x_msg_count
5328 ,x_error_code => l_error_code
5329 );
5330 l_progress := '310';
5331
5332 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
5333 IF (l_debug = 1) THEN
5334 DEBUG(l_error_code || ' Error in Rollback_operation_plan ' ,l_proc_name,1);
5335 END IF;
5336 l_progress := '320';
5337 x_return_status := fnd_api.g_ret_sts_error;
5338 /* Don't raise error in case of failure, instead set the ret status as error
5339 and proceed with the next record */
5340 --RAISE fnd_api.g_exc_error;
5341 END IF;
5342
5343 --Bug 5075410: If the cleanup is called
5344 --for a single step drop for an inventory lpn and there is
5345 --no operation plan associated with the lpn then, we should
5346 --delete the task and close the MOL.
5347
5348 IF (l_debug = 1) THEN
5349 debug('Inside the begin, before selection from mmtt',l_proc_name,1);
5350 END IF;
5351
5352 BEGIN
5353 SELECT mmtt.operation_plan_id
5354 , mmtt.transaction_uom
5355 , mmtt.transaction_quantity
5356 , mmtt.move_order_line_id
5357 , mmtt.inventory_item_id
5358 , mtrl.uom_code
5359 , mtrl.wms_process_flag
5360 INTO l_op_plan_id
5361 , l_mmtt_uom
5362 , l_mmtt_qty
5363 , l_mol_id
5364 , l_mmtt_item_id
5365 , l_mol_uom
5366 , l_wms_process_flag
5367 FROM mtl_material_transactions_temp mmtt
5368 , mtl_txn_request_lines mtrl
5369 WHERE mmtt.transaction_temp_id = l_tempid_tab(i)
5370 AND mmtt.move_order_line_id = mtrl.line_id;
5371 EXCEPTION
5372 WHEN OTHERS THEN
5373 IF (l_debug = 1) THEN
5374 debug('Error querying op_plan_id of MMTT. SQLERRM:'||Sqlerrm,l_proc_name,1);
5375 END IF;
5376 RAISE fnd_api.g_exc_error;
5377 END;
5378
5379 IF (l_lpn_context IS NULL) THEN
5380 BEGIN
5381 SELECT lpn_context
5382 INTO l_lpn_context
5383 FROM wms_license_plate_numbers
5384 WHERE lpn_id = p_lpn_id;
5385 EXCEPTION
5386 WHEN OTHERS THEN
5387 IF (l_debug = 1) THEN
5388 debug('Error querying lpn_context of WLPN. SQLERRM:'||Sqlerrm,l_proc_name,1);
5389 END IF;
5390 RAISE fnd_api.g_exc_error;
5391 END;
5392 END IF;
5393
5394 l_mmtt_qty_mol_uom := inv_convert.inv_um_convert
5395 (item_id => l_mmtt_item_id
5396 ,precision => NULL
5397 ,from_quantity => l_mmtt_qty
5398 ,from_unit => l_mmtt_uom
5399 ,to_unit => l_mol_uom
5400 ,from_name => NULL
5401 ,to_name => NULL
5402 );
5403
5404 IF (l_debug = 1) THEN
5405 debug('l_op_plan_id:'||l_op_plan_id||
5406 ' l_lpn_context:'||l_lpn_context||
5407 ' l_mmtt_uom:'||l_mmtt_uom||
5408 ' l_mmtt_qty:'||l_mmtt_qty||
5409 ' l_mol_id:'||l_mol_id||
5410 ' l_mol_uom:'||l_mol_uom||
5411 ' l_mmtt_item_id:'||l_mmtt_item_id||
5412 ' l_mmtt_qty_mol_uom:'||l_mmtt_qty_mol_uom||
5413 ' l_wms_process_flag:'||l_wms_process_flag
5414 ,l_proc_name,1);
5415 END IF;
5416
5417 IF (l_lpn_context IN (g_lpn_context_inv,g_lpn_context_wip)) THEN
5418 --Delete WDT
5419 BEGIN
5420 DELETE FROM wms_dispatched_tasks
5421 WHERE transaction_temp_id = l_tempid_tab(i);
5422 EXCEPTION
5423 WHEN OTHERS THEN
5424 IF (l_debug = 1) THEN
5425 debug('Error deleting WDT. SQLCODE:'||SQLCODE||' SQLERRM:'||SQLERRM,l_proc_name,1);
5426 END IF;
5427 END;
5428
5429 IF (l_debug = 1) THEN
5430 debug('# of WDT deleted:'||SQL%rowcount,l_proc_name,1);
5431 END IF;
5432 END IF;
5433
5434 IF (l_op_plan_id IS NULL AND l_lpn_context = g_lpn_context_inv) THEN
5435 IF (l_debug = 1) THEN
5436 debug('DELETE MMTT/MTLT and close/reduce MOL for:'||l_tempid_tab(i),l_proc_name,1);
5437 END IF;
5438
5439 BEGIN
5440 --update MOL
5441 UPDATE mtl_txn_request_lines mol
5442 SET quantity = quantity - l_mmtt_qty_mol_uom
5443 , quantity_detailed = quantity_detailed - l_mmtt_qty_mol_uom
5444 , line_status = Decode(quantity-Nvl(quantity_delivered,0)-l_mmtt_qty_mol_uom
5445 ,0
5446 ,inv_globals.g_to_status_closed
5447 ,line_status)
5448 WHERE line_id = l_mol_id;
5449 EXCEPTION
5450 WHEN OTHERS THEN
5451 IF (l_debug = 1) THEN
5452 debug('Error updating MOL. SQLCODE:'||SQLCODE||' SQLERRM:'||SQLERRM,l_proc_name,1);
5453 END IF;
5454 END;
5455
5456 IF (l_debug = 1) THEN
5457 debug('# of MOL updated/closed:'||SQL%rowcount,l_proc_name,1);
5458 END IF;
5459
5460 BEGIN
5461 --delete MTLT
5462 DELETE FROM mtl_transaction_lots_temp
5463 WHERE transaction_temp_id = l_tempid_tab(i);
5464 EXCEPTION
5465 WHEN OTHERS THEN
5466 IF (l_debug = 1) THEN
5467 debug('Error deleting MTLT. SQLCODE:'||SQLCODE||' SQLERRM:'||SQLERRM,l_proc_name,1);
5468 END IF;
5469 END;
5470
5471 IF (l_debug = 1) THEN
5472 debug('# of MTLT closed:'||SQL%rowcount,l_proc_name,1);
5473 END IF;
5474
5475 BEGIN
5476 --delete MMTT
5477 DELETE FROM mtl_material_transactions_temp
5478 WHERE transaction_temp_id = l_tempid_tab(i);
5479 EXCEPTION
5480 WHEN OTHERS THEN
5481 IF (l_debug = 1) THEN
5482 debug('Error deleting MMTT. SQLCODE:'||SQLCODE||' SQLERRM:'||SQLERRM,l_proc_name,1);
5483 END IF;
5484 END;
5485
5486 IF (l_debug = 1) THEN
5487 debug('# of MMTT closed:'||SQL%rowcount,l_proc_name,1);
5488 END IF;
5489 END IF;--END IF l_op_plan_id IS NULL AND l_lpn_context = g_lpn_context_inv) THEN
5490
5491 IF (l_wms_process_flag = 2) THEN
5492 BEGIN
5493 UPDATE mtl_txn_request_lines
5494 SET wms_process_flag = 1
5495 WHERE line_id = l_mol_id;
5496 EXCEPTION
5497 WHEN OTHERS THEN
5498 IF (l_debug = 1) THEN
5499 debug('No MOL updated. SQLERRM:'||Sqlerrm,l_proc_name,1);
5500 END IF;
5501 END;
5502
5503 IF (l_debug = 1) THEN
5504 debug('# of MOL with process_flag = 2 updated:'||SQL%rowcount,l_proc_name,1);
5505 END IF;
5506 END IF;--END IF (l_wms_process_flag = 2) THEN
5507 --END BUG 5075410
5508 END LOOP; -- All MMTTs loop
5509
5510 ELSIF ( p_call_type = G_CT_NORMAL_LOAD OR
5511 p_call_type = G_CT_NORMAL_DROP OR
5512 p_call_type = G_CT_INSPECT_TM_FAILED OR
5513 p_call_type = G_CT_INSPECT_B4_TM) THEN
5514 -- Normal Load/Drop or Inspect scenario hence call Cleanup_Operation_Instance
5515
5516 -- BUG 3288374
5517 IF (p_call_type = g_ct_inspect_b4_tm) THEN
5518 ROLLBACK;
5519 END IF;
5520
5521 -- All MMTTs loop
5522 FOR i IN 1..l_tempid_tab.COUNT
5523 LOOP
5524
5525 -- BUG 3288374
5526 -- If call type is G_CT_INSPECT_B4_TM, then we have to roll back
5527 -- AND then delete the dispatched task. Otherwise, we can just
5528 -- call complete_operation_instance
5529 IF (p_call_type = g_ct_inspect_b4_tm) THEN
5530 IF (l_debug = 1) THEN
5531 DEBUG('Calling DELETE_DISPATCHED_TASK ...',l_proc_name,9);
5532 DEBUG('p_source_task_id => ' || l_tempid_tab(i),l_proc_name,9);
5533 DEBUG('p_wms_task_type =====> ' || WMS_GLOBALS.G_WMS_TASK_TYPE_PUTAWAY,l_proc_name,9);
5534 END IF;
5535 l_progress := '305';
5536
5537 WMS_OP_RUNTIME_PVT_APIS.delete_dispatched_task
5538 ( p_source_task_id => l_tempid_tab(i)
5539 ,p_wms_task_type => WMS_GLOBALS.G_WMS_TASK_TYPE_INSPECT
5540 ,x_return_status => x_return_status
5541 ,x_msg_count => x_msg_count
5542 ,x_msg_data => x_msg_data
5543 );
5544 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
5545 IF (l_debug = 1) THEN
5546 DEBUG('Error in Delete_dispatched_tasks ' ,l_proc_name,1);
5547 END IF;
5548 l_progress := '306';
5549 x_return_status := fnd_api.g_ret_sts_error;
5550 END IF;
5551
5552 ELSE --IF (p_call_type = g_ct_inspect_b4_tm)
5553 IF (l_debug = 1) THEN
5554 DEBUG('Calling Cleanup_Operation_Instance with ...',l_proc_name,9);
5555 DEBUG('p_source_task_id => ' || l_tempid_tab(i),l_proc_name,9);
5556 DEBUG('p_activity_type_id => ' || G_OP_ACTIVITY_INBOUND,l_proc_name,9);
5557 END IF;
5558 l_progress := '310';
5559
5560 wms_atf_runtime_pub_apis.Cleanup_Operation_Instance
5561 ( p_source_task_id => l_tempid_tab(i)
5562 ,p_activity_type_id => G_OP_ACTIVITY_INBOUND
5563 ,x_return_status => x_return_status
5564 ,x_msg_data => x_msg_data
5565 ,x_msg_count => x_msg_count
5566 ,x_error_code => l_error_code
5567 );
5568 l_progress := '320';
5569
5570 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
5571 IF (l_debug = 1) THEN
5572 DEBUG(l_error_code || ' Error in Cleanup_Operation_Instance ' ,l_proc_name,1);
5573 END IF;
5574 l_progress := '330';
5575 x_return_status := fnd_api.g_ret_sts_error;
5576 /* Don't raise error in case of failure, instead set the ret status as error
5577 and proceed with the next record */
5578 --RAISE fnd_api.g_exc_error;
5579 END IF;
5580 END IF;--IF (p_call_type = g_ct_inspect_b4_tm) THEN
5581
5582 --BUG 5075410
5583 BEGIN
5584 UPDATE mtl_txn_request_lines
5585 SET wms_process_flag = 1
5586 WHERE line_id IN (SELECT move_order_line_id
5587 FROM mtl_material_transactions_temp
5588 WHERE transaction_temp_id = l_tempid_tab(i))
5589 AND wms_process_flag = 2;
5590 EXCEPTION
5591 WHEN OTHERS THEN
5592 IF (l_debug = 1) THEN
5593 debug('No MOL updated. SQLERRM:'||Sqlerrm,l_proc_name,1);
5594 END IF;
5595 END;
5596
5597 IF (l_debug = 1) THEN
5598 debug('# of MOL with process_flag = 2 updated:'||SQL%rowcount,l_proc_name,1);
5599 END IF;
5600 --END BUG 5075410
5601 END LOOP; -- All MMTTs loop
5602
5603 ELSE
5604 -- Invalid inputs passed hence error out
5605 l_progress := '340';
5606 RAISE fnd_api.g_exc_error;
5607 END IF;
5608
5609
5610 IF c_mol_mmtt_cursor%ISOPEN THEN
5611 l_progress := '970';
5612 CLOSE c_mol_mmtt_cursor;
5613 END IF;
5614
5615 IF c_tmp_mmtt_cursor%ISOPEN THEN
5616 l_progress := '980';
5617 CLOSE c_tmp_mmtt_cursor;
5618 END IF;
5619
5620 IF c_all_mmtt_cursor%isopen THEN
5621 CLOSE c_all_mmtt_cursor;
5622 END IF;
5623
5624 l_progress := '985';
5625
5626
5627 l_progress := '990';
5628
5629 -- Also need to clean up the TM variables. This is needed because
5630 -- in an online transactions, the variables will not be reset
5631 inv_rcv_common_apis.rcv_clear_global;
5632
5633 EXCEPTION
5634 WHEN fnd_api.g_exc_error THEN
5635 x_return_status := fnd_api.g_ret_sts_error;
5636 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
5637 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
5638 DEBUG(SQLERRM,l_proc_name,1);
5639
5640 IF c_mol_mmtt_cursor%ISOPEN THEN
5641 CLOSE c_mol_mmtt_cursor;
5642 END IF;
5643
5644 IF c_tmp_mmtt_cursor%ISOPEN THEN
5645 CLOSE c_tmp_mmtt_cursor;
5646 END IF;
5647
5648 IF c_all_mmtt_cursor%isopen THEN
5649 CLOSE c_all_mmtt_cursor;
5650 END IF;
5651
5652 WHEN fnd_api.g_exc_unexpected_error THEN
5653 x_return_status := fnd_api.g_ret_sts_unexp_error;
5654 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
5655
5656 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
5657 DEBUG(SQLERRM,l_proc_name,1);
5658
5659 IF c_mol_mmtt_cursor%ISOPEN THEN
5660 CLOSE c_mol_mmtt_cursor;
5661 END IF;
5662
5663 IF c_tmp_mmtt_cursor%ISOPEN THEN
5664 CLOSE c_tmp_mmtt_cursor;
5665 END IF;
5666
5667 IF c_all_mmtt_cursor%isopen THEN
5668 CLOSE c_all_mmtt_cursor;
5669 END IF;
5670 WHEN OTHERS THEN
5671 x_return_status := fnd_api.g_ret_sts_unexp_error;
5672 fnd_msg_pub.count_and_get(p_encoded => fnd_api.g_false, p_count => x_msg_count, p_data => x_msg_data);
5673 DEBUG(' Exception occured at l_progress = ' || l_progress || ' during ' || to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
5674 DEBUG(SQLERRM,l_proc_name,1);
5675
5676 IF c_mol_mmtt_cursor%ISOPEN THEN
5677 CLOSE c_mol_mmtt_cursor;
5678 END IF;
5679
5680 IF c_tmp_mmtt_cursor%ISOPEN THEN
5681 CLOSE c_tmp_mmtt_cursor;
5682 END IF;
5683
5684 IF c_all_mmtt_cursor%isopen THEN
5685 CLOSE c_all_mmtt_cursor;
5686 END IF;
5687 END Cleanup_ATF;
5688
5689
5690 /**
5691 * Nested LPN changes, This procedure explodes the given LPN
5692 * and for each LPN checks the validity of the given LPN and returns
5693 * @param p_org_id Current Organization
5694 * @param p_lpn_id From LPN ID
5695 * @param p_mode
5696 Purpose of the parameter - This method can be called
5697 from both UI as well as grouping logic. If this method
5698 is called from grouping logic, check only for the given LPN
5699 and not for the child LPNs.
5700 0 - Check for the given LPN iteself and not for the child LPNs
5701 1 - Check for the given LPN as well as it child LPNs (All
5702 putaway other than MANUAL LOAD.
5703 2 - Check for the given LPN as well as it child LPNs (for
5704 the MANUAL DROP case)
5705 * @param x_ret returns the following values
5706 * 0 - Success
5707 * 1 - Entire LPN needs Inspection.
5708 * 2 - Entire LPN is Invalid
5709 * 3 - Entire LPN is Invalid and cannot be putawayed.
5710 * 4 - Some child LPNs are invalid and cannot be putawayed.
5711 * 5 - Some child LPNs need inspection.
5712 * 6 - There is no contents in LPN or an inner LPN inside the LPN
5713 * 7 - LPN invalid because you cannot load the LPN due to sub
5714 * transfer restrictions specified in the material status form
5715 * @param x_loaded_stauts
5716 * 0 - not loaded
5717 * 1 - loaded
5718 * @param x_return_status
5719 * @param x_msg_count
5720 * @param x_context
5721 * @param p_user_id
5722 **/
5723
5724 PROCEDURE Check_LPN_Validity_Wrapper(
5725 p_org_id IN NUMBER
5726 , p_lpn_id IN NUMBER
5727 , p_user_id IN NUMBER
5728 , p_mode IN NUMBER
5729 , x_ret OUT NOCOPY NUMBER
5730 , x_lpn_context OUT NOCOPY NUMBER
5731 , x_loaded_status OUT NOCOPY VARCHAR2
5732 , x_return_status OUT NOCOPY VARCHAR2
5733 , x_msg_count OUT NOCOPY NUMBER
5734 , x_msg_data OUT NOCOPY VARCHAR2
5735 ) IS
5736 l_progress NUMBER;
5737 l_lpn_id NUMBER;
5738 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
5739 l_content_lpn VARCHAR2(1) := 'N';
5740 l_x_ret NUMBER :=0;
5741
5742 l_x_msg_count NUMBER;
5743 l_x_return_status VARCHAR2(2);
5744 l_x_msg_data VARCHAR2(2000);
5745 l_x_context NUMBER;
5746 l_is_nested_lpn VARCHAR2(1) := 'N';
5747 l_lpn_has_contents VARCHAR2(1) := 'N';
5748 l_lpn_sub VARCHAR2(10);
5749 l_lpn_loc NUMBER;
5750 l_drop_active VARCHAR(1) := 'N';
5751 l_userid NUMBER;
5752 l_username VARCHAR2(100);
5753
5754 -- Flags to identify the LPN validity
5755 l_entire_lpn_empty BOOLEAN := TRUE;
5756
5757 l_child_lpn_state VARCHAR2(1) := NULL; -- 'V' Valid, 'I' Inspect 'U' INVALID
5758 l_parent_lpn_state VARCHAR2(1) := NULL; -- 'V' Valid, 'I' Inspect 'U' INVALID.
5759
5760 CURSOR lpn_cursor IS
5761 SELECT lpn_id
5762 FROM wms_license_plate_numbers
5763 WHERE lpn_id <> p_lpn_id
5764 START WITH lpn_id = p_lpn_id
5765 CONNECT BY parent_lpn_id = PRIOR lpn_id;
5766 BEGIN
5767
5768 -- Intialize out variables.
5769 l_progress := 10;
5770 l_content_lpn := 'N';
5771 x_return_status := fnd_api.g_ret_sts_success;
5772 x_loaded_status := 'N';
5773 x_ret := 0;
5774
5775 IF (l_debug = 1) THEN
5776 debug('Patchset J code - Chcek_LPN_Validity_Wrapper');
5777 debug('p_org_id==> '|| p_org_id);
5778 debug('p_lpn_id==> '|| p_lpn_id);
5779 END IF;
5780
5781 -- Get LPN Context
5782 SELECT lpn_context,subinventory_code,locator_id
5783 INTO x_lpn_context,l_lpn_sub,l_lpn_loc
5784 FROM wms_license_plate_numbers
5785 WHERE lpn_id = p_lpn_id;
5786
5787 --BUG 3473899: p_mode = 2 => it is coming from MANUAL_LOAD
5788 --check the material status, and see if a sub transfer is allowed
5789 --in the source LPN sub/loc. If it is not, that you cannot load the
5790 --LPN
5791 IF (p_mode = 2 AND x_lpn_context = 1) THEN
5792 IF (inv_material_status_grp.is_status_applicable('TRUE',
5793 NULL,
5794 2,--subtransfer
5795 NULL,
5796 NULL,
5797 p_org_id,
5798 NULL,
5799 l_lpn_sub,
5800 l_lpn_loc,
5801 NULL,
5802 NULL,
5803 'Z') <> 'Y' OR
5804 inv_material_status_grp.is_status_applicable('TRUE',
5805 NULL,
5806 2,--Sub Transfer
5807 NULL,
5808 NULL,
5809 p_org_id,
5810 NULL,
5811 l_lpn_sub,
5812 l_lpn_loc,
5813 NULL,
5814 NULL,
5815 'L') <> 'Y') THEN
5816 x_ret := 7;
5817 RETURN ;
5818 END IF;
5819 END IF;
5820
5821 IF (x_lpn_context = 3) THEN
5822 --BUG 3625990: For receiving, instead of checking if the LPN is
5823 --locked or not, check if it has any WOOI that has type 'DROP'
5824 --and status 'ACTIVE'. This is because in WMSTKPTB.CHECK_LPN_VALIDITY,
5825 --we no longer lock the LPN if it is a Receiving LPN
5826 l_drop_active := 'N';
5827 BEGIN
5828 SELECT DISTINCT 'Y'
5829 , wooi.last_updated_by
5830 INTO l_drop_active
5831 , l_userid
5832 FROM mtl_txn_request_lines mtrl,
5833 mtl_material_transactions_temp mmtt,
5834 wms_op_operation_instances wooi ,
5835 (SELECT wlpn.lpn_id /*5723418*/
5836 FROM wms_license_plate_numbers wlpn
5837 START WITH wlpn.lpn_id = p_lpn_id
5838 CONNECT BY PRIOR wlpn.lpn_id = wlpn.parent_lpn_id) wlpn
5839 WHERE mtrl.lpn_id = wlpn.lpn_id
5840 AND mmtt.move_order_line_id = mtrl.line_id
5841 AND wooi.source_task_id = mmtt.transaction_temp_id
5842 AND wooi.operation_status = 2
5843 AND wooi.operation_type_id = 2
5844 AND wooi.last_updated_by <> p_user_id;
5845 EXCEPTION
5846 WHEN no_data_found THEN
5847 IF (l_debug = 1) THEN
5848 debug('No Operation Plan with status Drop Active');
5849 END IF;
5850 l_drop_active := 'N';
5851 WHEN too_many_rows THEN
5852 IF (l_debug = 1) THEN
5853 debug('More than 1 Operation Plan with status Drop Active');
5854 END IF;
5855 l_drop_active := 'Y';
5856 l_username := NULL;
5857 l_userid := NULL;
5858 END;
5859
5860 IF (l_debug = 1) THEN
5861 debug(' Drop Active by another user? '||l_drop_active);
5862 END IF;
5863
5864 IF (l_drop_active = 'Y') THEN
5865 IF (l_userid IS NOT NULL) THEN
5866 BEGIN
5867 SELECT user_name
5868 INTO l_username
5869 FROM fnd_user
5870 WHERE user_id = l_userid;
5871 EXCEPTION
5872 WHEN OTHERS THEN
5873 l_username := NULL;
5874 END;
5875
5876 IF (l_username IS NOT NULL) THEN
5877 fnd_message.set_name('WMS','WMS_PUTAWAY_LPN_LOCKED');
5878 fnd_message.set_token('USER',l_username);
5879 fnd_msg_pub.ADD;
5880 fnd_message.set_name('WMS','WMS_CONT_INVALID_LPN');
5881 fnd_msg_pub.ADD;
5882 END IF;
5883
5884 END IF;
5885 x_ret := 3; --return error
5886 x_return_status := fnd_api.g_ret_sts_success;
5887 RETURN;
5888 END IF;--END IF (l_drop_active = 'Y') THEN
5889 END IF;--END IF (x_lpn_context = 3) THEN
5890
5891 -- Check if the given lpn has contents.
5892
5893 BEGIN
5894 SELECT 'Y','Y'
5895 INTO l_content_lpn,l_lpn_has_contents
5896 FROM wms_lpn_contents
5897 WHERE parent_lpn_id = p_lpn_id
5898 AND ROWNUM<2;
5899 EXCEPTION
5900 WHEN no_data_found THEN
5901 l_content_lpn := 'N';
5902 END;
5903
5904 IF l_content_lpn='Y' THEN
5905 wms_task_dispatch_put_away.check_lpn_validity
5906 (p_org_id=> p_org_id
5907 , p_lpn_id=> p_lpn_id
5908 , x_ret=> l_x_ret
5909 , x_return_status=> l_x_return_status
5910 , x_msg_count=> l_x_msg_count
5911 , x_msg_data=> l_x_msg_data
5912 , x_context=> l_x_context
5913 , p_user_id=> p_user_id
5914 );
5915
5916 -- Check if the lPN is alredy loaded
5917 BEGIN
5918 SELECT 'Y' INTO x_loaded_status FROM dual where exists
5919 (SELECT 1 from
5920 wms_dispatched_tasks W,
5921 mtl_material_transactions_temp t,
5922 mtl_txn_request_lines M
5923 WHERE m.lpn_id = p_lpn_id
5924 AND m.organization_id = p_org_id
5925 AND m.line_status <> 5
5926 AND m.quantity-Nvl(m.quantity_delivered,0)>0
5927 AND t.move_order_line_id = m.line_id
5928 AND t.organization_id = p_org_id
5929 AND w.organization_id = p_org_id
5930 AND t.transaction_temp_id = w.transaction_temp_id
5931 AND w.status = 4);
5932 EXCEPTION
5933 WHEN NO_DATA_FOUND THEN
5934 x_loaded_status := 'N';
5935 END;
5936
5937 --bug 5590439
5938 -- Bug 5768339 ( Regression of 5590439)
5939 begin
5940 if (x_lpn_context =1 and x_loaded_status = 'N' ) then
5941 -- SELECT 'Y' INTO x_loaded_status FROM dual where exists
5942 SELECT 'Z' INTO x_loaded_status FROM dual where exists -- End of changes for the bug 5768339.
5943 (SELECT 1 FROM mtl_material_transactions_temp mmtt, wms_dispatched_tasks wdt
5944 WHERE mmtt.transaction_temp_id = wdt.transaction_temp_id
5945 AND mmtt.organization_id = wdt.organization_id
5946 AND wdt.status = 4
5947 AND wdt.organization_id = p_org_id
5948 AND (
5949 ((mmtt.lpn_id = p_lpn_id) AND (mmtt.transfer_lpn_id IS NOT NULL))
5950 OR
5951 ((mmtt.content_lpn_id = p_lpn_id) AND (mmtt.transfer_lpn_id IS NOT NULL))
5952 ));
5953 end if;
5954 Exception
5955 when no_data_found then
5956 x_loaded_status := 'N';
5957 end;
5958 --bug 5590439 end
5959
5960 l_entire_lpn_empty := FALSE;
5961 END IF;--IF l_content_lpn='Y' AND l_drop_active = 'N' THEN
5962
5963 IF(l_debug =1) THEN
5964 debug(' Loaded status of the LPN is '|| x_loaded_status );
5965 END IF;
5966
5967
5968 -- If return value is error then parent lpn state 'U' - INVALID
5969 -- else if return value = 0 then parent lpn state 'V' - VALID;
5970 -- else if return value = 1 then parent lpn state 'I' - INSPECT;
5971 -- else paretn lpn statue - 'U' - INVALID.
5972 IF (l_x_return_status = fnd_api.g_ret_sts_error OR l_x_return_status = fnd_api.g_ret_sts_unexp_error ) THEN
5973 l_parent_lpn_state := 'U'; -- invalid
5974 ELSIF (l_x_ret =0) THEN
5975 l_parent_lpn_state := 'V'; -- valid.
5976 ELSIF (l_x_ret =1) THEN
5977 l_parent_lpn_state := 'I'; -- Inspect required
5978 ELSIF (l_x_ret =4) THEN
5979 x_ret := 5;
5980 RETURN;
5981 ELSE
5982 l_parent_lpn_state := 'U'; -- Invalid
5983 END IF; -- for return state.
5984
5985 IF(l_debug= 1) THEN
5986 debug('l_x_return_status ' || l_x_return_status);
5987 debug('l_x_ret ' || l_x_ret);
5988 END IF;
5989
5990
5991 -- If mode value is '0' then this method is called from grouping logic,
5992 -- In this case check for the given LPN itself and return.
5993
5994 IF p_mode = 0 THEN
5995 -- In case of failures l_x_ret might be '0' set it to proper value;
5996 IF (l_x_return_status = fnd_api.g_ret_sts_error OR
5997 l_x_return_status = fnd_api.g_ret_sts_unexp_error ) THEN
5998 l_x_ret := 3;
5999 END IF;
6000 x_ret := l_x_ret;
6001 RETURN;
6002 END IF;
6003
6004 -- Check the validity of child LPNs
6005 IF (l_debug = 1) THEN
6006 debug('Given LPN is validity checked, Now check if the child LPNs are valid');
6007 END IF;
6008
6009 OPEN lpn_cursor;
6010
6011 LOOP
6012 FETCH lpn_cursor INTO l_lpn_id;
6013 EXIT WHEN lpn_cursor%NOTFOUND;
6014 l_content_lpn := 'N';
6015
6016 IF(l_debug = 1) THEN
6017 debug('Checking validity of Child Lpn ' || l_lpn_id);
6018 END IF;
6019
6020 -- Check lpn has contents
6021 BEGIN
6022 SELECT 'Y','Y'
6023 INTO l_content_lpn,l_lpn_has_contents
6024 FROM wms_lpn_contents
6025 WHERE parent_lpn_id = l_lpn_id
6026 AND ROWNUM<2;
6027 EXCEPTION
6028 WHEN no_data_found THEN
6029 l_content_lpn := 'N';
6030 END;
6031
6032 IF l_debug = 1 THEN
6033 IF (l_content_lpn = 'N') THEN debug('lpn ' || l_lpn_id || 'has no contents'); END IF;
6034 IF (l_content_lpn = 'Y') THEN debug('lpn ' || l_lpn_id || 'has contents'); END IF;
6035 END IF;
6036
6037 IF l_content_lpn ='Y' THEN
6038 --BUG 5130266 - No need to check for drop active here, because
6039 --the CONNECT BY PRIOR query on the outermost LPN would have
6040 --checked
6041 wms_task_dispatch_put_away.check_lpn_validity
6042 (p_org_id=> p_org_id
6043 , p_lpn_id=> l_lpn_id
6044 , x_ret=> l_x_ret
6045 , x_return_status=> l_x_return_status
6046 , x_msg_count=> l_x_msg_count
6047 , x_msg_data=> l_x_msg_data
6048 , x_context=> l_x_context
6049 , p_user_id=> p_user_id
6050 );
6051
6052 IF(l_debug= 1) THEN
6053 debug('After checking validity for lpn '|| l_lpn_id);
6054 debug('Return status ' || l_x_return_status);
6055 debug('return value for the chld LPN ' || l_x_ret);
6056 END IF;
6057
6058 -- If return value is error then child lpn state 'U' - INVALID
6059 -- else if return value = 0 then child lpn state 'V' - VALID;
6060 -- else if return value = 1 then child lpn state 'I' - INSPECT;
6061 -- else paretn lpn statue - 'U' - INVALID.
6062 IF (l_x_return_status = fnd_api.g_ret_sts_error OR l_x_return_status = fnd_api.g_ret_sts_unexp_error ) THEN
6063 l_child_lpn_state := 'U'; -- invalid
6064 ELSIF (l_x_ret =0) THEN
6065 l_child_lpn_state := 'V'; -- valid.
6066 ELSIF (l_x_ret =1) THEN
6067 l_child_lpn_state := 'I'; -- Inspect required
6068 ELSE
6069 l_child_lpn_state := 'U'; -- Invalid
6070 END IF; -- for return state.
6071
6072 -- logic used.
6073
6074 /*-------------------------------------------------------------------
6075 * Given lpn child LPN result
6076 *-------------------------------------------------------------------
6077 * INVALID VALID oh.. oh.. We have a problem
6078 * Break the loop, return 4
6079 * INSP REQ VALID Break the loop, return 4
6080 * INSP Req Invalid Break the loop, return 4
6081 * VALID INVALID Break the loop, return 4
6082 * INSP Req INSP Req Continue loop. return 1 if
6083 * entire lpn req inspection.
6084 * INVALID INVALID No problem continue looping,
6085 * Until you find valid lpn.
6086 * VAlID VALID No Problem continue looping
6087 Until you find Invalid lpn.
6088 ------------------------------------------------------------------*/
6089
6090 -- Conclusion: From above table if Given LPN and child LPN states
6091 -- are same continue/otherwise error out.
6092
6093
6094 IF (l_parent_lpn_state <> l_child_lpn_state) THEN
6095 x_ret := 4; RETURN;
6096 END IF;
6097
6098 /*--------------------------------------------------------------------
6099 * If one child LPN is loaded then the entire LPN is loaded.
6100 * To know whether a lpn is loaded or not, that lpn should have
6101 * some cotents inside it. An lpn with some contents here after
6102 * will be called as content lpn.
6103 *
6104 * To make sure loaded check will be called only for one contentlpn
6105 * and not every lpn, make use of the flag l_entire_lpn_empty.
6106 *
6107 * First time when the flow comes here l_entire_lpn_empty will be false,
6108 * and from second time it will be true because we are updating
6109 * l_entire_lpn_empty flag in the end. This way we can make sure
6110 * loaded check will be called only once.
6111 ------------------------------------------------------------------------*/
6112
6113 IF l_entire_lpn_empty THEN
6114 BEGIN
6115 SELECT 'Y' INTO x_loaded_status FROM dual where exists
6116 (select 1 from
6117 WMS_DISPATCHED_TASKS W, MTL_MATERIAL_TRANSACTIONS_TEMP T
6118 WHERE T.lpn_id = l_lpn_id
6119 AND t.organization_id = p_org_id
6120 AND w.organization_id = p_org_id
6121 AND T.transaction_temp_id = W.transaction_temp_id
6122 AND W.STATUS = 4 );
6123 EXCEPTION
6124 WHEN NO_DATA_FOUND THEN
6125 x_loaded_status := 'N';
6126 END;
6127 END IF;
6128 l_entire_lpn_empty := FALSE;
6129 END IF;
6130 END LOOP;
6131
6132 -- Compare with childs state only atleast one child is processed.
6133 -- If child lpn state is null, then no child is so far processed.
6134 IF (l_parent_lpn_state <> nvl(l_child_lpn_state,l_parent_lpn_state)) THEN
6135 x_ret := 4;
6136 END IF;
6137
6138 IF(l_parent_lpn_state = nvl(l_child_lpn_state,l_parent_lpn_state)) THEN
6139 IF l_parent_lpn_state = 'I' THEN
6140 x_ret:=1;
6141 ELSIF (l_parent_lpn_state = 'U') THEN
6142 x_ret := 3;
6143 ELSIF (l_parent_lpn_state = 'V') THEN
6144 x_ret :=0;
6145 END IF;
6146 END IF;
6147
6148 IF (l_lpn_has_contents = 'N') THEN
6149 x_ret := 6;
6150 END IF;
6151
6152 IF lpn_cursor%isopen THEN
6153 CLOSE lpn_cursor;
6154 END IF;
6155
6156 RETURN;
6157
6158
6159 EXCEPTION
6160 WHEN OTHERS THEN
6161 x_return_status := fnd_api.g_ret_sts_unexp_error;
6162 x_ret := 3;
6163 debug(SQLCODE, 1);
6164
6165 IF lpn_cursor%isopen THEN
6166 CLOSE lpn_cursor;
6167 END IF;
6168
6169 IF SQLCODE IS NOT NULL THEN
6170 l_progress := 100;
6171 inv_mobile_helper_functions.sql_error('validate_nested_lpns', l_progress, SQLCODE);
6172 END IF;
6173 END check_lpn_validity_wrapper;
6174
6175
6176
6177 /**
6178 * Nested LPN changes, This procedure Loads the given FromLPN into ToLPN
6179 * and calls suggestions_pub
6180 * @param p_org_id Current Organization
6181 * @param p_sub_code If tosub is receving then call transfer transaction
6182 If to sub is inventory sub then call Pack Unpack API.
6183 * @param p_from_lpn_id From LPN id
6184 * @param p_to_lpn_id Transfer LPN id
6185 * @param p_mode
6186 1 - Load entire LPN
6187 If the parent_lpn for the given from lpn is not null then unpack the lpn from its parent
6188 If the to_lpn is not null then pack the lpn into tolpn.
6189 2 - Transfer All contents
6190 3 - Transfer parial quantity.
6191
6192 * @param x_ret returns the following values
6193 * 0 - Success
6194 * 1 - failure.
6195 * @param x_return_status
6196 * @param x_msg_count
6197 * @param x_context
6198 * @param p_user_id
6199 **/
6200
6201 PROCEDURE suggestions_pub_wrapper(
6202 p_lpn_id IN NUMBER
6203 , p_org_id IN NUMBER
6204 , p_user_id IN NUMBER
6205 , p_eqp_ins IN VARCHAR2
6206 , p_status IN NUMBER := 3
6207 , p_check_for_crossdock IN VARCHAR2 := 'Y'
6208 , x_number_of_rows OUT NOCOPY NUMBER
6209 , x_return_status OUT NOCOPY VARCHAR2
6210 , x_msg_count OUT NOCOPY NUMBER
6211 , x_msg_data OUT NOCOPY VARCHAR2
6212 , x_crossdock OUT NOCOPY VARCHAR2
6213 ) IS
6214
6215 l_lpn_id NUMBER;
6216 l_number_of_rows NUMBER := 0;
6217 l_x_crossdock VARCHAR2(2) := 'Y';
6218 l_progress NUMBER := 10;
6219 l_is_content_lpn VARCHAR2(2) := 'N';
6220 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6221 l_error_messages VARCHAR2(1200);
6222 l_msg_count NUMBER;
6223 l_msg_data VARCHAR2(1200);
6224 CURSOR lpn_cursor IS
6225 SELECT lpn_id
6226 FROM wms_license_plate_numbers
6227 START WITH lpn_id = p_lpn_id
6228 CONNECT BY parent_lpn_id = PRIOR lpn_id;
6229 BEGIN
6230
6231 -- Intializat out variables.
6232 x_return_status := fnd_api.g_ret_sts_success;
6233
6234 -- Explode the LPN and for each child LPN call suggestions_pub_wrapper.
6235 IF (l_debug = 1) THEN
6236 debug('Patchset J code');
6237 debug(' p_org_id==> '|| p_org_id);
6238 debug(' p_lpn_id==> '|| p_lpn_id);
6239 debug(' p_user_id==> '|| p_user_id);
6240 END IF;
6241
6242 -- Initialize out variables
6243 x_return_status := fnd_api.g_ret_sts_success;
6244 x_crossdock:= 'N';
6245 x_number_of_rows := 0;
6246
6247 OPEN lpn_cursor;
6248 LOOP
6249 FETCH lpn_cursor INTO l_lpn_id;
6250 EXIT WHEN lpn_cursor%notfound;
6251 -- Check if the given LPN has contents.
6252 BEGIN
6253 SELECT 'Y' INTO l_is_content_lpn
6254 FROM wms_lpn_contents
6255 WHERE parent_lpn_id = l_lpn_id
6256 AND ROWNUM<2;
6257 EXCEPTION
6258 WHEN no_data_found THEN l_is_content_lpn := 'N';
6259 END;
6260
6261 -- Call suggestions pub for each of the LPN.
6262 IF (l_is_content_lpn = 'Y') THEN
6263
6264 wms_Task_Dispatch_put_away.suggestions_pub(
6265 p_lpn_id => l_lpn_id
6266 ,p_org_id => p_org_id
6267 ,p_user_id => p_user_id
6268 ,p_eqp_ins => p_eqp_ins
6269 ,x_number_of_rows => l_number_of_rows
6270 ,x_return_status => x_return_status
6271 ,x_msg_count => x_msg_count
6272 ,x_msg_data => x_msg_data
6273 ,x_crossdock => l_x_crossdock
6274 ,p_status => p_status
6275 ,p_check_for_crossdock => p_check_for_crossdock
6276 ,p_commit => 'N');
6277
6278
6279 IF (l_debug=1) THEN
6280 debug('ret status after suggestion pug for : ' ||l_lpn_id||' is '|| x_return_status);
6281 END IF;
6282
6283
6284 IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6285 -- IF x_msg_count = 0 THEN
6286 -- FND_MESSAGE.SET_NAME('WMS','WMS_LOG_EXCEPTION_FAIL');
6287 -- FND_MSG_PUB.ADD;
6288 -- END IF;
6289 RAISE FND_API.g_exc_unexpected_error;
6290
6291 ELSIF x_return_status = FND_API.G_RET_STS_ERROR THEN
6292 -- IF x_msg_count = 0 THEN
6293 -- FND_MESSAGE.SET_NAME('WMS','WMS_LOG_EXCEPTION_FAIL');
6294 -- FND_MSG_PUB.ADD;
6295 -- END IF;
6296 RAISE FND_API.G_EXC_ERROR;
6297 END IF;
6298
6299 IF l_x_crossdock = 'Y' THEN
6300 x_crossdock := 'Y';
6301 END IF;
6302 x_number_of_rows := l_number_of_rows+x_number_of_rows;
6303 END IF;
6304 END LOOP;
6305
6306 IF l_debug = 1 THEN
6307 debug('End of loop: Final ret status: ' || x_return_status || ' no of rows: ' || x_number_of_rows);
6308 END IF;
6309
6310
6311
6312 IF x_number_of_rows = 0 THEN
6313 fnd_msg_pub.count_and_get(p_count => l_msg_count, p_data =>
6314 l_msg_data);
6315 IF l_debug = 1 THEN
6316 debug('l_msg_count: ' || l_msg_count);
6317 debug('l_msg_data: ' || l_msg_data);
6318 END IF;
6319
6320 IF (l_msg_count IS NULL OR l_msg_count = 0) THEN
6321 -- use default message if there are no message on stack
6322 -- first reset message stack
6323 fnd_msg_pub.initialize();
6324 FND_MESSAGE.SET_NAME('WMS','WMS_ALLOCATE_FAIL');
6325 FND_MSG_PUB.ADD;
6326 ELSIF l_msg_count > 1 THEN
6327 FOR i IN 2 .. l_msg_count LOOP
6328 fnd_msg_pub.delete_msg(i);
6329 END LOOP;
6330 END IF;
6331 RAISE fnd_api.g_exc_error;
6332 END IF;
6333
6334 EXCEPTION
6335 WHEN OTHERS THEN
6336 x_return_status := fnd_api.g_ret_sts_unexp_error;
6337 debug(SQLCODE, 1);
6338
6339 IF lpn_cursor%isopen THEN
6340 CLOSE lpn_cursor;
6341 END IF;
6342
6343 -- Get rid of the folloiwng, as it appends a junk message to the
6344 -- error message stack
6345 -- IF SQLCODE IS NOT NULL AND l_no_lines <> 1 THEN
6346 -- l_progress := 100;
6347 -- inv_mobile_helper_functions.sql_error('suggestions_pub_wrapper', l_progress, SQLCODE);
6348 -- END IF;
6349 END suggestions_pub_wrapper;
6350
6351 /**
6352 * Nested LPN changes, This procedure packs the given from lpn into tolpn
6353 * and calls suggestions_pub
6354 * @param p_org_id Current Organization
6355 * @param p_sub_code If tosub is receving then call transfer transaction
6356 If to sub is inventory sub then call Pack Unpack API.
6357 * @param p_from_lpn_id From LPN id
6358 * @param p_to_lpn_id Transfer LPN id
6359 * @param p_mode
6360 1 - Pack from_lpn into to_lpn
6361 2 - unpack to_lpn from from_lpn
6362 for unpcaking lpn
6363 fromlpnid -> parentlpnid
6364 tolpnid -> child lPNID
6365 * @param x_ret returns the following values
6366 * 0 - Success
6367 * 1 - failure.
6368 **/
6369 PROCEDURE PackUnpack_lpn(
6370 p_from_lpn_id IN NUMBER
6371 , p_to_lpn_id IN NUMBER
6372 , p_org_id IN NUMBER
6373 , p_sub_code IN VARCHAR2
6374 , p_loc_id IN NUMBER
6375 , p_user_id IN NUMBER
6376 , p_project_id IN NUMBER DEFAULT NULL
6377 , p_task_id IN NUMBER DEFAULT NULL
6378 , p_trx_header_id IN NUMBER
6379 , p_mode IN NUMBER
6380 , p_batch_id IN NUMBER DEFAULT NULL
6381 , p_batch_seq IN NUMBER DEFAULT NULL
6382 , x_return_status OUT NOCOPY VARCHAR2
6383 , x_msg_count OUT NOCOPY NUMBER
6384 , x_msg_data OUT NOCOPY VARCHAR2
6385 ) IS
6386 l_progress NUMBER;
6387 l_txn_temp_id NUMBER;
6388 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6389 l_ret NUMBER;
6390
6391 BEGIN
6392 x_return_status := fnd_api.g_ret_sts_success;
6393 l_progress := 10;
6394
6395 IF(l_debug =1) THEN
6396 debug('In Patchset J code: ','PackUnpackLpn');
6397 END IF;
6398
6399
6400 -- Pack from lpn into to lpn
6401 IF p_mode = 1 THEN
6402 l_ret := inv_trx_util_pub.insert_line_trx(
6403 p_trx_hdr_id => p_trx_header_id
6404 , p_item_id => '0'
6405 , p_org_id => p_org_id
6406 , p_trx_action_id => inv_globals.g_action_containerpack
6407 , p_subinv_code => p_sub_code
6408 , p_locator_id => p_loc_id
6409 , p_trx_type_id => inv_globals.g_type_container_pack
6410 , p_trx_src_type_id => inv_globals.g_sourcetype_inventory
6411 , p_trx_qty => 1
6412 , p_pri_qty => 1
6413 , p_uom => 'Ea'
6414 , p_user_id => p_user_id
6415 , p_from_lpn_id => NULL
6416 , p_cnt_lpn_id => p_from_lpn_id
6417 , p_xfr_lpn_id => p_to_lpn_id
6418 , x_trx_tmp_id => l_txn_temp_id
6419 , x_proc_msg => x_msg_data
6420 , p_project_id => p_project_id
6421 , p_task_id => p_task_id);
6422 END IF;
6423
6424
6425 -- UnPack to lpn from from lpn
6426 IF p_mode = 2 THEN
6427 l_ret := inv_trx_util_pub.insert_line_trx(
6428 p_trx_hdr_id => p_trx_header_id
6429 , p_item_id => '-1'
6430 , p_org_id => p_org_id
6431 , p_trx_action_id => inv_globals.g_action_containerunpack
6432 , p_subinv_code => p_sub_code
6433 , p_locator_id => p_loc_id
6434 , p_trx_type_id => inv_globals.g_type_container_unpack
6435 , p_trx_src_type_id => inv_globals.g_sourcetype_inventory
6436 , p_trx_qty => 1
6437 , p_pri_qty => 1
6438 , p_uom => 'Ea'
6439 , p_user_id => p_user_id
6440 , p_from_lpn_id => p_from_lpn_id
6441 , p_cnt_lpn_id => p_to_lpn_id
6442 , p_xfr_lpn_id => NULL
6443 , x_trx_tmp_id => l_txn_temp_id
6444 , x_proc_msg => x_msg_data
6445 , p_project_id => p_project_id
6446 , p_task_id => p_task_id);
6447 END IF;
6448
6449 IF (l_txn_temp_id <=0 ) OR (l_ret<>0) THEN
6450 x_return_status := fnd_api.g_ret_sts_unexp_error;
6451 END IF;
6452
6453 -- Update batch id and seq id
6454 IF p_batch_id IS NOT NULL AND p_batch_seq IS NOT NULL THEN
6455 UPDATE mtl_material_transactions_temp
6456 SET transaction_header_id = p_trx_header_id
6457 , transaction_batch_id = p_batch_id
6458 , transaction_batch_seq = p_batch_seq
6459 WHERE transaction_temp_id = l_txn_temp_id;
6460 END IF; -- Update batch id
6461
6462 IF l_debug = 1 THEN
6463 debug('return status' || l_ret);
6464 debug('New transaction created with transaction temp id ' || l_txn_temp_id,'packunpack_lpn');
6465 END IF;
6466
6467 EXCEPTION
6468 WHEN OTHERS THEN
6469 x_return_status := fnd_api.g_ret_sts_unexp_error;
6470 debug(SQLCODE, 1);
6471
6472 IF SQLCODE IS NOT NULL THEN
6473 l_progress := 100;
6474 inv_mobile_helper_functions.sql_error('Pack Unpack Lpn', l_progress, SQLCODE);
6475 END IF;
6476 END;
6477
6478
6479 PROCEDURE load_lpn(
6480 p_org_id IN NUMBER
6481 , p_sub_code IN VARCHAR2
6482 , p_loc_id IN NUMBER
6483 , p_from_lpn_id IN NUMBER
6484 , p_to_lpn_id IN NUMBER
6485 , p_mode IN NUMBER
6486 , p_user_id IN NUMBER
6487 , p_eqp_ins IN VARCHAR2
6488 , p_project_id IN NUMBER DEFAULT NULL
6489 , p_task_id IN NUMBER DEFAULT NULL
6490 , p_check_for_crossdock IN VARCHAR2
6491 , x_return_status OUT NOCOPY VARCHAR2
6492 , x_msg_count OUT NOCOPY NUMBER
6493 , x_msg_data OUT NOCOPY VARCHAR2
6494 , x_crossdock OUT NOCOPY VARCHAR2
6495 ) IS
6496 l_progress NUMBER;
6497 l_lpn_context NUMBER;
6498 l_parent_lpn_id NUMBER;
6499 l_trx_header_id NUMBER;
6500 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
6501 l_x_num_of_rows NUMBER := 0;
6502 l_x_return_status VARCHAR2(2);
6503 l_x_msg_count NUMBER;
6504 l_x_msg_data VARCHAR2(2000);
6505 l_ret NUMBER;
6506 l_is_tm_call_needed BOOLEAN := FALSE;
6507 l_is_rcv_tm_call_needed BOOLEAN := FALSE;
6508 l_old_txn_mode_code VARCHAR2(10);
6509 l_group_id NUMBER;
6510 l_to_sub VARCHAR2(10);
6511 l_to_loc NUMBER;
6512 l_to_context NUMBER;
6513 l_sub_loc_changed VARCHAR2(1);
6514 l_txn_temp_id NUMBER;
6515 TYPE number_tb_tp IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
6516 l_mmtt_ids number_tb_tp;
6517 l_emp_id NUMBER;
6518 l_task_execute_rec wms_dispatched_tasks%ROWTYPE;
6519 l_error_code NUMBER;
6520
6521 l_consolidation_method_id NUMBER;
6522 l_drop_lpn_option NUMBER;
6523
6524 l_msg_count NUMBER;
6525 l_msg_data VARCHAR2(10000);
6526 l_discrepancy NUMBER;
6527 BEGIN
6528 l_progress := 10;
6529 x_return_status := fnd_api.g_ret_sts_success;
6530
6531 IF (l_debug = 1) THEN
6532 debug('Patchset J code - Load LPN');
6533 debug(' p_org_id=======> '|| p_org_id);
6534 debug(' p_from_lpn_id==> '|| p_from_lpn_id);
6535 debug(' p_to_lpn_id====> '|| p_to_lpn_id);
6536 debug(' p_user_id======> '|| p_user_id);
6537 debug(' p_sub_code=====> '|| p_sub_code);
6538 debug(' p_loc_id=======> '|| p_loc_id);
6539 END IF;
6540
6541 SELECT parent_lpn_id,lpn_context
6542 INTO l_parent_lpn_id,l_lpn_context
6543 FROM wms_license_plate_numbers
6544 WHERE lpn_id = p_from_lpn_id;
6545
6546 IF (p_to_lpn_id IS NOT NULL AND p_to_lpn_id <> 0) THEN
6547 l_progress := 20;
6548 BEGIN
6549 SELECT lpn_context,subinventory_code,locator_id
6550 INTO l_to_context,l_to_sub,l_to_loc
6551 FROM wms_license_plate_numbers
6552 WHERE lpn_id = p_to_lpn_id;
6553 EXCEPTION
6554 WHEN OTHERS THEN
6555 l_to_context := -1;
6556 l_to_sub := NULL;
6557 l_to_loc := NULL;
6558 END;
6559 l_progress := 30;
6560 END IF;
6561
6562 -- Set variable if sub/loc of toLPN is different from that of from LPN
6563 IF (Nvl(p_to_lpn_id,0) <> 0
6564 AND l_to_context IN (1,2,3) -- No need to call TM if DFBU LPN
6565 AND (Nvl(l_to_sub,'@@@') <> Nvl(p_sub_code,'@@@')
6566 OR Nvl(l_to_loc,-1) <> Nvl(p_loc_id,-1))) THEN
6567 l_sub_loc_changed := 'Y';
6568 ELSE
6569 l_sub_loc_changed := 'N';
6570 END IF;
6571
6572 IF (l_debug = 1) THEN
6573 debug('Sub/loc changed: ' || l_sub_loc_changed,9);
6574 debug('l_to_sub => ' || l_to_sub,9);
6575 debug('l_to_loc => ' || l_to_loc,9);
6576 END IF;
6577
6578 -- Get Transaction header id.
6579
6580 SELECT mtl_material_transactions_s.NEXTVAL
6581 INTO l_trx_header_id
6582 FROM dual;
6583
6584
6585 -- Pack Entire lpn witn LPN context Resides in inventory
6586 IF l_lpn_context = 1 AND p_mode = 1 THEN
6587
6588 IF l_parent_lpn_id IS NOT NULL THEN
6589
6590 IF(l_debug =1) THEN
6591 debug('Inventory LPN, Parent lpn is not null, Unpack '||p_from_lpn_id|| ' from ' ||l_parent_lpn_id);
6592 END IF;
6593
6594 PackUnpack_LPN(
6595 p_from_lpn_id => l_parent_lpn_id
6596 , p_to_lpn_id => p_from_lpn_id
6597 , p_org_id => p_org_id
6598 , p_sub_code => p_sub_code
6599 , p_loc_id => p_loc_id
6600 , p_user_id => p_user_id
6601 , p_project_id => p_project_id
6602 , p_task_id => p_task_id
6603 , p_trx_header_id => l_trx_header_id
6604 , p_mode => 2
6605 , p_batch_id => l_trx_header_id
6606 , p_batch_seq => 1
6607 , x_return_status => l_x_return_status
6608 , x_msg_count => l_x_msg_count
6609 , x_msg_data => l_x_msg_data);
6610
6611 l_is_tm_call_needed := TRUE;
6612 END IF;
6613
6614 IF (p_to_lpn_id IS NOT NULL) AND (p_to_lpn_id <> p_from_lpn_id) AND (p_to_lpn_id <> 0) THEN
6615
6616 IF (l_debug = 1) THEN
6617 debug('Inventory LPN, To lpn is not null, Pack '||p_from_lpn_id|| ' Into ' ||p_to_lpn_id);
6618 END IF;
6619
6620 IF (l_sub_loc_changed = 'Y') THEN
6621 l_ret := inv_trx_util_pub.insert_line_trx
6622 (
6623 p_trx_hdr_id => l_trx_header_id
6624 , p_item_id => '0'
6625 , p_org_id => p_org_id
6626 , p_trx_action_id => 2
6627 , p_subinv_code => p_sub_code
6628 , p_tosubinv_code => l_to_sub
6629 , p_locator_id => p_loc_id
6630 , p_tolocator_id => l_to_loc
6631 , p_trx_type_id => 2
6632 , p_trx_src_type_id => 13
6633 , p_trx_qty => 1
6634 , p_pri_qty => 1
6635 , p_uom => 'Ea'
6636 , p_user_id => p_user_id
6637 , p_from_lpn_id => NULL
6638 , p_cnt_lpn_id => p_from_lpn_id
6639 , p_xfr_lpn_id => NULL
6640 , x_trx_tmp_id => l_txn_temp_id
6641 , x_proc_msg => x_msg_data
6642 , p_project_id => p_project_id
6643 , p_task_id => p_task_id);
6644 IF (l_txn_temp_id <= 0 ) OR (l_ret<>0) THEN
6645 IF (l_debug = 1) THEN
6646 debug('Error inserting MMTT ID: ' ||
6647 l_txn_temp_id,9);
6648 END IF;
6649 RAISE fnd_api.g_exc_error;
6650 END IF;
6651
6652 BEGIN
6653 UPDATE mtl_material_transactions_temp
6654 SET transaction_header_id = l_trx_header_id
6655 , transaction_batch_id = l_trx_header_id
6656 , transaction_batch_seq = 2
6657 WHERE transaction_temp_id = l_txn_temp_id;
6658 EXCEPTION
6659 WHEN OTHERS THEN
6660 IF (l_debug = 1) THEN
6661 debug('Error updating MMTT with ID: ' ||
6662 l_txn_temp_id,9);
6663 END IF;
6664 RAISE fnd_api.g_exc_error;
6665 END;
6666
6667 packunpack_lpn
6668 (
6669 p_from_lpn_id => p_from_lpn_id
6670 , p_to_lpn_id => p_to_lpn_id
6671 , p_org_id => p_org_id
6672 , p_sub_code => l_to_sub
6673 , p_loc_id => l_to_loc
6674 , p_user_id => p_user_id
6675 , p_project_id => p_project_id
6676 , p_task_id => p_task_id
6677 , p_trx_header_id => l_trx_header_id
6678 , p_mode => 1 -- Pack
6679 , p_batch_id => l_trx_header_id
6680 , p_batch_seq => 3
6681 , x_return_status => l_x_return_status
6682 , x_msg_count => l_x_msg_count
6683 , x_msg_data => l_x_msg_data);
6684 ELSE -- If no sub/loc changed
6685 packunpack_lpn
6686 (
6687 p_from_lpn_id => p_from_lpn_id
6688 , p_to_lpn_id => p_to_lpn_id
6689 , p_org_id => p_org_id
6690 , p_sub_code => p_sub_code
6691 , p_loc_id => p_loc_id
6692 , p_user_id => p_user_id
6693 , p_project_id => p_project_id
6694 , p_task_id => p_task_id
6695 , p_trx_header_id => l_trx_header_id
6696 , p_mode => 1 -- Pack
6697 , p_batch_id => l_trx_header_id
6698 , p_batch_seq => 2
6699 , x_return_status => l_x_return_status
6700 , x_msg_count => l_x_msg_count
6701 , x_msg_data => l_x_msg_data);
6702 END IF;
6703 l_is_tm_call_needed := TRUE;
6704 END IF;
6705
6706 END IF; ---IF l_lpn_context = 1 AND p_mode = 1 THEN
6707
6708 IF(l_debug = 1) THEN
6709 debug('After calling pack unpack ');
6710 END IF;
6711
6712 -- Call pup if 1) it is WIP LPN, or if 2) it is RCV LPN and
6713 -- i) it is not doing any nesting
6714 -- ii) or if it is, the sub and loc is the same as the from LPN
6715 IF p_mode = 1
6716 AND ((l_lpn_context = 3 AND l_sub_loc_changed = 'N')
6717 OR l_lpn_context = 2) THEN
6718
6719 -- Unpack the given LPN from its parent lpn
6720 IF l_parent_lpn_id IS NOT NULL THEN
6721 IF(l_debug = 1) THEN
6722 debug('Receiving LPN, Parent lpn is not null, Unpack '||p_from_lpn_id||' from ' ||l_parent_lpn_id);
6723 END IF;
6724 wms_container_pvt.packunpack_container
6725 (p_api_version => 1.0
6726 ,p_content_lpn_id => p_from_lpn_id
6727 ,p_lpn_id => l_parent_lpn_id
6728 ,p_operation => 2 -- Unpack
6729 ,p_organization_id => p_org_id
6730 ,p_commit => fnd_api.g_false
6731 ,x_return_status => x_return_status
6732 ,x_msg_count => x_msg_count
6733 ,x_msg_data => x_msg_data);
6734
6735 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
6736 IF (l_debug = 1) THEN
6737 DEBUG('Error unpacking content_lpn = ' ||
6738 p_from_lpn_id || ' into lpn = ' ||
6739 l_parent_lpn_id,'load_lpn',9);
6740 debug('Error message:'||x_msg_data,9);
6741 END IF;
6742 RAISE fnd_api.g_exc_error;
6743 END IF;
6744 END IF; --IF l_parent_lpn_id IS NOT NULL THEN
6745
6746 -- Pack the given LPN into ToLPN
6747 IF p_to_lpn_id IS NOT NULL AND p_to_lpn_id <> p_from_lpn_id AND (p_to_lpn_id <> 0) THEN
6748 IF(l_debug = 1) THEN
6749 debug('Receiving LPN, To lpn is not null, Pack '||p_from_lpn_id|| ' Into ' ||p_to_lpn_id);
6750 END IF;
6751
6752 -- Only modify LPN sub/loc if it is WIP LPN, since the RCV case
6753 -- won't even reach this point
6754 IF (l_lpn_context=2 AND l_sub_loc_changed = 'Y') THEN
6755 wms_container_pvt.modify_lpn_wrapper
6756 ( p_api_version => 1.0
6757 ,x_return_status => x_return_status
6758 ,x_msg_count => x_msg_count
6759 ,x_msg_data => x_msg_data
6760 ,p_lpn_id => p_from_lpn_id
6761 ,p_subinventory => l_to_sub
6762 ,p_locator_id => l_to_loc
6763 );
6764 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
6765 IF (l_debug = 1) THEN
6766 debug('Error modifying lpn',
6767 'load_lpn', 9);
6768 END IF;
6769 END IF;
6770 END IF;
6771
6772 wms_container_pvt.packunpack_container
6773 (p_api_version => 1.0
6774 ,p_content_lpn_id => p_from_lpn_id
6775 ,p_lpn_id => p_to_lpn_id
6776 ,p_operation => 1 --Pack
6777 ,p_organization_id => p_org_id
6778 ,p_commit => fnd_api.g_false
6779 ,x_return_status => x_return_status
6780 ,x_msg_count => x_msg_count
6781 ,x_msg_data => x_msg_data);
6782 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
6783 IF (l_debug = 1) THEN
6784 DEBUG('Error packing content_lpn = ' ||
6785 p_from_lpn_id || ' into lpn = ' ||
6786 p_to_lpn_id,'load_lpn',9);
6787 debug('Error message:'||x_msg_data,9);
6788 END IF;
6789 RAISE fnd_api.g_exc_error;
6790 END IF;
6791 END IF; -- IF p_to_lpn_id IS NOT NULL AND p_to_lpn_id <> p_from_lpn_id AND (p_to_lpn_id <> 0) THEN
6792
6793 END IF; --IF p_mode = 1
6794
6795 -- only call rcv tm if loading into an lpn with different sub/loc
6796 IF l_lpn_context = 3 AND l_sub_loc_changed = 'Y' THEN
6797 l_group_id := insert_rti
6798 (p_from_org => p_org_id
6799 ,p_lpn_id => p_from_lpn_id
6800 ,p_to_org => p_org_id -- same as from lpn
6801 ,p_to_sub => l_to_sub
6802 ,p_to_loc => l_to_loc
6803 ,p_xfer_lpn_id => p_from_lpn_id
6804 ,p_first_time => 1
6805 ,p_mobile_txn => 'Y'
6806 ,p_txn_mode_code => 'ONLINE'
6807 ,x_return_status => x_return_status
6808 ,x_msg_count => x_msg_count
6809 ,x_msg_data => x_msg_data);
6810 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
6811 IF (l_debug = 1) THEN
6812 debug('Error inserting RTI');
6813 END IF;
6814 RAISE fnd_api.g_exc_error;
6815 END IF;
6816
6817 IF (l_debug = 1 ) then
6818 debug('RTI inserted with group_id:'|| l_group_id, 9);
6819 END IF;
6820
6821 inv_rcv_integration_apis.insert_wlpni
6822 (p_api_version => 1.0
6823 ,x_return_status => x_return_status
6824 ,x_msg_count => x_msg_count
6825 ,x_msg_data => x_msg_data
6826 ,p_organization_id => p_org_id
6827 ,p_lpn_id => p_from_lpn_id
6828 ,p_license_plate_number => NULL
6829 ,p_lpn_group_id => l_group_id
6830 ,p_parent_lpn_id => p_to_lpn_id
6831 );
6832 l_is_rcv_tm_call_needed := TRUE;
6833 END IF; -- If Into LPN has different sub/loc
6834
6835 -- Call suggestions_pub_wrapper for the from lpn
6836 suggestions_pub_wrapper(
6837 p_lpn_id => p_from_lpn_id
6838 , p_org_id => p_org_id
6839 , p_user_id => p_user_id
6840 , p_eqp_ins => p_eqp_ins
6841 , p_status => 4 --loaded
6842 , p_check_for_crossdock => p_check_for_crossdock
6843 , x_number_of_rows => l_x_num_of_rows
6844 , x_return_status => l_x_return_status
6845 , x_msg_count => l_x_msg_count
6846 , x_msg_data => l_x_msg_data
6847 , x_crossdock => x_crossdock
6848 );
6849
6850 IF(l_debug = 1) THEN
6851 debug('x_return_status from suggestions_pub ' || l_x_return_status);
6852 debug('After creating suggestions for ' || p_from_lpn_id);
6853 END IF;
6854
6855
6856 IF l_x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
6857 -- IF (x_msg_count = 0) THEN
6858 -- FND_MESSAGE.SET_NAME('WMS','WMS_LOG_EXCEPTION_FAIL');
6859 -- FND_MSG_PUB.ADD;
6860 -- END IF;
6861 RAISE FND_API.g_exc_unexpected_error;
6862 ELSIF l_x_return_status = FND_API.G_RET_STS_ERROR THEN
6863 -- IF (x_msg_count = 0 ) THEN
6864 -- FND_MESSAGE.SET_NAME('WMS','WMS_LOG_EXCEPTION_FAIL');
6865 -- FND_MSG_PUB.ADD;
6866 -- END IF;
6867 RAISE FND_API.G_EXC_ERROR;
6868 END IF;
6869
6870 --BUG 4345714: If any line is not detailed, then fail.
6871 BEGIN
6872 SELECT /*+ ORDERED INDEX(MTRL MTL_TXN_REQUEST_LINES_N7) */ 1
6873 INTO l_discrepancy
6874 FROM mtl_txn_request_lines mtrl ,
6875 (SELECT wlpn.lpn_id /*5723418*/
6876 FROM wms_license_plate_numbers wlpn
6877 START WITH wlpn.lpn_id = p_from_lpn_id
6878 CONNECT BY PRIOR wlpn.lpn_id = wlpn.parent_lpn_id) wlpn
6879
6880 WHERE mtrl.lpn_id = wlpn.lpn_id
6881 AND mtrl.line_status = 7
6882 AND (mtrl.quantity-Nvl(mtrl.quantity_delivered,0)) <> Nvl(mtrl.quantity_detailed,0)
6883 AND mtrl.organization_id = p_org_id;
6884 EXCEPTION
6885 WHEN too_many_rows THEN
6886 l_discrepancy := 1;
6887 WHEN no_data_found THEN
6888 l_discrepancy := 0;
6889 WHEN OTHERS THEN
6890 l_discrepancy := 0;
6891 END;
6892
6893 IF (l_debug = 1) THEN
6894 debug('l_discrepancy = ' || l_discrepancy, 'load_lpn', 9);
6895 END IF;
6896
6897 IF l_discrepancy = 1 THEN
6898 fnd_msg_pub.count_and_get(p_count => l_msg_count, p_data =>
6899 l_msg_data);
6900 IF l_debug = 1 THEN
6901 debug('l_msg_count: ' || l_msg_count);
6902 debug('l_msg_data: ' || l_msg_data);
6903 END IF;
6904
6905 IF (l_msg_count IS NULL OR l_msg_count = 0) THEN
6906 -- use default message if there are no message on stack
6907 -- first reset message stack
6908 fnd_msg_pub.initialize();
6909 FND_MESSAGE.SET_NAME('WMS','WMS_ALLOCATE_FAIL');
6910 FND_MSG_PUB.ADD;
6911 ELSIF l_msg_count > 1 THEN
6912 FOR i IN 2 .. l_msg_count LOOP
6913 fnd_msg_pub.delete_msg(i);
6914 END LOOP;
6915 END IF;
6916
6917 -- 6962664
6918 debug('Suggested locator capacity should be reverted as putaway fails');
6919 debug('Before calling the revert_loc_suggested_capacity');
6920 wms_task_dispatch_put_away.revert_loc_suggested_capacity(
6921 x_return_status => l_x_return_status
6922 , x_msg_count => l_x_msg_count
6923 , x_msg_data => l_x_msg_data
6924 , p_organization_id => p_org_id
6925 , p_lpn_id => p_from_lpn_id
6926 );
6927 debug('After calling the revert_loc_suggested_capacity');
6928 ROLLBACK;
6929 -- 6962664
6930
6931 RAISE fnd_api.g_exc_error;
6932 END IF;
6933
6934 -- Call TM for Pack/Unpack the given lpn
6935 IF (l_is_tm_call_needed = TRUE) THEN
6936 l_ret := inv_lpn_trx_pub.process_lpn_trx(
6937 p_trx_hdr_id => l_trx_header_id,
6938 p_commit => fnd_api.g_false,
6939 x_proc_msg => x_msg_data,
6940 p_atomic => fnd_api.g_true);
6941 -- Check return value and in case of failure raise exception
6942 IF (l_ret <> 0) THEN
6943 IF l_debug = 1 THEN
6944 debug('TM call for pack unpack faluire');
6945 debug('Failure message ' || x_msg_data);
6946 END IF;
6947 FND_MESSAGE.SET_NAME('WMS','WMS_LOG_EXCEPTION_FAIL');
6948 RAISE FND_API.G_EXC_ERROR;
6949 END IF;
6950 END IF;
6951
6952 IF (l_is_rcv_tm_call_needed = TRUE) THEN
6953
6954 --BUG 3359835: Must call activate_operation_instance
6955 l_progress := 40;
6956 SELECT mmtt.transaction_temp_id
6957 bulk collect INTO l_mmtt_ids
6958 FROM mtl_material_transactions_temp mmtt
6959 WHERE mmtt.organization_id = p_org_id
6960 AND mmtt.move_order_line_id IN
6961 ( SELECT mtrl.line_id
6962 FROM mtl_txn_request_lines mtrl ,
6963 (SELECT wlpn.lpn_id /* 5723418 */
6964 FROM wms_license_plate_numbers wlpn
6965 START WITH wlpn.lpn_id = p_from_lpn_id
6966 CONNECT BY PRIOR wlpn.lpn_id = wlpn.parent_lpn_id) wlpn
6967 WHERE mtrl.organization_id = p_org_id
6968 AND mtrl.lpn_id = wlpn.lpn_id );
6969 l_progress := 50;
6970
6971 BEGIN
6972 SELECT employee_id
6973 INTO l_emp_id
6974 FROM fnd_user
6975 WHERE user_id = p_user_id;
6976 EXCEPTION
6977 WHEN OTHERS THEN
6978 IF (l_debug = 1) THEN
6979 DEBUG('There is no employee id tied to the user','load_lpn',9);
6980 END IF;
6981 fnd_message.set_name('WMS', 'WMS_NO_EMP_FOR_USR');
6982 fnd_msg_pub.ADD;
6983 RAISE fnd_api.g_exc_error;
6984 END;
6985
6986 -- BEGIN DBI FIX
6987 l_task_execute_rec.person_id := l_emp_id;
6988 l_task_execute_rec.organization_id := p_org_id;
6989 l_task_execute_rec.loaded_time := Sysdate;
6990 l_task_execute_rec.user_task_type := -1;
6991 -- END DBI FIX
6992
6993 FOR i IN 1 .. l_mmtt_ids.COUNT LOOP
6994 IF (l_debug = 1) THEN
6995 DEBUG('Calling activate_operation_instance','load_lpn',1);
6996 DEBUG(' ( p_source_task_id => ' || l_mmtt_ids(i),'load_lpn',9);
6997 DEBUG(' ,p_activity_type_id => 1','load_lpn',9);
6998 DEBUG(' ,p_task_execute_rec => l_task_execute_rec','load_lpn',9);
6999 DEBUG(' ,p_operation_type_id => 1 )','load_lpn',9);
7000 END IF;
7001
7002 --Moving the following line before the loop starts to stamp the
7003 --same time on all tasks for the given lpn - BEGIN DBI FIX
7004 --l_task_execute_rec.person_id := l_emp_id;
7005 --l_task_execute_rec.organization_id := p_org_id;
7006 --l_task_execute_rec.loaded_time := Sysdate;
7007 --l_task_execute_rec.user_task_type := -1;
7008 --END DBI FIX
7009
7010 wms_atf_runtime_pub_apis.activate_operation_instance
7011 ( p_source_task_id => l_mmtt_ids(i)
7012 ,p_activity_id => 1 -- Inbound
7013 ,p_task_execute_rec => l_task_execute_rec
7014 ,p_operation_type_id => 1 -- load
7015 ,x_return_status => x_return_status
7016 ,x_msg_data => x_msg_data
7017 ,x_msg_count => x_msg_count
7018 ,x_error_code => l_error_code
7019 ,x_consolidation_method_id => l_consolidation_method_id
7020 ,x_drop_lpn_option => l_drop_lpn_option
7021 );
7022 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
7023 IF (l_debug = 1) THEN
7024 DEBUG('xxx: Error in activate_operation_instance','transfer_contents',9);
7025 END IF;
7026 RAISE fnd_api.g_exc_error;
7027 END IF;
7028 END LOOP;
7029
7030 --End of BUG FIX 3359835
7031
7032 l_old_txn_mode_code := inv_rcv_common_apis.g_po_startup_value.transaction_mode;
7033 inv_rcv_common_apis.g_po_startup_value.transaction_mode := 'ONLINE';
7034
7035 l_progress := 100;
7036
7037 BEGIN
7038 inv_rcv_mobile_process_txn.rcv_process_receive_txn
7039 (x_return_status => x_return_status
7040 ,x_msg_data => x_msg_data
7041 );
7042 EXCEPTION
7043 WHEN OTHERS THEN
7044 inv_rcv_common_apis.g_po_startup_value.transaction_mode := l_old_txn_mode_code;
7045 IF (l_debug = 1) THEN
7046 DEBUG('xxx: Error - Rcv TM Failed','load_lpn',9);
7047 END IF;
7048 RAISE fnd_api.g_exc_error;
7049 END;
7050
7051 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
7052 IF (l_debug = 1) THEN
7053 DEBUG('xxx: Error - Rcv TM Failed','load_lpn',9);
7054 END IF;
7055 inv_rcv_common_apis.g_po_startup_value.transaction_mode := l_old_txn_mode_code;
7056 RAISE fnd_api.g_exc_error;
7057 END IF;
7058
7059 l_progress := 150;
7060
7061 inv_rcv_common_apis.g_po_startup_value.transaction_mode := l_old_txn_mode_code;
7062 inv_rcv_common_apis.rcv_clear_global;
7063 END IF;
7064
7065 -- RCV TM would call complete_operation_instance
7066 IF (l_is_rcv_tm_call_needed <> TRUE) THEN
7067 BEGIN
7068 SELECT employee_id
7069 INTO l_emp_id
7070 FROM fnd_user
7071 WHERE user_id = p_user_id;
7072 EXCEPTION
7073 WHEN OTHERS THEN
7074 IF (l_debug = 1) THEN
7075 DEBUG('There is no employee id tied to the user','transfer_contents',9);
7076 END IF;
7077 fnd_message.set_name('WMS', 'WMS_NO_EMP_FOR_USR');
7078 fnd_msg_pub.ADD;
7079 RAISE fnd_api.g_exc_error;
7080 END;
7081 debug('Calling complete_atf_load for:'||p_from_lpn_id);
7082 DEBUG(' p_org_id => '||p_org_id, 'load_lpn',4);
7083 DEBUG(' p_emp_id => '||l_emp_id, 'load_lpn',4);
7084
7085 Complete_ATF_Load (x_return_status => x_return_status
7086 ,x_msg_count => x_msg_count
7087 ,x_msg_data => x_msg_data
7088 ,p_org_id => p_org_id
7089 ,p_lpn_id => p_from_lpn_id
7090 ,p_emp_id => l_emp_id );
7091
7092 -- Check for the return status
7093 IF x_return_status = fnd_api.g_ret_sts_success THEN
7094 -- Activate completed successfully.
7095 NULL;
7096 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
7097 RAISE fnd_api.g_exc_error;
7098 ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
7099 RAISE fnd_api.g_exc_unexpected_error;
7100 END IF;
7101 END IF;
7102
7103 -- Before returning commit all changes to datbase.
7104 COMMIT;
7105
7106 EXCEPTION
7107 WHEN OTHERS THEN
7108 x_return_status := fnd_api.g_ret_sts_unexp_error;
7109 debug(SQLCODE, 1);
7110
7111 -- Get rid of the folloiwng, as it appends a junk message to the
7112 -- error message stack
7113 -- IF SQLCODE IS NOT NULL THEN
7114 -- l_progress := 100;
7115 -- debug('Exception in load_lpn : ' || SQLCODE);
7116 -- inv_mobile_helper_functions.sql_error('load_lpn', l_progress, SQLCODE);
7117 -- END IF;
7118 END;
7119
7120
7121 PROCEDURE update_mo(
7122 MoLineId NUMBER,
7123 ReferenceId NUMBER,
7124 Reference VARCHAR2,
7125 Reference_type_code NUMBER,
7126 lpn_id NUMBER,
7127 wms_process_flag NUMBER,
7128 inspect_status NUMBER)
7129 IS
7130 BEGIN
7131 UPDATE mtl_txn_request_lines
7132 SET Reference_id = decode(ReferenceId,-9999,referenceId,NULL,NULL,referenceId),
7133 Reference = decode(Reference,'-9999',reference,NULL,NULL,reference),
7134 Reference_type_code = decode(Reference_type_code,'-9999',reference_type_code,NULL,NULL,reference_type_code),
7135 lpn_id = decode(lpn_id,-9999,lpn_id,NULL,NULL,lpn_id),
7136 wms_process_flag = decode(wms_process_flag,-9999,wms_process_flag,NULL,NULL,wms_process_flag),
7137 inspection_status = decode(inspect_status,-9999,inspect_status,NULL,null,inspect_status)
7138 WHERE line_id = MoLineid;
7139 END;
7140
7141
7142 FUNCTION insert_rti(p_from_org IN NUMBER
7143 ,p_lpn_id IN NUMBER
7144 ,p_to_org IN NUMBER
7145 ,p_to_sub IN VARCHAR2
7146 ,p_to_loc IN NUMBER
7147 ,p_xfer_lpn_id IN NUMBER
7148 ,p_first_time IN NUMBER
7149 ,p_mobile_txn IN VARCHAR2
7150 ,p_txn_mode_code IN VARCHAR2
7151 ,x_return_status OUT nocopy VARCHAR2
7152 ,x_msg_count OUT nocopy NUMBER
7153 ,x_msg_data OUT nocopy VARCHAR2 )
7154 RETURN NUMBER
7155 IS
7156 l_rowid VARCHAR2(40);
7157 l_interface_transaction_id NUMBER;
7158 l_group_id NUMBER;
7159 l_sysdate DATE := Sysdate;
7160 l_user_id NUMBER := fnd_global.user_id;
7161 l_login_id NUMBER := fnd_global.login_id;
7162 l_to_sub VARCHAR2(10);
7163 l_to_loc NUMBER;
7164 l_lpn_id NUMBER;
7165 l_xfer_lpn_id NUMBER;
7166 l_from_org NUMBER;
7167 l_to_org NUMBER;
7168 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
7169 l_progress VARCHAR(3) := '0';
7170 l_txn_mode_code VARCHAR2(10);
7171 l_error_code NUMBER;
7172
7173 l_operating_unit_id MO_GLOB_ORG_ACCESS_TMP.ORGANIZATION_ID%TYPE; --<R12 MOAC>
7174
7175 BEGIN
7176 x_return_status := fnd_api.g_ret_sts_success;
7177
7178 l_to_sub := p_to_sub;
7179 l_to_loc := p_to_loc;
7180 l_lpn_id := p_lpn_id;
7181 l_xfer_lpn_id := p_xfer_lpn_id;
7182 l_from_org := p_from_org;
7183 l_to_org := p_to_org;
7184 l_txn_mode_code := p_txn_mode_code;
7185
7186 IF (l_debug = 1) THEN
7187 DEBUG('Entering...', 'insert_rti', 9);
7188 debug(' (p_to_sub => ' || p_to_sub, 'insert_rti', 9);
7189 debug(' p_from_org => ' || p_from_org, 'insert_rti', 9);
7190 debug(' p_to_org => ' || p_to_org, 'insert_rti', 9);
7191 debug(' p_to_loc => ' || p_to_loc, 'insert_rti', 9);
7192 debug(' p_lpn_id => ' || p_lpn_id, 'insert_rti', 9);
7193 debug(' p_xfer_lpn_id => ' || p_xfer_lpn_id, 'insert_rti', 9);
7194 debug(' p_first_time => ' || p_first_time, 'insert_rti', 9);
7195 debug(' p_mobile_txn => ' || p_mobile_txn, 'insert_rti', 9);
7196 debug(' p_txn_mode_code => ' || p_txn_mode_code||')', 'insert_rti', 9);
7197 END IF;
7198
7199 IF (p_first_time = 1) THEN
7200 IF (l_debug = 1) THEN
7201 debug('Calling init_startup_values','insert_rti',9);
7202 debug(' p_org_id => '||l_from_org, 'insert_rti',9);
7203 END IF;
7204
7205 BEGIN
7206 inv_rcv_common_apis.init_startup_values(l_from_org);
7207 EXCEPTION
7208 WHEN NO_DATA_FOUND THEN
7209 fnd_message.set_name('INV', 'INV_RCV_PARAM');
7210 fnd_msg_pub.ADD;
7211 RAISE fnd_api.g_exc_error;
7212 END;
7213
7214 l_progress := '2';
7215
7216 IF inv_rcv_common_apis.g_po_startup_value.sob_id IS NULL THEN
7217 --BUG 3435079: For performance reason, do not go against the view
7218 --org_organization_definitions. instead, use
7219 --the query below
7220 SELECT TO_NUMBER(hoi.org_information1)
7221 INTO inv_rcv_common_apis.g_po_startup_value.sob_id
7222 FROM hr_organization_information hoi
7223 WHERE hoi.organization_id = l_from_org
7224 AND (hoi.org_information_context || '') = 'Accounting Information';
7225
7226 END IF;
7227
7228 l_progress := '4';
7229
7230 IF (l_debug = 1) THEN
7231 debug('init_startup_value exited. Calling validate_trx_date'
7232 ,'insert_rti', 9);
7233 END IF;
7234
7235 inv_rcv_common_apis.validate_trx_date
7236 (
7237 p_trx_date => SYSDATE
7238 , p_organization_id => l_from_org
7239 , p_sob_id => inv_rcv_common_apis.g_po_startup_value.sob_id
7240 , x_return_status => x_return_status
7241 , x_error_code => l_error_code
7242 );
7243
7244 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
7245 IF (l_debug = 1)THEN
7246 debug('Date validation failed','insert_rti',9);
7247 END IF;
7248 RAISE fnd_api.g_exc_error;
7249 END IF;
7250
7251 l_progress := '6';
7252
7253 END IF; --IF (p_first_time = 1)
7254
7255 SELECT rcv_transactions_interface_s.NEXTVAL
7256 INTO l_interface_transaction_id
7257 FROM dual;
7258
7259 -- init_start_values should have called gen_txn_group_id
7260 l_group_id := inv_rcv_common_apis.g_rcv_global_var.interface_group_id;
7261
7262 IF (l_debug = 1) THEN
7263 DEBUG('Calling rcv_trx_interface_insert_pkg.insert_row',
7264 'insert_rti', 9);
7265 END IF;
7266
7267 SELECT org_information2
7268 INTO l_operating_unit_id
7269 FROM hr_organization_information
7270 WHERE organization_id = l_to_org
7271 AND org_information_context || '' ='Accounting Information'; --<R12 MOAC>
7272
7273 l_progress := '10';
7274
7275 rcv_trx_interface_insert_pkg.insert_row
7276 (
7277 x_rowid => l_rowid
7278 ,x_interface_transaction_id => l_interface_transaction_id
7279 ,x_group_id => l_group_id
7280 ,x_last_update_date => l_sysdate
7281 ,x_last_updated_by => l_user_id
7282 ,x_creation_date => l_sysdate
7283 ,x_created_by => l_user_id
7284 ,x_last_update_login => l_login_id
7285 ,x_transaction_type => 'TRANSFER'
7286 ,x_transaction_date => l_sysdate
7287 ,x_processing_status_code => 'PENDING'
7288 ,x_processing_mode_code => l_txn_mode_code
7289 ,x_processing_request_id => NULL
7290 ,x_transaction_status_code => 'PENDING'
7291 ,x_category_id => NULL
7292 ,x_quantity => 0
7293 ,x_unit_of_measure => 'X'
7294 ,x_interface_source_code => 'RCV'
7295 ,x_interface_source_line_id => NULL
7296 ,x_inv_transaction_id => NULL
7297 ,x_item_id => NULL
7298 ,x_item_description => NULL
7299 ,x_item_revision => NULL
7300 ,x_uom_code => NULL
7301 ,x_employee_id => l_user_id
7302 ,x_auto_transact_code => NULL
7303 ,x_shipment_header_id => NULL
7304 ,x_shipment_line_id => NULL
7305 ,x_ship_to_location_id => NULL
7306 ,x_primary_quantity => NULL
7307 ,x_primary_unit_of_measure => NULL
7308 ,x_receipt_source_code => NULL
7309 ,x_vendor_id => NULL
7310 ,x_vendor_site_id => NULL
7311 ,x_from_organization_id => l_from_org
7312 ,x_to_organization_id => l_to_org
7313 ,x_routing_header_id => NULL
7314 ,x_routing_step_id => NULL
7315 ,x_source_document_code => NULL
7316 ,x_parent_transaction_id => NULL
7317 ,x_po_header_id => NULL
7318 ,x_po_revision_num => NULL
7319 ,x_po_release_id => NULL
7320 ,x_po_line_id => NULL
7321 ,x_po_line_location_id => NULL
7322 ,x_po_unit_price => NULL
7323 ,x_currency_code => NULL
7324 ,x_currency_conversion_type => NULL
7325 ,x_currency_conversion_rate => NULL
7326 ,x_currency_conversion_date => NULL
7327 ,x_po_distribution_id => NULL
7328 ,x_requisition_line_id => NULL
7329 ,x_req_distribution_id => NULL
7330 ,x_charge_account_id => NULL
7331 ,x_substitute_unordered_code => NULL
7332 ,x_receipt_exception_flag => NULL
7333 ,x_accrual_status_code => NULL
7334 ,x_inspection_status_code => NULL
7335 ,x_inspection_quality_code => NULL
7336 ,x_destination_type_code => 'RECEIVING'
7337 ,x_deliver_to_person_id => NULL
7338 ,x_location_id => NULL
7339 ,x_deliver_to_location_id => NULL
7340 ,x_subinventory => l_to_sub
7341 ,x_locator_id => l_to_loc
7342 ,x_wip_entity_id => NULL
7343 ,x_wip_line_id => NULL
7344 ,x_department_code => NULL
7345 ,x_wip_repetitive_schedule_id=> NULL
7346 ,x_wip_operation_seq_num => NULL
7347 ,x_wip_resource_seq_num => NULL
7348 ,x_bom_resource_id => NULL
7349 ,x_shipment_num => NULL
7350 ,x_freight_carrier_code => NULL
7351 ,x_bill_of_lading => NULL
7352 ,x_packing_slip => NULL
7353 ,x_shipped_date => NULL
7354 ,x_expected_receipt_date => NULL
7355 ,x_actual_cost => NULL
7356 ,x_transfer_cost => NULL
7357 ,x_transportation_cost => NULL
7358 ,x_transportation_account_id => NULL
7359 ,x_num_of_containers => NULL
7360 ,x_waybill_airbill_num => NULL
7361 ,x_vendor_item_num => NULL
7362 ,x_vendor_lot_num => NULL
7363 ,x_rma_reference => NULL
7364 ,x_comments => NULL
7365 ,x_attribute_category => NULL
7366 ,x_attribute1 => NULL
7367 ,x_attribute2 => NULL
7368 ,x_attribute3 => NULL
7369 ,x_attribute4 => NULL
7370 ,x_attribute5 => NULL
7371 ,x_attribute6 => NULL
7372 ,x_attribute7 => NULL
7373 ,x_attribute8 => NULL
7374 ,x_attribute9 => NULL
7375 ,x_attribute10 => NULL
7376 ,x_attribute11 => NULL
7377 ,x_attribute12 => NULL
7378 ,x_attribute13 => NULL
7379 ,x_attribute14 => NULL
7380 ,x_attribute15 => NULL
7381 ,x_ship_head_attribute_category => NULL
7382 ,x_ship_head_attribute1 => NULL
7383 ,x_ship_head_attribute2 => NULL
7384 ,x_ship_head_attribute3 => NULL
7385 ,x_ship_head_attribute4 => NULL
7386 ,x_ship_head_attribute5 => NULL
7387 ,x_ship_head_attribute6 => NULL
7388 ,x_ship_head_attribute7 => NULL
7389 ,x_ship_head_attribute8 => NULL
7390 ,x_ship_head_attribute9 => NULL
7391 ,x_ship_head_attribute10 => NULL
7392 ,x_ship_head_attribute11 => NULL
7393 ,x_ship_head_attribute12 => NULL
7394 ,x_ship_head_attribute13 => NULL
7395 ,x_ship_head_attribute14 => NULL
7396 ,x_ship_head_attribute15 => NULL
7397 ,x_ship_line_attribute_category => NULL
7398 ,x_ship_line_attribute1 => NULL
7399 ,x_ship_line_attribute2 => NULL
7400 ,x_ship_line_attribute3 => NULL
7401 ,x_ship_line_attribute4 => NULL
7402 ,x_ship_line_attribute5 => NULL
7403 ,x_ship_line_attribute6 => NULL
7404 ,x_ship_line_attribute7 => NULL
7405 ,x_ship_line_attribute8 => NULL
7406 ,x_ship_line_attribute9 => NULL
7407 ,x_ship_line_attribute10 => NULL
7408 ,x_ship_line_attribute11 => NULL
7409 ,x_ship_line_attribute12 => NULL
7410 ,x_ship_line_attribute13 => NULL
7411 ,x_ship_line_attribute14 => NULL
7412 ,x_ship_line_attribute15 => NULL
7413 ,x_ussgl_transaction_code => NULL
7414 ,x_government_context => NULL
7415 ,x_reason_id => NULL
7416 ,x_destination_context => NULL
7417 ,x_source_doc_quantity => NULL
7418 ,x_source_doc_unit_of_measure=> NULL
7419 ,x_lot_number_cc => NULL
7420 ,x_serial_number_cc => NULL
7421 ,x_qa_collection_id => NULL
7422 ,x_country_of_origin_code => NULL
7423 ,x_oe_order_header_id => NULL
7424 ,x_oe_order_line_id => NULL
7425 ,x_customer_item_num => NULL
7426 ,x_customer_id => NULL
7427 ,x_customer_site_id => NULL
7428 ,x_put_away_rule_id => NULL
7429 ,x_put_away_strategy_id => NULL
7430 ,x_lpn_id => l_lpn_id
7431 ,x_transfer_lpn_id => l_xfer_lpn_id
7432 ,x_cost_group_id => NULL
7433 ,x_mmtt_temp_id => NULL
7434 ,x_mobile_txn => p_mobile_txn
7435 ,x_transfer_cost_group_id => NULL
7436 ,x_secondary_quantity => NULL
7437 ,x_secondary_unit_of_measure => NULL
7438 ,p_org_id => l_operating_unit_id --<R12 MOAC>
7439 );
7440
7441 UPDATE
7442 rcv_transactions_interface
7443 SET
7444 validation_flag = 'Y'
7445 ,lpn_group_id = l_group_id
7446 WHERE ROWID = l_rowid;
7447
7448 l_progress := '20';
7449
7450 IF (l_debug = 1) THEN
7451 DEBUG('Quiting with group_id = '||l_group_id, 'insert_rti', 9);
7452 END IF;
7453
7454 RETURN l_group_id;
7455 EXCEPTION
7456 WHEN OTHERS THEN
7457 x_return_status := fnd_api.g_ret_sts_error;
7458 IF (l_debug = 1) THEN
7459 debug('Error after progress = ' || l_progress,
7460 'insert_rti',
7461 9);
7462 END IF;
7463 IF SQLCODE IS NOT NULL THEN
7464 IF (l_debug = 1) THEN
7465 debug(SQLCODE, 'insert_rti', 9);
7466 END IF;
7467 END IF;
7468 RETURN -1;
7469 END insert_rti;
7470
7471
7472 PROCEDURE pre_process_lpn (
7473 x_return_status OUT NOCOPY VARCHAR2
7474 , x_msg_count OUT NOCOPY NUMBER
7475 , x_msg_data OUT NOCOPY VARCHAR2
7476 , p_from_lpn_id IN NUMBER
7477 , p_organization_id IN NUMBER
7478 , p_subinventory_code IN VARCHAR2
7479 , p_lpn_mode IN NUMBER
7480 , p_locator_id IN NUMBER
7481 , p_to_lpn_id IN NUMBER
7482 , p_project_id IN NUMBER DEFAULT NULL
7483 , p_task_id IN NUMBER DEFAULT NULL
7484 , p_user_id IN NUMBER
7485 , p_lpn_context IN NUMBER
7486 , p_batch_id IN NUMBER
7487 , p_batch_seq IN NUMBER
7488 , p_pack_trans_id IN NUMBER
7489 , x_batch_seq OUT NOCOPY NUMBER --BUG 3544918
7490 ) IS
7491 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7492 l_group_id NUMBER;
7493 l_progress NUMBER;
7494 l_ret NUMBER;
7495 l_lpn_id NUMBER;
7496 p_parent_lpn_id NUMBER;
7497 l_lpn_sub mtl_secondary_inventories.secondary_inventory_name%TYPE;
7498 l_lpn_loc NUMBER;
7499 l_to_lpn_id NUMBER;
7500
7501
7502 CURSOR lpn_cursor IS
7503 SELECT lpn_id
7504 FROM wms_license_plate_numbers
7505 WHERE parent_lpn_id = p_from_lpn_id;
7506
7507 l_batch_seq NUMBER := p_batch_seq;
7508
7509 BEGIN
7510
7511 l_progress := 10;
7512
7513 x_return_status := fnd_api.g_ret_sts_success;
7514
7515 IF (l_debug = 1) THEN
7516 debug('Pre_Process_lpn : Patchset J code - Nested LPNs are supported');
7517 debug(' p_from_lpn_id: '||p_from_lpn_id);
7518 debug(' p_to_lpn_id: '||p_to_lpn_id);
7519 END IF;
7520
7521 BEGIN
7522 -- Get Parent lpn id
7523 SELECT parent_lpn_id
7524 ,subinventory_code
7525 ,locator_id
7526 INTO p_parent_lpn_id
7527 ,l_lpn_sub
7528 ,l_lpn_loc
7529 FROM wms_license_plate_numbers
7530 WHERE lpn_id = p_from_lpn_id;
7531 EXCEPTION
7532 WHEN OTHERS THEN
7533 IF (l_debug = 1) THEN
7534 debug('Error retrieving parent_lpn_id');
7535 debug('SQLCODE:'||SQLCODE||' SQLERRM'||Sqlerrm,9);
7536 END IF;
7537 END;
7538
7539 -- Get LPN group Id
7540 IF p_lpn_context = 3 THEN
7541 IF inv_rcv_common_apis.g_rcv_global_var.interface_group_id IS NULL THEN
7542 SELECT rcv_interface_groups_s.NEXTVAL
7543 INTO l_group_id
7544 FROM DUAL;
7545 inv_rcv_common_apis.g_rcv_global_var.interface_group_id := l_group_id;
7546 ELSE
7547 l_group_id := inv_rcv_common_apis.g_rcv_global_var.interface_group_id;
7548 END IF;
7549 END IF;
7550
7551 -- Drop Entire LPN,
7552 IF p_lpn_mode = 2 THEN
7553
7554 -- Process Resides in inventory LPN
7555 IF p_lpn_context = 1 AND p_parent_lpn_id IS NOT NULL THEN
7556
7557 IF(l_debug =1) THEN
7558 debug('Inventory LPN, Parent lpn is not null, Unpack '||p_from_lpn_id|| ' from ' ||p_parent_lpn_id);
7559 END IF;
7560
7561 -- Unpack the given LPN from its parent.
7562 PackUnpack_LPN(
7563 p_from_lpn_id => p_parent_lpn_id
7564 , p_to_lpn_id => p_from_lpn_id
7565 , p_org_id => p_organization_id
7566 , p_sub_code => l_lpn_sub
7567 , p_loc_id => l_lpn_loc
7568 , p_user_id => p_user_id
7569 , p_project_id => p_project_id
7570 , p_task_id => p_task_id
7571 , p_trx_header_id => p_pack_trans_id
7572 , p_mode => 2 -- unpack
7573 , p_batch_id => p_batch_id
7574 , p_batch_seq => l_batch_seq
7575 , x_return_status => x_return_status
7576 , x_msg_count => x_msg_count
7577 , x_msg_data => x_msg_data);
7578
7579 -- Check return value and in case of failure raise exception
7580 IF (l_ret <> 0) THEN
7581 IF l_debug = 1 THEN
7582 debug('TM call for pack unpack faluire');
7583 debug('Failure message ' || x_msg_data);
7584 END IF;
7585 FND_MESSAGE.SET_NAME('WMS','WMS_LOG_EXCEPTION_FAIL');
7586 RAISE FND_API.G_EXC_ERROR;
7587 END IF;
7588
7589 l_batch_seq := l_batch_seq + 1;
7590 END IF;
7591
7592 -- Process Resides in Wip LPN
7593 IF p_lpn_context=2 AND p_parent_lpn_id IS NOT NULL THEN
7594
7595 IF(l_debug = 1) THEN
7596 debug('Resides in WIP LPN, Parent lpn is not null, Unpack '||p_from_lpn_id||' from ' ||p_parent_lpn_id);
7597 END IF;
7598
7599 -- unpack from LPN from its parent.
7600 wms_container_pvt.packunpack_container
7601 (p_api_version => 1.0
7602 ,p_content_lpn_id => p_from_lpn_id
7603 ,p_lpn_id => p_parent_lpn_id
7604 ,p_operation => 2 -- Unpack
7605 ,p_organization_id => p_organization_id
7606 ,p_commit => fnd_api.g_false
7607 ,x_return_status => x_return_status
7608 ,x_msg_count => x_msg_count
7609 ,x_msg_data => x_msg_data);
7610
7611 END IF;
7612
7613 -- Process Resides in receiving LPN
7614 IF p_lpn_context = 3 THEN
7615
7616 IF p_from_lpn_id = p_to_lpn_id THEN
7617 l_to_lpn_id := NULL;
7618 ELSE
7619 l_to_lpn_id := p_to_lpn_id;
7620 END IF;
7621
7622 inv_rcv_integration_apis.insert_wlpni(
7623 p_api_version => 1.0
7624 ,x_return_status => x_return_status
7625 ,x_msg_count => x_msg_count
7626 ,x_msg_data => x_msg_data
7627 ,p_organization_id => p_organization_id
7628 ,p_lpn_id => p_from_lpn_id
7629 ,p_license_plate_number => NULL
7630 ,p_lpn_group_id => l_group_id
7631 ,p_parent_lpn_id => l_to_lpn_id);
7632
7633 END IF;
7634 END IF;
7635
7636 -- If p_lpn_mode is transfer all contents then do the following.
7637 IF p_lpn_mode = 1 THEN
7638
7639 OPEN lpn_cursor;
7640 LOOP
7641 FETCH lpn_cursor INTO l_lpn_id;
7642 EXIT WHEN lpn_cursor%NOTFOUND;
7643
7644 --UnPack child LPNs from the ginve LPN Resides in inventory
7645 IF p_lpn_context = 1 THEN
7646
7647 IF(l_debug =1) THEN
7648 debug('Inventory LPN, Parent lpn is not null, Unpack '||l_lpn_id|| ' from ' ||p_from_lpn_id);
7649 END IF;
7650
7651 PackUnpack_LPN(
7652 p_from_lpn_id => p_from_lpn_id
7653 , p_to_lpn_id => l_lpn_id --BUG 3544918
7654 , p_org_id => p_organization_id
7655 , p_sub_code => l_lpn_sub
7656 , p_loc_id => l_lpn_loc
7657 , p_user_id => p_user_id
7658 , p_project_id => p_project_id
7659 , p_task_id => p_task_id
7660 , p_trx_header_id => p_pack_trans_id
7661 , p_mode => 2
7662 , p_batch_id => p_batch_id
7663 , p_batch_seq => l_batch_seq
7664 , x_return_status => x_return_status
7665 , x_msg_count => x_msg_count
7666 , x_msg_data => x_msg_data);
7667
7668 -- Check return value and in case of failure raise exception
7669 IF (l_ret <> 0) THEN
7670 IF l_debug = 1 THEN
7671 debug('TM call for pack unpack faluire');
7672 debug('Failure message ' || x_msg_data);
7673 END IF;
7674 FND_MESSAGE.SET_NAME('WMS','WMS_LOG_EXCEPTION_FAIL');
7675 RAISE FND_API.G_EXC_ERROR;
7676 END IF; -- if l_ret<> 0
7677
7678 l_batch_seq := l_batch_seq + 1;
7679
7680 -- If the lpn context is resides in WIP and transaction mode is transfer all
7681 -- contents, then unpack each child LPN lpn from its parent
7682 ELSIF p_lpn_context = 2 THEN
7683
7684 IF(l_debug = 1) THEN
7685 debug('WIP LPN, Parent lpn is not null, Unpack '||l_lpn_id||' from ' ||p_from_lpn_id);
7686 END IF;
7687
7688 wms_container_pvt.packunpack_container
7689 (p_api_version => 1.0
7690 ,p_content_lpn_id => l_lpn_id -- child LPN ID
7691 ,p_lpn_id => p_from_lpn_id -- Parent LPN ID
7692 ,p_operation => 2 -- Unpack
7693 ,p_organization_id => p_organization_id
7694 ,p_commit => fnd_api.g_false
7695 ,x_return_status => x_return_status
7696 ,x_msg_count => x_msg_count
7697 ,x_msg_data => x_msg_data);
7698
7699 ELSIF p_lpn_context = 3 THEN
7700
7701 -- Resides in Receving LPN, Unpack all child LPNs from their parents.
7702 inv_rcv_integration_apis.insert_wlpni(
7703 p_api_version => 1.0
7704 ,x_return_status => x_return_status
7705 ,x_msg_count => x_msg_count
7706 ,x_msg_data => x_msg_data
7707 ,p_organization_id => p_organization_id
7708 ,p_lpn_id => l_lpn_id
7709 ,p_license_plate_number => NULL
7710 ,p_lpn_group_id => l_group_id
7711 ,p_parent_lpn_id => p_to_lpn_id);
7712 END IF; -- If lpn context =1
7713 END LOOP;
7714
7715 IF lpn_cursor%isopen THEN
7716 CLOSE lpn_cursor;
7717 END IF;
7718
7719 x_batch_seq := l_batch_seq;
7720 END IF;
7721
7722
7723 EXCEPTION
7724
7725 WHEN OTHERS THEN
7726 x_return_status := fnd_api.g_ret_sts_unexp_error;
7727 debug(SQLCODE, 1);
7728
7729 IF lpn_cursor%isopen THEN
7730 CLOSE lpn_cursor;
7731 END IF;
7732
7733 IF SQLCODE IS NOT NULL THEN
7734 l_progress := 100;
7735 inv_mobile_helper_functions.sql_error('pre_process_lpn', l_progress, SQLCODE);
7736 END IF;
7737
7738 END pre_process_lpn;
7739
7740 PROCEDURE post_process_lpn (
7741 x_return_status OUT NOCOPY VARCHAR2
7742 , x_msg_count OUT NOCOPY NUMBER
7743 , x_msg_data OUT NOCOPY VARCHAR2
7744 , p_from_lpn_id IN NUMBER
7745 , p_organization_id IN NUMBER
7746 , p_subinventory_code IN VARCHAR2
7747 , p_lpn_mode IN VARCHAR2
7748 , p_locator_id IN NUMBER
7749 , p_to_lpn_id IN NUMBER
7750 , p_project_id IN NUMBER DEFAULT NULL
7751 , p_task_id IN NUMBER DEFAULT NULL
7752 , p_user_id IN NUMBER
7753 , p_lpn_context IN NUMBER
7754 , p_pack_trans_id IN NUMBER
7755 , p_batch_id IN NUMBER
7756 , p_batch_seq IN NUMBER
7757 ) IS
7758 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
7759 l_group_id NUMBER;
7760 l_progress NUMBER;
7761 l_ret NUMBER;
7762 l_lpn_id NUMBER;
7763
7764 CURSOR lpn_cursor IS
7765 SELECT lpn_id
7766 FROM wms_license_plate_numbers
7767 WHERE parent_lpn_id = p_from_lpn_id;
7768
7769 l_batch_seq NUMBER := p_batch_seq; --BUG 3544918
7770 BEGIN
7771
7772 l_progress := 10;
7773
7774 x_return_status := fnd_api.g_ret_sts_success;
7775
7776 IF (l_debug = 1) THEN
7777 debug('Post_Process_lpn : Patchset J code - Nested LPNs are supported');
7778 END IF;
7779
7780
7781 -- Drop entire LPN
7782 IF(p_lpn_mode = 2 ) THEN
7783
7784 IF (p_lpn_context = 1 OR p_lpn_context = 2) AND (p_to_lpn_id IS NOT NULL) AND
7785 (p_to_lpn_id <> p_from_lpn_id) AND (p_to_lpn_id <> 0) THEN
7786
7787 IF (l_debug = 1) THEN
7788 debug('Inventory/WP LPN, To lpn is not null, Pack '||p_from_lpn_id|| ' Into ' ||p_to_lpn_id);
7789 END IF;
7790
7791 PackUnpack_LPN(
7792 p_from_lpn_id => p_from_lpn_id
7793 , p_to_lpn_id => p_to_lpn_id
7794 , p_org_id => p_organization_id
7795 , p_sub_code => p_subinventory_code
7796 , p_loc_id => p_locator_id
7797 , p_user_id => p_user_id
7798 , p_project_id => p_project_id
7799 , p_task_id => p_task_id
7800 , p_trx_header_id => p_pack_trans_id
7801 , p_mode => 1 -- Pack
7802 , p_batch_id => p_batch_id
7803 , p_batch_seq => l_batch_seq
7804 , x_return_status => x_return_status
7805 , x_msg_count => x_msg_count
7806 , x_msg_data => x_msg_data);
7807
7808 END IF;
7809 END IF;
7810
7811 -- Transfer All contents
7812 IF p_lpn_mode = 1 THEN
7813
7814 OPEN lpn_cursor;
7815 LOOP
7816 FETCH lpn_cursor INTO l_lpn_id;
7817 EXIT WHEN lpn_cursor%NOTFOUND;
7818
7819 IF (p_lpn_context = 1 OR p_lpn_context = 2) AND (p_to_lpn_id IS NOT NULL) AND
7820 (p_to_lpn_id <> p_from_lpn_id) AND (p_to_lpn_id <> 0) THEN
7821
7822 IF (l_debug = 1) THEN
7823 debug('Inventory/WP LPN, To lpn is not null, Pack '||l_lpn_id || ' Into ' ||p_to_lpn_id);
7824 END IF;
7825
7826 PackUnpack_LPN(
7827 p_from_lpn_id => l_lpn_id
7828 , p_to_lpn_id => p_to_lpn_id
7829 , p_org_id => p_organization_id
7830 , p_sub_code => p_subinventory_code
7831 , p_loc_id => p_locator_id
7832 , p_user_id => p_user_id
7833 , p_project_id => p_project_id
7834 , p_task_id => p_task_id
7835 , p_trx_header_id => p_pack_trans_id
7836 , p_mode => 1 -- Pack
7837 , p_batch_id => p_batch_id
7838 , p_batch_seq => l_batch_seq
7839 , x_return_status => x_return_status
7840 , x_msg_count => x_msg_count
7841 , x_msg_data => x_msg_data);
7842 l_batch_seq := l_batch_seq + 1;
7843 END IF;
7844 END LOOP;
7845
7846 END IF;
7847
7848 IF lpn_cursor%isopen THEN
7849 CLOSE lpn_cursor;
7850 END IF;
7851
7852
7853 EXCEPTION
7854
7855 WHEN OTHERS THEN
7856 x_return_status := fnd_api.g_ret_sts_unexp_error;
7857 debug(SQLCODE, 1);
7858
7859 IF lpn_cursor%isopen THEN
7860 CLOSE lpn_cursor;
7861 END IF;
7862
7863 IF SQLCODE IS NOT NULL THEN
7864 l_progress := 100;
7865 inv_mobile_helper_functions.sql_error('post_process_lpn', l_progress, SQLCODE);
7866 END IF;
7867
7868 END post_process_lpn;
7869
7870 PROCEDURE transfer_contents
7871 (
7872 p_org_id IN NUMBER DEFAULT NULL
7873 , p_sub_code IN VARCHAR2 DEFAULT NULL
7874 , p_loc_id IN NUMBER DEFAULT NULL
7875 , p_from_lpn_id IN NUMBER
7876 , p_into_lpn_id IN NUMBER
7877 , p_operation IN VARCHAR2
7878 , p_mode IN NUMBER
7879 , p_user_id IN NUMBER
7880 , p_eqp_ins IN VARCHAR2
7881 , p_project_id IN NUMBER DEFAULT NULL
7882 , p_task_id IN NUMBER DEFAULT NULL
7883 , x_return_status OUT NOCOPY VARCHAR2
7884 , x_msg_count OUT NOCOPY NUMBER
7885 , x_msg_data OUT NOCOPY VARCHAR2 )
7886 IS
7887 TYPE number_tb_tp IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
7888 TYPE varchar30_tb_tp IS TABLE OF VARCHAR2(30) INDEX BY BINARY_INTEGER;
7889 l_from_context NUMBER;
7890 l_into_context NUMBER;
7891 l_is_loaded VARCHAR2(1);
7892 l_number_of_rows NUMBER;
7893 l_crossdock VARCHAR2(1); --??
7894 l_count NUMBER;
7895 l_org_id NUMBER;
7896 l_lpn_ids number_tb_tp;
7897 l_serial_numbers varchar30_tb_tp;
7898 l_txn_tmp_id_tb number_tb_tp;
7899 l_txn_tmp_id NUMBER;
7900 l_hdr_id NUMBER;
7901 l_sub_code VARCHAR2(10);
7902 l_loc_id NUMBER;
7903 l_to_sub VARCHAR2(10);
7904 l_to_loc NUMBER;
7905 l_ser_trx_id NUMBER;
7906 l_return_status NUMBER;
7907 l_task_execute_rec wms_dispatched_tasks%ROWTYPE;
7908 l_debug number := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
7909 l_progress VARCHAR2(10) := '0';
7910 l_user_id NUMBER;
7911 l_emp_id NUMBER;
7912 l_error_code NUMBER;
7913 l_message VARCHAR2(1);
7914 l_prim_qty NUMBER;
7915 l_loose_contents NUMBER := 0;
7916 l_old_txn_mode_code VARCHAR2(10);
7917 l_inspection_flag NUMBER;
7918 l_load_flag NUMBER;
7919 l_drop_flag NUMBER;
7920 l_load_prim_quantity NUMBER;
7921 l_inspect_prim_quantity NUMBER;
7922 l_drop_prim_quantity NUMBER;
7923 l_sub_loc_changed VARCHAR2(1);
7924 l_batch_seq NUMBER := 1;
7925 l_uom VARCHAR2(5);
7926
7927 l_consolidation_method_id NUMBER;
7928 l_drop_lpn_option NUMBER;
7929
7930 CURSOR wlpnc_cur IS
7931 SELECT
7932 wlpnc.inventory_item_id
7933 ,wlpnc.organization_id
7934 ,wlpnc.revision
7935 ,wlpnc.lot_number
7936 ,wlpnc.quantity
7937 ,wlpnc.uom_code
7938 ,msi.serial_number_control_code
7939 ,msi.primary_uom_code
7940 FROM
7941 wms_lpn_contents wlpnc, mtl_system_items msi
7942 WHERE
7943 wlpnc.parent_lpn_id = p_from_lpn_id
7944 AND wlpnc.inventory_item_id = msi.inventory_item_id
7945 AND wlpnc.organization_id = msi.organization_id;
7946
7947 l_msg_count NUMBER;
7948 l_msg_data VARCHAR2(10000);
7949
7950 BEGIN
7951 IF (l_debug = 0) THEN
7952 DEBUG('Entering transfer_contents.pls', 'transfer_contents', 9);
7953 DEBUG(' ( p_from_lpn_id => ' || p_from_lpn_id,'transfer_contents',9);
7954 DEBUG(' ,p_into_lpn_id=> ' || p_into_lpn_id,'transfer_contents',9);
7955 DEBUG(' ,p_org_id => ' || p_org_id,'transfer_contents',9);
7956 DEBUG(' ,p_operation => ' || p_operation,'transfer_contents',9);
7957 DEBUG(' ,p_mode => ' || p_mode,'transfer_contents',9);
7958 DEBUG(' ,p_user_id => ' || p_user_id,'transfer_contents',9);
7959 DEBUG(' ,p_eqp_ins => ' || p_eqp_ins || ')','transfer_contents',9);
7960 END IF;
7961 -- ignore operation/mode.
7962 -- assume 'XFER_CONTENTS' and 'LOAD' for now
7963
7964 SAVEPOINT transfer_contents_pub;
7965
7966 l_progress := '3';
7967
7968 IF (p_user_id IS NULL) THEN
7969 l_user_id := fnd_global.user_id;
7970 ELSE
7971 l_user_id := p_user_id;
7972 END IF;
7973
7974 l_progress := '5';
7975 BEGIN
7976 SELECT employee_id
7977 INTO l_emp_id
7978 FROM fnd_user
7979 WHERE user_id = l_user_id;
7980 EXCEPTION
7981 WHEN OTHERS THEN
7982 IF (l_debug = 1) THEN
7983 DEBUG('There is no employee id tied to the user','transfer_contents',9);
7984 END IF;
7985 fnd_message.set_name('WMS', 'WMS_NO_EMP_FOR_USR');
7986 fnd_msg_pub.ADD;
7987 RAISE fnd_api.g_exc_error;
7988 END;
7989
7990 l_progress := '7';
7991
7992 BEGIN
7993 SELECT
7994 lpn_context from_context
7995 ,organization_id organization_id
7996 ,subinventory_code
7997 ,locator_id
7998 INTO
7999 l_from_context
8000 ,l_org_id
8001 ,l_sub_code
8002 ,l_loc_id
8003 FROM
8004 wms_license_plate_numbers
8005 WHERE
8006 lpn_id = p_from_lpn_id;
8007 EXCEPTION
8008 WHEN OTHERS THEN
8009 IF (l_debug = 1) THEN
8010 DEBUG('from LPN not found in WMS_LICENSE_PLATE_NUMBERS',
8011 'transfer_contents',9);
8012 END IF;
8013 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
8014 fnd_msg_pub.ADD;
8015 RAISE fnd_api.g_exc_error;
8016 END;
8017
8018 l_progress := '9';
8019
8020 BEGIN
8021 SELECT
8022 lpn_context
8023 ,subinventory_code
8024 ,locator_id
8025 INTO
8026 l_into_context
8027 ,l_to_sub
8028 ,l_to_loc
8029 FROM
8030 wms_license_plate_numbers
8031 WHERE
8032 lpn_id = p_into_lpn_id;
8033 EXCEPTION
8034 WHEN OTHERS THEN
8035 IF (l_debug = 1) THEN
8036 DEBUG('INTO LPN not found in WMS_LICENSE_PLATE_NUMBERS',
8037 'transfer_contents',9);
8038 END IF;
8039 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN');
8040 fnd_msg_pub.ADD;
8041 RAISE fnd_api.g_exc_error;
8042 END;
8043
8044 -- Set variable if sub/loc of toLPN is different from that of from LPN
8045 IF (Nvl(p_into_lpn_id,0) <> 0
8046 AND l_into_context IN (1,2,3) -- No need to call TM if DFBU LPN
8047 AND (Nvl(l_to_sub,'@@@') <> Nvl(p_sub_code,'@@@')
8048 OR Nvl(l_to_loc,-1) <> Nvl(p_loc_id,-1))) THEN
8049 l_sub_loc_changed := 'Y';
8050 ELSE
8051 l_sub_loc_changed := 'N';
8052 END IF;
8053
8054 l_progress := '10';
8055 IF (l_debug = 1) THEN
8056 DEBUG('from_content = ' || l_from_context ||
8057 ' into_context = ' || l_into_context ||
8058 ' from_sub_code = ' || l_sub_code ||
8059 ' from_loc_id = ' || l_loc_id
8060 || ' l_to_sub = '||l_to_sub ||
8061 ' l_to_loc = ' || l_to_loc ||
8062 ' l_sub_loc_changed = ' || l_sub_loc_changed
8063 ,'transfer_contents', 9);
8064 END IF;
8065
8066 -- From LPN must be either in receiving, inventory, or WIP
8067 IF (l_from_context NOT IN (1, 2, 3)) THEN
8068 IF (l_debug = 1) THEN
8069 DEBUG('Invalid context for from_lpn_id',
8070 'transfer_contents', 9);
8071 END IF;
8072 fnd_message.set_name('WMS', 'WMS_CONT_INVALID_LPN_CONTEXT');
8073 fnd_msg_pub.ADD;
8074 RAISE fnd_api.g_exc_error;
8075 END IF;
8076
8077 l_progress := '30';
8078
8079 IF (l_debug = 1) THEN
8080 DEBUG('Calling suggestions_pub_wrapper','transfer_contents',9);
8081 DEBUG(' (p_lpn_id => ' || p_from_lpn_id,'transfer_contents',9);
8082 DEBUG(' ,p_org_id => ' || l_org_id,'transfer_contents',9);
8083 DEBUG(' ,p_user_id => ' || l_user_id,'transfer_contents',9);
8084 DEBUG(' ,p_eqp_ins => ' || p_eqp_ins || ')','transfer_contents',9);
8085 END IF;
8086
8087 wms_putaway_utils.suggestions_pub_wrapper
8088 (p_lpn_id => p_from_lpn_id
8089 ,p_org_id => l_org_id
8090 ,p_user_id => l_user_id
8091 ,p_eqp_ins => p_eqp_ins
8092 ,x_number_of_rows => l_number_of_rows
8093 ,x_return_status => x_return_status
8094 ,x_msg_count => x_msg_count
8095 ,x_msg_data => x_msg_data
8096 ,x_crossdock => l_crossdock
8097 );
8098
8099 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8100 IF (l_debug = 1) THEN
8101 DEBUG('Error in suggestions_pub_wrapper','transfer_contents',9);
8102 END IF;
8103 RAISE fnd_api.g_exc_error;
8104 END IF;
8105
8106 l_progress := '40';
8107
8108 IF (l_debug = 1) THEN
8109 DEBUG('Suggestions_pub_wrapper returns sucessfully','transfer_contents',9);
8110 END IF;
8111
8112
8113 --BUG 4345714: Change the way quantities is validated from 11.5.10
8114 BEGIN
8115 SELECT /*+ ORDERED INDEX(MTRL MTL_TXN_REQUEST_LINES_N7) */ 1
8116 INTO l_count
8117 FROM mtl_txn_request_lines mtrl ,
8118 (SELECT wlpn.lpn_id /*5723418*/
8119 FROM wms_license_plate_numbers wlpn
8120 START WITH wlpn.lpn_id = p_from_lpn_id
8121 CONNECT BY PRIOR wlpn.lpn_id = wlpn.parent_lpn_id ) wlpn
8122 WHERE mtrl.lpn_id = wlpn.lpn_id
8123 AND mtrl.line_status = 7
8124 AND (mtrl.quantity-Nvl(mtrl.quantity_delivered,0)) <> Nvl(mtrl.quantity_detailed,0)
8125 AND mtrl.organization_id = l_org_id;
8126 EXCEPTION
8127 WHEN too_many_rows THEN
8128 l_count := 1;
8129 WHEN no_data_found THEN
8130 l_count := 0;
8131 WHEN OTHERS THEN
8132 l_count := 0;
8133 END;
8134
8135
8136 l_progress := '50';
8137
8138 IF (l_count > 0) THEN
8139 fnd_msg_pub.count_and_get(p_count => l_msg_count, p_data =>
8140 l_msg_data);
8141 IF l_debug = 1 THEN
8142 debug('l_msg_count: ' || l_msg_count);
8143 debug('l_msg_data: ' || l_msg_data);
8144 END IF;
8145
8146 IF (l_msg_count IS NULL OR l_msg_count = 0) THEN
8147 -- use default message if there are no message on stack
8148 -- first reset message stack
8149 fnd_msg_pub.initialize();
8150 FND_MESSAGE.SET_NAME('WMS','WMS_ALLOCATE_FAIL');
8151 FND_MSG_PUB.ADD;
8152 ELSIF l_msg_count > 1 THEN
8153 FOR i IN 2 .. l_msg_count LOOP
8154 fnd_msg_pub.delete_msg(i);
8155 END LOOP;
8156 END IF;
8157 RAISE fnd_api.g_exc_error;
8158 END IF;
8159
8160 l_progress := '60';
8161
8162 -- Retrieve all the suggestion MMTT
8163 IF (l_from_context = 3) THEN
8164 -- Retrieve all the suggestion MMTT
8165 -- Distinguish from other dummy ones
8166 BEGIN
8167 -- Bug 5231114: Added the condition on transaction_source_type_id and
8168 -- transaction_action_id for the following combinations:13/12 and 4/27
8169 SELECT
8170 mmtt.transaction_temp_id
8171 BULK COLLECT INTO
8172 l_txn_tmp_id_tb
8173 FROM mtl_material_transactions_temp mmtt
8174 WHERE -- suggestion mmtts?
8175 ( ( mmtt.transaction_source_type_id = 1 AND
8176 mmtt.transaction_action_id = 27) OR
8177 ( mmtt.transaction_source_type_id = 7 AND
8178 mmtt.transaction_action_id = 12) OR
8179 ( mmtt.transaction_source_type_id = 12 AND
8180 mmtt.transaction_action_id = 27) OR
8181 ( mmtt.transaction_source_type_id = 13 AND
8182 mmtt.transaction_action_id = 12) OR
8183 ( mmtt.transaction_source_type_id = 4 AND
8184 mmtt.transaction_action_id = 27)) AND
8185 mmtt.organization_id = l_org_id AND
8186 mmtt.move_order_line_id --BUG 3435079: use org_id for performace reason
8187 IN ( SELECT mtrl.line_id
8188 FROM mtl_txn_request_lines mtrl,
8189 ( SELECT wlpn.lpn_id /*5723418*/
8190 FROM wms_license_plate_numbers wlpn
8191 START WITH wlpn.lpn_id = p_from_lpn_id
8192 CONNECT BY PRIOR wlpn.lpn_id = wlpn.parent_lpn_id ) wlpn
8193 WHERE mtrl.organization_id = l_org_id
8194 --BUG 3435079: use org_id for performace reason
8195 AND mtrl.lpn_id = wlpn.lpn_id );
8196
8197 EXCEPTION
8198 WHEN OTHERS THEN
8199 IF (l_debug = 1 ) THEN
8200 DEBUG('Unexpected Exception Raised in Bulk Select'
8201 ,'transfer_contents', 9);
8202 END IF;
8203 RAISE fnd_api.g_exc_error;
8204 END;
8205
8206 IF (l_debug = 1) THEN
8207 debug('# of MMTT returned: '||l_txn_tmp_id_tb.COUNT,'transfer_contents',9);
8208 END IF;
8209
8210 IF (l_txn_tmp_id_tb.COUNT = 0) THEN
8211 IF (l_debug = 1) THEN
8212 debug('No MMTT returned!','transfer_contents',9);
8213 END IF;
8214 FND_MESSAGE.SET_NAME('WMS','WMS_ALLOCATE_FAIL');
8215 FND_MSG_PUB.ADD;
8216 RAISE fnd_api.g_exc_error;
8217 END IF;
8218 ELSE
8219 -- For inventory and wip, just query based on move_order_line_id
8220 BEGIN
8221 SELECT
8222 mmtt.transaction_temp_id
8223 BULK COLLECT INTO
8224 l_txn_tmp_id_tb
8225 FROM mtl_material_transactions_temp mmtt
8226 WHERE -- suggestion mmtts?
8227 mmtt.organization_id = l_org_id AND
8228 mmtt.move_order_line_id --BUG 3435079: use org_id for performace reason
8229 IN ( SELECT mtrl.line_id
8230 FROM mtl_txn_request_lines mtrl ,
8231 (SELECT wlpn.lpn_id /*5723418*/
8232 FROM wms_license_plate_numbers wlpn
8233 START WITH wlpn.lpn_id = p_from_lpn_id
8234 CONNECT BY PRIOR wlpn.lpn_id = wlpn.parent_lpn_id ) wlpn
8235 WHERE mtrl.organization_id = l_org_id AND --BUG 3435079: use org_id for performace reason
8236 mtrl.lpn_id = wlpn.lpn_id );
8237 EXCEPTION
8238 WHEN OTHERS THEN
8239 IF (l_debug = 1 ) THEN
8240 DEBUG('Unexpected Exception Raised in Bulk Select'
8241 ,'transfer_contents', 9);
8242 END IF;
8243 RAISE fnd_api.g_exc_error;
8244 END;
8245 END IF; -- IF (l_from_context = 3)
8246
8247 l_progress := '70';
8248
8249 l_task_execute_rec.person_id := l_emp_id;
8250 l_task_execute_rec.organization_id := l_org_id;
8251 l_task_execute_rec.loaded_time := Sysdate;
8252 l_task_execute_rec.user_task_type := -1;
8253
8254 -- Activate each MMTT's
8255 FOR i IN 1 .. l_txn_tmp_id_tb.COUNT LOOP
8256 l_progress := '73';
8257
8258 wms_atf_runtime_pub_apis.validate_operation
8259 (x_return_status => x_return_status
8260 ,x_msg_data => x_msg_data
8261 ,x_msg_count => x_msg_count
8262 ,x_error_code => l_error_code
8263 ,x_inspection_flag => l_inspection_flag
8264 ,x_load_flag => l_load_flag
8265 ,x_drop_flag => l_drop_flag
8266 ,x_load_prim_quantity => l_load_prim_quantity
8267 ,x_drop_prim_quantity => l_drop_prim_quantity
8268 ,x_inspect_prim_quantity => l_inspect_prim_quantity
8269 ,p_source_task_id => l_txn_tmp_id_tb(i)
8270 ,p_move_order_line_id => NULL
8271 ,p_inventory_item_id => NULL
8272 ,p_lpn_id => NULL
8273 ,p_activity_type_id => 1 -- INBOUND
8274 ,p_organization_id => l_org_id);
8275 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8276 IF (l_debug = 1) THEN
8277 debug('Validate_operation failed','transfer_contents',9);
8278 END IF;
8279 RAISE fnd_api.g_exc_error;
8280 END IF;
8281
8282 l_progress := '75';
8283
8284 IF (l_load_flag <> 3) THEN
8285 debug('MMTT:'||l_txn_tmp_id_tb(i)||' not full loaded','transfer_contents',9);
8286 RAISE fnd_api.g_exc_error;
8287 END IF;
8288
8289 l_progress := '77';
8290
8291 IF (l_debug = 1) THEN
8292 DEBUG('Calling activate_operation_instance','transfer_contents',9);
8293 DEBUG(' ( p_source_task_id => ' || l_txn_tmp_id_tb(i),'transfer_contents',9);
8294 DEBUG(' ,p_activity_type_id => 1','transfer_contents',9);
8295 DEBUG(' ,p_task_execute_rec => l_task_execute_rec','transfer_contents',9);
8296 DEBUG(' ,p_operation_type_id => 1 )','transfer_contents',9);
8297 END IF;
8298
8299 wms_atf_runtime_pub_apis.activate_operation_instance
8300 ( p_source_task_id => l_txn_tmp_id_tb(i)
8301 ,p_activity_id => 1 -- Inbound
8302 ,p_task_execute_rec => l_task_execute_rec
8303 ,p_operation_type_id => 1 -- load
8304 ,x_return_status => x_return_status
8305 ,x_msg_data => x_msg_data
8306 ,x_msg_count => x_msg_count
8307 ,x_error_code => l_error_code
8308 ,x_consolidation_method_id => l_consolidation_method_id
8309 ,x_drop_lpn_option => l_drop_lpn_option
8310 );
8311 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8312 IF (l_debug = 1) THEN
8313 DEBUG('xxx: Error in activate_operation_instance','transfer_contents',9);
8314 END IF;
8315 RAISE fnd_api.g_exc_error;
8316 END IF;
8317 END LOOP;
8318
8319 l_progress := '80';
8320
8321 IF (l_from_context = 3) THEN -- resides in receiving
8322 IF (l_debug = 1) THEN
8323 DEBUG('xxx: l_from_context = ' || l_from_context
8324 || '. Resides in receiving','transfer_contents',9);
8325 END IF;
8326
8327 l_progress := '90';
8328
8329 BEGIN
8330 SELECT COUNT(lpn_content_id)
8331 INTO l_count
8332 FROM wms_lpn_contents
8333 WHERE parent_lpn_id = p_from_lpn_id;
8334 EXCEPTION
8335 WHEN no_data_found THEN
8336 l_count := 0;
8337 END;
8338
8339 l_progress := '100';
8340
8341 --loose item exists or the into lpn sub/loc is different than
8342 -- that of the from lpn
8343 IF (l_count > 0 OR l_sub_loc_changed = 'Y') THEN
8344 IF (l_debug = 1) THEN
8345 DEBUG('xxx: There are ' || l_count ||
8346 ' entries of wlpnc. Inserting rti...','transfer_contents',9);
8347 DEBUG(' (p_from_org => ' || l_org_id,'transfer_contents',9);
8348 DEBUG(' p_to_org => ' || l_org_id,'transfer_contents',9);
8349 DEBUG(' p_to_sub => ' || l_sub_code,'transfer_contents',9);
8350 DEBUG(' p_to_loc => ' || l_loc_id,'transfer_contents',9);
8351 DEBUG(' p_lpn_id => ' || p_from_lpn_id,'transfer_contents',9);
8352 DEBUG(' p_xfer_lpn_id => ' || p_into_lpn_id,'transfer_contents',9);
8353 END IF;
8354
8355 l_progress := '110';
8356
8357 IF (l_sub_loc_changed = 'Y') THEN
8358 l_return_status := insert_rti
8359 (p_from_org => l_org_id
8360 ,p_lpn_id => p_from_lpn_id
8361 ,p_to_org => l_org_id
8362 ,p_to_sub => l_to_sub
8363 ,p_to_loc => l_to_loc
8364 ,p_xfer_lpn_id => p_into_lpn_id
8365 ,p_first_time => 1
8366 ,p_mobile_txn => 'Y'
8367 ,p_txn_mode_code => 'ONLINE'
8368 ,x_return_status => x_return_status
8369 ,x_msg_count => x_msg_count
8370 ,x_msg_data => x_msg_data
8371 );
8372 ELSE -- If no sub/loc changed, then into LPN must be DFBU
8373 -- So pass in sub/loc of the from LPN
8374 l_return_status := insert_rti
8375 (p_from_org => l_org_id
8376 ,p_lpn_id => p_from_lpn_id
8377 ,p_to_org => l_org_id
8378 ,p_to_sub => l_sub_code
8379 ,p_to_loc => l_loc_id
8380 ,p_xfer_lpn_id => p_into_lpn_id
8381 ,p_first_time => 1
8382 ,p_mobile_txn => 'Y'
8383 ,p_txn_mode_code => 'ONLINE'
8384 ,x_return_status => x_return_status
8385 ,x_msg_count => x_msg_count
8386 ,x_msg_data => x_msg_data
8387 );
8388 END IF; -- IF (l_sub_loc_changed = 'Y') THEN
8389
8390 IF (x_return_status <> fnd_api.g_ret_sts_success OR l_return_status = -1) THEN
8391 IF (l_debug = 1) THEN
8392 DEBUG('xxx: Error inserting_rti','transfer_contents',9);
8393 END IF;
8394 RAISE fnd_api.g_exc_error;
8395 END IF;
8396
8397 l_progress := '120';
8398
8399 -- Update WMS_PROCESS_FLAG of MOL to 2
8400 BEGIN
8401 UPDATE
8402 mtl_txn_request_lines
8403 SET
8404 wms_process_flag = 2
8405 WHERE
8406 lpn_id IN (SELECT wlpn.lpn_id
8407 FROM wms_license_plate_numbers wlpn
8408 START WITH wlpn.lpn_id = p_from_lpn_id
8409 CONNECT BY PRIOR wlpn.lpn_id =
8410 wlpn.parent_lpn_id);
8411 EXCEPTION
8412 WHEN OTHERS THEN
8413 IF (l_debug = 1 ) THEN
8414 debug('Error updating MOL statuses','transfer_contents',9);
8415 END IF;
8416 END;
8417
8418 --call rcv tm
8419 l_progress := '130';
8420 IF (l_debug = 1) THEN
8421 DEBUG('xxx: Calling rcv_process_receive_txn','transfer_contents',9);
8422 END IF;
8423
8424 l_old_txn_mode_code := inv_rcv_common_apis.g_po_startup_value.transaction_mode;
8425 inv_rcv_common_apis.g_po_startup_value.transaction_mode := 'ONLINE';
8426
8427 l_progress := '135';
8428
8429 BEGIN
8430 inv_rcv_mobile_process_txn.rcv_process_receive_txn
8431 (x_return_status => x_return_status
8432 ,x_msg_data => x_msg_data
8433 );
8434 EXCEPTION
8435 WHEN OTHERS THEN
8436 inv_rcv_common_apis.g_po_startup_value.transaction_mode := l_old_txn_mode_code;
8437 IF (l_debug = 1) THEN
8438 DEBUG('xxx: Error - Rcv TM Failed','transfer_contents',9);
8439 END IF;
8440 RAISE fnd_api.g_exc_error;
8441 END;
8442
8443 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8444 IF (l_debug = 1) THEN
8445 DEBUG('xxx: Error - Rcv TM Failed','transfer_contents',9);
8446 END IF;
8447 inv_rcv_common_apis.g_po_startup_value.transaction_mode := l_old_txn_mode_code;
8448 RAISE fnd_api.g_exc_error;
8449 END IF;
8450
8451 l_progress := '140';
8452
8453 inv_rcv_common_apis.g_po_startup_value.transaction_mode := l_old_txn_mode_code;
8454 inv_rcv_common_apis.rcv_clear_global;
8455
8456 ELSE -- No loose items and no sub/loc change
8457 IF (l_debug = 1) THEN
8458 DEBUG('xxx: No loose items exist','transfer_contents',9);
8459 END IF;
8460
8461 l_progress := '150';
8462
8463 BEGIN
8464 SELECT lpn_id
8465 bulk collect INTO l_lpn_ids
8466 FROM wms_license_plate_numbers
8467 WHERE parent_lpn_id = p_from_lpn_id;
8468 EXCEPTION
8469 WHEN OTHERS THEN
8470 IF (l_debug = 1) THEN
8471 DEBUG('xxx: Error getting nested lpns','transfer_contents',9);
8472 END IF;
8473 END;
8474
8475 l_progress := '160';
8476
8477 -- Call packunpack on each inner LPN
8478 FOR i IN 1 .. l_lpn_ids.COUNT LOOP
8479 wms_container_pvt.packunpack_container
8480 (p_api_version => 1.0
8481 ,p_content_lpn_id => l_lpn_ids(i)
8482 ,p_lpn_id => p_from_lpn_id
8483 ,p_operation => 2 /* Unpack */
8484 ,p_organization_id => l_org_id
8485 ,x_return_status => x_return_status
8486 ,x_msg_count => x_msg_count
8487 ,x_msg_data => x_msg_data
8488 );
8489 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8490 IF (l_debug = 1) THEN
8491 DEBUG('xxx: Error unpacking content_lpn = ' ||
8492 l_lpn_ids(i) || ' from lpn = ' ||
8493 p_from_lpn_id,'transfer_contents',9);
8494 END IF;
8495 RAISE fnd_api.g_exc_error;
8496 END IF;
8497
8498 wms_container_pvt.packunpack_container
8499 (p_api_version => 1.0
8500 ,p_content_lpn_id => l_lpn_ids(i)
8501 ,p_lpn_id => p_into_lpn_Id
8502 ,p_operation => 1 /* Pack */
8503 ,p_organization_id => l_org_id
8504 ,x_return_status => x_return_status
8505 ,x_msg_count => x_msg_count
8506 ,x_msg_data => x_msg_data
8507 );
8508 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8509 IF (l_debug = 1) THEN
8510 DEBUG('xxx: Error packing content_lpn = ' ||
8511 l_lpn_ids(i) || ' into lpn = ' ||
8512 p_into_lpn_id,'transfer_contents',9);
8513 END IF;
8514 RAISE fnd_api.g_exc_error;
8515 END IF;
8516 END LOOP; -- end nested lpn loop
8517
8518 l_progress := '170';
8519
8520 -- At the end, update the intoLPN context into 3 (RCV)
8521 wms_container_pub.modify_lpn_wrapper
8522 ( p_api_version => 1.0
8523 ,x_return_status => x_return_status
8524 ,x_msg_count => x_msg_count
8525 ,x_msg_data => x_msg_data
8526 ,p_lpn_id => p_into_lpn_id
8527 ,p_lpn_context => 3 --RCV
8528 ,p_subinventory => l_sub_code -- same as from LPN
8529 ,p_locator_id => l_loc_id
8530 );
8531 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8532 IF (l_debug = 1) THEN
8533 debug('Error modifying lpn',
8534 'transfer_contents', 9);
8535 END IF;
8536 END IF;
8537
8538 -- Call complete operation instance
8539 FOR i IN 1 .. l_txn_tmp_id_tb.COUNT LOOP
8540 wms_atf_runtime_pub_apis.complete_operation_instance
8541 ( p_source_task_id => l_txn_tmp_id_tb(i)
8542 ,p_activity_id => 1 -- inbound
8543 ,p_operation_type_id => 1 -- load
8544 ,x_return_status => x_return_status
8545 ,x_msg_data => x_msg_data
8546 ,x_msg_count => x_msg_count
8547 ,x_error_code => l_error_code
8548 );
8549 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8550 IF (l_debug = 1) THEN
8551 DEBUG('xxx: Error in complete_operation_instance on '
8552 || ' MMTT = ' || l_txn_tmp_id_tb(i),'transfer_contents',9);
8553 END IF;
8554 RAISE fnd_api.g_exc_error;
8555 END IF;
8556
8557 END LOOP;
8558
8559 -- No need to update any MMTT/MOL, since there will none
8560 -- assoc with from_lpn
8561 END IF; -- end count > 0
8562 ELSIF (l_from_context = 2) THEN -- WIP LPN
8563
8564 l_progress := '180';
8565
8566 IF (l_debug = 1) THEN
8567 DEBUG('xxx: l_from_context = ' || l_from_context
8568 || '. Resides in WIP','transfer_contents',9);
8569 END IF;
8570
8571 -- Deal with loose item
8572 -- First deal with non-serial controlled items
8573 l_loose_contents := 0;
8574 FOR l_wlpnc_rec IN wlpnc_cur LOOP
8575 IF (l_loose_contents = 0) THEN
8576 l_loose_contents := 1;
8577 END IF;
8578 IF Nvl(l_wlpnc_rec.serial_number_control_code,1) IN (1, 6) THEN
8579 -- ??
8580 IF (l_debug = 1) THEN
8581 debug('calling pup on item:
8582 '||l_wlpnc_rec.inventory_item_id,
8583 'transfer_contents',9);
8584 END IF;
8585
8586 wms_container_pvt.packunpack_container
8587 (p_api_version => 1.0
8588 ,p_lpn_id => p_from_lpn_id
8589 ,p_operation => 2 -- UNPACK
8590 ,p_organization_id => l_org_id
8591 ,p_content_item_id => l_wlpnc_rec.inventory_item_id
8592 ,p_revision => l_wlpnc_rec.revision
8593 ,p_lot_number => l_wlpnc_rec.lot_number
8594 ,p_quantity => l_wlpnc_rec.quantity
8595 ,p_uom => l_wlpnc_rec.uom_code
8596 ,x_return_status => x_return_status
8597 ,x_msg_count => x_msg_count
8598 ,x_msg_data => x_msg_data
8599 );
8600 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8601 IF (l_debug = 1) THEN
8602 DEBUG('xxx: Error unpacking item_id = ' ||
8603 l_wlpnc_rec.inventory_item_id || ' from lpn = ' ||
8604 p_from_lpn_id,'transfer_contents',9);
8605 END IF;
8606 RAISE fnd_api.g_exc_error;
8607 END IF;
8608
8609 wms_container_pvt.packunpack_container
8610 (p_api_version => 1.0
8611 ,p_lpn_id => p_into_lpn_id
8612 ,p_operation => 1 -- PACK
8613 ,p_organization_id => l_org_id
8614 ,p_content_item_id => l_wlpnc_rec.inventory_item_id
8615 ,p_revision => l_wlpnc_rec.revision
8616 ,p_lot_number => l_wlpnc_rec.lot_number
8617 ,p_quantity => l_wlpnc_rec.quantity
8618 ,p_uom => l_wlpnc_rec.uom_code
8619 ,x_return_status => x_return_status
8620 ,x_msg_count => x_msg_count
8621 ,x_msg_data => x_msg_data
8622 );
8623 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8624 IF (l_debug = 1) THEN
8625 DEBUG('xxx: Error packing item_id = ' ||
8626 l_wlpnc_rec.inventory_item_id || ' from lpn = ' ||
8627 p_from_lpn_id,'transfer_contents',9);
8628 END IF;
8629 RAISE fnd_api.g_exc_error;
8630 END IF;
8631 ELSE -- If item is serial controlled
8632 -- Call packunpack on each serial number
8633 IF (l_serial_numbers.COUNT > 0) THEN
8634 l_serial_numbers.DELETE;
8635 END IF;
8636
8637 BEGIN
8638 SELECT serial_number
8639 bulk collect INTO l_serial_numbers
8640 FROM mtl_serial_numbers
8641 WHERE lpn_id = p_from_lpn_id
8642 AND inventory_item_id = l_wlpnc_rec.inventory_item_id
8643 AND Nvl(lot_number, '@@@') = Nvl(l_wlpnc_rec.lot_number, '@@@')
8644 AND Nvl(revision, '@@@') = Nvl(l_wlpnc_rec.revision,'@@@');
8645 EXCEPTION
8646 WHEN OTHERS THEN
8647 IF (l_debug = 1) THEN
8648 debug('Error retrieving entries from MTL_SERIAL_NUMBERS',
8649 'transfer_contents', 9);
8650 END IF;
8651 RAISE fnd_api.g_exc_error;
8652 END;
8653
8654 FOR i IN 1 .. l_serial_numbers.COUNT LOOP
8655 IF (l_debug = 1) THEN
8656 DEBUG('transfer_contents: unpacking serial number:'
8657 || l_serial_numbers(i),9);
8658 END IF;
8659 wms_container_pvt.packunpack_container
8660 (p_api_version => 1.0
8661 ,p_lpn_id => p_from_lpn_id
8662 ,p_operation => 2 -- UNPACK
8663 ,p_organization_id => l_org_id
8664 ,p_content_item_id => l_wlpnc_rec.inventory_item_id
8665 ,p_revision => l_wlpnc_rec.revision
8666 ,p_lot_number => l_wlpnc_rec.lot_number
8667 ,p_from_serial_number => l_serial_numbers(i)
8668 ,p_to_serial_number => l_serial_numbers(i)
8669 ,p_uom => l_wlpnc_rec.uom_code
8670 ,x_return_status => x_return_status
8671 ,x_msg_count => x_msg_count
8672 ,x_msg_data => x_msg_data
8673 );
8674 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8675 IF (l_debug = 1) THEN
8676 DEBUG('xxx: Error unpacking serial_number = ' ||
8677 l_serial_numbers(i) || ' from lpn = ' ||
8678 p_from_lpn_id,'transfer_contents',9);
8679 END IF;
8680 RAISE fnd_api.g_exc_error;
8681 END IF;
8682 wms_container_pvt.packunpack_container
8683 (p_api_version => 1.0
8684 ,p_lpn_id => p_into_lpn_id
8685 ,p_operation => 1 -- PACK
8686 ,p_organization_id => l_org_id
8687 ,p_content_item_id => l_wlpnc_rec.inventory_item_id
8688 ,p_revision => l_wlpnc_rec.revision
8689 ,p_lot_number => l_wlpnc_rec.lot_number
8690 ,p_from_serial_number => l_serial_numbers(i)
8691 ,p_to_serial_number => l_serial_numbers(i)
8692 ,p_uom => l_wlpnc_rec.uom_code
8693 ,x_return_status => x_return_status
8694 ,x_msg_count => x_msg_count
8695 ,x_msg_data => x_msg_data
8696 );
8697 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8698 IF (l_debug = 1) THEN
8699 DEBUG('xxx: Error packing serial_number = ' ||
8700 l_serial_numbers(i) || ' from lpn = ' ||
8701 p_from_lpn_id,'transfer_contents',9);
8702 END IF;
8703 RAISE fnd_api.g_exc_error;
8704 END IF;
8705 END LOOP; -- FOR i in 1 .. l_serial_numbers.COUNT LOOP
8706 END IF; -- IF Nvl(l_wlpnc_rec.serial_number_control_code,1) IN (1, 6) THEN
8707 END LOOP; --FOR l_wlpnc_rec IN wlpnc_cur LOOP
8708
8709 l_progress := '200';
8710
8711 -- Now deal with Nested LPN. For now, there should be none
8712 BEGIN
8713 SELECT lpn_id
8714 bulk collect INTO l_lpn_ids
8715 FROM wms_license_plate_numbers
8716 WHERE parent_lpn_id = p_from_lpn_id;
8717 EXCEPTION
8718 WHEN OTHERS THEN
8719 IF (l_debug = 1) THEN
8720 DEBUG('xxx: Error getting nested lpns','transfer_contents',9);
8721 END IF;
8722 END;
8723
8724 l_progress := '210';
8725
8726 FOR i IN 1 .. l_lpn_ids.COUNT LOOP
8727 wms_container_pvt.packunpack_container
8728 (p_api_version => 1.0
8729 ,p_content_lpn_id => l_lpn_ids(i)
8730 ,p_lpn_id => p_from_lpn_id
8731 ,p_operation => 2 /* Unpack */
8732 ,p_organization_id => l_org_id
8733 ,x_return_status => x_return_status
8734 ,x_msg_count => x_msg_count
8735 ,x_msg_data => x_msg_data
8736 );
8737 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8738 IF (l_debug = 1) THEN
8739 DEBUG('xxx: Error unpacking lpn = ' ||
8740 l_lpn_ids(i) || ' from lpn = ' ||
8741 p_from_lpn_id,'transfer_contents',9);
8742 END IF;
8743 RAISE fnd_api.g_exc_error;
8744 END IF;
8745 wms_container_pvt.packunpack_container
8746 (p_api_version => 1.0
8747 ,p_content_lpn_id => l_lpn_ids(i)
8748 ,p_lpn_id => p_into_lpn_Id
8749 ,p_operation => 1 /* Pack */
8750 ,p_organization_id => l_org_id
8751 ,x_return_status => x_return_status
8752 ,x_msg_count => x_msg_count
8753 ,x_msg_data => x_msg_data
8754 );
8755 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8756 IF (l_debug = 1) THEN
8757 DEBUG('xxx: Error packing lpn = ' ||
8758 l_lpn_ids(i) || ' into lpn = ' ||
8759 p_into_lpn_id,'transfer_contents',9);
8760 END IF;
8761 RAISE fnd_api.g_exc_error;
8762 END IF;
8763 END LOOP;
8764
8765 l_progress := '220';
8766
8767 -- At the end, update the intoLPN context into 2 (WIP
8768 wms_container_pub.modify_lpn_wrapper
8769 ( p_api_version => 1.0
8770 ,x_return_status => x_return_status
8771 ,x_msg_count => x_msg_count
8772 ,x_msg_data => x_msg_data
8773 ,p_lpn_id => p_into_lpn_id
8774 ,p_lpn_context => 2 --WIP
8775 );
8776 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8777 IF (l_debug = 1) THEN
8778 debug('Error modifying lpn context to wip',
8779 'transfer_contents', 9);
8780 END IF;
8781 END IF;
8782
8783 -- Call complete operation instance
8784 FOR i IN 1 .. l_txn_tmp_id_tb.COUNT LOOP
8785 wms_atf_runtime_pub_apis.complete_operation_instance
8786 ( p_source_task_id => l_txn_tmp_id_tb(i)
8787 ,p_activity_id => 1 -- inbound
8788 ,p_operation_type_id => 1 -- load
8789 ,x_return_status => x_return_status
8790 ,x_msg_data => x_msg_data
8791 ,x_msg_count => x_msg_count
8792 ,x_error_code => l_error_code
8793 );
8794 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
8795 IF (l_debug = 1) THEN
8796 DEBUG('xxx: Error in complete_operation_instance on '
8797 || ' MMTT = ' || l_txn_tmp_id_tb(i),'transfer_contents',9);
8798 END IF;
8799 RAISE fnd_api.g_exc_error;
8800 END IF;
8801
8802 END LOOP;
8803
8804 -- Update MOL to new LPN id, only if there are loose contents
8805 -- associated with fromLPN
8806 IF (l_loose_contents = 1) THEN
8807 -- Update any MMTT assoc with the old LPN to the new LPN id
8808 IF (l_debug = 1) THEN
8809 -- ER 7307189 changes start
8810 debug('Updating MMTT...','transfer_contents',9);
8811 debug('Updating MMTT...','transfer_contents p_into_lpn_id'||p_into_lpn_id,9);
8812 debug('Updating MMTT...','transfer_contents p_from_lpn_id'||p_from_lpn_id,9);
8813 -- ER 7307189 changes end
8814 END IF;
8815
8816 --BUG 3435079: The query doesn't seem to be picking up the lpn_id
8817 --index on MMTT. So replace it with the following, and also
8818 --Move it BEFORE updating MOL
8819 UPDATE
8820 mtl_material_transactions_temp
8821 SET
8822 lpn_id = p_into_lpn_id
8823 WHERE
8824 lpn_id = p_from_lpn_id;
8825
8826
8827 BEGIN
8828 UPDATE
8829 mtl_txn_request_lines
8830 SET
8831 lpn_id = p_into_lpn_id
8832 WHERE
8833 lpn_id = p_from_lpn_id;
8834 EXCEPTION
8835 WHEN OTHERS THEN
8836 IF (l_debug =1 ) THEN
8837 DEBUG('xxx: Error updating MOL','transfer_contents',9);
8838 END IF;
8839 RAISE fnd_api.g_exc_error;
8840 END;
8841
8842 l_progress := '230';
8843
8844 END IF;
8845
8846 ELSE -- inventory LPN l_from_context = 1
8847
8848 IF (l_debug = 1) THEN
8849 DEBUG('xxx: l_from_context = ' || l_from_context
8850 || '. Resides in Inventory','transfer_contents',9);
8851 END IF;
8852
8853 l_progress := '240';
8854
8855 -- create MMTT records for each loose item, each inner LPN
8856 -- Group them into same header, and then call inventory TM
8857 SELECT mtl_material_transactions_s.NEXTVAL
8858 INTO l_hdr_id
8859 FROM dual;
8860
8861 l_progress := '250';
8862
8863 IF (l_sub_loc_changed = 'Y') THEN
8864 l_return_status := inv_trx_util_pub.insert_line_trx
8865 (
8866 p_trx_hdr_id => l_hdr_id
8867 , p_item_id => '0'
8868 , p_org_id => l_org_id
8869 , p_trx_action_id => 2
8870 , p_subinv_code => l_sub_code
8871 , p_tosubinv_code => l_to_sub
8872 , p_locator_id => l_loc_id
8873 , p_tolocator_id => l_to_loc
8874 , p_trx_type_id => 2
8875 , p_trx_src_type_id => 13
8876 , p_trx_qty => 1
8877 , p_pri_qty => 1
8878 , p_uom => 'Ea'
8879 , p_user_id => l_user_id
8880 , p_from_lpn_id => NULL
8881 , p_cnt_lpn_id => p_from_lpn_id
8882 , p_xfr_lpn_id => NULL
8883 , x_trx_tmp_id => l_txn_tmp_id
8884 , x_proc_msg => x_msg_data
8885 , p_project_id => p_project_id
8886 , p_task_id => p_task_id);
8887 IF (l_txn_tmp_id <= 0 ) OR (l_return_status<>0) THEN
8888 IF (l_debug = 1) THEN
8889 debug('Error inserting MMTT ID: ' ||
8890 l_txn_tmp_id,'transfer_contents',9);
8891 END IF;
8892 RAISE fnd_api.g_exc_error;
8893 END IF;
8894
8895 BEGIN
8896 UPDATE mtl_material_transactions_temp
8897 SET transaction_header_id = l_hdr_id
8898 , transaction_batch_id = l_hdr_id
8899 , transaction_batch_seq = l_batch_seq
8900 WHERE transaction_temp_id = l_txn_tmp_id;
8901 EXCEPTION
8902 WHEN OTHERS THEN
8903 IF (l_debug = 1) THEN
8904 debug('Error updating MMTT with ID: ' ||
8905 l_txn_tmp_id,9);
8906 END IF;
8907 RAISE fnd_api.g_exc_error;
8908 END;
8909
8910 l_batch_seq := l_batch_seq + 1;
8911 -- update local variables for sub and loc
8912 l_sub_code := l_to_sub;
8913 l_loc_id := l_to_loc;
8914
8915 END IF; --IF (l_sub_loc_changed = 'Y') THEN
8916
8917 -- Deal with Nested LPN first
8918 BEGIN
8919 SELECT lpn_id
8920 bulk collect INTO l_lpn_ids
8921 FROM wms_license_plate_numbers
8922 WHERE parent_lpn_id = p_from_lpn_id;
8923 EXCEPTION
8924 WHEN OTHERS THEN
8925 IF (l_debug = 1) THEN
8926 DEBUG('xxx: Error getting nested lpns','transfer_contents',9);
8927 END IF;
8928 END;
8929
8930 l_progress := '260';
8931
8932 FOR i IN 1 .. l_lpn_ids.COUNT LOOP
8933 IF (l_debug = 1) THEN
8934 DEBUG('Inserting MMTT for lpn: ' || l_lpn_ids(i),
8935 'transfer_contents',
8936 9);
8937 END IF;
8938
8939 l_return_Status := inv_trx_util_pub.insert_line_trx
8940 (
8941 p_trx_hdr_id => l_hdr_id
8942 , p_item_id => -1
8943 , p_org_id => l_org_id
8944 , p_trx_action_id => inv_globals.g_action_containersplit
8945 , p_subinv_code => l_sub_code
8946 , p_locator_id => l_loc_id
8947 , p_trx_type_id => inv_globals.g_type_container_split
8948 , p_trx_src_type_id => inv_globals.g_sourcetype_inventory
8949 , p_trx_qty => 1
8950 , p_pri_qty => 1
8951 , p_uom => 'X'
8952 , p_user_id => l_user_id --??
8953 , p_from_lpn_id => p_from_lpn_id
8954 , p_cnt_lpn_id => l_lpn_ids(i)
8955 , p_xfr_lpn_id => p_into_lpn_id
8956 , x_trx_tmp_id => l_txn_tmp_id
8957 , x_proc_msg => x_msg_data );
8958
8959 IF (l_return_status = -1) THEN
8960 IF (l_debug = 1) THEN
8961 debug('Error inserting MMTT', 'transfer_contents', 9);
8962 END IF;
8963 RAISE fnd_api.g_exc_error;
8964 END IF;
8965
8966 BEGIN
8967 UPDATE mtl_material_transactions_temp
8968 SET transaction_header_id = l_hdr_id
8969 , transaction_batch_id = l_hdr_id
8970 , transaction_batch_seq = l_batch_seq
8971 WHERE transaction_temp_id = l_txn_tmp_id;
8972 EXCEPTION
8973 WHEN OTHERS THEN
8974 IF (l_debug = 1) THEN
8975 debug('Error updating MMTT with ID: ' ||
8976 l_txn_tmp_id,9);
8977 END IF;
8978 RAISE fnd_api.g_exc_error;
8979 END;
8980
8981 l_batch_seq := l_batch_seq + 1;
8982 END LOOP;
8983
8984 l_progress := '270';
8985
8986 -- Now deal with loose items
8987 l_loose_contents := 0;
8988 FOR l_wlpnc_rec IN wlpnc_cur LOOP
8989 IF (l_loose_contents = 0) THEN
8990 l_loose_contents := 1;
8991 END IF;
8992
8993 IF (l_wlpnc_rec.uom_code <> l_wlpnc_rec.primary_uom_code) THEN
8994 l_prim_qty := inv_rcv_cache.convert_qty
8995 (p_inventory_item_id => l_wlpnc_rec.inventory_item_id
8996 ,p_from_qty => l_wlpnc_rec.quantity
8997 ,p_from_uom_code => l_wlpnc_rec.uom_code
8998 ,p_to_uom_code => l_wlpnc_rec.primary_uom_code);
8999 ELSE
9000 l_prim_qty := l_wlpnc_rec.quantity;
9001 END IF;
9002
9003 IF (l_debug = 1) THEN
9004 debug('Inserting MMTT...', 'transfer_contents', 9);
9005 END IF;
9006 l_return_status := inv_trx_util_pub.insert_line_trx
9007 (
9008 p_trx_hdr_id => l_hdr_id
9009 , p_item_id => l_wlpnc_rec.inventory_item_id
9010 , p_revision => l_wlpnc_rec.revision
9011 , p_org_id => l_org_id
9012 , p_trx_action_id => inv_globals.g_action_containersplit
9013 , p_subinv_code => l_sub_code
9014 , p_locator_id => l_loc_id
9015 , p_trx_type_id => inv_globals.g_type_container_split
9016 , p_trx_src_type_id => inv_globals.g_sourcetype_inventory
9017 , p_trx_qty => l_wlpnc_rec.quantity
9018 , p_pri_qty => l_prim_qty
9019 , p_uom => l_wlpnc_rec.uom_code
9020 , p_user_id => l_user_id --??
9021 , p_from_lpn_id => p_from_lpn_id
9022 , p_xfr_lpn_id => p_into_lpn_id
9023 , x_trx_tmp_id => l_txn_tmp_id
9024 , x_proc_msg => x_msg_data);
9025 IF (l_return_status = -1) THEN
9026 IF (l_debug = 1) THEN
9027 debug('Error inserting MMTT', 'transfer_contents', 9);
9028 END IF;
9029 RAISE fnd_api.g_exc_error;
9030 END IF;
9031
9032 BEGIN
9033 UPDATE mtl_material_transactions_temp
9034 SET transaction_header_id = l_hdr_id
9035 , transaction_batch_id = l_hdr_id
9036 , transaction_batch_seq = l_batch_seq
9037 WHERE transaction_temp_id = l_txn_tmp_id;
9038 EXCEPTION
9039 WHEN OTHERS THEN
9040 IF (l_debug = 1) THEN
9041 debug('Error updating MMTT with ID: ' ||
9042 l_txn_tmp_id,9);
9043 END IF;
9044 RAISE fnd_api.g_exc_error;
9045 END;
9046
9047 l_batch_seq := l_batch_seq + 1;
9048
9049 IF (l_debug = 1) THEN
9050 debug('MMTT:' || l_txn_tmp_id || 'Inserted', 'transfer_contents', 9);
9051 END IF;
9052
9053 IF (l_wlpnc_rec.lot_number IS NOT NULL) THEN
9054 l_return_status := inv_trx_util_pub.insert_lot_trx
9055 ( p_trx_tmp_id => l_txn_tmp_id
9056 ,p_user_id => l_user_id
9057 ,p_lot_number => l_wlpnc_rec.lot_number
9058 ,p_trx_qty => l_wlpnc_rec.quantity
9059 ,p_pri_qty => l_prim_qty
9060 ,x_ser_trx_id => l_ser_trx_id
9061 ,x_proc_msg => x_msg_data);
9062 IF (l_return_status = -1) THEN
9063 IF (l_debug = 1) THEN
9064 debug('Error inserting MTLT', 'transfer_contents', 9);
9065 END IF;
9066 RAISE fnd_api.g_exc_error;
9067 END IF;
9068 END IF;
9069
9070 IF (Nvl(l_wlpnc_rec.serial_number_control_code,1)
9071 NOT IN (1, 6)) THEN -- Item is serial control
9072 IF (l_serial_numbers.COUNT > 0) THEN
9073 l_serial_numbers.DELETE;
9074 END IF;
9075
9076 BEGIN
9077 SELECT serial_number
9078 bulk collect INTO l_serial_numbers
9079 FROM mtl_serial_numbers
9080 WHERE lpn_id = p_from_lpn_id
9081 AND inventory_item_id = l_wlpnc_rec.inventory_item_id
9082 AND Nvl(lot_number, '@@@') = Nvl(l_wlpnc_rec.lot_number, '@@@')
9083 AND Nvl(revision, '@@@') = Nvl(l_wlpnc_rec.revision,'@@@');
9084 EXCEPTION
9085 WHEN OTHERS THEN
9086 IF (l_debug = 1) THEN
9087 debug('Error retrieving entries from MTL_SERIAL_NUMBERS',
9088 'transfer_contents', 9);
9089 END IF;
9090 RAISE fnd_api.g_exc_error;
9091 END;
9092
9093 IF (l_wlpnc_rec.lot_number IS NOT NULL) THEN
9094 l_txn_tmp_id := l_ser_trx_id;
9095 END IF;
9096
9097 FOR i IN 1 .. l_serial_numbers.COUNT LOOP
9098 l_return_status := inv_trx_util_pub.insert_ser_trx
9099 (p_trx_tmp_id => l_txn_tmp_id
9100 ,p_user_id => l_user_id
9101 ,p_fm_ser_num=> l_serial_numbers(i)
9102 ,p_to_ser_num=> l_serial_numbers(i)
9103 ,x_proc_msg => x_msg_data );
9104 IF (l_return_status = -1) THEN
9105 IF (l_debug = 1) THEN
9106 debug('Error inserting MSNT', 'transfer_contents', 9);
9107 END IF;
9108 RAISE fnd_api.g_exc_error;
9109 END IF;
9110 END LOOP;
9111 END IF;
9112 END LOOP;
9113
9114 IF (l_debug = 1) THEN
9115 DEBUG('xxx: Calling process_lpn_trx','transfer_contents',9);
9116 DEBUG(' (p_trx_hdr_id => ' || l_hdr_id,'transfer_contents',9);
9117 END IF;
9118
9119 l_return_status :=inv_lpn_trx_pub.process_lpn_trx
9120 (p_trx_hdr_id => l_hdr_id
9121 ,p_proc_mode => 1
9122 ,p_commit => fnd_api.g_false
9123 ,x_proc_msg => x_msg_data);
9124
9125 -- Call complete operation instance
9126 FOR i IN 1 .. l_txn_tmp_id_tb.COUNT LOOP
9127 wms_atf_runtime_pub_apis.complete_operation_instance
9128 ( p_source_task_id => l_txn_tmp_id_tb(i)
9129 ,p_activity_id => 1 -- inbound
9130 ,p_operation_type_id => 1 -- load
9131 ,x_return_status => x_return_status
9132 ,x_msg_data => x_msg_data
9133 ,x_msg_count => x_msg_count
9134 ,x_error_code => l_error_code
9135 );
9136 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
9137 IF (l_debug = 1) THEN
9138 DEBUG('xxx: Error in complete_operation_instance on '
9139 || ' MMTT = ' || l_txn_tmp_id_tb(i),'transfer_contents',9);
9140 END IF;
9141 RAISE fnd_api.g_exc_error;
9142 END IF;
9143
9144 END LOOP;
9145
9146 -- Update any MOL assoc with the old LPN to new LPN id
9147 IF (l_loose_contents = 1) THEN
9148 l_progress := '290';
9149 -- Update any MMTT assoc with the old LPN to the new LPN id
9150 IF (l_debug = 1) THEN
9151 -- ER 7307189 changes start
9152 debug('Updating MMTT...','transfer_contents11111',9);
9153 debug('Updating MMTT...','transfer_contents p_into_lpn_id'||p_into_lpn_id,9);
9154 debug('Updating MMTT...','transfer_contents p_from_lpn_id'||p_from_lpn_id,9);
9155 -- ER 7307189 changes end
9156
9157 END IF;
9158
9159 --BUG 3435079: The query doesn't seem to be picking up the lpn_id
9160 --index on MMTT. So replace it with the following, and also
9161 --Move it BEFORE updating MOL
9162 UPDATE
9163 mtl_material_transactions_temp
9164 SET
9165 lpn_id = p_into_lpn_id
9166 WHERE
9167 lpn_id = p_from_lpn_id;
9168
9169 IF (l_debug = 1) THEN
9170 debug('Updating MOL...','transfer_contents',9);
9171 END IF;
9172
9173 BEGIN
9174 UPDATE
9175 mtl_txn_request_lines
9176 SET
9177 lpn_id = p_into_lpn_id
9178 WHERE
9179 lpn_id = p_from_lpn_id;
9180 EXCEPTION
9181 WHEN OTHERS THEN
9182 IF (l_debug = 1) THEN
9183 DEBUG('xxx: Error updating MOLs','transfer_contents',9);
9184 END IF;
9185 RAISE fnd_api.g_exc_error;
9186 END;
9187
9188 l_progress := '300';
9189
9190 END IF;
9191 END IF; -- end l_from_context check
9192
9193 IF (l_debug = 1) THEN
9194 DEBUG('Exiting transfer_contents','transfer_contents', 9);
9195 END IF;
9196
9197 COMMIT;
9198
9199 EXCEPTION
9200 WHEN OTHERS THEN
9201 fnd_message.set_name('WMS', 'WMS_TASK_ERROR');
9202 fnd_msg_pub.add;
9203 x_return_status := fnd_api.g_ret_sts_unexp_error;
9204 IF (l_debug = 1) THEN
9205 debug('Exception occured after l_progress ='|| l_progress, 'transfer_contents', 9);
9206 END IF;
9207 IF (wlpnc_cur%isopen) THEN
9208 CLOSE wlpnc_cur;
9209 END IF;
9210 BEGIN
9211 ROLLBACK TO transfer_contents_pub;
9212 EXCEPTION
9213 WHEN OTHERS THEN
9214 IF (l_debug = 1) THEN
9215 debug('SQLCODE:'||SQLCODE||' SQLERRM'||Sqlerrm,9);
9216 END IF;
9217 END;
9218 END transfer_contents;
9219
9220
9221 /**
9222 * This procedure is a wrapper for the complete_putaway API and will be
9223 * called for a group of tasks. Accepts the current group Id or
9224 * transaction_header_id and the values confirmed by the user on the page
9225 * and processes the eligible tasks
9226 * Processing Logic:
9227 * -> Loop through each task/MMTT row given the group_id/header_id
9228 * -> Consume the task quantity based on the confirmed quantity
9229 * -> Create the lots and serials interface records (receiving LPN)
9230 * -> Create the WLPNI records (receiving LPN) or
9231 * call pack/unpack API to reflect nesting changes
9232 * -> Call the complete_putaway API for the given task
9233 * -> Call the receiving Transaction Manager (receiving LPN)
9234 *
9235 * @param x_return_status Return Status Indicator
9236 * @param x_msg_count Stacked messages counter
9237 * @param x_msg_data Stacked Messages
9238 * @param p_group_id ID of the current group of tasks
9239 * @param p_txn_header_id header_id for the current group of tasks
9240 * @param p_drop_type Drop Type Identifier.<br>
9241 * ID - Item Drop<br>
9242 * CD - Consolidated Drop<br>
9243 * MD - Manual Drop<br>
9244 * UD - User Drop<br>
9245 * @param p_lpn_mode Flag for LPN actions
9246 * 1 - Transfer Contents<br>
9247 * 2 - Drop Entire LPN<br>
9248 * 3 - Item Drop
9249 * @param p_lpn_id LPN being putaway
9250 * @param p_lpn_context Context of the LPN being putaway
9251 * @param p_organization_id Organization ID
9252 * @param p_user_id Logged in Employee ID
9253 * @param p_item_id Item for the current group (item drop)
9254 * @param p_revision Revision confirmed (item drop)
9255 * @param p_lot_number Lot Number confirmed (item drop)
9256 * @param p_subinventory_code Drop to Subinventory Code
9257 * @param p_locator_id Drop to Locator ID
9258 * @param p_quantity Quantity Confirmed (item drop)
9259 * @param p_uom_code Unit of Measure confirmed (item drop)
9260 * @param p_entire_lpn Flag to indicate if entire LPN is putaway
9261 * @param p_to_lpn_name License Plate number of the Into LPN
9262 * @param p_to_lpn_id LPN Id of the Into LPN
9263 * @param p_project_id Project ID
9264 * @param p_task_id Task ID
9265 * @param p_reference MOL reference
9266 * @param p_qty_reason_id Reason ID for Quantity Discrepancy
9267 * @param p_loc_reason_id Reason ID for locator discrepancy
9268 * @param p_process_serial_flag Flag set if serials are confirmed in UI
9269 * @param p_msni_txn_interface_id Transaction_interface_id of MSNI records
9270 * created from the UI
9271 * @param p_product_transaction_id Product_transaction_id of MTLI/MSNI
9272 * populated if user confirms partial qty
9273 **/
9274 PROCEDURE Complete_Putaway_Wrapper(
9275 x_return_status OUT NOCOPY VARCHAR2
9276 , x_msg_count OUT NOCOPY NUMBER
9277 , x_msg_data OUT NOCOPY VARCHAR2
9278 /* Added for LMS project: Anupam Jain*/
9279 , x_lms_operation_plan_id OUT NOCOPY NUMBER
9280 /* LMS change end*/
9281 , p_group_id IN NUMBER
9282 , p_txn_header_id IN NUMBER
9283 , p_drop_type IN VARCHAR2
9284 , p_lpn_mode IN NUMBER
9285 , p_lpn_id IN NUMBER
9286 , p_lpn_context IN NUMBER
9287 , p_organization_id IN NUMBER
9288 , p_user_id IN NUMBER
9289 , p_item_id IN NUMBER
9290 , p_revision IN VARCHAR2
9291 , p_lot_number IN VARCHAR2
9292 , p_subinventory_code IN VARCHAR2
9293 , p_locator_id IN NUMBER
9294 , p_quantity IN NUMBER
9295 , p_uom_code IN VARCHAR2
9296 , p_entire_lpn IN VARCHAR2
9297 , p_to_lpn_name IN VARCHAR2
9298 , p_to_lpn_id IN NUMBER
9299 , p_project_id IN NUMBER
9300 , p_task_id IN NUMBER
9301 , p_reference IN VARCHAR2
9302 , p_qty_reason_id IN NUMBER
9303 , p_loc_reason_id IN NUMBER
9304 , p_process_serial_flag IN VARCHAR2
9305 , p_msni_txn_interface_id IN NUMBER
9306 , p_product_transaction_id IN NUMBER
9307 , p_secondary_quantity IN NUMBER --OPM Convergence
9308 , p_secondary_uom IN VARCHAR2 --OPM Convergence
9309 , p_lpn_initially_loaded IN VARCHAR2 ) IS
9310
9311 --Cursor Declarations
9312
9313 --Fetches the move order lines in the global temporary table for the current group
9314 CURSOR mol_csr IS
9315 SELECT mtrl.line_id
9316 , mtrl.quantity
9317 , NVL(mtrl.quantity_detailed, 0)
9318 , NVL(mtrl.quantity_delivered, 0)
9319 , mtrl.uom_code
9320 , mtrl.secondary_quantity --OPM Convergence
9321 , NVL(mtrl.secondary_quantity_detailed, 0) --OPM Convergence
9322 , NVL(mtrl.secondary_quantity_delivered, 0) --OPM Convergence
9323 , mtrl.secondary_uom_code --OPM Convergence
9324 FROM mtl_txn_request_lines mtrl
9325 WHERE mtrl.line_id IN (SELECT DISTINCT gtmp.move_order_line_id
9326 FROM wms_putaway_group_tasks_gtmp gtmp
9327 WHERE gtmp.group_id = p_group_id
9328 AND gtmp.transaction_header_id = p_txn_header_id
9329 AND gtmp.row_type = g_row_tp_all_task);
9330
9331 --R12: This cursor is used to find out the matching MOL for a
9332 --given group of serials with a particular inspection status and
9333 --lot number
9334 CURSOR serial_mol_csr(v_inspect_status NUMBER, v_lot_number VARCHAR2) IS
9335 SELECT mtrl.line_id
9336 , mtrl.quantity
9337 , NVL(mtrl.quantity_detailed, 0)
9338 , NVL(mtrl.quantity_delivered, 0)
9339 , mtrl.uom_code
9340 , mtrl.secondary_quantity --OPM Convergence
9341 , NVL(mtrl.secondary_quantity_detailed, 0) --OPM Convergence
9342 , NVL(mtrl.secondary_quantity_delivered, 0) --OPM Convergence
9343 , mtrl.secondary_uom_code --OPM Convergence
9344 FROM mtl_txn_request_lines mtrl
9345 WHERE mtrl.line_id IN (SELECT DISTINCT gtmp.move_order_line_id
9346 FROM wms_putaway_group_tasks_gtmp gtmp
9347 WHERE gtmp.group_id = p_group_id
9348 AND gtmp.transaction_header_id = p_txn_header_id
9349 AND gtmp.row_type = g_row_tp_all_task)
9350 AND Nvl(mtrl.lot_number,'&*_') = Nvl(v_lot_number,'&*_')
9351 AND Nvl(mtrl.inspection_status,-1) = Nvl(v_inspect_status,-1);
9352
9353 --Fetches the details of the current task from the global temp table
9354 --drop types 'Consolidated Drop' or 'Item Drop'
9355 CURSOR all_tasks_csr(v_disc VARCHAR2) IS
9356 SELECT transaction_temp_id
9357 , lpn_id
9358 , move_order_line_id
9359 , inventory_item_id
9360 , revision
9361 , lot_number
9362 , transaction_quantity
9363 , transaction_uom
9364 , txn_source_id
9365 , backorder_delivery_detail
9366 , crossdock_type
9367 , wip_supply_type
9368 , secondary_quantity -- OPM Convergence
9369 , inspection_status
9370 , primary_uom_code
9371 FROM wms_putaway_group_tasks_gtmp
9372 WHERE group_id = p_group_id
9373 AND transaction_header_id = p_txn_header_id
9374 AND row_type = G_ROW_TP_ALL_TASK
9375 AND ( (v_disc = 'N') --no qty idsc
9376 OR
9377 (v_disc = 'Y' AND p_drop_type = G_DT_ITEM_DROP
9378 AND process_flag = 'Y' --item drop and qty disc
9379 )
9380 );
9381
9382 --Fetches the information for the current task for the drop types
9383 --'Manual Drop' or 'User Drop'
9384 CURSOR md_tasks_csr IS
9385 SELECT mmtt.transaction_temp_id
9386 , mtrl.lpn_id
9387 , mtrl.line_id
9388 , mmtt.inventory_item_id
9389 , mmtt.revision
9390 , mtrl.lot_number
9391 , mmtt.transaction_quantity
9392 , mmtt.transaction_uom
9393 , mtrl.txn_source_id
9394 , mtrl.backorder_delivery_detail_id
9395 , mtrl.crossdock_type
9396 , mmtt.wip_supply_type
9397 , mmtt.secondary_transaction_quantity --OPM Convergence
9398 , mtrl.inspection_status
9399 , msi.primary_uom_code
9400 FROM mtl_material_transactions_temp mmtt
9401 , mtl_txn_request_lines mtrl
9402 , mtl_txn_request_headers mtrh
9403 , mtl_system_items_kfv msi
9404 , ( /*5723418*/
9405 SELECT wlpn.lpn_id
9406 FROM wms_license_plate_numbers wlpn
9407 START WITH wlpn.lpn_id = p_lpn_id
9408 CONNECT BY PRIOR wlpn.lpn_id = wlpn.parent_lpn_id
9409 ) wlpn
9410 WHERE mtrh.organization_id = p_organization_id
9411 AND mtrh.move_order_type = 6
9412 AND mtrl.header_id = mtrh.header_id
9413 AND mtrl.line_id = mmtt.move_order_line_id
9414 AND mtrl.line_status = 7
9415 AND mtrl.lpn_id = wlpn.lpn_id
9416 AND msi.inventory_item_id = mtrl.inventory_item_id
9417 AND msi.organization_id = mtrl.organization_id;
9418
9419 --R12: This cursor will return all serials entered by the user
9420 --in this transaction
9421 CURSOR rcv_serials_csr IS
9422 SELECT msn.serial_number
9423 , 'N'
9424 , msn.inspection_status
9425 , msn.lot_number
9426 FROM mtl_serial_numbers_interface msni
9427 , mtl_serial_numbers msn
9428 , rcv_serials_supply rss
9429 WHERE msni.transaction_interface_id = p_msni_txn_interface_id
9430 AND msn.serial_number BETWEEN msni.fm_serial_number AND Nvl(msni.to_serial_number, msni.fm_serial_number)
9431 AND Length(msn.serial_number) = Length(msni.fm_serial_number)
9432 AND msn.inventory_item_id = p_item_id
9433 AND msn.current_organization_id = p_organization_id
9434 AND msn.lpn_id = p_lpn_id
9435 AND rss.serial_num = msn.serial_number
9436 AND rss.supply_type_code = 'RECEIVING'
9437 ORDER BY msn.serial_number,msn.lot_number;
9438
9439 --Fetches the serials that were consumed by the user in UI if user confirms
9440 --partial quantity for an Inventory/WIP LPN
9441 CURSOR msnt_ser_csr(v_lpn_id NUMBER
9442 , v_item_id NUMBER) IS
9443 SELECT serial_number
9444 , 'N'
9445 FROM mtl_serial_numbers
9446 WHERE inventory_item_id = v_item_id
9447 AND lpn_id = v_lpn_id
9448 AND (
9449 (p_revision IS NOT NULL and revision = p_revision)
9450 OR
9451 (p_revision IS NULL)
9452 )
9453 AND (
9454 (p_lot_number IS NOT NULL and lot_number = p_lot_number)
9455 OR
9456 (p_lot_number IS NULL)
9457 )
9458 AND group_mark_id = -4936;
9459
9460 --Local variables
9461 l_quantity NUMBER; --Quantity passed to complete_putaway
9462 l_remaining_qty NUMBER; --Track remaining quantity to confirm
9463 l_sug_grp_quantity NUMBER; --Total suggested quantity for the group
9464 l_grp_prm_quantity NUMBER; --Total group quantity in primary UOM
9465 l_rem_grp_quantity NUMBER; --Remaining quantity to consume for MO splits
9466 l_prm_user_qty NUMBER; --Confirmed quantity in primary uom
9467 l_rem_user_qty NUMBER; --Remaining quantity to be confirmed
9468 l_mol_qty NUMBER; --MOL quantity
9469 l_mol_qty_detailed NUMBER; --MOL total allocated quantity
9470 l_mol_qty_delivered NUMBER; --MOL transacted quantity
9471 l_new_txn_header_id NUMBER; --New value for transaction_header_id
9472 l_mol_uom_code MTL_UNITS_OF_MEASURE_TL.uom_code%TYPE; --MOL uom code
9473 l_tmp_qty1 NUMBER; --MOL Qty - MOL Delivered Qty
9474 l_tmp_prm_qty NUMBER; --MOL Qty - Delivered Qty in primary uom
9475 l_lpn_controlled_flag NUMBER; --LPN controlled flag for the drop sub
9476 l_qty_to_split NUMBER; --Quantity to split
9477 l_uom_con_sug_grp_qty NUMBER; --Suggested quantity converted to primary UOM???
9478 l_grp_uom_code MTL_UNITS_OF_MEASURE_TL.uom_code%TYPE;
9479 l_uom_code MTL_UNITS_OF_MEASURE_TL.uom_code%TYPE;
9480 l_primary_uom_code MTL_UNITS_OF_MEASURE_TL.uom_code%TYPE;
9481 l_serialized_item BOOLEAN; --Flag to indicate if the item is serialized
9482 l_group_id NUMBER; -- Group ID
9483 l_product_transaction_id NUMBER; --Product transaction id for complete_putaway
9484 l_item_id NUMBER; --Item ID for complete_putaway
9485 l_subinventory_code mtl_secondary_inventories.secondary_inventory_name%TYPE;
9486 l_locator_id NUMBER; --Locator for complete_putaway
9487 l_lpn_id NUMBER; --p_LPN_ID for complete_putaway???--check
9488 l_to_lpn_id NUMBER; --To LPN ID -- for pack/unpack
9489 l_to_lpn_name wms_license_plate_numbers.license_plate_number%TYPE;
9490 l_revision mtl_item_revisions.revision%TYPE; --p_rev for complete_putaway
9491 l_lot_number mtl_lot_numbers.lot_number%type; --p_lot for complete_putaway
9492 l_mmtt_prm_qty NUMBER; --Lot quantity in primary uom
9493 l_lot_expiration_date DATE; --Lot expiration date
9494 l_lot_status_id NUMBER; --Lot Status
9495 l_cur_ser_number mtl_serial_numbers.serial_number%TYPE;
9496 l_mmtt_temp_id NUMBER; --Variable to store p_temp_id of complete_putaway
9497 l_mmtt_temp_id_tbl num_tab; --Transaction_Temp_ids for the current group
9498 l_mmtt_item_id_tbl num_tab; --Item ID for the current group
9499 l_mmtt_rev_tbl rev_tab; --Revision for the current group
9500 l_mmtt_lot_tbl lot_tab; --Lot Number for the current group
9501 l_mmtt_qty_tbl num_tab; --transaction_quantity for the current group
9502 l_mmtt_uom_tbl uom_tab; --uom for the current group
9503 l_bk_del_det_tbl num_tab; --Backorder Delivery Detail to hold crossdock infor
9504 l_xdock_type_tbl num_tab; --Crossdock type for the current group
9505 l_wip_sup_typ_tbl num_tab; --Wip Supply Type for the current group
9506 l_mol_line_id NUMBER; --MO Line ID
9507 l_mol_lpn_id_tbl num_tab; --LPN_ID for the current task => p_lpn_id of complete_putaway
9508 l_mol_line_id_tbl num_tab; --MO Line ID
9509 l_parent_txn_id_tbl num_tab; --Parent Transaction Id - for rcv_serials_supply
9510 l_parent_txn_id NUMBER; --Parent Transaction Id - for rcv_serials_supply
9511 l_lot_control_code NUMBER; --Item Lot control code
9512 l_serial_control_code NUMBER; --Item Serial control code
9513 l_mmtt_count NUMBER; --No. of MMTTs for the current MOL
9514 l_ser_intf_id NUMBER; --Updated txn_interface_id for MSNI
9515 l_cur_task_ser_count NUMBER; --Count of serials consumed for the current task
9516 l_entire_lpn VARCHAR2(1); --Is entire LPN putaway
9517 l_process_flag VARCHAR2(10); --Indicator to pick tasks from global temp table
9518 l_disc VARCHAR2(10); --Quantity discrepancy indicator
9519 l_serial_txn_temp_id NUMBER; --Serial temp id for lot and serial controlled item
9520 l_serial_temp_id NUMBER; --serial_transaction_temp_id - for MSNI
9521 l_temp_id_tbl num_tab; --Table of transaction_temp_id for the group
9522 l_ser_num_tbl ser_num_tab; --Table to hold serials in MSNI
9523 l_parent_ser_tbl ser_num_tab; --Table for serials for the parent serial
9524 l_ser_mark_tbl ser_mark_tab; --Flag to indicate if serial is confirmed
9525 l_ser_qty NUMBER; --Quantity for process_lot_serial API
9526 l_action NUMBER; --Action code for the process_lot_serial API
9527 l_txn_ret NUMBER := 0; --Return status of the Inventory TM
9528 l_msg_data VARCHAR2(10000);
9529 l_del_count NUMBER; --No. of rows deleted in the temp table
9530 l_business_flow_code NUMBER := 30; -- default to Inventory Putaway
9531 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
9532 l_progress VARCHAR2(10); --Progress indicator
9533 l_proc_name VARCHAR2(30) := 'complete_putaway_wrapper';
9534 l_mos_to_split_tbl split_mo_tb_tp;
9535 l_mo_splt_tb inv_rcv_integration_apis.mo_in_tb_tp;
9536 l_mo_splt_cnt NUMBER; --MO Split table counter
9537 l_rcv_commit BOOLEAN := FALSE;
9538 l_lpn_mode NUMBER; -- Drop mode
9539 l_drop_sub_type NUMBER; -- Drop subinventory type
9540 l_xdock_to_wip BOOLEAN; -- Flag to indicate if the task is xdocked to WIP
9541 l_transaction_interface_id NUMBER; -- For interface recors
9542 l_dummy_temp_id NUMBER;
9543 l_emp_id NUMBER;
9544 l_batch_seq NUMBER; --BUG 3306988
9545 l_lpn_serials_cnt NUMBER := 0; --Count of serials in the LPN
9546 l_skip_mmtt BOOLEAN := FALSE; --
9547 l_error_code NUMBER;
9548 l_drop_off_time DATE := Sysdate; --DBI FIX
9549 l_grp_sec_quantity NUMBER; --OPM Convergence
9550 l_grp_sec_uom VARCHAR2(3); --OPM Convergence
9551 l_mol_sec_qty NUMBER; --OPM Convergence
9552 l_mol_sec_qty_detailed NUMBER; --OPM Convergence
9553 l_mol_sec_qty_delivered NUMBER; --OPM Convergence
9554 l_mol_sec_uom_code VARCHAR2(3); --OPM Convergence
9555 l_tmp_sec_qty NUMBER; --OPM Convergence
9556 l_sec_user_qty NUMBER; --opm convergence
9557 l_mmtt_sec_qty_tbl num_tab; --OPM Convergence
9558 l_remaining_sec_qty NUMBER; --OPM Convergence
9559 l_mmtt_sec_qty NUMBER;--OPM Convergence
9560 l_secondary_quantity NUMBER; --OPM Convergence
9561 l_secondary_uom NUMBER; --OPM Convergence
9562 l_prim_qty_consumable NUMBER; --BUG 5075410
9563
9564 l_msni_inspect_status_tbl num_tab;
9565 TYPE varchar80_tab IS TABLE OF VARCHAR2(80) INDEX BY BINARY_INTEGER;
9566 l_msni_lot_tbl varchar80_tab;
9567 l_msni_qty_tbl num_tab;
9568 l_inspection_status_tbl num_tab;
9569 l_ser_inspect_status_tbl num_tab;
9570 l_ser_lot_num_tbl varchar80_tab;
9571 TYPE varchar3_tab IS TABLE OF VARCHAR2(3) INDEX BY BINARY_INTEGER;
9572 l_primary_uom_code_tbl varchar3_tab;
9573 l_result BOOLEAN;
9574 -- LMS specific variable
9575 l_lms_rec_count NUMBER := 0;
9576 -- LMS code end
9577
9578
9579 BEGIN
9580 IF (l_debug = 1) THEN
9581 DEBUG('Entered complete_putaway_wrapper with the following params:', l_proc_name);
9582 DEBUG(' p_group_id ==> '||p_group_id, l_proc_name);
9583 DEBUG(' p_txn_header_id ==> '||p_txn_header_id,l_proc_name);
9584 DEBUG(' p_drop_type ==> '||p_drop_type,l_proc_name);
9585 DEBUG(' p_drop_type ==> '||p_drop_type,l_proc_name);
9586 DEBUG(' p_lpn_mode ==> '||p_lpn_mode,l_proc_name);
9587 DEBUG(' p_lpn_id ==> '||p_lpn_id,l_proc_name);
9588 DEBUG(' p_organization_id ==> '||p_organization_id,l_proc_name);
9589 DEBUG(' p_user_id ==> '||p_user_id,l_proc_name);
9590 DEBUG(' p_item_id ==> '||p_item_id,l_proc_name);
9591 DEBUG(' p_revision ==> '||p_revision,l_proc_name);
9592 DEBUG(' p_lot_number ==> '||p_lot_number,l_proc_name);
9593 DEBUG(' p_subinventory_code ==> '||p_subinventory_code,l_proc_name);
9594 DEBUG(' p_locator_id ==> '||p_locator_id,l_proc_name);
9595 DEBUG(' p_quantity ==> '||p_quantity,l_proc_name);
9596 DEBUG(' p_uom_code ==> '||p_uom_code,l_proc_name);
9597 DEBUG(' p_to_lpn_name ==> '||p_to_lpn_name,l_proc_name);
9598 DEBUG(' p_to_lpn_id ==> '||p_to_lpn_id,l_proc_name);
9599 DEBUG(' p_project_id ==> '||p_project_id,l_proc_name);
9600 DEBUG(' p_task_id ==> '||p_task_id,l_proc_name);
9601 DEBUG(' p_reference ==> '||p_reference, l_proc_name);
9602 DEBUG(' p_qty_reason_id ==> '||p_qty_reason_id,l_proc_name);
9603 DEBUG(' p_loc_reason_id ==> '||p_loc_reason_id,l_proc_name);
9604 DEBUG(' p_process_serial_flag ==> '||p_process_serial_flag,l_proc_name);
9605 DEBUG(' p_entire_lpn ==> '||p_entire_lpn,l_proc_name);
9606 DEBUG(' p_msni_txn_interface_id ==> '||p_msni_txn_interface_id,l_proc_name);
9607 DEBUG(' p_product_transaction_id ==> '||p_product_transaction_id,l_proc_name);
9608 DEBUG(' p_secondary_quantity ==> '||p_secondary_quantity,l_proc_name);
9609 DEBUG(' p_secondary_uom ==> '||p_secondary_uom,l_proc_name);
9610 DEBUG(' p_lpn_initially_loaded ==> '||p_lpn_initially_loaded,l_proc_name);
9611 END IF;
9612
9613 -- Initialize the return status
9614 x_return_status := FND_API.G_RET_STS_SUCCESS;
9615
9616 -- Read the input parameters
9617 l_group_id := p_group_id;
9618 l_product_transaction_id := p_product_transaction_id;
9619 l_serialized_item := FALSE;
9620 l_mo_splt_cnt := 0;
9621 l_lpn_serials_cnt := 0;
9622 l_skip_mmtt := FALSE;
9623
9624 IF (l_debug = 1) THEN
9625 DEBUG('Entering complete_putaway_wrapper. Entry time : ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), l_proc_name);
9626 END IF;
9627
9628 -- Create the save point
9629 SAVEPOINT complete_putaway_wrap_sp;
9630
9631 -- Assign p_lpn_mode to l_lpn_mode
9632 l_lpn_mode := p_lpn_mode;
9633
9634 -- For manual drops, since a load is not explicitly done first, we need
9635 -- to perform the activate and complete operation instance for load.
9636 -- We also then need to activate the drop operation.
9637 IF (p_drop_type = G_DT_MANUAL_DROP) THEN
9638 IF (l_debug = 1) THEN
9639 DEBUG('complete_putaway_wrapper: Activate/Complete operations for Manual Drop');
9640 END IF;
9641 l_progress := '5.1';
9642
9643 BEGIN
9644 SELECT employee_id
9645 INTO l_emp_id
9646 FROM fnd_user
9647 WHERE user_id = p_user_id;
9648 EXCEPTION
9649 WHEN NO_DATA_FOUND THEN
9650 IF (l_debug = 1) THEN
9651 DEBUG('complete_putaway_wrapper: There is no employee tied to the user');
9652 END IF;
9653 l_emp_id := NULL;
9654 END;
9655 IF (l_debug = 1) THEN
9656 DEBUG('complete_putaway_wrapper: Employee ID: ' || l_emp_id);
9657 END IF;
9658 l_progress := '5.2';
9659
9660 BEGIN -- Simulate Load Operation
9661 IF (l_debug = 1) THEN
9662 DEBUG('complete_putaway_wrapper: Calling Complete_ATF_Load API');
9663 END IF;
9664 l_progress := '5.3';
9665
9666 WMS_PUTAWAY_UTILS.Complete_ATF_Load
9667 (x_return_status => x_return_status,
9668 x_msg_count => x_msg_count,
9669 x_msg_data => x_msg_data,
9670 p_org_id => p_organization_id,
9671 p_lpn_id => p_lpn_id,
9672 p_emp_id => l_emp_id);
9673 IF (l_debug = 1) THEN
9674 DEBUG('complete_putaway_wrapper: Successfully called Complete_ATF_Load');
9675 END IF;
9676 l_progress := '5.4';
9677
9678 -- Check for the return status
9679 IF (l_debug = 1) THEN
9680 debug('complete_putaway_wrapper: Return status of API: ' || x_return_status);
9681 END IF;
9682
9683 IF x_return_status = fnd_api.g_ret_sts_success THEN
9684 -- Activate completed successfully.
9685 NULL;
9686 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
9687 RAISE fnd_api.g_exc_error;
9688 ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
9689 RAISE fnd_api.g_exc_unexpected_error;
9690 END IF;
9691 l_progress := '5.5';
9692 EXCEPTION
9693 WHEN OTHERS THEN
9694 RAISE fnd_api.g_exc_unexpected_error;
9695 END; -- Simulate Load Operation
9696
9697 BEGIN -- Activate operation for Drop
9698 IF (l_debug = 1) THEN
9699 DEBUG('complete_putaway_wrapper: Calling ATF_For_Manual_Drop API');
9700 END IF;
9701 l_progress := '5.6';
9702
9703 WMS_PUTAWAY_UTILS.ATF_For_Manual_Drop
9704 (x_return_status => x_return_status,
9705 x_msg_count => x_msg_count,
9706 x_msg_data => x_msg_data,
9707 p_call_type => G_ATF_ACTIVATE_PLAN,
9708 p_org_id => p_organization_id,
9709 p_lpn_id => p_lpn_id,
9710 p_emp_id => l_emp_id);
9711 IF (l_debug = 1) THEN
9712 DEBUG('complete_putaway_wrapper: Successfully called ATF_For_Manual_Drop');
9713 END IF;
9714
9715 l_progress := '5.7';
9716 IF (l_debug = 1) THEN
9717 debug('complete_putaway_wrapper: Return status of API: ' || x_return_status);
9718 END IF;
9719
9720 IF x_return_status = fnd_api.g_ret_sts_success THEN
9721 -- Activate op plan completed successfully.
9722 NULL;
9723 ELSIF x_return_status = fnd_api.g_ret_sts_error THEN
9724 RAISE fnd_api.g_exc_error;
9725 ELSIF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
9726 RAISE fnd_api.g_exc_unexpected_error;
9727 END IF;
9728 l_progress := '5.8';
9729 EXCEPTION
9730 WHEN OTHERS THEN
9731 RAISE fnd_api.g_exc_unexpected_error;
9732 END; -- Activate operation for Drop
9733 END IF; -- Manual Drop activate/complete operation instance
9734
9735 --For the item drop scenario, first check if there was a quantity discrepancy
9736 --and set the flag appropriately
9737 IF (p_drop_type = G_DT_ITEM_DROP) THEN
9738 BEGIN
9739 l_progress := '10';
9740
9741 --Get the primary_uom_code, lot_control_code and serial_control_code
9742 --for the item being dropped
9743 SELECT transaction_quantity
9744 , transaction_uom
9745 , primary_quantity
9746 , primary_uom_code
9747 , lot_control_code
9748 , serial_number_control_code
9749 , secondary_quantity --OPM Convergence
9750 , secondary_uom --OPM Convergence
9751 INTO l_sug_grp_quantity
9752 , l_grp_uom_code
9753 , l_grp_prm_quantity
9754 , l_primary_uom_code
9755 , l_lot_control_code
9756 , l_serial_control_code
9757 , l_grp_sec_quantity
9758 , l_grp_sec_uom
9759 FROM wms_putaway_group_tasks_gtmp
9760 WHERE group_id = p_group_id
9761 AND transaction_header_id = p_txn_header_id
9762 AND row_type = G_ROW_TP_GROUP_TASK;
9763
9764 IF (l_debug =1) THEN
9765 DEBUG('The suggested quantity for the group: ' || l_sug_grp_quantity, l_proc_name);
9766 DEBUG('lot code: ' || l_lot_control_code || ', serial code: ' || l_serial_control_code);
9767 END IF;
9768
9769 l_progress := '20';
9770
9771 --Convert the grp quantity into transaction uom
9772 IF l_grp_uom_code <> p_uom_code THEN
9773 l_uom_con_sug_grp_qty := inv_rcv_cache.convert_qty
9774 (p_inventory_item_id => p_item_id
9775 ,p_from_qty => l_sug_grp_quantity
9776 ,p_from_uom_code => l_grp_uom_code
9777 ,p_to_uom_code => p_uom_code);
9778 ELSE
9779 l_uom_con_sug_grp_qty := l_sug_grp_quantity;
9780 END IF;
9781
9782 l_progress := '30';
9783
9784 --Convert the confirmed quantity into primary uom
9785 IF (p_uom_code <> l_primary_uom_code) THEN
9786 l_prm_user_qty := inv_rcv_cache.convert_qty
9787 (p_inventory_item_id => p_item_id
9788 ,p_from_qty => p_quantity
9789 ,p_from_uom_code => p_uom_code
9790 ,p_to_uom_code => l_primary_uom_code);
9791 ELSE
9792 l_prm_user_qty := p_quantity;
9793 END IF;
9794 l_sec_user_qty := p_secondary_quantity; --OPM Convergence
9795 --Set the discrepancy flag if confirmed quantity does not match the
9796 --total quantity for the current group
9797 IF l_prm_user_qty <> l_grp_prm_quantity THEN
9798 l_disc := 'Y';
9799 ELSE
9800 l_disc := 'N';
9801 END IF;
9802
9803 EXCEPTION
9804 WHEN OTHERS THEN
9805 IF (l_debug = 1) THEN
9806 DEBUG('Error fetching MMTTs for the current group. Cannot drop', l_proc_name, 1);
9807 END IF;
9808 fnd_message.set_name('WMS', 'WMS_TASK_ERROR');
9809 fnd_msg_pub.add;
9810 RAISE FND_API.G_EXC_ERROR;
9811 END;
9812 ELSE
9813 --For other drop types, the user would not be confirming quantity and uom
9814 --We would be transacting only the suggested quantities. Only sub and loc
9815 --would be user entered. So, set the quantity discrepancy flag as 'N'
9816 l_disc := 'N';
9817 END IF; --END IF check qty discrepancy for item drop
9818
9819 l_progress := '40';
9820
9821 IF (l_debug = 1) THEN
9822 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress || '. Quantity Discrepancy flag: ' || l_disc, l_progress);
9823 END IF;
9824
9825 --Move Order Splits
9826 --For an item drop scenario, we would need to split the move order line under
9827 --the following scenarios:
9828 -- a) User confirmed lesser than the suggested quantity in the UI
9829 -- b) Part of the MO Line is detailed to an MMTT record in another group
9830 -- c) Move Order line is not completely detailed
9831 --We would need to split the move orders only for an item drop since
9832 --the user would be transacting the entire quantity for other drop types
9833
9834 --Decide on move order splits based on whether the item is serialized
9835 --This is needed since we will be matching the parent transactions with the
9836 --serials confirmed in the UI
9837 --The check for serialized item is needed only for a receiving LPN
9838 --We need this because for splitting move orders, we must first consume those
9839 --MOLS with serials of the parent txn
9840 --Eg. MOL1 has serials S1 - S5 with parent tranasction RT1 (rcv_serials_supply)
9841 -- MOL2 has serials S6 -S10 with parent transaction RT2
9842 -- User confirms S2, S6, S8 from the UI.
9843 --We should split MOL1 into MOL1 = 1 and create new line MOL3 for qty 4
9844 --We should split MOL2 into MOL2 = 2 and create new line MOL4 for qty 3
9845 --Later we would match the the serials S1, S6 and S8 against the parent txn
9846 --Even for a receiving LPN, if the user confirms the entire quantity, we
9847 --would be splitting the move order lines as if it were a non-serialized item
9848 --since the serials are anyway matched and only the quantity needs to be
9849 --matched.
9850 IF (p_drop_type = G_DT_ITEM_DROP) THEN
9851 --{
9852
9853 -- BUG 5198628
9854 -- Get the serialized flag irrespective of l_disc
9855 IF (p_lpn_context = G_LPN_CONTEXT_RCV) THEN
9856 --Bug 5208888
9857 --For internal receipts, serials would be populated even if the serial control
9858 --code is dynamic at SO issue
9859 IF (l_serial_control_code = 6) THEN
9860 SELECT count(1)
9861 INTO l_lpn_serials_cnt
9862 FROM mtl_serial_numbers
9863 WHERE lpn_id = p_lpn_id
9864 AND inventory_item_id = p_item_id;
9865 END IF;
9866 IF ((l_serial_control_code IN (2, 5)) OR
9867 (l_serial_control_code = 6 AND p_reference = 'ORDER_LINE_ID') OR
9868 (l_serial_control_code = 6 AND p_reference = 'SHIPMENT_LINE_ID' AND
9869 l_lpn_serials_cnt > 0)) THEN
9870 l_serialized_item := TRUE;
9871 ELSE
9872 l_serialized_item := FALSE;
9873 END IF;
9874 ELSE
9875 l_serialized_item := FALSE;
9876 END IF;
9877 -- bug 5333789
9878 -- ELSE
9879 -- l_serialized_item := FALSE;
9880 -- END IF;
9881
9882 -- IF (l_disc = 'Y' ) THEN
9883 -- bug 5333789
9884
9885 --Initialize the remaining quantity in primary uom
9886 l_rem_user_qty := l_prm_user_qty;
9887
9888 IF (l_debug = 1) THEN
9889 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress || '. Item Drop scenario. Checking if MO Splits are required', l_proc_name);
9890 END IF;
9891
9892 --The logic would be different based on whether the item is serial controlled or not
9893 -- IF (l_serialized_item) THEN bug 5333789
9894 IF (l_serialized_item and l_disc = 'Y') THEN
9895 --{
9896 IF (l_debug = 1) THEN
9897 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress || '. Processing the MO lines for a serialized item', l_proc_name);
9898 END IF;
9899
9900 l_progress := '50';
9901
9902 --R12: Find out the serials entered by the user in the UI,
9903 --grouping by their inspection_status and lot_number
9904 SELECT count(1), Nvl(msn.inspection_status,-1), Nvl(msn.lot_number,'&*_')
9905 bulk collect INTO l_msni_qty_tbl, l_msni_inspect_status_tbl, l_msni_lot_tbl
9906 FROM mtl_serial_numbers_interface msni, mtl_serial_numbers msn
9907 WHERE msni.transaction_interface_id = p_msni_txn_interface_id
9908 AND msn.serial_number BETWEEN msni.fm_serial_number AND Nvl(msni.to_serial_number,msni.fm_serial_number)
9909 AND Length(msn.serial_number) = Length(msni.fm_serial_number)
9910 GROUP BY msn.inspection_status, msn.lot_number;
9911
9912 IF (l_debug = 1) THEN
9913 debug('Number of serial groups:'||l_msni_qty_tbl.COUNT,l_proc_name);
9914 END IF;
9915
9916 --R12: Loop through each group of serials and find
9917 --the MOL to consume
9918 FOR i IN 1..l_msni_inspect_status_tbl.COUNT LOOP
9919
9920 IF (l_debug = 1) THEN
9921 debug('Group ('||i||') Number:'||l_msni_qty_tbl(i)||' Inspect Status:'||
9922 l_msni_inspect_status_tbl(i)||' lot NUMBER:'
9923 ||l_msni_lot_tbl(i),l_proc_name);
9924 END IF;
9925
9926 --Processing for a serialized item
9927
9928 OPEN serial_mol_csr(l_msni_inspect_status_tbl(i),l_msni_lot_tbl(i));
9929
9930 LOOP
9931 FETCH serial_mol_csr
9932 INTO l_mol_line_id
9933 , l_mol_qty
9934 , l_mol_qty_detailed
9935 , l_mol_qty_delivered
9936 , l_mol_uom_code
9937 , l_mol_sec_qty --OPM Convergence
9938 , l_mol_sec_qty_detailed --OPM Convergence
9939 , l_mol_sec_qty_delivered --OPM Convergence
9940 , l_mol_sec_uom_code;
9941 EXIT WHEN serial_mol_csr%NOTFOUND;
9942
9943 l_progress := '60';
9944
9945 --Have consumed the entire quantity confirmed and marked the temp table records
9946 IF l_rem_user_qty = 0 OR l_msni_qty_tbl(i) = 0 THEN
9947 EXIT;
9948 END IF;
9949
9950 IF (l_debug = 1) THEN
9951 DEBUG('complete_putaway_wrapper: Working with mol: ' || l_mol_line_id ||
9952 ' qty: ' || l_mol_qty || ' qty det: ' || l_mol_qty_detailed || ' qty del: '
9953 || l_mol_qty_delivered || ' uom_code: ' || l_mol_uom_code, l_proc_name);
9954 END IF;
9955
9956 --First get the difference between the quantity and quantity delivered
9957 l_tmp_qty1 := l_mol_qty - l_mol_qty_delivered;
9958
9959 l_progress := '70';
9960
9961 --Convert this into primary uom
9962 IF (l_mol_uom_code <> l_primary_uom_code) THEN
9963 l_tmp_prm_qty := inv_rcv_cache.convert_qty
9964 (p_inventory_item_id => p_item_id
9965 ,p_from_qty => l_tmp_qty1
9966 ,p_from_uom_code => l_mol_uom_code
9967 ,p_to_uom_code => l_primary_uom_code
9968 );
9969 ELSE
9970 l_tmp_prm_qty := l_tmp_qty1;
9971 END IF;
9972
9973 IF(l_debug = 1) THEN
9974 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress ||
9975 '. Available MO quantity for this group: ' || l_tmp_prm_qty, l_proc_name);
9976 END IF;
9977
9978 l_progress := '80';
9979
9980 --Now that we are ready with quantity calculations, mark the all tasks
9981 --in the current group for this move order line
9982 UPDATE wms_putaway_group_tasks_gtmp
9983 SET process_flag = 'Y'
9984 WHERE group_id = p_group_id
9985 AND transaction_header_id = p_txn_header_id
9986 AND move_order_line_id = l_mol_line_id;
9987
9988 IF l_tmp_prm_qty <= l_msni_qty_tbl(i) THEN
9989 --Consumed the entire MOL qty. Still need to check other MOLs
9990 l_rem_user_qty := l_rem_user_qty - l_tmp_prm_qty;
9991 l_msni_qty_tbl(i) := l_msni_qty_tbl(i) - l_tmp_prm_qty;
9992 ELSE
9993 --OK. The total available quantity is greater than the confirmed quantity
9994 --We have to split the move order line. So populate the table
9995 l_mo_splt_cnt := l_mo_splt_cnt + 1;
9996
9997 --MOL.qty = 10, MOL.qty_delivered = 4. remaining user qty = 3
9998 --So we need to split the mol and create a mew one for 10-4-3 = 3
9999 l_qty_to_split := l_tmp_prm_qty - l_msni_qty_tbl(i);
10000
10001 --First decrement the remaining quantity
10002 l_rem_user_qty := l_rem_user_qty - l_msni_qty_tbl(i);
10003 l_msni_qty_tbl(i) := 0;
10004
10005 IF (l_debug = 1) THEN
10006 DEBUG('complete_putaway_wrapper: Need to split the move order line id: '
10007 || l_mol_line_id || ' with qty: ' || l_qty_to_split, l_proc_name);
10008 END IF;
10009
10010 l_mos_to_split_tbl(l_mo_splt_cnt).line_id := l_mol_line_id;
10011 l_mos_to_split_tbl(l_mo_splt_cnt).prim_qty := l_qty_to_split;
10012 END IF; --END IF compare the remaining qty with available qty
10013 END LOOP; --END loop through each mol for the current group
10014
10015 IF l_msni_qty_tbl(i) > 0 THEN
10016 IF(l_debug = 1) THEN
10017 DEBUG('complete_putaway_wrapper: Unable to match MOL for all serial IN the group! How?',l_proc_name);
10018 END IF;
10019 RAISE fnd_api.g_exc_error;
10020 END IF;
10021 END LOOP;
10022
10023 --MO Splits for a non-serialized item
10024 --}
10025 ELSE
10026 --{
10027 l_progress := '90';
10028
10029 --Processing for a non-serialized item
10030 IF (l_debug = 1) THEN
10031 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress ||
10032 '. Processing the MO lines for a non-serialized item', l_proc_name);
10033 END IF;
10034
10035 OPEN mol_csr;
10036 LOOP
10037 FETCH mol_csr
10038 INTO l_mol_line_id
10039 , l_mol_qty
10040 , l_mol_qty_detailed
10041 , l_mol_qty_delivered
10042 , l_mol_uom_code
10043 , l_mol_sec_qty --OPM Convergence
10044 , l_mol_sec_qty_detailed --OPM Convergence
10045 , l_mol_sec_qty_delivered --OPM Convergence
10046 , l_mol_sec_uom_code; --OPM Convergence
10047 EXIT WHEN mol_csr%NOTFOUND;
10048
10049 --Have consumed the entire quantity confirmed and marked the temp table records
10050 IF l_rem_user_qty = 0 THEN
10051 EXIT;
10052 END IF;
10053
10054 --BUG 5075410: MOL1 has 6, MMTT1 3 LOC1 MMTT2 3 LOC2
10055 -- MOL2 has 3, MMTT3 3 LOC1
10056 --System would suggest task for 6 to LOC1, 3 to LOC2
10057 --If the user enter 5 for the first task, then we cannot
10058 --just use the 5 from MOL1. We must use 3 from MOL1 and
10059 --2 from MOL2, or vice versa. So the following check is
10060 --needed to find out the quantity from the MOL that is
10061 --suggested for the current group of tasks
10062 BEGIN
10063 SELECT SUM(mmtt.primary_quantity)
10064 INTO l_prim_qty_consumable
10065 FROM mtl_material_transactions_temp mmtt
10066 , mtl_txn_request_lines mtrl
10067 WHERE mmtt.transaction_header_id = p_txn_header_id
10068 AND mtrl.line_id = l_mol_line_id
10069 AND mtrl.line_id = mmtt.move_order_line_id;
10070 EXCEPTION
10071 WHEN OTHERS THEN
10072 IF (l_debug = 1) THEN
10073 debug('Error querying total consumable qty. SQLCODE:'||SQLCODE||' Sqlerrm:'||SQLERRM,l_proc_name,1);
10074 END IF;
10075 END;
10076
10077 IF (l_debug = 1) THEN
10078 DEBUG('complete_putaway_wrapper: Working with mol: ' || l_mol_line_id ||
10079 ' qty: ' || l_mol_qty || ' qty det: ' || l_mol_qty_detailed || ' qty del: '
10080 || l_mol_qty_delivered || ' uom_code: ' || l_mol_uom_code||
10081 ' consumable qty'||l_prim_qty_consumable, l_proc_name);
10082 END IF;
10083
10084 --First get the difference between the quantity and quantity delivered
10085 l_tmp_qty1 := l_mol_qty - l_mol_qty_delivered;
10086
10087 --Convert this into primary uom
10088 IF (l_mol_uom_code <> l_primary_uom_code) THEN
10089 l_tmp_prm_qty := inv_rcv_cache.convert_qty
10090 (p_inventory_item_id => p_item_id
10091 ,p_from_qty => l_tmp_qty1
10092 ,p_from_uom_code => l_mol_uom_code
10093 ,p_to_uom_code => l_primary_uom_code);
10094 ELSE
10095 l_tmp_prm_qty := l_tmp_qty1;
10096 END IF;
10097
10098 /*OPM Convergence get the difference between the secondary quantity
10099 and the secondary quantity delivered. */
10100 l_tmp_sec_qty := l_mol_sec_qty - l_mol_sec_qty_delivered;
10101
10102 l_progress := '100';
10103
10104 IF(l_debug = 1) THEN
10105 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress ||
10106 '. Available MO quantity for this group: ' || l_tmp_prm_qty, l_proc_name);
10107 END IF;
10108
10109 --Now that we are ready with quantity calculations, mark the all tasks
10110 --in the current group for this move order line
10111 UPDATE wms_putaway_group_tasks_gtmp
10112 SET process_flag = 'Y'
10113 WHERE group_id = p_group_id
10114 AND transaction_header_id = p_txn_header_id
10115 AND move_order_line_id = l_mol_line_id;
10116
10117 IF l_prim_qty_consumable <= l_rem_user_qty THEN
10118 l_rem_user_qty := l_rem_user_qty - l_prim_qty_consumable;
10119
10120 IF (l_prim_qty_consumable < l_tmp_prm_qty) THEN
10121 l_qty_to_split := l_tmp_prm_qty - l_prim_qty_consumable;
10122 IF (l_debug = 1) THEN
10123 DEBUG('complete_putaway_wrapper: Need to split the move order line id: '
10124 || l_mol_line_id || ' with qty: ' || l_qty_to_split, l_proc_name);
10125 END IF;
10126
10127 l_mo_splt_cnt := l_mo_splt_cnt + 1;
10128 l_mos_to_split_tbl(l_mo_splt_cnt).line_id := l_mol_line_id;
10129 l_mos_to_split_tbl(l_mo_splt_cnt).prim_qty := l_qty_to_split;
10130 END IF;
10131 ELSE
10132 --OK. The total available quantity is greater than the confirmed quantity
10133 --We have to split the move order line. So populate the table
10134 l_mo_splt_cnt := l_mo_splt_cnt + 1;
10135
10136 --MOL.qty = 10, MOL.qty_delivered = 4. remaining user qty = 3
10137 --So we need to split the mol and create a mew one for 10-4-3 = 3
10138 l_qty_to_split := l_tmp_prm_qty - l_rem_user_qty;
10139
10140 IF (l_debug = 1) THEN
10141 DEBUG('complete_putaway_wrapper: Need to split the move order line id: '
10142 || l_mol_line_id || ' with qty: ' || l_qty_to_split, l_proc_name);
10143 END IF;
10144
10145 l_mos_to_split_tbl(l_mo_splt_cnt).line_id := l_mol_line_id;
10146 l_mos_to_split_tbl(l_mo_splt_cnt).prim_qty := l_qty_to_split;
10147
10148 --Non-serialized item. Only one MO line can be split
10149 l_rem_user_qty := 0;
10150 END IF; --END IF compare remaining qty and MOL qty
10151 END LOOP; --END loop through each mol for the current group
10152 --}
10153 END IF; --END IF MO processing based on serialized flag
10154
10155 IF (l_rem_user_qty > 0) THEN
10156 IF (l_debug = 1) THEN
10157 DEBUG('complete_putaway_wrapper: l_rem_user_qty > 0. Unable to find MOL for qty. There must be some data corruption'||l_proc_name);
10158 END IF;
10159 RAISE fnd_api.g_exc_error;
10160 END IF;
10161
10162 --Close the mol cursor
10163 IF mol_csr%ISOPEN THEN
10164 CLOSE mol_csr;
10165 END IF;
10166
10167 IF serial_mol_csr%ISOPEN THEN
10168 CLOSE serial_mol_csr;
10169 END IF;
10170
10171 --If at all any move order lines belonging to the current group have been
10172 --identified for splits, they would have been populated in the PL/SQL table
10173 --Loop through each and call the split_mo API to split the move order lines
10174 --Pass two additional parameters that are needed to sync up the
10175 --global temporary table with the move order lines/MMTTs so that when we
10176 --actually loop through the tasks in the group, they will reflect the changes
10177 IF (l_debug = 1) THEN
10178 DEBUG('complete_putaway_wrapper: Count of move order lines that need to be split: ' || l_mo_splt_cnt, l_proc_name);
10179 END IF;
10180
10181 l_progress := '110';
10182
10183 IF (l_mo_splt_cnt > 0) THEN
10184 FOR i IN 1 .. l_mo_splt_cnt LOOP
10185 l_qty_to_split := l_mos_to_split_tbl(i).prim_qty;
10186 l_mo_splt_tb(1).prim_qty := l_qty_to_split;
10187 --Call the Split_MO API
10188 IF (l_debug = 1) THEN
10189 debug('complete_putaway_wrapper: Progress: ' || l_progress ||
10190 '. Calling the split_mo API with primary qty: ' || l_qty_to_split, 4);
10191 END IF;
10192
10193 inv_rcv_integration_apis.split_mo(
10194 p_orig_mol_id => l_mos_to_split_tbl(i).line_id
10195 , p_mo_splt_tb => l_mo_splt_tb
10196 , p_updt_putaway_temp_tbl => FND_API.G_TRUE
10197 , p_txn_header_id => p_txn_header_id
10198 , x_return_status => x_return_status
10199 , x_msg_count => x_msg_count
10200 , x_msg_data => x_msg_data);
10201
10202 IF (l_debug = 1) THEN
10203 DEBUG('complete_putaway_wrapper: split_mo API return status: ' || x_return_status, 4);
10204 END IF;
10205
10206 IF x_return_status = fnd_api.g_ret_sts_error THEN
10207 RAISE fnd_api.g_exc_error;
10208 END IF;
10209
10210 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
10211 RAISE fnd_api.g_exc_unexpected_error;
10212 END IF;
10213
10214 IF (l_debug = 1) THEN
10215 DEBUG('complete_putaway_wrapper: new MOL ID: ' || l_mo_splt_tb(1).line_id, 4);
10216 END IF;
10217
10218 --Bug 5075410: Cannot cleanup here because say 1 MOL
10219 --have two MMTT, then complete 1 of the task would cause
10220 --cleanup of the other MMTT, and transaction will fail
10221 --when user tries to complete the second task
10222 END LOOP; --END Loop through each MOL identified for split
10223 END IF; --END IF l_mo_splt_cnt > 0
10224 -- bug 5333789
10225 --}
10226 ELSE
10227 --{
10228 l_serialized_item := FALSE;
10229 --}
10230 -- bug 5333789
10231 END IF; --END IF p_drop_type = G_DT_ITEM_DROP AND l_disc = 'Y'
10232
10233 --Now that the MO splits are done, we have the temp table in sync and we
10234 --know the rows that we need to process.
10235
10236 l_progress := '120';
10237
10238 --Get the lpn_controlled_flag and subinventory_type attributes for the
10239 --destination subinventory
10240 BEGIN
10241 SELECT NVL(lpn_controlled_flag, 1)
10242 , NVL(subinventory_type, 1)
10243 INTO l_lpn_controlled_flag
10244 , l_drop_sub_type
10245 FROM mtl_secondary_inventories
10246 WHERE organization_id = p_organization_id
10247 AND secondary_inventory_name = p_subinventory_code;
10248 EXCEPTION
10249 WHEN OTHERS THEN
10250 l_lpn_controlled_flag := 2;
10251 END;
10252
10253 IF (p_lpn_context IN (G_LPN_CONTEXT_INV, G_LPN_CONTEXT_WIP)) THEN
10254
10255 SELECT mtl_material_transactions_s.NEXTVAL
10256 INTO l_new_txn_header_id
10257 FROM DUAL;
10258
10259 --For an item drop of an Inventory/WIP LPN with quantity
10260 --discrepancy/partial lpn drop,
10261 --we would have marked the serials in UI. Have to first fetch all such
10262 --serials and then consume these for each task on a FIFO basis.
10263 --Basically, no matching is needed unlike receiving LPNs
10264 IF ((p_drop_type = G_DT_ITEM_DROP) AND (l_disc = 'Y' OR p_entire_lpn = 'N') AND
10265 (l_serial_control_code IN (2,5))) THEN
10266
10267 l_progress := '130';
10268
10269 IF (l_debug = 1) THEN
10270 DEBUG('complete_putaway_wrapper: Progress: ' ||l_progress ||'. Process Serials', l_proc_name);
10271 END IF;
10272
10273 OPEN msnt_ser_csr(p_lpn_id, p_item_id);
10274 FETCH msnt_ser_csr
10275 BULK COLLECT INTO l_ser_num_tbl, l_ser_mark_tbl;
10276
10277 IF (l_debug = 1) THEN
10278 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress || '. Serial item partial qty. '
10279 || l_ser_num_tbl.COUNT || ' serials confirmed in UI', l_proc_name);
10280 END IF;
10281 END IF;
10282 ELSE
10283 --For a reveiving LPN, setting l_new_txn_header_id to the parameter.
10284 --This is not actually needed since for receiving LPNs, a new txn_hdr_id
10285 --would always be created for each MMTT we process.
10286 l_new_txn_header_id := p_txn_header_id;
10287
10288 --R12: Open the rcv_serials_csr here. It will be used later
10289 --when we try to match serials with the MMTT quantitty
10290 IF (p_drop_type = g_dt_item_drop AND
10291 l_disc = 'Y'AND
10292 ((l_serial_control_code > 1 AND l_serial_control_code <> 6) OR
10293 (l_serial_control_code = 6 AND p_reference = 'ORDER_LINE_ID') OR
10294 (l_serial_control_code = 6 AND p_reference = 'SHIPMENT_LINE_ID' AND l_lpn_serials_cnt > 0))) THEN
10295
10296 OPEN rcv_serials_csr;
10297 FETCH rcv_serials_csr
10298 BULK COLLECT INTO l_ser_num_tbl, l_ser_mark_tbl,l_ser_inspect_status_tbl,l_ser_lot_num_tbl;
10299
10300 DELETE FROM mtl_serial_numbers_interface
10301 WHERE transaction_interface_id = p_msni_txn_interface_id;
10302
10303 IF (l_debug = 1) THEN
10304 debug('Number of MSNI deleted: '||SQL%rowcount,l_proc_name,9);
10305 END IF;
10306 END IF;
10307 END IF; --END IF Inventory/WIP LPNs
10308
10309 IF (msnt_ser_csr%ISOPEN) THEN
10310 CLOSE msnt_ser_csr;
10311 END IF;
10312
10313 --Nested LPN changes
10314 pre_process_lpn(
10315 x_return_status => x_return_status
10316 , x_msg_count => x_msg_count
10317 , x_msg_data => x_msg_data
10318 , p_from_lpn_id => p_lpn_id
10319 , p_organization_id => p_organization_id
10320 , p_subinventory_code => p_subinventory_code
10321 , p_lpn_mode => l_lpn_mode
10322 , p_locator_id => p_locator_id
10323 , p_to_lpn_id => p_to_lpn_id
10324 , p_project_id => p_project_id
10325 , p_task_id => p_task_id
10326 , p_user_id => p_user_id
10327 , p_lpn_context => p_lpn_context
10328 , p_batch_id => l_new_txn_header_id
10329 , p_batch_seq => 1
10330 , p_pack_trans_id => l_new_txn_header_id
10331 , x_batch_seq => l_batch_seq ); --BUG 3544918
10332 IF (l_debug = 1) THEN
10333 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress || '. pre_process_lpn returns: ' || x_return_status, 4);
10334 END IF;
10335
10336 IF x_return_status = fnd_api.g_ret_sts_error THEN
10337 RAISE fnd_api.g_exc_error;
10338 END IF;
10339
10340 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
10341 RAISE fnd_api.g_exc_unexpected_error;
10342 END IF;
10343 -- Nested LPN changes end;
10344
10345 --We should be calling complete_putaway for the eligible rows
10346 --Based on the drop type, open the appropriate cursors
10347 IF (p_drop_type IN (G_DT_CONSOLIDATED_DROP, G_DT_ITEM_DROP)) THEN
10348 OPEN all_tasks_csr(l_disc);
10349 ELSIF (p_drop_type IN (G_DT_USER_DROP, G_DT_MANUAL_DROP)) THEN
10350 IF (l_debug = 1) THEN
10351 DEBUG('complete_putaway_wrapper: Manual Drop case. Opening the md_tasks_csr to fetch the tasks', l_proc_name);
10352 END IF;
10353 OPEN md_tasks_csr;
10354 END IF;
10355
10356 --Fetch all the tasks for the current group being putaway
10357 --LOOP
10358 IF (p_drop_type IN (G_DT_CONSOLIDATED_DROP, G_DT_ITEM_DROP)) THEN
10359 l_progress := 140;
10360 IF (l_debug = 1) THEN
10361 DEBUG('complete_putaway_wrapper: Fetching the all_tasks_csr...', l_proc_name);
10362 END IF;
10363 FETCH all_tasks_csr
10364 BULK COLLECT INTO
10365 l_temp_id_tbl
10366 , l_mol_lpn_id_tbl
10367 , l_mol_line_id_tbl
10368 , l_mmtt_item_id_tbl
10369 , l_mmtt_rev_tbl
10370 , l_mmtt_lot_tbl
10371 , l_mmtt_qty_tbl
10372 , l_mmtt_uom_tbl
10373 , l_parent_txn_id_tbl
10374 , l_bk_del_det_tbl
10375 , l_xdock_type_tbl
10376 , l_wip_sup_typ_tbl
10377 , l_mmtt_sec_qty_tbl
10378 , l_inspection_status_tbl
10379 , l_primary_uom_code_tbl;
10380 --EXIT WHEN all_tasks_csr%NOTFOUND;
10381 ELSIF (p_drop_type IN (G_DT_USER_DROP, G_DT_MANUAL_DROP)) THEN
10382 l_progress := '150';
10383 IF (l_debug = 1) THEN
10384 DEBUG('complete_putaway_wrapper: Fetching the md_tasks_csr...', l_proc_name);
10385 END IF;
10386 FETCH md_tasks_csr
10387 BULK COLLECT INTO
10388 l_temp_id_tbl
10389 , l_mol_lpn_id_tbl
10390 , l_mol_line_id_tbl
10391 , l_mmtt_item_id_tbl
10392 , l_mmtt_rev_tbl
10393 , l_mmtt_lot_tbl
10394 , l_mmtt_qty_tbl
10395 , l_mmtt_uom_tbl
10396 , l_parent_txn_id_tbl
10397 , l_bk_del_det_tbl
10398 , l_xdock_type_tbl
10399 , l_wip_sup_typ_tbl
10400 , l_mmtt_sec_qty_tbl
10401 , l_inspection_status_tbl
10402 , l_primary_uom_code_tbl;
10403 --EXIT WHEN md_tasks_csr%NOTFOUND;
10404 END IF;
10405
10406 --At this stage, I know the list of 'All Task' rows for the current group.
10407 --Will be fetching the details of each task, do the calculations and call
10408 --the complete_putaway for the current task
10409 IF (l_debug = 1) THEN
10410 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress || 'No. of tasks for this group: ' || l_temp_id_tbl.COUNT, l_proc_name);
10411 END IF;
10412
10413 IF (l_temp_id_tbl.COUNT = 0) THEN
10414 fnd_message.set_name('WMS', 'WMS_TASK_ERROR');
10415 fnd_msg_pub.ADD;
10416 END IF;
10417
10418 IF (p_drop_type = G_DT_ITEM_DROP) THEN
10419 --First get the total drop quantity in transaction uom
10420 l_remaining_qty := p_quantity;
10421 l_remaining_sec_qty := p_secondary_quantity;
10422 END IF;
10423
10424 FOR i IN 1 .. l_temp_id_tbl.COUNT
10425 LOOP
10426
10427 l_mmtt_temp_id := l_temp_id_tbl(i);
10428 l_item_id := l_mmtt_item_id_tbl(i);
10429 l_product_transaction_id := p_product_transaction_id;
10430 --Initialize the count of serials to be consumed for the current task
10431 l_cur_task_ser_count := 0;
10432
10433 --After inspecting a serialized item, there is one MO line for each serial inspected.
10434 --If the user confirms partial quantity, then we might be fetching a move order line
10435 --whose parent RT record might not correspond to the serial confirmed on the UI.
10436 -- eg: MO1 RT1 1 Ea SN1, MO2 RT2 1 Ea SN2, MO3 RT3 1 Ea SN3
10437 --If the user confirms the serials SN1 and SN3 on the UI, we should create deliver
10438 --RTIs only for RT1 and RT3. But we might have MMTT corresponding to MO2 fetched by
10439 --the tasks cursor. In which case, we would not be able to match the serials with the
10440 --parent transaction. So we should not call the complete_putaway API for this MMTT.
10441 --For this purpose have created the flag below which would always be FALSE
10442 --and will be set only if no serials can be matched for the current move order line
10443 l_skip_mmtt := FALSE;
10444
10445 l_progress := '160';
10446 IF (l_debug = 1) THEN
10447 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress || '. Am working on the task with temp_id: ' || l_mmtt_temp_id, l_proc_name);
10448 END IF;
10449
10450 --Process the current task based on the drop type
10451 IF (p_drop_type = G_DT_ITEM_DROP) THEN
10452
10453 --If I have consumed the entire drop quantity confirmed by the user
10454 --should be coming out of the processing loop
10455 IF (l_remaining_qty = 0) THEN
10456 IF (l_debug = 1) THEN
10457 DEBUG('complete_putaway_wrapper: Have consumed entire quantity confirmed by the user. No further processing', l_proc_name);
10458 END IF;
10459 EXIT;
10460 END IF;
10461
10462 IF (l_debug =1) THEN
10463 DEBUG('complete_putaway_wrapper: Qty still to drop: ' || l_remaining_qty, l_proc_name);
10464 END IF;
10465
10466 --Convert the current task quantity into the user confirmed UOM code
10467 IF (l_mmtt_uom_tbl(i) <> p_uom_code) THEN
10468 l_quantity := inv_rcv_cache.convert_qty
10469 (p_inventory_item_id => l_mmtt_item_id_tbl(i)
10470 ,p_from_qty => l_mmtt_qty_tbl(i)
10471 ,p_from_uom_code => l_mmtt_uom_tbl(i)
10472 ,p_to_uom_code => p_uom_code);
10473 ELSE
10474 l_quantity := l_mmtt_qty_tbl(i);
10475 END IF;
10476
10477 IF (l_debug = 1) THEN
10478 DEBUG('Item Drop - Current Task quantity: ' || l_quantity, l_proc_name);
10479 END IF;
10480
10481 l_progress := '170';
10482
10483 IF (l_disc = 'Y' OR p_entire_lpn = 'N') THEN
10484 SELECT mtl_material_transactions_s.NEXTVAL
10485 INTO l_dummy_temp_id
10486 FROM dual;
10487 END IF;
10488
10489 IF (l_quantity <= l_remaining_qty) THEN
10490 l_remaining_qty := l_remaining_qty - l_quantity;
10491 ELSE --Is this possible?
10492 l_remaining_qty := l_quantity;
10493 END IF;
10494
10495 --Set the rev, lot, sub and loc from the values confirmed in the UI
10496 l_lpn_id := l_mol_lpn_id_tbl(i);
10497 l_entire_lpn := p_entire_lpn;
10498 l_revision := p_revision;
10499 l_lot_number := p_lot_number;
10500 l_uom_code := p_uom_code;
10501 l_subinventory_code := p_subinventory_code;
10502 l_locator_id := p_locator_id;
10503
10504 --If user scans the same LPN in case of quantity discrepancy, we need
10505 --to stamp the transfer_lpn_id and not content_lpn_id. This will
10506 --be done through the p_entire_lpn_flag. Reference - Bug #2310097
10507 IF (l_disc = 'Y' and l_entire_lpn = 'Y') THEN
10508 l_entire_lpn := 'N';
10509 END IF;
10510
10511 --In case of a quantity discrepancy for a lot/serialized items,
10512 --have to create the interface records for lots and serials from
10513 --here itself and we would not be doing it from complete_putaway
10514 --More importantly, do it only if there is a quantity discrepancy
10515 --Also create interface record if entire_lpn is 'N'
10516 IF (l_disc = 'Y' OR p_entire_lpn = 'N') THEN
10517 --Convert the task quantity into primary uom
10518 IF (l_mmtt_uom_tbl(i) <> l_primary_uom_code) THEN
10519 l_mmtt_prm_qty := inv_rcv_cache.convert_qty
10520 (p_inventory_item_id => l_mmtt_item_id_tbl(i)
10521 ,p_from_qty => l_mmtt_qty_tbl(i)
10522 ,p_from_uom_code => l_mmtt_uom_tbl(i)
10523 ,p_to_uom_code => l_primary_uom_code);
10524 ELSE
10525 l_mmtt_prm_qty := l_mmtt_qty_tbl(i);
10526 END IF; --END IF UOM conversions for lot quantity
10527 l_mmtt_sec_qty := l_mmtt_qty_tbl(i); --OPM Convergence
10528
10529 IF (p_lpn_context = G_LPN_CONTEXT_RCV) THEN
10530 --On inspecting a serialized item, one move order line is created for each
10531 --serial number. When the user confirms the serials on the UI, we generate
10532 --one single product_transaction_id for all such serials. However, when we
10533 --create the RTI records for these we have to associate only that serial
10534 --number corresponding to the parent transaction. So in such cases, we have to
10535 --generate a new value of product_transaction_id while updating the MSNI
10536 --ramarava
10537 IF (l_serialized_item AND l_mmtt_prm_qty = 1) THEN
10538 SELECT rcv_transactions_interface_s.NEXTVAL
10539 INTO l_product_transaction_id
10540 FROM sys.dual;
10541 END IF;
10542
10543 --Insert MSNI for receiving LPN
10544 IF (l_lot_control_code > 1 AND p_lot_number IS NOT NULL) THEN
10545 l_progress := '180';
10546 IF (l_debug =1) THEN
10547 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress ||
10548 ' Have to create MTLIs for prm qty ' || l_mmtt_prm_qty, l_proc_name);
10549 END IF;
10550
10551 --Get the lot expiration date and lot status
10552 SELECT expiration_date
10553 , status_id
10554 INTO l_lot_expiration_date
10555 , l_lot_status_id
10556 FROM mtl_lot_numbers
10557 WHERE lot_number = p_lot_number
10558 AND inventory_item_id = p_item_id
10559 AND organization_id = p_organization_id;
10560
10561 --Call the insert_mtli API to insert the lot_number in MTLI
10562 inv_rcv_integration_apis.insert_mtli(
10563 p_api_version => 1.0
10564 , p_init_msg_lst => FND_API.G_FALSE
10565 , x_return_status => x_return_status
10566 , x_msg_count => x_msg_count
10567 , x_msg_data => x_msg_data
10568 , p_transaction_interface_id => l_dummy_temp_id --l_mmtt_temp_id
10569 , p_lot_number => p_lot_number
10570 , p_transaction_quantity => l_mmtt_qty_tbl(i)
10571 , p_primary_quantity => l_mmtt_prm_qty
10572 , p_organization_id => p_organization_id
10573 , p_inventory_item_id => p_item_id
10574 , p_expiration_date => l_lot_expiration_date
10575 , p_status_id => l_lot_status_id
10576 , x_serial_transaction_temp_id => l_serial_temp_id
10577 , p_product_transaction_id => l_product_transaction_id
10578 , p_product_code => 'RCV'
10579 , p_att_exist => 'Y'
10580 , p_update_mln => 'N'
10581 , p_secondary_quantity => l_mmtt_sec_qty); --OPM CONVERGENCE
10582
10583 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
10584 IF (l_debug = 1) THEN
10585 DEBUG('complete_putaway_wrapper: Error at progress: ' || l_progress ||
10586 ' insert_mtli returns g_exc_error', l_proc_name, 1);
10587 END IF;
10588 RAISE FND_API.G_EXC_ERROR;
10589 END IF;
10590
10591 IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10592 IF (l_debug = 1) THEN
10593 DEBUG('complete_putaway_wrapper: Error at progress: ' || l_progress ||
10594 ' insert_mtli returns g_unexp_error', l_proc_name, 1);
10595 END IF;
10596 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10597 END IF;
10598
10599 IF (l_debug = 1) THEN
10600 DEBUG('complete_putaway_wrapper: Inserted MTLI intf_txn_id: ' || l_transaction_interface_id ||
10601 ', ser_temp_id : ' || l_serial_temp_id || ' , prod_txn_id: ' || l_product_transaction_id);
10602 END IF;
10603 END IF; --END Insert MTLI for receiving LPN
10604
10605 --Match serial numbers for receiving LPN
10606 IF ((l_serial_control_code > 1 AND l_serial_control_code <> 6) OR
10607 (l_serial_control_code = 6 AND p_reference = 'ORDER_LINE_ID') OR
10608 (l_serial_control_code = 6 AND p_reference = 'SHIPMENT_LINE_ID' AND
10609 l_lpn_serials_cnt > 0)) THEN
10610
10611 l_progress := '190';
10612 IF (l_debug =1) THEN
10613 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress ||
10614 ' Should match serials for the parent txn ' || l_parent_txn_id_tbl(i), l_proc_name);
10615 END IF;
10616
10617 FOR j in 1 .. l_ser_num_tbl.COUNT LOOP
10618
10619 IF ((l_ser_mark_tbl(j) = 'Y') OR
10620 (Nvl(l_ser_inspect_status_tbl(j),-1) <> Nvl(l_inspection_status_tbl(i),-1)) OR
10621 (Nvl(l_ser_lot_num_tbl(j),'&*_') <> Nvl(l_lot_number,'&*_'))) THEN
10622 NULL;
10623 ELSE
10624 --The MSNI records would have been created with a dummy interface_transaction_id.
10625 --On matching the serial, we need to update the transaction_interface_id
10626 --with the transaction_temp_id (for a serial and non-lot controlled item)
10627 --or with the serial_transaction_temp_id of the MTLI (for lot and serial controlled item)
10628 l_cur_ser_number := l_ser_num_tbl(j);
10629 DEBUG('complete_putaway_wrapper: cur_serial_number: ' || l_cur_ser_number);
10630
10631 IF (l_lot_control_code > 1) THEN
10632 l_ser_intf_id := l_serial_temp_id;
10633 ELSE
10634 l_ser_intf_id := l_dummy_temp_id;--l_mmtt_temp_id;
10635 END IF;
10636
10637 -- INSERT MSNI HERE
10638 l_result := wms_task_dispatch_put_away.insert_msni_helper
10639 (p_txn_if_id => l_ser_intf_id
10640 , p_serial_number => l_cur_ser_number
10641 , p_org_id => p_organization_id
10642 , p_item_id => p_item_id
10643 , p_product_txn_id => l_product_transaction_id
10644 );
10645
10646 IF NOT l_result THEN
10647 IF (l_debug = 1) THEN
10648 debug('Failure while Inserting MSNI records - lot and serial controlled item',l_proc_name);
10649 END IF;
10650 RAISE fnd_api.g_exc_unexpected_error;
10651 END IF; -- END IF check l_result
10652
10653 l_cur_task_ser_count := l_cur_task_ser_count + 1;
10654 l_ser_mark_tbl(j) := 'Y';
10655
10656 IF (l_cur_task_ser_count = l_mmtt_prm_qty) THEN
10657 EXIT;
10658 END IF;
10659
10660 END IF;
10661 END LOOP; --END LOOP through serials for the parent transaction
10662
10663 --On matching all the serials for the current task, exit out the loop
10664 IF (l_cur_task_ser_count = l_mmtt_prm_qty) THEN
10665 l_skip_mmtt := FALSE; -- Bug 3495726 issue 33
10666 ELSE --l_cur_task_ser_count < l_mmtt_prm_qty
10667 IF (l_debug = 1) THEN
10668 DEBUG('complete_putaway_wrapper: l_cur_task_ser_count < l_mmtt_prm_qty. how???',l_proc_name);
10669 END IF;
10670 END IF; --END IF check if all serials are consumed
10671
10672 --We have now consumed all the serials for the current task after
10673 --matching them with the serials entered.
10674 --Compare the serials consumed with the task quantity in primary uom
10675 --In case of a mismatch, throw error
10676 l_progress := '200';
10677 IF (l_debug = 1) THEN
10678 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress || '. Have matched ' ||
10679 l_cur_task_ser_count || ' as against the task qty: ' || l_mmtt_prm_qty);
10680 END IF;
10681 IF (l_cur_task_ser_count <> l_mmtt_prm_qty) THEN
10682 NULL; --Do I throw the serial mismatch error here itself
10683 END IF;
10684 END IF; --END IF Match serial numbers for receiving LPN
10685 --LPN context is Inventory/WIP
10686 ELSE
10687 --Create MSNT records for the serials confirmed from the UI
10688 l_progress := '210';
10689 IF (l_debug = 1) THEN
10690 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress ||
10691 '. INV/WIP LPN. Count of serials confirmed in the UI: ' || l_ser_num_tbl.COUNT, l_proc_name);
10692 END IF;
10693
10694 FOR k IN 1 .. l_ser_num_tbl.COUNT LOOP
10695 --Process the serial only if the serial has not already been
10696 --marked
10697 IF l_ser_mark_tbl(k) <> 'Y' THEN
10698
10699 --For a serialized item, the user can enter the quantity
10700 --ONLY in the item's primary UOM
10701 IF l_remaining_qty < l_mmtt_prm_qty THEN
10702 l_ser_qty := l_remaining_qty;
10703 ELSE
10704 l_ser_qty := l_mmtt_prm_qty;
10705 END IF;
10706
10707 l_cur_ser_number := l_ser_num_tbl(k);
10708
10709 IF (l_lot_control_code > 1) THEN
10710 l_action := 2;
10711 ELSE
10712 l_action := 3;
10713 END IF;
10714
10715 --Call the API to create the MSNT records for the current serial number
10716 wms_task_dispatch_gen.process_lot_serial(
10717 p_org_id => p_organization_id
10718 , p_user_id => p_user_id
10719 , p_temp_id => l_mmtt_temp_id
10720 , p_item_id => p_item_id
10721 , p_qty => l_ser_qty
10722 , p_uom => p_uom_code
10723 , p_lot => p_lot_number
10724 , p_fm_serial => l_cur_ser_number
10725 , p_to_serial => l_cur_ser_number
10726 , p_action => l_action
10727 , x_return_status => x_return_status
10728 , x_msg_count => x_msg_count
10729 , x_msg_data => x_msg_data);
10730
10731 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
10732 IF (l_debug = 1) THEN
10733 DEBUG('complete_putaway_wrapper: Error at progress: ' || l_progress ||
10734 ' process_lot_serial API returns g_exc_error', l_proc_name, 1);
10735 END IF;
10736 RAISE FND_API.G_EXC_ERROR;
10737 END IF;
10738
10739 IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10740 IF (l_debug = 1) THEN
10741 DEBUG('complete_putaway_wrapper: Error at progress: ' || l_progress ||
10742 ' process_lot_serial API returns g_unexp_error', l_proc_name, 1);
10743 END IF;
10744 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10745 END IF;
10746
10747 --Mark the serial as processed so that it does not get picked up again
10748 l_ser_mark_tbl(k) := 'Y';
10749
10750 END IF; --END IF l_ser_mark_tbl(k) <> 'Y' THEN
10751 END LOOP; --END Loop through all serials confirmed in the UI
10752 END IF; --END Do the lot and serial processing based on LPN context
10753
10754 --Item based Drop, with no quantity discrepancy
10755 ELSE
10756 l_progress := '210';
10757 IF (l_debug = 1) THEN
10758 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress ||
10759 '. Item based drop but no quantity discrepancy', l_proc_name);
10760 END IF;
10761 END IF; --END IF (l_disc = 'Y')
10762
10763 --BUG 5208888
10764 IF (l_serialized_item AND p_lpn_context = 3) THEN
10765 IF (l_entire_lpn = 'Y') THEN
10766 If (l_debug = 1) THEN
10767 DEBUG('Serials not entered from UI. Setting DISC flag to N so complete_putaway will insert the interface records',l_proc_name);
10768 END IF;
10769 l_disc := 'N';
10770 ELSE
10771 If (l_debug = 1) THEN
10772 DEBUG('Serials entered from UI. Setting DISC flag to Y so that complete_putaway will not insert the interface records',l_proc_name);
10773 END IF;
10774 l_disc := 'Y';
10775 END IF;
10776 END IF;
10777
10778 --For other drop types (Consolidated Drop/Manual Drop/User Drop)
10779 ELSE
10780 l_progress := '220';
10781 IF (l_debug = 1) THEN
10782 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress ||
10783 '. Drop type is CD/UD/MD. Consume MMTT directly', l_proc_name);
10784 END IF;
10785
10786 --As the user does not confirm item, quantity, rev etc. we just need
10787 --read them from the MMTT and pass it on to complete_putaway. The
10788 --subinventory and locator must be set from the UI though
10789 l_lpn_id := l_mol_lpn_id_tbl(i);
10790 l_quantity := l_mmtt_qty_tbl(i);
10791 l_uom_code := l_mmtt_uom_tbl(i);
10792 l_revision := l_mmtt_rev_tbl(i);
10793 l_lot_number := l_mmtt_lot_tbl(i);
10794 l_subinventory_code := p_subinventory_code;
10795 l_locator_id := p_locator_id;
10796
10797 l_secondary_quantity := l_mmtt_sec_qty_tbl(i); --OPM Convergence
10798 l_secondary_uom := p_secondary_uom;
10799 If (l_debug = 1) THEN
10800 DEBUG('CD/MD : Current Task quantity: ' || l_quantity, l_proc_name);
10801 END IF;
10802
10803 --Setting the p_entire_lpn_flag for complete_putaway
10804 --If there is only one MMTT for the current mol, then p_entire_flag
10805 --should be 'N' else it should be 'Y'
10806 SELECT count(1)
10807 INTO l_mmtt_count
10808 FROM mtl_material_transactions_temp
10809 WHERE move_order_line_id = l_mol_line_id_tbl(i);
10810
10811 IF l_mmtt_count > 1 THEN
10812 l_entire_lpn := 'N';
10813 ELSE
10814 l_entire_lpn := 'Y';
10815 END IF;
10816 END IF; --END IF Process the current task based on the drop type
10817
10818 --Do this stuff if the flag to skip the current task is not set
10819 IF l_skip_mmtt = FALSE THEN
10820
10821 l_xdock_to_wip := FALSE;
10822 --Set the flag to check if the current task is crossdocked to a
10823 --WIP Issue job since for this case, we have to drop tht material as loose
10824 --So even if I have an entire nested LPN being crossdocked to a WIP issue
10825 --job, at the end of the drop, the entire nesting structure must be broken
10826 --Set this flag only if the destination sub is a storage sub since the user
10827 --might be performing a manual drop of a crossdocked line to receiving sub
10828 IF ((l_bk_del_det_tbl(i) IS NOT NULL) AND
10829 (NVL(l_xdock_type_tbl(i), 0) = 2) AND
10830 (NVL(l_wip_sup_typ_tbl(i),0) IN (1, 5)) AND
10831 (l_drop_sub_type = 1)) THEN
10832 l_xdock_to_wip := TRUE;
10833 END IF;
10834
10835
10836 /* Setting the p_to_lpn_id parameter for complete_putaway
10837 * If the drop sub is not LPN controlled, always pass to_lpn as NULL
10838 * Elsif the task is crossdocked to WIP issue job, pass to_lpn as NULL
10839 * Else
10840 * If we are transacting the immediate contents of the from LPN Then
10841 * IF Drop Mode = Transfer contents then
10842 * pass p_to_lpn_name (from parameter) to complete_putaway
10843 * ELSE if Drop Mode = Drop Entire LPN then
10844 * pass lpn_name of p_lpn_id itself (since we would create a new
10845 * pack transaction for packing the from LPN into the "Into LPN")
10846 * END IF;
10847 * Else
10848 * Read the LPN name and pass it to the complete_putaway_wrapper
10849 * End If;
10850 * End IF;
10851 */
10852 IF l_lpn_controlled_flag = 2 THEN
10853 l_to_lpn_name := NULL;
10854 ELSIF l_xdock_to_wip = TRUE THEN
10855 l_to_lpn_name := NULL;
10856 ELSE
10857 IF ((l_mol_lpn_id_tbl(i) = p_lpn_id) AND (l_lpn_mode <> 2)) THEN
10858 l_to_lpn_name := p_to_lpn_name;
10859 ELSE
10860 --Replace this with LPN_NAME from global_temp table for this task
10861 SELECT license_plate_number
10862 INTO l_to_lpn_name
10863 FROM wms_license_plate_numbers
10864 WHERE lpn_id = l_mol_lpn_id_tbl(i);
10865 END IF; --END IF check MOL LPN and confirmed LPN
10866 END IF; --END IF check lpn_controlled_flag for the sub
10867
10868 --For INV/WIP LPNs, we would be calling the Inventory TM for the current
10869 --group. So, should update the MMTT with the new txn_header_id
10870 IF (p_lpn_context <> G_LPN_CONTEXT_RCV) THEN
10871 UPDATE mtl_material_transactions_temp
10872 SET transaction_header_id = l_new_txn_header_id
10873 , transaction_batch_id = l_new_txn_header_id
10874 , transaction_batch_seq = l_batch_seq --BUG 3306988
10875 WHERE transaction_temp_id = l_mmtt_temp_id;
10876 l_batch_seq := l_batch_seq + 1;
10877 END IF;
10878
10879 --Begin DBI FIX
10880 --Need to update the drop_off_time on WDT for all the tasks
10881 l_progress := '228';
10882
10883 BEGIN
10884 UPDATE wms_dispatched_tasks
10885 SET drop_off_time = l_drop_off_time
10886 WHERE transaction_temp_id = l_mmtt_temp_id;
10887 EXCEPTION
10888 WHEN OTHERS THEN
10889 NULL;
10890 END;
10891 --END DBI FIX
10892
10893 l_progress := '230';
10894 IF (l_debug = 1) THEN
10895 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress, l_proc_name);
10896 DEBUG('Calling complete_putaway API with the following parameters: ', l_proc_name);
10897 DEBUG('p_lpn_id => ' || l_mol_lpn_id_tbl(i), l_proc_name);
10898 DEBUG('p_org_id => ' || p_organization_id, l_proc_name);
10899 DEBUG('p_temp_id => ' || l_mmtt_temp_id, l_proc_name);
10900 DEBUG('p_item_id => ' || l_item_id, l_proc_name);
10901 DEBUG('p_rev => ' || l_revision, l_proc_name);
10902 DEBUG('p_lot => ' || l_lot_number, l_proc_name);
10903 DEBUG('p_loc => ' || l_locator_id, l_proc_name);
10904 DEBUG('p_sub => ' || l_subinventory_code, l_proc_name);
10905 DEBUG('p_qty => ' || l_quantity, l_proc_name);
10906 DEBUG('p_uom => ' || l_uom_code, l_proc_name);
10907 DEBUG('p_user_id => ' || p_user_id, l_proc_name);
10908 DEBUG('p_disc => ' || l_disc, l_proc_name);
10909 DEBUG('p_entire_lpn => ' || l_entire_lpn, l_proc_name);
10910 DEBUG('p_to_lpn => ' || l_to_lpn_name, l_proc_name);
10911 DEBUG('p_qty_reason_id => ' || p_qty_reason_id, l_proc_name);
10912 DEBUG('p_loc_reason_id => ' || p_loc_reason_id, l_proc_name);
10913 DEBUG('p_loc_reason_id => ' || p_loc_reason_id, l_proc_name);
10914 DEBUG('p_process_serial_flag => ' || p_process_serial_flag, l_proc_name);
10915 DEBUG('p_product_transaction_id => ' || l_product_transaction_id, l_proc_name);
10916 DEBUG('p_new_txn_header_id => ' || l_new_txn_header_id, l_proc_name);
10917 END IF;
10918
10919 --Now that I have all the values calculated and set for this task,
10920 --call the complete_putaway API
10921 wms_task_dispatch_put_away.complete_putaway(
10922 p_lpn_id => l_mol_lpn_id_tbl(i)
10923 , p_org_id => p_organization_id
10924 , p_temp_id => l_mmtt_temp_id
10925 , p_item_id => l_item_id
10926 , p_rev => l_revision
10927 , p_lot => l_lot_number
10928 , p_loc => l_locator_id
10929 , p_sub => l_subinventory_code
10930 , p_qty => l_quantity
10931 , p_uom => l_uom_code
10932 , p_user_id => p_user_id
10933 , p_disc => l_disc
10934 , x_return_status => x_return_status
10935 , x_msg_count => x_msg_count
10936 , x_msg_data => x_msg_data
10937 , p_entire_lpn => l_entire_lpn
10938 , p_to_lpn => l_to_lpn_name
10939 , p_qty_reason_id => p_qty_reason_id
10940 , p_loc_reason_id => p_loc_reason_id
10941 , p_process_serial_flag => p_process_serial_flag
10942 , p_commit => 'N'
10943 , p_product_transaction_id => l_product_transaction_id
10944 , p_lpn_mode => l_lpn_mode
10945 , p_new_txn_header_id => l_new_txn_header_id
10946 , p_secondary_quantity => l_secondary_quantity --OPM Convergence
10947 , p_secondary_uom => l_secondary_uom --OPM Convergence
10948 , p_primary_uom => l_primary_uom_code_tbl(i)
10949 );
10950
10951 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
10952 IF (l_debug = 1) THEN
10953 DEBUG('complete_putaway_wrapper: Error at progress: ' || l_progress || ' complete_putaway API returns g_exc_error', l_proc_name, 1);
10954 END IF;
10955 RAISE FND_API.G_EXC_ERROR;
10956 END IF;
10957
10958 IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
10959 IF (l_debug = 1) THEN
10960 DEBUG('complete_putaway_wrapper: Error at progress: ' || l_progress || ' complete_putaway API returns g_unexp_error', l_proc_name, 1);
10961 END IF;
10962 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
10963 END IF;
10964
10965 IF (l_debug = 1) THEN
10966 DEBUG('complete_putaway_wrapper: successful execution of complete_putaway for temp_id : ' || l_mmtt_temp_id, l_proc_name);
10967 END IF;
10968 ELSE
10969 IF (l_debug = 1) THEN
10970 DEBUG('complete_putaway_wrapper: skip_mmtt is TRUE, should not drop this task.' ||
10971 ' Could be because the serial could not be matched with the task', l_proc_name);
10972 END IF;
10973 l_remaining_qty := l_remaining_qty + l_mmtt_prm_qty;
10974 END IF; --END IF l_skip_mmtt = FALSE
10975 END LOOP; --END For each MMTT in the group
10976 --END LOOP; --END loop through all the tasks for the current group
10977
10978 --Close the cursor opened above
10979 IF all_tasks_csr%ISOPEN THEN
10980 CLOSE all_tasks_csr;
10981 END IF;
10982
10983 IF md_tasks_csr%ISOPEN THEN
10984 CLOSE md_tasks_csr;
10985 END IF;
10986
10987 --So far so good. We're done with the RTIs/MMTTs for this group
10988 --Should now process all the MMTTs for the current group and call
10989 --the appropriate Transaction Managers
10990 IF (p_lpn_context = G_LPN_CONTEXT_RCV) THEN
10991 l_progress := '240';
10992
10993 -- LMS code (start) (Anupam Jain)
10994 -- get the distinct OperationPlanId from MMTT for receiving LPNs
10995 -- logic is: return the operationplanid only if it is same for all the MMTTs
10996 -- for the given transaction_header_id
10997
10998 IF (l_debug = 1) THEN
10999 debug('complete_putaway_wrapper: Before calling LMS Code for receiving LPNs', l_proc_name);
11000 END IF;
11001
11002
11003 SELECT count(DISTINCT operation_plan_id) INTO l_lms_rec_count
11004 FROM mtl_material_transactions_temp mmtt
11005 WHERE transaction_header_id = p_txn_header_id;
11006
11007 IF (l_debug = 1) THEN
11008 debug('complete_putaway_wrapper: LMS Code, l_lms_rec_count: ' || l_lms_rec_count , l_proc_name);
11009 END IF;
11010
11011 IF l_lms_rec_count = 1 THEN
11012 -- since same OperationPlanId stamped for all the MMTTs of the group
11013 -- return its value for LMS data capture
11014 SELECT operation_plan_id INTO x_lms_operation_plan_id
11015 FROM mtl_material_transactions_temp
11016 WHERE transaction_header_id = p_txn_header_id
11017 AND ROWNUM = 1;
11018
11019 IF (l_debug = 1) THEN
11020 debug('complete_putaway_wrapper: LMS Code, p_lms_operation_plan_id: ' || x_lms_operation_plan_id , l_proc_name);
11021 END IF;
11022
11023 END IF;
11024
11025 IF (l_debug = 1) THEN
11026 debug('complete_putaway_wrapper: After calling LMS Code for receiving LPNs', l_proc_name);
11027 END IF;
11028
11029 -- LMS Code (end)
11030
11031 --Receiving LPN. Call Receiving Transaction Manager
11032 IF (l_debug = 1) THEN
11033 DEBUG('complete_putaway_wrapper: LPN Resides in receiving. Calling the receiving manager...');
11034 END IF;
11035
11036 INV_RCV_MOBILE_PROCESS_TXN.rcv_process_receive_txn(
11037 x_return_status => x_return_status
11038 , x_msg_data => l_msg_data);
11039
11040 --Set the flag to indicate that data has been committed (would be used
11041 --to rollback to the appropriate savepoint)
11042 l_rcv_commit := TRUE;
11043
11044 IF (l_debug = 1) THEN
11045 DEBUG('complete_putaway_wrapper: After calling the receiving manager');
11046 DEBUG('status returned by the receiving manager ' || x_return_status, 4);
11047 DEBUG('complete_putaway_wrapper: Rxing TM Txn Message: ' || l_msg_data, 4);
11048 END IF;
11049
11050 IF x_return_status = FND_API.G_RET_STS_ERROR THEN
11051 IF (l_debug = 1) THEN
11052 DEBUG('complete_putaway_wrapper: Encountered g_exc_error while calling receiving manager;'|| to_char(sysdate, 'YYYY-MM-DD HH:DD:SS'), 4);
11053 END IF;
11054 fnd_message.set_name('WMS', 'WMS_TD_TXNMGR_ERROR');
11055 fnd_msg_pub.add;
11056 RAISE FND_API.G_EXC_ERROR;
11057 END IF;
11058
11059 IF x_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
11060 IF (l_debug = 1) THEN
11061 DEBUG('complete_putaway_wrapper: Encountered g_exc_unexp_error while calling receiving manager;'|| to_char(sysdate, 'YYYY-MM-DD HH:DD:SS'), 4);
11062 END IF;
11063 fnd_message.set_name('WMS', 'WMS_TD_TXNMGR_ERROR');
11064 fnd_msg_pub.add;
11065 RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
11066 END IF;
11067
11068 --If the LPN context is Inventory/WIP
11069 ELSE
11070 l_progress := '240';
11071 IF (p_lpn_context = G_LPN_CONTEXT_WIP) THEN
11072 --For WIP Putaway, use the new business flow code
11073 l_business_flow_code := 35;
11074 END IF;
11075
11076 IF (l_debug = 1) THEN
11077 DEBUG('complete_putaway_wrapper: Progress: ' || l_progress || '. Calling post_process_lpn', l_proc_name);
11078 END IF;
11079
11080 -- Nested LPN changes
11081 --Do not call the post_process_lpn if dest sub is NOT LPN controlled or passed to_lpn is NULL
11082 IF (l_lpn_controlled_flag = 2 OR p_to_lpn_name IS NULL) THEN
11083 IF l_debug = 1 THEN
11084 DEBUG('Dest sub is not LPN controlled, or passed TO LPN is NULL or Dest sub is not storage sub . No post_process_lpn calls.', l_proc_name);
11085 DEBUG('l_drop_sub_type : '|| l_drop_sub_type || ' to_lpn_name : ' || p_to_lpn_name || ' l_lpn_controlled_flag : ' || l_lpn_controlled_flag );
11086 END IF;
11087
11088 ELSE
11089 IF l_debug = 1 THEN
11090 DEBUG('Calling post_process_lpn to handle the pack/unpacks.', l_proc_name);
11091 END IF;
11092
11093 post_process_lpn(
11094 x_return_status => x_return_status
11095 , x_msg_count => x_msg_count
11096 , x_msg_data => x_msg_data
11097 , p_from_lpn_id => p_lpn_id
11098 , p_organization_id => p_organization_id
11099 , p_subinventory_code => p_subinventory_code
11100 , p_lpn_mode => l_lpn_mode
11101 , p_locator_id => p_locator_id
11102 , p_to_lpn_id => p_to_lpn_id
11103 , p_project_id => p_project_id
11104 , p_task_id => p_task_id
11105 , p_user_id => p_user_id
11106 , p_lpn_context => p_lpn_context
11107 , p_pack_trans_id => l_new_txn_header_id
11108 , p_batch_id => l_new_txn_header_id
11109 , p_batch_seq => l_batch_seq );
11110
11111 IF (l_debug = 1) THEN
11112 DEBUG('complete_putaway_wrapper: post_process_lpn returns: ' || x_return_status, 4);
11113 END IF;
11114
11115 IF x_return_status = fnd_api.g_ret_sts_error THEN
11116 RAISE fnd_api.g_exc_error;
11117 END IF;
11118
11119 IF x_return_status = fnd_api.g_ret_sts_unexp_error THEN
11120 RAISE fnd_api.g_exc_unexpected_error;
11121 END IF;
11122 END IF;
11123 -- Nested LPN changes end
11124
11125 --Call the Inventory Transaction Manager
11126 IF (l_debug = 1) THEN
11127 DEBUG('complete_putaway_wrapper: INV or WIP LPN. Am calling the Inventory TM with txn_header_id ' || l_new_txn_header_id, l_proc_name);
11128 END IF;
11129
11130 IF p_lpn_context = 2 THEN
11131 l_txn_ret := inv_lpn_trx_pub.process_lpn_trx(
11132 p_trx_hdr_id => l_new_txn_header_id
11133 , p_commit => fnd_api.g_false
11134 , x_proc_msg => x_msg_data
11135 , p_business_flow_code => l_business_flow_code
11136 , p_proc_mode => 1);
11137 ELSE
11138 l_txn_ret := inv_lpn_trx_pub.process_lpn_trx(
11139 p_trx_hdr_id => l_new_txn_header_id
11140 , p_commit => fnd_api.g_false
11141 , x_proc_msg => x_msg_data
11142 , p_business_flow_code => l_business_flow_code);
11143 END IF;
11144
11145 IF (l_debug = 1) THEN
11146 debug('complete_putaway_wrapper: After Calling Inventory TM', l_proc_name);
11147 debug('complete_putaway_wrapper: l_txn_ret: ' || l_txn_ret, l_proc_name);
11148 debug('complete_putaway_wrapper: Txn Message ' || x_msg_data, l_proc_name);
11149 END IF;
11150
11151 IF (l_txn_ret <> 0) THEN
11152 fnd_message.set_name('WMS', 'WMS_TD_TXNMGR_ERROR');
11153 fnd_msg_pub.ADD;
11154 RAISE fnd_api.g_exc_unexpected_error;
11155 END IF;
11156 END IF; --END IF call the managers based on lpn_context
11157
11158 --Done with the TM calls. Go delete the records from the global temp rable
11159 --for the current group
11160 l_progress := '250';
11161 l_del_count := Remove_Tasks_In_Group(
11162 p_del_type => 1
11163 , p_group_id => p_group_id);
11164
11165 -- Call the API to clear the receiving global variables
11166 inv_rcv_common_apis.rcv_clear_global;
11167
11168 --At last, I'm done for the current group. Can go ahead and commit my work!
11169 COMMIT;
11170
11171 --BUG 3625990: Do not lock the LPN if it has context 3
11172 IF (p_lpn_context <> 3) THEN
11173 -- Lock all the remaining LPNs the user is currently working on
11174 -- We are re-locking again since the commit above would have relieved the lock.
11175 Lock_LPNs( x_return_status => x_return_status
11176 ,x_msg_count => x_msg_count
11177 ,x_msg_data => x_msg_data );
11178
11179 l_progress := '260';
11180
11181 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
11182 IF (l_debug = 1) THEN
11183 DEBUG(' Error in locking LPNs ' || x_msg_data ,l_proc_name,1);
11184 END IF;
11185 RAISE fnd_api.g_exc_error;
11186 END IF;
11187
11188 IF (l_debug = 1) THEN
11189 DEBUG(':-)complete_putaway_wrapper exitted with success for group id ' || p_group_id || ' :-). Exit time: ' || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'), l_proc_name);
11190 END IF;
11191 END IF;
11192
11193 EXCEPTION
11194 WHEN fnd_api.g_exc_error THEN
11195 x_return_status := fnd_api.g_ret_sts_error;
11196 --Close the cursors
11197 IF mol_csr%ISOPEN THEN
11198 CLOSE mol_csr;
11199 END IF;
11200 IF all_tasks_csr%ISOPEN THEN
11201 CLOSE all_tasks_csr;
11202 END IF;
11203 IF md_tasks_csr%ISOPEN THEN
11204 CLOSE md_tasks_csr;
11205 END IF;
11206 IF rcv_serials_csr%ISOPEN THEN
11207 CLOSE rcv_serials_csr;
11208 END IF;
11209 IF msnt_ser_csr%ISOPEN THEN
11210 CLOSE msnt_ser_csr;
11211 END IF;
11212
11213 IF NOT l_rcv_commit THEN
11214 ROLLBACK TO complete_putaway_wrap_sp;
11215 END IF;
11216
11217 IF (l_debug = 1) THEN
11218 DEBUG('complete_putaway_wrapper: G_EXC_ERROR ocurred after l_progress = ' || l_progress, l_proc_name);
11219 END IF;
11220
11221 --Get message count and data
11222 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
11223
11224 WHEN fnd_api.g_exc_unexpected_error THEN
11225 x_return_status := fnd_api.g_ret_sts_unexp_error;
11226
11227 --Close the cursors
11228 IF mol_csr%ISOPEN THEN
11229 CLOSE mol_csr;
11230 END IF;
11231 IF all_tasks_csr%ISOPEN THEN
11232 CLOSE all_tasks_csr;
11233 END IF;
11234 IF md_tasks_csr%ISOPEN THEN
11235 CLOSE md_tasks_csr;
11236 END IF;
11237 IF rcv_serials_csr%ISOPEN THEN
11238 CLOSE rcv_serials_csr;
11239 END IF;
11240 IF msnt_ser_csr%ISOPEN THEN
11241 CLOSE msnt_ser_csr;
11242 END IF;
11243
11244 IF NOT l_rcv_commit THEN
11245 ROLLBACK TO complete_putaway_wrap_sp;
11246 END IF;
11247
11248 IF (l_debug = 1) THEN
11249 DEBUG('complete_putaway_wrapper: G_EXC_UNEXPECTED_ERROR ocurred after l_progress = ' || l_progress, l_proc_name);
11250 END IF;
11251
11252 --Get message count and data
11253 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
11254
11255 WHEN OTHERS THEN
11256 x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
11257
11258 --Close the cursors
11259 IF mol_csr%ISOPEN THEN
11260 CLOSE mol_csr;
11261 END IF;
11262 IF all_tasks_csr%ISOPEN THEN
11263 CLOSE all_tasks_csr;
11264 END IF;
11265 IF md_tasks_csr%ISOPEN THEN
11266 CLOSE md_tasks_csr;
11267 END IF;
11268 IF rcv_serials_csr%ISOPEN THEN
11269 CLOSE rcv_serials_csr;
11270 END IF;
11271 IF msnt_ser_csr%ISOPEN THEN
11272 CLOSE msnt_ser_csr;
11273 END IF;
11274
11275 IF NOT l_rcv_commit THEN
11276 ROLLBACK TO complete_putaway_wrap_sp;
11277 END IF;
11278
11279 IF (l_debug = 1) THEN
11280 DEBUG('complete_putaway_wrapper: OTHER EXCEPTION ' || SQLERRM || ' ocurred after l_progress = ' || l_progress, l_proc_name);
11281 END IF;
11282
11283 --Get message count and data
11284 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
11285 IF SQLCODE IS NOT NULL THEN
11286 inv_mobile_helper_functions.sql_error('wms_putaway_utils_pvt.complete_putaway_wrapper',l_progress, SQLCODE);
11287 END IF;
11288
11289 END complete_putaway_wrapper;
11290
11291 PROCEDURE validate_into_lpn
11292 (p_organization_id IN NUMBER ,
11293 p_lpn_id IN NUMBER ,
11294 p_employee_id IN NUMBER ,
11295 p_into_lpn IN VARCHAR2 ,
11296 x_return_status OUT NOCOPY VARCHAR2 ,
11297 x_msg_count OUT NOCOPY NUMBER ,
11298 x_msg_data OUT NOCOPY VARCHAR2 ,
11299 x_validation_passed OUT NOCOPY VARCHAR2 ,
11300 x_new_lpn_created OUT NOCOPY VARCHAR2 ,
11301 p_project_id IN NUMBER ,
11302 p_task_id IN NUMBER ,
11303 p_drop_type IN VARCHAR2 ,
11304 p_sub IN VARCHAR2 ,
11305 p_loc IN NUMBER ,
11306 p_crossdock_type IN VARCHAR2,
11307 p_consolidation_method_id IN NUMBER,
11308 p_backorder_delivery_detail_id IN NUMBER,
11309 p_suggested_into_lpn_id IN NUMBER
11310 )
11311 IS
11312 l_api_name CONSTANT VARCHAR2(30) := 'validate_into_lpn';
11313 l_progress VARCHAR2(10);
11314 l_count NUMBER;
11315 l_into_lpn_id NUMBER;
11316 l_lpn_context NUMBER;
11317 l_lpn_sub VARCHAR2(10);
11318 l_lpn_loc_id NUMBER;
11319 l_into_lpn_sub VARCHAR2(10);
11320 l_into_lpn_loc_id NUMBER;
11321 l_into_lpn_context NUMBER;
11322 l_into_lpn_project_id NUMBER;
11323 l_into_lpn_task_id NUMBER;
11324 l_passed VARCHAR2(1);
11325 l_item_count NUMBER;
11326 l_lot_count NUMBER;
11327 l_rev_count NUMBER;
11328 l_qty_gtmp NUMBER;
11329 l_qty_wlc NUMBER;
11330 l_debug NUMBER := NVL(FND_PROFILE.VALUE('INV_DEBUG_TRACE'),0);
11331 l_back_order_delivery_id NUMBER := -999;
11332 l_crossdock_type NUMBER;
11333 l_wip_supply_type NUMBER := -999;
11334 l_sub_validation_passed NUMBER := 1;
11335 l_lpn_sub_type NUMBER;
11336 l_lpn_controlled_flag NUMBER;
11337 l_reservable_type NUMBER;
11338 l_sub_type NUMBER;
11339 l_allowed VARCHAR2(1);--R12
11340 l_into_outermost_lpn_id NUMBER;
11341 l_lpn_has_material NUMBER;
11342 BEGIN
11343 IF (l_debug = 1) THEN
11344 debug('***Calling validate_into_lpn with the following parameters***','validate_into_lpn',9);
11345 debug('p_organization_id: => ' || p_organization_id,'validate_into_lpn',9);
11346 debug('p_lpn_id: ==========> ' || p_lpn_id,'validate_into_lpn',9);
11347 debug('p_employee_id: =====> ' || p_employee_id,'validate_into_lpn',9);
11348 debug('p_project_id: =====> ' || p_project_id,'validate_into_lpn',9);
11349 debug('p_task_id: =====> ' || p_task_id,'validate_into_lpn',9);
11350 debug('p_into_lpn: ========> ' || p_into_lpn,'validate_into_lpn',9);
11351 debug('p_drop_type: ========> ' || p_drop_type,'validate_into_lpn',9);
11352 debug('p_sub: ==============> ' || p_sub,'validate_into_lpn',9);
11353 debug('p_loc: ==============> ' || p_loc,'validate_into_lpn',9);
11354 debug('p_crossdock_type================>'||p_crossdock_type,'validate_into_lpn',9);
11355 debug('p_consolidation_method_id=======>'||p_consolidation_method_id,'validate_into_lpn',9);
11356 debug('p_backorder_delivery_detail_id==>'||p_backorder_delivery_detail_id,'validate_into_lpn',9);
11357 debug('p_suggested_into_lpn_id=========>'||p_suggested_into_lpn_id,'validate_into_lpn',9);
11358 END IF;
11359
11360 -- Set the savepoint
11361 SAVEPOINT validate_lpn_sp;
11362 x_return_status := fnd_api.g_ret_sts_success;
11363
11364 l_progress := '10';
11365
11366 -- Get the required LPN values
11367 SELECT lpn_context, subinventory_code, locator_id
11368 INTO l_lpn_context, l_lpn_sub, l_lpn_loc_id
11369 FROM wms_license_plate_numbers
11370 WHERE organization_id = p_organization_id
11371 AND lpn_id = p_lpn_id;
11372 l_progress := '20';
11373 IF (l_debug = 1) THEN
11374 debug('Retrieved LPN attributes','validate_into_lpn',9);
11375 debug('LPN Context: =======> ' || l_lpn_context,'validate_into_lpn',9);
11376 debug('Subinventory: ======> ' || l_lpn_sub,'validate_into_lpn',9);
11377 debug('Locator ID: ========> ' || l_lpn_loc_id,'validate_into_lpn',9);
11378 END IF;
11379
11380 -- See if the Into LPN exists
11381 BEGIN
11382 SELECT 1, lpn_id, subinventory_code, locator_id, lpn_context,outermost_lpn_id
11383 INTO l_count, l_into_lpn_id, l_into_lpn_sub, l_into_lpn_loc_id, l_into_lpn_context,
11384 l_into_outermost_lpn_id
11385 FROM wms_license_plate_numbers
11386 WHERE license_plate_number = p_into_lpn
11387 AND organization_id = p_organization_id
11388 FOR UPDATE OF lpn_id NOWAIT;
11389 -- lock so no other user can load into this lpn
11390 EXCEPTION
11391 WHEN NO_DATA_FOUND THEN
11392 l_count := 0;
11393 END;
11394 l_progress := '30';
11395 IF (l_debug = 1) THEN
11396 debug('Into LPN count: ' || l_count,'validate_into_lpn',9);
11397 END IF;
11398
11399 --BUG 3354934
11400 IF (l_count <> 0 AND l_into_lpn_context = 5) THEN
11401 IF (l_debug = 1) THEN
11402 debug('Into LPN context is 5, so bypass all validation','validate_into_lpn',9);
11403 END IF;
11404 x_return_status := fnd_api.g_ret_sts_success;
11405 x_validation_passed := 'Y';
11406 x_new_lpn_created := 'N';
11407 RETURN;
11408 END IF;
11409
11410 IF (l_count = 0) THEN
11411 -- New LPN
11412 IF (l_debug = 1) THEN
11413 debug('LPN does not exist so create new LPN','validate_into_lpn',9);
11414 END IF;
11415
11416 -- Create the LPN
11417 wms_container_pub.create_lpn
11418 ( p_api_version => 1.0,
11419 p_init_msg_list => fnd_api.g_false,
11420 p_commit => fnd_api.g_false,
11421 x_return_status => x_return_status,
11422 x_msg_count => x_msg_count,
11423 x_msg_data => x_msg_data,
11424 p_lpn => p_into_lpn,
11425 p_organization_id => p_organization_id,
11426 p_container_item_id => NULL,
11427 p_lot_number => NULL,
11428 p_revision => NULL,
11429 p_serial_number => NULL,
11430 -- p_subinventory => l_lpn_sub,
11431 -- p_locator_id => l_lpn_loc_id,
11432 p_source => 5, -- defined but not used
11433 p_cost_group_id => NULL,
11434 x_lpn_id => l_into_lpn_id
11435 );
11436 l_progress := '40';
11437 IF (l_debug = 1) THEN
11438 debug('Finished calling create LPN API: ' || l_into_lpn_id,'validate_into_lpn',9);
11439 END IF;
11440
11441 -- Check the return status from the API call
11442 IF (x_return_status = fnd_api.g_ret_sts_success) THEN
11443 IF (l_debug = 1) THEN
11444 debug('Success returned from wms_container_pub.create_lpn API','validate_into_lpn',9);
11445 END IF;
11446 ELSE
11447 IF (l_debug = 1) THEN
11448 debug('Failure returned from wms_container_pub.create_lpn API','validate_into_lpn',9);
11449 END IF;
11450 FND_MESSAGE.SET_NAME('WMS', 'WMS_TD_CREATE_LPN_ERROR');
11451 FND_MSG_PUB.ADD;
11452 RAISE fnd_api.g_exc_error;
11453 END IF;
11454 l_progress := '60';
11455
11456 -- Set the validation passed output parameter
11457 x_validation_passed := 'Y';
11458
11459 -- Set the new LPN created output parameter
11460 x_new_lpn_created := 'Y';
11461
11462 --BUG 3354934
11463 IF (l_debug = 1) THEN
11464 debug('LPN created. Can bypass rest of validation','validate_into_lpn',9);
11465 END IF;
11466 x_return_status := fnd_api.g_ret_sts_success;
11467 RETURN;
11468
11469 ELSE
11470 -- Existing LPN
11471 IF (l_debug =1 ) THEN
11472 debug('INTO LPN exists so validate it','validate_into_lpn',9);
11473 debug('Retrieved INTO LPN attributes','validate_into_lpn',9);
11474 debug('LPN ID: ============> ' || l_into_lpn_id,'validate_into_lpn',9);
11475 debug('LPN Context: =======> ' || l_into_lpn_context,'validate_into_lpn',9);
11476 debug('Subinventory: ======> ' || l_into_lpn_sub,'validate_into_lpn',9);
11477 debug('Locator ID: ========> ' || l_into_lpn_loc_id,'validate_into_lpn',9);
11478 END IF;
11479
11480 -- Set the new LPN created output parameter
11481 x_new_lpn_created := 'N';
11482
11483 l_count := 0;
11484
11485 IF p_drop_type = 'LOAD' THEN
11486
11487 BEGIN
11488 -- Validate the LPN
11489 -- Bug 4652943
11490 -- For Performance Reason the count for WMS_LPN_CONTENTS
11491 -- is done outside.
11492
11493 l_lpn_has_material := 0;
11494
11495 select NVL(count(1),0)
11496 into l_lpn_has_material
11497 FROM wms_lpn_contents
11498 WHERE parent_lpn_id IN (SELECT wlpn1.lpn_id
11499 FROM wms_license_plate_numbers wlpn1
11500 START WITH wlpn1.lpn_id = l_into_outermost_lpn_id
11501 CONNECT BY PRIOR wlpn1.lpn_id = wlpn1.parent_lpn_id);
11502
11503 SELECT 1
11504 INTO l_count
11505 FROM dual
11506 WHERE EXISTS
11507 (SELECT 'INTO_LPN_EXISTS'
11508 FROM wms_license_plate_numbers wlpn
11509 WHERE wlpn.organization_id = p_organization_id
11510 AND wlpn.lpn_id <> p_lpn_id
11511 AND wlpn.lpn_id = l_into_lpn_id
11512 AND (wlpn.lpn_context = WMS_CONTAINER_PUB.LPN_CONTEXT_PREGENERATED
11513 OR (wlpn.lpn_context = l_lpn_context
11514 AND (
11515 ( l_lpn_has_material = 0
11516 --NOT EXISTS (SELECT 'LPN_HAS_MATERIAL'
11517 --FROM wms_lpn_contents
11518 --WHERE parent_lpn_id IN (SELECT wlpn1.lpn_id
11519 -- FROM wms_license_plate_numbers wlpn1
11520 -- START WITH wlpn1.lpn_id = wlpn.outermost_lpn_id
11521 -- CONNECT BY PRIOR wlpn1.lpn_id = wlpn1.parent_lpn_id)
11522 --)
11523 )
11524 OR
11525 /** Bug:5650113
11526 While performing Manual Load by Item by Item, mmtt.lpn_id
11527 is stamped with from lpn_id not with into_lpn_id and
11528 because of this no rows is getting fetched for the query
11529 'LOADED_BY_SAME_USER'.
11530 So, modified mmmt.lpn_id to mtrl.lpn_id and introduced join
11531 with mmmt and mtrl table.
11532 */
11533 (EXISTS (SELECT 'LOADED_BY_SAME_USER'
11534 FROM mtl_material_transactions_temp mmtt,
11535 wms_dispatched_tasks wdt,--5650113
11536 mtl_txn_request_lines mtrl--5650113
11537 WHERE mmtt.organization_id = p_organization_id
11538 AND mmtt.transaction_temp_id = wdt.transaction_temp_id
11539 AND wdt.organization_id = p_organization_id
11540 AND wdt.task_type = 2
11541 AND wdt.status = 4
11542 AND wdt.person_id = p_employee_id
11543 AND mtrl.line_id = mmtt.move_order_line_id--5650113
11544 AND mtrl.lpn_id IN (SELECT lpn_id--5650113
11545 FROM wms_license_plate_numbers
11546 START WITH lpn_id = wlpn.outermost_lpn_id
11547 CONNECT BY PRIOR lpn_id = parent_lpn_id
11548 )
11549 )
11550 )
11551 )
11552 )
11553 )
11554 AND inv_material_status_grp.is_status_applicable('TRUE',
11555 NULL,
11556 INV_GLOBALS.G_TYPE_CONTAINER_PACK,
11557 NULL,
11558 NULL,
11559 p_organization_id,
11560 NULL,
11561 wlpn.subinventory_code,
11562 wlpn.locator_id,
11563 NULL,
11564 NULL,
11565 'Z') = 'Y'
11566 AND inv_material_status_grp.is_status_applicable('TRUE',
11567 NULL,
11568 INV_GLOBALS.G_TYPE_CONTAINER_PACK,
11569 NULL,
11570 NULL,
11571 p_organization_id,
11572 NULL,
11573 wlpn.subinventory_code,
11574 wlpn.locator_id,
11575 NULL,
11576 NULL,
11577 'L') = 'Y');
11578 EXCEPTION
11579 WHEN NO_DATA_FOUND THEN
11580 l_count := 0;
11581 IF (l_debug = 1) THEN
11582 debug('No data found','validate_into_lpn',9);
11583 END IF;
11584 END;
11585 l_progress := '70';
11586 IF (l_debug = 1) THEN
11587 debug('Validated Into LPN count: ' || l_count,'validate_into_lpn',9);
11588 END IF;
11589
11590 IF (l_count = 0) THEN
11591 x_validation_passed := 'N';
11592 IF (l_debug = 1) THEN
11593 debug('Into LPN validation failed!','validate_into_lpn',9);
11594 END IF;
11595 FND_MESSAGE.SET_NAME('WMS','WMS_NO_LPN_LOAD_ALLOWED');
11596 FND_MSG_PUB.ADD;
11597 RAISE fnd_api.g_exc_error;
11598 ELSE
11599 x_validation_passed := 'Y';
11600 IF (l_debug = 1) THEN
11601 debug('Into LPN validation passed!','validate_into_lpn',9);
11602 END IF;
11603 END IF;
11604 END IF;
11605
11606 -- Validate Into lpn for drop
11607 IF (p_drop_type IN ('MANUAL_DROP', 'SYSTEM_DROP')) THEN
11608
11609 --R12
11610 IF (p_crossdock_type IS NOT NULL AND
11611 p_backorder_delivery_detail_id IS NOT NULL AND
11612 l_into_lpn_context = 11) THEN
11613 IF (p_consolidation_method_id = 1) THEN
11614
11615 --If user override the LPN suggested by MDC
11616 IF (p_suggested_into_lpn_id IS NOT NULL AND
11617 p_suggested_into_lpn_id <> l_into_lpn_id) THEN
11618
11619 IF (l_debug = 1) THEN
11620 debug('Calling wms_mdc_pvt.validate_to_lpn','validate_into_lpn',9);
11621 END IF;
11622
11623 wms_mdc_pvt.validate_to_lpn
11624 (p_from_lpn_id => p_lpn_id
11625 ,p_to_lpn_id => l_into_lpn_id
11626 ,p_is_from_to_delivery_same => 'U'
11627 ,x_allow_packing => l_allowed
11628 ,x_return_status => x_return_status
11629 ,x_msg_count => x_msg_count
11630 ,x_msg_data => x_msg_data
11631 );
11632
11633 IF (x_return_status = 'U') THEN
11634 IF (l_debug = 1) THEN
11635 DEBUG(' Error in wms_mdc_pvt.validate_to_lpn','validate_into_lpn',9);
11636 END IF;
11637 RAISE fnd_api.g_exc_error;
11638 ELSE
11639 IF (l_allowed = 'Y') THEN
11640 IF (l_debug = 1) THEN
11641 debug(' validation passed!','validate_into_lpn',9);
11642 END IF;
11643 ELSE
11644 x_validation_passed := 'N';
11645 RETURN;
11646 END IF;
11647 END IF;
11648 END IF;--IF (p_suggested_into_lpn_id IS NOT NULL AND p_suggested_into_lpn_id <> l_into_lpn_id) THEN
11649
11650 ELSE --Non-MDC cases
11651
11652 IF (l_debug = 1) THEN
11653 debug('Checking for comingling','validate_into_lpn',9);
11654 END IF;
11655
11656 -- Make sure that the Into LPN does not contain other deliveres
11657 BEGIN
11658 SELECT 'N'
11659 INTO l_allowed
11660 FROM wsh_delivery_assignments_v wda1
11661 , wsh_delivery_assignments_v wda2
11662 , wsh_delivery_details wdd
11663 WHERE wda1.delivery_detail_id = p_backorder_delivery_detail_id
11664 AND wda2.delivery_detail_id = wdd.delivery_detail_id
11665 AND wdd.lpn_id = l_into_lpn_id
11666 AND Nvl(wda1.delivery_id,-1) <> Nvl(wda2.delivery_id,-2);
11667 EXCEPTION
11668 WHEN too_many_rows THEN
11669 IF (l_debug = 1) THEN
11670 debug('too many rows','validate_into_lpn',9);
11671 END IF;
11672 l_allowed := 'N';
11673 WHEN no_data_found THEN
11674 IF (l_debug = 1) THEN
11675 debug('no data found','validate_into_lpn',9);
11676 END IF;
11677 l_allowed := 'Y';
11678 WHEN OTHERS THEN
11679 IF (l_debug = 1) THEN
11680 debug('others exception: '||Sqlerrm,'validate_into_lpn',9);
11681 END IF;
11682 l_allowed := 'N';
11683 END;
11684
11685 IF (l_debug = 1) THEN
11686 debug('l_allowed:'||l_allowed,'validate_into_lpn',9);
11687 END IF;
11688
11689 /* Bug 5474915: Changed the error message from
11690 WMS_COMMINGLE_EXISTS to WMS_LOOSE_TO_LPN.*/
11691
11692 IF l_allowed = 'N' THEN
11693 x_return_status := fnd_api.g_ret_sts_error;
11694 x_validation_passed := 'N';
11695 fnd_message.set_name('WMS', 'WMS_LOOSE_TO_LPN');
11696 fnd_msg_pub.ADD;
11697 RETURN;
11698 END IF;
11699 END IF;
11700 x_validation_passed := 'Y';
11701 RETURN;
11702 END IF;
11703 --R12 END
11704
11705 ---Check If the from LPN and ToLPN are same.
11706 IF p_lpn_id = l_into_lpn_id THEN
11707
11708 -- Check there are no child LPNs and there is only one item left for Item drop
11709 BEGIN
11710 select count(DISTINCT inventory_item_id),count(DISTINCT lot_number),count(DISTINCT revision)
11711 into l_item_count,l_lot_count,l_rev_count
11712 from WMS_PUTAWAY_GROUP_TASKS_GTMP wpgtg
11713 where lpn_id = p_lpn_id
11714 and drop_type='ID'
11715 and row_type = 'Group Task'
11716 and not exists
11717 (select 1
11718 from wms_license_plate_numbers wln
11719 where wln.parent_lpn_id = p_lpn_id);
11720 EXCEPTION
11721 WHEN OTHERS THEN
11722 l_item_count :=2;
11723 END;
11724
11725 IF (l_item_count > 1 OR l_lot_count > 1 OR l_rev_count > 1) THEN
11726 IF (l_debug = 1) THEN
11727 debug('There are multiple items/lot/rev in the LPN or the LPN has child LPNS.!','validate_into_lpn',9);
11728 END IF;
11729
11730 x_validation_passed := 'N';
11731 RETURN;
11732 END IF;
11733
11734 -- check LPN is fully allocated.
11735 select sum(primary_quantity) INTO l_qty_gtmp
11736 from WMS_PUTAWAY_GROUP_TASKS_GTMP
11737 where lpn_id = p_lpn_id
11738 and row_type = 'Group Task'
11739 and drop_type = 'ID';
11740
11741 select sum(quantity) into l_qty_wlc
11742 from wms_lpn_contents
11743 where parent_lpn_id = p_lpn_id;
11744
11745 IF (l_qty_gtmp<>l_qty_wlc) THEN
11746 IF (l_debug = 1) THEN
11747 debug(' quantity from global temp table ' || l_qty_gtmp);
11748 debug(' quantity from wms license plate Numbers ' || l_qty_wlc);
11749 debug('Given LPN is not fully allocated!','validate_into_lpn',9);
11750 END IF;
11751 x_validation_passed := 'N';
11752 RETURN;
11753 END IF;
11754 /** Bug 5684823:
11755 During Drop txn, if "from lpn" and "to lpn" are same, no need to
11756 verify the "to lpn" exists and it is in loaded state through the query
11757 "INTO_LPN_EXISTS". We can safely bypass it, as the "to lpn" will exist
11758 as "from lpn" exists and "from lpn" will be in loaded status irrespective
11759 of system generated drop or manual drop.
11760 So, bypassing the query 'INTO_LPN_EXISTS' and setting l_count to 1.
11761 */
11762 l_count := 1;
11763 ELSE--IF p_lpn_id = l_into_lpn_id THEN
11764 BEGIN
11765 SELECT 1 INTO l_count
11766 FROM DUAL
11767 WHERE EXISTS (
11768 SELECT 'INTO_LPN_EXISTS'
11769 FROM wms_license_plate_numbers wlpn
11770 WHERE wlpn.organization_id = p_organization_id
11771 AND wlpn.lpn_id = l_into_lpn_id
11772 AND (wlpn.lpn_context = 5 OR
11773 ((wlpn.lpn_context = 1 AND l_lpn_context IN (1,2) ) OR
11774 wlpn.lpn_context IN (1,3) AND l_lpn_context = 3)--BUG 3463634
11775 AND (p_lpn_id = wlpn.lpn_id OR --BUG 3368408
11776 (NOT EXISTS (SELECT 'LOADED'
11777 FROM mtl_material_transactions_temp mmtt,
11778 wms_dispatched_tasks wdt
11779 WHERE mmtt.organization_id = p_organization_id
11780 AND mmtt.transaction_temp_id = wdt.transaction_temp_id
11781 AND wdt.organization_id = p_organization_id
11782 AND wdt.task_type = 2
11783 AND wdt.status = 4
11784 AND mmtt.lpn_id IN (SELECT wlpn2.lpn_id
11785 FROM wms_license_plate_numbers wlpn2
11786 START WITH wlpn2.lpn_id = wlpn.outermost_lpn_id
11787 CONNECT BY PRIOR wlpn2.lpn_id = wlpn2.parent_lpn_id
11788 )
11789 )
11790 )
11791 )
11792 AND inv_material_status_grp.is_status_applicable
11793 ('TRUE',NULL,inv_globals.g_type_container_pack,
11794 NULL,NULL,p_organization_id,NULL,wlpn.subinventory_code,
11795 wlpn.locator_id,NULL,NULL,'Z') = 'Y'
11796 AND inv_material_status_grp.is_status_applicable
11797 ('TRUE',NULL,inv_globals.g_type_container_pack,NULL,
11798 NULL,p_organization_id,NULL,wlpn.subinventory_code,
11799 wlpn.locator_id,NULL,NULL,'L') = 'Y'
11800 )
11801 );
11802 EXCEPTION
11803 WHEN NO_DATA_FOUND THEN
11804 l_count := 0;
11805 IF (l_debug = 1) THEN
11806 debug('No data found for drop','validate_into_lpn',9);
11807 END IF;
11808 END; -- End for validation of drop
11809
11810 END IF;--IF p_lpn_id = l_into_lpn_id THEN
11811 l_progress := '70';
11812
11813 IF (l_debug = 1) THEN
11814 debug('Validated Into LPN count for drop: ' || l_count,'validate_into_lpn',9);
11815 END IF;
11816
11817 IF (l_count = 0) THEN
11818 x_validation_passed := 'N';
11819 IF (l_debug = 1) THEN
11820 debug('Into LPN validation failed! for drop! ','validate_into_lpn',9);
11821 END IF;
11822 RAISE fnd_api.g_exc_error;
11823 ELSE
11824 x_validation_passed := 'Y';
11825 IF (l_debug = 1) THEN
11826 debug('Into LPN validation passed for drop!','validate_into_lpn',9);
11827 END IF;
11828 END IF; -- end for l_count=0
11829
11830 -- LPN Sub/LOC validation
11831 --Bug #4414782
11832 IF (l_into_lpn_context = 3 AND
11833 l_into_lpn_sub IS NULL AND
11834 p_sub IS NULL AND p_loc IS NULL) THEN
11835 --The user should be be allowed to nest a LPN with sub/loc
11836 --into a RCV LPN that has no sub/loc
11837 l_sub_validation_passed := 0;
11838 ELSIF (p_drop_type = 'MANUAL_DROP' AND l_lpn_context <> l_into_lpn_context) THEN
11839 --If it is a Manual Drop, then the user should be able to drop
11840 --into a storage inventory if it is in RCV or WIP
11841 l_sub_validation_passed := 1;
11842 ELSE
11843 IF (l_into_lpn_sub IS NOT NULL AND l_into_lpn_loc_id IS NOT NULL) THEN
11844 IF (p_sub IS NOT NULL AND p_loc IS NOT NULL) THEN
11845 -- This is called from the PutawayDropPage
11846 -- So p_sub and p_loc must match the sub/loc of the
11847 -- into LPN
11848 IF (l_debug = 1) THEN
11849 debug('Validate sub for PutawayDrop scenario','validate_into_lpn',9);
11850 END IF;
11851
11852 IF (p_lpn_id <> l_into_lpn_id AND --If user enter same into
11853 --lpn AS the from LPN,
11854 --We should allow him move it
11855 --to a different place
11856 (p_sub <> Nvl(l_into_lpn_sub, '@@@') OR
11857 p_loc <> Nvl(l_into_lpn_loc_id,-999))) THEN
11858 l_sub_validation_passed := 0;
11859 ELSE
11860 l_sub_validation_passed := 1;
11861 END IF;
11862 ELSE
11863 IF (l_debug = 1) THEN
11864 debug('Calling get_crossdock_info','validate_into_lpn',9);
11865 debug(' p_lpn_id =======> '||p_lpn_id,'validate_into_lpn',9);
11866 debug(' p_organization_id ===> '||p_organization_id,'validate_into_lpn',9);
11867 END IF;
11868 wms_putaway_utils.get_crossdock_info
11869 (p_lpn_id => p_lpn_id
11870 ,p_organization_id => p_organization_id
11871 ,x_back_order_delivery_id => l_back_order_delivery_id
11872 ,x_crossdock_type => l_crossdock_type
11873 ,x_wip_supply_type => l_wip_supply_type
11874 );
11875 IF (l_debug = 1) THEN
11876 debug('After calling get_crossdock_info','validate_into_lpn',9);
11877 debug(' l_crossdock_type =======> '||l_crossdock_type,'validate_into_lpn',9);
11878 END IF;
11879
11880 BEGIN
11881 SELECT lpn_controlled_flag,reservable_type,Nvl(subinventory_type,1)
11882 INTO l_lpn_controlled_flag,l_reservable_type,l_lpn_sub_type
11883 FROM mtl_secondary_inventories
11884 WHERE organization_id = p_organization_id
11885 AND secondary_inventory_name = l_into_lpn_sub
11886 AND ((Nvl(subinventory_type,1)=1 AND
11887 NVL(disable_date, TRUNC(SYSDATE + 1)) > TRUNC(SYSDATE))
11888 OR
11889 (Nvl(subinventory_type,1)=2 AND
11890 (trunc(disable_date + (300*365)) >= trunc(SYSDATE)
11891 OR TO_CHAR(disable_date, 'YYYY/MM/DD') = '1700/01/01')))
11892 AND (((Nvl(subinventory_type,1)=1) AND
11893 inv_ui_item_sub_loc_lovs.validate_lpn_sub
11894 (p_organization_id,
11895 secondary_inventory_name,
11896 p_lpn_id) = 'Y') OR
11897 Nvl(subinventory_type,1)=2);
11898 EXCEPTION
11899 WHEN OTHERS THEN
11900 l_lpn_sub_type := -999;
11901 l_lpn_controlled_flag := -999;
11902 l_reservable_type := -999;
11903 END;
11904
11905 IF (p_drop_type <> 'MANUAL_DROP') THEN
11906 --If it is MANUAL_DROP, p_sub won't be passed
11907 BEGIN
11908 SELECT Nvl(subinventory_type,1)
11909 INTO l_sub_type
11910 FROM mtl_secondary_inventories
11911 WHERE organization_id = p_organization_id
11912 AND secondary_inventory_name = p_sub
11913 AND ((Nvl(subinventory_type,1)=1 AND
11914 NVL(disable_date, TRUNC(SYSDATE + 1)) > TRUNC(SYSDATE))
11915 OR
11916 (Nvl(subinventory_type,1)=2 AND
11917 (trunc(disable_date + (300*365)) >= trunc(SYSDATE)
11918 OR TO_CHAR(disable_date,'YYYY/MM/DD') = '1700/01/01')));
11919 EXCEPTION
11920 WHEN OTHERS THEN
11921 l_sub_type := -999;
11922 END;
11923 END IF;
11924
11925 IF (l_debug = 1) THEN
11926 debug('l_lpn_sub_type: ' || l_lpn_sub_type,'validate_into_lpn',9);
11927 debug('l_lpn_controlled_flag: ' || l_lpn_controlled_flag ,'validate_into_lpn',9);
11928 debug('l_reservable_type: ' || l_reservable_type,'validate_into_lpn',9);
11929 debug('l_sub_type: ' || l_sub_type,'validate_into_lpn',9);
11930 END IF;
11931
11932
11933 IF l_crossdock_type = 0 THEN
11934 --No crossdocking
11935 IF p_drop_type = 'SYSTEM_DROP' THEN
11936 --Directed Drop:
11937 --In this case, lpn sub must be same as suggested sub
11938 IF (p_lpn_id <> l_into_lpn_id) THEN --bug 5380737
11939 IF (l_sub_type = 1 AND l_lpn_sub_type = 1) OR
11940 (l_sub_type = 2 AND l_lpn_sub_type = 2) THEN
11941 l_sub_validation_passed := 1;
11942 ELSE
11943 l_sub_validation_passed := 0;
11944 END IF;
11945 ELSE
11946 l_sub_validation_passed := 1;
11947 END IF;
11948 ELSE
11949 --Manual drop, all sub is OK
11950 l_sub_validation_passed := 1;
11951 END IF; --IF p_drop_type = 'SYSTEM_DROP' THEN
11952 ELSIF l_crossdock_type = 1 THEN
11953 --SO xdock:
11954 IF (p_drop_type = 'MANUAL_DROP') THEN
11955 --If fromLPN is a WIP lpn, then LPN sub
11956 --must be storage sub, reservable and lpn-controlled
11957 --Otherwise, it can be rcv sub and a valid storage sub
11958 IF (l_lpn_context = 2
11959 AND l_lpn_sub_type = 1
11960 AND l_lpn_controlled_flag = 1
11961 AND l_reservable_type = 1) OR
11962 (l_lpn_context = 3
11963 AND (l_lpn_sub_type = 3 OR
11964 (l_lpn_sub_type = 1
11965 AND l_lpn_controlled_flag = 1
11966 AND l_reservable_type = 1)
11967 )
11968 ) THEN
11969 l_sub_validation_passed := 1;
11970 ELSE
11971 l_sub_validation_passed := 0;
11972 END IF;
11973 ELSE
11974 --If system suggested storage sub, then
11975 --LPN sub must be valid storage sub
11976 IF (p_lpn_id <> l_into_lpn_id) THEN --bug 5380737
11977 IF (l_sub_type = 1
11978 AND l_lpn_sub_type = 1
11979 AND l_lpn_controlled_flag = 1
11980 AND l_reservable_type = 1) OR
11981 (l_sub_type = 2
11982 AND l_lpn_sub_type = 2) THEN
11983 l_sub_validation_passed := 1;
11984 ELSE
11985 l_sub_validation_passed := 0;
11986 END IF;
11987 ELSE
11988 l_sub_validation_passed := 1;
11989 END IF;
11990 END IF; --IF (p_drop_type = 'MANUAL_DROP') THEN
11991 ELSIF l_crossdock_type = 2 THEN
11992 --WIP PULL
11993 IF (p_drop_type = 'MANUAL_LOAD') THEN
11994 IF (l_lpn_context = 2) THEN
11995 --Destination sub is not lpn controlled.
11996 --So shouldn't be allowed to enter LPN
11997 l_sub_validation_passed := 0;
11998 ELSE
11999 IF (l_lpn_sub_type = 2) THEN
12000 l_sub_validation_passed := 1;
12001 ELSE
12002 l_sub_validation_passed := 0;
12003 END IF;
12004 END IF;
12005 ELSE
12006 --The user should not be allowed to enter
12007 --LPN in inventory LPN
12008 IF (p_lpn_id <> l_into_lpn_id) THEN --bug 5380737
12009 IF (l_sub_type = 2
12010 AND l_lpn_sub_type = 2) THEN
12011 l_sub_validation_passed := 1;
12012 ELSE
12013 l_sub_validation_passed := 0;
12014 END IF;
12015 ELSE
12016 l_sub_validation_passed := 1;
12017 END IF;
12018 END IF;
12019 ELSIF l_crossdock_type = 3 THEN
12020 -- WIP Push. Into LPN field shouldn't be shown
12021 l_sub_validation_passed := 1;
12022 ELSE --l_crossdock_type = 4: SO XDOCK mixed with WIP PULL
12023 IF l_lpn_context = 2 THEN
12024 l_sub_validation_passed := 0;
12025 ELSE
12026 --System won't suggest inventory loc
12027 IF (l_lpn_sub_type = 2) THEN
12028 l_sub_validation_passed := 1;
12029 ELSE
12030 l_sub_validation_passed := 0;
12031 END IF;
12032 END IF; --IF l_lpn_context = 2 THEN
12033 END IF; --IF l_crossdock_type = 0 THEN
12034 END IF;--IF (p_sub IS NOT NULL AND p_loc IS NOT NULL) THEN
12035 END IF;--IF (p_drop_type = 'MANUAL_DROP' AND l_lpn_context <> l_into_lpn_context) THEN
12036 END IF;--IF (l_into_lpn_sub IS NOT NULL AND l_into_lpn_loc_id IS NOT NULL) THEN
12037
12038 IF (l_debug = 1) THEN
12039 debug('l_sub_validation_passed ===> '||l_sub_validation_passed,'validate_into_lpn',9);
12040 END IF;
12041
12042 IF (l_sub_validation_passed <> 1) THEN
12043 x_validation_passed := 'N';
12044 END IF;
12045
12046 END IF; -- Enf for p_drop_type = 'MANUAL_DROP' or p_drop_type = 'SYSTEM_DROP
12047 -- End for validating drop
12048 END IF;
12049
12050 -- if into LPN is an old one, need to check project/task ID
12051 IF (x_new_lpn_created = 'N') THEN
12052 IF (l_debug = 1) THEN
12053 debug('Validating project and task IDs...','validate_into_lpn', 9);
12054 END IF;
12055
12056 BEGIN
12057 IF (l_lpn_context = 1) THEN
12058 SELECT
12059 project_id
12060 ,task_id
12061 INTO
12062 l_into_lpn_project_id
12063 ,l_into_lpn_task_id
12064 FROM
12065 mtl_item_locations
12066 WHERE
12067 inventory_location_id = l_into_lpn_loc_id;
12068 ELSE -- context is 2 or 3
12069 SELECT
12070 project_id
12071 ,task_id
12072 INTO
12073 l_into_lpn_project_id
12074 ,l_into_lpn_task_id
12075 FROM
12076 mtl_txn_request_lines mtrl, (SELECT lpn_id
12077 FROM wms_license_plate_numbers
12078 START WITH lpn_id = 1
12079 CONNECT BY PRIOR lpn_id = parent_lpn_id
12080 ) wlpn2
12081 WHERE
12082 mtrl.lpn_id= wlpn2.lpn_id
12083 AND ROWNUM = 1;
12084 END IF;
12085 EXCEPTION
12086 WHEN no_data_found THEN
12087 l_into_lpn_project_id := null;
12088 l_into_lpn_task_id := null;
12089 WHEN OTHERS THEN
12090 IF (l_debug = 1) THEN
12091 debug('unexpected exception in select project/task id',
12092 'validate_into_lpn', 9);
12093 END IF;
12094 END;
12095
12096 IF (l_debug = 1) THEN
12097 debug('Into LPN Project Id = '||l_into_lpn_project_id
12098 ||' Task Id = ' || l_into_lpn_task_id,
12099 'validate_into_lpn', 9);
12100 END IF;
12101
12102 IF NOT (Nvl(p_project_id, -9999) = Nvl(l_into_lpn_project_id, -9999) AND
12103 Nvl(p_task_id, -9999) = Nvl(l_into_lpn_task_id, -9999)) THEN
12104 IF (l_debug = 1) THEN
12105 debug('validate project/task ID failed','validate_into_lpn',9);
12106 END IF;
12107
12108 x_validation_passed := 'N';
12109 RAISE fnd_api.g_exc_error;
12110 END IF; --NOT (Nvl(p_project_id, 9999) = Nvl(l_into_lpn_project_id, 9999)
12111 -- AND Nvl(p_task_id, 9999) = Nvl(l_into_lpn_task_id, 9999))
12112 END IF; -- IF (x_new_lpn_created = 'N')
12113
12114 -- Set the return status to success
12115 x_return_status := fnd_api.g_ret_sts_success;
12116 l_progress := '80';
12117
12118 IF (l_debug = 1) THEN
12119 debug('***End of validate_into_lpn***','validate_into_lpn',9);
12120 END IF;
12121
12122 EXCEPTION
12123 WHEN FND_API.G_EXC_ERROR THEN
12124 ROLLBACK TO validate_lpn_sp;
12125 x_return_status := fnd_api.g_ret_sts_error;
12126 x_validation_passed := 'N';
12127 x_new_lpn_created := 'N';
12128 fnd_msg_pub.count_and_get(p_count => x_msg_count,
12129 p_data => x_msg_data);
12130 IF (l_debug = 1) THEN
12131 debug('Exiting validate_into_lpn - Execution error: ' ||
12132 l_progress ||' '|| TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),'validate_into_lpn',9);
12133 END IF;
12134
12135 WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
12136 ROLLBACK TO validate_lpn_sp;
12137 x_return_status := fnd_api.g_ret_sts_unexp_error;
12138 x_validation_passed := 'N';
12139 x_new_lpn_created := 'N';
12140 fnd_msg_pub.count_and_get(p_count => x_msg_count,
12141 p_data => x_msg_data);
12142 IF (l_debug = 1) THEN
12143 debug('Exiting validate_into_lpn - Unexpected error: ' ||
12144 l_progress ||' '|| TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),'validate_into_lpn',9);
12145 END IF;
12146
12147 WHEN OTHERS THEN
12148 ROLLBACK TO validate_lpn_sp;
12149 x_return_status := fnd_api.g_ret_sts_unexp_error;
12150 x_validation_passed := 'N';
12151 x_new_lpn_created := 'N';
12152 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
12153 fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
12154 END IF;
12155 fnd_msg_pub.count_and_get(p_count => x_msg_count,
12156 p_data => x_msg_data);
12157 IF (l_debug = 1) THEN
12158 debug('Exiting validate_into_lpn - Others exception: ' ||
12159 l_progress ||' '|| TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),'validate_into_lpn',9);
12160 END IF;
12161
12162 END validate_into_lpn;
12163
12164 PROCEDURE get_crossdock_info
12165 (p_lpn_id IN NUMBER,
12166 p_organization_id IN NUMBER,
12167 x_back_order_delivery_id OUT nocopy NUMBER,
12168 x_crossdock_type OUT nocopy NUMBER,
12169 x_wip_supply_type OUT nocopy NUMBER )
12170 IS
12171 l_back_order_delivery_id NUMBER := -1;
12172 l_crossdock_type NUMBER := -1;
12173 l_wip_supply_type NUMBER := -1;
12174 l_backorder_delivery_ids num_tab;
12175 l_crossdock_types num_tab;
12176 l_wip_supply_types num_tab;
12177 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'),
12178 0);
12179 l_progress VARCHAR(5) := '0';
12180
12181 BEGIN
12182 IF (l_debug = 1) THEN
12183 debug('Entering get_crossdock_into:','get_crossdock_info',9);
12184 debug(' p_lpn_id ==========> ' || p_lpn_id, 'get_crossdock_info',9);
12185 debug(' p_organization_id =>'||p_organization_id,'get_crossdock_info',9);
12186 END IF;
12187
12188 l_progress := '10';
12189
12190 BEGIN
12191 SELECT
12192 DISTINCT
12193 Nvl(mol.backorder_delivery_detail_id,-1) back_order_delivery_detail_id,
12194 Nvl(mol.crossdock_type,1) crossdock_type,
12195 Nvl(mmtt.wip_supply_type,0) wip_supply_type
12196 bulk collect INTO
12197 l_backorder_delivery_ids,
12198 l_crossdock_types,
12199 l_wip_supply_types
12200 FROM
12201 mtl_txn_request_lines mol,
12202 mtl_material_transactions_temp mmtt ,
12203 (SELECT wlpn.lpn_id /*5723418*/
12204 FROM wms_license_plate_numbers wlpn
12205 START WITH wlpn.lpn_id = p_lpn_id
12206 CONNECT BY PRIOR wlpn.lpn_id = wlpn.parent_lpn_id ) wlpn
12207 WHERE mol.lpn_id = wlpn.lpn_id
12208 AND mol.organization_id = p_organization_id
12209 AND mol.line_id = mmtt.move_order_line_id
12210 AND mmtt.organization_id = p_organization_id
12211 ORDER BY wip_supply_type DESC;
12212 EXCEPTION
12213 WHEN OTHERS THEN
12214 IF (l_debug = 1) THEN
12215 debug('MMTT exists. Treat it as no crossdock','get_crossdock_info',9);
12216 END IF;
12217 END;
12218
12219 l_progress := '20';
12220
12221 l_crossdock_type := 0;
12222
12223 FOR i IN 1 .. l_backorder_delivery_ids.COUNT LOOP
12224 IF l_wip_supply_types(i) = 1 THEN
12225 l_crossdock_type := 3; -- WIP PUSH overrides all other types
12226 EXIT;
12227 END IF;
12228
12229 IF l_backorder_delivery_ids(i) <> -1 AND l_crossdock_types(i) = 1 THEN
12230 IF (l_crossdock_type = 0) THEN
12231 l_crossdock_type := 1; -- SO xdock.
12232 ELSIF (l_crossdock_type = 2) THEN
12233 l_crossdock_type := 4; -- Both SO xdock and WIP Pulled XDOCK
12234 -- No need to look further, since if there
12235 -- is a WIP push, it should have been already processed
12236 EXIT;
12237 END IF;
12238 END IF;
12239
12240 IF l_backorder_delivery_ids(i) <> -1 AND l_crossdock_types(i) = 2 THEN
12241 -- If it comes here, then it must by a WIP PULL xdock
12242 IF (l_crossdock_type = 0) THEN
12243 l_crossdock_type := 2;
12244 ELSIF (l_crossdock_type = 1) THEN
12245 l_crossdock_type := 4; -- Both SO xdock and WIP Pulled XDOCK
12246 EXIT;
12247 END IF;
12248 END IF;
12249 END LOOP;
12250
12251 l_progress := '30';
12252
12253 x_back_order_delivery_id := -9999;
12254 x_crossdock_type := l_crossdock_type;
12255 x_wip_supply_type := -9999;
12256
12257 IF (l_debug = 1) THEN
12258 debug('Exitting get_crossdock_into:','get_crossdock_info',9);
12259 debug(' x_backorder_delivery_detail_id ==========> ' || l_back_order_delivery_id, 'get_crossdock_info',9);
12260 debug(' x_crossdock_type =>'||l_crossdock_type,'get_crossdock_info',9);
12261 debug(' x_wip_supply_type =>'||l_wip_supply_type,'get_crossdock_info',9);
12262 END IF;
12263 EXCEPTION
12264 WHEN OTHERS THEN
12265 IF (l_debug = 1) THEN
12266 debug('Exception occured after progress' || l_progress,'get_crossdock_info',9);
12267 END IF;
12268
12269 NULL;
12270 END get_crossdock_info;
12271
12272 PROCEDURE update_loc_suggested_capacity(
12273 x_return_status OUT NOCOPY VARCHAR2
12274 , x_msg_count OUT NOCOPY NUMBER
12275 , x_msg_data OUT NOCOPY VARCHAR2
12276 , p_organization_id IN NUMBER
12277 , p_lpn_id IN NUMBER
12278 , p_location_id IN NUMBER
12279 ) IS
12280 l_api_name CONSTANT VARCHAR2(30) := 'update_loc_suggested_capacity';
12281 l_progress VARCHAR2(10);
12282 l_item_id NUMBER;
12283 l_locator_id NUMBER;
12284 l_quantity NUMBER;
12285 l_uom_code VARCHAR2(3);
12286 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
12287
12288 CURSOR l_suggestions_cursor IS
12289 --BUG 3435079: Use organization_id MTRL and MMTT
12290 --for performance reason
12291 SELECT mmtt.inventory_item_id
12292 , mmtt.locator_id
12293 , mmtt.transaction_quantity
12294 , mmtt.transaction_uom
12295 FROM mtl_material_transactions_temp mmtt,
12296 mtl_txn_request_lines mtrl ,
12297 (SELECT lpn_id /*5723418*/
12298 FROM wms_license_plate_numbers
12299 START WITH lpn_id = p_lpn_id
12300 CONNECT BY PRIOR lpn_id = parent_lpn_id) wlpn
12301 WHERE mmtt.move_order_line_id = mtrl.line_id
12302 AND mmtt.organization_id = p_organization_id
12303 AND mtrl.organization_id = p_organization_id
12304 AND mtrl.lpn_id = wlpn.lpn_id
12305 AND NVL(mmtt.wms_task_type, 0) <> -1;
12306
12307 BEGIN
12308 IF (l_debug = 1) THEN
12309 debug('***Calling WMSPUTLB.update_loc_suggested_capacity***');
12310 debug('Org ID: => ' || p_organization_id);
12311 debug('LPN ID: => ' || p_lpn_id);
12312 debug('USER ENTERED LOCATOR ID: => ' || p_location_id);
12313 END IF;
12314
12315 -- Set the savepoint
12316 SAVEPOINT update_capacity_sp;
12317 l_progress := '10';
12318 -- Loop through each suggested MMTT line for the LPN
12319 OPEN l_suggestions_cursor;
12320
12321 LOOP
12322 FETCH l_suggestions_cursor INTO l_item_id, l_locator_id, l_quantity, l_uom_code;
12323 EXIT WHEN l_suggestions_cursor%NOTFOUND;
12324
12325 IF (l_debug = 1) THEN
12326 debug('Current MMTT suggestion values:');
12327 debug('Inventory Item ID: => ' || l_item_id);
12328 debug('Locator ID: ========> ' || l_locator_id);
12329 debug('Transaction qty: ===> ' || l_quantity);
12330 debug('Transaction UOM: ===> ' || l_uom_code);
12331 END IF;
12332
12333 l_progress := '20';
12334
12335 IF (l_debug = 1) THEN
12336 debug('Call INV_LOC_WMS_UTILS.update_loc_suggested_capacity API');
12337 END IF;
12338
12339 inv_loc_wms_utils.update_loc_suggested_capacity(
12340 x_return_status => x_return_status
12341 , x_msg_count => x_msg_count
12342 , x_msg_data => x_msg_data
12343 , p_organization_id => p_organization_id
12344 , p_inventory_location_id => p_location_id
12345 , p_inventory_item_id => l_item_id
12346 , p_primary_uom_flag => 'N'
12347 , p_transaction_uom_code => l_uom_code
12348 , p_quantity => l_quantity
12349 );
12350 l_progress := '30';
12351
12352 IF (x_return_status = fnd_api.g_ret_sts_success) THEN
12353 IF (l_debug = 1) THEN
12354 debug('Success returned from update_loc_suggested_capacity API');
12355 END IF;
12356 ELSE
12357 IF (l_debug = 1) THEN
12358 debug('Failure returned from update_loc_suggested_capacity API');
12359 END IF;
12360 -- Bug 5393727: do not raise an exception if locator API returns an error
12361 -- RAISE fnd_api.g_exc_error;
12362 END IF;
12363
12364 l_progress := '40';
12365 END LOOP;
12366
12367 CLOSE l_suggestions_cursor;
12368 -- Set the output variable
12369 x_return_status := fnd_api.g_ret_sts_success;
12370 l_progress := '50';
12371
12372 IF (l_debug = 1) THEN
12373 debug('***End of update_loc_suggested_capacity***');
12374 END IF;
12375 EXCEPTION
12376 WHEN fnd_api.g_exc_error THEN
12377 ROLLBACK TO update_capacity_sp;
12378 x_return_status := fnd_api.g_ret_sts_error;
12379 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
12380
12381 IF (l_debug = 1) THEN
12382 debug(
12383 'Exiting update_loc_suggested_capacity - Execution error: ' || l_progress || ' '
12384 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
12385 );
12386 END IF;
12387 WHEN fnd_api.g_exc_unexpected_error THEN
12388 ROLLBACK TO update_capacity_sp;
12389 x_return_status := fnd_api.g_ret_sts_unexp_error;
12390 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
12391
12392 IF (l_debug = 1) THEN
12393 debug(
12394 'Exiting update_loc_suggested_capacity - Unexpected error: ' || l_progress || ' '
12395 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
12396 );
12397 END IF;
12398 WHEN OTHERS THEN
12399 ROLLBACK TO update_capacity_sp;
12400 x_return_status := fnd_api.g_ret_sts_unexp_error;
12401
12402 IF fnd_msg_pub.check_msg_level(fnd_msg_pub.g_msg_lvl_unexp_error) THEN
12403 fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
12404 END IF;
12405
12406 fnd_msg_pub.count_and_get(p_count => x_msg_count, p_data => x_msg_data);
12407
12408 IF (l_debug = 1) THEN
12409 debug(
12410 'Exiting update_loc_suggested_capacity - Others exception: ' || l_progress || ' '
12411 || TO_CHAR(SYSDATE, 'YYYY-MM-DD HH:DD:SS')
12412 );
12413 END IF;
12414 END update_loc_suggested_capacity;
12415
12416 PROCEDURE validate_material_status
12417 (x_passed OUT NOCOPY VARCHAR2
12418 , p_organization_id IN NUMBER
12419 , p_sub IN VARCHAR2
12420 , p_loc IN NUMBER
12421 ) IS
12422 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
12423 l_proc_name VARCHAR2(30) := 'validate_material_status';
12424 BEGIN
12425 IF (l_debug = 1) THEN
12426 DEBUG(' Function Entered at ' ||
12427 to_char(SYSDATE, 'YYYY-MM-DD HH:DD:SS'),l_proc_name,1);
12428 DEBUG(' p_organization_id => '||p_organization_id,l_proc_name , 4);
12429 DEBUG(' p_sub => '||p_sub,l_proc_name, 4);
12430 DEBUG(' p_loc => '||p_loc,l_proc_name, 4);
12431 END IF;
12432
12433 IF (inv_material_status_grp.is_status_applicable('TRUE',
12434 NULL,
12435 2,--subtransfer
12436 NULL,
12437 NULL,
12438 p_organization_id,
12439 NULL,
12440 p_sub,
12441 p_loc,
12442 NULL,
12443 NULL,
12444 'Z') ='Y' AND
12445 inv_material_status_grp.is_status_applicable('TRUE',
12446 NULL,
12447 2,--Sub Transfer
12448 NULL,
12449 NULL,
12450 p_organization_id,
12451 NULL,
12452 p_sub,
12453 p_loc,
12454 NULL,
12455 NULL,
12456 'L') = 'Y') THEN
12457 x_passed := 'Y';
12458 ELSE
12459 x_passed := 'N';
12460 END IF;
12461 IF (l_debug = 1) THEN
12462 DEBUG(' x_passed => '||x_passed,l_proc_name, 4);
12463 END IF;
12464
12465 EXCEPTION
12466 WHEN OTHERS THEN
12467 x_passed := 'Y';
12468 END validate_material_status;
12469
12470 FUNCTION populate_grouping_rows
12471 (p_lpn_id IN NUMBER)
12472 RETURN NUMBER IS
12473
12474 CURSOR c_lpn_bo_dd_id (v_lpn_id NUMBER)IS
12475 SELECT mtrl.backorder_delivery_detail_id,
12476 wda.delivery_id
12477 FROM mtl_txn_request_lines mtrl,
12478 wsh_delivery_assignments_v wda
12479 WHERE lpn_id = v_lpn_id
12480 AND mtrl.backorder_delivery_detail_id = wda.delivery_detail_id;
12481
12482 l_count NUMBER := 1;
12483 l_bo_dd_id NUMBER;
12484 l_return_status VARCHAR2(1);
12485 l_progress NUMBER;
12486 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
12487 l_proc_name VARCHAR2(30) := 'populate_grouping_rows';
12488
12489 BEGIN
12490
12491 g_line_rows.delete;
12492 g_grouping_rows.delete;
12493
12494 IF (l_debug = 1) THEN
12495 debug('populate_grouping_rows: p_lpn_id='||p_lpn_id);
12496 END IF;
12497
12498 l_progress := 100;
12499
12500 OPEN c_lpn_bo_dd_id(p_lpn_id);
12501
12502 FETCH c_lpn_bo_dd_id BULK COLLECT INTO g_line_rows, g_grouping_rows;
12503 CLOSE c_lpn_bo_dd_id;
12504
12505 l_progress := 300;
12506
12507 IF (l_debug = 1) THEN
12508 debug('populate_grouping_rows: g_line_rows.count='||g_line_rows.count);
12509 debug('populate_grouping_rows: g_grouping_rows.count='||g_grouping_rows.COUNT);
12510 END IF;
12511
12512 RETURN g_grouping_rows.COUNT;
12513
12514 END populate_grouping_rows;
12515
12516 FUNCTION get_grouping_count
12517 (p_line_rows IN WSH_UTIL_CORE.id_tab_type)
12518 RETURN NUMBER IS
12519
12520 l_count NUMBER;
12521 l_bo_dd_id NUMBER := -1;
12522 l_duplicate NUMBER := 0;
12523 l_progress NUMBER;
12524 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
12525 l_proc_name VARCHAR2(30) := 'get_grouping_count';
12526
12527 BEGIN
12528
12529 IF (l_debug = 1) THEN
12530 debug('get_grouping_count: Inside get_grouping_count');
12531 END IF;
12532
12533 FOR l_count IN 1..p_line_rows.COUNT LOOP
12534 IF (l_debug = 1) THEN
12535 debug('get_grouping_count: l_bo_dd_id='||l_bo_dd_id);
12536 debug('get_grouping_count: p_line_rows(l_count)='||p_line_rows(l_count));
12537 END IF;
12538
12539 IF (l_bo_dd_id <> p_line_rows(l_count)) THEN
12540 l_duplicate := l_duplicate + 1;
12541 END IF;
12542
12543 l_bo_dd_id := p_line_rows(l_count);
12544 END LOOP;
12545
12546 IF (l_debug = 1) THEN
12547 debug('get_grouping_count: l_duplicate='||l_duplicate);
12548 END IF;
12549
12550 RETURN l_duplicate;
12551
12552 END get_grouping_count;
12553
12554 FUNCTION get_grouping
12555 (p_bo_dd_id IN NUMBER)
12556 RETURN NUMBER IS
12557
12558 l_index NUMBER;
12559 i NUMBER;
12560 l_progress NUMBER;
12561 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
12562 l_proc_name VARCHAR2(30) := 'get_grouping';
12563
12564 BEGIN
12565 IF (l_debug = 1) THEN
12566 debug('get_grouping: p_bo_dd_id='||p_bo_dd_id);
12567 END IF;
12568
12569 <<get_grouping_loop>>
12570 FOR i IN 1..g_line_rows.COUNT LOOP
12571 IF (l_debug = 1) THEN
12572 debug('get_grouping: g_line_rows(i)='||g_line_rows(i));
12573 END IF;
12574 IF (g_line_rows(i) = p_bo_dd_id) THEN
12575 l_index := i;
12576 debug('get_grouping: l_index='||l_index);
12577 EXIT get_grouping_loop;
12578 END IF;
12579 END LOOP;
12580
12581 IF (l_debug = 1) THEN
12582 debug('get_grouping: l_index='||l_index);
12583 IF l_index IS NOT NULL THEN
12584 debug('get_grouping: g_grouping_rows(l_index)='||g_grouping_rows(l_index));
12585 END IF;
12586 END IF;
12587
12588 IF l_index IS NOT NULL THEN
12589 RETURN g_grouping_rows(l_index);
12590 ELSE
12591 RETURN p_bo_dd_id;
12592 END IF;
12593
12594 END get_grouping;
12595
12596 --Added following procedure for bug 7143123
12597 /**
12598 * Cleanup_LPN_Crossdock_Wrapper, This procedure explodes the given LPN
12599 * and for each LPN checks whether crossdock move order exists and if so clean up the crossdock related data.
12600 * @param p_org_id Current Organization
12601 * @param p_lpn_id From LPN ID
12602 * @param x_return_status
12603 **/
12604
12605 PROCEDURE Cleanup_LPN_Crossdock_Wrapper(
12606 p_org_id IN NUMBER
12607 , p_lpn_id IN NUMBER
12608 , x_return_status OUT NOCOPY VARCHAR2
12609 )
12610 IS
12611 l_progress NUMBER;
12612 l_lpn_id NUMBER;
12613 l_tempid NUMBER;
12614 l_debug NUMBER := NVL(fnd_profile.VALUE('INV_DEBUG_TRACE'), 0);
12615 l_content_lpn VARCHAR2(1) := 'N';
12616 l_lpn_context NUMBER;
12617 l_lpn_has_contents VARCHAR2(1) := 'N';
12618 l_x_msg_count NUMBER;
12619 l_error_code NUMBER;
12620 l_x_msg_data FND_NEW_MESSAGES.MESSAGE_TEXT%TYPE; --VARCHAR2(2000);
12621 l_proc_name VARCHAR2(100) := 'Cleanup_LPN_Crossdock_Wrapper';
12622
12623
12624 CURSOR lpn_cursor IS
12625 SELECT lpn_id
12626 FROM wms_license_plate_numbers
12627 START WITH lpn_id = p_lpn_id
12628 CONNECT BY parent_lpn_id = PRIOR lpn_id;
12629
12630 CURSOR c_mmtt_cursor(p_lpn number) IS
12631 SELECT mmtt.transaction_temp_id,
12632 mmtt.parent_line_id,
12633 mmtt.operation_plan_id,
12634 mol.line_id move_order_line_id,
12635 mmtt.operation_seq_num,
12636 mmtt.repetitive_line_id,
12637 mmtt.primary_quantity,
12638 mmtt.inventory_item_id,
12639 mol.crossdock_type,
12640 mol.backorder_delivery_detail_id
12641 FROM mtl_material_transactions_temp mmtt,
12642 mtl_txn_request_lines mol
12643 WHERE mmtt.move_order_line_id(+) = mol.line_id
12644 AND mmtt.wms_task_type=2
12645 AND mol.organization_id = mmtt.organization_id(+)
12646 AND mol.organization_id=p_org_id
12647 AND mol.lpn_id = p_lpn
12648 AND mol.LINE_STATUS <> 5
12649 AND EXISTS (SELECT 1 FROM mtl_txn_request_lines
12650 WHERE lpn_id = p_lpn
12651 AND BACKORDER_DELIVERY_DETAIL_ID IS NOT NULL);
12652
12653 l_mmtt_rec c_mmtt_cursor%ROWTYPE;
12654 PRAGMA AUTONOMOUS_TRANSACTION;
12655 BEGIN
12656
12657 -- Intialize out variables.
12658 l_progress := 10;
12659 l_content_lpn := 'N';
12660 x_return_status := fnd_api.g_ret_sts_success;
12661
12662 IF (l_debug = 1) THEN
12663 debug(l_progress||'Patchset J code - Cleanup_LPN_Crossdock_Wrapper');
12664 debug(l_progress||'p_org_id==> '|| p_org_id);
12665 debug(l_progress||'p_lpn_id==> '|| p_lpn_id);
12666 END IF;
12667
12668 -- Get LPN Context
12669 SELECT lpn_context
12670 INTO l_lpn_context
12671 FROM wms_license_plate_numbers
12672 WHERE lpn_id = p_lpn_id;
12673
12674 l_progress := 20;
12675
12676 OPEN lpn_cursor;
12677 l_progress := 30;
12678 LOOP
12679 FETCH lpn_cursor INTO l_lpn_id;
12680 EXIT WHEN lpn_cursor%NOTFOUND;
12681 l_content_lpn := 'N';
12682
12683 IF(l_debug = 1) THEN
12684 debug(l_progress||'cleaning crossdock of Lpn ' || l_lpn_id);
12685 END IF;
12686 l_progress := 40;
12687 -- Check lpn has contents
12688 BEGIN
12689 SELECT 'Y','Y'
12690 INTO l_content_lpn,l_lpn_has_contents
12691 FROM wms_lpn_contents
12692 WHERE parent_lpn_id = l_lpn_id
12693 AND ROWNUM<2;
12694 EXCEPTION
12695 WHEN no_data_found THEN
12696 l_content_lpn := 'N';
12697 END;
12698
12699 IF l_debug = 1 THEN
12700 IF (l_content_lpn = 'N') THEN debug(l_progress||'lpn ' || l_lpn_id || 'has no contents'); END IF;
12701 IF (l_content_lpn = 'Y') THEN debug(l_progress||'lpn ' || l_lpn_id || 'has contents'); END IF;
12702 END IF;
12703
12704 IF l_content_lpn ='Y' THEN
12705 IF (l_lpn_context = 3) THEN
12706 OPEN c_mmtt_cursor(l_lpn_id);
12707 l_progress := 50;
12708 LOOP
12709 FETCH c_mmtt_cursor INTO l_mmtt_rec;
12710 EXIT WHEN c_mmtt_cursor%NOTFOUND;
12711
12712 IF (l_debug=1) THEN
12713 debug(l_progress||'Before calling revert_crossdock with following params:', l_proc_name,1);
12714 debug(l_progress||'transaction_temp_id => '|| l_mmtt_rec.transaction_temp_id, l_proc_name,1);
12715 debug(l_progress||'parent_line_id => '|| l_mmtt_rec.parent_line_id, l_proc_name,1);
12716 debug(l_progress||'p_move_order_line_id => '|| l_mmtt_rec.move_order_line_id, l_proc_name,1);
12717 debug(l_progress||'p_crossdock_type => '|| l_mmtt_rec.crossdock_type, l_proc_name,1);
12718 debug(l_progress||'p_backorder_delivery_detail_id => '|| l_mmtt_rec.backorder_delivery_detail_id, l_proc_name,1);
12719 debug(l_progress||'p_repetitive_line_id => '|| l_mmtt_rec.repetitive_line_id, l_proc_name,1);
12720 debug(l_progress||'p_operation_seq_number => '|| l_mmtt_rec.operation_seq_num, l_proc_name,1);
12721 debug(l_progress||'p_inventory_item_id => '|| l_mmtt_rec.inventory_item_id, l_proc_name,1);
12722 debug(l_progress||'p_primary_quantity => '|| l_mmtt_rec.primary_quantity, l_proc_name,1);
12723 END IF;
12724
12725 l_progress := 60;
12726 IF l_mmtt_rec.transaction_temp_id IS NOT NULL THEN
12727 wms_atf_runtime_pub_apis.Cleanup_Operation_Instance
12728 ( p_source_task_id => l_mmtt_rec.transaction_temp_id
12729 , p_activity_type_id => G_OP_ACTIVITY_INBOUND
12730 , x_return_status => x_return_status
12731 , x_msg_data => l_x_msg_data
12732 , x_msg_count => l_x_msg_count
12733 , x_error_code => l_error_code
12734 );
12735
12736 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
12737 IF (l_debug = 1) THEN
12738 debug(l_progress||l_error_code || ' Error in Cleanup_Operation_Instance ' ,l_proc_name,1);
12739 END IF;
12740 l_progress := 70;
12741 x_return_status := fnd_api.g_ret_sts_error;
12742 /* Don't raise error in case of failure, instead set the ret status as error
12743 and proceed with the next record */
12744 END IF;
12745
12746 l_progress := 80;
12747
12748 FOR wooi IN (SELECT operation_instance_id
12749 FROM wms_op_operation_instances
12750 WHERE source_task_id = l_mmtt_rec.transaction_temp_id
12751 ) LOOP
12752
12753 wms_op_runtime_pvt_apis.delete_operation_instance
12754 ( p_operation_instance_id => wooi.operation_instance_id
12755 , x_return_status => x_return_status
12756 , x_msg_data => l_x_msg_data
12757 , x_msg_count => l_x_msg_count
12758 );
12759
12760 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
12761 IF (l_debug = 1) THEN
12762 debug(l_progress||l_error_code || ' Error in delete_operation_instance ' ,l_proc_name,1);
12763 END IF;
12764 l_progress := 90;
12765 x_return_status := fnd_api.g_ret_sts_error;
12766 /* Don't raise error in case of failure, instead set the ret status as error
12767 and proceed with the next record */
12768 END IF;
12769
12770
12771 END LOOP;
12772 l_progress := 100;
12773
12774 FOR wopi IN (SELECT OP_PLAN_INSTANCE_ID
12775 FROM wms_op_plan_instances
12776 WHERE source_task_id = l_mmtt_rec.parent_line_id
12777 ) LOOP
12778 l_progress := 110;
12779 wms_op_runtime_pvt_apis.delete_plan_instance
12780 ( p_op_plan_instance_id => wopi.OP_PLAN_INSTANCE_ID
12781 , x_return_status => x_return_status
12782 , x_msg_data => l_x_msg_data
12783 , x_msg_count => l_x_msg_count
12784 );
12785
12786 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
12787 IF (l_debug = 1) THEN
12788 debug(l_progress||l_error_code || ' Error in delete_plan_instance ' ,l_proc_name,1);
12789 END IF;
12790 l_progress := 120;
12791 x_return_status := fnd_api.g_ret_sts_error;
12792 /* Don't raise error in case of failure, instead set the ret status as error
12793 and proceed with the next record */
12794 END IF;
12795
12796 END LOOP;
12797
12798 l_progress := 130;
12799 inv_trx_util_pub.delete_transaction
12800 ( x_return_status => x_return_status
12801 , x_msg_data => l_x_msg_data
12802 , x_msg_count => l_x_msg_count
12803 , p_transaction_temp_id => l_mmtt_rec.transaction_temp_id
12804 , p_update_parent => true
12805 );
12806
12807 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
12808 IF (l_debug = 1) THEN
12809 debug(l_progress||' Error in delete_transaction ' ,l_proc_name,1);
12810 END IF;
12811 l_progress := 140;
12812 x_return_status := fnd_api.g_ret_sts_error;
12813 /* Don't raise error in case of failure, instead set the ret status as error
12814 and proceed with the next record */
12815 END IF;
12816 END IF;
12817
12818 l_progress := 150;
12819
12820
12821 IF l_mmtt_rec.backorder_delivery_detail_id IS NOT NULL then
12822 WMS_OP_INBOUND_PVT.revert_crossdock
12823 (x_return_status => x_return_status
12824 , x_msg_count => l_x_msg_count
12825 , x_msg_data => l_x_msg_data
12826 , p_move_order_line_id => l_mmtt_rec.move_order_line_id
12827 , p_crossdock_type => l_mmtt_rec.crossdock_type
12828 , p_backorder_delivery_detail_id => l_mmtt_rec.backorder_delivery_detail_id
12829 , p_repetitive_line_id => l_mmtt_rec.repetitive_line_id
12830 , p_operation_seq_number => l_mmtt_rec.operation_seq_num
12831 , p_inventory_item_id => l_mmtt_rec.inventory_item_id
12832 , p_primary_quantity => l_mmtt_rec.primary_quantity
12833 );
12834
12835 IF (x_return_status <> fnd_api.g_ret_sts_success) THEN
12836 IF (l_debug = 1) THEN
12837 debug(l_progress||' Error in revert_crossdock ' ,l_proc_name,1);
12838 END IF;
12839 l_progress := 160;
12840 x_return_status := fnd_api.g_ret_sts_error;
12841 /* Don't raise error in case of failure, instead set the ret status as error
12842 and proceed with the next record */
12843 END IF;
12844
12845 END IF;
12846 l_progress := 170;
12847
12848 UPDATE mtl_txn_request_lines SET quantity_detailed=NULL WHERE line_id=l_mmtt_rec.move_order_line_id;
12849
12850 l_progress := 180;
12851
12852 END LOOP;
12853
12854 IF c_mmtt_cursor%isopen THEN
12855 CLOSE c_mmtt_cursor;
12856 END IF;
12857 l_progress := 190;
12858
12859 END IF;
12860
12861 IF(l_debug= 1) THEN
12862 debug(l_progress||'After cleaning crossdock for lpn '|| l_lpn_id);
12863 debug(l_progress||'Return status ' || x_return_status);
12864 END IF;
12865
12866 l_progress := 200;
12867 END IF;
12868 END LOOP;
12869
12870 l_progress := 210;
12871 IF lpn_cursor%isopen THEN
12872 CLOSE lpn_cursor;
12873 END IF;
12874
12875 COMMIT;
12876 RETURN;
12877
12878
12879 EXCEPTION
12880 WHEN OTHERS THEN
12881 ROLLBACK;
12882 x_return_status := fnd_api.g_ret_sts_unexp_error;
12883 debug(l_progress||SQLCODE, 1);
12884
12885 IF lpn_cursor%isopen THEN
12886 CLOSE lpn_cursor;
12887 END IF;
12888
12889 IF c_mmtt_cursor%isopen THEN
12890 CLOSE c_mmtt_cursor;
12891 END IF;
12892
12893 IF SQLCODE IS NOT NULL THEN
12894 l_progress := 220;
12895 inv_mobile_helper_functions.sql_error('Cleanup_LPN_Crossdock_Wrapper', l_progress, SQLCODE);
12896 END IF;
12897 END Cleanup_LPN_Crossdock_Wrapper;
12898
12899 END WMS_PUTAWAY_UTILS; --End of Package